clanka 0.20.0 → 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/bin/cli.mjs CHANGED
@@ -11587,13 +11587,13 @@ var CommandLimits = class extends Reference("clanka/AgentTools/CommandLimits", {
11587
11587
  outputChars: void 0
11588
11588
  }) }) {};
11589
11589
  const makeBashTool = (timeout) => make$17("bash", {
11590
- description: "Run a bash command and return the output. With `background: true` it returns straight away with a job id while the command keeps running. A command still running at its timeout is not stopped: it is moved to the background, and the output so far is returned with its job id. Read a job with \"jobOutput\" and stop it with \"stopJob\".",
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.",
11591
11591
  parameters: Struct({
11592
11592
  command: String$7,
11593
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)})` }),
11594
- background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background and return its job id without waiting" })
11594
+ background: optional$2(Boolean$4).annotate({ documentation: "Start the command in the background and return it as \"running\" without waiting" })
11595
11595
  }).annotate({ identifier: "command" }),
11596
- success: String$7,
11596
+ success: BashJob,
11597
11597
  dependencies: [CurrentDirectory]
11598
11598
  });
11599
11599
  const globNamesDirectory = (glob) => glob.split("/").slice(0, -1).some((segment) => segment.length > 0 && !/[*?[\]{}]/.test(segment));
@@ -11672,6 +11672,14 @@ const AgentTools = make$16(make$17("changeDirectory", {
11672
11672
  parameters: String$7.annotate({ identifier: "id" }),
11673
11673
  success: BashJob,
11674
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
11675
11683
  }), make$17("stopJob", {
11676
11684
  description: "Stop a background bash job and return its final status and output.",
11677
11685
  parameters: String$7.annotate({ identifier: "id" }),
@@ -11746,13 +11754,19 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11746
11754
  });
11747
11755
  const jobs = new Map();
11748
11756
  let nextJobId = 1;
11749
- const addJob = fnUntraced(function* (command) {
11757
+ const addJob = (command) => {
11750
11758
  const id = String(nextJobId++);
11751
11759
  const running = {
11752
11760
  ...command,
11753
11761
  reported: false
11754
11762
  };
11755
11763
  jobs.set(id, running);
11764
+ return {
11765
+ id,
11766
+ running
11767
+ };
11768
+ };
11769
+ const watchJob = fnUntraced(function* (id, running) {
11756
11770
  yield* (yield* JobWatcher)({
11757
11771
  id,
11758
11772
  await: await_(running.fiber).pipe(map$5(() => jobInfo(id, running))),
@@ -11762,31 +11776,20 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11762
11776
  return true;
11763
11777
  })
11764
11778
  });
11765
- return id;
11766
11779
  });
11767
11780
  const findJob = (id) => {
11768
11781
  const running = jobs.get(id);
11769
11782
  return running === void 0 ? fail$1(`No background job with id "${id}"`) : succeed$1(running);
11770
11783
  };
11771
- const runCommand = fnUntraced(function* (command, timeout, onTimeout) {
11772
- const running = yield* startCommand(command);
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) => {
11773
11790
  const awaited = await_(running.fiber);
11774
- const exit = yield* (timeout === void 0 ? asSome(awaited) : timeoutOption(awaited, timeout)).pipe(onInterrupt(() => interrupt$2(running.fiber)));
11775
- if (isNone(exit)) {
11776
- const timeoutMs = toMillis(timeout);
11777
- if (onTimeout === "stop") {
11778
- yield* interrupt$2(running.fiber);
11779
- return yield* die(new Error(`Command timed out after ${timeoutMs}ms`));
11780
- }
11781
- const id = yield* addJob(running);
11782
- const output = running.output();
11783
- return `${output}${output === "" || output.endsWith("\n") ? "" : "\n"}[Still running after ${timeoutMs}ms, so it was moved to the background as job ${id}. ${jobUsage(id)}]`;
11784
- }
11785
- const exitCode = yield* exit.value;
11786
- const output = running.output();
11787
- if (exitCode === 0) return output;
11788
- return yield* die(new Error(`Command failed with exit code ${exitCode}: ${output}`));
11789
- });
11791
+ return (timeout === void 0 ? asSome(awaited) : timeoutOption(awaited, timeout)).pipe(onInterrupt(() => interrupt$2(running.fiber)));
11792
+ };
11790
11793
  const readImage = fnUntraced(function* (path, extensionType, options) {
11791
11794
  if (options.startLine !== void 0 || options.endLine !== void 0) return yield* die(new Error(`startLine / endLine are not supported for images: ${path}`));
11792
11795
  const bytes = yield* readBoundedFile(fs, path).pipe(catchReason("PlatformError", "NotFound", () => succeed$1(null)), orDie);
@@ -11891,8 +11894,7 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11891
11894
  return yield* promise(() => import("./index.min-ClUfQ5ji.mjs").then((Glob) => Glob.glob(pattern, { cwd })));
11892
11895
  }),
11893
11896
  bash: fn("AgentTools.bash")(function* (options) {
11894
- const limits = yield* CommandLimits;
11895
- const maxMs = toMillis(limits.timeout ?? defaultBashTimeout);
11897
+ const maxMs = bashTimeoutMs(yield* CommandLimits);
11896
11898
  const timeoutMs = Math.min(options.timeoutMs ?? maxMs, maxMs);
11897
11899
  yield* logInfo(`Calling "bash"`).pipe(annotateLogs({
11898
11900
  ...options,
@@ -11903,19 +11905,36 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11903
11905
  cwd,
11904
11906
  stdin: "ignore"
11905
11907
  });
11906
- if (options.background === true) {
11907
- const id = yield* addJob(yield* startCommand(cmd));
11908
- return `Started background job ${id}. ${jobUsage(id)}`;
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
+ }
11909
11917
  }
11910
- return yield* runCommand(cmd, millis(timeoutMs), "background");
11918
+ const job = reportJob(id, running);
11919
+ if (job.status === "running") yield* watchJob(id, running);
11920
+ return job;
11911
11921
  }, orDie),
11912
11922
  jobOutput: fn("AgentTools.jobOutput")(function* (input) {
11913
11923
  const id = yield* decodeJobOutput(input);
11914
11924
  yield* logInfo(`Calling "jobOutput"`).pipe(annotateLogs({ id }));
11915
- const running = yield* findJob(id);
11916
- const job = jobInfo(id, running);
11917
- if (job.status !== "running") running.reported = true;
11918
- return job;
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);
11919
11938
  }),
11920
11939
  stopJob: fn("AgentTools.stopJob")(function* (input) {
11921
11940
  const id = yield* decodeStopJob(input);
@@ -11933,7 +11952,16 @@ const AgentToolHandlersNoDeps = AgentToolsWithSearch.toLayer(gen(function* () {
11933
11952
  stdin: "ignore"
11934
11953
  });
11935
11954
  const { timeout } = yield* CommandLimits;
11936
- return yield* runCommand(cmd, timeout, "stop");
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}`));
11937
11965
  }, orDie),
