@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,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and constants for polyphase: subagent/workflow orchestration, the child
|
|
3
|
+
* event stream, and the persisted/live views consumed by rendering and the inspector.
|
|
4
|
+
*
|
|
5
|
+
* This module owns the vocabulary. Other polyphase modules import from here instead of
|
|
6
|
+
* redeclaring these shapes.
|
|
7
|
+
*/
|
|
8
|
+
import type { ThinkingLevel } from "@draht/agent-core";
|
|
9
|
+
import type { JsonObject, JsonValue, StopReason, Usage } from "@draht/ai";
|
|
10
|
+
import type { MergeResult } from "../multi-agent/index.ts";
|
|
11
|
+
import type { ChildEventReducer } from "./child-events.ts";
|
|
12
|
+
export declare const POLYPHASE_DEPTH_ENV = "DRAHT_POLYPHASE_DEPTH";
|
|
13
|
+
export declare const POLYPHASE_SCHEMA_FILE_ENV = "DRAHT_POLYPHASE_SCHEMA_FILE";
|
|
14
|
+
export declare const SUBAGENT_TOOL_NAME = "subagent";
|
|
15
|
+
export declare const WORKFLOW_TOOL_NAME = "workflow";
|
|
16
|
+
export declare const DUET_DELEGATE_TOOL_NAME = "duet_delegate";
|
|
17
|
+
export declare const POLYPHASE_RESULT_TOOL_NAME = "polyphase_result";
|
|
18
|
+
/** Suffix of the permission gate's block reason when no UI can answer (builtins/subagent.ts). */
|
|
19
|
+
export declare const NO_UI_APPROVAL_SUFFIX = "(no UI available to request approval)";
|
|
20
|
+
export declare const FINAL_DETAILS_MAX_BYTES = 16384;
|
|
21
|
+
export declare const PARTIAL_DETAILS_MAX_BYTES = 8192;
|
|
22
|
+
export declare const THINKING_LEVELS: readonly ThinkingLevel[];
|
|
23
|
+
export declare function isThinkingLevel(value: unknown): value is ThinkingLevel;
|
|
24
|
+
/** Nesting depth of this process: 0 for the user's session, n for a child spawned at depth n-1. */
|
|
25
|
+
export declare function currentPolyphaseDepth(env?: NodeJS.ProcessEnv): number;
|
|
26
|
+
export interface AgentConfig {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
tools?: string[];
|
|
30
|
+
model?: string;
|
|
31
|
+
/** Disable user and project extensions in the child process. Core builtins still load. */
|
|
32
|
+
disableExtensions?: boolean;
|
|
33
|
+
systemPrompt: string;
|
|
34
|
+
source: "user" | "project";
|
|
35
|
+
}
|
|
36
|
+
export interface ModelRef {
|
|
37
|
+
provider: string;
|
|
38
|
+
id: string;
|
|
39
|
+
}
|
|
40
|
+
export interface RunResult {
|
|
41
|
+
agent: string;
|
|
42
|
+
task: string;
|
|
43
|
+
exitCode: number;
|
|
44
|
+
output: string;
|
|
45
|
+
stderr: string;
|
|
46
|
+
usage?: Usage;
|
|
47
|
+
step?: number;
|
|
48
|
+
merge?: MergeResult;
|
|
49
|
+
/** Confirmed from the child's first assistant message_start. */
|
|
50
|
+
model?: ModelRef;
|
|
51
|
+
/** Confirmed from the child's assistant message_end. */
|
|
52
|
+
thinkingLevel?: ThinkingLevel;
|
|
53
|
+
stopReason?: StopReason;
|
|
54
|
+
turns?: number;
|
|
55
|
+
toolCalls?: number;
|
|
56
|
+
blockedToolCalls?: number;
|
|
57
|
+
/** Validated polyphase_result arguments when a schema was requested. */
|
|
58
|
+
structured?: {
|
|
59
|
+
value: JsonValue;
|
|
60
|
+
};
|
|
61
|
+
cancelled?: boolean;
|
|
62
|
+
durationMs?: number;
|
|
63
|
+
}
|
|
64
|
+
export type ProgressFn = (activity: string) => void;
|
|
65
|
+
export type ChildStateChange = "none" | "fine" | "coarse";
|
|
66
|
+
/** Per-run options threaded from orchestrators to the process runner. All optional. */
|
|
67
|
+
export interface AgentRunContext {
|
|
68
|
+
/** `--model` value. Overrides agent.model when set. */
|
|
69
|
+
model?: string;
|
|
70
|
+
/** `--thinking` value. */
|
|
71
|
+
thinking?: ThinkingLevel;
|
|
72
|
+
/** Model display info used when the runner creates its own reducer. */
|
|
73
|
+
modelInfo?: AgentModelInfo;
|
|
74
|
+
/** Retry once without --model/--thinking when the child cannot resolve the inherited model (§7.3). */
|
|
75
|
+
fallbackToChildDefaultModel?: boolean;
|
|
76
|
+
/** Added to the runner's fixed exclusions (workflow, duet_delegate). */
|
|
77
|
+
excludeTools?: readonly string[];
|
|
78
|
+
/** Appended to `--tools` only when the agent has a tools allowlist. */
|
|
79
|
+
extraTools?: readonly string[];
|
|
80
|
+
/** Appended to the agent system prompt in the same temp file. */
|
|
81
|
+
extraSystemPrompt?: string;
|
|
82
|
+
/** Extra environment for the child. */
|
|
83
|
+
env?: Readonly<Record<string, string>>;
|
|
84
|
+
/** Object JSON Schema for polyphase_result. The runner writes it to a 0600 temp file. */
|
|
85
|
+
schema?: JsonObject;
|
|
86
|
+
/** Live state sink. When absent the runner uses a private reducer. */
|
|
87
|
+
reducer?: ChildEventReducer;
|
|
88
|
+
onQueued?: () => void;
|
|
89
|
+
onStart?: (info: {
|
|
90
|
+
pid: number | undefined;
|
|
91
|
+
argv: readonly string[];
|
|
92
|
+
}) => void;
|
|
93
|
+
onChange?: (change: "fine" | "coarse") => void;
|
|
94
|
+
/** Called once by runAgentWithLifecycle with the final result (after merge-back). */
|
|
95
|
+
onFinish?: (result: RunResult) => void;
|
|
96
|
+
}
|
|
97
|
+
export type AgentRunner = (cwd: string, agent: AgentConfig, task: string, signal?: AbortSignal, step?: number, onProgress?: ProgressFn, run?: AgentRunContext) => Promise<RunResult>;
|
|
98
|
+
export type AgentStatus = "pending" | "queued" | "starting" | "running" | "done" | "failed" | "cancelled" | "skipped";
|
|
99
|
+
export type AgentActivity = "idle" | "waiting" | "thinking" | "writing" | "tool" | "retrying" | "compacting";
|
|
100
|
+
export type ModelSource = "override" | "phase" | "frontmatter" | "inherited" | "child-default";
|
|
101
|
+
export type CancelReason = "user" | "budget" | "run" | "parent" | "shutdown";
|
|
102
|
+
export interface AgentModelInfo {
|
|
103
|
+
source: ModelSource;
|
|
104
|
+
/** Value passed with --model (or the frontmatter pattern). */
|
|
105
|
+
requested?: string;
|
|
106
|
+
requestedThinking?: ThinkingLevel;
|
|
107
|
+
/** Pre-resolved in the parent, then confirmed by the child's assistant message_start. */
|
|
108
|
+
provider?: string;
|
|
109
|
+
id?: string;
|
|
110
|
+
/** Confirmed at message_end, or by thinking_level_changed. */
|
|
111
|
+
thinkingLevel?: ThinkingLevel;
|
|
112
|
+
confirmed: boolean;
|
|
113
|
+
}
|
|
114
|
+
export type ToolItemStatus = "pending" | "running" | "ok" | "error" | "blocked";
|
|
115
|
+
/** `rev` increments on every mutation of the item (cache key for wrapped lines). */
|
|
116
|
+
export type TranscriptItem = {
|
|
117
|
+
kind: "thinking";
|
|
118
|
+
seq: number;
|
|
119
|
+
rev: number;
|
|
120
|
+
text: string;
|
|
121
|
+
droppedChars: number;
|
|
122
|
+
done: boolean;
|
|
123
|
+
redacted: boolean;
|
|
124
|
+
} | {
|
|
125
|
+
kind: "text";
|
|
126
|
+
seq: number;
|
|
127
|
+
rev: number;
|
|
128
|
+
text: string;
|
|
129
|
+
droppedChars: number;
|
|
130
|
+
done: boolean;
|
|
131
|
+
} | {
|
|
132
|
+
kind: "tool";
|
|
133
|
+
seq: number;
|
|
134
|
+
rev: number;
|
|
135
|
+
toolCallId: string;
|
|
136
|
+
name: string;
|
|
137
|
+
summary: string;
|
|
138
|
+
status: ToolItemStatus;
|
|
139
|
+
startedAt?: number;
|
|
140
|
+
endedAt?: number;
|
|
141
|
+
resultPreview?: string;
|
|
142
|
+
blockedReason?: string;
|
|
143
|
+
} | {
|
|
144
|
+
kind: "notice";
|
|
145
|
+
seq: number;
|
|
146
|
+
rev: number;
|
|
147
|
+
level: "info" | "warning" | "error";
|
|
148
|
+
text: string;
|
|
149
|
+
at: number;
|
|
150
|
+
};
|
|
151
|
+
export interface BlockedToolCall {
|
|
152
|
+
toolName: string;
|
|
153
|
+
summary: string;
|
|
154
|
+
reason: string;
|
|
155
|
+
}
|
|
156
|
+
export interface ChildStateLimits {
|
|
157
|
+
maxItems: number;
|
|
158
|
+
maxChars: number;
|
|
159
|
+
maxItemChars: number;
|
|
160
|
+
maxFinalTextChars: number;
|
|
161
|
+
maxStderrChars: number;
|
|
162
|
+
finishedMaxChars: number;
|
|
163
|
+
}
|
|
164
|
+
export declare const DEFAULT_CHILD_STATE_LIMITS: ChildStateLimits;
|
|
165
|
+
export interface ChildAgentState {
|
|
166
|
+
lifecycle: "pending" | "queued" | "spawning" | "running" | "settled" | "exited";
|
|
167
|
+
activity: AgentActivity;
|
|
168
|
+
sessionId?: string;
|
|
169
|
+
model: AgentModelInfo;
|
|
170
|
+
turns: number;
|
|
171
|
+
toolCalls: number;
|
|
172
|
+
toolErrors: number;
|
|
173
|
+
toolCounts: Record<string, number>;
|
|
174
|
+
/** Newest last, at most 20 kept. */
|
|
175
|
+
blocked: BlockedToolCall[];
|
|
176
|
+
blockedCount: number;
|
|
177
|
+
currentTool?: {
|
|
178
|
+
toolCallId: string;
|
|
179
|
+
name: string;
|
|
180
|
+
summary: string;
|
|
181
|
+
startedAt: number;
|
|
182
|
+
};
|
|
183
|
+
/** Sum of finished assistant message usage (combineUsage). */
|
|
184
|
+
usage?: Usage;
|
|
185
|
+
/** Cumulative usage of the in-flight assistant message. */
|
|
186
|
+
liveUsage?: Usage;
|
|
187
|
+
transcript: TranscriptItem[];
|
|
188
|
+
transcriptChars: number;
|
|
189
|
+
droppedItems: number;
|
|
190
|
+
nextSeq: number;
|
|
191
|
+
/** One line, ≤ 160 chars: what the agent is doing right now. */
|
|
192
|
+
nowLine: string;
|
|
193
|
+
/** First text part of the last assistant message that had text, capped. */
|
|
194
|
+
finalText: string;
|
|
195
|
+
stopReason?: StopReason;
|
|
196
|
+
errorMessage?: string;
|
|
197
|
+
/** Arguments of the last successful polyphase_result call (validated later by the runner). */
|
|
198
|
+
structured?: {
|
|
199
|
+
value: JsonValue;
|
|
200
|
+
};
|
|
201
|
+
retry?: {
|
|
202
|
+
attempt: number;
|
|
203
|
+
maxAttempts: number;
|
|
204
|
+
delayMs: number;
|
|
205
|
+
errorMessage: string;
|
|
206
|
+
};
|
|
207
|
+
stderrTail: string;
|
|
208
|
+
malformedLines: number;
|
|
209
|
+
droppedLines: number;
|
|
210
|
+
recordsSeen: number;
|
|
211
|
+
queuedAt?: number;
|
|
212
|
+
startedAt?: number;
|
|
213
|
+
endedAt?: number;
|
|
214
|
+
lastEventAt?: number;
|
|
215
|
+
/** ++ on every fine or coarse change. */
|
|
216
|
+
version: number;
|
|
217
|
+
/** ++ on every coarse change. */
|
|
218
|
+
coarseVersion: number;
|
|
219
|
+
}
|
|
220
|
+
export type RunKind = "subagent" | "workflow" | "duet";
|
|
221
|
+
export type RunOrigin = "tool" | "command";
|
|
222
|
+
export type SubagentMode = "single" | "parallel" | "chain";
|
|
223
|
+
export type RunStatus = "running" | "done" | "failed" | "cancelled";
|
|
224
|
+
export type WorkflowSource = "inline" | "project" | "user";
|
|
225
|
+
export interface PhaseInfo {
|
|
226
|
+
title: string;
|
|
227
|
+
detail?: string;
|
|
228
|
+
model?: string;
|
|
229
|
+
/** True for phases created by phase()/agent({phase}) that meta did not declare. */
|
|
230
|
+
dynamic: boolean;
|
|
231
|
+
}
|
|
232
|
+
export interface WorkflowRunInfo {
|
|
233
|
+
name: string;
|
|
234
|
+
description: string;
|
|
235
|
+
source: WorkflowSource;
|
|
236
|
+
path?: string;
|
|
237
|
+
args: string;
|
|
238
|
+
}
|
|
239
|
+
export interface LogLine {
|
|
240
|
+
at: number;
|
|
241
|
+
level: "info" | "warning";
|
|
242
|
+
text: string;
|
|
243
|
+
phase?: number;
|
|
244
|
+
}
|
|
245
|
+
export interface AgentView {
|
|
246
|
+
/** `${runId}#${index}` */
|
|
247
|
+
readonly key: string;
|
|
248
|
+
readonly index: number;
|
|
249
|
+
readonly label: string;
|
|
250
|
+
readonly agentType: string;
|
|
251
|
+
readonly task: string;
|
|
252
|
+
readonly phase?: number;
|
|
253
|
+
/** 1-based chain step. */
|
|
254
|
+
readonly step?: number;
|
|
255
|
+
readonly status: AgentStatus;
|
|
256
|
+
readonly cancelReason?: CancelReason;
|
|
257
|
+
readonly state: Readonly<ChildAgentState>;
|
|
258
|
+
readonly result?: Readonly<RunResult>;
|
|
259
|
+
readonly createdAt: number;
|
|
260
|
+
}
|
|
261
|
+
export interface RunView {
|
|
262
|
+
readonly id: string;
|
|
263
|
+
readonly kind: RunKind;
|
|
264
|
+
readonly origin: RunOrigin;
|
|
265
|
+
readonly mode?: SubagentMode;
|
|
266
|
+
readonly title: string;
|
|
267
|
+
readonly workflow?: Readonly<WorkflowRunInfo>;
|
|
268
|
+
readonly phases: readonly PhaseInfo[];
|
|
269
|
+
readonly currentPhase?: number;
|
|
270
|
+
readonly status: RunStatus;
|
|
271
|
+
readonly startedAt: number;
|
|
272
|
+
readonly endedAt?: number;
|
|
273
|
+
readonly agents: readonly AgentView[];
|
|
274
|
+
readonly log: readonly LogLine[];
|
|
275
|
+
readonly logDropped: number;
|
|
276
|
+
readonly budget: Readonly<{
|
|
277
|
+
totalTokens: number | null;
|
|
278
|
+
spentTokens: number;
|
|
279
|
+
exhausted: boolean;
|
|
280
|
+
}>;
|
|
281
|
+
readonly resultPreview?: string;
|
|
282
|
+
readonly error?: string;
|
|
283
|
+
readonly version: number;
|
|
284
|
+
readonly coarseVersion: number;
|
|
285
|
+
}
|
|
286
|
+
export interface PolyphaseDetails {
|
|
287
|
+
v: 1;
|
|
288
|
+
runId: string;
|
|
289
|
+
kind: RunKind;
|
|
290
|
+
origin: RunOrigin;
|
|
291
|
+
mode?: SubagentMode;
|
|
292
|
+
title: string;
|
|
293
|
+
/** "running" in partial details. */
|
|
294
|
+
status: RunStatus;
|
|
295
|
+
startedAt: number;
|
|
296
|
+
endedAt?: number;
|
|
297
|
+
workflow?: {
|
|
298
|
+
name: string;
|
|
299
|
+
description: string;
|
|
300
|
+
source: WorkflowSource;
|
|
301
|
+
path?: string;
|
|
302
|
+
args?: string;
|
|
303
|
+
};
|
|
304
|
+
phases?: PhaseDetails[];
|
|
305
|
+
currentPhase?: number;
|
|
306
|
+
agents: AgentDetails[];
|
|
307
|
+
agentsOmitted?: {
|
|
308
|
+
count: number;
|
|
309
|
+
byStatus: Partial<Record<AgentStatus, number>>;
|
|
310
|
+
};
|
|
311
|
+
log?: string[];
|
|
312
|
+
logOmitted?: number;
|
|
313
|
+
totals: {
|
|
314
|
+
agents: number;
|
|
315
|
+
/** Billable tokens: input + output + cacheWrite. */
|
|
316
|
+
tokens: number;
|
|
317
|
+
/** USD. */
|
|
318
|
+
cost: number;
|
|
319
|
+
byStatus: Partial<Record<AgentStatus, number>>;
|
|
320
|
+
blockedToolCalls: number;
|
|
321
|
+
};
|
|
322
|
+
budget?: {
|
|
323
|
+
totalTokens: number;
|
|
324
|
+
spentTokens: number;
|
|
325
|
+
exhausted: boolean;
|
|
326
|
+
};
|
|
327
|
+
resultPreview?: string;
|
|
328
|
+
error?: string;
|
|
329
|
+
/** Degradation level applied to fit the byte cap (§9.2). */
|
|
330
|
+
degraded?: 0 | 1 | 2 | 3 | 4;
|
|
331
|
+
}
|
|
332
|
+
export interface PhaseDetails {
|
|
333
|
+
title: string;
|
|
334
|
+
detail?: string;
|
|
335
|
+
model?: string;
|
|
336
|
+
dynamic?: boolean;
|
|
337
|
+
}
|
|
338
|
+
export interface AgentDetails {
|
|
339
|
+
i: number;
|
|
340
|
+
label: string;
|
|
341
|
+
agent: string;
|
|
342
|
+
phase?: number;
|
|
343
|
+
step?: number;
|
|
344
|
+
status: AgentStatus;
|
|
345
|
+
cancelReason?: CancelReason;
|
|
346
|
+
/** "provider/id" when known, else the requested pattern. */
|
|
347
|
+
model?: string;
|
|
348
|
+
thinking?: ThinkingLevel;
|
|
349
|
+
modelSource?: ModelSource;
|
|
350
|
+
modelConfirmed?: boolean;
|
|
351
|
+
startedAt?: number;
|
|
352
|
+
endedAt?: number;
|
|
353
|
+
turns?: number;
|
|
354
|
+
toolCalls?: number;
|
|
355
|
+
tools?: Record<string, number>;
|
|
356
|
+
tokens?: number;
|
|
357
|
+
cost?: number;
|
|
358
|
+
blocked?: number;
|
|
359
|
+
/** e.g. "bash: npm test -- auth". */
|
|
360
|
+
blockedSample?: string;
|
|
361
|
+
task: string;
|
|
362
|
+
/** Partial details only. */
|
|
363
|
+
now?: string;
|
|
364
|
+
/** Last `STATUS: ...` line of the output. */
|
|
365
|
+
statusLine?: string;
|
|
366
|
+
/** Head+tail preview of the final output. */
|
|
367
|
+
output?: string;
|
|
368
|
+
error?: string;
|
|
369
|
+
merge?: "ok" | "failed";
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=types.d.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AC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAC;CACxB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types and constants for polyphase: subagent/workflow orchestration, the child
|
|
3
|
+
* event stream, and the persisted/live views consumed by rendering and the inspector.
|
|
4
|
+
*
|
|
5
|
+
* This module owns the vocabulary. Other polyphase modules import from here instead of
|
|
6
|
+
* redeclaring these shapes.
|
|
7
|
+
*/
|
|
8
|
+
// ── Names and limits ───────────────────────────────────────────────────────
|
|
9
|
+
export const POLYPHASE_DEPTH_ENV = "DRAHT_POLYPHASE_DEPTH";
|
|
10
|
+
export const POLYPHASE_SCHEMA_FILE_ENV = "DRAHT_POLYPHASE_SCHEMA_FILE";
|
|
11
|
+
export const SUBAGENT_TOOL_NAME = "subagent";
|
|
12
|
+
export const WORKFLOW_TOOL_NAME = "workflow";
|
|
13
|
+
export const DUET_DELEGATE_TOOL_NAME = "duet_delegate";
|
|
14
|
+
export const POLYPHASE_RESULT_TOOL_NAME = "polyphase_result";
|
|
15
|
+
/** Suffix of the permission gate's block reason when no UI can answer (builtins/subagent.ts). */
|
|
16
|
+
export const NO_UI_APPROVAL_SUFFIX = "(no UI available to request approval)";
|
|
17
|
+
export const FINAL_DETAILS_MAX_BYTES = 16_384;
|
|
18
|
+
export const PARTIAL_DETAILS_MAX_BYTES = 8_192;
|
|
19
|
+
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
20
|
+
export function isThinkingLevel(value) {
|
|
21
|
+
return typeof value === "string" && THINKING_LEVELS.includes(value);
|
|
22
|
+
}
|
|
23
|
+
/** Nesting depth of this process: 0 for the user's session, n for a child spawned at depth n-1. */
|
|
24
|
+
export function currentPolyphaseDepth(env = process.env) {
|
|
25
|
+
const parsed = Number.parseInt(env[POLYPHASE_DEPTH_ENV] ?? "0", 10);
|
|
26
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
|
27
|
+
}
|
|
28
|
+
export const DEFAULT_CHILD_STATE_LIMITS = {
|
|
29
|
+
maxItems: 400,
|
|
30
|
+
maxChars: 256_000,
|
|
31
|
+
maxItemChars: 32_000,
|
|
32
|
+
maxFinalTextChars: 200_000,
|
|
33
|
+
maxStderrChars: 16_384,
|
|
34
|
+
finishedMaxChars: 32_000,
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/polyphase/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,8EAA8E;AAE9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAC3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,6BAA6B,CAAC;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AAE7D,iGAAiG;AACjG,MAAM,CAAC,MAAM,qBAAqB,GAAG,uCAAuC,CAAC;AAE7E,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAC9C,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAErH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5F,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,qBAAqB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AA4JD,MAAM,CAAC,MAAM,0BAA0B,GAAqB;IAC3D,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,OAAO;IACjB,YAAY,EAAE,MAAM;IACpB,iBAAiB,EAAE,OAAO;IAC1B,cAAc,EAAE,MAAM;IACtB,gBAAgB,EAAE,MAAM;CACxB,CAAC","sourcesContent":["/**\n * Shared types and constants for polyphase: subagent/workflow orchestration, the child\n * event stream, and the persisted/live views consumed by rendering and the inspector.\n *\n * This module owns the vocabulary. Other polyphase modules import from here instead of\n * redeclaring these shapes.\n */\n\nimport type { ThinkingLevel } from \"@draht/agent-core\";\nimport type { JsonObject, JsonValue, StopReason, Usage } from \"@draht/ai\";\nimport type { MergeResult } from \"../multi-agent/index.ts\";\nimport type { ChildEventReducer } from \"./child-events.ts\";\n\n// ── Names and limits ───────────────────────────────────────────────────────\n\nexport const POLYPHASE_DEPTH_ENV = \"DRAHT_POLYPHASE_DEPTH\";\nexport const POLYPHASE_SCHEMA_FILE_ENV = \"DRAHT_POLYPHASE_SCHEMA_FILE\";\nexport const SUBAGENT_TOOL_NAME = \"subagent\";\nexport const WORKFLOW_TOOL_NAME = \"workflow\";\nexport const DUET_DELEGATE_TOOL_NAME = \"duet_delegate\";\nexport const POLYPHASE_RESULT_TOOL_NAME = \"polyphase_result\";\n\n/** Suffix of the permission gate's block reason when no UI can answer (builtins/subagent.ts). */\nexport const NO_UI_APPROVAL_SUFFIX = \"(no UI available to request approval)\";\n\nexport const FINAL_DETAILS_MAX_BYTES = 16_384;\nexport const PARTIAL_DETAILS_MAX_BYTES = 8_192;\n\nexport const THINKING_LEVELS: readonly ThinkingLevel[] = [\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"];\n\nexport function isThinkingLevel(value: unknown): value is ThinkingLevel {\n\treturn typeof value === \"string\" && (THINKING_LEVELS as readonly string[]).includes(value);\n}\n\n/** Nesting depth of this process: 0 for the user's session, n for a child spawned at depth n-1. */\nexport function currentPolyphaseDepth(env: NodeJS.ProcessEnv = process.env): number {\n\tconst parsed = Number.parseInt(env[POLYPHASE_DEPTH_ENV] ?? \"0\", 10);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : 0;\n}\n\n// ── Agent definitions and the runner seam (moved from builtins/subagent.ts) ──\n\nexport interface AgentConfig {\n\tname: string;\n\tdescription: string;\n\ttools?: string[];\n\tmodel?: string;\n\t/** Disable user and project extensions in the child process. Core builtins still load. */\n\tdisableExtensions?: boolean;\n\tsystemPrompt: string;\n\tsource: \"user\" | \"project\";\n}\n\nexport interface ModelRef {\n\tprovider: string;\n\tid: string;\n}\n\nexport interface RunResult {\n\tagent: string;\n\ttask: string;\n\texitCode: number;\n\toutput: string;\n\tstderr: string;\n\tusage?: Usage;\n\tstep?: number;\n\tmerge?: MergeResult;\n\t/** Confirmed from the child's first assistant message_start. */\n\tmodel?: ModelRef;\n\t/** Confirmed from the child's assistant message_end. */\n\tthinkingLevel?: ThinkingLevel;\n\tstopReason?: StopReason;\n\tturns?: number;\n\ttoolCalls?: number;\n\tblockedToolCalls?: number;\n\t/** Validated polyphase_result arguments when a schema was requested. */\n\tstructured?: { value: JsonValue };\n\tcancelled?: boolean;\n\tdurationMs?: number;\n}\n\nexport type ProgressFn = (activity: string) => void;\nexport type ChildStateChange = \"none\" | \"fine\" | \"coarse\";\n\n/** Per-run options threaded from orchestrators to the process runner. All optional. */\nexport interface AgentRunContext {\n\t/** `--model` value. Overrides agent.model when set. */\n\tmodel?: string;\n\t/** `--thinking` value. */\n\tthinking?: ThinkingLevel;\n\t/** Model display info used when the runner creates its own reducer. */\n\tmodelInfo?: AgentModelInfo;\n\t/** Retry once without --model/--thinking when the child cannot resolve the inherited model (§7.3). */\n\tfallbackToChildDefaultModel?: boolean;\n\t/** Added to the runner's fixed exclusions (workflow, duet_delegate). */\n\texcludeTools?: readonly string[];\n\t/** Appended to `--tools` only when the agent has a tools allowlist. */\n\textraTools?: readonly string[];\n\t/** Appended to the agent system prompt in the same temp file. */\n\textraSystemPrompt?: string;\n\t/** Extra environment for the child. */\n\tenv?: Readonly<Record<string, string>>;\n\t/** Object JSON Schema for polyphase_result. The runner writes it to a 0600 temp file. */\n\tschema?: JsonObject;\n\t/** Live state sink. When absent the runner uses a private reducer. */\n\treducer?: ChildEventReducer;\n\tonQueued?: () => void;\n\tonStart?: (info: { pid: number | undefined; argv: readonly string[] }) => void;\n\tonChange?: (change: \"fine\" | \"coarse\") => void;\n\t/** Called once by runAgentWithLifecycle with the final result (after merge-back). */\n\tonFinish?: (result: RunResult) => void;\n}\n\nexport type AgentRunner = (\n\tcwd: string,\n\tagent: AgentConfig,\n\ttask: string,\n\tsignal?: AbortSignal,\n\tstep?: number,\n\tonProgress?: ProgressFn,\n\trun?: AgentRunContext,\n) => Promise<RunResult>;\n\n// ── Child state ─────────────────────────────────────────────────────────────\n\nexport type AgentStatus =\n\t| \"pending\" // created, not yet asked to run (later chain step)\n\t| \"queued\" // waiting for a limiter slot\n\t| \"starting\" // process spawned, no agent_start yet\n\t| \"running\"\n\t| \"done\"\n\t| \"failed\"\n\t| \"cancelled\"\n\t| \"skipped\"; // never started because its run ended (e.g. chain stopped)\nexport type AgentActivity = \"idle\" | \"waiting\" | \"thinking\" | \"writing\" | \"tool\" | \"retrying\" | \"compacting\";\nexport type ModelSource = \"override\" | \"phase\" | \"frontmatter\" | \"inherited\" | \"child-default\";\nexport type CancelReason = \"user\" | \"budget\" | \"run\" | \"parent\" | \"shutdown\";\n\nexport interface AgentModelInfo {\n\tsource: ModelSource;\n\t/** Value passed with --model (or the frontmatter pattern). */\n\trequested?: string;\n\trequestedThinking?: ThinkingLevel;\n\t/** Pre-resolved in the parent, then confirmed by the child's assistant message_start. */\n\tprovider?: string;\n\tid?: string;\n\t/** Confirmed at message_end, or by thinking_level_changed. */\n\tthinkingLevel?: ThinkingLevel;\n\tconfirmed: boolean;\n}\n\nexport type ToolItemStatus = \"pending\" | \"running\" | \"ok\" | \"error\" | \"blocked\";\n\n/** `rev` increments on every mutation of the item (cache key for wrapped lines). */\nexport type TranscriptItem =\n\t| {\n\t\t\tkind: \"thinking\";\n\t\t\tseq: number;\n\t\t\trev: number;\n\t\t\ttext: string;\n\t\t\tdroppedChars: number;\n\t\t\tdone: boolean;\n\t\t\tredacted: boolean;\n\t }\n\t| { kind: \"text\"; seq: number; rev: number; text: string; droppedChars: number; done: boolean }\n\t| {\n\t\t\tkind: \"tool\";\n\t\t\tseq: number;\n\t\t\trev: number;\n\t\t\ttoolCallId: string;\n\t\t\tname: string;\n\t\t\tsummary: string;\n\t\t\tstatus: ToolItemStatus;\n\t\t\tstartedAt?: number;\n\t\t\tendedAt?: number;\n\t\t\tresultPreview?: string;\n\t\t\tblockedReason?: string;\n\t }\n\t| { kind: \"notice\"; seq: number; rev: number; level: \"info\" | \"warning\" | \"error\"; text: string; at: number };\n\nexport interface BlockedToolCall {\n\ttoolName: string;\n\tsummary: string;\n\treason: string;\n}\n\nexport interface ChildStateLimits {\n\tmaxItems: number; // 400\n\tmaxChars: number; // 256_000 transcript chars while running\n\tmaxItemChars: number; // 32_000 per thinking/text item (tail kept)\n\tmaxFinalTextChars: number; // 200_000\n\tmaxStderrChars: number; // 16_384 (tail kept)\n\tfinishedMaxChars: number; // 32_000 after the run finished\n}\nexport const DEFAULT_CHILD_STATE_LIMITS: ChildStateLimits = {\n\tmaxItems: 400,\n\tmaxChars: 256_000,\n\tmaxItemChars: 32_000,\n\tmaxFinalTextChars: 200_000,\n\tmaxStderrChars: 16_384,\n\tfinishedMaxChars: 32_000,\n};\n\nexport interface ChildAgentState {\n\tlifecycle: \"pending\" | \"queued\" | \"spawning\" | \"running\" | \"settled\" | \"exited\";\n\tactivity: AgentActivity;\n\tsessionId?: string;\n\tmodel: AgentModelInfo;\n\tturns: number;\n\ttoolCalls: number;\n\ttoolErrors: number;\n\ttoolCounts: Record<string, number>;\n\t/** Newest last, at most 20 kept. */\n\tblocked: BlockedToolCall[];\n\tblockedCount: number;\n\tcurrentTool?: { toolCallId: string; name: string; summary: string; startedAt: number };\n\t/** Sum of finished assistant message usage (combineUsage). */\n\tusage?: Usage;\n\t/** Cumulative usage of the in-flight assistant message. */\n\tliveUsage?: Usage;\n\ttranscript: TranscriptItem[];\n\ttranscriptChars: number;\n\tdroppedItems: number;\n\tnextSeq: number;\n\t/** One line, ≤ 160 chars: what the agent is doing right now. */\n\tnowLine: string;\n\t/** First text part of the last assistant message that had text, capped. */\n\tfinalText: string;\n\tstopReason?: StopReason;\n\terrorMessage?: string;\n\t/** Arguments of the last successful polyphase_result call (validated later by the runner). */\n\tstructured?: { value: JsonValue };\n\tretry?: { attempt: number; maxAttempts: number; delayMs: number; errorMessage: string };\n\tstderrTail: string;\n\tmalformedLines: number;\n\tdroppedLines: number;\n\trecordsSeen: number;\n\tqueuedAt?: number;\n\tstartedAt?: number;\n\tendedAt?: number;\n\tlastEventAt?: number;\n\t/** ++ on every fine or coarse change. */\n\tversion: number;\n\t/** ++ on every coarse change. */\n\tcoarseVersion: number;\n}\n\n// ── Runs: read-only views implemented by store.ts, consumed by details/text/render/inspector ──\n\nexport type RunKind = \"subagent\" | \"workflow\" | \"duet\";\nexport type RunOrigin = \"tool\" | \"command\";\nexport type SubagentMode = \"single\" | \"parallel\" | \"chain\";\nexport type RunStatus = \"running\" | \"done\" | \"failed\" | \"cancelled\";\nexport type WorkflowSource = \"inline\" | \"project\" | \"user\";\n\nexport interface PhaseInfo {\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n\t/** True for phases created by phase()/agent({phase}) that meta did not declare. */\n\tdynamic: boolean;\n}\n\nexport interface WorkflowRunInfo {\n\tname: string;\n\tdescription: string;\n\tsource: WorkflowSource;\n\tpath?: string;\n\targs: string;\n}\n\nexport interface LogLine {\n\tat: number;\n\tlevel: \"info\" | \"warning\";\n\ttext: string;\n\tphase?: number;\n}\n\nexport interface AgentView {\n\t/** `${runId}#${index}` */\n\treadonly key: string;\n\treadonly index: number;\n\treadonly label: string;\n\treadonly agentType: string;\n\treadonly task: string;\n\treadonly phase?: number;\n\t/** 1-based chain step. */\n\treadonly step?: number;\n\treadonly status: AgentStatus;\n\treadonly cancelReason?: CancelReason;\n\treadonly state: Readonly<ChildAgentState>;\n\treadonly result?: Readonly<RunResult>;\n\treadonly createdAt: number;\n}\n\nexport interface RunView {\n\treadonly id: string;\n\treadonly kind: RunKind;\n\treadonly origin: RunOrigin;\n\treadonly mode?: SubagentMode;\n\treadonly title: string;\n\treadonly workflow?: Readonly<WorkflowRunInfo>;\n\treadonly phases: readonly PhaseInfo[];\n\treadonly currentPhase?: number;\n\treadonly status: RunStatus;\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly agents: readonly AgentView[];\n\treadonly log: readonly LogLine[];\n\treadonly logDropped: number;\n\treadonly budget: Readonly<{ totalTokens: number | null; spentTokens: number; exhausted: boolean }>;\n\treadonly resultPreview?: string;\n\treadonly error?: string;\n\treadonly version: number;\n\treadonly coarseVersion: number;\n}\n\n// ── Persisted, bounded, JSON-compatible tool-result details (D2) ────────────\n\nexport interface PolyphaseDetails {\n\tv: 1;\n\trunId: string;\n\tkind: RunKind;\n\torigin: RunOrigin;\n\tmode?: SubagentMode;\n\ttitle: string;\n\t/** \"running\" in partial details. */\n\tstatus: RunStatus;\n\tstartedAt: number;\n\tendedAt?: number;\n\tworkflow?: { name: string; description: string; source: WorkflowSource; path?: string; args?: string };\n\tphases?: PhaseDetails[];\n\tcurrentPhase?: number;\n\tagents: AgentDetails[];\n\tagentsOmitted?: { count: number; byStatus: Partial<Record<AgentStatus, number>> };\n\tlog?: string[];\n\tlogOmitted?: number;\n\ttotals: {\n\t\tagents: number;\n\t\t/** Billable tokens: input + output + cacheWrite. */\n\t\ttokens: number;\n\t\t/** USD. */\n\t\tcost: number;\n\t\tbyStatus: Partial<Record<AgentStatus, number>>;\n\t\tblockedToolCalls: number;\n\t};\n\tbudget?: { totalTokens: number; spentTokens: number; exhausted: boolean };\n\tresultPreview?: string;\n\terror?: string;\n\t/** Degradation level applied to fit the byte cap (§9.2). */\n\tdegraded?: 0 | 1 | 2 | 3 | 4;\n}\n\nexport interface PhaseDetails {\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n\tdynamic?: boolean;\n}\n\nexport interface AgentDetails {\n\ti: number;\n\tlabel: string;\n\tagent: string;\n\tphase?: number;\n\tstep?: number;\n\tstatus: AgentStatus;\n\tcancelReason?: CancelReason;\n\t/** \"provider/id\" when known, else the requested pattern. */\n\tmodel?: string;\n\tthinking?: ThinkingLevel;\n\tmodelSource?: ModelSource;\n\tmodelConfirmed?: boolean;\n\tstartedAt?: number;\n\tendedAt?: number;\n\tturns?: number;\n\ttoolCalls?: number;\n\ttools?: Record<string, number>;\n\ttokens?: number;\n\tcost?: number;\n\tblocked?: number;\n\t/** e.g. \"bash: npm test -- auth\". */\n\tblockedSample?: string;\n\ttask: string;\n\t/** Partial details only. */\n\tnow?: string;\n\t/** Last `STATUS: ...` line of the output. */\n\tstatusLine?: string;\n\t/** Head+tail preview of the final output. */\n\toutput?: string;\n\terror?: string;\n\tmerge?: \"ok\" | \"failed\";\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `installPolyphaseUi`: wires the `alt+a` agent inspector overlay and the above-editor dock
|
|
3
|
+
* widget into one TUI session. Inert outside `ctx.mode === "tui" && ctx.hasUI` (§12.1, §12.7).
|
|
4
|
+
*/
|
|
5
|
+
import type { ExtensionContext, UIPromptKind } from "../../extensions/types.ts";
|
|
6
|
+
import type { ArchivedRun } from "../details.ts";
|
|
7
|
+
import type { PolyphaseSession } from "../session.ts";
|
|
8
|
+
import type { SavedWorkflowSummary } from "../workflow/saved.ts";
|
|
9
|
+
import { type InspectorInitialView } from "./inspector.ts";
|
|
10
|
+
export interface PolyphaseUiOptions {
|
|
11
|
+
ctx: ExtensionContext;
|
|
12
|
+
session: PolyphaseSession;
|
|
13
|
+
getArchivedRuns(): readonly ArchivedRun[];
|
|
14
|
+
getSavedWorkflows(): readonly SavedWorkflowSummary[];
|
|
15
|
+
/** `!hideThinkingBlock` is the inspector's initial thinking visibility (§12.3). Defaults to
|
|
16
|
+
* showing thinking when omitted. */
|
|
17
|
+
hideThinkingBlock?(): boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface PolyphaseUiController {
|
|
20
|
+
openInspector(initial?: InspectorInitialView): void;
|
|
21
|
+
closeInspector(): void;
|
|
22
|
+
isInspectorOpen(): boolean;
|
|
23
|
+
notePromptStart(kind: UIPromptKind): void;
|
|
24
|
+
notePromptEnd(): void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function installPolyphaseUi(options: PolyphaseUiOptions): PolyphaseUiController;
|
|
28
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/core/polyphase/ui/controller.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,KAAK,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AAE/E,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,gBAAgB,CAAC;IACtB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,eAAe,IAAI,SAAS,WAAW,EAAE,CAAC;IAC1C,iBAAiB,IAAI,SAAS,oBAAoB,EAAE,CAAC;IACrD;wCACoC;IACpC,iBAAiB,CAAC,IAAI,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACrC,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACpD,cAAc,IAAI,IAAI,CAAC;IACvB,eAAe,IAAI,OAAO,CAAC;IAC3B,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1C,aAAa,IAAI,IAAI,CAAC;IACtB,OAAO,IAAI,IAAI,CAAC;CAChB;AAqJD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,qBAAqB,CAGrF"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `installPolyphaseUi`: wires the `alt+a` agent inspector overlay and the above-editor dock
|
|
3
|
+
* widget into one TUI session. Inert outside `ctx.mode === "tui" && ctx.hasUI` (§12.1, §12.7).
|
|
4
|
+
*/
|
|
5
|
+
import { getKeybindings } from "@draht/tui";
|
|
6
|
+
import { PolyphaseDock } from "./dock.js";
|
|
7
|
+
import { PolyphaseInspector } from "./inspector.js";
|
|
8
|
+
const DOCK_WIDGET_KEY = "polyphase";
|
|
9
|
+
function inertController() {
|
|
10
|
+
return {
|
|
11
|
+
openInspector: () => { },
|
|
12
|
+
closeInspector: () => { },
|
|
13
|
+
isInspectorOpen: () => false,
|
|
14
|
+
notePromptStart: () => { },
|
|
15
|
+
notePromptEnd: () => { },
|
|
16
|
+
dispose: () => { },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
class PolyphaseUiControllerImpl {
|
|
20
|
+
options;
|
|
21
|
+
unsubscribeTerminalInput;
|
|
22
|
+
unsubscribeStore;
|
|
23
|
+
unsubscribeParentPrompt;
|
|
24
|
+
inspectorActive = false;
|
|
25
|
+
activeDone;
|
|
26
|
+
dockVisible = false;
|
|
27
|
+
/** The runner (`extensions/runner.ts` `withUIPrompt`) emits `ui_prompt_start`/`ui_prompt_end`
|
|
28
|
+
* only for the outermost prompt bracket, so this is always 0 or 1 - counting every pair,
|
|
29
|
+
* including our own inspector's "custom" prompt, keeps it correct when a nested prompt (e.g.
|
|
30
|
+
* the subagent gate's confirm) starts before our bracket has finished closing: the runner
|
|
31
|
+
* folds that nested prompt into the still-open outer bracket instead of starting a new one,
|
|
32
|
+
* so `outerPromptCount` only reaches 0 once the whole bracket - nested confirm included - ends.
|
|
33
|
+
* `handleTerminalInput` checks `inspectorActive` before this count, so our own prompt alone
|
|
34
|
+
* never blocks opening or closing. */
|
|
35
|
+
outerPromptCount = 0;
|
|
36
|
+
disposed = false;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.unsubscribeTerminalInput = options.ctx.ui.onTerminalInput((data) => this.handleTerminalInput(data));
|
|
40
|
+
this.unsubscribeStore = options.session.store.subscribe((change) => {
|
|
41
|
+
if (change.type === "runs" && change.coarse)
|
|
42
|
+
this.syncDockVisibility();
|
|
43
|
+
});
|
|
44
|
+
this.unsubscribeParentPrompt = options.session.onParentPrompt(() => this.closeInspector());
|
|
45
|
+
this.syncDockVisibility();
|
|
46
|
+
}
|
|
47
|
+
handleTerminalInput(data) {
|
|
48
|
+
if (!getKeybindings().matches(data, "app.polyphase.inspector"))
|
|
49
|
+
return undefined;
|
|
50
|
+
if (this.inspectorActive) {
|
|
51
|
+
this.closeInspector();
|
|
52
|
+
return { consume: true };
|
|
53
|
+
}
|
|
54
|
+
if (this.outerPromptCount > 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
this.openInspector();
|
|
57
|
+
return { consume: true };
|
|
58
|
+
}
|
|
59
|
+
openInspector(initial = { view: "auto" }) {
|
|
60
|
+
if (this.disposed || this.inspectorActive)
|
|
61
|
+
return;
|
|
62
|
+
this.inspectorActive = true;
|
|
63
|
+
this.options.session.setInspectorOpen(true);
|
|
64
|
+
const settle = () => {
|
|
65
|
+
this.inspectorActive = false;
|
|
66
|
+
this.activeDone = undefined;
|
|
67
|
+
this.options.session.setInspectorOpen(false);
|
|
68
|
+
};
|
|
69
|
+
this.options.ctx.ui
|
|
70
|
+
.custom((tui, theme, keybindings, done) => {
|
|
71
|
+
const inspector = new PolyphaseInspector({
|
|
72
|
+
session: this.options.session,
|
|
73
|
+
tui,
|
|
74
|
+
theme,
|
|
75
|
+
keybindings,
|
|
76
|
+
getArchivedRuns: () => this.options.getArchivedRuns(),
|
|
77
|
+
getSavedWorkflows: () => this.options.getSavedWorkflows(),
|
|
78
|
+
initial,
|
|
79
|
+
showThinking: !(this.options.hideThinkingBlock?.() ?? false),
|
|
80
|
+
close: () => done(undefined),
|
|
81
|
+
insertCommand: (text) => this.options.ctx.ui.setEditorText(text),
|
|
82
|
+
});
|
|
83
|
+
// Assigned only once construction succeeds, so a throwing constructor never leaves
|
|
84
|
+
// `activeDone` pointing at a factory call that never produced a component.
|
|
85
|
+
this.activeDone = () => done(undefined);
|
|
86
|
+
return inspector;
|
|
87
|
+
}, {
|
|
88
|
+
overlay: true,
|
|
89
|
+
overlayOptions: () => ({ anchor: "center", width: "100%", maxHeight: "100%", margin: 1 }),
|
|
90
|
+
})
|
|
91
|
+
// Both outcomes must clear `inspectorActive`/`activeDone` and flip the pump back to its
|
|
92
|
+
// slow interval - otherwise a throwing factory (or a rejecting `custom()`) leaves the
|
|
93
|
+
// inspector permanently unopenable and the session stuck on the fast inspector interval.
|
|
94
|
+
.then(settle, settle);
|
|
95
|
+
}
|
|
96
|
+
closeInspector() {
|
|
97
|
+
if (!this.inspectorActive)
|
|
98
|
+
return;
|
|
99
|
+
this.activeDone?.();
|
|
100
|
+
}
|
|
101
|
+
isInspectorOpen() {
|
|
102
|
+
return this.inspectorActive;
|
|
103
|
+
}
|
|
104
|
+
notePromptStart(_kind) {
|
|
105
|
+
if (this.disposed)
|
|
106
|
+
return;
|
|
107
|
+
this.outerPromptCount++;
|
|
108
|
+
}
|
|
109
|
+
notePromptEnd() {
|
|
110
|
+
if (this.disposed)
|
|
111
|
+
return;
|
|
112
|
+
this.outerPromptCount = Math.max(0, this.outerPromptCount - 1);
|
|
113
|
+
}
|
|
114
|
+
syncDockVisibility() {
|
|
115
|
+
if (this.disposed)
|
|
116
|
+
return;
|
|
117
|
+
const shouldShow = this.options.session.store.totals().running > 0 && this.options.session.settings().dock;
|
|
118
|
+
if (shouldShow === this.dockVisible)
|
|
119
|
+
return;
|
|
120
|
+
this.dockVisible = shouldShow;
|
|
121
|
+
this.setDockWidget(shouldShow);
|
|
122
|
+
}
|
|
123
|
+
setDockWidget(visible) {
|
|
124
|
+
if (visible) {
|
|
125
|
+
this.options.ctx.ui.setWidget(DOCK_WIDGET_KEY, (tui, theme) => new PolyphaseDock({ session: this.options.session, tui, theme }), { placement: "aboveEditor" });
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.options.ctx.ui.setWidget(DOCK_WIDGET_KEY, undefined);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
dispose() {
|
|
132
|
+
if (this.disposed)
|
|
133
|
+
return;
|
|
134
|
+
this.disposed = true;
|
|
135
|
+
this.unsubscribeTerminalInput();
|
|
136
|
+
this.unsubscribeStore();
|
|
137
|
+
this.unsubscribeParentPrompt();
|
|
138
|
+
this.closeInspector();
|
|
139
|
+
if (this.dockVisible) {
|
|
140
|
+
this.dockVisible = false;
|
|
141
|
+
this.setDockWidget(false);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function installPolyphaseUi(options) {
|
|
146
|
+
if (options.ctx.mode !== "tui" || !options.ctx.hasUI)
|
|
147
|
+
return inertController();
|
|
148
|
+
return new PolyphaseUiControllerImpl(options);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=controller.js.map
|