@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/lib/async-runner.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detached async-runner entrypoint logic.
|
|
3
|
-
* Zones: async run process, command-template execution telemetry
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { appendFileSync, readFileSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
|
|
9
|
-
import { appendRecipeContextToPiArgs } from "./actor-recipe-context.ts";
|
|
10
|
-
import { execCommandTemplate } from "./command-templates.ts";
|
|
11
|
-
import { executeRegisteredTool, type ToolExecOptions } from "./execution.ts";
|
|
12
|
-
import { writeJsonAtomic } from "./file-state.ts";
|
|
13
|
-
|
|
14
|
-
function quoteCommandDetailPart(value: string): string {
|
|
15
|
-
if (value === "") return "''";
|
|
16
|
-
if (/^[A-Za-z0-9_/:=.,@%+\-]+$/.test(value)) return value;
|
|
17
|
-
return `'${String(value).replaceAll("'", "'\\''")}'`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function formatCommandDetail(command: string, args: string[]): string {
|
|
21
|
-
return [command, ...args].map(quoteCommandDetailPart).join(" ");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function summarizeCommandDetail(commandDetail: string): string {
|
|
25
|
-
return commandDetail.length > 160
|
|
26
|
-
? `${commandDetail.slice(0, 157)}...`
|
|
27
|
-
: commandDetail;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function runAsyncRunner(stateDir = process.argv[2]): Promise<void> {
|
|
31
|
-
if (!stateDir) throw new Error("missing state dir");
|
|
32
|
-
|
|
33
|
-
const runPath = join(stateDir, "run.json");
|
|
34
|
-
const progressPath = join(stateDir, "progress.json");
|
|
35
|
-
const resultPath = join(stateDir, "result.json");
|
|
36
|
-
const eventsPath = join(stateDir, "events.jsonl");
|
|
37
|
-
const outboxPath = join(stateDir, "outbox.jsonl");
|
|
38
|
-
const stdoutPath = join(stateDir, "stdout.log");
|
|
39
|
-
const stderrPath = join(stateDir, "stderr.log");
|
|
40
|
-
const meta = JSON.parse(readFileSync(runPath, "utf8"));
|
|
41
|
-
|
|
42
|
-
function event(name: string, data: Record<string, unknown> = {}): void {
|
|
43
|
-
appendFileSync(
|
|
44
|
-
eventsPath,
|
|
45
|
-
`${JSON.stringify({ event: name, ts: new Date().toISOString(), ...data })}\n`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function outbox(
|
|
50
|
-
name: string,
|
|
51
|
-
summary: string,
|
|
52
|
-
data: Record<string, unknown> = {},
|
|
53
|
-
delivery = "log",
|
|
54
|
-
level = "info",
|
|
55
|
-
): void {
|
|
56
|
-
appendFileSync(
|
|
57
|
-
outboxPath,
|
|
58
|
-
`${JSON.stringify({ body: data, data, delivery, event: name, from: `run:${meta.run}`, level, summary, to: "coordinator", ts: new Date().toISOString(), type: name })}\n`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function progress(phase: string, extra: Record<string, unknown> = {}): void {
|
|
63
|
-
writeJsonAtomic(progressPath, {
|
|
64
|
-
phase,
|
|
65
|
-
updatedAt: new Date().toISOString(),
|
|
66
|
-
...extra,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let activeSubagents = 0;
|
|
71
|
-
let completedSubagents = 0;
|
|
72
|
-
const subagentFailures: Record<string, unknown>[] = [];
|
|
73
|
-
|
|
74
|
-
function getCommandDoneDelivery(result: { code: number }): string {
|
|
75
|
-
return result.code !== 0 || activeSubagents > 0 ? "followup" : "log";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function progressRunning(): void {
|
|
79
|
-
progress("running", {
|
|
80
|
-
activeSubagents,
|
|
81
|
-
completed: completedSubagents,
|
|
82
|
-
failures: subagentFailures,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function observedExec(command: string, args: string[], options?: ToolExecOptions) {
|
|
87
|
-
const commandDetail = formatCommandDetail(command, args);
|
|
88
|
-
const execArgs = appendRecipeContextToPiArgs(
|
|
89
|
-
command,
|
|
90
|
-
args,
|
|
91
|
-
meta.recipe_context_records,
|
|
92
|
-
options?.actorRecipeContext,
|
|
93
|
-
);
|
|
94
|
-
activeSubagents += 1;
|
|
95
|
-
event("command.start", { activeSubagents, command: commandDetail });
|
|
96
|
-
progressRunning();
|
|
97
|
-
const result = await execCommandTemplate(command, execArgs, options);
|
|
98
|
-
activeSubagents = Math.max(0, activeSubagents - 1);
|
|
99
|
-
completedSubagents += 1;
|
|
100
|
-
if (result.code !== 0) {
|
|
101
|
-
subagentFailures.push({
|
|
102
|
-
code: result.code,
|
|
103
|
-
command: commandDetail,
|
|
104
|
-
killed: result.killed,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
event("command.done", {
|
|
108
|
-
activeSubagents,
|
|
109
|
-
code: result.code,
|
|
110
|
-
command: commandDetail,
|
|
111
|
-
killed: result.killed,
|
|
112
|
-
});
|
|
113
|
-
outbox(
|
|
114
|
-
"command.done",
|
|
115
|
-
`Command ${summarizeCommandDetail(commandDetail)} completed with code ${result.code}`,
|
|
116
|
-
{
|
|
117
|
-
activeSubagents,
|
|
118
|
-
...(meta.artifacts ? { artifacts: meta.artifacts } : {}),
|
|
119
|
-
run_files: [stdoutPath, stderrPath, resultPath, eventsPath, outboxPath],
|
|
120
|
-
code: result.code,
|
|
121
|
-
command: commandDetail,
|
|
122
|
-
killed: result.killed,
|
|
123
|
-
},
|
|
124
|
-
getCommandDoneDelivery(result),
|
|
125
|
-
result.code === 0 ? "info" : "error",
|
|
126
|
-
);
|
|
127
|
-
progressRunning();
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
event("run.runner.start", { pid: process.pid });
|
|
133
|
-
progressRunning();
|
|
134
|
-
const result = await executeRegisteredTool(
|
|
135
|
-
{
|
|
136
|
-
name: "run_actor",
|
|
137
|
-
description: "Detached command-template run actor",
|
|
138
|
-
template: meta.template,
|
|
139
|
-
args: [],
|
|
140
|
-
defaults: {},
|
|
141
|
-
},
|
|
142
|
-
meta.values || {},
|
|
143
|
-
observedExec,
|
|
144
|
-
meta.cwd,
|
|
145
|
-
);
|
|
146
|
-
const text = result.content?.[0]?.text || "";
|
|
147
|
-
appendFileSync(stdoutPath, text);
|
|
148
|
-
writeJsonAtomic(resultPath, {
|
|
149
|
-
code: result.details.code,
|
|
150
|
-
command: result.details.command,
|
|
151
|
-
killed: result.details.killed,
|
|
152
|
-
truncated: result.details.truncated,
|
|
153
|
-
completedAt: new Date().toISOString(),
|
|
154
|
-
});
|
|
155
|
-
progress("done", {
|
|
156
|
-
completed: 1,
|
|
157
|
-
failures: result.details.nonCriticalFailures || [],
|
|
158
|
-
});
|
|
159
|
-
event("run.done", { code: result.details.code });
|
|
160
|
-
} catch (error) {
|
|
161
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
162
|
-
appendFileSync(stderrPath, `${message}\n`);
|
|
163
|
-
writeJsonAtomic(resultPath, {
|
|
164
|
-
code: 1,
|
|
165
|
-
error: message,
|
|
166
|
-
killed: false,
|
|
167
|
-
completedAt: new Date().toISOString(),
|
|
168
|
-
});
|
|
169
|
-
progress("failed", { completed: 0, failures: [{ message }] });
|
|
170
|
-
event("run.failed", { error: message });
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
}
|