@llblab/pi-actors 0.33.0 → 0.34.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.
- package/AGENTS.md +22 -11
- package/BACKLOG.md +3 -34
- package/CHANGELOG.md +14 -0
- package/dist/index.js +10 -10
- package/dist/lib/async-runs.d.ts +23 -75
- package/dist/lib/async-runs.js +49 -801
- package/dist/lib/command-templates.d.ts +3 -3
- package/dist/lib/command-templates.js +3 -3
- package/dist/lib/config.d.ts +2 -2
- package/dist/lib/config.js +5 -5
- package/dist/lib/{output.d.ts → execution-output.d.ts} +3 -3
- package/dist/lib/{output.js → execution-output.js} +3 -3
- package/dist/lib/execution.js +1 -1
- package/dist/lib/{actor-inspector-tui.d.ts → inspector.d.ts} +3 -2
- package/dist/lib/{actor-inspector-tui.js → inspector.js} +3 -2
- package/dist/lib/mailbox-loop.d.ts +3 -3
- package/dist/lib/mailbox-loop.js +3 -3
- package/dist/lib/{actor-messages.d.ts → messages.d.ts} +3 -3
- package/dist/lib/{actor-messages.js → messages.js} +3 -3
- package/dist/lib/{actor-recipe-context.d.ts → recipes-context.d.ts} +3 -2
- package/dist/lib/{actor-recipe-context.js → recipes-context.js} +2 -1
- package/dist/lib/{recipe-discovery.d.ts → recipes-discovery.d.ts} +8 -8
- package/dist/lib/{recipe-discovery.js → recipes-discovery.js} +6 -6
- package/dist/lib/registry.d.ts +1 -1
- package/dist/lib/registry.js +22 -22
- package/dist/lib/{actor-rooms.d.ts → rooms.d.ts} +4 -4
- package/dist/lib/{actor-rooms.js → rooms.js} +3 -3
- package/dist/lib/runs-artifacts.d.ts +21 -0
- package/dist/lib/runs-artifacts.js +68 -0
- package/dist/lib/runs-control.d.ts +13 -0
- package/dist/lib/runs-control.js +59 -0
- package/dist/lib/runs-identity.d.ts +5 -0
- package/dist/lib/runs-identity.js +11 -0
- package/dist/lib/runs-index.d.ts +18 -0
- package/dist/lib/runs-index.js +119 -0
- package/dist/lib/runs-mailbox.d.ts +25 -0
- package/dist/lib/runs-mailbox.js +146 -0
- package/dist/lib/runs-messages.d.ts +15 -0
- package/dist/lib/runs-messages.js +179 -0
- package/dist/lib/runs-outbox.d.ts +41 -0
- package/dist/lib/runs-outbox.js +87 -0
- package/dist/lib/runs-process.d.ts +7 -0
- package/dist/lib/runs-process.js +36 -0
- package/dist/lib/runs-retention.d.ts +8 -0
- package/dist/lib/runs-retention.js +56 -0
- package/dist/lib/runs-start.d.ts +9 -0
- package/dist/lib/runs-start.js +67 -0
- package/dist/lib/runs-status.d.ts +8 -0
- package/dist/lib/runs-status.js +60 -0
- package/dist/lib/runtime.d.ts +2 -2
- package/dist/lib/runtime.js +5 -5
- package/dist/lib/schema.d.ts +9 -0
- package/dist/lib/schema.js +40 -0
- package/dist/lib/tools-access.d.ts +19 -0
- package/dist/lib/tools-access.js +44 -0
- package/dist/lib/tools-inspect.d.ts +11 -0
- package/dist/lib/tools-inspect.js +534 -0
- package/dist/lib/tools-local.d.ts +14 -0
- package/dist/lib/tools-local.js +156 -0
- package/dist/lib/tools-mailbox.d.ts +8 -0
- package/dist/lib/tools-mailbox.js +48 -0
- package/dist/lib/tools-message.d.ts +9 -0
- package/dist/lib/tools-message.js +428 -0
- package/dist/lib/tools-register.d.ts +18 -0
- package/dist/lib/tools-register.js +40 -0
- package/dist/lib/tools-response.d.ts +21 -0
- package/dist/lib/tools-response.js +219 -0
- package/dist/lib/tools-spawn.d.ts +12 -0
- package/dist/lib/tools-spawn.js +159 -0
- package/dist/lib/tools.d.ts +8 -39
- package/dist/lib/tools.js +11 -1490
- package/dist/recipes/utility-coordinator-lock-snapshot.json +1 -1
- package/dist/scripts/actor-worker.mjs +190 -7
- package/dist/scripts/async-runner.mjs +171 -8
- package/dist/scripts/build-dist.mjs +1 -1
- package/dist/scripts/conformance.mjs +3 -3
- package/dist/scripts/coordinator.mjs +733 -11
- package/dist/scripts/locker.mjs +345 -16
- package/dist/scripts/recipe-utils.mjs +478 -14
- package/dist/scripts/validate-recipe.mjs +110 -10
- package/dist/skills/actors/SKILL.md +1 -1
- package/dist/skills/swarm/SKILL.md +1 -1
- package/docs/recipe-library.md +1 -1
- package/docs/template-recipes.md +1 -1
- package/index.ts +11 -18
- package/lib/async-runs.ts +124 -1016
- package/lib/command-templates.ts +3 -3
- package/lib/config.ts +7 -7
- package/lib/{output.ts → execution-output.ts} +3 -3
- package/lib/execution.ts +5 -1
- package/lib/{actor-inspector-tui.ts → inspector.ts} +4 -3
- package/lib/mailbox-loop.ts +3 -3
- package/lib/{actor-messages.ts → messages.ts} +3 -3
- package/lib/{actor-recipe-context.ts → recipes-context.ts} +3 -2
- package/lib/{recipe-discovery.ts → recipes-discovery.ts} +19 -19
- package/lib/{recipe-usage.ts → recipes-usage.ts} +2 -2
- package/lib/registry.ts +37 -24
- package/lib/{actor-rooms.ts → rooms.ts} +4 -4
- package/lib/runs-artifacts.ts +96 -0
- package/lib/runs-control.ts +85 -0
- package/lib/runs-identity.ts +14 -0
- package/lib/runs-index.ts +156 -0
- package/lib/runs-mailbox.ts +208 -0
- package/lib/runs-messages.ts +252 -0
- package/lib/runs-outbox.ts +144 -0
- package/lib/runs-process.ts +51 -0
- package/lib/runs-retention.ts +77 -0
- package/lib/runs-start.ts +98 -0
- package/lib/runs-status.ts +78 -0
- package/lib/runtime.ts +6 -6
- package/lib/schema.ts +55 -0
- package/lib/tools-access.ts +68 -0
- package/lib/tools-inspect.ts +735 -0
- package/lib/tools-local.ts +234 -0
- package/lib/tools-mailbox.ts +56 -0
- package/lib/tools-message.ts +569 -0
- package/lib/tools-register.ts +64 -0
- package/lib/tools-response.ts +267 -0
- package/lib/tools-spawn.ts +240 -0
- package/lib/tools.ts +20 -2040
- package/package.json +1 -1
- package/recipes/utility-coordinator-lock-snapshot.json +1 -1
- package/scripts/actor-worker.mjs +190 -7
- package/scripts/async-runner.mjs +171 -8
- package/scripts/build-dist.mjs +1 -1
- package/scripts/conformance.mjs +3 -3
- package/scripts/coordinator.mjs +733 -11
- package/scripts/locker.mjs +345 -16
- package/scripts/recipe-utils.mjs +478 -14
- package/scripts/validate-recipe.mjs +110 -10
- package/skills/actors/SKILL.md +1 -1
- package/skills/swarm/SKILL.md +1 -1
- package/dist/lib/actor-worker.d.ts +0 -16
- package/dist/lib/actor-worker.js +0 -134
- package/dist/lib/async-runner.d.ts +0 -5
- package/dist/lib/async-runner.js +0 -134
- package/dist/lib/coordinator.d.ts +0 -5
- package/dist/lib/coordinator.js +0 -660
- package/dist/lib/locker.d.ts +0 -5
- package/dist/lib/locker.js +0 -310
- package/dist/lib/recipe-utils.d.ts +0 -5
- package/dist/lib/recipe-utils.js +0 -385
- package/dist/lib/validate-recipe.d.ts +0 -6
- package/dist/lib/validate-recipe.js +0 -104
- package/lib/actor-worker.ts +0 -174
- package/lib/async-runner.ts +0 -173
- package/lib/coordinator.ts +0 -742
- package/lib/locker.ts +0 -340
- package/lib/recipe-utils.ts +0 -486
- package/lib/validate-recipe.ts +0 -110
- /package/dist/lib/{recipe-references.d.ts → recipes-references.d.ts} +0 -0
- /package/dist/lib/{recipe-references.js → recipes-references.js} +0 -0
- /package/dist/lib/{recipe-usage.d.ts → recipes-usage.d.ts} +0 -0
- /package/dist/lib/{recipe-usage.js → recipes-usage.js} +0 -0
- /package/lib/{recipe-references.ts → recipes-references.ts} +0 -0
package/package.json
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"state_dir": "~/.pi/agent/tmp/pi-actors/runs/coordinator-locker",
|
|
10
10
|
"lines": "20"
|
|
11
11
|
},
|
|
12
|
-
"template": "{repo}/scripts/
|
|
12
|
+
"template": "{repo}/scripts/locker.mjs snapshot --state-dir {state_dir} --lines {lines}"
|
|
13
13
|
}
|
package/scripts/actor-worker.mjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Canonical mailbox-backed actor worker demo.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Owns the worker argument parsing and control loop directly. Reusable room and
|
|
7
|
+
* mailbox primitives stay in lib/; this script remains the public executable.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { existsSync } from "node:fs";
|
|
10
|
+
import { appendFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
12
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
13
|
|
|
@@ -15,13 +15,196 @@ function packageRoot() {
|
|
|
15
15
|
return dirname(dirname(fileURLToPath(import.meta.url)));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
async function importRuntimeModule(name) {
|
|
19
19
|
const root = packageRoot();
|
|
20
|
-
const compiled = join(root, "dist", "lib",
|
|
21
|
-
|
|
20
|
+
const compiled = join(root, "dist", "lib", `${name}.js`);
|
|
21
|
+
const source = join(root, "lib", `${name}.ts`);
|
|
22
|
+
return await import(
|
|
23
|
+
pathToFileURL(existsSync(compiled) ? compiled : source).href
|
|
24
|
+
);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
const {
|
|
27
|
+
const { appendRoomMessage, ensureRoomMember, readBranchInboxMessages } =
|
|
28
|
+
await importRuntimeModule("rooms");
|
|
29
|
+
const { handleMailboxLoopOnce, isMailboxLoopStopMessage } =
|
|
30
|
+
await importRuntimeModule("mailbox-loop");
|
|
31
|
+
|
|
32
|
+
export function parseActorWorkerArgs(argv) {
|
|
33
|
+
const args = {};
|
|
34
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
35
|
+
const token = argv[index];
|
|
36
|
+
if (!token.startsWith("--")) continue;
|
|
37
|
+
const key = token.slice(2).replaceAll("-", "_");
|
|
38
|
+
const next = argv[index + 1];
|
|
39
|
+
if (!next || next.startsWith("--")) {
|
|
40
|
+
args[key] = true;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
args[key] = next;
|
|
44
|
+
index += 1;
|
|
45
|
+
}
|
|
46
|
+
return args;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function sleep(ms) {
|
|
50
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function text(value) {
|
|
54
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function enabled(value) {
|
|
58
|
+
return value !== false && value !== "false" && value !== "0";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function safeName(value) {
|
|
62
|
+
return String(value ?? "unknown").replaceAll(/[^A-Za-z0-9_.-]+/g, "_");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function runActorWorker(argv = process.argv.slice(2)) {
|
|
66
|
+
const args = parseActorWorkerArgs(argv);
|
|
67
|
+
const stateDir = String(args.state_dir ?? "");
|
|
68
|
+
const run = String(args.run ?? "");
|
|
69
|
+
const branch = String(args.branch ?? "worker");
|
|
70
|
+
const pollMs = Math.max(50, Number(args.poll_ms ?? 1000));
|
|
71
|
+
const staleClaimMs = Math.max(0, Number(args.stale_claim_ms ?? 0));
|
|
72
|
+
const artifactDir = String(
|
|
73
|
+
args.artifact_dir ?? join(stateDir, "worker-artifacts"),
|
|
74
|
+
);
|
|
75
|
+
const writeArtifacts = enabled(args.write_artifacts ?? true);
|
|
76
|
+
|
|
77
|
+
if (!stateDir || !run) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"usage: actor-worker.mjs --state-dir <dir> --run <id> [--branch worker] [--poll-ms 1000]",
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const branchAddress = `branch:${run}/${branch}`;
|
|
84
|
+
const roomAddress = `room:${run}`;
|
|
85
|
+
const journalPath = join(stateDir, "worker-events.jsonl");
|
|
86
|
+
const statusPath = join(stateDir, "worker-status.json");
|
|
87
|
+
if (writeArtifacts) mkdirSync(artifactDir, { recursive: true });
|
|
88
|
+
|
|
89
|
+
function journal(event, data = {}) {
|
|
90
|
+
appendFileSync(
|
|
91
|
+
journalPath,
|
|
92
|
+
`${JSON.stringify({ event, ts: new Date().toISOString(), ...data })}\n`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function staleClaims() {
|
|
97
|
+
if (staleClaimMs <= 0) return 0;
|
|
98
|
+
const cutoff = Date.now() - staleClaimMs;
|
|
99
|
+
return readBranchInboxMessages(stateDir, run, branchAddress).filter(
|
|
100
|
+
(record) => {
|
|
101
|
+
if (record.status !== "claimed" || !record.claimed_at) return false;
|
|
102
|
+
const claimedAt = Date.parse(record.claimed_at);
|
|
103
|
+
return Number.isFinite(claimedAt) && claimedAt < cutoff;
|
|
104
|
+
},
|
|
105
|
+
).length;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function status(state, data = {}) {
|
|
109
|
+
writeFileSync(
|
|
110
|
+
statusPath,
|
|
111
|
+
`${JSON.stringify({ artifact_dir: artifactDir, branch, run, stale_claims: staleClaims(), state, ts: new Date().toISOString(), ...data }, null, 2)}\n`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function writeResultArtifact(id, result) {
|
|
116
|
+
if (!writeArtifacts) return undefined;
|
|
117
|
+
const path = join(artifactDir, `${safeName(id)}.txt`);
|
|
118
|
+
writeFileSync(path, `${result}\n`);
|
|
119
|
+
return path;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function room(type, summary, body = {}) {
|
|
123
|
+
appendRoomMessage(stateDir, "main", {
|
|
124
|
+
body,
|
|
125
|
+
from: branchAddress,
|
|
126
|
+
summary,
|
|
127
|
+
to: roomAddress,
|
|
128
|
+
type,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ensureRoomMember(
|
|
133
|
+
stateDir,
|
|
134
|
+
run,
|
|
135
|
+
"main",
|
|
136
|
+
branchAddress,
|
|
137
|
+
{ display: branch, role: "worker", status: "present" },
|
|
138
|
+
`${branch} joined as mailbox worker`,
|
|
139
|
+
);
|
|
140
|
+
room("awaiting_assignment", `${branch} awaiting assignment`, {
|
|
141
|
+
branch,
|
|
142
|
+
stale_claim_ms: staleClaimMs,
|
|
143
|
+
stale_claims: staleClaims(),
|
|
144
|
+
});
|
|
145
|
+
journal("worker.started", {
|
|
146
|
+
artifact_dir: artifactDir,
|
|
147
|
+
branch,
|
|
148
|
+
run,
|
|
149
|
+
stale_claim_ms: staleClaimMs,
|
|
150
|
+
});
|
|
151
|
+
status("awaiting_assignment", { handled: 0, stale_claim_ms: staleClaimMs });
|
|
152
|
+
|
|
153
|
+
let handled = 0;
|
|
154
|
+
let stopping = false;
|
|
155
|
+
while (!stopping) {
|
|
156
|
+
const result = await handleMailboxLoopOnce(
|
|
157
|
+
{ address: branchAddress, kind: "branch", run, stateDir },
|
|
158
|
+
(message) => {
|
|
159
|
+
if (isMailboxLoopStopMessage(message)) {
|
|
160
|
+
stopping = true;
|
|
161
|
+
room("actor.leave", `${branch} stopping`, {
|
|
162
|
+
branch,
|
|
163
|
+
reason: message.type,
|
|
164
|
+
});
|
|
165
|
+
journal("worker.stopping", { id: message.id, type: message.type });
|
|
166
|
+
status("stopping", { handled, reason: message.type });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
room("task.claim", `${branch} claimed ${message.type}`, {
|
|
170
|
+
branch,
|
|
171
|
+
id: message.id,
|
|
172
|
+
type: message.type,
|
|
173
|
+
});
|
|
174
|
+
const result = text(message.body);
|
|
175
|
+
const artifact = writeResultArtifact(message.id, result);
|
|
176
|
+
handled += 1;
|
|
177
|
+
room("task.result", `${branch} handled ${message.type}`, {
|
|
178
|
+
artifact,
|
|
179
|
+
branch,
|
|
180
|
+
id: message.id,
|
|
181
|
+
result,
|
|
182
|
+
type: message.type,
|
|
183
|
+
});
|
|
184
|
+
room("awaiting_assignment", `${branch} awaiting assignment`, {
|
|
185
|
+
branch,
|
|
186
|
+
});
|
|
187
|
+
journal("task.handled", {
|
|
188
|
+
artifact,
|
|
189
|
+
id: message.id,
|
|
190
|
+
type: message.type,
|
|
191
|
+
});
|
|
192
|
+
status("awaiting_assignment", {
|
|
193
|
+
handled,
|
|
194
|
+
last_artifact: artifact,
|
|
195
|
+
last_id: message.id,
|
|
196
|
+
last_type: message.type,
|
|
197
|
+
stale_claim_ms: staleClaimMs,
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
{ owner: branchAddress },
|
|
201
|
+
);
|
|
202
|
+
if (!result.handled) await sleep(pollMs);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
journal("worker.done", { branch, handled, run });
|
|
206
|
+
status("done", { handled });
|
|
207
|
+
}
|
|
25
208
|
|
|
26
209
|
try {
|
|
27
210
|
await runActorWorker(process.argv.slice(2));
|
package/scripts/async-runner.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Detached async-runner
|
|
4
|
+
* Detached async-runner executable.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Owns the run child-process control loop directly. Reusable runtime
|
|
7
|
+
* primitives stay in lib/; this script should remain understandable without
|
|
8
|
+
* chasing a one-off lib entrypoint domain.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import { existsSync } from "node:fs";
|
|
11
|
+
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
|
11
12
|
import { dirname, join } from "node:path";
|
|
12
13
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
14
|
|
|
@@ -15,13 +16,175 @@ function packageRoot() {
|
|
|
15
16
|
return dirname(dirname(fileURLToPath(import.meta.url)));
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function
|
|
19
|
+
async function importRuntimeModule(name) {
|
|
19
20
|
const root = packageRoot();
|
|
20
|
-
const compiled = join(root, "dist", "lib",
|
|
21
|
-
|
|
21
|
+
const compiled = join(root, "dist", "lib", `${name}.js`);
|
|
22
|
+
const source = join(root, "lib", `${name}.ts`);
|
|
23
|
+
return await import(
|
|
24
|
+
pathToFileURL(existsSync(compiled) ? compiled : source).href
|
|
25
|
+
);
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
const {
|
|
28
|
+
const { appendRecipeContextToPiArgs } =
|
|
29
|
+
await importRuntimeModule("recipes-context");
|
|
30
|
+
const { execCommandTemplate } = await importRuntimeModule("command-templates");
|
|
31
|
+
const { executeRegisteredTool } = await importRuntimeModule("execution");
|
|
32
|
+
const { writeJsonAtomic } = await importRuntimeModule("file-state");
|
|
33
|
+
|
|
34
|
+
function quoteCommandDetailPart(value) {
|
|
35
|
+
if (value === "") return "''";
|
|
36
|
+
if (/^[A-Za-z0-9_/:=.,@%+\-]+$/.test(value)) return value;
|
|
37
|
+
return `'${String(value).replaceAll("'", "'\\''")}'`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function formatCommandDetail(command, args) {
|
|
41
|
+
return [command, ...args].map(quoteCommandDetailPart).join(" ");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function summarizeCommandDetail(commandDetail) {
|
|
45
|
+
return commandDetail.length > 160
|
|
46
|
+
? `${commandDetail.slice(0, 157)}...`
|
|
47
|
+
: commandDetail;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function runAsyncRunner(stateDir = process.argv[2]) {
|
|
51
|
+
if (!stateDir) throw new Error("missing state dir");
|
|
52
|
+
|
|
53
|
+
const runPath = join(stateDir, "run.json");
|
|
54
|
+
const progressPath = join(stateDir, "progress.json");
|
|
55
|
+
const resultPath = join(stateDir, "result.json");
|
|
56
|
+
const eventsPath = join(stateDir, "events.jsonl");
|
|
57
|
+
const outboxPath = join(stateDir, "outbox.jsonl");
|
|
58
|
+
const stdoutPath = join(stateDir, "stdout.log");
|
|
59
|
+
const stderrPath = join(stateDir, "stderr.log");
|
|
60
|
+
const meta = JSON.parse(readFileSync(runPath, "utf8"));
|
|
61
|
+
|
|
62
|
+
function event(name, data = {}) {
|
|
63
|
+
appendFileSync(
|
|
64
|
+
eventsPath,
|
|
65
|
+
`${JSON.stringify({ event: name, ts: new Date().toISOString(), ...data })}\n`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function outbox(name, summary, data = {}, delivery = "log", level = "info") {
|
|
70
|
+
appendFileSync(
|
|
71
|
+
outboxPath,
|
|
72
|
+
`${JSON.stringify({ body: data, data, delivery, event: name, from: `run:${meta.run}`, level, summary, to: "coordinator", ts: new Date().toISOString(), type: name })}\n`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function progress(phase, extra = {}) {
|
|
77
|
+
writeJsonAtomic(progressPath, {
|
|
78
|
+
phase,
|
|
79
|
+
updatedAt: new Date().toISOString(),
|
|
80
|
+
...extra,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let activeSubagents = 0;
|
|
85
|
+
let completedSubagents = 0;
|
|
86
|
+
const subagentFailures = [];
|
|
87
|
+
|
|
88
|
+
function getCommandDoneDelivery(result) {
|
|
89
|
+
return result.code !== 0 || activeSubagents > 0 ? "followup" : "log";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function progressRunning() {
|
|
93
|
+
progress("running", {
|
|
94
|
+
activeSubagents,
|
|
95
|
+
completed: completedSubagents,
|
|
96
|
+
failures: subagentFailures,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function observedExec(command, args, options) {
|
|
101
|
+
const commandDetail = formatCommandDetail(command, args);
|
|
102
|
+
const execArgs = appendRecipeContextToPiArgs(
|
|
103
|
+
command,
|
|
104
|
+
args,
|
|
105
|
+
meta.recipe_context_records,
|
|
106
|
+
options?.actorRecipeContext,
|
|
107
|
+
);
|
|
108
|
+
activeSubagents += 1;
|
|
109
|
+
event("command.start", { activeSubagents, command: commandDetail });
|
|
110
|
+
progressRunning();
|
|
111
|
+
const result = await execCommandTemplate(command, execArgs, options);
|
|
112
|
+
activeSubagents = Math.max(0, activeSubagents - 1);
|
|
113
|
+
completedSubagents += 1;
|
|
114
|
+
if (result.code !== 0) {
|
|
115
|
+
subagentFailures.push({
|
|
116
|
+
code: result.code,
|
|
117
|
+
command: commandDetail,
|
|
118
|
+
killed: result.killed,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
event("command.done", {
|
|
122
|
+
activeSubagents,
|
|
123
|
+
code: result.code,
|
|
124
|
+
command: commandDetail,
|
|
125
|
+
killed: result.killed,
|
|
126
|
+
});
|
|
127
|
+
outbox(
|
|
128
|
+
"command.done",
|
|
129
|
+
`Command ${summarizeCommandDetail(commandDetail)} completed with code ${result.code}`,
|
|
130
|
+
{
|
|
131
|
+
activeSubagents,
|
|
132
|
+
...(meta.artifacts ? { artifacts: meta.artifacts } : {}),
|
|
133
|
+
run_files: [stdoutPath, stderrPath, resultPath, eventsPath, outboxPath],
|
|
134
|
+
code: result.code,
|
|
135
|
+
command: commandDetail,
|
|
136
|
+
killed: result.killed,
|
|
137
|
+
},
|
|
138
|
+
getCommandDoneDelivery(result),
|
|
139
|
+
result.code === 0 ? "info" : "error",
|
|
140
|
+
);
|
|
141
|
+
progressRunning();
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
event("run.runner.start", { pid: process.pid });
|
|
147
|
+
progressRunning();
|
|
148
|
+
const result = await executeRegisteredTool(
|
|
149
|
+
{
|
|
150
|
+
name: "run_actor",
|
|
151
|
+
description: "Detached command-template run actor",
|
|
152
|
+
template: meta.template,
|
|
153
|
+
args: [],
|
|
154
|
+
defaults: {},
|
|
155
|
+
},
|
|
156
|
+
meta.values || {},
|
|
157
|
+
observedExec,
|
|
158
|
+
meta.cwd,
|
|
159
|
+
);
|
|
160
|
+
const text = result.content?.[0]?.text || "";
|
|
161
|
+
appendFileSync(stdoutPath, text);
|
|
162
|
+
writeJsonAtomic(resultPath, {
|
|
163
|
+
code: result.details.code,
|
|
164
|
+
command: result.details.command,
|
|
165
|
+
killed: result.details.killed,
|
|
166
|
+
truncated: result.details.truncated,
|
|
167
|
+
completedAt: new Date().toISOString(),
|
|
168
|
+
});
|
|
169
|
+
progress("done", {
|
|
170
|
+
completed: 1,
|
|
171
|
+
failures: result.details.nonCriticalFailures || [],
|
|
172
|
+
});
|
|
173
|
+
event("run.done", { code: result.details.code });
|
|
174
|
+
} catch (error) {
|
|
175
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
176
|
+
appendFileSync(stderrPath, `${message}\n`);
|
|
177
|
+
writeJsonAtomic(resultPath, {
|
|
178
|
+
code: 1,
|
|
179
|
+
error: message,
|
|
180
|
+
killed: false,
|
|
181
|
+
completedAt: new Date().toISOString(),
|
|
182
|
+
});
|
|
183
|
+
progress("failed", { completed: 0, failures: [{ message }] });
|
|
184
|
+
event("run.failed", { error: message });
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
25
188
|
|
|
26
189
|
try {
|
|
27
190
|
await runAsyncRunner(process.argv[2]);
|
package/scripts/build-dist.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This is intentionally standalone: it is package/build glue, not reusable
|
|
7
7
|
* actor-domain behavior. It cleans dist, compiles TypeScript, mirrors runtime
|
|
8
|
-
* assets, and syntax-checks packaged
|
|
8
|
+
* assets, and syntax-checks packaged scripts.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { spawnSync } from "node:child_process";
|
package/scripts/conformance.mjs
CHANGED
|
@@ -13,11 +13,11 @@ import { fileURLToPath } from "node:url";
|
|
|
13
13
|
|
|
14
14
|
const conformanceSuites = [
|
|
15
15
|
"tests/protocol-examples.test.ts",
|
|
16
|
-
"tests/
|
|
16
|
+
"tests/recipes-discovery.test.ts",
|
|
17
17
|
"tests/registry.test.ts",
|
|
18
|
-
"tests/runtime
|
|
18
|
+
"tests/runtime.test.ts",
|
|
19
19
|
"tests/async-runs.test.ts",
|
|
20
|
-
"tests/
|
|
20
|
+
"tests/rooms.test.ts",
|
|
21
21
|
"tests/tools.test.ts",
|
|
22
22
|
];
|
|
23
23
|
|