@llblab/pi-actors 0.54.0 → 0.56.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 (188) hide show
  1. package/AGENTS.md +110 -20
  2. package/BACKLOG.md +207 -4
  3. package/CHANGELOG.md +17 -0
  4. package/README.md +33 -3
  5. package/dist/index.js +2 -1
  6. package/dist/lib/async-runs.d.ts +37 -0
  7. package/dist/lib/async-runs.js +131 -62
  8. package/dist/lib/automatic-review-runtime.d.ts +2 -0
  9. package/dist/lib/automatic-review-runtime.js +3 -2
  10. package/dist/lib/command-templates.d.ts +37 -0
  11. package/dist/lib/command-templates.js +263 -129
  12. package/dist/lib/execution-files.d.ts +32 -0
  13. package/dist/lib/execution-files.js +128 -0
  14. package/dist/lib/execution-output.js +5 -4
  15. package/dist/lib/execution-sessions.d.ts +19 -1
  16. package/dist/lib/execution-sessions.js +62 -26
  17. package/dist/lib/execution.d.ts +4 -1
  18. package/dist/lib/execution.js +6 -1
  19. package/dist/lib/extension-runtime.d.ts +10 -2
  20. package/dist/lib/extension-runtime.js +95 -14
  21. package/dist/lib/file-state.js +21 -2
  22. package/dist/lib/inspector-command.js +2 -2
  23. package/dist/lib/inspector-overlay.d.ts +25 -7
  24. package/dist/lib/inspector-overlay.js +562 -262
  25. package/dist/lib/inspector.d.ts +20 -10
  26. package/dist/lib/inspector.js +80 -91
  27. package/dist/lib/limits.d.ts +1 -0
  28. package/dist/lib/limits.js +1 -0
  29. package/dist/lib/observability.d.ts +15 -1
  30. package/dist/lib/observability.js +216 -99
  31. package/dist/lib/pi.d.ts +9 -3
  32. package/dist/lib/pi.js +80 -12
  33. package/dist/lib/recipe-projection.d.ts +18 -0
  34. package/dist/lib/recipe-projection.js +220 -0
  35. package/dist/lib/recipes-context.d.ts +2 -0
  36. package/dist/lib/recipes-context.js +30 -6
  37. package/dist/lib/registry.js +270 -36
  38. package/dist/lib/run-delivery.d.ts +213 -5
  39. package/dist/lib/run-delivery.js +1909 -40
  40. package/dist/lib/run-supervision.d.ts +107 -0
  41. package/dist/lib/run-supervision.js +412 -0
  42. package/dist/lib/run-ui-runtime.d.ts +10 -2
  43. package/dist/lib/run-ui-runtime.js +347 -124
  44. package/dist/lib/runs-artifacts.d.ts +26 -1
  45. package/dist/lib/runs-artifacts.js +68 -2
  46. package/dist/lib/runs-context-exports.d.ts +451 -0
  47. package/dist/lib/runs-context-exports.js +2315 -0
  48. package/dist/lib/runs-context-index.d.ts +97 -0
  49. package/dist/lib/runs-context-index.js +368 -0
  50. package/dist/lib/runs-control-delivery.js +46 -7
  51. package/dist/lib/runs-control.d.ts +78 -2
  52. package/dist/lib/runs-control.js +334 -2
  53. package/dist/lib/runs-controls.js +4 -1
  54. package/dist/lib/runs-descendant-launches.d.ts +80 -0
  55. package/dist/lib/runs-descendant-launches.js +287 -0
  56. package/dist/lib/runs-execution-evidence.d.ts +110 -0
  57. package/dist/lib/runs-execution-evidence.js +282 -0
  58. package/dist/lib/runs-index.d.ts +66 -1
  59. package/dist/lib/runs-index.js +349 -13
  60. package/dist/lib/runs-native-launches.d.ts +73 -0
  61. package/dist/lib/runs-native-launches.js +227 -0
  62. package/dist/lib/runs-outcomes.d.ts +141 -0
  63. package/dist/lib/runs-outcomes.js +292 -0
  64. package/dist/lib/runs-ownership.d.ts +10 -1
  65. package/dist/lib/runs-ownership.js +36 -4
  66. package/dist/lib/runs-process-windows-mi.d.ts +46 -0
  67. package/dist/lib/runs-process-windows-mi.js +114 -0
  68. package/dist/lib/runs-process.d.ts +34 -1
  69. package/dist/lib/runs-process.js +158 -26
  70. package/dist/lib/runs-results.d.ts +116 -0
  71. package/dist/lib/runs-results.js +518 -0
  72. package/dist/lib/runs-retention.d.ts +15 -2
  73. package/dist/lib/runs-retention.js +148 -9
  74. package/dist/lib/runs-session-exports.d.ts +95 -0
  75. package/dist/lib/runs-session-exports.js +470 -0
  76. package/dist/lib/runs-snapshot.d.ts +58 -0
  77. package/dist/lib/runs-snapshot.js +92 -0
  78. package/dist/lib/runs-start.d.ts +2 -0
  79. package/dist/lib/runs-start.js +44 -3
  80. package/dist/lib/runs-status.d.ts +15 -1
  81. package/dist/lib/runs-status.js +337 -13
  82. package/dist/lib/runs-supervision.d.ts +105 -0
  83. package/dist/lib/runs-supervision.js +501 -0
  84. package/dist/lib/runs-trace.d.ts +1 -0
  85. package/dist/lib/runs-trace.js +14 -3
  86. package/dist/lib/runtime.js +22 -3
  87. package/dist/lib/session-evidence.d.ts +37 -0
  88. package/dist/lib/session-evidence.js +59 -3
  89. package/dist/lib/state-readers.d.ts +4 -1
  90. package/dist/lib/state-readers.js +14 -8
  91. package/dist/lib/temp.d.ts +2 -4
  92. package/dist/lib/temp.js +4 -56
  93. package/dist/lib/tools-access.d.ts +3 -0
  94. package/dist/lib/tools-access.js +13 -0
  95. package/dist/lib/tools-inspect.d.ts +1 -0
  96. package/dist/lib/tools-inspect.js +110 -43
  97. package/dist/lib/tools-local.d.ts +3 -0
  98. package/dist/lib/tools-local.js +18 -6
  99. package/dist/lib/tools-message.d.ts +4 -1
  100. package/dist/lib/tools-message.js +126 -31
  101. package/dist/lib/tools-response.d.ts +31 -3
  102. package/dist/lib/tools-response.js +311 -47
  103. package/dist/lib/tools-spawn.d.ts +3 -0
  104. package/dist/lib/tools-spawn.js +29 -7
  105. package/dist/lib/trace-projection.d.ts +20 -0
  106. package/dist/lib/trace-projection.js +192 -43
  107. package/dist/scripts/async-runner.mjs +272 -194
  108. package/dist/scripts/conformance.mjs +14 -2
  109. package/dist/skills/actors/SKILL.md +47 -3
  110. package/dist/skills/actors/references/diagnostics.md +40 -0
  111. package/dist/skills/actors/references/runs.md +56 -2
  112. package/docs/README.md +9 -1
  113. package/docs/actor-inspector.md +84 -15
  114. package/docs/agent-experience.md +216 -0
  115. package/docs/async-runs.md +21 -3
  116. package/docs/composition-transport.md +103 -0
  117. package/docs/coordinator-delivery.md +226 -24
  118. package/docs/inspection.md +38 -2
  119. package/docs/output-projection-map.md +130 -0
  120. package/docs/releasing.md +19 -2
  121. package/docs/run-supervision.md +1622 -0
  122. package/docs/template-recipes.md +4 -0
  123. package/docs/windows-process-observation.md +248 -0
  124. package/index.ts +2 -1
  125. package/lib/async-runs.ts +164 -73
  126. package/lib/automatic-review-runtime.ts +4 -2
  127. package/lib/command-templates.ts +287 -138
  128. package/lib/execution-files.ts +118 -0
  129. package/lib/execution-output.ts +4 -4
  130. package/lib/execution-sessions.ts +57 -27
  131. package/lib/execution.ts +8 -0
  132. package/lib/extension-runtime.ts +106 -12
  133. package/lib/file-state.ts +16 -2
  134. package/lib/inspector-command.ts +2 -2
  135. package/lib/inspector-overlay.ts +524 -261
  136. package/lib/inspector.ts +101 -130
  137. package/lib/limits.ts +1 -0
  138. package/lib/observability.ts +235 -116
  139. package/lib/pi.ts +89 -17
  140. package/lib/recipe-projection.ts +232 -0
  141. package/lib/recipes-context.ts +27 -6
  142. package/lib/registry.ts +266 -36
  143. package/lib/run-delivery.ts +1737 -49
  144. package/lib/run-supervision.ts +411 -0
  145. package/lib/run-ui-runtime.ts +293 -126
  146. package/lib/runs-artifacts.ts +73 -1
  147. package/lib/runs-context-exports.ts +1871 -0
  148. package/lib/runs-context-index.ts +372 -0
  149. package/lib/runs-control-delivery.ts +36 -18
  150. package/lib/runs-control.ts +297 -1
  151. package/lib/runs-controls.ts +3 -1
  152. package/lib/runs-descendant-launches.ts +338 -0
  153. package/lib/runs-execution-evidence.ts +302 -0
  154. package/lib/runs-index.ts +345 -17
  155. package/lib/runs-native-launches.ts +270 -0
  156. package/lib/runs-outcomes.ts +377 -0
  157. package/lib/runs-ownership.ts +37 -4
  158. package/lib/runs-process-windows-mi.ts +113 -0
  159. package/lib/runs-process.ts +210 -34
  160. package/lib/runs-results.ts +601 -0
  161. package/lib/runs-retention.ts +134 -10
  162. package/lib/runs-session-exports.ts +406 -0
  163. package/lib/runs-snapshot.ts +143 -0
  164. package/lib/runs-start.ts +44 -2
  165. package/lib/runs-status.ts +252 -10
  166. package/lib/runs-supervision.ts +394 -0
  167. package/lib/runs-trace.ts +14 -3
  168. package/lib/runtime.ts +22 -3
  169. package/lib/session-evidence.ts +76 -4
  170. package/lib/state-readers.ts +16 -7
  171. package/lib/temp.ts +3 -56
  172. package/lib/tools-access.ts +13 -0
  173. package/lib/tools-inspect.ts +110 -51
  174. package/lib/tools-local.ts +37 -24
  175. package/lib/tools-message.ts +120 -37
  176. package/lib/tools-response.ts +273 -50
  177. package/lib/tools-spawn.ts +31 -10
  178. package/lib/trace-projection.ts +165 -42
  179. package/package.json +10 -6
  180. package/scripts/async-runner.mjs +272 -194
  181. package/scripts/conformance.mjs +14 -2
  182. package/skills/actors/SKILL.md +47 -3
  183. package/skills/actors/references/diagnostics.md +40 -0
  184. package/skills/actors/references/runs.md +56 -2
  185. package/banner.jpg +0 -0
  186. package/dist/lib/inspector-actions.d.ts +0 -16
  187. package/dist/lib/inspector-actions.js +0 -57
  188. package/lib/inspector-actions.ts +0 -79
