wildcrane-runner 0.6.55 → 0.6.57
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 +1334 -892
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/launcher.mjs +447 -73
- package/dist/plugin.mjs +485 -111
- package/dist/runner.mjs +1084 -593
- package/dist/settings.mjs +437 -63
- package/package.json +1 -1
package/dist/akb/dist/kanban.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// ai4kanban 0.11.
|
|
2
|
+
// ai4kanban 0.11.45 — built by runner/scripts/build.mjs. Do not edit.
|
|
3
3
|
import { createRequire as __ai4kanbanRequire } from 'node:module'
|
|
4
4
|
const require = __ai4kanbanRequire(import.meta.url)
|
|
5
5
|
var __create = Object.create;
|
|
@@ -50,27 +50,66 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
50
50
|
mod
|
|
51
51
|
));
|
|
52
52
|
|
|
53
|
-
// ../cli/src/lib/
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
anonKey: process.env.AI4KANBAN_SUPABASE_ANON_KEY || SUPABASE_ANON_KEY,
|
|
58
|
-
api: trimSlash(process.env.AI4KANBAN_CLOUD_URL || API_URL)
|
|
59
|
-
};
|
|
53
|
+
// ../cli/src/lib/io.ts
|
|
54
|
+
function startCollecting() {
|
|
55
|
+
sink = { out: [], warnings: [] };
|
|
56
|
+
return sink;
|
|
60
57
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
return !!supabaseUrl && !!anonKey;
|
|
58
|
+
function stopCollecting() {
|
|
59
|
+
sink = null;
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
function quietly(fn) {
|
|
62
|
+
const before = sink;
|
|
63
|
+
sink = { out: [], warnings: [] };
|
|
64
|
+
try {
|
|
65
|
+
return fn();
|
|
66
|
+
} finally {
|
|
67
|
+
sink = before;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function quietlyAsync(fn) {
|
|
71
|
+
const before = sink;
|
|
72
|
+
sink = { out: [], warnings: [] };
|
|
73
|
+
try {
|
|
74
|
+
return await fn();
|
|
75
|
+
} finally {
|
|
76
|
+
sink = before;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function say(line = "") {
|
|
80
|
+
const text4 = String(line);
|
|
81
|
+
if (sink) sink.out.push(...text4.split("\n"));
|
|
82
|
+
else console.log(text4);
|
|
83
|
+
}
|
|
84
|
+
function warn(message) {
|
|
85
|
+
if (sink) sink.warnings.push(String(message));
|
|
86
|
+
else console.error(`kanban: warning \u2014 ${message}`);
|
|
87
|
+
}
|
|
88
|
+
var BoardError, sink;
|
|
89
|
+
var init_io = __esm({
|
|
90
|
+
"../cli/src/lib/io.ts"() {
|
|
68
91
|
"use strict";
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
BoardError = class extends Error {
|
|
93
|
+
// `kind` is the machine-readable name of the refusal (card-not-found, no-board,
|
|
94
|
+
// unknown-module, …). It is what a caller reads; the exit code stays 1 for every
|
|
95
|
+
// refusal, so nobody has to keep a table of numbers.
|
|
96
|
+
kind;
|
|
97
|
+
// Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
|
|
98
|
+
exitCode;
|
|
99
|
+
// `bare` says the message is already the whole thing a person should see — a usage
|
|
100
|
+
// block, say — so the dispatcher prints it without putting the command in front of it.
|
|
101
|
+
bare;
|
|
102
|
+
details;
|
|
103
|
+
constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
|
|
104
|
+
super(message);
|
|
105
|
+
this.name = "BoardError";
|
|
106
|
+
this.kind = kind;
|
|
107
|
+
this.bare = bare;
|
|
108
|
+
this.exitCode = exitCode;
|
|
109
|
+
this.details = details;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
sink = null;
|
|
74
113
|
}
|
|
75
114
|
});
|
|
76
115
|
|
|
@@ -86,643 +125,637 @@ var init_home = __esm({
|
|
|
86
125
|
}
|
|
87
126
|
});
|
|
88
127
|
|
|
89
|
-
// ../cli/src/lib/
|
|
128
|
+
// ../cli/src/lib/machine/project.ts
|
|
129
|
+
import { createHash } from "node:crypto";
|
|
90
130
|
import fs from "node:fs";
|
|
91
131
|
import path2 from "node:path";
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return null;
|
|
132
|
+
function realPathOf(dir) {
|
|
133
|
+
const here = path2.resolve(dir);
|
|
134
|
+
const rest = [];
|
|
135
|
+
let at = here;
|
|
136
|
+
for (; ; ) {
|
|
137
|
+
try {
|
|
138
|
+
return path2.join(fs.realpathSync(at), ...rest);
|
|
139
|
+
} catch {
|
|
140
|
+
const up = path2.dirname(at);
|
|
141
|
+
if (up === at) return here;
|
|
142
|
+
rest.unshift(path2.basename(at));
|
|
143
|
+
at = up;
|
|
144
|
+
}
|
|
106
145
|
}
|
|
107
146
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
fs.renameSync(tmp, sessionFile());
|
|
147
|
+
function readableName(real2) {
|
|
148
|
+
const here = path2.basename(real2);
|
|
149
|
+
const up = path2.dirname(real2);
|
|
150
|
+
if (here !== "kanban") return slug(here);
|
|
151
|
+
return path2.basename(up) === "docs" ? slug(path2.basename(path2.dirname(up))) : slug(`${path2.basename(up)}-kanban`);
|
|
114
152
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
function legacyProjectStateDir(board2) {
|
|
154
|
+
const real2 = realPathOf(board2);
|
|
155
|
+
const id = createHash("sha256").update(real2).digest("hex").slice(0, ID_LENGTH);
|
|
156
|
+
return path2.join(machineHome(), PROJECTS, `${readableName(real2)}-${id}`);
|
|
157
|
+
}
|
|
158
|
+
function stateRootOf(board2) {
|
|
159
|
+
let dir = realPathOf(board2);
|
|
160
|
+
for (; ; ) {
|
|
161
|
+
if (fs.existsSync(path2.join(dir, ".git"))) return dir;
|
|
162
|
+
const up = path2.dirname(dir);
|
|
163
|
+
if (up === dir) break;
|
|
164
|
+
dir = up;
|
|
119
165
|
}
|
|
166
|
+
return rootAbove(realPathOf(board2));
|
|
120
167
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
if (!expiringSoon(held4)) return { ok: true, token: held4.accessToken, session: held4 };
|
|
125
|
-
return refresh();
|
|
168
|
+
function rootAbove(board2) {
|
|
169
|
+
const parent = path2.dirname(board2);
|
|
170
|
+
return ["docs", ".akb"].includes(path2.basename(parent)) ? path2.dirname(parent) : parent;
|
|
126
171
|
}
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (!now) return { ok: false, reason: "signed-out" };
|
|
132
|
-
if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
|
|
133
|
-
const { api, anonKey } = cloudEndpoints();
|
|
134
|
-
let response;
|
|
135
|
-
try {
|
|
136
|
-
response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
|
|
137
|
-
method: "POST",
|
|
138
|
-
headers: { apikey: anonKey, "content-type": "application/json" },
|
|
139
|
-
body: JSON.stringify({ refresh_token: now.refreshToken })
|
|
140
|
-
});
|
|
141
|
-
} catch (e) {
|
|
142
|
-
return { ok: false, reason: "unreachable", error: e instanceof Error ? e.message : String(e) };
|
|
143
|
-
}
|
|
144
|
-
if (!response.ok) {
|
|
145
|
-
const body = await response.json().catch(() => ({}));
|
|
146
|
-
if (response.status >= 500) {
|
|
147
|
-
return { ok: false, reason: "unreachable", error: body.error_description ?? `Cloud answered ${response.status}` };
|
|
148
|
-
}
|
|
149
|
-
return { ok: false, reason: "expired", error: body.error_description };
|
|
150
|
-
}
|
|
151
|
-
const fresh = sessionFrom(await response.json(), now);
|
|
152
|
-
if (!fresh) return { ok: false, reason: "expired" };
|
|
153
|
-
const current = readSession();
|
|
154
|
-
if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
|
|
155
|
-
if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
|
|
156
|
-
writeSession(fresh);
|
|
157
|
-
return { ok: true, token: fresh.accessToken, session: fresh };
|
|
158
|
-
} finally {
|
|
159
|
-
lock();
|
|
172
|
+
function projectStateDir(board2, root2 = stateRootOf(board2)) {
|
|
173
|
+
const relative = path2.relative(realPathOf(root2), realPathOf(board2));
|
|
174
|
+
if (relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative)) {
|
|
175
|
+
throw new Error("The board must be inside its project root.");
|
|
160
176
|
}
|
|
177
|
+
return path2.join(realPathOf(root2), ".akb", "boards", relative || "_root");
|
|
161
178
|
}
|
|
162
|
-
function
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
version: 1,
|
|
169
|
-
supabaseUrl: cloudEndpoints().supabaseUrl,
|
|
170
|
-
accessToken: token2.access_token,
|
|
171
|
-
refreshToken: token2.refresh_token,
|
|
172
|
-
expiresAt,
|
|
173
|
-
subject,
|
|
174
|
-
email: token2.user?.email ?? previous?.email,
|
|
175
|
-
handle: previous?.handle,
|
|
176
|
-
name: previous?.name,
|
|
177
|
-
avatarUrl: previous?.avatarUrl,
|
|
178
|
-
avatar: previous?.avatar
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
async function takeLock() {
|
|
182
|
-
const until = Date.now() + LOCK_WAIT_MS;
|
|
183
|
-
for (; ; ) {
|
|
179
|
+
function ensureProjectState(board2, root2 = stateRootOf(board2)) {
|
|
180
|
+
const dir = projectStateDir(board2, root2);
|
|
181
|
+
if (!fs.existsSync(dir)) {
|
|
182
|
+
const legacy2 = legacyProjectStateDir(board2);
|
|
183
|
+
fs.mkdirSync(path2.dirname(dir), { recursive: true });
|
|
184
|
+
const temporary = fs.mkdtempSync(`${dir}.import-`);
|
|
184
185
|
try {
|
|
185
|
-
fs.
|
|
186
|
-
|
|
186
|
+
if (fs.existsSync(legacy2)) fs.cpSync(legacy2, temporary, {
|
|
187
|
+
recursive: true,
|
|
188
|
+
filter: (source) => ![".lock", ".answering"].some((suffix) => path2.basename(source).endsWith(suffix))
|
|
189
|
+
});
|
|
187
190
|
try {
|
|
188
|
-
fs.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
return () => {
|
|
193
|
-
try {
|
|
194
|
-
fs.rmSync(lockDir(), { recursive: true, force: true });
|
|
195
|
-
} catch {
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
} catch (err) {
|
|
199
|
-
if (err.code !== "EEXIST") throw err;
|
|
200
|
-
if (stale()) {
|
|
201
|
-
fs.rmSync(lockDir(), { recursive: true, force: true });
|
|
202
|
-
continue;
|
|
191
|
+
fs.renameSync(temporary, dir);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (!["EEXIST", "ENOTEMPTY"].includes(err.code ?? "")) throw err;
|
|
203
194
|
}
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
await sleep(LOCK_RETRY_MS);
|
|
195
|
+
} finally {
|
|
196
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
207
197
|
}
|
|
208
198
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
const pid = Number(fs.readFileSync(lockOwner(), "utf8").trim());
|
|
214
|
-
held4 = Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
215
|
-
} catch {
|
|
216
|
-
held4 = void 0;
|
|
217
|
-
}
|
|
218
|
-
if (held4 !== void 0 && !alive(held4)) return true;
|
|
219
|
-
try {
|
|
220
|
-
return Date.now() - fs.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
|
|
221
|
-
} catch {
|
|
222
|
-
return false;
|
|
199
|
+
if (recordedBoard(dir) !== realPathOf(board2)) {
|
|
200
|
+
fs.writeFileSync(path2.join(dir, RECORD), `${JSON.stringify({ board: realPathOf(board2) })}
|
|
201
|
+
`);
|
|
223
202
|
}
|
|
203
|
+
return dir;
|
|
224
204
|
}
|
|
225
|
-
function
|
|
205
|
+
function recordedBoard(dir) {
|
|
226
206
|
try {
|
|
227
|
-
|
|
228
|
-
return
|
|
229
|
-
} catch
|
|
230
|
-
return
|
|
207
|
+
const held4 = JSON.parse(fs.readFileSync(path2.join(dir, RECORD), "utf8"));
|
|
208
|
+
return typeof held4.board === "string" ? held4.board : null;
|
|
209
|
+
} catch {
|
|
210
|
+
return null;
|
|
231
211
|
}
|
|
232
212
|
}
|
|
233
|
-
var
|
|
234
|
-
var
|
|
235
|
-
"../cli/src/lib/
|
|
213
|
+
var PROJECTS, ID_LENGTH, RECORD, SESSIONS_FILE, SESSIONS_FOLDER, ASSETS_FOLDER, MOCKUPS_FOLDER, SESSIONS_LOCK, INDEX_LOCK, UI_CONFIG_FILE, slug;
|
|
214
|
+
var init_project = __esm({
|
|
215
|
+
"../cli/src/lib/machine/project.ts"() {
|
|
236
216
|
"use strict";
|
|
237
217
|
init_home();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
218
|
+
PROJECTS = "projects";
|
|
219
|
+
ID_LENGTH = 10;
|
|
220
|
+
RECORD = "board.json";
|
|
221
|
+
SESSIONS_FILE = "sessions.json";
|
|
222
|
+
SESSIONS_FOLDER = "sessions";
|
|
223
|
+
ASSETS_FOLDER = "assets";
|
|
224
|
+
MOCKUPS_FOLDER = "mockups";
|
|
225
|
+
SESSIONS_LOCK = "sessions.lock";
|
|
226
|
+
INDEX_LOCK = "index.lock";
|
|
227
|
+
UI_CONFIG_FILE = "ui.config.json";
|
|
228
|
+
slug = (text4) => text4.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "board";
|
|
248
229
|
}
|
|
249
230
|
});
|
|
250
231
|
|
|
251
|
-
// ../cli/src/lib/
|
|
252
|
-
import
|
|
232
|
+
// ../cli/src/lib/paths.ts
|
|
233
|
+
import { spawnSync } from "node:child_process";
|
|
253
234
|
import fs2 from "node:fs";
|
|
254
235
|
import path3 from "node:path";
|
|
255
|
-
function
|
|
256
|
-
const
|
|
257
|
-
|
|
236
|
+
function boardLockName(kanban, root2) {
|
|
237
|
+
const from = path3.relative(root2, kanban);
|
|
238
|
+
const name = from && !from.startsWith("..") ? from : path3.basename(kanban);
|
|
239
|
+
return `${name.split(path3.sep).join("-")}.lock`;
|
|
258
240
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
241
|
+
function ensureAkbDir() {
|
|
242
|
+
fs2.mkdirSync(AKB_DIR, { recursive: true });
|
|
243
|
+
writeRootIgnoreIfMissing();
|
|
244
|
+
return AKB_DIR;
|
|
262
245
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
return { ok: false, error: `Cloud could not be reached: ${e instanceof Error ? e.message : String(e)}` };
|
|
246
|
+
function writeRootIgnoreIfMissing() {
|
|
247
|
+
const text4 = fs2.existsSync(ROOT_GITIGNORE) ? fs2.readFileSync(ROOT_GITIGNORE, "utf8") : "";
|
|
248
|
+
if (text4.split("\n").some((line) => line.trim() === AKB_IGNORE_LINE)) return false;
|
|
249
|
+
const ignored = spawnSync("git", ["-C", REPO_ROOT, "check-ignore", "-q", AKB_IGNORE_LINE], { stdio: "ignore" }).status;
|
|
250
|
+
if (ignored === 0 || ignored === 128 && KANBAN.startsWith(AKB_DIR + path3.sep)) return false;
|
|
251
|
+
const separator = !text4 || text4.endsWith("\n") ? "" : "\n";
|
|
252
|
+
const block = `# Delivery state \u2014 worktrees and the like. Never committed.
|
|
253
|
+
${AKB_IGNORE_LINE}
|
|
254
|
+
`;
|
|
255
|
+
fs2.writeFileSync(ROOT_GITIGNORE, `${text4}${separator}${block}`);
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
function projectRootOf(board2) {
|
|
259
|
+
let dir = path3.resolve(board2);
|
|
260
|
+
for (; ; ) {
|
|
261
|
+
if (fs2.existsSync(path3.join(dir, ".git"))) return dir;
|
|
262
|
+
const up = path3.dirname(dir);
|
|
263
|
+
if (up === dir) return rootAbove(path3.resolve(board2));
|
|
264
|
+
dir = up;
|
|
283
265
|
}
|
|
284
|
-
const parsed = await response.json().catch(() => ({}));
|
|
285
|
-
if (!response.ok) return { ok: false, code: parsed.error?.code ?? "refused", error: parsed.error?.message ?? `Cloud answered ${response.status}.` };
|
|
286
|
-
return { ok: true, value: parsed, replayed: response.headers.get("idempotent-replayed") === "true" };
|
|
287
266
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
267
|
+
function setBoard(kanban, root2, flag) {
|
|
268
|
+
REPO_ROOT = path3.resolve(root2);
|
|
269
|
+
KANBAN = path3.resolve(kanban);
|
|
270
|
+
BOARD_FLAG = flag;
|
|
271
|
+
TODO = path3.join(KANBAN, "todo");
|
|
272
|
+
ARCHIVE = path3.join(KANBAN, ".archive");
|
|
273
|
+
ARCHIVE_MD = path3.join(KANBAN, "archive.md");
|
|
274
|
+
README = path3.join(TODO, "README.md");
|
|
275
|
+
MODULES_MD = path3.join(KANBAN, "modules.md");
|
|
276
|
+
CONFIG = path3.join(KANBAN, "config.md");
|
|
277
|
+
KANBAN_GITIGNORE = path3.join(KANBAN, ".gitignore");
|
|
278
|
+
RELEASES = path3.join(KANBAN, "releases.md");
|
|
279
|
+
RELEASE_SUMMARIES = path3.join(KANBAN, ".release-summaries");
|
|
280
|
+
AGENTS = path3.join(KANBAN, "agents");
|
|
281
|
+
STUDIOS = path3.join(KANBAN, "studios");
|
|
282
|
+
LEGACY_AGENTS = path3.join(KANBAN, "skills");
|
|
283
|
+
MEMORY = path3.join(KANBAN, "memory");
|
|
284
|
+
AGENT_MEMORY = path3.join(MEMORY, "agents");
|
|
285
|
+
PROJECT_MD = path3.join(MEMORY, "project.md");
|
|
286
|
+
LEGACY_UI_CONFIG = path3.join(KANBAN, UI_CONFIG_FILE);
|
|
287
|
+
LOCAL_CONFIG = path3.join(KANBAN, ".local.json");
|
|
288
|
+
ENV_FILE = path3.join(KANBAN, ".env");
|
|
289
|
+
const machine = projectStateDir(KANBAN, REPO_ROOT);
|
|
290
|
+
BOARD_STATE = machine;
|
|
291
|
+
UI_CONFIG = path3.join(machine, UI_CONFIG_FILE);
|
|
292
|
+
ASSETS = path3.join(machine, ASSETS_FOLDER);
|
|
293
|
+
MOCKUPS = path3.join(machine, MOCKUPS_FOLDER);
|
|
294
|
+
SESSIONS = path3.join(machine, SESSIONS_FILE);
|
|
295
|
+
SESSIONS_DIR = path3.join(machine, SESSIONS_FOLDER);
|
|
296
|
+
SESSIONS_LOCK2 = path3.join(machine, SESSIONS_LOCK);
|
|
297
|
+
INDEX_LOCK2 = path3.join(machine, INDEX_LOCK);
|
|
298
|
+
DELIVERIES = path3.join(KANBAN, "deliveries");
|
|
299
|
+
RULES = path3.join(KANBAN, "rules");
|
|
300
|
+
PLANS = path3.join(machine, "plans");
|
|
301
|
+
PLANS_ARCHIVE = path3.join(PLANS, "archive");
|
|
302
|
+
TRIAGE = path3.join(KANBAN, "triage");
|
|
303
|
+
SIGNALS_ARCHIVED = path3.join(TRIAGE, "archived");
|
|
304
|
+
SIGNALS_DISMISSED = path3.join(TRIAGE, "dismissed");
|
|
305
|
+
SIGNALS_FILES = path3.join(TRIAGE, "files");
|
|
306
|
+
SIGNALS_OLD_INBOX = path3.join(TRIAGE, "inbox");
|
|
307
|
+
SIGNALS_OLD_HANDLED = path3.join(TRIAGE, "handled.md");
|
|
308
|
+
AKB_DIR = path3.join(REPO_ROOT, ".akb");
|
|
309
|
+
ROOT_GITIGNORE = path3.join(REPO_ROOT, ".gitignore");
|
|
310
|
+
LOCK = path3.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
|
|
311
|
+
return REPO_ROOT;
|
|
310
312
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
return linked2.ok ? linked2.value : null;
|
|
313
|
+
function setBoardRoot(root2, named2 = false) {
|
|
314
|
+
const project2 = path3.resolve(root2);
|
|
315
|
+
return setBoard(path3.join(project2, "docs", "kanban"), project2, named2 ? ` --dir ${project2}` : "");
|
|
315
316
|
}
|
|
316
|
-
function
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
const base = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
321
|
-
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();
|
|
322
|
-
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p) => /^projects\/([^/]+)\//.exec(p)?.[1] ?? []));
|
|
323
|
-
if (typeof base.project === "string") projects.add(base.project);
|
|
324
|
-
if (projects.size !== 1) throw new Error();
|
|
325
|
-
return { ok: true, value: [...projects][0] };
|
|
326
|
-
} catch {
|
|
327
|
-
return { ok: false, error: "The project link is invalid or names multiple projects.", code: "invalid-link" };
|
|
328
|
-
}
|
|
317
|
+
function setBoardDir(board2, root2) {
|
|
318
|
+
const folder = path3.resolve(board2);
|
|
319
|
+
return setBoard(folder, root2 ?? projectRootOf(folder), ` --board ${folder}`);
|
|
329
320
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (!link2.ok) return link2;
|
|
333
|
-
let project2 = link2.value;
|
|
334
|
-
if (task) {
|
|
335
|
-
const source = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
|
|
336
|
-
if (!source.ok) return {
|
|
337
|
-
...source,
|
|
338
|
-
error: source.code === "forbidden" ? "Cannot access this task. Check your account and task access in WildCrane, then try again." : source.code === "not_found" ? "This task does not exist. Start a new task from the WildCrane web app." : source.error
|
|
339
|
-
};
|
|
340
|
-
if (project2 && project2 !== source.value.project) return { ok: false, error: "The source task conflicts with this board\u2019s project link.", code: "invalid-link" };
|
|
341
|
-
project2 = source.value.project;
|
|
342
|
-
}
|
|
343
|
-
if (!project2) return { ok: false, error: "This board is not linked to a Cloud project.", code: "unlinked" };
|
|
344
|
-
const checked = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
345
|
-
return checked.ok ? { ok: true, value: project2 } : checked;
|
|
321
|
+
function die(msg, kind) {
|
|
322
|
+
throw new BoardError(msg, typeof kind === "string" ? { kind } : kind);
|
|
346
323
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
title: said2.title,
|
|
350
|
-
project: project2,
|
|
351
|
-
source: "api",
|
|
352
|
-
...said2.studio ? { studio: cloudStudio(said2.studio) } : {},
|
|
353
|
-
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
354
|
-
...said2.agent ? { source_context: { agent: said2.agent } } : {},
|
|
355
|
-
...said2.triage ? { triage: `tri_${project2.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
356
|
-
}, key);
|
|
357
|
-
if (!made.ok) return made;
|
|
358
|
-
const number = numberOf(made.value.key);
|
|
359
|
-
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
360
|
-
return { ok: true, value: { task: made.value, number } };
|
|
324
|
+
function warn2(msg) {
|
|
325
|
+
warn(msg);
|
|
361
326
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (!held4.ok) return held4;
|
|
365
|
-
const key = `${held4.value.prefix}-${number}`;
|
|
366
|
-
const task = await call("GET", `/v1/tasks/${encodeURIComponent(key)}`);
|
|
367
|
-
if (!task.ok) return task;
|
|
368
|
-
const revision = task.value.review?.revision;
|
|
369
|
-
const decided = await call("POST", `/v1/tasks/${encodeURIComponent(key)}/decisions`, {
|
|
370
|
-
decision: "approve",
|
|
371
|
-
...revision !== void 0 ? { review_revision: revision } : {}
|
|
372
|
-
});
|
|
373
|
-
return decided.ok ? { ok: true, value: { key } } : decided;
|
|
327
|
+
function boardPath() {
|
|
328
|
+
return rel(KANBAN).split(path3.sep).join("/");
|
|
374
329
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
330
|
+
function boardText(text4) {
|
|
331
|
+
const posix = (p) => rel(p).split(path3.sep).join("/");
|
|
332
|
+
const swaps = [
|
|
333
|
+
[ASSETS_PATH_IN_TEXT, posix(ASSETS)],
|
|
334
|
+
[MOCKUPS_PATH_IN_TEXT, posix(MOCKUPS)],
|
|
335
|
+
[BOARD_STATE_IN_TEXT, posix(BOARD_STATE)],
|
|
336
|
+
[BOARD_PATH_IN_TEXT, boardPath()]
|
|
337
|
+
];
|
|
338
|
+
const swap = (part, i) => i === swaps.length ? part : part.split(swaps[i][0]).map((p) => swap(p, i + 1)).join(swaps[i][1]);
|
|
339
|
+
return swap(text4, 0);
|
|
340
|
+
}
|
|
341
|
+
function useProjectState() {
|
|
342
|
+
ensureAkbDir();
|
|
343
|
+
return ensureProjectState(KANBAN, REPO_ROOT);
|
|
344
|
+
}
|
|
345
|
+
var REPO_ROOT, KANBAN, TODO, ARCHIVE, REJECTIONS_TO_REVIEW, ARCHIVE_MD, README, MODULES_MD, CONFIG, KANBAN_GITIGNORE, RELEASES, RELEASE_SUMMARIES, AGENTS, STUDIOS, LEGACY_AGENTS, ASSETS, BOARD_STATE, MOCKUPS, MEMORY, AGENT_MEMORY, PROJECT_MD, LOCK, UI_CONFIG, LEGACY_UI_CONFIG, LOCAL_CONFIG, ENV_FILE, SESSIONS, SESSIONS_DIR, SESSIONS_LOCK2, INDEX_LOCK2, DELIVERIES, PLANS, PLANS_ARCHIVE, RULES, TRIAGE, SIGNALS_ARCHIVED, SIGNALS_DISMISSED, SIGNALS_FILES, SIGNALS_OLD_INBOX, SIGNALS_OLD_HANDLED, AKB_DIR, ROOT_GITIGNORE, AKB_IGNORE_LINE, BOARD_FLAG, rel, BOARD_PATH_IN_TEXT, ASSETS_PATH_IN_TEXT, MOCKUPS_PATH_IN_TEXT, BOARD_STATE_IN_TEXT;
|
|
346
|
+
var init_paths = __esm({
|
|
347
|
+
"../cli/src/lib/paths.ts"() {
|
|
378
348
|
"use strict";
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
349
|
+
init_io();
|
|
350
|
+
init_project();
|
|
351
|
+
REPO_ROOT = "";
|
|
352
|
+
KANBAN = "";
|
|
353
|
+
TODO = "";
|
|
354
|
+
ARCHIVE = "";
|
|
355
|
+
REJECTIONS_TO_REVIEW = ".sync";
|
|
356
|
+
ARCHIVE_MD = "";
|
|
357
|
+
README = "";
|
|
358
|
+
MODULES_MD = "";
|
|
359
|
+
CONFIG = "";
|
|
360
|
+
KANBAN_GITIGNORE = "";
|
|
361
|
+
RELEASES = "";
|
|
362
|
+
RELEASE_SUMMARIES = "";
|
|
363
|
+
AGENTS = "";
|
|
364
|
+
STUDIOS = "";
|
|
365
|
+
LEGACY_AGENTS = "";
|
|
366
|
+
ASSETS = "";
|
|
367
|
+
BOARD_STATE = "";
|
|
368
|
+
MOCKUPS = "";
|
|
369
|
+
MEMORY = "";
|
|
370
|
+
AGENT_MEMORY = "";
|
|
371
|
+
PROJECT_MD = "";
|
|
372
|
+
LOCK = "";
|
|
373
|
+
UI_CONFIG = "";
|
|
374
|
+
LEGACY_UI_CONFIG = "";
|
|
375
|
+
LOCAL_CONFIG = "";
|
|
376
|
+
ENV_FILE = "";
|
|
377
|
+
SESSIONS = "";
|
|
378
|
+
SESSIONS_DIR = "";
|
|
379
|
+
SESSIONS_LOCK2 = "";
|
|
380
|
+
INDEX_LOCK2 = "";
|
|
381
|
+
DELIVERIES = "";
|
|
382
|
+
PLANS = "";
|
|
383
|
+
PLANS_ARCHIVE = "";
|
|
384
|
+
RULES = "";
|
|
385
|
+
TRIAGE = "";
|
|
386
|
+
SIGNALS_ARCHIVED = "";
|
|
387
|
+
SIGNALS_DISMISSED = "";
|
|
388
|
+
SIGNALS_FILES = "";
|
|
389
|
+
SIGNALS_OLD_INBOX = "";
|
|
390
|
+
SIGNALS_OLD_HANDLED = "";
|
|
391
|
+
AKB_DIR = "";
|
|
392
|
+
ROOT_GITIGNORE = "";
|
|
393
|
+
AKB_IGNORE_LINE = ".akb/";
|
|
394
|
+
BOARD_FLAG = "";
|
|
395
|
+
setBoardRoot(process.cwd());
|
|
396
|
+
rel = (p) => {
|
|
397
|
+
const from = path3.relative(REPO_ROOT, p);
|
|
398
|
+
if (!from) return p;
|
|
399
|
+
return from.startsWith("..") ? p : from;
|
|
400
|
+
};
|
|
401
|
+
BOARD_PATH_IN_TEXT = "docs/kanban";
|
|
402
|
+
ASSETS_PATH_IN_TEXT = "docs/kanban/.assets";
|
|
403
|
+
MOCKUPS_PATH_IN_TEXT = "docs/kanban/.mockups";
|
|
404
|
+
BOARD_STATE_IN_TEXT = "<board-state>";
|
|
383
405
|
}
|
|
384
406
|
});
|
|
385
407
|
|
|
386
|
-
// ../cli/src/lib/
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
return
|
|
390
|
-
}
|
|
391
|
-
function stopCollecting() {
|
|
392
|
-
sink = null;
|
|
393
|
-
}
|
|
394
|
-
function quietly(fn) {
|
|
395
|
-
const before = sink;
|
|
396
|
-
sink = { out: [], warnings: [] };
|
|
408
|
+
// ../cli/src/lib/cloud/reply-approval.ts
|
|
409
|
+
async function approveAfterReply(task, comment) {
|
|
410
|
+
const context = process.env[REPLY_APPROVAL_ENV];
|
|
411
|
+
if (!context) return null;
|
|
397
412
|
try {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
413
|
+
const { url, token: token2 } = JSON.parse(context);
|
|
414
|
+
if (!/^http:\/\/127\.0\.0\.1:\d+\/$/.test(url) || !/^[a-f0-9]{64}$/.test(token2)) throw Error("Invalid reply context.");
|
|
415
|
+
const response = await fetch(url, {
|
|
416
|
+
method: "POST",
|
|
417
|
+
headers: { authorization: `Bearer ${token2}`, "content-type": "application/json" },
|
|
418
|
+
body: JSON.stringify({ task, comment }),
|
|
419
|
+
signal: AbortSignal.timeout(12e4)
|
|
420
|
+
});
|
|
421
|
+
const result = await response.json();
|
|
422
|
+
if (!result.ok || !result.value) throw Error(result.error ?? "The request was not accepted.");
|
|
423
|
+
const held4 = result.value;
|
|
424
|
+
if (held4.status === "cancelled") throw Error(held4.reason ?? "The request was cancelled. Ask again in a new reply.");
|
|
425
|
+
say(held4.status === "pending" ? `Approval pending for ${task}; it will be checked after this reply finishes.` : `Approval already committed for ${task}.`);
|
|
426
|
+
return { ...held4, pending: held4.status === "pending" };
|
|
427
|
+
} catch (e) {
|
|
428
|
+
return die(e instanceof Error ? e.message : "Reply approval failed.", { kind: "refused" });
|
|
410
429
|
}
|
|
411
430
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
else console.log(text4);
|
|
416
|
-
}
|
|
417
|
-
function warn(message) {
|
|
418
|
-
if (sink) sink.warnings.push(String(message));
|
|
419
|
-
else console.error(`kanban: warning \u2014 ${message}`);
|
|
420
|
-
}
|
|
421
|
-
var BoardError, sink;
|
|
422
|
-
var init_io = __esm({
|
|
423
|
-
"../cli/src/lib/io.ts"() {
|
|
431
|
+
var REPLY_APPROVAL_ENV;
|
|
432
|
+
var init_reply_approval = __esm({
|
|
433
|
+
"../cli/src/lib/cloud/reply-approval.ts"() {
|
|
424
434
|
"use strict";
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
// refusal, so nobody has to keep a table of numbers.
|
|
429
|
-
kind;
|
|
430
|
-
// Only `cloud image` / `cloud tts` set it: 2 for a usage error, as the scripts they replaced did.
|
|
431
|
-
exitCode;
|
|
432
|
-
// `bare` says the message is already the whole thing a person should see — a usage
|
|
433
|
-
// block, say — so the dispatcher prints it without putting the command in front of it.
|
|
434
|
-
bare;
|
|
435
|
-
details;
|
|
436
|
-
constructor(message, { kind = "refused", bare = false, exitCode = 1, ...details } = {}) {
|
|
437
|
-
super(message);
|
|
438
|
-
this.name = "BoardError";
|
|
439
|
-
this.kind = kind;
|
|
440
|
-
this.bare = bare;
|
|
441
|
-
this.exitCode = exitCode;
|
|
442
|
-
this.details = details;
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
sink = null;
|
|
435
|
+
init_io();
|
|
436
|
+
init_paths();
|
|
437
|
+
REPLY_APPROVAL_ENV = "AI4KANBAN_REPLY_APPROVAL";
|
|
446
438
|
}
|
|
447
439
|
});
|
|
448
440
|
|
|
449
|
-
// ../cli/src/lib/
|
|
450
|
-
|
|
441
|
+
// ../cli/src/lib/cloud/config.ts
|
|
442
|
+
function cloudEndpoints() {
|
|
443
|
+
return {
|
|
444
|
+
supabaseUrl: trimSlash(process.env.AI4KANBAN_SUPABASE_URL || SUPABASE_URL),
|
|
445
|
+
anonKey: process.env.AI4KANBAN_SUPABASE_ANON_KEY || SUPABASE_ANON_KEY,
|
|
446
|
+
api: trimSlash(process.env.AI4KANBAN_CLOUD_URL || API_URL)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function cloudConfigured() {
|
|
450
|
+
const { supabaseUrl, anonKey } = cloudEndpoints();
|
|
451
|
+
return !!supabaseUrl && !!anonKey;
|
|
452
|
+
}
|
|
453
|
+
var SUPABASE_URL, SUPABASE_ANON_KEY, API_URL, trimSlash, NOT_CONFIGURED;
|
|
454
|
+
var init_config = __esm({
|
|
455
|
+
"../cli/src/lib/cloud/config.ts"() {
|
|
456
|
+
"use strict";
|
|
457
|
+
SUPABASE_URL = "https://yajrbpprmdvtkvjjfpbk.supabase.co";
|
|
458
|
+
SUPABASE_ANON_KEY = "sb_publishable_ioUQ23BTtoj8NKqndp0Jrw_omVR3m4n";
|
|
459
|
+
API_URL = "https://api.ai4kanban.dev";
|
|
460
|
+
trimSlash = (url) => url.replace(/\/+$/, "");
|
|
461
|
+
NOT_CONFIGURED = "This build of WildCrane carries no Cloud project to sign in against.";
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// ../cli/src/lib/cloud/session.ts
|
|
451
466
|
import fs3 from "node:fs";
|
|
452
467
|
import path4 from "node:path";
|
|
453
|
-
function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return path4.join(fs3.realpathSync(at), ...rest);
|
|
460
|
-
} catch {
|
|
461
|
-
const up = path4.dirname(at);
|
|
462
|
-
if (up === at) return here;
|
|
463
|
-
rest.unshift(path4.basename(at));
|
|
464
|
-
at = up;
|
|
465
|
-
}
|
|
468
|
+
function readSession() {
|
|
469
|
+
let raw;
|
|
470
|
+
try {
|
|
471
|
+
raw = fs3.readFileSync(sessionFile(), "utf8");
|
|
472
|
+
} catch {
|
|
473
|
+
return null;
|
|
466
474
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
function legacyProjectStateDir(board2) {
|
|
475
|
-
const real2 = realPathOf(board2);
|
|
476
|
-
const id = createHash("sha256").update(real2).digest("hex").slice(0, ID_LENGTH);
|
|
477
|
-
return path4.join(machineHome(), PROJECTS, `${readableName(real2)}-${id}`);
|
|
478
|
-
}
|
|
479
|
-
function stateRootOf(board2) {
|
|
480
|
-
let dir = realPathOf(board2);
|
|
481
|
-
for (; ; ) {
|
|
482
|
-
if (fs3.existsSync(path4.join(dir, ".git"))) return dir;
|
|
483
|
-
const up = path4.dirname(dir);
|
|
484
|
-
if (up === dir) break;
|
|
485
|
-
dir = up;
|
|
475
|
+
try {
|
|
476
|
+
const held4 = JSON.parse(raw);
|
|
477
|
+
if (!held4.accessToken || !held4.refreshToken || !held4.subject) return null;
|
|
478
|
+
if (held4.supabaseUrl !== cloudEndpoints().supabaseUrl) return null;
|
|
479
|
+
return { ...held4, version: 1, expiresAt: Number(held4.expiresAt) || 0 };
|
|
480
|
+
} catch {
|
|
481
|
+
return null;
|
|
486
482
|
}
|
|
487
|
-
return rootAbove(realPathOf(board2));
|
|
488
483
|
}
|
|
489
|
-
function
|
|
490
|
-
|
|
491
|
-
|
|
484
|
+
function writeSession(session) {
|
|
485
|
+
fs3.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
486
|
+
const tmp = `${sessionFile()}.${process.pid}.tmp`;
|
|
487
|
+
fs3.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
|
|
488
|
+
`, { mode: 384 });
|
|
489
|
+
fs3.renameSync(tmp, sessionFile());
|
|
492
490
|
}
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
491
|
+
function clearSession() {
|
|
492
|
+
try {
|
|
493
|
+
fs3.rmSync(sessionFile());
|
|
494
|
+
} catch {
|
|
497
495
|
}
|
|
498
|
-
return path4.join(realPathOf(root2), ".akb", "boards", relative || "_root");
|
|
499
496
|
}
|
|
500
|
-
function
|
|
501
|
-
const
|
|
502
|
-
if (!
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
497
|
+
async function accessToken() {
|
|
498
|
+
const held4 = readSession();
|
|
499
|
+
if (!held4) return { ok: false, reason: "signed-out" };
|
|
500
|
+
if (!expiringSoon(held4)) return { ok: true, token: held4.accessToken, session: held4 };
|
|
501
|
+
return refresh();
|
|
502
|
+
}
|
|
503
|
+
async function refresh() {
|
|
504
|
+
const lock = await takeLock();
|
|
505
|
+
try {
|
|
506
|
+
const now = readSession();
|
|
507
|
+
if (!now) return { ok: false, reason: "signed-out" };
|
|
508
|
+
if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
|
|
509
|
+
const { api, anonKey } = cloudEndpoints();
|
|
510
|
+
let response;
|
|
506
511
|
try {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
512
|
+
response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
|
|
513
|
+
method: "POST",
|
|
514
|
+
headers: { apikey: anonKey, "content-type": "application/json" },
|
|
515
|
+
body: JSON.stringify({ refresh_token: now.refreshToken })
|
|
510
516
|
});
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
517
|
+
} catch (e) {
|
|
518
|
+
return { ok: false, reason: "unreachable", error: e instanceof Error ? e.message : String(e) };
|
|
519
|
+
}
|
|
520
|
+
if (!response.ok) {
|
|
521
|
+
const body = await response.json().catch(() => ({}));
|
|
522
|
+
if (response.status >= 500) {
|
|
523
|
+
return { ok: false, reason: "unreachable", error: body.error_description ?? `Cloud answered ${response.status}` };
|
|
515
524
|
}
|
|
516
|
-
|
|
517
|
-
fs3.rmSync(temporary, { recursive: true, force: true });
|
|
525
|
+
return { ok: false, reason: "expired", error: body.error_description };
|
|
518
526
|
}
|
|
527
|
+
const fresh = sessionFrom(await response.json(), now);
|
|
528
|
+
if (!fresh) return { ok: false, reason: "expired" };
|
|
529
|
+
const current = readSession();
|
|
530
|
+
if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
|
|
531
|
+
if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
|
|
532
|
+
writeSession(fresh);
|
|
533
|
+
return { ok: true, token: fresh.accessToken, session: fresh };
|
|
534
|
+
} finally {
|
|
535
|
+
lock();
|
|
519
536
|
}
|
|
520
|
-
|
|
521
|
-
|
|
537
|
+
}
|
|
538
|
+
function sessionFrom(body, previous) {
|
|
539
|
+
const token2 = body;
|
|
540
|
+
const subject = token2.user?.id ?? previous?.subject;
|
|
541
|
+
if (!token2.access_token || !token2.refresh_token || !subject) return null;
|
|
542
|
+
const expiresAt = token2.expires_at ? token2.expires_at * 1e3 : Date.now() + (token2.expires_in ?? 3600) * 1e3;
|
|
543
|
+
return {
|
|
544
|
+
version: 1,
|
|
545
|
+
supabaseUrl: cloudEndpoints().supabaseUrl,
|
|
546
|
+
accessToken: token2.access_token,
|
|
547
|
+
refreshToken: token2.refresh_token,
|
|
548
|
+
expiresAt,
|
|
549
|
+
subject,
|
|
550
|
+
email: token2.user?.email ?? previous?.email,
|
|
551
|
+
handle: previous?.handle,
|
|
552
|
+
name: previous?.name,
|
|
553
|
+
avatarUrl: previous?.avatarUrl,
|
|
554
|
+
avatar: previous?.avatar
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
async function takeLock() {
|
|
558
|
+
const until = Date.now() + LOCK_WAIT_MS;
|
|
559
|
+
for (; ; ) {
|
|
560
|
+
try {
|
|
561
|
+
fs3.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
562
|
+
fs3.mkdirSync(lockDir());
|
|
563
|
+
try {
|
|
564
|
+
fs3.writeFileSync(lockOwner(), `${process.pid}
|
|
522
565
|
`);
|
|
566
|
+
} catch {
|
|
567
|
+
}
|
|
568
|
+
return () => {
|
|
569
|
+
try {
|
|
570
|
+
fs3.rmSync(lockDir(), { recursive: true, force: true });
|
|
571
|
+
} catch {
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
} catch (err) {
|
|
575
|
+
if (err.code !== "EEXIST") throw err;
|
|
576
|
+
if (stale()) {
|
|
577
|
+
fs3.rmSync(lockDir(), { recursive: true, force: true });
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (Date.now() > until) return () => {
|
|
581
|
+
};
|
|
582
|
+
await sleep(LOCK_RETRY_MS);
|
|
583
|
+
}
|
|
523
584
|
}
|
|
524
|
-
return dir;
|
|
525
585
|
}
|
|
526
|
-
function
|
|
586
|
+
function stale() {
|
|
587
|
+
let held4;
|
|
527
588
|
try {
|
|
528
|
-
const
|
|
529
|
-
|
|
589
|
+
const pid = Number(fs3.readFileSync(lockOwner(), "utf8").trim());
|
|
590
|
+
held4 = Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
530
591
|
} catch {
|
|
531
|
-
|
|
592
|
+
held4 = void 0;
|
|
593
|
+
}
|
|
594
|
+
if (held4 !== void 0 && !alive(held4)) return true;
|
|
595
|
+
try {
|
|
596
|
+
return Date.now() - fs3.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
|
|
597
|
+
} catch {
|
|
598
|
+
return false;
|
|
532
599
|
}
|
|
533
600
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
601
|
+
function alive(pid) {
|
|
602
|
+
try {
|
|
603
|
+
process.kill(pid, 0);
|
|
604
|
+
return true;
|
|
605
|
+
} catch (e) {
|
|
606
|
+
return e.code === "EPERM";
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, sessionFile, lockDir, lockOwner, expiringSoon, sleep;
|
|
610
|
+
var init_session = __esm({
|
|
611
|
+
"../cli/src/lib/cloud/session.ts"() {
|
|
537
612
|
"use strict";
|
|
538
613
|
init_home();
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
slug = (text4) => text4.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "board";
|
|
614
|
+
init_config();
|
|
615
|
+
REFRESH_MARGIN_MS = 6e4;
|
|
616
|
+
LOCK_STALE_MS = 3e4;
|
|
617
|
+
LOCK_WAIT_MS = 2e4;
|
|
618
|
+
LOCK_RETRY_MS = 50;
|
|
619
|
+
sessionFile = () => path4.join(machineHome(), "session.json");
|
|
620
|
+
lockDir = () => path4.join(machineHome(), "session.lock");
|
|
621
|
+
lockOwner = () => path4.join(lockDir(), "owner");
|
|
622
|
+
expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
|
|
623
|
+
sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
550
624
|
}
|
|
551
625
|
});
|
|
552
626
|
|
|
553
|
-
// ../cli/src/lib/
|
|
554
|
-
import
|
|
627
|
+
// ../cli/src/lib/cloud/tasks.ts
|
|
628
|
+
import crypto from "node:crypto";
|
|
555
629
|
import fs4 from "node:fs";
|
|
556
630
|
import path5 from "node:path";
|
|
557
|
-
function
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
return `${name.split(path5.sep).join("-")}.lock`;
|
|
561
|
-
}
|
|
562
|
-
function ensureAkbDir() {
|
|
563
|
-
fs4.mkdirSync(AKB_DIR, { recursive: true });
|
|
564
|
-
writeRootIgnoreIfMissing();
|
|
565
|
-
return AKB_DIR;
|
|
631
|
+
function workspaceTask() {
|
|
632
|
+
const id = process.env[TASK_ENV];
|
|
633
|
+
return id && id.trim() ? id.trim() : null;
|
|
566
634
|
}
|
|
567
|
-
function
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const ignored = spawnSync("git", ["-C", REPO_ROOT, "check-ignore", "-q", AKB_IGNORE_LINE], { stdio: "ignore" }).status;
|
|
571
|
-
if (ignored === 0 || ignored === 128 && KANBAN.startsWith(AKB_DIR + path5.sep)) return false;
|
|
572
|
-
const separator = !text4 || text4.endsWith("\n") ? "" : "\n";
|
|
573
|
-
const block = `# Delivery state \u2014 worktrees and the like. Never committed.
|
|
574
|
-
${AKB_IGNORE_LINE}
|
|
575
|
-
`;
|
|
576
|
-
fs4.writeFileSync(ROOT_GITIGNORE, `${text4}${separator}${block}`);
|
|
577
|
-
return true;
|
|
635
|
+
function cloudStudio(name) {
|
|
636
|
+
if (/^wf-/.test(name)) return name.replace("-", "_");
|
|
637
|
+
return `wf_builtin_${name.replace(/-/g, "_")}`;
|
|
578
638
|
}
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
if (up === dir) return rootAbove(path5.resolve(board2));
|
|
585
|
-
dir = up;
|
|
639
|
+
async function call(method, route2, body, key) {
|
|
640
|
+
if (!cloudConfigured()) return { ok: false, error: NOT_CONFIGURED, code: "bad_request" };
|
|
641
|
+
const token2 = await accessToken();
|
|
642
|
+
if (!token2.ok) {
|
|
643
|
+
return token2.reason === "unreachable" ? { ok: false, error: `Cloud could not be reached: ${token2.error}` } : { ok: false, error: token2.reason === "expired" ? "Cloud sign-in has expired. Sign in again." : "This machine is not signed in to Cloud.", code: "unauthenticated" };
|
|
586
644
|
}
|
|
645
|
+
let response;
|
|
646
|
+
try {
|
|
647
|
+
response = await fetch(`${cloudEndpoints().api}${route2}`, {
|
|
648
|
+
method,
|
|
649
|
+
headers: {
|
|
650
|
+
authorization: `Bearer ${token2.token}`,
|
|
651
|
+
...body ? { "content-type": "application/json" } : {},
|
|
652
|
+
...key ? { "idempotency-key": key } : {}
|
|
653
|
+
},
|
|
654
|
+
...body ? { body: JSON.stringify(body) } : {},
|
|
655
|
+
signal: AbortSignal.timeout(2e4)
|
|
656
|
+
});
|
|
657
|
+
} catch (e) {
|
|
658
|
+
return { ok: false, error: `Cloud could not be reached: ${e instanceof Error ? e.message : String(e)}` };
|
|
659
|
+
}
|
|
660
|
+
const parsed = await response.json().catch(() => ({}));
|
|
661
|
+
if (!response.ok) return { ok: false, code: parsed.error?.code ?? "refused", error: parsed.error?.message ?? `Cloud answered ${response.status}.` };
|
|
662
|
+
return { ok: true, value: parsed, replayed: response.headers.get("idempotent-replayed") === "true" };
|
|
587
663
|
}
|
|
588
|
-
function
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const machine = projectStateDir(KANBAN, REPO_ROOT);
|
|
611
|
-
BOARD_STATE = machine;
|
|
612
|
-
UI_CONFIG = path5.join(machine, UI_CONFIG_FILE);
|
|
613
|
-
ASSETS = path5.join(machine, ASSETS_FOLDER);
|
|
614
|
-
MOCKUPS = path5.join(machine, MOCKUPS_FOLDER);
|
|
615
|
-
SESSIONS = path5.join(machine, SESSIONS_FILE);
|
|
616
|
-
SESSIONS_DIR = path5.join(machine, SESSIONS_FOLDER);
|
|
617
|
-
SESSIONS_LOCK2 = path5.join(machine, SESSIONS_LOCK);
|
|
618
|
-
INDEX_LOCK2 = path5.join(machine, INDEX_LOCK);
|
|
619
|
-
DELIVERIES = path5.join(KANBAN, "deliveries");
|
|
620
|
-
RULES = path5.join(KANBAN, "rules");
|
|
621
|
-
PLANS = path5.join(machine, "plans");
|
|
622
|
-
PLANS_ARCHIVE = path5.join(PLANS, "archive");
|
|
623
|
-
TRIAGE = path5.join(KANBAN, "triage");
|
|
624
|
-
SIGNALS_ARCHIVED = path5.join(TRIAGE, "archived");
|
|
625
|
-
SIGNALS_DISMISSED = path5.join(TRIAGE, "dismissed");
|
|
626
|
-
SIGNALS_FILES = path5.join(TRIAGE, "files");
|
|
627
|
-
SIGNALS_OLD_INBOX = path5.join(TRIAGE, "inbox");
|
|
628
|
-
SIGNALS_OLD_HANDLED = path5.join(TRIAGE, "handled.md");
|
|
629
|
-
AKB_DIR = path5.join(REPO_ROOT, ".akb");
|
|
630
|
-
ROOT_GITIGNORE = path5.join(REPO_ROOT, ".gitignore");
|
|
631
|
-
LOCK = path5.join(AKB_DIR, boardLockName(KANBAN, REPO_ROOT));
|
|
632
|
-
return REPO_ROOT;
|
|
633
|
-
}
|
|
634
|
-
function setBoardRoot(root2, named2 = false) {
|
|
635
|
-
const project2 = path5.resolve(root2);
|
|
636
|
-
return setBoard(path5.join(project2, "docs", "kanban"), project2, named2 ? ` --dir ${project2}` : "");
|
|
637
|
-
}
|
|
638
|
-
function setBoardDir(board2, root2) {
|
|
639
|
-
const folder = path5.resolve(board2);
|
|
640
|
-
return setBoard(folder, root2 ?? projectRootOf(folder), ` --board ${folder}`);
|
|
664
|
+
async function createTask(from, said2) {
|
|
665
|
+
const source = await call("GET", `/v1/tasks/${encodeURIComponent(from)}`);
|
|
666
|
+
if (!source.ok) return source;
|
|
667
|
+
const studio = said2.studio ? cloudStudio(said2.studio) : source.value.studio?.id;
|
|
668
|
+
const body = {
|
|
669
|
+
title: said2.title,
|
|
670
|
+
project: source.value.project,
|
|
671
|
+
...studio ? { studio } : {},
|
|
672
|
+
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
673
|
+
source: "api",
|
|
674
|
+
source_context: { task: from, ...said2.agent ? { agent: said2.agent } : {} },
|
|
675
|
+
...said2.run ? { run: true } : {},
|
|
676
|
+
...said2.metadata && Object.keys(said2.metadata).length ? { metadata: said2.metadata } : {},
|
|
677
|
+
...said2.triage ? { triage: `tri_${source.value.project.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
678
|
+
};
|
|
679
|
+
const key = `akb-${crypto.createHash("sha256").update(`${from}
|
|
680
|
+
${said2.slug?.trim() || said2.title}`).digest("hex").slice(0, 40)}`;
|
|
681
|
+
const made = await call("POST", "/v1/tasks", body, key);
|
|
682
|
+
if (!made.ok) return made;
|
|
683
|
+
const number = numberOf(made.value.key);
|
|
684
|
+
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
685
|
+
return { ok: true, value: { task: made.value, number, from: source.value, replayed: made.replayed === true } };
|
|
641
686
|
}
|
|
642
|
-
function
|
|
643
|
-
|
|
687
|
+
function runnerProject(board2) {
|
|
688
|
+
if (path5.basename(board2) !== "kanban" || path5.basename(path5.dirname(board2)) !== ".akb") return null;
|
|
689
|
+
const linked2 = linkedProject(board2, path5.dirname(path5.dirname(board2)));
|
|
690
|
+
return linked2.ok ? linked2.value : null;
|
|
644
691
|
}
|
|
645
|
-
function
|
|
646
|
-
|
|
692
|
+
function linkedProject(board2, root2) {
|
|
693
|
+
const file = path5.join(root2, ".akb", "base.json");
|
|
694
|
+
if (!fs4.existsSync(file)) return { ok: true, value: null };
|
|
695
|
+
try {
|
|
696
|
+
const base = JSON.parse(fs4.readFileSync(file, "utf8"));
|
|
697
|
+
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();
|
|
698
|
+
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p) => /^projects\/([^/]+)\//.exec(p)?.[1] ?? []));
|
|
699
|
+
if (typeof base.project === "string") projects.add(base.project);
|
|
700
|
+
if (projects.size !== 1) throw new Error();
|
|
701
|
+
return { ok: true, value: [...projects][0] };
|
|
702
|
+
} catch {
|
|
703
|
+
return { ok: false, error: "The project link is invalid or names multiple projects.", code: "invalid-link" };
|
|
704
|
+
}
|
|
647
705
|
}
|
|
648
|
-
function
|
|
649
|
-
|
|
706
|
+
async function creationProject(board2, root2, task = workspaceTask()) {
|
|
707
|
+
const link2 = linkedProject(board2, root2);
|
|
708
|
+
if (!link2.ok) return link2;
|
|
709
|
+
let project2 = link2.value;
|
|
710
|
+
if (task) {
|
|
711
|
+
const source = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
|
|
712
|
+
if (!source.ok) return {
|
|
713
|
+
...source,
|
|
714
|
+
error: source.code === "forbidden" ? "Cannot access this task. Check your account and task access in WildCrane, then try again." : source.code === "not_found" ? "This task does not exist. Start a new task from the WildCrane web app." : source.error
|
|
715
|
+
};
|
|
716
|
+
if (project2 && project2 !== source.value.project) return { ok: false, error: "The source task conflicts with this board\u2019s project link.", code: "invalid-link" };
|
|
717
|
+
project2 = source.value.project;
|
|
718
|
+
}
|
|
719
|
+
if (!project2) return { ok: false, error: "This board is not linked to a Cloud project.", code: "unlinked" };
|
|
720
|
+
const checked = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
721
|
+
return checked.ok ? { ok: true, value: project2 } : checked;
|
|
650
722
|
}
|
|
651
|
-
function
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
723
|
+
async function createProjectTask(project2, said2, key) {
|
|
724
|
+
const made = await call("POST", "/v1/tasks", {
|
|
725
|
+
title: said2.title,
|
|
726
|
+
project: project2,
|
|
727
|
+
source: "api",
|
|
728
|
+
...said2.studio ? { studio: cloudStudio(said2.studio) } : {},
|
|
729
|
+
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
730
|
+
...said2.agent ? { source_context: { agent: said2.agent } } : {},
|
|
731
|
+
...said2.triage ? { triage: `tri_${project2.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
732
|
+
}, key);
|
|
733
|
+
if (!made.ok) return made;
|
|
734
|
+
const number = numberOf(made.value.key);
|
|
735
|
+
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
736
|
+
return { ok: true, value: { task: made.value, number } };
|
|
661
737
|
}
|
|
662
|
-
function
|
|
663
|
-
|
|
664
|
-
|
|
738
|
+
async function approveTask(project2, number) {
|
|
739
|
+
const held4 = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
740
|
+
if (!held4.ok) return held4;
|
|
741
|
+
const key = `${held4.value.prefix}-${number}`;
|
|
742
|
+
const task = await call("GET", `/v1/tasks/${encodeURIComponent(key)}`);
|
|
743
|
+
if (!task.ok) return task;
|
|
744
|
+
const revision = task.value.review?.revision;
|
|
745
|
+
const decided = await call("POST", `/v1/tasks/${encodeURIComponent(key)}/decisions`, {
|
|
746
|
+
decision: "approve",
|
|
747
|
+
...revision !== void 0 ? { review_revision: revision } : {}
|
|
748
|
+
});
|
|
749
|
+
return decided.ok ? { ok: true, value: { key } } : decided;
|
|
665
750
|
}
|
|
666
|
-
var
|
|
667
|
-
var
|
|
668
|
-
"../cli/src/lib/
|
|
751
|
+
var TASK_ENV, numberOf;
|
|
752
|
+
var init_tasks = __esm({
|
|
753
|
+
"../cli/src/lib/cloud/tasks.ts"() {
|
|
669
754
|
"use strict";
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
TODO = "";
|
|
675
|
-
ARCHIVE = "";
|
|
676
|
-
REJECTIONS_TO_REVIEW = ".sync";
|
|
677
|
-
ARCHIVE_MD = "";
|
|
678
|
-
README = "";
|
|
679
|
-
MODULES_MD = "";
|
|
680
|
-
CONFIG = "";
|
|
681
|
-
KANBAN_GITIGNORE = "";
|
|
682
|
-
RELEASES = "";
|
|
683
|
-
RELEASE_SUMMARIES = "";
|
|
684
|
-
AGENTS = "";
|
|
685
|
-
STUDIOS = "";
|
|
686
|
-
LEGACY_AGENTS = "";
|
|
687
|
-
ASSETS = "";
|
|
688
|
-
BOARD_STATE = "";
|
|
689
|
-
MOCKUPS = "";
|
|
690
|
-
MEMORY = "";
|
|
691
|
-
AGENT_MEMORY = "";
|
|
692
|
-
PROJECT_MD = "";
|
|
693
|
-
LOCK = "";
|
|
694
|
-
UI_CONFIG = "";
|
|
695
|
-
LEGACY_UI_CONFIG = "";
|
|
696
|
-
LOCAL_CONFIG = "";
|
|
697
|
-
ENV_FILE = "";
|
|
698
|
-
SESSIONS = "";
|
|
699
|
-
SESSIONS_DIR = "";
|
|
700
|
-
SESSIONS_LOCK2 = "";
|
|
701
|
-
INDEX_LOCK2 = "";
|
|
702
|
-
DELIVERIES = "";
|
|
703
|
-
PLANS = "";
|
|
704
|
-
PLANS_ARCHIVE = "";
|
|
705
|
-
RULES = "";
|
|
706
|
-
TRIAGE = "";
|
|
707
|
-
SIGNALS_ARCHIVED = "";
|
|
708
|
-
SIGNALS_DISMISSED = "";
|
|
709
|
-
SIGNALS_FILES = "";
|
|
710
|
-
SIGNALS_OLD_INBOX = "";
|
|
711
|
-
SIGNALS_OLD_HANDLED = "";
|
|
712
|
-
AKB_DIR = "";
|
|
713
|
-
ROOT_GITIGNORE = "";
|
|
714
|
-
AKB_IGNORE_LINE = ".akb/";
|
|
715
|
-
BOARD_FLAG = "";
|
|
716
|
-
setBoardRoot(process.cwd());
|
|
717
|
-
rel = (p) => {
|
|
718
|
-
const from = path5.relative(REPO_ROOT, p);
|
|
719
|
-
if (!from) return p;
|
|
720
|
-
return from.startsWith("..") ? p : from;
|
|
721
|
-
};
|
|
722
|
-
BOARD_PATH_IN_TEXT = "docs/kanban";
|
|
723
|
-
ASSETS_PATH_IN_TEXT = "docs/kanban/.assets";
|
|
724
|
-
MOCKUPS_PATH_IN_TEXT = "docs/kanban/.mockups";
|
|
725
|
-
BOARD_STATE_IN_TEXT = "<board-state>";
|
|
755
|
+
init_config();
|
|
756
|
+
init_session();
|
|
757
|
+
TASK_ENV = "AI4KANBAN_TASK";
|
|
758
|
+
numberOf = (key) => Number(/-(\d+)$/.exec(key)?.[1] ?? NaN);
|
|
726
759
|
}
|
|
727
760
|
});
|
|
728
761
|
|
|
@@ -823,8 +856,8 @@ var init_question_block = __esm({
|
|
|
823
856
|
// ../cli/src/lib/view/rules.ts
|
|
824
857
|
function creationRefusal(id, creation, what, discard = false) {
|
|
825
858
|
if (!creation || creation.state === "unfinished" && discard) return null;
|
|
826
|
-
const
|
|
827
|
-
return creation.state === "creating" ? `#${id} is still being created by run ${
|
|
859
|
+
const run3 = creation.runId.slice(0, 8);
|
|
860
|
+
return creation.state === "creating" ? `#${id} is still being created by run ${run3} \u2014 \`${what}\` is refused until that run finishes.` : `#${id} was never finished being created: run ${run3} stopped short. \`${what}\` is refused until that run is picked back up from the board and finishes. Use reject --discard to discard it instead.`;
|
|
828
861
|
}
|
|
829
862
|
function hasOptions(q) {
|
|
830
863
|
return Array.isArray(q.options) && q.options.length > 0;
|
|
@@ -1634,6 +1667,8 @@ async function act(id, route2, body, done2) {
|
|
|
1634
1667
|
return value;
|
|
1635
1668
|
}
|
|
1636
1669
|
async function taskApprove(id, comment) {
|
|
1670
|
+
const deferred = await approveAfterReply(id, comment);
|
|
1671
|
+
if (deferred) return deferred;
|
|
1637
1672
|
const task = await cloud("GET", `/v1/tasks/${enc(await taskRef(id))}`);
|
|
1638
1673
|
return act(task.key, "decisions", {
|
|
1639
1674
|
decision: "approve",
|
|
@@ -1687,6 +1722,7 @@ var refuse2, enc, WEB, taskUrl, projectLine, taskChat, taskRemove, taskResume, t
|
|
|
1687
1722
|
var init_task = __esm({
|
|
1688
1723
|
"../cli/src/commands/task.ts"() {
|
|
1689
1724
|
"use strict";
|
|
1725
|
+
init_reply_approval();
|
|
1690
1726
|
init_config();
|
|
1691
1727
|
init_session();
|
|
1692
1728
|
init_tasks();
|
|
@@ -2639,11 +2675,11 @@ function checkHarnesses(harnesses) {
|
|
|
2639
2675
|
if (providers.length > 1) {
|
|
2640
2676
|
throw new Error(`harness "${harness.name}": a connector declares one provider list, not ${providers.length}`);
|
|
2641
2677
|
}
|
|
2642
|
-
const
|
|
2643
|
-
if (!
|
|
2644
|
-
if (!
|
|
2678
|
+
const list2 = providers[0];
|
|
2679
|
+
if (!list2) continue;
|
|
2680
|
+
if (!list2.providers?.length) throw new Error(`harness "${harness.name}": the provider setting "${list2.key}" offers no providers`);
|
|
2645
2681
|
const ids = /* @__PURE__ */ new Set();
|
|
2646
|
-
for (const provider of
|
|
2682
|
+
for (const provider of list2.providers) {
|
|
2647
2683
|
if (ids.has(provider.id)) throw new Error(`harness "${harness.name}": two providers share the id "${provider.id}"`);
|
|
2648
2684
|
ids.add(provider.id);
|
|
2649
2685
|
for (const need of [...provider.needs, ...provider.preferWhenSet ?? []]) {
|
|
@@ -2656,8 +2692,8 @@ function checkHarnesses(harnesses) {
|
|
|
2656
2692
|
if (!provider.needs.includes(key)) throw new Error(`harness "${harness.name}": the provider "${provider.id}" renames the variable of "${key}" without needing it`);
|
|
2657
2693
|
}
|
|
2658
2694
|
}
|
|
2659
|
-
if (
|
|
2660
|
-
throw new Error(`harness "${harness.name}": the default provider "${
|
|
2695
|
+
if (list2.defaultProvider && !ids.has(list2.defaultProvider)) {
|
|
2696
|
+
throw new Error(`harness "${harness.name}": the default provider "${list2.defaultProvider}" isn't on the list`);
|
|
2661
2697
|
}
|
|
2662
2698
|
}
|
|
2663
2699
|
}
|
|
@@ -2905,9 +2941,9 @@ function copyEnv(file, given = process.env) {
|
|
|
2905
2941
|
function probe(file) {
|
|
2906
2942
|
const key = keyOf(file);
|
|
2907
2943
|
const start = spawnable(file, ["--version"], { ...probeOptions(file), stdio: ["ignore", "pipe", "pipe"], timeout: PROBE_MS });
|
|
2908
|
-
const
|
|
2909
|
-
const code =
|
|
2910
|
-
const answer2 = { key, at: Date.now(), ...judge(code,
|
|
2944
|
+
const run3 = spawnSync2(start.command, start.args, { ...start.options, encoding: "utf8" });
|
|
2945
|
+
const code = run3.error?.code;
|
|
2946
|
+
const answer2 = { key, at: Date.now(), ...judge(code, run3.status, run3.stdout ?? "", run3.stderr ?? "") };
|
|
2911
2947
|
keep(file, answer2);
|
|
2912
2948
|
return answer2;
|
|
2913
2949
|
}
|
|
@@ -3061,8 +3097,8 @@ function createEventCollector() {
|
|
|
3061
3097
|
case "tool_call_update": {
|
|
3062
3098
|
const id = str(u.toolCallId);
|
|
3063
3099
|
if (todoCalls.has(id)) {
|
|
3064
|
-
const
|
|
3065
|
-
if (Array.isArray(
|
|
3100
|
+
const list2 = obj(u.rawInput).todos;
|
|
3101
|
+
if (Array.isArray(list2) && !str(obj(u.rawInput)._toolName)) queue.push({ kind: "plan", data: { entries: entriesOf(list2) } });
|
|
3066
3102
|
return;
|
|
3067
3103
|
}
|
|
3068
3104
|
release(id, targetIn(u));
|
|
@@ -3242,10 +3278,10 @@ function failedWith(ev) {
|
|
|
3242
3278
|
return str(ev.result).trim() || "the agent reported the session failed";
|
|
3243
3279
|
}
|
|
3244
3280
|
function denials(ev) {
|
|
3245
|
-
const
|
|
3246
|
-
const names3 = [...new Set(
|
|
3281
|
+
const list2 = Array.isArray(ev.permission_denials) ? ev.permission_denials : [];
|
|
3282
|
+
const names3 = [...new Set(list2.map((raw) => str(obj(raw).tool_name)).filter(Boolean))];
|
|
3247
3283
|
if (!names3.length) return "";
|
|
3248
|
-
return `[refused] ${
|
|
3284
|
+
return `[refused] ${list2.length} tool call${list2.length === 1 ? "" : "s"} were not allowed: ${names3.join(", ")}
|
|
3249
3285
|
`;
|
|
3250
3286
|
}
|
|
3251
3287
|
function promptSize(raw) {
|
|
@@ -3429,6 +3465,48 @@ var init_claude_stream = __esm({
|
|
|
3429
3465
|
}
|
|
3430
3466
|
});
|
|
3431
3467
|
|
|
3468
|
+
// ../cli/src/lib/agent/wire/background.ts
|
|
3469
|
+
function createBackgroundTasks() {
|
|
3470
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
3471
|
+
return {
|
|
3472
|
+
update(id, status, result = "") {
|
|
3473
|
+
if (!id) return false;
|
|
3474
|
+
const previous = tasks.get(id);
|
|
3475
|
+
if (previous?.status === status && previous.result === result) return false;
|
|
3476
|
+
tasks.set(id, { status, result });
|
|
3477
|
+
return true;
|
|
3478
|
+
},
|
|
3479
|
+
results: () => [...tasks].map(([id, task]) => ({ id, ...task })),
|
|
3480
|
+
running: () => [...tasks].filter(([, t]) => t.status === "running").map(([id]) => id),
|
|
3481
|
+
count: () => [...tasks.values()].filter((t) => t.status === "running").length,
|
|
3482
|
+
failure: () => [...tasks].filter(([, t]) => t.status === "failed").map(([id, t]) => t.result || `Background task ${id} failed.`).join("\n") || void 0
|
|
3483
|
+
};
|
|
3484
|
+
}
|
|
3485
|
+
function streamFinished(stream) {
|
|
3486
|
+
if (stream.background?.()) return false;
|
|
3487
|
+
const turns = stream.turns?.();
|
|
3488
|
+
return turns ? !!turns.length && !turns.at(-1).background : stream.result() !== void 0;
|
|
3489
|
+
}
|
|
3490
|
+
function createBackgroundWait(milliseconds, expired) {
|
|
3491
|
+
let timer;
|
|
3492
|
+
return {
|
|
3493
|
+
pending() {
|
|
3494
|
+
if (!timer && milliseconds > 0) timer = setTimeout(expired, milliseconds);
|
|
3495
|
+
},
|
|
3496
|
+
close() {
|
|
3497
|
+
clearTimeout(timer);
|
|
3498
|
+
timer = void 0;
|
|
3499
|
+
}
|
|
3500
|
+
};
|
|
3501
|
+
}
|
|
3502
|
+
var backgroundWaitMessage;
|
|
3503
|
+
var init_background = __esm({
|
|
3504
|
+
"../cli/src/lib/agent/wire/background.ts"() {
|
|
3505
|
+
"use strict";
|
|
3506
|
+
backgroundWaitMessage = (minutes) => `the agent's background tasks did not finish within ${minutes / 60} hours, so the run was ended.`;
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3509
|
+
|
|
3432
3510
|
// ../cli/src/lib/agent/wire/codex-session.ts
|
|
3433
3511
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3434
3512
|
import { homedir } from "node:os";
|
|
@@ -3713,6 +3791,31 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
3713
3791
|
let lookedAt = 0;
|
|
3714
3792
|
const events = createEventCollector();
|
|
3715
3793
|
const started = /* @__PURE__ */ new Set();
|
|
3794
|
+
const background = createBackgroundTasks();
|
|
3795
|
+
const subagents = /* @__PURE__ */ new Set();
|
|
3796
|
+
const collabItems = /* @__PURE__ */ new Set();
|
|
3797
|
+
const collab = (item, done2) => {
|
|
3798
|
+
if (item.type !== "collab_tool_call") return;
|
|
3799
|
+
const key = `${str(item.id)}:${done2}`;
|
|
3800
|
+
if (collabItems.has(key)) return;
|
|
3801
|
+
collabItems.add(key);
|
|
3802
|
+
for (const [id, raw] of Object.entries(obj(item.agents_states))) {
|
|
3803
|
+
const state = obj(raw);
|
|
3804
|
+
const status = str(state.status);
|
|
3805
|
+
if (!["pending_init", "running", "completed", "interrupted", "errored", "shutdown", "not_found"].includes(status)) continue;
|
|
3806
|
+
const previous = background.results().find((t) => t.id === id);
|
|
3807
|
+
if (["shutdown", "not_found"].includes(status) && previous && previous.status !== "running") continue;
|
|
3808
|
+
if (!subagents.has(id)) {
|
|
3809
|
+
subagents.add(id);
|
|
3810
|
+
events.subagent(`agent:${id}`, str(item.prompt) || "Agent");
|
|
3811
|
+
}
|
|
3812
|
+
const running = status === "pending_init" || status === "running";
|
|
3813
|
+
const failed = !running && status !== "completed";
|
|
3814
|
+
if (background.update(id, running ? "running" : failed ? "failed" : "completed", str(state.message)) && !running) {
|
|
3815
|
+
events.toolResult(`agent:${id}`, failed ? "failed" : "completed", str(state.message));
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
};
|
|
3716
3819
|
const look = (now) => {
|
|
3717
3820
|
if (!threadId) return;
|
|
3718
3821
|
const at = Date.now();
|
|
@@ -3739,6 +3842,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
3739
3842
|
if (!threadId) threadId = str(ev.thread_id).trim() || void 0;
|
|
3740
3843
|
return "";
|
|
3741
3844
|
case "item.started":
|
|
3845
|
+
collab(obj(ev.item), false);
|
|
3742
3846
|
itemEvents(events, started, obj(ev.item), false);
|
|
3743
3847
|
return renderStarted(obj(ev.item));
|
|
3744
3848
|
case "item.updated":
|
|
@@ -3746,6 +3850,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
3746
3850
|
return "";
|
|
3747
3851
|
case "item.completed": {
|
|
3748
3852
|
const item = obj(ev.item);
|
|
3853
|
+
collab(item, true);
|
|
3749
3854
|
if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str(item.tool))) {
|
|
3750
3855
|
const content = obj(item.result).content;
|
|
3751
3856
|
for (const block of Array.isArray(content) ? content : []) {
|
|
@@ -3817,7 +3922,8 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
3817
3922
|
// whose rates the board knows.
|
|
3818
3923
|
costUsd: () => priceUsd(facts?.provider, turn2()?.model ?? facts?.model, own()),
|
|
3819
3924
|
resumeId: () => threadId,
|
|
3820
|
-
failure: () => failure,
|
|
3925
|
+
failure: () => failure ?? background.failure(),
|
|
3926
|
+
background: () => subagents.size ? background.count() : void 0,
|
|
3821
3927
|
events: events.events
|
|
3822
3928
|
};
|
|
3823
3929
|
}
|
|
@@ -3825,6 +3931,7 @@ var imageSafeText, CALLS, LOOK_EVERY_MS;
|
|
|
3825
3931
|
var init_codex_stream = __esm({
|
|
3826
3932
|
"../cli/src/lib/agent/wire/codex-stream.ts"() {
|
|
3827
3933
|
"use strict";
|
|
3934
|
+
init_background();
|
|
3828
3935
|
init_codex_session();
|
|
3829
3936
|
init_events();
|
|
3830
3937
|
init_json();
|
|
@@ -4138,6 +4245,9 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
4138
4245
|
send({ id, method, params });
|
|
4139
4246
|
});
|
|
4140
4247
|
},
|
|
4248
|
+
notify(method, params = {}) {
|
|
4249
|
+
send({ method, params });
|
|
4250
|
+
},
|
|
4141
4251
|
/** Answer something the agent asked us. */
|
|
4142
4252
|
reply(id, result) {
|
|
4143
4253
|
send({ id, result });
|
|
@@ -4223,8 +4333,8 @@ var init_package = __esm({
|
|
|
4223
4333
|
"../cli/package.json"() {
|
|
4224
4334
|
package_default = {
|
|
4225
4335
|
name: "wildcrane",
|
|
4226
|
-
version: "0.11.
|
|
4227
|
-
akbContract:
|
|
4336
|
+
version: "0.11.45",
|
|
4337
|
+
akbContract: 12,
|
|
4228
4338
|
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.",
|
|
4229
4339
|
keywords: [
|
|
4230
4340
|
"kanban",
|
|
@@ -4315,23 +4425,23 @@ function saidBy(update2) {
|
|
|
4315
4425
|
function modelOf(answer2) {
|
|
4316
4426
|
const current = str(obj(answer2.models).currentModelId).trim();
|
|
4317
4427
|
if (current) return modelsIn(answer2).find((m) => m.modelId === current)?.name ?? current;
|
|
4318
|
-
const
|
|
4319
|
-
for (const raw of
|
|
4428
|
+
const list2 = Array.isArray(answer2.configOptions) ? answer2.configOptions : [];
|
|
4429
|
+
for (const raw of list2) {
|
|
4320
4430
|
const option = obj(raw);
|
|
4321
4431
|
if (option.id === "model") return str(option.currentValue).trim() || void 0;
|
|
4322
4432
|
}
|
|
4323
4433
|
return void 0;
|
|
4324
4434
|
}
|
|
4325
4435
|
function modelsIn(answer2) {
|
|
4326
|
-
const
|
|
4327
|
-
return (Array.isArray(
|
|
4436
|
+
const list2 = obj(answer2.models).availableModels;
|
|
4437
|
+
return (Array.isArray(list2) ? list2 : []).map(obj).flatMap((m) => {
|
|
4328
4438
|
const modelId = str(m.modelId);
|
|
4329
4439
|
return modelId ? [{ modelId, name: str(m.name) || modelId }] : [];
|
|
4330
4440
|
});
|
|
4331
4441
|
}
|
|
4332
4442
|
function pickedModel(answer2, wanted) {
|
|
4333
|
-
const
|
|
4334
|
-
return
|
|
4443
|
+
const list2 = modelsIn(answer2);
|
|
4444
|
+
return list2.find((m) => m.modelId === wanted) ?? list2.find((m) => m.name === wanted || m.modelId.split("[")[0] === wanted);
|
|
4335
4445
|
}
|
|
4336
4446
|
function usageOf2(value, grossInput = false) {
|
|
4337
4447
|
const usage3 = obj(value);
|
|
@@ -4844,6 +4954,328 @@ var init_zcode = __esm({
|
|
|
4844
4954
|
}
|
|
4845
4955
|
});
|
|
4846
4956
|
|
|
4957
|
+
// ../cli/src/lib/agent/wire/codex.ts
|
|
4958
|
+
function createCodexConnection(argv) {
|
|
4959
|
+
const execAt = argv.indexOf("exec");
|
|
4960
|
+
if (execAt < 1) return void 0;
|
|
4961
|
+
const server = [argv[0], "app-server"];
|
|
4962
|
+
const options = { images: [] };
|
|
4963
|
+
const roots = [];
|
|
4964
|
+
for (let i = 1; i < argv.length; i++) {
|
|
4965
|
+
if (i === execAt) continue;
|
|
4966
|
+
const arg = argv[i];
|
|
4967
|
+
const [flag, inline] = arg.split(/=(.*)/s);
|
|
4968
|
+
const value = () => inline ?? argv[++i];
|
|
4969
|
+
if (["--json", "--experimental-json", "--skip-git-repo-check"].includes(arg)) continue;
|
|
4970
|
+
if (["-c", "--config", "--enable", "--disable"].includes(flag)) {
|
|
4971
|
+
const v = value();
|
|
4972
|
+
if (!v) return void 0;
|
|
4973
|
+
server.push(flag, v);
|
|
4974
|
+
} else if (["-m", "--model", "-s", "--sandbox"].includes(flag)) {
|
|
4975
|
+
const v = value();
|
|
4976
|
+
if (!v) return void 0;
|
|
4977
|
+
server.push("-c", `${flag === "-m" || flag === "--model" ? "model" : "sandbox_mode"}=${JSON.stringify(v)}`);
|
|
4978
|
+
} else if (arg === "--dangerously-bypass-approvals-and-sandbox") {
|
|
4979
|
+
server.push("-c", 'approval_policy="never"', "-c", 'sandbox_mode="danger-full-access"');
|
|
4980
|
+
} else if (arg === "--full-auto") {
|
|
4981
|
+
server.push("-c", 'approval_policy="on-request"', "-c", 'sandbox_mode="workspace-write"');
|
|
4982
|
+
} else if (flag === "--add-dir") {
|
|
4983
|
+
const v = value();
|
|
4984
|
+
if (!v) return void 0;
|
|
4985
|
+
roots.push(v);
|
|
4986
|
+
} else if (flag === "-C" || flag === "--cd") {
|
|
4987
|
+
options.cwd = value();
|
|
4988
|
+
if (!options.cwd) return void 0;
|
|
4989
|
+
} else if (flag === "-i" || flag === "--image") {
|
|
4990
|
+
const v = value();
|
|
4991
|
+
if (!v) return void 0;
|
|
4992
|
+
options.images.push(v);
|
|
4993
|
+
} else if (arg === "resume" || arg === "fork") {
|
|
4994
|
+
options.mode = arg;
|
|
4995
|
+
options.threadId = argv[++i];
|
|
4996
|
+
if (!options.threadId || options.threadId.startsWith("-")) return void 0;
|
|
4997
|
+
} else {
|
|
4998
|
+
return void 0;
|
|
4999
|
+
}
|
|
5000
|
+
}
|
|
5001
|
+
if (roots.length) server.push("-c", `sandbox_workspace_write.writable_roots=${JSON.stringify(roots)}`);
|
|
5002
|
+
return { argv: server, client: createCodexClient(options) };
|
|
5003
|
+
}
|
|
5004
|
+
function createCodexClient(options = { images: [] }) {
|
|
5005
|
+
const tasks = createBackgroundTasks();
|
|
5006
|
+
return {
|
|
5007
|
+
structured: true,
|
|
5008
|
+
background: tasks.count,
|
|
5009
|
+
turn: (io) => run(io, options, tasks)
|
|
5010
|
+
};
|
|
5011
|
+
}
|
|
5012
|
+
async function run(io, options, tasks) {
|
|
5013
|
+
const renderer = createCodexStreamRenderer();
|
|
5014
|
+
const children = /* @__PURE__ */ new Set();
|
|
5015
|
+
const commands = /* @__PURE__ */ new Set();
|
|
5016
|
+
const seenItems = /* @__PURE__ */ new Set();
|
|
5017
|
+
const completedTurns = /* @__PURE__ */ new Set();
|
|
5018
|
+
let threadId = "";
|
|
5019
|
+
let active2 = true;
|
|
5020
|
+
let waiting = false;
|
|
5021
|
+
let terminalListing = true;
|
|
5022
|
+
let timer;
|
|
5023
|
+
let ended = false;
|
|
5024
|
+
let checking = false;
|
|
5025
|
+
let context;
|
|
5026
|
+
let total;
|
|
5027
|
+
let baseline;
|
|
5028
|
+
let model;
|
|
5029
|
+
let provider;
|
|
5030
|
+
let resolve2;
|
|
5031
|
+
const done2 = new Promise((r) => {
|
|
5032
|
+
resolve2 = r;
|
|
5033
|
+
});
|
|
5034
|
+
const deadline = createBackgroundWait(BACKGROUND_WAIT.minutes * 6e4, () => end2(backgroundWaitMessage(BACKGROUND_WAIT.minutes)));
|
|
5035
|
+
const emit = (type, extra = {}) => {
|
|
5036
|
+
io.log(renderer.push(JSON.stringify({ type, ...extra }) + "\n"));
|
|
5037
|
+
for (const event2 of renderer.events?.() ?? []) io.event?.(event2);
|
|
5038
|
+
};
|
|
5039
|
+
const end2 = (error) => {
|
|
5040
|
+
if (ended) return;
|
|
5041
|
+
ended = true;
|
|
5042
|
+
clearTimeout(timer);
|
|
5043
|
+
deadline.close();
|
|
5044
|
+
io.stdout.off("close", closed2);
|
|
5045
|
+
io.log(renderer.flush());
|
|
5046
|
+
const usage3 = total && (!options.threadId && !io.resumeId ? total : baseline ? {
|
|
5047
|
+
input: Math.max(0, total.input - baseline.input),
|
|
5048
|
+
cacheRead: Math.max(0, total.cacheRead - baseline.cacheRead),
|
|
5049
|
+
cacheCreation: Math.max(0, total.cacheCreation - baseline.cacheCreation),
|
|
5050
|
+
output: Math.max(0, total.output - baseline.output)
|
|
5051
|
+
} : void 0);
|
|
5052
|
+
const failure = error || tasks.failure();
|
|
5053
|
+
if (failure) io.event?.({ kind: "error", data: { text: failure } });
|
|
5054
|
+
resolve2({ ok: !failure, error: failure, result: renderer.result(), replyParts: renderer.replyParts?.(), usage: usage3, context, costUsd: priceUsd(provider, model, usage3) });
|
|
5055
|
+
};
|
|
5056
|
+
const closed2 = () => end2("Codex closed the connection before all work and results finished.");
|
|
5057
|
+
io.stdout.once("close", closed2);
|
|
5058
|
+
const update2 = (id, state, title = "") => {
|
|
5059
|
+
if (ended) return;
|
|
5060
|
+
const status = str(state.status);
|
|
5061
|
+
if (!status || !id) return;
|
|
5062
|
+
const previous = tasks.results().find((t) => t.id === `agent:${id}`);
|
|
5063
|
+
if (["shutdown", "notFound", "not_found"].includes(status) && previous && previous.status !== "running") return;
|
|
5064
|
+
const running = ["pendingInit", "running", "pending_init"].includes(status);
|
|
5065
|
+
const failed = ["interrupted", "errored", "shutdown", "notFound", "not_found"].includes(status);
|
|
5066
|
+
if (!running && !failed && status !== "completed") return;
|
|
5067
|
+
const known2 = children.has(id);
|
|
5068
|
+
children.add(id);
|
|
5069
|
+
if (!known2) io.event?.({ kind: "tool_call", data: { toolCallId: `agent:${id}`, title: targetOf(title) || "Agent", kind: "other", status: "in_progress", subagent: true } });
|
|
5070
|
+
if (tasks.update(`agent:${id}`, running ? "running" : failed ? "failed" : "completed", str(state.message)) && !running) {
|
|
5071
|
+
io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str(state.message) } });
|
|
5072
|
+
}
|
|
5073
|
+
};
|
|
5074
|
+
const item = (raw, completed) => {
|
|
5075
|
+
if (ended) return;
|
|
5076
|
+
const id = str(raw.id);
|
|
5077
|
+
if (raw.type === "collabAgentToolCall") {
|
|
5078
|
+
const key2 = `${id}:${completed}`;
|
|
5079
|
+
if (seenItems.has(key2)) return;
|
|
5080
|
+
seenItems.add(key2);
|
|
5081
|
+
for (const [child, state] of Object.entries(obj(raw.agentsStates))) update2(child, obj(state), str(raw.prompt));
|
|
5082
|
+
for (const child of Array.isArray(raw.receiverThreadIds) ? raw.receiverThreadIds : []) {
|
|
5083
|
+
if (typeof child === "string" && !children.has(child) && raw.tool === "spawnAgent") update2(child, { status: "running" }, str(raw.prompt));
|
|
5084
|
+
}
|
|
5085
|
+
return;
|
|
5086
|
+
}
|
|
5087
|
+
if (raw.type === "commandExecution") {
|
|
5088
|
+
if (seenItems.has(`${id}:true`)) return;
|
|
5089
|
+
if (raw.status === "inProgress") completed = false;
|
|
5090
|
+
if (!completed) {
|
|
5091
|
+
commands.add(id);
|
|
5092
|
+
if (tasks.results().some((t) => t.id === `command:${id}`)) tasks.update(`command:${id}`, "running");
|
|
5093
|
+
} else {
|
|
5094
|
+
commands.delete(id);
|
|
5095
|
+
const failed = raw.status === "failed" || typeof raw.exitCode === "number" && raw.exitCode !== 0;
|
|
5096
|
+
if (tasks.results().some((t) => t.id === `command:${id}`)) tasks.update(`command:${id}`, failed ? "failed" : "completed", str(raw.aggregatedOutput));
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
const key = `${id}:${completed}`;
|
|
5100
|
+
if (seenItems.has(key)) return;
|
|
5101
|
+
seenItems.add(key);
|
|
5102
|
+
const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
|
|
5103
|
+
const type = types[str(raw.type)];
|
|
5104
|
+
if (!type) return;
|
|
5105
|
+
emit(completed ? "item.completed" : "item.started", { item: {
|
|
5106
|
+
...raw,
|
|
5107
|
+
type,
|
|
5108
|
+
...raw.type === "imageGeneration" ? { path: raw.savedPath ?? raw.path } : {},
|
|
5109
|
+
...raw.type === "fileChange" ? { changes: list(raw.changes).map((c) => ({ ...c, kind: str(obj(c.kind).type) || c.kind })) } : {},
|
|
5110
|
+
aggregated_output: raw.aggregatedOutput,
|
|
5111
|
+
exit_code: raw.exitCode,
|
|
5112
|
+
status: raw.status === "inProgress" ? "in_progress" : raw.status
|
|
5113
|
+
} });
|
|
5114
|
+
};
|
|
5115
|
+
const start = async (text4, images = []) => {
|
|
5116
|
+
active2 = true;
|
|
5117
|
+
waiting = false;
|
|
5118
|
+
await rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path86) => ({ type: "localImage", path: path86 }))] });
|
|
5119
|
+
};
|
|
5120
|
+
const schedule = () => {
|
|
5121
|
+
if (ended || timer) return;
|
|
5122
|
+
timer = setTimeout(() => {
|
|
5123
|
+
timer = void 0;
|
|
5124
|
+
void check();
|
|
5125
|
+
}, 1e3);
|
|
5126
|
+
};
|
|
5127
|
+
const check = async () => {
|
|
5128
|
+
if (ended || checking || active2) return;
|
|
5129
|
+
checking = true;
|
|
5130
|
+
try {
|
|
5131
|
+
for (const key of tasks.running().filter((id) => id.startsWith("agent:"))) {
|
|
5132
|
+
const id = key.slice(6);
|
|
5133
|
+
let thread = obj((await rpc.call("thread/read", { threadId: id, includeTurns: false })).thread);
|
|
5134
|
+
let turns = list(thread.turns);
|
|
5135
|
+
if (thread.historyMode === "paginated") {
|
|
5136
|
+
turns = list((await rpc.call("thread/turns/list", { threadId: id, sortDirection: "desc", limit: 1, itemsView: "full" })).data).reverse();
|
|
5137
|
+
} else if (!turns.length) {
|
|
5138
|
+
thread = obj((await rpc.call("thread/read", { threadId: id, includeTurns: true })).thread);
|
|
5139
|
+
turns = list(thread.turns);
|
|
5140
|
+
}
|
|
5141
|
+
const turn2 = turns.at(-1);
|
|
5142
|
+
const status = str(turn2?.status);
|
|
5143
|
+
if (obj(thread.status).type === "systemError") update2(id, { status: "errored", message: "Codex subagent reported a system error." });
|
|
5144
|
+
else if (obj(thread.status).type !== "active" && turn2 && ["completed", "failed", "interrupted"].includes(status)) {
|
|
5145
|
+
const message = list(turn2.items).filter((i) => i.type === "agentMessage").map((i) => str(i.text)).join("\n\n");
|
|
5146
|
+
update2(id, { status: status === "completed" ? "completed" : "errored", message: str(obj(turn2.error).message) || message });
|
|
5147
|
+
}
|
|
5148
|
+
}
|
|
5149
|
+
if (terminalListing) {
|
|
5150
|
+
try {
|
|
5151
|
+
const running = /* @__PURE__ */ new Set();
|
|
5152
|
+
let cursor = null;
|
|
5153
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
5154
|
+
do {
|
|
5155
|
+
if (cursor && cursors.has(cursor)) throw Error("Codex repeated a background terminal cursor.");
|
|
5156
|
+
cursors.add(cursor);
|
|
5157
|
+
const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
5158
|
+
for (const terminal of list(page.data)) {
|
|
5159
|
+
const id = str(terminal.itemId) || str(terminal.processId);
|
|
5160
|
+
if (id) {
|
|
5161
|
+
running.add(id);
|
|
5162
|
+
tasks.update(`command:${id}`, "running");
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
cursor = page.nextCursor;
|
|
5166
|
+
} while (cursor && !ended);
|
|
5167
|
+
for (const id of tasks.running().filter((id2) => id2.startsWith("command:"))) if (!running.has(id.slice(8))) {
|
|
5168
|
+
tasks.update(id, "completed");
|
|
5169
|
+
commands.delete(id.slice(8));
|
|
5170
|
+
}
|
|
5171
|
+
} catch (e) {
|
|
5172
|
+
if (!(e instanceof RpcError) || e.code !== -32601) throw e;
|
|
5173
|
+
terminalListing = false;
|
|
5174
|
+
io.log("[Codex] This version does not report background terminals.\n");
|
|
5175
|
+
if (commands.size) throw Error("This Codex version cannot report the unfinished background commands. Update Codex to collect their results.");
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5178
|
+
if (ended || active2) return;
|
|
5179
|
+
if (tasks.count()) {
|
|
5180
|
+
waiting = true;
|
|
5181
|
+
deadline.pending();
|
|
5182
|
+
schedule();
|
|
5183
|
+
return;
|
|
5184
|
+
}
|
|
5185
|
+
if (waiting) {
|
|
5186
|
+
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()));
|
|
5187
|
+
} else end2();
|
|
5188
|
+
} catch (e) {
|
|
5189
|
+
end2(String(e instanceof Error ? e.message : e));
|
|
5190
|
+
} finally {
|
|
5191
|
+
checking = false;
|
|
5192
|
+
}
|
|
5193
|
+
};
|
|
5194
|
+
const rpc = connect(io.stdout, io.stdin, (msg) => {
|
|
5195
|
+
if (ended) return;
|
|
5196
|
+
if (msg.id !== void 0) {
|
|
5197
|
+
rpc.refuse(msg.id, "WildCrane cannot answer interactive requests in an unattended run.");
|
|
5198
|
+
end2(`Codex requested interaction: ${msg.method}`);
|
|
5199
|
+
return;
|
|
5200
|
+
}
|
|
5201
|
+
const p = obj(msg.params);
|
|
5202
|
+
if (str(p.threadId) !== threadId) return;
|
|
5203
|
+
if (msg.method === "turn/started") {
|
|
5204
|
+
active2 = true;
|
|
5205
|
+
return;
|
|
5206
|
+
}
|
|
5207
|
+
if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed");
|
|
5208
|
+
if (msg.method === "thread/tokenUsage/updated") {
|
|
5209
|
+
const token2 = obj(p.tokenUsage);
|
|
5210
|
+
const counts = obj(token2.total);
|
|
5211
|
+
const input = Number(counts.inputTokens) || 0;
|
|
5212
|
+
const read3 = Number(counts.cachedInputTokens) || 0;
|
|
5213
|
+
const write2 = Number(counts.cacheWriteInputTokens) || 0;
|
|
5214
|
+
total = { input: Math.max(0, input - read3 - write2), cacheRead: read3, cacheCreation: write2, output: Number(counts.outputTokens) || 0 };
|
|
5215
|
+
const last = obj(token2.last);
|
|
5216
|
+
context = { used: (Number(last.inputTokens) || 0) + (Number(last.outputTokens) || 0), ...Number(token2.modelContextWindow) > 0 ? { limit: Number(token2.modelContextWindow) } : {} };
|
|
5217
|
+
io.gotContext?.(context);
|
|
5218
|
+
}
|
|
5219
|
+
if (msg.method === "error" && p.willRetry !== true) end2(str(obj(p.error).message) || "Codex failed.");
|
|
5220
|
+
if (msg.method === "turn/completed") {
|
|
5221
|
+
const turn2 = obj(p.turn);
|
|
5222
|
+
const id = str(turn2.id);
|
|
5223
|
+
if (completedTurns.has(id)) return;
|
|
5224
|
+
completedTurns.add(id);
|
|
5225
|
+
for (const raw of list(turn2.items)) item(raw, true);
|
|
5226
|
+
if (turn2.status !== "completed") {
|
|
5227
|
+
end2(str(obj(turn2.error).message) || `Codex turn ${str(turn2.status)}.`);
|
|
5228
|
+
return;
|
|
5229
|
+
}
|
|
5230
|
+
active2 = false;
|
|
5231
|
+
for (const id2 of commands) tasks.update(`command:${id2}`, "running");
|
|
5232
|
+
waiting ||= tasks.count() > 0 || commands.size > 0;
|
|
5233
|
+
deadline.pending();
|
|
5234
|
+
void check();
|
|
5235
|
+
}
|
|
5236
|
+
});
|
|
5237
|
+
try {
|
|
5238
|
+
await rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } });
|
|
5239
|
+
rpc.notify("initialized");
|
|
5240
|
+
const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
|
|
5241
|
+
let response;
|
|
5242
|
+
try {
|
|
5243
|
+
response = await rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} });
|
|
5244
|
+
} catch (e) {
|
|
5245
|
+
if (mode && e instanceof RpcError && /no rollout found for thread id/i.test(e.message)) throw Error(`Thread not found: ${e.message}`);
|
|
5246
|
+
throw e;
|
|
5247
|
+
}
|
|
5248
|
+
const thread = obj(response.thread);
|
|
5249
|
+
threadId = str(thread.id);
|
|
5250
|
+
if (!threadId) throw Error("Codex did not return a thread id.");
|
|
5251
|
+
provider = str(thread.modelProvider) || void 0;
|
|
5252
|
+
model = str(response.model) || str(thread.model) || void 0;
|
|
5253
|
+
if (model) io.gotModel(model);
|
|
5254
|
+
io.gotResumeId(threadId);
|
|
5255
|
+
baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
|
|
5256
|
+
emit("thread.started", { thread_id: threadId });
|
|
5257
|
+
await start(io.prompt, options.images);
|
|
5258
|
+
} catch (e) {
|
|
5259
|
+
end2(e instanceof Error ? e.message : String(e));
|
|
5260
|
+
}
|
|
5261
|
+
return done2;
|
|
5262
|
+
}
|
|
5263
|
+
var list;
|
|
5264
|
+
var init_codex = __esm({
|
|
5265
|
+
"../cli/src/lib/agent/wire/codex.ts"() {
|
|
5266
|
+
"use strict";
|
|
5267
|
+
init_settings();
|
|
5268
|
+
init_background();
|
|
5269
|
+
init_codex_stream();
|
|
5270
|
+
init_codex_session();
|
|
5271
|
+
init_json();
|
|
5272
|
+
init_events();
|
|
5273
|
+
init_rpc();
|
|
5274
|
+
init_prices();
|
|
5275
|
+
list = (value) => Array.isArray(value) ? value.map(obj) : [];
|
|
5276
|
+
}
|
|
5277
|
+
});
|
|
5278
|
+
|
|
4847
5279
|
// ../cli/src/lib/agent/wire/index.ts
|
|
4848
5280
|
var init_wire = __esm({
|
|
4849
5281
|
"../cli/src/lib/agent/wire/index.ts"() {
|
|
@@ -4855,6 +5287,8 @@ var init_wire = __esm({
|
|
|
4855
5287
|
init_kimi_stream();
|
|
4856
5288
|
init_acp();
|
|
4857
5289
|
init_zcode();
|
|
5290
|
+
init_codex();
|
|
5291
|
+
init_background();
|
|
4858
5292
|
}
|
|
4859
5293
|
});
|
|
4860
5294
|
|
|
@@ -4877,8 +5311,8 @@ function str2(value) {
|
|
|
4877
5311
|
function num2(value) {
|
|
4878
5312
|
return typeof value === "number" ? value : Number.MAX_SAFE_INTEGER;
|
|
4879
5313
|
}
|
|
4880
|
-
function uniqueIds(
|
|
4881
|
-
return [...new Set(
|
|
5314
|
+
function uniqueIds(list2) {
|
|
5315
|
+
return [...new Set(list2.map((id) => id.trim()).filter(Boolean))];
|
|
4882
5316
|
}
|
|
4883
5317
|
function modelsIn2(file, pick2, salt = "") {
|
|
4884
5318
|
let stamp4;
|
|
@@ -5403,7 +5837,7 @@ function codexInstalls() {
|
|
|
5403
5837
|
];
|
|
5404
5838
|
}
|
|
5405
5839
|
var QUIET_CONFIG, ARCHES, CODEX;
|
|
5406
|
-
var
|
|
5840
|
+
var init_codex2 = __esm({
|
|
5407
5841
|
"../cli/src/lib/agent/harnesses/codex.ts"() {
|
|
5408
5842
|
"use strict";
|
|
5409
5843
|
init_paths();
|
|
@@ -5425,6 +5859,7 @@ var init_codex = __esm({
|
|
|
5425
5859
|
"codex exec --json --sandbox workspace-write",
|
|
5426
5860
|
"codex exec --json --sandbox workspace-write -c sandbox_workspace_write.network_access=true"
|
|
5427
5861
|
],
|
|
5862
|
+
connection: createCodexConnection,
|
|
5428
5863
|
installs: codexInstalls,
|
|
5429
5864
|
pinned: () => process.env.CODEX_CLI_PATH?.trim() || void 0,
|
|
5430
5865
|
// Nothing to pin: Codex mints its own thread id and takes none from us, so the generated
|
|
@@ -6376,7 +6811,7 @@ var init_harnesses = __esm({
|
|
|
6376
6811
|
"use strict";
|
|
6377
6812
|
init_check();
|
|
6378
6813
|
init_claude_code();
|
|
6379
|
-
|
|
6814
|
+
init_codex2();
|
|
6380
6815
|
init_cursor();
|
|
6381
6816
|
init_dsh();
|
|
6382
6817
|
init_grok();
|
|
@@ -6659,8 +7094,8 @@ function settingArgs(harness, held4) {
|
|
|
6659
7094
|
const { values } = held4;
|
|
6660
7095
|
const ignored = held4.ignored ?? [];
|
|
6661
7096
|
const picked = providerFor(harness, held4);
|
|
6662
|
-
const
|
|
6663
|
-
const byHand = !!
|
|
7097
|
+
const list2 = providerSetting(harness.settings);
|
|
7098
|
+
const byHand = !!list2 && ignored.includes(list2.key);
|
|
6664
7099
|
const providerArgs = byHand ? [] : picked?.args ?? [];
|
|
6665
7100
|
const flags = harness.settings.flatMap((setting) => {
|
|
6666
7101
|
const value = values[setting.key];
|
|
@@ -6690,9 +7125,9 @@ function settingEnv(harness, held4, secrets, cwd) {
|
|
|
6690
7125
|
}
|
|
6691
7126
|
function ownedVars(harness) {
|
|
6692
7127
|
const names3 = new Set(harness.providerEnv ?? []);
|
|
6693
|
-
const
|
|
6694
|
-
if (!
|
|
6695
|
-
for (const provider of
|
|
7128
|
+
const list2 = providerSetting(harness.settings);
|
|
7129
|
+
if (!list2) return [...names3];
|
|
7130
|
+
for (const provider of list2.providers ?? []) {
|
|
6696
7131
|
for (const name of Object.values(provider.envAs ?? {})) names3.add(name);
|
|
6697
7132
|
for (const name of Object.keys(provider.env ?? {})) names3.add(name);
|
|
6698
7133
|
for (const key of provider.needs) {
|
|
@@ -7194,17 +7629,17 @@ function noteRefineTried(store, cardId2) {
|
|
|
7194
7629
|
}
|
|
7195
7630
|
function cardsBeingCreated(runs = readRuns()) {
|
|
7196
7631
|
const newest2 = /* @__PURE__ */ new Map();
|
|
7197
|
-
for (const
|
|
7198
|
-
for (const id of
|
|
7199
|
-
if (
|
|
7632
|
+
for (const run3 of runs) {
|
|
7633
|
+
for (const id of run3.createdCardIds ?? []) {
|
|
7634
|
+
if (run3.cardId === id) continue;
|
|
7200
7635
|
const best = newest2.get(id);
|
|
7201
|
-
if (!best ||
|
|
7636
|
+
if (!best || run3.startedAt >= best.startedAt) newest2.set(id, run3);
|
|
7202
7637
|
}
|
|
7203
7638
|
}
|
|
7204
7639
|
const out = /* @__PURE__ */ new Map();
|
|
7205
|
-
for (const [id,
|
|
7206
|
-
if (runIsLive(
|
|
7207
|
-
else if (
|
|
7640
|
+
for (const [id, run3] of newest2) {
|
|
7641
|
+
if (runIsLive(run3)) out.set(id, { state: "creating", runId: run3.sessionId });
|
|
7642
|
+
else if (run3.status !== "done") out.set(id, { state: "unfinished", runId: run3.sessionId });
|
|
7208
7643
|
}
|
|
7209
7644
|
return out;
|
|
7210
7645
|
}
|
|
@@ -7462,9 +7897,9 @@ function recordCreatedCards(sessionId, ids) {
|
|
|
7462
7897
|
const valid = ids.filter((id) => Number.isInteger(id) && id > 0);
|
|
7463
7898
|
if (!valid.length) return false;
|
|
7464
7899
|
return withRuns((runs) => {
|
|
7465
|
-
const
|
|
7466
|
-
if (!
|
|
7467
|
-
|
|
7900
|
+
const run3 = runs.find((entry) => entry.sessionId === sessionId && entry.status === "running");
|
|
7901
|
+
if (!run3) return false;
|
|
7902
|
+
run3.createdCardIds = [.../* @__PURE__ */ new Set([...run3.createdCardIds ?? [], ...valid])];
|
|
7468
7903
|
return true;
|
|
7469
7904
|
});
|
|
7470
7905
|
}
|
|
@@ -7506,7 +7941,7 @@ var init_store = __esm({
|
|
|
7506
7941
|
stringRecord = (raw) => raw && typeof raw === "object" && !Array.isArray(raw) && Object.values(raw).every((v) => typeof v === "string") ? raw : void 0;
|
|
7507
7942
|
readRuns = () => readStore().runs;
|
|
7508
7943
|
PENDING_MS = 3e4;
|
|
7509
|
-
runIsLive = (
|
|
7944
|
+
runIsLive = (run3) => run3.status === "running" && (run3.pid ? pidAlive(run3.pid) : Date.now() - run3.startedAt < PENDING_MS);
|
|
7510
7945
|
creationOf = (runs, cardId2) => cardsBeingCreated(runs).get(cardId2);
|
|
7511
7946
|
cardCreation = (cardId2, strict = false) => {
|
|
7512
7947
|
const runs = readRuns();
|
|
@@ -7655,9 +8090,9 @@ var init_flows = __esm({
|
|
|
7655
8090
|
import fs25 from "node:fs";
|
|
7656
8091
|
function readRuntimes(cfg = safeConfig()) {
|
|
7657
8092
|
const saved = Array.isArray(cfg.runtimes) ? cfg.runtimes.map(parseRuntime).filter(isRuntime) : null;
|
|
7658
|
-
const
|
|
7659
|
-
const global =
|
|
7660
|
-
const rest =
|
|
8093
|
+
const list2 = saved?.length ? dedupe(saved) : fromHarnessBlocks(cfg);
|
|
8094
|
+
const global = list2.find((r) => r.id === GLOBAL_ID);
|
|
8095
|
+
const rest = list2.filter((r) => r.id !== GLOBAL_ID);
|
|
7661
8096
|
return [global ?? { id: GLOBAL_ID, name: GLOBAL_NAME, harness: DEFAULT_HARNESS.name, settings: {} }, ...rest];
|
|
7662
8097
|
}
|
|
7663
8098
|
function parseRuntime(value) {
|
|
@@ -7673,15 +8108,15 @@ function parseRuntime(value) {
|
|
|
7673
8108
|
const away = typeof raw.away === "string" && raw.away.trim() ? { away: raw.away.trim() } : {};
|
|
7674
8109
|
return { id, name: id === GLOBAL_ID ? GLOBAL_NAME : name, harness, settings, ...away };
|
|
7675
8110
|
}
|
|
7676
|
-
function dedupe(
|
|
8111
|
+
function dedupe(list2) {
|
|
7677
8112
|
const seen = /* @__PURE__ */ new Set();
|
|
7678
|
-
return
|
|
8113
|
+
return list2.filter((r) => !seen.has(r.id) && seen.add(r.id));
|
|
7679
8114
|
}
|
|
7680
8115
|
function fromHarnessBlocks(cfg) {
|
|
7681
8116
|
const asked = typeof cfg.harness === "string" ? cfg.harness.trim() : "";
|
|
7682
8117
|
const fallback = (harnessByName(asked) ?? DEFAULT_HARNESS).name;
|
|
7683
8118
|
const blocks = configBlock(cfg.harnessSettings);
|
|
7684
|
-
const
|
|
8119
|
+
const list2 = [
|
|
7685
8120
|
{ id: GLOBAL_ID, name: GLOBAL_NAME, harness: asked || fallback, settings: valuesOf(blocks[asked || fallback]) }
|
|
7686
8121
|
];
|
|
7687
8122
|
const taken = /* @__PURE__ */ new Set([GLOBAL_ID]);
|
|
@@ -7689,9 +8124,9 @@ function fromHarnessBlocks(cfg) {
|
|
|
7689
8124
|
if (harness === (asked || fallback)) continue;
|
|
7690
8125
|
const id = freeId(harness, taken);
|
|
7691
8126
|
taken.add(id);
|
|
7692
|
-
|
|
8127
|
+
list2.push({ id, name: harnessByName(harness)?.label ?? harness, harness, settings: valuesOf(block) });
|
|
7693
8128
|
}
|
|
7694
|
-
return
|
|
8129
|
+
return list2;
|
|
7695
8130
|
}
|
|
7696
8131
|
function valuesOf(block) {
|
|
7697
8132
|
const out = {};
|
|
@@ -7700,15 +8135,15 @@ function valuesOf(block) {
|
|
|
7700
8135
|
}
|
|
7701
8136
|
return out;
|
|
7702
8137
|
}
|
|
7703
|
-
function pickRuntime(
|
|
7704
|
-
const rows = harness ?
|
|
8138
|
+
function pickRuntime(list2, pin, harness) {
|
|
8139
|
+
const rows = harness ? list2.filter((r) => r.harness === harness) : list2;
|
|
7705
8140
|
const want = pin?.trim();
|
|
7706
8141
|
const found2 = want && (rows.find((r) => r.id === want) ?? rows.find((r) => r.harness === want));
|
|
7707
8142
|
if (found2) return found2;
|
|
7708
8143
|
return rows[0] ?? { id: "", name: harness ?? "", harness: harness ?? DEFAULT_HARNESS.name, settings: {} };
|
|
7709
8144
|
}
|
|
7710
|
-
function runtimeById(id,
|
|
7711
|
-
return
|
|
8145
|
+
function runtimeById(id, list2 = readRuntimes()) {
|
|
8146
|
+
return list2.find((r) => r.id === id);
|
|
7712
8147
|
}
|
|
7713
8148
|
function secretVar(env2, runtimeId) {
|
|
7714
8149
|
return `${env2}__${runtimeId.replace(/[^A-Za-z0-9]+/g, "_").toUpperCase()}`;
|
|
@@ -7775,23 +8210,23 @@ function setHarness(name) {
|
|
|
7775
8210
|
return setRuntimeHarness(GLOBAL_ID, name);
|
|
7776
8211
|
}
|
|
7777
8212
|
function change(id, edit) {
|
|
7778
|
-
const
|
|
7779
|
-
if (!
|
|
7780
|
-
return save(
|
|
8213
|
+
const list2 = readRuntimes();
|
|
8214
|
+
if (!list2.some((r) => r.id === id)) return { ok: false, ...noRuntime(id) };
|
|
8215
|
+
return save(list2.map((r) => r.id === id ? edit(r) : r));
|
|
7781
8216
|
}
|
|
7782
|
-
function save(
|
|
8217
|
+
function save(list2) {
|
|
7783
8218
|
return writeConfig((cfg) => {
|
|
7784
8219
|
const picks = readAgentRuntime(cfg);
|
|
7785
|
-
cfg.runtimes =
|
|
8220
|
+
cfg.runtimes = list2;
|
|
7786
8221
|
delete cfg.harnessSettings;
|
|
7787
8222
|
delete cfg.harness;
|
|
7788
|
-
writePicks(cfg, picks,
|
|
8223
|
+
writePicks(cfg, picks, list2);
|
|
7789
8224
|
});
|
|
7790
8225
|
}
|
|
7791
|
-
function writePicks(cfg, picks,
|
|
8226
|
+
function writePicks(cfg, picks, list2 = readRuntimes(cfg)) {
|
|
7792
8227
|
const block = {};
|
|
7793
8228
|
for (const [agent, pin] of Object.entries(picks)) {
|
|
7794
|
-
const row = pickRuntime(
|
|
8229
|
+
const row = pickRuntime(list2, pin);
|
|
7795
8230
|
if (keepsPick(row.id)) block[agent] = row.id;
|
|
7796
8231
|
}
|
|
7797
8232
|
delete cfg.agentHarness;
|
|
@@ -7816,13 +8251,13 @@ function migrateRuntimes(agents, localModels) {
|
|
|
7816
8251
|
return null;
|
|
7817
8252
|
}
|
|
7818
8253
|
if (Array.isArray(cfg.runtimes) && cfg.runtimes.length) return null;
|
|
7819
|
-
const
|
|
7820
|
-
const taken = new Set(
|
|
8254
|
+
const list2 = fromHarnessBlocks(cfg);
|
|
8255
|
+
const taken = new Set(list2.map((r) => r.id));
|
|
7821
8256
|
const picks = {};
|
|
7822
8257
|
const bound = configBlock(cfg.agentHarness);
|
|
7823
8258
|
for (const agent of agents) {
|
|
7824
8259
|
const named2 = typeof bound[agent] === "string" ? bound[agent].trim() : "";
|
|
7825
|
-
const base = pickRuntime(
|
|
8260
|
+
const base = pickRuntime(list2, named2 || void 0);
|
|
7826
8261
|
const model = localModels[agent]?.[base.harness] ?? {};
|
|
7827
8262
|
if (!Object.keys(model).length || sameValues(base.settings, model)) {
|
|
7828
8263
|
if (named2 && base.id !== GLOBAL_ID) picks[agent] = base.id;
|
|
@@ -7830,17 +8265,17 @@ function migrateRuntimes(agents, localModels) {
|
|
|
7830
8265
|
}
|
|
7831
8266
|
const id = freeId(agent, taken);
|
|
7832
8267
|
taken.add(id);
|
|
7833
|
-
|
|
8268
|
+
list2.push({ id, name: agent, harness: base.harness, settings: { ...base.settings, ...model } });
|
|
7834
8269
|
picks[agent] = id;
|
|
7835
8270
|
}
|
|
7836
|
-
cfg.runtimes =
|
|
8271
|
+
cfg.runtimes = list2;
|
|
7837
8272
|
if (Object.keys(picks).length) cfg.agentRuntime = picks;
|
|
7838
8273
|
delete cfg.harness;
|
|
7839
8274
|
delete cfg.harnessSettings;
|
|
7840
8275
|
delete cfg.agentHarness;
|
|
7841
8276
|
fs25.writeFileSync(UI_CONFIG, JSON.stringify(cfg, null, 2) + "\n");
|
|
7842
|
-
const minted =
|
|
7843
|
-
return `turned this board's connector settings into ${
|
|
8277
|
+
const minted = list2.length - 1;
|
|
8278
|
+
return `turned this board's connector settings into ${list2.length} runtime${list2.length === 1 ? "" : "s"}${minted ? ` \u2014 ${GLOBAL_NAME} and ${minted} more` : ""}, and pointed each agent at one`;
|
|
7844
8279
|
}
|
|
7845
8280
|
function repairEnvFile() {
|
|
7846
8281
|
const env2 = readEnvFile();
|
|
@@ -7927,11 +8362,11 @@ function readBlock(harness, block, argv, runtimeId) {
|
|
|
7927
8362
|
if (value) values[setting.key] = value;
|
|
7928
8363
|
if (setting.flags?.length && namesFlag(argv, setting.flags)) ignored.push(setting.key);
|
|
7929
8364
|
}
|
|
7930
|
-
const
|
|
7931
|
-
if (
|
|
7932
|
-
const picked = pickedProvider(
|
|
7933
|
-
if (picked) values[
|
|
7934
|
-
else delete values[
|
|
8365
|
+
const list2 = providerSetting(harness.settings);
|
|
8366
|
+
if (list2) {
|
|
8367
|
+
const picked = pickedProvider(list2, values[list2.key] ?? "", isFilled(harness, { values, secretsSet }));
|
|
8368
|
+
if (picked) values[list2.key] = picked.id;
|
|
8369
|
+
else delete values[list2.key];
|
|
7935
8370
|
}
|
|
7936
8371
|
return { values, secretsSet, ignored };
|
|
7937
8372
|
}
|
|
@@ -7950,13 +8385,13 @@ function resolveHarness(ask2 = {}) {
|
|
|
7950
8385
|
const cfg = safeConfig();
|
|
7951
8386
|
const staleCommand = typeof cfg.command === "string" && cfg.command.trim() ? true : void 0;
|
|
7952
8387
|
const agent = ask2.agent ?? "";
|
|
7953
|
-
const
|
|
8388
|
+
const list2 = readRuntimes(cfg);
|
|
7954
8389
|
const table = readAgentRuntime(cfg);
|
|
7955
8390
|
const owner = agent ? runtimeOwner(agent) : "";
|
|
7956
8391
|
const picked = owner ? runtimeOfAgent(specAgentNames(owner), table) : void 0;
|
|
7957
8392
|
const asked = ask2.pin ?? picked;
|
|
7958
|
-
const runtime = pickRuntime(
|
|
7959
|
-
const unknownAgentRuntime = picked && !ask2.pin && !
|
|
8393
|
+
const runtime = pickRuntime(list2, asked, ask2.harness);
|
|
8394
|
+
const unknownAgentRuntime = picked && !ask2.pin && !list2.some((r) => r.id === picked || r.harness === picked) ? picked : void 0;
|
|
7960
8395
|
const known2 = harnessByName(runtime.harness);
|
|
7961
8396
|
const harness = known2 ?? DEFAULT_HARNESS;
|
|
7962
8397
|
const command = commandOf(runtime.settings, harness);
|
|
@@ -7995,13 +8430,13 @@ function agentHarness(agent) {
|
|
|
7995
8430
|
function settingSaveError(key, value, ask2 = {}) {
|
|
7996
8431
|
const resolved2 = resolveHarness(ask2);
|
|
7997
8432
|
const { harness, values, secretsSet } = resolved2;
|
|
7998
|
-
const
|
|
7999
|
-
if (!
|
|
8433
|
+
const list2 = providerSetting(harness.settings);
|
|
8434
|
+
if (!list2) return null;
|
|
8000
8435
|
const filled = isFilled(harness, { values, secretsSet });
|
|
8001
8436
|
const label = (k) => harness.settings.find((s) => s.key === k)?.label ?? k;
|
|
8002
|
-
if (key ===
|
|
8003
|
-
const provider =
|
|
8004
|
-
if (!provider) return `"${value}" isn't one of the ${
|
|
8437
|
+
if (key === list2.key) {
|
|
8438
|
+
const provider = list2.providers?.find((p) => p.id === value);
|
|
8439
|
+
if (!provider) return `"${value}" isn't one of the ${list2.label.toLowerCase()} choices`;
|
|
8005
8440
|
const missing = missingHere(harness, provider, filled);
|
|
8006
8441
|
if (missing.length) {
|
|
8007
8442
|
const names3 = missing.map((k) => `"${label(k)}"`).join(" and ");
|
|
@@ -8085,20 +8520,21 @@ function openPlan(plan) {
|
|
|
8085
8520
|
const started = [start.binary, ...plan.argv.slice(1)];
|
|
8086
8521
|
const { argv, env: planned, note } = withSystemLanguage(harness, started, runEnv2(resolved2, plan.cwd ?? REPO_ROOT), runLanguage());
|
|
8087
8522
|
const env2 = copyEnv(start.binary, planned);
|
|
8523
|
+
const connection = harness.connection?.(argv);
|
|
8088
8524
|
return {
|
|
8089
8525
|
...plan,
|
|
8090
|
-
argv,
|
|
8526
|
+
argv: connection?.argv ?? argv,
|
|
8091
8527
|
...[start.note, note].some(Boolean) ? { startNote: [start.note, note].filter(Boolean).join("\n") } : {},
|
|
8092
8528
|
env: env2,
|
|
8093
8529
|
// The folder and the binary: what a renderer needs to go looking for what the stream
|
|
8094
8530
|
// left out (agent/harnesses/types.ts). argv's first word is the command's own binary,
|
|
8095
8531
|
// the same one the spawn resolves and an ENOENT names.
|
|
8096
|
-
renderer: harness.renderer?.(plan.cwd ?? REPO_ROOT, argv[0], argv),
|
|
8532
|
+
renderer: connection ? void 0 : harness.renderer?.(plan.cwd ?? REPO_ROOT, argv[0], argv),
|
|
8097
8533
|
// The client is handed the settings that are actually in effect — the same ones that
|
|
8098
8534
|
// would have reached the run as flags, minus whatever the picked provider doesn't
|
|
8099
8535
|
// need — because for a connector that talks, a setting is something the conversation
|
|
8100
8536
|
// opens with rather than something argv carries.
|
|
8101
|
-
client: harness.client?.(effectiveValues2(resolved2)),
|
|
8537
|
+
client: connection?.client ?? harness.client?.(effectiveValues2(resolved2)),
|
|
8102
8538
|
// Read off the argv, so a plan written before the CLI took its turns on stdin still runs.
|
|
8103
8539
|
stdinPrompt: harness.stdinPrompt?.(argv),
|
|
8104
8540
|
quietStderr: harness.quietStderr,
|
|
@@ -8127,11 +8563,11 @@ function modelsRun() {
|
|
|
8127
8563
|
const ran = /* @__PURE__ */ new Map();
|
|
8128
8564
|
const { runs } = readStore();
|
|
8129
8565
|
for (let i = runs.length - 1; i >= 0; i--) {
|
|
8130
|
-
const
|
|
8131
|
-
if (!
|
|
8132
|
-
const seen = ran.get(
|
|
8133
|
-
if (!seen.includes(
|
|
8134
|
-
ran.set(
|
|
8566
|
+
const run3 = runs[i];
|
|
8567
|
+
if (!run3.harness || !run3.model) continue;
|
|
8568
|
+
const seen = ran.get(run3.harness) ?? [];
|
|
8569
|
+
if (!seen.includes(run3.model)) seen.push(run3.model);
|
|
8570
|
+
ran.set(run3.harness, seen);
|
|
8135
8571
|
}
|
|
8136
8572
|
return ran;
|
|
8137
8573
|
}
|
|
@@ -9441,7 +9877,7 @@ var init_yaml2 = __esm({
|
|
|
9441
9877
|
});
|
|
9442
9878
|
|
|
9443
9879
|
// ../cli/src/lib/agents/parse.ts
|
|
9444
|
-
function parseSpecAgent(text4, from, file, builtIn = false,
|
|
9880
|
+
function parseSpecAgent(text4, from, file, builtIn = false, list2 = () => []) {
|
|
9445
9881
|
let named2 = "";
|
|
9446
9882
|
const bad = (why2, old2) => ({
|
|
9447
9883
|
problem: `${from}: ${why2}`,
|
|
@@ -9503,7 +9939,7 @@ function parseSpecAgent(text4, from, file, builtIn = false, list = () => []) {
|
|
|
9503
9939
|
...declaredSession ? { session: "new" } : {},
|
|
9504
9940
|
memory: names(akb.memory),
|
|
9505
9941
|
memoryFiles: { workspace: workspace2 },
|
|
9506
|
-
files:
|
|
9942
|
+
files: list2(),
|
|
9507
9943
|
body: instructions,
|
|
9508
9944
|
from,
|
|
9509
9945
|
builtIn,
|
|
@@ -9532,12 +9968,12 @@ function memoryPaths(raw, folder = "memory/agents/<name>/") {
|
|
|
9532
9968
|
const block = map(raw);
|
|
9533
9969
|
const extra = block ? Object.keys(block).filter((key) => key !== "workspace") : [];
|
|
9534
9970
|
if (!block || extra.length) return `\`akb.memoryFiles\` with ${block ? `\`${extra.join("`, `")}\`` : "no `workspace:` list"} \u2014 it holds only \`workspace: [<path>, ...]\``;
|
|
9535
|
-
const
|
|
9536
|
-
if (
|
|
9537
|
-
if (!Array.isArray(
|
|
9971
|
+
const list2 = block.workspace;
|
|
9972
|
+
if (list2 === void 0) return [];
|
|
9973
|
+
if (!Array.isArray(list2) || list2.some((v) => typeof v !== "string" || !v.trim())) {
|
|
9538
9974
|
return "`akb.memoryFiles.workspace` that is not a list of paths \u2014 write `workspace: [style.md]`";
|
|
9539
9975
|
}
|
|
9540
|
-
const paths = [...new Set(
|
|
9976
|
+
const paths = [...new Set(list2.map((v) => v.trim()))];
|
|
9541
9977
|
const outside = paths.find((p) => p.startsWith("/") || p.includes("\\") || p.split("/").some((part) => part === ".." || part === "."));
|
|
9542
9978
|
if (outside) return `\`akb.memoryFiles.workspace: ${outside}\`, which is outside its memory folder \u2014 use a path inside \`${folder}\``;
|
|
9543
9979
|
return paths;
|
|
@@ -10046,8 +10482,8 @@ function readFlows() {
|
|
|
10046
10482
|
}
|
|
10047
10483
|
const project2 = boardProject();
|
|
10048
10484
|
if (!project2 || !readSession()) return [];
|
|
10049
|
-
const
|
|
10050
|
-
const flows2 =
|
|
10485
|
+
const list2 = readJson(listFile(project2))?.studios ?? [];
|
|
10486
|
+
const flows2 = list2.flatMap((w) => {
|
|
10051
10487
|
const held4 = readVersion(w.id, w.version);
|
|
10052
10488
|
return held4 ? flowOf(held4) ?? [] : [];
|
|
10053
10489
|
});
|
|
@@ -10242,8 +10678,8 @@ function readBundled(folder) {
|
|
|
10242
10678
|
const file = (relative) => shipped[`${folder}/${relative}`] ?? null;
|
|
10243
10679
|
const text4 = file("AGENT.md");
|
|
10244
10680
|
if (text4 === null) return { problem: `${label} has no AGENT.md` };
|
|
10245
|
-
const
|
|
10246
|
-
return parseSpecAgent(text4, label, file, official,
|
|
10681
|
+
const list2 = () => ownFiles(Object.keys(shipped).filter((k) => k.startsWith(`${folder}/`)).map((k) => k.slice(folder.length + 1)));
|
|
10682
|
+
return parseSpecAgent(text4, label, file, official, list2);
|
|
10247
10683
|
}
|
|
10248
10684
|
function projectFolders(root2) {
|
|
10249
10685
|
let entries;
|
|
@@ -10936,8 +11372,8 @@ async function queryPreviews(studio, workspace2) {
|
|
|
10936
11372
|
if (externalGoalSession()) return withGoalDiscussion(() => cmdGoalPreviews(studio));
|
|
10937
11373
|
die("--workspace is required outside a goal discussion.");
|
|
10938
11374
|
}
|
|
10939
|
-
const
|
|
10940
|
-
const flow =
|
|
11375
|
+
const list2 = await studios2(workspace2);
|
|
11376
|
+
const flow = list2.find((w) => w.id === studio || shortStudioId(w.id) === studio);
|
|
10941
11377
|
if (!flow) die(`No studio \`${studio}\` here.`);
|
|
10942
11378
|
if (!flow.previews) die("Preview agents are unavailable; update Runner and try again.");
|
|
10943
11379
|
const agents = flow.previews.map((p) => ({ name: p.agent, when: p.when || null }));
|
|
@@ -15553,23 +15989,23 @@ import path49 from "node:path";
|
|
|
15553
15989
|
function writeAudit(delivery, runs) {
|
|
15554
15990
|
const known2 = new Map(readAudit(delivery.deliveryId)?.sessions.map((s) => [s.sessionId, s]) ?? []);
|
|
15555
15991
|
const sessions = delivery.sessions.flatMap((id) => {
|
|
15556
|
-
const
|
|
15557
|
-
if (!
|
|
15992
|
+
const run3 = runs.find((r) => r.sessionId === id);
|
|
15993
|
+
if (!run3) {
|
|
15558
15994
|
const before = known2.get(id);
|
|
15559
15995
|
return before ? [before] : [];
|
|
15560
15996
|
}
|
|
15561
15997
|
return [
|
|
15562
15998
|
{
|
|
15563
|
-
sessionId:
|
|
15564
|
-
action:
|
|
15565
|
-
status:
|
|
15566
|
-
startedAt:
|
|
15567
|
-
endedAt:
|
|
15568
|
-
harness:
|
|
15569
|
-
model:
|
|
15570
|
-
costUsd:
|
|
15571
|
-
resumedFrom:
|
|
15572
|
-
log: rel(
|
|
15999
|
+
sessionId: run3.sessionId,
|
|
16000
|
+
action: run3.action,
|
|
16001
|
+
status: run3.status,
|
|
16002
|
+
startedAt: run3.startedAt,
|
|
16003
|
+
endedAt: run3.endedAt,
|
|
16004
|
+
harness: run3.harness || void 0,
|
|
16005
|
+
model: run3.model,
|
|
16006
|
+
costUsd: run3.costUsd,
|
|
16007
|
+
resumedFrom: run3.resumedFrom,
|
|
16008
|
+
log: rel(run3.logPath)
|
|
15573
16009
|
}
|
|
15574
16010
|
];
|
|
15575
16011
|
});
|
|
@@ -15647,7 +16083,7 @@ function settleOrphanedDeliveries() {
|
|
|
15647
16083
|
const recovered = [];
|
|
15648
16084
|
withStore((store) => {
|
|
15649
16085
|
const known2 = new Set(store.deliveries.map((d) => d.deliveryId));
|
|
15650
|
-
for (const
|
|
16086
|
+
for (const run3 of store.runs) if (run3.deliveryId) known2.add(run3.deliveryId);
|
|
15651
16087
|
for (const audit of audits) {
|
|
15652
16088
|
if (known2.has(audit.deliveryId) || !localAudit(audit)) continue;
|
|
15653
16089
|
if (lastSessionRunning(audit)) {
|
|
@@ -15858,16 +16294,16 @@ function deliveryFor(req) {
|
|
|
15858
16294
|
}
|
|
15859
16295
|
return req.id === void 0 ? void 0 : activeDelivery(req.id);
|
|
15860
16296
|
}
|
|
15861
|
-
function joinDelivery(store,
|
|
15862
|
-
const cardId2 =
|
|
15863
|
-
let delivery =
|
|
16297
|
+
function joinDelivery(store, run3, title, step, start, direct) {
|
|
16298
|
+
const cardId2 = run3.cardId;
|
|
16299
|
+
let delivery = run3.deliveryId ? store.deliveries.find((d) => d.deliveryId === run3.deliveryId && d.status === "active") : cardId2 === null ? void 0 : activeIn(store, cardId2);
|
|
15864
16300
|
if (!delivery) {
|
|
15865
16301
|
delivery = {
|
|
15866
16302
|
deliveryId: start?.deliveryId ?? newDeliveryId(store.deliveries),
|
|
15867
16303
|
cardId: cardId2,
|
|
15868
16304
|
title,
|
|
15869
16305
|
status: "active",
|
|
15870
|
-
startedAt:
|
|
16306
|
+
startedAt: run3.startedAt,
|
|
15871
16307
|
sessions: [],
|
|
15872
16308
|
// The one read of the card this delivery will ever make for its requirements — or,
|
|
15873
16309
|
// with no card, the sentence or the plan's words it was handed, which can never move
|
|
@@ -15902,21 +16338,21 @@ function joinDelivery(store, run2, title, step, start, direct) {
|
|
|
15902
16338
|
} else if (step === "implement" && delivery.review?.stopped) {
|
|
15903
16339
|
delivery.review.stopped = void 0;
|
|
15904
16340
|
}
|
|
15905
|
-
delivery.sessions.push(
|
|
15906
|
-
delivery.steps.push({ step, at:
|
|
15907
|
-
joinFlow(
|
|
16341
|
+
delivery.sessions.push(run3.sessionId);
|
|
16342
|
+
delivery.steps.push({ step, at: run3.startedAt });
|
|
16343
|
+
joinFlow(run3, delivery);
|
|
15908
16344
|
writeAudit(delivery, store.runs);
|
|
15909
16345
|
return delivery;
|
|
15910
16346
|
}
|
|
15911
16347
|
function adoptDirectCard(sessionId, cardId2) {
|
|
15912
16348
|
return withStore((store) => {
|
|
15913
|
-
const
|
|
15914
|
-
if (!
|
|
15915
|
-
const delivery =
|
|
15916
|
-
if (
|
|
16349
|
+
const run3 = store.runs.find((r) => r.sessionId === sessionId && r.status === "running");
|
|
16350
|
+
if (!run3 || run3.action !== "implement" || run3.cardId !== null) return false;
|
|
16351
|
+
const delivery = run3.deliveryId ? store.deliveries.find((d) => d.deliveryId === run3.deliveryId && d.status === "active") : void 0;
|
|
16352
|
+
if (run3.deliveryId && (!delivery || delivery.cardId !== null)) return false;
|
|
15917
16353
|
const idle = "ready";
|
|
15918
|
-
|
|
15919
|
-
|
|
16354
|
+
run3.cardId = cardId2;
|
|
16355
|
+
run3.priorStatus = idle;
|
|
15920
16356
|
if (!delivery) return true;
|
|
15921
16357
|
delivery.cardId = cardId2;
|
|
15922
16358
|
delivery.priorStatus = idle;
|
|
@@ -15924,21 +16360,21 @@ function adoptDirectCard(sessionId, cardId2) {
|
|
|
15924
16360
|
return true;
|
|
15925
16361
|
});
|
|
15926
16362
|
}
|
|
15927
|
-
function joinActive(store,
|
|
15928
|
-
const delivery = deliveryId ? store.deliveries.find((d) => d.status === "active" && d.deliveryId === deliveryId) :
|
|
16363
|
+
function joinActive(store, run3, step, deliveryId) {
|
|
16364
|
+
const delivery = deliveryId ? store.deliveries.find((d) => d.status === "active" && d.deliveryId === deliveryId) : run3.cardId === null ? void 0 : activeIn(store, run3.cardId);
|
|
15929
16365
|
if (!delivery) return void 0;
|
|
15930
|
-
delivery.sessions.push(
|
|
15931
|
-
delivery.steps.push({ step, at:
|
|
16366
|
+
delivery.sessions.push(run3.sessionId);
|
|
16367
|
+
delivery.steps.push({ step, at: run3.startedAt });
|
|
15932
16368
|
if (delivery.review?.stopped) delivery.review.stopped = void 0;
|
|
15933
16369
|
const now = Date.now();
|
|
15934
16370
|
for (const answer2 of delivery.answers ?? []) if (!answer2.actedAt) answer2.actedAt = now;
|
|
15935
|
-
joinFlow(
|
|
16371
|
+
joinFlow(run3, delivery);
|
|
15936
16372
|
writeAudit(delivery, store.runs);
|
|
15937
16373
|
return delivery;
|
|
15938
16374
|
}
|
|
15939
|
-
function joinFlow(
|
|
15940
|
-
|
|
15941
|
-
|
|
16375
|
+
function joinFlow(run3, delivery) {
|
|
16376
|
+
run3.deliveryId = delivery.deliveryId;
|
|
16377
|
+
run3.flowId = delivery.deliveryId;
|
|
15942
16378
|
}
|
|
15943
16379
|
function endDelivery(deliveryId, status) {
|
|
15944
16380
|
const ended = withBoardLock(() => withStore((store) => {
|
|
@@ -15953,8 +16389,8 @@ function endDelivery(deliveryId, status) {
|
|
|
15953
16389
|
}
|
|
15954
16390
|
return ended;
|
|
15955
16391
|
}
|
|
15956
|
-
async function settleDelivery(
|
|
15957
|
-
if (
|
|
16392
|
+
async function settleDelivery(run3) {
|
|
16393
|
+
if (run3.deliveryId) syncAudit(run3.deliveryId, run3);
|
|
15958
16394
|
}
|
|
15959
16395
|
function deliveryAcceptsAnswers(cardId2) {
|
|
15960
16396
|
return !!deliveryStateOf(cardId2)?.paused;
|
|
@@ -16839,7 +17275,7 @@ var init_prompts = __esm({
|
|
|
16839
17275
|
`The session you were continuing is gone, and this one holds nothing of it.`,
|
|
16840
17276
|
`Do the task below from the top, checking each step's precondition before you do it \u2014 work an earlier run already finished is done, so don't repeat it.`
|
|
16841
17277
|
].join(" ");
|
|
16842
|
-
restartable = (
|
|
17278
|
+
restartable = (run3) => (run3.cardId !== null || !!run3.deliveryId) && RESTARTABLE.has(run3.action);
|
|
16843
17279
|
NO_IMPLEMENT = `(Unless the request explicitly asks for implementation, don't implement it; revising the card's drafts is not implementing.)`;
|
|
16844
17280
|
BOARD_FOLDER = "<board folder>";
|
|
16845
17281
|
CARD_FILE = "<card file>";
|
|
@@ -16922,16 +17358,16 @@ function signal(pids, sig) {
|
|
|
16922
17358
|
}
|
|
16923
17359
|
}
|
|
16924
17360
|
}
|
|
16925
|
-
function startedUnder(
|
|
16926
|
-
const self =
|
|
17361
|
+
function startedUnder(list2, root2, since) {
|
|
17362
|
+
const self = list2.procs.find((p) => p.pid === root2);
|
|
16927
17363
|
const from = since ?? self?.startedAt;
|
|
16928
|
-
if (from === void 0 ||
|
|
17364
|
+
if (from === void 0 || list2.bootedAt > from) return [];
|
|
16929
17365
|
if (self && self.startedAt > from) return [];
|
|
16930
17366
|
const found2 = self ? [root2] : [];
|
|
16931
17367
|
const seen = /* @__PURE__ */ new Set([root2]);
|
|
16932
17368
|
const queue = [{ pid: root2, startedAt: from }];
|
|
16933
17369
|
for (const parent of queue) {
|
|
16934
|
-
for (const p of
|
|
17370
|
+
for (const p of list2.procs) {
|
|
16935
17371
|
if (p.ppid !== parent.pid || seen.has(p.pid) || p.startedAt < parent.startedAt) continue;
|
|
16936
17372
|
seen.add(p.pid);
|
|
16937
17373
|
found2.push(p.pid);
|
|
@@ -16962,9 +17398,9 @@ function procsOnWindows() {
|
|
|
16962
17398
|
}
|
|
16963
17399
|
function killUnderOnWindows(pid, since) {
|
|
16964
17400
|
if (!WINDOWS3 || !pid) return;
|
|
16965
|
-
const
|
|
16966
|
-
if (!
|
|
16967
|
-
const pids = startedUnder(
|
|
17401
|
+
const list2 = procsOnWindows();
|
|
17402
|
+
if (!list2) return;
|
|
17403
|
+
const pids = startedUnder(list2, pid, since).filter((p) => p !== process.pid);
|
|
16968
17404
|
if (!pids.length) return;
|
|
16969
17405
|
spawnSync4("taskkill", ["/F", ...pids.flatMap((p) => ["/PID", String(p)])], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
|
|
16970
17406
|
}
|
|
@@ -17069,9 +17505,9 @@ function reap(runs, reaped = [], restore = []) {
|
|
|
17069
17505
|
}
|
|
17070
17506
|
return changed;
|
|
17071
17507
|
}
|
|
17072
|
-
function stampDuration(
|
|
17508
|
+
function stampDuration(run3, endedAt) {
|
|
17073
17509
|
try {
|
|
17074
|
-
fs53.appendFileSync(
|
|
17510
|
+
fs53.appendFileSync(run3.logPath, durationLine(endedAt - run3.startedAt));
|
|
17075
17511
|
} catch {
|
|
17076
17512
|
}
|
|
17077
17513
|
}
|
|
@@ -17092,19 +17528,19 @@ function cardNow(cardId2) {
|
|
|
17092
17528
|
return null;
|
|
17093
17529
|
}
|
|
17094
17530
|
}
|
|
17095
|
-
function claimCard(
|
|
17096
|
-
const wanted =
|
|
17097
|
-
if (
|
|
17098
|
-
const delivery =
|
|
17099
|
-
|
|
17100
|
-
return { cardId:
|
|
17531
|
+
function claimCard(run3) {
|
|
17532
|
+
const wanted = run3.cardId !== null ? RUN_STATUS[run3.action] : void 0;
|
|
17533
|
+
if (run3.cardId === null || !wanted) return void 0;
|
|
17534
|
+
const delivery = run3.deliveryId ? activeDelivery(run3.cardId) : void 0;
|
|
17535
|
+
run3.priorStatus = (delivery && delivery.deliveryId === run3.deliveryId ? delivery.priorStatus : void 0) ?? cardNow(run3.cardId)?.status ?? "todo";
|
|
17536
|
+
return { cardId: run3.cardId, status: wanted };
|
|
17101
17537
|
}
|
|
17102
|
-
async function restoreCardStatus(
|
|
17103
|
-
if (
|
|
17104
|
-
if (
|
|
17105
|
-
const card = cardNow(
|
|
17538
|
+
async function restoreCardStatus(run3) {
|
|
17539
|
+
if (run3.cardId === null || !RUN_STATUS[run3.action]) return;
|
|
17540
|
+
if (run3.deliveryId && activeDelivery(run3.cardId)?.deliveryId === run3.deliveryId) return;
|
|
17541
|
+
const card = cardNow(run3.cardId);
|
|
17106
17542
|
if (!card) return;
|
|
17107
|
-
await setCardStatus(
|
|
17543
|
+
await setCardStatus(run3.cardId, card.questions > 0 ? "todo" : run3.priorStatus ?? "todo");
|
|
17108
17544
|
}
|
|
17109
17545
|
async function releaseCard(delivery) {
|
|
17110
17546
|
if (delivery.cardId === null) return;
|
|
@@ -17112,39 +17548,39 @@ async function releaseCard(delivery) {
|
|
|
17112
17548
|
if (card?.status !== "implementing") return;
|
|
17113
17549
|
await setCardStatus(delivery.cardId, card.questions > 0 ? "todo" : delivery.priorStatus ?? "ready");
|
|
17114
17550
|
}
|
|
17115
|
-
function recordPrune(
|
|
17116
|
-
if (
|
|
17551
|
+
function recordPrune(run3) {
|
|
17552
|
+
if (run3.action !== "prune-memory" || run3.status !== "done") return;
|
|
17117
17553
|
try {
|
|
17118
17554
|
stampMemoryPrune();
|
|
17119
17555
|
} catch {
|
|
17120
17556
|
}
|
|
17121
17557
|
}
|
|
17122
|
-
function recordMemoryReview(
|
|
17123
|
-
if (
|
|
17558
|
+
function recordMemoryReview(run3) {
|
|
17559
|
+
if (run3.action !== "review-memory" || run3.status !== "done") return;
|
|
17124
17560
|
try {
|
|
17125
|
-
stampMemoryReview(new Date(
|
|
17561
|
+
stampMemoryReview(new Date(run3.startedAt));
|
|
17126
17562
|
} catch {
|
|
17127
17563
|
}
|
|
17128
17564
|
}
|
|
17129
|
-
function recordReflection(
|
|
17130
|
-
if (
|
|
17565
|
+
function recordReflection(run3) {
|
|
17566
|
+
if (run3.action !== "reflect" || run3.status !== "done" || !run3.cards?.length) return;
|
|
17131
17567
|
try {
|
|
17132
|
-
dropReflected(
|
|
17568
|
+
dropReflected(run3.cards);
|
|
17133
17569
|
} catch {
|
|
17134
17570
|
}
|
|
17135
17571
|
}
|
|
17136
|
-
function recordScheduledRun(
|
|
17137
|
-
if (
|
|
17572
|
+
function recordScheduledRun(run3) {
|
|
17573
|
+
if (run3.action !== "scheduled" || run3.status !== "done" || !run3.studio || !run3.specAgent) return;
|
|
17138
17574
|
try {
|
|
17139
|
-
const began = (
|
|
17140
|
-
stampScheduledRun(
|
|
17575
|
+
const began = (run3.deliveryId ? findDelivery(run3.deliveryId)?.startedAt : void 0) ?? run3.startedAt;
|
|
17576
|
+
stampScheduledRun(run3.studio, run3.specAgent, new Date(began));
|
|
17141
17577
|
} catch {
|
|
17142
17578
|
}
|
|
17143
17579
|
}
|
|
17144
|
-
function recordProjectDescription(
|
|
17145
|
-
if (
|
|
17580
|
+
function recordProjectDescription(run3) {
|
|
17581
|
+
if (run3.action !== "describe-project" || run3.status !== "done") return;
|
|
17146
17582
|
try {
|
|
17147
|
-
stampProjectDescription(new Date(
|
|
17583
|
+
stampProjectDescription(new Date(run3.startedAt));
|
|
17148
17584
|
} catch {
|
|
17149
17585
|
}
|
|
17150
17586
|
}
|
|
@@ -17152,8 +17588,8 @@ function resumeIdOf(r) {
|
|
|
17152
17588
|
if (adoptsSessionId(r.harness) && !carriesSession(r)) return r.sessionId;
|
|
17153
17589
|
return r.resumeId;
|
|
17154
17590
|
}
|
|
17155
|
-
function resumeSessionId(
|
|
17156
|
-
return resumesUnder(
|
|
17591
|
+
function resumeSessionId(run3) {
|
|
17592
|
+
return resumesUnder(run3.harness) && !neverStarted(run3) ? resumeIdOf(run3) : void 0;
|
|
17157
17593
|
}
|
|
17158
17594
|
function endedDeliveryRefusal(r, refusals) {
|
|
17159
17595
|
if (!r.deliveryId || !canPickUp(r)) return void 0;
|
|
@@ -17227,7 +17663,7 @@ function archivedRejected(id) {
|
|
|
17227
17663
|
}
|
|
17228
17664
|
function goneCards(runs) {
|
|
17229
17665
|
const asking = /* @__PURE__ */ new Set();
|
|
17230
|
-
for (const
|
|
17666
|
+
for (const run3 of runs) if (run3.cardId !== null && canPickUp(run3)) asking.add(run3.cardId);
|
|
17231
17667
|
if (asking.size === 0) return asking;
|
|
17232
17668
|
const onBoard3 = boardCardIds();
|
|
17233
17669
|
const gone = /* @__PURE__ */ new Set();
|
|
@@ -17241,8 +17677,8 @@ async function listRuns() {
|
|
|
17241
17677
|
reap(all2, reaped, restore);
|
|
17242
17678
|
return all2.map((r) => ({ ...r }));
|
|
17243
17679
|
});
|
|
17244
|
-
for (const
|
|
17245
|
-
for (const
|
|
17680
|
+
for (const run3 of restore) await restoreCardStatus(run3);
|
|
17681
|
+
for (const run3 of reaped) await settleDelivery(run3);
|
|
17246
17682
|
for (const sub of runs) {
|
|
17247
17683
|
if (sub.action !== "sub" || sub.status !== "running" || !sub.parentId) continue;
|
|
17248
17684
|
if (!runs.some((r) => r.sessionId === sub.parentId && r.status === "running")) await stopRun(sub.sessionId);
|
|
@@ -17283,7 +17719,7 @@ async function getRun(id, bytes2) {
|
|
|
17283
17719
|
reap(all2, [], restore);
|
|
17284
17720
|
return all2.map((r) => ({ ...r }));
|
|
17285
17721
|
});
|
|
17286
|
-
for (const
|
|
17722
|
+
for (const run3 of restore) await restoreCardStatus(run3);
|
|
17287
17723
|
const found2 = findRun(runs, id);
|
|
17288
17724
|
if (!found2) return null;
|
|
17289
17725
|
const view = toView(found2, goneCards([found2]));
|
|
@@ -17506,8 +17942,8 @@ function carriedSession(req) {
|
|
|
17506
17942
|
};
|
|
17507
17943
|
}
|
|
17508
17944
|
function planningRun(sessionId) {
|
|
17509
|
-
const
|
|
17510
|
-
return
|
|
17945
|
+
const run3 = peekRun(sessionId);
|
|
17946
|
+
return run3?.status === "running" && PLANNING.has(run3.action) ? run3 : void 0;
|
|
17511
17947
|
}
|
|
17512
17948
|
function requestOf(record) {
|
|
17513
17949
|
const id = record.cardId ?? void 0;
|
|
@@ -17539,7 +17975,7 @@ async function openResume(id, options) {
|
|
|
17539
17975
|
reap(all2, [], restore);
|
|
17540
17976
|
return all2.map((r) => ({ ...r }));
|
|
17541
17977
|
});
|
|
17542
|
-
for (const
|
|
17978
|
+
for (const run3 of restore) await restoreCardStatus(run3);
|
|
17543
17979
|
const prev = findRun(runs, id);
|
|
17544
17980
|
if (prev === null) return ambiguousRun(id);
|
|
17545
17981
|
if (!prev) return unknownRun(id);
|
|
@@ -17720,8 +18156,8 @@ function forgetRun(sessionId) {
|
|
|
17720
18156
|
}
|
|
17721
18157
|
}
|
|
17722
18158
|
function askForSpec(sessionId, ask2) {
|
|
17723
|
-
const
|
|
17724
|
-
if (!
|
|
18159
|
+
const run3 = peekRun(sessionId);
|
|
18160
|
+
if (!run3) return "no-run";
|
|
17725
18161
|
const file = readAsks(sessionId);
|
|
17726
18162
|
if (file.asks.some((a) => a.specAgent === ask2.specAgent && a.cardId === ask2.cardId)) return "already";
|
|
17727
18163
|
file.asks.push(ask2);
|
|
@@ -17790,9 +18226,9 @@ function markSpawned(sessionId, pid) {
|
|
|
17790
18226
|
}
|
|
17791
18227
|
function patch(sessionId, change2) {
|
|
17792
18228
|
return withRuns((runs) => {
|
|
17793
|
-
const
|
|
17794
|
-
if (
|
|
17795
|
-
return
|
|
18229
|
+
const run3 = runs.find((r) => r.sessionId === sessionId);
|
|
18230
|
+
if (run3) change2(run3);
|
|
18231
|
+
return run3 ? { ...run3 } : void 0;
|
|
17796
18232
|
});
|
|
17797
18233
|
}
|
|
17798
18234
|
function peekRun(sessionId) {
|
|
@@ -17800,18 +18236,18 @@ function peekRun(sessionId) {
|
|
|
17800
18236
|
}
|
|
17801
18237
|
async function closeRun(sessionId, res) {
|
|
17802
18238
|
const closed2 = withRuns((runs) => {
|
|
17803
|
-
const
|
|
17804
|
-
if (!
|
|
17805
|
-
|
|
17806
|
-
if (res.ok !== void 0)
|
|
17807
|
-
|
|
17808
|
-
if (res.error)
|
|
17809
|
-
if (res.note)
|
|
17810
|
-
if (res.errorWhy?.length)
|
|
17811
|
-
if (res.noteWhy?.length)
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
return { ...
|
|
18239
|
+
const run3 = runs.find((r) => r.sessionId === sessionId);
|
|
18240
|
+
if (!run3 || run3.status !== "running") return void 0;
|
|
18241
|
+
run3.status = res.status;
|
|
18242
|
+
if (res.ok !== void 0) run3.ok = res.ok;
|
|
18243
|
+
run3.code = res.code ?? null;
|
|
18244
|
+
if (res.error) run3.error = res.error;
|
|
18245
|
+
if (res.note) run3.note = res.note;
|
|
18246
|
+
if (res.errorWhy?.length) run3.errorWhy = res.errorWhy;
|
|
18247
|
+
if (res.noteWhy?.length) run3.noteWhy = res.noteWhy;
|
|
18248
|
+
run3.endedAt = res.endedAt ?? Date.now();
|
|
18249
|
+
run3.pid = void 0;
|
|
18250
|
+
return { ...run3 };
|
|
17815
18251
|
});
|
|
17816
18252
|
if (!closed2) return;
|
|
17817
18253
|
if (closed2.status === "done" || closed2.status === "error") {
|
|
@@ -17836,14 +18272,14 @@ async function stopRun(id) {
|
|
|
17836
18272
|
const restore = [];
|
|
17837
18273
|
const out = withRuns((runs) => {
|
|
17838
18274
|
reap(runs, [], restore);
|
|
17839
|
-
const
|
|
17840
|
-
if (
|
|
17841
|
-
if (!
|
|
17842
|
-
if (
|
|
17843
|
-
|
|
17844
|
-
return { ok: true, sessionId:
|
|
18275
|
+
const run3 = findRun(runs, id);
|
|
18276
|
+
if (run3 === null) return { ok: false, ...ambiguousRun(id) };
|
|
18277
|
+
if (!run3) return { ok: false, ...unknownRun(id) };
|
|
18278
|
+
if (run3.status !== "running") return { ok: true, sessionId: run3.sessionId };
|
|
18279
|
+
run3.stopping = true;
|
|
18280
|
+
return { ok: true, sessionId: run3.sessionId, pid: run3.pid, live: true };
|
|
17845
18281
|
});
|
|
17846
|
-
for (const
|
|
18282
|
+
for (const run3 of restore) await restoreCardStatus(run3);
|
|
17847
18283
|
const live = out;
|
|
17848
18284
|
if (!live.ok || !live.live) {
|
|
17849
18285
|
return { ok: live.ok, sessionId: live.sessionId, error: live.error, reason: live.reason, args: live.args };
|
|
@@ -17889,13 +18325,13 @@ async function cancelDelivery(id) {
|
|
|
17889
18325
|
}
|
|
17890
18326
|
async function stopSubRuns(parentId) {
|
|
17891
18327
|
const live = liveSubRuns(parentId);
|
|
17892
|
-
for (const
|
|
17893
|
-
await Promise.all(live.map((
|
|
18328
|
+
for (const run3 of live) await stopRun(run3.sessionId);
|
|
18329
|
+
await Promise.all(live.map((run3) => runIsDown(run3.sessionId)));
|
|
17894
18330
|
}
|
|
17895
18331
|
async function runIsDown(sessionId) {
|
|
17896
18332
|
for (const until = Date.now() + STOP_WAIT_MS; Date.now() < until; ) {
|
|
17897
|
-
const
|
|
17898
|
-
if (!
|
|
18333
|
+
const run3 = readRuns().find((r) => r.sessionId === sessionId);
|
|
18334
|
+
if (!run3 || !runIsLive(run3)) return;
|
|
17899
18335
|
await sleep3(STOP_POLL_MS);
|
|
17900
18336
|
}
|
|
17901
18337
|
}
|
|
@@ -19387,14 +19823,14 @@ function compareProblem(attrs, id) {
|
|
|
19387
19823
|
return { message: `${at} is not valid JSON.` };
|
|
19388
19824
|
}
|
|
19389
19825
|
};
|
|
19390
|
-
const
|
|
19391
|
-
if ("message" in
|
|
19392
|
-
const why2 = Array.isArray(
|
|
19826
|
+
const list2 = read3(attrs.shots);
|
|
19827
|
+
if ("message" in list2) return shots(list2.message);
|
|
19828
|
+
const why2 = Array.isArray(list2.data) ? shotsProblem(list2.data) : storyboardProblem(list2.data);
|
|
19393
19829
|
if (why2) return shots(`${attrs.shots}: ${why2}`);
|
|
19394
19830
|
if (!script) return null;
|
|
19395
19831
|
const bad = storyboardProblem(board2);
|
|
19396
19832
|
if (bad) return src(`${attrs.b}: ${bad}`);
|
|
19397
|
-
const known2 = new Set((Array.isArray(
|
|
19833
|
+
const known2 = new Set((Array.isArray(list2.data) ? list2.data : list2.data.shots).map((s) => s.id));
|
|
19398
19834
|
const extra = board2.shots.find((s) => !known2.has(s.id));
|
|
19399
19835
|
return extra ? shots(`${attrs.b} has shot ${extra.id}, which ${attrs.shots} lacks. Add ${extra.id} to ${attrs.shots}, or drop it from ${attrs.b}.`) : null;
|
|
19400
19836
|
}
|
|
@@ -19842,8 +20278,8 @@ function cmdUpdateQuestions(id, input) {
|
|
|
19842
20278
|
function specRunAgent() {
|
|
19843
20279
|
const id = insideRun();
|
|
19844
20280
|
if (!id) return void 0;
|
|
19845
|
-
const
|
|
19846
|
-
return
|
|
20281
|
+
const run3 = readStore().runs.find((r) => r.sessionId === id);
|
|
20282
|
+
return run3?.action === "spec" ? run3.specAgent : void 0;
|
|
19847
20283
|
}
|
|
19848
20284
|
var TODO_ITEM;
|
|
19849
20285
|
var init_card = __esm({
|
|
@@ -20609,21 +21045,21 @@ function scheduledBusy(pass, store = readStore()) {
|
|
|
20609
21045
|
}
|
|
20610
21046
|
function insideScheduledPass() {
|
|
20611
21047
|
const sessionId = insideRun();
|
|
20612
|
-
const
|
|
20613
|
-
return
|
|
21048
|
+
const run3 = sessionId ? readStore().runs.find((r) => r.sessionId === sessionId) : void 0;
|
|
21049
|
+
return run3?.action === "scheduled" && run3.studio && run3.specAgent ? { studio: run3.studio, agent: run3.specAgent } : null;
|
|
20614
21050
|
}
|
|
20615
21051
|
function runAgent() {
|
|
20616
21052
|
const sessionId = insideRun();
|
|
20617
21053
|
const runs = sessionId ? readStore().runs : [];
|
|
20618
|
-
const
|
|
20619
|
-
if (!
|
|
20620
|
-
if (
|
|
20621
|
-
const parent = runs.find((r) => r.sessionId ===
|
|
20622
|
-
return parent ? agentOf(parent) :
|
|
21054
|
+
const run3 = runs.find((r) => r.sessionId === sessionId);
|
|
21055
|
+
if (!run3) return null;
|
|
21056
|
+
if (run3.action !== "sub") return agentOf(run3);
|
|
21057
|
+
const parent = runs.find((r) => r.sessionId === run3.parentId);
|
|
21058
|
+
return parent ? agentOf(parent) : run3.specAgent ?? null;
|
|
20623
21059
|
}
|
|
20624
|
-
function agentOf(
|
|
20625
|
-
if (
|
|
20626
|
-
return flowNodes().find((n) => n.flow ===
|
|
21060
|
+
function agentOf(run3) {
|
|
21061
|
+
if (run3.action === "scheduled") return run3.specAgent ?? null;
|
|
21062
|
+
return flowNodes().find((n) => n.flow === run3.action)?.agent ?? null;
|
|
20627
21063
|
}
|
|
20628
21064
|
var scheduledRequest, isPass, openPasses, stalePasses;
|
|
20629
21065
|
var init_scheduled = __esm({
|
|
@@ -20638,7 +21074,7 @@ var init_scheduled = __esm({
|
|
|
20638
21074
|
studio: pass.studio,
|
|
20639
21075
|
specAgent: pass.agent
|
|
20640
21076
|
});
|
|
20641
|
-
isPass = (
|
|
21077
|
+
isPass = (run3, pass) => run3.action === "scheduled" && run3.studio === pass.studio && run3.specAgent === pass.agent;
|
|
20642
21078
|
openPasses = (deliveries, pass) => deliveries.filter(
|
|
20643
21079
|
(d) => d.status === "active" && d.scheduled?.studio === pass.studio && d.scheduled.agent === pass.agent
|
|
20644
21080
|
);
|
|
@@ -21376,16 +21812,16 @@ function removeCard2(id, metric, options) {
|
|
|
21376
21812
|
}
|
|
21377
21813
|
}
|
|
21378
21814
|
withStore((store) => {
|
|
21379
|
-
for (const
|
|
21380
|
-
if (!leaving.some((c) =>
|
|
21381
|
-
const marks = new Map((
|
|
21815
|
+
for (const run3 of store.runs) {
|
|
21816
|
+
if (!leaving.some((c) => run3.createdCardIds?.includes(c.id))) continue;
|
|
21817
|
+
const marks = new Map((run3.discardedCards ?? []).map((c) => [c.id, c]));
|
|
21382
21818
|
for (const c of leaving) marks.set(c.id, { id: c.id, path: rel(c.file), pending: true });
|
|
21383
|
-
|
|
21819
|
+
run3.discardedCards = [...marks.values()];
|
|
21384
21820
|
}
|
|
21385
21821
|
});
|
|
21386
21822
|
}
|
|
21387
21823
|
if (options.discard) withStore((store) => {
|
|
21388
|
-
for (const
|
|
21824
|
+
for (const run3 of store.runs) for (const card of run3.discardedCards ?? []) {
|
|
21389
21825
|
if (leftIds.includes(card.id)) delete card.pending;
|
|
21390
21826
|
}
|
|
21391
21827
|
});
|
|
@@ -21661,11 +22097,11 @@ function newOpId() {
|
|
|
21661
22097
|
opCounter += 1;
|
|
21662
22098
|
return `${process.pid.toString(36)}-${Date.now().toString(36)}-${opCounter.toString(36)}`;
|
|
21663
22099
|
}
|
|
21664
|
-
async function leaseAnd(provider, target,
|
|
22100
|
+
async function leaseAnd(provider, target, run3) {
|
|
21665
22101
|
const got = await provider.lease(target);
|
|
21666
22102
|
if (!got.ok) return { ok: false, kind: "refused", error: got.error };
|
|
21667
22103
|
try {
|
|
21668
|
-
return await
|
|
22104
|
+
return await run3(envelope(got.lease.revision, got.lease.id));
|
|
21669
22105
|
} finally {
|
|
21670
22106
|
await provider.releaseLease(got.lease.id);
|
|
21671
22107
|
}
|
|
@@ -21793,14 +22229,14 @@ function localBoard() {
|
|
|
21793
22229
|
},
|
|
21794
22230
|
// ---- the named `akb raw` moves ----------------------------------------
|
|
21795
22231
|
async runMove(move, input, env2) {
|
|
21796
|
-
const
|
|
21797
|
-
if (!
|
|
22232
|
+
const run3 = MOVES[move];
|
|
22233
|
+
if (!run3) return Promise.resolve(opRefused(new Error(`unknown command "${move}".`)));
|
|
21798
22234
|
const target = moveTarget(move, input.args);
|
|
21799
22235
|
try {
|
|
21800
22236
|
return await withBoardLock(() => {
|
|
21801
22237
|
const no = checkWrite(target, env2, revisionAt(target));
|
|
21802
22238
|
if (no) return no;
|
|
21803
|
-
const data =
|
|
22239
|
+
const data = run3(input);
|
|
21804
22240
|
if (data instanceof Promise) return data.then((data2) => opOk(revisionAt(target), { data: data2 }));
|
|
21805
22241
|
return opOk(revisionAt(target), { data: data || {} });
|
|
21806
22242
|
});
|
|
@@ -21809,10 +22245,10 @@ function localBoard() {
|
|
|
21809
22245
|
}
|
|
21810
22246
|
},
|
|
21811
22247
|
readMove(move, input) {
|
|
21812
|
-
const
|
|
21813
|
-
if (!
|
|
22248
|
+
const run3 = MOVES[move];
|
|
22249
|
+
if (!run3) return Promise.reject(new Error(`unknown command "${move}".`));
|
|
21814
22250
|
try {
|
|
21815
|
-
return Promise.resolve(
|
|
22251
|
+
return Promise.resolve(run3(input) || {});
|
|
21816
22252
|
} catch (e) {
|
|
21817
22253
|
return Promise.reject(e);
|
|
21818
22254
|
}
|
|
@@ -21864,8 +22300,8 @@ function board() {
|
|
|
21864
22300
|
if (!active) active = localBoard();
|
|
21865
22301
|
return active;
|
|
21866
22302
|
}
|
|
21867
|
-
function withLease(target,
|
|
21868
|
-
return leaseAnd(board(), target,
|
|
22303
|
+
function withLease(target, run3) {
|
|
22304
|
+
return leaseAnd(board(), target, run3);
|
|
21869
22305
|
}
|
|
21870
22306
|
var active, setCardStatusOn, cancelBoardDelivery, resumeBoardDelivery;
|
|
21871
22307
|
var init_board = __esm({
|
|
@@ -22167,8 +22603,8 @@ async function dispatch(move, cmd, args, opts, cli) {
|
|
|
22167
22603
|
cli.onAnswer?.(data);
|
|
22168
22604
|
}
|
|
22169
22605
|
async function cloudCard(task, opts) {
|
|
22170
|
-
const
|
|
22171
|
-
const triage = typeof opts.triage === "string" ? opts.triage :
|
|
22606
|
+
const run3 = insideRun() ? peekRun(insideRun()) : void 0;
|
|
22607
|
+
const triage = typeof opts.triage === "string" ? opts.triage : run3?.triage;
|
|
22172
22608
|
opts = { ...opts, ...triage ? { triage } : {} };
|
|
22173
22609
|
const sourceFile = triage ? triageFile(triage) : void 0;
|
|
22174
22610
|
let request2;
|
|
@@ -22199,7 +22635,7 @@ async function cloudCard(task, opts) {
|
|
|
22199
22635
|
}
|
|
22200
22636
|
const checked = await creationProject(KANBAN, REPO_ROOT);
|
|
22201
22637
|
if (!checked.ok) throw new BoardError(creationError(checked.error, triage), { kind: "refused" });
|
|
22202
|
-
const requestId = triage ? `triage:${triage}` :
|
|
22638
|
+
const requestId = triage ? `triage:${triage}` : run3?.sessionId ?? crypto5.randomUUID();
|
|
22203
22639
|
const slot = triage ? triage : String(opts.slug ?? opts.title);
|
|
22204
22640
|
const file = creationReceipt(`${checked.value}:${requestId}`, slot);
|
|
22205
22641
|
const journal = readCreation(file, said2);
|
|
@@ -22717,8 +23153,8 @@ function checkSetting(setting, value, ask2) {
|
|
|
22717
23153
|
return `"${value}" isn't one of the ${setting.label} choices: ${choices}`;
|
|
22718
23154
|
}
|
|
22719
23155
|
if (setting.kind === "provider" && !value) {
|
|
22720
|
-
const
|
|
22721
|
-
return `a run always goes through a provider, so this one can't be cleared. Pick one: ${
|
|
23156
|
+
const list2 = providerSetting(activeSettings(ask2));
|
|
23157
|
+
return `a run always goes through a provider, so this one can't be cleared. Pick one: ${list2?.providers?.map((p) => p.id).join(", ") ?? ""}`;
|
|
22722
23158
|
}
|
|
22723
23159
|
return settingSaveError(setting.key, value, ask2);
|
|
22724
23160
|
}
|
|
@@ -23137,7 +23573,7 @@ var init_board3 = __esm({
|
|
|
23137
23573
|
var card_chat_default;
|
|
23138
23574
|
var init_card_chat = __esm({
|
|
23139
23575
|
"../cli/src/guide/card-chat.md"() {
|
|
23140
|
-
card_chat_default = '# Answer a card\'s conversation\n\nWork on the current card and its assets by default. Project implementation requires approval on the review page.\n\n- **Where the task stands**: read it with `akb task show <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb raw update-questions <id>` to edit the question list.\n- **Change card fields**: when the user changes metadata such as priority, modules, or dependencies, use `akb raw update <id>`.\n- **Choose a preview agent**: when a preview is needed and the agent is unclear, use `akb raw previews --triggers` to match the work to an agent.\n- **Create or revise a preview**: when the user asks to see or change a preview for the current card, use `akb raw previews <agent> <id> --print`; never write embed tags by hand.\n- **Create a separate task**: when the user asks to capture work unrelated to this card, follow `akb guide add-task`.\n- **Split this card**: when the user asks to break this card\'s outcome into subtasks, follow the group procedure in `akb guide add-task`.\n- **Change a studio**: when the user asks to change a studio or one of its agents, follow `akb guide update-studio`.\n- **Check card edits**: after writing a card, run `akb raw validate <id>` and fix what it reports.\n- **Anything else**: for a request this guide does not cover, read `akb help` once, then the matching command\'s `--help`.\n\nReply in plain, natural language. Do not write memory, including through any flow this conversation starts.\n';
|
|
23576
|
+
card_chat_default = '# Answer a card\'s conversation\n\nWork on the current card and its assets by default. Project implementation requires approval on the review page.\n\n- **Where the task stands**: read it with `akb task show <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb raw update-questions <id>` to edit the question list.\n- **Change card fields**: when the user changes metadata such as priority, modules, or dependencies, use `akb raw update <id>`.\n- **Choose a preview agent**: when a preview is needed and the agent is unclear, use `akb raw previews --triggers` to match the work to an agent.\n- **Create or revise a preview**: when the user asks to see or change a preview for the current card, use `akb raw previews <agent> <id> --print`; never write embed tags by hand.\n- **Create a separate task**: when the user asks to capture work unrelated to this card, follow `akb guide add-task`.\n- **Split this card**: when the user asks to break this card\'s outcome into subtasks, follow the group procedure in `akb guide add-task`.\n- **Change a studio**: when the user asks to change a studio or one of its agents, follow `akb guide update-studio`.\n- **Check card edits**: after writing a card, run `akb raw validate <id>` and fix what it reports.\n- **Anything else**: for a request this guide does not cover, read `akb help` once, then the matching command\'s `--help`.\n\nReply in plain, natural language. Do not write memory, including through any flow this conversation starts.\n\n- **Start this task**: when the user explicitly asks to start, implement or approve it, use `akb task approve` or `akb raw card approve/implement`. In a task reply these register one approval for after the reply finishes and syncs. Pending means accepted, not started; finish the reply and do not wait or edit the card again. Preview approvals still apply.\n';
|
|
23141
23577
|
}
|
|
23142
23578
|
});
|
|
23143
23579
|
|
|
@@ -23663,24 +24099,24 @@ function completeDelivery(named2, result = {}) {
|
|
|
23663
24099
|
delivery2.completions = durable.completions;
|
|
23664
24100
|
}
|
|
23665
24101
|
const receipts = delivery2.completions ??= [];
|
|
23666
|
-
const
|
|
24102
|
+
const run3 = store.runs.find((r) => r.sessionId === sessionId);
|
|
23667
24103
|
const current = store.runs.filter((r) => r.deliveryId === delivery2.deliveryId && ["implement", "scheduled"].includes(r.action)).pop();
|
|
23668
|
-
if (!
|
|
24104
|
+
if (!run3 || run3.deliveryId !== delivery2.deliveryId) throw new Error("This run does not own the delivery.");
|
|
23669
24105
|
const pending = receipts[deliveryStep(delivery2)];
|
|
23670
24106
|
const previous = receipts.find((c) => c.sessionId === sessionId || c.resumedSessions?.includes(sessionId));
|
|
23671
24107
|
if (previous) {
|
|
23672
24108
|
if (previous.commit !== commit || previous.branch !== branch) throw new Error("This step already recorded a different result.");
|
|
23673
|
-
if (!previous.finished && previous.step === deliveryStep(delivery2) && (delivery2.status !== "active" ||
|
|
24109
|
+
if (!previous.finished && previous.step === deliveryStep(delivery2) && (delivery2.status !== "active" || run3 !== current || run3.status !== "running")) {
|
|
23674
24110
|
throw new Error("Only the current owning run can finish pending completion.");
|
|
23675
24111
|
}
|
|
23676
24112
|
return { delivery: delivery2, receipt: previous };
|
|
23677
24113
|
}
|
|
23678
|
-
if (delivery2.status !== "active" || !
|
|
24114
|
+
if (delivery2.status !== "active" || !run3 || run3.status !== "running" || run3 !== current || run3.deliveryId !== delivery2.deliveryId) {
|
|
23679
24115
|
throw new Error("Only the current owning run can complete this delivery.");
|
|
23680
24116
|
}
|
|
23681
24117
|
if (answerOutcome(delivery2) === "changed") throw new Error("The approved requirements were superseded. Continue with the updated delivery.");
|
|
23682
24118
|
if (delivery2.cardId !== null && openQuestions(delivery2.cardId)) throw new Error("Answer the open questions before completing.");
|
|
23683
|
-
if (pending &&
|
|
24119
|
+
if (pending && run3 === current) {
|
|
23684
24120
|
if (pending.commit !== commit || pending.branch !== branch) throw new Error("This step already recorded a different result.");
|
|
23685
24121
|
pending.resumedSessions = [...pending.resumedSessions ?? [], sessionId];
|
|
23686
24122
|
return { delivery: delivery2, receipt: pending };
|
|
@@ -23876,10 +24312,10 @@ function open2(req, sessionId) {
|
|
|
23876
24312
|
returnRunPictures(sessionId, req.box);
|
|
23877
24313
|
return opened;
|
|
23878
24314
|
}
|
|
23879
|
-
const { run:
|
|
23880
|
-
const pid = spawnWatcher(
|
|
23881
|
-
markSpawned(
|
|
23882
|
-
return { run:
|
|
24315
|
+
const { run: run3 } = opened;
|
|
24316
|
+
const pid = spawnWatcher(run3.sessionId);
|
|
24317
|
+
markSpawned(run3.sessionId, pid);
|
|
24318
|
+
return { run: run3, spawned: pid !== void 0 };
|
|
23883
24319
|
}
|
|
23884
24320
|
async function startResume(id, options) {
|
|
23885
24321
|
const opened = await openResume(id, options);
|
|
@@ -24616,7 +25052,7 @@ var init_stage_end = __esm({
|
|
|
24616
25052
|
const flow = flowByAction(action);
|
|
24617
25053
|
return flow ? stageOfFlow(flow.command) : void 0;
|
|
24618
25054
|
};
|
|
24619
|
-
askedFor = (cardId2, agent) => readStore().runs.some((
|
|
25055
|
+
askedFor = (cardId2, agent) => readStore().runs.some((run3) => run3.action === "spec" && run3.cardId === cardId2 && run3.specAgent === agent);
|
|
24620
25056
|
}
|
|
24621
25057
|
});
|
|
24622
25058
|
|
|
@@ -24701,26 +25137,26 @@ function stalledLine(cardId2, next) {
|
|
|
24701
25137
|
if (!card || refinementStep(card) === "done") return null;
|
|
24702
25138
|
return `#${card.id} is still in To do after planning, and the board won't plan it again on its own \u2014 refine it again, or mark it ready yourself.`;
|
|
24703
25139
|
}
|
|
24704
|
-
function planStageEnd(
|
|
24705
|
-
if (
|
|
24706
|
-
const card = currentCard(
|
|
25140
|
+
function planStageEnd(run3) {
|
|
25141
|
+
if (run3.cardId === null || stageOfAction(run3.action) !== "plan") return null;
|
|
25142
|
+
const card = currentCard(run3.cardId);
|
|
24707
25143
|
if (!card || card.openBlockers.length > 0 || card.questions.length > 0) return null;
|
|
24708
25144
|
if (refinementStep(card) !== "done") return null;
|
|
24709
25145
|
return endOfStage(stageContract("plan"), card);
|
|
24710
25146
|
}
|
|
24711
|
-
function refinementRunsAfter(
|
|
24712
|
-
const next = waitingForSpec ||
|
|
24713
|
-
const starts = refinesAfter(
|
|
24714
|
-
(req) => req.id !==
|
|
25147
|
+
function refinementRunsAfter(run3, changed, before, waitingForSpec = false, refused = []) {
|
|
25148
|
+
const next = waitingForSpec || run3.cardId === null || !["clarify", "resolve", "edit", "approve"].includes(run3.action) ? null : refinementAfter(run3.action, run3.cardId, run3.flowId);
|
|
25149
|
+
const starts = refinesAfter(run3.action, changed, before).filter(
|
|
25150
|
+
(req) => req.id !== run3.cardId || run3.refineRound === void 0 && run3.action !== "spec"
|
|
24715
25151
|
);
|
|
24716
25152
|
const refusedNote = waitingForSpec || !refused.length ? "" : `Preview agents not started: ${refused.map((r) => r.error).join(" ")}`;
|
|
24717
25153
|
const carryOn = next && refusedNote ? { ...next, notes: [next.notes, refusedNote].filter(Boolean).join("\n\n") } : next;
|
|
24718
|
-
const end2 = waitingForSpec || carryOn || starts.length ? null : planStageEnd(
|
|
25154
|
+
const end2 = waitingForSpec || carryOn || starts.length ? null : planStageEnd(run3);
|
|
24719
25155
|
const short2 = end2 && "missing" in end2 ? end2 : null;
|
|
24720
|
-
const stalled = (short2 ? shortLine(short2,
|
|
25156
|
+
const stalled = (short2 ? shortLine(short2, run3.cardId) : void 0) ?? (waitingForSpec ? void 0 : run3.refineRound !== void 0 && stalledLine(run3.cardId, next) || void 0);
|
|
24721
25157
|
const stalledWhy = [
|
|
24722
25158
|
...refusedNote ? [{ kind: "specRefused", refusals: refused }] : [],
|
|
24723
|
-
...!stalled ? [] : short2 ? [{ kind: "stageShort", args: { stage: short2.stage, card: String(
|
|
25159
|
+
...!stalled ? [] : short2 ? [{ kind: "stageShort", args: { stage: short2.stage, card: String(run3.cardId), agents: short2.missing.join(", ") } }] : [{ kind: "refineStalled", args: { card: String(run3.cardId) } }]
|
|
24724
25160
|
];
|
|
24725
25161
|
return {
|
|
24726
25162
|
runs: [...starts, ...carryOn ? [carryOn] : [], ...end2 && "ask" in end2 ? [end2.ask] : []],
|
|
@@ -24934,18 +25370,18 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
24934
25370
|
import fs82 from "node:fs";
|
|
24935
25371
|
async function watchRun(sessionId, resume = startResume) {
|
|
24936
25372
|
const spec = readSpec(sessionId);
|
|
24937
|
-
const
|
|
24938
|
-
if (!
|
|
24939
|
-
if (
|
|
25373
|
+
const run3 = peekRun(sessionId);
|
|
25374
|
+
if (!run3 || !spec) {
|
|
25375
|
+
if (run3?.status === "running") await closeRun(sessionId, { status: "interrupted", code: null });
|
|
24940
25376
|
return 1;
|
|
24941
25377
|
}
|
|
24942
|
-
if (
|
|
25378
|
+
if (run3.stopping) {
|
|
24943
25379
|
await closeRun(sessionId, { status: "stopped", code: null });
|
|
24944
25380
|
return 1;
|
|
24945
25381
|
}
|
|
24946
25382
|
const stopping = () => peekRun(sessionId)?.status !== "running";
|
|
24947
25383
|
let releaseIndex = null;
|
|
24948
|
-
if (needsIndexLock(
|
|
25384
|
+
if (needsIndexLock(run3.action)) {
|
|
24949
25385
|
releaseIndex = await acquireIndexLock(stopping);
|
|
24950
25386
|
if (!releaseIndex) {
|
|
24951
25387
|
if (!stopping()) await closeRun(sessionId, { status: "interrupted", code: null });
|
|
@@ -24964,7 +25400,7 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
24964
25400
|
const claimed = patch(sessionId, (r) => {
|
|
24965
25401
|
claim = claimCard(r);
|
|
24966
25402
|
});
|
|
24967
|
-
const record = claimed ??
|
|
25403
|
+
const record = claimed ?? run3;
|
|
24968
25404
|
const sub = record.action === "sub";
|
|
24969
25405
|
if (claim) await setCardStatus(claim.cardId, claim.status);
|
|
24970
25406
|
fs82.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
@@ -25069,7 +25505,7 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
25069
25505
|
const turns = renderer?.turns?.() ?? [];
|
|
25070
25506
|
if (turns.length === turnsSeen) return;
|
|
25071
25507
|
turnsSeen = turns.length;
|
|
25072
|
-
if (
|
|
25508
|
+
if (renderer && streamFinished(renderer)) endInput();
|
|
25073
25509
|
};
|
|
25074
25510
|
let sawResumeId = !!record.resumeId;
|
|
25075
25511
|
let sawModel = false;
|
|
@@ -25160,7 +25596,7 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
25160
25596
|
if (errRest) log.write(errRest);
|
|
25161
25597
|
const endedAt = Date.now();
|
|
25162
25598
|
const blocker = peekRun(sessionId)?.blocker;
|
|
25163
|
-
const failure = renderer?.failure?.();
|
|
25599
|
+
const failure = renderer?.failure?.() ?? (renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
|
|
25164
25600
|
const unfinished = blocker || failure;
|
|
25165
25601
|
const result = spoken ? spoken.result : renderer?.result();
|
|
25166
25602
|
const held4 = peekRun(sessionId) ?? record;
|
|
@@ -25168,7 +25604,7 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
25168
25604
|
const said2 = failure ?? spoken?.error;
|
|
25169
25605
|
const offStream = renderer?.offStream?.();
|
|
25170
25606
|
const quiet = silent && !asked && !blocker && !sub && !!resumeSessionId(held4);
|
|
25171
|
-
const blip = quiet ? { reason: waited ?
|
|
25607
|
+
const blip = quiet ? { reason: waited ? backgroundWaitMessage(BACKGROUND_WAIT.minutes) : silenceSaid(silenceFor) } : ours || sub || code === 0 && !said2 || !resumeSessionId(held4) ? void 0 : active2.transient?.({ failure: said2, result, offStream });
|
|
25172
25608
|
const again = blip ? planRetry2(held4.retry, blip, held4.startedAt, Date.now(), Math.random, !quiet) : null;
|
|
25173
25609
|
if (again) {
|
|
25174
25610
|
log.write(`
|
|
@@ -25294,7 +25730,7 @@ ${result}
|
|
|
25294
25730
|
...spawnWhy ? [spawnWhy] : [],
|
|
25295
25731
|
...saidOurs ? [waited ? { kind: "backgroundSilent", args: { n: String(BACKGROUND_WAIT.minutes / 60) } } : { kind: "silent", args: { n: String(silenceFor) } }] : []
|
|
25296
25732
|
];
|
|
25297
|
-
const quietSaid = waited ?
|
|
25733
|
+
const quietSaid = waited ? backgroundWaitMessage(BACKGROUND_WAIT.minutes) : silenceSaid(silenceFor);
|
|
25298
25734
|
if (sub) {
|
|
25299
25735
|
await closeRun(sessionId, {
|
|
25300
25736
|
status,
|
|
@@ -25381,7 +25817,7 @@ Cannot resume board repair: ${next.error}`;
|
|
|
25381
25817
|
touch = () => {
|
|
25382
25818
|
if (done2 || !silenceMs) return;
|
|
25383
25819
|
if (idle) clearTimeout(idle);
|
|
25384
|
-
const background = renderer?.background?.() ?? 0;
|
|
25820
|
+
const background = client?.background?.() ?? renderer?.background?.() ?? 0;
|
|
25385
25821
|
idle = setTimeout(() => {
|
|
25386
25822
|
if (done2 || stopped2 || silent) return;
|
|
25387
25823
|
if (liveSubRuns(sessionId).length) {
|
|
@@ -25396,7 +25832,7 @@ Cannot resume board repair: ${next.error}`;
|
|
|
25396
25832
|
silent = true;
|
|
25397
25833
|
waited = background > 0;
|
|
25398
25834
|
log.write(`
|
|
25399
|
-
[board] ${waited ?
|
|
25835
|
+
[board] ${waited ? backgroundWaitMessage(BACKGROUND_WAIT.minutes) : silenceSaid(silenceFor)}
|
|
25400
25836
|
`);
|
|
25401
25837
|
giveUp(false);
|
|
25402
25838
|
}, background ? BACKGROUND_WAIT.minutes * 6e4 : silenceMs);
|
|
@@ -25423,7 +25859,8 @@ Cannot resume board repair: ${next.error}`;
|
|
|
25423
25859
|
log: append2,
|
|
25424
25860
|
gotResumeId: (id, restarted) => gotResumeId(id, restarted),
|
|
25425
25861
|
gotModel: (model) => gotModel(model),
|
|
25426
|
-
event: event2
|
|
25862
|
+
event: event2,
|
|
25863
|
+
gotContext
|
|
25427
25864
|
}).then((end2) => {
|
|
25428
25865
|
spoken = end2;
|
|
25429
25866
|
endChild();
|
|
@@ -25437,11 +25874,11 @@ Cannot resume board repair: ${next.error}`;
|
|
|
25437
25874
|
child.on("close", (code) => void finish(code, peekRun(sessionId)?.stopping === true || stopped2));
|
|
25438
25875
|
});
|
|
25439
25876
|
}
|
|
25440
|
-
function settleBoard(
|
|
25877
|
+
function settleBoard(run3, changed, before) {
|
|
25441
25878
|
try {
|
|
25442
|
-
const helpers = specRunsAfter(readSpecAsks(
|
|
25443
|
-
const waitingForSpec = helpers.some((req) => req.id ===
|
|
25444
|
-
return refinementRunsAfter(
|
|
25879
|
+
const helpers = specRunsAfter(readSpecAsks(run3.sessionId));
|
|
25880
|
+
const waitingForSpec = helpers.some((req) => req.id === run3.cardId);
|
|
25881
|
+
return refinementRunsAfter(run3, changed, before, waitingForSpec, readSpecRefusals(run3.sessionId));
|
|
25445
25882
|
} catch {
|
|
25446
25883
|
return null;
|
|
25447
25884
|
}
|
|
@@ -25501,7 +25938,7 @@ function catchModel(sessionId, model) {
|
|
|
25501
25938
|
});
|
|
25502
25939
|
return true;
|
|
25503
25940
|
}
|
|
25504
|
-
var STOP_GRACE_MS, STOP_CLOSE_MS, STOP_FINISH_MS, silenceSaid,
|
|
25941
|
+
var STOP_GRACE_MS, STOP_CLOSE_MS, STOP_FINISH_MS, silenceSaid, MAX_FORMAT_REPAIRS, joinNotes;
|
|
25505
25942
|
var init_watch = __esm({
|
|
25506
25943
|
"../cli/src/lib/agent/watch.ts"() {
|
|
25507
25944
|
"use strict";
|
|
@@ -25522,6 +25959,7 @@ var init_watch = __esm({
|
|
|
25522
25959
|
init_follow();
|
|
25523
25960
|
init_propose();
|
|
25524
25961
|
init_log();
|
|
25962
|
+
init_background();
|
|
25525
25963
|
init_wire();
|
|
25526
25964
|
init_prompts();
|
|
25527
25965
|
init_resolve();
|
|
@@ -25534,7 +25972,6 @@ var init_watch = __esm({
|
|
|
25534
25972
|
STOP_CLOSE_MS = 2e3;
|
|
25535
25973
|
STOP_FINISH_MS = 1e4;
|
|
25536
25974
|
silenceSaid = (minutes) => `the agent said nothing for ${minutes} minute${minutes === 1 ? "" : "s"}, so the run was ended.`;
|
|
25537
|
-
backgroundSaid = (minutes) => `the agent's background tasks did not finish within ${minutes / 60} hours, so the run was ended.`;
|
|
25538
25975
|
MAX_FORMAT_REPAIRS = 3;
|
|
25539
25976
|
joinNotes = (...parts) => parts.filter(Boolean).join("\n\n") || void 0;
|
|
25540
25977
|
}
|
|
@@ -25545,6 +25982,10 @@ import fs83 from "node:fs";
|
|
|
25545
25982
|
import path83 from "node:path";
|
|
25546
25983
|
async function cmdStartRun(action, args, opts, program2 = "akb") {
|
|
25547
25984
|
const { req, follow: follow2, print } = readRequest(action, args, opts);
|
|
25985
|
+
if (!print && (action === "approve" || action === "implement")) {
|
|
25986
|
+
const deferred = await approveAfterReply(String(req.id), req.notes);
|
|
25987
|
+
if (deferred) return deferred;
|
|
25988
|
+
}
|
|
25548
25989
|
if (Number.isInteger(req.id)) {
|
|
25549
25990
|
const creating = creationRefusal(req.id, cardCreation(req.id, req.discard === true), action, req.discard === true);
|
|
25550
25991
|
if (creating) die(creating, { kind: "card-being-created", action });
|
|
@@ -25587,13 +26028,13 @@ async function cmdStartRun(action, args, opts, program2 = "akb") {
|
|
|
25587
26028
|
sayIfHeld(req, program2);
|
|
25588
26029
|
const started = action === "refine" ? await startRefinement(req) : await startRun(runnable);
|
|
25589
26030
|
if ("error" in started) die(started.error, { kind: "run-refused", action });
|
|
25590
|
-
const { run:
|
|
25591
|
-
if (!spawned) die(`couldn't start a process for run ${
|
|
25592
|
-
say(`${action} \u2014 run ${
|
|
25593
|
-
say(` follow it: ${program2} raw run log ${short(
|
|
25594
|
-
say(` stop it: ${program2} raw run stop ${short(
|
|
25595
|
-
if (follow2) return await followStarted(
|
|
25596
|
-
return { sessionId:
|
|
26031
|
+
const { run: run3, spawned } = started;
|
|
26032
|
+
if (!spawned) die(`couldn't start a process for run ${run3.sessionId}`, { kind: "spawn-failed" });
|
|
26033
|
+
say(`${action} \u2014 run ${run3.sessionId}${run3.deliveryId ? ` in delivery ${run3.deliveryId}` : ""}`);
|
|
26034
|
+
say(` follow it: ${program2} raw run log ${short(run3.sessionId)} --follow${BOARD_FLAG}`);
|
|
26035
|
+
say(` stop it: ${program2} raw run stop ${short(run3.sessionId)}${BOARD_FLAG}`);
|
|
26036
|
+
if (follow2) return await followStarted(run3.sessionId, program2, opts.events === true);
|
|
26037
|
+
return { sessionId: run3.sessionId, action, cardId: run3.cardId };
|
|
25597
26038
|
}
|
|
25598
26039
|
async function cmdRunScheduled(studio, agent, opts, program2 = "akb") {
|
|
25599
26040
|
const id = knownStudio(studio);
|
|
@@ -25603,12 +26044,12 @@ async function cmdRunScheduled(studio, agent, opts, program2 = "akb") {
|
|
|
25603
26044
|
if (insideRun() || opts.print) return printFlow(req, program2);
|
|
25604
26045
|
const started = await startRun(req);
|
|
25605
26046
|
if ("error" in started) die(started.error, { kind: "run-refused", action: "scheduled" });
|
|
25606
|
-
const { run:
|
|
25607
|
-
if (!spawned) die(`couldn't start a process for run ${
|
|
25608
|
-
say(`${one.agent} \u2014 run ${
|
|
25609
|
-
say(` follow it: ${program2} raw run log ${short(
|
|
25610
|
-
if (opts.follow) return await followStarted(
|
|
25611
|
-
return { sessionId:
|
|
26047
|
+
const { run: run3, spawned } = started;
|
|
26048
|
+
if (!spawned) die(`couldn't start a process for run ${run3.sessionId}`, { kind: "spawn-failed" });
|
|
26049
|
+
say(`${one.agent} \u2014 run ${run3.sessionId}${run3.deliveryId ? ` in delivery ${run3.deliveryId}` : ""}`);
|
|
26050
|
+
say(` follow it: ${program2} raw run log ${short(run3.sessionId)} --follow${BOARD_FLAG}`);
|
|
26051
|
+
if (opts.follow) return await followStarted(run3.sessionId, program2, opts.events === true);
|
|
26052
|
+
return { sessionId: run3.sessionId, action: "scheduled" };
|
|
25612
26053
|
}
|
|
25613
26054
|
async function approveInCloud(project2, id) {
|
|
25614
26055
|
const approved = await approveTask(project2, id);
|
|
@@ -25698,12 +26139,12 @@ function readRequest(action, args, opts) {
|
|
|
25698
26139
|
async function cmdResume(id, opts) {
|
|
25699
26140
|
const opened = await startResume(id ?? "last", opts.requireSession);
|
|
25700
26141
|
if ("error" in opened) die(opened.error, { kind: "run-refused", ..."reason" in opened ? { reason: opened.reason } : {} });
|
|
25701
|
-
const { run:
|
|
25702
|
-
if (!opened.spawned) die(`couldn't start a process for run ${
|
|
25703
|
-
const within =
|
|
25704
|
-
say(
|
|
25705
|
-
if (opts.follow === true) return await followStarted(
|
|
25706
|
-
return { sessionId:
|
|
26142
|
+
const { run: run3 } = opened;
|
|
26143
|
+
if (!opened.spawned) die(`couldn't start a process for run ${run3.sessionId}`, { kind: "spawn-failed" });
|
|
26144
|
+
const within = run3.deliveryId ? ` in delivery ${run3.deliveryId}` : "";
|
|
26145
|
+
say(run3.resumedFrom ? `continuing ${short(run3.resumedFrom)} \u2014 run ${run3.sessionId}${within}` : `trying again \u2014 run ${run3.sessionId}${within}`);
|
|
26146
|
+
if (opts.follow === true) return await followStarted(run3.sessionId, "akb", opts.events === true);
|
|
26147
|
+
return { sessionId: run3.sessionId, resumedFrom: run3.resumedFrom };
|
|
25707
26148
|
}
|
|
25708
26149
|
async function cmdCancel(named2) {
|
|
25709
26150
|
const res = await cancelBoardDelivery(named2);
|
|
@@ -26058,6 +26499,7 @@ var init_run = __esm({
|
|
|
26058
26499
|
init_io();
|
|
26059
26500
|
init_lock();
|
|
26060
26501
|
init_paths();
|
|
26502
|
+
init_reply_approval();
|
|
26061
26503
|
init_tasks();
|
|
26062
26504
|
init_read();
|
|
26063
26505
|
init_rules();
|
|
@@ -26240,16 +26682,16 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
26240
26682
|
}
|
|
26241
26683
|
const started = await startRun(req);
|
|
26242
26684
|
if ("error" in started) die(started.error, { kind: "run-refused", action: "spec" });
|
|
26243
|
-
const { run:
|
|
26244
|
-
if (!spawned) die(`couldn't start a process to run ${
|
|
26685
|
+
const { run: run3, spawned } = started;
|
|
26686
|
+
if (!spawned) die(`couldn't start a process to run ${run3.sessionId}`, { kind: "spawn-failed" });
|
|
26245
26687
|
if (ownRuntime || ownSession) {
|
|
26246
26688
|
say(`${name} runs in ${ownRuntime ? "its own runtime" : "a session of its own"}, so it started as a separate run \u2014 don't write its section yourself.`);
|
|
26247
26689
|
}
|
|
26248
|
-
say(`previews ${name} #${id} \u2014 run ${
|
|
26249
|
-
say(` follow it: ${program2} raw run log ${short(
|
|
26250
|
-
say(` stop it: ${program2} raw run stop ${short(
|
|
26251
|
-
if (opts.follow === true) return await followStarted(
|
|
26252
|
-
return { sessionId:
|
|
26690
|
+
say(`previews ${name} #${id} \u2014 run ${run3.sessionId}`);
|
|
26691
|
+
say(` follow it: ${program2} raw run log ${short(run3.sessionId)} --follow${BOARD_FLAG}`);
|
|
26692
|
+
say(` stop it: ${program2} raw run stop ${short(run3.sessionId)}${BOARD_FLAG}`);
|
|
26693
|
+
if (opts.follow === true) return await followStarted(run3.sessionId, program2);
|
|
26694
|
+
return { sessionId: run3.sessionId, action: "spec", specAgent: name, cardId: id };
|
|
26253
26695
|
}
|
|
26254
26696
|
function noteOf(words, flag) {
|
|
26255
26697
|
const typed = words.join(" ").trim();
|
|
@@ -26322,7 +26764,7 @@ var init_telemetry2 = __esm({
|
|
|
26322
26764
|
|
|
26323
26765
|
// ../cli/src/commands/agent-check.ts
|
|
26324
26766
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
26325
|
-
function
|
|
26767
|
+
function run2(file, args) {
|
|
26326
26768
|
const start = spawnable(file, args, { env: copyEnv(file), stdio: ["ignore", "pipe", "pipe"], timeout: 1e4 });
|
|
26327
26769
|
const ran = spawnSync5(start.command, start.args, { ...start.options, encoding: "utf8" });
|
|
26328
26770
|
return { out: `${ran.stdout ?? ""}${ran.stderr ?? ""}`.trim(), error: ran.error?.message };
|
|
@@ -26336,14 +26778,14 @@ function cmdAgentCheck(name) {
|
|
|
26336
26778
|
const answer2 = { agent: harness.name, file: copy2?.file ?? null, version: copy2?.version ?? null };
|
|
26337
26779
|
if (!copy2) die(`${harness.label} not found: no \`${binary}\` on the PATH or in its usual install folders.`, { kind: "agent-missing" });
|
|
26338
26780
|
if (!copy2.starts) {
|
|
26339
|
-
const said2 =
|
|
26781
|
+
const said2 = run2(copy2.file, ["--version"]);
|
|
26340
26782
|
die(`${harness.label} at ${copy2.file} failed to start: ${said2.error ?? said2.out.split("\n")[0] ?? "no output"}`, { kind: "agent-broken" });
|
|
26341
26783
|
}
|
|
26342
26784
|
if (harness.name === "dsh" && !dshFound(copy2.file, binaryOnPath)) {
|
|
26343
26785
|
die(`${harness.label}: dsh-acp is installed, but the dsh it starts is not \u2014 install dsh beside it or on the PATH.`, { kind: "agent-missing" });
|
|
26344
26786
|
}
|
|
26345
26787
|
if (harness.login) {
|
|
26346
|
-
const said2 =
|
|
26788
|
+
const said2 = run2(copy2.file, harness.login.args).out;
|
|
26347
26789
|
if (!harness.login.ready(said2) && harness.login.loggedOut(said2)) {
|
|
26348
26790
|
die(`${harness.label} is signed out: run \`${harness.login.login}\`.`, { kind: "agent-signed-out" });
|
|
26349
26791
|
}
|
|
@@ -26636,8 +27078,8 @@ function declareRuns(program2, cli) {
|
|
|
26636
27078
|
if (code !== 0) throw new BoardError(`the watcher for ${sessionId} ended with ${code}`, { kind: "watch-failed" });
|
|
26637
27079
|
});
|
|
26638
27080
|
}
|
|
26639
|
-
function declareRunning(
|
|
26640
|
-
const verb = (name) => withShared(
|
|
27081
|
+
function declareRunning(run3, cli) {
|
|
27082
|
+
const verb = (name) => withShared(run3.command(name));
|
|
26641
27083
|
verb("list").summary("what is running, and what ran lately").description("A creation run with no card fails even if the agent exits with code 0. Failure reason, triage source and cost are kept. In JSON the run reports status: error and ok: false; the outer ok describes this query. A successful query exits with code 0.").option("-c, --card <id>", "only the runs on that card", cardId).option("-a, --all", "every run this board has kept, not just the last ten").action(async function() {
|
|
26642
27084
|
await onBoard2(this, cli, (p) => cmdRuns(this.opts(), p));
|
|
26643
27085
|
});
|