@phren/cli 0.3.19 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/agent-hooks.d.ts +38 -20
- package/dist/bridge/agent-hooks.js +100 -37
- package/dist/bridge/approval-summary.d.ts +4 -0
- package/dist/bridge/approval-summary.js +12 -1
- package/dist/bridge/changes.d.ts +4 -0
- package/dist/bridge/changes.js +25 -2
- package/dist/bridge/code-note.d.ts +1 -0
- package/dist/bridge/code-note.js +2 -2
- package/dist/bridge/codex-binary.d.ts +5 -0
- package/dist/bridge/codex-binary.js +7 -0
- package/dist/bridge/command.js +24 -6
- package/dist/bridge/dispatch-command.js +1 -1
- package/dist/bridge/dispatch-returns.d.ts +14 -2
- package/dist/bridge/dispatch-returns.js +72 -16
- package/dist/bridge/dispatch.d.ts +23 -0
- package/dist/bridge/dispatch.js +169 -8
- package/dist/bridge/folder-trust.d.ts +13 -3
- package/dist/bridge/folder-trust.js +42 -4
- package/dist/bridge/hand-off.js +2 -1
- package/dist/bridge/herdr.js +6 -5
- package/dist/bridge/hook-fast.d.ts +13 -1
- package/dist/bridge/hook-fast.js +17 -2
- package/dist/bridge/launch-brief.d.ts +3 -1
- package/dist/bridge/launch-brief.js +3 -1
- package/dist/bridge/memory-store.d.ts +7 -0
- package/dist/bridge/memory-store.js +37 -1
- package/dist/bridge/models.d.ts +11 -1
- package/dist/bridge/models.js +47 -2
- package/dist/bridge/schedule-format.d.ts +1 -1
- package/dist/bridge/schedule-format.js +1 -1
- package/dist/bridge/schedule-launch.js +5 -0
- package/dist/bridge/schedule-watch.d.ts +5 -2
- package/dist/bridge/schedule-watch.js +59 -20
- package/dist/bridge/server-launch.d.ts +26 -0
- package/dist/bridge/server-launch.js +122 -12
- package/dist/bridge/server-pane-routes.js +20 -13
- package/dist/bridge/server-routes.d.ts +5 -0
- package/dist/bridge/server-routes.js +2 -2
- package/dist/bridge/server-stream.js +12 -0
- package/dist/bridge/server.js +8 -3
- package/dist/bridge/session-activity.d.ts +6 -0
- package/dist/bridge/session-activity.js +16 -0
- package/dist/bridge/settings-switch.d.ts +7 -0
- package/dist/bridge/settings-switch.js +15 -0
- package/dist/bridge/speech-live.d.ts +45 -0
- package/dist/bridge/speech-live.js +413 -0
- package/dist/bridge/speech-transcribe.d.ts +13 -3
- package/dist/bridge/speech-transcribe.js +26 -8
- package/dist/bridge/speech-voice.d.ts +22 -1
- package/dist/bridge/speech-voice.js +20 -2
- package/dist/bridge/speech.d.ts +24 -4
- package/dist/bridge/speech.js +115 -14
- package/dist/bridge/stalls.d.ts +9 -2
- package/dist/bridge/stalls.js +20 -4
- package/dist/bridge/transcript-claude.js +39 -10
- package/dist/bridge/transcript-preview.d.ts +11 -1
- package/dist/bridge/transcript-preview.js +37 -11
- package/dist/bridge/transcripts.d.ts +2 -1
- package/dist/bridge/transcripts.js +7 -3
- package/dist/bridge/turn-records.d.ts +6 -3
- package/dist/bridge/turn-records.js +9 -4
- package/dist/bridge/usage.d.ts +1 -1
- package/dist/bridge/usage.js +4 -3
- package/dist/bridge/worker-close.js +3 -1
- package/dist/bridge/worker-unfinished.d.ts +43 -0
- package/dist/bridge/worker-unfinished.js +178 -0
- package/dist/bridge-hook.mjs +2458 -1351
- package/dist/cli-registry.js +3 -2
- package/dist/home-paths.d.ts +2 -0
- package/dist/home-paths.js +4 -0
- package/dist/modules/registry.js +2 -2
- package/dist/test-global-setup.js +2 -1
- package/dist/test-sandbox.d.ts +15 -0
- package/dist/test-sandbox.js +36 -0
- package/package.json +1 -1
- package/starter/global/skills/conductor/SKILL.md +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Marking a folder the Hook chose as trusted, so a Claude or
|
|
2
|
+
* Marking a folder the Hook chose as trusted, so a Claude, Codex or Copilot launched
|
|
3
3
|
* there starts without its folder-trust screen. Claude's default on that
|
|
4
4
|
* screen is "No, exit", so a dispatched worker would otherwise sit there
|
|
5
5
|
* until the owner answers it (the brief is never sent; see dispatch.ts).
|
|
@@ -15,11 +15,15 @@
|
|
|
15
15
|
* that key for the working folder and each parent up to its git root.
|
|
16
16
|
* - Codex: `[projects."<dir>"]` `trust_level = "trusted"` in
|
|
17
17
|
* `$CODEX_HOME/config.toml`, the table Codex itself writes on "Yes".
|
|
18
|
+
* - Copilot: the folder added to `trustedFolders` in
|
|
19
|
+
* `$COPILOT_HOME/settings.json` (else `~/.copilot/settings.json`), the list
|
|
20
|
+
* its "Yes, and remember this folder" answer keeps.
|
|
18
21
|
*
|
|
19
|
-
*
|
|
22
|
+
* Claude and Codex were checked against Claude Code 2.1.280 and codex-cli
|
|
23
|
+
* 0.155.1, Copilot against Copilot CLI 1.0.89.
|
|
20
24
|
* `PHREN_PRETRUST=off` turns all of it off.
|
|
21
25
|
*/
|
|
22
|
-
export type TrustHarness = "claude" | "codex";
|
|
26
|
+
export type TrustHarness = "claude" | "codex" | "copilot";
|
|
23
27
|
export type TrustResult = "trusted" | "already" | "skipped";
|
|
24
28
|
export declare function pretrustEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
25
29
|
/** Claude Code's global config file, resolved the way Claude resolves it. */
|
|
@@ -48,6 +52,12 @@ export declare function codexTrustedText(text: string, dir: string): string | un
|
|
|
48
52
|
* file is kept byte for byte. An unreadable config is left untouched.
|
|
49
53
|
*/
|
|
50
54
|
export declare function ensureCodexDirTrusted(dir: string, env?: NodeJS.ProcessEnv): Promise<TrustResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Adds `dir` to `trustedFolders` in Copilot's `settings.json`, creating the
|
|
57
|
+
* file when Copilot has none yet. Other settings are kept; a file that is not
|
|
58
|
+
* a JSON object is left alone (the launch then meets the trust screen).
|
|
59
|
+
*/
|
|
60
|
+
export declare function ensureCopilotFolderTrusted(dir: string, env?: NodeJS.ProcessEnv): Promise<TrustResult>;
|
|
51
61
|
/**
|
|
52
62
|
* Trusts `dir` for `harness` before a launch, when the harness has a trust
|
|
53
63
|
* screen and pre-trust is on. Never throws: a failure is logged and the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, realpath, rmdir, stat, utimes } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { claudeConfigDir, codexHome, homeDir } from "../home-paths.js";
|
|
3
|
+
import { claudeConfigDir, codexHome, copilotHome, homeDir } from "../home-paths.js";
|
|
4
4
|
import { logger } from "../logger.js";
|
|
5
5
|
import { atomic } from "./protocol.js";
|
|
6
6
|
export function pretrustEnabled(env = process.env) {
|
|
@@ -156,19 +156,56 @@ export async function ensureCodexDirTrusted(dir, env = process.env) {
|
|
|
156
156
|
}
|
|
157
157
|
throw new Error("config.toml kept changing while it was being updated");
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Adds `dir` to `trustedFolders` in Copilot's `settings.json`, creating the
|
|
161
|
+
* file when Copilot has none yet. Other settings are kept; a file that is not
|
|
162
|
+
* a JSON object is left alone (the launch then meets the trust screen).
|
|
163
|
+
*/
|
|
164
|
+
export async function ensureCopilotFolderTrusted(dir, env = process.env) {
|
|
165
|
+
const directory = copilotHome(env);
|
|
166
|
+
const configured = path.join(directory, "settings.json");
|
|
167
|
+
const file = await realpath(configured).catch(() => configured);
|
|
168
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
169
|
+
let text = "";
|
|
170
|
+
try {
|
|
171
|
+
text = await readFile(file, "utf8");
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (error.code !== "ENOENT")
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
const settings = text.trim() ? JSON.parse(text) : {};
|
|
178
|
+
if (!settings || typeof settings !== "object" || Array.isArray(settings))
|
|
179
|
+
throw new Error("settings.json is not a JSON object");
|
|
180
|
+
const record = settings;
|
|
181
|
+
if (record.trustedFolders !== undefined && !Array.isArray(record.trustedFolders))
|
|
182
|
+
throw new Error("trustedFolders in settings.json is not a list");
|
|
183
|
+
const trusted = (record.trustedFolders ?? []);
|
|
184
|
+
if (trusted.includes(dir))
|
|
185
|
+
return "already";
|
|
186
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
187
|
+
const metadata = await lstat(file).catch(() => undefined);
|
|
188
|
+
// Copilot may have rewritten the file meanwhile; start over from its text.
|
|
189
|
+
if (await readFile(file, "utf8").catch(() => "") !== text)
|
|
190
|
+
continue;
|
|
191
|
+
await atomic(file, JSON.stringify({ ...record, trustedFolders: [...trusted, dir] }, null, 2) + "\n", metadata ? metadata.mode & 0o777 : 0o600);
|
|
192
|
+
return "trusted";
|
|
193
|
+
}
|
|
194
|
+
throw new Error("settings.json kept changing while it was being updated");
|
|
195
|
+
}
|
|
159
196
|
/**
|
|
160
197
|
* Trusts `dir` for `harness` before a launch, when the harness has a trust
|
|
161
198
|
* screen and pre-trust is on. Never throws: a failure is logged and the
|
|
162
199
|
* launch goes on to meet the screen, which dispatch then reports.
|
|
163
200
|
*/
|
|
164
201
|
export async function pretrustFolder(harness, dir, why, env = process.env) {
|
|
165
|
-
if (harness !== "claude" && harness !== "codex")
|
|
202
|
+
if (harness !== "claude" && harness !== "codex" && harness !== "copilot")
|
|
166
203
|
return "skipped";
|
|
167
204
|
if (!pretrustEnabled(env))
|
|
168
205
|
return "skipped";
|
|
169
206
|
if (!path.isAbsolute(dir))
|
|
170
207
|
return "skipped";
|
|
171
|
-
const name = harness === "claude" ? "Claude" : "Codex";
|
|
208
|
+
const name = harness === "claude" ? "Claude" : harness === "codex" ? "Codex" : "Copilot";
|
|
172
209
|
// The same folder by the path the Hook was given and by its real path: the
|
|
173
210
|
// harness keys trust by whichever one its working directory reports.
|
|
174
211
|
const real = await realpath(dir).catch(() => undefined);
|
|
@@ -177,7 +214,8 @@ export async function pretrustFolder(harness, dir, why, env = process.env) {
|
|
|
177
214
|
let outcome = "already";
|
|
178
215
|
for (const folder of [...new Set([dir, real])]) {
|
|
179
216
|
try {
|
|
180
|
-
const result = harness === "claude" ? await ensureClaudeFolderTrusted(folder, env)
|
|
217
|
+
const result = harness === "claude" ? await ensureClaudeFolderTrusted(folder, env)
|
|
218
|
+
: harness === "codex" ? await ensureCodexDirTrusted(folder, env) : await ensureCopilotFolderTrusted(folder, env);
|
|
181
219
|
if (result === "trusted")
|
|
182
220
|
logger.info("launch", `Marked ${folder} trusted for ${name} (${why}).`);
|
|
183
221
|
else if (result === "skipped")
|
package/dist/bridge/hand-off.js
CHANGED
|
@@ -5,6 +5,7 @@ import { z } from "zod";
|
|
|
5
5
|
import { computerName } from "./computers.js";
|
|
6
6
|
import { hookRequest } from "./client.js";
|
|
7
7
|
import { projectName } from "./dispatch.js";
|
|
8
|
+
import { paneProject } from "./approval-summary.js";
|
|
8
9
|
import { isAccountSlug } from "./claude-accounts.js";
|
|
9
10
|
import { grantLabel, findGrant } from "./grants.js";
|
|
10
11
|
import { hookPeers, optionalHookPeers, peerRequest } from "./peers.js";
|
|
@@ -131,7 +132,7 @@ function sessionsFrom(overview, computer, local, now = Date.now()) {
|
|
|
131
132
|
const text = (value) => typeof value === "string" && value ? value : undefined;
|
|
132
133
|
const changedAt = typeof tab.lastChangedAt === "string" ? Date.parse(tab.lastChangedAt) : NaN;
|
|
133
134
|
// A conductor sits in the store, not a project.
|
|
134
|
-
sessions.push({ computer, local, project: tab.role === "conductor" ? undefined : text(cwd
|
|
135
|
+
sessions.push({ computer, local, project: tab.role === "conductor" ? undefined : text(paneProject(cwd)), label: text(label),
|
|
135
136
|
title: text(tab.title), agent: tab.agent, status: text(tab.agentStatus), role: text(tab.role),
|
|
136
137
|
branch: text(tab.branch), model: text(tab.model), ...(typeof object(tab.account).id === "string" ? { account: String(object(tab.account).id) } : {}), ...(target.success ? { target: target.data } : {}),
|
|
137
138
|
...(typeof tab.backgroundTasks === "number" && tab.backgroundTasks > 0 ? { backgroundTasks: tab.backgroundTasks } : {}),
|
package/dist/bridge/herdr.js
CHANGED
|
@@ -304,14 +304,14 @@ async function resolveIdentity(server, pane, fresh) {
|
|
|
304
304
|
const owned = pane.agent === "codex" && !!codexServers.forPane(server, String(pane.pane_id))?.threadId;
|
|
305
305
|
if (pane.agent !== "copilot" && !owned && reported.kind === "id" && reported.agent === pane.agent && typeof reported.value === "string" && sessionId.safeParse(reported.value).success) {
|
|
306
306
|
countIdentity("reported");
|
|
307
|
-
return { sessionId: reported.value };
|
|
307
|
+
return { sessionId: reported.value, noTranscriptLogs: false };
|
|
308
308
|
}
|
|
309
309
|
const pids = await foregroundPids(server, pane);
|
|
310
310
|
const key = identityKey(server, pane, pids);
|
|
311
311
|
const cached = identities.get(key);
|
|
312
312
|
if (!fresh && cached && Date.now() - cached.at < IDENTITY_CACHE_MS) {
|
|
313
313
|
countIdentity("cached");
|
|
314
|
-
return {
|
|
314
|
+
return { ...await cached.result, pids };
|
|
315
315
|
}
|
|
316
316
|
countIdentity(fresh ? "probe-fresh" : "probe");
|
|
317
317
|
const result = identityFromProcesses(server, pane, pids);
|
|
@@ -324,7 +324,7 @@ async function resolveIdentity(server, pane, fresh) {
|
|
|
324
324
|
// brand-new conversation it just proved as starting.
|
|
325
325
|
void result.then(() => { entry.at = Date.now(); }, () => { });
|
|
326
326
|
identities.set(key, entry);
|
|
327
|
-
return {
|
|
327
|
+
return { ...await result, pids };
|
|
328
328
|
}
|
|
329
329
|
export async function paneIdentity(server, pane, fresh = false) {
|
|
330
330
|
return (await resolveIdentity(server, pane, fresh)).sessionId;
|
|
@@ -562,8 +562,9 @@ export async function paneChatState(server, pane, options = {}) {
|
|
|
562
562
|
// An ambiguous set of open logs is not a brand-new conversation.
|
|
563
563
|
// Reuse the same two-second identity probe as context/overview polling;
|
|
564
564
|
// discovering a new chat must not run lsof again for every list refresh.
|
|
565
|
-
|
|
566
|
-
|
|
565
|
+
// Carry the evidence returned by this probe. A concurrent lookup may replace
|
|
566
|
+
// its cache entry, or a busy event loop may advance past the reuse window.
|
|
567
|
+
const starting = !sessionId && !!process && identity.noTranscriptLogs;
|
|
567
568
|
let binding = startingBindings.get(key);
|
|
568
569
|
if (process) {
|
|
569
570
|
// Lost identity, changed process, or newly ambiguous evidence requires a
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
/** The script's file name in a version's folder, beside `bridge-hook.mjs`. */
|
|
2
2
|
export declare const FAST_HOOK_FILE = "claude-hook.mjs";
|
|
3
3
|
export declare const fastHookPath: (versionDir: string) => string;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* How long a PreToolUse or PostToolUse callback may run, from its process's
|
|
6
|
+
* start. Install registers them for every tool call (Codex takes no matcher),
|
|
7
|
+
* and Codex kills a hook at 10 s: on the Mini under a load average near 130
|
|
8
|
+
* (2026-10-01) the old 8 s socket wait, after a slow start, ran past it and
|
|
9
|
+
* Codex showed "Hook failed: hook timed out after 10s" on every call. These
|
|
10
|
+
* callbacks only snapshot changed files for the phone and nothing waits on
|
|
11
|
+
* them, so once the budget is spent they give up and the tool runs.
|
|
12
|
+
*/
|
|
13
|
+
export declare const TOOL_HOOK_BUDGET_MS = 5000;
|
|
14
|
+
/** The forwarder's source, with the ToolUse budget written in. */
|
|
15
|
+
export declare const fastHookSource: (toolBudgetMs?: number) => string;
|
|
16
|
+
export declare const FAST_HOOK_SOURCE: string;
|
package/dist/bridge/hook-fast.js
CHANGED
|
@@ -15,7 +15,18 @@ import path from "node:path";
|
|
|
15
15
|
/** The script's file name in a version's folder, beside `bridge-hook.mjs`. */
|
|
16
16
|
export const FAST_HOOK_FILE = "claude-hook.mjs";
|
|
17
17
|
export const fastHookPath = (versionDir) => path.join(versionDir, FAST_HOOK_FILE);
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* How long a PreToolUse or PostToolUse callback may run, from its process's
|
|
20
|
+
* start. Install registers them for every tool call (Codex takes no matcher),
|
|
21
|
+
* and Codex kills a hook at 10 s: on the Mini under a load average near 130
|
|
22
|
+
* (2026-10-01) the old 8 s socket wait, after a slow start, ran past it and
|
|
23
|
+
* Codex showed "Hook failed: hook timed out after 10s" on every call. These
|
|
24
|
+
* callbacks only snapshot changed files for the phone and nothing waits on
|
|
25
|
+
* them, so once the budget is spent they give up and the tool runs.
|
|
26
|
+
*/
|
|
27
|
+
export const TOOL_HOOK_BUDGET_MS = 5_000;
|
|
28
|
+
/** The forwarder's source, with the ToolUse budget written in. */
|
|
29
|
+
export const fastHookSource = (toolBudgetMs = TOOL_HOOK_BUDGET_MS) => `// Installed by Phren Hook: Claude Code's hook events, forwarded to the running Hook.
|
|
19
30
|
import { request } from "node:http";
|
|
20
31
|
import { homedir } from "node:os";
|
|
21
32
|
import path from "node:path";
|
|
@@ -51,8 +62,11 @@ async function forward(place) {
|
|
|
51
62
|
tool: value.tool_name, input: value.tool_input, toolUseId: value.tool_use_id, cwd: value.cwd,
|
|
52
63
|
...(event === "UserPromptSubmit" && typeof value.prompt === "string" ? { prompt: value.prompt.slice(0, 65_536) } : {}), ...stop });
|
|
53
64
|
const socketPath = path.join(env.PHREN_BRIDGE_HOME || path.join(homedir(), ".local/share/phren/bridge"), "agent.sock");
|
|
65
|
+
// A tool call's callback fits its budget from process start, or is skipped.
|
|
66
|
+
const left = Math.floor(${toolBudgetMs} - performance.now());
|
|
67
|
+
if (event.endsWith("ToolUse") && left <= 0) return;
|
|
54
68
|
await new Promise(resolve => {
|
|
55
|
-
const req = request({ socketPath, path: "/hook", method: "POST", timeout: event === "PermissionRequest" ? 58_000 : event.endsWith("ToolUse") ?
|
|
69
|
+
const req = request({ socketPath, path: "/hook", method: "POST", timeout: event === "PermissionRequest" ? 58_000 : event.endsWith("ToolUse") ? left : 12_000,
|
|
56
70
|
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(data) } }, res => {
|
|
57
71
|
let result = "";
|
|
58
72
|
res.on("data", chunk => { result += chunk.toString(); if (result.length > 16_384) req.destroy(); });
|
|
@@ -66,3 +80,4 @@ async function forward(place) {
|
|
|
66
80
|
if (source !== "claude" || (env.HERDR_ENV !== "1" && env.TMUX)) await full().catch(() => {});
|
|
67
81
|
else if (env.HERDR_ENV === "1") { const place = herdrPane(); if (place) await forward(place).catch(() => {}); }
|
|
68
82
|
`;
|
|
83
|
+
export const FAST_HOOK_SOURCE = fastHookSource();
|
|
@@ -12,7 +12,9 @@ import { type Target } from "./protocol.js";
|
|
|
12
12
|
*
|
|
13
13
|
* OpenCode takes its brief over the HTTP API its launched TUI serves
|
|
14
14
|
* (opencode-panes.ts); the file is still written so the arrival is recorded
|
|
15
|
-
* here. Copilot
|
|
15
|
+
* here. Copilot keeps the typed path: its `-i <prompt>` would submit a first
|
|
16
|
+
* prompt, but its hooks fire SessionStart lazily and their payload was not
|
|
17
|
+
* confirmed to carry the event name, so no arrival could be recorded.
|
|
16
18
|
*/
|
|
17
19
|
/** A dispatch receipt id or a scheduled run id: what `PHREN_DISPATCH_ID` carries. */
|
|
18
20
|
export declare const briefId: z.ZodString;
|
|
@@ -15,7 +15,9 @@ import { atomic, bridgeRoot, targetSchema } from "./protocol.js";
|
|
|
15
15
|
*
|
|
16
16
|
* OpenCode takes its brief over the HTTP API its launched TUI serves
|
|
17
17
|
* (opencode-panes.ts); the file is still written so the arrival is recorded
|
|
18
|
-
* here. Copilot
|
|
18
|
+
* here. Copilot keeps the typed path: its `-i <prompt>` would submit a first
|
|
19
|
+
* prompt, but its hooks fire SessionStart lazily and their payload was not
|
|
20
|
+
* confirmed to carry the event name, so no arrival could be recorded.
|
|
19
21
|
*/
|
|
20
22
|
/** A dispatch receipt id or a scheduled run id: what `PHREN_DISPATCH_ID` carries. */
|
|
21
23
|
export const briefId = z.string().regex(/^[A-Za-z0-9_-]{8,64}$/);
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { type Json } from "./protocol.js";
|
|
2
2
|
/** The sha git gives these bytes as a blob; GitHub reports the same one. */
|
|
3
3
|
export declare function blobSha(content: Buffer): string;
|
|
4
|
+
/** Only the public repository identity reaches the phone, never credentials
|
|
5
|
+
* embedded in a remote URL or a local filesystem path. */
|
|
6
|
+
export declare function githubStoreRepository(remote: string): string | undefined;
|
|
4
7
|
/** A tree sha for the store's current working tree, written through a private index. */
|
|
5
8
|
export declare function storeHead(store: string, indexFile?: string): Promise<{
|
|
6
9
|
sha: string;
|
|
10
|
+
repositoryIdentity?: {
|
|
11
|
+
repository: string;
|
|
12
|
+
branch: string;
|
|
13
|
+
};
|
|
7
14
|
}>;
|
|
8
15
|
/** The recursive tree for a head, with the fields the phone's GitTree decodes. */
|
|
9
16
|
export declare function storeTree(store: string, sha: string): Promise<Json>;
|
|
@@ -39,6 +39,40 @@ export function blobSha(content) {
|
|
|
39
39
|
async function isRepository(store) {
|
|
40
40
|
return (await lstat(path.join(store, ".git")).catch(() => undefined)) !== undefined;
|
|
41
41
|
}
|
|
42
|
+
/** Only the public repository identity reaches the phone, never credentials
|
|
43
|
+
* embedded in a remote URL or a local filesystem path. */
|
|
44
|
+
export function githubStoreRepository(remote) {
|
|
45
|
+
let host, pathname;
|
|
46
|
+
const scp = /^(?:[^@/\s]+@)?github\.com:([^\s]+)$/i.exec(remote.trim());
|
|
47
|
+
if (scp) {
|
|
48
|
+
host = "github.com";
|
|
49
|
+
pathname = scp[1];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
try {
|
|
53
|
+
const url = new URL(remote.trim());
|
|
54
|
+
if (!["https:", "ssh:"].includes(url.protocol) || url.search || url.hash)
|
|
55
|
+
return undefined;
|
|
56
|
+
host = url.hostname;
|
|
57
|
+
pathname = url.pathname.replace(/^\//, "");
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (host.toLowerCase() !== "github.com")
|
|
64
|
+
return undefined;
|
|
65
|
+
const repository = pathname.replace(/\/$/, "").replace(/\.git$/i, "");
|
|
66
|
+
return /^[A-Za-z0-9][A-Za-z0-9-]*\/[A-Za-z0-9_.-]+$/.test(repository) ? repository.toLowerCase() : undefined;
|
|
67
|
+
}
|
|
68
|
+
async function storeRepositoryIdentity(store) {
|
|
69
|
+
const [remote, branch] = await Promise.all([
|
|
70
|
+
git(store, ["config", "--get", "remote.origin.url"]).catch(() => ""),
|
|
71
|
+
git(store, ["symbolic-ref", "--quiet", "--short", "HEAD"]).catch(() => ""),
|
|
72
|
+
]);
|
|
73
|
+
const repository = githubStoreRepository(remote);
|
|
74
|
+
return repository && branch.trim() ? { repository, branch: branch.trim() } : undefined;
|
|
75
|
+
}
|
|
42
76
|
/** A tree sha for the store's current working tree, written through a private index. */
|
|
43
77
|
export function storeHead(store, indexFile = path.join(bridgeRoot(), "store-snapshot.index")) {
|
|
44
78
|
return serialized(async () => {
|
|
@@ -51,7 +85,9 @@ export function storeHead(store, indexFile = path.join(bridgeRoot(), "store-snap
|
|
|
51
85
|
await git(store, head.trim() ? ["read-tree", "HEAD"] : ["read-tree", "--empty"], env);
|
|
52
86
|
}
|
|
53
87
|
await git(store, ["add", "--all", "--", "."], env);
|
|
54
|
-
|
|
88
|
+
const sha = (await git(store, ["write-tree"], env)).trim();
|
|
89
|
+
const repositoryIdentity = await storeRepositoryIdentity(store);
|
|
90
|
+
return { sha, ...(repositoryIdentity ? { repositoryIdentity } : {}) };
|
|
55
91
|
});
|
|
56
92
|
}
|
|
57
93
|
/** The recursive tree for a head, with the fields the phone's GitTree decodes. */
|
package/dist/bridge/models.d.ts
CHANGED
|
@@ -33,6 +33,15 @@ export declare function readClaudeModels(configDir?: string, installed?: string
|
|
|
33
33
|
* models sit under `opencode-go/`, Zen's under `opencode/`, and everything
|
|
34
34
|
* else under the gateway it came from; the configured default is marked. */
|
|
35
35
|
export declare function readOpenCodeModels(executable?: string, configDir?: string): Promise<AgentModel[]>;
|
|
36
|
+
/** phren agent's catalog (`phren-agent models --json`): only providers with
|
|
37
|
+
* credentials on this computer, ids as `<provider>/<model>`, the
|
|
38
|
+
* auto-detected default marked. The agent package next to this CLI (or this
|
|
39
|
+
* checkout's) runs under this Node; otherwise `phren-agent` on PATH. Never the
|
|
40
|
+
* npm global lookup, which blocks. */
|
|
41
|
+
export declare function readPhrenModels(command?: {
|
|
42
|
+
file: string;
|
|
43
|
+
args: string[];
|
|
44
|
+
}): Promise<AgentModel[]>;
|
|
36
45
|
/** "claude-fable-5-1" reads as "Fable 5.1"; a date suffix is dropped. */
|
|
37
46
|
export declare function claudeName(id: string): string;
|
|
38
47
|
/** The account a request names is not one on this computer (or has no catalogue for that source). */
|
|
@@ -44,7 +53,8 @@ export declare class ModelCatalog {
|
|
|
44
53
|
private readonly claude;
|
|
45
54
|
private readonly opencode;
|
|
46
55
|
private readonly cacheMs;
|
|
56
|
+
private readonly phren;
|
|
47
57
|
private cache;
|
|
48
|
-
constructor(codex?: () => Promise<AgentModel[]>, claude?: (configDir?: string) => Promise<AgentModel[]>, opencode?: () => Promise<AgentModel[]>, cacheMs?: number);
|
|
58
|
+
constructor(codex?: () => Promise<AgentModel[]>, claude?: (configDir?: string) => Promise<AgentModel[]>, opencode?: () => Promise<AgentModel[]>, cacheMs?: number, phren?: () => Promise<AgentModel[]>);
|
|
49
59
|
list(source: string, account?: string): Promise<AgentModel[]>;
|
|
50
60
|
}
|
package/dist/bridge/models.js
CHANGED
|
@@ -230,6 +230,49 @@ export async function readOpenCodeModels(executable = "opencode", configDir = pa
|
|
|
230
230
|
return { id, name, description, ...(id === configured ? { isDefault: true } : {}) };
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
|
+
/** phren agent's catalog (`phren-agent models --json`): only providers with
|
|
234
|
+
* credentials on this computer, ids as `<provider>/<model>`, the
|
|
235
|
+
* auto-detected default marked. The agent package next to this CLI (or this
|
|
236
|
+
* checkout's) runs under this Node; otherwise `phren-agent` on PATH. Never the
|
|
237
|
+
* npm global lookup, which blocks. */
|
|
238
|
+
export async function readPhrenModels(command) {
|
|
239
|
+
const found = command ? undefined : (await import("../modules/agent-package.js")).findAgentPackage({ global: false });
|
|
240
|
+
const run = command ?? (found ? { file: process.execPath, args: [found.bin, "models", "--json"] } : { file: "phren-agent", args: ["models", "--json"] });
|
|
241
|
+
const listed = await new Promise(resolve => {
|
|
242
|
+
const child = spawn(run.file, run.args, { cwd: homedir(), stdio: ["ignore", "pipe", "ignore"] });
|
|
243
|
+
let out = "", done = false;
|
|
244
|
+
const finish = () => { if (!done) {
|
|
245
|
+
done = true;
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
resolve(out);
|
|
248
|
+
} };
|
|
249
|
+
const timer = setTimeout(() => { child.kill("SIGTERM"); finish(); }, 12_000);
|
|
250
|
+
child.stdout.setEncoding("utf8");
|
|
251
|
+
child.stdout.on("data", (chunk) => { if (out.length < 262_144)
|
|
252
|
+
out += chunk; });
|
|
253
|
+
child.on("error", finish);
|
|
254
|
+
child.on("close", finish);
|
|
255
|
+
});
|
|
256
|
+
let rows;
|
|
257
|
+
try {
|
|
258
|
+
rows = objects(object(JSON.parse(listed)).models);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
const text = (value, max) => typeof value === "string" && value.trim() && !/[\x00-\x1f\x7f]/.test(value) ? value.trim().slice(0, max) : undefined;
|
|
264
|
+
const models = [];
|
|
265
|
+
for (const row of rows.slice(0, 200)) {
|
|
266
|
+
const id = text(row.id, 200), name = text(row.name, 120);
|
|
267
|
+
if (!id || !name || !/^[a-z0-9-]+\/\S+$/.test(id))
|
|
268
|
+
continue;
|
|
269
|
+
const description = text(row.description, 120), effort = text(row.defaultReasoningEffort, 20);
|
|
270
|
+
const efforts = Array.isArray(row.supportedReasoningEfforts) ? row.supportedReasoningEfforts.map(value => text(value, 20)).filter((value) => !!value) : [];
|
|
271
|
+
models.push({ id, name, ...(description ? { description } : {}), ...(row.isDefault === true ? { isDefault: true } : {}),
|
|
272
|
+
...(effort ? { defaultReasoningEffort: effort } : {}), ...(efforts.length ? { supportedReasoningEfforts: efforts } : {}) });
|
|
273
|
+
}
|
|
274
|
+
return models;
|
|
275
|
+
}
|
|
233
276
|
/** "claude-fable-5-1" reads as "Fable 5.1"; a date suffix is dropped. */
|
|
234
277
|
export function claudeName(id) {
|
|
235
278
|
const parts = id.replace(/^claude-/, "").replace(/-\d{8}$/, "").replace(/\[1m\]$/, "").split("-");
|
|
@@ -247,12 +290,14 @@ export class ModelCatalog {
|
|
|
247
290
|
claude;
|
|
248
291
|
opencode;
|
|
249
292
|
cacheMs;
|
|
293
|
+
phren;
|
|
250
294
|
cache = new Map();
|
|
251
|
-
constructor(codex = () => readCodexModels(), claude = dir => readClaudeModels(dir), opencode = () => readOpenCodeModels(), cacheMs = 600_000) {
|
|
295
|
+
constructor(codex = () => readCodexModels(), claude = dir => readClaudeModels(dir), opencode = () => readOpenCodeModels(), cacheMs = 600_000, phren = () => readPhrenModels()) {
|
|
252
296
|
this.codex = codex;
|
|
253
297
|
this.claude = claude;
|
|
254
298
|
this.opencode = opencode;
|
|
255
299
|
this.cacheMs = cacheMs;
|
|
300
|
+
this.phren = phren;
|
|
256
301
|
}
|
|
257
302
|
list(source, account) {
|
|
258
303
|
const id = account?.trim() || DEFAULT_ACCOUNT;
|
|
@@ -268,7 +313,7 @@ export class ModelCatalog {
|
|
|
268
313
|
const key = `${source}:${id}`, cached = this.cache.get(key);
|
|
269
314
|
if (cached && Date.now() - cached.at < this.cacheMs)
|
|
270
315
|
return cached.value;
|
|
271
|
-
const value = (source === "codex" ? this.codex() : source === "claude" ? this.claude(dir) : source === "opencode" ? this.opencode() : Promise.resolve([])).catch(() => []);
|
|
316
|
+
const value = (source === "codex" ? this.codex() : source === "claude" ? this.claude(dir) : source === "opencode" ? this.opencode() : source === "phren" ? this.phren() : Promise.resolve([])).catch(() => []);
|
|
272
317
|
this.cache.set(key, { at: Date.now(), value });
|
|
273
318
|
return value;
|
|
274
319
|
}
|
|
@@ -2,7 +2,7 @@ import type { SchedulePush, SchedulePushResult } from "./push.js";
|
|
|
2
2
|
/** The schedules.yaml store: the schedule and run record shapes, validation,
|
|
3
3
|
* the five timing forms evaluated in local time, and the run history file. */
|
|
4
4
|
export declare const SCHEDULE_EVERY: readonly ["interval", "daily", "weekly", "once", "cron"];
|
|
5
|
-
export declare const SCHEDULE_HARNESSES: readonly ["claude", "codex", "opencode"];
|
|
5
|
+
export declare const SCHEDULE_HARNESSES: readonly ["claude", "codex", "opencode", "copilot"];
|
|
6
6
|
export declare const SCHEDULE_NOTIFY: readonly ["start", "finish", "failure"];
|
|
7
7
|
export declare const WEEKDAYS: readonly ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
8
8
|
export type ScheduleEvery = typeof SCHEDULE_EVERY[number];
|
|
@@ -8,7 +8,7 @@ import { isAccountSlug } from "./claude-accounts.js";
|
|
|
8
8
|
/** The schedules.yaml store: the schedule and run record shapes, validation,
|
|
9
9
|
* the five timing forms evaluated in local time, and the run history file. */
|
|
10
10
|
export const SCHEDULE_EVERY = ["interval", "daily", "weekly", "once", "cron"];
|
|
11
|
-
export const SCHEDULE_HARNESSES = ["claude", "codex", "opencode"];
|
|
11
|
+
export const SCHEDULE_HARNESSES = ["claude", "codex", "opencode", "copilot"];
|
|
12
12
|
export const SCHEDULE_NOTIFY = ["start", "finish", "failure"];
|
|
13
13
|
export const WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
14
14
|
export const SCHEDULE_RUN_STATUSES = ["launched", "running", "blocked", "finished", "needs-you", "failed", "skipped"];
|
|
@@ -162,6 +162,11 @@ export function headlessCommand(schedule, cwd) {
|
|
|
162
162
|
"--skip-git-repo-check", "--json", "-"] };
|
|
163
163
|
if (schedule.harness === "opencode")
|
|
164
164
|
return { file: "opencode", cwd, args: ["run", "--format", "json", "--dir", cwd, ...model] };
|
|
165
|
+
// Copilot's non-interactive mode needs every tool allowed up front; file
|
|
166
|
+
// access stays inside the working folder. `=` keeps a prompt that starts
|
|
167
|
+
// with "-" from reading as a flag.
|
|
168
|
+
if (schedule.harness === "copilot")
|
|
169
|
+
return { file: "copilot", cwd, args: [`--prompt=${schedule.prompt}`, "--allow-all-tools", "--output-format", "json", ...model] };
|
|
165
170
|
return { file: "claude", cwd, args: ["-p", "--output-format", "stream-json", "--settings", CLAUDE_SCHEDULE_SETTINGS, ...model] };
|
|
166
171
|
}
|
|
167
172
|
async function writeManifest(jobDir, manifest) {
|
|
@@ -38,8 +38,10 @@ export interface StartupWatchEnv {
|
|
|
38
38
|
* `finishedTasks`: when each Claude background task the tail shows finishing
|
|
39
39
|
* finished (its first final task-notification's timestamp), one per task.
|
|
40
40
|
* `awaited`: those of the running tasks that are shells or monitors started
|
|
41
|
-
* since the owner's last prompt,
|
|
42
|
-
*
|
|
41
|
+
* since the owner's last prompt, or started before it and looked at since
|
|
42
|
+
* (its output read, its id named), other than streams that never end (a log
|
|
43
|
+
* tail, a watcher, a dev server). Sub-agents are left to the child tree.
|
|
44
|
+
* `endless`: the running shells that are such streams. */
|
|
43
45
|
export interface FinalTurn {
|
|
44
46
|
completed: boolean;
|
|
45
47
|
lastAssistant?: string;
|
|
@@ -48,6 +50,7 @@ export interface FinalTurn {
|
|
|
48
50
|
background?: number;
|
|
49
51
|
finishedTasks?: string[];
|
|
50
52
|
awaited?: number;
|
|
53
|
+
endless?: number;
|
|
51
54
|
}
|
|
52
55
|
/** The public text of one assistant row, without reasoning or tool output. */
|
|
53
56
|
export declare function publicAssistant(raw: Json, source: Provider): string | undefined;
|