wildcrane-runner 0.6.97 → 0.6.98

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/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.97 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.98 — 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;
@@ -61002,506 +61002,9 @@ var reviewPlanSchema = external_exports.array(reviewNodeSchema).max(50).superRef
61002
61002
  }
61003
61003
  }).nullable();
61004
61004
 
61005
- // ../runner/src/settings-control.ts
61006
- import fs6 from "node:fs";
61007
- import path8 from "node:path";
61008
-
61009
- // ../runner/src/codex-native.ts
61010
- import fs5 from "node:fs";
61011
- import path7 from "node:path";
61012
- var import_undici2 = __toESM(require_undici(), 1);
61013
-
61014
- // ../cli/src/lib/shared/conversation.ts
61015
- var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
61016
- function bounded(work, ms, reason) {
61017
- return new Promise((resolve2, reject) => {
61018
- const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
61019
- work.then((value) => {
61020
- clearTimeout(timer);
61021
- resolve2(value);
61022
- }, (error62) => {
61023
- clearTimeout(timer);
61024
- reject(error62);
61025
- });
61026
- });
61027
- }
61028
-
61029
- // ../cli/src/lib/agent/connection-process.ts
61030
- import { spawnSync } from "node:child_process";
61031
-
61032
- // ../cli/src/lib/paths.ts
61033
- import path5 from "node:path";
61034
-
61035
- // ../cli/src/lib/io.ts
61036
- var BoardError = class extends Error {
61037
- // `kind` is the machine-readable name of the refusal (card-not-found, no-board,
61038
- // unknown-module, …). It is what a caller reads; the exit code stays 1 for every
61039
- // refusal, so nobody has to keep a table of numbers.
61040
- kind;
61041
- // Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
61042
- exitCode;
61043
- // `bare` says the message is already the whole thing a person should see — a usage
61044
- // block, say — so the dispatcher prints it without putting the command in front of it.
61045
- bare;
61046
- details;
61047
- constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
61048
- super(message);
61049
- this.name = "BoardError";
61050
- this.kind = kind;
61051
- this.bare = bare;
61052
- this.exitCode = exitCode;
61053
- this.details = details;
61054
- }
61055
- };
61056
-
61057
- // ../cli/src/lib/machine/project.ts
61058
- import fs3 from "node:fs";
61059
- import path4 from "node:path";
61060
- var SESSIONS_FILE = "sessions.json";
61061
- var SESSIONS_FOLDER = "sessions";
61062
- var ASSETS_FOLDER = "assets";
61063
- var SESSIONS_LOCK = "sessions.lock";
61064
- var INDEX_LOCK = "index.lock";
61065
- var UI_CONFIG_FILE = "ui.config.json";
61066
- function realPathOf(dir) {
61067
- const here2 = path4.resolve(dir);
61068
- const rest = [];
61069
- let at = here2;
61070
- for (; ; ) {
61071
- try {
61072
- return path4.join(fs3.realpathSync(at), ...rest);
61073
- } catch {
61074
- const up = path4.dirname(at);
61075
- if (up === at) return here2;
61076
- rest.unshift(path4.basename(at));
61077
- at = up;
61078
- }
61079
- }
61080
- }
61081
- function stateRootOf(board) {
61082
- let dir = realPathOf(board);
61083
- for (; ; ) {
61084
- if (fs3.existsSync(path4.join(dir, ".git"))) return dir;
61085
- const up = path4.dirname(dir);
61086
- if (up === dir) break;
61087
- dir = up;
61088
- }
61089
- return rootAbove(realPathOf(board));
61090
- }
61091
- function rootAbove(board) {
61092
- const parent = path4.dirname(board);
61093
- return ["docs", ".akb"].includes(path4.basename(parent)) ? path4.dirname(parent) : parent;
61094
- }
61095
- function projectStateDir(board, root2 = stateRootOf(board)) {
61096
- const relative = path4.relative(realPathOf(root2), realPathOf(board));
61097
- if (relative === ".." || relative.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative)) {
61098
- throw new Error("The board must be inside its project root.");
61099
- }
61100
- return path4.join(realPathOf(root2), ".akb", "boards", relative || "_root");
61101
- }
61102
-
61103
- // ../cli/src/lib/paths.ts
61104
- var REPO_ROOT = "";
61105
- var KANBAN = "";
61106
- var TODO = "";
61107
- var ARCHIVE = "";
61108
- var ARCHIVE_MD = "";
61109
- var README = "";
61110
- var MODULES_MD = "";
61111
- var CONFIG = "";
61112
- var KANBAN_GITIGNORE = "";
61113
- var RELEASES = "";
61114
- var RELEASE_SUMMARIES = "";
61115
- var AGENTS = "";
61116
- var STUDIOS = "";
61117
- var ASSETS = "";
61118
- var BOARD_STATE = "";
61119
- var MEMORY = "";
61120
- var AGENT_MEMORY = "";
61121
- var PROJECT_MD = "";
61122
- var LOCK = "";
61123
- var UI_CONFIG = "";
61124
- var ENV_FILE = "";
61125
- var SESSIONS = "";
61126
- var SESSIONS_DIR = "";
61127
- var SESSIONS_LOCK2 = "";
61128
- var INDEX_LOCK2 = "";
61129
- var DELIVERIES = "";
61130
- var PLANS = "";
61131
- var PLANS_ARCHIVE = "";
61132
- var RULES = "";
61133
- var TRIAGE = "";
61134
- var SIGNALS_ARCHIVED = "";
61135
- var SIGNALS_DISMISSED = "";
61136
- var SIGNALS_FILES = "";
61137
- var SIGNALS_OLD_INBOX = "";
61138
- var SIGNALS_OLD_HANDLED = "";
61139
- var AKB_DIR = "";
61140
- var ROOT_GITIGNORE = "";
61141
- function boardLockName(kanban, root2) {
61142
- const from = path5.relative(root2, kanban);
61143
- const name = from && !from.startsWith("..") ? from : path5.basename(kanban);
61144
- return `${name.split(path5.sep).join("-")}.lock`;
61145
- }
61146
- var BOARD_FLAG = "";
61147
- function setBoard(kanban, root2, flag) {
61148
- REPO_ROOT = path5.resolve(root2);
61149
- KANBAN = path5.resolve(kanban);
61150
- BOARD_FLAG = flag;
61151
- TODO = path5.join(KANBAN, "todo");
61152
- ARCHIVE = path5.join(KANBAN, ".archive");
61153
- ARCHIVE_MD = path5.join(KANBAN, "archive.md");
61154
- README = path5.join(TODO, "README.md");
61155
- MODULES_MD = path5.join(KANBAN, "modules.md");
61156
- CONFIG = path5.join(KANBAN, "config.md");
61157
- KANBAN_GITIGNORE = path5.join(KANBAN, ".gitignore");
61158
- RELEASES = path5.join(KANBAN, "releases.md");
61159
- RELEASE_SUMMARIES = path5.join(KANBAN, ".release-summaries");
61160
- AGENTS = path5.join(KANBAN, "agents");
61161
- STUDIOS = path5.join(KANBAN, "studios");
61162
- MEMORY = path5.join(KANBAN, "memory");
61163
- AGENT_MEMORY = path5.join(MEMORY, "agents");
61164
- PROJECT_MD = path5.join(MEMORY, "project.md");
61165
- ENV_FILE = path5.join(KANBAN, ".env");
61166
- const machine = projectStateDir(KANBAN, REPO_ROOT);
61167
- BOARD_STATE = machine;
61168
- UI_CONFIG = path5.join(machine, UI_CONFIG_FILE);
61169
- ASSETS = path5.join(machine, ASSETS_FOLDER);
61170
- SESSIONS = path5.join(machine, SESSIONS_FILE);
61171
- SESSIONS_DIR = path5.join(machine, SESSIONS_FOLDER);
61172
- SESSIONS_LOCK2 = path5.join(machine, SESSIONS_LOCK);
61173
- INDEX_LOCK2 = path5.join(machine, INDEX_LOCK);
61174
- DELIVERIES = path5.join(KANBAN, "deliveries");
61175
- RULES = path5.join(KANBAN, "rules");
61176
- PLANS = path5.join(machine, "plans");
61177
- PLANS_ARCHIVE = path5.join(PLANS, "archive");
61178
- TRIAGE = path5.join(KANBAN, "triage");
61179
- SIGNALS_ARCHIVED = path5.join(TRIAGE, "archived");
61180
- SIGNALS_DISMISSED = path5.join(TRIAGE, "dismissed");
61181
- SIGNALS_FILES = path5.join(TRIAGE, "files");
61182
- SIGNALS_OLD_INBOX = path5.join(TRIAGE, "inbox");
61183
- SIGNALS_OLD_HANDLED = path5.join(TRIAGE, "handled.md");
61184
- AKB_DIR = path5.join(REPO_ROOT, ".akb");
61185
- ROOT_GITIGNORE = path5.join(REPO_ROOT, ".gitignore");
61186
- LOCK = path5.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
61187
- return REPO_ROOT;
61188
- }
61189
- function setBoardRoot(root2, named = false) {
61190
- const project = path5.resolve(root2);
61191
- return setBoard(path5.join(project, "docs", "kanban"), project, named ? ` --dir ${project}` : "");
61192
- }
61193
- setBoardRoot(process.cwd());
61194
-
61195
- // ../cli/src/lib/lock.ts
61196
- function pidAlive(pid) {
61197
- if (!pid) return false;
61198
- try {
61199
- process.kill(pid, 0);
61200
- return true;
61201
- } catch (e) {
61202
- return e.code === "EPERM";
61203
- }
61204
- }
61205
-
61206
- // ../cli/src/lib/agent/connection-process.ts
61207
- function connectionIdentity(pid) {
61208
- const result = process.platform === "win32" ? spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CreationDate.ToUniversalTime().ToString('o')`], { encoding: "utf8", timeout: 2e3, windowsHide: true }) : spawnSync("ps", ["-p", String(pid), "-o", "lstart="], { encoding: "utf8", timeout: 2e3, env: { ...process.env, LC_ALL: "C" } });
61209
- return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
61210
- }
61211
- function connectionStopped(root2) {
61212
- if (!root2) return true;
61213
- if (!pidAlive(root2.pid)) return true;
61214
- const identity = connectionIdentity(root2.pid);
61215
- return !!root2.identity && !!identity && identity !== root2.identity;
61216
- }
61217
-
61218
- // ../cli/src/lib/machine/settings.ts
61219
- import fs4 from "node:fs";
61220
- import path6 from "node:path";
61221
-
61222
- // ../cli/src/lib/machine/types.ts
61223
- var LANGUAGES = ["en", "zh"];
61224
- var DEFAULT_LANGUAGE = "en";
61225
- function isLanguage(value) {
61226
- return typeof value === "string" && LANGUAGES.includes(value);
61227
- }
61228
-
61229
- // ../cli/src/lib/machine/settings.ts
61230
- var settingsFile = () => path6.join(machineHome(), "settings.json");
61231
- function heldSettings() {
61232
- let text2;
61233
- try {
61234
- text2 = fs4.readFileSync(settingsFile(), "utf8");
61235
- } catch (err) {
61236
- if (err.code === "ENOENT") return { unreadable: false, values: {} };
61237
- return { unreadable: true, values: {} };
61238
- }
61239
- try {
61240
- const parsed = JSON.parse(text2);
61241
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { unreadable: true, values: {} };
61242
- return { unreadable: false, values: parsed };
61243
- } catch {
61244
- return { unreadable: true, values: {} };
61245
- }
61246
- }
61247
- var held = () => heldSettings().values;
61248
- function readLanguage() {
61249
- const value = held().language;
61250
- return isLanguage(value) ? value : DEFAULT_LANGUAGE;
61251
- }
61252
-
61253
- // ../cli/src/lib/agent/language.ts
61254
- var LANGUAGE_ENV = "AI4KANBAN_LANGUAGE";
61255
- var languageCode = (value) => value === "zh" || value === "en" ? value : null;
61256
- function runLanguage() {
61257
- if (process.env[LANGUAGE_ENV] !== void 0) return languageCode(process.env[LANGUAGE_ENV]);
61258
- return readLanguage();
61259
- }
61260
- var translating = () => runLanguage() === "zh";
61261
-
61262
- // ../cli/src/lib/agent/retry.ts
61263
- function readFailure(raw) {
61264
- if (!raw || typeof raw !== "object") return;
61265
- const { code, level, reason, source, retryAfterMs: retryAfterMs2 } = raw;
61266
- if (typeof code !== "string" || !code || typeof reason !== "string" || level !== 1 && level !== 2 && level !== 3) return;
61267
- return { code, level, reason, ...["validation", "provider", "harness", "invariant"].some((value) => value === source) ? { source } : {}, ...typeof retryAfterMs2 === "number" && retryAfterMs2 >= 0 ? { retryAfterMs: retryAfterMs2 } : {} };
61268
- }
61269
-
61270
- // ../cli/src/lib/agent/wire/json.ts
61271
- function obj(value) {
61272
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
61273
- }
61274
- function str(value) {
61275
- return typeof value === "string" ? value : "";
61276
- }
61277
- function num(value) {
61278
- return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
61279
- }
61280
- function hint(raw) {
61281
- const line = raw.split("\n")[0].trim();
61282
- if (!line) return "";
61283
- return `(${line.length > 96 ? `${line.slice(0, 93)}\u2026` : line})`;
61284
- }
61285
- function argHint(input2, keys) {
61286
- const args2 = obj(input2);
61287
- for (const key of keys) {
61288
- const value = str(args2[key]);
61289
- if (value.trim()) return hint(value);
61290
- }
61291
- return "";
61292
- }
61293
-
61294
- // ../cli/src/lib/agent/wire/failures.ts
61295
- var ExecutionError = class extends Error {
61296
- constructor(failure3) {
61297
- super(failure3.reason);
61298
- this.failure = failure3;
61299
- }
61300
- failure;
61301
- };
61302
- var NETWORK = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT", "ENETUNREACH", "EAI_AGAIN", "UND_ERR_SOCKET"]);
61303
- var TEMPORARY_HTTP = /* @__PURE__ */ new Set([502, 503, 504, 529]);
61304
- function executionFailure(error62) {
61305
- if (error62 instanceof ExecutionError) return error62.failure;
61306
- const code = str(obj(error62).code);
61307
- const reason = error62 instanceof Error ? error62.message : String(error62);
61308
- return {
61309
- code: NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed",
61310
- level: NETWORK.has(code) ? 2 : 3,
61311
- source: "harness",
61312
- reason
61313
- };
61314
- }
61315
- function retryAfterMs(value, now = Date.now()) {
61316
- if (typeof value !== "string") return;
61317
- const header = value.trim();
61318
- if (/^\d+$/.test(header)) return Math.min(Number(header) * 1e3, Number.MAX_SAFE_INTEGER);
61319
- if (!/^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)) return;
61320
- const date5 = Date.parse(header);
61321
- if (Number.isFinite(date5)) return Math.max(0, date5 - now);
61322
- }
61323
- function providerFailure(error62, reason) {
61324
- const info = obj(error62);
61325
- const status2 = typeof info.status === "number" ? info.status : void 0;
61326
- const headers = obj(info.headers);
61327
- const wait = retryAfterMs(headers["retry-after"] ?? headers["Retry-After"]);
61328
- const code = info.code ?? info.type;
61329
- if (code === "session_not_found") return { code, source: "provider", level: 3, reason };
61330
- if (status2 === 401 || status2 === 403 || ["authentication_error", "permission_error", "invalid_request_error"].includes(str(code))) {
61331
- return { code: "provider_refused", source: "provider", level: 3, reason };
61332
- }
61333
- if (code === "rate_limit_error") return { code: "rate_limited", source: "provider", level: 2, reason, retryAfterMs: wait };
61334
- if (TEMPORARY_HTTP.has(status2 ?? 0) || code === "overloaded_error") return { code: "service_overloaded", source: "provider", level: 2, reason, retryAfterMs: wait };
61335
- if (NETWORK.has(str(code))) return { code: "connection_lost", source: "provider", level: 2, reason, retryAfterMs: wait };
61336
- return { code: "provider_failed", source: "provider", level: 3, reason };
61337
- }
61338
- function codexFailure(raw, fallback) {
61339
- const error62 = obj(raw);
61340
- const failure3 = readFailure(error62.wildcraneFailure);
61341
- if (failure3?.source === "harness" || failure3?.source === "invariant") return failure3;
61342
- const reason = str(error62.message) || fallback;
61343
- const info = error62.codexErrorInfo;
61344
- if (info === "serverOverloaded") return providerFailure({ ...error62, type: "overloaded_error" }, reason);
61345
- if (info === "rateLimitExceeded") return providerFailure({ ...error62, type: "rate_limit_error" }, reason);
61346
- const types = obj(info);
61347
- for (const kind of ["httpConnectionFailed", "responseStreamConnectionFailed", "responseStreamDisconnected", "responseTooManyFailedAttempts"]) {
61348
- if (!(kind in types)) continue;
61349
- const status2 = obj(types[kind]).httpStatusCode;
61350
- if (typeof status2 === "number") return providerFailure({ ...error62, status: status2 }, reason);
61351
- if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error62, code: "ECONNRESET" }, reason);
61352
- }
61353
- return providerFailure(error62, reason);
61354
- }
61355
-
61356
- // ../cli/src/lib/agent/wire/rpc.ts
61357
- var RpcError = class extends Error {
61358
- constructor(message, code, data) {
61359
- super(message);
61360
- this.code = code;
61361
- this.data = data;
61362
- this.name = "RpcError";
61363
- }
61364
- code;
61365
- data;
61366
- };
61367
- function connect(stdout, stdin, onCall, dialect = {}) {
61368
- let buf = "";
61369
- let nextId = 1;
61370
- let gone;
61371
- const waiting = /* @__PURE__ */ new Map();
61372
- const send2 = (msg) => {
61373
- if (gone) return;
61374
- try {
61375
- stdin.write(`${JSON.stringify(dialect.jsonrpc ? { jsonrpc: "2.0", ...msg } : msg)}
61376
- `);
61377
- } catch {
61378
- }
61379
- };
61380
- const closed = (why) => {
61381
- if (gone) return;
61382
- gone = why;
61383
- for (const { fail } of waiting.values()) fail(why);
61384
- waiting.clear();
61385
- };
61386
- stdout.on("data", (chunk) => {
61387
- buf += chunk.toString();
61388
- const lines = buf.split("\n");
61389
- buf = lines.pop() ?? "";
61390
- for (const line of lines) {
61391
- if (!line.trim()) continue;
61392
- let msg;
61393
- try {
61394
- msg = JSON.parse(line);
61395
- } catch {
61396
- continue;
61397
- }
61398
- if (msg.method) {
61399
- onCall(msg);
61400
- continue;
61401
- }
61402
- if (msg.id === void 0) continue;
61403
- const pending = waiting.get(String(msg.id));
61404
- if (!pending) continue;
61405
- waiting.delete(String(msg.id));
61406
- if (msg.error) {
61407
- const said = [str(msg.error.message), str(obj(msg.error.data).message)].filter(Boolean).join(": ");
61408
- pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code, msg.error.data));
61409
- } else pending.ok(obj(msg.result));
61410
- }
61411
- });
61412
- stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", level: 2, reason: "The agent closed the connection." })));
61413
- stdout.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
61414
- stdin.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
61415
- return {
61416
- /** Ask the agent something. Rejects with the agent's own words when it says no. */
61417
- call(method, params) {
61418
- if (gone) return Promise.reject(gone);
61419
- const id2 = dialect.stringIds ? String(nextId++) : nextId++;
61420
- return new Promise((ok, fail) => {
61421
- waiting.set(String(id2), { ok, fail });
61422
- send2({ id: id2, method, params });
61423
- });
61424
- },
61425
- notify(method, params = {}) {
61426
- send2({ method, params });
61427
- },
61428
- /** Answer something the agent asked us. */
61429
- reply(id2, result) {
61430
- send2({ id: id2, result });
61431
- },
61432
- /** Say we can't. Sent for anything we never offered to do, so the agent gets an answer
61433
- * rather than waiting on one forever. */
61434
- refuse(id2, message) {
61435
- send2({ id: id2, error: { code: -32601, message } });
61436
- }
61437
- };
61438
- }
61439
-
61440
- // ../runner/src/codex-native.ts
61441
- var nativeDirectory = () => path7.join(runnerCwd(), "codex-native");
61442
- var liveBackend = (backend) => !connectionStopped(backend);
61443
- function readPrivate(file3) {
61444
- try {
61445
- return JSON.parse(fs5.readFileSync(file3, "utf8"));
61446
- } catch (error62) {
61447
- if (error62.code === "ENOENT") return;
61448
- throw error62;
61449
- }
61450
- }
61451
- function stopNativeBackends() {
61452
- let files = [];
61453
- try {
61454
- files = fs5.readdirSync(nativeDirectory()).filter((name) => /^[a-f0-9]{64}\.json$/.test(name));
61455
- } catch {
61456
- return [];
61457
- }
61458
- const targets = [];
61459
- for (const file3 of files) {
61460
- const backend = readPrivate(path7.join(nativeDirectory(), file3));
61461
- if (backend?.identity && liveBackend(backend) && connectionIdentity(backend.pid) === backend.identity) {
61462
- targets.push(backend);
61463
- try {
61464
- process.kill(backend.pid, "SIGTERM");
61465
- } catch {
61466
- }
61467
- }
61468
- }
61469
- return targets;
61470
- }
61471
-
61472
- // ../runner/src/settings-control.ts
61473
- var directory = () => path8.join(runnerHome(), "executors");
61474
- var epochFile = () => path8.join(runnerHome(), "account-generation");
61475
- function accountGeneration() {
61476
- try {
61477
- return fs6.readFileSync(epochFile(), "utf8");
61478
- } catch {
61479
- return "";
61480
- }
61481
- }
61482
- async function stopExecutors() {
61483
- fs6.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
61484
- fs6.writeFileSync(epochFile(), `${Date.now()}-${process.pid}`, { mode: 384 });
61485
- const backends = stopNativeBackends();
61486
- for (let n = 0; n < 160; n++) {
61487
- const active = fs6.existsSync(directory()) ? fs6.readdirSync(directory()).filter((name) => {
61488
- try {
61489
- process.kill(Number(name.split(".")[0]), 0);
61490
- return true;
61491
- } catch {
61492
- fs6.rmSync(path8.join(directory(), name), { force: true });
61493
- return false;
61494
- }
61495
- }) : [];
61496
- if (!active.length && backends.every((backend) => !liveBackend(backend))) return true;
61497
- await new Promise((resolve2) => setTimeout(resolve2, 100));
61498
- }
61499
- return false;
61500
- }
61501
-
61502
61005
  // ../runner/src/protocol.ts
61503
- var VERSION = true ? "0.6.97" : "0.0.0";
61504
- var AKB_VERSION = true ? "0.11.78" : "0.0.0";
61006
+ var VERSION = true ? "0.6.98" : "0.0.0";
61007
+ var AKB_VERSION = true ? "0.11.79" : "0.0.0";
61505
61008
 
61506
61009
  // ../runner/src/api.ts
61507
61010
  var RUNTIMES = ["claude-code", "codex", "cursor", "opencode", "kimi", "dsh", "zcode", "grok", "antigravity"];
@@ -61565,8 +61068,8 @@ var removeFolder = (machineId2, project) => request("POST", `/v1/runner/folders/
61565
61068
  var import_yaml7 = __toESM(require_dist(), 1);
61566
61069
 
61567
61070
  // ../cli/src/lib/agent/cloud-studios.ts
61568
- import fs11 from "node:fs";
61569
- import path13 from "node:path";
61071
+ import fs8 from "node:fs";
61072
+ import path10 from "node:path";
61570
61073
 
61571
61074
  // ../cli/src/lib/shared/file-limits.ts
61572
61075
  var BOARD_FILE_LIMIT = 10 * 1024 * 1024;
@@ -61592,8 +61095,8 @@ var studioName = (id2) => id2.startsWith("wf_builtin_") ? id2.slice("wf_builtin_
61592
61095
 
61593
61096
  // ../official/pack.ts
61594
61097
  import crypto2 from "node:crypto";
61595
- import fs8 from "node:fs";
61596
- import path10 from "node:path";
61098
+ import fs4 from "node:fs";
61099
+ import path5 from "node:path";
61597
61100
  import { fileURLToPath } from "node:url";
61598
61101
 
61599
61102
  // ../cli/src/lib/agent/studio-def.ts
@@ -61749,7 +61252,28 @@ var STUDIO_SCHEMA = {
61749
61252
  }
61750
61253
  };
61751
61254
  var validate2 = new import_ajv.Ajv({ allErrors: true, meta: false, validateSchema: false }).compile(STUDIO_SCHEMA);
61752
- function parseStudioFile(id2, source, from, requirePreviewCopy = false) {
61255
+ function landSections(body, previews) {
61256
+ const blank = (text2) => text2.replace(/[^\r\n]/g, " ");
61257
+ let visible = "", at = 0;
61258
+ for (const { start, end } of previews) {
61259
+ visible += body.slice(at, start) + blank(body.slice(start, end));
61260
+ at = end;
61261
+ }
61262
+ visible += body.slice(at);
61263
+ const comments = /<!--[^]*?(?:-->|$)/g;
61264
+ const markdown = withoutCode(visible).replace(comments, blank);
61265
+ const headings = [...markdown.matchAll(/^ {0,3}#{1,2}(?=[ \t\r\n]|$)[^\r\n]*/gm)];
61266
+ return headings.flatMap((heading, index) => {
61267
+ const start = heading.index;
61268
+ const end = start + heading[0].length;
61269
+ if (!/^ {0,3}##[ \t]+Land(?:[ \t]+#+)?[ \t]*$/.test(visible.slice(start, end))) return [];
61270
+ return [{
61271
+ offset: start + heading[0].indexOf("#"),
61272
+ empty: !visible.slice(end, headings[index + 1]?.index).replace(comments, "").trim()
61273
+ }];
61274
+ });
61275
+ }
61276
+ function parseStudioFile(id2, source, from, { requirePreviewCopy = false, requireLand = false } = {}) {
61753
61277
  const problems = [];
61754
61278
  const fail = (offset, path36, code, message, hint2) => problems.push({ file: from, ...sourcePosition(source, offset), path: path36, code, message, hint: hint2 });
61755
61279
  const result = () => ({ problem: problems.map((p) => `${p.file}:${p.line}:${p.column} ${p.path}: ${p.code} \u2014 ${p.message}. ${p.hint}`).join("\n"), problems });
@@ -61801,6 +61325,14 @@ function parseStudioFile(id2, source, from, requirePreviewCopy = false) {
61801
61325
  );
61802
61326
  }
61803
61327
  }
61328
+ if (requireLand) {
61329
+ const sections = landSections(body, parsed.blocks);
61330
+ if (!sections.length) fail(bodyOffset, "Land", "studio-land-missing", "Missing ## Land section", "Add ## Land to the Studio body and describe delivery, checks and what to record.");
61331
+ for (const [index, { offset, empty }] of sections.entries()) {
61332
+ if (index) fail(bodyOffset + offset, "Land", "studio-land-duplicate", "Repeated ## Land section", "Combine delivery instructions under one ## Land heading.");
61333
+ if (empty) fail(bodyOffset + offset, "Land", "studio-land-empty", "The ## Land section is empty", "Describe delivery, checks and what to record under ## Land.");
61334
+ }
61335
+ }
61804
61336
  if (problems.length) return result();
61805
61337
  let rules = "", at = 0;
61806
61338
  for (const block of parsed.blocks) {
@@ -61821,11 +61353,11 @@ function parseStudioFile(id2, source, from, requirePreviewCopy = false) {
61821
61353
  }
61822
61354
 
61823
61355
  // ../cli/src/lib/agent/studio-folder.ts
61824
- import fs7 from "node:fs";
61825
- import path9 from "node:path";
61356
+ import fs3 from "node:fs";
61357
+ import path4 from "node:path";
61826
61358
 
61827
61359
  // ../cli/src/lib/shared/guide-topics.ts
61828
- var GUIDE_TOPICS = ["board", "writing", "add-task", "follow-up", "discuss-goal", "troubleshoot", "card-chat", "update-studio", "implement", "settle-background", "archive", "update-questions", "refine", "revise", "resolve", "prune-memory", "review-memory", "describe-project", "review-rejections", "reflect", "preview-agent", "write-agent", "write-prompt", "module-map"];
61360
+ var GUIDE_TOPICS = ["board", "writing", "add-task", "follow-up", "discuss-goal", "troubleshoot", "card-chat", "update-studio", "implement", "settle-background", "archive", "update-questions", "refine", "revise", "resolve", "prune-memory", "review-memory", "describe-project", "review-rejections", "reflect", "write-agent", "write-prompt", "module-map"];
61829
61361
 
61830
61362
  // ../cli/src/lib/shared/studio-files.ts
61831
61363
  var STUDIO_FILE = "STUDIO.md";
@@ -61868,12 +61400,16 @@ function mcpProblem(text2) {
61868
61400
  }
61869
61401
  return null;
61870
61402
  }
61871
- function checkStudioFiles(value, official = false, allowLegacyPreviewCopy = false) {
61872
- const read3 = inspect(value, official, allowLegacyPreviewCopy);
61403
+ function formatStudioProblem({ file: file3, line, column, reason, hint: hint2 }) {
61404
+ const location = line === void 0 ? file3 : `${file3}:${line}:${column ?? 1}`;
61405
+ return `${location}: ${reason}${hint2 ? `. ${hint2}` : ""}`;
61406
+ }
61407
+ function checkStudioFiles(value, official = false, checks = {}) {
61408
+ const read3 = inspect(value, official, checks);
61873
61409
  const first = read3.problems[0];
61874
61410
  return first ? { ok: false, ...first, problems: read3.problems } : { ok: true, def: read3.def, files: read3.files };
61875
61411
  }
61876
- function inspect(value, official, allowLegacyPreviewCopy = false) {
61412
+ function inspect(value, official, { allowLegacyPreviewCopy, allowLegacyLand } = {}) {
61877
61413
  const problems = [];
61878
61414
  const fail = (file3, reason, tooLarge = false) => {
61879
61415
  problems.push({ file: file3, reason, ...tooLarge ? { tooLarge } : {} });
@@ -61918,7 +61454,7 @@ function inspect(value, official, allowLegacyPreviewCopy = false) {
61918
61454
  if (files[`skills/${name}/SKILL.md`] === void 0) fail(`skills/${name}/SKILL.md`, "is missing");
61919
61455
  }
61920
61456
  const source = files[STUDIO_FILE];
61921
- const read3 = typeof source === "string" ? parseStudioFile("studio", source, STUDIO_FILE, !official && !allowLegacyPreviewCopy) : null;
61457
+ const read3 = typeof source === "string" ? parseStudioFile("studio", source, STUDIO_FILE, { requirePreviewCopy: !official && !allowLegacyPreviewCopy, requireLand: !allowLegacyLand }) : null;
61922
61458
  if (!read3) fail(STUDIO_FILE, "is missing");
61923
61459
  else if ("problem" in read3) for (const problem of read3.problems) problems.push({ ...problem, reason: problem.message });
61924
61460
  if (!read3 || "problem" in read3) return { problems };
@@ -61952,31 +61488,31 @@ function inspect(value, official, allowLegacyPreviewCopy = false) {
61952
61488
  // ../cli/src/lib/agent/studio-folder.ts
61953
61489
  var MIME = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp" };
61954
61490
  function filesOf(dir, base = dir) {
61955
- return fs7.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
61956
- const full = path9.join(dir, e.name);
61491
+ return fs3.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
61492
+ const full = path4.join(dir, e.name);
61957
61493
  if (e.isSymbolicLink()) throw new Error(`${full}: symbolic links are not allowed`);
61958
- return e.isDirectory() ? filesOf(full, base) : [path9.relative(base, full).split(path9.sep).join("/")];
61494
+ return e.isDirectory() ? filesOf(full, base) : [path4.relative(base, full).split(path4.sep).join("/")];
61959
61495
  });
61960
61496
  }
61961
61497
  function readStudioFile(dir, file3) {
61962
- const full = path9.join(dir, file3);
61963
- return isAboutFile(file3) && !file3.endsWith(".md") ? `data:${MIME[path9.extname(file3)]};base64,${fs7.readFileSync(full).toString("base64")}` : fs7.readFileSync(full, "utf8");
61498
+ const full = path4.join(dir, file3);
61499
+ return isAboutFile(file3) && !file3.endsWith(".md") ? `data:${MIME[path4.extname(file3)]};base64,${fs3.readFileSync(full).toString("base64")}` : fs3.readFileSync(full, "utf8");
61964
61500
  }
61965
61501
  var readStudioFolder = (dir) => Object.fromEntries(filesOf(dir).sort().map((f) => [f, readStudioFile(dir, f)]));
61966
61502
 
61967
61503
  // ../official/pack.ts
61968
- var OFFICIAL = path10.dirname(fileURLToPath(import.meta.url));
61969
- var dirs = (dir) => fs8.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
61504
+ var OFFICIAL = path5.dirname(fileURLToPath(import.meta.url));
61505
+ var dirs = (dir) => fs4.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
61970
61506
  var hashOf = (files) => crypto2.createHash("sha256").update(hashInput(files)).digest("hex");
61971
61507
  function packOfficial(root2 = OFFICIAL, loose = false) {
61972
- const studiosDir = path10.join(root2, "studios");
61508
+ const studiosDir = path5.join(root2, "studios");
61973
61509
  return dirs(studiosDir).map((folder2) => {
61974
- const files = readStudioFolder(path10.join(studiosDir, folder2));
61510
+ const files = readStudioFolder(path5.join(studiosDir, folder2));
61975
61511
  const parsed = parseStudioFile(folder2, files[STUDIO_FILE] ?? "", STUDIO_FILE);
61976
61512
  if ("problem" in parsed) throw new Error(parsed.problem);
61977
61513
  const def = parsed.def;
61978
61514
  const checked = loose ? { ok: true } : checkStudioFiles(files, true);
61979
- if (!checked.ok) throw new Error(`official/studios/${folder2}: ${checked.file}: ${checked.reason}`);
61515
+ if (!checked.ok) throw new Error(`official/studios/${folder2}: ${formatStudioProblem(checked)}`);
61980
61516
  if (!def.names?.zh && !loose) throw new Error(`official/studios/${folder2}/${STUDIO_FILE}: add its Chinese name under \`names: zh\``);
61981
61517
  return {
61982
61518
  id: officialId(folder2),
@@ -61992,23 +61528,23 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
61992
61528
  }
61993
61529
 
61994
61530
  // ../cli/src/lib/cloud/tasks.ts
61995
- import fs9 from "node:fs";
61996
- import path11 from "node:path";
61531
+ import fs5 from "node:fs";
61532
+ import path6 from "node:path";
61997
61533
  var TASK_ENV = "AI4KANBAN_TASK";
61998
61534
  function workspaceTask() {
61999
61535
  const id2 = process.env[TASK_ENV];
62000
61536
  return id2 && id2.trim() ? id2.trim() : null;
62001
61537
  }
62002
61538
  function runnerProject(board) {
62003
- if (path11.basename(board) !== "kanban" || path11.basename(path11.dirname(board)) !== ".akb") return null;
62004
- const linked = linkedProject(board, path11.dirname(path11.dirname(board)));
61539
+ if (path6.basename(board) !== "kanban" || path6.basename(path6.dirname(board)) !== ".akb") return null;
61540
+ const linked = linkedProject(board, path6.dirname(path6.dirname(board)));
62005
61541
  return linked.ok ? linked.value : null;
62006
61542
  }
62007
61543
  function linkedProject(board, root2) {
62008
- const file3 = path11.join(root2, ".akb", "base.json");
62009
- if (!fs9.existsSync(file3)) return { ok: true, value: null };
61544
+ const file3 = path6.join(root2, ".akb", "base.json");
61545
+ if (!fs5.existsSync(file3)) return { ok: true, value: null };
62010
61546
  try {
62011
- const base = JSON.parse(fs9.readFileSync(file3, "utf8"));
61547
+ const base = JSON.parse(fs5.readFileSync(file3, "utf8"));
62012
61548
  if (!base || typeof base !== "object" || base.project !== void 0 && (typeof base.project !== "string" || !base.project.trim()) || base.files !== void 0 && (!base.files || typeof base.files !== "object" || Array.isArray(base.files))) throw new Error();
62013
61549
  const projects = new Set(Object.keys(base.files ?? {}).flatMap((p) => /^projects\/([^/]+)\//.exec(p)?.[1] ?? []));
62014
61550
  if (typeof base.project === "string") projects.add(base.project);
@@ -62020,14 +61556,14 @@ function linkedProject(board, root2) {
62020
61556
  }
62021
61557
 
62022
61558
  // ../cli/src/lib/file-memo.ts
62023
- import fs10 from "node:fs";
62024
- import path12 from "node:path";
61559
+ import fs6 from "node:fs";
61560
+ import path7 from "node:path";
62025
61561
  function stamp(paths) {
62026
61562
  const parts = [];
62027
61563
  const visit2 = (p) => {
62028
61564
  let st;
62029
61565
  try {
62030
- st = fs10.statSync(p, { bigint: true });
61566
+ st = fs6.statSync(p, { bigint: true });
62031
61567
  } catch {
62032
61568
  parts.push(`${p}:-`);
62033
61569
  return;
@@ -62039,11 +61575,11 @@ function stamp(paths) {
62039
61575
  parts.push(`${p}/`);
62040
61576
  let names;
62041
61577
  try {
62042
- names = fs10.readdirSync(p).sort();
61578
+ names = fs6.readdirSync(p).sort();
62043
61579
  } catch {
62044
61580
  return;
62045
61581
  }
62046
- for (const name of names) if (name !== "node_modules" && name !== ".git") visit2(path12.join(p, name));
61582
+ for (const name of names) if (name !== "node_modules" && name !== ".git") visit2(path7.join(p, name));
62047
61583
  };
62048
61584
  for (const p of paths) visit2(p);
62049
61585
  return parts.join("\n");
@@ -62084,16 +61620,179 @@ function memoByFiles(paths, read3) {
62084
61620
  };
62085
61621
  }
62086
61622
 
61623
+ // ../cli/src/lib/paths.ts
61624
+ import path9 from "node:path";
61625
+
61626
+ // ../cli/src/lib/io.ts
61627
+ var BoardError = class extends Error {
61628
+ // `kind` is the machine-readable name of the refusal (card-not-found, no-board,
61629
+ // unknown-module, …). It is what a caller reads; the exit code stays 1 for every
61630
+ // refusal, so nobody has to keep a table of numbers.
61631
+ kind;
61632
+ // Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
61633
+ exitCode;
61634
+ // `bare` says the message is already the whole thing a person should see — a usage
61635
+ // block, say — so the dispatcher prints it without putting the command in front of it.
61636
+ bare;
61637
+ details;
61638
+ constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
61639
+ super(message);
61640
+ this.name = "BoardError";
61641
+ this.kind = kind;
61642
+ this.bare = bare;
61643
+ this.exitCode = exitCode;
61644
+ this.details = details;
61645
+ }
61646
+ };
61647
+
61648
+ // ../cli/src/lib/machine/project.ts
61649
+ import fs7 from "node:fs";
61650
+ import path8 from "node:path";
61651
+ var SESSIONS_FILE = "sessions.json";
61652
+ var SESSIONS_FOLDER = "sessions";
61653
+ var ASSETS_FOLDER = "assets";
61654
+ var SESSIONS_LOCK = "sessions.lock";
61655
+ var INDEX_LOCK = "index.lock";
61656
+ var UI_CONFIG_FILE = "ui.config.json";
61657
+ function realPathOf(dir) {
61658
+ const here2 = path8.resolve(dir);
61659
+ const rest = [];
61660
+ let at = here2;
61661
+ for (; ; ) {
61662
+ try {
61663
+ return path8.join(fs7.realpathSync(at), ...rest);
61664
+ } catch {
61665
+ const up = path8.dirname(at);
61666
+ if (up === at) return here2;
61667
+ rest.unshift(path8.basename(at));
61668
+ at = up;
61669
+ }
61670
+ }
61671
+ }
61672
+ function stateRootOf(board) {
61673
+ let dir = realPathOf(board);
61674
+ for (; ; ) {
61675
+ if (fs7.existsSync(path8.join(dir, ".git"))) return dir;
61676
+ const up = path8.dirname(dir);
61677
+ if (up === dir) break;
61678
+ dir = up;
61679
+ }
61680
+ return rootAbove(realPathOf(board));
61681
+ }
61682
+ function rootAbove(board) {
61683
+ const parent = path8.dirname(board);
61684
+ return ["docs", ".akb"].includes(path8.basename(parent)) ? path8.dirname(parent) : parent;
61685
+ }
61686
+ function projectStateDir(board, root2 = stateRootOf(board)) {
61687
+ const relative = path8.relative(realPathOf(root2), realPathOf(board));
61688
+ if (relative === ".." || relative.startsWith(`..${path8.sep}`) || path8.isAbsolute(relative)) {
61689
+ throw new Error("The board must be inside its project root.");
61690
+ }
61691
+ return path8.join(realPathOf(root2), ".akb", "boards", relative || "_root");
61692
+ }
61693
+
61694
+ // ../cli/src/lib/paths.ts
61695
+ var REPO_ROOT = "";
61696
+ var KANBAN = "";
61697
+ var TODO = "";
61698
+ var ARCHIVE = "";
61699
+ var ARCHIVE_MD = "";
61700
+ var README = "";
61701
+ var MODULES_MD = "";
61702
+ var CONFIG = "";
61703
+ var KANBAN_GITIGNORE = "";
61704
+ var RELEASES = "";
61705
+ var RELEASE_SUMMARIES = "";
61706
+ var AGENTS = "";
61707
+ var STUDIOS = "";
61708
+ var ASSETS = "";
61709
+ var BOARD_STATE = "";
61710
+ var MEMORY = "";
61711
+ var AGENT_MEMORY = "";
61712
+ var PROJECT_MD = "";
61713
+ var LOCK = "";
61714
+ var UI_CONFIG = "";
61715
+ var ENV_FILE = "";
61716
+ var SESSIONS = "";
61717
+ var SESSIONS_DIR = "";
61718
+ var SESSIONS_LOCK2 = "";
61719
+ var INDEX_LOCK2 = "";
61720
+ var DELIVERIES = "";
61721
+ var PLANS = "";
61722
+ var PLANS_ARCHIVE = "";
61723
+ var RULES = "";
61724
+ var TRIAGE = "";
61725
+ var SIGNALS_ARCHIVED = "";
61726
+ var SIGNALS_DISMISSED = "";
61727
+ var SIGNALS_FILES = "";
61728
+ var SIGNALS_OLD_INBOX = "";
61729
+ var SIGNALS_OLD_HANDLED = "";
61730
+ var AKB_DIR = "";
61731
+ var ROOT_GITIGNORE = "";
61732
+ function boardLockName(kanban, root2) {
61733
+ const from = path9.relative(root2, kanban);
61734
+ const name = from && !from.startsWith("..") ? from : path9.basename(kanban);
61735
+ return `${name.split(path9.sep).join("-")}.lock`;
61736
+ }
61737
+ var BOARD_FLAG = "";
61738
+ function setBoard(kanban, root2, flag) {
61739
+ REPO_ROOT = path9.resolve(root2);
61740
+ KANBAN = path9.resolve(kanban);
61741
+ BOARD_FLAG = flag;
61742
+ TODO = path9.join(KANBAN, "todo");
61743
+ ARCHIVE = path9.join(KANBAN, ".archive");
61744
+ ARCHIVE_MD = path9.join(KANBAN, "archive.md");
61745
+ README = path9.join(TODO, "README.md");
61746
+ MODULES_MD = path9.join(KANBAN, "modules.md");
61747
+ CONFIG = path9.join(KANBAN, "config.md");
61748
+ KANBAN_GITIGNORE = path9.join(KANBAN, ".gitignore");
61749
+ RELEASES = path9.join(KANBAN, "releases.md");
61750
+ RELEASE_SUMMARIES = path9.join(KANBAN, ".release-summaries");
61751
+ AGENTS = path9.join(KANBAN, "agents");
61752
+ STUDIOS = path9.join(KANBAN, "studios");
61753
+ MEMORY = path9.join(KANBAN, "memory");
61754
+ AGENT_MEMORY = path9.join(MEMORY, "agents");
61755
+ PROJECT_MD = path9.join(MEMORY, "project.md");
61756
+ ENV_FILE = path9.join(KANBAN, ".env");
61757
+ const machine = projectStateDir(KANBAN, REPO_ROOT);
61758
+ BOARD_STATE = machine;
61759
+ UI_CONFIG = path9.join(machine, UI_CONFIG_FILE);
61760
+ ASSETS = path9.join(machine, ASSETS_FOLDER);
61761
+ SESSIONS = path9.join(machine, SESSIONS_FILE);
61762
+ SESSIONS_DIR = path9.join(machine, SESSIONS_FOLDER);
61763
+ SESSIONS_LOCK2 = path9.join(machine, SESSIONS_LOCK);
61764
+ INDEX_LOCK2 = path9.join(machine, INDEX_LOCK);
61765
+ DELIVERIES = path9.join(KANBAN, "deliveries");
61766
+ RULES = path9.join(KANBAN, "rules");
61767
+ PLANS = path9.join(machine, "plans");
61768
+ PLANS_ARCHIVE = path9.join(PLANS, "archive");
61769
+ TRIAGE = path9.join(KANBAN, "triage");
61770
+ SIGNALS_ARCHIVED = path9.join(TRIAGE, "archived");
61771
+ SIGNALS_DISMISSED = path9.join(TRIAGE, "dismissed");
61772
+ SIGNALS_FILES = path9.join(TRIAGE, "files");
61773
+ SIGNALS_OLD_INBOX = path9.join(TRIAGE, "inbox");
61774
+ SIGNALS_OLD_HANDLED = path9.join(TRIAGE, "handled.md");
61775
+ AKB_DIR = path9.join(REPO_ROOT, ".akb");
61776
+ ROOT_GITIGNORE = path9.join(REPO_ROOT, ".gitignore");
61777
+ LOCK = path9.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
61778
+ return REPO_ROOT;
61779
+ }
61780
+ function setBoardRoot(root2, named = false) {
61781
+ const project = path9.resolve(root2);
61782
+ return setBoard(path9.join(project, "docs", "kanban"), project, named ? ` --dir ${project}` : "");
61783
+ }
61784
+ setBoardRoot(process.cwd());
61785
+
62087
61786
  // ../cli/src/lib/agent/cloud-studios.ts
62088
61787
  var DEV = "AI4KANBAN_STUDIOS";
62089
- var root = () => path13.join(machineHome(), "studios");
61788
+ var root = () => path10.join(machineHome(), "studios");
62090
61789
  var safe = (name) => name.replace(/[^\w.@-]/g, "_");
62091
- var versionFile = (id2, version2) => path13.join(root(), "versions", `${safe(id2)}@${version2}.json`);
62092
- var listFile = (project) => path13.join(root(), "lists", `${safe(project)}.json`);
62093
- var pinFile = (task) => path13.join(root(), "tasks", `${safe(task)}.json`);
61790
+ var versionFile = (id2, version2) => path10.join(root(), "versions", `${safe(id2)}@${version2}.json`);
61791
+ var listFile = (project) => path10.join(root(), "lists", `${safe(project)}.json`);
61792
+ var pinFile = (task) => path10.join(root(), "tasks", `${safe(task)}.json`);
62094
61793
  function readJson(file3) {
62095
61794
  try {
62096
- return JSON.parse(fs11.readFileSync(file3, "utf8"));
61795
+ return JSON.parse(fs8.readFileSync(file3, "utf8"));
62097
61796
  } catch {
62098
61797
  return null;
62099
61798
  }
@@ -62136,18 +61835,31 @@ var sources = () => {
62136
61835
  var flows = memoByFiles(sources, readFlows);
62137
61836
 
62138
61837
  // ../cli/src/lib/shared/board-conflicts.ts
62139
- import fs12 from "node:fs";
62140
- import path14 from "node:path";
62141
- var folder = (board) => path14.join(projectStateDir(board), "conflicts");
61838
+ import fs9 from "node:fs";
61839
+ import path11 from "node:path";
61840
+
61841
+ // ../cli/src/lib/lock.ts
61842
+ function pidAlive(pid) {
61843
+ if (!pid) return false;
61844
+ try {
61845
+ process.kill(pid, 0);
61846
+ return true;
61847
+ } catch (e) {
61848
+ return e.code === "EPERM";
61849
+ }
61850
+ }
61851
+
61852
+ // ../cli/src/lib/shared/board-conflicts.ts
61853
+ var folder = (board) => path11.join(projectStateDir(board), "conflicts");
62142
61854
  var fileOf = (board, id2) => {
62143
61855
  if (!/^c_[a-f0-9]{32}$/.test(id2)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
62144
- return path14.join(folder(board), `${id2}.json`);
61856
+ return path11.join(folder(board), `${id2}.json`);
62145
61857
  };
62146
61858
  function read(board, id2) {
62147
61859
  const file3 = fileOf(board, id2);
62148
- if (!fs12.existsSync(file3)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
61860
+ if (!fs9.existsSync(file3)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
62149
61861
  try {
62150
- const r = JSON.parse(fs12.readFileSync(file3, "utf8"));
61862
+ const r = JSON.parse(fs9.readFileSync(file3, "utf8"));
62151
61863
  if (r.id !== id2 || !r.project || !["open", "unconfirmed", "resolved"].includes(r.state) || !Array.isArray(r.files) || !r.files.length) throw Error();
62152
61864
  const names = /* @__PURE__ */ new Set();
62153
61865
  for (const f of r.files) {
@@ -62169,7 +61881,7 @@ function read(board, id2) {
62169
61881
  function conflictRecords(board) {
62170
61882
  let names;
62171
61883
  try {
62172
- names = fs12.readdirSync(folder(board));
61884
+ names = fs9.readdirSync(folder(board));
62173
61885
  } catch (e) {
62174
61886
  if (e.code === "ENOENT") return [];
62175
61887
  throw e;
@@ -62180,24 +61892,24 @@ var pendingConflicts = (board) => conflictRecords(board).filter((r) => r.state !
62180
61892
 
62181
61893
  // ../runner/src/cache.ts
62182
61894
  import crypto3 from "node:crypto";
62183
- import fs14 from "node:fs";
62184
- import path16 from "node:path";
61895
+ import fs11 from "node:fs";
61896
+ import path13 from "node:path";
62185
61897
 
62186
61898
  // ../runner/src/folders.ts
62187
- import fs13 from "node:fs";
61899
+ import fs10 from "node:fs";
62188
61900
  import os4 from "node:os";
62189
- import path15 from "node:path";
62190
- var projectsFile = () => path15.join(runnerHome(), "projects.json");
61901
+ import path12 from "node:path";
61902
+ var projectsFile = () => path12.join(runnerHome(), "projects.json");
62191
61903
  function realpath(p) {
62192
61904
  try {
62193
- return fs13.realpathSync(p);
61905
+ return fs10.realpathSync(p);
62194
61906
  } catch {
62195
61907
  return null;
62196
61908
  }
62197
61909
  }
62198
61910
  function readGrants() {
62199
61911
  try {
62200
- const held2 = JSON.parse(fs13.readFileSync(projectsFile(), "utf8"));
61912
+ const held2 = JSON.parse(fs10.readFileSync(projectsFile(), "utf8"));
62201
61913
  if (!Array.isArray(held2.projects)) throw new Error("invalid_projects");
62202
61914
  return held2;
62203
61915
  } catch (error62) {
@@ -62211,23 +61923,23 @@ function listOf(held2) {
62211
61923
  return subject ? held2.accounts[subject] ?? [] : [];
62212
61924
  }
62213
61925
  function update(change) {
62214
- fs13.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
61926
+ fs10.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
62215
61927
  const lock = `${projectsFile()}.lock`;
62216
61928
  let fd;
62217
61929
  const until = Date.now() + 2e3;
62218
61930
  for (; ; ) {
62219
61931
  try {
62220
- fd = fs13.openSync(lock, "wx", 384);
62221
- fs13.writeFileSync(fd, String(process.pid));
61932
+ fd = fs10.openSync(lock, "wx", 384);
61933
+ fs10.writeFileSync(fd, String(process.pid));
62222
61934
  break;
62223
61935
  } catch {
62224
61936
  try {
62225
- const pid = Number(fs13.readFileSync(lock, "utf8"));
61937
+ const pid = Number(fs10.readFileSync(lock, "utf8"));
62226
61938
  if (pid > 0) {
62227
61939
  try {
62228
61940
  process.kill(pid, 0);
62229
61941
  } catch {
62230
- fs13.rmSync(lock, { force: true });
61942
+ fs10.rmSync(lock, { force: true });
62231
61943
  }
62232
61944
  }
62233
61945
  } catch {
@@ -62250,13 +61962,13 @@ function update(change) {
62250
61962
  held2.projects = after;
62251
61963
  } else held2.projects = after;
62252
61964
  const tmp = `${projectsFile()}.${process.pid}.tmp`;
62253
- fs13.writeFileSync(tmp, `${JSON.stringify(held2, null, 2)}
61965
+ fs10.writeFileSync(tmp, `${JSON.stringify(held2, null, 2)}
62254
61966
  `, { mode: 384 });
62255
- fs13.renameSync(tmp, projectsFile());
61967
+ fs10.renameSync(tmp, projectsFile());
62256
61968
  return before.filter((p) => !after.includes(p));
62257
61969
  } finally {
62258
- fs13.closeSync(fd);
62259
- fs13.rmSync(lock, { force: true });
61970
+ fs10.closeSync(fd);
61971
+ fs10.rmSync(lock, { force: true });
62260
61972
  }
62261
61973
  }
62262
61974
  function adoptLegacy() {
@@ -62271,9 +61983,9 @@ var SYSTEM_WIN = ["Windows", "Program Files", "Program Files (x86)", "ProgramDat
62271
61983
  var here = () => ({ platform: process.platform, home: os4.homedir(), resolve: realpath });
62272
61984
  function refusal(picked, where = here()) {
62273
61985
  const win = where.platform === "win32";
62274
- const p = win ? path15.win32 : path15.posix;
61986
+ const p = win ? path12.win32 : path12.posix;
62275
61987
  const real = where.resolve(picked);
62276
- if (!real || !p.isAbsolute(real) || where.resolve === realpath && !fs13.statSync(real).isDirectory()) return "missing";
61988
+ if (!real || !p.isAbsolute(real) || where.resolve === realpath && !fs10.statSync(real).isDirectory()) return "missing";
62277
61989
  const norm = (d) => {
62278
61990
  const n = p.normalize(d).replace(/[\\/]+$/, "") || p.sep;
62279
61991
  return win ? n.toLowerCase() : n;
@@ -62296,16 +62008,16 @@ function refusal(picked, where = here()) {
62296
62008
  // ../runner/src/cache.ts
62297
62009
  var IDLE_MS = 7 * 24 * 60 * 6e4;
62298
62010
  var SWEEP_MS = 24 * 60 * 6e4;
62299
- var akbDir = (dir) => path16.join(dir, ".akb");
62300
- var unsentFile = (dir) => path16.join(akbDir(dir), "unsent");
62301
- var unsent = (dir) => fs14.existsSync(unsentFile(dir));
62011
+ var akbDir = (dir) => path13.join(dir, ".akb");
62012
+ var unsentFile = (dir) => path13.join(akbDir(dir), "unsent");
62013
+ var unsent = (dir) => fs11.existsSync(unsentFile(dir));
62302
62014
  var holds = /* @__PURE__ */ new Map();
62303
- var holdsDir = () => path16.join(runnerHome(), "holds");
62304
- var holdFile = (dir) => path16.join(holdsDir(), `${crypto3.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
62015
+ var holdsDir = () => path13.join(runnerHome(), "holds");
62016
+ var holdFile = (dir) => path13.join(holdsDir(), `${crypto3.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
62305
62017
  function paused(dir) {
62306
62018
  try {
62307
- const file3 = path16.join(projectStateDir(path16.join(akbDir(dir), "kanban")), SESSIONS_FILE);
62308
- const held2 = JSON.parse(fs14.readFileSync(file3, "utf8"));
62019
+ const file3 = path13.join(projectStateDir(path13.join(akbDir(dir), "kanban")), SESSIONS_FILE);
62020
+ const held2 = JSON.parse(fs11.readFileSync(file3, "utf8"));
62309
62021
  return (held2.deliveries ?? []).some((d) => d.status === "active");
62310
62022
  } catch {
62311
62023
  return false;
@@ -62313,14 +62025,14 @@ function paused(dir) {
62313
62025
  }
62314
62026
  function busy(dir) {
62315
62027
  if (holds.has(dir)) return true;
62316
- const prefix = path16.basename(holdFile(dir)).split(".")[0] + ".";
62028
+ const prefix = path13.basename(holdFile(dir)).split(".")[0] + ".";
62317
62029
  try {
62318
- return fs14.readdirSync(holdsDir()).filter((file3) => file3.startsWith(prefix)).some((file3) => {
62030
+ return fs11.readdirSync(holdsDir()).filter((file3) => file3.startsWith(prefix)).some((file3) => {
62319
62031
  try {
62320
62032
  process.kill(Number(file3.split(".")[1]), 0);
62321
62033
  return true;
62322
62034
  } catch {
62323
- fs14.rmSync(path16.join(holdsDir(), file3), { force: true });
62035
+ fs11.rmSync(path13.join(holdsDir(), file3), { force: true });
62324
62036
  return false;
62325
62037
  }
62326
62038
  });
@@ -62330,7 +62042,7 @@ function busy(dir) {
62330
62042
  }
62331
62043
  function conflicted(dir) {
62332
62044
  try {
62333
- return pendingConflicts(path16.join(dir, ".akb", "kanban")).length > 0;
62045
+ return pendingConflicts(path13.join(dir, ".akb", "kanban")).length > 0;
62334
62046
  } catch {
62335
62047
  return true;
62336
62048
  }
@@ -62338,49 +62050,49 @@ function conflicted(dir) {
62338
62050
  var kept = (dir) => busy(dir) || unsent(dir) || paused(dir) || conflicted(dir);
62339
62051
  function clearAkb(dir) {
62340
62052
  dir = realpath2(dir);
62341
- if (kept(dir) || fs14.existsSync(path16.join(akbDir(dir), "worktrees")) || fs14.existsSync(path16.join(akbDir(dir), "handoffs"))) return false;
62053
+ if (kept(dir) || fs11.existsSync(path13.join(akbDir(dir), "worktrees")) || fs11.existsSync(path13.join(akbDir(dir), "handoffs"))) return false;
62342
62054
  let entries;
62343
62055
  try {
62344
- entries = fs14.readdirSync(akbDir(dir));
62056
+ entries = fs11.readdirSync(akbDir(dir));
62345
62057
  } catch {
62346
62058
  return true;
62347
62059
  }
62348
- for (const name of entries) fs14.rmSync(path16.join(akbDir(dir), name), { recursive: true, force: true });
62060
+ for (const name of entries) fs11.rmSync(path13.join(akbDir(dir), name), { recursive: true, force: true });
62349
62061
  return true;
62350
62062
  }
62351
62063
  function realpath2(p) {
62352
62064
  try {
62353
- return fs14.realpathSync(p);
62065
+ return fs11.realpathSync(p);
62354
62066
  } catch {
62355
62067
  return p;
62356
62068
  }
62357
62069
  }
62358
62070
 
62359
62071
  // ../runner/src/kanban-skill.ts
62360
- import { spawnSync as spawnSync2 } from "node:child_process";
62361
- import fs15 from "node:fs";
62362
- import path17 from "node:path";
62072
+ import { spawnSync } from "node:child_process";
62073
+ import fs12 from "node:fs";
62074
+ import path14 from "node:path";
62363
62075
  var SKILL_FOLDERS = [".claude/skills/kanban", ".agents/skills/kanban"];
62364
62076
  var MANAGED = /^<!-- ai4kanban \S+ -->$/m;
62365
62077
  function removeLegacyKanbanSkill(root2) {
62366
62078
  for (const folder2 of SKILL_FOLDERS) {
62367
62079
  try {
62368
62080
  let at = root2;
62369
- if (!fs15.lstatSync(at, { throwIfNoEntry: false })?.isDirectory()) continue;
62081
+ if (!fs12.lstatSync(at, { throwIfNoEntry: false })?.isDirectory()) continue;
62370
62082
  let safe2 = true;
62371
62083
  const parts = `${folder2}/SKILL.md`.split("/");
62372
62084
  for (const [i, name] of parts.entries()) {
62373
- at = path17.join(at, name);
62374
- const stat = fs15.lstatSync(at, { throwIfNoEntry: false });
62085
+ at = path14.join(at, name);
62086
+ const stat = fs12.lstatSync(at, { throwIfNoEntry: false });
62375
62087
  if (!stat || stat.isSymbolicLink() || (i < parts.length - 1 ? !stat.isDirectory() : !stat.isFile())) {
62376
62088
  safe2 = false;
62377
62089
  break;
62378
62090
  }
62379
62091
  }
62380
- if (!safe2 || !MANAGED.test(fs15.readFileSync(at, "utf8"))) continue;
62381
- fs15.unlinkSync(at);
62382
- const dir = path17.dirname(at);
62383
- if (fs15.readdirSync(dir).length === 0) fs15.rmdirSync(dir);
62092
+ if (!safe2 || !MANAGED.test(fs12.readFileSync(at, "utf8"))) continue;
62093
+ fs12.unlinkSync(at);
62094
+ const dir = path14.dirname(at);
62095
+ if (fs12.readdirSync(dir).length === 0) fs12.rmdirSync(dir);
62384
62096
  } catch (e) {
62385
62097
  process.stderr.write(`wildcrane: \u65E0\u6CD5\u6E05\u7406 ${folder2}\uFF1A${e instanceof Error ? e.message : String(e)}
62386
62098
  `);
@@ -62388,15 +62100,15 @@ function removeLegacyKanbanSkill(root2) {
62388
62100
  }
62389
62101
  }
62390
62102
  function keepOutOfGit(dir, folders2 = SKILL_FOLDERS) {
62391
- const git2 = (...args2) => spawnSync2("git", ["-C", dir, ...args2], { encoding: "utf8" });
62103
+ const git2 = (...args2) => spawnSync("git", ["-C", dir, ...args2], { encoding: "utf8" });
62392
62104
  const inside = git2("rev-parse", "--git-path", "info/exclude");
62393
62105
  if (inside.status !== 0) return;
62394
62106
  const missing = [".akb/", ...folders2.map((f) => `${f}/`)].filter((p) => git2("check-ignore", "-q", p).status !== 0);
62395
62107
  if (!missing.length) return;
62396
- const exclude = path17.resolve(dir, inside.stdout.trim());
62397
- fs15.mkdirSync(path17.dirname(exclude), { recursive: true });
62398
- const held2 = fs15.existsSync(exclude) ? fs15.readFileSync(exclude, "utf8") : "";
62399
- fs15.writeFileSync(exclude, `${held2}${held2 && !held2.endsWith("\n") ? "\n" : ""}${missing.join("\n")}
62108
+ const exclude = path14.resolve(dir, inside.stdout.trim());
62109
+ fs12.mkdirSync(path14.dirname(exclude), { recursive: true });
62110
+ const held2 = fs12.existsSync(exclude) ? fs12.readFileSync(exclude, "utf8") : "";
62111
+ fs12.writeFileSync(exclude, `${held2}${held2 && !held2.endsWith("\n") ? "\n" : ""}${missing.join("\n")}
62400
62112
  `);
62401
62113
  }
62402
62114
  function retireKanbanSkill(dir) {
@@ -62411,21 +62123,21 @@ function retireKanbanSkill(dir) {
62411
62123
 
62412
62124
  // ../runner/src/runtimes.ts
62413
62125
  import { spawn as spawn2 } from "node:child_process";
62414
- import fs24 from "node:fs";
62126
+ import fs22 from "node:fs";
62415
62127
  import os6 from "node:os";
62416
- import path28 from "node:path";
62128
+ import path26 from "node:path";
62417
62129
 
62418
62130
  // ../cli/src/lib/agent/harnesses/antigravity.ts
62419
- import fs19 from "node:fs";
62420
- import path22 from "node:path";
62131
+ import fs17 from "node:fs";
62132
+ import path20 from "node:path";
62421
62133
  import { createHash as createHash3 } from "node:crypto";
62422
- import { spawnSync as spawnSync4 } from "node:child_process";
62134
+ import { spawnSync as spawnSync3 } from "node:child_process";
62423
62135
 
62424
62136
  // ../cli/src/lib/agent/locate.ts
62425
- import { spawn, spawnSync as spawnSync3 } from "node:child_process";
62426
- import fs17 from "node:fs";
62137
+ import { spawn, spawnSync as spawnSync2 } from "node:child_process";
62138
+ import fs14 from "node:fs";
62427
62139
  import os5 from "node:os";
62428
- import path19 from "node:path";
62140
+ import path16 from "node:path";
62429
62141
 
62430
62142
  // ../cli/src/lib/agent/argv.ts
62431
62143
  function splitCommand(command) {
@@ -62464,8 +62176,8 @@ function commandBinary(command) {
62464
62176
  }
62465
62177
 
62466
62178
  // ../cli/src/lib/agent/spawnable.ts
62467
- import fs16 from "node:fs";
62468
- import path18 from "node:path";
62179
+ import fs13 from "node:fs";
62180
+ import path15 from "node:path";
62469
62181
  var META = /([()\][%!^"`<>&|;, *?])/g;
62470
62182
  function cmdArg(arg) {
62471
62183
  const quoted = `"${arg.replace(/\r?\n|\r/g, " ").replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
@@ -62475,21 +62187,21 @@ function cmdLine(file3, args2) {
62475
62187
  return `"${[file3.replace(META, "^$1"), ...args2.map(cmdArg)].join(" ")}"`;
62476
62188
  }
62477
62189
  function shimTarget(text2, file3) {
62478
- const dir = path18.win32.dirname(file3);
62190
+ const dir = path15.win32.dirname(file3);
62479
62191
  const found = /"%(?:~dp0|dp0%)\\?([^"%]+)"\s+%\*/i.exec(text2);
62480
62192
  if (!found || !/\\node\.exe"/i.test(text2)) return null;
62481
- const script = path18.win32.resolve(dir, found[1].replace(/\//g, "\\"));
62482
- const local = path18.win32.join(dir, "node.exe");
62193
+ const script = path15.win32.resolve(dir, found[1].replace(/\//g, "\\"));
62194
+ const local = path15.win32.join(dir, "node.exe");
62483
62195
  const nodePath = /SET "NODE_PATH=([^"]*)"/i.exec(text2)?.[1];
62484
- return { script, node: fs16.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
62196
+ return { script, node: fs13.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
62485
62197
  }
62486
62198
  function onWindowsPath(name, env2) {
62487
62199
  const exts = (env2.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
62488
62200
  const key = Object.keys(env2).find((k) => k.toUpperCase() === "PATH") ?? "PATH";
62489
62201
  for (const dir of (env2[key] ?? "").split(";").filter(Boolean)) {
62490
62202
  for (const ext of exts) {
62491
- const file3 = path18.win32.join(dir, `${name}${ext.toLowerCase()}`);
62492
- if (fs16.existsSync(file3)) return file3;
62203
+ const file3 = path15.win32.join(dir, `${name}${ext.toLowerCase()}`);
62204
+ if (fs13.existsSync(file3)) return file3;
62493
62205
  }
62494
62206
  }
62495
62207
  return void 0;
@@ -62497,13 +62209,13 @@ function onWindowsPath(name, env2) {
62497
62209
  function spawnable(command, args2, options = {}, platform = process.platform) {
62498
62210
  if (platform !== "win32") return { command, args: args2, options };
62499
62211
  const env2 = options.env ?? process.env;
62500
- const file3 = path18.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
62501
- const ext = path18.extname(file3).toLowerCase();
62212
+ const file3 = path15.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
62213
+ const ext = path15.extname(file3).toLowerCase();
62502
62214
  const hidden = { ...options, windowsHide: true, shell: false };
62503
62215
  if (ext !== ".cmd" && ext !== ".bat") return { command: file3, args: args2, options: hidden };
62504
62216
  let text2 = "";
62505
62217
  try {
62506
- text2 = fs16.readFileSync(file3, "utf8");
62218
+ text2 = fs13.readFileSync(file3, "utf8");
62507
62219
  } catch {
62508
62220
  }
62509
62221
  const shim = shimTarget(text2, file3);
@@ -62567,7 +62279,7 @@ function pick2(copies) {
62567
62279
  }
62568
62280
  function folders(parent) {
62569
62281
  try {
62570
- return fs17.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
62282
+ return fs14.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
62571
62283
  } catch {
62572
62284
  return [];
62573
62285
  }
@@ -62586,29 +62298,29 @@ function byVersion(names) {
62586
62298
  function latestIn(parent, tail = "") {
62587
62299
  let names;
62588
62300
  try {
62589
- names = fs17.readdirSync(parent);
62301
+ names = fs14.readdirSync(parent);
62590
62302
  } catch {
62591
62303
  return [];
62592
62304
  }
62593
- return byVersion(names.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path19.join(parent, name, tail));
62305
+ return byVersion(names.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path16.join(parent, name, tail));
62594
62306
  }
62595
62307
  var env = (name) => process.env[name]?.trim() ?? "";
62596
62308
  function commonDirs() {
62597
62309
  const home3 = os5.homedir();
62598
- const under = (...parts) => path19.join(home3, ...parts);
62599
- const nodes = (root2, tail = []) => root2 ? folders(root2).map((version2) => path19.join(root2, version2, ...tail)) : [];
62310
+ const under = (...parts) => path16.join(home3, ...parts);
62311
+ const nodes = (root2, tail = []) => root2 ? folders(root2).map((version2) => path16.join(root2, version2, ...tail)) : [];
62600
62312
  if (WINDOWS2) {
62601
62313
  const [app, local, data, programs] = [env("APPDATA"), env("LOCALAPPDATA"), env("ProgramData"), env("ProgramFiles")];
62602
62314
  return [
62603
62315
  under(".local", "bin"),
62604
62316
  under(".bun", "bin"),
62605
62317
  under("scoop", "shims"),
62606
- ...app ? [path19.join(app, "npm")] : [],
62607
- ...local ? [path19.join(local, "pnpm"), path19.join(local, "Volta", "bin"), path19.join(local, "Microsoft", "WinGet", "Links")] : [],
62608
- ...data ? [path19.join(data, "chocolatey", "bin")] : [],
62609
- ...programs ? [path19.join(programs, "nodejs")] : [],
62318
+ ...app ? [path16.join(app, "npm")] : [],
62319
+ ...local ? [path16.join(local, "pnpm"), path16.join(local, "Volta", "bin"), path16.join(local, "Microsoft", "WinGet", "Links")] : [],
62320
+ ...data ? [path16.join(data, "chocolatey", "bin")] : [],
62321
+ ...programs ? [path16.join(programs, "nodejs")] : [],
62610
62322
  ...nodes(env("NVM_HOME")),
62611
- ...app ? nodes(path19.join(app, "fnm", "node-versions"), ["installation"]) : []
62323
+ ...app ? nodes(path16.join(app, "fnm", "node-versions"), ["installation"]) : []
62612
62324
  ];
62613
62325
  }
62614
62326
  const support = process.platform === "darwin" ? under("Library", "Application Support") : under(".local", "share");
@@ -62625,10 +62337,10 @@ function commonDirs() {
62625
62337
  ...env("PNPM_HOME") ? [env("PNPM_HOME")] : [],
62626
62338
  under("Library", "pnpm"),
62627
62339
  under(".local", "share", "pnpm"),
62628
- path19.join(env("VOLTA_HOME") || under(".volta"), "bin"),
62629
- ...nodes(path19.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
62630
- ...nodes(path19.join(env("FNM_DIR") || path19.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
62631
- ...nodes(path19.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
62340
+ path16.join(env("VOLTA_HOME") || under(".volta"), "bin"),
62341
+ ...nodes(path16.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
62342
+ ...nodes(path16.join(env("FNM_DIR") || path16.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
62343
+ ...nodes(path16.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
62632
62344
  ...nodes(under(".local", "share", "mise", "installs", "node"), ["bin"]),
62633
62345
  ...nodes(under(".nodenv", "versions"), ["bin"]),
62634
62346
  ...nodes("/usr/local/n/versions/node", ["bin"])
@@ -62636,11 +62348,11 @@ function commonDirs() {
62636
62348
  }
62637
62349
  function onPath(binary) {
62638
62350
  const names = WINDOWS2 ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((ext) => `${binary}${ext.toLowerCase()}`) : [binary];
62639
- return (process.env.PATH ?? "").split(path19.delimiter).filter(Boolean).flatMap((dir) => names.map((name) => path19.join(dir, name)));
62351
+ return (process.env.PATH ?? "").split(path16.delimiter).filter(Boolean).flatMap((dir) => names.map((name) => path16.join(dir, name)));
62640
62352
  }
62641
62353
  var isFile = (file3) => {
62642
62354
  try {
62643
- return fs17.statSync(file3).isFile();
62355
+ return fs14.statSync(file3).isFile();
62644
62356
  } catch {
62645
62357
  return false;
62646
62358
  }
@@ -62649,24 +62361,24 @@ function copyFiles(harness) {
62649
62361
  const pinned = harness.pinned?.();
62650
62362
  if (pinned && isFile(pinned)) return [{ file: pinned, entry: false }];
62651
62363
  const binary = commandBinary(harness.command);
62652
- const exe = (file3) => WINDOWS2 && !path19.extname(file3) ? [`${file3}.exe`, `${file3}.cmd`] : [file3];
62364
+ const exe = (file3) => WINDOWS2 && !path16.extname(file3) ? [`${file3}.exe`, `${file3}.cmd`] : [file3];
62653
62365
  const path_ = onPath(binary).filter(isFile);
62654
- const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path19.join(dir, binary))];
62366
+ const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path16.join(dir, binary))];
62655
62367
  const others = elsewhere.flatMap(exe).filter(isFile);
62656
62368
  const seen = /* @__PURE__ */ new Set();
62657
62369
  return [...path_, ...others].flatMap((file3, i) => {
62658
- const real = fs17.realpathSync.native(file3);
62370
+ const real = fs14.realpathSync.native(file3);
62659
62371
  if (seen.has(real)) return [];
62660
62372
  seen.add(real);
62661
62373
  return [{ file: file3, entry: i === 0 && path_.length > 0 }];
62662
62374
  });
62663
62375
  }
62664
62376
  var answers;
62665
- var answersFile = () => path19.join(machineHome(), "agent-copies.json");
62377
+ var answersFile = () => path16.join(machineHome(), "agent-copies.json");
62666
62378
  function kept2() {
62667
62379
  if (answers) return answers;
62668
62380
  try {
62669
- answers = JSON.parse(fs17.readFileSync(answersFile(), "utf8"));
62381
+ answers = JSON.parse(fs14.readFileSync(answersFile(), "utf8"));
62670
62382
  } catch {
62671
62383
  answers = {};
62672
62384
  }
@@ -62675,16 +62387,16 @@ function kept2() {
62675
62387
  function keep(file3, answer) {
62676
62388
  kept2()[file3] = answer;
62677
62389
  try {
62678
- fs17.mkdirSync(machineHome(), { recursive: true });
62390
+ fs14.mkdirSync(machineHome(), { recursive: true });
62679
62391
  const staged = `${answersFile()}.${process.pid}`;
62680
- fs17.writeFileSync(staged, JSON.stringify(answers));
62681
- fs17.renameSync(staged, answersFile());
62392
+ fs14.writeFileSync(staged, JSON.stringify(answers));
62393
+ fs14.renameSync(staged, answersFile());
62682
62394
  } catch {
62683
62395
  }
62684
62396
  }
62685
62397
  function keyOf(file3) {
62686
- const real = fs17.realpathSync.native(file3);
62687
- const stat = fs17.statSync(real);
62398
+ const real = fs14.realpathSync.native(file3);
62399
+ const stat = fs14.statSync(real);
62688
62400
  return `${real}|${stat.size}|${stat.mtimeMs}`;
62689
62401
  }
62690
62402
  function known(file3, maxAge) {
@@ -62697,14 +62409,14 @@ function judge(code, status2, stdout, stderr) {
62697
62409
  return { starts: true, version: status2 === 0 ? versionIn(stdout) ?? versionIn(stderr) : null };
62698
62410
  }
62699
62411
  function copyEnv(file3, given = process.env) {
62700
- if (!path19.isAbsolute(file3)) return given;
62701
- return { ...given, PATH: [path19.dirname(file3), given.PATH].filter(Boolean).join(path19.delimiter) };
62412
+ if (!path16.isAbsolute(file3)) return given;
62413
+ return { ...given, PATH: [path16.dirname(file3), given.PATH].filter(Boolean).join(path16.delimiter) };
62702
62414
  }
62703
62415
  var probeOptions = (file3) => ({ cwd: os5.tmpdir(), env: copyEnv(file3), windowsHide: true, shell: false });
62704
62416
  function probe(file3) {
62705
62417
  const key = keyOf(file3);
62706
62418
  const start = spawnable(file3, ["--version"], { ...probeOptions(file3), stdio: ["ignore", "pipe", "pipe"], timeout: PROBE_MS });
62707
- const run2 = spawnSync3(start.command, start.args, { ...start.options, encoding: "utf8" });
62419
+ const run2 = spawnSync2(start.command, start.args, { ...start.options, encoding: "utf8" });
62708
62420
  const code = run2.error?.code;
62709
62421
  const answer = { key, at: Date.now(), ...judge(code, run2.status, run2.stdout ?? "", run2.stderr ?? "") };
62710
62422
  keep(file3, answer);
@@ -62756,16 +62468,16 @@ import { join } from "node:path";
62756
62468
  function home(...parts) {
62757
62469
  return join(homedir(), ...parts);
62758
62470
  }
62759
- function obj2(value) {
62471
+ function obj(value) {
62760
62472
  return value && typeof value === "object" ? value : {};
62761
62473
  }
62762
62474
  function arr(value) {
62763
62475
  return Array.isArray(value) ? value : [];
62764
62476
  }
62765
- function str2(value) {
62477
+ function str(value) {
62766
62478
  return typeof value === "string" ? value : "";
62767
62479
  }
62768
- function num2(value) {
62480
+ function num(value) {
62769
62481
  return typeof value === "number" ? value : Number.MAX_SAFE_INTEGER;
62770
62482
  }
62771
62483
  function uniqueIds(list3) {
@@ -62794,8 +62506,8 @@ function modelsIn(file3, pick3, salt = "") {
62794
62506
 
62795
62507
  // ../cli/src/lib/agent/harnesses/types.ts
62796
62508
  import { createHash as createHash2 } from "node:crypto";
62797
- import fs18 from "node:fs";
62798
- import path20 from "node:path";
62509
+ import fs15 from "node:fs";
62510
+ import path17 from "node:path";
62799
62511
  function namesFlag(argv, flags) {
62800
62512
  return argv.some((tok) => flags.some((flag) => tok === flag || tok.startsWith(`${flag}=`)));
62801
62513
  }
@@ -62817,18 +62529,62 @@ var MCP_CONFIG = {
62817
62529
  };
62818
62530
  function machineFile(name, text2) {
62819
62531
  const suffix = createHash2("sha256").update(text2).digest("hex").slice(0, 16);
62820
- const file3 = path20.join(machineHome(), "prompts", `${path20.parse(name).name}-${suffix}${path20.extname(name)}`);
62532
+ const file3 = path17.join(machineHome(), "prompts", `${path17.parse(name).name}-${suffix}${path17.extname(name)}`);
62821
62533
  try {
62822
- if (fs18.readFileSync(file3, "utf8") === text2) return file3;
62534
+ if (fs15.readFileSync(file3, "utf8") === text2) return file3;
62823
62535
  } catch {
62824
62536
  }
62825
- fs18.mkdirSync(path20.dirname(file3), { recursive: true });
62826
- fs18.writeFileSync(file3, text2);
62537
+ fs15.mkdirSync(path17.dirname(file3), { recursive: true });
62538
+ fs15.writeFileSync(file3, text2);
62827
62539
  return file3;
62828
62540
  }
62829
62541
 
62542
+ // ../cli/src/lib/machine/settings.ts
62543
+ import fs16 from "node:fs";
62544
+ import path18 from "node:path";
62545
+
62546
+ // ../cli/src/lib/machine/types.ts
62547
+ var LANGUAGES = ["en", "zh"];
62548
+ var DEFAULT_LANGUAGE = "en";
62549
+ function isLanguage(value) {
62550
+ return typeof value === "string" && LANGUAGES.includes(value);
62551
+ }
62552
+
62553
+ // ../cli/src/lib/machine/settings.ts
62554
+ var settingsFile = () => path18.join(machineHome(), "settings.json");
62555
+ function heldSettings() {
62556
+ let text2;
62557
+ try {
62558
+ text2 = fs16.readFileSync(settingsFile(), "utf8");
62559
+ } catch (err) {
62560
+ if (err.code === "ENOENT") return { unreadable: false, values: {} };
62561
+ return { unreadable: true, values: {} };
62562
+ }
62563
+ try {
62564
+ const parsed = JSON.parse(text2);
62565
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { unreadable: true, values: {} };
62566
+ return { unreadable: false, values: parsed };
62567
+ } catch {
62568
+ return { unreadable: true, values: {} };
62569
+ }
62570
+ }
62571
+ var held = () => heldSettings().values;
62572
+ function readLanguage() {
62573
+ const value = held().language;
62574
+ return isLanguage(value) ? value : DEFAULT_LANGUAGE;
62575
+ }
62576
+
62577
+ // ../cli/src/lib/agent/language.ts
62578
+ var LANGUAGE_ENV = "AI4KANBAN_LANGUAGE";
62579
+ var languageCode = (value) => value === "zh" || value === "en" ? value : null;
62580
+ function runLanguage() {
62581
+ if (process.env[LANGUAGE_ENV] !== void 0) return languageCode(process.env[LANGUAGE_ENV]);
62582
+ return readLanguage();
62583
+ }
62584
+ var translating = () => runLanguage() === "zh";
62585
+
62830
62586
  // ../cli/src/lib/agent/wire/antigravity.ts
62831
- import path21 from "node:path";
62587
+ import path19 from "node:path";
62832
62588
 
62833
62589
  // ../cli/src/lib/agent/prices.ts
62834
62590
  var OPENAI = {
@@ -62881,9 +62637,33 @@ function priceUsd(provider, model, usage, at = Date.now()) {
62881
62637
  return Number.isFinite(usd) && usd >= 0 ? usd : void 0;
62882
62638
  }
62883
62639
 
62640
+ // ../cli/src/lib/agent/wire/json.ts
62641
+ function obj2(value) {
62642
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
62643
+ }
62644
+ function str2(value) {
62645
+ return typeof value === "string" ? value : "";
62646
+ }
62647
+ function num2(value) {
62648
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
62649
+ }
62650
+ function hint(raw) {
62651
+ const line = raw.split("\n")[0].trim();
62652
+ if (!line) return "";
62653
+ return `(${line.length > 96 ? `${line.slice(0, 93)}\u2026` : line})`;
62654
+ }
62655
+ function argHint(input2, keys) {
62656
+ const args2 = obj2(input2);
62657
+ for (const key of keys) {
62658
+ const value = str2(args2[key]);
62659
+ if (value.trim()) return hint(value);
62660
+ }
62661
+ return "";
62662
+ }
62663
+
62884
62664
  // ../cli/src/lib/agent/wire/events.ts
62885
62665
  var TOOL_KINDS = ["read", "edit", "delete", "move", "search", "execute", "fetch", "other"];
62886
- var toolKind = (v) => TOOL_KINDS.includes(str(v)) ? v : "other";
62666
+ var toolKind = (v) => TOOL_KINDS.includes(str2(v)) ? v : "other";
62887
62667
  function targetOf(raw) {
62888
62668
  const line = raw.split("\n")[0].trim();
62889
62669
  if (!line) return void 0;
@@ -62892,29 +62672,29 @@ function targetOf(raw) {
62892
62672
  function contentText(raw) {
62893
62673
  const parts = Array.isArray(raw) ? raw : [];
62894
62674
  return parts.map((p) => {
62895
- const part = obj(p);
62896
- if (part.type === "diff") return str(part.path);
62897
- return str(obj(part.content).text) || str(part.text);
62675
+ const part = obj2(p);
62676
+ if (part.type === "diff") return str2(part.path);
62677
+ return str2(obj2(part.content).text) || str2(part.text);
62898
62678
  }).filter((t2) => t2.trim()).join("\n");
62899
62679
  }
62900
62680
  function statusOf(raw) {
62901
- const s = str(raw).toLowerCase();
62681
+ const s = str2(raw).toLowerCase();
62902
62682
  if (s.includes("progress")) return "in_progress";
62903
62683
  if (/complete|done|cancel/.test(s)) return "completed";
62904
62684
  return "pending";
62905
62685
  }
62906
62686
  function entriesOf(raw) {
62907
- return (Array.isArray(raw) ? raw : []).map(obj).flatMap((e) => {
62908
- const content = str(e.content).trim();
62687
+ return (Array.isArray(raw) ? raw : []).map(obj2).flatMap((e) => {
62688
+ const content = str2(e.content).trim();
62909
62689
  if (!content) return [];
62910
- return [{ content, status: statusOf(e.status), ...str(e.priority) ? { priority: str(e.priority) } : {} }];
62690
+ return [{ content, status: statusOf(e.status), ...str2(e.priority) ? { priority: str2(e.priority) } : {} }];
62911
62691
  });
62912
62692
  }
62913
- var isTodoCall = (u) => str(u.title) === "todowrite" || str(obj(u.rawInput)._toolName) === "updateTodos";
62914
- var inputTarget = (input2) => str(input2.command) || str(input2.path) || str(input2.filePath);
62693
+ var isTodoCall = (u) => str2(u.title) === "todowrite" || str2(obj2(u.rawInput)._toolName) === "updateTodos";
62694
+ var inputTarget = (input2) => str2(input2.command) || str2(input2.path) || str2(input2.filePath);
62915
62695
  var targetIn = (u) => {
62916
62696
  const locations = Array.isArray(u.locations) ? u.locations : [];
62917
- return targetOf(inputTarget(obj(u.rawInput)) || str(obj(locations[0]).path) || "");
62697
+ return targetOf(inputTarget(obj2(u.rawInput)) || str2(obj2(locations[0]).path) || "");
62918
62698
  };
62919
62699
  function createEventCollector() {
62920
62700
  let queue = [];
@@ -62940,34 +62720,34 @@ function createEventCollector() {
62940
62720
  },
62941
62721
  /** One ACP `session/update`'s `update`. Thoughts and housekeeping updates yield nothing. */
62942
62722
  update(raw) {
62943
- const u = obj(raw);
62723
+ const u = obj2(raw);
62944
62724
  if (u.sessionUpdate === "agent_message_chunk") {
62945
- const chunk = str(obj(u.content).text);
62725
+ const chunk = str2(obj2(u.content).text);
62946
62726
  if (chunk) activity++;
62947
62727
  said += chunk;
62948
62728
  return;
62949
62729
  }
62950
- if (!["tool_call", "tool_call_update", "plan"].includes(str(u.sessionUpdate))) return;
62730
+ if (!["tool_call", "tool_call_update", "plan"].includes(str2(u.sessionUpdate))) return;
62951
62731
  close();
62952
62732
  switch (u.sessionUpdate) {
62953
62733
  case "tool_call": {
62954
- const id2 = str(u.toolCallId);
62734
+ const id2 = str2(u.toolCallId);
62955
62735
  if (isTodoCall(u)) {
62956
62736
  todoCalls.add(id2);
62957
62737
  return;
62958
62738
  }
62959
62739
  const target = targetIn(u);
62960
- const subagent = /^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(str(u.title)) || !!obj(u.rawInput).subagent_type;
62961
- const data = { toolCallId: id2, title: str(u.title) || "tool", kind: toolKind(u.kind), status: str(u.status) || "pending", ...subagent ? { subagent: true } : {}, ...target ? { target } : {} };
62962
- if (data.kind !== "execute" && !subagent && u.rawInput !== void 0 && !inputTarget(obj(u.rawInput))) held2.set(id2, data);
62740
+ const subagent = /^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(str2(u.title)) || !!obj2(u.rawInput).subagent_type;
62741
+ const data = { toolCallId: id2, title: str2(u.title) || "tool", kind: toolKind(u.kind), status: str2(u.status) || "pending", ...subagent ? { subagent: true } : {}, ...target ? { target } : {} };
62742
+ if (data.kind !== "execute" && !subagent && u.rawInput !== void 0 && !inputTarget(obj2(u.rawInput))) held2.set(id2, data);
62963
62743
  else queue.push({ kind: "tool_call", data });
62964
62744
  return;
62965
62745
  }
62966
62746
  case "tool_call_update": {
62967
- const id2 = str(u.toolCallId);
62747
+ const id2 = str2(u.toolCallId);
62968
62748
  if (todoCalls.has(id2)) {
62969
- const list3 = obj(u.rawInput).todos;
62970
- if (Array.isArray(list3) && !str(obj(u.rawInput)._toolName)) queue.push({ kind: "plan", data: { entries: entriesOf(list3) } });
62749
+ const list3 = obj2(u.rawInput).todos;
62750
+ if (Array.isArray(list3) && !str2(obj2(u.rawInput)._toolName)) queue.push({ kind: "plan", data: { entries: entriesOf(list3) } });
62971
62751
  return;
62972
62752
  }
62973
62753
  release(id2, targetIn(u));
@@ -62975,7 +62755,7 @@ function createEventCollector() {
62975
62755
  if (!u.status && !result) return;
62976
62756
  queue.push({
62977
62757
  kind: "tool_call_update",
62978
- data: { toolCallId: str(u.toolCallId), status: str(u.status) || "in_progress", ...result ? { result } : {} }
62758
+ data: { toolCallId: str2(u.toolCallId), status: str2(u.status) || "in_progress", ...result ? { result } : {} }
62979
62759
  });
62980
62760
  return;
62981
62761
  }
@@ -63010,9 +62790,9 @@ function createEventCollector() {
63010
62790
  /** Cursor's `cursor/update_todos`: the whole list, or under `merge` only what changed, by id. */
63011
62791
  todos(raw, merge2) {
63012
62792
  close();
63013
- const items = (Array.isArray(raw) ? raw : []).map(obj).flatMap((e) => {
62793
+ const items = (Array.isArray(raw) ? raw : []).map(obj2).flatMap((e) => {
63014
62794
  const [entry] = entriesOf([e]);
63015
- return entry ? [{ ...entry, id: str(e.id) }] : [];
62795
+ return entry ? [{ ...entry, id: str2(e.id) }] : [];
63016
62796
  });
63017
62797
  const next = merge2 ? [...todos] : [];
63018
62798
  for (const item of items) {
@@ -63171,8 +62951,8 @@ var KINDS = {
63171
62951
  };
63172
62952
  var zero = () => ({ input: 0, cacheCreation: 0, cacheRead: 0, output: 0 });
63173
62953
  var usageOf = (raw) => {
63174
- const u = obj(raw);
63175
- return { input: num(u.input_tokens), output: num(u.output_tokens), cacheRead: num(u.cache_read_tokens), cacheCreation: 0 };
62954
+ const u = obj2(raw);
62955
+ return { input: num2(u.input_tokens), output: num2(u.output_tokens), cacheRead: num2(u.cache_read_tokens), cacheCreation: 0 };
63176
62956
  };
63177
62957
  var add = (a, b) => ({ input: a.input + b.input, output: a.output + b.output, cacheRead: a.cacheRead + b.cacheRead, cacheCreation: 0 });
63178
62958
  function failureHint(reason) {
@@ -63214,7 +62994,7 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
63214
62994
  const index = step.step_index;
63215
62995
  if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || priced.has(index) || !model && index <= prompt) return;
63216
62996
  priced.add(index);
63217
- const u = obj(step.usage);
62997
+ const u = obj2(step.usage);
63218
62998
  const valid = [u.input_tokens, u.output_tokens, u.cache_read_tokens].every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0);
63219
62999
  if (!valid || !model && prompt < 0) incomplete = true;
63220
63000
  else if (model) estimate(model, usageOf(u));
@@ -63240,33 +63020,33 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
63240
63020
  `;
63241
63021
  }
63242
63022
  if (e.event === "init") {
63243
- const got = str(e.conversation_id);
63023
+ const got = str2(e.conversation_id);
63244
63024
  if (expectedSession && got !== expectedSession) {
63245
63025
  fail(translating() ? "Antigravity \u672A\u7EED\u63A5\u6307\u5B9A\u4F1A\u8BDD\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u539F\u4F1A\u8BDD\u540E\u91CD\u8BD5\u3002" : "Antigravity did not resume the requested conversation.", "session_mismatch");
63246
63026
  return "";
63247
63027
  }
63248
63028
  session = got || session;
63249
- model = str(obj(e.init).model) || model;
63029
+ model = str2(obj2(e.init).model) || model;
63250
63030
  return "";
63251
63031
  }
63252
63032
  if (e.event === "step_update") {
63253
- const step = obj(e.step_update);
63254
- const got = str(step.conversation_id);
63033
+ const step = obj2(e.step_update);
63034
+ const got = str2(step.conversation_id);
63255
63035
  if (expectedSession && got !== expectedSession || session && got && got !== session) return "";
63256
63036
  session = got || session;
63257
63037
  const id2 = String(step.step_index ?? "");
63258
63038
  if (step.state === "DONE" && step.step_type === "user_input" && typeof step.step_index === "number" && Number.isSafeInteger(step.step_index) && step.step_index > prompt) prompt = step.step_index;
63259
- if (step.state === "DONE" && ["agent_response", "checkpoint"].includes(str(step.step_type))) countCost(step);
63039
+ if (step.state === "DONE" && ["agent_response", "checkpoint"].includes(str2(step.step_type))) countCost(step);
63260
63040
  if (step.step_type === "agent_response") {
63261
- const text2 = str(step.text_delta);
63041
+ const text2 = str2(step.text_delta);
63262
63042
  partial2 += text2;
63263
63043
  if (text2) events.update({ sessionUpdate: "agent_message_chunk", content: { text: text2 } });
63264
- const index = num(step.step_index);
63044
+ const index = num2(step.step_index);
63265
63045
  if (step.state === "DONE" && Number.isSafeInteger(index) && step.step_index === index && index > contextStep) {
63266
63046
  contextStep = index;
63267
- const u = obj(step.usage);
63047
+ const u = obj2(step.usage);
63268
63048
  const counts = [u.input_tokens, u.cache_read_tokens];
63269
- const prompt2 = counts.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0) ? num(u.input_tokens) + num(u.cache_read_tokens) : 0;
63049
+ const prompt2 = counts.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0) ? num2(u.input_tokens) + num2(u.cache_read_tokens) : 0;
63270
63050
  context = prompt2 > 0 && Number.isFinite(prompt2) ? { used: prompt2 } : void 0;
63271
63051
  }
63272
63052
  if (step.state === "DONE" && step.usage && !counted.has(index)) {
@@ -63277,10 +63057,10 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
63277
63057
  return text2;
63278
63058
  }
63279
63059
  if (step.step_type === "tool") {
63280
- const tool = obj(step.tool_info);
63281
- const name = str(tool.name) || str(step.tool_name) || "tool";
63282
- const p = obj(tool.parameters);
63283
- const target = str(p.CommandLine) || str(p.Path) || str(p.TargetFile) || str(p.AbsolutePath) || str(p.Query);
63060
+ const tool = obj2(step.tool_info);
63061
+ const name = str2(tool.name) || str2(step.tool_name) || "tool";
63062
+ const p = obj2(tool.parameters);
63063
+ const target = str2(p.CommandLine) || str2(p.Path) || str2(p.TargetFile) || str2(p.AbsolutePath) || str2(p.Query);
63284
63064
  let out = "";
63285
63065
  if (!calls.has(id2)) {
63286
63066
  calls.add(id2);
@@ -63289,41 +63069,41 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
63289
63069
  \u23FA ${name}${target ? ` ${target}` : ""}
63290
63070
  `;
63291
63071
  }
63292
- const error62 = obj(tool.error);
63293
- const reason = str(error62.message) || str(error62.type);
63294
- if (["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(str(step.state)) && !closed.has(id2)) {
63072
+ const error62 = obj2(tool.error);
63073
+ const reason = str2(error62.message) || str2(error62.type);
63074
+ if (["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(str2(step.state)) && !closed.has(id2)) {
63295
63075
  closed.add(id2);
63296
63076
  const failed = !!reason || step.state !== "DONE";
63297
63077
  if (["read_file", "view_file"].includes(name) && imagePath(target)) {
63298
- const file3 = path21.resolve(cwd, target);
63078
+ const file3 = path19.resolve(cwd, target);
63299
63079
  if (failed) {
63300
- imageErrors.set(file3, reason || str(step.state));
63080
+ imageErrors.set(file3, reason || str2(step.state));
63301
63081
  out += `
63302
- ${imageError(target, reason || str(step.state))}
63082
+ ${imageError(target, reason || str2(step.state))}
63303
63083
  `;
63304
63084
  } else {
63305
63085
  readImages.add(file3);
63306
63086
  imageErrors.delete(file3);
63307
63087
  }
63308
63088
  }
63309
- events.toolResult(id2, failed ? "failed" : "completed", str(tool.output) || reason);
63089
+ events.toolResult(id2, failed ? "failed" : "completed", str2(tool.output) || reason);
63310
63090
  }
63311
63091
  return out;
63312
63092
  }
63313
63093
  return "";
63314
63094
  }
63315
63095
  if (e.event === "result") {
63316
- const result = obj(e.result);
63317
- if (expectedSession && str(result.conversation_id) && result.conversation_id !== expectedSession) {
63096
+ const result = obj2(e.result);
63097
+ if (expectedSession && str2(result.conversation_id) && result.conversation_id !== expectedSession) {
63318
63098
  fail(translating() ? "Antigravity \u672A\u7EED\u63A5\u6307\u5B9A\u4F1A\u8BDD\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u539F\u4F1A\u8BDD\u540E\u91CD\u8BD5\u3002" : "Antigravity did not resume the requested conversation.", "session_mismatch");
63319
63099
  terminal = true;
63320
63100
  return "";
63321
63101
  }
63322
- session ||= str(result.conversation_id) || void 0;
63102
+ session ||= str2(result.conversation_id) || void 0;
63323
63103
  terminal = true;
63324
63104
  final = typeof result.response === "string" ? result.response : void 0;
63325
63105
  const total = usageOf(result.usage);
63326
- used = previous ? { input: Math.max(0, total.input - previous.input), output: Math.max(0, total.output - previous.output), cacheRead: Math.max(0, total.cacheRead - previous.cacheRead), cacheCreation: 0 } : num(result.num_turns) === 1 ? total : turnUsage;
63106
+ used = previous ? { input: Math.max(0, total.input - previous.input), output: Math.max(0, total.output - previous.output), cacheRead: Math.max(0, total.cacheRead - previous.cacheRead), cacheCreation: 0 } : num2(result.num_turns) === 1 ? total : turnUsage;
63327
63107
  previous = total;
63328
63108
  if (!Object.values(used).some((n) => n > 0)) used = void 0;
63329
63109
  const missing = requiredImages.length ? requiredImages.filter((file3) => !readImages.has(file3)) : [...imageErrors.keys()];
@@ -63332,8 +63112,8 @@ ${imageError(target, reason || str(step.state))}
63332
63112
  readImages.clear();
63333
63113
  imageErrors.clear();
63334
63114
  if (Array.isArray(result.denied_actions) && result.denied_actions.length) fail(translating() ? "Antigravity \u6743\u9650\u62D2\u7EDD\uFF0C\u8BF7\u68C0\u67E5\u6743\u9650\u89C4\u5219\u540E\u91CD\u8BD5\u3002" : "Antigravity permission denied. Check permission rules, then retry.", "permission_denied");
63335
- else if (!failure3 && (typeof result.response !== "string" || result.status !== "SUCCESS" || str(result.error) || result.finished_reason && result.finished_reason !== "completed" && result.finished_reason !== "success")) {
63336
- fail(result.status === "CANCELED" ? `Antigravity: CANCELED${result.error ? `: ${str(result.error)}` : ""}` : str(result.error) || `Antigravity: ${str(result.status) || "missing status"}`);
63115
+ else if (!failure3 && (typeof result.response !== "string" || result.status !== "SUCCESS" || str2(result.error) || result.finished_reason && result.finished_reason !== "completed" && result.finished_reason !== "success")) {
63116
+ fail(result.status === "CANCELED" ? `Antigravity: CANCELED${result.error ? `: ${str2(result.error)}` : ""}` : str2(result.error) || `Antigravity: ${str2(result.status) || "missing status"}`);
63337
63117
  }
63338
63118
  events.end();
63339
63119
  turnUsage = zero();
@@ -63347,7 +63127,7 @@ ${imageError(target, reason || str(step.state))}
63347
63127
  return {
63348
63128
  push: reader.push,
63349
63129
  setRequiredImages(files) {
63350
- requiredImages = files.filter(imagePath).map((file3) => path21.resolve(cwd, file3));
63130
+ requiredImages = files.filter(imagePath).map((file3) => path19.resolve(cwd, file3));
63351
63131
  },
63352
63132
  flush() {
63353
63133
  const text2 = reader.flush();
@@ -63403,7 +63183,7 @@ function args(argv, resume) {
63403
63183
  if (namesFlag(argv, ["--continue", "-c", "--conversation", "--remote-agent"])) throw new Error(translating() ? "\u8BF7\u901A\u8FC7 WildCrane \u9009\u62E9 Antigravity \u4F1A\u8BDD\uFF0C\u4E0D\u8981\u5728\u989D\u5916\u53C2\u6570\u4E2D\u6307\u5B9A\u4F1A\u8BDD\u6216\u8FDC\u7A0B\u6267\u884C\u3002" : "Antigravity: select a session through WildCrane, not extra arguments.");
63404
63184
  if (resume) {
63405
63185
  const file3 = antigravityConversationFile(resume);
63406
- if (!file3 || !fs19.existsSync(file3)) throw new Error(translating() ? "Antigravity \u4F1A\u8BDD\u4E0D\u5B58\u5728\u3002\u8BF7\u5728\u672C\u673A\u6062\u590D\u539F\u4F1A\u8BDD\u540E\u7EED\u63A5\u3002" : "Antigravity session not found. Restore the original conversation on this computer before resuming.");
63186
+ if (!file3 || !fs17.existsSync(file3)) throw new Error(translating() ? "Antigravity \u4F1A\u8BDD\u4E0D\u5B58\u5728\u3002\u8BF7\u5728\u672C\u673A\u6062\u590D\u539F\u4F1A\u8BDD\u540E\u7EED\u63A5\u3002" : "Antigravity session not found. Restore the original conversation on this computer before resuming.");
63407
63187
  }
63408
63188
  const extra = resume ? ["--conversation", resume] : [];
63409
63189
  if (!namesFlag(argv, ["--output-format"])) extra.push("--output-format", "stream-json");
@@ -63448,7 +63228,7 @@ var ANTIGRAVITY = {
63448
63228
  const copy2 = locate(ANTIGRAVITY);
63449
63229
  if (!copy2) return [];
63450
63230
  const start = spawnable(copy2.file, ["models"], { env: copyEnv(copy2.file), stdio: ["ignore", "pipe", "ignore"], timeout: 15e3 });
63451
- const result = spawnSync4(start.command, start.args, { ...start.options, encoding: "utf8" });
63231
+ const result = spawnSync3(start.command, start.args, { ...start.options, encoding: "utf8" });
63452
63232
  return result.status === 0 ? antigravityModels(result.stdout ?? "").map((m) => m.id) : [];
63453
63233
  },
63454
63234
  env: () => ({ ...process.env }),
@@ -63462,10 +63242,10 @@ var ANTIGRAVITY = {
63462
63242
 
63463
63243
  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.`;
63464
63244
  const hash2 = createHash3("sha256").update(rule).digest("hex").slice(0, 16);
63465
- const root2 = path22.join(machineHome(), "prompts", `antigravity-${hash2}`);
63466
- const file3 = path22.join(root2, ".agents", "rules", "language.md");
63467
- fs19.mkdirSync(path22.dirname(file3), { recursive: true });
63468
- fs19.writeFileSync(file3, `---
63245
+ const root2 = path20.join(machineHome(), "prompts", `antigravity-${hash2}`);
63246
+ const file3 = path20.join(root2, ".agents", "rules", "language.md");
63247
+ fs17.mkdirSync(path20.dirname(file3), { recursive: true });
63248
+ fs17.writeFileSync(file3, `---
63469
63249
  trigger: always_on
63470
63250
  ---
63471
63251
 
@@ -63567,7 +63347,77 @@ function checkHarnesses(harnesses) {
63567
63347
  }
63568
63348
 
63569
63349
  // ../cli/src/lib/agent/harnesses/claude-code.ts
63570
- import path25 from "node:path";
63350
+ import path23 from "node:path";
63351
+
63352
+ // ../cli/src/lib/agent/retry.ts
63353
+ function readFailure(raw) {
63354
+ if (!raw || typeof raw !== "object") return;
63355
+ const { code, level, reason, source, retryAfterMs: retryAfterMs2 } = raw;
63356
+ if (typeof code !== "string" || !code || typeof reason !== "string" || level !== 1 && level !== 2 && level !== 3) return;
63357
+ return { code, level, reason, ...["validation", "provider", "harness", "invariant"].some((value) => value === source) ? { source } : {}, ...typeof retryAfterMs2 === "number" && retryAfterMs2 >= 0 ? { retryAfterMs: retryAfterMs2 } : {} };
63358
+ }
63359
+
63360
+ // ../cli/src/lib/agent/wire/failures.ts
63361
+ var ExecutionError = class extends Error {
63362
+ constructor(failure3) {
63363
+ super(failure3.reason);
63364
+ this.failure = failure3;
63365
+ }
63366
+ failure;
63367
+ };
63368
+ var NETWORK = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT", "ENETUNREACH", "EAI_AGAIN", "UND_ERR_SOCKET"]);
63369
+ var TEMPORARY_HTTP = /* @__PURE__ */ new Set([502, 503, 504, 529]);
63370
+ function executionFailure(error62) {
63371
+ if (error62 instanceof ExecutionError) return error62.failure;
63372
+ const code = str2(obj2(error62).code);
63373
+ const reason = error62 instanceof Error ? error62.message : String(error62);
63374
+ return {
63375
+ code: NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed",
63376
+ level: NETWORK.has(code) ? 2 : 3,
63377
+ source: "harness",
63378
+ reason
63379
+ };
63380
+ }
63381
+ function retryAfterMs(value, now = Date.now()) {
63382
+ if (typeof value !== "string") return;
63383
+ const header = value.trim();
63384
+ if (/^\d+$/.test(header)) return Math.min(Number(header) * 1e3, Number.MAX_SAFE_INTEGER);
63385
+ if (!/^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)) return;
63386
+ const date5 = Date.parse(header);
63387
+ if (Number.isFinite(date5)) return Math.max(0, date5 - now);
63388
+ }
63389
+ function providerFailure(error62, reason) {
63390
+ const info = obj2(error62);
63391
+ const status2 = typeof info.status === "number" ? info.status : void 0;
63392
+ const headers = obj2(info.headers);
63393
+ const wait = retryAfterMs(headers["retry-after"] ?? headers["Retry-After"]);
63394
+ const code = info.code ?? info.type;
63395
+ if (code === "session_not_found") return { code, source: "provider", level: 3, reason };
63396
+ if (status2 === 401 || status2 === 403 || ["authentication_error", "permission_error", "invalid_request_error"].includes(str2(code))) {
63397
+ return { code: "provider_refused", source: "provider", level: 3, reason };
63398
+ }
63399
+ if (code === "rate_limit_error") return { code: "rate_limited", source: "provider", level: 2, reason, retryAfterMs: wait };
63400
+ if (TEMPORARY_HTTP.has(status2 ?? 0) || code === "overloaded_error") return { code: "service_overloaded", source: "provider", level: 2, reason, retryAfterMs: wait };
63401
+ if (NETWORK.has(str2(code))) return { code: "connection_lost", source: "provider", level: 2, reason, retryAfterMs: wait };
63402
+ return { code: "provider_failed", source: "provider", level: 3, reason };
63403
+ }
63404
+ function codexFailure(raw, fallback) {
63405
+ const error62 = obj2(raw);
63406
+ const failure3 = readFailure(error62.wildcraneFailure);
63407
+ if (failure3?.source === "harness" || failure3?.source === "invariant") return failure3;
63408
+ const reason = str2(error62.message) || fallback;
63409
+ const info = error62.codexErrorInfo;
63410
+ if (info === "serverOverloaded") return providerFailure({ ...error62, type: "overloaded_error" }, reason);
63411
+ if (info === "rateLimitExceeded") return providerFailure({ ...error62, type: "rate_limit_error" }, reason);
63412
+ const types = obj2(info);
63413
+ for (const kind of ["httpConnectionFailed", "responseStreamConnectionFailed", "responseStreamDisconnected", "responseTooManyFailedAttempts"]) {
63414
+ if (!(kind in types)) continue;
63415
+ const status2 = obj2(types[kind]).httpStatusCode;
63416
+ if (typeof status2 === "number") return providerFailure({ ...error62, status: status2 }, reason);
63417
+ if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error62, code: "ECONNRESET" }, reason);
63418
+ }
63419
+ return providerFailure(error62, reason);
63420
+ }
63571
63421
 
63572
63422
  // ../cli/src/lib/agent/wire/claude-stream.ts
63573
63423
  var ARG_KEYS = ["command", "file_path", "path", "pattern", "description", "prompt", "query", "url"];
@@ -63585,13 +63435,13 @@ var TOOL_KINDS2 = {
63585
63435
  };
63586
63436
  var SUBAGENT_TOOLS = /* @__PURE__ */ new Set(["Agent", "Task"]);
63587
63437
  function targetOf2(input2) {
63588
- const args2 = obj(input2);
63589
- for (const key of ARG_KEYS) if (str(args2[key]).trim()) return str(args2[key]);
63438
+ const args2 = obj2(input2);
63439
+ for (const key of ARG_KEYS) if (str2(args2[key]).trim()) return str2(args2[key]);
63590
63440
  return "";
63591
63441
  }
63592
63442
  function resultText(raw) {
63593
63443
  if (typeof raw === "string") return raw;
63594
- return (Array.isArray(raw) ? raw : []).map((b) => str(obj(b).text)).filter(Boolean).join("\n");
63444
+ return (Array.isArray(raw) ? raw : []).map((b) => str2(obj2(b).text)).filter(Boolean).join("\n");
63595
63445
  }
63596
63446
  function eventModel(ev) {
63597
63447
  if (ev.type === "system" && ev.subtype === "init" && typeof ev.model === "string") {
@@ -63614,29 +63464,29 @@ var USER_FIXES = [
63614
63464
  [/usage limit|credit balance is too low|quota/i, "Wait for the usage limit to reset, or add credit, then press Resume."]
63615
63465
  ];
63616
63466
  function failedWith(ev) {
63617
- const errors = Array.isArray(ev.errors) ? ev.errors.map(str).filter(Boolean) : [];
63467
+ const errors = Array.isArray(ev.errors) ? ev.errors.map(str2).filter(Boolean) : [];
63618
63468
  if (errors.length) return errors.join("; ");
63619
- const named = str(ev.subtype) || str(ev.terminal_reason);
63469
+ const named = str2(ev.subtype) || str2(ev.terminal_reason);
63620
63470
  if (named && named !== "error" && named !== "success") return named;
63621
- return str(ev.result).trim() || "the agent reported the session failed";
63471
+ return str2(ev.result).trim() || "the agent reported the session failed";
63622
63472
  }
63623
63473
  function denials(ev) {
63624
63474
  const list3 = Array.isArray(ev.permission_denials) ? ev.permission_denials : [];
63625
- const names = [...new Set(list3.map((raw) => str(obj(raw).tool_name)).filter(Boolean))];
63475
+ const names = [...new Set(list3.map((raw) => str2(obj2(raw).tool_name)).filter(Boolean))];
63626
63476
  if (!names.length) return "";
63627
63477
  return `[refused] ${list3.length} tool call${list3.length === 1 ? "" : "s"} were not allowed: ${names.join(", ")}
63628
63478
  `;
63629
63479
  }
63630
63480
  function promptSize(raw) {
63631
- const u = obj(raw);
63632
- const size = num(u.input_tokens) + num(u.cache_creation_input_tokens) + num(u.cache_read_input_tokens);
63481
+ const u = obj2(raw);
63482
+ const size = num2(u.input_tokens) + num2(u.cache_creation_input_tokens) + num2(u.cache_read_input_tokens);
63633
63483
  return size > 0 ? size : void 0;
63634
63484
  }
63635
63485
  function windowOf(raw, model) {
63636
- const entries = obj(raw);
63486
+ const entries = obj2(raw);
63637
63487
  const names = Object.keys(entries);
63638
63488
  const name = model && names.includes(model) ? model : names.length === 1 ? names[0] : void 0;
63639
- return name ? num(obj(entries[name]).contextWindow) || void 0 : void 0;
63489
+ return name ? num2(obj2(entries[name]).contextWindow) || void 0 : void 0;
63640
63490
  }
63641
63491
  function createStreamRenderer() {
63642
63492
  let final;
@@ -63666,8 +63516,8 @@ function createStreamRenderer() {
63666
63516
  if (!ev) return `${line}
63667
63517
  `;
63668
63518
  if (model === void 0) model = eventModel(ev);
63669
- if (str(ev.parent_tool_use_id)) return "";
63670
- if (ev.type === "assistant" || ev.type === "stream_event" && obj(ev.event).type === "content_block_delta") events.progress();
63519
+ if (str2(ev.parent_tool_use_id)) return "";
63520
+ if (ev.type === "assistant" || ev.type === "stream_event" && obj2(ev.event).type === "content_block_delta") events.progress();
63671
63521
  switch (ev.type) {
63672
63522
  case "assistant": {
63673
63523
  apiFailure = typeof ev.error === "string" ? providerFailure({ type: ev.error }, "Claude could not complete the request.") : void 0;
@@ -63687,30 +63537,30 @@ function createStreamRenderer() {
63687
63537
  out.push(`\u23FA ${b.name}${argHint(b.input, ARG_KEYS)}
63688
63538
  `);
63689
63539
  if (SUBAGENT_TOOLS.has(b.name)) {
63690
- const input2 = obj(b.input);
63691
- subagents.set(str(b.id), false);
63692
- if (input2.run_in_background === true) detached.add(str(b.id));
63693
- events.subagent(str(b.id), str(input2.description) || str(input2.subagent_type) || b.name);
63540
+ const input2 = obj2(b.input);
63541
+ subagents.set(str2(b.id), false);
63542
+ if (input2.run_in_background === true) detached.add(str2(b.id));
63543
+ events.subagent(str2(b.id), str2(input2.description) || str2(input2.subagent_type) || b.name);
63694
63544
  } else if (b.name === "TodoWrite") {
63695
- plans.add(str(b.id));
63696
- events.plan(obj(b.input).todos);
63545
+ plans.add(str2(b.id));
63546
+ events.plan(obj2(b.input).todos);
63697
63547
  } else {
63698
- events.toolCall(str(b.id), b.name, TOOL_KINDS2[b.name] ?? "other", targetOf2(b.input));
63548
+ events.toolCall(str2(b.id), b.name, TOOL_KINDS2[b.name] ?? "other", targetOf2(b.input));
63699
63549
  }
63700
63550
  }
63701
63551
  }
63702
63552
  return out.join("");
63703
63553
  }
63704
63554
  case "user": {
63705
- const content = obj(ev.message).content;
63555
+ const content = obj2(ev.message).content;
63706
63556
  for (const raw of Array.isArray(content) ? content : []) {
63707
- const b = obj(raw);
63708
- if (b.type !== "tool_result" || plans.has(str(b.tool_use_id))) continue;
63709
- if (subagents.has(str(b.tool_use_id))) {
63710
- if (!detached.has(str(b.tool_use_id))) endSubagent(str(b.tool_use_id), b.is_error === true ? "failed" : "completed");
63557
+ const b = obj2(raw);
63558
+ if (b.type !== "tool_result" || plans.has(str2(b.tool_use_id))) continue;
63559
+ if (subagents.has(str2(b.tool_use_id))) {
63560
+ if (!detached.has(str2(b.tool_use_id))) endSubagent(str2(b.tool_use_id), b.is_error === true ? "failed" : "completed");
63711
63561
  continue;
63712
63562
  }
63713
- events.toolResult(str(b.tool_use_id), b.is_error === true ? "failed" : "completed", resultText(b.content));
63563
+ events.toolResult(str2(b.tool_use_id), b.is_error === true ? "failed" : "completed", resultText(b.content));
63714
63564
  }
63715
63565
  return "";
63716
63566
  }
@@ -63738,12 +63588,12 @@ function createStreamRenderer() {
63738
63588
  }
63739
63589
  case "system":
63740
63590
  if (ev.subtype === "background_tasks_changed" && Array.isArray(ev.tasks)) background = ev.tasks.length;
63741
- if (ev.subtype === "task_started" && ev.is_backgrounded === true) backgrounded.add(str(ev.task_id));
63742
- if (ev.subtype === "task_notification" && subagents.has(str(ev.tool_use_id))) {
63743
- endSubagent(str(ev.tool_use_id), str(ev.status) === "completed" ? "completed" : "failed");
63591
+ if (ev.subtype === "task_started" && ev.is_backgrounded === true) backgrounded.add(str2(ev.task_id));
63592
+ if (ev.subtype === "task_notification" && subagents.has(str2(ev.tool_use_id))) {
63593
+ endSubagent(str2(ev.tool_use_id), str2(ev.status) === "completed" ? "completed" : "failed");
63744
63594
  }
63745
- if (ev.subtype === "task_notification" && backgrounded.has(str(ev.task_id)) && str(ev.summary)) {
63746
- return `\u23FA ${str(ev.summary)}
63595
+ if (ev.subtype === "task_notification" && backgrounded.has(str2(ev.task_id)) && str2(ev.summary)) {
63596
+ return `\u23FA ${str2(ev.summary)}
63747
63597
  `;
63748
63598
  }
63749
63599
  return "";
@@ -63770,10 +63620,10 @@ function usageOf2(raw) {
63770
63620
  if (!raw || typeof raw !== "object") return void 0;
63771
63621
  const u = raw;
63772
63622
  const parsed = {
63773
- input: num(u.input_tokens),
63774
- cacheCreation: num(u.cache_creation_input_tokens),
63775
- cacheRead: num(u.cache_read_input_tokens),
63776
- output: num(u.output_tokens)
63623
+ input: num2(u.input_tokens),
63624
+ cacheCreation: num2(u.cache_creation_input_tokens),
63625
+ cacheRead: num2(u.cache_read_input_tokens),
63626
+ output: num2(u.output_tokens)
63777
63627
  };
63778
63628
  return parsed.input + parsed.cacheCreation + parsed.cacheRead + parsed.output > 0 ? parsed : void 0;
63779
63629
  }
@@ -63968,13 +63818,13 @@ var imageSafeText = (text2) => text2.replace(/data:image\/[a-z0-9.+-]+;base64,[A
63968
63818
  function renderStarted(item) {
63969
63819
  switch (item.type) {
63970
63820
  case "command_execution":
63971
- return `\u23FA Command${hint(str(item.command))}
63821
+ return `\u23FA Command${hint(str2(item.command))}
63972
63822
  `;
63973
63823
  case "mcp_tool_call":
63974
- return `\u23FA ${str(item.server)}.${str(item.tool)}
63824
+ return `\u23FA ${str2(item.server)}.${str2(item.tool)}
63975
63825
  `;
63976
63826
  case "web_search":
63977
- return `\u23FA WebSearch${hint(str(item.query))}
63827
+ return `\u23FA WebSearch${hint(str2(item.query))}
63978
63828
  `;
63979
63829
  default:
63980
63830
  return "";
@@ -63983,7 +63833,7 @@ function renderStarted(item) {
63983
63833
  function renderCompleted(item) {
63984
63834
  switch (item.type) {
63985
63835
  case "agent_message": {
63986
- const said = imageSafeText(str(item.text)).trim();
63836
+ const said = imageSafeText(str2(item.text)).trim();
63987
63837
  return said ? `${said}
63988
63838
 
63989
63839
  ` : "";
@@ -63991,18 +63841,18 @@ function renderCompleted(item) {
63991
63841
  case "file_change": {
63992
63842
  const changes = Array.isArray(item.changes) ? item.changes : [];
63993
63843
  return changes.map((raw) => {
63994
- const change = obj(raw);
63995
- const path36 = str(change.path);
63996
- return path36 ? `\u23FA ${str(change.kind) || "change"}(${path36})
63844
+ const change = obj2(raw);
63845
+ const path36 = str2(change.path);
63846
+ return path36 ? `\u23FA ${str2(change.kind) || "change"}(${path36})
63997
63847
  ` : "";
63998
63848
  }).join("");
63999
63849
  }
64000
63850
  case "error":
64001
- return `[error] ${str(item.message)}
63851
+ return `[error] ${str2(item.message)}
64002
63852
  `;
64003
63853
  case "mcp_tool_call": {
64004
- const error62 = str(obj(item.error).message);
64005
- return error62 ? `[MCP ${str(item.server)}.${str(item.tool)}] ${error62}
63854
+ const error62 = str2(obj2(item.error).message);
63855
+ return error62 ? `[MCP ${str2(item.server)}.${str2(item.tool)}] ${error62}
64006
63856
  ` : "";
64007
63857
  }
64008
63858
  default:
@@ -64017,47 +63867,47 @@ function unwrapShell(command) {
64017
63867
  function callOf(item) {
64018
63868
  switch (item.type) {
64019
63869
  case "command_execution":
64020
- return { title: "Command", target: unwrapShell(str(item.command)) };
63870
+ return { title: "Command", target: unwrapShell(str2(item.command)) };
64021
63871
  case "mcp_tool_call":
64022
- return { title: `${str(item.server)}.${str(item.tool)}`, target: "" };
63872
+ return { title: `${str2(item.server)}.${str2(item.tool)}`, target: "" };
64023
63873
  case "web_search":
64024
- return { title: "WebSearch", target: str(item.query) };
63874
+ return { title: "WebSearch", target: str2(item.query) };
64025
63875
  default: {
64026
- const changes = (Array.isArray(item.changes) ? item.changes : []).map((c) => str(obj(c).path)).filter(Boolean);
63876
+ const changes = (Array.isArray(item.changes) ? item.changes : []).map((c) => str2(obj2(c).path)).filter(Boolean);
64027
63877
  return { title: "Edit", target: changes.join(", ") };
64028
63878
  }
64029
63879
  }
64030
63880
  }
64031
63881
  function callResult(item) {
64032
- if (item.type === "command_execution") return str(item.aggregated_output);
63882
+ if (item.type === "command_execution") return str2(item.aggregated_output);
64033
63883
  if (item.type === "mcp_tool_call") {
64034
- const error62 = str(obj(item.error).message);
63884
+ const error62 = str2(obj2(item.error).message);
64035
63885
  if (error62) return error62;
64036
- const content = obj(item.result).content;
64037
- return (Array.isArray(content) ? content : []).map((b) => imageSafeText(str(obj(b).text))).filter(Boolean).join("\n");
63886
+ const content = obj2(item.result).content;
63887
+ return (Array.isArray(content) ? content : []).map((b) => imageSafeText(str2(obj2(b).text))).filter(Boolean).join("\n");
64038
63888
  }
64039
63889
  if (item.type === "file_change") {
64040
- return (Array.isArray(item.changes) ? item.changes : []).map((c) => `${str(obj(c).kind) || "change"} ${str(obj(c).path)}`).join("\n");
63890
+ return (Array.isArray(item.changes) ? item.changes : []).map((c) => `${str2(obj2(c).kind) || "change"} ${str2(obj2(c).path)}`).join("\n");
64041
63891
  }
64042
63892
  return "";
64043
63893
  }
64044
63894
  function itemEvents(events, started, item, done) {
64045
- const id2 = str(item.id);
63895
+ const id2 = str2(item.id);
64046
63896
  if (item.type === "agent_message") {
64047
- if (done) events.message(imageSafeText(str(item.text)));
63897
+ if (done) events.message(imageSafeText(str2(item.text)));
64048
63898
  return;
64049
63899
  }
64050
63900
  if (item.type === "todo_list") {
64051
63901
  const items = Array.isArray(item.items) ? item.items : [];
64052
- events.plan(items.map(obj).map((t2) => ({ content: str(t2.text), status: t2.completed === true ? "completed" : "pending" })));
63902
+ events.plan(items.map(obj2).map((t2) => ({ content: str2(t2.text), status: t2.completed === true ? "completed" : "pending" })));
64053
63903
  return;
64054
63904
  }
64055
63905
  if (item.type === "error") {
64056
- if (done) events.log(`${str(item.message)}
63906
+ if (done) events.log(`${str2(item.message)}
64057
63907
  `);
64058
63908
  return;
64059
63909
  }
64060
- const kind = CALLS[str(item.type)];
63910
+ const kind = CALLS[str2(item.type)];
64061
63911
  if (!kind) return;
64062
63912
  if (!started.has(id2)) {
64063
63913
  started.add(id2);
@@ -64086,23 +63936,23 @@ function createCodexStreamRenderer(carried = false) {
64086
63936
  const collabItems = /* @__PURE__ */ new Set();
64087
63937
  const collab = (item, done) => {
64088
63938
  if (item.type !== "collab_tool_call") return;
64089
- const key = `${str(item.id)}:${done}`;
63939
+ const key = `${str2(item.id)}:${done}`;
64090
63940
  if (collabItems.has(key)) return;
64091
63941
  collabItems.add(key);
64092
- for (const [id2, raw] of Object.entries(obj(item.agents_states))) {
64093
- const state = obj(raw);
64094
- const status2 = str(state.status);
63942
+ for (const [id2, raw] of Object.entries(obj2(item.agents_states))) {
63943
+ const state = obj2(raw);
63944
+ const status2 = str2(state.status);
64095
63945
  if (!["pending_init", "running", "completed", "interrupted", "errored", "shutdown", "not_found"].includes(status2)) continue;
64096
63946
  const previous = background.results().find((t2) => t2.id === id2);
64097
63947
  if (["shutdown", "not_found"].includes(status2) && previous && previous.status !== "running") continue;
64098
63948
  if (!subagents.has(id2)) {
64099
63949
  subagents.add(id2);
64100
- events.subagent(`agent:${id2}`, str(item.prompt) || "Agent");
63950
+ events.subagent(`agent:${id2}`, str2(item.prompt) || "Agent");
64101
63951
  }
64102
63952
  const running = status2 === "pending_init" || status2 === "running";
64103
63953
  const failed = !running && status2 !== "completed";
64104
- if (background.update(id2, running ? "running" : failed ? "failed" : "completed", str(state.message)) && !running) {
64105
- events.toolResult(`agent:${id2}`, failed ? "failed" : "completed", str(state.message));
63954
+ if (background.update(id2, running ? "running" : failed ? "failed" : "completed", str2(state.message)) && !running) {
63955
+ events.toolResult(`agent:${id2}`, failed ? "failed" : "completed", str2(state.message));
64106
63956
  }
64107
63957
  }
64108
63958
  };
@@ -64129,34 +63979,34 @@ function createCodexStreamRenderer(carried = false) {
64129
63979
  `;
64130
63980
  switch (ev.type) {
64131
63981
  case "thread.started":
64132
- if (!threadId) threadId = str(ev.thread_id).trim() || void 0;
63982
+ if (!threadId) threadId = str2(ev.thread_id).trim() || void 0;
64133
63983
  return "";
64134
63984
  case "item.started":
64135
- collab(obj(ev.item), false);
64136
- itemEvents(events, started, obj(ev.item), false);
64137
- return renderStarted(obj(ev.item));
63985
+ collab(obj2(ev.item), false);
63986
+ itemEvents(events, started, obj2(ev.item), false);
63987
+ return renderStarted(obj2(ev.item));
64138
63988
  case "item.updated":
64139
- if (obj(ev.item).type === "todo_list") itemEvents(events, started, obj(ev.item), false);
63989
+ if (obj2(ev.item).type === "todo_list") itemEvents(events, started, obj2(ev.item), false);
64140
63990
  return "";
64141
63991
  case "item.completed": {
64142
- const item = obj(ev.item);
63992
+ const item = obj2(ev.item);
64143
63993
  collab(item, true);
64144
- if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str(item.tool))) {
64145
- const content = obj(item.result).content;
63994
+ if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str2(item.tool))) {
63995
+ const content = obj2(item.result).content;
64146
63996
  for (const block of Array.isArray(content) ? content : []) {
64147
- const b = obj(block);
64148
- const audience = obj(b.annotations).audience;
63997
+ const b = obj2(block);
63998
+ const audience = obj2(b.annotations).audience;
64149
63999
  if (Array.isArray(audience) && !audience.includes("user")) continue;
64150
- if (b.type === "resource_link" && str(b.uri).startsWith("file:") && /^image\/(png|jpeg|gif|webp)$/.test(str(b.mimeType)) && pictures.length < 100) {
64151
- pictures.push({ type: "image", path: str(b.uri), mime: str(b.mimeType), registered: true });
64000
+ if (b.type === "resource_link" && str2(b.uri).startsWith("file:") && /^image\/(png|jpeg|gif|webp)$/.test(str2(b.mimeType)) && pictures.length < 100) {
64001
+ pictures.push({ type: "image", path: str2(b.uri), mime: str2(b.mimeType), registered: true });
64152
64002
  }
64153
- if (b.type === "image" && pictures.length < 100) pictures.push(str(b.data).length <= 14e7 ? { type: "image", data: str(b.data), mime: str(b.mimeType) } : { type: "image" });
64003
+ if (b.type === "image" && pictures.length < 100) pictures.push(str2(b.data).length <= 14e7 ? { type: "image", data: str2(b.data), mime: str2(b.mimeType) } : { type: "image" });
64154
64004
  }
64155
64005
  }
64156
64006
  if (item.type === "image_generation" && typeof item.path === "string") pictures.push({ type: "image", path: item.path, registered: true });
64157
64007
  itemEvents(events, started, item, true);
64158
64008
  if (item.type === "agent_message") {
64159
- const said = str(item.text).trim();
64009
+ const said = str2(item.text).trim();
64160
64010
  if (item.phase !== "commentary" && (said || pictures.length)) final = said;
64161
64011
  }
64162
64012
  return renderCompleted(item);
@@ -64167,14 +64017,14 @@ function createCodexStreamRenderer(carried = false) {
64167
64017
  return "";
64168
64018
  // 最终失败保留;连接提示只在没有后续成功完成时才作为失败。
64169
64019
  case "turn.failed": {
64170
- const said = str(obj(ev.error).message) || failure3?.reason || "Codex execution failed.";
64020
+ const said = str2(obj2(ev.error).message) || failure3?.reason || "Codex execution failed.";
64171
64021
  failure3 = codexFailure(ev.error, said);
64172
64022
  events.error(said);
64173
64023
  return `[error] ${said}
64174
64024
  `;
64175
64025
  }
64176
64026
  case "error": {
64177
- const said = str(ev.message);
64027
+ const said = str2(ev.message);
64178
64028
  if (ev.willRetry !== true && ev.will_retry !== true && said) failure3 = codexFailure(ev.error ?? ev, said);
64179
64029
  events.log(`[Codex] ${said}
64180
64030
  `);
@@ -64266,14 +64116,14 @@ function readIndex() {
64266
64116
  } catch {
64267
64117
  continue;
64268
64118
  }
64269
- const sessionId = str(record2.sessionId).trim();
64119
+ const sessionId = str2(record2.sessionId).trim();
64270
64120
  if (!sessionId) continue;
64271
64121
  if (record2.deleted === true) {
64272
64122
  entries.delete(sessionId);
64273
64123
  continue;
64274
64124
  }
64275
- const sessionDir = str(record2.sessionDir).trim();
64276
- const workDir = str(record2.workDir).trim();
64125
+ const sessionDir = str2(record2.sessionDir).trim();
64126
+ const workDir = str2(record2.workDir).trim();
64277
64127
  if (sessionDir && workDir) entries.set(sessionId, { sessionId, sessionDir, workDir });
64278
64128
  }
64279
64129
  return entries;
@@ -64329,14 +64179,14 @@ function readKimiRunFacts(sessionId) {
64329
64179
  continue;
64330
64180
  }
64331
64181
  if (record2.type !== "usage.record") continue;
64332
- model ??= str(record2.model).trim() || void 0;
64333
- const usage = obj(record2.usage);
64334
- total.input += num(usage.inputOther);
64335
- total.cacheCreation += num(usage.inputCacheCreation);
64336
- total.cacheRead += num(usage.inputCacheRead);
64337
- total.output += num(usage.output);
64182
+ model ??= str2(record2.model).trim() || void 0;
64183
+ const usage = obj2(record2.usage);
64184
+ total.input += num2(usage.inputOther);
64185
+ total.cacheCreation += num2(usage.inputCacheCreation);
64186
+ total.cacheRead += num2(usage.inputCacheRead);
64187
+ total.output += num2(usage.output);
64338
64188
  if (main) {
64339
- holding = num(usage.inputOther) + num(usage.inputCacheCreation) + num(usage.inputCacheRead);
64189
+ holding = num2(usage.inputOther) + num2(usage.inputCacheCreation) + num2(usage.inputCacheRead);
64340
64190
  }
64341
64191
  }
64342
64192
  }
@@ -64353,7 +64203,7 @@ function readKimiRunFacts(sessionId) {
64353
64203
  // ../cli/src/lib/agent/wire/kimi-stream.ts
64354
64204
  var ARG_KEYS2 = ["command", "path", "pattern", "query", "url", "prompt", "prompt_template", "description"];
64355
64205
  function callArgs(raw) {
64356
- const text2 = str(raw);
64206
+ const text2 = str2(raw);
64357
64207
  if (!text2.trim()) return {};
64358
64208
  try {
64359
64209
  return JSON.parse(text2);
@@ -64372,16 +64222,16 @@ var kindOf = (name) => TOOL_KINDS3.find(([re]) => re.test(name))?.[1] ?? "other"
64372
64222
  function toolCalls(row) {
64373
64223
  const calls = Array.isArray(row.tool_calls) ? row.tool_calls : [];
64374
64224
  return calls.map((raw) => {
64375
- const call2 = obj(raw);
64376
- const fn = obj(call2.function);
64377
- const name = str(fn.name) || "tool";
64225
+ const call2 = obj2(raw);
64226
+ const fn = obj2(call2.function);
64227
+ const name = str2(fn.name) || "tool";
64378
64228
  return `\u23FA ${name}${argHint(callArgs(fn.arguments), ARG_KEYS2)}
64379
64229
  `;
64380
64230
  }).join("");
64381
64231
  }
64382
64232
  function retry(row) {
64383
- const why = str(row.error_message) || str(row.error_name) || "the provider failed";
64384
- const attempt = `${num(row.next_attempt)}/${num(row.max_attempts)}`;
64233
+ const why = str2(row.error_message) || str2(row.error_name) || "the provider failed";
64234
+ const attempt = `${num2(row.next_attempt)}/${num2(row.max_attempts)}`;
64385
64235
  return `[retry ${attempt}] ${why}
64386
64236
  `;
64387
64237
  }
@@ -64410,18 +64260,18 @@ function createKimiStreamRenderer(cwd, resumeId) {
64410
64260
  switch (row.role) {
64411
64261
  case "assistant": {
64412
64262
  events.progress();
64413
- const said = str(row.content).trim();
64263
+ const said = str2(row.content).trim();
64414
64264
  if (said) final = said;
64415
64265
  if (said) events.message(said);
64416
64266
  for (const raw of Array.isArray(row.tool_calls) ? row.tool_calls : []) {
64417
- const call2 = obj(raw);
64418
- const name = str(obj(call2.function).name) || "tool";
64419
- const args2 = obj(callArgs(obj(call2.function).arguments));
64267
+ const call2 = obj2(raw);
64268
+ const name = str2(obj2(call2.function).name) || "tool";
64269
+ const args2 = obj2(callArgs(obj2(call2.function).arguments));
64420
64270
  if (name === "Agent") {
64421
- subagents.add(str(call2.id));
64422
- events.subagent(str(call2.id), str(args2.description) || name);
64271
+ subagents.add(str2(call2.id));
64272
+ events.subagent(str2(call2.id), str2(args2.description) || name);
64423
64273
  } else {
64424
- events.toolCall(str(call2.id), name, kindOf(name), ARG_KEYS2.map((k) => str(args2[k])).find((v) => v.trim()));
64274
+ events.toolCall(str2(call2.id), name, kindOf(name), ARG_KEYS2.map((k) => str2(args2[k])).find((v) => v.trim()));
64425
64275
  }
64426
64276
  }
64427
64277
  return `${said ? `${said}
@@ -64429,11 +64279,11 @@ function createKimiStreamRenderer(cwd, resumeId) {
64429
64279
  ` : ""}${toolCalls(row)}`;
64430
64280
  }
64431
64281
  case "meta":
64432
- if (row.type === "session.resume_hint") sessionId ??= str(row.session_id).trim() || void 0;
64282
+ if (row.type === "session.resume_hint") sessionId ??= str2(row.session_id).trim() || void 0;
64433
64283
  return row.type === "turn.step.retrying" ? retry(row) : "";
64434
64284
  case "tool": {
64435
- const id2 = str(row.tool_call_id);
64436
- const text2 = str(row.content);
64285
+ const id2 = str2(row.tool_call_id);
64286
+ const text2 = str2(row.content);
64437
64287
  if (subagents.delete(id2)) events.toolResult(id2, /^status: completed$/m.test(text2) ? "completed" : "failed", "");
64438
64288
  else events.toolResult(id2, "completed", text2);
64439
64289
  return "";
@@ -64473,16 +64323,16 @@ function createKimiStreamRenderer(cwd, resumeId) {
64473
64323
  }
64474
64324
 
64475
64325
  // ../cli/src/lib/agent/wire/acp-cost.ts
64476
- import fs20 from "node:fs";
64477
- import path23 from "node:path";
64326
+ import fs18 from "node:fs";
64327
+ import path21 from "node:path";
64478
64328
  import { createHash as createHash4 } from "node:crypto";
64479
64329
  function acpCostFile(tool, cwd, session) {
64480
64330
  const key = createHash4("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
64481
- return path23.join(machineHome(), "usage", "acp", `${key}.json`);
64331
+ return path21.join(machineHome(), "usage", "acp", `${key}.json`);
64482
64332
  }
64483
64333
  function readAcpCost(file3) {
64484
64334
  try {
64485
- const n = JSON.parse(fs20.readFileSync(file3, "utf8"));
64335
+ const n = JSON.parse(fs18.readFileSync(file3, "utf8"));
64486
64336
  return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
64487
64337
  } catch {
64488
64338
  return void 0;
@@ -64491,16 +64341,115 @@ function readAcpCost(file3) {
64491
64341
  function saveAcpCost(file3, cost) {
64492
64342
  if (cost === void 0) return;
64493
64343
  try {
64494
- fs20.mkdirSync(path23.dirname(file3), { recursive: true, mode: 448 });
64344
+ fs18.mkdirSync(path21.dirname(file3), { recursive: true, mode: 448 });
64495
64345
  const tmp = `${file3}.${process.pid}.tmp`;
64496
- fs20.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
64497
- fs20.renameSync(tmp, file3);
64346
+ fs18.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
64347
+ fs18.renameSync(tmp, file3);
64498
64348
  } catch {
64499
64349
  }
64500
64350
  }
64501
64351
 
64352
+ // ../cli/src/lib/shared/conversation.ts
64353
+ var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
64354
+ function bounded(work, ms, reason) {
64355
+ return new Promise((resolve2, reject) => {
64356
+ const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
64357
+ work.then((value) => {
64358
+ clearTimeout(timer);
64359
+ resolve2(value);
64360
+ }, (error62) => {
64361
+ clearTimeout(timer);
64362
+ reject(error62);
64363
+ });
64364
+ });
64365
+ }
64366
+
64502
64367
  // ../cli/src/lib/agent/wire/acp.ts
64503
- import fs21 from "node:fs";
64368
+ import fs19 from "node:fs";
64369
+
64370
+ // ../cli/src/lib/agent/wire/rpc.ts
64371
+ var RpcError = class extends Error {
64372
+ constructor(message, code, data) {
64373
+ super(message);
64374
+ this.code = code;
64375
+ this.data = data;
64376
+ this.name = "RpcError";
64377
+ }
64378
+ code;
64379
+ data;
64380
+ };
64381
+ function connect(stdout, stdin, onCall, dialect = {}) {
64382
+ let buf = "";
64383
+ let nextId = 1;
64384
+ let gone;
64385
+ const waiting = /* @__PURE__ */ new Map();
64386
+ const send2 = (msg) => {
64387
+ if (gone) return;
64388
+ try {
64389
+ stdin.write(`${JSON.stringify(dialect.jsonrpc ? { jsonrpc: "2.0", ...msg } : msg)}
64390
+ `);
64391
+ } catch {
64392
+ }
64393
+ };
64394
+ const closed = (why) => {
64395
+ if (gone) return;
64396
+ gone = why;
64397
+ for (const { fail } of waiting.values()) fail(why);
64398
+ waiting.clear();
64399
+ };
64400
+ stdout.on("data", (chunk) => {
64401
+ buf += chunk.toString();
64402
+ const lines = buf.split("\n");
64403
+ buf = lines.pop() ?? "";
64404
+ for (const line of lines) {
64405
+ if (!line.trim()) continue;
64406
+ let msg;
64407
+ try {
64408
+ msg = JSON.parse(line);
64409
+ } catch {
64410
+ continue;
64411
+ }
64412
+ if (msg.method) {
64413
+ onCall(msg);
64414
+ continue;
64415
+ }
64416
+ if (msg.id === void 0) continue;
64417
+ const pending = waiting.get(String(msg.id));
64418
+ if (!pending) continue;
64419
+ waiting.delete(String(msg.id));
64420
+ if (msg.error) {
64421
+ const said = [str2(msg.error.message), str2(obj2(msg.error.data).message)].filter(Boolean).join(": ");
64422
+ pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code, msg.error.data));
64423
+ } else pending.ok(obj2(msg.result));
64424
+ }
64425
+ });
64426
+ stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", level: 2, reason: "The agent closed the connection." })));
64427
+ stdout.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
64428
+ stdin.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
64429
+ return {
64430
+ /** Ask the agent something. Rejects with the agent's own words when it says no. */
64431
+ call(method, params) {
64432
+ if (gone) return Promise.reject(gone);
64433
+ const id2 = dialect.stringIds ? String(nextId++) : nextId++;
64434
+ return new Promise((ok, fail) => {
64435
+ waiting.set(String(id2), { ok, fail });
64436
+ send2({ id: id2, method, params });
64437
+ });
64438
+ },
64439
+ notify(method, params = {}) {
64440
+ send2({ method, params });
64441
+ },
64442
+ /** Answer something the agent asked us. */
64443
+ reply(id2, result) {
64444
+ send2({ id: id2, result });
64445
+ },
64446
+ /** Say we can't. Sent for anything we never offered to do, so the agent gets an answer
64447
+ * rather than waiting on one forever. */
64448
+ refuse(id2, message) {
64449
+ send2({ id: id2, error: { code: -32601, message } });
64450
+ }
64451
+ };
64452
+ }
64504
64453
 
64505
64454
  // ../cli/src/lib/agent/wire/tail.ts
64506
64455
  function createTail(log) {
@@ -64552,8 +64501,8 @@ function createTail(log) {
64552
64501
  // ../cli/package.json
64553
64502
  var package_default = {
64554
64503
  name: "wildcrane",
64555
- version: "0.11.78",
64556
- akbContract: 25,
64504
+ version: "0.11.79",
64505
+ akbContract: 26,
64557
64506
  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.",
64558
64507
  keywords: [
64559
64508
  "kanban",
@@ -64629,33 +64578,33 @@ var CLIENT_CAPABILITIES = {
64629
64578
  };
64630
64579
  function whereHint(update3, title) {
64631
64580
  const locations = Array.isArray(update3.locations) ? update3.locations : [];
64632
- const path36 = str(obj(locations[0]).path);
64581
+ const path36 = str2(obj2(locations[0]).path);
64633
64582
  return path36 && !title.includes(path36) ? hint(path36) : "";
64634
64583
  }
64635
64584
  function saidBy(update3) {
64636
64585
  const content = Array.isArray(update3.content) ? update3.content : [];
64637
64586
  for (const raw of content) {
64638
- const part = obj(raw);
64639
- const text2 = str(obj(part.content).text) || str(part.text);
64587
+ const part = obj2(raw);
64588
+ const text2 = str2(obj2(part.content).text) || str2(part.text);
64640
64589
  if (text2.trim()) return text2.trim();
64641
64590
  }
64642
64591
  return "";
64643
64592
  }
64644
64593
  function modelOf(answer) {
64645
- const current2 = str(obj(answer.models).currentModelId).trim();
64594
+ const current2 = str2(obj2(answer.models).currentModelId).trim();
64646
64595
  if (current2) return modelsIn2(answer).find((m) => m.modelId === current2)?.name ?? current2;
64647
64596
  const list3 = Array.isArray(answer.configOptions) ? answer.configOptions : [];
64648
64597
  for (const raw of list3) {
64649
- const option = obj(raw);
64650
- if (option.id === "model") return str(option.currentValue).trim() || void 0;
64598
+ const option = obj2(raw);
64599
+ if (option.id === "model") return str2(option.currentValue).trim() || void 0;
64651
64600
  }
64652
64601
  return void 0;
64653
64602
  }
64654
64603
  function modelsIn2(answer) {
64655
- const list3 = obj(answer.models).availableModels;
64656
- return (Array.isArray(list3) ? list3 : []).map(obj).flatMap((m) => {
64657
- const modelId = str(m.modelId);
64658
- return modelId ? [{ modelId, name: str(m.name) || modelId }] : [];
64604
+ const list3 = obj2(answer.models).availableModels;
64605
+ return (Array.isArray(list3) ? list3 : []).map(obj2).flatMap((m) => {
64606
+ const modelId = str2(m.modelId);
64607
+ return modelId ? [{ modelId, name: str2(m.name) || modelId }] : [];
64659
64608
  });
64660
64609
  }
64661
64610
  function pickedModel(answer, wanted) {
@@ -64663,16 +64612,16 @@ function pickedModel(answer, wanted) {
64663
64612
  return list3.find((m) => m.modelId === wanted) ?? list3.find((m) => m.name === wanted || m.modelId.split("[")[0] === wanted);
64664
64613
  }
64665
64614
  function usageOf3(value, grossInput = false) {
64666
- const usage = obj(value);
64615
+ const usage = obj2(value);
64667
64616
  if (!Object.keys(usage).length) return void 0;
64668
- const cacheCreation = num(usage.cachedWriteTokens) + num(usage.cacheCreationTokens);
64669
- const cacheRead = num(usage.cachedReadTokens);
64670
- const input2 = num(usage.inputTokens);
64617
+ const cacheCreation = num2(usage.cachedWriteTokens) + num2(usage.cacheCreationTokens);
64618
+ const cacheRead = num2(usage.cachedReadTokens);
64619
+ const input2 = num2(usage.inputTokens);
64671
64620
  const counts = {
64672
64621
  input: grossInput ? Math.max(input2 - cacheRead - cacheCreation, 0) : input2,
64673
64622
  cacheCreation,
64674
64623
  cacheRead,
64675
- output: num(usage.outputTokens)
64624
+ output: num2(usage.outputTokens)
64676
64625
  };
64677
64626
  const sum = counts.input + counts.cacheCreation + counts.cacheRead + counts.output;
64678
64627
  return sum > 0 ? counts : void 0;
@@ -64680,13 +64629,13 @@ function usageOf3(value, grossInput = false) {
64680
64629
  var RESTARTED = "[board] that conversation is gone \u2014 the task was restarted in a new session\n";
64681
64630
  async function newSession(rpc, cwd, mcpServers) {
64682
64631
  const opened = await rpc.call("session/new", { cwd, mcpServers });
64683
- const sessionId = str(opened.sessionId);
64632
+ const sessionId = str2(opened.sessionId);
64684
64633
  if (!sessionId) throw new Error("the agent opened a session without giving it an id");
64685
64634
  return { opened, sessionId };
64686
64635
  }
64687
64636
  var TICKS_PER_USD = 1e10;
64688
64637
  function ticksUsd(value) {
64689
- const ticks = num(value);
64638
+ const ticks = num2(value);
64690
64639
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? ticks / TICKS_PER_USD : void 0;
64691
64640
  }
64692
64641
  var STOPPED = {
@@ -64696,14 +64645,14 @@ var STOPPED = {
64696
64645
  cancelled: "the turn was cancelled"
64697
64646
  };
64698
64647
  function mcpServersIn(file3) {
64699
- const servers = obj(obj(JSON.parse(fs21.readFileSync(file3, "utf8"))).mcpServers);
64648
+ const servers = obj2(obj2(JSON.parse(fs19.readFileSync(file3, "utf8"))).mcpServers);
64700
64649
  return Object.entries(servers).map(([name, raw]) => {
64701
- const s = obj(raw);
64650
+ const s = obj2(raw);
64702
64651
  return {
64703
64652
  name,
64704
- command: str(s.command),
64653
+ command: str2(s.command),
64705
64654
  args: Array.isArray(s.args) ? s.args.map(String) : [],
64706
- env: Object.entries(obj(s.env)).map(([key, value]) => ({ name: key, value: String(value) }))
64655
+ env: Object.entries(obj2(s.env)).map(([key, value]) => ({ name: key, value: String(value) }))
64707
64656
  };
64708
64657
  });
64709
64658
  }
@@ -64737,7 +64686,7 @@ async function oneTurn(io, options) {
64737
64686
  io.stdin,
64738
64687
  (msg) => {
64739
64688
  if (msg.method === "session/update") {
64740
- const params = obj(msg.params);
64689
+ const params = obj2(msg.params);
64741
64690
  if (!live && (!params.sessionId || params.sessionId === io.resumeId)) {
64742
64691
  update2(params.update, createTail(() => {
64743
64692
  }), (usd) => {
@@ -64745,9 +64694,9 @@ async function oneTurn(io, options) {
64745
64694
  }, () => {
64746
64695
  });
64747
64696
  }
64748
- if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
64749
- const kind = str(obj(obj(msg.params).update).sessionUpdate);
64750
- if (["agent_message_chunk", "agent_thought_chunk"].includes(kind) && str(obj(obj(obj(msg.params).update).content).text)) {
64697
+ if (live && (!obj2(msg.params).sessionId || obj2(msg.params).sessionId === currentSession)) {
64698
+ const kind = str2(obj2(obj2(msg.params).update).sessionUpdate);
64699
+ if (["agent_message_chunk", "agent_thought_chunk"].includes(kind) && str2(obj2(obj2(obj2(msg.params).update).content).text)) {
64751
64700
  io.activity?.();
64752
64701
  if (kind === "agent_thought_chunk") {
64753
64702
  if (!thinking || Date.now() - thinkingAt >= 1e3) {
@@ -64769,20 +64718,20 @@ async function oneTurn(io, options) {
64769
64718
  contentAt = Date.now();
64770
64719
  io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
64771
64720
  }
64772
- update2(obj(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
64773
- events.update(obj(msg.params).update);
64721
+ update2(obj2(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
64722
+ events.update(obj2(msg.params).update);
64774
64723
  emit();
64775
64724
  }
64776
64725
  return;
64777
64726
  }
64778
64727
  if (msg.id === void 0) return;
64779
64728
  if (msg.method === "session/request_permission") {
64780
- rpc.reply(msg.id, decide(obj(msg.params), tail, events));
64729
+ rpc.reply(msg.id, decide(obj2(msg.params), tail, events));
64781
64730
  emit();
64782
64731
  return;
64783
64732
  }
64784
64733
  if (msg.method === "cursor/update_todos") {
64785
- const params = obj(msg.params);
64734
+ const params = obj2(msg.params);
64786
64735
  if (live) {
64787
64736
  events.todos(params.todos, params.merge === true);
64788
64737
  emit();
@@ -64832,7 +64781,7 @@ async function oneTurn(io, options) {
64832
64781
  }
64833
64782
  let model = modelOf(opened);
64834
64783
  if (options.model) {
64835
- const listed = obj(opened.models).currentModelId !== void 0;
64784
+ const listed = obj2(opened.models).currentModelId !== void 0;
64836
64785
  const picked = listed ? pickedModel(opened, options.model) : void 0;
64837
64786
  const set2 = listed ? await bounded(rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }), preparingUntil - Date.now(), "ACP session/set_model timed out.") : await bounded(rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model }), preparingUntil - Date.now(), "ACP session/set_config_option timed out.");
64838
64787
  model = picked?.name ?? modelOf(set2) ?? options.model;
@@ -64849,8 +64798,8 @@ async function oneTurn(io, options) {
64849
64798
  });
64850
64799
  const result = tail.end();
64851
64800
  events.end();
64852
- const stopReason = str(done.stopReason);
64853
- const spent = obj(obj(done._meta).usage);
64801
+ const stopReason = str2(done.stopReason);
64802
+ const spent = obj2(obj2(done._meta).usage);
64854
64803
  const usage = usageOf3(done.usage) ?? usageOf3(spent, true);
64855
64804
  saveAcpCost(acpCostFile(options.tool ?? "acp", io.cwd, sessionId), costUsd);
64856
64805
  costUsd = costUsd === void 0 ? ticksUsd(spent.costUsdTicks) : costBefore === void 0 ? void 0 : costUsd < costBefore ? costUsd : costUsd - costBefore;
@@ -64879,32 +64828,32 @@ async function oneTurn(io, options) {
64879
64828
  }
64880
64829
  }
64881
64830
  function update2(raw, tail, gotCost, gotContext) {
64882
- const change = obj(raw);
64831
+ const change = obj2(raw);
64883
64832
  switch (change.sessionUpdate) {
64884
64833
  case "agent_message_chunk":
64885
- tail.text(str(obj(change.content).text));
64834
+ tail.text(str2(obj2(change.content).text));
64886
64835
  return;
64887
64836
  case "agent_thought_chunk":
64888
- tail.thought(str(obj(change.content).text));
64837
+ tail.thought(str2(obj2(change.content).text));
64889
64838
  return;
64890
64839
  case "tool_call": {
64891
- const title = str(change.title) || str(change.name) || "tool";
64840
+ const title = str2(change.title) || str2(change.name) || "tool";
64892
64841
  tail.line(`\u23FA ${title}${whereHint(change, title)}`);
64893
64842
  return;
64894
64843
  }
64895
64844
  case "tool_call_update": {
64896
64845
  if (change.status !== "failed") return;
64897
64846
  const why = saidBy(change);
64898
- tail.line(`[error] ${str(change.title) || "that tool call"} failed${why ? `: ${why}` : ""}`);
64847
+ tail.line(`[error] ${str2(change.title) || "that tool call"} failed${why ? `: ${why}` : ""}`);
64899
64848
  return;
64900
64849
  }
64901
64850
  case "usage_update": {
64902
- const used = num(change.used);
64903
- const size = num(change.size);
64851
+ const used = num2(change.used);
64852
+ const size = num2(change.size);
64904
64853
  if (used > 0) gotContext({ used, ...size > 0 ? { limit: size } : {} });
64905
- const cost = obj(change.cost);
64854
+ const cost = obj2(change.cost);
64906
64855
  const amount = cost.amount;
64907
- if (str(cost.currency).toUpperCase() === "USD" && typeof amount === "number" && Number.isFinite(amount) && amount >= 0) {
64856
+ if (str2(cost.currency).toUpperCase() === "USD" && typeof amount === "number" && Number.isFinite(amount) && amount >= 0) {
64908
64857
  gotCost(amount);
64909
64858
  }
64910
64859
  return;
@@ -64915,8 +64864,8 @@ function update2(raw, tail, gotCost, gotContext) {
64915
64864
  }
64916
64865
  function decide(params, tail, events) {
64917
64866
  const options = Array.isArray(params.options) ? params.options : [];
64918
- const no = options.map(obj).find((option) => str(option.kind).startsWith("reject"));
64919
- const title = str(obj(params.toolCall).title) || "that";
64867
+ const no = options.map(obj2).find((option) => str2(option.kind).startsWith("reject"));
64868
+ const title = str2(obj2(params.toolCall).title) || "that";
64920
64869
  const said = `[refused] ${title} \u2014 a run reaches no further than this project`;
64921
64870
  tail.line(said);
64922
64871
  events.log(`${said}
@@ -64926,21 +64875,21 @@ function decide(params, tail, events) {
64926
64875
  }
64927
64876
 
64928
64877
  // ../cli/src/lib/agent/wire/zcode.ts
64929
- import path24 from "node:path";
64878
+ import path22 from "node:path";
64930
64879
  function whereHint2(input2, title) {
64931
- const named = obj(input2);
64880
+ const named = obj2(input2);
64932
64881
  for (const key of ["command", "file_path", "path", "url", "pattern"]) {
64933
- const value = str(named[key]).trim();
64882
+ const value = str2(named[key]).trim();
64934
64883
  if (value && !title.includes(value)) return hint(value);
64935
64884
  }
64936
64885
  return "";
64937
64886
  }
64938
64887
  function usageOf4(value) {
64939
64888
  const counts = {
64940
- input: num(value.inputTokens),
64941
- cacheCreation: num(value.cacheCreationTokens) || num(value.cacheWriteTokens),
64942
- cacheRead: num(value.cacheReadTokens),
64943
- output: num(value.outputTokens)
64889
+ input: num2(value.inputTokens),
64890
+ cacheCreation: num2(value.cacheCreationTokens) || num2(value.cacheWriteTokens),
64891
+ cacheRead: num2(value.cacheReadTokens),
64892
+ output: num2(value.outputTokens)
64944
64893
  };
64945
64894
  const sum = counts.input + counts.cacheCreation + counts.cacheRead + counts.output;
64946
64895
  return sum > 0 ? counts : void 0;
@@ -64953,10 +64902,10 @@ var STOPPED2 = {
64953
64902
  error_during_execution: "the agent stopped part-way through"
64954
64903
  };
64955
64904
  function modelOf2(ref) {
64956
- const model = obj(ref);
64957
- const id2 = str(model.modelId);
64905
+ const model = obj2(ref);
64906
+ const id2 = str2(model.modelId);
64958
64907
  if (!id2) return "";
64959
- const provider = str(model.providerId);
64908
+ const provider = str2(model.providerId);
64960
64909
  return provider ? `${provider}/${id2}` : id2;
64961
64910
  }
64962
64911
  function createParts(tail) {
@@ -64974,33 +64923,33 @@ function createParts(tail) {
64974
64923
  return {
64975
64924
  /** A whole part, as `part.started` or `part.upserted` sends it. */
64976
64925
  upsert(raw) {
64977
- const part = obj(raw);
64978
- const type = str(part.type);
64979
- const partId = str(part.partId);
64926
+ const part = obj2(raw);
64927
+ const type = str2(part.type);
64928
+ const partId = str2(part.partId);
64980
64929
  if (type === "text" || type === "reasoning" || type === "thought") {
64981
- if (partId) say(partId, type, str(part.text));
64982
- else tail.text(str(part.text));
64930
+ if (partId) say(partId, type, str2(part.text));
64931
+ else tail.text(str2(part.text));
64983
64932
  return;
64984
64933
  }
64985
64934
  if (type !== "tool") return;
64986
- const state = obj(part.state);
64987
- const callId = str(part.callId) || partId;
64988
- const title = str(state.title) || str(part.tool) || "tool";
64935
+ const state = obj2(part.state);
64936
+ const callId = str2(part.callId) || partId;
64937
+ const title = str2(state.title) || str2(part.tool) || "tool";
64989
64938
  if (callId && !tools.has(callId)) {
64990
64939
  tools.add(callId);
64991
64940
  tail.line(`\u23FA ${title}${whereHint2(state.input, title)}`);
64992
64941
  }
64993
- if (str(state.status) === "error") {
64994
- const why = str(state.error).trim();
64942
+ if (str2(state.status) === "error") {
64943
+ const why = str2(state.error).trim();
64995
64944
  tail.line(`[error] ${title} failed${why ? `: ${why}` : ""}`);
64996
64945
  }
64997
64946
  },
64998
64947
  /** A piece of one part, as `part.delta` sends it. */
64999
64948
  delta(event2) {
65000
- const field = str(event2.field) || "text";
64949
+ const field = str2(event2.field) || "text";
65001
64950
  if (field !== "text" && field !== "reasoning") return;
65002
- const partId = str(event2.partId);
65003
- const delta = str(event2.delta);
64951
+ const partId = str2(event2.partId);
64952
+ const delta = str2(event2.delta);
65004
64953
  if (!delta) return;
65005
64954
  written.set(partId, (written.get(partId) ?? "") + delta);
65006
64955
  if (field === "reasoning") tail.thought(delta);
@@ -65008,12 +64957,12 @@ function createParts(tail) {
65008
64957
  },
65009
64958
  /** A piece of the turn, as `model.streaming` sends it. */
65010
64959
  streaming(payload) {
65011
- const kind = str(payload.kind);
65012
- if (kind === "text_delta") return tail.text(str(payload.delta));
65013
- if (kind === "reasoning_delta") return tail.thought(str(payload.delta));
64960
+ const kind = str2(payload.kind);
64961
+ if (kind === "text_delta") return tail.text(str2(payload.delta));
64962
+ if (kind === "reasoning_delta") return tail.thought(str2(payload.delta));
65014
64963
  if (kind !== "tool_call") return;
65015
- const callId = str(payload.toolCallId);
65016
- const name = str(payload.toolName) || "tool";
64964
+ const callId = str2(payload.toolCallId);
64965
+ const name = str2(payload.toolName) || "tool";
65017
64966
  named.set(callId, name);
65018
64967
  if (callId && tools.has(callId)) return;
65019
64968
  tools.add(callId);
@@ -65023,9 +64972,9 @@ function createParts(tail) {
65023
64972
  * `batch` are progress on a call that already has its line; only `error` is worth a
65024
64973
  * second one. */
65025
64974
  toolUpdate(payload) {
65026
- if (str(payload.kind) !== "error") return;
65027
- const name = named.get(str(payload.toolCallId)) ?? "tool";
65028
- const why = str(obj(payload.error).message).split("\n")[0].trim();
64975
+ if (str2(payload.kind) !== "error") return;
64976
+ const name = named.get(str2(payload.toolCallId)) ?? "tool";
64977
+ const why = str2(obj2(payload.error).message).split("\n")[0].trim();
65029
64978
  tail.line(`[error] ${name} failed${why ? `: ${why.slice(0, 200)}` : ""}`);
65030
64979
  }
65031
64980
  };
@@ -65070,22 +65019,22 @@ async function oneTurn2(io, options) {
65070
65019
  io.stdin,
65071
65020
  (msg) => {
65072
65021
  if (msg.method === "session/event") {
65073
- const envelope = obj(msg.params);
65074
- if (str(envelope.sessionId) === sessionId) {
65022
+ const envelope = obj2(msg.params);
65023
+ if (str2(envelope.sessionId) === sessionId) {
65075
65024
  if (live) {
65076
- const payload = obj(envelope.payload);
65077
- const part = obj(payload.part);
65078
- const state = obj(part.state);
65079
- const type = str(envelope.type);
65080
- if (["part.delta", "model.streaming"].includes(type) && str(payload.delta)) io.activity?.();
65081
- const id2 = str(payload.toolCallId) || str(part.callId) || str(part.partId);
65082
- const name = str(payload.toolName) || str(part.tool) || str(state.title);
65025
+ const payload = obj2(envelope.payload);
65026
+ const part = obj2(payload.part);
65027
+ const state = obj2(part.state);
65028
+ const type = str2(envelope.type);
65029
+ if (["part.delta", "model.streaming"].includes(type) && str2(payload.delta)) io.activity?.();
65030
+ const id2 = str2(payload.toolCallId) || str2(part.callId) || str2(part.partId);
65031
+ const name = str2(payload.toolName) || str2(part.tool) || str2(state.title);
65083
65032
  if (id2 && name && !activeCalls.has(id2)) {
65084
65033
  activeCalls.add(id2);
65085
65034
  if (/^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(name)) activityEvents.subagent(id2, name);
65086
65035
  else activityEvents.toolCall(id2, name, /^(?:bash|shell|execute|run_command|terminal)$/i.test(name) ? "execute" : "other");
65087
65036
  }
65088
- const status2 = str(state.status) || str(payload.kind);
65037
+ const status2 = str2(state.status) || str2(payload.kind);
65089
65038
  if (id2 && ["completed", "error", "result"].includes(status2)) activityEvents.toolResult(id2, status2 === "error" ? "failed" : "completed", "");
65090
65039
  for (const e of activityEvents.events()) io.event?.(e);
65091
65040
  }
@@ -65099,7 +65048,7 @@ async function oneTurn2(io, options) {
65099
65048
  return;
65100
65049
  }
65101
65050
  if (msg.method === "interaction/requestPermission") {
65102
- rpc.reply(msg.id, decide2(obj(msg.params), tail));
65051
+ rpc.reply(msg.id, decide2(obj2(msg.params), tail));
65103
65052
  return;
65104
65053
  }
65105
65054
  if (msg.method === "interaction/requestUserInput") {
@@ -65119,7 +65068,7 @@ async function oneTurn2(io, options) {
65119
65068
  { stringIds: true }
65120
65069
  );
65121
65070
  try {
65122
- const workspacePath = path24.resolve(io.cwd);
65071
+ const workspacePath = path22.resolve(io.cwd);
65123
65072
  const workspace = { workspacePath, workspaceKey: workspacePath };
65124
65073
  let opened;
65125
65074
  if (io.resumeId) {
@@ -65137,13 +65086,13 @@ async function oneTurn2(io, options) {
65137
65086
  // The session's name is the board's business, not a model call of its own.
65138
65087
  titleGenerationEnabled: false
65139
65088
  });
65140
- sessionId = str(obj(opened.session).sessionId);
65089
+ sessionId = str2(obj2(opened.session).sessionId);
65141
65090
  if (!sessionId) throw new Error("the agent opened a session without giving it an id");
65142
65091
  io.gotResumeId(sessionId);
65143
65092
  }
65144
- let model = modelOf2(obj(opened.session).model);
65093
+ let model = modelOf2(obj2(opened.session).model);
65145
65094
  if (options.model) {
65146
- const wanted = options.model.includes("/") ? { providerId: options.model.split("/")[0], modelId: options.model.split("/").slice(1).join("/") } : { providerId: str(obj(obj(opened.session).model).providerId) || "zai", modelId: options.model };
65095
+ const wanted = options.model.includes("/") ? { providerId: options.model.split("/")[0], modelId: options.model.split("/").slice(1).join("/") } : { providerId: str2(obj2(obj2(opened.session).model).providerId) || "zai", modelId: options.model };
65147
65096
  await rpc.call("session/setModel", { sessionId, model: wanted });
65148
65097
  model = modelOf2(wanted);
65149
65098
  }
@@ -65186,17 +65135,17 @@ async function tokensOf(rpc, sessionId) {
65186
65135
  async function contextOf(rpc, sessionId) {
65187
65136
  try {
65188
65137
  const read3 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
65189
- const state = obj(read3.projection);
65190
- const used = num(state.contextUsed);
65191
- const limit = num(state.contextWindow);
65138
+ const state = obj2(read3.projection);
65139
+ const used = num2(state.contextUsed);
65140
+ const limit = num2(state.contextWindow);
65192
65141
  return used > 0 ? { used, limit: limit > 0 ? limit : void 0 } : void 0;
65193
65142
  } catch {
65194
65143
  return void 0;
65195
65144
  }
65196
65145
  }
65197
65146
  function event(envelope, parts, tail, live, ended) {
65198
- const payload = obj(envelope.payload);
65199
- switch (str(envelope.type)) {
65147
+ const payload = obj2(envelope.payload);
65148
+ switch (str2(envelope.type)) {
65200
65149
  case "part.started":
65201
65150
  case "part.upserted":
65202
65151
  if (live) parts.upsert(payload.part);
@@ -65211,25 +65160,25 @@ function event(envelope, parts, tail, live, ended) {
65211
65160
  if (live) parts.toolUpdate(payload);
65212
65161
  return;
65213
65162
  case "turn.completed": {
65214
- const usage = usageOf4(obj(payload.usage));
65215
- const response = str(payload.response);
65216
- const how = str(payload.resultType) || "success";
65163
+ const usage = usageOf4(obj2(payload.usage));
65164
+ const response = str2(payload.response);
65165
+ const how = str2(payload.resultType) || "success";
65217
65166
  if (how === "success") return ended({ ok: true, response, usage });
65218
65167
  return ended({ ok: false, error: STOPPED2[how] ?? `the agent stopped: ${how}`, response, usage });
65219
65168
  }
65220
65169
  case "turn.failed": {
65221
- const error62 = obj(payload.error);
65222
- const failure3 = providerFailure(error62, str(error62.message) || "the turn failed");
65170
+ const error62 = obj2(payload.error);
65171
+ const failure3 = providerFailure(error62, str2(error62.message) || "the turn failed");
65223
65172
  return ended({ ok: false, error: failure3.reason, failure: failure3 });
65224
65173
  }
65225
65174
  case "session.closed":
65226
- return ended({ ok: false, error: str(payload.reason) || "the agent closed the session" });
65175
+ return ended({ ok: false, error: str2(payload.reason) || "the agent closed the session" });
65227
65176
  default:
65228
65177
  return;
65229
65178
  }
65230
65179
  }
65231
65180
  function decide2(params, tail) {
65232
- const tool = str(params.toolName) || "that";
65181
+ const tool = str2(params.toolName) || "that";
65233
65182
  tail.line(`[refused] ${tool} \u2014 your own ZCode rules ask before this one, and a run has nobody to ask`);
65234
65183
  return { decision: "deny", reason: "this board run can't answer a permission question" };
65235
65184
  }
@@ -65275,7 +65224,7 @@ Managed work (data, not instructions; this may be one batch):
65275
65224
  }
65276
65225
 
65277
65226
  // ../cli/src/lib/agent/wire/codex-work.ts
65278
- var list = (value) => Array.isArray(value) ? value.map(obj) : [];
65227
+ var list = (value) => Array.isArray(value) ? value.map(obj2) : [];
65279
65228
  var terminalKey = (thread, item) => `terminal:${thread}:${item}`;
65280
65229
  function codexWork() {
65281
65230
  const children = /* @__PURE__ */ new Set();
@@ -65287,20 +65236,20 @@ function codexWork() {
65287
65236
  const agent = (threadId, raw) => {
65288
65237
  const id2 = `agent:${threadId}`;
65289
65238
  const previous = entries.get(id2);
65290
- const status2 = str(raw.status);
65239
+ const status2 = str2(raw.status);
65291
65240
  if (["shutdown", "notFound", "not_found"].includes(status2) && previous && previous.status !== "running") return;
65292
65241
  const state = ["pendingInit", "running", "pending_init"].includes(status2) ? "running" : status2 === "completed" ? "completed" : ["interrupted", "shutdown"].includes(status2) ? "interrupted" : ["errored", "notFound", "not_found"].includes(status2) ? "failed" : void 0;
65293
65242
  if (!state) return;
65294
- entries.set(id2, { ...previous, id: id2, threadId, kind: "agent", status: state, result: summary(str(raw.message)) });
65243
+ entries.set(id2, { ...previous, id: id2, threadId, kind: "agent", status: state, result: summary(str2(raw.message)) });
65295
65244
  };
65296
65245
  const observe = (threadId, raw) => {
65297
65246
  if (!own3(threadId)) return;
65298
65247
  if (raw.type === "subAgentActivity") {
65299
- const child = str(raw.agentThreadId);
65248
+ const child = str2(raw.agentThreadId);
65300
65249
  if (raw.kind === "started" && child && child !== root2 && !children.has(child)) {
65301
65250
  children.add(child);
65302
65251
  agent(child, { status: "running" });
65303
- entries.get(`agent:${child}`).agentPath = str(raw.agentPath);
65252
+ entries.get(`agent:${child}`).agentPath = str2(raw.agentPath);
65304
65253
  }
65305
65254
  return;
65306
65255
  }
@@ -65314,10 +65263,10 @@ function codexWork() {
65314
65263
  if (!entries.has(`agent:${id3}`)) agent(id3, { status: "running" });
65315
65264
  }
65316
65265
  }
65317
- for (const [id3, state] of Object.entries(obj(raw.agentsStates))) if (children.has(id3)) agent(id3, obj(state));
65266
+ for (const [id3, state] of Object.entries(obj2(raw.agentsStates))) if (children.has(id3)) agent(id3, obj2(state));
65318
65267
  }
65319
- if (raw.type !== "commandExecution" || !str(raw.id)) return;
65320
- const id2 = terminalKey(threadId, str(raw.id));
65268
+ if (raw.type !== "commandExecution" || !str2(raw.id)) return;
65269
+ const id2 = terminalKey(threadId, str2(raw.id));
65321
65270
  const previous = entries.get(id2);
65322
65271
  const running = raw.status === "inProgress";
65323
65272
  if (running && previous?.exitCode !== void 0) return;
@@ -65327,36 +65276,36 @@ function codexWork() {
65327
65276
  id: id2,
65328
65277
  threadId,
65329
65278
  kind: "terminal",
65330
- itemId: str(raw.id),
65331
- processId: str(raw.processId) || previous?.processId,
65332
- command: summary(str(raw.command) || previous?.command || "", 600),
65279
+ itemId: str2(raw.id),
65280
+ processId: str2(raw.processId) || previous?.processId,
65281
+ command: summary(str2(raw.command) || previous?.command || "", 600),
65333
65282
  status: running ? "running" : exitCode !== void 0 ? exitCode === 0 ? "completed" : "failed" : "unknown",
65334
- result: summary(str(raw.aggregatedOutput) || previous?.result || ""),
65283
+ result: summary(str2(raw.aggregatedOutput) || previous?.result || ""),
65335
65284
  exitCode
65336
65285
  });
65337
65286
  };
65338
65287
  const observeTurn = (threadId, turn2) => {
65339
65288
  if (!children.has(threadId)) return;
65340
- const status2 = str(turn2.status);
65289
+ const status2 = str2(turn2.status);
65341
65290
  if (!["completed", "failed", "interrupted"].includes(status2)) return;
65342
- const message = list(turn2.items).filter((i) => i.type === "agentMessage" && i.phase !== "commentary").map((i) => str(i.text)).join("\n\n");
65343
- agent(threadId, { status: status2 === "failed" ? "errored" : status2, message: str(obj(turn2.error).message) || message });
65291
+ const message = list(turn2.items).filter((i) => i.type === "agentMessage" && i.phase !== "commentary").map((i) => str2(i.text)).join("\n\n");
65292
+ agent(threadId, { status: status2 === "failed" ? "errored" : status2, message: str2(obj2(turn2.error).message) || message });
65344
65293
  };
65345
65294
  const readThread = async (rpc, threadId) => {
65346
- let thread = obj((await rpc.call("thread/read", { threadId, includeTurns: false })).thread);
65295
+ let thread = obj2((await rpc.call("thread/read", { threadId, includeTurns: false })).thread);
65347
65296
  let turns = list(thread.turns);
65348
65297
  if (thread.historyMode === "paginated") {
65349
65298
  turns = list((await rpc.call("thread/turns/list", { threadId, sortDirection: "desc", limit: 1, itemsView: "full" })).data);
65350
65299
  } else if (!turns.length) {
65351
- thread = obj((await rpc.call("thread/read", { threadId, includeTurns: true })).thread);
65300
+ thread = obj2((await rpc.call("thread/read", { threadId, includeTurns: true })).thread);
65352
65301
  turns = list(thread.turns).slice(-1);
65353
65302
  } else turns = turns.slice(-1);
65354
65303
  const turn2 = turns[0];
65355
65304
  for (const item of list(turn2?.items)) observe(threadId, item);
65356
65305
  if (threadId !== root2) {
65357
- const status2 = str(turn2?.status);
65358
- if (obj(thread.status).type === "systemError") agent(threadId, { status: "errored", message: "Codex subagent reported a system error." });
65359
- else if (obj(thread.status).type !== "active" && ["completed", "failed", "interrupted"].includes(status2)) {
65306
+ const status2 = str2(turn2?.status);
65307
+ if (obj2(thread.status).type === "systemError") agent(threadId, { status: "errored", message: "Codex subagent reported a system error." });
65308
+ else if (obj2(thread.status).type !== "active" && ["completed", "failed", "interrupted"].includes(status2)) {
65360
65309
  observeTurn(threadId, turn2 ?? {});
65361
65310
  }
65362
65311
  }
@@ -65394,7 +65343,7 @@ function codexWork() {
65394
65343
  cursors.add(cursor);
65395
65344
  const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
65396
65345
  for (const terminal of list(page.data)) {
65397
- const itemId = str(terminal.itemId), processId = str(terminal.processId);
65346
+ const itemId = str2(terminal.itemId), processId = str2(terminal.processId);
65398
65347
  if (!itemId || !processId) throw Error("Codex returned a background terminal without its complete handles.");
65399
65348
  const id2 = terminalKey(threadId, itemId);
65400
65349
  present.add(id2);
@@ -65407,7 +65356,7 @@ function codexWork() {
65407
65356
  itemId,
65408
65357
  processId,
65409
65358
  ...typeof terminal.osPid === "number" ? { osPid: terminal.osPid } : {},
65410
- command: summary(str(terminal.command) || previous?.command || "", 600),
65359
+ command: summary(str2(terminal.command) || previous?.command || "", 600),
65411
65360
  status: "running",
65412
65361
  result: previous?.result ?? ""
65413
65362
  });
@@ -65431,7 +65380,7 @@ function codexWork() {
65431
65380
  }
65432
65381
 
65433
65382
  // ../cli/src/lib/agent/wire/codex.ts
65434
- var list2 = (value) => Array.isArray(value) ? value.map(obj) : [];
65383
+ var list2 = (value) => Array.isArray(value) ? value.map(obj2) : [];
65435
65384
  function createCodexConnection(argv) {
65436
65385
  const execAt = argv.indexOf("exec");
65437
65386
  if (execAt < 1) return void 0;
@@ -65640,8 +65589,8 @@ async function run(io, options, count2) {
65640
65589
  };
65641
65590
  const item = (raw, completed, proof = true) => {
65642
65591
  if (ended) return;
65643
- const id2 = str(raw.id);
65644
- if (["collabAgentToolCall", "subAgentActivity"].includes(str(raw.type))) {
65592
+ const id2 = str2(raw.id);
65593
+ if (["collabAgentToolCall", "subAgentActivity"].includes(str2(raw.type))) {
65645
65594
  if (proof) began();
65646
65595
  childUpdates();
65647
65596
  return;
@@ -65649,7 +65598,7 @@ async function run(io, options, count2) {
65649
65598
  const key = `${id2}:${completed}`;
65650
65599
  if (seenItems.has(key)) return;
65651
65600
  seenItems.add(key);
65652
- if (raw.type === "agentMessage" && completed && raw.phase !== "commentary" && str(raw.text).trim()) {
65601
+ if (raw.type === "agentMessage" && completed && raw.phase !== "commentary" && str2(raw.text).trim()) {
65653
65602
  const eligible = /* @__PURE__ */ new Set([...settlement?.work.map((w) => w.id) ?? [], ...visible]);
65654
65603
  replySnapshots = new Map([...work.entries.values()].filter((w) => eligible.has(w.id) && !["running", "unknown"].includes(w.status)).map((w) => [w.id, snapshot(w)]));
65655
65604
  }
@@ -65659,14 +65608,14 @@ async function run(io, options, count2) {
65659
65608
  return;
65660
65609
  }
65661
65610
  const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
65662
- const type = types[str(raw.type)];
65611
+ const type = types[str2(raw.type)];
65663
65612
  if (!type) return;
65664
65613
  if (proof) began();
65665
65614
  emit(completed ? "item.completed" : "item.started", { item: {
65666
65615
  ...raw,
65667
65616
  type,
65668
65617
  ...raw.type === "imageGeneration" ? { path: raw.savedPath ?? raw.path } : {},
65669
- ...raw.type === "fileChange" ? { changes: list2(raw.changes).map((c) => ({ ...c, kind: str(obj(c.kind).type) || c.kind })) } : {},
65618
+ ...raw.type === "fileChange" ? { changes: list2(raw.changes).map((c) => ({ ...c, kind: str2(obj2(c.kind).type) || c.kind })) } : {},
65670
65619
  aggregated_output: raw.aggregatedOutput,
65671
65620
  exit_code: raw.exitCode,
65672
65621
  status: raw.status === "inProgress" ? "in_progress" : raw.status
@@ -65808,12 +65757,12 @@ async function run(io, options, count2) {
65808
65757
  end(`Codex requested interaction: ${msg.method}`);
65809
65758
  return;
65810
65759
  }
65811
- const p = obj(msg.params);
65812
- const source = str(p.threadId);
65760
+ const p = obj2(msg.params);
65761
+ const source = str2(p.threadId);
65813
65762
  if (!work.own(source)) return;
65814
65763
  if (msg.method === "item/commandExecution/terminalInteraction") {
65815
65764
  for (const w of work.entries.values()) if (w.kind === "terminal" && w.threadId === source && w.processId === p.processId && w.status === "running") {
65816
- if (str(p.stdin).includes("")) w.intentionalStop = true;
65765
+ if (str2(p.stdin).includes("")) w.intentionalStop = true;
65817
65766
  else if (settlement && p.stdin === "") {
65818
65767
  settlement.polled.add(w.id);
65819
65768
  armCleanup();
@@ -65821,26 +65770,26 @@ async function run(io, options, count2) {
65821
65770
  }
65822
65771
  }
65823
65772
  if (msg.method === "item/started" || msg.method === "item/completed") {
65824
- const raw = obj(p.item);
65773
+ const raw = obj2(p.item);
65825
65774
  work.observe(source, raw);
65826
65775
  if (source === threadId && active) {
65827
- if (raw.type === "commandExecution") visible.add(`terminal:${source}:${str(raw.id)}`);
65828
- if (raw.type === "collabAgentToolCall") for (const id2 of Object.keys(obj(raw.agentsStates))) visible.add(`agent:${id2}`);
65776
+ if (raw.type === "commandExecution") visible.add(`terminal:${source}:${str2(raw.id)}`);
65777
+ if (raw.type === "collabAgentToolCall") for (const id2 of Object.keys(obj2(raw.agentsStates))) visible.add(`agent:${id2}`);
65829
65778
  }
65830
65779
  armCleanup();
65831
- if (source === threadId && obj(p.item).type !== "agentMessage") item(obj(p.item), msg.method === "item/completed", false);
65780
+ if (source === threadId && obj2(p.item).type !== "agentMessage") item(obj2(p.item), msg.method === "item/completed", false);
65832
65781
  }
65833
65782
  if (source !== threadId) {
65834
65783
  if (msg.method === "turn/completed") {
65835
- work.observeTurn(source, obj(p.turn));
65784
+ work.observeTurn(source, obj2(p.turn));
65836
65785
  armCleanup();
65837
65786
  }
65838
65787
  childUpdates();
65839
65788
  return;
65840
65789
  }
65841
- const turnId = str(p.turnId) || str(obj(p.turn).id);
65790
+ const turnId = str2(p.turnId) || str2(obj2(p.turn).id);
65842
65791
  if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
65843
- if (submitted && ["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "") && str(p.delta)) {
65792
+ if (submitted && ["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "") && str2(p.delta)) {
65844
65793
  if (msg.method?.startsWith("item/reasoning/")) thinking();
65845
65794
  else recovered();
65846
65795
  io.activity?.();
@@ -65859,17 +65808,17 @@ async function run(io, options, count2) {
65859
65808
  }
65860
65809
  if (msg.method === "item/started" || msg.method === "item/completed") {
65861
65810
  recovered();
65862
- item(obj(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
65811
+ item(obj2(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
65863
65812
  }
65864
65813
  if (msg.method === "thread/tokenUsage/updated") {
65865
65814
  if (!submitted) return;
65866
- const token = obj(p.tokenUsage);
65867
- const counts = obj(token.total);
65815
+ const token = obj2(p.tokenUsage);
65816
+ const counts = obj2(token.total);
65868
65817
  const input2 = Number(counts.inputTokens) || 0;
65869
65818
  const read3 = Number(counts.cachedInputTokens) || 0;
65870
65819
  const write = Number(counts.cacheWriteInputTokens) || 0;
65871
65820
  total = { input: Math.max(0, input2 - read3 - write), cacheRead: read3, cacheCreation: write, output: Number(counts.outputTokens) || 0 };
65872
- const last2 = obj(token.last);
65821
+ const last2 = obj2(token.last);
65873
65822
  if (!baseline && Object.keys(last2).length) {
65874
65823
  const cached3 = Number(last2.cachedInputTokens) || 0;
65875
65824
  const written = Number(last2.cacheWriteInputTokens) || 0;
@@ -65888,8 +65837,8 @@ async function run(io, options, count2) {
65888
65837
  } else if (p.willRetry !== true) end(failure3.reason, failure3);
65889
65838
  }
65890
65839
  if (msg.method === "turn/completed") {
65891
- const turn2 = obj(p.turn);
65892
- const id2 = str(turn2.id);
65840
+ const turn2 = obj2(p.turn);
65841
+ const id2 = str2(turn2.id);
65893
65842
  if (completedTurns.has(id2)) return;
65894
65843
  completedTurns.add(id2);
65895
65844
  for (const raw of list2(turn2.items)) {
@@ -65898,7 +65847,7 @@ async function run(io, options, count2) {
65898
65847
  }
65899
65848
  if (idling) return;
65900
65849
  if (turn2.status !== "completed") {
65901
- const reason = str(obj(turn2.error).message) || `Codex turn ${str(turn2.status)}.`;
65850
+ const reason = str2(obj2(turn2.error).message) || `Codex turn ${str2(turn2.status)}.`;
65902
65851
  const failure3 = turn2.status === "failed" ? codexFailure(turn2.error, reason) : { code: "turn_stopped", level: 3, reason };
65903
65852
  end(reason, failure3);
65904
65853
  return;
@@ -65923,8 +65872,8 @@ async function run(io, options, count2) {
65923
65872
  }
65924
65873
  phase("preparing");
65925
65874
  const initialized = await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
65926
- host = obj(initialized.wildcrane);
65927
- if (host.instance) cleanup.instance = str(host.instance);
65875
+ host = obj2(initialized.wildcrane);
65876
+ if (host.instance) cleanup.instance = str2(host.instance);
65928
65877
  phase("initialized");
65929
65878
  rpc.notify("initialized");
65930
65879
  const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
@@ -65948,15 +65897,15 @@ async function run(io, options, count2) {
65948
65897
  }
65949
65898
  }
65950
65899
  if (ended || !response) return done;
65951
- const thread = obj(response.thread);
65952
- for (const turn2 of list2(thread.turns)) historicalTurns.add(str(turn2.id));
65953
- threadId = str(thread.id);
65900
+ const thread = obj2(response.thread);
65901
+ for (const turn2 of list2(thread.turns)) historicalTurns.add(str2(turn2.id));
65902
+ threadId = str2(thread.id);
65954
65903
  if (!threadId) throw Error("Codex did not return a thread id.");
65955
65904
  if (mode === "resume" && threadId !== params.threadId) throw Error("Codex did not return the requested session.");
65956
- work.root(threadId, list2(response.retainedThreads).map((t2) => str(t2.id)));
65957
- for (const terminal of list2(response.retainedTerminals)) retained.set(`terminal:${str(terminal.threadId)}:${str(terminal.itemId)}`, str(terminal.processId));
65958
- provider = str(thread.modelProvider) || void 0;
65959
- model = str(response.model) || str(thread.model) || void 0;
65905
+ work.root(threadId, list2(response.retainedThreads).map((t2) => str2(t2.id)));
65906
+ for (const terminal of list2(response.retainedTerminals)) retained.set(`terminal:${str2(terminal.threadId)}:${str2(terminal.itemId)}`, str2(terminal.processId));
65907
+ provider = str2(thread.modelProvider) || void 0;
65908
+ model = str2(response.model) || str2(thread.model) || void 0;
65960
65909
  if (model) io.gotModel(model);
65961
65910
  io.gotResumeId(threadId);
65962
65911
  baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total ?? (!options.threadId && !io.resumeId ? ZERO_USAGE : void 0);
@@ -65982,15 +65931,15 @@ var userMessage = (prompt) => `${JSON.stringify({ type: "user", message: { role:
65982
65931
  `;
65983
65932
  function claudeOnWindows() {
65984
65933
  const [local, roaming] = [process.env.LOCALAPPDATA?.trim(), process.env.APPDATA?.trim()];
65985
- const packages = local ? path25.join(local, "Packages") : "";
65934
+ const packages = local ? path23.join(local, "Packages") : "";
65986
65935
  const data = [
65987
- ...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path25.join(packages, name, "LocalCache", "Roaming", "Claude")),
65988
- ...roaming ? [path25.join(roaming, "Claude")] : []
65936
+ ...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path23.join(packages, name, "LocalCache", "Roaming", "Claude")),
65937
+ ...roaming ? [path23.join(roaming, "Claude")] : []
65989
65938
  ];
65990
65939
  return data.flatMap(
65991
- (dir) => latestIn(path25.join(dir, "claude-code")).flatMap((version2) => [
65992
- path25.join(version2, "claude.exe"),
65993
- ...folders(version2).map((build) => path25.join(version2, build, "claude.exe"))
65940
+ (dir) => latestIn(path23.join(dir, "claude-code")).flatMap((version2) => [
65941
+ path23.join(version2, "claude.exe"),
65942
+ ...folders(version2).map((build) => path23.join(version2, build, "claude.exe"))
65994
65943
  ])
65995
65944
  );
65996
65945
  }
@@ -66163,7 +66112,7 @@ var CLAUDE_CODE = {
66163
66112
  ...MODEL_ALIASES,
66164
66113
  ...modelsIn(
66165
66114
  home(".claude.json"),
66166
- (data) => arr(obj2(data).additionalModelOptionsCache).map((option) => str2(obj2(option).value))
66115
+ (data) => arr(obj(data).additionalModelOptionsCache).map((option) => str(obj(option).value))
66167
66116
  )
66168
66117
  ];
66169
66118
  },
@@ -66234,24 +66183,24 @@ var CLAUDE_CODE = {
66234
66183
  ...latestIn(home(".local", "share", "claude", "versions")),
66235
66184
  // The copy Claude Desktop carries.
66236
66185
  ...process.platform === "win32" ? claudeOnWindows() : latestIn(home("Library", "Application Support", "Claude", "claude-code")).flatMap(
66237
- (version2) => folders(version2).map((build) => path25.join(version2, build, "claude.app", "Contents", "MacOS", "claude"))
66186
+ (version2) => folders(version2).map((build) => path23.join(version2, build, "claude.app", "Contents", "MacOS", "claude"))
66238
66187
  )
66239
66188
  ],
66240
66189
  install: "npm install -g @anthropic-ai/claude-code"
66241
66190
  };
66242
66191
 
66243
66192
  // ../cli/src/lib/agent/harnesses/codex.ts
66244
- import fs22 from "node:fs";
66245
- import path26 from "node:path";
66193
+ import fs20 from "node:fs";
66194
+ import path24 from "node:path";
66246
66195
 
66247
66196
  // ../cli/src/lib/agent/worktree.ts
66248
- import { spawnSync as spawnSync5 } from "node:child_process";
66197
+ import { spawnSync as spawnSync4 } from "node:child_process";
66249
66198
  var MAX_OUTPUT = 64 * 1024 * 1024;
66250
66199
  var gitLimits = { timeoutMs: 3e4 };
66251
66200
  var GitTimeoutError = class extends Error {
66252
66201
  };
66253
66202
  function spawnGit(args2, options) {
66254
- const out = spawnSync5("git", args2, {
66203
+ const out = spawnSync4("git", args2, {
66255
66204
  ...options,
66256
66205
  encoding: "utf8",
66257
66206
  stdio: ["ignore", "pipe", "pipe"],
@@ -66289,10 +66238,10 @@ function codexExtraArgs(argv, cwd = REPO_ROOT) {
66289
66238
  }
66290
66239
  const flags = [...argv, ...extra];
66291
66240
  const workspaceWrite = flags.some((arg, i) => arg === "--full-auto" || arg === "--sandbox=workspace-write" || (arg === "--sandbox" || arg === "-s") && flags[i + 1] === "workspace-write");
66292
- if (workspaceWrite && path26.resolve(cwd) !== path26.resolve(REPO_ROOT)) {
66241
+ if (workspaceWrite && path24.resolve(cwd) !== path24.resolve(REPO_ROOT)) {
66293
66242
  for (const dir of [KANBAN, AKB_DIR]) {
66294
- const relative = path26.relative(cwd, dir);
66295
- if (relative === ".." || relative.startsWith(`..${path26.sep}`) || path26.isAbsolute(relative)) {
66243
+ const relative = path24.relative(cwd, dir);
66244
+ if (relative === ".." || relative.startsWith(`..${path24.sep}`) || path24.isAbsolute(relative)) {
66296
66245
  extra.push("--add-dir", dir);
66297
66246
  }
66298
66247
  }
@@ -66315,7 +66264,7 @@ function envRoot(name) {
66315
66264
  }
66316
66265
  function modified(file3) {
66317
66266
  try {
66318
- return fs22.statSync(file3).mtimeMs;
66267
+ return fs20.statSync(file3).mtimeMs;
66319
66268
  } catch {
66320
66269
  return 0;
66321
66270
  }
@@ -66341,28 +66290,28 @@ function codexOnWindows() {
66341
66290
  const local = envRoot("LOCALAPPDATA");
66342
66291
  const profile = envRoot("USERPROFILE");
66343
66292
  const programs = envRoot("ProgramFiles");
66344
- const cache = local ? path26.join(local, "OpenAI", "Codex", "bin") : "";
66345
- const releases = profile ? path26.join(profile, ".codex", "packages", "standalone", "releases") : "";
66346
- const packages = programs ? path26.join(programs, "WindowsApps") : "";
66293
+ const cache = local ? path24.join(local, "OpenAI", "Codex", "bin") : "";
66294
+ const releases = profile ? path24.join(profile, ".codex", "packages", "standalone", "releases") : "";
66295
+ const packages = programs ? path24.join(programs, "WindowsApps") : "";
66347
66296
  return [
66348
66297
  // Desktop's relocated CLI cache: a folder per build hash, newest file first.
66349
- ...byNewest(folders(cache).map((name) => path26.join(cache, name, "codex.exe"))),
66298
+ ...byNewest(folders(cache).map((name) => path24.join(cache, name, "codex.exe"))),
66350
66299
  // The separate standalone launcher, at a path with nothing variable in it.
66351
- ...local ? [path26.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
66300
+ ...local ? [path24.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
66352
66301
  // That launcher's release payload: a folder per version and target.
66353
66302
  ...byVersion(folders(releases).filter(ourArch)).map(
66354
- (name) => path26.join(releases, name, "bin", "codex.exe")
66303
+ (name) => path24.join(releases, name, "bin", "codex.exe")
66355
66304
  ),
66356
66305
  // Desktop's own MSIX package.
66357
66306
  ...byVersion(folders(packages).filter((name) => name.startsWith("OpenAI.Codex_")).filter(ourArch)).map(
66358
- (name) => path26.join(packages, name, "app", "resources", "codex.exe")
66307
+ (name) => path24.join(packages, name, "app", "resources", "codex.exe")
66359
66308
  )
66360
66309
  ];
66361
66310
  }
66362
66311
  function codexInstalls() {
66363
66312
  const chosen = process.env.CODEX_INSTALL_DIR?.trim();
66364
66313
  return [
66365
- ...chosen ? [path26.join(chosen, "codex")] : [],
66314
+ ...chosen ? [path24.join(chosen, "codex")] : [],
66366
66315
  ...process.platform === "win32" ? codexOnWindows() : [
66367
66316
  // macOS, where Codex now lives in the merged app — `codex-cli/bin/` since 26.928…
66368
66317
  "/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex",
@@ -66408,7 +66357,7 @@ var CODEX = {
66408
66357
  systemPrompt(text2, argv) {
66409
66358
  if (namesFlag(argv, ["developer_instructions", "model_instructions_file"])) return {};
66410
66359
  try {
66411
- const config2 = fs22.readFileSync(path26.join(process.env.CODEX_HOME || home(".codex"), "config.toml"), "utf8");
66360
+ const config2 = fs20.readFileSync(path24.join(process.env.CODEX_HOME || home(".codex"), "config.toml"), "utf8");
66412
66361
  if (/^\s*(?:developer_instructions|model_instructions_file)\s*=/m.test(config2)) return {};
66413
66362
  } catch {
66414
66363
  }
@@ -66530,7 +66479,7 @@ var CODEX = {
66530
66479
  models() {
66531
66480
  return modelsIn(
66532
66481
  home(".codex", "models_cache.json"),
66533
- (data) => arr(obj2(data).models).map(obj2).filter((model) => str2(model.visibility) !== "hide").sort((a, b) => num2(a.priority) - num2(b.priority)).map((model) => str2(model.slug))
66482
+ (data) => arr(obj(data).models).map(obj).filter((model) => str(model.visibility) !== "hide").sort((a, b) => num(a.priority) - num(b.priority)).map((model) => str(model.slug))
66534
66483
  );
66535
66484
  },
66536
66485
  // Nothing extra. Claude Code gets CLAUDE_CODE_MAX_RETRIES=0 so a rate limit fails at
@@ -66648,24 +66597,24 @@ var CURSOR = {
66648
66597
  };
66649
66598
 
66650
66599
  // ../cli/src/lib/agent/harnesses/dsh.ts
66651
- import fs23 from "node:fs";
66652
- import path27 from "node:path";
66600
+ import fs21 from "node:fs";
66601
+ import path25 from "node:path";
66653
66602
  function dshHome(argv) {
66654
66603
  const binary = argv[0];
66655
66604
  if (!binary) return void 0;
66656
- const names = process.platform === "win32" && !path27.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
66657
- const candidates = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path27.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path27.join(dir2, name)));
66605
+ const names = process.platform === "win32" && !path25.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
66606
+ const candidates = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path25.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path25.join(dir2, name)));
66658
66607
  let dir;
66659
66608
  try {
66660
- const found = candidates.find((candidate) => fs23.existsSync(candidate));
66609
+ const found = candidates.find((candidate) => fs21.existsSync(candidate));
66661
66610
  if (!found) return void 0;
66662
- const script = /\.cmd$/i.test(found) ? shimTarget(fs23.readFileSync(found, "utf8"), found)?.script : void 0;
66663
- dir = path27.dirname(fs23.realpathSync(script ?? found));
66611
+ const script = /\.cmd$/i.test(found) ? shimTarget(fs21.readFileSync(found, "utf8"), found)?.script : void 0;
66612
+ dir = path25.dirname(fs21.realpathSync(script ?? found));
66664
66613
  } catch {
66665
66614
  return void 0;
66666
66615
  }
66667
- for (let up = path27.dirname(dir); dir !== up; up = path27.dirname(dir)) {
66668
- if (fs23.existsSync(path27.join(dir, "package.json"))) return dir;
66616
+ for (let up = path25.dirname(dir); dir !== up; up = path25.dirname(dir)) {
66617
+ if (fs21.existsSync(path25.join(dir, "package.json"))) return dir;
66669
66618
  dir = up;
66670
66619
  }
66671
66620
  return void 0;
@@ -66819,7 +66768,7 @@ var GROK = {
66819
66768
  // subscription's models, one on a key sees the key's, and the board reads whichever is
66820
66769
  // there rather than deciding.
66821
66770
  models() {
66822
- return modelsIn(home(".grok", "models_cache.json"), (data) => Object.keys(obj2(obj2(data).models)));
66771
+ return modelsIn(home(".grok", "models_cache.json"), (data) => Object.keys(obj(obj(data).models)));
66823
66772
  },
66824
66773
  // Everything that could send a Grok run to a provider the user didn't pick: where the
66825
66774
  // requests go, the second name the key answers to, and the three that decide who issues
@@ -67098,12 +67047,12 @@ var OPENCODE = {
67098
67047
  models() {
67099
67048
  const cache = process.env.XDG_CACHE_HOME || home(".cache");
67100
67049
  const data = process.env.XDG_DATA_HOME || home(".local", "share");
67101
- const mine = modelsIn(join6(data, "opencode", "auth.json"), (auth) => Object.keys(obj2(auth)));
67050
+ const mine = modelsIn(join6(data, "opencode", "auth.json"), (auth) => Object.keys(obj(auth)));
67102
67051
  if (!mine.length) return [];
67103
67052
  return modelsIn(
67104
67053
  join6(cache, "opencode", "models.json"),
67105
67054
  (catalogue) => mine.flatMap(
67106
- (provider) => Object.keys(obj2(obj2(obj2(catalogue)[provider]).models)).map((model) => `${provider}/${model}`)
67055
+ (provider) => Object.keys(obj(obj(obj(catalogue)[provider]).models)).map((model) => `${provider}/${model}`)
67107
67056
  ),
67108
67057
  mine.join(" ")
67109
67058
  );
@@ -67116,7 +67065,7 @@ var OPENCODE = {
67116
67065
  `);
67117
67066
  let own3 = {};
67118
67067
  try {
67119
- own3 = obj2(JSON.parse(env2.OPENCODE_CONFIG_CONTENT ?? "{}"));
67068
+ own3 = obj(JSON.parse(env2.OPENCODE_CONFIG_CONTENT ?? "{}"));
67120
67069
  } catch {
67121
67070
  }
67122
67071
  const instructions = [...Array.isArray(own3.instructions) ? own3.instructions : [], file3];
@@ -67203,8 +67152,8 @@ var ZCODE = {
67203
67152
  models() {
67204
67153
  return modelsIn(
67205
67154
  home(".zcode", "v2", "config.json"),
67206
- (data) => Object.values(obj2(obj2(data).provider)).flatMap(
67207
- (provider) => Object.keys(obj2(obj2(provider).models))
67155
+ (data) => Object.values(obj(obj(data).provider)).flatMap(
67156
+ (provider) => Object.keys(obj(obj(provider).models))
67208
67157
  )
67209
67158
  );
67210
67159
  },
@@ -67363,8 +67312,8 @@ var sources2 = Object.fromEntries(
67363
67312
  ])
67364
67313
  );
67365
67314
  Object.assign(sources2, {
67366
- "claude-code": () => claudeModels(path28.join(process.env.CLAUDE_CONFIG_DIR || path28.join(os6.homedir(), ".claude"), "cache", "model-catalog")),
67367
- codex: () => codexModels(path28.join(process.env.CODEX_HOME || path28.join(os6.homedir(), ".codex"), "models_cache.json")),
67315
+ "claude-code": () => claudeModels(path26.join(process.env.CLAUDE_CONFIG_DIR || path26.join(os6.homedir(), ".claude"), "cache", "model-catalog")),
67316
+ codex: () => codexModels(path26.join(process.env.CODEX_HOME || path26.join(os6.homedir(), ".codex"), "models_cache.json")),
67368
67317
  opencode: async (signal) => opencodeModels(await output2(commandOf(HARNESSES2.opencode)[0], ["models"], signal)),
67369
67318
  cursor: (signal) => cursorModels(signal),
67370
67319
  antigravity: async (signal) => antigravityModels(await output2(commandOf(HARNESSES2.antigravity)[0], ["models"], signal))
@@ -67400,10 +67349,10 @@ function cursorModels(signal, argv = commandOf(HARNESSES2.cursor)) {
67400
67349
  });
67401
67350
  }
67402
67351
  function acpModels(opened) {
67403
- const list3 = obj(opened.models).availableModels;
67404
- return (Array.isArray(list3) ? list3 : []).map(obj).flatMap((m) => {
67405
- const id2 = str(m.modelId);
67406
- return id2 && id2 !== "default[]" ? [{ id: id2, name: str(m.name) || id2 }] : [];
67352
+ const list3 = obj2(opened.models).availableModels;
67353
+ return (Array.isArray(list3) ? list3 : []).map(obj2).flatMap((m) => {
67354
+ const id2 = str2(m.modelId);
67355
+ return id2 && id2 !== "default[]" ? [{ id: id2, name: str2(m.name) || id2 }] : [];
67407
67356
  });
67408
67357
  }
67409
67358
  function output2(command, args2, signal) {
@@ -67434,7 +67383,7 @@ function output2(command, args2, signal) {
67434
67383
  }
67435
67384
  function codexModels(file3) {
67436
67385
  try {
67437
- const cache = JSON.parse(fs24.readFileSync(file3, "utf8"));
67386
+ const cache = JSON.parse(fs22.readFileSync(file3, "utf8"));
67438
67387
  if (!Array.isArray(cache.models)) return [];
67439
67388
  return cache.models.flatMap(
67440
67389
  (m) => m.visibility === "list" && typeof m.slug === "string" && m.slug ? [{ id: m.slug, name: typeof m.display_name === "string" && m.display_name ? m.display_name : m.slug }] : []
@@ -67446,30 +67395,30 @@ function codexModels(file3) {
67446
67395
  function claudeModels(dir) {
67447
67396
  let files;
67448
67397
  try {
67449
- files = fs24.readdirSync(dir).filter((f) => f.endsWith(".json"));
67398
+ files = fs22.readdirSync(dir).filter((f) => f.endsWith(".json"));
67450
67399
  } catch {
67451
67400
  return [];
67452
67401
  }
67453
67402
  const catalogs = files.flatMap((f) => {
67454
67403
  try {
67455
- const data = obj(JSON.parse(fs24.readFileSync(path28.join(dir, f), "utf8")));
67456
- const catalog = obj(data.catalog);
67457
- const surface = str(catalog.surface);
67458
- return surface === "cc" || surface === "ccd" ? [{ surface, at: Number(data.fetchedAt) || 0, config: obj(catalog.config) }] : [];
67404
+ const data = obj2(JSON.parse(fs22.readFileSync(path26.join(dir, f), "utf8")));
67405
+ const catalog = obj2(data.catalog);
67406
+ const surface = str2(catalog.surface);
67407
+ return surface === "cc" || surface === "ccd" ? [{ surface, at: Number(data.fetchedAt) || 0, config: obj2(catalog.config) }] : [];
67459
67408
  } catch {
67460
67409
  return [];
67461
67410
  }
67462
67411
  });
67463
67412
  const newest2 = catalogs.sort((a, b) => a.surface === b.surface ? b.at - a.at : a.surface === "cc" ? -1 : 1)[0];
67464
67413
  if (!newest2) return [];
67465
- const aliases = obj(newest2.config.provider_alias_targets);
67414
+ const aliases = obj2(newest2.config.provider_alias_targets);
67466
67415
  const models = Array.isArray(newest2.config.models) ? newest2.config.models : [];
67467
- return models.map(obj).flatMap((m) => {
67468
- const id2 = str(m.id);
67416
+ return models.map(obj2).flatMap((m) => {
67417
+ const id2 = str2(m.id);
67469
67418
  if (!id2 || m.section !== "main") return [];
67470
- const family = str(obj(m.runtime).family);
67471
- const alias = family && str(obj(aliases[family]).default) === id2 ? family : "";
67472
- return [{ id: alias || id2, name: str(m.short_name) || str(m.name) || id2 }];
67419
+ const family = str2(obj2(m.runtime).family);
67420
+ const alias = family && str2(obj2(aliases[family]).default) === id2 ? family : "";
67421
+ return [{ id: alias || id2, name: str2(m.short_name) || str2(m.name) || id2 }];
67473
67422
  });
67474
67423
  }
67475
67424
  function probeLogin(binary, harness) {
@@ -67498,43 +67447,43 @@ function probeLogin(binary, harness) {
67498
67447
  }
67499
67448
 
67500
67449
  // ../runner/src/akb.ts
67501
- import fs25 from "node:fs";
67502
- import path29 from "node:path";
67450
+ import fs23 from "node:fs";
67451
+ import path27 from "node:path";
67503
67452
  import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
67504
- var akbHome = () => path29.join(runnerHome(), "bin", "akb");
67453
+ var akbHome = () => path27.join(runnerHome(), "bin", "akb");
67505
67454
  var BUNDLED_SHIM = `bundled-${AKB_VERSION}`;
67506
- var HERE = path29.dirname(fileURLToPath2(import.meta.url));
67455
+ var HERE = path27.dirname(fileURLToPath2(import.meta.url));
67507
67456
  function akbArgs(entry, dist = HERE) {
67508
- const preload = path29.join(dist, "akb-proxy.mjs");
67509
- return fs25.existsSync(preload) ? ["--import", pathToFileURL(preload).href, entry] : [entry];
67457
+ const preload = path27.join(dist, "akb-proxy.mjs");
67458
+ return fs23.existsSync(preload) ? ["--import", pathToFileURL(preload).href, entry] : [entry];
67510
67459
  }
67511
67460
  var bundledAkb = (dist = HERE) => ({
67512
67461
  command: process.execPath,
67513
- args: akbArgs(path29.join(dist, "akb", "bin", "ai4kanban.mjs"), dist),
67462
+ args: akbArgs(path27.join(dist, "akb", "bin", "ai4kanban.mjs"), dist),
67514
67463
  version: AKB_VERSION,
67515
- shim: path29.join(akbHome(), BUNDLED_SHIM)
67464
+ shim: path27.join(akbHome(), BUNDLED_SHIM)
67516
67465
  });
67517
67466
  var quote = (s) => /^[\w./:@=-]+$/.test(s) ? s : `"${s}"`;
67518
67467
  function shimDir(akb) {
67519
67468
  const dir = akb.shim;
67520
67469
  const line = [akb.command, ...akb.args].map(quote).join(" ");
67521
- const [file3, text2] = process.platform === "win32" ? [path29.join(dir, "akb.cmd"), `@${line} %*\r
67522
- `] : [path29.join(dir, "akb"), `#!/bin/sh
67470
+ const [file3, text2] = process.platform === "win32" ? [path27.join(dir, "akb.cmd"), `@${line} %*\r
67471
+ `] : [path27.join(dir, "akb"), `#!/bin/sh
67523
67472
  exec ${line} "$@"
67524
67473
  `];
67525
67474
  if (process.platform === "win32") {
67526
- fs25.mkdirSync(dir, { recursive: true });
67475
+ fs23.mkdirSync(dir, { recursive: true });
67527
67476
  const shellLine = [akb.command, ...akb.args].map((s) => `'${s.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`).join(" ");
67528
- fs25.writeFileSync(path29.join(dir, "akb"), `#!/bin/sh
67477
+ fs23.writeFileSync(path27.join(dir, "akb"), `#!/bin/sh
67529
67478
  exec ${shellLine} "$@"
67530
67479
  `, { mode: 493 });
67531
67480
  }
67532
67481
  try {
67533
- if (fs25.readFileSync(file3, "utf8") === text2) return dir;
67482
+ if (fs23.readFileSync(file3, "utf8") === text2) return dir;
67534
67483
  } catch {
67535
67484
  }
67536
- fs25.mkdirSync(dir, { recursive: true });
67537
- fs25.writeFileSync(file3, text2, { mode: 493 });
67485
+ fs23.mkdirSync(dir, { recursive: true });
67486
+ fs23.writeFileSync(file3, text2, { mode: 493 });
67538
67487
  return dir;
67539
67488
  }
67540
67489
  var KEEP = 256 * 1024;
@@ -67542,11 +67491,11 @@ var KEEP = 256 * 1024;
67542
67491
  // ../runner/src/lock.ts
67543
67492
  import crypto4 from "node:crypto";
67544
67493
  import net from "node:net";
67545
- import path30 from "node:path";
67494
+ import path28 from "node:path";
67546
67495
  function lockPath() {
67547
67496
  const home3 = runnerHome();
67548
67497
  if (process.platform === "win32") return `\\\\.\\pipe\\wildcrane-${crypto4.createHash("sha256").update(home3).digest("hex").slice(0, 16)}`;
67549
- return path30.join(home3, "runner.sock");
67498
+ return path28.join(home3, "runner.sock");
67550
67499
  }
67551
67500
  function runnerSettingsSupport() {
67552
67501
  return new Promise((resolve2) => {
@@ -67579,6 +67528,90 @@ import { spawn as spawn3 } from "node:child_process";
67579
67528
  import crypto5 from "node:crypto";
67580
67529
  import http from "node:http";
67581
67530
 
67531
+ // ../runner/src/settings-control.ts
67532
+ import fs25 from "node:fs";
67533
+ import path30 from "node:path";
67534
+
67535
+ // ../runner/src/codex-native.ts
67536
+ import fs24 from "node:fs";
67537
+ import path29 from "node:path";
67538
+ var import_undici2 = __toESM(require_undici(), 1);
67539
+
67540
+ // ../cli/src/lib/agent/connection-process.ts
67541
+ import { spawnSync as spawnSync5 } from "node:child_process";
67542
+ function connectionIdentity(pid) {
67543
+ const result = process.platform === "win32" ? spawnSync5("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CreationDate.ToUniversalTime().ToString('o')`], { encoding: "utf8", timeout: 2e3, windowsHide: true }) : spawnSync5("ps", ["-p", String(pid), "-o", "lstart="], { encoding: "utf8", timeout: 2e3, env: { ...process.env, LC_ALL: "C" } });
67544
+ return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
67545
+ }
67546
+ function connectionStopped(root2) {
67547
+ if (!root2) return true;
67548
+ if (!pidAlive(root2.pid)) return true;
67549
+ const identity = connectionIdentity(root2.pid);
67550
+ return !!root2.identity && !!identity && identity !== root2.identity;
67551
+ }
67552
+
67553
+ // ../runner/src/codex-native.ts
67554
+ var nativeDirectory = () => path29.join(runnerCwd(), "codex-native");
67555
+ var liveBackend = (backend) => !connectionStopped(backend);
67556
+ function readPrivate(file3) {
67557
+ try {
67558
+ return JSON.parse(fs24.readFileSync(file3, "utf8"));
67559
+ } catch (error62) {
67560
+ if (error62.code === "ENOENT") return;
67561
+ throw error62;
67562
+ }
67563
+ }
67564
+ function stopNativeBackends() {
67565
+ let files = [];
67566
+ try {
67567
+ files = fs24.readdirSync(nativeDirectory()).filter((name) => /^[a-f0-9]{64}\.json$/.test(name));
67568
+ } catch {
67569
+ return [];
67570
+ }
67571
+ const targets = [];
67572
+ for (const file3 of files) {
67573
+ const backend = readPrivate(path29.join(nativeDirectory(), file3));
67574
+ if (backend?.identity && liveBackend(backend) && connectionIdentity(backend.pid) === backend.identity) {
67575
+ targets.push(backend);
67576
+ try {
67577
+ process.kill(backend.pid, "SIGTERM");
67578
+ } catch {
67579
+ }
67580
+ }
67581
+ }
67582
+ return targets;
67583
+ }
67584
+
67585
+ // ../runner/src/settings-control.ts
67586
+ var directory = () => path30.join(runnerHome(), "executors");
67587
+ var epochFile = () => path30.join(runnerHome(), "account-generation");
67588
+ function accountGeneration() {
67589
+ try {
67590
+ return fs25.readFileSync(epochFile(), "utf8");
67591
+ } catch {
67592
+ return "";
67593
+ }
67594
+ }
67595
+ async function stopExecutors() {
67596
+ fs25.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
67597
+ fs25.writeFileSync(epochFile(), `${Date.now()}-${process.pid}`, { mode: 384 });
67598
+ const backends = stopNativeBackends();
67599
+ for (let n = 0; n < 160; n++) {
67600
+ const active = fs25.existsSync(directory()) ? fs25.readdirSync(directory()).filter((name) => {
67601
+ try {
67602
+ process.kill(Number(name.split(".")[0]), 0);
67603
+ return true;
67604
+ } catch {
67605
+ fs25.rmSync(path30.join(directory(), name), { force: true });
67606
+ return false;
67607
+ }
67608
+ }) : [];
67609
+ if (!active.length && backends.every((backend) => !liveBackend(backend))) return true;
67610
+ await new Promise((resolve2) => setTimeout(resolve2, 100));
67611
+ }
67612
+ return false;
67613
+ }
67614
+
67582
67615
  // ../runner/src/i18n.ts
67583
67616
  var ZH_HOLDER = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", dsh: "dsh", zcode: "ZCode", kimi: "Kimi Code", terminal: "\u672C\u673A\u7EC8\u7AEF" };
67584
67617
  var EN_HOLDER = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", dsh: "dsh", zcode: "ZCode", kimi: "Kimi Code", terminal: "the terminal" };