@llblab/pi-actors 0.32.0 → 0.34.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.
- package/AGENTS.md +23 -11
- package/BACKLOG.md +2 -30
- package/CHANGELOG.md +30 -1
- 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/paths.d.ts +1 -1
- package/dist/lib/paths.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} +9 -9
- package/dist/lib/{recipe-discovery.js → recipes-discovery.js} +17 -17
- 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 +346 -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 +13 -39
- package/dist/lib/tools.js +11 -1497
- package/dist/recipes/utility-coordinator-lock-snapshot.json +1 -1
- package/dist/scripts/actor-worker.mjs +186 -7
- package/dist/scripts/async-runner.mjs +171 -8
- package/dist/scripts/build-dist.mjs +1 -1
- package/dist/scripts/conformance.mjs +34 -18
- 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 +2 -2
- package/dist/skills/swarm/SKILL.md +2 -2
- package/docs/recipe-library.md +1 -1
- package/docs/template-recipes.md +1 -1
- package/docs/tool-registry.md +3 -3
- package/index.ts +12 -19
- 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/paths.ts +3 -3
- package/lib/{actor-recipe-context.ts → recipes-context.ts} +3 -2
- package/lib/{recipe-discovery.ts → recipes-discovery.ts} +30 -30
- 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 +483 -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 +26 -2051
- package/package.json +1 -1
- package/recipes/utility-coordinator-lock-snapshot.json +1 -1
- package/scripts/actor-worker.mjs +186 -7
- package/scripts/async-runner.mjs +171 -8
- package/scripts/build-dist.mjs +1 -1
- package/scripts/conformance.mjs +34 -18
- 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 +2 -2
- package/skills/swarm/SKILL.md +2 -2
- 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/conformance.d.ts +0 -12
- package/dist/lib/conformance.js +0 -28
- 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/conformance.ts +0 -46
- 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/runtime.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { existsSync, watch, type FSWatcher } from "node:fs";
|
|
|
9
9
|
import * as Config from "./config.ts";
|
|
10
10
|
import type { RegisteredToolExec } from "./execution.ts";
|
|
11
11
|
import * as Paths from "./paths.ts";
|
|
12
|
-
import * as
|
|
13
|
-
import * as
|
|
12
|
+
import * as RecipesDiscovery from "./recipes-discovery.ts";
|
|
13
|
+
import * as ToolsLocal from "./tools-local.ts";
|
|
14
14
|
|
|
15
15
|
export interface RuntimeContext {
|
|
16
16
|
hasUI: boolean;
|
|
@@ -31,7 +31,7 @@ export interface ToolRegistryRuntimeDeps {
|
|
|
31
31
|
getActiveTools?: () => string[];
|
|
32
32
|
getAllTools: () => ToolInfoLike[];
|
|
33
33
|
registerTool: (
|
|
34
|
-
definition: ReturnType<typeof
|
|
34
|
+
definition: ReturnType<typeof ToolsLocal.createRuntimeToolDefinition>,
|
|
35
35
|
) => void;
|
|
36
36
|
reservedToolNames: Set<string>;
|
|
37
37
|
setActiveTools?: (toolNames: string[]) => void;
|
|
@@ -100,7 +100,7 @@ export function createAutoToolsRuntime(
|
|
|
100
100
|
function registerRuntimeTool(cfg: Config.RegisteredTool) {
|
|
101
101
|
const fingerprint = getToolFingerprint(cfg);
|
|
102
102
|
if (runtimeToolFingerprints.get(cfg.name) === fingerprint) return;
|
|
103
|
-
deps.registerTool(
|
|
103
|
+
deps.registerTool(ToolsLocal.createRuntimeToolDefinition(cfg, deps.exec));
|
|
104
104
|
runtimeTools.add(cfg.name);
|
|
105
105
|
runtimeToolFingerprints.set(cfg.name, fingerprint);
|
|
106
106
|
}
|
|
@@ -148,7 +148,7 @@ export function createAutoToolsRuntime(
|
|
|
148
148
|
const recipeRoot = deps.recipeRoot ?? Paths.getRecipeRoot();
|
|
149
149
|
const packagedRecipeRoot =
|
|
150
150
|
deps.packagedRecipeRoot ?? Paths.getPackagedRecipeRoot();
|
|
151
|
-
const discovered =
|
|
151
|
+
const discovered = RecipesDiscovery.discoverRecipeSources([
|
|
152
152
|
{ root: recipeRoot, defaultTool: true, mutableUsage: true },
|
|
153
153
|
{ root: packagedRecipeRoot },
|
|
154
154
|
]);
|
|
@@ -156,7 +156,7 @@ export function createAutoToolsRuntime(
|
|
|
156
156
|
tools.clear();
|
|
157
157
|
for (const entry of discovered.active.values()) {
|
|
158
158
|
try {
|
|
159
|
-
const cfg =
|
|
159
|
+
const cfg = RecipesDiscovery.toRegisteredTool(entry);
|
|
160
160
|
if (cfg) tools.set(cfg.name, cfg);
|
|
161
161
|
} catch (error) {
|
|
162
162
|
warnings.push(
|
package/lib/schema.ts
CHANGED
|
@@ -30,6 +30,61 @@ export interface ToolArgSpec {
|
|
|
30
30
|
error?: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export type JsonSchema = Record<string, unknown>;
|
|
34
|
+
|
|
35
|
+
export function stringSchema(description: string): JsonSchema {
|
|
36
|
+
return { description, type: "string" };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function typedArgSchema(
|
|
40
|
+
description: string,
|
|
41
|
+
type: ToolArgType | undefined,
|
|
42
|
+
): JsonSchema {
|
|
43
|
+
if (!type) return stringSchema(description);
|
|
44
|
+
switch (type.kind) {
|
|
45
|
+
case "int":
|
|
46
|
+
return { description, type: "integer" };
|
|
47
|
+
case "number":
|
|
48
|
+
return { description, type: "number" };
|
|
49
|
+
case "bool":
|
|
50
|
+
return { description, type: "boolean" };
|
|
51
|
+
case "array":
|
|
52
|
+
return { description, items: {}, type: "array" };
|
|
53
|
+
case "enum":
|
|
54
|
+
return { description, enum: type.values, type: "string" };
|
|
55
|
+
case "path":
|
|
56
|
+
case "string":
|
|
57
|
+
return stringSchema(description);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function booleanSchema(description: string): JsonSchema {
|
|
62
|
+
return { description, type: "boolean" };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function nullSchema(description: string): JsonSchema {
|
|
66
|
+
return { description, type: "null" };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function arraySchema(description: string): JsonSchema {
|
|
70
|
+
return { description, items: {}, type: "array" };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function unionSchema(anyOf: JsonSchema[]): JsonSchema {
|
|
74
|
+
return { anyOf };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function objectSchema(
|
|
78
|
+
properties: Record<string, JsonSchema>,
|
|
79
|
+
required: string[] = [],
|
|
80
|
+
): JsonSchema {
|
|
81
|
+
return { additionalProperties: false, properties, required, type: "object" };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function looseObjectSchema(description: string): JsonSchema {
|
|
85
|
+
return { additionalProperties: true, description, type: "object" };
|
|
86
|
+
}
|
|
87
|
+
|
|
33
88
|
function mergeUnique(items: string[]): string[] {
|
|
34
89
|
return [...new Set(items.filter(Boolean))];
|
|
35
90
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public tool access and ownership checks
|
|
3
|
+
* Zones: session ownership, run visibility guards, tool authorization errors
|
|
4
|
+
* Owns consistent session-mismatch diagnostics for public tool execution paths
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as AsyncRuns from "./async-runs.ts";
|
|
8
|
+
|
|
9
|
+
export interface SessionContext {
|
|
10
|
+
sessionManager?: { getSessionId?: () => string };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getContextSessionId(ctx: unknown): string | undefined {
|
|
14
|
+
return (ctx as SessionContext | undefined)?.sessionManager?.getSessionId?.();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function requireContextSessionId(ctx: unknown, actor: string): string {
|
|
18
|
+
const sessionId = getContextSessionId(ctx);
|
|
19
|
+
if (!sessionId) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`${actor} requires a current coordinator session; use session:<id> or session:all for explicit session inventory.`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return sessionId;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function sessionMismatchError(input: {
|
|
28
|
+
currentSession?: string;
|
|
29
|
+
expectedSession?: string;
|
|
30
|
+
run?: string;
|
|
31
|
+
target?: string;
|
|
32
|
+
}): Error {
|
|
33
|
+
const ownerSession = input.expectedSession ?? "none";
|
|
34
|
+
const currentSession = input.currentSession ?? "none";
|
|
35
|
+
const actor = input.run ? `run:${input.run}` : (input.target ?? "session");
|
|
36
|
+
const hintTarget = input.expectedSession
|
|
37
|
+
? `session:${input.expectedSession}`
|
|
38
|
+
: "session:all";
|
|
39
|
+
return Object.assign(
|
|
40
|
+
new Error(
|
|
41
|
+
`${actor} reason=session_mismatch owner_session=${ownerSession} current_session=${currentSession} hint=inspect_session:${input.expectedSession ?? "all"}`,
|
|
42
|
+
),
|
|
43
|
+
{
|
|
44
|
+
current_session: input.currentSession,
|
|
45
|
+
hint: `inspect target=${hintTarget} view=status`,
|
|
46
|
+
owner_session: input.expectedSession,
|
|
47
|
+
reason: "session_mismatch",
|
|
48
|
+
run: input.run,
|
|
49
|
+
target: input.target,
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function assertRunAccessibleToContext(
|
|
55
|
+
runId: string,
|
|
56
|
+
ctx: unknown,
|
|
57
|
+
): Record<string, unknown> {
|
|
58
|
+
const status = AsyncRuns.getRunStatus(runId);
|
|
59
|
+
const sessionId = getContextSessionId(ctx);
|
|
60
|
+
if (sessionId && status.ownerId && status.ownerId !== sessionId) {
|
|
61
|
+
throw sessionMismatchError({
|
|
62
|
+
currentSession: sessionId,
|
|
63
|
+
expectedSession: String(status.ownerId),
|
|
64
|
+
run: runId,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return status;
|
|
68
|
+
}
|