11938
11966
  webSearch: fn("AgentTools.webSearch")(function* (options) {
11939
11967
  yield* logInfo(`Calling "webSearch"`).pipe(annotateLogs(options));
@@ -12079,8 +12107,9 @@ const decodeWaitAgents = decodeParams$1(AgentTools.tools.waitAgents.parametersSc
12079
12107
  const decodeMessageAgent = decodeParams$1(AgentTools.tools.messageAgent.parametersSchema, "messageAgent requires an options object, for example: messageAgent({ id: \"3\", message: \"...\" }).");
12080
12108
  const decodeStopAgent = decodeParams$1(AgentTools.tools.stopAgent.parametersSchema, "stopAgent requires an agent id, for example: stopAgent(\"3\").");
12081
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 }).");
12082
12112
  const decodeStopJob = decodeParams$1(AgentTools.tools.stopJob.parametersSchema, "stopJob requires a job id, for example: stopJob(\"1\").");
12083
- const jobUsage = (id) => `Use jobOutput("${id}") for its status and output, or stopJob("${id}") to stop it.`;
12084
12113
  const jobInfo = (id, running) => {
12085
12114
  const exit = running.fiber.pollUnsafe();
12086
12115
  const output = running.output();
@@ -14511,6 +14540,7 @@ const excludedToolNames = (excludeTools) => {
14511
14540
  ]) names.add(name);
14512
14541
  if (names.has("bash")) {
14513
14542
  names.add("jobOutput");
14543
+ names.add("waitJob");
14514
14544
  names.add("stopJob");
14515
14545
  }
14516
14546
  return names;
@@ -21317,7 +21347,7 @@ const generateSystemTools = (tools, conversationMode) => `YOU ONLY HAVE ONE TOOL
21317
21347
  - Prefer using the "search" function over "rg", unless you are targeting specific files or patterns.`)}${when(tools.offers("applyPatch"), `
21318
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"), `
21319
21349
  - Avoid passing scripts into the "bash" function, and instead write javascript.
21320
- - 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.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.`)}`)}
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.`)}`)}
21321
21351
  - Variables are not shared between executions.
21322
21352
  - Do not use \`require\`, \`import\`, \`process\`, or any other Node.js apis.${when(tools.offers("delegate"), `
21323
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, `
@@ -28463,7 +28493,7 @@ const transformToolCallParams$1 = fnUntraced(function* (options, toolName, toolP
28463
28493
  return yield* decodeEffect(codec)(toolParams).pipe(flatMap$1((decoded) => encodeUnknownEffect(tool.parametersSchema)(decoded)), orElseSucceed(() => toolParams));
28464
28494
  });
28465
28495
  // package.json
28466
- var version$1 = "0.20.0";
28496
+ var version$1 = "0.21.0";
28467
28497
  // src/ClaudeAgent.ts
28468
28498
  const minimumClaudeCodeVersion = "2.1.248";
28469
28499
  const serverName = "clanka";