@phren/cli 0.3.4 → 0.3.6

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 (79) hide show
  1. package/dist/bridge/agent-hooks.d.ts +6 -0
  2. package/dist/bridge/agent-hooks.js +63 -23
  3. package/dist/bridge/canary.d.ts +4 -0
  4. package/dist/bridge/canary.js +17 -4
  5. package/dist/bridge/changes.d.ts +7 -0
  6. package/dist/bridge/changes.js +6 -1
  7. package/dist/bridge/client.js +2 -1
  8. package/dist/bridge/command.js +7 -5
  9. package/dist/bridge/conductor-group.d.ts +1 -0
  10. package/dist/bridge/conductor-group.js +4 -3
  11. package/dist/bridge/dispatch-command.js +2 -2
  12. package/dist/bridge/fanouts.js +6 -2
  13. package/dist/bridge/hand-off.d.ts +1 -0
  14. package/dist/bridge/hand-off.js +3 -2
  15. package/dist/bridge/harness-status.d.ts +12 -0
  16. package/dist/bridge/harness-status.js +153 -0
  17. package/dist/bridge/health.d.ts +18 -0
  18. package/dist/bridge/health.js +30 -4
  19. package/dist/bridge/herdr.d.ts +6 -0
  20. package/dist/bridge/herdr.js +62 -8
  21. package/dist/bridge/install.js +4 -0
  22. package/dist/bridge/model-switch.js +5 -4
  23. package/dist/bridge/models.js +3 -2
  24. package/dist/bridge/pane-status.d.ts +37 -0
  25. package/dist/bridge/pane-status.js +139 -0
  26. package/dist/bridge/pane-text.d.ts +3 -11
  27. package/dist/bridge/pane-text.js +9 -16
  28. package/dist/bridge/peers.js +9 -6
  29. package/dist/bridge/prompt-once.d.ts +26 -0
  30. package/dist/bridge/prompt-once.js +69 -0
  31. package/dist/bridge/protocol.d.ts +10 -0
  32. package/dist/bridge/protocol.js +10 -0
  33. package/dist/bridge/schedule-format.d.ts +2 -0
  34. package/dist/bridge/schedule-launch.d.ts +10 -1
  35. package/dist/bridge/schedule-launch.js +29 -3
  36. package/dist/bridge/schedule-watch.js +1 -1
  37. package/dist/bridge/schedules.d.ts +10 -0
  38. package/dist/bridge/schedules.js +40 -0
  39. package/dist/bridge/server-launch.js +12 -10
  40. package/dist/bridge/server-pane-routes.js +23 -9
  41. package/dist/bridge/server-routes.d.ts +1 -0
  42. package/dist/bridge/server-routes.js +1 -1
  43. package/dist/bridge/session-servers.js +5 -6
  44. package/dist/bridge/side-questions.js +6 -5
  45. package/dist/bridge/terminal-choice.d.ts +11 -0
  46. package/dist/bridge/terminal-choice.js +37 -0
  47. package/dist/bridge/terminal-herdr.d.ts +5 -0
  48. package/dist/bridge/terminal-herdr.js +57 -0
  49. package/dist/bridge/terminal-tmux.d.ts +111 -0
  50. package/dist/bridge/terminal-tmux.js +549 -0
  51. package/dist/bridge/terminal.d.ts +119 -0
  52. package/dist/bridge/terminal.js +66 -0
  53. package/dist/bridge/transcript-claude.d.ts +6 -0
  54. package/dist/bridge/transcript-claude.js +20 -0
  55. package/dist/bridge/transcript-opencode.js +1 -1
  56. package/dist/bridge/transcript-preview.js +1 -1
  57. package/dist/bridge/transport.js +10 -4
  58. package/dist/bridge-hook.mjs +4800 -3397
  59. package/dist/cli-registry.js +7 -0
  60. package/dist/entrypoint.d.ts +2 -0
  61. package/dist/entrypoint.js +5 -1
  62. package/dist/index.js +8 -2
  63. package/dist/init/init.js +4 -0
  64. package/dist/link/doctor.js +33 -30
  65. package/dist/mcp/plugin-mode.d.ts +16 -0
  66. package/dist/mcp/plugin-mode.js +106 -0
  67. package/dist/modules/agent-package.d.ts +35 -0
  68. package/dist/modules/agent-package.js +133 -0
  69. package/dist/modules/registry.js +2 -2
  70. package/dist/session/utils.js +1 -1
  71. package/dist/tools/dispatch.js +2 -2
  72. package/package.json +1 -1
  73. package/plugins/opencode/phren-transcript.js +97 -6
  74. package/starter/global/skills/phren-consolidate/SKILL.md +1 -1
  75. package/starter/global/skills/phren-discover/SKILL.md +1 -1
  76. package/starter/global/skills/phren-init/SKILL.md +6 -8
  77. package/starter/global/skills/phren-profiles/SKILL.md +1 -1
  78. package/starter/global/skills/phren-summarize/SKILL.md +1 -1
  79. package/starter/global/skills/phren-sync/SKILL.md +1 -1
