@esso0428/pi-subagents 0.17.5 → 0.17.7
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 +14 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +1 -1
- package/dist/abortable.d.ts +13 -0
- package/dist/abortable.d.ts.map +1 -0
- package/dist/abortable.js +43 -0
- package/dist/abortable.js.map +1 -0
- package/dist/agent-color.d.ts +36 -0
- package/dist/agent-color.d.ts.map +1 -0
- package/dist/agent-color.js +124 -0
- package/dist/agent-color.js.map +1 -0
- package/dist/agent-file-toggle.d.ts +126 -0
- package/dist/agent-file-toggle.d.ts.map +1 -0
- package/dist/agent-file-toggle.js +259 -0
- package/dist/agent-file-toggle.js.map +1 -0
- package/dist/agent-history.d.ts +4 -0
- package/dist/agent-history.d.ts.map +1 -1
- package/dist/agent-history.js +47 -1
- package/dist/agent-history.js.map +1 -1
- package/dist/agent-manager.d.ts +370 -56
- package/dist/agent-manager.d.ts.map +1 -1
- package/dist/agent-manager.js +1123 -409
- package/dist/agent-manager.js.map +1 -1
- package/dist/agent-runner.d.ts +100 -10
- package/dist/agent-runner.d.ts.map +1 -1
- package/dist/agent-runner.js +166 -21
- package/dist/agent-runner.js.map +1 -1
- package/dist/agent-types.d.ts +57 -5
- package/dist/agent-types.d.ts.map +1 -1
- package/dist/agent-types.js +164 -32
- package/dist/agent-types.js.map +1 -1
- package/dist/child-context.d.ts +3 -0
- package/dist/child-context.d.ts.map +1 -0
- package/dist/child-context.js +13 -0
- package/dist/child-context.js.map +1 -0
- package/dist/cross-extension-rpc.d.ts +23 -3
- package/dist/cross-extension-rpc.d.ts.map +1 -1
- package/dist/cross-extension-rpc.js +79 -17
- package/dist/cross-extension-rpc.js.map +1 -1
- package/dist/custom-agents.d.ts +38 -1
- package/dist/custom-agents.d.ts.map +1 -1
- package/dist/custom-agents.js +164 -12
- package/dist/custom-agents.js.map +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1908 -495
- package/dist/index.js.map +1 -1
- package/dist/invocation-config.d.ts +87 -2
- package/dist/invocation-config.d.ts.map +1 -1
- package/dist/invocation-config.js +71 -3
- package/dist/invocation-config.js.map +1 -1
- package/dist/mention-clone.d.ts +88 -0
- package/dist/mention-clone.d.ts.map +1 -0
- package/dist/mention-clone.js +154 -0
- package/dist/mention-clone.js.map +1 -0
- package/dist/mention.d.ts +82 -0
- package/dist/mention.d.ts.map +1 -0
- package/dist/mention.js +132 -0
- package/dist/mention.js.map +1 -0
- package/dist/model-resolver.d.ts +17 -0
- package/dist/model-resolver.d.ts.map +1 -1
- package/dist/model-resolver.js +15 -0
- package/dist/model-resolver.js.map +1 -1
- package/dist/model-scope.d.ts +50 -0
- package/dist/model-scope.d.ts.map +1 -0
- package/dist/model-scope.js +49 -0
- package/dist/model-scope.js.map +1 -0
- package/dist/nested-tools.d.ts +57 -0
- package/dist/nested-tools.d.ts.map +1 -0
- package/dist/nested-tools.js +301 -0
- package/dist/nested-tools.js.map +1 -0
- package/dist/output-file.d.ts +22 -3
- package/dist/output-file.d.ts.map +1 -1
- package/dist/output-file.js +58 -7
- package/dist/output-file.js.map +1 -1
- package/dist/prompts.d.ts +23 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +20 -2
- package/dist/prompts.js.map +1 -1
- package/dist/schedule.d.ts.map +1 -1
- package/dist/schedule.js +36 -15
- package/dist/schedule.js.map +1 -1
- package/dist/settings.d.ts +228 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +94 -0
- package/dist/settings.js.map +1 -1
- package/dist/status-note.d.ts +49 -1
- package/dist/status-note.d.ts.map +1 -1
- package/dist/status-note.js +62 -1
- package/dist/status-note.js.map +1 -1
- package/dist/structured-output.d.ts +62 -0
- package/dist/structured-output.d.ts.map +1 -0
- package/dist/structured-output.js +113 -0
- package/dist/structured-output.js.map +1 -0
- package/dist/types.d.ts +176 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/agent-mention.d.ts +83 -0
- package/dist/ui/agent-mention.d.ts.map +1 -0
- package/dist/ui/agent-mention.js +188 -0
- package/dist/ui/agent-mention.js.map +1 -0
- package/dist/ui/agent-widget.d.ts +96 -75
- package/dist/ui/agent-widget.d.ts.map +1 -1
- package/dist/ui/agent-widget.js +397 -420
- package/dist/ui/agent-widget.js.map +1 -1
- package/dist/ui/conversation-blocks.d.ts.map +1 -1
- package/dist/ui/conversation-blocks.js +6 -0
- package/dist/ui/conversation-blocks.js.map +1 -1
- package/dist/ui/conversation-timeline.d.ts +10 -2
- package/dist/ui/conversation-timeline.d.ts.map +1 -1
- package/dist/ui/conversation-timeline.js +130 -23
- package/dist/ui/conversation-timeline.js.map +1 -1
- package/dist/ui/conversation-viewer.d.ts +20 -5
- package/dist/ui/conversation-viewer.d.ts.map +1 -1
- package/dist/ui/conversation-viewer.js +274 -73
- package/dist/ui/conversation-viewer.js.map +1 -1
- package/dist/ui/fleet-list.d.ts +198 -0
- package/dist/ui/fleet-list.d.ts.map +1 -0
- package/dist/ui/fleet-list.js +487 -0
- package/dist/ui/fleet-list.js.map +1 -0
- package/dist/ui/schedule-menu.d.ts.map +1 -1
- package/dist/ui/schedule-menu.js +6 -7
- package/dist/ui/schedule-menu.js.map +1 -1
- package/dist/ui/select-item.d.ts +28 -0
- package/dist/ui/select-item.d.ts.map +1 -0
- package/dist/ui/select-item.js +35 -0
- package/dist/ui/select-item.js.map +1 -0
- package/dist/ui/workflow-card.d.ts +176 -0
- package/dist/ui/workflow-card.d.ts.map +1 -0
- package/dist/ui/workflow-card.js +333 -0
- package/dist/ui/workflow-card.js.map +1 -0
- package/dist/ui/workflow-dialog.d.ts +306 -0
- package/dist/ui/workflow-dialog.d.ts.map +1 -0
- package/dist/ui/workflow-dialog.js +844 -0
- package/dist/ui/workflow-dialog.js.map +1 -0
- package/dist/ui/workflow-menu.d.ts +61 -0
- package/dist/ui/workflow-menu.d.ts.map +1 -0
- package/dist/ui/workflow-menu.js +148 -0
- package/dist/ui/workflow-menu.js.map +1 -0
- package/dist/usage.d.ts +86 -1
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +72 -1
- package/dist/usage.js.map +1 -1
- package/dist/workflow/collisions.d.ts +96 -0
- package/dist/workflow/collisions.d.ts.map +1 -0
- package/dist/workflow/collisions.js +89 -0
- package/dist/workflow/collisions.js.map +1 -0
- package/dist/workflow/entry.d.ts +33 -0
- package/dist/workflow/entry.d.ts.map +1 -0
- package/dist/workflow/entry.js +30 -0
- package/dist/workflow/entry.js.map +1 -0
- package/dist/workflow/host.d.ts +63 -0
- package/dist/workflow/host.d.ts.map +1 -0
- package/dist/workflow/host.js +363 -0
- package/dist/workflow/host.js.map +1 -0
- package/dist/workflow/journal.d.ts +98 -0
- package/dist/workflow/journal.d.ts.map +1 -0
- package/dist/workflow/journal.js +121 -0
- package/dist/workflow/journal.js.map +1 -0
- package/dist/workflow/json-schema.d.ts +52 -0
- package/dist/workflow/json-schema.d.ts.map +1 -0
- package/dist/workflow/json-schema.js +112 -0
- package/dist/workflow/json-schema.js.map +1 -0
- package/dist/workflow/meta.d.ts +68 -0
- package/dist/workflow/meta.d.ts.map +1 -0
- package/dist/workflow/meta.js +318 -0
- package/dist/workflow/meta.js.map +1 -0
- package/dist/workflow/progress.d.ts +225 -0
- package/dist/workflow/progress.d.ts.map +1 -0
- package/dist/workflow/progress.js +362 -0
- package/dist/workflow/progress.js.map +1 -0
- package/dist/workflow/runtime.d.ts +335 -0
- package/dist/workflow/runtime.d.ts.map +1 -0
- package/dist/workflow/runtime.js +831 -0
- package/dist/workflow/runtime.js.map +1 -0
- package/dist/workflow/saved.d.ts +91 -0
- package/dist/workflow/saved.d.ts.map +1 -0
- package/dist/workflow/saved.js +204 -0
- package/dist/workflow/saved.js.map +1 -0
- package/dist/workflow/task.d.ts +137 -0
- package/dist/workflow/task.d.ts.map +1 -0
- package/dist/workflow/task.js +208 -0
- package/dist/workflow/task.js.map +1 -0
- package/dist/workflow/tool-description.d.ts +39 -0
- package/dist/workflow/tool-description.d.ts.map +1 -0
- package/dist/workflow/tool-description.js +200 -0
- package/dist/workflow/tool-description.js.map +1 -0
- package/dist/workflow/worker-source.d.ts +48 -0
- package/dist/workflow/worker-source.d.ts.map +1 -0
- package/dist/workflow/worker-source.js +779 -0
- package/dist/workflow/worker-source.js.map +1 -0
- package/dist/worktree.d.ts +10 -3
- package/dist/worktree.d.ts.map +1 -1
- package/dist/worktree.js +58 -54
- package/dist/worktree.js.map +1 -1
- package/dist/xml.d.ts +11 -0
- package/dist/xml.d.ts.map +1 -0
- package/dist/xml.js +13 -0
- package/dist/xml.js.map +1 -0
- package/docs/rpc.md +183 -0
- package/docs/superpowers/plans/2026-09-30-conversation-viewer-scrollbar.md +216 -0
- package/docs/superpowers/plans/2026-09-30-upstream-event-workflow-partial-history.md +195 -0
- package/docs/superpowers/specs/2026-09-30-conversation-viewer-scrollbar-design.md +82 -0
- package/docs/superpowers/specs/2026-09-30-upstream-event-workflow-partial-history-design.md +49 -0
- package/docs/workflows.md +437 -0
- package/examples/agent-tool-description.md +7 -7
- package/examples/workflows/compose.js +51 -0
- package/examples/workflows/fan-out-audit.js +47 -0
- package/examples/workflows/gated-fix.js +60 -0
- package/examples/workflows/lib/count-child.js +27 -0
- package/examples/workflows/review-panel.js +63 -0
- package/examples/workflows/structured-findings.js +78 -0
- package/package.json +1 -1
- package/src/abortable.ts +43 -0
- package/src/agent-color.ts +161 -0
- package/src/agent-file-toggle.ts +269 -0
- package/src/agent-history.ts +54 -2
- package/src/agent-manager.ts +1263 -402
- package/src/agent-runner.ts +251 -27
- package/src/agent-types.ts +188 -32
- package/src/child-context.ts +15 -0
- package/src/cross-extension-rpc.ts +96 -20
- package/src/custom-agents.ts +170 -13
- package/src/index.ts +2024 -537
- package/src/invocation-config.ts +118 -3
- package/src/mention-clone.ts +196 -0
- package/src/mention.ts +141 -0
- package/src/model-resolver.ts +18 -0
- package/src/model-scope.ts +70 -0
- package/src/nested-tools.ts +424 -0
- package/src/output-file.ts +61 -6
- package/src/prompts.ts +45 -2
- package/src/schedule.ts +35 -14
- package/src/settings.ts +312 -2
- package/src/status-note.ts +66 -1
- package/src/structured-output.ts +130 -0
- package/src/types.ts +177 -10
- package/src/ui/agent-mention.ts +216 -0
- package/src/ui/agent-widget.ts +389 -441
- package/src/ui/conversation-blocks.ts +6 -0
- package/src/ui/conversation-timeline.ts +139 -25
- package/src/ui/conversation-viewer.ts +284 -69
- package/src/ui/fleet-list.ts +558 -0
- package/src/ui/schedule-menu.ts +9 -8
- package/src/ui/select-item.ts +45 -0
- package/src/ui/workflow-card.ts +470 -0
- package/src/ui/workflow-dialog.ts +1115 -0
- package/src/ui/workflow-menu.ts +193 -0
- package/src/usage.ts +109 -2
- package/src/workflow/collisions.ts +123 -0
- package/src/workflow/entry.ts +47 -0
- package/src/workflow/host.ts +403 -0
- package/src/workflow/journal.ts +164 -0
- package/src/workflow/json-schema.ts +128 -0
- package/src/workflow/meta.ts +325 -0
- package/src/workflow/progress.ts +550 -0
- package/src/workflow/runtime.ts +1219 -0
- package/src/workflow/saved.ts +217 -0
- package/src/workflow/task.ts +302 -0
- package/src/workflow/tool-description.ts +200 -0
- package/src/workflow/worker-source.ts +781 -0
- package/src/worktree.ts +69 -55
- package/src/xml.ts +13 -0
- package/vitest.config.ts +0 -18
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime.ts — the host half of a workflow run.
|
|
3
|
+
*
|
|
4
|
+
* Owns the worker lifecycle, the RPC bridge, the concurrency semaphore, the
|
|
5
|
+
* per-run caps, and the progress log. The script's only route to an agent is a
|
|
6
|
+
* `call` message landing here, which is what makes the caps and the abort story
|
|
7
|
+
* enforceable at all: a script cannot go around them because it has nothing to
|
|
8
|
+
* go around them *with*.
|
|
9
|
+
*
|
|
10
|
+
* Spawning is injected rather than imported. `AgentManager` is a large, stateful
|
|
11
|
+
* dependency and wiring it in directly would make every test here an integration
|
|
12
|
+
* test; a {@link WorkflowHost} stub is a dozen lines. The adapter that binds this
|
|
13
|
+
* to the real manager lives at the call site.
|
|
14
|
+
*/
|
|
15
|
+
import { type WorkflowJournalEntry } from "./journal.js";
|
|
16
|
+
import { type CompiledSchema } from "./json-schema.js";
|
|
17
|
+
import { type WorkflowMeta } from "./meta.js";
|
|
18
|
+
import type { WorkflowEntry } from "./progress.js";
|
|
19
|
+
/** Matches the `script` field's `maxLength` in the tool schema. */
|
|
20
|
+
export declare const MAX_SCRIPT_LENGTH = 524288;
|
|
21
|
+
/** Agents one run may schedule, in total. */
|
|
22
|
+
export declare const WORKFLOW_AGENT_CAP = 1000;
|
|
23
|
+
/** Items one `parallel()` or `pipeline()` call may take. */
|
|
24
|
+
export declare const WORKFLOW_ITEM_CAP = 4096;
|
|
25
|
+
/** Nested `workflow()` invocations allowed per run. */
|
|
26
|
+
export declare const WORKFLOW_NESTED_CAP = 256;
|
|
27
|
+
export declare class WorkflowRuntimeError extends Error {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Concurrent agents allowed, leaving two cores for the host and the TUI.
|
|
31
|
+
*
|
|
32
|
+
* `Math.max(1, …)` is not decoration: the raw `min(16, cpus - 2)` is 0 on a one-
|
|
33
|
+
* or two-core machine, and a semaphore with zero permits never hands out a slot,
|
|
34
|
+
* so the run would hang before its first agent rather than fail.
|
|
35
|
+
*/
|
|
36
|
+
export declare function workflowConcurrency(cpuCount?: number): number;
|
|
37
|
+
/** One agent the script asked for. `agentId` is the handle for {@link WorkflowHost.abortAgent}. */
|
|
38
|
+
export interface WorkflowSpawnRequest {
|
|
39
|
+
agentId: string;
|
|
40
|
+
/** Position in the run, and the progress entry's stable identity. */
|
|
41
|
+
index: number;
|
|
42
|
+
prompt: string;
|
|
43
|
+
label: string;
|
|
44
|
+
agentType: string;
|
|
45
|
+
model?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Reasoning effort for this child, as one of pi's thinking levels.
|
|
48
|
+
*
|
|
49
|
+
* Typed as a plain string because this interface is the host boundary and
|
|
50
|
+
* deliberately knows nothing about pi — `host.ts` is where it becomes a
|
|
51
|
+
* `ThinkingLevel`. The worker has already rejected anything off the list.
|
|
52
|
+
*/
|
|
53
|
+
effort?: string;
|
|
54
|
+
isolation?: "worktree";
|
|
55
|
+
/**
|
|
56
|
+
* Called by the host once the child's EFFECTIVE configuration is known —
|
|
57
|
+
* which is when its session exists, not when the spawn resolves.
|
|
58
|
+
*
|
|
59
|
+
* Without it a row could only ever show what the script asked for: a fuzzy
|
|
60
|
+
* `model: "haiku"` stays `haiku` instead of the id it resolved to, an
|
|
61
|
+
* `agent()` that named no model shows nothing at all, and a level pi clamped
|
|
62
|
+
* is presented as the level that was requested (#168, #182).
|
|
63
|
+
*
|
|
64
|
+
* Plain strings, like `effort` above: this interface is the host boundary and
|
|
65
|
+
* deliberately knows nothing about pi's `AgentInvocation`. Optional, so a host
|
|
66
|
+
* that cannot report any of this simply does not, and the row keeps the
|
|
67
|
+
* requested values it started with.
|
|
68
|
+
*/
|
|
69
|
+
onResolved?(info: {
|
|
70
|
+
/**
|
|
71
|
+
* The host's own id for the child — the manager's `AgentRecord` id here.
|
|
72
|
+
*
|
|
73
|
+
* Reported as soon as the host has one, which is earlier than the rest of
|
|
74
|
+
* this: the model is knowable only once a session exists, but the id is
|
|
75
|
+
* what lets a reader open that child's conversation, and a child that
|
|
76
|
+
* never got a model is exactly the one worth opening.
|
|
77
|
+
*/
|
|
78
|
+
recordId?: string;
|
|
79
|
+
modelName?: string;
|
|
80
|
+
modelId?: string;
|
|
81
|
+
thinking?: string;
|
|
82
|
+
requestedThinking?: string;
|
|
83
|
+
requestedModel?: string;
|
|
84
|
+
}): void;
|
|
85
|
+
/**
|
|
86
|
+
* Compiled from the script's `agent({ schema })`.
|
|
87
|
+
*
|
|
88
|
+
* The host must give the child a `StructuredOutput` tool built from it and
|
|
89
|
+
* return the validated payload as JSON text. Compiled rather than raw so the
|
|
90
|
+
* runtime can re-check the answer without re-parsing the schema per call.
|
|
91
|
+
*/
|
|
92
|
+
schema?: CompiledSchema;
|
|
93
|
+
phaseIndex?: number;
|
|
94
|
+
phaseTitle?: string;
|
|
95
|
+
/**
|
|
96
|
+
* The `gate` command this agent is being spawned under, when it has one.
|
|
97
|
+
*
|
|
98
|
+
* Passed down rather than run purely from here because an isolated child's
|
|
99
|
+
* worktree is destroyed as part of its own settle: a host that can reach
|
|
100
|
+
* inside that settle runs the gate there, against the tree the child wrote,
|
|
101
|
+
* and reports the outcome back as {@link WorkflowSpawnResult.gate}. A host
|
|
102
|
+
* that ignores this leaves the gate to {@link applyGate}, which then runs it
|
|
103
|
+
* itself — so exactly one execution either way.
|
|
104
|
+
*/
|
|
105
|
+
gate?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface WorkflowSpawnResult {
|
|
108
|
+
ok: boolean;
|
|
109
|
+
/** The agent's answer. Present when `ok`. */
|
|
110
|
+
text?: string;
|
|
111
|
+
/** Why it failed. Present when not `ok`. */
|
|
112
|
+
error?: string;
|
|
113
|
+
/** The user dismissed it rather than it failing; renders as skipped. */
|
|
114
|
+
skipped?: boolean;
|
|
115
|
+
tokens?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Output tokens only, for the script's `budget.spent()`.
|
|
118
|
+
*
|
|
119
|
+
* Separate from {@link tokens}, which is the lifetime total. Claude Code's
|
|
120
|
+
* budget counts output, and a fan-out's re-sent input would swamp it.
|
|
121
|
+
*/
|
|
122
|
+
outputTokens?: number;
|
|
123
|
+
/** Whether the child needed an extra prompt to produce its structured answer. */
|
|
124
|
+
structuredRetried?: boolean;
|
|
125
|
+
toolCalls?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Where the child actually ran.
|
|
128
|
+
*
|
|
129
|
+
* Only meaningful for `isolation: "worktree"`, and the whole reason it exists:
|
|
130
|
+
* a gate has to run against the tree the child edited, not the main one, or it
|
|
131
|
+
* verifies the wrong working copy. Left unset, a gate runs wherever the host
|
|
132
|
+
* runs commands by default.
|
|
133
|
+
*
|
|
134
|
+
* Usually unset for a worktree child even so: the copy is removed during the
|
|
135
|
+
* child's own settle, so it no longer exists by the time this is read. That
|
|
136
|
+
* is what {@link gate} is for.
|
|
137
|
+
*/
|
|
138
|
+
cwd?: string;
|
|
139
|
+
/**
|
|
140
|
+
* The outcome of this agent's `gate`, when the host already ran it.
|
|
141
|
+
*
|
|
142
|
+
* Set only by a host that ran the command itself — inside the child's
|
|
143
|
+
* worktree, while that directory still existed. Its presence is what tells
|
|
144
|
+
* {@link applyGate} the command has already been executed; the pass/fail
|
|
145
|
+
* decision and the error shaping still happen there, in one place.
|
|
146
|
+
*/
|
|
147
|
+
gate?: WorkflowGateResult;
|
|
148
|
+
}
|
|
149
|
+
/** Outcome of a `gate` command. `output` is what the user is shown when it fails. */
|
|
150
|
+
export interface WorkflowGateResult {
|
|
151
|
+
ok: boolean;
|
|
152
|
+
/** Combined stdout/stderr, or whatever the host wants surfaced as the failure. */
|
|
153
|
+
output: string;
|
|
154
|
+
}
|
|
155
|
+
/** The one seam between a workflow and the rest of the extension. */
|
|
156
|
+
/** How a script names another workflow: a saved name, or a path to a file. */
|
|
157
|
+
export interface WorkflowScriptRef {
|
|
158
|
+
name?: string;
|
|
159
|
+
scriptPath?: string;
|
|
160
|
+
}
|
|
161
|
+
export type WorkflowScriptSource = {
|
|
162
|
+
ok: true;
|
|
163
|
+
script: string;
|
|
164
|
+
path?: string;
|
|
165
|
+
} | {
|
|
166
|
+
ok: false;
|
|
167
|
+
message: string;
|
|
168
|
+
};
|
|
169
|
+
export interface WorkflowHost {
|
|
170
|
+
spawnAgent(request: WorkflowSpawnRequest): Promise<WorkflowSpawnResult>;
|
|
171
|
+
/** Called for every in-flight agent when the run aborts. */
|
|
172
|
+
abortAgent(agentId: string): void;
|
|
173
|
+
/**
|
|
174
|
+
* Continue a child that already ran in this run, keeping its context.
|
|
175
|
+
*
|
|
176
|
+
* `agentId` is one previously handed out in a {@link WorkflowSpawnRequest};
|
|
177
|
+
* the child keeps the agent type, model and tool contract it started with, so
|
|
178
|
+
* only the follow-up prompt crosses.
|
|
179
|
+
*
|
|
180
|
+
* Optional: a host without it rejects `resume` rather than quietly starting a
|
|
181
|
+
* fresh child that has none of the context the script is counting on.
|
|
182
|
+
*/
|
|
183
|
+
resumeAgent?(agentId: string, prompt: string,
|
|
184
|
+
/**
|
|
185
|
+
* Same reporter {@link WorkflowSpawnRequest.onResolved} carries, for the
|
|
186
|
+
* same reason: a resumed row is rebuilt from scratch, so without it the
|
|
187
|
+
* continuation of a child would show the model the script *asked* for while
|
|
188
|
+
* the row above it shows the one that ran.
|
|
189
|
+
*/
|
|
190
|
+
onResolved?: WorkflowSpawnRequest["onResolved"]): Promise<WorkflowSpawnResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Run a `gate` command and report whether it passed.
|
|
193
|
+
*
|
|
194
|
+
* `cwd` is the child's worktree when it had one. Optional for the same reason
|
|
195
|
+
* as {@link resumeAgent}, and more sharply: a gate that silently does not run
|
|
196
|
+
* would mark unverified work as verified, so the runtime fails the call
|
|
197
|
+
* instead of skipping it.
|
|
198
|
+
*/
|
|
199
|
+
runGate?(command: string, options: {
|
|
200
|
+
agentId: string;
|
|
201
|
+
cwd?: string;
|
|
202
|
+
}): Promise<WorkflowGateResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Resolve a nested `workflow()` reference to source.
|
|
205
|
+
*
|
|
206
|
+
* The runtime knows nothing about the filesystem or about pi, so it asks. It
|
|
207
|
+
* still decides whether what comes back *is* a workflow — see
|
|
208
|
+
* {@link validateScript} — because those rules belong with the runtime that
|
|
209
|
+
* enforces them everywhere else.
|
|
210
|
+
*
|
|
211
|
+
* Optional for the same reason as {@link resumeAgent}: a host without it
|
|
212
|
+
* rejects `workflow()` outright rather than silently running nothing.
|
|
213
|
+
*/
|
|
214
|
+
loadWorkflow?(ref: WorkflowScriptRef): Promise<WorkflowScriptSource> | WorkflowScriptSource;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* What a run can be told to do while it is going, from the workflows dialog.
|
|
218
|
+
*
|
|
219
|
+
* Every method is best-effort and idempotent: the dialog renders off a progress
|
|
220
|
+
* log that lags the runtime slightly, so it will sometimes ask for something
|
|
221
|
+
* that has just stopped being possible. `false` means "there was nothing to do
|
|
222
|
+
* that to" — a caller can say so, but it is never an error.
|
|
223
|
+
*/
|
|
224
|
+
export interface WorkflowControl {
|
|
225
|
+
/**
|
|
226
|
+
* Stop *starting* agents. Ones already running are left to finish, because
|
|
227
|
+
* killing model work mid-turn throws away everything it has spent and there
|
|
228
|
+
* is no way to hand it back its context.
|
|
229
|
+
*/
|
|
230
|
+
pause(): void;
|
|
231
|
+
resume(): void;
|
|
232
|
+
isPaused(): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Give up on the agent at `index`: its `agent()` call returns `null`, exactly
|
|
235
|
+
* as a terminal failure does, and the row renders skipped.
|
|
236
|
+
*
|
|
237
|
+
* Immediate for a running agent and for one held at a pause. An agent parked
|
|
238
|
+
* behind the concurrency limit takes its skip when it reaches the front —
|
|
239
|
+
* the alternative is a cancellable semaphore for a case that resolves itself
|
|
240
|
+
* as soon as any sibling finishes.
|
|
241
|
+
*/
|
|
242
|
+
skip(index: number): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Start the agent at `index` over: the child is stopped and the same call is
|
|
245
|
+
* re-run, so the script's `agent()` promise is still the one waiting and it
|
|
246
|
+
* gets the new answer.
|
|
247
|
+
*
|
|
248
|
+
* Only while it is running — that is the whole window. Once the call has
|
|
249
|
+
* settled its value is already the script's, and re-running would produce a
|
|
250
|
+
* result with nowhere to go.
|
|
251
|
+
*/
|
|
252
|
+
retry(index: number): boolean;
|
|
253
|
+
}
|
|
254
|
+
export interface RunWorkflowOptions {
|
|
255
|
+
/** Full script source, starting with `export const meta = { … }`. */
|
|
256
|
+
script: string;
|
|
257
|
+
args?: unknown;
|
|
258
|
+
host: WorkflowHost;
|
|
259
|
+
signal?: AbortSignal;
|
|
260
|
+
/** Fired per batch, not per entry — see the worker's progress batching. */
|
|
261
|
+
onProgress?(entries: readonly WorkflowEntry[]): void;
|
|
262
|
+
concurrency?: number;
|
|
263
|
+
agentCap?: number;
|
|
264
|
+
itemCap?: number;
|
|
265
|
+
/**
|
|
266
|
+
* Hands the caller the run's control surface, once per run.
|
|
267
|
+
*
|
|
268
|
+
* A callback rather than a return value because `runWorkflow` resolves when
|
|
269
|
+
* the run is *over*, which is the one moment there is nothing left to
|
|
270
|
+
* control. Fired before the first agent starts.
|
|
271
|
+
*/
|
|
272
|
+
onControl?(control: WorkflowControl): void;
|
|
273
|
+
/**
|
|
274
|
+
* How many nested `workflow()` invocations one run may make in total.
|
|
275
|
+
*
|
|
276
|
+
* Each costs a compile and a scope rather than a thread, so the ceiling is
|
|
277
|
+
* generous — but unbounded is worse than capped, on the same reasoning as
|
|
278
|
+
* {@link agentCap}.
|
|
279
|
+
*/
|
|
280
|
+
nestedCap?: number;
|
|
281
|
+
/**
|
|
282
|
+
* Replay and record, for `resumeFromRunId`.
|
|
283
|
+
*
|
|
284
|
+
* The runtime does no file IO — `entries` come in already read and `append`
|
|
285
|
+
* goes back out — so its tests stay free of a filesystem, the same reason
|
|
286
|
+
* spawning is behind {@link WorkflowHost}.
|
|
287
|
+
*/
|
|
288
|
+
journal?: {
|
|
289
|
+
/** A previous run's settled calls, in position order. Empty replays nothing. */
|
|
290
|
+
entries?: readonly WorkflowJournalEntry[];
|
|
291
|
+
/** Called as each call of *this* run settles, so it can be resumed in turn. */
|
|
292
|
+
append?(entry: WorkflowJournalEntry): void;
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
export interface WorkflowRunResult {
|
|
296
|
+
status: "completed" | "failed" | "killed";
|
|
297
|
+
meta: WorkflowMeta;
|
|
298
|
+
/** The script's return value, JSON-checked at the boundary. */
|
|
299
|
+
value?: unknown;
|
|
300
|
+
error?: string;
|
|
301
|
+
/** The append-only log, in emission order. */
|
|
302
|
+
progress: WorkflowEntry[];
|
|
303
|
+
/** Agents scheduled, including those that failed. */
|
|
304
|
+
agentCount: number;
|
|
305
|
+
/** How many of those came back from the journal instead of being spawned. */
|
|
306
|
+
replayedCount: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Reject anything that cannot survive the round trip to the worker and into a
|
|
310
|
+
* resume journal. Structured clone would happily carry a `Map` or a cycle that
|
|
311
|
+
* the journal then cannot represent, so the check is stricter than the transport.
|
|
312
|
+
*/
|
|
313
|
+
export declare function assertBoundarySafe(value: unknown, path: string): void;
|
|
314
|
+
/**
|
|
315
|
+
* Run one workflow script to completion.
|
|
316
|
+
*
|
|
317
|
+
* Rejects before starting for a script that cannot run at all (bad `meta`, over
|
|
318
|
+
* the size limit, control characters, non-JSON `args`). Everything after the
|
|
319
|
+
* worker is live resolves instead, carrying the failure in `status` — by then
|
|
320
|
+
* there is a progress log worth handing back.
|
|
321
|
+
*/
|
|
322
|
+
/**
|
|
323
|
+
* Everything a script must satisfy before it is compiled.
|
|
324
|
+
*
|
|
325
|
+
* Extracted so a nested `workflow()` is held to exactly the same standard as a
|
|
326
|
+
* top-level run: same size limit, same character rules, same `meta` contract.
|
|
327
|
+
* The host resolves a reference to source; deciding whether that source is a
|
|
328
|
+
* workflow stays here, where the rules live.
|
|
329
|
+
*/
|
|
330
|
+
export declare function validateScript(script: string): {
|
|
331
|
+
meta: WorkflowMeta;
|
|
332
|
+
body: string;
|
|
333
|
+
};
|
|
334
|
+
export declare function runWorkflow(options: RunWorkflowOptions): Promise<WorkflowRunResult>;
|
|
335
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/workflow/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAoC,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAE,KAAK,cAAc,EAAqB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