@phren/cli 0.2.16 → 0.3.0

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 (60) hide show
  1. package/dist/bridge/agent-hooks.d.ts +2 -0
  2. package/dist/bridge/agent-hooks.js +4 -0
  3. package/dist/bridge/code-note.d.ts +2 -1
  4. package/dist/bridge/code-note.js +13 -4
  5. package/dist/bridge/code-routes.d.ts +32 -14
  6. package/dist/bridge/code-routes.js +131 -8
  7. package/dist/bridge/dispatch-returns.d.ts +2 -0
  8. package/dist/bridge/dispatch-returns.js +12 -8
  9. package/dist/bridge/dispatch.d.ts +4 -1
  10. package/dist/bridge/dispatch.js +30 -5
  11. package/dist/bridge/install.d.ts +0 -4
  12. package/dist/bridge/install.js +3 -3
  13. package/dist/bridge/protocol.js +20 -1
  14. package/dist/bridge/schedule-watch.d.ts +2 -0
  15. package/dist/bridge/schedule-watch.js +16 -3
  16. package/dist/bridge/server-pane-routes.d.ts +7 -0
  17. package/dist/bridge/server-pane-routes.js +90 -11
  18. package/dist/bridge/server-routes.d.ts +2 -0
  19. package/dist/bridge/server-routes.js +44 -26
  20. package/dist/bridge/transcript-preview.d.ts +2 -0
  21. package/dist/bridge/transcript-preview.js +15 -0
  22. package/dist/bridge-hook.mjs +8842 -3209
  23. package/dist/cli/config-policy.js +25 -0
  24. package/dist/cli/extract.d.ts +0 -8
  25. package/dist/cli/extract.js +1 -1
  26. package/dist/cli-registry.js +7 -7
  27. package/dist/content/validate.d.ts +14 -3
  28. package/dist/content/validate.js +174 -114
  29. package/dist/data/access.d.ts +9 -0
  30. package/dist/data/access.js +18 -0
  31. package/dist/generated/memory-ui-graph.browser.js +520 -410
  32. package/dist/governance/policy.js +4 -3
  33. package/dist/hooks.d.ts +0 -15
  34. package/dist/hooks.js +1 -1
  35. package/dist/init/init-uninstall.js +13 -3
  36. package/dist/init/setup.js +19 -5
  37. package/dist/init/store-gitignore.d.ts +0 -5
  38. package/dist/init/store-gitignore.js +0 -8
  39. package/dist/link/context-imports.d.ts +15 -0
  40. package/dist/link/context-imports.js +101 -0
  41. package/dist/link/doctor.js +28 -4
  42. package/dist/mcp/profile.d.ts +0 -4
  43. package/dist/mcp/profile.js +0 -13
  44. package/dist/memory-ui-graph.runtime.js +520 -410
  45. package/dist/modules/code-package.js +10 -2
  46. package/dist/modules/registry.js +1 -1
  47. package/dist/profile-store.js +39 -3
  48. package/dist/project-topics.d.ts +1 -0
  49. package/dist/project-topics.js +9 -6
  50. package/dist/shared/retrieval.d.ts +0 -2
  51. package/dist/shared/retrieval.js +1 -1
  52. package/dist/tools/code.js +29 -21
  53. package/dist/tools/config.js +3 -0
  54. package/dist/tools/dispatch.js +1 -1
  55. package/dist/tools/finding.d.ts +11 -0
  56. package/dist/tools/finding.js +154 -99
  57. package/dist/ui/server.js +18 -1
  58. package/dist/update.js +21 -10
  59. package/package.json +7 -7
  60. package/starter/global/skills/conductor/SKILL.md +1 -1
@@ -1,3 +1,5 @@
1
+ import path from "node:path";
2
+ import { setTimeout as sleep } from "node:timers/promises";
1
3
  import { z } from "zod";
2
4
  import { gitBranches, gitDiscard, gitLog, gitPulls, gitStage, gitStatus, gitTree, gitUnstage } from "./git.js";
3
5
  import { fanoutWorktrees } from "./fanouts.js";
