@phren/cli 0.3.32 → 0.3.33
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-hook.mjs +71 -37
- package/package.json +1 -1
|
@@ -2,3 +2,7 @@
|
|
|
2
2
|
* same Mac as its hostname, the hostname's first label and its Bonjour name.
|
|
3
3
|
* The Hook reports them in /v1/health so a peer can recognize this computer. */
|
|
4
4
|
export declare function localNames(): string[];
|
|
5
|
+
/** The name a schedule should carry for this computer: the Sharing name on a
|
|
6
|
+
* Mac (the hostname there follows the network, "Mac" or "Mac.example.net"),
|
|
7
|
+
* otherwise the hostname. */
|
|
8
|
+
export declare function stableComputerName(): string;
|
|
@@ -11,6 +11,25 @@ export function localNames() {
|
|
|
11
11
|
names.push(execFileSync("scutil", ["--get", "LocalHostName"], { encoding: "utf8", timeout: 1_000 }).trim());
|
|
12
12
|
}
|
|
13
13
|
catch { /* No Bonjour name set: the hostname forms above still match. */ }
|
|
14
|
+
// The name people see in Sharing ("Sam’s Mac mini"), which the phone and schedules use.
|
|
15
|
+
try {
|
|
16
|
+
names.push(execFileSync("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1_000 }).trim());
|
|
17
|
+
}
|
|
18
|
+
catch { /* No Sharing name set. */ }
|
|
14
19
|
}
|
|
15
20
|
return [...new Set(names.filter(Boolean))];
|
|
16
21
|
}
|
|
22
|
+
/** The name a schedule should carry for this computer: the Sharing name on a
|
|
23
|
+
* Mac (the hostname there follows the network, "Mac" or "Mac.example.net"),
|
|
24
|
+
* otherwise the hostname. */
|
|
25
|
+
export function stableComputerName() {
|
|
26
|
+
if (process.platform === "darwin") {
|
|
27
|
+
try {
|
|
28
|
+
const name = execFileSync("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1_000 }).trim();
|
|
29
|
+
if (name)
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
catch { /* No Sharing name set: fall back to the hostname. */ }
|
|
33
|
+
}
|
|
34
|
+
return hostname();
|
|
35
|
+
}
|
|
@@ -24,6 +24,10 @@ export declare function claudeEffortReply(text: string): EffortReply | undefined
|
|
|
24
24
|
/** Empty prompts can draw a dim placeholder. Only ANSI evidence that every
|
|
25
25
|
* character after the prompt is dim distinguishes that from a person's draft. */
|
|
26
26
|
export declare function emptyComposer(line: string): boolean;
|
|
27
|
+
/** Typing a slash command into a draft or an open menu would corrupt both, so
|
|
28
|
+
* the terminal must show an empty composer and no menu first. The `code` says
|
|
29
|
+
* which: the phone names the cause and offers the terminal. */
|
|
30
|
+
export declare function assertComposerReady(before: string, action: string): void;
|
|
27
31
|
/** Only a footer below Codex's empty composer proves the active model. Text
|
|
28
32
|
* in history, a menu, or the startup banner must never confirm a switch. */
|
|
29
33
|
export declare function codexModelStatus(text: string, model: AgentModel): boolean;
|
|
@@ -82,6 +82,21 @@ export function emptyComposer(line) {
|
|
|
82
82
|
}
|
|
83
83
|
return prompt;
|
|
84
84
|
}
|
|
85
|
+
/** Typing a slash command into a draft or an open menu would corrupt both, so
|
|
86
|
+
* the terminal must show an empty composer and no menu first. The `code` says
|
|
87
|
+
* which: the phone names the cause and offers the terminal. */
|
|
88
|
+
export function assertComposerReady(before, action) {
|
|
89
|
+
const composer = before.split(/\r?\n/).reverse().find(line => /^\s*[›❯>]/.test(stripTerminal(line)));
|
|
90
|
+
if (visibleTerminalChoice(stripTerminal(before))) {
|
|
91
|
+
throw new BridgeError(409, `A menu is open in the terminal. Open terminal to finish it, then ${action}.`, { code: "terminal-menu" });
|
|
92
|
+
}
|
|
93
|
+
if (!composer) {
|
|
94
|
+
throw new BridgeError(409, `Phren couldn't find the terminal's input line. Open terminal to ${action}.`, { code: "terminal-unreadable" });
|
|
95
|
+
}
|
|
96
|
+
if (!emptyComposer(composer)) {
|
|
97
|
+
throw new BridgeError(409, `There's unsent text in the terminal. Send or clear it, then ${action}.`, { code: "terminal-draft" });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
85
100
|
/** Only a footer below Codex's empty composer proves the active model. Text
|
|
86
101
|
* in history, a menu, or the startup banner must never confirm a switch. */
|
|
87
102
|
export function codexModelStatus(text, model) {
|
|
@@ -182,10 +197,7 @@ export class ModelSwitcher {
|
|
|
182
197
|
let claudeEffort;
|
|
183
198
|
const before = await this.hooks.paneLines(target, false);
|
|
184
199
|
// Preserve a person's draft and any pre-existing menu. Never clear it.
|
|
185
|
-
|
|
186
|
-
if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before))) {
|
|
187
|
-
throw new BridgeError(409, "The terminal has a draft or an unreadable prompt. Open terminal before switching models.");
|
|
188
|
-
}
|
|
200
|
+
assertComposerReady(before, "switch models");
|
|
189
201
|
await validate(true);
|
|
190
202
|
opened = true;
|
|
191
203
|
this.hooks.menuOpened(target, "/model");
|
|
@@ -90,6 +90,8 @@ export interface ScheduleStatus extends Schedule {
|
|
|
90
90
|
lastRun: Omit<ScheduleRun, "id" | "scheduleId" | "project"> | null;
|
|
91
91
|
lastRuns: ScheduleRun[];
|
|
92
92
|
running: boolean;
|
|
93
|
+
/** Whether this computer owns the schedule: it runs it and answers Run now. */
|
|
94
|
+
owned: boolean;
|
|
93
95
|
}
|
|
94
96
|
interface ScheduleDocument {
|
|
95
97
|
document: Record<string, unknown>;
|
|
@@ -121,8 +121,16 @@ export function canonicalComputer(value) {
|
|
|
121
121
|
const normalized = value.trim().toLowerCase();
|
|
122
122
|
return normalized.endsWith(".local") ? normalized.slice(0, -".local".length) : normalized;
|
|
123
123
|
}
|
|
124
|
+
/** One computer's names differ only in punctuation across macOS ("Sam’s Mac mini",
|
|
125
|
+
* "Sams-Mac-mini"), so letters and digits alone also match. */
|
|
126
|
+
function foldedComputer(value) {
|
|
127
|
+
return canonicalComputer(value).replace(/[^\p{L}\p{N}]/gu, "");
|
|
128
|
+
}
|
|
124
129
|
export function computerMatches(wanted, current) {
|
|
125
|
-
|
|
130
|
+
if (canonicalComputer(wanted) === canonicalComputer(current))
|
|
131
|
+
return true;
|
|
132
|
+
const folded = foldedComputer(wanted);
|
|
133
|
+
return folded !== "" && folded === foldedComputer(current);
|
|
126
134
|
}
|
|
127
135
|
export function scheduleNotifications(schedule) {
|
|
128
136
|
return new Set(schedule.notify ?? ["finish", "failure"]);
|
|
@@ -8,6 +8,8 @@ export declare class Scheduler {
|
|
|
8
8
|
private readonly launch;
|
|
9
9
|
private readonly runsFile;
|
|
10
10
|
private readonly computer;
|
|
11
|
+
/** Every name this computer answers to; a schedule names one of them. */
|
|
12
|
+
private readonly names;
|
|
11
13
|
private readonly locateProject;
|
|
12
14
|
private readonly push?;
|
|
13
15
|
private readonly log;
|
|
@@ -25,6 +27,8 @@ export declare class Scheduler {
|
|
|
25
27
|
launch: ScheduleLauncher;
|
|
26
28
|
runsFile: string;
|
|
27
29
|
computer?: string | (() => string);
|
|
30
|
+
/** Further names this computer answers to, such as its Hook computer id. */
|
|
31
|
+
aliases?: string[];
|
|
28
32
|
locateProject?: (project: string) => Promise<string | undefined>;
|
|
29
33
|
push?: SchedulePushSender;
|
|
30
34
|
log?: (message: string) => void;
|
|
@@ -32,6 +36,7 @@ export declare class Scheduler {
|
|
|
32
36
|
private projectDirectories;
|
|
33
37
|
private projectDirectory;
|
|
34
38
|
private exclusive;
|
|
39
|
+
private owns;
|
|
35
40
|
statuses(): Promise<{
|
|
36
41
|
computer: string;
|
|
37
42
|
timeZone: string;
|
package/dist/bridge/schedules.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { stat } from "node:fs/promises";
|
|
3
|
-
import {
|
|
3
|
+
import { localNames, stableComputerName } from "./computer-names.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { BridgeError } from "./protocol.js";
|
|
6
6
|
import { getProjectSourcePath } from "../project-config.js";
|
|
@@ -15,6 +15,8 @@ export class Scheduler {
|
|
|
15
15
|
launch;
|
|
16
16
|
runsFile;
|
|
17
17
|
computer;
|
|
18
|
+
/** Every name this computer answers to; a schedule names one of them. */
|
|
19
|
+
names;
|
|
18
20
|
locateProject;
|
|
19
21
|
push;
|
|
20
22
|
log;
|
|
@@ -35,8 +37,10 @@ export class Scheduler {
|
|
|
35
37
|
this.computer = options.computer;
|
|
36
38
|
else {
|
|
37
39
|
const computer = options.computer;
|
|
38
|
-
this.computer = () => computer ??
|
|
40
|
+
this.computer = () => computer ?? stableComputerName();
|
|
39
41
|
}
|
|
42
|
+
const aliases = options.aliases ?? [];
|
|
43
|
+
this.names = options.computer === undefined ? () => [...localNames(), ...aliases] : () => [this.computer(), ...aliases];
|
|
40
44
|
this.locateProject = options.locateProject ?? (async () => undefined);
|
|
41
45
|
this.push = options.push;
|
|
42
46
|
this.log = options.log ?? (message => console.error(message));
|
|
@@ -60,8 +64,11 @@ export class Scheduler {
|
|
|
60
64
|
release();
|
|
61
65
|
}
|
|
62
66
|
}
|
|
67
|
+
owns(schedule, names = this.names()) {
|
|
68
|
+
return names.some(name => computerMatches(schedule.computer, name));
|
|
69
|
+
}
|
|
63
70
|
async statuses() {
|
|
64
|
-
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer();
|
|
71
|
+
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer(), names = this.names();
|
|
65
72
|
for (const directory of this.projectDirectories()) {
|
|
66
73
|
let schedules;
|
|
67
74
|
try {
|
|
@@ -75,8 +82,9 @@ export class Scheduler {
|
|
|
75
82
|
const matching = runs.filter(run => (run.scheduleProject ?? run.project) === project && run.scheduleId === schedule.id);
|
|
76
83
|
const { lastRun: last, lastRuns } = latestScheduleBatch(matching);
|
|
77
84
|
const running = matching.some(run => runningStatuses.has(run.status));
|
|
78
|
-
const due =
|
|
79
|
-
|
|
85
|
+
const due = this.owns(schedule, names) ? nextRun(schedule, last) : null;
|
|
86
|
+
const owned = this.owns(schedule, names);
|
|
87
|
+
result.push({ ...schedule, project, lastRuns, owned, nextRun: due?.toISOString() ?? null,
|
|
80
88
|
lastRun: last ? { startedAt: last.startedAt, ...(last.finishedAt ? { finishedAt: last.finishedAt } : {}), status: last.status,
|
|
81
89
|
...(last.batchId ? { batchId: last.batchId, scheduleProject: last.scheduleProject } : {}),
|
|
82
90
|
...(last.reason ? { reason: last.reason } : {}),
|
|
@@ -112,7 +120,7 @@ export class Scheduler {
|
|
|
112
120
|
if (expectedUpdatedAt !== undefined && Date.parse(expectedUpdatedAt) !== Date.parse(schedule.updatedAt)) {
|
|
113
121
|
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.");
|
|
114
122
|
}
|
|
115
|
-
if (!
|
|
123
|
+
if (!this.owns(schedule))
|
|
116
124
|
throw new BridgeError(409, `${schedule.computer} owns this schedule; run it from that computer.`);
|
|
117
125
|
const runs = await readScheduleRuns(this.runsFile);
|
|
118
126
|
const matching = runs.filter(run => (run.scheduleProject ?? run.project) === project && run.scheduleId === id);
|
package/dist/bridge/server.js
CHANGED
|
@@ -155,6 +155,7 @@ export async function serve(version, options = {}) {
|
|
|
155
155
|
const codexQuestions = new CodexQuestions(undefined, codexServers);
|
|
156
156
|
const scheduleStore = defaultPhrenPath();
|
|
157
157
|
const scheduler = modules.has("schedules") ? new Scheduler({ now: () => new Date(), store: scheduleStore, runsFile: scheduleRunsFile(),
|
|
158
|
+
aliases: [computerID],
|
|
158
159
|
// A schedule starts in its project's folder, which the Hook resolved itself.
|
|
159
160
|
launch: createScheduleLauncher((server, data) => launchSession(server, data, { trustFolder: true }), scheduleStore),
|
|
160
161
|
push: { notify: value => agentHooks.push.notifySchedule(value) },
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { open, stat } from "node:fs/promises";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { stripTerminal } from "../terminal-text.js";
|
|
4
|
-
import { visibleTerminalChoice } from "./agent-hooks.js";
|
|
5
4
|
import { claudeSuggestion } from "./claude-suggestion.js";
|
|
6
5
|
import { codexServers } from "./codex-servers.js";
|
|
7
6
|
import { validateTarget } from "./herdr.js";
|
|
8
7
|
import { intervalFromEnv } from "./limits.js";
|
|
9
|
-
import {
|
|
8
|
+
import { assertComposerReady } from "./model-switch.js";
|
|
10
9
|
import { claudeFooterMode, permissionModes } from "./permission-mode.js";
|
|
11
10
|
import { BridgeError, object, PERMISSION_MODES } from "./protocol.js";
|
|
12
11
|
import { terminalProvider } from "./terminal.js";
|
|
@@ -216,10 +215,7 @@ export class SettingsSwitcher {
|
|
|
216
215
|
const slash = async (command) => {
|
|
217
216
|
// Typing into a draft would corrupt both it and the command.
|
|
218
217
|
const before = await this.hooks.paneLines(target, false);
|
|
219
|
-
|
|
220
|
-
if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before))) {
|
|
221
|
-
throw new BridgeError(409, "The terminal has a draft or an unreadable prompt. Open terminal before changing settings.");
|
|
222
|
-
}
|
|
218
|
+
assertComposerReady(before, "change settings");
|
|
223
219
|
await validate();
|
|
224
220
|
await terminalProvider().prompt(target.server, target.pane, command);
|
|
225
221
|
};
|
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.33" : "0.0.0";
|
|
37424
37424
|
PACKAGE_JSON = readPackageJson();
|
|
37425
37425
|
PACKAGE_NAME = PACKAGE_JSON.name || "phren";
|
|
37426
37426
|
VERSION = PACKAGE_JSON.version || BUNDLED_VERSION;
|
|
@@ -40504,9 +40504,23 @@ function localNames() {
|
|
|
40504
40504
|
names.push(execFileSync3("scutil", ["--get", "LocalHostName"], { encoding: "utf8", timeout: 1e3 }).trim());
|
|
40505
40505
|
} catch {
|
|
40506
40506
|
}
|
|
40507
|
+
try {
|
|
40508
|
+
names.push(execFileSync3("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1e3 }).trim());
|
|
40509
|
+
} catch {
|
|
40510
|
+
}
|
|
40507
40511
|
}
|
|
40508
40512
|
return [...new Set(names.filter(Boolean))];
|
|
40509
40513
|
}
|
|
40514
|
+
function stableComputerName() {
|
|
40515
|
+
if (process.platform === "darwin") {
|
|
40516
|
+
try {
|
|
40517
|
+
const name = execFileSync3("scutil", ["--get", "ComputerName"], { encoding: "utf8", timeout: 1e3 }).trim();
|
|
40518
|
+
if (name) return name;
|
|
40519
|
+
} catch {
|
|
40520
|
+
}
|
|
40521
|
+
}
|
|
40522
|
+
return hostname5();
|
|
40523
|
+
}
|
|
40510
40524
|
var init_computer_names = __esm({
|
|
40511
40525
|
"src/bridge/computer-names.ts"() {
|
|
40512
40526
|
"use strict";
|
|
@@ -41966,8 +41980,13 @@ function canonicalComputer(value2) {
|
|
|
41966
41980
|
const normalized = value2.trim().toLowerCase();
|
|
41967
41981
|
return normalized.endsWith(".local") ? normalized.slice(0, -".local".length) : normalized;
|
|
41968
41982
|
}
|
|
41983
|
+
function foldedComputer(value2) {
|
|
41984
|
+
return canonicalComputer(value2).replace(/[^\p{L}\p{N}]/gu, "");
|
|
41985
|
+
}
|
|
41969
41986
|
function computerMatches(wanted, current2) {
|
|
41970
|
-
|
|
41987
|
+
if (canonicalComputer(wanted) === canonicalComputer(current2)) return true;
|
|
41988
|
+
const folded = foldedComputer(wanted);
|
|
41989
|
+
return folded !== "" && folded === foldedComputer(current2);
|
|
41971
41990
|
}
|
|
41972
41991
|
function scheduleNotifications(schedule) {
|
|
41973
41992
|
return new Set(schedule.notify ?? ["finish", "failure"]);
|
|
@@ -42654,12 +42673,12 @@ var init_schedule_launch = __esm({
|
|
|
42654
42673
|
// src/bridge/schedules.ts
|
|
42655
42674
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
42656
42675
|
import { stat as stat16 } from "node:fs/promises";
|
|
42657
|
-
import { hostname as hostname6 } from "node:os";
|
|
42658
42676
|
import path59 from "node:path";
|
|
42659
42677
|
var Scheduler;
|
|
42660
42678
|
var init_schedules = __esm({
|
|
42661
42679
|
"src/bridge/schedules.ts"() {
|
|
42662
42680
|
"use strict";
|
|
42681
|
+
init_computer_names();
|
|
42663
42682
|
init_protocol();
|
|
42664
42683
|
init_project_config();
|
|
42665
42684
|
init_shared();
|
|
@@ -42673,6 +42692,8 @@ var init_schedules = __esm({
|
|
|
42673
42692
|
launch;
|
|
42674
42693
|
runsFile;
|
|
42675
42694
|
computer;
|
|
42695
|
+
/** Every name this computer answers to; a schedule names one of them. */
|
|
42696
|
+
names;
|
|
42676
42697
|
locateProject;
|
|
42677
42698
|
push;
|
|
42678
42699
|
log;
|
|
@@ -42692,8 +42713,10 @@ var init_schedules = __esm({
|
|
|
42692
42713
|
if (typeof options.computer === "function") this.computer = options.computer;
|
|
42693
42714
|
else {
|
|
42694
42715
|
const computer = options.computer;
|
|
42695
|
-
this.computer = () => computer ??
|
|
42716
|
+
this.computer = () => computer ?? stableComputerName();
|
|
42696
42717
|
}
|
|
42718
|
+
const aliases = options.aliases ?? [];
|
|
42719
|
+
this.names = options.computer === void 0 ? () => [...localNames(), ...aliases] : () => [this.computer(), ...aliases];
|
|
42697
42720
|
this.locateProject = options.locateProject ?? (async () => void 0);
|
|
42698
42721
|
this.push = options.push;
|
|
42699
42722
|
this.log = options.log ?? ((message) => console.error(message));
|
|
@@ -42719,8 +42742,11 @@ var init_schedules = __esm({
|
|
|
42719
42742
|
release();
|
|
42720
42743
|
}
|
|
42721
42744
|
}
|
|
42745
|
+
owns(schedule, names = this.names()) {
|
|
42746
|
+
return names.some((name) => computerMatches(schedule.computer, name));
|
|
42747
|
+
}
|
|
42722
42748
|
async statuses() {
|
|
42723
|
-
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer();
|
|
42749
|
+
const runs = await readScheduleRuns(this.runsFile), result = [], computer = this.computer(), names = this.names();
|
|
42724
42750
|
for (const directory of this.projectDirectories()) {
|
|
42725
42751
|
let schedules;
|
|
42726
42752
|
try {
|
|
@@ -42733,11 +42759,13 @@ var init_schedules = __esm({
|
|
|
42733
42759
|
const matching = runs.filter((run2) => (run2.scheduleProject ?? run2.project) === project && run2.scheduleId === schedule.id);
|
|
42734
42760
|
const { lastRun: last, lastRuns } = latestScheduleBatch(matching);
|
|
42735
42761
|
const running2 = matching.some((run2) => runningStatuses.has(run2.status));
|
|
42736
|
-
const due =
|
|
42762
|
+
const due = this.owns(schedule, names) ? nextRun(schedule, last) : null;
|
|
42763
|
+
const owned = this.owns(schedule, names);
|
|
42737
42764
|
result.push({
|
|
42738
42765
|
...schedule,
|
|
42739
42766
|
project,
|
|
42740
42767
|
lastRuns,
|
|
42768
|
+
owned,
|
|
42741
42769
|
nextRun: due?.toISOString() ?? null,
|
|
42742
42770
|
lastRun: last ? {
|
|
42743
42771
|
startedAt: last.startedAt,
|
|
@@ -42777,7 +42805,7 @@ var init_schedules = __esm({
|
|
|
42777
42805
|
if (expectedUpdatedAt !== void 0 && Date.parse(expectedUpdatedAt) !== Date.parse(schedule.updatedAt)) {
|
|
42778
42806
|
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
42807
|
}
|
|
42780
|
-
if (!
|
|
42808
|
+
if (!this.owns(schedule)) throw new BridgeError(409, `${schedule.computer} owns this schedule; run it from that computer.`);
|
|
42781
42809
|
const runs = await readScheduleRuns(this.runsFile);
|
|
42782
42810
|
const matching = runs.filter((run2) => (run2.scheduleProject ?? run2.project) === project && run2.scheduleId === id2);
|
|
42783
42811
|
if (matching.some((run2) => runningStatuses.has(run2.status))) {
|
|
@@ -42968,7 +42996,7 @@ var init_schedules = __esm({
|
|
|
42968
42996
|
// src/bridge/health.ts
|
|
42969
42997
|
import { execFile as execFile11, spawn as spawn8 } from "node:child_process";
|
|
42970
42998
|
import { lstat as lstat16, readFile as readFile30 } from "node:fs/promises";
|
|
42971
|
-
import { homedir as homedir14, hostname as
|
|
42999
|
+
import { homedir as homedir14, hostname as hostname6 } from "node:os";
|
|
42972
43000
|
import path60 from "node:path";
|
|
42973
43001
|
import { promisify as promisify10 } from "node:util";
|
|
42974
43002
|
async function terminalHealth() {
|
|
@@ -43150,7 +43178,7 @@ async function pushConfigured() {
|
|
|
43150
43178
|
return { configured: !!info?.isFile() };
|
|
43151
43179
|
}
|
|
43152
43180
|
async function healthDetails(options) {
|
|
43153
|
-
const name =
|
|
43181
|
+
const name = hostname6();
|
|
43154
43182
|
const hostKey = await ownHostKey();
|
|
43155
43183
|
const peersPromise = (async () => {
|
|
43156
43184
|
let peers2;
|
|
@@ -43213,10 +43241,10 @@ var init_health = __esm({
|
|
|
43213
43241
|
});
|
|
43214
43242
|
|
|
43215
43243
|
// src/bridge/conductor-group.ts
|
|
43216
|
-
import { hostname as
|
|
43244
|
+
import { hostname as hostname7 } from "node:os";
|
|
43217
43245
|
async function localCaller() {
|
|
43218
43246
|
const hostKey = await ownHostKey();
|
|
43219
|
-
return { name:
|
|
43247
|
+
return { name: hostname7(), ...hostKey ? { hostKey } : {} };
|
|
43220
43248
|
}
|
|
43221
43249
|
function callerQuery(caller) {
|
|
43222
43250
|
return new URLSearchParams({ name: caller.name, ...caller.hostKey ? { hostKey: caller.hostKey } : {} }).toString();
|
|
@@ -46789,7 +46817,7 @@ import { execFile as execFile14 } from "node:child_process";
|
|
|
46789
46817
|
import { promisify as promisify13 } from "node:util";
|
|
46790
46818
|
import { createHash as createHash23, createPublicKey, verify } from "node:crypto";
|
|
46791
46819
|
import { lstat as lstat24, mkdir as mkdir19, readFile as readFile36, realpath as realpath13 } from "node:fs/promises";
|
|
46792
|
-
import { hostname as
|
|
46820
|
+
import { hostname as hostname8 } from "node:os";
|
|
46793
46821
|
import path72 from "node:path";
|
|
46794
46822
|
async function git4(cwd, ...args) {
|
|
46795
46823
|
return (await exec13("git", ["-C", cwd, "--no-pager", ...args], {
|
|
@@ -46903,7 +46931,7 @@ async function approvalRuleContext(cwd, harness, session) {
|
|
|
46903
46931
|
const listed2 = (await git4(common, "worktree", "list", "--porcelain", "-z")).split("\0").filter((field) => field.startsWith("worktree ")).map((field) => field.slice("worktree ".length));
|
|
46904
46932
|
const registered = await Promise.all(listed2.map((directory2) => realpath13(directory2).catch(() => void 0)));
|
|
46905
46933
|
if (!registered.includes(checkout)) return void 0;
|
|
46906
|
-
return { project: path72.dirname(common), harness: scopeSchema.shape.harness.unwrap().parse(harness), session, computer:
|
|
46934
|
+
return { project: path72.dirname(common), harness: scopeSchema.shape.harness.unwrap().parse(harness), session, computer: hostname8() };
|
|
46907
46935
|
} catch {
|
|
46908
46936
|
return void 0;
|
|
46909
46937
|
}
|
|
@@ -47441,14 +47469,14 @@ var init_push = __esm({
|
|
|
47441
47469
|
|
|
47442
47470
|
// src/bridge/pair.ts
|
|
47443
47471
|
import { execFile as execFile15 } from "node:child_process";
|
|
47444
|
-
import { homedir as homedir16, hostname as
|
|
47472
|
+
import { homedir as homedir16, hostname as hostname9, networkInterfaces, userInfo as userInfo4 } from "node:os";
|
|
47445
47473
|
import { promisify as promisify14 } from "node:util";
|
|
47446
47474
|
async function computerDisplayName() {
|
|
47447
47475
|
if (process.platform === "darwin") {
|
|
47448
47476
|
const name = await exec14("scutil", ["--get", "ComputerName"], { timeout: 2e3 }).then(({ stdout }) => stdout.trim()).catch(() => "");
|
|
47449
47477
|
if (name) return name.slice(0, 64);
|
|
47450
47478
|
}
|
|
47451
|
-
return
|
|
47479
|
+
return hostname9().replace(/\.local$/i, "").split(".")[0] || "Computer";
|
|
47452
47480
|
}
|
|
47453
47481
|
var exec14, request5;
|
|
47454
47482
|
var init_pair = __esm({
|
|
@@ -48378,7 +48406,7 @@ import { mkdir as mkdir21, readFile as readFile40, chmod as chmod4, unlink as un
|
|
|
48378
48406
|
import { watch } from "node:fs";
|
|
48379
48407
|
import path80 from "node:path";
|
|
48380
48408
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
48381
|
-
import { hostname as
|
|
48409
|
+
import { hostname as hostname10 } from "node:os";
|
|
48382
48410
|
function watchHangUp(res) {
|
|
48383
48411
|
let closed = res.destroyed || res.socket?.destroyed === true;
|
|
48384
48412
|
const onClose = () => {
|
|
@@ -48679,7 +48707,7 @@ var init_agent_hooks = __esm({
|
|
|
48679
48707
|
fanoutArchiveTimer;
|
|
48680
48708
|
/** The name the phone paired with (macOS Computer Name), for approval alerts;
|
|
48681
48709
|
* the short host name until that lookup answers. */
|
|
48682
|
-
computerName =
|
|
48710
|
+
computerName = hostname10().replace(/\.local$/i, "").split(".")[0] || "Computer";
|
|
48683
48711
|
/** sudo -A requests from askpass, answered from the phone (sudo.ts). */
|
|
48684
48712
|
sudo;
|
|
48685
48713
|
approvalsDirectory() {
|
|
@@ -50026,7 +50054,7 @@ ${await conductorBrief()}` : context } : {}));
|
|
|
50026
50054
|
approvalRuleContext(body2.cwd, target.source, target.session)
|
|
50027
50055
|
]);
|
|
50028
50056
|
return paneContext && requestContext?.project === paneContext.project ? requestContext : void 0;
|
|
50029
|
-
}, void 0, { harness: target.source, session: target.session, computer:
|
|
50057
|
+
}, void 0, { harness: target.source, session: target.session, computer: hostname10() }) : void 0;
|
|
50030
50058
|
if (ruleEffect === "deny") {
|
|
50031
50059
|
res.end(JSON.stringify({ hookSpecificOutput: { hookEventName: "PermissionRequest", decision: { behavior: "deny", message: "Denied by an owner approval rule." } } }));
|
|
50032
50060
|
return;
|
|
@@ -50761,6 +50789,18 @@ function emptyComposer(line) {
|
|
|
50761
50789
|
}
|
|
50762
50790
|
return prompt;
|
|
50763
50791
|
}
|
|
50792
|
+
function assertComposerReady(before, action) {
|
|
50793
|
+
const composer = before.split(/\r?\n/).reverse().find((line) => /^\s*[›❯>]/.test(stripTerminal(line)));
|
|
50794
|
+
if (visibleTerminalChoice(stripTerminal(before))) {
|
|
50795
|
+
throw new BridgeError(409, `A menu is open in the terminal. Open terminal to finish it, then ${action}.`, { code: "terminal-menu" });
|
|
50796
|
+
}
|
|
50797
|
+
if (!composer) {
|
|
50798
|
+
throw new BridgeError(409, `Phren couldn't find the terminal's input line. Open terminal to ${action}.`, { code: "terminal-unreadable" });
|
|
50799
|
+
}
|
|
50800
|
+
if (!emptyComposer(composer)) {
|
|
50801
|
+
throw new BridgeError(409, `There's unsent text in the terminal. Send or clear it, then ${action}.`, { code: "terminal-draft" });
|
|
50802
|
+
}
|
|
50803
|
+
}
|
|
50764
50804
|
function codexModelStatus(text5, model) {
|
|
50765
50805
|
const lines = text5.split(/\r?\n/).reverse();
|
|
50766
50806
|
const composer = lines.findIndex((line) => /^\s*[›❯>]/.test(stripTerminal(line)));
|
|
@@ -50866,10 +50906,7 @@ var init_model_switch = __esm({
|
|
|
50866
50906
|
}
|
|
50867
50907
|
let claudeEffort;
|
|
50868
50908
|
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
|
-
}
|
|
50909
|
+
assertComposerReady(before, "switch models");
|
|
50873
50910
|
await validate2(true);
|
|
50874
50911
|
opened2 = true;
|
|
50875
50912
|
this.hooks.menuOpened(target, "/model");
|
|
@@ -54437,7 +54474,6 @@ var init_settings_switch = __esm({
|
|
|
54437
54474
|
"use strict";
|
|
54438
54475
|
init_zod();
|
|
54439
54476
|
init_terminal_text();
|
|
54440
|
-
init_agent_hooks();
|
|
54441
54477
|
init_claude_suggestion();
|
|
54442
54478
|
init_codex_servers();
|
|
54443
54479
|
init_herdr();
|
|
@@ -54577,10 +54613,7 @@ var init_settings_switch = __esm({
|
|
|
54577
54613
|
};
|
|
54578
54614
|
const slash = async (command) => {
|
|
54579
54615
|
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
|
-
}
|
|
54616
|
+
assertComposerReady(before, "change settings");
|
|
54584
54617
|
await validate2();
|
|
54585
54618
|
await terminalProvider().prompt(target.server, target.pane, command);
|
|
54586
54619
|
};
|
|
@@ -55257,7 +55290,7 @@ var init_resources = __esm({
|
|
|
55257
55290
|
|
|
55258
55291
|
// src/bridge/canary.ts
|
|
55259
55292
|
import { lstat as lstat29, mkdtemp as mkdtemp5, realpath as realpath16, rm as rm12 } from "node:fs/promises";
|
|
55260
|
-
import { hostname as
|
|
55293
|
+
import { hostname as hostname11, tmpdir as tmpdir3 } from "node:os";
|
|
55261
55294
|
import path94 from "node:path";
|
|
55262
55295
|
function reason(error62) {
|
|
55263
55296
|
const text5 = error62 instanceof Error ? error62.message : "Unknown failure.";
|
|
@@ -55372,7 +55405,7 @@ function runCanary(options) {
|
|
|
55372
55405
|
const result = {
|
|
55373
55406
|
version: 1,
|
|
55374
55407
|
trigger: options.trigger,
|
|
55375
|
-
computer:
|
|
55408
|
+
computer: hostname11(),
|
|
55376
55409
|
startedAt: started.toISOString(),
|
|
55377
55410
|
finishedAt: finished2.toISOString(),
|
|
55378
55411
|
durationMs: finished2.getTime() - started.getTime(),
|
|
@@ -63497,7 +63530,7 @@ import { randomUUID as randomUUID27 } from "node:crypto";
|
|
|
63497
63530
|
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
63531
|
import { readFileSync as readFileSync42 } from "node:fs";
|
|
63499
63532
|
import { createServer as createServer3 } from "node:http";
|
|
63500
|
-
import { cpus as cpus2, hostname as
|
|
63533
|
+
import { cpus as cpus2, hostname as hostname12, loadavg as loadavg2 } from "node:os";
|
|
63501
63534
|
import path124 from "node:path";
|
|
63502
63535
|
async function serve(version3, options = {}) {
|
|
63503
63536
|
process.umask(63);
|
|
@@ -63618,6 +63651,7 @@ async function serve(version3, options = {}) {
|
|
|
63618
63651
|
now: () => /* @__PURE__ */ new Date(),
|
|
63619
63652
|
store: scheduleStore,
|
|
63620
63653
|
runsFile: scheduleRunsFile(),
|
|
63654
|
+
aliases: [computerID2],
|
|
63621
63655
|
// A schedule starts in its project's folder, which the Hook resolved itself.
|
|
63622
63656
|
launch: createScheduleLauncher((server, data) => launchSession(server, data, { trustFolder: true }), scheduleStore),
|
|
63623
63657
|
push: { notify: (value2) => agentHooks.push.notifySchedule(value2) },
|
|
@@ -63643,7 +63677,7 @@ async function serve(version3, options = {}) {
|
|
|
63643
63677
|
product: "phren-hook",
|
|
63644
63678
|
protocol: PROTOCOL,
|
|
63645
63679
|
version: version3,
|
|
63646
|
-
computer: { id: computerID2, name:
|
|
63680
|
+
computer: { id: computerID2, name: hostname12(), aliases: localNames() },
|
|
63647
63681
|
capabilities: activeCapabilities,
|
|
63648
63682
|
modules: Object.fromEntries(modules.modules.map((module) => [module.name, module.version])),
|
|
63649
63683
|
store: modules.store,
|
|
@@ -63919,7 +63953,7 @@ var init_server = __esm({
|
|
|
63919
63953
|
// src/bridge/link.ts
|
|
63920
63954
|
import { execFile as execFile25 } from "node:child_process";
|
|
63921
63955
|
import { readFile as readFile53 } from "node:fs/promises";
|
|
63922
|
-
import { homedir as homedir21, hostname as
|
|
63956
|
+
import { homedir as homedir21, hostname as hostname13, userInfo as userInfo5 } from "node:os";
|
|
63923
63957
|
import path125 from "node:path";
|
|
63924
63958
|
import { promisify as promisify24 } from "node:util";
|
|
63925
63959
|
function sshConfigHosts(text5) {
|
|
@@ -63992,7 +64026,7 @@ async function linkComputer(host, options = {}) {
|
|
|
63992
64026
|
const own2 = (await readFile53(path125.join(bridgeRoot(), "computer-id"), "utf8").catch(() => "")).trim();
|
|
63993
64027
|
if (remote.computerId === own2) throw new BridgeError(409, `${host} is this computer.`);
|
|
63994
64028
|
const name = computerName.parse(options.name ?? slugName(host));
|
|
63995
|
-
const as = computerName.parse(options.as ?? slugName(
|
|
64029
|
+
const as = computerName.parse(options.as ?? slugName(hostname13()));
|
|
63996
64030
|
const backAddress = options.backAddress ?? remote.client;
|
|
63997
64031
|
if (!backAddress) throw new BridgeError(409, `${host} did not report this computer's address; pass --back-address.`);
|
|
63998
64032
|
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 +64368,7 @@ async function main() {
|
|
|
64334
64368
|
return askpass2(args[1]);
|
|
64335
64369
|
}
|
|
64336
64370
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
64337
|
-
return runBridge2(args, "0.3.
|
|
64371
|
+
return runBridge2(args, "0.3.33");
|
|
64338
64372
|
}
|
|
64339
64373
|
main().then((code) => {
|
|
64340
64374
|
process.exitCode = code;
|