Skip to content

Split createRunner into runner modules (behavior-preserving) - #127

Merged
alosec merged 1 commit into
mainfrom
riker/split-create-runner
Nov 16, 2026
Merged

alosec merged 1 commit into
mainfrom
riker/split-create-runner

Conversation

@alosec

@alosec alosec commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Behavior-preserving refactor of src/agent.ts. createRunner was one ~1,900-line closure; it is now ~1,000 lines of wiring plus the AgentRunner methods, with self-contained pieces moved to src/runner/:

Module What moved there
run-state.ts RunState type + factory, per-run reset (beginRunState) and clear (clearRunState), the per-run output queue (createRunQueue), splitMessage / MAX_MESSAGE_LENGTH
session-events.ts The AgentSession / CLI-tool event handler (logs, live snapshots, assistant-text events, tool progress, thread transcript, usage totals, compaction status) and the CLI tool-output handler
stream-fn.ts Provider stream boundary: option shaping, forced checkpoint tool call, Claude/Codex CLI routing, compact prompt, input budget, local prefill watch
handoff.ts handoff_context tool callback and the pressure-triggered handoff extension
private-checkpoint.ts Out-of-session private checkpoint call
compaction.ts Compaction timeout, status tracker with cancellation timer, AgentSession settings proxy, isCliHarnessProvider
context-transitions.ts Context transition persistence/publishing
presentation.ts Live event sink and assistant-text boundary / durable-ID claiming
prompt-message.ts User-turn assembly (timestamp, channel tag, attachments, ack fast path), user-visible error redaction
run-outcome.ts Final outcome delivery (redacted error, final text, yield, text-form checkpoint capture)
skills.ts, context-files.ts, event-format.ts Skills loading/cache, context archive/quarantine/truncate + host path translation, tool/event formatting helpers

Code moved verbatim except where closure state is now passed as explicit dependencies or getters (read at call time, as before). agent.ts re-exports DEFAULT_COMPACTION_TIMEOUT_MS, resolveCompactionTimeoutMs and CompactionStatus, so imports are unchanged.

Tests: source-shape assertions that read src/agent.ts now read agent.ts + src/runner/*.ts through test/support/runner-source.ts; the asserted patterns are unchanged.

Verified: pnpm run typecheck, pnpm run build, pnpm run check:public-safety, full pnpm test locally (same results as main; the remaining local failures are environment-specific and also fail on main), and the Tests workflow in CI.

🤖 Generated with Claude Code

Behavior-preserving refactor of src/agent.ts. createRunner kept the Pi
Agent/AgentSession wiring and the AgentRunner methods; self-contained pieces
move to src/runner/:

- run-state.ts: RunState type, per-run reset/clear, output queue, splitMessage
- session-events.ts: AgentSession/CLI tool event handling (logs, snapshots,
  tool progress, thread transcript, usage, compaction status)
- stream-fn.ts: provider stream boundary (option shaping, CLI routing,
  compact prompt, input budget, local prefill watch)
- handoff.ts: handoff_context tool callback and pressure extension
- private-checkpoint.ts: out-of-session checkpoint call
- compaction.ts: timeout, status tracker, settings proxy
- context-transitions.ts, presentation.ts, prompt-message.ts,
  run-outcome.ts, skills.ts, context-files.ts, event-format.ts

Code moved verbatim apart from passing closure state as explicit
dependencies or getters. Source-shape tests now read agent.ts plus
src/runner/*.ts via test/support/runner-source.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alosec
alosec merged commit 18565ad into main Nov 16, 2026
3 checks passed
@alosec
alosec deleted the riker/split-create-runner branch November 16, 2026 10:54
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.

1 participant