@evandu/super-pi 0.1.0 → 0.1.2
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/agents/super-pi-task/core.ts +748 -485
- package/agents/super-pi-task/index.ts +198 -141
- package/dist/client/assets/index-CHw4ZoY4.js +43 -0
- package/dist/client/assets/{index-CsbZzuMy.css → index-WlIFA_Dt.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/application/run-service.d.ts +48 -1
- package/dist/server/application/run-service.js +78 -2
- package/dist/server/capability.d.ts +89 -0
- package/dist/server/capability.js +136 -0
- package/dist/server/command-handler.js +4 -0
- package/dist/server/http-server.js +20 -0
- package/dist/server/index.js +25 -2
- package/dist/server/runtime.d.ts +1 -0
- package/dist/server/runtime.js +13 -2
- package/dist/server/store.d.ts +42 -0
- package/dist/server/store.js +144 -1
- package/dist/server/task-tool.d.ts +21 -0
- package/dist/server/task-tool.js +21 -0
- package/dist/server/types.d.ts +34 -0
- package/dist/server/workflow-engine.d.ts +129 -0
- package/dist/server/workflow-engine.js +253 -0
- package/dist/server/workflow.d.ts +287 -0
- package/dist/server/workflow.js +387 -0
- package/package.json +5 -1
- package/dist/client/assets/index-BMQsEdio.js +0 -24
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import type { SubagentRosterEntry } from "./task-tool.js";
|
|
2
|
+
import type { SubagentRun } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The workflow PLAN: an ordered list of sub-agent steps the server will execute on the primary agent's
|
|
5
|
+
* behalf, carrying each step's output into the next one.
|
|
6
|
+
*
|
|
7
|
+
* WHY THIS FILE EXISTS, and why it holds no I/O at all.
|
|
8
|
+
*
|
|
9
|
+
* The dispatch pipe was already built and already proved: `task-tool.ts` is the policy half of the mouth,
|
|
10
|
+
* `subagent-runs.ts` records and publishes a run, `subagents.ts` spawns and drains a child. What was
|
|
11
|
+
* missing was that a MODEL, given a request that needs three different specialists in a row, had to
|
|
12
|
+
* remember the order itself and hand-copy each result into the next prompt by hand. That is the
|
|
13
|
+
* orchestration gap - and the reason the seam here is pure is the same reason `task-tool.ts` is: every
|
|
14
|
+
* rule in this file can then be proved without spawning a process, which is the only layer where a
|
|
15
|
+
* plan's shape, its refusals and its truncation budgets are cheap to test exhaustively.
|
|
16
|
+
*
|
|
17
|
+
* WHAT IS BORROWED FROM OPENCODE, and what is not: nothing. That is a deliberate departure from the
|
|
18
|
+
* sibling files, which each cite upstream lines they ported. OpenCode has no multi-sub-agent pipeline
|
|
19
|
+
* primitive to port - it composes `task` calls the same way this project did, by model convention, which
|
|
20
|
+
* is the gap. What this file reuses instead is local: the roster filter from `task-tool.ts` (the same one
|
|
21
|
+
* that decides who may be dispatched), and the `SubagentRunRecorder.dispatch` seam, which always resolves
|
|
22
|
+
* with a settled record and therefore needs no error parsing here.
|
|
23
|
+
*
|
|
24
|
+
* WHAT THIS FILE DELIBERATELY DOES NOT MODEL, because `docs/AGENT_LOOP_DESIGN.md` proposed all of it and
|
|
25
|
+
* each one is a second orchestration authority rather than a capability:
|
|
26
|
+
*
|
|
27
|
+
* - BRANCHES AND EDGES. A declared graph makes the model learn a language to express sequencing it can
|
|
28
|
+
* already express by dispatching twice. It also cannot be expressive enough, and a model that finds it
|
|
29
|
+
* too rigid bypasses it, leaving two ways to orchestrate that behave differently.
|
|
30
|
+
* - LOOP-BACK. `verifier.md` already ends its report with `通过`/`失败`, so the model can read a failed
|
|
31
|
+
* step and decide whether to run another round. That judgement is the thing worth keeping on the side
|
|
32
|
+
* that can read the output; encoding it as an edge would move it to a component that never sees the text.
|
|
33
|
+
* - A SEPARATE ARTIFACT STORE. `WorkflowAttempt` below IS the versioned artefact: one attempt's output is
|
|
34
|
+
* written once and never edited, and the next attempt appends beside it rather than replacing it.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* The id an orchestrated plan answers to.
|
|
38
|
+
*
|
|
39
|
+
* Prefixed and uuid-shaped for the same reason run ids are: the string is a lookup key in `state.json`
|
|
40
|
+
* and appears in `data-*` attributes in the browser, and a shape a person can recognise in a log is worth
|
|
41
|
+
* more than a bare uuid. `engine.ts` validates caller-supplied ids against this prefix the way
|
|
42
|
+
* `subagents.ts:358` validates run ids, because the same string becomes a reconciliation key at startup.
|
|
43
|
+
*/
|
|
44
|
+
export declare const newWorkflowRunId: () => string;
|
|
45
|
+
/** Matches the shape `newWorkflowRunId` produces, for validating a caller-supplied id. */
|
|
46
|
+
export declare const WORKFLOW_ID_PATTERN: RegExp;
|
|
47
|
+
/**
|
|
48
|
+
* How many steps one plan may hold.
|
|
49
|
+
*
|
|
50
|
+
* A bound, because every step is a real Pi process that runs for minutes and every step's output is
|
|
51
|
+
* carried forward: the cost of a plan grows with both its length and the size of what it accumulates.
|
|
52
|
+
* Eight steps is more than the pipelines this install's four sub-agents are built for (`scout` to
|
|
53
|
+
* `patcher` to `verifier`, maybe twice), so the bound is one a real request would not reach rather than
|
|
54
|
+
* one it would hit by accident.
|
|
55
|
+
*/
|
|
56
|
+
export declare const WORKFLOW_MAX_STEPS = 8;
|
|
57
|
+
/**
|
|
58
|
+
* What happens to a step that failed.
|
|
59
|
+
*
|
|
60
|
+
* `stop` is the DEFAULT and it is the honest one. `docs/AGENT_LOOP_DESIGN.md` named the failure this
|
|
61
|
+
* guards against in a sentence worth keeping: "A failed step never silently advances with missing input."
|
|
62
|
+
* Continuing past a failed step means the next sub-agent is handed a hole it cannot see, and the plan
|
|
63
|
+
* reports success. So a caller that says nothing about failure gets the behaviour that cannot lie.
|
|
64
|
+
*/
|
|
65
|
+
export type WorkflowFailurePolicy = "stop" | "skip" | "retry:1" | "retry:2" | "retry:3";
|
|
66
|
+
/** Every accepted policy, in the order the refusal message lists them for a model that guesses wrong. */
|
|
67
|
+
export declare const WORKFLOW_FAILURE_POLICIES: readonly WorkflowFailurePolicy[];
|
|
68
|
+
/**
|
|
69
|
+
* Reads a failure policy, or `undefined` for anything that is not one.
|
|
70
|
+
*
|
|
71
|
+
* `retry` alone normalizes to `retry:1`: a model that reaches for retry almost always means "try it
|
|
72
|
+
* again once", and refusing over a missing count would cost a retry of the plan itself. Everything else
|
|
73
|
+
* is refused rather than coerced, because guessing `stop` for a model that asked for `parallel` would
|
|
74
|
+
* silently run a different plan than the one it wrote.
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseFailurePolicy(raw: unknown): WorkflowFailurePolicy | undefined;
|
|
77
|
+
/** How many times a policy re-runs a failing step. `stop` and `skip` both run it zero further times. */
|
|
78
|
+
export declare function retriesFor(policy: WorkflowFailurePolicy): number;
|
|
79
|
+
/** Where a whole plan ended. `running` is the only state from which it advances on its own. */
|
|
80
|
+
export type WorkflowStatus = "running" | "completed" | "failed" | "stopped";
|
|
81
|
+
/** Where one step ended. `skipped` means the policy chose to walk past it after a failure. */
|
|
82
|
+
export type WorkflowStepStatus = "pending" | "running" | "completed" | "failed" | "skipped" | "stopped";
|
|
83
|
+
/**
|
|
84
|
+
* One try at one step.
|
|
85
|
+
*
|
|
86
|
+
* THE ARTEFACT, AND THE REASON THERE IS NO ARTIFACT STORE. A failed `verifier` that is retried has two
|
|
87
|
+
* different answers - the first one found two failing assertions, the second found none - and the first
|
|
88
|
+
* is exactly what makes the second legible. So an attempt is written once and never edited, and a retry
|
|
89
|
+
* appends beside the attempt it replaced instead of overwriting it. `n` is the attempt number within its
|
|
90
|
+
* step, not a global counter, so one step's history reads 1, 2, 3 without knowing anything about its neighbours.
|
|
91
|
+
*/
|
|
92
|
+
export type WorkflowAttempt = {
|
|
93
|
+
/** 1-based within the step. Attempt 1 is the first try, not a zero-th. */
|
|
94
|
+
n: number;
|
|
95
|
+
/** The `SubagentRun` this attempt produced. Absent only when the dispatch was refused before a run row existed. */
|
|
96
|
+
runId?: string;
|
|
97
|
+
/** How the run settled. Never `running`: `dispatch` resolves only once the child is terminal. */
|
|
98
|
+
status: "completed" | "failed" | "stopped";
|
|
99
|
+
/** The child's final message. Carried forward to later steps, and read by the primary agent afterwards. */
|
|
100
|
+
output?: string;
|
|
101
|
+
outputTruncated?: boolean;
|
|
102
|
+
startedAt: string;
|
|
103
|
+
finishedAt?: string;
|
|
104
|
+
/** Why this attempt did not complete. Present only beside a `failed` or `stopped` status. */
|
|
105
|
+
error?: string;
|
|
106
|
+
};
|
|
107
|
+
/** One step of a plan. Its `attempts` array is append-only; `status` is the derived summary of it. */
|
|
108
|
+
export type WorkflowStep = {
|
|
109
|
+
index: number;
|
|
110
|
+
agentId: string;
|
|
111
|
+
/** An opaque label for a person to read. The engine never branches on it. */
|
|
112
|
+
label?: string;
|
|
113
|
+
/** The prompt as the model wrote it, before any prior output is composed into it. */
|
|
114
|
+
prompt: string;
|
|
115
|
+
attempts: WorkflowAttempt[];
|
|
116
|
+
status: WorkflowStepStatus;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* A whole orchestrated plan, as persisted.
|
|
120
|
+
*
|
|
121
|
+
* The plan is written in full BEFORE step one runs, and that is the point of the record: progression is
|
|
122
|
+
* controlled by the server walking this structure, not by conventions inside successive prompts, so a
|
|
123
|
+
* browser that reloads mid-plan reads an accurate account of what was intended and not merely what
|
|
124
|
+
* happened to be written in a transcript so far.
|
|
125
|
+
*/
|
|
126
|
+
export type WorkflowRun = {
|
|
127
|
+
id: string;
|
|
128
|
+
conversationId: string;
|
|
129
|
+
/** One line describing what the whole plan is for, shown to a person above the timeline. */
|
|
130
|
+
summary: string;
|
|
131
|
+
onFailure: WorkflowFailurePolicy;
|
|
132
|
+
status: WorkflowStatus;
|
|
133
|
+
steps: WorkflowStep[];
|
|
134
|
+
/** Which step is executing or next. `steps.length` means the plan is past its last step. */
|
|
135
|
+
currentIndex: number;
|
|
136
|
+
startedAt: string;
|
|
137
|
+
finishedAt?: string;
|
|
138
|
+
};
|
|
139
|
+
/** One step as the primary agent is told about it: the last attempt, not the whole history. */
|
|
140
|
+
export type WorkflowStepSummary = {
|
|
141
|
+
n: number;
|
|
142
|
+
agentId: string;
|
|
143
|
+
label?: string;
|
|
144
|
+
status: WorkflowStepStatus;
|
|
145
|
+
/** How many tries this step took. Above one, the step failed before it passed, and that is visible. */
|
|
146
|
+
attempts: number;
|
|
147
|
+
output?: string;
|
|
148
|
+
outputTruncated?: boolean;
|
|
149
|
+
error?: string;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* What the endpoint hands back so the extension can render one envelope.
|
|
153
|
+
*
|
|
154
|
+
* The last attempt's output rather than all of them, for the same reason the conversation transcript is
|
|
155
|
+
* not re-sent into every turn: the primary agent needs to know what the pipeline concluded, and the
|
|
156
|
+
* earlier attempts are already in the run records and the timeline. Rendering happens on the extension
|
|
157
|
+
* side because the envelope is the tool's return value, not the server's - the same split
|
|
158
|
+
* `task-tool.ts:17-19` states for `<task>`.
|
|
159
|
+
*/
|
|
160
|
+
export type WorkflowSummary = {
|
|
161
|
+
id: string;
|
|
162
|
+
summary: string;
|
|
163
|
+
status: WorkflowStatus;
|
|
164
|
+
onFailure: WorkflowFailurePolicy;
|
|
165
|
+
steps: WorkflowStepSummary[];
|
|
166
|
+
finishedAt?: string;
|
|
167
|
+
};
|
|
168
|
+
/** The plan shape the engine executes, after validation. What `validateWorkflowPlan` returns on success. */
|
|
169
|
+
export type WorkflowPlan = {
|
|
170
|
+
summary: string;
|
|
171
|
+
onFailure: WorkflowFailurePolicy;
|
|
172
|
+
steps: {
|
|
173
|
+
agentId: string;
|
|
174
|
+
label?: string;
|
|
175
|
+
prompt: string;
|
|
176
|
+
}[];
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Text that had to lose its front, plus what it lost and why.
|
|
180
|
+
*
|
|
181
|
+
* `truncated` is carried rather than inferred from length so a CALLER can announce the loss. The house
|
|
182
|
+
* rule here is the one `task-tool.ts:102-116` already follows for an over-long roster: a payload that
|
|
183
|
+
* quietly omits part of itself makes a reader act on a belief that is not true, with no way to notice.
|
|
184
|
+
*/
|
|
185
|
+
export type CappedText = {
|
|
186
|
+
text: string;
|
|
187
|
+
truncated: boolean;
|
|
188
|
+
droppedChars: number;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Caps a block of text from the FRONT, and says in the surviving text that something was dropped.
|
|
192
|
+
*
|
|
193
|
+
* THE TAIL IS WHAT SURVIVES, and that is not an arbitrary choice. Every sub-agent in `agents/` is written
|
|
194
|
+
* to put its conclusion last - `verifier.md` says its last line is `通过`/`失败`/`无法验证` and nothing
|
|
195
|
+
* else - so keeping the end of a report keeps the part the next step and the human both need. Cutting
|
|
196
|
+
* from the end would keep the preamble and discard the verdict, which is the one line that matters.
|
|
197
|
+
*/
|
|
198
|
+
export declare function capText(text: string, budget: number, what: string): CappedText;
|
|
199
|
+
export declare const stepStatusWord: (status: WorkflowStepStatus) => string;
|
|
200
|
+
export declare const workflowStatusWord: (status: WorkflowStatus) => string;
|
|
201
|
+
/**
|
|
202
|
+
* Per-step cap on how much of one prior output is carried into the next step's prompt.
|
|
203
|
+
*
|
|
204
|
+
* Eight KB is roughly two thousand tokens of Chinese prose or a little more of code, which is enough for
|
|
205
|
+
* the conclusion-plus-evidence shape every sub-agent in `agents/` is instructed to produce, and small
|
|
206
|
+
* enough that eight of them plus the plan itself stay inside a normal model's working context.
|
|
207
|
+
*/
|
|
208
|
+
export declare const STEP_OUTPUT_BUDGET = 8000;
|
|
209
|
+
/**
|
|
210
|
+
* Total cap across all carried-forward output in one step's prompt.
|
|
211
|
+
*
|
|
212
|
+
* Separate from the per-step cap because the per-step one alone does not bound anything: eight steps
|
|
213
|
+
* carrying 8 KB each is 64 KB, which is larger than the whole context most sub-agents run with. The
|
|
214
|
+
* budget is spent newest-first, so the immediately preceding step - the one whose conclusion the current
|
|
215
|
+
* step is most likely acting on - is never the one that loses characters.
|
|
216
|
+
*/
|
|
217
|
+
export declare const WORKFLOW_CONTEXT_BUDGET = 32000;
|
|
218
|
+
/** The token that hands a step exactly the previous step's output, with nothing prepended. */
|
|
219
|
+
export declare const PREVIOUS_TOKEN = "{{previous}}";
|
|
220
|
+
/** The token that hands a step every prior step's output, with nothing prepended. */
|
|
221
|
+
export declare const HISTORY_TOKEN = "{{history}}";
|
|
222
|
+
/** What a composed prompt ended up carrying, so a caller can report it without re-parsing the string. */
|
|
223
|
+
export type ComposedPrompt = {
|
|
224
|
+
prompt: string;
|
|
225
|
+
/** How many prior steps actually contributed output. */
|
|
226
|
+
handedOff: number;
|
|
227
|
+
/** Whether anything was dropped for space. */
|
|
228
|
+
truncated: boolean;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Composes the prompt one step actually runs with, carrying earlier results into it.
|
|
232
|
+
*
|
|
233
|
+
* THE DEFAULT IS THE HANDOFF BLOCK, and the two tokens are the opt-outs. A model that does nothing
|
|
234
|
+
* special gets every prior step's output prepended, because "did the model remember to copy the last
|
|
235
|
+
* result forward" is not a property worth trusting a multi-step plan to. A model that WANTS control -
|
|
236
|
+
* wants the last output and nothing else, or wants the whole history verbatim - says so with a token,
|
|
237
|
+
* and in exchange the automatic block is suppressed entirely rather than being added alongside. Both
|
|
238
|
+
* spellings keep one rule intact: whatever this returns is the complete prompt, never a prefix that
|
|
239
|
+
* hides some of the instruction.
|
|
240
|
+
*
|
|
241
|
+
* AN EMPTY FIRST STEP IS THE PROMPT, VERBATIM. Composing a handoff header onto step one would tell a
|
|
242
|
+
* sub-agent about previous steps that do not exist, and would spend its attention on the header.
|
|
243
|
+
*/
|
|
244
|
+
export declare function composeStepPrompt(prompt: string, prior: readonly WorkflowStep[]): ComposedPrompt;
|
|
245
|
+
/**
|
|
246
|
+
* A plan that survived validation, or a sentence telling a MODEL what to fix.
|
|
247
|
+
*
|
|
248
|
+
* The refusal half exists because this value's first reader is a model about to retry: every message
|
|
249
|
+
* names what was wrong AND what an acceptable value looks like, following the rule `task-tool.ts:142`
|
|
250
|
+
* states for the depth refusal. `agents` is supplied in full even when the mistake is one member of it,
|
|
251
|
+
* because a model that guessed `scouter` has one correct answer and should not have to infer it.
|
|
252
|
+
*/
|
|
253
|
+
export type ValidatedPlan = {
|
|
254
|
+
plan: WorkflowPlan;
|
|
255
|
+
refusal?: undefined;
|
|
256
|
+
} | {
|
|
257
|
+
plan?: undefined;
|
|
258
|
+
refusal: string;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Checks an untrusted plan body against the roster that may actually be dispatched.
|
|
262
|
+
*
|
|
263
|
+
* VALIDATES, NEVER REWRITES, THE AGENT LIST. `agentId` is matched against the roster rather than
|
|
264
|
+
* defaulted, because defaulting would run a different sub-agent than the model asked for - a plan that
|
|
265
|
+
* silently substituted `patcher` for a misspelled `patchre` would edit files on a read-only request.
|
|
266
|
+
* The roster arrives already filtered to `mode: subagent` and non-hidden (`task-tool.ts:88`), so a
|
|
267
|
+
* primary agent's id is refused here by the same rule that refuses it at dispatch time
|
|
268
|
+
* (`subagents.ts:368`) - one lock, consulted twice, rather than a second list that could drift.
|
|
269
|
+
*/
|
|
270
|
+
export declare function validateWorkflowPlan(raw: unknown, roster: readonly SubagentRosterEntry[]): ValidatedPlan;
|
|
271
|
+
/**
|
|
272
|
+
* Reduces a persisted plan to what the primary agent is told when the workflow returns.
|
|
273
|
+
*
|
|
274
|
+
* ONE ATTEMPT PER STEP, THE LAST ONE. The earlier attempts stay in the run records and on the timeline,
|
|
275
|
+
* which is where a person debugging a retried plan looks; putting all of them in the envelope would make
|
|
276
|
+
* the model re-read a failure it has already acted on.
|
|
277
|
+
*/
|
|
278
|
+
export declare function workflowSummary(plan: WorkflowRun): WorkflowSummary;
|
|
279
|
+
/**
|
|
280
|
+
* The step a settled run became, as an attempt record.
|
|
281
|
+
*
|
|
282
|
+
* The narrow seam between the run recorder and this engine: everything about spawning, streaming and
|
|
283
|
+
* process teardown is the recorder's, and the only thing that crosses here is the settled record it
|
|
284
|
+
* always resolves with (`subagent-runs.ts:159`). `output` is copied rather than referenced because the
|
|
285
|
+
* store hands out clones, and a plan that kept a live reference would read whatever the run wrote next.
|
|
286
|
+
*/
|
|
287
|
+
export declare function attemptFromRun(run: SubagentRun, n: number): WorkflowAttempt;
|