wildcrane-runner 0.6.41 → 0.6.43

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/runner.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.41 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.43 — built by runner/scripts/build.mjs. Do not edit.
2
2
  import { createRequire as __ai4kanbanRequire } from 'node:module'
3
3
  const require = __ai4kanbanRequire(import.meta.url)
4
4
  var __create = Object.create;
@@ -4480,7 +4480,7 @@ var require_webidl = __commonJS({
4480
4480
  "node_modules/undici/lib/web/webidl/index.js"(exports, module) {
4481
4481
  "use strict";
4482
4482
  var assert = __require("node:assert");
4483
- var { types, inspect } = __require("node:util");
4483
+ var { types, inspect: inspect2 } = __require("node:util");
4484
4484
  var { runtimeFeatures } = require_runtime_features();
4485
4485
  var UNDEFINED = 1;
4486
4486
  var BOOLEAN = 2;
@@ -4672,7 +4672,7 @@ var require_webidl = __commonJS({
4672
4672
  case SYMBOL:
4673
4673
  return `Symbol(${V3.description})`;
4674
4674
  case OBJECT:
4675
- return inspect(V3);
4675
+ return inspect2(V3);
4676
4676
  case STRING:
4677
4677
  return `"${V3}"`;
4678
4678
  case BIGINT:
@@ -111406,9 +111406,9 @@ function status(line) {
111406
111406
  }
111407
111407
 
111408
111408
  // src/protocol.ts
111409
- var VERSION = true ? "0.6.41" : "0.0.0";
111410
- var AKB_VERSION = true ? "0.11.35" : "0.0.0";
111411
- var AKB_CONTRACT = true ? 8 : 0;
111409
+ var VERSION = true ? "0.6.43" : "0.0.0";
111410
+ var AKB_VERSION = true ? "0.11.37" : "0.0.0";
111411
+ var AKB_CONTRACT = true ? 9 : 0;
111412
111412
  var EXIT_REFUSED = 10;
111413
111413
  var EXIT_OUTDATED = 11;
111414
111414
  var EXIT_UPDATE = 12;
@@ -112030,6 +112030,11 @@ function createEventCollector() {
112030
112030
  const t2 = target ? targetOf(target) : void 0;
112031
112031
  queue.push({ kind: "tool_call", data: { toolCallId, title, kind, status: "in_progress", ...t2 ? { target: t2 } : {} } });
112032
112032
  },
112033
+ /** A subagent the agent started, titled by its task; it ends with its call's `toolResult`. */
112034
+ subagent(toolCallId, title) {
112035
+ close();
112036
+ queue.push({ kind: "tool_call", data: { toolCallId, title: targetOf(title) ?? "subagent", kind: "other", status: "in_progress", subagent: true } });
112037
+ },
112033
112038
  toolResult(toolCallId, status2, result) {
112034
112039
  close();
112035
112040
  queue.push({ kind: "tool_call_update", data: { toolCallId, status: status2, ...result.trim() ? { result: result.trim() } : {} } });
@@ -112123,6 +112128,7 @@ var TOOL_KINDS2 = {
112123
112128
  WebFetch: "fetch",
112124
112129
  WebSearch: "fetch"
112125
112130
  };
112131
+ var SUBAGENT_TOOLS = /* @__PURE__ */ new Set(["Agent", "Task"]);
112126
112132
  function targetOf2(input) {
112127
112133
  const args = obj(input);
112128
112134
  for (const key of ARG_KEYS) if (str(args[key]).trim()) return str(args[key]);
@@ -112191,6 +112197,13 @@ function createStreamRenderer() {
112191
112197
  const backgrounded = /* @__PURE__ */ new Set();
112192
112198
  const events = createEventCollector();
112193
112199
  const plans = /* @__PURE__ */ new Set();
112200
+ const subagents = /* @__PURE__ */ new Map();
112201
+ const detached = /* @__PURE__ */ new Set();
112202
+ const endSubagent = (id, status2) => {
112203
+ if (subagents.get(id) !== false) return;
112204
+ subagents.set(id, true);
112205
+ events.toolResult(id, status2, "");
112206
+ };
112194
112207
  const renderLine = (line) => {
112195
112208
  if (!line.trim()) return "";
112196
112209
  const ev = frame(line);
@@ -112200,6 +112213,7 @@ function createStreamRenderer() {
112200
112213
  `;
112201
112214
  }
112202
112215
  if (model === void 0) model = eventModel(ev);
112216
+ if (str(ev.parent_tool_use_id)) return "";
112203
112217
  switch (ev.type) {
112204
112218
  case "assistant": {
112205
112219
  const msg = ev.message;
@@ -112217,7 +112231,12 @@ function createStreamRenderer() {
112217
112231
  } else if (b2?.type === "tool_use" && typeof b2.name === "string") {
112218
112232
  out.push(`\u23FA ${b2.name}${argHint(b2.input, ARG_KEYS)}
112219
112233
  `);
112220
- if (b2.name === "TodoWrite") {
112234
+ if (SUBAGENT_TOOLS.has(b2.name)) {
112235
+ const input = obj(b2.input);
112236
+ subagents.set(str(b2.id), false);
112237
+ if (input.run_in_background === true) detached.add(str(b2.id));
112238
+ events.subagent(str(b2.id), str(input.description) || str(input.subagent_type) || b2.name);
112239
+ } else if (b2.name === "TodoWrite") {
112221
112240
  plans.add(str(b2.id));
112222
112241
  events.plan(obj(b2.input).todos);
112223
112242
  } else {
@@ -112232,6 +112251,10 @@ function createStreamRenderer() {
112232
112251
  for (const raw of Array.isArray(content) ? content : []) {
112233
112252
  const b2 = obj(raw);
112234
112253
  if (b2.type !== "tool_result" || plans.has(str(b2.tool_use_id))) continue;
112254
+ if (subagents.has(str(b2.tool_use_id))) {
112255
+ if (!detached.has(str(b2.tool_use_id))) endSubagent(str(b2.tool_use_id), b2.is_error === true ? "failed" : "completed");
112256
+ continue;
112257
+ }
112235
112258
  events.toolResult(str(b2.tool_use_id), b2.is_error === true ? "failed" : "completed", resultText(b2.content));
112236
112259
  }
112237
112260
  return "";
@@ -112259,6 +112282,9 @@ function createStreamRenderer() {
112259
112282
  case "system":
112260
112283
  if (ev.subtype === "background_tasks_changed" && Array.isArray(ev.tasks)) background = ev.tasks.length;
112261
112284
  if (ev.subtype === "task_started" && ev.is_backgrounded === true) backgrounded.add(str(ev.task_id));
112285
+ if (ev.subtype === "task_notification" && subagents.has(str(ev.tool_use_id))) {
112286
+ endSubagent(str(ev.tool_use_id), str(ev.status) === "completed" ? "completed" : "failed");
112287
+ }
112262
112288
  if (ev.subtype === "task_notification" && backgrounded.has(str(ev.task_id)) && str(ev.summary)) {
112263
112289
  return `\u23FA ${str(ev.summary)}
112264
112290
  `;
@@ -112788,6 +112814,14 @@ function callArgs(raw) {
112788
112814
  return {};
112789
112815
  }
112790
112816
  }
112817
+ var TOOL_KINDS3 = [
112818
+ [/read/i, "read"],
112819
+ [/grep|glob|search/i, "search"],
112820
+ [/fetch|web/i, "fetch"],
112821
+ [/bash|shell/i, "execute"],
112822
+ [/write|edit|replace/i, "edit"]
112823
+ ];
112824
+ var kindOf = (name) => TOOL_KINDS3.find(([re3]) => re3.test(name))?.[1] ?? "other";
112791
112825
  function toolCalls(row) {
112792
112826
  const calls = Array.isArray(row.tool_calls) ? row.tool_calls : [];
112793
112827
  return calls.map((raw) => {
@@ -112811,6 +112845,8 @@ function createKimiStreamRenderer(cwd) {
112811
112845
  let sessionId;
112812
112846
  let facts;
112813
112847
  let lookedAt = 0;
112848
+ const events = createEventCollector();
112849
+ const subagents = /* @__PURE__ */ new Set();
112814
112850
  const look = (now) => {
112815
112851
  const at2 = Date.now();
112816
112852
  if (!now && at2 - lookedAt < LOOK_EVERY_MS2) return;
@@ -112827,6 +112863,18 @@ function createKimiStreamRenderer(cwd) {
112827
112863
  case "assistant": {
112828
112864
  const said = str(row.content).trim();
112829
112865
  if (said) final = said;
112866
+ if (said) events.message(said);
112867
+ for (const raw of Array.isArray(row.tool_calls) ? row.tool_calls : []) {
112868
+ const call2 = obj(raw);
112869
+ const name = str(obj(call2.function).name) || "tool";
112870
+ const args = obj(callArgs(obj(call2.function).arguments));
112871
+ if (name === "Agent") {
112872
+ subagents.add(str(call2.id));
112873
+ events.subagent(str(call2.id), str(args.description) || name);
112874
+ } else {
112875
+ events.toolCall(str(call2.id), name, kindOf(name), ARG_KEYS2.map((k2) => str(args[k2])).find((v) => v.trim()));
112876
+ }
112877
+ }
112830
112878
  return `${said ? `${said}
112831
112879
 
112832
112880
  ` : ""}${toolCalls(row)}`;
@@ -112834,6 +112882,13 @@ function createKimiStreamRenderer(cwd) {
112834
112882
  case "meta":
112835
112883
  if (row.type === "session.resume_hint") sessionId ??= str(row.session_id).trim() || void 0;
112836
112884
  return row.type === "turn.step.retrying" ? retry(row) : "";
112885
+ case "tool": {
112886
+ const id = str(row.tool_call_id);
112887
+ const text3 = str(row.content);
112888
+ if (subagents.delete(id)) events.toolResult(id, /^status: completed$/m.test(text3) ? "completed" : "failed", "");
112889
+ else events.toolResult(id, "completed", text3);
112890
+ return "";
112891
+ }
112837
112892
  default:
112838
112893
  return "";
112839
112894
  }
@@ -112847,6 +112902,7 @@ function createKimiStreamRenderer(cwd) {
112847
112902
  return out;
112848
112903
  },
112849
112904
  result: () => final,
112905
+ events: events.events,
112850
112906
  usage: () => facts?.usage,
112851
112907
  context: () => {
112852
112908
  look(false);
@@ -112997,8 +113053,8 @@ function createTail(log) {
112997
113053
  // ../cli/package.json
112998
113054
  var package_default = {
112999
113055
  name: "wildcrane",
113000
- version: "0.11.35",
113001
- akbContract: 8,
113056
+ version: "0.11.37",
113057
+ akbContract: 9,
113002
113058
  description: "WildCrane's `akb` command \u2014 scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
113003
113059
  keywords: [
113004
113060
  "kanban",
@@ -115153,6 +115209,7 @@ import path13 from "node:path";
115153
115209
  // ../cli/src/lib/agent/env.ts
115154
115210
  var RUN_ENV = "KANBAN_RUN";
115155
115211
  var SCHEDULED_AGENTS_ENV = "AI4KANBAN_SCHEDULED_AGENTS";
115212
+ var SESSION_COST_ENV = "AI4KANBAN_SESSION_COST";
115156
115213
  var STOP_ENV = "KANBAN_STOP_ID";
115157
115214
  var SESSION_VARS = {
115158
115215
  "claude-code": "CLAUDE_CODE_SESSION_ID",
@@ -116264,7 +116321,7 @@ exec ${shellLine} "$@"
116264
116321
  }
116265
116322
  function akbEnv(akb, board, task, language, base = process.env) {
116266
116323
  const env2 = {};
116267
- const dropped = ["AI4KANBAN_BOARD", "AI4KANBAN_TASK", "AI4KANBAN_EXECUTION", LANGUAGE_ENV, LANGUAGE_LINE_ENV, SCHEDULED_AGENTS_ENV];
116324
+ const dropped = ["AI4KANBAN_BOARD", "AI4KANBAN_TASK", "AI4KANBAN_EXECUTION", LANGUAGE_ENV, LANGUAGE_LINE_ENV, SCHEDULED_AGENTS_ENV, SESSION_COST_ENV];
116268
116325
  for (const [k2, v] of Object.entries({ ...proxyEnv(), ...base })) if (!k2.startsWith("KANBAN_") && !dropped.includes(k2)) env2[k2] = v;
116269
116326
  const key = Object.keys(env2).find((k2) => k2.toUpperCase() === "PATH") ?? "PATH";
116270
116327
  env2[key] = [shimDir(akb), env2[key]].filter(Boolean).join(path19.delimiter);
@@ -117157,7 +117214,7 @@ var TYPES = {
117157
117214
  ".tmj": "application/json",
117158
117215
  ".tsj": "application/json"
117159
117216
  };
117160
- function kindOf(ext) {
117217
+ function kindOf2(ext) {
117161
117218
  if (ext === ".tsx" || ext === ".html") return "html";
117162
117219
  if (ext === ".md" || ext === ".mdx") return "markdown";
117163
117220
  if (ext === ".tmx" || ext === ".tmj" || ext === ".tsj") return "tiled";
@@ -117172,7 +117229,7 @@ var why = (error) => error instanceof Error ? error.message : String(error);
117172
117229
  var textKind = (ext, types) => types.find((t2) => {
117173
117230
  const m = manifestOf(t2);
117174
117231
  return m && !m.schema;
117175
- }) ?? kindOf(ext);
117232
+ }) ?? kindOf2(ext);
117176
117233
  var kindAt = (src, types) => extOf(src) === ".json" ? types.includes("asset") ? "asset" : types[0] ?? "asset" : textKind(extOf(src), types);
117177
117234
  function collect(body, card, host) {
117178
117235
  const nodes = /* @__PURE__ */ new Map();
@@ -117950,17 +118007,32 @@ function mcpProblem(text3) {
117950
118007
  return null;
117951
118008
  }
117952
118009
  function checkWorkflowFiles(value, official = false) {
117953
- const fail = (file3, reason, tooLarge = false) => ({ ok: false, file: file3, reason, ...tooLarge ? { tooLarge } : {} });
118010
+ const read4 = inspect(value, official);
118011
+ const first = read4.problems[0];
118012
+ return first ? { ok: false, ...first } : { ok: true, def: read4.def, files: read4.files };
118013
+ }
118014
+ function inspect(value, official) {
118015
+ const problems = [];
118016
+ const fail = (file3, reason, tooLarge = false) => {
118017
+ problems.push({ file: file3, reason, ...tooLarge ? { tooLarge } : {} });
118018
+ return { problems };
118019
+ };
117954
118020
  if (!value || typeof value !== "object" || Array.isArray(value)) return fail("files", "must be an object of path \u2192 text");
117955
- value = Object.fromEntries(Object.entries(value).filter(([file3]) => file3 !== VERSION_FILE));
117956
- const entries = Object.entries(value);
118021
+ const files = Object.fromEntries(Object.entries(value).filter(([file3]) => file3 !== VERSION_FILE));
118022
+ const entries = Object.entries(files);
117957
118023
  if (entries.length > FILE_LIMITS.count) return fail("files", `holds at most ${FILE_LIMITS.count} files`, true);
117958
118024
  let total = 0;
117959
118025
  const folders2 = /* @__PURE__ */ new Map();
117960
118026
  const skills = /* @__PURE__ */ new Set();
117961
118027
  for (const [file3, text3] of entries) {
117962
- if (typeof text3 !== "string" || text3.includes("\0")) return fail(file3, "is not a text file");
117963
- if (file3.length > FILE_LIMITS.path) return fail(file3, `the path is longer than ${FILE_LIMITS.path} characters`);
118028
+ if (typeof text3 !== "string" || text3.includes("\0")) {
118029
+ fail(file3, "is not a text file");
118030
+ continue;
118031
+ }
118032
+ if (file3.length > FILE_LIMITS.path) {
118033
+ fail(file3, `the path is longer than ${FILE_LIMITS.path} characters`);
118034
+ continue;
118035
+ }
117964
118036
  const size = bytes(text3);
117965
118037
  if (size > FILE_LIMITS.file) return fail(file3, `is larger than ${FILE_LIMITS.file / KB} KB`, true);
117966
118038
  total += size;
@@ -117968,47 +118040,54 @@ function checkWorkflowFiles(value, official = false) {
117968
118040
  if (file3 === WORKFLOW_FILE) continue;
117969
118041
  if (official && file3 === MCP_FILE) {
117970
118042
  const problem = mcpProblem(text3);
117971
- if (problem) return fail(file3, problem);
118043
+ if (problem) fail(file3, problem);
117972
118044
  continue;
117973
118045
  }
117974
118046
  if (official && isAboutFile(file3)) continue;
117975
118047
  if (official && file3.startsWith("skills/")) {
117976
- if (!folderPath(file3, "skills")) return fail(file3, "is not inside skills/<name>/");
117977
- skills.add(file3.split("/")[1]);
118048
+ if (!folderPath(file3, "skills")) fail(file3, "is not inside skills/<name>/");
118049
+ else skills.add(file3.split("/")[1]);
117978
118050
  continue;
117979
118051
  }
117980
118052
  const at2 = folderPath(file3, "agents");
117981
- if (!at2) return fail(file3, `is neither ${WORKFLOW_FILE} nor inside agents/<name>/`);
118053
+ if (!at2) {
118054
+ fail(file3, `is neither ${WORKFLOW_FILE} nor inside agents/<name>/`);
118055
+ continue;
118056
+ }
117982
118057
  if (!folders2.has(at2[0])) folders2.set(at2[0], /* @__PURE__ */ new Map());
117983
118058
  folders2.get(at2[0]).set(at2[1], text3);
117984
118059
  }
117985
118060
  for (const name of skills) {
117986
- if (value[`skills/${name}/SKILL.md`] === void 0) return fail(`skills/${name}/SKILL.md`, "is missing");
118061
+ if (files[`skills/${name}/SKILL.md`] === void 0) fail(`skills/${name}/SKILL.md`, "is missing");
117987
118062
  }
117988
- const source = value[WORKFLOW_FILE];
117989
- if (source === void 0) return fail(WORKFLOW_FILE, "is missing");
117990
- const read4 = parseWorkflowFile("workflow", source, WORKFLOW_FILE);
117991
- if ("problem" in read4) return fail(WORKFLOW_FILE, read4.problem.replace(`${WORKFLOW_FILE}: `, ""));
117992
- const def = read4.def;
118063
+ const source = files[WORKFLOW_FILE];
118064
+ const read4 = typeof source === "string" ? parseWorkflowFile("workflow", source, WORKFLOW_FILE) : null;
118065
+ if (!read4) fail(WORKFLOW_FILE, "is missing");
118066
+ else if ("problem" in read4) fail(WORKFLOW_FILE, read4.problem.replace(`${WORKFLOW_FILE}: `, ""));
117993
118067
  const agents = /* @__PURE__ */ new Map();
117994
118068
  for (const [name, own2] of folders2) {
117995
118069
  const from = `agents/${name}/AGENT.md`;
117996
118070
  const text3 = own2.get("AGENT.md");
117997
- if (text3 === void 0) return fail(from, "is missing");
118071
+ if (text3 === void 0) {
118072
+ fail(from, "is missing");
118073
+ continue;
118074
+ }
117998
118075
  const parsed = parseSpecAgent(text3, from, (p2) => own2.get(p2) ?? null, false, () => [...own2.keys()].filter((p2) => p2 !== "AGENT.md"));
117999
- if ("problem" in parsed) return fail(from, parsed.problem.replace(`${from}: `, ""));
118000
- if (parsed.agent.name !== name) return fail(from, `calls itself \`${parsed.agent.name}\`; it must match its folder`);
118001
- agents.set(name, parsed.agent);
118076
+ if ("problem" in parsed) fail(from, parsed.problem.replace(`${from}: `, ""));
118077
+ else if (parsed.agent.name !== name) fail(from, `calls itself \`${parsed.agent.name}\`; it must match its folder`);
118078
+ else agents.set(name, parsed.agent);
118002
118079
  }
118080
+ if (!read4 || "problem" in read4) return { problems };
118081
+ const def = read4.def;
118003
118082
  const named2 = [
118004
118083
  ...def.previews.map((h3) => [h3.agent, "it previews with"]),
118005
118084
  ...def.land.map((h3) => [h3.agent, "it lands with"]),
118006
118085
  ...def.scheduled.map((s) => [s.agent, "it schedules"])
118007
118086
  ];
118008
118087
  for (const [name, why2] of named2) {
118009
- if (!agents.has(name)) return fail(WORKFLOW_FILE, `${why2} \`${name}\`, which has no agents/${name}/AGENT.md`);
118088
+ if (!agents.has(name) && !folders2.has(name)) fail(WORKFLOW_FILE, `${why2} \`${name}\`, which has no agents/${name}/AGENT.md`);
118010
118089
  }
118011
- return { ok: true, def, files: value };
118090
+ return { problems, def, files };
118012
118091
  }
118013
118092
 
118014
118093
  // ../cli/src/lib/agent/workflow-folder.ts
@@ -119015,7 +119094,7 @@ async function pushAssets(ws, record, before) {
119015
119094
  const unchanged = restored && previous && (previous.kind ?? out.kind) === out.kind && localHash === (previous.localHash ?? previous.hash) && [...node.dependencies.values()].every((key) => refs[key]?.artifact === before[key]?.artifact);
119016
119095
  if (!entry || !unchanged && entry.hash !== hash || entry.kind && entry.kind !== out.kind) {
119017
119096
  if (!ws.cloudTask) continue;
119018
- let artifact = previous && (previous.kind ?? kindOf(path34.extname(node.file).toLowerCase())) === out.kind ? previous.artifact : void 0;
119097
+ let artifact = previous && (previous.kind ?? kindOf2(path34.extname(node.file).toLowerCase())) === out.kind ? previous.artifact : void 0;
119019
119098
  if (!artifact) {
119020
119099
  const made = await createArtifact(ws.cloudTask, node.key.slice(0, 200), out.kind);
119021
119100
  if (!made.ok) return { ...made, error: `${node.key}: ${made.error}` };
@@ -119539,8 +119618,7 @@ function normalizeQuestion(raw) {
119539
119618
  const source = raw;
119540
119619
  const text3 = withoutTag(String(source.question ?? source.text ?? ""));
119541
119620
  const extra = {
119542
- ...typeof source.agent === "string" && source.agent.trim() ? { agent: source.agent.trim() } : {},
119543
- ...source.skipped === true || source.skipped === "true" ? { skipped: true } : {}
119621
+ ...typeof source.agent === "string" && source.agent.trim() ? { agent: source.agent.trim() } : {}
119544
119622
  };
119545
119623
  const options = (Array.isArray(source.options) ? source.options : []).map((o3) => String(o3).trim()).filter(Boolean);
119546
119624
  if (options.length === 0) return { text: text3, ...extra };
@@ -119561,6 +119639,7 @@ function parseQuestionsBlock(lines) {
119561
119639
  out.push(normalizeQuestion(unquote2(head2)));
119562
119640
  continue;
119563
119641
  }
119642
+ let skipped = false;
119564
119643
  const q4 = {
119565
119644
  question: unquote2(opened[1]),
119566
119645
  options: [],
@@ -119583,17 +119662,14 @@ function parseQuestionsBlock(lines) {
119583
119662
  } else if (key === "agent") {
119584
119663
  q4.agent = unquote2(val);
119585
119664
  } else if (key === "skipped") {
119586
- q4.skipped = unquote2(val) === "true";
119665
+ skipped = unquote2(val) === "true";
119587
119666
  }
119588
119667
  }
119589
- out.push(normalizeQuestion(q4));
119668
+ if (!skipped) out.push(normalizeQuestion(q4));
119590
119669
  }
119591
119670
  return out;
119592
119671
  }
119593
119672
 
119594
- // ../cli/src/lib/view/rules.ts
119595
- var openOf = (questions) => questions.filter((q4) => !q4.skipped);
119596
-
119597
119673
  // ../cli/src/lib/frontmatter.ts
119598
119674
  function parseFrontmatter(text3) {
119599
119675
  const lines = text3.split("\n");
@@ -119677,13 +119753,10 @@ function parseFrontmatter(text3) {
119677
119753
  // ../cli/src/lib/card-review.ts
119678
119754
  function reviewOf(meta) {
119679
119755
  const questions = meta.questions ?? [];
119680
- let open = false;
119681
119756
  for (const [i, q4] of questions.entries()) {
119682
- if (!openOf([q4]).length) continue;
119683
- open = true;
119684
119757
  if (q4.options?.length) return { question: q4.text, options: q4.options.slice(0, 8), position: i + 1 };
119685
119758
  }
119686
- return open || meta.status === "ready" || meta.status === "implementing" ? true : null;
119759
+ return questions.length || meta.status === "ready" || meta.status === "implementing" ? true : null;
119687
119760
  }
119688
119761
 
119689
119762
  // src/triage.ts
@@ -119829,22 +119902,20 @@ async function placeDraft(ws, read4) {
119829
119902
  var named = (def) => [...new Set([...def.previews, ...def.land, ...def.scheduled].map((h3) => h3.agent))];
119830
119903
  async function builtWorkflow(ws, akb) {
119831
119904
  if (!isBuilder(ws)) return null;
119832
- const fail = (problem) => ({ ok: false, reason: `The workflow has a problem: ${problem}` });
119833
119905
  const id = draftFolder(ws.task);
119834
119906
  const dir = draftDir(ws);
119835
- let source;
119907
+ let source = "";
119836
119908
  try {
119837
119909
  source = fs36.readFileSync(path39.join(dir, WORKFLOW_FILE), "utf8");
119838
119910
  } catch {
119839
- return fail(`workflows/${id}/${WORKFLOW_FILE} is missing.`);
119840
119911
  }
119841
119912
  const read4 = parseWorkflowFile(id, source, `workflows/${id}/${WORKFLOW_FILE}`);
119842
- if ("problem" in read4) return fail(read4.problem);
119843
- const names2 = named(read4.def);
119844
- const run2 = async (args) => answerOf2(await runAkb(akb, [...args, "--json", "--board", ws.board], { cwd: ws.cwd, board: ws.board }));
119913
+ const names2 = "def" in read4 ? named(read4.def) : [];
119845
119914
  const agents = path39.join(dir, "agents");
119846
- for (const old of fs36.existsSync(agents) ? fs36.readdirSync(agents) : []) {
119847
- if (!names2.includes(old)) fs36.rmSync(path39.join(agents, old), { recursive: true, force: true });
119915
+ if ("def" in read4) {
119916
+ for (const old of fs36.existsSync(agents) ? fs36.readdirSync(agents) : []) {
119917
+ if (!names2.includes(old)) fs36.rmSync(path39.join(agents, old), { recursive: true, force: true });
119918
+ }
119848
119919
  }
119849
119920
  for (const name of names2) {
119850
119921
  const from = path39.join(ws.board, "agents", name);
@@ -119853,25 +119924,16 @@ async function builtWorkflow(ws, akb) {
119853
119924
  fs36.rmSync(to, { recursive: true, force: true });
119854
119925
  fs36.cpSync(from, to, { recursive: true });
119855
119926
  } else if (!fs36.existsSync(path39.join(to, "AGENT.md"))) {
119856
- const own2 = await run2(["raw", "agent-file", name, "AGENT.md"]);
119927
+ const own2 = answerOf2(
119928
+ await runAkb(akb, ["raw", "agent-file", name, "AGENT.md", "--json", "--board", ws.board], { cwd: ws.cwd, board: ws.board })
119929
+ );
119857
119930
  if (own2?.text) {
119858
119931
  fs36.mkdirSync(to, { recursive: true });
119859
119932
  fs36.writeFileSync(path39.join(to, "AGENT.md"), own2.text);
119860
119933
  }
119861
119934
  }
119862
119935
  }
119863
- const files = Object.fromEntries(filesUnder(dir).map((f2) => [f2, fs36.readFileSync(path39.join(dir, f2), "utf8")]));
119864
- const checked = checkWorkflowFiles(files);
119865
- if (!checked.ok) return fail(`${checked.file} ${checked.reason}.`);
119866
- const list = await run2(["workflow", "list"]);
119867
- const spec = await run2(["raw", "previews"]);
119868
- if (!list?.workflows || !spec) return fail("akb could not check it.");
119869
- const problems = [
119870
- ...list.workflows.find((w2) => w2.id === id)?.problems ?? [],
119871
- ...(list.problems ?? []).filter((p2) => p2.includes(`workflows/${id}/`)),
119872
- ...(spec.problems ?? []).filter((p2) => names2.some((n) => p2.includes(`agents/${n}/`)))
119873
- ];
119874
- return problems.length ? fail(problems.join(" ")) : { ok: true, files: checked.files };
119936
+ return Object.fromEntries(filesUnder(dir).filter((f2) => f2 !== VERSION_FILE).map((f2) => [f2, fs36.readFileSync(path39.join(dir, f2), "utf8")]));
119875
119937
  }
119876
119938
 
119877
119939
  // src/flow.ts
@@ -119881,17 +119943,29 @@ function unavailable(wanted2, reports) {
119881
119943
  if (report2.loggedIn === false) return `${LABELS[wanted2]} is not signed in on this computer.`;
119882
119944
  return null;
119883
119945
  }
119884
- function spentBy(runs) {
119946
+ function spentBy(runs, job) {
119885
119947
  const used = runs.filter((r2) => r2.usage);
119886
119948
  const costed = runs.filter((r2) => typeof r2.costUsd === "number");
119887
119949
  const sum = (key) => used.reduce((n, r2) => n + (r2.usage[key] || 0), 0);
119888
119950
  const context = runs.filter((r2) => r2.context?.used !== void 0 && r2.context.limit).reduce((last2, r2) => !last2 || (r2.startedAt ?? 0) >= (last2.startedAt ?? 0) ? r2 : last2, void 0)?.context;
119889
119951
  return {
119890
119952
  ...used.length ? { usage: { input: sum("input"), cacheCreation: sum("cacheCreation"), cacheRead: sum("cacheRead"), output: sum("output") } } : {},
119891
- ...costed.length ? { costUsd: costed.reduce((n, r2) => n + r2.costUsd, 0) } : {},
119953
+ ...costed.length ? { costUsd: costed.reduce((n, r2) => n + r2.costUsd, 0), runtimeCosts: runtimeCosts(costed, job) } : {},
119892
119954
  ...context ? { context: { used: context.used, limit: context.limit } } : {}
119893
119955
  };
119894
119956
  }
119957
+ function runtimeCosts(runs, job) {
119958
+ const picks = Object.values(job.agentRuntimes ?? {});
119959
+ const out = /* @__PURE__ */ new Map();
119960
+ for (const r2 of runs) {
119961
+ const pick2 = picks.find((p2) => p2.id === r2.runtime);
119962
+ const runtimeId = pick2 ? pick2.id : job.runtimeId ?? null;
119963
+ const row = out.get(runtimeId) ?? { runtimeId, runtime: pick2?.runtime ?? job.runtime, costUsd: 0 };
119964
+ row.costUsd += r2.costUsd;
119965
+ out.set(runtimeId, row);
119966
+ }
119967
+ return [...out.values()];
119968
+ }
119895
119969
  function reviewOf2(file3) {
119896
119970
  try {
119897
119971
  const meta = parseFrontmatter(fs37.readFileSync(file3, "utf8")).meta;
@@ -119902,7 +119976,7 @@ function reviewOf2(file3) {
119902
119976
  }
119903
119977
  function asks(file3) {
119904
119978
  try {
119905
- return openOf(parseFrontmatter(fs37.readFileSync(file3, "utf8")).meta?.questions ?? []).length > 0;
119979
+ return (parseFrontmatter(fs37.readFileSync(file3, "utf8")).meta?.questions ?? []).length > 0;
119906
119980
  } catch {
119907
119981
  return false;
119908
119982
  }
@@ -120062,9 +120136,7 @@ async function setUp(job, ws, deps, io) {
120062
120136
  const mcpFile = path40.join(ws.board, ".sync", `${ws.task}.mcp.json`);
120063
120137
  const takes = new Set(settingKeys(runtime));
120064
120138
  const given = job.settings ?? {};
120065
- const values = { ...given, model: job.model ?? "" };
120066
- if (takes.has(MCP_KEY)) values[MCP_KEY] = mcpConfig(servers, mcpFile) ?? given[MCP_KEY] ?? "";
120067
- else values[RAW_ARGS_KEY] = [given[RAW_ARGS_KEY], mcpArgs(runtime, servers, mcpFile)].filter(Boolean).join(" ");
120139
+ const values = valuesOf(runtime, job.model, given, servers, mcpFile);
120068
120140
  const secrets = secretsOf(job.runtimeId);
120069
120141
  const valueOf = (key) => (secretKeys(runtime).includes(key) ? secrets[key] : values[key]) ?? "";
120070
120142
  const set = async (key, value) => {
@@ -120085,8 +120157,33 @@ async function setUp(job, ws, deps, io) {
120085
120157
  const failed = await set(key, "");
120086
120158
  if (failed) return failed;
120087
120159
  }
120160
+ if (job.agentRuntimes) {
120161
+ const reports = await deps.runtimes();
120162
+ const rows = Object.fromEntries(Object.entries(job.agentRuntimes).map(([agent, r2]) => [agent, pickRow(job, r2, deps.machineId, reports, servers, mcpFile)]));
120163
+ const picked = await akb(["raw", "agent", "picks", JSON.stringify(rows)]);
120164
+ if (picked.code !== 0) return refusal2(picked);
120165
+ }
120088
120166
  return null;
120089
120167
  }
120168
+ function valuesOf(runtime, model, given, servers, mcpFile) {
120169
+ const values = { ...given, model: model ?? "" };
120170
+ if (settingKeys(runtime).includes(MCP_KEY)) values[MCP_KEY] = mcpConfig(servers, mcpFile) ?? given[MCP_KEY] ?? "";
120171
+ else values[RAW_ARGS_KEY] = [given[RAW_ARGS_KEY], mcpArgs(runtime, servers, mcpFile)].filter(Boolean).join(" ");
120172
+ return values;
120173
+ }
120174
+ function pickRow(job, r2, machine, reports, servers, mcpFile) {
120175
+ const zh = cloudLanguage(job) === "zh";
120176
+ const known2 = RUNTIMES.includes(r2.runtime);
120177
+ const runtime = known2 ? r2.runtime : "claude-code";
120178
+ const away = !known2 || r2.runner !== machine ? zh ? `\u6240\u9009\u8FD0\u884C\u65F6\u300C${r2.name}\u300D\u4E0D\u5728\u8FD9\u53F0\u7535\u8111\u4E0A\u3002` : `The runtime "${r2.name}" picked for this step is not on this computer.` : unavailable(runtime, reports);
120179
+ if (away) return { id: r2.id, name: r2.name, harness: runtime, settings: {}, away };
120180
+ const secrets = secretsOf(r2.id);
120181
+ const values = valuesOf(runtime, r2.model, r2.settings, servers, mcpFile);
120182
+ const provider = providerKey(runtime);
120183
+ if (provider) values[provider] = providerOf(runtime, r2.model, { settings: r2.settings, secrets }) ?? "";
120184
+ const settings = Object.fromEntries(Object.entries(values).filter(([k2, v]) => v && !secretKeys(runtime).includes(k2)));
120185
+ return { id: r2.id, name: r2.name, harness: runtime, settings, secrets: Object.fromEntries(secretKeys(runtime).flatMap((k2) => secrets[k2] ? [[k2, secrets[k2]]] : [])) };
120186
+ }
120090
120187
  async function runReview(job, ws, tasks, deps, io) {
120091
120188
  const since = Date.now();
120092
120189
  const failed = await setUp(job, ws, deps, io);
@@ -120097,7 +120194,7 @@ async function runReview(job, ws, tasks, deps, io) {
120097
120194
  const answer = answerOf2(ran);
120098
120195
  if (ran.code !== 0) return { ok: false, reason: reasonOf(answer?.error?.message?.replace(/^run \S+ ended \w+: /, "")) ?? refusal2(ran) };
120099
120196
  const runs = answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? [];
120100
- return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since)) } };
120197
+ return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since), job) } };
120101
120198
  }
120102
120199
  async function reviewRejections(job, ws, deps, io) {
120103
120200
  const workspace = workspaceOf(ws);
@@ -120143,7 +120240,7 @@ async function runAgent(job, ws, deps, io) {
120143
120240
  if (name === "review-dismissals") {
120144
120241
  const { runs: runs2, failure: failure2 } = await reviewRejections(job, ws, deps, io);
120145
120242
  if (io.lost()) return { ok: false, reason: "" };
120146
- return failure2 ? { ok: false, reason: failure2 } : { ok: true, report: spentBy(runs2) };
120243
+ return failure2 ? { ok: false, reason: failure2 } : { ok: true, report: spentBy(runs2, job) };
120147
120244
  }
120148
120245
  if (name === "reflect" && !tasks?.length) return { ok: true, report: {} };
120149
120246
  const args = workflow ? ["raw", "agent", "run", workflowName(workflow), name] : name === "reflect" ? ["raw", "reflect", "--cards", ...tasks.map((t2) => String(t2.number))] : ["raw", ...name === "prune-memory" ? ["memory", "prune"] : [name]];
@@ -120155,7 +120252,7 @@ async function runAgent(job, ws, deps, io) {
120155
120252
  const answer = answerOf2(ran);
120156
120253
  if (ran.code !== 0) return { ok: false, reason: reasonOf(answer?.error?.message?.replace(/^run \S+ ended \w+: /, "")) ?? refusal2(ran) };
120157
120254
  const runs = answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? [];
120158
- return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since)) } };
120255
+ return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since), job) } };
120159
120256
  }
120160
120257
  function writeTranscript(job, dir) {
120161
120258
  if (!job.transcript) return "";
@@ -120306,7 +120403,11 @@ ${draftLine(ws)}
120306
120403
  if (rejected) ran = resolved;
120307
120404
  else if (resolved.code !== 0) note = text3;
120308
120405
  }
120309
- const fresh = () => akb(["raw", "card", verb, String(id2), "--follow", "--events", "--json", ...carryArgs(verb), ...note ? ["--", note] : []], true);
120406
+ const fresh = () => {
120407
+ const carry = carryArgs(verb);
120408
+ const costFrom = carry.includes("--session") && job.resumeCostUsd ? { [SESSION_COST_ENV]: String(job.resumeCostUsd) } : void 0;
120409
+ return akb(["raw", "card", verb, String(id2), "--follow", "--events", "--json", ...carry, ...note ? ["--", note] : []], true, costFrom);
120410
+ };
120310
120411
  ran ??= await (continuation ? akb([...continuation, "--follow", "--events", "--json"], true) : fresh());
120311
120412
  if (continuation && ran.code !== 0 && answerOf2(ran)?.error?.reason === "runNoSession") ran = await fresh();
120312
120413
  if (io.lost()) return fail("");
@@ -120327,7 +120428,7 @@ ${draftLine(ws)}
120327
120428
  const last2 = answer?.lastSessionId ?? answer?.error?.lastSessionId;
120328
120429
  const runs = answerOf2(await akb(["raw", "run", "list", "--card", String(id2), "--all", "--json"]))?.runs ?? [];
120329
120430
  const said = ((last2 ? runs.find((r2) => r2.sessionId === last2)?.result : void 0) ?? answer?.result ?? answer?.error?.result)?.trim();
120330
- const spent = spentBy([...learned, ...runs.filter((r2) => (r2.startedAt ?? 0) >= since)]);
120431
+ const spent = spentBy([...learned, ...runs.filter((r2) => (r2.startedAt ?? 0) >= since)], job);
120331
120432
  const commit = !rejected && ran.code === 0 ? answer?.delivery?.commit : void 0;
120332
120433
  const landing = commit ? { landing: { commit, branch: answer?.delivery?.branch ?? "" } } : {};
120333
120434
  const session = answer?.agentSession ?? answer?.error?.agentSession;
@@ -120828,6 +120929,41 @@ function contextLimit(harness, model) {
120828
120929
  return widest || void 0;
120829
120930
  }
120830
120931
 
120932
+ // src/subagents.ts
120933
+ var BEFORE_CHARS = 4096;
120934
+ function trackSubagents(now = Date.now) {
120935
+ const said = [];
120936
+ let before = null;
120937
+ const items = /* @__PURE__ */ new Map();
120938
+ return {
120939
+ event(e2) {
120940
+ if (e2.kind === "message" && before === null) said.push(e2.data.text);
120941
+ if (e2.kind === "tool_call" && e2.data.subagent && !items.has(e2.data.toolCallId)) {
120942
+ before ??= said.join("\n\n").slice(0, BEFORE_CHARS);
120943
+ items.set(e2.data.toolCallId, { title: e2.data.title, state: "running", started: now() });
120944
+ }
120945
+ if (e2.kind !== "tool_call_update") return;
120946
+ const item = items.get(e2.data.toolCallId);
120947
+ if (item?.state === "running" && (e2.data.status === "completed" || e2.data.status === "failed")) {
120948
+ item.state = e2.data.status === "completed" ? "done" : "failed";
120949
+ item.ms = now() - item.started;
120950
+ }
120951
+ },
120952
+ /** Null without a subagent; one still running when the reply ends is stopped. */
120953
+ summary() {
120954
+ if (!items.size) return void 0;
120955
+ return {
120956
+ before: before ?? "",
120957
+ items: [...items.values()].map((i) => ({
120958
+ title: i.title,
120959
+ state: i.state === "running" ? "stopped" : i.state,
120960
+ duration_ms: i.ms ?? now() - i.started
120961
+ }))
120962
+ };
120963
+ }
120964
+ };
120965
+ }
120966
+
120831
120967
  // src/jobs.ts
120832
120968
  var FLUSH_MS = 2e3;
120833
120969
  var FLUSH_CHARS = 32 * 1024;
@@ -121359,9 +121495,11 @@ ${prompt}` : prompt;
121359
121495
  return { ...rest, ...replySpent(checkpoint, job.runtime) };
121360
121496
  };
121361
121497
  let replyProgress = false;
121498
+ const subagents = trackSubagents();
121362
121499
  const remember = (event2) => {
121363
121500
  if (["message", "tool_call", "tool_call_update"].includes(event2.kind)) replyProgress = true;
121364
121501
  if (stream.lost()) return;
121502
+ subagents.event(event2);
121365
121503
  checkpointEvent(checkpoint, event2);
121366
121504
  const session = run2?.session();
121367
121505
  if (session) checkpoint.session = session;
@@ -121403,8 +121541,10 @@ ${prompt}` : prompt;
121403
121541
  persist();
121404
121542
  };
121405
121543
  let savedGoals;
121406
- const told = (said2) => {
121544
+ const told = (report2) => {
121407
121545
  if (goalFile) savedGoals ??= readGoals(goalFile);
121546
+ const ran = subagents.summary();
121547
+ const said2 = ran ? { ...report2, subagents: ran } : report2;
121408
121548
  return savedGoals ? { ...said2, ...job.discussion?.goals !== void 0 ? { goals: savedGoals } : { ideas: savedGoals } } : said2;
121409
121549
  };
121410
121550
  track(stream.stop);
@@ -121701,8 +121841,7 @@ async function finish(deps, id, lease, outcome, reason = "", report2) {
121701
121841
  async function sendBack(deps, id, lease, ws, said, landed = () => {
121702
121842
  }) {
121703
121843
  const built = await builtWorkflow(ws, deps.akb);
121704
- if (built && !built.ok) return finish(deps, id, lease, "failed", built.reason, said);
121705
- const report2 = built ? { ...said, workflow: { files: built.files } } : said;
121844
+ const report2 = built ? { ...said, workflow: { files: built } } : said;
121706
121845
  const pushed = await whileOffline(deps, id, lease, () => push(ws, { id, machineId: deps.machineId }));
121707
121846
  if (!pushed) return;
121708
121847
  if (pushed.ok) {