@phren/cli 0.3.15 → 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.
Files changed (41) hide show
  1. package/dist/bridge/agent-hooks.d.ts +10 -0
  2. package/dist/bridge/agent-hooks.js +49 -10
  3. package/dist/bridge/claude-suggestion.d.ts +8 -0
  4. package/dist/bridge/claude-suggestion.js +71 -0
  5. package/dist/bridge/dispatch-returns.d.ts +6 -3
  6. package/dist/bridge/dispatch-returns.js +29 -17
  7. package/dist/bridge/job-registry.d.ts +144 -0
  8. package/dist/bridge/job-registry.js +247 -0
  9. package/dist/bridge/opencode-permissions.d.ts +17 -0
  10. package/dist/bridge/opencode-permissions.js +96 -0
  11. package/dist/bridge/protocol.d.ts +4 -0
  12. package/dist/bridge/protocol.js +3 -0
  13. package/dist/bridge/resources.d.ts +38 -5
  14. package/dist/bridge/resources.js +110 -19
  15. package/dist/bridge/server-launch.js +8 -0
  16. package/dist/bridge/server-routes.d.ts +1 -1
  17. package/dist/bridge/server-routes.js +8 -6
  18. package/dist/bridge/server-stream.js +11 -2
  19. package/dist/bridge/session-activity.d.ts +13 -0
  20. package/dist/bridge/session-activity.js +27 -2
  21. package/dist/bridge/settings-switch.d.ts +12 -2
  22. package/dist/bridge/settings-switch.js +13 -6
  23. package/dist/bridge/speech.d.ts +6 -4
  24. package/dist/bridge/speech.js +6 -4
  25. package/dist/bridge/terminal-tmux.d.ts +4 -2
  26. package/dist/bridge/terminal-tmux.js +13 -7
  27. package/dist/bridge/transcript-claude.d.ts +9 -1
  28. package/dist/bridge/transcript-claude.js +50 -1
  29. package/dist/bridge/transcript-codex.js +23 -3
  30. package/dist/bridge/transcripts.d.ts +5 -1
  31. package/dist/bridge/transcripts.js +21 -5
  32. package/dist/bridge-hook.mjs +1046 -530
  33. package/dist/computers/command.js +2 -1
  34. package/dist/fanout/opencode-serve.js +3 -2
  35. package/dist/hooks.d.ts +3 -0
  36. package/dist/hooks.js +41 -6
  37. package/dist/init/setup.js +6 -3
  38. package/dist/modules/registry.js +1 -1
  39. package/dist/tools/dispatch.js +3 -2
  40. package/package.json +1 -1
  41. 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 pane = job.pane ? ` ${[job.pane.workspace, job.pane.pane, job.pane.agent].filter(Boolean).join(" · ")}` : "";
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
- : { reply: "reject", message: decision === "deny" ? DENIED_FEEDBACK : UNANSWERED_FEEDBACK });
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
- return true;
45
+ found = true;
23
46
  }
24
47
  catch (err) {
25
48
  debugLog(`commandExists: ${cmd} not found: ${errorMessage(err)}`);
26
- return false;
49
+ found = false;
27
50
  }
51
+ cache.set(cmd, { found, at: Date.now() });
52
+ return found;
28
53
  }
29
- export function detectInstalledTools() {
30
- const tools = new Set();
31
- if (commandExists("copilot")
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";
@@ -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 { detectInstalledTools } from "../hooks.js";
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 (detectInstalledTools().has("copilot")) {
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
- const nodeVersion = commandVersion("node");
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),
@@ -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
  ],
@@ -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(["approve", "deny"]),
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 === "approve" ? "Approved." : "Denied." });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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
  },