@phren/cli 0.3.23 → 0.3.25
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/code-routes.d.ts +12 -0
- package/dist/bridge/code-routes.js +23 -0
- package/dist/bridge/file-resolve.d.ts +10 -0
- package/dist/bridge/file-resolve.js +63 -0
- package/dist/bridge/server-routes.d.ts +2 -0
- package/dist/bridge/server-routes.js +14 -1
- package/dist/bridge-hook.mjs +167 -84
- package/dist/generated/memory-ui-graph.browser.js +57 -57
- package/dist/memory-ui-graph.runtime.js +57 -57
- package/dist/modules/registry.js +4 -4
- package/package.json +1 -1
package/dist/bridge-hook.mjs
CHANGED
|
@@ -268,10 +268,10 @@ function mergeDefs(...defs) {
|
|
|
268
268
|
function cloneDef(schema) {
|
|
269
269
|
return mergeDefs(schema._zod.def);
|
|
270
270
|
}
|
|
271
|
-
function getElementAtPath(obj,
|
|
272
|
-
if (!
|
|
271
|
+
function getElementAtPath(obj, path117) {
|
|
272
|
+
if (!path117)
|
|
273
273
|
return obj;
|
|
274
|
-
return
|
|
274
|
+
return path117.reduce((acc, key3) => acc?.[key3], obj);
|
|
275
275
|
}
|
|
276
276
|
function promiseAllObject(promisesObj) {
|
|
277
277
|
const keys = Object.keys(promisesObj);
|
|
@@ -530,11 +530,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
530
530
|
}
|
|
531
531
|
return false;
|
|
532
532
|
}
|
|
533
|
-
function prefixIssues(
|
|
533
|
+
function prefixIssues(path117, issues) {
|
|
534
534
|
return issues.map((iss) => {
|
|
535
535
|
var _a3;
|
|
536
536
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
537
|
-
iss.path.unshift(
|
|
537
|
+
iss.path.unshift(path117);
|
|
538
538
|
return iss;
|
|
539
539
|
});
|
|
540
540
|
}
|
|
@@ -1055,16 +1055,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
1055
1055
|
}
|
|
1056
1056
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
1057
1057
|
const fieldErrors = { _errors: [] };
|
|
1058
|
-
const processError = (error63,
|
|
1058
|
+
const processError = (error63, path117 = []) => {
|
|
1059
1059
|
for (const issue2 of error63.issues) {
|
|
1060
1060
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1061
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1061
|
+
issue2.errors.map((issues) => processError({ issues }, [...path117, ...issue2.path]));
|
|
1062
1062
|
} else if (issue2.code === "invalid_key") {
|
|
1063
|
-
processError({ issues: issue2.issues }, [...
|
|
1063
|
+
processError({ issues: issue2.issues }, [...path117, ...issue2.path]);
|
|
1064
1064
|
} else if (issue2.code === "invalid_element") {
|
|
1065
|
-
processError({ issues: issue2.issues }, [...
|
|
1065
|
+
processError({ issues: issue2.issues }, [...path117, ...issue2.path]);
|
|
1066
1066
|
} else {
|
|
1067
|
-
const fullpath = [...
|
|
1067
|
+
const fullpath = [...path117, ...issue2.path];
|
|
1068
1068
|
if (fullpath.length === 0) {
|
|
1069
1069
|
fieldErrors._errors.push(mapper(issue2));
|
|
1070
1070
|
} else {
|
|
@@ -1103,17 +1103,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
1103
1103
|
}
|
|
1104
1104
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
1105
1105
|
const result = { errors: [] };
|
|
1106
|
-
const processError = (error63,
|
|
1106
|
+
const processError = (error63, path117 = []) => {
|
|
1107
1107
|
var _a3;
|
|
1108
1108
|
for (const issue2 of error63.issues) {
|
|
1109
1109
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1110
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1110
|
+
issue2.errors.map((issues) => processError({ issues }, [...path117, ...issue2.path]));
|
|
1111
1111
|
} else if (issue2.code === "invalid_key") {
|
|
1112
|
-
processError({ issues: issue2.issues }, [...
|
|
1112
|
+
processError({ issues: issue2.issues }, [...path117, ...issue2.path]);
|
|
1113
1113
|
} else if (issue2.code === "invalid_element") {
|
|
1114
|
-
processError({ issues: issue2.issues }, [...
|
|
1114
|
+
processError({ issues: issue2.issues }, [...path117, ...issue2.path]);
|
|
1115
1115
|
} else {
|
|
1116
|
-
const fullpath = [...
|
|
1116
|
+
const fullpath = [...path117, ...issue2.path];
|
|
1117
1117
|
if (fullpath.length === 0) {
|
|
1118
1118
|
result.errors.push(mapper(issue2));
|
|
1119
1119
|
continue;
|
|
@@ -1152,8 +1152,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
1152
1152
|
}
|
|
1153
1153
|
function toDotPath(_path) {
|
|
1154
1154
|
const segs = [];
|
|
1155
|
-
const
|
|
1156
|
-
for (const seg of
|
|
1155
|
+
const path117 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1156
|
+
for (const seg of path117) {
|
|
1157
1157
|
if (typeof seg === "number")
|
|
1158
1158
|
segs.push(`[${seg}]`);
|
|
1159
1159
|
else if (typeof seg === "symbol")
|
|
@@ -19149,13 +19149,13 @@ function resolveRef(ref, ctx) {
|
|
|
19149
19149
|
if (!ref.startsWith("#")) {
|
|
19150
19150
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
19151
19151
|
}
|
|
19152
|
-
const
|
|
19153
|
-
if (
|
|
19152
|
+
const path117 = ref.slice(1).split("/").filter(Boolean);
|
|
19153
|
+
if (path117.length === 0) {
|
|
19154
19154
|
return ctx.rootSchema;
|
|
19155
19155
|
}
|
|
19156
19156
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
19157
|
-
if (
|
|
19158
|
-
const key3 =
|
|
19157
|
+
if (path117[0] === defsKey) {
|
|
19158
|
+
const key3 = path117[1] === void 0 ? void 0 : decodeJSONPointerSegment(path117[1]);
|
|
19159
19159
|
if (!key3 || !ctx.defs[key3]) {
|
|
19160
19160
|
throw new Error(`Reference not found: ${ref}`);
|
|
19161
19161
|
}
|
|
@@ -25352,7 +25352,7 @@ var init_package_metadata = __esm({
|
|
|
25352
25352
|
__dirname = path15.dirname(fileURLToPath2(import.meta.url));
|
|
25353
25353
|
ROOT = path15.join(__dirname, "..");
|
|
25354
25354
|
PACKAGE_JSON_PATH = path15.join(ROOT, "package.json");
|
|
25355
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
25355
|
+
BUNDLED_VERSION = true ? "0.3.25" : "0.0.0";
|
|
25356
25356
|
PACKAGE_JSON = readPackageJson();
|
|
25357
25357
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
25358
25358
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -37556,7 +37556,7 @@ import * as fs17 from "node:fs";
|
|
|
37556
37556
|
import * as path16 from "node:path";
|
|
37557
37557
|
var core = (names) => names.map((name) => ({ name, profiles: ["core", "full"] }));
|
|
37558
37558
|
var full = (names) => names.map((name) => ({ name, profiles: ["full"] }));
|
|
37559
|
-
var routes = (method, paths) => paths.map((
|
|
37559
|
+
var routes = (method, paths) => paths.map((path117) => ({ method, path: path117 }));
|
|
37560
37560
|
var BUILTIN_MODULES = [
|
|
37561
37561
|
{
|
|
37562
37562
|
schemaVersion: 1,
|
|
@@ -37784,6 +37784,7 @@ var BUILTIN_MODULES = [
|
|
|
37784
37784
|
"/v1/projects/files",
|
|
37785
37785
|
"/v1/uploads/image",
|
|
37786
37786
|
"/v1/files/range",
|
|
37787
|
+
"/v1/files/resolve",
|
|
37787
37788
|
"/v1/usage",
|
|
37788
37789
|
"/v1/resources",
|
|
37789
37790
|
"/v1/speech/voices",
|
|
@@ -37851,6 +37852,7 @@ var BUILTIN_MODULES = [
|
|
|
37851
37852
|
"providers",
|
|
37852
37853
|
"files",
|
|
37853
37854
|
"repositoryFiles",
|
|
37855
|
+
"fileResolution",
|
|
37854
37856
|
"subagents",
|
|
37855
37857
|
"sideQuestions",
|
|
37856
37858
|
"approvalPush",
|
|
@@ -37973,8 +37975,8 @@ var BUILTIN_MODULES = [
|
|
|
37973
37975
|
tools: full(["code_search", "code_definition", "code_references", "code_outline", "code_usage"]),
|
|
37974
37976
|
cliCommands: ["code index", "code status", "code search", "code outline", "code refs", "code def", "code usage"],
|
|
37975
37977
|
agentHooks: [],
|
|
37976
|
-
hookRoutes: [...routes("GET", ["/v1/code/tree", "/v1/code/usage-page", "/v1/code/changed", "/v1/code/change-counts", "/v1/code/status", "/v1/code/search", "/v1/code/outline", "/v1/code/outline-summary", "/v1/code/file-references", "/v1/code/definition", "/v1/code/references", "/v1/code/usage"]), ...routes("POST", ["/v1/code/note", "/v1/code/reindex", "/v1/code/disable"])],
|
|
37977
|
-
capabilities: ["code"],
|
|
37978
|
+
hookRoutes: [...routes("GET", ["/v1/code/tree", "/v1/code/usage-page", "/v1/code/changed", "/v1/code/change-counts", "/v1/code/status", "/v1/code/search", "/v1/code/files", "/v1/code/outline", "/v1/code/outline-summary", "/v1/code/file-references", "/v1/code/definition", "/v1/code/references", "/v1/code/usage"]), ...routes("POST", ["/v1/code/note", "/v1/code/reindex", "/v1/code/disable"])],
|
|
37979
|
+
capabilities: ["code", "codeFiles"],
|
|
37978
37980
|
storeFiles: [],
|
|
37979
37981
|
localFiles: ["<store>/.runtime/code/*.sqlite"],
|
|
37980
37982
|
phoneScreens: [{ screen: "CodeView", capability: "code" }],
|
|
@@ -41154,10 +41156,10 @@ function projectAgents(values, parent, receipt, fallbackComputer, fallbackTarget
|
|
|
41154
41156
|
for (const value2 of values.slice(0, 128)) {
|
|
41155
41157
|
if (state.count >= 128) break;
|
|
41156
41158
|
const raw = object2(value2), id2 = childID.safeParse(raw.id), source = provider.safeParse(raw.provider);
|
|
41157
|
-
const
|
|
41159
|
+
const path117 = publicLabel(raw.path);
|
|
41158
41160
|
const callId = typeof raw.callId === "string" && raw.callId.length > 0 && raw.callId.length <= 200 ? raw.callId : void 0;
|
|
41159
41161
|
const routed = destination(raw, fallbackComputer, fallbackTarget);
|
|
41160
|
-
if (!id2.success || !source.success || !
|
|
41162
|
+
if (!id2.success || !source.success || !path117 || !callId || !routed) continue;
|
|
41161
41163
|
const descendant = lineage ? `${lineage}/${id2.data}` : id2.data;
|
|
41162
41164
|
const nestedSession = sessionId.safeParse(raw.session);
|
|
41163
41165
|
const cycleIdentity = nestedSession.success ? nestedSession.data : routed.remote.child ?? routed.remote.target.session;
|
|
@@ -41170,7 +41172,7 @@ function projectAgents(values, parent, receipt, fallbackComputer, fallbackTarget
|
|
|
41170
41172
|
projected.push({
|
|
41171
41173
|
id: publicID(parent, routed.computer.id, receipt.id, descendant),
|
|
41172
41174
|
provider: source.data,
|
|
41173
|
-
path:
|
|
41175
|
+
path: path117,
|
|
41174
41176
|
callId,
|
|
41175
41177
|
state: raw.failed === true ? "failed" : childState,
|
|
41176
41178
|
...typeof raw.finishedAt === "string" && Number.isFinite(Date.parse(raw.finishedAt)) ? { finishedAt: raw.finishedAt } : {},
|
|
@@ -51164,11 +51166,11 @@ var FanoutMessages = class {
|
|
|
51164
51166
|
// src/bridge/server.ts
|
|
51165
51167
|
init_wrapper();
|
|
51166
51168
|
import { randomUUID as randomUUID26 } from "node:crypto";
|
|
51167
|
-
import { chmod as chmod6, lstat as
|
|
51169
|
+
import { chmod as chmod6, lstat as lstat33, mkdir as mkdir30, readFile as readFile52, rm as rm15, unlink as unlink10, writeFile as writeFile12 } from "node:fs/promises";
|
|
51168
51170
|
import { readFileSync as readFileSync37 } from "node:fs";
|
|
51169
51171
|
import { createServer as createServer3 } from "node:http";
|
|
51170
51172
|
import { cpus as cpus2, hostname as hostname12, loadavg as loadavg2 } from "node:os";
|
|
51171
|
-
import
|
|
51173
|
+
import path115 from "node:path";
|
|
51172
51174
|
|
|
51173
51175
|
// src/bridge/speech-live.ts
|
|
51174
51176
|
init_wrapper();
|
|
@@ -51631,8 +51633,8 @@ function relayLiveSpeech(client, query, options = {}) {
|
|
|
51631
51633
|
params.set("auto_mode", "true");
|
|
51632
51634
|
params.set("inactivity_timeout", "180");
|
|
51633
51635
|
}
|
|
51634
|
-
const
|
|
51635
|
-
const socket = connect4(`${origin}${
|
|
51636
|
+
const path117 = endpoint === "dialogue" ? "/v1/text-to-dialogue/stream-input" : `/v1/text-to-speech/${encodeURIComponent(voice)}/stream-input`;
|
|
51637
|
+
const socket = connect4(`${origin}${path117}?${params}`, key3);
|
|
51636
51638
|
upstream = socket;
|
|
51637
51639
|
const current2 = () => upstream === socket && !closed;
|
|
51638
51640
|
let voiced = false, firstAudio;
|
|
@@ -52149,6 +52151,34 @@ var CodeRoutes = class {
|
|
|
52149
52151
|
this.store = store;
|
|
52150
52152
|
}
|
|
52151
52153
|
store;
|
|
52154
|
+
/** A filename need not resemble a symbol declared inside it. Query the
|
|
52155
|
+
* index's files table through @phren/code's existing public read API so
|
|
52156
|
+
* installed optional packages need no new export to serve this route. */
|
|
52157
|
+
async files(projectValue, nameValue, limitValue) {
|
|
52158
|
+
const project = projectSchema.parse(projectValue ?? "");
|
|
52159
|
+
const name = relativePathSchema.refine((value2) => !/[\x00-\x1f\x7f]/.test(value2) && !value2.split("/").includes(".git")).parse(nameValue ?? "");
|
|
52160
|
+
const limit = limitValue ? topSchema.parse(limitValue) : 20;
|
|
52161
|
+
const code = await requireCodePackage(this.store);
|
|
52162
|
+
const database = await code.openCodeDatabase(this.store, project, false);
|
|
52163
|
+
if (!database) throw noIndex(project);
|
|
52164
|
+
try {
|
|
52165
|
+
const suffix = "/" + name;
|
|
52166
|
+
const rows = code.rowsOf(
|
|
52167
|
+
database.db,
|
|
52168
|
+
`SELECT path, language FROM files WHERE path = ? OR substr(path, -?) = ?
|
|
52169
|
+
ORDER BY CASE WHEN path = ? THEN 0 ELSE 1 END, length(path), path LIMIT ?`,
|
|
52170
|
+
[name, [...suffix].length, suffix, name, limit + 1]
|
|
52171
|
+
);
|
|
52172
|
+
return {
|
|
52173
|
+
project,
|
|
52174
|
+
name,
|
|
52175
|
+
files: rows.slice(0, limit).map((row) => ({ path: code.stringAt(row, 0), language: code.stringAt(row, 1) })),
|
|
52176
|
+
truncated: rows.length > limit
|
|
52177
|
+
};
|
|
52178
|
+
} finally {
|
|
52179
|
+
database.close();
|
|
52180
|
+
}
|
|
52181
|
+
}
|
|
52152
52182
|
async status(projectValue) {
|
|
52153
52183
|
const project = projectSchema.parse(projectValue ?? "");
|
|
52154
52184
|
const result = await (await requireCodePackage(this.store)).codeIndexStatus(this.store, project);
|
|
@@ -52316,7 +52346,7 @@ var CodeRoutes = class {
|
|
|
52316
52346
|
const project = projectSchema.parse(projectValue ?? "");
|
|
52317
52347
|
const { codeDatabasePath } = await requireCodePackage(this.store);
|
|
52318
52348
|
const file3 = codeDatabasePath(this.store, project);
|
|
52319
|
-
await Promise.all([file3, `${file3}-journal`, `${file3}-wal`, `${file3}-shm`].map((
|
|
52349
|
+
await Promise.all([file3, `${file3}-journal`, `${file3}-wal`, `${file3}-shm`].map((path117) => rm11(path117, { force: true })));
|
|
52320
52350
|
return { project, disabled: true };
|
|
52321
52351
|
}
|
|
52322
52352
|
async reindex(projectValue) {
|
|
@@ -53925,7 +53955,7 @@ async function ownerInboxView(inbox, input2, localOnly = false) {
|
|
|
53925
53955
|
|
|
53926
53956
|
// src/bridge/server-routes.ts
|
|
53927
53957
|
init_zod();
|
|
53928
|
-
import
|
|
53958
|
+
import path113 from "node:path";
|
|
53929
53959
|
|
|
53930
53960
|
// src/bridge/code-note.ts
|
|
53931
53961
|
init_zod();
|
|
@@ -57522,13 +57552,53 @@ async function readFileRange(root, requested, offset, length, expectedVersion) {
|
|
|
57522
57552
|
}
|
|
57523
57553
|
}
|
|
57524
57554
|
|
|
57555
|
+
// src/bridge/file-resolve.ts
|
|
57556
|
+
import { lstat as lstat31, realpath as realpath18 } from "node:fs/promises";
|
|
57557
|
+
import path106 from "node:path";
|
|
57558
|
+
init_protocol();
|
|
57559
|
+
function beneath(root, file3) {
|
|
57560
|
+
const relative3 = path106.relative(root, file3);
|
|
57561
|
+
return relative3 !== ".." && !relative3.startsWith(`..${path106.sep}`) && !path106.isAbsolute(relative3);
|
|
57562
|
+
}
|
|
57563
|
+
async function resolveFilePath(root, cwd, requested) {
|
|
57564
|
+
if (process.platform === "win32") requested = requested.replaceAll("\\", "/");
|
|
57565
|
+
if (!requested || requested.length > 4096 || /[\x00-\x1f\x7f\\]/.test(requested) || /^[A-Za-z]:[^/]/.test(requested) || requested.split("/").includes(".git") || path106.win32.isAbsolute(requested) && !path106.isAbsolute(requested)) {
|
|
57566
|
+
throw new BridgeError(400, "Invalid file path.");
|
|
57567
|
+
}
|
|
57568
|
+
const base = await realpath18(root), folder = await realpath18(cwd);
|
|
57569
|
+
if (!beneath(base, folder)) throw new BridgeError(403, "This folder is outside the repository.");
|
|
57570
|
+
const roots = [base, path106.resolve(root), path106.resolve(cwd, path106.relative(folder, base))].map((value2) => value2.split(path106.sep).join("/"));
|
|
57571
|
+
const absolute = path106.isAbsolute(requested);
|
|
57572
|
+
const alias = roots.find((candidate) => requested === candidate || requested.startsWith(candidate + "/"));
|
|
57573
|
+
if (absolute && !alias) throw new BridgeError(403, "This file is outside the repository.");
|
|
57574
|
+
const candidates = absolute ? [{ start: base, name: requested.slice(alias.length) }] : [.../* @__PURE__ */ new Set([folder, base])].map((start) => ({ start, name: requested }));
|
|
57575
|
+
for (const candidate of candidates) {
|
|
57576
|
+
try {
|
|
57577
|
+
let file3 = candidate.start;
|
|
57578
|
+
for (const part of candidate.name.split("/").filter((part2) => part2 && part2 !== ".")) {
|
|
57579
|
+
file3 = path106.resolve(file3, part);
|
|
57580
|
+
if (!beneath(base, file3)) throw new BridgeError(403, "This file is outside the repository.");
|
|
57581
|
+
if ((await lstat31(file3)).isSymbolicLink()) throw new BridgeError(403, "Symbolic links cannot be opened.");
|
|
57582
|
+
}
|
|
57583
|
+
const relative3 = path106.relative(base, file3).split(path106.sep).join("/");
|
|
57584
|
+
const metadata = await readFileRange(base, relative3, 0, 0);
|
|
57585
|
+
return { path: relative3, size: metadata.total, contentType: metadata.contentType, version: metadata.version };
|
|
57586
|
+
} catch (error62) {
|
|
57587
|
+
if (error62 instanceof BridgeError && error62.status === 404) continue;
|
|
57588
|
+
if (["ENOENT", "ENOTDIR"].includes(error62.code ?? "")) continue;
|
|
57589
|
+
throw error62;
|
|
57590
|
+
}
|
|
57591
|
+
}
|
|
57592
|
+
throw new BridgeError(404, "This file is no longer available.");
|
|
57593
|
+
}
|
|
57594
|
+
|
|
57525
57595
|
// src/bridge/memory-store.ts
|
|
57526
57596
|
init_zod();
|
|
57527
57597
|
init_protocol();
|
|
57528
57598
|
import { execFile as execFile20 } from "node:child_process";
|
|
57529
57599
|
import { createHash as createHash26 } from "node:crypto";
|
|
57530
|
-
import { lstat as
|
|
57531
|
-
import
|
|
57600
|
+
import { lstat as lstat32, mkdir as mkdir26, readFile as readFile48, realpath as realpath19, rename as rename9, rm as rm13, writeFile as writeFile10 } from "node:fs/promises";
|
|
57601
|
+
import path107 from "node:path";
|
|
57532
57602
|
import { promisify as promisify19 } from "node:util";
|
|
57533
57603
|
var exec19 = promisify19(execFile20);
|
|
57534
57604
|
var SHA = /^[0-9a-f]{40}$/;
|
|
@@ -57556,7 +57626,7 @@ function blobSha(content) {
|
|
|
57556
57626
|
return createHash26("sha1").update(`blob ${content.length}\0`).update(content).digest("hex");
|
|
57557
57627
|
}
|
|
57558
57628
|
async function isRepository2(store) {
|
|
57559
|
-
return await
|
|
57629
|
+
return await lstat32(path107.join(store, ".git")).catch(() => void 0) !== void 0;
|
|
57560
57630
|
}
|
|
57561
57631
|
function githubStoreRepository(remote) {
|
|
57562
57632
|
let host, pathname;
|
|
@@ -57586,12 +57656,12 @@ async function storeRepositoryIdentity(store) {
|
|
|
57586
57656
|
const repository3 = githubStoreRepository(remote);
|
|
57587
57657
|
return repository3 && branch.trim() ? { repository: repository3, branch: branch.trim() } : void 0;
|
|
57588
57658
|
}
|
|
57589
|
-
function storeHead(store, indexFile =
|
|
57659
|
+
function storeHead(store, indexFile = path107.join(bridgeRoot(), "store-snapshot.index")) {
|
|
57590
57660
|
return serialized2(async () => {
|
|
57591
57661
|
if (!await isRepository2(store)) throw new BridgeError(409, "This computer's phren store is not a git repository. Run phren init.");
|
|
57592
|
-
await mkdir26(
|
|
57662
|
+
await mkdir26(path107.dirname(indexFile), { recursive: true, mode: 448 });
|
|
57593
57663
|
const env = { GIT_INDEX_FILE: indexFile };
|
|
57594
|
-
if (!await
|
|
57664
|
+
if (!await lstat32(indexFile).catch(() => void 0)) {
|
|
57595
57665
|
const head = await git5(store, ["rev-parse", "--verify", "--quiet", "HEAD"]).catch(() => "");
|
|
57596
57666
|
await git5(store, head.trim() ? ["read-tree", "HEAD"] : ["read-tree", "--empty"], env);
|
|
57597
57667
|
}
|
|
@@ -57624,22 +57694,22 @@ async function storeBlob(store, sha) {
|
|
|
57624
57694
|
return { sha, encoding: "base64", content: stdout.toString("base64") };
|
|
57625
57695
|
}
|
|
57626
57696
|
async function storeFile(store, relative3) {
|
|
57627
|
-
const normalized =
|
|
57628
|
-
if (!relative3 || relative3 !== normalized || normalized.startsWith("../") || normalized === ".." ||
|
|
57697
|
+
const normalized = path107.posix.normalize(relative3);
|
|
57698
|
+
if (!relative3 || relative3 !== normalized || normalized.startsWith("../") || normalized === ".." || path107.posix.isAbsolute(normalized) || normalized.split("/").some((part) => part === ".git" || part === "" || part === ".") || /[\0\r\n]/.test(normalized)) {
|
|
57629
57699
|
throw new BridgeError(400, "Invalid store path.");
|
|
57630
57700
|
}
|
|
57631
|
-
const root = await
|
|
57632
|
-
let parent =
|
|
57701
|
+
const root = await realpath19(store);
|
|
57702
|
+
let parent = path107.dirname(path107.join(root, normalized));
|
|
57633
57703
|
for (; ; ) {
|
|
57634
|
-
const real2 = await
|
|
57704
|
+
const real2 = await realpath19(parent).catch(() => void 0);
|
|
57635
57705
|
if (real2) {
|
|
57636
|
-
if (real2 !== root && !real2.startsWith(root +
|
|
57706
|
+
if (real2 !== root && !real2.startsWith(root + path107.sep)) throw new BridgeError(400, "Invalid store path.");
|
|
57637
57707
|
break;
|
|
57638
57708
|
}
|
|
57639
|
-
parent =
|
|
57709
|
+
parent = path107.dirname(parent);
|
|
57640
57710
|
}
|
|
57641
|
-
const file3 =
|
|
57642
|
-
const info = await
|
|
57711
|
+
const file3 = path107.join(root, normalized);
|
|
57712
|
+
const info = await lstat32(file3).catch(() => void 0);
|
|
57643
57713
|
if (info && !info.isFile()) throw new BridgeError(400, "Invalid store path.");
|
|
57644
57714
|
return file3;
|
|
57645
57715
|
}
|
|
@@ -57659,7 +57729,7 @@ function putStoreFile(store, data) {
|
|
|
57659
57729
|
return serialized2(async () => {
|
|
57660
57730
|
const file3 = await storeFile(store, input2.path);
|
|
57661
57731
|
if (await currentSha(file3) !== (input2.sha ?? null)) throw new BridgeError(409, `${input2.path} changed on this computer.`);
|
|
57662
|
-
await mkdir26(
|
|
57732
|
+
await mkdir26(path107.dirname(file3), { recursive: true });
|
|
57663
57733
|
const temporary = `${file3}.phren-${process.pid}-${Date.now()}`;
|
|
57664
57734
|
await writeFile10(temporary, content, { flag: "wx" });
|
|
57665
57735
|
await rename9(temporary, file3);
|
|
@@ -57695,7 +57765,7 @@ init_protocol();
|
|
|
57695
57765
|
import { execFile as execFile21 } from "node:child_process";
|
|
57696
57766
|
import { chmod as chmod5, mkdir as mkdir27, readFile as readFile49, rename as rename10, stat as stat27, unlink as unlink9, writeFile as writeFile11 } from "node:fs/promises";
|
|
57697
57767
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
57698
|
-
import
|
|
57768
|
+
import path108 from "node:path";
|
|
57699
57769
|
import { createHash as createHash27, randomUUID as randomUUID25 } from "node:crypto";
|
|
57700
57770
|
import { promisify as promisify20 } from "node:util";
|
|
57701
57771
|
var exec20 = promisify20(execFile21);
|
|
@@ -57723,7 +57793,7 @@ async function bootedSimulators() {
|
|
|
57723
57793
|
async function simulatorScreenshot(udid) {
|
|
57724
57794
|
if (!UDID.test(udid)) throw new BridgeError(400, "Invalid simulator identifier.");
|
|
57725
57795
|
if (process.platform !== "darwin") throw new BridgeError(404, "Simulators run on macOS only.");
|
|
57726
|
-
const file3 =
|
|
57796
|
+
const file3 = path108.join(tmpdir4(), `phren-sim-${randomUUID25()}.png`);
|
|
57727
57797
|
try {
|
|
57728
57798
|
await exec20("/usr/bin/xcrun", ["simctl", "io", udid, "screenshot", "--type=png", file3], { timeout: 15e3 });
|
|
57729
57799
|
return await readFile49(file3);
|
|
@@ -57742,14 +57812,14 @@ function helper() {
|
|
|
57742
57812
|
return building;
|
|
57743
57813
|
}
|
|
57744
57814
|
async function buildHelper() {
|
|
57745
|
-
const dir =
|
|
57746
|
-
const binary =
|
|
57815
|
+
const dir = path108.join(bridgeRoot(), "native");
|
|
57816
|
+
const binary = path108.join(dir, "simtap");
|
|
57747
57817
|
const code = true ? '// Touches and keys for the iOS Simulator, without AppleScript: the window\n// is found through the Accessibility API and events are posted with CGEvent,\n// so one Accessibility grant for this helper is all macOS asks for.\n// Built on demand by Phren Hook with swiftc; see simulators.ts.\nimport ApplicationServices\nimport Cocoa\n\nfunc fail(_ code: Int32, _ message: String) -> Never { FileHandle.standardError.write((message + "\\n").data(using: .utf8)!); exit(code) }\n\nlet args = CommandLine.arguments\nguard args.count >= 3 else { fail(2, "usage: simtap <window-title-prefix> tap <fx> <fy> | key <keycode> [cmd] [shift] | type <text> | raise") }\nlet prefix = args[1], command = args[2]\n\nguard AXIsProcessTrusted() else { fail(3, "accessibility") }\nguard let app = NSRunningApplication.runningApplications(withBundleIdentifier: "com.apple.iphonesimulator").first else { fail(4, "Simulator is not running") }\nlet element = AXUIElementCreateApplication(app.processIdentifier)\nvar windowsRef: CFTypeRef?\nAXUIElementCopyAttributeValue(element, kAXWindowsAttribute as CFString, &windowsRef)\nlet windows = (windowsRef as? [AXUIElement]) ?? []\nvar target: AXUIElement?\nfor window in windows {\n var titleRef: CFTypeRef?\n AXUIElementCopyAttributeValue(window, kAXTitleAttribute as CFString, &titleRef)\n if let title = titleRef as? String, title.hasPrefix(prefix + " ") || title == prefix { target = window; break }\n}\nguard let window = target else { fail(5, "no window for \\(prefix)") }\n\nfunc frame(_ window: AXUIElement) -> CGRect {\n var posRef: CFTypeRef?, sizeRef: CFTypeRef?\n AXUIElementCopyAttributeValue(window, kAXPositionAttribute as CFString, &posRef)\n AXUIElementCopyAttributeValue(window, kAXSizeAttribute as CFString, &sizeRef)\n var pos = CGPoint.zero, size = CGSize.zero\n if let p = posRef { AXValueGetValue(p as! AXValue, .cgPoint, &pos) }\n if let s = sizeRef { AXValueGetValue(s as! AXValue, .cgSize, &size) }\n return CGRect(origin: pos, size: size)\n}\nfunc raise() {\n app.activate(options: [])\n AXUIElementPerformAction(window, kAXRaiseAction as CFString)\n usleep(120_000)\n}\nfunc post(_ event: CGEvent?) {\n guard NSWorkspace.shared.frontmostApplication?.processIdentifier == app.processIdentifier else { fail(6, "focus lost") }\n event?.postToPid(app.processIdentifier)\n usleep(40_000)\n}\n\nswitch command {\ncase "raise": raise()\ncase "tap":\n guard args.count >= 5, let fx = Double(args[3]), let fy = Double(args[4]) else { fail(2, "tap needs fx fy") }\n raise()\n let f = frame(window)\n // The device screen fills the window below its title bar.\n let titleBar: CGFloat = 28\n let point = CGPoint(x: f.origin.x + CGFloat(fx) * f.width, y: f.origin.y + titleBar + CGFloat(fy) * (f.height - titleBar))\n post(CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left))\n post(CGEvent(mouseEventSource: nil, mouseType: .leftMouseDown, mouseCursorPosition: point, mouseButton: .left))\n post(CGEvent(mouseEventSource: nil, mouseType: .leftMouseUp, mouseCursorPosition: point, mouseButton: .left))\ncase "key":\n guard args.count >= 4, let code = UInt16(args[3]) else { fail(2, "key needs a keycode") }\n raise()\n var flags: CGEventFlags = []\n if args.contains("cmd") { flags.insert(.maskCommand) }\n if args.contains("shift") { flags.insert(.maskShift) }\n let down = CGEvent(keyboardEventSource: nil, virtualKey: code, keyDown: true), up = CGEvent(keyboardEventSource: nil, virtualKey: code, keyDown: false)\n down?.flags = flags; up?.flags = flags\n post(down); post(up)\ncase "type":\n guard args.count >= 4, !args[3].isEmpty, args[3].utf16.count <= 500 else { fail(2, "type needs at most 500 characters") }\n let submit = args.count == 5 && args[4] == "submit"\n guard args[3].unicodeScalars.allSatisfy({ scalar in\n (scalar.value >= 32 && scalar.value != 127) || (scalar.value == 10 && submit)\n }) else { fail(2, "invalid type controls; newline needs submit") }\n raise()\n for scalar in args[3].unicodeScalars {\n var chars = Array(String(scalar).utf16)\n let down = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: true), up = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: false)\n down?.keyboardSetUnicodeString(stringLength: chars.count, unicodeString: &chars)\n up?.keyboardSetUnicodeString(stringLength: chars.count, unicodeString: &chars)\n post(down); post(up)\n }\ndefault: fail(2, "unknown command \\(command)")\n}\n' : await readFile49(new URL("./native/simtap.swift", import.meta.url), "utf8");
|
|
57748
57818
|
const digest2 = createHash27("sha256").update(code).digest("hex");
|
|
57749
57819
|
const saved = await readFile49(binary + ".sha256", "utf8").then(JSON.parse).catch(() => void 0);
|
|
57750
57820
|
if (await stat27(binary).catch(() => void 0) && saved?.sourceSha === digest2) return binary;
|
|
57751
57821
|
await mkdir27(dir, { recursive: true, mode: 448 });
|
|
57752
|
-
const temporary =
|
|
57822
|
+
const temporary = path108.join(dir, `simtap.${randomUUID25()}`), source = temporary + ".swift";
|
|
57753
57823
|
const sidecar = temporary + ".sha256";
|
|
57754
57824
|
try {
|
|
57755
57825
|
await writeFile11(source, code, { mode: 384, flag: "wx" });
|
|
@@ -57862,7 +57932,7 @@ init_transcripts();
|
|
|
57862
57932
|
init_transcript_index();
|
|
57863
57933
|
init_transcripts();
|
|
57864
57934
|
import { homedir as homedir20, tmpdir as tmpdir5 } from "node:os";
|
|
57865
|
-
import
|
|
57935
|
+
import path109 from "node:path";
|
|
57866
57936
|
init_protocol();
|
|
57867
57937
|
var cache = /* @__PURE__ */ new Map();
|
|
57868
57938
|
var modelCache = /* @__PURE__ */ new Map();
|
|
@@ -58000,7 +58070,7 @@ function describe3(tool, args) {
|
|
|
58000
58070
|
return "";
|
|
58001
58071
|
};
|
|
58002
58072
|
const firstLine = (v) => v.split(/\r?\n/).map((l) => l.trim()).find((l) => l) ?? "";
|
|
58003
|
-
const base = (v) =>
|
|
58073
|
+
const base = (v) => path109.basename(v.split(" \xB7 ")[0].trim()) || "file";
|
|
58004
58074
|
const name = tool.toLowerCase();
|
|
58005
58075
|
let value2;
|
|
58006
58076
|
if (["bash", "shell", "exec_command", "exec", "parallel", "tools", "write_stdin", "container.exec"].includes(name)) {
|
|
@@ -58040,7 +58110,7 @@ init_terminal_text();
|
|
|
58040
58110
|
init_codex_servers();
|
|
58041
58111
|
init_herdr();
|
|
58042
58112
|
import { open as open23 } from "node:fs/promises";
|
|
58043
|
-
import
|
|
58113
|
+
import path110 from "node:path";
|
|
58044
58114
|
init_protocol();
|
|
58045
58115
|
init_terminal();
|
|
58046
58116
|
init_terminal_choice();
|
|
@@ -58101,7 +58171,7 @@ var defaultRenameDeps = {
|
|
|
58101
58171
|
return text4 === void 0 ? void 0 : lastCustomTitle(text4);
|
|
58102
58172
|
},
|
|
58103
58173
|
async codexIndexTitle(thread) {
|
|
58104
|
-
const text4 = await tail(
|
|
58174
|
+
const text4 = await tail(path110.join(codexHome(), "session_index.jsonl"));
|
|
58105
58175
|
return text4 === void 0 ? void 0 : lastIndexedName(text4, thread);
|
|
58106
58176
|
},
|
|
58107
58177
|
sleep: (ms) => new Promise((resolve11) => setTimeout(resolve11, ms)),
|
|
@@ -58195,15 +58265,15 @@ init_terminal();
|
|
|
58195
58265
|
init_terminal_tmux();
|
|
58196
58266
|
init_limits();
|
|
58197
58267
|
import { mkdir as mkdir29, readFile as readFile50 } from "node:fs/promises";
|
|
58198
|
-
import
|
|
58268
|
+
import path112 from "node:path";
|
|
58199
58269
|
|
|
58200
58270
|
// src/bridge/launch-worktree.ts
|
|
58201
58271
|
init_zod();
|
|
58202
58272
|
init_utils_helpers();
|
|
58203
58273
|
init_metrics();
|
|
58204
58274
|
import { execFile as execFile22 } from "node:child_process";
|
|
58205
|
-
import { mkdir as mkdir28, realpath as
|
|
58206
|
-
import
|
|
58275
|
+
import { mkdir as mkdir28, realpath as realpath20, rm as rm14, stat as stat28 } from "node:fs/promises";
|
|
58276
|
+
import path111 from "node:path";
|
|
58207
58277
|
import { promisify as promisify21 } from "node:util";
|
|
58208
58278
|
init_protocol();
|
|
58209
58279
|
var exec21 = promisify21(execFile22);
|
|
@@ -58232,20 +58302,20 @@ async function createLaunchWorktree(cwd, request9) {
|
|
|
58232
58302
|
if (await git6(root, "show-ref", "--verify", "--quiet", `refs/heads/${branch}`).then(() => true, () => false)) {
|
|
58233
58303
|
throw new BridgeError(409, `A branch named "${branch}" already exists in this repository. Choose another branch name.`);
|
|
58234
58304
|
}
|
|
58235
|
-
const worktree =
|
|
58305
|
+
const worktree = path111.join(root, ".claude", "worktrees", worktreeFolderName(branch));
|
|
58236
58306
|
if (await stat28(worktree).then(() => true, () => false)) {
|
|
58237
58307
|
throw new BridgeError(409, `The folder .claude/worktrees/${worktreeFolderName(branch)} already exists. Choose another branch name.`);
|
|
58238
58308
|
}
|
|
58239
|
-
await mkdir28(
|
|
58309
|
+
await mkdir28(path111.dirname(worktree), { recursive: true });
|
|
58240
58310
|
try {
|
|
58241
58311
|
await git6(root, "worktree", "add", "-b", branch, worktree, head);
|
|
58242
58312
|
} catch (error62) {
|
|
58243
58313
|
const detail = error62 instanceof Error && "stderr" in error62 ? String(error62.stderr ?? "").trim().split("\n").at(-1) : "";
|
|
58244
58314
|
throw new BridgeError(409, `Git could not create the worktree${detail ? `: ${detail.replace(/^fatal:\s*/, "")}` : "."}`);
|
|
58245
58315
|
}
|
|
58246
|
-
const abs = await
|
|
58247
|
-
const inside =
|
|
58248
|
-
const start = inside && !inside.startsWith("..") ?
|
|
58316
|
+
const abs = await realpath20(worktree);
|
|
58317
|
+
const inside = path111.relative(root, await realpath20(cwd));
|
|
58318
|
+
const start = inside && !inside.startsWith("..") ? path111.join(abs, inside) : abs;
|
|
58249
58319
|
const startDir = await stat28(start).then((value2) => value2.isDirectory(), () => false) ? start : abs;
|
|
58250
58320
|
return {
|
|
58251
58321
|
cwd: startDir,
|
|
@@ -58288,7 +58358,7 @@ async function phrenLaunchArgs(kind, data, store = phrenStoreRoot()) {
|
|
|
58288
58358
|
return [...mode === "chat" ? ["--mode", "chat"] : [], ...resume ? ["--session", resume] : []];
|
|
58289
58359
|
}
|
|
58290
58360
|
async function sessionUsedTools(session, store = phrenStoreRoot()) {
|
|
58291
|
-
const raw = await readFile50(
|
|
58361
|
+
const raw = await readFile50(path112.join(store, ".sessions", `session-${session}.events.jsonl`), "utf8").catch(() => "");
|
|
58292
58362
|
const withTools = (message) => {
|
|
58293
58363
|
const content = message?.content;
|
|
58294
58364
|
return Array.isArray(content) && content.some((block) => ["tool_use", "tool_result"].includes(String(block?.type)));
|
|
@@ -58320,8 +58390,8 @@ async function prepareConductor(kind, effort, model) {
|
|
|
58320
58390
|
if (kind === "claude") return [...model ? ["--model", model] : [], "--append-system-prompt-file", briefFile, "--effort", effort];
|
|
58321
58391
|
if (kind === "codex") return [...model ? ["--model", model] : [], "-c", `model_reasoning_effort=${effort}`, "-c", `developer_instructions=${JSON.stringify(brief)}`];
|
|
58322
58392
|
if (kind === "opencode") {
|
|
58323
|
-
const directory =
|
|
58324
|
-
const file3 =
|
|
58393
|
+
const directory = path112.join(process.env.XDG_CONFIG_HOME || path112.join(homeDir(), ".config"), "opencode", "agents");
|
|
58394
|
+
const file3 = path112.join(directory, "conductor.md");
|
|
58325
58395
|
const definition = `---
|
|
58326
58396
|
description: Coordinate the owner's work across agent sessions.
|
|
58327
58397
|
mode: primary
|
|
@@ -58457,7 +58527,7 @@ async function stillListed(server, result) {
|
|
|
58457
58527
|
}
|
|
58458
58528
|
async function startSession(server, data, options) {
|
|
58459
58529
|
const role = external_exports.enum(["agent", "conductor"]).default("agent").parse(data.role);
|
|
58460
|
-
const projectDirectory = external_exports.string().min(1).max(4096).refine((t) =>
|
|
58530
|
+
const projectDirectory = external_exports.string().min(1).max(4096).refine((t) => path112.isAbsolute(t) && !/[\x00-\x1f\x7f]/.test(t)).parse(data.cwd);
|
|
58461
58531
|
const worktreeRequest = data.worktree === void 0 || data.worktree === null ? void 0 : launchWorktreeSchema.parse(data.worktree);
|
|
58462
58532
|
if (worktreeRequest && role === "conductor") throw new BridgeError(400, "A conductor works across projects, so it cannot start in a worktree.");
|
|
58463
58533
|
const label2 = plainText(200).parse(data.label);
|
|
@@ -58643,7 +58713,7 @@ async function workspaceAction(server, operation, data) {
|
|
|
58643
58713
|
if (tab && !objects(s.tabs).some((t) => t.tab_id === tab && (!workspace || t.workspace_id === workspace))) throw new BridgeError(409, "The tab changed.");
|
|
58644
58714
|
if (pane && !objects(s.panes).some((p) => p.pane_id === pane && (!tab || p.tab_id === tab) && (!workspace || p.workspace_id === workspace))) throw new BridgeError(409, "The pane changed.");
|
|
58645
58715
|
const label2 = data.label === void 0 ? void 0 : external_exports.string().min(1).max(200).refine((t) => !/[\x00-\x1f\x7f]/.test(t)).parse(data.label);
|
|
58646
|
-
const cwd = data.cwd === void 0 ? void 0 : external_exports.string().max(4096).refine((t) =>
|
|
58716
|
+
const cwd = data.cwd === void 0 ? void 0 : external_exports.string().max(4096).refine((t) => path112.isAbsolute(t) && !/[\x00-\x1f\x7f]/.test(t)).parse(data.cwd);
|
|
58647
58717
|
if (operation === "create") await terminalProvider().create(server, { workspace, label: label2, cwd });
|
|
58648
58718
|
else if (!workspace && !tab && !pane) throw new BridgeError(400, "Choose a Herdr destination.");
|
|
58649
58719
|
else if (pane && operation === "focus") await terminalProvider().focusPane(server, pane);
|
|
@@ -58798,6 +58868,7 @@ var capabilities = {
|
|
|
58798
58868
|
providers: ["codex", "claude", "copilot", "opencode"],
|
|
58799
58869
|
files: true,
|
|
58800
58870
|
repositoryFiles: true,
|
|
58871
|
+
fileResolution: true,
|
|
58801
58872
|
subagents: true,
|
|
58802
58873
|
sideQuestions: true,
|
|
58803
58874
|
dispatch: true,
|
|
@@ -58808,6 +58879,7 @@ var capabilities = {
|
|
|
58808
58879
|
approvalPush: "direct-apns",
|
|
58809
58880
|
simulators: process.platform === "darwin",
|
|
58810
58881
|
code: true,
|
|
58882
|
+
codeFiles: true,
|
|
58811
58883
|
overviewStream: true,
|
|
58812
58884
|
speech: true,
|
|
58813
58885
|
speechTimestamps: true,
|
|
@@ -59135,10 +59207,18 @@ function createRouteHandler(ctx) {
|
|
|
59135
59207
|
case "/v1/files":
|
|
59136
59208
|
result = { files: await listUploads("files") };
|
|
59137
59209
|
break;
|
|
59210
|
+
case "/v1/files/resolve": {
|
|
59211
|
+
const target = targetFromURL(url2), pane = await validateTarget(target);
|
|
59212
|
+
const cwd = await gitRepository(pane, target, url2.searchParams.get("child") ?? void 0, url2.searchParams.get("worktree") ?? void 0);
|
|
59213
|
+
const repository3 = await gitRoot(cwd);
|
|
59214
|
+
if (!repository3) throw new BridgeError(409, "This pane is not in a project repository.");
|
|
59215
|
+
result = await resolveFilePath(repository3, cwd, url2.searchParams.get("path") ?? "");
|
|
59216
|
+
break;
|
|
59217
|
+
}
|
|
59138
59218
|
case "/v1/files/range": {
|
|
59139
59219
|
let root;
|
|
59140
59220
|
if (url2.searchParams.get("scope") === "uploads") {
|
|
59141
|
-
root =
|
|
59221
|
+
root = path113.join(bridgeRoot(), "uploads");
|
|
59142
59222
|
} else if (url2.searchParams.has("session")) {
|
|
59143
59223
|
const target = targetFromURL(url2), pane = await validateTarget(target);
|
|
59144
59224
|
const cwd = await gitRepository(pane, target, url2.searchParams.get("child") ?? void 0, url2.searchParams.get("worktree") ?? void 0);
|
|
@@ -59318,6 +59398,9 @@ function createRouteHandler(ctx) {
|
|
|
59318
59398
|
case "/v1/code/search":
|
|
59319
59399
|
result = await new CodeRoutes(await resolveCodeStore(scheduleStore, url2.searchParams.get("store"))).search(url2.searchParams.get("project"), url2.searchParams.get("q"), url2.searchParams.get("kind"), url2.searchParams.get("limit"), url2.searchParams.get("directory"));
|
|
59320
59400
|
break;
|
|
59401
|
+
case "/v1/code/files":
|
|
59402
|
+
result = await new CodeRoutes(await resolveCodeStore(scheduleStore, url2.searchParams.get("store"))).files(url2.searchParams.get("project"), url2.searchParams.get("name"), url2.searchParams.get("limit"));
|
|
59403
|
+
break;
|
|
59321
59404
|
case "/v1/code/outline-summary":
|
|
59322
59405
|
result = await new CodeRoutes(await resolveCodeStore(scheduleStore, url2.searchParams.get("store"))).outlineSummary(url2.searchParams.get("project"), url2.searchParams.get("paths"));
|
|
59323
59406
|
break;
|
|
@@ -60259,9 +60342,9 @@ init_home_paths();
|
|
|
60259
60342
|
init_logger();
|
|
60260
60343
|
init_protocol();
|
|
60261
60344
|
import { readFile as readFile51 } from "node:fs/promises";
|
|
60262
|
-
import
|
|
60345
|
+
import path114 from "node:path";
|
|
60263
60346
|
var REFRESH_AFTER_MS = 6 * 864e5;
|
|
60264
|
-
async function lastCodexRefresh(file3 =
|
|
60347
|
+
async function lastCodexRefresh(file3 = path114.join(codexHome(), "auth.json")) {
|
|
60265
60348
|
try {
|
|
60266
60349
|
const auth = object2(JSON.parse(await readFile51(file3, "utf8")));
|
|
60267
60350
|
if (!object2(auth.tokens).refresh_token) return void 0;
|
|
@@ -60317,7 +60400,7 @@ async function serve(version3, options = {}) {
|
|
|
60317
60400
|
await mkdir30(root, { recursive: true, mode: 448 });
|
|
60318
60401
|
await chmod6(root, 448);
|
|
60319
60402
|
let computerID2;
|
|
60320
|
-
const identityFile =
|
|
60403
|
+
const identityFile = path115.join(root, "computer-id");
|
|
60321
60404
|
try {
|
|
60322
60405
|
computerID2 = (await readFile52(identityFile, "utf8")).trim();
|
|
60323
60406
|
} catch {
|
|
@@ -60437,7 +60520,7 @@ async function serve(version3, options = {}) {
|
|
|
60437
60520
|
if (codeReindexer) agentHooks.changes.onRecord = (files) => codeReindexer.record(files);
|
|
60438
60521
|
function gatewayTiming() {
|
|
60439
60522
|
try {
|
|
60440
|
-
const parsed = JSON.parse(readFileSync37(
|
|
60523
|
+
const parsed = JSON.parse(readFileSync37(path115.join(root, "gateway.json"), "utf8"));
|
|
60441
60524
|
if (typeof parsed.ms === "number" && Number.isFinite(parsed.ms) && parsed.ms >= 0) return Math.round(parsed.ms);
|
|
60442
60525
|
} catch {
|
|
60443
60526
|
}
|
|
@@ -60466,7 +60549,7 @@ async function serve(version3, options = {}) {
|
|
|
60466
60549
|
launch: (server, data) => launches.run(() => launchSession(server, data, { canary: true })),
|
|
60467
60550
|
scheduler
|
|
60468
60551
|
});
|
|
60469
|
-
const old = await
|
|
60552
|
+
const old = await lstat33(socketPath()).catch(() => null);
|
|
60470
60553
|
if (old) {
|
|
60471
60554
|
if (!old.isSocket() || process.getuid && old.uid !== process.getuid()) throw new Error("Refusing to replace an unexpected hook socket.");
|
|
60472
60555
|
const { connect: connect4 } = await import("node:net");
|
|
@@ -60483,7 +60566,7 @@ async function serve(version3, options = {}) {
|
|
|
60483
60566
|
}
|
|
60484
60567
|
const stopRetention = modules.has("git") ? await startChangeRetention() : () => {
|
|
60485
60568
|
};
|
|
60486
|
-
if (modules.has("git")) await rm15(
|
|
60569
|
+
if (modules.has("git")) await rm15(path115.join(root, "changes-scratch"), { recursive: true, force: true });
|
|
60487
60570
|
const streams = transcriptStreams({ modules, agentHooks, codexQuestions, sideQuestions, settingsSwitcher, info, activeCapabilities });
|
|
60488
60571
|
const { stream } = streams;
|
|
60489
60572
|
const overview = overviewStream({
|
|
@@ -60671,7 +60754,7 @@ init_phren_paths();
|
|
|
60671
60754
|
import { execFile as execFile23 } from "node:child_process";
|
|
60672
60755
|
import { readFile as readFile53 } from "node:fs/promises";
|
|
60673
60756
|
import { homedir as homedir21, hostname as hostname13, userInfo as userInfo5 } from "node:os";
|
|
60674
|
-
import
|
|
60757
|
+
import path116 from "node:path";
|
|
60675
60758
|
import { promisify as promisify22 } from "node:util";
|
|
60676
60759
|
init_protocol();
|
|
60677
60760
|
var exec22 = promisify22(execFile23);
|
|
@@ -60718,11 +60801,11 @@ async function probe2(host) {
|
|
|
60718
60801
|
return computerId ? { host, computerId, user: field("user") ?? "", client: field("client") } : void 0;
|
|
60719
60802
|
}
|
|
60720
60803
|
async function discoverComputers(options = {}) {
|
|
60721
|
-
const config3 = options.sshConfig ?? await readFile53(
|
|
60804
|
+
const config3 = options.sshConfig ?? await readFile53(path116.join(homedir21(), ".ssh", "config"), "utf8").catch(() => "");
|
|
60722
60805
|
const store = options.store !== void 0 ? options.store : findPhrenPath();
|
|
60723
60806
|
const machines = store ? listMachines(store) : void 0;
|
|
60724
60807
|
const { peers } = await optionalHookPeers();
|
|
60725
|
-
const own2 = (await readFile53(
|
|
60808
|
+
const own2 = (await readFile53(path116.join(bridgeRoot(), "computer-id"), "utf8").catch(() => "")).trim();
|
|
60726
60809
|
const known2 = new Set([...localNames(), ...peers.flatMap((peer) => [peer.name, peer.address])].map(computerLabel));
|
|
60727
60810
|
const candidates = [.../* @__PURE__ */ new Set([...sshConfigHosts(config3), ...machines?.ok ? Object.keys(machines.data) : []])].filter((host) => !known2.has(computerLabel(host))).slice(0, 32);
|
|
60728
60811
|
const [found, peerIds] = await Promise.all([
|
|
@@ -60744,7 +60827,7 @@ function slugName(value2) {
|
|
|
60744
60827
|
async function linkComputer(host, options = {}) {
|
|
60745
60828
|
const remote = await probe2(host);
|
|
60746
60829
|
if (!remote) throw new BridgeError(409, `${host} answers over ssh but Phren Hook is not installed there. Run phren bridge install on it first.`);
|
|
60747
|
-
const own2 = (await readFile53(
|
|
60830
|
+
const own2 = (await readFile53(path116.join(bridgeRoot(), "computer-id"), "utf8").catch(() => "")).trim();
|
|
60748
60831
|
if (remote.computerId === own2) throw new BridgeError(409, `${host} is this computer.`);
|
|
60749
60832
|
const name = computerName.parse(options.name ?? slugName(host));
|
|
60750
60833
|
const as = computerName.parse(options.as ?? slugName(hostname13()));
|
|
@@ -61037,7 +61120,7 @@ async function readSecret(prompt) {
|
|
|
61037
61120
|
// src/bridge/hook-main.ts
|
|
61038
61121
|
init_utils_helpers();
|
|
61039
61122
|
Object.assign(process.env, nonInteractiveGitEnv());
|
|
61040
|
-
runBridge(process.argv.slice(2), "0.3.
|
|
61123
|
+
runBridge(process.argv.slice(2), "0.3.25").then((code) => {
|
|
61041
61124
|
process.exitCode = code;
|
|
61042
61125
|
}).catch((error62) => {
|
|
61043
61126
|
console.error(error62 instanceof Error ? error62.message : "Phren Hook failed.");
|