AIF Handoff

repository·main·Indexed 42 days ago

https://github.com/lee-to/aif-handoff

An autonomous Kanban-based orchestration system built on the AI Factory framework. It enables AI agents to manage the full task lifecycle—from planning to implementation and review—using specialized subagents and automatic rework loops. Version 0.1.0 includes a React Kanban UI, a Hono REST and WebSocket API, and support for multiple runtime providers including Claude, Codex, OpenRouter, and OpenCode.

Tokens
118K
Snippets
300
Records
484
Agent score
54%

What's inside AIF Handoff

  1. Overview of AIF Handoff

    main

    AIF Handoff is an autonomous Kanban board designed for AI agents to plan, implement, and review tasks without manual intervention. It is built on the AI Factory framework and uses specialized AI subagents to orchestrate tasks through a lifecycle of stages: Backlog → Planning → Plan Ready → Implementing → Review → Done.

    Key characteristics include:

    • Automatic Rework Loops: In auto mode, if a review results in request_changes, the task automatically returns to the Implementing stage.
    • Convergence-Aware Auto-Review: If the review loop fails to converge, the system marks the task as done with manualReviewRequired=true to ensure human oversight rather than silently passing a failing task.
    • Skill-mode Tasks: Can include additional stages like Improve (after planning) and Verify (before done).
  2. Overview of AIF Handoff Architecture

    main

    AIF Handoff is a task management automation system built as a Turborepo monorepo. It uses a React Kanban UI for task creation, a Hono-based API server, and an agent coordinator that orchestrates tasks via a provider-neutral runtime layer. All data is managed through a centralized layer backed by SQLite using drizzle-orm.

    ┌─────────────┐     HTTP/WS      ┌─────────────┐
    │   Web (UI)  │ ◄──────────────► │  API Server  │
    │  React+Vite │                  │    Hono      │
    └─────────────┘                  └──────┬───────┘
                                            │
    ┌───────────────┐   Runtime API   ┌──────┴───────┐
    │ Runtime/Provider│ ◄────────────► │    Agent     │
    │ adapters        │                │ Coordinator  │
    └───────────────┘                └──────┬───────┘
                                              │
                                       ┌──────┴───────┐
                                       │ @aif/runtime
                                       │ (registry + 
                                       │ workflow spec)
                                       └──────┬───────┘
                                            │
                                     ┌──────┴───────┐
                                     │ @aif/data     
                                     │ (DB access)   
                                     └──────┬───────┘
                                            │
                                     ┌──────┴───────┐
                                     │   Database    
                                     │ (drizzle-orm) 
                                     └──────────────┘
  3. How environment variable validation works

    main
    The application uses Zod for environment variable validation, located in packages/shared/src/env.ts. If required environment variables are missing or invalid, the application will fail to start and provide a descriptive error message indicating the validation failure.
  4. How bidirectional sync works in AIF Handoff

    main

    AIF Handoff uses two execution modes to manage task state synchronization between agents and the Handoff database. The mode is determined by the presence of specific environment variables injected into the Claude Code subprocess.

    Mode 1: Managed by Handoff (HANDOFF_MODE=1)

    In this mode, the Handoff Coordinator (TypeScript) is the source of truth. It manages all status transitions and database writes directly.

    • Behavior: Skills and agents (like aif-plan or aif-implement) do not call MCP tools. Instead, they operate in a non-interactive mode, skipping prompts and relying on the coordinator to handle status updates.
    • Use Case: Automated pipelines where the coordinator drives the workflow (coordinator → planner → implementer → reviewer).

    Mode 2: Manual Claude Code session (HANDOFF_TASK_ID set, HANDOFF_MODE not set)

    In this mode, a developer runs skills directly in a Claude Code session but wants to sync progress with the Handoff system.

    • Behavior: Because there is no coordinator managing the run, skills call MCP tools themselves to update the task status and push plan content.
    • Use Case: Manual development where you want your local Claude Code actions to reflect in the Handoff Kanban UI.
    • Requirement: The Handoff MCP server must be registered in your .mcp.json configuration.
    # Skills read these at load time via dynamic shell substitution
    Handoff mode: !`echo ${HANDOFF_MODE:-}`
    Handoff task ID: !`echo ${HANDOFF_TASK_ID:-}`
    Handoff skip review: !`echo ${HANDOFF_SKIP_REVIEW:-}`
  5. How the Stale Task Watchdog works

    main

    The coordinator uses a stale-stage watchdog to prevent tasks from hanging indefinitely in specific stages (planning, implementing, or review).

    Mechanism:

    • It tracks liveness using lastHeartbeatAt (falling back to updatedAt).
    • If a task exceeds AGENT_STAGE_STALE_TIMEOUT_MS, it is moved to blocked_external with backoff.
    • If the recovery count reaches AGENT_STAGE_STALE_MAX_RETRY, the task remains in blocked_external and requires manual intervention.
    • Recovery: For implementing tasks, recovery resumes from plan_ready to ensure a clean state. Any valid human or stage transition resets the retryCount to 0.
  6. Choose between Subagents and Skills execution modes

    main

    AIF Handoff supports two execution modes, configurable via AGENT_USE_SUBAGENTS or in the Web UI:

    Subagents Mode (AGENT_USE_SUBAGENTS=true)

    Each stage runs through specialized coordinator agents (e.g., plan-coordinator, implement-coordinator) that iteratively refine results until quality criteria are met. Trade-off: Higher quality and thoroughness, but consumes more time and tokens.

    Skills Mode (AGENT_USE_SUBAGENTS=false, Default)

    Each stage runs as individual AIF skills (e.g., /aif-plan, /aif-implement, /aif-review). Trade-off: Faster execution and lower token usage. Optional flags like runPlanImprove or runPostVerify can add extra checks.

  7. Concept: Human vs AI ownership

    main

    In AIF Handoff, Human/AI ownership is distinct from autoMode.

    • Human-owned tasks: These tasks never enter the coordinator, scheduler, auto-queue, watchdog, or runtime-budget execution paths.
    • Handoffs: A handoff is rejected if an AI lease is currently live.
    • Isolation: Ownership is not filesystem isolation. You should wait for in-flight work to finish and inspect the shared project/worktree before attempting to edit it manually.
  8. Understand Runtime Model Effort Discovery

    main

    The system uses a provider-neutral discovery mechanism to determine the available 'effort' levels (e.g., low, high, max, ultra) for a selected model.

    Mental Model:

    1. Discovery: The RuntimeModel.metadata object serves as the shared Data Transfer Object (DTO) for model capabilities.
    2. Normalization: Instead of using a fixed allowlist of effort strings, the system normalizes provider-specific strings (like Codex's max or ultra) into a standard format.
    3. Authority & Fallback: The UI (specifically RuntimeProfileForm) treats the selected model's metadata as the authoritative source for effort levels. If a model does not provide metadata, the system falls back to the runtime's default effort list. If a model explicitly sets supportsEffort: false, the effort control is hidden.
    4. Mapping: Each runtime adapter (Claude, Codex, OpenCode, OpenRouter) is responsible for mapping its native payload into the RuntimeModel.metadata structure.
  9. Understand Codex Native Subagent Runtime Behavior

    main

    The runtime determines whether to use native Codex subagents or the legacy isolated skill-session mode based on a combination of environment variables, runtime settings, and file system state.

    Configuration StateResulting Behavior
    AIF_RUNTIME_CODEX_NATIVE_SUBAGENTS_ENABLED=falseIsolated mode (default)
    ENABLED=true + codex + sdk + useSubagents=true + assets presentNative Codex subagents
    ENABLED=true + codex + sdk + useSubagents=true + assets missingAutomatic fallback to isolated mode
    codexSubagentStrategy: "isolated"Explicit legacy flow (escape hatch)
    codexSubagentStrategy: "native"Profile opt-in (still requires global flag)

    Note on Claude: Claude usage remains unchanged and continues to use .claude/agents/* files.

  10. How effective profile resolution works

    main

    The system uses a specific fallback order to determine which runtime profile to use based on the current mode (Task, Planning, Review, or Chat).

    Task Mode Fallback Order

    1. tasks.runtime_profile_id
    2. projects.default_task_runtime_profile_id
    3. app_settings.default_task_runtime_profile_id
    4. Environment fallback

    Planning, Review, and Chat

    • Planning and Review: Use the same chain as Task mode. If default_plan_runtime_profile_id or default_review_runtime_profile_id are unset, they fall back to the task default at the same scope.
    • Chat: Uses default_chat_runtime_profile_id for project or app-level steps.

    Scope and Security Rules

    • App Defaults: May only point to enabled global profiles (runtime_profiles.project_id = null).
    • Project/Task Overrides: Project defaults and task/chat overrides may point to either a same-project profile or a global profile.
    • Isolation: The API rejects project-owned profiles that belong to a different project when accessed via a project scope.
  11. Understand the AIF Handoff Architecture

    main

    AIF Handoff is organized as a monorepo with several specialized packages:

    • @aif/shared: Contains types, schemas, the state machine, environment configurations, constants, and the logger.
    • @aif/runtime: Manages the runtime registry, adapters, module loader, and workflow specifications.
    • @aif/data: The centralized database access layer. Note: The api and agent packages must use @aif/data for all database operations; direct DB imports in those packages are blocked by ESLint guards.
    • @aif/api: A Hono-based REST and WebSocket server running on port 3009.
    • @aif/web: A React + Vite + TailwindCSS Kanban UI running on port 5180.
    • @aif/agent: The coordinator that uses node-cron to orchestrate subagents based on runtime definitions.
  12. Enable multi-session support for HTTP MCP transport

    main

    By default, the HTTP transport runs in single-session mode. Because the transport is stateful, only the first client can successfully initialize. Subsequent concurrent clients (e.g., a second Claude Code window) will receive a -32600 "Server already initialized" error.

    To allow multiple clients to connect concurrently to the same /mcp endpoint, enable stateless multi-session mode by setting the environment variable: AIF_MCP_HTTP_MULTI_SESSION_ENABLED=true.

    Behavior in Multi-session mode:

    • Each request gets its own short-lived server/transport.
    • The transport is POST-only. A GET /mcp request will return a 405 error.
    • Server-to-client events (like task updates) are delivered via the API broadcast endpoint rather than through the MCP transport.