Skip to content

Implement delegated execution with worker sessions and fleet UI - #6

Merged
MaxInGaussian merged 4 commits into
mainfrom
claude/inspiring-euler-edlztu
Oct 7, 2026
Merged

MaxInGaussian merged 4 commits into
mainfrom
claude/inspiring-euler-edlztu

Conversation

@MaxInGaussian

Copy link
Copy Markdown
Owner

Summary

This PR implements delegated execution mode for pi-plans, allowing plan implementation to run on worker sessions while the main session supervises. Key changes:

New execution mode:

  • Added executor-config.ts to define execution choices (current-session vs. delegated workers)
  • Added exec-mode-picker.ts for the handoff UI to select execution mode and worker model/effort
  • Modified exec.ts to support delegated execution via a pluggable DelegateDriver interface

In-process agent sessions:

  • Added agent-session.ts providing startAgentSession() and runAgentSession() for long-lived SDK sessions that can be re-prompted and steered
  • Refactored subagent.ts to hold only shared types and event normalization (moved subprocess spawning to agent-session)
  • Sessions support custom tools that close over live state (e.g., task progress reporting)

Delegated worker orchestration:

  • Added exec-delegate.ts implementing wave-based scheduling: groups tasks by shared files, balances across workers, reuses sessions across waves
  • Workers report progress through an in-process plans_update_task tool; completion is never inferred from session end
  • Handles worker failures, stalls, and repair rounds routed back to owning workers

Unified agent fleet UI:

  • Replaced separate refine/refs overlays with unified fleet-ui.ts showing all delegated agents (reviewers, ref analysts, execution reviewer, workers)
  • Added agent-fleet.ts registry tracking live agents across spawn sites
  • Added fleet-run.ts glue connecting spawn sites to the fleet and TUI
  • Moved overlay rendering logic from refine-ui.ts to fleet-ui.ts; kept state management in refine-ui-state.ts

Supporting changes:

  • Updated ui-language.ts to provide fleetChrome (renamed from refineChrome)
  • Added agents/executor.md defining the execution worker agent
  • Updated global-state.ts to remember last executor choice
  • Modified tools/refine.ts and tools/analyze-refs.ts to use the new fleet registration
  • Updated tests: moved refine-ui tests to fleet-ui, added exec-delegate, agent-session, and exec-mode-picker tests

The implementation maintains backward compatibility: current-session execution (the default) works unchanged; delegated mode is opt-in at the handoff.

Test Plan

  • Added comprehensive test suites: tests/exec-delegate.test.ts (wave scheduling, worker assignment), tests/agent-session.test.ts (session lifecycle and re-prompting), tests/fleet-ui.test.ts (list rendering and overlay), tests/exec-mode-picker.test.ts (mode selection UI), tests/agent-session-sdk.test.ts (real SDK integration)
  • Moved and updated existing refine-ui tests to tests/fleet-ui.test.ts and tests/refine-ui-state.test.ts
  • Existing tests pass; new tests cover task grouping, worker balancing, session steering, and UI rendering

Docs

  • Updated README.md to mention delegated execution
  • Updated references/state-and-config.md to document executor choice storage
  • Updated references/pi-planning-workflow.md to reflect new execution modes
  • Updated tool docstrings in tools/refine.ts and tools/analyze-refs.ts to reference the shared fleet UI

https://claude.ai/code/session_01DLopn2G79H3ffu1ZdjGVz6

claude added 4 commits October 7, 2026 08:00
…subagent list

Reviewers, reference analysts and the execution reviewer used to be separate
pi processes whose output was a one-shot stream, rendered as up to three
stacked panes in one overlay. They now run as in-process agent sessions that
stay addressable (steer, re-prompt, abort) and report into a shared fleet.

- add src/agent-session.ts: session engine with a per-run abort/timeout,
  usage metering, errored-final-turn detection and a test seam
- add src/agent-fleet.ts and src/fleet-run.ts: registry of live agents with a
  concurrency helper, so long reference lists queue instead of batching
- add src/fleet-ui.ts: bulleted list above the editor (Down focuses it with an
  empty editor, Up/Down select, Enter opens one agent's overlay, Esc backs
  out) plus a single-agent detail overlay with scroll, follow and stop
- hand reviewers a read-only code_graph tool (buildCodeGraphTool) since
  in-process sessions load no extensions
- remove the process spawner and the three-pane overlay; port their tests
At the execution handoff the user now picks where the plan runs: the current
session (same model), one delegated subagent, or several. For delegated runs
the model and effort come from the same picker the reviewer uses, which is
extracted into pickModelAndEffort without persistence. The last choice is
offered first and stored per run in the checkpoint.

Workers are in-process sessions that receive their own plans_update_task tool
closed over the live execution state, so a finished task repaints the
dashboard immediately while the worker's loop keeps going; completion is never
inferred from a session ending.

- add src/exec-delegate.ts: per-wave scheduling (tasks sharing a file go to one
  worker, a wave starts only after the previous one is terminal), session reuse
  across waves and repair rounds, stall and failure ladders, restore from the
  checkpoint or session snapshot
- add src/exec-mode-picker.ts, src/executor-config.ts and agents/executor.md
- store an executor block in the execution checkpoint and an executor_last
  default in the global config; the legacy v0.6.0 delegate marker stays refused
- route review repair briefs to the owning worker instead of waking the main
  model, and block edit/write in the supervising session while delegated
…sessions

Rewrite the README overlay section as "Delegated subagents", document the
execution-placement question, the executor checkpoint block and the
executor_last default, and replace the stale child-process wording (including
the default-level row, which now says "no explicit level").

- validate: require the new modules and a write-enabled agents/executor.md
  that declares plans_update_task
- readme-check: count defineTool literals and mandate the renamed heading
- agent sessions: allowlist custom tool names, because the SDK enables only
  named tools; add an integration test against the real SDK that runs a
  custom tool mid-run and re-prompts the same session
- fleet: drop finished agents from the list after ten minutes
pi-tui's Editor class can be a second module copy inside the host, which
defeats instanceof and would leave the subagent list unreachable. Fall back to
the editor's getText() API while still ignoring select dialogs.
@MaxInGaussian
MaxInGaussian merged commit 273ea51 into main Oct 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants