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/akb/dist/kanban.mjs +3049 -3298
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/codex-proxy.mjs +1 -1
- package/dist/codex-retained.mjs +1 -1
- package/dist/flow-worker-main.mjs +2101 -2304
- package/dist/launcher.mjs +914 -879
- package/dist/plugin.mjs +1131 -1089
- package/dist/runner.mjs +1719 -1936
- package/dist/settings.mjs +1095 -1062
- package/package.json +1 -1
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
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;
|
|
@@ -107840,8 +107840,8 @@ function machineId() {
|
|
|
107840
107840
|
var machineName = () => os3.hostname().replace(/\.local$/, "");
|
|
107841
107841
|
|
|
107842
107842
|
// ../runner/src/protocol.ts
|
|
107843
|
-
var VERSION = true ? "0.6.
|
|
107844
|
-
var AKB_VERSION = true ? "0.11.
|
|
107843
|
+
var VERSION = true ? "0.6.98" : "0.0.0";
|
|
107844
|
+
var AKB_VERSION = true ? "0.11.79" : "0.0.0";
|
|
107845
107845
|
var EXIT_REFUSED = 10;
|
|
107846
107846
|
var EXIT_OUTDATED = 11;
|
|
107847
107847
|
var EXIT_UPDATE = 12;
|
|
@@ -107885,465 +107885,24 @@ exec ${shellLine} "$@"
|
|
|
107885
107885
|
}
|
|
107886
107886
|
var KEEP = 256 * 1024;
|
|
107887
107887
|
|
|
107888
|
-
// ../
|
|
107889
|
-
|
|
107890
|
-
|
|
107891
|
-
|
|
107892
|
-
// ../runner/src/codex-native.ts
|
|
107893
|
-
import fs6 from "node:fs";
|
|
107894
|
-
import path8 from "node:path";
|
|
107895
|
-
var import_undici2 = __toESM(require_undici(), 1);
|
|
107896
|
-
|
|
107897
|
-
// ../cli/src/lib/shared/conversation.ts
|
|
107898
|
-
var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
|
|
107899
|
-
function bounded(work, ms, reason) {
|
|
107900
|
-
return new Promise((resolve2, reject) => {
|
|
107901
|
-
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
107902
|
-
work.then((value) => {
|
|
107903
|
-
clearTimeout(timer);
|
|
107904
|
-
resolve2(value);
|
|
107905
|
-
}, (error63) => {
|
|
107906
|
-
clearTimeout(timer);
|
|
107907
|
-
reject(error63);
|
|
107908
|
-
});
|
|
107909
|
-
});
|
|
107910
|
-
}
|
|
107911
|
-
|
|
107912
|
-
// ../cli/src/lib/agent/connection-process.ts
|
|
107913
|
-
import { spawnSync } from "node:child_process";
|
|
107914
|
-
|
|
107915
|
-
// ../cli/src/lib/paths.ts
|
|
107916
|
-
import path7 from "node:path";
|
|
107917
|
-
|
|
107918
|
-
// ../cli/src/lib/io.ts
|
|
107919
|
-
var BoardError = class extends Error {
|
|
107920
|
-
// `kind` is the machine-readable name of the refusal (card-not-found, no-board,
|
|
107921
|
-
// unknown-module, …). It is what a caller reads; the exit code stays 1 for every
|
|
107922
|
-
// refusal, so nobody has to keep a table of numbers.
|
|
107923
|
-
kind;
|
|
107924
|
-
// Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
|
|
107925
|
-
exitCode;
|
|
107926
|
-
// `bare` says the message is already the whole thing a person should see — a usage
|
|
107927
|
-
// block, say — so the dispatcher prints it without putting the command in front of it.
|
|
107928
|
-
bare;
|
|
107929
|
-
details;
|
|
107930
|
-
constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
|
|
107931
|
-
super(message);
|
|
107932
|
-
this.name = "BoardError";
|
|
107933
|
-
this.kind = kind;
|
|
107934
|
-
this.bare = bare;
|
|
107935
|
-
this.exitCode = exitCode;
|
|
107936
|
-
this.details = details;
|
|
107937
|
-
}
|
|
107938
|
-
};
|
|
107939
|
-
|
|
107940
|
-
// ../cli/src/lib/machine/project.ts
|
|
107941
|
-
import fs5 from "node:fs";
|
|
107942
|
-
import path6 from "node:path";
|
|
107943
|
-
var SESSIONS_FILE = "sessions.json";
|
|
107944
|
-
var SESSIONS_FOLDER = "sessions";
|
|
107945
|
-
var ASSETS_FOLDER = "assets";
|
|
107946
|
-
var SESSIONS_LOCK = "sessions.lock";
|
|
107947
|
-
var INDEX_LOCK = "index.lock";
|
|
107948
|
-
var UI_CONFIG_FILE = "ui.config.json";
|
|
107949
|
-
function realPathOf(dir) {
|
|
107950
|
-
const here2 = path6.resolve(dir);
|
|
107951
|
-
const rest = [];
|
|
107952
|
-
let at = here2;
|
|
107953
|
-
for (; ; ) {
|
|
107954
|
-
try {
|
|
107955
|
-
return path6.join(fs5.realpathSync(at), ...rest);
|
|
107956
|
-
} catch {
|
|
107957
|
-
const up = path6.dirname(at);
|
|
107958
|
-
if (up === at) return here2;
|
|
107959
|
-
rest.unshift(path6.basename(at));
|
|
107960
|
-
at = up;
|
|
107961
|
-
}
|
|
107962
|
-
}
|
|
107963
|
-
}
|
|
107964
|
-
function stateRootOf(board) {
|
|
107965
|
-
let dir = realPathOf(board);
|
|
107966
|
-
for (; ; ) {
|
|
107967
|
-
if (fs5.existsSync(path6.join(dir, ".git"))) return dir;
|
|
107968
|
-
const up = path6.dirname(dir);
|
|
107969
|
-
if (up === dir) break;
|
|
107970
|
-
dir = up;
|
|
107971
|
-
}
|
|
107972
|
-
return rootAbove(realPathOf(board));
|
|
107973
|
-
}
|
|
107974
|
-
function rootAbove(board) {
|
|
107975
|
-
const parent = path6.dirname(board);
|
|
107976
|
-
return ["docs", ".akb"].includes(path6.basename(parent)) ? path6.dirname(parent) : parent;
|
|
107977
|
-
}
|
|
107978
|
-
function projectStateDir(board, root2 = stateRootOf(board)) {
|
|
107979
|
-
const relative = path6.relative(realPathOf(root2), realPathOf(board));
|
|
107980
|
-
if (relative === ".." || relative.startsWith(`..${path6.sep}`) || path6.isAbsolute(relative)) {
|
|
107981
|
-
throw new Error("The board must be inside its project root.");
|
|
107982
|
-
}
|
|
107983
|
-
return path6.join(realPathOf(root2), ".akb", "boards", relative || "_root");
|
|
107984
|
-
}
|
|
107985
|
-
|
|
107986
|
-
// ../cli/src/lib/paths.ts
|
|
107987
|
-
var REPO_ROOT = "";
|
|
107988
|
-
var KANBAN = "";
|
|
107989
|
-
var TODO = "";
|
|
107990
|
-
var ARCHIVE = "";
|
|
107991
|
-
var ARCHIVE_MD = "";
|
|
107992
|
-
var README = "";
|
|
107993
|
-
var MODULES_MD = "";
|
|
107994
|
-
var CONFIG = "";
|
|
107995
|
-
var KANBAN_GITIGNORE = "";
|
|
107996
|
-
var RELEASES = "";
|
|
107997
|
-
var RELEASE_SUMMARIES = "";
|
|
107998
|
-
var AGENTS = "";
|
|
107999
|
-
var STUDIOS = "";
|
|
108000
|
-
var ASSETS = "";
|
|
108001
|
-
var BOARD_STATE = "";
|
|
108002
|
-
var MEMORY = "";
|
|
108003
|
-
var AGENT_MEMORY = "";
|
|
108004
|
-
var PROJECT_MD = "";
|
|
108005
|
-
var LOCK = "";
|
|
108006
|
-
var UI_CONFIG = "";
|
|
108007
|
-
var ENV_FILE = "";
|
|
108008
|
-
var SESSIONS = "";
|
|
108009
|
-
var SESSIONS_DIR = "";
|
|
108010
|
-
var SESSIONS_LOCK2 = "";
|
|
108011
|
-
var INDEX_LOCK2 = "";
|
|
108012
|
-
var DELIVERIES = "";
|
|
108013
|
-
var PLANS = "";
|
|
108014
|
-
var PLANS_ARCHIVE = "";
|
|
108015
|
-
var RULES = "";
|
|
108016
|
-
var TRIAGE = "";
|
|
108017
|
-
var SIGNALS_ARCHIVED = "";
|
|
108018
|
-
var SIGNALS_DISMISSED = "";
|
|
108019
|
-
var SIGNALS_FILES = "";
|
|
108020
|
-
var SIGNALS_OLD_INBOX = "";
|
|
108021
|
-
var SIGNALS_OLD_HANDLED = "";
|
|
108022
|
-
var AKB_DIR = "";
|
|
108023
|
-
var ROOT_GITIGNORE = "";
|
|
108024
|
-
function boardLockName(kanban, root2) {
|
|
108025
|
-
const from = path7.relative(root2, kanban);
|
|
108026
|
-
const name = from && !from.startsWith("..") ? from : path7.basename(kanban);
|
|
108027
|
-
return `${name.split(path7.sep).join("-")}.lock`;
|
|
108028
|
-
}
|
|
108029
|
-
var BOARD_FLAG = "";
|
|
108030
|
-
function setBoard(kanban, root2, flag) {
|
|
108031
|
-
REPO_ROOT = path7.resolve(root2);
|
|
108032
|
-
KANBAN = path7.resolve(kanban);
|
|
108033
|
-
BOARD_FLAG = flag;
|
|
108034
|
-
TODO = path7.join(KANBAN, "todo");
|
|
108035
|
-
ARCHIVE = path7.join(KANBAN, ".archive");
|
|
108036
|
-
ARCHIVE_MD = path7.join(KANBAN, "archive.md");
|
|
108037
|
-
README = path7.join(TODO, "README.md");
|
|
108038
|
-
MODULES_MD = path7.join(KANBAN, "modules.md");
|
|
108039
|
-
CONFIG = path7.join(KANBAN, "config.md");
|
|
108040
|
-
KANBAN_GITIGNORE = path7.join(KANBAN, ".gitignore");
|
|
108041
|
-
RELEASES = path7.join(KANBAN, "releases.md");
|
|
108042
|
-
RELEASE_SUMMARIES = path7.join(KANBAN, ".release-summaries");
|
|
108043
|
-
AGENTS = path7.join(KANBAN, "agents");
|
|
108044
|
-
STUDIOS = path7.join(KANBAN, "studios");
|
|
108045
|
-
MEMORY = path7.join(KANBAN, "memory");
|
|
108046
|
-
AGENT_MEMORY = path7.join(MEMORY, "agents");
|
|
108047
|
-
PROJECT_MD = path7.join(MEMORY, "project.md");
|
|
108048
|
-
ENV_FILE = path7.join(KANBAN, ".env");
|
|
108049
|
-
const machine = projectStateDir(KANBAN, REPO_ROOT);
|
|
108050
|
-
BOARD_STATE = machine;
|
|
108051
|
-
UI_CONFIG = path7.join(machine, UI_CONFIG_FILE);
|
|
108052
|
-
ASSETS = path7.join(machine, ASSETS_FOLDER);
|
|
108053
|
-
SESSIONS = path7.join(machine, SESSIONS_FILE);
|
|
108054
|
-
SESSIONS_DIR = path7.join(machine, SESSIONS_FOLDER);
|
|
108055
|
-
SESSIONS_LOCK2 = path7.join(machine, SESSIONS_LOCK);
|
|
108056
|
-
INDEX_LOCK2 = path7.join(machine, INDEX_LOCK);
|
|
108057
|
-
DELIVERIES = path7.join(KANBAN, "deliveries");
|
|
108058
|
-
RULES = path7.join(KANBAN, "rules");
|
|
108059
|
-
PLANS = path7.join(machine, "plans");
|
|
108060
|
-
PLANS_ARCHIVE = path7.join(PLANS, "archive");
|
|
108061
|
-
TRIAGE = path7.join(KANBAN, "triage");
|
|
108062
|
-
SIGNALS_ARCHIVED = path7.join(TRIAGE, "archived");
|
|
108063
|
-
SIGNALS_DISMISSED = path7.join(TRIAGE, "dismissed");
|
|
108064
|
-
SIGNALS_FILES = path7.join(TRIAGE, "files");
|
|
108065
|
-
SIGNALS_OLD_INBOX = path7.join(TRIAGE, "inbox");
|
|
108066
|
-
SIGNALS_OLD_HANDLED = path7.join(TRIAGE, "handled.md");
|
|
108067
|
-
AKB_DIR = path7.join(REPO_ROOT, ".akb");
|
|
108068
|
-
ROOT_GITIGNORE = path7.join(REPO_ROOT, ".gitignore");
|
|
108069
|
-
LOCK = path7.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
|
|
108070
|
-
return REPO_ROOT;
|
|
108071
|
-
}
|
|
108072
|
-
function setBoardRoot(root2, named = false) {
|
|
108073
|
-
const project = path7.resolve(root2);
|
|
108074
|
-
return setBoard(path7.join(project, "docs", "kanban"), project, named ? ` --dir ${project}` : "");
|
|
108075
|
-
}
|
|
108076
|
-
setBoardRoot(process.cwd());
|
|
108077
|
-
|
|
108078
|
-
// ../cli/src/lib/lock.ts
|
|
108079
|
-
function pidAlive(pid) {
|
|
108080
|
-
if (!pid) return false;
|
|
108081
|
-
try {
|
|
108082
|
-
process.kill(pid, 0);
|
|
108083
|
-
return true;
|
|
108084
|
-
} catch (e) {
|
|
108085
|
-
return e.code === "EPERM";
|
|
108086
|
-
}
|
|
108087
|
-
}
|
|
108088
|
-
|
|
108089
|
-
// ../cli/src/lib/agent/connection-process.ts
|
|
108090
|
-
function connectionIdentity(pid) {
|
|
108091
|
-
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" } });
|
|
108092
|
-
return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
|
|
108093
|
-
}
|
|
108094
|
-
function connectionStopped(root2) {
|
|
108095
|
-
if (!root2) return true;
|
|
108096
|
-
if (!pidAlive(root2.pid)) return true;
|
|
108097
|
-
const identity = connectionIdentity(root2.pid);
|
|
108098
|
-
return !!root2.identity && !!identity && identity !== root2.identity;
|
|
108099
|
-
}
|
|
108100
|
-
|
|
108101
|
-
// ../cli/src/lib/agent/retry.ts
|
|
108102
|
-
function readFailure(raw) {
|
|
108103
|
-
if (!raw || typeof raw !== "object") return;
|
|
108104
|
-
const { code, level, reason, source, retryAfterMs: retryAfterMs2 } = raw;
|
|
108105
|
-
if (typeof code !== "string" || !code || typeof reason !== "string" || level !== 1 && level !== 2 && level !== 3) return;
|
|
108106
|
-
return { code, level, reason, ...["validation", "provider", "harness", "invariant"].some((value) => value === source) ? { source } : {}, ...typeof retryAfterMs2 === "number" && retryAfterMs2 >= 0 ? { retryAfterMs: retryAfterMs2 } : {} };
|
|
108107
|
-
}
|
|
108108
|
-
|
|
108109
|
-
// ../cli/src/lib/agent/wire/json.ts
|
|
108110
|
-
function obj(value) {
|
|
108111
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
108112
|
-
}
|
|
108113
|
-
function str(value) {
|
|
108114
|
-
return typeof value === "string" ? value : "";
|
|
108115
|
-
}
|
|
108116
|
-
function num(value) {
|
|
108117
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
108118
|
-
}
|
|
108119
|
-
function hint(raw) {
|
|
108120
|
-
const line = raw.split("\n")[0].trim();
|
|
108121
|
-
if (!line) return "";
|
|
108122
|
-
return `(${line.length > 96 ? `${line.slice(0, 93)}\u2026` : line})`;
|
|
108123
|
-
}
|
|
108124
|
-
function argHint(input2, keys) {
|
|
108125
|
-
const args2 = obj(input2);
|
|
108126
|
-
for (const key of keys) {
|
|
108127
|
-
const value = str(args2[key]);
|
|
108128
|
-
if (value.trim()) return hint(value);
|
|
108129
|
-
}
|
|
108130
|
-
return "";
|
|
108131
|
-
}
|
|
108132
|
-
|
|
108133
|
-
// ../cli/src/lib/agent/wire/failures.ts
|
|
108134
|
-
var ExecutionError = class extends Error {
|
|
108135
|
-
constructor(failure5) {
|
|
108136
|
-
super(failure5.reason);
|
|
108137
|
-
this.failure = failure5;
|
|
108138
|
-
}
|
|
108139
|
-
failure;
|
|
108140
|
-
};
|
|
108141
|
-
var NETWORK = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT", "ENETUNREACH", "EAI_AGAIN", "UND_ERR_SOCKET"]);
|
|
108142
|
-
var TEMPORARY_HTTP = /* @__PURE__ */ new Set([502, 503, 504, 529]);
|
|
108143
|
-
function executionFailure(error63) {
|
|
108144
|
-
if (error63 instanceof ExecutionError) return error63.failure;
|
|
108145
|
-
const code = str(obj(error63).code);
|
|
108146
|
-
const reason = error63 instanceof Error ? error63.message : String(error63);
|
|
107888
|
+
// ../cli/src/lib/shared/goal.ts
|
|
107889
|
+
function readGoal({ studio, workflow, previews, task, review_plan, ...goal }) {
|
|
107890
|
+
const plan = review_plan !== void 0 ? readReviewPlan(review_plan) : previews?.length ? [{ id: "review", after: [], previews }] : previews ? [] : void 0;
|
|
108147
107891
|
return {
|
|
108148
|
-
|
|
108149
|
-
|
|
108150
|
-
|
|
108151
|
-
|
|
108152
|
-
};
|
|
108153
|
-
}
|
|
108154
|
-
function retryAfterMs(value, now = Date.now()) {
|
|
108155
|
-
if (typeof value !== "string") return;
|
|
108156
|
-
const header = value.trim();
|
|
108157
|
-
if (/^\d+$/.test(header)) return Math.min(Number(header) * 1e3, Number.MAX_SAFE_INTEGER);
|
|
108158
|
-
if (!/^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)) return;
|
|
108159
|
-
const date7 = Date.parse(header);
|
|
108160
|
-
if (Number.isFinite(date7)) return Math.max(0, date7 - now);
|
|
108161
|
-
}
|
|
108162
|
-
function providerFailure(error63, reason) {
|
|
108163
|
-
const info = obj(error63);
|
|
108164
|
-
const status2 = typeof info.status === "number" ? info.status : void 0;
|
|
108165
|
-
const headers = obj(info.headers);
|
|
108166
|
-
const wait = retryAfterMs(headers["retry-after"] ?? headers["Retry-After"]);
|
|
108167
|
-
const code = info.code ?? info.type;
|
|
108168
|
-
if (code === "session_not_found") return { code, source: "provider", level: 3, reason };
|
|
108169
|
-
if (status2 === 401 || status2 === 403 || ["authentication_error", "permission_error", "invalid_request_error"].includes(str(code))) {
|
|
108170
|
-
return { code: "provider_refused", source: "provider", level: 3, reason };
|
|
108171
|
-
}
|
|
108172
|
-
if (code === "rate_limit_error") return { code: "rate_limited", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
108173
|
-
if (TEMPORARY_HTTP.has(status2 ?? 0) || code === "overloaded_error") return { code: "service_overloaded", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
108174
|
-
if (NETWORK.has(str(code))) return { code: "connection_lost", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
108175
|
-
return { code: "provider_failed", source: "provider", level: 3, reason };
|
|
108176
|
-
}
|
|
108177
|
-
function codexFailure(raw, fallback) {
|
|
108178
|
-
const error63 = obj(raw);
|
|
108179
|
-
const failure5 = readFailure(error63.wildcraneFailure);
|
|
108180
|
-
if (failure5?.source === "harness" || failure5?.source === "invariant") return failure5;
|
|
108181
|
-
const reason = str(error63.message) || fallback;
|
|
108182
|
-
const info = error63.codexErrorInfo;
|
|
108183
|
-
if (info === "serverOverloaded") return providerFailure({ ...error63, type: "overloaded_error" }, reason);
|
|
108184
|
-
if (info === "rateLimitExceeded") return providerFailure({ ...error63, type: "rate_limit_error" }, reason);
|
|
108185
|
-
const types = obj(info);
|
|
108186
|
-
for (const kind of ["httpConnectionFailed", "responseStreamConnectionFailed", "responseStreamDisconnected", "responseTooManyFailedAttempts"]) {
|
|
108187
|
-
if (!(kind in types)) continue;
|
|
108188
|
-
const status2 = obj(types[kind]).httpStatusCode;
|
|
108189
|
-
if (typeof status2 === "number") return providerFailure({ ...error63, status: status2 }, reason);
|
|
108190
|
-
if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error63, code: "ECONNRESET" }, reason);
|
|
108191
|
-
}
|
|
108192
|
-
return providerFailure(error63, reason);
|
|
108193
|
-
}
|
|
108194
|
-
|
|
108195
|
-
// ../cli/src/lib/agent/wire/rpc.ts
|
|
108196
|
-
var RpcError = class extends Error {
|
|
108197
|
-
constructor(message, code, data) {
|
|
108198
|
-
super(message);
|
|
108199
|
-
this.code = code;
|
|
108200
|
-
this.data = data;
|
|
108201
|
-
this.name = "RpcError";
|
|
108202
|
-
}
|
|
108203
|
-
code;
|
|
108204
|
-
data;
|
|
108205
|
-
};
|
|
108206
|
-
function connect(stdout, stdin, onCall, dialect = {}) {
|
|
108207
|
-
let buf = "";
|
|
108208
|
-
let nextId = 1;
|
|
108209
|
-
let gone;
|
|
108210
|
-
const waiting2 = /* @__PURE__ */ new Map();
|
|
108211
|
-
const send2 = (msg) => {
|
|
108212
|
-
if (gone) return;
|
|
108213
|
-
try {
|
|
108214
|
-
stdin.write(`${JSON.stringify(dialect.jsonrpc ? { jsonrpc: "2.0", ...msg } : msg)}
|
|
108215
|
-
`);
|
|
108216
|
-
} catch {
|
|
108217
|
-
}
|
|
108218
|
-
};
|
|
108219
|
-
const closed = (why) => {
|
|
108220
|
-
if (gone) return;
|
|
108221
|
-
gone = why;
|
|
108222
|
-
for (const { fail } of waiting2.values()) fail(why);
|
|
108223
|
-
waiting2.clear();
|
|
108224
|
-
};
|
|
108225
|
-
stdout.on("data", (chunk) => {
|
|
108226
|
-
buf += chunk.toString();
|
|
108227
|
-
const lines = buf.split("\n");
|
|
108228
|
-
buf = lines.pop() ?? "";
|
|
108229
|
-
for (const line of lines) {
|
|
108230
|
-
if (!line.trim()) continue;
|
|
108231
|
-
let msg;
|
|
108232
|
-
try {
|
|
108233
|
-
msg = JSON.parse(line);
|
|
108234
|
-
} catch {
|
|
108235
|
-
continue;
|
|
108236
|
-
}
|
|
108237
|
-
if (msg.method) {
|
|
108238
|
-
onCall(msg);
|
|
108239
|
-
continue;
|
|
108240
|
-
}
|
|
108241
|
-
if (msg.id === void 0) continue;
|
|
108242
|
-
const pending = waiting2.get(String(msg.id));
|
|
108243
|
-
if (!pending) continue;
|
|
108244
|
-
waiting2.delete(String(msg.id));
|
|
108245
|
-
if (msg.error) {
|
|
108246
|
-
const said = [str(msg.error.message), str(obj(msg.error.data).message)].filter(Boolean).join(": ");
|
|
108247
|
-
pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code, msg.error.data));
|
|
108248
|
-
} else pending.ok(obj(msg.result));
|
|
108249
|
-
}
|
|
108250
|
-
});
|
|
108251
|
-
stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", level: 2, reason: "The agent closed the connection." })));
|
|
108252
|
-
stdout.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
|
|
108253
|
-
stdin.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
|
|
108254
|
-
return {
|
|
108255
|
-
/** Ask the agent something. Rejects with the agent's own words when it says no. */
|
|
108256
|
-
call(method, params) {
|
|
108257
|
-
if (gone) return Promise.reject(gone);
|
|
108258
|
-
const id2 = dialect.stringIds ? String(nextId++) : nextId++;
|
|
108259
|
-
return new Promise((ok, fail) => {
|
|
108260
|
-
waiting2.set(String(id2), { ok, fail });
|
|
108261
|
-
send2({ id: id2, method, params });
|
|
108262
|
-
});
|
|
108263
|
-
},
|
|
108264
|
-
notify(method, params = {}) {
|
|
108265
|
-
send2({ method, params });
|
|
108266
|
-
},
|
|
108267
|
-
/** Answer something the agent asked us. */
|
|
108268
|
-
reply(id2, result) {
|
|
108269
|
-
send2({ id: id2, result });
|
|
108270
|
-
},
|
|
108271
|
-
/** Say we can't. Sent for anything we never offered to do, so the agent gets an answer
|
|
108272
|
-
* rather than waiting on one forever. */
|
|
108273
|
-
refuse(id2, message) {
|
|
108274
|
-
send2({ id: id2, error: { code: -32601, message } });
|
|
108275
|
-
}
|
|
107892
|
+
...goal,
|
|
107893
|
+
studio: studio ?? workflow,
|
|
107894
|
+
...plan === void 0 ? {} : { review_plan: plan },
|
|
107895
|
+
task: typeof task === "string" ? { id: task } : task ?? null
|
|
108276
107896
|
};
|
|
108277
107897
|
}
|
|
108278
|
-
|
|
108279
|
-
|
|
108280
|
-
|
|
108281
|
-
var liveBackend = (backend) => !connectionStopped(backend);
|
|
108282
|
-
function readPrivate(file3) {
|
|
108283
|
-
try {
|
|
108284
|
-
return JSON.parse(fs6.readFileSync(file3, "utf8"));
|
|
108285
|
-
} catch (error63) {
|
|
108286
|
-
if (error63.code === "ENOENT") return;
|
|
108287
|
-
throw error63;
|
|
108288
|
-
}
|
|
108289
|
-
}
|
|
108290
|
-
function stopNativeBackends() {
|
|
108291
|
-
let files = [];
|
|
108292
|
-
try {
|
|
108293
|
-
files = fs6.readdirSync(nativeDirectory()).filter((name) => /^[a-f0-9]{64}\.json$/.test(name));
|
|
108294
|
-
} catch {
|
|
108295
|
-
return [];
|
|
107898
|
+
function decodeGoals({ goals, ideas, ...rest }) {
|
|
107899
|
+
if (goals !== void 0 && ideas !== void 0 && JSON.stringify(goals) !== JSON.stringify(ideas)) {
|
|
107900
|
+
throw new Error("goals and ideas do not match.");
|
|
108296
107901
|
}
|
|
108297
|
-
const
|
|
108298
|
-
|
|
108299
|
-
|
|
108300
|
-
|
|
108301
|
-
targets.push(backend);
|
|
108302
|
-
try {
|
|
108303
|
-
process.kill(backend.pid, "SIGTERM");
|
|
108304
|
-
} catch {
|
|
108305
|
-
}
|
|
108306
|
-
}
|
|
108307
|
-
}
|
|
108308
|
-
return targets;
|
|
108309
|
-
}
|
|
108310
|
-
|
|
108311
|
-
// ../runner/src/settings-control.ts
|
|
108312
|
-
var directory = () => path9.join(runnerHome(), "executors");
|
|
108313
|
-
var epochFile = () => path9.join(runnerHome(), "account-generation");
|
|
108314
|
-
function accountGeneration() {
|
|
108315
|
-
try {
|
|
108316
|
-
return fs7.readFileSync(epochFile(), "utf8");
|
|
108317
|
-
} catch {
|
|
108318
|
-
return "";
|
|
108319
|
-
}
|
|
108320
|
-
}
|
|
108321
|
-
async function stopExecutors() {
|
|
108322
|
-
fs7.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
|
|
108323
|
-
fs7.writeFileSync(epochFile(), `${Date.now()}-${process.pid}`, { mode: 384 });
|
|
108324
|
-
const backends = stopNativeBackends();
|
|
108325
|
-
for (let n = 0; n < 160; n++) {
|
|
108326
|
-
const active = fs7.existsSync(directory()) ? fs7.readdirSync(directory()).filter((name) => {
|
|
108327
|
-
try {
|
|
108328
|
-
process.kill(Number(name.split(".")[0]), 0);
|
|
108329
|
-
return true;
|
|
108330
|
-
} catch {
|
|
108331
|
-
fs7.rmSync(path9.join(directory(), name), { force: true });
|
|
108332
|
-
return false;
|
|
108333
|
-
}
|
|
108334
|
-
}) : [];
|
|
108335
|
-
if (!active.length && backends.every((backend) => !liveBackend(backend))) return true;
|
|
108336
|
-
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
108337
|
-
}
|
|
108338
|
-
return false;
|
|
108339
|
-
}
|
|
108340
|
-
|
|
108341
|
-
// ../runner/src/goals.ts
|
|
108342
|
-
function goalsOf(held2) {
|
|
108343
|
-
if (held2.goals !== void 0 && held2.ideas !== void 0 && JSON.stringify(held2.goals) !== JSON.stringify(held2.ideas)) throw new Error("goals and ideas do not match.");
|
|
108344
|
-
const goals = held2.goals ?? held2.ideas;
|
|
108345
|
-
if (!Array.isArray(goals)) throw new Error("The goals array is missing or invalid.");
|
|
108346
|
-
return goals;
|
|
107902
|
+
const entries = goals ?? ideas;
|
|
107903
|
+
if (!Array.isArray(entries)) throw new Error("The goals array is missing or invalid.");
|
|
107904
|
+
const field = goals === void 0 ? "ideas" : "goals";
|
|
107905
|
+
return { field, value: { ...rest, goals: entries.map(readGoal) } };
|
|
108347
107906
|
}
|
|
108348
107907
|
|
|
108349
107908
|
// ../runner/src/api.ts
|
|
@@ -108395,6 +107954,14 @@ async function request(method, route, body, signedIn = true) {
|
|
|
108395
107954
|
}
|
|
108396
107955
|
var FILE_TIMEOUT_MS = 10 * 6e4;
|
|
108397
107956
|
var readRunner = () => request("GET", "/v1/runner");
|
|
107957
|
+
function decodeAnswer(answer, decode5) {
|
|
107958
|
+
if (!answer.ok) return answer;
|
|
107959
|
+
try {
|
|
107960
|
+
return { ok: true, value: decode5(answer.value) };
|
|
107961
|
+
} catch (e) {
|
|
107962
|
+
return { ok: false, code: "bad_response", error: String(e) };
|
|
107963
|
+
}
|
|
107964
|
+
}
|
|
108398
107965
|
var q = encodeURIComponent;
|
|
108399
107966
|
var listFolders = (machineId2) => request("GET", `/v1/runner/folders?machine=${q(machineId2)}`);
|
|
108400
107967
|
var listElsewhere = (machineId2) => request("GET", `/v1/runner/folders?machine=${q(machineId2)}&elsewhere=1`);
|
|
@@ -108407,41 +107974,32 @@ async function createProject(name, workspace, key) {
|
|
|
108407
107974
|
}
|
|
108408
107975
|
var removeFolder = (machineId2, project) => request("POST", `/v1/runner/folders/${q(project)}/remove`, { machineId: machineId2 });
|
|
108409
107976
|
var listStudios = (workspace, after) => request("GET", `/v1/studios?workspace=${q(workspace)}&limit=100${after ? `&after=${q(after)}` : ""}`);
|
|
108410
|
-
var
|
|
108411
|
-
|
|
108412
|
-
|
|
108413
|
-
|
|
108414
|
-
|
|
108415
|
-
const d = answer.value;
|
|
108416
|
-
if (d.goals !== void 0) goalDiscussions.add(d.id);
|
|
108417
|
-
else goalDiscussions.delete(d.id);
|
|
108418
|
-
try {
|
|
108419
|
-
return { ...answer, value: { ...d, goals: goalsOf(d) } };
|
|
108420
|
-
} catch (e) {
|
|
108421
|
-
return { ok: false, code: "bad_response", error: String(e) };
|
|
108422
|
-
}
|
|
107977
|
+
var discussionFields = /* @__PURE__ */ new Map();
|
|
107978
|
+
function readDiscussionGoals(d) {
|
|
107979
|
+
const { field, value } = decodeGoals(d);
|
|
107980
|
+
discussionFields.set(value.id, field);
|
|
107981
|
+
return value;
|
|
108423
107982
|
}
|
|
108424
|
-
var openDiscussion = async (
|
|
108425
|
-
var readDiscussion = async (id2) =>
|
|
107983
|
+
var openDiscussion = async (project, requestId, host2 = "claude-code") => decodeAnswer(await request("POST", "/v1/discussions/external", { ...project ? { project } : {}, requestId, host: host2 }), readDiscussionGoals);
|
|
107984
|
+
var readDiscussion = async (id2) => decodeAnswer(await request("GET", `/v1/discussions/${q(id2)}`), readDiscussionGoals);
|
|
108426
107985
|
async function saveDraft(id2, expectedVersion, goals) {
|
|
108427
|
-
const
|
|
107986
|
+
const field = discussionFields.get(id2) ?? "ideas";
|
|
107987
|
+
const sent = await send("PUT", `/v1/discussions/${q(id2)}/draft`, { expectedVersion, [field]: goals }, true, TIMEOUT_MS);
|
|
108428
107988
|
if (!sent.ok) return sent;
|
|
108429
|
-
if (sent.value.status !== 409) return
|
|
107989
|
+
if (sent.value.status !== 409) return decodeAnswer(await answerOf(sent.value), readDiscussionGoals);
|
|
108430
107990
|
const answer = await sent.value.json().catch(() => null);
|
|
108431
|
-
|
|
108432
|
-
|
|
108433
|
-
|
|
108434
|
-
|
|
108435
|
-
}
|
|
108436
|
-
return { ok: false, error: answer?.error?.message ?? "Cloud answered 409", code: answer?.error?.code ?? "refused", ...answer?.discussion ? { discussion: answer.discussion } : {} };
|
|
107991
|
+
const refusal3 = { ok: false, error: answer?.error?.message ?? "Cloud answered 409", code: answer?.error?.code ?? "refused" };
|
|
107992
|
+
if (!answer?.discussion) return refusal3;
|
|
107993
|
+
const normalized = decodeAnswer({ ok: true, value: answer.discussion }, readDiscussionGoals);
|
|
107994
|
+
return normalized.ok ? { ...refusal3, discussion: normalized.value } : normalized;
|
|
108437
107995
|
}
|
|
108438
107996
|
|
|
108439
107997
|
// ../cli/src/lib/shared/board-conflicts.ts
|
|
108440
107998
|
var import_yaml7 = __toESM(require_dist2(), 1);
|
|
108441
107999
|
|
|
108442
108000
|
// ../cli/src/lib/agent/cloud-studios.ts
|
|
108443
|
-
import
|
|
108444
|
-
import
|
|
108001
|
+
import fs10 from "node:fs";
|
|
108002
|
+
import path12 from "node:path";
|
|
108445
108003
|
|
|
108446
108004
|
// ../cli/src/lib/shared/file-limits.ts
|
|
108447
108005
|
var BOARD_FILE_LIMIT = 10 * 1024 * 1024;
|
|
@@ -108467,8 +108025,8 @@ var studioName = (id2) => id2.startsWith("wf_builtin_") ? id2.slice("wf_builtin_
|
|
|
108467
108025
|
|
|
108468
108026
|
// ../official/pack.ts
|
|
108469
108027
|
import crypto2 from "node:crypto";
|
|
108470
|
-
import
|
|
108471
|
-
import
|
|
108028
|
+
import fs6 from "node:fs";
|
|
108029
|
+
import path7 from "node:path";
|
|
108472
108030
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
108473
108031
|
|
|
108474
108032
|
// ../cli/src/lib/agent/studio-def.ts
|
|
@@ -108624,7 +108182,28 @@ var STUDIO_SCHEMA = {
|
|
|
108624
108182
|
}
|
|
108625
108183
|
};
|
|
108626
108184
|
var validate3 = new import_ajv2.Ajv({ allErrors: true, meta: false, validateSchema: false }).compile(STUDIO_SCHEMA);
|
|
108627
|
-
function
|
|
108185
|
+
function landSections(body, previews) {
|
|
108186
|
+
const blank = (text3) => text3.replace(/[^\r\n]/g, " ");
|
|
108187
|
+
let visible = "", at = 0;
|
|
108188
|
+
for (const { start, end } of previews) {
|
|
108189
|
+
visible += body.slice(at, start) + blank(body.slice(start, end));
|
|
108190
|
+
at = end;
|
|
108191
|
+
}
|
|
108192
|
+
visible += body.slice(at);
|
|
108193
|
+
const comments = /<!--[^]*?(?:-->|$)/g;
|
|
108194
|
+
const markdown = withoutCode(visible).replace(comments, blank);
|
|
108195
|
+
const headings = [...markdown.matchAll(/^ {0,3}#{1,2}(?=[ \t\r\n]|$)[^\r\n]*/gm)];
|
|
108196
|
+
return headings.flatMap((heading, index) => {
|
|
108197
|
+
const start = heading.index;
|
|
108198
|
+
const end = start + heading[0].length;
|
|
108199
|
+
if (!/^ {0,3}##[ \t]+Land(?:[ \t]+#+)?[ \t]*$/.test(visible.slice(start, end))) return [];
|
|
108200
|
+
return [{
|
|
108201
|
+
offset: start + heading[0].indexOf("#"),
|
|
108202
|
+
empty: !visible.slice(end, headings[index + 1]?.index).replace(comments, "").trim()
|
|
108203
|
+
}];
|
|
108204
|
+
});
|
|
108205
|
+
}
|
|
108206
|
+
function parseStudioFile(id2, source, from, { requirePreviewCopy = false, requireLand = false } = {}) {
|
|
108628
108207
|
const problems = [];
|
|
108629
108208
|
const fail = (offset, path38, code, message, hint2) => problems.push({ file: from, ...sourcePosition(source, offset), path: path38, code, message, hint: hint2 });
|
|
108630
108209
|
const result = () => ({ problem: problems.map((p) => `${p.file}:${p.line}:${p.column} ${p.path}: ${p.code} \u2014 ${p.message}. ${p.hint}`).join("\n"), problems });
|
|
@@ -108676,6 +108255,14 @@ function parseStudioFile(id2, source, from, requirePreviewCopy = false) {
|
|
|
108676
108255
|
);
|
|
108677
108256
|
}
|
|
108678
108257
|
}
|
|
108258
|
+
if (requireLand) {
|
|
108259
|
+
const sections = landSections(body, parsed.blocks);
|
|
108260
|
+
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.");
|
|
108261
|
+
for (const [index, { offset, empty }] of sections.entries()) {
|
|
108262
|
+
if (index) fail(bodyOffset + offset, "Land", "studio-land-duplicate", "Repeated ## Land section", "Combine delivery instructions under one ## Land heading.");
|
|
108263
|
+
if (empty) fail(bodyOffset + offset, "Land", "studio-land-empty", "The ## Land section is empty", "Describe delivery, checks and what to record under ## Land.");
|
|
108264
|
+
}
|
|
108265
|
+
}
|
|
108679
108266
|
if (problems.length) return result();
|
|
108680
108267
|
let rules = "", at = 0;
|
|
108681
108268
|
for (const block of parsed.blocks) {
|
|
@@ -108696,11 +108283,11 @@ function parseStudioFile(id2, source, from, requirePreviewCopy = false) {
|
|
|
108696
108283
|
}
|
|
108697
108284
|
|
|
108698
108285
|
// ../cli/src/lib/agent/studio-folder.ts
|
|
108699
|
-
import
|
|
108700
|
-
import
|
|
108286
|
+
import fs5 from "node:fs";
|
|
108287
|
+
import path6 from "node:path";
|
|
108701
108288
|
|
|
108702
108289
|
// ../cli/src/lib/shared/guide-topics.ts
|
|
108703
|
-
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", "
|
|
108290
|
+
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"];
|
|
108704
108291
|
|
|
108705
108292
|
// ../cli/src/lib/shared/studio-files.ts
|
|
108706
108293
|
var STUDIO_FILE = "STUDIO.md";
|
|
@@ -108743,12 +108330,16 @@ function mcpProblem(text3) {
|
|
|
108743
108330
|
}
|
|
108744
108331
|
return null;
|
|
108745
108332
|
}
|
|
108746
|
-
function
|
|
108747
|
-
const
|
|
108333
|
+
function formatStudioProblem({ file: file3, line, column, reason, hint: hint2 }) {
|
|
108334
|
+
const location = line === void 0 ? file3 : `${file3}:${line}:${column ?? 1}`;
|
|
108335
|
+
return `${location}: ${reason}${hint2 ? `. ${hint2}` : ""}`;
|
|
108336
|
+
}
|
|
108337
|
+
function checkStudioFiles(value, official = false, checks = {}) {
|
|
108338
|
+
const read3 = inspect(value, official, checks);
|
|
108748
108339
|
const first = read3.problems[0];
|
|
108749
108340
|
return first ? { ok: false, ...first, problems: read3.problems } : { ok: true, def: read3.def, files: read3.files };
|
|
108750
108341
|
}
|
|
108751
|
-
function inspect(value, official, allowLegacyPreviewCopy =
|
|
108342
|
+
function inspect(value, official, { allowLegacyPreviewCopy, allowLegacyLand } = {}) {
|
|
108752
108343
|
const problems = [];
|
|
108753
108344
|
const fail = (file3, reason, tooLarge = false) => {
|
|
108754
108345
|
problems.push({ file: file3, reason, ...tooLarge ? { tooLarge } : {} });
|
|
@@ -108793,7 +108384,7 @@ function inspect(value, official, allowLegacyPreviewCopy = false) {
|
|
|
108793
108384
|
if (files[`skills/${name}/SKILL.md`] === void 0) fail(`skills/${name}/SKILL.md`, "is missing");
|
|
108794
108385
|
}
|
|
108795
108386
|
const source = files[STUDIO_FILE];
|
|
108796
|
-
const read3 = typeof source === "string" ? parseStudioFile("studio", source, STUDIO_FILE, !official && !allowLegacyPreviewCopy) : null;
|
|
108387
|
+
const read3 = typeof source === "string" ? parseStudioFile("studio", source, STUDIO_FILE, { requirePreviewCopy: !official && !allowLegacyPreviewCopy, requireLand: !allowLegacyLand }) : null;
|
|
108797
108388
|
if (!read3) fail(STUDIO_FILE, "is missing");
|
|
108798
108389
|
else if ("problem" in read3) for (const problem of read3.problems) problems.push({ ...problem, reason: problem.message });
|
|
108799
108390
|
if (!read3 || "problem" in read3) return { problems };
|
|
@@ -108827,31 +108418,31 @@ function inspect(value, official, allowLegacyPreviewCopy = false) {
|
|
|
108827
108418
|
// ../cli/src/lib/agent/studio-folder.ts
|
|
108828
108419
|
var MIME = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp" };
|
|
108829
108420
|
function filesOf(dir, base = dir) {
|
|
108830
|
-
return
|
|
108831
|
-
const full =
|
|
108421
|
+
return fs5.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
|
|
108422
|
+
const full = path6.join(dir, e.name);
|
|
108832
108423
|
if (e.isSymbolicLink()) throw new Error(`${full}: symbolic links are not allowed`);
|
|
108833
|
-
return e.isDirectory() ? filesOf(full, base) : [
|
|
108424
|
+
return e.isDirectory() ? filesOf(full, base) : [path6.relative(base, full).split(path6.sep).join("/")];
|
|
108834
108425
|
});
|
|
108835
108426
|
}
|
|
108836
108427
|
function readStudioFile(dir, file3) {
|
|
108837
|
-
const full =
|
|
108838
|
-
return isAboutFile(file3) && !file3.endsWith(".md") ? `data:${MIME[
|
|
108428
|
+
const full = path6.join(dir, file3);
|
|
108429
|
+
return isAboutFile(file3) && !file3.endsWith(".md") ? `data:${MIME[path6.extname(file3)]};base64,${fs5.readFileSync(full).toString("base64")}` : fs5.readFileSync(full, "utf8");
|
|
108839
108430
|
}
|
|
108840
108431
|
var readStudioFolder = (dir) => Object.fromEntries(filesOf(dir).sort().map((f) => [f, readStudioFile(dir, f)]));
|
|
108841
108432
|
|
|
108842
108433
|
// ../official/pack.ts
|
|
108843
|
-
var OFFICIAL =
|
|
108844
|
-
var dirs = (dir) =>
|
|
108434
|
+
var OFFICIAL = path7.dirname(fileURLToPath2(import.meta.url));
|
|
108435
|
+
var dirs = (dir) => fs6.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
108845
108436
|
var hashOf = (files) => crypto2.createHash("sha256").update(hashInput(files)).digest("hex");
|
|
108846
108437
|
function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
108847
|
-
const studiosDir =
|
|
108438
|
+
const studiosDir = path7.join(root2, "studios");
|
|
108848
108439
|
return dirs(studiosDir).map((folder2) => {
|
|
108849
|
-
const files = readStudioFolder(
|
|
108440
|
+
const files = readStudioFolder(path7.join(studiosDir, folder2));
|
|
108850
108441
|
const parsed = parseStudioFile(folder2, files[STUDIO_FILE] ?? "", STUDIO_FILE);
|
|
108851
108442
|
if ("problem" in parsed) throw new Error(parsed.problem);
|
|
108852
108443
|
const def = parsed.def;
|
|
108853
108444
|
const checked = loose ? { ok: true } : checkStudioFiles(files, true);
|
|
108854
|
-
if (!checked.ok) throw new Error(`official/studios/${folder2}: ${checked
|
|
108445
|
+
if (!checked.ok) throw new Error(`official/studios/${folder2}: ${formatStudioProblem(checked)}`);
|
|
108855
108446
|
if (!def.names?.zh && !loose) throw new Error(`official/studios/${folder2}/${STUDIO_FILE}: add its Chinese name under \`names: zh\``);
|
|
108856
108447
|
return {
|
|
108857
108448
|
id: officialId(folder2),
|
|
@@ -108867,23 +108458,23 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
|
108867
108458
|
}
|
|
108868
108459
|
|
|
108869
108460
|
// ../cli/src/lib/cloud/tasks.ts
|
|
108870
|
-
import
|
|
108871
|
-
import
|
|
108461
|
+
import fs7 from "node:fs";
|
|
108462
|
+
import path8 from "node:path";
|
|
108872
108463
|
var TASK_ENV = "AI4KANBAN_TASK";
|
|
108873
108464
|
function workspaceTask() {
|
|
108874
108465
|
const id2 = process.env[TASK_ENV];
|
|
108875
108466
|
return id2 && id2.trim() ? id2.trim() : null;
|
|
108876
108467
|
}
|
|
108877
108468
|
function runnerProject(board) {
|
|
108878
|
-
if (
|
|
108879
|
-
const linked2 = linkedProject(board,
|
|
108469
|
+
if (path8.basename(board) !== "kanban" || path8.basename(path8.dirname(board)) !== ".akb") return null;
|
|
108470
|
+
const linked2 = linkedProject(board, path8.dirname(path8.dirname(board)));
|
|
108880
108471
|
return linked2.ok ? linked2.value : null;
|
|
108881
108472
|
}
|
|
108882
108473
|
function linkedProject(board, root2) {
|
|
108883
|
-
const file3 =
|
|
108884
|
-
if (!
|
|
108474
|
+
const file3 = path8.join(root2, ".akb", "base.json");
|
|
108475
|
+
if (!fs7.existsSync(file3)) return { ok: true, value: null };
|
|
108885
108476
|
try {
|
|
108886
|
-
const base = JSON.parse(
|
|
108477
|
+
const base = JSON.parse(fs7.readFileSync(file3, "utf8"));
|
|
108887
108478
|
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();
|
|
108888
108479
|
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p) => /^projects\/([^/]+)\//.exec(p)?.[1] ?? []));
|
|
108889
108480
|
if (typeof base.project === "string") projects.add(base.project);
|
|
@@ -108895,14 +108486,14 @@ function linkedProject(board, root2) {
|
|
|
108895
108486
|
}
|
|
108896
108487
|
|
|
108897
108488
|
// ../cli/src/lib/file-memo.ts
|
|
108898
|
-
import
|
|
108899
|
-
import
|
|
108489
|
+
import fs8 from "node:fs";
|
|
108490
|
+
import path9 from "node:path";
|
|
108900
108491
|
function stamp(paths) {
|
|
108901
108492
|
const parts = [];
|
|
108902
108493
|
const visit2 = (p) => {
|
|
108903
108494
|
let st;
|
|
108904
108495
|
try {
|
|
108905
|
-
st =
|
|
108496
|
+
st = fs8.statSync(p, { bigint: true });
|
|
108906
108497
|
} catch {
|
|
108907
108498
|
parts.push(`${p}:-`);
|
|
108908
108499
|
return;
|
|
@@ -108914,11 +108505,11 @@ function stamp(paths) {
|
|
|
108914
108505
|
parts.push(`${p}/`);
|
|
108915
108506
|
let names;
|
|
108916
108507
|
try {
|
|
108917
|
-
names =
|
|
108508
|
+
names = fs8.readdirSync(p).sort();
|
|
108918
108509
|
} catch {
|
|
108919
108510
|
return;
|
|
108920
108511
|
}
|
|
108921
|
-
for (const name of names) if (name !== "node_modules" && name !== ".git") visit2(
|
|
108512
|
+
for (const name of names) if (name !== "node_modules" && name !== ".git") visit2(path9.join(p, name));
|
|
108922
108513
|
};
|
|
108923
108514
|
for (const p of paths) visit2(p);
|
|
108924
108515
|
return parts.join("\n");
|
|
@@ -108959,16 +108550,179 @@ function memoByFiles(paths, read3) {
|
|
|
108959
108550
|
};
|
|
108960
108551
|
}
|
|
108961
108552
|
|
|
108553
|
+
// ../cli/src/lib/paths.ts
|
|
108554
|
+
import path11 from "node:path";
|
|
108555
|
+
|
|
108556
|
+
// ../cli/src/lib/io.ts
|
|
108557
|
+
var BoardError = class extends Error {
|
|
108558
|
+
// `kind` is the machine-readable name of the refusal (card-not-found, no-board,
|
|
108559
|
+
// unknown-module, …). It is what a caller reads; the exit code stays 1 for every
|
|
108560
|
+
// refusal, so nobody has to keep a table of numbers.
|
|
108561
|
+
kind;
|
|
108562
|
+
// Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
|
|
108563
|
+
exitCode;
|
|
108564
|
+
// `bare` says the message is already the whole thing a person should see — a usage
|
|
108565
|
+
// block, say — so the dispatcher prints it without putting the command in front of it.
|
|
108566
|
+
bare;
|
|
108567
|
+
details;
|
|
108568
|
+
constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
|
|
108569
|
+
super(message);
|
|
108570
|
+
this.name = "BoardError";
|
|
108571
|
+
this.kind = kind;
|
|
108572
|
+
this.bare = bare;
|
|
108573
|
+
this.exitCode = exitCode;
|
|
108574
|
+
this.details = details;
|
|
108575
|
+
}
|
|
108576
|
+
};
|
|
108577
|
+
|
|
108578
|
+
// ../cli/src/lib/machine/project.ts
|
|
108579
|
+
import fs9 from "node:fs";
|
|
108580
|
+
import path10 from "node:path";
|
|
108581
|
+
var SESSIONS_FILE = "sessions.json";
|
|
108582
|
+
var SESSIONS_FOLDER = "sessions";
|
|
108583
|
+
var ASSETS_FOLDER = "assets";
|
|
108584
|
+
var SESSIONS_LOCK = "sessions.lock";
|
|
108585
|
+
var INDEX_LOCK = "index.lock";
|
|
108586
|
+
var UI_CONFIG_FILE = "ui.config.json";
|
|
108587
|
+
function realPathOf(dir) {
|
|
108588
|
+
const here2 = path10.resolve(dir);
|
|
108589
|
+
const rest = [];
|
|
108590
|
+
let at = here2;
|
|
108591
|
+
for (; ; ) {
|
|
108592
|
+
try {
|
|
108593
|
+
return path10.join(fs9.realpathSync(at), ...rest);
|
|
108594
|
+
} catch {
|
|
108595
|
+
const up = path10.dirname(at);
|
|
108596
|
+
if (up === at) return here2;
|
|
108597
|
+
rest.unshift(path10.basename(at));
|
|
108598
|
+
at = up;
|
|
108599
|
+
}
|
|
108600
|
+
}
|
|
108601
|
+
}
|
|
108602
|
+
function stateRootOf(board) {
|
|
108603
|
+
let dir = realPathOf(board);
|
|
108604
|
+
for (; ; ) {
|
|
108605
|
+
if (fs9.existsSync(path10.join(dir, ".git"))) return dir;
|
|
108606
|
+
const up = path10.dirname(dir);
|
|
108607
|
+
if (up === dir) break;
|
|
108608
|
+
dir = up;
|
|
108609
|
+
}
|
|
108610
|
+
return rootAbove(realPathOf(board));
|
|
108611
|
+
}
|
|
108612
|
+
function rootAbove(board) {
|
|
108613
|
+
const parent = path10.dirname(board);
|
|
108614
|
+
return ["docs", ".akb"].includes(path10.basename(parent)) ? path10.dirname(parent) : parent;
|
|
108615
|
+
}
|
|
108616
|
+
function projectStateDir(board, root2 = stateRootOf(board)) {
|
|
108617
|
+
const relative = path10.relative(realPathOf(root2), realPathOf(board));
|
|
108618
|
+
if (relative === ".." || relative.startsWith(`..${path10.sep}`) || path10.isAbsolute(relative)) {
|
|
108619
|
+
throw new Error("The board must be inside its project root.");
|
|
108620
|
+
}
|
|
108621
|
+
return path10.join(realPathOf(root2), ".akb", "boards", relative || "_root");
|
|
108622
|
+
}
|
|
108623
|
+
|
|
108624
|
+
// ../cli/src/lib/paths.ts
|
|
108625
|
+
var REPO_ROOT = "";
|
|
108626
|
+
var KANBAN = "";
|
|
108627
|
+
var TODO = "";
|
|
108628
|
+
var ARCHIVE = "";
|
|
108629
|
+
var ARCHIVE_MD = "";
|
|
108630
|
+
var README = "";
|
|
108631
|
+
var MODULES_MD = "";
|
|
108632
|
+
var CONFIG = "";
|
|
108633
|
+
var KANBAN_GITIGNORE = "";
|
|
108634
|
+
var RELEASES = "";
|
|
108635
|
+
var RELEASE_SUMMARIES = "";
|
|
108636
|
+
var AGENTS = "";
|
|
108637
|
+
var STUDIOS = "";
|
|
108638
|
+
var ASSETS = "";
|
|
108639
|
+
var BOARD_STATE = "";
|
|
108640
|
+
var MEMORY = "";
|
|
108641
|
+
var AGENT_MEMORY = "";
|
|
108642
|
+
var PROJECT_MD = "";
|
|
108643
|
+
var LOCK = "";
|
|
108644
|
+
var UI_CONFIG = "";
|
|
108645
|
+
var ENV_FILE = "";
|
|
108646
|
+
var SESSIONS = "";
|
|
108647
|
+
var SESSIONS_DIR = "";
|
|
108648
|
+
var SESSIONS_LOCK2 = "";
|
|
108649
|
+
var INDEX_LOCK2 = "";
|
|
108650
|
+
var DELIVERIES = "";
|
|
108651
|
+
var PLANS = "";
|
|
108652
|
+
var PLANS_ARCHIVE = "";
|
|
108653
|
+
var RULES = "";
|
|
108654
|
+
var TRIAGE = "";
|
|
108655
|
+
var SIGNALS_ARCHIVED = "";
|
|
108656
|
+
var SIGNALS_DISMISSED = "";
|
|
108657
|
+
var SIGNALS_FILES = "";
|
|
108658
|
+
var SIGNALS_OLD_INBOX = "";
|
|
108659
|
+
var SIGNALS_OLD_HANDLED = "";
|
|
108660
|
+
var AKB_DIR = "";
|
|
108661
|
+
var ROOT_GITIGNORE = "";
|
|
108662
|
+
function boardLockName(kanban, root2) {
|
|
108663
|
+
const from = path11.relative(root2, kanban);
|
|
108664
|
+
const name = from && !from.startsWith("..") ? from : path11.basename(kanban);
|
|
108665
|
+
return `${name.split(path11.sep).join("-")}.lock`;
|
|
108666
|
+
}
|
|
108667
|
+
var BOARD_FLAG = "";
|
|
108668
|
+
function setBoard(kanban, root2, flag) {
|
|
108669
|
+
REPO_ROOT = path11.resolve(root2);
|
|
108670
|
+
KANBAN = path11.resolve(kanban);
|
|
108671
|
+
BOARD_FLAG = flag;
|
|
108672
|
+
TODO = path11.join(KANBAN, "todo");
|
|
108673
|
+
ARCHIVE = path11.join(KANBAN, ".archive");
|
|
108674
|
+
ARCHIVE_MD = path11.join(KANBAN, "archive.md");
|
|
108675
|
+
README = path11.join(TODO, "README.md");
|
|
108676
|
+
MODULES_MD = path11.join(KANBAN, "modules.md");
|
|
108677
|
+
CONFIG = path11.join(KANBAN, "config.md");
|
|
108678
|
+
KANBAN_GITIGNORE = path11.join(KANBAN, ".gitignore");
|
|
108679
|
+
RELEASES = path11.join(KANBAN, "releases.md");
|
|
108680
|
+
RELEASE_SUMMARIES = path11.join(KANBAN, ".release-summaries");
|
|
108681
|
+
AGENTS = path11.join(KANBAN, "agents");
|
|
108682
|
+
STUDIOS = path11.join(KANBAN, "studios");
|
|
108683
|
+
MEMORY = path11.join(KANBAN, "memory");
|
|
108684
|
+
AGENT_MEMORY = path11.join(MEMORY, "agents");
|
|
108685
|
+
PROJECT_MD = path11.join(MEMORY, "project.md");
|
|
108686
|
+
ENV_FILE = path11.join(KANBAN, ".env");
|
|
108687
|
+
const machine = projectStateDir(KANBAN, REPO_ROOT);
|
|
108688
|
+
BOARD_STATE = machine;
|
|
108689
|
+
UI_CONFIG = path11.join(machine, UI_CONFIG_FILE);
|
|
108690
|
+
ASSETS = path11.join(machine, ASSETS_FOLDER);
|
|
108691
|
+
SESSIONS = path11.join(machine, SESSIONS_FILE);
|
|
108692
|
+
SESSIONS_DIR = path11.join(machine, SESSIONS_FOLDER);
|
|
108693
|
+
SESSIONS_LOCK2 = path11.join(machine, SESSIONS_LOCK);
|
|
108694
|
+
INDEX_LOCK2 = path11.join(machine, INDEX_LOCK);
|
|
108695
|
+
DELIVERIES = path11.join(KANBAN, "deliveries");
|
|
108696
|
+
RULES = path11.join(KANBAN, "rules");
|
|
108697
|
+
PLANS = path11.join(machine, "plans");
|
|
108698
|
+
PLANS_ARCHIVE = path11.join(PLANS, "archive");
|
|
108699
|
+
TRIAGE = path11.join(KANBAN, "triage");
|
|
108700
|
+
SIGNALS_ARCHIVED = path11.join(TRIAGE, "archived");
|
|
108701
|
+
SIGNALS_DISMISSED = path11.join(TRIAGE, "dismissed");
|
|
108702
|
+
SIGNALS_FILES = path11.join(TRIAGE, "files");
|
|
108703
|
+
SIGNALS_OLD_INBOX = path11.join(TRIAGE, "inbox");
|
|
108704
|
+
SIGNALS_OLD_HANDLED = path11.join(TRIAGE, "handled.md");
|
|
108705
|
+
AKB_DIR = path11.join(REPO_ROOT, ".akb");
|
|
108706
|
+
ROOT_GITIGNORE = path11.join(REPO_ROOT, ".gitignore");
|
|
108707
|
+
LOCK = path11.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
|
|
108708
|
+
return REPO_ROOT;
|
|
108709
|
+
}
|
|
108710
|
+
function setBoardRoot(root2, named = false) {
|
|
108711
|
+
const project = path11.resolve(root2);
|
|
108712
|
+
return setBoard(path11.join(project, "docs", "kanban"), project, named ? ` --dir ${project}` : "");
|
|
108713
|
+
}
|
|
108714
|
+
setBoardRoot(process.cwd());
|
|
108715
|
+
|
|
108962
108716
|
// ../cli/src/lib/agent/cloud-studios.ts
|
|
108963
108717
|
var DEV = "AI4KANBAN_STUDIOS";
|
|
108964
|
-
var root = () =>
|
|
108718
|
+
var root = () => path12.join(machineHome(), "studios");
|
|
108965
108719
|
var safe = (name) => name.replace(/[^\w.@-]/g, "_");
|
|
108966
|
-
var versionFile = (id2, version3) =>
|
|
108967
|
-
var listFile = (project) =>
|
|
108968
|
-
var pinFile = (task) =>
|
|
108720
|
+
var versionFile = (id2, version3) => path12.join(root(), "versions", `${safe(id2)}@${version3}.json`);
|
|
108721
|
+
var listFile = (project) => path12.join(root(), "lists", `${safe(project)}.json`);
|
|
108722
|
+
var pinFile = (task) => path12.join(root(), "tasks", `${safe(task)}.json`);
|
|
108969
108723
|
function readJson(file3) {
|
|
108970
108724
|
try {
|
|
108971
|
-
return JSON.parse(
|
|
108725
|
+
return JSON.parse(fs10.readFileSync(file3, "utf8"));
|
|
108972
108726
|
} catch {
|
|
108973
108727
|
return null;
|
|
108974
108728
|
}
|
|
@@ -109011,18 +108765,31 @@ var sources = () => {
|
|
|
109011
108765
|
var flows = memoByFiles(sources, readFlows);
|
|
109012
108766
|
|
|
109013
108767
|
// ../cli/src/lib/shared/board-conflicts.ts
|
|
109014
|
-
import
|
|
109015
|
-
import
|
|
109016
|
-
|
|
108768
|
+
import fs11 from "node:fs";
|
|
108769
|
+
import path13 from "node:path";
|
|
108770
|
+
|
|
108771
|
+
// ../cli/src/lib/lock.ts
|
|
108772
|
+
function pidAlive(pid) {
|
|
108773
|
+
if (!pid) return false;
|
|
108774
|
+
try {
|
|
108775
|
+
process.kill(pid, 0);
|
|
108776
|
+
return true;
|
|
108777
|
+
} catch (e) {
|
|
108778
|
+
return e.code === "EPERM";
|
|
108779
|
+
}
|
|
108780
|
+
}
|
|
108781
|
+
|
|
108782
|
+
// ../cli/src/lib/shared/board-conflicts.ts
|
|
108783
|
+
var folder = (board) => path13.join(projectStateDir(board), "conflicts");
|
|
109017
108784
|
var fileOf = (board, id2) => {
|
|
109018
108785
|
if (!/^c_[a-f0-9]{32}$/.test(id2)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
|
|
109019
|
-
return
|
|
108786
|
+
return path13.join(folder(board), `${id2}.json`);
|
|
109020
108787
|
};
|
|
109021
108788
|
function read(board, id2) {
|
|
109022
108789
|
const file3 = fileOf(board, id2);
|
|
109023
|
-
if (!
|
|
108790
|
+
if (!fs11.existsSync(file3)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
|
|
109024
108791
|
try {
|
|
109025
|
-
const r = JSON.parse(
|
|
108792
|
+
const r = JSON.parse(fs11.readFileSync(file3, "utf8"));
|
|
109026
108793
|
if (r.id !== id2 || !r.project || !["open", "unconfirmed", "resolved"].includes(r.state) || !Array.isArray(r.files) || !r.files.length) throw Error();
|
|
109027
108794
|
const names = /* @__PURE__ */ new Set();
|
|
109028
108795
|
for (const f of r.files) {
|
|
@@ -109044,7 +108811,7 @@ function read(board, id2) {
|
|
|
109044
108811
|
function conflictRecords(board) {
|
|
109045
108812
|
let names;
|
|
109046
108813
|
try {
|
|
109047
|
-
names =
|
|
108814
|
+
names = fs11.readdirSync(folder(board));
|
|
109048
108815
|
} catch (e) {
|
|
109049
108816
|
if (e.code === "ENOENT") return [];
|
|
109050
108817
|
throw e;
|
|
@@ -109055,24 +108822,24 @@ var pendingConflicts = (board) => conflictRecords(board).filter((r) => r.state !
|
|
|
109055
108822
|
|
|
109056
108823
|
// ../runner/src/cache.ts
|
|
109057
108824
|
import crypto3 from "node:crypto";
|
|
109058
|
-
import
|
|
109059
|
-
import
|
|
108825
|
+
import fs13 from "node:fs";
|
|
108826
|
+
import path15 from "node:path";
|
|
109060
108827
|
|
|
109061
108828
|
// ../runner/src/folders.ts
|
|
109062
|
-
import
|
|
108829
|
+
import fs12 from "node:fs";
|
|
109063
108830
|
import os4 from "node:os";
|
|
109064
|
-
import
|
|
109065
|
-
var projectsFile = () =>
|
|
108831
|
+
import path14 from "node:path";
|
|
108832
|
+
var projectsFile = () => path14.join(runnerHome(), "projects.json");
|
|
109066
108833
|
function realpath(p) {
|
|
109067
108834
|
try {
|
|
109068
|
-
return
|
|
108835
|
+
return fs12.realpathSync(p);
|
|
109069
108836
|
} catch {
|
|
109070
108837
|
return null;
|
|
109071
108838
|
}
|
|
109072
108839
|
}
|
|
109073
108840
|
function readGrants() {
|
|
109074
108841
|
try {
|
|
109075
|
-
const held2 = JSON.parse(
|
|
108842
|
+
const held2 = JSON.parse(fs12.readFileSync(projectsFile(), "utf8"));
|
|
109076
108843
|
if (!Array.isArray(held2.projects)) throw new Error("invalid_projects");
|
|
109077
108844
|
return held2;
|
|
109078
108845
|
} catch (error63) {
|
|
@@ -109086,23 +108853,23 @@ function listOf(held2) {
|
|
|
109086
108853
|
return subject ? held2.accounts[subject] ?? [] : [];
|
|
109087
108854
|
}
|
|
109088
108855
|
function update(change) {
|
|
109089
|
-
|
|
108856
|
+
fs12.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
|
|
109090
108857
|
const lock = `${projectsFile()}.lock`;
|
|
109091
108858
|
let fd;
|
|
109092
108859
|
const until = Date.now() + 2e3;
|
|
109093
108860
|
for (; ; ) {
|
|
109094
108861
|
try {
|
|
109095
|
-
fd =
|
|
109096
|
-
|
|
108862
|
+
fd = fs12.openSync(lock, "wx", 384);
|
|
108863
|
+
fs12.writeFileSync(fd, String(process.pid));
|
|
109097
108864
|
break;
|
|
109098
108865
|
} catch {
|
|
109099
108866
|
try {
|
|
109100
|
-
const pid = Number(
|
|
108867
|
+
const pid = Number(fs12.readFileSync(lock, "utf8"));
|
|
109101
108868
|
if (pid > 0) {
|
|
109102
108869
|
try {
|
|
109103
108870
|
process.kill(pid, 0);
|
|
109104
108871
|
} catch {
|
|
109105
|
-
|
|
108872
|
+
fs12.rmSync(lock, { force: true });
|
|
109106
108873
|
}
|
|
109107
108874
|
}
|
|
109108
108875
|
} catch {
|
|
@@ -109125,13 +108892,13 @@ function update(change) {
|
|
|
109125
108892
|
held2.projects = after;
|
|
109126
108893
|
} else held2.projects = after;
|
|
109127
108894
|
const tmp = `${projectsFile()}.${process.pid}.tmp`;
|
|
109128
|
-
|
|
108895
|
+
fs12.writeFileSync(tmp, `${JSON.stringify(held2, null, 2)}
|
|
109129
108896
|
`, { mode: 384 });
|
|
109130
|
-
|
|
108897
|
+
fs12.renameSync(tmp, projectsFile());
|
|
109131
108898
|
return before.filter((p) => !after.includes(p));
|
|
109132
108899
|
} finally {
|
|
109133
|
-
|
|
109134
|
-
|
|
108900
|
+
fs12.closeSync(fd);
|
|
108901
|
+
fs12.rmSync(lock, { force: true });
|
|
109135
108902
|
}
|
|
109136
108903
|
}
|
|
109137
108904
|
function adoptLegacy() {
|
|
@@ -109146,9 +108913,9 @@ var SYSTEM_WIN = ["Windows", "Program Files", "Program Files (x86)", "ProgramDat
|
|
|
109146
108913
|
var here = () => ({ platform: process.platform, home: os4.homedir(), resolve: realpath });
|
|
109147
108914
|
function refusal(picked, where = here()) {
|
|
109148
108915
|
const win = where.platform === "win32";
|
|
109149
|
-
const p = win ?
|
|
108916
|
+
const p = win ? path14.win32 : path14.posix;
|
|
109150
108917
|
const real = where.resolve(picked);
|
|
109151
|
-
if (!real || !p.isAbsolute(real) || where.resolve === realpath && !
|
|
108918
|
+
if (!real || !p.isAbsolute(real) || where.resolve === realpath && !fs12.statSync(real).isDirectory()) return "missing";
|
|
109152
108919
|
const norm = (d) => {
|
|
109153
108920
|
const n = p.normalize(d).replace(/[\\/]+$/, "") || p.sep;
|
|
109154
108921
|
return win ? n.toLowerCase() : n;
|
|
@@ -109171,16 +108938,16 @@ function refusal(picked, where = here()) {
|
|
|
109171
108938
|
// ../runner/src/cache.ts
|
|
109172
108939
|
var IDLE_MS = 7 * 24 * 60 * 6e4;
|
|
109173
108940
|
var SWEEP_MS = 24 * 60 * 6e4;
|
|
109174
|
-
var akbDir = (dir) =>
|
|
109175
|
-
var unsentFile = (dir) =>
|
|
109176
|
-
var unsent = (dir) =>
|
|
108941
|
+
var akbDir = (dir) => path15.join(dir, ".akb");
|
|
108942
|
+
var unsentFile = (dir) => path15.join(akbDir(dir), "unsent");
|
|
108943
|
+
var unsent = (dir) => fs13.existsSync(unsentFile(dir));
|
|
109177
108944
|
var holds = /* @__PURE__ */ new Map();
|
|
109178
|
-
var holdsDir = () =>
|
|
109179
|
-
var holdFile = (dir) =>
|
|
108945
|
+
var holdsDir = () => path15.join(runnerHome(), "holds");
|
|
108946
|
+
var holdFile = (dir) => path15.join(holdsDir(), `${crypto3.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
|
|
109180
108947
|
function paused(dir) {
|
|
109181
108948
|
try {
|
|
109182
|
-
const file3 =
|
|
109183
|
-
const held2 = JSON.parse(
|
|
108949
|
+
const file3 = path15.join(projectStateDir(path15.join(akbDir(dir), "kanban")), SESSIONS_FILE);
|
|
108950
|
+
const held2 = JSON.parse(fs13.readFileSync(file3, "utf8"));
|
|
109184
108951
|
return (held2.deliveries ?? []).some((d) => d.status === "active");
|
|
109185
108952
|
} catch {
|
|
109186
108953
|
return false;
|
|
@@ -109188,14 +108955,14 @@ function paused(dir) {
|
|
|
109188
108955
|
}
|
|
109189
108956
|
function busy(dir) {
|
|
109190
108957
|
if (holds.has(dir)) return true;
|
|
109191
|
-
const prefix =
|
|
108958
|
+
const prefix = path15.basename(holdFile(dir)).split(".")[0] + ".";
|
|
109192
108959
|
try {
|
|
109193
|
-
return
|
|
108960
|
+
return fs13.readdirSync(holdsDir()).filter((file3) => file3.startsWith(prefix)).some((file3) => {
|
|
109194
108961
|
try {
|
|
109195
108962
|
process.kill(Number(file3.split(".")[1]), 0);
|
|
109196
108963
|
return true;
|
|
109197
108964
|
} catch {
|
|
109198
|
-
|
|
108965
|
+
fs13.rmSync(path15.join(holdsDir(), file3), { force: true });
|
|
109199
108966
|
return false;
|
|
109200
108967
|
}
|
|
109201
108968
|
});
|
|
@@ -109205,7 +108972,7 @@ function busy(dir) {
|
|
|
109205
108972
|
}
|
|
109206
108973
|
function conflicted(dir) {
|
|
109207
108974
|
try {
|
|
109208
|
-
return pendingConflicts(
|
|
108975
|
+
return pendingConflicts(path15.join(dir, ".akb", "kanban")).length > 0;
|
|
109209
108976
|
} catch {
|
|
109210
108977
|
return true;
|
|
109211
108978
|
}
|
|
@@ -109213,19 +108980,19 @@ function conflicted(dir) {
|
|
|
109213
108980
|
var kept = (dir) => busy(dir) || unsent(dir) || paused(dir) || conflicted(dir);
|
|
109214
108981
|
function clearAkb(dir) {
|
|
109215
108982
|
dir = realpath2(dir);
|
|
109216
|
-
if (kept(dir) ||
|
|
108983
|
+
if (kept(dir) || fs13.existsSync(path15.join(akbDir(dir), "worktrees")) || fs13.existsSync(path15.join(akbDir(dir), "handoffs"))) return false;
|
|
109217
108984
|
let entries;
|
|
109218
108985
|
try {
|
|
109219
|
-
entries =
|
|
108986
|
+
entries = fs13.readdirSync(akbDir(dir));
|
|
109220
108987
|
} catch {
|
|
109221
108988
|
return true;
|
|
109222
108989
|
}
|
|
109223
|
-
for (const name of entries)
|
|
108990
|
+
for (const name of entries) fs13.rmSync(path15.join(akbDir(dir), name), { recursive: true, force: true });
|
|
109224
108991
|
return true;
|
|
109225
108992
|
}
|
|
109226
108993
|
function realpath2(p) {
|
|
109227
108994
|
try {
|
|
109228
|
-
return
|
|
108995
|
+
return fs13.realpathSync(p);
|
|
109229
108996
|
} catch {
|
|
109230
108997
|
return p;
|
|
109231
108998
|
}
|
|
@@ -109233,8 +109000,8 @@ function realpath2(p) {
|
|
|
109233
109000
|
|
|
109234
109001
|
// ../runner/src/launcher.ts
|
|
109235
109002
|
import { spawn } from "node:child_process";
|
|
109236
|
-
import
|
|
109237
|
-
import
|
|
109003
|
+
import fs16 from "node:fs";
|
|
109004
|
+
import path18 from "node:path";
|
|
109238
109005
|
|
|
109239
109006
|
// ../runner/src/i18n.ts
|
|
109240
109007
|
var ZH_HOLDER = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", dsh: "dsh", zcode: "ZCode", kimi: "Kimi Code", terminal: "\u672C\u673A\u7EC8\u7AEF" };
|
|
@@ -109295,12 +109062,12 @@ function status(line) {
|
|
|
109295
109062
|
|
|
109296
109063
|
// ../runner/src/preferences.ts
|
|
109297
109064
|
import crypto4 from "node:crypto";
|
|
109298
|
-
import
|
|
109299
|
-
import
|
|
109300
|
-
var file2 = () =>
|
|
109065
|
+
import fs14 from "node:fs";
|
|
109066
|
+
import path16 from "node:path";
|
|
109067
|
+
var file2 = () => path16.join(runnerHome(), "preferences.json");
|
|
109301
109068
|
function read2() {
|
|
109302
109069
|
try {
|
|
109303
|
-
const value = JSON.parse(
|
|
109070
|
+
const value = JSON.parse(fs14.readFileSync(file2(), "utf8"));
|
|
109304
109071
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
109305
109072
|
} catch {
|
|
109306
109073
|
return {};
|
|
@@ -109309,32 +109076,32 @@ function read2() {
|
|
|
109309
109076
|
var acceptAlphaUpdates = () => read2().acceptAlphaUpdates === true;
|
|
109310
109077
|
function saveAlphaUpdates(value) {
|
|
109311
109078
|
const target = file2(), temporary = `${target}.${crypto4.randomUUID()}.tmp`;
|
|
109312
|
-
|
|
109079
|
+
fs14.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
|
|
109313
109080
|
try {
|
|
109314
|
-
|
|
109315
|
-
|
|
109081
|
+
fs14.writeFileSync(temporary, JSON.stringify({ ...read2(), acceptAlphaUpdates: value }) + "\n", { mode: 384 });
|
|
109082
|
+
fs14.renameSync(temporary, target);
|
|
109316
109083
|
} finally {
|
|
109317
|
-
|
|
109084
|
+
fs14.rmSync(temporary, { force: true });
|
|
109318
109085
|
}
|
|
109319
109086
|
}
|
|
109320
109087
|
|
|
109321
109088
|
// ../runner/src/update.ts
|
|
109322
109089
|
import crypto5 from "node:crypto";
|
|
109323
|
-
import
|
|
109324
|
-
import
|
|
109090
|
+
import fs15 from "node:fs";
|
|
109091
|
+
import path17 from "node:path";
|
|
109325
109092
|
import zlib from "node:zlib";
|
|
109326
109093
|
var PACKAGE = "wildcrane-runner";
|
|
109327
109094
|
var TIMEOUT_MS2 = 6e4;
|
|
109328
|
-
var versionsDir = () =>
|
|
109329
|
-
var legacyVersionsDir = () =>
|
|
109330
|
-
var versionDir = (version3) =>
|
|
109331
|
-
var entryOf = (dir) =>
|
|
109095
|
+
var versionsDir = () => path17.join(runnerHome(), "bin", "runner");
|
|
109096
|
+
var legacyVersionsDir = () => path17.join(runnerHome(), "runner");
|
|
109097
|
+
var versionDir = (version3) => path17.join(versionsDir(), version3);
|
|
109098
|
+
var entryOf = (dir) => path17.join(dir, "dist", "runner.mjs");
|
|
109332
109099
|
var RUNNER = { name: PACKAGE, dirOf: versionDir, entryOf };
|
|
109333
109100
|
var registry3 = () => (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
109334
109101
|
var install2 = (version3, nodeVersion) => installPackage(RUNNER, version3, nodeVersion);
|
|
109335
109102
|
async function installPackage(pkg, version3, nodeVersion = process.versions.node) {
|
|
109336
109103
|
const dir = pkg.dirOf(version3);
|
|
109337
|
-
if (
|
|
109104
|
+
if (fs15.existsSync(pkg.entryOf(dir))) return { ok: true, dir };
|
|
109338
109105
|
let meta4;
|
|
109339
109106
|
let tarball;
|
|
109340
109107
|
try {
|
|
@@ -109355,13 +109122,13 @@ async function installPackage(pkg, version3, nodeVersion = process.versions.node
|
|
|
109355
109122
|
if (!expected || expected !== actual) return { ok: false, why: "integrity", detail: "sha512 mismatch" };
|
|
109356
109123
|
const staging = `${dir}.${process.pid}.tmp`;
|
|
109357
109124
|
try {
|
|
109358
|
-
|
|
109125
|
+
fs15.rmSync(staging, { recursive: true, force: true });
|
|
109359
109126
|
extract(zlib.gunzipSync(tarball), staging);
|
|
109360
|
-
if (!
|
|
109361
|
-
|
|
109362
|
-
|
|
109127
|
+
if (!fs15.existsSync(pkg.entryOf(staging))) throw new Error(`the package carries no ${path17.relative(staging, pkg.entryOf(staging))}`);
|
|
109128
|
+
fs15.rmSync(dir, { recursive: true, force: true });
|
|
109129
|
+
fs15.renameSync(staging, dir);
|
|
109363
109130
|
} catch (e) {
|
|
109364
|
-
|
|
109131
|
+
fs15.rmSync(staging, { recursive: true, force: true });
|
|
109365
109132
|
return { ok: false, why: "integrity", detail: e instanceof Error ? e.message : String(e) };
|
|
109366
109133
|
}
|
|
109367
109134
|
return { ok: true, dir };
|
|
@@ -109391,12 +109158,12 @@ function extract(tar, into) {
|
|
|
109391
109158
|
if (type !== "0" && type !== "5") continue;
|
|
109392
109159
|
const relative = name.replace(/^[^/]+\//, "");
|
|
109393
109160
|
if (!relative) continue;
|
|
109394
|
-
const target =
|
|
109395
|
-
if (!target.startsWith(
|
|
109396
|
-
if (type === "5")
|
|
109161
|
+
const target = path17.resolve(into, relative);
|
|
109162
|
+
if (!target.startsWith(path17.resolve(into) + path17.sep)) throw new Error(`refusing ${name}`);
|
|
109163
|
+
if (type === "5") fs15.mkdirSync(target, { recursive: true });
|
|
109397
109164
|
else {
|
|
109398
|
-
|
|
109399
|
-
|
|
109165
|
+
fs15.mkdirSync(path17.dirname(target), { recursive: true });
|
|
109166
|
+
fs15.writeFileSync(target, body);
|
|
109400
109167
|
}
|
|
109401
109168
|
}
|
|
109402
109169
|
}
|
|
@@ -109458,27 +109225,27 @@ function meets(version3, comparator) {
|
|
|
109458
109225
|
var ASK_MS = 5e3;
|
|
109459
109226
|
var CONNECT_MS = 2 * 6e4;
|
|
109460
109227
|
var KEEP2 = 2;
|
|
109461
|
-
var stateFile = () =>
|
|
109228
|
+
var stateFile = () => path18.join(versionsDir(), "state.json");
|
|
109462
109229
|
function readState() {
|
|
109463
109230
|
try {
|
|
109464
|
-
const held2 = JSON.parse(
|
|
109231
|
+
const held2 = JSON.parse(fs16.readFileSync(stateFile(), "utf8"));
|
|
109465
109232
|
return { ...held2, good: held2.good ?? [], bad: held2.bad ?? [] };
|
|
109466
109233
|
} catch {
|
|
109467
109234
|
return { good: [], bad: [] };
|
|
109468
109235
|
}
|
|
109469
109236
|
}
|
|
109470
109237
|
function writeState(state2) {
|
|
109471
|
-
|
|
109472
|
-
|
|
109238
|
+
fs16.mkdirSync(versionsDir(), { recursive: true });
|
|
109239
|
+
fs16.writeFileSync(stateFile(), `${JSON.stringify(state2, null, 2)}
|
|
109473
109240
|
`);
|
|
109474
109241
|
}
|
|
109475
109242
|
function markGood(version3) {
|
|
109476
109243
|
const state2 = readState();
|
|
109477
109244
|
state2.good = [version3, ...state2.good.filter((v) => v !== version3)].slice(0, KEEP2);
|
|
109478
109245
|
writeState(state2);
|
|
109479
|
-
for (const name of
|
|
109480
|
-
if (name === "state.json" || state2.good.includes(name) || name.endsWith(".tmp") || busy(
|
|
109481
|
-
|
|
109246
|
+
for (const name of fs16.readdirSync(versionsDir())) {
|
|
109247
|
+
if (name === "state.json" || state2.good.includes(name) || name.endsWith(".tmp") || busy(path18.join(versionsDir(), name))) continue;
|
|
109248
|
+
fs16.rmSync(path18.join(versionsDir(), name), { recursive: true, force: true });
|
|
109482
109249
|
}
|
|
109483
109250
|
}
|
|
109484
109251
|
function markBad(version3) {
|
|
@@ -109512,7 +109279,7 @@ function remember(target) {
|
|
|
109512
109279
|
writeState(state2);
|
|
109513
109280
|
}
|
|
109514
109281
|
function provenNewer(own4) {
|
|
109515
|
-
const proven = readState().good.find((v) =>
|
|
109282
|
+
const proven = readState().good.find((v) => fs16.existsSync(entryOf(versionDir(v))));
|
|
109516
109283
|
return proven && compare(proven, own4) > 0 ? proven : null;
|
|
109517
109284
|
}
|
|
109518
109285
|
async function candidates(own4) {
|
|
@@ -109616,8 +109383,8 @@ function runOnce(candidate, options) {
|
|
|
109616
109383
|
if (message.type === "connected" && !connected) {
|
|
109617
109384
|
connected = true;
|
|
109618
109385
|
if (timer) clearTimeout(timer);
|
|
109619
|
-
if (candidate.entry.startsWith(versionsDir() +
|
|
109620
|
-
const installed = candidate.entry.startsWith(versionsDir() +
|
|
109386
|
+
if (candidate.entry.startsWith(versionsDir() + path18.sep)) fs16.rmSync(legacyVersionsDir(), { recursive: true, force: true });
|
|
109387
|
+
const installed = candidate.entry.startsWith(versionsDir() + path18.sep);
|
|
109621
109388
|
if (candidate.fresh || installed && !readState().good.includes(candidate.version)) markGood(candidate.version);
|
|
109622
109389
|
if (candidate.fresh) status(t.updated(candidate.version));
|
|
109623
109390
|
}
|
|
@@ -109674,20 +109441,20 @@ var WEB_URL = () => (process.env.WILDCRANE_WEB_URL || "https://app.wildcrane.ai"
|
|
|
109674
109441
|
var taskUrl = (task) => `${WEB_URL()}/tasks/${encodeURIComponent(task)}`;
|
|
109675
109442
|
|
|
109676
109443
|
// ../runner/src/plugin-version.ts
|
|
109677
|
-
import
|
|
109444
|
+
import fs17 from "node:fs";
|
|
109678
109445
|
import os5 from "node:os";
|
|
109679
|
-
import
|
|
109446
|
+
import path19 from "node:path";
|
|
109680
109447
|
var RELEASED = "https://raw.githubusercontent.com/wildcrane-ai/wildcrane/main/plugins/claude-code/.claude-plugin/plugin.json";
|
|
109681
109448
|
var TIMEOUT_MS3 = 5e3;
|
|
109682
109449
|
var KEEP_MS = 6 * 60 * 6e4;
|
|
109683
109450
|
var RETRY_MS = 5 * 6e4;
|
|
109684
|
-
var pluginRoot = (host2) => (host2 === "claude-code" || host2 === "zcode") && process.env.CLAUDE_PLUGIN_ROOT ||
|
|
109685
|
-
var CLAUDE_MANIFEST =
|
|
109686
|
-
var MANIFEST = { "claude-code": CLAUDE_MANIFEST, zcode: CLAUDE_MANIFEST, codex: "plugin.json", grok: "plugin.json", opencode: "package.json", dsh: "package.json", cursor:
|
|
109451
|
+
var pluginRoot = (host2) => (host2 === "claude-code" || host2 === "zcode") && process.env.CLAUDE_PLUGIN_ROOT || path19.resolve(path19.dirname(process.argv[1] ?? ""), "..", "..");
|
|
109452
|
+
var CLAUDE_MANIFEST = path19.join(".claude-plugin", "plugin.json");
|
|
109453
|
+
var MANIFEST = { "claude-code": CLAUDE_MANIFEST, zcode: CLAUDE_MANIFEST, codex: "plugin.json", grok: "plugin.json", opencode: "package.json", dsh: "package.json", cursor: path19.join(".cursor-plugin", "plugin.json"), kimi: "kimi.plugin.json" };
|
|
109687
109454
|
function pluginVersion(host2 = "claude-code", root2 = pluginRoot(host2)) {
|
|
109688
109455
|
const file3 = MANIFEST[host2];
|
|
109689
109456
|
try {
|
|
109690
|
-
const version3 = JSON.parse(
|
|
109457
|
+
const version3 = JSON.parse(fs17.readFileSync(path19.join(root2, file3), "utf8")).version;
|
|
109691
109458
|
return typeof version3 === "string" ? version3 : null;
|
|
109692
109459
|
} catch {
|
|
109693
109460
|
return null;
|
|
@@ -109710,9 +109477,9 @@ function checkReleased(url2 = RELEASED, now = Date.now()) {
|
|
|
109710
109477
|
fetching = get(url2).then(releasedOf, () => null).then((value) => void (released = { at: Date.now(), value })).finally(() => fetching = null);
|
|
109711
109478
|
return fetching;
|
|
109712
109479
|
}
|
|
109713
|
-
function codexSource(home4 = process.env.CODEX_HOME ||
|
|
109480
|
+
function codexSource(home4 = process.env.CODEX_HOME || path19.join(os5.homedir(), ".codex")) {
|
|
109714
109481
|
try {
|
|
109715
|
-
const config3 =
|
|
109482
|
+
const config3 = fs17.readFileSync(path19.join(home4, "config.toml"), "utf8");
|
|
109716
109483
|
const section = /^\[marketplaces\.wildcrane\][^\n]*\n((?:(?!\[)[^\n]*\n?)*)/m.exec(config3)?.[1] ?? "";
|
|
109717
109484
|
const type = /^source_type\s*=\s*"(\w+)"/m.exec(section)?.[1];
|
|
109718
109485
|
return type === "git" || type === "local" ? type : null;
|
|
@@ -109733,21 +109500,21 @@ async function get(url2) {
|
|
|
109733
109500
|
|
|
109734
109501
|
// ../runner/src/runtimes.ts
|
|
109735
109502
|
import { spawn as spawn3 } from "node:child_process";
|
|
109736
|
-
import
|
|
109503
|
+
import fs26 from "node:fs";
|
|
109737
109504
|
import os7 from "node:os";
|
|
109738
|
-
import
|
|
109505
|
+
import path30 from "node:path";
|
|
109739
109506
|
|
|
109740
109507
|
// ../cli/src/lib/agent/harnesses/antigravity.ts
|
|
109741
|
-
import
|
|
109742
|
-
import
|
|
109508
|
+
import fs21 from "node:fs";
|
|
109509
|
+
import path24 from "node:path";
|
|
109743
109510
|
import { createHash as createHash3 } from "node:crypto";
|
|
109744
|
-
import { spawnSync as
|
|
109511
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
109745
109512
|
|
|
109746
109513
|
// ../cli/src/lib/agent/locate.ts
|
|
109747
|
-
import { spawn as spawn2, spawnSync
|
|
109748
|
-
import
|
|
109514
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
109515
|
+
import fs19 from "node:fs";
|
|
109749
109516
|
import os6 from "node:os";
|
|
109750
|
-
import
|
|
109517
|
+
import path21 from "node:path";
|
|
109751
109518
|
|
|
109752
109519
|
// ../cli/src/lib/agent/argv.ts
|
|
109753
109520
|
function splitCommand(command) {
|
|
@@ -109786,8 +109553,8 @@ function commandBinary(command) {
|
|
|
109786
109553
|
}
|
|
109787
109554
|
|
|
109788
109555
|
// ../cli/src/lib/agent/spawnable.ts
|
|
109789
|
-
import
|
|
109790
|
-
import
|
|
109556
|
+
import fs18 from "node:fs";
|
|
109557
|
+
import path20 from "node:path";
|
|
109791
109558
|
var META = /([()\][%!^"`<>&|;, *?])/g;
|
|
109792
109559
|
function cmdArg(arg) {
|
|
109793
109560
|
const quoted = `"${arg.replace(/\r?\n|\r/g, " ").replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
|
|
@@ -109797,21 +109564,21 @@ function cmdLine(file3, args2) {
|
|
|
109797
109564
|
return `"${[file3.replace(META, "^$1"), ...args2.map(cmdArg)].join(" ")}"`;
|
|
109798
109565
|
}
|
|
109799
109566
|
function shimTarget(text3, file3) {
|
|
109800
|
-
const dir =
|
|
109567
|
+
const dir = path20.win32.dirname(file3);
|
|
109801
109568
|
const found = /"%(?:~dp0|dp0%)\\?([^"%]+)"\s+%\*/i.exec(text3);
|
|
109802
109569
|
if (!found || !/\\node\.exe"/i.test(text3)) return null;
|
|
109803
|
-
const script =
|
|
109804
|
-
const local =
|
|
109570
|
+
const script = path20.win32.resolve(dir, found[1].replace(/\//g, "\\"));
|
|
109571
|
+
const local = path20.win32.join(dir, "node.exe");
|
|
109805
109572
|
const nodePath = /SET "NODE_PATH=([^"]*)"/i.exec(text3)?.[1];
|
|
109806
|
-
return { script, node:
|
|
109573
|
+
return { script, node: fs18.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
|
|
109807
109574
|
}
|
|
109808
109575
|
function onWindowsPath(name, env2) {
|
|
109809
109576
|
const exts = (env2.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
109810
109577
|
const key = Object.keys(env2).find((k) => k.toUpperCase() === "PATH") ?? "PATH";
|
|
109811
109578
|
for (const dir of (env2[key] ?? "").split(";").filter(Boolean)) {
|
|
109812
109579
|
for (const ext of exts) {
|
|
109813
|
-
const file3 =
|
|
109814
|
-
if (
|
|
109580
|
+
const file3 = path20.win32.join(dir, `${name}${ext.toLowerCase()}`);
|
|
109581
|
+
if (fs18.existsSync(file3)) return file3;
|
|
109815
109582
|
}
|
|
109816
109583
|
}
|
|
109817
109584
|
return void 0;
|
|
@@ -109819,13 +109586,13 @@ function onWindowsPath(name, env2) {
|
|
|
109819
109586
|
function spawnable(command, args2, options = {}, platform = process.platform) {
|
|
109820
109587
|
if (platform !== "win32") return { command, args: args2, options };
|
|
109821
109588
|
const env2 = options.env ?? process.env;
|
|
109822
|
-
const file3 =
|
|
109823
|
-
const ext =
|
|
109589
|
+
const file3 = path20.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
|
|
109590
|
+
const ext = path20.extname(file3).toLowerCase();
|
|
109824
109591
|
const hidden = { ...options, windowsHide: true, shell: false };
|
|
109825
109592
|
if (ext !== ".cmd" && ext !== ".bat") return { command: file3, args: args2, options: hidden };
|
|
109826
109593
|
let text3 = "";
|
|
109827
109594
|
try {
|
|
109828
|
-
text3 =
|
|
109595
|
+
text3 = fs18.readFileSync(file3, "utf8");
|
|
109829
109596
|
} catch {
|
|
109830
109597
|
}
|
|
109831
109598
|
const shim = shimTarget(text3, file3);
|
|
@@ -109889,7 +109656,7 @@ function pick3(copies) {
|
|
|
109889
109656
|
}
|
|
109890
109657
|
function folders(parent) {
|
|
109891
109658
|
try {
|
|
109892
|
-
return
|
|
109659
|
+
return fs19.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
|
|
109893
109660
|
} catch {
|
|
109894
109661
|
return [];
|
|
109895
109662
|
}
|
|
@@ -109908,29 +109675,29 @@ function byVersion(names) {
|
|
|
109908
109675
|
function latestIn(parent, tail = "") {
|
|
109909
109676
|
let names;
|
|
109910
109677
|
try {
|
|
109911
|
-
names =
|
|
109678
|
+
names = fs19.readdirSync(parent);
|
|
109912
109679
|
} catch {
|
|
109913
109680
|
return [];
|
|
109914
109681
|
}
|
|
109915
|
-
return byVersion(names.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) =>
|
|
109682
|
+
return byVersion(names.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path21.join(parent, name, tail));
|
|
109916
109683
|
}
|
|
109917
109684
|
var env = (name) => process.env[name]?.trim() ?? "";
|
|
109918
109685
|
function commonDirs() {
|
|
109919
109686
|
const home4 = os6.homedir();
|
|
109920
|
-
const under = (...parts) =>
|
|
109921
|
-
const nodes = (root2, tail = []) => root2 ? folders(root2).map((version3) =>
|
|
109687
|
+
const under = (...parts) => path21.join(home4, ...parts);
|
|
109688
|
+
const nodes = (root2, tail = []) => root2 ? folders(root2).map((version3) => path21.join(root2, version3, ...tail)) : [];
|
|
109922
109689
|
if (WINDOWS2) {
|
|
109923
109690
|
const [app, local, data, programs] = [env("APPDATA"), env("LOCALAPPDATA"), env("ProgramData"), env("ProgramFiles")];
|
|
109924
109691
|
return [
|
|
109925
109692
|
under(".local", "bin"),
|
|
109926
109693
|
under(".bun", "bin"),
|
|
109927
109694
|
under("scoop", "shims"),
|
|
109928
|
-
...app ? [
|
|
109929
|
-
...local ? [
|
|
109930
|
-
...data ? [
|
|
109931
|
-
...programs ? [
|
|
109695
|
+
...app ? [path21.join(app, "npm")] : [],
|
|
109696
|
+
...local ? [path21.join(local, "pnpm"), path21.join(local, "Volta", "bin"), path21.join(local, "Microsoft", "WinGet", "Links")] : [],
|
|
109697
|
+
...data ? [path21.join(data, "chocolatey", "bin")] : [],
|
|
109698
|
+
...programs ? [path21.join(programs, "nodejs")] : [],
|
|
109932
109699
|
...nodes(env("NVM_HOME")),
|
|
109933
|
-
...app ? nodes(
|
|
109700
|
+
...app ? nodes(path21.join(app, "fnm", "node-versions"), ["installation"]) : []
|
|
109934
109701
|
];
|
|
109935
109702
|
}
|
|
109936
109703
|
const support = process.platform === "darwin" ? under("Library", "Application Support") : under(".local", "share");
|
|
@@ -109947,10 +109714,10 @@ function commonDirs() {
|
|
|
109947
109714
|
...env("PNPM_HOME") ? [env("PNPM_HOME")] : [],
|
|
109948
109715
|
under("Library", "pnpm"),
|
|
109949
109716
|
under(".local", "share", "pnpm"),
|
|
109950
|
-
|
|
109951
|
-
...nodes(
|
|
109952
|
-
...nodes(
|
|
109953
|
-
...nodes(
|
|
109717
|
+
path21.join(env("VOLTA_HOME") || under(".volta"), "bin"),
|
|
109718
|
+
...nodes(path21.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
|
|
109719
|
+
...nodes(path21.join(env("FNM_DIR") || path21.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
|
|
109720
|
+
...nodes(path21.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
|
|
109954
109721
|
...nodes(under(".local", "share", "mise", "installs", "node"), ["bin"]),
|
|
109955
109722
|
...nodes(under(".nodenv", "versions"), ["bin"]),
|
|
109956
109723
|
...nodes("/usr/local/n/versions/node", ["bin"])
|
|
@@ -109958,11 +109725,11 @@ function commonDirs() {
|
|
|
109958
109725
|
}
|
|
109959
109726
|
function onPath(binary) {
|
|
109960
109727
|
const names = WINDOWS2 ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((ext) => `${binary}${ext.toLowerCase()}`) : [binary];
|
|
109961
|
-
return (process.env.PATH ?? "").split(
|
|
109728
|
+
return (process.env.PATH ?? "").split(path21.delimiter).filter(Boolean).flatMap((dir) => names.map((name) => path21.join(dir, name)));
|
|
109962
109729
|
}
|
|
109963
109730
|
var isFile = (file3) => {
|
|
109964
109731
|
try {
|
|
109965
|
-
return
|
|
109732
|
+
return fs19.statSync(file3).isFile();
|
|
109966
109733
|
} catch {
|
|
109967
109734
|
return false;
|
|
109968
109735
|
}
|
|
@@ -109971,24 +109738,24 @@ function copyFiles(harness) {
|
|
|
109971
109738
|
const pinned = harness.pinned?.();
|
|
109972
109739
|
if (pinned && isFile(pinned)) return [{ file: pinned, entry: false }];
|
|
109973
109740
|
const binary = commandBinary(harness.command);
|
|
109974
|
-
const exe = (file3) => WINDOWS2 && !
|
|
109741
|
+
const exe = (file3) => WINDOWS2 && !path21.extname(file3) ? [`${file3}.exe`, `${file3}.cmd`] : [file3];
|
|
109975
109742
|
const path_ = onPath(binary).filter(isFile);
|
|
109976
|
-
const elsewhere2 = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) =>
|
|
109743
|
+
const elsewhere2 = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path21.join(dir, binary))];
|
|
109977
109744
|
const others = elsewhere2.flatMap(exe).filter(isFile);
|
|
109978
109745
|
const seen = /* @__PURE__ */ new Set();
|
|
109979
109746
|
return [...path_, ...others].flatMap((file3, i) => {
|
|
109980
|
-
const real =
|
|
109747
|
+
const real = fs19.realpathSync.native(file3);
|
|
109981
109748
|
if (seen.has(real)) return [];
|
|
109982
109749
|
seen.add(real);
|
|
109983
109750
|
return [{ file: file3, entry: i === 0 && path_.length > 0 }];
|
|
109984
109751
|
});
|
|
109985
109752
|
}
|
|
109986
109753
|
var answers;
|
|
109987
|
-
var answersFile = () =>
|
|
109754
|
+
var answersFile = () => path21.join(machineHome(), "agent-copies.json");
|
|
109988
109755
|
function kept2() {
|
|
109989
109756
|
if (answers) return answers;
|
|
109990
109757
|
try {
|
|
109991
|
-
answers = JSON.parse(
|
|
109758
|
+
answers = JSON.parse(fs19.readFileSync(answersFile(), "utf8"));
|
|
109992
109759
|
} catch {
|
|
109993
109760
|
answers = {};
|
|
109994
109761
|
}
|
|
@@ -109997,16 +109764,16 @@ function kept2() {
|
|
|
109997
109764
|
function keep(file3, answer) {
|
|
109998
109765
|
kept2()[file3] = answer;
|
|
109999
109766
|
try {
|
|
110000
|
-
|
|
109767
|
+
fs19.mkdirSync(machineHome(), { recursive: true });
|
|
110001
109768
|
const staged = `${answersFile()}.${process.pid}`;
|
|
110002
|
-
|
|
110003
|
-
|
|
109769
|
+
fs19.writeFileSync(staged, JSON.stringify(answers));
|
|
109770
|
+
fs19.renameSync(staged, answersFile());
|
|
110004
109771
|
} catch {
|
|
110005
109772
|
}
|
|
110006
109773
|
}
|
|
110007
109774
|
function keyOf(file3) {
|
|
110008
|
-
const real =
|
|
110009
|
-
const stat =
|
|
109775
|
+
const real = fs19.realpathSync.native(file3);
|
|
109776
|
+
const stat = fs19.statSync(real);
|
|
110010
109777
|
return `${real}|${stat.size}|${stat.mtimeMs}`;
|
|
110011
109778
|
}
|
|
110012
109779
|
function known(file3, maxAge) {
|
|
@@ -110019,14 +109786,14 @@ function judge(code, status2, stdout, stderr) {
|
|
|
110019
109786
|
return { starts: true, version: status2 === 0 ? versionIn(stdout) ?? versionIn(stderr) : null };
|
|
110020
109787
|
}
|
|
110021
109788
|
function copyEnv(file3, given = process.env) {
|
|
110022
|
-
if (!
|
|
110023
|
-
return { ...given, PATH: [
|
|
109789
|
+
if (!path21.isAbsolute(file3)) return given;
|
|
109790
|
+
return { ...given, PATH: [path21.dirname(file3), given.PATH].filter(Boolean).join(path21.delimiter) };
|
|
110024
109791
|
}
|
|
110025
109792
|
var probeOptions = (file3) => ({ cwd: os6.tmpdir(), env: copyEnv(file3), windowsHide: true, shell: false });
|
|
110026
109793
|
function probe(file3) {
|
|
110027
109794
|
const key = keyOf(file3);
|
|
110028
109795
|
const start = spawnable(file3, ["--version"], { ...probeOptions(file3), stdio: ["ignore", "pipe", "pipe"], timeout: PROBE_MS });
|
|
110029
|
-
const run3 =
|
|
109796
|
+
const run3 = spawnSync(start.command, start.args, { ...start.options, encoding: "utf8" });
|
|
110030
109797
|
const code = run3.error?.code;
|
|
110031
109798
|
const answer = { key, at: Date.now(), ...judge(code, run3.status, run3.stdout ?? "", run3.stderr ?? "") };
|
|
110032
109799
|
keep(file3, answer);
|
|
@@ -110078,16 +109845,16 @@ import { join } from "node:path";
|
|
|
110078
109845
|
function home(...parts) {
|
|
110079
109846
|
return join(homedir(), ...parts);
|
|
110080
109847
|
}
|
|
110081
|
-
function
|
|
109848
|
+
function obj(value) {
|
|
110082
109849
|
return value && typeof value === "object" ? value : {};
|
|
110083
109850
|
}
|
|
110084
109851
|
function arr(value) {
|
|
110085
109852
|
return Array.isArray(value) ? value : [];
|
|
110086
109853
|
}
|
|
110087
|
-
function
|
|
109854
|
+
function str(value) {
|
|
110088
109855
|
return typeof value === "string" ? value : "";
|
|
110089
109856
|
}
|
|
110090
|
-
function
|
|
109857
|
+
function num(value) {
|
|
110091
109858
|
return typeof value === "number" ? value : Number.MAX_SAFE_INTEGER;
|
|
110092
109859
|
}
|
|
110093
109860
|
function uniqueIds(list3) {
|
|
@@ -110116,8 +109883,8 @@ function modelsIn(file3, pick4, salt = "") {
|
|
|
110116
109883
|
|
|
110117
109884
|
// ../cli/src/lib/agent/harnesses/types.ts
|
|
110118
109885
|
import { createHash as createHash2 } from "node:crypto";
|
|
110119
|
-
import
|
|
110120
|
-
import
|
|
109886
|
+
import fs20 from "node:fs";
|
|
109887
|
+
import path22 from "node:path";
|
|
110121
109888
|
function namesFlag(argv, flags) {
|
|
110122
109889
|
return argv.some((tok) => flags.some((flag) => tok === flag || tok.startsWith(`${flag}=`)));
|
|
110123
109890
|
}
|
|
@@ -110139,18 +109906,18 @@ var MCP_CONFIG = {
|
|
|
110139
109906
|
};
|
|
110140
109907
|
function machineFile(name, text3) {
|
|
110141
109908
|
const suffix = createHash2("sha256").update(text3).digest("hex").slice(0, 16);
|
|
110142
|
-
const file3 =
|
|
109909
|
+
const file3 = path22.join(machineHome(), "prompts", `${path22.parse(name).name}-${suffix}${path22.extname(name)}`);
|
|
110143
109910
|
try {
|
|
110144
|
-
if (
|
|
109911
|
+
if (fs20.readFileSync(file3, "utf8") === text3) return file3;
|
|
110145
109912
|
} catch {
|
|
110146
109913
|
}
|
|
110147
|
-
|
|
110148
|
-
|
|
109914
|
+
fs20.mkdirSync(path22.dirname(file3), { recursive: true });
|
|
109915
|
+
fs20.writeFileSync(file3, text3);
|
|
110149
109916
|
return file3;
|
|
110150
109917
|
}
|
|
110151
109918
|
|
|
110152
109919
|
// ../cli/src/lib/agent/wire/antigravity.ts
|
|
110153
|
-
import
|
|
109920
|
+
import path23 from "node:path";
|
|
110154
109921
|
|
|
110155
109922
|
// ../cli/src/lib/agent/prices.ts
|
|
110156
109923
|
var OPENAI = {
|
|
@@ -110203,9 +109970,33 @@ function priceUsd(provider, model, usage, at = Date.now()) {
|
|
|
110203
109970
|
return Number.isFinite(usd) && usd >= 0 ? usd : void 0;
|
|
110204
109971
|
}
|
|
110205
109972
|
|
|
109973
|
+
// ../cli/src/lib/agent/wire/json.ts
|
|
109974
|
+
function obj2(value) {
|
|
109975
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
109976
|
+
}
|
|
109977
|
+
function str2(value) {
|
|
109978
|
+
return typeof value === "string" ? value : "";
|
|
109979
|
+
}
|
|
109980
|
+
function num2(value) {
|
|
109981
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
109982
|
+
}
|
|
109983
|
+
function hint(raw) {
|
|
109984
|
+
const line = raw.split("\n")[0].trim();
|
|
109985
|
+
if (!line) return "";
|
|
109986
|
+
return `(${line.length > 96 ? `${line.slice(0, 93)}\u2026` : line})`;
|
|
109987
|
+
}
|
|
109988
|
+
function argHint(input2, keys) {
|
|
109989
|
+
const args2 = obj2(input2);
|
|
109990
|
+
for (const key of keys) {
|
|
109991
|
+
const value = str2(args2[key]);
|
|
109992
|
+
if (value.trim()) return hint(value);
|
|
109993
|
+
}
|
|
109994
|
+
return "";
|
|
109995
|
+
}
|
|
109996
|
+
|
|
110206
109997
|
// ../cli/src/lib/agent/wire/events.ts
|
|
110207
109998
|
var TOOL_KINDS = ["read", "edit", "delete", "move", "search", "execute", "fetch", "other"];
|
|
110208
|
-
var toolKind = (v) => TOOL_KINDS.includes(
|
|
109999
|
+
var toolKind = (v) => TOOL_KINDS.includes(str2(v)) ? v : "other";
|
|
110209
110000
|
function targetOf(raw) {
|
|
110210
110001
|
const line = raw.split("\n")[0].trim();
|
|
110211
110002
|
if (!line) return void 0;
|
|
@@ -110214,29 +110005,29 @@ function targetOf(raw) {
|
|
|
110214
110005
|
function contentText(raw) {
|
|
110215
110006
|
const parts = Array.isArray(raw) ? raw : [];
|
|
110216
110007
|
return parts.map((p) => {
|
|
110217
|
-
const part =
|
|
110218
|
-
if (part.type === "diff") return
|
|
110219
|
-
return
|
|
110008
|
+
const part = obj2(p);
|
|
110009
|
+
if (part.type === "diff") return str2(part.path);
|
|
110010
|
+
return str2(obj2(part.content).text) || str2(part.text);
|
|
110220
110011
|
}).filter((t2) => t2.trim()).join("\n");
|
|
110221
110012
|
}
|
|
110222
110013
|
function statusOf(raw) {
|
|
110223
|
-
const s =
|
|
110014
|
+
const s = str2(raw).toLowerCase();
|
|
110224
110015
|
if (s.includes("progress")) return "in_progress";
|
|
110225
110016
|
if (/complete|done|cancel/.test(s)) return "completed";
|
|
110226
110017
|
return "pending";
|
|
110227
110018
|
}
|
|
110228
110019
|
function entriesOf(raw) {
|
|
110229
|
-
return (Array.isArray(raw) ? raw : []).map(
|
|
110230
|
-
const content =
|
|
110020
|
+
return (Array.isArray(raw) ? raw : []).map(obj2).flatMap((e) => {
|
|
110021
|
+
const content = str2(e.content).trim();
|
|
110231
110022
|
if (!content) return [];
|
|
110232
|
-
return [{ content, status: statusOf(e.status), ...
|
|
110023
|
+
return [{ content, status: statusOf(e.status), ...str2(e.priority) ? { priority: str2(e.priority) } : {} }];
|
|
110233
110024
|
});
|
|
110234
110025
|
}
|
|
110235
|
-
var isTodoCall = (u) =>
|
|
110236
|
-
var inputTarget = (input2) =>
|
|
110026
|
+
var isTodoCall = (u) => str2(u.title) === "todowrite" || str2(obj2(u.rawInput)._toolName) === "updateTodos";
|
|
110027
|
+
var inputTarget = (input2) => str2(input2.command) || str2(input2.path) || str2(input2.filePath);
|
|
110237
110028
|
var targetIn = (u) => {
|
|
110238
110029
|
const locations = Array.isArray(u.locations) ? u.locations : [];
|
|
110239
|
-
return targetOf(inputTarget(
|
|
110030
|
+
return targetOf(inputTarget(obj2(u.rawInput)) || str2(obj2(locations[0]).path) || "");
|
|
110240
110031
|
};
|
|
110241
110032
|
function createEventCollector() {
|
|
110242
110033
|
let queue = [];
|
|
@@ -110262,34 +110053,34 @@ function createEventCollector() {
|
|
|
110262
110053
|
},
|
|
110263
110054
|
/** One ACP `session/update`'s `update`. Thoughts and housekeeping updates yield nothing. */
|
|
110264
110055
|
update(raw) {
|
|
110265
|
-
const u =
|
|
110056
|
+
const u = obj2(raw);
|
|
110266
110057
|
if (u.sessionUpdate === "agent_message_chunk") {
|
|
110267
|
-
const chunk =
|
|
110058
|
+
const chunk = str2(obj2(u.content).text);
|
|
110268
110059
|
if (chunk) activity++;
|
|
110269
110060
|
said += chunk;
|
|
110270
110061
|
return;
|
|
110271
110062
|
}
|
|
110272
|
-
if (!["tool_call", "tool_call_update", "plan"].includes(
|
|
110063
|
+
if (!["tool_call", "tool_call_update", "plan"].includes(str2(u.sessionUpdate))) return;
|
|
110273
110064
|
close();
|
|
110274
110065
|
switch (u.sessionUpdate) {
|
|
110275
110066
|
case "tool_call": {
|
|
110276
|
-
const id2 =
|
|
110067
|
+
const id2 = str2(u.toolCallId);
|
|
110277
110068
|
if (isTodoCall(u)) {
|
|
110278
110069
|
todoCalls.add(id2);
|
|
110279
110070
|
return;
|
|
110280
110071
|
}
|
|
110281
110072
|
const target = targetIn(u);
|
|
110282
|
-
const subagent = /^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(
|
|
110283
|
-
const data = { toolCallId: id2, title:
|
|
110284
|
-
if (data.kind !== "execute" && !subagent && u.rawInput !== void 0 && !inputTarget(
|
|
110073
|
+
const subagent = /^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(str2(u.title)) || !!obj2(u.rawInput).subagent_type;
|
|
110074
|
+
const data = { toolCallId: id2, title: str2(u.title) || "tool", kind: toolKind(u.kind), status: str2(u.status) || "pending", ...subagent ? { subagent: true } : {}, ...target ? { target } : {} };
|
|
110075
|
+
if (data.kind !== "execute" && !subagent && u.rawInput !== void 0 && !inputTarget(obj2(u.rawInput))) held2.set(id2, data);
|
|
110285
110076
|
else queue.push({ kind: "tool_call", data });
|
|
110286
110077
|
return;
|
|
110287
110078
|
}
|
|
110288
110079
|
case "tool_call_update": {
|
|
110289
|
-
const id2 =
|
|
110080
|
+
const id2 = str2(u.toolCallId);
|
|
110290
110081
|
if (todoCalls.has(id2)) {
|
|
110291
|
-
const list3 =
|
|
110292
|
-
if (Array.isArray(list3) && !
|
|
110082
|
+
const list3 = obj2(u.rawInput).todos;
|
|
110083
|
+
if (Array.isArray(list3) && !str2(obj2(u.rawInput)._toolName)) queue.push({ kind: "plan", data: { entries: entriesOf(list3) } });
|
|
110293
110084
|
return;
|
|
110294
110085
|
}
|
|
110295
110086
|
release(id2, targetIn(u));
|
|
@@ -110297,7 +110088,7 @@ function createEventCollector() {
|
|
|
110297
110088
|
if (!u.status && !result) return;
|
|
110298
110089
|
queue.push({
|
|
110299
110090
|
kind: "tool_call_update",
|
|
110300
|
-
data: { toolCallId:
|
|
110091
|
+
data: { toolCallId: str2(u.toolCallId), status: str2(u.status) || "in_progress", ...result ? { result } : {} }
|
|
110301
110092
|
});
|
|
110302
110093
|
return;
|
|
110303
110094
|
}
|
|
@@ -110332,9 +110123,9 @@ function createEventCollector() {
|
|
|
110332
110123
|
/** Cursor's `cursor/update_todos`: the whole list, or under `merge` only what changed, by id. */
|
|
110333
110124
|
todos(raw, merge3) {
|
|
110334
110125
|
close();
|
|
110335
|
-
const items = (Array.isArray(raw) ? raw : []).map(
|
|
110126
|
+
const items = (Array.isArray(raw) ? raw : []).map(obj2).flatMap((e) => {
|
|
110336
110127
|
const [entry] = entriesOf([e]);
|
|
110337
|
-
return entry ? [{ ...entry, id:
|
|
110128
|
+
return entry ? [{ ...entry, id: str2(e.id) }] : [];
|
|
110338
110129
|
});
|
|
110339
110130
|
const next = merge3 ? [...todos] : [];
|
|
110340
110131
|
for (const item of items) {
|
|
@@ -110493,8 +110284,8 @@ var KINDS = {
|
|
|
110493
110284
|
};
|
|
110494
110285
|
var zero = () => ({ input: 0, cacheCreation: 0, cacheRead: 0, output: 0 });
|
|
110495
110286
|
var usageOf = (raw) => {
|
|
110496
|
-
const u =
|
|
110497
|
-
return { input:
|
|
110287
|
+
const u = obj2(raw);
|
|
110288
|
+
return { input: num2(u.input_tokens), output: num2(u.output_tokens), cacheRead: num2(u.cache_read_tokens), cacheCreation: 0 };
|
|
110498
110289
|
};
|
|
110499
110290
|
var add = (a, b) => ({ input: a.input + b.input, output: a.output + b.output, cacheRead: a.cacheRead + b.cacheRead, cacheCreation: 0 });
|
|
110500
110291
|
function failureHint(reason) {
|
|
@@ -110536,7 +110327,7 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
110536
110327
|
const index = step.step_index;
|
|
110537
110328
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || priced.has(index) || !model && index <= prompt) return;
|
|
110538
110329
|
priced.add(index);
|
|
110539
|
-
const u =
|
|
110330
|
+
const u = obj2(step.usage);
|
|
110540
110331
|
const valid = [u.input_tokens, u.output_tokens, u.cache_read_tokens].every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0);
|
|
110541
110332
|
if (!valid || !model && prompt < 0) incomplete = true;
|
|
110542
110333
|
else if (model) estimate(model, usageOf(u));
|
|
@@ -110562,33 +110353,33 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
110562
110353
|
`;
|
|
110563
110354
|
}
|
|
110564
110355
|
if (e.event === "init") {
|
|
110565
|
-
const got =
|
|
110356
|
+
const got = str2(e.conversation_id);
|
|
110566
110357
|
if (expectedSession && got !== expectedSession) {
|
|
110567
110358
|
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");
|
|
110568
110359
|
return "";
|
|
110569
110360
|
}
|
|
110570
110361
|
session = got || session;
|
|
110571
|
-
model =
|
|
110362
|
+
model = str2(obj2(e.init).model) || model;
|
|
110572
110363
|
return "";
|
|
110573
110364
|
}
|
|
110574
110365
|
if (e.event === "step_update") {
|
|
110575
|
-
const step =
|
|
110576
|
-
const got =
|
|
110366
|
+
const step = obj2(e.step_update);
|
|
110367
|
+
const got = str2(step.conversation_id);
|
|
110577
110368
|
if (expectedSession && got !== expectedSession || session && got && got !== session) return "";
|
|
110578
110369
|
session = got || session;
|
|
110579
110370
|
const id2 = String(step.step_index ?? "");
|
|
110580
110371
|
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;
|
|
110581
|
-
if (step.state === "DONE" && ["agent_response", "checkpoint"].includes(
|
|
110372
|
+
if (step.state === "DONE" && ["agent_response", "checkpoint"].includes(str2(step.step_type))) countCost(step);
|
|
110582
110373
|
if (step.step_type === "agent_response") {
|
|
110583
|
-
const text3 =
|
|
110374
|
+
const text3 = str2(step.text_delta);
|
|
110584
110375
|
partial3 += text3;
|
|
110585
110376
|
if (text3) events.update({ sessionUpdate: "agent_message_chunk", content: { text: text3 } });
|
|
110586
|
-
const index =
|
|
110377
|
+
const index = num2(step.step_index);
|
|
110587
110378
|
if (step.state === "DONE" && Number.isSafeInteger(index) && step.step_index === index && index > contextStep) {
|
|
110588
110379
|
contextStep = index;
|
|
110589
|
-
const u =
|
|
110380
|
+
const u = obj2(step.usage);
|
|
110590
110381
|
const counts = [u.input_tokens, u.cache_read_tokens];
|
|
110591
|
-
const prompt2 = counts.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0) ?
|
|
110382
|
+
const prompt2 = counts.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0) ? num2(u.input_tokens) + num2(u.cache_read_tokens) : 0;
|
|
110592
110383
|
context = prompt2 > 0 && Number.isFinite(prompt2) ? { used: prompt2 } : void 0;
|
|
110593
110384
|
}
|
|
110594
110385
|
if (step.state === "DONE" && step.usage && !counted.has(index)) {
|
|
@@ -110599,10 +110390,10 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
110599
110390
|
return text3;
|
|
110600
110391
|
}
|
|
110601
110392
|
if (step.step_type === "tool") {
|
|
110602
|
-
const tool =
|
|
110603
|
-
const name =
|
|
110604
|
-
const p =
|
|
110605
|
-
const target =
|
|
110393
|
+
const tool = obj2(step.tool_info);
|
|
110394
|
+
const name = str2(tool.name) || str2(step.tool_name) || "tool";
|
|
110395
|
+
const p = obj2(tool.parameters);
|
|
110396
|
+
const target = str2(p.CommandLine) || str2(p.Path) || str2(p.TargetFile) || str2(p.AbsolutePath) || str2(p.Query);
|
|
110606
110397
|
let out = "";
|
|
110607
110398
|
if (!calls.has(id2)) {
|
|
110608
110399
|
calls.add(id2);
|
|
@@ -110611,41 +110402,41 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
110611
110402
|
\u23FA ${name}${target ? ` ${target}` : ""}
|
|
110612
110403
|
`;
|
|
110613
110404
|
}
|
|
110614
|
-
const error63 =
|
|
110615
|
-
const reason =
|
|
110616
|
-
if (["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(
|
|
110405
|
+
const error63 = obj2(tool.error);
|
|
110406
|
+
const reason = str2(error63.message) || str2(error63.type);
|
|
110407
|
+
if (["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(str2(step.state)) && !closed.has(id2)) {
|
|
110617
110408
|
closed.add(id2);
|
|
110618
110409
|
const failed = !!reason || step.state !== "DONE";
|
|
110619
110410
|
if (["read_file", "view_file"].includes(name) && imagePath(target)) {
|
|
110620
|
-
const file3 =
|
|
110411
|
+
const file3 = path23.resolve(cwd, target);
|
|
110621
110412
|
if (failed) {
|
|
110622
|
-
imageErrors.set(file3, reason ||
|
|
110413
|
+
imageErrors.set(file3, reason || str2(step.state));
|
|
110623
110414
|
out += `
|
|
110624
|
-
${imageError(target, reason ||
|
|
110415
|
+
${imageError(target, reason || str2(step.state))}
|
|
110625
110416
|
`;
|
|
110626
110417
|
} else {
|
|
110627
110418
|
readImages.add(file3);
|
|
110628
110419
|
imageErrors.delete(file3);
|
|
110629
110420
|
}
|
|
110630
110421
|
}
|
|
110631
|
-
events.toolResult(id2, failed ? "failed" : "completed",
|
|
110422
|
+
events.toolResult(id2, failed ? "failed" : "completed", str2(tool.output) || reason);
|
|
110632
110423
|
}
|
|
110633
110424
|
return out;
|
|
110634
110425
|
}
|
|
110635
110426
|
return "";
|
|
110636
110427
|
}
|
|
110637
110428
|
if (e.event === "result") {
|
|
110638
|
-
const result =
|
|
110639
|
-
if (expectedSession &&
|
|
110429
|
+
const result = obj2(e.result);
|
|
110430
|
+
if (expectedSession && str2(result.conversation_id) && result.conversation_id !== expectedSession) {
|
|
110640
110431
|
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");
|
|
110641
110432
|
terminal = true;
|
|
110642
110433
|
return "";
|
|
110643
110434
|
}
|
|
110644
|
-
session ||=
|
|
110435
|
+
session ||= str2(result.conversation_id) || void 0;
|
|
110645
110436
|
terminal = true;
|
|
110646
110437
|
final = typeof result.response === "string" ? result.response : void 0;
|
|
110647
110438
|
const total = usageOf(result.usage);
|
|
110648
|
-
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 } :
|
|
110439
|
+
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;
|
|
110649
110440
|
previous = total;
|
|
110650
110441
|
if (!Object.values(used).some((n) => n > 0)) used = void 0;
|
|
110651
110442
|
const missing = requiredImages.length ? requiredImages.filter((file3) => !readImages.has(file3)) : [...imageErrors.keys()];
|
|
@@ -110654,8 +110445,8 @@ ${imageError(target, reason || str(step.state))}
|
|
|
110654
110445
|
readImages.clear();
|
|
110655
110446
|
imageErrors.clear();
|
|
110656
110447
|
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");
|
|
110657
|
-
else if (!failure5 && (typeof result.response !== "string" || result.status !== "SUCCESS" ||
|
|
110658
|
-
fail(result.status === "CANCELED" ? `Antigravity: CANCELED${result.error ? `: ${
|
|
110448
|
+
else if (!failure5 && (typeof result.response !== "string" || result.status !== "SUCCESS" || str2(result.error) || result.finished_reason && result.finished_reason !== "completed" && result.finished_reason !== "success")) {
|
|
110449
|
+
fail(result.status === "CANCELED" ? `Antigravity: CANCELED${result.error ? `: ${str2(result.error)}` : ""}` : str2(result.error) || `Antigravity: ${str2(result.status) || "missing status"}`);
|
|
110659
110450
|
}
|
|
110660
110451
|
events.end();
|
|
110661
110452
|
turnUsage = zero();
|
|
@@ -110669,7 +110460,7 @@ ${imageError(target, reason || str(step.state))}
|
|
|
110669
110460
|
return {
|
|
110670
110461
|
push: reader.push,
|
|
110671
110462
|
setRequiredImages(files) {
|
|
110672
|
-
requiredImages = files.filter(imagePath).map((file3) =>
|
|
110463
|
+
requiredImages = files.filter(imagePath).map((file3) => path23.resolve(cwd, file3));
|
|
110673
110464
|
},
|
|
110674
110465
|
flush() {
|
|
110675
110466
|
const text3 = reader.flush();
|
|
@@ -110725,7 +110516,7 @@ function args(argv, resume) {
|
|
|
110725
110516
|
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.");
|
|
110726
110517
|
if (resume) {
|
|
110727
110518
|
const file3 = antigravityConversationFile(resume);
|
|
110728
|
-
if (!file3 || !
|
|
110519
|
+
if (!file3 || !fs21.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.");
|
|
110729
110520
|
}
|
|
110730
110521
|
const extra = resume ? ["--conversation", resume] : [];
|
|
110731
110522
|
if (!namesFlag(argv, ["--output-format"])) extra.push("--output-format", "stream-json");
|
|
@@ -110770,7 +110561,7 @@ var ANTIGRAVITY = {
|
|
|
110770
110561
|
const copy2 = locate(ANTIGRAVITY);
|
|
110771
110562
|
if (!copy2) return [];
|
|
110772
110563
|
const start = spawnable(copy2.file, ["models"], { env: copyEnv(copy2.file), stdio: ["ignore", "pipe", "ignore"], timeout: 15e3 });
|
|
110773
|
-
const result =
|
|
110564
|
+
const result = spawnSync2(start.command, start.args, { ...start.options, encoding: "utf8" });
|
|
110774
110565
|
return result.status === 0 ? antigravityModels(result.stdout ?? "").map((m) => m.id) : [];
|
|
110775
110566
|
},
|
|
110776
110567
|
env: () => ({ ...process.env }),
|
|
@@ -110784,10 +110575,10 @@ var ANTIGRAVITY = {
|
|
|
110784
110575
|
|
|
110785
110576
|
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.`;
|
|
110786
110577
|
const hash2 = createHash3("sha256").update(rule).digest("hex").slice(0, 16);
|
|
110787
|
-
const root2 =
|
|
110788
|
-
const file3 =
|
|
110789
|
-
|
|
110790
|
-
|
|
110578
|
+
const root2 = path24.join(machineHome(), "prompts", `antigravity-${hash2}`);
|
|
110579
|
+
const file3 = path24.join(root2, ".agents", "rules", "language.md");
|
|
110580
|
+
fs21.mkdirSync(path24.dirname(file3), { recursive: true });
|
|
110581
|
+
fs21.writeFileSync(file3, `---
|
|
110791
110582
|
trigger: always_on
|
|
110792
110583
|
---
|
|
110793
110584
|
|
|
@@ -110889,7 +110680,77 @@ function checkHarnesses(harnesses) {
|
|
|
110889
110680
|
}
|
|
110890
110681
|
|
|
110891
110682
|
// ../cli/src/lib/agent/harnesses/claude-code.ts
|
|
110892
|
-
import
|
|
110683
|
+
import path27 from "node:path";
|
|
110684
|
+
|
|
110685
|
+
// ../cli/src/lib/agent/retry.ts
|
|
110686
|
+
function readFailure(raw) {
|
|
110687
|
+
if (!raw || typeof raw !== "object") return;
|
|
110688
|
+
const { code, level, reason, source, retryAfterMs: retryAfterMs2 } = raw;
|
|
110689
|
+
if (typeof code !== "string" || !code || typeof reason !== "string" || level !== 1 && level !== 2 && level !== 3) return;
|
|
110690
|
+
return { code, level, reason, ...["validation", "provider", "harness", "invariant"].some((value) => value === source) ? { source } : {}, ...typeof retryAfterMs2 === "number" && retryAfterMs2 >= 0 ? { retryAfterMs: retryAfterMs2 } : {} };
|
|
110691
|
+
}
|
|
110692
|
+
|
|
110693
|
+
// ../cli/src/lib/agent/wire/failures.ts
|
|
110694
|
+
var ExecutionError = class extends Error {
|
|
110695
|
+
constructor(failure5) {
|
|
110696
|
+
super(failure5.reason);
|
|
110697
|
+
this.failure = failure5;
|
|
110698
|
+
}
|
|
110699
|
+
failure;
|
|
110700
|
+
};
|
|
110701
|
+
var NETWORK = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT", "ENETUNREACH", "EAI_AGAIN", "UND_ERR_SOCKET"]);
|
|
110702
|
+
var TEMPORARY_HTTP = /* @__PURE__ */ new Set([502, 503, 504, 529]);
|
|
110703
|
+
function executionFailure(error63) {
|
|
110704
|
+
if (error63 instanceof ExecutionError) return error63.failure;
|
|
110705
|
+
const code = str2(obj2(error63).code);
|
|
110706
|
+
const reason = error63 instanceof Error ? error63.message : String(error63);
|
|
110707
|
+
return {
|
|
110708
|
+
code: NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed",
|
|
110709
|
+
level: NETWORK.has(code) ? 2 : 3,
|
|
110710
|
+
source: "harness",
|
|
110711
|
+
reason
|
|
110712
|
+
};
|
|
110713
|
+
}
|
|
110714
|
+
function retryAfterMs(value, now = Date.now()) {
|
|
110715
|
+
if (typeof value !== "string") return;
|
|
110716
|
+
const header = value.trim();
|
|
110717
|
+
if (/^\d+$/.test(header)) return Math.min(Number(header) * 1e3, Number.MAX_SAFE_INTEGER);
|
|
110718
|
+
if (!/^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)) return;
|
|
110719
|
+
const date7 = Date.parse(header);
|
|
110720
|
+
if (Number.isFinite(date7)) return Math.max(0, date7 - now);
|
|
110721
|
+
}
|
|
110722
|
+
function providerFailure(error63, reason) {
|
|
110723
|
+
const info = obj2(error63);
|
|
110724
|
+
const status2 = typeof info.status === "number" ? info.status : void 0;
|
|
110725
|
+
const headers = obj2(info.headers);
|
|
110726
|
+
const wait = retryAfterMs(headers["retry-after"] ?? headers["Retry-After"]);
|
|
110727
|
+
const code = info.code ?? info.type;
|
|
110728
|
+
if (code === "session_not_found") return { code, source: "provider", level: 3, reason };
|
|
110729
|
+
if (status2 === 401 || status2 === 403 || ["authentication_error", "permission_error", "invalid_request_error"].includes(str2(code))) {
|
|
110730
|
+
return { code: "provider_refused", source: "provider", level: 3, reason };
|
|
110731
|
+
}
|
|
110732
|
+
if (code === "rate_limit_error") return { code: "rate_limited", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
110733
|
+
if (TEMPORARY_HTTP.has(status2 ?? 0) || code === "overloaded_error") return { code: "service_overloaded", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
110734
|
+
if (NETWORK.has(str2(code))) return { code: "connection_lost", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
110735
|
+
return { code: "provider_failed", source: "provider", level: 3, reason };
|
|
110736
|
+
}
|
|
110737
|
+
function codexFailure(raw, fallback) {
|
|
110738
|
+
const error63 = obj2(raw);
|
|
110739
|
+
const failure5 = readFailure(error63.wildcraneFailure);
|
|
110740
|
+
if (failure5?.source === "harness" || failure5?.source === "invariant") return failure5;
|
|
110741
|
+
const reason = str2(error63.message) || fallback;
|
|
110742
|
+
const info = error63.codexErrorInfo;
|
|
110743
|
+
if (info === "serverOverloaded") return providerFailure({ ...error63, type: "overloaded_error" }, reason);
|
|
110744
|
+
if (info === "rateLimitExceeded") return providerFailure({ ...error63, type: "rate_limit_error" }, reason);
|
|
110745
|
+
const types = obj2(info);
|
|
110746
|
+
for (const kind of ["httpConnectionFailed", "responseStreamConnectionFailed", "responseStreamDisconnected", "responseTooManyFailedAttempts"]) {
|
|
110747
|
+
if (!(kind in types)) continue;
|
|
110748
|
+
const status2 = obj2(types[kind]).httpStatusCode;
|
|
110749
|
+
if (typeof status2 === "number") return providerFailure({ ...error63, status: status2 }, reason);
|
|
110750
|
+
if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error63, code: "ECONNRESET" }, reason);
|
|
110751
|
+
}
|
|
110752
|
+
return providerFailure(error63, reason);
|
|
110753
|
+
}
|
|
110893
110754
|
|
|
110894
110755
|
// ../cli/src/lib/agent/wire/claude-stream.ts
|
|
110895
110756
|
var ARG_KEYS = ["command", "file_path", "path", "pattern", "description", "prompt", "query", "url"];
|
|
@@ -110907,13 +110768,13 @@ var TOOL_KINDS2 = {
|
|
|
110907
110768
|
};
|
|
110908
110769
|
var SUBAGENT_TOOLS = /* @__PURE__ */ new Set(["Agent", "Task"]);
|
|
110909
110770
|
function targetOf2(input2) {
|
|
110910
|
-
const args2 =
|
|
110911
|
-
for (const key of ARG_KEYS) if (
|
|
110771
|
+
const args2 = obj2(input2);
|
|
110772
|
+
for (const key of ARG_KEYS) if (str2(args2[key]).trim()) return str2(args2[key]);
|
|
110912
110773
|
return "";
|
|
110913
110774
|
}
|
|
110914
110775
|
function resultText(raw) {
|
|
110915
110776
|
if (typeof raw === "string") return raw;
|
|
110916
|
-
return (Array.isArray(raw) ? raw : []).map((b) =>
|
|
110777
|
+
return (Array.isArray(raw) ? raw : []).map((b) => str2(obj2(b).text)).filter(Boolean).join("\n");
|
|
110917
110778
|
}
|
|
110918
110779
|
function eventModel(ev) {
|
|
110919
110780
|
if (ev.type === "system" && ev.subtype === "init" && typeof ev.model === "string") {
|
|
@@ -110936,29 +110797,29 @@ var USER_FIXES = [
|
|
|
110936
110797
|
[/usage limit|credit balance is too low|quota/i, "Wait for the usage limit to reset, or add credit, then press Resume."]
|
|
110937
110798
|
];
|
|
110938
110799
|
function failedWith(ev) {
|
|
110939
|
-
const errors = Array.isArray(ev.errors) ? ev.errors.map(
|
|
110800
|
+
const errors = Array.isArray(ev.errors) ? ev.errors.map(str2).filter(Boolean) : [];
|
|
110940
110801
|
if (errors.length) return errors.join("; ");
|
|
110941
|
-
const named =
|
|
110802
|
+
const named = str2(ev.subtype) || str2(ev.terminal_reason);
|
|
110942
110803
|
if (named && named !== "error" && named !== "success") return named;
|
|
110943
|
-
return
|
|
110804
|
+
return str2(ev.result).trim() || "the agent reported the session failed";
|
|
110944
110805
|
}
|
|
110945
110806
|
function denials(ev) {
|
|
110946
110807
|
const list3 = Array.isArray(ev.permission_denials) ? ev.permission_denials : [];
|
|
110947
|
-
const names = [...new Set(list3.map((raw) =>
|
|
110808
|
+
const names = [...new Set(list3.map((raw) => str2(obj2(raw).tool_name)).filter(Boolean))];
|
|
110948
110809
|
if (!names.length) return "";
|
|
110949
110810
|
return `[refused] ${list3.length} tool call${list3.length === 1 ? "" : "s"} were not allowed: ${names.join(", ")}
|
|
110950
110811
|
`;
|
|
110951
110812
|
}
|
|
110952
110813
|
function promptSize(raw) {
|
|
110953
|
-
const u =
|
|
110954
|
-
const size =
|
|
110814
|
+
const u = obj2(raw);
|
|
110815
|
+
const size = num2(u.input_tokens) + num2(u.cache_creation_input_tokens) + num2(u.cache_read_input_tokens);
|
|
110955
110816
|
return size > 0 ? size : void 0;
|
|
110956
110817
|
}
|
|
110957
110818
|
function windowOf(raw, model) {
|
|
110958
|
-
const entries =
|
|
110819
|
+
const entries = obj2(raw);
|
|
110959
110820
|
const names = Object.keys(entries);
|
|
110960
110821
|
const name = model && names.includes(model) ? model : names.length === 1 ? names[0] : void 0;
|
|
110961
|
-
return name ?
|
|
110822
|
+
return name ? num2(obj2(entries[name]).contextWindow) || void 0 : void 0;
|
|
110962
110823
|
}
|
|
110963
110824
|
function createStreamRenderer() {
|
|
110964
110825
|
let final;
|
|
@@ -110988,8 +110849,8 @@ function createStreamRenderer() {
|
|
|
110988
110849
|
if (!ev) return `${line}
|
|
110989
110850
|
`;
|
|
110990
110851
|
if (model === void 0) model = eventModel(ev);
|
|
110991
|
-
if (
|
|
110992
|
-
if (ev.type === "assistant" || ev.type === "stream_event" &&
|
|
110852
|
+
if (str2(ev.parent_tool_use_id)) return "";
|
|
110853
|
+
if (ev.type === "assistant" || ev.type === "stream_event" && obj2(ev.event).type === "content_block_delta") events.progress();
|
|
110993
110854
|
switch (ev.type) {
|
|
110994
110855
|
case "assistant": {
|
|
110995
110856
|
apiFailure = typeof ev.error === "string" ? providerFailure({ type: ev.error }, "Claude could not complete the request.") : void 0;
|
|
@@ -111009,30 +110870,30 @@ function createStreamRenderer() {
|
|
|
111009
110870
|
out.push(`\u23FA ${b.name}${argHint(b.input, ARG_KEYS)}
|
|
111010
110871
|
`);
|
|
111011
110872
|
if (SUBAGENT_TOOLS.has(b.name)) {
|
|
111012
|
-
const input2 =
|
|
111013
|
-
subagents.set(
|
|
111014
|
-
if (input2.run_in_background === true) detached.add(
|
|
111015
|
-
events.subagent(
|
|
110873
|
+
const input2 = obj2(b.input);
|
|
110874
|
+
subagents.set(str2(b.id), false);
|
|
110875
|
+
if (input2.run_in_background === true) detached.add(str2(b.id));
|
|
110876
|
+
events.subagent(str2(b.id), str2(input2.description) || str2(input2.subagent_type) || b.name);
|
|
111016
110877
|
} else if (b.name === "TodoWrite") {
|
|
111017
|
-
plans.add(
|
|
111018
|
-
events.plan(
|
|
110878
|
+
plans.add(str2(b.id));
|
|
110879
|
+
events.plan(obj2(b.input).todos);
|
|
111019
110880
|
} else {
|
|
111020
|
-
events.toolCall(
|
|
110881
|
+
events.toolCall(str2(b.id), b.name, TOOL_KINDS2[b.name] ?? "other", targetOf2(b.input));
|
|
111021
110882
|
}
|
|
111022
110883
|
}
|
|
111023
110884
|
}
|
|
111024
110885
|
return out.join("");
|
|
111025
110886
|
}
|
|
111026
110887
|
case "user": {
|
|
111027
|
-
const content =
|
|
110888
|
+
const content = obj2(ev.message).content;
|
|
111028
110889
|
for (const raw of Array.isArray(content) ? content : []) {
|
|
111029
|
-
const b =
|
|
111030
|
-
if (b.type !== "tool_result" || plans.has(
|
|
111031
|
-
if (subagents.has(
|
|
111032
|
-
if (!detached.has(
|
|
110890
|
+
const b = obj2(raw);
|
|
110891
|
+
if (b.type !== "tool_result" || plans.has(str2(b.tool_use_id))) continue;
|
|
110892
|
+
if (subagents.has(str2(b.tool_use_id))) {
|
|
110893
|
+
if (!detached.has(str2(b.tool_use_id))) endSubagent(str2(b.tool_use_id), b.is_error === true ? "failed" : "completed");
|
|
111033
110894
|
continue;
|
|
111034
110895
|
}
|
|
111035
|
-
events.toolResult(
|
|
110896
|
+
events.toolResult(str2(b.tool_use_id), b.is_error === true ? "failed" : "completed", resultText(b.content));
|
|
111036
110897
|
}
|
|
111037
110898
|
return "";
|
|
111038
110899
|
}
|
|
@@ -111060,12 +110921,12 @@ function createStreamRenderer() {
|
|
|
111060
110921
|
}
|
|
111061
110922
|
case "system":
|
|
111062
110923
|
if (ev.subtype === "background_tasks_changed" && Array.isArray(ev.tasks)) background = ev.tasks.length;
|
|
111063
|
-
if (ev.subtype === "task_started" && ev.is_backgrounded === true) backgrounded.add(
|
|
111064
|
-
if (ev.subtype === "task_notification" && subagents.has(
|
|
111065
|
-
endSubagent(
|
|
110924
|
+
if (ev.subtype === "task_started" && ev.is_backgrounded === true) backgrounded.add(str2(ev.task_id));
|
|
110925
|
+
if (ev.subtype === "task_notification" && subagents.has(str2(ev.tool_use_id))) {
|
|
110926
|
+
endSubagent(str2(ev.tool_use_id), str2(ev.status) === "completed" ? "completed" : "failed");
|
|
111066
110927
|
}
|
|
111067
|
-
if (ev.subtype === "task_notification" && backgrounded.has(
|
|
111068
|
-
return `\u23FA ${
|
|
110928
|
+
if (ev.subtype === "task_notification" && backgrounded.has(str2(ev.task_id)) && str2(ev.summary)) {
|
|
110929
|
+
return `\u23FA ${str2(ev.summary)}
|
|
111069
110930
|
`;
|
|
111070
110931
|
}
|
|
111071
110932
|
return "";
|
|
@@ -111092,10 +110953,10 @@ function usageOf2(raw) {
|
|
|
111092
110953
|
if (!raw || typeof raw !== "object") return void 0;
|
|
111093
110954
|
const u = raw;
|
|
111094
110955
|
const parsed = {
|
|
111095
|
-
input:
|
|
111096
|
-
cacheCreation:
|
|
111097
|
-
cacheRead:
|
|
111098
|
-
output:
|
|
110956
|
+
input: num2(u.input_tokens),
|
|
110957
|
+
cacheCreation: num2(u.cache_creation_input_tokens),
|
|
110958
|
+
cacheRead: num2(u.cache_read_input_tokens),
|
|
110959
|
+
output: num2(u.output_tokens)
|
|
111099
110960
|
};
|
|
111100
110961
|
return parsed.input + parsed.cacheCreation + parsed.cacheRead + parsed.output > 0 ? parsed : void 0;
|
|
111101
110962
|
}
|
|
@@ -111290,13 +111151,13 @@ var imageSafeText = (text3) => text3.replace(/data:image\/[a-z0-9.+-]+;base64,[A
|
|
|
111290
111151
|
function renderStarted(item) {
|
|
111291
111152
|
switch (item.type) {
|
|
111292
111153
|
case "command_execution":
|
|
111293
|
-
return `\u23FA Command${hint(
|
|
111154
|
+
return `\u23FA Command${hint(str2(item.command))}
|
|
111294
111155
|
`;
|
|
111295
111156
|
case "mcp_tool_call":
|
|
111296
|
-
return `\u23FA ${
|
|
111157
|
+
return `\u23FA ${str2(item.server)}.${str2(item.tool)}
|
|
111297
111158
|
`;
|
|
111298
111159
|
case "web_search":
|
|
111299
|
-
return `\u23FA WebSearch${hint(
|
|
111160
|
+
return `\u23FA WebSearch${hint(str2(item.query))}
|
|
111300
111161
|
`;
|
|
111301
111162
|
default:
|
|
111302
111163
|
return "";
|
|
@@ -111305,7 +111166,7 @@ function renderStarted(item) {
|
|
|
111305
111166
|
function renderCompleted(item) {
|
|
111306
111167
|
switch (item.type) {
|
|
111307
111168
|
case "agent_message": {
|
|
111308
|
-
const said = imageSafeText(
|
|
111169
|
+
const said = imageSafeText(str2(item.text)).trim();
|
|
111309
111170
|
return said ? `${said}
|
|
111310
111171
|
|
|
111311
111172
|
` : "";
|
|
@@ -111313,18 +111174,18 @@ function renderCompleted(item) {
|
|
|
111313
111174
|
case "file_change": {
|
|
111314
111175
|
const changes = Array.isArray(item.changes) ? item.changes : [];
|
|
111315
111176
|
return changes.map((raw) => {
|
|
111316
|
-
const change =
|
|
111317
|
-
const path38 =
|
|
111318
|
-
return path38 ? `\u23FA ${
|
|
111177
|
+
const change = obj2(raw);
|
|
111178
|
+
const path38 = str2(change.path);
|
|
111179
|
+
return path38 ? `\u23FA ${str2(change.kind) || "change"}(${path38})
|
|
111319
111180
|
` : "";
|
|
111320
111181
|
}).join("");
|
|
111321
111182
|
}
|
|
111322
111183
|
case "error":
|
|
111323
|
-
return `[error] ${
|
|
111184
|
+
return `[error] ${str2(item.message)}
|
|
111324
111185
|
`;
|
|
111325
111186
|
case "mcp_tool_call": {
|
|
111326
|
-
const error63 =
|
|
111327
|
-
return error63 ? `[MCP ${
|
|
111187
|
+
const error63 = str2(obj2(item.error).message);
|
|
111188
|
+
return error63 ? `[MCP ${str2(item.server)}.${str2(item.tool)}] ${error63}
|
|
111328
111189
|
` : "";
|
|
111329
111190
|
}
|
|
111330
111191
|
default:
|
|
@@ -111339,47 +111200,47 @@ function unwrapShell(command) {
|
|
|
111339
111200
|
function callOf(item) {
|
|
111340
111201
|
switch (item.type) {
|
|
111341
111202
|
case "command_execution":
|
|
111342
|
-
return { title: "Command", target: unwrapShell(
|
|
111203
|
+
return { title: "Command", target: unwrapShell(str2(item.command)) };
|
|
111343
111204
|
case "mcp_tool_call":
|
|
111344
|
-
return { title: `${
|
|
111205
|
+
return { title: `${str2(item.server)}.${str2(item.tool)}`, target: "" };
|
|
111345
111206
|
case "web_search":
|
|
111346
|
-
return { title: "WebSearch", target:
|
|
111207
|
+
return { title: "WebSearch", target: str2(item.query) };
|
|
111347
111208
|
default: {
|
|
111348
|
-
const changes = (Array.isArray(item.changes) ? item.changes : []).map((c) =>
|
|
111209
|
+
const changes = (Array.isArray(item.changes) ? item.changes : []).map((c) => str2(obj2(c).path)).filter(Boolean);
|
|
111349
111210
|
return { title: "Edit", target: changes.join(", ") };
|
|
111350
111211
|
}
|
|
111351
111212
|
}
|
|
111352
111213
|
}
|
|
111353
111214
|
function callResult(item) {
|
|
111354
|
-
if (item.type === "command_execution") return
|
|
111215
|
+
if (item.type === "command_execution") return str2(item.aggregated_output);
|
|
111355
111216
|
if (item.type === "mcp_tool_call") {
|
|
111356
|
-
const error63 =
|
|
111217
|
+
const error63 = str2(obj2(item.error).message);
|
|
111357
111218
|
if (error63) return error63;
|
|
111358
|
-
const content =
|
|
111359
|
-
return (Array.isArray(content) ? content : []).map((b) => imageSafeText(
|
|
111219
|
+
const content = obj2(item.result).content;
|
|
111220
|
+
return (Array.isArray(content) ? content : []).map((b) => imageSafeText(str2(obj2(b).text))).filter(Boolean).join("\n");
|
|
111360
111221
|
}
|
|
111361
111222
|
if (item.type === "file_change") {
|
|
111362
|
-
return (Array.isArray(item.changes) ? item.changes : []).map((c) => `${
|
|
111223
|
+
return (Array.isArray(item.changes) ? item.changes : []).map((c) => `${str2(obj2(c).kind) || "change"} ${str2(obj2(c).path)}`).join("\n");
|
|
111363
111224
|
}
|
|
111364
111225
|
return "";
|
|
111365
111226
|
}
|
|
111366
111227
|
function itemEvents(events, started, item, done) {
|
|
111367
|
-
const id2 =
|
|
111228
|
+
const id2 = str2(item.id);
|
|
111368
111229
|
if (item.type === "agent_message") {
|
|
111369
|
-
if (done) events.message(imageSafeText(
|
|
111230
|
+
if (done) events.message(imageSafeText(str2(item.text)));
|
|
111370
111231
|
return;
|
|
111371
111232
|
}
|
|
111372
111233
|
if (item.type === "todo_list") {
|
|
111373
111234
|
const items = Array.isArray(item.items) ? item.items : [];
|
|
111374
|
-
events.plan(items.map(
|
|
111235
|
+
events.plan(items.map(obj2).map((t2) => ({ content: str2(t2.text), status: t2.completed === true ? "completed" : "pending" })));
|
|
111375
111236
|
return;
|
|
111376
111237
|
}
|
|
111377
111238
|
if (item.type === "error") {
|
|
111378
|
-
if (done) events.log(`${
|
|
111239
|
+
if (done) events.log(`${str2(item.message)}
|
|
111379
111240
|
`);
|
|
111380
111241
|
return;
|
|
111381
111242
|
}
|
|
111382
|
-
const kind = CALLS[
|
|
111243
|
+
const kind = CALLS[str2(item.type)];
|
|
111383
111244
|
if (!kind) return;
|
|
111384
111245
|
if (!started.has(id2)) {
|
|
111385
111246
|
started.add(id2);
|
|
@@ -111408,23 +111269,23 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
111408
111269
|
const collabItems = /* @__PURE__ */ new Set();
|
|
111409
111270
|
const collab = (item, done) => {
|
|
111410
111271
|
if (item.type !== "collab_tool_call") return;
|
|
111411
|
-
const key = `${
|
|
111272
|
+
const key = `${str2(item.id)}:${done}`;
|
|
111412
111273
|
if (collabItems.has(key)) return;
|
|
111413
111274
|
collabItems.add(key);
|
|
111414
|
-
for (const [id2, raw] of Object.entries(
|
|
111415
|
-
const state2 =
|
|
111416
|
-
const status2 =
|
|
111275
|
+
for (const [id2, raw] of Object.entries(obj2(item.agents_states))) {
|
|
111276
|
+
const state2 = obj2(raw);
|
|
111277
|
+
const status2 = str2(state2.status);
|
|
111417
111278
|
if (!["pending_init", "running", "completed", "interrupted", "errored", "shutdown", "not_found"].includes(status2)) continue;
|
|
111418
111279
|
const previous = background.results().find((t2) => t2.id === id2);
|
|
111419
111280
|
if (["shutdown", "not_found"].includes(status2) && previous && previous.status !== "running") continue;
|
|
111420
111281
|
if (!subagents.has(id2)) {
|
|
111421
111282
|
subagents.add(id2);
|
|
111422
|
-
events.subagent(`agent:${id2}`,
|
|
111283
|
+
events.subagent(`agent:${id2}`, str2(item.prompt) || "Agent");
|
|
111423
111284
|
}
|
|
111424
111285
|
const running = status2 === "pending_init" || status2 === "running";
|
|
111425
111286
|
const failed = !running && status2 !== "completed";
|
|
111426
|
-
if (background.update(id2, running ? "running" : failed ? "failed" : "completed",
|
|
111427
|
-
events.toolResult(`agent:${id2}`, failed ? "failed" : "completed",
|
|
111287
|
+
if (background.update(id2, running ? "running" : failed ? "failed" : "completed", str2(state2.message)) && !running) {
|
|
111288
|
+
events.toolResult(`agent:${id2}`, failed ? "failed" : "completed", str2(state2.message));
|
|
111428
111289
|
}
|
|
111429
111290
|
}
|
|
111430
111291
|
};
|
|
@@ -111451,34 +111312,34 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
111451
111312
|
`;
|
|
111452
111313
|
switch (ev.type) {
|
|
111453
111314
|
case "thread.started":
|
|
111454
|
-
if (!threadId) threadId =
|
|
111315
|
+
if (!threadId) threadId = str2(ev.thread_id).trim() || void 0;
|
|
111455
111316
|
return "";
|
|
111456
111317
|
case "item.started":
|
|
111457
|
-
collab(
|
|
111458
|
-
itemEvents(events, started,
|
|
111459
|
-
return renderStarted(
|
|
111318
|
+
collab(obj2(ev.item), false);
|
|
111319
|
+
itemEvents(events, started, obj2(ev.item), false);
|
|
111320
|
+
return renderStarted(obj2(ev.item));
|
|
111460
111321
|
case "item.updated":
|
|
111461
|
-
if (
|
|
111322
|
+
if (obj2(ev.item).type === "todo_list") itemEvents(events, started, obj2(ev.item), false);
|
|
111462
111323
|
return "";
|
|
111463
111324
|
case "item.completed": {
|
|
111464
|
-
const item =
|
|
111325
|
+
const item = obj2(ev.item);
|
|
111465
111326
|
collab(item, true);
|
|
111466
|
-
if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(
|
|
111467
|
-
const content =
|
|
111327
|
+
if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str2(item.tool))) {
|
|
111328
|
+
const content = obj2(item.result).content;
|
|
111468
111329
|
for (const block of Array.isArray(content) ? content : []) {
|
|
111469
|
-
const b =
|
|
111470
|
-
const audience =
|
|
111330
|
+
const b = obj2(block);
|
|
111331
|
+
const audience = obj2(b.annotations).audience;
|
|
111471
111332
|
if (Array.isArray(audience) && !audience.includes("user")) continue;
|
|
111472
|
-
if (b.type === "resource_link" &&
|
|
111473
|
-
pictures.push({ type: "image", path:
|
|
111333
|
+
if (b.type === "resource_link" && str2(b.uri).startsWith("file:") && /^image\/(png|jpeg|gif|webp)$/.test(str2(b.mimeType)) && pictures.length < 100) {
|
|
111334
|
+
pictures.push({ type: "image", path: str2(b.uri), mime: str2(b.mimeType), registered: true });
|
|
111474
111335
|
}
|
|
111475
|
-
if (b.type === "image" && pictures.length < 100) pictures.push(
|
|
111336
|
+
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" });
|
|
111476
111337
|
}
|
|
111477
111338
|
}
|
|
111478
111339
|
if (item.type === "image_generation" && typeof item.path === "string") pictures.push({ type: "image", path: item.path, registered: true });
|
|
111479
111340
|
itemEvents(events, started, item, true);
|
|
111480
111341
|
if (item.type === "agent_message") {
|
|
111481
|
-
const said =
|
|
111342
|
+
const said = str2(item.text).trim();
|
|
111482
111343
|
if (item.phase !== "commentary" && (said || pictures.length)) final = said;
|
|
111483
111344
|
}
|
|
111484
111345
|
return renderCompleted(item);
|
|
@@ -111489,14 +111350,14 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
111489
111350
|
return "";
|
|
111490
111351
|
// 最终失败保留;连接提示只在没有后续成功完成时才作为失败。
|
|
111491
111352
|
case "turn.failed": {
|
|
111492
|
-
const said =
|
|
111353
|
+
const said = str2(obj2(ev.error).message) || failure5?.reason || "Codex execution failed.";
|
|
111493
111354
|
failure5 = codexFailure(ev.error, said);
|
|
111494
111355
|
events.error(said);
|
|
111495
111356
|
return `[error] ${said}
|
|
111496
111357
|
`;
|
|
111497
111358
|
}
|
|
111498
111359
|
case "error": {
|
|
111499
|
-
const said =
|
|
111360
|
+
const said = str2(ev.message);
|
|
111500
111361
|
if (ev.willRetry !== true && ev.will_retry !== true && said) failure5 = codexFailure(ev.error ?? ev, said);
|
|
111501
111362
|
events.log(`[Codex] ${said}
|
|
111502
111363
|
`);
|
|
@@ -111588,14 +111449,14 @@ function readIndex() {
|
|
|
111588
111449
|
} catch {
|
|
111589
111450
|
continue;
|
|
111590
111451
|
}
|
|
111591
|
-
const sessionId =
|
|
111452
|
+
const sessionId = str2(record3.sessionId).trim();
|
|
111592
111453
|
if (!sessionId) continue;
|
|
111593
111454
|
if (record3.deleted === true) {
|
|
111594
111455
|
entries.delete(sessionId);
|
|
111595
111456
|
continue;
|
|
111596
111457
|
}
|
|
111597
|
-
const sessionDir =
|
|
111598
|
-
const workDir =
|
|
111458
|
+
const sessionDir = str2(record3.sessionDir).trim();
|
|
111459
|
+
const workDir = str2(record3.workDir).trim();
|
|
111599
111460
|
if (sessionDir && workDir) entries.set(sessionId, { sessionId, sessionDir, workDir });
|
|
111600
111461
|
}
|
|
111601
111462
|
return entries;
|
|
@@ -111651,14 +111512,14 @@ function readKimiRunFacts(sessionId) {
|
|
|
111651
111512
|
continue;
|
|
111652
111513
|
}
|
|
111653
111514
|
if (record3.type !== "usage.record") continue;
|
|
111654
|
-
model ??=
|
|
111655
|
-
const usage =
|
|
111656
|
-
total.input +=
|
|
111657
|
-
total.cacheCreation +=
|
|
111658
|
-
total.cacheRead +=
|
|
111659
|
-
total.output +=
|
|
111515
|
+
model ??= str2(record3.model).trim() || void 0;
|
|
111516
|
+
const usage = obj2(record3.usage);
|
|
111517
|
+
total.input += num2(usage.inputOther);
|
|
111518
|
+
total.cacheCreation += num2(usage.inputCacheCreation);
|
|
111519
|
+
total.cacheRead += num2(usage.inputCacheRead);
|
|
111520
|
+
total.output += num2(usage.output);
|
|
111660
111521
|
if (main2) {
|
|
111661
|
-
holding =
|
|
111522
|
+
holding = num2(usage.inputOther) + num2(usage.inputCacheCreation) + num2(usage.inputCacheRead);
|
|
111662
111523
|
}
|
|
111663
111524
|
}
|
|
111664
111525
|
}
|
|
@@ -111675,7 +111536,7 @@ function readKimiRunFacts(sessionId) {
|
|
|
111675
111536
|
// ../cli/src/lib/agent/wire/kimi-stream.ts
|
|
111676
111537
|
var ARG_KEYS2 = ["command", "path", "pattern", "query", "url", "prompt", "prompt_template", "description"];
|
|
111677
111538
|
function callArgs(raw) {
|
|
111678
|
-
const text3 =
|
|
111539
|
+
const text3 = str2(raw);
|
|
111679
111540
|
if (!text3.trim()) return {};
|
|
111680
111541
|
try {
|
|
111681
111542
|
return JSON.parse(text3);
|
|
@@ -111694,16 +111555,16 @@ var kindOf = (name) => TOOL_KINDS3.find(([re]) => re.test(name))?.[1] ?? "other"
|
|
|
111694
111555
|
function toolCalls(row) {
|
|
111695
111556
|
const calls = Array.isArray(row.tool_calls) ? row.tool_calls : [];
|
|
111696
111557
|
return calls.map((raw) => {
|
|
111697
|
-
const call2 =
|
|
111698
|
-
const fn =
|
|
111699
|
-
const name =
|
|
111558
|
+
const call2 = obj2(raw);
|
|
111559
|
+
const fn = obj2(call2.function);
|
|
111560
|
+
const name = str2(fn.name) || "tool";
|
|
111700
111561
|
return `\u23FA ${name}${argHint(callArgs(fn.arguments), ARG_KEYS2)}
|
|
111701
111562
|
`;
|
|
111702
111563
|
}).join("");
|
|
111703
111564
|
}
|
|
111704
111565
|
function retry(row) {
|
|
111705
|
-
const why =
|
|
111706
|
-
const attempt = `${
|
|
111566
|
+
const why = str2(row.error_message) || str2(row.error_name) || "the provider failed";
|
|
111567
|
+
const attempt = `${num2(row.next_attempt)}/${num2(row.max_attempts)}`;
|
|
111707
111568
|
return `[retry ${attempt}] ${why}
|
|
111708
111569
|
`;
|
|
111709
111570
|
}
|
|
@@ -111732,18 +111593,18 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
111732
111593
|
switch (row.role) {
|
|
111733
111594
|
case "assistant": {
|
|
111734
111595
|
events.progress();
|
|
111735
|
-
const said =
|
|
111596
|
+
const said = str2(row.content).trim();
|
|
111736
111597
|
if (said) final = said;
|
|
111737
111598
|
if (said) events.message(said);
|
|
111738
111599
|
for (const raw of Array.isArray(row.tool_calls) ? row.tool_calls : []) {
|
|
111739
|
-
const call2 =
|
|
111740
|
-
const name =
|
|
111741
|
-
const args2 =
|
|
111600
|
+
const call2 = obj2(raw);
|
|
111601
|
+
const name = str2(obj2(call2.function).name) || "tool";
|
|
111602
|
+
const args2 = obj2(callArgs(obj2(call2.function).arguments));
|
|
111742
111603
|
if (name === "Agent") {
|
|
111743
|
-
subagents.add(
|
|
111744
|
-
events.subagent(
|
|
111604
|
+
subagents.add(str2(call2.id));
|
|
111605
|
+
events.subagent(str2(call2.id), str2(args2.description) || name);
|
|
111745
111606
|
} else {
|
|
111746
|
-
events.toolCall(
|
|
111607
|
+
events.toolCall(str2(call2.id), name, kindOf(name), ARG_KEYS2.map((k) => str2(args2[k])).find((v) => v.trim()));
|
|
111747
111608
|
}
|
|
111748
111609
|
}
|
|
111749
111610
|
return `${said ? `${said}
|
|
@@ -111751,11 +111612,11 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
111751
111612
|
` : ""}${toolCalls(row)}`;
|
|
111752
111613
|
}
|
|
111753
111614
|
case "meta":
|
|
111754
|
-
if (row.type === "session.resume_hint") sessionId ??=
|
|
111615
|
+
if (row.type === "session.resume_hint") sessionId ??= str2(row.session_id).trim() || void 0;
|
|
111755
111616
|
return row.type === "turn.step.retrying" ? retry(row) : "";
|
|
111756
111617
|
case "tool": {
|
|
111757
|
-
const id2 =
|
|
111758
|
-
const text3 =
|
|
111618
|
+
const id2 = str2(row.tool_call_id);
|
|
111619
|
+
const text3 = str2(row.content);
|
|
111759
111620
|
if (subagents.delete(id2)) events.toolResult(id2, /^status: completed$/m.test(text3) ? "completed" : "failed", "");
|
|
111760
111621
|
else events.toolResult(id2, "completed", text3);
|
|
111761
111622
|
return "";
|
|
@@ -111795,16 +111656,16 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
111795
111656
|
}
|
|
111796
111657
|
|
|
111797
111658
|
// ../cli/src/lib/agent/wire/acp-cost.ts
|
|
111798
|
-
import
|
|
111799
|
-
import
|
|
111659
|
+
import fs22 from "node:fs";
|
|
111660
|
+
import path25 from "node:path";
|
|
111800
111661
|
import { createHash as createHash4 } from "node:crypto";
|
|
111801
111662
|
function acpCostFile(tool, cwd, session) {
|
|
111802
111663
|
const key = createHash4("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
|
|
111803
|
-
return
|
|
111664
|
+
return path25.join(machineHome(), "usage", "acp", `${key}.json`);
|
|
111804
111665
|
}
|
|
111805
111666
|
function readAcpCost(file3) {
|
|
111806
111667
|
try {
|
|
111807
|
-
const n = JSON.parse(
|
|
111668
|
+
const n = JSON.parse(fs22.readFileSync(file3, "utf8"));
|
|
111808
111669
|
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
111809
111670
|
} catch {
|
|
111810
111671
|
return void 0;
|
|
@@ -111813,16 +111674,115 @@ function readAcpCost(file3) {
|
|
|
111813
111674
|
function saveAcpCost(file3, cost) {
|
|
111814
111675
|
if (cost === void 0) return;
|
|
111815
111676
|
try {
|
|
111816
|
-
|
|
111677
|
+
fs22.mkdirSync(path25.dirname(file3), { recursive: true, mode: 448 });
|
|
111817
111678
|
const tmp = `${file3}.${process.pid}.tmp`;
|
|
111818
|
-
|
|
111819
|
-
|
|
111679
|
+
fs22.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
|
|
111680
|
+
fs22.renameSync(tmp, file3);
|
|
111820
111681
|
} catch {
|
|
111821
111682
|
}
|
|
111822
111683
|
}
|
|
111823
111684
|
|
|
111685
|
+
// ../cli/src/lib/shared/conversation.ts
|
|
111686
|
+
var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
|
|
111687
|
+
function bounded(work, ms, reason) {
|
|
111688
|
+
return new Promise((resolve2, reject) => {
|
|
111689
|
+
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
111690
|
+
work.then((value) => {
|
|
111691
|
+
clearTimeout(timer);
|
|
111692
|
+
resolve2(value);
|
|
111693
|
+
}, (error63) => {
|
|
111694
|
+
clearTimeout(timer);
|
|
111695
|
+
reject(error63);
|
|
111696
|
+
});
|
|
111697
|
+
});
|
|
111698
|
+
}
|
|
111699
|
+
|
|
111824
111700
|
// ../cli/src/lib/agent/wire/acp.ts
|
|
111825
|
-
import
|
|
111701
|
+
import fs23 from "node:fs";
|
|
111702
|
+
|
|
111703
|
+
// ../cli/src/lib/agent/wire/rpc.ts
|
|
111704
|
+
var RpcError = class extends Error {
|
|
111705
|
+
constructor(message, code, data) {
|
|
111706
|
+
super(message);
|
|
111707
|
+
this.code = code;
|
|
111708
|
+
this.data = data;
|
|
111709
|
+
this.name = "RpcError";
|
|
111710
|
+
}
|
|
111711
|
+
code;
|
|
111712
|
+
data;
|
|
111713
|
+
};
|
|
111714
|
+
function connect(stdout, stdin, onCall, dialect = {}) {
|
|
111715
|
+
let buf = "";
|
|
111716
|
+
let nextId = 1;
|
|
111717
|
+
let gone;
|
|
111718
|
+
const waiting2 = /* @__PURE__ */ new Map();
|
|
111719
|
+
const send2 = (msg) => {
|
|
111720
|
+
if (gone) return;
|
|
111721
|
+
try {
|
|
111722
|
+
stdin.write(`${JSON.stringify(dialect.jsonrpc ? { jsonrpc: "2.0", ...msg } : msg)}
|
|
111723
|
+
`);
|
|
111724
|
+
} catch {
|
|
111725
|
+
}
|
|
111726
|
+
};
|
|
111727
|
+
const closed = (why) => {
|
|
111728
|
+
if (gone) return;
|
|
111729
|
+
gone = why;
|
|
111730
|
+
for (const { fail } of waiting2.values()) fail(why);
|
|
111731
|
+
waiting2.clear();
|
|
111732
|
+
};
|
|
111733
|
+
stdout.on("data", (chunk) => {
|
|
111734
|
+
buf += chunk.toString();
|
|
111735
|
+
const lines = buf.split("\n");
|
|
111736
|
+
buf = lines.pop() ?? "";
|
|
111737
|
+
for (const line of lines) {
|
|
111738
|
+
if (!line.trim()) continue;
|
|
111739
|
+
let msg;
|
|
111740
|
+
try {
|
|
111741
|
+
msg = JSON.parse(line);
|
|
111742
|
+
} catch {
|
|
111743
|
+
continue;
|
|
111744
|
+
}
|
|
111745
|
+
if (msg.method) {
|
|
111746
|
+
onCall(msg);
|
|
111747
|
+
continue;
|
|
111748
|
+
}
|
|
111749
|
+
if (msg.id === void 0) continue;
|
|
111750
|
+
const pending = waiting2.get(String(msg.id));
|
|
111751
|
+
if (!pending) continue;
|
|
111752
|
+
waiting2.delete(String(msg.id));
|
|
111753
|
+
if (msg.error) {
|
|
111754
|
+
const said = [str2(msg.error.message), str2(obj2(msg.error.data).message)].filter(Boolean).join(": ");
|
|
111755
|
+
pending.fail(new RpcError(said || `the agent refused (${msg.error.code ?? "no code"})`, msg.error.code, msg.error.data));
|
|
111756
|
+
} else pending.ok(obj2(msg.result));
|
|
111757
|
+
}
|
|
111758
|
+
});
|
|
111759
|
+
stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", level: 2, reason: "The agent closed the connection." })));
|
|
111760
|
+
stdout.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
|
|
111761
|
+
stdin.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
|
|
111762
|
+
return {
|
|
111763
|
+
/** Ask the agent something. Rejects with the agent's own words when it says no. */
|
|
111764
|
+
call(method, params) {
|
|
111765
|
+
if (gone) return Promise.reject(gone);
|
|
111766
|
+
const id2 = dialect.stringIds ? String(nextId++) : nextId++;
|
|
111767
|
+
return new Promise((ok, fail) => {
|
|
111768
|
+
waiting2.set(String(id2), { ok, fail });
|
|
111769
|
+
send2({ id: id2, method, params });
|
|
111770
|
+
});
|
|
111771
|
+
},
|
|
111772
|
+
notify(method, params = {}) {
|
|
111773
|
+
send2({ method, params });
|
|
111774
|
+
},
|
|
111775
|
+
/** Answer something the agent asked us. */
|
|
111776
|
+
reply(id2, result) {
|
|
111777
|
+
send2({ id: id2, result });
|
|
111778
|
+
},
|
|
111779
|
+
/** Say we can't. Sent for anything we never offered to do, so the agent gets an answer
|
|
111780
|
+
* rather than waiting on one forever. */
|
|
111781
|
+
refuse(id2, message) {
|
|
111782
|
+
send2({ id: id2, error: { code: -32601, message } });
|
|
111783
|
+
}
|
|
111784
|
+
};
|
|
111785
|
+
}
|
|
111826
111786
|
|
|
111827
111787
|
// ../cli/src/lib/agent/wire/tail.ts
|
|
111828
111788
|
function createTail(log) {
|
|
@@ -111874,8 +111834,8 @@ function createTail(log) {
|
|
|
111874
111834
|
// ../cli/package.json
|
|
111875
111835
|
var package_default = {
|
|
111876
111836
|
name: "wildcrane",
|
|
111877
|
-
version: "0.11.
|
|
111878
|
-
akbContract:
|
|
111837
|
+
version: "0.11.79",
|
|
111838
|
+
akbContract: 26,
|
|
111879
111839
|
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.",
|
|
111880
111840
|
keywords: [
|
|
111881
111841
|
"kanban",
|
|
@@ -111951,33 +111911,33 @@ var CLIENT_CAPABILITIES = {
|
|
|
111951
111911
|
};
|
|
111952
111912
|
function whereHint(update3, title) {
|
|
111953
111913
|
const locations = Array.isArray(update3.locations) ? update3.locations : [];
|
|
111954
|
-
const path38 =
|
|
111914
|
+
const path38 = str2(obj2(locations[0]).path);
|
|
111955
111915
|
return path38 && !title.includes(path38) ? hint(path38) : "";
|
|
111956
111916
|
}
|
|
111957
111917
|
function saidBy(update3) {
|
|
111958
111918
|
const content = Array.isArray(update3.content) ? update3.content : [];
|
|
111959
111919
|
for (const raw of content) {
|
|
111960
|
-
const part =
|
|
111961
|
-
const text3 =
|
|
111920
|
+
const part = obj2(raw);
|
|
111921
|
+
const text3 = str2(obj2(part.content).text) || str2(part.text);
|
|
111962
111922
|
if (text3.trim()) return text3.trim();
|
|
111963
111923
|
}
|
|
111964
111924
|
return "";
|
|
111965
111925
|
}
|
|
111966
111926
|
function modelOf(answer) {
|
|
111967
|
-
const current2 =
|
|
111927
|
+
const current2 = str2(obj2(answer.models).currentModelId).trim();
|
|
111968
111928
|
if (current2) return modelsIn2(answer).find((m) => m.modelId === current2)?.name ?? current2;
|
|
111969
111929
|
const list3 = Array.isArray(answer.configOptions) ? answer.configOptions : [];
|
|
111970
111930
|
for (const raw of list3) {
|
|
111971
|
-
const option =
|
|
111972
|
-
if (option.id === "model") return
|
|
111931
|
+
const option = obj2(raw);
|
|
111932
|
+
if (option.id === "model") return str2(option.currentValue).trim() || void 0;
|
|
111973
111933
|
}
|
|
111974
111934
|
return void 0;
|
|
111975
111935
|
}
|
|
111976
111936
|
function modelsIn2(answer) {
|
|
111977
|
-
const list3 =
|
|
111978
|
-
return (Array.isArray(list3) ? list3 : []).map(
|
|
111979
|
-
const modelId =
|
|
111980
|
-
return modelId ? [{ modelId, name:
|
|
111937
|
+
const list3 = obj2(answer.models).availableModels;
|
|
111938
|
+
return (Array.isArray(list3) ? list3 : []).map(obj2).flatMap((m) => {
|
|
111939
|
+
const modelId = str2(m.modelId);
|
|
111940
|
+
return modelId ? [{ modelId, name: str2(m.name) || modelId }] : [];
|
|
111981
111941
|
});
|
|
111982
111942
|
}
|
|
111983
111943
|
function pickedModel(answer, wanted) {
|
|
@@ -111985,16 +111945,16 @@ function pickedModel(answer, wanted) {
|
|
|
111985
111945
|
return list3.find((m) => m.modelId === wanted) ?? list3.find((m) => m.name === wanted || m.modelId.split("[")[0] === wanted);
|
|
111986
111946
|
}
|
|
111987
111947
|
function usageOf3(value, grossInput = false) {
|
|
111988
|
-
const usage =
|
|
111948
|
+
const usage = obj2(value);
|
|
111989
111949
|
if (!Object.keys(usage).length) return void 0;
|
|
111990
|
-
const cacheCreation =
|
|
111991
|
-
const cacheRead =
|
|
111992
|
-
const input2 =
|
|
111950
|
+
const cacheCreation = num2(usage.cachedWriteTokens) + num2(usage.cacheCreationTokens);
|
|
111951
|
+
const cacheRead = num2(usage.cachedReadTokens);
|
|
111952
|
+
const input2 = num2(usage.inputTokens);
|
|
111993
111953
|
const counts = {
|
|
111994
111954
|
input: grossInput ? Math.max(input2 - cacheRead - cacheCreation, 0) : input2,
|
|
111995
111955
|
cacheCreation,
|
|
111996
111956
|
cacheRead,
|
|
111997
|
-
output:
|
|
111957
|
+
output: num2(usage.outputTokens)
|
|
111998
111958
|
};
|
|
111999
111959
|
const sum = counts.input + counts.cacheCreation + counts.cacheRead + counts.output;
|
|
112000
111960
|
return sum > 0 ? counts : void 0;
|
|
@@ -112002,13 +111962,13 @@ function usageOf3(value, grossInput = false) {
|
|
|
112002
111962
|
var RESTARTED = "[board] that conversation is gone \u2014 the task was restarted in a new session\n";
|
|
112003
111963
|
async function newSession(rpc, cwd, mcpServers) {
|
|
112004
111964
|
const opened = await rpc.call("session/new", { cwd, mcpServers });
|
|
112005
|
-
const sessionId =
|
|
111965
|
+
const sessionId = str2(opened.sessionId);
|
|
112006
111966
|
if (!sessionId) throw new Error("the agent opened a session without giving it an id");
|
|
112007
111967
|
return { opened, sessionId };
|
|
112008
111968
|
}
|
|
112009
111969
|
var TICKS_PER_USD = 1e10;
|
|
112010
111970
|
function ticksUsd(value) {
|
|
112011
|
-
const ticks =
|
|
111971
|
+
const ticks = num2(value);
|
|
112012
111972
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? ticks / TICKS_PER_USD : void 0;
|
|
112013
111973
|
}
|
|
112014
111974
|
var STOPPED = {
|
|
@@ -112018,14 +111978,14 @@ var STOPPED = {
|
|
|
112018
111978
|
cancelled: "the turn was cancelled"
|
|
112019
111979
|
};
|
|
112020
111980
|
function mcpServersIn(file3) {
|
|
112021
|
-
const servers =
|
|
111981
|
+
const servers = obj2(obj2(JSON.parse(fs23.readFileSync(file3, "utf8"))).mcpServers);
|
|
112022
111982
|
return Object.entries(servers).map(([name, raw]) => {
|
|
112023
|
-
const s =
|
|
111983
|
+
const s = obj2(raw);
|
|
112024
111984
|
return {
|
|
112025
111985
|
name,
|
|
112026
|
-
command:
|
|
111986
|
+
command: str2(s.command),
|
|
112027
111987
|
args: Array.isArray(s.args) ? s.args.map(String) : [],
|
|
112028
|
-
env: Object.entries(
|
|
111988
|
+
env: Object.entries(obj2(s.env)).map(([key, value]) => ({ name: key, value: String(value) }))
|
|
112029
111989
|
};
|
|
112030
111990
|
});
|
|
112031
111991
|
}
|
|
@@ -112059,7 +112019,7 @@ async function oneTurn(io, options) {
|
|
|
112059
112019
|
io.stdin,
|
|
112060
112020
|
(msg) => {
|
|
112061
112021
|
if (msg.method === "session/update") {
|
|
112062
|
-
const params =
|
|
112022
|
+
const params = obj2(msg.params);
|
|
112063
112023
|
if (!live && (!params.sessionId || params.sessionId === io.resumeId)) {
|
|
112064
112024
|
update2(params.update, createTail(() => {
|
|
112065
112025
|
}), (usd) => {
|
|
@@ -112067,9 +112027,9 @@ async function oneTurn(io, options) {
|
|
|
112067
112027
|
}, () => {
|
|
112068
112028
|
});
|
|
112069
112029
|
}
|
|
112070
|
-
if (live && (!
|
|
112071
|
-
const kind =
|
|
112072
|
-
if (["agent_message_chunk", "agent_thought_chunk"].includes(kind) &&
|
|
112030
|
+
if (live && (!obj2(msg.params).sessionId || obj2(msg.params).sessionId === currentSession)) {
|
|
112031
|
+
const kind = str2(obj2(obj2(msg.params).update).sessionUpdate);
|
|
112032
|
+
if (["agent_message_chunk", "agent_thought_chunk"].includes(kind) && str2(obj2(obj2(obj2(msg.params).update).content).text)) {
|
|
112073
112033
|
io.activity?.();
|
|
112074
112034
|
if (kind === "agent_thought_chunk") {
|
|
112075
112035
|
if (!thinking || Date.now() - thinkingAt >= 1e3) {
|
|
@@ -112091,20 +112051,20 @@ async function oneTurn(io, options) {
|
|
|
112091
112051
|
contentAt = Date.now();
|
|
112092
112052
|
io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
|
|
112093
112053
|
}
|
|
112094
|
-
update2(
|
|
112095
|
-
events.update(
|
|
112054
|
+
update2(obj2(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
|
|
112055
|
+
events.update(obj2(msg.params).update);
|
|
112096
112056
|
emit();
|
|
112097
112057
|
}
|
|
112098
112058
|
return;
|
|
112099
112059
|
}
|
|
112100
112060
|
if (msg.id === void 0) return;
|
|
112101
112061
|
if (msg.method === "session/request_permission") {
|
|
112102
|
-
rpc.reply(msg.id, decide(
|
|
112062
|
+
rpc.reply(msg.id, decide(obj2(msg.params), tail, events));
|
|
112103
112063
|
emit();
|
|
112104
112064
|
return;
|
|
112105
112065
|
}
|
|
112106
112066
|
if (msg.method === "cursor/update_todos") {
|
|
112107
|
-
const params =
|
|
112067
|
+
const params = obj2(msg.params);
|
|
112108
112068
|
if (live) {
|
|
112109
112069
|
events.todos(params.todos, params.merge === true);
|
|
112110
112070
|
emit();
|
|
@@ -112154,7 +112114,7 @@ async function oneTurn(io, options) {
|
|
|
112154
112114
|
}
|
|
112155
112115
|
let model = modelOf(opened);
|
|
112156
112116
|
if (options.model) {
|
|
112157
|
-
const listed =
|
|
112117
|
+
const listed = obj2(opened.models).currentModelId !== void 0;
|
|
112158
112118
|
const picked = listed ? pickedModel(opened, options.model) : void 0;
|
|
112159
112119
|
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.");
|
|
112160
112120
|
model = picked?.name ?? modelOf(set2) ?? options.model;
|
|
@@ -112171,8 +112131,8 @@ async function oneTurn(io, options) {
|
|
|
112171
112131
|
});
|
|
112172
112132
|
const result = tail.end();
|
|
112173
112133
|
events.end();
|
|
112174
|
-
const stopReason =
|
|
112175
|
-
const spent =
|
|
112134
|
+
const stopReason = str2(done.stopReason);
|
|
112135
|
+
const spent = obj2(obj2(done._meta).usage);
|
|
112176
112136
|
const usage = usageOf3(done.usage) ?? usageOf3(spent, true);
|
|
112177
112137
|
saveAcpCost(acpCostFile(options.tool ?? "acp", io.cwd, sessionId), costUsd);
|
|
112178
112138
|
costUsd = costUsd === void 0 ? ticksUsd(spent.costUsdTicks) : costBefore === void 0 ? void 0 : costUsd < costBefore ? costUsd : costUsd - costBefore;
|
|
@@ -112201,32 +112161,32 @@ async function oneTurn(io, options) {
|
|
|
112201
112161
|
}
|
|
112202
112162
|
}
|
|
112203
112163
|
function update2(raw, tail, gotCost, gotContext) {
|
|
112204
|
-
const change =
|
|
112164
|
+
const change = obj2(raw);
|
|
112205
112165
|
switch (change.sessionUpdate) {
|
|
112206
112166
|
case "agent_message_chunk":
|
|
112207
|
-
tail.text(
|
|
112167
|
+
tail.text(str2(obj2(change.content).text));
|
|
112208
112168
|
return;
|
|
112209
112169
|
case "agent_thought_chunk":
|
|
112210
|
-
tail.thought(
|
|
112170
|
+
tail.thought(str2(obj2(change.content).text));
|
|
112211
112171
|
return;
|
|
112212
112172
|
case "tool_call": {
|
|
112213
|
-
const title =
|
|
112173
|
+
const title = str2(change.title) || str2(change.name) || "tool";
|
|
112214
112174
|
tail.line(`\u23FA ${title}${whereHint(change, title)}`);
|
|
112215
112175
|
return;
|
|
112216
112176
|
}
|
|
112217
112177
|
case "tool_call_update": {
|
|
112218
112178
|
if (change.status !== "failed") return;
|
|
112219
112179
|
const why = saidBy(change);
|
|
112220
|
-
tail.line(`[error] ${
|
|
112180
|
+
tail.line(`[error] ${str2(change.title) || "that tool call"} failed${why ? `: ${why}` : ""}`);
|
|
112221
112181
|
return;
|
|
112222
112182
|
}
|
|
112223
112183
|
case "usage_update": {
|
|
112224
|
-
const used =
|
|
112225
|
-
const size =
|
|
112184
|
+
const used = num2(change.used);
|
|
112185
|
+
const size = num2(change.size);
|
|
112226
112186
|
if (used > 0) gotContext({ used, ...size > 0 ? { limit: size } : {} });
|
|
112227
|
-
const cost =
|
|
112187
|
+
const cost = obj2(change.cost);
|
|
112228
112188
|
const amount = cost.amount;
|
|
112229
|
-
if (
|
|
112189
|
+
if (str2(cost.currency).toUpperCase() === "USD" && typeof amount === "number" && Number.isFinite(amount) && amount >= 0) {
|
|
112230
112190
|
gotCost(amount);
|
|
112231
112191
|
}
|
|
112232
112192
|
return;
|
|
@@ -112237,8 +112197,8 @@ function update2(raw, tail, gotCost, gotContext) {
|
|
|
112237
112197
|
}
|
|
112238
112198
|
function decide(params, tail, events) {
|
|
112239
112199
|
const options = Array.isArray(params.options) ? params.options : [];
|
|
112240
|
-
const no = options.map(
|
|
112241
|
-
const title =
|
|
112200
|
+
const no = options.map(obj2).find((option) => str2(option.kind).startsWith("reject"));
|
|
112201
|
+
const title = str2(obj2(params.toolCall).title) || "that";
|
|
112242
112202
|
const said = `[refused] ${title} \u2014 a run reaches no further than this project`;
|
|
112243
112203
|
tail.line(said);
|
|
112244
112204
|
events.log(`${said}
|
|
@@ -112248,21 +112208,21 @@ function decide(params, tail, events) {
|
|
|
112248
112208
|
}
|
|
112249
112209
|
|
|
112250
112210
|
// ../cli/src/lib/agent/wire/zcode.ts
|
|
112251
|
-
import
|
|
112211
|
+
import path26 from "node:path";
|
|
112252
112212
|
function whereHint2(input2, title) {
|
|
112253
|
-
const named =
|
|
112213
|
+
const named = obj2(input2);
|
|
112254
112214
|
for (const key of ["command", "file_path", "path", "url", "pattern"]) {
|
|
112255
|
-
const value =
|
|
112215
|
+
const value = str2(named[key]).trim();
|
|
112256
112216
|
if (value && !title.includes(value)) return hint(value);
|
|
112257
112217
|
}
|
|
112258
112218
|
return "";
|
|
112259
112219
|
}
|
|
112260
112220
|
function usageOf4(value) {
|
|
112261
112221
|
const counts = {
|
|
112262
|
-
input:
|
|
112263
|
-
cacheCreation:
|
|
112264
|
-
cacheRead:
|
|
112265
|
-
output:
|
|
112222
|
+
input: num2(value.inputTokens),
|
|
112223
|
+
cacheCreation: num2(value.cacheCreationTokens) || num2(value.cacheWriteTokens),
|
|
112224
|
+
cacheRead: num2(value.cacheReadTokens),
|
|
112225
|
+
output: num2(value.outputTokens)
|
|
112266
112226
|
};
|
|
112267
112227
|
const sum = counts.input + counts.cacheCreation + counts.cacheRead + counts.output;
|
|
112268
112228
|
return sum > 0 ? counts : void 0;
|
|
@@ -112275,10 +112235,10 @@ var STOPPED2 = {
|
|
|
112275
112235
|
error_during_execution: "the agent stopped part-way through"
|
|
112276
112236
|
};
|
|
112277
112237
|
function modelOf2(ref) {
|
|
112278
|
-
const model =
|
|
112279
|
-
const id2 =
|
|
112238
|
+
const model = obj2(ref);
|
|
112239
|
+
const id2 = str2(model.modelId);
|
|
112280
112240
|
if (!id2) return "";
|
|
112281
|
-
const provider =
|
|
112241
|
+
const provider = str2(model.providerId);
|
|
112282
112242
|
return provider ? `${provider}/${id2}` : id2;
|
|
112283
112243
|
}
|
|
112284
112244
|
function createParts(tail) {
|
|
@@ -112296,33 +112256,33 @@ function createParts(tail) {
|
|
|
112296
112256
|
return {
|
|
112297
112257
|
/** A whole part, as `part.started` or `part.upserted` sends it. */
|
|
112298
112258
|
upsert(raw) {
|
|
112299
|
-
const part =
|
|
112300
|
-
const type =
|
|
112301
|
-
const partId =
|
|
112259
|
+
const part = obj2(raw);
|
|
112260
|
+
const type = str2(part.type);
|
|
112261
|
+
const partId = str2(part.partId);
|
|
112302
112262
|
if (type === "text" || type === "reasoning" || type === "thought") {
|
|
112303
|
-
if (partId) say(partId, type,
|
|
112304
|
-
else tail.text(
|
|
112263
|
+
if (partId) say(partId, type, str2(part.text));
|
|
112264
|
+
else tail.text(str2(part.text));
|
|
112305
112265
|
return;
|
|
112306
112266
|
}
|
|
112307
112267
|
if (type !== "tool") return;
|
|
112308
|
-
const state2 =
|
|
112309
|
-
const callId =
|
|
112310
|
-
const title =
|
|
112268
|
+
const state2 = obj2(part.state);
|
|
112269
|
+
const callId = str2(part.callId) || partId;
|
|
112270
|
+
const title = str2(state2.title) || str2(part.tool) || "tool";
|
|
112311
112271
|
if (callId && !tools.has(callId)) {
|
|
112312
112272
|
tools.add(callId);
|
|
112313
112273
|
tail.line(`\u23FA ${title}${whereHint2(state2.input, title)}`);
|
|
112314
112274
|
}
|
|
112315
|
-
if (
|
|
112316
|
-
const why =
|
|
112275
|
+
if (str2(state2.status) === "error") {
|
|
112276
|
+
const why = str2(state2.error).trim();
|
|
112317
112277
|
tail.line(`[error] ${title} failed${why ? `: ${why}` : ""}`);
|
|
112318
112278
|
}
|
|
112319
112279
|
},
|
|
112320
112280
|
/** A piece of one part, as `part.delta` sends it. */
|
|
112321
112281
|
delta(event2) {
|
|
112322
|
-
const field =
|
|
112282
|
+
const field = str2(event2.field) || "text";
|
|
112323
112283
|
if (field !== "text" && field !== "reasoning") return;
|
|
112324
|
-
const partId =
|
|
112325
|
-
const delta =
|
|
112284
|
+
const partId = str2(event2.partId);
|
|
112285
|
+
const delta = str2(event2.delta);
|
|
112326
112286
|
if (!delta) return;
|
|
112327
112287
|
written.set(partId, (written.get(partId) ?? "") + delta);
|
|
112328
112288
|
if (field === "reasoning") tail.thought(delta);
|
|
@@ -112330,12 +112290,12 @@ function createParts(tail) {
|
|
|
112330
112290
|
},
|
|
112331
112291
|
/** A piece of the turn, as `model.streaming` sends it. */
|
|
112332
112292
|
streaming(payload) {
|
|
112333
|
-
const kind =
|
|
112334
|
-
if (kind === "text_delta") return tail.text(
|
|
112335
|
-
if (kind === "reasoning_delta") return tail.thought(
|
|
112293
|
+
const kind = str2(payload.kind);
|
|
112294
|
+
if (kind === "text_delta") return tail.text(str2(payload.delta));
|
|
112295
|
+
if (kind === "reasoning_delta") return tail.thought(str2(payload.delta));
|
|
112336
112296
|
if (kind !== "tool_call") return;
|
|
112337
|
-
const callId =
|
|
112338
|
-
const name =
|
|
112297
|
+
const callId = str2(payload.toolCallId);
|
|
112298
|
+
const name = str2(payload.toolName) || "tool";
|
|
112339
112299
|
named.set(callId, name);
|
|
112340
112300
|
if (callId && tools.has(callId)) return;
|
|
112341
112301
|
tools.add(callId);
|
|
@@ -112345,9 +112305,9 @@ function createParts(tail) {
|
|
|
112345
112305
|
* `batch` are progress on a call that already has its line; only `error` is worth a
|
|
112346
112306
|
* second one. */
|
|
112347
112307
|
toolUpdate(payload) {
|
|
112348
|
-
if (
|
|
112349
|
-
const name = named.get(
|
|
112350
|
-
const why =
|
|
112308
|
+
if (str2(payload.kind) !== "error") return;
|
|
112309
|
+
const name = named.get(str2(payload.toolCallId)) ?? "tool";
|
|
112310
|
+
const why = str2(obj2(payload.error).message).split("\n")[0].trim();
|
|
112351
112311
|
tail.line(`[error] ${name} failed${why ? `: ${why.slice(0, 200)}` : ""}`);
|
|
112352
112312
|
}
|
|
112353
112313
|
};
|
|
@@ -112392,22 +112352,22 @@ async function oneTurn2(io, options) {
|
|
|
112392
112352
|
io.stdin,
|
|
112393
112353
|
(msg) => {
|
|
112394
112354
|
if (msg.method === "session/event") {
|
|
112395
|
-
const envelope =
|
|
112396
|
-
if (
|
|
112355
|
+
const envelope = obj2(msg.params);
|
|
112356
|
+
if (str2(envelope.sessionId) === sessionId) {
|
|
112397
112357
|
if (live) {
|
|
112398
|
-
const payload =
|
|
112399
|
-
const part =
|
|
112400
|
-
const state2 =
|
|
112401
|
-
const type =
|
|
112402
|
-
if (["part.delta", "model.streaming"].includes(type) &&
|
|
112403
|
-
const id2 =
|
|
112404
|
-
const name =
|
|
112358
|
+
const payload = obj2(envelope.payload);
|
|
112359
|
+
const part = obj2(payload.part);
|
|
112360
|
+
const state2 = obj2(part.state);
|
|
112361
|
+
const type = str2(envelope.type);
|
|
112362
|
+
if (["part.delta", "model.streaming"].includes(type) && str2(payload.delta)) io.activity?.();
|
|
112363
|
+
const id2 = str2(payload.toolCallId) || str2(part.callId) || str2(part.partId);
|
|
112364
|
+
const name = str2(payload.toolName) || str2(part.tool) || str2(state2.title);
|
|
112405
112365
|
if (id2 && name && !activeCalls.has(id2)) {
|
|
112406
112366
|
activeCalls.add(id2);
|
|
112407
112367
|
if (/^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(name)) activityEvents.subagent(id2, name);
|
|
112408
112368
|
else activityEvents.toolCall(id2, name, /^(?:bash|shell|execute|run_command|terminal)$/i.test(name) ? "execute" : "other");
|
|
112409
112369
|
}
|
|
112410
|
-
const status2 =
|
|
112370
|
+
const status2 = str2(state2.status) || str2(payload.kind);
|
|
112411
112371
|
if (id2 && ["completed", "error", "result"].includes(status2)) activityEvents.toolResult(id2, status2 === "error" ? "failed" : "completed", "");
|
|
112412
112372
|
for (const e of activityEvents.events()) io.event?.(e);
|
|
112413
112373
|
}
|
|
@@ -112421,7 +112381,7 @@ async function oneTurn2(io, options) {
|
|
|
112421
112381
|
return;
|
|
112422
112382
|
}
|
|
112423
112383
|
if (msg.method === "interaction/requestPermission") {
|
|
112424
|
-
rpc.reply(msg.id, decide2(
|
|
112384
|
+
rpc.reply(msg.id, decide2(obj2(msg.params), tail));
|
|
112425
112385
|
return;
|
|
112426
112386
|
}
|
|
112427
112387
|
if (msg.method === "interaction/requestUserInput") {
|
|
@@ -112441,7 +112401,7 @@ async function oneTurn2(io, options) {
|
|
|
112441
112401
|
{ stringIds: true }
|
|
112442
112402
|
);
|
|
112443
112403
|
try {
|
|
112444
|
-
const workspacePath =
|
|
112404
|
+
const workspacePath = path26.resolve(io.cwd);
|
|
112445
112405
|
const workspace = { workspacePath, workspaceKey: workspacePath };
|
|
112446
112406
|
let opened;
|
|
112447
112407
|
if (io.resumeId) {
|
|
@@ -112459,13 +112419,13 @@ async function oneTurn2(io, options) {
|
|
|
112459
112419
|
// The session's name is the board's business, not a model call of its own.
|
|
112460
112420
|
titleGenerationEnabled: false
|
|
112461
112421
|
});
|
|
112462
|
-
sessionId =
|
|
112422
|
+
sessionId = str2(obj2(opened.session).sessionId);
|
|
112463
112423
|
if (!sessionId) throw new Error("the agent opened a session without giving it an id");
|
|
112464
112424
|
io.gotResumeId(sessionId);
|
|
112465
112425
|
}
|
|
112466
|
-
let model = modelOf2(
|
|
112426
|
+
let model = modelOf2(obj2(opened.session).model);
|
|
112467
112427
|
if (options.model) {
|
|
112468
|
-
const wanted = options.model.includes("/") ? { providerId: options.model.split("/")[0], modelId: options.model.split("/").slice(1).join("/") } : { providerId:
|
|
112428
|
+
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 };
|
|
112469
112429
|
await rpc.call("session/setModel", { sessionId, model: wanted });
|
|
112470
112430
|
model = modelOf2(wanted);
|
|
112471
112431
|
}
|
|
@@ -112508,17 +112468,17 @@ async function tokensOf(rpc, sessionId) {
|
|
|
112508
112468
|
async function contextOf(rpc, sessionId) {
|
|
112509
112469
|
try {
|
|
112510
112470
|
const read3 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
|
|
112511
|
-
const state2 =
|
|
112512
|
-
const used =
|
|
112513
|
-
const limit =
|
|
112471
|
+
const state2 = obj2(read3.projection);
|
|
112472
|
+
const used = num2(state2.contextUsed);
|
|
112473
|
+
const limit = num2(state2.contextWindow);
|
|
112514
112474
|
return used > 0 ? { used, limit: limit > 0 ? limit : void 0 } : void 0;
|
|
112515
112475
|
} catch {
|
|
112516
112476
|
return void 0;
|
|
112517
112477
|
}
|
|
112518
112478
|
}
|
|
112519
112479
|
function event(envelope, parts, tail, live, ended) {
|
|
112520
|
-
const payload =
|
|
112521
|
-
switch (
|
|
112480
|
+
const payload = obj2(envelope.payload);
|
|
112481
|
+
switch (str2(envelope.type)) {
|
|
112522
112482
|
case "part.started":
|
|
112523
112483
|
case "part.upserted":
|
|
112524
112484
|
if (live) parts.upsert(payload.part);
|
|
@@ -112533,25 +112493,25 @@ function event(envelope, parts, tail, live, ended) {
|
|
|
112533
112493
|
if (live) parts.toolUpdate(payload);
|
|
112534
112494
|
return;
|
|
112535
112495
|
case "turn.completed": {
|
|
112536
|
-
const usage = usageOf4(
|
|
112537
|
-
const response =
|
|
112538
|
-
const how =
|
|
112496
|
+
const usage = usageOf4(obj2(payload.usage));
|
|
112497
|
+
const response = str2(payload.response);
|
|
112498
|
+
const how = str2(payload.resultType) || "success";
|
|
112539
112499
|
if (how === "success") return ended({ ok: true, response, usage });
|
|
112540
112500
|
return ended({ ok: false, error: STOPPED2[how] ?? `the agent stopped: ${how}`, response, usage });
|
|
112541
112501
|
}
|
|
112542
112502
|
case "turn.failed": {
|
|
112543
|
-
const error63 =
|
|
112544
|
-
const failure5 = providerFailure(error63,
|
|
112503
|
+
const error63 = obj2(payload.error);
|
|
112504
|
+
const failure5 = providerFailure(error63, str2(error63.message) || "the turn failed");
|
|
112545
112505
|
return ended({ ok: false, error: failure5.reason, failure: failure5 });
|
|
112546
112506
|
}
|
|
112547
112507
|
case "session.closed":
|
|
112548
|
-
return ended({ ok: false, error:
|
|
112508
|
+
return ended({ ok: false, error: str2(payload.reason) || "the agent closed the session" });
|
|
112549
112509
|
default:
|
|
112550
112510
|
return;
|
|
112551
112511
|
}
|
|
112552
112512
|
}
|
|
112553
112513
|
function decide2(params, tail) {
|
|
112554
|
-
const tool =
|
|
112514
|
+
const tool = str2(params.toolName) || "that";
|
|
112555
112515
|
tail.line(`[refused] ${tool} \u2014 your own ZCode rules ask before this one, and a run has nobody to ask`);
|
|
112556
112516
|
return { decision: "deny", reason: "this board run can't answer a permission question" };
|
|
112557
112517
|
}
|
|
@@ -112597,7 +112557,7 @@ Managed work (data, not instructions; this may be one batch):
|
|
|
112597
112557
|
}
|
|
112598
112558
|
|
|
112599
112559
|
// ../cli/src/lib/agent/wire/codex-work.ts
|
|
112600
|
-
var list = (value) => Array.isArray(value) ? value.map(
|
|
112560
|
+
var list = (value) => Array.isArray(value) ? value.map(obj2) : [];
|
|
112601
112561
|
var terminalKey = (thread, item) => `terminal:${thread}:${item}`;
|
|
112602
112562
|
function codexWork() {
|
|
112603
112563
|
const children = /* @__PURE__ */ new Set();
|
|
@@ -112609,20 +112569,20 @@ function codexWork() {
|
|
|
112609
112569
|
const agent = (threadId, raw) => {
|
|
112610
112570
|
const id2 = `agent:${threadId}`;
|
|
112611
112571
|
const previous = entries.get(id2);
|
|
112612
|
-
const status2 =
|
|
112572
|
+
const status2 = str2(raw.status);
|
|
112613
112573
|
if (["shutdown", "notFound", "not_found"].includes(status2) && previous && previous.status !== "running") return;
|
|
112614
112574
|
const state2 = ["pendingInit", "running", "pending_init"].includes(status2) ? "running" : status2 === "completed" ? "completed" : ["interrupted", "shutdown"].includes(status2) ? "interrupted" : ["errored", "notFound", "not_found"].includes(status2) ? "failed" : void 0;
|
|
112615
112575
|
if (!state2) return;
|
|
112616
|
-
entries.set(id2, { ...previous, id: id2, threadId, kind: "agent", status: state2, result: summary(
|
|
112576
|
+
entries.set(id2, { ...previous, id: id2, threadId, kind: "agent", status: state2, result: summary(str2(raw.message)) });
|
|
112617
112577
|
};
|
|
112618
112578
|
const observe = (threadId, raw) => {
|
|
112619
112579
|
if (!own4(threadId)) return;
|
|
112620
112580
|
if (raw.type === "subAgentActivity") {
|
|
112621
|
-
const child =
|
|
112581
|
+
const child = str2(raw.agentThreadId);
|
|
112622
112582
|
if (raw.kind === "started" && child && child !== root2 && !children.has(child)) {
|
|
112623
112583
|
children.add(child);
|
|
112624
112584
|
agent(child, { status: "running" });
|
|
112625
|
-
entries.get(`agent:${child}`).agentPath =
|
|
112585
|
+
entries.get(`agent:${child}`).agentPath = str2(raw.agentPath);
|
|
112626
112586
|
}
|
|
112627
112587
|
return;
|
|
112628
112588
|
}
|
|
@@ -112636,10 +112596,10 @@ function codexWork() {
|
|
|
112636
112596
|
if (!entries.has(`agent:${id3}`)) agent(id3, { status: "running" });
|
|
112637
112597
|
}
|
|
112638
112598
|
}
|
|
112639
|
-
for (const [id3, state2] of Object.entries(
|
|
112599
|
+
for (const [id3, state2] of Object.entries(obj2(raw.agentsStates))) if (children.has(id3)) agent(id3, obj2(state2));
|
|
112640
112600
|
}
|
|
112641
|
-
if (raw.type !== "commandExecution" || !
|
|
112642
|
-
const id2 = terminalKey(threadId,
|
|
112601
|
+
if (raw.type !== "commandExecution" || !str2(raw.id)) return;
|
|
112602
|
+
const id2 = terminalKey(threadId, str2(raw.id));
|
|
112643
112603
|
const previous = entries.get(id2);
|
|
112644
112604
|
const running = raw.status === "inProgress";
|
|
112645
112605
|
if (running && previous?.exitCode !== void 0) return;
|
|
@@ -112649,36 +112609,36 @@ function codexWork() {
|
|
|
112649
112609
|
id: id2,
|
|
112650
112610
|
threadId,
|
|
112651
112611
|
kind: "terminal",
|
|
112652
|
-
itemId:
|
|
112653
|
-
processId:
|
|
112654
|
-
command: summary(
|
|
112612
|
+
itemId: str2(raw.id),
|
|
112613
|
+
processId: str2(raw.processId) || previous?.processId,
|
|
112614
|
+
command: summary(str2(raw.command) || previous?.command || "", 600),
|
|
112655
112615
|
status: running ? "running" : exitCode !== void 0 ? exitCode === 0 ? "completed" : "failed" : "unknown",
|
|
112656
|
-
result: summary(
|
|
112616
|
+
result: summary(str2(raw.aggregatedOutput) || previous?.result || ""),
|
|
112657
112617
|
exitCode
|
|
112658
112618
|
});
|
|
112659
112619
|
};
|
|
112660
112620
|
const observeTurn = (threadId, turn2) => {
|
|
112661
112621
|
if (!children.has(threadId)) return;
|
|
112662
|
-
const status2 =
|
|
112622
|
+
const status2 = str2(turn2.status);
|
|
112663
112623
|
if (!["completed", "failed", "interrupted"].includes(status2)) return;
|
|
112664
|
-
const message = list(turn2.items).filter((i) => i.type === "agentMessage" && i.phase !== "commentary").map((i) =>
|
|
112665
|
-
agent(threadId, { status: status2 === "failed" ? "errored" : status2, message:
|
|
112624
|
+
const message = list(turn2.items).filter((i) => i.type === "agentMessage" && i.phase !== "commentary").map((i) => str2(i.text)).join("\n\n");
|
|
112625
|
+
agent(threadId, { status: status2 === "failed" ? "errored" : status2, message: str2(obj2(turn2.error).message) || message });
|
|
112666
112626
|
};
|
|
112667
112627
|
const readThread = async (rpc, threadId) => {
|
|
112668
|
-
let thread =
|
|
112628
|
+
let thread = obj2((await rpc.call("thread/read", { threadId, includeTurns: false })).thread);
|
|
112669
112629
|
let turns = list(thread.turns);
|
|
112670
112630
|
if (thread.historyMode === "paginated") {
|
|
112671
112631
|
turns = list((await rpc.call("thread/turns/list", { threadId, sortDirection: "desc", limit: 1, itemsView: "full" })).data);
|
|
112672
112632
|
} else if (!turns.length) {
|
|
112673
|
-
thread =
|
|
112633
|
+
thread = obj2((await rpc.call("thread/read", { threadId, includeTurns: true })).thread);
|
|
112674
112634
|
turns = list(thread.turns).slice(-1);
|
|
112675
112635
|
} else turns = turns.slice(-1);
|
|
112676
112636
|
const turn2 = turns[0];
|
|
112677
112637
|
for (const item of list(turn2?.items)) observe(threadId, item);
|
|
112678
112638
|
if (threadId !== root2) {
|
|
112679
|
-
const status2 =
|
|
112680
|
-
if (
|
|
112681
|
-
else if (
|
|
112639
|
+
const status2 = str2(turn2?.status);
|
|
112640
|
+
if (obj2(thread.status).type === "systemError") agent(threadId, { status: "errored", message: "Codex subagent reported a system error." });
|
|
112641
|
+
else if (obj2(thread.status).type !== "active" && ["completed", "failed", "interrupted"].includes(status2)) {
|
|
112682
112642
|
observeTurn(threadId, turn2 ?? {});
|
|
112683
112643
|
}
|
|
112684
112644
|
}
|
|
@@ -112716,7 +112676,7 @@ function codexWork() {
|
|
|
112716
112676
|
cursors.add(cursor);
|
|
112717
112677
|
const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
112718
112678
|
for (const terminal of list(page.data)) {
|
|
112719
|
-
const itemId =
|
|
112679
|
+
const itemId = str2(terminal.itemId), processId = str2(terminal.processId);
|
|
112720
112680
|
if (!itemId || !processId) throw Error("Codex returned a background terminal without its complete handles.");
|
|
112721
112681
|
const id2 = terminalKey(threadId, itemId);
|
|
112722
112682
|
present.add(id2);
|
|
@@ -112729,7 +112689,7 @@ function codexWork() {
|
|
|
112729
112689
|
itemId,
|
|
112730
112690
|
processId,
|
|
112731
112691
|
...typeof terminal.osPid === "number" ? { osPid: terminal.osPid } : {},
|
|
112732
|
-
command: summary(
|
|
112692
|
+
command: summary(str2(terminal.command) || previous?.command || "", 600),
|
|
112733
112693
|
status: "running",
|
|
112734
112694
|
result: previous?.result ?? ""
|
|
112735
112695
|
});
|
|
@@ -112753,7 +112713,7 @@ function codexWork() {
|
|
|
112753
112713
|
}
|
|
112754
112714
|
|
|
112755
112715
|
// ../cli/src/lib/agent/wire/codex.ts
|
|
112756
|
-
var list2 = (value) => Array.isArray(value) ? value.map(
|
|
112716
|
+
var list2 = (value) => Array.isArray(value) ? value.map(obj2) : [];
|
|
112757
112717
|
function createCodexConnection(argv) {
|
|
112758
112718
|
const execAt = argv.indexOf("exec");
|
|
112759
112719
|
if (execAt < 1) return void 0;
|
|
@@ -112962,8 +112922,8 @@ async function run(io, options, count2) {
|
|
|
112962
112922
|
};
|
|
112963
112923
|
const item = (raw, completed, proof = true) => {
|
|
112964
112924
|
if (ended) return;
|
|
112965
|
-
const id2 =
|
|
112966
|
-
if (["collabAgentToolCall", "subAgentActivity"].includes(
|
|
112925
|
+
const id2 = str2(raw.id);
|
|
112926
|
+
if (["collabAgentToolCall", "subAgentActivity"].includes(str2(raw.type))) {
|
|
112967
112927
|
if (proof) began();
|
|
112968
112928
|
childUpdates();
|
|
112969
112929
|
return;
|
|
@@ -112971,7 +112931,7 @@ async function run(io, options, count2) {
|
|
|
112971
112931
|
const key = `${id2}:${completed}`;
|
|
112972
112932
|
if (seenItems.has(key)) return;
|
|
112973
112933
|
seenItems.add(key);
|
|
112974
|
-
if (raw.type === "agentMessage" && completed && raw.phase !== "commentary" &&
|
|
112934
|
+
if (raw.type === "agentMessage" && completed && raw.phase !== "commentary" && str2(raw.text).trim()) {
|
|
112975
112935
|
const eligible = /* @__PURE__ */ new Set([...settlement?.work.map((w) => w.id) ?? [], ...visible]);
|
|
112976
112936
|
replySnapshots = new Map([...work.entries.values()].filter((w) => eligible.has(w.id) && !["running", "unknown"].includes(w.status)).map((w) => [w.id, snapshot(w)]));
|
|
112977
112937
|
}
|
|
@@ -112981,14 +112941,14 @@ async function run(io, options, count2) {
|
|
|
112981
112941
|
return;
|
|
112982
112942
|
}
|
|
112983
112943
|
const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
|
|
112984
|
-
const type = types[
|
|
112944
|
+
const type = types[str2(raw.type)];
|
|
112985
112945
|
if (!type) return;
|
|
112986
112946
|
if (proof) began();
|
|
112987
112947
|
emit(completed ? "item.completed" : "item.started", { item: {
|
|
112988
112948
|
...raw,
|
|
112989
112949
|
type,
|
|
112990
112950
|
...raw.type === "imageGeneration" ? { path: raw.savedPath ?? raw.path } : {},
|
|
112991
|
-
...raw.type === "fileChange" ? { changes: list2(raw.changes).map((c) => ({ ...c, kind:
|
|
112951
|
+
...raw.type === "fileChange" ? { changes: list2(raw.changes).map((c) => ({ ...c, kind: str2(obj2(c.kind).type) || c.kind })) } : {},
|
|
112992
112952
|
aggregated_output: raw.aggregatedOutput,
|
|
112993
112953
|
exit_code: raw.exitCode,
|
|
112994
112954
|
status: raw.status === "inProgress" ? "in_progress" : raw.status
|
|
@@ -113130,12 +113090,12 @@ async function run(io, options, count2) {
|
|
|
113130
113090
|
end(`Codex requested interaction: ${msg.method}`);
|
|
113131
113091
|
return;
|
|
113132
113092
|
}
|
|
113133
|
-
const p =
|
|
113134
|
-
const source =
|
|
113093
|
+
const p = obj2(msg.params);
|
|
113094
|
+
const source = str2(p.threadId);
|
|
113135
113095
|
if (!work.own(source)) return;
|
|
113136
113096
|
if (msg.method === "item/commandExecution/terminalInteraction") {
|
|
113137
113097
|
for (const w of work.entries.values()) if (w.kind === "terminal" && w.threadId === source && w.processId === p.processId && w.status === "running") {
|
|
113138
|
-
if (
|
|
113098
|
+
if (str2(p.stdin).includes("")) w.intentionalStop = true;
|
|
113139
113099
|
else if (settlement && p.stdin === "") {
|
|
113140
113100
|
settlement.polled.add(w.id);
|
|
113141
113101
|
armCleanup();
|
|
@@ -113143,26 +113103,26 @@ async function run(io, options, count2) {
|
|
|
113143
113103
|
}
|
|
113144
113104
|
}
|
|
113145
113105
|
if (msg.method === "item/started" || msg.method === "item/completed") {
|
|
113146
|
-
const raw =
|
|
113106
|
+
const raw = obj2(p.item);
|
|
113147
113107
|
work.observe(source, raw);
|
|
113148
113108
|
if (source === threadId && active) {
|
|
113149
|
-
if (raw.type === "commandExecution") visible.add(`terminal:${source}:${
|
|
113150
|
-
if (raw.type === "collabAgentToolCall") for (const id2 of Object.keys(
|
|
113109
|
+
if (raw.type === "commandExecution") visible.add(`terminal:${source}:${str2(raw.id)}`);
|
|
113110
|
+
if (raw.type === "collabAgentToolCall") for (const id2 of Object.keys(obj2(raw.agentsStates))) visible.add(`agent:${id2}`);
|
|
113151
113111
|
}
|
|
113152
113112
|
armCleanup();
|
|
113153
|
-
if (source === threadId &&
|
|
113113
|
+
if (source === threadId && obj2(p.item).type !== "agentMessage") item(obj2(p.item), msg.method === "item/completed", false);
|
|
113154
113114
|
}
|
|
113155
113115
|
if (source !== threadId) {
|
|
113156
113116
|
if (msg.method === "turn/completed") {
|
|
113157
|
-
work.observeTurn(source,
|
|
113117
|
+
work.observeTurn(source, obj2(p.turn));
|
|
113158
113118
|
armCleanup();
|
|
113159
113119
|
}
|
|
113160
113120
|
childUpdates();
|
|
113161
113121
|
return;
|
|
113162
113122
|
}
|
|
113163
|
-
const turnId =
|
|
113123
|
+
const turnId = str2(p.turnId) || str2(obj2(p.turn).id);
|
|
113164
113124
|
if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
|
|
113165
|
-
if (submitted && ["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "") &&
|
|
113125
|
+
if (submitted && ["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "") && str2(p.delta)) {
|
|
113166
113126
|
if (msg.method?.startsWith("item/reasoning/")) thinking();
|
|
113167
113127
|
else recovered();
|
|
113168
113128
|
io.activity?.();
|
|
@@ -113181,17 +113141,17 @@ async function run(io, options, count2) {
|
|
|
113181
113141
|
}
|
|
113182
113142
|
if (msg.method === "item/started" || msg.method === "item/completed") {
|
|
113183
113143
|
recovered();
|
|
113184
|
-
item(
|
|
113144
|
+
item(obj2(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
|
|
113185
113145
|
}
|
|
113186
113146
|
if (msg.method === "thread/tokenUsage/updated") {
|
|
113187
113147
|
if (!submitted) return;
|
|
113188
|
-
const token =
|
|
113189
|
-
const counts =
|
|
113148
|
+
const token = obj2(p.tokenUsage);
|
|
113149
|
+
const counts = obj2(token.total);
|
|
113190
113150
|
const input2 = Number(counts.inputTokens) || 0;
|
|
113191
113151
|
const read3 = Number(counts.cachedInputTokens) || 0;
|
|
113192
113152
|
const write = Number(counts.cacheWriteInputTokens) || 0;
|
|
113193
113153
|
total = { input: Math.max(0, input2 - read3 - write), cacheRead: read3, cacheCreation: write, output: Number(counts.outputTokens) || 0 };
|
|
113194
|
-
const last2 =
|
|
113154
|
+
const last2 = obj2(token.last);
|
|
113195
113155
|
if (!baseline && Object.keys(last2).length) {
|
|
113196
113156
|
const cached4 = Number(last2.cachedInputTokens) || 0;
|
|
113197
113157
|
const written = Number(last2.cacheWriteInputTokens) || 0;
|
|
@@ -113210,8 +113170,8 @@ async function run(io, options, count2) {
|
|
|
113210
113170
|
} else if (p.willRetry !== true) end(failure5.reason, failure5);
|
|
113211
113171
|
}
|
|
113212
113172
|
if (msg.method === "turn/completed") {
|
|
113213
|
-
const turn2 =
|
|
113214
|
-
const id2 =
|
|
113173
|
+
const turn2 = obj2(p.turn);
|
|
113174
|
+
const id2 = str2(turn2.id);
|
|
113215
113175
|
if (completedTurns.has(id2)) return;
|
|
113216
113176
|
completedTurns.add(id2);
|
|
113217
113177
|
for (const raw of list2(turn2.items)) {
|
|
@@ -113220,7 +113180,7 @@ async function run(io, options, count2) {
|
|
|
113220
113180
|
}
|
|
113221
113181
|
if (idling) return;
|
|
113222
113182
|
if (turn2.status !== "completed") {
|
|
113223
|
-
const reason =
|
|
113183
|
+
const reason = str2(obj2(turn2.error).message) || `Codex turn ${str2(turn2.status)}.`;
|
|
113224
113184
|
const failure5 = turn2.status === "failed" ? codexFailure(turn2.error, reason) : { code: "turn_stopped", level: 3, reason };
|
|
113225
113185
|
end(reason, failure5);
|
|
113226
113186
|
return;
|
|
@@ -113245,8 +113205,8 @@ async function run(io, options, count2) {
|
|
|
113245
113205
|
}
|
|
113246
113206
|
phase("preparing");
|
|
113247
113207
|
const initialized = await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
|
|
113248
|
-
host2 =
|
|
113249
|
-
if (host2.instance) cleanup.instance =
|
|
113208
|
+
host2 = obj2(initialized.wildcrane);
|
|
113209
|
+
if (host2.instance) cleanup.instance = str2(host2.instance);
|
|
113250
113210
|
phase("initialized");
|
|
113251
113211
|
rpc.notify("initialized");
|
|
113252
113212
|
const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
|
|
@@ -113270,15 +113230,15 @@ async function run(io, options, count2) {
|
|
|
113270
113230
|
}
|
|
113271
113231
|
}
|
|
113272
113232
|
if (ended || !response) return done;
|
|
113273
|
-
const thread =
|
|
113274
|
-
for (const turn2 of list2(thread.turns)) historicalTurns.add(
|
|
113275
|
-
threadId =
|
|
113233
|
+
const thread = obj2(response.thread);
|
|
113234
|
+
for (const turn2 of list2(thread.turns)) historicalTurns.add(str2(turn2.id));
|
|
113235
|
+
threadId = str2(thread.id);
|
|
113276
113236
|
if (!threadId) throw Error("Codex did not return a thread id.");
|
|
113277
113237
|
if (mode === "resume" && threadId !== params.threadId) throw Error("Codex did not return the requested session.");
|
|
113278
|
-
work.root(threadId, list2(response.retainedThreads).map((t2) =>
|
|
113279
|
-
for (const terminal of list2(response.retainedTerminals)) retained.set(`terminal:${
|
|
113280
|
-
provider =
|
|
113281
|
-
model =
|
|
113238
|
+
work.root(threadId, list2(response.retainedThreads).map((t2) => str2(t2.id)));
|
|
113239
|
+
for (const terminal of list2(response.retainedTerminals)) retained.set(`terminal:${str2(terminal.threadId)}:${str2(terminal.itemId)}`, str2(terminal.processId));
|
|
113240
|
+
provider = str2(thread.modelProvider) || void 0;
|
|
113241
|
+
model = str2(response.model) || str2(thread.model) || void 0;
|
|
113282
113242
|
if (model) io.gotModel(model);
|
|
113283
113243
|
io.gotResumeId(threadId);
|
|
113284
113244
|
baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total ?? (!options.threadId && !io.resumeId ? ZERO_USAGE : void 0);
|
|
@@ -113304,15 +113264,15 @@ var userMessage = (prompt) => `${JSON.stringify({ type: "user", message: { role:
|
|
|
113304
113264
|
`;
|
|
113305
113265
|
function claudeOnWindows() {
|
|
113306
113266
|
const [local, roaming] = [process.env.LOCALAPPDATA?.trim(), process.env.APPDATA?.trim()];
|
|
113307
|
-
const packages = local ?
|
|
113267
|
+
const packages = local ? path27.join(local, "Packages") : "";
|
|
113308
113268
|
const data = [
|
|
113309
|
-
...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) =>
|
|
113310
|
-
...roaming ? [
|
|
113269
|
+
...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path27.join(packages, name, "LocalCache", "Roaming", "Claude")),
|
|
113270
|
+
...roaming ? [path27.join(roaming, "Claude")] : []
|
|
113311
113271
|
];
|
|
113312
113272
|
return data.flatMap(
|
|
113313
|
-
(dir) => latestIn(
|
|
113314
|
-
|
|
113315
|
-
...folders(version3).map((build) =>
|
|
113273
|
+
(dir) => latestIn(path27.join(dir, "claude-code")).flatMap((version3) => [
|
|
113274
|
+
path27.join(version3, "claude.exe"),
|
|
113275
|
+
...folders(version3).map((build) => path27.join(version3, build, "claude.exe"))
|
|
113316
113276
|
])
|
|
113317
113277
|
);
|
|
113318
113278
|
}
|
|
@@ -113485,7 +113445,7 @@ var CLAUDE_CODE = {
|
|
|
113485
113445
|
...MODEL_ALIASES,
|
|
113486
113446
|
...modelsIn(
|
|
113487
113447
|
home(".claude.json"),
|
|
113488
|
-
(data) => arr(
|
|
113448
|
+
(data) => arr(obj(data).additionalModelOptionsCache).map((option) => str(obj(option).value))
|
|
113489
113449
|
)
|
|
113490
113450
|
];
|
|
113491
113451
|
},
|
|
@@ -113556,24 +113516,24 @@ var CLAUDE_CODE = {
|
|
|
113556
113516
|
...latestIn(home(".local", "share", "claude", "versions")),
|
|
113557
113517
|
// The copy Claude Desktop carries.
|
|
113558
113518
|
...process.platform === "win32" ? claudeOnWindows() : latestIn(home("Library", "Application Support", "Claude", "claude-code")).flatMap(
|
|
113559
|
-
(version3) => folders(version3).map((build) =>
|
|
113519
|
+
(version3) => folders(version3).map((build) => path27.join(version3, build, "claude.app", "Contents", "MacOS", "claude"))
|
|
113560
113520
|
)
|
|
113561
113521
|
],
|
|
113562
113522
|
install: "npm install -g @anthropic-ai/claude-code"
|
|
113563
113523
|
};
|
|
113564
113524
|
|
|
113565
113525
|
// ../cli/src/lib/agent/harnesses/codex.ts
|
|
113566
|
-
import
|
|
113567
|
-
import
|
|
113526
|
+
import fs24 from "node:fs";
|
|
113527
|
+
import path28 from "node:path";
|
|
113568
113528
|
|
|
113569
113529
|
// ../cli/src/lib/agent/worktree.ts
|
|
113570
|
-
import { spawnSync as
|
|
113530
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
113571
113531
|
var MAX_OUTPUT = 64 * 1024 * 1024;
|
|
113572
113532
|
var gitLimits = { timeoutMs: 3e4 };
|
|
113573
113533
|
var GitTimeoutError = class extends Error {
|
|
113574
113534
|
};
|
|
113575
113535
|
function spawnGit(args2, options) {
|
|
113576
|
-
const out =
|
|
113536
|
+
const out = spawnSync3("git", args2, {
|
|
113577
113537
|
...options,
|
|
113578
113538
|
encoding: "utf8",
|
|
113579
113539
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -113611,10 +113571,10 @@ function codexExtraArgs(argv, cwd = REPO_ROOT) {
|
|
|
113611
113571
|
}
|
|
113612
113572
|
const flags = [...argv, ...extra];
|
|
113613
113573
|
const workspaceWrite = flags.some((arg, i) => arg === "--full-auto" || arg === "--sandbox=workspace-write" || (arg === "--sandbox" || arg === "-s") && flags[i + 1] === "workspace-write");
|
|
113614
|
-
if (workspaceWrite &&
|
|
113574
|
+
if (workspaceWrite && path28.resolve(cwd) !== path28.resolve(REPO_ROOT)) {
|
|
113615
113575
|
for (const dir of [KANBAN, AKB_DIR]) {
|
|
113616
|
-
const relative =
|
|
113617
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
113576
|
+
const relative = path28.relative(cwd, dir);
|
|
113577
|
+
if (relative === ".." || relative.startsWith(`..${path28.sep}`) || path28.isAbsolute(relative)) {
|
|
113618
113578
|
extra.push("--add-dir", dir);
|
|
113619
113579
|
}
|
|
113620
113580
|
}
|
|
@@ -113637,7 +113597,7 @@ function envRoot(name) {
|
|
|
113637
113597
|
}
|
|
113638
113598
|
function modified(file3) {
|
|
113639
113599
|
try {
|
|
113640
|
-
return
|
|
113600
|
+
return fs24.statSync(file3).mtimeMs;
|
|
113641
113601
|
} catch {
|
|
113642
113602
|
return 0;
|
|
113643
113603
|
}
|
|
@@ -113663,28 +113623,28 @@ function codexOnWindows() {
|
|
|
113663
113623
|
const local = envRoot("LOCALAPPDATA");
|
|
113664
113624
|
const profile = envRoot("USERPROFILE");
|
|
113665
113625
|
const programs = envRoot("ProgramFiles");
|
|
113666
|
-
const cache = local ?
|
|
113667
|
-
const releases = profile ?
|
|
113668
|
-
const packages = programs ?
|
|
113626
|
+
const cache = local ? path28.join(local, "OpenAI", "Codex", "bin") : "";
|
|
113627
|
+
const releases = profile ? path28.join(profile, ".codex", "packages", "standalone", "releases") : "";
|
|
113628
|
+
const packages = programs ? path28.join(programs, "WindowsApps") : "";
|
|
113669
113629
|
return [
|
|
113670
113630
|
// Desktop's relocated CLI cache: a folder per build hash, newest file first.
|
|
113671
|
-
...byNewest(folders(cache).map((name) =>
|
|
113631
|
+
...byNewest(folders(cache).map((name) => path28.join(cache, name, "codex.exe"))),
|
|
113672
113632
|
// The separate standalone launcher, at a path with nothing variable in it.
|
|
113673
|
-
...local ? [
|
|
113633
|
+
...local ? [path28.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
|
|
113674
113634
|
// That launcher's release payload: a folder per version and target.
|
|
113675
113635
|
...byVersion(folders(releases).filter(ourArch)).map(
|
|
113676
|
-
(name) =>
|
|
113636
|
+
(name) => path28.join(releases, name, "bin", "codex.exe")
|
|
113677
113637
|
),
|
|
113678
113638
|
// Desktop's own MSIX package.
|
|
113679
113639
|
...byVersion(folders(packages).filter((name) => name.startsWith("OpenAI.Codex_")).filter(ourArch)).map(
|
|
113680
|
-
(name) =>
|
|
113640
|
+
(name) => path28.join(packages, name, "app", "resources", "codex.exe")
|
|
113681
113641
|
)
|
|
113682
113642
|
];
|
|
113683
113643
|
}
|
|
113684
113644
|
function codexInstalls() {
|
|
113685
113645
|
const chosen = process.env.CODEX_INSTALL_DIR?.trim();
|
|
113686
113646
|
return [
|
|
113687
|
-
...chosen ? [
|
|
113647
|
+
...chosen ? [path28.join(chosen, "codex")] : [],
|
|
113688
113648
|
...process.platform === "win32" ? codexOnWindows() : [
|
|
113689
113649
|
// macOS, where Codex now lives in the merged app — `codex-cli/bin/` since 26.928…
|
|
113690
113650
|
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex",
|
|
@@ -113730,7 +113690,7 @@ var CODEX = {
|
|
|
113730
113690
|
systemPrompt(text3, argv) {
|
|
113731
113691
|
if (namesFlag(argv, ["developer_instructions", "model_instructions_file"])) return {};
|
|
113732
113692
|
try {
|
|
113733
|
-
const config3 =
|
|
113693
|
+
const config3 = fs24.readFileSync(path28.join(process.env.CODEX_HOME || home(".codex"), "config.toml"), "utf8");
|
|
113734
113694
|
if (/^\s*(?:developer_instructions|model_instructions_file)\s*=/m.test(config3)) return {};
|
|
113735
113695
|
} catch {
|
|
113736
113696
|
}
|
|
@@ -113852,7 +113812,7 @@ var CODEX = {
|
|
|
113852
113812
|
models() {
|
|
113853
113813
|
return modelsIn(
|
|
113854
113814
|
home(".codex", "models_cache.json"),
|
|
113855
|
-
(data) => arr(
|
|
113815
|
+
(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))
|
|
113856
113816
|
);
|
|
113857
113817
|
},
|
|
113858
113818
|
// Nothing extra. Claude Code gets CLAUDE_CODE_MAX_RETRIES=0 so a rate limit fails at
|
|
@@ -113970,24 +113930,24 @@ var CURSOR = {
|
|
|
113970
113930
|
};
|
|
113971
113931
|
|
|
113972
113932
|
// ../cli/src/lib/agent/harnesses/dsh.ts
|
|
113973
|
-
import
|
|
113974
|
-
import
|
|
113933
|
+
import fs25 from "node:fs";
|
|
113934
|
+
import path29 from "node:path";
|
|
113975
113935
|
function dshHome(argv) {
|
|
113976
113936
|
const binary = argv[0];
|
|
113977
113937
|
if (!binary) return void 0;
|
|
113978
|
-
const names = process.platform === "win32" && !
|
|
113979
|
-
const candidates2 = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(
|
|
113938
|
+
const names = process.platform === "win32" && !path29.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
|
|
113939
|
+
const candidates2 = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path29.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path29.join(dir2, name)));
|
|
113980
113940
|
let dir;
|
|
113981
113941
|
try {
|
|
113982
|
-
const found = candidates2.find((candidate) =>
|
|
113942
|
+
const found = candidates2.find((candidate) => fs25.existsSync(candidate));
|
|
113983
113943
|
if (!found) return void 0;
|
|
113984
|
-
const script = /\.cmd$/i.test(found) ? shimTarget(
|
|
113985
|
-
dir =
|
|
113944
|
+
const script = /\.cmd$/i.test(found) ? shimTarget(fs25.readFileSync(found, "utf8"), found)?.script : void 0;
|
|
113945
|
+
dir = path29.dirname(fs25.realpathSync(script ?? found));
|
|
113986
113946
|
} catch {
|
|
113987
113947
|
return void 0;
|
|
113988
113948
|
}
|
|
113989
|
-
for (let up =
|
|
113990
|
-
if (
|
|
113949
|
+
for (let up = path29.dirname(dir); dir !== up; up = path29.dirname(dir)) {
|
|
113950
|
+
if (fs25.existsSync(path29.join(dir, "package.json"))) return dir;
|
|
113991
113951
|
dir = up;
|
|
113992
113952
|
}
|
|
113993
113953
|
return void 0;
|
|
@@ -114141,7 +114101,7 @@ var GROK = {
|
|
|
114141
114101
|
// subscription's models, one on a key sees the key's, and the board reads whichever is
|
|
114142
114102
|
// there rather than deciding.
|
|
114143
114103
|
models() {
|
|
114144
|
-
return modelsIn(home(".grok", "models_cache.json"), (data) => Object.keys(
|
|
114104
|
+
return modelsIn(home(".grok", "models_cache.json"), (data) => Object.keys(obj(obj(data).models)));
|
|
114145
114105
|
},
|
|
114146
114106
|
// Everything that could send a Grok run to a provider the user didn't pick: where the
|
|
114147
114107
|
// requests go, the second name the key answers to, and the three that decide who issues
|
|
@@ -114420,12 +114380,12 @@ var OPENCODE = {
|
|
|
114420
114380
|
models() {
|
|
114421
114381
|
const cache = process.env.XDG_CACHE_HOME || home(".cache");
|
|
114422
114382
|
const data = process.env.XDG_DATA_HOME || home(".local", "share");
|
|
114423
|
-
const mine = modelsIn(join6(data, "opencode", "auth.json"), (auth) => Object.keys(
|
|
114383
|
+
const mine = modelsIn(join6(data, "opencode", "auth.json"), (auth) => Object.keys(obj(auth)));
|
|
114424
114384
|
if (!mine.length) return [];
|
|
114425
114385
|
return modelsIn(
|
|
114426
114386
|
join6(cache, "opencode", "models.json"),
|
|
114427
114387
|
(catalogue) => mine.flatMap(
|
|
114428
|
-
(provider) => Object.keys(
|
|
114388
|
+
(provider) => Object.keys(obj(obj(obj(catalogue)[provider]).models)).map((model) => `${provider}/${model}`)
|
|
114429
114389
|
),
|
|
114430
114390
|
mine.join(" ")
|
|
114431
114391
|
);
|
|
@@ -114438,7 +114398,7 @@ var OPENCODE = {
|
|
|
114438
114398
|
`);
|
|
114439
114399
|
let own4 = {};
|
|
114440
114400
|
try {
|
|
114441
|
-
own4 =
|
|
114401
|
+
own4 = obj(JSON.parse(env2.OPENCODE_CONFIG_CONTENT ?? "{}"));
|
|
114442
114402
|
} catch {
|
|
114443
114403
|
}
|
|
114444
114404
|
const instructions = [...Array.isArray(own4.instructions) ? own4.instructions : [], file3];
|
|
@@ -114525,8 +114485,8 @@ var ZCODE = {
|
|
|
114525
114485
|
models() {
|
|
114526
114486
|
return modelsIn(
|
|
114527
114487
|
home(".zcode", "v2", "config.json"),
|
|
114528
|
-
(data) => Object.values(
|
|
114529
|
-
(provider) => Object.keys(
|
|
114488
|
+
(data) => Object.values(obj(obj(data).provider)).flatMap(
|
|
114489
|
+
(provider) => Object.keys(obj(obj(provider).models))
|
|
114530
114490
|
)
|
|
114531
114491
|
);
|
|
114532
114492
|
},
|
|
@@ -114685,8 +114645,8 @@ var sources2 = Object.fromEntries(
|
|
|
114685
114645
|
])
|
|
114686
114646
|
);
|
|
114687
114647
|
Object.assign(sources2, {
|
|
114688
|
-
"claude-code": () => claudeModels(
|
|
114689
|
-
codex: () => codexModels(
|
|
114648
|
+
"claude-code": () => claudeModels(path30.join(process.env.CLAUDE_CONFIG_DIR || path30.join(os7.homedir(), ".claude"), "cache", "model-catalog")),
|
|
114649
|
+
codex: () => codexModels(path30.join(process.env.CODEX_HOME || path30.join(os7.homedir(), ".codex"), "models_cache.json")),
|
|
114690
114650
|
opencode: async (signal) => opencodeModels(await output2(commandOf(HARNESSES2.opencode)[0], ["models"], signal)),
|
|
114691
114651
|
cursor: (signal) => cursorModels(signal),
|
|
114692
114652
|
antigravity: async (signal) => antigravityModels(await output2(commandOf(HARNESSES2.antigravity)[0], ["models"], signal))
|
|
@@ -114722,10 +114682,10 @@ function cursorModels(signal, argv = commandOf(HARNESSES2.cursor)) {
|
|
|
114722
114682
|
});
|
|
114723
114683
|
}
|
|
114724
114684
|
function acpModels(opened) {
|
|
114725
|
-
const list3 =
|
|
114726
|
-
return (Array.isArray(list3) ? list3 : []).map(
|
|
114727
|
-
const id2 =
|
|
114728
|
-
return id2 && id2 !== "default[]" ? [{ id: id2, name:
|
|
114685
|
+
const list3 = obj2(opened.models).availableModels;
|
|
114686
|
+
return (Array.isArray(list3) ? list3 : []).map(obj2).flatMap((m) => {
|
|
114687
|
+
const id2 = str2(m.modelId);
|
|
114688
|
+
return id2 && id2 !== "default[]" ? [{ id: id2, name: str2(m.name) || id2 }] : [];
|
|
114729
114689
|
});
|
|
114730
114690
|
}
|
|
114731
114691
|
function output2(command, args2, signal) {
|
|
@@ -114756,7 +114716,7 @@ function output2(command, args2, signal) {
|
|
|
114756
114716
|
}
|
|
114757
114717
|
function codexModels(file3) {
|
|
114758
114718
|
try {
|
|
114759
|
-
const cache = JSON.parse(
|
|
114719
|
+
const cache = JSON.parse(fs26.readFileSync(file3, "utf8"));
|
|
114760
114720
|
if (!Array.isArray(cache.models)) return [];
|
|
114761
114721
|
return cache.models.flatMap(
|
|
114762
114722
|
(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 }] : []
|
|
@@ -114768,30 +114728,30 @@ function codexModels(file3) {
|
|
|
114768
114728
|
function claudeModels(dir) {
|
|
114769
114729
|
let files;
|
|
114770
114730
|
try {
|
|
114771
|
-
files =
|
|
114731
|
+
files = fs26.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
114772
114732
|
} catch {
|
|
114773
114733
|
return [];
|
|
114774
114734
|
}
|
|
114775
114735
|
const catalogs = files.flatMap((f) => {
|
|
114776
114736
|
try {
|
|
114777
|
-
const data =
|
|
114778
|
-
const catalog =
|
|
114779
|
-
const surface =
|
|
114780
|
-
return surface === "cc" || surface === "ccd" ? [{ surface, at: Number(data.fetchedAt) || 0, config:
|
|
114737
|
+
const data = obj2(JSON.parse(fs26.readFileSync(path30.join(dir, f), "utf8")));
|
|
114738
|
+
const catalog = obj2(data.catalog);
|
|
114739
|
+
const surface = str2(catalog.surface);
|
|
114740
|
+
return surface === "cc" || surface === "ccd" ? [{ surface, at: Number(data.fetchedAt) || 0, config: obj2(catalog.config) }] : [];
|
|
114781
114741
|
} catch {
|
|
114782
114742
|
return [];
|
|
114783
114743
|
}
|
|
114784
114744
|
});
|
|
114785
114745
|
const newest2 = catalogs.sort((a, b) => a.surface === b.surface ? b.at - a.at : a.surface === "cc" ? -1 : 1)[0];
|
|
114786
114746
|
if (!newest2) return [];
|
|
114787
|
-
const aliases =
|
|
114747
|
+
const aliases = obj2(newest2.config.provider_alias_targets);
|
|
114788
114748
|
const models = Array.isArray(newest2.config.models) ? newest2.config.models : [];
|
|
114789
|
-
return models.map(
|
|
114790
|
-
const id2 =
|
|
114749
|
+
return models.map(obj2).flatMap((m) => {
|
|
114750
|
+
const id2 = str2(m.id);
|
|
114791
114751
|
if (!id2 || m.section !== "main") return [];
|
|
114792
|
-
const family =
|
|
114793
|
-
const alias = family &&
|
|
114794
|
-
return [{ id: alias || id2, name:
|
|
114752
|
+
const family = str2(obj2(m.runtime).family);
|
|
114753
|
+
const alias = family && str2(obj2(aliases[family]).default) === id2 ? family : "";
|
|
114754
|
+
return [{ id: alias || id2, name: str2(m.short_name) || str2(m.name) || id2 }];
|
|
114795
114755
|
});
|
|
114796
114756
|
}
|
|
114797
114757
|
function probeLogin(binary, harness) {
|
|
@@ -114825,30 +114785,30 @@ import fs30 from "node:fs";
|
|
|
114825
114785
|
import path35 from "node:path";
|
|
114826
114786
|
|
|
114827
114787
|
// ../runner/src/kanban-skill.ts
|
|
114828
|
-
import { spawnSync as
|
|
114829
|
-
import
|
|
114830
|
-
import
|
|
114788
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
114789
|
+
import fs27 from "node:fs";
|
|
114790
|
+
import path31 from "node:path";
|
|
114831
114791
|
var SKILL_FOLDERS = [".claude/skills/kanban", ".agents/skills/kanban"];
|
|
114832
114792
|
var MANAGED = /^<!-- ai4kanban \S+ -->$/m;
|
|
114833
114793
|
function removeLegacyKanbanSkill(root2) {
|
|
114834
114794
|
for (const folder2 of SKILL_FOLDERS) {
|
|
114835
114795
|
try {
|
|
114836
114796
|
let at = root2;
|
|
114837
|
-
if (!
|
|
114797
|
+
if (!fs27.lstatSync(at, { throwIfNoEntry: false })?.isDirectory()) continue;
|
|
114838
114798
|
let safe2 = true;
|
|
114839
114799
|
const parts = `${folder2}/SKILL.md`.split("/");
|
|
114840
114800
|
for (const [i, name] of parts.entries()) {
|
|
114841
|
-
at =
|
|
114842
|
-
const stat =
|
|
114801
|
+
at = path31.join(at, name);
|
|
114802
|
+
const stat = fs27.lstatSync(at, { throwIfNoEntry: false });
|
|
114843
114803
|
if (!stat || stat.isSymbolicLink() || (i < parts.length - 1 ? !stat.isDirectory() : !stat.isFile())) {
|
|
114844
114804
|
safe2 = false;
|
|
114845
114805
|
break;
|
|
114846
114806
|
}
|
|
114847
114807
|
}
|
|
114848
|
-
if (!safe2 || !MANAGED.test(
|
|
114849
|
-
|
|
114850
|
-
const dir =
|
|
114851
|
-
if (
|
|
114808
|
+
if (!safe2 || !MANAGED.test(fs27.readFileSync(at, "utf8"))) continue;
|
|
114809
|
+
fs27.unlinkSync(at);
|
|
114810
|
+
const dir = path31.dirname(at);
|
|
114811
|
+
if (fs27.readdirSync(dir).length === 0) fs27.rmdirSync(dir);
|
|
114852
114812
|
} catch (e) {
|
|
114853
114813
|
process.stderr.write(`wildcrane: \u65E0\u6CD5\u6E05\u7406 ${folder2}\uFF1A${e instanceof Error ? e.message : String(e)}
|
|
114854
114814
|
`);
|
|
@@ -114856,15 +114816,15 @@ function removeLegacyKanbanSkill(root2) {
|
|
|
114856
114816
|
}
|
|
114857
114817
|
}
|
|
114858
114818
|
function keepOutOfGit(dir, folders2 = SKILL_FOLDERS) {
|
|
114859
|
-
const git2 = (...args2) =>
|
|
114819
|
+
const git2 = (...args2) => spawnSync4("git", ["-C", dir, ...args2], { encoding: "utf8" });
|
|
114860
114820
|
const inside = git2("rev-parse", "--git-path", "info/exclude");
|
|
114861
114821
|
if (inside.status !== 0) return;
|
|
114862
114822
|
const missing = [".akb/", ...folders2.map((f) => `${f}/`)].filter((p) => git2("check-ignore", "-q", p).status !== 0);
|
|
114863
114823
|
if (!missing.length) return;
|
|
114864
|
-
const exclude =
|
|
114865
|
-
|
|
114866
|
-
const held2 =
|
|
114867
|
-
|
|
114824
|
+
const exclude = path31.resolve(dir, inside.stdout.trim());
|
|
114825
|
+
fs27.mkdirSync(path31.dirname(exclude), { recursive: true });
|
|
114826
|
+
const held2 = fs27.existsSync(exclude) ? fs27.readFileSync(exclude, "utf8") : "";
|
|
114827
|
+
fs27.writeFileSync(exclude, `${held2}${held2 && !held2.endsWith("\n") ? "\n" : ""}${missing.join("\n")}
|
|
114868
114828
|
`);
|
|
114869
114829
|
}
|
|
114870
114830
|
function retireKanbanSkill(dir) {
|
|
@@ -114880,11 +114840,11 @@ function retireKanbanSkill(dir) {
|
|
|
114880
114840
|
// ../runner/src/lock.ts
|
|
114881
114841
|
import crypto6 from "node:crypto";
|
|
114882
114842
|
import net from "node:net";
|
|
114883
|
-
import
|
|
114843
|
+
import path32 from "node:path";
|
|
114884
114844
|
function lockPath() {
|
|
114885
114845
|
const home4 = runnerHome();
|
|
114886
114846
|
if (process.platform === "win32") return `\\\\.\\pipe\\wildcrane-${crypto6.createHash("sha256").update(home4).digest("hex").slice(0, 16)}`;
|
|
114887
|
-
return
|
|
114847
|
+
return path32.join(home4, "runner.sock");
|
|
114888
114848
|
}
|
|
114889
114849
|
function runnerSettingsSupport() {
|
|
114890
114850
|
return new Promise((resolve2) => {
|
|
@@ -114916,6 +114876,92 @@ function runnerSettingsSupport() {
|
|
|
114916
114876
|
import { spawn as spawn4 } from "node:child_process";
|
|
114917
114877
|
import crypto7 from "node:crypto";
|
|
114918
114878
|
import http from "node:http";
|
|
114879
|
+
|
|
114880
|
+
// ../runner/src/settings-control.ts
|
|
114881
|
+
import fs29 from "node:fs";
|
|
114882
|
+
import path34 from "node:path";
|
|
114883
|
+
|
|
114884
|
+
// ../runner/src/codex-native.ts
|
|
114885
|
+
import fs28 from "node:fs";
|
|
114886
|
+
import path33 from "node:path";
|
|
114887
|
+
var import_undici2 = __toESM(require_undici(), 1);
|
|
114888
|
+
|
|
114889
|
+
// ../cli/src/lib/agent/connection-process.ts
|
|
114890
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
114891
|
+
function connectionIdentity(pid) {
|
|
114892
|
+
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" } });
|
|
114893
|
+
return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
|
|
114894
|
+
}
|
|
114895
|
+
function connectionStopped(root2) {
|
|
114896
|
+
if (!root2) return true;
|
|
114897
|
+
if (!pidAlive(root2.pid)) return true;
|
|
114898
|
+
const identity = connectionIdentity(root2.pid);
|
|
114899
|
+
return !!root2.identity && !!identity && identity !== root2.identity;
|
|
114900
|
+
}
|
|
114901
|
+
|
|
114902
|
+
// ../runner/src/codex-native.ts
|
|
114903
|
+
var nativeDirectory = () => path33.join(runnerCwd(), "codex-native");
|
|
114904
|
+
var liveBackend = (backend) => !connectionStopped(backend);
|
|
114905
|
+
function readPrivate(file3) {
|
|
114906
|
+
try {
|
|
114907
|
+
return JSON.parse(fs28.readFileSync(file3, "utf8"));
|
|
114908
|
+
} catch (error63) {
|
|
114909
|
+
if (error63.code === "ENOENT") return;
|
|
114910
|
+
throw error63;
|
|
114911
|
+
}
|
|
114912
|
+
}
|
|
114913
|
+
function stopNativeBackends() {
|
|
114914
|
+
let files = [];
|
|
114915
|
+
try {
|
|
114916
|
+
files = fs28.readdirSync(nativeDirectory()).filter((name) => /^[a-f0-9]{64}\.json$/.test(name));
|
|
114917
|
+
} catch {
|
|
114918
|
+
return [];
|
|
114919
|
+
}
|
|
114920
|
+
const targets = [];
|
|
114921
|
+
for (const file3 of files) {
|
|
114922
|
+
const backend = readPrivate(path33.join(nativeDirectory(), file3));
|
|
114923
|
+
if (backend?.identity && liveBackend(backend) && connectionIdentity(backend.pid) === backend.identity) {
|
|
114924
|
+
targets.push(backend);
|
|
114925
|
+
try {
|
|
114926
|
+
process.kill(backend.pid, "SIGTERM");
|
|
114927
|
+
} catch {
|
|
114928
|
+
}
|
|
114929
|
+
}
|
|
114930
|
+
}
|
|
114931
|
+
return targets;
|
|
114932
|
+
}
|
|
114933
|
+
|
|
114934
|
+
// ../runner/src/settings-control.ts
|
|
114935
|
+
var directory = () => path34.join(runnerHome(), "executors");
|
|
114936
|
+
var epochFile = () => path34.join(runnerHome(), "account-generation");
|
|
114937
|
+
function accountGeneration() {
|
|
114938
|
+
try {
|
|
114939
|
+
return fs29.readFileSync(epochFile(), "utf8");
|
|
114940
|
+
} catch {
|
|
114941
|
+
return "";
|
|
114942
|
+
}
|
|
114943
|
+
}
|
|
114944
|
+
async function stopExecutors() {
|
|
114945
|
+
fs29.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
|
|
114946
|
+
fs29.writeFileSync(epochFile(), `${Date.now()}-${process.pid}`, { mode: 384 });
|
|
114947
|
+
const backends = stopNativeBackends();
|
|
114948
|
+
for (let n = 0; n < 160; n++) {
|
|
114949
|
+
const active = fs29.existsSync(directory()) ? fs29.readdirSync(directory()).filter((name) => {
|
|
114950
|
+
try {
|
|
114951
|
+
process.kill(Number(name.split(".")[0]), 0);
|
|
114952
|
+
return true;
|
|
114953
|
+
} catch {
|
|
114954
|
+
fs29.rmSync(path34.join(directory(), name), { force: true });
|
|
114955
|
+
return false;
|
|
114956
|
+
}
|
|
114957
|
+
}) : [];
|
|
114958
|
+
if (!active.length && backends.every((backend) => !liveBackend(backend))) return true;
|
|
114959
|
+
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
114960
|
+
}
|
|
114961
|
+
return false;
|
|
114962
|
+
}
|
|
114963
|
+
|
|
114964
|
+
// ../runner/src/signin.ts
|
|
114919
114965
|
var WAIT_MS = 10 * 60 * 1e3;
|
|
114920
114966
|
var CRANE = "M2 55.75C2 55.69 2.69 55.09 3.55 54.37L5.09 53.1L6.61 53.1L8.13 53.1L12.49 49.87C14.9 48.07 16.83 46.58 16.77 46.53C16.75 46.47 15.56 46.64 14.15 46.89C12.74 47.13 11.55 47.3 11.53 47.24C11.47 47.19 12.02 46.22 12.71 45.06L14.01 42.96L18.21 41.34C20.53 40.45 22.41 39.65 22.41 39.57C22.41 39.49 21.27 38.55 19.92 37.5C15.92 34.4 13.13 31.31 10.86 27.47L10.01 26.01L10.53 26.18C10.84 26.26 12.96 27.2 15.28 28.25C17.6 29.32 19.53 30.12 19.59 30.07C19.64 30.01 17.68 28.69 15.25 27.11C12.8 25.57 10.56 23.97 10.31 23.58C9.15 21.95 7.25 17.5 7.25 16.46C7.25 16.26 10.01 17.95 13.38 20.18C16.77 22.45 19.73 24.38 19.95 24.49C20.42 24.74 20.25 24.57 13.9 19.02L9.18 14.88L8.6 13.36C7.72 10.96 6.97 7.54 6.97 5.77L6.97 4.14L9.4 6.46C12.66 9.61 15.56 12.01 23.57 18.25C27.32 21.18 30.5 23.72 30.64 23.91C30.8 24.08 31.68 26.51 32.6 29.3L34.28 34.35L35.72 35.65C37.54 37.3 37.98 37.47 36.85 36.09L35.96 35.01L37.12 34.71C39.11 34.21 40.16 33.52 42.54 31.12L44.8 28.8L46.02 28.96C46.71 29.07 47.56 29.07 47.95 28.96L48.67 28.8L48.67 28.25L48.67 27.69L49.27 27.69C49.63 27.69 50.1 27.58 50.32 27.42L50.71 27.17L51.01 27.42C51.18 27.56 52.78 27.86 54.58 28.08C56.37 28.3 57.86 28.52 57.94 28.58C58 28.63 56.73 28.85 55.13 29.05C53.53 29.24 50.96 29.77 49.44 30.21C47.92 30.65 46.57 31.01 46.43 31.01C46.29 31.01 44.22 32.97 41.85 35.37C37.57 39.62 34.42 42.14 30.83 44.15L29.14 45.09L25.97 45.73L22.77 46.39L14.59 51.11L6.42 55.86L4.21 55.86C2.99 55.86 2 55.8 2 55.75Z";
|
|
114921
114967
|
var CREST = "M44.97 27.45C44.61 26.89 46.57 25.76 47.87 25.76C48.72 25.76 50.6 26.7 50.6 27.14C50.6 27.64 45.27 27.97 44.97 27.45Z";
|
|
@@ -115690,7 +115736,7 @@ var goalOf = (i) => ({
|
|
|
115690
115736
|
outcome: i.outcome,
|
|
115691
115737
|
acceptance: i.acceptance,
|
|
115692
115738
|
studio: i.studio,
|
|
115693
|
-
review_plan:
|
|
115739
|
+
review_plan: i.review_plan ?? null,
|
|
115694
115740
|
task: i.task ? { ...i.task, url: taskUrl(i.task.key || i.task.id) } : null
|
|
115695
115741
|
});
|
|
115696
115742
|
async function studiosOf(workspace) {
|
|
@@ -115702,8 +115748,8 @@ async function draftOf(id2) {
|
|
|
115702
115748
|
const read3 = await readDiscussion(id2);
|
|
115703
115749
|
if (!read3.ok) return failure4(read3);
|
|
115704
115750
|
const d = read3.value;
|
|
115705
|
-
const goals = linked(d,
|
|
115706
|
-
return { discussion: d.id, url: discussionUrl(d.id), project: d.project, version: d.version, goals,
|
|
115751
|
+
const goals = linked(d.id, d.goals);
|
|
115752
|
+
return { discussion: d.id, url: discussionUrl(d.id), project: d.project, version: d.version, goals, studios: await studiosOf(d.workspace) };
|
|
115707
115753
|
}
|
|
115708
115754
|
var runner = null;
|
|
115709
115755
|
var runnerState = "off";
|
|
@@ -115833,7 +115879,7 @@ async function chats() {
|
|
|
115833
115879
|
chats: held2.flatMap((c, n) => {
|
|
115834
115880
|
const d = read3[n];
|
|
115835
115881
|
if (!d.ok) return d.code === "not_found" ? [] : [{ ...c, title: "", goals: 0, offline: true }];
|
|
115836
|
-
return [{ ...c, dir: home3(c.dir), title: d.value.title, goals:
|
|
115882
|
+
return [{ ...c, dir: home3(c.dir), title: d.value.title, goals: d.value.goals.length, at: d.value.updated_at }];
|
|
115837
115883
|
})
|
|
115838
115884
|
};
|
|
115839
115885
|
}
|
|
@@ -115925,7 +115971,8 @@ var GoalInput = import_zod3.z.object({
|
|
|
115925
115971
|
studio: import_zod3.z.string().describe("One of the studio ids wildcrane_draft_read lists."),
|
|
115926
115972
|
review_plan: reviewPlanSchema.optional()
|
|
115927
115973
|
});
|
|
115928
|
-
var linked = (
|
|
115974
|
+
var linked = (id2, goals) => goals.map(goalOf).map((goal) => ({ ...goal, url: goal.task?.url ?? discussionUrl(id2) }));
|
|
115975
|
+
var draftText = (draft) => text2({ ...draft, ideas: draft.goals });
|
|
115929
115976
|
var PROCESS = `process-${crypto10.randomUUID()}`;
|
|
115930
115977
|
var threadOf = (meta4) => {
|
|
115931
115978
|
if (host === "opencode" && (typeof meta4?.threadId !== "string" || !meta4.threadId.trim())) throw new Error("OpenCode session identity is missing. Reload the WildCrane plugin and retry.");
|
|
@@ -115953,12 +116000,10 @@ function server() {
|
|
|
115953
116000
|
if (goals === void 0 === (ideas === void 0)) return { ...text2({ error: "bad_request", message: "Provide exactly one of goals or ideas." }), isError: true };
|
|
115954
116001
|
const saved = await saveDraft(discussionId, expectedVersion, goals ?? ideas);
|
|
115955
116002
|
if (saved.ok) {
|
|
115956
|
-
|
|
115957
|
-
return text2({ saved: true, url: discussionUrl(discussionId), version: saved.value.version, goals: out, ideas: out });
|
|
116003
|
+
return draftText({ saved: true, url: discussionUrl(discussionId), version: saved.value.version, goals: linked(discussionId, saved.value.goals) });
|
|
115958
116004
|
}
|
|
115959
116005
|
if (saved.discussion) {
|
|
115960
|
-
|
|
115961
|
-
return text2({ saved: false, reason: "The goals have changed. Merge your changes with the latest goals and save again.", url: discussionUrl(discussionId), version: saved.discussion.version, goals: out, ideas: out });
|
|
116006
|
+
return draftText({ saved: false, reason: "The goals have changed. Merge your changes with the latest goals and save again.", url: discussionUrl(discussionId), version: saved.discussion.version, goals: linked(discussionId, saved.discussion.goals) });
|
|
115962
116007
|
}
|
|
115963
116008
|
return { ...text2({ saved: false, ...failure4(saved) }), isError: true };
|
|
115964
116009
|
};
|
|
@@ -115993,11 +116038,8 @@ function server() {
|
|
|
115993
116038
|
const name = list3.ok ? list3.value.folders.find((f) => f.project === draft.project)?.name : void 0;
|
|
115994
116039
|
project = { name: name ?? draft.project, board: boardUrl(draft.project) };
|
|
115995
116040
|
}
|
|
115996
|
-
return
|
|
116041
|
+
return draftText({
|
|
115997
116042
|
...draft,
|
|
115998
|
-
url: discussionUrl(id2),
|
|
115999
|
-
goals: linked({ id: id2 }, draft.goals ?? draft.ideas),
|
|
116000
|
-
ideas: linked({ id: id2 }, draft.goals ?? draft.ideas),
|
|
116001
116043
|
project,
|
|
116002
116044
|
...akbFile2 ? { akb: akbFile2 } : {},
|
|
116003
116045
|
...project ? {} : { note: "This folder is not a WildCrane project: goals go to General. The user can ask to add it." }
|
|
@@ -116060,9 +116102,9 @@ function server() {
|
|
|
116060
116102
|
}
|
|
116061
116103
|
}, async ({ discussionId, sessionId }) => {
|
|
116062
116104
|
if (!readSession()) return { ...text2(PANEL_SIGNED_OUT), isError: true };
|
|
116063
|
-
if (discussionId) return text2(
|
|
116064
|
-
|
|
116065
|
-
return text2(
|
|
116105
|
+
if (!discussionId && !sessionId) return { ...text2({ error: "bad_request", message: "Give discussionId or sessionId." }), isError: true };
|
|
116106
|
+
const draft = discussionId ? await draftOf(discussionId) : await sessionDraft(sessionId, process.cwd());
|
|
116107
|
+
return "error" in draft ? text2(draft) : draftText(draft);
|
|
116066
116108
|
});
|
|
116067
116109
|
mcp.registerTool("wildcrane_draft_save", { description: saveWhat, inputSchema: saveSchema }, save);
|
|
116068
116110
|
mcp.registerTool("wildcrane_panel", {
|