clanka 0.22.5 → 0.22.6
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/Agent.d.ts.map +1 -1
- package/dist/Agent.js +4 -13
- package/dist/Agent.js.map +1 -1
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +3 -3
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +3 -1
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentSubagents.test.js +34 -5
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +5 -45
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +1 -2
- package/dist/AgentTools.js.map +1 -1
- package/dist/bin/cli.mjs +7 -18
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Agent.ts +3 -24
- package/src/AgentExecutor.test.ts +3 -1
- package/src/AgentExecutor.ts +8 -5
- package/src/AgentSubagents.test.ts +50 -9
- package/src/AgentTools.ts +2 -3
package/package.json
CHANGED
package/src/Agent.ts
CHANGED
|
@@ -686,7 +686,7 @@ ${prompt}`,
|
|
|
686
686
|
if (child.turn.status === "running") {
|
|
687
687
|
child.mailbox.messages.add({ message, resume: () => {} })
|
|
688
688
|
child.mailbox.notify()
|
|
689
|
-
return
|
|
689
|
+
return
|
|
690
690
|
}
|
|
691
691
|
child.turn = makeTurn(true)
|
|
692
692
|
yield* startTurn({
|
|
@@ -695,7 +695,6 @@ ${prompt}`,
|
|
|
695
695
|
label: message,
|
|
696
696
|
background: true,
|
|
697
697
|
})
|
|
698
|
-
return childTask(child)
|
|
699
698
|
}),
|
|
700
699
|
stopTask: Effect.fnUntraced(function* (id) {
|
|
701
700
|
const child = yield* lookupChild(id)
|
|
@@ -704,7 +703,6 @@ ${prompt}`,
|
|
|
704
703
|
if (turn.status === "running") {
|
|
705
704
|
yield* Fiber.interrupt(turn.fiber!)
|
|
706
705
|
}
|
|
707
|
-
return childTask(child)
|
|
708
706
|
}),
|
|
709
707
|
listTasks: Effect.sync(() =>
|
|
710
708
|
Array.Array.from(children.values(), childTask),
|
|
@@ -1795,27 +1793,13 @@ const generateSystemTools = (
|
|
|
1795
1793
|
tools.offers("search") && tools.offers("rg"),
|
|
1796
1794
|
`
|
|
1797
1795
|
- Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`,
|
|
1798
|
-
)}${when(
|
|
1799
|
-
tools.offers("applyPatch"),
|
|
1800
|
-
`
|
|
1801
|
-
- You can add / update / remove multiple files in one go with "applyPatch".${when(
|
|
1802
|
-
tools.offers("writeFile"),
|
|
1803
|
-
` Prefer it over "writeFile" to update existing files.`,
|
|
1804
|
-
)}`,
|
|
1805
1796
|
)}${when(
|
|
1806
1797
|
tools.offers("bash"),
|
|
1807
1798
|
`
|
|
1808
1799
|
- Avoid passing scripts into the "bash" function, and instead write javascript.`,
|
|
1809
1800
|
)}
|
|
1810
1801
|
- Variables are not shared between executions.
|
|
1811
|
-
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(
|
|
1812
|
-
tools.offers("delegate"),
|
|
1813
|
-
`
|
|
1814
|
-
- "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs: it returns an agent task straight away, and the agent's result is sent to you when it ends.${when(
|
|
1815
|
-
tools.offers("messageAgent"),
|
|
1816
|
-
` Use "messageAgent" to send a message to a sub-agent.`,
|
|
1817
|
-
)}`,
|
|
1818
|
-
)}${taskInstructions(tools)}${when(
|
|
1802
|
+
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${taskInstructions(tools)}${when(
|
|
1819
1803
|
!conversationMode,
|
|
1820
1804
|
`
|
|
1821
1805
|
|
|
@@ -1850,12 +1834,7 @@ Here is how you would read a file and list a directory:
|
|
|
1850
1834
|
\`\`\`
|
|
1851
1835
|
const [files, content] = await Promise.all([
|
|
1852
1836
|
ls("."),
|
|
1853
|
-
readFile({
|
|
1854
|
-
path: "package.json",
|
|
1855
|
-
startLine: 1,
|
|
1856
|
-
endLine: 10,
|
|
1857
|
-
lineNumbers: false,
|
|
1858
|
-
})
|
|
1837
|
+
readFile({ path: "package.json", startLine: 1, endLine: 10 })
|
|
1859
1838
|
])
|
|
1860
1839
|
console.log("files:", files)
|
|
1861
1840
|
console.log("package.json:", JSON.parse(content))
|
|
@@ -801,7 +801,8 @@ try {
|
|
|
801
801
|
} catch (error) {
|
|
802
802
|
console.log("MESSAGE-REJECTED:", String(error))
|
|
803
803
|
}
|
|
804
|
-
console.log("
|
|
804
|
+
console.log("STOP-VOID:", (await stopTask("1")) === undefined)
|
|
805
|
+
console.log("STOPPED:", show(await taskOutput("1")))
|
|
805
806
|
try {
|
|
806
807
|
await stopTask("99")
|
|
807
808
|
} catch (error) {
|
|
@@ -816,6 +817,7 @@ try {
|
|
|
816
817
|
output,
|
|
817
818
|
'STOPPED: {"id":"1","kind":"bash","status":"stopped"}',
|
|
818
819
|
)
|
|
820
|
+
assert.include(output, "STOP-VOID: true")
|
|
819
821
|
assert.match(output, /REJECTED:.*No task with id "99".*listTasks\(\)/)
|
|
820
822
|
openGate(environment.cwd)
|
|
821
823
|
yield* Effect.sleep("500 millis")
|
package/src/AgentExecutor.ts
CHANGED
|
@@ -1008,11 +1008,14 @@ export const layerRpcServer = <Toolkit extends Toolkit.Any = never>(
|
|
|
1008
1008
|
timeoutMs,
|
|
1009
1009
|
}),
|
|
1010
1010
|
messageAgent: (options) =>
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1011
|
+
Effect.asVoid(
|
|
1012
|
+
request<void>({
|
|
1013
|
+
_tag: "MessageAgent",
|
|
1014
|
+
...options,
|
|
1015
|
+
}),
|
|
1016
|
+
),
|
|
1017
|
+
stopTask: (id) =>
|
|
1018
|
+
Effect.asVoid(request<void>({ _tag: "StopTask", id })),
|
|
1016
1019
|
listTasks: Effect.orDie(
|
|
1017
1020
|
request<ReadonlyArray<Task>>({
|
|
1018
1021
|
_tag: "ListTasks",
|
|
@@ -603,8 +603,8 @@ await taskComplete("done")`,
|
|
|
603
603
|
Stream.as(
|
|
604
604
|
toolCall(
|
|
605
605
|
"stop",
|
|
606
|
-
`
|
|
607
|
-
console.log(JSON.stringify(
|
|
606
|
+
`console.log("STOP-VOID:", (await stopTask("1")) === undefined)
|
|
607
|
+
console.log(JSON.stringify(await taskOutput("1")))`,
|
|
608
608
|
),
|
|
609
609
|
),
|
|
610
610
|
)
|
|
@@ -622,6 +622,7 @@ console.log(JSON.stringify(result))`,
|
|
|
622
622
|
assert.deepStrictEqual(exit, Exit.succeed("stopped"))
|
|
623
623
|
const root = calls.filter((call) => call.role === "root")
|
|
624
624
|
const stopped = lastToolResult(root[2]!.prompt)
|
|
625
|
+
assert.include(stopped, "STOP-VOID: true")
|
|
625
626
|
assert.include(stopped, '"id":"1"')
|
|
626
627
|
assert.include(stopped, '"status":"stopped"')
|
|
627
628
|
assert.isTrue(
|
|
@@ -630,6 +631,51 @@ console.log(JSON.stringify(result))`,
|
|
|
630
631
|
)
|
|
631
632
|
}))
|
|
632
633
|
|
|
634
|
+
test("messageAgent returns void when steering a running child", () =>
|
|
635
|
+
Effect.gen(function* () {
|
|
636
|
+
const childStarted = Latch.makeUnsafe(false)
|
|
637
|
+
const childRelease = Latch.makeUnsafe(false)
|
|
638
|
+
const { exit, calls } = yield* runAgent({
|
|
639
|
+
conversationMode: true,
|
|
640
|
+
respond: (call) => {
|
|
641
|
+
if (call.role === "child") {
|
|
642
|
+
if (call.index === 0) {
|
|
643
|
+
return Stream.fromEffect(
|
|
644
|
+
Effect.sync(() => childStarted.openUnsafe()).pipe(
|
|
645
|
+
Effect.andThen(childRelease.await),
|
|
646
|
+
),
|
|
647
|
+
).pipe(Stream.flatMap(() => Stream.fromIterable(text("ready"))))
|
|
648
|
+
}
|
|
649
|
+
return complete("STEERED-ANSWER")
|
|
650
|
+
}
|
|
651
|
+
if (call.index === 0) {
|
|
652
|
+
return Stream.make(spawnBackground("TASK-CHILD"))
|
|
653
|
+
}
|
|
654
|
+
if (call.index === 1) {
|
|
655
|
+
return Stream.fromEffect(childStarted.await).pipe(
|
|
656
|
+
Stream.as(
|
|
657
|
+
toolCall(
|
|
658
|
+
"message",
|
|
659
|
+
`console.log("MESSAGE-VOID:", (await messageAgent({ id: "1", message: "STEER" })) === undefined)`,
|
|
660
|
+
),
|
|
661
|
+
),
|
|
662
|
+
)
|
|
663
|
+
}
|
|
664
|
+
childRelease.openUnsafe()
|
|
665
|
+
return Stream.fromIterable(text("steered"))
|
|
666
|
+
},
|
|
667
|
+
})
|
|
668
|
+
|
|
669
|
+
assert.deepStrictEqual(exit, Exit.succeed("steered"))
|
|
670
|
+
const root = calls.filter((call) => call.role === "root")
|
|
671
|
+
assert.include(lastToolResult(root[2]!.prompt), "MESSAGE-VOID: true")
|
|
672
|
+
const steered = calls.find(
|
|
673
|
+
(call) => call.role === "child" && call.index === 1,
|
|
674
|
+
)
|
|
675
|
+
assert.isDefined(steered, "the running child received the message")
|
|
676
|
+
assert.include(JSON.stringify(steered!.prompt), "STEER")
|
|
677
|
+
}))
|
|
678
|
+
|
|
633
679
|
test("messageAgent resumes a finished child on top of its history", () =>
|
|
634
680
|
Effect.gen(function* () {
|
|
635
681
|
let messageCall: number | undefined
|
|
@@ -666,7 +712,7 @@ console.log(JSON.stringify(result))`,
|
|
|
666
712
|
toolCall(
|
|
667
713
|
"message",
|
|
668
714
|
`const result = await messageAgent({ id: "1", message: "FOLLOW-UP" })
|
|
669
|
-
console.log(
|
|
715
|
+
console.log("MESSAGE-VOID:", result === undefined)`,
|
|
670
716
|
),
|
|
671
717
|
)
|
|
672
718
|
}
|
|
@@ -678,12 +724,7 @@ console.log(JSON.stringify(result))`,
|
|
|
678
724
|
assert.isDefined(messageCall, "the first answer was pushed")
|
|
679
725
|
const root = calls.filter((call) => call.role === "root")
|
|
680
726
|
const messaged = lastToolResult(root[messageCall! + 1]!.prompt)
|
|
681
|
-
assert.include(messaged,
|
|
682
|
-
assert.include(
|
|
683
|
-
messaged,
|
|
684
|
-
'"status":"running"',
|
|
685
|
-
"messageAgent returns without waiting for the new turn",
|
|
686
|
-
)
|
|
727
|
+
assert.include(messaged, "MESSAGE-VOID: true")
|
|
687
728
|
|
|
688
729
|
assert.isDefined(resumedPrompt, "the finished child was resumed")
|
|
689
730
|
const resumed = messageJsons(resumedPrompt!)
|
package/src/AgentTools.ts
CHANGED
|
@@ -161,7 +161,7 @@ export interface AgentTasks {
|
|
|
161
161
|
/**
|
|
162
162
|
* Interrupt an agent and everything it spawned.
|
|
163
163
|
*/
|
|
164
|
-
readonly stopTask: (id: string) => Effect.Effect<
|
|
164
|
+
readonly stopTask: (id: string) => Effect.Effect<void, string>
|
|
165
165
|
/**
|
|
166
166
|
* The agents this agent started.
|
|
167
167
|
*/
|
|
@@ -454,7 +454,6 @@ export const AgentTools = Toolkit.make(
|
|
|
454
454
|
parameters: Schema.String.annotate({
|
|
455
455
|
identifier: "id",
|
|
456
456
|
}),
|
|
457
|
-
success: Task,
|
|
458
457
|
failure: Schema.String,
|
|
459
458
|
dependencies: [AgentTaskExecutor],
|
|
460
459
|
}),
|
|
@@ -979,7 +978,7 @@ export const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(
|
|
|
979
978
|
return yield* agentTasks.stopTask(id)
|
|
980
979
|
}
|
|
981
980
|
yield* Fiber.interrupt(entry.command.fiber)
|
|
982
|
-
|
|
981
|
+
entry.command.reported = true
|
|
983
982
|
}),
|
|
984
983
|
listTasks: Effect.fn("AgentTools.listTasks")(function* () {
|
|
985
984
|
yield* Effect.logInfo(`Calling "listTasks"`)
|