wildcrane-runner 0.6.72 → 0.6.74

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.59 — built by runner/scripts/build.mjs. Do not edit.
2
+ // ai4kanban 0.11.61 — built by runner/scripts/build.mjs. Do not edit.
3
3
  import { createRequire as __ai4kanbanRequire } from 'node:module'
4
4
  const require = __ai4kanbanRequire(import.meta.url)
5
5
  var __create = Object.create;
@@ -3139,7 +3139,7 @@ var init_package = __esm({
3139
3139
  "../cli/package.json"() {
3140
3140
  package_default = {
3141
3141
  name: "wildcrane",
3142
- version: "0.11.59",
3142
+ version: "0.11.61",
3143
3143
  akbContract: 17,
3144
3144
  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.",
3145
3145
  keywords: [
@@ -6308,7 +6308,29 @@ var init_config = __esm({
6308
6308
 
6309
6309
  // ../cli/src/lib/cloud/session.ts
6310
6310
  import fs19 from "node:fs";
6311
+ import { createHash as createHash4 } from "node:crypto";
6311
6312
  import path22 from "node:path";
6313
+ function readRetry(session) {
6314
+ try {
6315
+ const retry2 = JSON.parse(fs19.readFileSync(retryFile(), "utf8"));
6316
+ if (retry2.key === refreshKey(session) && Number.isFinite(retry2.until) && Number.isInteger(retry2.attempt) && retry2.attempt > 0 && typeof retry2.error === "string") return retry2;
6317
+ } catch {
6318
+ }
6319
+ }
6320
+ function deferRefresh(session, error, after2) {
6321
+ const current = readSession();
6322
+ if (current?.subject === session.subject && current.refreshToken === session.refreshToken) {
6323
+ const attempt2 = Math.min((readRetry(session)?.attempt ?? 0) + 1, 4);
6324
+ const seconds = after2?.trim() ? Number(after2) : NaN;
6325
+ const serverDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(after2 ?? "") - Date.now();
6326
+ const delay = Math.max(Math.min(REFRESH_BACKOFF_MS * 2 ** (attempt2 - 1), 3e5), Number.isFinite(serverDelay) ? serverDelay : 0);
6327
+ const retry2 = { key: refreshKey(session), until: Date.now() + delay, attempt: attempt2, error };
6328
+ const temporary = `${retryFile()}.${process.pid}.tmp`;
6329
+ fs19.writeFileSync(temporary, JSON.stringify(retry2), { mode: 384 });
6330
+ fs19.renameSync(temporary, retryFile());
6331
+ }
6332
+ return { ok: false, reason: "unreachable", error };
6333
+ }
6312
6334
  function readSession() {
6313
6335
  let raw;
6314
6336
  try {
@@ -6331,10 +6353,12 @@ function writeSession(session) {
6331
6353
  fs19.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
6332
6354
  `, { mode: 384 });
6333
6355
  fs19.renameSync(tmp, sessionFile());
6356
+ if (!expiringSoon(session) || !readRetry(session)) fs19.rmSync(retryFile(), { force: true });
6334
6357
  }
6335
6358
  function clearSession() {
6336
6359
  try {
6337
6360
  fs19.rmSync(sessionFile());
6361
+ fs19.rmSync(retryFile(), { force: true });
6338
6362
  } catch {
6339
6363
  }
6340
6364
  }
@@ -6346,30 +6370,33 @@ async function accessToken() {
6346
6370
  }
6347
6371
  async function refresh() {
6348
6372
  const lock = await takeLock();
6373
+ if (!lock) return { ok: false, reason: "unreachable", error: "Cloud sign-in refresh is busy. Try again shortly." };
6349
6374
  try {
6350
6375
  const now = readSession();
6351
6376
  if (!now) return { ok: false, reason: "signed-out" };
6352
6377
  if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
6378
+ const retry2 = readRetry(now);
6379
+ if (retry2 && retry2.until > Date.now()) return { ok: false, reason: "unreachable", error: retry2.error };
6353
6380
  const { api, anonKey } = cloudEndpoints();
6354
6381
  let response;
6355
6382
  try {
6356
6383
  response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
6357
6384
  method: "POST",
6358
6385
  headers: { apikey: anonKey, "content-type": "application/json" },
6359
- body: JSON.stringify({ refresh_token: now.refreshToken })
6386
+ body: JSON.stringify({ refresh_token: now.refreshToken }),
6387
+ signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS)
6360
6388
  });
6361
6389
  } catch (e2) {
6362
- return { ok: false, reason: "unreachable", error: e2 instanceof Error ? e2.message : String(e2) };
6390
+ return deferRefresh(now, e2 instanceof Error ? e2.message : String(e2));
6363
6391
  }
6364
6392
  if (!response.ok) {
6365
- const body = await response.json().catch(() => ({}));
6366
- if (response.status >= 500) {
6367
- return { ok: false, reason: "unreachable", error: body.error_description ?? `Cloud answered ${response.status}` };
6368
- }
6369
- return { ok: false, reason: "expired", error: body.error_description };
6393
+ const body = await response.json().catch(() => null);
6394
+ const error = body?.error_description ?? body?.msg ?? body?.message;
6395
+ if (![400, 401, 403].includes(response.status)) return deferRefresh(now, error ?? `Cloud answered ${response.status}`, response.headers.get("retry-after"));
6396
+ return { ok: false, reason: "expired", error };
6370
6397
  }
6371
- const fresh = sessionFrom(await response.json(), now);
6372
- if (!fresh) return { ok: false, reason: "expired" };
6398
+ const fresh = sessionFrom(await response.json().catch(() => null), now);
6399
+ if (!fresh) return deferRefresh(now, "Cloud returned an invalid sign-in refresh response.");
6373
6400
  const current = readSession();
6374
6401
  if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
6375
6402
  if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
@@ -6380,6 +6407,7 @@ async function refresh() {
6380
6407
  }
6381
6408
  }
6382
6409
  function sessionFrom(body, previous) {
6410
+ if (!body || typeof body !== "object") return null;
6383
6411
  const token2 = body;
6384
6412
  const subject = token2.user?.id ?? previous?.subject;
6385
6413
  if (!token2.access_token || !token2.refresh_token || !subject) return null;
@@ -6421,8 +6449,7 @@ async function takeLock() {
6421
6449
  fs19.rmSync(lockDir(), { recursive: true, force: true });
6422
6450
  continue;
6423
6451
  }
6424
- if (Date.now() > until) return () => {
6425
- };
6452
+ if (Date.now() > until) return null;
6426
6453
  await sleep2(LOCK_RETRY_MS);
6427
6454
  }
6428
6455
  }
@@ -6435,7 +6462,7 @@ function stale() {
6435
6462
  } catch {
6436
6463
  held4 = void 0;
6437
6464
  }
6438
- if (held4 !== void 0 && !alive(held4)) return true;
6465
+ if (held4 !== void 0) return !alive(held4);
6439
6466
  try {
6440
6467
  return Date.now() - fs19.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
6441
6468
  } catch {
@@ -6450,7 +6477,7 @@ function alive(pid) {
6450
6477
  return e2.code === "EPERM";
6451
6478
  }
6452
6479
  }
6453
- var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, sessionFile, lockDir, lockOwner, expiringSoon, sleep2;
6480
+ var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, REFRESH_TIMEOUT_MS, REFRESH_BACKOFF_MS, sessionFile, lockDir, lockOwner, retryFile, refreshKey, expiringSoon, sleep2;
6454
6481
  var init_session = __esm({
6455
6482
  "../cli/src/lib/cloud/session.ts"() {
6456
6483
  "use strict";
@@ -6460,9 +6487,13 @@ var init_session = __esm({
6460
6487
  LOCK_STALE_MS = 3e4;
6461
6488
  LOCK_WAIT_MS = 2e4;
6462
6489
  LOCK_RETRY_MS = 50;
6490
+ REFRESH_TIMEOUT_MS = 15e3;
6491
+ REFRESH_BACKOFF_MS = 6e4;
6463
6492
  sessionFile = () => path22.join(machineHome(), "session.json");
6464
6493
  lockDir = () => path22.join(machineHome(), "session.lock");
6465
6494
  lockOwner = () => path22.join(lockDir(), "owner");
6495
+ retryFile = () => path22.join(machineHome(), "session-refresh.json");
6496
+ refreshKey = (session) => createHash4("sha256").update(JSON.stringify([cloudEndpoints().api, session.subject, session.refreshToken])).digest("hex");
6466
6497
  expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
6467
6498
  sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
6468
6499
  }
@@ -6753,7 +6784,7 @@ function parseStore() {
6753
6784
  resumedFrom: typeof entry.resumedFrom === "string" ? entry.resumedFrom : void 0,
6754
6785
  continues: typeof entry.continues?.resumeId === "string" && entry.continues.resumeId ? { resumeId: entry.continues.resumeId, ...entry.continues.fork === true ? { fork: true } : {} } : void 0,
6755
6786
  formatRepair: entry.formatRepair && typeof entry.formatRepair === "object" && Number.isInteger(entry.formatRepair.attempt) && entry.formatRepair.attempt >= 0 && typeof entry.formatRepair.errors === "string" && [entry.formatRepair.cardIds, entry.formatRepair.changedIds, entry.formatRepair.existingIds].every((ids) => Array.isArray(ids) && ids.every(Number.isInteger)) ? entry.formatRepair : void 0,
6756
- retry: readRetry(entry.retry),
6787
+ retry: readRetry2(entry.retry),
6757
6788
  priorStatus: typeof entry.priorStatus === "string" ? entry.priorStatus : void 0,
6758
6789
  // The pictures the create sheet handed this run (#517), as paths in its own folder.
6759
6790
  pictures: readPictures(entry.pictures),
@@ -6795,7 +6826,7 @@ function readReasons(raw) {
6795
6826
  });
6796
6827
  return reasons.length ? reasons : void 0;
6797
6828
  }
6798
- function readRetry(raw) {
6829
+ function readRetry2(raw) {
6799
6830
  if (!raw || typeof raw !== "object") return void 0;
6800
6831
  const r2 = raw;
6801
6832
  const whole2 = Number.isInteger(r2.attempt) && r2.attempt > 0 && Number.isInteger(r2.of) && r2.of > 0 && typeof r2.reason === "string" && !!r2.reason && typeof r2.at === "number" && typeof r2.since === "number";
@@ -17573,7 +17604,7 @@ var init_read = __esm({
17573
17604
  // ../cli/src/lib/agent/preview-progress.ts
17574
17605
  import fs62 from "node:fs";
17575
17606
  import path65 from "node:path";
17576
- import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
17607
+ import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
17577
17608
  function readPreviewProgress(id) {
17578
17609
  try {
17579
17610
  return JSON.parse(fs62.readFileSync(file(id), "utf8"));
@@ -17605,7 +17636,7 @@ function freezePreviewProgress(id, name) {
17605
17636
  const files = Object.fromEntries(agent.files.map((file2) => [file2, agent.file(file2)]).filter((entry) => entry[1] !== null));
17606
17637
  if (!agent.stages) files["preview.md"] = agent.body;
17607
17638
  for (const stage of definitions) files[stage.instructions] ??= agent.file(stage.instructions);
17608
- const definitionRevision = createHash4("sha256").update(JSON.stringify({ stages: definitions, body: agent.body, files })).digest("hex");
17639
+ const definitionRevision = createHash5("sha256").update(JSON.stringify({ stages: definitions, body: agent.body, files })).digest("hex");
17609
17640
  const progress = { agent: name, definitionRevision, generation: 1, currentStageId: null, definitions, body: agent.body, files, stages: [], displayedArtifact: null, execution: null };
17610
17641
  if (!agent.stages) selectPreviewStages(progress, ["preview"]);
17611
17642
  return updatePreviewProgress(id, (all2) => all2[name] ??= progress);
@@ -17759,7 +17790,7 @@ var init_preview_progress = __esm({
17759
17790
  init_execution();
17760
17791
  init_preview_stages();
17761
17792
  file = (id) => path65.join(BOARD_STATE, "previews", `${id}.json`);
17762
- contextFile = (id, name, owner) => path65.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash4("sha256").update(owner).digest("hex")}.json`);
17793
+ contextFile = (id, name, owner) => path65.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash5("sha256").update(owner).digest("hex")}.json`);
17763
17794
  PreviewContextMissing = class extends Error {
17764
17795
  };
17765
17796
  baselineFile = (id, name, run4) => path65.join(BOARD_STATE, "previews", "runs", String(id), name, `${run4}.json`);
@@ -23009,7 +23040,7 @@ var init_agent = __esm({
23009
23040
  });
23010
23041
 
23011
23042
  // ../cli/src/commands/cloud-template.ts
23012
- import { createHash as createHash5 } from "node:crypto";
23043
+ import { createHash as createHash6 } from "node:crypto";
23013
23044
  import fs73 from "node:fs";
23014
23045
  import path75 from "node:path";
23015
23046
  function usage2(problem, line) {
@@ -23107,7 +23138,7 @@ async function templateGet(name, opts, program2) {
23107
23138
  const out = path75.resolve(to, f2.path);
23108
23139
  if (!out.startsWith(path75.resolve(to) + path75.sep)) refuse3(T.corrupt, WITHOUT);
23109
23140
  const bytes2 = Buffer.from(await (await ask(`/${at2}/files/${route(f2.path)}`, {}, WITHOUT)).arrayBuffer());
23110
- if (bytes2.byteLength !== f2.size || createHash5("sha256").update(bytes2).digest("hex") !== f2.sha256) {
23141
+ if (bytes2.byteLength !== f2.size || createHash6("sha256").update(bytes2).digest("hex") !== f2.sha256) {
23111
23142
  refuse3(T.corrupt, WITHOUT);
23112
23143
  }
23113
23144
  fetched.push({ out, bytes: bytes2 });
@@ -23447,7 +23478,7 @@ var init_follow_up = __esm({
23447
23478
  var implement_default;
23448
23479
  var init_implement = __esm({
23449
23480
  "../cli/src/guide/implement.md"() {
23450
- implement_default = "# Implement the approved requirements\n\nBuild the approved card or plan directly. Preserve settled decisions and unrelated questions;\ndo not replace or contradict the approved requirements. With no card, build only the given\nrequirement and create no card.\n\n- **Authorization**: approval covers the necessary operations within the agreed scope and\n constraints; carry it across commands, tools and stages without repeated confirmation.\n- **User-action blockers**: resolve routine choices and problems yourself; ask only when\n reasonable investigation leaves a blocker requiring user action or a decision beyond the\n approved scope. On a card, use `akb guide update-questions`, stating what you tried, what\n is blocked and your recommendation; continue independent work.\n- **Defer what can wait**: follow `akb guide follow-up` for work this build does not require;\n never ask about it or let it block this build.\n- **Decisions made while building**: record an answered material decision the user could\n reasonably reverse under `## Worth noting after implementation` on the card.\n";
23481
+ implement_default = "# Implement the approved requirements\n\nBuild the approved requirements without reopening settled decisions or unrelated questions; without a card, create none.\n\n- **Verification**: run required and minimal representative checks, reuse valid results, distinguish defects from environment or tool limits, stop retries that add no evidence, and finish when acceptance is proven.\n- **Authorization**: carry approval for necessary in-scope operations across tools and stages without asking again.\n- **Blockers**: resolve routine problems and use `akb guide update-questions` only for user-action blockers or out-of-scope decisions, stating attempts, impact and recommendation while continuing independent work.\n- **Defer**: follow `akb guide follow-up` for unrelated work and keep it from blocking delivery.\n- **Decisions**: record material, reversible build decisions under `## Worth noting after implementation`.\n";
23451
23482
  }
23452
23483
  });
23453
23484
 
@@ -23487,7 +23518,7 @@ var init_review_rejections = __esm({
23487
23518
  var refine_default;
23488
23519
  var init_refine = __esm({
23489
23520
  "../cli/src/guide/refine.md"() {
23490
- refine_default = "# Refine a card\n\nPlan one card until it can be built.\n\n- **Unchecked card**: a card with `triage:` set and an empty `## Scope` was never checked\n against the project. Check it first; when the project already does\n the work, or what it concerns no longer exists, run\n `akb raw reject <id> --reason \"<what shows it>\"` and stop.\n- **Gone or already done**: for any other card, append a question asking the user whether to\n discard it, run no preview agent, and stop.\n- **Existing group**: read its subtasks and check that they cover the parent\u2019s outcome;\n keep a complete split, or fill gaps by updating subtasks and dependencies without\n duplicating work or resetting progress. Finish the pass without marking the parent\n ready merely because its split is complete; its completion still follows its subtasks.\n- **Studio rules**: write the card as the studio rules at the end of this prompt say.\n- **Preview agents**: an agent's `After` names the previews it waits for; the board approves\n previews in stages, one stage per Approve, and the card's `previews` were chosen when its\n goal was written. A card without `previews` has not chosen: choose and save them first, as\n the list says, then run only its first stage. Run each listed agent whose section is missing\n or outdated with `akb raw previews <agent> <id>`; choose `--print` for this session or\n omit it for a separate session.\n- **Stale mentions**: rewrite any sentence that relies on a card no longer on the board.\n- **Questions**: settle every decision you can and record the answers as `akb guide writing`\n says; ask only what `akb guide update-questions` says to ask.\n- **Write**: shape the card as `akb guide writing` says, then run `akb raw validate <id>` and\n fix every reported line.\n- **Ready**: settle every fact from the project and authoritative sources. Once the card\n validates, judge whether it can be built as written, or before its last Approve: if so, run\n `akb raw update <id> --status ready`; otherwise leave what blocks it as an open question.\n\nFollow any closing steps the flow printed, then stop: the user approves the previews or starts\nthe build.\n";
23521
+ refine_default = '# Refine a card\n\nPlan one card until it is buildable.\n\n- **Unchecked cards**: check cards with `triage:` and empty `## Scope` against the project, rejecting obsolete or completed work with `akb raw reject <id> --reason "<evidence>"` and stopping.\n- **Other obsolete or completed cards**: ask whether to discard, run no previews, and stop.\n- **Groups**: preserve subtask coverage and progress, fill gaps without duplication, and do not mark the parent ready merely because its split is complete.\n- **Verification**: plan representative checks for the outcome, project rules and material risks, confirm prerequisites, and keep optional coverage optional.\n- **Previews**: keep chosen `previews` or select and save them if absent, then follow `After` dependencies and run only missing or outdated work in the current stage with `akb raw previews <agent> <id>`, using `--print` for this session or omitting it for a separate session.\n- **References**: rewrite mentions of cards no longer on the board.\n- **Decisions**: settle choices supported by evidence and ask only as `akb guide update-questions` allows.\n- **Card**: follow studio rules and `akb guide writing`, fixing all errors from `akb raw validate <id>`.\n- **Ready**: when validated and buildable with prerequisites settled, run `akb raw update <id> --status ready`; otherwise leave blockers as open questions.\n\nFollow the printed closing steps, then stop for the user to approve previews or start the build.\n';
23491
23522
  }
23492
23523
  });
23493
23524
 
@@ -24745,7 +24776,7 @@ var init_stage_end = __esm({
24745
24776
  });
24746
24777
 
24747
24778
  // ../cli/src/lib/agent/refine.ts
24748
- import { createHash as createHash6 } from "node:crypto";
24779
+ import { createHash as createHash7 } from "node:crypto";
24749
24780
  function markBoard() {
24750
24781
  try {
24751
24782
  return new Map(allCards().map((card) => [card.id, wroteOf(card)]));
@@ -24882,7 +24913,7 @@ var init_refine2 = __esm({
24882
24913
  };
24883
24914
  MARKER = /^<!--\s*agent\s*-->$/;
24884
24915
  asMoved = (body) => body.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim() && !MARKER.test(line.trim())).sort();
24885
- wroteOf = (card) => createHash6("sha1").update(
24916
+ wroteOf = (card) => createHash7("sha1").update(
24886
24917
  JSON.stringify([
24887
24918
  card.status,
24888
24919
  card.relPath,
@@ -26321,7 +26352,7 @@ var init_check2 = __esm({
26321
26352
  });
26322
26353
 
26323
26354
  // ../cli/src/lib/signals/identity.ts
26324
- import { createHash as createHash7 } from "node:crypto";
26355
+ import { createHash as createHash8 } from "node:crypto";
26325
26356
  function host(url) {
26326
26357
  try {
26327
26358
  return new URL(url).hostname.replace(/^www\./, "");
@@ -26343,14 +26374,14 @@ var init_identity2 = __esm({
26343
26374
  "../cli/src/lib/signals/identity.ts"() {
26344
26375
  "use strict";
26345
26376
  DERIVED = "derived-";
26346
- derivedSourceId = (seed) => `${DERIVED}${createHash7("sha256").update(seed).digest("hex").slice(0, 16)}`;
26377
+ derivedSourceId = (seed) => `${DERIVED}${createHash8("sha256").update(seed).digest("hex").slice(0, 16)}`;
26347
26378
  }
26348
26379
  });
26349
26380
 
26350
26381
  // ../cli/src/lib/signals/add.ts
26351
26382
  import fs82 from "node:fs";
26352
26383
  import path83 from "node:path";
26353
- import { createHash as createHash8 } from "node:crypto";
26384
+ import { createHash as createHash9 } from "node:crypto";
26354
26385
  function linkTitle(url) {
26355
26386
  let at2;
26356
26387
  try {
@@ -26375,7 +26406,7 @@ function fileName2(name, data) {
26375
26406
  const base = path83.basename(name);
26376
26407
  const ext = path83.extname(base).toLowerCase().slice(0, 12);
26377
26408
  const word = path83.basename(base, path83.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
26378
- const hash2 = createHash8("sha256").update(data).digest("hex").slice(0, 8);
26409
+ const hash2 = createHash9("sha256").update(data).digest("hex").slice(0, 8);
26379
26410
  return `${word}-${hash2}${ext}`;
26380
26411
  }
26381
26412
  function addToInbox(drop) {
@@ -111046,7 +111077,7 @@ var init_draw_mockup = __esm({
111046
111077
  // ../cli/src/commands/studio-preview.ts
111047
111078
  import fs85 from "node:fs";
111048
111079
  import path85 from "node:path";
111049
- import { createHash as createHash9, randomUUID as randomUUID8 } from "node:crypto";
111080
+ import { createHash as createHash10, randomUUID as randomUUID8 } from "node:crypto";
111050
111081
  import { spawnSync as spawnSync6 } from "node:child_process";
111051
111082
  function readFolder2(folder) {
111052
111083
  const root2 = fs85.realpathSync(folder);
@@ -111067,7 +111098,7 @@ function readFolder2(folder) {
111067
111098
  scan(root2);
111068
111099
  const files = readStudioFolder(root2), checked = checkStudioFiles(files, readVersion2(files)?.id.startsWith("wf_builtin_") === true);
111069
111100
  if (!checked.ok) die(`${folder}/${checked.file}: ${checked.reason}`, "studio-problems");
111070
- const fingerprint = createHash9("sha256").update(hashInput({ ...checked.files, ...files[VERSION_FILE] ? { [VERSION_FILE]: files[VERSION_FILE] } : {} })).digest("hex");
111101
+ const fingerprint = createHash10("sha256").update(hashInput({ ...checked.files, ...files[VERSION_FILE] ? { [VERSION_FILE]: files[VERSION_FILE] } : {} })).digest("hex");
111071
111102
  return { files, def: checked.def, fingerprint };
111072
111103
  }
111073
111104
  function agentsOf2(held4) {
@@ -2228,7 +2228,7 @@ function createTail(log) {
2228
2228
  // ../cli/package.json
2229
2229
  var package_default = {
2230
2230
  name: "wildcrane",
2231
- version: "0.11.59",
2231
+ version: "0.11.61",
2232
2232
  akbContract: 17,
2233
2233
  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.",
2234
2234
  keywords: [
@@ -1 +1 @@
1
- {"name":"wildcrane","version":"0.11.59","akbContract":17,"type":"module","private":true}
1
+ {"name":"wildcrane","version":"0.11.61","akbContract":17,"type":"module","private":true}
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.72 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.74 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.72 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.74 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.72 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.74 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.72 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.74 — 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;
@@ -111178,6 +111178,7 @@ import { fileURLToPath as fileURLToPath4 } from "node:url";
111178
111178
 
111179
111179
  // ../cli/src/lib/cloud/session.ts
111180
111180
  import fs2 from "node:fs";
111181
+ import { createHash } from "node:crypto";
111181
111182
  import path3 from "node:path";
111182
111183
 
111183
111184
  // ../cli/src/lib/machine/home.ts
@@ -111205,9 +111206,34 @@ var REFRESH_MARGIN_MS = 6e4;
111205
111206
  var LOCK_STALE_MS = 3e4;
111206
111207
  var LOCK_WAIT_MS = 2e4;
111207
111208
  var LOCK_RETRY_MS = 50;
111209
+ var REFRESH_TIMEOUT_MS = 15e3;
111210
+ var REFRESH_BACKOFF_MS = 6e4;
111208
111211
  var sessionFile = () => path3.join(machineHome(), "session.json");
111209
111212
  var lockDir = () => path3.join(machineHome(), "session.lock");
111210
111213
  var lockOwner = () => path3.join(lockDir(), "owner");
111214
+ var retryFile = () => path3.join(machineHome(), "session-refresh.json");
111215
+ var refreshKey = (session) => createHash("sha256").update(JSON.stringify([cloudEndpoints().api, session.subject, session.refreshToken])).digest("hex");
111216
+ function readRetry(session) {
111217
+ try {
111218
+ const retry2 = JSON.parse(fs2.readFileSync(retryFile(), "utf8"));
111219
+ if (retry2.key === refreshKey(session) && Number.isFinite(retry2.until) && Number.isInteger(retry2.attempt) && retry2.attempt > 0 && typeof retry2.error === "string") return retry2;
111220
+ } catch {
111221
+ }
111222
+ }
111223
+ function deferRefresh(session, error, after) {
111224
+ const current2 = readSession();
111225
+ if (current2?.subject === session.subject && current2.refreshToken === session.refreshToken) {
111226
+ const attempt = Math.min((readRetry(session)?.attempt ?? 0) + 1, 4);
111227
+ const seconds = after?.trim() ? Number(after) : NaN;
111228
+ const serverDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(after ?? "") - Date.now();
111229
+ const delay = Math.max(Math.min(REFRESH_BACKOFF_MS * 2 ** (attempt - 1), 3e5), Number.isFinite(serverDelay) ? serverDelay : 0);
111230
+ const retry2 = { key: refreshKey(session), until: Date.now() + delay, attempt, error };
111231
+ const temporary = `${retryFile()}.${process.pid}.tmp`;
111232
+ fs2.writeFileSync(temporary, JSON.stringify(retry2), { mode: 384 });
111233
+ fs2.renameSync(temporary, retryFile());
111234
+ }
111235
+ return { ok: false, reason: "unreachable", error };
111236
+ }
111211
111237
  function readSession() {
111212
111238
  let raw;
111213
111239
  try {
@@ -111230,6 +111256,7 @@ function writeSession(session) {
111230
111256
  fs2.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
111231
111257
  `, { mode: 384 });
111232
111258
  fs2.renameSync(tmp, sessionFile());
111259
+ if (!expiringSoon(session) || !readRetry(session)) fs2.rmSync(retryFile(), { force: true });
111233
111260
  }
111234
111261
  async function accessToken() {
111235
111262
  const held5 = readSession();
@@ -111240,30 +111267,33 @@ async function accessToken() {
111240
111267
  var expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
111241
111268
  async function refresh() {
111242
111269
  const lock = await takeLock();
111270
+ if (!lock) return { ok: false, reason: "unreachable", error: "Cloud sign-in refresh is busy. Try again shortly." };
111243
111271
  try {
111244
111272
  const now = readSession();
111245
111273
  if (!now) return { ok: false, reason: "signed-out" };
111246
111274
  if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
111275
+ const retry2 = readRetry(now);
111276
+ if (retry2 && retry2.until > Date.now()) return { ok: false, reason: "unreachable", error: retry2.error };
111247
111277
  const { api, anonKey } = cloudEndpoints();
111248
111278
  let response;
111249
111279
  try {
111250
111280
  response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
111251
111281
  method: "POST",
111252
111282
  headers: { apikey: anonKey, "content-type": "application/json" },
111253
- body: JSON.stringify({ refresh_token: now.refreshToken })
111283
+ body: JSON.stringify({ refresh_token: now.refreshToken }),
111284
+ signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS)
111254
111285
  });
111255
111286
  } catch (e2) {
111256
- return { ok: false, reason: "unreachable", error: e2 instanceof Error ? e2.message : String(e2) };
111287
+ return deferRefresh(now, e2 instanceof Error ? e2.message : String(e2));
111257
111288
  }
111258
111289
  if (!response.ok) {
111259
- const body = await response.json().catch(() => ({}));
111260
- if (response.status >= 500) {
111261
- return { ok: false, reason: "unreachable", error: body.error_description ?? `Cloud answered ${response.status}` };
111262
- }
111263
- return { ok: false, reason: "expired", error: body.error_description };
111290
+ const body = await response.json().catch(() => null);
111291
+ const error = body?.error_description ?? body?.msg ?? body?.message;
111292
+ if (![400, 401, 403].includes(response.status)) return deferRefresh(now, error ?? `Cloud answered ${response.status}`, response.headers.get("retry-after"));
111293
+ return { ok: false, reason: "expired", error };
111264
111294
  }
111265
- const fresh = sessionFrom(await response.json(), now);
111266
- if (!fresh) return { ok: false, reason: "expired" };
111295
+ const fresh = sessionFrom(await response.json().catch(() => null), now);
111296
+ if (!fresh) return deferRefresh(now, "Cloud returned an invalid sign-in refresh response.");
111267
111297
  const current2 = readSession();
111268
111298
  if (!current2 || current2.subject !== now.subject) return { ok: false, reason: "expired" };
111269
111299
  if (current2.refreshToken !== now.refreshToken) return { ok: true, token: current2.accessToken, session: current2 };
@@ -111274,6 +111304,7 @@ async function refresh() {
111274
111304
  }
111275
111305
  }
111276
111306
  function sessionFrom(body, previous) {
111307
+ if (!body || typeof body !== "object") return null;
111277
111308
  const token = body;
111278
111309
  const subject = token.user?.id ?? previous?.subject;
111279
111310
  if (!token.access_token || !token.refresh_token || !subject) return null;
@@ -111315,8 +111346,7 @@ async function takeLock() {
111315
111346
  fs2.rmSync(lockDir(), { recursive: true, force: true });
111316
111347
  continue;
111317
111348
  }
111318
- if (Date.now() > until) return () => {
111319
- };
111349
+ if (Date.now() > until) return null;
111320
111350
  await sleep(LOCK_RETRY_MS);
111321
111351
  }
111322
111352
  }
@@ -111329,7 +111359,7 @@ function stale() {
111329
111359
  } catch {
111330
111360
  held5 = void 0;
111331
111361
  }
111332
- if (held5 !== void 0 && !alive(held5)) return true;
111362
+ if (held5 !== void 0) return !alive(held5);
111333
111363
  try {
111334
111364
  return Date.now() - fs2.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
111335
111365
  } catch {
@@ -111884,7 +111914,7 @@ async function studioSnapshot(workspace, catalog, list2) {
111884
111914
  }
111885
111915
 
111886
111916
  // src/protocol.ts
111887
- var AKB_VERSION = true ? "0.11.59" : "0.0.0";
111917
+ var AKB_VERSION = true ? "0.11.61" : "0.0.0";
111888
111918
  var AKB_CONTRACT = true ? 17 : 0;
111889
111919
 
111890
111920
  // src/secrets.ts
@@ -116298,9 +116328,9 @@ function createKimiStreamRenderer(cwd, resumeId) {
116298
116328
  // ../cli/src/lib/agent/wire/acp-cost.ts
116299
116329
  import fs22 from "node:fs";
116300
116330
  import path23 from "node:path";
116301
- import { createHash } from "node:crypto";
116331
+ import { createHash as createHash2 } from "node:crypto";
116302
116332
  function acpCostFile(tool, cwd, session) {
116303
- const key = createHash("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
116333
+ const key = createHash2("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
116304
116334
  return path23.join(machineHome(), "usage", "acp", `${key}.json`);
116305
116335
  }
116306
116336
  function readAcpCost(file2) {
@@ -116473,7 +116503,7 @@ function createTail(log) {
116473
116503
  // ../cli/package.json
116474
116504
  var package_default = {
116475
116505
  name: "wildcrane",
116476
- version: "0.11.59",
116506
+ version: "0.11.61",
116477
116507
  akbContract: 17,
116478
116508
  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.",
116479
116509
  keywords: [
@@ -117607,7 +117637,7 @@ function quoteArg(arg) {
117607
117637
  }
117608
117638
 
117609
117639
  // ../cli/src/lib/agent/harnesses/types.ts
117610
- import { createHash as createHash2 } from "node:crypto";
117640
+ import { createHash as createHash3 } from "node:crypto";
117611
117641
  import fs25 from "node:fs";
117612
117642
  import path26 from "node:path";
117613
117643
  var SKILL_SENTENCE = "Use the kanban skill";
@@ -117631,7 +117661,7 @@ var MCP_CONFIG = {
117631
117661
  help: "A JSON file of `mcpServers`, as Claude Code's --mcp-config takes. Empty opens no servers."
117632
117662
  };
117633
117663
  function machineFile(name, text4) {
117634
- const suffix = createHash2("sha256").update(text4).digest("hex").slice(0, 16);
117664
+ const suffix = createHash3("sha256").update(text4).digest("hex").slice(0, 16);
117635
117665
  const file2 = path26.join(machineHome(), "prompts", `${path26.parse(name).name}-${suffix}${path26.extname(name)}`);
117636
117666
  try {
117637
117667
  if (fs25.readFileSync(file2, "utf8") === text4) return file2;
@@ -117652,7 +117682,7 @@ import path34 from "node:path";
117652
117682
  // ../cli/src/lib/agent/harnesses/antigravity.ts
117653
117683
  import fs28 from "node:fs";
117654
117684
  import path29 from "node:path";
117655
- import { createHash as createHash3 } from "node:crypto";
117685
+ import { createHash as createHash4 } from "node:crypto";
117656
117686
  import { spawnSync as spawnSync4 } from "node:child_process";
117657
117687
 
117658
117688
  // ../cli/src/lib/agent/locate.ts
@@ -118199,7 +118229,7 @@ var ANTIGRAVITY = {
118199
118229
  const rule = `${text4}
118200
118230
 
118201
118231
  The task working directory is ${env2.PWD ?? process.cwd()}. Use it as the base for project files and commands. This additional workspace contains only language rules; do not write task output here.`;
118202
- const hash = createHash3("sha256").update(rule).digest("hex").slice(0, 16);
118232
+ const hash = createHash4("sha256").update(rule).digest("hex").slice(0, 16);
118203
118233
  const root2 = path29.join(machineHome(), "prompts", `antigravity-${hash}`);
118204
118234
  const file2 = path29.join(root2, ".agents", "rules", "language.md");
118205
118235
  fs28.mkdirSync(path29.dirname(file2), { recursive: true });
@@ -120043,9 +120073,9 @@ import fs32 from "node:fs";
120043
120073
  import path35 from "node:path";
120044
120074
 
120045
120075
  // ../cli/src/lib/signals/identity.ts
120046
- import { createHash as createHash4 } from "node:crypto";
120076
+ import { createHash as createHash5 } from "node:crypto";
120047
120077
  var DERIVED = "derived-";
120048
- var derivedSourceId = (seed) => `${DERIVED}${createHash4("sha256").update(seed).digest("hex").slice(0, 16)}`;
120078
+ var derivedSourceId = (seed) => `${DERIVED}${createHash5("sha256").update(seed).digest("hex").slice(0, 16)}`;
120049
120079
 
120050
120080
  // ../cli/src/lib/slug.ts
120051
120081
  function slugify(s) {
@@ -120873,7 +120903,7 @@ import fs36 from "node:fs";
120873
120903
  import path39 from "node:path";
120874
120904
  import os6 from "node:os";
120875
120905
  import { fileURLToPath as fileURLToPath3 } from "node:url";
120876
- import { createHash as createHash5 } from "node:crypto";
120906
+ import { createHash as createHash6 } from "node:crypto";
120877
120907
 
120878
120908
  // ../cli/src/lib/shared/reply-parts.ts
120879
120909
  function imageMime(bytes2) {
@@ -120949,7 +120979,7 @@ function collectReplyImages(parts, cwd) {
120949
120979
  const bytes2 = read4();
120950
120980
  const mime = imageMime(bytes2);
120951
120981
  if (!mime || p2.mime && p2.mime !== mime || bytes2.length > ASSET_FILE_LIMIT) throw Error();
120952
- const id = `rim_${createHash5("sha256").update(bytes2).digest("hex")}`;
120982
+ const id = `rim_${createHash6("sha256").update(bytes2).digest("hex")}`;
120953
120983
  if (!files.has(id)) files.set(id, { read: read4, mime });
120954
120984
  return { type: "image", id, mime, status: "saved" };
120955
120985
  } catch {
@@ -121004,7 +121034,7 @@ async function saveReplyImages(parts, cwd, upload2) {
121004
121034
  let bytes2;
121005
121035
  try {
121006
121036
  bytes2 = f2.read();
121007
- if (`rim_${createHash5("sha256").update(bytes2).digest("hex")}` !== key || imageMime(bytes2) !== f2.mime) continue;
121037
+ if (`rim_${createHash6("sha256").update(bytes2).digest("hex")}` !== key || imageMime(bytes2) !== f2.mime) continue;
121008
121038
  } catch {
121009
121039
  continue;
121010
121040
  }