@chances-ai/engine 27.0.0 → 29.0.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/dist/agents/bundled.d.ts +5 -0
- package/dist/agents/bundled.d.ts.map +1 -0
- package/dist/agents/bundled.js +66 -0
- package/dist/agents/bundled.js.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/parse.d.ts +3 -0
- package/dist/agents/parse.d.ts.map +1 -1
- package/dist/agents/parse.js +17 -0
- package/dist/agents/parse.js.map +1 -1
- package/dist/agents/types.d.ts +8 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/ai/adapters/ai-sdk-stream.js +15 -0
- package/dist/ai/adapters/ai-sdk-stream.js.map +1 -1
- package/dist/ai/types.d.ts +12 -0
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/core/coordinator-mode.d.ts +32 -0
- package/dist/core/coordinator-mode.d.ts.map +1 -0
- package/dist/core/coordinator-mode.js +98 -0
- package/dist/core/coordinator-mode.js.map +1 -0
- package/dist/core/coordinator-tools.d.ts +22 -0
- package/dist/core/coordinator-tools.d.ts.map +1 -0
- package/dist/core/coordinator-tools.js +262 -0
- package/dist/core/coordinator-tools.js.map +1 -0
- package/dist/core/engine.d.ts +50 -6
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +107 -17
- package/dist/core/engine.js.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/task-tool.d.ts +85 -1
- package/dist/core/task-tool.d.ts.map +1 -1
- package/dist/core/task-tool.js +456 -500
- package/dist/core/task-tool.js.map +1 -1
- package/dist/hashline/apply.d.ts +9 -0
- package/dist/hashline/apply.d.ts.map +1 -0
- package/dist/hashline/apply.js +523 -0
- package/dist/hashline/apply.js.map +1 -0
- package/dist/hashline/block.d.ts +25 -0
- package/dist/hashline/block.d.ts.map +1 -0
- package/dist/hashline/block.js +71 -0
- package/dist/hashline/block.js.map +1 -0
- package/dist/hashline/format.d.ts +106 -0
- package/dist/hashline/format.d.ts.map +1 -0
- package/dist/hashline/format.js +191 -0
- package/dist/hashline/format.js.map +1 -0
- package/dist/hashline/fs.d.ts +87 -0
- package/dist/hashline/fs.d.ts.map +1 -0
- package/dist/hashline/fs.js +123 -0
- package/dist/hashline/fs.js.map +1 -0
- package/dist/hashline/index.d.ts +27 -0
- package/dist/hashline/index.d.ts.map +1 -0
- package/dist/hashline/index.js +27 -0
- package/dist/hashline/index.js.map +1 -0
- package/dist/hashline/input.d.ts +101 -0
- package/dist/hashline/input.d.ts.map +1 -0
- package/dist/hashline/input.js +378 -0
- package/dist/hashline/input.js.map +1 -0
- package/dist/hashline/messages.d.ts +87 -0
- package/dist/hashline/messages.d.ts.map +1 -0
- package/dist/hashline/messages.js +94 -0
- package/dist/hashline/messages.js.map +1 -0
- package/dist/hashline/mismatch.d.ts +45 -0
- package/dist/hashline/mismatch.d.ts.map +1 -0
- package/dist/hashline/mismatch.js +118 -0
- package/dist/hashline/mismatch.js.map +1 -0
- package/dist/hashline/normalize.d.ts +22 -0
- package/dist/hashline/normalize.d.ts.map +1 -0
- package/dist/hashline/normalize.js +31 -0
- package/dist/hashline/normalize.js.map +1 -0
- package/dist/hashline/parser.d.ts +24 -0
- package/dist/hashline/parser.d.ts.map +1 -0
- package/dist/hashline/parser.js +295 -0
- package/dist/hashline/parser.js.map +1 -0
- package/dist/hashline/patcher.d.ts +111 -0
- package/dist/hashline/patcher.d.ts.map +1 -0
- package/dist/hashline/patcher.js +332 -0
- package/dist/hashline/patcher.js.map +1 -0
- package/dist/hashline/recovery.d.ts +41 -0
- package/dist/hashline/recovery.d.ts.map +1 -0
- package/dist/hashline/recovery.js +175 -0
- package/dist/hashline/recovery.js.map +1 -0
- package/dist/hashline/snapshots.d.ts +62 -0
- package/dist/hashline/snapshots.d.ts.map +1 -0
- package/dist/hashline/snapshots.js +127 -0
- package/dist/hashline/snapshots.js.map +1 -0
- package/dist/hashline/tokenizer.d.ts +66 -0
- package/dist/hashline/tokenizer.d.ts.map +1 -0
- package/dist/hashline/tokenizer.js +408 -0
- package/dist/hashline/tokenizer.js.map +1 -0
- package/dist/hashline/types.d.ts +117 -0
- package/dist/hashline/types.d.ts.map +1 -0
- package/dist/hashline/types.js +13 -0
- package/dist/hashline/types.js.map +1 -0
- package/dist/tools/builtins/_hashline-fs.d.ts +16 -0
- package/dist/tools/builtins/_hashline-fs.d.ts.map +1 -0
- package/dist/tools/builtins/_hashline-fs.js +62 -0
- package/dist/tools/builtins/_hashline-fs.js.map +1 -0
- package/dist/tools/builtins/_image.d.ts +26 -0
- package/dist/tools/builtins/_image.d.ts.map +1 -0
- package/dist/tools/builtins/_image.js +76 -0
- package/dist/tools/builtins/_image.js.map +1 -0
- package/dist/tools/builtins/_login-shell.d.ts +17 -0
- package/dist/tools/builtins/_login-shell.d.ts.map +1 -0
- package/dist/tools/builtins/_login-shell.js +66 -0
- package/dist/tools/builtins/_login-shell.js.map +1 -0
- package/dist/tools/builtins/_notebook.d.ts +15 -0
- package/dist/tools/builtins/_notebook.d.ts.map +1 -0
- package/dist/tools/builtins/_notebook.js +81 -0
- package/dist/tools/builtins/_notebook.js.map +1 -0
- package/dist/tools/builtins/_pdf.d.ts +19 -0
- package/dist/tools/builtins/_pdf.d.ts.map +1 -0
- package/dist/tools/builtins/_pdf.js +42 -0
- package/dist/tools/builtins/_pdf.js.map +1 -0
- package/dist/tools/builtins/_shared.d.ts +11 -0
- package/dist/tools/builtins/_shared.d.ts.map +1 -1
- package/dist/tools/builtins/_shared.js +40 -1
- package/dist/tools/builtins/_shared.js.map +1 -1
- package/dist/tools/builtins/ast-edit.d.ts +18 -0
- package/dist/tools/builtins/ast-edit.d.ts.map +1 -0
- package/dist/tools/builtins/ast-edit.js +109 -0
- package/dist/tools/builtins/ast-edit.js.map +1 -0
- package/dist/tools/builtins/ast-grep.d.ts +6 -0
- package/dist/tools/builtins/ast-grep.d.ts.map +1 -0
- package/dist/tools/builtins/ast-grep.js +67 -0
- package/dist/tools/builtins/ast-grep.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +13 -2
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +112 -31
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/read.d.ts.map +1 -1
- package/dist/tools/builtins/read.js +187 -11
- package/dist/tools/builtins/read.js.map +1 -1
- package/dist/tools/builtins.d.ts.map +1 -1
- package/dist/tools/builtins.js +4 -0
- package/dist/tools/builtins.js.map +1 -1
- package/dist/tools/file-lock.d.ts +8 -0
- package/dist/tools/file-lock.d.ts.map +1 -1
- package/dist/tools/file-lock.js +22 -0
- package/dist/tools/file-lock.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.ts +26 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { AppError, ErrorCode } from "@chances-ai/runtime";
|
|
2
|
+
import { DEFAULT_MAX_TURNS } from "./engine.js";
|
|
3
|
+
import { CREATE_TEAM_TOOL_NAME, DISMISS_WORKER_TOOL_NAME, LIST_WORKERS_TOOL_NAME, SEND_MESSAGE_TOOL_NAME, SPAWN_WORKER_TOOL_NAME, STOP_WORKER_TOOL_NAME, createChildAgentRuntime, } from "./task-tool.js";
|
|
4
|
+
/** Upper bound on a worker child's `maxTurns` — matches the one-shot `task`
|
|
5
|
+
* tool's `CHILD_MAX_TURNS_CEILING` so a worker can't wedge for hours. */
|
|
6
|
+
const WORKER_MAX_TURNS_CEILING = 50;
|
|
7
|
+
function strArg(args, key, required) {
|
|
8
|
+
const v = args[key];
|
|
9
|
+
if (v === undefined || v === null) {
|
|
10
|
+
if (required)
|
|
11
|
+
throw new AppError(ErrorCode.Tool, `Expected string arg "${key}"`);
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (typeof v !== "string") {
|
|
15
|
+
throw new AppError(ErrorCode.Tool, `Expected string arg "${key}"`);
|
|
16
|
+
}
|
|
17
|
+
return v;
|
|
18
|
+
}
|
|
19
|
+
/** A `to` target of the form `team:<id>` → the team id, else null. */
|
|
20
|
+
function teamTarget(to) {
|
|
21
|
+
return to.startsWith("team:") ? to.slice("team:".length) : null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* (7.8 §3.2) Build the coordinator's orchestration tool set:
|
|
25
|
+
* `spawn_worker` / `send_message` / `stop_worker` / `create_team` /
|
|
26
|
+
* `list_workers`. Registered on the COORDINATOR's main engine ONLY (coordinator
|
|
27
|
+
* mode) — a normal session never sees them, and the one-shot `task` stays the
|
|
28
|
+
* simple-delegation default. All orchestration ops are `isConcurrencySafe:false`
|
|
29
|
+
* (stateful side effects); only `list_workers` is read-only/parallel-safe.
|
|
30
|
+
*/
|
|
31
|
+
export function createCoordinatorTools(deps) {
|
|
32
|
+
const reg = deps.workerRegistry;
|
|
33
|
+
const childMaxTurns = Math.min(Math.max(1, deps.maxTurns ?? DEFAULT_MAX_TURNS), WORKER_MAX_TURNS_CEILING);
|
|
34
|
+
const spawnWorker = {
|
|
35
|
+
name: SPAWN_WORKER_TOOL_NAME,
|
|
36
|
+
description: "Spawn a PERSISTENT worker (a child agent that stays alive so you can continue it with send_message, reusing its context). Unlike the one-shot `task` tool, the worker does not die after one reply — direct it to research/implement/verify, then `send_message` it follow-up work or `stop_worker` it if it goes the wrong way. Returns an agent_id you address it by. The worker has full tool access (it does the editing); YOU only direct.",
|
|
37
|
+
category: "integration",
|
|
38
|
+
parameters: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
description: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Short label (1–3 words) for this worker. Shown in the permission prompt and the worker panel.",
|
|
44
|
+
},
|
|
45
|
+
prompt: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "The worker's first instruction. Make it self-contained — include specific file paths, line numbers, and exactly what to do (you must understand the work before delegating it).",
|
|
48
|
+
},
|
|
49
|
+
subagent_type: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Optional persona from the agent catalog. Omit for a full-inheritance worker.",
|
|
52
|
+
},
|
|
53
|
+
team: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Optional team id (from create_team) to group this worker under, for broadcast / batch-stop.",
|
|
56
|
+
},
|
|
57
|
+
isolation: {
|
|
58
|
+
type: "string",
|
|
59
|
+
enum: ["worktree", "none"],
|
|
60
|
+
description: "'worktree' runs the worker in an isolated git worktree; 'none' (default) shares the working tree.",
|
|
61
|
+
},
|
|
62
|
+
context: {
|
|
63
|
+
type: "string",
|
|
64
|
+
enum: ["fork", "fresh"],
|
|
65
|
+
description: "'fresh' (default) = empty context. 'fork' = inherit a copy of THIS conversation's completed turns as background.",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
required: ["prompt"],
|
|
69
|
+
},
|
|
70
|
+
isConcurrencySafe: () => false,
|
|
71
|
+
summarize: (args) => {
|
|
72
|
+
const prompt = strArg(args, "prompt", true);
|
|
73
|
+
const desc = strArg(args, "description", false);
|
|
74
|
+
const head = prompt.length > 80 ? prompt.slice(0, 80) + "…" : prompt;
|
|
75
|
+
return `spawn_worker${desc ? `[${desc}]` : ""}: ${head}`;
|
|
76
|
+
},
|
|
77
|
+
async execute(args, ctx) {
|
|
78
|
+
const prompt = strArg(args, "prompt", true);
|
|
79
|
+
const team = strArg(args, "team", false);
|
|
80
|
+
if (team !== undefined && !reg.hasTeam(team)) {
|
|
81
|
+
return { ok: false, output: `Unknown team '${team}'. Create it first with create_team.` };
|
|
82
|
+
}
|
|
83
|
+
const built = await createChildAgentRuntime(deps, {
|
|
84
|
+
prompt,
|
|
85
|
+
subagentType: strArg(args, "subagent_type", false),
|
|
86
|
+
isolation: strArg(args, "isolation", false),
|
|
87
|
+
context: strArg(args, "context", false),
|
|
88
|
+
}, childMaxTurns, ctx.signal);
|
|
89
|
+
if (!built.ok)
|
|
90
|
+
return { ok: false, output: built.output };
|
|
91
|
+
try {
|
|
92
|
+
const { agentId } = reg.spawn({
|
|
93
|
+
teamId: team,
|
|
94
|
+
firstPrompt: built.firstPrompt,
|
|
95
|
+
runtime: built.runtime,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
ok: true,
|
|
99
|
+
output: [
|
|
100
|
+
`(worker spawned) agent_id=${agentId} name=${built.runtime.agentName}${team ? ` team=${team}` : ""}`,
|
|
101
|
+
"Continue it with send_message(to: \"" + agentId + "\", message: …); stop it with stop_worker. You will get its result as a <task-notification> on a future turn.",
|
|
102
|
+
].join("\n"),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
// Capacity refusal etc. → AppError(Tool) folded to ok:false.
|
|
107
|
+
if (e instanceof AppError) {
|
|
108
|
+
// worktree was created inside createChildAgentRuntime; close-on-failure
|
|
109
|
+
// happens via finalize() at the registry's next teardown — but since
|
|
110
|
+
// spawn never registered the worker, finalize the runtime now.
|
|
111
|
+
await built.runtime.finalize().catch(() => { });
|
|
112
|
+
await built.runtime.drainPty().catch(() => { });
|
|
113
|
+
return { ok: false, output: e.message };
|
|
114
|
+
}
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const sendMessage = {
|
|
120
|
+
name: SEND_MESSAGE_TOOL_NAME,
|
|
121
|
+
description: "Send a follow-up instruction to a live worker, CONTINUING it on its existing context (it remembers what it already read/did). `to` is an agent_id, a worker name, or `team:<id>` to broadcast to every worker in a team. If the worker is busy the message queues (FIFO); if it's idle/stopped it resumes. Synthesize the worker's prior findings into a concrete spec before sending — never delegate understanding back to it.",
|
|
122
|
+
category: "integration",
|
|
123
|
+
parameters: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
to: { type: "string", description: "agent_id, worker name, or 'team:<id>' to broadcast." },
|
|
127
|
+
message: { type: "string", description: "The follow-up instruction (self-contained, with specifics)." },
|
|
128
|
+
},
|
|
129
|
+
required: ["to", "message"],
|
|
130
|
+
},
|
|
131
|
+
isConcurrencySafe: () => false,
|
|
132
|
+
summarize: (args) => {
|
|
133
|
+
const to = strArg(args, "to", true);
|
|
134
|
+
const msg = strArg(args, "message", true);
|
|
135
|
+
const head = msg.length > 60 ? msg.slice(0, 60) + "…" : msg;
|
|
136
|
+
return `send_message → ${to}: ${head}`;
|
|
137
|
+
},
|
|
138
|
+
async execute(args) {
|
|
139
|
+
const to = strArg(args, "to", true);
|
|
140
|
+
const message = strArg(args, "message", true);
|
|
141
|
+
const team = teamTarget(to);
|
|
142
|
+
if (team !== null) {
|
|
143
|
+
if (!reg.hasTeam(team))
|
|
144
|
+
return { ok: false, output: `Unknown team '${team}'.` };
|
|
145
|
+
const n = reg.broadcast(team, message);
|
|
146
|
+
return { ok: true, output: `Broadcast to ${n} worker(s) in team ${team}.` };
|
|
147
|
+
}
|
|
148
|
+
const delivered = reg.send(to, message);
|
|
149
|
+
if (!delivered) {
|
|
150
|
+
return {
|
|
151
|
+
ok: false,
|
|
152
|
+
output: `No live worker matches '${to}' (it may have been stopped-and-evicted or never existed). Use list_workers, or spawn_worker a fresh one.`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return { ok: true, output: `Message queued for worker ${to}.` };
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const stopWorker = {
|
|
159
|
+
name: STOP_WORKER_TOOL_NAME,
|
|
160
|
+
description: "Stop a worker that's going the wrong way: cancels its in-flight work but KEEPS it resumable (a later send_message continues it on the same context). `to` is an agent_id, a worker name, or `team:<id>` to stop every worker in a team.",
|
|
161
|
+
category: "integration",
|
|
162
|
+
parameters: {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
to: { type: "string", description: "agent_id, worker name, or 'team:<id>'." },
|
|
166
|
+
},
|
|
167
|
+
required: ["to"],
|
|
168
|
+
},
|
|
169
|
+
isConcurrencySafe: () => false,
|
|
170
|
+
summarize: (args) => `stop_worker → ${strArg(args, "to", true)}`,
|
|
171
|
+
async execute(args) {
|
|
172
|
+
const to = strArg(args, "to", true);
|
|
173
|
+
const team = teamTarget(to);
|
|
174
|
+
if (team !== null) {
|
|
175
|
+
if (!reg.hasTeam(team))
|
|
176
|
+
return { ok: false, output: `Unknown team '${team}'.` };
|
|
177
|
+
const n = reg.stopTeam(team);
|
|
178
|
+
return { ok: true, output: `Stopped ${n} worker(s) in team ${team}.` };
|
|
179
|
+
}
|
|
180
|
+
const stopped = reg.stop(to);
|
|
181
|
+
if (!stopped)
|
|
182
|
+
return { ok: false, output: `No live worker matches '${to}'.` };
|
|
183
|
+
return { ok: true, output: `Stopped worker ${to} (resumable with send_message).` };
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
const dismissWorker = {
|
|
187
|
+
name: DISMISS_WORKER_TOOL_NAME,
|
|
188
|
+
description: "Permanently dismiss a worker you are DONE with — it is closed (its worktree/PTY finalized) and its capacity slot is freed immediately. Unlike stop_worker (which keeps the worker resumable), a dismissed worker cannot be continued. Use this to reclaim a slot when you hit the worker capacity limit and no longer need a finished worker. `to` is an agent_id, a worker name, or `team:<id>` to dismiss every worker in a team.",
|
|
189
|
+
category: "integration",
|
|
190
|
+
parameters: {
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: {
|
|
193
|
+
to: { type: "string", description: "agent_id, worker name, or 'team:<id>'." },
|
|
194
|
+
},
|
|
195
|
+
required: ["to"],
|
|
196
|
+
},
|
|
197
|
+
isConcurrencySafe: () => false,
|
|
198
|
+
summarize: (args) => `dismiss_worker → ${strArg(args, "to", true)}`,
|
|
199
|
+
async execute(args) {
|
|
200
|
+
const to = strArg(args, "to", true);
|
|
201
|
+
const team = teamTarget(to);
|
|
202
|
+
if (team !== null) {
|
|
203
|
+
if (!reg.hasTeam(team))
|
|
204
|
+
return { ok: false, output: `Unknown team '${team}'.` };
|
|
205
|
+
const n = await reg.dismissTeam(team);
|
|
206
|
+
return { ok: true, output: `Dismissed ${n} worker(s) in team ${team} (slots freed).` };
|
|
207
|
+
}
|
|
208
|
+
// Resolve a name → agentId so a name target works (close() is by agentId).
|
|
209
|
+
const match = reg.listWorkers().find((w) => w.agentId === to || w.name === to);
|
|
210
|
+
const dismissed = match ? await reg.close(match.agentId) : false;
|
|
211
|
+
if (!dismissed)
|
|
212
|
+
return { ok: false, output: `No live worker matches '${to}'.` };
|
|
213
|
+
return { ok: true, output: `Dismissed worker ${to} (slot freed; not resumable).` };
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
const createTeam = {
|
|
217
|
+
name: CREATE_TEAM_TOOL_NAME,
|
|
218
|
+
description: "Create a team to group related workers. Returns a team_id; pass it as spawn_worker's `team`, then send_message/stop_worker with `to: \"team:<id>\"` to broadcast / batch-stop.",
|
|
219
|
+
category: "integration",
|
|
220
|
+
parameters: {
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
name: { type: "string", description: "Human-readable team label." },
|
|
224
|
+
},
|
|
225
|
+
required: ["name"],
|
|
226
|
+
},
|
|
227
|
+
isConcurrencySafe: () => false,
|
|
228
|
+
summarize: (args) => `create_team: ${strArg(args, "name", true)}`,
|
|
229
|
+
async execute(args) {
|
|
230
|
+
const name = strArg(args, "name", true);
|
|
231
|
+
const { teamId } = reg.createTeam(name);
|
|
232
|
+
return { ok: true, output: `(team created) team_id=${teamId} name=${name}` };
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
const listWorkers = {
|
|
236
|
+
name: LIST_WORKERS_TOOL_NAME,
|
|
237
|
+
description: "List your live workers and their status (running / idle / stopped / failed), optionally filtered by team. Use it to see what's in flight before directing more work.",
|
|
238
|
+
category: "file-read",
|
|
239
|
+
parameters: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
team: { type: "string", description: "Optional team id to filter by." },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
isConcurrencySafe: () => true,
|
|
246
|
+
summarize: (args) => {
|
|
247
|
+
const team = strArg(args, "team", false);
|
|
248
|
+
return team ? `list_workers (team ${team})` : "list_workers";
|
|
249
|
+
},
|
|
250
|
+
async execute(args) {
|
|
251
|
+
const team = strArg(args, "team", false);
|
|
252
|
+
const workers = reg.listWorkers(team);
|
|
253
|
+
if (workers.length === 0) {
|
|
254
|
+
return { ok: true, output: team ? `No workers in team ${team}.` : "No live workers." };
|
|
255
|
+
}
|
|
256
|
+
const lines = workers.map((w) => `- ${w.agentId} "${w.name}" [${w.status}]${w.teamId ? ` team=${w.teamId}` : ""} turns=${w.turnsRun} queued=${w.queued} — ${w.lastMessageHead}`);
|
|
257
|
+
return { ok: true, output: lines.join("\n") };
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
return [spawnWorker, sendMessage, stopWorker, dismissWorker, createTeam, listWorkers];
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=coordinator-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator-tools.js","sourceRoot":"","sources":["../../src/core/coordinator-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAuB,MAAM,qBAAqB,CAAC;AAG/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AAExB;yEACyE;AACzE,MAAM,wBAAw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C,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,CAAC,CAAC,sBAAsB,IAAI,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC;QAC/D,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,IAAI;YAChB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACzC,MAAM,OAAO,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,sBAAsB,IAAI,GAAG,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;YACzF,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CACvB,CAAC,CAAC,EAAE,EAAE,CACJ,KAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,QAAQ,WAAW,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,eAAe,EAAE,CACjJ,CAAC;YACF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AACxF,CAAC"}
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type ApprovalMode, type AsyncTaskRegistry, type BoundaryInjectionQueue, type CancellationToken, type EventBus, type TaskNotification, ModelSelection } from "@chances-ai/runtime";
|
|
1
|
+
import { type ApprovalMode, type AsyncTaskRegistry, type BoundaryInjectionQueue, type NotificationSource, type CancellationToken, type EventBus, type TaskNotification, ModelSelection } from "@chances-ai/runtime";
|
|
2
2
|
import { type Message, type ModelRouter, type Route, type RetryConfig, type ToolCallRequest, type ToolDefinition } from "../ai/index.js";
|
|
3
3
|
import type { SessionManager } from "../session/index.js";
|
|
4
4
|
import type { MemoryStore } from "../memory/index.js";
|
|
5
5
|
import type { PermissionGate, ToolRegistry } from "../tools/index.js";
|
|
6
6
|
import type { PluginHost } from "../plugin-api/index.js";
|
|
7
|
+
import { type SnapshotStore } from "../hashline/index.js";
|
|
7
8
|
export interface AgentEngineOptions {
|
|
8
9
|
bus: EventBus;
|
|
9
10
|
router: ModelRouter;
|
|
@@ -13,6 +14,16 @@ export interface AgentEngineOptions {
|
|
|
13
14
|
workspaceRoot: string;
|
|
14
15
|
memory?: MemoryStore;
|
|
15
16
|
plugins?: PluginHost;
|
|
17
|
+
/**
|
|
18
|
+
* (7.9) Per-session hashline snapshot store. `read`/`search` record the full
|
|
19
|
+
* normalized text they return (minting a `¶path#TAG`); `edit` validates the
|
|
20
|
+
* tag against it. Omit and the engine creates its own {@link
|
|
21
|
+
* InMemorySnapshotStore} — so the root engine and each task-tool child engine
|
|
22
|
+
* get a fresh, isolated store keyed by their own (possibly worktree)
|
|
23
|
+
* canonical paths (R1-OQ10). Inject one only to share snapshots across
|
|
24
|
+
* engines (uncommon).
|
|
25
|
+
*/
|
|
26
|
+
snapshots?: SnapshotStore;
|
|
16
27
|
/**
|
|
17
28
|
* (5.3) Session approval-mode getter. Read at the start of every turn (for
|
|
18
29
|
* the plan-mode system reminder) and per tool call (for the `blockByMode`
|
|
@@ -126,6 +137,15 @@ export interface AgentEngineOptions {
|
|
|
126
137
|
* backgrounds never accidentally orphan into a process exit.
|
|
127
138
|
*/
|
|
128
139
|
backgroundTasks?: AsyncTaskRegistry;
|
|
140
|
+
/**
|
|
141
|
+
* (7.8 §3.4) Persistent coordinator worker registry. A SECOND
|
|
142
|
+
* {@link NotificationSource} the engine drains alongside `backgroundTasks` at
|
|
143
|
+
* every turn boundary — a worker's per-message result reaches the coordinator
|
|
144
|
+
* as a `<task-notification>` exactly like a background subagent's. Undefined on
|
|
145
|
+
* a normal (non-coordinator) session (drain is a no-op). Per-session in the
|
|
146
|
+
* isolated serve path, same as `backgroundTasks`.
|
|
147
|
+
*/
|
|
148
|
+
workerRegistry?: NotificationSource;
|
|
129
149
|
/**
|
|
130
150
|
* (7.7 §4) Per-session steering queue. When provided, the engine drains it at
|
|
131
151
|
* every turn boundary (turn-top + after each tool batch) and injects the
|
|
@@ -273,14 +293,19 @@ interface TurnState {
|
|
|
273
293
|
* `injected*Ids` collections are mutated in place (append-only) by the loop and
|
|
274
294
|
* its hooks; the engine reads them back after the loop to persist + acknowledge.
|
|
275
295
|
*/
|
|
296
|
+
/** (7.8 §3.4 — codex R2 M1) Per-source injected-notification tracking. Keyed by
|
|
297
|
+
* the `NotificationSource` object so each source's ack set is independent — a
|
|
298
|
+
* cross-source id collision can't shadow or mis-ack a note. Turn-local. */
|
|
299
|
+
export type InjectedNotifs = Map<NotificationSource, Set<string>>;
|
|
276
300
|
export interface LoopRun {
|
|
277
301
|
turnId: string;
|
|
278
302
|
system: string;
|
|
279
303
|
toolDefs: ToolDefinition[];
|
|
280
304
|
/** Accumulator: assistant/tool/steering messages appended as the loop runs. */
|
|
281
305
|
turnMessages: Message[];
|
|
282
|
-
/** Notification ids already injected
|
|
283
|
-
|
|
306
|
+
/** (codex R2 M1) Notification ids already injected this turn, keyed PER source
|
|
307
|
+
* (turn-top + mid-turn) — ack the right source's own ids after persist. */
|
|
308
|
+
injectedNotifIds: InjectedNotifs;
|
|
284
309
|
/** Steering ids already injected — ack after persist. */
|
|
285
310
|
injectedSteerIds: string[];
|
|
286
311
|
/** Soft turn ceiling for THIS run (already clamped to the hard cap). */
|
|
@@ -315,7 +340,7 @@ export interface AgentLoopHooks {
|
|
|
315
340
|
/** Iteration-boundary injections: steering the user queued mid-turn + bg-task
|
|
316
341
|
* notifications that completed mid-turn (peek-not-drain; ids recorded for the
|
|
317
342
|
* post-persist ack). pi `getSteeringMessages`. */
|
|
318
|
-
getBoundaryMessages(injectedNotifIds:
|
|
343
|
+
getBoundaryMessages(injectedNotifIds: InjectedNotifs, injectedSteerIds: string[]): Message[];
|
|
319
344
|
/** When the model returned NO tool calls: a `user`-role reminder to finish
|
|
320
345
|
* open todos (loop continues) or `null` to let the turn resolve. The inverse
|
|
321
346
|
* of pi's `shouldStopAfterTurn`. */
|
|
@@ -327,8 +352,11 @@ export interface AgentLoopHooks {
|
|
|
327
352
|
* emitting events on the bus — it never imports the TUI.
|
|
328
353
|
*/
|
|
329
354
|
export declare class AgentEngine {
|
|
355
|
+
#private;
|
|
330
356
|
private readonly opts;
|
|
331
357
|
private readonly selection;
|
|
358
|
+
/** (7.9) Per-session hashline snapshot store shared by `read` and `edit`. */
|
|
359
|
+
private readonly snapshots;
|
|
332
360
|
constructor(opts: AgentEngineOptions);
|
|
333
361
|
/**
|
|
334
362
|
* Exposes the mutable selection so callers — typically slash commands like
|
|
@@ -347,8 +375,24 @@ export declare class AgentEngine {
|
|
|
347
375
|
* render each as a user message, and append its id to `injectedSteerIds` for
|
|
348
376
|
* post-persist ack. Peek-not-drain: a cancelled turn re-delivers. */
|
|
349
377
|
private drainSteering;
|
|
350
|
-
/** (7.
|
|
351
|
-
*
|
|
378
|
+
/** (7.8 §3.4) The notification sources the engine drains at turn boundaries:
|
|
379
|
+
* background subagent tasks AND persistent coordinator workers. Both
|
|
380
|
+
* implement {@link NotificationSource}; the engine renders their pending
|
|
381
|
+
* `<task-notification>`s together (FIFO within each) and acks EACH source's
|
|
382
|
+
* own ids after persist — never broadcasting a global id list (codex R1-§5). */
|
|
383
|
+
private notificationSources;
|
|
384
|
+
/** (7.7 §4 / 7.8 §3.4 — codex R2 M1) Collect notifications not yet injected this
|
|
385
|
+
* turn, across ALL sources, recording each into its OWN per-source injected set
|
|
386
|
+
* as it's taken. The injected tracking is keyed by `NotificationSource` (NOT a
|
|
387
|
+
* flat id set) so a hypothetical cross-source id collision can never make one
|
|
388
|
+
* source's note shadow another's, nor ack a note that was never injected. */
|
|
389
|
+
private collectFreshNotifications;
|
|
390
|
+
/** (7.7 §4 / 7.8 — codex R2 M1) Ack AFTER persist: each source acks EXACTLY the
|
|
391
|
+
* ids injected FROM it this turn (per-source set), never a merged global list.
|
|
392
|
+
* A cancelled turn (no ack) re-delivers; injected ids are turn-local. */
|
|
393
|
+
private ackNotifications;
|
|
394
|
+
/** (7.7 §4) Iteration-boundary drain: notifications that arrived mid-turn
|
|
395
|
+
* (combined render across all sources, same as turn-top) PLUS steering. Both
|
|
352
396
|
* peek-not-drain; ids recorded for post-persist ack. */
|
|
353
397
|
private drainBoundaryInjections;
|
|
354
398
|
/** (7.7 §5.3) Build an incomplete-todos reminder when the model stopped with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/core/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAGrB,cAAc,EAIf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,WAAW,EAEhB,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EAKpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/core/engine.ts"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