package/lib/inspector.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  /**
2
- * Actor Inspector evidence readers.
3
- * Zones: owned actor-instance inventory and captured Recipe projection
4
- * Owns actor-instance TUI evidence; Trace, Control, and execution parsing stay in their domains.
2
+ * Actor Inspector owned-Run evidence and actions.
3
+ * Zones: owned inventory, captured Recipe reads, exact-session/generation action fencing
4
+ * Owns Inspector domain operations; command/overlay wiring and lifecycle actuation stay in adapters.
5
5
  */
6
6
 
7
7
  import * as fs from "node:fs";
8
8
  import * as path from "node:path";
9
+ import { join } from "node:path";
9
10
 
10
- import * as SessionEvidence from "./session-evidence.ts";
11
+ import { projectRunRecipe, type RunRecipeView } from "./recipe-projection.ts";
12
+ import { safeRunId } from "./runs-identity.ts";
11
13
  import { readJsonFileResilient } from "./state-readers.ts";
14
+ import { formatMarkdownField } from "./tools-response.ts";
12
15
 
13
16
  export interface ActorInspectorRunItem {
14
17
  run: string;
@@ -73,132 +76,100 @@ export function readActorInspectorRuns(
73
76
  }
74
77
  }
75
78
 
76
- export interface ActorInspectorRecipeView {
77
- composition: Array<Record<string, unknown>>;
78
- definition?: Record<string, unknown>;
79
- diagnostics: string[];
80
- identity: Record<string, unknown>;
81
- launch: Record<string, unknown>;
79
+ export function readActorInspectorRecipe(stateDir: string): RunRecipeView {
80
+ const result = readJsonFileResilient<Record<string, unknown>>(path.join(stateDir, "run.json"), {});
81
+ return projectRunRecipe(result.value, result.diagnostics.map(diagnostic => diagnostic.message));
82
82
  }
83
83
 
84
- export function readActorInspectorRecipe(
85
- stateDir: string,
86
- ): ActorInspectorRecipeView {
87
- const result = readJsonFileResilient<Record<string, unknown>>(
88
- path.join(stateDir, "run.json"),
89
- {},
90
- );
91
- const meta = result.value;
92
- const contexts = Array.isArray(meta.recipe_context_records)
93
- ? meta.recipe_context_records.filter(
94
- (entry): entry is Record<string, unknown> =>
95
- Boolean(entry && typeof entry === "object" && !Array.isArray(entry)),
96
- )
97
- : [];
98
- const primary = contexts.find((entry) => entry.depth === 0) ?? contexts[0];
99
- const definition =
100
- primary?.recipe &&
101
- typeof primary.recipe === "object" &&
102
- !Array.isArray(primary.recipe)
103
- ? (primary.recipe as Record<string, unknown>)
104
- : undefined;
105
- const stripPrivateOrigins = (value: unknown): unknown => {
106
- if (Array.isArray(value)) return value.map(stripPrivateOrigins);
107
- if (!value || typeof value !== "object") return value;
108
- return Object.fromEntries(
109
- Object.entries(value as Record<string, unknown>)
110
- .filter(
111
- ([key, entry]) =>
112
- entry !== undefined &&
113
- key !== "recipe_dir" &&
114
- key !== "skill_dir" &&
115
- key !== "source_file",
116
- )
117
- .map(([key, entry]) => [
118
- key,
119
- key === "actorRecipeContext" && entry && typeof entry === "object"
120
- ? stripPrivateOrigins(
121
- Object.fromEntries(
122
- Object.entries(entry as Record<string, unknown>).filter(
123
- ([contextKey]) => contextKey !== "file",
124
- ),
125
- ),
126
- )
127
- : stripPrivateOrigins(entry),
128
- ]),
129
- );
130
- };
131
- const redactedRecord = (value: Record<string, unknown>): Record<string, unknown> =>
132
- SessionEvidence.redactSessionEvidenceValue(
133
- stripPrivateOrigins(value),
134
- ) as Record<string, unknown>;
135
- const primarySourceKind =
136
- primary?.source_kind === "active_skill_component"
137
- ? "active_skill_component"
138
- : primary?.source_kind === "user_registry_capability" ||
139
- meta.launch_source === "tool"
140
- ? "user_registry_capability"
141
- : "explicit_file_recipe";
142
- const primaryLogicalReference =
143
- typeof primary?.logical_reference === "string"
144
- ? primary.logical_reference
145
- : typeof primary?.name === "string"
146
- ? primary.name
147
- : typeof meta.recipe === "string"
148
- ? meta.recipe
149
- : "unknown";
150
- const launchValues =
151
- meta.values && typeof meta.values === "object" && !Array.isArray(meta.values)
152
- ? Object.fromEntries(
153
- Object.entries(meta.values as Record<string, unknown>).filter(
154
- ([key]) => key !== "recipe_dir" && key !== "skill_dir",
155
- ),
156
- )
157
- : meta.values;
158
- return {
159
- composition: contexts.map((entry) =>
160
- redactedRecord({
161
- ...(typeof entry.alias === "string" ? { alias: entry.alias } : {}),
162
- depth: entry.depth,
163
- import_path: entry.import_path,
164
- logical_reference: entry.logical_reference ?? entry.name,
165
- recipe_stem: entry.name,
166
- role: entry.role,
167
- ...(typeof entry.skill === "string" ? { skill: entry.skill } : {}),
168
- source_kind:
169
- entry.source_kind === "active_skill_component"
170
- ? "active_skill_component"
171
- : entry.source_kind === "user_registry_capability" ||
172
- (entry.depth === 0 && meta.launch_source === "tool")
173
- ? "user_registry_capability"
174
- : "explicit_file_recipe",
175
- }),
176
- ),
177
- ...(definition ? { definition: redactedRecord(definition) } : {}),
178
- diagnostics: result.diagnostics.map((diagnostic) => diagnostic.message),
179
- identity: redactedRecord({
180
- run: meta.run,
181
- recipe: meta.recipe,
182
- recipe_stem: primary?.name ?? meta.recipe,
183
- logical_reference: primaryLogicalReference,
184
- ...(typeof primary?.skill === "string" ? { skill: primary.skill } : {}),
185
- source_kind: primarySourceKind,
186
- launch_kind: meta.launch_kind ?? meta.launch_source,
187
- launch_source: meta.launch_source,
188
- ...(meta.singleton === true
189
- ? { singleton: true, singleton_recipe_id: meta.singleton_recipe_id }
190
- : {}),
191
- }),
192
- launch: redactedRecord({
193
- cwd: meta.cwd,
194
- template: meta.template,
195
- values: launchValues,
196
- model_policy: meta.model_policy,
197
- control: meta.control,
198
- artifacts: meta.artifacts,
199
- notification_policy: meta.notification_policy,
200
- retire_when: meta.retire_when,
201
- singleton_values: meta.singleton_values,
202
- }),
203
- };
84
+ const FEEDBACK_LIMIT = 180;
85
+
86
+ export interface ActorInspectorKillResult {
87
+ ok: boolean;
88
+ message: string;
89
+ }
90
+
91
+ export interface ActorInspectorKillDeps {
92
+ getRunStatus: (runOrDir: string) => Record<string, unknown>;
93
+ killRun: (
94
+ runOrDir: string,
95
+ expected: { ownerId: string; runInstanceId: string },
96
+ ) => Record<string, unknown>;
97
+ }
98
+
99
+ /** Pure presentation of an already selected value; legacy metadata grants no source/privacy authority. */
100
+ export function formatActorInspectorKillFeedback(
101
+ result: "rejected" | "unavailable" | "failed",
102
+ selected: string,
103
+ legacy?: { readonly clipped: boolean },
104
+ ): string {
105
+ const key = result === "unavailable" ? "state" : "diagnostic";
106
+ const fields = [formatMarkdownField("action", "kill"), formatMarkdownField("result", result)];
107
+ if (Buffer.from(selected).toString("utf8") !== selected) {
108
+ fields.push(formatMarkdownField(key, "unavailable"), formatMarkdownField(`${key}_reason`, "malformed_legacy_preview"),
109
+ formatMarkdownField(`${key}_omission`, "[omitted: unknown]"));
110
+ } else {
111
+ fields.push(formatMarkdownField(key, selected + (legacy?.clipped ? "…" : "")));
112
+ if (legacy?.clipped) fields.push(formatMarkdownField(`${key}_omission`, "[omitted: unknown]"));
113
+ }
114
+ if (legacy) fields.push(formatMarkdownField("preview_basis", "selected legacy preview; upstream completeness/privacy unproven"));
115
+ fields.push(formatMarkdownField("closure", "unconfirmed"));
116
+ if (result === "failed") fields.push(formatMarkdownField("safety", "Do not repeat automatically."));
117
+ return fields.join("\n");
118
+ }
119
+
120
+ function bounded(result: "rejected" | "unavailable" | "failed", value: unknown): string {
121
+ const text = String(value ?? "").replaceAll(/\s+/g, " ").trim();
122
+ const clipped = text.length > FEEDBACK_LIMIT;
123
+ let end = clipped ? FEEDBACK_LIMIT - 1 : text.length;
124
+ if (clipped && end > 0 && /[\uD800-\uDBFF]/u.test(text[end - 1]!) && /[\uDC00-\uDFFF]/u.test(text[end]!)) end -= 1;
125
+ return formatActorInspectorKillFeedback(result, clipped ? text.slice(0, end) : text, { clipped });
126
+ }
127
+
128
+ export function killOwnedRunFromInspector(
129
+ ownerId: string,
130
+ run: string,
131
+ stateRoot: string,
132
+ expectedRunInstanceId: string,
133
+ deps: ActorInspectorKillDeps,
134
+ ): ActorInspectorKillResult {
135
+ let stateDir: string;
136
+ try {
137
+ stateDir = join(stateRoot, safeRunId(run));
138
+ } catch (error) {
139
+ return {
140
+ ok: false,
141
+ message: bounded("rejected", error instanceof Error ? error.message : error),
142
+ };
143
+ }
144
+ try {
145
+ const status = deps.getRunStatus(stateDir);
146
+ if (status.ownerId !== ownerId) {
147
+ return { ok: false, message: formatActorInspectorKillFeedback("rejected", "run ownership changed.") };
148
+ }
149
+ if (status.status !== "running") {
150
+ return {
151
+ ok: false,
152
+ message: bounded("unavailable", status.status || "terminal"),
153
+ };
154
+ }
155
+ if (status.run_instance_id !== expectedRunInstanceId) {
156
+ return { ok: false, message: formatActorInspectorKillFeedback("rejected", "run generation changed.") };
157
+ }
158
+ const result = deps.killRun(stateDir, {
159
+ ownerId,
160
+ runInstanceId: expectedRunInstanceId,
161
+ });
162
+ if (result.killed === true) {
163
+ return { ok: true, message: `Killed run:${run}.` };
164
+ }
165
+ return {
166
+ ok: false,
167
+ message: bounded("failed", result.reason || "control rejected"),
168
+ };
169
+ } catch (error) {
170
+ return {
171
+ ok: false,
172
+ message: bounded("failed", error instanceof Error ? error.message : error),
173
+ };
174
+ }
204
175
  }
package/lib/limits.ts CHANGED
@@ -31,6 +31,7 @@ export const RUN_RETENTION_MAX_BYTES = 1024 * 1024;
31
31
  export const RUN_DELIVERY_BATCH_MAX_MEMBERS = 256;
32
32
  export const RUN_DELIVERY_MODEL_MAX_MEMBERS = 64;
33
33
  export const RUN_DELIVERY_MODEL_MAX_BYTES = 16 * 1024;
34
+ export const RUN_COMPLETION_MODEL_MAX_BYTES = 48 * 1024;
34
35
  export const RUN_DELIVERY_RECEIPT_LIMIT = 128;
35
36
  export const RUN_DELIVERY_SESSION_MAX_ENTRIES = 256;
36
37
  export const RUN_DELIVERY_SESSION_MAX_BYTES = 1024 * 1024;