@juicesharp/rpiv-workflow 1.14.0 → 1.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/handle.ts +70 -0
  2. package/package.json +85 -81
  3. package/predicates.ts +42 -0
package/handle.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Artifact handle — the storage-agnostic reference a collector emits and
3
+ * a parser consumes. Tagged union so collectors / parsers narrow
4
+ * structurally (`if (h.kind === "fs") fs.readFile(h.path)`); plain
5
+ * `string` would force a parse on every consumer.
6
+ *
7
+ * Four built-in kinds cover the practical universe:
8
+ * - `fs` — cwd-relative or absolute filesystem path.
9
+ * - `url` — RFC-3986 reference (https, file://, custom scheme).
10
+ * - `opaque` — external system id (Linear ticket, S3 key, commit SHA).
11
+ * - `inline` — bytes the collector gathered directly (rare; useful for
12
+ * a binary the consumer wants without an fs round-trip).
13
+ *
14
+ * Authors who need a kind not in this list write a custom collector that
15
+ * emits `opaque` and a custom parser that knows how to dereference it.
16
+ */
17
+ export type ArtifactHandle =
18
+ | { kind: "fs"; path: string }
19
+ | { kind: "url"; href: string }
20
+ | { kind: "opaque"; id: string }
21
+ | { kind: "inline"; bytes: Uint8Array; mime?: string };
22
+
23
+ /**
24
+ * One artifact a stage produced. The handle is the storage reference;
25
+ * `role` is an optional user-facing label (`"primary"`, `"patch"`,
26
+ * `"log"`) downstream stages can route on; `meta` carries any
27
+ * collector-attached hints the matching parser needs.
28
+ *
29
+ * The framework reads `artifacts[0]` as the "primary" artifact for chain
30
+ * inheritance (side-effect stages without their own artifacts inherit the
31
+ * upstream list forward). `role` is metadata only — the framework does
32
+ * not gate on it.
33
+ */
34
+ export interface Artifact {
35
+ handle: ArtifactHandle;
36
+ role?: string;
37
+ meta?: Record<string, unknown>;
38
+ }
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Handle constructors — eliminate kind-literal boilerplate at collector
42
+ // call sites. `fs(path)` reads cleaner than `{ kind: "fs", path }` and
43
+ // keeps the discriminator value in one place.
44
+ // ---------------------------------------------------------------------------
45
+
46
+ export const fs = (path: string): ArtifactHandle => ({ kind: "fs", path });
47
+ export const url = (href: string): ArtifactHandle => ({ kind: "url", href });
48
+ export const opaque = (id: string): ArtifactHandle => ({ kind: "opaque", id });
49
+ export const inline = (bytes: Uint8Array, mime?: string): ArtifactHandle =>
50
+ mime !== undefined ? { kind: "inline", bytes, mime } : { kind: "inline", bytes };
51
+
52
+ /**
53
+ * Serialise a handle to a human-readable string — used by the runner
54
+ * when threading the primary artifact into a downstream stage's prompt
55
+ * input (the prompt is plain text; URLs / paths / opaque ids all have a
56
+ * natural one-line form). Inline handles serialise to their byte length
57
+ * since their content isn't meaningfully promptable.
58
+ */
59
+ export function handleToString(h: ArtifactHandle): string {
60
+ switch (h.kind) {
61
+ case "fs":
62
+ return h.path;
63
+ case "url":
64
+ return h.href;
65
+ case "opaque":
66
+ return h.id;
67
+ case "inline":
68
+ return `inline:${h.bytes.byteLength}b${h.mime ? `;${h.mime}` : ""}`;
69
+ }
70
+ }
package/package.json CHANGED
@@ -1,83 +1,87 @@
1
1
  {
2
- "name": "@juicesharp/rpiv-workflow",
3
- "version": "1.14.0",
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
- "keywords": [
6
- "pi-package",
7
- "pi-extension",
8
- "rpiv",
9
- "workflow",
10
- "skills",
11
- "orchestration",
12
- "dag",
13
- "pipeline"
14
- ],
15
- "type": "module",
16
- "license": "MIT",
17
- "author": "juicesharp",
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/juicesharp/rpiv-mono.git",
21
- "directory": "packages/rpiv-workflow"
22
- },
23
- "homepage": "https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-workflow#readme",
24
- "bugs": {
25
- "url": "https://github.com/juicesharp/rpiv-mono/issues"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "scripts": {
31
- "test": "vitest run"
32
- },
33
- "files": [
34
- "index.ts",
35
- "internal.ts",
36
- "api.ts",
37
- "artifacts-layout.ts",
38
- "audit.ts",
39
- "built-ins.ts",
40
- "command.ts",
41
- "fanout.ts",
42
- "host.ts",
43
- "internal-utils.ts",
44
- "layers.ts",
45
- "lifecycle.ts",
46
- "load",
47
- "output.ts",
48
- "messages.ts",
49
- "output-spec.ts",
50
- "outcomes",
51
- "preview.ts",
52
- "routing.ts",
53
- "runner",
54
- "sessions",
55
- "state",
56
- "transcript.ts",
57
- "triggers.ts",
58
- "typebox-adapter.ts",
59
- "types.ts",
60
- "validate-output.ts",
61
- "validate-workflow.ts",
62
- "docs-protocol.ts",
63
- "docs",
64
- "README.md",
65
- "LICENSE"
66
- ],
67
- "exports": {
68
- ".": "./index.ts",
69
- "./internal": "./internal.ts"
70
- },
71
- "pi": {
72
- "extensions": [
73
- "./index.ts"
74
- ]
75
- },
76
- "peerDependencies": {
77
- "@earendil-works/pi-coding-agent": "*",
78
- "@juicesharp/rpiv-config": "*",
79
- "@standard-schema/spec": "*",
80
- "jiti": "*",
81
- "typebox": "*"
82
- }
2
+ "name": "@juicesharp/rpiv-workflow",
3
+ "version": "1.14.2",
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
+ "keywords": [
6
+ "pi-package",
7
+ "pi-extension",
8
+ "rpiv",
9
+ "workflow",
10
+ "skills",
11
+ "orchestration",
12
+ "dag",
13
+ "pipeline"
14
+ ],
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "author": "juicesharp",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/juicesharp/rpiv-mono.git",
21
+ "directory": "packages/rpiv-workflow"
22
+ },
23
+ "homepage": "https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-workflow#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/juicesharp/rpiv-mono/issues"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "test": "vitest run"
32
+ },
33
+ "files": [
34
+ "index.ts",
35
+ "internal.ts",
36
+ "api.ts",
37
+ "artifacts-layout.ts",
38
+ "audit.ts",
39
+ "built-ins.ts",
40
+ "command.ts",
41
+ "fanout.ts",
42
+ "handle.ts",
43
+ "host.ts",
44
+ "internal-utils.ts",
45
+ "layers.ts",
46
+ "lifecycle.ts",
47
+ "load",
48
+ "output.ts",
49
+ "messages.ts",
50
+ "output-spec.ts",
51
+ "outcomes",
52
+ "predicates.ts",
53
+ "preview.ts",
54
+ "routing.ts",
55
+ "runner",
56
+ "sessions",
57
+ "state",
58
+ "transcript.ts",
59
+ "triggers.ts",
60
+ "typebox-adapter.ts",
61
+ "types.ts",
62
+ "validate-output.ts",
63
+ "validate-workflow.ts",
64
+ "docs-protocol.ts",
65
+ "docs",
66
+ "README.md",
67
+ "LICENSE"
68
+ ],
69
+ "exports": {
70
+ ".": "./index.ts",
71
+ "./internal": "./internal.ts"
72
+ },
73
+ "pi": {
74
+ "extensions": [
75
+ "./index.ts"
76
+ ]
77
+ },
78
+ "dependencies": {
79
+ "@juicesharp/rpiv-config": "^1.14.2",
80
+ "jiti": "^2.7.0"
81
+ },
82
+ "peerDependencies": {
83
+ "@earendil-works/pi-coding-agent": "*",
84
+ "@standard-schema/spec": "*",
85
+ "typebox": "*"
86
+ }
83
87
  }