@@ -63,7 +65,7 @@ export function herdrWorktreeWorkers(s) {
63
65
  const workers = [];
64
66
  for (const pane of objects(s.panes)) {
65
67
  const cwd = pane.foreground_cwd || pane.cwd;
66
- if (typeof pane.agent !== "string" || typeof cwd !== "string" || !cwd.startsWith("/"))
68
+ if (typeof pane.agent !== "string" || typeof cwd !== "string" || !path.isAbsolute(cwd))
67
69
  continue;
68
70
  const name = paneAgentName(s, pane);
69
71
  workers.push({ cwd, label: name || pane.agent, provider: pane.agent,
@@ -99,6 +101,72 @@ async function resubmitIfIdle(agentHooks, target, text) {
99
101
  return outcome;
100
102
  return await status() === "working" ? "pending" : "unsubmitted";
101
103
  }
104
+ /** A busy Claude Code queues typed text on Enter, but after a long paste
105
+ * ("paste again to expand") it can swallow that Enter and leave the text in
106
+ * its input line, where it stays after the turn ends. Follow the pane: once
107
+ * it has stayed finished for two looks while the prompt is still unsubmitted,
108
+ * press Enter once. A closed or replaced pane, a delivery the conversation
109
+ * took, or ten minutes end the watch; a pane asking for input is never answered. */
110
+ export function followQueuedDelivery(agentHooks, target, terminal, text, intervalMs = 2_000) {
111
+ const started = Date.now();
112
+ let finishedLooks = 0;
113
+ const look = async () => {
114
+ if (!agentHooks.deliveryPending(target, text) || Date.now() - started > 600_000)
115
+ return;
116
+ let pane;
117
+ try {
118
+ pane = findPane(await snapshot(target.server), target);
119
+ }
120
+ catch {
121
+ pane = undefined;
122
+ }
123
+ if (!pane) {
124
+ schedule();
125
+ return;
126
+ }
127
+ if (pane.terminal_id !== terminal)
128
+ return;
129
+ const status = String(pane.agent_status);
130
+ finishedLooks = status === "idle" || status === "done" ? finishedLooks + 1 : 0;
131
+ if (finishedLooks >= 2) {
132
+ await resubmitIfIdle(agentHooks, target, text).catch(() => undefined);
133
+ return;
134
+ }
135
+ schedule();
136
+ };
137
+ const schedule = () => { const timer = setTimeout(() => void look(), intervalMs); timer.unref?.(); };
138
+ schedule();
139
+ }
140
+ /** A fresh Claude Code that took its first prompt starts working. One that
141
+ * stays idle kept the brief in its input line (a long paste can swallow the
142
+ * Enter): press Enter once, only while it is idle, so a dialog is never
143
+ * answered. False when it still has not started. */
144
+ async function submitStartingPrompt(server, target, terminal, looks = 4, intervalMs = 500) {
145
+ const status = async () => {
146
+ try {
147
+ const pane = findPane(await snapshot(server), target);
148
+ return pane && pane.terminal_id === terminal ? String(pane.agent_status) : "gone";
149
+ }
150
+ catch {
151
+ return "unknown";
152
+ }
153
+ };
154
+ const settled = async () => {
155
+ for (let look = 0; look < looks; look++) {
156
+ await sleep(intervalMs);
157
+ const current = await status();
158
+ if (current !== "idle" && current !== "done")
159
+ return current;
160
+ }
161
+ return "idle";
162
+ };
163
+ const first = await settled();
164
+ if (first !== "idle")
165
+ return first !== "gone";
166
+ await rpc(server, "agent.send_keys", { target: target.pane, keys: ["enter"] });
167
+ const second = await settled();
168
+ return second !== "idle" && second !== "gone";
169
+ }
102
170
  /** One key per character; Herdr's send_keys takes single characters and named
103
171
  * keys only, and a tty password read is corrupted by a bracketed paste. */
104
172
  function secretKeys(text) {
@@ -160,15 +228,23 @@ export async function paneRoute(ctx, url, data, response) {
160
228
  const text = z.string().min(1).max(32768).refine(t => !/[\x00-\x08\x0b-\x1f\x7f]/.test(t)).parse(data.text);
161
229
  refuseWorkingSlash(pane, text);
162
230
  await rpc(target.server, "agent.prompt", { target: target.pane, text });
163
- // A first prompt may create its transcript immediately. Recheck the
164
- // terminal/process binding, not the absence of a session. Never retry.
165
- let confirmed = false;
166
- try {
167
- const current = findPane(await snapshot(target.server), target);
168
- confirmed = !!current && current.terminal_id === pane.terminal_id && (await paneChatState(target.server, current)).startingToken === target.startingToken;
231
+ // A dispatched worker's brief is often long enough for Claude Code to
232
+ // swallow the Enter; a slash command opens a menu an Enter would answer.
233
+ const submitted = target.source !== "claude" || text.trim().startsWith("/")
234
+ || await submitStartingPrompt(target.server, target, pane.terminal_id);
235
+ if (!submitted)
236
+ result = { ok: true, deliveryUncertain: true, unsubmitted: true };
237
+ else {
238
+ // A first prompt may create its transcript immediately. Recheck the
239
+ // terminal/process binding, not the absence of a session. Never retry.
240
+ let confirmed = false;
241
+ try {
242
+ const current = findPane(await snapshot(target.server), target);
243
+ confirmed = !!current && current.terminal_id === pane.terminal_id && (await paneChatState(target.server, current)).startingToken === target.startingToken;
244
+ }
245
+ catch { /* Already delivered; an uncertain reply must not resend. */ }
246
+ result = { ok: true, ...(!confirmed ? { deliveryUncertain: true } : {}) };
169
247
  }
170
- catch { /* Already delivered; an uncertain reply must not resend. */ }
171
- result = { ok: true, ...(!confirmed ? { deliveryUncertain: true } : {}) };
172
248
  }
173
249
  else {
174
250
  const target = targetSchema.parse(data.target);
@@ -218,8 +294,11 @@ export async function paneRoute(ctx, url, data, response) {
218
294
  let outcome = await expected;
219
295
  // Only Claude confirms plain prompts through its hook, and a slash
220
296
  // command opens a menu that a second Enter would answer.
221
- if (outcome === "pending" && !busy && target.source === "claude" && !text.trim().startsWith("/")) {
222
- outcome = await resubmitIfIdle(agentHooks, target, text);
297
+ if (outcome === "pending" && target.source === "claude" && !text.trim().startsWith("/")) {
298
+ if (!busy)
299
+ outcome = await resubmitIfIdle(agentHooks, target, text);
300
+ else
301
+ followQueuedDelivery(agentHooks, target, pane.terminal_id, text);
223
302
  }
224
303
  if (outcome === "blocked")
225
304
  throw new BridgeError(409, "The conversation in this pane changed; the message was not delivered. Reopen the chat and send it again.");
@@ -63,6 +63,8 @@ export interface RouteContext {
63
63
  canary: (trigger: "manual" | "daily") => Promise<unknown>;
64
64
  streams: TranscriptStreams;
65
65
  }
66
+ /** How long the overview waits for per-tab git and transcript reads; the phone gives up at 20 s. */
67
+ export declare const OVERVIEW_ENRICH_BUDGET_MS = 5000;
66
68
  export declare const capabilities: {
67
69
  transcript: boolean;
68
70
  progress: boolean;
@@ -29,6 +29,8 @@ import { launchSession, workspaceAction } from "./server-launch.js";
29
29
  import { hookMetrics } from "./metrics.js";
30
30
  import { streamSpeech } from "./speech.js";
31
31
  const CHILD_ACTIVITY_CACHE_MS = 5_000;
32
+ /** How long the overview waits for per-tab git and transcript reads; the phone gives up at 20 s. */
33
+ export const OVERVIEW_ENRICH_BUDGET_MS = 5_000;
32
34
  const childActivityCache = new Map();
33
35
  async function childActivity(source, session) {
34
36
  const key = `${source}\0${session}`, now = Date.now(), cached = childActivityCache.get(key);
@@ -109,48 +111,61 @@ export function workspacesReader(ctx) {
109
111
  agentsByTab.set(key, agents);
110
112
  }
111
113
  const tabs = objects(workspaces.groups).flatMap(group => objects(group.children).map(tab => ({ group, tab })));
114
+ // What a chat needs to open (the exact conversation) comes straight from the
115
+ // chat states; everything below it is decoration.
116
+ for (const { group, tab } of tabs) {
117
+ const agents = agentsByTab.get(JSON.stringify([group.id, tab.id])) ?? [];
118
+ if (agents.length !== 1)
119
+ continue;
120
+ const chat = chatStates.get(agents[0]);
121
+ if (chat?.starting === true)
122
+ tab.starting = true;
123
+ if (typeof chat?.sessionId === "string" && provider.safeParse(agents[0].agent).success) {
124
+ tab.target = { server, workspace: group.id, tab: tab.id, pane: agents[0].pane_id, source: agents[0].agent, session: chat.sessionId };
125
+ }
126
+ }
127
+ // Branch, model, children and current step read git and transcripts. On a
128
+ // starved machine (load 230 on 10 cores, 2026-09-24) that took longer than
129
+ // the phone waits, so the computer read as offline. The overview answers
130
+ // within its budget with whatever decoration is ready; a later read fills in.
131
+ let expired = false;
112
132
  let nextTab = 0;
113
- // Bound transcript and git work across tabs. Each worker owns one
114
- // response row; snapshot order and target validation are unchanged.
115
- await Promise.all(Array.from({ length: Math.min(4, tabs.length) }, async () => {
116
- while (nextTab < tabs.length) {
133
+ const enrich = Promise.all(Array.from({ length: Math.min(4, tabs.length) }, async () => {
134
+ while (!expired && nextTab < tabs.length) {
117
135
  const { group, tab } = tabs[nextTab++];
118
136
  const agents = agentsByTab.get(JSON.stringify([group.id, tab.id])) ?? [];
119
- if (agents.length === 1) {
120
- const chat = chatStates.get(agents[0]);
121
- if (chat?.starting === true)
122
- tab.starting = true;
123
- if (typeof chat?.sessionId === "string" && provider.safeParse(agents[0].agent).success) {
124
- tab.target = { server, workspace: group.id, tab: tab.id, pane: agents[0].pane_id,
125
- source: agents[0].agent, session: chat.sessionId };
126
- }
127
- }
137
+ const found = {};
128
138
  if (modules.has("git") && typeof tab.cwd === "string" && tab.agent)
129
- tab.branch = await repositoryBranch(tab.cwd);
130
- // The model the pane's agent is running, and what it is doing
131
- // right now, for cards and the lock screen.
139
+ found.branch = await repositoryBranch(tab.cwd);
132
140
  if (agents.length === 1 && provider.safeParse(agents[0].agent).success) {
133
141
  const session = chatStates.get(agents[0])?.sessionId;
134
- tab.runningChildren = 0;
135
- tab.childProviders = [];
142
+ found.runningChildren = 0;
143
+ found.childProviders = [];
136
144
  if (typeof session === "string") {
137
145
  const source = agents[0].agent;
138
146
  const [model, children] = await Promise.all([
139
147
  currentModel(source, session).catch(() => undefined), childActivity(source, session),
140
148
  ]);
141
149
  if (model)
142
- tab.model = model;
143
- tab.runningChildren = children.runningChildren;
144
- tab.childProviders = children.childProviders;
150
+ found.model = model;
151
+ found.runningChildren = children.runningChildren;
152
+ found.childProviders = children.childProviders;
145
153
  if (agents[0].agent_status === "working") {
146
154
  const step = await currentStep(source, session).catch(() => undefined);
147
155
  if (step)
148
- tab.currentStep = step;
156
+ found.currentStep = step;
149
157
  }
150
158
  }
151
159
  }
160
+ // A row finished after the answer left belongs to the next read.
161
+ if (!expired)
162
+ Object.assign(tab, Object.fromEntries(Object.entries(found).filter(([, value]) => value !== undefined)));
152
163
  }
153
164
  }));
165
+ let timer;
166
+ await Promise.race([enrich, new Promise(resolve => { timer = setTimeout(resolve, OVERVIEW_ENRICH_BUDGET_MS); })]);
167
+ expired = true;
168
+ clearTimeout(timer);
154
169
  return { ...workspaces, phren: info };
155
170
  };
156
171
  }
@@ -365,8 +380,11 @@ export function createRouteHandler(ctx) {
365
380
  case "/v1/code/tree":
366
381
  result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).tree(url.searchParams.get("project"), url.searchParams.get("directory"));
367
382
  break;
368
- case "/v1/code/recent":
369
- result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).recent(url.searchParams.get("project"), url.searchParams.get("directory"));
383
+ case "/v1/code/changed":
384
+ result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).whatChanged(url.searchParams.get("project"));
385
+ break;
386
+ case "/v1/code/change-counts":
387
+ result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).changeCounts(url.searchParams.get("project"), url.searchParams.get("paths"));
370
388
  break;
371
389
  case "/v1/code/usage-page":
372
390
  result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).usagePage(url.searchParams.get("project"), {
@@ -390,10 +408,10 @@ export function createRouteHandler(ctx) {
390
408
  result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).outline(url.searchParams.get("project"), url.searchParams.get("path"));
391
409
  break;
392
410
  case "/v1/code/definition":
393
- result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).definition(url.searchParams.get("project"), url.searchParams.get("symbol"));
411
+ result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).definition(url.searchParams.get("project"), (url.searchParams.get("name") ?? url.searchParams.get("symbol")));
394
412
  break;
395
413
  case "/v1/code/references":
396
- result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).references(url.searchParams.get("project"), url.searchParams.get("symbol"), url.searchParams.get("limit"));
414
+ result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).references(url.searchParams.get("project"), (url.searchParams.get("name") ?? url.searchParams.get("symbol")), url.searchParams.get("limit"));
397
415
  break;
398
416
  case "/v1/code/usage":
399
417
  result = await (new CodeRoutes(await resolveCodeStore(scheduleStore, url.searchParams.get("store")))).usage(url.searchParams.get("project"), url.searchParams.get("top"));
@@ -8,6 +8,8 @@ export declare const PREVIEW_INTERVAL_MS = 500;
8
8
  /** Only the last Claude reply after the current prompt is eligible. A missing
9
9
  * prompt anchor is deliberately silent: scrollback could belong to an old turn. */
10
10
  export declare function claudePanePreview(rendered: string, prompt: string, previous?: string): string;
11
+ /** An unbulleted tool-group summary line, e.g. " Read 1 file, ran 1 shell command". */
12
+ export declare function claudeToolSummary(line: string): boolean;
11
13
  /**
12
14
  * Claude Code's own screen text, never part of a reply: the update and
13
15
  * restart notices, status lines it marks ✔ / ✗ / ⚠ / ※, tips, and the
@@ -69,6 +69,15 @@ export function claudePanePreview(rendered, prompt, previous = "") {
69
69
  break;
70
70
  if (/^\s*[✻✽✶✢✳✦·⠁-⣿]/u.test(line) || parseClaudeSpinnerLine(line))
71
71
  continue;
72
+ // Claude Code draws a finished or running tool group as an unbulleted,
73
+ // indented summary under the reply (" Ran 1 shell command", " Called
74
+ // phren, ran 1 shell command", " Running 1 shell command… grep -rn …").
75
+ // It starts a block after a blank line; it and its wrapped command lines
76
+ // are tool activity, which lands as its own entry.
77
+ if (!body[index - 1]?.trim() && claudeToolSummary(line)) {
78
+ writing = false;
79
+ continue;
80
+ }
72
81
  // A running tool group ("⏺ Running 2 agents…") and a tool call
73
82
  // ("⏺ Bash(ls)", "⏺ phren - search (MCP)(…)") are not reply
74
83
  // text; it lands as its own entry a moment later.
@@ -101,6 +110,12 @@ export function claudePanePreview(rendered, prompt, previous = "") {
101
110
  return overlap >= 0 && text.startsWith(previous.slice(overlap))
102
111
  ? (previous.slice(0, overlap) + text).slice(0, MAX_TEXT) : previous;
103
112
  }
113
+ const TOOL_SUMMARY_CLAUSE = String.raw `(?:(?:[Cc]alled|[Cc]alling) [\w.-]+(?: \d+ times?)?|(?:[Rr]an|[Rr]unning|[Rr]ead|[Rr]eading|[Ss]earched|[Ss]earching|[Ww]rote|[Ww]riting|[Ee]dited|[Ee]diting|[Uu]pdated|[Uu]pdating|[Ff]etched|[Ff]etching|[Ll]isted|[Ll]isting|[Cc]reated|[Cc]reating|[Ll]aunched|[Ll]aunching) \d+ [a-z]+(?: [a-z]+)?)`;
114
+ const TOOL_SUMMARY = new RegExp(`^ {1,4}${TOOL_SUMMARY_CLAUSE}(?:, ${TOOL_SUMMARY_CLAUSE})*(?:(?:…|\\.\\.\\.)(?:\\s.*)?)?(?: \\(ctrl\\+o to expand\\))?\\s*$`);
115
+ /** An unbulleted tool-group summary line, e.g. " Read 1 file, ran 1 shell command". */
116
+ export function claudeToolSummary(line) {
117
+ return TOOL_SUMMARY.test(line);
118
+ }
104
119
  /**
105
120
  * Claude Code's own screen text, never part of a reply: the update and
106
121
  * restart notices, status lines it marks ✔ / ✗ / ⚠ / ※, tips, and the