@draht/coding-agent 2026.10.4-3 → 2026.10.8-1
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.
- package/CHANGELOG.md +13 -0
- package/README.md +32 -6
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/{chunk-JTLUBTZT.js → chunk-6QIFWMDF.js} +1 -1
- package/dist/bundle/chunks/{chunk-AFL4IDSI.js → chunk-AHGUOQPH.js} +2 -2
- package/dist/bundle/chunks/{chunk-VPYAVQLP.js → chunk-BOGY4QVF.js} +4 -4
- package/dist/bundle/chunks/chunk-GD2WVXWT.js +65 -0
- package/dist/bundle/chunks/{chunk-3HF756LN.js → chunk-KJJJSTND.js} +292 -153
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +107 -0
- package/dist/bundle/chunks/chunk-QVFELZW2.js +312 -0
- package/dist/bundle/chunks/{chunk-V5HG6S2T.js → chunk-QVTLBSTH.js} +1 -1
- package/dist/bundle/chunks/{chunk-A4OX5CPR.js → chunk-U6LDZZGM.js} +1 -1
- package/dist/bundle/chunks/{chunk-XO3IECI5.js → chunk-VQOV5VFH.js} +1 -1
- package/dist/bundle/chunks/{cli-L74YA5GF.js → cli-O6OWCY7N.js} +1 -1
- package/dist/bundle/chunks/execute-4JU5WQXP.js +18 -0
- package/dist/bundle/chunks/google-antigravity.js +1 -1
- package/dist/bundle/chunks/google-gemini-cli.js +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/openrouter.js +1 -1
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-RYUR6LRB.js → runtime-FIGQHW75.js} +1 -1
- package/dist/bundle/chunks/runtime-TJ3EAMJK.js +3 -0
- package/dist/bundle/chunks/{settings-manager-CHEMMAGQ.js → settings-manager-HC5RR36T.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-UIGTRGHQ.js +2 -0
- package/dist/bundle/chunks/xai.js +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.js +3 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +5 -2
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +65 -27
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +2 -0
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts +15 -0
- package/dist/core/builtins/polyphase.d.ts.map +1 -0
- package/dist/core/builtins/polyphase.js +196 -0
- package/dist/core/builtins/polyphase.js.map +1 -0
- package/dist/core/builtins/subagent.d.ts +44 -34
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +827 -560
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/types.d.ts +17 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +30 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-resolver.js +4 -4
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -1
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +35 -0
- package/dist/core/polyphase/approval.d.ts.map +1 -0
- package/dist/core/polyphase/approval.js +184 -0
- package/dist/core/polyphase/approval.js.map +1 -0
- package/dist/core/polyphase/child-events.d.ts +107 -0
- package/dist/core/polyphase/child-events.d.ts.map +1 -0
- package/dist/core/polyphase/child-events.js +862 -0
- package/dist/core/polyphase/child-events.js.map +1 -0
- package/dist/core/polyphase/child-process.d.ts +65 -0
- package/dist/core/polyphase/child-process.d.ts.map +1 -0
- package/dist/core/polyphase/child-process.js +361 -0
- package/dist/core/polyphase/child-process.js.map +1 -0
- package/dist/core/polyphase/commands.d.ts +44 -0
- package/dist/core/polyphase/commands.d.ts.map +1 -0
- package/dist/core/polyphase/commands.js +244 -0
- package/dist/core/polyphase/commands.js.map +1 -0
- package/dist/core/polyphase/details.d.ts +40 -0
- package/dist/core/polyphase/details.d.ts.map +1 -0
- package/dist/core/polyphase/details.js +538 -0
- package/dist/core/polyphase/details.js.map +1 -0
- package/dist/core/polyphase/emitter.d.ts +20 -0
- package/dist/core/polyphase/emitter.d.ts.map +1 -0
- package/dist/core/polyphase/emitter.js +90 -0
- package/dist/core/polyphase/emitter.js.map +1 -0
- package/dist/core/polyphase/jsonl-reader.d.ts +31 -0
- package/dist/core/polyphase/jsonl-reader.d.ts.map +1 -0
- package/dist/core/polyphase/jsonl-reader.js +161 -0
- package/dist/core/polyphase/jsonl-reader.js.map +1 -0
- package/dist/core/polyphase/keyword.d.ts +27 -0
- package/dist/core/polyphase/keyword.d.ts.map +1 -0
- package/dist/core/polyphase/keyword.js +97 -0
- package/dist/core/polyphase/keyword.js.map +1 -0
- package/dist/core/polyphase/limiter.d.ts +38 -0
- package/dist/core/polyphase/limiter.d.ts.map +1 -0
- package/dist/core/polyphase/limiter.js +129 -0
- package/dist/core/polyphase/limiter.js.map +1 -0
- package/dist/core/polyphase/model-selection.d.ts +35 -0
- package/dist/core/polyphase/model-selection.d.ts.map +1 -0
- package/dist/core/polyphase/model-selection.js +72 -0
- package/dist/core/polyphase/model-selection.js.map +1 -0
- package/dist/core/polyphase/render/format.d.ts +52 -0
- package/dist/core/polyphase/render/format.d.ts.map +1 -0
- package/dist/core/polyphase/render/format.js +169 -0
- package/dist/core/polyphase/render/format.js.map +1 -0
- package/dist/core/polyphase/render/renderers.d.ts +63 -0
- package/dist/core/polyphase/render/renderers.d.ts.map +1 -0
- package/dist/core/polyphase/render/renderers.js +277 -0
- package/dist/core/polyphase/render/renderers.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts +45 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -0
- package/dist/core/polyphase/render/run-block.js +843 -0
- package/dist/core/polyphase/render/run-block.js.map +1 -0
- package/dist/core/polyphase/render/snapshot.d.ts +106 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -0
- package/dist/core/polyphase/render/snapshot.js +292 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -0
- package/dist/core/polyphase/result-text.d.ts +41 -0
- package/dist/core/polyphase/result-text.d.ts.map +1 -0
- package/dist/core/polyphase/result-text.js +326 -0
- package/dist/core/polyphase/result-text.js.map +1 -0
- package/dist/core/polyphase/session.d.ts +33 -0
- package/dist/core/polyphase/session.d.ts.map +1 -0
- package/dist/core/polyphase/session.js +106 -0
- package/dist/core/polyphase/session.js.map +1 -0
- package/dist/core/polyphase/settings.d.ts +18 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -0
- package/dist/core/polyphase/settings.js +93 -0
- package/dist/core/polyphase/settings.js.map +1 -0
- package/dist/core/polyphase/store.d.ts +197 -0
- package/dist/core/polyphase/store.d.ts.map +1 -0
- package/dist/core/polyphase/store.js +558 -0
- package/dist/core/polyphase/store.js.map +1 -0
- package/dist/core/polyphase/types.d.ts +371 -0
- package/dist/core/polyphase/types.d.ts.map +1 -0
- package/dist/core/polyphase/types.js +36 -0
- package/dist/core/polyphase/types.js.map +1 -0
- package/dist/core/polyphase/ui/controller.d.ts +28 -0
- package/dist/core/polyphase/ui/controller.d.ts.map +1 -0
- package/dist/core/polyphase/ui/controller.js +150 -0
- package/dist/core/polyphase/ui/controller.js.map +1 -0
- package/dist/core/polyphase/ui/dock.d.ts +27 -0
- package/dist/core/polyphase/ui/dock.d.ts.map +1 -0
- package/dist/core/polyphase/ui/dock.js +121 -0
- package/dist/core/polyphase/ui/dock.js.map +1 -0
- package/dist/core/polyphase/ui/inspector.d.ts +117 -0
- package/dist/core/polyphase/ui/inspector.d.ts.map +1 -0
- package/dist/core/polyphase/ui/inspector.js +1016 -0
- package/dist/core/polyphase/ui/inspector.js.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts +55 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.js +210 -0
- package/dist/core/polyphase/ui/transcript-layout.js.map +1 -0
- package/dist/core/polyphase/update-pump.d.ts +18 -0
- package/dist/core/polyphase/update-pump.d.ts.map +1 -0
- package/dist/core/polyphase/update-pump.js +132 -0
- package/dist/core/polyphase/update-pump.js.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts +26 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.js +187 -0
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -0
- package/dist/core/polyphase/workflow/guidance.d.ts +19 -0
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/guidance.js +119 -0
- package/dist/core/polyphase/workflow/guidance.js.map +1 -0
- package/dist/core/polyphase/workflow/launch.d.ts +41 -0
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/launch.js +173 -0
- package/dist/core/polyphase/workflow/launch.js.map +1 -0
- package/dist/core/polyphase/workflow/meta.d.ts +43 -0
- package/dist/core/polyphase/workflow/meta.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/meta.js +529 -0
- package/dist/core/polyphase/workflow/meta.js.map +1 -0
- package/dist/core/polyphase/workflow/prelude.d.ts +24 -0
- package/dist/core/polyphase/workflow/prelude.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/prelude.js +93 -0
- package/dist/core/polyphase/workflow/prelude.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +79 -0
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.js +217 -0
- package/dist/core/polyphase/workflow/runtime.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js.map +1 -0
- package/dist/core/polyphase/workflow/saved.d.ts +55 -0
- package/dist/core/polyphase/workflow/saved.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/saved.js +299 -0
- package/dist/core/polyphase/workflow/saved.js.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts +22 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.js +66 -0
- package/dist/core/polyphase/workflow/structured-output.js.map +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts +24 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/tool.js +139 -0
- package/dist/core/polyphase/workflow/tool.js.map +1 -0
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +27 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/socket-server/permission-relay.js +4 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -1
- package/dist/core/trust-manager.d.ts +3 -2
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +5 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/experimental/micro/runtime.js +1 -1
- package/dist/experimental/micro/runtime.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +18 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +11 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +9 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +7 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/docs.json +4 -0
- package/docs/duet.md +3 -3
- package/docs/environment-variables.md +11 -0
- package/docs/json.md +7 -0
- package/docs/keybindings.md +20 -0
- package/docs/polyphase.md +391 -0
- package/docs/rpc-commands.md +9 -9
- package/docs/settings.md +12 -0
- package/docs/virtual-models.md +3 -3
- package/examples/extensions/preset.ts +3 -3
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +1 -1
- package/examples/extensions/subagent/agents/worker.md +1 -1
- package/examples/extensions/summarize.ts +3 -3
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/package.json +10 -10
- package/prompts/commands/orchestrate.md +1 -1
- package/dist/bundle/chunks/chunk-SPZUYYP5.js +0 -170
- package/dist/bundle/chunks/execute-EMOVNTD6.js +0 -328
- package/dist/bundle/chunks/virtual-modules-OC56AAJ7.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../../src/core/polyphase/render/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAiGvE,SAAS,WAAW;IACnB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,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otFromRun`)\n * or from persisted details (`snapshotFromDetails`). `render/run-block.ts` (P9) and `ui/inspector.ts`\n * (P10) consume only this snapshot, never `RunView`/`AgentView` or `PolyphaseDetails` directly, so the\n * same layout code renders live and archived runs identically.\n */\n\nimport type { ThinkingLevel } from \"@draht/agent-core\";\nimport { billableTokens, extractStatusLine } from \"../child-events.ts\";\nimport type { LimiterStats } from \"../limiter.ts\";\nimport type {\n\tAgentDetails,\n\tAgentStatus,\n\tAgentView,\n\tCancelReason,\n\tChildAgentState,\n\tModelSource,\n\tPhaseDetails,\n\tPhaseInfo,\n\tPolyphaseDetails,\n\tRunKind,\n\tRunOrigin,\n\tRunStatus,\n\tRunView,\n\tSubagentMode,\n\tTranscriptItem,\n\tWorkflowSource,\n} from \"../types.ts\";\n\nexport interface PhaseSnapshot {\n\tindex: number;\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n\tdynamic: boolean;\n\tstatus: \"pending\" | \"running\" | \"done\" | \"failed\";\n\tagentIdx: number[];\n\tdone: number;\n\ttotal: number;\n\telapsedMs?: number;\n\t/** True when `done`/`total` are computed from a subset of agents (archived details with\n\t * `agentsOmitted`), so they must not be read as the phase's true totals. See `RunSnapshot.agentsOmitted`\n\t * for the omitted count. */\n\tincomplete?: boolean;\n}\n\nexport interface AgentSnapshotRow {\n\ti: number;\n\tlabel: string;\n\tagentType: string;\n\tphase?: number;\n\tstep?: number;\n\tstatus: AgentStatus;\n\tcancelReason?: CancelReason;\n\tprovider?: string;\n\tmodelId?: string;\n\tmodelText?: string;\n\tthinking?: ThinkingLevel;\n\tmodelSource?: ModelSource;\n\tmodelConfirmed?: boolean;\n\telapsedMs?: number;\n\tturns: number;\n\ttoolCalls: number;\n\ttools?: Record<string, number>;\n\ttokens: number;\n\tcost: number;\n\tblocked: number;\n\tblockedSample?: string;\n\ttask: string;\n\tnow?: string;\n\tstatusLine?: string;\n\toutput?: string;\n\terror?: string;\n\tmerge?: \"ok\" | \"failed\";\n\t/** Live only: the newest `tailItems` transcript items (references, not copies). */\n\ttail?: readonly TranscriptItem[];\n}\n\nexport interface RunSnapshot {\n\trunId: string;\n\tkind: RunKind;\n\torigin: RunOrigin;\n\tmode?: SubagentMode;\n\ttitle: string;\n\tstatus: RunStatus;\n\tlive: boolean;\n\tstartedAt: number;\n\telapsedMs: number;\n\tcounts: Record<AgentStatus, number>;\n\ttokens: number;\n\tcost: number;\n\tbudget?: { totalTokens: number; spentTokens: number; exhausted: boolean };\n\tworkflow?: { name: string; description: string; source: WorkflowSource; args?: string };\n\tphases: PhaseSnapshot[];\n\tcurrentPhase?: number;\n\tagents: AgentSnapshotRow[];\n\tagentsOmitted?: { count: number; byStatus: Partial<Record<AgentStatus, number>> };\n\tlog: string[];\n\tresultPreview?: string;\n\terror?: string;\n\tblockedToolCalls: number;\n\tlimiter?: LimiterStats;\n\tversion: number;\n}\n\nfunction emptyCounts(): Record<AgentStatus, number> {\n\treturn { pending: 0, queued: 0, starting: 0, running: 0, done: 0, failed: 0, cancelled: 0, skipped: 0 };\n}\n\nconst ACTIVE_STATUSES: readonly AgentStatus[] = [\"running\", \"starting\"];\nconst FINISHED_STATUSES: readonly AgentStatus[] = [\"done\", \"failed\", \"cancelled\", \"skipped\"];\n\nfunction isActive(status: AgentStatus): boolean {\n\treturn ACTIVE_STATUSES.includes(status);\n}\n\nfunction isFinished(status: AgentStatus): boolean {\n\treturn FINISHED_STATUSES.includes(status);\n}\n\nfunction firstLine(text: string): string {\n\tconst idx = text.indexOf(\"\\n\");\n\treturn idx === -1 ? text : text.slice(0, idx);\n}\n\nfunction splitModel(model: string | undefined): { provider?: string; id?: string } {\n\tif (!model) return {};\n\tconst slash = model.indexOf(\"/\");\n\tif (slash === -1) return { id: model };\n\treturn { provider: model.slice(0, slash), id: model.slice(slash + 1) };\n}\n\n/**\n * Implements DESIGN §11.1's phase status rules, plus two deliberate extra rules the design's\n * unordered rule list leaves ambiguous (both pinned by tests in render-snapshot.test.ts):\n * 1. **Precedence is failed > done > running > pending.** A non-current phase whose agents all\n * finished with at least one failure reads \"failed\", not \"done\", because that is the more\n * actionable signal.\n * 2. **A non-current phase with some finished and some not-yet-started (queued/pending) agents,\n * but none active, reads \"running\" rather than falling through to \"pending\".** \"Pending\" is\n * reserved for phases where no agent has made any progress yet; partial progress should not\n * look identical to \"not started\".\n */\nfunction phaseStatusFor(agentRows: readonly AgentSnapshotRow[], isCurrent: boolean): PhaseSnapshot[\"status\"] {\n\tconst total = agentRows.length;\n\tconst anyActive = agentRows.some((row) => isActive(row.status));\n\tconst anyFinished = agentRows.some((row) => isFinished(row.status));\n\tconst allFinished = total > 0 && agentRows.every((row) => isFinished(row.status));\n\tconst anyFailed = agentRows.some((row) => row.status === \"failed\");\n\tif (anyFailed && !anyActive) return \"failed\";\n\tif (allFinished && !isCurrent) return \"done\";\n\tif (isCurrent || anyActive) return \"running\";\n\tif (anyFinished) return \"running\";\n\treturn \"pending\";\n}\n\nfunction phaseElapsedMs(agentRows: readonly AgentSnapshotRow[]): number | undefined {\n\tconst withElapsed = agentRows.map((row) => row.elapsedMs).filter((ms): ms is number => ms !== undefined);\n\tif (withElapsed.length === 0) return undefined;\n\treturn Math.max(...withElapsed);\n}\n\nfunction boundedTail(items: readonly TranscriptItem[], tailItems: number): readonly TranscriptItem[] {\n\treturn tailItems > 0 ? items.slice(-tailItems) : [];\n}\n\nfunction buildPhaseSnapshots(\n\tphases: readonly { title: string; detail?: string; model?: string; dynamic: boolean }[],\n\tagents: readonly AgentSnapshotRow[],\n\tcurrentPhase: number | undefined,\n\tincomplete = false,\n): PhaseSnapshot[] {\n\treturn phases.map((phase, index) => {\n\t\tconst agentRows = agents.filter((row) => row.phase === index);\n\t\tconst agentIdx = agentRows.map((row) => row.i);\n\t\tconst done = agentRows.filter((row) => row.status === \"done\").length;\n\t\treturn {\n\t\t\tindex,\n\t\t\ttitle: phase.title,\n\t\t\tdetail: phase.detail,\n\t\t\tmodel: phase.model,\n\t\t\tdynamic: phase.dynamic,\n\t\t\tstatus: phaseStatusFor(agentRows, currentPhase === index),\n\t\t\tagentIdx,\n\t\t\tdone,\n\t\t\ttotal: agentRows.length,\n\t\t\telapsedMs: phaseElapsedMs(agentRows),\n\t\t\t...(incomplete ? { incomplete: true } : {}),\n\t\t};\n\t});\n}\n\nfunction rowFromAgentView(agent: AgentView, now: number, tailItems: number): AgentSnapshotRow {\n\tconst state: Readonly<ChildAgentState> = agent.state;\n\tconst tokens = billableTokens(state.usage) + billableTokens(state.liveUsage);\n\tconst cost = (state.usage?.cost.total ?? 0) + (state.liveUsage?.cost.total ?? 0);\n\tconst firstBlocked = state.blocked[0];\n\tconst result = agent.result;\n\t// Matches details.ts's buildAgentDetails: gate on status, and prefer stderr over errorMessage\n\t// (details.ts: `agent.result?.stderr || agent.state.errorMessage`), so the error text does not\n\t// change when a row switches from the live store to persisted details at completion.\n\tconst isFailureStatus = agent.status === \"failed\" || agent.status === \"cancelled\";\n\tconst errorSource = result?.stderr || state.errorMessage;\n\tconst error = isFailureStatus && errorSource ? firstLine(errorSource) : undefined;\n\tconst elapsedMs = state.startedAt === undefined ? undefined : Math.max(0, (state.endedAt ?? now) - state.startedAt);\n\tconst resolved = Boolean(state.model.provider && state.model.id);\n\tconst modelText =\n\t\t!state.model.confirmed && !resolved\n\t\t\t? (state.model.requested ?? (state.model.source === \"child-default\" ? \"default model\" : undefined))\n\t\t\t: undefined;\n\treturn {\n\t\ti: agent.index,\n\t\tlabel: agent.label,\n\t\tagentType: agent.agentType,\n\t\tphase: agent.phase,\n\t\tstep: agent.step,\n\t\tstatus: agent.status,\n\t\tcancelReason: agent.cancelReason,\n\t\tprovider: state.model.provider,\n\t\tmodelId: state.model.id,\n\t\tmodelText,\n\t\t// Matches details.ts's buildAgentDetails, which writes `thinking` only from the confirmed\n\t\t// `state.model.thinkingLevel`, never from `requestedThinking`. A queued/pending agent's\n\t\t// requested thinking level is therefore not shown until the child confirms it.\n\t\tthinking: state.model.thinkingLevel,\n\t\tmodelSource: state.model.source,\n\t\tmodelConfirmed: state.model.confirmed,\n\t\telapsedMs,\n\t\tturns: state.turns,\n\t\ttoolCalls: state.toolCalls,\n\t\ttools: Object.keys(state.toolCounts).length > 0 ? state.toolCounts : undefined,\n\t\ttokens,\n\t\tcost,\n\t\tblocked: state.blockedCount,\n\t\tblockedSample: firstBlocked ? `${firstBlocked.toolName}: ${firstBlocked.summary}` : undefined,\n\t\ttask: agent.task,\n\t\tnow: isFinished(agent.status) ? undefined : state.nowLine || undefined,\n\t\tstatusLine: extractStatusLine(result?.output ?? state.finalText),\n\t\toutput: result?.output,\n\t\terror,\n\t\tmerge: result?.merge ? (result.merge.success ? \"ok\" : \"failed\") : undefined,\n\t\ttail: boundedTail(state.transcript, tailItems),\n\t};\n}\n\n/** Live view of a run, taken from the store. `tailItems` bounds `AgentSnapshotRow.tail`. */\nexport function snapshotFromRun(\n\trun: RunView,\n\toptions: { now: number; tailItems: number; limiter?: LimiterStats },\n): RunSnapshot {\n\tconst counts = emptyCounts();\n\tconst agents = run.agents.map((agent) => {\n\t\tconst row = rowFromAgentView(agent, options.now, options.tailItems);\n\t\tcounts[row.status]++;\n\t\treturn row;\n\t});\n\tconst tokens = agents.reduce((sum, row) => sum + row.tokens, 0);\n\tconst cost = agents.reduce((sum, row) => sum + row.cost, 0);\n\tconst blockedToolCalls = agents.reduce((sum, row) => sum + row.blocked, 0);\n\tconst phases: readonly PhaseInfo[] = run.phases;\n\tconst elapsedMs = Math.max(0, (run.endedAt ?? options.now) - run.startedAt);\n\treturn {\n\t\trunId: run.id,\n\t\tkind: run.kind,\n\t\torigin: run.origin,\n\t\tmode: run.mode,\n\t\ttitle: run.title,\n\t\tstatus: run.status,\n\t\tlive: true,\n\t\tstartedAt: run.startedAt,\n\t\telapsedMs,\n\t\tcounts,\n\t\ttokens,\n\t\tcost,\n\t\tbudget: run.budget.totalTokens === null ? undefined : { ...run.budget, totalTokens: run.budget.totalTokens },\n\t\tworkflow: run.workflow\n\t\t\t? {\n\t\t\t\t\tname: run.workflow.name,\n\t\t\t\t\tdescription: run.workflow.description,\n\t\t\t\t\tsource: run.workflow.source,\n\t\t\t\t\targs: run.workflow.args,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tphases: buildPhaseSnapshots(phases, agents, run.status === \"running\" ? run.currentPhase : undefined),\n\t\tcurrentPhase: run.currentPhase,\n\t\tagents,\n\t\tlog: run.log.map((line) => line.text),\n\t\tresultPreview: run.resultPreview,\n\t\terror: run.error,\n\t\tblockedToolCalls,\n\t\tlimiter: options.limiter,\n\t\tversion: run.version,\n\t};\n}\n\nfunction rowFromAgentDetails(d: AgentDetails, now: number): AgentSnapshotRow {\n\t// details.ts's modelText() writes \"provider/id\" when both are known, else the raw requested\n\t// pattern verbatim (§9.2). A requested pattern can itself contain a \"/\" (e.g. a frontmatter\n\t// model written as \"anthropic/claude-opus\"), so a resolved value cannot be told apart from an\n\t// unresolved one by searching for a slash; that inference wrongly split such patterns.\n\t// Override, phase and inherited sources always resolve provider/id before the child even\n\t// starts (model-selection.ts), so `model` is \"provider/id\" for them regardless of confirmation.\n\t// Frontmatter is the only source whose pre-confirmation display resolution is ambiguous from\n\t// `model` alone, so it is treated as resolved only once `modelConfirmed` is true; `child-default`\n\t// never sets `model` while unconfirmed (modelText() returns `requested`, which is undefined).\n\tconst resolved =\n\t\td.model !== undefined &&\n\t\t(d.modelConfirmed === true ||\n\t\t\td.modelSource === \"override\" ||\n\t\t\td.modelSource === \"phase\" ||\n\t\t\td.modelSource === \"inherited\");\n\tconst split = resolved ? splitModel(d.model) : {};\n\tconst modelText = resolved\n\t\t? undefined\n\t\t: (d.model ?? (d.modelSource === \"child-default\" ? \"default model\" : undefined));\n\tconst elapsedMs = d.startedAt === undefined ? undefined : Math.max(0, (d.endedAt ?? now) - d.startedAt);\n\tconst isFailureStatus = d.status === \"failed\" || d.status === \"cancelled\";\n\treturn {\n\t\ti: d.i,\n\t\tlabel: d.label,\n\t\tagentType: d.agent,\n\t\tphase: d.phase,\n\t\tstep: d.step,\n\t\tstatus: d.status,\n\t\tcancelReason: d.cancelReason,\n\t\tprovider: split.provider,\n\t\tmodelId: split.id,\n\t\tmodelText,\n\t\tthinking: d.thinking,\n\t\tmodelSource: d.modelSource,\n\t\tmodelConfirmed: d.modelConfirmed,\n\t\telapsedMs,\n\t\tturns: d.turns ?? 0,\n\t\ttoolCalls: d.toolCalls ?? 0,\n\t\ttools: d.tools,\n\t\ttokens: d.tokens ?? 0,\n\t\tcost: d.cost ?? 0,\n\t\tblocked: d.blocked ?? 0,\n\t\tblockedSample: d.blockedSample,\n\t\ttask: d.task,\n\t\tnow: d.now,\n\t\tstatusLine: d.statusLine,\n\t\toutput: d.output,\n\t\terror: isFailureStatus ? d.error : undefined,\n\t\tmerge: d.merge,\n\t};\n}\n\nfunction phaseInfoFromDetails(phase: PhaseDetails): {\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n\tdynamic: boolean;\n} {\n\treturn { title: phase.title, detail: phase.detail, model: phase.model, dynamic: phase.dynamic ?? false };\n}\n\n/** Cheap djb2 hash of the whole payload, so a line cache keyed on `RunSnapshot.version` (§11.2)\n * invalidates on every field a renderer can show (model confirmation, log lines, resultPreview,\n * agent `now`/tokens, degradation level, ...), not only status/endedAt/totals.byStatus. Details are\n * capped at `FINAL_DETAILS_MAX_BYTES`/`PARTIAL_DETAILS_MAX_BYTES`, so stringifying them is cheap.\n * `PolyphaseDetails` carries no version counter of its own. */\nfunction detailsVersion(details: PolyphaseDetails): number {\n\tconst fingerprint = JSON.stringify(details);\n\tlet hash = 5381;\n\tfor (let i = 0; i < fingerprint.length; i++) {\n\t\thash = (hash * 33) ^ fingerprint.charCodeAt(i);\n\t}\n\treturn hash >>> 0;\n}\n\n/** Archived or persisted view of a run, taken from `PolyphaseDetails`. No transcript is available, so\n * every `AgentSnapshotRow.tail` is left undefined. */\nexport function snapshotFromDetails(details: PolyphaseDetails, options?: { now?: number }): RunSnapshot {\n\tconst now = options?.now ?? Date.now();\n\tconst agents = details.agents.map((agent) => rowFromAgentDetails(agent, now));\n\tconst counts: Record<AgentStatus, number> = { ...emptyCounts(), ...details.totals.byStatus };\n\tconst phases = (details.phases ?? []).map(phaseInfoFromDetails);\n\tconst elapsedMs = Math.max(0, (details.endedAt ?? now) - details.startedAt);\n\treturn {\n\t\trunId: details.runId,\n\t\tkind: details.kind,\n\t\torigin: details.origin,\n\t\tmode: details.mode,\n\t\ttitle: details.title,\n\t\tstatus: details.status,\n\t\tlive: false,\n\t\tstartedAt: details.startedAt,\n\t\telapsedMs,\n\t\tcounts,\n\t\ttokens: details.totals.tokens,\n\t\tcost: details.totals.cost,\n\t\tbudget: details.budget,\n\t\tworkflow: details.workflow\n\t\t\t? {\n\t\t\t\t\tname: details.workflow.name,\n\t\t\t\t\tdescription: details.workflow.description,\n\t\t\t\t\tsource: details.workflow.source,\n\t\t\t\t\targs: details.workflow.args,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\tphases: buildPhaseSnapshots(\n\t\t\tphases,\n\t\t\tagents,\n\t\t\tdetails.status === \"running\" ? details.currentPhase : undefined,\n\t\t\tdetails.agentsOmitted !== undefined,\n\t\t),\n\t\tcurrentPhase: details.currentPhase,\n\t\tagents,\n\t\tagentsOmitted: details.agentsOmitted,\n\t\tlog: details.log ?? [],\n\t\tresultPreview: details.resultPreview,\n\t\terror: details.error,\n\t\tblockedToolCalls: details.totals.blockedToolCalls,\n\t\tversion: detailsVersion(details),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { JsonValue } from "@draht/ai";
|
|
2
|
+
import type { RunView, SubagentMode } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Text handed back to the parent model for subagent and workflow tool calls (D3). Bounded by
|
|
5
|
+
* character budgets rather than the byte budgets `details.ts` uses, since this text is tokenized
|
|
6
|
+
* context, not a persisted JSON blob.
|
|
7
|
+
*/
|
|
8
|
+
export interface HeadTailResult {
|
|
9
|
+
text: string;
|
|
10
|
+
omittedChars: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the head and tail of `text`, snapped to line boundaries, with a marker in between.
|
|
14
|
+
* `keepStatusLine` (default true) re-appends the source's last `STATUS: ...` line when the
|
|
15
|
+
* result does not already contain it, so callers never lose it to truncation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function capHeadTail(text: string, maxChars: number, options?: {
|
|
18
|
+
headRatio?: number;
|
|
19
|
+
keepStatusLine?: boolean;
|
|
20
|
+
}): HeadTailResult;
|
|
21
|
+
/** `clamp(floor(totalChars / agentCount), 2000, 16000)`. */
|
|
22
|
+
export declare function perAgentResultChars(totalChars: number, agentCount: number): number;
|
|
23
|
+
/** `undefined` when `count` is zero. */
|
|
24
|
+
export declare function formatBlockedNote(count: number, samples: readonly string[]): string | undefined;
|
|
25
|
+
export declare function formatSubagentResultText(run: RunView, options: {
|
|
26
|
+
mode: SubagentMode;
|
|
27
|
+
resultChars: number;
|
|
28
|
+
notices?: readonly string[];
|
|
29
|
+
}): string;
|
|
30
|
+
export interface WorkflowOutcomeSummary {
|
|
31
|
+
ok: boolean;
|
|
32
|
+
value?: JsonValue;
|
|
33
|
+
errorKind?: string;
|
|
34
|
+
errorMessage?: string;
|
|
35
|
+
errorLine?: number;
|
|
36
|
+
consoleOutput: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
export declare function formatWorkflowResultText(run: RunView, outcome: WorkflowOutcomeSummary): string;
|
|
39
|
+
/** ≤ 20 lines, each ≤ 120 chars. */
|
|
40
|
+
export declare function formatPartialStatusText(run: RunView, now?: number): string;
|
|
41
|
+
//# sourceMappingURL=result-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-text.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/result-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAa,OAAO,EAAE,YAAY,EAAE,MAAM,Y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
|
1
|
+
import { billableTokens, extractStatusLine } from "./child-events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the head and tail of `text`, snapped to line boundaries, with a marker in between.
|
|
4
|
+
* `keepStatusLine` (default true) re-appends the source's last `STATUS: ...` line when the
|
|
5
|
+
* result does not already contain it, so callers never lose it to truncation.
|
|
6
|
+
*/
|
|
7
|
+
export function capHeadTail(text, maxChars, options = {}) {
|
|
8
|
+
if (text.length <= maxChars)
|
|
9
|
+
return { text, omittedChars: 0 };
|
|
10
|
+
const headRatio = options.headRatio ?? 0.4;
|
|
11
|
+
const keepStatusLine = options.keepStatusLine ?? true;
|
|
12
|
+
const headBudget = Math.max(0, Math.floor(maxChars * headRatio));
|
|
13
|
+
const tailBudget = Math.max(0, maxChars - headBudget);
|
|
14
|
+
const headEnd = boundedSnap(text, headBudget, "backward", headBudget);
|
|
15
|
+
const tailStart = Math.max(headEnd, boundedSnap(text, text.length - tailBudget, "forward", tailBudget));
|
|
16
|
+
const head = text.slice(0, headEnd);
|
|
17
|
+
const tail = text.slice(tailStart);
|
|
18
|
+
const omittedChars = tailStart - headEnd;
|
|
19
|
+
let result = `${head}\n[... ${omittedChars} characters omitted ...]\n${tail}`;
|
|
20
|
+
if (keepStatusLine) {
|
|
21
|
+
const statusLine = extractStatusLine(text);
|
|
22
|
+
if (statusLine && !result.includes(statusLine))
|
|
23
|
+
result += `\n${statusLine}`;
|
|
24
|
+
}
|
|
25
|
+
return { text: result, omittedChars };
|
|
26
|
+
}
|
|
27
|
+
function snapToLineStart(text, pos, direction) {
|
|
28
|
+
if (direction === "backward") {
|
|
29
|
+
const idx = text.lastIndexOf("\n", Math.max(0, pos));
|
|
30
|
+
return idx === -1 ? Math.max(0, pos) : idx + 1;
|
|
31
|
+
}
|
|
32
|
+
const idx = text.indexOf("\n", Math.max(0, pos));
|
|
33
|
+
return idx === -1 ? Math.min(text.length, Math.max(0, pos)) : idx + 1;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Snaps `pos` to the nearest line boundary, but only when that stays within 20% of `budget` of the
|
|
37
|
+
* raw position. A long paragraph with no nearby newline (or a text that ends right at a trailing
|
|
38
|
+
* newline) would otherwise snap arbitrarily far, discarding almost the whole head or tail even
|
|
39
|
+
* though the caller asked for `budget` characters.
|
|
40
|
+
*/
|
|
41
|
+
function boundedSnap(text, pos, direction, budget) {
|
|
42
|
+
const raw = Math.max(0, Math.min(text.length, pos));
|
|
43
|
+
const snapped = snapToLineStart(text, pos, direction);
|
|
44
|
+
return Math.abs(snapped - raw) <= budget * 0.2 ? snapped : raw;
|
|
45
|
+
}
|
|
46
|
+
/** `clamp(floor(totalChars / agentCount), 2000, 16000)`. */
|
|
47
|
+
export function perAgentResultChars(totalChars, agentCount) {
|
|
48
|
+
const n = Math.max(1, agentCount);
|
|
49
|
+
return Math.min(16_000, Math.max(2_000, Math.floor(totalChars / n)));
|
|
50
|
+
}
|
|
51
|
+
function agentOutput(agent) {
|
|
52
|
+
return agent.result?.output ?? agent.state.finalText ?? "";
|
|
53
|
+
}
|
|
54
|
+
function modelLabel(agent) {
|
|
55
|
+
const model = agent.state.model;
|
|
56
|
+
if (model.provider && model.id)
|
|
57
|
+
return `${model.provider}/${model.id}`;
|
|
58
|
+
return model.requested ?? "default model";
|
|
59
|
+
}
|
|
60
|
+
function formatElapsedMs(ms) {
|
|
61
|
+
const totalSeconds = Math.floor(Math.max(0, ms) / 1000);
|
|
62
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
63
|
+
const seconds = totalSeconds % 60;
|
|
64
|
+
return `${minutes}:${String(seconds).padStart(2, "0")}`;
|
|
65
|
+
}
|
|
66
|
+
function formatElapsedAgent(agent, now) {
|
|
67
|
+
const start = agent.state.startedAt ?? agent.createdAt;
|
|
68
|
+
const end = agent.state.endedAt ?? now;
|
|
69
|
+
return formatElapsedMs(end - start);
|
|
70
|
+
}
|
|
71
|
+
function formatElapsedRun(run, now) {
|
|
72
|
+
return formatElapsedMs((run.endedAt ?? now) - run.startedAt);
|
|
73
|
+
}
|
|
74
|
+
function tailChars(text, maxChars) {
|
|
75
|
+
return text.length <= maxChars ? text : text.slice(text.length - maxChars);
|
|
76
|
+
}
|
|
77
|
+
function totalBillableTokens(run) {
|
|
78
|
+
return run.agents.reduce((sum, agent) => sum + billableTokens(agent.state.usage), 0);
|
|
79
|
+
}
|
|
80
|
+
function totalCost(run) {
|
|
81
|
+
return run.agents.reduce((sum, agent) => sum + (agent.state.usage?.cost.total ?? 0), 0);
|
|
82
|
+
}
|
|
83
|
+
function formatTokensPlain(n) {
|
|
84
|
+
return n.toLocaleString("en-US");
|
|
85
|
+
}
|
|
86
|
+
function formatCostPlain(n) {
|
|
87
|
+
return `$${n.toFixed(2)}`;
|
|
88
|
+
}
|
|
89
|
+
function collectBlockedSamples(run, limit = 3) {
|
|
90
|
+
const samples = [];
|
|
91
|
+
for (const agent of run.agents) {
|
|
92
|
+
for (const blocked of agent.state.blocked) {
|
|
93
|
+
samples.push(truncateLine(`${blocked.toolName}: ${blocked.summary}`, 200));
|
|
94
|
+
if (samples.length >= limit)
|
|
95
|
+
return samples;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return samples;
|
|
99
|
+
}
|
|
100
|
+
function totalBlockedToolCalls(run) {
|
|
101
|
+
return run.agents.reduce((sum, agent) => sum + agent.state.blockedCount, 0);
|
|
102
|
+
}
|
|
103
|
+
/** `undefined` when `count` is zero. */
|
|
104
|
+
export function formatBlockedNote(count, samples) {
|
|
105
|
+
if (count <= 0)
|
|
106
|
+
return undefined;
|
|
107
|
+
const suffix = samples.length > 0 ? `: ${samples.join(", ")}` : "";
|
|
108
|
+
return `${count} tool call(s) inside subagents were blocked because subagents cannot ask for approval${suffix}. Allow them with rules in permissions.yml, /permissions auto, or /yolo, then retry.`;
|
|
109
|
+
}
|
|
110
|
+
function appendBlockedNote(parts, run) {
|
|
111
|
+
const count = totalBlockedToolCalls(run);
|
|
112
|
+
const note = formatBlockedNote(count, collectBlockedSamples(run));
|
|
113
|
+
if (note)
|
|
114
|
+
parts.push(note);
|
|
115
|
+
}
|
|
116
|
+
function formatSingleAgent(agent, now) {
|
|
117
|
+
if (!agent)
|
|
118
|
+
return "";
|
|
119
|
+
if (agent.status === "cancelled") {
|
|
120
|
+
const base = `CANCELLED by ${agent.cancelReason ?? "user"} after ${formatElapsedAgent(agent, now)}`;
|
|
121
|
+
const output = agentOutput(agent);
|
|
122
|
+
return output.length > 0 ? `${base}\n${capHeadTail(output, 8000).text}` : base;
|
|
123
|
+
}
|
|
124
|
+
if (agent.status === "failed") {
|
|
125
|
+
const exitCode = agent.result?.exitCode ?? 1;
|
|
126
|
+
const stderr = agent.result?.stderr ?? "";
|
|
127
|
+
return `FAILED (exit ${exitCode}, model ${modelLabel(agent)})\n${capHeadTail(agentOutput(agent), 8000).text}\nstderr:\n${tailChars(stderr, 2000)}`;
|
|
128
|
+
}
|
|
129
|
+
return capHeadTail(agentOutput(agent), 50_000).text;
|
|
130
|
+
}
|
|
131
|
+
function parallelStatusLabel(agent) {
|
|
132
|
+
if (agent.result?.merge && !agent.result.merge.success)
|
|
133
|
+
return "merge-failed";
|
|
134
|
+
if (agent.status === "cancelled")
|
|
135
|
+
return "CANCELLED";
|
|
136
|
+
if (agent.status === "failed")
|
|
137
|
+
return "FAILED";
|
|
138
|
+
return "ok";
|
|
139
|
+
}
|
|
140
|
+
function isMergeFailed(agent) {
|
|
141
|
+
return agent.result?.merge !== undefined && !agent.result.merge.success;
|
|
142
|
+
}
|
|
143
|
+
function formatParallel(run, resultChars, now) {
|
|
144
|
+
const total = run.agents.length;
|
|
145
|
+
// A merge-failed agent's own block reads "merge-failed", not "ok", so it must not also count
|
|
146
|
+
// toward "succeeded" here; it is folded into the failed count instead.
|
|
147
|
+
const succeeded = run.agents.filter((a) => a.status === "done" && !isMergeFailed(a)).length;
|
|
148
|
+
const failed = run.agents.filter((a) => a.status === "failed" || (a.status === "done" && isMergeFailed(a))).length;
|
|
149
|
+
const cancelled = run.agents.filter((a) => a.status === "cancelled").length;
|
|
150
|
+
const headerParts = [`${succeeded}/${total} succeeded`];
|
|
151
|
+
if (failed > 0)
|
|
152
|
+
headerParts.push(`${failed} failed`);
|
|
153
|
+
if (cancelled > 0)
|
|
154
|
+
headerParts.push(`${cancelled} cancelled`);
|
|
155
|
+
const header = `Parallel: ${headerParts.join(", ")}`;
|
|
156
|
+
const perAgentChars = perAgentResultChars(resultChars, total);
|
|
157
|
+
const blocks = run.agents.map((agent, i) => {
|
|
158
|
+
const label = parallelStatusLabel(agent);
|
|
159
|
+
const title = `=== [${i + 1}/${total}] ${agent.label} (${agent.agentType}) — ${label} · ${modelLabel(agent)} · ${formatElapsedAgent(agent, now)} ===`;
|
|
160
|
+
const lines = [title, capHeadTail(agentOutput(agent), perAgentChars).text];
|
|
161
|
+
if (label === "FAILED" || label === "merge-failed") {
|
|
162
|
+
const stderr = agent.result?.stderr ?? "";
|
|
163
|
+
if (stderr.length > 0)
|
|
164
|
+
lines.push(`stderr:\n${tailChars(stderr, 1500)}`);
|
|
165
|
+
}
|
|
166
|
+
return lines.join("\n");
|
|
167
|
+
});
|
|
168
|
+
return [header, ...blocks].join("\n\n");
|
|
169
|
+
}
|
|
170
|
+
function chainStatusWord(agent) {
|
|
171
|
+
if (agent.status === "cancelled")
|
|
172
|
+
return "CANCELLED";
|
|
173
|
+
if (agent.status === "failed")
|
|
174
|
+
return "FAILED";
|
|
175
|
+
if (agent.status === "done")
|
|
176
|
+
return "ok";
|
|
177
|
+
// "pending"/"skipped" (never started because the chain already stopped), or a status this
|
|
178
|
+
// text is never expected to see (e.g. "running"): show it verbatim rather than mislabel it "ok".
|
|
179
|
+
return agent.status;
|
|
180
|
+
}
|
|
181
|
+
/** Steps the chain never started (pending/skipped after a break) have no elapsed time to show. */
|
|
182
|
+
function formatChainStepLine(agent, now) {
|
|
183
|
+
const step = agent.step ?? agent.index + 1;
|
|
184
|
+
const word = chainStatusWord(agent);
|
|
185
|
+
if (agent.status === "pending" || agent.status === "skipped")
|
|
186
|
+
return `${step}. ${agent.label} ${word}`;
|
|
187
|
+
return `${step}. ${agent.label} ${word} · ${formatElapsedAgent(agent, now)}`;
|
|
188
|
+
}
|
|
189
|
+
function formatChain(run, now) {
|
|
190
|
+
// Every step is rendered, including pending/skipped ones after a break, so the parent model
|
|
191
|
+
// sees where the chain stopped (D3 owner decision).
|
|
192
|
+
const steps = run.agents;
|
|
193
|
+
const lines = steps.map((a) => formatChainStepLine(a, now));
|
|
194
|
+
const stepsText = lines.join("\n");
|
|
195
|
+
const brokenStep = steps.find((a) => a.status === "failed" || a.status === "cancelled");
|
|
196
|
+
if (brokenStep) {
|
|
197
|
+
const verb = brokenStep.status === "cancelled" ? "cancelled" : "failed";
|
|
198
|
+
const parts = [
|
|
199
|
+
stepsText,
|
|
200
|
+
`Chain ${verb} at step ${brokenStep.step ?? brokenStep.index + 1} (${brokenStep.label})`,
|
|
201
|
+
capHeadTail(agentOutput(brokenStep), 8000).text,
|
|
202
|
+
];
|
|
203
|
+
const stderr = brokenStep.result?.stderr ?? "";
|
|
204
|
+
if (stderr.length > 0)
|
|
205
|
+
parts.push(`stderr:\n${tailChars(stderr, 2000)}`);
|
|
206
|
+
return parts.join("\n");
|
|
207
|
+
}
|
|
208
|
+
const last = steps[steps.length - 1];
|
|
209
|
+
const lastOutput = last ? capHeadTail(agentOutput(last), 50_000).text : "";
|
|
210
|
+
return [stepsText, lastOutput].join("\n\n");
|
|
211
|
+
}
|
|
212
|
+
export function formatSubagentResultText(run, options) {
|
|
213
|
+
const now = Date.now();
|
|
214
|
+
const body = options.mode === "parallel"
|
|
215
|
+
? formatParallel(run, options.resultChars, now)
|
|
216
|
+
: options.mode === "chain"
|
|
217
|
+
? formatChain(run, now)
|
|
218
|
+
: formatSingleAgent(run.agents[0], now);
|
|
219
|
+
const parts = [body];
|
|
220
|
+
if (options.notices && options.notices.length > 0)
|
|
221
|
+
parts.push(...options.notices);
|
|
222
|
+
appendBlockedNote(parts, run);
|
|
223
|
+
return parts.join("\n\n");
|
|
224
|
+
}
|
|
225
|
+
function formatWorkflowHeader(run, now) {
|
|
226
|
+
const name = run.workflow?.name ?? run.title;
|
|
227
|
+
const total = run.agents.length;
|
|
228
|
+
const done = run.agents.filter((a) => a.status === "done").length;
|
|
229
|
+
const failed = run.agents.filter((a) => a.status === "failed").length;
|
|
230
|
+
const cancelled = run.agents.filter((a) => a.status === "cancelled").length;
|
|
231
|
+
return `Workflow ${name}: ${run.status} · ${total} agents (${done} ok, ${failed} failed, ${cancelled} cancelled) · ${formatElapsedRun(run, now)} · ${formatTokensPlain(totalBillableTokens(run))} tokens · ${formatCostPlain(totalCost(run))}`;
|
|
232
|
+
}
|
|
233
|
+
function formatWorkflowPhases(run) {
|
|
234
|
+
const lines = run.phases.map((phase, i) => {
|
|
235
|
+
const agents = run.agents.filter((a) => a.phase === i);
|
|
236
|
+
const done = agents.filter((a) => a.status === "done").length;
|
|
237
|
+
const failed = agents.filter((a) => a.status === "failed").length;
|
|
238
|
+
const cancelled = agents.filter((a) => a.status === "cancelled").length;
|
|
239
|
+
const tally = [`${done}/${agents.length} ok`];
|
|
240
|
+
if (failed > 0)
|
|
241
|
+
tally.push(`${failed} failed`);
|
|
242
|
+
if (cancelled > 0)
|
|
243
|
+
tally.push(`${cancelled} cancelled`);
|
|
244
|
+
return `${i + 1}. ${phase.title} — ${tally.join(", ")}`;
|
|
245
|
+
});
|
|
246
|
+
return ["Phases:", ...lines].join("\n");
|
|
247
|
+
}
|
|
248
|
+
function formatWorkflowResult(outcome) {
|
|
249
|
+
const value = outcome.value;
|
|
250
|
+
const text = value === undefined ? "" : typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
251
|
+
return ["Result:", capHeadTail(text, 32_000).text].join("\n");
|
|
252
|
+
}
|
|
253
|
+
function formatWorkflowLog(run) {
|
|
254
|
+
const lines = run.log.slice(-30).map((line) => truncateLine(line.text, 200));
|
|
255
|
+
return ["Log:", ...lines].join("\n");
|
|
256
|
+
}
|
|
257
|
+
function formatWorkflowConsole(outcome) {
|
|
258
|
+
return ["Console:", capHeadTail(outcome.consoleOutput.join("\n"), 8000).text].join("\n");
|
|
259
|
+
}
|
|
260
|
+
function firstNonBlankLine(text) {
|
|
261
|
+
for (const line of text.split("\n")) {
|
|
262
|
+
if (line.trim().length > 0)
|
|
263
|
+
return line;
|
|
264
|
+
}
|
|
265
|
+
return "";
|
|
266
|
+
}
|
|
267
|
+
function formatWorkflowAgents(run) {
|
|
268
|
+
const lines = run.agents.slice(0, 100).map((agent) => {
|
|
269
|
+
const output = agentOutput(agent);
|
|
270
|
+
const info = extractStatusLine(output) ?? firstNonBlankLine(agent.result?.stderr || agent.state.errorMessage || "");
|
|
271
|
+
return truncateLine(`${agent.label} ${agent.status} ${modelLabel(agent)} ${info}`.trimEnd(), 200);
|
|
272
|
+
});
|
|
273
|
+
return ["Agents:", ...lines].join("\n");
|
|
274
|
+
}
|
|
275
|
+
function formatBudgetNotice(run) {
|
|
276
|
+
const total = run.budget.totalTokens ?? 0;
|
|
277
|
+
return `Budget exhausted: ${formatTokensPlain(run.budget.spentTokens)} / ${formatTokensPlain(total)} tokens; remaining agents were skipped.`;
|
|
278
|
+
}
|
|
279
|
+
function formatScriptError(outcome) {
|
|
280
|
+
if (outcome.ok || !outcome.errorMessage)
|
|
281
|
+
return undefined;
|
|
282
|
+
const prefix = outcome.errorKind && outcome.errorKind !== "script" ? `Workflow ${outcome.errorKind}` : "Script error";
|
|
283
|
+
return outcome.errorLine !== undefined
|
|
284
|
+
? `${prefix} at line ${outcome.errorLine}: ${outcome.errorMessage}`
|
|
285
|
+
: `${prefix}: ${outcome.errorMessage}`;
|
|
286
|
+
}
|
|
287
|
+
export function formatWorkflowResultText(run, outcome) {
|
|
288
|
+
const now = Date.now();
|
|
289
|
+
const sections = [
|
|
290
|
+
formatWorkflowHeader(run, now),
|
|
291
|
+
formatWorkflowPhases(run),
|
|
292
|
+
formatWorkflowResult(outcome),
|
|
293
|
+
formatWorkflowLog(run),
|
|
294
|
+
];
|
|
295
|
+
if (outcome.consoleOutput.length > 0)
|
|
296
|
+
sections.push(formatWorkflowConsole(outcome));
|
|
297
|
+
sections.push(formatWorkflowAgents(run));
|
|
298
|
+
const trailer = [];
|
|
299
|
+
if (run.budget.exhausted)
|
|
300
|
+
trailer.push(formatBudgetNotice(run));
|
|
301
|
+
const scriptError = formatScriptError(outcome);
|
|
302
|
+
if (scriptError)
|
|
303
|
+
trailer.push(scriptError);
|
|
304
|
+
appendBlockedNote(trailer, run);
|
|
305
|
+
if (trailer.length > 0)
|
|
306
|
+
sections.push(trailer.join("\n"));
|
|
307
|
+
return sections.join("\n\n");
|
|
308
|
+
}
|
|
309
|
+
/** ≤ 20 lines, each ≤ 120 chars. */
|
|
310
|
+
export function formatPartialStatusText(run, now = Date.now()) {
|
|
311
|
+
const lines = [];
|
|
312
|
+
const done = run.agents.filter((a) => a.status === "done").length;
|
|
313
|
+
lines.push(truncateLine(`${run.title}: ${done}/${run.agents.length} done · ${formatElapsedRun(run, now)}`, 120));
|
|
314
|
+
for (const agent of run.agents) {
|
|
315
|
+
if (lines.length >= 20)
|
|
316
|
+
break;
|
|
317
|
+
const activity = agent.status === "running" ? agent.state.nowLine : agent.status;
|
|
318
|
+
lines.push(truncateLine(`${agent.index + 1}. ${agent.label} ${activity}`, 120));
|
|
319
|
+
}
|
|
320
|
+
return lines.slice(0, 20).join("\n");
|
|
321
|
+
}
|
|
322
|
+
function truncateLine(text, maxChars) {
|
|
323
|
+
const singleLine = text.replace(/\s+/g, " ").trim();
|
|
324
|
+
return singleLine.length <= maxChars ? singleLine : `${singleLine.slice(0, maxChars - 1)}…`;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=result-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-text.js","sourceRoot":"","sources":["../../../src/core/polyphase/result-text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAA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{ AgentView, RunView, SubagentMode } from \"./types.ts\";\n\n/**\n * Text handed back to the parent model for subagent and workflow tool calls (D3). Bounded by\n * character budgets rather than the byte budgets `details.ts` uses, since this text is tokenized\n * context, not a persisted JSON blob.\n */\n\nexport interface HeadTailResult {\n\ttext: string;\n\tomittedChars: number;\n}\n\n/**\n * Keeps the head and tail of `text`, snapped to line boundaries, with a marker in between.\n * `keepStatusLine` (default true) re-appends the source's last `STATUS: ...` line when the\n * result does not already contain it, so callers never lose it to truncation.\n */\nexport function capHeadTail(\n\ttext: string,\n\tmaxChars: number,\n\toptions: { headRatio?: number; keepStatusLine?: boolean } = {},\n): HeadTailResult {\n\tif (text.length <= maxChars) return { text, omittedChars: 0 };\n\n\tconst headRatio = options.headRatio ?? 0.4;\n\tconst keepStatusLine = options.keepStatusLine ?? true;\n\n\tconst headBudget = Math.max(0, Math.floor(maxChars * headRatio));\n\tconst tailBudget = Math.max(0, maxChars - headBudget);\n\n\tconst headEnd = boundedSnap(text, headBudget, \"backward\", headBudget);\n\tconst tailStart = Math.max(headEnd, boundedSnap(text, text.length - tailBudget, \"forward\", tailBudget));\n\n\tconst head = text.slice(0, headEnd);\n\tconst tail = text.slice(tailStart);\n\tconst omittedChars = tailStart - headEnd;\n\n\tlet result = `${head}\\n[... ${omittedChars} characters omitted ...]\\n${tail}`;\n\tif (keepStatusLine) {\n\t\tconst statusLine = extractStatusLine(text);\n\t\tif (statusLine && !result.includes(statusLine)) result += `\\n${statusLine}`;\n\t}\n\n\treturn { text: result, omittedChars };\n}\n\nfunction snapToLineStart(text: string, pos: number, direction: \"backward\" | \"forward\"): number {\n\tif (direction === \"backward\") {\n\t\tconst idx = text.lastIndexOf(\"\\n\", Math.max(0, pos));\n\t\treturn idx === -1 ? Math.max(0, pos) : idx + 1;\n\t}\n\tconst idx = text.indexOf(\"\\n\", Math.max(0, pos));\n\treturn idx === -1 ? Math.min(text.length, Math.max(0, pos)) : idx + 1;\n}\n\n/**\n * Snaps `pos` to the nearest line boundary, but only when that stays within 20% of `budget` of the\n * raw position. A long paragraph with no nearby newline (or a text that ends right at a trailing\n * newline) would otherwise snap arbitrarily far, discarding almost the whole head or tail even\n * though the caller asked for `budget` characters.\n */\nfunction boundedSnap(text: string, pos: number, direction: \"backward\" | \"forward\", budget: number): number {\n\tconst raw = Math.max(0, Math.min(text.length, pos));\n\tconst snapped = snapToLineStart(text, pos, direction);\n\treturn Math.abs(snapped - raw) <= budget * 0.2 ? snapped : raw;\n}\n\n/** `clamp(floor(totalChars / agentCount), 2000, 16000)`. */\nexport function perAgentResultChars(totalChars: number, agentCount: number): number {\n\tconst n = Math.max(1, agentCount);\n\treturn Math.min(16_000, Math.max(2_000, Math.floor(totalChars / n)));\n}\n\nfunction agentOutput(agent: AgentView): string {\n\treturn agent.result?.output ?? agent.state.finalText ?? \"\";\n}\n\nfunction modelLabel(agent: AgentView): string {\n\tconst model = agent.state.model;\n\tif (model.provider && model.id) return `${model.provider}/${model.id}`;\n\treturn model.requested ?? \"default model\";\n}\n\nfunction formatElapsedMs(ms: number): string {\n\tconst totalSeconds = Math.floor(Math.max(0, ms) / 1000);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst seconds = totalSeconds % 60;\n\treturn `${minutes}:${String(seconds).padStart(2, \"0\")}`;\n}\n\nfunction formatElapsedAgent(agent: AgentView, now: number): string {\n\tconst start = agent.state.startedAt ?? agent.createdAt;\n\tconst end = agent.state.endedAt ?? now;\n\treturn formatElapsedMs(end - start);\n}\n\nfunction formatElapsedRun(run: RunView, now: number): string {\n\treturn formatElapsedMs((run.endedAt ?? now) - run.startedAt);\n}\n\nfunction tailChars(text: string, maxChars: number): string {\n\treturn text.length <= maxChars ? text : text.slice(text.length - maxChars);\n}\n\nfunction totalBillableTokens(run: RunView): number {\n\treturn run.agents.reduce((sum, agent) => sum + billableTokens(agent.state.usage), 0);\n}\n\nfunction totalCost(run: RunView): number {\n\treturn run.agents.reduce((sum, agent) => sum + (agent.state.usage?.cost.total ?? 0), 0);\n}\n\nfunction formatTokensPlain(n: number): string {\n\treturn n.toLocaleString(\"en-US\");\n}\n\nfunction formatCostPlain(n: number): string {\n\treturn `$${n.toFixed(2)}`;\n}\n\nfunction collectBlockedSamples(run: RunView, limit = 3): string[] {\n\tconst samples: string[] = [];\n\tfor (const agent of run.agents) {\n\t\tfor (const blocked of agent.state.blocked) {\n\t\t\tsamples.push(truncateLine(`${blocked.toolName}: ${blocked.summary}`, 200));\n\t\t\tif (samples.length >= limit) return samples;\n\t\t}\n\t}\n\treturn samples;\n}\n\nfunction totalBlockedToolCalls(run: RunView): number {\n\treturn run.agents.reduce((sum, agent) => sum + agent.state.blockedCount, 0);\n}\n\n/** `undefined` when `count` is zero. */\nexport function formatBlockedNote(count: number, samples: readonly string[]): string | undefined {\n\tif (count <= 0) return undefined;\n\tconst suffix = samples.length > 0 ? `: ${samples.join(\", \")}` : \"\";\n\treturn `${count} tool call(s) inside subagents were blocked because subagents cannot ask for approval${suffix}. Allow them with rules in permissions.yml, /permissions auto, or /yolo, then retry.`;\n}\n\nfunction appendBlockedNote(parts: string[], run: RunView): void {\n\tconst count = totalBlockedToolCalls(run);\n\tconst note = formatBlockedNote(count, collectBlockedSamples(run));\n\tif (note) parts.push(note);\n}\n\nfunction formatSingleAgent(agent: AgentView | undefined, now: number): string {\n\tif (!agent) return \"\";\n\tif (agent.status === \"cancelled\") {\n\t\tconst base = `CANCELLED by ${agent.cancelReason ?? \"user\"} after ${formatElapsedAgent(agent, now)}`;\n\t\tconst output = agentOutput(agent);\n\t\treturn output.length > 0 ? `${base}\\n${capHeadTail(output, 8000).text}` : base;\n\t}\n\tif (agent.status === \"failed\") {\n\t\tconst exitCode = agent.result?.exitCode ?? 1;\n\t\tconst stderr = agent.result?.stderr ?? \"\";\n\t\treturn `FAILED (exit ${exitCode}, model ${modelLabel(agent)})\\n${capHeadTail(agentOutput(agent), 8000).text}\\nstderr:\\n${tailChars(stderr, 2000)}`;\n\t}\n\treturn capHeadTail(agentOutput(agent), 50_000).text;\n}\n\nfunction parallelStatusLabel(agent: AgentView): \"ok\" | \"FAILED\" | \"CANCELLED\" | \"merge-failed\" {\n\tif (agent.result?.merge && !agent.result.merge.success) return \"merge-failed\";\n\tif (agent.status === \"cancelled\") return \"CANCELLED\";\n\tif (agent.status === \"failed\") return \"FAILED\";\n\treturn \"ok\";\n}\n\nfunction isMergeFailed(agent: AgentView): boolean {\n\treturn agent.result?.merge !== undefined && !agent.result.merge.success;\n}\n\nfunction formatParallel(run: RunView, resultChars: number, now: number): string {\n\tconst total = run.agents.length;\n\t// A merge-failed agent's own block reads \"merge-failed\", not \"ok\", so it must not also count\n\t// toward \"succeeded\" here; it is folded into the failed count instead.\n\tconst succeeded = run.agents.filter((a) => a.status === \"done\" && !isMergeFailed(a)).length;\n\tconst failed = run.agents.filter((a) => a.status === \"failed\" || (a.status === \"done\" && isMergeFailed(a))).length;\n\tconst cancelled = run.agents.filter((a) => a.status === \"cancelled\").length;\n\n\tconst headerParts = [`${succeeded}/${total} succeeded`];\n\tif (failed > 0) headerParts.push(`${failed} failed`);\n\tif (cancelled > 0) headerParts.push(`${cancelled} cancelled`);\n\tconst header = `Parallel: ${headerParts.join(\", \")}`;\n\n\tconst perAgentChars = perAgentResultChars(resultChars, total);\n\tconst blocks = run.agents.map((agent, i) => {\n\t\tconst label = parallelStatusLabel(agent);\n\t\tconst title = `=== [${i + 1}/${total}] ${agent.label} (${agent.agentType}) — ${label} · ${modelLabel(agent)} · ${formatElapsedAgent(agent, now)} ===`;\n\t\tconst lines = [title, capHeadTail(agentOutput(agent), perAgentChars).text];\n\t\tif (label === \"FAILED\" || label === \"merge-failed\") {\n\t\t\tconst stderr = agent.result?.stderr ?? \"\";\n\t\t\tif (stderr.length > 0) lines.push(`stderr:\\n${tailChars(stderr, 1500)}`);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t});\n\n\treturn [header, ...blocks].join(\"\\n\\n\");\n}\n\nfunction chainStatusWord(agent: AgentView): string {\n\tif (agent.status === \"cancelled\") return \"CANCELLED\";\n\tif (agent.status === \"failed\") return \"FAILED\";\n\tif (agent.status === \"done\") return \"ok\";\n\t// \"pending\"/\"skipped\" (never started because the chain already stopped), or a status this\n\t// text is never expected to see (e.g. \"running\"): show it verbatim rather than mislabel it \"ok\".\n\treturn agent.status;\n}\n\n/** Steps the chain never started (pending/skipped after a break) have no elapsed time to show. */\nfunction formatChainStepLine(agent: AgentView, now: number): string {\n\tconst step = agent.step ?? agent.index + 1;\n\tconst word = chainStatusWord(agent);\n\tif (agent.status === \"pending\" || agent.status === \"skipped\") return `${step}. ${agent.label} ${word}`;\n\treturn `${step}. ${agent.label} ${word} · ${formatElapsedAgent(agent, now)}`;\n}\n\nfunction formatChain(run: RunView, now: number): string {\n\t// Every step is rendered, including pending/skipped ones after a break, so the parent model\n\t// sees where the chain stopped (D3 owner decision).\n\tconst steps = run.agents;\n\tconst lines = steps.map((a) => formatChainStepLine(a, now));\n\tconst stepsText = lines.join(\"\\n\");\n\n\tconst brokenStep = steps.find((a) => a.status === \"failed\" || a.status === \"cancelled\");\n\tif (brokenStep) {\n\t\tconst verb = brokenStep.status === \"cancelled\" ? \"cancelled\" : \"failed\";\n\t\tconst parts = [\n\t\t\tstepsText,\n\t\t\t`Chain ${verb} at step ${brokenStep.step ?? brokenStep.index + 1} (${brokenStep.label})`,\n\t\t\tcapHeadTail(agentOutput(brokenStep), 8000).text,\n\t\t];\n\t\tconst stderr = brokenStep.result?.stderr ?? \"\";\n\t\tif (stderr.length > 0) parts.push(`stderr:\\n${tailChars(stderr, 2000)}`);\n\t\treturn parts.join(\"\\n\");\n\t}\n\n\tconst last = steps[steps.length - 1];\n\tconst lastOutput = last ? capHeadTail(agentOutput(last), 50_000).text : \"\";\n\treturn [stepsText, lastOutput].join(\"\\n\\n\");\n}\n\nexport function formatSubagentResultText(\n\trun: RunView,\n\toptions: { mode: SubagentMode; resultChars: number; notices?: readonly string[] },\n): string {\n\tconst now = Date.now();\n\tconst body =\n\t\toptions.mode === \"parallel\"\n\t\t\t? formatParallel(run, options.resultChars, now)\n\t\t\t: options.mode === \"chain\"\n\t\t\t\t? formatChain(run, now)\n\t\t\t\t: formatSingleAgent(run.agents[0], now);\n\n\tconst parts = [body];\n\tif (options.notices && options.notices.length > 0) parts.push(...options.notices);\n\tappendBlockedNote(parts, run);\n\treturn parts.join(\"\\n\\n\");\n}\n\nexport interface WorkflowOutcomeSummary {\n\tok: boolean;\n\tvalue?: JsonValue;\n\terrorKind?: string;\n\terrorMessage?: string;\n\terrorLine?: number;\n\tconsoleOutput: readonly string[];\n}\n\nfunction formatWorkflowHeader(run: RunView, now: number): string {\n\tconst name = run.workflow?.name ?? run.title;\n\tconst total = run.agents.length;\n\tconst done = run.agents.filter((a) => a.status === \"done\").length;\n\tconst failed = run.agents.filter((a) => a.status === \"failed\").length;\n\tconst cancelled = run.agents.filter((a) => a.status === \"cancelled\").length;\n\treturn `Workflow ${name}: ${run.status} · ${total} agents (${done} ok, ${failed} failed, ${cancelled} cancelled) · ${formatElapsedRun(run, now)} · ${formatTokensPlain(totalBillableTokens(run))} tokens · ${formatCostPlain(totalCost(run))}`;\n}\n\nfunction formatWorkflowPhases(run: RunView): string {\n\tconst lines = run.phases.map((phase, i) => {\n\t\tconst agents = run.agents.filter((a) => a.phase === i);\n\t\tconst done = agents.filter((a) => a.status === \"done\").length;\n\t\tconst failed = agents.filter((a) => a.status === \"failed\").length;\n\t\tconst cancelled = agents.filter((a) => a.status === \"cancelled\").length;\n\t\tconst tally = [`${done}/${agents.length} ok`];\n\t\tif (failed > 0) tally.push(`${failed} failed`);\n\t\tif (cancelled > 0) tally.push(`${cancelled} cancelled`);\n\t\treturn `${i + 1}. ${phase.title} — ${tally.join(\", \")}`;\n\t});\n\treturn [\"Phases:\", ...lines].join(\"\\n\");\n}\n\nfunction formatWorkflowResult(outcome: WorkflowOutcomeSummary): string {\n\tconst value = outcome.value;\n\tconst text = value === undefined ? \"\" : typeof value === \"string\" ? value : JSON.stringify(value, null, 2);\n\treturn [\"Result:\", capHeadTail(text, 32_000).text].join(\"\\n\");\n}\n\nfunction formatWorkflowLog(run: RunView): string {\n\tconst lines = run.log.slice(-30).map((line) => truncateLine(line.text, 200));\n\treturn [\"Log:\", ...lines].join(\"\\n\");\n}\n\nfunction formatWorkflowConsole(outcome: WorkflowOutcomeSummary): string {\n\treturn [\"Console:\", capHeadTail(outcome.consoleOutput.join(\"\\n\"), 8000).text].join(\"\\n\");\n}\n\nfunction firstNonBlankLine(text: string): string {\n\tfor (const line of text.split(\"\\n\")) {\n\t\tif (line.trim().length > 0) return line;\n\t}\n\treturn \"\";\n}\n\nfunction formatWorkflowAgents(run: RunView): string {\n\tconst lines = run.agents.slice(0, 100).map((agent) => {\n\t\tconst output = agentOutput(agent);\n\t\tconst info =\n\t\t\textractStatusLine(output) ?? firstNonBlankLine(agent.result?.stderr || agent.state.errorMessage || \"\");\n\t\treturn truncateLine(`${agent.label} ${agent.status} ${modelLabel(agent)} ${info}`.trimEnd(), 200);\n\t});\n\treturn [\"Agents:\", ...lines].join(\"\\n\");\n}\n\nfunction formatBudgetNotice(run: RunView): string {\n\tconst total = run.budget.totalTokens ?? 0;\n\treturn `Budget exhausted: ${formatTokensPlain(run.budget.spentTokens)} / ${formatTokensPlain(total)} tokens; remaining agents were skipped.`;\n}\n\nfunction formatScriptError(outcome: WorkflowOutcomeSummary): string | undefined {\n\tif (outcome.ok || !outcome.errorMessage) return undefined;\n\tconst prefix =\n\t\toutcome.errorKind && outcome.errorKind !== \"script\" ? `Workflow ${outcome.errorKind}` : \"Script error\";\n\treturn outcome.errorLine !== undefined\n\t\t? `${prefix} at line ${outcome.errorLine}: ${outcome.errorMessage}`\n\t\t: `${prefix}: ${outcome.errorMessage}`;\n}\n\nexport function formatWorkflowResultText(run: RunView, outcome: WorkflowOutcomeSummary): string {\n\tconst now = Date.now();\n\tconst sections = [\n\t\tformatWorkflowHeader(run, now),\n\t\tformatWorkflowPhases(run),\n\t\tformatWorkflowResult(outcome),\n\t\tformatWorkflowLog(run),\n\t];\n\tif (outcome.consoleOutput.length > 0) sections.push(formatWorkflowConsole(outcome));\n\tsections.push(formatWorkflowAgents(run));\n\n\tconst trailer: string[] = [];\n\tif (run.budget.exhausted) trailer.push(formatBudgetNotice(run));\n\tconst scriptError = formatScriptError(outcome);\n\tif (scriptError) trailer.push(scriptError);\n\tappendBlockedNote(trailer, run);\n\tif (trailer.length > 0) sections.push(trailer.join(\"\\n\"));\n\n\treturn sections.join(\"\\n\\n\");\n}\n\n/** ≤ 20 lines, each ≤ 120 chars. */\nexport function formatPartialStatusText(run: RunView, now: number = Date.now()): string {\n\tconst lines: string[] = [];\n\tconst done = run.agents.filter((a) => a.status === \"done\").length;\n\tlines.push(truncateLine(`${run.title}: ${done}/${run.agents.length} done · ${formatElapsedRun(run, now)}`, 120));\n\tfor (const agent of run.agents) {\n\t\tif (lines.length >= 20) break;\n\t\tconst activity = agent.status === \"running\" ? agent.state.nowLine : agent.status;\n\t\tlines.push(truncateLine(`${agent.index + 1}. ${agent.label} ${activity}`, 120));\n\t}\n\treturn lines.slice(0, 20).join(\"\\n\");\n}\n\nfunction truncateLine(text: string, maxChars: number): string {\n\tconst singleLine = text.replace(/\\s+/g, \" \").trim();\n\treturn singleLine.length <= maxChars ? singleLine : `${singleLine.slice(0, maxChars - 1)}…`;\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-scoped polyphase state, keyed off `ctx.sessionManager` so draht-acp sessions never
|
|
3
|
+
* mix. Created on first use and disposed on `session_shutdown`.
|
|
4
|
+
*/
|
|
5
|
+
import type { PermissionMode } from "../multi-agent/index.ts";
|
|
6
|
+
import type { PolyphaseSettings } from "../settings-manager.ts";
|
|
7
|
+
import { AgentLimiter } from "./limiter.ts";
|
|
8
|
+
import { type ResolvedPolyphaseSettings } from "./settings.ts";
|
|
9
|
+
import { PolyphaseStore } from "./store.ts";
|
|
10
|
+
export interface PolyphaseSession {
|
|
11
|
+
readonly store: PolyphaseStore;
|
|
12
|
+
readonly limiter: AgentLimiter;
|
|
13
|
+
settings(): ResolvedPolyphaseSettings;
|
|
14
|
+
/** Re-resolves settings; updates the limiter's capacity and the pump's interval. */
|
|
15
|
+
refreshSettings(raw: PolyphaseSettings | undefined): void;
|
|
16
|
+
/** "default" until a provider is set. */
|
|
17
|
+
permissionMode(): PermissionMode;
|
|
18
|
+
setPermissionModeProvider(provider: () => PermissionMode): void;
|
|
19
|
+
onParentPrompt(listener: () => void): () => void;
|
|
20
|
+
/** The inspector closes so a parent dialog stays reachable. */
|
|
21
|
+
notifyParentPrompt(): void;
|
|
22
|
+
/** Pump interval: `min(100, liveUpdateMs)` while open. */
|
|
23
|
+
setInspectorOpen(open: boolean): void;
|
|
24
|
+
readonly disposed: boolean;
|
|
25
|
+
dispose(reason: string): void;
|
|
26
|
+
}
|
|
27
|
+
/** Creates on first use; refreshes settings on every call. `key` is `ctx.sessionManager`. */
|
|
28
|
+
export declare function getPolyphaseSession(key: object, raw: PolyphaseSettings | undefined): PolyphaseSession;
|
|
29
|
+
/** Returns undefined for non-object keys (tests pass contexts without `sessionManager`). */
|
|
30
|
+
export declare function peekPolyphaseSession(key: unknown): PolyphaseSession | undefined;
|
|
31
|
+
/** Idempotent: disposes and deletes the entry, if any. */
|
|
32
|
+
export declare function disposePolyphaseSession(key: unknown, reason: string): void;
|
|
33
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,KAAK,yBAAyB,EAA4B,MAAM,e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