@@ -0,0 +1,66 @@
1
+ // What the Hook needs from the terminal multiplexer its agents run in: Herdr
2
+ // (terminal-herdr.ts) or, on a computer without it, tmux (terminal-tmux.ts).
3
+ // Nothing Herdr- or tmux-specific may leak past a provider's own file.
4
+ //
5
+ // Identity (which conversation a pane runs) and agent status are not the
6
+ // provider's job. A multiplexer that knows them reports them as `hints`; one
7
+ // that does not leaves them out and the Hook falls back to lifecycle hooks
8
+ // and process logs.
9
+ import { existsSync } from "node:fs";
10
+ import { herdrPaneFromEnv, herdrSocketPath } from "./herdr.js";
11
+ import { BridgeError } from "./protocol.js";
12
+ import { herdrTerminal } from "./terminal-herdr.js";
13
+ import { tmuxPaneFromEnv, tmuxSocketName, tmuxTerminal } from "./terminal-tmux.js";
14
+ /** The pane this process runs in, from the variables its multiplexer sets:
15
+ * inside Herdr only Herdr's pane counts, elsewhere a tmux pane does. */
16
+ export async function terminalPaneFromEnv(env = process.env) {
17
+ if (env.HERDR_ENV === "1")
18
+ return env.HERDR_SOCKET_PATH ? herdrPaneFromEnv(env) : undefined;
19
+ return tmuxPaneFromEnv(env);
20
+ }
21
+ /** Which multiplexer a Hook server name belongs to: "tmux" and "tmux-<socket>"
22
+ * are tmux servers unless Herdr has a session of that name; every other name
23
+ * is a Herdr server, exactly as before tmux support. */
24
+ export function terminalKind(server) {
25
+ if (!tmuxSocketName(server))
26
+ return "herdr";
27
+ try {
28
+ return existsSync(herdrSocketPath(server)) ? "herdr" : "tmux";
29
+ }
30
+ catch {
31
+ return "tmux";
32
+ }
33
+ }
34
+ /** The multiplexer's name as the phone shows it in messages. */
35
+ export function terminalName(server) { return terminalKind(server) === "tmux" ? "tmux" : "Herdr"; }
36
+ const route = (server) => terminalKind(server) === "tmux" ? tmuxTerminal : herdrTerminal;
37
+ /** The provider for each server by its name: Herdr's or tmux's. */
38
+ export const routedTerminal = {
39
+ kind: "routed",
40
+ ping: server => route(server).ping(server),
41
+ snapshot: server => route(server).snapshot(server),
42
+ listPanes: server => route(server).listPanes(server),
43
+ processes: (server, pane) => route(server).processes(server, pane),
44
+ readScreen: (server, pane, read) => route(server).readScreen(server, pane, read),
45
+ sendKeys: (server, pane, keys) => route(server).sendKeys(server, pane, keys),
46
+ prompt: (server, pane, text, signal) => route(server).prompt(server, pane, text, signal),
47
+ create: (server, placement) => route(server).create(server, placement),
48
+ startAgent: (server, pane, agent) => route(server).startAgent(server, pane, agent),
49
+ focusPane: (server, pane) => route(server).focusPane(server, pane),
50
+ groupAction: (server, operation, group, label) => route(server).groupAction(server, operation, group, label),
51
+ };
52
+ /** True when a start or prompt was refused because the agent is still
53
+ * starting (a folder-trust or login screen holds it). Herdr says so with its
54
+ * own error code; another provider with `code`. */
55
+ export function agentNotReady(error) {
56
+ return error instanceof BridgeError && (error.details?.code === "agent_not_ready" || error.details?.herdrCode === "agent_not_ready");
57
+ }
58
+ let current = routedTerminal;
59
+ /** The multiplexer the Hook drives: each call goes to its server's provider. */
60
+ export function terminalProvider() { return current; }
61
+ /** For tests: drive the Hook through `provider`; the returned function restores the previous one. */
62
+ export function setTerminalProvider(provider) {
63
+ const previous = current;
64
+ current = provider;
65
+ return () => { current = previous; };
66
+ }
@@ -13,6 +13,12 @@ export declare function unwrapPastedContent(text: string): string;
13
13
  * signature is a length-prefixed field reading "narration" (private
14
14
  * reasoning reads "thinking" and is stored without text). */
