@llblab/pi-actors 0.41.1 → 0.42.1

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 (157) hide show
  1. package/AGENTS.md +11 -6
  2. package/BACKLOG.md +1 -65
  3. package/CHANGELOG.md +25 -0
  4. package/README.md +24 -4
  5. package/dist/index.js +25 -121
  6. package/dist/lib/async-runs.d.ts +37 -5
  7. package/dist/lib/async-runs.js +181 -51
  8. package/dist/lib/automatic-review-runtime.d.ts +18 -0
  9. package/dist/lib/automatic-review-runtime.js +96 -0
  10. package/dist/lib/command-templates.js +1 -1
  11. package/dist/lib/draft-consolidation-transaction.d.ts +65 -0
  12. package/dist/lib/draft-consolidation-transaction.js +610 -0
  13. package/dist/lib/draft-consolidation.d.ts +35 -0
  14. package/dist/lib/draft-consolidation.js +126 -0
  15. package/dist/lib/draft-review.d.ts +56 -0
  16. package/dist/lib/draft-review.js +254 -0
  17. package/dist/lib/draft-sleep.d.ts +65 -0
  18. package/dist/lib/draft-sleep.js +468 -0
  19. package/dist/lib/file-state.d.ts +8 -1
  20. package/dist/lib/file-state.js +115 -18
  21. package/dist/lib/inspector-actions.d.ts +16 -0
  22. package/dist/lib/inspector-actions.js +57 -0
  23. package/dist/lib/inspector-command.d.ts +7 -0
  24. package/dist/lib/inspector-command.js +37 -0
  25. package/dist/lib/inspector-overlay.d.ts +23 -3
  26. package/dist/lib/inspector-overlay.js +327 -70
  27. package/dist/lib/inspector.d.ts +9 -0
  28. package/dist/lib/inspector.js +49 -1
  29. package/dist/lib/observability.d.ts +13 -0
  30. package/dist/lib/observability.js +160 -6
  31. package/dist/lib/paths.d.ts +7 -0
  32. package/dist/lib/paths.js +28 -0
  33. package/dist/lib/recipes-discovery.js +32 -24
  34. package/dist/lib/recipes-usage.d.ts +18 -6
  35. package/dist/lib/recipes-usage.js +445 -34
  36. package/dist/lib/review-control.d.ts +14 -0
  37. package/dist/lib/review-control.js +111 -0
  38. package/dist/lib/review-diagnostics.d.ts +11 -0
  39. package/dist/lib/review-diagnostics.js +148 -0
  40. package/dist/lib/review-projection.d.ts +14 -0
  41. package/dist/lib/review-projection.js +170 -0
  42. package/dist/lib/run-ui-runtime.d.ts +18 -0
  43. package/dist/lib/run-ui-runtime.js +123 -0
  44. package/dist/lib/runs-artifacts.d.ts +1 -1
  45. package/dist/lib/runs-artifacts.js +1 -1
  46. package/dist/lib/runs-control.d.ts +10 -2
  47. package/dist/lib/runs-control.js +37 -7
  48. package/dist/lib/runs-identity.d.ts +1 -1
  49. package/dist/lib/runs-identity.js +1 -1
  50. package/dist/lib/runs-index.d.ts +11 -2
  51. package/dist/lib/runs-index.js +46 -23
  52. package/dist/lib/runs-mailbox.d.ts +1 -1
  53. package/dist/lib/runs-mailbox.js +1 -1
  54. package/dist/lib/runs-messages.d.ts +1 -1
  55. package/dist/lib/runs-messages.js +1 -1
  56. package/dist/lib/runs-outbox.d.ts +1 -1
  57. package/dist/lib/runs-outbox.js +1 -1
  58. package/dist/lib/runs-ownership.d.ts +1 -1
  59. package/dist/lib/runs-ownership.js +18 -4
  60. package/dist/lib/runs-parent-teardown.d.ts +51 -0
  61. package/dist/lib/runs-parent-teardown.js +172 -0
  62. package/dist/lib/runs-process.d.ts +1 -1
  63. package/dist/lib/runs-process.js +5 -4
  64. package/dist/lib/runs-retention.d.ts +1 -1
  65. package/dist/lib/runs-retention.js +1 -1
  66. package/dist/lib/runs-start.d.ts +5 -3
  67. package/dist/lib/runs-start.js +7 -48
  68. package/dist/lib/runs-status.d.ts +5 -3
  69. package/dist/lib/runs-status.js +7 -6
  70. package/dist/lib/runtime.d.ts +7 -1
  71. package/dist/lib/runtime.js +32 -18
  72. package/dist/lib/tool-review-lineage-transaction.d.ts +27 -0
  73. package/dist/lib/tool-review-lineage-transaction.js +597 -0
  74. package/dist/lib/tool-review-lineage.d.ts +24 -0
  75. package/dist/lib/tool-review-lineage.js +98 -0
  76. package/dist/lib/tool-review-scheduler.d.ts +80 -0
  77. package/dist/lib/tool-review-scheduler.js +494 -0
  78. package/dist/lib/tool-review-transaction.d.ts +50 -0
  79. package/dist/lib/tool-review-transaction.js +362 -0
  80. package/dist/lib/tool-review.d.ts +56 -0
  81. package/dist/lib/tool-review.js +197 -0
  82. package/dist/lib/tools-inspect.js +28 -4
  83. package/dist/lib/tools-local.js +21 -4
  84. package/dist/lib/tools-message.d.ts +1 -0
  85. package/dist/lib/tools-message.js +29 -17
  86. package/dist/lib/tools-spawn.js +14 -2
  87. package/dist/lib/tools.d.ts +1 -0
  88. package/dist/lib/tools.js +1 -0
  89. package/dist/recipes/draft-review.json +24 -0
  90. package/dist/recipes/tool-review.json +24 -0
  91. package/dist/scripts/async-runner.mjs +9 -9
  92. package/dist/scripts/build-dist.mjs +6 -1
  93. package/dist/scripts/conformance.mjs +6 -1
  94. package/dist/scripts/recipe-utils.mjs +3 -3
  95. package/dist/scripts/release-gates.mjs +165 -0
  96. package/dist/skills/actors/SKILL.md +9 -8
  97. package/dist/skills/swarm/SKILL.md +1 -1
  98. package/docs/actor-inspector.md +20 -11
  99. package/docs/async-runs.md +16 -2
  100. package/docs/recipe-library.md +7 -3
  101. package/docs/template-recipes.md +4 -11
  102. package/docs/tool-registry.md +13 -4
  103. package/index.ts +27 -142
  104. package/lib/async-runs.ts +283 -67
  105. package/lib/automatic-review-runtime.ts +135 -0
  106. package/lib/command-templates.ts +1 -1
  107. package/lib/draft-consolidation-transaction.ts +821 -0
  108. package/lib/draft-consolidation.ts +181 -0
  109. package/lib/draft-review.ts +325 -0
  110. package/lib/draft-sleep.ts +576 -0
  111. package/lib/file-state.ts +143 -19
  112. package/lib/inspector-actions.ts +79 -0
  113. package/lib/inspector-command.ts +54 -0
  114. package/lib/inspector-overlay.ts +377 -91
  115. package/lib/inspector.ts +73 -1
  116. package/lib/observability.ts +194 -5
  117. package/lib/paths.ts +43 -0
  118. package/lib/recipes-discovery.ts +34 -26
  119. package/lib/recipes-usage.ts +569 -40
  120. package/lib/review-control.ts +137 -0
  121. package/lib/review-diagnostics.ts +164 -0
  122. package/lib/review-projection.ts +200 -0
  123. package/lib/run-ui-runtime.ts +153 -0
  124. package/lib/runs-artifacts.ts +1 -1
  125. package/lib/runs-control.ts +69 -6
  126. package/lib/runs-identity.ts +1 -1
  127. package/lib/runs-index.ts +57 -21
  128. package/lib/runs-mailbox.ts +1 -1
  129. package/lib/runs-messages.ts +1 -1
  130. package/lib/runs-outbox.ts +1 -1
  131. package/lib/runs-ownership.ts +23 -4
  132. package/lib/runs-parent-teardown.ts +257 -0
  133. package/lib/runs-process.ts +5 -4
  134. package/lib/runs-retention.ts +1 -1
  135. package/lib/runs-start.ts +13 -68
  136. package/lib/runs-status.ts +17 -8
  137. package/lib/runtime.ts +34 -17
  138. package/lib/tool-review-lineage-transaction.ts +881 -0
  139. package/lib/tool-review-lineage.ts +145 -0
  140. package/lib/tool-review-scheduler.ts +635 -0
  141. package/lib/tool-review-transaction.ts +563 -0
  142. package/lib/tool-review.ts +270 -0
  143. package/lib/tools-inspect.ts +35 -4
  144. package/lib/tools-local.ts +29 -4
  145. package/lib/tools-message.ts +45 -30
  146. package/lib/tools-spawn.ts +22 -2
  147. package/lib/tools.ts +5 -0
  148. package/package.json +5 -3
  149. package/recipes/draft-review.json +24 -0
  150. package/recipes/tool-review.json +24 -0
  151. package/scripts/async-runner.mjs +9 -9
  152. package/scripts/build-dist.mjs +6 -1
  153. package/scripts/conformance.mjs +6 -1
  154. package/scripts/recipe-utils.mjs +3 -3
  155. package/scripts/release-gates.mjs +165 -0
  156. package/skills/actors/SKILL.md +9 -8
  157. package/skills/swarm/SKILL.md +1 -1
