wildcrane-runner 0.6.121 → 0.6.123
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 +89671 -4665
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +3 -2
- package/dist/codex-proxy.mjs +2 -2
- package/dist/codex-retained.mjs +2 -2
- package/dist/flow-worker-main.mjs +29036 -28251
- package/dist/launcher.mjs +238 -57
- package/dist/plugin.mjs +302 -120
- package/dist/runner.mjs +16205 -15339
- package/dist/settings.mjs +187 -57
- package/package.json +1 -1
package/dist/launcher.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.123 — built by runner/scripts/build.mjs. Do not edit.
|
|
2
2
|
import { createRequire as __ai4kanbanRequire } from 'node:module'
|
|
3
3
|
const require = __ai4kanbanRequire(import.meta.url)
|
|
4
4
|
var __create = Object.create;
|
|
@@ -40963,6 +40963,7 @@ function withSystemProxy(env2 = process.env, platform = process.platform, read3
|
|
|
40963
40963
|
|
|
40964
40964
|
// src/proxy.ts
|
|
40965
40965
|
var LOOPBACK = "localhost,127.0.0.1,[::1]";
|
|
40966
|
+
var withLoopback = (value) => [value, LOOPBACK].filter(Boolean).join(",");
|
|
40966
40967
|
var HOST_PROXY_ENV = "WILDCRANE_HOST_PROXY";
|
|
40967
40968
|
var HOST = null;
|
|
40968
40969
|
var current = {};
|
|
@@ -40983,7 +40984,7 @@ function followProxy(read3) {
|
|
|
40983
40984
|
const route = {
|
|
40984
40985
|
httpProxy,
|
|
40985
40986
|
httpsProxy: current.HTTPS_PROXY || current.https_proxy || httpProxy,
|
|
40986
|
-
noProxy:
|
|
40987
|
+
noProxy: withLoopback(current.NO_PROXY ?? current.no_proxy)
|
|
40987
40988
|
};
|
|
40988
40989
|
const key = JSON.stringify(route);
|
|
40989
40990
|
if (key !== applied) {
|
|
@@ -41120,8 +41121,8 @@ function saveAlphaUpdates(value) {
|
|
|
41120
41121
|
}
|
|
41121
41122
|
|
|
41122
41123
|
// src/protocol.ts
|
|
41123
|
-
var VERSION = true ? "0.6.
|
|
41124
|
-
var AKB_VERSION = true ? "0.11.
|
|
41124
|
+
var VERSION = true ? "0.6.123" : "0.0.0";
|
|
41125
|
+
var AKB_VERSION = true ? "0.11.105" : "0.0.0";
|
|
41125
41126
|
var EXIT_REFUSED = 10;
|
|
41126
41127
|
var EXIT_OUTDATED = 11;
|
|
41127
41128
|
var EXIT_UPDATE = 12;
|
|
@@ -41133,26 +41134,71 @@ import fs3 from "node:fs";
|
|
|
41133
41134
|
import path3 from "node:path";
|
|
41134
41135
|
import zlib from "node:zlib";
|
|
41135
41136
|
var PACKAGE = "wildcrane-runner";
|
|
41137
|
+
var OFFICIAL_REGISTRY = "https://registry.npmjs.org";
|
|
41136
41138
|
var TIMEOUT_MS = 6e4;
|
|
41137
41139
|
var versionsDir = () => path3.join(runnerHome(), "bin", "runner");
|
|
41138
41140
|
var legacyVersionsDir = () => path3.join(runnerHome(), "runner");
|
|
41139
41141
|
var versionDir = (version) => path3.join(versionsDir(), version);
|
|
41140
41142
|
var entryOf = (dir) => path3.join(dir, "dist", "runner.mjs");
|
|
41141
41143
|
var RUNNER = { name: PACKAGE, dirOf: versionDir, entryOf };
|
|
41142
|
-
var
|
|
41144
|
+
var testRegistryOverride = null;
|
|
41145
|
+
var cachedKeys = null;
|
|
41146
|
+
function resolveRegistry() {
|
|
41147
|
+
if (testRegistryOverride) return { ok: true, url: testRegistryOverride };
|
|
41148
|
+
const configured = process.env.npm_config_registry?.trim().replace(/\/+$/, "");
|
|
41149
|
+
if (configured && configured !== OFFICIAL_REGISTRY) {
|
|
41150
|
+
return { ok: false, detail: `untrusted npm_config_registry: ${configured}` };
|
|
41151
|
+
}
|
|
41152
|
+
return { ok: true, url: OFFICIAL_REGISTRY };
|
|
41153
|
+
}
|
|
41154
|
+
async function registryKeys(registryUrl) {
|
|
41155
|
+
if (cachedKeys?.source === registryUrl) return cachedKeys.keys;
|
|
41156
|
+
const answer = await fetch(`${registryUrl}/-/npm/v1/keys`, { signal: AbortSignal.timeout(TIMEOUT_MS) });
|
|
41157
|
+
if (!answer.ok) throw new Error(`keys answered ${answer.status}`);
|
|
41158
|
+
const body = await answer.json();
|
|
41159
|
+
const keys = /* @__PURE__ */ new Map();
|
|
41160
|
+
for (const entry2 of body.keys ?? []) {
|
|
41161
|
+
if (!entry2.keyid || !entry2.key) continue;
|
|
41162
|
+
if (entry2.expires && Date.parse(entry2.expires) <= Date.now()) continue;
|
|
41163
|
+
keys.set(entry2.keyid, crypto4.createPublicKey({ key: Buffer.from(entry2.key, "base64"), format: "der", type: "spki" }));
|
|
41164
|
+
}
|
|
41165
|
+
cachedKeys = { source: registryUrl, keys };
|
|
41166
|
+
return keys;
|
|
41167
|
+
}
|
|
41168
|
+
async function verifySignature(registryUrl, pkgName, version, integrity, signatures) {
|
|
41169
|
+
if (!Array.isArray(signatures) || signatures.length === 0) return false;
|
|
41170
|
+
const keys = await registryKeys(registryUrl);
|
|
41171
|
+
const payload = Buffer.from(`${pkgName}@${version}:${integrity}`);
|
|
41172
|
+
for (const entry2 of signatures) {
|
|
41173
|
+
if (!entry2.keyid || !entry2.sig) continue;
|
|
41174
|
+
const key = keys.get(entry2.keyid);
|
|
41175
|
+
if (!key) continue;
|
|
41176
|
+
try {
|
|
41177
|
+
if (crypto4.verify("sha256", payload, key, Buffer.from(entry2.sig, "base64"))) return true;
|
|
41178
|
+
} catch {
|
|
41179
|
+
}
|
|
41180
|
+
}
|
|
41181
|
+
return false;
|
|
41182
|
+
}
|
|
41143
41183
|
var install2 = (version, nodeVersion) => installPackage(RUNNER, version, nodeVersion);
|
|
41144
41184
|
async function installPackage(pkg, version, nodeVersion = process.versions.node) {
|
|
41145
41185
|
const dir = pkg.dirOf(version);
|
|
41146
41186
|
if (fs3.existsSync(pkg.entryOf(dir))) return { ok: true, dir };
|
|
41187
|
+
const reg = resolveRegistry();
|
|
41188
|
+
if (!reg.ok) return { ok: false, why: "integrity", detail: reg.detail };
|
|
41189
|
+
const registryUrl = reg.url;
|
|
41147
41190
|
let meta;
|
|
41148
41191
|
let tarball;
|
|
41149
41192
|
try {
|
|
41150
|
-
const answer = await fetch(`${
|
|
41193
|
+
const answer = await fetch(`${registryUrl}/${pkg.name}/${encodeURIComponent(version)}`, { signal: AbortSignal.timeout(TIMEOUT_MS) });
|
|
41151
41194
|
if (!answer.ok) return { ok: false, why: "unreachable", detail: `registry answered ${answer.status}` };
|
|
41152
41195
|
meta = await answer.json();
|
|
41153
41196
|
const range = meta.engines?.node;
|
|
41154
41197
|
if (range && !satisfies(nodeVersion, range)) return { ok: false, why: "node", detail: range };
|
|
41155
41198
|
if (!meta.dist?.tarball) return { ok: false, why: "unreachable", detail: "no tarball" };
|
|
41199
|
+
if (!testRegistryOverride && !meta.dist.tarball.startsWith(`${OFFICIAL_REGISTRY}/`)) {
|
|
41200
|
+
return { ok: false, why: "integrity", detail: "tarball outside official registry" };
|
|
41201
|
+
}
|
|
41156
41202
|
const download = await fetch(meta.dist.tarball, { signal: AbortSignal.timeout(TIMEOUT_MS) });
|
|
41157
41203
|
if (!download.ok) return { ok: false, why: "unreachable", detail: `download answered ${download.status}` };
|
|
41158
41204
|
tarball = Buffer.from(await download.arrayBuffer());
|
|
@@ -41162,6 +41208,12 @@ async function installPackage(pkg, version, nodeVersion = process.versions.node)
|
|
|
41162
41208
|
const expected = /^sha512-(.+)$/.exec(meta.dist.integrity ?? "")?.[1];
|
|
41163
41209
|
const actual = crypto4.createHash("sha512").update(tarball).digest("base64");
|
|
41164
41210
|
if (!expected || expected !== actual) return { ok: false, why: "integrity", detail: "sha512 mismatch" };
|
|
41211
|
+
try {
|
|
41212
|
+
const signed = await verifySignature(registryUrl, pkg.name, version, meta.dist.integrity, meta.dist.signatures);
|
|
41213
|
+
if (!signed) return { ok: false, why: "integrity", detail: "dist.signatures verification failed" };
|
|
41214
|
+
} catch (e) {
|
|
41215
|
+
return { ok: false, why: "unreachable", detail: e instanceof Error ? e.message : String(e) };
|
|
41216
|
+
}
|
|
41165
41217
|
const staging = `${dir}.${process.pid}.tmp`;
|
|
41166
41218
|
try {
|
|
41167
41219
|
fs3.rmSync(staging, { recursive: true, force: true });
|
|
@@ -41349,7 +41401,7 @@ function rootAbove(board) {
|
|
|
41349
41401
|
var NESTED_STATE = /(^|[/\\])\.akb[/\\](?:(?:boards|hidden-boards)[/\\])?\.akb(?=[/\\]|$)/;
|
|
41350
41402
|
var InvalidBoardStatePath = class extends BoardError {
|
|
41351
41403
|
constructor(file2, state, id) {
|
|
41352
|
-
const use = state ? `Use ${state}${id ? ` or an
|
|
41404
|
+
const use = state ? `Use ${state}${id ? ` or an asset:<path> reference` : ""}.` : "Use the board\u2019s project-local state directory.";
|
|
41353
41405
|
super(`Invalid nested board state path: ${file2}. ${use}`, { kind: "board-state-path" });
|
|
41354
41406
|
}
|
|
41355
41407
|
};
|
|
@@ -41715,10 +41767,8 @@ function landSections(body, previews) {
|
|
|
41715
41767
|
const start = heading.index;
|
|
41716
41768
|
const end = start + heading[0].length;
|
|
41717
41769
|
if (!/^ {0,3}##[ \t]+Land(?:[ \t]+#+)?[ \t]*$/.test(visible.slice(start, end))) return [];
|
|
41718
|
-
|
|
41719
|
-
|
|
41720
|
-
empty: !visible.slice(end, headings[index + 1]?.index).replace(comments, "").trim()
|
|
41721
|
-
}];
|
|
41770
|
+
const text2 = visible.slice(end, headings[index + 1]?.index).replace(comments, "").trim();
|
|
41771
|
+
return [{ offset: start + heading[0].indexOf("#"), empty: !text2, text: text2 }];
|
|
41722
41772
|
});
|
|
41723
41773
|
}
|
|
41724
41774
|
function parseStudioFile(id, source, from, { requirePreviewCopy = false, requireLand = false } = {}) {
|
|
@@ -42549,7 +42599,7 @@ import path27 from "node:path";
|
|
|
42549
42599
|
// ../cli/src/lib/agent/harnesses/antigravity.ts
|
|
42550
42600
|
import fs19 from "node:fs";
|
|
42551
42601
|
import path21 from "node:path";
|
|
42552
|
-
import { createHash as
|
|
42602
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
42553
42603
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
42554
42604
|
|
|
42555
42605
|
// ../cli/src/lib/agent/locate.ts
|
|
@@ -43219,7 +43269,22 @@ ${files.map((file2) => `- ${file2}`).join("\n")}` : "";
|
|
|
43219
43269
|
import fs18 from "node:fs";
|
|
43220
43270
|
|
|
43221
43271
|
// ../cli/src/lib/agent/wire/events.ts
|
|
43272
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
43222
43273
|
var TOOL_KINDS = ["read", "edit", "delete", "move", "search", "execute", "fetch", "other"];
|
|
43274
|
+
var isPollingTool = (title) => /^(?:.*\.)?(?:command_status|wait(?:_5_seconds|_agent)?|TaskOutput)$/i.test(title);
|
|
43275
|
+
var toolOutput = (text2) => text2.split(/\r?\n/).map((line) => line.trim()).filter(
|
|
43276
|
+
(line) => line && !/^(?:\[?heartbeat\]?(?:\b|\s|$)|(?:status:\s*)?(?:(?:command|task) (?:is )?(?:still )?running|running|in[_ ]progress|pending)[.!]?$)/i.test(line)
|
|
43277
|
+
).join("\n");
|
|
43278
|
+
function progressSnapshots() {
|
|
43279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
43280
|
+
return (key, text2) => {
|
|
43281
|
+
if (!text2) return false;
|
|
43282
|
+
const digest = createHash5("sha256").update(key).update("\0").update(text2).digest("base64");
|
|
43283
|
+
if (seen.has(digest)) return false;
|
|
43284
|
+
seen.add(digest);
|
|
43285
|
+
return true;
|
|
43286
|
+
};
|
|
43287
|
+
}
|
|
43223
43288
|
var toolKind = (v) => TOOL_KINDS.includes(str2(v)) ? v : "other";
|
|
43224
43289
|
function targetOf(raw) {
|
|
43225
43290
|
const line = raw.split("\n")[0].trim();
|
|
@@ -43257,6 +43322,8 @@ function createEventCollector() {
|
|
|
43257
43322
|
let queue = [];
|
|
43258
43323
|
let said = "";
|
|
43259
43324
|
let activity = 0;
|
|
43325
|
+
const fresh = progressSnapshots();
|
|
43326
|
+
const polls = /* @__PURE__ */ new Map();
|
|
43260
43327
|
const todoCalls = /* @__PURE__ */ new Set();
|
|
43261
43328
|
const held2 = /* @__PURE__ */ new Map();
|
|
43262
43329
|
let todos = [];
|
|
@@ -43275,6 +43342,9 @@ function createEventCollector() {
|
|
|
43275
43342
|
progress: () => {
|
|
43276
43343
|
activity++;
|
|
43277
43344
|
},
|
|
43345
|
+
progressSnapshot(key, text2) {
|
|
43346
|
+
if (fresh(key, toolOutput(text2))) activity++;
|
|
43347
|
+
},
|
|
43278
43348
|
submitted() {
|
|
43279
43349
|
queue.push({ kind: "phase", data: { phase: "submitted", at: (/* @__PURE__ */ new Date()).toISOString() } });
|
|
43280
43350
|
},
|
|
@@ -43296,6 +43366,8 @@ function createEventCollector() {
|
|
|
43296
43366
|
todoCalls.add(id);
|
|
43297
43367
|
return;
|
|
43298
43368
|
}
|
|
43369
|
+
const title = str2(u.title);
|
|
43370
|
+
if (isPollingTool(title)) polls.set(id, `${title}:${str2(obj2(u.rawInput).task_id) || str2(obj2(u.rawInput).CommandId)}`);
|
|
43299
43371
|
const target = targetIn(u);
|
|
43300
43372
|
const subagent = /^(?:Task|Agent|delegate_task|spawn_agent)$/i.test(str2(u.title)) || !!obj2(u.rawInput).subagent_type;
|
|
43301
43373
|
const data = { toolCallId: id, title: str2(u.title) || "tool", kind: toolKind(u.kind), status: str2(u.status) || "pending", ...subagent ? { subagent: true } : {}, ...target ? { target } : {} };
|
|
@@ -43311,7 +43383,9 @@ function createEventCollector() {
|
|
|
43311
43383
|
return;
|
|
43312
43384
|
}
|
|
43313
43385
|
release(id, targetIn(u));
|
|
43314
|
-
const result = contentText(u.content);
|
|
43386
|
+
const result = contentText(u.content) || str2(obj2(u.rawOutput).output) || str2(u.rawOutput);
|
|
43387
|
+
const poll = polls.get(id);
|
|
43388
|
+
if (poll && fresh(poll, toolOutput(result))) activity++;
|
|
43315
43389
|
if (!u.status && !result) return;
|
|
43316
43390
|
queue.push({
|
|
43317
43391
|
kind: "tool_call_update",
|
|
@@ -43519,8 +43593,8 @@ function createTail(log) {
|
|
|
43519
43593
|
// ../cli/package.json
|
|
43520
43594
|
var package_default = {
|
|
43521
43595
|
name: "wildcrane",
|
|
43522
|
-
version: "0.11.
|
|
43523
|
-
akbContract:
|
|
43596
|
+
version: "0.11.105",
|
|
43597
|
+
akbContract: 39,
|
|
43524
43598
|
canonicalCommands: true,
|
|
43525
43599
|
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.",
|
|
43526
43600
|
keywords: [
|
|
@@ -44287,11 +44361,22 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
44287
44361
|
let out = "";
|
|
44288
44362
|
if (!calls.has(id)) {
|
|
44289
44363
|
calls.add(id);
|
|
44290
|
-
events.
|
|
44364
|
+
if (["invoke_subagent", "browser_subagent"].includes(name)) events.subagent(id, target || name);
|
|
44365
|
+
else events.toolCall(id, name, KINDS[name] ?? "other", target);
|
|
44291
44366
|
out = `
|
|
44292
44367
|
\u23FA ${name}${target ? ` ${target}` : ""}
|
|
44293
44368
|
`;
|
|
44294
44369
|
}
|
|
44370
|
+
const output2 = str2(tool.output);
|
|
44371
|
+
if (isPollingTool(name)) {
|
|
44372
|
+
const command = str2(p.CommandId) || str2(p.CommandID) || name;
|
|
44373
|
+
const commandOutput = /(?:^|\n)Command output:\s*([\s\S]*)/.exec(output2)?.[1].trim();
|
|
44374
|
+
const exit = /(?:^|\n)(Command exited with code -?\d+\.)/.exec(output2)?.[1];
|
|
44375
|
+
if (commandOutput) events.progressSnapshot(`command:${command}`, commandOutput);
|
|
44376
|
+
if (exit) events.progressSnapshot(`exit:${command}`, exit);
|
|
44377
|
+
} else if (!["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(str2(step.state))) {
|
|
44378
|
+
events.progressSnapshot(id, output2);
|
|
44379
|
+
}
|
|
44295
44380
|
const error = obj2(tool.error);
|
|
44296
44381
|
const reason = str2(error.message) || str2(error.type);
|
|
44297
44382
|
if (["DONE", "ERROR", "CANCELED", "INTERRUPTED"].includes(str2(step.state)) && !closed.has(id)) {
|
|
@@ -44309,7 +44394,7 @@ ${imageError(target, reason || str2(step.state))}
|
|
|
44309
44394
|
imageErrors.delete(file2);
|
|
44310
44395
|
}
|
|
44311
44396
|
}
|
|
44312
|
-
events.toolResult(id, failed ? "failed" : "completed",
|
|
44397
|
+
events.toolResult(id, failed ? "failed" : "completed", output2 || reason);
|
|
44313
44398
|
}
|
|
44314
44399
|
return out;
|
|
44315
44400
|
}
|
|
@@ -44423,7 +44508,7 @@ function systemPrompt(text2, _argv, env2) {
|
|
|
44423
44508
|
const rule = `${text2}
|
|
44424
44509
|
|
|
44425
44510
|
The task working directory is ${env2.PWD ?? process.cwd()}. Use it as the base for project files and commands. This additional workspace contains only language rules; do not write task output here.`;
|
|
44426
|
-
const hash =
|
|
44511
|
+
const hash = createHash6("sha256").update(rule).digest("hex").slice(0, 16);
|
|
44427
44512
|
const root2 = path21.join(machineHome(), "prompts", `antigravity-${hash}`);
|
|
44428
44513
|
const file2 = path21.join(root2, ".agents", "rules", "language.md");
|
|
44429
44514
|
fs19.mkdirSync(path21.dirname(file2), { recursive: true });
|
|
@@ -44675,6 +44760,7 @@ function createStreamRenderer() {
|
|
|
44675
44760
|
const plans = /* @__PURE__ */ new Set();
|
|
44676
44761
|
const subagents = /* @__PURE__ */ new Map();
|
|
44677
44762
|
const detached = /* @__PURE__ */ new Set();
|
|
44763
|
+
const taskUsage = /* @__PURE__ */ new Map();
|
|
44678
44764
|
const endSubagent = (id, status2) => {
|
|
44679
44765
|
if (subagents.get(id) !== false) return;
|
|
44680
44766
|
subagents.set(id, true);
|
|
@@ -44686,8 +44772,18 @@ function createStreamRenderer() {
|
|
|
44686
44772
|
if (!ev) return `${line}
|
|
44687
44773
|
`;
|
|
44688
44774
|
if (model === void 0) model = eventModel(ev);
|
|
44689
|
-
|
|
44690
|
-
|
|
44775
|
+
const parent = str2(ev.parent_tool_use_id);
|
|
44776
|
+
const content = obj2(ev.message).content;
|
|
44777
|
+
const streamEvent = obj2(ev.event);
|
|
44778
|
+
const delta = obj2(streamEvent.delta);
|
|
44779
|
+
if (ev.type === "stream_event" && streamEvent.type === "content_block_delta" && (str2(delta.text) || str2(delta.thinking) || str2(delta.partial_json))) events.progress();
|
|
44780
|
+
if (parent) {
|
|
44781
|
+
if (["assistant", "user"].includes(str2(ev.type)) && Array.isArray(content)) {
|
|
44782
|
+
const useful = content.map(obj2).filter((block) => !!str2(block.text).trim() || !!str2(block.thinking).trim() || block.type === "tool_use" || block.type === "tool_result" && !!resultText(block.content).trim());
|
|
44783
|
+
if (useful.length) events.progressSnapshot(parent, JSON.stringify(useful));
|
|
44784
|
+
}
|
|
44785
|
+
return "";
|
|
44786
|
+
}
|
|
44691
44787
|
switch (ev.type) {
|
|
44692
44788
|
case "assistant": {
|
|
44693
44789
|
apiFailure = typeof ev.error === "string" ? providerFailure({ type: ev.error }, "Claude could not complete the request.") : void 0;
|
|
@@ -44703,6 +44799,8 @@ function createStreamRenderer() {
|
|
|
44703
44799
|
|
|
44704
44800
|
`);
|
|
44705
44801
|
events.message(b.text);
|
|
44802
|
+
} else if (b?.type === "thinking" && str2(b.thinking).trim()) {
|
|
44803
|
+
events.progressSnapshot("thinking", str2(b.thinking));
|
|
44706
44804
|
} else if (b?.type === "tool_use" && typeof b.name === "string") {
|
|
44707
44805
|
out.push(`\u23FA ${b.name}${argHint(b.input, ARG_KEYS)}
|
|
44708
44806
|
`);
|
|
@@ -44722,8 +44820,8 @@ function createStreamRenderer() {
|
|
|
44722
44820
|
return out.join("");
|
|
44723
44821
|
}
|
|
44724
44822
|
case "user": {
|
|
44725
|
-
const
|
|
44726
|
-
for (const raw of Array.isArray(
|
|
44823
|
+
const content2 = obj2(ev.message).content;
|
|
44824
|
+
for (const raw of Array.isArray(content2) ? content2 : []) {
|
|
44727
44825
|
const b = obj2(raw);
|
|
44728
44826
|
if (b.type !== "tool_result" || plans.has(str2(b.tool_use_id))) continue;
|
|
44729
44827
|
if (subagents.has(str2(b.tool_use_id))) {
|
|
@@ -44767,8 +44865,20 @@ function createStreamRenderer() {
|
|
|
44767
44865
|
if (ev.subtype === "task_notification" && subagents.has(str2(ev.tool_use_id))) {
|
|
44768
44866
|
endSubagent(str2(ev.tool_use_id), str2(ev.status) === "completed" ? "completed" : "failed");
|
|
44769
44867
|
}
|
|
44770
|
-
|
|
44771
|
-
|
|
44868
|
+
const task = str2(ev.task_id);
|
|
44869
|
+
if (ev.subtype === "task_progress" && task) {
|
|
44870
|
+
const usage2 = obj2(ev.usage);
|
|
44871
|
+
const previous = taskUsage.get(task) ?? { tokens: 0, tools: 0 };
|
|
44872
|
+
const tokens = Math.max(previous.tokens, Number(usage2.total_tokens) || 0);
|
|
44873
|
+
const tools = Math.max(previous.tools, Number(usage2.tool_uses) || 0);
|
|
44874
|
+
if (tokens > previous.tokens || tools > previous.tools) {
|
|
44875
|
+
taskUsage.set(task, { tokens, tools });
|
|
44876
|
+
events.progress();
|
|
44877
|
+
}
|
|
44878
|
+
}
|
|
44879
|
+
if (ev.subtype === "task_notification" && backgrounded.delete(task)) {
|
|
44880
|
+
events.progress();
|
|
44881
|
+
if (str2(ev.summary)) return `\u23FA ${str2(ev.summary)}
|
|
44772
44882
|
`;
|
|
44773
44883
|
}
|
|
44774
44884
|
return "";
|
|
@@ -45108,23 +45218,20 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
45108
45218
|
const started = /* @__PURE__ */ new Set();
|
|
45109
45219
|
const background = createBackgroundTasks();
|
|
45110
45220
|
const subagents = /* @__PURE__ */ new Set();
|
|
45111
|
-
const
|
|
45112
|
-
const collab = (item, done) => {
|
|
45221
|
+
const collab = (item) => {
|
|
45113
45222
|
if (item.type !== "collab_tool_call") return;
|
|
45114
|
-
const key = `${str2(item.id)}:${done}`;
|
|
45115
|
-
if (collabItems.has(key)) return;
|
|
45116
|
-
collabItems.add(key);
|
|
45117
45223
|
for (const [id, raw] of Object.entries(obj2(item.agents_states))) {
|
|
45118
45224
|
const state = obj2(raw);
|
|
45119
45225
|
const status2 = str2(state.status);
|
|
45120
45226
|
if (!["pending_init", "running", "completed", "interrupted", "errored", "shutdown", "not_found"].includes(status2)) continue;
|
|
45121
45227
|
const previous = background.results().find((t2) => t2.id === id);
|
|
45122
|
-
|
|
45228
|
+
const running = status2 === "pending_init" || status2 === "running";
|
|
45229
|
+
if ((running || ["shutdown", "not_found"].includes(status2)) && previous && previous.status !== "running") continue;
|
|
45123
45230
|
if (!subagents.has(id)) {
|
|
45124
45231
|
subagents.add(id);
|
|
45125
45232
|
events.subagent(`agent:${id}`, str2(item.prompt) || "Agent");
|
|
45126
45233
|
}
|
|
45127
|
-
|
|
45234
|
+
if (running) events.progressSnapshot(`agent:${id}`, str2(state.message));
|
|
45128
45235
|
const failed = !running && status2 !== "completed";
|
|
45129
45236
|
if (background.update(id, running ? "running" : failed ? "failed" : "completed", str2(state.message)) && !running) {
|
|
45130
45237
|
events.toolResult(`agent:${id}`, failed ? "failed" : "completed", str2(state.message));
|
|
@@ -45157,15 +45264,21 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
45157
45264
|
if (!threadId) threadId = str2(ev.thread_id).trim() || void 0;
|
|
45158
45265
|
return "";
|
|
45159
45266
|
case "item.started":
|
|
45160
|
-
collab(obj2(ev.item)
|
|
45267
|
+
collab(obj2(ev.item));
|
|
45161
45268
|
itemEvents(events, started, obj2(ev.item), false);
|
|
45162
45269
|
return renderStarted(obj2(ev.item));
|
|
45163
|
-
case "item.updated":
|
|
45164
|
-
|
|
45270
|
+
case "item.updated": {
|
|
45271
|
+
const item = obj2(ev.item);
|
|
45272
|
+
collab(item);
|
|
45273
|
+
if (item.type === "todo_list") itemEvents(events, started, item, false);
|
|
45274
|
+
if (item.type === "command_execution" && started.has(str2(item.id))) {
|
|
45275
|
+
events.progressSnapshot(`command:${str2(item.id)}`, str2(item.aggregated_output));
|
|
45276
|
+
}
|
|
45165
45277
|
return "";
|
|
45278
|
+
}
|
|
45166
45279
|
case "item.completed": {
|
|
45167
45280
|
const item = obj2(ev.item);
|
|
45168
|
-
collab(item
|
|
45281
|
+
collab(item);
|
|
45169
45282
|
if (item.type === "mcp_tool_call" && !/view_image|read_image|open_image/.test(str2(item.tool))) {
|
|
45170
45283
|
const content = obj2(item.result).content;
|
|
45171
45284
|
for (const block of Array.isArray(content) ? content : []) {
|
|
@@ -45434,7 +45547,8 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
45434
45547
|
`;
|
|
45435
45548
|
switch (row.role) {
|
|
45436
45549
|
case "assistant": {
|
|
45437
|
-
|
|
45550
|
+
const thought = str2(row.reasoning_content);
|
|
45551
|
+
if (thought) events.progressSnapshot("reasoning", thought);
|
|
45438
45552
|
const said = str2(row.content).trim();
|
|
45439
45553
|
if (said) final = said;
|
|
45440
45554
|
if (said) events.message(said);
|
|
@@ -45531,7 +45645,7 @@ function modelOf2(ref) {
|
|
|
45531
45645
|
const provider = str2(model.providerId);
|
|
45532
45646
|
return provider ? `${provider}/${id}` : id;
|
|
45533
45647
|
}
|
|
45534
|
-
function createParts(tail) {
|
|
45648
|
+
function createParts(tail, activity) {
|
|
45535
45649
|
const written = /* @__PURE__ */ new Map();
|
|
45536
45650
|
const tools = /* @__PURE__ */ new Set();
|
|
45537
45651
|
const named = /* @__PURE__ */ new Map();
|
|
@@ -45540,6 +45654,7 @@ function createParts(tail) {
|
|
|
45540
45654
|
const fresh = text2.startsWith(before) ? text2.slice(before.length) : text2;
|
|
45541
45655
|
if (!fresh) return;
|
|
45542
45656
|
written.set(partId, text2);
|
|
45657
|
+
activity();
|
|
45543
45658
|
if (kind === "reasoning" || kind === "thought") tail.thought(fresh);
|
|
45544
45659
|
else tail.text(fresh);
|
|
45545
45660
|
};
|
|
@@ -45551,7 +45666,10 @@ function createParts(tail) {
|
|
|
45551
45666
|
const partId = str2(part.partId);
|
|
45552
45667
|
if (type === "text" || type === "reasoning" || type === "thought") {
|
|
45553
45668
|
if (partId) say(partId, type, str2(part.text));
|
|
45554
|
-
else
|
|
45669
|
+
else if (str2(part.text)) {
|
|
45670
|
+
activity();
|
|
45671
|
+
tail.text(str2(part.text));
|
|
45672
|
+
}
|
|
45555
45673
|
return;
|
|
45556
45674
|
}
|
|
45557
45675
|
if (type !== "tool") return;
|
|
@@ -45575,14 +45693,18 @@ function createParts(tail) {
|
|
|
45575
45693
|
const delta = str2(event2.delta);
|
|
45576
45694
|
if (!delta) return;
|
|
45577
45695
|
written.set(partId, (written.get(partId) ?? "") + delta);
|
|
45696
|
+
activity();
|
|
45578
45697
|
if (field === "reasoning") tail.thought(delta);
|
|
45579
45698
|
else tail.text(delta);
|
|
45580
45699
|
},
|
|
45581
45700
|
/** A piece of the turn, as `model.streaming` sends it. */
|
|
45582
45701
|
streaming(payload) {
|
|
45583
45702
|
const kind = str2(payload.kind);
|
|
45584
|
-
|
|
45585
|
-
if (kind === "
|
|
45703
|
+
const delta = str2(payload.delta);
|
|
45704
|
+
if (delta && (kind === "text_delta" || kind === "reasoning_delta")) {
|
|
45705
|
+
activity();
|
|
45706
|
+
return kind === "text_delta" ? tail.text(delta) : tail.thought(delta);
|
|
45707
|
+
}
|
|
45586
45708
|
if (kind !== "tool_call") return;
|
|
45587
45709
|
const callId = str2(payload.toolCallId);
|
|
45588
45710
|
const name = str2(payload.toolName) || "tool";
|
|
@@ -45622,7 +45744,7 @@ function stopped(io, why) {
|
|
|
45622
45744
|
}
|
|
45623
45745
|
async function oneTurn2(io, options) {
|
|
45624
45746
|
const tail = createTail(io.log);
|
|
45625
|
-
const parts = createParts(tail);
|
|
45747
|
+
const parts = createParts(tail, () => io.activity?.());
|
|
45626
45748
|
const activityEvents = createEventCollector();
|
|
45627
45749
|
const activeCalls = /* @__PURE__ */ new Set();
|
|
45628
45750
|
let live = false;
|
|
@@ -45649,7 +45771,6 @@ async function oneTurn2(io, options) {
|
|
|
45649
45771
|
const part = obj2(payload.part);
|
|
45650
45772
|
const state = obj2(part.state);
|
|
45651
45773
|
const type = str2(envelope.type);
|
|
45652
|
-
if (["part.delta", "model.streaming"].includes(type) && str2(payload.delta)) io.activity?.();
|
|
45653
45774
|
const id = str2(payload.toolCallId) || str2(part.callId) || str2(part.partId);
|
|
45654
45775
|
const name = str2(payload.toolName) || str2(part.tool) || str2(state.title);
|
|
45655
45776
|
if (id && name && !activeCalls.has(id)) {
|
|
@@ -45658,7 +45779,21 @@ async function oneTurn2(io, options) {
|
|
|
45658
45779
|
else activityEvents.toolCall(id, name, /^(?:bash|shell|execute|run_command|terminal)$/i.test(name) ? "execute" : "other");
|
|
45659
45780
|
}
|
|
45660
45781
|
const status2 = str2(state.status) || str2(payload.kind);
|
|
45661
|
-
|
|
45782
|
+
const output2 = str2(state.output) || str2(payload.output);
|
|
45783
|
+
if (type === "part.delta" && payload.field === "output") {
|
|
45784
|
+
const before = activityEvents.activity();
|
|
45785
|
+
activityEvents.progressSnapshot(id || str2(payload.partId), str2(payload.delta));
|
|
45786
|
+
if (activityEvents.activity() > before) io.activity?.();
|
|
45787
|
+
}
|
|
45788
|
+
if (id && ["completed", "error", "result"].includes(status2)) {
|
|
45789
|
+
activityEvents.toolResult(id, status2 === "error" ? "failed" : "completed", output2);
|
|
45790
|
+
} else if (id && output2) {
|
|
45791
|
+
activityEvents.update({
|
|
45792
|
+
sessionUpdate: "tool_call_update",
|
|
45793
|
+
toolCallId: id,
|
|
45794
|
+
content: [{ type: "content", content: { text: output2 } }]
|
|
45795
|
+
});
|
|
45796
|
+
}
|
|
45662
45797
|
for (const e of activityEvents.events()) io.event?.(e);
|
|
45663
45798
|
}
|
|
45664
45799
|
event(envelope, parts, tail, live, ended);
|
|
@@ -45727,6 +45862,7 @@ async function oneTurn2(io, options) {
|
|
|
45727
45862
|
});
|
|
45728
45863
|
const before = io.resumeId ? await tokensOf(rpc, sessionId) : ZERO_USAGE;
|
|
45729
45864
|
live = true;
|
|
45865
|
+
io.event?.({ kind: "phase", data: { phase: "submitted", at: (/* @__PURE__ */ new Date()).toISOString() } });
|
|
45730
45866
|
const accepted = await rpc.call("session/send", { sessionId, content: io.prompt });
|
|
45731
45867
|
if (accepted.accepted === false) throw new Error("the agent would not take the prompt");
|
|
45732
45868
|
const done = await finished;
|
|
@@ -45808,9 +45944,8 @@ function decide2(params, tail) {
|
|
|
45808
45944
|
|
|
45809
45945
|
// ../cli/src/lib/agent/idle.ts
|
|
45810
45946
|
var IDLE_MS = 5 * 6e4;
|
|
45811
|
-
var IDLE_ERROR = "No
|
|
45947
|
+
var IDLE_ERROR = "No verifiable progress for 5 minutes (idle timeout).";
|
|
45812
45948
|
var IDLE_FAILURE = { code: "idle_timeout", source: "runtime", summary: IDLE_ERROR };
|
|
45813
|
-
var PROVIDER_RETRY_MS = { announcement: 10 * 6e4, episode: 30 * 6e4 };
|
|
45814
45949
|
|
|
45815
45950
|
// ../cli/src/lib/agent/wire/codex.ts
|
|
45816
45951
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
@@ -46139,6 +46274,7 @@ async function run(io, options, count2) {
|
|
|
46139
46274
|
const offered = /* @__PURE__ */ new Map();
|
|
46140
46275
|
const snapshot = (w) => JSON.stringify([w.threadId, w.processId, w.status, w.exitCode, w.result]);
|
|
46141
46276
|
const childEvents = /* @__PURE__ */ new Map();
|
|
46277
|
+
const freshOutput = progressSnapshots();
|
|
46142
46278
|
const seenItems = /* @__PURE__ */ new Set();
|
|
46143
46279
|
const completedTurns = /* @__PURE__ */ new Set();
|
|
46144
46280
|
const historicalTurns = /* @__PURE__ */ new Set();
|
|
@@ -46173,6 +46309,9 @@ async function run(io, options, count2) {
|
|
|
46173
46309
|
io.stdout.off("close", closed);
|
|
46174
46310
|
io.stdin.off("error", inputFailed);
|
|
46175
46311
|
if (settlement) flushMessages(work.work().some((w) => !w.intentionalStop && !["running", "unknown"].includes(w.status) && presented.get(w.id) !== snapshot(w)));
|
|
46312
|
+
if (classified?.code === "codex_ownership_unconfirmed") {
|
|
46313
|
+
cleanup = { ...cleanup, status: "unconfirmed", detail: classified.detail ?? classified.summary };
|
|
46314
|
+
}
|
|
46176
46315
|
cleanup.items = work.work().map(({ id, threadId: threadId2, processId, status: status3, disposition }) => ({ id, threadId: threadId2, processId, status: status3, disposition }));
|
|
46177
46316
|
io.log(renderer.flush());
|
|
46178
46317
|
const usage = ownUsage(total, baseline);
|
|
@@ -46233,7 +46372,9 @@ async function run(io, options, count2) {
|
|
|
46233
46372
|
io.idleSignal?.addEventListener("abort", idle, { once: true });
|
|
46234
46373
|
const childUpdates = () => {
|
|
46235
46374
|
for (const w of work.entries.values()) {
|
|
46236
|
-
if (w.kind !== "agent"
|
|
46375
|
+
if (w.kind !== "agent") continue;
|
|
46376
|
+
if (w.status === "running" && freshOutput(w.id, toolOutput(w.result))) io.activity?.();
|
|
46377
|
+
if (childEvents.get(w.id) === w.status) continue;
|
|
46237
46378
|
if (!childEvents.has(w.id)) io.event?.({ kind: "tool_call", data: { toolCallId: w.id, title: "Agent", kind: "other", status: "in_progress", subagent: true } });
|
|
46238
46379
|
if (w.status !== "running") io.event?.({ kind: "tool_call_update", data: { toolCallId: w.id, status: w.status === "completed" ? "completed" : "failed", result: w.result } });
|
|
46239
46380
|
childEvents.set(w.id, w.status);
|
|
@@ -46471,7 +46612,26 @@ async function run(io, options, count2) {
|
|
|
46471
46612
|
armCleanup();
|
|
46472
46613
|
if (source === threadId && obj2(p.item).type !== "agentMessage") item(obj2(p.item), msg.method === "item/completed", false);
|
|
46473
46614
|
}
|
|
46474
|
-
|
|
46615
|
+
const turnId = str2(p.turnId) || str2(obj2(p.turn).id);
|
|
46616
|
+
const main = source === threadId;
|
|
46617
|
+
const live = main ? !historicalTurns.has(turnId) && (!currentTurn2 || !turnId || currentTurn2 === turnId) : work.entries.get(`agent:${source}`)?.status === "running";
|
|
46618
|
+
const delta = str2(p.delta);
|
|
46619
|
+
if (submitted && live && delta) {
|
|
46620
|
+
if (["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "")) {
|
|
46621
|
+
if (main) {
|
|
46622
|
+
if (msg.method?.startsWith("item/reasoning/")) thinking();
|
|
46623
|
+
else recovered();
|
|
46624
|
+
}
|
|
46625
|
+
io.activity?.();
|
|
46626
|
+
}
|
|
46627
|
+
const terminal = terminalKey(source, str2(p.itemId));
|
|
46628
|
+
if (msg.method === "item/commandExecution/outputDelta" && work.entries.get(terminal)?.status === "running" && freshOutput(terminal, toolOutput(delta))) io.activity?.();
|
|
46629
|
+
}
|
|
46630
|
+
if (!main) {
|
|
46631
|
+
if (live && msg.method === "item/completed") {
|
|
46632
|
+
const item2 = obj2(p.item);
|
|
46633
|
+
if (freshOutput(`${source}:${str2(item2.id)}`, toolOutput(str2(item2.text) || str2(item2.aggregatedOutput)))) io.activity?.();
|
|
46634
|
+
}
|
|
46475
46635
|
if (msg.method === "turn/completed") {
|
|
46476
46636
|
work.observeTurn(source, obj2(p.turn));
|
|
46477
46637
|
armCleanup();
|
|
@@ -46479,13 +46639,7 @@ async function run(io, options, count2) {
|
|
|
46479
46639
|
childUpdates();
|
|
46480
46640
|
return;
|
|
46481
46641
|
}
|
|
46482
|
-
|
|
46483
|
-
if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
|
|
46484
|
-
if (submitted && ["item/agentMessage/delta", "item/plan/delta", "item/reasoning/summaryTextDelta", "item/reasoning/textDelta"].includes(msg.method ?? "") && str2(p.delta)) {
|
|
46485
|
-
if (msg.method?.startsWith("item/reasoning/")) thinking();
|
|
46486
|
-
else recovered();
|
|
46487
|
-
io.activity?.();
|
|
46488
|
-
}
|
|
46642
|
+
if (!live) return;
|
|
46489
46643
|
if (msg.method === "turn/started") {
|
|
46490
46644
|
if (!submitted || completedTurns.has(turnId)) return;
|
|
46491
46645
|
currentTurn2 = turnId;
|
|
@@ -46587,7 +46741,6 @@ async function run(io, options, count2) {
|
|
|
46587
46741
|
waiting2 = true;
|
|
46588
46742
|
io.event?.({ kind: "log", data: { text: failure2.summary } });
|
|
46589
46743
|
}
|
|
46590
|
-
io.activity?.();
|
|
46591
46744
|
await delay(500, void 0, { signal: io.signal });
|
|
46592
46745
|
preparingUntil = Date.now() + CONVERSATION_MS.prepare;
|
|
46593
46746
|
}
|
|
@@ -49461,16 +49614,36 @@ var PAGE = (outcome, lang, links) => {
|
|
|
49461
49614
|
const top = links ? `<h1>${title}</h1><p>${body}</p><form id="f" novalidate><input id="e" type="email" autocomplete="email" placeholder="${c.email}" required><input id="c" inputmode="numeric" autocomplete="one-time-code" maxlength="10" placeholder="${c.code}" hidden><button id="b" class="dark">${c.send}</button><small id="m"></small><button id="x" type="button" class="link" hidden>${c.change}</button></form><div class="or">${c.or}</div><nav><a href="${links.github}">${GITHUB_ICON}${c.github}</a><a href="${links.google}">${GOOGLE_ICON}${c.google}</a></nav><script>${EMAIL_SCRIPT(c)}</script>` : `<span class="icon"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${icon2}</svg></span><h1 class="below">${title}</h1><p>${body}</p>`;
|
|
49462
49615
|
return `<!doctype html><html lang="${lang === "zh" ? "zh-CN" : "en"}"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title} \xB7 WildCrane</title><style>*{margin:0;box-sizing:border-box}body{display:flex;flex-direction:column;min-height:100dvh;background:#fff;color:#24231f;font-family:ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}header{padding:16px 36px 0}main{flex:1;display:flex;align-items:center;justify-content:center;padding:0 36px 64px;text-align:center}.icon{display:flex;margin:0 auto;width:44px;height:44px;border-radius:50%;align-items:center;justify-content:center;background:${ok ? "#e4f3ea" : "#f7ddce"};color:${ok ? "#2f6b46" : "#b83a12"}}h1{font-size:24px;font-weight:850;line-height:1.25;letter-spacing:-0.02em}h1.below{margin-top:16px}p{margin:8px auto 0;max-width:38ch;font-size:13px;line-height:19px;color:#565550}main>div.choose{width:100%;max-width:320px}nav{margin-top:28px;display:flex;flex-direction:column;gap:12px}nav a{display:flex;height:44px;align-items:center;justify-content:center;gap:8px;border-radius:10px;font-size:14.5px;font-weight:600;color:#24231f;text-decoration:none;background:#fff;border:1px solid rgba(36,35,31,0.14)}nav a.dark{background:#24231f;color:#fff;border-color:#24231f}form{margin-top:28px;display:flex;flex-direction:column;gap:12px}input{height:44px;padding:0 14px;border-radius:10px;border:1px solid rgba(36,35,31,0.14);font:inherit;font-size:14.5px}button{height:44px;border-radius:10px;border:0;font:inherit;font-size:14.5px;font-weight:600;cursor:pointer}button.dark{background:#24231f;color:#fff}button:disabled{opacity:.6}button.link{height:auto;background:none;color:#565550;font-size:13px;font-weight:500}small{font-size:13px;line-height:19px;color:#565550}small.bad{color:#b83a12}small:empty{display:none}.or{margin-top:20px;display:flex;align-items:center;gap:12px;font-size:13px;color:#8a8984}.or::before,.or::after{content:"";flex:1;height:1px;background:rgba(36,35,31,0.12)}.or+nav{margin-top:20px}</style><header><svg viewBox="2 4 56 52" width="23.7" height="22" aria-hidden="true"><path d="${CRANE}" fill="#24231f"/><path d="${CREST}" fill="#dd4f1e"/></svg></header><main><div${links ? ' class="choose"' : ""}>${top}</div></main></html>`;
|
|
49463
49616
|
};
|
|
49617
|
+
function sameToken(a, b) {
|
|
49618
|
+
if (!a || a.length !== b.length) return false;
|
|
49619
|
+
return crypto9.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
49620
|
+
}
|
|
49464
49621
|
async function signIn(options = {}) {
|
|
49465
49622
|
const generation = accountGeneration();
|
|
49466
49623
|
const verifier = base64url(crypto9.randomBytes(32));
|
|
49467
49624
|
const challenge = base64url(crypto9.createHash("sha256").update(verifier).digest());
|
|
49625
|
+
const oauthState = base64url(crypto9.randomBytes(24));
|
|
49468
49626
|
let finish = () => {
|
|
49469
49627
|
};
|
|
49470
49628
|
const answered = new Promise((resolve2) => finish = resolve2);
|
|
49471
49629
|
let answering = false;
|
|
49630
|
+
let expectedOrigin = "";
|
|
49472
49631
|
const server = http2.createServer(async (req, res) => {
|
|
49632
|
+
res.setHeader("cache-control", "no-store");
|
|
49633
|
+
res.setHeader("referrer-policy", "no-referrer");
|
|
49634
|
+
res.setHeader("x-content-type-options", "nosniff");
|
|
49635
|
+
const expectedHost = expectedOrigin.slice(7);
|
|
49636
|
+
const secFetchSite = req.headers["sec-fetch-site"] ? String(req.headers["sec-fetch-site"]) : null;
|
|
49637
|
+
if (req.headers.host !== expectedHost || req.headers.origin && req.headers.origin !== expectedOrigin) {
|
|
49638
|
+
res.writeHead(403, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: "forbidden" }));
|
|
49639
|
+
return;
|
|
49640
|
+
}
|
|
49473
49641
|
const asked = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
49642
|
+
const isCallback = asked.pathname === "/signed-in";
|
|
49643
|
+
if (secFetchSite && !(isCallback ? ["same-origin", "none", "cross-site"] : ["same-origin", "none"]).includes(secFetchSite)) {
|
|
49644
|
+
res.writeHead(403, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: "forbidden" }));
|
|
49645
|
+
return;
|
|
49646
|
+
}
|
|
49474
49647
|
const lang = langOf(req.headers["accept-language"]);
|
|
49475
49648
|
if (asked.pathname === "/" && !answering) {
|
|
49476
49649
|
res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
|
|
@@ -49478,6 +49651,10 @@ async function signIn(options = {}) {
|
|
|
49478
49651
|
return;
|
|
49479
49652
|
}
|
|
49480
49653
|
if (req.method === "POST" && (asked.pathname === "/send" || asked.pathname === "/verify") && !answering) {
|
|
49654
|
+
if (req.headers.origin !== expectedOrigin) {
|
|
49655
|
+
res.writeHead(403, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: "forbidden" }));
|
|
49656
|
+
return;
|
|
49657
|
+
}
|
|
49481
49658
|
const asks = await readJson2(req);
|
|
49482
49659
|
const answer = asked.pathname === "/send" ? await sendCode(asks.email ?? "", lang) : await verifyCode(asks.email ?? "", asks.code ?? "", generation, options.signal);
|
|
49483
49660
|
const done = answer.ok && asked.pathname === "/verify";
|
|
@@ -49497,7 +49674,8 @@ async function signIn(options = {}) {
|
|
|
49497
49674
|
const params = asked.searchParams;
|
|
49498
49675
|
const code = params.get("code");
|
|
49499
49676
|
const error = params.get("error");
|
|
49500
|
-
const
|
|
49677
|
+
const stateOk = sameToken(params.get("state"), oauthState);
|
|
49678
|
+
const failure3 = !stateOk ? { why: "other", detail: "invalid oauth state" } : code ? await exchange(code, verifier, generation, options.signal) : {
|
|
49501
49679
|
why: error === "access_denied" ? "denied" : "other",
|
|
49502
49680
|
detail: params.get("error_description") || error || "no code came back"
|
|
49503
49681
|
};
|
|
@@ -49508,6 +49686,7 @@ async function signIn(options = {}) {
|
|
|
49508
49686
|
});
|
|
49509
49687
|
await new Promise((resolve2) => server.listen(0, "127.0.0.1", resolve2));
|
|
49510
49688
|
const { port } = server.address();
|
|
49689
|
+
expectedOrigin = `http://127.0.0.1:${port}`;
|
|
49511
49690
|
const { supabaseUrl } = cloudEndpoints();
|
|
49512
49691
|
const authorize = (provider) => {
|
|
49513
49692
|
const url = new URL(`${supabaseUrl}/auth/v1/authorize`);
|
|
@@ -49516,18 +49695,20 @@ async function signIn(options = {}) {
|
|
|
49516
49695
|
if (provider === "github") url.searchParams.set("scopes", "user:email");
|
|
49517
49696
|
url.searchParams.set("code_challenge", challenge);
|
|
49518
49697
|
url.searchParams.set("code_challenge_method", "s256");
|
|
49698
|
+
url.searchParams.set("state", oauthState);
|
|
49519
49699
|
return url.toString().replace(/&/g, "&");
|
|
49520
49700
|
};
|
|
49521
49701
|
const choose = `http://127.0.0.1:${port}/`;
|
|
49522
49702
|
const onUrl = options.onUrl ?? ((u) => status(t.signIn(u)));
|
|
49523
49703
|
onUrl(choose);
|
|
49524
|
-
openBrowser2(choose);
|
|
49704
|
+
if (!options.noBrowser) openBrowser2(choose);
|
|
49525
49705
|
const timer = setTimeout(() => finish({ why: "timeout", detail: "timed out" }), WAIT_MS);
|
|
49526
49706
|
const cancel = () => finish({ why: "cancelled", detail: "cancelled" });
|
|
49527
49707
|
options.signal?.addEventListener("abort", cancel);
|
|
49528
49708
|
const failure2 = await answered;
|
|
49529
49709
|
clearTimeout(timer);
|
|
49530
49710
|
options.signal?.removeEventListener("abort", cancel);
|
|
49711
|
+
server.closeAllConnections();
|
|
49531
49712
|
server.close();
|
|
49532
49713
|
return failure2;
|
|
49533
49714
|
}
|