15
15
  export declare function isNarration(block: Record<string, unknown>): boolean;
16
+ /** What a Skill call loaded. Claude Code answers the call itself with only
17
+ * "Launching skill: <name>" and writes the skill's text as a hidden user row
18
+ * pointing back at the call (`sourceToolUseID`). That row alone crosses, as a
19
+ * second result for the same call, so the phone can show what the skill said;
20
+ * every other hidden row stays private. */
21
+ export declare function skillBody(raw: Json): Json | undefined;
16
22
  /** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
17
23
  * parentUuid, content }`, or undefined for any other row. */
18
24
  export declare function phrenHookContext(raw: Json, includeSidechain?: boolean): Json | undefined;
@@ -256,6 +256,23 @@ export function isNarration(block) {
256
256
  }
257
257
  /** The largest injection the phone is sent; the hook's own budget keeps real ones far smaller. */
258
258
  const HOOK_CONTEXT_LIMIT = 16_384;
259
+ const SKILL_BODY = "Base directory for this skill:";
260
+ /** What a Skill call loaded. Claude Code answers the call itself with only
261
+ * "Launching skill: <name>" and writes the skill's text as a hidden user row
262
+ * pointing back at the call (`sourceToolUseID`). That row alone crosses, as a
263
+ * second result for the same call, so the phone can show what the skill said;
264
+ * every other hidden row stays private. */
265
+ export function skillBody(raw) {
266
+ if (raw.type !== "user" || raw.isMeta !== true || raw.isSidechain || typeof raw.sourceToolUseID !== "string" || !raw.sourceToolUseID)
267
+ return undefined;
268
+ const content = object(raw.message).content;
269
+ const text = typeof content === "string" ? content
270
+ : objects(content).filter(block => block.type === "text").map(block => String(block.text ?? "")).join("\n");
271
+ if (!text.startsWith(SKILL_BODY))
272
+ return undefined;
273
+ return { type: "user", timestamp: raw.timestamp, ...(typeof raw.uuid === "string" ? { uuid: raw.uuid } : {}),
274
+ message: { role: "user", content: [{ type: "tool_result", tool_use_id: raw.sourceToolUseID, content: text.slice(0, 32_768), phrenSkillBody: true }] } };
275
+ }
259
276
  /** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
260
277
  * parentUuid, content }`, or undefined for any other row. */
