wildcrane 0.11.60 → 0.11.61

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/kanban.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.60 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
2
+ // ai4kanban 0.11.61 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
3
3
  // Do not edit: every change belongs in cli/src/, and a build overwrites this file.
4
4
  import { createRequire as __ai4kanbanRequire } from 'node:module'
5
5
  const require = __ai4kanbanRequire(import.meta.url)
@@ -3140,7 +3140,7 @@ var init_package = __esm({
3140
3140
  "package.json"() {
3141
3141
  package_default = {
3142
3142
  name: "wildcrane",
3143
- version: "0.11.60",
3143
+ version: "0.11.61",
3144
3144
  akbContract: 17,
3145
3145
  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.",
3146
3146
  keywords: [
@@ -6309,7 +6309,29 @@ var init_config = __esm({
6309
6309
 
6310
6310
  // src/lib/cloud/session.ts
6311
6311
  import fs19 from "node:fs";
6312
+ import { createHash as createHash4 } from "node:crypto";
6312
6313
  import path22 from "node:path";
6314
+ function readRetry(session) {
6315
+ try {
6316
+ const retry2 = JSON.parse(fs19.readFileSync(retryFile(), "utf8"));
6317
+ if (retry2.key === refreshKey(session) && Number.isFinite(retry2.until) && Number.isInteger(retry2.attempt) && retry2.attempt > 0 && typeof retry2.error === "string") return retry2;
6318
+ } catch {
6319
+ }
6320
+ }
6321
+ function deferRefresh(session, error, after2) {
6322
+ const current = readSession();
6323
+ if (current?.subject === session.subject && current.refreshToken === session.refreshToken) {
6324
+ const attempt2 = Math.min((readRetry(session)?.attempt ?? 0) + 1, 4);
6325
+ const seconds = after2?.trim() ? Number(after2) : NaN;
6326
+ const serverDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(after2 ?? "") - Date.now();
6327
+ const delay = Math.max(Math.min(REFRESH_BACKOFF_MS * 2 ** (attempt2 - 1), 3e5), Number.isFinite(serverDelay) ? serverDelay : 0);
6328
+ const retry2 = { key: refreshKey(session), until: Date.now() + delay, attempt: attempt2, error };
6329
+ const temporary = `${retryFile()}.${process.pid}.tmp`;
6330
+ fs19.writeFileSync(temporary, JSON.stringify(retry2), { mode: 384 });
6331
+ fs19.renameSync(temporary, retryFile());
6332
+ }
6333
+ return { ok: false, reason: "unreachable", error };
6334
+ }
6313
6335
  function readSession() {
6314
6336
  let raw;
6315
6337
  try {
@@ -6332,10 +6354,12 @@ function writeSession(session) {
6332
6354
  fs19.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
6333
6355
  `, { mode: 384 });
6334
6356
  fs19.renameSync(tmp, sessionFile());
6357
+ if (!expiringSoon(session) || !readRetry(session)) fs19.rmSync(retryFile(), { force: true });
6335
6358
  }
6336
6359
  function clearSession() {
6337
6360
  try {
6338
6361
  fs19.rmSync(sessionFile());
6362
+ fs19.rmSync(retryFile(), { force: true });
6339
6363
  } catch {
6340
6364
  }
6341
6365
  }
@@ -6347,30 +6371,33 @@ async function accessToken() {
6347
6371
  }
6348
6372
  async function refresh() {
6349
6373
  const lock = await takeLock();
6374
+ if (!lock) return { ok: false, reason: "unreachable", error: "Cloud sign-in refresh is busy. Try again shortly." };
6350
6375
  try {
6351
6376
  const now = readSession();
6352
6377
  if (!now) return { ok: false, reason: "signed-out" };
6353
6378
  if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
6379
+ const retry2 = readRetry(now);
6380
+ if (retry2 && retry2.until > Date.now()) return { ok: false, reason: "unreachable", error: retry2.error };
6354
6381
  const { api, anonKey } = cloudEndpoints();
6355
6382
  let response;
6356
6383
  try {
6357
6384
  response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
6358
6385
  method: "POST",
6359
6386
  headers: { apikey: anonKey, "content-type": "application/json" },
6360
- body: JSON.stringify({ refresh_token: now.refreshToken })
6387
+ body: JSON.stringify({ refresh_token: now.refreshToken }),
6388
+ signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS)
6361
6389
  });
6362
6390
  } catch (e2) {
6363
- return { ok: false, reason: "unreachable", error: e2 instanceof Error ? e2.message : String(e2) };
6391
+ return deferRefresh(now, e2 instanceof Error ? e2.message : String(e2));
6364
6392
  }
6365
6393
  if (!response.ok) {
6366
- const body = await response.json().catch(() => ({}));
6367
- if (response.status >= 500) {
6368
- return { ok: false, reason: "unreachable", error: body.error_description ?? `Cloud answered ${response.status}` };
6369
- }
6370
- return { ok: false, reason: "expired", error: body.error_description };
6394
+ const body = await response.json().catch(() => null);
6395
+ const error = body?.error_description ?? body?.msg ?? body?.message;
6396
+ if (![400, 401, 403].includes(response.status)) return deferRefresh(now, error ?? `Cloud answered ${response.status}`, response.headers.get("retry-after"));
6397
+ return { ok: false, reason: "expired", error };
6371
6398
  }
6372
- const fresh = sessionFrom(await response.json(), now);
6373
- if (!fresh) return { ok: false, reason: "expired" };
6399
+ const fresh = sessionFrom(await response.json().catch(() => null), now);
6400
+ if (!fresh) return deferRefresh(now, "Cloud returned an invalid sign-in refresh response.");
6374
6401
  const current = readSession();
6375
6402
  if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
6376
6403
  if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
@@ -6381,6 +6408,7 @@ async function refresh() {
6381
6408
  }
6382
6409
  }
6383
6410
  function sessionFrom(body, previous) {
6411
+ if (!body || typeof body !== "object") return null;
6384
6412
  const token2 = body;
6385
6413
  const subject = token2.user?.id ?? previous?.subject;
6386
6414
  if (!token2.access_token || !token2.refresh_token || !subject) return null;
@@ -6422,8 +6450,7 @@ async function takeLock() {
6422
6450
  fs19.rmSync(lockDir(), { recursive: true, force: true });
6423
6451
  continue;
6424
6452
  }
6425
- if (Date.now() > until) return () => {
6426
- };
6453
+ if (Date.now() > until) return null;
6427
6454
  await sleep2(LOCK_RETRY_MS);
6428
6455
  }
6429
6456
  }
@@ -6436,7 +6463,7 @@ function stale() {
6436
6463
  } catch {
6437
6464
  held4 = void 0;
6438
6465
  }
6439
- if (held4 !== void 0 && !alive(held4)) return true;
6466
+ if (held4 !== void 0) return !alive(held4);
6440
6467
  try {
6441
6468
  return Date.now() - fs19.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
6442
6469
  } catch {
@@ -6451,7 +6478,7 @@ function alive(pid) {
6451
6478
  return e2.code === "EPERM";
6452
6479
  }
6453
6480
  }
6454
- var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, sessionFile, lockDir, lockOwner, expiringSoon, sleep2;
6481
+ 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;
6455
6482
  var init_session = __esm({
6456
6483
  "src/lib/cloud/session.ts"() {
6457
6484
  "use strict";
@@ -6461,9 +6488,13 @@ var init_session = __esm({
6461
6488
  LOCK_STALE_MS = 3e4;
6462
6489
  LOCK_WAIT_MS = 2e4;
6463
6490
  LOCK_RETRY_MS = 50;
6491
+ REFRESH_TIMEOUT_MS = 15e3;
6492
+ REFRESH_BACKOFF_MS = 6e4;
6464
6493
  sessionFile = () => path22.join(machineHome(), "session.json");
6465
6494
  lockDir = () => path22.join(machineHome(), "session.lock");
6466
6495
  lockOwner = () => path22.join(lockDir(), "owner");
6496
+ retryFile = () => path22.join(machineHome(), "session-refresh.json");
6497
+ refreshKey = (session) => createHash4("sha256").update(JSON.stringify([cloudEndpoints().api, session.subject, session.refreshToken])).digest("hex");
6467
6498
  expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
6468
6499
  sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
6469
6500
  }
@@ -6754,7 +6785,7 @@ function parseStore() {
6754
6785
  resumedFrom: typeof entry.resumedFrom === "string" ? entry.resumedFrom : void 0,
6755
6786
  continues: typeof entry.continues?.resumeId === "string" && entry.continues.resumeId ? { resumeId: entry.continues.resumeId, ...entry.continues.fork === true ? { fork: true } : {} } : void 0,
6756
6787
  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,
6757
- retry: readRetry(entry.retry),
6788
+ retry: readRetry2(entry.retry),
6758
6789
  priorStatus: typeof entry.priorStatus === "string" ? entry.priorStatus : void 0,
6759
6790
  // The pictures the create sheet handed this run (#517), as paths in its own folder.
6760
6791
  pictures: readPictures(entry.pictures),
@@ -6796,7 +6827,7 @@ function readReasons(raw) {
6796
6827
  });
6797
6828
  return reasons.length ? reasons : void 0;
6798
6829
  }
6799
- function readRetry(raw) {
6830
+ function readRetry2(raw) {
6800
6831
  if (!raw || typeof raw !== "object") return void 0;
6801
6832
  const r2 = raw;
6802
6833
  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";
@@ -17574,7 +17605,7 @@ var init_read = __esm({
17574
17605
  // src/lib/agent/preview-progress.ts
17575
17606
  import fs62 from "node:fs";
17576
17607
  import path65 from "node:path";
17577
- import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
17608
+ import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
17578
17609
  function readPreviewProgress(id) {
17579
17610
  try {
17580
17611
  return JSON.parse(fs62.readFileSync(file(id), "utf8"));
@@ -17606,7 +17637,7 @@ function freezePreviewProgress(id, name) {
17606
17637
  const files = Object.fromEntries(agent.files.map((file2) => [file2, agent.file(file2)]).filter((entry) => entry[1] !== null));
17607
17638
  if (!agent.stages) files["preview.md"] = agent.body;
17608
17639
  for (const stage of definitions) files[stage.instructions] ??= agent.file(stage.instructions);
17609
- const definitionRevision = createHash4("sha256").update(JSON.stringify({ stages: definitions, body: agent.body, files })).digest("hex");
17640
+ const definitionRevision = createHash5("sha256").update(JSON.stringify({ stages: definitions, body: agent.body, files })).digest("hex");
17610
17641
  const progress = { agent: name, definitionRevision, generation: 1, currentStageId: null, definitions, body: agent.body, files, stages: [], displayedArtifact: null, execution: null };
17611
17642
  if (!agent.stages) selectPreviewStages(progress, ["preview"]);
17612
17643
  return updatePreviewProgress(id, (all2) => all2[name] ??= progress);
@@ -17760,7 +17791,7 @@ var init_preview_progress = __esm({
17760
17791
  init_execution();
17761
17792
  init_preview_stages();
17762
17793
  file = (id) => path65.join(BOARD_STATE, "previews", `${id}.json`);
17763
- contextFile = (id, name, owner) => path65.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash4("sha256").update(owner).digest("hex")}.json`);
17794
+ contextFile = (id, name, owner) => path65.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash5("sha256").update(owner).digest("hex")}.json`);
17764
17795
  PreviewContextMissing = class extends Error {
17765
17796
  };
17766
17797
  baselineFile = (id, name, run4) => path65.join(BOARD_STATE, "previews", "runs", String(id), name, `${run4}.json`);
@@ -23010,7 +23041,7 @@ var init_agent = __esm({
23010
23041
  });
23011
23042
 
23012
23043
  // src/commands/cloud-template.ts
23013
- import { createHash as createHash5 } from "node:crypto";
23044
+ import { createHash as createHash6 } from "node:crypto";
23014
23045
  import fs73 from "node:fs";
23015
23046
  import path75 from "node:path";
23016
23047
  function usage2(problem, line) {
@@ -23108,7 +23139,7 @@ async function templateGet(name, opts, program2) {
23108
23139
  const out = path75.resolve(to, f2.path);
23109
23140
  if (!out.startsWith(path75.resolve(to) + path75.sep)) refuse3(T.corrupt, WITHOUT);
23110
23141
  const bytes2 = Buffer.from(await (await ask(`/${at2}/files/${route(f2.path)}`, {}, WITHOUT)).arrayBuffer());
23111
- if (bytes2.byteLength !== f2.size || createHash5("sha256").update(bytes2).digest("hex") !== f2.sha256) {
23142
+ if (bytes2.byteLength !== f2.size || createHash6("sha256").update(bytes2).digest("hex") !== f2.sha256) {
23112
23143
  refuse3(T.corrupt, WITHOUT);
23113
23144
  }
23114
23145
  fetched.push({ out, bytes: bytes2 });
@@ -24746,7 +24777,7 @@ var init_stage_end = __esm({
24746
24777
  });
24747
24778
 
24748
24779
  // src/lib/agent/refine.ts
24749
- import { createHash as createHash6 } from "node:crypto";
24780
+ import { createHash as createHash7 } from "node:crypto";
24750
24781
  function markBoard() {
24751
24782
  try {
24752
24783
  return new Map(allCards().map((card) => [card.id, wroteOf(card)]));
@@ -24883,7 +24914,7 @@ var init_refine2 = __esm({
24883
24914
  };
24884
24915
  MARKER = /^<!--\s*agent\s*-->$/;
24885
24916
  asMoved = (body) => body.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim() && !MARKER.test(line.trim())).sort();
24886
- wroteOf = (card) => createHash6("sha1").update(
24917
+ wroteOf = (card) => createHash7("sha1").update(
24887
24918
  JSON.stringify([
24888
24919
  card.status,
24889
24920
  card.relPath,
@@ -26322,7 +26353,7 @@ var init_check2 = __esm({
26322
26353
  });
26323
26354
 
26324
26355
  // src/lib/signals/identity.ts
26325
- import { createHash as createHash7 } from "node:crypto";
26356
+ import { createHash as createHash8 } from "node:crypto";
26326
26357
  function host(url) {
26327
26358
  try {
26328
26359
  return new URL(url).hostname.replace(/^www\./, "");
@@ -26344,14 +26375,14 @@ var init_identity2 = __esm({
26344
26375
  "src/lib/signals/identity.ts"() {
26345
26376
  "use strict";
26346
26377
  DERIVED = "derived-";
26347
- derivedSourceId = (seed) => `${DERIVED}${createHash7("sha256").update(seed).digest("hex").slice(0, 16)}`;
26378
+ derivedSourceId = (seed) => `${DERIVED}${createHash8("sha256").update(seed).digest("hex").slice(0, 16)}`;
26348
26379
  }
26349
26380
  });
26350
26381
 
26351
26382
  // src/lib/signals/add.ts
26352
26383
  import fs82 from "node:fs";
26353
26384
  import path83 from "node:path";
26354
- import { createHash as createHash8 } from "node:crypto";
26385
+ import { createHash as createHash9 } from "node:crypto";
26355
26386
  function linkTitle(url) {
26356
26387
  let at2;
26357
26388
  try {
@@ -26376,7 +26407,7 @@ function fileName2(name, data) {
26376
26407
  const base = path83.basename(name);
26377
26408
  const ext = path83.extname(base).toLowerCase().slice(0, 12);
26378
26409
  const word = path83.basename(base, path83.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
26379
- const hash2 = createHash8("sha256").update(data).digest("hex").slice(0, 8);
26410
+ const hash2 = createHash9("sha256").update(data).digest("hex").slice(0, 8);
26380
26411
  return `${word}-${hash2}${ext}`;
26381
26412
  }
26382
26413
  function addToInbox(drop) {
@@ -111047,7 +111078,7 @@ var init_draw_mockup = __esm({
111047
111078
  // src/commands/studio-preview.ts
111048
111079
  import fs85 from "node:fs";
111049
111080
  import path85 from "node:path";
111050
- import { createHash as createHash9, randomUUID as randomUUID8 } from "node:crypto";
111081
+ import { createHash as createHash10, randomUUID as randomUUID8 } from "node:crypto";
111051
111082
  import { spawnSync as spawnSync6 } from "node:child_process";
111052
111083
  function readFolder2(folder) {
111053
111084
  const root2 = fs85.realpathSync(folder);
@@ -111068,7 +111099,7 @@ function readFolder2(folder) {
111068
111099
  scan(root2);
111069
111100
  const files = readStudioFolder(root2), checked = checkStudioFiles(files, readVersion2(files)?.id.startsWith("wf_builtin_") === true);
111070
111101
  if (!checked.ok) die(`${folder}/${checked.file}: ${checked.reason}`, "studio-problems");
111071
- const fingerprint = createHash9("sha256").update(hashInput({ ...checked.files, ...files[VERSION_FILE] ? { [VERSION_FILE]: files[VERSION_FILE] } : {} })).digest("hex");
111102
+ const fingerprint = createHash10("sha256").update(hashInput({ ...checked.files, ...files[VERSION_FILE] ? { [VERSION_FILE]: files[VERSION_FILE] } : {} })).digest("hex");
111072
111103
  return { files, def: checked.def, fingerprint };
111073
111104
  }
111074
111105
  function agentsOf2(held4) {
@@ -2228,7 +2228,7 @@ function createTail(log) {
2228
2228
  // package.json
2229
2229
  var package_default = {
2230
2230
  name: "wildcrane",
2231
- version: "0.11.60",
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: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildcrane",
3
- "version": "0.11.60",
3
+ "version": "0.11.61",
4
4
  "akbContract": 17,
5
5
  "description": "WildCrane's `akb` command — scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
6
6
  "keywords": [