@phren/cli 0.3.35 → 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 +18 -9
- 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 +809 -471
- 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);
|
|
@@ -26681,7 +26682,7 @@ function outputCallIds(raw, source) {
|
|
|
26681
26682
|
if (!Array.isArray(content)) return [];
|
|
26682
26683
|
return content.flatMap((block) => block && typeof block === "object" && block.type === "tool_result" ? ids(block.tool_use_id) : []);
|
|
26683
26684
|
}
|
|
26684
|
-
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;
|
|
26685
26686
|
var init_changes = __esm({
|
|
26686
26687
|
"src/bridge/changes.ts"() {
|
|
26687
26688
|
"use strict";
|
|
@@ -26706,7 +26707,7 @@ var init_changes = __esm({
|
|
|
26706
26707
|
});
|
|
26707
26708
|
changeRowSchema = external_exports.object({ toolUseId: external_exports.string(), files: external_exports.array(changedFileSchema) });
|
|
26708
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));
|
|
26709
|
-
|
|
26710
|
+
capturePool = new ProcessPool(2);
|
|
26710
26711
|
SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash", "bash", "shell", "Shell", "exec_command", "shell_command", "local_shell", "write_stdin"]);
|
|
26711
26712
|
NAMED = /(?<![\w@:/])(?:~\/|\.\/|\/)[\w.@+~-]+(?:\/[\w.@+~-]+)*/g;
|
|
26712
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"]);
|
|
@@ -26773,7 +26774,7 @@ var init_changes = __esm({
|
|
|
26773
26774
|
const snapshot2 = { at: Date.now(), conversation, own: new Set(claimed), trees: /* @__PURE__ */ new Map(), taking: true };
|
|
26774
26775
|
this.snapshots.set(key4, snapshot2);
|
|
26775
26776
|
try {
|
|
26776
|
-
await this.budget(async (
|
|
26777
|
+
await this.budget((signal) => capturePool.run(signal, async () => {
|
|
26777
26778
|
await realpath2(cwd);
|
|
26778
26779
|
const roots = /* @__PURE__ */ new Set();
|
|
26779
26780
|
for (const target of [cwd, phrenStoreRoot(), ...namedPaths(command, input2)]) {
|
|
@@ -26786,7 +26787,7 @@ var init_changes = __esm({
|
|
|
26786
26787
|
snapshot2.trees.set(root, await scratchTree(root, signal));
|
|
26787
26788
|
}
|
|
26788
26789
|
signal.throwIfAborted();
|
|
26789
|
-
});
|
|
26790
|
+
}));
|
|
26790
26791
|
snapshot2.taking = false;
|
|
26791
26792
|
if (snapshot2.dropped) {
|
|
26792
26793
|
await this.discard(snapshot2);
|
|
@@ -26854,10 +26855,13 @@ var init_changes = __esm({
|
|
|
26854
26855
|
async compute(snapshot2) {
|
|
26855
26856
|
try {
|
|
26856
26857
|
return await this.budget(async (signal) => {
|
|
26857
|
-
const files =
|
|
26858
|
-
|
|
26859
|
-
|
|
26860
|
-
|
|
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
|
+
});
|
|
26861
26865
|
const until = Date.now();
|
|
26862
26866
|
const kept = [];
|
|
26863
26867
|
for (const file4 of files) {
|
|
@@ -28446,14 +28450,14 @@ function unescapeJs(value2) {
|
|
|
28446
28450
|
});
|
|
28447
28451
|
}
|
|
28448
28452
|
function literalValue(expression) {
|
|
28449
|
-
const text5 = expression.trim(),
|
|
28450
|
-
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;
|
|
28451
28455
|
for (let index2 = 1; index2 < text5.length - 1; index2++) {
|
|
28452
28456
|
if (text5[index2] === "\\") {
|
|
28453
28457
|
index2++;
|
|
28454
28458
|
continue;
|
|
28455
28459
|
}
|
|
28456
|
-
if (text5[index2] ===
|
|
28460
|
+
if (text5[index2] === quote6) return void 0;
|
|
28457
28461
|
}
|
|
28458
28462
|
return unescapeJs(text5.slice(1, -1));
|
|
28459
28463
|
}
|
|
@@ -28466,16 +28470,16 @@ function resolveString(expression, source) {
|
|
|
28466
28470
|
return declaration ? unescapeJs(declaration[1].slice(1, -1)) : void 0;
|
|
28467
28471
|
}
|
|
28468
28472
|
function callArguments(source, open28) {
|
|
28469
|
-
let depth = 0,
|
|
28473
|
+
let depth = 0, quote6 = "";
|
|
28470
28474
|
for (let index2 = open28; index2 < source.length; index2++) {
|
|
28471
28475
|
const character = source[index2];
|
|
28472
|
-
if (
|
|
28476
|
+
if (quote6) {
|
|
28473
28477
|
if (character === "\\") index2++;
|
|
28474
|
-
else if (character ===
|
|
28478
|
+
else if (character === quote6) quote6 = "";
|
|
28475
28479
|
continue;
|
|
28476
28480
|
}
|
|
28477
28481
|
if (character === '"' || character === "'" || character === "`") {
|
|
28478
|
-
|
|
28482
|
+
quote6 = character;
|
|
28479
28483
|
continue;
|
|
28480
28484
|
}
|
|
28481
28485
|
if (character === "(" || character === "{" || character === "[") depth++;
|
|
@@ -31896,7 +31900,7 @@ var require_websocket = __commonJS({
|
|
|
31896
31900
|
var http = __require("http");
|
|
31897
31901
|
var net2 = __require("net");
|
|
31898
31902
|
var tls = __require("tls");
|
|
31899
|
-
var { randomBytes:
|
|
31903
|
+
var { randomBytes: randomBytes9, createHash: createHash29 } = __require("crypto");
|
|
31900
31904
|
var { Duplex: Duplex2, Readable: Readable2 } = __require("stream");
|
|
31901
31905
|
var { URL: URL2 } = __require("url");
|
|
31902
31906
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -32447,7 +32451,7 @@ var require_websocket = __commonJS({
|
|
|
32447
32451
|
}
|
|
32448
32452
|
}
|
|
32449
32453
|
const defaultPort = isSecure ? 443 : 80;
|
|
32450
|
-
const key4 =
|
|
32454
|
+
const key4 = randomBytes9(16).toString("base64");
|
|
32451
32455
|
const request9 = isSecure ? https.request : http.request;
|
|
32452
32456
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
32453
32457
|
let perMessageDeflate;
|
|
@@ -32577,7 +32581,7 @@ var require_websocket = __commonJS({
|
|
|
32577
32581
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
32578
32582
|
return;
|
|
32579
32583
|
}
|
|
32580
|
-
const digest2 =
|
|
32584
|
+
const digest2 = createHash29("sha1").update(key4 + GUID).digest("base64");
|
|
32581
32585
|
if (res.headers["sec-websocket-accept"] !== digest2) {
|
|
32582
32586
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
32583
32587
|
return;
|
|
@@ -32946,7 +32950,7 @@ var require_websocket_server = __commonJS({
|
|
|
32946
32950
|
var EventEmitter2 = __require("events");
|
|
32947
32951
|
var http = __require("http");
|
|
32948
32952
|
var { Duplex: Duplex2 } = __require("stream");
|
|
32949
|
-
var { createHash:
|
|
32953
|
+
var { createHash: createHash29 } = __require("crypto");
|
|
32950
32954
|
var extension2 = require_extension();
|
|
32951
32955
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
32952
32956
|
var subprotocol2 = require_subprotocol();
|
|
@@ -33253,7 +33257,7 @@ var require_websocket_server = __commonJS({
|
|
|
33253
33257
|
);
|
|
33254
33258
|
}
|
|
33255
33259
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
33256
|
-
const digest2 =
|
|
33260
|
+
const digest2 = createHash29("sha1").update(key4 + GUID).digest("base64");
|
|
33257
33261
|
const headers = [
|
|
33258
33262
|
"HTTP/1.1 101 Switching Protocols",
|
|
33259
33263
|
"Upgrade: websocket",
|
|
@@ -36340,7 +36344,12 @@ __export(sudo_exports, {
|
|
|
36340
36344
|
askpassPath: () => askpassPath,
|
|
36341
36345
|
askpassScript: () => askpassScript,
|
|
36342
36346
|
connectionHolders: () => connectionHolders,
|
|
36347
|
+
deliverToListener: () => deliverToListener,
|
|
36348
|
+
deliveryFrom: () => deliveryFrom,
|
|
36343
36349
|
installAskpass: () => installAskpass,
|
|
36350
|
+
listenerHolders: () => listenerHolders,
|
|
36351
|
+
listeningInode: () => listeningInode,
|
|
36352
|
+
newDelivery: () => newDelivery,
|
|
36344
36353
|
processStart: () => processStart,
|
|
36345
36354
|
readProcess: () => readProcess,
|
|
36346
36355
|
removeAskpass: () => removeAskpass,
|
|
@@ -36351,11 +36360,12 @@ __export(sudo_exports, {
|
|
|
36351
36360
|
verifyAsker: () => verifyAsker
|
|
36352
36361
|
});
|
|
36353
36362
|
import { execFile as execFile7 } from "node:child_process";
|
|
36354
|
-
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
36363
|
+
import { randomBytes as randomBytes3, randomUUID as randomUUID6, timingSafeEqual } from "node:crypto";
|
|
36355
36364
|
import { EventEmitter } from "node:events";
|
|
36356
36365
|
import { existsSync as existsSync10, readlinkSync } from "node:fs";
|
|
36357
36366
|
import { open as open10, readdir as readdir10, readFile as readFile16, readlink as readlink2, unlink as unlink3 } from "node:fs/promises";
|
|
36358
36367
|
import { request as request2 } from "node:http";
|
|
36368
|
+
import { createConnection, createServer } from "node:net";
|
|
36359
36369
|
import path32 from "node:path";
|
|
36360
36370
|
import { promisify as promisify6 } from "node:util";
|
|
36361
36371
|
import { userInfo as userInfo3 } from "node:os";
|
|
@@ -36443,29 +36453,32 @@ async function readProcess(pid) {
|
|
|
36443
36453
|
return void 0;
|
|
36444
36454
|
}
|
|
36445
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
|
+
}
|
|
36446
36476
|
async function stdoutReaders(pid, allowed) {
|
|
36447
36477
|
try {
|
|
36448
36478
|
if (process.platform === "linux") {
|
|
36449
36479
|
const target = await readlink2(`/proc/${pid}/fd/1`);
|
|
36450
36480
|
if (!/^pipe:\[\d+\]$/.test(target)) return "other";
|
|
36451
|
-
|
|
36452
|
-
let next = 0, other = false;
|
|
36453
|
-
await Promise.all(Array.from({ length: Math.min(16, holders.length) }, async () => {
|
|
36454
|
-
while (!other && next < holders.length) {
|
|
36455
|
-
const holder2 = holders[next++];
|
|
36456
|
-
const fds = await readdir10(`/proc/${holder2}/fd`).catch(() => []);
|
|
36457
|
-
for (const fd of fds) {
|
|
36458
|
-
try {
|
|
36459
|
-
if (readlinkSync(`/proc/${holder2}/fd/${fd}`) === target) {
|
|
36460
|
-
other = true;
|
|
36461
|
-
break;
|
|
36462
|
-
}
|
|
36463
|
-
} catch {
|
|
36464
|
-
}
|
|
36465
|
-
}
|
|
36466
|
-
}
|
|
36467
|
-
}));
|
|
36468
|
-
return other ? "other" : "sudo";
|
|
36481
|
+
return await heldElsewhere(target, [pid, ...allowed]) ? "other" : "sudo";
|
|
36469
36482
|
}
|
|
36470
36483
|
const own2 = await exec6("lsof", ["-nP", "-a", "-p", String(pid), "-d", "1", "-F", "tdn"], { timeout: 5e3, maxBuffer: 65536 });
|
|
36471
36484
|
const type = /^t(.+)$/m.exec(own2.stdout)?.[1], peer = /^n->(0x[0-9a-f]+)$/m.exec(own2.stdout)?.[1];
|
|
@@ -36503,6 +36516,67 @@ async function processStart(pid) {
|
|
|
36503
36516
|
const stat30 = await readFile16(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
|
|
36504
36517
|
return stat30?.slice(stat30.lastIndexOf(")") + 2).split(" ")[19];
|
|
36505
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
|
+
}
|
|
36506
36580
|
async function writeToAsker(pid, start, password) {
|
|
36507
36581
|
if (await processStart(pid) !== start) return { status: 410, error: "askpass went away." };
|
|
36508
36582
|
try {
|
|
@@ -36542,23 +36616,25 @@ function placeFrom(value2) {
|
|
|
36542
36616
|
if (!fields2.every((key4) => typeof item[key4] === "string" && placeName.test(item[key4]))) return void 0;
|
|
36543
36617
|
return Object.fromEntries(fields2.map((key4) => [key4, item[key4]]));
|
|
36544
36618
|
}
|
|
36545
|
-
async function defaultVerify(pid, hookFd) {
|
|
36619
|
+
async function defaultVerify(pid, hookFd, delivery) {
|
|
36546
36620
|
const linux = process.platform === "linux";
|
|
36547
36621
|
const running2 = process.argv[1] ? [path32.resolve(process.argv[1])] : [];
|
|
36548
36622
|
const start = linux ? await processStart(pid) : void 0;
|
|
36623
|
+
const inode = linux && delivery ? await listeningInode(delivery.socket) : void 0;
|
|
36549
36624
|
const result = await verifyAsker(pid, {
|
|
36550
36625
|
processes: readProcess,
|
|
36551
36626
|
stdout: stdoutReaders,
|
|
36552
36627
|
node: process.execPath,
|
|
36553
36628
|
script: askpassPath(),
|
|
36554
36629
|
bundles: [.../* @__PURE__ */ new Set([path32.join(bridgeRoot(), "current/bridge-hook.mjs"), ...running2])],
|
|
36555
|
-
// On Linux the password goes to the asker's
|
|
36556
|
-
|
|
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),
|
|
36557
36633
|
// The real-Hook tests stand a copy of bash named sudo in for sudo, which cannot run as root.
|
|
36558
36634
|
unprivilegedSudo: process.env.NODE_ENV === "test" && process.env.PHREN_SUDO_TEST_PARENT === "1"
|
|
36559
36635
|
});
|
|
36560
36636
|
if ("refused" in result) return result;
|
|
36561
|
-
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) };
|
|
36562
36638
|
}
|
|
36563
36639
|
function userName() {
|
|
36564
36640
|
try {
|
|
@@ -36582,12 +36658,63 @@ function sudoAnswer(data) {
|
|
|
36582
36658
|
async function askpass(prompt, env = process.env) {
|
|
36583
36659
|
const place = await terminalPaneFromEnv(env).catch(() => void 0);
|
|
36584
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) {
|
|
36585
36711
|
const data = JSON.stringify({
|
|
36586
36712
|
pid: process.pid,
|
|
36587
36713
|
cwd: process.cwd(),
|
|
36588
36714
|
...prompt ? { prompt: prompt.slice(0, 200) } : {},
|
|
36589
36715
|
...place ? { place } : {},
|
|
36590
|
-
...dispatchId ? { dispatchId } : {}
|
|
36716
|
+
...dispatchId ? { dispatchId } : {},
|
|
36717
|
+
...listener ? { delivery: listener.delivery } : {}
|
|
36591
36718
|
});
|
|
36592
36719
|
const reply = await new Promise((resolve14) => {
|
|
36593
36720
|
const req = request2({
|
|
@@ -36641,7 +36768,7 @@ async function runSudo(args) {
|
|
|
36641
36768
|
child.on("exit", (code, signal) => resolve14(code ?? (signal ? 128 + ({ SIGINT: 2, SIGTERM: 15, SIGKILL: 9, SIGHUP: 1 }[signal] ?? 1) : 1)));
|
|
36642
36769
|
});
|
|
36643
36770
|
}
|
|
36644
|
-
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;
|
|
36645
36772
|
var init_sudo = __esm({
|
|
36646
36773
|
"src/bridge/sudo.ts"() {
|
|
36647
36774
|
"use strict";
|
|
@@ -36687,6 +36814,8 @@ var init_sudo = __esm({
|
|
|
36687
36814
|
]);
|
|
36688
36815
|
SHORT_VALUE = /* @__PURE__ */ new Set([..."ugpCDhrtTUcR"]);
|
|
36689
36816
|
exec6 = promisify6(execFile7);
|
|
36817
|
+
DELIVERY_SOCKET = /^phren-askpass-[0-9a-f]{32}$/;
|
|
36818
|
+
DELIVERY_NONCE = /^[0-9a-f]{64}$/;
|
|
36690
36819
|
PRELOADS = ["LD_PRELOAD", "DYLD_INSERT_LIBRARIES"];
|
|
36691
36820
|
NODE_LOADERS = [...PRELOADS, "NODE_OPTIONS"];
|
|
36692
36821
|
placeName = /^[A-Za-z0-9_.:%@-]{1,128}$/;
|
|
@@ -36728,7 +36857,7 @@ var init_sudo = __esm({
|
|
|
36728
36857
|
async ask(body2, respond, hookFd) {
|
|
36729
36858
|
const none = { cancel: () => {
|
|
36730
36859
|
} };
|
|
36731
|
-
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));
|
|
36732
36861
|
if ("refused" in verified2) {
|
|
36733
36862
|
respond({ status: 400, error: verified2.refused });
|
|
36734
36863
|
return none;
|
|
@@ -37426,7 +37555,7 @@ var init_package_metadata = __esm({
|
|
|
37426
37555
|
__dirname = path37.dirname(fileURLToPath2(import.meta.url));
|
|
37427
37556
|
ROOT = path37.join(__dirname, "..");
|
|
37428
37557
|
PACKAGE_JSON_PATH = path37.join(ROOT, "package.json");
|
|
37429
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
37558
|
+
BUNDLED_VERSION = true ? "0.3.36" : "0.0.0";
|
|
37430
37559
|
PACKAGE_JSON = readPackageJson();
|
|
37431
37560
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
37432
37561
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -41153,16 +41282,16 @@ function projectAuthority(policy, project) {
|
|
|
41153
41282
|
const entry2 = Object.hasOwn(policy.projects, project) ? policy.projects[project] : void 0;
|
|
41154
41283
|
const verdictOf = (action) => entry2?.actions?.[action] ?? entry2?.default ?? "go";
|
|
41155
41284
|
const go = RELEASE_ACTIONS.filter((action) => verdictOf(action) === "go");
|
|
41156
|
-
const
|
|
41157
|
-
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);
|
|
41158
41287
|
const parts = [
|
|
41159
41288
|
...!entry2 ? ["no release restrictions listed"] : [],
|
|
41160
41289
|
...entry2 && go.length ? [`go for ${go.join(", ")}`] : [],
|
|
41161
|
-
...
|
|
41290
|
+
...ask2.length ? [`ask-first for ${ask2.join(", ")}`] : [],
|
|
41162
41291
|
...maxPermissionMode ? [`dispatched workers start at most in ${maxPermissionMode}`] : []
|
|
41163
41292
|
];
|
|
41164
41293
|
const line = `Release authority for ${project} (owner policy): ${parts.join("; ")}.${entry2?.note ? ` Note: ${entry2.note}` : ""}`;
|
|
41165
|
-
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 };
|
|
41166
41295
|
}
|
|
41167
41296
|
function lowerMode(a, b) {
|
|
41168
41297
|
if (!a || !b) return a ?? b;
|
|
@@ -41920,6 +42049,39 @@ var init_policy = __esm({
|
|
|
41920
42049
|
}
|
|
41921
42050
|
});
|
|
41922
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
|
+
|
|
41923
42085
|
// src/bridge/schedule-format.ts
|
|
41924
42086
|
import { readFile as readFile28 } from "node:fs/promises";
|
|
41925
42087
|
import path57 from "node:path";
|
|
@@ -43014,7 +43176,7 @@ var init_schedules = __esm({
|
|
|
43014
43176
|
});
|
|
43015
43177
|
|
|
43016
43178
|
// src/bridge/health.ts
|
|
43017
|
-
import { execFile as
|
|
43179
|
+
import { execFile as execFile12, spawn as spawn8 } from "node:child_process";
|
|
43018
43180
|
import { lstat as lstat16, readFile as readFile30 } from "node:fs/promises";
|
|
43019
43181
|
import { homedir as homedir14, hostname as hostname6 } from "node:os";
|
|
43020
43182
|
import path60 from "node:path";
|
|
@@ -43138,8 +43300,9 @@ async function lastScheduledRun(store, runsFile = scheduleRunsFile()) {
|
|
|
43138
43300
|
};
|
|
43139
43301
|
}
|
|
43140
43302
|
async function ownHostKey() {
|
|
43303
|
+
const line = await localHostKeyLine();
|
|
43141
43304
|
try {
|
|
43142
|
-
return publicComputerKey(
|
|
43305
|
+
return line ? publicComputerKey(line) : void 0;
|
|
43143
43306
|
} catch {
|
|
43144
43307
|
return void 0;
|
|
43145
43308
|
}
|
|
@@ -43247,12 +43410,13 @@ var init_health = __esm({
|
|
|
43247
43410
|
init_phren_paths();
|
|
43248
43411
|
init_store_registry();
|
|
43249
43412
|
init_computers();
|
|
43413
|
+
init_host_key();
|
|
43250
43414
|
init_peers();
|
|
43251
43415
|
init_protocol();
|
|
43252
43416
|
init_schedules();
|
|
43253
43417
|
init_metrics();
|
|
43254
43418
|
init_terminal_tmux();
|
|
43255
|
-
exec10 = promisify10(
|
|
43419
|
+
exec10 = promisify10(execFile12);
|
|
43256
43420
|
VERSION_TIMEOUT_MS = 3e3;
|
|
43257
43421
|
VERSION_CACHE_MS = 5 * 6e4;
|
|
43258
43422
|
PEER_TIMEOUT_MS = 5e3;
|
|
@@ -43269,10 +43433,10 @@ async function localCaller() {
|
|
|
43269
43433
|
function callerQuery(caller) {
|
|
43270
43434
|
return new URLSearchParams({ name: caller.name, ...caller.hostKey ? { hostKey: caller.hostKey } : {} }).toString();
|
|
43271
43435
|
}
|
|
43272
|
-
async function askPeers(peers, caller,
|
|
43436
|
+
async function askPeers(peers, caller, ask2 = peerRequest) {
|
|
43273
43437
|
return Promise.all(peers.map(async (peer) => {
|
|
43274
43438
|
try {
|
|
43275
|
-
const answer = await
|
|
43439
|
+
const answer = await ask2(peer, `/v1/conductor?${callerQuery(caller)}`, void 0, 8e3);
|
|
43276
43440
|
const computer = object2(answer.computer);
|
|
43277
43441
|
const conductor = answer.conductor && typeof answer.conductor === "object" ? object2(answer.conductor) : void 0;
|
|
43278
43442
|
const set2 = object2(answer.set);
|
|
@@ -43315,8 +43479,8 @@ function setConductor(answers, localNames2) {
|
|
|
43315
43479
|
]
|
|
43316
43480
|
};
|
|
43317
43481
|
}
|
|
43318
|
-
async function groupConductor(peers, localNames2,
|
|
43319
|
-
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);
|
|
43320
43484
|
}
|
|
43321
43485
|
function conductorOf(entries2) {
|
|
43322
43486
|
const running2 = entries2.filter((entry2) => entry2.conductor);
|
|
@@ -44265,141 +44429,81 @@ var init_dispatch = __esm({
|
|
|
44265
44429
|
}
|
|
44266
44430
|
});
|
|
44267
44431
|
|
|
44268
|
-
// src/bridge/
|
|
44269
|
-
import { createHash as createHash14
|
|
44270
|
-
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";
|
|
44271
44435
|
import path64 from "node:path";
|
|
44272
|
-
|
|
44273
|
-
|
|
44274
|
-
|
|
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"() {
|
|
44275
44499
|
"use strict";
|
|
44276
44500
|
init_zod();
|
|
44277
44501
|
init_protocol();
|
|
44278
|
-
|
|
44279
|
-
|
|
44280
|
-
|
|
44281
|
-
|
|
44282
|
-
|
|
44283
|
-
kind: external_exports.enum(["manual", "needs-you", "blocked"]),
|
|
44284
|
-
title,
|
|
44285
|
-
createdAt: external_exports.string().datetime(),
|
|
44286
|
-
updatedAt: external_exports.string().datetime(),
|
|
44287
|
-
state: external_exports.enum(["open", "resolved"]),
|
|
44288
|
-
resolvedAt: external_exports.string().datetime().optional(),
|
|
44289
|
-
resolution: external_exports.string().max(2e3).optional(),
|
|
44290
|
-
project: external_exports.string().max(200).optional(),
|
|
44291
|
-
computer: external_exports.string().max(253).optional(),
|
|
44292
|
-
target: inboxTargetSchema.optional(),
|
|
44293
|
-
dispatch: external_exports.string().uuid().optional(),
|
|
44294
|
-
actionId: external_exports.string().max(200).optional(),
|
|
44295
|
-
source: external_exports.string().max(500).optional(),
|
|
44296
|
-
live: external_exports.boolean().optional()
|
|
44297
|
-
}).strict();
|
|
44298
|
-
ownerInboxSchema = external_exports.object({
|
|
44299
|
-
action: external_exports.enum(["add", "list", "resolve"]).default("list"),
|
|
44300
|
-
title: title.optional(),
|
|
44301
|
-
project: external_exports.string().max(200).optional(),
|
|
44302
|
-
id: external_exports.string().uuid().optional(),
|
|
44303
|
-
resolution: external_exports.string().max(2e3).optional(),
|
|
44304
|
-
includeResolved: external_exports.boolean().optional(),
|
|
44305
|
-
computer: computerName.optional()
|
|
44306
|
-
}).strict();
|
|
44307
|
-
uuidOf = (source) => {
|
|
44308
|
-
const h = createHash14("sha256").update(source).digest("hex");
|
|
44309
|
-
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
44310
|
-
};
|
|
44311
|
-
OwnerInbox = class {
|
|
44312
|
-
constructor(sources = async () => [], file4 = path64.join(bridgeRoot(), "owner-inbox.json")) {
|
|
44313
|
-
this.sources = sources;
|
|
44314
|
-
this.file = file4;
|
|
44315
|
-
}
|
|
44316
|
-
sources;
|
|
44317
|
-
file;
|
|
44318
|
-
pending = Promise.resolve();
|
|
44319
|
-
async read() {
|
|
44320
|
-
const info = await lstat18(this.file).catch((error62) => {
|
|
44321
|
-
if (error62.code === "ENOENT") return void 0;
|
|
44322
|
-
throw error62;
|
|
44323
|
-
});
|
|
44324
|
-
if (!info) return [];
|
|
44325
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > 4 * 1024 * 1024) throw new BridgeError(409, "The owner inbox cannot be read safely.");
|
|
44326
|
-
return external_exports.array(itemSchema).max(1e4).parse(JSON.parse(await readFile32(this.file, "utf8")));
|
|
44327
|
-
}
|
|
44328
|
-
run(input2) {
|
|
44329
|
-
const run2 = this.pending.then(async () => {
|
|
44330
|
-
const data = ownerInboxSchema.parse(input2), rows = await this.read(), at = (/* @__PURE__ */ new Date()).toISOString();
|
|
44331
|
-
const sources = [];
|
|
44332
|
-
for (const receipt of await dispatchStatus()) {
|
|
44333
|
-
const returned = receipt.returned;
|
|
44334
|
-
if (receipt.closedAt || !returned || !["needs-you", "blocked"].includes(returned.state)) continue;
|
|
44335
|
-
if (receipt.worker && receipt.worker.state !== returned.state && !receipt.approval) continue;
|
|
44336
|
-
const actionId = receipt.approval?.actionId;
|
|
44337
|
-
sources.push({
|
|
44338
|
-
source: `dispatch:${receipt.id}:${actionId ?? returned.at}`,
|
|
44339
|
-
kind: returned.state,
|
|
44340
|
-
title: (receipt.approval?.request ?? returned.question ?? returned.reply ?? `${receipt.label} needs input`).replace(/[\x00-\x1f\x7f]+/g, " ").slice(0, 500),
|
|
44341
|
-
project: receipt.project,
|
|
44342
|
-
computer: receipt.computer,
|
|
44343
|
-
..."session" in (receipt.target ?? {}) ? { target: receipt.target } : {},
|
|
44344
|
-
dispatch: receipt.id,
|
|
44345
|
-
...actionId ? { actionId } : {}
|
|
44346
|
-
});
|
|
44347
|
-
}
|
|
44348
|
-
for (const source of await this.sources()) {
|
|
44349
|
-
if (source.actionId && sources.some((other) => other.actionId === source.actionId && JSON.stringify(other.target) === JSON.stringify(source.target))) continue;
|
|
44350
|
-
sources.push(source);
|
|
44351
|
-
}
|
|
44352
|
-
let changed2 = false;
|
|
44353
|
-
const live = new Set(sources.map((s) => s.source));
|
|
44354
|
-
for (const row of rows) if (row.source && row.live !== live.has(row.source)) {
|
|
44355
|
-
row.live = live.has(row.source);
|
|
44356
|
-
row.updatedAt = at;
|
|
44357
|
-
changed2 = true;
|
|
44358
|
-
}
|
|
44359
|
-
for (const source of sources) {
|
|
44360
|
-
const existing = rows.find((row) => row.source === source.source);
|
|
44361
|
-
if (existing) continue;
|
|
44362
|
-
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
44363
|
-
rows.push(itemSchema.parse({ ...source, id: uuidOf(source.source), state: "open", live: true, createdAt: at, updatedAt: at }));
|
|
44364
|
-
changed2 = true;
|
|
44365
|
-
}
|
|
44366
|
-
if (data.action === "add") {
|
|
44367
|
-
if (!data.title) throw new BridgeError(400, "Name the owner inbox item.");
|
|
44368
|
-
const item = itemSchema.parse({ id: data.id ?? randomUUID13(), kind: "manual", title: data.title, state: "open", createdAt: at, updatedAt: at, ...data.project ? { project: data.project } : {} });
|
|
44369
|
-
const prior = rows.find((row) => row.id === item.id);
|
|
44370
|
-
if (prior && (prior.title !== item.title || prior.project !== item.project || prior.kind !== "manual")) throw new BridgeError(409, "This inbox id names another item.");
|
|
44371
|
-
if (!prior) {
|
|
44372
|
-
if (rows.length >= 1e4) throw new BridgeError(409, "The owner inbox is full.");
|
|
44373
|
-
rows.push(item);
|
|
44374
|
-
changed2 = true;
|
|
44375
|
-
}
|
|
44376
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44377
|
-
return { ok: true, item: prior ?? item };
|
|
44378
|
-
}
|
|
44379
|
-
if (data.action === "resolve") {
|
|
44380
|
-
const item = rows.find((row) => row.id === data.id);
|
|
44381
|
-
if (!item) throw new BridgeError(404, "No owner inbox item with that id.");
|
|
44382
|
-
if (item.state !== "resolved") {
|
|
44383
|
-
item.state = "resolved";
|
|
44384
|
-
item.resolvedAt = at;
|
|
44385
|
-
item.updatedAt = at;
|
|
44386
|
-
item.resolution = data.resolution;
|
|
44387
|
-
changed2 = true;
|
|
44388
|
-
}
|
|
44389
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44390
|
-
return { ok: true, item };
|
|
44391
|
-
}
|
|
44392
|
-
if (changed2) await atomicInPrivateDir(this.file, rows);
|
|
44393
|
-
return { ok: true, items: rows.filter((row) => data.includeResolved || row.state === "open").sort((a, b) => a.createdAt.localeCompare(b.createdAt)) };
|
|
44394
|
-
});
|
|
44395
|
-
this.pending = run2.catch(() => {
|
|
44396
|
-
});
|
|
44397
|
-
return run2;
|
|
44398
|
-
}
|
|
44399
|
-
async tick() {
|
|
44400
|
-
await this.run({ action: "list" });
|
|
44401
|
-
}
|
|
44402
|
-
};
|
|
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`);
|
|
44403
44507
|
}
|
|
44404
44508
|
});
|
|
44405
44509
|
|
|
@@ -44408,23 +44512,32 @@ import { createHash as createHash15 } from "node:crypto";
|
|
|
44408
44512
|
import { lstat as lstat19, readFile as readFile33 } from "node:fs/promises";
|
|
44409
44513
|
import path65 from "node:path";
|
|
44410
44514
|
async function reportWorker(input2) {
|
|
44411
|
-
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);
|
|
44412
44516
|
const pane = findPane(await snapshot(data.origin.server), data.origin);
|
|
44413
44517
|
if (!pane) throw new BridgeError(409, "The worker pane changed.");
|
|
44414
44518
|
const session = await paneIdentity(data.origin.server, pane, true);
|
|
44415
44519
|
const target = targetSchema.parse({ ...data.origin, source: pane.agent, session });
|
|
44416
44520
|
await validateTarget(target, false, true);
|
|
44417
44521
|
const record3 = await paneTurn(target.server, pane, target.source);
|
|
44418
|
-
|
|
44419
|
-
|
|
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() }));
|
|
44420
44526
|
return { ok: true, target, prs: data.prs };
|
|
44421
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
|
+
}
|
|
44422
44533
|
async function workerPrs(target, record3) {
|
|
44423
44534
|
try {
|
|
44424
44535
|
const file4 = reportFile(target), info = await lstat19(file4);
|
|
44425
44536
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 131072) return void 0;
|
|
44426
44537
|
const report = reportSchema.parse(JSON.parse(await readFile33(file4, "utf8")));
|
|
44427
|
-
|
|
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;
|
|
44428
44541
|
} catch (error62) {
|
|
44429
44542
|
if (error62.code !== "ENOENT") throw error62;
|
|
44430
44543
|
return void 0;
|
|
@@ -44457,9 +44570,10 @@ var init_worker_reports = __esm({
|
|
|
44457
44570
|
init_herdr();
|
|
44458
44571
|
init_dispatch();
|
|
44459
44572
|
init_dispatch_returns();
|
|
44573
|
+
init_launch_brief();
|
|
44460
44574
|
init_return_contract();
|
|
44461
44575
|
init_return_contract();
|
|
44462
|
-
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();
|
|
44463
44577
|
key2 = (target) => createHash15("sha256").update(JSON.stringify([target.server, target.workspace, target.tab, target.pane, target.source, target.session])).digest("hex");
|
|
44464
44578
|
reportFile = (target) => path65.join(bridgeRoot(), "worker-reports", `${key2(target)}.json`);
|
|
44465
44579
|
}
|
|
@@ -44713,7 +44827,7 @@ var init_approval_summary = __esm({
|
|
|
44713
44827
|
});
|
|
44714
44828
|
|
|
44715
44829
|
// src/bridge/hand-off.ts
|
|
44716
|
-
import { randomUUID as
|
|
44830
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
44717
44831
|
function labelOf(group, tab) {
|
|
44718
44832
|
const folder = typeof tab.cwd === "string" && tab.role !== "conductor" ? tab.cwd.split("/").filter(Boolean).at(-1) : void 0;
|
|
44719
44833
|
return folder || (typeof group.label === "string" && group.label ? group.label : void 0);
|
|
@@ -44764,7 +44878,7 @@ async function handOff(input2, options = {}) {
|
|
|
44764
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);
|
|
44765
44879
|
}
|
|
44766
44880
|
const originComputer = peer && origin ? await hookRequest("/v1/health").then((health2) => object2(health2.computer).name, () => void 0) : void 0;
|
|
44767
|
-
const deliveryId = data.deliveryId ?? options.deliveryId ??
|
|
44881
|
+
const deliveryId = data.deliveryId ?? options.deliveryId ?? randomUUID13().replaceAll("-", "");
|
|
44768
44882
|
const result = await request9(data.status ? "/v1/hand-off/status" : "/v1/hand-off", {
|
|
44769
44883
|
target,
|
|
44770
44884
|
deliveryId,
|
|
@@ -44883,7 +44997,7 @@ var init_hand_off = __esm({
|
|
|
44883
44997
|
});
|
|
44884
44998
|
|
|
44885
44999
|
// src/bridge/worker-unfinished.ts
|
|
44886
|
-
import { execFile as
|
|
45000
|
+
import { execFile as execFile13 } from "node:child_process";
|
|
44887
45001
|
import { lstat as lstat20 } from "node:fs/promises";
|
|
44888
45002
|
import path67 from "node:path";
|
|
44889
45003
|
import { promisify as promisify11 } from "node:util";
|
|
@@ -44981,7 +45095,7 @@ var init_worker_unfinished = __esm({
|
|
|
44981
45095
|
"use strict";
|
|
44982
45096
|
init_utils_helpers();
|
|
44983
45097
|
init_metrics();
|
|
44984
|
-
exec11 = promisify11(
|
|
45098
|
+
exec11 = promisify11(execFile13);
|
|
44985
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;
|
|
44986
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;
|
|
44987
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;
|
|
@@ -45259,16 +45373,16 @@ function observeState(receipt, parsed, now) {
|
|
|
45259
45373
|
return true;
|
|
45260
45374
|
}
|
|
45261
45375
|
function noticeLine(receipts) {
|
|
45262
|
-
const
|
|
45376
|
+
const clean3 = (value2, max) => value2.replace(/[\x00-\x1f\x7f]+/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
|
|
45263
45377
|
const word = { "done": "done", "needs-you": "needs you", "failed": "failed", "blocked": "blocked", "gone": "gone", "stalled": "stalled" };
|
|
45264
45378
|
const describe4 = (receipt, room) => {
|
|
45265
45379
|
const returned = receipt.returned;
|
|
45266
45380
|
const asking = returned.state === "blocked" ? receipt.approval : void 0;
|
|
45267
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;
|
|
45268
|
-
const excerpt = detail ?
|
|
45382
|
+
const excerpt = detail ? clean3(detail.replace(/[*_`#>]+/g, ""), room) : "";
|
|
45269
45383
|
const tasks = (count2) => `${count2} background task${count2 === 1 ? "" : "s"}`;
|
|
45270
45384
|
const left = returned.background ? ` (${tasks(returned.background)} still running)` : returned.waited ? ` (after ${tasks(returned.waited)} finished)` : "";
|
|
45271
|
-
return `${
|
|
45385
|
+
return `${clean3(receipt.computer, 60)} ${clean3(receipt.label, 80)} ${asking ? "needs approval" : word[returned.state]}${left}${excerpt ? `, ${excerpt}` : ""}`;
|
|
45272
45386
|
};
|
|
45273
45387
|
if (receipts.length === 1) {
|
|
45274
45388
|
const [only] = receipts;
|
|
@@ -45686,86 +45800,279 @@ ${JSON.stringify({ dispatch: receipt.id, project: receipt.project, prs: result.p
|
|
|
45686
45800
|
}
|
|
45687
45801
|
});
|
|
45688
45802
|
|
|
45689
|
-
// src/bridge/
|
|
45690
|
-
import {
|
|
45691
|
-
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";
|
|
45692
45806
|
import path68 from "node:path";
|
|
45693
|
-
|
|
45694
|
-
|
|
45695
|
-
|
|
45696
|
-
|
|
45697
|
-
|
|
45698
|
-
|
|
45699
|
-
|
|
45700
|
-
|
|
45701
|
-
|
|
45702
|
-
|
|
45703
|
-
|
|
45704
|
-
|
|
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
|
+
};
|
|
45705
45971
|
}
|
|
45706
|
-
}
|
|
45707
|
-
|
|
45708
|
-
|
|
45709
|
-
|
|
45710
|
-
|
|
45711
|
-
|
|
45712
|
-
|
|
45713
|
-
pane
|
|
45714
|
-
|
|
45715
|
-
|
|
45716
|
-
|
|
45717
|
-
|
|
45718
|
-
|
|
45719
|
-
|
|
45720
|
-
|
|
45721
|
-
|
|
45722
|
-
|
|
45723
|
-
|
|
45724
|
-
|
|
45725
|
-
|
|
45726
|
-
|
|
45727
|
-
|
|
45728
|
-
}
|
|
45729
|
-
|
|
45730
|
-
|
|
45731
|
-
|
|
45732
|
-
|
|
45733
|
-
|
|
45734
|
-
|
|
45735
|
-
|
|
45736
|
-
|
|
45737
|
-
|
|
45738
|
-
|
|
45739
|
-
|
|
45740
|
-
|
|
45741
|
-
|
|
45742
|
-
|
|
45743
|
-
await markWorkerClosed(data.target, String(pane.terminal_id));
|
|
45744
|
-
try {
|
|
45745
|
-
await terminalProvider().closePane(data.target.server, data.target.pane);
|
|
45746
|
-
} catch (error62) {
|
|
45747
|
-
const remaining = await snapshot2(data.target.server).catch(() => void 0);
|
|
45748
|
-
if (remaining && findPane2(remaining, data.target)?.terminal_id === pane.terminal_id) await rm9(file2(data.target), { force: true });
|
|
45749
|
-
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
|
+
}
|
|
45750
46009
|
}
|
|
45751
|
-
|
|
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 };
|
|
45752
46057
|
}
|
|
45753
|
-
var
|
|
45754
|
-
var
|
|
45755
|
-
"src/bridge/
|
|
46058
|
+
var clean2;
|
|
46059
|
+
var init_owner_inbox_sources = __esm({
|
|
46060
|
+
"src/bridge/owner-inbox-sources.ts"() {
|
|
45756
46061
|
"use strict";
|
|
45757
|
-
|
|
45758
|
-
|
|
45759
|
-
init_herdr();
|
|
45760
|
-
init_terminal();
|
|
46062
|
+
init_dispatch();
|
|
46063
|
+
init_dispatch_hosts();
|
|
45761
46064
|
init_dispatch_returns();
|
|
45762
|
-
|
|
45763
|
-
|
|
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);
|
|
45764
46071
|
}
|
|
45765
46072
|
});
|
|
45766
46073
|
|
|
45767
46074
|
// src/bridge/hand-off-queue.ts
|
|
45768
|
-
import { createHash as
|
|
46075
|
+
import { createHash as createHash19, randomUUID as randomUUID15 } from "node:crypto";
|
|
45769
46076
|
import { lstat as lstat22, open as open15, readFile as readFile35, readdir as readdir13, unlink as unlink5 } from "node:fs/promises";
|
|
45770
46077
|
import path69 from "node:path";
|
|
45771
46078
|
var queuedHandOffSchema, rowSchema, DAY2, HAND_OFF_RETENTION_MS, HAND_OFF_MAX_ROWS, settled2, samePane, HandOffQueue;
|
|
@@ -46027,7 +46334,7 @@ var init_hand_off_queue = __esm({
|
|
|
46027
46334
|
}));
|
|
46028
46335
|
}
|
|
46029
46336
|
noticeId(row) {
|
|
46030
|
-
return `handoff-notice-${
|
|
46337
|
+
return `handoff-notice-${createHash19("sha256").update(row.deliveryId).digest("hex").slice(0, 40)}`;
|
|
46031
46338
|
}
|
|
46032
46339
|
/** Hold enqueues and delivery while the Hook validates and closes a worker.
|
|
46033
46340
|
* A new hand-off cannot be accepted between the pending check and closure. */
|
|
@@ -46045,8 +46352,8 @@ var init_hand_off_queue = __esm({
|
|
|
46045
46352
|
});
|
|
46046
46353
|
|
|
46047
46354
|
// src/bridge/git.ts
|
|
46048
|
-
import { createHash as
|
|
46049
|
-
import { execFile as
|
|
46355
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
46356
|
+
import { execFile as execFile14 } from "node:child_process";
|
|
46050
46357
|
import { lstat as lstat23, open as open16, readdir as readdir14, realpath as realpath11 } from "node:fs/promises";
|
|
46051
46358
|
import path70 from "node:path";
|
|
46052
46359
|
import { promisify as promisify12 } from "node:util";
|
|
@@ -46345,9 +46652,9 @@ async function repositoryPath(root, raw, allowRoot = false) {
|
|
|
46345
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.");
|
|
46346
46653
|
const segments = raw.split(/[\\/]/);
|
|
46347
46654
|
if (segments.includes("..") || segments.includes(".git")) throw new BridgeError(400, "Invalid path.");
|
|
46348
|
-
const
|
|
46349
|
-
if (!
|
|
46350
|
-
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);
|
|
46351
46658
|
if (abs !== root && !abs.startsWith(root + path70.sep)) throw new BridgeError(403, "This path is outside the repository.");
|
|
46352
46659
|
let existing = abs;
|
|
46353
46660
|
while (true) {
|
|
@@ -46366,7 +46673,7 @@ async function repositoryPath(root, raw, allowRoot = false) {
|
|
|
46366
46673
|
throw new BridgeError(403, "This path cannot be resolved inside the repository.");
|
|
46367
46674
|
}
|
|
46368
46675
|
if (resolved !== root && !resolved.startsWith(root + path70.sep)) throw new BridgeError(403, "This path is outside the repository.");
|
|
46369
|
-
return
|
|
46676
|
+
return clean3;
|
|
46370
46677
|
}
|
|
46371
46678
|
function invalidateTree(root) {
|
|
46372
46679
|
treeCache.delete(root);
|
|
@@ -46414,7 +46721,7 @@ async function treeSnapshot(root, head) {
|
|
|
46414
46721
|
parent = full2;
|
|
46415
46722
|
}
|
|
46416
46723
|
}
|
|
46417
|
-
const version3 =
|
|
46724
|
+
const version3 = createHash20("sha256").update(head).update(tracked).update(porcelain).digest("hex");
|
|
46418
46725
|
return { version: version3, levels: new Map([...levels].map(([directory, entries2]) => [
|
|
46419
46726
|
directory,
|
|
46420
46727
|
[...entries2.values()].sort((a, b) => a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === "dir" ? -1 : 1)
|
|
@@ -46488,8 +46795,8 @@ async function repositoryPaths(root, raw, limit = 64) {
|
|
|
46488
46795
|
if (!list.length || list.length > limit) throw new BridgeError(400, `Choose between 1 and ${limit} paths.`);
|
|
46489
46796
|
const paths = [];
|
|
46490
46797
|
for (const entry2 of list) {
|
|
46491
|
-
const
|
|
46492
|
-
if (
|
|
46798
|
+
const clean3 = await repositoryPath(root, entry2);
|
|
46799
|
+
if (clean3 && !paths.includes(clean3)) paths.push(clean3);
|
|
46493
46800
|
}
|
|
46494
46801
|
if (!paths.length) throw new BridgeError(400, `Choose between 1 and ${limit} paths.`);
|
|
46495
46802
|
return paths;
|
|
@@ -46555,7 +46862,7 @@ var init_git = __esm({
|
|
|
46555
46862
|
"use strict";
|
|
46556
46863
|
init_protocol();
|
|
46557
46864
|
init_projects();
|
|
46558
|
-
exec12 = promisify12(
|
|
46865
|
+
exec12 = promisify12(execFile14);
|
|
46559
46866
|
UNKNOWN_COUNTS = { additions: 0, deletions: 0, countsComplete: false };
|
|
46560
46867
|
NO_DIFF2 = ["diff", "--no-ext-diff", "--no-textconv", "--no-color"];
|
|
46561
46868
|
MAX_STATUS_ROWS = 500;
|
|
@@ -46568,12 +46875,12 @@ var init_git = __esm({
|
|
|
46568
46875
|
});
|
|
46569
46876
|
|
|
46570
46877
|
// src/bridge/git-worktrees.ts
|
|
46571
|
-
import { createHash as
|
|
46878
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
46572
46879
|
import { realpath as realpath12, stat as stat18 } from "node:fs/promises";
|
|
46573
46880
|
import { homedir as homedir15 } from "node:os";
|
|
46574
46881
|
import path71 from "node:path";
|
|
46575
46882
|
function worktreeId(abs) {
|
|
46576
|
-
return
|
|
46883
|
+
return createHash21("sha256").update(`worktree\0${abs}`).digest("hex").slice(0, 32);
|
|
46577
46884
|
}
|
|
46578
46885
|
async function listed(root) {
|
|
46579
46886
|
const output2 = await git(root, "worktree", "list", "--porcelain", "-z");
|
|
@@ -46833,10 +47140,10 @@ var init_git_publish = __esm({
|
|
|
46833
47140
|
});
|
|
46834
47141
|
|
|
46835
47142
|
// src/bridge/approval-rules.ts
|
|
46836
|
-
import { execFile as
|
|
47143
|
+
import { execFile as execFile15 } from "node:child_process";
|
|
46837
47144
|
import { promisify as promisify13 } from "node:util";
|
|
46838
|
-
import { createHash as
|
|
46839
|
-
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";
|
|
46840
47147
|
import { hostname as hostname8 } from "node:os";
|
|
46841
47148
|
import path72 from "node:path";
|
|
46842
47149
|
async function git4(cwd, ...args) {
|
|
@@ -46863,7 +47170,7 @@ function verified(envelope, keys2) {
|
|
|
46863
47170
|
const key4 = createPublicKey({ key: Buffer.concat([Buffer.from("302a300506032b6570032100", "hex"), raw]), format: "der", type: "spki" });
|
|
46864
47171
|
if (!verify(null, payload, key4, signature)) throw forbidden();
|
|
46865
47172
|
const operation = operationSchema.parse(JSON.parse(payload.toString("utf8")));
|
|
46866
|
-
return { operation, owner:
|
|
47173
|
+
return { operation, owner: createHash22("sha256").update(raw).digest("hex") };
|
|
46867
47174
|
}
|
|
46868
47175
|
async function privateJSON(file4, fallback2, max = 2097152) {
|
|
46869
47176
|
const info = await lstat24(file4).catch((error62) => {
|
|
@@ -46895,7 +47202,7 @@ async function locked(root, work) {
|
|
|
46895
47202
|
const key4 = path72.resolve(root), previous = queues.get(key4) ?? Promise.resolve();
|
|
46896
47203
|
const next = previous.catch(() => {
|
|
46897
47204
|
}).then(async () => {
|
|
46898
|
-
await
|
|
47205
|
+
await mkdir20(key4, { recursive: true, mode: 448 });
|
|
46899
47206
|
const release = tryFileLock(policyPath(key4));
|
|
46900
47207
|
if (!release) throw new BridgeError(409, "Approval rules are busy. Try again.");
|
|
46901
47208
|
try {
|
|
@@ -46913,7 +47220,7 @@ async function locked(root, work) {
|
|
|
46913
47220
|
}
|
|
46914
47221
|
async function listApprovalRules(root = bridgeRoot(), pairedKey) {
|
|
46915
47222
|
try {
|
|
46916
|
-
const pairedOwner = pairedKey ?
|
|
47223
|
+
const pairedOwner = pairedKey ? createHash22("sha256").update(Buffer.from(pairedKey, "base64")).digest("hex") : void 0;
|
|
46917
47224
|
return [...(await readPolicy(root)).rules.values()].map((rule2) => ({
|
|
46918
47225
|
...rule2,
|
|
46919
47226
|
signerFingerprint: "SHA256:" + Buffer.from(rule2.owner, "hex").toString("base64").replace(/=+$/, ""),
|
|
@@ -47000,7 +47307,7 @@ var init_approval_rules = __esm({
|
|
|
47000
47307
|
init_home_paths();
|
|
47001
47308
|
init_locks();
|
|
47002
47309
|
init_protocol();
|
|
47003
|
-
exec13 = promisify13(
|
|
47310
|
+
exec13 = promisify13(execFile15);
|
|
47004
47311
|
text3 = external_exports.string().min(1).max(4096).refine((value2) => !/[\x00-\x1f\x7f]/.test(value2));
|
|
47005
47312
|
scopeSchema = external_exports.object({
|
|
47006
47313
|
project: text3.refine((value2) => path72.isAbsolute(value2) && path72.normalize(value2) === value2),
|
|
@@ -47157,7 +47464,7 @@ var init_codex_thread_origin = __esm({
|
|
|
47157
47464
|
});
|
|
47158
47465
|
|
|
47159
47466
|
// src/bridge/push.ts
|
|
47160
|
-
import { createCipheriv, createHmac as createHmac2, createPrivateKey, randomBytes as
|
|
47467
|
+
import { createCipheriv, createHmac as createHmac2, createPrivateKey, randomBytes as randomBytes4, sign } from "node:crypto";
|
|
47161
47468
|
import { readFile as readFile38, stat as stat19 } from "node:fs/promises";
|
|
47162
47469
|
import { connect as connect3 } from "node:http2";
|
|
47163
47470
|
import path76 from "node:path";
|
|
@@ -47260,7 +47567,7 @@ function upsertPushDevice(devices, value2) {
|
|
|
47260
47567
|
const device = deviceSchema.parse(value2);
|
|
47261
47568
|
return [...devices.filter((item) => item.deviceID !== device.deviceID), device].slice(-16);
|
|
47262
47569
|
}
|
|
47263
|
-
function relayCiphertext(key4, payload, nonce =
|
|
47570
|
+
function relayCiphertext(key4, payload, nonce = randomBytes4(12)) {
|
|
47264
47571
|
const aps = payload.aps ?? {};
|
|
47265
47572
|
let body2 = aps.alert?.body ?? "";
|
|
47266
47573
|
for (; ; ) {
|
|
@@ -47488,7 +47795,7 @@ var init_push = __esm({
|
|
|
47488
47795
|
});
|
|
47489
47796
|
|
|
47490
47797
|
// src/bridge/pair.ts
|
|
47491
|
-
import { execFile as
|
|
47798
|
+
import { execFile as execFile16 } from "node:child_process";
|
|
47492
47799
|
import { homedir as homedir16, hostname as hostname9, networkInterfaces, userInfo as userInfo4 } from "node:os";
|
|
47493
47800
|
import { promisify as promisify14 } from "node:util";
|
|
47494
47801
|
async function computerDisplayName() {
|
|
@@ -47504,9 +47811,10 @@ var init_pair = __esm({
|
|
|
47504
47811
|
"use strict";
|
|
47505
47812
|
init_zod();
|
|
47506
47813
|
init_computers();
|
|
47814
|
+
init_host_key();
|
|
47507
47815
|
init_install();
|
|
47508
47816
|
init_protocol();
|
|
47509
|
-
exec14 = promisify14(
|
|
47817
|
+
exec14 = promisify14(execFile16);
|
|
47510
47818
|
request5 = external_exports.object({
|
|
47511
47819
|
v: external_exports.literal(1),
|
|
47512
47820
|
publicKey: external_exports.string().max(512),
|
|
@@ -47519,7 +47827,7 @@ var init_pair = __esm({
|
|
|
47519
47827
|
|
|
47520
47828
|
// src/bridge/opencode-permissions.ts
|
|
47521
47829
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
47522
|
-
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";
|
|
47523
47831
|
import path77 from "node:path";
|
|
47524
47832
|
function opencodeConfigPath(env = process.env, home = homeDir(env)) {
|
|
47525
47833
|
return path77.join(env.XDG_CONFIG_HOME || path77.join(home, ".config"), "opencode", "opencode.json");
|
|
@@ -47570,7 +47878,7 @@ async function allowOpencodeToolEverywhere(tool, file4 = opencodeConfigPath()) {
|
|
|
47570
47878
|
try {
|
|
47571
47879
|
const config3 = withAllowedTool(await readConfig2(file4), name);
|
|
47572
47880
|
const mode = (await lstat25(file4).catch(() => void 0))?.mode;
|
|
47573
|
-
await
|
|
47881
|
+
await mkdir21(path77.dirname(file4), { recursive: true, mode: 448 });
|
|
47574
47882
|
const temporary = `${file4}.${randomUUID16()}.tmp`;
|
|
47575
47883
|
await writeFile6(temporary, `${JSON.stringify(config3, null, 2)}
|
|
47576
47884
|
`, { mode: mode === void 0 ? 384 : mode & 511, flag: "wx" });
|
|
@@ -47595,7 +47903,7 @@ var init_opencode_permissions = __esm({
|
|
|
47595
47903
|
});
|
|
47596
47904
|
|
|
47597
47905
|
// src/bridge/prompt-deliveries.ts
|
|
47598
|
-
import { createHash as
|
|
47906
|
+
import { createHash as createHash23 } from "node:crypto";
|
|
47599
47907
|
import { readFileSync as readFileSync24 } from "node:fs";
|
|
47600
47908
|
import { open as open19 } from "node:fs/promises";
|
|
47601
47909
|
function promptKey(text5) {
|
|
@@ -47645,7 +47953,7 @@ var init_prompt_deliveries = __esm({
|
|
|
47645
47953
|
DELIVERY_GIVE_UP_MS = 3e4;
|
|
47646
47954
|
MAX_RECORDS = 512;
|
|
47647
47955
|
PICTURE_PATH_LINE = /^\s*\/.*\.(?:png|jpe?g|gif|webp)\s*$/i;
|
|
47648
|
-
promptHash = (text5) =>
|
|
47956
|
+
promptHash = (text5) => createHash23("sha256").update(promptKey(text5)).digest("hex");
|
|
47649
47957
|
recordSchema2 = external_exports.object({
|
|
47650
47958
|
id: external_exports.string().regex(/^[A-Za-z0-9_-]{8,64}$/).optional(),
|
|
47651
47959
|
hash: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
@@ -48182,7 +48490,7 @@ var init_opencode_pane_server = __esm({
|
|
|
48182
48490
|
});
|
|
48183
48491
|
|
|
48184
48492
|
// src/bridge/opencode-panes.ts
|
|
48185
|
-
import { execFile as
|
|
48493
|
+
import { execFile as execFile17 } from "node:child_process";
|
|
48186
48494
|
import path79 from "node:path";
|
|
48187
48495
|
import { promisify as promisify15 } from "node:util";
|
|
48188
48496
|
function paneServersDir() {
|
|
@@ -48318,7 +48626,7 @@ var init_opencode_panes = __esm({
|
|
|
48318
48626
|
init_opencode_pane_server();
|
|
48319
48627
|
init_protocol();
|
|
48320
48628
|
init_terminal();
|
|
48321
|
-
exec15 = promisify15(
|
|
48629
|
+
exec15 = promisify15(execFile17);
|
|
48322
48630
|
PANE_PORT_ENV = "PHREN_OPENCODE_PORT";
|
|
48323
48631
|
PASSWORD_ENV = "OPENCODE_SERVER_PASSWORD";
|
|
48324
48632
|
READY_MS = 2e4;
|
|
@@ -48421,8 +48729,8 @@ var init_opencode_panes = __esm({
|
|
|
48421
48729
|
});
|
|
48422
48730
|
|
|
48423
48731
|
// src/bridge/agent-hooks.ts
|
|
48424
|
-
import { request as request6, createServer as
|
|
48425
|
-
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";
|
|
48426
48734
|
import { watch } from "node:fs";
|
|
48427
48735
|
import path80 from "node:path";
|
|
48428
48736
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
@@ -48695,7 +49003,9 @@ var init_agent_hooks = __esm({
|
|
|
48695
49003
|
pushBindings = new PushBindingStore();
|
|
48696
49004
|
/** Held asks that were pushed: action -> when the notification expires. */
|
|
48697
49005
|
pushedHolds = /* @__PURE__ */ new Map();
|
|
48698
|
-
/**
|
|
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. */
|
|
48699
49009
|
releasedHolds = /* @__PURE__ */ new Map();
|
|
48700
49010
|
/** Terminal dialogs pushed to phones: by pane, the dialog last pushed; by
|
|
48701
49011
|
* action, what an answer from the notification types. */
|
|
@@ -48830,28 +49140,28 @@ var init_agent_hooks = __esm({
|
|
|
48830
49140
|
const key4 = paneKey2(entry2), where = { key: key4, server: entry2.server, pane: entry2.pane };
|
|
48831
49141
|
const expiresAt = Date.now() + SERVED_ASK_MS;
|
|
48832
49142
|
const permissions = /* @__PURE__ */ new Set();
|
|
48833
|
-
for (const
|
|
48834
|
-
if (typeof
|
|
48835
|
-
permissions.add(
|
|
48836
|
-
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);
|
|
48837
49147
|
if (known2) {
|
|
48838
49148
|
if (known2.served?.key === key4) {
|
|
48839
49149
|
known2.expiresAt = expiresAt;
|
|
48840
49150
|
known2.request.expiresAt = new Date(expiresAt).toISOString();
|
|
48841
|
-
this.pushBindings.extendAction(
|
|
49151
|
+
this.pushBindings.extendAction(ask2.id, expiresAt);
|
|
48842
49152
|
}
|
|
48843
49153
|
continue;
|
|
48844
49154
|
}
|
|
48845
|
-
const target = await this.servedTarget(entry2, client,
|
|
49155
|
+
const target = await this.servedTarget(entry2, client, ask2.sessionID).catch(() => void 0);
|
|
48846
49156
|
if (this.closed) return;
|
|
48847
|
-
const type = typeof
|
|
48848
|
-
const patterns = (Array.isArray(
|
|
48849
|
-
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);
|
|
48850
49160
|
const detail = [patterns.join(", "), metadata.command, metadata.description, metadata.filepath, metadata.path, metadata.url].find((value2) => typeof value2 === "string" && !!value2);
|
|
48851
49161
|
const message = (detail ? `${type}: ${detail}` : `opencode asks to use ${type}.`).slice(0, 2e3);
|
|
48852
49162
|
const request9 = {
|
|
48853
|
-
id:
|
|
48854
|
-
sessionID:
|
|
49163
|
+
id: ask2.id,
|
|
49164
|
+
sessionID: ask2.sessionID,
|
|
48855
49165
|
type,
|
|
48856
49166
|
title: `Allow ${type}?`,
|
|
48857
49167
|
message,
|
|
@@ -48860,10 +49170,10 @@ var init_agent_hooks = __esm({
|
|
|
48860
49170
|
expiresAt: new Date(expiresAt).toISOString()
|
|
48861
49171
|
};
|
|
48862
49172
|
const summary = approvalSummary({ tool: type, input: request9, message, cwd: entry2.directory });
|
|
48863
|
-
this.opencode.set(
|
|
49173
|
+
this.opencode.set(ask2.id, { ...target ? { target } : {}, request: request9, requestLine: summary.request, expiresAt, served: where });
|
|
48864
49174
|
if (!this.push.available) continue;
|
|
48865
49175
|
const binding = randomUUID17();
|
|
48866
|
-
this.pushBindings.add(binding, { action:
|
|
49176
|
+
this.pushBindings.add(binding, { action: ask2.id, expiresAt });
|
|
48867
49177
|
void this.push.notify({
|
|
48868
49178
|
binding,
|
|
48869
49179
|
provider: "opencode",
|
|
@@ -48873,7 +49183,7 @@ var init_agent_hooks = __esm({
|
|
|
48873
49183
|
computer: this.computerName,
|
|
48874
49184
|
...summary
|
|
48875
49185
|
}).then((delivered) => {
|
|
48876
|
-
if (!delivered) this.pushBindings.dropAction(
|
|
49186
|
+
if (!delivered) this.pushBindings.dropAction(ask2.id);
|
|
48877
49187
|
}).catch(() => {
|
|
48878
49188
|
});
|
|
48879
49189
|
}
|
|
@@ -48884,16 +49194,16 @@ var init_agent_hooks = __esm({
|
|
|
48884
49194
|
}
|
|
48885
49195
|
}
|
|
48886
49196
|
const questions = /* @__PURE__ */ new Set();
|
|
48887
|
-
for (const
|
|
48888
|
-
if (typeof
|
|
48889
|
-
questions.add(
|
|
48890
|
-
if (this.servedQuestions.has(
|
|
48891
|
-
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 : [];
|
|
48892
49202
|
const mapped = terminalQuestions({ questions: raw.map((value2) => ({ ...object2(value2), multiSelect: object2(value2).multiple === true })) });
|
|
48893
49203
|
if (!mapped || mapped.length !== raw.length) continue;
|
|
48894
|
-
const target = await this.servedTarget(entry2, client,
|
|
49204
|
+
const target = await this.servedTarget(entry2, client, ask2.sessionID).catch(() => void 0);
|
|
48895
49205
|
if (this.closed) return;
|
|
48896
|
-
this.servedQuestions.set(
|
|
49206
|
+
this.servedQuestions.set(ask2.id, { ...where, ...target ? { target } : {}, question: ask2, questions: mapped, at: Date.now() });
|
|
48897
49207
|
while (this.servedQuestions.size > 64) this.servedQuestions.delete(this.servedQuestions.keys().next().value);
|
|
48898
49208
|
}
|
|
48899
49209
|
for (const [id2, held] of this.servedQuestions) if (held.key === key4 && !questions.has(id2)) this.servedQuestions.delete(id2);
|
|
@@ -49498,7 +49808,7 @@ var init_agent_hooks = __esm({
|
|
|
49498
49808
|
this.pushBindings.dropAction(id2);
|
|
49499
49809
|
}
|
|
49500
49810
|
async answer(target, id2, decision, updatedInput) {
|
|
49501
|
-
if (id2.startsWith("dialog-")) {
|
|
49811
|
+
if (id2.startsWith("dialog-") || !this.pending.has(id2) && await this.releasedHoldDialog(id2)) {
|
|
49502
49812
|
const dialog = this.dialogActions.get(id2);
|
|
49503
49813
|
if (!dialog || JSON.stringify(dialog.target) !== JSON.stringify(target)) throw new BridgeError(409, "This approval is no longer pending.");
|
|
49504
49814
|
if (updatedInput !== void 0 || !["approve", "deny"].includes(String(decision))) throw new BridgeError(400, "The approval answer is not valid.");
|
|
@@ -49611,15 +49921,7 @@ var init_agent_hooks = __esm({
|
|
|
49611
49921
|
await this.answer(pending.target, linked.action, decision);
|
|
49612
49922
|
return;
|
|
49613
49923
|
}
|
|
49614
|
-
|
|
49615
|
-
if (released && !this.dialogActions.has(linked.action)) {
|
|
49616
|
-
const target = JSON.parse(released[0]);
|
|
49617
|
-
await this.syncTerminalDialog(target, true).catch(() => {
|
|
49618
|
-
});
|
|
49619
|
-
const entry2 = this.terminalPrompts.get(released[0]);
|
|
49620
|
-
if (entry2?.choice?.title) this.adoptReleasedHold(released[0], target, entry2.choice, entry2.choice.title);
|
|
49621
|
-
}
|
|
49622
|
-
if (this.dialogActions.has(linked.action)) {
|
|
49924
|
+
if (await this.releasedHoldDialog(linked.action)) {
|
|
49623
49925
|
await this.answerDialog(linked.action, decision);
|
|
49624
49926
|
return;
|
|
49625
49927
|
}
|
|
@@ -49638,6 +49940,20 @@ var init_agent_hooks = __esm({
|
|
|
49638
49940
|
}
|
|
49639
49941
|
throw new BridgeError(409, "This approval is no longer pending.");
|
|
49640
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
|
+
}
|
|
49641
49957
|
/** Where a pushed ask lives, without answering it: the phone opens that
|
|
49642
49958
|
* session's details when the notification itself is tapped. */
|
|
49643
49959
|
pushTarget(binding) {
|
|
@@ -49693,6 +50009,15 @@ var init_agent_hooks = __esm({
|
|
|
49693
50009
|
if (!delivered) this.dropDialogPush(key4);
|
|
49694
50010
|
}).catch(() => this.dropDialogPush(key4));
|
|
49695
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
|
+
}
|
|
49696
50021
|
for (const [key4, hold] of this.releasedHolds) {
|
|
49697
50022
|
if (!waiting.has(key4) && JSON.parse(key4).server === server || hold.expiresAt <= Date.now()) {
|
|
49698
50023
|
this.dropPushBindings(hold.action);
|
|
@@ -49761,9 +50086,10 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49761
50086
|
const key4 = JSON.stringify(target), entry2 = this.terminalPrompts.get(key4);
|
|
49762
50087
|
const title2 = entry2 && (entry2.dialog || entry2.released) ? entry2.choice?.title : void 0;
|
|
49763
50088
|
if (!entry2?.choice || !title2) return void 0;
|
|
50089
|
+
this.adoptReleasedHold(key4, target, entry2.choice, title2);
|
|
49764
50090
|
const pushedDialog = this.dialogPushes.get(key4);
|
|
49765
50091
|
const pushedAction = pushedDialog && this.dialogActions.get(pushedDialog.action);
|
|
49766
|
-
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;
|
|
49767
50093
|
if (!action) {
|
|
49768
50094
|
const known2 = this.forwardedDialogs.get(key4);
|
|
49769
50095
|
if (known2?.title === title2 && known2.body === entry2.choice.body && (this.dialogActions.get(known2.action)?.expiresAt ?? 0) > Date.now()) action = known2.action;
|
|
@@ -49817,13 +50143,25 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49817
50143
|
if (!delivered) drop();
|
|
49818
50144
|
}).catch(drop);
|
|
49819
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. */
|
|
49820
50150
|
adoptReleasedHold(key4, target, choice, title2) {
|
|
49821
50151
|
const hold = this.releasedHolds.get(key4);
|
|
50152
|
+
if (!hold) return false;
|
|
49822
50153
|
this.releasedHolds.delete(key4);
|
|
49823
|
-
if (
|
|
49824
|
-
|
|
50154
|
+
if (hold.expiresAt <= Date.now()) {
|
|
50155
|
+
this.dropPushBindings(hold.action);
|
|
50156
|
+
return false;
|
|
50157
|
+
}
|
|
49825
50158
|
this.dialogActions.set(hold.action, { target, choice, expiresAt: hold.expiresAt });
|
|
49826
|
-
|
|
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;
|
|
49827
50165
|
}
|
|
49828
50166
|
dropDialogPush(key4) {
|
|
49829
50167
|
const pushed = this.dialogPushes.get(key4);
|
|
@@ -49939,7 +50277,7 @@ ${target.source}`) ?? 0) > Date.now();
|
|
|
49939
50277
|
if (!previous.isSocket() || previous.uid !== process.getuid?.()) throw new Error("Unexpected agent callback socket.");
|
|
49940
50278
|
await unlink7(localSocket());
|
|
49941
50279
|
}
|
|
49942
|
-
this.server =
|
|
50280
|
+
this.server = createServer3(async (req, res) => {
|
|
49943
50281
|
res.setHeader("Content-Type", "application/json");
|
|
49944
50282
|
try {
|
|
49945
50283
|
if (req.method === "POST" && req.url === "/sudo") {
|
|
@@ -50121,7 +50459,8 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50121
50459
|
released = true;
|
|
50122
50460
|
this.pending.delete(action);
|
|
50123
50461
|
this.rememberTerminalPrompt(target, body2);
|
|
50124
|
-
|
|
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 });
|
|
50125
50464
|
this.pushedHolds.delete(action);
|
|
50126
50465
|
res.end("{}");
|
|
50127
50466
|
}, APPROVAL_HOLD_MS);
|
|
@@ -50183,7 +50522,7 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50183
50522
|
this.server.listen(localSocket(), () => resolve14());
|
|
50184
50523
|
});
|
|
50185
50524
|
await chmod4(localSocket(), 384);
|
|
50186
|
-
await
|
|
50525
|
+
await mkdir22(this.approvalsDirectory(), { recursive: true, mode: 448 }).catch(() => {
|
|
50187
50526
|
});
|
|
50188
50527
|
try {
|
|
50189
50528
|
this.opencodeWatcher = watch(this.approvalsDirectory(), { persistent: false }, () => this.scheduleOpencodeSweep());
|
|
@@ -51116,7 +51455,7 @@ var init_permission_mode = __esm({
|
|
|
51116
51455
|
});
|
|
51117
51456
|
|
|
51118
51457
|
// src/bridge/session-servers.ts
|
|
51119
|
-
import { execFile as
|
|
51458
|
+
import { execFile as execFile18 } from "node:child_process";
|
|
51120
51459
|
import { open as open20, stat as stat21 } from "node:fs/promises";
|
|
51121
51460
|
import { promisify as promisify16 } from "node:util";
|
|
51122
51461
|
function mentionedPorts(text5) {
|
|
@@ -51215,7 +51554,7 @@ var init_session_servers = __esm({
|
|
|
51215
51554
|
init_terminal();
|
|
51216
51555
|
init_projects();
|
|
51217
51556
|
init_transcripts();
|
|
51218
|
-
exec16 = promisify16(
|
|
51557
|
+
exec16 = promisify16(execFile18);
|
|
51219
51558
|
MAX_DEPTH = 64;
|
|
51220
51559
|
TRANSCRIPT_TAIL_BYTES = 1048576;
|
|
51221
51560
|
MAX_OTHER_PANES = 48;
|
|
@@ -51224,7 +51563,7 @@ var init_session_servers = __esm({
|
|
|
51224
51563
|
});
|
|
51225
51564
|
|
|
51226
51565
|
// src/bridge/uploads.ts
|
|
51227
|
-
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";
|
|
51228
51567
|
import path82 from "node:path";
|
|
51229
51568
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
51230
51569
|
function imageBytes(bytes) {
|
|
@@ -51237,7 +51576,7 @@ async function saveUpload(session, name, bytes) {
|
|
|
51237
51576
|
const task = uploadQueue.catch(() => {
|
|
51238
51577
|
}).then(async () => {
|
|
51239
51578
|
const root = path82.join(bridgeRoot(), "uploads");
|
|
51240
|
-
await
|
|
51579
|
+
await mkdir23(root, { recursive: true, mode: 448 });
|
|
51241
51580
|
let used = 0;
|
|
51242
51581
|
const directories = await readdir16(root, { withFileTypes: true });
|
|
51243
51582
|
for (const dir of directories) {
|
|
@@ -51252,7 +51591,7 @@ async function saveUpload(session, name, bytes) {
|
|
|
51252
51591
|
}
|
|
51253
51592
|
if (used + bytes.length > 268435456) throw new BridgeError(413, "Phren's image storage is full. Remove older uploads on the computer.");
|
|
51254
51593
|
const folder = path82.join(root, session);
|
|
51255
|
-
await
|
|
51594
|
+
await mkdir23(folder, { recursive: true, mode: 448 });
|
|
51256
51595
|
saved = path82.join(folder, `${randomUUID19()}-${name}`);
|
|
51257
51596
|
await writeFile7(saved, bytes, { flag: "wx", mode: 384 });
|
|
51258
51597
|
});
|
|
@@ -51935,7 +52274,7 @@ async function driveOpencode(child, o) {
|
|
|
51935
52274
|
const family = /* @__PURE__ */ new Set([session]);
|
|
51936
52275
|
let error62, busy = false, asks = Promise.resolve();
|
|
51937
52276
|
const stop = new AbortController();
|
|
51938
|
-
const
|
|
52277
|
+
const ask2 = async (asked) => {
|
|
51939
52278
|
if (asked.permission === "doom_loop") {
|
|
51940
52279
|
await call("POST", `/permission/${encodeURIComponent(asked.id)}/reply`, { reply: "once" });
|
|
51941
52280
|
return;
|
|
@@ -51988,7 +52327,7 @@ ${message}` : message;
|
|
|
51988
52327
|
permission: String(p.permission ?? "action"),
|
|
51989
52328
|
patterns: Array.isArray(p.patterns) ? p.patterns.filter((value3) => typeof value3 === "string") : []
|
|
51990
52329
|
};
|
|
51991
|
-
asks = asks.then(() =>
|
|
52330
|
+
asks = asks.then(() => ask2(asked)).catch((failure2) => {
|
|
51992
52331
|
error62 = String(failure2);
|
|
51993
52332
|
});
|
|
51994
52333
|
}
|
|
@@ -52151,7 +52490,7 @@ __export(launcher_exports, {
|
|
|
52151
52490
|
writeManifest: () => writeManifest2
|
|
52152
52491
|
});
|
|
52153
52492
|
import { spawn as spawn11, execFileSync as execFileSync4 } from "node:child_process";
|
|
52154
|
-
import { randomBytes as
|
|
52493
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
52155
52494
|
import * as fs25 from "node:fs";
|
|
52156
52495
|
import * as path86 from "node:path";
|
|
52157
52496
|
function jobsRoot(store) {
|
|
@@ -52207,7 +52546,7 @@ function createJob(options, env = process.env, nearest = nearestAgent) {
|
|
|
52207
52546
|
if (!options.label.trim() || options.label.length > 200) throw new Error("Choose a label of 1 to 200 characters.");
|
|
52208
52547
|
const worktree = fs25.realpathSync(options.worktree);
|
|
52209
52548
|
if (!fs25.statSync(worktree).isDirectory()) throw new Error("Choose a worktree directory.");
|
|
52210
|
-
const id2 = `${options.provider}-${
|
|
52549
|
+
const id2 = `${options.provider}-${randomBytes6(12).toString("hex")}`;
|
|
52211
52550
|
const root = jobsRoot(options.store), job = path86.join(root, id2);
|
|
52212
52551
|
fs25.mkdirSync(job, { recursive: true, mode: 448 });
|
|
52213
52552
|
fs25.chmodSync(root, 448);
|
|
@@ -52240,7 +52579,7 @@ async function launch(options, reservation = createJob(options)) {
|
|
|
52240
52579
|
const { job, manifest } = reservation, adapter = adapters[options.provider];
|
|
52241
52580
|
console.log(job);
|
|
52242
52581
|
const out = fs25.openSync(path86.join(job, manifest.eventLog), "a"), err = fs25.openSync(path86.join(job, "stderr.log"), "a");
|
|
52243
|
-
const password =
|
|
52582
|
+
const password = randomBytes6(24).toString("hex");
|
|
52244
52583
|
const child = spawn11("nice", ["-n", "15", adapter.command, ...adapter.argv({ ...options, job })], {
|
|
52245
52584
|
cwd: manifest.worktree,
|
|
52246
52585
|
env: {
|
|
@@ -52363,7 +52702,7 @@ var init_launcher = __esm({
|
|
|
52363
52702
|
|
|
52364
52703
|
// src/bridge/fanout-messages.ts
|
|
52365
52704
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
52366
|
-
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";
|
|
52367
52706
|
import path87 from "node:path";
|
|
52368
52707
|
var fanoutMessageSchema, receiptSchema2, FanoutMessages;
|
|
52369
52708
|
var init_fanout_messages = __esm({
|
|
@@ -52464,7 +52803,7 @@ var init_fanout_messages = __esm({
|
|
|
52464
52803
|
}
|
|
52465
52804
|
async messageDirectory(job) {
|
|
52466
52805
|
const directory = path87.join(job.directory, "messages");
|
|
52467
|
-
await
|
|
52806
|
+
await mkdir24(directory, { recursive: true, mode: 448 });
|
|
52468
52807
|
if (await realpath15(directory) !== directory) throw new BridgeError(400, "Invalid worker message directory.");
|
|
52469
52808
|
return directory;
|
|
52470
52809
|
}
|
|
@@ -52503,7 +52842,7 @@ var init_fanout_messages = __esm({
|
|
|
52503
52842
|
async drain(job) {
|
|
52504
52843
|
const lock = path87.join(job.directory, "message-lock");
|
|
52505
52844
|
try {
|
|
52506
|
-
await
|
|
52845
|
+
await mkdir24(lock, { mode: 448 });
|
|
52507
52846
|
} catch {
|
|
52508
52847
|
return;
|
|
52509
52848
|
}
|
|
@@ -52523,10 +52862,10 @@ var init_fanout_messages = __esm({
|
|
|
52523
52862
|
if (info && (!info.isFile() || info.isSymbolicLink())) throw new BridgeError(400, "Invalid worker output file.");
|
|
52524
52863
|
}
|
|
52525
52864
|
const round = path87.join(fresh.directory, "rounds");
|
|
52526
|
-
await
|
|
52865
|
+
await mkdir24(round, { recursive: true, mode: 448 });
|
|
52527
52866
|
if (await realpath15(round) !== round) throw new BridgeError(400, "Invalid worker round directory.");
|
|
52528
52867
|
const roundDir = path87.join(round, next.message.id);
|
|
52529
|
-
await
|
|
52868
|
+
await mkdir24(roundDir, { mode: 448 });
|
|
52530
52869
|
await writeFile8(path87.join(roundDir, "prompt.txt"), next.message.text, { mode: 384 });
|
|
52531
52870
|
for (const name of ["stderr.log", "final.txt", "exit.txt", "blocked.json", "prompt.txt"]) {
|
|
52532
52871
|
await rename7(path87.join(fresh.directory, name), path87.join(roundDir, `previous-${name}`)).catch((error62) => {
|
|
@@ -53378,7 +53717,7 @@ var init_speech_transcribe = __esm({
|
|
|
53378
53717
|
});
|
|
53379
53718
|
|
|
53380
53719
|
// src/bridge/activity.ts
|
|
53381
|
-
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";
|
|
53382
53721
|
import path88 from "node:path";
|
|
53383
53722
|
var ActivityJournal;
|
|
53384
53723
|
var init_activity2 = __esm({
|
|
@@ -53412,7 +53751,7 @@ var init_activity2 = __esm({
|
|
|
53412
53751
|
}
|
|
53413
53752
|
if (!changes.length) return;
|
|
53414
53753
|
const root = bridgeRoot(), file4 = path88.join(root, "activity.jsonl");
|
|
53415
|
-
await
|
|
53754
|
+
await mkdir25(root, { recursive: true, mode: 448 });
|
|
53416
53755
|
if ((await stat23(file4).catch(() => null))?.size && (await stat23(file4)).size > 2097152) await rename8(file4, file4 + ".previous");
|
|
53417
53756
|
await appendFile3(file4, changes.map((row) => JSON.stringify(row)).join("\n") + "\n", { mode: 384 });
|
|
53418
53757
|
if (this.previous.size > 4096) this.previous.clear();
|
|
@@ -54104,9 +54443,9 @@ var init_context = __esm({
|
|
|
54104
54443
|
});
|
|
54105
54444
|
|
|
54106
54445
|
// src/bridge/questions.ts
|
|
54107
|
-
import { execFile as
|
|
54108
|
-
import { createHash as
|
|
54109
|
-
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";
|
|
54110
54449
|
import path91 from "node:path";
|
|
54111
54450
|
import { promisify as promisify17 } from "node:util";
|
|
54112
54451
|
function asyncQuestion(raw, id2) {
|
|
@@ -54270,14 +54609,14 @@ var init_questions = __esm({
|
|
|
54270
54609
|
init_transcript_index();
|
|
54271
54610
|
init_codex_question_reply();
|
|
54272
54611
|
init_uploads();
|
|
54273
|
-
exec17 = promisify17(
|
|
54612
|
+
exec17 = promisify17(execFile19);
|
|
54274
54613
|
text4 = external_exports.string().trim().min(1).max(4e3).refine((t) => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t));
|
|
54275
54614
|
question = external_exports.object({ title: text4, options: external_exports.array(text4).max(12).nullable().optional() });
|
|
54276
54615
|
questionSet = external_exports.array(question).min(1).max(8);
|
|
54277
54616
|
answersQuestions = (reply, questions) => questions.every((q) => {
|
|
54278
|
-
const
|
|
54279
|
-
const index2 = reply.indexOf(
|
|
54280
|
-
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;
|
|
54281
54620
|
});
|
|
54282
54621
|
attachedFiles = (paths) => paths.length ? `Attached files on this computer:
|
|
54283
54622
|
${paths.join("\n")}` : "";
|
|
@@ -54348,7 +54687,7 @@ ${attachedFiles(paths)}` : answer;
|
|
|
54348
54687
|
this.snapshots.set(target.session, { at: Date.now(), stamp: stamp2, pending });
|
|
54349
54688
|
}
|
|
54350
54689
|
return Promise.all((pending ?? []).map(async (p) => {
|
|
54351
|
-
const key4 =
|
|
54690
|
+
const key4 = createHash24("sha256").update(JSON.stringify([target.source, target.session, p.id])).digest("hex");
|
|
54352
54691
|
const submitted = await readFile45(path91.join(bridgeRoot(), "question-replies", key4), "utf8").then((value2) => value2 === "submitted").catch(() => false);
|
|
54353
54692
|
return { toolUseId: p.id, isAsync: true, submitted, questions: asPrompt(p.questions) };
|
|
54354
54693
|
})).then((prompts) => prompts.filter((p) => !p.submitted));
|
|
@@ -54383,8 +54722,8 @@ ${attachedFiles(paths)}` : answer;
|
|
|
54383
54722
|
const pane = await validateTarget(target);
|
|
54384
54723
|
if (await paneIdentity(target.server, pane, true) !== target.session) throw new BridgeError(409, "This pane's conversation changed. Reopen the chat.");
|
|
54385
54724
|
const directory = path91.join(bridgeRoot(), "question-replies");
|
|
54386
|
-
await
|
|
54387
|
-
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");
|
|
54388
54727
|
const receiptPath = path91.join(directory, key4);
|
|
54389
54728
|
const receipt = await open22(receiptPath, "wx", 384).catch((error62) => {
|
|
54390
54729
|
if (error62.code === "EEXIST") throw new BridgeError(409, "An answer was already submitted. Check the conversation before answering again.");
|
|
@@ -54898,7 +55237,7 @@ var init_job_registry = __esm({
|
|
|
54898
55237
|
});
|
|
54899
55238
|
|
|
54900
55239
|
// src/bridge/resources.ts
|
|
54901
|
-
import { execFile as
|
|
55240
|
+
import { execFile as execFile20 } from "node:child_process";
|
|
54902
55241
|
import { readdir as readdir18, readFile as readFile46, statfs } from "node:fs/promises";
|
|
54903
55242
|
import { cpus, loadavg, totalmem, uptime } from "node:os";
|
|
54904
55243
|
import path93 from "node:path";
|
|
@@ -54910,12 +55249,12 @@ function parseMacHardware(json2) {
|
|
|
54910
55249
|
return { ...model ? { model } : {}, ...chip ? { chip } : {} };
|
|
54911
55250
|
}
|
|
54912
55251
|
function linuxModel(vendor, product, version3) {
|
|
54913
|
-
const
|
|
55252
|
+
const clean3 = (value2) => {
|
|
54914
55253
|
const text5 = value2?.replace(/\s+/g, " ").trim();
|
|
54915
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;
|
|
54916
55255
|
};
|
|
54917
|
-
const brand =
|
|
54918
|
-
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);
|
|
54919
55258
|
if (!name) return brand;
|
|
54920
55259
|
const label2 = brand && !name.toLowerCase().startsWith(brand.toLowerCase()) ? `${brand === "LENOVO" ? "Lenovo" : brand} ${name}` : name;
|
|
54921
55260
|
return label2.slice(0, 80);
|
|
@@ -55261,7 +55600,7 @@ var init_resources = __esm({
|
|
|
55261
55600
|
init_job_registry();
|
|
55262
55601
|
init_limits();
|
|
55263
55602
|
init_protocol();
|
|
55264
|
-
exec18 = promisify18(
|
|
55603
|
+
exec18 = promisify18(execFile20);
|
|
55265
55604
|
RESOURCES_MAX_AGE_MS = intervalFromEnv("PHREN_RESOURCES_MAX_AGE_MS", 1e4, 1e3, 6e4);
|
|
55266
55605
|
LOW_DISK_BYTES = 10 * 1024 ** 3;
|
|
55267
55606
|
GB = 1024 ** 3;
|
|
@@ -55623,7 +55962,7 @@ function taskWriterSafety(base) {
|
|
|
55623
55962
|
...status.acknowledgedAt ? { acknowledgedAt: status.acknowledgedAt } : {}
|
|
55624
55963
|
};
|
|
55625
55964
|
}
|
|
55626
|
-
var file3, taskFormatMigrationHint;
|
|
55965
|
+
var file3, taskFormatCurrentWriters, taskFormatMigrationHint;
|
|
55627
55966
|
var init_task_format = __esm({
|
|
55628
55967
|
"src/data/task-format.ts"() {
|
|
55629
55968
|
"use strict";
|
|
@@ -55632,7 +55971,8 @@ var init_task_format = __esm({
|
|
|
55632
55971
|
init_rbac();
|
|
55633
55972
|
init_store_registry();
|
|
55634
55973
|
file3 = (base) => path96.join(base, ".config", "task-format.json");
|
|
55635
|
-
|
|
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.`;
|
|
55636
55976
|
}
|
|
55637
55977
|
});
|
|
55638
55978
|
|
|
@@ -57075,9 +57415,9 @@ var init_dedup = __esm({
|
|
|
57075
57415
|
});
|
|
57076
57416
|
|
|
57077
57417
|
// src/finding-graph-id.ts
|
|
57078
|
-
import { createHash as
|
|
57418
|
+
import { createHash as createHash25 } from "crypto";
|
|
57079
57419
|
function findingStableId(scoreKey) {
|
|
57080
|
-
return `finding:${
|
|
57420
|
+
return `finding:${createHash25("sha1").update(scoreKey).digest("hex").slice(0, 12)}`;
|
|
57081
57421
|
}
|
|
57082
57422
|
function findingNodeIdForLine(project, line) {
|
|
57083
57423
|
const tagMatch = line.match(TAGGED_BULLET);
|
|
@@ -57146,14 +57486,14 @@ function parseTaskItems(taskPath) {
|
|
|
57146
57486
|
counters[section] += 1;
|
|
57147
57487
|
const itemId = `${section === "Active" ? "A" : section === "Queue" ? "Q" : "D"}${counters[section]}`;
|
|
57148
57488
|
const stripped = stripBulletPrefix(line).body;
|
|
57149
|
-
const { clean:
|
|
57489
|
+
const { clean: clean3, bid } = stripBid(stripped);
|
|
57150
57490
|
items.push({
|
|
57151
57491
|
id: itemId,
|
|
57152
57492
|
stableId: bid,
|
|
57153
57493
|
section,
|
|
57154
|
-
line:
|
|
57155
|
-
priority: normalizePriority(
|
|
57156
|
-
pinned: detectPinned(
|
|
57494
|
+
line: clean3,
|
|
57495
|
+
priority: normalizePriority(clean3),
|
|
57496
|
+
pinned: detectPinned(clean3) || void 0
|
|
57157
57497
|
});
|
|
57158
57498
|
}
|
|
57159
57499
|
return items;
|
|
@@ -57591,9 +57931,9 @@ var init_content = __esm({
|
|
|
57591
57931
|
});
|
|
57592
57932
|
|
|
57593
57933
|
// src/bridge/memory-store.ts
|
|
57594
|
-
import { execFile as
|
|
57595
|
-
import { createHash as
|
|
57596
|
-
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";
|
|
57597
57937
|
import path102 from "node:path";
|
|
57598
57938
|
import { promisify as promisify19 } from "node:util";
|
|
57599
57939
|
function serialized2(work) {
|
|
@@ -57615,7 +57955,7 @@ async function git5(store, args, env = {}) {
|
|
|
57615
57955
|
}
|
|
57616
57956
|
}
|
|
57617
57957
|
function blobSha(content) {
|
|
57618
|
-
return
|
|
57958
|
+
return createHash26("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
|
|
57619
57959
|
}
|
|
57620
57960
|
async function isRepository(store) {
|
|
57621
57961
|
return await lstat30(path102.join(store, ".git")).catch(() => void 0) !== void 0;
|
|
@@ -57651,7 +57991,7 @@ async function storeRepositoryIdentity(store) {
|
|
|
57651
57991
|
function storeHead(store, indexFile = path102.join(bridgeRoot(), "store-snapshot.index")) {
|
|
57652
57992
|
return serialized2(async () => {
|
|
57653
57993
|
if (!await isRepository(store)) throw new BridgeError(409, "This computer's phren store is not a git repository. Run phren init.");
|
|
57654
|
-
await
|
|
57994
|
+
await mkdir27(path102.dirname(indexFile), { recursive: true, mode: 448 });
|
|
57655
57995
|
const env = { GIT_INDEX_FILE: indexFile };
|
|
57656
57996
|
if (!await lstat30(indexFile).catch(() => void 0)) {
|
|
57657
57997
|
const head = await git5(store, ["rev-parse", "--verify", "--quiet", "HEAD"]).catch(() => "");
|
|
@@ -57719,7 +58059,7 @@ function putStoreFile(store, data) {
|
|
|
57719
58059
|
return serialized2(async () => {
|
|
57720
58060
|
const file4 = await storeFile(store, input2.path);
|
|
57721
58061
|
if (await currentSha(file4) !== (input2.sha ?? null)) throw new BridgeError(409, `${input2.path} changed on this computer.`);
|
|
57722
|
-
await
|
|
58062
|
+
await mkdir27(path102.dirname(file4), { recursive: true });
|
|
57723
58063
|
const temporary = `${file4}.phren-${process.pid}-${Date.now()}`;
|
|
57724
58064
|
await writeFile10(temporary, content, { flag: "wx" });
|
|
57725
58065
|
await rename9(temporary, file4);
|
|
@@ -57749,7 +58089,7 @@ var init_memory_store = __esm({
|
|
|
57749
58089
|
"use strict";
|
|
57750
58090
|
init_zod();
|
|
57751
58091
|
init_protocol();
|
|
57752
|
-
exec19 = promisify19(
|
|
58092
|
+
exec19 = promisify19(execFile21);
|
|
57753
58093
|
SHA = /^[0-9a-f]{40}$/;
|
|
57754
58094
|
MAX_FILE = 4 * 1024 * 1024;
|
|
57755
58095
|
queue2 = Promise.resolve();
|
|
@@ -57761,7 +58101,7 @@ var init_memory_store = __esm({
|
|
|
57761
58101
|
|
|
57762
58102
|
// src/data/task-store-directory.ts
|
|
57763
58103
|
import * as path103 from "node:path";
|
|
57764
|
-
import { execFile as
|
|
58104
|
+
import { execFile as execFile22 } from "node:child_process";
|
|
57765
58105
|
import { promisify as promisify20 } from "node:util";
|
|
57766
58106
|
function taskStores(base) {
|
|
57767
58107
|
return readTaskStoreEntries(base).map((store) => ({
|
|
@@ -57796,7 +58136,7 @@ var init_task_store_directory = __esm({
|
|
|
57796
58136
|
"use strict";
|
|
57797
58137
|
init_store_registry();
|
|
57798
58138
|
init_memory_store();
|
|
57799
|
-
exec20 = promisify20(
|
|
58139
|
+
exec20 = promisify20(execFile22);
|
|
57800
58140
|
}
|
|
57801
58141
|
});
|
|
57802
58142
|
|
|
@@ -57957,7 +58297,7 @@ var init_task_receipts = __esm({
|
|
|
57957
58297
|
// src/data/tasks.ts
|
|
57958
58298
|
import * as fs35 from "fs";
|
|
57959
58299
|
import * as path106 from "path";
|
|
57960
|
-
import { createHash as
|
|
58300
|
+
import { createHash as createHash27, randomBytes as randomBytes8, randomUUID as randomUUID24 } from "crypto";
|
|
57961
58301
|
function formatClaim(claim2) {
|
|
57962
58302
|
return `Claimed: ${claim2.computer} ${claim2.at}${claim2.session ? ` session:${claim2.session}` : ""}`;
|
|
57963
58303
|
}
|
|
@@ -58070,7 +58410,7 @@ function parseContinuation(lines, idx) {
|
|
|
58070
58410
|
};
|
|
58071
58411
|
}
|
|
58072
58412
|
function newBid() {
|
|
58073
|
-
return
|
|
58413
|
+
return randomBytes8(4).toString("hex");
|
|
58074
58414
|
}
|
|
58075
58415
|
function stripBid(text5) {
|
|
58076
58416
|
const m = text5.match(METADATA_PATTERN);
|
|
@@ -58194,7 +58534,7 @@ function parseTaskContent(project, taskPath, content) {
|
|
|
58194
58534
|
title: title2,
|
|
58195
58535
|
path: taskPath,
|
|
58196
58536
|
items,
|
|
58197
|
-
revision:
|
|
58537
|
+
revision: createHash27("sha256").update(content).digest("hex"),
|
|
58198
58538
|
issues: validateTaskFormat(content)
|
|
58199
58539
|
};
|
|
58200
58540
|
}
|
|
@@ -58285,7 +58625,7 @@ function readTasks(phrenPath, project) {
|
|
|
58285
58625
|
return phrenOk({
|
|
58286
58626
|
project,
|
|
58287
58627
|
title: `# ${project} tasks`,
|
|
58288
|
-
revision:
|
|
58628
|
+
revision: createHash27("sha256").update("").digest("hex"),
|
|
58289
58629
|
path: taskPath,
|
|
58290
58630
|
issues: [],
|
|
58291
58631
|
items: { Active: [], Queue: [], Done: [] }
|
|
@@ -58508,8 +58848,8 @@ var init_tasks = __esm({
|
|
|
58508
58848
|
});
|
|
58509
58849
|
|
|
58510
58850
|
// src/bridge/launch-worktree.ts
|
|
58511
|
-
import { execFile as
|
|
58512
|
-
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";
|
|
58513
58853
|
import path107 from "node:path";
|
|
58514
58854
|
import { promisify as promisify21 } from "node:util";
|
|
58515
58855
|
async function git6(cwd, ...args) {
|
|
@@ -58539,7 +58879,7 @@ async function createLaunchWorktree(cwd, request9) {
|
|
|
58539
58879
|
if (await stat26(worktree).then(() => true, () => false)) {
|
|
58540
58880
|
throw new BridgeError(409, `The folder .claude/worktrees/${worktreeFolderName(branch)} already exists. Choose another branch name.`);
|
|
58541
58881
|
}
|
|
58542
|
-
await
|
|
58882
|
+
await mkdir28(path107.dirname(worktree), { recursive: true });
|
|
58543
58883
|
try {
|
|
58544
58884
|
await git6(root, "worktree", "add", "-b", branch, worktree, head);
|
|
58545
58885
|
} catch (error62) {
|
|
@@ -58570,14 +58910,14 @@ var init_launch_worktree = __esm({
|
|
|
58570
58910
|
init_metrics();
|
|
58571
58911
|
init_projects();
|
|
58572
58912
|
init_protocol();
|
|
58573
|
-
exec21 = promisify21(
|
|
58913
|
+
exec21 = promisify21(execFile23);
|
|
58574
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.");
|
|
58575
58915
|
launchWorktreeSchema = external_exports.object({ branch: worktreeBranch }).strict();
|
|
58576
58916
|
}
|
|
58577
58917
|
});
|
|
58578
58918
|
|
|
58579
58919
|
// src/bridge/server-launch.ts
|
|
58580
|
-
import { mkdir as
|
|
58920
|
+
import { mkdir as mkdir29, mkdtemp as mkdtemp6, readFile as readFile48, realpath as realpath19, rmdir as rmdir2 } from "node:fs/promises";
|
|
58581
58921
|
import path108 from "node:path";
|
|
58582
58922
|
function effortArgs(kind, effort) {
|
|
58583
58923
|
if (kind === "claude") return ["--effort", effort];
|
|
@@ -58638,7 +58978,7 @@ mode: primary
|
|
|
58638
58978
|
|
|
58639
58979
|
${brief}
|
|
58640
58980
|
`;
|
|
58641
|
-
await
|
|
58981
|
+
await mkdir29(directory, { recursive: true, mode: 448 });
|
|
58642
58982
|
if (await readFile48(file4, "utf8").catch(() => void 0) !== definition) await atomic(file4, definition, 420);
|
|
58643
58983
|
return [...model ? ["--model", model] : [], "--agent", "conductor", "--variant", effort];
|
|
58644
58984
|
}
|
|
@@ -58819,10 +59159,10 @@ async function startSession(server, data, options) {
|
|
|
58819
59159
|
if (agentFolder) {
|
|
58820
59160
|
const store = await realpath19(defaultPhrenPath());
|
|
58821
59161
|
const runtime = path108.join(store, ".runtime");
|
|
58822
|
-
await
|
|
59162
|
+
await mkdir29(runtime, { recursive: true, mode: 448 });
|
|
58823
59163
|
if (await realpath19(runtime) !== runtime) throw new BridgeError(403, "The runtime folder must be inside the Phren directory.");
|
|
58824
59164
|
const agents = path108.join(runtime, "agents");
|
|
58825
|
-
await
|
|
59165
|
+
await mkdir29(agents, { recursive: true, mode: 448 });
|
|
58826
59166
|
if (await realpath19(agents) !== agents) throw new BridgeError(403, "The agents folder must be inside the Phren directory.");
|
|
58827
59167
|
scratch = await mkdtemp6(path108.join(agents, `${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}-${herdrAgentName(label2)}-`));
|
|
58828
59168
|
}
|
|
@@ -59216,7 +59556,28 @@ async function ownerInboxView(inbox, input2, localOnly = false) {
|
|
|
59216
59556
|
unreachable.push({ computer: peer.name, error: error62 instanceof Error ? error62.message : "Unreachable." });
|
|
59217
59557
|
}
|
|
59218
59558
|
}));
|
|
59219
|
-
|
|
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 };
|
|
59220
59581
|
}
|
|
59221
59582
|
var init_owner_inbox_view = __esm({
|
|
59222
59583
|
"src/bridge/owner-inbox-view.ts"() {
|
|
@@ -60306,8 +60667,8 @@ function mergeText(base, ours, theirs) {
|
|
|
60306
60667
|
}
|
|
60307
60668
|
}
|
|
60308
60669
|
function unionText(base, ours, theirs) {
|
|
60309
|
-
const
|
|
60310
|
-
if (
|
|
60670
|
+
const clean3 = mergeText(base, ours, theirs);
|
|
60671
|
+
if (clean3 !== null) return clean3;
|
|
60311
60672
|
const dir = fs38.mkdtempSync(path114.join(os3.tmpdir(), "phren-merge-"));
|
|
60312
60673
|
try {
|
|
60313
60674
|
const [o, b, t] = ["ours", "base", "theirs"].map((name) => path114.join(dir, name));
|
|
@@ -60697,10 +61058,10 @@ var init_session_git = __esm({
|
|
|
60697
61058
|
});
|
|
60698
61059
|
|
|
60699
61060
|
// src/bridge/enroll.ts
|
|
60700
|
-
import { execFile as
|
|
61061
|
+
import { execFile as execFile24 } from "node:child_process";
|
|
60701
61062
|
import { promisify as promisify22 } from "node:util";
|
|
60702
61063
|
import { realpathSync as realpathSync5 } from "node:fs";
|
|
60703
|
-
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";
|
|
60704
61065
|
import { homedir as homedir19 } from "node:os";
|
|
60705
61066
|
import path115 from "node:path";
|
|
60706
61067
|
function repoName(url2) {
|
|
@@ -60804,7 +61165,7 @@ async function cloneRoot(env) {
|
|
|
60804
61165
|
}
|
|
60805
61166
|
}
|
|
60806
61167
|
const fallback2 = path115.join(home, "Projects");
|
|
60807
|
-
await
|
|
61168
|
+
await mkdir30(fallback2, { recursive: true });
|
|
60808
61169
|
return fallback2;
|
|
60809
61170
|
}
|
|
60810
61171
|
async function publishStore(store, project) {
|
|
@@ -60886,7 +61247,7 @@ var init_enroll = __esm({
|
|
|
60886
61247
|
init_code_routes();
|
|
60887
61248
|
init_utils_paths();
|
|
60888
61249
|
init_machine_identity();
|
|
60889
|
-
exec22 = promisify22(
|
|
61250
|
+
exec22 = promisify22(execFile24);
|
|
60890
61251
|
runEnrollStoreGit = async (cwd, args) => {
|
|
60891
61252
|
const result = await runBestEffortGit(args, cwd);
|
|
60892
61253
|
return { ok: result.ok, output: result.output ?? "", error: result.error };
|
|
@@ -61109,11 +61470,11 @@ var init_file_resolve = __esm({
|
|
|
61109
61470
|
});
|
|
61110
61471
|
|
|
61111
61472
|
// src/bridge/simulators.ts
|
|
61112
|
-
import { execFile as
|
|
61113
|
-
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";
|
|
61114
61475
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
61115
61476
|
import path119 from "node:path";
|
|
61116
|
-
import { createHash as
|
|
61477
|
+
import { createHash as createHash28, randomUUID as randomUUID26 } from "node:crypto";
|
|
61117
61478
|
import { promisify as promisify23 } from "node:util";
|
|
61118
61479
|
async function bootedSimulators() {
|
|
61119
61480
|
if (process.platform !== "darwin") return [];
|
|
@@ -61250,10 +61611,10 @@ case "type":
|
|
|
61250
61611
|
default: fail(2, "unknown command \\(command)")
|
|
61251
61612
|
}
|
|
61252
61613
|
` : await readFile50(new URL("./native/simtap.swift", import.meta.url), "utf8");
|
|
61253
|
-
const digest2 =
|
|
61614
|
+
const digest2 = createHash28("sha256").update(code).digest("hex");
|
|
61254
61615
|
const saved = await readFile50(binary + ".sha256", "utf8").then(JSON.parse).catch(() => void 0);
|
|
61255
61616
|
if (await stat29(binary).catch(() => void 0) && saved?.sourceSha === digest2) return binary;
|
|
61256
|
-
await
|
|
61617
|
+
await mkdir31(dir, { recursive: true, mode: 448 });
|
|
61257
61618
|
const temporary = path119.join(dir, `simtap.${randomUUID26()}`), source = temporary + ".swift";
|
|
61258
61619
|
const sidecar = temporary + ".sha256";
|
|
61259
61620
|
try {
|
|
@@ -61262,7 +61623,7 @@ default: fail(2, "unknown command \\(command)")
|
|
|
61262
61623
|
throw new BridgeError(409, "Couldn't build the simulator input helper (needs Xcode's swiftc).");
|
|
61263
61624
|
});
|
|
61264
61625
|
await chmod5(temporary, 448);
|
|
61265
|
-
const binarySha =
|
|
61626
|
+
const binarySha = createHash28("sha256").update(await readFile50(temporary)).digest("hex");
|
|
61266
61627
|
await writeFile11(sidecar, JSON.stringify({ sourceSha: digest2, binarySha }), { mode: 384, flag: "wx" });
|
|
61267
61628
|
await rename10(temporary, binary);
|
|
61268
61629
|
await rename10(sidecar, binary + ".sha256");
|
|
@@ -61280,7 +61641,7 @@ function simtap(name, ...args) {
|
|
|
61280
61641
|
async function verifiedHelper() {
|
|
61281
61642
|
const binary = await helper();
|
|
61282
61643
|
const saved = await readFile50(binary + ".sha256", "utf8").then(JSON.parse).catch(() => void 0);
|
|
61283
|
-
const binarySha =
|
|
61644
|
+
const binarySha = createHash28("sha256").update(await readFile50(binary)).digest("hex");
|
|
61284
61645
|
if (!saved || saved.binarySha !== binarySha) throw new BridgeError(409, "Simulator input helper integrity check failed.");
|
|
61285
61646
|
return binary;
|
|
61286
61647
|
}
|
|
@@ -61384,7 +61745,7 @@ var init_simulators = __esm({
|
|
|
61384
61745
|
"src/bridge/simulators.ts"() {
|
|
61385
61746
|
"use strict";
|
|
61386
61747
|
init_protocol();
|
|
61387
|
-
exec23 = promisify23(
|
|
61748
|
+
exec23 = promisify23(execFile25);
|
|
61388
61749
|
UDID = /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i;
|
|
61389
61750
|
inputQueue = Promise.resolve();
|
|
61390
61751
|
prompted = false;
|
|
@@ -62753,9 +63114,9 @@ function claudePanePreview(rendered, prompt, previous = "") {
|
|
|
62753
63114
|
}
|
|
62754
63115
|
if (!writing) continue;
|
|
62755
63116
|
const tidy = (value2) => value2.replace(/^\s*[⏺●]\s?/, "").replace(/[⠁-⣿✻✽✶✢✳]/gu, "");
|
|
62756
|
-
const
|
|
62757
|
-
if (/^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(
|
|
62758
|
-
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}/, ""));
|
|
62759
63120
|
shown.push(tidy(markedBody[index2] ?? line).replace(/^ {2}/, ""));
|
|
62760
63121
|
}
|
|
62761
63122
|
const text5 = unwrapTerminalLines(reply, shown).trim().slice(0, MAX_TEXT3);
|
|
@@ -63547,9 +63908,9 @@ var init_codex_auth_refresh = __esm({
|
|
|
63547
63908
|
|
|
63548
63909
|
// src/bridge/server.ts
|
|
63549
63910
|
import { randomUUID as randomUUID27 } from "node:crypto";
|
|
63550
|
-
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";
|
|
63551
63912
|
import { readFileSync as readFileSync42 } from "node:fs";
|
|
63552
|
-
import { createServer as
|
|
63913
|
+
import { createServer as createServer4 } from "node:http";
|
|
63553
63914
|
import { cpus as cpus2, hostname as hostname12, loadavg as loadavg2 } from "node:os";
|
|
63554
63915
|
import path124 from "node:path";
|
|
63555
63916
|
async function serve(version3, options = {}) {
|
|
@@ -63558,7 +63919,7 @@ async function serve(version3, options = {}) {
|
|
|
63558
63919
|
if (!modules.has("hook")) throw new BridgeError(404, disabledHint("hook"));
|
|
63559
63920
|
const activeCapabilities = capabilitiesForModules(modules);
|
|
63560
63921
|
const root = bridgeRoot();
|
|
63561
|
-
await
|
|
63922
|
+
await mkdir32(root, { recursive: true, mode: 448 });
|
|
63562
63923
|
await chmod6(root, 448);
|
|
63563
63924
|
let computerID2;
|
|
63564
63925
|
const identityFile = path124.join(root, "computer-id");
|
|
@@ -63610,36 +63971,7 @@ async function serve(version3, options = {}) {
|
|
|
63610
63971
|
if ("approvalPush" in activeCapabilities) {
|
|
63611
63972
|
Object.defineProperty(activeCapabilities, "approvalPush", { enumerable: true, get: () => approvalPushCapability(agentHooks.push.status) });
|
|
63612
63973
|
}
|
|
63613
|
-
const inbox = dispatches ? new OwnerInbox(
|
|
63614
|
-
const items = [];
|
|
63615
|
-
for (const server of await recentServers()) {
|
|
63616
|
-
const name = String(server.session), state = await sharedSnapshot(name, 4e3);
|
|
63617
|
-
for (const pane of objects(state.panes)) {
|
|
63618
|
-
const chat = await paneChatState(name, pane, { tokenWhenIdentified: false }).catch(() => ({}));
|
|
63619
|
-
const parsed = inboxTargetSchema.safeParse({
|
|
63620
|
-
server: name,
|
|
63621
|
-
workspace: pane.workspace_id,
|
|
63622
|
-
tab: pane.tab_id,
|
|
63623
|
-
pane: pane.pane_id,
|
|
63624
|
-
source: pane.agent,
|
|
63625
|
-
...chat.sessionId ? { session: chat.sessionId } : { starting: true, startingToken: chat.startingToken }
|
|
63626
|
-
});
|
|
63627
|
-
if (!parsed.success) continue;
|
|
63628
|
-
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;
|
|
63629
|
-
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);
|
|
63630
|
-
if (!request9) continue;
|
|
63631
|
-
const source = `prompt:${JSON.stringify(target)}:${approval?.actionId ?? JSON.stringify(question2 ?? terminal2)}`;
|
|
63632
|
-
items.push({
|
|
63633
|
-
source,
|
|
63634
|
-
kind: "blocked",
|
|
63635
|
-
title: String(request9).replace(/[\x00-\x1f\x7f]+/g, " ").slice(0, 500),
|
|
63636
|
-
target,
|
|
63637
|
-
...approval?.actionId ? { actionId: approval.actionId } : {}
|
|
63638
|
-
});
|
|
63639
|
-
}
|
|
63640
|
-
}
|
|
63641
|
-
return items;
|
|
63642
|
-
}) : void 0;
|
|
63974
|
+
const inbox = dispatches ? new OwnerInbox(() => ownerInboxSources(agentHooks)) : void 0;
|
|
63643
63975
|
const modelCatalog = options.modelCatalog ?? new ModelCatalog();
|
|
63644
63976
|
const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
|
|
63645
63977
|
const settingsSwitcher = new SettingsSwitcher(agentHooks);
|
|
@@ -63743,7 +64075,7 @@ async function serve(version3, options = {}) {
|
|
|
63743
64075
|
resources: () => resources.read(),
|
|
63744
64076
|
sudo: agentHooks.sudo
|
|
63745
64077
|
});
|
|
63746
|
-
const http =
|
|
64078
|
+
const http = createServer4(createRouteHandler({
|
|
63747
64079
|
version: version3,
|
|
63748
64080
|
modules,
|
|
63749
64081
|
info,
|
|
@@ -63916,6 +64248,7 @@ async function serve(version3, options = {}) {
|
|
|
63916
64248
|
var init_server = __esm({
|
|
63917
64249
|
"src/bridge/server.ts"() {
|
|
63918
64250
|
"use strict";
|
|
64251
|
+
init_owner_inbox_sources();
|
|
63919
64252
|
init_owner_inbox();
|
|
63920
64253
|
init_worker_close();
|
|
63921
64254
|
init_dispatch_hosts();
|
|
@@ -63971,7 +64304,7 @@ var init_server = __esm({
|
|
|
63971
64304
|
});
|
|
63972
64305
|
|
|
63973
64306
|
// src/bridge/link.ts
|
|
63974
|
-
import { execFile as
|
|
64307
|
+
import { execFile as execFile26 } from "node:child_process";
|
|
63975
64308
|
import { readFile as readFile53 } from "node:fs/promises";
|
|
63976
64309
|
import { homedir as homedir21, hostname as hostname13, userInfo as userInfo5 } from "node:os";
|
|
63977
64310
|
import path125 from "node:path";
|
|
@@ -63998,7 +64331,7 @@ function sshConfigHosts(text5) {
|
|
|
63998
64331
|
}
|
|
63999
64332
|
async function ssh(host, command, input2, timeout = 2e4) {
|
|
64000
64333
|
return new Promise((resolve14, reject) => {
|
|
64001
|
-
const child =
|
|
64334
|
+
const child = execFile26(
|
|
64002
64335
|
"ssh",
|
|
64003
64336
|
["-o", "BatchMode=yes", "-o", "ConnectTimeout=5", "--", host, command],
|
|
64004
64337
|
{ timeout, maxBuffer: 1048576 },
|
|
@@ -64050,8 +64383,12 @@ async function linkComputer(host, options = {}) {
|
|
|
64050
64383
|
const backAddress = options.backAddress ?? remote.client;
|
|
64051
64384
|
if (!backAddress) throw new BridgeError(409, `${host} did not report this computer's address; pass --back-address.`);
|
|
64052
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(" ")]));
|
|
64053
|
-
const
|
|
64054
|
-
|
|
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(" "));
|
|
64055
64392
|
const remoteLine = (await ssh(host, `${REMOTE_PATH} phren bridge enroll-computer ${name}`)).trim();
|
|
64056
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));
|
|
64057
64394
|
await acceptComputer(name, remoteLine);
|
|
@@ -64086,10 +64423,11 @@ var init_link = __esm({
|
|
|
64086
64423
|
init_hand_off();
|
|
64087
64424
|
init_computer_names();
|
|
64088
64425
|
init_computers();
|
|
64426
|
+
init_host_key();
|
|
64089
64427
|
init_peers();
|
|
64090
64428
|
init_protocol();
|
|
64091
|
-
exec24 = promisify24(
|
|
64092
|
-
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"';
|
|
64093
64431
|
GIT_HOSTS = /(^|\.)(github\.com|gitlab\.com|bitbucket\.org)$/i;
|
|
64094
64432
|
}
|
|
64095
64433
|
});
|
|
@@ -64388,7 +64726,7 @@ async function main() {
|
|
|
64388
64726
|
return askpass2(args[1]);
|
|
64389
64727
|
}
|
|
64390
64728
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
64391
|
-
return runBridge2(args, "0.3.
|
|
64729
|
+
return runBridge2(args, "0.3.36");
|
|
64392
64730
|
}
|
|
64393
64731
|
main().then((code) => {
|
|
64394
64732
|
process.exitCode = code;
|