@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/command.ts
CHANGED
|
@@ -1,37 +1,126 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* /wf slash command registration — kept light. The heavy run-path (runner +
|
|
3
|
-
* loader, ~
|
|
4
|
-
*
|
|
3
|
+
* loader, ~0.9s of module evaluation) lives in `./command-run.js`, dynamically
|
|
4
|
+
* imported only when needed, so registering the command costs nothing at
|
|
5
|
+
* startup. The import promise is memoized in the handler closure: Pi's
|
|
6
|
+
* extension loader runs jiti with `moduleCache: false`, so a bare `import()`
|
|
7
|
+
* here would re-evaluate the entire graph on EVERY `/wf` — a recurring ~0.9s
|
|
8
|
+
* stall. The closure is held by Pi's command registry and survives across
|
|
9
|
+
* invocations; `/reload` re-registers and resets the memo, so edit pickup is
|
|
10
|
+
* preserved. A post-registration pre-warm kicks the same memoized import
|
|
11
|
+
* shortly after startup: jiti evaluation yields between modules (measured
|
|
12
|
+
* max event-loop stall ~0ms at 5ms sampling), so the warm-up causes no
|
|
13
|
+
* perceptible jank and the first real `/wf` finds the graph ready.
|
|
5
14
|
* `parseArgs` stays here (pure, exported for tests).
|
|
6
15
|
*/
|
|
7
16
|
|
|
8
|
-
import type { WorkflowHost, WorkflowHostContext } from "./host.js";
|
|
9
|
-
|
|
17
|
+
import type { WorkflowHost, WorkflowHostContext, WorkflowLauncherContext } from "./host.js";
|
|
18
|
+
|
|
19
|
+
/** Pi command registry — displayed by Pi's `/?` / command list. */
|
|
20
|
+
export const CMD_DESCRIPTION = "Run a skill workflow: /wf [workflow] [description]";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Cold-path toast — shown only when the user invokes `/wf` before the
|
|
24
|
+
* command-run graph has finished evaluating (i.e. they beat the pre-warm);
|
|
25
|
+
* this line is the only feedback in that ~1s window.
|
|
26
|
+
*/
|
|
27
|
+
export const MSG_RUNTIME_LOADING = "rpiv: loading workflow runtime (first /wf after load)…";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pre-warm delay — long enough to stay clear of Pi's own startup work,
|
|
31
|
+
* short enough to beat a human typing their first `/wf`.
|
|
32
|
+
*/
|
|
33
|
+
export const PREWARM_DELAY_MS = 2000;
|
|
10
34
|
|
|
11
35
|
// ---------------------------------------------------------------------------
|
|
12
36
|
// Public entry
|
|
13
37
|
// ---------------------------------------------------------------------------
|
|
14
38
|
|
|
39
|
+
type CommandRunModule = typeof import("./command-run.js");
|
|
40
|
+
|
|
41
|
+
export interface WfCommandHandler {
|
|
42
|
+
(args: string, ctx: WorkflowLauncherContext): Promise<void>;
|
|
43
|
+
/** Kick (or join) the memoized command-run import — the pre-warm entry. */
|
|
44
|
+
prewarm(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Build the `/wf` handler with a per-closure memo of the command-run import,
|
|
49
|
+
* shared between the handler and `prewarm()`. A rejected import is NOT
|
|
50
|
+
* memoized — the memo clears so the next call retries instead of replaying
|
|
51
|
+
* the cached rejection forever (a failed pre-warm therefore degrades to
|
|
52
|
+
* exactly the pre-warm-less behavior). Exported for tests (the importer is
|
|
53
|
+
* injectable); production callers go through `registerWorkflowCommand`.
|
|
54
|
+
*/
|
|
55
|
+
export function makeWfHandler(
|
|
56
|
+
host: WorkflowHost,
|
|
57
|
+
importRun: () => Promise<CommandRunModule> = () => import("./command-run.js"),
|
|
58
|
+
): WfCommandHandler {
|
|
59
|
+
let memo: Promise<CommandRunModule> | undefined;
|
|
60
|
+
let ready = false;
|
|
61
|
+
|
|
62
|
+
const load = async (): Promise<CommandRunModule> => {
|
|
63
|
+
memo ??= importRun();
|
|
64
|
+
try {
|
|
65
|
+
const mod = await memo;
|
|
66
|
+
ready = true;
|
|
67
|
+
return mod;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
memo = undefined;
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handler = async (args: string, ctx: WorkflowLauncherContext): Promise<void> => {
|
|
75
|
+
// `ready`, not `memo`: an in-flight pre-warm still leaves the user
|
|
76
|
+
// waiting, so the toast covers that window too.
|
|
77
|
+
if (!ready && ctx.hasUI) ctx.ui.notify(MSG_RUNTIME_LOADING, "info");
|
|
78
|
+
const mod = await load();
|
|
79
|
+
// The launcher hands us an OBSERVER ctx (Pi's command ctx has no
|
|
80
|
+
// spawnChild/maxConcurrency). The run-path is typed against the executor
|
|
81
|
+
// ctx, but it never executes a stage on this ctx directly: with a provider
|
|
82
|
+
// registered, runWorkflow builds the detached executor; with
|
|
83
|
+
// none, the test/embedder contract guarantees an executor-capable ctx. So
|
|
84
|
+
// narrow here at the single Pi→runtime boundary.
|
|
85
|
+
return mod.handleWorkflowCommand(host, args, ctx as WorkflowHostContext);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return Object.assign(handler, {
|
|
89
|
+
prewarm: async (): Promise<void> => {
|
|
90
|
+
const mod = await load();
|
|
91
|
+
// Also flush the lazy provider registries (built-ins DSL + skill
|
|
92
|
+
// contracts) — the other ~550ms of first-/wf work. Both are memoized
|
|
93
|
+
// latches; loadWorkflows joins the same promises later.
|
|
94
|
+
await mod.prewarmWorkflowRuntime();
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
15
99
|
export function registerWorkflowCommand(host: WorkflowHost): void {
|
|
100
|
+
const handler = makeWfHandler(host);
|
|
16
101
|
host.registerCommand("wf", {
|
|
17
102
|
description: CMD_DESCRIPTION,
|
|
18
|
-
handler
|
|
19
|
-
// Lazy — runner/loader graph evaluates on first `/wf`, not at startup.
|
|
20
|
-
const { handleWorkflowCommand } = await import("./command-run.js");
|
|
21
|
-
return handleWorkflowCommand(host, args, ctx);
|
|
22
|
-
},
|
|
103
|
+
handler,
|
|
23
104
|
});
|
|
105
|
+
// Swallowed rejection is safe: load() already cleared the memo, so the
|
|
106
|
+
// first real /wf retries and surfaces the error through its own path.
|
|
107
|
+
// unref keeps the timer from holding a non-TUI embedder's process open.
|
|
108
|
+
const timer = setTimeout(() => void handler.prewarm().catch(() => undefined), PREWARM_DELAY_MS);
|
|
109
|
+
timer.unref?.();
|
|
24
110
|
}
|
|
25
111
|
|
|
26
112
|
// ---------------------------------------------------------------------------
|
|
27
113
|
// Arg parsing (pure; exported for tests + consumed by ./command-run.js)
|
|
28
114
|
// ---------------------------------------------------------------------------
|
|
29
115
|
|
|
30
|
-
const
|
|
116
|
+
const LEADING_NAME_FLAG = /^--name\s+(\S+)\s*/;
|
|
117
|
+
const TRAILING_NAME_FLAG = /\s+--name\s+(\S+)$/;
|
|
118
|
+
/** Any surviving `--name` token after the leading/trailing extraction — input text, flagged. */
|
|
119
|
+
const MID_NAME_FLAG = /(?:^|\s)--name(?:\s|$)/;
|
|
31
120
|
|
|
32
121
|
export type ParsedCommand =
|
|
33
|
-
| { kind: "run"; workflow: string; input: string; name?: string }
|
|
34
|
-
| { kind: "resume"; ref: string; droppedName?: string };
|
|
122
|
+
| { kind: "run"; workflow: string; input: string; name?: string; nameFlagIgnored?: boolean }
|
|
123
|
+
| { kind: "resume"; ref: string; droppedName?: string; nameFlagIgnored?: boolean };
|
|
35
124
|
|
|
36
125
|
/**
|
|
37
126
|
* First token is a workflow name iff recognised; otherwise the whole arg is
|
|
@@ -39,6 +128,11 @@ export type ParsedCommand =
|
|
|
39
128
|
* empty-registry case), the returned `workflow` is `""` and the orchestrator
|
|
40
129
|
* surfaces `MSG_NO_WORKFLOWS_REGISTERED`.
|
|
41
130
|
*
|
|
131
|
+
* `--name <slug>` is honored ONLY in leading or trailing position (leading
|
|
132
|
+
* wins when both are present). A `--name` anywhere else is the user's own
|
|
133
|
+
* prompt text (`/wf fix the --name handling bug`) — it stays in the input
|
|
134
|
+
* untouched and `nameFlagIgnored` is set so the command layer can warn.
|
|
135
|
+
*
|
|
42
136
|
* `@<ref>` on the first token is the resume sigil — the first whitespace-
|
|
43
137
|
* delimited token after `@` is the run reference. Leading space after the
|
|
44
138
|
* sigil is tolerated (`@ ref` === `@ref`); trailing tokens are ignored.
|
|
@@ -50,21 +144,29 @@ export function parseArgs(
|
|
|
50
144
|
let trimmed = args.trim();
|
|
51
145
|
let name: string | undefined;
|
|
52
146
|
|
|
53
|
-
// Extract --name <slug>
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
name =
|
|
57
|
-
trimmed = trimmed.
|
|
147
|
+
// Extract --name <slug> from the leading or trailing token position only.
|
|
148
|
+
const leading = LEADING_NAME_FLAG.exec(trimmed);
|
|
149
|
+
if (leading) {
|
|
150
|
+
name = leading[1];
|
|
151
|
+
trimmed = trimmed.slice(leading[0].length);
|
|
152
|
+
} else {
|
|
153
|
+
const trailing = TRAILING_NAME_FLAG.exec(trimmed);
|
|
154
|
+
if (trailing) {
|
|
155
|
+
name = trailing[1];
|
|
156
|
+
trimmed = trimmed.slice(0, trailing.index);
|
|
157
|
+
}
|
|
58
158
|
}
|
|
159
|
+
const nameFlagIgnored = MID_NAME_FLAG.test(trimmed);
|
|
160
|
+
const ignored = nameFlagIgnored ? { nameFlagIgnored: true as const } : {};
|
|
59
161
|
|
|
60
162
|
if (trimmed.startsWith("@")) {
|
|
61
163
|
// @resume — name has no meaning here; carry it as `droppedName` so the
|
|
62
164
|
// command layer can warn instead of silently dropping it.
|
|
63
|
-
return { kind: "resume", ref: trimmed.slice(1).trim().split(/\s+/)[0] ?? "", droppedName: name };
|
|
165
|
+
return { kind: "resume", ref: trimmed.slice(1).trim().split(/\s+/)[0] ?? "", droppedName: name, ...ignored };
|
|
64
166
|
}
|
|
65
167
|
|
|
66
168
|
if (!trimmed) {
|
|
67
|
-
return { kind: "run", workflow: loaded.default ?? "", input: "", name };
|
|
169
|
+
return { kind: "run", workflow: loaded.default ?? "", input: "", name, ...ignored };
|
|
68
170
|
}
|
|
69
171
|
|
|
70
172
|
const firstSpace = trimmed.indexOf(" ");
|
|
@@ -72,8 +174,8 @@ export function parseArgs(
|
|
|
72
174
|
|
|
73
175
|
if (loaded.workflowNames.has(firstToken)) {
|
|
74
176
|
const remaining = firstSpace === -1 ? "" : trimmed.slice(firstSpace + 1).trim();
|
|
75
|
-
return { kind: "run", workflow: firstToken, input: remaining, name };
|
|
177
|
+
return { kind: "run", workflow: firstToken, input: remaining, name, ...ignored };
|
|
76
178
|
}
|
|
77
179
|
|
|
78
|
-
return { kind: "run", workflow: loaded.default ?? "", input: trimmed, name };
|
|
180
|
+
return { kind: "run", workflow: loaded.default ?? "", input: trimmed, name, ...ignored };
|
|
79
181
|
}
|