@juicesharp/rpiv-workflow 2.13.4 → 2.13.6

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.
@@ -86,6 +86,15 @@ Every workflow file is TypeScript, loaded via `jiti` (no build step required). I
86
86
  import { defineWorkflow, produces, acts, gate, gt, eq } from "@juicesharp/rpiv-workflow";
87
87
  ```
88
88
 
89
+ These imports work wherever the file lives, without a `node_modules` folder next to it. The loader maps them to the running copy of rpiv-workflow and to the `typebox` Pi provides:
90
+
91
+ | Import | Resolves to |
92
+ | --- | --- |
93
+ | `@juicesharp/rpiv-workflow`, `/registration`, `/startup`, `/runner` | the rpiv-workflow already loaded in Pi |
94
+ | `typebox`, `typebox/value`, `typebox/compile` | the `typebox` Pi supplies to extensions |
95
+
96
+ Any other package an overlay imports resolves normally from the overlay's own folder, so it must be installed where Node can find it.
97
+
89
98
  ## Where files resolve
90
99
 
91
100
  | Layer | Path |
package/load/cache.ts CHANGED
@@ -8,7 +8,8 @@
8
8
  *
9
9
  * The `jiti` instance lives here so the cache and the underlying importer
10
10
  * co-locate. Other loader modules import `cachedImport` — none touches
11
- * `jiti` directly.
11
+ * `jiti` directly. It is created on first use with the overlay module map
12
+ * (`overlayVirtualModules`).
12
13
  *
13
14
  * The cache does not invalidate on file deletion — a stale entry for a
14
15
  * deleted overlay sits dormant (the enumerator never passes it back to
@@ -19,12 +20,66 @@
19
20
  import { statSync } from "node:fs";
20
21
  import { createJiti } from "jiti";
21
22
 
22
- const jiti = createJiti(import.meta.url, {
23
- // Module cache OFF so /reload picks up edits without restart. The fs
24
- // transform cache (default ON) is deliberately kept: it is content-hash
25
- // validated (edit-safe) and saves ~70ms/file of Babel work per session.
26
- moduleCache: false,
27
- });
23
+ type Jiti = ReturnType<typeof createJiti>;
24
+
25
+ /**
26
+ * Bare specifiers an overlay may import, mapped to modules this package already
27
+ * holds — the same `virtualModules` mechanism Pi's extension loader uses for
28
+ * extensions. Overlays live outside any `node_modules` tree (`~/.config/…`,
29
+ * `<cwd>/.rpiv/workflows/`), so plain Node resolution finds neither this package
30
+ * nor `typebox`, which Pi supplies to extensions (a `"*"` peer, often not on disk
31
+ * at all in a compiled Pi) (#298).
32
+ *
33
+ * - `@juicesharp/rpiv-workflow` and its public subpaths → the running package's
34
+ * own entries: the documented authoring import resolves, and nothing is
35
+ * re-evaluated (state lives on `globalThis` slots regardless).
36
+ * - `typebox` (+ `/value`, `/compile`) → the copy THIS package received from its
37
+ * host. Fail-soft per entry: a host that does not provide a subpath simply
38
+ * leaves it unmapped instead of breaking every overlay.
39
+ *
40
+ * Imported lazily on the first overlay load (during `/wf`), so the thin
41
+ * startup/registration entries never pull the runner graph.
42
+ */
43
+ async function overlayVirtualModules(): Promise<Record<string, unknown>> {
44
+ const [root, registration, startup, runner] = await Promise.all([
45
+ import("../index.js"),
46
+ import("../registration.js"),
47
+ import("../startup.js"),
48
+ import("../runner/index.js"),
49
+ ]);
50
+ const modules: Record<string, unknown> = {
51
+ "@juicesharp/rpiv-workflow": root,
52
+ "@juicesharp/rpiv-workflow/registration": registration,
53
+ "@juicesharp/rpiv-workflow/startup": startup,
54
+ "@juicesharp/rpiv-workflow/runner": runner,
55
+ };
56
+ const typebox = await Promise.allSettled([import("typebox"), import("typebox/value"), import("typebox/compile")]);
57
+ (["typebox", "typebox/value", "typebox/compile"] as const).forEach((specifier, i) => {
58
+ const result = typebox[i];
59
+ if (result.status === "fulfilled") modules[specifier] = result.value;
60
+ });
61
+ return modules;
62
+ }
63
+
64
+ let jitiPromise: Promise<Jiti> | undefined;
65
+
66
+ function getJiti(): Promise<Jiti> {
67
+ jitiPromise ??= overlayVirtualModules().then(
68
+ (virtualModules) =>
69
+ createJiti(import.meta.url, {
70
+ // Module cache OFF so /reload picks up edits without restart. The fs
71
+ // transform cache (default ON) is deliberately kept: it is content-hash
72
+ // validated (edit-safe) and saves ~70ms/file of Babel work per session.
73
+ moduleCache: false,
74
+ virtualModules,
75
+ }),
76
+ (err: unknown) => {
77
+ jitiPromise = undefined; // a failed setup must not poison every later /wf
78
+ throw err;
79
+ },
80
+ );
81
+ return jitiPromise;
82
+ }
28
83
 
29
84
  const overlayCache = new Map<string, { mtimeMs: number; parsed: unknown }>();
30
85
 
@@ -32,6 +87,7 @@ export async function cachedImport(path: string): Promise<unknown> {
32
87
  const stat = statSync(path);
33
88
  const cached = overlayCache.get(path);
34
89
  if (cached && cached.mtimeMs === stat.mtimeMs) return cached.parsed;
90
+ const jiti = await getJiti();
35
91
  const value = await jiti.import(path, { default: true });
36
92
  overlayCache.set(path, { mtimeMs: stat.mtimeMs, parsed: value });
37
93
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-workflow",
3
- "version": "2.13.4",
3
+ "version": "2.13.6",
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",
@@ -112,7 +112,7 @@
112
112
  ]
113
113
  },
114
114
  "dependencies": {
115
- "@juicesharp/rpiv-config": "^2.13.4",
115
+ "@juicesharp/rpiv-config": "^2.13.6",
116
116
  "jiti": "^2.7.0"
117
117
  },
118
118
  "peerDependencies": {