261
278
  export function phrenHookContext(raw, includeSidechain = false) {
@@ -334,6 +351,9 @@ export function visibleClaudeEvent(raw, includeSidechain = false) {
334
351
  const hookContext = phrenHookContext(raw, includeSidechain);
335
352
  if (hookContext)
336
353
  return hookContext;
354
+ const skill = skillBody(raw);
355
+ if (skill)
356
+ return skill;
337
357
  if (raw.isMeta || (raw.isSidechain && !includeSidechain) || !["user", "assistant", "system"].includes(String(raw.type)))
338
358
  return undefined;
339
359
  raw = Object.fromEntries(Object.entries(raw).filter(([key]) => CLAUDE_KEYS.has(key)));
@@ -9,7 +9,7 @@ export function visibleOpencodeEvent(raw, source, cwd) {
9
9
  if (runEvent)
10
10
  return runEvent;
11
11
  }
12
- // phren-agent's event log (experimental/agent/src/session/log.ts): the
12
+ // phren-agent's event log (packages/agent/src/session/log.ts): the
13
13
  // header and log/replace splices are bookkeeping; the three message
14
14
  // events are the conversation. Reasoning blocks stay on the computer.
15
15
  if (!["user/message", "assistant/message", "tool/results"].includes(String(raw.type)))
@@ -247,7 +247,7 @@ export function copilotThinking(rendered) {
247
247
  }
248
248
  export function readPreviewPane(target) {
249
249
  // With its styles: Claude's bold becomes Markdown; everything else strips.
250
- return readPaneText(target.server, target.pane, { method: "agent.read", source: "visible", lines: 80, stripAnsi: false, format: "ansi", timeoutMs: 2_000, what: "Preview pane read" });
250
+ return readPaneText(target.server, target.pane, { scope: "agent", source: "visible", lines: 80, stripAnsi: false, format: "ansi", timeoutMs: 2_000, what: "Preview pane read" });
251
251
  }
252
252
  // An SGR sequence (captured) or any other control sequence stripTerminal removes.
253
253
  const PANE_CONTROL = /\x1b\[([0-?]*)[ -/]*([@-~])|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\r/g;
@@ -7,7 +7,8 @@ import { spawn } from "node:child_process";
7
7
  import { homedir } from "node:os";
8
8
  import path from "node:path";
9
9
  import { BridgeError, object, PROTOCOL, serverName, socketPath, bridgeRoot, atomic } from "./protocol.js";
10
- import { rpc } from "./herdr.js";
10
+ import { terminalKind, terminalProvider } from "./terminal.js";
11
+ import { tmuxAttach } from "./terminal-tmux.js";
11
12
  import { launchDirectory } from "./projects.js";
12
13
  /** Decode the base64url project folder from a `phren-hook v1 shell` command; undefined when it is not a path. */
13
14
  export function decodeShellDirectory(encoded) {
@@ -20,7 +21,7 @@ export function decodeShellDirectory(encoded) {
20
21
  return path.isAbsolute(dir) && !/[\x00-\x1f\x7f]/.test(dir) && !dir.includes("\ufffd") ? dir : undefined;
21
22
  }
22
23
  export function shellEnvironment(base = process.env) {
23
- const env = Object.fromEntries(Object.entries(base).filter(([key]) => !key.startsWith("HERDR_")));
24
+ const env = Object.fromEntries(Object.entries(base).filter(([key]) => !key.startsWith("HERDR_") && key !== "TMUX" && key !== "TMUX_PANE"));
24
25
  env.PATH = [path.join(homedir(), ".local/bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].join(":");
25
26
  return env;
26
27
  }
@@ -122,13 +123,18 @@ export async function dispatch(command) {
122
123
  }
123
124
  const terminal = /^phren-hook v1 terminal ([A-Za-z0-9_.-]{1,100})$/.exec(command);
124
125
  if (!terminal || terminal[0] !== command)
125
- throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr terminals.");
126
+ throw new BridgeError(403, "This SSH key only permits Phren Hook, loopback web previews, project shells, and existing Herdr or tmux terminals.");
126
127
  requireHook();
127
128
  const server = serverName.parse(terminal[1]);
128
129
  if (!process.stdin.isTTY || !process.stdout.isTTY)
129
130
  throw new Error("Request an SSH terminal first.");
130
131
  // Verify the named server exists; never create a workspace or an agent implicitly.
131
- await rpc(server, "ping");
132
+ await terminalProvider().ping(server);
133
+ if (terminalKind(server) === "tmux") {
134
+ const { file, args } = tmuxAttach(server);
135
+ await attach(file, args, { env: shellEnvironment() }, "The tmux terminal disconnected.");
136
+ return;
137
+ }
132
138
  await attach("herdr", ["session", "attach", server], { env: shellEnvironment() }, "The Herdr terminal disconnected.");
133
139
  }
134
140
  /** Run one program on the inherited SSH PTY until it exits or the session hangs up. */