@phren/cli 0.3.34 → 0.3.36
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/bridge/agent-hooks.d.ts +11 -1
- package/dist/bridge/agent-hooks.js +56 -19
- package/dist/bridge/changes.js +30 -13
- package/dist/bridge/dispatch-command.js +3 -1
- package/dist/bridge/health.js +3 -1
- package/dist/bridge/host-key.d.ts +16 -0
- package/dist/bridge/host-key.js +35 -0
- package/dist/bridge/launch-brief.d.ts +2 -0
- package/dist/bridge/launch-brief.js +5 -0
- package/dist/bridge/link.js +11 -4
- package/dist/bridge/owner-inbox-sources.d.ts +5 -0
- package/dist/bridge/owner-inbox-sources.js +94 -0
- package/dist/bridge/owner-inbox-view.js +20 -1
- package/dist/bridge/owner-inbox.d.ts +7 -3
- package/dist/bridge/owner-inbox.js +113 -69
- package/dist/bridge/pair.js +3 -2
- package/dist/bridge/server.js +3 -23
- package/dist/bridge/sudo.d.ts +36 -6
- package/dist/bridge/sudo.js +180 -37
- package/dist/bridge/worker-reports.d.ts +8 -1
- package/dist/bridge/worker-reports.js +28 -7
- package/dist/bridge-hook.mjs +817 -473
- package/dist/clanker.d.ts +54 -0
- package/dist/clanker.js +188 -0
- package/dist/cli/config.js +30 -0
- package/dist/cli/hooks-output.d.ts +1 -1
- package/dist/cli/hooks-output.js +28 -21
- package/dist/cli/hooks.js +1 -1
- package/dist/cli/namespaces-skills.js +2 -2
- package/dist/cli/namespaces-tasks.js +46 -7
- package/dist/cli/session-start.js +12 -3
- package/dist/cli/session-stop.js +9 -0
- package/dist/cli/team.js +3 -0
- package/dist/cli-handlers.js +7 -0
- package/dist/cli-registry.js +1 -0
- package/dist/data/task-format.d.ts +5 -1
- package/dist/data/task-format.js +13 -5
- package/dist/index.js +82 -50
- package/dist/init/init-configure.d.ts +2 -0
- package/dist/init/init-configure.js +12 -0
- package/dist/init/init-uninstall.js +21 -2
- package/dist/init/init.d.ts +2 -0
- package/dist/init/init.js +11 -3
- package/dist/init/preferences.d.ts +6 -0
- package/dist/init/teardown.js +18 -4
- package/dist/link/doctor.js +2 -2
- package/dist/link/link.js +9 -0
- package/dist/link/refresh.d.ts +10 -0
- package/dist/link/refresh.js +34 -0
- package/dist/mcp/local-index.d.ts +20 -0
- package/dist/mcp/local-index.js +39 -1
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/index.js +88 -74
- package/dist/shared/retrieval.js +1 -1
- package/dist/skill/files.js +40 -11
- package/dist/skill/registry.d.ts +6 -0
- package/dist/skill/registry.js +21 -5
- package/dist/task/lifecycle.js +3 -1
- package/dist/tools/dispatch.js +5 -2
- package/dist/tools/finding.js +20 -11
- package/dist/tools/graph.d.ts +2 -0
- package/dist/tools/graph.js +2 -0
- package/dist/tools/search.d.ts +2 -0
- package/dist/tools/search.js +88 -6
- package/dist/tools/tasks.js +45 -0
- package/dist/tools/types.d.ts +3 -1
- package/dist/tools/types.js +3 -2
- package/package.json +1 -1
package/dist/bridge-hook.mjs
CHANGED
|
@@ -21454,13 +21454,13 @@ function chargeMergeWork(state) {
|
|
|
21454
21454
|
}
|
|
21455
21455
|
function mergeKeys(state, frame, source, sourceTag) {
|
|
21456
21456
|
chargeMergeWork(state);
|
|
21457
|
-
for (const
|
|
21457
|
+
for (const sourceKey2 of sourceTag.keys(source)) {
|
|
21458
21458
|
chargeMergeWork(state);
|
|
21459
|
-
if (frame.tag.has(frame.value,
|
|
21460
|
-
const err = frame.tag.addPair(frame.value,
|
|
21459
|
+
if (frame.tag.has(frame.value, sourceKey2)) continue;
|
|
21460
|
+
const err = frame.tag.addPair(frame.value, sourceKey2, sourceTag.get(source, sourceKey2));
|
|
21461
21461
|
if (err) throwError$1(state, err);
|
|
21462
21462
|
frame.overridable ??= /* @__PURE__ */ new Set();
|
|
21463
|
-
frame.overridable.add(
|
|
21463
|
+
frame.overridable.add(sourceKey2);
|
|
21464
21464
|
}
|
|
21465
21465
|
}
|
|
21466
21466
|
function mergeSource(state, frame, source, sourceTag) {
|
|
@@ -24040,8 +24040,8 @@ function accountLabel(id2, labels = readLabels()) {
|
|
|
24040
24040
|
}
|
|
24041
24041
|
async function setAccountLabel(id2, label2) {
|
|
24042
24042
|
if (!isAccountSlug(id2)) throw new Error(`"${id2}" is not an account name: use lowercase letters, digits and dashes.`);
|
|
24043
|
-
const
|
|
24044
|
-
if (!
|
|
24043
|
+
const clean3 = label2.trim();
|
|
24044
|
+
if (!clean3 || clean3.length > 40 || /[\u0000-\u001f]/.test(clean3)) throw new Error("A label is 1 to 40 printable characters.");
|
|
24045
24045
|
let parsed = {};
|
|
24046
24046
|
try {
|
|
24047
24047
|
const raw = load(await readFile2(accountsFile(), "utf8"));
|
|
@@ -24049,7 +24049,7 @@ async function setAccountLabel(id2, label2) {
|
|
|
24049
24049
|
} catch {
|
|
24050
24050
|
}
|
|
24051
24051
|
const claude2 = parsed.claude && typeof parsed.claude === "object" ? parsed.claude : {};
|
|
24052
|
-
parsed.claude = { ...claude2, [id2]:
|
|
24052
|
+
parsed.claude = { ...claude2, [id2]: clean3 };
|
|
24053
24053
|
await mkdir2(bridgeRoot(), { recursive: true, mode: 448 });
|
|
24054
24054
|
await atomic(accountsFile(), dump(parsed), 384);
|
|
24055
24055
|
}
|
|
@@ -26543,12 +26543,13 @@ function namedPaths(command, input2 = {}) {
|
|
|
26543
26543
|
return [...found].slice(0, 48);
|
|
26544
26544
|
}
|
|
26545
26545
|
async function git2(cwd, args, extra = {}, signal) {
|
|
26546
|
-
|
|
26546
|
+
countGit("changes");
|
|
26547
|
+
return (await exec2("git", ["-C", cwd, "--no-pager", ...args], {
|
|
26547
26548
|
signal,
|
|
26548
26549
|
timeout: 1e4,
|
|
26549
26550
|
maxBuffer: 8388608,
|
|
26550
26551
|
env: { ...checkoutGitEnv(), ...extra }
|
|
26551
|
-
})).stdout
|
|
26552
|
+
})).stdout;
|
|
26552
26553
|
}
|
|
26553
26554
|
async function repositoryOf(target, cwd, home = homeDir(), signal) {
|
|
26554
26555
|
const absolute = target === "~" || target.startsWith("~/") ? path18.join(home, target.slice(1)) : path18.resolve(cwd, target);
|
|
@@ -26587,10 +26588,16 @@ async function treeHash(root, env, signal) {
|
|
|
26587
26588
|
const index2 = path18.resolve(root, (await git2(root, ["rev-parse", "--git-path", "index"], {}, signal)).trim());
|
|
26588
26589
|
const temp = env.GIT_INDEX_FILE;
|
|
26589
26590
|
await unlink2(temp).catch(() => void 0);
|
|
26590
|
-
await
|
|
26591
|
+
const real2 = await stat5(index2).catch((error62) => {
|
|
26591
26592
|
if (error62.code !== "ENOENT") throw error62;
|
|
26593
|
+
return void 0;
|
|
26592
26594
|
});
|
|
26593
|
-
await
|
|
26595
|
+
if (real2 && await copyFile(index2, temp).then(() => true, (error62) => {
|
|
26596
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
26597
|
+
return false;
|
|
26598
|
+
})) {
|
|
26599
|
+
await utimes(temp, real2.atimeMs / 1e3, real2.mtimeMs / 1e3 - 1);
|
|
26600
|
+
}
|
|
26594
26601
|
await git2(root, ["add", "-A", "--", "."], env, signal);
|
|
26595
26602
|
return (await git2(root, ["write-tree"], env, signal)).trim();
|
|
26596
26603
|
}
|
|
@@ -26675,7 +26682,7 @@ function outputCallIds(raw, source) {
|
|
|
26675
26682
|
if (!Array.isArray(content)) return [];
|
|
26676
26683
|
return content.flatMap((block) => block && typeof block === "object" && block.type === "tool_result" ? ids(block.tool_use_id) : []);
|
|
26677
26684
|
}
|
|
26678
|
-
var exec2, changedFileSchema, changeRowSchema, secretName,
|
|
26685
|
+
var exec2, changedFileSchema, changeRowSchema, secretName, capturePool, SHELL_TOOLS, NAMED, FILE_TOOLS, NO_DIFF, CLAIM_RETENTION, PENDING_FOR, BUDGET, DAY, ToolChanges;
|
|
26679
26686
|
var init_changes = __esm({
|
|
26680
26687
|
"src/bridge/changes.ts"() {
|
|
26681
26688
|
"use strict";
|
|
@@ -26700,7 +26707,7 @@ var init_changes = __esm({
|
|
|
26700
26707
|
});
|
|
26701
26708
|
changeRowSchema = external_exports.object({ toolUseId: external_exports.string(), files: external_exports.array(changedFileSchema) });
|
|
26702
26709
|
secretName = (file4) => /^(?:\.env(?:\..*)?|.*\.(?:pem|key|p12|pfx|keychain-db|tfstate)|id_rsa.*|id_ed25519.*|(?:.*\.)?credentials\.json|\.netrc|\.npmrc|\.pypirc)$/i.test(path18.basename(file4));
|
|
26703
|
-
|
|
26710
|
+
capturePool = new ProcessPool(2);
|
|
26704
26711
|
SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash", "bash", "shell", "Shell", "exec_command", "shell_command", "local_shell", "write_stdin"]);
|
|
26705
26712
|
NAMED = /(?<![\w@:/])(?:~\/|\.\/|\/)[\w.@+~-]+(?:\/[\w.@+~-]+)*/g;
|
|
26706
26713
|
FILE_TOOLS = /* @__PURE__ */ new Set(["write", "edit", "multiedit", "notebookedit", "apply_patch", "str_replace_editor", "create_file", "replace_string_in_file", "multi_replace_string_in_file"]);
|
|
@@ -26767,7 +26774,7 @@ var init_changes = __esm({
|
|
|
26767
26774
|
const snapshot2 = { at: Date.now(), conversation, own: new Set(claimed), trees: /* @__PURE__ */ new Map(), taking: true };
|
|
26768
26775
|
this.snapshots.set(key4, snapshot2);
|
|
26769
26776
|
try {
|
|
26770
|
-
await this.budget(async (
|
|
26777
|
+
await this.budget((signal) => capturePool.run(signal, async () => {
|
|
26771
26778
|
await realpath2(cwd);
|
|
26772
26779
|
const roots = /* @__PURE__ */ new Set();
|
|
26773
26780
|
for (const target of [cwd, phrenStoreRoot(), ...namedPaths(command, input2)]) {
|
|
@@ -26780,7 +26787,7 @@ var init_changes = __esm({
|
|
|
26780
26787
|
snapshot2.trees.set(root, await scratchTree(root, signal));
|
|
26781
26788
|
}
|
|
26782
26789
|
signal.throwIfAborted();
|
|
26783
|
-
});
|
|
26790
|
+
}));
|
|
26784
26791
|
snapshot2.taking = false;
|
|
26785
26792
|
if (snapshot2.dropped) {
|
|
26786
26793
|
await this.discard(snapshot2);
|
|
@@ -26848,10 +26855,13 @@ var init_changes = __esm({
|
|
|
26848
26855
|
async compute(snapshot2) {
|
|
26849
26856
|
try {
|
|
26850
26857
|
return await this.budget(async (signal) => {
|
|
26851
|
-
const files =
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26858
|
+
const files = await capturePool.run(signal, async () => {
|
|
26859
|
+
const found = [];
|
|
26860
|
+
for (const [root, before] of snapshot2.trees) {
|
|
26861
|
+
found.push(...await treeDiff(root, before.hash, await treeHash(root, before.env, signal), before.env, signal));
|
|
26862
|
+
}
|
|
26863
|
+
return found;
|
|
26864
|
+
});
|
|
26855
26865
|
const until = Date.now();
|
|
26856
26866
|
const kept = [];
|
|
26857
26867
|
for (const file4 of files) {
|
|
@@ -28440,14 +28450,14 @@ function unescapeJs(value2) {
|
|
|
28440
28450
|
});
|
|
28441
28451
|
}
|
|
28442
28452
|
function literalValue(expression) {
|
|
28443
|
-
const text5 = expression.trim(),
|
|
28444
|
-
if (!["'", '"', "`"].includes(
|
|
28453
|
+
const text5 = expression.trim(), quote6 = text5[0];
|
|
28454
|
+
if (!["'", '"', "`"].includes(quote6) || text5.length < 2 || text5[text5.length - 1] !== quote6) return void 0;
|
|
28445
28455
|
for (let index2 = 1; index2 < text5.length - 1; index2++) {
|
|
28446
28456
|
if (text5[index2] === "\\") {
|
|
28447
28457
|
index2++;
|
|
28448
28458
|
continue;
|
|
28449
28459
|
}
|
|
28450
|
-
if (text5[index2] ===
|
|
28460
|
+
if (text5[index2] === quote6) return void 0;
|
|
28451
28461
|
}
|
|
28452
28462
|
return unescapeJs(text5.slice(1, -1));
|
|
28453
28463
|
}
|
|
@@ -28460,16 +28470,16 @@ function resolveString(expression, source) {
|
|
|
28460
28470
|
return declaration ? unescapeJs(declaration[1].slice(1, -1)) : void 0;
|
|
28461
28471
|
}
|
|
28462
28472
|
function callArguments(source, open28) {
|
|
28463
|
-
let depth = 0,
|
|
28473
|
+
let depth = 0, quote6 = "";
|
|
28464
28474
|
for (let index2 = open28; index2 < source.length; index2++) {
|
|
28465
28475
|
const character = source[index2];
|
|
28466
|
-
if (
|
|
28476
|
+
if (quote6) {
|
|
28467
28477
|
if (character === "\\") index2++;
|
|
28468
|
-
else if (character ===
|
|
28478
|
+
else if (character === quote6) quote6 = "";
|
|
28469
28479
|
continue;
|
|
28470
28480
|
}
|
|
28471
28481
|
if (character === '"' || character === "'" || character === "`") {
|
|
28472
|
-
|
|
28482
|
+
quote6 = character;
|
|
28473
28483
|
continue;
|
|
28474
28484
|
}
|
|
28475
28485
|
if (character === "(" || character === "{" || character === "[") depth++;
|
|
@@ -31890,7 +31900,7 @@ var require_websocket = __commonJS({
|
|
|
31890
31900
|
var http = __require("http");
|
|
31891
31901
|
var net2 = __require("net");
|
|
31892
31902
|
var tls = __require("tls");
|
|
31893
|
-
var { randomBytes:
|
|
31903
|
+
var { randomBytes: randomBytes9, createHash: createHash29 } = __require("crypto");
|
|
31894
31904
|
var { Duplex: Duplex2, Readable: Readable2 } = __require("stream");
|
|
31895
31905
|
var { URL: URL2 } = __require("url");
|
|
31896
31906
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -32441,7 +32451,7 @@ var require_websocket = __commonJS({
|
|
|
32441
32451
|
}
|
|
32442
32452
|
}
|
|
32443
32453
|
const defaultPort = isSecure ? 443 : 80;
|
|
32444
|
-
const key4 =
|
|
32454
|
+
const key4 = randomBytes9(16).toString("base64");
|
|
32445
32455
|
const request9 = isSecure ? https.request : http.request;
|
|
32446
32456
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
32447
32457
|
let perMessageDeflate;
|
|
@@ -32571,7 +32581,7 @@ var require_websocket = __commonJS({
|
|
|
32571
32581
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
32572
32582
|
return;
|
|
32573
32583
|
}
|
|
32574
|
-
const digest2 =
|
|
32584
|
+
const digest2 = createHash29("sha1").update(key4 + GUID).digest("base64");
|
|
32575
32585
|
if (res.headers["sec-websocket-accept"] !== digest2) {
|
|
32576
32586
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
32577
32587
|
return;
|
|
@@ -32940,7 +32950,7 @@ var require_websocket_server = __commonJS({
|
|
|
32940
32950
|
var EventEmitter2 = __require("events");
|
|
32941
32951
|
var http = __require("http");
|
|
32942
32952
|
var { Duplex: Duplex2 } = __require("stream");
|
|
32943
|
-
var { createHash:
|
|
32953
|
+
var { createHash: createHash29 } = __require("crypto");
|
|
32944
32954
|
var extension2 = require_extension();
|
|
32945
32955
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
32946
32956
|
var subprotocol2 = require_subprotocol();
|
|
@@ -33247,7 +33257,7 @@ var require_websocket_server = __commonJS({
|
|
|
33247
33257
|
);
|
|
33248
33258
|
}
|
|
33249
33259
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
33250
|
-
const digest2 =
|
|
33260
|
+
const digest2 = createHash29("sha1").update(key4 + GUID).digest("base64");
|
|
33251
33261
|
const headers = [
|
|
33252
33262
|
"HTTP/1.1 101 Switching Protocols",
|
|
33253
33263
|
"Upgrade: websocket",
|
|
@@ -36334,7 +36344,12 @@ __export(sudo_exports, {
|
|
|
36334
36344
|
askpassPath: () => askpassPath,
|
|
36335
36345
|
askpassScript: () => askpassScript,
|
|
36336
36346
|
connectionHolders: () => connectionHolders,
|
|
36347
|
+
deliverToListener: () => deliverToListener,
|
|
36348
|
+
deliveryFrom: () => deliveryFrom,
|
|
36337
36349
|
installAskpass: () => installAskpass,
|
|
36350
|
+
listenerHolders: () => listenerHolders,
|
|
36351
|
+
listeningInode: () => listeningInode,
|
|
36352
|
+
newDelivery: () => newDelivery,
|
|
36338
36353
|
processStart: () => processStart,
|
|
36339
36354
|
readProcess: () => readProcess,
|
|
36340
36355
|
removeAskpass: () => removeAskpass,
|
|
@@ -36345,11 +36360,12 @@ __export(sudo_exports, {
|
|
|
36345
36360
|
verifyAsker: () => verifyAsker
|
|
36346
36361
|
});
|
|
36347
36362
|
import { execFile as execFile7 } from "node:child_process";
|
|
36348
|
-
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
36363
|
+
import { randomBytes as randomBytes3, randomUUID as randomUUID6, timingSafeEqual } from "node:crypto";
|
|
36349
36364
|
import { EventEmitter } from "node:events";
|
|
36350
36365
|
import { existsSync as existsSync10, readlinkSync } from "node:fs";
|
|
36351
36366
|
import { open as open10, readdir as readdir10, readFile as readFile16, readlink as readlink2, unlink as unlink3 } from "node:fs/promises";
|
|
36352
36367
|
import { request as request2 } from "node:http";
|
|
36368
|
+
import { createConnection, createServer } from "node:net";
|
|
36353
36369
|
import path32 from "node:path";
|
|
36354
36370
|
import { promisify as promisify6 } from "node:util";
|
|
36355
36371
|
import { userInfo as userInfo3 } from "node:os";
|
|
@@ -36437,29 +36453,32 @@ async function readProcess(pid) {
|
|
|
36437
36453
|
return void 0;
|
|
36438
36454
|
}
|
|
36439
36455
|
}
|
|
36456
|
+
async function heldElsewhere(target, exclude) {
|
|
36457
|
+
const holders = (await readdir10("/proc")).map(Number).filter((holder) => Number.isInteger(holder) && !exclude.includes(holder));
|
|
36458
|
+
let next = 0, other = false;
|
|
36459
|
+
await Promise.all(Array.from({ length: Math.min(16, holders.length) }, async () => {
|
|
36460
|
+
while (!other && next < holders.length) {
|
|
36461
|
+
const holder = holders[next++];
|
|
36462
|
+
const fds = await readdir10(`/proc/${holder}/fd`).catch(() => []);
|
|
36463
|
+
for (const fd of fds) {
|
|
36464
|
+
try {
|
|
36465
|
+
if (readlinkSync(`/proc/${holder}/fd/${fd}`) === target) {
|
|
36466
|
+
other = true;
|
|
36467
|
+
break;
|
|
36468
|
+
}
|
|
36469
|
+
} catch {
|
|
36470
|
+
}
|
|
36471
|
+
}
|
|
36472
|
+
}
|
|
36473
|
+
}));
|
|
36474
|
+
return other;
|
|
36475
|
+
}
|
|
36440
36476
|
async function stdoutReaders(pid, allowed) {
|
|
36441
36477
|
try {
|
|
36442
36478
|
if (process.platform === "linux") {
|
|
36443
36479
|
const target = await readlink2(`/proc/${pid}/fd/1`);
|
|
36444
36480
|
if (!/^pipe:\[\d+\]$/.test(target)) return "other";
|
|
36445
|
-
|
|
36446
|
-
let next = 0, other = false;
|
|
36447
|
-
await Promise.all(Array.from({ length: Math.min(16, holders.length) }, async () => {
|
|
36448
|
-
while (!other && next < holders.length) {
|
|
36449
|
-
const holder2 = holders[next++];
|
|
36450
|
-
const fds = await readdir10(`/proc/${holder2}/fd`).catch(() => []);
|
|
36451
|
-
for (const fd of fds) {
|
|
36452
|
-
try {
|
|
36453
|
-
if (readlinkSync(`/proc/${holder2}/fd/${fd}`) === target) {
|
|
36454
|
-
other = true;
|
|
36455
|
-
break;
|
|
36456
|
-
}
|
|
36457
|
-
} catch {
|
|
36458
|
-
}
|
|
36459
|
-
}
|
|
36460
|
-
}
|
|
36461
|
-
}));
|
|
36462
|
-
return other ? "other" : "sudo";
|
|
36481
|
+
return await heldElsewhere(target, [pid, ...allowed]) ? "other" : "sudo";
|
|
36463
36482
|
}
|
|
36464
36483
|
const own2 = await exec6("lsof", ["-nP", "-a", "-p", String(pid), "-d", "1", "-F", "tdn"], { timeout: 5e3, maxBuffer: 65536 });
|
|
36465
36484
|
const type = /^t(.+)$/m.exec(own2.stdout)?.[1], peer = /^n->(0x[0-9a-f]+)$/m.exec(own2.stdout)?.[1];
|
|
@@ -36497,6 +36516,67 @@ async function processStart(pid) {
|
|
|
36497
36516
|
const stat30 = await readFile16(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
|
|
36498
36517
|
return stat30?.slice(stat30.lastIndexOf(")") + 2).split(" ")[19];
|
|
36499
36518
|
}
|
|
36519
|
+
function deliveryFrom(value2) {
|
|
36520
|
+
const item = object2(value2);
|
|
36521
|
+
return typeof item.socket === "string" && DELIVERY_SOCKET.test(item.socket) && typeof item.nonce === "string" && DELIVERY_NONCE.test(item.nonce) ? { socket: item.socket, nonce: item.nonce } : void 0;
|
|
36522
|
+
}
|
|
36523
|
+
function newDelivery() {
|
|
36524
|
+
return { socket: `phren-askpass-${randomBytes3(16).toString("hex")}`, nonce: randomBytes3(32).toString("hex") };
|
|
36525
|
+
}
|
|
36526
|
+
async function listeningInode(name, table2 = () => readFile16("/proc/net/unix", "utf8")) {
|
|
36527
|
+
const text5 = await table2().catch(() => "");
|
|
36528
|
+
const found = text5.split("\n").slice(1).map((row) => row.trim().split(/\s+/)).filter((cols) => cols.length >= 8 && cols[7] === `@${name}` && (Number.parseInt(cols[3], 16) & 65536) !== 0 && /^\d+$/.test(cols[6]));
|
|
36529
|
+
return found.length === 1 ? found[0][6] : void 0;
|
|
36530
|
+
}
|
|
36531
|
+
async function listenerHolders(pid, inode) {
|
|
36532
|
+
try {
|
|
36533
|
+
const target = `socket:[${inode}]`;
|
|
36534
|
+
const own2 = await readdir10(`/proc/${pid}/fd`);
|
|
36535
|
+
if (!own2.some((fd) => {
|
|
36536
|
+
try {
|
|
36537
|
+
return readlinkSync(`/proc/${pid}/fd/${fd}`) === target;
|
|
36538
|
+
} catch {
|
|
36539
|
+
return false;
|
|
36540
|
+
}
|
|
36541
|
+
})) return "other";
|
|
36542
|
+
return await heldElsewhere(target, [pid]) ? "other" : "asker";
|
|
36543
|
+
} catch {
|
|
36544
|
+
return "unknown";
|
|
36545
|
+
}
|
|
36546
|
+
}
|
|
36547
|
+
async function deliverToListener(pid, start, delivery, inode, password, checks = {}) {
|
|
36548
|
+
const gone = { status: 410, error: "askpass went away." };
|
|
36549
|
+
const socket = (checks.connect ?? ((target) => createConnection({ path: target })))(`\0${delivery.socket}`);
|
|
36550
|
+
try {
|
|
36551
|
+
await new Promise((resolve14, reject) => {
|
|
36552
|
+
socket.once("connect", resolve14);
|
|
36553
|
+
socket.once("error", reject);
|
|
36554
|
+
setTimeout(() => reject(new Error("connect timeout")), 3e3).unref();
|
|
36555
|
+
});
|
|
36556
|
+
if (await (checks.start ?? processStart)(pid) !== start) return gone;
|
|
36557
|
+
if (await (checks.inode ?? listeningInode)(delivery.socket) !== inode) return gone;
|
|
36558
|
+
if (await (checks.holders ?? listenerHolders)(pid, inode) !== "asker") return gone;
|
|
36559
|
+
const ack = new Promise((resolve14) => {
|
|
36560
|
+
let text5 = "";
|
|
36561
|
+
socket.on("data", (chunk) => {
|
|
36562
|
+
text5 += chunk.toString();
|
|
36563
|
+
if (text5.includes("\n")) resolve14(text5.startsWith("ok\n"));
|
|
36564
|
+
if (text5.length > 64) resolve14(false);
|
|
36565
|
+
});
|
|
36566
|
+
socket.once("close", () => resolve14(false));
|
|
36567
|
+
socket.once("error", () => resolve14(false));
|
|
36568
|
+
setTimeout(() => resolve14(false), 5e3).unref();
|
|
36569
|
+
});
|
|
36570
|
+
socket.write(`${delivery.nonce}
|
|
36571
|
+
${password}
|
|
36572
|
+
`);
|
|
36573
|
+
return await ack ? { delivered: true } : gone;
|
|
36574
|
+
} catch {
|
|
36575
|
+
return gone;
|
|
36576
|
+
} finally {
|
|
36577
|
+
socket.destroy();
|
|
36578
|
+
}
|
|
36579
|
+
}
|
|
36500
36580
|
async function writeToAsker(pid, start, password) {
|
|
36501
36581
|
if (await processStart(pid) !== start) return { status: 410, error: "askpass went away." };
|
|
36502
36582
|
try {
|
|
@@ -36536,23 +36616,25 @@ function placeFrom(value2) {
|
|
|
36536
36616
|
if (!fields2.every((key4) => typeof item[key4] === "string" && placeName.test(item[key4]))) return void 0;
|
|
36537
36617
|
return Object.fromEntries(fields2.map((key4) => [key4, item[key4]]));
|
|
36538
36618
|
}
|
|
36539
|
-
async function defaultVerify(pid, hookFd) {
|
|
36619
|
+
async function defaultVerify(pid, hookFd, delivery) {
|
|
36540
36620
|
const linux = process.platform === "linux";
|
|
36541
36621
|
const running2 = process.argv[1] ? [path32.resolve(process.argv[1])] : [];
|
|
36542
36622
|
const start = linux ? await processStart(pid) : void 0;
|
|
36623
|
+
const inode = linux && delivery ? await listeningInode(delivery.socket) : void 0;
|
|
36543
36624
|
const result = await verifyAsker(pid, {
|
|
36544
36625
|
processes: readProcess,
|
|
36545
36626
|
stdout: stdoutReaders,
|
|
36546
36627
|
node: process.execPath,
|
|
36547
36628
|
script: askpassPath(),
|
|
36548
36629
|
bundles: [.../* @__PURE__ */ new Set([path32.join(bridgeRoot(), "current/bridge-hook.mjs"), ...running2])],
|
|
36549
|
-
// On Linux the password goes to the asker's
|
|
36550
|
-
|
|
36630
|
+
// On Linux the password goes to the asker's own listener (or, for an
|
|
36631
|
+
// askpass that names none, its stdout), not this connection.
|
|
36632
|
+
connection: linux ? async (asker) => !start ? "unknown" : !delivery ? "asker" : !inode ? "other" : listenerHolders(asker, inode) : (asker) => connectionHolders(asker, hookFd),
|
|
36551
36633
|
// The real-Hook tests stand a copy of bash named sudo in for sudo, which cannot run as root.
|
|
36552
36634
|
unprivilegedSudo: process.env.NODE_ENV === "test" && process.env.PHREN_SUDO_TEST_PARENT === "1"
|
|
36553
36635
|
});
|
|
36554
36636
|
if ("refused" in result) return result;
|
|
36555
|
-
return { sudo: result.sudo, sudoPid: result.sudoPid, deliver: linux ? (password) =>
|
|
36637
|
+
return { sudo: result.sudo, sudoPid: result.sudoPid, deliver: !linux ? async (password) => ({ password }) : delivery && inode ? (password) => deliverToListener(pid, start, delivery, inode, password) : (password) => writeToAsker(pid, start, password) };
|
|
36556
36638
|
}
|
|
36557
36639
|
function userName() {
|
|
36558
36640
|
try {
|
|
@@ -36576,12 +36658,63 @@ function sudoAnswer(data) {
|
|
|
36576
36658
|
async function askpass(prompt, env = process.env) {
|
|
36577
36659
|
const place = await terminalPaneFromEnv(env).catch(() => void 0);
|
|
36578
36660
|
const dispatchId = env.PHREN_DISPATCH_ID && briefId.safeParse(env.PHREN_DISPATCH_ID).success ? env.PHREN_DISPATCH_ID : void 0;
|
|
36661
|
+
const listener = process.platform === "linux" ? await deliveryListener().catch(() => void 0) : void 0;
|
|
36662
|
+
if (process.platform === "linux" && !listener) {
|
|
36663
|
+
process.stderr.write("phren askpass: could not open its delivery socket.\n");
|
|
36664
|
+
return 1;
|
|
36665
|
+
}
|
|
36666
|
+
try {
|
|
36667
|
+
return await ask(prompt, place, dispatchId, listener);
|
|
36668
|
+
} finally {
|
|
36669
|
+
listener?.close();
|
|
36670
|
+
}
|
|
36671
|
+
}
|
|
36672
|
+
function deliveryListener() {
|
|
36673
|
+
const delivery = newDelivery(), expected = Buffer.from(delivery.nonce);
|
|
36674
|
+
let printed = false;
|
|
36675
|
+
const server = createServer((socket) => {
|
|
36676
|
+
let text5 = "";
|
|
36677
|
+
socket.setTimeout(1e4, () => socket.destroy());
|
|
36678
|
+
socket.on("error", () => {
|
|
36679
|
+
});
|
|
36680
|
+
socket.on("data", (chunk) => {
|
|
36681
|
+
if (printed) {
|
|
36682
|
+
socket.destroy();
|
|
36683
|
+
return;
|
|
36684
|
+
}
|
|
36685
|
+
text5 += chunk.toString();
|
|
36686
|
+
if (text5.length > 2200) {
|
|
36687
|
+
socket.destroy();
|
|
36688
|
+
return;
|
|
36689
|
+
}
|
|
36690
|
+
const lines = text5.split("\n");
|
|
36691
|
+
if (lines.length < 3) return;
|
|
36692
|
+
const nonce = Buffer.from(lines[0]);
|
|
36693
|
+
if (nonce.length !== expected.length || !timingSafeEqual(nonce, expected) || !lines[1]) {
|
|
36694
|
+
socket.destroy();
|
|
36695
|
+
return;
|
|
36696
|
+
}
|
|
36697
|
+
printed = true;
|
|
36698
|
+
process.stdout.write(`${lines[1]}
|
|
36699
|
+
`);
|
|
36700
|
+
text5 = "";
|
|
36701
|
+
socket.end("ok\n");
|
|
36702
|
+
server.close();
|
|
36703
|
+
});
|
|
36704
|
+
});
|
|
36705
|
+
return new Promise((resolve14, reject) => {
|
|
36706
|
+
server.once("error", reject);
|
|
36707
|
+
server.listen({ path: `\0${delivery.socket}` }, () => resolve14({ delivery, printed: () => printed, close: () => server.close() }));
|
|
36708
|
+
});
|
|
36709
|
+
}
|
|
36710
|
+
async function ask(prompt, place, dispatchId, listener) {
|
|
36579
36711
|
const data = JSON.stringify({
|
|
36580
36712
|
pid: process.pid,
|
|
36581
36713
|
cwd: process.cwd(),
|
|
36582
36714
|
...prompt ? { prompt: prompt.slice(0, 200) } : {},
|
|
36583
36715
|
...place ? { place } : {},
|
|
36584
|
-
...dispatchId ? { dispatchId } : {}
|
|
36716
|
+
...dispatchId ? { dispatchId } : {},
|
|
36717
|
+
...listener ? { delivery: listener.delivery } : {}
|
|
36585
36718
|
});
|
|
36586
36719
|
const reply = await new Promise((resolve14) => {
|
|
36587
36720
|
const req = request2({
|
|
@@ -36635,7 +36768,7 @@ async function runSudo(args) {
|
|
|
36635
36768
|
child.on("exit", (code, signal) => resolve14(code ?? (signal ? 128 + ({ SIGINT: 2, SIGTERM: 15, SIGKILL: 9, SIGHUP: 1 }[signal] ?? 1) : 1)));
|
|
36636
36769
|
});
|
|
36637
36770
|
}
|
|
36638
|
-
var SUDO_HOLD_MS, MAX_SUDO_PENDING, SUDO_OUTCOME_MS, SUDO_TRIES, ASKPASS_FILE, askpassPath, askpassInstalled, askpassEnv, quote, VALUE_FLAGS, SHORT_VALUE, exec6, PRELOADS, NODE_LOADERS, placeName, SudoBroker, SudoAnswerError;
|
|
36771
|
+
var SUDO_HOLD_MS, MAX_SUDO_PENDING, SUDO_OUTCOME_MS, SUDO_TRIES, ASKPASS_FILE, askpassPath, askpassInstalled, askpassEnv, quote, VALUE_FLAGS, SHORT_VALUE, exec6, DELIVERY_SOCKET, DELIVERY_NONCE, PRELOADS, NODE_LOADERS, placeName, SudoBroker, SudoAnswerError;
|
|
36639
36772
|
var init_sudo = __esm({
|
|
36640
36773
|
"src/bridge/sudo.ts"() {
|
|
36641
36774
|
"use strict";
|
|
@@ -36681,6 +36814,8 @@ var init_sudo = __esm({
|
|
|
36681
36814
|
]);
|
|
36682
36815
|
SHORT_VALUE = /* @__PURE__ */ new Set([..."ugpCDhrtTUcR"]);
|
|
36683
36816
|
exec6 = promisify6(execFile7);
|
|
36817
|
+
DELIVERY_SOCKET = /^phren-askpass-[0-9a-f]{32}$/;
|
|
36818
|
+
DELIVERY_NONCE = /^[0-9a-f]{64}$/;
|
|
36684
36819
|
PRELOADS = ["LD_PRELOAD", "DYLD_INSERT_LIBRARIES"];
|
|
36685
36820
|
NODE_LOADERS = [...PRELOADS, "NODE_OPTIONS"];
|
|
36686
36821
|
placeName = /^[A-Za-z0-9_.:%@-]{1,128}$/;
|
|
@@ -36722,7 +36857,7 @@ var init_sudo = __esm({
|
|
|
36722
36857
|
async ask(body2, respond, hookFd) {
|
|
36723
36858
|
const none = { cancel: () => {
|
|
36724
36859
|
} };
|
|
36725
|
-
const verified2 = await (this.options.verify ?? defaultVerify)(Number(body2.pid), hookFd);
|
|
36860
|
+
const verified2 = await (this.options.verify ?? defaultVerify)(Number(body2.pid), hookFd, deliveryFrom(body2.delivery));
|
|
36726
36861
|
if ("refused" in verified2) {
|
|
36727
36862
|
respond({ status: 400, error: verified2.refused });
|
|
36728
36863
|
return none;
|
|
@@ -37420,7 +37555,7 @@ var init_package_metadata = __esm({
|
|
|
37420
37555
|
__dirname = path37.dirname(fileURLToPath2(import.meta.url));
|
|
37421
37556
|
ROOT = path37.join(__dirname, "..");
|
|
37422
37557
|
PACKAGE_JSON_PATH = path37.join(ROOT, "package.json");
|
|
37423
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
37558
|
+
BUNDLED_VERSION = true ? "0.3.36" : "0.0.0";
|
|
37424
37559
|
PACKAGE_JSON = readPackageJson();
|
|
37425
37560
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
37426
37561
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -41147,16 +41282,16 @@ function projectAuthority(policy, project) {
|
|
|
41147
41282
|
const entry2 = Object.hasOwn(policy.projects, project) ? policy.projects[project] : void 0;
|
|
41148
41283
|
const verdictOf = (action) => entry2?.actions?.[action] ?? entry2?.default ?? "go";
|
|
41149
41284
|
const go = RELEASE_ACTIONS.filter((action) => verdictOf(action) === "go");
|
|
41150
|
-
const
|
|
41151
|
-
const maxPermissionMode = entry2?.maxPermissionMode ?? (
|
|
41285
|
+
const ask2 = RELEASE_ACTIONS.filter((action) => verdictOf(action) === "ask");
|
|
41286
|
+
const maxPermissionMode = entry2?.maxPermissionMode ?? (ask2.length ? ASK_FIRST_PERMISSION_MODE : void 0);
|
|
41152
41287
|
const parts = [
|
|
41153
41288
|
...!entry2 ? ["no release restrictions listed"] : [],
|
|
41154
41289
|
...entry2 && go.length ? [`go for ${go.join(", ")}`] : [],
|
|
41155
|
-
...
|
|
41290
|
+
...ask2.length ? [`ask-first for ${ask2.join(", ")}`] : [],
|
|
41156
41291
|
...maxPermissionMode ? [`dispatched workers start at most in ${maxPermissionMode}`] : []
|
|
41157
41292
|
];
|
|
41158
41293
|
const line = `Release authority for ${project} (owner policy): ${parts.join("; ")}.${entry2?.note ? ` Note: ${entry2.note}` : ""}`;
|
|
41159
|
-
return { project, listed: !!entry2, go, ask, ...maxPermissionMode ? { maxPermissionMode } : {}, ...entry2?.note ? { note: entry2.note } : {}, line };
|
|
41294
|
+
return { project, listed: !!entry2, go, ask: ask2, ...maxPermissionMode ? { maxPermissionMode } : {}, ...entry2?.note ? { note: entry2.note } : {}, line };
|
|
41160
41295
|
}
|
|
41161
41296
|
function lowerMode(a, b) {
|
|
41162
41297
|
if (!a || !b) return a ?? b;
|
|
@@ -41914,6 +42049,39 @@ var init_policy = __esm({
|
|
|
41914
42049
|
}
|
|
41915
42050
|
});
|
|
41916
42051
|
|
|
42052
|
+
// src/bridge/host-key.ts
|
|
42053
|
+
import { execFile as execFile11 } from "node:child_process";
|
|
42054
|
+
function hostKeyScript(dirs = HOST_KEY_DIRS, sshd = "sshd") {
|
|
42055
|
+
const candidates = dirs.map((dir) => quote5(`${dir}/ssh_host_ed25519_key`)).join(" ");
|
|
42056
|
+
return `keys=$( (PATH="$PATH:/usr/sbin:/sbin:/usr/local/sbin:/opt/sbin" ${quote5(sshd)} -T 2>/dev/null) | awk '$1 == "hostkey" { print $2 }')
|
|
42057
|
+
for k in $keys ${candidates}; do
|
|
42058
|
+
[ -r "$k.pub" ] || continue
|
|
42059
|
+
line=$(head -n 1 "$k.pub")
|
|
42060
|
+
case "$line" in "ssh-ed25519 "*) printf '%s\\n' "$line"; exit 0;; esac
|
|
42061
|
+
done
|
|
42062
|
+
true`;
|
|
42063
|
+
}
|
|
42064
|
+
function noHostKey(where, dirs = HOST_KEY_DIRS) {
|
|
42065
|
+
return new BridgeError(409, `${where} has no ssh-ed25519 host key: none in sshd -T's hostkey entries or ${dirs.join(", ")}. Generate one with sudo ssh-keygen -A and restart sshd.`);
|
|
42066
|
+
}
|
|
42067
|
+
function hostKeyLine(stdout) {
|
|
42068
|
+
return stdout.split("\n").map((line) => line.trim()).find((line) => line.startsWith("ssh-ed25519 "));
|
|
42069
|
+
}
|
|
42070
|
+
function localHostKeyLine(dirs, sshd) {
|
|
42071
|
+
return new Promise((resolve14) => {
|
|
42072
|
+
execFile11("sh", ["-c", hostKeyScript(dirs, sshd)], { timeout: 1e4 }, (error62, stdout) => resolve14(hostKeyLine(stdout ?? "")));
|
|
42073
|
+
});
|
|
42074
|
+
}
|
|
42075
|
+
var HOST_KEY_DIRS, quote5;
|
|
42076
|
+
var init_host_key = __esm({
|
|
42077
|
+
"src/bridge/host-key.ts"() {
|
|
42078
|
+
"use strict";
|
|
42079
|
+
init_protocol();
|
|
42080
|
+
HOST_KEY_DIRS = ["/etc/ssh", "/usr/etc/ssh", "/usr/local/etc/ssh", "/opt/etc/ssh"];
|
|
42081
|
+
quote5 = (value2) => `'${value2.replace(/'/g, `'\\''`)}'`;
|
|
42082
|
+
}
|
|
42083
|
+
});
|
|
42084
|
+
|
|
41917
42085
|
// src/bridge/schedule-format.ts
|
|
41918
42086
|
import { readFile as readFile28 } from "node:fs/promises";
|
|
41919
42087
|
import path57 from "node:path";
|
|
@@ -43008,7 +43176,7 @@ var init_schedules = __esm({
|
|
|
43008
43176
|
});
|
|
43009
43177
|
|
|
43010
43178
|
// src/bridge/health.ts
|
|
43011
|
-
import { execFile as
|
|
43179
|
+
import { execFile as execFile12, spawn as spawn8 } from "node:child_process";
|
|
43012
43180
|
import { lstat as lstat16, readFile as readFile30 } from "node:fs/promises";
|
|
43013
43181
|
import { homedir as homedir14, hostname as hostname6 } from "node:os";
|
|
43014
43182
|
import path60 from "node:path";
|
|
@@ -43132,8 +43300,9 @@ async function lastScheduledRun(store, runsFile = scheduleRunsFile()) {
|
|
|
43132
43300
|
};
|
|
43133
43301
|
}
|
|
43134
43302
|
async function ownHostKey() {
|
|
43303
|
+
const line = await localHostKeyLine();
|
|
43135
43304
|
try {
|
|
43136
|
-
return publicComputerKey(
|
|
43305
|
+
return line ? publicComputerKey(line) : void 0;
|
|
43137
43306
|
} catch {
|
|
43138
43307
|
return void 0;
|
|
43139
43308
|
}
|
|
@@ -43241,12 +43410,13 @@ var init_health = __esm({
|
|
|
43241
43410
|
init_phren_paths();
|
|
43242
43411
|
init_store_registry();
|
|
43243
43412
|
init_computers();
|
|
43413
|
+
init_host_key();
|
|
43244
43414
|
init_peers();
|
|
43245
43415
|
init_protocol();
|
|
43246
43416
|
init_schedules();
|
|
43247
43417
|
init_metrics();
|
|
43248
43418
|
init_terminal_tmux();
|
|
43249
|
-
exec10 = promisify10(
|
|
43419
|
+
exec10 = promisify10(execFile12);
|
|
43250
43420
|
VERSION_TIMEOUT_MS = 3e3;
|
|
43251
43421
|
VERSION_CACHE_MS = 5 * 6e4;
|
|
43252
43422
|
PEER_TIMEOUT_MS = 5e3;
|
|
@@ -43263,10 +43433,10 @@ async function localCaller() {
|
|
|
43263
43433
|
function callerQuery(caller) {
|
|
43264
43434
|
return new URLSearchParams({ name: caller.name, ...caller.hostKey ? { hostKey: caller.hostKey } : {} }).toString();
|
|
43265
43435
|
}
|
|
43266
|
-
async function askPeers(peers, caller,
|
|
43436
|
+
async function askPeers(peers, caller, ask2 = peerRequest) {
|
|
43267
43437
|
return Promise.all(peers.map(async (peer) => {
|
|
43268
43438
|
try {
|
|
43269
|
-
const answer = await
|
|
43439
|
+
const answer = await ask2(peer, `/v1/conductor?${callerQuery(caller)}`, void 0, 8e3);
|
|
43270
43440
|
const computer = object2(answer.computer);
|
|
43271
43441
|
const conductor = answer.conductor && typeof answer.conductor === "object" ? object2(answer.conductor) : void 0;
|
|
43272
43442
|
const set2 = object2(answer.set);
|
|
@@ -43309,8 +43479,8 @@ function setConductor(answers, localNames2) {
|
|
|
43309
43479
|
]
|
|
43310
43480
|
};
|
|
43311
43481
|
}
|
|
43312
|
-
async function groupConductor(peers, localNames2,
|
|
43313
|
-
return setConductor(await askPeers(peers, caller ?? await localCaller(),
|
|
43482
|
+
async function groupConductor(peers, localNames2, ask2 = peerRequest, caller) {
|
|
43483
|
+
return setConductor(await askPeers(peers, caller ?? await localCaller(), ask2), localNames2);
|
|
43314
43484
|
}
|
|
43315
43485
|
function conductorOf(entries2) {
|
|
43316
43486
|
const running2 = entries2.filter((entry2) => entry2.conductor);
|
|
@@ -44259,141 +44429,81 @@ var init_dispatch = __esm({
|
|
|
44259
44429
|
}
|
|
44260
44430
|
});
|
|
44261
44431
|
|
|
44262
|
-
// src/bridge/
|
|
44263
|
-
import { createHash as createHash14
|
|
44264
|
-
import { lstat as lstat18, readFile as readFile32 } from "node:fs/promises";
|
|
44432
|
+
// src/bridge/worker-close.ts
|
|
44433
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
44434
|
+
import { lstat as lstat18, readFile as readFile32, rm as rm9 } from "node:fs/promises";
|
|
44265
44435
|
import path64 from "node:path";
|
|
44266
|
-
|
|
44267
|
-
|
|
44268
|
-
|
|
44436
|
+
async function markWorkerClosed(target, terminal2) {
|
|
44437
|
+
await atomicInPrivateDir(file2(target), { target, terminal: terminal2, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
44438
|
+
}
|
|
44439
|
+
async function intentionallyClosed(target) {
|
|
44440
|
+
try {
|
|
44441
|
+
const info = await lstat18(file2(target));
|
|
44442
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 4096) return false;
|
|
44443
|
+
const row = JSON.parse(await readFile32(file2(target), "utf8"));
|
|
44444
|
+
return closedTargetSchema.safeParse(row.target).success;
|
|
44445
|
+
} catch (error62) {
|
|
44446
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
44447
|
+
return false;
|
|
44448
|
+
}
|
|
44449
|
+
}
|
|
44450
|
+
async function markPaneClosed(server, pane) {
|
|
44451
|
+
const chat = await paneChatState(server, pane);
|
|
44452
|
+
const target = closedTargetSchema.safeParse({
|
|
44453
|
+
server,
|
|
44454
|
+
workspace: pane.workspace_id,
|
|
44455
|
+
tab: pane.tab_id,
|
|
44456
|
+
pane: pane.pane_id,
|
|
44457
|
+
source: pane.agent,
|
|
44458
|
+
...chat.sessionId ? { session: chat.sessionId } : { starting: true, startingToken: chat.startingToken }
|
|
44459
|
+
});
|
|
44460
|
+
if (target.success) await markWorkerClosed(target.data, String(pane.terminal_id));
|
|
44461
|
+
const starting = startingTargetSchema.safeParse({
|
|
44462
|
+
server,
|
|
44463
|
+
workspace: pane.workspace_id,
|
|
44464
|
+
tab: pane.tab_id,
|
|
44465
|
+
pane: pane.pane_id,
|
|
44466
|
+
source: pane.agent,
|
|
44467
|
+
starting: true,
|
|
44468
|
+
startingToken: chat.startingToken
|
|
44469
|
+
});
|
|
44470
|
+
if (starting.success) await markWorkerClosed(starting.data, String(pane.terminal_id));
|
|
44471
|
+
}
|
|
44472
|
+
async function closeFinishedWorker(input2, queue3) {
|
|
44473
|
+
const data = external_exports.object({ target: targetSchema, turn: external_exports.string().regex(/^[a-f0-9]{16}$/), dispatch: external_exports.string().uuid() }).strict().parse(input2);
|
|
44474
|
+
if (queue3) return queue3.whenNoPending(data.target, () => closeFinishedWorker(input2));
|
|
44475
|
+
const { snapshot: snapshot2, findPane: findPane2 } = await Promise.resolve().then(() => (init_herdr(), herdr_exports));
|
|
44476
|
+
if (await intentionallyClosed(data.target) && !findPane2(await snapshot2(data.target.server), data.target)) return { ok: true, closed: true, replayed: true };
|
|
44477
|
+
const pane = await validateTarget(data.target, false, true);
|
|
44478
|
+
if (!["idle", "done"].includes(String(pane.agent_status))) return { ok: true, closed: false };
|
|
44479
|
+
const seen = (await workerStates2({ targets: [{ ...data.target, dispatch: data.dispatch }] })).workers[0];
|
|
44480
|
+
const turn = workerTurnKey(seen);
|
|
44481
|
+
if (seen.state !== "done" && seen.state !== "idle" || !seen.completed || seen.background || seen.error || seen.unfinished || seen.unchecked || turn !== data.turn) return { ok: true, closed: false };
|
|
44482
|
+
const current2 = await validateTarget(data.target, false, true);
|
|
44483
|
+
if (current2.terminal_id !== pane.terminal_id || !["idle", "done"].includes(String(current2.agent_status))) throw new BridgeError(409, "The worker resumed before it could close.");
|
|
44484
|
+
const record3 = await paneTurn(data.target.server, current2, data.target.source);
|
|
44485
|
+
if (record3?.prompt && (!record3.stop || record3.stop.seq <= record3.prompt.seq || record3.terminal !== current2.terminal_id || record3.session !== data.target.session || workerTurnKey({ endedAt: record3.stop.at, stopSeq: record3.stop.seq }) !== data.turn)) return { ok: true, closed: false };
|
|
44486
|
+
await markWorkerClosed(data.target, String(pane.terminal_id));
|
|
44487
|
+
try {
|
|
44488
|
+
await terminalProvider().closePane(data.target.server, data.target.pane);
|
|
44489
|
+
} catch (error62) {
|
|
44490
|
+
const remaining = await snapshot2(data.target.server).catch(() => void 0);
|
|
44491
|
+
if (remaining && findPane2(remaining, data.target)?.terminal_id === pane.terminal_id) await rm9(file2(data.target), { force: true });
|
|
44492
|
+
throw error62;
|
|
44493
|
+
}
|
|
44494
|
+
return { ok: true, closed: true };
|
|
44495
|
+
}
|
|
44496
|
+
var closedTargetSchema, file2;
|
|
44497
|
+
var init_worker_close = __esm({
|
|
44498
|
+
"src/bridge/worker-close.ts"() {
|
|
44269
44499
|
"use strict";
|
|
44270
44500
|
init_zod();
|
|
44271
44501
|
init_protocol();
|
|
44272
|
-
|
|
44273
|
-
|
|
44274
|
-
|
|
44275
|
-
|
|
44276
|
-
|
|
44277
|
-
kind: external_exports.enum(["manual", "needs-you", "blocked"]),
|
|
44278
|
-
title,
|
|
44279
|
-
createdAt: external_exports.string().datetime(),
|
|
44280
|
-
updatedAt: external_exports.string().datetime(),
|
|
44281
|
-
state: external_exports.enum(["open", "resolved"]),
|
|
44282
|
-
resolvedAt: external_exports.string().datetime().optional(),
|
|
44283
|
-
resolution: external_exports.string().max(2e3).optional(),
|
|
44284
|
-
project: external_exports.string().max(200).optional(),
|
|
44285
|
-
computer: external_exports.string().max(253).optional(),
|
|
44286
|
-
target: inboxTargetSchema.optional(),
|
|
44287
|
-
dispatch: external_exports.string().uuid().optional(),
|
|
44288
|
-
actionId: external_exports.string().max(200).optional(),
|
|
44289
|
-
source: external_exports.string().max(500).optional(),
|
|
44290
|
-
live: external_exports.boolean().optional()
|
|
44291
|
-
}).strict();
|
|
44292
|
-
ownerInboxSchema = external_exports.object({
|
|
44293
|
-
action: external_exports.enum(["add", "list", "resolve"]).default("list"),
|
|
44294
|
-
title: title.optional(),
|
|
44295
|
-
project: external_exports.string().max(200).optional(),
|
|
44296
|
-
id: external_exports.string().uuid().optional(),
|
|
44297
|
-
resolution: external_exports.string().max(2e3).optional(),
|
|
44298
|
-
includeResolved: external_exports.boolean().optional(),
|
|
44299
|
-
computer: computerName.optional()
|
|
44300
|
-
}).strict();
|
|
44301
|
-
uuidOf = (source) => {
|
|
44302
|
-
const h = createHash14("sha256").update(source).digest("hex");
|
|
44303
|
-
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
44304
|
-
};
|
|
44305
|
-
OwnerInbox = class {
|
|
44306
|
-
constructor(sources = async () => [], file4 = path64.join(bridgeRoot(), "owner-inbox.json")) {
|
|
44307
|
-
this.sources = sources;
|
|
44308
|
-
this.file = file4;
|
|
44309
|
-
}
|
|
44310
|
-
sources;
|
|
44311
|
-
file;
|
|
44312
|
-
pending = Promise.resolve();
|
|
44313
|
-
async read() {
|
|
44314
|
-
const info = await lstat18(this.file).catch((error62) => {
|
|
44315
|
-
if (error62.code === "ENOENT") return void 0;
|
|
44316
|
-
throw error62;
|
|
44317
|
-
});
|
|
44318
|
-
if (!info) return [];
|
|
44319
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > 4 * 1024 * 1024) throw new BridgeError(409, "The owner inbox cannot be read safely.");
|
|
44320
|
-
return external_exports.array(itemSchema).max(1e4).parse(JSON.parse(await readFile32(this.file, "utf8")));
|
|
44321
|
-
}
|
|
44322
|
-
run(input2) {
|
|
44323
|
-
const run2 = this.pending.then(async () => {
|
|
44324
|
-
const data = ownerInboxSchema.parse(input2), rows = await this.read(), at = (/* @__PURE__ */ new Date()).toISOString();
|
|
44325
|
-
const sources = [];
|
|
44326
|
-
for (const receipt of await dispatchStatus()) {
|
|
44327
|
-
const returned = receipt.returned;
|
|
44328
|
-
if (receipt.closedAt || !returned || !["needs-you", "blocked"].includes(returned.state)) continue;
|
|
44329
|
-
if (receipt.worker && receipt.worker.state !== returned.state && !receipt.approval) continue;
|
|
44330
|
-
const actionId = receipt.approval?.actionId;
|
|
44331
|
-
sources.push({
|
|
44332
|
-
source: `dispatch:${receipt.id}:${actionId ?? returned.at}`,
|
|
44333
|
-
kind: returned.state,
|
|
44334
|
-
title: (receipt.approval?.request ?? returned.question ?? returned.reply ?? `${receipt.label} needs input`).replace(/[\x00-\x1f\x7f]+/g, " ").slice(0, 500),
|
|
44335
|
-
project: receipt.project,
|
|
44336
|
-
computer: receipt.computer,
|
|
44337
|
-
..."session" in (receipt.target ?? {}) ? { target: receipt.target } : {},
|
|
44338
|
-
dispatch: receipt.id,
|
|
44339
|
-
...actionId ? { actionId } : {}
|
|
44340
|
-
});
|
|
44341
|
-
}
|
|
44342
|
-
for (const source of await this.sources()) {
|
|
44343
|
-
if (source.actionId && sources.some((other) => other.actionId === source.actionId && JSON.stringify(other.target) === JSON.stringify(source.target))) continue;
|
|
44344
|
-
sources.push(source);
|
|
44345
|
-
}
|
|
44346
|
-
let changed2 = false;
|
|
44347
|
-
const live = new Set(sources.map((s) => s.source));
|
|
44348
|
-
for (const row of rows) if (row.source && row.live !== live.has(row.source)) {
|
|
44349
|
-
row.live = live.has(row.source);
|
|
44350
|
-
row.updatedAt = at;
|
|
44351
|
-
changed2 = true;
|
|
44352
|
-
}
|
|
44353
|
-
for (const source of sources) {
|
|
44354
|
-
const existing = rows.find((row) => row.source === source.source);
|
|
44355
|
-
if (existing) continue;
|
|
44356
|
-
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
44357
|
-
rows.push(itemSchema.parse({ ...source, id: uuidOf(source.source), state: "open", live: true, createdAt: at, updatedAt: at }));
|
|
44358
|
-
changed2 = true;
|
|
44359
|
-
}
|
|
44360
|
-
if (data.action === "add") {
|
|
44361
|
-
if (!data.title) throw new BridgeError(400, "Name the owner inbox item.");
|
|
44362
|
-
const item = itemSchema.parse({ id: data.id ?? randomUUID13(), kind: "manual", title: data.title, state: "open", createdAt: at, updatedAt: at, ...data.project ? { project: data.project } : {} });
|
|
44363
|
-
const prior = rows.find((row) => row.id === item.id);
|
|
44364
|
-
if (prior && (prior.title !== item.title || prior.project !== item.project || prior.kind !== "manual")) throw new BridgeError(409, "This inbox id names another item.");
|
|
44365
|
-
if (!prior) {
|
|
44366
|
-
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
44367
|
-
rows.push(item);
|
|
44368
|
-
changed2 = true;
|
|
44369
|
-
}
|
|
44370
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44371
|
-
return { ok: true, item: prior ?? item };
|
|
44372
|
-
}
|
|
44373
|
-
if (data.action === "resolve") {
|
|
44374
|
-
const item = rows.find((row) => row.id === data.id);
|
|
44375
|
-
if (!item) throw new BridgeError(404, "No owner inbox item with that id.");
|
|
44376
|
-
if (item.state !== "resolved") {
|
|
44377
|
-
item.state = "resolved";
|
|
44378
|
-
item.resolvedAt = at;
|
|
44379
|
-
item.updatedAt = at;
|
|
44380
|
-
item.resolution = data.resolution;
|
|
44381
|
-
changed2 = true;
|
|
44382
|
-
}
|
|
44383
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44384
|
-
return { ok: true, item };
|
|
44385
|
-
}
|
|
44386
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44387
|
-
return { ok: true, items: rows.filter((row) => data.includeResolved || row.state === "open").sort((a, b) => a.createdAt.localeCompare(b.createdAt)) };
|
|
44388
|
-
});
|
|
44389
|
-
this.pending = run2.catch(() => {
|
|
44390
|
-
});
|
|
44391
|
-
return run2;
|
|
44392
|
-
}
|
|
44393
|
-
async tick() {
|
|
44394
|
-
await this.run({ action: "list" });
|
|
44395
|
-
}
|
|
44396
|
-
};
|
|
44502
|
+
init_herdr();
|
|
44503
|
+
init_terminal();
|
|
44504
|
+
init_dispatch_returns();
|
|
44505
|
+
closedTargetSchema = external_exports.union([targetSchema, startingTargetSchema]);
|
|
44506
|
+
file2 = (target) => path64.join(bridgeRoot(), "closed-workers", `${createHash14("sha256").update(JSON.stringify([target.server, target.workspace, target.tab, target.pane, target.source, "session" in target ? target.session : target.startingToken])).digest("hex")}.json`);
|
|
44397
44507
|
}
|
|
44398
44508
|
});
|
|
44399
44509
|
|
|
@@ -44402,23 +44512,32 @@ import { createHash as createHash15 } from "node:crypto";
|
|
|
44402
44512
|
import { lstat as lstat19, readFile as readFile33 } from "node:fs/promises";
|
|
44403
44513
|
import path65 from "node:path";
|
|
44404
44514
|
async function reportWorker(input2) {
|
|
44405
|
-
const data = external_exports.object({ origin: originPaneSchema, prs: prsSchema }).strict().parse(input2);
|
|
44515
|
+
const data = external_exports.object({ origin: originPaneSchema, prs: prsSchema, dispatch: briefId.optional() }).strict().parse(input2);
|
|
44406
44516
|
const pane = findPane(await snapshot(data.origin.server), data.origin);
|
|
44407
44517
|
if (!pane) throw new BridgeError(409, "The worker pane changed.");
|
|
44408
44518
|
const session = await paneIdentity(data.origin.server, pane, true);
|
|
44409
44519
|
const target = targetSchema.parse({ ...data.origin, source: pane.agent, session });
|
|
44410
44520
|
await validateTarget(target, false, true);
|
|
44411
44521
|
const record3 = await paneTurn(target.server, pane, target.source);
|
|
44412
|
-
|
|
44413
|
-
|
|
44522
|
+
const promptSeq = record3?.prompt && record3.session === session && record3.terminal === pane.terminal_id ? record3.prompt.seq : void 0;
|
|
44523
|
+
if (promptSeq === void 0 && !(typeof pane.terminal_id === "string" && await arrivedHere(data.dispatch ?? (record3 && record3.session === session ? record3.dispatch : void 0), target)))
|
|
44524
|
+
throw new BridgeError(409, "The Hook has not recorded this worker's submitted turn yet, and no dispatch it launched arrived in this pane.");
|
|
44525
|
+
await atomicInPrivateDir(reportFile(target), reportSchema.parse({ target, terminal: pane.terminal_id, ...promptSeq !== void 0 ? { promptSeq } : {}, prs: data.prs, at: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
44414
44526
|
return { ok: true, target, prs: data.prs };
|
|
44415
44527
|
}
|
|
44528
|
+
async function arrivedHere(id2, target) {
|
|
44529
|
+
if (!id2) return false;
|
|
44530
|
+
const arrival = await briefArrival(id2);
|
|
44531
|
+
return [arrival?.accepted, arrival?.started].some((event) => event && key2(event.target) === key2(target));
|
|
44532
|
+
}
|
|
44416
44533
|
async function workerPrs(target, record3) {
|
|
44417
44534
|
try {
|
|
44418
44535
|
const file4 = reportFile(target), info = await lstat19(file4);
|
|
44419
44536
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 131072) return void 0;
|
|
44420
44537
|
const report = reportSchema.parse(JSON.parse(await readFile33(file4, "utf8")));
|
|
44421
|
-
|
|
44538
|
+
if (report.terminal !== record3.terminal) return void 0;
|
|
44539
|
+
if (report.promptSeq !== void 0) return report.promptSeq === record3.prompt?.seq ? report.prs : void 0;
|
|
44540
|
+
return !record3.prompt || Date.parse(record3.prompt.at) <= Date.parse(report.at) ? report.prs : void 0;
|
|
44422
44541
|
} catch (error62) {
|
|
44423
44542
|
if (error62.code !== "ENOENT") throw error62;
|
|
44424
44543
|
return void 0;
|
|
@@ -44451,9 +44570,10 @@ var init_worker_reports = __esm({
|
|
|
44451
44570
|
init_herdr();
|
|
44452
44571
|
init_dispatch();
|
|
44453
44572
|
init_dispatch_returns();
|
|
44573
|
+
init_launch_brief();
|
|
44454
44574
|
init_return_contract();
|
|
44455
44575
|
init_return_contract();
|
|
44456
|
-
reportSchema = external_exports.object({ target: targetSchema, terminal: reportText(200), promptSeq: external_exports.number().int(), prs: prsSchema, at: external_exports.string().datetime() }).strict();
|
|
44576
|
+
reportSchema = external_exports.object({ target: targetSchema, terminal: reportText(200), promptSeq: external_exports.number().int().optional(), prs: prsSchema, at: external_exports.string().datetime() }).strict();
|
|
44457
44577
|
key2 = (target) => createHash15("sha256").update(JSON.stringify([target.server, target.workspace, target.tab, target.pane, target.source, target.session])).digest("hex");
|
|
44458
44578
|
reportFile = (target) => path65.join(bridgeRoot(), "worker-reports", `${key2(target)}.json`);
|
|
44459
44579
|
}
|
|
@@ -44707,7 +44827,7 @@ var init_approval_summary = __esm({
|
|
|
44707
44827
|
});
|
|
44708
44828
|
|
|
44709
44829
|
// src/bridge/hand-off.ts
|
|
44710
|
-
import { randomUUID as
|
|
44830
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
44711
44831
|
function labelOf(group, tab) {
|
|
44712
44832
|
const folder = typeof tab.cwd === "string" && tab.role !== "conductor" ? tab.cwd.split("/").filter(Boolean).at(-1) : void 0;
|
|
44713
44833
|
return folder || (typeof group.label === "string" && group.label ? group.label : void 0);
|
|
@@ -44758,7 +44878,7 @@ async function handOff(input2, options = {}) {
|
|
|
44758
44878
|
if (here) origin = await findInOverview((route2, body2) => hookRequest(route2, body2), (found) => found.server === here.server && found.pane === here.pane, here.server).then((found) => found?.target, () => void 0);
|
|
44759
44879
|
}
|
|
44760
44880
|
const originComputer = peer && origin ? await hookRequest("/v1/health").then((health2) => object2(health2.computer).name, () => void 0) : void 0;
|
|
44761
|
-
const deliveryId = data.deliveryId ?? options.deliveryId ??
|
|
44881
|
+
const deliveryId = data.deliveryId ?? options.deliveryId ?? randomUUID13().replaceAll("-", "");
|
|
44762
44882
|
const result = await request9(data.status ? "/v1/hand-off/status" : "/v1/hand-off", {
|
|
44763
44883
|
target,
|
|
44764
44884
|
deliveryId,
|
|
@@ -44877,7 +44997,7 @@ var init_hand_off = __esm({
|
|
|
44877
44997
|
});
|
|
44878
44998
|
|
|
44879
44999
|
// src/bridge/worker-unfinished.ts
|
|
44880
|
-
import { execFile as
|
|
45000
|
+
import { execFile as execFile13 } from "node:child_process";
|
|
44881
45001
|
import { lstat as lstat20 } from "node:fs/promises";
|
|
44882
45002
|
import path67 from "node:path";
|
|
44883
45003
|
import { promisify as promisify11 } from "node:util";
|
|
@@ -44975,7 +45095,7 @@ var init_worker_unfinished = __esm({
|
|
|
44975
45095
|
"use strict";
|
|
44976
45096
|
init_utils_helpers();
|
|
44977
45097
|
init_metrics();
|
|
44978
|
-
exec11 = promisify11(
|
|
45098
|
+
exec11 = promisify11(execFile13);
|
|
44979
45099
|
NEXT_STEP = /^(?:(?:ok(?:ay)?|alright|now|next|then|first|great|good)\b[,.!:]?\s+)*(?:let me(?! know)|let's|let us|i'll|i will|i'm going to|i am going to|i need to|i'm now|i am now|now i)\s+(.*)$/i;
|
|
44980
45100
|
NOW_DOING = /^now,?\s+(?:adding|applying|building|checking|cleaning|committing|compiling|creating|debugging|editing|fixing|generating|implementing|installing|investigating|launching|looking|moving|opening|patching|pushing|reading|rebuilding|refactoring|removing|rerunning|re-running|running|searching|setting|starting|testing|trying|updating|verifying|wiring|working|writing)\b/i;
|
|
44981
45101
|
HANDOVER = /^(?:just\s+)?(?:wait|await|leave|stop|hold|pause|be|hand|defer|stand|end|wrap|let you|keep an eye|check back|merge|ship|land|release|discuss|review|done|finished|ready)\b/i;
|
|
@@ -45253,16 +45373,16 @@ function observeState(receipt, parsed, now) {
|
|
|
45253
45373
|
return true;
|
|
45254
45374
|
}
|
|
45255
45375
|
function noticeLine(receipts) {
|
|
45256
|
-
const
|
|
45376
|
+
const clean3 = (value2, max) => value2.replace(/[\x00-\x1f\x7f]+/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
|
|
45257
45377
|
const word = { "done": "done", "needs-you": "needs you", "failed": "failed", "blocked": "blocked", "gone": "gone", "stalled": "stalled" };
|
|
45258
45378
|
const describe4 = (receipt, room) => {
|
|
45259
45379
|
const returned = receipt.returned;
|
|
45260
45380
|
const asking = returned.state === "blocked" ? receipt.approval : void 0;
|
|
45261
45381
|
const detail = asking ? asking.request ?? asking.title ?? asking.tool : returned.state === "needs-you" ? returned.question : returned.state === "failed" ? returned.error : returned.state === "done" ? returned.reply?.split("\n").find((line) => line.trim()) : void 0;
|
|
45262
|
-
const excerpt = detail ?
|
|
45382
|
+
const excerpt = detail ? clean3(detail.replace(/[*_`#>]+/g, ""), room) : "";
|
|
45263
45383
|
const tasks = (count2) => `${count2} background task${count2 === 1 ? "" : "s"}`;
|
|
45264
45384
|
const left = returned.background ? ` (${tasks(returned.background)} still running)` : returned.waited ? ` (after ${tasks(returned.waited)} finished)` : "";
|
|
45265
|
-
return `${
|
|
45385
|
+
return `${clean3(receipt.computer, 60)} ${clean3(receipt.label, 80)} ${asking ? "needs approval" : word[returned.state]}${left}${excerpt ? `, ${excerpt}` : ""}`;
|
|
45266
45386
|
};
|
|
45267
45387
|
if (receipts.length === 1) {
|
|
45268
45388
|
const [only] = receipts;
|
|
@@ -45680,86 +45800,279 @@ ${JSON.stringify({ dispatch: receipt.id, project: receipt.project, prs: result.p
|
|
|
45680
45800
|
}
|
|
45681
45801
|
});
|
|
45682
45802
|
|
|
45683
|
-
// src/bridge/
|
|
45684
|
-
import {
|
|
45685
|
-
import { lstat as lstat21,
|
|
45803
|
+
// src/bridge/owner-inbox.ts
|
|
45804
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
45805
|
+
import { lstat as lstat21, mkdir as mkdir19, readFile as readFile34 } from "node:fs/promises";
|
|
45686
45806
|
import path68 from "node:path";
|
|
45687
|
-
|
|
45688
|
-
|
|
45689
|
-
|
|
45690
|
-
|
|
45691
|
-
|
|
45692
|
-
|
|
45693
|
-
|
|
45694
|
-
|
|
45695
|
-
|
|
45696
|
-
|
|
45697
|
-
|
|
45698
|
-
|
|
45807
|
+
function sourceKey(row) {
|
|
45808
|
+
const t = row.target;
|
|
45809
|
+
return t ? JSON.stringify([
|
|
45810
|
+
row.computer ?? "local",
|
|
45811
|
+
t.server,
|
|
45812
|
+
t.workspace,
|
|
45813
|
+
t.tab,
|
|
45814
|
+
t.pane,
|
|
45815
|
+
t.source,
|
|
45816
|
+
"session" in t ? t.session : t.startingToken,
|
|
45817
|
+
row.actionId ?? "waiting"
|
|
45818
|
+
]) : row.dispatch ? `dispatch:${row.dispatch}:${row.actionId ?? "waiting"}` : row.source;
|
|
45819
|
+
}
|
|
45820
|
+
var title, inboxTargetSchema, itemSchema, ownerInboxSchema, OwnerInbox;
|
|
45821
|
+
var init_owner_inbox = __esm({
|
|
45822
|
+
"src/bridge/owner-inbox.ts"() {
|
|
45823
|
+
"use strict";
|
|
45824
|
+
init_zod();
|
|
45825
|
+
init_protocol();
|
|
45826
|
+
init_locks();
|
|
45827
|
+
title = external_exports.string().trim().min(1).max(500).refine((s) => !/[\x00-\x1f\x7f]/.test(s));
|
|
45828
|
+
inboxTargetSchema = external_exports.union([targetSchema, startingTargetSchema]);
|
|
45829
|
+
itemSchema = external_exports.object({
|
|
45830
|
+
id: external_exports.string().uuid(),
|
|
45831
|
+
kind: external_exports.enum(["manual", "needs-you", "blocked"]),
|
|
45832
|
+
title,
|
|
45833
|
+
createdAt: external_exports.string().datetime(),
|
|
45834
|
+
updatedAt: external_exports.string().datetime(),
|
|
45835
|
+
state: external_exports.enum(["open", "resolved"]),
|
|
45836
|
+
resolvedAt: external_exports.string().datetime().optional(),
|
|
45837
|
+
resolution: external_exports.string().max(2e3).optional(),
|
|
45838
|
+
project: external_exports.string().max(200).optional(),
|
|
45839
|
+
computer: external_exports.string().max(253).optional(),
|
|
45840
|
+
target: inboxTargetSchema.optional(),
|
|
45841
|
+
dispatch: external_exports.string().uuid().optional(),
|
|
45842
|
+
actionId: external_exports.string().max(200).optional(),
|
|
45843
|
+
source: external_exports.string().max(500).optional(),
|
|
45844
|
+
live: external_exports.boolean().optional()
|
|
45845
|
+
}).strict();
|
|
45846
|
+
ownerInboxSchema = external_exports.object({
|
|
45847
|
+
action: external_exports.enum(["add", "list", "resolve"]).default("list"),
|
|
45848
|
+
title: title.optional(),
|
|
45849
|
+
project: external_exports.string().max(200).optional(),
|
|
45850
|
+
id: external_exports.string().uuid().optional(),
|
|
45851
|
+
resolution: external_exports.string().max(2e3).optional(),
|
|
45852
|
+
includeResolved: external_exports.boolean().optional(),
|
|
45853
|
+
computer: computerName.optional()
|
|
45854
|
+
}).strict();
|
|
45855
|
+
OwnerInbox = class {
|
|
45856
|
+
constructor(sources = async () => [], file4 = path68.join(bridgeRoot(), "owner-inbox.json")) {
|
|
45857
|
+
this.sources = sources;
|
|
45858
|
+
this.file = file4;
|
|
45859
|
+
}
|
|
45860
|
+
sources;
|
|
45861
|
+
file;
|
|
45862
|
+
pending = Promise.resolve();
|
|
45863
|
+
async read() {
|
|
45864
|
+
const info = await lstat21(this.file).catch((error62) => {
|
|
45865
|
+
if (error62.code === "ENOENT") return void 0;
|
|
45866
|
+
throw error62;
|
|
45867
|
+
});
|
|
45868
|
+
if (!info) return [];
|
|
45869
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 4 * 1024 * 1024) throw new BridgeError(409, "The owner inbox cannot be read safely.");
|
|
45870
|
+
return external_exports.array(itemSchema).max(1e4).parse(JSON.parse(await readFile34(this.file, "utf8")));
|
|
45871
|
+
}
|
|
45872
|
+
run(input2) {
|
|
45873
|
+
const run2 = this.pending.then(async () => {
|
|
45874
|
+
const data = ownerInboxSchema.parse(input2);
|
|
45875
|
+
await mkdir19(path68.dirname(this.file), { recursive: true, mode: 448 });
|
|
45876
|
+
const deadline = Date.now() + 3e4;
|
|
45877
|
+
let release = tryFileLock(this.file);
|
|
45878
|
+
while (!release) {
|
|
45879
|
+
if (Date.now() >= deadline) throw new BridgeError(503, "The owner inbox is busy; retry the operation.");
|
|
45880
|
+
await new Promise((resolve14) => setTimeout(resolve14, 20));
|
|
45881
|
+
release = tryFileLock(this.file);
|
|
45882
|
+
}
|
|
45883
|
+
try {
|
|
45884
|
+
const rows = await this.read(), at = (/* @__PURE__ */ new Date()).toISOString();
|
|
45885
|
+
let changed2 = false;
|
|
45886
|
+
if (data.action === "list") {
|
|
45887
|
+
const observed = await this.sources();
|
|
45888
|
+
const { sources, unavailableDispatches = [] } = Array.isArray(observed) ? { sources: observed } : observed;
|
|
45889
|
+
const active = new Map(sources.map((source) => [sourceKey(source), source]));
|
|
45890
|
+
const retained = /* @__PURE__ */ new Set();
|
|
45891
|
+
const resolve14 = (row, reason2) => {
|
|
45892
|
+
row.state = "resolved";
|
|
45893
|
+
row.live = false;
|
|
45894
|
+
row.resolvedAt = at;
|
|
45895
|
+
row.updatedAt = at;
|
|
45896
|
+
row.resolution = reason2;
|
|
45897
|
+
changed2 = true;
|
|
45898
|
+
};
|
|
45899
|
+
for (const row of rows) {
|
|
45900
|
+
if (row.kind === "manual") continue;
|
|
45901
|
+
if (row.state === "resolved" && !row.live) continue;
|
|
45902
|
+
const key4 = sourceKey(row), source = key4 ? active.get(key4) : void 0;
|
|
45903
|
+
const unavailable = !!row.dispatch && unavailableDispatches.includes(row.dispatch);
|
|
45904
|
+
const live = !!source && !retained.has(key4);
|
|
45905
|
+
if (row.live !== live) {
|
|
45906
|
+
row.live = live;
|
|
45907
|
+
row.updatedAt = at;
|
|
45908
|
+
changed2 = true;
|
|
45909
|
+
}
|
|
45910
|
+
if (!source) {
|
|
45911
|
+
if (row.state === "open" && !unavailable) resolve14(row, "stale: source gone");
|
|
45912
|
+
continue;
|
|
45913
|
+
}
|
|
45914
|
+
if (retained.has(key4)) {
|
|
45915
|
+
if (row.state === "open") resolve14(row, "duplicate: source");
|
|
45916
|
+
continue;
|
|
45917
|
+
}
|
|
45918
|
+
retained.add(key4);
|
|
45919
|
+
if (row.state === "open" && JSON.stringify({ ...row, ...source }) !== JSON.stringify(row)) {
|
|
45920
|
+
Object.assign(row, source, { updatedAt: at });
|
|
45921
|
+
changed2 = true;
|
|
45922
|
+
}
|
|
45923
|
+
}
|
|
45924
|
+
for (const [key4, source] of active) {
|
|
45925
|
+
if (retained.has(key4)) continue;
|
|
45926
|
+
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
45927
|
+
rows.push(itemSchema.parse({ ...source, id: randomUUID14(), state: "open", live: true, createdAt: at, updatedAt: at }));
|
|
45928
|
+
changed2 = true;
|
|
45929
|
+
}
|
|
45930
|
+
}
|
|
45931
|
+
if (data.action === "add") {
|
|
45932
|
+
if (!data.title) throw new BridgeError(400, "Name the owner inbox item.");
|
|
45933
|
+
const item = itemSchema.parse({ id: data.id ?? randomUUID14(), kind: "manual", title: data.title, state: "open", createdAt: at, updatedAt: at, ...data.project ? { project: data.project } : {} });
|
|
45934
|
+
const prior = rows.find((row) => row.id === item.id);
|
|
45935
|
+
if (prior && (prior.title !== item.title || prior.project !== item.project || prior.kind !== "manual")) throw new BridgeError(409, "This inbox id names another item.");
|
|
45936
|
+
if (!prior) {
|
|
45937
|
+
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
45938
|
+
rows.push(item);
|
|
45939
|
+
changed2 = true;
|
|
45940
|
+
}
|
|
45941
|
+
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
45942
|
+
return { ok: true, item: prior ?? item };
|
|
45943
|
+
}
|
|
45944
|
+
if (data.action === "resolve") {
|
|
45945
|
+
const item = rows.find((row) => row.id === data.id);
|
|
45946
|
+
if (!item) throw new BridgeError(404, "No owner inbox item with that id.");
|
|
45947
|
+
if (item.state !== "resolved") {
|
|
45948
|
+
item.state = "resolved";
|
|
45949
|
+
item.resolvedAt = at;
|
|
45950
|
+
item.updatedAt = at;
|
|
45951
|
+
item.resolution = data.resolution;
|
|
45952
|
+
changed2 = true;
|
|
45953
|
+
}
|
|
45954
|
+
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
45955
|
+
return { ok: true, item };
|
|
45956
|
+
}
|
|
45957
|
+
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
45958
|
+
return { ok: true, items: rows.filter((row) => data.includeResolved || row.state === "open" && (row.kind === "manual" || row.live === true)).sort((a, b) => a.createdAt.localeCompare(b.createdAt)) };
|
|
45959
|
+
} finally {
|
|
45960
|
+
release();
|
|
45961
|
+
}
|
|
45962
|
+
});
|
|
45963
|
+
this.pending = run2.catch(() => {
|
|
45964
|
+
});
|
|
45965
|
+
return run2;
|
|
45966
|
+
}
|
|
45967
|
+
async tick() {
|
|
45968
|
+
await this.run({ action: "list" });
|
|
45969
|
+
}
|
|
45970
|
+
};
|
|
45699
45971
|
}
|
|
45700
|
-
}
|
|
45701
|
-
|
|
45702
|
-
|
|
45703
|
-
|
|
45704
|
-
|
|
45705
|
-
|
|
45706
|
-
|
|
45707
|
-
pane
|
|
45708
|
-
|
|
45709
|
-
|
|
45710
|
-
|
|
45711
|
-
|
|
45712
|
-
|
|
45713
|
-
|
|
45714
|
-
|
|
45715
|
-
|
|
45716
|
-
|
|
45717
|
-
|
|
45718
|
-
|
|
45719
|
-
|
|
45720
|
-
|
|
45721
|
-
|
|
45722
|
-
}
|
|
45723
|
-
|
|
45724
|
-
|
|
45725
|
-
|
|
45726
|
-
|
|
45727
|
-
|
|
45728
|
-
|
|
45729
|
-
|
|
45730
|
-
|
|
45731
|
-
|
|
45732
|
-
|
|
45733
|
-
|
|
45734
|
-
|
|
45735
|
-
|
|
45736
|
-
|
|
45737
|
-
await markWorkerClosed(data.target, String(pane.terminal_id));
|
|
45738
|
-
try {
|
|
45739
|
-
await terminalProvider().closePane(data.target.server, data.target.pane);
|
|
45740
|
-
} catch (error62) {
|
|
45741
|
-
const remaining = await snapshot2(data.target.server).catch(() => void 0);
|
|
45742
|
-
if (remaining && findPane2(remaining, data.target)?.terminal_id === pane.terminal_id) await rm9(file2(data.target), { force: true });
|
|
45743
|
-
throw error62;
|
|
45972
|
+
});
|
|
45973
|
+
|
|
45974
|
+
// src/bridge/owner-inbox-sources.ts
|
|
45975
|
+
async function ownerInboxSources(hooks) {
|
|
45976
|
+
const sources = [], unavailableDispatches = [];
|
|
45977
|
+
for (const server of await recentServers()) {
|
|
45978
|
+
const name = String(server.session), state = await snapshot(name);
|
|
45979
|
+
for (const pane of objects(state.panes)) {
|
|
45980
|
+
const chat = await paneChatState(name, pane, { tokenWhenIdentified: false });
|
|
45981
|
+
const parsed = inboxTargetSchema.safeParse({
|
|
45982
|
+
server: name,
|
|
45983
|
+
workspace: pane.workspace_id,
|
|
45984
|
+
tab: pane.tab_id,
|
|
45985
|
+
pane: pane.pane_id,
|
|
45986
|
+
source: pane.agent,
|
|
45987
|
+
...chat.sessionId ? { session: chat.sessionId } : { starting: true, startingToken: chat.startingToken }
|
|
45988
|
+
});
|
|
45989
|
+
if (!parsed.success) continue;
|
|
45990
|
+
const target = parsed.data, waiting = ["blocked", "waiting"].includes(String(pane.agent_status));
|
|
45991
|
+
if ("session" in target) {
|
|
45992
|
+
await hooks.syncTerminalDialog(target, waiting);
|
|
45993
|
+
if (!waiting) hooks.clearTerminalPrompt(target);
|
|
45994
|
+
}
|
|
45995
|
+
const approval = "session" in target ? hooks.workerApproval(target) : void 0;
|
|
45996
|
+
const question2 = "session" in target ? hooks.servedQuestion(target) : void 0;
|
|
45997
|
+
const terminal2 = waiting && "session" in target ? hooks.terminalPrompt(target) : void 0;
|
|
45998
|
+
const request9 = approval?.request ?? question2?.message ?? terminal2?.request ?? terminal2?.message ?? (waiting ? `${pane.agent} needs terminal input.` : void 0);
|
|
45999
|
+
if (!request9) continue;
|
|
46000
|
+
const actionId = approval?.actionId ?? (typeof question2?.actionId === "string" ? question2.actionId : void 0);
|
|
46001
|
+
sources.push({
|
|
46002
|
+
source: `prompt:${JSON.stringify(target)}:${actionId ?? "waiting"}`,
|
|
46003
|
+
kind: "blocked",
|
|
46004
|
+
title: clean2(request9),
|
|
46005
|
+
target,
|
|
46006
|
+
...actionId ? { actionId } : {}
|
|
46007
|
+
});
|
|
46008
|
+
}
|
|
45744
46009
|
}
|
|
45745
|
-
|
|
46010
|
+
const candidates = (await dispatchStatus()).filter((receipt) => !receipt.closedAt && receipt.target && receipt.returned && ["needs-you", "blocked"].includes(receipt.returned.state));
|
|
46011
|
+
const groups = /* @__PURE__ */ new Map();
|
|
46012
|
+
for (const receipt of candidates) {
|
|
46013
|
+
const computer = isLocalComputer(receipt.computer) ? "local" : receipt.computer;
|
|
46014
|
+
groups.set(computer, [...groups.get(computer) ?? [], receipt]);
|
|
46015
|
+
}
|
|
46016
|
+
const peers = groups.size && [...groups.keys()].some((name) => name !== "local") ? await hookPeers() : [];
|
|
46017
|
+
for (const [computer, receipts] of groups) {
|
|
46018
|
+
for (let offset = 0; offset < receipts.length; offset += 64) {
|
|
46019
|
+
const batch = receipts.slice(offset, offset + 64);
|
|
46020
|
+
const input2 = { targets: batch.map((receipt) => ({ ...receipt.target, dispatch: receipt.id })) };
|
|
46021
|
+
let workers;
|
|
46022
|
+
try {
|
|
46023
|
+
const peer = peers.find((peer2) => peer2.name === computer);
|
|
46024
|
+
const result = computer === "local" ? await workerStates2(input2, { ...workerReaders((target) => hooks.workerApproval(target)), snapshot }) : peer ? await peerRequest(peer, "/v1/dispatch/workers", input2) : void 0;
|
|
46025
|
+
workers = objects(result?.workers);
|
|
46026
|
+
} catch {
|
|
46027
|
+
workers = [];
|
|
46028
|
+
}
|
|
46029
|
+
for (const [index2, receipt] of batch.entries()) {
|
|
46030
|
+
const seen = workers[index2];
|
|
46031
|
+
if (!seen || ["unavailable", "unknown"].includes(String(seen.state))) {
|
|
46032
|
+
unavailableDispatches.push(receipt.id);
|
|
46033
|
+
continue;
|
|
46034
|
+
}
|
|
46035
|
+
if (["gone", "closed"].includes(String(seen.state))) continue;
|
|
46036
|
+
const approval = object2(seen.approval);
|
|
46037
|
+
const actionId = typeof approval.actionId === "string" ? approval.actionId : void 0;
|
|
46038
|
+
const question2 = ["idle", "done"].includes(String(seen.state)) && seen.completed && !seen.error && !seen.interrupted ? (typeof seen.reply === "string" ? ownerQuestion(seen.reply) : void 0) ?? seen.unfinished : void 0;
|
|
46039
|
+
if (!actionId && seen.state !== "blocked" && !question2) continue;
|
|
46040
|
+
const source = {
|
|
46041
|
+
source: `dispatch:${receipt.id}:${actionId ?? "waiting"}`,
|
|
46042
|
+
kind: actionId || seen.state === "blocked" ? "blocked" : "needs-you",
|
|
46043
|
+
title: clean2(approval.request ?? question2 ?? `${receipt.label} needs input`),
|
|
46044
|
+
project: receipt.project,
|
|
46045
|
+
...computer !== "local" ? { computer } : {},
|
|
46046
|
+
target: receipt.target,
|
|
46047
|
+
dispatch: receipt.id,
|
|
46048
|
+
...actionId ? { actionId } : {}
|
|
46049
|
+
};
|
|
46050
|
+
const local = sources.findIndex((row) => JSON.stringify(row.target) === JSON.stringify(source.target) && !row.computer);
|
|
46051
|
+
if (computer === "local" && local >= 0) sources.splice(local, 1);
|
|
46052
|
+
sources.push(source);
|
|
46053
|
+
}
|
|
46054
|
+
}
|
|
46055
|
+
}
|
|
46056
|
+
return { sources, unavailableDispatches };
|
|
45746
46057
|
}
|
|
45747
|
-
var
|
|
45748
|
-
var
|
|
45749
|
-
"src/bridge/
|
|
46058
|
+
var clean2;
|
|
46059
|
+
var init_owner_inbox_sources = __esm({
|
|
46060
|
+
"src/bridge/owner-inbox-sources.ts"() {
|
|
45750
46061
|
"use strict";
|
|
45751
|
-
|
|
45752
|
-
|
|
45753
|
-
init_herdr();
|
|
45754
|
-
init_terminal();
|
|
46062
|
+
init_dispatch();
|
|
46063
|
+
init_dispatch_hosts();
|
|
45755
46064
|
init_dispatch_returns();
|
|
45756
|
-
|
|
45757
|
-
|
|
46065
|
+
init_herdr();
|
|
46066
|
+
init_owner_inbox();
|
|
46067
|
+
init_peers();
|
|
46068
|
+
init_schedule_watch();
|
|
46069
|
+
init_protocol();
|
|
46070
|
+
clean2 = (text5) => String(text5).replace(/[\x00-\x1f\x7f]+/g, " ").trim().slice(0, 500);
|
|
45758
46071
|
}
|
|
45759
46072
|
});
|
|
45760
46073
|
|
|
45761
46074
|
// src/bridge/hand-off-queue.ts
|
|
45762
|
-
import { createHash as
|
|
46075
|
+
import { createHash as createHash19, randomUUID as randomUUID15 } from "node:crypto";
|
|
45763
46076
|
import { lstat as lstat22, open as open15, readFile as readFile35, readdir as readdir13, unlink as unlink5 } from "node:fs/promises";
|
|
45764
46077
|
import path69 from "node:path";
|
|
45765
46078
|
var queuedHandOffSchema, rowSchema, DAY2, HAND_OFF_RETENTION_MS, HAND_OFF_MAX_ROWS, settled2, samePane, HandOffQueue;
|
|
@@ -46021,7 +46334,7 @@ var init_hand_off_queue = __esm({
|
|
|
46021
46334
|
}));
|
|
46022
46335
|
}
|
|
46023
46336
|
noticeId(row) {
|
|
46024
|
-
return `handoff-notice-${
|
|
46337
|
+
return `handoff-notice-${createHash19("sha256").update(row.deliveryId).digest("hex").slice(0, 40)}`;
|
|
46025
46338
|
}
|
|
46026
46339
|
/** Hold enqueues and delivery while the Hook validates and closes a worker.
|
|
46027
46340
|
* A new hand-off cannot be accepted between the pending check and closure. */
|
|
@@ -46039,8 +46352,8 @@ var init_hand_off_queue = __esm({
|
|
|
46039
46352
|
});
|
|
46040
46353
|
|
|
46041
46354
|
// src/bridge/git.ts
|
|
46042
|
-
import { createHash as
|
|
46043
|
-
import { execFile as
|
|
46355
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
46356
|
+
import { execFile as execFile14 } from "node:child_process";
|
|
46044
46357
|
import { lstat as lstat23, open as open16, readdir as readdir14, realpath as realpath11 } from "node:fs/promises";
|
|
46045
46358
|
import path70 from "node:path";
|
|
46046
46359
|
import { promisify as promisify12 } from "node:util";
|
|
@@ -46339,9 +46652,9 @@ async function repositoryPath(root, raw, allowRoot = false) {
|
|
|
46339
46652
|
if (typeof raw !== "string" || raw.length > 4096 || raw.includes("\0") || path70.isAbsolute(raw) || path70.win32.isAbsolute(raw) || raw.startsWith("\\")) throw new BridgeError(400, "Invalid path.");
|
|
46340
46653
|
const segments = raw.split(/[\\/]/);
|
|
46341
46654
|
if (segments.includes("..") || segments.includes(".git")) throw new BridgeError(400, "Invalid path.");
|
|
46342
|
-
const
|
|
46343
|
-
if (!
|
|
46344
|
-
const abs = path70.resolve(root,
|
|
46655
|
+
const clean3 = segments.filter((part) => part && part !== ".").join("/");
|
|
46656
|
+
if (!clean3 && !allowRoot || clean3.startsWith("-")) throw new BridgeError(400, "Invalid path.");
|
|
46657
|
+
const abs = path70.resolve(root, clean3);
|
|
46345
46658
|
if (abs !== root && !abs.startsWith(root + path70.sep)) throw new BridgeError(403, "This path is outside the repository.");
|
|
46346
46659
|
let existing = abs;
|
|
46347
46660
|
while (true) {
|
|
@@ -46360,7 +46673,7 @@ async function repositoryPath(root, raw, allowRoot = false) {
|
|
|
46360
46673
|
throw new BridgeError(403, "This path cannot be resolved inside the repository.");
|
|
46361
46674
|
}
|
|
46362
46675
|
if (resolved !== root && !resolved.startsWith(root + path70.sep)) throw new BridgeError(403, "This path is outside the repository.");
|
|
46363
|
-
return
|
|
46676
|
+
return clean3;
|
|
46364
46677
|
}
|
|
46365
46678
|
function invalidateTree(root) {
|
|
46366
46679
|
treeCache.delete(root);
|
|
@@ -46408,7 +46721,7 @@ async function treeSnapshot(root, head) {
|
|
|
46408
46721
|
parent = full2;
|
|
46409
46722
|
}
|
|
46410
46723
|
}
|
|
46411
|
-
const version3 =
|
|
46724
|
+
const version3 = createHash20("sha256").update(head).update(tracked).update(porcelain).digest("hex");
|
|
46412
46725
|
return { version: version3, levels: new Map([...levels].map(([directory, entries2]) => [
|
|
46413
46726
|
directory,
|
|
46414
46727
|
[...entries2.values()].sort((a, b) => a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === "dir" ? -1 : 1)
|
|
@@ -46482,8 +46795,8 @@ async function repositoryPaths(root, raw, limit = 64) {
|
|
|
46482
46795
|
if (!list.length || list.length > limit) throw new BridgeError(400, `Choose between 1 and ${limit} paths.`);
|
|
46483
46796
|
const paths = [];
|
|
46484
46797
|
for (const entry2 of list) {
|
|
46485
|
-
const
|
|
46486
|
-
if (
|
|
46798
|
+
const clean3 = await repositoryPath(root, entry2);
|
|
46799
|
+
if (clean3 && !paths.includes(clean3)) paths.push(clean3);
|
|
46487
46800
|
}
|
|
46488
46801
|
if (!paths.length) throw new BridgeError(400, `Choose between 1 and ${limit} paths.`);
|
|
46489
46802
|
return paths;
|
|
@@ -46549,7 +46862,7 @@ var init_git = __esm({
|
|
|
46549
46862
|
"use strict";
|
|
46550
46863
|
init_protocol();
|
|
46551
46864
|
init_projects();
|
|
46552
|
-
exec12 = promisify12(
|
|
46865
|
+
exec12 = promisify12(execFile14);
|
|
46553
46866
|
UNKNOWN_COUNTS = { additions: 0, deletions: 0, countsComplete: false };
|
|
46554
46867
|
NO_DIFF2 = ["diff", "--no-ext-diff", "--no-textconv", "--no-color"];
|
|
46555
46868
|
MAX_STATUS_ROWS = 500;
|
|
@@ -46562,12 +46875,12 @@ var init_git = __esm({
|
|
|
46562
46875
|
});
|
|
46563
46876
|
|
|
46564
46877
|
// src/bridge/git-worktrees.ts
|
|
46565
|
-
import { createHash as
|
|
46878
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
46566
46879
|
import { realpath as realpath12, stat as stat18 } from "node:fs/promises";
|
|
46567
46880
|
import { homedir as homedir15 } from "node:os";
|
|
46568
46881
|
import path71 from "node:path";
|
|
46569
46882
|
function worktreeId(abs) {
|
|
46570
|
-
return
|
|
46883
|
+
return createHash21("sha256").update(`worktree\0${abs}`).digest("hex").slice(0, 32);
|
|
46571
46884
|
}
|
|
46572
46885
|
async function listed(root) {
|
|
46573
46886
|
const output2 = await git(root, "worktree", "list", "--porcelain", "-z");
|
|
@@ -46827,10 +47140,10 @@ var init_git_publish = __esm({
|
|
|
46827
47140
|
});
|
|
46828
47141
|
|
|
46829
47142
|
// src/bridge/approval-rules.ts
|
|
46830
|
-
import { execFile as
|
|
47143
|
+
import { execFile as execFile15 } from "node:child_process";
|
|
46831
47144
|
import { promisify as promisify13 } from "node:util";
|
|
46832
|
-
import { createHash as
|
|
46833
|
-
import { lstat as lstat24, mkdir as
|
|
47145
|
+
import { createHash as createHash22, createPublicKey, verify } from "node:crypto";
|
|
47146
|
+
import { lstat as lstat24, mkdir as mkdir20, readFile as readFile36, realpath as realpath13 } from "node:fs/promises";
|
|
46834
47147
|
import { hostname as hostname8 } from "node:os";
|
|
46835
47148
|
import path72 from "node:path";
|
|
46836
47149
|
async function git4(cwd, ...args) {
|
|
@@ -46857,7 +47170,7 @@ function verified(envelope, keys2) {
|
|
|
46857
47170
|
const key4 = createPublicKey({ key: Buffer.concat([Buffer.from("302a300506032b6570032100", "hex"), raw]), format: "der", type: "spki" });
|
|
46858
47171
|
if (!verify(null, payload, key4, signature)) throw forbidden();
|
|
46859
47172
|
const operation = operationSchema.parse(JSON.parse(payload.toString("utf8")));
|
|
46860
|
-
return { operation, owner:
|
|
47173
|
+
return { operation, owner: createHash22("sha256").update(raw).digest("hex") };
|
|
46861
47174
|
}
|
|
46862
47175
|
async function privateJSON(file4, fallback2, max = 2097152) {
|
|
46863
47176
|
const info = await lstat24(file4).catch((error62) => {
|
|
@@ -46889,7 +47202,7 @@ async function locked(root, work) {
|
|
|
46889
47202
|
const key4 = path72.resolve(root), previous = queues.get(key4) ?? Promise.resolve();
|
|
46890
47203
|
const next = previous.catch(() => {
|
|
46891
47204
|
}).then(async () => {
|
|
46892
|
-
await
|
|
47205
|
+
await mkdir20(key4, { recursive: true, mode: 448 });
|
|
46893
47206
|
const release = tryFileLock(policyPath(key4));
|
|
46894
47207
|
if (!release) throw new BridgeError(409, "Approval rules are busy. Try again.");
|
|
46895
47208
|
try {
|
|
@@ -46907,7 +47220,7 @@ async function locked(root, work) {
|
|
|
46907
47220
|
}
|
|
46908
47221
|
async function listApprovalRules(root = bridgeRoot(), pairedKey) {
|
|
46909
47222
|
try {
|
|
46910
|
-
const pairedOwner = pairedKey ?
|
|
47223
|
+
const pairedOwner = pairedKey ? createHash22("sha256").update(Buffer.from(pairedKey, "base64")).digest("hex") : void 0;
|
|
46911
47224
|
return [...(await readPolicy(root)).rules.values()].map((rule2) => ({
|
|
46912
47225
|
...rule2,
|
|
46913
47226
|
signerFingerprint: "SHA256:" + Buffer.from(rule2.owner, "hex").toString("base64").replace(/=+$/, ""),
|
|
@@ -46994,7 +47307,7 @@ var init_approval_rules = __esm({
|
|
|
46994
47307
|
init_home_paths();
|
|
46995
47308
|
init_locks();
|
|
46996
47309
|
init_protocol();
|
|
46997
|
-
exec13 = promisify13(
|
|
47310
|
+
exec13 = promisify13(execFile15);
|
|
46998
47311
|
text3 = external_exports.string().min(1).max(4096).refine((value2) => !/[\x00-\x1f\x7f]/.test(value2));
|
|
46999
47312
|
scopeSchema = external_exports.object({
|
|
47000
47313
|
project: text3.refine((value2) => path72.isAbsolute(value2) && path72.normalize(value2) === value2),
|
|
@@ -47151,7 +47464,7 @@ var init_codex_thread_origin = __esm({
|
|
|
47151
47464
|
});
|
|
47152
47465
|
|
|
47153
47466
|
// src/bridge/push.ts
|
|
47154
|
-
import { createCipheriv, createHmac as createHmac2, createPrivateKey, randomBytes as
|
|
47467
|
+
import { createCipheriv, createHmac as createHmac2, createPrivateKey, randomBytes as randomBytes4, sign } from "node:crypto";
|
|
47155
47468
|
import { readFile as readFile38, stat as stat19 } from "node:fs/promises";
|
|
47156
47469
|
import { connect as connect3 } from "node:http2";
|
|
47157
47470
|
import path76 from "node:path";
|
|
@@ -47254,7 +47567,7 @@ function upsertPushDevice(devices, value2) {
|
|
|
47254
47567
|
const device = deviceSchema.parse(value2);
|
|
47255
47568
|
return [...devices.filter((item) => item.deviceID !== device.deviceID), device].slice(-16);
|
|
47256
47569
|
}
|
|
47257
|
-
function relayCiphertext(key4, payload, nonce =
|
|
47570
|
+
function relayCiphertext(key4, payload, nonce = randomBytes4(12)) {
|
|
47258
47571
|
const aps = payload.aps ?? {};
|
|
47259
47572
|
let body2 = aps.alert?.body ?? "";
|
|
47260
47573
|
for (; ; ) {
|
|
@@ -47482,7 +47795,7 @@ var init_push = __esm({
|
|
|
47482
47795
|
});
|
|
47483
47796
|
|
|
47484
47797
|
// src/bridge/pair.ts
|
|
47485
|
-
import { execFile as
|
|
47798
|
+
import { execFile as execFile16 } from "node:child_process";
|
|
47486
47799
|
import { homedir as homedir16, hostname as hostname9, networkInterfaces, userInfo as userInfo4 } from "node:os";
|
|
47487
47800
|
import { promisify as promisify14 } from "node:util";
|
|
47488
47801
|
async function computerDisplayName() {
|
|
@@ -47498,9 +47811,10 @@ var init_pair = __esm({
|
|
|
47498
47811
|
"use strict";
|
|
47499
47812
|
init_zod();
|
|
47500
47813
|
init_computers();
|
|
47814
|
+
init_host_key();
|
|
47501
47815
|
init_install();
|
|
47502
47816
|
init_protocol();
|
|
47503
|
-
exec14 = promisify14(
|
|
47817
|
+
exec14 = promisify14(execFile16);
|
|
47504
47818
|
request5 = external_exports.object({
|
|
47505
47819
|
v: external_exports.literal(1),
|
|
47506
47820
|
publicKey: external_exports.string().max(512),
|
|
@@ -47513,7 +47827,7 @@ var init_pair = __esm({
|
|
|
47513
47827
|
|
|
47514
47828
|
// src/bridge/opencode-permissions.ts
|
|
47515
47829
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
47516
|
-
import { lstat as lstat25, mkdir as
|
|
47830
|
+
import { lstat as lstat25, mkdir as mkdir21, readFile as readFile39, rename as rename6, unlink as unlink6, writeFile as writeFile6 } from "node:fs/promises";
|
|
47517
47831
|
import path77 from "node:path";
|
|
47518
47832
|
function opencodeConfigPath(env = process.env, home = homeDir(env)) {
|
|
47519
47833
|
return path77.join(env.XDG_CONFIG_HOME || path77.join(home, ".config"), "opencode", "opencode.json");
|
|
@@ -47564,7 +47878,7 @@ async function allowOpencodeToolEverywhere(tool, file4 = opencodeConfigPath()) {
|
|
|
47564
47878
|
try {
|
|
47565
47879
|
const config3 = withAllowedTool(await readConfig2(file4), name);
|
|
47566
47880
|
const mode = (await lstat25(file4).catch(() => void 0))?.mode;
|
|
47567
|
-
await
|
|
47881
|
+
await mkdir21(path77.dirname(file4), { recursive: true, mode: 448 });
|
|
47568
47882
|
const temporary = `${file4}.${randomUUID16()}.tmp`;
|
|
47569
47883
|
await writeFile6(temporary, `${JSON.stringify(config3, null, 2)}
|
|
47570
47884
|
`, { mode: mode === void 0 ? 384 : mode & 511, flag: "wx" });
|
|
@@ -47589,7 +47903,7 @@ var init_opencode_permissions = __esm({
|
|
|
47589
47903
|
});
|
|
47590
47904
|
|
|
47591
47905
|
// src/bridge/prompt-deliveries.ts
|
|
47592
|
-
import { createHash as
|
|
47906
|
+
import { createHash as createHash23 } from "node:crypto";
|
|
47593
47907
|
import { readFileSync as readFileSync24 } from "node:fs";
|
|
47594
47908
|
import { open as open19 } from "node:fs/promises";
|
|
47595
47909
|
function promptKey(text5) {
|
|
@@ -47639,7 +47953,7 @@ var init_prompt_deliveries = __esm({
|
|
|
47639
47953
|
DELIVERY_GIVE_UP_MS = 3e4;
|
|
47640
47954
|
MAX_RECORDS = 512;
|
|
47641
47955
|
PICTURE_PATH_LINE = /^\s*\/.*\.(?:png|jpe?g|gif|webp)\s*$/i;
|
|
47642
|
-
promptHash = (text5) =>
|
|
47956
|
+
promptHash = (text5) => createHash23("sha256").update(promptKey(text5)).digest("hex");
|
|
47643
47957
|
recordSchema2 = external_exports.object({
|
|
47644
47958
|
id: external_exports.string().regex(/^[A-Za-z0-9_-]{8,64}$/).optional(),
|
|
47645
47959
|
hash: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
@@ -48176,7 +48490,7 @@ var init_opencode_pane_server = __esm({
|
|
|
48176
48490
|
});
|
|
48177
48491
|
|
|
48178
48492
|
// src/bridge/opencode-panes.ts
|
|
48179
|
-
import { execFile as
|
|
48493
|
+
import { execFile as execFile17 } from "node:child_process";
|
|
48180
48494
|
import path79 from "node:path";
|
|
48181
48495
|
import { promisify as promisify15 } from "node:util";
|
|
48182
48496
|
function paneServersDir() {
|
|
@@ -48312,7 +48626,7 @@ var init_opencode_panes = __esm({
|
|
|
48312
48626
|
init_opencode_pane_server();
|
|
48313
48627
|
init_protocol();
|
|
48314
48628
|
init_terminal();
|
|
48315
|
-
exec15 = promisify15(
|
|
48629
|
+
exec15 = promisify15(execFile17);
|
|
48316
48630
|
PANE_PORT_ENV = "PHREN_OPENCODE_PORT";
|
|
48317
48631
|
PASSWORD_ENV = "OPENCODE_SERVER_PASSWORD";
|
|
48318
48632
|
READY_MS = 2e4;
|
|
@@ -48415,8 +48729,8 @@ var init_opencode_panes = __esm({
|
|
|
48415
48729
|
});
|
|
48416
48730
|
|
|
48417
48731
|
// src/bridge/agent-hooks.ts
|
|
48418
|
-
import { request as request6, createServer as
|
|
48419
|
-
import { mkdir as
|
|
48732
|
+
import { request as request6, createServer as createServer3 } from "node:http";
|
|
48733
|
+
import { mkdir as mkdir22, readFile as readFile40, chmod as chmod4, unlink as unlink7, lstat as lstat26 } from "node:fs/promises";
|
|
48420
48734
|
import { watch } from "node:fs";
|
|
48421
48735
|
import path80 from "node:path";
|
|
48422
48736
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
@@ -48689,7 +49003,9 @@ var init_agent_hooks = __esm({
|
|
|
48689
49003
|
pushBindings = new PushBindingStore();
|
|
48690
49004
|
/** Held asks that were pushed: action -> when the notification expires. */
|
|
48691
49005
|
pushedHolds = /* @__PURE__ */ new Map();
|
|
48692
|
-
/**
|
|
49006
|
+
/** Held asks whose hold ended with the request left in the terminal, by
|
|
49007
|
+
* pane: the action keeps answering the pane's dialog, so a phone card,
|
|
49008
|
+
* notification or dispatcher holding it is not left with a dead id. */
|
|
48693
49009
|
releasedHolds = /* @__PURE__ */ new Map();
|
|
48694
49010
|
/** Terminal dialogs pushed to phones: by pane, the dialog last pushed; by
|
|
48695
49011
|
* action, what an answer from the notification types. */
|
|
@@ -48824,28 +49140,28 @@ var init_agent_hooks = __esm({
|
|
|
48824
49140
|
const key4 = paneKey2(entry2), where = { key: key4, server: entry2.server, pane: entry2.pane };
|
|
48825
49141
|
const expiresAt = Date.now() + SERVED_ASK_MS;
|
|
48826
49142
|
const permissions = /* @__PURE__ */ new Set();
|
|
48827
|
-
for (const
|
|
48828
|
-
if (typeof
|
|
48829
|
-
permissions.add(
|
|
48830
|
-
const known2 = this.opencode.get(
|
|
49143
|
+
for (const ask2 of asks.permissions) {
|
|
49144
|
+
if (typeof ask2.id !== "string" || !/^[A-Za-z0-9_]{1,200}$/.test(ask2.id)) continue;
|
|
49145
|
+
permissions.add(ask2.id);
|
|
49146
|
+
const known2 = this.opencode.get(ask2.id);
|
|
48831
49147
|
if (known2) {
|
|
48832
49148
|
if (known2.served?.key === key4) {
|
|
48833
49149
|
known2.expiresAt = expiresAt;
|
|
48834
49150
|
known2.request.expiresAt = new Date(expiresAt).toISOString();
|
|
48835
|
-
this.pushBindings.extendAction(
|
|
49151
|
+
this.pushBindings.extendAction(ask2.id, expiresAt);
|
|
48836
49152
|
}
|
|
48837
49153
|
continue;
|
|
48838
49154
|
}
|
|
48839
|
-
const target = await this.servedTarget(entry2, client,
|
|
49155
|
+
const target = await this.servedTarget(entry2, client, ask2.sessionID).catch(() => void 0);
|
|
48840
49156
|
if (this.closed) return;
|
|
48841
|
-
const type = typeof
|
|
48842
|
-
const patterns = (Array.isArray(
|
|
48843
|
-
const metadata = object2(
|
|
49157
|
+
const type = typeof ask2.permission === "string" && ask2.permission ? ask2.permission.slice(0, 200) : "action";
|
|
49158
|
+
const patterns = (Array.isArray(ask2.patterns) ? ask2.patterns : []).filter((value2) => typeof value2 === "string").slice(0, 32);
|
|
49159
|
+
const metadata = object2(ask2.metadata);
|
|
48844
49160
|
const detail = [patterns.join(", "), metadata.command, metadata.description, metadata.filepath, metadata.path, metadata.url].find((value2) => typeof value2 === "string" && !!value2);
|
|
48845
49161
|
const message = (detail ? `${type}: ${detail}` : `opencode asks to use ${type}.`).slice(0, 2e3);
|
|
48846
49162
|
const request9 = {
|
|
48847
|
-
id:
|
|
48848
|
-
sessionID:
|
|
49163
|
+
id: ask2.id,
|
|
49164
|
+
sessionID: ask2.sessionID,
|
|
48849
49165
|
type,
|
|
48850
49166
|
title: `Allow ${type}?`,
|
|
48851
49167
|
message,
|
|
@@ -48854,10 +49170,10 @@ var init_agent_hooks = __esm({
|
|
|
48854
49170
|
expiresAt: new Date(expiresAt).toISOString()
|
|
48855
49171
|
};
|
|
48856
49172
|
const summary = approvalSummary({ tool: type, input: request9, message, cwd: entry2.directory });
|
|
48857
|
-
this.opencode.set(
|
|
49173
|
+
this.opencode.set(ask2.id, { ...target ? { target } : {}, request: request9, requestLine: summary.request, expiresAt, served: where });
|
|
48858
49174
|
if (!this.push.available) continue;
|
|
48859
49175
|
const binding = randomUUID17();
|
|
48860
|
-
this.pushBindings.add(binding, { action:
|
|
49176
|
+
this.pushBindings.add(binding, { action: ask2.id, expiresAt });
|
|
48861
49177
|
void this.push.notify({
|
|
48862
49178
|
binding,
|
|
48863
49179
|
provider: "opencode",
|
|
@@ -48867,7 +49183,7 @@ var init_agent_hooks = __esm({
|
|
|
48867
49183
|
computer: this.computerName,
|
|
48868
49184
|
...summary
|
|
48869
49185
|
}).then((delivered) => {
|
|
48870
|
-
if (!delivered) this.pushBindings.dropAction(
|
|
49186
|
+
if (!delivered) this.pushBindings.dropAction(ask2.id);
|
|
48871
49187
|
}).catch(() => {
|
|
48872
49188
|
});
|
|
48873
49189
|
}
|
|
@@ -48878,16 +49194,16 @@ var init_agent_hooks = __esm({
|
|
|
48878
49194
|
}
|
|
48879
49195
|
}
|
|
48880
49196
|
const questions = /* @__PURE__ */ new Set();
|
|
48881
|
-
for (const
|
|
48882
|
-
if (typeof
|
|
48883
|
-
questions.add(
|
|
48884
|
-
if (this.servedQuestions.has(
|
|
48885
|
-
const raw = Array.isArray(
|
|
49197
|
+
for (const ask2 of asks.questions) {
|
|
49198
|
+
if (typeof ask2.id !== "string" || !/^[A-Za-z0-9_]{1,200}$/.test(ask2.id)) continue;
|
|
49199
|
+
questions.add(ask2.id);
|
|
49200
|
+
if (this.servedQuestions.has(ask2.id)) continue;
|
|
49201
|
+
const raw = Array.isArray(ask2.questions) ? ask2.questions : [];
|
|
48886
49202
|
const mapped = terminalQuestions({ questions: raw.map((value2) => ({ ...object2(value2), multiSelect: object2(value2).multiple === true })) });
|
|
48887
49203
|
if (!mapped || mapped.length !== raw.length) continue;
|
|
48888
|
-
const target = await this.servedTarget(entry2, client,
|
|
49204
|
+
const target = await this.servedTarget(entry2, client, ask2.sessionID).catch(() => void 0);
|
|
48889
49205
|
if (this.closed) return;
|
|
48890
|
-
this.servedQuestions.set(
|
|
49206
|
+
this.servedQuestions.set(ask2.id, { ...where, ...target ? { target } : {}, question: ask2, questions: mapped, at: Date.now() });
|
|
48891
49207
|
while (this.servedQuestions.size > 64) this.servedQuestions.delete(this.servedQuestions.keys().next().value);
|
|
48892
49208
|
}
|
|
48893
49209
|
for (const [id2, held] of this.servedQuestions) if (held.key === key4 && !questions.has(id2)) this.servedQuestions.delete(id2);
|
|
@@ -49492,7 +49808,7 @@ var init_agent_hooks = __esm({
|
|
|
49492
49808
|
this.pushBindings.dropAction(id2);
|
|
49493
49809
|
}
|
|
49494
49810
|
async answer(target, id2, decision, updatedInput) {
|
|
49495
|
-
if (id2.startsWith("dialog-")) {
|
|
49811
|
+
if (id2.startsWith("dialog-") || !this.pending.has(id2) && await this.releasedHoldDialog(id2)) {
|
|
49496
49812
|
const dialog = this.dialogActions.get(id2);
|
|
49497
49813
|
if (!dialog || JSON.stringify(dialog.target) !== JSON.stringify(target)) throw new BridgeError(409, "This approval is no longer pending.");
|
|
49498
49814
|
if (updatedInput !== void 0 || !["approve", "deny"].includes(String(decision))) throw new BridgeError(400, "The approval answer is not valid.");
|
|
@@ -49605,15 +49921,7 @@ var init_agent_hooks = __esm({
|
|
|
49605
49921
|
await this.answer(pending.target, linked.action, decision);
|
|
49606
49922
|
return;
|
|
49607
49923
|
}
|
|
49608
|
-
|
|
49609
|
-
if (released && !this.dialogActions.has(linked.action)) {
|
|
49610
|
-
const target = JSON.parse(released[0]);
|
|
49611
|
-
await this.syncTerminalDialog(target, true).catch(() => {
|
|
49612
|
-
});
|
|
49613
|
-
const entry2 = this.terminalPrompts.get(released[0]);
|
|
49614
|
-
if (entry2?.choice?.title) this.adoptReleasedHold(released[0], target, entry2.choice, entry2.choice.title);
|
|
49615
|
-
}
|
|
49616
|
-
if (this.dialogActions.has(linked.action)) {
|
|
49924
|
+
if (await this.releasedHoldDialog(linked.action)) {
|
|
49617
49925
|
await this.answerDialog(linked.action, decision);
|
|
49618
49926
|
return;
|
|
49619
49927
|
}
|
|
@@ -49632,6 +49940,20 @@ var init_agent_hooks = __esm({
|
|
|
49632
49940
|
}
|
|
49633
49941
|
throw new BridgeError(409, "This approval is no longer pending.");
|
|
49634
49942
|
}
|
|
49943
|
+
/** Whether this action now answers a terminal dialog: a released hold's
|
|
49944
|
+
* pane is read at once rather than at the next tick, and its dialog
|
|
49945
|
+
* adopted under the hold's own action. */
|
|
49946
|
+
async releasedHoldDialog(action) {
|
|
49947
|
+
const released = [...this.releasedHolds].find(([, hold]) => hold.action === action);
|
|
49948
|
+
if (released && !this.dialogActions.has(action)) {
|
|
49949
|
+
const target = JSON.parse(released[0]);
|
|
49950
|
+
await this.syncTerminalDialog(target, true).catch(() => {
|
|
49951
|
+
});
|
|
49952
|
+
const entry2 = this.terminalPrompts.get(released[0]);
|
|
49953
|
+
if (entry2?.choice?.title) this.adoptReleasedHold(released[0], target, entry2.choice, entry2.choice.title);
|
|
49954
|
+
}
|
|
49955
|
+
return this.dialogActions.has(action);
|
|
49956
|
+
}
|
|
49635
49957
|
/** Where a pushed ask lives, without answering it: the phone opens that
|
|
49636
49958
|
* session's details when the notification itself is tapped. */
|
|
49637
49959
|
pushTarget(binding) {
|
|
@@ -49687,6 +50009,15 @@ var init_agent_hooks = __esm({
|
|
|
49687
50009
|
if (!delivered) this.dropDialogPush(key4);
|
|
49688
50010
|
}).catch(() => this.dropDialogPush(key4));
|
|
49689
50011
|
}
|
|
50012
|
+
const horizon = Date.now() + DIALOG_PUSH_MS;
|
|
50013
|
+
for (const key4 of waiting) {
|
|
50014
|
+
const hold = this.releasedHolds.get(key4);
|
|
50015
|
+
if (hold && hold.expiresAt > Date.now()) hold.expiresAt = Math.max(hold.expiresAt, horizon);
|
|
50016
|
+
for (const action of [this.dialogPushes.get(key4)?.action, this.forwardedDialogs.get(key4)?.action]) {
|
|
50017
|
+
const dialog = action ? this.dialogActions.get(action) : void 0;
|
|
50018
|
+
if (dialog && dialog.expiresAt > Date.now()) dialog.expiresAt = Math.max(dialog.expiresAt, horizon);
|
|
50019
|
+
}
|
|
50020
|
+
}
|
|
49690
50021
|
for (const [key4, hold] of this.releasedHolds) {
|
|
49691
50022
|
if (!waiting.has(key4) && JSON.parse(key4).server === server || hold.expiresAt <= Date.now()) {
|
|
49692
50023
|
this.dropPushBindings(hold.action);
|
|
@@ -49755,9 +50086,10 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49755
50086
|
const key4 = JSON.stringify(target), entry2 = this.terminalPrompts.get(key4);
|
|
49756
50087
|
const title2 = entry2 && (entry2.dialog || entry2.released) ? entry2.choice?.title : void 0;
|
|
49757
50088
|
if (!entry2?.choice || !title2) return void 0;
|
|
50089
|
+
this.adoptReleasedHold(key4, target, entry2.choice, title2);
|
|
49758
50090
|
const pushedDialog = this.dialogPushes.get(key4);
|
|
49759
50091
|
const pushedAction = pushedDialog && this.dialogActions.get(pushedDialog.action);
|
|
49760
|
-
let action = pushedDialog?.title === title2 && pushedAction && pushedAction.choice.body === entry2.choice.body ? pushedDialog.action : void 0;
|
|
50092
|
+
let action = pushedDialog?.title === title2 && pushedAction && pushedAction.choice.body === entry2.choice.body && pushedAction.expiresAt > Date.now() ? pushedDialog.action : void 0;
|
|
49761
50093
|
if (!action) {
|
|
49762
50094
|
const known2 = this.forwardedDialogs.get(key4);
|
|
49763
50095
|
if (known2?.title === title2 && known2.body === entry2.choice.body && (this.dialogActions.get(known2.action)?.expiresAt ?? 0) > Date.now()) action = known2.action;
|
|
@@ -49811,13 +50143,25 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49811
50143
|
if (!delivered) drop();
|
|
49812
50144
|
}).catch(drop);
|
|
49813
50145
|
}
|
|
50146
|
+
/** Moves a released hold onto the dialog its pane now draws, under the
|
|
50147
|
+
* hold's action: as the pushed dialog when its notification is on the
|
|
50148
|
+
* phone, else as the dialog offered to a dispatching Hook. True when the
|
|
50149
|
+
* hold was pushed, so the dialog needs no second notification. */
|
|
49814
50150
|
adoptReleasedHold(key4, target, choice, title2) {
|
|
49815
50151
|
const hold = this.releasedHolds.get(key4);
|
|
50152
|
+
if (!hold) return false;
|
|
49816
50153
|
this.releasedHolds.delete(key4);
|
|
49817
|
-
if (
|
|
49818
|
-
|
|
50154
|
+
if (hold.expiresAt <= Date.now()) {
|
|
50155
|
+
this.dropPushBindings(hold.action);
|
|
50156
|
+
return false;
|
|
50157
|
+
}
|
|
49819
50158
|
this.dialogActions.set(hold.action, { target, choice, expiresAt: hold.expiresAt });
|
|
49820
|
-
|
|
50159
|
+
if (hold.pushed) this.dialogPushes.set(key4, { action: hold.action, title: title2 });
|
|
50160
|
+
else {
|
|
50161
|
+
this.dropForwardedDialog(key4);
|
|
50162
|
+
this.forwardedDialogs.set(key4, { action: hold.action, title: title2, body: choice.body });
|
|
50163
|
+
}
|
|
50164
|
+
return hold.pushed;
|
|
49821
50165
|
}
|
|
49822
50166
|
dropDialogPush(key4) {
|
|
49823
50167
|
const pushed = this.dialogPushes.get(key4);
|
|
@@ -49933,7 +50277,7 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49933
50277
|
if (!previous.isSocket() || previous.uid !== process.getuid?.()) throw new Error("Unexpected agent callback socket.");
|
|
49934
50278
|
await unlink7(localSocket());
|
|
49935
50279
|
}
|
|
49936
|
-
this.server =
|
|
50280
|
+
this.server = createServer3(async (req, res) => {
|
|
49937
50281
|
res.setHeader("Content-Type", "application/json");
|
|
49938
50282
|
try {
|
|
49939
50283
|
if (req.method === "POST" && req.url === "/sudo") {
|
|
@@ -50115,7 +50459,8 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50115
50459
|
released = true;
|
|
50116
50460
|
this.pending.delete(action);
|
|
50117
50461
|
this.rememberTerminalPrompt(target, body2);
|
|
50118
|
-
|
|
50462
|
+
const pushed = this.pushedHolds.get(action);
|
|
50463
|
+
this.releasedHolds.set(JSON.stringify(target), { action, expiresAt: pushed ?? Date.now() + DIALOG_PUSH_MS, pushed: pushed !== void 0 });
|
|
50119
50464
|
this.pushedHolds.delete(action);
|
|
50120
50465
|
res.end("{}");
|
|
50121
50466
|
}, APPROVAL_HOLD_MS);
|
|
@@ -50177,7 +50522,7 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50177
50522
|
this.server.listen(localSocket(), () => resolve14());
|
|
50178
50523
|
});
|
|
50179
50524
|
await chmod4(localSocket(), 384);
|
|
50180
|
-
await
|
|
50525
|
+
await mkdir22(this.approvalsDirectory(), { recursive: true, mode: 448 }).catch(() => {
|
|
50181
50526
|
});
|
|
50182
50527
|
try {
|
|
50183
50528
|
this.opencodeWatcher = watch(this.approvalsDirectory(), { persistent: false }, () => this.scheduleOpencodeSweep());
|
|
@@ -51110,7 +51455,7 @@ var init_permission_mode = __esm({
|
|
|
51110
51455
|
});
|
|
51111
51456
|
|
|
51112
51457
|
// src/bridge/session-servers.ts
|
|
51113
|
-
import { execFile as
|
|
51458
|
+
import { execFile as execFile18 } from "node:child_process";
|
|
51114
51459
|
import { open as open20, stat as stat21 } from "node:fs/promises";
|
|
51115
51460
|
import { promisify as promisify16 } from "node:util";
|
|
51116
51461
|
function mentionedPorts(text5) {
|
|
@@ -51209,7 +51554,7 @@ var init_session_servers = __esm({
|
|
|
51209
51554
|
init_terminal();
|
|
51210
51555
|
init_projects();
|
|
51211
51556
|
init_transcripts();
|
|
51212
|
-
exec16 = promisify16(
|
|
51557
|
+
exec16 = promisify16(execFile18);
|
|
51213
51558
|
MAX_DEPTH = 64;
|
|
51214
51559
|
TRANSCRIPT_TAIL_BYTES = 1048576;
|
|
51215
51560
|
MAX_OTHER_PANES = 48;
|
|
@@ -51218,7 +51563,7 @@ var init_session_servers = __esm({
|
|
|
51218
51563
|
});
|
|
51219
51564
|
|
|
51220
51565
|
// src/bridge/uploads.ts
|
|
51221
|
-
import { mkdir as
|
|
51566
|
+
import { mkdir as mkdir23, readdir as readdir16, lstat as lstat27, realpath as realpath14, readFile as readFile42, stat as stat22, unlink as unlink8, writeFile as writeFile7 } from "node:fs/promises";
|
|
51222
51567
|
import path82 from "node:path";
|
|
51223
51568
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
51224
51569
|
function imageBytes(bytes) {
|
|
@@ -51231,7 +51576,7 @@ async function saveUpload(session, name, bytes) {
|
|
|
51231
51576
|
const task = uploadQueue.catch(() => {
|
|
51232
51577
|
}).then(async () => {
|
|
51233
51578
|
const root = path82.join(bridgeRoot(), "uploads");
|
|
51234
|
-
await
|
|
51579
|
+
await mkdir23(root, { recursive: true, mode: 448 });
|
|
51235
51580
|
let used = 0;
|
|
51236
51581
|
const directories = await readdir16(root, { withFileTypes: true });
|
|
51237
51582
|
for (const dir of directories) {
|
|
@@ -51246,7 +51591,7 @@ async function saveUpload(session, name, bytes) {
|
|
|
51246
51591
|
}
|
|
51247
51592
|
if (used + bytes.length > 268435456) throw new BridgeError(413, "Phren's image storage is full. Remove older uploads on the computer.");
|
|
51248
51593
|
const folder = path82.join(root, session);
|
|
51249
|
-
await
|
|
51594
|
+
await mkdir23(folder, { recursive: true, mode: 448 });
|
|
51250
51595
|
saved = path82.join(folder, `${randomUUID19()}-${name}`);
|
|
51251
51596
|
await writeFile7(saved, bytes, { flag: "wx", mode: 384 });
|
|
51252
51597
|
});
|
|
@@ -51929,7 +52274,7 @@ async function driveOpencode(child, o) {
|
|
|
51929
52274
|
const family = /* @__PURE__ */ new Set([session]);
|
|
51930
52275
|
let error62, busy = false, asks = Promise.resolve();
|
|
51931
52276
|
const stop = new AbortController();
|
|
51932
|
-
const
|
|
52277
|
+
const ask2 = async (asked) => {
|
|
51933
52278
|
if (asked.permission === "doom_loop") {
|
|
51934
52279
|
await call("POST", `/permission/${encodeURIComponent(asked.id)}/reply`, { reply: "once" });
|
|
51935
52280
|
return;
|
|
@@ -51982,7 +52327,7 @@ ${message}` : message;
|
|
|
51982
52327
|
permission: String(p.permission ?? "action"),
|
|
51983
52328
|
patterns: Array.isArray(p.patterns) ? p.patterns.filter((value3) => typeof value3 === "string") : []
|
|
51984
52329
|
};
|
|
51985
|
-
asks = asks.then(() =>
|
|
52330
|
+
asks = asks.then(() => ask2(asked)).catch((failure2) => {
|
|
51986
52331
|
error62 = String(failure2);
|
|
51987
52332
|
});
|
|
51988
52333
|
}
|
|
@@ -52145,7 +52490,7 @@ __export(launcher_exports, {
|
|
|
52145
52490
|
writeManifest: () => writeManifest2
|
|
52146
52491
|
});
|
|
52147
52492
|
import { spawn as spawn11, execFileSync as execFileSync4 } from "node:child_process";
|
|
52148
|
-
import { randomBytes as
|
|
52493
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
52149
52494
|
import * as fs25 from "node:fs";
|
|
52150
52495
|
import * as path86 from "node:path";
|
|
52151
52496
|
function jobsRoot(store) {
|
|
@@ -52201,7 +52546,7 @@ function createJob(options, env = process.env, nearest = nearestAgent) {
|
|
|
52201
52546
|
if (!options.label.trim() || options.label.length > 200) throw new Error("Choose a label of 1 to 200 characters.");
|
|
52202
52547
|
const worktree = fs25.realpathSync(options.worktree);
|
|
52203
52548
|
if (!fs25.statSync(worktree).isDirectory()) throw new Error("Choose a worktree directory.");
|
|
52204
|
-
const id2 = `${options.provider}-${
|
|
52549
|
+
const id2 = `${options.provider}-${randomBytes6(12).toString("hex")}`;
|
|
52205
52550
|
const root = jobsRoot(options.store), job = path86.join(root, id2);
|
|
52206
52551
|
fs25.mkdirSync(job, { recursive: true, mode: 448 });
|
|
52207
52552
|
fs25.chmodSync(root, 448);
|
|
@@ -52234,7 +52579,7 @@ async function launch(options, reservation = createJob(options)) {
|
|
|
52234
52579
|
const { job, manifest } = reservation, adapter = adapters[options.provider];
|
|
52235
52580
|
console.log(job);
|
|
52236
52581
|
const out = fs25.openSync(path86.join(job, manifest.eventLog), "a"), err = fs25.openSync(path86.join(job, "stderr.log"), "a");
|
|
52237
|
-
const password =
|
|
52582
|
+
const password = randomBytes6(24).toString("hex");
|
|
52238
52583
|
const child = spawn11("nice", ["-n", "15", adapter.command, ...adapter.argv({ ...options, job })], {
|
|
52239
52584
|
cwd: manifest.worktree,
|
|
52240
52585
|
env: {
|
|
@@ -52357,7 +52702,7 @@ var init_launcher = __esm({
|
|
|
52357
52702
|
|
|
52358
52703
|
// src/bridge/fanout-messages.ts
|
|
52359
52704
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
52360
|
-
import { appendFile as appendFile2, lstat as lstat28, mkdir as
|
|
52705
|
+
import { appendFile as appendFile2, lstat as lstat28, mkdir as mkdir24, readdir as readdir17, readFile as readFile43, realpath as realpath15, rename as rename7, rm as rm10, writeFile as writeFile8 } from "node:fs/promises";
|
|
52361
52706
|
import path87 from "node:path";
|
|
52362
52707
|
var fanoutMessageSchema, receiptSchema2, FanoutMessages;
|
|
52363
52708
|
var init_fanout_messages = __esm({
|
|
@@ -52458,7 +52803,7 @@ var init_fanout_messages = __esm({
|
|
|
52458
52803
|
}
|
|
52459
52804
|
async messageDirectory(job) {
|
|
52460
52805
|
const directory = path87.join(job.directory, "messages");
|
|
52461
|
-
await
|
|
52806
|
+
await mkdir24(directory, { recursive: true, mode: 448 });
|
|
52462
52807
|
if (await realpath15(directory) !== directory) throw new BridgeError(400, "Invalid worker message directory.");
|
|
52463
52808
|
return directory;
|
|
52464
52809
|
}
|
|
@@ -52497,7 +52842,7 @@ var init_fanout_messages = __esm({
|
|
|
52497
52842
|
async drain(job) {
|
|
52498
52843
|
const lock = path87.join(job.directory, "message-lock");
|
|
52499
52844
|
try {
|
|
52500
|
-
await
|
|
52845
|
+
await mkdir24(lock, { mode: 448 });
|
|
52501
52846
|
} catch {
|
|
52502
52847
|
return;
|
|
52503
52848
|
}
|
|
@@ -52517,10 +52862,10 @@ var init_fanout_messages = __esm({
|
|
|
52517
52862
|
if (info && (!info.isFile() || info.isSymbolicLink())) throw new BridgeError(400, "Invalid worker output file.");
|
|
52518
52863
|
}
|
|
52519
52864
|
const round = path87.join(fresh.directory, "rounds");
|
|
52520
|
-
await
|
|
52865
|
+
await mkdir24(round, { recursive: true, mode: 448 });
|
|
52521
52866
|
if (await realpath15(round) !== round) throw new BridgeError(400, "Invalid worker round directory.");
|
|
52522
52867
|
const roundDir = path87.join(round, next.message.id);
|
|
52523
|
-
await
|
|
52868
|
+
await mkdir24(roundDir, { mode: 448 });
|
|
52524
52869
|
await writeFile8(path87.join(roundDir, "prompt.txt"), next.message.text, { mode: 384 });
|
|
52525
52870
|
for (const name of ["stderr.log", "final.txt", "exit.txt", "blocked.json", "prompt.txt"]) {
|
|
52526
52871
|
await rename7(path87.join(fresh.directory, name), path87.join(roundDir, `previous-${name}`)).catch((error62) => {
|
|
@@ -53372,7 +53717,7 @@ var init_speech_transcribe = __esm({
|
|
|
53372
53717
|
});
|
|
53373
53718
|
|
|
53374
53719
|
// src/bridge/activity.ts
|
|
53375
|
-
import { appendFile as appendFile3, mkdir as
|
|
53720
|
+
import { appendFile as appendFile3, mkdir as mkdir25, readFile as readFile44, rename as rename8, stat as stat23 } from "node:fs/promises";
|
|
53376
53721
|
import path88 from "node:path";
|
|
53377
53722
|
var ActivityJournal;
|
|
53378
53723
|
var init_activity2 = __esm({
|
|
@@ -53406,7 +53751,7 @@ var init_activity2 = __esm({
|
|
|
53406
53751
|
}
|
|
53407
53752
|
if (!changes.length) return;
|
|
53408
53753
|
const root = bridgeRoot(), file4 = path88.join(root, "activity.jsonl");
|
|
53409
|
-
await
|
|
53754
|
+
await mkdir25(root, { recursive: true, mode: 448 });
|
|
53410
53755
|
if ((await stat23(file4).catch(() => null))?.size && (await stat23(file4)).size > 2097152) await rename8(file4, file4 + ".previous");
|
|
53411
53756
|
await appendFile3(file4, changes.map((row) => JSON.stringify(row)).join("\n") + "\n", { mode: 384 });
|
|
53412
53757
|
if (this.previous.size > 4096) this.previous.clear();
|
|
@@ -54098,9 +54443,9 @@ var init_context = __esm({
|
|
|
54098
54443
|
});
|
|
54099
54444
|
|
|
54100
54445
|
// src/bridge/questions.ts
|
|
54101
|
-
import { execFile as
|
|
54102
|
-
import { createHash as
|
|
54103
|
-
import { mkdir as
|
|
54446
|
+
import { execFile as execFile19 } from "node:child_process";
|
|
54447
|
+
import { createHash as createHash24 } from "node:crypto";
|
|
54448
|
+
import { mkdir as mkdir26, open as open22, stat as stat24, readFile as readFile45, writeFile as writeFile9 } from "node:fs/promises";
|
|
54104
54449
|
import path91 from "node:path";
|
|
54105
54450
|
import { promisify as promisify17 } from "node:util";
|
|
54106
54451
|
function asyncQuestion(raw, id2) {
|
|
@@ -54264,14 +54609,14 @@ var init_questions = __esm({
|
|
|
54264
54609
|
init_transcript_index();
|
|
54265
54610
|
init_codex_question_reply();
|
|
54266
54611
|
init_uploads();
|
|
54267
|
-
exec17 = promisify17(
|
|
54612
|
+
exec17 = promisify17(execFile19);
|
|
54268
54613
|
text4 = external_exports.string().trim().min(1).max(4e3).refine((t) => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t));
|
|
54269
54614
|
question = external_exports.object({ title: text4, options: external_exports.array(text4).max(12).nullable().optional() });
|
|
54270
54615
|
questionSet = external_exports.array(question).min(1).max(8);
|
|
54271
54616
|
answersQuestions = (reply, questions) => questions.every((q) => {
|
|
54272
|
-
const
|
|
54273
|
-
const index2 = reply.indexOf(
|
|
54274
|
-
return index2 >= 0 && reply.slice(index2 +
|
|
54617
|
+
const quote6 = q.title.split("\n").map((line) => `> ${line}`).join("\n") + "\n\n";
|
|
54618
|
+
const index2 = reply.indexOf(quote6);
|
|
54619
|
+
return index2 >= 0 && reply.slice(index2 + quote6.length).trim().length > 0;
|
|
54275
54620
|
});
|
|
54276
54621
|
attachedFiles = (paths) => paths.length ? `Attached files on this computer:
|
|
54277
54622
|
${paths.join("\n")}` : "";
|
|
@@ -54342,7 +54687,7 @@ ${attachedFiles(paths)}` : answer;
|
|
|
54342
54687
|
this.snapshots.set(target.session, { at: Date.now(), stamp: stamp2, pending });
|
|
54343
54688
|
}
|
|
54344
54689
|
return Promise.all((pending ?? []).map(async (p) => {
|
|
54345
|
-
const key4 =
|
|
54690
|
+
const key4 = createHash24("sha256").update(JSON.stringify([target.source, target.session, p.id])).digest("hex");
|
|
54346
54691
|
const submitted = await readFile45(path91.join(bridgeRoot(), "question-replies", key4), "utf8").then((value2) => value2 === "submitted").catch(() => false);
|
|
54347
54692
|
return { toolUseId: p.id, isAsync: true, submitted, questions: asPrompt(p.questions) };
|
|
54348
54693
|
})).then((prompts) => prompts.filter((p) => !p.submitted));
|
|
@@ -54377,8 +54722,8 @@ ${attachedFiles(paths)}` : answer;
|
|
|
54377
54722
|
const pane = await validateTarget(target);
|
|
54378
54723
|
if (await paneIdentity(target.server, pane, true) !== target.session) throw new BridgeError(409, "This pane's conversation changed. Reopen the chat.");
|
|
54379
54724
|
const directory = path91.join(bridgeRoot(), "question-replies");
|
|
54380
|
-
await
|
|
54381
|
-
const key4 =
|
|
54725
|
+
await mkdir26(directory, { recursive: true, mode: 448 });
|
|
54726
|
+
const key4 = createHash24("sha256").update(JSON.stringify([target.source, target.session, id2])).digest("hex");
|
|
54382
54727
|
const receiptPath = path91.join(directory, key4);
|
|
54383
54728
|
const receipt = await open22(receiptPath, "wx", 384).catch((error62) => {
|
|
54384
54729
|
if (error62.code === "EEXIST") throw new BridgeError(409, "An answer was already submitted. Check the conversation before answering again.");
|
|
@@ -54892,7 +55237,7 @@ var init_job_registry = __esm({
|
|
|
54892
55237
|
});
|
|
54893
55238
|
|
|
54894
55239
|
// src/bridge/resources.ts
|
|
54895
|
-
import { execFile as
|
|
55240
|
+
import { execFile as execFile20 } from "node:child_process";
|
|
54896
55241
|
import { readdir as readdir18, readFile as readFile46, statfs } from "node:fs/promises";
|
|
54897
55242
|
import { cpus, loadavg, totalmem, uptime } from "node:os";
|
|
54898
55243
|
import path93 from "node:path";
|
|
@@ -54904,12 +55249,12 @@ function parseMacHardware(json2) {
|
|
|
54904
55249
|
return { ...model ? { model } : {}, ...chip ? { chip } : {} };
|
|
54905
55250
|
}
|
|
54906
55251
|
function linuxModel(vendor, product, version3) {
|
|
54907
|
-
const
|
|
55252
|
+
const clean3 = (value2) => {
|
|
54908
55253
|
const text5 = value2?.replace(/\s+/g, " ").trim();
|
|
54909
55254
|
return text5 && !/^(to be filled|default string|system (product name|manufacturer)|not specified|none|o\.e\.m\.?|unknown)/i.test(text5) ? text5 : void 0;
|
|
54910
55255
|
};
|
|
54911
|
-
const brand =
|
|
54912
|
-
const name = brand === "LENOVO" || brand === "Lenovo" ?
|
|
55256
|
+
const brand = clean3(vendor)?.replace(/,?\s+(Inc\.?|Corporation|Corp\.?|Co\.,? Ltd\.?|Ltd\.?|GmbH|Technology)$/i, "");
|
|
55257
|
+
const name = brand === "LENOVO" || brand === "Lenovo" ? clean3(version3) ?? clean3(product) : clean3(product);
|
|
54913
55258
|
if (!name) return brand;
|
|
54914
55259
|
const label2 = brand && !name.toLowerCase().startsWith(brand.toLowerCase()) ? `${brand === "LENOVO" ? "Lenovo" : brand} ${name}` : name;
|
|
54915
55260
|
return label2.slice(0, 80);
|
|
@@ -55255,7 +55600,7 @@ var init_resources = __esm({
|
|
|
55255
55600
|
init_job_registry();
|
|
55256
55601
|
init_limits();
|
|
55257
55602
|
init_protocol();
|
|
55258
|
-
exec18 = promisify18(
|
|
55603
|
+
exec18 = promisify18(execFile20);
|
|
55259
55604
|
RESOURCES_MAX_AGE_MS = intervalFromEnv("PHREN_RESOURCES_MAX_AGE_MS", 1e4, 1e3, 6e4);
|
|
55260
55605
|
LOW_DISK_BYTES = 10 * 1024 ** 3;
|
|
55261
55606
|
GB = 1024 ** 3;
|
|
@@ -55617,7 +55962,7 @@ function taskWriterSafety(base) {
|
|
|
55617
55962
|
...status.acknowledgedAt ? { acknowledgedAt: status.acknowledgedAt } : {}
|
|
55618
55963
|
};
|
|
55619
55964
|
}
|
|
55620
|
-
var file3, taskFormatMigrationHint;
|
|
55965
|
+
var file3, taskFormatCurrentWriters, taskFormatMigrationHint;
|
|
55621
55966
|
var init_task_format = __esm({
|
|
55622
55967
|
"src/data/task-format.ts"() {
|
|
55623
55968
|
"use strict";
|
|
@@ -55626,7 +55971,8 @@ var init_task_format = __esm({
|
|
|
55626
55971
|
init_rbac();
|
|
55627
55972
|
init_store_registry();
|
|
55628
55973
|
file3 = (base) => path96.join(base, ".config", "task-format.json");
|
|
55629
|
-
|
|
55974
|
+
taskFormatCurrentWriters = "Phren CLI, MCP and Hook 0.3.30, iOS build 177, Android 1.0.5";
|
|
55975
|
+
taskFormatMigrationHint = `Task metadata is off for this store. Once every app and tool that writes it is current (${taskFormatCurrentWriters} or later), an owner can turn it on with phren task format enable --all-writers-compatible.`;
|
|
55630
55976
|
}
|
|
55631
55977
|
});
|
|
55632
55978
|
|
|
@@ -57069,9 +57415,9 @@ var init_dedup = __esm({
|
|
|
57069
57415
|
});
|
|
57070
57416
|
|
|
57071
57417
|
// src/finding-graph-id.ts
|
|
57072
|
-
import { createHash as
|
|
57418
|
+
import { createHash as createHash25 } from "crypto";
|
|
57073
57419
|
function findingStableId(scoreKey) {
|
|
57074
|
-
return `finding:${
|
|
57420
|
+
return `finding:${createHash25("sha1").update(scoreKey).digest("hex").slice(0, 12)}`;
|
|
57075
57421
|
}
|
|
57076
57422
|
function findingNodeIdForLine(project, line) {
|
|
57077
57423
|
const tagMatch = line.match(TAGGED_BULLET);
|
|
@@ -57140,14 +57486,14 @@ function parseTaskItems(taskPath) {
|
|
|
57140
57486
|
counters[section] += 1;
|
|
57141
57487
|
const itemId = `${section === "Active" ? "A" : section === "Queue" ? "Q" : "D"}${counters[section]}`;
|
|
57142
57488
|
const stripped = stripBulletPrefix(line).body;
|
|
57143
|
-
const { clean:
|
|
57489
|
+
const { clean: clean3, bid } = stripBid(stripped);
|
|
57144
57490
|
items.push({
|
|
57145
57491
|
id: itemId,
|
|
57146
57492
|
stableId: bid,
|
|
57147
57493
|
section,
|
|
57148
|
-
line:
|
|
57149
|
-
priority: normalizePriority(
|
|
57150
|
-
pinned: detectPinned(
|
|
57494
|
+
line: clean3,
|
|
57495
|
+
priority: normalizePriority(clean3),
|
|
57496
|
+
pinned: detectPinned(clean3) || void 0
|
|
57151
57497
|
});
|
|
57152
57498
|
}
|
|
57153
57499
|
return items;
|
|
@@ -57585,9 +57931,9 @@ var init_content = __esm({
|
|
|
57585
57931
|
});
|
|
57586
57932
|
|
|
57587
57933
|
// src/bridge/memory-store.ts
|
|
57588
|
-
import { execFile as
|
|
57589
|
-
import { createHash as
|
|
57590
|
-
import { lstat as lstat30, mkdir as
|
|
57934
|
+
import { execFile as execFile21 } from "node:child_process";
|
|
57935
|
+
import { createHash as createHash26 } from "node:crypto";
|
|
57936
|
+
import { lstat as lstat30, mkdir as mkdir27, readFile as readFile47, realpath as realpath17, rename as rename9, rm as rm13, writeFile as writeFile10 } from "node:fs/promises";
|
|
57591
57937
|
import path102 from "node:path";
|
|
57592
57938
|
import { promisify as promisify19 } from "node:util";
|
|
57593
57939
|
function serialized2(work) {
|
|
@@ -57609,7 +57955,7 @@ async function git5(store, args, env = {}) {
|
|
|
57609
57955
|
}
|
|
57610
57956
|
}
|
|
57611
57957
|
function blobSha(content) {
|
|
57612
|
-
return
|
|
57958
|
+
return createHash26("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
|
|
57613
57959
|
}
|
|
57614
57960
|
async function isRepository(store) {
|
|
57615
57961
|
return await lstat30(path102.join(store, ".git")).catch(() => void 0) !== void 0;
|
|
@@ -57645,7 +57991,7 @@ async function storeRepositoryIdentity(store) {
|
|
|
57645
57991
|
function storeHead(store, indexFile = path102.join(bridgeRoot(), "store-snapshot.index")) {
|
|
57646
57992
|
return serialized2(async () => {
|
|
57647
57993
|
if (!await isRepository(store)) throw new BridgeError(409, "This computer's phren store is not a git repository. Run phren init.");
|
|
57648
|
-
await
|
|
57994
|
+
await mkdir27(path102.dirname(indexFile), { recursive: true, mode: 448 });
|
|
57649
57995
|
const env = { GIT_INDEX_FILE: indexFile };
|
|
57650
57996
|
if (!await lstat30(indexFile).catch(() => void 0)) {
|
|
57651
57997
|
const head = await git5(store, ["rev-parse", "--verify", "--quiet", "HEAD"]).catch(() => "");
|
|
@@ -57713,7 +58059,7 @@ function putStoreFile(store, data) {
|
|
|
57713
58059
|
return serialized2(async () => {
|
|
57714
58060
|
const file4 = await storeFile(store, input2.path);
|
|
57715
58061
|
if (await currentSha(file4) !== (input2.sha ?? null)) throw new BridgeError(409, `${input2.path} changed on this computer.`);
|
|
57716
|
-
await
|
|
58062
|
+
await mkdir27(path102.dirname(file4), { recursive: true });
|
|
57717
58063
|
const temporary = `${file4}.phren-${process.pid}-${Date.now()}`;
|
|
57718
58064
|
await writeFile10(temporary, content, { flag: "wx" });
|
|
57719
58065
|
await rename9(temporary, file4);
|
|
@@ -57743,7 +58089,7 @@ var init_memory_store = __esm({
|
|
|
57743
58089
|
"use strict";
|
|
57744
58090
|
init_zod();
|
|
57745
58091
|
init_protocol();
|
|
57746
|
-
exec19 = promisify19(
|
|
58092
|
+
exec19 = promisify19(execFile21);
|
|
57747
58093
|
SHA = /^[0-9a-f]{40}$/;
|
|
57748
58094
|
MAX_FILE = 4 * 1024 * 1024;
|
|
57749
58095
|
queue2 = Promise.resolve();
|
|
@@ -57755,7 +58101,7 @@ var init_memory_store = __esm({
|
|
|
57755
58101
|
|
|
57756
58102
|
// src/data/task-store-directory.ts
|
|
57757
58103
|
import * as path103 from "node:path";
|
|
57758
|
-
import { execFile as
|
|
58104
|
+
import { execFile as execFile22 } from "node:child_process";
|
|
57759
58105
|
import { promisify as promisify20 } from "node:util";
|
|
57760
58106
|
function taskStores(base) {
|
|
57761
58107
|
return readTaskStoreEntries(base).map((store) => ({
|
|
@@ -57790,7 +58136,7 @@ var init_task_store_directory = __esm({
|
|
|
57790
58136
|
"use strict";
|
|
57791
58137
|
init_store_registry();
|
|
57792
58138
|
init_memory_store();
|
|
57793
|
-
exec20 = promisify20(
|
|
58139
|
+
exec20 = promisify20(execFile22);
|
|
57794
58140
|
}
|
|
57795
58141
|
});
|
|
57796
58142
|
|
|
@@ -57951,7 +58297,7 @@ var init_task_receipts = __esm({
|
|
|
57951
58297
|
// src/data/tasks.ts
|
|
57952
58298
|
import * as fs35 from "fs";
|
|
57953
58299
|
import * as path106 from "path";
|
|
57954
|
-
import { createHash as
|
|
58300
|
+
import { createHash as createHash27, randomBytes as randomBytes8, randomUUID as randomUUID24 } from "crypto";
|
|
57955
58301
|
function formatClaim(claim2) {
|
|
57956
58302
|
return `Claimed: ${claim2.computer} ${claim2.at}${claim2.session ? ` session:${claim2.session}` : ""}`;
|
|
57957
58303
|
}
|
|
@@ -58064,7 +58410,7 @@ function parseContinuation(lines, idx) {
|
|
|
58064
58410
|
};
|
|
58065
58411
|
}
|
|
58066
58412
|
function newBid() {
|
|
58067
|
-
return
|
|
58413
|
+
return randomBytes8(4).toString("hex");
|
|
58068
58414
|
}
|
|
58069
58415
|
function stripBid(text5) {
|
|
58070
58416
|
const m = text5.match(METADATA_PATTERN);
|
|
@@ -58188,7 +58534,7 @@ function parseTaskContent(project, taskPath, content) {
|
|
|
58188
58534
|
title: title2,
|
|
58189
58535
|
path: taskPath,
|
|
58190
58536
|
items,
|
|
58191
|
-
revision:
|
|
58537
|
+
revision: createHash27("sha256").update(content).digest("hex"),
|
|
58192
58538
|
issues: validateTaskFormat(content)
|
|
58193
58539
|
};
|
|
58194
58540
|
}
|
|
@@ -58279,7 +58625,7 @@ function readTasks(phrenPath, project) {
|
|
|
58279
58625
|
return phrenOk({
|
|
58280
58626
|
project,
|
|
58281
58627
|
title: `# ${project} tasks`,
|
|
58282
|
-
revision:
|
|
58628
|
+
revision: createHash27("sha256").update("").digest("hex"),
|
|
58283
58629
|
path: taskPath,
|
|
58284
58630
|
issues: [],
|
|
58285
58631
|
items: { Active: [], Queue: [], Done: [] }
|
|
@@ -58502,8 +58848,8 @@ var init_tasks = __esm({
|
|
|
58502
58848
|
});
|
|
58503
58849
|
|
|
58504
58850
|
// src/bridge/launch-worktree.ts
|
|
58505
|
-
import { execFile as
|
|
58506
|
-
import { mkdir as
|
|
58851
|
+
import { execFile as execFile23 } from "node:child_process";
|
|
58852
|
+
import { mkdir as mkdir28, realpath as realpath18, rm as rm14, stat as stat26 } from "node:fs/promises";
|
|
58507
58853
|
import path107 from "node:path";
|
|
58508
58854
|
import { promisify as promisify21 } from "node:util";
|
|
58509
58855
|
async function git6(cwd, ...args) {
|
|
@@ -58533,7 +58879,7 @@ async function createLaunchWorktree(cwd, request9) {
|
|
|
58533
58879
|
if (await stat26(worktree).then(() => true, () => false)) {
|
|
58534
58880
|
throw new BridgeError(409, `The folder .claude/worktrees/${worktreeFolderName(branch)} already exists. Choose another branch name.`);
|
|
58535
58881
|
}
|
|
58536
|
-
await
|
|
58882
|
+
await mkdir28(path107.dirname(worktree), { recursive: true });
|
|
58537
58883
|
try {
|
|
58538
58884
|
await git6(root, "worktree", "add", "-b", branch, worktree, head);
|
|
58539
58885
|
} catch (error62) {
|
|
@@ -58564,14 +58910,14 @@ var init_launch_worktree = __esm({
|
|
|
58564
58910
|
init_metrics();
|
|
58565
58911
|
init_projects();
|
|
58566
58912
|
init_protocol();
|
|
58567
|
-
exec21 = promisify21(
|
|
58913
|
+
exec21 = promisify21(execFile23);
|
|
58568
58914
|
worktreeBranch = external_exports.string().trim().min(1).max(100).regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/, "A branch name uses letters, digits, dots, dashes, underscores and slashes.");
|
|
58569
58915
|
launchWorktreeSchema = external_exports.object({ branch: worktreeBranch }).strict();
|
|
58570
58916
|
}
|
|
58571
58917
|
});
|
|
58572
58918
|
|
|
58573
58919
|
// src/bridge/server-launch.ts
|
|
58574
|
-
import { mkdir as
|
|
58920
|
+
import { mkdir as mkdir29, mkdtemp as mkdtemp6, readFile as readFile48, realpath as realpath19, rmdir as rmdir2 } from "node:fs/promises";
|
|
58575
58921
|
import path108 from "node:path";
|
|
58576
58922
|
function effortArgs(kind, effort) {
|
|
58577
58923
|
if (kind === "claude") return ["--effort", effort];
|
|
@@ -58632,7 +58978,7 @@ mode: primary
|
|
|
58632
58978
|
|
|
58633
58979
|
${brief}
|
|
58634
58980
|
`;
|
|
58635
|
-
await
|
|
58981
|
+
await mkdir29(directory, { recursive: true, mode: 448 });
|
|
58636
58982
|
if (await readFile48(file4, "utf8").catch(() => void 0) !== definition) await atomic(file4, definition, 420);
|
|
58637
58983
|
return [...model ? ["--model", model] : [], "--agent", "conductor", "--variant", effort];
|
|
58638
58984
|
}
|
|
@@ -58813,10 +59159,10 @@ async function startSession(server, data, options) {
|
|
|
58813
59159
|
if (agentFolder) {
|
|
58814
59160
|
const store = await realpath19(defaultPhrenPath());
|
|
58815
59161
|
const runtime = path108.join(store, ".runtime");
|
|
58816
|
-
await
|
|
59162
|
+
await mkdir29(runtime, { recursive: true, mode: 448 });
|
|
58817
59163
|
if (await realpath19(runtime) !== runtime) throw new BridgeError(403, "The runtime folder must be inside the Phren directory.");
|
|
58818
59164
|
const agents = path108.join(runtime, "agents");
|
|
58819
|
-
await
|
|
59165
|
+
await mkdir29(agents, { recursive: true, mode: 448 });
|
|
58820
59166
|
if (await realpath19(agents) !== agents) throw new BridgeError(403, "The agents folder must be inside the Phren directory.");
|
|
58821
59167
|
scratch = await mkdtemp6(path108.join(agents, `${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}-${herdrAgentName(label2)}-`));
|
|
58822
59168
|
}
|
|
@@ -59210,7 +59556,28 @@ async function ownerInboxView(inbox, input2, localOnly = false) {
|
|
|
59210
59556
|
unreachable.push({ computer: peer.name, error: error62 instanceof Error ? error62.message : "Unreachable." });
|
|
59211
59557
|
}
|
|
59212
59558
|
}));
|
|
59213
|
-
|
|
59559
|
+
const seen = /* @__PURE__ */ new Set();
|
|
59560
|
+
const current2 = items.filter((item) => {
|
|
59561
|
+
if (data.includeResolved || item.kind === "manual") return true;
|
|
59562
|
+
if (item.live !== true || item.state !== "open") return false;
|
|
59563
|
+
const t = item.target;
|
|
59564
|
+
if (!t) return true;
|
|
59565
|
+
const computer2 = String(item.computer ?? item.inboxComputer);
|
|
59566
|
+
const key4 = JSON.stringify([
|
|
59567
|
+
isLocalComputer(computer2) ? "local" : computer2,
|
|
59568
|
+
t.server,
|
|
59569
|
+
t.workspace,
|
|
59570
|
+
t.tab,
|
|
59571
|
+
t.pane,
|
|
59572
|
+
t.source,
|
|
59573
|
+
t.session ?? t.startingToken,
|
|
59574
|
+
item.actionId ?? "waiting"
|
|
59575
|
+
]);
|
|
59576
|
+
if (seen.has(key4)) return false;
|
|
59577
|
+
seen.add(key4);
|
|
59578
|
+
return true;
|
|
59579
|
+
});
|
|
59580
|
+
return { ok: true, items: current2, unreachable };
|
|
59214
59581
|
}
|
|
59215
59582
|
var init_owner_inbox_view = __esm({
|
|
59216
59583
|
"src/bridge/owner-inbox-view.ts"() {
|
|
@@ -60300,8 +60667,8 @@ function mergeText(base, ours, theirs) {
|
|
|
60300
60667
|
}
|
|
60301
60668
|
}
|
|
60302
60669
|
function unionText(base, ours, theirs) {
|
|
60303
|
-
const
|
|
60304
|
-
if (
|
|
60670
|
+
const clean3 = mergeText(base, ours, theirs);
|
|
60671
|
+
if (clean3 !== null) return clean3;
|
|
60305
60672
|
const dir = fs38.mkdtempSync(path114.join(os3.tmpdir(), "phren-merge-"));
|
|
60306
60673
|
try {
|
|
60307
60674
|
const [o, b, t] = ["ours", "base", "theirs"].map((name) => path114.join(dir, name));
|
|
@@ -60691,10 +61058,10 @@ var init_session_git = __esm({
|
|
|
60691
61058
|
});
|
|
60692
61059
|
|
|
60693
61060
|
// src/bridge/enroll.ts
|
|
60694
|
-
import { execFile as
|
|
61061
|
+
import { execFile as execFile24 } from "node:child_process";
|
|
60695
61062
|
import { promisify as promisify22 } from "node:util";
|
|
60696
61063
|
import { realpathSync as realpathSync5 } from "node:fs";
|
|
60697
|
-
import { readdir as readdir19, readFile as readFile49, stat as stat28, mkdir as
|
|
61064
|
+
import { readdir as readdir19, readFile as readFile49, stat as stat28, mkdir as mkdir30 } from "node:fs/promises";
|
|
60698
61065
|
import { homedir as homedir19 } from "node:os";
|
|
60699
61066
|
import path115 from "node:path";
|
|
60700
61067
|
function repoName(url2) {
|
|
@@ -60798,7 +61165,7 @@ async function cloneRoot(env) {
|
|
|
60798
61165
|
}
|
|
60799
61166
|
}
|
|
60800
61167
|
const fallback2 = path115.join(home, "Projects");
|
|
60801
|
-
await
|
|
61168
|
+
await mkdir30(fallback2, { recursive: true });
|
|
60802
61169
|
return fallback2;
|
|
60803
61170
|
}
|
|
60804
61171
|
async function publishStore(store, project) {
|
|
@@ -60880,7 +61247,7 @@ var init_enroll = __esm({
|
|
|
60880
61247
|
init_code_routes();
|
|
60881
61248
|
init_utils_paths();
|
|
60882
61249
|
init_machine_identity();
|
|
60883
|
-
exec22 = promisify22(
|
|
61250
|
+
exec22 = promisify22(execFile24);
|
|
60884
61251
|
runEnrollStoreGit = async (cwd, args) => {
|
|
60885
61252
|
const result = await runBestEffortGit(args, cwd);
|
|
60886
61253
|
return { ok: result.ok, output: result.output ?? "", error: result.error };
|
|
@@ -61103,11 +61470,11 @@ var init_file_resolve = __esm({
|
|
|
61103
61470
|
});
|
|
61104
61471
|
|
|
61105
61472
|
// src/bridge/simulators.ts
|
|
61106
|
-
import { execFile as
|
|
61107
|
-
import { chmod as chmod5, mkdir as
|
|
61473
|
+
import { execFile as execFile25 } from "node:child_process";
|
|
61474
|
+
import { chmod as chmod5, mkdir as mkdir31, readFile as readFile50, rename as rename10, stat as stat29, unlink as unlink9, writeFile as writeFile11 } from "node:fs/promises";
|
|
61108
61475
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
61109
61476
|
import path119 from "node:path";
|
|
61110
|
-
import { createHash as
|
|
61477
|
+
import { createHash as createHash28, randomUUID as randomUUID26 } from "node:crypto";
|
|
61111
61478
|
import { promisify as promisify23 } from "node:util";
|
|
61112
61479
|
async function bootedSimulators() {
|
|
61113
61480
|
if (process.platform !== "darwin") return [];
|
|
@@ -61244,10 +61611,10 @@ case "type":
|
|
|
61244
61611
|
default: fail(2, "unknown command \\(command)")
|
|
61245
61612
|
}
|
|
61246
61613
|
` : await readFile50(new URL("./native/simtap.swift", import.meta.url), "utf8");
|
|
61247
|
-
const digest2 =
|
|
61614
|
+
const digest2 = createHash28("sha256").update(code).digest("hex");
|
|
61248
61615
|
const saved = await readFile50(binary + ".sha256", "utf8").then(JSON.parse).catch(() => void 0);
|
|
61249
61616
|
if (await stat29(binary).catch(() => void 0) && saved?.sourceSha === digest2) return binary;
|
|
61250
|
-
await
|
|
61617
|
+
await mkdir31(dir, { recursive: true, mode: 448 });
|
|
61251
61618
|
const temporary = path119.join(dir, `simtap.${randomUUID26()}`), source = temporary + ".swift";
|
|
61252
61619
|
const sidecar = temporary + ".sha256";
|
|
61253
61620
|
try {
|
|
@@ -61256,7 +61623,7 @@ default: fail(2, "unknown command \\(command)")
|
|
|
61256
61623
|
throw new BridgeError(409, "Couldn't build the simulator input helper (needs Xcode's swiftc).");
|
|
61257
61624
|
});
|
|
61258
61625
|
await chmod5(temporary, 448);
|
|
61259
|
-
const binarySha =
|
|
61626
|
+
const binarySha = createHash28("sha256").update(await readFile50(temporary)).digest("hex");
|
|
61260
61627
|
await writeFile11(sidecar, JSON.stringify({ sourceSha: digest2, binarySha }), { mode: 384, flag: "wx" });
|
|
61261
61628
|
await rename10(temporary, binary);
|
|
61262
61629
|
await rename10(sidecar, binary + ".sha256");
|
|
@@ -61274,7 +61641,7 @@ function simtap(name, ...args) {
|
|
|
61274
61641
|
async function verifiedHelper() {
|
|
61275
61642
|
const binary = await helper();
|
|
61276
61643
|
const saved = await readFile50(binary + ".sha256", "utf8").then(JSON.parse).catch(() => void 0);
|
|
61277
|
-
const binarySha =
|
|
61644
|
+
const binarySha = createHash28("sha256").update(await readFile50(binary)).digest("hex");
|
|
61278
61645
|
if (!saved || saved.binarySha !== binarySha) throw new BridgeError(409, "Simulator input helper integrity check failed.");
|
|
61279
61646
|
return binary;
|
|
61280
61647
|
}
|
|
@@ -61378,7 +61745,7 @@ var init_simulators = __esm({
|
|
|
61378
61745
|
"src/bridge/simulators.ts"() {
|
|
61379
61746
|
"use strict";
|
|
61380
61747
|
init_protocol();
|
|
61381
|
-
exec23 = promisify23(
|
|
61748
|
+
exec23 = promisify23(execFile25);
|
|
61382
61749
|
UDID = /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i;
|
|
61383
61750
|
inputQueue = Promise.resolve();
|
|
61384
61751
|
prompted = false;
|
|
@@ -62747,9 +63114,9 @@ function claudePanePreview(rendered, prompt, previous = "") {
|
|
|
62747
63114
|
}
|
|
62748
63115
|
if (!writing) continue;
|
|
62749
63116
|
const tidy = (value2) => value2.replace(/^\s*[⏺●]\s?/, "").replace(/[⠁-⣿✻✽✶✢✳]/gu, "");
|
|
62750
|
-
const
|
|
62751
|
-
if (/^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(
|
|
62752
|
-
reply.push(
|
|
63117
|
+
const clean3 = tidy(line);
|
|
63118
|
+
if (/^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(clean3) || claudeChrome(clean3)) continue;
|
|
63119
|
+
reply.push(clean3.replace(/^ {2}/, ""));
|
|
62753
63120
|
shown.push(tidy(markedBody[index2] ?? line).replace(/^ {2}/, ""));
|
|
62754
63121
|
}
|
|
62755
63122
|
const text5 = unwrapTerminalLines(reply, shown).trim().slice(0, MAX_TEXT3);
|
|
@@ -63541,9 +63908,9 @@ var init_codex_auth_refresh = __esm({
|
|
|
63541
63908
|
|
|
63542
63909
|
// src/bridge/server.ts
|
|
63543
63910
|
import { randomUUID as randomUUID27 } from "node:crypto";
|
|
63544
|
-
import { chmod as chmod6, lstat as lstat34, mkdir as
|
|
63911
|
+
import { chmod as chmod6, lstat as lstat34, mkdir as mkdir32, readFile as readFile52, rm as rm15, unlink as unlink10, writeFile as writeFile12 } from "node:fs/promises";
|
|
63545
63912
|
import { readFileSync as readFileSync42 } from "node:fs";
|
|
63546
|
-
import { createServer as
|
|
63913
|
+
import { createServer as createServer4 } from "node:http";
|
|
63547
63914
|
import { cpus as cpus2, hostname as hostname12, loadavg as loadavg2 } from "node:os";
|
|
63548
63915
|
import path124 from "node:path";
|
|
63549
63916
|
async function serve(version3, options = {}) {
|
|
@@ -63552,7 +63919,7 @@ async function serve(version3, options = {}) {
|
|
|
63552
63919
|
if (!modules.has("hook")) throw new BridgeError(404, disabledHint("hook"));
|
|
63553
63920
|
const activeCapabilities = capabilitiesForModules(modules);
|
|
63554
63921
|
const root = bridgeRoot();
|
|
63555
|
-
await
|
|
63922
|
+
await mkdir32(root, { recursive: true, mode: 448 });
|
|
63556
63923
|
await chmod6(root, 448);
|
|
63557
63924
|
let computerID2;
|
|
63558
63925
|
const identityFile = path124.join(root, "computer-id");
|
|
@@ -63604,36 +63971,7 @@ async function serve(version3, options = {}) {
|
|
|
63604
63971
|
if ("approvalPush" in activeCapabilities) {
|
|
63605
63972
|
Object.defineProperty(activeCapabilities, "approvalPush", { enumerable: true, get: () => approvalPushCapability(agentHooks.push.status) });
|
|
63606
63973
|
}
|
|
63607
|
-
const inbox = dispatches ? new OwnerInbox(
|
|
63608
|
-
const items = [];
|
|
63609
|
-
for (const server of await recentServers()) {
|
|
63610
|
-
const name = String(server.session), state = await sharedSnapshot(name, 4e3);
|
|
63611
|
-
for (const pane of objects(state.panes)) {
|
|
63612
|
-
const chat = await paneChatState(name, pane, { tokenWhenIdentified: false }).catch(() => ({}));
|
|
63613
|
-
const parsed = inboxTargetSchema.safeParse({
|
|
63614
|
-
server: name,
|
|
63615
|
-
workspace: pane.workspace_id,
|
|
63616
|
-
tab: pane.tab_id,
|
|
63617
|
-
pane: pane.pane_id,
|
|
63618
|
-
source: pane.agent,
|
|
63619
|
-
...chat.sessionId ? { session: chat.sessionId } : { starting: true, startingToken: chat.startingToken }
|
|
63620
|
-
});
|
|
63621
|
-
if (!parsed.success) continue;
|
|
63622
|
-
const target = parsed.data, approval = "session" in target ? agentHooks.workerApproval(target) : void 0, question2 = "session" in target ? agentHooks.servedQuestion(target) : void 0, terminal2 = "session" in target ? agentHooks.terminalPrompt(target) : void 0;
|
|
63623
|
-
const request9 = approval?.request ?? (question2 ? "The worker has a question for the owner." : void 0) ?? terminal2?.message ?? (["blocked", "waiting"].includes(String(pane.agent_status)) ? `${pane.agent} needs terminal input.` : void 0);
|
|
63624
|
-
if (!request9) continue;
|
|
63625
|
-
const source = `prompt:${JSON.stringify(target)}:${approval?.actionId ?? JSON.stringify(question2 ?? terminal2)}`;
|
|
63626
|
-
items.push({
|
|
63627
|
-
source,
|
|
63628
|
-
kind: "blocked",
|
|
63629
|
-
title: String(request9).replace(/[\x00-\x1f\x7f]+/g, " ").slice(0, 500),
|
|
63630
|
-
target,
|
|
63631
|
-
...approval?.actionId ? { actionId: approval.actionId } : {}
|
|
63632
|
-
});
|
|
63633
|
-
}
|
|
63634
|
-
}
|
|
63635
|
-
return items;
|
|
63636
|
-
}) : void 0;
|
|
63974
|
+
const inbox = dispatches ? new OwnerInbox(() => ownerInboxSources(agentHooks)) : void 0;
|
|
63637
63975
|
const modelCatalog = options.modelCatalog ?? new ModelCatalog();
|
|
63638
63976
|
const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
|
|
63639
63977
|
const settingsSwitcher = new SettingsSwitcher(agentHooks);
|
|
@@ -63737,7 +64075,7 @@ async function serve(version3, options = {}) {
|
|
|
63737
64075
|
resources: () => resources.read(),
|
|
63738
64076
|
sudo: agentHooks.sudo
|
|
63739
64077
|
});
|
|
63740
|
-
const http =
|
|
64078
|
+
const http = createServer4(createRouteHandler({
|
|
63741
64079
|
version: version3,
|
|
63742
64080
|
modules,
|
|
63743
64081
|
info,
|
|
@@ -63910,6 +64248,7 @@ async function serve(version3, options = {}) {
|
|
|
63910
64248
|
var init_server = __esm({
|
|
63911
64249
|
"src/bridge/server.ts"() {
|
|
63912
64250
|
"use strict";
|
|
64251
|
+
init_owner_inbox_sources();
|
|
63913
64252
|
init_owner_inbox();
|
|
63914
64253
|
init_worker_close();
|
|
63915
64254
|
init_dispatch_hosts();
|
|
@@ -63965,7 +64304,7 @@ var init_server = __esm({
|
|
|
63965
64304
|
});
|
|
63966
64305
|
|
|
63967
64306
|
// src/bridge/link.ts
|
|
63968
|
-
import { execFile as
|
|
64307
|
+
import { execFile as execFile26 } from "node:child_process";
|
|
63969
64308
|
import { readFile as readFile53 } from "node:fs/promises";
|
|
63970
64309
|
import { homedir as homedir21, hostname as hostname13, userInfo as userInfo5 } from "node:os";
|
|
63971
64310
|
import path125 from "node:path";
|
|
@@ -63992,7 +64331,7 @@ function sshConfigHosts(text5) {
|
|
|
63992
64331
|
}
|
|
63993
64332
|
async function ssh(host, command, input2, timeout = 2e4) {
|
|
63994
64333
|
return new Promise((resolve14, reject) => {
|
|
63995
|
-
const child =
|
|
64334
|
+
const child = execFile26(
|
|
63996
64335
|
"ssh",
|
|
63997
64336
|
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", "--", host, command],
|
|
63998
64337
|
{ timeout, maxBuffer: 1048576 },
|
|
@@ -64044,8 +64383,12 @@ async function linkComputer(host, options = {}) {
|
|
|
64044
64383
|
const backAddress = options.backAddress ?? remote.client;
|
|
64045
64384
|
if (!backAddress) throw new BridgeError(409, `${host} did not report this computer's address; pass --back-address.`);
|
|
64046
64385
|
const resolved = Object.fromEntries((await exec24("ssh", ["-G", "--", host], { timeout: 5e3 })).stdout.split("\n").map((line) => line.split(" ")).filter((parts) => parts.length >= 2).map(([key4, ...rest]) => [key4, rest.join(" ")]));
|
|
64047
|
-
const
|
|
64048
|
-
|
|
64386
|
+
const remoteKeyLine = hostKeyLine(await ssh(host, hostKeyScript()));
|
|
64387
|
+
if (!remoteKeyLine) throw noHostKey(host);
|
|
64388
|
+
const localLine = await localHostKeyLine();
|
|
64389
|
+
if (!localLine) throw noHostKey("This computer");
|
|
64390
|
+
const remoteHostKey = publicComputerKey(remoteKeyLine.split(/\s+/).slice(0, 2).join(" "));
|
|
64391
|
+
const localHostKey = publicComputerKey(localLine.split(/\s+/).slice(0, 2).join(" "));
|
|
64049
64392
|
const remoteLine = (await ssh(host, `${REMOTE_PATH} phren bridge enroll-computer ${name}`)).trim();
|
|
64050
64393
|
await ssh(host, `f=$(mktemp) && cat > "$f" && ${REMOTE_PATH} phren bridge enroll-computer ${as} --accept "$f"; s=$?; rm -f "$f"; exit $s`, await enrollComputer(as));
|
|
64051
64394
|
await acceptComputer(name, remoteLine);
|
|
@@ -64080,10 +64423,11 @@ var init_link = __esm({
|
|
|
64080
64423
|
init_hand_off();
|
|
64081
64424
|
init_computer_names();
|
|
64082
64425
|
init_computers();
|
|
64426
|
+
init_host_key();
|
|
64083
64427
|
init_peers();
|
|
64084
64428
|
init_protocol();
|
|
64085
|
-
exec24 = promisify24(
|
|
64086
|
-
REMOTE_PATH = 'PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"';
|
|
64429
|
+
exec24 = promisify24(execFile26);
|
|
64430
|
+
REMOTE_PATH = 'PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/opt/bin:$PATH"';
|
|
64087
64431
|
GIT_HOSTS = /(^|\.)(github\.com|gitlab\.com|bitbucket\.org)$/i;
|
|
64088
64432
|
}
|
|
64089
64433
|
});
|
|
@@ -64382,7 +64726,7 @@ async function main() {
|
|
|
64382
64726
|
return askpass2(args[1]);
|
|
64383
64727
|
}
|
|
64384
64728
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
64385
|
-
return runBridge2(args, "0.3.
|
|
64729
|
+
return runBridge2(args, "0.3.36");
|
|
64386
64730
|
}
|
|
64387
64731
|
main().then((code) => {
|
|
64388
64732
|
process.exitCode = code;
|