clanka 0.22.6 → 0.23.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/bin/cli.mjs CHANGED
@@ -11556,7 +11556,7 @@ const Task = Struct({
11556
11556
  });
11557
11557
  var AgentTaskExecutor = class extends Service()("clanka/AgentTools/AgentTaskExecutor") {};
11558
11558
  const agentTasksUnavailable = {
11559
- delegate: () => die(new Error("Sub-agents are not available here")),
11559
+ subagent: () => die(new Error("Sub-agents are not available here")),
11560
11560
  taskOutput: () => fail$1("Sub-agents are not available here"),
11561
11561
  waitTasks: () => fail$1("Sub-agents are not available here"),
11562
11562
  messageAgent: () => fail$1("Sub-agents are not available here"),
@@ -11608,7 +11608,7 @@ const AgentTools = make$16(make$17("changeDirectory", {
11608
11608
  }),
11609
11609
  success: String$7,
11610
11610
  dependencies: [CurrentDirectory]
11611
- }), make$17("delegate", {
11611
+ }), make$17("subagent", {
11612
11612
  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.",
11613
11613
  parameters: Struct({
11614
11614
  prompt: String$7,
@@ -11719,17 +11719,32 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11719
11719
  const webSearch = yield* ExaSearch;
11720
11720
  const fetchMarkdown = yield* WebToMarkdown;
11721
11721
  const commandScope = yield* scope;
11722
- const startCommand = fnUntraced(function* (command) {
11722
+ const startCommand = fnUntraced(function* (command, saveLargeOutput = false) {
11723
11723
  const { outputChars } = yield* CommandLimits;
11724
- const output = makeOutputBuffer(outputChars);
11724
+ const maxChars = saveLargeOutput ? outputChars ?? 3e4 : outputChars;
11725
+ const output = makeOutputBuffer(maxChars);
11726
+ let total = 0;
11727
+ let outputFile;
11728
+ const append = fnUntraced(function* (chunk) {
11729
+ if (saveLargeOutput) {
11730
+ if (outputFile !== void 0) yield* fs.writeFileString(outputFile, chunk, { flag: "a" });
11731
+ else if (total + chunk.length > maxChars) {
11732
+ const file = yield* fs.makeTempFileScoped({ prefix: "clanka-bash-" }).pipe(provideService(Scope, commandScope));
11733
+ yield* fs.writeFileString(file, output.render() + chunk);
11734
+ outputFile = file;
11735
+ }
11736
+ }
11737
+ total += chunk.length;
11738
+ output.append(chunk);
11739
+ });
11725
11740
  return {
11726
- fiber: yield* spawner.spawn(command).pipe(flatMap$1((handle) => handle.all.pipe(decodeText, runForEach((chunk) => sync(() => output.append(chunk))), andThen(handle.exitCode))), scoped, forkIn(commandScope)),
11727
- output: output.render
11741
+ fiber: yield* spawner.spawn(command).pipe(flatMap$1((handle) => handle.all.pipe(decodeText, runForEach(append), andThen(handle.exitCode))), scoped, forkIn(commandScope)),
11742
+ output: () => outputFile === void 0 ? output.render() : `Output was too large. Saved to: ${outputFile}`
11728
11743
  };
11729
11744
  });
11730
11745
  const tasks = new Map();
11731
11746
  let nextTaskId = 1;
11732
- const registerAgentTask = fnUntraced(function* () {
11747
+ const registerAgentTask = gen(function* () {
11733
11748
  const id = String(nextTaskId++);
11734
11749
  tasks.set(id, {
11735
11750
  kind: "agent",
@@ -11886,7 +11901,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11886
11901
  cwd,
11887
11902
  stdin: "ignore"
11888
11903
  });
11889
- const entry = yield* addBashTask(options.command, yield* startCommand(cmd));
11904
+ const entry = yield* addBashTask(options.command, yield* startCommand(cmd, true));
11890
11905
  if (options.background !== true) {
11891
11906
  const exit = yield* awaitCommand(entry.command, millis(timeoutMs));
11892
11907
  if (isSome(exit)) {
@@ -12062,11 +12077,11 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
12062
12077
  }
12063
12078
  return `Success. Updated the following files:\n${out.join("\n")}`;
12064
12079
  }, orDie),
12065
- delegate: fn("AgentTools.delegate")(function* (options) {
12066
- const { prompt, background = false } = yield* decodeDelegate(options);
12067
- yield* logInfo(`Calling "delegate"`).pipe(annotateLogs({ background }));
12068
- const id = yield* registerAgentTask();
12069
- return yield* (yield* AgentTaskExecutor).delegate({
12080
+ subagent: fn("AgentTools.subagent")(function* (options) {
12081
+ const { prompt, background = false } = yield* decodeSubagent(options);
12082
+ yield* logInfo(`Calling "subagent"`).pipe(annotateLogs({ background }));
12083
+ const id = yield* registerAgentTask;
12084
+ return yield* (yield* AgentTaskExecutor).subagent({
12070
12085
  id,
12071
12086
  prompt,
12072
12087
  background
@@ -12091,7 +12106,7 @@ const decodeParams$1 = (schema, usage) => {
12091
12106
  const decode = decodeUnknownEffect$1(schema);
12092
12107
  return (input) => mapError(decode(input), () => usage);
12093
12108
  };
12094
- const decodeDelegate = decodeParams$1(AgentTools.tools.delegate.parametersSchema, "delegate requires an options object, for example: delegate({ prompt: \"...\" }) or delegate({ prompt: \"...\", background: true }).");
12109
+ const decodeSubagent = decodeParams$1(AgentTools.tools.subagent.parametersSchema, "subagent requires an options object, for example: subagent({ prompt: \"...\" }) or subagent({ prompt: \"...\", background: true }).");
12095
12110
  const decodeMessageAgent = decodeParams$1(AgentTools.tools.messageAgent.parametersSchema, "messageAgent requires an options object, for example: messageAgent({ id: \"3\", message: \"...\" }).");
12096
12111
  const decodeTaskOutput = decodeParams$1(AgentTools.tools.taskOutput.parametersSchema, "taskOutput requires a task id, for example: taskOutput(\"1\").");
12097
12112
  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 }).");
@@ -14248,7 +14263,7 @@ const makeLocalWith = fnUntraced(function* (options) {
14248
14263
  }));
14249
14264
  const taskServices = empty$5().pipe(add(TaskCompleter, opts.onTaskComplete), add(DirectoryChanger, changeDirectory), add(AgentTaskExecutor, {
14250
14265
  ...opts.agentTasks,
14251
- delegate: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(flatMap$1((environment) => opts.agentTasks.delegate({
14266
+ subagent: (options) => renderEnvironment(currentEnvironment(), { reset: true }).pipe(flatMap$1((environment) => opts.agentTasks.subagent({
14252
14267
  ...options,
14253
14268
  environment
14254
14269
  })))
@@ -14420,7 +14435,7 @@ const layerLocal$1 = (options) => effect(AgentExecutor, withBuiltInHandlers(make
14420
14435
  const layerRpc = effect(AgentExecutor, makeRpc);
14421
14436
  const AgentRequest = TaggedUnion({
14422
14437
  TaskComplete: { summary: String$7 },
14423
- Delegate: {
14438
+ Subagent: {
14424
14439
  id: String$7,
14425
14440
  prompt: String$7,
14426
14441
  background: Boolean$4,
@@ -14523,7 +14538,7 @@ const encodeRpcParams = (tool, params) => {
14523
14538
  const handleRequest = (opts, request) => {
14524
14539
  switch (request._tag) {
14525
14540
  case "TaskComplete": return opts.onTaskComplete(request.summary);
14526
- case "Delegate": return opts.agentTasks.delegate(request);
14541
+ case "Subagent": return opts.agentTasks.subagent(request);
14527
14542
  case "TaskOutput": return opts.agentTasks.taskOutput(request.id);
14528
14543
  case "WaitTasks": return opts.agentTasks.waitTasks(request.ids, request);
14529
14544
  case "MessageAgent": return opts.agentTasks.messageAgent(request);
@@ -14550,7 +14565,7 @@ const exitToResponse = (exit) => {
14550
14565
  const errorMessage$2 = (error) => typeof error === "string" ? error : error instanceof Error ? error.message : String(error);
14551
14566
  const excludedToolNames = (excludeTools) => {
14552
14567
  const names = new Set(excludeTools);
14553
- if (names.has("delegate")) {
14568
+ if (names.has("subagent")) {
14554
14569
  names.add("messageAgent");
14555
14570
  if (names.has("bash")) for (const name of [
14556
14571
  "taskOutput",
@@ -20810,7 +20825,7 @@ const makeWith$1 = fnUntraced(function* (options) {
20810
20825
  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.`);
20811
20826
  });
20812
20827
  const agentTasks = {
20813
- delegate: fnUntraced(function* ({ id, prompt, background, environment }) {
20828
+ subagent: fnUntraced(function* ({ id, prompt, background, environment }) {
20814
20829
  const child = {
20815
20830
  id: Number(id),
20816
20831
  taskOwner: crypto.randomUUID(),
@@ -20825,7 +20840,7 @@ const makeWith$1 = fnUntraced(function* (options) {
20825
20840
  yield* startTurn({
20826
20841
  child,
20827
20842
  label: prompt,
20828
- prompt: `You have been asked using the "delegate" function to complete the following task. Try to avoid using the "delegate" function yourself unless strictly necessary:
20843
+ prompt: `You have been asked using the "subagent" function to complete the following task. Try to avoid using the "subagent" function yourself unless strictly necessary:
20829
20844
 
20830
20845
  ${prompt}`,
20831
20846
  environmentUpdate: getOrUndefined(environment.update),
@@ -21454,8 +21469,8 @@ ${options.agentsMd}
21454
21469
  const when = (condition, text) => condition ? text : "";
21455
21470
  const taskInstructions = (tools) => {
21456
21471
  const bash = tools.offers("bash");
21457
- const delegate = tools.offers("delegate");
21458
- if (!bash && !delegate) return "";
21472
+ const subagent = tools.offers("subagent");
21473
+ if (!bash && !subagent) return "";
21459
21474
  const functions = [
21460
21475
  ["taskOutput", `"taskOutput" reads one`],
21461
21476
  ["waitTasks", `"waitTasks" waits for a list of them and returns any still running at its timeout as "running"`],
@@ -21463,7 +21478,7 @@ const taskInstructions = (tools) => {
21463
21478
  ["listTasks", `"listTasks" lists yours`]
21464
21479
  ].filter(([name]) => tools.offers(name)).map(([, text]) => text);
21465
21480
  return `
21466
- - ${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".` : ""}`;
21481
+ - ${bash && subagent ? "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".` : ""}`;
21467
21482
  };
21468
21483
  const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL AVAILABLE: "execute", to run javascript code to do your work.
21469
21484
 
@@ -21476,7 +21491,7 @@ const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL
21476
21491
  - Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${taskInstructions(tools)}${when(!conversationMode, `
21477
21492
 
21478
21493
  When you have fully completed your task, call the "taskComplete" function with the final output.
21479
- Make sure every detail of the task is done before calling "taskComplete".${when(tools.offers("delegate"), `
21494
+ Make sure every detail of the task is done before calling "taskComplete".${when(tools.offers("subagent"), `
21480
21495
  Any sub-agents you started must finish first: "taskComplete" fails while they are running.`)}`)}${when(tools.offers("readFile") && tools.offers("ls"), example)}
21481
21496
 
21482
21497
  These are the functions available to you:
@@ -22065,7 +22080,7 @@ const make$7 = fnUntraced(function* (options) {
22065
22080
  return update(session.id, {
22066
22081
  sessionUpdate: announced ? "tool_call_update" : "tool_call",
22067
22082
  toolCallId: `subagent-${part.id}`,
22068
- title: `delegate: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
22083
+ title: `subagent: ${part.prompt.replace(/\s+/g, " ").trim().slice(0, 120)}`,
22069
22084
  kind: "think",
22070
22085
  status: "in_progress",
22071
22086
  rawInput: { prompt: part.prompt }
@@ -28616,7 +28631,7 @@ const transformToolCallParams$1 = fnUntraced(function* (options, toolName, toolP
28616
28631
  return yield* decodeEffect(codec)(toolParams).pipe(flatMap$1((decoded) => encodeUnknownEffect(tool.parametersSchema)(decoded)), orElseSucceed(() => toolParams));
28617
28632
  });
28618
28633
  // package.json
28619
- var version$1 = "0.22.6";
28634
+ var version$1 = "0.23.1";
28620
28635
  // src/ClaudeAgent.ts
28621
28636
  const minimumClaudeCodeVersion = "2.1.248";
28622
28637
  const serverName = "clanka";