@phren/cli 0.2.16 → 0.3.1

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 (102) hide show
  1. package/dist/bridge/agent-hooks.d.ts +17 -6
  2. package/dist/bridge/agent-hooks.js +59 -24
  3. package/dist/bridge/claude-question-dialog.d.ts +65 -0
  4. package/dist/bridge/claude-question-dialog.js +210 -0
  5. package/dist/bridge/code-note.d.ts +2 -1
  6. package/dist/bridge/code-note.js +13 -4
  7. package/dist/bridge/code-routes.d.ts +32 -14
  8. package/dist/bridge/code-routes.js +131 -8
  9. package/dist/bridge/command.js +92 -2
  10. package/dist/bridge/computers.d.ts +5 -0
  11. package/dist/bridge/computers.js +10 -4
  12. package/dist/bridge/conductor-group.d.ts +23 -0
  13. package/dist/bridge/conductor-group.js +25 -0
  14. package/dist/bridge/dispatch-returns.d.ts +2 -0
  15. package/dist/bridge/dispatch-returns.js +12 -8
  16. package/dist/bridge/dispatch.d.ts +4 -1
  17. package/dist/bridge/dispatch.js +30 -5
  18. package/dist/bridge/hand-off.js +5 -1
  19. package/dist/bridge/herdr.d.ts +7 -0
  20. package/dist/bridge/herdr.js +53 -2
  21. package/dist/bridge/install.d.ts +0 -4
  22. package/dist/bridge/install.js +3 -3
  23. package/dist/bridge/link.d.ts +48 -0
  24. package/dist/bridge/link.js +136 -0
  25. package/dist/bridge/memory-store.d.ts +23 -0
  26. package/dist/bridge/memory-store.js +152 -0
  27. package/dist/bridge/pair.d.ts +46 -0
  28. package/dist/bridge/pair.js +240 -0
  29. package/dist/bridge/peers.d.ts +9 -0
  30. package/dist/bridge/peers.js +25 -2
  31. package/dist/bridge/protocol.js +20 -1
  32. package/dist/bridge/schedule-watch.d.ts +2 -0
  33. package/dist/bridge/schedule-watch.js +16 -3
  34. package/dist/bridge/server-launch.d.ts +9 -0
  35. package/dist/bridge/server-launch.js +34 -11
  36. package/dist/bridge/server-pane-routes.d.ts +7 -0
  37. package/dist/bridge/server-pane-routes.js +128 -18
  38. package/dist/bridge/server-routes.d.ts +3 -0
  39. package/dist/bridge/server-routes.js +55 -29
  40. package/dist/bridge/server-stream.js +4 -1
  41. package/dist/bridge/speech-key.d.ts +33 -0
  42. package/dist/bridge/speech-key.js +106 -0
  43. package/dist/bridge/speech-transcribe.js +1 -1
  44. package/dist/bridge/speech.d.ts +1 -3
  45. package/dist/bridge/speech.js +2 -16
  46. package/dist/bridge/transcript-preview.d.ts +2 -0
  47. package/dist/bridge/transcript-preview.js +15 -0
  48. package/dist/bridge-hook.mjs +9940 -3601
  49. package/dist/cli/config-policy.js +25 -0
  50. package/dist/cli/extract.d.ts +0 -8
  51. package/dist/cli/extract.js +1 -1
  52. package/dist/cli-handlers.js +6 -0
  53. package/dist/cli-registry.js +21 -9
  54. package/dist/content/learning.js +1 -1
  55. package/dist/content/validate.d.ts +14 -3
  56. package/dist/content/validate.js +174 -114
  57. package/dist/data/access.d.ts +9 -0
  58. package/dist/data/access.js +18 -0
  59. package/dist/data/tasks.d.ts +26 -0
  60. package/dist/data/tasks.js +72 -1
  61. package/dist/entrypoint.js +7 -0
  62. package/dist/generated/memory-ui-graph.browser.js +520 -410
  63. package/dist/governance/policy.js +4 -3
  64. package/dist/governance/rbac.d.ts +1 -1
  65. package/dist/governance/rbac.js +1 -0
  66. package/dist/hooks.d.ts +0 -15
  67. package/dist/hooks.js +1 -1
  68. package/dist/init/init-uninstall.js +13 -3
  69. package/dist/init/init-walkthrough.d.ts +10 -0
  70. package/dist/init/init-walkthrough.js +24 -1
  71. package/dist/init/init.d.ts +5 -0
  72. package/dist/init/init.js +54 -32
  73. package/dist/init/setup.js +19 -5
  74. package/dist/init/store-gitignore.d.ts +0 -5
  75. package/dist/init/store-gitignore.js +0 -8
  76. package/dist/link/context-imports.d.ts +15 -0
  77. package/dist/link/context-imports.js +101 -0
  78. package/dist/link/doctor.js +38 -4
  79. package/dist/mcp/profile.d.ts +0 -4
  80. package/dist/mcp/profile.js +2 -14
  81. package/dist/memory-ui-graph.runtime.js +520 -410
  82. package/dist/modules/code-package.js +10 -2
  83. package/dist/modules/config.d.ts +7 -0
  84. package/dist/modules/config.js +17 -0
  85. package/dist/modules/registry.js +6 -5
  86. package/dist/profile-store.js +39 -3
  87. package/dist/project-topics.d.ts +1 -0
  88. package/dist/project-topics.js +9 -6
  89. package/dist/shared/retrieval.d.ts +0 -2
  90. package/dist/shared/retrieval.js +1 -1
  91. package/dist/sync/task-claim.d.ts +22 -0
  92. package/dist/sync/task-claim.js +45 -0
  93. package/dist/tools/code.js +29 -21
  94. package/dist/tools/config.js +3 -0
  95. package/dist/tools/dispatch.js +3 -3
  96. package/dist/tools/finding.d.ts +11 -0
  97. package/dist/tools/finding.js +154 -99
  98. package/dist/tools/tasks.js +40 -1
  99. package/dist/ui/server.js +18 -1
  100. package/dist/update.js +21 -10
  101. package/package.json +8 -7
  102. package/starter/global/skills/conductor/SKILL.md +42 -10
