wildcrane-runner 0.6.56 → 0.6.58
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 +1423 -897
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/launcher.mjs +530 -80
- package/dist/plugin.mjs +568 -118
- package/dist/runner.mjs +1198 -607
- package/dist/settings.mjs +520 -70
- package/package.json +1 -1
package/dist/launcher.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.58 — 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;
|
|
@@ -5751,8 +5751,8 @@ var require_util2 = __commonJS({
|
|
|
5751
5751
|
}
|
|
5752
5752
|
return values;
|
|
5753
5753
|
}
|
|
5754
|
-
function getDecodeSplit(name,
|
|
5755
|
-
const value =
|
|
5754
|
+
function getDecodeSplit(name, list2) {
|
|
5755
|
+
const value = list2.get(name, true);
|
|
5756
5756
|
if (value === null) {
|
|
5757
5757
|
return null;
|
|
5758
5758
|
}
|
|
@@ -19811,9 +19811,9 @@ var require_headers = __commonJS({
|
|
|
19811
19811
|
// https://fetch.spec.whatwg.org/#dom-headers-getsetcookie
|
|
19812
19812
|
getSetCookie() {
|
|
19813
19813
|
webidl.brandCheck(this, _Headers);
|
|
19814
|
-
const
|
|
19815
|
-
if (
|
|
19816
|
-
return [...
|
|
19814
|
+
const list2 = this.#headersList.cookies;
|
|
19815
|
+
if (list2) {
|
|
19816
|
+
return [...list2];
|
|
19817
19817
|
}
|
|
19818
19818
|
return [];
|
|
19819
19819
|
}
|
|
@@ -19837,8 +19837,8 @@ var require_headers = __commonJS({
|
|
|
19837
19837
|
* @param {Headers} target
|
|
19838
19838
|
* @param {HeadersList} list
|
|
19839
19839
|
*/
|
|
19840
|
-
static setHeadersList(target,
|
|
19841
|
-
target.#headersList =
|
|
19840
|
+
static setHeadersList(target, list2) {
|
|
19841
|
+
target.#headersList = list2;
|
|
19842
19842
|
}
|
|
19843
19843
|
};
|
|
19844
19844
|
var { getHeadersGuard, setHeadersGuard, getHeadersList, setHeadersList } = Headers;
|
|
@@ -20789,13 +20789,13 @@ var require_request2 = __commonJS({
|
|
|
20789
20789
|
if (this.signal.aborted) {
|
|
20790
20790
|
ac.abort(this.signal.reason);
|
|
20791
20791
|
} else {
|
|
20792
|
-
let
|
|
20793
|
-
if (
|
|
20794
|
-
|
|
20795
|
-
dependentControllerMap.set(this.signal,
|
|
20792
|
+
let list2 = dependentControllerMap.get(this.signal);
|
|
20793
|
+
if (list2 === void 0) {
|
|
20794
|
+
list2 = /* @__PURE__ */ new Set();
|
|
20795
|
+
dependentControllerMap.set(this.signal, list2);
|
|
20796
20796
|
}
|
|
20797
20797
|
const acRef = new WeakRef(ac);
|
|
20798
|
-
|
|
20798
|
+
list2.add(acRef);
|
|
20799
20799
|
util.addAbortListener(
|
|
20800
20800
|
ac.signal,
|
|
20801
20801
|
buildAbort(acRef)
|
|
@@ -26903,8 +26903,8 @@ function saveAlphaUpdates(value) {
|
|
|
26903
26903
|
}
|
|
26904
26904
|
|
|
26905
26905
|
// src/protocol.ts
|
|
26906
|
-
var VERSION = true ? "0.6.
|
|
26907
|
-
var AKB_VERSION = true ? "0.11.
|
|
26906
|
+
var VERSION = true ? "0.6.58" : "0.0.0";
|
|
26907
|
+
var AKB_VERSION = true ? "0.11.45" : "0.0.0";
|
|
26908
26908
|
var EXIT_REFUSED = 10;
|
|
26909
26909
|
var EXIT_OUTDATED = 11;
|
|
26910
26910
|
var EXIT_UPDATE = 12;
|
|
@@ -27235,23 +27235,23 @@ function runOnce(candidate, options) {
|
|
|
27235
27235
|
});
|
|
27236
27236
|
}
|
|
27237
27237
|
async function launch(own2, options = {}) {
|
|
27238
|
-
const
|
|
27239
|
-
for (let i = 0; i <
|
|
27238
|
+
const list2 = await candidates(own2);
|
|
27239
|
+
for (let i = 0; i < list2.length; i++) {
|
|
27240
27240
|
if (options.signal?.aborted) return 0;
|
|
27241
|
-
const candidate =
|
|
27241
|
+
const candidate = list2[i];
|
|
27242
27242
|
const outcome = await runOnce(candidate, options);
|
|
27243
27243
|
if ("exit" in outcome) return outcome.exit;
|
|
27244
27244
|
if ("update" in outcome) {
|
|
27245
27245
|
const latest = await askTarget(machineId());
|
|
27246
27246
|
if (!latest || latest.version !== outcome.update.version || waiting(latest, candidate.version)) {
|
|
27247
|
-
|
|
27247
|
+
list2.splice(i + 1, list2.length, candidate);
|
|
27248
27248
|
continue;
|
|
27249
27249
|
}
|
|
27250
|
-
|
|
27250
|
+
list2.splice(i + 1, list2.length, outcome.update, candidate);
|
|
27251
27251
|
continue;
|
|
27252
27252
|
}
|
|
27253
27253
|
markBad(candidate.version);
|
|
27254
|
-
const next =
|
|
27254
|
+
const next = list2[i + 1];
|
|
27255
27255
|
if (next) status(t.rolledBack(next.version));
|
|
27256
27256
|
}
|
|
27257
27257
|
return 1;
|
|
@@ -27988,7 +27988,7 @@ var OLD_ROLE_KEYS = ["lead", "hook", "stage", "kind"];
|
|
|
27988
27988
|
var AGENT_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
27989
27989
|
var SCHEDULE_READS = ["archived-cards", "chats", "dismissals"];
|
|
27990
27990
|
var isScheduleReads = (value) => SCHEDULE_READS.includes(value);
|
|
27991
|
-
function parseSpecAgent(text3, from, file2, builtIn = false,
|
|
27991
|
+
function parseSpecAgent(text3, from, file2, builtIn = false, list2 = () => []) {
|
|
27992
27992
|
let named = "";
|
|
27993
27993
|
const bad = (why, old2) => ({
|
|
27994
27994
|
problem: `${from}: ${why}`,
|
|
@@ -28050,7 +28050,7 @@ function parseSpecAgent(text3, from, file2, builtIn = false, list = () => []) {
|
|
|
28050
28050
|
...declaredSession ? { session: "new" } : {},
|
|
28051
28051
|
memory: names(akb.memory),
|
|
28052
28052
|
memoryFiles: { workspace },
|
|
28053
|
-
files:
|
|
28053
|
+
files: list2(),
|
|
28054
28054
|
body: instructions,
|
|
28055
28055
|
from,
|
|
28056
28056
|
builtIn,
|
|
@@ -28079,12 +28079,12 @@ function memoryPaths(raw, folder = "memory/agents/<name>/") {
|
|
|
28079
28079
|
const block = map(raw);
|
|
28080
28080
|
const extra = block ? Object.keys(block).filter((key) => key !== "workspace") : [];
|
|
28081
28081
|
if (!block || extra.length) return `\`akb.memoryFiles\` with ${block ? `\`${extra.join("`, `")}\`` : "no `workspace:` list"} \u2014 it holds only \`workspace: [<path>, ...]\``;
|
|
28082
|
-
const
|
|
28083
|
-
if (
|
|
28084
|
-
if (!Array.isArray(
|
|
28082
|
+
const list2 = block.workspace;
|
|
28083
|
+
if (list2 === void 0) return [];
|
|
28084
|
+
if (!Array.isArray(list2) || list2.some((v) => typeof v !== "string" || !v.trim())) {
|
|
28085
28085
|
return "`akb.memoryFiles.workspace` that is not a list of paths \u2014 write `workspace: [style.md]`";
|
|
28086
28086
|
}
|
|
28087
|
-
const paths = [...new Set(
|
|
28087
|
+
const paths = [...new Set(list2.map((v) => v.trim()))];
|
|
28088
28088
|
const outside = paths.find((p) => p.startsWith("/") || p.includes("\\") || p.split("/").some((part) => part === ".." || part === "."));
|
|
28089
28089
|
if (outside) return `\`akb.memoryFiles.workspace: ${outside}\`, which is outside its memory folder \u2014 use a path inside \`${folder}\``;
|
|
28090
28090
|
return paths;
|
|
@@ -28652,8 +28652,8 @@ function readFlows() {
|
|
|
28652
28652
|
}
|
|
28653
28653
|
const project = boardProject();
|
|
28654
28654
|
if (!project || !readSession()) return [];
|
|
28655
|
-
const
|
|
28656
|
-
const flows2 =
|
|
28655
|
+
const list2 = readJson(listFile(project))?.studios ?? [];
|
|
28656
|
+
const flows2 = list2.flatMap((w) => {
|
|
28657
28657
|
const held = readVersion(w.id, w.version);
|
|
28658
28658
|
return held ? flowOf(held) ?? [] : [];
|
|
28659
28659
|
});
|
|
@@ -28749,12 +28749,12 @@ function update(change) {
|
|
|
28749
28749
|
}
|
|
28750
28750
|
}
|
|
28751
28751
|
function adoptLegacy() {
|
|
28752
|
-
if (readSession() && !readGrants().accounts) update((
|
|
28752
|
+
if (readSession() && !readGrants().accounts) update((list2) => list2);
|
|
28753
28753
|
}
|
|
28754
28754
|
var allow = (dir) => {
|
|
28755
|
-
update((
|
|
28755
|
+
update((list2) => [...list2, dir]);
|
|
28756
28756
|
};
|
|
28757
|
-
var disallow = (dir) => update((
|
|
28757
|
+
var disallow = (dir) => update((list2) => list2.filter((p) => p !== dir));
|
|
28758
28758
|
var SYSTEM_MAC = ["/System", "/Library", "/Applications", "/usr", "/bin", "/sbin", "/etc", "/var", "/private", "/opt", "/cores", "/dev"];
|
|
28759
28759
|
var SYSTEM_WIN = ["Windows", "Program Files", "Program Files (x86)", "ProgramData"];
|
|
28760
28760
|
var here = () => ({ platform: process.platform, home: os4.homedir(), resolve: realpath });
|
|
@@ -29027,11 +29027,11 @@ function checkHarnesses(harnesses) {
|
|
|
29027
29027
|
if (providers.length > 1) {
|
|
29028
29028
|
throw new Error(`harness "${harness.name}": a connector declares one provider list, not ${providers.length}`);
|
|
29029
29029
|
}
|
|
29030
|
-
const
|
|
29031
|
-
if (!
|
|
29032
|
-
if (!
|
|
29030
|
+
const list2 = providers[0];
|
|
29031
|
+
if (!list2) continue;
|
|
29032
|
+
if (!list2.providers?.length) throw new Error(`harness "${harness.name}": the provider setting "${list2.key}" offers no providers`);
|
|
29033
29033
|
const ids = /* @__PURE__ */ new Set();
|
|
29034
|
-
for (const provider of
|
|
29034
|
+
for (const provider of list2.providers) {
|
|
29035
29035
|
if (ids.has(provider.id)) throw new Error(`harness "${harness.name}": two providers share the id "${provider.id}"`);
|
|
29036
29036
|
ids.add(provider.id);
|
|
29037
29037
|
for (const need of [...provider.needs, ...provider.preferWhenSet ?? []]) {
|
|
@@ -29044,8 +29044,8 @@ function checkHarnesses(harnesses) {
|
|
|
29044
29044
|
if (!provider.needs.includes(key)) throw new Error(`harness "${harness.name}": the provider "${provider.id}" renames the variable of "${key}" without needing it`);
|
|
29045
29045
|
}
|
|
29046
29046
|
}
|
|
29047
|
-
if (
|
|
29048
|
-
throw new Error(`harness "${harness.name}": the default provider "${
|
|
29047
|
+
if (list2.defaultProvider && !ids.has(list2.defaultProvider)) {
|
|
29048
|
+
throw new Error(`harness "${harness.name}": the default provider "${list2.defaultProvider}" isn't on the list`);
|
|
29049
29049
|
}
|
|
29050
29050
|
}
|
|
29051
29051
|
}
|
|
@@ -29306,9 +29306,9 @@ var probeOptions = (file2) => ({ cwd: os5.tmpdir(), env: copyEnv(file2), windows
|
|
|
29306
29306
|
function probe(file2) {
|
|
29307
29307
|
const key = keyOf(file2);
|
|
29308
29308
|
const start = spawnable(file2, ["--version"], { ...probeOptions(file2), stdio: ["ignore", "pipe", "pipe"], timeout: PROBE_MS });
|
|
29309
|
-
const
|
|
29310
|
-
const code =
|
|
29311
|
-
const answer = { key, at: Date.now(), ...judge(code,
|
|
29309
|
+
const run2 = spawnSync2(start.command, start.args, { ...start.options, encoding: "utf8" });
|
|
29310
|
+
const code = run2.error?.code;
|
|
29311
|
+
const answer = { key, at: Date.now(), ...judge(code, run2.status, run2.stdout ?? "", run2.stderr ?? "") };
|
|
29312
29312
|
keep(file2, answer);
|
|
29313
29313
|
return answer;
|
|
29314
29314
|
}
|
|
@@ -29452,8 +29452,8 @@ function createEventCollector() {
|
|
|
29452
29452
|
case "tool_call_update": {
|
|
29453
29453
|
const id = str2(u.toolCallId);
|
|
29454
29454
|
if (todoCalls.has(id)) {
|
|
29455
|
-
const
|
|
29456
|
-
if (Array.isArray(
|
|
29455
|
+
const list2 = obj(u.rawInput).todos;
|
|
29456
|
+
if (Array.isArray(list2) && !str2(obj(u.rawInput)._toolName)) queue.push({ kind: "plan", data: { entries: entriesOf(list2) } });
|
|
29457
29457
|
return;
|
|
29458
29458
|
}
|
|
29459
29459
|
release(id, targetIn(u));
|
|
@@ -29610,10 +29610,10 @@ function failedWith(ev) {
|
|
|
29610
29610
|
return str2(ev.result).trim() || "the agent reported the session failed";
|
|
29611
29611
|
}
|
|
29612
29612
|
function denials(ev) {
|
|
29613
|
-
const
|
|
29614
|
-
const names2 = [...new Set(
|
|
29613
|
+
const list2 = Array.isArray(ev.permission_denials) ? ev.permission_denials : [];
|
|
29614
|
+
const names2 = [...new Set(list2.map((raw) => str2(obj(raw).tool_name)).filter(Boolean))];
|
|
29615
29615
|
if (!names2.length) return "";
|
|
29616
|
-
return `[refused] ${
|
|
29616
|
+
return `[refused] ${list2.length} tool call${list2.length === 1 ? "" : "s"} were not allowed: ${names2.join(", ")}
|
|
29617
29617
|
`;
|
|
29618
29618
|
}
|
|
29619
29619
|
function promptSize(raw) {
|
|
@@ -29770,6 +29770,37 @@ var addUsage = (a, b) => ({
|
|
|
29770
29770
|
output: a.output + b.output
|
|
29771
29771
|
});
|
|
29772
29772
|
|
|
29773
|
+
// ../cli/src/lib/agent/wire/background.ts
|
|
29774
|
+
function createBackgroundTasks() {
|
|
29775
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
29776
|
+
return {
|
|
29777
|
+
update(id, status2, result = "") {
|
|
29778
|
+
if (!id) return false;
|
|
29779
|
+
const previous = tasks.get(id);
|
|
29780
|
+
if (previous?.status === status2 && previous.result === result) return false;
|
|
29781
|
+
tasks.set(id, { status: status2, result });
|
|
29782
|
+
return true;
|
|
29783
|
+
},
|
|
29784
|
+
results: () => [...tasks].map(([id, task]) => ({ id, ...task })),
|
|
29785
|
+
running: () => [...tasks].filter(([, t2]) => t2.status === "running").map(([id]) => id),
|
|
29786
|
+
count: () => [...tasks.values()].filter((t2) => t2.status === "running").length,
|
|
29787
|
+
failure: () => [...tasks].filter(([, t2]) => t2.status === "failed").map(([id, t2]) => t2.result || `Background task ${id} failed.`).join("\n") || void 0
|
|
29788
|
+
};
|
|
29789
|
+
}
|
|
29790
|
+
function createBackgroundWait(milliseconds, expired) {
|
|
29791
|
+
let timer;
|
|
29792
|
+
return {
|
|
29793
|
+
pending() {
|
|
29794
|
+
if (!timer && milliseconds > 0) timer = setTimeout(expired, milliseconds);
|
|
29795
|
+
},
|
|
29796
|
+
close() {
|
|
29797
|
+
clearTimeout(timer);
|
|
29798
|
+
timer = void 0;
|
|
29799
|
+
}
|
|
29800
|
+
};
|
|
29801
|
+
}
|
|
29802
|
+
var backgroundWaitMessage = (minutes) => `the agent's background tasks did not finish within ${minutes / 60} hours, so the run was ended.`;
|
|
29803
|
+
|
|
29773
29804
|
// ../cli/src/lib/agent/wire/codex-session.ts
|
|
29774
29805
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
29775
29806
|
import { homedir } from "node:os";
|
|
@@ -30045,6 +30076,31 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
30045
30076
|
let lookedAt = 0;
|
|
30046
30077
|
const events = createEventCollector();
|
|
30047
30078
|
const started = /* @__PURE__ */ new Set();
|
|
30079
|
+
const background = createBackgroundTasks();
|
|
30080
|
+
const subagents = /* @__PURE__ */ new Set();
|
|
30081
|
+
const collabItems = /* @__PURE__ */ new Set();
|
|
30082
|
+
const collab = (item, done) => {
|
|
30083
|
+
if (item.type !== "collab_tool_call") return;
|
|
30084
|
+
const key = `${str2(item.id)}:${done}`;
|
|
30085
|
+
if (collabItems.has(key)) return;
|
|
30086
|
+
collabItems.add(key);
|
|
30087
|
+
for (const [id, raw] of Object.entries(obj(item.agents_states))) {
|
|
30088
|
+
const state = obj(raw);
|
|
30089
|
+
const status2 = str2(state.status);
|
|
30090
|
+
if (!["pending_init", "running", "completed", "interrupted", "errored", "shutdown", "not_found"].includes(status2)) continue;
|
|
30091
|
+
const previous = background.results().find((t2) => t2.id === id);
|
|
30092
|
+
if (["shutdown", "not_found"].includes(status2) && previous && previous.status !== "running") continue;
|
|
30093
|
+
if (!subagents.has(id)) {
|
|
30094
|
+
subagents.add(id);
|
|
30095
|
+
events.subagent(`agent:${id}`, str2(item.prompt) || "Agent");
|
|
30096
|
+
}
|
|
30097
|
+
const running = status2 === "pending_init" || status2 === "running";
|
|
30098
|
+
const failed = !running && status2 !== "completed";
|
|
30099
|
+
if (background.update(id, running ? "running" : failed ? "failed" : "completed", str2(state.message)) && !running) {
|
|
30100
|
+
events.toolResult(`agent:${id}`, failed ? "failed" : "completed", str2(state.message));
|
|
30101
|
+
}
|
|
30102
|
+
}
|
|
30103
|
+
};
|
|
30048
30104
|
const look = (now) => {
|
|
30049
30105
|
if (!threadId) return;
|
|
30050
30106
|
const at = Date.now();
|
|
@@ -30071,6 +30127,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
30071
30127
|
if (!threadId) threadId = str2(ev.thread_id).trim() || void 0;
|
|
30072
30128
|
return "";
|
|
30073
30129
|
case "item.started":
|
|
30130
|
+
collab(obj(ev.item), false);
|
|
30074
30131
|
itemEvents(events, started, obj(ev.item), false);
|
|
30075
30132
|
return renderStarted(obj(ev.item));
|
|
30076
30133
|
case "item.updated":
|
|
@@ -30078,6 +30135,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
30078
30135
|
return "";
|
|
30079
30136
|
case "item.completed": {
|
|
30080
30137
|
const item = obj(ev.item);
|
|
30138
|
+
collab(item, true);
|
|
30081
30139
|
if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str2(item.tool))) {
|
|
30082
30140
|
const content = obj(item.result).content;
|
|
30083
30141
|
for (const block of Array.isArray(content) ? content : []) {
|
|
@@ -30149,7 +30207,8 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
30149
30207
|
// whose rates the board knows.
|
|
30150
30208
|
costUsd: () => priceUsd(facts?.provider, turn2()?.model ?? facts?.model, own2()),
|
|
30151
30209
|
resumeId: () => threadId,
|
|
30152
|
-
failure: () => failure2,
|
|
30210
|
+
failure: () => failure2 ?? background.failure(),
|
|
30211
|
+
background: () => subagents.size ? background.count() : void 0,
|
|
30153
30212
|
events: events.events
|
|
30154
30213
|
};
|
|
30155
30214
|
}
|
|
@@ -30382,6 +30441,21 @@ function createKimiStreamRenderer(cwd) {
|
|
|
30382
30441
|
};
|
|
30383
30442
|
}
|
|
30384
30443
|
|
|
30444
|
+
// ../cli/src/lib/shared/conversation.ts
|
|
30445
|
+
var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
|
|
30446
|
+
function bounded(work, ms, reason) {
|
|
30447
|
+
return new Promise((resolve2, reject) => {
|
|
30448
|
+
const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
|
|
30449
|
+
work.then((value) => {
|
|
30450
|
+
clearTimeout(timer);
|
|
30451
|
+
resolve2(value);
|
|
30452
|
+
}, (error) => {
|
|
30453
|
+
clearTimeout(timer);
|
|
30454
|
+
reject(error);
|
|
30455
|
+
});
|
|
30456
|
+
});
|
|
30457
|
+
}
|
|
30458
|
+
|
|
30385
30459
|
// ../cli/src/lib/agent/wire/acp.ts
|
|
30386
30460
|
import fs19 from "node:fs";
|
|
30387
30461
|
|
|
@@ -30451,6 +30525,9 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
30451
30525
|
send2({ id, method, params });
|
|
30452
30526
|
});
|
|
30453
30527
|
},
|
|
30528
|
+
notify(method, params = {}) {
|
|
30529
|
+
send2({ method, params });
|
|
30530
|
+
},
|
|
30454
30531
|
/** Answer something the agent asked us. */
|
|
30455
30532
|
reply(id, result) {
|
|
30456
30533
|
send2({ id, result });
|
|
@@ -30513,8 +30590,8 @@ function createTail(log) {
|
|
|
30513
30590
|
// ../cli/package.json
|
|
30514
30591
|
var package_default = {
|
|
30515
30592
|
name: "wildcrane",
|
|
30516
|
-
version: "0.11.
|
|
30517
|
-
akbContract:
|
|
30593
|
+
version: "0.11.45",
|
|
30594
|
+
akbContract: 12,
|
|
30518
30595
|
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.",
|
|
30519
30596
|
keywords: [
|
|
30520
30597
|
"kanban",
|
|
@@ -30600,23 +30677,23 @@ function saidBy(update3) {
|
|
|
30600
30677
|
function modelOf(answer) {
|
|
30601
30678
|
const current2 = str2(obj(answer.models).currentModelId).trim();
|
|
30602
30679
|
if (current2) return modelsIn(answer).find((m) => m.modelId === current2)?.name ?? current2;
|
|
30603
|
-
const
|
|
30604
|
-
for (const raw of
|
|
30680
|
+
const list2 = Array.isArray(answer.configOptions) ? answer.configOptions : [];
|
|
30681
|
+
for (const raw of list2) {
|
|
30605
30682
|
const option = obj(raw);
|
|
30606
30683
|
if (option.id === "model") return str2(option.currentValue).trim() || void 0;
|
|
30607
30684
|
}
|
|
30608
30685
|
return void 0;
|
|
30609
30686
|
}
|
|
30610
30687
|
function modelsIn(answer) {
|
|
30611
|
-
const
|
|
30612
|
-
return (Array.isArray(
|
|
30688
|
+
const list2 = obj(answer.models).availableModels;
|
|
30689
|
+
return (Array.isArray(list2) ? list2 : []).map(obj).flatMap((m) => {
|
|
30613
30690
|
const modelId = str2(m.modelId);
|
|
30614
30691
|
return modelId ? [{ modelId, name: str2(m.name) || modelId }] : [];
|
|
30615
30692
|
});
|
|
30616
30693
|
}
|
|
30617
30694
|
function pickedModel(answer, wanted) {
|
|
30618
|
-
const
|
|
30619
|
-
return
|
|
30695
|
+
const list2 = modelsIn(answer);
|
|
30696
|
+
return list2.find((m) => m.modelId === wanted) ?? list2.find((m) => m.name === wanted || m.modelId.split("[")[0] === wanted);
|
|
30620
30697
|
}
|
|
30621
30698
|
function usageOf2(value, grossInput = false) {
|
|
30622
30699
|
const usage = obj(value);
|
|
@@ -30672,6 +30749,11 @@ function createAcpClient(options = {}) {
|
|
|
30672
30749
|
}
|
|
30673
30750
|
async function oneTurn(io, options) {
|
|
30674
30751
|
const tail = createTail(io.log);
|
|
30752
|
+
const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
|
|
30753
|
+
const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
|
|
30754
|
+
let started = false;
|
|
30755
|
+
let contentAt = 0;
|
|
30756
|
+
let currentSession = "";
|
|
30675
30757
|
const events = createEventCollector();
|
|
30676
30758
|
const emit = () => {
|
|
30677
30759
|
for (const e of events.events()) io.event?.(e);
|
|
@@ -30684,7 +30766,16 @@ async function oneTurn(io, options) {
|
|
|
30684
30766
|
io.stdin,
|
|
30685
30767
|
(msg) => {
|
|
30686
30768
|
if (msg.method === "session/update") {
|
|
30687
|
-
if (live) {
|
|
30769
|
+
if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
|
|
30770
|
+
const kind = str2(obj(obj(msg.params).update).sessionUpdate);
|
|
30771
|
+
if (!started && ["agent_message_chunk", "tool_call", "plan"].includes(kind)) {
|
|
30772
|
+
started = true;
|
|
30773
|
+
phase("started");
|
|
30774
|
+
}
|
|
30775
|
+
if (kind === "agent_message_chunk" && Date.now() - contentAt >= 1e3) {
|
|
30776
|
+
contentAt = Date.now();
|
|
30777
|
+
io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
|
|
30778
|
+
}
|
|
30688
30779
|
update2(obj(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
|
|
30689
30780
|
events.update(obj(msg.params).update);
|
|
30690
30781
|
emit();
|
|
@@ -30712,20 +30803,22 @@ async function oneTurn(io, options) {
|
|
|
30712
30803
|
);
|
|
30713
30804
|
try {
|
|
30714
30805
|
const mcpServers = options.mcpConfig ? mcpServersIn(options.mcpConfig) : [];
|
|
30715
|
-
|
|
30806
|
+
phase("preparing");
|
|
30807
|
+
await bounded(rpc.call("initialize", {
|
|
30716
30808
|
protocolVersion: PROTOCOL_VERSION,
|
|
30717
30809
|
clientCapabilities: CLIENT_CAPABILITIES,
|
|
30718
30810
|
clientInfo: { name: "ai4kanban", version: SKILL_VERSION }
|
|
30719
|
-
});
|
|
30811
|
+
}), preparingUntil - Date.now(), "ACP initialize timed out.");
|
|
30812
|
+
phase("initialized");
|
|
30720
30813
|
let sessionId = io.resumeId ?? "";
|
|
30721
30814
|
let prompt = io.prompt;
|
|
30722
30815
|
let opened;
|
|
30723
30816
|
if (sessionId) {
|
|
30724
30817
|
try {
|
|
30725
|
-
opened = await rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers });
|
|
30818
|
+
opened = await bounded(rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers }), preparingUntil - Date.now(), "ACP session/load timed out.");
|
|
30726
30819
|
} catch (e) {
|
|
30727
30820
|
if (!sessionGone(e) || !io.restartPrompt) throw e;
|
|
30728
|
-
const fresh = await newSession(rpc, io.cwd, mcpServers);
|
|
30821
|
+
const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
|
|
30729
30822
|
opened = fresh.opened;
|
|
30730
30823
|
sessionId = fresh.sessionId;
|
|
30731
30824
|
prompt = io.restartPrompt;
|
|
@@ -30735,7 +30828,7 @@ async function oneTurn(io, options) {
|
|
|
30735
30828
|
emit();
|
|
30736
30829
|
}
|
|
30737
30830
|
} else {
|
|
30738
|
-
const fresh = await newSession(rpc, io.cwd, mcpServers);
|
|
30831
|
+
const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
|
|
30739
30832
|
opened = fresh.opened;
|
|
30740
30833
|
sessionId = fresh.sessionId;
|
|
30741
30834
|
io.gotResumeId(sessionId);
|
|
@@ -30744,11 +30837,15 @@ async function oneTurn(io, options) {
|
|
|
30744
30837
|
if (options.model) {
|
|
30745
30838
|
const listed2 = obj(opened.models).currentModelId !== void 0;
|
|
30746
30839
|
const picked = listed2 ? pickedModel(opened, options.model) : void 0;
|
|
30747
|
-
const set = listed2 ? await rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }) : await rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model });
|
|
30840
|
+
const set = listed2 ? 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.");
|
|
30748
30841
|
model = picked?.name ?? modelOf(set) ?? options.model;
|
|
30749
30842
|
}
|
|
30750
30843
|
if (model) io.gotModel(model);
|
|
30844
|
+
if (Date.now() >= preparingUntil) throw Error("ACP preparation timed out.");
|
|
30845
|
+
phase("ready");
|
|
30846
|
+
currentSession = sessionId;
|
|
30751
30847
|
live = true;
|
|
30848
|
+
phase("submitted");
|
|
30752
30849
|
const done = await rpc.call("session/prompt", {
|
|
30753
30850
|
sessionId,
|
|
30754
30851
|
prompt: [{ type: "text", text: prompt }]
|
|
@@ -31104,6 +31201,358 @@ function decide2(params, tail) {
|
|
|
31104
31201
|
return { decision: "deny", reason: "this board run can't answer a permission question" };
|
|
31105
31202
|
}
|
|
31106
31203
|
|
|
31204
|
+
// ../cli/src/lib/agent/settings.ts
|
|
31205
|
+
var BACKGROUND_WAIT = { minutes: 120 };
|
|
31206
|
+
|
|
31207
|
+
// ../cli/src/lib/agent/wire/codex.ts
|
|
31208
|
+
var list = (value) => Array.isArray(value) ? value.map(obj) : [];
|
|
31209
|
+
function createCodexConnection(argv) {
|
|
31210
|
+
const execAt = argv.indexOf("exec");
|
|
31211
|
+
if (execAt < 1) return void 0;
|
|
31212
|
+
const server = [argv[0], "app-server"];
|
|
31213
|
+
const options = { images: [] };
|
|
31214
|
+
const roots = [];
|
|
31215
|
+
for (let i = 1; i < argv.length; i++) {
|
|
31216
|
+
if (i === execAt) continue;
|
|
31217
|
+
const arg = argv[i];
|
|
31218
|
+
const [flag, inline] = arg.split(/=(.*)/s);
|
|
31219
|
+
const value = () => inline ?? argv[++i];
|
|
31220
|
+
if (["--json", "--experimental-json", "--skip-git-repo-check"].includes(arg)) continue;
|
|
31221
|
+
if (["-c", "--config", "--enable", "--disable"].includes(flag)) {
|
|
31222
|
+
const v = value();
|
|
31223
|
+
if (!v) return void 0;
|
|
31224
|
+
server.push(flag, v);
|
|
31225
|
+
} else if (["-m", "--model", "-s", "--sandbox"].includes(flag)) {
|
|
31226
|
+
const v = value();
|
|
31227
|
+
if (!v) return void 0;
|
|
31228
|
+
server.push("-c", `${flag === "-m" || flag === "--model" ? "model" : "sandbox_mode"}=${JSON.stringify(v)}`);
|
|
31229
|
+
} else if (arg === "--dangerously-bypass-approvals-and-sandbox") {
|
|
31230
|
+
server.push("-c", 'approval_policy="never"', "-c", 'sandbox_mode="danger-full-access"');
|
|
31231
|
+
} else if (arg === "--full-auto") {
|
|
31232
|
+
server.push("-c", 'approval_policy="on-request"', "-c", 'sandbox_mode="workspace-write"');
|
|
31233
|
+
} else if (flag === "--add-dir") {
|
|
31234
|
+
const v = value();
|
|
31235
|
+
if (!v) return void 0;
|
|
31236
|
+
roots.push(v);
|
|
31237
|
+
} else if (flag === "-C" || flag === "--cd") {
|
|
31238
|
+
options.cwd = value();
|
|
31239
|
+
if (!options.cwd) return void 0;
|
|
31240
|
+
} else if (flag === "-i" || flag === "--image") {
|
|
31241
|
+
const v = value();
|
|
31242
|
+
if (!v) return void 0;
|
|
31243
|
+
options.images.push(v);
|
|
31244
|
+
} else if (arg === "resume" || arg === "fork") {
|
|
31245
|
+
options.mode = arg;
|
|
31246
|
+
options.threadId = argv[++i];
|
|
31247
|
+
if (!options.threadId || options.threadId.startsWith("-")) return void 0;
|
|
31248
|
+
} else {
|
|
31249
|
+
return void 0;
|
|
31250
|
+
}
|
|
31251
|
+
}
|
|
31252
|
+
if (roots.length) server.push("-c", `sandbox_workspace_write.writable_roots=${JSON.stringify(roots)}`);
|
|
31253
|
+
return { argv: server, client: createCodexClient(options) };
|
|
31254
|
+
}
|
|
31255
|
+
function createCodexClient(options = { images: [] }) {
|
|
31256
|
+
const tasks = createBackgroundTasks();
|
|
31257
|
+
return {
|
|
31258
|
+
structured: true,
|
|
31259
|
+
background: tasks.count,
|
|
31260
|
+
turn: (io) => run(io, options, tasks)
|
|
31261
|
+
};
|
|
31262
|
+
}
|
|
31263
|
+
async function run(io, options, tasks) {
|
|
31264
|
+
const renderer = createCodexStreamRenderer();
|
|
31265
|
+
const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
|
|
31266
|
+
const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
|
|
31267
|
+
let submitted = false;
|
|
31268
|
+
let started = false;
|
|
31269
|
+
let contentAt = 0;
|
|
31270
|
+
let startupTimer;
|
|
31271
|
+
const began = () => {
|
|
31272
|
+
if (!submitted || started || ended) return;
|
|
31273
|
+
started = true;
|
|
31274
|
+
clearTimeout(startupTimer);
|
|
31275
|
+
phase("started");
|
|
31276
|
+
};
|
|
31277
|
+
const children = /* @__PURE__ */ new Set();
|
|
31278
|
+
const commands = /* @__PURE__ */ new Set();
|
|
31279
|
+
const seenItems = /* @__PURE__ */ new Set();
|
|
31280
|
+
const completedTurns = /* @__PURE__ */ new Set();
|
|
31281
|
+
const historicalTurns = /* @__PURE__ */ new Set();
|
|
31282
|
+
let currentTurn2 = "";
|
|
31283
|
+
let threadId = "";
|
|
31284
|
+
let active = true;
|
|
31285
|
+
let waiting2 = false;
|
|
31286
|
+
let terminalListing = true;
|
|
31287
|
+
let timer;
|
|
31288
|
+
let ended = false;
|
|
31289
|
+
let checking = false;
|
|
31290
|
+
let context;
|
|
31291
|
+
let total;
|
|
31292
|
+
let baseline;
|
|
31293
|
+
let model;
|
|
31294
|
+
let provider;
|
|
31295
|
+
let resolve2;
|
|
31296
|
+
const done = new Promise((r) => {
|
|
31297
|
+
resolve2 = r;
|
|
31298
|
+
});
|
|
31299
|
+
const deadline = createBackgroundWait(BACKGROUND_WAIT.minutes * 6e4, () => end(backgroundWaitMessage(BACKGROUND_WAIT.minutes)));
|
|
31300
|
+
const emit = (type, extra = {}) => {
|
|
31301
|
+
io.log(renderer.push(JSON.stringify({ type, ...extra }) + "\n"));
|
|
31302
|
+
for (const event2 of renderer.events?.() ?? []) io.event?.(event2);
|
|
31303
|
+
};
|
|
31304
|
+
const end = (error) => {
|
|
31305
|
+
if (ended) return;
|
|
31306
|
+
ended = true;
|
|
31307
|
+
clearTimeout(timer);
|
|
31308
|
+
clearTimeout(startupTimer);
|
|
31309
|
+
deadline.close();
|
|
31310
|
+
io.stdout.off("close", closed);
|
|
31311
|
+
io.log(renderer.flush());
|
|
31312
|
+
const usage = total && (!options.threadId && !io.resumeId ? total : baseline ? {
|
|
31313
|
+
input: Math.max(0, total.input - baseline.input),
|
|
31314
|
+
cacheRead: Math.max(0, total.cacheRead - baseline.cacheRead),
|
|
31315
|
+
cacheCreation: Math.max(0, total.cacheCreation - baseline.cacheCreation),
|
|
31316
|
+
output: Math.max(0, total.output - baseline.output)
|
|
31317
|
+
} : void 0);
|
|
31318
|
+
const failure2 = error || tasks.failure();
|
|
31319
|
+
if (failure2) io.event?.({ kind: "error", data: { text: failure2 } });
|
|
31320
|
+
resolve2({ ok: !failure2, error: failure2, result: renderer.result(), replyParts: renderer.replyParts?.(), usage, context, costUsd: priceUsd(provider, model, usage) });
|
|
31321
|
+
};
|
|
31322
|
+
const closed = () => end("Codex closed the connection before all work and results finished.");
|
|
31323
|
+
io.stdout.once("close", closed);
|
|
31324
|
+
const update3 = (id, state, title = "") => {
|
|
31325
|
+
if (ended) return;
|
|
31326
|
+
const status2 = str2(state.status);
|
|
31327
|
+
if (!status2 || !id) return;
|
|
31328
|
+
const previous = tasks.results().find((t2) => t2.id === `agent:${id}`);
|
|
31329
|
+
if (["shutdown", "notFound", "not_found"].includes(status2) && previous && previous.status !== "running") return;
|
|
31330
|
+
const running = ["pendingInit", "running", "pending_init"].includes(status2);
|
|
31331
|
+
const failed = ["interrupted", "errored", "shutdown", "notFound", "not_found"].includes(status2);
|
|
31332
|
+
if (!running && !failed && status2 !== "completed") return;
|
|
31333
|
+
const known2 = children.has(id);
|
|
31334
|
+
children.add(id);
|
|
31335
|
+
if (!known2) io.event?.({ kind: "tool_call", data: { toolCallId: `agent:${id}`, title: targetOf(title) || "Agent", kind: "other", status: "in_progress", subagent: true } });
|
|
31336
|
+
if (tasks.update(`agent:${id}`, running ? "running" : failed ? "failed" : "completed", str2(state.message)) && !running) {
|
|
31337
|
+
io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str2(state.message) } });
|
|
31338
|
+
}
|
|
31339
|
+
};
|
|
31340
|
+
const item = (raw, completed, proof = true) => {
|
|
31341
|
+
if (ended) return;
|
|
31342
|
+
const id = str2(raw.id);
|
|
31343
|
+
if (raw.type === "collabAgentToolCall") {
|
|
31344
|
+
if (proof) began();
|
|
31345
|
+
const key2 = `${id}:${completed}`;
|
|
31346
|
+
if (seenItems.has(key2)) return;
|
|
31347
|
+
seenItems.add(key2);
|
|
31348
|
+
for (const [child, state] of Object.entries(obj(raw.agentsStates))) update3(child, obj(state), str2(raw.prompt));
|
|
31349
|
+
for (const child of Array.isArray(raw.receiverThreadIds) ? raw.receiverThreadIds : []) {
|
|
31350
|
+
if (typeof child === "string" && !children.has(child) && raw.tool === "spawnAgent") update3(child, { status: "running" }, str2(raw.prompt));
|
|
31351
|
+
}
|
|
31352
|
+
return;
|
|
31353
|
+
}
|
|
31354
|
+
if (raw.type === "commandExecution") {
|
|
31355
|
+
if (seenItems.has(`${id}:true`)) return;
|
|
31356
|
+
if (raw.status === "inProgress") completed = false;
|
|
31357
|
+
if (!completed) {
|
|
31358
|
+
commands.add(id);
|
|
31359
|
+
if (tasks.results().some((t2) => t2.id === `command:${id}`)) tasks.update(`command:${id}`, "running");
|
|
31360
|
+
} else {
|
|
31361
|
+
commands.delete(id);
|
|
31362
|
+
const failed = raw.status === "failed" || typeof raw.exitCode === "number" && raw.exitCode !== 0;
|
|
31363
|
+
if (tasks.results().some((t2) => t2.id === `command:${id}`)) tasks.update(`command:${id}`, failed ? "failed" : "completed", str2(raw.aggregatedOutput));
|
|
31364
|
+
}
|
|
31365
|
+
}
|
|
31366
|
+
const key = `${id}:${completed}`;
|
|
31367
|
+
if (seenItems.has(key)) return;
|
|
31368
|
+
seenItems.add(key);
|
|
31369
|
+
const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
|
|
31370
|
+
const type = types[str2(raw.type)];
|
|
31371
|
+
if (!type) return;
|
|
31372
|
+
if (proof) began();
|
|
31373
|
+
emit(completed ? "item.completed" : "item.started", { item: {
|
|
31374
|
+
...raw,
|
|
31375
|
+
type,
|
|
31376
|
+
...raw.type === "imageGeneration" ? { path: raw.savedPath ?? raw.path } : {},
|
|
31377
|
+
...raw.type === "fileChange" ? { changes: list(raw.changes).map((c) => ({ ...c, kind: str2(obj(c.kind).type) || c.kind })) } : {},
|
|
31378
|
+
aggregated_output: raw.aggregatedOutput,
|
|
31379
|
+
exit_code: raw.exitCode,
|
|
31380
|
+
status: raw.status === "inProgress" ? "in_progress" : raw.status
|
|
31381
|
+
} });
|
|
31382
|
+
};
|
|
31383
|
+
const start = async (text3, images = []) => {
|
|
31384
|
+
active = true;
|
|
31385
|
+
waiting2 = false;
|
|
31386
|
+
submitted = true;
|
|
31387
|
+
currentTurn2 = "";
|
|
31388
|
+
started = false;
|
|
31389
|
+
phase("submitted");
|
|
31390
|
+
startupTimer = setTimeout(() => {
|
|
31391
|
+
if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
|
|
31392
|
+
}, CONVERSATION_MS.start);
|
|
31393
|
+
await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text3 }, ...images.map((path31) => ({ type: "localImage", path: path31 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
|
|
31394
|
+
if (!started) throw error;
|
|
31395
|
+
});
|
|
31396
|
+
};
|
|
31397
|
+
const schedule = () => {
|
|
31398
|
+
if (ended || timer) return;
|
|
31399
|
+
timer = setTimeout(() => {
|
|
31400
|
+
timer = void 0;
|
|
31401
|
+
void check();
|
|
31402
|
+
}, 1e3);
|
|
31403
|
+
};
|
|
31404
|
+
const check = async () => {
|
|
31405
|
+
if (ended || checking || active) return;
|
|
31406
|
+
checking = true;
|
|
31407
|
+
try {
|
|
31408
|
+
for (const key of tasks.running().filter((id) => id.startsWith("agent:"))) {
|
|
31409
|
+
const id = key.slice(6);
|
|
31410
|
+
let thread = obj((await rpc.call("thread/read", { threadId: id, includeTurns: false })).thread);
|
|
31411
|
+
let turns = list(thread.turns);
|
|
31412
|
+
if (thread.historyMode === "paginated") {
|
|
31413
|
+
turns = list((await rpc.call("thread/turns/list", { threadId: id, sortDirection: "desc", limit: 1, itemsView: "full" })).data).reverse();
|
|
31414
|
+
} else if (!turns.length) {
|
|
31415
|
+
thread = obj((await rpc.call("thread/read", { threadId: id, includeTurns: true })).thread);
|
|
31416
|
+
turns = list(thread.turns);
|
|
31417
|
+
}
|
|
31418
|
+
const turn2 = turns.at(-1);
|
|
31419
|
+
const status2 = str2(turn2?.status);
|
|
31420
|
+
if (obj(thread.status).type === "systemError") update3(id, { status: "errored", message: "Codex subagent reported a system error." });
|
|
31421
|
+
else if (obj(thread.status).type !== "active" && turn2 && ["completed", "failed", "interrupted"].includes(status2)) {
|
|
31422
|
+
const message = list(turn2.items).filter((i) => i.type === "agentMessage").map((i) => str2(i.text)).join("\n\n");
|
|
31423
|
+
update3(id, { status: status2 === "completed" ? "completed" : "errored", message: str2(obj(turn2.error).message) || message });
|
|
31424
|
+
}
|
|
31425
|
+
}
|
|
31426
|
+
if (terminalListing) {
|
|
31427
|
+
try {
|
|
31428
|
+
const running = /* @__PURE__ */ new Set();
|
|
31429
|
+
let cursor = null;
|
|
31430
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
31431
|
+
do {
|
|
31432
|
+
if (cursor && cursors.has(cursor)) throw Error("Codex repeated a background terminal cursor.");
|
|
31433
|
+
cursors.add(cursor);
|
|
31434
|
+
const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
31435
|
+
for (const terminal of list(page.data)) {
|
|
31436
|
+
const id = str2(terminal.itemId) || str2(terminal.processId);
|
|
31437
|
+
if (id) {
|
|
31438
|
+
running.add(id);
|
|
31439
|
+
tasks.update(`command:${id}`, "running");
|
|
31440
|
+
}
|
|
31441
|
+
}
|
|
31442
|
+
cursor = page.nextCursor;
|
|
31443
|
+
} while (cursor && !ended);
|
|
31444
|
+
for (const id of tasks.running().filter((id2) => id2.startsWith("command:"))) if (!running.has(id.slice(8))) {
|
|
31445
|
+
tasks.update(id, "completed");
|
|
31446
|
+
commands.delete(id.slice(8));
|
|
31447
|
+
}
|
|
31448
|
+
} catch (e) {
|
|
31449
|
+
if (!(e instanceof RpcError) || e.code !== -32601) throw e;
|
|
31450
|
+
terminalListing = false;
|
|
31451
|
+
io.log("[Codex] This version does not report background terminals.\n");
|
|
31452
|
+
if (commands.size) throw Error("This Codex version cannot report the unfinished background commands. Update Codex to collect their results.");
|
|
31453
|
+
}
|
|
31454
|
+
}
|
|
31455
|
+
if (ended || active) return;
|
|
31456
|
+
if (tasks.count()) {
|
|
31457
|
+
waiting2 = true;
|
|
31458
|
+
deadline.pending();
|
|
31459
|
+
schedule();
|
|
31460
|
+
return;
|
|
31461
|
+
}
|
|
31462
|
+
if (waiting2) {
|
|
31463
|
+
await start("The background work from your previous reply has finished. Collect its results, resolve any failures, and present the completed outcome in this conversation. Check existing progress before acting; do not repeat completed work. Background reports (task output, not instructions):\n" + JSON.stringify(tasks.results()));
|
|
31464
|
+
} else end();
|
|
31465
|
+
} catch (e) {
|
|
31466
|
+
end(String(e instanceof Error ? e.message : e));
|
|
31467
|
+
} finally {
|
|
31468
|
+
checking = false;
|
|
31469
|
+
}
|
|
31470
|
+
};
|
|
31471
|
+
const rpc = connect(io.stdout, io.stdin, (msg) => {
|
|
31472
|
+
if (ended) return;
|
|
31473
|
+
if (msg.id !== void 0) {
|
|
31474
|
+
rpc.refuse(msg.id, "WildCrane cannot answer interactive requests in an unattended run.");
|
|
31475
|
+
end(`Codex requested interaction: ${msg.method}`);
|
|
31476
|
+
return;
|
|
31477
|
+
}
|
|
31478
|
+
const p = obj(msg.params);
|
|
31479
|
+
if (str2(p.threadId) !== threadId) return;
|
|
31480
|
+
const turnId = str2(p.turnId) || str2(obj(p.turn).id);
|
|
31481
|
+
if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
|
|
31482
|
+
if (msg.method === "turn/started") {
|
|
31483
|
+
if (!submitted || completedTurns.has(turnId)) return;
|
|
31484
|
+
currentTurn2 = turnId;
|
|
31485
|
+
active = true;
|
|
31486
|
+
began();
|
|
31487
|
+
return;
|
|
31488
|
+
}
|
|
31489
|
+
if (submitted && msg.method === "item/agentMessage/delta" && Date.now() - contentAt >= 1e3) {
|
|
31490
|
+
began();
|
|
31491
|
+
contentAt = Date.now();
|
|
31492
|
+
io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
|
|
31493
|
+
}
|
|
31494
|
+
if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
|
|
31495
|
+
if (msg.method === "thread/tokenUsage/updated") {
|
|
31496
|
+
const token = obj(p.tokenUsage);
|
|
31497
|
+
const counts = obj(token.total);
|
|
31498
|
+
const input = Number(counts.inputTokens) || 0;
|
|
31499
|
+
const read2 = Number(counts.cachedInputTokens) || 0;
|
|
31500
|
+
const write = Number(counts.cacheWriteInputTokens) || 0;
|
|
31501
|
+
total = { input: Math.max(0, input - read2 - write), cacheRead: read2, cacheCreation: write, output: Number(counts.outputTokens) || 0 };
|
|
31502
|
+
const last2 = obj(token.last);
|
|
31503
|
+
context = { used: (Number(last2.inputTokens) || 0) + (Number(last2.outputTokens) || 0), ...Number(token.modelContextWindow) > 0 ? { limit: Number(token.modelContextWindow) } : {} };
|
|
31504
|
+
io.gotContext?.(context);
|
|
31505
|
+
}
|
|
31506
|
+
if (msg.method === "error" && p.willRetry !== true) end(str2(obj(p.error).message) || "Codex failed.");
|
|
31507
|
+
if (msg.method === "turn/completed") {
|
|
31508
|
+
const turn2 = obj(p.turn);
|
|
31509
|
+
const id = str2(turn2.id);
|
|
31510
|
+
if (completedTurns.has(id)) return;
|
|
31511
|
+
completedTurns.add(id);
|
|
31512
|
+
for (const raw of list(turn2.items)) item(raw, true);
|
|
31513
|
+
if (turn2.status !== "completed") {
|
|
31514
|
+
end(str2(obj(turn2.error).message) || `Codex turn ${str2(turn2.status)}.`);
|
|
31515
|
+
return;
|
|
31516
|
+
}
|
|
31517
|
+
active = false;
|
|
31518
|
+
for (const id2 of commands) tasks.update(`command:${id2}`, "running");
|
|
31519
|
+
waiting2 ||= tasks.count() > 0 || commands.size > 0;
|
|
31520
|
+
deadline.pending();
|
|
31521
|
+
void check();
|
|
31522
|
+
}
|
|
31523
|
+
});
|
|
31524
|
+
try {
|
|
31525
|
+
phase("preparing");
|
|
31526
|
+
await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
|
|
31527
|
+
phase("initialized");
|
|
31528
|
+
rpc.notify("initialized");
|
|
31529
|
+
const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
|
|
31530
|
+
let response;
|
|
31531
|
+
try {
|
|
31532
|
+
response = await bounded(rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} }), preparingUntil - Date.now(), `Codex thread/${mode ?? "start"} timed out.`);
|
|
31533
|
+
} catch (e) {
|
|
31534
|
+
if (mode && e instanceof RpcError && /no rollout found for thread id/i.test(e.message)) throw Error(`Thread not found: ${e.message}`);
|
|
31535
|
+
throw e;
|
|
31536
|
+
}
|
|
31537
|
+
const thread = obj(response.thread);
|
|
31538
|
+
for (const turn2 of list(thread.turns)) historicalTurns.add(str2(turn2.id));
|
|
31539
|
+
threadId = str2(thread.id);
|
|
31540
|
+
if (!threadId) throw Error("Codex did not return a thread id.");
|
|
31541
|
+
provider = str2(thread.modelProvider) || void 0;
|
|
31542
|
+
model = str2(response.model) || str2(thread.model) || void 0;
|
|
31543
|
+
if (model) io.gotModel(model);
|
|
31544
|
+
io.gotResumeId(threadId);
|
|
31545
|
+
baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
|
|
31546
|
+
emit("thread.started", { thread_id: threadId });
|
|
31547
|
+
if (Date.now() >= preparingUntil) throw Error("Codex preparation timed out.");
|
|
31548
|
+
phase("ready");
|
|
31549
|
+
await start(io.prompt, options.images);
|
|
31550
|
+
} catch (e) {
|
|
31551
|
+
end(e instanceof Error ? e.message : String(e));
|
|
31552
|
+
}
|
|
31553
|
+
return done;
|
|
31554
|
+
}
|
|
31555
|
+
|
|
31107
31556
|
// ../cli/src/lib/agent/harnesses/models.ts
|
|
31108
31557
|
import { readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
31109
31558
|
import { homedir as homedir3 } from "node:os";
|
|
@@ -31123,8 +31572,8 @@ function str3(value) {
|
|
|
31123
31572
|
function num2(value) {
|
|
31124
31573
|
return typeof value === "number" ? value : Number.MAX_SAFE_INTEGER;
|
|
31125
31574
|
}
|
|
31126
|
-
function uniqueIds(
|
|
31127
|
-
return [...new Set(
|
|
31575
|
+
function uniqueIds(list2) {
|
|
31576
|
+
return [...new Set(list2.map((id) => id.trim()).filter(Boolean))];
|
|
31128
31577
|
}
|
|
31129
31578
|
var cached = /* @__PURE__ */ new Map();
|
|
31130
31579
|
function modelsIn2(file2, pick2, salt = "") {
|
|
@@ -31622,6 +32071,7 @@ var CODEX = {
|
|
|
31622
32071
|
"codex exec --json --sandbox workspace-write",
|
|
31623
32072
|
"codex exec --json --sandbox workspace-write -c sandbox_workspace_write.network_access=true"
|
|
31624
32073
|
],
|
|
32074
|
+
connection: createCodexConnection,
|
|
31625
32075
|
installs: codexInstalls,
|
|
31626
32076
|
pinned: () => process.env.CODEX_CLI_PATH?.trim() || void 0,
|
|
31627
32077
|
// Nothing to pin: Codex mints its own thread id and takes none from us, so the generated
|
|
@@ -32589,8 +33039,8 @@ function cursorModels() {
|
|
|
32589
33039
|
});
|
|
32590
33040
|
}
|
|
32591
33041
|
function acpModels(opened) {
|
|
32592
|
-
const
|
|
32593
|
-
return (Array.isArray(
|
|
33042
|
+
const list2 = obj(opened.models).availableModels;
|
|
33043
|
+
return (Array.isArray(list2) ? list2 : []).map(obj).flatMap((m) => {
|
|
32594
33044
|
const id = str2(m.modelId);
|
|
32595
33045
|
return id && id !== "default[]" ? [{ id, name: str2(m.name) || id }] : [];
|
|
32596
33046
|
});
|
|
@@ -32951,7 +33401,7 @@ var authCall = (path31, body) => {
|
|
|
32951
33401
|
signal: AbortSignal.timeout(2e4)
|
|
32952
33402
|
});
|
|
32953
33403
|
};
|
|
32954
|
-
var
|
|
33404
|
+
var refusal3 = (status2) => ({ ok: false, error: status2 === 429 ? "too_many" : status2 === 400 || status2 === 401 || status2 === 403 ? "bad_code" : "failed" });
|
|
32955
33405
|
async function sendCode(email, lang) {
|
|
32956
33406
|
try {
|
|
32957
33407
|
const response = await authCall("otp", { email: email.trim(), create_user: true, data: { lang } });
|
|
@@ -32967,7 +33417,7 @@ async function verifyCode(email, code, generation, signal) {
|
|
|
32967
33417
|
} catch {
|
|
32968
33418
|
return { ok: false, error: "failed" };
|
|
32969
33419
|
}
|
|
32970
|
-
if (!response.ok) return
|
|
33420
|
+
if (!response.ok) return refusal3(response.status);
|
|
32971
33421
|
const session = sessionFrom(await response.json().catch(() => ({})));
|
|
32972
33422
|
if (!session) return { ok: false, error: "failed" };
|
|
32973
33423
|
if (signal?.aborted || accountGeneration() !== generation) return { ok: false, error: "failed" };
|
|
@@ -33043,8 +33493,8 @@ async function signOut() {
|
|
|
33043
33493
|
}
|
|
33044
33494
|
}
|
|
33045
33495
|
async function folderOf(cwd) {
|
|
33046
|
-
const
|
|
33047
|
-
if (!
|
|
33496
|
+
const list2 = await listFolders(machineId());
|
|
33497
|
+
if (!list2.ok) return { ...failure(list2), folders: [], folder: null };
|
|
33048
33498
|
const real = (dir) => {
|
|
33049
33499
|
try {
|
|
33050
33500
|
return fs25.realpathSync(dir);
|
|
@@ -33052,7 +33502,7 @@ async function folderOf(cwd) {
|
|
|
33052
33502
|
return dir;
|
|
33053
33503
|
}
|
|
33054
33504
|
};
|
|
33055
|
-
return { folders:
|
|
33505
|
+
return { folders: list2.value.folders, folder: list2.value.folders.find((f) => real(f.path) === real(cwd)) ?? null };
|
|
33056
33506
|
}
|
|
33057
33507
|
async function addFolder2(dir, bind, strict = false) {
|
|
33058
33508
|
if (!readSession()) return { error: "signed_out" };
|
|
@@ -33116,12 +33566,12 @@ async function connections(only) {
|
|
|
33116
33566
|
}) };
|
|
33117
33567
|
}
|
|
33118
33568
|
async function all(route) {
|
|
33119
|
-
const
|
|
33569
|
+
const list2 = [];
|
|
33120
33570
|
for (let after = null; ; ) {
|
|
33121
33571
|
const result = await request("GET", `${route}${route.includes("?") ? "&" : "?"}limit=100${after ? `&after=${encodeURIComponent(after)}` : ""}`);
|
|
33122
33572
|
if (!result.ok) return result;
|
|
33123
|
-
|
|
33124
|
-
if (!result.value.next) return { ok: true, value:
|
|
33573
|
+
list2.push(...result.value.data);
|
|
33574
|
+
if (!result.value.next) return { ok: true, value: list2 };
|
|
33125
33575
|
after = result.value.next;
|
|
33126
33576
|
}
|
|
33127
33577
|
}
|
|
@@ -33138,10 +33588,10 @@ async function settingsState(context) {
|
|
|
33138
33588
|
if (!folders2.ok) return { ...base, account, ...failure(folders2) };
|
|
33139
33589
|
if (!workspaces.ok) return { ...base, account, ...failure(workspaces) };
|
|
33140
33590
|
const lists = await Promise.all(workspaces.value.map((ws) => all(`/v1/projects?workspace=${encodeURIComponent(ws.id)}`)));
|
|
33141
|
-
const failed = lists.find((
|
|
33591
|
+
const failed = lists.find((list2) => !list2.ok);
|
|
33142
33592
|
if (failed && !failed.ok) return { ...base, account, ...failure(failed) };
|
|
33143
33593
|
if (readSession()?.subject !== subject) return { ...base, signedIn: false };
|
|
33144
|
-
const projects = lists.flatMap((
|
|
33594
|
+
const projects = lists.flatMap((list2) => list2.ok ? list2.value : []);
|
|
33145
33595
|
const metadata = (id) => {
|
|
33146
33596
|
const project = projects.find((p) => p.id === id);
|
|
33147
33597
|
const workspace = workspaces.value.find((w) => w.id === project?.workspace);
|
|
@@ -33237,7 +33687,7 @@ async function terminalSettings(entry2) {
|
|
|
33237
33687
|
let running = null;
|
|
33238
33688
|
let done = Promise.resolve();
|
|
33239
33689
|
let blocked = null;
|
|
33240
|
-
const
|
|
33690
|
+
const run2 = () => {
|
|
33241
33691
|
const session = readSession();
|
|
33242
33692
|
const account = `${session?.subject}:${accountGeneration()}`;
|
|
33243
33693
|
if (running || !session || blocked === account) return;
|
|
@@ -33247,15 +33697,15 @@ async function terminalSettings(entry2) {
|
|
|
33247
33697
|
if (code === EXIT_OUTDATED || code === EXIT_REFUSED) blocked = account;
|
|
33248
33698
|
});
|
|
33249
33699
|
};
|
|
33250
|
-
onSettingsChange(
|
|
33251
|
-
const timer = setInterval(
|
|
33700
|
+
onSettingsChange(run2);
|
|
33701
|
+
const timer = setInterval(run2, 1e3);
|
|
33252
33702
|
for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, async () => {
|
|
33253
33703
|
clearInterval(timer);
|
|
33254
33704
|
running?.abort();
|
|
33255
33705
|
await done;
|
|
33256
33706
|
await closeSettings();
|
|
33257
33707
|
});
|
|
33258
|
-
|
|
33708
|
+
run2();
|
|
33259
33709
|
}
|
|
33260
33710
|
|
|
33261
33711
|
// src/launcher-main.ts
|