@draht/coding-agent 2026.10.4-3 → 2026.10.8-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +32 -6
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/{chunk-JTLUBTZT.js → chunk-6QIFWMDF.js} +1 -1
- package/dist/bundle/chunks/{chunk-AFL4IDSI.js → chunk-AHGUOQPH.js} +2 -2
- package/dist/bundle/chunks/{chunk-VPYAVQLP.js → chunk-BOGY4QVF.js} +4 -4
- package/dist/bundle/chunks/chunk-GD2WVXWT.js +65 -0
- package/dist/bundle/chunks/{chunk-3HF756LN.js → chunk-KJJJSTND.js} +292 -153
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +107 -0
- package/dist/bundle/chunks/chunk-QVFELZW2.js +312 -0
- package/dist/bundle/chunks/{chunk-V5HG6S2T.js → chunk-QVTLBSTH.js} +1 -1
- package/dist/bundle/chunks/{chunk-A4OX5CPR.js → chunk-U6LDZZGM.js} +1 -1
- package/dist/bundle/chunks/{chunk-XO3IECI5.js → chunk-VQOV5VFH.js} +1 -1
- package/dist/bundle/chunks/{cli-L74YA5GF.js → cli-O6OWCY7N.js} +1 -1
- package/dist/bundle/chunks/execute-4JU5WQXP.js +18 -0
- package/dist/bundle/chunks/google-antigravity.js +1 -1
- package/dist/bundle/chunks/google-gemini-cli.js +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/openrouter.js +1 -1
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-RYUR6LRB.js → runtime-FIGQHW75.js} +1 -1
- package/dist/bundle/chunks/runtime-TJ3EAMJK.js +3 -0
- package/dist/bundle/chunks/{settings-manager-CHEMMAGQ.js → settings-manager-HC5RR36T.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-UIGTRGHQ.js +2 -0
- package/dist/bundle/chunks/xai.js +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.js +3 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +5 -2
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +65 -27
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +2 -0
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts +15 -0
- package/dist/core/builtins/polyphase.d.ts.map +1 -0
- package/dist/core/builtins/polyphase.js +196 -0
- package/dist/core/builtins/polyphase.js.map +1 -0
- package/dist/core/builtins/subagent.d.ts +44 -34
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +827 -560
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/types.d.ts +17 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +30 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-resolver.js +4 -4
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -1
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +35 -0
- package/dist/core/polyphase/approval.d.ts.map +1 -0
- package/dist/core/polyphase/approval.js +184 -0
- package/dist/core/polyphase/approval.js.map +1 -0
- package/dist/core/polyphase/child-events.d.ts +107 -0
- package/dist/core/polyphase/child-events.d.ts.map +1 -0
- package/dist/core/polyphase/child-events.js +862 -0
- package/dist/core/polyphase/child-events.js.map +1 -0
- package/dist/core/polyphase/child-process.d.ts +65 -0
- package/dist/core/polyphase/child-process.d.ts.map +1 -0
- package/dist/core/polyphase/child-process.js +361 -0
- package/dist/core/polyphase/child-process.js.map +1 -0
- package/dist/core/polyphase/commands.d.ts +44 -0
- package/dist/core/polyphase/commands.d.ts.map +1 -0
- package/dist/core/polyphase/commands.js +244 -0
- package/dist/core/polyphase/commands.js.map +1 -0
- package/dist/core/polyphase/details.d.ts +40 -0
- package/dist/core/polyphase/details.d.ts.map +1 -0
- package/dist/core/polyphase/details.js +538 -0
- package/dist/core/polyphase/details.js.map +1 -0
- package/dist/core/polyphase/emitter.d.ts +20 -0
- package/dist/core/polyphase/emitter.d.ts.map +1 -0
- package/dist/core/polyphase/emitter.js +90 -0
- package/dist/core/polyphase/emitter.js.map +1 -0
- package/dist/core/polyphase/jsonl-reader.d.ts +31 -0
- package/dist/core/polyphase/jsonl-reader.d.ts.map +1 -0
- package/dist/core/polyphase/jsonl-reader.js +161 -0
- package/dist/core/polyphase/jsonl-reader.js.map +1 -0
- package/dist/core/polyphase/keyword.d.ts +27 -0
- package/dist/core/polyphase/keyword.d.ts.map +1 -0
- package/dist/core/polyphase/keyword.js +97 -0
- package/dist/core/polyphase/keyword.js.map +1 -0
- package/dist/core/polyphase/limiter.d.ts +38 -0
- package/dist/core/polyphase/limiter.d.ts.map +1 -0
- package/dist/core/polyphase/limiter.js +129 -0
- package/dist/core/polyphase/limiter.js.map +1 -0
- package/dist/core/polyphase/model-selection.d.ts +35 -0
- package/dist/core/polyphase/model-selection.d.ts.map +1 -0
- package/dist/core/polyphase/model-selection.js +72 -0
- package/dist/core/polyphase/model-selection.js.map +1 -0
- package/dist/core/polyphase/render/format.d.ts +52 -0
- package/dist/core/polyphase/render/format.d.ts.map +1 -0
- package/dist/core/polyphase/render/format.js +169 -0
- package/dist/core/polyphase/render/format.js.map +1 -0
- package/dist/core/polyphase/render/renderers.d.ts +63 -0
- package/dist/core/polyphase/render/renderers.d.ts.map +1 -0
- package/dist/core/polyphase/render/renderers.js +277 -0
- package/dist/core/polyphase/render/renderers.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts +45 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -0
- package/dist/core/polyphase/render/run-block.js +843 -0
- package/dist/core/polyphase/render/run-block.js.map +1 -0
- package/dist/core/polyphase/render/snapshot.d.ts +106 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -0
- package/dist/core/polyphase/render/snapshot.js +292 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -0
- package/dist/core/polyphase/result-text.d.ts +41 -0
- package/dist/core/polyphase/result-text.d.ts.map +1 -0
- package/dist/core/polyphase/result-text.js +326 -0
- package/dist/core/polyphase/result-text.js.map +1 -0
- package/dist/core/polyphase/session.d.ts +33 -0
- package/dist/core/polyphase/session.d.ts.map +1 -0
- package/dist/core/polyphase/session.js +106 -0
- package/dist/core/polyphase/session.js.map +1 -0
- package/dist/core/polyphase/settings.d.ts +18 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -0
- package/dist/core/polyphase/settings.js +93 -0
- package/dist/core/polyphase/settings.js.map +1 -0
- package/dist/core/polyphase/store.d.ts +197 -0
- package/dist/core/polyphase/store.d.ts.map +1 -0
- package/dist/core/polyphase/store.js +558 -0
- package/dist/core/polyphase/store.js.map +1 -0
- package/dist/core/polyphase/types.d.ts +371 -0
- package/dist/core/polyphase/types.d.ts.map +1 -0
- package/dist/core/polyphase/types.js +36 -0
- package/dist/core/polyphase/types.js.map +1 -0
- package/dist/core/polyphase/ui/controller.d.ts +28 -0
- package/dist/core/polyphase/ui/controller.d.ts.map +1 -0
- package/dist/core/polyphase/ui/controller.js +150 -0
- package/dist/core/polyphase/ui/controller.js.map +1 -0
- package/dist/core/polyphase/ui/dock.d.ts +27 -0
- package/dist/core/polyphase/ui/dock.d.ts.map +1 -0
- package/dist/core/polyphase/ui/dock.js +121 -0
- package/dist/core/polyphase/ui/dock.js.map +1 -0
- package/dist/core/polyphase/ui/inspector.d.ts +117 -0
- package/dist/core/polyphase/ui/inspector.d.ts.map +1 -0
- package/dist/core/polyphase/ui/inspector.js +1016 -0
- package/dist/core/polyphase/ui/inspector.js.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts +55 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.js +210 -0
- package/dist/core/polyphase/ui/transcript-layout.js.map +1 -0
- package/dist/core/polyphase/update-pump.d.ts +18 -0
- package/dist/core/polyphase/update-pump.d.ts.map +1 -0
- package/dist/core/polyphase/update-pump.js +132 -0
- package/dist/core/polyphase/update-pump.js.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts +26 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.js +187 -0
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -0
- package/dist/core/polyphase/workflow/guidance.d.ts +19 -0
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/guidance.js +119 -0
- package/dist/core/polyphase/workflow/guidance.js.map +1 -0
- package/dist/core/polyphase/workflow/launch.d.ts +41 -0
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/launch.js +173 -0
- package/dist/core/polyphase/workflow/launch.js.map +1 -0
- package/dist/core/polyphase/workflow/meta.d.ts +43 -0
- package/dist/core/polyphase/workflow/meta.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/meta.js +529 -0
- package/dist/core/polyphase/workflow/meta.js.map +1 -0
- package/dist/core/polyphase/workflow/prelude.d.ts +24 -0
- package/dist/core/polyphase/workflow/prelude.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/prelude.js +93 -0
- package/dist/core/polyphase/workflow/prelude.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +79 -0
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.js +217 -0
- package/dist/core/polyphase/workflow/runtime.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js.map +1 -0
- package/dist/core/polyphase/workflow/saved.d.ts +55 -0
- package/dist/core/polyphase/workflow/saved.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/saved.js +299 -0
- package/dist/core/polyphase/workflow/saved.js.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts +22 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.js +66 -0
- package/dist/core/polyphase/workflow/structured-output.js.map +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts +24 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/tool.js +139 -0
- package/dist/core/polyphase/workflow/tool.js.map +1 -0
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +27 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/socket-server/permission-relay.js +4 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -1
- package/dist/core/trust-manager.d.ts +3 -2
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +5 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/experimental/micro/runtime.js +1 -1
- package/dist/experimental/micro/runtime.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +18 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +11 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +9 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +7 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/docs.json +4 -0
- package/docs/duet.md +3 -3
- package/docs/environment-variables.md +11 -0
- package/docs/json.md +7 -0
- package/docs/keybindings.md +20 -0
- package/docs/polyphase.md +391 -0
- package/docs/rpc-commands.md +9 -9
- package/docs/settings.md +12 -0
- package/docs/virtual-models.md +3 -3
- package/examples/extensions/preset.ts +3 -3
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +1 -1
- package/examples/extensions/subagent/agents/worker.md +1 -1
- package/examples/extensions/summarize.ts +3 -3
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/package.json +10 -10
- package/prompts/commands/orchestrate.md +1 -1
- package/dist/bundle/chunks/chunk-SPZUYYP5.js +0 -170
- package/dist/bundle/chunks/execute-EMOVNTD6.js +0 -328
- package/dist/bundle/chunks/virtual-modules-OC56AAJ7.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-process.js","sourceRoot":"","sources":["../../../src/core/polyphase/child-process.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,I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,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACtD,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACX,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAsB;IAC9D,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,CAC1D,aAAa,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["/**\n * Spawns and supervises one child draht process for a subagent/workflow run (§7.1-7.4).\n *\n * `buildChildInvocation` and `resolveDrahtCommand` are pure; `runChildAgent` owns every\n * side effect (temp files, spawn, line reading, abort escalation) and never rejects.\n */\n\nimport { type ChildProcessWithoutNullStreams, spawn } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport type { JsonObject, JsonValue } from \"@draht/ai\";\nimport { validateToolArguments } from \"@draht/ai\";\nimport type { TSchema } from \"typebox\";\nimport { isBunBinary } from \"../../config.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport {\n\tChildEventReducer,\n\ttype ChildExit,\n\ttype ChildFinish,\n\ttype ChildWireRecord,\n\tparseChildLine,\n\tsummarizeToolArgs,\n\ttoRunResult,\n} from \"./child-events.ts\";\nimport { attachChildLineReader } from \"./jsonl-reader.ts\";\nimport {\n\ttype AgentConfig,\n\ttype AgentRunContext,\n\ttype AgentRunner,\n\tcurrentPolyphaseDepth,\n\tDUET_DELEGATE_TOOL_NAME,\n\tPOLYPHASE_DEPTH_ENV,\n\tPOLYPHASE_RESULT_TOOL_NAME,\n\tPOLYPHASE_SCHEMA_FILE_ENV,\n\ttype ProgressFn,\n\ttype RunResult,\n\ttype TranscriptItem,\n\tWORKFLOW_TOOL_NAME,\n} from \"./types.ts\";\n\nconst DEFAULT_KILL_GRACE_MS = 5000;\nconst LEGACY_TOOL_SUMMARY_MAX_CHARS = 60;\nconst LEGACY_TEXT_PROGRESS_MAX_CHARS = 80;\nconst INSPECT_OR_DEBUG_FLAG = /^--(?:inspect|debug)/;\nconst STRUCTURED_OUTPUT_NOTICE_MAX_CHARS = 200;\n\nexport interface ChildCommand {\n\tbin: string;\n\targsPrefix: readonly string[];\n}\n\n/**\n * Bun binary: `{execPath, []}`. Otherwise `{execPath, [...execArgv without --inspect*\n * and --debug*, argv[1]]}`, which keeps tsx (and other loader-based dev runs) working in children.\n */\nexport function resolveDrahtCommand(): ChildCommand {\n\tif (isBunBinary) return { bin: process.execPath, argsPrefix: [] };\n\tconst execArgv = process.execArgv.filter((arg) => !INSPECT_OR_DEBUG_FLAG.test(arg));\n\treturn { bin: process.execPath, argsPrefix: [...execArgv, process.argv[1]] };\n}\n\nexport interface ChildSpawnSpec {\n\tcwd: string;\n\tagent: AgentConfig;\n\ttask: string;\n\tstep?: number;\n\trun?: AgentRunContext;\n\tsignal?: AbortSignal;\n\tonProgress?: ProgressFn;\n\tcommand?: ChildCommand;\n\t/** Grace period between SIGTERM and SIGKILL-via-tree on abort. Default 5000. */\n\tkillGraceMs?: number;\n\tbaseEnv?: NodeJS.ProcessEnv;\n}\n\n/** Pure: computes argv and env for one spawn. `files` are temp paths already written by the caller. */\nexport function buildChildInvocation(\n\tspec: ChildSpawnSpec,\n\tfiles: { systemPromptFile?: string; schemaFile?: string },\n\toptions?: { omitModel?: boolean },\n): { args: string[]; env: NodeJS.ProcessEnv } {\n\tconst { agent, run } = spec;\n\tconst omitModel = options?.omitModel ?? false;\n\tconst args: string[] = [\"--mode\", \"json\", \"-p\", \"--no-session\"];\n\n\tconst model = run?.model ?? agent.model;\n\tif (!omitModel && model) args.push(\"--model\", model);\n\tif (!omitModel && run?.thinking) args.push(\"--thinking\", run.thinking);\n\n\tif (agent.tools?.length) {\n\t\tconst tools = [...agent.tools, ...(run?.extraTools ?? [])];\n\t\targs.push(\"--tools\", tools.join(\",\"));\n\t}\n\n\tif (agent.disableExtensions) args.push(\"--no-extensions\");\n\n\tconst excludeTools = [WORKFLOW_TOOL_NAME, DUET_DELEGATE_TOOL_NAME, ...(run?.excludeTools ?? [])];\n\targs.push(\"--exclude-tools\", [...new Set(excludeTools)].join(\",\"));\n\n\tif (files.systemPromptFile) args.push(\"--append-system-prompt\", files.systemPromptFile);\n\n\tconst baseEnv = spec.baseEnv ?? process.env;\n\tconst env: NodeJS.ProcessEnv = { ...baseEnv, ...(run?.env ?? {}) };\n\tenv[POLYPHASE_DEPTH_ENV] = String(currentPolyphaseDepth(baseEnv) + 1);\n\tif (files.schemaFile) {\n\t\tenv[POLYPHASE_SCHEMA_FILE_ENV] = files.schemaFile;\n\t} else {\n\t\tdelete env[POLYPHASE_SCHEMA_FILE_ENV];\n\t}\n\n\treturn { args, env };\n}\n\nfunction truncateProgress(text: string, max: number): string {\n\treturn text.length > max ? `${text.slice(0, max)}...` : text;\n}\n\n/**\n * Legacy `onProgress` strings duet relies on: a short line on every tool start, and one line for\n * the first delta of each new text item (a cheap \"what is it writing\" signal, not a transcript).\n */\nfunction legacyProgressText(record: ChildWireRecord, pendingFirstDelta: Set<number>): string | undefined {\n\tif (record.type === \"tool_execution_start\") {\n\t\tconst summary = truncateProgress(\n\t\t\tsummarizeToolArgs(record.toolName, record.args as JsonValue | undefined),\n\t\t\tLEGACY_TOOL_SUMMARY_MAX_CHARS,\n\t\t);\n\t\treturn summary ? `${record.toolName} ${summary}` : record.toolName;\n\t}\n\tif (record.type === \"message_update\") {\n\t\tconst event = record.assistantMessageEvent;\n\t\tif (event.type === \"text_start\") {\n\t\t\tpendingFirstDelta.add(event.contentIndex);\n\t\t\treturn undefined;\n\t\t}\n\t\tif (event.type === \"text_delta\" && pendingFirstDelta.delete(event.contentIndex)) {\n\t\t\tconst firstLine = event.delta.split(\"\\n\")[0] ?? \"\";\n\t\t\treturn truncateProgress(firstLine, LEGACY_TEXT_PROGRESS_MAX_CHARS);\n\t\t}\n\t}\n\treturn undefined;\n}\n\ninterface SpawnAttemptResult {\n\texit: ChildExit;\n\tfinish: ChildFinish;\n}\n\n/** One spawn: wires the line reader, stderr tail, abort escalation, and resolves via `reducer.finish`. */\nfunction spawnAttempt(\n\tspec: ChildSpawnSpec,\n\tcommand: ChildCommand,\n\treducer: ChildEventReducer,\n\tfiles: { systemPromptFile?: string; schemaFile?: string },\n\toptions: { omitModel?: boolean },\n): Promise<SpawnAttemptResult> {\n\tconst killGraceMs = spec.killGraceMs ?? DEFAULT_KILL_GRACE_MS;\n\tconst { args, env } = buildChildInvocation(spec, files, options);\n\n\treturn new Promise<SpawnAttemptResult>((resolve) => {\n\t\tlet settled = false;\n\t\tlet closed = false;\n\t\tlet killTimer: NodeJS.Timeout | undefined;\n\t\tlet proc: ChildProcessWithoutNullStreams;\n\n\t\tconst finishOnce = (exit: ChildExit) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (killTimer) clearTimeout(killTimer);\n\t\t\tif (spec.signal) spec.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve({ exit, finish: reducer.finish(exit) });\n\t\t};\n\n\t\tfunction onAbort(): void {\n\t\t\tif (settled) return;\n\t\t\ttry {\n\t\t\t\tproc.kill(\"SIGTERM\");\n\t\t\t} catch {}\n\t\t\tkillTimer = setTimeout(() => {\n\t\t\t\tif (!closed && proc.pid !== undefined) killProcessTree(proc.pid);\n\t\t\t}, killGraceMs);\n\t\t\tkillTimer.unref();\n\t\t}\n\n\t\ttry {\n\t\t\tproc = spawn(command.bin, [...command.argsPrefix, ...args], {\n\t\t\t\tcwd: spec.cwd,\n\t\t\t\tenv,\n\t\t\t\tshell: false,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tfinishOnce({\n\t\t\t\tcode: null,\n\t\t\t\tsignal: null,\n\t\t\t\tcancelled: spec.signal?.aborted === true,\n\t\t\t\tspawnError: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst pid = proc.pid;\n\t\tif (pid !== undefined) trackDetachedChildPid(pid);\n\t\ttry {\n\t\t\tspec.run?.onStart?.({ pid, argv: args });\n\t\t} catch {\n\t\t\t// A throwing onStart must not cut this executor short: the stdin/stdout/stderr wiring and\n\t\t\t// close/error handlers below still need to run, or this child would keep running with\n\t\t\t// nothing left to supervise it (never settling, never killed on abort).\n\t\t}\n\n\t\tproc.stdin.on(\"error\", () => {});\n\t\tproc.stdin.end(`Task: ${spec.task}`);\n\n\t\tconst forward = (change: ReturnType<ChildEventReducer[\"apply\"]>) => {\n\t\t\tif (change !== \"none\") spec.run?.onChange?.(change);\n\t\t};\n\t\tconst pendingFirstDelta = new Set<number>();\n\t\tattachChildLineReader(\n\t\t\tproc.stdout,\n\t\t\t(line) => {\n\t\t\t\tconst record = parseChildLine(line);\n\t\t\t\tif (!record) return;\n\t\t\t\tforward(reducer.apply(record));\n\t\t\t\tconst progress = legacyProgressText(record, pendingFirstDelta);\n\t\t\t\tif (progress) spec.onProgress?.(progress);\n\t\t\t},\n\t\t\t{\n\t\t\t\tonSkipped: (prefix) => {\n\t\t\t\t\tif (prefix.includes(\"tool_execution_update\")) forward(reducer.noteHeartbeat());\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tproc.stderr.setEncoding(\"utf8\");\n\t\tproc.stderr.on(\"data\", (chunk: string) => reducer.noteStderr(chunk));\n\n\t\tif (spec.signal) {\n\t\t\tif (spec.signal.aborted) onAbort();\n\t\t\telse spec.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t}\n\n\t\tproc.on(\"error\", (error) => {\n\t\t\tclosed = true;\n\t\t\tfinishOnce({\n\t\t\t\tcode: null,\n\t\t\t\tsignal: null,\n\t\t\t\tcancelled: spec.signal?.aborted === true,\n\t\t\t\tspawnError: error.message,\n\t\t\t});\n\t\t});\n\n\t\tproc.on(\"close\", (code, signal) => {\n\t\t\tclosed = true;\n\t\t\tif (pid !== undefined) untrackDetachedChildPid(pid);\n\t\t\tfinishOnce({ code, signal, cancelled: spec.signal?.aborted === true });\n\t\t});\n\t});\n}\n\nfunction isJsonObjectValue(value: JsonValue): value is JsonObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * §7.4: extracts the per-field errors from `validateToolArguments`'s formatted message (one\n * ` - path: message` line per failing field, then a blank line and \"Received arguments:\"),\n * joins them onto one line, and caps the result. Any other error (e.g. \"structured output must\n * be a JSON object\") has no such lines and is passed through as its own (single-line) message.\n */\nexport function formatStructuredOutputError(rawMessage: string): string {\n\tconst [body] = rawMessage.split(\"\\n\\nReceived arguments:\");\n\tconst lines = (body ?? rawMessage).split(\"\\n\");\n\tconst fieldErrors = lines\n\t\t.slice(1)\n\t\t.map((line) => line.replace(/^\\s*-\\s*/, \"\").trim())\n\t\t.filter((line) => line.length > 0);\n\tconst detail = fieldErrors.length > 0 ? fieldErrors.join(\"; \") : (lines[0] ?? rawMessage);\n\treturn truncateProgress(detail.replace(/\\s+/g, \" \").trim(), STRUCTURED_OUTPUT_NOTICE_MAX_CHARS);\n}\n\n/**\n * ChildEventReducer exposes no public \"add a notice\" API (pushNotice and bump are private, with\n * no exported hook for callers outside the class). This pushes the item directly, then reuses\n * the public `trimForRetention` pass with an unreachable budget, which recomputes\n * `transcriptChars` from scratch and bumps `version`/`coarseVersion` without evicting anything,\n * so version-keyed consumers (render caches, store) observe the change. Passing the run's\n * post-finish budget here would trim the whole live transcript down to that size as a side\n * effect, which is the store's job at `finish()` (§8.3 retention), not this mid-run notice's.\n * Always \"coarse\", since `trimForRetention` always bumps coarse.\n */\nexport function recordReducerNotice(\n\treducer: ChildEventReducer,\n\tlevel: \"info\" | \"warning\" | \"error\",\n\ttext: string,\n): \"coarse\" {\n\tconst item: TranscriptItem = { kind: \"notice\", seq: reducer.state.nextSeq++, rev: 1, level, text, at: Date.now() };\n\treducer.state.transcript.push(item);\n\treducer.trimForRetention(Number.POSITIVE_INFINITY);\n\treturn \"coarse\";\n}\n\nconst REDOS_SCHEMA_KEYWORDS = new Set([\"pattern\", \"patternProperties\"]);\n\n/**\n * Deep-clones `schema`, dropping every `pattern`/`patternProperties` keyword at any depth. A\n * workflow script controls `schema` end to end (§guardAgentRequest only caps its JSON size), so a\n * crafted `pattern` such as `\"^(a+)+$\"` paired with a near-matching structured-output value makes\n * `validateToolArguments` backtrack exponentially. The child already validated the same value\n * against the *full* schema (including any `pattern`) before this parent-side re-validation runs,\n * so dropping regex keywords here only removes a redundant, attacker-triggerable check — it does\n * not let a value through the child missed.\n */\nfunction stripRegexSchemaKeywords(value: JsonValue): JsonValue {\n\tif (Array.isArray(value)) return value.map(stripRegexSchemaKeywords);\n\tif (typeof value === \"object\" && value !== null) {\n\t\tconst result: JsonObject = {};\n\t\tfor (const [key, child] of Object.entries(value)) {\n\t\t\tif (REDOS_SCHEMA_KEYWORDS.has(key)) continue;\n\t\t\tresult[key] = stripRegexSchemaKeywords(child);\n\t\t}\n\t\treturn result;\n\t}\n\treturn value;\n}\n\n/** §7.4: validate `state.structured` against `run.schema`, mutating the reducer's public state in place. */\nexport function validateStructuredOutput(\n\treducer: ChildEventReducer,\n\tschema: JsonObject,\n\tonChange?: (change: \"fine\" | \"coarse\") => void,\n): void {\n\tconst pending = reducer.state.structured;\n\tif (!pending) return;\n\ttry {\n\t\tif (!isJsonObjectValue(pending.value)) throw new Error(\"structured output must be a JSON object\");\n\t\tconst safeSchema = stripRegexSchemaKeywords(schema) as JsonObject;\n\t\tconst validated = validateToolArguments(\n\t\t\t{ name: POLYPHASE_RESULT_TOOL_NAME, description: \"\", parameters: safeSchema as unknown as TSchema },\n\t\t\t{ type: \"toolCall\", id: \"result\", name: POLYPHASE_RESULT_TOOL_NAME, arguments: pending.value },\n\t\t);\n\t\treducer.state.structured = { value: validated as JsonValue };\n\t} catch (error) {\n\t\treducer.state.structured = undefined;\n\t\tconst rawMessage = error instanceof Error ? error.message : String(error);\n\t\tconst message = formatStructuredOutputError(rawMessage);\n\t\tconst change = recordReducerNotice(reducer, \"warning\", `structured output invalid: ${message}`);\n\t\tonChange?.(change);\n\t}\n}\n\n/** §7.3: re-spawn once without `--model`/`--thinking` when the inherited model could not be resolved. */\nfunction shouldFallbackToChildDefault(\n\tspec: ChildSpawnSpec,\n\treducer: ChildEventReducer,\n\tresult: SpawnAttemptResult,\n): boolean {\n\treturn (\n\t\tspec.run?.fallbackToChildDefaultModel === true &&\n\t\t!result.exit.cancelled &&\n\t\tresult.finish.exitCode !== 0 &&\n\t\treducer.state.recordsSeen === 0 &&\n\t\t/model/i.test(reducer.state.stderrTail)\n\t);\n}\n\n/** Writes the appended-system-prompt and polyphase_result schema temp files, then runs §7.2-7.4. */\nasync function runInTempDir(spec: ChildSpawnSpec, tempDir: string, reducer: ChildEventReducer): Promise<RunResult> {\n\tconst combinedPrompt = `${spec.agent.systemPrompt}\\n\\n${spec.run?.extraSystemPrompt ?? \"\"}`;\n\tlet systemPromptFile: string | undefined;\n\tif (combinedPrompt.trim().length > 0) {\n\t\tsystemPromptFile = path.join(tempDir, \"prompt.md\");\n\t\tfs.writeFileSync(systemPromptFile, combinedPrompt, { encoding: \"utf-8\", mode: 0o600 });\n\t}\n\n\tlet schemaFile: string | undefined;\n\tif (spec.run?.schema) {\n\t\tschemaFile = path.join(tempDir, \"schema.json\");\n\t\tfs.writeFileSync(schemaFile, JSON.stringify(spec.run.schema), { encoding: \"utf-8\", mode: 0o600 });\n\t}\n\n\tconst files = { systemPromptFile, schemaFile };\n\tconst command = spec.command ?? resolveDrahtCommand();\n\n\treducer.markSpawning();\n\tconst start = Date.now();\n\tlet result = await spawnAttempt(spec, command, reducer, files, {});\n\n\tif (shouldFallbackToChildDefault(spec, reducer, result)) {\n\t\tconst requested = spec.run?.model ?? spec.agent.model ?? \"\";\n\t\treducer.resetForRetry(\n\t\t\t{ source: \"child-default\", confirmed: false },\n\t\t\t`inherited model ${requested} is unavailable in the child; using the child's default model`,\n\t\t);\n\t\tresult = await spawnAttempt(spec, command, reducer, files, { omitModel: true });\n\t}\n\n\tif (spec.run?.schema) validateStructuredOutput(reducer, spec.run.schema, spec.run?.onChange);\n\n\treturn toRunResult(reducer.state, { agent: spec.agent.name, task: spec.task, step: spec.step }, result.finish, {\n\t\tcancelled: result.exit.cancelled,\n\t\tstructured: reducer.state.structured,\n\t\tdurationMs: Date.now() - start,\n\t});\n}\n\nfunction createReducerForSpec(spec: ChildSpawnSpec): ChildEventReducer {\n\treturn (\n\t\tspec.run?.reducer ??\n\t\tnew ChildEventReducer({\n\t\t\tmodel: spec.run?.modelInfo ?? {\n\t\t\t\tsource: spec.agent.model ? \"frontmatter\" : \"child-default\",\n\t\t\t\trequested: spec.agent.model,\n\t\t\t\tconfirmed: false,\n\t\t\t},\n\t\t})\n\t);\n}\n\n/** Never rejects: spawn and runtime failures resolve as a failed `RunResult`. */\nexport async function runChildAgent(spec: ChildSpawnSpec): Promise<RunResult> {\n\tconst reducer = createReducerForSpec(spec);\n\tconst base = { agent: spec.agent.name, task: spec.task, step: spec.step };\n\tconst attemptStart = Date.now();\n\n\tif (spec.signal?.aborted) {\n\t\tconst finish = reducer.finish({ code: null, signal: null, cancelled: true });\n\t\treturn toRunResult(reducer.state, base, finish, {\n\t\t\tcancelled: true,\n\t\t\tdurationMs: Date.now() - attemptStart,\n\t\t});\n\t}\n\n\tlet tempDir: string | undefined;\n\ttry {\n\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"draht-polyphase-\"));\n\t\treturn await runInTempDir(spec, tempDir, reducer);\n\t} catch (error) {\n\t\tconst cancelled = spec.signal?.aborted === true;\n\t\tconst finish = reducer.finish({\n\t\t\tcode: null,\n\t\t\tsignal: null,\n\t\t\tcancelled,\n\t\t\tspawnError: error instanceof Error ? error.message : String(error),\n\t\t});\n\t\treturn toRunResult(reducer.state, base, finish, { cancelled, durationMs: Date.now() - attemptStart });\n\t} finally {\n\t\tif (tempDir) {\n\t\t\ttry {\n\t\t\t\tfs.rmSync(tempDir, { recursive: true, force: true });\n\t\t\t} catch {}\n\t\t}\n\t}\n}\n\nexport function createProcessAgentRunner(command?: ChildCommand): AgentRunner {\n\treturn (cwd, agent, task, signal, step, onProgress, run) =>\n\t\trunChildAgent({ cwd, agent, task, step, run, signal, onProgress, command });\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/workflow`, `/workflows` and the per-saved-workflow `/<name>` commands (§16.2), plus the
|
|
3
|
+
* command-path approval flow (§15.3). Saved workflow runs started this way are host-side: they
|
|
4
|
+
* are independent of agent turns and report back with a non-triggering custom message.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "../extensions/types.ts";
|
|
7
|
+
import type { SlashCommandInfo } from "../slash-commands.ts";
|
|
8
|
+
import type { PolyphaseSession } from "./session.ts";
|
|
9
|
+
import type { AgentRunner } from "./types.ts";
|
|
10
|
+
import type { PolyphaseUiController } from "./ui/controller.ts";
|
|
11
|
+
import { type SavedWorkflow } from "./workflow/saved.ts";
|
|
12
|
+
export interface PolyphaseCommandDeps {
|
|
13
|
+
pi: ExtensionAPI;
|
|
14
|
+
getSession(ctx: ExtensionContext): PolyphaseSession;
|
|
15
|
+
getUi(): PolyphaseUiController | undefined;
|
|
16
|
+
runner?: AgentRunner;
|
|
17
|
+
keyword(): string;
|
|
18
|
+
/** The most recent discovery result, refreshed at every `session_start`. */
|
|
19
|
+
getSavedWorkflows(): readonly SavedWorkflow[];
|
|
20
|
+
}
|
|
21
|
+
export interface SavedCommandPlan {
|
|
22
|
+
register: SavedWorkflow[];
|
|
23
|
+
skipped: Array<{
|
|
24
|
+
workflow: SavedWorkflow;
|
|
25
|
+
reason: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Collision check for every valid saved workflow name against `BUILTIN_SLASH_COMMANDS`,
|
|
30
|
+
* `pi.getCommands()` (including the bare name after `skill:`), and the reserved polyphase names.
|
|
31
|
+
* Invalid workflows are silently excluded: they are already diagnosed by `discoverSavedWorkflows`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function planSavedWorkflowCommands(workflows: readonly SavedWorkflow[], existing: {
|
|
34
|
+
builtin: readonly string[];
|
|
35
|
+
commands: readonly SlashCommandInfo[];
|
|
36
|
+
reserved: readonly string[];
|
|
37
|
+
}): SavedCommandPlan;
|
|
38
|
+
/** Called at `session_start`: registers `/<name>` for every planned saved workflow. */
|
|
39
|
+
export declare function registerSavedWorkflowCommands(deps: PolyphaseCommandDeps, plan: SavedCommandPlan): void;
|
|
40
|
+
/** `/<name> [args]` and `/workflow <name> [args]` (§15.3): gate, approve, start, report back. */
|
|
41
|
+
export declare function runSavedWorkflowFromCommand(deps: PolyphaseCommandDeps, name: string, args: string, ctx: ExtensionCommandContext): Promise<void>;
|
|
42
|
+
/** `/workflow` and `/workflows` (factory body, registered once per extension instance). */
|
|
43
|
+
export declare function registerWorkflowCommands(deps: PolyphaseCommandDeps): void;
|
|
44
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/commands.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEtG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,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AAoB,GAAG,IAAI,CAoEzE"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/workflow`, `/workflows` and the per-saved-workflow `/<name>` commands (§16.2), plus the
|
|
3
|
+
* command-path approval flow (§15.3). Saved workflow runs started this way are host-side: they
|
|
4
|
+
* are independent of agent turns and report back with a non-triggering custom message.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { getAgentDir } from "../../config.js";
|
|
8
|
+
import { keyDisplayText } from "../../modes/interactive/components/keybinding-hints.js";
|
|
9
|
+
import { loadPermissionRules } from "../builtins/subagent.js";
|
|
10
|
+
import { PermissionGate } from "../multi-agent/index.js";
|
|
11
|
+
import { describeToolCallForApproval } from "./approval.js";
|
|
12
|
+
import { collectArchivedRuns } from "./details.js";
|
|
13
|
+
import { startWorkflowRun } from "./workflow/launch.js";
|
|
14
|
+
import { extractWorkflowMeta } from "./workflow/meta.js";
|
|
15
|
+
import { discoverSavedWorkflows, readSavedWorkflowSource, } from "./workflow/saved.js";
|
|
16
|
+
function discoveryOptions(ctx) {
|
|
17
|
+
return { cwd: ctx.cwd, agentDir: getAgentDir(), projectTrusted: ctx.isProjectTrusted() };
|
|
18
|
+
}
|
|
19
|
+
function describeSavedWorkflow(workflow) {
|
|
20
|
+
return `${workflow.name} — ${workflow.description}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Collision check for every valid saved workflow name against `BUILTIN_SLASH_COMMANDS`,
|
|
24
|
+
* `pi.getCommands()` (including the bare name after `skill:`), and the reserved polyphase names.
|
|
25
|
+
* Invalid workflows are silently excluded: they are already diagnosed by `discoverSavedWorkflows`.
|
|
26
|
+
*/
|
|
27
|
+
export function planSavedWorkflowCommands(workflows, existing) {
|
|
28
|
+
const builtinNames = new Set(existing.builtin);
|
|
29
|
+
const reservedNames = new Set(existing.reserved);
|
|
30
|
+
const commandNames = new Set();
|
|
31
|
+
for (const command of existing.commands) {
|
|
32
|
+
commandNames.add(command.name);
|
|
33
|
+
if (command.name.startsWith("skill:"))
|
|
34
|
+
commandNames.add(command.name.slice("skill:".length));
|
|
35
|
+
}
|
|
36
|
+
const register = [];
|
|
37
|
+
const skipped = [];
|
|
38
|
+
const claimed = new Set();
|
|
39
|
+
for (const workflow of workflows) {
|
|
40
|
+
if (!workflow.valid)
|
|
41
|
+
continue;
|
|
42
|
+
const name = workflow.name;
|
|
43
|
+
if (builtinNames.has(name)) {
|
|
44
|
+
skipped.push({ workflow, reason: "conflicts with a built-in command" });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (reservedNames.has(name)) {
|
|
48
|
+
skipped.push({ workflow, reason: "is a reserved polyphase command name" });
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (commandNames.has(name) || claimed.has(name)) {
|
|
52
|
+
skipped.push({ workflow, reason: "conflicts with an existing command" });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
claimed.add(name);
|
|
56
|
+
register.push(workflow);
|
|
57
|
+
}
|
|
58
|
+
return { register, skipped };
|
|
59
|
+
}
|
|
60
|
+
/** Called at `session_start`: registers `/<name>` for every planned saved workflow. */
|
|
61
|
+
export function registerSavedWorkflowCommands(deps, plan) {
|
|
62
|
+
for (const workflow of plan.register) {
|
|
63
|
+
deps.pi.registerCommand(workflow.name, {
|
|
64
|
+
description: workflow.description,
|
|
65
|
+
handler: async (args, ctx) => {
|
|
66
|
+
await runSavedWorkflowFromCommand(deps, workflow.name, args.trim(), ctx);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** `/<name> [args]` and `/workflow <name> [args]` (§15.3): gate, approve, start, report back. */
|
|
72
|
+
export async function runSavedWorkflowFromCommand(deps, name, args, ctx) {
|
|
73
|
+
const discovery = discoverSavedWorkflows(discoveryOptions(ctx));
|
|
74
|
+
const workflow = discovery.workflows.find((candidate) => candidate.name === name);
|
|
75
|
+
if (!workflow) {
|
|
76
|
+
const available = discovery.workflows.map((candidate) => candidate.name).join(", ");
|
|
77
|
+
ctx.ui.notify(`Unknown saved workflow "${name}". Available: ${available || "(none)"}`, "error");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!workflow.valid) {
|
|
81
|
+
ctx.ui.notify(`Saved workflow "${name}" has an invalid meta block: ${workflow.error ?? "unknown error"}`, "error");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
let source;
|
|
85
|
+
try {
|
|
86
|
+
source = readSavedWorkflowSource(workflow);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const extraction = extractWorkflowMeta(source);
|
|
93
|
+
if (!extraction.ok) {
|
|
94
|
+
ctx.ui.notify(`Saved workflow "${name}" has an invalid meta block at line ${extraction.error.line}: ${extraction.error.message}`, "error");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const session = deps.getSession(ctx);
|
|
98
|
+
const settings = session.settings();
|
|
99
|
+
const gate = new PermissionGate(loadPermissionRules(ctx.cwd, ctx.isProjectTrusted()), {
|
|
100
|
+
cwd: ctx.cwd,
|
|
101
|
+
mode: session.permissionMode(),
|
|
102
|
+
});
|
|
103
|
+
const decision = gate.evaluate("workflow", { name, args });
|
|
104
|
+
if (decision.action === "deny") {
|
|
105
|
+
ctx.ui.notify(decision.reason, "error");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (decision.action === "approve") {
|
|
109
|
+
if (!ctx.hasUI) {
|
|
110
|
+
ctx.ui.notify(`Workflow ${name} needs approval but no UI is available; use /yolo or an allow rule`, "error");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
session.notifyParentPrompt();
|
|
114
|
+
const approvalContext = {
|
|
115
|
+
cwd: ctx.cwd,
|
|
116
|
+
projectTrusted: ctx.isProjectTrusted(),
|
|
117
|
+
agentDir: getAgentDir(),
|
|
118
|
+
limits: {
|
|
119
|
+
concurrency: settings.maxConcurrency,
|
|
120
|
+
maxAgents: settings.maxAgentsPerRun,
|
|
121
|
+
budgetTokens: settings.defaultBudgetTokens,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const description = describeToolCallForApproval("workflow", { name, args }, approvalContext);
|
|
125
|
+
const title = description?.title ?? `Run workflow "${name}"?`;
|
|
126
|
+
const message = description?.message ?? extraction.meta.description;
|
|
127
|
+
const approved = await ctx.ui.confirm(title, message);
|
|
128
|
+
if (!approved) {
|
|
129
|
+
ctx.ui.notify(`Workflow ${name} not started`, "info");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// A session_shutdown can run while the confirm dialog is open (e.g. an RPC new_session or
|
|
133
|
+
// switch_session); the disposed session's store/limiter have already cancelled and rejected
|
|
134
|
+
// everything, and nothing is left to cancel a run started on it afterwards.
|
|
135
|
+
if (session.disposed)
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const handle = startWorkflowRun({
|
|
139
|
+
ctx,
|
|
140
|
+
session,
|
|
141
|
+
id: `cmd-${randomUUID()}`,
|
|
142
|
+
origin: "command",
|
|
143
|
+
parentSignal: undefined,
|
|
144
|
+
meta: extraction.meta,
|
|
145
|
+
body: extraction.body,
|
|
146
|
+
args,
|
|
147
|
+
source: { kind: workflow.source, path: workflow.path },
|
|
148
|
+
budgetTokens: settings.defaultBudgetTokens,
|
|
149
|
+
runner: deps.runner,
|
|
150
|
+
});
|
|
151
|
+
const reportCompletion = (completion) => {
|
|
152
|
+
if (session.disposed)
|
|
153
|
+
return;
|
|
154
|
+
try {
|
|
155
|
+
deps.pi.sendMessage({
|
|
156
|
+
customType: "polyphase-workflow",
|
|
157
|
+
content: [{ type: "text", text: completion.text }],
|
|
158
|
+
display: true,
|
|
159
|
+
details: completion.details,
|
|
160
|
+
}, { triggerTurn: false });
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// The extension runtime can go stale concurrently (e.g. a session shutdown that raced
|
|
164
|
+
// this report); the run already finished and was recorded, so dropping the message here
|
|
165
|
+
// is safe and must never surface as an unhandled rejection.
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const inspectorHint = keyDisplayText("app.polyphase.inspector");
|
|
169
|
+
ctx.ui.notify(`Started workflow ${name}${inspectorHint ? ` · ${inspectorHint} to inspect` : ""}`, "info");
|
|
170
|
+
// print/json have no inspector and no later agent turn to pick up a background report, and
|
|
171
|
+
// disposing the runtime right after this handler returns (print mode) would cancel the run
|
|
172
|
+
// before it ever reports (§19): await it instead of firing and forgetting.
|
|
173
|
+
if (ctx.mode === "print" || ctx.mode === "json") {
|
|
174
|
+
const completion = await handle.done;
|
|
175
|
+
reportCompletion(completion);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
void handle.done.then(reportCompletion);
|
|
179
|
+
}
|
|
180
|
+
/** `/workflow` and `/workflows` (factory body, registered once per extension instance). */
|
|
181
|
+
export function registerWorkflowCommands(deps) {
|
|
182
|
+
deps.pi.registerCommand("workflow", {
|
|
183
|
+
description: "Run a saved workflow, or describe a new one. Usage: /workflow [name] [args]",
|
|
184
|
+
getArgumentCompletions: (partial) => {
|
|
185
|
+
return deps
|
|
186
|
+
.getSavedWorkflows()
|
|
187
|
+
.filter((workflow) => workflow.name.startsWith(partial))
|
|
188
|
+
.map((workflow) => ({ value: workflow.name, label: describeSavedWorkflow(workflow) }));
|
|
189
|
+
},
|
|
190
|
+
handler: async (args, ctx) => {
|
|
191
|
+
const trimmed = args.trim();
|
|
192
|
+
if (trimmed) {
|
|
193
|
+
const match = /\s/.exec(trimmed);
|
|
194
|
+
const name = match ? trimmed.slice(0, match.index) : trimmed;
|
|
195
|
+
const workflowArgs = match ? trimmed.slice(match.index + 1).trim() : "";
|
|
196
|
+
await runSavedWorkflowFromCommand(deps, name, workflowArgs, ctx);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const discovery = discoverSavedWorkflows(discoveryOptions(ctx));
|
|
200
|
+
if (ctx.mode === "tui" && ctx.hasUI) {
|
|
201
|
+
const describeNew = "Describe a new workflow…";
|
|
202
|
+
const options = [...discovery.workflows.map(describeSavedWorkflow), describeNew];
|
|
203
|
+
const choice = await ctx.ui.select("Run a workflow", options);
|
|
204
|
+
if (choice === undefined)
|
|
205
|
+
return;
|
|
206
|
+
if (choice === describeNew) {
|
|
207
|
+
ctx.ui.setEditorText(`${deps.keyword()} `);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const index = options.indexOf(choice);
|
|
211
|
+
const workflow = discovery.workflows[index];
|
|
212
|
+
if (workflow)
|
|
213
|
+
await runSavedWorkflowFromCommand(deps, workflow.name, "", ctx);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const lines = [
|
|
217
|
+
...discovery.workflows.map((workflow) => `${workflow.name} (${workflow.source}${workflow.valid ? "" : ", invalid"}) — ${workflow.description}`),
|
|
218
|
+
...discovery.diagnostics.map((diagnostic) => diagnostic.message),
|
|
219
|
+
];
|
|
220
|
+
ctx.ui.notify(lines.length > 0 ? lines.join("\n") : "No saved workflows found.", "info");
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
deps.pi.registerCommand("workflows", {
|
|
224
|
+
description: "List workflow runs and saved workflows, or open the inspector. Usage: /workflows [list]",
|
|
225
|
+
handler: async (args, ctx) => {
|
|
226
|
+
if (args.trim() !== "list" && ctx.mode === "tui" && ctx.hasUI) {
|
|
227
|
+
deps.getUi()?.openInspector({ view: "runs" });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const session = deps.getSession(ctx);
|
|
231
|
+
const runs = session.store.runs();
|
|
232
|
+
const liveRunIds = new Set(runs.map((run) => run.id));
|
|
233
|
+
const archived = collectArchivedRuns(ctx.sessionManager.getBranch(), liveRunIds);
|
|
234
|
+
const discovery = discoverSavedWorkflows(discoveryOptions(ctx));
|
|
235
|
+
const lines = [
|
|
236
|
+
...runs.map((run) => `${run.status}: ${run.title}`),
|
|
237
|
+
...archived.map((entry) => `${entry.details.status}: ${entry.details.title}`),
|
|
238
|
+
...discovery.workflows.map(describeSavedWorkflow),
|
|
239
|
+
];
|
|
240
|
+
ctx.ui.notify(lines.length > 0 ? lines.join("\n") : "No workflow runs.", "info");
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/core/polyphase/commands.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAwB,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAInD,OAAO,EAAE,gBAAgB,EAA8B,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACN,sBAAsB,EACtB,uBAAuB,GAGvB,MAAM,qBAAqB,CAAC;AAiB7B,SAAS,gBAAgB,CAAC,GAAqB;IAC9C,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC;AAC1F,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAuB;IACrD,OAAO,GAAG,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC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,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;YACjF,MAAM,SAAS,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;YAEhE,MAAM,KAAK,GAAG;gBACb,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC;gBACnD,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC7E,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,qBAAqB,CAAC;aACjD,CAAC;YACF,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;QAClF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `/workflow`, `/workflows` and the per-saved-workflow `/<name>` commands (§16.2), plus the\n * command-path approval flow (§15.3). Saved workflow runs started this way are host-side: they\n * are independent of agent turns and report back with a non-triggering custom message.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { keyDisplayText } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport { loadPermissionRules } from \"../builtins/subagent.ts\";\nimport type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from \"../extensions/types.ts\";\nimport { PermissionGate } from \"../multi-agent/index.ts\";\nimport type { SlashCommandInfo } from \"../slash-commands.ts\";\nimport { type ApprovalContext, describeToolCallForApproval } from \"./approval.ts\";\nimport { collectArchivedRuns } from \"./details.ts\";\nimport type { PolyphaseSession } from \"./session.ts\";\nimport type { AgentRunner } from \"./types.ts\";\nimport type { PolyphaseUiController } from \"./ui/controller.ts\";\nimport { startWorkflowRun, type WorkflowRunCompletion } from \"./workflow/launch.ts\";\nimport { extractWorkflowMeta } from \"./workflow/meta.ts\";\nimport {\n\tdiscoverSavedWorkflows,\n\treadSavedWorkflowSource,\n\ttype SavedDiscoveryOptions,\n\ttype SavedWorkflow,\n} from \"./workflow/saved.ts\";\n\nexport interface PolyphaseCommandDeps {\n\tpi: ExtensionAPI;\n\tgetSession(ctx: ExtensionContext): PolyphaseSession;\n\tgetUi(): PolyphaseUiController | undefined;\n\trunner?: AgentRunner;\n\tkeyword(): string;\n\t/** The most recent discovery result, refreshed at every `session_start`. */\n\tgetSavedWorkflows(): readonly SavedWorkflow[];\n}\n\nexport interface SavedCommandPlan {\n\tregister: SavedWorkflow[];\n\tskipped: Array<{ workflow: SavedWorkflow; reason: string }>;\n}\n\nfunction discoveryOptions(ctx: ExtensionContext): SavedDiscoveryOptions {\n\treturn { cwd: ctx.cwd, agentDir: getAgentDir(), projectTrusted: ctx.isProjectTrusted() };\n}\n\nfunction describeSavedWorkflow(workflow: SavedWorkflow): string {\n\treturn `${workflow.name} — ${workflow.description}`;\n}\n\n/**\n * Collision check for every valid saved workflow name against `BUILTIN_SLASH_COMMANDS`,\n * `pi.getCommands()` (including the bare name after `skill:`), and the reserved polyphase names.\n * Invalid workflows are silently excluded: they are already diagnosed by `discoverSavedWorkflows`.\n */\nexport function planSavedWorkflowCommands(\n\tworkflows: readonly SavedWorkflow[],\n\texisting: { builtin: readonly string[]; commands: readonly SlashCommandInfo[]; reserved: readonly string[] },\n): SavedCommandPlan {\n\tconst builtinNames = new Set(existing.builtin);\n\tconst reservedNames = new Set(existing.reserved);\n\tconst commandNames = new Set<string>();\n\tfor (const command of existing.commands) {\n\t\tcommandNames.add(command.name);\n\t\tif (command.name.startsWith(\"skill:\")) commandNames.add(command.name.slice(\"skill:\".length));\n\t}\n\n\tconst register: SavedWorkflow[] = [];\n\tconst skipped: SavedCommandPlan[\"skipped\"] = [];\n\tconst claimed = new Set<string>();\n\n\tfor (const workflow of workflows) {\n\t\tif (!workflow.valid) continue;\n\t\tconst name = workflow.name;\n\t\tif (builtinNames.has(name)) {\n\t\t\tskipped.push({ workflow, reason: \"conflicts with a built-in command\" });\n\t\t\tcontinue;\n\t\t}\n\t\tif (reservedNames.has(name)) {\n\t\t\tskipped.push({ workflow, reason: \"is a reserved polyphase command name\" });\n\t\t\tcontinue;\n\t\t}\n\t\tif (commandNames.has(name) || claimed.has(name)) {\n\t\t\tskipped.push({ workflow, reason: \"conflicts with an existing command\" });\n\t\t\tcontinue;\n\t\t}\n\t\tclaimed.add(name);\n\t\tregister.push(workflow);\n\t}\n\n\treturn { register, skipped };\n}\n\n/** Called at `session_start`: registers `/<name>` for every planned saved workflow. */\nexport function registerSavedWorkflowCommands(deps: PolyphaseCommandDeps, plan: SavedCommandPlan): void {\n\tfor (const workflow of plan.register) {\n\t\tdeps.pi.registerCommand(workflow.name, {\n\t\t\tdescription: workflow.description,\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tawait runSavedWorkflowFromCommand(deps, workflow.name, args.trim(), ctx);\n\t\t\t},\n\t\t});\n\t}\n}\n\n/** `/<name> [args]` and `/workflow <name> [args]` (§15.3): gate, approve, start, report back. */\nexport async function runSavedWorkflowFromCommand(\n\tdeps: PolyphaseCommandDeps,\n\tname: string,\n\targs: string,\n\tctx: ExtensionCommandContext,\n): Promise<void> {\n\tconst discovery = discoverSavedWorkflows(discoveryOptions(ctx));\n\tconst workflow = discovery.workflows.find((candidate) => candidate.name === name);\n\tif (!workflow) {\n\t\tconst available = discovery.workflows.map((candidate) => candidate.name).join(\", \");\n\t\tctx.ui.notify(`Unknown saved workflow \"${name}\". Available: ${available || \"(none)\"}`, \"error\");\n\t\treturn;\n\t}\n\tif (!workflow.valid) {\n\t\tctx.ui.notify(\n\t\t\t`Saved workflow \"${name}\" has an invalid meta block: ${workflow.error ?? \"unknown error\"}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn;\n\t}\n\n\tlet source: string;\n\ttry {\n\t\tsource = readSavedWorkflowSource(workflow);\n\t} catch (error) {\n\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\treturn;\n\t}\n\n\tconst extraction = extractWorkflowMeta(source);\n\tif (!extraction.ok) {\n\t\tctx.ui.notify(\n\t\t\t`Saved workflow \"${name}\" has an invalid meta block at line ${extraction.error.line}: ${extraction.error.message}`,\n\t\t\t\"error\",\n\t\t);\n\t\treturn;\n\t}\n\n\tconst session = deps.getSession(ctx);\n\tconst settings = session.settings();\n\n\tconst gate = new PermissionGate(loadPermissionRules(ctx.cwd, ctx.isProjectTrusted()), {\n\t\tcwd: ctx.cwd,\n\t\tmode: session.permissionMode(),\n\t});\n\tconst decision = gate.evaluate(\"workflow\", { name, args });\n\n\tif (decision.action === \"deny\") {\n\t\tctx.ui.notify(decision.reason, \"error\");\n\t\treturn;\n\t}\n\n\tif (decision.action === \"approve\") {\n\t\tif (!ctx.hasUI) {\n\t\t\tctx.ui.notify(`Workflow ${name} needs approval but no UI is available; use /yolo or an allow rule`, \"error\");\n\t\t\treturn;\n\t\t}\n\t\tsession.notifyParentPrompt();\n\t\tconst approvalContext: ApprovalContext = {\n\t\t\tcwd: ctx.cwd,\n\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\tagentDir: getAgentDir(),\n\t\t\tlimits: {\n\t\t\t\tconcurrency: settings.maxConcurrency,\n\t\t\t\tmaxAgents: settings.maxAgentsPerRun,\n\t\t\t\tbudgetTokens: settings.defaultBudgetTokens,\n\t\t\t},\n\t\t};\n\t\tconst description = describeToolCallForApproval(\"workflow\", { name, args }, approvalContext);\n\t\tconst title = description?.title ?? `Run workflow \"${name}\"?`;\n\t\tconst message = description?.message ?? extraction.meta.description;\n\t\tconst approved = await ctx.ui.confirm(title, message);\n\t\tif (!approved) {\n\t\t\tctx.ui.notify(`Workflow ${name} not started`, \"info\");\n\t\t\treturn;\n\t\t}\n\t\t// A session_shutdown can run while the confirm dialog is open (e.g. an RPC new_session or\n\t\t// switch_session); the disposed session's store/limiter have already cancelled and rejected\n\t\t// everything, and nothing is left to cancel a run started on it afterwards.\n\t\tif (session.disposed) return;\n\t}\n\n\tconst handle = startWorkflowRun({\n\t\tctx,\n\t\tsession,\n\t\tid: `cmd-${randomUUID()}`,\n\t\torigin: \"command\",\n\t\tparentSignal: undefined,\n\t\tmeta: extraction.meta,\n\t\tbody: extraction.body,\n\t\targs,\n\t\tsource: { kind: workflow.source, path: workflow.path },\n\t\tbudgetTokens: settings.defaultBudgetTokens,\n\t\trunner: deps.runner,\n\t});\n\n\tconst reportCompletion = (completion: WorkflowRunCompletion): void => {\n\t\tif (session.disposed) return;\n\t\ttry {\n\t\t\tdeps.pi.sendMessage(\n\t\t\t\t{\n\t\t\t\t\tcustomType: \"polyphase-workflow\",\n\t\t\t\t\tcontent: [{ type: \"text\", text: completion.text }],\n\t\t\t\t\tdisplay: true,\n\t\t\t\t\tdetails: completion.details,\n\t\t\t\t},\n\t\t\t\t{ triggerTurn: false },\n\t\t\t);\n\t\t} catch {\n\t\t\t// The extension runtime can go stale concurrently (e.g. a session shutdown that raced\n\t\t\t// this report); the run already finished and was recorded, so dropping the message here\n\t\t\t// is safe and must never surface as an unhandled rejection.\n\t\t}\n\t};\n\n\tconst inspectorHint = keyDisplayText(\"app.polyphase.inspector\");\n\tctx.ui.notify(`Started workflow ${name}${inspectorHint ? ` · ${inspectorHint} to inspect` : \"\"}`, \"info\");\n\n\t// print/json have no inspector and no later agent turn to pick up a background report, and\n\t// disposing the runtime right after this handler returns (print mode) would cancel the run\n\t// before it ever reports (§19): await it instead of firing and forgetting.\n\tif (ctx.mode === \"print\" || ctx.mode === \"json\") {\n\t\tconst completion = await handle.done;\n\t\treportCompletion(completion);\n\t\treturn;\n\t}\n\n\tvoid handle.done.then(reportCompletion);\n}\n\n/** `/workflow` and `/workflows` (factory body, registered once per extension instance). */\nexport function registerWorkflowCommands(deps: PolyphaseCommandDeps): void {\n\tdeps.pi.registerCommand(\"workflow\", {\n\t\tdescription: \"Run a saved workflow, or describe a new one. Usage: /workflow [name] [args]\",\n\t\tgetArgumentCompletions: (partial) => {\n\t\t\treturn deps\n\t\t\t\t.getSavedWorkflows()\n\t\t\t\t.filter((workflow) => workflow.name.startsWith(partial))\n\t\t\t\t.map((workflow) => ({ value: workflow.name, label: describeSavedWorkflow(workflow) }));\n\t\t},\n\t\thandler: async (args, ctx) => {\n\t\t\tconst trimmed = args.trim();\n\t\t\tif (trimmed) {\n\t\t\t\tconst match = /\\s/.exec(trimmed);\n\t\t\t\tconst name = match ? trimmed.slice(0, match.index) : trimmed;\n\t\t\t\tconst workflowArgs = match ? trimmed.slice(match.index + 1).trim() : \"\";\n\t\t\t\tawait runSavedWorkflowFromCommand(deps, name, workflowArgs, ctx);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst discovery = discoverSavedWorkflows(discoveryOptions(ctx));\n\t\t\tif (ctx.mode === \"tui\" && ctx.hasUI) {\n\t\t\t\tconst describeNew = \"Describe a new workflow…\";\n\t\t\t\tconst options = [...discovery.workflows.map(describeSavedWorkflow), describeNew];\n\t\t\t\tconst choice = await ctx.ui.select(\"Run a workflow\", options);\n\t\t\t\tif (choice === undefined) return;\n\t\t\t\tif (choice === describeNew) {\n\t\t\t\t\tctx.ui.setEditorText(`${deps.keyword()} `);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst index = options.indexOf(choice);\n\t\t\t\tconst workflow = discovery.workflows[index];\n\t\t\t\tif (workflow) await runSavedWorkflowFromCommand(deps, workflow.name, \"\", ctx);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst lines = [\n\t\t\t\t...discovery.workflows.map(\n\t\t\t\t\t(workflow) =>\n\t\t\t\t\t\t`${workflow.name} (${workflow.source}${workflow.valid ? \"\" : \", invalid\"}) — ${workflow.description}`,\n\t\t\t\t),\n\t\t\t\t...discovery.diagnostics.map((diagnostic) => diagnostic.message),\n\t\t\t];\n\t\t\tctx.ui.notify(lines.length > 0 ? lines.join(\"\\n\") : \"No saved workflows found.\", \"info\");\n\t\t},\n\t});\n\n\tdeps.pi.registerCommand(\"workflows\", {\n\t\tdescription: \"List workflow runs and saved workflows, or open the inspector. Usage: /workflows [list]\",\n\t\thandler: async (args, ctx) => {\n\t\t\tif (args.trim() !== \"list\" && ctx.mode === \"tui\" && ctx.hasUI) {\n\t\t\t\tdeps.getUi()?.openInspector({ view: \"runs\" });\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst session = deps.getSession(ctx);\n\t\t\tconst runs = session.store.runs();\n\t\t\tconst liveRunIds = new Set(runs.map((run) => run.id));\n\t\t\tconst archived = collectArchivedRuns(ctx.sessionManager.getBranch(), liveRunIds);\n\t\t\tconst discovery = discoverSavedWorkflows(discoveryOptions(ctx));\n\n\t\t\tconst lines = [\n\t\t\t\t...runs.map((run) => `${run.status}: ${run.title}`),\n\t\t\t\t...archived.map((entry) => `${entry.details.status}: ${entry.details.title}`),\n\t\t\t\t...discovery.workflows.map(describeSavedWorkflow),\n\t\t\t];\n\t\t\tctx.ui.notify(lines.length > 0 ? lines.join(\"\\n\") : \"No workflow runs.\", \"info\");\n\t\t},\n\t});\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Usage } from "@draht/ai";
|
|
2
|
+
import type { SessionEntry } from "../session-manager.ts";
|
|
3
|
+
import type { PolyphaseDetails, RunView } from "./types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Degrades `run` through L0-L4 (§9.2) until the JSON-stringified result fits `maxBytes`
|
|
6
|
+
* (`FINAL_DETAILS_MAX_BYTES` or `PARTIAL_DETAILS_MAX_BYTES` by default). L4 always fits: per-level
|
|
7
|
+
* caps keep run-level strings and phases bounded at every level, and a final {@link forceFit} pass
|
|
8
|
+
* strips fields and agents if an L4 result (e.g. hundreds of near-cap agents) still does not.
|
|
9
|
+
*
|
|
10
|
+
* `options.now` is accepted for signature symmetry with the rest of the polyphase API (store.ts's
|
|
11
|
+
* injectable clock) but is not currently read: every persisted field is an absolute timestamp, and
|
|
12
|
+
* no derived field here depends on "the current time".
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildDetails(run: RunView, options: {
|
|
15
|
+
final: boolean;
|
|
16
|
+
maxBytes?: number;
|
|
17
|
+
now?: number;
|
|
18
|
+
}): PolyphaseDetails;
|
|
19
|
+
/** Structural guard: `v === 1`, the required top-level fields, every agent's required fields, and
|
|
20
|
+
* the shape of the optional array/object fields (`phases`, `log`, `totals`). Persisted details can
|
|
21
|
+
* be hand-edited or come from an older schema version, so this is read defensively, not just at the
|
|
22
|
+
* top level: {@link collectArchivedRuns} hands these straight to renderers as `PolyphaseDetails`. */
|
|
23
|
+
export declare function isPolyphaseDetails(value: unknown): value is PolyphaseDetails;
|
|
24
|
+
export interface ArchivedRun {
|
|
25
|
+
runId: string;
|
|
26
|
+
entryId: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
source: "toolResult" | "message";
|
|
29
|
+
toolName?: string;
|
|
30
|
+
details: PolyphaseDetails;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `toolResult` entries for `subagent`/`workflow` and `custom_message` "polyphase-workflow"
|
|
34
|
+
* entries whose `details` pass {@link isPolyphaseDetails}, excluding `liveRunIds`, deduped by
|
|
35
|
+
* `runId` (newest kept), newest first, capped at `limit`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function collectArchivedRuns(entries: readonly SessionEntry[], liveRunIds: ReadonlySet<string>, limit?: number): ArchivedRun[];
|
|
38
|
+
/** `combineUsage` over every agent's `state.usage`. */
|
|
39
|
+
export declare function sumRunUsage(run: RunView): Usage | undefined;
|
|
40
|
+
//# sourceMappingURL=details.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/details.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,OAAO,KAAK,EAMX,gBAAgB,EAChB,OAAO,EACP,MAAM,YAAY,CAAC;AAqcpB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,gBAAgB,CAWlB;AAoBD;;;qGAGqG;AACrG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAe5E;AAED,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,gBAAgB,CAAC;CAC1B;AA6BD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAC/B,KAAK,SAAK,GACR,WAAW,EAAE,CASf;AAED,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAQ3D"}
|