@juicesharp/rpiv-workflow 1.19.1 → 2.0.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.
- package/README.md +81 -8
- package/api.ts +18 -703
- package/audit-ctx.ts +103 -0
- package/audit-rows.ts +154 -0
- package/audit.ts +158 -190
- package/built-ins.ts +40 -45
- package/chain-state.ts +220 -0
- package/command-run.ts +64 -31
- package/command.ts +123 -21
- package/docs/workflow-authoring.md +356 -63
- package/{lifecycle.ts → events.ts} +161 -37
- package/execution-host.ts +75 -0
- package/host.ts +149 -64
- package/index.ts +25 -81
- package/internal-utils.ts +171 -71
- package/internal.ts +22 -1
- package/judge.ts +241 -0
- package/layers.ts +10 -15
- package/load/alias.ts +6 -12
- package/load/cache.ts +9 -6
- package/load/index.ts +27 -106
- package/load/issues.ts +31 -0
- package/load/legacy.ts +102 -0
- package/load/merge.ts +2 -2
- package/load/resolve-default.ts +3 -4
- package/load/shape-guards.ts +3 -6
- package/load/skill-contract-phase.ts +94 -0
- package/loop-constructors.ts +24 -0
- package/loop-def.ts +285 -0
- package/loop-kinds.ts +750 -0
- package/loop-parallel.ts +250 -0
- package/loop-waves.ts +99 -0
- package/loop.ts +330 -0
- package/loops/constructors.ts +334 -0
- package/loops/derivations.ts +65 -0
- package/loops/introspection.ts +184 -0
- package/loops/panel.ts +196 -0
- package/loops/verify.ts +99 -0
- package/messages.ts +249 -156
- package/outcomes/collectors/directory-path.ts +7 -3
- package/outcomes/collectors/index.ts +1 -0
- package/outcomes/collectors/require-opt.ts +11 -0
- package/outcomes/collectors/text-scan.ts +47 -0
- package/outcomes/collectors/tool-call.ts +8 -3
- package/outcomes/collectors/transcript-path.ts +4 -18
- package/outcomes/collectors/union.ts +30 -10
- package/outcomes/collectors/url.ts +9 -14
- package/outcomes/collectors/workspace-diff.ts +21 -14
- package/outcomes/exec.ts +17 -0
- package/outcomes/git-commit.ts +190 -100
- package/outcomes/index.ts +1 -0
- package/outcomes/parsers/json-body.ts +2 -2
- package/outcomes/side-effect.ts +3 -3
- package/output-spec.ts +36 -10
- package/output.ts +98 -20
- package/package.json +27 -11
- package/predicates.ts +11 -8
- package/preview.ts +81 -21
- package/registration.ts +117 -36
- package/routing-dsl.ts +322 -0
- package/routing.ts +48 -2
- package/runner/by-name.ts +2 -1
- package/runner/by-run-id.ts +2 -1
- package/runner/chain-advance.ts +84 -56
- package/runner/errors.ts +10 -0
- package/runner/failure.ts +163 -0
- package/runner/index.ts +7 -13
- package/runner/input-validation.ts +16 -23
- package/runner/preflight.ts +169 -0
- package/runner/resolve-stage.ts +68 -0
- package/runner/resume-entry.ts +121 -0
- package/runner/resume-loop.ts +131 -0
- package/runner/resume.ts +368 -262
- package/runner/run-context.ts +165 -0
- package/runner/run-stage.ts +490 -0
- package/runner/runner.ts +202 -449
- package/runner/script-stage.ts +104 -112
- package/schema-compat.ts +12 -1
- package/semaphore.ts +55 -0
- package/sessions/extraction.ts +146 -81
- package/sessions/halt-routing.ts +195 -0
- package/sessions/index.ts +3 -1
- package/sessions/locate.ts +141 -0
- package/sessions/reattach.ts +71 -0
- package/sessions/sessions.ts +114 -199
- package/sessions/spawn.ts +132 -119
- package/sessions/success-persist.ts +89 -0
- package/skill-contract.ts +22 -25
- package/skill-contracts/composition.ts +86 -37
- package/skill-contracts/{registries.ts → extension-points.ts} +45 -12
- package/skill-contracts/harvest.ts +4 -4
- package/skill-contracts/index.ts +15 -8
- package/skill-contracts/registry.ts +33 -50
- package/stage-def.ts +595 -0
- package/stage-errors.ts +84 -0
- package/stage-identity.ts +56 -0
- package/startup.ts +4 -1
- package/state/index.ts +8 -1
- package/state/names.ts +91 -65
- package/state/paths.ts +20 -0
- package/state/raw.ts +77 -0
- package/state/reads.ts +103 -85
- package/state/resolve.ts +73 -0
- package/state/state.ts +135 -15
- package/state/writes.ts +29 -12
- package/transcript.ts +24 -0
- package/triggers.ts +11 -3
- package/types.ts +290 -78
- package/validate/contract-compat.ts +198 -0
- package/validate/graph.ts +134 -0
- package/validate/issue.ts +328 -0
- package/validate/stage-rules.ts +499 -0
- package/validate-output.ts +82 -7
- package/validate-workflow.ts +57 -759
- package/validation-bounds.ts +35 -0
- package/control-flow.ts +0 -135
- package/fanout.ts +0 -102
- package/iterate.ts +0 -155
- package/load/cache.test.ts +0 -82
- package/load/shape-guards.test.ts +0 -74
- package/outcomes/collectors/directory-path.test.ts +0 -64
- package/outcomes/collectors/tool-call.test.ts +0 -110
- package/outcomes/collectors/transcript-path.test.ts +0 -70
- package/outcomes/collectors/union.test.ts +0 -59
- package/outcomes/collectors/url.test.ts +0 -67
- package/outcomes/collectors/workspace-diff.test.ts +0 -107
- package/outcomes/git-commit.test.ts +0 -194
- package/outcomes/parsers/json-body.test.ts +0 -80
- package/runner/by-name.test.ts +0 -95
- package/runner/by-run-id.test.ts +0 -115
- package/runner/resume-fanout.test.ts +0 -331
- package/runner/resume-fanout.ts +0 -136
- package/runner/resume-iterate.test.ts +0 -444
- package/runner/resume-iterate.ts +0 -111
- package/runner/resume.test.ts +0 -1130
- package/runner/stage-lifecycle.ts +0 -500
package/output-spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Outcome authoring surface — the contract a stage's data-channel
|
|
3
3
|
* implementation satisfies. Decomposed into two orthogonal halves so
|
|
4
4
|
* authors can mix-and-match:
|
|
5
5
|
*
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - `ArtifactParser<B, K, D>` — INTERPRET: given the artifacts, what
|
|
10
10
|
* typed data does downstream see?
|
|
11
11
|
*
|
|
12
|
-
* `
|
|
12
|
+
* `Outcome` is the wired-up pair — `{ collector, parser? }` — that
|
|
13
13
|
* stages declare via `StageDef.outcome`. When `parser` is omitted the
|
|
14
14
|
* output data IS the artifact list (kind = `"artifacts"`).
|
|
15
15
|
*
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { Artifact } from "./handle.js";
|
|
23
|
+
import type { RunView } from "./output.js";
|
|
23
24
|
import type { BranchEntry } from "./transcript.js";
|
|
24
|
-
import type { RunState } from "./types.js";
|
|
25
25
|
|
|
26
26
|
// ---------------------------------------------------------------------------
|
|
27
27
|
// Snapshot — pre-stage reference capture (shared by collector + parser)
|
|
@@ -31,12 +31,9 @@ export interface SnapshotCtx {
|
|
|
31
31
|
cwd: string;
|
|
32
32
|
runId: string;
|
|
33
33
|
stageIndex: number;
|
|
34
|
-
state:
|
|
34
|
+
state: RunView;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/** Fail-soft: implementations catch and return undefined rather than throwing. */
|
|
38
|
-
export type SnapshotFn<Snapshot = unknown> = (ctx: SnapshotCtx) => Promise<Snapshot> | Snapshot;
|
|
39
|
-
|
|
40
37
|
// ---------------------------------------------------------------------------
|
|
41
38
|
// Collector — discover what the stage produced
|
|
42
39
|
// ---------------------------------------------------------------------------
|
|
@@ -66,6 +63,24 @@ export interface CollectCtx<Snapshot = unknown> extends SnapshotCtx {
|
|
|
66
63
|
* `kind: "ok"` + `artifacts: [...]` — N>=1 artifacts; parser (or default) shapes the data.
|
|
67
64
|
* `kind: "fatal"` — collector cannot satisfy its contract;
|
|
68
65
|
* runner halts with the carried message.
|
|
66
|
+
*
|
|
67
|
+
* THE "NOTHING FOUND" CONVENTION — what a collector returns when it
|
|
68
|
+
* comes up empty depends on WHY it's empty, and the two must never be
|
|
69
|
+
* conflated:
|
|
70
|
+
*
|
|
71
|
+
* - Genuinely empty (the stage really produced nothing the collector
|
|
72
|
+
* watches): `{ kind: "ok", artifacts: [] }` — honest empty; the runner's
|
|
73
|
+
* completion contract decides whether that halts.
|
|
74
|
+
* - Environment broke MID-STAGE (the channel worked at snapshot time and
|
|
75
|
+
* fails after — git gone, fs unreadable): `{ kind: "fatal" }` with the
|
|
76
|
+
* real cause. Returning `ok []` here would let routing/judges act on
|
|
77
|
+
* fabricated "nothing happened" data.
|
|
78
|
+
* - Environment absent from the START (snapshot already found no channel —
|
|
79
|
+
* e.g. not a git repo): degrade to the collector's documented no-signal
|
|
80
|
+
* shape (`ok []` for diff collectors; `gitCommitOutcome` instead emits
|
|
81
|
+
* its one sentinel no-op artifact so its parser stays total — the
|
|
82
|
+
* documented exception). The stage ran outside the watched environment
|
|
83
|
+
* on purpose; halting would punish a legitimate setup.
|
|
69
84
|
*/
|
|
70
85
|
export type CollectResult = { kind: "ok"; artifacts: readonly Artifact[] } | { kind: "fatal"; message: string };
|
|
71
86
|
|
|
@@ -122,7 +137,7 @@ export interface ArtifactParser<Snapshot = unknown, Kind extends string = string
|
|
|
122
137
|
}
|
|
123
138
|
|
|
124
139
|
// ---------------------------------------------------------------------------
|
|
125
|
-
//
|
|
140
|
+
// Outcome — wired-up pair on `StageDef.outcome`
|
|
126
141
|
// ---------------------------------------------------------------------------
|
|
127
142
|
|
|
128
143
|
/**
|
|
@@ -130,11 +145,11 @@ export interface ArtifactParser<Snapshot = unknown, Kind extends string = string
|
|
|
130
145
|
* the output emits `kind: "artifacts"` with `data = artifacts`.
|
|
131
146
|
*
|
|
132
147
|
* Generic over `<Snapshot, Kind, Data>` so specialised output specs
|
|
133
|
-
* (`
|
|
148
|
+
* (`Outcome<GitHeadSnapshot, "git-commit", GitCommitData>`) flow types
|
|
134
149
|
* end-to-end from snapshot through collect into the downstream
|
|
135
150
|
* `output.data`.
|
|
136
151
|
*/
|
|
137
|
-
export interface
|
|
152
|
+
export interface Outcome<Snapshot = unknown, Kind extends string = string, Data = unknown> {
|
|
138
153
|
/**
|
|
139
154
|
* Categorical name this outcome publishes under in `state.named`. When set,
|
|
140
155
|
* the runner uses it as the default publish name for any stage wired with
|
|
@@ -151,6 +166,17 @@ export interface OutputSpec<Snapshot = unknown, Kind extends string = string, Da
|
|
|
151
166
|
parser?: ArtifactParser<Snapshot, Kind, Data>;
|
|
152
167
|
}
|
|
153
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @deprecated Renamed to `Outcome` (matching the `StageDef.outcome` field,
|
|
171
|
+
* the `outcomes/` directory, and the `*Outcome` instances). This alias ships
|
|
172
|
+
* for one release and will be removed.
|
|
173
|
+
*/
|
|
174
|
+
export type OutputSpec<Snapshot = unknown, Kind extends string = string, Data = unknown> = Outcome<
|
|
175
|
+
Snapshot,
|
|
176
|
+
Kind,
|
|
177
|
+
Data
|
|
178
|
+
>;
|
|
179
|
+
|
|
154
180
|
// ---------------------------------------------------------------------------
|
|
155
181
|
// Author helpers — `define*` shorthands match `defineWorkflow` /
|
|
156
182
|
// `defineRoute` in api.ts. Pure passthroughs: they exist for type
|
package/output.ts
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
* Audience: predicate authors and downstream-stage authors reading
|
|
7
7
|
* `output.artifacts` (the storage references) and `output.data`
|
|
8
8
|
* (the typed channel a parser shaped). The producer-side surface
|
|
9
|
-
* (`ArtifactCollector` / `ArtifactParser` / `
|
|
9
|
+
* (`ArtifactCollector` / `ArtifactParser` / `Outcome`) lives in
|
|
10
10
|
* `output-spec.ts`.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { Artifact } from "./handle.js";
|
|
14
|
-
import type { GitCommitData } from "./outcomes/git-commit.js";
|
|
15
14
|
|
|
16
15
|
// ---------------------------------------------------------------------------
|
|
17
16
|
// Output envelope
|
|
@@ -49,32 +48,53 @@ export interface Output<K extends string = string, D = unknown> {
|
|
|
49
48
|
// ---------------------------------------------------------------------------
|
|
50
49
|
// Built-in output kind aliases
|
|
51
50
|
//
|
|
52
|
-
// Tagged-union narrowing convenience for consumers.
|
|
53
|
-
//
|
|
54
|
-
//
|
|
51
|
+
// Tagged-union narrowing convenience for consumers. Only the two
|
|
52
|
+
// framework-native kinds live here; outcome-specific aliases live with
|
|
53
|
+
// their producing outcome (`GitCommitOutput` → outcomes/git-commit.ts) so
|
|
54
|
+
// the core envelope module never enumerates concrete plugins.
|
|
55
55
|
// ---------------------------------------------------------------------------
|
|
56
56
|
|
|
57
57
|
export type ArtifactsOutput = Output<"artifacts", readonly Artifact[]>;
|
|
58
58
|
export type SideEffectOutput = Output<"side-effect", Record<string, never>>;
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A judge's graded output — structurally just an `Output` (the verdict is a
|
|
62
|
+
* normal envelope published to the judge's named channel), named so judged
|
|
63
|
+
* signatures (`done(verdict)`, `FeedForwardContext.verdict`) can say what
|
|
64
|
+
* they mean.
|
|
65
|
+
*/
|
|
66
|
+
export type Verdict = Output;
|
|
60
67
|
|
|
61
68
|
// ---------------------------------------------------------------------------
|
|
62
|
-
//
|
|
63
|
-
// CollectCtx, ... } from "../output.js"` without rewriting every
|
|
64
|
-
// site. Canonical definitions live in `output-spec.ts`.
|
|
69
|
+
// RunView — the user-facing read surface over a live run
|
|
65
70
|
// ---------------------------------------------------------------------------
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Deep-readonly view of a run's data channels — what user-authored functions
|
|
74
|
+
* (edge predicates, script stages, loop unit sources, judges, collectors)
|
|
75
|
+
* receive as `ctx.state`. The runner threads its live mutable `RunState`
|
|
76
|
+
* here (it satisfies this shape structurally); the narrowed type is what
|
|
77
|
+
* keeps a user fn from corrupting an audited run — `Readonly<RunState>` was
|
|
78
|
+
* shallow, so `ctx.state.named["plans"].push(...)` compiled.
|
|
79
|
+
*
|
|
80
|
+
* Deliberately omits runner bookkeeping (`stagesCompleted`,
|
|
81
|
+
* `lastAllocatedStageNumber`, `telemetry`, `termination`, the
|
|
82
|
+
* accessor-guarded `primaryArtifact`) — those are runtime internals, not
|
|
83
|
+
* authoring inputs. Adding a field later is non-breaking; removing one is
|
|
84
|
+
* not, hence the minimal start.
|
|
85
|
+
*/
|
|
86
|
+
export interface RunView {
|
|
87
|
+
/** The user's original `/wf` argument — frozen for the whole run. */
|
|
88
|
+
readonly originalInput: string;
|
|
89
|
+
/** The most recent completed stage's full `Output` envelope. */
|
|
90
|
+
readonly output: Output | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Named publish registry — each `produces` success APPENDS its envelope
|
|
93
|
+
* onto the slot named by `stage.outcome?.name ?? stage.<record-key>`.
|
|
94
|
+
* Slots are histories; read the latest via `named[name]?.at(-1)`.
|
|
95
|
+
*/
|
|
96
|
+
readonly named: { readonly [name: string]: readonly Output[] };
|
|
97
|
+
}
|
|
78
98
|
|
|
79
99
|
// ---------------------------------------------------------------------------
|
|
80
100
|
// Output construction
|
|
@@ -96,3 +116,61 @@ export function finalizeOutput<K extends string, D>(
|
|
|
96
116
|
meta,
|
|
97
117
|
};
|
|
98
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The single construction home for an `OutputMeta` literal. The five former
|
|
122
|
+
* assembly sites (`sessions/extraction.ts:wrapOutput`, `sessions/sessions.ts:
|
|
123
|
+
* outputMetaFor`, `loop-parallel.ts:unitOutputMeta`, the `runner/script-stage.ts`
|
|
124
|
+
* produce hook, and the `runner/resume.ts` soft-halt sentinel) all route through
|
|
125
|
+
* this — so a structural divergence between the live path's minted meta and the
|
|
126
|
+
* resume fold's rebuilt sentinel is unrepresentable (modeled on the `audit.ts`
|
|
127
|
+
* `terminalArgsOf` flat-pairing authority).
|
|
128
|
+
*
|
|
129
|
+
* `ts` is a PARAMETER, not an injected `nowIso()`: live call sites pass
|
|
130
|
+
* `nowIso()`; the resume fold replays the persisted `row.ts`. That is what lets
|
|
131
|
+
* the two paths share one constructor — resume stays byte-identical to the row
|
|
132
|
+
* the live path wrote.
|
|
133
|
+
*
|
|
134
|
+
* `skill` is conditionally spread (not defaulted) so a call site that omits it
|
|
135
|
+
* (script-stage rows, and any resume row whose `skill` is absent) produces an
|
|
136
|
+
* object with NO `skill` key — preserving the script-row "no skill field"
|
|
137
|
+
* contract (`JSON.stringify` drops `undefined`, so this must stay a key
|
|
138
|
+
* omission, not `{ skill: undefined }`).
|
|
139
|
+
*/
|
|
140
|
+
export function outputMeta(args: {
|
|
141
|
+
stage: string;
|
|
142
|
+
skill?: string;
|
|
143
|
+
stageNumber: number;
|
|
144
|
+
ts: string;
|
|
145
|
+
runId: string;
|
|
146
|
+
}): OutputMeta {
|
|
147
|
+
return {
|
|
148
|
+
stage: args.stage,
|
|
149
|
+
...(args.skill !== undefined ? { skill: args.skill } : {}),
|
|
150
|
+
stageNumber: args.stageNumber,
|
|
151
|
+
ts: args.ts,
|
|
152
|
+
runId: args.runId,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// Failed-unit sentinel (collect-all fanout)
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
/** The data shape of a failed-unit sentinel — collect-all fanout places one of
|
|
161
|
+
* these in a unit's declared slot when the unit halts (the run survives). */
|
|
162
|
+
export const FAILED_OUTPUT_KIND = "failed";
|
|
163
|
+
export type FailedOutput = Output<"failed", { reason: string }>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A failed unit's contribution to a collect-all fanout. A real `Output` with NO
|
|
167
|
+
* artifacts, so: `applyCompletedStage` leaves the rolling primary alone; the
|
|
168
|
+
* `fanin` reader contributes no args for it (the `.filter(Boolean)` convention
|
|
169
|
+
* needs no widening); `advanceCursor` advances the index without making it the
|
|
170
|
+
* "last" produce; and the resume fold replays it like any produce row.
|
|
171
|
+
*/
|
|
172
|
+
export function failedOutput(meta: OutputMeta, reason: string): FailedOutput {
|
|
173
|
+
return finalizeOutput({ kind: FAILED_OUTPUT_KIND, artifacts: [], data: { reason } }, meta);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const isFailedOutput = (o: Output): o is FailedOutput => o.kind === FAILED_OUTPUT_KIND;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-workflow",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Pi extension. Chain skills into typed multi-stage workflows with audited JSONL state, predicate routing, and per-stage output validation. Skill-agnostic — bring your own skills.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -34,23 +34,35 @@
|
|
|
34
34
|
"index.ts",
|
|
35
35
|
"internal.ts",
|
|
36
36
|
"api.ts",
|
|
37
|
-
"
|
|
37
|
+
"stage-def.ts",
|
|
38
|
+
"stage-identity.ts",
|
|
39
|
+
"stage-errors.ts",
|
|
40
|
+
"loop-def.ts",
|
|
41
|
+
"routing-dsl.ts",
|
|
38
42
|
"audit.ts",
|
|
43
|
+
"audit-ctx.ts",
|
|
44
|
+
"audit-rows.ts",
|
|
39
45
|
"built-ins.ts",
|
|
46
|
+
"chain-state.ts",
|
|
40
47
|
"command.ts",
|
|
41
48
|
"command-run.ts",
|
|
42
|
-
"
|
|
49
|
+
"execution-host.ts",
|
|
50
|
+
"loop-constructors.ts",
|
|
51
|
+
"loops/",
|
|
43
52
|
"extension.ts",
|
|
44
53
|
"registration.ts",
|
|
45
|
-
"fanout.ts",
|
|
46
54
|
"handle.ts",
|
|
47
55
|
"host.ts",
|
|
56
|
+
"judge.ts",
|
|
48
57
|
"json-schema.ts",
|
|
49
58
|
"schema-compat.ts",
|
|
50
59
|
"internal-utils.ts",
|
|
51
|
-
"iterate.ts",
|
|
52
60
|
"layers.ts",
|
|
53
|
-
"
|
|
61
|
+
"events.ts",
|
|
62
|
+
"loop.ts",
|
|
63
|
+
"loop-kinds.ts",
|
|
64
|
+
"loop-parallel.ts",
|
|
65
|
+
"loop-waves.ts",
|
|
54
66
|
"load/",
|
|
55
67
|
"output.ts",
|
|
56
68
|
"messages.ts",
|
|
@@ -62,6 +74,7 @@
|
|
|
62
74
|
"skill-contracts/",
|
|
63
75
|
"routing.ts",
|
|
64
76
|
"runner/",
|
|
77
|
+
"semaphore.ts",
|
|
65
78
|
"startup.ts",
|
|
66
79
|
"sessions/",
|
|
67
80
|
"state/",
|
|
@@ -70,11 +83,14 @@
|
|
|
70
83
|
"typebox-adapter.ts",
|
|
71
84
|
"types.ts",
|
|
72
85
|
"validate-output.ts",
|
|
86
|
+
"validation-bounds.ts",
|
|
73
87
|
"validate-workflow.ts",
|
|
88
|
+
"validate/",
|
|
74
89
|
"docs-protocol.ts",
|
|
75
90
|
"docs/",
|
|
76
91
|
"README.md",
|
|
77
|
-
"LICENSE"
|
|
92
|
+
"LICENSE",
|
|
93
|
+
"!**/*.test.ts"
|
|
78
94
|
],
|
|
79
95
|
"exports": {
|
|
80
96
|
".": "./index.ts",
|
|
@@ -89,12 +105,12 @@
|
|
|
89
105
|
]
|
|
90
106
|
},
|
|
91
107
|
"dependencies": {
|
|
92
|
-
"@juicesharp/rpiv-config": "^
|
|
93
|
-
"jiti": "^2.7.0"
|
|
108
|
+
"@juicesharp/rpiv-config": "^2.0.0",
|
|
109
|
+
"jiti": "^2.7.0",
|
|
110
|
+
"typebox": "^1.1.24"
|
|
94
111
|
},
|
|
95
112
|
"peerDependencies": {
|
|
96
113
|
"@earendil-works/pi-coding-agent": "*",
|
|
97
|
-
"@standard-schema/spec": "*"
|
|
98
|
-
"typebox": "*"
|
|
114
|
+
"@standard-schema/spec": "*"
|
|
99
115
|
}
|
|
100
116
|
}
|
package/predicates.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Predicate helpers for `gate(...)` — small, side-effect-free combinators
|
|
3
|
-
* over a single field value. Each helper returns a `
|
|
4
|
-
* runtime evaluates against `Number(output.data[field])`.
|
|
3
|
+
* over a single field value. Each helper returns a `NumericPredicate` that
|
|
4
|
+
* the runtime evaluates against `Number(output.data[field])`.
|
|
5
5
|
*
|
|
6
6
|
* Numeric coercion via `Number(...)` matches the prior `threshold` semantics:
|
|
7
7
|
* missing or non-numeric fields coerce to `NaN`, and `NaN` compares false
|
|
@@ -9,34 +9,37 @@
|
|
|
9
9
|
* `gate`'s last-branch fallback handle the unmatched case.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export type
|
|
12
|
+
export type NumericPredicate = (value: number) => boolean;
|
|
13
|
+
|
|
14
|
+
/** @deprecated Renamed to `NumericPredicate` (the bare name collided with `EdgePredicate`-style route predicates). Ships for one release. */
|
|
15
|
+
export type Predicate = NumericPredicate;
|
|
13
16
|
|
|
14
17
|
/** Strictly greater than. */
|
|
15
18
|
export const gt =
|
|
16
|
-
(n: number):
|
|
19
|
+
(n: number): NumericPredicate =>
|
|
17
20
|
(v) =>
|
|
18
21
|
v > n;
|
|
19
22
|
|
|
20
23
|
/** Greater than or equal. */
|
|
21
24
|
export const gte =
|
|
22
|
-
(n: number):
|
|
25
|
+
(n: number): NumericPredicate =>
|
|
23
26
|
(v) =>
|
|
24
27
|
v >= n;
|
|
25
28
|
|
|
26
29
|
/** Strictly less than. */
|
|
27
30
|
export const lt =
|
|
28
|
-
(n: number):
|
|
31
|
+
(n: number): NumericPredicate =>
|
|
29
32
|
(v) =>
|
|
30
33
|
v < n;
|
|
31
34
|
|
|
32
35
|
/** Less than or equal. */
|
|
33
36
|
export const lte =
|
|
34
|
-
(n: number):
|
|
37
|
+
(n: number): NumericPredicate =>
|
|
35
38
|
(v) =>
|
|
36
39
|
v <= n;
|
|
37
40
|
|
|
38
41
|
/** Numeric equality (after `Number(...)` coercion of `output.data[field]`). */
|
|
39
42
|
export const eq =
|
|
40
|
-
(n: number):
|
|
43
|
+
(n: number): NumericPredicate =>
|
|
41
44
|
(v) =>
|
|
42
45
|
v === n;
|
package/preview.ts
CHANGED
|
@@ -5,12 +5,21 @@
|
|
|
5
5
|
* string that `command.ts` hands straight to `ctx.ui.notify(..., "info")`.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { STOP, type StageDef } from "./api.js";
|
|
9
9
|
import { type ConfigLayer, renderConfigLayer } from "./layers.js";
|
|
10
10
|
import type { LoadedWorkflows } from "./load/index.js";
|
|
11
|
-
import {
|
|
11
|
+
import { type AnyJudgeSpec, describeFlow, type StageShape } from "./loop-constructors.js";
|
|
12
12
|
import type { SkillContractMap } from "./skill-contract.js";
|
|
13
13
|
|
|
14
|
+
/** No-args listing footer — generic usage hint. */
|
|
15
|
+
export const CMD_USAGE_LIST = "Usage: /wf [workflow] <description>";
|
|
16
|
+
|
|
17
|
+
/** No-args listing footer — preview-mode hint paired with CMD_USAGE_LIST. */
|
|
18
|
+
export const CMD_USAGE_PREVIEW = "/wf <workflow> — preview stages";
|
|
19
|
+
|
|
20
|
+
/** Per-workflow details footer — narrowed to the workflow the user previewed. */
|
|
21
|
+
export const CMD_USAGE_RUN = (name: string) => `Usage: /wf ${name} <description>`;
|
|
22
|
+
|
|
14
23
|
// ===========================================================================
|
|
15
24
|
// Public formatters
|
|
16
25
|
// ===========================================================================
|
|
@@ -78,8 +87,12 @@ export function formatWorkflowDetails(loaded: LoadedWorkflows, name: string): st
|
|
|
78
87
|
const layer = loaded.workflowSources.get(name) ?? "built-in";
|
|
79
88
|
const heading = formatWorkflowHeading(name, layer, name === loaded.default);
|
|
80
89
|
const descriptionLine = workflow.description ? [workflow.description] : [];
|
|
90
|
+
// Flow facets (loop / verify / edge) come from `describeFlow` — the ONE
|
|
91
|
+
// introspector, so preview never lags a new loop kind. Per-stage knobs
|
|
92
|
+
// (kind, policy, outcome, schemas) are plain field reads off the def.
|
|
93
|
+
const shapeByStage = new Map(describeFlow(workflow).map((shape) => [shape.stage, shape]));
|
|
81
94
|
const stageRows = Object.entries(workflow.stages).map(([stageName, stage], i) =>
|
|
82
|
-
formatStageRow(i + 1, stageName, stage, workflow),
|
|
95
|
+
formatStageRow(i + 1, stageName, stage, shapeByStage.get(stageName)!, stageName in workflow.edges),
|
|
83
96
|
);
|
|
84
97
|
const aliasBanner = formatAliasBanner(loaded.skillAliases);
|
|
85
98
|
|
|
@@ -106,25 +119,32 @@ function formatWorkflowHeading(name: string, layer: ConfigLayer, isDefault: bool
|
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
/** Numbered row showing the stage + its outgoing edge target(s). */
|
|
109
|
-
function formatStageRow(
|
|
122
|
+
function formatStageRow(
|
|
123
|
+
idx: number,
|
|
124
|
+
stageName: string,
|
|
125
|
+
stage: StageDef,
|
|
126
|
+
shape: StageShape,
|
|
127
|
+
edgeDeclared: boolean,
|
|
128
|
+
): string {
|
|
110
129
|
const num = `${idx}.`.padEnd(3);
|
|
111
130
|
const decorations = [stage.kind.padEnd(13), stage.sessionPolicy, outcomeTag(stage)];
|
|
112
131
|
if (stage.inputSchema) decorations.push("in-schema");
|
|
113
132
|
if (stage.outputSchema) decorations.push("out-schema");
|
|
133
|
+
if (shape.control.mode !== "single") decorations.push(loopTag(shape.control));
|
|
134
|
+
if (shape.verify) decorations.push(verifyTag(shape.verify));
|
|
135
|
+
const fanin = faninTag(shape);
|
|
136
|
+
if (fanin) decorations.push(fanin);
|
|
114
137
|
|
|
115
|
-
const displayName =
|
|
116
|
-
const arrow = formatEdge(
|
|
138
|
+
const displayName = shape.skill && shape.skill !== stageName ? `${stageName} (skill: ${shape.skill})` : stageName;
|
|
139
|
+
const arrow = formatEdge(shape.edge, edgeDeclared);
|
|
117
140
|
const trailer = arrow ? ` → ${arrow}` : "";
|
|
118
141
|
|
|
119
142
|
return ` ${num} ${displayName.padEnd(36)} ${decorations.join(" · ")}${trailer}`;
|
|
120
143
|
}
|
|
121
144
|
|
|
122
145
|
/**
|
|
123
|
-
|
|
124
|
-
*
|
|
125
|
-
* report `custom` (+`snapshot` when the collector declares a snapshot
|
|
126
|
-
* hook, +`parser` when a parser is wired). Stages without an outcome
|
|
127
|
-
* fall through to the framework default: `side-effect` for
|
|
146
|
+
* Single tag per stage encoding the outcome shape. Stages without an
|
|
147
|
+
* outcome fall through to the framework default: `side-effect` for
|
|
128
148
|
* side-effect stages (the only kind that has a default); `???` for
|
|
129
149
|
* `produces` (load-time validation rejects this — the tag is for
|
|
130
150
|
* defensive rendering only).
|
|
@@ -139,15 +159,55 @@ function outcomeTag(stage: StageDef): string {
|
|
|
139
159
|
return stage.kind === "produces" ? "???" : "side-effect";
|
|
140
160
|
}
|
|
141
161
|
|
|
142
|
-
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Decoration for a loop stage. Assess keeps its exact pre-redesign strings
|
|
164
|
+
* (`assess(judge: skill:<name>)·max=N`, `assess(judge: prompt)·max=N` — the
|
|
165
|
+
* constructor always sets `max`, defaulting to 8).
|
|
166
|
+
*/
|
|
167
|
+
function loopTag(control: StageShape["control"]): string {
|
|
168
|
+
const spec = control.spec;
|
|
169
|
+
if (!spec) return control.mode;
|
|
170
|
+
if (spec.kind === "assess") {
|
|
171
|
+
const judge = spec.judge ? judgeSlotTag(spec.judge) : "prompt";
|
|
172
|
+
return `assess(judge: ${judge})·max=${spec.max}`;
|
|
173
|
+
}
|
|
174
|
+
return spec.max !== undefined ? `${spec.kind}·max=${spec.max}` : spec.kind;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Judge-slot label: skill/prompt/panel. */
|
|
178
|
+
function judgeSlotTag(spec: AnyJudgeSpec): string {
|
|
179
|
+
if ("panel" in spec) return `panel(${spec.panel.length}, ${spec.fold})`;
|
|
180
|
+
return spec.skill ? `skill:${spec.skill}` : "prompt";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Fan-in decoration for `fanin()` all-reads: `⇉ <names>`. */
|
|
184
|
+
function faninTag(shape: StageShape): string | undefined {
|
|
185
|
+
const allReads = shape.reads?.filter((r) => r.all).map((r) => r.name);
|
|
186
|
+
return allReads?.length ? `⇉ ${allReads.join(",")}` : undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Verify decoration: `verify(<judge>)` + `·attempts=N` when retrying. */
|
|
190
|
+
function verifyTag(v: NonNullable<StageShape["verify"]>): string {
|
|
191
|
+
const attempts = v.max > 1 ? `·attempts=${v.max}` : "";
|
|
192
|
+
return `verify(${judgeSlotTag(v)})${attempts}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Render the outgoing edge as a human-readable trailer from the introspected
|
|
197
|
+
* `StageShape.edge`. `describeFlow` collapses "no edge declared" and an
|
|
198
|
+
* explicit `STOP` into one `terminal` mode; the declared-or-not distinction
|
|
199
|
+
* is a one-key lookup the caller supplies (it matters to authors — the
|
|
200
|
+
* validator warns on the undeclared form).
|
|
201
|
+
*
|
|
202
|
+
* The "terminal" rendered below is the GRAPH-SINK sense (a stage with no
|
|
203
|
+
* outgoing edge OR an explicit `STOP`) — NOT the `terminal()` stage factory
|
|
204
|
+
* (stage-def.ts) and NOT a "terminal failure" run outcome (audit.ts). See the
|
|
205
|
+
* glossary on `stage-def.ts`'s `terminal` export.
|
|
206
|
+
*/
|
|
207
|
+
function formatEdge(edge: StageShape["edge"], declared: boolean): string | undefined {
|
|
208
|
+
if (edge.mode === "terminal") return declared ? STOP : "(terminal — no edge declared)";
|
|
209
|
+
if (edge.mode === "linear") return edge.targets?.[0];
|
|
210
|
+
return edge.targets?.length ? `predicate(${edge.targets.join(" | ")})` : "predicate";
|
|
151
211
|
}
|
|
152
212
|
|
|
153
213
|
/** "Sources: built-in + user + project" — single-line layer banner. */
|
|
@@ -178,7 +238,7 @@ function formatContractsBanner(contracts: SkillContractMap): string | undefined
|
|
|
178
238
|
let harvested = 0;
|
|
179
239
|
for (const c of contracts.values()) {
|
|
180
240
|
if (c.source === "declared") declared++;
|
|
181
|
-
else
|
|
241
|
+
else harvested++;
|
|
182
242
|
}
|
|
183
243
|
return `Skill contracts: ${declared} declared, ${harvested} harvested`;
|
|
184
244
|
}
|