@voyager-crew/cli 0.3.0 → 0.5.0
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/README.md +24 -3
- package/README_ZH.md +15 -3
- package/dist/cli.mjs +678 -196
- package/package.json +4 -3
- package/skills/voyager/SKILL.md +28 -13
package/dist/cli.mjs
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
import { basename as basename3 } from "node:path";
|
|
5
5
|
|
|
6
6
|
// src/plugins/api.ts
|
|
7
|
+
function conversationConflictKey(conversationId) {
|
|
8
|
+
return `conversation ${conversationId}`;
|
|
9
|
+
}
|
|
7
10
|
function definePlugin(plugin) {
|
|
8
11
|
return plugin;
|
|
9
12
|
}
|
|
@@ -225,6 +228,7 @@ var ERROR_CATEGORIES = {
|
|
|
225
228
|
"model-not-found": "user-action",
|
|
226
229
|
"effort-unavailable": "user-action",
|
|
227
230
|
"composer-busy": "user-action",
|
|
231
|
+
"approval-required": "user-action",
|
|
228
232
|
"tab-hidden": "user-action",
|
|
229
233
|
"busy-stale": "user-action",
|
|
230
234
|
"extension-offline": "user-action",
|
|
@@ -271,6 +275,7 @@ var POLL_HOLD_MS = 25000;
|
|
|
271
275
|
var TASK_ACK_DEADLINE_MS = 1e4;
|
|
272
276
|
var EXTENSION_OFFLINE_MS = 90000;
|
|
273
277
|
var MAX_JSON_BODY_BYTES = 1024 * 1024;
|
|
278
|
+
var MAX_INFLIGHT_TASKS = 16;
|
|
274
279
|
var MAX_BLOB_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
275
280
|
var EXTENSION_ORIGIN_PATTERNS = [
|
|
276
281
|
/^chrome-extension:\/\/[a-p]{32}$/,
|
|
@@ -350,6 +355,7 @@ var OP_NAMES = [
|
|
|
350
355
|
"composer.attach",
|
|
351
356
|
"composer.send",
|
|
352
357
|
"turns.waitReply",
|
|
358
|
+
"turns.approve",
|
|
353
359
|
"turns.read",
|
|
354
360
|
"files.download",
|
|
355
361
|
"catalog.refresh",
|
|
@@ -366,6 +372,7 @@ var MAX_ATTACHMENTS = 10;
|
|
|
366
372
|
var MAX_ATTACHMENT_BYTES = 64 * 1024 * 1024;
|
|
367
373
|
var WAIT_REPLY_MAX_TIMEOUT_MS = 12 * 60 * 60000;
|
|
368
374
|
var WAIT_REPLY_DEFAULT_STALL_MS = 20 * 60000;
|
|
375
|
+
var MAX_FILE_CANDIDATES = 100;
|
|
369
376
|
var CATALOG_HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
370
377
|
// node_modules/@voyager-crew/bridge-protocol/src/version.ts
|
|
371
378
|
var PROTOCOL = { min: 1, max: 1 };
|
|
@@ -379,6 +386,7 @@ var OP_VERSIONS = {
|
|
|
379
386
|
"composer.attach": 1,
|
|
380
387
|
"composer.send": 1,
|
|
381
388
|
"turns.waitReply": 1,
|
|
389
|
+
"turns.approve": 1,
|
|
382
390
|
"turns.read": 1,
|
|
383
391
|
"files.download": 1,
|
|
384
392
|
"catalog.refresh": 1,
|
|
@@ -554,11 +562,11 @@ var PROJECT_RESULT_READERS = {
|
|
|
554
562
|
// node_modules/@voyager-crew/bridge-protocol/src/validate/ops.ts
|
|
555
563
|
var CHAT_MODES = ["chat", "work", "unknown"];
|
|
556
564
|
var SWITCHABLE_MODES2 = ["chat", "work"];
|
|
565
|
+
var APPROVAL_CHOICES = ["always", "once"];
|
|
557
566
|
var HTTPS_URL2 = { pattern: /^https:\/\//, maxLength: 4096 };
|
|
558
567
|
var TURN_KEY = { maxLength: 256 };
|
|
559
568
|
var LABEL = { maxLength: 200, allowEmpty: true };
|
|
560
569
|
var FILE_NAME2 = { pattern: /^[^/\\\0]+$/, maxLength: 255 };
|
|
561
|
-
var MAX_FILE_CANDIDATES = 100;
|
|
562
570
|
var CATALOG_HOST = { pattern: CATALOG_HOST_PATTERN, maxLength: 253 };
|
|
563
571
|
var CATALOG_STATUSES = [
|
|
564
572
|
"updated",
|
|
@@ -725,12 +733,22 @@ var PARAM_READERS = {
|
|
|
725
733
|
max: WAIT_REPLY_MAX_TIMEOUT_MS
|
|
726
734
|
});
|
|
727
735
|
const stableMs = optionalInt(rec, "stableMs", path, issues, { max: 60000 });
|
|
736
|
+
const stopOnApproval = optionalBoolean(rec, "stopOnApproval", path, issues);
|
|
728
737
|
return {
|
|
729
738
|
conversationId: readConversationId(rec, path, issues),
|
|
730
739
|
afterUserTurnKey: requireString(rec, "afterUserTurnKey", path, issues, TURN_KEY),
|
|
731
740
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
732
741
|
...stallMs === undefined ? {} : { stallMs },
|
|
733
|
-
...stableMs === undefined ? {} : { stableMs }
|
|
742
|
+
...stableMs === undefined ? {} : { stableMs },
|
|
743
|
+
...stopOnApproval === undefined ? {} : { stopOnApproval }
|
|
744
|
+
};
|
|
745
|
+
},
|
|
746
|
+
"turns.approve": (raw, path, issues) => {
|
|
747
|
+
const rec = readObject(raw, path, issues);
|
|
748
|
+
return {
|
|
749
|
+
conversationId: readConversationId(rec, path, issues),
|
|
750
|
+
afterUserTurnKey: requireString(rec, "afterUserTurnKey", path, issues, TURN_KEY),
|
|
751
|
+
choice: requireLiteral(rec, "choice", path, issues, APPROVAL_CHOICES)
|
|
734
752
|
};
|
|
735
753
|
},
|
|
736
754
|
"turns.read": (raw, path, issues) => {
|
|
@@ -846,6 +864,14 @@ var RESULT_READERS = {
|
|
|
846
864
|
evidence: requireRecord(rec, "evidence", path, issues)
|
|
847
865
|
};
|
|
848
866
|
},
|
|
867
|
+
"turns.approve": (raw, path, issues) => {
|
|
868
|
+
const rec = readObject(raw, path, issues);
|
|
869
|
+
return {
|
|
870
|
+
clicked: requireBoolean(rec, "clicked", path, issues),
|
|
871
|
+
app: requireString(rec, "app", path, issues, LABEL),
|
|
872
|
+
evidence: requireRecord(rec, "evidence", path, issues)
|
|
873
|
+
};
|
|
874
|
+
},
|
|
849
875
|
"turns.read": (raw, path, issues) => {
|
|
850
876
|
const rec = readObject(raw, path, issues);
|
|
851
877
|
const messageId = optionalString(rec, "messageId", path, issues, { maxLength: 256 });
|
|
@@ -926,6 +952,11 @@ function envelopeReader(data) {
|
|
|
926
952
|
};
|
|
927
953
|
}
|
|
928
954
|
var anyData = (raw) => raw;
|
|
955
|
+
function readMaxTasks(raw) {
|
|
956
|
+
if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 1)
|
|
957
|
+
return 1;
|
|
958
|
+
return Math.min(raw, MAX_INFLIGHT_TASKS);
|
|
959
|
+
}
|
|
929
960
|
var readOpCapability = (raw, path, issues) => {
|
|
930
961
|
const rec = readObject(raw, path, issues);
|
|
931
962
|
return {
|
|
@@ -1005,12 +1036,13 @@ var READERS = {
|
|
|
1005
1036
|
taskId: requireString(entry, "taskId", itemPath, list, ID),
|
|
1006
1037
|
state: requireLiteral(entry, "state", itemPath, list, ["acked", "running"])
|
|
1007
1038
|
};
|
|
1008
|
-
}, { max:
|
|
1039
|
+
}, { max: MAX_INFLIGHT_TASKS }),
|
|
1009
1040
|
policy: {
|
|
1010
1041
|
revision: requireInt(policy, "revision", policyPath, issues),
|
|
1011
1042
|
state: requireLiteral(policy, "state", policyPath, issues, POLICY_STATES)
|
|
1012
1043
|
},
|
|
1013
|
-
...rec.account === undefined ? {} : { account: readAccountPlan(rec.account) }
|
|
1044
|
+
...rec.account === undefined ? {} : { account: readAccountPlan(rec.account) },
|
|
1045
|
+
...rec.maxTasks === undefined ? {} : { maxTasks: readMaxTasks(rec.maxTasks) }
|
|
1014
1046
|
};
|
|
1015
1047
|
},
|
|
1016
1048
|
pollResponse: (raw, path, issues) => {
|
|
@@ -1061,13 +1093,17 @@ var READERS = {
|
|
|
1061
1093
|
},
|
|
1062
1094
|
blobChunk: (raw, path, issues) => {
|
|
1063
1095
|
const rec = readObject(raw, path, issues);
|
|
1096
|
+
const base64 = requireString(rec, "base64", path, issues, {
|
|
1097
|
+
pattern: /^[A-Za-z0-9+/]*={0,2}$/,
|
|
1098
|
+
maxLength: MAX_BLOB_CHUNK_BASE64
|
|
1099
|
+
});
|
|
1100
|
+
if (base64.length > 0 && base64DecodedLength(base64) === undefined) {
|
|
1101
|
+
fail(issues, at(path, "base64"), "must be padded base64");
|
|
1102
|
+
}
|
|
1064
1103
|
return {
|
|
1065
1104
|
blobId: requireString(rec, "blobId", path, issues, ID),
|
|
1066
1105
|
offset: requireInt(rec, "offset", path, issues),
|
|
1067
|
-
base64
|
|
1068
|
-
pattern: /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
|
|
1069
|
-
maxLength: MAX_BLOB_CHUNK_BASE64
|
|
1070
|
-
})
|
|
1106
|
+
base64
|
|
1071
1107
|
};
|
|
1072
1108
|
},
|
|
1073
1109
|
blobCommitResponse: (raw, path, issues) => {
|
|
@@ -2196,6 +2232,52 @@ function presentResponse(job) {
|
|
|
2196
2232
|
};
|
|
2197
2233
|
}
|
|
2198
2234
|
|
|
2235
|
+
// plugins/ask/approval.ts
|
|
2236
|
+
var APPROVAL_CHOICES2 = ["always", "once"];
|
|
2237
|
+
var MAX_APPROVALS = 10;
|
|
2238
|
+
function parseApproveApps(raw) {
|
|
2239
|
+
if (raw === undefined)
|
|
2240
|
+
return;
|
|
2241
|
+
const choice = APPROVAL_CHOICES2.find((known) => known === raw);
|
|
2242
|
+
if (choice === undefined) {
|
|
2243
|
+
throw failure("bad-request", `--approve-apps takes ${APPROVAL_CHOICES2.join(" or ")}`);
|
|
2244
|
+
}
|
|
2245
|
+
return choice;
|
|
2246
|
+
}
|
|
2247
|
+
async function waitReplyApproving(ctx, target, choice) {
|
|
2248
|
+
const params = {
|
|
2249
|
+
conversationId: target.conversationId,
|
|
2250
|
+
afterUserTurnKey: target.afterUserTurnKey,
|
|
2251
|
+
stopOnApproval: true
|
|
2252
|
+
};
|
|
2253
|
+
for (let answered = 0;; answered += 1) {
|
|
2254
|
+
try {
|
|
2255
|
+
return await ctx.ops.call("turns.waitReply", params);
|
|
2256
|
+
} catch (thrown) {
|
|
2257
|
+
const error = toBridgeError(thrown);
|
|
2258
|
+
if (error.code !== "approval-required")
|
|
2259
|
+
throw thrown;
|
|
2260
|
+
const app = typeof error.details?.app === "string" && error.details.app !== "" ? error.details.app : "one of its apps";
|
|
2261
|
+
if (choice === undefined) {
|
|
2262
|
+
throw failure("approval-required", `ChatGPT asks to allow ${app} before the reply goes on: answer it at ${target.url} and read the reply with \`voyager read\`, or ask with --approve-apps always`, error.details);
|
|
2263
|
+
}
|
|
2264
|
+
if (answered >= MAX_APPROVALS) {
|
|
2265
|
+
throw failure("approval-required", `ChatGPT asked to allow ${app} again after ${MAX_APPROVALS} answers`, error.details);
|
|
2266
|
+
}
|
|
2267
|
+
const approved = await ctx.ops.call("turns.approve", {
|
|
2268
|
+
conversationId: target.conversationId,
|
|
2269
|
+
afterUserTurnKey: target.afterUserTurnKey,
|
|
2270
|
+
choice
|
|
2271
|
+
});
|
|
2272
|
+
ctx.log.info("answered an app approval card", {
|
|
2273
|
+
app: approved.app,
|
|
2274
|
+
choice,
|
|
2275
|
+
clicked: approved.clicked
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2199
2281
|
// plugins/ask/drive.ts
|
|
2200
2282
|
import { execFile as execFile2 } from "node:child_process";
|
|
2201
2283
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
@@ -2209,7 +2291,13 @@ async function loadConfig(paths) {
|
|
|
2209
2291
|
const port = isRecord2(raw) ? raw.port : undefined;
|
|
2210
2292
|
const valid = typeof port === "number" && Number.isInteger(port) && port > 0 && port < 65536;
|
|
2211
2293
|
const driveRemote = isRecord2(raw) && typeof raw.driveRemote === "string" ? raw.driveRemote.trim() : "";
|
|
2212
|
-
|
|
2294
|
+
const maxJobs = isRecord2(raw) ? raw.maxParallelJobs : undefined;
|
|
2295
|
+
const usable2 = typeof maxJobs === "number" && Number.isSafeInteger(maxJobs) && maxJobs >= 1;
|
|
2296
|
+
return {
|
|
2297
|
+
port: valid ? port : DEFAULT_PORT,
|
|
2298
|
+
...driveRemote === "" ? {} : { driveRemote },
|
|
2299
|
+
...maxJobs === undefined ? {} : usable2 ? { maxParallelJobs: maxJobs } : { maxParallelJobs: 1, invalidMaxParallelJobs: JSON.stringify(maxJobs) }
|
|
2300
|
+
};
|
|
2213
2301
|
}
|
|
2214
2302
|
|
|
2215
2303
|
// src/state/paths.ts
|
|
@@ -2430,6 +2518,33 @@ function checkRepoReach(target, result) {
|
|
|
2430
2518
|
});
|
|
2431
2519
|
}
|
|
2432
2520
|
|
|
2521
|
+
// plugins/ask/timebox.ts
|
|
2522
|
+
var SUGGESTED_TIMEBOX_MINUTES = 70;
|
|
2523
|
+
var MIN_MINUTES = 5;
|
|
2524
|
+
var MAX_MINUTES = 600;
|
|
2525
|
+
function parseTimebox(raw) {
|
|
2526
|
+
if (raw === undefined)
|
|
2527
|
+
return;
|
|
2528
|
+
const text = String(raw).trim().replace(/m$/i, "");
|
|
2529
|
+
const minutes = /^\d+$/.test(text) ? Number(text) : Number.NaN;
|
|
2530
|
+
if (!(minutes >= MIN_MINUTES && minutes <= MAX_MINUTES)) {
|
|
2531
|
+
throw failure("bad-request", `--timebox takes minutes from ${MIN_MINUTES} to ${MAX_MINUTES} (${SUGGESTED_TIMEBOX_MINUTES} for long Pro work), not ${JSON.stringify(String(raw))}`);
|
|
2532
|
+
}
|
|
2533
|
+
return minutes;
|
|
2534
|
+
}
|
|
2535
|
+
function timeboxPromptBlock(minutes) {
|
|
2536
|
+
return [
|
|
2537
|
+
`Time and wrap-up: a turn like this can lose its connection after about 80 minutes of work, and after that nothing is delivered and the sandbox files are lost. So please plan around a ${minutes}-minute countdown:`,
|
|
2538
|
+
`- When you start, note the time in your sandbox, and check it after each piece of work.`,
|
|
2539
|
+
`- When the ${minutes} minutes are up, start nothing new, wherever you are, and wrap up; leave about 10 minutes for that.`,
|
|
2540
|
+
`- Finish one piece completely before starting the next, so that a stop leaves whole pieces rather than many halves. If something still fails on the third try, set it aside, note it, and move on.`,
|
|
2541
|
+
`- If you make files, put them under /mnt/data/ and link them in your reply. Link each finished piece as soon as it is done, then one ZIP at the end with finished/ (work that passed your checks), unfinished/ (each with how far it got and what is missing) and METHOD.md (how you worked, how you checked, what did not work).`,
|
|
2542
|
+
`- If you use subagents, they keep the same countdown and hand back what they have before it ends.`,
|
|
2543
|
+
`- Open your reply with one line: finished N / unfinished M / about X minutes.`
|
|
2544
|
+
].join(`
|
|
2545
|
+
`);
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2433
2548
|
// plugins/ask/index.ts
|
|
2434
2549
|
var PHASE_C_OPTIONS = ["out"];
|
|
2435
2550
|
function attachTimeoutMs(bytes) {
|
|
@@ -2484,9 +2599,16 @@ async function prepare(fg, argv) {
|
|
|
2484
2599
|
dryRun: argv.options["dry-run"] === true
|
|
2485
2600
|
});
|
|
2486
2601
|
const repo = typeof argv.options.repo === "string" ? parseRepo(argv.options.repo) : undefined;
|
|
2602
|
+
const approveApps = parseApproveApps(argv.options["approve-apps"]);
|
|
2487
2603
|
if (repo !== undefined)
|
|
2488
2604
|
fg.note(`repo: ChatGPT is asked to write only to ${repo.branch}`);
|
|
2489
|
-
const
|
|
2605
|
+
const timebox = parseTimebox(argv.options.timebox);
|
|
2606
|
+
const prompt = [
|
|
2607
|
+
asked,
|
|
2608
|
+
drive.block,
|
|
2609
|
+
repo === undefined ? "" : repoPromptBlock(repo),
|
|
2610
|
+
timebox === undefined ? "" : timeboxPromptBlock(timebox)
|
|
2611
|
+
].filter((part) => part !== "").join(`
|
|
2490
2612
|
|
|
2491
2613
|
`);
|
|
2492
2614
|
return {
|
|
@@ -2497,7 +2619,8 @@ async function prepare(fg, argv) {
|
|
|
2497
2619
|
...project === undefined ? {} : { project },
|
|
2498
2620
|
...conversationId === undefined ? {} : { conversationId },
|
|
2499
2621
|
...attachments.length > 0 ? { attachments } : {},
|
|
2500
|
-
...repo === undefined ? {} : { repo }
|
|
2622
|
+
...repo === undefined ? {} : { repo },
|
|
2623
|
+
...approveApps === undefined ? {} : { approveApps }
|
|
2501
2624
|
};
|
|
2502
2625
|
}
|
|
2503
2626
|
function optionList(raw) {
|
|
@@ -2538,14 +2661,12 @@ async function run2(ctx, input) {
|
|
|
2538
2661
|
const shown = await callProjectOp(ctx, "project.open", { projectId, view: "chat" });
|
|
2539
2662
|
await ctx.checkpoint("project", { projectId, url: shown.url });
|
|
2540
2663
|
}
|
|
2541
|
-
const model = await chooseModel(ctx, input.model ?? DEFAULT_ASK_MODEL);
|
|
2542
2664
|
const result = await askInTab(ctx, input, {
|
|
2543
2665
|
startedAt,
|
|
2544
2666
|
blobs,
|
|
2545
2667
|
attachments,
|
|
2546
2668
|
existing,
|
|
2547
|
-
opened
|
|
2548
|
-
model
|
|
2669
|
+
opened
|
|
2549
2670
|
});
|
|
2550
2671
|
if (input.repo !== undefined)
|
|
2551
2672
|
checkRepoReach(input.repo, result);
|
|
@@ -2557,25 +2678,28 @@ async function askInTab(ctx, input, {
|
|
|
2557
2678
|
blobs,
|
|
2558
2679
|
attachments,
|
|
2559
2680
|
existing,
|
|
2560
|
-
opened
|
|
2561
|
-
model
|
|
2681
|
+
opened
|
|
2562
2682
|
}) {
|
|
2563
|
-
|
|
2564
|
-
const
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2683
|
+
const { model, sent } = await ctx.ops.exclusive(async () => {
|
|
2684
|
+
const chosen = await chooseModel(ctx, input.model ?? DEFAULT_ASK_MODEL);
|
|
2685
|
+
if (blobs.length > 0) {
|
|
2686
|
+
const bytes = blobs.reduce((sum, blob) => sum + blob.size, 0);
|
|
2687
|
+
const attached = await ctx.ops.call("composer.attach", { blobs }, { timeoutMs: attachTimeoutMs(bytes) });
|
|
2688
|
+
await ctx.checkpoint("attached", {
|
|
2689
|
+
names: attached.attached.map((entry) => entry.name),
|
|
2690
|
+
bytes
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
const preamble = attachmentPreamble(attachments);
|
|
2694
|
+
const text = preamble === "" ? input.prompt : `${input.prompt}
|
|
2573
2695
|
|
|
2574
2696
|
${preamble}`;
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2697
|
+
const confirmed = await sendOnce(ctx, {
|
|
2698
|
+
text,
|
|
2699
|
+
...blobs.length > 0 ? { expectAttachments: blobs.map((blob) => blob.name) } : {},
|
|
2700
|
+
...existing === undefined ? {} : { expect: { conversationId: existing } }
|
|
2701
|
+
});
|
|
2702
|
+
return { model: chosen, sent: confirmed };
|
|
2579
2703
|
});
|
|
2580
2704
|
const sentAt = Date.now();
|
|
2581
2705
|
if (existing !== undefined && sent.conversationId !== existing) {
|
|
@@ -2590,10 +2714,7 @@ ${preamble}`;
|
|
|
2590
2714
|
url: sent.url,
|
|
2591
2715
|
tabId: opened.tabId
|
|
2592
2716
|
});
|
|
2593
|
-
const reply = await ctx.
|
|
2594
|
-
conversationId: sent.conversationId,
|
|
2595
|
-
afterUserTurnKey: sent.userTurnKey
|
|
2596
|
-
});
|
|
2717
|
+
const reply = await waitReplyApproving(ctx, { conversationId: sent.conversationId, afterUserTurnKey: sent.userTurnKey, url: sent.url }, input.approveApps);
|
|
2597
2718
|
const repliedAt = Date.now();
|
|
2598
2719
|
const read = await ctx.ops.call("turns.read", {
|
|
2599
2720
|
conversationId: sent.conversationId,
|
|
@@ -2681,17 +2802,26 @@ var askPlugin = definePlugin({
|
|
|
2681
2802
|
multiple: true,
|
|
2682
2803
|
summary: "file or folder to attach (repeatable; folders are zipped without credentials)"
|
|
2683
2804
|
},
|
|
2805
|
+
timebox: {
|
|
2806
|
+
type: "string",
|
|
2807
|
+
summary: "ask ChatGPT to wrap up and hand over what it has after this many minutes (70 for long Pro sandbox work)"
|
|
2808
|
+
},
|
|
2684
2809
|
"dry-run": {
|
|
2685
2810
|
type: "boolean",
|
|
2686
2811
|
summary: "pack the attachments and print what would be sent, without sending"
|
|
2687
2812
|
},
|
|
2688
2813
|
out: { type: "string", summary: "also copy the outputs to this folder (Phase C)" },
|
|
2814
|
+
"approve-apps": {
|
|
2815
|
+
type: "string",
|
|
2816
|
+
summary: "answer ChatGPT's app approval card (Google Drive, GitHub…) mid-reply: always (its Always allow, kept in your ChatGPT settings) or once; without it the job stops there (exit 3)"
|
|
2817
|
+
},
|
|
2689
2818
|
"no-files": {
|
|
2690
2819
|
type: "boolean",
|
|
2691
2820
|
summary: "do not download the files the reply offers (saved under files/ otherwise)"
|
|
2692
2821
|
}
|
|
2693
2822
|
},
|
|
2694
2823
|
prepare,
|
|
2824
|
+
conflictKey: (input) => input.conversationId === undefined ? undefined : conversationConflictKey(input.conversationId),
|
|
2695
2825
|
run: run2,
|
|
2696
2826
|
present: presentResponse
|
|
2697
2827
|
}
|
|
@@ -2712,12 +2842,13 @@ function readFingerprint(raw) {
|
|
|
2712
2842
|
};
|
|
2713
2843
|
}
|
|
2714
2844
|
async function load(state) {
|
|
2715
|
-
let raw;
|
|
2716
2845
|
try {
|
|
2717
|
-
|
|
2846
|
+
return parse(await state.read());
|
|
2718
2847
|
} catch {
|
|
2719
2848
|
return {};
|
|
2720
2849
|
}
|
|
2850
|
+
}
|
|
2851
|
+
function parse(raw) {
|
|
2721
2852
|
const projects = {};
|
|
2722
2853
|
if (!isRecord2(raw) || !isRecord2(raw.uploads))
|
|
2723
2854
|
return projects;
|
|
@@ -2739,14 +2870,16 @@ async function fingerprintOf(state, projectId, name) {
|
|
|
2739
2870
|
return Object.hasOwn(projects, projectId) && Object.hasOwn(projects[projectId], name) ? projects[projectId][name] : undefined;
|
|
2740
2871
|
}
|
|
2741
2872
|
async function rememberUpload(state, projectId, name, fingerprint) {
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2873
|
+
await state.update((raw) => {
|
|
2874
|
+
const projects = parse(raw);
|
|
2875
|
+
const files = { ...Object.hasOwn(projects, projectId) ? projects[projectId] : {} };
|
|
2876
|
+
if (fingerprint)
|
|
2877
|
+
files[name] = fingerprint;
|
|
2878
|
+
else
|
|
2879
|
+
delete files[name];
|
|
2880
|
+
projects[projectId] = files;
|
|
2881
|
+
return { version: 1, uploads: projects };
|
|
2882
|
+
});
|
|
2750
2883
|
}
|
|
2751
2884
|
|
|
2752
2885
|
// plugins/project/index.ts
|
|
@@ -2959,6 +3092,7 @@ var projectPlugin = definePlugin({
|
|
|
2959
3092
|
"keep-tab": { type: "boolean", summary: "leave the bridge tab open afterwards" }
|
|
2960
3093
|
},
|
|
2961
3094
|
prepare: prepare2,
|
|
3095
|
+
conflictKey: (input) => input.action === "create" || input.action === "upload" || input.action === "remove" ? "project changes" : undefined,
|
|
2962
3096
|
run: run3,
|
|
2963
3097
|
present
|
|
2964
3098
|
}
|
|
@@ -3099,7 +3233,7 @@ class PluginRegistry {
|
|
|
3099
3233
|
// package.json
|
|
3100
3234
|
var package_default = {
|
|
3101
3235
|
name: "@voyager-crew/cli",
|
|
3102
|
-
version: "0.
|
|
3236
|
+
version: "0.5.0",
|
|
3103
3237
|
description: "Ask ChatGPT from your terminal or your coding agent, through the Voyager browser extension",
|
|
3104
3238
|
keywords: [
|
|
3105
3239
|
"chatgpt",
|
|
@@ -3141,11 +3275,12 @@ var package_default = {
|
|
|
3141
3275
|
format: "oxfmt",
|
|
3142
3276
|
"format:check": "oxfmt --check",
|
|
3143
3277
|
verify: "bun run format:check && bun run lint:check && bun run typecheck && bun run test",
|
|
3144
|
-
prepublishOnly: "bun run verify && bun run build"
|
|
3278
|
+
prepublishOnly: "bun run verify && bun run build",
|
|
3279
|
+
prepare: "node scripts/install-git-hooks.cjs"
|
|
3145
3280
|
},
|
|
3146
3281
|
devDependencies: {
|
|
3147
3282
|
"@types/node": "^24.9.0",
|
|
3148
|
-
"@voyager-crew/bridge-protocol": "^0.
|
|
3283
|
+
"@voyager-crew/bridge-protocol": "^0.5.0",
|
|
3149
3284
|
fflate: "0.8.2",
|
|
3150
3285
|
oxfmt: "^0.65.0",
|
|
3151
3286
|
oxlint: "^1.80.0",
|
|
@@ -3413,7 +3548,7 @@ function parseDuration(input) {
|
|
|
3413
3548
|
}
|
|
3414
3549
|
|
|
3415
3550
|
// src/cli/args.ts
|
|
3416
|
-
function
|
|
3551
|
+
function parse2(argv, defs) {
|
|
3417
3552
|
const options = {};
|
|
3418
3553
|
for (const [name, def] of Object.entries(defs)) {
|
|
3419
3554
|
options[name] = {
|
|
@@ -3455,7 +3590,7 @@ function waitTimeout(args) {
|
|
|
3455
3590
|
|
|
3456
3591
|
// src/cli/commands/info.ts
|
|
3457
3592
|
async function statusCommand(paths, argv) {
|
|
3458
|
-
const args =
|
|
3593
|
+
const args = parse2(argv, { json: { type: "boolean", summary: "JSON output" } });
|
|
3459
3594
|
const client = await ensureServe(paths);
|
|
3460
3595
|
const status = await client.request("GET", BRIDGE_PATHS.status);
|
|
3461
3596
|
if (args.options.json === true) {
|
|
@@ -3476,11 +3611,46 @@ async function statusCommand(paths, argv) {
|
|
|
3476
3611
|
const age = seenAt === undefined ? "" : `, seen ${Math.max(0, Math.round((Date.now() - seenAt) / 60000))} min ago`;
|
|
3477
3612
|
printLine(`${describeAccount(ext.account)}${ext.account ? age : ""}`);
|
|
3478
3613
|
}
|
|
3479
|
-
|
|
3614
|
+
for (const line of statusJobLines(status))
|
|
3615
|
+
printLine(line);
|
|
3480
3616
|
return 0;
|
|
3481
3617
|
}
|
|
3618
|
+
function statusJobLines(status, now = Date.now()) {
|
|
3619
|
+
const active = status.activeJobs ?? (status.activeJob === undefined ? [] : [status.activeJob]);
|
|
3620
|
+
const turns = active.length > 1;
|
|
3621
|
+
const named = active.map((job) => {
|
|
3622
|
+
const turn = !turns ? undefined : job.pageTurn === "holding" ? "has the page turn" : job.pageTurn === "waiting" ? "waiting for the page turn" : undefined;
|
|
3623
|
+
const notes = [job.op, turn].filter((part) => part !== undefined);
|
|
3624
|
+
return `${job.jobId}${notes.length > 0 ? ` (${notes.join(", ")})` : ""}`;
|
|
3625
|
+
});
|
|
3626
|
+
const label = named.length > 1 ? "active jobs" : "active job";
|
|
3627
|
+
const lines = [`${label}: ${named.length === 0 ? "none" : named.join(", ")}`];
|
|
3628
|
+
const parallel = parallelLine(status, now);
|
|
3629
|
+
if (parallel !== undefined)
|
|
3630
|
+
lines.push(parallel);
|
|
3631
|
+
return lines;
|
|
3632
|
+
}
|
|
3633
|
+
function parallelLine(status, now) {
|
|
3634
|
+
const ext = status.extension;
|
|
3635
|
+
const last = ext.lastPollAt;
|
|
3636
|
+
if (!ext.paired || last === null || now - last > EXTENSION_OFFLINE_MS)
|
|
3637
|
+
return;
|
|
3638
|
+
const offered = ext.maxTasks;
|
|
3639
|
+
const maxJobs = status.maxJobs ?? 1;
|
|
3640
|
+
if (offered === undefined) {
|
|
3641
|
+
return maxJobs > 1 ? `parallel jobs: up to ${maxJobs} at once` : undefined;
|
|
3642
|
+
}
|
|
3643
|
+
if (offered === null) {
|
|
3644
|
+
return `parallel jobs: not in Voyager ${ext.version ?? "?"} (one job at a time; a newer Voyager runs several)`;
|
|
3645
|
+
}
|
|
3646
|
+
if (offered <= 1)
|
|
3647
|
+
return "parallel jobs: off (one job at a time; turn it on in the Voyager popup)";
|
|
3648
|
+
if (maxJobs >= offered)
|
|
3649
|
+
return `parallel jobs: up to ${maxJobs} at once`;
|
|
3650
|
+
return `parallel jobs: up to ${maxJobs} at once (maxParallelJobs in config.json; the Voyager popup allows ${offered})`;
|
|
3651
|
+
}
|
|
3482
3652
|
async function commandsCommand(paths, argv) {
|
|
3483
|
-
const args =
|
|
3653
|
+
const args = parse2(argv, { json: { type: "boolean", summary: "JSON output" } });
|
|
3484
3654
|
const client = await ensureServe(paths);
|
|
3485
3655
|
const listed2 = await client.request("GET", BRIDGE_PATHS.commands);
|
|
3486
3656
|
if (args.options.json === true) {
|
|
@@ -3636,11 +3806,10 @@ async function submitAndWait(client, registry, args, submit) {
|
|
|
3636
3806
|
({ jobId } = await submit());
|
|
3637
3807
|
} catch (error) {
|
|
3638
3808
|
if (error instanceof BridgeFailure && error.code === "busy") {
|
|
3639
|
-
const active = String(error.error.details?.activeJobId ?? "?");
|
|
3640
3809
|
if (args.json)
|
|
3641
3810
|
printJson({ ok: false, error: error.error });
|
|
3642
3811
|
else
|
|
3643
|
-
note(
|
|
3812
|
+
note(busyNote(error.error));
|
|
3644
3813
|
return EXIT.busy;
|
|
3645
3814
|
}
|
|
3646
3815
|
throw error;
|
|
@@ -3656,6 +3825,17 @@ async function submitAndWait(client, registry, args, submit) {
|
|
|
3656
3825
|
note(`job ${jobId}`);
|
|
3657
3826
|
return waitAndPresent(client, registry, jobId, { ...args, account: account2 });
|
|
3658
3827
|
}
|
|
3828
|
+
function busyNote(error) {
|
|
3829
|
+
const active = String(error.details?.activeJobId ?? "?");
|
|
3830
|
+
const maxJobs = error.details?.maxJobs;
|
|
3831
|
+
if (typeof maxJobs !== "number" || maxJobs <= 1) {
|
|
3832
|
+
return `busy: job ${active} is running. Wait with voyager job wait ${active}; jobs are not queued.`;
|
|
3833
|
+
}
|
|
3834
|
+
const others = error.details?.activeJobIds;
|
|
3835
|
+
const several = error.details?.conflict === undefined && Array.isArray(others) && others.length > 1;
|
|
3836
|
+
const which = several ? ` (running: ${others.join(", ")})` : "";
|
|
3837
|
+
return `busy: ${error.message}. Wait with voyager job wait ${active}${which}.`;
|
|
3838
|
+
}
|
|
3659
3839
|
async function waitAndPresent(client, registry, jobId, args) {
|
|
3660
3840
|
const outcome = await waitForJob(client, jobId, args.timeoutMs, (event) => {
|
|
3661
3841
|
const line = args.json ? undefined : describeEvent(event);
|
|
@@ -3677,7 +3857,7 @@ async function waitAndPresent(client, registry, jobId, args) {
|
|
|
3677
3857
|
return presentJob(outcome.job, registry, args.json);
|
|
3678
3858
|
}
|
|
3679
3859
|
async function callCommand(paths, registry, argv) {
|
|
3680
|
-
const args =
|
|
3860
|
+
const args = parse2(argv, {
|
|
3681
3861
|
...WAIT_OPTIONS,
|
|
3682
3862
|
params: { type: "string", summary: "op params as JSON" }
|
|
3683
3863
|
});
|
|
@@ -3700,7 +3880,7 @@ async function callCommand(paths, registry, argv) {
|
|
|
3700
3880
|
}
|
|
3701
3881
|
async function jobCommand(paths, registry, argv) {
|
|
3702
3882
|
const [sub, ...rest] = argv;
|
|
3703
|
-
const args =
|
|
3883
|
+
const args = parse2(rest, WAIT_OPTIONS);
|
|
3704
3884
|
const json = args.options.json === true;
|
|
3705
3885
|
const jobId = args.positionals[0];
|
|
3706
3886
|
const needId = () => {
|
|
@@ -3750,7 +3930,7 @@ var CLI_LOCAL_PATHS = {
|
|
|
3750
3930
|
|
|
3751
3931
|
// src/cli/commands/pair.ts
|
|
3752
3932
|
async function pairCommand(paths, argv) {
|
|
3753
|
-
const args =
|
|
3933
|
+
const args = parse2(argv, {
|
|
3754
3934
|
revoke: { type: "boolean", summary: "forget the paired extension" },
|
|
3755
3935
|
json: { type: "boolean", summary: "JSON lines on stdout" }
|
|
3756
3936
|
});
|
|
@@ -3881,7 +4061,7 @@ function terminalConfirm() {
|
|
|
3881
4061
|
};
|
|
3882
4062
|
}
|
|
3883
4063
|
async function pluginCommand(paths, registry, found, argv) {
|
|
3884
|
-
const args =
|
|
4064
|
+
const args = parse2(argv, { ...WAIT_OPTIONS, ...found.def.options });
|
|
3885
4065
|
const confirm = terminalConfirm();
|
|
3886
4066
|
const fg = {
|
|
3887
4067
|
cwd: process.cwd(),
|
|
@@ -4178,7 +4358,7 @@ class IncomingBlobStore {
|
|
|
4178
4358
|
}
|
|
4179
4359
|
|
|
4180
4360
|
// src/jobs/jobRunner.ts
|
|
4181
|
-
import { join as
|
|
4361
|
+
import { join as join12 } from "node:path";
|
|
4182
4362
|
|
|
4183
4363
|
// src/server/extensionState.ts
|
|
4184
4364
|
function policyFailure(state, op) {
|
|
@@ -4198,6 +4378,7 @@ class ExtensionState {
|
|
|
4198
4378
|
ops = null;
|
|
4199
4379
|
policy = null;
|
|
4200
4380
|
account = null;
|
|
4381
|
+
maxTasks = null;
|
|
4201
4382
|
opNames() {
|
|
4202
4383
|
return this.ops === null ? null : new Set(this.ops.map((op) => op.name));
|
|
4203
4384
|
}
|
|
@@ -4206,12 +4387,78 @@ class ExtensionState {
|
|
|
4206
4387
|
this.ops = null;
|
|
4207
4388
|
this.policy = null;
|
|
4208
4389
|
this.account = null;
|
|
4390
|
+
this.maxTasks = null;
|
|
4209
4391
|
}
|
|
4210
4392
|
}
|
|
4211
4393
|
|
|
4212
|
-
// src/
|
|
4213
|
-
import {
|
|
4394
|
+
// src/state/pluginState.ts
|
|
4395
|
+
import { mkdir as mkdir6 } from "node:fs/promises";
|
|
4214
4396
|
import { join as join10 } from "node:path";
|
|
4397
|
+
var PLUGIN_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
4398
|
+
function pluginStateStore(paths, plugin) {
|
|
4399
|
+
if (!PLUGIN_NAME.test(plugin))
|
|
4400
|
+
throw new Error(`not a plugin name: ${plugin}`);
|
|
4401
|
+
const file = join10(paths.pluginState, `${plugin}.json`);
|
|
4402
|
+
return {
|
|
4403
|
+
read: () => readJsonFile(file),
|
|
4404
|
+
write: async (value) => {
|
|
4405
|
+
await mkdir6(paths.pluginState, { recursive: true, mode: 448 });
|
|
4406
|
+
await writeJsonAtomic(file, value);
|
|
4407
|
+
}
|
|
4408
|
+
};
|
|
4409
|
+
}
|
|
4410
|
+
function withSerialUpdates(base, last) {
|
|
4411
|
+
return {
|
|
4412
|
+
read: () => base.read(),
|
|
4413
|
+
write: (value) => base.write(value),
|
|
4414
|
+
update: (change) => {
|
|
4415
|
+
const next = last.current.then(async () => {
|
|
4416
|
+
const current = await base.read().catch(() => {
|
|
4417
|
+
return;
|
|
4418
|
+
});
|
|
4419
|
+
await base.write(change(current));
|
|
4420
|
+
});
|
|
4421
|
+
last.current = next.catch(() => {
|
|
4422
|
+
return;
|
|
4423
|
+
});
|
|
4424
|
+
return next;
|
|
4425
|
+
}
|
|
4426
|
+
};
|
|
4427
|
+
}
|
|
4428
|
+
|
|
4429
|
+
// src/jobs/admission.ts
|
|
4430
|
+
function jobCapacity(extensionMaxTasks, configured) {
|
|
4431
|
+
const extension = extensionMaxTasks ?? 1;
|
|
4432
|
+
return configured === undefined ? extension : Math.max(1, Math.min(extension, configured));
|
|
4433
|
+
}
|
|
4434
|
+
function admissionFailure(running, next, capacity) {
|
|
4435
|
+
const first = running[0];
|
|
4436
|
+
if (first === undefined)
|
|
4437
|
+
return;
|
|
4438
|
+
const details = {
|
|
4439
|
+
activeJobId: first.jobId,
|
|
4440
|
+
activeJobIds: running.map((job) => job.jobId),
|
|
4441
|
+
maxJobs: capacity
|
|
4442
|
+
};
|
|
4443
|
+
if (capacity <= 1)
|
|
4444
|
+
return failure("busy", "another job is running; it is not queued", details);
|
|
4445
|
+
if (next.alone || running.some((job) => job.alone)) {
|
|
4446
|
+
return failure("busy", "voyager call runs only while no other job does; it is not queued", details);
|
|
4447
|
+
}
|
|
4448
|
+
if (running.length >= capacity) {
|
|
4449
|
+
return failure("busy", `${running.length} jobs are running, as many as may run at once; it is not queued`, details);
|
|
4450
|
+
}
|
|
4451
|
+
const key = next.conflictKey;
|
|
4452
|
+
const clash = key === undefined ? undefined : running.find((job) => job.conflictKeys.includes(key));
|
|
4453
|
+
if (clash !== undefined) {
|
|
4454
|
+
return failure("busy", `job ${clash.jobId} is working on ${next.conflictKey}; it is not queued`, { ...details, activeJobId: clash.jobId, conflict: next.conflictKey });
|
|
4455
|
+
}
|
|
4456
|
+
return;
|
|
4457
|
+
}
|
|
4458
|
+
|
|
4459
|
+
// src/jobs/jobStore.ts
|
|
4460
|
+
import { appendFile, mkdir as mkdir7, readdir as readdir5, readFile as readFile6, rm as rm4 } from "node:fs/promises";
|
|
4461
|
+
import { join as join11 } from "node:path";
|
|
4215
4462
|
var TERMINAL_STATUSES = new Set([
|
|
4216
4463
|
"succeeded",
|
|
4217
4464
|
"failed",
|
|
@@ -4242,7 +4489,7 @@ class JobStore {
|
|
|
4242
4489
|
if (job === undefined || isTerminal(job.status))
|
|
4243
4490
|
continue;
|
|
4244
4491
|
await this.loadEvents(jobId);
|
|
4245
|
-
await rm4(
|
|
4492
|
+
await rm4(join11(this.jobDir(jobId), "incoming"), { recursive: true, force: true });
|
|
4246
4493
|
if (sendInterrupted(job.checkpoints)) {
|
|
4247
4494
|
const error = sendUnverified("serve stopped before the send was confirmed; the prompt may have been sent", { reason: "serve restarted" });
|
|
4248
4495
|
this.update(job, { status: "failed", error });
|
|
@@ -4272,7 +4519,7 @@ class JobStore {
|
|
|
4272
4519
|
this.jobs.set(job.jobId, job);
|
|
4273
4520
|
this.events.set(job.jobId, []);
|
|
4274
4521
|
this.enqueue(job.jobId, async () => {
|
|
4275
|
-
await
|
|
4522
|
+
await mkdir7(this.outputDir(job.jobId), { recursive: true, mode: 448 });
|
|
4276
4523
|
});
|
|
4277
4524
|
this.persist(job);
|
|
4278
4525
|
return job;
|
|
@@ -4289,7 +4536,7 @@ class JobStore {
|
|
|
4289
4536
|
this.events.set(jobId, list);
|
|
4290
4537
|
const event = { seq: (list.at(-1)?.seq ?? 0) + 1, at: this.now(), type, data };
|
|
4291
4538
|
list.push(event);
|
|
4292
|
-
this.enqueue(jobId, () => appendFile(
|
|
4539
|
+
this.enqueue(jobId, () => appendFile(join11(this.jobDir(jobId), "events.jsonl"), `${JSON.stringify(event)}
|
|
4293
4540
|
`, {
|
|
4294
4541
|
mode: 384
|
|
4295
4542
|
}));
|
|
@@ -4338,10 +4585,10 @@ class JobStore {
|
|
|
4338
4585
|
};
|
|
4339
4586
|
}
|
|
4340
4587
|
jobDir(jobId) {
|
|
4341
|
-
return
|
|
4588
|
+
return join11(this.paths.jobs, jobId);
|
|
4342
4589
|
}
|
|
4343
4590
|
outputDir(jobId) {
|
|
4344
|
-
return
|
|
4591
|
+
return join11(this.jobDir(jobId), "output");
|
|
4345
4592
|
}
|
|
4346
4593
|
async flush(jobId) {
|
|
4347
4594
|
const ids = jobId === undefined ? [...this.writes.keys()] : [jobId];
|
|
@@ -4363,10 +4610,10 @@ class JobStore {
|
|
|
4363
4610
|
}
|
|
4364
4611
|
persist(job) {
|
|
4365
4612
|
const snapshot = JSON.parse(JSON.stringify(job));
|
|
4366
|
-
this.enqueue(job.jobId, () => writeJsonAtomic(
|
|
4613
|
+
this.enqueue(job.jobId, () => writeJsonAtomic(join11(this.jobDir(job.jobId), "job.json"), snapshot));
|
|
4367
4614
|
}
|
|
4368
4615
|
enqueue(jobId, write) {
|
|
4369
|
-
const previous = this.writes.get(jobId) ??
|
|
4616
|
+
const previous = this.writes.get(jobId) ?? mkdir7(this.jobDir(jobId), { recursive: true, mode: 448 }).then(() => {
|
|
4370
4617
|
return;
|
|
4371
4618
|
});
|
|
4372
4619
|
const next = previous.then(write).then(() => {
|
|
@@ -4392,7 +4639,7 @@ class JobStore {
|
|
|
4392
4639
|
async load(jobId) {
|
|
4393
4640
|
if (!/^[A-Za-z0-9_-]{1,128}$/.test(jobId))
|
|
4394
4641
|
return;
|
|
4395
|
-
const raw = await readJsonFile(
|
|
4642
|
+
const raw = await readJsonFile(join11(this.jobDir(jobId), "job.json"));
|
|
4396
4643
|
if (!isRecord2(raw) || raw.jobId !== jobId || typeof raw.status !== "string")
|
|
4397
4644
|
return;
|
|
4398
4645
|
const job = raw;
|
|
@@ -4406,7 +4653,7 @@ class JobStore {
|
|
|
4406
4653
|
return cached;
|
|
4407
4654
|
let text = "";
|
|
4408
4655
|
try {
|
|
4409
|
-
text = await readFile6(
|
|
4656
|
+
text = await readFile6(join11(this.jobDir(jobId), "events.jsonl"), "utf8");
|
|
4410
4657
|
} catch (error) {
|
|
4411
4658
|
if (!isErrno(error, "ENOENT"))
|
|
4412
4659
|
throw error;
|
|
@@ -4435,6 +4682,154 @@ function summarize(job) {
|
|
|
4435
4682
|
};
|
|
4436
4683
|
}
|
|
4437
4684
|
|
|
4685
|
+
// src/jobs/pageTurns.ts
|
|
4686
|
+
var PASSIVE_OPS = new Set([
|
|
4687
|
+
"model.inspect",
|
|
4688
|
+
"turns.waitReply",
|
|
4689
|
+
"turns.read",
|
|
4690
|
+
"files.download",
|
|
4691
|
+
"project.list",
|
|
4692
|
+
"catalog.refresh"
|
|
4693
|
+
]);
|
|
4694
|
+
function takesPageTurn(op) {
|
|
4695
|
+
return !PASSIVE_OPS.has(op);
|
|
4696
|
+
}
|
|
4697
|
+
var PAGE_TURN_GRACE_MS = 60000;
|
|
4698
|
+
var CLEANUP_TURN_WAIT_MS = 60000;
|
|
4699
|
+
|
|
4700
|
+
class PageTurns {
|
|
4701
|
+
holder;
|
|
4702
|
+
depth = 0;
|
|
4703
|
+
queue = [];
|
|
4704
|
+
holderDue = 0;
|
|
4705
|
+
holderOp;
|
|
4706
|
+
overdueTimer;
|
|
4707
|
+
graceMs;
|
|
4708
|
+
cleanupWaitMs;
|
|
4709
|
+
constructor(options = {}) {
|
|
4710
|
+
this.graceMs = options.graceMs ?? PAGE_TURN_GRACE_MS;
|
|
4711
|
+
this.cleanupWaitMs = options.cleanupWaitMs ?? CLEANUP_TURN_WAIT_MS;
|
|
4712
|
+
}
|
|
4713
|
+
async take(jobId, options = {}) {
|
|
4714
|
+
const { signal } = options;
|
|
4715
|
+
if (signal?.aborted)
|
|
4716
|
+
throw failure("cancelled", "job was cancelled");
|
|
4717
|
+
if (this.holder === undefined || this.holder === jobId)
|
|
4718
|
+
this.grant(jobId);
|
|
4719
|
+
else
|
|
4720
|
+
await this.wait(jobId, signal, options.cleanup === true);
|
|
4721
|
+
let given = false;
|
|
4722
|
+
return () => {
|
|
4723
|
+
if (given)
|
|
4724
|
+
return;
|
|
4725
|
+
given = true;
|
|
4726
|
+
this.giveBack();
|
|
4727
|
+
};
|
|
4728
|
+
}
|
|
4729
|
+
opStarted(jobId, op, deadlineMs) {
|
|
4730
|
+
if (this.holder !== jobId)
|
|
4731
|
+
return;
|
|
4732
|
+
this.holderOp = op;
|
|
4733
|
+
this.due(deadlineMs + this.graceMs);
|
|
4734
|
+
}
|
|
4735
|
+
opEnded(jobId) {
|
|
4736
|
+
if (this.holder !== jobId)
|
|
4737
|
+
return;
|
|
4738
|
+
this.holderOp = undefined;
|
|
4739
|
+
this.due(this.graceMs);
|
|
4740
|
+
}
|
|
4741
|
+
current() {
|
|
4742
|
+
return this.holder;
|
|
4743
|
+
}
|
|
4744
|
+
waiting() {
|
|
4745
|
+
return this.queue.map((waiter) => waiter.jobId);
|
|
4746
|
+
}
|
|
4747
|
+
wait(jobId, signal, cleanup) {
|
|
4748
|
+
if (Date.now() >= this.holderDue)
|
|
4749
|
+
return Promise.reject(this.overdueFailure());
|
|
4750
|
+
return new Promise((resolve2, reject) => {
|
|
4751
|
+
const leave = () => {
|
|
4752
|
+
clearTimeout(cleanupTimer);
|
|
4753
|
+
signal?.removeEventListener("abort", onAbort);
|
|
4754
|
+
const index = this.queue.indexOf(waiter);
|
|
4755
|
+
if (index < 0)
|
|
4756
|
+
return false;
|
|
4757
|
+
this.queue.splice(index, 1);
|
|
4758
|
+
return true;
|
|
4759
|
+
};
|
|
4760
|
+
const waiter = {
|
|
4761
|
+
jobId,
|
|
4762
|
+
grant: () => {
|
|
4763
|
+
leave();
|
|
4764
|
+
resolve2();
|
|
4765
|
+
},
|
|
4766
|
+
fail: (error) => {
|
|
4767
|
+
if (leave())
|
|
4768
|
+
reject(error);
|
|
4769
|
+
}
|
|
4770
|
+
};
|
|
4771
|
+
const onAbort = () => waiter.fail(failure("cancelled", "job was cancelled"));
|
|
4772
|
+
const cleanupTimer = cleanup ? setTimeout(() => waiter.fail(this.overdueFailure(this.cleanupWaitMs)), this.cleanupWaitMs) : undefined;
|
|
4773
|
+
this.queue.push(waiter);
|
|
4774
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
4775
|
+
this.armOverdue();
|
|
4776
|
+
});
|
|
4777
|
+
}
|
|
4778
|
+
due(fromNowMs) {
|
|
4779
|
+
this.holderDue = Date.now() + fromNowMs;
|
|
4780
|
+
this.armOverdue();
|
|
4781
|
+
}
|
|
4782
|
+
armOverdue() {
|
|
4783
|
+
clearTimeout(this.overdueTimer);
|
|
4784
|
+
this.overdueTimer = undefined;
|
|
4785
|
+
if (this.holder === undefined || this.queue.length === 0)
|
|
4786
|
+
return;
|
|
4787
|
+
this.overdueTimer = setTimeout(() => {
|
|
4788
|
+
if (Date.now() < this.holderDue) {
|
|
4789
|
+
this.armOverdue();
|
|
4790
|
+
return;
|
|
4791
|
+
}
|
|
4792
|
+
const error = this.overdueFailure();
|
|
4793
|
+
for (const waiter of this.queue.slice())
|
|
4794
|
+
waiter.fail(error);
|
|
4795
|
+
}, Math.max(0, this.holderDue - Date.now()));
|
|
4796
|
+
}
|
|
4797
|
+
overdueFailure(cleanupWaitMs) {
|
|
4798
|
+
const holder = this.holder ?? "?";
|
|
4799
|
+
const step = this.holderOp === undefined ? "between its steps" : `in ${this.holderOp}`;
|
|
4800
|
+
const why = cleanupWaitMs === undefined ? `job ${holder} has held the ChatGPT page past the time it may take (${step})` : `job ${holder} still holds the ChatGPT page (${step}) after ${Math.round(cleanupWaitMs / 1000)} s`;
|
|
4801
|
+
return failure("busy", `${why}; nothing was sent for this step`, {
|
|
4802
|
+
activeJobId: this.holder,
|
|
4803
|
+
pageTurn: true,
|
|
4804
|
+
...this.holderOp === undefined ? {} : { holderOp: this.holderOp }
|
|
4805
|
+
});
|
|
4806
|
+
}
|
|
4807
|
+
grant(jobId) {
|
|
4808
|
+
if (this.holder !== jobId) {
|
|
4809
|
+
this.holder = jobId;
|
|
4810
|
+
this.holderOp = undefined;
|
|
4811
|
+
this.due(this.graceMs);
|
|
4812
|
+
}
|
|
4813
|
+
this.depth += 1;
|
|
4814
|
+
}
|
|
4815
|
+
giveBack() {
|
|
4816
|
+
this.depth -= 1;
|
|
4817
|
+
if (this.depth > 0)
|
|
4818
|
+
return;
|
|
4819
|
+
this.holder = undefined;
|
|
4820
|
+
this.holderOp = undefined;
|
|
4821
|
+
const next = this.queue[0];
|
|
4822
|
+
if (next === undefined) {
|
|
4823
|
+
clearTimeout(this.overdueTimer);
|
|
4824
|
+
this.overdueTimer = undefined;
|
|
4825
|
+
return;
|
|
4826
|
+
}
|
|
4827
|
+
this.grant(next.jobId);
|
|
4828
|
+
next.grant();
|
|
4829
|
+
this.armOverdue();
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4438
4833
|
// src/jobs/opsClient.ts
|
|
4439
4834
|
var DEFAULT_OP_TIMEOUT_MS = {
|
|
4440
4835
|
"conversation.open": 60000,
|
|
@@ -4445,6 +4840,7 @@ var DEFAULT_OP_TIMEOUT_MS = {
|
|
|
4445
4840
|
"composer.attach": 120000,
|
|
4446
4841
|
"composer.send": 30000,
|
|
4447
4842
|
"turns.read": 30000,
|
|
4843
|
+
"turns.approve": 30000,
|
|
4448
4844
|
"files.download": 10 * 60000,
|
|
4449
4845
|
"project.list": 20000,
|
|
4450
4846
|
"project.create": 45000,
|
|
@@ -4463,7 +4859,18 @@ function defaultOpTimeout(op, params) {
|
|
|
4463
4859
|
return DEFAULT_OP_TIMEOUT_MS[op];
|
|
4464
4860
|
}
|
|
4465
4861
|
function createOpsClient(hooks) {
|
|
4862
|
+
const { jobId, signal, slot, turns } = hooks;
|
|
4863
|
+
const inTurn = async (work, cleanup = false) => {
|
|
4864
|
+
const giveBack = await turns.take(jobId, { signal, cleanup });
|
|
4865
|
+
try {
|
|
4866
|
+
return await work();
|
|
4867
|
+
} finally {
|
|
4868
|
+
await slot.idle(jobId);
|
|
4869
|
+
giveBack();
|
|
4870
|
+
}
|
|
4871
|
+
};
|
|
4466
4872
|
return {
|
|
4873
|
+
exclusive: (work) => inTurn(work),
|
|
4467
4874
|
async call(op, params, options = {}) {
|
|
4468
4875
|
if (hooks.signal.aborted)
|
|
4469
4876
|
throw failure("cancelled", "job was cancelled");
|
|
@@ -4480,20 +4887,26 @@ function createOpsClient(hooks) {
|
|
|
4480
4887
|
if (!checked.ok) {
|
|
4481
4888
|
throw failure("bad-request", `invalid params for ${op}`, { issues: checked.issues });
|
|
4482
4889
|
}
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4890
|
+
const deadlineMs = options.timeoutMs ?? defaultOpTimeout(op, checked.value);
|
|
4891
|
+
const run5 = async () => {
|
|
4892
|
+
hooks.onStart(op);
|
|
4893
|
+
turns.opStarted(jobId, op, deadlineMs);
|
|
4894
|
+
try {
|
|
4895
|
+
const result = await slot.run({
|
|
4896
|
+
jobId,
|
|
4897
|
+
op,
|
|
4898
|
+
params: checked.value,
|
|
4899
|
+
deadlineMs,
|
|
4900
|
+
signal,
|
|
4901
|
+
onProgress: (event) => hooks.onProgress(op, event)
|
|
4902
|
+
});
|
|
4903
|
+
return result;
|
|
4904
|
+
} finally {
|
|
4905
|
+
turns.opEnded(jobId);
|
|
4906
|
+
hooks.onEnd(op);
|
|
4907
|
+
}
|
|
4908
|
+
};
|
|
4909
|
+
return takesPageTurn(op) ? inTurn(run5, op === "conversation.close") : run5();
|
|
4497
4910
|
}
|
|
4498
4911
|
};
|
|
4499
4912
|
}
|
|
@@ -4501,18 +4914,27 @@ function createOpsClient(hooks) {
|
|
|
4501
4914
|
// src/jobs/jobRunner.ts
|
|
4502
4915
|
class JobRunner {
|
|
4503
4916
|
deps;
|
|
4504
|
-
active;
|
|
4917
|
+
active = new Map;
|
|
4505
4918
|
memoryState = new Map;
|
|
4919
|
+
turns;
|
|
4920
|
+
stateUpdates = new Map;
|
|
4506
4921
|
constructor(deps) {
|
|
4507
4922
|
this.deps = deps;
|
|
4923
|
+
this.turns = new PageTurns(deps.pageTurns);
|
|
4508
4924
|
}
|
|
4509
|
-
submit(plugin, command, input) {
|
|
4510
|
-
if (this.active !== undefined) {
|
|
4511
|
-
throw failure("busy", "another job is running; it is not queued", {
|
|
4512
|
-
activeJobId: this.active.job.jobId
|
|
4513
|
-
});
|
|
4514
|
-
}
|
|
4925
|
+
submit(plugin, command, input, options = {}) {
|
|
4515
4926
|
const def = this.deps.registry.command(plugin, command);
|
|
4927
|
+
const running = [...this.active.values()].map((entry) => ({
|
|
4928
|
+
jobId: entry.job.jobId,
|
|
4929
|
+
alone: entry.alone,
|
|
4930
|
+
conflictKeys: [...entry.conflictKeys]
|
|
4931
|
+
}));
|
|
4932
|
+
const alone = plugin === CALL_PLUGIN;
|
|
4933
|
+
const conflictKey = conflictKeyOf(def, input);
|
|
4934
|
+
const capacity = jobCapacity(this.deps.extension.maxTasks, options.maxParallelJobs);
|
|
4935
|
+
const busy = admissionFailure(running, { alone, conflictKey }, capacity);
|
|
4936
|
+
if (busy !== undefined)
|
|
4937
|
+
throw busy;
|
|
4516
4938
|
if (def === undefined)
|
|
4517
4939
|
throw failure("bad-request", `unknown command ${plugin} ${command}`);
|
|
4518
4940
|
if (!this.deps.isPaired()) {
|
|
@@ -4531,31 +4953,40 @@ class JobRunner {
|
|
|
4531
4953
|
const job = this.deps.store.create(plugin, command, input);
|
|
4532
4954
|
const controller = new AbortController;
|
|
4533
4955
|
this.deps.store.appendEvent(job.jobId, "status", { status: "running" });
|
|
4956
|
+
const conflictKeys = new Set(conflictKey === undefined ? [] : [conflictKey]);
|
|
4534
4957
|
const done = this.execute(job, def, controller);
|
|
4535
|
-
this.active
|
|
4958
|
+
this.active.set(job.jobId, { job, controller, done, alone, conflictKeys });
|
|
4536
4959
|
return job;
|
|
4537
4960
|
}
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4961
|
+
activeJobs() {
|
|
4962
|
+
const holder = this.turns.current();
|
|
4963
|
+
const waiting = new Set(this.turns.waiting());
|
|
4964
|
+
return [...this.active.keys()].map((jobId) => {
|
|
4965
|
+
const op = this.deps.slot.taskOf(jobId)?.op;
|
|
4966
|
+
const pageTurn = holder === jobId ? "holding" : waiting.has(jobId) ? "waiting" : undefined;
|
|
4967
|
+
return {
|
|
4968
|
+
jobId,
|
|
4969
|
+
...op === undefined ? {} : { op },
|
|
4970
|
+
...pageTurn === undefined ? {} : { pageTurn }
|
|
4971
|
+
};
|
|
4972
|
+
});
|
|
4543
4973
|
}
|
|
4544
4974
|
async cancel(jobId) {
|
|
4545
4975
|
const job = await this.deps.store.get(jobId);
|
|
4546
4976
|
if (job === undefined)
|
|
4547
4977
|
throw failure("not-found", `no job ${jobId}`);
|
|
4548
|
-
|
|
4978
|
+
const active = this.active.get(jobId);
|
|
4979
|
+
if (active?.job !== job) {
|
|
4549
4980
|
throw failure("gone", `job ${jobId} has already ended (${job.status})`);
|
|
4550
4981
|
}
|
|
4551
4982
|
if (job.status !== "cancelling") {
|
|
4552
4983
|
this.setStatus(job, "cancelling");
|
|
4553
|
-
|
|
4984
|
+
active.controller.abort();
|
|
4554
4985
|
}
|
|
4555
4986
|
return job;
|
|
4556
4987
|
}
|
|
4557
4988
|
async settled() {
|
|
4558
|
-
await this.active
|
|
4989
|
+
await Promise.all([...this.active.values()].map((entry) => entry.done));
|
|
4559
4990
|
}
|
|
4560
4991
|
async execute(job, def, controller) {
|
|
4561
4992
|
await Promise.resolve();
|
|
@@ -4575,7 +5006,7 @@ class JobRunner {
|
|
|
4575
5006
|
}
|
|
4576
5007
|
status = statusForError(error, job.checkpoints);
|
|
4577
5008
|
}
|
|
4578
|
-
await this.deps.slot.idle();
|
|
5009
|
+
await this.deps.slot.idle(job.jobId);
|
|
4579
5010
|
this.deps.blobs.forgetJob(job.jobId);
|
|
4580
5011
|
await this.deps.incoming.forgetJob(job.jobId).catch((error2) => {
|
|
4581
5012
|
this.deps.log.warn("could not delete unsaved downloads", {
|
|
@@ -4597,7 +5028,7 @@ class JobRunner {
|
|
|
4597
5028
|
...error === undefined ? {} : { error }
|
|
4598
5029
|
});
|
|
4599
5030
|
this.deps.log.info("job finished", { jobId: job.jobId, status, code: error?.code });
|
|
4600
|
-
this.active
|
|
5031
|
+
this.active.delete(job.jobId);
|
|
4601
5032
|
}
|
|
4602
5033
|
context(job, controller) {
|
|
4603
5034
|
const { store, slot, extension, log } = this.deps;
|
|
@@ -4605,6 +5036,7 @@ class JobRunner {
|
|
|
4605
5036
|
jobId: job.jobId,
|
|
4606
5037
|
signal: controller.signal,
|
|
4607
5038
|
slot,
|
|
5039
|
+
turns: this.turns,
|
|
4608
5040
|
available: () => extension.opNames(),
|
|
4609
5041
|
policy: () => extension.policy?.state,
|
|
4610
5042
|
onStart: (op) => {
|
|
@@ -4624,10 +5056,13 @@ class JobRunner {
|
|
|
4624
5056
|
ops: ops2,
|
|
4625
5057
|
blobs: {
|
|
4626
5058
|
register: (path, options) => this.deps.blobs.register(job.jobId, path, options),
|
|
4627
|
-
save: (blob, name) => this.deps.incoming.take(job.jobId, blob,
|
|
5059
|
+
save: (blob, name) => this.deps.incoming.take(job.jobId, blob, join12(store.outputDir(job.jobId), "files"), name)
|
|
4628
5060
|
},
|
|
4629
5061
|
progress: (event) => store.appendEvent(job.jobId, "progress", event),
|
|
4630
5062
|
checkpoint: async (name, data) => {
|
|
5063
|
+
if (typeof data.conversationId === "string") {
|
|
5064
|
+
this.active.get(job.jobId)?.conflictKeys.add(conversationConflictKey(data.conversationId));
|
|
5065
|
+
}
|
|
4631
5066
|
job.checkpoints[name] = data;
|
|
4632
5067
|
store.update(job, {});
|
|
4633
5068
|
store.appendEvent(job.jobId, "checkpoint", { name, data });
|
|
@@ -4639,10 +5074,7 @@ class JobRunner {
|
|
|
4639
5074
|
});
|
|
4640
5075
|
}
|
|
4641
5076
|
},
|
|
4642
|
-
state: this.
|
|
4643
|
-
read: async () => this.memoryState.get(job.plugin),
|
|
4644
|
-
write: async (value) => void this.memoryState.set(job.plugin, value)
|
|
4645
|
-
},
|
|
5077
|
+
state: this.pluginState(job.plugin),
|
|
4646
5078
|
log: {
|
|
4647
5079
|
info: (message, fields) => {
|
|
4648
5080
|
store.appendEvent(job.jobId, "log", { level: "info", message, ...fields });
|
|
@@ -4655,6 +5087,18 @@ class JobRunner {
|
|
|
4655
5087
|
}
|
|
4656
5088
|
};
|
|
4657
5089
|
}
|
|
5090
|
+
pluginState(plugin) {
|
|
5091
|
+
const base = this.deps.pluginState?.(plugin) ?? {
|
|
5092
|
+
read: async () => this.memoryState.get(plugin),
|
|
5093
|
+
write: async (value) => void this.memoryState.set(plugin, value)
|
|
5094
|
+
};
|
|
5095
|
+
let last = this.stateUpdates.get(plugin);
|
|
5096
|
+
if (last === undefined) {
|
|
5097
|
+
last = { current: Promise.resolve() };
|
|
5098
|
+
this.stateUpdates.set(plugin, last);
|
|
5099
|
+
}
|
|
5100
|
+
return withSerialUpdates(base, last);
|
|
5101
|
+
}
|
|
4658
5102
|
async remember(job, result) {
|
|
4659
5103
|
const conversationId = result?.conversationId;
|
|
4660
5104
|
if (this.deps.rememberConversation === undefined || typeof conversationId !== "string")
|
|
@@ -4682,6 +5126,13 @@ class JobRunner {
|
|
|
4682
5126
|
this.deps.store.appendEvent(job.jobId, "status", { status });
|
|
4683
5127
|
}
|
|
4684
5128
|
}
|
|
5129
|
+
function conflictKeyOf(def, input) {
|
|
5130
|
+
try {
|
|
5131
|
+
return def?.conflictKey?.(input);
|
|
5132
|
+
} catch {
|
|
5133
|
+
return;
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
4685
5136
|
function statusForError(error, checkpoints) {
|
|
4686
5137
|
if (error.code === "cancelled")
|
|
4687
5138
|
return "cancelled";
|
|
@@ -4698,10 +5149,12 @@ function statusForError(error, checkpoints) {
|
|
|
4698
5149
|
var FINISHED_MEMORY = 64;
|
|
4699
5150
|
|
|
4700
5151
|
class TaskSlot {
|
|
4701
|
-
|
|
5152
|
+
entries = new Map;
|
|
4702
5153
|
finished = new Map;
|
|
4703
5154
|
idleWaiters = [];
|
|
4704
5155
|
listeners = new Set;
|
|
5156
|
+
polling = false;
|
|
5157
|
+
changePending = false;
|
|
4705
5158
|
offlineTimer;
|
|
4706
5159
|
now;
|
|
4707
5160
|
ackDeadlineMs;
|
|
@@ -4716,10 +5169,10 @@ class TaskSlot {
|
|
|
4716
5169
|
this.abortResendMs = options.abortResendMs ?? 2000;
|
|
4717
5170
|
}
|
|
4718
5171
|
async run(input) {
|
|
4719
|
-
await this.idle();
|
|
5172
|
+
await this.idle(input.jobId);
|
|
4720
5173
|
if (input.signal?.aborted)
|
|
4721
5174
|
throw failure("cancelled", "job was cancelled");
|
|
4722
|
-
if (this.
|
|
5175
|
+
if (this.taskOf(input.jobId) !== undefined)
|
|
4723
5176
|
return this.run(input);
|
|
4724
5177
|
return new Promise((resolve2, reject) => {
|
|
4725
5178
|
const entry = {
|
|
@@ -4742,7 +5195,7 @@ class TaskSlot {
|
|
|
4742
5195
|
reject,
|
|
4743
5196
|
...input.onProgress === undefined ? {} : { onProgress: input.onProgress }
|
|
4744
5197
|
};
|
|
4745
|
-
this.entry
|
|
5198
|
+
this.entries.set(entry.task.taskId, entry);
|
|
4746
5199
|
this.armOffline();
|
|
4747
5200
|
input.signal?.addEventListener("abort", () => this.abandon(entry, "cancelled"), {
|
|
4748
5201
|
once: true
|
|
@@ -4750,76 +5203,87 @@ class TaskSlot {
|
|
|
4750
5203
|
this.changed();
|
|
4751
5204
|
});
|
|
4752
5205
|
}
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
return entry && { taskId: entry.task.taskId, jobId: entry.task.jobId, op: entry.task.op };
|
|
5206
|
+
tasks() {
|
|
5207
|
+
return [...this.entries.values()].map(view);
|
|
4756
5208
|
}
|
|
4757
|
-
|
|
4758
|
-
|
|
5209
|
+
taskOf(jobId) {
|
|
5210
|
+
const entry = [...this.entries.values()].find((item) => item.task.jobId === jobId);
|
|
5211
|
+
return entry && view(entry);
|
|
5212
|
+
}
|
|
5213
|
+
idle(jobId) {
|
|
5214
|
+
if (this.isIdle(jobId))
|
|
4759
5215
|
return Promise.resolve();
|
|
4760
|
-
return new Promise((
|
|
5216
|
+
return new Promise((wake) => this.idleWaiters.push({ jobId, wake }));
|
|
4761
5217
|
}
|
|
4762
5218
|
onChange(listener) {
|
|
4763
5219
|
this.listeners.add(listener);
|
|
4764
5220
|
return () => this.listeners.delete(listener);
|
|
4765
5221
|
}
|
|
4766
5222
|
notePoll() {
|
|
4767
|
-
if (this.
|
|
5223
|
+
if (this.entries.size > 0)
|
|
4768
5224
|
this.armOffline();
|
|
4769
5225
|
}
|
|
4770
5226
|
poll(view) {
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
5227
|
+
this.polling = true;
|
|
5228
|
+
try {
|
|
5229
|
+
const waiting = [...this.entries.values()].filter((entry) => this.settleByPoll(entry, view));
|
|
5230
|
+
const abort = waiting.find((entry) => entry.abandoned !== undefined);
|
|
5231
|
+
if (abort !== undefined)
|
|
5232
|
+
return this.sendAbort(abort);
|
|
5233
|
+
const next = waiting.find((entry) => entry.state === "queued" || entry.state === "dispatched");
|
|
5234
|
+
return next === undefined ? undefined : this.dispatch(next);
|
|
5235
|
+
} finally {
|
|
5236
|
+
this.polling = false;
|
|
5237
|
+
if (this.changePending) {
|
|
5238
|
+
this.changePending = false;
|
|
5239
|
+
queueMicrotask(() => this.changed());
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
settleByPoll(entry, view) {
|
|
4774
5244
|
const { taskId } = entry.task;
|
|
4775
5245
|
const listed2 = view.inflight.has(taskId);
|
|
4776
5246
|
if (entry.abandoned !== undefined) {
|
|
4777
|
-
if (!entry.delivered) {
|
|
4778
|
-
this.release(entry);
|
|
4779
|
-
return;
|
|
4780
|
-
}
|
|
4781
|
-
if (entry.abortDelivered && !listed2) {
|
|
5247
|
+
if (!entry.delivered || entry.abortDelivered && !listed2) {
|
|
4782
5248
|
this.release(entry);
|
|
4783
|
-
return;
|
|
4784
|
-
}
|
|
4785
|
-
if (!entry.abortDelivered || this.now() - entry.abortSentAt >= this.abortResendMs) {
|
|
4786
|
-
entry.abortDelivered = true;
|
|
4787
|
-
entry.abortSentAt = this.now();
|
|
4788
|
-
clearTimeout(entry.resendTimer);
|
|
4789
|
-
entry.resendTimer = setTimeout(() => this.changed(), this.abortResendMs);
|
|
4790
|
-
return { kind: "abort", taskId, reason: entry.abandoned };
|
|
5249
|
+
return false;
|
|
4791
5250
|
}
|
|
4792
|
-
return;
|
|
5251
|
+
return !entry.abortDelivered || this.now() - entry.abortSentAt >= this.abortResendMs;
|
|
4793
5252
|
}
|
|
4794
5253
|
if ((entry.state === "acked" || entry.state === "running") && !listed2) {
|
|
4795
5254
|
this.settle(entry, failure("extension-reloaded", `extension lost task ${taskId} (${entry.task.op})`));
|
|
4796
5255
|
this.release(entry);
|
|
4797
|
-
return;
|
|
5256
|
+
return false;
|
|
4798
5257
|
}
|
|
4799
5258
|
if (entry.state === "dispatched" && listed2) {
|
|
4800
5259
|
entry.state = "acked";
|
|
4801
5260
|
clearTimeout(entry.ackTimer);
|
|
4802
|
-
return;
|
|
5261
|
+
return false;
|
|
4803
5262
|
}
|
|
4804
5263
|
if (entry.state === "queued") {
|
|
4805
5264
|
const refused = policyFailure(view.policy, entry.task.op);
|
|
4806
5265
|
if (refused !== undefined) {
|
|
4807
5266
|
this.settle(entry, refused);
|
|
4808
5267
|
this.release(entry);
|
|
4809
|
-
return;
|
|
5268
|
+
return false;
|
|
4810
5269
|
}
|
|
4811
5270
|
if (view.ops !== null && !view.ops.has(entry.task.op)) {
|
|
4812
5271
|
this.settle(entry, failure("unsupported-op", `the extension does not offer ${entry.task.op}`, {
|
|
4813
5272
|
available: [...view.ops]
|
|
4814
5273
|
}));
|
|
4815
5274
|
this.release(entry);
|
|
4816
|
-
return;
|
|
5275
|
+
return false;
|
|
4817
5276
|
}
|
|
4818
|
-
return
|
|
5277
|
+
return true;
|
|
4819
5278
|
}
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
5279
|
+
return entry.state === "dispatched";
|
|
5280
|
+
}
|
|
5281
|
+
sendAbort(entry) {
|
|
5282
|
+
entry.abortDelivered = true;
|
|
5283
|
+
entry.abortSentAt = this.now();
|
|
5284
|
+
clearTimeout(entry.resendTimer);
|
|
5285
|
+
entry.resendTimer = setTimeout(() => this.changed(), this.abortResendMs);
|
|
5286
|
+
return { kind: "abort", taskId: entry.task.taskId, reason: entry.abandoned ?? "cancelled" };
|
|
4823
5287
|
}
|
|
4824
5288
|
ack(taskId) {
|
|
4825
5289
|
const entry = this.match(taskId);
|
|
@@ -4878,13 +5342,8 @@ class TaskSlot {
|
|
|
4878
5342
|
this.release(entry);
|
|
4879
5343
|
return reply;
|
|
4880
5344
|
}
|
|
4881
|
-
abandonCurrent(reason) {
|
|
4882
|
-
if (this.entry !== undefined)
|
|
4883
|
-
this.abandon(this.entry, reason);
|
|
4884
|
-
}
|
|
4885
5345
|
close() {
|
|
4886
|
-
const entry
|
|
4887
|
-
if (entry !== undefined) {
|
|
5346
|
+
for (const entry of this.entries.values()) {
|
|
4888
5347
|
this.settle(entry, failure("server-unreachable", "voyager serve stopped"));
|
|
4889
5348
|
this.release(entry);
|
|
4890
5349
|
}
|
|
@@ -4898,7 +5357,7 @@ class TaskSlot {
|
|
|
4898
5357
|
entry.state = "dispatched";
|
|
4899
5358
|
clearTimeout(entry.ackTimer);
|
|
4900
5359
|
entry.ackTimer = setTimeout(() => {
|
|
4901
|
-
if (this.entry
|
|
5360
|
+
if (this.holds(entry) && entry.state === "dispatched" && entry.abandoned === undefined) {
|
|
4902
5361
|
entry.state = "queued";
|
|
4903
5362
|
this.changed();
|
|
4904
5363
|
}
|
|
@@ -4906,7 +5365,7 @@ class TaskSlot {
|
|
|
4906
5365
|
return { kind: "task", task: { ...entry.task } };
|
|
4907
5366
|
}
|
|
4908
5367
|
abandon(entry, reason) {
|
|
4909
|
-
if (this.entry
|
|
5368
|
+
if (!this.holds(entry) || entry.abandoned !== undefined)
|
|
4910
5369
|
return;
|
|
4911
5370
|
const message = reason === "timeout" ? `${entry.task.op} timed out` : "job was cancelled";
|
|
4912
5371
|
this.settle(entry, failure(reason, message));
|
|
@@ -4922,11 +5381,10 @@ class TaskSlot {
|
|
|
4922
5381
|
armOffline() {
|
|
4923
5382
|
clearTimeout(this.offlineTimer);
|
|
4924
5383
|
this.offlineTimer = setTimeout(() => {
|
|
4925
|
-
const entry
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
this.release(entry);
|
|
5384
|
+
for (const entry of this.entries.values()) {
|
|
5385
|
+
this.settle(entry, failure("extension-offline", `no poll from the extension for ${this.extensionOfflineMs / 1000}s`));
|
|
5386
|
+
this.release(entry);
|
|
5387
|
+
}
|
|
4930
5388
|
}, this.extensionOfflineMs);
|
|
4931
5389
|
}
|
|
4932
5390
|
settle(entry, error, value) {
|
|
@@ -4939,13 +5397,16 @@ class TaskSlot {
|
|
|
4939
5397
|
entry.resolve(value);
|
|
4940
5398
|
}
|
|
4941
5399
|
release(entry) {
|
|
4942
|
-
if (this.entry
|
|
5400
|
+
if (!this.holds(entry))
|
|
4943
5401
|
return;
|
|
4944
5402
|
clearTimeout(entry.ackTimer);
|
|
4945
5403
|
clearTimeout(entry.deadlineTimer);
|
|
4946
5404
|
clearTimeout(entry.resendTimer);
|
|
4947
|
-
|
|
4948
|
-
this.
|
|
5405
|
+
this.entries.delete(entry.task.taskId);
|
|
5406
|
+
if (this.entries.size === 0) {
|
|
5407
|
+
clearTimeout(this.offlineTimer);
|
|
5408
|
+
this.offlineTimer = undefined;
|
|
5409
|
+
}
|
|
4949
5410
|
this.finished.set(entry.task.taskId, entry.abandoned === undefined ? "done" : "abandoned");
|
|
4950
5411
|
while (this.finished.size > FINISHED_MEMORY) {
|
|
4951
5412
|
const oldest = this.finished.keys().next().value;
|
|
@@ -4953,38 +5414,37 @@ class TaskSlot {
|
|
|
4953
5414
|
break;
|
|
4954
5415
|
this.finished.delete(oldest);
|
|
4955
5416
|
}
|
|
4956
|
-
this.
|
|
4957
|
-
|
|
4958
|
-
wake();
|
|
5417
|
+
for (const waiter of this.idleWaiters.filter((item) => this.isIdle(item.jobId))) {
|
|
5418
|
+
this.idleWaiters.splice(this.idleWaiters.indexOf(waiter), 1);
|
|
5419
|
+
waiter.wake();
|
|
5420
|
+
}
|
|
4959
5421
|
this.changed();
|
|
4960
5422
|
}
|
|
5423
|
+
holds(entry) {
|
|
5424
|
+
return this.entries.get(entry.task.taskId) === entry;
|
|
5425
|
+
}
|
|
5426
|
+
isIdle(jobId) {
|
|
5427
|
+
if (jobId === undefined)
|
|
5428
|
+
return this.entries.size === 0;
|
|
5429
|
+
return [...this.entries.values()].every((entry) => entry.task.jobId !== jobId);
|
|
5430
|
+
}
|
|
4961
5431
|
match(taskId) {
|
|
4962
|
-
return this.
|
|
5432
|
+
return this.entries.get(taskId);
|
|
4963
5433
|
}
|
|
4964
5434
|
unknown(taskId) {
|
|
4965
5435
|
return this.finished.has(taskId) ? { kind: "gone" } : { kind: "not-found" };
|
|
4966
5436
|
}
|
|
4967
5437
|
changed() {
|
|
5438
|
+
if (this.polling) {
|
|
5439
|
+
this.changePending = true;
|
|
5440
|
+
return;
|
|
5441
|
+
}
|
|
4968
5442
|
for (const listener of this.listeners)
|
|
4969
5443
|
listener();
|
|
4970
5444
|
}
|
|
4971
5445
|
}
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
import { mkdir as mkdir7 } from "node:fs/promises";
|
|
4975
|
-
import { join as join12 } from "node:path";
|
|
4976
|
-
var PLUGIN_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
4977
|
-
function pluginStateStore(paths, plugin) {
|
|
4978
|
-
if (!PLUGIN_NAME.test(plugin))
|
|
4979
|
-
throw new Error(`not a plugin name: ${plugin}`);
|
|
4980
|
-
const file = join12(paths.pluginState, `${plugin}.json`);
|
|
4981
|
-
return {
|
|
4982
|
-
read: () => readJsonFile(file),
|
|
4983
|
-
write: async (value) => {
|
|
4984
|
-
await mkdir7(paths.pluginState, { recursive: true, mode: 448 });
|
|
4985
|
-
await writeJsonAtomic(file, value);
|
|
4986
|
-
}
|
|
4987
|
-
};
|
|
5446
|
+
function view(entry) {
|
|
5447
|
+
return { taskId: entry.task.taskId, jobId: entry.task.jobId, op: entry.task.op };
|
|
4988
5448
|
}
|
|
4989
5449
|
|
|
4990
5450
|
// src/util/log.ts
|
|
@@ -5243,6 +5703,19 @@ var JOB = "([A-Za-z0-9_-]{1,128})";
|
|
|
5243
5703
|
var MAX_EVENTS_WAIT_S = 25;
|
|
5244
5704
|
function cliRoutes(core) {
|
|
5245
5705
|
const { pairing, extension, runner, store, registry } = core;
|
|
5706
|
+
let warnedLimit;
|
|
5707
|
+
const limits = async () => {
|
|
5708
|
+
const config = await loadConfig(core.paths).catch((error) => {
|
|
5709
|
+
core.log.warn("config.json could not be read", { error: String(error) });
|
|
5710
|
+
return { maxParallelJobs: undefined, invalidMaxParallelJobs: undefined };
|
|
5711
|
+
});
|
|
5712
|
+
const invalid = config.invalidMaxParallelJobs;
|
|
5713
|
+
if (invalid !== undefined && invalid !== warnedLimit) {
|
|
5714
|
+
core.log.warn("maxParallelJobs in config.json is not a whole number of 1 or more; running one job at a time", { maxParallelJobs: invalid });
|
|
5715
|
+
}
|
|
5716
|
+
warnedLimit = invalid;
|
|
5717
|
+
return config.maxParallelJobs === undefined ? {} : { maxParallelJobs: config.maxParallelJobs };
|
|
5718
|
+
};
|
|
5246
5719
|
const requireJob = async (jobId) => {
|
|
5247
5720
|
const job = await store.get(jobId);
|
|
5248
5721
|
if (job === undefined)
|
|
@@ -5254,9 +5727,12 @@ function cliRoutes(core) {
|
|
|
5254
5727
|
method: "GET",
|
|
5255
5728
|
pattern: /^\/v1\/status$/,
|
|
5256
5729
|
access: "cli",
|
|
5257
|
-
handle: () => {
|
|
5730
|
+
handle: async () => {
|
|
5258
5731
|
const current = pairing.current;
|
|
5259
|
-
const
|
|
5732
|
+
const { maxParallelJobs } = await limits();
|
|
5733
|
+
const activeJobs = runner.activeJobs();
|
|
5734
|
+
const first = activeJobs[0];
|
|
5735
|
+
const activeJob = first === undefined ? undefined : { jobId: first.jobId, ...first.op === undefined ? {} : { op: first.op } };
|
|
5260
5736
|
const data = {
|
|
5261
5737
|
extension: {
|
|
5262
5738
|
paired: current !== null,
|
|
@@ -5264,9 +5740,11 @@ function cliRoutes(core) {
|
|
|
5264
5740
|
version: current?.extensionVersion ?? null,
|
|
5265
5741
|
browser: current?.browser ?? null,
|
|
5266
5742
|
policy: extension.policy,
|
|
5267
|
-
account: extension.account
|
|
5743
|
+
account: extension.account,
|
|
5744
|
+
maxTasks: extension.maxTasks
|
|
5268
5745
|
},
|
|
5269
|
-
...activeJob === undefined ? {} : { activeJob },
|
|
5746
|
+
...activeJob === undefined ? {} : { activeJob, activeJobs },
|
|
5747
|
+
maxJobs: jobCapacity(extension.maxTasks, maxParallelJobs),
|
|
5270
5748
|
serverVersion: CLI_VERSION
|
|
5271
5749
|
};
|
|
5272
5750
|
return { status: 200, data };
|
|
@@ -5318,14 +5796,15 @@ function cliRoutes(core) {
|
|
|
5318
5796
|
method: "POST",
|
|
5319
5797
|
pattern: /^\/v1\/jobs$/,
|
|
5320
5798
|
access: "cli",
|
|
5321
|
-
handle: ({ body }) => {
|
|
5799
|
+
handle: async ({ body }) => {
|
|
5322
5800
|
const checked = validateMessage("jobSubmitRequest", body);
|
|
5323
5801
|
if (!checked.ok)
|
|
5324
5802
|
throw failure("bad-request", "invalid job", { issues: checked.issues });
|
|
5325
5803
|
const { plugin, command, input } = checked.value;
|
|
5326
5804
|
if (plugin === CALL_PLUGIN)
|
|
5327
5805
|
throw failure("bad-request", `use ${BRIDGE_PATHS.call} for single ops`);
|
|
5328
|
-
const
|
|
5806
|
+
const { maxParallelJobs } = await limits();
|
|
5807
|
+
const job = runner.submit(plugin, command, input, maxParallelJobs === undefined ? {} : { maxParallelJobs });
|
|
5329
5808
|
const data = { jobId: job.jobId };
|
|
5330
5809
|
return { status: 202, data };
|
|
5331
5810
|
}
|
|
@@ -5433,9 +5912,9 @@ async function readBlob(core, ctx) {
|
|
|
5433
5912
|
const blob = core.blobs.get(ctx.params[0]);
|
|
5434
5913
|
if (blob === undefined)
|
|
5435
5914
|
throw failure("not-found", "no such blob");
|
|
5436
|
-
const task = core.slot.
|
|
5915
|
+
const task = core.slot.taskOf(blob.jobId);
|
|
5437
5916
|
const uploads = task?.op === "composer.attach" || task?.op === "project.upload";
|
|
5438
|
-
if (task === undefined ||
|
|
5917
|
+
if (task === undefined || !uploads) {
|
|
5439
5918
|
throw failure("gone", "no upload of this blob is running");
|
|
5440
5919
|
}
|
|
5441
5920
|
const { offset, length } = checked.value;
|
|
@@ -5446,8 +5925,8 @@ async function readBlob(core, ctx) {
|
|
|
5446
5925
|
return { status: 200, data: chunk };
|
|
5447
5926
|
}
|
|
5448
5927
|
function requireDownloadTask(core, jobId, taskId) {
|
|
5449
|
-
const task = core.slot.
|
|
5450
|
-
if (task?.op !== "files.download" || task.
|
|
5928
|
+
const task = core.slot.taskOf(jobId);
|
|
5929
|
+
if (task?.op !== "files.download" || task.taskId !== taskId) {
|
|
5451
5930
|
throw failure("gone", "no files.download of this job is running as that task");
|
|
5452
5931
|
}
|
|
5453
5932
|
}
|
|
@@ -5504,16 +5983,17 @@ async function poll(core, ctx) {
|
|
|
5504
5983
|
core.extension.ops = request.capabilities.ops;
|
|
5505
5984
|
core.extension.policy = request.policy;
|
|
5506
5985
|
core.extension.account = request.account ?? null;
|
|
5986
|
+
core.extension.maxTasks = request.maxTasks ?? null;
|
|
5507
5987
|
core.slot.notePoll();
|
|
5508
5988
|
core.heldPoll?.();
|
|
5509
5989
|
const token = bearer(ctx.req);
|
|
5510
5990
|
const stillPaired = () => core.pairing.checkToken(token, ctx.origin) === "ok";
|
|
5511
|
-
const
|
|
5991
|
+
const view2 = {
|
|
5512
5992
|
inflight: new Set(request.inflight.map((entry) => entry.taskId)),
|
|
5513
5993
|
ops: core.extension.opNames(),
|
|
5514
5994
|
policy: request.policy.state
|
|
5515
5995
|
};
|
|
5516
|
-
const immediate = core.slot.poll(
|
|
5996
|
+
const immediate = core.slot.poll(view2);
|
|
5517
5997
|
if (immediate !== undefined)
|
|
5518
5998
|
return { status: 200, data: immediate };
|
|
5519
5999
|
const held = await new Promise((resolve2) => {
|
|
@@ -5537,7 +6017,7 @@ async function poll(core, ctx) {
|
|
|
5537
6017
|
end();
|
|
5538
6018
|
return;
|
|
5539
6019
|
}
|
|
5540
|
-
const response = core.slot.poll(
|
|
6020
|
+
const response = core.slot.poll(view2);
|
|
5541
6021
|
if (response !== undefined)
|
|
5542
6022
|
finish(response);
|
|
5543
6023
|
});
|
|
@@ -5713,7 +6193,8 @@ async function startBridgeServer(options) {
|
|
|
5713
6193
|
isPaired: () => pairing.current !== null,
|
|
5714
6194
|
log,
|
|
5715
6195
|
rememberConversation: (entry) => recordLastConversation(options.paths, entry),
|
|
5716
|
-
pluginState: (plugin) => pluginStateStore(options.paths, plugin)
|
|
6196
|
+
pluginState: (plugin) => pluginStateStore(options.paths, plugin),
|
|
6197
|
+
...options.pageTurns === undefined ? {} : { pageTurns: options.pageTurns }
|
|
5717
6198
|
});
|
|
5718
6199
|
const core = {
|
|
5719
6200
|
paths: options.paths,
|
|
@@ -5904,7 +6385,7 @@ async function readLockPid(paths) {
|
|
|
5904
6385
|
|
|
5905
6386
|
// src/cli/commands/serve.ts
|
|
5906
6387
|
async function serveCommand(paths, argv) {
|
|
5907
|
-
const args =
|
|
6388
|
+
const args = parse2(argv, {
|
|
5908
6389
|
foreground: { type: "boolean", summary: "run in this terminal" },
|
|
5909
6390
|
daemon: { type: "boolean", summary: "internal: run detached" },
|
|
5910
6391
|
stop: { type: "boolean", summary: "stop the running serve" },
|
|
@@ -6291,7 +6772,7 @@ async function pairedExtensionVersion(deps) {
|
|
|
6291
6772
|
}
|
|
6292
6773
|
}
|
|
6293
6774
|
async function updateCommand(paths, argv, deps = defaultUpdateDeps(paths)) {
|
|
6294
|
-
const args =
|
|
6775
|
+
const args = parse2(argv, { json: { type: "boolean", summary: "JSON output" } });
|
|
6295
6776
|
const cli = await updateCli(deps);
|
|
6296
6777
|
const serve = await restartServe(deps, cli.serveTarget);
|
|
6297
6778
|
const page = await refreshPageData(deps);
|
|
@@ -6350,7 +6831,7 @@ usage:
|
|
|
6350
6831
|
skips one unchanged; a folder goes up as <folder>.zip
|
|
6351
6832
|
| remove <project> <file> [--yes] deletes at once, no undo; asks, or needs --yes without a tty
|
|
6352
6833
|
[--keep-tab] any project command: leave its ChatGPT tab open
|
|
6353
|
-
voyager status [--json] serve, pairing and
|
|
6834
|
+
voyager status [--json] serve, pairing, active jobs and how many may run at once
|
|
6354
6835
|
voyager commands [--json] plugin commands and extension ops
|
|
6355
6836
|
voyager call <op> [--params JSON] run one extension op (debugging); files.download saves the file
|
|
6356
6837
|
voyager job list | show <id> | wait <id> [--timeout 30m] | cancel <id>
|
|
@@ -6365,7 +6846,8 @@ each job opens its own ChatGPT tab and closes it when it ends, also after a fail
|
|
|
6365
6846
|
unless --keep-tab; one you need to look at (sign-in, an unconfirmed send) stays open
|
|
6366
6847
|
results name the ChatGPT plan the pages last showed (JSON: account; may trail a change)
|
|
6367
6848
|
exit codes: 0 ok, 2 failed (data), 3 needs a person, 4 wait timed out (job continues),
|
|
6368
|
-
5 busy
|
|
6849
|
+
5 busy (one job at a time, unless parallel jobs are on in the Voyager popup),
|
|
6850
|
+
6 transient/detached/reply-stalled, 7 not paired or extension offline
|
|
6369
6851
|
a reply saved with some files not downloaded is 0: see failedFiles (JSON) or stderr
|
|
6370
6852
|
state: ~/.voyager (override with VOYAGER_HOME)`;
|
|
6371
6853
|
async function main(argv) {
|