@bypane/cli 0.1.0 → 0.2.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.
package/dist/state.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync, statSync } from "node:fs";
2
2
  import { basename, extname, resolve } from "node:path";
3
3
  import { decodePng, isPngBuffer } from "./png.js";
4
+ import { collectUiDefaults } from "./ui-surface.js";
4
5
  const CHECKLIST_RE = /^(\s*[-*+]\s+\[)([ xX])(\]\s+)(.*)$/;
5
6
  export function extractChecklist(markdown) {
6
7
  const lines = markdown.split(/\r?\n/);
@@ -125,6 +126,8 @@ export class WorkspaceStore {
125
126
  idCounter = 1;
126
127
  listeners = new Set();
127
128
  askWaiters = new Map();
129
+ uiWaiters = new Map();
130
+ appWaiters = new Map();
128
131
  constructor(session) {
129
132
  this.session = session;
130
133
  }
@@ -183,6 +186,12 @@ export class WorkspaceStore {
183
186
  if (removed && removed.kind === "ask" && removed.answer.status === "pending") {
184
187
  this.resolveAskWaiters(removed.id, { status: "cancelled", submittedAt: Date.now() });
185
188
  }
189
+ if (removed && removed.kind === "ui" && removed.submission.status === "pending") {
190
+ this.resolveUiWaiters(removed.id, { status: "cancelled", submittedAt: Date.now() });
191
+ }
192
+ if (removed && removed.kind === "app" && removed.submission.status === "pending") {
193
+ this.resolveAppWaiters(removed.id, { status: "cancelled", submittedAt: Date.now() });
194
+ }
186
195
  if (this.activeId === targetId) {
187
196
  const next = this.surfaces[Math.min(idx, this.surfaces.length - 1)];
188
197
  this.activeId = next ? next.id : "";
@@ -195,18 +204,22 @@ export class WorkspaceStore {
195
204
  addNote(surfaceId, noteText) {
196
205
  const trimmed = noteText.trim();
197
206
  if (!trimmed)
198
- return false;
207
+ return null;
199
208
  const s = this.get(surfaceId);
200
209
  if (!s)
201
- return false;
202
- s.notes.push({
203
- id: `note-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
210
+ return null;
211
+ const now = Date.now();
212
+ const context = captureNoteContext(s);
213
+ const note = {
214
+ id: `note-${now}-${Math.random().toString(36).slice(2, 6)}`,
204
215
  text: trimmed,
205
- createdAt: Date.now(),
206
- });
207
- s.updatedAt = Date.now();
216
+ ...(context ? { context } : {}),
217
+ createdAt: now,
218
+ };
219
+ s.notes.push(note);
220
+ s.updatedAt = now;
208
221
  this.notify();
209
- return true;
222
+ return note;
210
223
  }
211
224
  nextId(prefix) {
212
225
  return `${prefix}-${this.idCounter++}`;
@@ -240,6 +253,12 @@ export class WorkspaceStore {
240
253
  case "ask":
241
254
  surface = this.buildAsk(id, input, existingNotes, createdAt, now);
242
255
  break;
256
+ case "ui":
257
+ surface = this.buildUi(id, input, existing, existingNotes, createdAt, now);
258
+ break;
259
+ case "app":
260
+ surface = this.buildApp(id, input, existing, existingNotes, createdAt, now);
261
+ break;
243
262
  }
244
263
  const idx = this.surfaces.findIndex((s) => s.id === id);
245
264
  if (idx >= 0) {
@@ -248,7 +267,11 @@ export class WorkspaceStore {
248
267
  else {
249
268
  this.surfaces.push(surface);
250
269
  }
251
- const shouldFocus = input.focus ?? (this.surfaces.length === 1 || input.kind === "ask" || idx < 0);
270
+ const shouldFocus = input.focus ??
271
+ (this.surfaces.length === 1 ||
272
+ input.kind === "ask" ||
273
+ ((input.kind === "ui" || input.kind === "app") && Boolean(input.wait)) ||
274
+ idx < 0);
252
275
  if (shouldFocus) {
253
276
  this.activeId = surface.id;
254
277
  surface.unread = false;
@@ -351,6 +374,198 @@ export class WorkspaceStore {
351
374
  w.resolve(answer);
352
375
  }
353
376
  }
377
+ setUiValue(surfaceId, key, value) {
378
+ const s = this.get(surfaceId);
379
+ if (!s || s.kind !== "ui")
380
+ return false;
381
+ s.state[key] = value;
382
+ s.updatedAt = Date.now();
383
+ this.notify();
384
+ return true;
385
+ }
386
+ recordUiAction(surfaceId, action) {
387
+ const s = this.get(surfaceId);
388
+ if (!s || s.kind !== "ui")
389
+ return false;
390
+ const now = Date.now();
391
+ s.lastAction = { action, at: now };
392
+ s.updatedAt = now;
393
+ this.setToast(`Action: ${action} (press 's' to send state to agent)`, "info", 2200);
394
+ return true;
395
+ }
396
+ hasUiWaiter(surfaceId) {
397
+ return (this.uiWaiters.get(surfaceId)?.length ?? 0) > 0;
398
+ }
399
+ submitUi(surfaceId, action) {
400
+ const s = this.get(surfaceId);
401
+ if (!s || s.kind !== "ui")
402
+ return false;
403
+ const now = Date.now();
404
+ const submission = {
405
+ status: "submitted",
406
+ action,
407
+ state: { ...s.state },
408
+ submittedAt: now,
409
+ };
410
+ s.submission = submission;
411
+ s.lastAction = { action, at: now };
412
+ s.updatedAt = now;
413
+ this.resolveUiWaiters(surfaceId, submission);
414
+ this.setToast(`Submitted: ${s.title} (${action})`, "success");
415
+ return true;
416
+ }
417
+ cancelUi(surfaceId) {
418
+ const s = this.get(surfaceId);
419
+ if (!s || s.kind !== "ui")
420
+ return false;
421
+ const submission = { status: "cancelled", submittedAt: Date.now() };
422
+ s.submission = submission;
423
+ s.updatedAt = submission.submittedAt;
424
+ this.resolveUiWaiters(surfaceId, submission);
425
+ this.setToast(`Cancelled: ${s.title}`, "info");
426
+ return true;
427
+ }
428
+ waitForUi(surfaceId, timeoutMs) {
429
+ const s = this.get(surfaceId);
430
+ if (!s || s.kind !== "ui") {
431
+ return Promise.resolve({ status: "cancelled", submittedAt: Date.now() });
432
+ }
433
+ if (s.submission.status === "submitted" || s.submission.status === "cancelled") {
434
+ return Promise.resolve(s.submission);
435
+ }
436
+ return new Promise((resolvePromise) => {
437
+ const waiter = { resolve: resolvePromise };
438
+ if (timeoutMs && timeoutMs > 0) {
439
+ waiter.timer = setTimeout(() => {
440
+ const list = this.uiWaiters.get(surfaceId);
441
+ if (list) {
442
+ const i = list.indexOf(waiter);
443
+ if (i >= 0)
444
+ list.splice(i, 1);
445
+ }
446
+ resolvePromise({ status: "pending" });
447
+ }, timeoutMs);
448
+ }
449
+ const list = this.uiWaiters.get(surfaceId) ?? [];
450
+ list.push(waiter);
451
+ this.uiWaiters.set(surfaceId, list);
452
+ });
453
+ }
454
+ resolveUiWaiters(surfaceId, submission) {
455
+ const list = this.uiWaiters.get(surfaceId);
456
+ if (!list)
457
+ return;
458
+ this.uiWaiters.delete(surfaceId);
459
+ for (const w of list) {
460
+ if (w.timer)
461
+ clearTimeout(w.timer);
462
+ w.resolve(submission);
463
+ }
464
+ }
465
+ setAppState(surfaceId, nextState, customSummary) {
466
+ const s = this.get(surfaceId);
467
+ if (!s || s.kind !== "app")
468
+ return false;
469
+ s.state = { ...nextState };
470
+ if (customSummary !== undefined)
471
+ s.customSummary = customSummary || undefined;
472
+ s.updatedAt = Date.now();
473
+ this.notify();
474
+ return true;
475
+ }
476
+ setAppMeta(surfaceId, meta) {
477
+ const s = this.get(surfaceId);
478
+ if (!s || s.kind !== "app")
479
+ return false;
480
+ if (meta.hints !== undefined)
481
+ s.hints = meta.hints;
482
+ if (meta.captureKeys !== undefined)
483
+ s.captureKeys = meta.captureKeys;
484
+ if (meta.customSummary !== undefined)
485
+ s.customSummary = meta.customSummary || undefined;
486
+ this.notify();
487
+ return true;
488
+ }
489
+ setAppRuntime(surfaceId, status, error) {
490
+ const s = this.get(surfaceId);
491
+ if (!s || s.kind !== "app")
492
+ return false;
493
+ s.runtimeStatus = status;
494
+ s.runtimeError = error;
495
+ s.updatedAt = Date.now();
496
+ this.notify();
497
+ return true;
498
+ }
499
+ hasAppWaiter(surfaceId) {
500
+ return (this.appWaiters.get(surfaceId)?.length ?? 0) > 0;
501
+ }
502
+ submitApp(surfaceId, action, state) {
503
+ const s = this.get(surfaceId);
504
+ if (!s || s.kind !== "app")
505
+ return false;
506
+ if (state)
507
+ s.state = { ...state };
508
+ const now = Date.now();
509
+ const submission = {
510
+ status: "submitted",
511
+ action,
512
+ state: { ...s.state },
513
+ submittedAt: now,
514
+ };
515
+ s.submission = submission;
516
+ s.updatedAt = now;
517
+ this.resolveAppWaiters(surfaceId, submission);
518
+ this.setToast(`Submitted: ${s.title} (${action})`, "success");
519
+ return true;
520
+ }
521
+ cancelApp(surfaceId) {
522
+ const s = this.get(surfaceId);
523
+ if (!s || s.kind !== "app")
524
+ return false;
525
+ const submission = { status: "cancelled", submittedAt: Date.now() };
526
+ s.submission = submission;
527
+ s.updatedAt = submission.submittedAt;
528
+ this.resolveAppWaiters(surfaceId, submission);
529
+ this.setToast(`Cancelled: ${s.title}`, "info");
530
+ return true;
531
+ }
532
+ waitForApp(surfaceId, timeoutMs) {
533
+ const s = this.get(surfaceId);
534
+ if (!s || s.kind !== "app") {
535
+ return Promise.resolve({ status: "cancelled", submittedAt: Date.now() });
536
+ }
537
+ if (s.submission.status === "submitted" || s.submission.status === "cancelled") {
538
+ return Promise.resolve(s.submission);
539
+ }
540
+ return new Promise((resolvePromise) => {
541
+ const waiter = { resolve: resolvePromise };
542
+ if (timeoutMs && timeoutMs > 0) {
543
+ waiter.timer = setTimeout(() => {
544
+ const list = this.appWaiters.get(surfaceId);
545
+ if (list) {
546
+ const i = list.indexOf(waiter);
547
+ if (i >= 0)
548
+ list.splice(i, 1);
549
+ }
550
+ resolvePromise({ status: "pending" });
551
+ }, timeoutMs);
552
+ }
553
+ const list = this.appWaiters.get(surfaceId) ?? [];
554
+ list.push(waiter);
555
+ this.appWaiters.set(surfaceId, list);
556
+ });
557
+ }
558
+ resolveAppWaiters(surfaceId, submission) {
559
+ const list = this.appWaiters.get(surfaceId);
560
+ if (!list)
561
+ return;
562
+ this.appWaiters.delete(surfaceId);
563
+ for (const w of list) {
564
+ if (w.timer)
565
+ clearTimeout(w.timer);
566
+ w.resolve(submission);
567
+ }
568
+ }
354
569
  buildMarkdown(id, input, notes, createdAt, now) {
355
570
  return {
356
571
  id,
@@ -569,6 +784,76 @@ export class WorkspaceStore {
569
784
  updatedAt: now,
570
785
  };
571
786
  }
787
+ buildUi(id, input, existing, notes, createdAt, now) {
788
+ const prev = existing && existing.kind === "ui" ? existing : undefined;
789
+ const root = input.root ?? input.body ?? { type: "text", content: "(empty ui surface)", tone: "muted" };
790
+ const preserve = input.preserveState !== false;
791
+ const state = {
792
+ ...(input.state ?? {}),
793
+ ...(preserve && prev ? prev.state : {}),
794
+ };
795
+ collectUiDefaults(root, state);
796
+ const submission = input.wait
797
+ ? { status: "pending" }
798
+ : prev && prev.submission.status !== "idle"
799
+ ? prev.submission
800
+ : { status: "idle" };
801
+ return {
802
+ id,
803
+ kind: "ui",
804
+ title: input.title || "Interactive UI",
805
+ root,
806
+ state,
807
+ lastAction: prev?.lastAction,
808
+ submission,
809
+ origin: input.origin,
810
+ notes,
811
+ unread: false,
812
+ createdAt,
813
+ updatedAt: now,
814
+ };
815
+ }
816
+ buildApp(id, input, existing, notes, createdAt, now) {
817
+ const prev = existing && existing.kind === "app" ? existing : undefined;
818
+ const resolvedPath = input.path ? resolve(input.path) : undefined;
819
+ const hasNewSource = Boolean(resolvedPath || input.code !== undefined);
820
+ const entryPath = resolvedPath ?? (input.code !== undefined ? undefined : prev?.entryPath);
821
+ const code = input.code !== undefined ? input.code : resolvedPath ? undefined : prev?.code;
822
+ // Live state patch onto an existing running app without restarting its worker when no new source was sent.
823
+ const stateOnlyUpdate = Boolean(prev && !hasNewSource);
824
+ const revision = prev ? (stateOnlyUpdate ? prev.revision : prev.revision + 1) : 1;
825
+ const stateRevision = prev ? (input.state ? prev.stateRevision + 1 : prev.stateRevision) : 1;
826
+ const state = stateOnlyUpdate
827
+ ? { ...prev.state, ...(input.state ?? {}) }
828
+ : { ...(input.state ?? {}) };
829
+ const submission = input.wait
830
+ ? { status: "pending" }
831
+ : prev && prev.submission.status !== "idle" && stateOnlyUpdate
832
+ ? prev.submission
833
+ : { status: "idle" };
834
+ const defaultTitle = entryPath ? basename(entryPath) : "Custom App";
835
+ return {
836
+ id,
837
+ kind: "app",
838
+ title: input.title || prev?.title || defaultTitle,
839
+ entryPath,
840
+ code,
841
+ revision,
842
+ stateRevision,
843
+ state,
844
+ customSummary: stateOnlyUpdate ? prev?.customSummary : undefined,
845
+ hints: stateOnlyUpdate ? prev?.hints : undefined,
846
+ captureKeys: stateOnlyUpdate ? prev?.captureKeys : undefined,
847
+ submission,
848
+ runtimeStatus: stateOnlyUpdate ? prev.runtimeStatus : "starting",
849
+ runtimeError: stateOnlyUpdate ? prev?.runtimeError : undefined,
850
+ origin: input.origin ?? prev?.origin,
851
+ notes,
852
+ unread: false,
853
+ createdAt,
854
+ updatedAt: now,
855
+ };
856
+ }
572
857
  listSummaries() {
573
858
  return this.surfaces.map((s) => ({
574
859
  id: s.id,
@@ -579,7 +864,17 @@ export class WorkspaceStore {
579
864
  notesCount: s.notes.length,
580
865
  updatedAt: s.updatedAt,
581
866
  origin: s.origin,
582
- status: s.kind === "ask" ? s.answer.status : undefined,
867
+ status: s.kind === "ask"
868
+ ? s.answer.status
869
+ : s.kind === "ui" && s.submission.status !== "idle"
870
+ ? s.submission.status
871
+ : s.kind === "app"
872
+ ? s.runtimeStatus === "error"
873
+ ? "error"
874
+ : s.submission.status !== "idle"
875
+ ? s.submission.status
876
+ : s.runtimeStatus
877
+ : undefined,
583
878
  }));
584
879
  }
585
880
  serializeSurface(surface) {
@@ -587,6 +882,10 @@ export class WorkspaceStore {
587
882
  const { rgba: _omit, ...rest } = surface;
588
883
  return { ...rest, hasPixels: Boolean(surface.rgba) };
589
884
  }
885
+ if (surface.kind === "app") {
886
+ const { code: rawCode, ...rest } = surface;
887
+ return { ...rest, hasInlineCode: Boolean(rawCode), codeLength: rawCode?.length ?? 0 };
888
+ }
590
889
  if (surface.kind === "table") {
591
890
  const selected = surface.rows.find((r) => r.id === surface.selectedRowId);
592
891
  const highlighted = surface.rows.find((r) => r.id === surface.highlightedRowId);
@@ -656,12 +955,98 @@ export function sortTableRows(surface) {
656
955
  });
657
956
  return rows;
658
957
  }
958
+ function compactQuote(raw, maxLen = 120) {
959
+ const flat = raw.replace(/\s+/g, " ").trim();
960
+ if (flat.length <= maxLen)
961
+ return `"${flat}"`;
962
+ return `"${flat.slice(0, Math.max(1, maxLen - 1)).trimEnd()}…"`;
963
+ }
964
+ /**
965
+ * Captures a concise snapshot of the surface's active state/selection at the moment a note is created.
966
+ */
967
+ export function captureNoteContext(surface) {
968
+ if (surface.kind === "ui") {
969
+ const entries = Object.entries(surface.state);
970
+ if (entries.length === 0)
971
+ return undefined;
972
+ return entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
973
+ }
974
+ if (surface.kind === "app") {
975
+ if (surface.customSummary)
976
+ return surface.customSummary;
977
+ const entries = Object.entries(surface.state);
978
+ if (entries.length === 0)
979
+ return undefined;
980
+ return entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
981
+ }
982
+ if (surface.kind === "table") {
983
+ const row = surface.rows.find((r) => r.id === surface.selectedRowId) ??
984
+ surface.rows.find((r) => r.id === surface.highlightedRowId);
985
+ if (row) {
986
+ const first = row.cells[0] ?? row.id;
987
+ const second = row.cells[1];
988
+ return second ? `${first} (${second})` : first;
989
+ }
990
+ return surface.filter ? `filter="${surface.filter}"` : undefined;
991
+ }
992
+ if (surface.kind === "file") {
993
+ const name = basename(surface.path);
994
+ if (surface.selection?.text) {
995
+ const s = surface.selection.startLine;
996
+ const e = surface.selection.endLine;
997
+ const range = s !== undefined ? `:L${s}${e && e !== s ? `-${e}` : ""}` : "";
998
+ return `${name}${range} ${compactQuote(surface.selection.text, 80)}`;
999
+ }
1000
+ if (surface.highlightStart !== undefined) {
1001
+ const range = surface.highlightEnd && surface.highlightEnd !== surface.highlightStart
1002
+ ? `L${surface.highlightStart}-${surface.highlightEnd}`
1003
+ : `L${surface.highlightStart}`;
1004
+ return `${name}:${range}`;
1005
+ }
1006
+ return name;
1007
+ }
1008
+ if (surface.kind === "markdown") {
1009
+ if (surface.selection?.text) {
1010
+ return compactQuote(surface.selection.text, 100);
1011
+ }
1012
+ if (surface.checklist.length > 0) {
1013
+ const done = surface.checklist.filter((c) => c.checked).length;
1014
+ return `${done}/${surface.checklist.length} checked`;
1015
+ }
1016
+ return undefined;
1017
+ }
1018
+ if (surface.kind === "log") {
1019
+ return surface.filter ? `filter="${surface.filter}"` : undefined;
1020
+ }
1021
+ if (surface.kind === "ask") {
1022
+ return surface.answer.status === "submitted"
1023
+ ? `answer=${JSON.stringify(surface.answer.value)}`
1024
+ : undefined;
1025
+ }
1026
+ return undefined;
1027
+ }
1028
+ function shallowStateEqual(a, b) {
1029
+ const ka = Object.keys(a);
1030
+ const kb = Object.keys(b);
1031
+ if (ka.length !== kb.length)
1032
+ return false;
1033
+ for (const k of ka) {
1034
+ if (JSON.stringify(a[k]) !== JSON.stringify(b[k]))
1035
+ return false;
1036
+ }
1037
+ return true;
1038
+ }
659
1039
  /**
660
- * Formats a compact, clean feedback message for human -> agent push-back (`s` hotkey).
1040
+ * Formats a compact, clean feedback message for human -> agent push-back.
1041
+ * By default omits notes already transmitted to the agent pane so consecutive sends never duplicate them.
661
1042
  */
662
- export function formatFeedbackSummary(surface) {
1043
+ export function formatFeedbackSummary(surface, options) {
1044
+ const singleNote = options?.singleNote;
663
1045
  const lines = [`[bypane · ${surface.title} (${surface.kind})]`];
664
1046
  if (surface.kind === "markdown") {
1047
+ if (surface.selection?.text) {
1048
+ lines.push(`Quote: ${compactQuote(surface.selection.text, 280)}`);
1049
+ }
665
1050
  if (surface.checklist.length > 0) {
666
1051
  const done = surface.checklist.filter((c) => c.checked).map((c) => c.text);
667
1052
  const todo = surface.checklist.filter((c) => !c.checked).map((c) => c.text);
@@ -672,10 +1057,13 @@ export function formatFeedbackSummary(surface) {
672
1057
  }
673
1058
  }
674
1059
  else if (surface.kind === "file") {
675
- const range = surface.highlightStart !== undefined
676
- ? `:${surface.highlightStart}${surface.highlightEnd && surface.highlightEnd !== surface.highlightStart ? `-${surface.highlightEnd}` : ""}`
677
- : "";
1060
+ const start = surface.selection?.startLine ?? surface.highlightStart;
1061
+ const end = surface.selection?.endLine ?? surface.highlightEnd;
1062
+ const range = start !== undefined ? `:${start}${end && end !== start ? `-${end}` : ""}` : "";
678
1063
  lines.push(`File: ${surface.path}${range}`);
1064
+ if (surface.selection?.text) {
1065
+ lines.push(`Quote: ${compactQuote(surface.selection.text, 280)}`);
1066
+ }
679
1067
  }
680
1068
  else if (surface.kind === "image") {
681
1069
  lines.push(`Image: ${surface.path}`);
@@ -710,10 +1098,49 @@ export function formatFeedbackSummary(surface) {
710
1098
  lines.push(`Status: ${surface.answer.status}`);
711
1099
  }
712
1100
  }
713
- if (surface.notes.length > 0) {
714
- lines.push("Notes:");
715
- for (const n of surface.notes) {
716
- lines.push(`- ${n.text}`);
1101
+ else if (surface.kind === "ui") {
1102
+ const entries = Object.entries(surface.state);
1103
+ if (entries.length > 0) {
1104
+ const formatted = entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
1105
+ lines.push(`State: ${formatted}`);
1106
+ }
1107
+ if (!singleNote) {
1108
+ if (surface.submission.status === "submitted" &&
1109
+ shallowStateEqual(surface.state, surface.submission.state)) {
1110
+ lines.push(`Submitted action: ${surface.submission.action}`);
1111
+ }
1112
+ else if (surface.lastAction && surface.submission.status !== "submitted") {
1113
+ lines.push(`Last action: ${surface.lastAction.action}`);
1114
+ }
1115
+ }
1116
+ }
1117
+ else if (surface.kind === "app") {
1118
+ if (surface.customSummary) {
1119
+ lines.push(`Summary: ${surface.customSummary}`);
1120
+ }
1121
+ const entries = Object.entries(surface.state);
1122
+ if (entries.length > 0) {
1123
+ const formatted = entries.map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
1124
+ lines.push(`State: ${formatted}`);
1125
+ }
1126
+ if (!singleNote &&
1127
+ surface.submission.status === "submitted" &&
1128
+ shallowStateEqual(surface.state, surface.submission.state)) {
1129
+ lines.push(`Submitted action: ${surface.submission.action}`);
1130
+ }
1131
+ }
1132
+ if (singleNote) {
1133
+ lines.push(`Note: ${singleNote.text}`);
1134
+ }
1135
+ else {
1136
+ const notes = options?.includeAllNotes
1137
+ ? surface.notes
1138
+ : surface.notes.filter((n) => n.sentAt === undefined);
1139
+ if (notes.length > 0) {
1140
+ lines.push("Notes:");
1141
+ for (const n of notes) {
1142
+ lines.push(`- ${n.context ? `[${n.context}] ` : ""}${n.text}`);
1143
+ }
717
1144
  }
718
1145
  }
719
1146
  return lines.join("\n");