@nubl/maestro 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../maestro/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Harness-agnostic orchestration domain types.\n *\n * This module (and all of @ephemeralabs/maestro-core) must not import from\n * @ephemeralabs/maestro-adapters, @ephemeralabs/maestro-surfaces, @ephemeralabs/maestro-cli, or @ephemeralabs/maestro-tui.\n * See ARCHITECTURE.md. `check-deps` enforces it.\n */\nimport type { AcceptSpec, ChildAcceptReport } from \"./accept.ts\";\n\n/** Coarse agent lifecycle state, deliberately small: every harness adapter\n * must be able to project its own richer states onto these five. */\nexport type AgentState = \"idle\" | \"working\" | \"blocked\" | \"done\" | \"unknown\";\n\n// pi-herdr-agents extension\nexport type ThinkingLevel =\n\t| \"off\"\n\t| \"minimal\"\n\t| \"low\"\n\t| \"medium\"\n\t| \"high\"\n\t| \"xhigh\"\n\t| \"max\";\n\nexport interface WorktreeSpec {\n\t/** New branch to create for the isolated checkout. */\n\tbranch: string;\n\t/** Git ref the worktree starts from. Defaults to HEAD. */\n\tbase?: string;\n}\n\nexport interface Task {\n\tid: string;\n\tname: string;\n\t/** Full task text handed to the agent. */\n\tprompt: string;\n\t/** Role name, resolved through the role-pack loader. */\n\trole: string;\n\t/** Repository root the task runs against. */\n\tcwd: string;\n\t/** When set, the task runs inside an isolated git worktree. */\n\tworktree?: WorktreeSpec;\n\ttimeoutMs?: number;\n\t/** Validated accept check; the parent re-check decides the verdict. */\n\t// pi-herdr-agents extension\n\taccept?: AcceptSpec;\n\t/** The caller's raw model request, such as `task:<category>`, for the outcome ledger. */\n\t// pi-herdr-agents extension\n\trequestedModel?: string;\n\t/**\n\t * Extra environment for the agent process, keyed by variable name.\n\t * The CLI merges task-file `env` over `--env` flags (task wins); each\n\t * adapter decides how to deliver it (subprocess env, spool envelope,\n\t * surface command prefix). Core passes it through untouched.\n\t */\n\tenv?: Record<string, string>;\n\t// pi-herdr-agents extension\n\truntime?: {\n\t\tmodel: string;\n\t\tthinking: ThinkingLevel;\n\t\t/** Ordered candidates tried after a launch failure or a running child's\n\t\t * provider error; today's launchSubagentWithFallbacks (index.ts:2631). */\n\t\tfallbacks?: { model: string; thinking: ThinkingLevel }[];\n\t};\n\t// pi-herdr-agents extension\n\tsession?: {\n\t\tmode: \"standalone\" | \"lineage-only\" | \"fork\";\n\t\tparentSessionId?: string;\n\t};\n\t// pi-herdr-agents extension\n\tbehavior?: {\n\t\tpersistent?: boolean;\n\t\t/** A persistent specialist may wake the parent with notices (ADR-0019). */\n\t\tnotify?: boolean;\n\t\tautoExit?: boolean;\n\t\tinteractive?: boolean;\n\t\tsystemPromptMode?: \"replace\" | \"append\";\n\t\tskills?: string[];\n\t\tdenyTools?: string[];\n\t};\n\t/** Explicit tool allowlist; overrides Role.allowedTools when set. */\n\t// pi-herdr-agents extension\n\ttools?: string[];\n\t/** Explicit system prompt; overrides Role.systemPrompt when set. */\n\t// pi-herdr-agents extension\n\tsystemPrompt?: string;\n}\n\n/**\n * A versioned, installable role definition: name, version, description, the\n * full prompt body, and an optional harness-level tool allowlist.\n *\n * The contract is deliberately small: every field must be honored by at\n * least one adapter. Former fields `deniedTools`, `spawning`, `autoExit`,\n * and `systemPromptMode` were deleted because no harness in scope honors\n * them — an unhonored contract field is worse than no field.\n */\nexport interface Role {\n\tname: string;\n\tversion: string;\n\tdescription: string;\n\t/** Full role prompt body (markdown). */\n\tsystemPrompt: string;\n\t/** Harness-level tool allowlist. Empty means \"harness default\". */\n\tallowedTools: string[];\n\t// pi-herdr-agents extension\n\tdefaults?: {\n\t\tmodel?: string;\n\t\tthinking?: ThinkingLevel;\n\t\tsessionMode?: \"standalone\" | \"lineage-only\" | \"fork\";\n\t\tspawning?: boolean;\n\t\tselfSpawn?: boolean;\n\t\tautoExit?: boolean;\n\t\tinteractive?: boolean;\n\t\tpersistent?: boolean;\n\t\tsystemPromptMode?: \"replace\" | \"append\";\n\t\tdenyTools?: string[];\n\t\tskills?: string[];\n\t\tcwd?: string;\n\t};\n\t/** Where the definition came from: project, global, or role pack. */\n\t// pi-herdr-agents extension\n\tsource?: string;\n}\n\nexport type WorktreeState =\n\t| \"provisioning\"\n\t| \"provisioned\"\n\t| \"running\"\n\t| \"ready_for_review\"\n\t| \"failed\"\n\t| \"needs_help\"\n\t// pi-herdr-agents extension\n\t| \"cancelled\"\n\t| \"removed\";\n\nexport interface WorktreeOwnership {\n\t/** Run id that owns this worktree. */\n\tid: string;\n\towner: \"maestro\";\n\tbranch: string;\n\tbaseRef: string;\n\tbaseSha: string;\n\tcreatedAt: number;\n}\n\nexport interface Worktree extends WorktreeOwnership {\n\tpath: string;\n\tstate: WorktreeState;\n\tmanifestFile: string;\n}\n\n/**\n * Structural seam for \"run this agent's process inside a multiplexer pane\".\n * Defined in core so adapters can accept it without importing surfaces.\n * The surfaces package produces implementations; the CLI wires them together.\n */\nexport interface SurfaceHandle {\n\tid: string;\n\trunCommand(command: string): void | Promise<void>;\n\treadScreen(lines?: number): string | Promise<string>;\n\t/**\n\t * Send keystrokes to the surface by key name (e.g. \"C-c\", \"Enter\",\n\t * \"Escape\"). Harness adapters use this for interrupt semantics on\n\t * surface-hosted agents (Ctrl-C mid-turn). Optional: providers without a\n\t * key-sending primitive omit it, and the adapter throws a clear error.\n\t */\n\tsendKeys?(keys: string): void | Promise<void>;\n\t/**\n\t * Destroy the surface (close the pane/tab). Harness adapters use this for\n\t * kill semantics on surface-hosted agents. Optional for the same reason\n\t * as `sendKeys`: absent means the provider cannot tear down the surface.\n\t */\n\tclose?(): void | Promise<void>;\n}\n\nexport interface AgentHandle {\n\t/** A real acquired owner whose dispatch/rollback is uncertain; never retry. */\n\tlaunchFailure?: string;\n\tid: string;\n\tname: string;\n\trole: string;\n\t/** Adapter name that spawned this agent, e.g. \"pi\". */\n\tharness: string;\n\tcwd: string;\n\tstartedAt: number;\n\tsessionId: string;\n\t/** Set when the agent runs inside a multiplexer surface. */\n\tsurfaceId?: string;\n\t/** Direct-spawn bookkeeping (pid) when no surface is used. */\n\tpid?: number;\n\tworktree?: Worktree;\n}\n\n// pi-herdr-agents extension\nexport type RunOutcome = \"completed\" | \"failed\" | \"timeout\" | \"killed\" | \"help\";\n\n// pi-herdr-agents extension\nexport interface CompletionResult {\n\treason: \"done\" | \"ping\" | \"sentinel\" | \"error\";\n\texitCode: number;\n\tping?: { name: string; message: string };\n\terrorMessage?: string;\n\terrorSource?: \"child\" | \"host\";\n\t/** The child's own accept-check report; evidence only, never the verdict. */\n\taccept?: ChildAcceptReport;\n}\n\n// pi-herdr-agents extension\nexport interface WorktreeHandoff {\n\tpath: string;\n\tbranch: string;\n\tbaseRef: string;\n\tbaseSha: string;\n\tmanifestFile: string;\n\tsessionFile?: string;\n\tsourceSessionFile?: string;\n\thandoffMessage?: string;\n\theadSha: string | null;\n\tcommitsAhead: number | null;\n\tclean: boolean | null;\n\tconflicted: boolean | null;\n\tchangedFiles: string[] | null;\n\tuntrackedFiles: string[] | null;\n\tgitError?: string;\n}\n\n// pi-herdr-agents extension\nexport interface CompletionEvidence {\n\treason: \"done\" | \"ping\" | \"sentinel\" | \"error\";\n\t/** Required harness exit status from CompletionResult. */\n\t// pi-herdr-agents extension\n\texitCode: number;\n\tping?: { name: string; message: string };\n\terrorMessage?: string;\n\t/** Who wrote errorMessage: the child's sidecar, or a host diagnostic. */\n\terrorSource?: \"child\" | \"host\";\n\t/** The child's own accept-check report from its sidecar; evidence only. */\n\taccept?: ChildAcceptReport;\n\tfinalMessage?: { text: string; stopReason?: string; errorMessage?: string };\n\t/** Harness session reference; for Pi, the session file path. */\n\t// pi-herdr-agents extension\n\tsessionRef?: string;\n\tworktree?: WorktreeHandoff;\n}\n\nexport interface RunResult {\n\thandle: AgentHandle;\n\toutcome: RunOutcome;\n\texitCode?: number;\n\t/** Tail of captured output. */\n\toutput?: string;\n\terror?: string;\n\tdurationMs: number;\n\t// pi-herdr-agents extension\n\tevidence?: CompletionEvidence;\n\t/** Present only for operator cancellation; the outcome is then \"killed\". */\n\t// pi-herdr-agents extension\n\tcancellation?: RunCancellation;\n}\n\n/**\n * Operator cancellation provenance. A delivered cancellation is always\n * confirmed: unconfirmed termination keeps the run live instead of settling.\n */\n// pi-herdr-agents extension\nexport interface RunCancellation {\n\t/** When the terminal intent was recorded, before any abort or kill. */\n\trequestedAt: number;\n\t/** \"confirmed\" only after the owning adapter's kill resolved. */\n\ttermination: \"confirmed\" | \"unconfirmed\";\n\tconfirmedAt?: number;\n\t/** Last kill failure while termination remains unconfirmed. */\n\terror?: string;\n}\n\n// pi-herdr-agents extension\nexport type SurfaceAgentStatus =\n\t| \"idle\"\n\t| \"working\"\n\t| \"blocked\"\n\t| \"done\"\n\t| \"unknown\";\n\n// pi-herdr-agents extension\nexport type PaneInspection =\n\t| {\n\t\t\tkind: \"present\";\n\t\t\tagent?: string;\n\t\t\tagentStatus: SurfaceAgentStatus;\n\t\t\tobservedAt: number;\n\t }\n\t| { kind: \"missing\"; error?: string }\n\t| { kind: \"unavailable\"; error?: string };\n\n// pi-herdr-agents extension\nexport type ProcessState =\n\t| { kind: \"starting\"; startedAt: number }\n\t| { kind: \"running\"; startedAt: number; confirmedAt: number }\n\t| {\n\t\t\tkind: \"finalizing\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletion: CompletionResult;\n\t }\n\t| {\n\t\t\tkind: \"completed\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletedAt: number;\n\t\t\tcompletion: CompletionResult;\n\t }\n\t| {\n\t\t\tkind: \"failed\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletedAt: number;\n\t\t\terror: string;\n\t\t\texitCode?: number;\n\t };\n\n// pi-herdr-agents extension\nexport type SubagentActivityPhase = \"starting\" | \"active\" | \"waiting\" | \"done\";\n// pi-herdr-agents extension\nexport type SubagentActivityScope =\n\t| \"agent\"\n\t| \"turn\"\n\t| \"provider\"\n\t| \"streaming\"\n\t| \"tool\";\n\n// pi-herdr-agents extension\nexport type SubagentActivityEvent =\n\t| \"session_start\"\n\t| \"input\"\n\t| \"before_agent_start\"\n\t| \"agent_start\"\n\t| \"agent_end\"\n\t| \"turn_start\"\n\t| \"turn_end\"\n\t| \"before_provider_request\"\n\t| \"after_provider_response\"\n\t| \"message_update\"\n\t| \"tool_execution_start\"\n\t| \"tool_call\"\n\t| \"tool_execution_update\"\n\t| \"tool_result\"\n\t| \"tool_execution_end\"\n\t| \"caller_ping\"\n\t| \"subagent_done\"\n\t| \"session_shutdown\";\n\n// pi-herdr-agents extension\nexport interface SubagentActivityState {\n\tversion: 1;\n\trunningChildId: string;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\tsequence: number;\n\tlatestEvent: SubagentActivityEvent;\n\tphase: SubagentActivityPhase;\n\tagentActive: boolean;\n\tturnActive: boolean;\n\tproviderActive: boolean;\n\ttoolActive: boolean;\n\tactiveScope?: SubagentActivityScope;\n\tactiveSince?: number;\n\twaitingSince?: number;\n\tturnIndex?: number;\n\tmessageEventType?: string;\n\ttoolCallId?: string;\n\ttoolName?: string;\n\ttoolStartedAt?: number;\n\ttoolEndedAt?: number;\n}\n\n// pi-herdr-agents extension\nexport type ActivityReadResult =\n\t| { ok: true; activity: SubagentActivityState }\n\t| { ok: false; reason: \"missing\" | \"invalid\" | \"wrong-id\"; error?: string };\n\n// pi-herdr-agents extension\nexport type ActivityDetail =\n\t| { kind: \"none\"; observedAt: number }\n\t| {\n\t\t\tkind: \"scope\";\n\t\t\tscope: SubagentActivityScope;\n\t\t\tlabel?: string;\n\t\t\tsince: number;\n\t\t\tobservedAt: number;\n\t\t\tsequence: number;\n\t };\n\n// pi-herdr-agents extension\nexport type TurnState =\n\t| { kind: \"unknown\" }\n\t| { kind: \"starting\"; observedAt: number }\n\t| {\n\t\t\tkind: \"active\";\n\t\t\tstartedAt: number;\n\t\t\tsource: \"activity\" | \"herdr\" | \"fallback\";\n\t\t\tactivity?: ActivityDetail;\n\t }\n\t| { kind: \"blocked\"; startedAt: number }\n\t| { kind: \"waiting\"; startedAt: number }\n\t| {\n\t\t\tkind: \"interrupted\";\n\t\t\trequestedAt: number;\n\t\t\tpreviousActivitySequence: number | null;\n\t };\n\n// pi-herdr-agents extension\nexport type ActivityHealth =\n\t| { kind: \"unseen\" }\n\t| { kind: \"healthy\"; observedAt: number }\n\t| {\n\t\t\tkind: \"problem\";\n\t\t\treason: \"missing\" | \"invalid\" | \"wrong-id\";\n\t\t\tsince: number;\n\t\t\terror?: string;\n\t };\n\n// pi-herdr-agents extension\nexport type PaneObservation =\n\t| { kind: \"unknown\" }\n\t| { kind: \"present\"; observedAt: number; agentStatus: SurfaceAgentStatus }\n\t| {\n\t\t\tkind: \"read-error\";\n\t\t\tfirstFailedAt: number;\n\t\t\tlastFailedAt: number;\n\t\t\tconsecutiveFailures: number;\n\t\t\terror?: string;\n\t }\n\t| { kind: \"missing\"; detectedAt: number; error?: string };\n\n// pi-herdr-agents extension\nexport type CompletionDelivery = \"pending\" | \"delivered\" | \"suppressed\";\n\n// pi-herdr-agents extension\nexport interface SubagentLifecycle {\n\tprocess: ProcessState;\n\tturn: TurnState;\n\tactivityHealth: ActivityHealth;\n\t/** Latest optional Pi detail, independent of Herdr coarse turn state. */\n\tactivityDetail: ActivityDetail | null;\n\tpane: PaneObservation;\n\t/** Durable across unavailable/missing observations. */\n\thasWorked: boolean;\n\tlastActivitySequence: number | null;\n\tdelivery: CompletionDelivery;\n}\n\n// pi-herdr-agents extension\nexport interface LifecycleProjection {\n\tkind:\n\t\t| \"starting\"\n\t\t| \"running\"\n\t\t| \"active\"\n\t\t| \"blocked\"\n\t\t| \"waiting\"\n\t\t| \"interrupted\"\n\t\t| \"stalled\"\n\t\t| \"finalizing\"\n\t\t| \"completed\"\n\t\t| \"failed\";\n\tlabel?: string;\n\truntimeEndedAt?: number;\n\tstateDurationSince?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../maestro/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Harness-agnostic orchestration domain types.\n *\n * This module (and all of @ephemeralabs/maestro-core) must not import from\n * @ephemeralabs/maestro-adapters, @ephemeralabs/maestro-surfaces, @ephemeralabs/maestro-cli, or @ephemeralabs/maestro-tui.\n * See ARCHITECTURE.md. `check-deps` enforces it.\n */\nimport type { AcceptSpec, ChildAcceptReport } from \"./accept.ts\";\n\n/** Coarse agent lifecycle state, deliberately small: every harness adapter\n * must be able to project its own richer states onto these five. */\nexport type AgentState = \"idle\" | \"working\" | \"blocked\" | \"done\" | \"unknown\";\n\n// pi-herdr-agents extension\nexport type ThinkingLevel =\n\t| \"off\"\n\t| \"minimal\"\n\t| \"low\"\n\t| \"medium\"\n\t| \"high\"\n\t| \"xhigh\"\n\t| \"max\";\n\nexport interface WorktreeSpec {\n\t/** New branch to create for the isolated checkout. */\n\tbranch: string;\n\t/** Git ref the worktree starts from. Defaults to HEAD. */\n\tbase?: string;\n}\n\nexport interface Task {\n\tid: string;\n\tname: string;\n\t/** Full task text handed to the agent. */\n\tprompt: string;\n\t/** Role name, resolved through the role-pack loader. */\n\trole: string;\n\t/** Repository root the task runs against. */\n\tcwd: string;\n\t/** When set, the task runs inside an isolated git worktree. */\n\tworktree?: WorktreeSpec;\n\ttimeoutMs?: number;\n\t/** Validated accept check; the parent re-check decides the verdict. */\n\t// pi-herdr-agents extension\n\taccept?: AcceptSpec;\n\t/** The caller's raw model request, such as `task:<category>`, for the outcome ledger. */\n\t// pi-herdr-agents extension\n\trequestedModel?: string;\n\t/**\n\t * Extra environment for the agent process, keyed by variable name.\n\t * The CLI merges task-file `env` over `--env` flags (task wins); each\n\t * adapter decides how to deliver it (subprocess env, spool envelope,\n\t * surface command prefix). Core passes it through untouched.\n\t */\n\tenv?: Record<string, string>;\n\t// pi-herdr-agents extension\n\truntime?: {\n\t\tmodel: string;\n\t\tthinking: ThinkingLevel;\n\t\t/** Ordered candidates tried after a launch failure or a running child's\n\t\t * provider error; today's launchSubagentWithFallbacks (index.ts:2631). */\n\t\tfallbacks?: { model: string; thinking: ThinkingLevel }[];\n\t};\n\t// pi-herdr-agents extension\n\tsession?: {\n\t\tmode: \"standalone\" | \"lineage-only\" | \"fork\";\n\t\tparentSessionId?: string;\n\t};\n\t// pi-herdr-agents extension\n\tbehavior?: {\n\t\tpersistent?: boolean;\n\t\t/** A persistent specialist may wake the parent with notices (ADR-0019). */\n\t\tnotify?: boolean;\n\t\tautoExit?: boolean;\n\t\tinteractive?: boolean;\n\t\tsystemPromptMode?: \"replace\" | \"append\";\n\t\tskills?: string[];\n\t\tdenyTools?: string[];\n\t};\n\t/** Explicit tool allowlist; overrides Role.allowedTools when set. */\n\t// pi-herdr-agents extension\n\ttools?: string[];\n\t/** Explicit system prompt; overrides Role.systemPrompt when set. */\n\t// pi-herdr-agents extension\n\tsystemPrompt?: string;\n}\n\n/**\n * A versioned, installable role definition: name, version, description, the\n * full prompt body, and an optional harness-level tool allowlist.\n *\n * The contract is deliberately small: every field must be honored by at\n * least one adapter. Former fields `deniedTools`, `spawning`, `autoExit`,\n * and `systemPromptMode` were deleted because no harness in scope honors\n * them — an unhonored contract field is worse than no field.\n */\nexport interface Role {\n\tname: string;\n\tversion: string;\n\tdescription: string;\n\t/** Full role prompt body (markdown). */\n\tsystemPrompt: string;\n\t/** Harness-level tool allowlist. Empty means \"harness default\". */\n\tallowedTools: string[];\n\t// pi-herdr-agents extension\n\tdefaults?: {\n\t\tmodel?: string;\n\t\tthinking?: ThinkingLevel;\n\t\tsessionMode?: \"standalone\" | \"lineage-only\" | \"fork\";\n\t\tspawning?: boolean;\n\t\tselfSpawn?: boolean;\n\t\tautoExit?: boolean;\n\t\tinteractive?: boolean;\n\t\tpersistent?: boolean;\n\t\tsystemPromptMode?: \"replace\" | \"append\";\n\t\tdenyTools?: string[];\n\t\tskills?: string[];\n\t\tcwd?: string;\n\t};\n\t/** Where the definition came from: project, global, or role pack. */\n\t// pi-herdr-agents extension\n\tsource?: string;\n}\n\nexport type WorktreeState =\n\t| \"provisioning\"\n\t| \"provisioned\"\n\t| \"running\"\n\t| \"ready_for_review\"\n\t| \"failed\"\n\t| \"needs_help\"\n\t// pi-herdr-agents extension\n\t| \"cancelled\"\n\t| \"removed\";\n\nexport interface WorktreeOwnership {\n\t/** Run id that owns this worktree. */\n\tid: string;\n\towner: \"maestro\";\n\tbranch: string;\n\tbaseRef: string;\n\tbaseSha: string;\n\tcreatedAt: number;\n}\n\nexport interface Worktree extends WorktreeOwnership {\n\tpath: string;\n\tstate: WorktreeState;\n\tmanifestFile: string;\n}\n\n/**\n * Structural seam for \"run this agent's process inside a multiplexer pane\".\n * Defined in core so adapters can accept it without importing surfaces.\n * The surfaces package produces implementations; the CLI wires them together.\n */\nexport interface SurfaceHandle {\n\tid: string;\n\trunCommand(command: string): void | Promise<void>;\n\treadScreen(lines?: number): string | Promise<string>;\n\t/**\n\t * Send keystrokes to the surface by key name (e.g. \"C-c\", \"Enter\",\n\t * \"Escape\"). Harness adapters use this for interrupt semantics on\n\t * surface-hosted agents (Ctrl-C mid-turn). Optional: providers without a\n\t * key-sending primitive omit it, and the adapter throws a clear error.\n\t */\n\tsendKeys?(keys: string): void | Promise<void>;\n\t/**\n\t * Destroy the surface (close the pane/tab). Harness adapters use this for\n\t * kill semantics on surface-hosted agents. Optional for the same reason\n\t * as `sendKeys`: absent means the provider cannot tear down the surface.\n\t */\n\tclose?(): void | Promise<void>;\n}\n\nexport interface AgentHandle {\n\t/** A real acquired owner whose dispatch/rollback is uncertain; never retry. */\n\tlaunchFailure?: string;\n\tid: string;\n\tname: string;\n\trole: string;\n\t/** Adapter name that spawned this agent, e.g. \"pi\". */\n\tharness: string;\n\tcwd: string;\n\tstartedAt: number;\n\tsessionId: string;\n\t/** Set when the agent runs inside a multiplexer surface. */\n\tsurfaceId?: string;\n\t/** Direct-spawn bookkeeping (pid) when no surface is used. */\n\tpid?: number;\n\tworktree?: Worktree;\n}\n\n// pi-herdr-agents extension\nexport type RunOutcome = \"completed\" | \"failed\" | \"timeout\" | \"killed\" | \"help\";\n\n// pi-herdr-agents extension\nexport interface CompletionResult {\n\treason: \"done\" | \"ping\" | \"sentinel\" | \"error\";\n\texitCode: number;\n\tping?: { name: string; message: string };\n\terrorMessage?: string;\n\terrorSource?: \"child\" | \"host\";\n\t/** The child's own accept-check report; evidence only, never the verdict. */\n\taccept?: ChildAcceptReport;\n}\n\n// pi-herdr-agents extension\nexport interface WorktreeHandoff {\n\tpath: string;\n\tbranch: string;\n\tbaseRef: string;\n\tbaseSha: string;\n\tmanifestFile: string;\n\tsessionFile?: string;\n\tsourceSessionFile?: string;\n\thandoffMessage?: string;\n\theadSha: string | null;\n\tcommitsAhead: number | null;\n\tclean: boolean | null;\n\tconflicted: boolean | null;\n\tchangedFiles: string[] | null;\n\tuntrackedFiles: string[] | null;\n\tgitError?: string;\n}\n\n// pi-herdr-agents extension\nexport interface CompletionEvidence {\n\treason: \"done\" | \"ping\" | \"sentinel\" | \"error\";\n\t/** Required harness exit status from CompletionResult. */\n\t// pi-herdr-agents extension\n\texitCode: number;\n\tping?: { name: string; message: string };\n\terrorMessage?: string;\n\t/** Who wrote errorMessage: the child's sidecar, or a host diagnostic. */\n\terrorSource?: \"child\" | \"host\";\n\t/** The child's own accept-check report from its sidecar; evidence only. */\n\taccept?: ChildAcceptReport;\n\tfinalMessage?: { text: string; stopReason?: string; errorMessage?: string };\n\t/**\n\t * The last lines a child printed when it failed before its session started:\n\t * bounded and redacted by the host, never instructions.\n\t */\n\texitOutput?: string;\n\t/** Harness session reference; for Pi, the session file path. */\n\t// pi-herdr-agents extension\n\tsessionRef?: string;\n\tworktree?: WorktreeHandoff;\n}\n\nexport interface RunResult {\n\thandle: AgentHandle;\n\toutcome: RunOutcome;\n\texitCode?: number;\n\t/** Tail of captured output. */\n\toutput?: string;\n\terror?: string;\n\tdurationMs: number;\n\t// pi-herdr-agents extension\n\tevidence?: CompletionEvidence;\n\t/** Present only for operator cancellation; the outcome is then \"killed\". */\n\t// pi-herdr-agents extension\n\tcancellation?: RunCancellation;\n}\n\n/**\n * Operator cancellation provenance. A delivered cancellation is always\n * confirmed: unconfirmed termination keeps the run live instead of settling.\n */\n// pi-herdr-agents extension\nexport interface RunCancellation {\n\t/** When the terminal intent was recorded, before any abort or kill. */\n\trequestedAt: number;\n\t/** \"confirmed\" only after the owning adapter's kill resolved. */\n\ttermination: \"confirmed\" | \"unconfirmed\";\n\tconfirmedAt?: number;\n\t/** Last kill failure while termination remains unconfirmed. */\n\terror?: string;\n}\n\n// pi-herdr-agents extension\nexport type SurfaceAgentStatus =\n\t| \"idle\"\n\t| \"working\"\n\t| \"blocked\"\n\t| \"done\"\n\t| \"unknown\";\n\n// pi-herdr-agents extension\nexport type PaneInspection =\n\t| {\n\t\t\tkind: \"present\";\n\t\t\tagent?: string;\n\t\t\tagentStatus: SurfaceAgentStatus;\n\t\t\tobservedAt: number;\n\t }\n\t| { kind: \"missing\"; error?: string }\n\t| { kind: \"unavailable\"; error?: string };\n\n// pi-herdr-agents extension\nexport type ProcessState =\n\t| { kind: \"starting\"; startedAt: number }\n\t| { kind: \"running\"; startedAt: number; confirmedAt: number }\n\t| {\n\t\t\tkind: \"finalizing\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletion: CompletionResult;\n\t }\n\t| {\n\t\t\tkind: \"completed\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletedAt: number;\n\t\t\tcompletion: CompletionResult;\n\t }\n\t| {\n\t\t\tkind: \"failed\";\n\t\t\tstartedAt: number;\n\t\t\tdetectedAt: number;\n\t\t\tcompletedAt: number;\n\t\t\terror: string;\n\t\t\texitCode?: number;\n\t };\n\n// pi-herdr-agents extension\nexport type SubagentActivityPhase = \"starting\" | \"active\" | \"waiting\" | \"done\";\n// pi-herdr-agents extension\nexport type SubagentActivityScope =\n\t| \"agent\"\n\t| \"turn\"\n\t| \"provider\"\n\t| \"streaming\"\n\t| \"tool\";\n\n// pi-herdr-agents extension\nexport type SubagentActivityEvent =\n\t| \"session_start\"\n\t| \"input\"\n\t| \"before_agent_start\"\n\t| \"agent_start\"\n\t| \"agent_end\"\n\t| \"turn_start\"\n\t| \"turn_end\"\n\t| \"before_provider_request\"\n\t| \"after_provider_response\"\n\t| \"message_update\"\n\t| \"tool_execution_start\"\n\t| \"tool_call\"\n\t| \"tool_execution_update\"\n\t| \"tool_result\"\n\t| \"tool_execution_end\"\n\t| \"caller_ping\"\n\t| \"subagent_done\"\n\t| \"session_shutdown\";\n\n// pi-herdr-agents extension\nexport interface SubagentActivityState {\n\tversion: 1;\n\trunningChildId: string;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\tsequence: number;\n\tlatestEvent: SubagentActivityEvent;\n\tphase: SubagentActivityPhase;\n\tagentActive: boolean;\n\tturnActive: boolean;\n\tproviderActive: boolean;\n\ttoolActive: boolean;\n\tactiveScope?: SubagentActivityScope;\n\tactiveSince?: number;\n\twaitingSince?: number;\n\tturnIndex?: number;\n\tmessageEventType?: string;\n\ttoolCallId?: string;\n\ttoolName?: string;\n\ttoolStartedAt?: number;\n\ttoolEndedAt?: number;\n}\n\n// pi-herdr-agents extension\nexport type ActivityReadResult =\n\t| { ok: true; activity: SubagentActivityState }\n\t| { ok: false; reason: \"missing\" | \"invalid\" | \"wrong-id\"; error?: string };\n\n// pi-herdr-agents extension\nexport type ActivityDetail =\n\t| { kind: \"none\"; observedAt: number }\n\t| {\n\t\t\tkind: \"scope\";\n\t\t\tscope: SubagentActivityScope;\n\t\t\tlabel?: string;\n\t\t\tsince: number;\n\t\t\tobservedAt: number;\n\t\t\tsequence: number;\n\t };\n\n// pi-herdr-agents extension\nexport type TurnState =\n\t| { kind: \"unknown\" }\n\t| { kind: \"starting\"; observedAt: number }\n\t| {\n\t\t\tkind: \"active\";\n\t\t\tstartedAt: number;\n\t\t\tsource: \"activity\" | \"herdr\" | \"fallback\";\n\t\t\tactivity?: ActivityDetail;\n\t }\n\t| { kind: \"blocked\"; startedAt: number }\n\t| { kind: \"waiting\"; startedAt: number }\n\t| {\n\t\t\tkind: \"interrupted\";\n\t\t\trequestedAt: number;\n\t\t\tpreviousActivitySequence: number | null;\n\t };\n\n// pi-herdr-agents extension\nexport type ActivityHealth =\n\t| { kind: \"unseen\" }\n\t| { kind: \"healthy\"; observedAt: number }\n\t| {\n\t\t\tkind: \"problem\";\n\t\t\treason: \"missing\" | \"invalid\" | \"wrong-id\";\n\t\t\tsince: number;\n\t\t\terror?: string;\n\t };\n\n// pi-herdr-agents extension\nexport type PaneObservation =\n\t| { kind: \"unknown\" }\n\t| { kind: \"present\"; observedAt: number; agentStatus: SurfaceAgentStatus }\n\t| {\n\t\t\tkind: \"read-error\";\n\t\t\tfirstFailedAt: number;\n\t\t\tlastFailedAt: number;\n\t\t\tconsecutiveFailures: number;\n\t\t\terror?: string;\n\t }\n\t| { kind: \"missing\"; detectedAt: number; error?: string };\n\n// pi-herdr-agents extension\nexport type CompletionDelivery = \"pending\" | \"delivered\" | \"suppressed\";\n\n// pi-herdr-agents extension\nexport interface SubagentLifecycle {\n\tprocess: ProcessState;\n\tturn: TurnState;\n\tactivityHealth: ActivityHealth;\n\t/** Latest optional Pi detail, independent of Herdr coarse turn state. */\n\tactivityDetail: ActivityDetail | null;\n\tpane: PaneObservation;\n\t/** Durable across unavailable/missing observations. */\n\thasWorked: boolean;\n\tlastActivitySequence: number | null;\n\tdelivery: CompletionDelivery;\n}\n\n// pi-herdr-agents extension\nexport interface LifecycleProjection {\n\tkind:\n\t\t| \"starting\"\n\t\t| \"running\"\n\t\t| \"active\"\n\t\t| \"blocked\"\n\t\t| \"waiting\"\n\t\t| \"interrupted\"\n\t\t| \"stalled\"\n\t\t| \"finalizing\"\n\t\t| \"completed\"\n\t\t| \"failed\";\n\tlabel?: string;\n\truntimeEndedAt?: number;\n\tstateDurationSince?: number;\n}\n"]}
@@ -478,7 +478,7 @@ export function createDefaultRunSession(options, previous) {
478
478
  ? cursor === undefined
479
479
  ? "Sub-agent exited without output"
480
480
  : "Resumed session exited without new output"
481
- : `${cursor === undefined ? "Sub-agent" : "Resumed session"} exited with code ${exitCode}`,
481
+ : `${cursor === undefined ? "Sub-agent" : "Resumed session"} exited with code ${exitCode}${evidence.exitOutput ? ` before its session started. Last output:\n${evidence.exitOutput}` : ""}`,
482
482
  // Only a child-written sidecar error is child provenance.
483
483
  summarySource: evidence.errorMessage
484
484
  ? errorProvenance(evidence.errorSource)
@@ -1 +1 @@
1
- {"version":3,"file":"pi-run-session.js","sourceRoot":"","sources":["../../../maestro/runtime/pi-run-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EACN,2BAA2B,GAE3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACN,wBAAwB,EACxB,+BAA+B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,mBAAmB,GAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,aAAa,EACb,wBAAwB,EACxB,0BAA0B,EAC1B,4BAA4B,GAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACN,sBAAsB,GAEtB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,iC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C,MAAM,CAAC;gBACR,iBAAiB;YAClB,CAAC;YACD,OAAO,EAAE,GAAG,4BAA4B,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;QACtE,CAAC;QACD,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,EAAE;QACjE,KAAK,CAAC,QAAQ,CAAC,MAAM;YACpB,IAAI,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;gBACjE,KAAK,MAAM,EAAE,IAAI,IAAI,GAAG,CAAC;oBACxB,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE;oBACvB,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;iBAC1C,CAAC;oBACD,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACrB,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;gBACzC,oEAAoE;gBACpE,MAAM,qBAAqB,CAAC,YAAY,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;KACD,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport type { SpawnOptions } from \"../core/harness-adapter.ts\";\nimport type {\n\tAgentHandle,\n\tTask,\n\tRole,\n\tSubagentLifecycle,\n\tActivityReadResult,\n\tCompletionEvidence,\n} from \"../core/types.ts\";\nimport type { SurfaceProvider } from \"../core/surface-provider.ts\";\nimport { PiHarnessAdapter } from \"../adapters/pi/pi-harness-adapter.ts\";\nimport {\n\tlaunchOperationsFromSurface,\n\ttype PiLaunchOperations,\n} from \"../adapters/pi/launch-operations.ts\";\nimport { launchPiWorktreeHandoff } from \"../adapters/pi/launch.ts\";\nimport {\n\tcreateWorktreeOperations,\n\tcreateWorktreeCleanupOperations,\n} from \"./worktree-operations.ts\";\nimport {\n\tworktreeResultState,\n\ttype WorktreeOperations,\n} from \"../core/worktree.ts\";\nimport {\n\tgetNewEntries,\n\tfindLastAssistantSummary,\n\tfindObservedSessionRuntime,\n\tinspectNoProgressSessionTail,\n\ttype AttributedSummary,\n} from \"../adapters/pi/session.ts\";\nimport {\n\tassertManagedWorktreesSupported,\n\tmanagedWorktreeRefusal,\n} from \"../core/platform-support.ts\";\nimport {\n\tassertSameHerdrBinding,\n\ttype HerdrBinding,\n} from \"../core/config/herdr-config.ts\";\nimport { createPiScriptShellResolver } from \"../adapters/pi/script-shell.ts\";\nimport { readSubagentActivityFile } from \"../adapters/pi/activity-file.ts\";\nimport { projectActivity } from \"../core/activity.ts\";\nimport {\n\tmarkCompletionDetected,\n\tmarkCompleted,\n\tmarkFailed,\n\tmarkDelivery,\n\tobserveActivity,\n\tprojectLifecycle,\n} from \"../core/lifecycle.ts\";\nimport { FileWakeRegistry } from \"../core/wake.ts\";\nimport { SupervisionCoordinator } from \"../core/supervision.ts\";\nimport {\n\tassertModelInScope,\n\tisThinkingLevel,\n\tresolveRuntimePlan,\n\tresolveRuntimePlans,\n\ttype ResolvedRuntimePlan,\n} from \"../core/routing.ts\";\nimport { loadPaneConfig } from \"../core/config/pane-config.ts\";\nimport { DelegatedMarkers, type DelegatedMarker } from \"./delegated-marker.ts\";\nimport {\n\tcreateRunSession,\n\ttype RunSession,\n\ttype RunObservation,\n\ttype OwnedRunAttempt,\n\ttype PreparedRun,\n} from \"./run-session.ts\";\nimport { createPiPersistentIO } from \"./pi-persistent-io.ts\";\nimport {\n\tappendOutcomeLedger,\n\tledgerOutcome,\n\toutcomeLedgerFile,\n\trunParentAcceptCheck,\n} from \"./accept-recheck.ts\";\nimport { runAcceptCommand } from \"../adapters/pi/accept-runner.ts\";\nimport {\n\tterminateAcceptChecks,\n\ttype AcceptCheckOwner,\n} from \"../adapters/pi/accept-groups.ts\";\nimport type {\n\tDefaultRunSessionOptions,\n\tPiCompletedMetadata,\n\tPiLaunchInput,\n\tPiLaunchSnapshot,\n\tPiResumeInput,\n\tPiRunRecord,\n\tPiRunSession,\n\tPiRunSessionInfrastructure,\n\tPiSettlementIO,\n\tPiStartedMetadata,\n\tPiWorktreeHandoff,\n} from \"./pi-run-session-types.ts\";\n\n// pi-herdr-agents extension; no owning session required\nexport function observePiActivity(\n\tinput: { id: string; activityFile?: string; lifecycle: SubagentLifecycle },\n\tobservedAt: number,\n): RunObservation & { activityRead: ActivityReadResult } {\n\tconst read = input.activityFile\n\t\t? readSubagentActivityFile(input.activityFile, input.id)\n\t\t: projectActivity(undefined);\n\tconst lifecycle = observeActivity(input.lifecycle, read, observedAt);\n\treturn {\n\t\tkind: \"refresh\",\n\t\tobservedAt,\n\t\tlifecycle,\n\t\tprojection: projectLifecycle(lifecycle, observedAt),\n\t\tactivity: read.ok ? read.activity : undefined,\n\t\tactivityRead: read,\n\t};\n}\n\n// pi-herdr-agents extension\ninterface PiEntry {\n\trecord: PiRunRecord;\n\tstarted: PiStartedMetadata;\n\tcompleted?: PiCompletedMetadata;\n\treadResumeResult?: PiSettlementIO[\"readResumeResult\"];\n\tmarker?: DelegatedMarker;\n}\n// The previous facade carries its live composition explicitly across module replacement.\n// No module-local lookup can accidentally rediscover an owner.\nconst OWNER = Symbol.for(\"pi-herdr-agents/PiRunSession-owner\");\n// pi-herdr-agents extension\ninterface PiSessionOwner {\n\tbinding: HerdrBinding;\n\toptions: DefaultRunSessionOptions;\n\troles: Role[];\n\t// Only acquisitions currently in flight; control reservation is kernel-owned.\n\tpending: Set<{ taskId: string; suppressed: boolean }>;\n\tresumePi(input: PiResumeInput): Promise<AgentHandle>;\n\tkernel: RunSession;\n\tentries: Map<string, PiEntry>;\n\tinfrastructure: Pick<\n\t\tPiRunSessionInfrastructure,\n\t\t\"surfaceProvider\" | \"supervision\" | \"processProbe\" | \"acceptRunner\"\n\t>;\n\tworktreeOperations: WorktreeOperations;\n\t/** Absent outside Herdr: without a socket nothing can be marked. */\n\tmarkers?: DelegatedMarkers;\n\t/** Owns this composition's parent re-checks; a quit terminates them. */\n\tacceptChecks?: AcceptCheckOwner;\n}\n\n// A detached close can outlive settlement without capturing a child, metadata,\n// adapter, current hook binding or the composition registry.\nfunction temporarySurfaceRelease(\n\tprovider: SurfaceProvider,\n\tsurface: string,\n): () => Promise<void> {\n\treturn async () => {\n\t\t// Suppression may release before a watcher observes native exit. Like a\n\t\t// legacy pane close, stop the owned program, but remove its record only\n\t\t// after independent exit confirmation and delivery/suppression gating.\n\t\tawait provider.nativeExecution?.terminate(surface);\n\t\tawait provider.closeSurface(surface);\n\t};\n}\n\nfunction createDelegatedMarkers(\n\toptions: DefaultRunSessionOptions,\n): DelegatedMarkers | undefined {\n\tconst transport = options.infrastructure\n\t\t? {\n\t\t\t\twrite: options.infrastructure.markerWriter,\n\t\t\t\treadSession: options.infrastructure.markerSessionReader,\n\t\t\t}\n\t\t: options.hostSurface!.markers?.();\n\treturn transport?.write && transport.readSession\n\t\t? new DelegatedMarkers({\n\t\t\t\twrite: transport.write,\n\t\t\t\treadSession: transport.readSession,\n\t\t\t})\n\t\t: undefined;\n}\n\n/** Host diagnostics stay host; only text the child wrote is child-error. */\nfunction errorProvenance(\n\tsource: CompletionEvidence[\"errorSource\"],\n): \"child-error\" | \"host\" {\n\treturn source === \"child\" ? \"child-error\" : \"host\";\n}\n\n// Capture only resume presentation scalars, not the child or its owning registry.\nfunction resumeResultReader(\n\tsessionFile: string,\n\tcursor: number,\n\texitCode: number,\n\terrorMessage: string | undefined,\n\terrorSource: CompletionEvidence[\"errorSource\"],\n): NonNullable<PiSettlementIO[\"readResumeResult\"]> {\n\treturn () => ({\n\t\t...(findLastAssistantSummary(getNewEntries(sessionFile, cursor)) ?? {\n\t\t\tsummary: errorMessage\n\t\t\t\t? `Subagent error: ${errorMessage}`\n\t\t\t\t: exitCode === 0\n\t\t\t\t\t? \"Resumed session exited without new output\"\n\t\t\t\t\t: `Resumed session exited with code ${exitCode}`,\n\t\t\tsummarySource: errorProvenance(errorSource),\n\t\t}),\n\t\tsessionFile,\n\t});\n}\n\n// pi-herdr-agents extension\nexport function createDefaultRunSession(\n\toptions: DefaultRunSessionOptions,\n\tprevious?: PiRunSession,\n): PiRunSession {\n\t// SAFETY: this factory alone attaches its private symbol owner to Pi facades.\n\tconst adopted =\n\t\tprevious &&\n\t\t(previous as PiRunSession & { [OWNER]?: PiSessionOwner })[OWNER];\n\tif (previous && !adopted)\n\t\tthrow new Error(\n\t\t\t\"Previous PiRunSession does not carry its owning composition.\",\n\t\t);\n\tif (\n\t\toptions.infrastructure &&\n\t\toptions.infrastructure.launchOperations.nativeExecution !==\n\t\t\toptions.infrastructure.surfaceProvider.nativeExecution\n\t)\n\t\tthrow new Error(\n\t\t\t\"Pi owning provider and launch operations must use the same native execution binding\",\n\t\t);\n\tif (!options.infrastructure && !options.hostSurface)\n\t\tthrow new Error(\"Pi run session requires a host surface binding\");\n\t// Injected infrastructure is a closed world: never inspect ambient Core sockets.\n\tconst binding: HerdrBinding = options.infrastructure\n\t\t? { backend: \"legacy\" }\n\t\t: options.hostSurface!.resolve(\n\t\t\t\toptions.configDir,\n\t\t\t\toptions.configExamplePath,\n\t\t\t\toptions.platform,\n\t\t\t);\n\tif (adopted) {\n\t\tassertSameHerdrBinding(adopted.binding, binding);\n\t\tconst previousNative =\n\t\t\tadopted.infrastructure.surfaceProvider.nativeExecution;\n\t\tconst nextNative = options.infrastructure?.surfaceProvider.nativeExecution;\n\t\tif (options.infrastructure && previousNative !== nextNative)\n\t\t\tthrow new Error(\"Injected native execution binding changed; restart Pi\");\n\t}\n\tlet state: PiSessionOwner;\n\tlet resumePi: (input: PiResumeInput) => Promise<AgentHandle>;\n\tif (adopted) {\n\t\tstate = adopted;\n\t\tconst supervision = state.infrastructure.supervision;\n\t\tif (supervision.setForcePolling) {\n\t\t\tsupervision.setForcePolling(options.forcePolling);\n\t\t} else if (\n\t\t\t(supervision.diagnostics().mode === \"polling(forced)\") !==\n\t\t\toptions.forcePolling\n\t\t) {\n\t\t\t// An owner created before live reconfiguration cannot transfer its\n\t\t\t// registrations safely. Never silently replace it or ignore config.\n\t\t\tthrow new Error(\n\t\t\t\t\"Cannot change supervision.forcePolling on a pre-upgrade coordinator. Let active children finish, then restart Pi to apply it.\",\n\t\t\t);\n\t\t}\n\t\tstate.options = options;\n\t\tstate.roles.splice(0, state.roles.length, ...options.roles);\n\t} else {\n\t\t// Configured placement belongs to each new launch; the coordinator alone owns\n\t\t// this explicitly injected registry. Injected infrastructure already owns one.\n\t\tconst provider =\n\t\t\toptions.infrastructure?.surfaceProvider ??\n\t\t\toptions.hostSurface!.createProvider(\n\t\t\t\tbinding,\n\t\t\t\tloadPaneConfig(\n\t\t\t\t\tjoin(options.configDir, \"herdr-agents\"),\n\t\t\t\t\toptions.configExamplePath,\n\t\t\t\t),\n\t\t\t\t// No launch context here, so project settings are untrusted.\n\t\t\t\tcreatePiScriptShellResolver({\n\t\t\t\t\tcwd: process.cwd(),\n\t\t\t\t\tprojectTrusted: false,\n\t\t\t\t}),\n\t\t\t);\n\t\tconst wake = options.infrastructure ? undefined : new FileWakeRegistry();\n\t\tconst supervision =\n\t\t\toptions.infrastructure?.supervision ??\n\t\t\tnew SupervisionCoordinator(\n\t\t\t\tasync () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcomplete: true,\n\t\t\t\t\t\t\tpanes: (await provider.listSurfaces()).map((s) => ({\n\t\t\t\t\t\t\t\tpaneId: s.id,\n\t\t\t\t\t\t\t\tworkspaceId: s.workspaceId ?? \"\",\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn { complete: false, panes: [] };\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(id) => provider.inspectSurface(id),\n\t\t\t\toptions.forcePolling,\n\t\t\t\twake,\n\t\t\t);\n\t\tconst infrastructure = options.infrastructure ?? {\n\t\t\tsurfaceProvider: provider,\n\t\t\tsupervision,\n\t\t};\n\t\tconst entries = new Map<string, PiEntry>();\n\t\tconst roles = [...options.roles];\n\t\tconst pending = new Set<{ taskId: string; suppressed: boolean }>();\n\t\t// The operations always supply an actual owning adapter. The lazy default is\n\t\t// an actual Pi adapter too, only constructed if the generic default is used.\n\t\tconst kernel = createRunSession({\n\t\t\tget adapter() {\n\t\t\t\treturn adapter(state.options.getLaunchSnapshot());\n\t\t\t},\n\t\t\troles,\n\t\t\tcwd: process.cwd(),\n\t\t\toperations: {\n\t\t\t\tasync prepare(task, role) {\n\t\t\t\t\tif (task.worktree)\n\t\t\t\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\t\t\tconst snapshot = state.options.getLaunchSnapshot();\n\t\t\t\t\tif (!snapshot.parentRuntime)\n\t\t\t\t\t\tthrow new Error(\"Pi launch requires the active parent runtime\");\n\t\t\t\t\tconst plans = resolveRuntimePlans(\n\t\t\t\t\t\ttask.runtime ?? {},\n\t\t\t\t\t\trole.defaults ?? {},\n\t\t\t\t\t\tsnapshot.parentRuntime,\n\t\t\t\t\t\tsnapshot.modelRegistry,\n\t\t\t\t\t);\n\t\t\t\t\tfor (const candidate of task.runtime?.fallbacks ?? [])\n\t\t\t\t\t\tplans.push(\n\t\t\t\t\t\t\tresolveRuntimePlan(\n\t\t\t\t\t\t\t\tcandidate,\n\t\t\t\t\t\t\t\trole.defaults ?? {},\n\t\t\t\t\t\t\t\tsnapshot.parentRuntime,\n\t\t\t\t\t\t\t\tsnapshot.modelRegistry,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\tconst [first, ...rest] = plans;\n\t\t\t\t\tif (!first) throw new Error(\"No resolved runtime plans\");\n\t\t\t\t\tconst id = randomUUID();\n\t\t\t\t\treturn prepare(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\trole,\n\t\t\t\t\t\t\tplans: [first, ...rest],\n\t\t\t\t\t\t\tresolved: {\n\t\t\t\t\t\t\t\tagent: role.name || undefined,\n\t\t\t\t\t\t\t\tcwd: task.cwd,\n\t\t\t\t\t\t\t\ttools: task.tools?.join(\",\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\tlogicalId: id,\n\t\t\t\t\t\t\t\tgenerationId: randomUUID(),\n\t\t\t\t\t\t\t\ttaskId: randomUUID(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tasync resume(resumeOptions, task) {\n\t\t\t\t\tconst acquisition = { taskId: task.id, suppressed: false };\n\t\t\t\t\tstate.pending.add(acquisition);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst snapshot = state.options.getLaunchSnapshot();\n\t\t\t\t\t\tconst before = getNewEntries(resumeOptions.sessionId, 0);\n\t\t\t\t\t\tconst owner = adapter(snapshot);\n\t\t\t\t\t\tconst handle = await owner.resume(resumeOptions);\n\t\t\t\t\t\ttask.cwd = handle.cwd;\n\t\t\t\t\t\treturn acquired(\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\towner,\n\t\t\t\t\t\t\thandle,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tbefore.length,\n\t\t\t\t\t\t\tacquisition.suppressed,\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tstate.pending.delete(acquisition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\thooks: {\n\t\t\t\tasync onSpawned(_handle, task) {\n\t\t\t\t\tconst entry = entries.get(task.id)!;\n\t\t\t\t\tawait state.options.hooks.onSpawned?.(\n\t\t\t\t\t\tentry.record,\n\t\t\t\t\t\tentry.started,\n\t\t\t\t\t\ttask,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tonCancelState(handle, task, cancelState) {\n\t\t\t\t\t// The kernel owns the intent; project it onto whichever owner is\n\t\t\t\t\t// current, including one transferred after the cancel call.\n\t\t\t\t\tconst entry = entries.get(task.id);\n\t\t\t\t\tif (\n\t\t\t\t\t\tentry &&\n\t\t\t\t\t\tentry.record.id === handle.id &&\n\t\t\t\t\t\tentry.record.sessionFile === handle.sessionId\n\t\t\t\t\t)\n\t\t\t\t\t\tentry.record.cancelState = cancelState;\n\t\t\t\t},\n\t\t\t\tonObserved(_handle, _projection, observation) {\n\t\t\t\t\tconst entry = [...entries.values()].find(\n\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\te.record.id === _handle.id &&\n\t\t\t\t\t\t\te.record.sessionFile === _handle.sessionId,\n\t\t\t\t\t);\n\t\t\t\t\tif (entry) observed(entry.record, observation);\n\t\t\t\t},\n\t\t\t\tasync onSettled(result, task) {\n\t\t\t\t\tconst entry = entries.get(task.id)!;\n\t\t\t\t\t// Exhausted acquisition failures are attached by the generic kernel after\n\t\t\t\t\t// the last real attempt was finalized; preserve its original raw text.\n\t\t\t\t\tconst completed = { ...entry.completed!, run: result };\n\t\t\t\t\tif (result.evidence?.errorMessage !== undefined)\n\t\t\t\t\t\tcompleted.errorMessage = result.evidence.errorMessage;\n\t\t\t\t\tif (result.cancellation) {\n\t\t\t\t\t\t// A cancel can settle after a retryable attempt was finalized with\n\t\t\t\t\t\t// its natural error; present the run's actual cancelled outcome.\n\t\t\t\t\t\tcompleted.summary = \"Subagent cancelled.\";\n\t\t\t\t\t\tcompleted.summarySource = \"host\";\n\t\t\t\t\t\tcompleted.error = \"cancelled\";\n\t\t\t\t\t\tcompleted.exitCode = 1;\n\t\t\t\t\t\tcompleted.sessionFile = entry.record.sessionFile;\n\t\t\t\t\t\tcompleted.errorMessage = undefined;\n\t\t\t\t\t\tcompleted.ping = undefined;\n\t\t\t\t\t}\n\t\t\t\t\tentry.completed = completed;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst decision = await state.options.hooks.onSettled(\n\t\t\t\t\t\t\tentry.record,\n\t\t\t\t\t\t\tcompleted,\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\tentry.readResumeResult\n\t\t\t\t\t\t\t\t? { ...io, readResumeResult: entry.readResumeResult }\n\t\t\t\t\t\t\t\t: io,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tentry.record.lifecycle = markDelivery(\n\t\t\t\t\t\t\tentry.record.lifecycle,\n\t\t\t\t\t\t\tdecision === \"suppressed\" ? \"suppressed\" : \"delivered\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn decision;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tentries.delete(task.id);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\t// Reserve through kernel.resume before any transcript read or adapter creation.\n\t\tresumePi = async (input) => {\n\t\t\tconst task: Task = {\n\t\t\t\tid: input.taskId,\n\t\t\t\tname: input.name,\n\t\t\t\tprompt: input.message ?? \"resumed session\",\n\t\t\t\trole: \"\",\n\t\t\t\tcwd: process.cwd(),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\treturn await kernel.resume({\n\t\t\t\t\ttask,\n\t\t\t\t\tname: input.name,\n\t\t\t\t\tsessionId: input.sessionPath,\n\t\t\t\t\tmessage: input.message,\n\t\t\t\t\tautoExit: input.autoExit,\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tprune(task.id);\n\t\t\t}\n\t\t};\n\t\tstate = {\n\t\t\tbinding,\n\t\t\toptions,\n\t\t\tkernel,\n\t\t\tentries,\n\t\t\tinfrastructure,\n\t\t\troles,\n\t\t\tpending,\n\t\t\tresumePi,\n\t\t\tworktreeOperations:\n\t\t\t\toptions.infrastructure?.worktreeOperations ??\n\t\t\t\toptions.infrastructure?.launchOperations.worktree ??\n\t\t\t\tcreateWorktreeOperations(),\n\t\t};\n\t}\n\t// Replacements must invoke the original kernel's invocation closure, which\n\t// reads this shared current binding, not the old facade's options.\n\tif (adopted) resumePi = state.resumePi;\n\t// Live markers and their sequence survive a reload with their runs.\n\tif (\n\t\tstate.binding.backend === \"legacy\" &&\n\t\t!state.infrastructure.surfaceProvider.nativeExecution\n\t)\n\t\tstate.markers ??= createDelegatedMarkers(options);\n\tconst acceptChecks = (state.acceptChecks ??= {\n\t\tlabel: \"parent run session\",\n\t});\n\n\tfunction prune(id: string) {\n\t\tif (!state.kernel.getTask(id)) state.entries.delete(id);\n\t}\n\tfunction live(id: string): PiEntry | undefined {\n\t\tprune(id);\n\t\treturn state.entries.get(id);\n\t}\n\tfunction record(id: string): PiRunRecord {\n\t\tconst value = live(id)?.record;\n\t\tif (!value) throw new Error(`Task \"${id}\" has no active Pi owner.`);\n\t\treturn value;\n\t}\n\tfunction hydrate(\n\t\tchild: PiRunRecord,\n\t\tat: number,\n\t\tkind: RunObservation[\"kind\"],\n\t): RunObservation {\n\t\tconst read = readSubagentActivityFile(child.activityFile, child.id);\n\t\tchild.lifecycle = observeActivity(child.lifecycle, read, at);\n\t\treturn {\n\t\t\tkind,\n\t\t\tobservedAt: at,\n\t\t\tlifecycle: child.lifecycle,\n\t\t\tprojection: projectLifecycle(child.lifecycle, at),\n\t\t\tactivity: read.ok ? read.activity : undefined,\n\t\t\tactivityRead: read,\n\t\t};\n\t}\n\tfunction observed(child: PiRunRecord, observation: RunObservation) {\n\t\tconst entry = [...state.entries.values()].find(\n\t\t\t(candidate) => candidate.record === child,\n\t\t);\n\t\tif (child.lifecycle.delivery === \"suppressed\" || !entry) return;\n\t\tentry.marker?.renew();\n\t\tif (observation.kind === \"local-evidence\" && child.persistent) {\n\t\t\ttry {\n\t\t\t\tstate.options.persistent.drain(child, io);\n\t\t\t} catch {\n\t\t\t\t/* unread event retries on a later wake */\n\t\t\t}\n\t\t}\n\t\tstate.options.hooks.onObserved?.(child, observation);\n\t}\n\tfunction launchOperations(snapshot: PiLaunchSnapshot): PiLaunchOperations {\n\t\treturn {\n\t\t\t...(state.options.infrastructure?.launchOperations ??\n\t\t\t\tlaunchOperationsFromSurface(\n\t\t\t\t\tstate.binding.backend === \"core\"\n\t\t\t\t\t\t? state.infrastructure.surfaceProvider\n\t\t\t\t\t\t: state.options.hostSurface!.createLaunchProvider(snapshot),\n\t\t\t\t\tsnapshot.paneConfig,\n\t\t\t\t)),\n\t\t\tworktree: state.worktreeOperations,\n\t\t};\n\t}\n\tfunction adapter(snapshot: PiLaunchSnapshot): PiHarnessAdapter {\n\t\treturn new PiHarnessAdapter({\n\t\t\tchildEntryPath: state.options.childEntryPath,\n\t\t\tsurface: state.infrastructure.surfaceProvider,\n\t\t\tpaneConfig: snapshot.paneConfig,\n\t\t\tmodelRegistry: snapshot.modelRegistry,\n\t\t\tparent: snapshot.parent,\n\t\t\tparentRuntime: snapshot.parentRuntime,\n\t\t\tsupervision: state.infrastructure.supervision,\n\t\t\tprocessProbe: state.infrastructure.processProbe,\n\t\t\toperations: launchOperations(snapshot),\n\t\t\tonObservation(child, kind) {\n\t\t\t\tconst at = Date.now();\n\t\t\t\t// Local evidence only drains events. Tick/refresh still hydrate fresh\n\t\t\t\t// activity; preserve the callback without another activity-file parse.\n\t\t\t\tobserved(\n\t\t\t\t\tchild,\n\t\t\t\t\tkind === \"local-evidence\"\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tobservedAt: at,\n\t\t\t\t\t\t\t\tlifecycle: child.lifecycle,\n\t\t\t\t\t\t\t\tprojection: projectLifecycle(child.lifecycle, at),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: hydrate(child, at, kind),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n\tfunction acquired(\n\t\ttask: Task,\n\t\towner: PiHarnessAdapter,\n\t\thandle: AgentHandle,\n\t\tattempts: string[],\n\t\tfailures: { model: string; error: string }[],\n\t\twarning?: string,\n\t\tcursor?: number,\n\t\tsuppressed = false,\n\t): OwnedRunAttempt {\n\t\tconst child = owner.getRunningChild(handle);\n\t\tconst entry: PiEntry = {\n\t\t\trecord: child,\n\t\t\tstarted: {\n\t\t\t\tid: child.id,\n\t\t\t\tname: child.name,\n\t\t\t\ttask: child.task,\n\t\t\t\tagent: child.agent,\n\t\t\t\tsessionFile: child.sessionFile,\n\t\t\t\tlaunchScriptFile: child.launchScriptFile,\n\t\t\t\tmodel: child.runtimePlan?.model,\n\t\t\t\tthinking: child.runtimePlan?.thinking,\n\t\t\t\truntimePlan: child.runtimePlan,\n\t\t\t\tworktree: child.worktree,\n\t\t\t\twarning,\n\t\t\t\tstatus: child.launchFailure ? \"uncertain\" : \"started\",\n\t\t\t\tlaunchFailure: child.launchFailure,\n\t\t\t},\n\t\t};\n\t\tif (suppressed)\n\t\t\tchild.lifecycle = markDelivery(child.lifecycle, \"suppressed\");\n\t\telse {\n\t\t\tentry.marker = state.markers?.attach(child);\n\t\t\tstate.entries.set(task.id, entry);\n\t\t}\n\t\treturn {\n\t\t\thandle,\n\t\t\tadapter: owner,\n\t\t\tpersistent: child.persistent ?? false,\n\t\t\tcloseTemporarySurface: child.ownsSurface\n\t\t\t\t? temporarySurfaceRelease(\n\t\t\t\t\t\tstate.infrastructure.surfaceProvider,\n\t\t\t\t\t\tchild.surface,\n\t\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tobserve: (at) => hydrate(child, at, \"refresh\"),\n\t\t\tfinalize: async (result, _task, control) => {\n\t\t\t\t// Clear before delivery; a retained worktree root keeps its pane.\n\t\t\t\tentry.marker?.retire();\n\t\t\t\tconst at = Date.now();\n\t\t\t\tlet evidence = result.evidence;\n\t\t\t\tif (evidence)\n\t\t\t\t\tchild.lifecycle = markCompletionDetected(\n\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\tat,\n\t\t\t\t\t);\n\t\t\t\t// A rejected adapter wait follows the shipped watch error result:\n\t\t\t\t// transcript I/O is not retried as part of presenting that failure.\n\t\t\t\tlet all: ReturnType<typeof getNewEntries> = [];\n\t\t\t\ttry {\n\t\t\t\t\tif (evidence && existsSync(child.sessionFile))\n\t\t\t\t\t\tall = getNewEntries(child.sessionFile, 0);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// This is Pi processing failure AFTER real adapter evidence, not a\n\t\t\t\t\t// provider error or a failed parent send. Normalize to the shipped\n\t\t\t\t\t// watch error result and settle once; no synthetic evidence/retry.\n\t\t\t\t\tresult = {\n\t\t\t\t\t\thandle: result.handle,\n\t\t\t\t\t\toutcome: \"failed\",\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tdurationMs: result.durationMs,\n\t\t\t\t\t};\n\t\t\t\t\tevidence = undefined;\n\t\t\t\t}\n\t\t\t\tconst exitCode = evidence?.exitCode ?? 1;\n\t\t\t\tconst observedRuntime = findObservedSessionRuntime(all);\n\t\t\t\tif (\n\t\t\t\t\tchild.runtimePlan &&\n\t\t\t\t\tobservedRuntime.provider &&\n\t\t\t\t\tobservedRuntime.modelId\n\t\t\t\t) {\n\t\t\t\t\tconst model = `${observedRuntime.provider}/${observedRuntime.modelId}`;\n\t\t\t\t\tconst thinking =\n\t\t\t\t\t\tobservedRuntime.thinking !== undefined &&\n\t\t\t\t\t\tisThinkingLevel(observedRuntime.thinking)\n\t\t\t\t\t\t\t? observedRuntime.thinking\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst plan: ResolvedRuntimePlan = {\n\t\t\t\t\t\t...child.runtimePlan,\n\t\t\t\t\t\tobserved: { model },\n\t\t\t\t\t};\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tplan.thinking = thinking;\n\t\t\t\t\t\tplan.observed!.thinking = thinking;\n\t\t\t\t\t}\n\t\t\t\t\tif (model !== plan.model)\n\t\t\t\t\t\tplan.runtimeMismatch = `Resolved model ${plan.model} but child reported ${model}`;\n\t\t\t\t\tchild.runtimePlan = plan;\n\t\t\t\t}\n\t\t\t\tconst { summary, summarySource }: AttributedSummary = evidence\n\t\t\t\t\t? (findLastAssistantSummary(\n\t\t\t\t\t\t\tcursor === undefined ? all : all.slice(cursor),\n\t\t\t\t\t\t) ?? {\n\t\t\t\t\t\t\tsummary: evidence.errorMessage\n\t\t\t\t\t\t\t\t? `Subagent error: ${evidence.errorMessage}`\n\t\t\t\t\t\t\t\t: exitCode === 0\n\t\t\t\t\t\t\t\t\t? cursor === undefined\n\t\t\t\t\t\t\t\t\t\t? \"Sub-agent exited without output\"\n\t\t\t\t\t\t\t\t\t\t: \"Resumed session exited without new output\"\n\t\t\t\t\t\t\t\t\t: `${cursor === undefined ? \"Sub-agent\" : \"Resumed session\"} exited with code ${exitCode}`,\n\t\t\t\t\t\t\t// Only a child-written sidecar error is child provenance.\n\t\t\t\t\t\t\tsummarySource: evidence.errorMessage\n\t\t\t\t\t\t\t\t? errorProvenance(evidence.errorSource)\n\t\t\t\t\t\t\t\t: \"host\",\n\t\t\t\t\t\t})\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tsummary:\n\t\t\t\t\t\t\t\tresult.outcome === \"killed\"\n\t\t\t\t\t\t\t\t\t? \"Subagent cancelled.\"\n\t\t\t\t\t\t\t\t\t: `Subagent error: ${result.error}`,\n\t\t\t\t\t\t\tsummarySource: \"host\",\n\t\t\t\t\t\t};\n\t\t\t\tlet worktree: PiWorktreeHandoff | undefined = child.worktree\n\t\t\t\t\t? await state.worktreeOperations.captureWorktreeHandoff(\n\t\t\t\t\t\t\tchild.worktree,\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\t\t// After the handoff capture, before the lifecycle and manifest marks:\n\t\t\t\t// the parent re-check decides the verdict (ADR-0017).\n\t\t\t\tconst accept = child.accept\n\t\t\t\t\t? await runParentAcceptCheck({\n\t\t\t\t\t\t\tspec: child.accept,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t\texitCode,\n\t\t\t\t\t\t\tcwd: child.cwd,\n\t\t\t\t\t\t\tworktree,\n\t\t\t\t\t\t\tcontrol,\n\t\t\t\t\t\t\trunner: state.infrastructure.acceptRunner ?? runAcceptCommand,\n\t\t\t\t\t\t\towner: acceptChecks,\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\t\t// A cancel that won during the re-check, with termination confirmed,\n\t\t\t\t// delivers the cancelled result: the kernel says so, not the check.\n\t\t\t\tconst cancelledInCheck =\n\t\t\t\t\t!result.cancellation && control.interruption() === \"cancelled\";\n\t\t\t\tif (child.worktree && worktree) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Only confirmed termination is a cancellation. Shutdown suppression\n\t\t\t\t\t\t// of an unconfirmed cancel records what a plain shutdown would. A\n\t\t\t\t\t\t// rejected verdict leaves the manifest state unchanged.\n\t\t\t\t\t\tstate.worktreeOperations.persistWorktreeResult(\n\t\t\t\t\t\t\tchild.worktree,\n\t\t\t\t\t\t\tresult.cancellation?.termination === \"confirmed\" ||\n\t\t\t\t\t\t\t\tcancelledInCheck\n\t\t\t\t\t\t\t\t? \"cancelled\"\n\t\t\t\t\t\t\t\t: worktreeResultState(exitCode, !!evidence?.ping),\n\t\t\t\t\t\t\tworktree,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tworktree = {\n\t\t\t\t\t\t\t...worktree,\n\t\t\t\t\t\t\tgitError: [\n\t\t\t\t\t\t\t\tworktree.gitError,\n\t\t\t\t\t\t\t\t`Manifest update failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t.join(\"; \"),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tchild.lifecycle =\n\t\t\t\t\texitCode === 0 && !cancelledInCheck\n\t\t\t\t\t\t? markCompleted(child.lifecycle, at)\n\t\t\t\t\t\t: markFailed(\n\t\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\t\tcancelledInCheck ? \"Subagent cancelled.\" : summary,\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\tcancelledInCheck ? 1 : exitCode,\n\t\t\t\t\t\t\t);\n\t\t\t\tif (evidence?.errorMessage)\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tmodel: child.runtimePlan?.model ?? attempts.at(-1)!,\n\t\t\t\t\t\terror: evidence.errorMessage,\n\t\t\t\t\t});\n\t\t\t\tentry.completed = {\n\t\t\t\t\trun: result,\n\t\t\t\t\tname: child.name,\n\t\t\t\t\ttask: child.task,\n\t\t\t\t\tagent: child.agent,\n\t\t\t\t\tsummary,\n\t\t\t\t\tsummarySource,\n\t\t\t\t\tsessionFile:\n\t\t\t\t\t\tevidence || result.outcome === \"killed\"\n\t\t\t\t\t\t\t? child.sessionFile\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\texitCode,\n\t\t\t\t\telapsed: Math.floor((at - child.startTime) / 1000),\n\t\t\t\t\terror: evidence\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: result.outcome === \"killed\"\n\t\t\t\t\t\t\t? \"cancelled\"\n\t\t\t\t\t\t\t: result.error,\n\t\t\t\t\terrorMessage: evidence?.errorMessage,\n\t\t\t\t\tping: evidence?.ping,\n\t\t\t\t\t// The watch catch omits its result plan; the host still reports the\n\t\t\t\t\t// live child's plan in structured details, not in the error summary.\n\t\t\t\t\truntimePlan: evidence ? child.runtimePlan : undefined,\n\t\t\t\t\tworktree,\n\t\t\t\t\taccept,\n\t\t\t\t\tlogicalId: child.logicalId,\n\t\t\t\t\tgenerationId: child.generationId,\n\t\t\t\t\tpolicyHash: child.policyHash,\n\t\t\t\t};\n\t\t\t\tif (state.options.outcomeLedger !== false)\n\t\t\t\t\tappendOutcomeLedger(outcomeLedgerFile(state.options.configDir), {\n\t\t\t\t\t\tat,\n\t\t\t\t\t\trunId: child.id,\n\t\t\t\t\t\tattempt: Math.max(1, attempts.length),\n\t\t\t\t\t\trole: child.agent,\n\t\t\t\t\t\trequestedModel:\n\t\t\t\t\t\t\ttask.requestedModel ?? child.runtimePlan?.requestedModel,\n\t\t\t\t\t\tmodel:\n\t\t\t\t\t\t\tchild.runtimePlan?.observed?.model ?? child.runtimePlan?.model,\n\t\t\t\t\t\tthinking: child.runtimePlan?.thinking,\n\t\t\t\t\t\telapsedSec: entry.completed.elapsed,\n\t\t\t\t\t\toutcome: ledgerOutcome(\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t\texitCode,\n\t\t\t\t\t\t\tcancelledInCheck,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taccept,\n\t\t\t\t\t});\n\t\t\t\tif (cursor !== undefined)\n\t\t\t\t\tentry.readResumeResult = resumeResultReader(\n\t\t\t\t\t\tchild.sessionFile,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t\texitCode,\n\t\t\t\t\t\tevidence?.errorMessage,\n\t\t\t\t\t\tevidence?.errorSource,\n\t\t\t\t\t);\n\t\t\t\tif (cursor === undefined) {\n\t\t\t\t\tentry.completed.fallbackAttempts = attempts;\n\t\t\t\t\tentry.completed.fallbackFailures = failures;\n\t\t\t\t}\n\t\t\t\treturn worktree && evidence\n\t\t\t\t\t? { ...result, evidence: { ...evidence, worktree } }\n\t\t\t\t\t: result;\n\t\t\t},\n\t\t};\n\t}\n\tfunction prepare(\n\t\tinput: PiLaunchInput,\n\t\tsnapshot?: PiLaunchSnapshot,\n\t): PreparedRun {\n\t\tconst attempts: string[] = [];\n\t\tconst failures: { model: string; error: string }[] = [];\n\t\tlet publicId: string | undefined;\n\t\tlet logicalId: string | undefined;\n\t\tlet capturedSnapshot = snapshot;\n\t\treturn {\n\t\t\trole: input.role,\n\t\t\tpersistent:\n\t\t\t\tinput.task.behavior?.persistent ??\n\t\t\t\tinput.role.defaults?.persistent ??\n\t\t\t\tfalse,\n\t\t\tcandidates: input.plans,\n\t\t\tasync spawnAttempt(_spawn: SpawnOptions, index, cancelled) {\n\t\t\t\tconst plan = input.plans[index];\n\t\t\t\tattempts.push(plan.model);\n\t\t\t\tconst acquisition = { taskId: input.task.id, suppressed: false };\n\t\t\t\tstate.pending.add(acquisition);\n\t\t\t\tlet spawning = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst current = (await input.prepareAttempt?.(index, cancelled)) ?? {\n\t\t\t\t\t\t...input,\n\t\t\t\t\t\tsnapshot: (capturedSnapshot ??= state.options.getLaunchSnapshot()),\n\t\t\t\t\t};\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent.task.id !== input.task.id ||\n\t\t\t\t\t\tcurrent.task.prompt !== input.task.prompt ||\n\t\t\t\t\t\tJSON.stringify(current.task.worktree) !==\n\t\t\t\t\t\t\tJSON.stringify(input.task.worktree)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\"Pi attempt preparation changed the invocation identity, prompt or worktree.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t// A candidate was authorized at planning time; the scope may have\n\t\t\t\t\t// changed since. Re-check it against this attempt's snapshot, which\n\t\t\t\t\t// prepareAttempt rebuilds from the live parent for every attempt.\n\t\t\t\t\tassertModelInScope(plan.model, current.snapshot.modelRegistry);\n\t\t\t\t\tconst owner = adapter(current.snapshot);\n\t\t\t\t\tspawning = true;\n\t\t\t\t\tconst handle = await owner.spawn({\n\t\t\t\t\t\tacquisitionSignal: cancelled,\n\t\t\t\t\t\tname: input.task.name,\n\t\t\t\t\t\ttask: input.task.prompt,\n\t\t\t\t\t\tcwd: current.task.cwd,\n\t\t\t\t\t\tsessionId: current.snapshot.parent.sessionId,\n\t\t\t\t\t\trole: current.role,\n\t\t\t\t\t\tenv: current.task.env,\n\t\t\t\t\t\tsession: current.task.session,\n\t\t\t\t\t\tbehavior: current.task.behavior,\n\t\t\t\t\t\ttools: current.task.tools,\n\t\t\t\t\t\tsystemPrompt: current.resolved.agent\n\t\t\t\t\t\t\t? current.role.systemPrompt\n\t\t\t\t\t\t\t: current.task.systemPrompt,\n\t\t\t\t\t\tsurface: input.surface,\n\t\t\t\t\t\tworktreeRequest: input.task.worktree,\n\t\t\t\t\t\taccept: input.task.accept,\n\t\t\t\t\t\truntime: { model: plan.model, thinking: plan.thinking },\n\t\t\t\t\t\tresolvedLaunch: { ...current.resolved, runtimePlan: plan },\n\t\t\t\t\t\tlaunchIdentity: {\n\t\t\t\t\t\t\t...current.identity,\n\t\t\t\t\t\t\tid: publicId ?? current.identity.id,\n\t\t\t\t\t\t\tlogicalId: logicalId ?? current.identity.logicalId,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tpublicId = handle.id;\n\t\t\t\t\tlogicalId ??= current.identity.logicalId;\n\t\t\t\t\treturn acquired(\n\t\t\t\t\t\tinput.task,\n\t\t\t\t\t\towner,\n\t\t\t\t\t\thandle,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tfailures,\n\t\t\t\t\t\tinput.warning,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tacquisition.suppressed,\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (cancelled.aborted && !spawning) {\n\t\t\t\t\t\t// Cancelled while preparing: the candidate neither launched nor failed.\n\t\t\t\t\t\tattempts.pop();\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tmodel: plan.model,\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tstate.pending.delete(acquisition);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\tconst io = createPiPersistentIO(state);\n\tconst facade: PiRunSession = {\n\t\t...state.kernel,\n\t\tasync handoffWorktree(input) {\n\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\t// This is a long-lived interactive handoff, deliberately outside the\n\t\t\t// watched kernel: no task reservation, acquire, producer or watcher.\n\t\t\tconst snapshot = input.snapshot;\n\t\t\tconst result = await launchPiWorktreeHandoff(\n\t\t\t\t{\n\t\t\t\t\tkind: \"fresh\",\n\t\t\t\t\tname: input.name,\n\t\t\t\t\ttask: input.task,\n\t\t\t\t\tcwd: snapshot.parent.cwd,\n\t\t\t\t\tworktree: { branch: input.branch },\n\t\t\t\t\thandoff: { leafId: input.leafId },\n\t\t\t\t\tparent: { ...snapshot.parent },\n\t\t\t\t\truntimePlan: input.runtimePlan,\n\t\t\t\t\tmodelScope: snapshot.modelRegistry.scope,\n\t\t\t\t\tbehavior: {\n\t\t\t\t\t\tdeniedTools: [],\n\t\t\t\t\t\tautoExit: false,\n\t\t\t\t\t\tinteractive: true,\n\t\t\t\t\t\tsessionMode: \"standalone\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlaunchOperations(snapshot),\n\t\t\t);\n\t\t\treturn { record: result.running, focusError: result.focusError };\n\t\t},\n\t\tcreateWorktreeCleanupOperations: (input) => {\n\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\tif (state.infrastructure.surfaceProvider.nativeExecution)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Managed worktree cleanup is not supported by Herdr Core\",\n\t\t\t\t);\n\t\t\treturn createWorktreeCleanupOperations(\n\t\t\t\tstate.infrastructure.surfaceProvider,\n\t\t\t\tinput,\n\t\t\t);\n\t\t},\n\t\tmanagedWorktreeRefusal: () =>\n\t\t\tmanagedWorktreeRefusal(state.options.platform),\n\t\tasync spawnPi(input) {\n\t\t\t// Refuse before the kernel reserves the task or any attempt starts.\n\t\t\tif (input.task.worktree)\n\t\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.spawn(input.task, prepare(input));\n\t\t\t} finally {\n\t\t\t\tprune(input.task.id);\n\t\t\t}\n\t\t},\n\t\tresumePi: (input) => resumePi(input),\n\t\tasync supervise(handle, task, signal) {\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.supervise(handle, task, signal);\n\t\t\t} finally {\n\t\t\t\tprune(task.id);\n\t\t\t}\n\t\t},\n\t\tgetRecord: (id) => live(id)?.record,\n\t\tgetStarted: (id) => live(id)?.started,\n\t\tgetCompleted: (id) => live(id)?.completed,\n\t\tgetControlTaskId(publicId) {\n\t\t\tfor (const [id, entry] of state.entries)\n\t\t\t\tif (live(id) && entry.record.id === publicId) return id;\n\t\t\treturn undefined;\n\t\t},\n\t\tsuppress(id) {\n\t\t\tfor (const acquisition of state.pending)\n\t\t\t\tif (acquisition.taskId === id) acquisition.suppressed = true;\n\t\t\tconst suppressed = live(id);\n\t\t\tconst r = suppressed?.record;\n\t\t\tif (r) r.lifecycle = markDelivery(r.lifecycle, \"suppressed\");\n\t\t\t// Nothing renews an unsupervised run's marker; clear it now.\n\t\t\tsuppressed?.marker?.retire();\n\t\t\tstate.kernel.suppress(id);\n\t\t\tstate.entries.delete(id);\n\t\t},\n\t\tasync cancel(id) {\n\t\t\t// The kernel records the intent and projects every owner's cancel state\n\t\t\t// through onCancelState; a natural result taken first keeps its own.\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.cancel(id);\n\t\t\t} finally {\n\t\t\t\tprune(id);\n\t\t\t}\n\t\t},\n\t\tasync sendPersistent(id, text) {\n\t\t\treturn state.options.persistent.send(record(id), text, io);\n\t\t},\n\t\tasync stopPersistent(id, timeoutMs = 15_000) {\n\t\t\treturn state.options.persistent.stop(record(id), timeoutMs, io);\n\t\t},\n\t\tasync send(id, text) {\n\t\t\tconst ack = await facade.sendPersistent(id, text);\n\t\t\tif (\"error\" in ack) throw new Error(ack.error);\n\t\t},\n\t\tavailability: () => ({\n\t\t\tavailable: state.infrastructure.surfaceProvider.isAvailable(),\n\t\t\tsetupHint: state.infrastructure.surfaceProvider.setupHint(),\n\t\t}),\n\t\tlistWorktreeSurfaces: (opts) =>\n\t\t\tstate.infrastructure.surfaceProvider.listWorktreeSurfaces(opts),\n\t\tinspectProgress(id) {\n\t\t\tconst r = record(id);\n\t\t\tlet updatedAt: number | undefined;\n\t\t\ttry {\n\t\t\t\tupdatedAt = statSync(r.sessionFile).mtimeMs;\n\t\t\t} catch {\n\t\t\t\t/* unavailable */\n\t\t\t}\n\t\t\treturn { ...inspectNoProgressSessionTail(r.sessionFile), updatedAt };\n\t\t},\n\t\tdiagnostics: () => state.infrastructure.supervision.diagnostics(),\n\t\tasync shutdown(reason) {\n\t\t\tif (![\"reload\", \"new\", \"resume\", \"fork\"].includes(reason ?? \"\")) {\n\t\t\t\tfor (const id of new Set([\n\t\t\t\t\t...state.entries.keys(),\n\t\t\t\t\t...[...state.pending].map((a) => a.taskId),\n\t\t\t\t]))\n\t\t\t\t\tfacade.suppress(id);\n\t\t\t\tstate.infrastructure.supervision.close();\n\t\t\t\t// Suppression aborted their re-checks; finish what ignores SIGTERM.\n\t\t\t\tawait terminateAcceptChecks(acceptChecks);\n\t\t\t}\n\t\t},\n\t};\n\tObject.defineProperty(facade, OWNER, { value: state });\n\treturn facade;\n}\n"]}
1
+ {"version":3,"file":"pi-run-session.js","sourceRoot":"","sources":["../../../maestro/runtime/pi-run-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EACN,2BAA2B,GAE3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACn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WAAW,CAAC,KAAK,EAAE,CAAC;gBACzC,oEAAoE;gBACpE,MAAM,qBAAqB,CAAC,YAAY,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;KACD,CAAC;IACF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport type { SpawnOptions } from \"../core/harness-adapter.ts\";\nimport type {\n\tAgentHandle,\n\tTask,\n\tRole,\n\tSubagentLifecycle,\n\tActivityReadResult,\n\tCompletionEvidence,\n} from \"../core/types.ts\";\nimport type { SurfaceProvider } from \"../core/surface-provider.ts\";\nimport { PiHarnessAdapter } from \"../adapters/pi/pi-harness-adapter.ts\";\nimport {\n\tlaunchOperationsFromSurface,\n\ttype PiLaunchOperations,\n} from \"../adapters/pi/launch-operations.ts\";\nimport { launchPiWorktreeHandoff } from \"../adapters/pi/launch.ts\";\nimport {\n\tcreateWorktreeOperations,\n\tcreateWorktreeCleanupOperations,\n} from \"./worktree-operations.ts\";\nimport {\n\tworktreeResultState,\n\ttype WorktreeOperations,\n} from \"../core/worktree.ts\";\nimport {\n\tgetNewEntries,\n\tfindLastAssistantSummary,\n\tfindObservedSessionRuntime,\n\tinspectNoProgressSessionTail,\n\ttype AttributedSummary,\n} from \"../adapters/pi/session.ts\";\nimport {\n\tassertManagedWorktreesSupported,\n\tmanagedWorktreeRefusal,\n} from \"../core/platform-support.ts\";\nimport {\n\tassertSameHerdrBinding,\n\ttype HerdrBinding,\n} from \"../core/config/herdr-config.ts\";\nimport { createPiScriptShellResolver } from \"../adapters/pi/script-shell.ts\";\nimport { readSubagentActivityFile } from \"../adapters/pi/activity-file.ts\";\nimport { projectActivity } from \"../core/activity.ts\";\nimport {\n\tmarkCompletionDetected,\n\tmarkCompleted,\n\tmarkFailed,\n\tmarkDelivery,\n\tobserveActivity,\n\tprojectLifecycle,\n} from \"../core/lifecycle.ts\";\nimport { FileWakeRegistry } from \"../core/wake.ts\";\nimport { SupervisionCoordinator } from \"../core/supervision.ts\";\nimport {\n\tassertModelInScope,\n\tisThinkingLevel,\n\tresolveRuntimePlan,\n\tresolveRuntimePlans,\n\ttype ResolvedRuntimePlan,\n} from \"../core/routing.ts\";\nimport { loadPaneConfig } from \"../core/config/pane-config.ts\";\nimport { DelegatedMarkers, type DelegatedMarker } from \"./delegated-marker.ts\";\nimport {\n\tcreateRunSession,\n\ttype RunSession,\n\ttype RunObservation,\n\ttype OwnedRunAttempt,\n\ttype PreparedRun,\n} from \"./run-session.ts\";\nimport { createPiPersistentIO } from \"./pi-persistent-io.ts\";\nimport {\n\tappendOutcomeLedger,\n\tledgerOutcome,\n\toutcomeLedgerFile,\n\trunParentAcceptCheck,\n} from \"./accept-recheck.ts\";\nimport { runAcceptCommand } from \"../adapters/pi/accept-runner.ts\";\nimport {\n\tterminateAcceptChecks,\n\ttype AcceptCheckOwner,\n} from \"../adapters/pi/accept-groups.ts\";\nimport type {\n\tDefaultRunSessionOptions,\n\tPiCompletedMetadata,\n\tPiLaunchInput,\n\tPiLaunchSnapshot,\n\tPiResumeInput,\n\tPiRunRecord,\n\tPiRunSession,\n\tPiRunSessionInfrastructure,\n\tPiSettlementIO,\n\tPiStartedMetadata,\n\tPiWorktreeHandoff,\n} from \"./pi-run-session-types.ts\";\n\n// pi-herdr-agents extension; no owning session required\nexport function observePiActivity(\n\tinput: { id: string; activityFile?: string; lifecycle: SubagentLifecycle },\n\tobservedAt: number,\n): RunObservation & { activityRead: ActivityReadResult } {\n\tconst read = input.activityFile\n\t\t? readSubagentActivityFile(input.activityFile, input.id)\n\t\t: projectActivity(undefined);\n\tconst lifecycle = observeActivity(input.lifecycle, read, observedAt);\n\treturn {\n\t\tkind: \"refresh\",\n\t\tobservedAt,\n\t\tlifecycle,\n\t\tprojection: projectLifecycle(lifecycle, observedAt),\n\t\tactivity: read.ok ? read.activity : undefined,\n\t\tactivityRead: read,\n\t};\n}\n\n// pi-herdr-agents extension\ninterface PiEntry {\n\trecord: PiRunRecord;\n\tstarted: PiStartedMetadata;\n\tcompleted?: PiCompletedMetadata;\n\treadResumeResult?: PiSettlementIO[\"readResumeResult\"];\n\tmarker?: DelegatedMarker;\n}\n// The previous facade carries its live composition explicitly across module replacement.\n// No module-local lookup can accidentally rediscover an owner.\nconst OWNER = Symbol.for(\"pi-herdr-agents/PiRunSession-owner\");\n// pi-herdr-agents extension\ninterface PiSessionOwner {\n\tbinding: HerdrBinding;\n\toptions: DefaultRunSessionOptions;\n\troles: Role[];\n\t// Only acquisitions currently in flight; control reservation is kernel-owned.\n\tpending: Set<{ taskId: string; suppressed: boolean }>;\n\tresumePi(input: PiResumeInput): Promise<AgentHandle>;\n\tkernel: RunSession;\n\tentries: Map<string, PiEntry>;\n\tinfrastructure: Pick<\n\t\tPiRunSessionInfrastructure,\n\t\t\"surfaceProvider\" | \"supervision\" | \"processProbe\" | \"acceptRunner\"\n\t>;\n\tworktreeOperations: WorktreeOperations;\n\t/** Absent outside Herdr: without a socket nothing can be marked. */\n\tmarkers?: DelegatedMarkers;\n\t/** Owns this composition's parent re-checks; a quit terminates them. */\n\tacceptChecks?: AcceptCheckOwner;\n}\n\n// A detached close can outlive settlement without capturing a child, metadata,\n// adapter, current hook binding or the composition registry.\nfunction temporarySurfaceRelease(\n\tprovider: SurfaceProvider,\n\tsurface: string,\n): () => Promise<void> {\n\treturn async () => {\n\t\t// Suppression may release before a watcher observes native exit. Like a\n\t\t// legacy pane close, stop the owned program, but remove its record only\n\t\t// after independent exit confirmation and delivery/suppression gating.\n\t\tawait provider.nativeExecution?.terminate(surface);\n\t\tawait provider.closeSurface(surface);\n\t};\n}\n\nfunction createDelegatedMarkers(\n\toptions: DefaultRunSessionOptions,\n): DelegatedMarkers | undefined {\n\tconst transport = options.infrastructure\n\t\t? {\n\t\t\t\twrite: options.infrastructure.markerWriter,\n\t\t\t\treadSession: options.infrastructure.markerSessionReader,\n\t\t\t}\n\t\t: options.hostSurface!.markers?.();\n\treturn transport?.write && transport.readSession\n\t\t? new DelegatedMarkers({\n\t\t\t\twrite: transport.write,\n\t\t\t\treadSession: transport.readSession,\n\t\t\t})\n\t\t: undefined;\n}\n\n/** Host diagnostics stay host; only text the child wrote is child-error. */\nfunction errorProvenance(\n\tsource: CompletionEvidence[\"errorSource\"],\n): \"child-error\" | \"host\" {\n\treturn source === \"child\" ? \"child-error\" : \"host\";\n}\n\n// Capture only resume presentation scalars, not the child or its owning registry.\nfunction resumeResultReader(\n\tsessionFile: string,\n\tcursor: number,\n\texitCode: number,\n\terrorMessage: string | undefined,\n\terrorSource: CompletionEvidence[\"errorSource\"],\n): NonNullable<PiSettlementIO[\"readResumeResult\"]> {\n\treturn () => ({\n\t\t...(findLastAssistantSummary(getNewEntries(sessionFile, cursor)) ?? {\n\t\t\tsummary: errorMessage\n\t\t\t\t? `Subagent error: ${errorMessage}`\n\t\t\t\t: exitCode === 0\n\t\t\t\t\t? \"Resumed session exited without new output\"\n\t\t\t\t\t: `Resumed session exited with code ${exitCode}`,\n\t\t\tsummarySource: errorProvenance(errorSource),\n\t\t}),\n\t\tsessionFile,\n\t});\n}\n\n// pi-herdr-agents extension\nexport function createDefaultRunSession(\n\toptions: DefaultRunSessionOptions,\n\tprevious?: PiRunSession,\n): PiRunSession {\n\t// SAFETY: this factory alone attaches its private symbol owner to Pi facades.\n\tconst adopted =\n\t\tprevious &&\n\t\t(previous as PiRunSession & { [OWNER]?: PiSessionOwner })[OWNER];\n\tif (previous && !adopted)\n\t\tthrow new Error(\n\t\t\t\"Previous PiRunSession does not carry its owning composition.\",\n\t\t);\n\tif (\n\t\toptions.infrastructure &&\n\t\toptions.infrastructure.launchOperations.nativeExecution !==\n\t\t\toptions.infrastructure.surfaceProvider.nativeExecution\n\t)\n\t\tthrow new Error(\n\t\t\t\"Pi owning provider and launch operations must use the same native execution binding\",\n\t\t);\n\tif (!options.infrastructure && !options.hostSurface)\n\t\tthrow new Error(\"Pi run session requires a host surface binding\");\n\t// Injected infrastructure is a closed world: never inspect ambient Core sockets.\n\tconst binding: HerdrBinding = options.infrastructure\n\t\t? { backend: \"legacy\" }\n\t\t: options.hostSurface!.resolve(\n\t\t\t\toptions.configDir,\n\t\t\t\toptions.configExamplePath,\n\t\t\t\toptions.platform,\n\t\t\t);\n\tif (adopted) {\n\t\tassertSameHerdrBinding(adopted.binding, binding);\n\t\tconst previousNative =\n\t\t\tadopted.infrastructure.surfaceProvider.nativeExecution;\n\t\tconst nextNative = options.infrastructure?.surfaceProvider.nativeExecution;\n\t\tif (options.infrastructure && previousNative !== nextNative)\n\t\t\tthrow new Error(\"Injected native execution binding changed; restart Pi\");\n\t}\n\tlet state: PiSessionOwner;\n\tlet resumePi: (input: PiResumeInput) => Promise<AgentHandle>;\n\tif (adopted) {\n\t\tstate = adopted;\n\t\tconst supervision = state.infrastructure.supervision;\n\t\tif (supervision.setForcePolling) {\n\t\t\tsupervision.setForcePolling(options.forcePolling);\n\t\t} else if (\n\t\t\t(supervision.diagnostics().mode === \"polling(forced)\") !==\n\t\t\toptions.forcePolling\n\t\t) {\n\t\t\t// An owner created before live reconfiguration cannot transfer its\n\t\t\t// registrations safely. Never silently replace it or ignore config.\n\t\t\tthrow new Error(\n\t\t\t\t\"Cannot change supervision.forcePolling on a pre-upgrade coordinator. Let active children finish, then restart Pi to apply it.\",\n\t\t\t);\n\t\t}\n\t\tstate.options = options;\n\t\tstate.roles.splice(0, state.roles.length, ...options.roles);\n\t} else {\n\t\t// Configured placement belongs to each new launch; the coordinator alone owns\n\t\t// this explicitly injected registry. Injected infrastructure already owns one.\n\t\tconst provider =\n\t\t\toptions.infrastructure?.surfaceProvider ??\n\t\t\toptions.hostSurface!.createProvider(\n\t\t\t\tbinding,\n\t\t\t\tloadPaneConfig(\n\t\t\t\t\tjoin(options.configDir, \"herdr-agents\"),\n\t\t\t\t\toptions.configExamplePath,\n\t\t\t\t),\n\t\t\t\t// No launch context here, so project settings are untrusted.\n\t\t\t\tcreatePiScriptShellResolver({\n\t\t\t\t\tcwd: process.cwd(),\n\t\t\t\t\tprojectTrusted: false,\n\t\t\t\t}),\n\t\t\t);\n\t\tconst wake = options.infrastructure ? undefined : new FileWakeRegistry();\n\t\tconst supervision =\n\t\t\toptions.infrastructure?.supervision ??\n\t\t\tnew SupervisionCoordinator(\n\t\t\t\tasync () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcomplete: true,\n\t\t\t\t\t\t\tpanes: (await provider.listSurfaces()).map((s) => ({\n\t\t\t\t\t\t\t\tpaneId: s.id,\n\t\t\t\t\t\t\t\tworkspaceId: s.workspaceId ?? \"\",\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treturn { complete: false, panes: [] };\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(id) => provider.inspectSurface(id),\n\t\t\t\toptions.forcePolling,\n\t\t\t\twake,\n\t\t\t);\n\t\tconst infrastructure = options.infrastructure ?? {\n\t\t\tsurfaceProvider: provider,\n\t\t\tsupervision,\n\t\t};\n\t\tconst entries = new Map<string, PiEntry>();\n\t\tconst roles = [...options.roles];\n\t\tconst pending = new Set<{ taskId: string; suppressed: boolean }>();\n\t\t// The operations always supply an actual owning adapter. The lazy default is\n\t\t// an actual Pi adapter too, only constructed if the generic default is used.\n\t\tconst kernel = createRunSession({\n\t\t\tget adapter() {\n\t\t\t\treturn adapter(state.options.getLaunchSnapshot());\n\t\t\t},\n\t\t\troles,\n\t\t\tcwd: process.cwd(),\n\t\t\toperations: {\n\t\t\t\tasync prepare(task, role) {\n\t\t\t\t\tif (task.worktree)\n\t\t\t\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\t\t\tconst snapshot = state.options.getLaunchSnapshot();\n\t\t\t\t\tif (!snapshot.parentRuntime)\n\t\t\t\t\t\tthrow new Error(\"Pi launch requires the active parent runtime\");\n\t\t\t\t\tconst plans = resolveRuntimePlans(\n\t\t\t\t\t\ttask.runtime ?? {},\n\t\t\t\t\t\trole.defaults ?? {},\n\t\t\t\t\t\tsnapshot.parentRuntime,\n\t\t\t\t\t\tsnapshot.modelRegistry,\n\t\t\t\t\t);\n\t\t\t\t\tfor (const candidate of task.runtime?.fallbacks ?? [])\n\t\t\t\t\t\tplans.push(\n\t\t\t\t\t\t\tresolveRuntimePlan(\n\t\t\t\t\t\t\t\tcandidate,\n\t\t\t\t\t\t\t\trole.defaults ?? {},\n\t\t\t\t\t\t\t\tsnapshot.parentRuntime,\n\t\t\t\t\t\t\t\tsnapshot.modelRegistry,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\tconst [first, ...rest] = plans;\n\t\t\t\t\tif (!first) throw new Error(\"No resolved runtime plans\");\n\t\t\t\t\tconst id = randomUUID();\n\t\t\t\t\treturn prepare(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\trole,\n\t\t\t\t\t\t\tplans: [first, ...rest],\n\t\t\t\t\t\t\tresolved: {\n\t\t\t\t\t\t\t\tagent: role.name || undefined,\n\t\t\t\t\t\t\t\tcwd: task.cwd,\n\t\t\t\t\t\t\t\ttools: task.tools?.join(\",\"),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\tlogicalId: id,\n\t\t\t\t\t\t\t\tgenerationId: randomUUID(),\n\t\t\t\t\t\t\t\ttaskId: randomUUID(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsnapshot,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tasync resume(resumeOptions, task) {\n\t\t\t\t\tconst acquisition = { taskId: task.id, suppressed: false };\n\t\t\t\t\tstate.pending.add(acquisition);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst snapshot = state.options.getLaunchSnapshot();\n\t\t\t\t\t\tconst before = getNewEntries(resumeOptions.sessionId, 0);\n\t\t\t\t\t\tconst owner = adapter(snapshot);\n\t\t\t\t\t\tconst handle = await owner.resume(resumeOptions);\n\t\t\t\t\t\ttask.cwd = handle.cwd;\n\t\t\t\t\t\treturn acquired(\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\towner,\n\t\t\t\t\t\t\thandle,\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tbefore.length,\n\t\t\t\t\t\t\tacquisition.suppressed,\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tstate.pending.delete(acquisition);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\thooks: {\n\t\t\t\tasync onSpawned(_handle, task) {\n\t\t\t\t\tconst entry = entries.get(task.id)!;\n\t\t\t\t\tawait state.options.hooks.onSpawned?.(\n\t\t\t\t\t\tentry.record,\n\t\t\t\t\t\tentry.started,\n\t\t\t\t\t\ttask,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tonCancelState(handle, task, cancelState) {\n\t\t\t\t\t// The kernel owns the intent; project it onto whichever owner is\n\t\t\t\t\t// current, including one transferred after the cancel call.\n\t\t\t\t\tconst entry = entries.get(task.id);\n\t\t\t\t\tif (\n\t\t\t\t\t\tentry &&\n\t\t\t\t\t\tentry.record.id === handle.id &&\n\t\t\t\t\t\tentry.record.sessionFile === handle.sessionId\n\t\t\t\t\t)\n\t\t\t\t\t\tentry.record.cancelState = cancelState;\n\t\t\t\t},\n\t\t\t\tonObserved(_handle, _projection, observation) {\n\t\t\t\t\tconst entry = [...entries.values()].find(\n\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\te.record.id === _handle.id &&\n\t\t\t\t\t\t\te.record.sessionFile === _handle.sessionId,\n\t\t\t\t\t);\n\t\t\t\t\tif (entry) observed(entry.record, observation);\n\t\t\t\t},\n\t\t\t\tasync onSettled(result, task) {\n\t\t\t\t\tconst entry = entries.get(task.id)!;\n\t\t\t\t\t// Exhausted acquisition failures are attached by the generic kernel after\n\t\t\t\t\t// the last real attempt was finalized; preserve its original raw text.\n\t\t\t\t\tconst completed = { ...entry.completed!, run: result };\n\t\t\t\t\tif (result.evidence?.errorMessage !== undefined)\n\t\t\t\t\t\tcompleted.errorMessage = result.evidence.errorMessage;\n\t\t\t\t\tif (result.cancellation) {\n\t\t\t\t\t\t// A cancel can settle after a retryable attempt was finalized with\n\t\t\t\t\t\t// its natural error; present the run's actual cancelled outcome.\n\t\t\t\t\t\tcompleted.summary = \"Subagent cancelled.\";\n\t\t\t\t\t\tcompleted.summarySource = \"host\";\n\t\t\t\t\t\tcompleted.error = \"cancelled\";\n\t\t\t\t\t\tcompleted.exitCode = 1;\n\t\t\t\t\t\tcompleted.sessionFile = entry.record.sessionFile;\n\t\t\t\t\t\tcompleted.errorMessage = undefined;\n\t\t\t\t\t\tcompleted.ping = undefined;\n\t\t\t\t\t}\n\t\t\t\t\tentry.completed = completed;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst decision = await state.options.hooks.onSettled(\n\t\t\t\t\t\t\tentry.record,\n\t\t\t\t\t\t\tcompleted,\n\t\t\t\t\t\t\ttask,\n\t\t\t\t\t\t\tentry.readResumeResult\n\t\t\t\t\t\t\t\t? { ...io, readResumeResult: entry.readResumeResult }\n\t\t\t\t\t\t\t\t: io,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tentry.record.lifecycle = markDelivery(\n\t\t\t\t\t\t\tentry.record.lifecycle,\n\t\t\t\t\t\t\tdecision === \"suppressed\" ? \"suppressed\" : \"delivered\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn decision;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tentries.delete(task.id);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\t// Reserve through kernel.resume before any transcript read or adapter creation.\n\t\tresumePi = async (input) => {\n\t\t\tconst task: Task = {\n\t\t\t\tid: input.taskId,\n\t\t\t\tname: input.name,\n\t\t\t\tprompt: input.message ?? \"resumed session\",\n\t\t\t\trole: \"\",\n\t\t\t\tcwd: process.cwd(),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\treturn await kernel.resume({\n\t\t\t\t\ttask,\n\t\t\t\t\tname: input.name,\n\t\t\t\t\tsessionId: input.sessionPath,\n\t\t\t\t\tmessage: input.message,\n\t\t\t\t\tautoExit: input.autoExit,\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tprune(task.id);\n\t\t\t}\n\t\t};\n\t\tstate = {\n\t\t\tbinding,\n\t\t\toptions,\n\t\t\tkernel,\n\t\t\tentries,\n\t\t\tinfrastructure,\n\t\t\troles,\n\t\t\tpending,\n\t\t\tresumePi,\n\t\t\tworktreeOperations:\n\t\t\t\toptions.infrastructure?.worktreeOperations ??\n\t\t\t\toptions.infrastructure?.launchOperations.worktree ??\n\t\t\t\tcreateWorktreeOperations(),\n\t\t};\n\t}\n\t// Replacements must invoke the original kernel's invocation closure, which\n\t// reads this shared current binding, not the old facade's options.\n\tif (adopted) resumePi = state.resumePi;\n\t// Live markers and their sequence survive a reload with their runs.\n\tif (\n\t\tstate.binding.backend === \"legacy\" &&\n\t\t!state.infrastructure.surfaceProvider.nativeExecution\n\t)\n\t\tstate.markers ??= createDelegatedMarkers(options);\n\tconst acceptChecks = (state.acceptChecks ??= {\n\t\tlabel: \"parent run session\",\n\t});\n\n\tfunction prune(id: string) {\n\t\tif (!state.kernel.getTask(id)) state.entries.delete(id);\n\t}\n\tfunction live(id: string): PiEntry | undefined {\n\t\tprune(id);\n\t\treturn state.entries.get(id);\n\t}\n\tfunction record(id: string): PiRunRecord {\n\t\tconst value = live(id)?.record;\n\t\tif (!value) throw new Error(`Task \"${id}\" has no active Pi owner.`);\n\t\treturn value;\n\t}\n\tfunction hydrate(\n\t\tchild: PiRunRecord,\n\t\tat: number,\n\t\tkind: RunObservation[\"kind\"],\n\t): RunObservation {\n\t\tconst read = readSubagentActivityFile(child.activityFile, child.id);\n\t\tchild.lifecycle = observeActivity(child.lifecycle, read, at);\n\t\treturn {\n\t\t\tkind,\n\t\t\tobservedAt: at,\n\t\t\tlifecycle: child.lifecycle,\n\t\t\tprojection: projectLifecycle(child.lifecycle, at),\n\t\t\tactivity: read.ok ? read.activity : undefined,\n\t\t\tactivityRead: read,\n\t\t};\n\t}\n\tfunction observed(child: PiRunRecord, observation: RunObservation) {\n\t\tconst entry = [...state.entries.values()].find(\n\t\t\t(candidate) => candidate.record === child,\n\t\t);\n\t\tif (child.lifecycle.delivery === \"suppressed\" || !entry) return;\n\t\tentry.marker?.renew();\n\t\tif (observation.kind === \"local-evidence\" && child.persistent) {\n\t\t\ttry {\n\t\t\t\tstate.options.persistent.drain(child, io);\n\t\t\t} catch {\n\t\t\t\t/* unread event retries on a later wake */\n\t\t\t}\n\t\t}\n\t\tstate.options.hooks.onObserved?.(child, observation);\n\t}\n\tfunction launchOperations(snapshot: PiLaunchSnapshot): PiLaunchOperations {\n\t\treturn {\n\t\t\t...(state.options.infrastructure?.launchOperations ??\n\t\t\t\tlaunchOperationsFromSurface(\n\t\t\t\t\tstate.binding.backend === \"core\"\n\t\t\t\t\t\t? state.infrastructure.surfaceProvider\n\t\t\t\t\t\t: state.options.hostSurface!.createLaunchProvider(snapshot),\n\t\t\t\t\tsnapshot.paneConfig,\n\t\t\t\t)),\n\t\t\tworktree: state.worktreeOperations,\n\t\t};\n\t}\n\tfunction adapter(snapshot: PiLaunchSnapshot): PiHarnessAdapter {\n\t\treturn new PiHarnessAdapter({\n\t\t\tchildEntryPath: state.options.childEntryPath,\n\t\t\tsurface: state.infrastructure.surfaceProvider,\n\t\t\tpaneConfig: snapshot.paneConfig,\n\t\t\tmodelRegistry: snapshot.modelRegistry,\n\t\t\tparent: snapshot.parent,\n\t\t\tparentRuntime: snapshot.parentRuntime,\n\t\t\tsupervision: state.infrastructure.supervision,\n\t\t\tprocessProbe: state.infrastructure.processProbe,\n\t\t\toperations: launchOperations(snapshot),\n\t\t\tonObservation(child, kind) {\n\t\t\t\tconst at = Date.now();\n\t\t\t\t// Local evidence only drains events. Tick/refresh still hydrate fresh\n\t\t\t\t// activity; preserve the callback without another activity-file parse.\n\t\t\t\tobserved(\n\t\t\t\t\tchild,\n\t\t\t\t\tkind === \"local-evidence\"\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tobservedAt: at,\n\t\t\t\t\t\t\t\tlifecycle: child.lifecycle,\n\t\t\t\t\t\t\t\tprojection: projectLifecycle(child.lifecycle, at),\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: hydrate(child, at, kind),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t}\n\tfunction acquired(\n\t\ttask: Task,\n\t\towner: PiHarnessAdapter,\n\t\thandle: AgentHandle,\n\t\tattempts: string[],\n\t\tfailures: { model: string; error: string }[],\n\t\twarning?: string,\n\t\tcursor?: number,\n\t\tsuppressed = false,\n\t): OwnedRunAttempt {\n\t\tconst child = owner.getRunningChild(handle);\n\t\tconst entry: PiEntry = {\n\t\t\trecord: child,\n\t\t\tstarted: {\n\t\t\t\tid: child.id,\n\t\t\t\tname: child.name,\n\t\t\t\ttask: child.task,\n\t\t\t\tagent: child.agent,\n\t\t\t\tsessionFile: child.sessionFile,\n\t\t\t\tlaunchScriptFile: child.launchScriptFile,\n\t\t\t\tmodel: child.runtimePlan?.model,\n\t\t\t\tthinking: child.runtimePlan?.thinking,\n\t\t\t\truntimePlan: child.runtimePlan,\n\t\t\t\tworktree: child.worktree,\n\t\t\t\twarning,\n\t\t\t\tstatus: child.launchFailure ? \"uncertain\" : \"started\",\n\t\t\t\tlaunchFailure: child.launchFailure,\n\t\t\t},\n\t\t};\n\t\tif (suppressed)\n\t\t\tchild.lifecycle = markDelivery(child.lifecycle, \"suppressed\");\n\t\telse {\n\t\t\tentry.marker = state.markers?.attach(child);\n\t\t\tstate.entries.set(task.id, entry);\n\t\t}\n\t\treturn {\n\t\t\thandle,\n\t\t\tadapter: owner,\n\t\t\tpersistent: child.persistent ?? false,\n\t\t\tcloseTemporarySurface: child.ownsSurface\n\t\t\t\t? temporarySurfaceRelease(\n\t\t\t\t\t\tstate.infrastructure.surfaceProvider,\n\t\t\t\t\t\tchild.surface,\n\t\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tobserve: (at) => hydrate(child, at, \"refresh\"),\n\t\t\tfinalize: async (result, _task, control) => {\n\t\t\t\t// Clear before delivery; a retained worktree root keeps its pane.\n\t\t\t\tentry.marker?.retire();\n\t\t\t\tconst at = Date.now();\n\t\t\t\tlet evidence = result.evidence;\n\t\t\t\tif (evidence)\n\t\t\t\t\tchild.lifecycle = markCompletionDetected(\n\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\tat,\n\t\t\t\t\t);\n\t\t\t\t// A rejected adapter wait follows the shipped watch error result:\n\t\t\t\t// transcript I/O is not retried as part of presenting that failure.\n\t\t\t\tlet all: ReturnType<typeof getNewEntries> = [];\n\t\t\t\ttry {\n\t\t\t\t\tif (evidence && existsSync(child.sessionFile))\n\t\t\t\t\t\tall = getNewEntries(child.sessionFile, 0);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// This is Pi processing failure AFTER real adapter evidence, not a\n\t\t\t\t\t// provider error or a failed parent send. Normalize to the shipped\n\t\t\t\t\t// watch error result and settle once; no synthetic evidence/retry.\n\t\t\t\t\tresult = {\n\t\t\t\t\t\thandle: result.handle,\n\t\t\t\t\t\toutcome: \"failed\",\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tdurationMs: result.durationMs,\n\t\t\t\t\t};\n\t\t\t\t\tevidence = undefined;\n\t\t\t\t}\n\t\t\t\tconst exitCode = evidence?.exitCode ?? 1;\n\t\t\t\tconst observedRuntime = findObservedSessionRuntime(all);\n\t\t\t\tif (\n\t\t\t\t\tchild.runtimePlan &&\n\t\t\t\t\tobservedRuntime.provider &&\n\t\t\t\t\tobservedRuntime.modelId\n\t\t\t\t) {\n\t\t\t\t\tconst model = `${observedRuntime.provider}/${observedRuntime.modelId}`;\n\t\t\t\t\tconst thinking =\n\t\t\t\t\t\tobservedRuntime.thinking !== undefined &&\n\t\t\t\t\t\tisThinkingLevel(observedRuntime.thinking)\n\t\t\t\t\t\t\t? observedRuntime.thinking\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tconst plan: ResolvedRuntimePlan = {\n\t\t\t\t\t\t...child.runtimePlan,\n\t\t\t\t\t\tobserved: { model },\n\t\t\t\t\t};\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tplan.thinking = thinking;\n\t\t\t\t\t\tplan.observed!.thinking = thinking;\n\t\t\t\t\t}\n\t\t\t\t\tif (model !== plan.model)\n\t\t\t\t\t\tplan.runtimeMismatch = `Resolved model ${plan.model} but child reported ${model}`;\n\t\t\t\t\tchild.runtimePlan = plan;\n\t\t\t\t}\n\t\t\t\tconst { summary, summarySource }: AttributedSummary = evidence\n\t\t\t\t\t? (findLastAssistantSummary(\n\t\t\t\t\t\t\tcursor === undefined ? all : all.slice(cursor),\n\t\t\t\t\t\t) ?? {\n\t\t\t\t\t\t\tsummary: evidence.errorMessage\n\t\t\t\t\t\t\t\t? `Subagent error: ${evidence.errorMessage}`\n\t\t\t\t\t\t\t\t: exitCode === 0\n\t\t\t\t\t\t\t\t\t? cursor === undefined\n\t\t\t\t\t\t\t\t\t\t? \"Sub-agent exited without output\"\n\t\t\t\t\t\t\t\t\t\t: \"Resumed session exited without new output\"\n\t\t\t\t\t\t\t\t\t: `${cursor === undefined ? \"Sub-agent\" : \"Resumed session\"} exited with code ${exitCode}${evidence.exitOutput ? ` before its session started. Last output:\\n${evidence.exitOutput}` : \"\"}`,\n\t\t\t\t\t\t\t// Only a child-written sidecar error is child provenance.\n\t\t\t\t\t\t\tsummarySource: evidence.errorMessage\n\t\t\t\t\t\t\t\t? errorProvenance(evidence.errorSource)\n\t\t\t\t\t\t\t\t: \"host\",\n\t\t\t\t\t\t})\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tsummary:\n\t\t\t\t\t\t\t\tresult.outcome === \"killed\"\n\t\t\t\t\t\t\t\t\t? \"Subagent cancelled.\"\n\t\t\t\t\t\t\t\t\t: `Subagent error: ${result.error}`,\n\t\t\t\t\t\t\tsummarySource: \"host\",\n\t\t\t\t\t\t};\n\t\t\t\tlet worktree: PiWorktreeHandoff | undefined = child.worktree\n\t\t\t\t\t? await state.worktreeOperations.captureWorktreeHandoff(\n\t\t\t\t\t\t\tchild.worktree,\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined;\n\t\t\t\t// After the handoff capture, before the lifecycle and manifest marks:\n\t\t\t\t// the parent re-check decides the verdict (ADR-0017).\n\t\t\t\tconst accept = child.accept\n\t\t\t\t\t? await runParentAcceptCheck({\n\t\t\t\t\t\t\tspec: child.accept,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t\texitCode,\n\t\t\t\t\t\t\tcwd: child.cwd,\n\t\t\t\t\t\t\tworktree,\n\t\t\t\t\t\t\tcontrol,\n\t\t\t\t\t\t\trunner: state.infrastructure.acceptRunner ?? runAcceptCommand,\n\t\t\t\t\t\t\towner: acceptChecks,\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\t\t// A cancel that won during the re-check, with termination confirmed,\n\t\t\t\t// delivers the cancelled result: the kernel says so, not the check.\n\t\t\t\tconst cancelledInCheck =\n\t\t\t\t\t!result.cancellation && control.interruption() === \"cancelled\";\n\t\t\t\tif (child.worktree && worktree) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Only confirmed termination is a cancellation. Shutdown suppression\n\t\t\t\t\t\t// of an unconfirmed cancel records what a plain shutdown would. A\n\t\t\t\t\t\t// rejected verdict leaves the manifest state unchanged.\n\t\t\t\t\t\tstate.worktreeOperations.persistWorktreeResult(\n\t\t\t\t\t\t\tchild.worktree,\n\t\t\t\t\t\t\tresult.cancellation?.termination === \"confirmed\" ||\n\t\t\t\t\t\t\t\tcancelledInCheck\n\t\t\t\t\t\t\t\t? \"cancelled\"\n\t\t\t\t\t\t\t\t: worktreeResultState(exitCode, !!evidence?.ping),\n\t\t\t\t\t\t\tworktree,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tworktree = {\n\t\t\t\t\t\t\t...worktree,\n\t\t\t\t\t\t\tgitError: [\n\t\t\t\t\t\t\t\tworktree.gitError,\n\t\t\t\t\t\t\t\t`Manifest update failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t.join(\"; \"),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tchild.lifecycle =\n\t\t\t\t\texitCode === 0 && !cancelledInCheck\n\t\t\t\t\t\t? markCompleted(child.lifecycle, at)\n\t\t\t\t\t\t: markFailed(\n\t\t\t\t\t\t\t\tchild.lifecycle,\n\t\t\t\t\t\t\t\tcancelledInCheck ? \"Subagent cancelled.\" : summary,\n\t\t\t\t\t\t\t\tat,\n\t\t\t\t\t\t\t\tcancelledInCheck ? 1 : exitCode,\n\t\t\t\t\t\t\t);\n\t\t\t\tif (evidence?.errorMessage)\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tmodel: child.runtimePlan?.model ?? attempts.at(-1)!,\n\t\t\t\t\t\terror: evidence.errorMessage,\n\t\t\t\t\t});\n\t\t\t\tentry.completed = {\n\t\t\t\t\trun: result,\n\t\t\t\t\tname: child.name,\n\t\t\t\t\ttask: child.task,\n\t\t\t\t\tagent: child.agent,\n\t\t\t\t\tsummary,\n\t\t\t\t\tsummarySource,\n\t\t\t\t\tsessionFile:\n\t\t\t\t\t\tevidence || result.outcome === \"killed\"\n\t\t\t\t\t\t\t? child.sessionFile\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\texitCode,\n\t\t\t\t\telapsed: Math.floor((at - child.startTime) / 1000),\n\t\t\t\t\terror: evidence\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: result.outcome === \"killed\"\n\t\t\t\t\t\t\t? \"cancelled\"\n\t\t\t\t\t\t\t: result.error,\n\t\t\t\t\terrorMessage: evidence?.errorMessage,\n\t\t\t\t\tping: evidence?.ping,\n\t\t\t\t\t// The watch catch omits its result plan; the host still reports the\n\t\t\t\t\t// live child's plan in structured details, not in the error summary.\n\t\t\t\t\truntimePlan: evidence ? child.runtimePlan : undefined,\n\t\t\t\t\tworktree,\n\t\t\t\t\taccept,\n\t\t\t\t\tlogicalId: child.logicalId,\n\t\t\t\t\tgenerationId: child.generationId,\n\t\t\t\t\tpolicyHash: child.policyHash,\n\t\t\t\t};\n\t\t\t\tif (state.options.outcomeLedger !== false)\n\t\t\t\t\tappendOutcomeLedger(outcomeLedgerFile(state.options.configDir), {\n\t\t\t\t\t\tat,\n\t\t\t\t\t\trunId: child.id,\n\t\t\t\t\t\tattempt: Math.max(1, attempts.length),\n\t\t\t\t\t\trole: child.agent,\n\t\t\t\t\t\trequestedModel:\n\t\t\t\t\t\t\ttask.requestedModel ?? child.runtimePlan?.requestedModel,\n\t\t\t\t\t\tmodel:\n\t\t\t\t\t\t\tchild.runtimePlan?.observed?.model ?? child.runtimePlan?.model,\n\t\t\t\t\t\tthinking: child.runtimePlan?.thinking,\n\t\t\t\t\t\telapsedSec: entry.completed.elapsed,\n\t\t\t\t\t\toutcome: ledgerOutcome(\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tevidence,\n\t\t\t\t\t\t\texitCode,\n\t\t\t\t\t\t\tcancelledInCheck,\n\t\t\t\t\t\t),\n\t\t\t\t\t\taccept,\n\t\t\t\t\t});\n\t\t\t\tif (cursor !== undefined)\n\t\t\t\t\tentry.readResumeResult = resumeResultReader(\n\t\t\t\t\t\tchild.sessionFile,\n\t\t\t\t\t\tcursor,\n\t\t\t\t\t\texitCode,\n\t\t\t\t\t\tevidence?.errorMessage,\n\t\t\t\t\t\tevidence?.errorSource,\n\t\t\t\t\t);\n\t\t\t\tif (cursor === undefined) {\n\t\t\t\t\tentry.completed.fallbackAttempts = attempts;\n\t\t\t\t\tentry.completed.fallbackFailures = failures;\n\t\t\t\t}\n\t\t\t\treturn worktree && evidence\n\t\t\t\t\t? { ...result, evidence: { ...evidence, worktree } }\n\t\t\t\t\t: result;\n\t\t\t},\n\t\t};\n\t}\n\tfunction prepare(\n\t\tinput: PiLaunchInput,\n\t\tsnapshot?: PiLaunchSnapshot,\n\t): PreparedRun {\n\t\tconst attempts: string[] = [];\n\t\tconst failures: { model: string; error: string }[] = [];\n\t\tlet publicId: string | undefined;\n\t\tlet logicalId: string | undefined;\n\t\tlet capturedSnapshot = snapshot;\n\t\treturn {\n\t\t\trole: input.role,\n\t\t\tpersistent:\n\t\t\t\tinput.task.behavior?.persistent ??\n\t\t\t\tinput.role.defaults?.persistent ??\n\t\t\t\tfalse,\n\t\t\tcandidates: input.plans,\n\t\t\tasync spawnAttempt(_spawn: SpawnOptions, index, cancelled) {\n\t\t\t\tconst plan = input.plans[index];\n\t\t\t\tattempts.push(plan.model);\n\t\t\t\tconst acquisition = { taskId: input.task.id, suppressed: false };\n\t\t\t\tstate.pending.add(acquisition);\n\t\t\t\tlet spawning = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst current = (await input.prepareAttempt?.(index, cancelled)) ?? {\n\t\t\t\t\t\t...input,\n\t\t\t\t\t\tsnapshot: (capturedSnapshot ??= state.options.getLaunchSnapshot()),\n\t\t\t\t\t};\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent.task.id !== input.task.id ||\n\t\t\t\t\t\tcurrent.task.prompt !== input.task.prompt ||\n\t\t\t\t\t\tJSON.stringify(current.task.worktree) !==\n\t\t\t\t\t\t\tJSON.stringify(input.task.worktree)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\"Pi attempt preparation changed the invocation identity, prompt or worktree.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t// A candidate was authorized at planning time; the scope may have\n\t\t\t\t\t// changed since. Re-check it against this attempt's snapshot, which\n\t\t\t\t\t// prepareAttempt rebuilds from the live parent for every attempt.\n\t\t\t\t\tassertModelInScope(plan.model, current.snapshot.modelRegistry);\n\t\t\t\t\tconst owner = adapter(current.snapshot);\n\t\t\t\t\tspawning = true;\n\t\t\t\t\tconst handle = await owner.spawn({\n\t\t\t\t\t\tacquisitionSignal: cancelled,\n\t\t\t\t\t\tname: input.task.name,\n\t\t\t\t\t\ttask: input.task.prompt,\n\t\t\t\t\t\tcwd: current.task.cwd,\n\t\t\t\t\t\tsessionId: current.snapshot.parent.sessionId,\n\t\t\t\t\t\trole: current.role,\n\t\t\t\t\t\tenv: current.task.env,\n\t\t\t\t\t\tsession: current.task.session,\n\t\t\t\t\t\tbehavior: current.task.behavior,\n\t\t\t\t\t\ttools: current.task.tools,\n\t\t\t\t\t\tsystemPrompt: current.resolved.agent\n\t\t\t\t\t\t\t? current.role.systemPrompt\n\t\t\t\t\t\t\t: current.task.systemPrompt,\n\t\t\t\t\t\tsurface: input.surface,\n\t\t\t\t\t\tworktreeRequest: input.task.worktree,\n\t\t\t\t\t\taccept: input.task.accept,\n\t\t\t\t\t\truntime: { model: plan.model, thinking: plan.thinking },\n\t\t\t\t\t\tresolvedLaunch: { ...current.resolved, runtimePlan: plan },\n\t\t\t\t\t\tlaunchIdentity: {\n\t\t\t\t\t\t\t...current.identity,\n\t\t\t\t\t\t\tid: publicId ?? current.identity.id,\n\t\t\t\t\t\t\tlogicalId: logicalId ?? current.identity.logicalId,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tpublicId = handle.id;\n\t\t\t\t\tlogicalId ??= current.identity.logicalId;\n\t\t\t\t\treturn acquired(\n\t\t\t\t\t\tinput.task,\n\t\t\t\t\t\towner,\n\t\t\t\t\t\thandle,\n\t\t\t\t\t\tattempts,\n\t\t\t\t\t\tfailures,\n\t\t\t\t\t\tinput.warning,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tacquisition.suppressed,\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (cancelled.aborted && !spawning) {\n\t\t\t\t\t\t// Cancelled while preparing: the candidate neither launched nor failed.\n\t\t\t\t\t\tattempts.pop();\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tmodel: plan.model,\n\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t});\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tstate.pending.delete(acquisition);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\tconst io = createPiPersistentIO(state);\n\tconst facade: PiRunSession = {\n\t\t...state.kernel,\n\t\tasync handoffWorktree(input) {\n\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\t// This is a long-lived interactive handoff, deliberately outside the\n\t\t\t// watched kernel: no task reservation, acquire, producer or watcher.\n\t\t\tconst snapshot = input.snapshot;\n\t\t\tconst result = await launchPiWorktreeHandoff(\n\t\t\t\t{\n\t\t\t\t\tkind: \"fresh\",\n\t\t\t\t\tname: input.name,\n\t\t\t\t\ttask: input.task,\n\t\t\t\t\tcwd: snapshot.parent.cwd,\n\t\t\t\t\tworktree: { branch: input.branch },\n\t\t\t\t\thandoff: { leafId: input.leafId },\n\t\t\t\t\tparent: { ...snapshot.parent },\n\t\t\t\t\truntimePlan: input.runtimePlan,\n\t\t\t\t\tmodelScope: snapshot.modelRegistry.scope,\n\t\t\t\t\tbehavior: {\n\t\t\t\t\t\tdeniedTools: [],\n\t\t\t\t\t\tautoExit: false,\n\t\t\t\t\t\tinteractive: true,\n\t\t\t\t\t\tsessionMode: \"standalone\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlaunchOperations(snapshot),\n\t\t\t);\n\t\t\treturn { record: result.running, focusError: result.focusError };\n\t\t},\n\t\tcreateWorktreeCleanupOperations: (input) => {\n\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\tif (state.infrastructure.surfaceProvider.nativeExecution)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Managed worktree cleanup is not supported by Herdr Core\",\n\t\t\t\t);\n\t\t\treturn createWorktreeCleanupOperations(\n\t\t\t\tstate.infrastructure.surfaceProvider,\n\t\t\t\tinput,\n\t\t\t);\n\t\t},\n\t\tmanagedWorktreeRefusal: () =>\n\t\t\tmanagedWorktreeRefusal(state.options.platform),\n\t\tasync spawnPi(input) {\n\t\t\t// Refuse before the kernel reserves the task or any attempt starts.\n\t\t\tif (input.task.worktree)\n\t\t\t\tassertManagedWorktreesSupported(state.options.platform);\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.spawn(input.task, prepare(input));\n\t\t\t} finally {\n\t\t\t\tprune(input.task.id);\n\t\t\t}\n\t\t},\n\t\tresumePi: (input) => resumePi(input),\n\t\tasync supervise(handle, task, signal) {\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.supervise(handle, task, signal);\n\t\t\t} finally {\n\t\t\t\tprune(task.id);\n\t\t\t}\n\t\t},\n\t\tgetRecord: (id) => live(id)?.record,\n\t\tgetStarted: (id) => live(id)?.started,\n\t\tgetCompleted: (id) => live(id)?.completed,\n\t\tgetControlTaskId(publicId) {\n\t\t\tfor (const [id, entry] of state.entries)\n\t\t\t\tif (live(id) && entry.record.id === publicId) return id;\n\t\t\treturn undefined;\n\t\t},\n\t\tsuppress(id) {\n\t\t\tfor (const acquisition of state.pending)\n\t\t\t\tif (acquisition.taskId === id) acquisition.suppressed = true;\n\t\t\tconst suppressed = live(id);\n\t\t\tconst r = suppressed?.record;\n\t\t\tif (r) r.lifecycle = markDelivery(r.lifecycle, \"suppressed\");\n\t\t\t// Nothing renews an unsupervised run's marker; clear it now.\n\t\t\tsuppressed?.marker?.retire();\n\t\t\tstate.kernel.suppress(id);\n\t\t\tstate.entries.delete(id);\n\t\t},\n\t\tasync cancel(id) {\n\t\t\t// The kernel records the intent and projects every owner's cancel state\n\t\t\t// through onCancelState; a natural result taken first keeps its own.\n\t\t\ttry {\n\t\t\t\treturn await state.kernel.cancel(id);\n\t\t\t} finally {\n\t\t\t\tprune(id);\n\t\t\t}\n\t\t},\n\t\tasync sendPersistent(id, text) {\n\t\t\treturn state.options.persistent.send(record(id), text, io);\n\t\t},\n\t\tasync stopPersistent(id, timeoutMs = 15_000) {\n\t\t\treturn state.options.persistent.stop(record(id), timeoutMs, io);\n\t\t},\n\t\tasync send(id, text) {\n\t\t\tconst ack = await facade.sendPersistent(id, text);\n\t\t\tif (\"error\" in ack) throw new Error(ack.error);\n\t\t},\n\t\tavailability: () => ({\n\t\t\tavailable: state.infrastructure.surfaceProvider.isAvailable(),\n\t\t\tsetupHint: state.infrastructure.surfaceProvider.setupHint(),\n\t\t}),\n\t\tlistWorktreeSurfaces: (opts) =>\n\t\t\tstate.infrastructure.surfaceProvider.listWorktreeSurfaces(opts),\n\t\tinspectProgress(id) {\n\t\t\tconst r = record(id);\n\t\t\tlet updatedAt: number | undefined;\n\t\t\ttry {\n\t\t\t\tupdatedAt = statSync(r.sessionFile).mtimeMs;\n\t\t\t} catch {\n\t\t\t\t/* unavailable */\n\t\t\t}\n\t\t\treturn { ...inspectNoProgressSessionTail(r.sessionFile), updatedAt };\n\t\t},\n\t\tdiagnostics: () => state.infrastructure.supervision.diagnostics(),\n\t\tasync shutdown(reason) {\n\t\t\tif (![\"reload\", \"new\", \"resume\", \"fork\"].includes(reason ?? \"\")) {\n\t\t\t\tfor (const id of new Set([\n\t\t\t\t\t...state.entries.keys(),\n\t\t\t\t\t...[...state.pending].map((a) => a.taskId),\n\t\t\t\t]))\n\t\t\t\t\tfacade.suppress(id);\n\t\t\t\tstate.infrastructure.supervision.close();\n\t\t\t\t// Suppression aborted their re-checks; finish what ignores SIGTERM.\n\t\t\t\tawait terminateAcceptChecks(acceptChecks);\n\t\t\t}\n\t\t},\n\t};\n\tObject.defineProperty(facade, OWNER, { value: state });\n\treturn facade;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubl/maestro",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Harness-neutral subagent engine extracted from pi-herdr-agents: the generic run owner, Pi adapters/runtime with explicit host ports, and the Pi tool surface behind createPiExtension.",
5
5
  "license": "MIT",
6
6
  "type": "module",