@draht/coding-agent 2026.10.16 → 2026.10.19
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 +39 -0
- package/README.md +1 -0
- package/dist/bundle/chunks/{chunk-OWGSPJPZ.js → chunk-7TYCZN4Z.js} +4 -4
- package/dist/bundle/chunks/{chunk-TJ3AW62W.js → chunk-KEUN2Y6B.js} +1 -1
- package/dist/bundle/chunks/{chunk-JFDPOIUH.js → chunk-MO3SCGBN.js} +1 -1
- package/dist/bundle/chunks/{chunk-6APPDDHH.js → chunk-N2QZNJT6.js} +3 -3
- package/dist/bundle/chunks/{chunk-MIUVNYYW.js → chunk-VOODMGI3.js} +103 -91
- package/dist/bundle/chunks/{chunk-NHTOADU6.js → chunk-ZA4QNPJY.js} +1 -1
- package/dist/bundle/chunks/{cli-U7Y4VNNI.js → cli-PYJB6AQ3.js} +1 -1
- package/dist/bundle/chunks/{execute-ZWB4PIQQ.js → execute-6N7T7VLY.js} +1 -1
- package/dist/bundle/chunks/{runtime-PXJK4L7Y.js → runtime-D3KV73AE.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-BEJ4ZJ3D.js → virtual-modules-GSNL3MCU.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/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +7 -1
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +83 -14
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts.map +1 -1
- package/dist/core/builtins/polyphase.js +21 -2
- package/dist/core/builtins/polyphase.js.map +1 -1
- package/dist/core/builtins/subagent.d.ts +59 -2
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +258 -62
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +23 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +2 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +12 -0
- 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 +5 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts +18 -6
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +867 -59
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +6 -2
- package/dist/core/polyphase/approval.d.ts.map +1 -1
- package/dist/core/polyphase/approval.js +23 -35
- package/dist/core/polyphase/approval.js.map +1 -1
- package/dist/core/polyphase/child-events.js +1 -1
- package/dist/core/polyphase/child-events.js.map +1 -1
- package/dist/core/polyphase/child-process.d.ts.map +1 -1
- package/dist/core/polyphase/child-process.js +65 -7
- package/dist/core/polyphase/child-process.js.map +1 -1
- package/dist/core/polyphase/commands.d.ts.map +1 -1
- package/dist/core/polyphase/commands.js +46 -5
- package/dist/core/polyphase/commands.js.map +1 -1
- package/dist/core/polyphase/details.d.ts.map +1 -1
- package/dist/core/polyphase/details.js +5 -0
- package/dist/core/polyphase/details.js.map +1 -1
- package/dist/core/polyphase/permission-bridge.d.ts +128 -0
- package/dist/core/polyphase/permission-bridge.d.ts.map +1 -0
- package/dist/core/polyphase/permission-bridge.js +357 -0
- package/dist/core/polyphase/permission-bridge.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -1
- package/dist/core/polyphase/render/run-block.js +13 -4
- package/dist/core/polyphase/render/run-block.js.map +1 -1
- package/dist/core/polyphase/render/snapshot.d.ts +4 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -1
- package/dist/core/polyphase/render/snapshot.js +4 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -1
- package/dist/core/polyphase/result-text.d.ts.map +1 -1
- package/dist/core/polyphase/result-text.js +23 -3
- package/dist/core/polyphase/result-text.js.map +1 -1
- package/dist/core/polyphase/session.d.ts +15 -1
- package/dist/core/polyphase/session.d.ts.map +1 -1
- package/dist/core/polyphase/session.js +36 -1
- package/dist/core/polyphase/session.js.map +1 -1
- package/dist/core/polyphase/settings.d.ts +1 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -1
- package/dist/core/polyphase/settings.js +1 -1
- package/dist/core/polyphase/settings.js.map +1 -1
- package/dist/core/polyphase/store.d.ts +18 -0
- package/dist/core/polyphase/store.d.ts.map +1 -1
- package/dist/core/polyphase/store.js +38 -0
- package/dist/core/polyphase/store.js.map +1 -1
- package/dist/core/polyphase/types.d.ts +60 -3
- package/dist/core/polyphase/types.d.ts.map +1 -1
- package/dist/core/polyphase/types.js.map +1 -1
- package/dist/core/polyphase/ui/inspector.js +1 -1
- package/dist/core/polyphase/ui/inspector.js.map +1 -1
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/agent-host.js +17 -3
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -1
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/guidance.js +16 -5
- package/dist/core/polyphase/workflow/guidance.js.map +1 -1
- package/dist/core/polyphase/workflow/launch.d.ts +2 -1
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/launch.js +22 -3
- package/dist/core/polyphase/workflow/launch.js.map +1 -1
- package/dist/core/polyphase/workflow/limits.d.ts +80 -0
- package/dist/core/polyphase/workflow/limits.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/limits.js +234 -0
- package/dist/core/polyphase/workflow/limits.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +1 -1
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/runtime.js.map +1 -1
- package/dist/core/polyphase/workflow/tool.d.ts +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -1
- package/dist/core/polyphase/workflow/tool.js +23 -2
- package/dist/core/polyphase/workflow/tool.js.map +1 -1
- package/dist/core/usage-totals.d.ts +5 -0
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +16 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +2 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +3 -0
- package/dist/utils/shell.js.map +1 -1
- package/docs/duet.md +1 -1
- package/docs/environment-variables.md +3 -1
- package/docs/extensions.md +2 -1
- package/docs/keybindings.md +1 -0
- package/docs/polyphase.md +97 -33
- package/docs/settings.md +2 -2
- package/package.json +10 -10
|
@@ -1 +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,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CA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,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,KAAK;QACX,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS;QACT,MAAM;QACN,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM;QAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI;QACzB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YACzB,CAAC,CAAC;gBACA,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBACzC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAC/B,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;aAC3B;YACF,CAAC,CAAC,SAAS;QACZ,MAAM,EAAE,mBAAmB,CAC1B,MAAM,EACN,MAAM,EACN,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,EAC/D,OAAO,CAAC,aAAa,KAAK,SAAS,CACnC;QACD,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,MAAM;QACN,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;QACtB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB;QACjD,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC;KAChC,CAAC;AACH,CAAC","sourcesContent":["/**\n * Render model: a plain-data snapshot of a run, taken either from the live store (`snapshotFromRun`)\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"]}
|
|
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;AAkGvE,SAAS,WAAW;IACnB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACzG,CAAC;AAED,MAAM,eAAe,GAA2B,CAAC,SAAS,EAAE,UAAU,CAAC,CA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CAAC;AACH,CAAC","sourcesContent":["/**\n * Render model: a plain-data snapshot of a run, taken either from the live store (`snapshotFromRun`)\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\ttimeLimit?: { totalMs: number; reached: 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\ttimeLimit:\n\t\t\trun.timeLimit?.totalMs === null || run.timeLimit?.totalMs === undefined\n\t\t\t\t? undefined\n\t\t\t\t: { totalMs: run.timeLimit.totalMs, reached: run.timeLimit.reached },\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\ttimeLimit: details.timeLimit,\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"]}
|
|
@@ -1 +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,YAAY,CAAC;
|
|
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,YAAY,CAAC;AAGnE;;;;GAIG;AAEH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5D,cAAc,CAuBhB;AAuBD,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAGlF;AAgED,wCAAwC;AACxC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAI/F;AA4GD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC/E,MAAM,CAaR;AAED,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAsFD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAqB9F;AAED,oCAAoC;AACpC,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,GAAE,MAAmB,GAAG,MAAM,CAUtF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { billableTokens, extractStatusLine } from "./child-events.js";
|
|
2
|
+
import { formatLimitDuration, formatWorkflowLimitsLine } from "./workflow/limits.js";
|
|
2
3
|
/**
|
|
3
4
|
* Keeps the head and tail of `text`, snapped to line boundaries, with a marker in between.
|
|
4
5
|
* `keepStatusLine` (default true) re-appends the source's last `STATUS: ...` line when the
|
|
@@ -105,7 +106,7 @@ export function formatBlockedNote(count, samples) {
|
|
|
105
106
|
if (count <= 0)
|
|
106
107
|
return undefined;
|
|
107
108
|
const suffix = samples.length > 0 ? `: ${samples.join(", ")}` : "";
|
|
108
|
-
return `${count} tool call(s) inside subagents were blocked because
|
|
109
|
+
return `${count} tool call(s) inside subagents were blocked because they needed approval and nobody could be asked${suffix}. Allow them with rules in permissions.yml, or switch this session with /permissions auto or /yolo and re-run (children inherit the mode at spawn time, so this already-finished run cannot be unblocked in place).`;
|
|
109
110
|
}
|
|
110
111
|
function appendBlockedNote(parts, run) {
|
|
111
112
|
const count = totalBlockedToolCalls(run);
|
|
@@ -113,11 +114,14 @@ function appendBlockedNote(parts, run) {
|
|
|
113
114
|
if (note)
|
|
114
115
|
parts.push(note);
|
|
115
116
|
}
|
|
117
|
+
function cancelReasonWord(reason) {
|
|
118
|
+
return reason === "time" ? "time limit" : (reason ?? "user");
|
|
119
|
+
}
|
|
116
120
|
function formatSingleAgent(agent, now) {
|
|
117
121
|
if (!agent)
|
|
118
122
|
return "";
|
|
119
123
|
if (agent.status === "cancelled") {
|
|
120
|
-
const base = `CANCELLED by ${agent.cancelReason
|
|
124
|
+
const base = `CANCELLED by ${cancelReasonWord(agent.cancelReason)} after ${formatElapsedAgent(agent, now)}`;
|
|
121
125
|
const output = agentOutput(agent);
|
|
122
126
|
return output.length > 0 ? `${base}\n${capHeadTail(output, 8000).text}` : base;
|
|
123
127
|
}
|
|
@@ -267,7 +271,9 @@ function firstNonBlankLine(text) {
|
|
|
267
271
|
function formatWorkflowAgents(run) {
|
|
268
272
|
const lines = run.agents.slice(0, 100).map((agent) => {
|
|
269
273
|
const output = agentOutput(agent);
|
|
270
|
-
const info =
|
|
274
|
+
const info = agent.status === "cancelled"
|
|
275
|
+
? `cancelled (${cancelReasonWord(agent.cancelReason)})`
|
|
276
|
+
: (extractStatusLine(output) ?? firstNonBlankLine(agent.result?.stderr || agent.state.errorMessage || ""));
|
|
271
277
|
return truncateLine(`${agent.label} ${agent.status} ${modelLabel(agent)} ${info}`.trimEnd(), 200);
|
|
272
278
|
});
|
|
273
279
|
return ["Agents:", ...lines].join("\n");
|
|
@@ -276,6 +282,17 @@ function formatBudgetNotice(run) {
|
|
|
276
282
|
const total = run.budget.totalTokens ?? 0;
|
|
277
283
|
return `Budget exhausted: ${formatTokensPlain(run.budget.spentTokens)} / ${formatTokensPlain(total)} tokens; remaining agents were skipped.`;
|
|
278
284
|
}
|
|
285
|
+
function formatTimeLimitNotice(run) {
|
|
286
|
+
return `Time limit of ${formatLimitDuration(run.timeLimit?.totalMs ?? 0)} reached; running and queued agents were cancelled.`;
|
|
287
|
+
}
|
|
288
|
+
/** Reconstructs the run's resolved limits (value + source) from the persisted/live view, for the
|
|
289
|
+
* `Limits:` line every workflow result shows (D-B). */
|
|
290
|
+
function runWorkflowLimits(run) {
|
|
291
|
+
return {
|
|
292
|
+
budgetTokens: { value: run.budget.totalTokens, source: run.workflow?.budgetSource ?? "none" },
|
|
293
|
+
timeLimitMs: { value: run.timeLimit?.totalMs ?? null, source: run.workflow?.timeLimitSource ?? "none" },
|
|
294
|
+
};
|
|
295
|
+
}
|
|
279
296
|
function formatScriptError(outcome) {
|
|
280
297
|
if (outcome.ok || !outcome.errorMessage)
|
|
281
298
|
return undefined;
|
|
@@ -298,10 +315,13 @@ export function formatWorkflowResultText(run, outcome) {
|
|
|
298
315
|
const trailer = [];
|
|
299
316
|
if (run.budget.exhausted)
|
|
300
317
|
trailer.push(formatBudgetNotice(run));
|
|
318
|
+
if (run.timeLimit?.reached)
|
|
319
|
+
trailer.push(formatTimeLimitNotice(run));
|
|
301
320
|
const scriptError = formatScriptError(outcome);
|
|
302
321
|
if (scriptError)
|
|
303
322
|
trailer.push(scriptError);
|
|
304
323
|
appendBlockedNote(trailer, run);
|
|
324
|
+
trailer.push(`Limits: ${formatWorkflowLimitsLine(runWorkflowLimits(run))}`);
|
|
305
325
|
if (trailer.length > 0)
|
|
306
326
|
sections.push(trailer.join("\n"));
|
|
307
327
|
return sections.join("\n\n");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-text.js","sourceRoot":"","sources":["../../../src/core/polyphase/result-text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AActE;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAY,EACZ,QAAgB,EAChB,OAAO,GAAqD,EAAE;IAE9D,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAE9D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;IAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC;IAEtD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAA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MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;QACjF,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,IAAI,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,QAAgB;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACpD,OAAO,UAAU,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC;AAC7F,CAAC","sourcesContent":["import type { JsonValue } from \"@draht/ai\";\nimport { billableTokens, extractStatusLine } from \"./child-events.ts\";\nimport type { 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"]}
|
|
1
|
+
{"version":3,"file":"result-text.js","sourceRoot":"","sources":["../../../src/core/polyphase/result-text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAA+B,MAAM,sBAAsB,CAAC;AAalH;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAY,EACZ,QAAgB,EAChB,OAAO,GAAqD,EAAE;IAE9D,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAE9D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;IAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC;IAEtD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;IAEtD,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IACtE,MA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AgB;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACpD,OAAO,UAAU,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC;AAC7F,CAAC","sourcesContent":["import type { JsonValue } from \"@draht/ai\";\nimport { billableTokens, extractStatusLine } from \"./child-events.ts\";\nimport type { AgentView, RunView, SubagentMode } from \"./types.ts\";\nimport { formatLimitDuration, formatWorkflowLimitsLine, type ResolvedWorkflowLimits } from \"./workflow/limits.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 they needed approval and nobody could be asked${suffix}. Allow them with rules in permissions.yml, or switch this session with /permissions auto or /yolo and re-run (children inherit the mode at spawn time, so this already-finished run cannot be unblocked in place).`;\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 cancelReasonWord(reason: string | undefined): string {\n\treturn reason === \"time\" ? \"time limit\" : (reason ?? \"user\");\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 ${cancelReasonWord(agent.cancelReason)} 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\tagent.status === \"cancelled\"\n\t\t\t\t? `cancelled (${cancelReasonWord(agent.cancelReason)})`\n\t\t\t\t: (extractStatusLine(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 formatTimeLimitNotice(run: RunView): string {\n\treturn `Time limit of ${formatLimitDuration(run.timeLimit?.totalMs ?? 0)} reached; running and queued agents were cancelled.`;\n}\n\n/** Reconstructs the run's resolved limits (value + source) from the persisted/live view, for the\n * `Limits:` line every workflow result shows (D-B). */\nfunction runWorkflowLimits(run: RunView): ResolvedWorkflowLimits {\n\treturn {\n\t\tbudgetTokens: { value: run.budget.totalTokens, source: run.workflow?.budgetSource ?? \"none\" },\n\t\ttimeLimitMs: { value: run.timeLimit?.totalMs ?? null, source: run.workflow?.timeLimitSource ?? \"none\" },\n\t};\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\tif (run.timeLimit?.reached) trailer.push(formatTimeLimitNotice(run));\n\tconst scriptError = formatScriptError(outcome);\n\tif (scriptError) trailer.push(scriptError);\n\tappendBlockedNote(trailer, run);\n\ttrailer.push(`Limits: ${formatWorkflowLimitsLine(runWorkflowLimits(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"]}
|
|
@@ -7,18 +7,32 @@ import type { PolyphaseSettings } from "../settings-manager.ts";
|
|
|
7
7
|
import { AgentLimiter } from "./limiter.ts";
|
|
8
8
|
import { type ResolvedPolyphaseSettings } from "./settings.ts";
|
|
9
9
|
import { PolyphaseStore } from "./store.ts";
|
|
10
|
+
import type { ParsedDirectives } from "./workflow/limits.ts";
|
|
10
11
|
export interface PolyphaseSession {
|
|
11
12
|
readonly store: PolyphaseStore;
|
|
12
13
|
readonly limiter: AgentLimiter;
|
|
13
14
|
settings(): ResolvedPolyphaseSettings;
|
|
14
15
|
/** Re-resolves settings; updates the limiter's capacity and the pump's interval. */
|
|
15
16
|
refreshSettings(raw: PolyphaseSettings | undefined): void;
|
|
16
|
-
/** "
|
|
17
|
+
/** "ask" until a provider is set. */
|
|
17
18
|
permissionMode(): PermissionMode;
|
|
18
19
|
setPermissionModeProvider(provider: () => PermissionMode): void;
|
|
20
|
+
/** The latest user prompt's `+500k`/`+30min`-style directives (D-B), kept until the turn
|
|
21
|
+
* settles (`clearPendingDirectives`). `undefined` when the current/last turn's prompt had none. */
|
|
22
|
+
pendingDirectives(): ParsedDirectives | undefined;
|
|
23
|
+
setPendingDirectives(directives: ParsedDirectives | undefined): void;
|
|
24
|
+
clearPendingDirectives(): void;
|
|
19
25
|
onParentPrompt(listener: () => void): () => void;
|
|
20
26
|
/** The inspector closes so a parent dialog stays reachable. */
|
|
21
27
|
notifyParentPrompt(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Runs `prompt` once every permission dialog queued before it has settled. The TUI has a single
|
|
30
|
+
* dialog slot and a newer dialog displaces the open one, settling it as a refusal, so permission
|
|
31
|
+
* asks from parallel agents must take turns or all but the last would be denied unseen. Once
|
|
32
|
+
* `signal` aborts, `prompt` runs at once instead of waiting its turn, and must then settle
|
|
33
|
+
* without showing anything.
|
|
34
|
+
*/
|
|
35
|
+
runPermissionPrompt<T>(prompt: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
22
36
|
/** Pump interval: `min(100, liveUpdateMs)` while open. */
|
|
23
37
|
setInspectorOpen(open: boolean): void;
|
|
24
38
|
readonly disposed: boolean;
|
|
@@ -1 +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,eAAe,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"session.d.ts","source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AG,IAAI,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AA2HD,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,GAAG,SAAS,GAAG,gBAAgB,CAUrG;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAG/E;AAED,0DAA0D;AAC1D,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM1E"}
|
|
@@ -12,8 +12,10 @@ class PolyphaseSessionImpl {
|
|
|
12
12
|
limiter;
|
|
13
13
|
pump;
|
|
14
14
|
resolved;
|
|
15
|
-
permissionModeProvider = () => "
|
|
15
|
+
permissionModeProvider = () => "ask";
|
|
16
|
+
pendingDirectivesValue;
|
|
16
17
|
parentPromptListeners = new Set();
|
|
18
|
+
permissionPromptTail = Promise.resolve();
|
|
17
19
|
inspectorOpen = false;
|
|
18
20
|
disposedValue = false;
|
|
19
21
|
constructor(raw) {
|
|
@@ -36,6 +38,15 @@ class PolyphaseSessionImpl {
|
|
|
36
38
|
setPermissionModeProvider(provider) {
|
|
37
39
|
this.permissionModeProvider = provider;
|
|
38
40
|
}
|
|
41
|
+
pendingDirectives() {
|
|
42
|
+
return this.pendingDirectivesValue;
|
|
43
|
+
}
|
|
44
|
+
setPendingDirectives(directives) {
|
|
45
|
+
this.pendingDirectivesValue = directives;
|
|
46
|
+
}
|
|
47
|
+
clearPendingDirectives() {
|
|
48
|
+
this.pendingDirectivesValue = undefined;
|
|
49
|
+
}
|
|
39
50
|
onParentPrompt(listener) {
|
|
40
51
|
this.parentPromptListeners.add(listener);
|
|
41
52
|
return () => this.parentPromptListeners.delete(listener);
|
|
@@ -50,6 +61,15 @@ class PolyphaseSessionImpl {
|
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
}
|
|
64
|
+
runPermissionPrompt(prompt, signal) {
|
|
65
|
+
const ahead = this.permissionPromptTail;
|
|
66
|
+
const turn = settledOrAborted(ahead, signal).then(prompt);
|
|
67
|
+
// The next prompt waits for BOTH the dialogs ahead and this one: a prompt that left the queue
|
|
68
|
+
// early because it was aborted must not let the next dialog open over one still showing. A
|
|
69
|
+
// rejection stays with its own caller.
|
|
70
|
+
this.permissionPromptTail = Promise.allSettled([ahead, turn]).then(() => undefined);
|
|
71
|
+
return turn;
|
|
72
|
+
}
|
|
53
73
|
setInspectorOpen(open) {
|
|
54
74
|
this.inspectorOpen = open;
|
|
55
75
|
this.applyPumpInterval();
|
|
@@ -71,6 +91,21 @@ class PolyphaseSessionImpl {
|
|
|
71
91
|
: this.resolved.liveUpdateMs);
|
|
72
92
|
}
|
|
73
93
|
}
|
|
94
|
+
/** Resolves once `promise` settles, or as soon as `signal` aborts, whichever is first. */
|
|
95
|
+
function settledOrAborted(promise, signal) {
|
|
96
|
+
if (!signal)
|
|
97
|
+
return promise;
|
|
98
|
+
if (signal.aborted)
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
const onAbort = () => resolve();
|
|
102
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
103
|
+
void promise.then(() => {
|
|
104
|
+
signal.removeEventListener("abort", onAbort);
|
|
105
|
+
resolve();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
74
109
|
const sessions = new WeakMap();
|
|
75
110
|
function isObjectKey(key) {
|
|
76
111
|
return typeof key === "object" && key !== null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/polyphase/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAkC,wBAA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,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEzD,SAAS,WAAW,CAAC,GAAY;IAChC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;AAChD,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,GAAkC;IAClF,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,+FAA+F;IAC/F,4DAA4D;IAC5D,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QAClC,OAAO,GAAG,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAC;QACxC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAChD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,uBAAuB,CAAC,GAAY,EAAE,MAAc;IACnE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,OAAO;IAC9B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC","sourcesContent":["/**\n * Session-scoped polyphase state, keyed off `ctx.sessionManager` so draht-acp sessions never\n * mix. Created on first use and disposed on `session_shutdown`.\n */\n\nimport type { PermissionMode } from \"../multi-agent/index.ts\";\nimport type { PolyphaseSettings } from \"../settings-manager.ts\";\nimport { AgentLimiter } from \"./limiter.ts\";\nimport { type ResolvedPolyphaseSettings, resolvePolyphaseSettings } from \"./settings.ts\";\nimport { PolyphaseStore } from \"./store.ts\";\nimport { createUpdatePump, type UpdatePump } from \"./update-pump.ts\";\n\nconst INSPECTOR_INTERVAL_CAP_MS = 100;\n\nexport interface PolyphaseSession {\n\treadonly store: PolyphaseStore;\n\treadonly limiter: AgentLimiter;\n\tsettings(): ResolvedPolyphaseSettings;\n\t/** Re-resolves settings; updates the limiter's capacity and the pump's interval. */\n\trefreshSettings(raw: PolyphaseSettings | undefined): void;\n\t/** \"default\" until a provider is set. */\n\tpermissionMode(): PermissionMode;\n\tsetPermissionModeProvider(provider: () => PermissionMode): void;\n\tonParentPrompt(listener: () => void): () => void;\n\t/** The inspector closes so a parent dialog stays reachable. */\n\tnotifyParentPrompt(): void;\n\t/** Pump interval: `min(100, liveUpdateMs)` while open. */\n\tsetInspectorOpen(open: boolean): void;\n\treadonly disposed: boolean;\n\tdispose(reason: string): void;\n}\n\nclass PolyphaseSessionImpl implements PolyphaseSession {\n\treadonly store: PolyphaseStore;\n\treadonly limiter: AgentLimiter;\n\n\tprivate readonly pump: UpdatePump;\n\tprivate resolved: ResolvedPolyphaseSettings;\n\tprivate permissionModeProvider: () => PermissionMode = () => \"default\";\n\tprivate readonly parentPromptListeners = new Set<() => void>();\n\tprivate inspectorOpen = false;\n\tprivate disposedValue = false;\n\n\tconstructor(raw: PolyphaseSettings | undefined) {\n\t\tthis.resolved = resolvePolyphaseSettings(raw);\n\t\tthis.limiter = new AgentLimiter(this.resolved.maxConcurrency);\n\t\tthis.pump = createUpdatePump({ intervalMs: this.resolved.liveUpdateMs });\n\t\tthis.store = new PolyphaseStore({ pump: this.pump, retainRuns: this.resolved.retainRuns });\n\t}\n\n\tsettings(): ResolvedPolyphaseSettings {\n\t\treturn this.resolved;\n\t}\n\n\trefreshSettings(raw: PolyphaseSettings | undefined): void {\n\t\tthis.resolved = resolvePolyphaseSettings(raw);\n\t\tthis.limiter.setCapacity(this.resolved.maxConcurrency);\n\t\tthis.applyPumpInterval();\n\t}\n\n\tpermissionMode(): PermissionMode {\n\t\treturn this.permissionModeProvider();\n\t}\n\n\tsetPermissionModeProvider(provider: () => PermissionMode): void {\n\t\tthis.permissionModeProvider = provider;\n\t}\n\n\tonParentPrompt(listener: () => void): () => void {\n\t\tthis.parentPromptListeners.add(listener);\n\t\treturn () => this.parentPromptListeners.delete(listener);\n\t}\n\n\tnotifyParentPrompt(): void {\n\t\tfor (const listener of this.parentPromptListeners) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// An inspector-close listener must not block the parent prompt it is making way for.\n\t\t\t}\n\t\t}\n\t}\n\n\tsetInspectorOpen(open: boolean): void {\n\t\tthis.inspectorOpen = open;\n\t\tthis.applyPumpInterval();\n\t}\n\n\tget disposed(): boolean {\n\t\treturn this.disposedValue;\n\t}\n\n\tdispose(reason: string): void {\n\t\tif (this.disposedValue) return;\n\t\tthis.disposedValue = true;\n\t\tthis.store.dispose();\n\t\tthis.limiter.rejectAll(new Error(reason));\n\t\tthis.parentPromptListeners.clear();\n\t}\n\n\tprivate applyPumpInterval(): void {\n\t\tthis.pump.setIntervalMs(\n\t\t\tthis.inspectorOpen\n\t\t\t\t? Math.min(INSPECTOR_INTERVAL_CAP_MS, this.resolved.liveUpdateMs)\n\t\t\t\t: this.resolved.liveUpdateMs,\n\t\t);\n\t}\n}\n\nconst sessions = new WeakMap<object, PolyphaseSession>();\n\nfunction isObjectKey(key: unknown): key is object {\n\treturn typeof key === \"object\" && key !== null;\n}\n\n/** Creates on first use; refreshes settings on every call. `key` is `ctx.sessionManager`. */\nexport function getPolyphaseSession(key: object, raw: PolyphaseSettings | undefined): PolyphaseSession {\n\tlet session = sessions.get(key);\n\t// A session disposed directly (not through disposePolyphaseSession) leaves a dead entry in the\n\t// map: its pump is disposed, so it would never flush again.\n\tif (!session || session.disposed) {\n\t\tsession = new PolyphaseSessionImpl(raw);\n\t\tsessions.set(key, session);\n\t}\n\tsession.refreshSettings(raw);\n\treturn session;\n}\n\n/** Returns undefined for non-object keys (tests pass contexts without `sessionManager`). */\nexport function peekPolyphaseSession(key: unknown): PolyphaseSession | undefined {\n\tif (!isObjectKey(key)) return undefined;\n\treturn sessions.get(key);\n}\n\n/** Idempotent: disposes and deletes the entry, if any. */\nexport function disposePolyphaseSession(key: unknown, reason: string): void {\n\tif (!isObjectKey(key)) return;\n\tconst session = sessions.get(key);\n\tif (!session) return;\n\tsession.dispose(reason);\n\tsessions.delete(key);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/polyphase/session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAkC,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAGrE,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAiCtC,MAAM,oBAAoB;IAChB,KAAK,CAAiB;IACtB,OAAO,CAAe;IAEd,IAAI,CAAa;IAC1B,QAAQ,CAA4B;IACpC,sBAAsB,GAAyB,GAAG,EAAE,CAAC,KAAK,CAAC;IAC3D,sBAAsB,CAA+B;IAC5C,qBAAqB,GAAG,IAAI,GAAG,EAAc,CAAC;IACvD,oBAAoB,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACxD,aAAa,GAAG,KAAK,CAAC;IACtB,aAAa,GAAG,KAAK,CAAC;IAE9B,YAAY,GAAkC;QAC7C,IAAI,CAAC,QAAQ,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CA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AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAChD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,uBAAuB,CAAC,GAAY,EAAE,MAAc;IACnE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,OAAO;IAC9B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC","sourcesContent":["/**\n * Session-scoped polyphase state, keyed off `ctx.sessionManager` so draht-acp sessions never\n * mix. Created on first use and disposed on `session_shutdown`.\n */\n\nimport type { PermissionMode } from \"../multi-agent/index.ts\";\nimport type { PolyphaseSettings } from \"../settings-manager.ts\";\nimport { AgentLimiter } from \"./limiter.ts\";\nimport { type ResolvedPolyphaseSettings, resolvePolyphaseSettings } from \"./settings.ts\";\nimport { PolyphaseStore } from \"./store.ts\";\nimport { createUpdatePump, type UpdatePump } from \"./update-pump.ts\";\nimport type { ParsedDirectives } from \"./workflow/limits.ts\";\n\nconst INSPECTOR_INTERVAL_CAP_MS = 100;\n\nexport interface PolyphaseSession {\n\treadonly store: PolyphaseStore;\n\treadonly limiter: AgentLimiter;\n\tsettings(): ResolvedPolyphaseSettings;\n\t/** Re-resolves settings; updates the limiter's capacity and the pump's interval. */\n\trefreshSettings(raw: PolyphaseSettings | undefined): void;\n\t/** \"ask\" until a provider is set. */\n\tpermissionMode(): PermissionMode;\n\tsetPermissionModeProvider(provider: () => PermissionMode): void;\n\t/** The latest user prompt's `+500k`/`+30min`-style directives (D-B), kept until the turn\n\t * settles (`clearPendingDirectives`). `undefined` when the current/last turn's prompt had none. */\n\tpendingDirectives(): ParsedDirectives | undefined;\n\tsetPendingDirectives(directives: ParsedDirectives | undefined): void;\n\tclearPendingDirectives(): void;\n\tonParentPrompt(listener: () => void): () => void;\n\t/** The inspector closes so a parent dialog stays reachable. */\n\tnotifyParentPrompt(): void;\n\t/**\n\t * Runs `prompt` once every permission dialog queued before it has settled. The TUI has a single\n\t * dialog slot and a newer dialog displaces the open one, settling it as a refusal, so permission\n\t * asks from parallel agents must take turns or all but the last would be denied unseen. Once\n\t * `signal` aborts, `prompt` runs at once instead of waiting its turn, and must then settle\n\t * without showing anything.\n\t */\n\trunPermissionPrompt<T>(prompt: () => Promise<T>, signal?: AbortSignal): Promise<T>;\n\t/** Pump interval: `min(100, liveUpdateMs)` while open. */\n\tsetInspectorOpen(open: boolean): void;\n\treadonly disposed: boolean;\n\tdispose(reason: string): void;\n}\n\nclass PolyphaseSessionImpl implements PolyphaseSession {\n\treadonly store: PolyphaseStore;\n\treadonly limiter: AgentLimiter;\n\n\tprivate readonly pump: UpdatePump;\n\tprivate resolved: ResolvedPolyphaseSettings;\n\tprivate permissionModeProvider: () => PermissionMode = () => \"ask\";\n\tprivate pendingDirectivesValue: ParsedDirectives | undefined;\n\tprivate readonly parentPromptListeners = new Set<() => void>();\n\tprivate permissionPromptTail: Promise<void> = Promise.resolve();\n\tprivate inspectorOpen = false;\n\tprivate disposedValue = false;\n\n\tconstructor(raw: PolyphaseSettings | undefined) {\n\t\tthis.resolved = resolvePolyphaseSettings(raw);\n\t\tthis.limiter = new AgentLimiter(this.resolved.maxConcurrency);\n\t\tthis.pump = createUpdatePump({ intervalMs: this.resolved.liveUpdateMs });\n\t\tthis.store = new PolyphaseStore({ pump: this.pump, retainRuns: this.resolved.retainRuns });\n\t}\n\n\tsettings(): ResolvedPolyphaseSettings {\n\t\treturn this.resolved;\n\t}\n\n\trefreshSettings(raw: PolyphaseSettings | undefined): void {\n\t\tthis.resolved = resolvePolyphaseSettings(raw);\n\t\tthis.limiter.setCapacity(this.resolved.maxConcurrency);\n\t\tthis.applyPumpInterval();\n\t}\n\n\tpermissionMode(): PermissionMode {\n\t\treturn this.permissionModeProvider();\n\t}\n\n\tsetPermissionModeProvider(provider: () => PermissionMode): void {\n\t\tthis.permissionModeProvider = provider;\n\t}\n\n\tpendingDirectives(): ParsedDirectives | undefined {\n\t\treturn this.pendingDirectivesValue;\n\t}\n\n\tsetPendingDirectives(directives: ParsedDirectives | undefined): void {\n\t\tthis.pendingDirectivesValue = directives;\n\t}\n\n\tclearPendingDirectives(): void {\n\t\tthis.pendingDirectivesValue = undefined;\n\t}\n\n\tonParentPrompt(listener: () => void): () => void {\n\t\tthis.parentPromptListeners.add(listener);\n\t\treturn () => this.parentPromptListeners.delete(listener);\n\t}\n\n\tnotifyParentPrompt(): void {\n\t\tfor (const listener of this.parentPromptListeners) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// An inspector-close listener must not block the parent prompt it is making way for.\n\t\t\t}\n\t\t}\n\t}\n\n\trunPermissionPrompt<T>(prompt: () => Promise<T>, signal?: AbortSignal): Promise<T> {\n\t\tconst ahead = this.permissionPromptTail;\n\t\tconst turn = settledOrAborted(ahead, signal).then(prompt);\n\t\t// The next prompt waits for BOTH the dialogs ahead and this one: a prompt that left the queue\n\t\t// early because it was aborted must not let the next dialog open over one still showing. A\n\t\t// rejection stays with its own caller.\n\t\tthis.permissionPromptTail = Promise.allSettled([ahead, turn]).then(() => undefined);\n\t\treturn turn;\n\t}\n\n\tsetInspectorOpen(open: boolean): void {\n\t\tthis.inspectorOpen = open;\n\t\tthis.applyPumpInterval();\n\t}\n\n\tget disposed(): boolean {\n\t\treturn this.disposedValue;\n\t}\n\n\tdispose(reason: string): void {\n\t\tif (this.disposedValue) return;\n\t\tthis.disposedValue = true;\n\t\tthis.store.dispose();\n\t\tthis.limiter.rejectAll(new Error(reason));\n\t\tthis.parentPromptListeners.clear();\n\t}\n\n\tprivate applyPumpInterval(): void {\n\t\tthis.pump.setIntervalMs(\n\t\t\tthis.inspectorOpen\n\t\t\t\t? Math.min(INSPECTOR_INTERVAL_CAP_MS, this.resolved.liveUpdateMs)\n\t\t\t\t: this.resolved.liveUpdateMs,\n\t\t);\n\t}\n}\n\n/** Resolves once `promise` settles, or as soon as `signal` aborts, whichever is first. */\nfunction settledOrAborted(promise: Promise<void>, signal: AbortSignal | undefined): Promise<void> {\n\tif (!signal) return promise;\n\tif (signal.aborted) return Promise.resolve();\n\treturn new Promise<void>((resolve) => {\n\t\tconst onAbort = () => resolve();\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(() => {\n\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nconst sessions = new WeakMap<object, PolyphaseSession>();\n\nfunction isObjectKey(key: unknown): key is object {\n\treturn typeof key === \"object\" && key !== null;\n}\n\n/** Creates on first use; refreshes settings on every call. `key` is `ctx.sessionManager`. */\nexport function getPolyphaseSession(key: object, raw: PolyphaseSettings | undefined): PolyphaseSession {\n\tlet session = sessions.get(key);\n\t// A session disposed directly (not through disposePolyphaseSession) leaves a dead entry in the\n\t// map: its pump is disposed, so it would never flush again.\n\tif (!session || session.disposed) {\n\t\tsession = new PolyphaseSessionImpl(raw);\n\t\tsessions.set(key, session);\n\t}\n\tsession.refreshSettings(raw);\n\treturn session;\n}\n\n/** Returns undefined for non-object keys (tests pass contexts without `sessionManager`). */\nexport function peekPolyphaseSession(key: unknown): PolyphaseSession | undefined {\n\tif (!isObjectKey(key)) return undefined;\n\treturn sessions.get(key);\n}\n\n/** Idempotent: disposes and deletes the entry, if any. */\nexport function disposePolyphaseSession(key: unknown, reason: string): void {\n\tif (!isObjectKey(key)) return;\n\tconst session = sessions.get(key);\n\tif (!session) return;\n\tsession.dispose(reason);\n\tsessions.delete(key);\n}\n"]}
|
|
@@ -14,5 +14,6 @@ export interface ResolvedPolyphaseSettings {
|
|
|
14
14
|
workflowTimeoutMs: number;
|
|
15
15
|
warnings: string[];
|
|
16
16
|
}
|
|
17
|
+
export declare const MAX_SET_TIMEOUT_MS = 2147483647;
|
|
17
18
|
export declare function resolvePolyphaseSettings(raw: PolyphaseSettings | undefined, cpuCount?: number): ResolvedPolyphaseSettings;
|
|
18
19
|
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/settings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,MAAM,WAAW,yBAAyB;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/settings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,MAAM,WAAW,yBAAyB;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAOD,eAAO,MAAM,kBAAkB,aAAgB,CAAC;AAyChD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,iBAAiB,GAAG,SAAS,EAClC,QAAQ,GAAE,MAA+B,GACvC,yBAAyB,CAyE3B"}
|
|
@@ -4,7 +4,7 @@ const KEYWORD_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{2,31}$/;
|
|
|
4
4
|
const WORKFLOW_TOOL_VALUES = new Set(["keyword", "always", "off"]);
|
|
5
5
|
const MIN_DEFAULT_BUDGET_TOKENS = 1000;
|
|
6
6
|
// Node's setTimeout silently truncates any larger delay to 1ms (TimeoutOverflowWarning).
|
|
7
|
-
const MAX_SET_TIMEOUT_MS = 2_147_483_647;
|
|
7
|
+
export const MAX_SET_TIMEOUT_MS = 2_147_483_647;
|
|
8
8
|
// Settings files are untyped JSON at runtime; a field declared `number` in PolyphaseSettings can
|
|
9
9
|
// still arrive as a string, null or NaN from a hand-edited settings.json.
|
|
10
10
|
function resolveClampedInt(raw, fieldName, fallback, min, max, warnings) {
|