@signalridge/pi-workflows 1.4.0 → 1.6.0

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.
@@ -1,8 +1,8 @@
1
1
  <!-- GENERATED from WORKFLOW_CAPABILITY_CONTRACT; do not edit by hand. -->
2
2
  # Exhaustive workflow capability facts
3
3
 
4
- Contract format: `1.0.0`<br>
5
- Contract content / skill / extension: `1.4.0`
4
+ Contract format: `2.0.0`<br>
5
+ Contract content / skill / extension: `1.6.0`
6
6
 
7
7
  Every exact fact below is projected from the installed extension's capability contract. Explanatory judgment belongs in the hand-written references next to this file.
8
8
 
@@ -16,8 +16,7 @@ Every exact fact below is projected from the installed extension's capability co
16
16
  - `label`: string (optional); default: derived from phase and call count
17
17
  - `phase`: string (optional); default: current phase
18
18
  - `schema`: plain JSON Schema (optional)
19
- - `model`: string (optional); default: pi-subagents model resolver
20
- - `tier`: small\|medium\|large (optional); default: pi-subagents workflow tier
19
+ - `strength`: "low" \| "medium" \| "high" (optional); default: no tier is sent; the agent's own tier, else agentTiers.defaultTier
21
20
  - `isolation`: "worktree" (optional); default: pi-subagents worktree policy
22
21
  - `thread`: string (optional); default: fresh session per call
23
22
  - `toolset`: string (optional); default: configured host/agent toolset hint
@@ -30,9 +29,15 @@ Every exact fact below is projected from the installed extension's capability co
30
29
  - Constraint: resume replays only the longest unchanged prefix; the first miss and every later call execute live
31
30
  - Constraint: replayed calls do not consume the real-dispatch maxAgents or token/phase budgets
32
31
  - Constraint: spawnKeys rotate by generation on resume so pi-subagents never raises a fingerprint conflict
33
- - Constraint: explicit model is resolved and scope-checked by pi-subagents; unavailable selectors fail closed
32
+ - Constraint: strength is this package's own vocabulary, not an agentTiers key; a word outside low/medium/high is rejected before dispatch
33
+ - Constraint: a strengths table alone binds a strength to an agent tier; an unmapped strength dispatches with no tier and takes the agent's own default
34
+ - Constraint: a call that names no strength also dispatches with no tier; there is no default strength, so an unlabelled call never outranks the agent type's own tier
35
+ - Constraint: an unconfigured host uses a shipped default table: each strength on the catalogue tier of the same name, where the host defines one
36
+ - Constraint: resolveAgentTier in pi-subagents owns model, thinking, clamping, availability, and the resolution snapshot
37
+ - Constraint: there is no per-call model, thinking, or tier: a strength is the only model policy a workflow can express
34
38
  - Constraint: same-thread calls must be sequential and preserve a stable workflow thread name
35
39
  - Constraint: threads cannot be combined with worktree isolation
40
+ - Constraint: an option name outside this list is rejected before dispatch, not ignored; tier, model, and thinking name their replacement
36
41
 
37
42
  <a id="runtime-global-parallel"></a>
38
43
  ## parallel
@@ -90,6 +95,7 @@ Every exact fact below is projected from the installed extension's capability co
90
95
  - `reviewers`: number (optional); default: 2
91
96
  - `threshold`: number (optional); default: 0.5
92
97
  - `lens`: string \| string[] (optional)
98
+ - `strength`: "low" \| "medium" \| "high" (optional); default: "low"
93
99
  - Constraint: threshold comparison is inclusive; real is false when no reviewer succeeds
94
100
 
95
101
  <a id="runtime-global-judgepanel"></a>
@@ -100,6 +106,7 @@ Every exact fact below is projected from the installed extension's capability co
100
106
  - Signature: `judgePanel(attempts, options?) => Promise<{ index, attempt, score, judgments } \| undefined>`
101
107
  - `judges`: number (optional); default: 3
102
108
  - `rubric`: string (optional); default: overall quality and correctness
109
+ - `strength`: "low" \| "medium" \| "high" (optional); default: "low"
103
110
  - Constraint: highest mean score wins with stable input index as the tie-break; empty input returns undefined
104
111
 
105
112
  <a id="runtime-global-loopuntildry"></a>
@@ -119,7 +126,8 @@ Every exact fact below is projected from the installed extension's capability co
119
126
 
120
127
  - Classification: `runtime-global`
121
128
  - Support: `supported`
122
- - Signature: `completenessCheck(taskArgs, results) => Promise<{ complete, missing? } \| null>`
129
+ - Signature: `completenessCheck(taskArgs, results, options?) => Promise<{ complete, missing? } \| null>`
130
+ - `strength`: "low" \| "medium" \| "high" (optional); default: "medium"
123
131
  - Constraint: only the first 4,000 characters of serialized result evidence are sent to the critic
124
132
 
125
133
  <a id="runtime-global-retry"></a>
@@ -154,6 +162,7 @@ Every exact fact below is projected from the installed extension's capability co
154
162
  - `timeoutMs`: number (optional)
155
163
  - Constraint: consumes one agent slot and no tokens
156
164
  - Constraint: journaled answers replay only within an unchanged resume prefix
165
+ - Constraint: an option name outside this list is rejected rather than ignored, since a dropped headless silently auto-approves
157
166
 