@@ -1,20 +1,26 @@
1
1
  /**
2
2
  * Async run status and log readers.
3
- * Owns status derivation from run state files plus bounded log/event tails.
3
+ * Owns: status derivation from run state files plus bounded log/event tails.
4
4
  */
5
5
 
6
6
  import { existsSync, readFileSync } from "node:fs";
7
7
  import { join } from "node:path";
8
8
 
9
- import type { AsyncRunStatus } from "./async-runs.ts";
10
9
  import {
11
- isWithinRunnerIdentityGrace,
12
10
  verifyRunProcessIdentity,
13
11
  type RunProcessIdentity,
14
12
  } from "./runs-process.ts";
15
13
  import { readJsonlFileResilient } from "./state-readers.ts";
16
14
 
17
- export type RunJsonReader = (path: string) => Record<string, unknown> | undefined;
15
+ export type AsyncRunStatus =
16
+ | "running"
17
+ | "done"
18
+ | "failed"
19
+ | "exited"
20
+ | "cancelled"
21
+ | "killed";
22
+
23
+ type RunJsonReader = (path: string) => Record<string, unknown> | undefined;
18
24
 
19
25
  function getInterruptedRunStatus(
20
26
  stateDir: string,
@@ -35,7 +41,7 @@ export function buildRunStatus(
35
41
  meta: Record<string, unknown>,
36
42
  readJson: RunJsonReader,
37
43
  _runnerPath: string,
38
- runnerIdentityGraceMs: number,
44
+ _runnerIdentityGraceMs: number,
39
45
  ): Record<string, unknown> {
40
46
  const result = readJson(join(stateDir, "result.json"));
41
47
  const pid = Number(meta.pid || 0);
@@ -45,9 +51,7 @@ export function buildRunStatus(
45
51
  );
46
52
  const aliveOwnedRunner = Boolean(
47
53
  pid &&
48
- (processIdentity.valid ||
49
- (processIdentity.status === "unsupported_proof" &&
50
- isWithinRunnerIdentityGrace(meta, runnerIdentityGraceMs))),
54
+ (processIdentity.valid || processIdentity.status === "unsupported_proof"),
51
55
  );
52
56
  const status: AsyncRunStatus = result
53
57
  ? Number(result.code ?? 0) === 0
@@ -57,6 +61,9 @@ export function buildRunStatus(
57
61
  ? "running"
58
62
  : (getInterruptedRunStatus(stateDir) ?? "exited");
59
63
  const terminalHandled = readJson(join(stateDir, "terminal-handled.json"));
64
+ const terminalDeliveryFailure = readJson(
65
+ join(stateDir, "terminal-delivery-failure.json"),
66
+ );
60
67
  return {
61
68
  ...meta,
62
69
  eventsFile: join(stateDir, "events.jsonl"),
@@ -66,6 +73,8 @@ export function buildRunStatus(
66
73
  process_identity_status: processIdentity.status,
67
74
  progress: readJson(join(stateDir, "progress.json")) || null,
68
75
  result: result || null,
76
+ ...(terminalDeliveryFailure
77
+ ? { terminal_delivery_failure: terminalDeliveryFailure } : {}),
69
78
  ...(terminalHandled ? { terminal_handled: terminalHandled } : {}),
70
79
  state_dir: String(meta.state_dir ?? stateDir),
71
80
  stderrLog: join(stateDir, "stderr.log"),
package/lib/runtime.ts CHANGED
@@ -182,18 +182,29 @@ export function createAutoToolsRuntime(
182
182
  };
183
183
  }
184
184
 
185
+ export interface RecipeToolReloadWatcherDeps {
186
+ exists?: (path: string) => boolean;
187
+ recipeRoot?: string;
188
+ watchPath?: typeof watch;
189
+ }
190
+
185
191
  export function createRecipeToolReloadWatcher(
186
192
  runtime: Pick<ToolRegistryRuntime, "loadTools">,
193
+ deps: RecipeToolReloadWatcherDeps = {},
187
194
  ): RecipeToolReloadWatcher {
195
+ const pathExists = deps.exists ?? existsSync;
196
+ const watchPath = deps.watchPath ?? watch;
188
197
  let reloadTimeout: NodeJS.Timeout | undefined;
189
198
  let rootWatcher: FSWatcher | undefined;
190
199
  let parentWatcher: FSWatcher | undefined;
191
200
  let failureNotified = false;
192
201
  const close = (): void => {
193
- rootWatcher?.close();
202
+ const closingRoot = rootWatcher;
194
203
  rootWatcher = undefined;
195
- parentWatcher?.close();
204
+ closingRoot?.close();
205
+ const closingParent = parentWatcher;
196
206
  parentWatcher = undefined;
207
+ closingParent?.close();
197
208
  if (reloadTimeout) clearTimeout(reloadTimeout);
198
209
  reloadTimeout = undefined;
199
210
  };
@@ -217,28 +228,31 @@ export function createRecipeToolReloadWatcher(
217
228
  const watchParent = (ctx: RuntimeContext, recipeRoot: string): void => {
218
229
  if (parentWatcher || rootWatcher) return;
219
230
  const parent = dirname(recipeRoot);
220
- if (!existsSync(parent)) {
231
+ if (!pathExists(parent)) {
221
232
  notifyFailure(ctx);
222
233
  return;
223
234
  }
224
235
  try {
225
- parentWatcher = watch(parent, (_event, changedFile) => {
236
+ const watcher = watchPath(parent, (_event, changedFile) => {
237
+ if (parentWatcher !== watcher) return;
226
238
  if (
227
239
  changedFile &&
228
240
  String(changedFile) !== basename(recipeRoot) &&
229
- !existsSync(recipeRoot)
241
+ !pathExists(recipeRoot)
230
242
  ) {
231
243
  return;
232
244
  }
233
- if (!existsSync(recipeRoot)) return;
234
- parentWatcher?.close();
245
+ if (!pathExists(recipeRoot)) return;
235
246
  parentWatcher = undefined;
247
+ watcher.close();
236
248
  watchRoot(ctx, recipeRoot);
237
249
  scheduleReload(ctx);
238
250
  });
239
- parentWatcher.on("error", () => {
240
- parentWatcher?.close();
251
+ parentWatcher = watcher;
252
+ watcher.on("error", () => {
253
+ if (parentWatcher !== watcher) return;
241
254
  parentWatcher = undefined;
255
+ watcher.close();
242
256
  notifyFailure(ctx);
243
257
  });
244
258
  } catch {
@@ -247,25 +261,28 @@ export function createRecipeToolReloadWatcher(
247
261
  };
248
262
  const watchRoot = (ctx: RuntimeContext, recipeRoot: string): void => {
249
263
  if (rootWatcher) return;
250
- if (!existsSync(recipeRoot)) {
264
+ if (!pathExists(recipeRoot)) {
251
265
  watchParent(ctx, recipeRoot);
252
266
  return;
253
267
  }
254
268
  try {
255
- rootWatcher = watch(recipeRoot, () => {
256
- if (!existsSync(recipeRoot)) {
257
- rootWatcher?.close();
269
+ const watcher = watchPath(recipeRoot, () => {
270
+ if (rootWatcher !== watcher) return;
271
+ if (!pathExists(recipeRoot)) {
258
272
  rootWatcher = undefined;
273
+ watcher.close();
259
274
  scheduleReload(ctx);
260
275
  watchParent(ctx, recipeRoot);
261
276
  return;
262
277
  }
263
278
  scheduleReload(ctx);
264
279
  });
265
- rootWatcher.on("error", () => {
266
- rootWatcher?.close();
280
+ rootWatcher = watcher;
281
+ watcher.on("error", () => {
282
+ if (rootWatcher !== watcher) return;
267
283
  rootWatcher = undefined;
268
- if (existsSync(recipeRoot)) notifyFailure(ctx);
284
+ watcher.close();
285
+ if (pathExists(recipeRoot)) notifyFailure(ctx);
269
286
  else watchParent(ctx, recipeRoot);
270
287
  });
271
288
  } catch {
@@ -276,7 +293,7 @@ export function createRecipeToolReloadWatcher(
276
293
  close,
277
294
  watch(ctx: RuntimeContext): void {
278
295
  if (rootWatcher || parentWatcher) return;
279
- watchRoot(ctx, Paths.getRecipeRoot());
296
+ watchRoot(ctx, deps.recipeRoot ?? Paths.getRecipeRoot());
280
297
  },
281
298
  };
282
299
  }