@@ -3,6 +3,7 @@ import { type ServerResponse } from "node:http";
3
3
  import { type Json, type Provider, type Target } from "./protocol.js";
4
4
  import { ToolChanges } from "./changes.js";
5
5
  import { ApprovalPushService } from "./push.js";
6
+ import { type DialogAnswer, type DialogQuestion } from "./claude-question-dialog.js";
6
7
  import { type TerminalChoice } from "./terminal-choice.js";
7
8
  import { ApprovalWatchLeases } from "./agent-hook-stores.js";
8
9
  export { permissionPrompt, terminalChoice, visibleTerminalChoice, type TerminalChoice, type TerminalQuestion } from "./terminal-choice.js";
@@ -113,6 +114,8 @@ export declare class AgentHooks {
113
114
  * its turn ends, so the record outlives the wait (up to ten minutes) and a
114
115
  * late submission to the wrong conversation is still refused. */
115
116
  expectDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
117
+ /** A prompt Phren typed into `target` that its conversation has not submitted yet. */
118
+ deliveryPending(target: Target, text: string): boolean;
116
119
  /** Wait again for a delivery `expectDelivery` already reported pending,
117
120
  * after the Hook pressed Enter a second time. */
118
121
  awaitLateDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
@@ -141,12 +144,20 @@ export declare class AgentHooks {
141
144
  * keyless rows are reached and verified before returning Enter to the route. */
142
145
  dialogAnswerKeys<K extends string>(target: Target, keys: readonly K[]): Promise<(K | "Enter")[]>;
143
146
  moveDialogHighlight(target: Target, expected: TerminalChoice, key: string, beforeKeys?: () => Promise<void>): Promise<void>;
144
- /** Answer one question of a released AskUserQuestion with the option's own
145
- * digit: send the chosen digit(s), then Tab to advance to the next
146
- * question or Enter after the last. The stored question index moves with
147
- * them and a finished set is cleared. Undefined when the prompt is not a
148
- * question, so an ordinary key falls through to the usual handling. */
149
- questionAnswerKeys(target: Target, keys: readonly string[]): string[] | undefined;
147
+ /** Answer Claude's AskUserQuestion dialog in the pane: every question in
148
+ * `answers` from `from` on, then the set's submission when `submit`. The
149
+ * walk reads the pane before and after each key, so a dialog on another
150
+ * tab, a changed question or a missed key stops it with nothing stray
151
+ * typed. A finished set clears the remembered question. */
152
+ answerClaudeQuestions(target: Target, questions: DialogQuestion[], answers: DialogAnswer[], options?: {
153
+ from?: number;
154
+ submit?: boolean;
155
+ }): Promise<void>;
156
+ /** An older phone answers a released AskUserQuestion one question at a
157
+ * time with the chosen digits through `/v1/keys`. Walk that question with
158
+ * the same verified steps and submit after the last. False when the
159
+ * prompt is not a remembered question, so the keys take the usual path. */
160
+ answerReleasedQuestion(target: Target, keys: readonly string[]): Promise<boolean>;
150
161
  private startCompacting;
151
162
  private stopCompacting;
152
163
  /** True while Claude Code is compacting `target`; a boundary older than ten
@@ -16,6 +16,7 @@ import { archiveFinishedFanouts, blockedFanouts, fanoutAsking } from "./fanouts.
16
16
  import { ensureGrant, listGrants, matchGrant } from "./grants.js";
17
17
  import { ApprovalPushService } from "./push.js";
18
18
  import { intervalFromEnv } from "./limits.js";
19
+ import { answerClaudeQuestionDialog, claudeQuestionDialog } from "./claude-question-dialog.js";
19
20
  import { answeredQuestionInput, numberedDialog, passwordLine, permissionPrompt, questionChoice, terminalChoice, terminalQuestions, visibleTerminalChoice } from "./terminal-choice.js";
20
21
  import { directoryNames, opencodeApprovalFile, opencodeRequest, readOpencodeRequest } from "./opencode-approvals.js";
21
22
  import { ApprovalWatchLeases, bindingPath, localSocket, PushBindingStore } from "./agent-hook-stores.js";
@@ -342,6 +343,10 @@ export class AgentHooks {
342
343
  this.deliveries.delete(this.deliveries.keys().next().value);
343
344
  });
344
345
  }
346
+ /** A prompt Phren typed into `target` that its conversation has not submitted yet. */
347
+ deliveryPending(target, text) {
348
+ return !!this.deliveries.get(promptKey(text))?.some(entry => entry.source === target.source && entry.session === target.session);
349
+ }
345
350
  /** Wait again for a delivery `expectDelivery` already reported pending,
346
351
  * after the Hook pressed Enter a second time. */
347
352
  awaitLateDelivery(target, text, waitMs = 2_500) {
@@ -426,18 +431,17 @@ export class AgentHooks {
426
431
  return;
427
432
  }
428
433
  // A released AskUserQuestion is answered by its own question card, never
429
- // by the pane's numbered lines; it is cleared only when the pane stops
430
- // waiting for it.
431
- if (entry?.questions?.length) {
432
- if (!active) {
433
- this.terminalPrompts.delete(key);
434
- this.passwords.delete(key);
435
- }
434
+ // by the pane's numbered lines. It is cleared when the pane stops waiting
435
+ // or no longer draws a question (answered or cancelled in the terminal).
436
+ const question = !!entry?.questions?.length;
437
+ if (question && !active) {
438
+ this.terminalPrompts.delete(key);
439
+ this.passwords.delete(key);
436
440
  return;
437
441
  }
438
442
  // A released permission request that carried its own choices keeps them;
439
443
  // one without (a Bash or MCP call) reads the pane's rows below.
440
- if (entry && !entry.dialog && entry.choice && !entry.released)
444
+ if (!question && entry && !entry.dialog && entry.choice && !entry.released)
441
445
  return;
442
446
  if (!active) {
443
447
  if (entry)
@@ -455,6 +459,19 @@ export class AgentHooks {
455
459
  this.passwords.set(key, passwordLine(text));
456
460
  while (this.passwords.size > 128)
457
461
  this.passwords.delete(this.passwords.keys().next().value);
462
+ // Claude's AskUserQuestion dialog is answered from the question itself
463
+ // (the held request, the remembered one, or the transcript's), never as
464
+ // a numbered dialog: its digits advance on their own and a trailing
465
+ // Enter would land on the next tab.
466
+ if (target.source === "claude" && claudeQuestionDialog(text)) {
467
+ if (entry && !question)
468
+ this.terminalPrompts.delete(key);
469
+ return;
470
+ }
471
+ if (question) {
472
+ this.terminalPrompts.delete(key);
473
+ return;
474
+ }
458
475
  // Codex draws "> 1. Yes, proceed (y)" rows; the other fallbacks number
459
476
  // rows without a key in the label.
460
477
  const dialog = target.source === "codex" ? visibleTerminalChoice(text) : numberedDialog(text);
@@ -532,26 +549,44 @@ export class AgentHooks {
532
549
  }
533
550
  throw new BridgeError(409, "Could not move and verify the terminal selection. Open terminal to choose this option.");
534
551
  }
535
- /** Answer one question of a released AskUserQuestion with the option's own
536
- * digit: send the chosen digit(s), then Tab to advance to the next
537
- * question or Enter after the last. The stored question index moves with
538
- * them and a finished set is cleared. Undefined when the prompt is not a
539
- * question, so an ordinary key falls through to the usual handling. */
540
- questionAnswerKeys(target, keys) {
552
+ /** Answer Claude's AskUserQuestion dialog in the pane: every question in
553
+ * `answers` from `from` on, then the set's submission when `submit`. The
554
+ * walk reads the pane before and after each key, so a dialog on another
555
+ * tab, a changed question or a missed key stops it with nothing stray
556
+ * typed. A finished set clears the remembered question. */
557
+ async answerClaudeQuestions(target, questions, answers, options = {}) {
558
+ const key = JSON.stringify(target);
559
+ await answerClaudeQuestionDialog({
560
+ read: () => this.paneLines(target),
561
+ keys: async (keys) => {
562
+ if (!keys.length)
563
+ return;
564
+ await validateTarget(target, false, true);
565
+ await rpc(target.server, "agent.send_keys", { target: target.pane, keys });
566
+ },
567
+ }, questions, answers, options);
568
+ this.dialogReads.delete(key);
569
+ if (options.submit ?? true)
570
+ this.terminalPrompts.delete(key);
571
+ }
572
+ /** An older phone answers a released AskUserQuestion one question at a
573
+ * time with the chosen digits through `/v1/keys`. Walk that question with
574
+ * the same verified steps and submit after the last. False when the
575
+ * prompt is not a remembered question, so the keys take the usual path. */
576
+ async answerReleasedQuestion(target, keys) {
541
577
  const key = JSON.stringify(target), entry = this.terminalPrompts.get(key);
542
- if (!entry?.questions?.length)
543
- return undefined;
578
+ if (target.source !== "claude" || !entry?.questions?.length)
579
+ return false;
544
580
  const digits = keys.filter(value => /^[1-9]$/.test(value));
545
581
  if (!digits.length)
546
- return undefined;
547
- const index = Math.min(entry.questionIndex ?? 0, entry.questions.length - 1), next = index + 1;
548
- if (next >= entry.questions.length) {
549
- this.terminalPrompts.delete(key);
550
- return [...digits, "Enter"];
582
+ return false;
583
+ const index = Math.min(entry.questionIndex ?? 0, entry.questions.length - 1), last = index + 1 >= entry.questions.length;
584
+ await this.answerClaudeQuestions(target, entry.questions, [{ options: digits.map(digit => Number(digit) - 1) }], { from: index, submit: last });
585
+ if (!last) {
586
+ entry.questionIndex = index + 1;
587
+ entry.choice = questionChoice(entry.questions, index + 1);
551
588
  }
552
- entry.questionIndex = next;
553
- entry.choice = questionChoice(entry.questions, next);
554
- return [...digits, "Tab"];
589
+ return true;
555
590
  }
556
591
  startCompacting(target) {
557
592
  this.compactingSince.set(JSON.stringify(target), Date.now());
@@ -0,0 +1,65 @@
1
+ /** Claude Code's AskUserQuestion dialog as the pane draws it, and a walk that
2
+ * answers it one verified key at a time. Claude's keys are not uniform: a
3
+ * digit on a single-select question picks the row and moves to the next
4
+ * question on its own, a digit on a multi-select question only toggles its
5
+ * box, Tab leaves a multi-select question (or, from the typed "Other" row,
6
+ * moves to its Next row), and a set of more than one question, or any
7
+ * multi-select question, ends on a "Review your answers" tab that "1"
8
+ * submits. Blind key sequences drift onto the wrong tab, so every step reads
9
+ * the pane first and checks the result before the next. */
10
+ interface Row {
11
+ number: number;
12
+ label: string;
13
+ checked?: boolean;
14
+ answered: boolean;
15
+ cursor: boolean;
16
+ }
17
+ export interface ClaudeQuestionScreen {
18
+ kind: "question";
19
+ /** Headers from the tab bar, without the trailing Submit tab. */
20
+ tabs: string[];
21
+ title: string;
22
+ multiSelect: boolean;
23
+ /** The asked options, in order; the typed "Other" row is `other`. */
24
+ options: Row[];
25
+ other?: Row;
26
+ /** The row number under the cursor, or "next" on a multi-select Next/Submit row. */
27
+ cursor?: number | "next";
28
+ }
29
+ export interface ClaudeReviewScreen {
30
+ kind: "review";
31
+ tabs: string[];
32
+ answers: {
33
+ question: string;
34
+ answer: string;
35
+ }[];
36
+ }
37
+ export type ClaudeDialogScreen = ClaudeQuestionScreen | ClaudeReviewScreen;
38
+ /** The question dialog the pane is drawing now, or undefined when the last
39
+ * lines are not one: the last tab bar anchors it, and an active dialog ends
40
+ * with its "Esc to cancel" footer or the review's Submit/Cancel rows. */
41
+ export declare function claudeQuestionDialog(text: string): ClaudeDialogScreen | undefined;
42
+ export interface DialogQuestion {
43
+ question: string;
44
+ multiSelect?: boolean;
45
+ options: {
46
+ label: string;
47
+ }[];
48
+ }
49
+ /** Option indexes into the question's options, plus a typed "Other" answer. */
50
+ export interface DialogAnswer {
51
+ options: number[];
52
+ text?: string;
53
+ }
54
+ export interface DialogIO {
55
+ read(): Promise<string>;
56
+ keys(keys: string[]): Promise<void>;
57
+ sleep?(ms: number): Promise<void>;
58
+ }
59
+ /** Answer `answers[i]` for question `from + i`, then submit the set when
60
+ * `submit` is true. Each step is checked against a fresh read of the pane. */
61
+ export declare function answerClaudeQuestionDialog(io: DialogIO, questions: DialogQuestion[], answers: DialogAnswer[], options?: {
62
+ from?: number;
63
+ submit?: boolean;
64
+ }): Promise<void>;
65
+ export {};
@@ -0,0 +1,210 @@
1
+ import { BridgeError } from "./protocol.js";
2
+ const TAB_BAR = /^\s*(?:←\s+)?((?:[☐☒]\s+\S[^☐☒✔→]*?\s*)+)(?:✔\s+Submit\s*)?(?:→\s*)?$/;
3
+ const ROW = /^\s*(❯)?\s*(\d)\.\s+(?:\[([ ✔])\]\s+)?(.*?)\s*$/;
4
+ const NEXT = /^\s*(❯)?\s+(?:Next|Submit)\s*$/;
5
+ const normalize = (text) => text.replace(/\s+/g, " ").trim();
6
+ /** The question dialog the pane is drawing now, or undefined when the last
7
+ * lines are not one: the last tab bar anchors it, and an active dialog ends
8
+ * with its "Esc to cancel" footer or the review's Submit/Cancel rows. */
9
+ export function claudeQuestionDialog(text) {
10
+ const lines = text.split(/\r?\n/);
11
+ let bar = -1;
12
+ for (let index = lines.length - 1; index >= 0; index--)
13
+ if (TAB_BAR.test(lines[index]) && /[☐☒]/.test(lines[index])) {
14
+ bar = index;
15
+ break;
16
+ }
17
+ if (bar < 0)
18
+ return undefined;
19
+ const tabs = [...lines[bar].matchAll(/[☐☒]\s+([^☐☒✔→]+?)(?=\s{2,}|\s*[☐☒✔→]|\s*$)/g)].map(match => match[1].trim());
20
+ const body = lines.slice(bar + 1);
21
+ const content = body.map(line => line.trim()).filter(line => line && !/^─+$/.test(line));
22
+ if (content[0] === "Review your answers") {
23
+ if (!body.some(line => /^\s*❯?\s*1\.\s+Submit answers\s*$/.test(line)))
24
+ return undefined;
25
+ const answers = [];
26
+ for (const line of content.slice(1)) {
27
+ if (/^Ready to submit/.test(line))
28
+ break;
29
+ const question = /^●\s+(.+)$/.exec(line), answer = /^→\s+(.+)$/.exec(line), last = answers[answers.length - 1];
30
+ if (question)
31
+ answers.push({ question: question[1], answer: "" });
32
+ else if (answer && last)
33
+ last.answer = answer[1];
34
+ // A long question or answer wraps onto the next line.
35
+ else if (last) {
36
+ if (last.answer)
37
+ last.answer += " " + line;
38
+ else
39
+ last.question += " " + line;
40
+ }
41
+ }
42
+ return { kind: "review", tabs, answers };
43
+ }
44
+ if (!content.some(line => /Esc to cancel/.test(line)))
45
+ return undefined;
46
+ const first = body.findIndex(line => ROW.test(line));
47
+ if (first < 0)
48
+ return undefined;
49
+ const title = normalize(body.slice(0, first).filter(line => line.trim()).join(" "));
50
+ const rows = [];
51
+ let cursor, chat = false;
52
+ for (const line of body.slice(first)) {
53
+ const next = NEXT.exec(line);
54
+ if (next) {
55
+ if (next[1])
56
+ cursor = "next";
57
+ continue;
58
+ }
59
+ const match = ROW.exec(line);
60
+ if (!match)
61
+ continue;
62
+ const number = Number(match[2]);
63
+ if (match[1])
64
+ cursor = number;
65
+ if (/^Chat about this$/.test(match[4])) {
66
+ chat = true;
67
+ continue;
68
+ }
69
+ const answered = !match[3] && / ✔$/.test(match[4]);
70
+ rows.push({ number, label: answered ? match[4].slice(0, -2).trim() : match[4], answered, cursor: !!match[1],
71
+ ...(match[3] ? { checked: match[3] === "✔" } : {}) });
72
+ }
73
+ if (!title || !chat || rows.length < 2)
74
+ return undefined;
75
+ // The last row above "Chat about this" is the typed answer ("Type
76
+ // something." until something is typed there).
77
+ const other = rows.pop();
78
+ return { kind: "question", tabs, title, multiSelect: rows.some(row => row.checked !== undefined), options: rows, other, ...(cursor !== undefined ? { cursor } : {}) };
79
+ }
80
+ const changed = (message) => new BridgeError(409, `${message} Nothing else was sent; check the question and answer again, or cancel it.`);
81
+ /** A typed answer, one key per character; herdr names the space bar. */
82
+ const typedKeys = (text) => [...text].map(character => character === " " ? "space" : character);
83
+ /** Answer `answers[i]` for question `from + i`, then submit the set when
84
+ * `submit` is true. Each step is checked against a fresh read of the pane. */
85
+ export async function answerClaudeQuestionDialog(io, questions, answers, options = {}) {
86
+ const from = options.from ?? 0, submit = options.submit ?? true;
87
+ const sleep = io.sleep ?? ((ms) => new Promise(resolve => setTimeout(resolve, ms)));
88
+ const matches = (screen, index) => screen?.kind === "question" && screen.title === normalize(questions[index].question);
89
+ // Claude redraws a moment after a key; poll until the expected screen shows.
90
+ const settle = async (check, ms = 2_000) => {
91
+ for (let waited = 0;; waited += 120) {
92
+ const value = check(claudeQuestionDialog(await io.read()));
93
+ if (value !== undefined || waited >= ms)
94
+ return value;
95
+ await sleep(120);
96
+ }
97
+ };
98
+ const initial = await settle(screen => screen);
99
+ if (!initial)
100
+ throw changed("The terminal is not showing Claude's question.");
101
+ // A set of several questions draws one tab per question; a single question
102
+ // draws its own header. The tabs must be this set's, in this order.
103
+ if (initial.tabs.length !== questions.length)
104
+ throw changed("The terminal is asking a different set of questions.");
105
+ const reach = async (index) => {
106
+ const screen = await settle(value => value);
107
+ if (screen?.kind === "question" && screen.title === normalize(questions[index].question))
108
+ return screen;
109
+ const at = screen?.kind === "review" ? questions.length
110
+ : screen?.kind === "question" ? questions.findIndex(question => normalize(question.question) === screen.title) : -1;
111
+ if (at < 0)
112
+ throw changed("The terminal is showing a different question.");
113
+ // Arrow keys would edit a typed answer; step off that row first.
114
+ if (screen?.kind === "question" && screen.other && screen.cursor === screen.other.number)
115
+ await io.keys(["up"]);
116
+ await io.keys(Array(Math.abs(index - at)).fill(index > at ? "right" : "left"));
117
+ const moved = await settle(value => matches(value, index) ? value : undefined);
118
+ if (!moved)
119
+ throw changed("Could not move the terminal to the question being answered.");
120
+ return moved;
121
+ };
122
+ const leaves = (index) => (value) => value === undefined ? "gone" : !matches(value, index) ? "moved" : undefined;
123
+ for (const [offset, answer] of answers.entries()) {
124
+ const index = from + offset, question = questions[index];
125
+ if (!question)
126
+ throw new BridgeError(400, "The answer names a question that was not asked.");
127
+ const typed = answer.text?.trim() ?? "";
128
+ let screen = await reach(index);
129
+ if (screen.multiSelect !== !!question.multiSelect || screen.options.length !== question.options.length
130
+ || screen.options.some((row, position) => row.label !== question.options[position].label.trim())) {
131
+ throw changed("The terminal's options differ from the question being answered.");
132
+ }
133
+ if (!screen.multiSelect) {
134
+ if (typed) {
135
+ const other = screen.other;
136
+ await io.keys([String(other.number)]);
137
+ const focused = await settle(value => matches(value, index) && value.cursor === other.number ? value : undefined);
138
+ if (!focused)
139
+ throw changed("Could not open the typed answer.");
140
+ await io.keys(typedKeys(typed));
141
+ const shown = await settle(value => matches(value, index) && value.other && normalize(value.other.label).startsWith(normalize(typed).slice(0, 20)) ? value : undefined);
142
+ if (!shown)
143
+ throw changed("The typed answer did not appear in the terminal.");
144
+ await io.keys(["enter"]);
145
+ }
146
+ else {
147
+ await io.keys([String(screen.options[answer.options[0]].number)]);
148
+ }
149
+ if (!await settle(leaves(index)))
150
+ throw changed("The terminal did not take the answer.");
151
+ continue;
152
+ }
153
+ // Multi-select: toggle only the boxes that differ, one key per write
154
+ // (Ink reads "13" in one write as a single input and toggles nothing),
155
+ // and check each box before the next.
156
+ const rows = [...screen.options, ...(screen.other ? [screen.other] : [])];
157
+ for (const [position, row] of rows.entries()) {
158
+ const wanted = position < screen.options.length ? answer.options.includes(position) : !!row.checked && !!typed;
159
+ if (wanted === !!row.checked)
160
+ continue;
161
+ const box = (value) => matches(value, index)
162
+ ? !!(position < value.options.length ? value.options[position] : value.other)?.checked : undefined;
163
+ // A key that lands while the tab is still drawing can be dropped; the
164
+ // box itself says whether one more press is needed.
165
+ for (let attempt = 0; attempt < 2 && box(screen) !== wanted; attempt++) {
166
+ await io.keys([String(row.number)]);
167
+ screen = await settle(value => box(value) === wanted ? value : undefined, 1_000) ?? screen;
168
+ }
169
+ if (box(screen) !== wanted)
170
+ throw changed("The terminal's checkboxes did not match the answer.");
171
+ }
172
+ if (typed) {
173
+ const other = screen.other, cursor = typeof screen.cursor === "number" ? screen.cursor : 1;
174
+ if (cursor !== other.number)
175
+ await io.keys(Array(Math.abs(other.number - cursor)).fill(other.number > cursor ? "down" : "up"));
176
+ if (!await settle(value => matches(value, index) && value.cursor === other.number ? value : undefined))
177
+ throw changed("Could not reach the typed answer row.");
178
+ await io.keys(typedKeys(typed));
179
+ const shown = await settle(value => matches(value, index) && value.other?.checked && normalize(value.other.label).startsWith(normalize(typed).slice(0, 20)) ? value : undefined);
180
+ if (!shown)
181
+ throw changed("The typed answer did not appear in the terminal.");
182
+ // Tab moves from the typed row to Next; Enter there leaves the question.
183
+ await io.keys(["tab"]);
184
+ if (!await settle(value => matches(value, index) && value.cursor === "next" ? value : undefined))
185
+ throw changed("Could not reach the question's Next row.");
186
+ await io.keys(["enter"]);
187
+ }
188
+ else {
189
+ // Tab from the typed row would stop on Next instead of leaving.
190
+ await io.keys(screen.other && screen.cursor === screen.other.number ? ["up", "tab"] : ["tab"]);
191
+ }
192
+ if (!await settle(leaves(index)))
193
+ throw changed("The terminal did not move past the question.");
194
+ }
195
+ if (!submit)
196
+ return;
197
+ const review = await settle(value => value?.kind === "review" ? value : value === undefined ? "gone" : undefined);
198
+ // A lone single-select question submits on its digit.
199
+ if (review === "gone")
200
+ return;
201
+ if (!review)
202
+ throw changed("The terminal did not reach the review of the answers.");
203
+ const expected = questions.map(question => normalize(question.question));
204
+ if (review.answers.length !== questions.length || review.answers.some((row, position) => normalize(row.question) !== expected[position] || !row.answer)) {
205
+ throw changed("Not every question has an answer in the terminal.");
206
+ }
207
+ await io.keys(["1"]);
208
+ if (await settle(value => value === undefined ? "gone" : undefined) !== "gone")
209
+ throw changed("The terminal did not submit the answers.");
210
+ }
@@ -3,7 +3,8 @@ import { type Json } from "./protocol.js";
3
3
  export declare const codeNoteSchema: z.ZodObject<{
4
4
  store: z.ZodOptional<z.ZodString>;
5
5
  project: z.ZodString;
6
- symbol: z.ZodString;
6
+ name: z.ZodOptional<z.ZodString>;
7
+ symbol: z.ZodOptional<z.ZodString>;
7
8
  file: z.ZodString;
8
9
  line: z.ZodNumber;
9
10
  text: z.ZodString;
@@ -6,23 +6,32 @@ import { BridgeError, sessionId } from "./protocol.js";
6
6
  import { projectName } from "./dispatch.js";
7
7
  export const codeNoteSchema = z.object({
8
8
  store: z.string().min(1).max(200).optional(),
9
- project: projectName, symbol: z.string().min(1).max(4600),
9
+ project: projectName,
10
+ // The function, type or variable the note is about; `symbol` is the older
11
+ // phone's spelling, accepted until 0.3.1.
12
+ name: z.string().min(1).max(4600).optional(), symbol: z.string().min(1).max(4600).optional(),
10
13
  file: z.string().min(1).max(4096).refine(file => !path.isAbsolute(file) && !file.includes("\0") && !file.split(/[\\/]/).includes("..")),
11
14
  line: z.number().int().positive(), text: z.string().trim().min(1).max(4500).refine(text => !/[\x00-\x08\x0b-\x1f\x7f]/.test(text)),
12
15
  target: z.union([z.object({ session: sessionId }).strict(), z.object({ harness: z.enum(["codex", "claude", "opencode"]) }).strict()]).optional(),
13
16
  }).strict();
17
+ const noteName = (note) => {
18
+ const name = note.name ?? note.symbol;
19
+ if (!name)
20
+ throw new BridgeError(400, "Say which function, type or variable the note is about.");
21
+ return name;
22
+ };
14
23
  export async function saveCodeNote(store, input, deliver) {
15
24
  const note = codeNoteSchema.parse(input);
16
25
  if (note.target && !deliver)
17
26
  throw new BridgeError(409, "Enable conductor to send code notes to an agent.");
18
27
  const code = await requireCodePackage(store);
19
- const result = await code.definition(store, note.project, note.symbol);
28
+ const result = await code.definition(store, note.project, noteName(note));
20
29
  if (!result.available || !result.value)
21
- throw new BridgeError(404, "The symbol is not in this project's code index.");
30
+ throw new BridgeError(404, "That function, type or variable is not in this project's code index.");
22
31
  const definition = result.value;
23
32
  const lastSnippetLine = definition.symbol.line + definition.snippet.split("\n").length - 1;
24
33
  if (definition.symbol.file !== note.file || note.line < definition.symbol.line || note.line > Math.min(definition.symbol.endLine, lastSnippetLine)) {
25
- throw new BridgeError(409, "The selected line no longer belongs to this symbol. Refresh its dossier.");
34
+ throw new BridgeError(409, `The selected line is no longer part of ${noteName(note)}. Open it again.`);
26
35
  }
27
36
  const citation = { file: note.file, line: note.line, symbol: code.citationSymbolName(definition.symbol) };
28
37
  const saved = addFindingToFile(store, note.project, note.text, citation);
@@ -35,22 +35,40 @@ export declare class CodeRoutes {
35
35
  maxUses: number;
36
36
  project: string;
37
37
  }>;
38
- recent(projectValue: string | null, directoryValue?: string | null): Promise<{
38
+ /** The checkout this computer indexes for `project`, or a 404 naming the project. */
39
+ private checkout;
40
+ private changedIn;
41
+ /**
42
+ * What changed: the functions, types and variables that today's agent
43
+ * sessions edited in this project's checkout, and its last 10 commits,
44
+ * grouped by file, most recent work first. Session edits carry the line
45
+ * numbers they had when made, so a later edit to the same file can shift one.
46
+ */
47
+ whatChanged(projectValue: string | null, now?: Date): Promise<{
48
+ project: string;
49
+ files: {
50
+ path: string;
51
+ items: import("@phren/code").ChangedDeclaration[];
52
+ }[];
53
+ }>;
54
+ /**
55
+ * Per-file counts for the Changes tree's chips: functions and types the
56
+ * working tree changes or adds (variables stay out to keep a chip short).
57
+ * An untracked file is new throughout.
58
+ */
59
+ changeCounts(projectValue: string | null, pathsValue: string | null): Promise<{
39
60
  project: string;
40
61
  entries: {
41
- id: number;
42
- name: string;
43
- kind: string;
44
- file: string;
45
- line: number;
46
- endLine: number;
47
- signature: string;
48
- doc: string;
49
- parent: string | null;
50
- exported: boolean;
51
- uses: number;
52
- rank?: number;
53
- indexedAt: number;
62
+ path: string;
63
+ functions: {
64
+ changed: number;
65
+ added: number;
66
+ };
67
+ types: {
68
+ changed: number;
69
+ added: number;
70
+ };
71
+ first?: string | undefined;
54
72
  }[];
55
73
  }>;
56
74
  /** Turns code intelligence off for a project: its index is deleted, and