clanka 0.20.0 → 0.22.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/Acp.test.js +20 -8
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts +4 -4
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +140 -99
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +5 -4
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentBashJobs.test.js +51 -32
- package/dist/AgentBashJobs.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.js +26 -7
- package/dist/AgentCallerConfig.test.js.map +1 -1
- package/dist/AgentExecutor.d.ts +71 -41
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +86 -78
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +173 -72
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +2 -2
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +3 -2
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +220 -31
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +369 -257
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +247 -190
- package/dist/AgentTools.js.map +1 -1
- package/dist/AgentTools.test.js +2 -2
- package/dist/AgentTools.test.js.map +1 -1
- package/dist/bin/cli.mjs +330 -281
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +32 -11
- package/src/Agent.test.ts +5 -4
- package/src/Agent.ts +175 -137
- package/src/AgentBashJobs.test.ts +74 -38
- package/src/AgentCallerConfig.test.ts +39 -7
- package/src/AgentExecutor.test.ts +229 -72
- package/src/AgentExecutor.ts +120 -104
- package/src/AgentExecutorImage.test.ts +2 -2
- package/src/AgentImage.test.ts +4 -3
- package/src/AgentSubagents.test.ts +825 -562
- package/src/AgentTools.test.ts +2 -2
- package/src/AgentTools.ts +370 -278
|
@@ -20,13 +20,14 @@ import * as Agent from "./Agent.ts"
|
|
|
20
20
|
import * as AgentExecutor from "./AgentExecutor.ts"
|
|
21
21
|
|
|
22
22
|
// =============================================================================
|
|
23
|
-
// Background bash
|
|
23
|
+
// Background bash tasks: completion pushes and lifecycle.
|
|
24
24
|
//
|
|
25
|
-
// These drive the real Agent loop and a real executor. When a background
|
|
26
|
-
// exits, the next model call gets a user message
|
|
27
|
-
// `<
|
|
28
|
-
// already reported by `
|
|
29
|
-
// status.
|
|
25
|
+
// These drive the real Agent loop and a real executor. When a background bash
|
|
26
|
+
// task exits, the next model call gets a user message
|
|
27
|
+
// `<task id="…" kind="bash" status="…" exitCode="…">output</task>`, unless the
|
|
28
|
+
// task was already reported by `stopTask`, `waitTasks` or a `taskOutput` call
|
|
29
|
+
// that saw its final status. Task IDs come from the executor's counter: "1",
|
|
30
|
+
// "2", ...
|
|
30
31
|
// =============================================================================
|
|
31
32
|
|
|
32
33
|
type Respond = (
|
|
@@ -103,11 +104,11 @@ const systemPrompt = (prompts: ReadonlyArray<Prompt.Prompt>): string =>
|
|
|
103
104
|
messageText(prompts[0]!.content[0]!)
|
|
104
105
|
|
|
105
106
|
/** The user messages in `prompt` that carry a completion push. */
|
|
106
|
-
const
|
|
107
|
+
const taskPushes = (prompt: Prompt.Prompt): Array<string> =>
|
|
107
108
|
prompt.content.flatMap((message) => {
|
|
108
109
|
if (message.role !== "user") return []
|
|
109
110
|
const text = messageText(message)
|
|
110
|
-
return text.includes("<
|
|
111
|
+
return text.includes("<task id=") ? [text] : []
|
|
111
112
|
})
|
|
112
113
|
|
|
113
114
|
// --- executors ---------------------------------------------------------------
|
|
@@ -157,16 +158,16 @@ const executors = [
|
|
|
157
158
|
// --- tests -------------------------------------------------------------------
|
|
158
159
|
|
|
159
160
|
for (const [executorName, executorLayer] of executors) {
|
|
160
|
-
// Each test gets its own executor, so
|
|
161
|
-
describe(`background bash
|
|
161
|
+
// Each test gets its own executor, so task IDs start at "1".
|
|
162
|
+
describe(`background bash tasks (${executorName} executor)`, () => {
|
|
162
163
|
it.live(
|
|
163
|
-
"a finished
|
|
164
|
+
"a finished bash task is pushed once with its id, kind, status, exit code and output",
|
|
164
165
|
() =>
|
|
165
166
|
Effect.gen(function* () {
|
|
166
167
|
const { exit, prompts } = yield* runAgent((index) => {
|
|
167
168
|
switch (index) {
|
|
168
169
|
case 0:
|
|
169
|
-
// The script outlives the
|
|
170
|
+
// The script outlives the task, so it has exited before the
|
|
170
171
|
// next model call.
|
|
171
172
|
return execute(
|
|
172
173
|
"start",
|
|
@@ -182,14 +183,14 @@ await sleep(500)`,
|
|
|
182
183
|
|
|
183
184
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
184
185
|
assert.strictEqual(prompts.length, 3)
|
|
185
|
-
const pushes =
|
|
186
|
+
const pushes = taskPushes(prompts[1]!)
|
|
186
187
|
assert.strictEqual(pushes.length, 1, "pushed before the next call")
|
|
187
188
|
assert.match(
|
|
188
189
|
pushes[0]!,
|
|
189
|
-
/^<
|
|
190
|
+
/^<task id="1" kind="bash" status="failed" exitCode="3">\s*JOB-OUTPUT\s*<\/task>$/,
|
|
190
191
|
)
|
|
191
192
|
assert.deepStrictEqual(
|
|
192
|
-
|
|
193
|
+
taskPushes(prompts[2]!),
|
|
193
194
|
pushes,
|
|
194
195
|
"not pushed a second time",
|
|
195
196
|
)
|
|
@@ -197,25 +198,28 @@ await sleep(500)`,
|
|
|
197
198
|
)
|
|
198
199
|
|
|
199
200
|
it.live(
|
|
200
|
-
"a
|
|
201
|
+
"a bash task whose final state stopTask, taskOutput, waitTasks or bash returned is not pushed",
|
|
201
202
|
() =>
|
|
202
203
|
Effect.gen(function* () {
|
|
203
204
|
const { exit, prompts } = yield* runAgent((index) => {
|
|
204
205
|
switch (index) {
|
|
205
206
|
case 0:
|
|
206
|
-
//
|
|
207
|
+
// Task 3 is never read, so it is the only push.
|
|
207
208
|
return execute(
|
|
208
209
|
"start",
|
|
209
210
|
`await bash({ command: "sleep 30", background: true })
|
|
210
211
|
await bash({ command: "echo READ", background: true })
|
|
211
212
|
await bash({ command: "echo UNREAD", background: true })
|
|
212
|
-
await
|
|
213
|
-
let
|
|
214
|
-
while (
|
|
213
|
+
await stopTask("1")
|
|
214
|
+
let task = await taskOutput("2")
|
|
215
|
+
while (task.status === "running") {
|
|
215
216
|
await sleep(20)
|
|
216
|
-
|
|
217
|
+
task = await taskOutput("2")
|
|
217
218
|
}
|
|
218
|
-
await
|
|
219
|
+
await bash({ command: "echo FOREGROUND" })
|
|
220
|
+
await waitTasks({ ids: [(await bash({ command: "echo WAITED", background: true })).id] })
|
|
221
|
+
await sleep(500)
|
|
222
|
+
console.log("SCRIPT" + "-DONE")`,
|
|
219
223
|
)
|
|
220
224
|
default:
|
|
221
225
|
return text("done")
|
|
@@ -224,12 +228,44 @@ await sleep(500)`,
|
|
|
224
228
|
|
|
225
229
|
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
226
230
|
assert.strictEqual(prompts.length, 2)
|
|
227
|
-
const pushes =
|
|
231
|
+
const pushes = taskPushes(prompts[1]!)
|
|
228
232
|
assert.strictEqual(pushes.length, 1)
|
|
229
233
|
assert.match(
|
|
230
234
|
pushes[0]!,
|
|
231
|
-
/^<
|
|
235
|
+
/^<task id="3" kind="bash" status="completed" exitCode="0">\s*UNREAD\s*<\/task>$/,
|
|
236
|
+
)
|
|
237
|
+
assert.include(JSON.stringify(prompts[1]), "SCRIPT-DONE")
|
|
238
|
+
}).pipe(Effect.provide(executorLayer)),
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
// Unlike a sub-agent, a running bash task such as a dev server never holds
|
|
242
|
+
// the run open. The run timeout fails a run that waits for it.
|
|
243
|
+
it.live(
|
|
244
|
+
"a running bash task neither keeps an idle turn alive nor blocks taskComplete",
|
|
245
|
+
() =>
|
|
246
|
+
Effect.gen(function* () {
|
|
247
|
+
const idle = yield* runAgent((index) =>
|
|
248
|
+
index === 0
|
|
249
|
+
? execute(
|
|
250
|
+
"start",
|
|
251
|
+
`await bash({ command: "sleep 30", background: true })`,
|
|
252
|
+
)
|
|
253
|
+
: text("idle"),
|
|
254
|
+
)
|
|
255
|
+
assert.deepStrictEqual(idle.exit, Exit.succeed("idle"))
|
|
256
|
+
assert.strictEqual(idle.prompts.length, 2)
|
|
257
|
+
|
|
258
|
+
const completed = yield* runAgent((index) =>
|
|
259
|
+
index === 0
|
|
260
|
+
? execute(
|
|
261
|
+
"complete",
|
|
262
|
+
`await bash({ command: "sleep 30", background: true })
|
|
263
|
+
await taskComplete("done")`,
|
|
264
|
+
)
|
|
265
|
+
: text("taskComplete was rejected"),
|
|
232
266
|
)
|
|
267
|
+
assert.deepStrictEqual(completed.exit, Exit.succeed("done"))
|
|
268
|
+
assert.strictEqual(completed.prompts.length, 1)
|
|
233
269
|
}).pipe(Effect.provide(executorLayer)),
|
|
234
270
|
)
|
|
235
271
|
})
|
|
@@ -237,9 +273,9 @@ await sleep(500)`,
|
|
|
237
273
|
|
|
238
274
|
// Clients and executor servers of different versions must keep working
|
|
239
275
|
// together.
|
|
240
|
-
describe("background bash
|
|
276
|
+
describe("background bash tasks across versions", () => {
|
|
241
277
|
it.live(
|
|
242
|
-
"the prompt promises
|
|
278
|
+
"the prompt promises task pushes only when the executor sends them",
|
|
243
279
|
() =>
|
|
244
280
|
Effect.gen(function* () {
|
|
245
281
|
const { current, capabilities } = yield* Effect.gen(function* () {
|
|
@@ -249,34 +285,34 @@ describe("background bash jobs across versions", () => {
|
|
|
249
285
|
capabilities: yield* executor.capabilities,
|
|
250
286
|
}
|
|
251
287
|
}).pipe(Effect.provide(localExecutorLayer))
|
|
252
|
-
assert.include(systemPrompt(current.prompts), '<
|
|
288
|
+
assert.include(systemPrompt(current.prompts), '<task id="..."')
|
|
253
289
|
|
|
254
|
-
// The current executor's tool typings without
|
|
290
|
+
// The current executor's tool typings without task pushes: what an
|
|
255
291
|
// older client sees from a current server, or what a custom executor
|
|
256
|
-
// that does not set `
|
|
257
|
-
const
|
|
292
|
+
// that does not set `taskPushes` renders.
|
|
293
|
+
const withoutTaskPushes = AgentExecutor.AgentExecutor.of({
|
|
258
294
|
capabilities: Effect.succeed(
|
|
259
295
|
new AgentExecutor.Capabilities({
|
|
260
296
|
...capabilities,
|
|
261
|
-
|
|
297
|
+
taskPushes: false,
|
|
262
298
|
}),
|
|
263
299
|
),
|
|
264
300
|
execute: () => Stream.empty,
|
|
265
301
|
executeUnsafe: () => Effect.die("executeUnsafe not implemented"),
|
|
266
302
|
})
|
|
267
303
|
const older = yield* runAgent(() => text("done")).pipe(
|
|
268
|
-
Effect.provideService(AgentExecutor.AgentExecutor,
|
|
304
|
+
Effect.provideService(AgentExecutor.AgentExecutor, withoutTaskPushes),
|
|
269
305
|
)
|
|
270
306
|
const olderPrompt = systemPrompt(older.prompts)
|
|
271
307
|
assert.include(olderPrompt, "bash(", "the tool typings are included")
|
|
272
|
-
assert.include(olderPrompt, '"
|
|
273
|
-
assert.notInclude(olderPrompt, "<
|
|
308
|
+
assert.include(olderPrompt, '"taskOutput"')
|
|
309
|
+
assert.notInclude(olderPrompt, "<task", "no push is promised")
|
|
274
310
|
}),
|
|
275
311
|
)
|
|
276
312
|
|
|
277
|
-
// A client from before
|
|
278
|
-
// end its script with a defect.
|
|
279
|
-
it.live("the server sends no
|
|
313
|
+
// A client from before task pushes cannot decode a `Task` part, so one
|
|
314
|
+
// would end its script with a defect.
|
|
315
|
+
it.live("the server sends no Task parts to a client that did not ask", () =>
|
|
280
316
|
Effect.gen(function* () {
|
|
281
317
|
const client = yield* RpcClient.make(AgentExecutor.Rpcs)
|
|
282
318
|
const { environment } = yield* client.capabilities()
|
|
@@ -289,7 +325,7 @@ describe("background bash jobs across versions", () => {
|
|
|
289
325
|
.pipe(Stream.runCollect)
|
|
290
326
|
const tags = parts.map((part) => part._tag)
|
|
291
327
|
assert.include(tags, "Environment", "the script ran")
|
|
292
|
-
assert.notInclude(tags, "
|
|
328
|
+
assert.notInclude(tags, "Task")
|
|
293
329
|
}).pipe(Effect.scoped, Effect.provide(rpcProtocolLayer)),
|
|
294
330
|
)
|
|
295
331
|
})
|
|
@@ -26,7 +26,7 @@ import * as RpcServer from "effect/rpc/RpcServer"
|
|
|
26
26
|
import * as Agent from "./Agent.ts"
|
|
27
27
|
import * as AgentExecutor from "./AgentExecutor.ts"
|
|
28
28
|
import * as AgentSkills from "./AgentSkills.ts"
|
|
29
|
-
import { type ExcludableTool,
|
|
29
|
+
import { type ExcludableTool, agentTasksUnavailable } from "./AgentTools.ts"
|
|
30
30
|
|
|
31
31
|
// =============================================================================
|
|
32
32
|
// Caller-selected tools, instructions, skills and loop-side tools.
|
|
@@ -218,7 +218,7 @@ const execute = (
|
|
|
218
218
|
onEnvironment: () => Effect.void,
|
|
219
219
|
onTaskComplete: () => Effect.void,
|
|
220
220
|
onImage: () => Effect.void,
|
|
221
|
-
|
|
221
|
+
agentTasks: agentTasksUnavailable,
|
|
222
222
|
loopTools,
|
|
223
223
|
})
|
|
224
224
|
.pipe(Stream.mkString)
|
|
@@ -236,7 +236,7 @@ for (const mode of modes) {
|
|
|
236
236
|
executor: {
|
|
237
237
|
excludeTools: ["gh", "webSearch", "fetchMarkdown", "delegate"],
|
|
238
238
|
},
|
|
239
|
-
script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof delegate, typeof
|
|
239
|
+
script: `const missing = [typeof gh, typeof webSearch, typeof fetchMarkdown, typeof delegate, typeof messageAgent].join(",")
|
|
240
240
|
let call
|
|
241
241
|
try {
|
|
242
242
|
await gh(["pr", "view"])
|
|
@@ -252,12 +252,44 @@ await taskComplete(missing + " " + call)`,
|
|
|
252
252
|
)
|
|
253
253
|
assert.notMatch(
|
|
254
254
|
system,
|
|
255
|
-
/\b(gh|webSearch|fetchMarkdown|delegate|
|
|
255
|
+
/\b(gh|webSearch|fetchMarkdown|delegate|messageAgent)\b/,
|
|
256
256
|
)
|
|
257
257
|
assert.include(system, "declare function readFile(")
|
|
258
258
|
}),
|
|
259
259
|
)
|
|
260
260
|
|
|
261
|
+
// The shared task functions address bash and agent tasks, so they stay
|
|
262
|
+
// while either kind can still be started.
|
|
263
|
+
it.live("the task functions go only when bash and delegate both go", () =>
|
|
264
|
+
Effect.gen(function* () {
|
|
265
|
+
const tasks =
|
|
266
|
+
"[typeof taskOutput, typeof waitTasks, typeof stopTask, typeof listTasks].join()"
|
|
267
|
+
const withBash = yield* runAgent({
|
|
268
|
+
mode,
|
|
269
|
+
executor: { excludeTools: ["delegate"] },
|
|
270
|
+
script: `await taskComplete(${tasks})`,
|
|
271
|
+
})
|
|
272
|
+
assert.strictEqual(
|
|
273
|
+
withBash.summary,
|
|
274
|
+
"function,function,function,function",
|
|
275
|
+
)
|
|
276
|
+
const withNeither = yield* runAgent({
|
|
277
|
+
mode,
|
|
278
|
+
executor: { excludeTools: ["bash", "delegate"] },
|
|
279
|
+
script: `await taskComplete(${tasks})`,
|
|
280
|
+
})
|
|
281
|
+
assert.strictEqual(
|
|
282
|
+
withNeither.summary,
|
|
283
|
+
"undefined,undefined,undefined,undefined",
|
|
284
|
+
)
|
|
285
|
+
assert.notMatch(
|
|
286
|
+
withNeither.system,
|
|
287
|
+
/\b(taskOutput|waitTasks|stopTask|listTasks)\b/,
|
|
288
|
+
)
|
|
289
|
+
assert.notInclude(withNeither.system, "<task")
|
|
290
|
+
}),
|
|
291
|
+
)
|
|
292
|
+
|
|
261
293
|
it.live("a caller tool replaces a left-out built-in of the same name", () =>
|
|
262
294
|
Effect.gen(function* () {
|
|
263
295
|
let calls = 0
|
|
@@ -404,12 +436,12 @@ describe("agent", () => {
|
|
|
404
436
|
// applyPatch hint and the executor's skills catalog.
|
|
405
437
|
const { system, summary } = yield* runAgent({
|
|
406
438
|
mode: "local",
|
|
407
|
-
executor: { excludeTools: ["
|
|
439
|
+
executor: { excludeTools: ["waitTasks", "applyPatch", "readFile"] },
|
|
408
440
|
script:
|
|
409
|
-
"await taskComplete([typeof
|
|
441
|
+
"await taskComplete([typeof waitTasks, typeof applyPatch, typeof readFile].join())",
|
|
410
442
|
})
|
|
411
443
|
assert.strictEqual(summary, "undefined,undefined,undefined")
|
|
412
|
-
assert.notMatch(system, /\b(
|
|
444
|
+
assert.notMatch(system, /\b(waitTasks|applyPatch|readFile)\b/)
|
|
413
445
|
assert.include(system, "declare function delegate(")
|
|
414
446
|
}),
|
|
415
447
|
)
|