@phren/cli 0.3.16 → 0.3.17
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 +10 -0
- package/dist/bridge/agent-hooks.js +49 -10
- package/dist/bridge/claude-suggestion.d.ts +8 -0
- package/dist/bridge/claude-suggestion.js +71 -0
- package/dist/bridge/dispatch-returns.d.ts +6 -3
- package/dist/bridge/dispatch-returns.js +29 -17
- package/dist/bridge/job-registry.d.ts +144 -0
- package/dist/bridge/job-registry.js +247 -0
- package/dist/bridge/opencode-permissions.d.ts +17 -0
- package/dist/bridge/opencode-permissions.js +96 -0
- package/dist/bridge/protocol.d.ts +4 -0
- package/dist/bridge/protocol.js +3 -0
- package/dist/bridge/resources.d.ts +38 -5
- package/dist/bridge/resources.js +110 -19
- package/dist/bridge/server-launch.js +8 -0
- package/dist/bridge/server-routes.d.ts +1 -1
- package/dist/bridge/server-routes.js +8 -6
- package/dist/bridge/server-stream.js +11 -2
- package/dist/bridge/session-activity.d.ts +13 -0
- package/dist/bridge/session-activity.js +27 -2
- package/dist/bridge/settings-switch.d.ts +12 -2
- package/dist/bridge/settings-switch.js +13 -6
- package/dist/bridge/speech.d.ts +6 -4
- package/dist/bridge/speech.js +6 -4
- package/dist/bridge/terminal-tmux.d.ts +4 -2
- package/dist/bridge/terminal-tmux.js +13 -7
- package/dist/bridge/transcript-claude.d.ts +9 -1
- package/dist/bridge/transcript-claude.js +50 -1
- package/dist/bridge/transcript-codex.js +23 -3
- package/dist/bridge/transcripts.d.ts +5 -1
- package/dist/bridge/transcripts.js +13 -3
- package/dist/bridge-hook.mjs +1044 -528
- package/dist/computers/command.js +2 -1
- package/dist/fanout/opencode-serve.js +3 -2
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +41 -6
- package/dist/init/setup.js +6 -3
- package/dist/modules/registry.js +1 -1
- package/dist/tools/dispatch.js +3 -2
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +4 -4
|
@@ -37,7 +37,8 @@ export function formatResources(name, r, detail) {
|
|
|
37
37
|
if (heavy.length)
|
|
38
38
|
lines.push(" heavy");
|
|
39
39
|
for (const job of heavy) {
|
|
40
|
-
const
|
|
40
|
+
const owner = job.pane ? [job.pane.workspace, job.pane.pane, job.pane.agent ?? job.agent].filter(Boolean).join(" · ") : job.agent;
|
|
41
|
+
const pane = owner ? ` ${owner}` : "";
|
|
41
42
|
lines.push(` ${job.name.padEnd(22)} ${String(job.cpuPercent).padStart(6)}% cpu ${(job.memoryBytes / GB).toFixed(1).padStart(5)} GB${job.processes > 1 ? ` ×${job.processes}` : ""}${pane}`);
|
|
42
43
|
}
|
|
43
44
|
if (!detail && r.heavy.length > heavy.length)
|
|
@@ -85,7 +85,8 @@ export async function driveOpencode(child, o) {
|
|
|
85
85
|
return;
|
|
86
86
|
line("phren/permission", { permission: asked.permission, patterns: asked.patterns, decision });
|
|
87
87
|
await call("POST", `/permission/${encodeURIComponent(asked.id)}/reply`, decision === "approve" ? { reply: "once" }
|
|
88
|
-
:
|
|
88
|
+
: decision === "always" ? { reply: "always" }
|
|
89
|
+
: { reply: "reject", message: decision === "deny" ? DENIED_FEEDBACK : UNANSWERED_FEEDBACK });
|
|
89
90
|
};
|
|
90
91
|
const reader = events.body.getReader(), decoder = new TextDecoder();
|
|
91
92
|
let pending = "";
|
|
@@ -177,7 +178,7 @@ async function relay(o, session, asked, signal) {
|
|
|
177
178
|
return "stopped";
|
|
178
179
|
try {
|
|
179
180
|
const value = JSON.parse(fs.readFileSync(answer, "utf8"));
|
|
180
|
-
if (value.id === asked.id && (value.decision === "approve" || value.decision === "deny"))
|
|
181
|
+
if (value.id === asked.id && (value.decision === "approve" || value.decision === "deny" || value.decision === "always"))
|
|
181
182
|
return value.decision;
|
|
182
183
|
}
|
|
183
184
|
catch { /* Not answered yet. */ }
|
package/dist/hooks.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export interface HookError {
|
|
|
4
4
|
message: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function commandExists(cmd: string): boolean;
|
|
7
|
+
/** Whether the GitHub Copilot CLI is present. Cheaper than
|
|
8
|
+
* `detectInstalledTools()` for the one call site that only needs copilot. */
|
|
9
|
+
export declare function isCopilotInstalled(): boolean;
|
|
7
10
|
export declare function detectInstalledTools(): Set<string>;
|
|
8
11
|
/**
|
|
9
12
|
* True if a path lives inside an ephemeral npx download cache
|
package/dist/hooks.js
CHANGED
|
@@ -15,23 +15,53 @@ import { resolveManagementCapabilities } from "./init/management-preset.js";
|
|
|
15
15
|
// Dependency-free leaf module — hooks.ts runs in a per-PostToolUse subprocess
|
|
16
16
|
// and must not pull in content/dedup.ts's import graph.
|
|
17
17
|
import { redactSecretsForLog } from "./content/secrets.js";
|
|
18
|
+
// Tool probes (`which`/`where.exe`) are deterministic for a given PATH but run
|
|
19
|
+
// several times for the same command during one `phren init`. On POSIX a spawn
|
|
20
|
+
// is cheap; on Windows every `where.exe` is a full process creation, and init
|
|
21
|
+
// already spawns git and node. Cache results and key the cache on PATH so a
|
|
22
|
+
// caller (or a test) that edits PATH still gets a fresh probe.
|
|
23
|
+
// Entries also expire: the MCP server and the Hook are long-lived, and a tool
|
|
24
|
+
// installed after a probe must show up without a restart.
|
|
25
|
+
const COMMAND_EXISTS_TTL_MS = 60_000;
|
|
26
|
+
let commandExistsPath;
|
|
27
|
+
const commandExistsCache = new Map();
|
|
28
|
+
function commandExistsCacheForCurrentPath() {
|
|
29
|
+
const path = process.env.PATH ?? "";
|
|
30
|
+
if (commandExistsPath !== path) {
|
|
31
|
+
commandExistsCache.clear();
|
|
32
|
+
commandExistsPath = path;
|
|
33
|
+
}
|
|
34
|
+
return commandExistsCache;
|
|
35
|
+
}
|
|
18
36
|
export function commandExists(cmd) {
|
|
37
|
+
const cache = commandExistsCacheForCurrentPath();
|
|
38
|
+
const cached = cache.get(cmd);
|
|
39
|
+
if (cached && Date.now() - cached.at < COMMAND_EXISTS_TTL_MS)
|
|
40
|
+
return cached.found;
|
|
41
|
+
let found;
|
|
19
42
|
try {
|
|
20
43
|
const whichCmd = process.platform === "win32" ? "where.exe" : "which";
|
|
21
44
|
execFileSync(whichCmd, [cmd], { stdio: ["ignore", "ignore", "ignore"], timeout: EXEC_TIMEOUT_QUICK_MS });
|
|
22
|
-
|
|
45
|
+
found = true;
|
|
23
46
|
}
|
|
24
47
|
catch (err) {
|
|
25
48
|
debugLog(`commandExists: ${cmd} not found: ${errorMessage(err)}`);
|
|
26
|
-
|
|
49
|
+
found = false;
|
|
27
50
|
}
|
|
51
|
+
cache.set(cmd, { found, at: Date.now() });
|
|
52
|
+
return found;
|
|
28
53
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
54
|
+
/** Whether the GitHub Copilot CLI is present. Cheaper than
|
|
55
|
+
* `detectInstalledTools()` for the one call site that only needs copilot. */
|
|
56
|
+
export function isCopilotInstalled() {
|
|
57
|
+
return (commandExists("copilot")
|
|
32
58
|
|| commandExists("github-copilot-cli")
|
|
33
59
|
|| fs.existsSync(homePath(".local", "share", "gh", "extensions", "gh-copilot"))
|
|
34
|
-
|| fs.existsSync(homePath(".copilot", "config.json")))
|
|
60
|
+
|| fs.existsSync(homePath(".copilot", "config.json")));
|
|
61
|
+
}
|
|
62
|
+
export function detectInstalledTools() {
|
|
63
|
+
const tools = new Set();
|
|
64
|
+
if (isCopilotInstalled()) {
|
|
35
65
|
tools.add("copilot");
|
|
36
66
|
}
|
|
37
67
|
if (commandExists("cursor")) {
|
|
@@ -43,6 +73,11 @@ export function detectInstalledTools() {
|
|
|
43
73
|
return tools;
|
|
44
74
|
}
|
|
45
75
|
function resolveToolBinary(tool) {
|
|
76
|
+
// The probe above already established presence; skip the extra `which -a` /
|
|
77
|
+
// `where` spawn (and its null result) when the tool is not installed. The
|
|
78
|
+
// cache makes this check free at sites that probed the tool already.
|
|
79
|
+
if (!commandExists(tool))
|
|
80
|
+
return null;
|
|
46
81
|
try {
|
|
47
82
|
const wrapperPath = path.resolve(homePath(".local", "bin", tool));
|
|
48
83
|
const whichCmd = process.platform === "win32" ? "where.exe" : "which";
|
package/dist/init/setup.js
CHANGED
|
@@ -24,7 +24,7 @@ import { getManagementPreset, resolveManagementCapabilities, } from "./managemen
|
|
|
24
24
|
import { TASKS_FILENAME } from "../data/tasks.js";
|
|
25
25
|
import { writeSkillMd } from "../link/skills.js";
|
|
26
26
|
import { syncScopeSkillsToDir } from "../skill/files.js";
|
|
27
|
-
import {
|
|
27
|
+
import { isCopilotInstalled } from "../hooks.js";
|
|
28
28
|
import { logger } from "../logger.js";
|
|
29
29
|
import { migrateStoreAgentInstructions } from "../agent-instructions.js";
|
|
30
30
|
import { bootstrapFromExisting, ensureProjectScaffold, inferInitScaffoldFromRepo, } from "../core/project-registry.js";
|
|
@@ -271,7 +271,7 @@ function ensureGeneratedSkillArtifacts(phrenPath, preferredHome) {
|
|
|
271
271
|
}
|
|
272
272
|
const copilotSkillsDir = path.join(preferredHome, ".copilot", "skills");
|
|
273
273
|
const hadCopilotSkillsDir = fs.existsSync(copilotSkillsDir);
|
|
274
|
-
if (
|
|
274
|
+
if (isCopilotInstalled()) {
|
|
275
275
|
try {
|
|
276
276
|
syncScopeSkillsToDir(phrenPath, "global", copilotSkillsDir);
|
|
277
277
|
if (!hadCopilotSkillsDir && fs.existsSync(copilotSkillsDir))
|
|
@@ -825,7 +825,10 @@ export function runPostInitVerify(phrenPath) {
|
|
|
825
825
|
const prefs = readInstallPreferences(phrenPath);
|
|
826
826
|
const manifest = readRootManifest(phrenPath);
|
|
827
827
|
const gitVersion = commandVersion("git");
|
|
828
|
-
|
|
828
|
+
// The CLI is running on the node we are checking, so read the version in
|
|
829
|
+
// process instead of paying for another `node --version` spawn (expensive on
|
|
830
|
+
// Windows, and init already runs enough processes).
|
|
831
|
+
const nodeVersion = process.version;
|
|
829
832
|
checks.push({
|
|
830
833
|
name: "git-installed",
|
|
831
834
|
ok: Boolean(gitVersion),
|
package/dist/modules/registry.js
CHANGED
|
@@ -89,7 +89,7 @@ export const BUILTIN_MODULES = [
|
|
|
89
89
|
"/v1/workspaces/launch", "/v1/workspaces/create", "/v1/workspaces/focus", "/v1/workspaces/rename",
|
|
90
90
|
"/v1/workspaces/close", "/v1/sessions/rename", "/v1/prompt", "/v1/prompt/status", "/v1/model", "/v1/settings", "/v1/side-question/dismiss", "/v1/keys", "/v1/secret", "/v1/upload",
|
|
91
91
|
"/v1/approvals/answer", "/v1/questions/answer", "/v1/subagents/resume", "/v1/subagents/archive-finished", "/v1/canary",
|
|
92
|
-
"/v1/speech", "/v1/sudo/answer",
|
|
92
|
+
"/v1/speech", "/v1/sudo/answer", "/v1/jobs/cleanup",
|
|
93
93
|
]),
|
|
94
94
|
...routes("WS", ["/v1/transcripts", "/v1/status", "/v1/overview", "/v1/speech/transcribe"]),
|
|
95
95
|
],
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -6,6 +6,7 @@ import { dispatchSchema } from "../bridge/dispatch.js";
|
|
|
6
6
|
import { handOff, handOffSchema, listLiveSessions } from "../bridge/hand-off.js";
|
|
7
7
|
import { readAccountUsage, usageSummary } from "../bridge/account-usage.js";
|
|
8
8
|
import { terminalPaneFromEnv } from "../bridge/terminal.js";
|
|
9
|
+
import { approvalDecisions } from "../bridge/protocol.js";
|
|
9
10
|
import { mcpResponse } from "./types.js";
|
|
10
11
|
export function register(server) {
|
|
11
12
|
server.registerTool("dispatch", {
|
|
@@ -72,14 +73,14 @@ export function register(server) {
|
|
|
72
73
|
description: "Answer the permission request a dispatched worker is waiting on, forwarded from its computer: a dispatch_returns row with an approval field names it. The owner's standing grants already answer the dispatch and hand_off requests they cover. Only the agent that dispatched the worker can answer, never the worker itself. Pass the approval's actionId, so a request that changed since you read it is never answered blind. Deny when unsure and ask the owner.",
|
|
73
74
|
inputSchema: {
|
|
74
75
|
id: z.string().uuid().describe("Dispatch id from dispatch_returns."),
|
|
75
|
-
decision: z.enum(
|
|
76
|
+
decision: z.enum(approvalDecisions),
|
|
76
77
|
actionId: z.string().min(1).max(200).describe("The approval's actionId from dispatch_returns; a request that has since changed is refused."),
|
|
77
78
|
},
|
|
78
79
|
}, async (input) => {
|
|
79
80
|
try {
|
|
80
81
|
const origin = await terminalPaneFromEnv();
|
|
81
82
|
const result = await hookRequest("/v1/dispatch/approve", { ...input, ...(origin ? { origin } : {}) });
|
|
82
|
-
return mcpResponse({ ok: result.ok === true, data: result, message: input.decision === "
|
|
83
|
+
return mcpResponse({ ok: result.ok === true, data: result, message: input.decision === "deny" ? "Denied." : "Approved." });
|
|
83
84
|
}
|
|
84
85
|
catch (error) {
|
|
85
86
|
return mcpResponse({ ok: false, error: error instanceof Error ? error.message : "Could not answer the approval." });
|
package/package.json
CHANGED
|
@@ -321,12 +321,12 @@ export const PhrenTranscriptPlugin = async input => {
|
|
|
321
321
|
const info = lstatSync(answer);
|
|
322
322
|
if (!info.isFile() || info.size > 65_536) continue;
|
|
323
323
|
const value = JSON.parse(readFileSync(answer, "utf8"));
|
|
324
|
-
if (value && value.id === id && (value.decision === "approve" || value.decision === "deny")) { decision = value.decision; break; }
|
|
324
|
+
if (value && value.id === id && (value.decision === "approve" || value.decision === "deny" || value.decision === "always")) { decision = value.decision; break; }
|
|
325
325
|
} catch {}
|
|
326
326
|
}
|
|
327
327
|
if (decision && !state.done) {
|
|
328
328
|
await client.postSessionIdPermissionsPermissionId({ path: { id: sessionID, permissionID: id },
|
|
329
|
-
body: { response: decision === "approve" ? "once" : "reject" } });
|
|
329
|
+
body: { response: decision === "approve" ? "once" : decision === "always" ? "always" : "reject" } });
|
|
330
330
|
}
|
|
331
331
|
} catch {} finally {
|
|
332
332
|
removeFile(answer); removeFile(request);
|
|
@@ -452,7 +452,7 @@ export const PhrenTranscriptPlugin = async input => {
|
|
|
452
452
|
if (value && value.id === id) { decision = value.decision; break; }
|
|
453
453
|
} catch {}
|
|
454
454
|
}
|
|
455
|
-
setStatus(output, decision === "approve" ? "allow" : decision === "deny" ? "deny" : "ask");
|
|
455
|
+
setStatus(output, decision === "approve" || decision === "always" ? "allow" : decision === "deny" ? "deny" : "ask");
|
|
456
456
|
} catch {
|
|
457
457
|
setStatus(output, "ask");
|
|
458
458
|
} finally {
|
|
@@ -460,7 +460,7 @@ export const PhrenTranscriptPlugin = async input => {
|
|
|
460
460
|
if (request) removeFile(request);
|
|
461
461
|
if (pendingSession) pendingApprovals.delete(pendingSession);
|
|
462
462
|
// Answered from the phone: back to work. Otherwise the terminal asks.
|
|
463
|
-
if (askId && (decision === "approve" || decision === "deny")) { asking.delete(askId); recordStatus("working", pendingSession); }
|
|
463
|
+
if (askId && (decision === "approve" || decision === "deny" || decision === "always")) { asking.delete(askId); recordStatus("working", pendingSession); }
|
|
464
464
|
if (askId) hookAsks.delete(askId);
|
|
465
465
|
}
|
|
466
466
|
},
|