@llblab/pi-actors 0.42.3 → 0.43.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.
Files changed (252) hide show
  1. package/AGENTS.md +121 -175
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +113 -276
  4. package/dist/fixtures/protocol/control-endpoint.json +6 -0
  5. package/dist/fixtures/protocol/control-record.json +9 -0
  6. package/dist/fixtures/protocol/recipe-summary.json +4 -12
  7. package/dist/fixtures/protocol/trace-event.json +9 -0
  8. package/dist/lib/async-runs.d.ts +14 -38
  9. package/dist/lib/async-runs.js +158 -108
  10. package/dist/lib/control.d.ts +12 -0
  11. package/dist/lib/control.js +84 -0
  12. package/dist/lib/execution-sessions.d.ts +17 -0
  13. package/dist/lib/execution-sessions.js +85 -0
  14. package/dist/lib/file-state.d.ts +1 -0
  15. package/dist/lib/file-state.js +17 -5
  16. package/dist/lib/inspector-actions.d.ts +2 -2
  17. package/dist/lib/inspector-actions.js +2 -2
  18. package/dist/lib/inspector-command.js +3 -3
  19. package/dist/lib/inspector-overlay.d.ts +52 -70
  20. package/dist/lib/inspector-overlay.js +532 -905
  21. package/dist/lib/inspector.d.ts +3 -71
  22. package/dist/lib/inspector.js +19 -665
  23. package/dist/lib/limits.d.ts +4 -2
  24. package/dist/lib/limits.js +4 -2
  25. package/dist/lib/observability.d.ts +16 -16
  26. package/dist/lib/observability.js +43 -82
  27. package/dist/lib/prompts.d.ts +1 -1
  28. package/dist/lib/prompts.js +2 -2
  29. package/dist/lib/recipe-control.d.ts +7 -0
  30. package/dist/lib/recipe-control.js +39 -0
  31. package/dist/lib/recipes-discovery.js +2 -0
  32. package/dist/lib/recipes-references.d.ts +1 -14
  33. package/dist/lib/recipes-references.js +6 -21
  34. package/dist/lib/review-projection.js +1 -5
  35. package/dist/lib/run-ui-runtime.js +2 -2
  36. package/dist/lib/runs-control-delivery.d.ts +21 -0
  37. package/dist/lib/runs-control-delivery.js +127 -0
  38. package/dist/lib/runs-controls.d.ts +35 -0
  39. package/dist/lib/runs-controls.js +144 -0
  40. package/dist/lib/runs-retention.d.ts +7 -0
  41. package/dist/lib/runs-retention.js +27 -3
  42. package/dist/lib/runs-start.js +4 -2
  43. package/dist/lib/runs-status.js +11 -6
  44. package/dist/lib/runs-trace.d.ts +24 -0
  45. package/dist/lib/runs-trace.js +98 -0
  46. package/dist/lib/runtime-notifier.d.ts +1 -1
  47. package/dist/lib/runtime-notifier.js +1 -1
  48. package/dist/lib/tools-inspect.d.ts +3 -3
  49. package/dist/lib/tools-inspect.js +203 -708
  50. package/dist/lib/tools-local.js +2 -10
  51. package/dist/lib/tools-message.d.ts +7 -7
  52. package/dist/lib/tools-message.js +95 -396
  53. package/dist/lib/tools-response.d.ts +1 -4
  54. package/dist/lib/tools-response.js +5 -39
  55. package/dist/lib/tools-spawn.js +16 -28
  56. package/dist/lib/tools.js +1 -2
  57. package/dist/lib/trace-projection.d.ts +22 -0
  58. package/dist/lib/trace-projection.js +165 -0
  59. package/dist/recipes/draft-review.json +0 -10
  60. package/dist/recipes/lens-swarm.json +0 -14
  61. package/dist/recipes/music-player.json +10 -19
  62. package/dist/recipes/pipeline-architect-coordinator.json +0 -11
  63. package/dist/recipes/pipeline-artifact-bundle.json +1 -22
  64. package/dist/recipes/pipeline-artifact-report.json +1 -18
  65. package/dist/recipes/pipeline-artifact-write.json +1 -18
  66. package/dist/recipes/pipeline-async-run-ops.json +0 -12
  67. package/dist/recipes/pipeline-checkpoint-continuation.json +0 -14
  68. package/dist/recipes/pipeline-development-tasking.json +0 -12
  69. package/dist/recipes/pipeline-docs-maintenance.json +0 -12
  70. package/dist/recipes/pipeline-media-library.json +0 -12
  71. package/dist/recipes/pipeline-quorum-review.json +0 -12
  72. package/dist/recipes/pipeline-release-readiness.json +0 -12
  73. package/dist/recipes/pipeline-release-summary.json +0 -12
  74. package/dist/recipes/pipeline-repo-health.json +0 -12
  75. package/dist/recipes/pipeline-research-synthesis.json +0 -11
  76. package/dist/recipes/pipeline-review-readiness.json +0 -12
  77. package/dist/recipes/resource-locker.json +27 -0
  78. package/dist/recipes/subagent-artifact.json +0 -9
  79. package/dist/recipes/subagent-checkpoint.json +0 -10
  80. package/dist/recipes/subagent-conflict-report.json +0 -11
  81. package/dist/recipes/subagent-contradiction-map.json +0 -11
  82. package/dist/recipes/subagent-critic.json +0 -11
  83. package/dist/recipes/subagent-evidence-map.json +0 -11
  84. package/dist/recipes/subagent-followup.json +0 -10
  85. package/dist/recipes/subagent-judge.json +0 -11
  86. package/dist/recipes/subagent-merge.json +0 -11
  87. package/dist/recipes/subagent-normalize.json +0 -11
  88. package/dist/recipes/subagent-plan.json +0 -11
  89. package/dist/recipes/subagent-preflight.json +0 -11
  90. package/dist/recipes/subagent-prompt.json +0 -10
  91. package/dist/recipes/subagent-quorum.json +0 -10
  92. package/dist/recipes/subagent-review-coordinator.json +0 -14
  93. package/dist/recipes/subagent-review.json +0 -11
  94. package/dist/recipes/subagent-task-card.json +0 -11
  95. package/dist/recipes/subagent-tools.json +0 -10
  96. package/dist/recipes/subagent-verify.json +0 -11
  97. package/dist/recipes/subagents-prompts.json +0 -10
  98. package/dist/recipes/tool-review.json +0 -10
  99. package/dist/scripts/async-runner.mjs +25 -25
  100. package/dist/scripts/conformance.mjs +4 -2
  101. package/dist/scripts/locker.mjs +200 -66
  102. package/dist/scripts/music-player.mjs +159 -150
  103. package/dist/scripts/recipe-utils.mjs +6 -96
  104. package/dist/scripts/release-gates.mjs +60 -0
  105. package/dist/scripts/validate-recipe.mjs +3 -53
  106. package/dist/skills/actors/SKILL.md +53 -266
  107. package/dist/skills/swarm/SKILL.md +11 -33
  108. package/docs/0.43-baseline.md +44 -0
  109. package/docs/README.md +3 -3
  110. package/docs/actor-inspector.md +26 -64
  111. package/docs/actors-deep-reference.md +92 -50
  112. package/docs/async-runs.md +81 -328
  113. package/docs/command-templates.md +2 -2
  114. package/docs/component-recipes.md +30 -133
  115. package/docs/recipe-library.md +57 -182
  116. package/docs/task-first-recipes.md +10 -12
  117. package/docs/template-recipes.md +76 -289
  118. package/docs/tool-registry.md +41 -161
  119. package/fixtures/protocol/control-endpoint.json +6 -0
  120. package/fixtures/protocol/control-record.json +9 -0
  121. package/fixtures/protocol/recipe-summary.json +4 -12
  122. package/fixtures/protocol/trace-event.json +9 -0
  123. package/lib/async-runs.ts +202 -201
  124. package/lib/control.ts +102 -0
  125. package/lib/execution-sessions.ts +111 -0
  126. package/lib/file-state.ts +17 -4
  127. package/lib/inspector-actions.ts +2 -2
  128. package/lib/inspector-command.ts +3 -3
  129. package/lib/inspector-overlay.ts +577 -1121
  130. package/lib/inspector.ts +46 -979
  131. package/lib/limits.ts +4 -2
  132. package/lib/observability.ts +60 -101
  133. package/lib/prompts.ts +2 -2
  134. package/lib/recipe-control.ts +45 -0
  135. package/lib/recipes-discovery.ts +2 -0
  136. package/lib/recipes-references.ts +9 -45
  137. package/lib/review-projection.ts +1 -5
  138. package/lib/run-ui-runtime.ts +2 -2
  139. package/lib/runs-control-delivery.ts +181 -0
  140. package/lib/runs-controls.ts +204 -0
  141. package/lib/runs-retention.ts +38 -3
  142. package/lib/runs-start.ts +4 -2
  143. package/lib/runs-status.ts +11 -6
  144. package/lib/runs-trace.ts +132 -0
  145. package/lib/runtime-notifier.ts +1 -1
  146. package/lib/tools-inspect.ts +240 -901
  147. package/lib/tools-local.ts +2 -12
  148. package/lib/tools-message.ts +112 -519
  149. package/lib/tools-response.ts +5 -52
  150. package/lib/tools-spawn.ts +16 -32
  151. package/lib/tools.ts +1 -2
  152. package/lib/trace-projection.ts +221 -0
  153. package/package.json +2 -1
  154. package/recipes/draft-review.json +0 -10
  155. package/recipes/lens-swarm.json +0 -14
  156. package/recipes/music-player.json +10 -19
  157. package/recipes/pipeline-architect-coordinator.json +0 -11
  158. package/recipes/pipeline-artifact-bundle.json +1 -22
  159. package/recipes/pipeline-artifact-report.json +1 -18
  160. package/recipes/pipeline-artifact-write.json +1 -18
  161. package/recipes/pipeline-async-run-ops.json +0 -12
  162. package/recipes/pipeline-checkpoint-continuation.json +0 -14
  163. package/recipes/pipeline-development-tasking.json +0 -12
  164. package/recipes/pipeline-docs-maintenance.json +0 -12
  165. package/recipes/pipeline-media-library.json +0 -12
  166. package/recipes/pipeline-quorum-review.json +0 -12
  167. package/recipes/pipeline-release-readiness.json +0 -12
  168. package/recipes/pipeline-release-summary.json +0 -12
  169. package/recipes/pipeline-repo-health.json +0 -12
  170. package/recipes/pipeline-research-synthesis.json +0 -11
  171. package/recipes/pipeline-review-readiness.json +0 -12
  172. package/recipes/resource-locker.json +27 -0
  173. package/recipes/subagent-artifact.json +0 -9
  174. package/recipes/subagent-checkpoint.json +0 -10
  175. package/recipes/subagent-conflict-report.json +0 -11
  176. package/recipes/subagent-contradiction-map.json +0 -11
  177. package/recipes/subagent-critic.json +0 -11
  178. package/recipes/subagent-evidence-map.json +0 -11
  179. package/recipes/subagent-followup.json +0 -10
  180. package/recipes/subagent-judge.json +0 -11
  181. package/recipes/subagent-merge.json +0 -11
  182. package/recipes/subagent-normalize.json +0 -11
  183. package/recipes/subagent-plan.json +0 -11
  184. package/recipes/subagent-preflight.json +0 -11
  185. package/recipes/subagent-prompt.json +0 -10
  186. package/recipes/subagent-quorum.json +0 -10
  187. package/recipes/subagent-review-coordinator.json +0 -14
  188. package/recipes/subagent-review.json +0 -11
  189. package/recipes/subagent-task-card.json +0 -11
  190. package/recipes/subagent-tools.json +0 -10
  191. package/recipes/subagent-verify.json +0 -11
  192. package/recipes/subagents-prompts.json +0 -10
  193. package/recipes/tool-review.json +0 -10
  194. package/scripts/async-runner.mjs +25 -25
  195. package/scripts/conformance.mjs +4 -2
  196. package/scripts/locker.mjs +200 -66
  197. package/scripts/music-player.mjs +159 -150
  198. package/scripts/recipe-utils.mjs +6 -96
  199. package/scripts/release-gates.mjs +60 -0
  200. package/scripts/validate-recipe.mjs +3 -53
  201. package/skills/actors/SKILL.md +53 -266
  202. package/skills/swarm/SKILL.md +11 -33
  203. package/dist/fixtures/protocol/actor-message-branch.json +0 -13
  204. package/dist/fixtures/protocol/mailbox-contract.json +0 -15
  205. package/dist/fixtures/protocol/room-message.json +0 -11
  206. package/dist/fixtures/protocol/room-roster.json +0 -11
  207. package/dist/fixtures/protocol/run-inbox-message.json +0 -9
  208. package/dist/fixtures/protocol/run-outbox-event.json +0 -9
  209. package/dist/lib/mailbox-loop.d.ts +0 -41
  210. package/dist/lib/mailbox-loop.js +0 -60
  211. package/dist/lib/messages.d.ts +0 -25
  212. package/dist/lib/messages.js +0 -122
  213. package/dist/lib/rooms.d.ts +0 -104
  214. package/dist/lib/rooms.js +0 -647
  215. package/dist/lib/runs-mailbox.d.ts +0 -25
  216. package/dist/lib/runs-mailbox.js +0 -146
  217. package/dist/lib/runs-messages.d.ts +0 -15
  218. package/dist/lib/runs-messages.js +0 -179
  219. package/dist/lib/runs-outbox.d.ts +0 -41
  220. package/dist/lib/runs-outbox.js +0 -87
  221. package/dist/lib/tools-mailbox.d.ts +0 -8
  222. package/dist/lib/tools-mailbox.js +0 -48
  223. package/dist/recipes/actor-worker.json +0 -39
  224. package/dist/recipes/coordinator-locker.json +0 -45
  225. package/dist/recipes/locker.json +0 -45
  226. package/dist/recipes/pipeline-room-swarm.json +0 -50
  227. package/dist/recipes/subagent-message.json +0 -32
  228. package/dist/recipes/utility-actor-message.json +0 -23
  229. package/dist/scripts/actor-worker.mjs +0 -214
  230. package/dist/scripts/coordinator.mjs +0 -799
  231. package/docs/actor-messages.md +0 -225
  232. package/fixtures/protocol/actor-message-branch.json +0 -13
  233. package/fixtures/protocol/mailbox-contract.json +0 -15
  234. package/fixtures/protocol/room-message.json +0 -11
  235. package/fixtures/protocol/room-roster.json +0 -11
  236. package/fixtures/protocol/run-inbox-message.json +0 -9
  237. package/fixtures/protocol/run-outbox-event.json +0 -9
  238. package/lib/mailbox-loop.ts +0 -144
  239. package/lib/messages.ts +0 -151
  240. package/lib/rooms.ts +0 -939
  241. package/lib/runs-mailbox.ts +0 -208
  242. package/lib/runs-messages.ts +0 -252
  243. package/lib/runs-outbox.ts +0 -144
  244. package/lib/tools-mailbox.ts +0 -56
  245. package/recipes/actor-worker.json +0 -39
  246. package/recipes/coordinator-locker.json +0 -45
  247. package/recipes/locker.json +0 -45
  248. package/recipes/pipeline-room-swarm.json +0 -50
  249. package/recipes/subagent-message.json +0 -32
  250. package/recipes/utility-actor-message.json +0 -23
  251. package/scripts/actor-worker.mjs +0 -214
  252. package/scripts/coordinator.mjs +0 -799
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Run-owned execution session evidence.
3
+ * Zones: execution manifest session discovery, canonical containment, rich turn correlation
4
+ * Owns reusable agent-turn loading; Trace and TUI projection stay in their adapters.
5
+ */
6
+
7
+ import * as fs from "node:fs";
8
+ import * as path from "node:path";
9
+
10
+ import * as SessionEvidence from "./session-evidence.ts";
11
+ import { readJsonFileResilient } from "./state-readers.ts";
12
+
13
+ export interface ExecutionTurnItem extends SessionEvidence.SessionEvidenceTurn {
14
+ commandId: string;
15
+ diagnostics: string[];
16
+ promptBytes?: number;
17
+ promptFile?: string;
18
+ recipeContext?: unknown;
19
+ sessionFile: string;
20
+ sessionTruncated: boolean;
21
+ stage?: string;
22
+ }
23
+
24
+ function ownedSessionPath(
25
+ stateDir: string,
26
+ sessionFile: string,
27
+ ): string | undefined {
28
+ if (path.isAbsolute(sessionFile)) return undefined;
29
+ const sessionsRoot = path.resolve(stateDir, "sessions");
30
+ const resolved = path.resolve(stateDir, sessionFile);
31
+ if (!resolved.startsWith(`${sessionsRoot}${path.sep}`)) return undefined;
32
+ try {
33
+ const canonicalRoot = fs.realpathSync(sessionsRoot);
34
+ const canonicalFile = fs.realpathSync(resolved);
35
+ return canonicalFile.startsWith(`${canonicalRoot}${path.sep}`)
36
+ ? canonicalFile
37
+ : undefined;
38
+ } catch {
39
+ return undefined;
40
+ }
41
+ }
42
+
43
+ export function readExecutionTurns(stateDir: string): ExecutionTurnItem[] {
44
+ const execution = readJsonFileResilient<Record<string, unknown>>(
45
+ path.join(stateDir, "execution.json"),
46
+ {},
47
+ ).value;
48
+ const commands = Array.isArray(execution.commands)
49
+ ? (execution.commands as Array<Record<string, unknown>>)
50
+ : [];
51
+ const recordedFiles = new Set(
52
+ commands.flatMap((command) =>
53
+ (Array.isArray(command.session_files) ? command.session_files : []).filter(
54
+ (file): file is string => typeof file === "string",
55
+ ),
56
+ ),
57
+ );
58
+ let discoveredCommands: Array<Record<string, unknown>> = [];
59
+ try {
60
+ const sessionsDir = path.join(stateDir, "sessions");
61
+ discoveredCommands = fs
62
+ .readdirSync(sessionsDir, { withFileTypes: true })
63
+ .filter((entry) => entry.isDirectory())
64
+ .flatMap((entry) => {
65
+ const files = fs
66
+ .readdirSync(path.join(sessionsDir, entry.name), {
67
+ withFileTypes: true,
68
+ })
69
+ .filter((file) => file.isFile() && file.name.endsWith(".jsonl"))
70
+ .map((file) => path.posix.join("sessions", entry.name, file.name))
71
+ .filter((file) => !recordedFiles.has(file));
72
+ return files.length > 0
73
+ ? [{ id: entry.name, session_files: files, stage: "subagent" }]
74
+ : [];
75
+ });
76
+ } catch {
77
+ discoveredCommands = [];
78
+ }
79
+ return [...commands, ...discoveredCommands]
80
+ .flatMap((command) =>
81
+ (Array.isArray(command.session_files) ? command.session_files : [])
82
+ .filter((file): file is string => typeof file === "string")
83
+ .flatMap((file) => {
84
+ const sessionPath = ownedSessionPath(stateDir, file);
85
+ if (!sessionPath) return [];
86
+ const session = SessionEvidence.readSessionEvidence(sessionPath);
87
+ return session.turns.map((turn) => ({
88
+ ...turn,
89
+ commandId: String(command.id ?? "unknown"),
90
+ diagnostics: session.diagnostics.map((item) =>
91
+ `${item.line === undefined ? "" : `line ${item.line}: `}${item.message}`,
92
+ ),
93
+ ...(typeof command.prompt_bytes === "number"
94
+ ? { promptBytes: command.prompt_bytes }
95
+ : {}),
96
+ ...(typeof command.prompt_file === "string"
97
+ ? { promptFile: command.prompt_file }
98
+ : {}),
99
+ ...(command.recipe_context !== undefined
100
+ ? { recipeContext: command.recipe_context }
101
+ : {}),
102
+ sessionFile: file,
103
+ sessionTruncated: session.truncated,
104
+ ...(typeof command.stage === "string"
105
+ ? { stage: command.stage }
106
+ : {}),
107
+ }));
108
+ }),
109
+ )
110
+ .map((turn, index) => ({ ...turn, index: index + 1 }));
111
+ }
package/lib/file-state.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  import { createHash, randomUUID } from "node:crypto";
8
8
  import {
9
9
  existsSync,
10
+ lstatSync,
10
11
  mkdirSync,
11
12
  readFileSync,
12
13
  realpathSync,
@@ -25,8 +26,16 @@ const FILE_MUTATION_LOCK_ROOT = join(tmpdir(), "pi-actors-file-locks");
25
26
 
26
27
  function canonicalMutationPath(path: string): string {
27
28
  const absolute = resolve(path);
28
- const suffix: string[] = [];
29
- let existing = absolute;
29
+ try {
30
+ if (lstatSync(absolute).isSymbolicLink()) {
31
+ const target = realpathSync.native(absolute);
32
+ return process.platform === "win32" ? target.toLowerCase() : target;
33
+ }
34
+ } catch {
35
+ /* Materialization may race lock-key derivation; canonicalize through the parent. */
36
+ }
37
+ const suffix: string[] = [basename(absolute)];
38
+ let existing = dirname(absolute);
30
39
  while (!existsSync(existing)) {
31
40
  const parent = dirname(existing);
32
41
  if (parent === existing || existing === parse(existing).root) break;
@@ -235,11 +244,11 @@ export function withFileMutationLock<T>(
235
244
  }
236
245
  }
237
246
 
238
- export function writeJsonAtomic(path: string, value: unknown): void {
247
+ export function writeTextAtomic(path: string, content: string): void {
239
248
  mkdirSync(dirname(path), { recursive: true });
240
249
  const tempPath = `${path}.${process.pid}.${Date.now()}.${randomUUID()}.tmp`;
241
250
  try {
242
- writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
251
+ writeFileSync(tempPath, content, "utf8");
243
252
  renameSync(tempPath, path);
244
253
  } catch (error) {
245
254
  try {
@@ -250,3 +259,7 @@ export function writeJsonAtomic(path: string, value: unknown): void {
250
259
  throw error;
251
260
  }
252
261
  }
262
+
263
+ export function writeJsonAtomic(path: string, value: unknown): void {
264
+ writeTextAtomic(path, `${JSON.stringify(value, null, 2)}\n`);
265
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Actor Inspector run actions.
2
+ * Actor Inspector actions for concrete Run instances.
3
3
  * Owns: exact-session run-action authorization, canonical kill routing, and bounded operator feedback.
4
4
  */
5
5
 
@@ -29,7 +29,7 @@ function bounded(value: unknown): string {
29
29
  : `${text.slice(0, FEEDBACK_LIMIT - 1)}…`;
30
30
  }
31
31
 
32
- export function killOwnedInspectorRun(
32
+ export function killOwnedRunFromInspector(
33
33
  ownerId: string,
34
34
  run: string,
35
35
  stateRoot: string,
@@ -14,8 +14,8 @@ export function registerActorInspectorCommand(
14
14
  pi: Pi.ExtensionAPI,
15
15
  getRunOwnerId: (ctx: Pi.ExtensionContext) => string,
16
16
  ): void {
17
- pi.registerCommand("actors-inspector", {
18
- description: "Open the keyboard-driven actor inspector overlay",
17
+ pi.registerCommand("actor-inspector", {
18
+ description: "Open the keyboard-driven Actor Inspector",
19
19
  handler: async (_args, ctx) => {
20
20
  ctx.ui.setWidget("zz-pi-actors-comms", undefined);
21
21
  await ctx.ui.custom<void>(
@@ -23,7 +23,7 @@ export function registerActorInspectorCommand(
23
23
  new InspectorOverlay.ActorInspectorOverlay({
24
24
  done,
25
25
  killRun: (run, runInstanceId) =>
26
- InspectorActions.killOwnedInspectorRun(
26
+ InspectorActions.killOwnedRunFromInspector(
27
27
  getRunOwnerId(ctx),
28
28
  run,
29
29
  Paths.EXTENSION_RUNTIME_PATHS.runStateRoot,