158
167
  <a id="runtime-global-log"></a>
159
168
  ## log
@@ -299,6 +308,7 @@ Every exact fact below is projected from the installed extension's capability co
299
308
  - Signature: `export const meta = { name, description, phases? }`
300
309
  - Constraint: must be the first statement
301
310
  - Constraint: name and description must be nonblank literals
311
+ - Constraint: workflow meta and phase metadata cannot contain model or thinking fields
302
312
  - Constraint: spread, computed keys, methods, template interpolation, and __proto__/constructor/prototype are rejected
303
313
 
304
314
  <a id="script-contract-determinism"></a>
@@ -8,7 +8,7 @@ Start from the symptom, then reproduce through the real workflow runtime with de
8
8
  | `parallel()` rejects input | Promises were passed instead of thunks | [runtime](runtime.md#topology) |
9
9
  | Synthesis starts early | Fan-out was not awaited as one complete result set | [pattern selection](pattern-selection.md#fan-out-and-synthesize) |
10
10
  | Coverage silently disappears | `null` results were filtered before IDs were ledgered | [lifecycle](lifecycle.md#retry-and-recoverable-failure) |
11
- | Wrong model is used | A higher-priority selector overrides the expected route | [registry ownership](registry-ownership.md#priority) |
11
+ | Wrong model or thinking is used | The call's strength is unmapped and fell to the agent's default, or the active `strengths` table — the user's, or the shipped default — points it at a profile that is not what you expected | [registry ownership](registry-ownership.md#priority) |
12
12
  | Unknown `agentType` log | A live registry name was guessed or is unavailable | [registry ownership](registry-ownership.md#agent-types) |
13
13
  | Budget exceeds the number shown | The budget is a soft pre-call gate and work was in flight | [lifecycle](lifecycle.md#bounds-and-budget) |
14
14
  | Later calls rerun on resume | An earlier call missed or changed, ending the replayable prefix | [lifecycle](lifecycle.md#resume) |
@@ -23,7 +23,7 @@ Start from the symptom, then reproduce through the real workflow runtime with de
23
23
 
24
24
  1. Reduce to the smallest script that preserves metadata, labels, work IDs, and the failing topology.
25
25
  2. Replace provider calls with deterministic, schema-aware fake agents.
26
- 3. Record call order, labels, phases, prompts, results, and `null` entries.
26
+ 3. Record call order, labels, phases, prompts, resolved tiers, results, and `null` entries.
27
27
  4. When the failure turns on a disputed signature or default, compare it with the compact [capability index](capabilities.md); follow its exhaustive-facts pointer only when needed.
28
28
  5. Separate runtime defects from unsupported authoring assumptions and compatibility-only behavior.
29
29
  6. Fix only the demonstrated authoring issue; do not rely on known out-of-scope gaps in nested persistence, resume accounting, checkpoint forms/timeouts, metadata validation, or budget overshoot.
@@ -4,5 +4,5 @@ Keep work IDs outside helper results that may omit failed agents.
4
4
 
5
5
  | Call | Contract |
6
6
  | --- | --- |
7
- | `verify(item, { reviewers: number, threshold: number, lens: string | string[] })` | Defaults: 2 reviewers, inclusive `0.5`, one lens or a cycled array. Returns `{ real, realCount, total, votes }`. Failed reviewers are omitted; successful votes are the denominator; zero survivors means `real: false`. |
8
- | `judgePanel(attempts, { judges: number, rubric: string })` | Defaults: 3 judges and `"overall quality and correctness"`. Failed judgments are omitted. Returns the highest mean `{ index, attempt, score, judgments }`; input order wins ties; empty input returns `undefined`. |
7
+ | `verify(item, { reviewers: number, threshold: number, lens: string | string[], strength })` | Defaults: 2 reviewers, inclusive `0.5`, one lens or a cycled array, and `strength: "low"` — reviewers are numerous and narrow, and the vote carries the gate rather than any one reviewer's depth. Returns `{ real, realCount, total, votes }`. Failed reviewers are omitted; successful votes are the denominator; zero survivors means `real: false`. |
8
+ | `judgePanel(attempts, { judges: number, rubric: string, strength })` | Defaults: 3 judges, `"overall quality and correctness"`, and `strength: "low"`. Failed judgments are omitted. Returns the highest mean `{ index, attempt, score, judgments }`; input order wins ties; empty input returns `undefined`. |
@@ -4,14 +4,16 @@ Model routes and agent types are dynamic references. Their shape and owner are d
4
4
 
5
5
  ## Model routes
6
6
 
7
- The `pi-subagents` workflow-tier settings own route names. Standard routes are `small`, `medium`, and `large`; use another route only when its name and purpose are supplied in context. A route is selected with `tier`. An exact user-requested model is selected with `model` and is resolved/scope-checked by pi-subagents.
7
+ pi-subagents owns the agent-tier catalogue. A workflow never names a key from it: a script names a *strength* (`low`/`medium`/`high`), and the user's `strengths` table is the only thing that binds one to a tier. Tier names depend on active configuration and are intentionally absent from static skill files; you do not need them, because you never write one.
8
+
9
+ A strength is a statement about the work, not a claim about the host. Every script — shipped or yours — names the same three, and there is no shipped/user distinction, because a strength can never reach the catalogue by itself: the binding is always an entry in a `strengths` table. A host that configured none uses the shipped default table, which is identity wherever the host defines a tier of the same name, so a stock machine honours your `low`/`medium` distinctions without configuration and a host with differently-named tiers leaves every strength unmapped. A user table replaces that default outright, and a strength it omits is unmapped even where a same-named tier exists — which is what lets workflow work be re-priced without touching the tier every ordinary spawn also names.
8
10
 
9
11
  ## Agent types
10
12
 
11
- The agent registry owns agent-type names and their bound instructions, tools, model, and isolation policy. Use `agentType` only when context supplies both its name and purpose. Do not infer an agent type from a role-like label.
13
+ The agent registry owns agent-type names and their bound instructions, tools, Agent-tier defaults, and isolation policy. Use `agentType` only when context supplies both its name and purpose. Do not infer an agent type from a role-like label.
12
14
 
13
15
  ## Priority
14
16
 
15
- An explicit per-call `model` wins. A named `agentType` model overrides a tier; an explicit `tier` suppresses the phase/run model so pi-subagents can apply the agent definition and then the selected workflow tier. Without a per-call model or tier, the phase/run model is used when present, followed by pi-subagents defaults and the parent session. Model and thinking fields are resolved independently. Avoid specifying competing selectors unless the override is deliberate.
17
+ A call's strength resolves through the user's `strengths` table into at most one tier key. That key, when there is one, takes precedence over an agent type's own tier default, which takes precedence over `agentTiers.defaultTier`. A call that names no strength, or one whose strength the table does not define, sends no key and leaves that precedence to the host — which is why there is no default strength: one would overrule every agent type's own tier on calls the script never meant to route. `resolveAgentTier()` in pi-subagents then resolves model, thinking, clamping, availability, and the immutable snapshot as one decision. Neither a call, nor workflow meta, nor a phase may carry model, thinking, or tier fields.
16
18
 
17
- Unavailability is fail-closed for explicit `model` and named tiers: pi-subagents reports the selector and does not silently run a different model. An omitted selector may inherit the parent session according to the companion's current settings.
19
+ Unavailability is fail-closed: pi-subagents names the tier and does not silently run a different model. A managed call with no tier and no applicable default is rejected rather than inheriting the parent session — which an unmapped strength can reach on a host whose default has been cleared.
@@ -6,6 +6,7 @@ Review author-visible behavior, not formatting preferences. When behavior depend
6
6
 
7
7
  - Is literal `export const meta` the first statement, with a short unique name and useful description?
8
8
  - Are only used phases declared, and does each named phase begin at the intended boundary?
9
+ - Are workflow meta and phase objects free of retired `model`/`thinking` fields?
9
10
  - Does the script call at least one agent and explicitly return JSON-serializable data?
10
11
  - Are imports and nondeterministic APIs absent?
11
12
 
@@ -21,8 +22,10 @@ Review author-visible behavior, not formatting preferences. When behavior depend
21
22
 
22
23
  - Does JavaScript consume structured fields only after a small plain JSON Schema guarantees them?
23
24
  - Does synthesis receive complete coverage and failure ledgers?
24
- - Are `model`, `tier`, and `agentType` used according to selector priority?
25
- - Did every nonstandard route or agent type come from context with a name and purpose?
25
+ - Does every call name a `strength` from `low`/`medium`/`high`, chosen for the effort the step deserves rather than copied from a tier name?
26
+ - Does every helper that dispatches for you (`verify`, `judgePanel`, `completenessCheck`) either take its documented default deliberately or pass an explicit `strength`?
27
+ - Is the strength the only model/thinking policy source, resolved through the active `strengths` table and then pi-subagents' `resolveAgentTier()`?
28
+ - Did every agent-type name come from context with a name and purpose?
26
29
 
27
30
  ## Lifecycle
28
31
 
@@ -33,6 +36,7 @@ Review author-visible behavior, not formatting preferences. When behavior depend
33
36
  - Does nesting stay one level, allow only safe sibling concurrency, and account for shared limits/store?
34
37
  - Are helper attempts and graph retries finite and separately visible?
35
38
  - Would lexical call order and generated graph order remain stable under resume?
39
+ - Does the journal/tombstone retain the resolved `tier`, including one the host defaulted to?
36
40
 
37
41
  ## Compatibility and publication
38
42
 
@@ -4,7 +4,7 @@ Use this page for routine scripts. Open the generated capability index only when
4
4
 
5
5
  ## Script envelope
6
6
 
7
- Start with the only legal export: `export const meta = { name, description, phases?: [{ title, detail?, model? }] }`. Values are nonblank literals; declare only used phases and call `phase()` before each phase's work. The remaining body already runs inside an async function: write helpers as ordinary declarations; `export default` and other exports are invalid. Return the result explicitly.
7
+ Start with the only legal export: `export const meta = { name, description, phases?: [{ title, detail? }] }`. Values are nonblank literals; declare only used phases and call `phase()` before each phase's work. Workflow meta and phase objects must not contain `model` or `thinking`; those retired fields are rejected. The remaining body already runs inside an async function: write helpers as ordinary declarations; `export default` and other exports are invalid. Return the result explicitly.
8
8
 
9
9
  The runtime supplies `agent`, `parallel`, `pipeline`, `orchestrate`, `workflow`, quality/control helpers, `phase`, `log`, `args`, `cwd`, restricted `process.cwd()`, and `budget`. Imports, `require()`, filesystem modules, `Date.now()`, `Math.random()`, and no-argument `new Date()` are unavailable. The Node VM realm is implementation substrate, not a security boundary or public API.
10
10
 
@@ -17,7 +17,7 @@ The runtime supplies `agent`, `parallel`, `pipeline`, `orchestrate`, `workflow`,
17
17
 
18
18
  ## Data and failure
19
19
 
20
- Call `agent(prompt, { label, schema? })`; it returns text, a schema-validated value, or recoverable `null`. Nonrecoverable limit, validation, and budget failures throw. Record each intended work ID before filtering. A `null` means missing coverage, never a negative finding.
20
+ Call `agent(prompt, { label, schema?, strength? })`; it returns text, a schema-validated value, or recoverable `null`. `strength` is `low`/`medium`/`high` and has no default — omitting it sends no tier. Nonrecoverable limit, validation, budget, unknown-strength, and unavailable-tier failures throw. Record each intended work ID before filtering. A `null` means missing coverage, never a negative finding.
21
21
 
22
22
  Use `agent(prompt, { thread: "implementer" })` when the same managed subagent must receive a later follow-up with its complete conversation intact. Reuse a thread name sequentially; never put same-thread calls in one `parallel()` batch. Threads are scoped to one workflow run/session and cannot use worktree isolation. A pause or process restart may require a fresh thread session.
23
23
 
@@ -25,6 +25,6 @@ When JavaScript reads fields, pass a small plain JSON Schema. Schema noncomplian
25
25
 
26
26
  ## Routing and support
27
27
 
28
- An explicit per-call `model` wins. A named `agentType` model overrides `tier`; specifying `tier` suppresses the phase/run model and delegates model/thinking resolution to pi-subagents. Without a per-call selector, the phase/run model is used when present, followed by pi-subagents defaults and the parent session. Explicit unavailable models and tiers fail closed. Worktree isolation is also fail-closed and remains owned by pi-subagents. See [registry ownership](registry-ownership.md).
28
+ `strength` is this package's own vocabulary — `low`, `medium`, `high` — not a model ID and not an agent-tier key. A `strengths` table is the only thing that binds a strength to a tier: the user's, or a shipped default (identity, wherever the host defines a tier of the same name) on a host that configured none. A strength no table defines dispatches with no tier and takes the agent's own default, then `agentTiers.defaultTier`; a call that names no strength takes that same untiered path, because a default strength would have outranked the agent type's own tier on every unlabelled call. A word outside the three is rejected before dispatch, and so is any option name `agent()` does not read — `tier`, `model`, and `thinking` answer by naming their replacement, anything else lists the legal keys. `checkpoint()` gates its own options the same way. pi-subagents' `resolveAgentTier()` alone resolves the final model, thinking, clamping, availability, and snapshot. A host whose default has been cleared rejects an untiered call instead of inheriting the parent model. There is no per-call model, thinking, or tier, and workflow meta and phases may not carry them either. Worktree isolation remains owned by pi-subagents. See [registry ownership](registry-ownership.md).
29
29
 
30
30
  Generated entries marked `supported` are authoring API. `console` and whole-script Markdown fences are compatibility-only. VM realm facilities are internal. Active model routes and agent types are dynamic. Use `log()` in new scripts.
@@ -6,7 +6,7 @@ Preserve candidate or work identity outside helper results that may omit failed
6
6
 
7
7
  | Helper | Authoring contract |
8
8
  | --- | --- |
9
- | `completenessCheck(args, results)` | Returns `{ complete, missing? }` or recoverable `null`. The critic sees only the first 4,000 serialized characters, so chunk or summarize larger evidence. Treat the verdict as advisory. |
9
+ | `completenessCheck(args, results, { strength })` | Returns `{ complete, missing? }` or recoverable `null`. Defaults to `strength: "medium"`, not `low` like the other gates: one call, no vote to average over, and an open-ended read of the whole task. The critic sees only the first 4,000 serialized characters, so chunk or summarize larger evidence. Treat the verdict as advisory. |
10
10
  | `loopUntilDry({ round, key, consecutiveEmpty, maxRounds })` | `round(index)` is zero-based. Defaults: `JSON.stringify` key, two dry rounds, 50 rounds. Null, non-array, and duplicate-only rounds are dry. Token-budget or agent-limit exhaustion returns the partial array without a termination reason; keep failed-round identity and stopping state outside the helper. |
11
11
 
12
12
  ## Control
@@ -9,5 +9,5 @@ When copying a workflow between installations:
9
9
  1. Check the destination's generated version and exact capability facts.
10
10
  2. Re-check every supported global, option, and constraint used by the script.
11
11
  3. Treat compatibility entries as preservation aids, not portable recommendations.
12
- 4. Re-resolve dynamic model routes and agent types from destination context; static docs intentionally contain no live entries.
12
+ 4. Re-resolve agent types from destination context; they come from the destination host's configuration, and static docs intentionally contain no live registry entries. Strengths need no re-resolution — the vocabulary is fixed and the mapping belongs to the destination, whether that is the user's table or the shipped default.
13
13
  5. Prefer runtime behavior when prose and execution disagree, and report the documentation mismatch rather than changing behavior during an authoring fix.
@@ -2,7 +2,7 @@
2
2
  name: workflow-patterns
3
3
  description: Choose and run one of Pi's built-in multi-agent workflows for research, adversarial review, code review, multi-perspective analysis, or codebase auditing. Use when the request matches a named pattern; use workflow-authoring instead for a new script or custom topology.
4
4
  metadata:
5
- version: "1.4.0"
5
+ version: "1.6.0"
6
6
  ---
7
7
 
8
8
  # Built-in workflow patterns
@@ -2,7 +2,7 @@
2
2
  name: workflow-review
3
3
  description: Audit an existing Pi JavaScript workflow for topology, prompt/data flow, limits, failure handling, cancellation, resume safety, and publication compatibility. Use when reviewing or debugging a workflow script or saved run; do not use to run a standard named workflow.
4
4
  metadata:
5
- version: "1.4.0"
5
+ version: "1.6.0"
6
6
  ---
7
7
 
8
8
  # Workflow review
package/src/builtins.ts CHANGED
@@ -55,7 +55,7 @@ const plan = await agent(
55
55
  'You are planning web research for this question:\\n' + question +
56
56
  '\\n\\nProduce ' + angles + ' diverse, specific search queries that together cover the question from different angles. ' +
57
57
  'Use your web search tools when helpful to refine them.',
58
- { label: 'plan queries', schema: { type: 'object', properties: { queries: { type: 'array', items: { type: 'string' } } }, required: ['queries'] } }
58
+ { label: 'plan queries', strength: 'medium', schema: { type: 'object', properties: { queries: { type: 'array', items: { type: 'string' } } }, required: ['queries'] } }
59
59
  )
60
60
  const planned = plan && Array.isArray(plan.queries) ? plan.queries.filter((q) => typeof q === 'string' && q.trim().length > 0) : []
61
61
  const queries = (planned.length > 0 ? planned : [question]).slice(0, angles)
@@ -67,7 +67,7 @@ const gathered = await parallel(queries.map((q, i) => () =>
67
67
  '\\n\\nSteps: (1) run a web search for the query; (2) fetch the most relevant result URLs; ' +
68
68
  '(3) extract concrete, verifiable factual claims, each tagged with the exact source URL it came from. ' +
69
69
  'Do NOT invent sources or claims — report only what the fetched pages actually say.',
70
- { label: 'research ' + (i + 1), schema: { type: 'object', properties: { sources: { type: 'array', items: { type: 'object', properties: { url: { type: 'string' }, claims: { type: 'array', items: { type: 'string' } } }, required: ['url', 'claims'] } } }, required: ['sources'] } }
70
+ { label: 'research ' + (i + 1), strength: 'low', schema: { type: 'object', properties: { sources: { type: 'array', items: { type: 'object', properties: { url: { type: 'string' }, claims: { type: 'array', items: { type: 'string' } } }, required: ['url', 'claims'] } } }, required: ['sources'] } }
71
71
  )
72
72
  ))
73
73
  const allSources = gathered.filter(Boolean).flatMap((g) => (g && g.sources) || [])
@@ -77,7 +77,7 @@ const verdict = await agent(
77
77
  'Cross-check these research sources. Group claims that assert the same fact across different source URLs. ' +
78
78
  'Keep a claim only if it is supported by at least ' + minSupport + ' distinct source URLs OR by one clearly authoritative source. ' +
79
79
  'Discard claims found in a single weak source or that conflict with others.\\n\\nSOURCES JSON:\\n' + JSON.stringify(allSources),
80
- { label: 'cross-check', schema: { type: 'object', properties: { supported: { type: 'array', items: { type: 'object', properties: { claim: { type: 'string' }, sources: { type: 'array', items: { type: 'string' } } }, required: ['claim', 'sources'] } }, discarded: { type: 'array', items: { type: 'string' } } }, required: ['supported'] } }
80
+ { label: 'cross-check', strength: 'medium', schema: { type: 'object', properties: { supported: { type: 'array', items: { type: 'object', properties: { claim: { type: 'string' }, sources: { type: 'array', items: { type: 'string' } } }, required: ['claim', 'sources'] } }, discarded: { type: 'array', items: { type: 'string' } } }, required: ['supported'] } }
81
81
  )
82
82
 
83
83
  phase('Report')
@@ -85,7 +85,7 @@ const report = await agent(
85
85
  'Write a concise, well-structured research report that answers the question using ONLY the supported claims below. ' +
86
86
  'Cite source URLs inline next to each claim. If the evidence is thin, say so explicitly.\\n\\n' +
87
87
  'QUESTION: ' + question + '\\n\\nSUPPORTED CLAIMS JSON:\\n' + JSON.stringify((verdict && verdict.supported) || []),
88
- { label: 'write report' }
88
+ { label: 'write report', strength: 'medium' }
89
89
  )
90
90
 
91
91
  return { question, queries, supported: (verdict && verdict.supported) || [], report }`;
@@ -107,7 +107,7 @@ const threshold = (args && args.threshold) || 0.5
107
107
  phase('Investigate')
108
108
  const investigation = await agent(
109
109
  'Investigate the following and list concrete, individually-checkable findings:\\n' + task,
110
- { label: 'investigate', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }
110
+ { label: 'investigate', strength: 'medium', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }
111
111
  )
112
112
  const findings = (investigation && Array.isArray(investigation.findings) ? investigation.findings : [])
113
113
 
@@ -118,7 +118,7 @@ const judged = await parallel(findings.map((f, i) => () =>
118
118
  'You are a skeptical reviewer. Try to REFUTE this finding for the task below. ' +
119
119
  'Default to real=false when uncertain. Investigate with the available tools if needed.\\n\\n' +
120
120
  'TASK: ' + task + '\\nFINDING: ' + f,
121
- { label: 'refute ' + (i + 1) + '.' + (r + 1), schema: { type: 'object', properties: { real: { type: 'boolean' }, reason: { type: 'string' } }, required: ['real'] } }
121
+ { label: 'refute ' + (i + 1) + '.' + (r + 1), strength: 'low', schema: { type: 'object', properties: { real: { type: 'boolean' }, reason: { type: 'string' } }, required: ['real'] } }
122
122
  )
123
123
  )).then((votes) => {
124
124
  const valid = votes.filter(Boolean)
@@ -134,7 +134,7 @@ const report = await agent(
134
134
  'Synthesize the surviving findings into a concise review. For each finding, note the skeptic agreement ' +
135
135
  '(realVotes/totalVotes). Do not include findings that failed the refutation pass.\\n\\n' +
136
136
  'TASK: ' + task + '\\n\\nSURVIVING FINDINGS JSON:\\n' + JSON.stringify(survivors),
137
- { label: 'consensus report' }
137
+ { label: 'consensus report', strength: 'medium' }
138
138
  )
139
139
 
140
140
  return { findings, judged: judged.filter(Boolean), survivors, report }`;
@@ -154,13 +154,13 @@ const diffSource = (args && args.diffSource) || 'provided diff'
154
154
 
155
155
  phase('Scan')
156
156
  const finders = await parallel([
157
- () => agent('You are a correctness reviewer. Find bugs, race conditions, error-handling gaps, and edge-case failures in this diff.\\n\\n' + diff, { label: 'correctness', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
158
- () => agent('You are a reuse reviewer. Find duplicated logic, reinvented wheels, and missed opportunities to reuse existing code or libraries.\\n\\n' + diff, { label: 'reuse', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
159
- () => agent('You are a simplification reviewer. Find over-engineering, unnecessary complexity, and simpler alternatives.\\n\\n' + diff, { label: 'simplification', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
160
- () => agent('You are an efficiency reviewer. Find performance problems, avoidable allocations, and scaling risks.\\n\\n' + diff, { label: 'efficiency', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
161
- () => agent('You are an architecture reviewer. Assess the change at the right altitude: design fit, layering, boundaries, and future maintenance.\\n\\n' + diff, { label: 'altitude', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
162
- () => agent('You are a security reviewer. Find trust-boundary, injection, secret-leak, permission, and unsafe-input risks in this diff.\\n\\n' + diff, { label: 'security', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
163
- () => agent('You are a testability reviewer. Find missing regression tests, observability gaps, and rollout/recovery risks in this diff.\\n\\n' + diff, { label: 'testability', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
157
+ () => agent('You are a correctness reviewer. Find bugs, race conditions, error-handling gaps, and edge-case failures in this diff.\\n\\n' + diff, { label: 'correctness', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
158
+ () => agent('You are a reuse reviewer. Find duplicated logic, reinvented wheels, and missed opportunities to reuse existing code or libraries.\\n\\n' + diff, { label: 'reuse', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
159
+ () => agent('You are a simplification reviewer. Find over-engineering, unnecessary complexity, and simpler alternatives.\\n\\n' + diff, { label: 'simplification', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
160
+ () => agent('You are an efficiency reviewer. Find performance problems, avoidable allocations, and scaling risks.\\n\\n' + diff, { label: 'efficiency', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
161
+ () => agent('You are an architecture reviewer. Assess the change at the right altitude: design fit, layering, boundaries, and future maintenance.\\n\\n' + diff, { label: 'altitude', strength: 'medium', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
162
+ () => agent('You are a security reviewer. Find trust-boundary, injection, secret-leak, permission, and unsafe-input risks in this diff.\\n\\n' + diff, { label: 'security', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
163
+ () => agent('You are a testability reviewer. Find missing regression tests, observability gaps, and rollout/recovery risks in this diff.\\n\\n' + diff, { label: 'testability', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } } }, required: ['findings'] } }),
164
164
  ])
165
165
  const candidates = finders.filter(Boolean).flatMap((f) => (f && f.findings) || [])
166
166
 
@@ -168,7 +168,7 @@ phase('Verify')
168
168
  const verified = await parallel(candidates.map((finding, i) => () =>
169
169
  agent('You are a skeptical verifier. For this candidate finding, check whether it is a REAL issue in the diff. ' +
170
170
  'Default to real=false when uncertain.\\n\\nCANDIDATE: ' + finding + '\\n\\nDIFF:\\n' + diff,
171
- { label: 'verify ' + (i + 1), schema: { type: 'object', properties: { real: { type: 'boolean' }, reason: { type: 'string' } }, required: ['real'] } })
171
+ { label: 'verify ' + (i + 1), strength: 'low', schema: { type: 'object', properties: { real: { type: 'boolean' }, reason: { type: 'string' } }, required: ['real'] } })
172
172
  ))
173
173
 
174
174
  phase('Report')
@@ -179,7 +179,7 @@ const report = await agent(
179
179
  'Write a ranked code review report for this diff (' + diffSource + '). ' +
180
180
  'Include only verified findings, ordered by severity, each with a concrete location and fix suggestion.\\n\\n' +
181
181
  'VERIFIED FINDINGS JSON:\\n' + JSON.stringify(ranked),
182
- { label: 'final report' }
182
+ { label: 'final report', strength: 'medium' }
183
183
  )
184
184
 
185
185
  return { candidates, ranked, report }`;
@@ -199,13 +199,13 @@ const perspectives = (args && Array.isArray(args.perspectives) && args.perspecti
199
199
  phase('Perspectives')
200
200
  const views = await parallel(perspectives.map((p, i) => () =>
201
201
  agent('Evaluate this topic from the perspective of: ' + p + '. Be concrete and specific; note risks, trade-offs, and what matters most from this angle.\\n\\nTOPIC: ' + topic,
202
- { label: 'perspective ' + (i + 1), schema: { type: 'object', properties: { angle: { type: 'string' }, points: { type: 'array', items: { type: 'string' } }, risks: { type: 'array', items: { type: 'string' } } }, required: ['angle', 'points', 'risks'] } })
202
+ { label: 'perspective ' + (i + 1), strength: 'low', schema: { type: 'object', properties: { angle: { type: 'string' }, points: { type: 'array', items: { type: 'string' } }, risks: { type: 'array', items: { type: 'string' } } }, required: ['angle', 'points', 'risks'] } })
203
203
  ))
204
204
 
205
205
  phase('Synthesis')
206
206
  const synthesis = await agent(
207
207
  'Synthesize these perspectives into a balanced assessment. Identify where perspectives agree, where they conflict, and give a bottom-line recommendation with the key trade-offs.\\n\\nTOPIC: ' + topic + '\\n\\nPERSPECTIVES JSON:\\n' + JSON.stringify(views.filter(Boolean)),
208
- { label: 'synthesis' }
208
+ { label: 'synthesis', strength: 'medium' }
209
209
  )
210
210
 
211
211
  return { views: views.filter(Boolean), synthesis }`;
@@ -229,21 +229,21 @@ const map = await agent(
229
229
  'Explore the codebase at ' + root + ' and produce a structural map: top-level modules, entry points, ' +
230
230
  'data flow, and where complexity concentrates. Use the available file tools.\\n' +
231
231
  (focus ? 'Focus/checks requested: ' + focus + '\\n' : ''),
232
- { label: 'map', schema: { type: 'object', properties: { modules: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, purpose: { type: 'string' }, risk: { type: 'string' } }, required: ['name', 'purpose'] } }, entryPoints: { type: 'array', items: { type: 'string' } }, complexityHotspots: { type: 'array', items: { type: 'string' } } }, required: ['modules'] } }
232
+ { label: 'map', strength: 'medium', schema: { type: 'object', properties: { modules: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, purpose: { type: 'string' }, risk: { type: 'string' } }, required: ['name', 'purpose'] } }, entryPoints: { type: 'array', items: { type: 'string' } }, complexityHotspots: { type: 'array', items: { type: 'string' } } }, required: ['modules'] } }
233
233
  )
234
234
 
235
235
  phase('Audit')
236
236
  const audits = await parallel([
237
- () => agent('Audit this codebase for correctness risks: error handling, boundary conditions, concurrency, security. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'correctness', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
238
- () => agent('Audit this codebase for maintainability: coupling, duplication, naming, test coverage, documentation. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'maintainability', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
239
- () => agent('Audit this codebase for operational health: dependencies, build, deployment, observability, secrets handling. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'operations', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
237
+ () => agent('Audit this codebase for correctness risks: error handling, boundary conditions, concurrency, security. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'correctness', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
238
+ () => agent('Audit this codebase for maintainability: coupling, duplication, naming, test coverage, documentation. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'maintainability', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
239
+ () => agent('Audit this codebase for operational health: dependencies, build, deployment, observability, secrets handling. Use file tools.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map), { label: 'operations', strength: 'low', schema: { type: 'object', properties: { findings: { type: 'array', items: { type: 'string' } }, severity: { type: 'string' } }, required: ['findings'] } }),
240
240
  ])
241
241
 
242
242
  phase('Report')
243
243
  const report = await agent(
244
244
  'Write a codebase health audit report: overall health score, ranked findings across dimensions with concrete locations, ' +
245
245
  'and a prioritized remediation roadmap.\\n\\nSTRUCTURE:\\n' + JSON.stringify(map) + '\\n\\nAUDITS JSON:\\n' + JSON.stringify(audits.filter(Boolean)),
246
- { label: 'audit report' }
246
+ { label: 'audit report', strength: 'medium' }
247
247
  )
248
248
 
249
249
  return { map, audits: audits.filter(Boolean), report }`;
@@ -29,11 +29,19 @@ export interface CapabilityEntry {
29
29
  }
30
30
 
31
31
  /** The contract format version. Bump on any breaking surface change. */
32
- export const WORKFLOW_CAPABILITY_CONTRACT_VERSION = "1.0.0";
32
+ export const WORKFLOW_CAPABILITY_CONTRACT_VERSION = "2.0.0";
33
33
 
34
34
  /**
35
35
  * The runtime globals a script can rely on. `options` documents each helper's
36
36
  * accepted inputs with defaults; `constraints` states the behavioral contract.
37
+ *
38
+ * The strength option's type is spelled out on each of the four helpers that
39
+ * take it, rather than derived from `WORKFLOW_STRENGTHS`, because this array
40
+ * must stay literal-only: `check:capabilities` evaluates it in an empty VM
41
+ * realm so the published contract can be read without executing this package.
42
+ * `strengths.test.ts` pins the four copies against the vocabulary the runtime
43
+ * enforces, which is the drift protection a shared constant would otherwise
44
+ * have provided.
37
45
  */
38
46
  export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
39
47
  {
@@ -44,8 +52,12 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
44
52
  { name: "label", kind: "string", optional: true, default: "derived from phase and call count" },
45
53
  { name: "phase", kind: "string", optional: true, default: "current phase" },
46
54
  { name: "schema", kind: "plain JSON Schema", optional: true, default: "none" },
47
- { name: "model", kind: "string", optional: true, default: "pi-subagents model resolver" },
48
- { name: "tier", kind: "small|medium|large", optional: true, default: "pi-subagents workflow tier" },
55
+ {
56
+ name: "strength",
57
+ kind: '"low" | "medium" | "high"',
58
+ optional: true,
59
+ default: "no tier is sent; the agent's own tier, else agentTiers.defaultTier",
60
+ },
49
61
  { name: "isolation", kind: '"worktree"', optional: true, default: "pi-subagents worktree policy" },
50
62
  { name: "thread", kind: "string", optional: true, default: "fresh session per call" },
51
63
  { name: "toolset", kind: "string", optional: true, default: "configured host/agent toolset hint" },
@@ -60,9 +72,15 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
60
72
  "resume replays only the longest unchanged prefix; the first miss and every later call execute live",
61
73
  "replayed calls do not consume the real-dispatch maxAgents or token/phase budgets",
62
74
  "spawnKeys rotate by generation on resume so pi-subagents never raises a fingerprint conflict",
63
- "explicit model is resolved and scope-checked by pi-subagents; unavailable selectors fail closed",
75
+ "strength is this package's own vocabulary, not an agentTiers key; a word outside low/medium/high is rejected before dispatch",
76
+ "a strengths table alone binds a strength to an agent tier; an unmapped strength dispatches with no tier and takes the agent's own default",
77
+ "a call that names no strength also dispatches with no tier; there is no default strength, so an unlabelled call never outranks the agent type's own tier",
78
+ "an unconfigured host uses a shipped default table: each strength on the catalogue tier of the same name, where the host defines one",
79
+ "resolveAgentTier in pi-subagents owns model, thinking, clamping, availability, and the resolution snapshot",
80
+ "there is no per-call model, thinking, or tier: a strength is the only model policy a workflow can express",
64
81
  "same-thread calls must be sequential and preserve a stable workflow thread name",
65
82
  "threads cannot be combined with worktree isolation",
83
+ "an option name outside this list is rejected before dispatch, not ignored; tier, model, and thinking name their replacement",
66
84
  ],
67
85
  },
68
86
  {
@@ -130,6 +148,7 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
130
148
  { name: "reviewers", kind: "number", optional: true, default: "2" },
131
149
  { name: "threshold", kind: "number", optional: true, default: "0.5" },
132
150
  { name: "lens", kind: "string | string[]", optional: true, default: "none" },
151
+ { name: "strength", kind: '"low" | "medium" | "high"', optional: true, default: '"low"' },
133
152
  ],
134
153
  constraints: ["threshold comparison is inclusive; real is false when no reviewer succeeds"],
135
154
  },
@@ -140,6 +159,7 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
140
159
  options: [
141
160
  { name: "judges", kind: "number", optional: true, default: "3" },
142
161
  { name: "rubric", kind: "string", optional: true, default: "overall quality and correctness" },
162
+ { name: "strength", kind: '"low" | "medium" | "high"', optional: true, default: '"low"' },
143
163
  ],
144
164
  constraints: ["highest mean score wins with stable input index as the tie-break; empty input returns undefined"],
145
165
  },
@@ -158,8 +178,8 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
158
178
  {
159
179
  name: "completenessCheck",
160
180
  classification: "runtime-global",
161
- signature: "completenessCheck(taskArgs, results) => Promise<{ complete, missing? } | null>",
162
- options: [],
181
+ signature: "completenessCheck(taskArgs, results, options?) => Promise<{ complete, missing? } | null>",
182
+ options: [{ name: "strength", kind: '"low" | "medium" | "high"', optional: true, default: '"medium"' }],
163
183
  constraints: ["only the first 4,000 characters of serialized result evidence are sent to the critic"],
164
184
  },
165
185
  {
@@ -193,6 +213,7 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
193
213
  constraints: [
194
214
  "consumes one agent slot and no tokens",
195
215
  "journaled answers replay only within an unchanged resume prefix",
216
+ "an option name outside this list is rejected rather than ignored, since a dropped headless silently auto-approves",
196
217
  ],
197
218
  },
198
219
  { name: "log", classification: "runtime-global", signature: "log(message) => void", options: [], constraints: [] },
@@ -308,6 +329,7 @@ export const WORKFLOW_CAPABILITIES: readonly CapabilityEntry[] = [
308
329
  constraints: [
309
330
  "must be the first statement",
310
331
  "name and description must be nonblank literals",
332
+ "workflow meta and phase metadata cannot contain model or thinking fields",
311
333
  "spread, computed keys, methods, template interpolation, and __proto__/constructor/prototype are rejected",
312
334
  ],
313
335
  },