package/predicates.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Predicate helpers for `gate(...)` — small, side-effect-free combinators
3
+ * over a single field value. Each helper returns a `Predicate` that the
4
+ * runtime evaluates against `Number(output.data[field])`.
5
+ *
6
+ * Numeric coercion via `Number(...)` matches the prior `threshold` semantics:
7
+ * missing or non-numeric fields coerce to `NaN`, and `NaN` compares false
8
+ * against any threshold. Callers wanting a non-default fall-through let
9
+ * `gate`'s last-branch fallback handle the unmatched case.
10
+ */
11
+
12
+ export type Predicate = (value: number) => boolean;
13
+
14
+ /** Strictly greater than. */
15
+ export const gt =
16
+ (n: number): Predicate =>
17
+ (v) =>
18
+ v > n;
19
+
20
+ /** Greater than or equal. */
21
+ export const gte =
22
+ (n: number): Predicate =>
23
+ (v) =>
24
+ v >= n;
25
+
26
+ /** Strictly less than. */
27
+ export const lt =
28
+ (n: number): Predicate =>
29
+ (v) =>
30
+ v < n;
31
+
32
+ /** Less than or equal. */
33
+ export const lte =
34
+ (n: number): Predicate =>
35
+ (v) =>
36
+ v <= n;
37
+
38
+ /** Numeric equality (after `Number(...)` coercion of `output.data[field]`). */
39
+ export const eq =
40
+ (n: number): Predicate =>
41
+ (v) =>
42
+ v === n;