clanka 0.19.1 → 0.21.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 +14 -0
- package/dist/Acp.js.map +1 -1
- package/dist/Acp.test.js +78 -1
- package/dist/Acp.test.js.map +1 -1
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +64 -3
- package/dist/Agent.js.map +1 -1
- package/dist/AgentBashJobs.test.d.ts +2 -0
- package/dist/AgentBashJobs.test.d.ts.map +1 -0
- package/dist/AgentBashJobs.test.js +177 -0
- package/dist/AgentBashJobs.test.js.map +1 -0
- package/dist/AgentExecutor.d.ts +35 -2
- package/dist/AgentExecutor.d.ts.map +1 -1
- package/dist/AgentExecutor.js +74 -3
- package/dist/AgentExecutor.js.map +1 -1
- package/dist/AgentExecutor.test.js +87 -11
- package/dist/AgentExecutor.test.js.map +1 -1
- package/dist/AgentOutput.d.ts +19 -4
- package/dist/AgentOutput.d.ts.map +1 -1
- package/dist/AgentOutput.js +15 -0
- package/dist/AgentOutput.js.map +1 -1
- package/dist/AgentSubagents.test.js +2 -2
- package/dist/AgentSubagents.test.js.map +1 -1
- package/dist/AgentTools.d.ts +119 -7
- package/dist/AgentTools.d.ts.map +1 -1
- package/dist/AgentTools.js +106 -39
- package/dist/AgentTools.js.map +1 -1
- package/dist/OutputFormatter.d.ts.map +1 -1
- package/dist/OutputFormatter.js +6 -0
- package/dist/OutputFormatter.js.map +1 -1
- package/dist/bin/{OutputFormatter-Dqxyk2qD.mjs → OutputFormatter-U02YKTfy.mjs} +5 -1
- package/dist/bin/{OutputFormatter-Dqxyk2qD.mjs.map → OutputFormatter-U02YKTfy.mjs.map} +1 -1
- package/dist/bin/cli.mjs +187 -44
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Acp.test.ts +111 -1
- package/src/Acp.ts +15 -0
- package/src/Agent.ts +100 -1
- package/src/AgentBashJobs.test.ts +299 -0
- package/src/AgentExecutor.test.ts +127 -11
- package/src/AgentExecutor.ts +87 -0
- package/src/AgentOutput.ts +19 -0
- package/src/AgentSubagents.test.ts +2 -2
- package/src/AgentTools.ts +153 -48
- package/src/OutputFormatter.ts +7 -0
package/dist/bin/cli.mjs
CHANGED
|
@@ -11579,6 +11579,7 @@ const BashJob = Struct({
|
|
|
11579
11579
|
exitCode: optional$2(Number$2),
|
|
11580
11580
|
output: String$7
|
|
11581
11581
|
});
|
|
11582
|
+
var JobWatcher = class extends Reference("clanka/AgentTools/JobWatcher", { defaultValue: () => () => void_ }) {};
|
|
11582
11583
|
const defaultBashTimeout = minutes(10);
|
|
11583
11584
|
const defaultMcpCallTimeout = minutes(10);
|
|
11584
11585
|
var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", { defaultValue: () => ({
|
|
@@ -11586,13 +11587,13 @@ var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", {
|
|
|
11586
11587
|
outputChars: void 0
|
|
11587
11588
|
}) }) {};
|
|
11588
11589
|
const makeBashTool = (timeout) => make$17("bash", {
|
|
11589
|
-
description: "Run a bash command and return
|
|
11590
|
+
description: "Run a bash command and return a task with its job id, status, exit code and output. A command that fails before it is returned rejects with its exit code and output. With `background: true` it returns straight away with status \"running\" while the command keeps going. A command still running at its timeout is not stopped: it is moved to the background and returned as \"running\" with the output so far. Wait for a job with \"waitJob\", read it with \"jobOutput\" and stop it with \"stopJob\"; a background job that fails is reported with status \"failed\" and its exitCode.",
|
|
11590
11591
|
parameters: Struct({
|
|
11591
11592
|
command: String$7,
|
|
11592
11593
|
timeoutMs: optional$2(Finite).annotate({ documentation: `How long to wait in ms before moving the command to the background (default and max: ${toMillis(timeout)})` }),
|
|
11593
|
-
background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background and return
|
|
11594
|
+
background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background and return it as \"running\" without waiting" })
|
|
11594
11595
|
}).annotate({ identifier: "command" }),
|
|
11595
|
-
success:
|
|
11596
|
+
success: BashJob,
|
|
11596
11597
|
dependencies: [CurrentDirectory]
|
|
11597
11598
|
});
|
|
11598
11599
|
const globNamesDirectory = (glob) => glob.split("/").slice(0, -1).some((segment) => segment.length > 0 && !/[*?[\]{}]/.test(segment));
|
|
@@ -11671,6 +11672,14 @@ const AgentTools = make$16(make$17("changeDirectory", {
|
|
|
11671
11672
|
parameters: String$7.annotate({ identifier: "id" }),
|
|
11672
11673
|
success: BashJob,
|
|
11673
11674
|
failure: String$7
|
|
11675
|
+
}), make$17("waitJob", {
|
|
11676
|
+
description: "Wait for a bash job to end and return its task. When the timeout passes first, the task is returned as \"running\" and the command keeps going.",
|
|
11677
|
+
parameters: Struct({
|
|
11678
|
+
id: String$7,
|
|
11679
|
+
timeoutMs: optional$2(Finite).annotate({ documentation: "How long to wait in ms (default and max: the bash timeout)" })
|
|
11680
|
+
}),
|
|
11681
|
+
success: BashJob,
|
|
11682
|
+
failure: String$7
|
|
11674
11683
|
}), make$17("stopJob", {
|
|
11675
11684
|
description: "Stop a background bash job and return its final status and output.",
|
|
11676
11685
|
parameters: String$7.annotate({ identifier: "id" }),
|
|
@@ -11745,34 +11754,42 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11745
11754
|
});
|
|
11746
11755
|
const jobs = new Map();
|
|
11747
11756
|
let nextJobId = 1;
|
|
11748
|
-
const addJob = (
|
|
11757
|
+
const addJob = (command) => {
|
|
11749
11758
|
const id = String(nextJobId++);
|
|
11759
|
+
const running = {
|
|
11760
|
+
...command,
|
|
11761
|
+
reported: false
|
|
11762
|
+
};
|
|
11750
11763
|
jobs.set(id, running);
|
|
11751
|
-
return
|
|
11764
|
+
return {
|
|
11765
|
+
id,
|
|
11766
|
+
running
|
|
11767
|
+
};
|
|
11752
11768
|
};
|
|
11769
|
+
const watchJob = fnUntraced(function* (id, running) {
|
|
11770
|
+
yield* (yield* JobWatcher)({
|
|
11771
|
+
id,
|
|
11772
|
+
await: await_(running.fiber).pipe(map$5(() => jobInfo(id, running))),
|
|
11773
|
+
claim: sync(() => {
|
|
11774
|
+
if (running.reported) return false;
|
|
11775
|
+
running.reported = true;
|
|
11776
|
+
return true;
|
|
11777
|
+
})
|
|
11778
|
+
});
|
|
11779
|
+
});
|
|
11753
11780
|
const findJob = (id) => {
|
|
11754
11781
|
const running = jobs.get(id);
|
|
11755
11782
|
return running === void 0 ? fail$1(`No background job with id "${id}"`) : succeed$1(running);
|
|
11756
11783
|
};
|
|
11757
|
-
const
|
|
11758
|
-
const
|
|
11784
|
+
const reportJob = (id, running) => {
|
|
11785
|
+
const job = jobInfo(id, running);
|
|
11786
|
+
if (job.status !== "running") running.reported = true;
|
|
11787
|
+
return job;
|
|
11788
|
+
};
|
|
11789
|
+
const awaitCommand = (running, timeout) => {
|
|
11759
11790
|
const awaited = await_(running.fiber);
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
const timeoutMs = toMillis(timeout);
|
|
11763
|
-
if (onTimeout === "stop") {
|
|
11764
|
-
yield* interrupt$2(running.fiber);
|
|
11765
|
-
return yield* die(new Error(`Command timed out after ${timeoutMs}ms`));
|
|
11766
|
-
}
|
|
11767
|
-
const id = addJob(running);
|
|
11768
|
-
const output = running.output();
|
|
11769
|
-
return `${output}${output === "" || output.endsWith("\n") ? "" : "\n"}[Still running after ${timeoutMs}ms, so it was moved to the background as job ${id}. ${jobUsage(id)}]`;
|
|
11770
|
-
}
|
|
11771
|
-
const exitCode = yield* exit.value;
|
|
11772
|
-
const output = running.output();
|
|
11773
|
-
if (exitCode === 0) return output;
|
|
11774
|
-
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${output}`));
|
|
11775
|
-
});
|
|
11791
|
+
return (timeout === void 0 ? asSome(awaited) : timeoutOption(awaited, timeout)).pipe(onInterrupt(() => interrupt$2(running.fiber)));
|
|
11792
|
+
};
|
|
11776
11793
|
const readImage = fnUntraced(function* (path, extensionType, options) {
|
|
11777
11794
|
if (options.startLine !== void 0 || options.endLine !== void 0) return yield* die(new Error(`startLine / endLine are not supported for images: ${path}`));
|
|
11778
11795
|
const bytes = yield* readBoundedFile(fs, path).pipe(catchReason("PlatformError", "NotFound", () => succeed$1(null)), orDie);
|
|
@@ -11877,8 +11894,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11877
11894
|
return yield* promise(() => import("./index.min-ClUfQ5ji.mjs").then((Glob) => Glob.glob(pattern, { cwd })));
|
|
11878
11895
|
}),
|
|
11879
11896
|
bash: fn("AgentTools.bash")(function* (options) {
|
|
11880
|
-
const
|
|
11881
|
-
const maxMs = toMillis(limits.timeout ?? defaultBashTimeout);
|
|
11897
|
+
const maxMs = bashTimeoutMs(yield* CommandLimits);
|
|
11882
11898
|
const timeoutMs = Math.min(options.timeoutMs ?? maxMs, maxMs);
|
|
11883
11899
|
yield* logInfo(`Calling "bash"`).pipe(annotateLogs({
|
|
11884
11900
|
...options,
|
|
@@ -11889,22 +11905,43 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11889
11905
|
cwd,
|
|
11890
11906
|
stdin: "ignore"
|
|
11891
11907
|
});
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11908
|
+
const { id, running } = addJob(yield* startCommand(cmd));
|
|
11909
|
+
if (options.background !== true) {
|
|
11910
|
+
const exit = yield* awaitCommand(running, millis(timeoutMs));
|
|
11911
|
+
if (isSome(exit)) {
|
|
11912
|
+
const exitCode = yield* exit.value;
|
|
11913
|
+
const job = reportJob(id, running);
|
|
11914
|
+
if (exitCode === 0) return job;
|
|
11915
|
+
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${job.output}`));
|
|
11916
|
+
}
|
|
11895
11917
|
}
|
|
11896
|
-
|
|
11918
|
+
const job = reportJob(id, running);
|
|
11919
|
+
if (job.status === "running") yield* watchJob(id, running);
|
|
11920
|
+
return job;
|
|
11897
11921
|
}, orDie),
|
|
11898
11922
|
jobOutput: fn("AgentTools.jobOutput")(function* (input) {
|
|
11899
11923
|
const id = yield* decodeJobOutput(input);
|
|
11900
11924
|
yield* logInfo(`Calling "jobOutput"`).pipe(annotateLogs({ id }));
|
|
11901
|
-
return
|
|
11925
|
+
return reportJob(id, yield* findJob(id));
|
|
11926
|
+
}),
|
|
11927
|
+
waitJob: fn("AgentTools.waitJob")(function* (input) {
|
|
11928
|
+
const options = yield* decodeWaitJob(input);
|
|
11929
|
+
const maxMs = bashTimeoutMs(yield* CommandLimits);
|
|
11930
|
+
const timeoutMs = Math.min(options.timeoutMs ?? maxMs, maxMs);
|
|
11931
|
+
yield* logInfo(`Calling "waitJob"`).pipe(annotateLogs({
|
|
11932
|
+
id: options.id,
|
|
11933
|
+
timeoutMs
|
|
11934
|
+
}));
|
|
11935
|
+
const running = yield* findJob(options.id);
|
|
11936
|
+
yield* timeoutOption(await_(running.fiber), timeoutMs);
|
|
11937
|
+
return reportJob(options.id, running);
|
|
11902
11938
|
}),
|
|
11903
11939
|
stopJob: fn("AgentTools.stopJob")(function* (input) {
|
|
11904
11940
|
const id = yield* decodeStopJob(input);
|
|
11905
11941
|
yield* logInfo(`Calling "stopJob"`).pipe(annotateLogs({ id }));
|
|
11906
11942
|
const running = yield* findJob(id);
|
|
11907
11943
|
yield* interrupt$2(running.fiber);
|
|
11944
|
+
running.reported = true;
|
|
11908
11945
|
return jobInfo(id, running);
|
|
11909
11946
|
}),
|
|
11910
11947
|
gh: fn("AgentTools.gh")(function* (args) {
|
|
@@ -11915,7 +11952,16 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
|
|
|
11915
11952
|
stdin: "ignore"
|
|
11916
11953
|
});
|
|
11917
11954
|
const { timeout } = yield* CommandLimits;
|
|
11918
|
-
|
|
11955
|
+
const running = yield* startCommand(cmd);
|
|
11956
|
+
const exit = yield* awaitCommand(running, timeout);
|
|
11957
|
+
if (isNone(exit)) {
|
|
11958
|
+
yield* interrupt$2(running.fiber);
|
|
11959
|
+
return yield* die(new Error(`Command timed out after ${toMillis(timeout)}ms`));
|
|
11960
|
+
}
|
|
11961
|
+
const exitCode = yield* exit.value;
|
|
11962
|
+
const output = running.output();
|
|
11963
|
+
if (exitCode === 0) return output;
|
|
11964
|
+
return yield* die(new Error(`Command failed with exit code ${exitCode}: ${output}`));
|
|
11919
11965
|
}, orDie),
|
|
11920
11966
|
webSearch: fn("AgentTools.webSearch")(function* (options) {
|
|
11921
11967
|
yield* logInfo(`Calling "webSearch"`).pipe(annotateLogs(options));
|
|
@@ -12061,8 +12107,9 @@ const decodeWaitAgents = decodeParams$1(AgentTools.tools.waitAgents.parametersSc
|
|
|
12061
12107
|
const decodeMessageAgent = decodeParams$1(AgentTools.tools.messageAgent.parametersSchema, "messageAgent requires an options object, for example: messageAgent({ id: \"3\", message: \"...\" }).");
|
|
12062
12108
|
const decodeStopAgent = decodeParams$1(AgentTools.tools.stopAgent.parametersSchema, "stopAgent requires an agent id, for example: stopAgent(\"3\").");
|
|
12063
12109
|
const decodeJobOutput = decodeParams$1(AgentTools.tools.jobOutput.parametersSchema, "jobOutput requires a job id, for example: jobOutput(\"1\").");
|
|
12110
|
+
const bashTimeoutMs = (limits) => toMillis(limits.timeout ?? defaultBashTimeout);
|
|
12111
|
+
const decodeWaitJob = decodeParams$1(AgentTools.tools.waitJob.parametersSchema, "waitJob requires an options object, for example: waitJob({ id: \"1\" }) or waitJob({ id: \"1\", timeoutMs: 60000 }).");
|
|
12064
12112
|
const decodeStopJob = decodeParams$1(AgentTools.tools.stopJob.parametersSchema, "stopJob requires a job id, for example: stopJob(\"1\").");
|
|
12065
|
-
const jobUsage = (id) => `Use jobOutput("${id}") for its status and output, or stopJob("${id}") to stop it.`;
|
|
12066
12113
|
const jobInfo = (id, running) => {
|
|
12067
12114
|
const exit = running.fiber.pollUnsafe();
|
|
12068
12115
|
const output = running.output();
|
|
@@ -14104,7 +14151,8 @@ var Capabilities = class extends Class$1("Capabilities")({
|
|
|
14104
14151
|
supportsSearch: Boolean$4,
|
|
14105
14152
|
environment: ExecutionEnvironment,
|
|
14106
14153
|
tools: ArraySchema(String$7),
|
|
14107
|
-
skills: ArraySchema(Skill).pipe(withDecodingDefaultKey(succeed$1([])), withConstructorDefault(succeed$1([])))
|
|
14154
|
+
skills: ArraySchema(Skill).pipe(withDecodingDefaultKey(succeed$1([])), withConstructorDefault(succeed$1([]))),
|
|
14155
|
+
jobPushes: Boolean$4.pipe(withDecodingDefaultKey(succeed$1(false)), withConstructorDefault(succeed$1(false)))
|
|
14108
14156
|
}) {};
|
|
14109
14157
|
const makeLocal = (options) => map$5(makeLocalWith(options), (local) => local.executor);
|
|
14110
14158
|
const makeLocalWith = fnUntraced(function* (options) {
|
|
@@ -14199,7 +14247,7 @@ const makeLocalWith = fnUntraced(function* (options) {
|
|
|
14199
14247
|
...options,
|
|
14200
14248
|
environment
|
|
14201
14249
|
})))
|
|
14202
|
-
}), add(ImageAttacher, opts.onImage), add(CommandLimits, commandLimits), add(Console, console), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14250
|
+
}), add(ImageAttacher, opts.onImage), add(JobWatcher, opts.onJob ?? (() => void_)), add(CommandLimits, commandLimits), add(Console, console), add(CurrentLogAnnotations, {}), isSome(search) ? add(SemanticSearch, search.value) : identity);
|
|
14203
14251
|
yield* gen(function* () {
|
|
14204
14252
|
const source = prepareScript(opts.script);
|
|
14205
14253
|
const settled = yield* make$42();
|
|
@@ -14284,7 +14332,8 @@ const makeLocalWith = fnUntraced(function* (options) {
|
|
|
14284
14332
|
seen: []
|
|
14285
14333
|
}),
|
|
14286
14334
|
tools: Object.keys(tools.tools),
|
|
14287
|
-
skills
|
|
14335
|
+
skills,
|
|
14336
|
+
jobPushes: true
|
|
14288
14337
|
});
|
|
14289
14338
|
}),
|
|
14290
14339
|
execute: (opts) => execute(opts),
|
|
@@ -14313,7 +14362,8 @@ const makeRpc = gen(function* () {
|
|
|
14313
14362
|
return client.execute({
|
|
14314
14363
|
script: opts.script,
|
|
14315
14364
|
environment: opts.environment,
|
|
14316
|
-
loopTools: Object.keys(opts.loopTools ?? {})
|
|
14365
|
+
loopTools: Object.keys(opts.loopTools ?? {}),
|
|
14366
|
+
...opts.onJob === void 0 ? {} : { watchJobs: true }
|
|
14317
14367
|
}).pipe(tap$1((part) => {
|
|
14318
14368
|
switch (part._tag) {
|
|
14319
14369
|
case "Text": return void_;
|
|
@@ -14333,6 +14383,15 @@ const makeRpc = gen(function* () {
|
|
|
14333
14383
|
case "Environment":
|
|
14334
14384
|
latest = part.environment;
|
|
14335
14385
|
return void_;
|
|
14386
|
+
case "Job": {
|
|
14387
|
+
if (opts.onJob === void 0) return void_;
|
|
14388
|
+
const id = part.id;
|
|
14389
|
+
return opts.onJob({
|
|
14390
|
+
id,
|
|
14391
|
+
await: orDie(client.awaitJob({ id })),
|
|
14392
|
+
claim: orDie(client.claimJob({ id }))
|
|
14393
|
+
});
|
|
14394
|
+
}
|
|
14336
14395
|
}
|
|
14337
14396
|
}), orDie$2, filterMap((part) => part._tag === "Text" ? succeed$2(part.text) : failVoid), ensuring$1(suspend(() => opts.onEnvironment(latest))));
|
|
14338
14397
|
}).pipe(unwrap$6),
|
|
@@ -14386,7 +14445,8 @@ const ExecuteOutput = TaggedUnion({
|
|
|
14386
14445
|
mediaType: ImageMediaType,
|
|
14387
14446
|
data: Uint8Array$2
|
|
14388
14447
|
},
|
|
14389
|
-
Environment: { environment: ExecutionEnvironment }
|
|
14448
|
+
Environment: { environment: ExecutionEnvironment },
|
|
14449
|
+
Job: { id: String$7 }
|
|
14390
14450
|
});
|
|
14391
14451
|
var Rpcs = class extends make$12(make$14("capabilities", { success: Capabilities }), make$14("respond", { payload: {
|
|
14392
14452
|
id: Finite,
|
|
@@ -14395,10 +14455,19 @@ var Rpcs = class extends make$12(make$14("capabilities", { success: Capabilities
|
|
|
14395
14455
|
payload: Struct({
|
|
14396
14456
|
script: String$7,
|
|
14397
14457
|
environment: ExecutionEnvironment,
|
|
14398
|
-
loopTools: ArraySchema(String$7).pipe(withDecodingDefaultKey(succeed$1([])))
|
|
14458
|
+
loopTools: ArraySchema(String$7).pipe(withDecodingDefaultKey(succeed$1([]))),
|
|
14459
|
+
watchJobs: optionalKey(Boolean$4)
|
|
14399
14460
|
}),
|
|
14400
14461
|
success: ExecuteOutput,
|
|
14401
14462
|
stream: true
|
|
14463
|
+
}), make$14("awaitJob", {
|
|
14464
|
+
payload: { id: String$7 },
|
|
14465
|
+
success: BashJob,
|
|
14466
|
+
error: String$7
|
|
14467
|
+
}), make$14("claimJob", {
|
|
14468
|
+
payload: { id: String$7 },
|
|
14469
|
+
success: Boolean$4,
|
|
14470
|
+
error: String$7
|
|
14402
14471
|
}), make$14("renderEnvironment", {
|
|
14403
14472
|
payload: {
|
|
14404
14473
|
environment: ExecutionEnvironment,
|
|
@@ -14471,6 +14540,7 @@ const excludedToolNames = (excludeTools) => {
|
|
|
14471
14540
|
]) names.add(name);
|
|
14472
14541
|
if (names.has("bash")) {
|
|
14473
14542
|
names.add("jobOutput");
|
|
14543
|
+
names.add("waitJob");
|
|
14474
14544
|
names.add("stopJob");
|
|
14475
14545
|
}
|
|
14476
14546
|
return names;
|
|
@@ -20457,6 +20527,16 @@ var SessionRestarted = class extends TaggedClass$2()("SessionRestarted", {
|
|
|
20457
20527
|
cacheWrite: Number$2
|
|
20458
20528
|
}) {};
|
|
20459
20529
|
var EnvironmentUpdated = class extends TaggedClass$2()("EnvironmentUpdated", { update: String$7 }) {};
|
|
20530
|
+
var JobComplete = class extends TaggedClass$2()("JobComplete", {
|
|
20531
|
+
id: String$7,
|
|
20532
|
+
status: Literals$2([
|
|
20533
|
+
"completed",
|
|
20534
|
+
"failed",
|
|
20535
|
+
"stopped"
|
|
20536
|
+
]),
|
|
20537
|
+
exitCode: optional$2(Number$2),
|
|
20538
|
+
output: String$7
|
|
20539
|
+
}) {};
|
|
20460
20540
|
const ContentPart = Union([
|
|
20461
20541
|
ReasoningStart,
|
|
20462
20542
|
ReasoningDelta,
|
|
@@ -20471,7 +20551,8 @@ const ContentPart = Union([
|
|
|
20471
20551
|
CompactionStarted,
|
|
20472
20552
|
CompactionEnded,
|
|
20473
20553
|
SessionRestarted,
|
|
20474
|
-
EnvironmentUpdated
|
|
20554
|
+
EnvironmentUpdated,
|
|
20555
|
+
JobComplete
|
|
20475
20556
|
]);
|
|
20476
20557
|
var SubagentPart = class extends TaggedClass$2()("SubagentPart", {
|
|
20477
20558
|
id: Number$2,
|
|
@@ -20498,6 +20579,7 @@ const TypeId$2 = "~clanka/Agent";
|
|
|
20498
20579
|
const Agent = Service("clanka/Agent");
|
|
20499
20580
|
const makeWith$1 = fnUntraced(function* (options) {
|
|
20500
20581
|
const executor = yield* AgentExecutor;
|
|
20582
|
+
const agentScope = yield* scope;
|
|
20501
20583
|
const singleTool = yield* SingleTools.pipe(provide$1(SingleToolHandlers));
|
|
20502
20584
|
const capabilities = yield* executor.capabilities;
|
|
20503
20585
|
const mcpServers = getOrUndefined(yield* serviceOption(McpServers));
|
|
@@ -20513,6 +20595,7 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20513
20595
|
mcpServers?.dts ?? ""
|
|
20514
20596
|
].filter((dts) => dts !== "").join("\n\n"),
|
|
20515
20597
|
offers: (name) => capabilities.tools.includes(name),
|
|
20598
|
+
jobPushes: capabilities.jobPushes,
|
|
20516
20599
|
skillsCatalog: options.skills === void 0 ? renderCatalog(capabilities.skills) : renderProvidedCatalog(options.skills),
|
|
20517
20600
|
mcp: mcpServers?.prompt ?? ""
|
|
20518
20601
|
};
|
|
@@ -20550,6 +20633,21 @@ const makeWith$1 = fnUntraced(function* (options) {
|
|
|
20550
20633
|
let cacheWrite = 0;
|
|
20551
20634
|
const prompt = opts.history;
|
|
20552
20635
|
const mailbox = opts.mailbox;
|
|
20636
|
+
const onJob = (job) => job.await.pipe(flatMap$1((final) => sync(() => {
|
|
20637
|
+
if (final.status === "running") return;
|
|
20638
|
+
mailbox.jobs.push({
|
|
20639
|
+
job: final,
|
|
20640
|
+
claim: job.claim
|
|
20641
|
+
});
|
|
20642
|
+
const event = new JobComplete({
|
|
20643
|
+
id: final.id,
|
|
20644
|
+
status: final.status,
|
|
20645
|
+
...final.exitCode === void 0 ? {} : { exitCode: final.exitCode },
|
|
20646
|
+
output: final.output
|
|
20647
|
+
});
|
|
20648
|
+
if (mailbox.emit === void 0) mailbox.events.push(event);
|
|
20649
|
+
else mailbox.emit(event);
|
|
20650
|
+
})), forkIn(agentScope), asVoid);
|
|
20553
20651
|
const appendHistory = (input) => {
|
|
20554
20652
|
update(prompt, concat(input));
|
|
20555
20653
|
if (!opts.historyEvents) return;
|
|
@@ -20880,6 +20978,7 @@ ${prompt}`,
|
|
|
20880
20978
|
subagents,
|
|
20881
20979
|
onTaskComplete,
|
|
20882
20980
|
onImage,
|
|
20981
|
+
onJob,
|
|
20883
20982
|
loopTools: scriptLoopTools
|
|
20884
20983
|
}), mkString);
|
|
20885
20984
|
const capped = capOutput(output);
|
|
@@ -20912,9 +21011,19 @@ ${prompt}`,
|
|
|
20912
21011
|
const messages = opts.prompt.content.filter((message) => message.role !== "system");
|
|
20913
21012
|
if (messages.length > 0) yield* offer(output, new HistoryAppended({ messages }));
|
|
20914
21013
|
}
|
|
21014
|
+
for (const part of mailbox.events.splice(0)) maybeSend({
|
|
21015
|
+
agentId,
|
|
21016
|
+
part
|
|
21017
|
+
});
|
|
21018
|
+
const emit = (part) => maybeSend({
|
|
21019
|
+
agentId,
|
|
21020
|
+
part
|
|
21021
|
+
});
|
|
21022
|
+
mailbox.emit = emit;
|
|
20915
21023
|
yield* gen(function* () {
|
|
20916
21024
|
while (true) {
|
|
20917
21025
|
if (isSome(finalSummary)) {
|
|
21026
|
+
mailbox.emit = void 0;
|
|
20918
21027
|
yield* fail$7(output, new AgentFinished({ summary: finalSummary.value }));
|
|
20919
21028
|
return;
|
|
20920
21029
|
}
|
|
@@ -20941,6 +21050,14 @@ ${capOutput(turn.output ?? "").output}
|
|
|
20941
21050
|
</subagent>`
|
|
20942
21051
|
}))));
|
|
20943
21052
|
}
|
|
21053
|
+
if (mailbox.jobs.length > 0) {
|
|
21054
|
+
const pushes = [];
|
|
21055
|
+
for (const { job, claim } of mailbox.jobs.splice(0)) if (yield* claim) pushes.push(job);
|
|
21056
|
+
if (pushes.length > 0) appendHistory(make$21(pushes.map((job) => ({
|
|
21057
|
+
role: "user",
|
|
21058
|
+
content: jobMessage(job)
|
|
21059
|
+
}))));
|
|
21060
|
+
}
|
|
20944
21061
|
yield* compactWithEvents("threshold", compactIfNeeded({
|
|
20945
21062
|
prompt: prompt.current,
|
|
20946
21063
|
contextTokens: lastContextTokens,
|
|
@@ -21132,7 +21249,9 @@ ${capOutput(turn.output ?? "").output}
|
|
|
21132
21249
|
part: new ScriptDelta({ delta: script })
|
|
21133
21250
|
});
|
|
21134
21251
|
return executeScript(script);
|
|
21135
|
-
}), ensuring(close(runScope, void_$1)),
|
|
21252
|
+
}), ensuring(close(runScope, void_$1)), ensuring(sync(() => {
|
|
21253
|
+
if (mailbox.emit === emit) mailbox.emit = void 0;
|
|
21254
|
+
})), catchCause((cause) => failCause$2(output, cause)), forkScoped);
|
|
21136
21255
|
return fromQueue(output);
|
|
21137
21256
|
}, unwrap$6);
|
|
21138
21257
|
const sendLock = makeUnsafe$4(1);
|
|
@@ -21167,8 +21286,17 @@ ${capOutput(turn.output ?? "").output}
|
|
|
21167
21286
|
const make$8 = makeWith$1({});
|
|
21168
21287
|
const makeMailbox = () => ({
|
|
21169
21288
|
messages: new Set(),
|
|
21170
|
-
notify: () => {}
|
|
21289
|
+
notify: () => {},
|
|
21290
|
+
jobs: [],
|
|
21291
|
+
emit: void 0,
|
|
21292
|
+
events: []
|
|
21171
21293
|
});
|
|
21294
|
+
const jobMessage = (job) => {
|
|
21295
|
+
const exitCode = job.exitCode === void 0 ? "" : ` exitCode="${job.exitCode}"`;
|
|
21296
|
+
return `<job id="${job.id}" status="${job.status}"${exitCode}>
|
|
21297
|
+
${capOutput(job.output).output}
|
|
21298
|
+
</job>`;
|
|
21299
|
+
};
|
|
21172
21300
|
const makeTurn = (agentId, background) => ({
|
|
21173
21301
|
agentId,
|
|
21174
21302
|
status: "running",
|
|
@@ -21219,7 +21347,7 @@ const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL
|
|
|
21219
21347
|
- Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`)}${when(tools.offers("applyPatch"), `
|
|
21220
21348
|
- 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"), `
|
|
21221
21349
|
- Avoid passing scripts into the "bash" function, and instead write javascript.
|
|
21222
|
-
- 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.`)}
|
|
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.`)}`)}
|
|
21223
21351
|
- Variables are not shared between executions.
|
|
21224
21352
|
- Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(tools.offers("delegate"), `
|
|
21225
21353
|
- "delegate" runs a sub-agent and waits for it. Pass \`background: true\` to keep working while it runs: its result is sent to you later as a \`<subagent id="..." status="...">\` message.${when(tools.offers("waitAgents"), ` Use "waitAgents" to wait for the returned id.`)}${when(tools.offers("messageAgent"), ` Use "messageAgent" to send a message to the returned id.`)}${when(tools.offers("stopAgent"), ` Use "stopAgent" to stop the returned id.`)}${when(tools.offers("listAgents"), ` "listAgents" shows the agents you started.`)}`)}${when(!conversationMode, `
|
|
@@ -21830,6 +21958,21 @@ const make$7 = fnUntraced(function* (options) {
|
|
|
21830
21958
|
content: textContent(part.summary)
|
|
21831
21959
|
}]
|
|
21832
21960
|
});
|
|
21961
|
+
case "JobComplete": {
|
|
21962
|
+
const exitCode = part.exitCode === void 0 ? "" : ` (exit code ${part.exitCode})`;
|
|
21963
|
+
return update(session.id, {
|
|
21964
|
+
sessionUpdate: "tool_call",
|
|
21965
|
+
toolCallId: `job-${part.id}`,
|
|
21966
|
+
title: `background job ${part.id} ${part.status}${exitCode}`,
|
|
21967
|
+
kind: "execute",
|
|
21968
|
+
status: part.status === "completed" ? "completed" : "failed",
|
|
21969
|
+
rawOutput: part.output,
|
|
21970
|
+
content: [{
|
|
21971
|
+
type: "content",
|
|
21972
|
+
content: textContent(part.output)
|
|
21973
|
+
}]
|
|
21974
|
+
});
|
|
21975
|
+
}
|
|
21833
21976
|
default: return void_;
|
|
21834
21977
|
}
|
|
21835
21978
|
};
|
|
@@ -28350,7 +28493,7 @@ const transformToolCallParams$1 = fnUntraced(function* (options, toolName, toolP
|
|
|
28350
28493
|
return yield* decodeEffect(codec)(toolParams).pipe(flatMap$1((decoded) => encodeUnknownEffect(tool.parametersSchema)(decoded)), orElseSucceed(() => toolParams));
|
|
28351
28494
|
});
|
|
28352
28495
|
// package.json
|
|
28353
|
-
var version$1 = "0.
|
|
28496
|
+
var version$1 = "0.21.0";
|
|
28354
28497
|
// src/ClaudeAgent.ts
|
|
28355
28498
|
const minimumClaudeCodeVersion = "2.1.248";
|
|
28356
28499
|
const serverName = "clanka";
|
|
@@ -31123,7 +31266,7 @@ make$27("clanka", {
|
|
|
31123
31266
|
files: mcpConfig,
|
|
31124
31267
|
enabled: mcp
|
|
31125
31268
|
});
|
|
31126
|
-
const OutputFormatter = yield* promise(() => import("./OutputFormatter-
|
|
31269
|
+
const OutputFormatter = yield* promise(() => import("./OutputFormatter-U02YKTfy.mjs"));
|
|
31127
31270
|
const { model, effort } = yield* match$2(modelRaw, {
|
|
31128
31271
|
onSome: (selected) => {
|
|
31129
31272
|
const [model, effort] = selected.split("/");
|