clanka 0.8.6 → 0.9.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.d.ts.map +1 -1
- package/dist/Acp.js +9 -3
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +72 -1
- package/dist/Acp.test.js.map +1 -1
- package/dist/AcpImage.test.js +1 -0
- package/dist/AcpImage.test.js.map +1 -1
- package/dist/Agent.d.ts +65 -8
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +481 -113
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +77 -4
- package/dist/Agent.test.js.map +1 -1
- package/dist/AgentCallerConfig.test.d.ts +2 -0
- package/dist/AgentCallerConfig.test.d.ts.map +1 -0
- package/dist/AgentCallerConfig.test.js +327 -0
- package/dist/AgentCallerConfig.test.js.map +1 -0
- package/dist/AgentExecutor.d.ts +254 -54
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +416 -99
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +201 -31
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentExecutorImage.test.js +2 -1
- package/dist/AgentExecutorImage.test.js.map +1 -1
- package/dist/AgentImage.test.js +5 -1
- package/dist/AgentImage.test.js.map +1 -1
- package/dist/AgentOutput.d.ts +54 -2
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +52 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/AgentSkills.d.ts +22 -0
- package/dist/AgentSkills.d.ts.map +1 -1
- package/dist/AgentSkills.js +36 -0
- package/dist/AgentSkills.js.map +1 -1
- package/dist/AgentSkills.test.js +2 -0
- package/dist/AgentSkills.test.js.map +1 -1
- package/dist/AgentSubagents.test.d.ts +2 -0
- package/dist/AgentSubagents.test.d.ts.map +1 -0
- package/dist/AgentSubagents.test.js +452 -0
- package/dist/AgentSubagents.test.js.map +1 -0
- package/dist/AgentTools.d.ts +356 -14
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +213 -34
- package/dist/AgentTools.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +16 -2
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/ToolkitRenderer.d.ts.map +1 -1
- package/dist/ToolkitRenderer.js +6 -1
- package/dist/ToolkitRenderer.js.map +1 -1
- package/dist/bin/{Effect-rADALOOD.mjs → Effect-2jPlJ8eu.mjs} +43 -38
- package/dist/bin/Effect-2jPlJ8eu.mjs.map +1 -0
- package/dist/bin/{McpClient-NazR2OwL.mjs → McpClient-1W508adc.mjs} +3 -3
- package/dist/bin/{McpClient-NazR2OwL.mjs.map → McpClient-1W508adc.mjs.map} +1 -1
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs → OutputFormatter-DXXKo4E8.mjs} +16 -5
- package/dist/bin/{OutputFormatter-BVHbgF2b.mjs.map → OutputFormatter-DXXKo4E8.mjs.map} +1 -1
- package/dist/bin/{Schema-C7NXAOWA.mjs → Schema-D-7VuCiC.mjs} +2 -2
- package/dist/bin/{Schema-C7NXAOWA.mjs.map → Schema-D-7VuCiC.mjs.map} +1 -1
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs → SemanticSearch-Cb8aqvGv.mjs} +4 -4
- package/dist/bin/{SemanticSearch-4Jes3jCl.mjs.map → SemanticSearch-Cb8aqvGv.mjs.map} +1 -1
- package/dist/bin/{Stream-CSLA1_GD.mjs → Stream-DEu2tfCV.mjs} +12 -3
- package/dist/bin/Stream-DEu2tfCV.mjs.map +1 -0
- package/dist/bin/cli.mjs +914 -273
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +121 -2
- package/src/Acp.ts +10 -3
- package/src/AcpImage.test.ts +1 -0
- package/src/Agent.test.ts +100 -3
- package/src/Agent.ts +752 -142
- package/src/AgentCallerConfig.test.ts +514 -0
- package/src/AgentExecutor.test.ts +297 -37
- package/src/AgentExecutor.ts +707 -159
- package/src/AgentExecutorImage.test.ts +2 -1
- package/src/AgentImage.test.ts +11 -2
- package/src/AgentOutput.ts +74 -1
- package/src/AgentSkills.test.ts +2 -0
- package/src/AgentSkills.ts +43 -0
- package/src/AgentSubagents.test.ts +758 -0
- package/src/AgentTools.ts +376 -52
- package/src/OutputFormatter.ts +16 -2
- package/src/ToolkitRenderer.ts +7 -1
- package/dist/bin/Effect-rADALOOD.mjs.map +0 -1
- package/dist/bin/Stream-CSLA1_GD.mjs.map +0 -1
package/package.json
CHANGED
package/src/Acp.test.ts
CHANGED
|
@@ -26,6 +26,7 @@ const capabilities = new AgentExecutor.Capabilities({
|
|
|
26
26
|
toolsDts: "",
|
|
27
27
|
agentsMd: Option.none(),
|
|
28
28
|
supportsSearch: false,
|
|
29
|
+
tools: [],
|
|
29
30
|
skills: [],
|
|
30
31
|
})
|
|
31
32
|
|
|
@@ -425,8 +426,13 @@ describe("Acp", () => {
|
|
|
425
426
|
: assistantSays(summary),
|
|
426
427
|
{
|
|
427
428
|
...executor,
|
|
428
|
-
execute: ({
|
|
429
|
-
Stream.fromEffect(
|
|
429
|
+
execute: ({ subagents }) =>
|
|
430
|
+
Stream.fromEffect(
|
|
431
|
+
subagents.delegate({ prompt, background: false }),
|
|
432
|
+
).pipe(
|
|
433
|
+
Stream.map((result) => result.output ?? ""),
|
|
434
|
+
Stream.orDie,
|
|
435
|
+
),
|
|
430
436
|
},
|
|
431
437
|
)
|
|
432
438
|
const created = yield* server.request(1, "session/new", {
|
|
@@ -468,6 +474,119 @@ describe("Acp", () => {
|
|
|
468
474
|
),
|
|
469
475
|
)
|
|
470
476
|
|
|
477
|
+
it.effect(
|
|
478
|
+
"resuming a finished subagent does not create its tool call twice",
|
|
479
|
+
() =>
|
|
480
|
+
withStore(
|
|
481
|
+
Effect.scoped(
|
|
482
|
+
Effect.gen(function* () {
|
|
483
|
+
let childId: string | undefined
|
|
484
|
+
let executions = 0
|
|
485
|
+
const server = yield* makeServer(
|
|
486
|
+
({ prompt }) => {
|
|
487
|
+
if (JSON.stringify(prompt.content).includes("TASK-CHILD")) {
|
|
488
|
+
const resumed = JSON.stringify(prompt.content).includes(
|
|
489
|
+
"FOLLOW-UP",
|
|
490
|
+
)
|
|
491
|
+
return assistantSays(
|
|
492
|
+
resumed ? "SECOND-RESULT" : "FIRST-RESULT",
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
const seen = JSON.stringify(prompt.content)
|
|
496
|
+
if (seen.includes("SECOND-RESULT")) return assistantSays("done")
|
|
497
|
+
if (
|
|
498
|
+
executions === 0 ||
|
|
499
|
+
(executions === 1 && seen.includes("FIRST-RESULT"))
|
|
500
|
+
) {
|
|
501
|
+
return parts({
|
|
502
|
+
type: "tool-call",
|
|
503
|
+
id: `call-${executions}`,
|
|
504
|
+
name: "execute",
|
|
505
|
+
params: { script: "await work()" },
|
|
506
|
+
})
|
|
507
|
+
}
|
|
508
|
+
return assistantSays("waiting")
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
...executor,
|
|
512
|
+
// The first script starts a background child; the second
|
|
513
|
+
// resumes it once its first result has been delivered.
|
|
514
|
+
execute: ({ subagents }) =>
|
|
515
|
+
Stream.fromEffect(
|
|
516
|
+
executions++ === 0
|
|
517
|
+
? subagents
|
|
518
|
+
.delegate({ prompt: "TASK-CHILD", background: true })
|
|
519
|
+
.pipe(
|
|
520
|
+
Effect.map((result) => {
|
|
521
|
+
childId = result.id
|
|
522
|
+
return "started"
|
|
523
|
+
}),
|
|
524
|
+
)
|
|
525
|
+
: subagents
|
|
526
|
+
.messageAgent({ id: childId!, message: "FOLLOW-UP" })
|
|
527
|
+
.pipe(Effect.as("resumed")),
|
|
528
|
+
).pipe(Stream.orDie),
|
|
529
|
+
},
|
|
530
|
+
)
|
|
531
|
+
const created = yield* server.request(1, "session/new", {
|
|
532
|
+
cwd: "/tmp",
|
|
533
|
+
})
|
|
534
|
+
const sessionId: string = created.result.sessionId
|
|
535
|
+
yield* server.request(2, "session/prompt", {
|
|
536
|
+
sessionId,
|
|
537
|
+
prompt: [{ type: "text", text: "delegate and resume" }],
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
assert.strictEqual(executions, 2, "the child was resumed")
|
|
541
|
+
const tools = server
|
|
542
|
+
.updates(sessionId)
|
|
543
|
+
.filter(
|
|
544
|
+
(u) =>
|
|
545
|
+
u.sessionUpdate.startsWith("tool_call") &&
|
|
546
|
+
u.toolCallId.startsWith("subagent-"),
|
|
547
|
+
)
|
|
548
|
+
const creations = tools
|
|
549
|
+
.filter((u) => u.sessionUpdate === "tool_call")
|
|
550
|
+
.map((u) => u.toolCallId)
|
|
551
|
+
assert.deepStrictEqual(
|
|
552
|
+
creations,
|
|
553
|
+
[...new Set(creations)],
|
|
554
|
+
"ACP tool call IDs must be unique within the session",
|
|
555
|
+
)
|
|
556
|
+
for (const u of tools) {
|
|
557
|
+
assert.include(
|
|
558
|
+
creations,
|
|
559
|
+
u.toolCallId,
|
|
560
|
+
"updates refer to a created tool call",
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const firstDone = tools.findIndex(
|
|
565
|
+
(u) => u.status === "completed" && u.rawOutput === "FIRST-RESULT",
|
|
566
|
+
)
|
|
567
|
+
const secondDone = tools.findIndex(
|
|
568
|
+
(u) =>
|
|
569
|
+
u.status === "completed" && u.rawOutput === "SECOND-RESULT",
|
|
570
|
+
)
|
|
571
|
+
assert.isAbove(firstDone, -1, "first result shown")
|
|
572
|
+
assert.isAbove(secondDone, firstDone, "second result shown")
|
|
573
|
+
assert.isTrue(
|
|
574
|
+
tools
|
|
575
|
+
.slice(firstDone + 1, secondDone)
|
|
576
|
+
.some((u) => u.status === "in_progress"),
|
|
577
|
+
"the resumed turn is shown as running",
|
|
578
|
+
)
|
|
579
|
+
assert.deepStrictEqual(tools[secondDone].content, [
|
|
580
|
+
{
|
|
581
|
+
type: "content",
|
|
582
|
+
content: { type: "text", text: "SECOND-RESULT" },
|
|
583
|
+
},
|
|
584
|
+
])
|
|
585
|
+
}),
|
|
586
|
+
),
|
|
587
|
+
),
|
|
588
|
+
)
|
|
589
|
+
|
|
471
590
|
it.effect("reports canonical state for new and loaded sessions", () =>
|
|
472
591
|
withStore(
|
|
473
592
|
Effect.gen(function* () {
|
package/src/Acp.ts
CHANGED
|
@@ -297,6 +297,7 @@ interface Session {
|
|
|
297
297
|
readonly agent: Agent.Agent
|
|
298
298
|
running: Fiber.Fiber<void, unknown> | undefined
|
|
299
299
|
toolCalls: number
|
|
300
|
+
readonly announcedSubagents: Set<number>
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
/**
|
|
@@ -394,6 +395,7 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
|
|
|
394
395
|
agent,
|
|
395
396
|
running: undefined,
|
|
396
397
|
toolCalls: 0,
|
|
398
|
+
announcedSubagents: new Set(),
|
|
397
399
|
}
|
|
398
400
|
sessions.set(id, session)
|
|
399
401
|
return session
|
|
@@ -669,20 +671,25 @@ export const make = Effect.fnUntraced(function* <RAgent, RModel>(
|
|
|
669
671
|
`Retrying after error: ${part.error.message}\n`,
|
|
670
672
|
),
|
|
671
673
|
})
|
|
672
|
-
|
|
674
|
+
// A background agent's tool call stays in progress until the agent
|
|
675
|
+
// finishes, while the parent keeps taking turns.
|
|
676
|
+
case "SubagentStart": {
|
|
677
|
+
const announced = session.announcedSubagents.has(part.id)
|
|
678
|
+
session.announcedSubagents.add(part.id)
|
|
673
679
|
return update(session.id, {
|
|
674
|
-
sessionUpdate: "tool_call",
|
|
680
|
+
sessionUpdate: announced ? "tool_call_update" : "tool_call",
|
|
675
681
|
toolCallId: `subagent-${part.id}`,
|
|
676
682
|
title: `delegate: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
|
|
677
683
|
kind: "think",
|
|
678
684
|
status: "in_progress",
|
|
679
685
|
rawInput: { prompt: part.prompt },
|
|
680
686
|
})
|
|
687
|
+
}
|
|
681
688
|
case "SubagentComplete":
|
|
682
689
|
return update(session.id, {
|
|
683
690
|
sessionUpdate: "tool_call_update",
|
|
684
691
|
toolCallId: `subagent-${part.id}`,
|
|
685
|
-
status: "completed",
|
|
692
|
+
status: part.status === "completed" ? "completed" : "failed",
|
|
686
693
|
rawOutput: part.summary,
|
|
687
694
|
content: [{ type: "content", content: textContent(part.summary) }],
|
|
688
695
|
})
|
package/src/AcpImage.test.ts
CHANGED
package/src/Agent.test.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type * as Response from "effect/ai/Response"
|
|
|
18
18
|
import * as ResponseIdTracker from "effect/ai/ResponseIdTracker"
|
|
19
19
|
import * as Agent from "./Agent.ts"
|
|
20
20
|
import * as AgentExecutor from "./AgentExecutor.ts"
|
|
21
|
+
import { subagentsUnavailable } from "./AgentTools.ts"
|
|
21
22
|
import * as AgentOutput from "./AgentOutput.ts"
|
|
22
23
|
import * as Compaction from "./Compaction.ts"
|
|
23
24
|
|
|
@@ -25,6 +26,7 @@ const capabilities = new AgentExecutor.Capabilities({
|
|
|
25
26
|
toolsDts: "",
|
|
26
27
|
agentsMd: Option.none(),
|
|
27
28
|
supportsSearch: false,
|
|
29
|
+
tools: [],
|
|
28
30
|
skills: [],
|
|
29
31
|
})
|
|
30
32
|
|
|
@@ -114,7 +116,10 @@ describe("Agent", () => {
|
|
|
114
116
|
conversationMode: true,
|
|
115
117
|
executor: makeExecutor(({ onTaskComplete }) =>
|
|
116
118
|
Stream.fromEffect(
|
|
117
|
-
onTaskComplete("done from taskComplete").pipe(
|
|
119
|
+
onTaskComplete("done from taskComplete").pipe(
|
|
120
|
+
Effect.as(""),
|
|
121
|
+
Effect.orDie,
|
|
122
|
+
),
|
|
118
123
|
),
|
|
119
124
|
),
|
|
120
125
|
streamText: () =>
|
|
@@ -162,6 +167,7 @@ const runAgentCollect = (options: {
|
|
|
162
167
|
readonly compaction?: Partial<Compaction.CompactionConfigService> | undefined
|
|
163
168
|
readonly prompt?: string | undefined
|
|
164
169
|
readonly turnTimeout?: Duration.Duration | undefined
|
|
170
|
+
readonly maxRetries?: number | undefined
|
|
165
171
|
readonly respond: ScriptedResponse
|
|
166
172
|
}) =>
|
|
167
173
|
Effect.scoped(
|
|
@@ -243,6 +249,9 @@ const runAgentCollect = (options: {
|
|
|
243
249
|
Agent.TurnTimeout,
|
|
244
250
|
options.turnTimeout ?? Duration.minutes(5),
|
|
245
251
|
),
|
|
252
|
+
options.maxRetries === undefined
|
|
253
|
+
? Layer.empty
|
|
254
|
+
: Agent.MaxRetries.layer(options.maxRetries),
|
|
246
255
|
),
|
|
247
256
|
),
|
|
248
257
|
Effect.exit,
|
|
@@ -474,7 +483,7 @@ it.layer(localExecutorLayer, { excludeTestServices: true })(
|
|
|
474
483
|
Effect.sync(() => {
|
|
475
484
|
summaries.push(summary)
|
|
476
485
|
}),
|
|
477
|
-
|
|
486
|
+
subagents: subagentsUnavailable,
|
|
478
487
|
onImage: () => Effect.void,
|
|
479
488
|
})
|
|
480
489
|
.pipe(Stream.mkString)
|
|
@@ -1164,7 +1173,7 @@ describe("Agent overflow compaction", () => {
|
|
|
1164
1173
|
})
|
|
1165
1174
|
assert.isTrue(Exit.isFailure(exit), "turn must fail")
|
|
1166
1175
|
const error = Option.getOrThrow(Exit.findErrorOption(exit))
|
|
1167
|
-
assert
|
|
1176
|
+
assert(error._tag === "AiError")
|
|
1168
1177
|
assert.strictEqual(error.reason._tag, "InvalidRequestError")
|
|
1169
1178
|
assert.strictEqual(calls.length, 3)
|
|
1170
1179
|
}),
|
|
@@ -1285,3 +1294,91 @@ describe("Agent overflow compaction", () => {
|
|
|
1285
1294
|
}),
|
|
1286
1295
|
)
|
|
1287
1296
|
})
|
|
1297
|
+
|
|
1298
|
+
describe("Agent retry limit", () => {
|
|
1299
|
+
it.live(
|
|
1300
|
+
"fails with RetriesExhausted once model errors and turn timeouts reach MaxRetries",
|
|
1301
|
+
() =>
|
|
1302
|
+
Effect.gen(function* () {
|
|
1303
|
+
const { exit, calls } = yield* runAgentCollect({
|
|
1304
|
+
maxRetries: 2,
|
|
1305
|
+
turnTimeout: Duration.millis(100),
|
|
1306
|
+
respond: (_call, index) => {
|
|
1307
|
+
switch (index) {
|
|
1308
|
+
case 0:
|
|
1309
|
+
return Stream.fail(providerError)
|
|
1310
|
+
case 1:
|
|
1311
|
+
return Stream.fromEffect(Effect.never)
|
|
1312
|
+
case 2:
|
|
1313
|
+
return Stream.fail(providerError)
|
|
1314
|
+
default:
|
|
1315
|
+
return Stream.die(
|
|
1316
|
+
`unexpected model call #${index}: must stop retrying`,
|
|
1317
|
+
)
|
|
1318
|
+
}
|
|
1319
|
+
},
|
|
1320
|
+
}).pipe(Effect.timeout("3 seconds"))
|
|
1321
|
+
assert.strictEqual(calls.length, 3)
|
|
1322
|
+
const error = Option.getOrThrow(Exit.findErrorOption(exit))
|
|
1323
|
+
assert(error._tag === "RetriesExhausted")
|
|
1324
|
+
assert.strictEqual(error.retries, 2)
|
|
1325
|
+
assert.strictEqual(error.error.reason._tag, "InternalProviderError")
|
|
1326
|
+
}),
|
|
1327
|
+
)
|
|
1328
|
+
})
|
|
1329
|
+
|
|
1330
|
+
describe("Agent history events", () => {
|
|
1331
|
+
it.effect(
|
|
1332
|
+
"rebuild the agent's history from the history it was resumed with",
|
|
1333
|
+
() =>
|
|
1334
|
+
Effect.gen(function* () {
|
|
1335
|
+
const { exit, outputs, history } = yield* runAgentCollect({
|
|
1336
|
+
history: fatHistory,
|
|
1337
|
+
compaction: {
|
|
1338
|
+
contextWindow: 12_000,
|
|
1339
|
+
reserveTokens: 2_000,
|
|
1340
|
+
keepRecentTokens: 9_000,
|
|
1341
|
+
},
|
|
1342
|
+
executor: makeExecutor(() => Stream.succeed("listed")),
|
|
1343
|
+
respond: (call, index) => {
|
|
1344
|
+
switch (index) {
|
|
1345
|
+
case 0:
|
|
1346
|
+
assertSummarizerCall(call)
|
|
1347
|
+
return Stream.fromIterable(text("SUMMARY"))
|
|
1348
|
+
case 1:
|
|
1349
|
+
return Stream.fromIterable([
|
|
1350
|
+
toolCall("call-3", "console.log(await ls('.'))"),
|
|
1351
|
+
finish(500),
|
|
1352
|
+
])
|
|
1353
|
+
case 2:
|
|
1354
|
+
return Stream.fromIterable([
|
|
1355
|
+
...text("done"),
|
|
1356
|
+
finish(600, "stop"),
|
|
1357
|
+
])
|
|
1358
|
+
default:
|
|
1359
|
+
return Stream.die(`unexpected model call #${index}`)
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
})
|
|
1363
|
+
assert.deepStrictEqual(exit, Exit.succeed("done"))
|
|
1364
|
+
|
|
1365
|
+
let replayed: Array<Prompt.Message> = [...fatHistory.content]
|
|
1366
|
+
for (const output of outputs) {
|
|
1367
|
+
if (output._tag === "HistoryAppended") {
|
|
1368
|
+
replayed.push(...output.messages)
|
|
1369
|
+
} else if (output._tag === "HistoryReplaced") {
|
|
1370
|
+
replayed = [...output.messages]
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
assert.strictEqual(outputsOfTag(outputs, "HistoryReplaced").length, 1)
|
|
1374
|
+
assert.strictEqual(
|
|
1375
|
+
promptJson(Prompt.fromMessages(replayed)),
|
|
1376
|
+
promptJson(
|
|
1377
|
+
Prompt.fromMessages(
|
|
1378
|
+
history.content.filter((message) => message.role !== "system"),
|
|
1379
|
+
),
|
|
1380
|
+
),
|
|
1381
|
+
)
|
|
1382
|
+
}),
|
|
1383
|
+
)
|
|
1384
|
+
})
|