@phren/cli 0.3.32 → 0.3.34
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/computer-names.d.ts +4 -0
- package/dist/bridge/computer-names.js +19 -0
- package/dist/bridge/model-switch.d.ts +4 -0
- package/dist/bridge/model-switch.js +16 -4
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-format.js +9 -1
- package/dist/bridge/schedules.d.ts +5 -0
- package/dist/bridge/schedules.js +14 -6
- package/dist/bridge/server.js +1 -0
- package/dist/bridge/settings-switch.js +2 -6
- package/dist/bridge/usage.d.ts +7 -0
- package/dist/bridge/usage.js +15 -1
- package/dist/bridge-hook.mjs +87 -39
- package/dist/cli/search.js +6 -1
- package/dist/index-query.d.ts +6 -1
- package/dist/index-query.js +22 -3
- package/dist/response-budget.d.ts +47 -0
- package/dist/response-budget.js +86 -0
- package/dist/tools/data.js +2 -1
- package/dist/tools/search.js +89 -50
- package/dist/tools/tasks.js +61 -33
- package/dist/tools/types.d.ts +5 -1
- package/dist/tools/types.js +18 -2
- package/package.json +1 -1
package/dist/bridge-hook.mjs
CHANGED
|
@@ -2276,9 +2276,9 @@ function parseURLObject(trimmed, def) {
|
|
|
2276
2276
|
function stripTabAndNewline(value2) {
|
|
2277
2277
|
return value2.replace(asciiTabOrNewline, "");
|
|
2278
2278
|
}
|
|
2279
|
-
function urlHostnameOk(url2,
|
|
2280
|
-
|
|
2281
|
-
return
|
|
2279
|
+
function urlHostnameOk(url2, hostname14) {
|
|
2280
|
+
hostname14.lastIndex = 0;
|
|
2281
|
+
return hostname14.test(url2.hostname);
|
|
2282
2282
|
}
|
|
2283
2283
|
function urlProtocolOk(url2, protocol) {
|
|
2284
2284
|
protocol.lastIndex = 0;
|
|
@@ -37420,7 +37420,7 @@ var init_package_metadata = __esm({
|
|
|
37420
37420
|
__dirname = path37.dirname(fileURLToPath2(import.meta.url));
|
|
37421
37421
|
ROOT = path37.join(__dirname, "..");
|
|
37422
37422
|
PACKAGE_JSON_PATH = path37.join(ROOT, "package.json");
|
|
37423
|
-
BUNDLED_VERSION = true ? "0.3.
|
|
37423
|
+
BUNDLED_VERSION = true ? "0.3.34" : "0.0.0";
|
|
37424
37424
|
PACKAGE_JSON = readPackageJson();
|
|
37425
37425
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
37426
37426
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -38824,7 +38824,7 @@ async function captureClaudeUsage(original) {
|
|
|
38824
38824
|
});
|
|
38825
38825
|
}
|
|
38826
38826
|
}
|
|
38827
|
-
var exec7, claudeFile, safeText, openCodeAuthFile, GO_GATEWAY, GO_KEY_MESSAGE, GO_WINDOWS, openCodeLogDir, refusalScans, FIRST_SCAN_BYTES, clock, goPlanCached, goPlanPending, claudeCredentialsFile, CLAUDE_REPORT_MAX_AGE_MS, AccountUsageReader, quote2;
|
|
38827
|
+
var exec7, claudeFile, safeText, openCodeAuthFile, GO_GATEWAY, GO_KEY_MESSAGE, GO_WINDOWS, openCodeLogDir, refusalScans, FIRST_SCAN_BYTES, clock, goPlanCached, goPlanPending, claudeCredentialsFile, CLAUDE_REPORT_MAX_AGE_MS, OPENCODE_STATS_REUSE_MS, AccountUsageReader, quote2;
|
|
38828
38828
|
var init_usage = __esm({
|
|
38829
38829
|
"src/bridge/usage.ts"() {
|
|
38830
38830
|
"use strict";
|
|
@@ -38856,6 +38856,7 @@ var init_usage = __esm({
|
|
|
38856
38856
|
clock = (iso) => `${iso.slice(11, 16)} UTC`;
|
|
38857
38857
|
claudeCredentialsFile = (home) => path43.join(home?.dir ?? claudeConfigDir(), ".credentials.json");
|
|
38858
38858
|
CLAUDE_REPORT_MAX_AGE_MS = 3 * 864e5;
|
|
38859
|
+
OPENCODE_STATS_REUSE_MS = 10 * 6e4;
|
|
38859
38860
|
AccountUsageReader = class {
|
|
38860
38861
|
constructor(readCodex = readCodexLimits, now = Date.now, readClaudeLive = liveClaudeUsage, readOpenCode = (now2) => readOpenCodeUsage("opencode", now2), readOpenRouter = liveOpenRouterUsage, readOpenCodeGo = readOpenCodeGoUsage, readCopilot = readCopilotUsage, platform = process.platform, readElevenLabs = liveElevenLabsUsage) {
|
|
38861
38862
|
this.readCodex = readCodex;
|
|
@@ -38883,6 +38884,8 @@ var init_usage = __esm({
|
|
|
38883
38884
|
claudePending = /* @__PURE__ */ new Map();
|
|
38884
38885
|
spendingCached = /* @__PURE__ */ new Map();
|
|
38885
38886
|
spendingPending = /* @__PURE__ */ new Map();
|
|
38887
|
+
openCodeCached;
|
|
38888
|
+
openCodePending;
|
|
38886
38889
|
/** `allAccounts`: one Claude row per home. Otherwise only the default home's, as
|
|
38887
38890
|
* before accounts existed, since older phones refuse two rows of one source. */
|
|
38888
38891
|
async read(sources, allAccounts = false) {
|
|
@@ -38920,7 +38923,7 @@ var init_usage = __esm({
|
|
|
38920
38923
|
const at = this.now();
|
|
38921
38924
|
if (!this.spendingPending.has(key4)) {
|
|
38922
38925
|
const pending = Promise.all([
|
|
38923
|
-
this.
|
|
38926
|
+
this.openCode(at),
|
|
38924
38927
|
this.readOpenCodeGo(new Date(at)),
|
|
38925
38928
|
this.readOpenRouter(new Date(at)),
|
|
38926
38929
|
includeCopilot ? this.readCopilot(new Date(at)) : Promise.resolve(void 0),
|
|
@@ -38936,6 +38939,17 @@ var init_usage = __esm({
|
|
|
38936
38939
|
}
|
|
38937
38940
|
return this.spendingPending.get(key4) ?? cached3.value;
|
|
38938
38941
|
}
|
|
38942
|
+
/** One `opencode stats` run serves every spending key for `OPENCODE_STATS_REUSE_MS`. */
|
|
38943
|
+
openCode(at) {
|
|
38944
|
+
if (this.openCodeCached && at - this.openCodeCached.at < OPENCODE_STATS_REUSE_MS) return Promise.resolve(this.openCodeCached.value);
|
|
38945
|
+
this.openCodePending ??= this.readOpenCode(new Date(at)).then((value2) => {
|
|
38946
|
+
this.openCodeCached = { at, value: value2 };
|
|
38947
|
+
return value2;
|
|
38948
|
+
}).finally(() => {
|
|
38949
|
+
this.openCodePending = void 0;
|
|
38950
|
+
});
|
|
38951
|
+
return this.openCodePending;
|
|
38952
|
+
}
|
|
38939
38953
|
/** Live first, so the phone's minute-by-minute poll keeps Claude current
|
|
38940
38954
|
* even when Claude Code is not running; the local snapshot is the backup.
|
|
38941
38955
|
* Off macOS a non-default home reads its own credentials file; on macOS it
|
|
@@ -40504,9 +40518,23 @@ function localNames() {
|
|
|
40504
40518
|
names.push(execFileSync3("scutil", ["--get", "LocalHostName"], { encoding: "utf8", timeout: 1e3 }).trim());
|
|
40505
40519
|
} catch {
|
|
40506
40520
|
}
|
|
40521
|
+
try {
|
|
40522
|
+
names.push(execFileSync3("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1e3 }).trim());
|
|
40523
|
+
} catch {
|
|
40524
|
+
}
|
|
40507
40525
|
}
|
|
40508
40526
|
return [...new Set(names.filter(Boolean))];
|
|
40509
40527
|
}
|
|
40528
|
+
function stableComputerName() {
|
|
40529
|
+
if (process.platform === "darwin") {
|
|
40530
|
+
try {
|
|
40531
|
+
const name = execFileSync3("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1e3 }).trim();
|
|
40532
|
+
if (name) return name;
|
|
40533
|
+
} catch {
|
|
40534
|
+
}
|
|
40535
|
+
}
|
|
40536
|
+
return hostname5();
|
|
40537
|
+
}
|
|
40510
40538
|
var init_computer_names = __esm({
|
|
40511
40539
|
"src/bridge/computer-names.ts"() {
|
|
40512
40540
|
"use strict";
|
|
@@ -41966,8 +41994,13 @@ function canonicalComputer(value2) {
|
|
|
41966
41994
|
const normalized = value2.trim().toLowerCase();
|
|
41967
41995
|
return normalized.endsWith(".local") ? normalized.slice(0, -".local".length) : normalized;
|
|
41968
41996
|
}
|
|
41997
|
+
function foldedComputer(value2) {
|
|
41998
|
+
return canonicalComputer(value2).replace(/[^\p{L}\p{N}]/gu, "");
|
|
41999
|
+
}
|
|
41969
42000
|
function computerMatches(wanted, current2) {
|
|
41970
|
-
|
|
42001
|
+
if (canonicalComputer(wanted) === canonicalComputer(current2)) return true;
|
|
42002
|
+
const folded = foldedComputer(wanted);
|
|
42003
|
+
return folded !== "" && folded === foldedComputer(current2);
|
|
41971
42004
|
}
|
|
41972
42005
|
function scheduleNotifications(schedule) {
|
|
41973
42006
|
return new Set(schedule.notify ?? ["finish", "failure"]);
|
|
@@ -42654,12 +42687,12 @@ var init_schedule_launch = __esm({
|
|
|
42654
42687
|
// src/bridge/schedules.ts
|
|
42655
42688
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
42656
42689
|
import { stat as stat16 } from "node:fs/promises";
|
|
42657
|
-
import { hostname as hostname6 } from "node:os";
|
|
42658
42690
|
import path59 from "node:path";
|
|
42659
42691
|
var Scheduler;
|
|
42660
42692
|
var init_schedules = __esm({
|
|
42661
42693
|
"src/bridge/schedules.ts"() {
|
|
42662
42694
|
"use strict";
|
|
42695
|
+
init_computer_names();
|
|
42663
42696
|
init_protocol();
|
|
42664
42697
|
init_project_config();
|
|
42665
42698
|
init_shared();
|
|
@@ -42673,6 +42706,8 @@ var init_schedules = __esm({
|
|
|
42673
42706
|
launch;
|
|
42674
42707
|
runsFile;
|
|
42675
42708
|
computer;
|
|
42709
|
+
/** Every name this computer answers to; a schedule names one of them. */
|
|
42710
|
+
names;
|
|
42676
42711
|
locateProject;
|
|
42677
42712
|
push;
|
|
42678
42713
|
log;
|
|
@@ -42692,8 +42727,10 @@ var init_schedules = __esm({
|
|
|
42692
42727
|
if (typeof options.computer === "function") this.computer = options.computer;
|
|
42693
42728
|
else {
|
|
42694
42729
|
const computer = options.computer;
|
|
42695
|
-
this.computer = () => computer ??
|
|
42730
|
+
this.computer = () => computer ?? stableComputerName();
|
|
42696
42731
|
}
|
|
42732
|
+
const aliases = options.aliases ?? [];
|
|
42733
|
+
this.names = options.computer === void 0 ? () => [...localNames(), ...aliases] : () => [this.computer(), ...aliases];
|
|
42697
42734
|
this.locateProject = options.locateProject ?? (async () => void 0);
|
|
42698
42735
|
this.push = options.push;
|
|
42699
42736
|
this.log = options.log ?? ((message) => console.error(message));
|
|
@@ -42719,8 +42756,11 @@ var init_schedules = __esm({
|
|
|
42719
42756
|
release();
|
|
42720
42757
|
}
|
|
42721
42758
|
}
|
|
42759
|
+
owns(schedule, names = this.names()) {
|
|
42760
|
+
return names.some((name) => computerMatches(schedule.computer, name));
|
|
42761
|
+
}
|
|
42722
42762
|
async statuses() {
|
|
42723
|
-
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer();
|
|
42763
|
+
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer(), names = this.names();
|
|
42724
42764
|
for (const directory of this.projectDirectories()) {
|
|
42725
42765
|
let schedules;
|
|
42726
42766
|
try {
|
|
@@ -42733,11 +42773,13 @@ var init_schedules = __esm({
|
|
|
42733
42773
|
const matching = runs.filter((run2) => (run2.scheduleProject ?? run2.project) === project && run2.scheduleId === schedule.id);
|
|
42734
42774
|
const { lastRun: last, lastRuns } = latestScheduleBatch(matching);
|
|
42735
42775
|
const running2 = matching.some((run2) => runningStatuses.has(run2.status));
|
|
42736
|
-
const due =
|
|
42776
|
+
const due = this.owns(schedule, names) ? nextRun(schedule, last) : null;
|
|
42777
|
+
const owned = this.owns(schedule, names);
|
|
42737
42778
|
result.push({
|
|
42738
42779
|
...schedule,
|
|
42739
42780
|
project,
|
|
42740
42781
|
lastRuns,
|
|
42782
|
+
owned,
|
|
42741
42783
|
nextRun: due?.toISOString() ?? null,
|
|
42742
42784
|
lastRun: last ? {
|
|
42743
42785
|
startedAt: last.startedAt,
|
|
@@ -42777,7 +42819,7 @@ var init_schedules = __esm({
|
|
|
42777
42819
|
if (expectedUpdatedAt !== void 0 && Date.parse(expectedUpdatedAt) !== Date.parse(schedule.updatedAt)) {
|
|
42778
42820
|
throw new BridgeError(409, "This computer has a different schedule revision. Wait for store sync to finish, refresh the schedule, and try Run now again.");
|
|
42779
42821
|
}
|
|
42780
|
-
if (!
|
|
42822
|
+
if (!this.owns(schedule)) throw new BridgeError(409, `${schedule.computer} owns this schedule; run it from that computer.`);
|
|
42781
42823
|
const runs = await readScheduleRuns(this.runsFile);
|
|
42782
42824
|
const matching = runs.filter((run2) => (run2.scheduleProject ?? run2.project) === project && run2.scheduleId === id2);
|
|
42783
42825
|
if (matching.some((run2) => runningStatuses.has(run2.status))) {
|
|
@@ -42968,7 +43010,7 @@ var init_schedules = __esm({
|
|
|
42968
43010
|
// src/bridge/health.ts
|
|
42969
43011
|
import { execFile as execFile11, spawn as spawn8 } from "node:child_process";
|
|
42970
43012
|
import { lstat as lstat16, readFile as readFile30 } from "node:fs/promises";
|
|
42971
|
-
import { homedir as homedir14, hostname as
|
|
43013
|
+
import { homedir as homedir14, hostname as hostname6 } from "node:os";
|
|
42972
43014
|
import path60 from "node:path";
|
|
42973
43015
|
import { promisify as promisify10 } from "node:util";
|
|
42974
43016
|
async function terminalHealth() {
|
|
@@ -43150,7 +43192,7 @@ async function pushConfigured() {
|
|
|
43150
43192
|
return { configured: !!info?.isFile() };
|
|
43151
43193
|
}
|
|
43152
43194
|
async function healthDetails(options) {
|
|
43153
|
-
const name =
|
|
43195
|
+
const name = hostname6();
|
|
43154
43196
|
const hostKey = await ownHostKey();
|
|
43155
43197
|
const peersPromise = (async () => {
|
|
43156
43198
|
let peers2;
|
|
@@ -43213,10 +43255,10 @@ var init_health = __esm({
|
|
|
43213
43255
|
});
|
|
43214
43256
|
|
|
43215
43257
|
// src/bridge/conductor-group.ts
|
|
43216
|
-
import { hostname as
|
|
43258
|
+
import { hostname as hostname7 } from "node:os";
|
|
43217
43259
|
async function localCaller() {
|
|
43218
43260
|
const hostKey = await ownHostKey();
|
|
43219
|
-
return { name:
|
|
43261
|
+
return { name: hostname7(), ...hostKey ? { hostKey } : {} };
|
|
43220
43262
|
}
|
|
43221
43263
|
function callerQuery(caller) {
|
|
43222
43264
|
return new URLSearchParams({ name: caller.name, ...caller.hostKey ? { hostKey: caller.hostKey } : {} }).toString();
|
|
@@ -46789,7 +46831,7 @@ import { execFile as execFile14 } from "node:child_process";
|
|
|
46789
46831
|
import { promisify as promisify13 } from "node:util";
|
|
46790
46832
|
import { createHash as createHash23, createPublicKey, verify } from "node:crypto";
|
|
46791
46833
|
import { lstat as lstat24, mkdir as mkdir19, readFile as readFile36, realpath as realpath13 } from "node:fs/promises";
|
|
46792
|
-
import { hostname as
|
|
46834
|
+
import { hostname as hostname8 } from "node:os";
|
|
46793
46835
|
import path72 from "node:path";
|
|
46794
46836
|
async function git4(cwd, ...args) {
|
|
46795
46837
|
return (await exec13("git", ["-C", cwd, "--no-pager", ...args], {
|
|
@@ -46903,7 +46945,7 @@ async function approvalRuleContext(cwd, harness, session) {
|
|
|
46903
46945
|
const listed2 = (await git4(common, "worktree", "list", "--porcelain", "-z")).split("\0").filter((field) => field.startsWith("worktree ")).map((field) => field.slice("worktree ".length));
|
|
46904
46946
|
const registered = await Promise.all(listed2.map((directory2) => realpath13(directory2).catch(() => void 0)));
|
|
46905
46947
|
if (!registered.includes(checkout)) return void 0;
|
|
46906
|
-
return { project: path72.dirname(common), harness: scopeSchema.shape.harness.unwrap().parse(harness), session, computer:
|
|
46948
|
+
return { project: path72.dirname(common), harness: scopeSchema.shape.harness.unwrap().parse(harness), session, computer: hostname8() };
|
|
46907
46949
|
} catch {
|
|
46908
46950
|
return void 0;
|
|
46909
46951
|
}
|
|
@@ -47441,14 +47483,14 @@ var init_push = __esm({
|
|
|
47441
47483
|
|
|
47442
47484
|
// src/bridge/pair.ts
|
|
47443
47485
|
import { execFile as execFile15 } from "node:child_process";
|
|
47444
|
-
import { homedir as homedir16, hostname as
|
|
47486
|
+
import { homedir as homedir16, hostname as hostname9, networkInterfaces, userInfo as userInfo4 } from "node:os";
|
|
47445
47487
|
import { promisify as promisify14 } from "node:util";
|
|
47446
47488
|
async function computerDisplayName() {
|
|
47447
47489
|
if (process.platform === "darwin") {
|
|
47448
47490
|
const name = await exec14("scutil", ["--get", "ComputerName"], { timeout: 2e3 }).then(({ stdout }) => stdout.trim()).catch(() => "");
|
|
47449
47491
|
if (name) return name.slice(0, 64);
|
|
47450
47492
|
}
|
|
47451
|
-
return
|
|
47493
|
+
return hostname9().replace(/\.local$/i, "").split(".")[0] || "Computer";
|
|
47452
47494
|
}
|
|
47453
47495
|
var exec14, request5;
|
|
47454
47496
|
var init_pair = __esm({
|
|
@@ -48378,7 +48420,7 @@ import { mkdir as mkdir21, readFile as readFile40, chmod as chmod4, unlink as un
|
|
|
48378
48420
|
import { watch } from "node:fs";
|
|
48379
48421
|
import path80 from "node:path";
|
|
48380
48422
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
48381
|
-
import { hostname as
|
|
48423
|
+
import { hostname as hostname10 } from "node:os";
|
|
48382
48424
|
function watchHangUp(res) {
|
|
48383
48425
|
let closed = res.destroyed || res.socket?.destroyed === true;
|
|
48384
48426
|
const onClose = () => {
|
|
@@ -48679,7 +48721,7 @@ var init_agent_hooks = __esm({
|
|
|
48679
48721
|
fanoutArchiveTimer;
|
|
48680
48722
|
/** The name the phone paired with (macOS Computer Name), for approval alerts;
|
|
48681
48723
|
* the short host name until that lookup answers. */
|
|
48682
|
-
computerName =
|
|
48724
|
+
computerName = hostname10().replace(/\.local$/i, "").split(".")[0] || "Computer";
|
|
48683
48725
|
/** sudo -A requests from askpass, answered from the phone (sudo.ts). */
|
|
48684
48726
|
sudo;
|
|
48685
48727
|
approvalsDirectory() {
|
|
@@ -50026,7 +50068,7 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50026
50068
|
approvalRuleContext(body2.cwd, target.source, target.session)
|
|
50027
50069
|
]);
|
|
50028
50070
|
return paneContext && requestContext?.project === paneContext.project ? requestContext : void 0;
|
|
50029
|
-
}, void 0, { harness: target.source, session: target.session, computer:
|
|
50071
|
+
}, void 0, { harness: target.source, session: target.session, computer: hostname10() }) : void 0;
|
|
50030
50072
|
if (ruleEffect === "deny") {
|
|
50031
50073
|
res.end(JSON.stringify({ hookSpecificOutput: { hookEventName: "PermissionRequest", decision: { behavior: "deny", message: "Denied by an owner approval rule." } } }));
|
|
50032
50074
|
return;
|
|
@@ -50761,6 +50803,18 @@ function emptyComposer(line) {
|
|
|
50761
50803
|
}
|
|
50762
50804
|
return prompt;
|
|
50763
50805
|
}
|
|
50806
|
+
function assertComposerReady(before, action) {
|
|
50807
|
+
const composer = before.split(/\r?\n/).reverse().find((line) => /^\s*[›❯>]/.test(stripTerminal(line)));
|
|
50808
|
+
if (visibleTerminalChoice(stripTerminal(before))) {
|
|
50809
|
+
throw new BridgeError(409, `A menu is open in the terminal. Open terminal to finish it, then ${action}.`, { code: "terminal-menu" });
|
|
50810
|
+
}
|
|
50811
|
+
if (!composer) {
|
|
50812
|
+
throw new BridgeError(409, `Phren couldn't find the terminal's input line. Open terminal to ${action}.`, { code: "terminal-unreadable" });
|
|
50813
|
+
}
|
|
50814
|
+
if (!emptyComposer(composer)) {
|
|
50815
|
+
throw new BridgeError(409, `There's unsent text in the terminal. Send or clear it, then ${action}.`, { code: "terminal-draft" });
|
|
50816
|
+
}
|
|
50817
|
+
}
|
|
50764
50818
|
function codexModelStatus(text5, model) {
|
|
50765
50819
|
const lines = text5.split(/\r?\n/).reverse();
|
|
50766
50820
|
const composer = lines.findIndex((line) => /^\s*[›❯>]/.test(stripTerminal(line)));
|
|
@@ -50866,10 +50920,7 @@ var init_model_switch = __esm({
|
|
|
50866
50920
|
}
|
|
50867
50921
|
let claudeEffort;
|
|
50868
50922
|
const before = await this.hooks.paneLines(target, false);
|
|
50869
|
-
|
|
50870
|
-
if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before))) {
|
|
50871
|
-
throw new BridgeError(409, "The terminal has a draft or an unreadable prompt. Open terminal before switching models.");
|
|
50872
|
-
}
|
|
50923
|
+
assertComposerReady(before, "switch models");
|
|
50873
50924
|
await validate2(true);
|
|
50874
50925
|
opened2 = true;
|
|
50875
50926
|
this.hooks.menuOpened(target, "/model");
|
|
@@ -54437,7 +54488,6 @@ var init_settings_switch = __esm({
|
|
|
54437
54488
|
"use strict";
|
|
54438
54489
|
init_zod();
|
|
54439
54490
|
init_terminal_text();
|
|
54440
|
-
init_agent_hooks();
|
|
54441
54491
|
init_claude_suggestion();
|
|
54442
54492
|
init_codex_servers();
|
|
54443
54493
|
init_herdr();
|
|
@@ -54577,10 +54627,7 @@ var init_settings_switch = __esm({
|
|
|
54577
54627
|
};
|
|
54578
54628
|
const slash = async (command) => {
|
|
54579
54629
|
const before = await this.hooks.paneLines(target, false);
|
|
54580
|
-
|
|
54581
|
-
if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before))) {
|
|
54582
|
-
throw new BridgeError(409, "The terminal has a draft or an unreadable prompt. Open terminal before changing settings.");
|
|
54583
|
-
}
|
|
54630
|
+
assertComposerReady(before, "change settings");
|
|
54584
54631
|
await validate2();
|
|
54585
54632
|
await terminalProvider().prompt(target.server, target.pane, command);
|
|
54586
54633
|
};
|
|
@@ -55257,7 +55304,7 @@ var init_resources = __esm({
|
|
|
55257
55304
|
|
|
55258
55305
|
// src/bridge/canary.ts
|
|
55259
55306
|
import { lstat as lstat29, mkdtemp as mkdtemp5, realpath as realpath16, rm as rm12 } from "node:fs/promises";
|
|
55260
|
-
import { hostname as
|
|
55307
|
+
import { hostname as hostname11, tmpdir as tmpdir3 } from "node:os";
|
|
55261
55308
|
import path94 from "node:path";
|
|
55262
55309
|
function reason(error62) {
|
|
55263
55310
|
const text5 = error62 instanceof Error ? error62.message : "Unknown failure.";
|
|
@@ -55372,7 +55419,7 @@ function runCanary(options) {
|
|
|
55372
55419
|
const result = {
|
|
55373
55420
|
version: 1,
|
|
55374
55421
|
trigger: options.trigger,
|
|
55375
|
-
computer:
|
|
55422
|
+
computer: hostname11(),
|
|
55376
55423
|
startedAt: started.toISOString(),
|
|
55377
55424
|
finishedAt: finished2.toISOString(),
|
|
55378
55425
|
durationMs: finished2.getTime() - started.getTime(),
|
|
@@ -63497,7 +63544,7 @@ import { randomUUID as randomUUID27 } from "node:crypto";
|
|
|
63497
63544
|
import { chmod as chmod6, lstat as lstat34, mkdir as mkdir31, readFile as readFile52, rm as rm15, unlink as unlink10, writeFile as writeFile12 } from "node:fs/promises";
|
|
63498
63545
|
import { readFileSync as readFileSync42 } from "node:fs";
|
|
63499
63546
|
import { createServer as createServer3 } from "node:http";
|
|
63500
|
-
import { cpus as cpus2, hostname as
|
|
63547
|
+
import { cpus as cpus2, hostname as hostname12, loadavg as loadavg2 } from "node:os";
|
|
63501
63548
|
import path124 from "node:path";
|
|
63502
63549
|
async function serve(version3, options = {}) {
|
|
63503
63550
|
process.umask(63);
|
|
@@ -63618,6 +63665,7 @@ async function serve(version3, options = {}) {
|
|
|
63618
63665
|
now: () => /* @__PURE__ */ new Date(),
|
|
63619
63666
|
store: scheduleStore,
|
|
63620
63667
|
runsFile: scheduleRunsFile(),
|
|
63668
|
+
aliases: [computerID2],
|
|
63621
63669
|
// A schedule starts in its project's folder, which the Hook resolved itself.
|
|
63622
63670
|
launch: createScheduleLauncher((server, data) => launchSession(server, data, { trustFolder: true }), scheduleStore),
|
|
63623
63671
|
push: { notify: (value2) => agentHooks.push.notifySchedule(value2) },
|
|
@@ -63643,7 +63691,7 @@ async function serve(version3, options = {}) {
|
|
|
63643
63691
|
product: "phren-hook",
|
|
63644
63692
|
protocol: PROTOCOL,
|
|
63645
63693
|
version: version3,
|
|
63646
|
-
computer: { id: computerID2, name:
|
|
63694
|
+
computer: { id: computerID2, name: hostname12(), aliases: localNames() },
|
|
63647
63695
|
capabilities: activeCapabilities,
|
|
63648
63696
|
modules: Object.fromEntries(modules.modules.map((module) => [module.name, module.version])),
|
|
63649
63697
|
store: modules.store,
|
|
@@ -63919,7 +63967,7 @@ var init_server = __esm({
|
|
|
63919
63967
|
// src/bridge/link.ts
|
|
63920
63968
|
import { execFile as execFile25 } from "node:child_process";
|
|
63921
63969
|
import { readFile as readFile53 } from "node:fs/promises";
|
|
63922
|
-
import { homedir as homedir21, hostname as
|
|
63970
|
+
import { homedir as homedir21, hostname as hostname13, userInfo as userInfo5 } from "node:os";
|
|
63923
63971
|
import path125 from "node:path";
|
|
63924
63972
|
import { promisify as promisify24 } from "node:util";
|
|
63925
63973
|
function sshConfigHosts(text5) {
|
|
@@ -63992,7 +64040,7 @@ async function linkComputer(host, options = {}) {
|
|
|
63992
64040
|
const own2 = (await readFile53(path125.join(bridgeRoot(), "computer-id"), "utf8").catch(() => "")).trim();
|
|
63993
64041
|
if (remote.computerId === own2) throw new BridgeError(409, `${host} is this computer.`);
|
|
63994
64042
|
const name = computerName.parse(options.name ?? slugName(host));
|
|
63995
|
-
const as = computerName.parse(options.as ?? slugName(
|
|
64043
|
+
const as = computerName.parse(options.as ?? slugName(hostname13()));
|
|
63996
64044
|
const backAddress = options.backAddress ?? remote.client;
|
|
63997
64045
|
if (!backAddress) throw new BridgeError(409, `${host} did not report this computer's address; pass --back-address.`);
|
|
63998
64046
|
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(" ")]));
|
|
@@ -64334,7 +64382,7 @@ async function main() {
|
|
|
64334
64382
|
return askpass2(args[1]);
|
|
64335
64383
|
}
|
|
64336
64384
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
64337
|
-
return runBridge2(args, "0.3.
|
|
64385
|
+
return runBridge2(args, "0.3.34");
|
|
64338
64386
|
}
|
|
64339
64387
|
main().then((code) => {
|
|
64340
64388
|
process.exitCode = code;
|
package/dist/cli/search.js
CHANGED
|
@@ -7,6 +7,7 @@ import { logger } from "../logger.js";
|
|
|
7
7
|
import { keywordFallbackSearch } from "../core/search.js";
|
|
8
8
|
import { recordLookupEvents } from "../shared/governance.js";
|
|
9
9
|
import { bestFindingNodeId } from "../finding-graph-id.js";
|
|
10
|
+
import { snippetBudget } from "../response-budget.js";
|
|
10
11
|
const MAX_HISTORY = 20;
|
|
11
12
|
const SEARCH_TYPE_ALIASES = {
|
|
12
13
|
skills: "skill",
|
|
@@ -270,10 +271,14 @@ export async function runSearch(opts, phrenPath, profile) {
|
|
|
270
271
|
lines.push("");
|
|
271
272
|
}
|
|
272
273
|
const hits = [];
|
|
274
|
+
// Same per-result budget as search_knowledge: store lines can run to many KB.
|
|
275
|
+
const perResultChars = snippetBudget(rows.length);
|
|
273
276
|
for (const row of rows) {
|
|
274
|
-
const snippet = extractSnippet(row.content, opts.query, 7);
|
|
277
|
+
const snippet = extractSnippet(row.content, opts.query, 7, perResultChars);
|
|
275
278
|
lines.push(`[${row.project}/${row.filename}] (${row.type})`);
|
|
276
279
|
lines.push(snippet);
|
|
280
|
+
if (row.path && snippet !== extractSnippet(row.content, opts.query, 7))
|
|
281
|
+
lines.push(` (shortened; full text: ${row.path})`);
|
|
277
282
|
lines.push("");
|
|
278
283
|
hits.push({ project: row.project, filename: row.filename, type: row.type, snippet, path: row.path, content: row.content });
|
|
279
284
|
}
|
package/dist/index-query.d.ts
CHANGED
|
@@ -30,4 +30,9 @@ export declare function rowToDocWithRowid(row: DbRow): {
|
|
|
30
30
|
export declare function queryRows(db: SqlJsDatabase, sql: string, params: (string | number)[]): DbRow[] | null;
|
|
31
31
|
export declare function queryDocRows(db: SqlJsDatabase, sql: string, params: (string | number)[]): DocRow[] | null;
|
|
32
32
|
export declare function queryDocBySourceKey(db: SqlJsDatabase, phrenPath: string, sourceKey: string): DocRow | null;
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Pick the lines of `content` that best match `query`. With `maxChars`, the
|
|
35
|
+
* result is also held to that many characters: store lines can run to several
|
|
36
|
+
* KB, so a few lines alone do not bound a snippet.
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractSnippet(content: string, query: string, lines?: number, maxChars?: number): string;
|
package/dist/index-query.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { debugLog } from "./shared.js";
|
|
3
3
|
import { logger } from "./logger.js";
|
|
4
|
+
import { clipText, focusText } from "./response-budget.js";
|
|
4
5
|
function describeSqlValue(value) {
|
|
5
6
|
if (value === null)
|
|
6
7
|
return "null";
|
|
@@ -102,14 +103,20 @@ export function queryDocBySourceKey(db, phrenPath, sourceKey) {
|
|
|
102
103
|
return null;
|
|
103
104
|
return rows.find((row) => getDocSourceKey(row, phrenPath) === sourceKey) ?? null;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Pick the lines of `content` that best match `query`. With `maxChars`, the
|
|
108
|
+
* result is also held to that many characters: store lines can run to several
|
|
109
|
+
* KB, so a few lines alone do not bound a snippet.
|
|
110
|
+
*/
|
|
111
|
+
export function extractSnippet(content, query, lines = 5, maxChars) {
|
|
106
112
|
const terms = query.replace(/\b(AND|OR|NOT|NEAR)\b/gi, "")
|
|
107
113
|
.replace(/['"]/g, "")
|
|
108
114
|
.split(/\s+/)
|
|
109
115
|
.filter((term) => term.length > 1)
|
|
110
116
|
.map((term) => term.toLowerCase());
|
|
111
117
|
if (terms.length === 0) {
|
|
112
|
-
|
|
118
|
+
const head = content.split("\n").slice(0, lines);
|
|
119
|
+
return maxChars === undefined ? head.join("\n") : fitSnippetLines(head, -1, terms, maxChars);
|
|
113
120
|
}
|
|
114
121
|
const contentLines = content.split("\n");
|
|
115
122
|
const headingIndices = [];
|
|
@@ -167,5 +174,17 @@ export function extractSnippet(content, query, lines = 5) {
|
|
|
167
174
|
}
|
|
168
175
|
const start = Math.max(0, bestIdx - 1);
|
|
169
176
|
const end = Math.min(contentLines.length, bestIdx + lines - 1);
|
|
170
|
-
|
|
177
|
+
const picked = contentLines.slice(start, end);
|
|
178
|
+
return maxChars === undefined ? picked.join("\n") : fitSnippetLines(picked, bestIdx - start, terms, maxChars);
|
|
179
|
+
}
|
|
180
|
+
/** Give the matched line most of the budget, centred on the match; clip the context lines. */
|
|
181
|
+
function fitSnippetLines(picked, bestIdx, terms, maxChars) {
|
|
182
|
+
const joined = picked.join("\n");
|
|
183
|
+
if (joined.length <= maxChars)
|
|
184
|
+
return joined;
|
|
185
|
+
const others = picked.length - (bestIdx >= 0 ? 1 : 0);
|
|
186
|
+
const bestBudget = bestIdx >= 0 ? (others > 0 ? Math.ceil(maxChars * 0.6) : maxChars) : 0;
|
|
187
|
+
const otherBudget = others > 0 ? Math.max(40, Math.floor((maxChars - bestBudget - picked.length) / others)) : 0;
|
|
188
|
+
const fitted = picked.map((line, i) => i === bestIdx ? focusText(line, terms, bestBudget) : clipText(line, otherBudget));
|
|
189
|
+
return clipText(fitted.join("\n"), maxChars);
|
|
171
190
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size budgets for tool output.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code rejects an MCP tool result over about 25k tokens, and the call
|
|
5
|
+
* then fails outright. Store text is long-lined (task Context fields and
|
|
6
|
+
* consolidated reference lines run to several KB), so line-based snippets and
|
|
7
|
+
* per-item limits alone do not bound a response. These budgets are in
|
|
8
|
+
* characters of the serialized result; JSON-escaped markdown is roughly 3–4
|
|
9
|
+
* characters per token.
|
|
10
|
+
*/
|
|
11
|
+
/** Most characters one search result's snippet may use. */
|
|
12
|
+
export declare const SNIPPET_MAX_CHARS = 1200;
|
|
13
|
+
/** Characters shared by all snippets in one search response (each also appears in `data`). */
|
|
14
|
+
export declare const SNIPPETS_TOTAL_CHARS = 6000;
|
|
15
|
+
/** Floor for a snippet when many results split the total. */
|
|
16
|
+
export declare const SNIPPET_MIN_CHARS = 240;
|
|
17
|
+
/** Per-field cap for text shown in list views (task context, truths). */
|
|
18
|
+
export declare const LIST_TEXT_MAX_CHARS = 300;
|
|
19
|
+
/** Most characters of a project's summary.md shown by get_project_summary. */
|
|
20
|
+
export declare const SUMMARY_MAX_CHARS = 6000;
|
|
21
|
+
/** Most truths listed by get_project_summary. */
|
|
22
|
+
export declare const SUMMARY_MAX_TRUTHS = 20;
|
|
23
|
+
/** Target ceiling for a list response before it shrinks its page size. */
|
|
24
|
+
export declare const LIST_RESPONSE_MAX_CHARS = 40000;
|
|
25
|
+
/** Page size for full-document reads (get_memory_detail). */
|
|
26
|
+
export declare const DETAIL_PAGE_CHARS = 16000;
|
|
27
|
+
/** Hard ceiling for any MCP response; past this the payload is replaced, not sent. */
|
|
28
|
+
export declare const MCP_RESPONSE_MAX_CHARS = 60000;
|
|
29
|
+
/** Per-result snippet budget when `count` results share one response. */
|
|
30
|
+
export declare function snippetBudget(count: number): number;
|
|
31
|
+
/** Cut `text` to at most `max` characters, ending with an ellipsis when cut. */
|
|
32
|
+
export declare function clipText(text: string, max: number): string;
|
|
33
|
+
/** Cut `text` to at most `max` characters, keeping the end (for append-only notes). */
|
|
34
|
+
export declare function clipTail(text: string, max: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Cut `text` to at most `max` characters, keeping a window around the first
|
|
37
|
+
* occurrence of any term (lowercase). Falls back to the start when no term hits.
|
|
38
|
+
*/
|
|
39
|
+
export declare function focusText(text: string, terms: string[], max: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Build a list payload, halving its page size until the serialized result fits
|
|
42
|
+
* `maxChars` (or the size reaches 1). `build` receives the size to use.
|
|
43
|
+
*/
|
|
44
|
+
export declare function shrinkToBudget<T>(initialSize: number, build: (size: number) => T, maxChars?: number): {
|
|
45
|
+
payload: T;
|
|
46
|
+
size: number;
|
|
47
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size budgets for tool output.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code rejects an MCP tool result over about 25k tokens, and the call
|
|
5
|
+
* then fails outright. Store text is long-lined (task Context fields and
|
|
6
|
+
* consolidated reference lines run to several KB), so line-based snippets and
|
|
7
|
+
* per-item limits alone do not bound a response. These budgets are in
|
|
8
|
+
* characters of the serialized result; JSON-escaped markdown is roughly 3–4
|
|
9
|
+
* characters per token.
|
|
10
|
+
*/
|
|
11
|
+
/** Most characters one search result's snippet may use. */
|
|
12
|
+
export const SNIPPET_MAX_CHARS = 1200;
|
|
13
|
+
/** Characters shared by all snippets in one search response (each also appears in `data`). */
|
|
14
|
+
export const SNIPPETS_TOTAL_CHARS = 6000;
|
|
15
|
+
/** Floor for a snippet when many results split the total. */
|
|
16
|
+
export const SNIPPET_MIN_CHARS = 240;
|
|
17
|
+
/** Per-field cap for text shown in list views (task context, truths). */
|
|
18
|
+
export const LIST_TEXT_MAX_CHARS = 300;
|
|
19
|
+
/** Most characters of a project's summary.md shown by get_project_summary. */
|
|
20
|
+
export const SUMMARY_MAX_CHARS = 6000;
|
|
21
|
+
/** Most truths listed by get_project_summary. */
|
|
22
|
+
export const SUMMARY_MAX_TRUTHS = 20;
|
|
23
|
+
/** Target ceiling for a list response before it shrinks its page size. */
|
|
24
|
+
export const LIST_RESPONSE_MAX_CHARS = 40_000;
|
|
25
|
+
/** Page size for full-document reads (get_memory_detail). */
|
|
26
|
+
export const DETAIL_PAGE_CHARS = 16_000;
|
|
27
|
+
/** Hard ceiling for any MCP response; past this the payload is replaced, not sent. */
|
|
28
|
+
export const MCP_RESPONSE_MAX_CHARS = 60_000;
|
|
29
|
+
/** Per-result snippet budget when `count` results share one response. */
|
|
30
|
+
export function snippetBudget(count) {
|
|
31
|
+
if (count <= 0)
|
|
32
|
+
return SNIPPET_MAX_CHARS;
|
|
33
|
+
return Math.max(SNIPPET_MIN_CHARS, Math.min(SNIPPET_MAX_CHARS, Math.floor(SNIPPETS_TOTAL_CHARS / count)));
|
|
34
|
+
}
|
|
35
|
+
/** Cut `text` to at most `max` characters, ending with an ellipsis when cut. */
|
|
36
|
+
export function clipText(text, max) {
|
|
37
|
+
if (text.length <= max)
|
|
38
|
+
return text;
|
|
39
|
+
if (max <= 1)
|
|
40
|
+
return "…".slice(0, max);
|
|
41
|
+
return `${text.slice(0, max - 1).trimEnd()}…`;
|
|
42
|
+
}
|
|
43
|
+
/** Cut `text` to at most `max` characters, keeping the end (for append-only notes). */
|
|
44
|
+
export function clipTail(text, max) {
|
|
45
|
+
if (text.length <= max)
|
|
46
|
+
return text;
|
|
47
|
+
if (max <= 1)
|
|
48
|
+
return "…".slice(0, max);
|
|
49
|
+
return `…${text.slice(text.length - (max - 1)).trimStart()}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Cut `text` to at most `max` characters, keeping a window around the first
|
|
53
|
+
* occurrence of any term (lowercase). Falls back to the start when no term hits.
|
|
54
|
+
*/
|
|
55
|
+
export function focusText(text, terms, max) {
|
|
56
|
+
if (text.length <= max)
|
|
57
|
+
return text;
|
|
58
|
+
const lower = text.toLowerCase();
|
|
59
|
+
let hit = -1;
|
|
60
|
+
for (const term of terms) {
|
|
61
|
+
const idx = lower.indexOf(term);
|
|
62
|
+
if (idx !== -1 && (hit === -1 || idx < hit))
|
|
63
|
+
hit = idx;
|
|
64
|
+
}
|
|
65
|
+
if (hit <= 0)
|
|
66
|
+
return clipText(text, max);
|
|
67
|
+
// Leave a third of the window as lead-in before the match.
|
|
68
|
+
const room = max - 2;
|
|
69
|
+
let start = Math.max(0, hit - Math.floor(room / 3));
|
|
70
|
+
const end = Math.min(text.length, start + room);
|
|
71
|
+
start = Math.max(0, end - room);
|
|
72
|
+
return `${start > 0 ? "…" : ""}${text.slice(start, end)}${end < text.length ? "…" : ""}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a list payload, halving its page size until the serialized result fits
|
|
76
|
+
* `maxChars` (or the size reaches 1). `build` receives the size to use.
|
|
77
|
+
*/
|
|
78
|
+
export function shrinkToBudget(initialSize, build, maxChars = LIST_RESPONSE_MAX_CHARS) {
|
|
79
|
+
let size = initialSize;
|
|
80
|
+
let payload = build(size);
|
|
81
|
+
while (size > 1 && JSON.stringify(payload, null, 2).length > maxChars) {
|
|
82
|
+
size = Math.max(1, Math.floor(size / 2));
|
|
83
|
+
payload = build(size);
|
|
84
|
+
}
|
|
85
|
+
return { payload, size };
|
|
86
|
+
}
|
package/dist/tools/data.js
CHANGED
|
@@ -79,7 +79,8 @@ export function register(server, ctx) {
|
|
|
79
79
|
exported.agentsMd = instructions;
|
|
80
80
|
exported.claudeMd = instructions; // Deprecated export alias for older clients.
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
// An export is only useful whole, so it is exempt from the response cap.
|
|
83
|
+
return mcpResponse({ ok: true, message: `Exported project "${project}".`, data: exported }, { unbounded: true });
|
|
83
84
|
});
|
|
84
85
|
server.registerTool("import_project", {
|
|
85
86
|
title: "◆ phren · import",
|