clanka 0.21.0 → 0.22.1
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 +19 -7
- 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 +47 -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 -79
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +108 -83
- 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 +218 -29
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +318 -290
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +225 -199
- package/dist/AgentTools.js.map +1 -1
- package/dist/AgentTools.test.js +2 -2
- package/dist/AgentTools.test.js.map +1 -1
- package/dist/AgentToolsReadFile.test.js +8 -2
- package/dist/AgentToolsReadFile.test.js.map +1 -1
- package/dist/bin/cli.mjs +309 -289
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +31 -10
- package/src/Agent.test.ts +5 -4
- package/src/Agent.ts +175 -140
- package/src/AgentBashJobs.test.ts +70 -38
- package/src/AgentCallerConfig.test.ts +39 -7
- package/src/AgentExecutor.test.ts +132 -91
- package/src/AgentExecutor.ts +120 -105
- 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 +345 -288
- package/src/AgentToolsReadFile.test.ts +14 -3
package/dist/bin/cli.mjs
CHANGED
|
@@ -11538,48 +11538,33 @@ const isUnsupportedImageError = (error) => {
|
|
|
11538
11538
|
var CurrentDirectory = class extends Service()("clanka/AgentTools/CurrentDirectory") {};
|
|
11539
11539
|
var DirectoryChanger = class extends Service()("clanka/AgentTools/DirectoryChanger") {};
|
|
11540
11540
|
var TaskCompleter = class extends Service()("clanka/AgentTools/TaskCompleter") {};
|
|
11541
|
-
const
|
|
11542
|
-
|
|
11541
|
+
const TaskKind = Literals$2(["bash", "agent"]);
|
|
11542
|
+
const TaskStatus = Literals$2([
|
|
11543
11543
|
"running",
|
|
11544
|
+
"completed",
|
|
11544
11545
|
"failed",
|
|
11545
|
-
"
|
|
11546
|
+
"stopped"
|
|
11546
11547
|
]);
|
|
11547
|
-
const
|
|
11548
|
-
id: String$7,
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
status: Literals$2(["completed", "running"])
|
|
11555
|
-
});
|
|
11556
|
-
const SubagentInfo = Struct({
|
|
11557
|
-
id: String$7,
|
|
11558
|
-
status: SubagentStatus,
|
|
11559
|
-
prompt: String$7
|
|
11548
|
+
const Task = Struct({
|
|
11549
|
+
id: String$7.annotate({ documentation: "The task id, which can be managed with the task tools." }),
|
|
11550
|
+
kind: TaskKind,
|
|
11551
|
+
status: TaskStatus,
|
|
11552
|
+
description: String$7,
|
|
11553
|
+
output: String$7,
|
|
11554
|
+
exitCode: optional$2(Number$2)
|
|
11560
11555
|
});
|
|
11561
|
-
var
|
|
11562
|
-
const
|
|
11556
|
+
var AgentTaskExecutor = class extends Service()("clanka/AgentTools/AgentTaskExecutor") {};
|
|
11557
|
+
const agentTasksUnavailable = {
|
|
11563
11558
|
delegate: () => die(new Error("Sub-agents are not available here")),
|
|
11564
|
-
|
|
11559
|
+
taskOutput: () => fail$1("Sub-agents are not available here"),
|
|
11560
|
+
waitTasks: () => fail$1("Sub-agents are not available here"),
|
|
11565
11561
|
messageAgent: () => fail$1("Sub-agents are not available here"),
|
|
11566
|
-
|
|
11567
|
-
|
|
11562
|
+
stopTask: () => fail$1("Sub-agents are not available here"),
|
|
11563
|
+
listTasks: succeed$1([])
|
|
11568
11564
|
};
|
|
11565
|
+
var TaskOwner = class extends Reference("clanka/AgentTools/TaskOwner", { defaultValue: () => void 0 }) {};
|
|
11569
11566
|
var ImageAttacher = class extends Service()("clanka/AgentTools/ImageAttacher") {};
|
|
11570
|
-
|
|
11571
|
-
"running",
|
|
11572
|
-
"completed",
|
|
11573
|
-
"failed",
|
|
11574
|
-
"stopped"
|
|
11575
|
-
]);
|
|
11576
|
-
const BashJob = Struct({
|
|
11577
|
-
id: String$7,
|
|
11578
|
-
status: BashJobStatus,
|
|
11579
|
-
exitCode: optional$2(Number$2),
|
|
11580
|
-
output: String$7
|
|
11581
|
-
});
|
|
11582
|
-
var JobWatcher = class extends Reference("clanka/AgentTools/JobWatcher", { defaultValue: () => () => void_ }) {};
|
|
11567
|
+
var TaskWatcher = class extends Reference("clanka/AgentTools/TaskWatcher", { defaultValue: () => () => void_ }) {};
|
|
11583
11568
|
const defaultBashTimeout = minutes(10);
|
|
11584
11569
|
const defaultMcpCallTimeout = minutes(10);
|
|
11585
11570
|
var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", { defaultValue: () => ({
|
|
@@ -11587,23 +11572,23 @@ var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", {
|
|
|
11587
11572
|
outputChars: void 0
|
|
11588
11573
|
}) }) {};
|
|
11589
11574
|
const makeBashTool = (timeout) => make$17("bash", {
|
|
11590
|
-
description: "Run a bash command and return a task
|
|
11575
|
+
description: "Run a bash command and return a task.",
|
|
11591
11576
|
parameters: Struct({
|
|
11592
11577
|
command: String$7,
|
|
11593
|
-
timeoutMs: optional$2(Finite).annotate({ documentation: `How long to wait in ms before moving the
|
|
11594
|
-
background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background
|
|
11578
|
+
timeoutMs: optional$2(Finite).annotate({ documentation: `How long to wait in ms before moving the task to the background (default and max: ${toMillis(timeout)})` }),
|
|
11579
|
+
background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background. Defaults to false which always returns 'completed' tasks." })
|
|
11595
11580
|
}).annotate({ identifier: "command" }),
|
|
11596
|
-
success:
|
|
11581
|
+
success: Task,
|
|
11597
11582
|
dependencies: [CurrentDirectory]
|
|
11598
11583
|
});
|
|
11599
11584
|
const globNamesDirectory = (glob) => glob.split("/").slice(0, -1).some((segment) => segment.length > 0 && !/[*?[\]{}]/.test(segment));
|
|
11600
11585
|
const AgentTools = make$16(make$17("changeDirectory", {
|
|
11601
|
-
description: "Change the executor's working directory to an existing directory and return its absolute path.
|
|
11586
|
+
description: "Change the executor's working directory to an existing directory and return its absolute path. The change persists across your scripts.",
|
|
11602
11587
|
parameters: String$7.annotate({ identifier: "directory" }),
|
|
11603
11588
|
success: String$7,
|
|
11604
11589
|
dependencies: [DirectoryChanger]
|
|
11605
11590
|
}), make$17("readFile", {
|
|
11606
|
-
description: "Read a file and optionally filter the lines to return. Returns null if the file doesn't exist. For png/jpeg/gif/webp files the image itself is attached to your next turn
|
|
11591
|
+
description: "Read a file and optionally filter the lines to return. Returns null if the file doesn't exist. For png/jpeg/gif/webp files the image itself is attached to your next turn.",
|
|
11607
11592
|
parameters: Struct({
|
|
11608
11593
|
path: String$7,
|
|
11609
11594
|
startLine: optional$2(Number$2),
|
|
@@ -11623,40 +11608,22 @@ const AgentTools = make$16(make$17("changeDirectory", {
|
|
|
11623
11608
|
success: String$7,
|
|
11624
11609
|
dependencies: [CurrentDirectory]
|
|
11625
11610
|
}), make$17("delegate", {
|
|
11626
|
-
description: "Delegate a task to another software engineer / sub-agent.
|
|
11611
|
+
description: "Delegate a task to another software engineer / sub-agent. With `background: true` the sub-agent works in the background, and its result is sent to you when it finishes.",
|
|
11627
11612
|
parameters: Struct({
|
|
11628
11613
|
prompt: String$7,
|
|
11629
11614
|
background: optional$2(Boolean$4)
|
|
11630
11615
|
}),
|
|
11631
|
-
success:
|
|
11632
|
-
failure: String$7,
|
|
11633
|
-
dependencies: [SubagentExecutor]
|
|
11634
|
-
}), make$17("waitAgents", {
|
|
11635
|
-
description: "Wait until the given sub-agents have finished, or all of your sub-agents when no ids are passed. A failed agent is returned with status \"failed\" and its error as the output; it does not throw.",
|
|
11636
|
-
parameters: UndefinedOr(ArraySchema(String$7)).annotate({ identifier: "ids" }),
|
|
11637
|
-
success: ArraySchema(SubagentResult),
|
|
11616
|
+
success: Task,
|
|
11638
11617
|
failure: String$7,
|
|
11639
|
-
dependencies: [
|
|
11618
|
+
dependencies: [AgentTaskExecutor]
|
|
11640
11619
|
}), make$17("messageAgent", {
|
|
11641
|
-
description: "Send a message to one of your sub-agents.
|
|
11620
|
+
description: "Send a message to one of your sub-agents.",
|
|
11642
11621
|
parameters: Struct({
|
|
11643
11622
|
id: String$7,
|
|
11644
11623
|
message: String$7
|
|
11645
11624
|
}),
|
|
11646
|
-
success: SubagentResult,
|
|
11647
|
-
failure: String$7,
|
|
11648
|
-
dependencies: [SubagentExecutor]
|
|
11649
|
-
}), make$17("stopAgent", {
|
|
11650
|
-
description: "Stop one of your sub-agents and every agent it started. Returns its final status.",
|
|
11651
|
-
parameters: String$7.annotate({ identifier: "id" }),
|
|
11652
|
-
success: SubagentResult,
|
|
11653
11625
|
failure: String$7,
|
|
11654
|
-
dependencies: [
|
|
11655
|
-
}), make$17("listAgents", {
|
|
11656
|
-
description: "List the sub-agents you have started in this run, with their status.",
|
|
11657
|
-
parameters: Void,
|
|
11658
|
-
success: ArraySchema(SubagentInfo),
|
|
11659
|
-
dependencies: [SubagentExecutor]
|
|
11626
|
+
dependencies: [AgentTaskExecutor]
|
|
11660
11627
|
}), make$17("glob", {
|
|
11661
11628
|
description: "Find files matching a glob pattern.",
|
|
11662
11629
|
parameters: String$7.annotate({ identifier: "pattern" }),
|
|
@@ -11667,24 +11634,32 @@ const AgentTools = make$16(make$17("changeDirectory", {
|
|
|
11667
11634
|
parameters: ArraySchema(String$7).annotate({ identifier: "args" }),
|
|
11668
11635
|
success: String$7,
|
|
11669
11636
|
dependencies: [CurrentDirectory]
|
|
11670
|
-
}), makeBashTool(defaultBashTimeout), make$17("
|
|
11671
|
-
description: "Return the status and output so far of a background bash
|
|
11637
|
+
}), makeBashTool(defaultBashTimeout), make$17("taskOutput", {
|
|
11638
|
+
description: "Return the status and output so far of one of your tasks: a background bash command or a sub-agent.",
|
|
11672
11639
|
parameters: String$7.annotate({ identifier: "id" }),
|
|
11673
|
-
success:
|
|
11674
|
-
failure: String$7
|
|
11675
|
-
|
|
11676
|
-
|
|
11640
|
+
success: Task,
|
|
11641
|
+
failure: String$7,
|
|
11642
|
+
dependencies: [AgentTaskExecutor]
|
|
11643
|
+
}), make$17("waitTasks", {
|
|
11644
|
+
description: "Wait until the given tasks have ended and return them, in the order given.",
|
|
11677
11645
|
parameters: Struct({
|
|
11678
|
-
|
|
11679
|
-
timeoutMs: optional$2(Finite).annotate({ documentation: "How long to wait in ms (default and max: the bash timeout)" })
|
|
11646
|
+
ids: ArraySchema(String$7),
|
|
11647
|
+
timeoutMs: optional$2(Finite).annotate({ documentation: "How long to wait in ms (default and max: the bash command timeout)" })
|
|
11680
11648
|
}),
|
|
11681
|
-
success:
|
|
11682
|
-
failure: String$7
|
|
11683
|
-
|
|
11684
|
-
|
|
11649
|
+
success: ArraySchema(Task),
|
|
11650
|
+
failure: String$7,
|
|
11651
|
+
dependencies: [AgentTaskExecutor]
|
|
11652
|
+
}), make$17("stopTask", {
|
|
11653
|
+
description: "Stop one of your tasks.",
|
|
11685
11654
|
parameters: String$7.annotate({ identifier: "id" }),
|
|
11686
|
-
success:
|
|
11687
|
-
failure: String$7
|
|
11655
|
+
success: Task,
|
|
11656
|
+
failure: String$7,
|
|
11657
|
+
dependencies: [AgentTaskExecutor]
|
|
11658
|
+
}), make$17("listTasks", {
|
|
11659
|
+
description: "List the tasks you have started, with their status.",
|
|
11660
|
+
parameters: Void,
|
|
11661
|
+
success: ArraySchema(Task),
|
|
11662
|
+
dependencies: [AgentTaskExecutor]
|
|
11688
11663
|
}), make$17("applyPatch", {
|
|
11689
11664
|
description: "Add, update or remove multiple files with a git diff / unified diff / wrapped patch.",
|
|
11690
11665
|
parameters: String$7.annotate({ identifier: "patch" }),
|
|
@@ -11752,44 +11727,49 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11752
11727
|
output: output.render
|
|
11753
11728
|
};
|
|
11754
11729
|
});
|
|
11755
|
-
const
|
|
11756
|
-
let
|
|
11757
|
-
const
|
|
11758
|
-
const id = String(
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
reported: false
|
|
11762
|
-
};
|
|
11763
|
-
jobs.set(id, running);
|
|
11764
|
-
return {
|
|
11730
|
+
const tasks = new Map();
|
|
11731
|
+
let nextTaskId = 1;
|
|
11732
|
+
const registerAgentTask = fnUntraced(function* () {
|
|
11733
|
+
const id = String(nextTaskId++);
|
|
11734
|
+
tasks.set(id, {
|
|
11735
|
+
kind: "agent",
|
|
11765
11736
|
id,
|
|
11766
|
-
|
|
11737
|
+
owner: yield* TaskOwner
|
|
11738
|
+
});
|
|
11739
|
+
return id;
|
|
11740
|
+
});
|
|
11741
|
+
const addBashTask = fnUntraced(function* (description, command) {
|
|
11742
|
+
const entry = {
|
|
11743
|
+
kind: "bash",
|
|
11744
|
+
id: String(nextTaskId++),
|
|
11745
|
+
owner: yield* TaskOwner,
|
|
11746
|
+
description,
|
|
11747
|
+
command: {
|
|
11748
|
+
...command,
|
|
11749
|
+
reported: false
|
|
11750
|
+
}
|
|
11767
11751
|
};
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11752
|
+
tasks.set(entry.id, entry);
|
|
11753
|
+
return entry;
|
|
11754
|
+
});
|
|
11755
|
+
const watchBashTask = fnUntraced(function* (entry) {
|
|
11756
|
+
yield* (yield* TaskWatcher)({
|
|
11757
|
+
id: entry.id,
|
|
11758
|
+
kind: "bash",
|
|
11759
|
+
await: await_(entry.command.fiber).pipe(map$5(() => bashTask(entry))),
|
|
11773
11760
|
claim: sync(() => {
|
|
11774
|
-
if (
|
|
11775
|
-
|
|
11761
|
+
if (entry.command.reported) return false;
|
|
11762
|
+
entry.command.reported = true;
|
|
11776
11763
|
return true;
|
|
11777
11764
|
})
|
|
11778
11765
|
});
|
|
11779
11766
|
});
|
|
11780
|
-
const
|
|
11781
|
-
const
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
if (job.status !== "running") running.reported = true;
|
|
11787
|
-
return job;
|
|
11788
|
-
};
|
|
11789
|
-
const awaitCommand = (running, timeout) => {
|
|
11790
|
-
const awaited = await_(running.fiber);
|
|
11791
|
-
return (timeout === void 0 ? asSome(awaited) : timeoutOption(awaited, timeout)).pipe(onInterrupt(() => interrupt$2(running.fiber)));
|
|
11792
|
-
};
|
|
11767
|
+
const findTask = fnUntraced(function* (id) {
|
|
11768
|
+
const owner = yield* TaskOwner;
|
|
11769
|
+
const entry = tasks.get(id);
|
|
11770
|
+
if (entry === void 0 || entry.owner !== owner) return yield* fail$1(`No task with id ${JSON.stringify(id)}. You can only address tasks you started; call listTasks() to see them.`);
|
|
11771
|
+
return entry;
|
|
11772
|
+
});
|
|
11793
11773
|
const readImage = fnUntraced(function* (path, extensionType, options) {
|
|
11794
11774
|
if (options.startLine !== void 0 || options.endLine !== void 0) return yield* die(new Error(`startLine / endLine are not supported for images: ${path}`));
|
|
11795
11775
|
const bytes = yield* readBoundedFile(fs, path).pipe(catchReason("PlatformError", "NotFound", () => succeed$1(null)), orDie);
|
|
@@ -11818,6 +11798,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11818
11798
|
const path = pathService.resolve(cwd, options.path);
|
|
11819
11799
|
const imageType = mediaTypeFromPath(path);
|
|
11820
11800
|
if (isSome(imageType)) return yield* readImage(path, imageType.value, options);
|
|
11801
|
+
if (options.lineNumbers === false && !options.startLine && !options.endLine) return yield* fs.readFileString(path).pipe(catchReason("PlatformError", "NotFound", () => succeed$1(null)), orDie);
|
|
11821
11802
|
let stream = pipe(fs.stream(path), decodeText, splitLines);
|
|
11822
11803
|
if (options.startLine) stream = drop(stream, options.startLine - 1);
|
|
11823
11804
|
if (options.endLine) stream = take$1(stream, options.endLine - (options.startLine ?? 1) + 1);
|
|
@@ -11905,44 +11886,62 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11905
11886
|
cwd,
|
|
11906
11887
|
stdin: "ignore"
|
|
11907
11888
|
});
|
|
11908
|
-
const
|
|
11889
|
+
const entry = yield* addBashTask(options.command, yield* startCommand(cmd));
|
|
11909
11890
|
if (options.background !== true) {
|
|
11910
|
-
const exit = yield* awaitCommand(
|
|
11891
|
+
const exit = yield* awaitCommand(entry.command, millis(timeoutMs));
|
|
11911
11892
|
if (isSome(exit)) {
|
|
11912
11893
|
const exitCode = yield* exit.value;
|
|
11913
|
-
const
|
|
11914
|
-
if (exitCode === 0) return
|
|
11915
|
-
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${
|
|
11894
|
+
const task = reportBash(entry);
|
|
11895
|
+
if (exitCode === 0) return task;
|
|
11896
|
+
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${task.output}`));
|
|
11916
11897
|
}
|
|
11917
11898
|
}
|
|
11918
|
-
const
|
|
11919
|
-
if (
|
|
11920
|
-
return
|
|
11899
|
+
const task = reportBash(entry);
|
|
11900
|
+
if (task.status === "running") yield* watchBashTask(entry);
|
|
11901
|
+
return task;
|
|
11921
11902
|
}, orDie),
|
|
11922
|
-
|
|
11923
|
-
const id = yield*
|
|
11924
|
-
yield* logInfo(`Calling "
|
|
11925
|
-
|
|
11903
|
+
taskOutput: fn("AgentTools.taskOutput")(function* (input) {
|
|
11904
|
+
const id = yield* decodeTaskOutput(input);
|
|
11905
|
+
yield* logInfo(`Calling "taskOutput"`).pipe(annotateLogs({ id }));
|
|
11906
|
+
const entry = yield* findTask(id);
|
|
11907
|
+
if (entry.kind === "bash") return reportBash(entry);
|
|
11908
|
+
return yield* (yield* AgentTaskExecutor).taskOutput(id);
|
|
11926
11909
|
}),
|
|
11927
|
-
|
|
11928
|
-
const
|
|
11910
|
+
waitTasks: fn("AgentTools.waitTasks")(function* (input) {
|
|
11911
|
+
const { ids, timeoutMs: requestedMs } = yield* decodeWaitTasks(input);
|
|
11929
11912
|
const maxMs = bashTimeoutMs(yield* CommandLimits);
|
|
11930
|
-
const timeoutMs = Math.min(
|
|
11931
|
-
yield* logInfo(`Calling "
|
|
11932
|
-
|
|
11913
|
+
const timeoutMs = Math.min(requestedMs ?? maxMs, maxMs);
|
|
11914
|
+
yield* logInfo(`Calling "waitTasks"`).pipe(annotateLogs({
|
|
11915
|
+
ids,
|
|
11933
11916
|
timeoutMs
|
|
11934
11917
|
}));
|
|
11935
|
-
const
|
|
11936
|
-
|
|
11937
|
-
|
|
11918
|
+
const entries = yield* forEach$1(ids, findTask);
|
|
11919
|
+
const bashEntries = entries.filter((entry) => entry.kind === "bash");
|
|
11920
|
+
const agentIds = entries.flatMap((entry) => entry.kind === "agent" ? [entry.id] : []);
|
|
11921
|
+
const agentTasks = yield* AgentTaskExecutor;
|
|
11922
|
+
const startedAt = yield* currentTimeMillis;
|
|
11923
|
+
yield* forEach$1(bashEntries, (entry) => await_(entry.command.fiber), {
|
|
11924
|
+
concurrency: "unbounded",
|
|
11925
|
+
discard: true
|
|
11926
|
+
}).pipe(timeoutOption(timeoutMs));
|
|
11927
|
+
const agentResults = agentIds.length === 0 ? [] : yield* agentTasks.waitTasks(agentIds, { timeoutMs: Math.max(0, timeoutMs - ((yield* currentTimeMillis) - startedAt)) });
|
|
11928
|
+
const ended = new Map([...bashEntries.map(reportBash), ...agentResults].map((task) => [task.id, task]));
|
|
11929
|
+
return ids.map((id) => ended.get(id));
|
|
11930
|
+
}),
|
|
11931
|
+
stopTask: fn("AgentTools.stopTask")(function* (input) {
|
|
11932
|
+
const id = yield* decodeStopTask(input);
|
|
11933
|
+
yield* logInfo(`Calling "stopTask"`).pipe(annotateLogs({ id }));
|
|
11934
|
+
const entry = yield* findTask(id);
|
|
11935
|
+
if (entry.kind === "agent") return yield* (yield* AgentTaskExecutor).stopTask(id);
|
|
11936
|
+
yield* interrupt$2(entry.command.fiber);
|
|
11937
|
+
return reportBash(entry);
|
|
11938
11938
|
}),
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
const
|
|
11943
|
-
yield*
|
|
11944
|
-
|
|
11945
|
-
return jobInfo(id, running);
|
|
11939
|
+
listTasks: fn("AgentTools.listTasks")(function* () {
|
|
11940
|
+
yield* logInfo(`Calling "listTasks"`);
|
|
11941
|
+
const owner = yield* TaskOwner;
|
|
11942
|
+
const bashTasks = Array$1.from(tasks.values()).flatMap((entry) => entry.kind === "bash" && entry.owner === owner ? [bashTask(entry)] : []);
|
|
11943
|
+
const agentTasks = yield* AgentTaskExecutor;
|
|
11944
|
+
return [...bashTasks, ...yield* agentTasks.listTasks].toSorted((a, b) => Number(a.id) - Number(b.id));
|
|
11946
11945
|
}),
|
|
11947
11946
|
gh: fn("AgentTools.gh")(function* (args) {
|
|
11948
11947
|
yield* logInfo(`Calling "gh"`).pipe(annotateLogs({ args }));
|
|
@@ -12066,29 +12065,19 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
12066
12065
|
delegate: fn("AgentTools.delegate")(function* (options) {
|
|
12067
12066
|
const { prompt, background = false } = yield* decodeDelegate(options);
|
|
12068
12067
|
yield* logInfo(`Calling "delegate"`).pipe(annotateLogs({ background }));
|
|
12069
|
-
|
|
12068
|
+
const id = yield* registerAgentTask();
|
|
12069
|
+
return yield* (yield* AgentTaskExecutor).delegate({
|
|
12070
|
+
id,
|
|
12070
12071
|
prompt,
|
|
12071
12072
|
background
|
|
12072
12073
|
});
|
|
12073
12074
|
}),
|
|
12074
|
-
waitAgents: fn("AgentTools.waitAgents")(function* (input) {
|
|
12075
|
-
const ids = yield* decodeWaitAgents(input);
|
|
12076
|
-
yield* logInfo(`Calling "waitAgents"`).pipe(annotateLogs({ ids }));
|
|
12077
|
-
return yield* (yield* SubagentExecutor).waitAgents(ids);
|
|
12078
|
-
}),
|
|
12079
12075
|
messageAgent: fn("AgentTools.messageAgent")(function* (input) {
|
|
12080
12076
|
const options = yield* decodeMessageAgent(input);
|
|
12081
12077
|
yield* logInfo(`Calling "messageAgent"`).pipe(annotateLogs({ id: options.id }));
|
|
12082
|
-
|
|
12083
|
-
|
|
12084
|
-
|
|
12085
|
-
const id = yield* decodeStopAgent(input);
|
|
12086
|
-
yield* logInfo(`Calling "stopAgent"`).pipe(annotateLogs({ id }));
|
|
12087
|
-
return yield* (yield* SubagentExecutor).stopAgent(id);
|
|
12088
|
-
}),
|
|
12089
|
-
listAgents: fn("AgentTools.listAgents")(function* () {
|
|
12090
|
-
yield* logInfo(`Calling "listAgents"`);
|
|
12091
|
-
return yield* (yield* SubagentExecutor).listAgents;
|
|
12078
|
+
const entry = yield* findTask(options.id);
|
|
12079
|
+
if (entry.kind === "bash") return yield* fail$1(`messageAgent only addresses sub-agents, and task ${JSON.stringify(entry.id)} is a bash task. Use taskOutput or stopTask with it instead.`);
|
|
12080
|
+
return yield* (yield* AgentTaskExecutor).messageAgent(options);
|
|
12092
12081
|
}),
|
|
12093
12082
|
taskComplete: fn("AgentTools.taskComplete")(function* (message) {
|
|
12094
12083
|
if (typeof message !== "string") return yield* fail$1("taskComplete requires a string argument. Pass your final output directly, for example: taskComplete(\"done\").");
|
|
@@ -12103,35 +12092,50 @@ const decodeParams$1 = (schema, usage) => {
|
|
|
12103
12092
|
return (input) => mapError(decode(input), () => usage);
|
|
12104
12093
|
};
|
|
12105
12094
|
const decodeDelegate = decodeParams$1(AgentTools.tools.delegate.parametersSchema, "delegate requires an options object, for example: delegate({ prompt: \"...\" }) or delegate({ prompt: \"...\", background: true }).");
|
|
12106
|
-
const decodeWaitAgents = decodeParams$1(AgentTools.tools.waitAgents.parametersSchema, "waitAgents takes an optional array of agent ids, for example: waitAgents([\"3\", \"4\"]).");
|
|
12107
12095
|
const decodeMessageAgent = decodeParams$1(AgentTools.tools.messageAgent.parametersSchema, "messageAgent requires an options object, for example: messageAgent({ id: \"3\", message: \"...\" }).");
|
|
12108
|
-
const
|
|
12109
|
-
const
|
|
12096
|
+
const decodeTaskOutput = decodeParams$1(AgentTools.tools.taskOutput.parametersSchema, "taskOutput requires a task id, for example: taskOutput(\"1\").");
|
|
12097
|
+
const decodeWaitTasks = decodeParams$1(AgentTools.tools.waitTasks.parametersSchema, "waitTasks requires an options object, for example: waitTasks({ ids: [\"3\", \"4\"] }) or waitTasks({ ids: [\"3\"], timeoutMs: 60000 }).");
|
|
12110
12098
|
const bashTimeoutMs = (limits) => toMillis(limits.timeout ?? defaultBashTimeout);
|
|
12111
|
-
const
|
|
12112
|
-
const
|
|
12113
|
-
const
|
|
12114
|
-
|
|
12115
|
-
|
|
12099
|
+
const decodeStopTask = decodeParams$1(AgentTools.tools.stopTask.parametersSchema, "stopTask requires a task id, for example: stopTask(\"1\").");
|
|
12100
|
+
const awaitCommand = (command, timeout) => {
|
|
12101
|
+
const awaited = await_(command.fiber);
|
|
12102
|
+
return (timeout === void 0 ? asSome(awaited) : timeoutOption(awaited, timeout)).pipe(onInterrupt(() => interrupt$2(command.fiber)));
|
|
12103
|
+
};
|
|
12104
|
+
const reportBash = (entry) => {
|
|
12105
|
+
const task = bashTask(entry);
|
|
12106
|
+
if (task.status !== "running") entry.command.reported = true;
|
|
12107
|
+
return task;
|
|
12108
|
+
};
|
|
12109
|
+
const bashTask = ({ id, description, command }) => {
|
|
12110
|
+
const exit = command.fiber.pollUnsafe();
|
|
12111
|
+
const output = command.output();
|
|
12116
12112
|
if (exit === void 0) return {
|
|
12117
12113
|
id,
|
|
12114
|
+
kind: "bash",
|
|
12118
12115
|
status: "running",
|
|
12116
|
+
description,
|
|
12119
12117
|
output
|
|
12120
12118
|
};
|
|
12121
12119
|
if (isSuccess(exit)) return {
|
|
12122
12120
|
id,
|
|
12121
|
+
kind: "bash",
|
|
12123
12122
|
status: exit.value === 0 ? "completed" : "failed",
|
|
12124
|
-
|
|
12125
|
-
output
|
|
12123
|
+
description,
|
|
12124
|
+
output,
|
|
12125
|
+
exitCode: exit.value
|
|
12126
12126
|
};
|
|
12127
12127
|
if (hasInterruptsOnly(exit.cause)) return {
|
|
12128
12128
|
id,
|
|
12129
|
+
kind: "bash",
|
|
12129
12130
|
status: "stopped",
|
|
12131
|
+
description,
|
|
12130
12132
|
output
|
|
12131
12133
|
};
|
|
12132
12134
|
return {
|
|
12133
12135
|
id,
|
|
12136
|
+
kind: "bash",
|
|
12134
12137
|
status: "failed",
|
|
12138
|
+
description,
|
|
12135
12139
|
output: `${output}${output === "" ? "" : "\n"}${pretty(exit.cause)}`
|
|
12136
12140
|
};
|
|
12137
12141
|
};
|
|
@@ -14152,7 +14156,7 @@ var Capabilities = class extends Class$1("Capabilities")({
|
|
|
14152
14156
|
environment: ExecutionEnvironment,
|
|
14153
14157
|
tools: ArraySchema(String$7),
|
|
14154
14158
|
skills: ArraySchema(Skill).pipe(withDecodingDefaultKey(succeed$1([])), withConstructorDefault(succeed$1([]))),
|
|
14155
|
-
|
|
14159
|
+
taskPushes: Boolean$4.pipe(withDecodingDefaultKey(succeed$1(false)), withConstructorDefault(succeed$1(false)))
|
|
14156
14160
|
}) {};
|
|
14157
14161
|
const makeLocal = (options) => map$5(makeLocalWith(options), (local) => local.executor);
|
|
14158
14162
|
const makeLocalWith = fnUntraced(function* (options) {
|
|
@@ -14241,13 +14245,13 @@ const makeLocalWith = fnUntraced(function* (options) {
|
|
|
14241
14245
|
currentDirectory = target;
|
|
14242
14246
|
return onChange ? onChange(currentEnvironment()) : void_;
|
|
14243
14247
|
}));
|
|
14244
|
-
const taskServices = empty$5().pipe(add(TaskCompleter, opts.onTaskComplete), add(DirectoryChanger, changeDirectory), add(
|
|
14245
|
-
...opts.
|
|
14246
|
-
delegate: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(flatMap$1((environment) => opts.
|
|
14248
|
+
const taskServices = empty$5().pipe(add(TaskCompleter, opts.onTaskComplete), add(DirectoryChanger, changeDirectory), add(AgentTaskExecutor, {
|
|
14249
|
+
...opts.agentTasks,
|
|
14250
|
+
delegate: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(flatMap$1((environment) => opts.agentTasks.delegate({
|
|
14247
14251
|
...options,
|
|
14248
14252
|
environment
|
|
14249
14253
|
})))
|
|
14250
|
-
}), add(ImageAttacher, opts.onImage), add(
|
|
14254
|
+
}), add(ImageAttacher, opts.onImage), add(TaskWatcher, opts.onTask ?? (() => void_)), add(TaskOwner, opts.agentId), add(CommandLimits, commandLimits), add(Console, console), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14251
14255
|
yield* gen(function* () {
|
|
14252
14256
|
const source = prepareScript(opts.script);
|
|
14253
14257
|
const settled = yield* make$42();
|
|
@@ -14333,7 +14337,7 @@ const makeLocalWith = fnUntraced(function* (options) {
|
|
|
14333
14337
|
}),
|
|
14334
14338
|
tools: Object.keys(tools.tools),
|
|
14335
14339
|
skills,
|
|
14336
|
-
|
|
14340
|
+
taskPushes: true
|
|
14337
14341
|
});
|
|
14338
14342
|
}),
|
|
14339
14343
|
execute: (opts) => execute(opts),
|
|
@@ -14344,7 +14348,7 @@ const makeLocalWith = fnUntraced(function* (options) {
|
|
|
14344
14348
|
const handler = services.mapUnsafe.get(tool.id);
|
|
14345
14349
|
if (!handler) return die(new Error(`Unknown tool: ${opts.tool}`));
|
|
14346
14350
|
const cwd = (opts.environment ?? startupEnvironment).cwd;
|
|
14347
|
-
const taskServices = handler.context.pipe(add(TaskCompleter, () => void_), add(CurrentDirectory, cwd), add(DirectoryChanger, (directory) => resolveDirectory(cwd, directory)), add(
|
|
14351
|
+
const taskServices = handler.context.pipe(add(TaskCompleter, () => void_), add(CurrentDirectory, cwd), add(DirectoryChanger, (directory) => resolveDirectory(cwd, directory)), add(AgentTaskExecutor, agentTasksUnavailable), add(ImageAttacher, () => void_), add(CommandLimits, commandLimits), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14348
14352
|
const encodeSuccess = encodeUnknownEffect(toCodecJson(tool.successSchema));
|
|
14349
14353
|
return pipe(handler.handler(opts.params, {}), flatMap$1(encodeSuccess), provideContext(taskServices), orDie);
|
|
14350
14354
|
})
|
|
@@ -14363,7 +14367,8 @@ const makeRpc = gen(function* () {
|
|
|
14363
14367
|
script: opts.script,
|
|
14364
14368
|
environment: opts.environment,
|
|
14365
14369
|
loopTools: Object.keys(opts.loopTools ?? {}),
|
|
14366
|
-
...opts.
|
|
14370
|
+
...opts.agentId === void 0 ? {} : { agentId: opts.agentId },
|
|
14371
|
+
...opts.onTask === void 0 ? {} : { watchTasks: true }
|
|
14367
14372
|
}).pipe(tap$1((part) => {
|
|
14368
14373
|
switch (part._tag) {
|
|
14369
14374
|
case "Text": return void_;
|
|
@@ -14383,13 +14388,14 @@ const makeRpc = gen(function* () {
|
|
|
14383
14388
|
case "Environment":
|
|
14384
14389
|
latest = part.environment;
|
|
14385
14390
|
return void_;
|
|
14386
|
-
case "
|
|
14387
|
-
if (opts.
|
|
14391
|
+
case "Task": {
|
|
14392
|
+
if (opts.onTask === void 0) return void_;
|
|
14388
14393
|
const id = part.id;
|
|
14389
|
-
return opts.
|
|
14394
|
+
return opts.onTask({
|
|
14390
14395
|
id,
|
|
14391
|
-
|
|
14392
|
-
|
|
14396
|
+
kind: part.kind,
|
|
14397
|
+
await: orDie(client.awaitTask({ id })),
|
|
14398
|
+
claim: orDie(client.claimTask({ id }))
|
|
14393
14399
|
});
|
|
14394
14400
|
}
|
|
14395
14401
|
}
|
|
@@ -14413,17 +14419,22 @@ const layerRpc = effect(AgentExecutor, makeRpc);
|
|
|
14413
14419
|
const AgentRequest = TaggedUnion({
|
|
14414
14420
|
TaskComplete: { summary: String$7 },
|
|
14415
14421
|
Delegate: {
|
|
14422
|
+
id: String$7,
|
|
14416
14423
|
prompt: String$7,
|
|
14417
14424
|
background: Boolean$4,
|
|
14418
14425
|
environment: EnvironmentUpdate
|
|
14419
14426
|
},
|
|
14420
|
-
|
|
14427
|
+
TaskOutput: { id: String$7 },
|
|
14428
|
+
WaitTasks: {
|
|
14429
|
+
ids: ArraySchema(String$7),
|
|
14430
|
+
timeoutMs: Finite
|
|
14431
|
+
},
|
|
14421
14432
|
MessageAgent: {
|
|
14422
14433
|
id: String$7,
|
|
14423
14434
|
message: String$7
|
|
14424
14435
|
},
|
|
14425
|
-
|
|
14426
|
-
|
|
14436
|
+
StopTask: { id: String$7 },
|
|
14437
|
+
ListTasks: {},
|
|
14427
14438
|
LoopTool: {
|
|
14428
14439
|
name: String$7,
|
|
14429
14440
|
params: optional$2(Json)
|
|
@@ -14446,7 +14457,10 @@ const ExecuteOutput = TaggedUnion({
|
|
|
14446
14457
|
data: Uint8Array$2
|
|
14447
14458
|
},
|
|
14448
14459
|
Environment: { environment: ExecutionEnvironment },
|
|
14449
|
-
|
|
14460
|
+
Task: {
|
|
14461
|
+
id: String$7,
|
|
14462
|
+
kind: TaskKind
|
|
14463
|
+
}
|
|
14450
14464
|
});
|
|
14451
14465
|
var Rpcs = class extends make$12(make$14("capabilities", { success: Capabilities }), make$14("respond", { payload: {
|
|
14452
14466
|
id: Finite,
|
|
@@ -14456,15 +14470,16 @@ var Rpcs = class extends make$12(make$14("capabilities", { success: Capabilities
|
|
|
14456
14470
|
script: String$7,
|
|
14457
14471
|
environment: ExecutionEnvironment,
|
|
14458
14472
|
loopTools: ArraySchema(String$7).pipe(withDecodingDefaultKey(succeed$1([]))),
|
|
14459
|
-
|
|
14473
|
+
agentId: optionalKey(String$7),
|
|
14474
|
+
watchTasks: optionalKey(Boolean$4)
|
|
14460
14475
|
}),
|
|
14461
14476
|
success: ExecuteOutput,
|
|
14462
14477
|
stream: true
|
|
14463
|
-
}), make$14("
|
|
14478
|
+
}), make$14("awaitTask", {
|
|
14464
14479
|
payload: { id: String$7 },
|
|
14465
|
-
success:
|
|
14480
|
+
success: Task,
|
|
14466
14481
|
error: String$7
|
|
14467
|
-
}), make$14("
|
|
14482
|
+
}), make$14("claimTask", {
|
|
14468
14483
|
payload: { id: String$7 },
|
|
14469
14484
|
success: Boolean$4,
|
|
14470
14485
|
error: String$7
|
|
@@ -14506,11 +14521,12 @@ const encodeRpcParams = (tool, params) => {
|
|
|
14506
14521
|
const handleRequest = (opts, request) => {
|
|
14507
14522
|
switch (request._tag) {
|
|
14508
14523
|
case "TaskComplete": return opts.onTaskComplete(request.summary);
|
|
14509
|
-
case "Delegate": return opts.
|
|
14510
|
-
case "
|
|
14511
|
-
case "
|
|
14512
|
-
case "
|
|
14513
|
-
case "
|
|
14524
|
+
case "Delegate": return opts.agentTasks.delegate(request);
|
|
14525
|
+
case "TaskOutput": return opts.agentTasks.taskOutput(request.id);
|
|
14526
|
+
case "WaitTasks": return opts.agentTasks.waitTasks(request.ids, request);
|
|
14527
|
+
case "MessageAgent": return opts.agentTasks.messageAgent(request);
|
|
14528
|
+
case "StopTask": return opts.agentTasks.stopTask(request.id);
|
|
14529
|
+
case "ListTasks": return opts.agentTasks.listTasks;
|
|
14514
14530
|
case "EnvironmentChanged": return void_;
|
|
14515
14531
|
case "LoopTool": {
|
|
14516
14532
|
const handler = opts.loopTools?.[request.name];
|
|
@@ -14532,16 +14548,14 @@ const exitToResponse = (exit) => {
|
|
|
14532
14548
|
const errorMessage$2 = (error) => typeof error === "string" ? error : error instanceof Error ? error.message : String(error);
|
|
14533
14549
|
const excludedToolNames = (excludeTools) => {
|
|
14534
14550
|
const names = new Set(excludeTools);
|
|
14535
|
-
if (names.has("delegate"))
|
|
14536
|
-
"
|
|
14537
|
-
"
|
|
14538
|
-
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
names.add(
|
|
14543
|
-
names.add("waitJob");
|
|
14544
|
-
names.add("stopJob");
|
|
14551
|
+
if (names.has("delegate")) {
|
|
14552
|
+
names.add("messageAgent");
|
|
14553
|
+
if (names.has("bash")) for (const name of [
|
|
14554
|
+
"taskOutput",
|
|
14555
|
+
"waitTasks",
|
|
14556
|
+
"stopTask",
|
|
14557
|
+
"listTasks"
|
|
14558
|
+
]) names.add(name);
|
|
14545
14559
|
}
|
|
14546
14560
|
return names;
|
|
14547
14561
|
};
|
|
@@ -20595,13 +20609,13 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20595
20609
|
mcpServers?.dts ?? ""
|
|
20596
20610
|
].filter((dts) => dts !== "").join("\n\n"),
|
|
20597
20611
|
offers: (name) => capabilities.tools.includes(name),
|
|
20598
|
-
|
|
20612
|
+
taskPushes: capabilities.taskPushes,
|
|
20599
20613
|
skillsCatalog: options.skills === void 0 ? renderCatalog(capabilities.skills) : renderProvidedCatalog(options.skills),
|
|
20600
20614
|
mcp: mcpServers?.prompt ?? ""
|
|
20601
20615
|
};
|
|
20602
20616
|
const rootMailbox = makeMailbox();
|
|
20603
20617
|
const agentsMd = options.instructions === void 0 ? capabilities.instructions : map$8(options.instructions, renderInstructions);
|
|
20604
|
-
|
|
20618
|
+
const rootTaskOwner = crypto.randomUUID();
|
|
20605
20619
|
const outputBuffer = new Map();
|
|
20606
20620
|
let currentOutputAgent = null;
|
|
20607
20621
|
const history = make$46(empty$1);
|
|
@@ -20633,11 +20647,11 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20633
20647
|
let cacheWrite = 0;
|
|
20634
20648
|
const prompt = opts.history;
|
|
20635
20649
|
const mailbox = opts.mailbox;
|
|
20636
|
-
const
|
|
20650
|
+
const onTask = (task) => task.await.pipe(flatMap$1((final) => sync(() => {
|
|
20637
20651
|
if (final.status === "running") return;
|
|
20638
|
-
mailbox.
|
|
20639
|
-
|
|
20640
|
-
claim:
|
|
20652
|
+
mailbox.tasks.push({
|
|
20653
|
+
task: final,
|
|
20654
|
+
claim: task.claim
|
|
20641
20655
|
});
|
|
20642
20656
|
const event = new JobComplete({
|
|
20643
20657
|
id: final.id,
|
|
@@ -20667,6 +20681,7 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20667
20681
|
agentsMd: getOrElse(agentsMd, () => "")
|
|
20668
20682
|
});
|
|
20669
20683
|
if (typeof opts.system === "string") system += `\n${opts.system}\n`;
|
|
20684
|
+
console.log("system:", system);
|
|
20670
20685
|
function maybeSend(options) {
|
|
20671
20686
|
if (!opts.display) {
|
|
20672
20687
|
offerUnsafe(output, options.part);
|
|
@@ -20712,22 +20727,25 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20712
20727
|
};
|
|
20713
20728
|
mailbox.notify = notify;
|
|
20714
20729
|
const runningChildren = () => Array$1.from(children.values()).filter((child) => child.turn.status === "running");
|
|
20715
|
-
const hasUndelivered = () => completions.some((turn) => !turn.
|
|
20716
|
-
const finishTurn = (turn, exit) => sync(() => {
|
|
20730
|
+
const hasUndelivered = () => completions.some(({ turn }) => !turn.reported);
|
|
20731
|
+
const finishTurn = (child, turn, exit) => sync(() => {
|
|
20717
20732
|
if (isSuccess(exit)) {
|
|
20718
20733
|
turn.status = "completed";
|
|
20719
20734
|
turn.output = exit.value;
|
|
20720
|
-
} else if (hasInterruptsOnly(exit.cause)) turn.status = "
|
|
20735
|
+
} else if (hasInterruptsOnly(exit.cause)) turn.status = "stopped";
|
|
20721
20736
|
else {
|
|
20722
20737
|
turn.status = "failed";
|
|
20723
20738
|
turn.output = causeMessage(exit.cause);
|
|
20724
20739
|
}
|
|
20725
20740
|
offerUnsafe(output, new SubagentComplete({
|
|
20726
|
-
id:
|
|
20741
|
+
id: child.id,
|
|
20727
20742
|
summary: turn.output ?? "",
|
|
20728
|
-
status: turn.status
|
|
20743
|
+
status: turn.status === "stopped" ? "cancelled" : turn.status
|
|
20729
20744
|
}));
|
|
20730
|
-
if (!turn.
|
|
20745
|
+
if (!turn.reported) completions.push({
|
|
20746
|
+
child,
|
|
20747
|
+
turn
|
|
20748
|
+
});
|
|
20731
20749
|
doneUnsafe(turn.done, void_);
|
|
20732
20750
|
notify();
|
|
20733
20751
|
});
|
|
@@ -20737,6 +20755,7 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20737
20755
|
const display = opts.display && !options.background;
|
|
20738
20756
|
const stream = spawn({
|
|
20739
20757
|
agentId: child.id,
|
|
20758
|
+
taskOwner: child.taskOwner,
|
|
20740
20759
|
prompt: make$21(options.prompt),
|
|
20741
20760
|
environmentUpdate: options.environmentUpdate,
|
|
20742
20761
|
system: opts.system,
|
|
@@ -20776,32 +20795,34 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20776
20795
|
}
|
|
20777
20796
|
return void_;
|
|
20778
20797
|
}), as(""), catchTag("AgentFinished", (finished) => succeed$1(finished.summary)));
|
|
20779
|
-
}).pipe(onExit((exit) => finishTurn(turn, exit)), provideSubagentModel, provideContext(runContext), forkIn(runScope, { startImmediately: true }));
|
|
20798
|
+
}).pipe(onExit((exit) => finishTurn(child, turn, exit)), provideSubagentModel, provideContext(runContext), forkIn(runScope, { startImmediately: true }));
|
|
20780
20799
|
});
|
|
20781
|
-
const
|
|
20782
|
-
id: String(id),
|
|
20783
|
-
status: turn.status
|
|
20784
|
-
} : {
|
|
20800
|
+
const childTask = ({ id, prompt, turn }) => ({
|
|
20785
20801
|
id: String(id),
|
|
20802
|
+
kind: "agent",
|
|
20786
20803
|
status: turn.status,
|
|
20787
|
-
|
|
20804
|
+
description: prompt,
|
|
20805
|
+
output: turn.output ?? ""
|
|
20806
|
+
});
|
|
20807
|
+
const reportChild = (child) => {
|
|
20808
|
+
if (child.turn.status !== "running") child.turn.reported = true;
|
|
20809
|
+
return childTask(child);
|
|
20788
20810
|
};
|
|
20789
20811
|
const lookupChild = (id) => suspend(() => {
|
|
20790
20812
|
const child = children.get(id);
|
|
20791
|
-
return child ? succeed$1(child) : fail$1(`
|
|
20813
|
+
return child ? succeed$1(child) : fail$1(`No task with id ${JSON.stringify(id)}. You can only address tasks you started; call listTasks() to see them.`);
|
|
20792
20814
|
});
|
|
20793
|
-
const
|
|
20794
|
-
delegate: fnUntraced(function* ({ prompt, background, environment }) {
|
|
20795
|
-
const agentId = agentCounter++;
|
|
20815
|
+
const agentTasks = {
|
|
20816
|
+
delegate: fnUntraced(function* ({ id, prompt, background, environment }) {
|
|
20796
20817
|
const child = {
|
|
20797
|
-
id:
|
|
20818
|
+
id: Number(id),
|
|
20819
|
+
taskOwner: crypto.randomUUID(),
|
|
20798
20820
|
prompt,
|
|
20799
20821
|
history: make$46(empty$1),
|
|
20800
20822
|
environment: make$46(environment.environment),
|
|
20801
20823
|
mailbox: makeMailbox(),
|
|
20802
|
-
turn: makeTurn(
|
|
20824
|
+
turn: makeTurn(background)
|
|
20803
20825
|
};
|
|
20804
|
-
const id = String(child.id);
|
|
20805
20826
|
children.set(id, child);
|
|
20806
20827
|
const turn = child.turn;
|
|
20807
20828
|
yield* startTurn({
|
|
@@ -20813,29 +20834,22 @@ ${prompt}`,
|
|
|
20813
20834
|
environmentUpdate: getOrUndefined(environment.update),
|
|
20814
20835
|
background
|
|
20815
20836
|
});
|
|
20816
|
-
if (background) return
|
|
20817
|
-
id,
|
|
20818
|
-
status: "running"
|
|
20819
|
-
};
|
|
20837
|
+
if (background) return childTask(child);
|
|
20820
20838
|
yield* _await(turn.done).pipe(onInterrupt(() => interrupt$2(turn.fiber)));
|
|
20821
20839
|
if (turn.status !== "completed") return yield* die(new Error(`Sub-agent ${child.id} ${turn.status}${turn.output ? `: ${turn.output}` : ""}`));
|
|
20822
|
-
return
|
|
20823
|
-
id,
|
|
20824
|
-
status: "completed",
|
|
20825
|
-
output: turn.output ?? ""
|
|
20826
|
-
};
|
|
20840
|
+
return childTask(child);
|
|
20827
20841
|
}),
|
|
20828
|
-
|
|
20829
|
-
|
|
20830
|
-
|
|
20831
|
-
|
|
20832
|
-
|
|
20833
|
-
|
|
20834
|
-
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20842
|
+
taskOutput: (id) => map$5(lookupChild(id), reportChild),
|
|
20843
|
+
waitTasks: fnUntraced(function* (ids, { timeoutMs }) {
|
|
20844
|
+
const targets = yield* forEach$1(ids, lookupChild);
|
|
20845
|
+
yield* gen(function* () {
|
|
20846
|
+
while (true) {
|
|
20847
|
+
const running = targets.find((child) => child.turn.status === "running");
|
|
20848
|
+
if (!running) break;
|
|
20849
|
+
yield* _await(running.turn.done);
|
|
20850
|
+
}
|
|
20851
|
+
}).pipe(timeoutOption(timeoutMs));
|
|
20852
|
+
return targets.map(reportChild);
|
|
20839
20853
|
}),
|
|
20840
20854
|
messageAgent: fnUntraced(function* ({ id, message }) {
|
|
20841
20855
|
const child = yield* lookupChild(id);
|
|
@@ -20845,35 +20859,32 @@ ${prompt}`,
|
|
|
20845
20859
|
resume: () => {}
|
|
20846
20860
|
});
|
|
20847
20861
|
child.mailbox.notify();
|
|
20848
|
-
return
|
|
20862
|
+
return childTask(child);
|
|
20849
20863
|
}
|
|
20850
|
-
child.turn = makeTurn(
|
|
20864
|
+
child.turn = makeTurn(true);
|
|
20851
20865
|
yield* startTurn({
|
|
20852
20866
|
child,
|
|
20853
20867
|
prompt: message,
|
|
20854
20868
|
label: message,
|
|
20855
20869
|
background: true
|
|
20856
20870
|
});
|
|
20857
|
-
return
|
|
20871
|
+
return childTask(child);
|
|
20858
20872
|
}),
|
|
20859
|
-
|
|
20873
|
+
stopTask: fnUntraced(function* (id) {
|
|
20860
20874
|
const child = yield* lookupChild(id);
|
|
20861
20875
|
const turn = child.turn;
|
|
20862
|
-
turn.
|
|
20876
|
+
turn.reported = true;
|
|
20863
20877
|
if (turn.status === "running") yield* interrupt$2(turn.fiber);
|
|
20864
|
-
return
|
|
20878
|
+
return childTask(child);
|
|
20865
20879
|
}),
|
|
20866
|
-
|
|
20867
|
-
id: String(child.id),
|
|
20868
|
-
status: child.turn.status,
|
|
20869
|
-
prompt: child.prompt
|
|
20870
|
-
})))
|
|
20880
|
+
listTasks: sync(() => Array$1.from(children.values(), childTask))
|
|
20871
20881
|
};
|
|
20872
20882
|
const onTaskComplete = (summary) => suspend(() => {
|
|
20873
20883
|
const running = runningChildren();
|
|
20874
20884
|
if (running.length > 0) {
|
|
20875
|
-
const ids = running.map((child) =>
|
|
20876
|
-
|
|
20885
|
+
const ids = running.map((child) => String(child.id));
|
|
20886
|
+
const quoted = ids.map((id) => JSON.stringify(id)).join(", ");
|
|
20887
|
+
return fail$1(`taskComplete was rejected: sub-agents ${quoted} are still running. Call waitTasks({ ids: ${JSON.stringify(ids)} }) to wait for them, or stopTask(id) to stop them, before calling taskComplete.`);
|
|
20877
20888
|
}
|
|
20878
20889
|
finalSummary = some(summary);
|
|
20879
20890
|
return void_;
|
|
@@ -20975,10 +20986,11 @@ ${prompt}`,
|
|
|
20975
20986
|
onEnvironment: (environment) => sync(() => {
|
|
20976
20987
|
set$1(opts.environment, environment);
|
|
20977
20988
|
}),
|
|
20978
|
-
|
|
20989
|
+
agentId: opts.taskOwner,
|
|
20990
|
+
agentTasks,
|
|
20979
20991
|
onTaskComplete,
|
|
20980
20992
|
onImage,
|
|
20981
|
-
|
|
20993
|
+
onTask,
|
|
20982
20994
|
loopTools: scriptLoopTools
|
|
20983
20995
|
}), mkString);
|
|
20984
20996
|
const capped = capOutput(output);
|
|
@@ -21037,25 +21049,21 @@ ${prompt}`,
|
|
|
21037
21049
|
})));
|
|
21038
21050
|
mailbox.messages.clear();
|
|
21039
21051
|
}
|
|
21040
|
-
if (completions.length > 0) {
|
|
21041
|
-
const pushes = completions.splice(0).filter((turn) => {
|
|
21042
|
-
if (turn.delivered) return false;
|
|
21043
|
-
turn.delivered = true;
|
|
21044
|
-
return true;
|
|
21045
|
-
});
|
|
21046
|
-
if (pushes.length > 0) appendHistory(make$21(pushes.map((turn) => ({
|
|
21047
|
-
role: "user",
|
|
21048
|
-
content: `<subagent id="${turn.agentId}" status="${turn.status}">
|
|
21049
|
-
${capOutput(turn.output ?? "").output}
|
|
21050
|
-
</subagent>`
|
|
21051
|
-
}))));
|
|
21052
|
-
}
|
|
21053
|
-
if (mailbox.jobs.length > 0) {
|
|
21052
|
+
if (completions.length > 0 || mailbox.tasks.length > 0) {
|
|
21054
21053
|
const pushes = [];
|
|
21055
|
-
for (const {
|
|
21056
|
-
|
|
21054
|
+
for (const { child, turn } of completions.splice(0)) {
|
|
21055
|
+
if (turn.reported) continue;
|
|
21056
|
+
turn.reported = true;
|
|
21057
|
+
pushes.push({
|
|
21058
|
+
...childTask(child),
|
|
21059
|
+
status: turn.status,
|
|
21060
|
+
output: turn.output ?? ""
|
|
21061
|
+
});
|
|
21062
|
+
}
|
|
21063
|
+
for (const { task, claim } of mailbox.tasks.splice(0)) if (yield* claim) pushes.push(task);
|
|
21064
|
+
if (pushes.length > 0) appendHistory(make$21(pushes.map((task) => ({
|
|
21057
21065
|
role: "user",
|
|
21058
|
-
content:
|
|
21066
|
+
content: taskMessage(task)
|
|
21059
21067
|
}))));
|
|
21060
21068
|
}
|
|
21061
21069
|
yield* compactWithEvents("threshold", compactIfNeeded({
|
|
@@ -21260,7 +21268,8 @@ ${capOutput(turn.output ?? "").output}
|
|
|
21260
21268
|
history,
|
|
21261
21269
|
environment,
|
|
21262
21270
|
send: (options) => spawn({
|
|
21263
|
-
agentId:
|
|
21271
|
+
agentId: 0,
|
|
21272
|
+
taskOwner: rootTaskOwner,
|
|
21264
21273
|
prompt: make$21(options.prompt),
|
|
21265
21274
|
system: options.system,
|
|
21266
21275
|
history,
|
|
@@ -21287,21 +21296,20 @@ const make$8 = makeWith$1({});
|
|
|
21287
21296
|
const makeMailbox = () => ({
|
|
21288
21297
|
messages: new Set(),
|
|
21289
21298
|
notify: () => {},
|
|
21290
|
-
|
|
21299
|
+
tasks: [],
|
|
21291
21300
|
emit: void 0,
|
|
21292
21301
|
events: []
|
|
21293
21302
|
});
|
|
21294
|
-
const
|
|
21295
|
-
const exitCode =
|
|
21296
|
-
return `<
|
|
21297
|
-
${capOutput(
|
|
21298
|
-
</
|
|
21303
|
+
const taskMessage = (task) => {
|
|
21304
|
+
const exitCode = task.exitCode === void 0 ? "" : ` exitCode="${task.exitCode}"`;
|
|
21305
|
+
return `<task id="${task.id}" kind="${task.kind}" status="${task.status}"${exitCode}>
|
|
21306
|
+
${capOutput(task.output).output}
|
|
21307
|
+
</task>`;
|
|
21299
21308
|
};
|
|
21300
|
-
const makeTurn = (
|
|
21301
|
-
agentId,
|
|
21309
|
+
const makeTurn = (background) => ({
|
|
21302
21310
|
status: "running",
|
|
21303
21311
|
output: void 0,
|
|
21304
|
-
|
|
21312
|
+
reported: !background,
|
|
21305
21313
|
done: makeUnsafe$1(),
|
|
21306
21314
|
fiber: void 0
|
|
21307
21315
|
});
|
|
@@ -21324,7 +21332,7 @@ const environmentUpdateMessage = (text) => make$21([{
|
|
|
21324
21332
|
}]);
|
|
21325
21333
|
const startsWith = (message, prefix) => message.role === "user" && message.content.length === 1 && message.content[0].type === "text" && message.content[0].text.trimStart().startsWith(prefix);
|
|
21326
21334
|
const isEnvironmentUpdate = (message) => startsWith(message, environmentUpdateOpen);
|
|
21327
|
-
const isInjectedMessage = (message) => isEnvironmentUpdate(message) || startsWith(message, "<subagent ");
|
|
21335
|
+
const isInjectedMessage = (message) => isEnvironmentUpdate(message) || startsWith(message, "<task ") || startsWith(message, "<subagent ") || startsWith(message, "<job ");
|
|
21328
21336
|
const renderInstructions = (content) => `# Project instructions
|
|
21329
21337
|
|
|
21330
21338
|
**ALWAYS follow these instructions when completing tasks**:
|
|
@@ -21339,6 +21347,19 @@ ${options.toolInstructions}
|
|
|
21339
21347
|
${options.agentsMd}
|
|
21340
21348
|
`;
|
|
21341
21349
|
const when = (condition, text) => condition ? text : "";
|
|
21350
|
+
const taskInstructions = (tools) => {
|
|
21351
|
+
const bash = tools.offers("bash");
|
|
21352
|
+
const delegate = tools.offers("delegate");
|
|
21353
|
+
if (!bash && !delegate) return "";
|
|
21354
|
+
const functions = [
|
|
21355
|
+
["taskOutput", `"taskOutput" reads one`],
|
|
21356
|
+
["waitTasks", `"waitTasks" waits for a list of them and returns any still running at its timeout as "running"`],
|
|
21357
|
+
["stopTask", `"stopTask" stops one`],
|
|
21358
|
+
["listTasks", `"listTasks" lists yours`]
|
|
21359
|
+
].filter(([name]) => tools.offers(name)).map(([, text]) => text);
|
|
21360
|
+
return `
|
|
21361
|
+
- ${bash && delegate ? "Background commands and sub-agents are" : bash ? "Background commands are" : "Sub-agents are"} tasks with ids.${functions.length === 0 ? "" : ` ${functions.length === 1 ? functions[0] : `${functions.slice(0, -1).join(", ")} and ${functions.at(-1)}`}.`}${tools.taskPushes ? ` When a task ends, its status and output are sent to you as a \`<task id="..." kind="..." status="...">\` message, unless a task function already gave you its final status, so you do not need to poll.` : bash && tools.offers("taskOutput") ? ` Background commands are not sent to you when they end: check them with "taskOutput".` : ""}`;
|
|
21362
|
+
};
|
|
21342
21363
|
const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL AVAILABLE: "execute", to run javascript code to do your work.
|
|
21343
21364
|
|
|
21344
21365
|
- Use \`console.log\` to print any output you need.
|
|
@@ -21346,11 +21367,10 @@ const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL
|
|
|
21346
21367
|
- Use top level await.${when(tools.offers("search") && tools.offers("rg"), `
|
|
21347
21368
|
- Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`)}${when(tools.offers("applyPatch"), `
|
|
21348
21369
|
- You can add / update / remove multiple files in one go with "applyPatch".${when(tools.offers("writeFile"), ` Prefer it over "writeFile" to update existing files.`)}`)}${when(tools.offers("bash"), `
|
|
21349
|
-
- Avoid passing scripts into the "bash" function, and instead write javascript
|
|
21350
|
-
- Pass \`background: true\` to "bash" for commands that keep running, such as dev servers or watchers. A command still running at its timeout is moved to the background instead of being stopped. Use "jobOutput" and "stopJob" with the returned job id.${when(tools.offers("waitJob"), ` "bash" returns a task, and rejects when a command that has not been moved to the background fails. Use "waitJob" to wait for a running task; it returns the task as "running" if its timeout passes first. A background task that fails is returned with status "failed" and its \`exitCode\`.`)}${when(tools.jobPushes, ` When a job ends, its status and output are sent to you as a \`<job id="..." status="..." exitCode="...">\` message, unless "jobOutput" or "stopJob" already gave you its final status. You do not need to poll jobs with "jobOutput" to find out when they end.`)}`)}
|
|
21370
|
+
- Avoid passing scripts into the "bash" function, and instead write javascript.`)}
|
|
21351
21371
|
- Variables are not shared between executions.
|
|
21352
21372
|
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(tools.offers("delegate"), `
|
|
21353
|
-
- "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs:
|
|
21373
|
+
- "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(tools.offers("messageAgent"), ` Use "messageAgent" to send a message to a sub-agent.`)}`)}${taskInstructions(tools)}${when(!conversationMode, `
|
|
21354
21374
|
|
|
21355
21375
|
When you have fully completed your task, call the "taskComplete" function with the final output.
|
|
21356
21376
|
Make sure every detail of the task is done before calling "taskComplete".${when(tools.offers("delegate"), `
|
|
@@ -28493,7 +28513,7 @@ const transformToolCallParams$1 = fnUntraced(function* (options, toolName, toolP
|
|
|
28493
28513
|
return yield* decodeEffect(codec)(toolParams).pipe(flatMap$1((decoded) => encodeUnknownEffect(tool.parametersSchema)(decoded)), orElseSucceed(() => toolParams));
|
|
28494
28514
|
});
|
|
28495
28515
|
// package.json
|
|
28496
|
-
var version$1 = "0.
|
|
28516
|
+
var version$1 = "0.22.1";
|
|
28497
28517
|
// src/ClaudeAgent.ts
|
|
28498
28518
|
const minimumClaudeCodeVersion = "2.1.248";
|
|
28499
28519
|
const serverName = "clanka";
|