pi-bro 0.37.0 → 0.38.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 (43) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +18 -22
  3. package/docs/README.md +7 -7
  4. package/docs/elevate.md +10 -93
  5. package/docs/examples.md +1 -1
  6. package/docs/feature-map.md +33 -0
  7. package/docs/features/architecture.md +1 -1
  8. package/docs/features/elevate.md +122 -0
  9. package/docs/features/explain.md +16 -20
  10. package/docs/features/grill-me.md +65 -0
  11. package/docs/features/guided-review.md +150 -0
  12. package/docs/features/overthink.md +66 -0
  13. package/docs/features/remember-me.md +92 -0
  14. package/docs/features/show.md +9 -15
  15. package/docs/getting-started.md +5 -5
  16. package/docs/grill-me.md +5 -51
  17. package/docs/guided-review.md +14 -113
  18. package/docs/overthink.md +7 -46
  19. package/docs/piG-agent-shell-qualification.md +3 -3
  20. package/docs/pig-compatibility.md +1 -1
  21. package/docs/reference/commands.md +18 -33
  22. package/docs/reference/data-and-permissions.md +9 -9
  23. package/docs/reference/settings.md +8 -8
  24. package/docs/reference/troubleshooting.md +3 -3
  25. package/docs/remember-me.md +6 -75
  26. package/docs/user-guide.md +4 -4
  27. package/package.json +6 -4
  28. package/src/advisor.ts +1 -1
  29. package/src/architecture.ts +1 -1
  30. package/src/backend.ts +1 -0
  31. package/src/bro.ts +47 -189
  32. package/src/btw.ts +10 -199
  33. package/src/composer-modal.ts +197 -0
  34. package/src/explain-modal.ts +28 -79
  35. package/src/grill.ts +3 -2
  36. package/src/overthink-state.ts +3 -3
  37. package/src/overthink.ts +2 -2
  38. package/src/remember.ts +3 -2
  39. package/src/session-state.ts +46 -28
  40. package/src/settings.ts +11 -3
  41. package/src/simplify-engine.ts +50 -24
  42. package/src/simplify-ui.ts +165 -126
  43. package/src/sources.ts +3 -3
@@ -1,5 +1,4 @@
1
1
  import { rm, writeFile } from "node:fs/promises";
2
- import { stripVTControlCharacters } from "node:util";
3
2
  import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
4
3
  import { copyToClipboard, getMarkdownTheme, getSelectListTheme } from "@earendil-works/pi-coding-agent";
5
4
  import {
@@ -19,7 +18,6 @@ import {
19
18
  MAX_PREFERENCES_CHARS,
20
19
  STARTER_PREFERENCES,
21
20
  buildDefaultPrompt,
22
- nextBroMode,
23
21
  } from "./prompt.ts";
24
22
  import {
25
23
  type BroSettings,
@@ -34,20 +32,20 @@ import {
34
32
  selectionLabel,
35
33
  settingsFile,
36
34
  } from "./settings.ts";
37
- import { openShowHtml, stripShowDiagramFence } from "./show.ts";
35
+ import { openShowHtml } from "./show.ts";
38
36
  import type { BroSource } from "./sources.ts";
39
37
  import { BRO_OVERLAY, broOverlayArea, delegateMouse, formatNotice, modalHeight, openBroOverlay, renderFrame, runningHint, Scroller, startProgressClock, type Area, type NoticeTone, type Theme, type TuiLike } from "./modal-kit.ts";
40
38
  import { hasBroCustomUi, type BroMouseEvent, type BroMouseResult } from "./ui-capabilities.ts";
41
39
  import { errorMessage } from "./util.ts";
42
40
  import { latestCompletedAssistantText } from "./last-assistant.ts";
43
41
 
44
- const LOADING_TEXT = "Simplifying for my bro…";
42
+ const LOADING_TEXT = "Working…";
45
43
 
46
44
  export type ModalKind = "loading" | "streaming" | "result" | "help" | "empty" | "error";
47
45
  // `mode` is the built-in explain mode that produced the text; absent for Show and Doctor.
48
46
  // `preferences` records whether bro-preferences.md shaped this result; like `mode`, it belongs to the result.
49
47
  export type BroResult = { source: BroSource; text: string; model?: string; mode?: BroMode; preferences?: boolean };
50
- export type ModalResult = { source?: BroSource; text: string; htmlPath?: string; model?: string; mode?: BroMode; preferences?: boolean };
48
+ export type ModalResult = { text: string; htmlPath?: string; model?: string; preferences?: boolean };
51
49
 
52
50
  export function latestAssistant(ctx: ExtensionCommandContext): BroSource | undefined {
53
51
  const text = latestCompletedAssistantText(ctx.sessionManager.getBranch())?.trim();
@@ -372,23 +370,19 @@ Quick reference. Full user guide: https://github.com/tranhoangnguyen03/pi-bro/bl
372
370
 
373
371
  ## Pick by need
374
372
 
375
- - **Understand what already exists:** Simplify and Show; Architecture for this repository.
373
+ - **Understand what already exists:** Simplify for plain words or diagrams; Architecture for this repository.
376
374
  - **Explore what could exist:** BTW for side questions; Grill Me for decisions.
377
375
  - **Get advice on existing work:** Guided Review; Overthink for automatic second looks; agent-facing Advisor.
378
376
  - **Guide the agent:** Elevate for assignments; Remember Me for approved context (about_user); Advisor Steering for priorities.
379
377
 
380
378
  These are needs, not modes. Copied text does not enter Pi until you paste and submit it.
381
379
 
382
- ## Explain and show
380
+ ## Simplify: understand in words or diagrams
383
381
 
384
- - \`/bro\` — read the saved explanation, or help if none exists; /simplify inside runs again
385
- - \`/bro simplify\` — reopen the current Simplify screen without another model call
386
- - \`/bro text [text]\` — explain pasted text, or the latest reply when text is omitted
387
- - \`/bro file <path>\` — explain a local \`.md\`, \`.markdown\`, \`.txt\`, \`.pdf\`, or \`.docx\` file
388
- - \`/bro url <url>\` — explain one public webpage
389
- - \`/bro <input>\` — a lone URL, an existing supported file, or anything else as pasted text
390
- - Inside Simplify: \`/simplify\`, \`/text <text>\`, \`/file <path>\`, \`/url <url>\`, \`/copy\`, \`/clear\`, \`/help\`. **M** changes the mode and re-explains; **R** retries. One source at a time, no chat thread.\n- \`/bro open\` — legacy last-result view (retained for compatibility)
391
- - \`/bro show [n-turns] [query]\` — draw recent turns' conversation text as shapes; an optional query steers the focus
382
+ - \`/bro\` or \`/bro simplify\` — reopen the saved result, or help if empty; no new model call.
383
+ - Inside Simplify, \`/simplify\` explains the latest reply; \`/text <text>\`, \`/file <path>\` and \`/url <url>\` explain another source. \`/show [n-turns] [query]\` draws recent conversation text.
384
+ - Use \`/bro simplify latest\` or \`/bro simplify text|file|url|show …\` to run directly, including without the viewer.
385
+ - \`/copy\`, \`/clear\`, and \`/help\` apply to both forms. One source and one saved result, no chat thread.
392
386
 
393
387
  - \`/bro copy\` — edit and preview the last reply before copying raw Markdown.
394
388
 
@@ -401,21 +395,21 @@ These are needs, not modes. Copied text does not enter Pi until you paste and su
401
395
  - \`/bro guided-review <PR number or URL>\` — assess captured PR code in local interactive Pi (requires Git and authenticated gh).
402
396
  - Reviews save automatically. Reopen without a model call; bare \`/bro guided-review\` lists saved reviews.\n- \`/bro guided-review delete [PR number or URL]\` — delete one local saved review with confirmation; Overview also offers Delete review.
403
397
  - Enter opens items or activates focused actions. Tab changes focus; Esc goes back, then closes from Contents. Close saves; Stop and close cancels active work first.
404
- - Copy finding goes to the clipboard, not GitHub. Regenerate reuses captured source. For untrusted PRs, choose file-only Claude/Muse/Pi; Codex/Grok offer sandboxed shell, while Agy may write captured files. Bro warns when shell is allowed. See docs/guided-review.md.
398
+ - Copy finding goes to the clipboard, not GitHub. Regenerate reuses captured source. For untrusted PRs, choose file-only Claude/Muse/Pi; Codex/Grok offer sandboxed shell, while Agy may write captured files. Bro warns when shell is allowed. See docs/features/guided-review.md.
405
399
 
406
400
  ## Elevate
407
401
 
408
402
  - \`/bro elevate [request]\` — improve a task before sending it. Ctrl+Shift+E uses the draft. Choose Messages/Full context; Space/Enter ticks findings; Tab focuses actions.
409
403
  - Enter adds a line; Ctrl+S or Ctrl+Enter discovers gaps. Use labelled buttons for actions.
410
- - Shares BTW settings; see docs/elevate.md.
404
+ - Shares BTW settings; see docs/features/elevate.md.
411
405
 
412
406
  ## Grill Me (experimental)
413
407
 
414
- - \`/bro grill-me [topic]\` — private decision interview. Use /consolidate, /copy or /help. Full-access risk: docs/grill-me.md.
408
+ - \`/bro grill-me [topic]\` — private decision interview. Use /consolidate, /copy or /help. Full-access risk: docs/features/grill-me.md.
415
409
 
416
410
  ## Overthink
417
411
 
418
- - \`/bro overthink\` — view private automatic second-look notes without a model call. Ctrl+R retries; Ctrl+E edits session questions; Ctrl+C copies. Uses the active Pi model. Turn off or edit defaults in \`/bro config\` → Features → Overthink. See docs/overthink.md.
412
+ - \`/bro overthink\` — view private second-look notes without a model call. Ctrl+R checks now; Ctrl+E edits session questions; Ctrl+C copies. Enable automatic checks in \`/bro config\` → Features → Overthink. See docs/features/overthink.md.
419
413
 
420
414
  ## Side conversation
421
415
 
@@ -473,7 +467,6 @@ export class BroModal implements Focusable {
473
467
  private readonly markdown = new Markdown("", 0, 0, getMarkdownTheme());
474
468
  private kind: ModalKind = "loading";
475
469
  private rawText = "";
476
- private sourceLabel = "";
477
470
  private modelLabel = "";
478
471
  private noticeText = "";
479
472
  private noticeTone: NoticeTone = "info";
@@ -487,8 +480,6 @@ export class BroModal implements Focusable {
487
480
  private retryable = false;
488
481
  private disposed = false;
489
482
  private htmlPath = "";
490
- // Survives loading/streaming so the header names the mode being produced; empty disables M.
491
- private modeLabel = "";
492
483
  // Set only with a result, so the tag never claims preferences for work still in flight.
493
484
  private preferencesUsed = false;
494
485
 
@@ -499,7 +490,6 @@ export class BroModal implements Focusable {
499
490
  private readonly onRetry: () => void,
500
491
  private readonly onDispose: () => void,
501
492
  private readonly retryLabel: string,
502
- private readonly onSwitchMode: () => void = () => {},
503
493
  ) {}
504
494
 
505
495
  setLoading(text = LOADING_TEXT): void {
@@ -518,8 +508,8 @@ export class BroModal implements Focusable {
518
508
  this.setNotice(text);
519
509
  }
520
510
 
521
- setResult(text: string, retryable: boolean, notice = "", sourceLabel = "", rawText = text, modelLabel = "", noticeTone: NoticeTone = "info"): void {
522
- this.setContent("result", text, rawText, true, retryable, notice, sourceLabel, modelLabel, noticeTone);
511
+ setResult(text: string, retryable: boolean, notice = "", modelLabel = "", noticeTone: NoticeTone = "info"): void {
512
+ this.setContent("result", text, text, true, retryable, notice, modelLabel, noticeTone);
523
513
  }
524
514
 
525
515
  setNotice(text: string, tone: NoticeTone = "info"): void {
@@ -540,11 +530,6 @@ export class BroModal implements Focusable {
540
530
  this.tui.requestRender();
541
531
  }
542
532
 
543
- setMode(mode: BroMode | undefined): void {
544
- this.modeLabel = mode ?? "";
545
- this.tui.requestRender();
546
- }
547
-
548
533
  setPreferences(used: boolean): void {
549
534
  this.preferencesUsed = used;
550
535
  this.tui.requestRender();
@@ -565,7 +550,6 @@ export class BroModal implements Focusable {
565
550
  copyable: boolean,
566
551
  retryable: boolean,
567
552
  notice = "",
568
- sourceLabel = "",
569
553
  modelLabel = "",
570
554
  noticeTone: NoticeTone = "info",
571
555
  ): void {
@@ -577,33 +561,24 @@ export class BroModal implements Focusable {
577
561
  this.retryable = retryable;
578
562
  this.noticeText = notice;
579
563
  this.noticeTone = noticeTone;
580
- this.sourceLabel = stripVTControlCharacters(sourceLabel)
581
- .replace(/[\u0000-\u001f\u007f-\u009f]/g, " ")
582
- .replace(/\s+/g, " ")
583
- .trim();
584
564
  this.modelLabel = modelLabel;
585
565
  if (kind !== "streaming") this.scroller.toStart();
586
566
  this.markdown.setText(text);
587
567
  this.tui.requestRender();
588
568
  }
589
569
 
590
- private canSwitchMode(): boolean {
591
- return Boolean(this.modeLabel) && (this.kind === "loading" || this.kind === "streaming" || this.kind === "result");
592
- }
593
-
594
570
  private controls(innerWidth: number): string {
595
- const mode = this.canSwitchMode() ? " · M mode" : "";
596
571
  if (this.kind === "loading" || this.kind === "streaming") {
597
572
  // The elapsed seconds and Esc matter more than a long stage name.
598
573
  // Keep one hint row so the body never jumps as that stage changes.
599
574
  const scroll = this.kind === "streaming" ? " · ↑/↓ scroll" : "";
600
575
  const phase = this.progressText || (this.kind === "loading" ? "Working…" : "Receiving output…");
601
576
  return runningHint(phase, innerWidth, [
602
- `${scroll}${mode} · Esc cancel`, `${mode} · Esc cancel`, " · Esc cancel",
577
+ `${scroll} · Esc cancel`, " · Esc cancel",
603
578
  ], 12);
604
579
  }
605
580
  if (this.kind === "result") {
606
- return `↑/↓ scroll · C copy${this.htmlPath ? " · O open diagram" : ""}${mode}${this.retryable ? ` · R ${this.retryLabel}` : ""} · Esc close`;
581
+ return `↑/↓ scroll · C copy${this.htmlPath ? " · O open diagram" : ""}${this.retryable ? ` · R ${this.retryLabel}` : ""} · Esc close`;
607
582
  }
608
583
  if (this.kind === "help") return "↑/↓ scroll · C copy · Esc close";
609
584
  if (this.kind === "error") return "R try again · Esc close";
@@ -617,8 +592,8 @@ export class BroModal implements Focusable {
617
592
  header: () => {
618
593
  const scroll = this.scroller.indicator();
619
594
  return (
620
- this.theme.fg("accent", this.theme.bold(`Bro${this.sourceLabel ? ` · ${this.sourceLabel}` : ""}`)) +
621
- this.theme.fg("dim", `${this.modelLabel ? ` · ${this.modelLabel}` : ""}${this.modeLabel ? ` · ${this.modeLabel}` : ""}${this.preferencesUsed ? " · prefs" : ""}${scroll ? ` · ${scroll}` : ""}`)
595
+ this.theme.fg("accent", this.theme.bold("Bro")) +
596
+ this.theme.fg("dim", `${this.modelLabel ? ` · ${this.modelLabel}` : ""}${this.preferencesUsed ? " · prefs" : ""}${scroll ? ` · ${scroll}` : ""}`)
622
597
  );
623
598
  },
624
599
  body: (rows, innerWidth) => this.scroller.view(this.markdown.render(innerWidth), rows),
@@ -663,11 +638,6 @@ export class BroModal implements Focusable {
663
638
  return;
664
639
  }
665
640
 
666
- if ((matchesKey(data, "m") || matchesKey(data, "shift+m")) && this.canSwitchMode()) {
667
- this.onSwitchMode();
668
- return;
669
- }
670
-
671
641
  if ((matchesKey(data, "o") || matchesKey(data, "shift+o")) && this.htmlPath && this.kind === "result") {
672
642
  const opened = openShowHtml(this.htmlPath);
673
643
  this.setNotice(
@@ -691,9 +661,7 @@ export interface BroModalOptions {
691
661
  result?: ModalResult;
692
662
  run?: (
693
663
  signal: AbortSignal,
694
- source?: BroSource,
695
664
  onProgress?: (text: string) => void,
696
- mode?: BroMode,
697
665
  ) => Promise<ModalResult>;
698
666
  onResult?: (result: ModalResult) => void;
699
667
  loadingText?: string;
@@ -717,8 +685,7 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
717
685
  let controller: AbortController | undefined;
718
686
  let stopProgress: (() => void) | undefined;
719
687
  let current = options.result;
720
- let inFlightMode: BroMode | undefined;
721
- let execute: (source?: BroSource, mode?: BroMode, notice?: string, noticeTone?: NoticeTone) => void = () => {};
688
+
722
689
 
723
690
  const close = () => {
724
691
  if (closed) return;
@@ -732,41 +699,27 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
732
699
  tui,
733
700
  theme,
734
701
  close,
735
- () => execute(current?.source, current?.mode),
702
+ () => execute(),
736
703
  () => {
737
704
  closed = true;
738
705
  stopProgress?.();
739
706
  controller?.abort();
740
707
  },
741
- options.retryLabel ?? "simplify again",
742
- // M advances from the mode in flight, so repeated presses cancel and skip ahead; the saved default is untouched.
743
- () => {
744
- const from = inFlightMode ?? current?.mode;
745
- if (!from || !current?.source || closed) return;
746
- const next = nextBroMode(from);
747
- stopProgress?.();
748
- controller?.abort();
749
- controller = undefined;
750
- execute(current.source, next, `Mode: ${next} (not saved)`);
751
- },
708
+ options.retryLabel ?? "try again",
752
709
  );
753
710
 
754
711
  const present = (result: ModalResult, notice = "", noticeTone: NoticeTone = "info") => {
755
- const display = result.htmlPath ? stripShowDiagramFence(result.text) : result.text;
756
- modal.setResult(display, options.retryable ?? Boolean(options.run), notice, result.source?.label, result.text, result.model, noticeTone);
712
+ modal.setResult(result.text, options.retryable ?? Boolean(options.run), notice, result.model, noticeTone);
757
713
  modal.setHtmlPath(result.htmlPath ?? "");
758
- modal.setMode(result.mode);
759
714
  modal.setPreferences(Boolean(result.preferences));
760
715
  };
761
716
 
762
- execute = (source?: BroSource, mode?: BroMode, notice = "", noticeTone: NoticeTone = "info") => {
717
+ const execute = () => {
763
718
  if (!options.run || controller || closed) return;
764
719
  const previous = current;
765
720
  const nextController = new AbortController();
766
721
  controller = nextController;
767
- inFlightMode = mode;
768
722
  modal.setLoading(options.loadingText);
769
- modal.setMode(mode);
770
723
  modal.setPreferences(false);
771
724
  const phase = options.loadingText ?? "Working";
772
725
  const stop = startProgressClock(nextController.signal, seconds => {
@@ -775,17 +728,17 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
775
728
  stopProgress = stop;
776
729
 
777
730
  void options
778
- .run(nextController.signal, source, (text) => {
731
+ .run(nextController.signal, (text) => {
779
732
  if (closed || nextController.signal.aborted || controller !== nextController) return;
780
733
  // This callback may be a workflow stage (Architecture), not
781
734
  // a streaming answer. The body owns the stage; keep the hint neutral.
782
735
  modal.setStreaming(text);
783
- }, mode)
736
+ })
784
737
  .then((result) => {
785
738
  if (closed || nextController.signal.aborted) return;
786
739
  current = result;
787
740
  options.onResult?.(result);
788
- present(result, notice, noticeTone);
741
+ present(result);
789
742
  })
790
743
  .catch((error) => {
791
744
  if (closed || nextController.signal.aborted) return;
@@ -794,17 +747,13 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
794
747
  current = previous;
795
748
  present(previous, `Retry failed: ${message}`, "error");
796
749
  } else {
797
- modal.setMode(undefined);
798
750
  modal.setError(message);
799
751
  }
800
752
  })
801
753
  .finally(() => {
802
754
  stop();
803
755
  if (stopProgress === stop) stopProgress = undefined;
804
- if (controller === nextController) {
805
- controller = undefined;
806
- inFlightMode = undefined;
807
- }
756
+ if (controller === nextController) controller = undefined;
808
757
  });
809
758
  };
810
759
 
package/src/grill.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { matchesKey } from "@earendil-works/pi-tui";
2
2
  import { copyToClipboard, type ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
3
3
  import { execute as executeBackend } from "./backend.ts";
4
- import { BtwModal, BTW_CONTEXT_MAX, BTW_CONTEXT_TURNS, formatBtwTranscript } from "./btw.ts";
4
+ import { ComposerModal } from "./composer-modal.ts";
5
+ import { BTW_CONTEXT_MAX, BTW_CONTEXT_TURNS, formatBtwTranscript } from "./btw.ts";
5
6
  import {
6
7
  buildGrillPrompt, grillExecution, parseGrillCommand, grillCommandSuggestions,
7
8
  type GrillThread, type GrillTurn,
@@ -60,7 +61,7 @@ export async function openGrillModal(
60
61
  controller?.abort();
61
62
  done(undefined);
62
63
  };
63
- const modal = new BtwModal(tui, theme, close, submit, () => {
64
+ const modal = new ComposerModal(tui, theme, close, submit, () => {
64
65
  closed = true;
65
66
  saveDraft();
66
67
  stopProgress?.();
@@ -121,13 +121,13 @@ export function globalQuestionsFile(dir = getAgentDir()): string {
121
121
  return join(dir, OVERTHINK_DEFAULTS_FILE);
122
122
  }
123
123
  export type OverthinkGlobal = { questions: string[]; automatic: boolean };
124
- /** Missing flag defaults to on, including files written before the on/off switch existed. */
124
+ /** Only an explicitly saved true enables automatic requests. */
125
125
  export async function readGlobalOverthink(dir = getAgentDir()): Promise<OverthinkGlobal> {
126
126
  const file = globalQuestionsFile(dir);
127
127
  let info;
128
128
  try { info = await lstat(file); }
129
129
  catch (error) {
130
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return { questions: [...FACTORY_QUESTIONS], automatic: true };
130
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return { questions: [...FACTORY_QUESTIONS], automatic: false };
131
131
  throw error;
132
132
  }
133
133
  if (!info.isFile() || info.isSymbolicLink() || info.size > 32768) throw new Error("Unsafe or oversized Overthink defaults file: " + file);
@@ -136,7 +136,7 @@ export async function readGlobalOverthink(dir = getAgentDir()): Promise<Overthin
136
136
  (data.automatic !== undefined && typeof data.automatic !== "boolean")) {
137
137
  throw new Error("Unsupported Overthink defaults format: " + file);
138
138
  }
139
- return { questions: checkQuestions(data.questions), automatic: data.automatic ?? true };
139
+ return { questions: checkQuestions(data.questions), automatic: data.automatic ?? false };
140
140
  }
141
141
 
142
142
  export async function readGlobalQuestions(dir = getAgentDir()): Promise<string[]> {
package/src/overthink.ts CHANGED
@@ -133,7 +133,7 @@ export function createOverthinkViewer(
133
133
  };
134
134
  if (help) {
135
135
  [
136
- "Overthink checks settled substantial work using the same Pi model.",
136
+ "Overthink uses the active Pi model. Enable automatic checks in /bro config → Features → Overthink.",
137
137
  "It stays private and only notifies about consequential new concerns.",
138
138
  "",
139
139
  "Ctrl+R Retry with the current session",
@@ -154,7 +154,7 @@ export function createOverthinkViewer(
154
154
  if (busy) {
155
155
  add("Checking the current Pi session…");
156
156
  } else if (!note) {
157
- add("No assessment yet. Bro checks after substantial work; Ctrl+R checks now.");
157
+ add("No assessment yet. Ctrl+R checks now.");
158
158
  } else if (!note.text) {
159
159
  add("No material concerns found in the last check.");
160
160
  } else if (note.assessment) {
package/src/remember.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /** Private, user-controlled workflow for approved personal memories. No durable unfinished drafts. */
2
2
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
3
3
  import { execute as executeBackend } from "./backend.ts";
4
- import { BtwModal, formatBtwTranscript } from "./btw.ts";
4
+ import { ComposerModal } from "./composer-modal.ts";
5
+ import { formatBtwTranscript } from "./btw.ts";
5
6
  import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
6
7
  import { captureShowTranscript } from "./show.ts";
7
8
  import { readPreferences, readSettings, selectionForCapability, selectionLabel } from "./settings.ts";
@@ -56,7 +57,7 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
56
57
  let selectedBackend = openingSelection.backend ?? "agy";
57
58
  let selectedModel = selectionLabel(openingSelection);
58
59
  const close = () => { if (closed) return; closed = true; stopProgress?.(); controller?.abort(); done(undefined); };
59
- const modal = new BtwModal(tui, theme, close, submit, () => { closed = true; stopProgress?.(); controller?.abort(); }, {
60
+ const modal = new ComposerModal(tui, theme, close, submit, () => { closed = true; stopProgress?.(); controller?.abort(); }, {
60
61
  title:"Bro · remember-me", commands:"", inputLabel:"Your memory or correction",
61
62
  idleHint:"Enter discuss · /save approve · /context show · /help",
62
63
  });
@@ -2,8 +2,8 @@
2
2
  import type { SessionEntry } from "@earendil-works/pi-coding-agent";
3
3
  import type { BtwThread } from "./btw.ts";
4
4
  import type { GrillThread } from "./grill-engine.ts";
5
- import type { ModalResult } from "./explain-modal.ts";
6
- import type { SimplifyState } from "./simplify-ui.ts";
5
+ import { parseBroMode } from "./prompt.ts";
6
+ import type { SimplifyResult, SimplifyState } from "./simplify-ui.ts";
7
7
  import { isRecord } from "./util.ts";
8
8
 
9
9
  export const BTW_SESSION_ENTRY = "bro-btw-thread";
@@ -15,16 +15,9 @@ export const LAST_RESULT_SESSION_ENTRY = "bro-last-result";
15
15
  * A tree move rebuilds these signatures from its own branch, not the old one.
16
16
  */
17
17
  export function privateSessionEntrySnapshots(branch: readonly SessionEntry[]): Map<string, string> {
18
- const types = new Set<string>([
19
- BTW_SESSION_ENTRY, GRILL_SESSION_ENTRY, SIMPLIFY_SESSION_ENTRY, LAST_RESULT_SESSION_ENTRY,
20
- ]);
21
- const saved = new Map<string, string>();
22
- for (const entry of branch) {
23
- if (entry.type === "custom" && types.has(entry.customType) && isRecord(entry.data)) {
24
- saved.set(entry.customType, JSON.stringify(entry.data));
25
- }
26
- }
27
- return saved;
18
+ const snapshots = new Map<string, string>();
19
+ restorePrivateBroState(branch, snapshots);
20
+ return snapshots;
28
21
  }
29
22
 
30
23
 
@@ -32,8 +25,6 @@ export type PrivateBroSessionState = {
32
25
  btw?: BtwThread;
33
26
  grill?: GrillThread;
34
27
  simplify: SimplifyState;
35
- lastResult?: ModalResult;
36
- lastShowSteering?: string;
37
28
  };
38
29
 
39
30
  const textTurns = (value: unknown): boolean =>
@@ -53,18 +44,26 @@ function grillThread(value: unknown): GrillThread | undefined {
53
44
  return value as unknown as GrillThread;
54
45
  }
55
46
 
56
- function modalResult(value: unknown): ModalResult | undefined {
57
- if (!isRecord(value) || typeof value.text !== "string") return undefined;
58
- if (value.source !== undefined && (!isRecord(value.source) || typeof value.source.text !== "string")) return undefined;
59
- return value as unknown as ModalResult;
47
+ function simplifyResult(value: unknown, legacySteering?: string): SimplifyResult | undefined {
48
+ if (!isRecord(value) || typeof value.text !== "string" || !isRecord(value.source) || typeof value.source.text !== "string") return undefined;
49
+ const steering = legacySteering ?? (typeof value.showSteering === "string" ? value.showSteering : undefined);
50
+ const mode = steering === undefined ? parseBroMode(value.mode) : undefined;
51
+ return {
52
+ text: value.text,
53
+ source: { text: value.source.text, ...(typeof value.source.label === "string" ? { label: value.source.label } : {}) },
54
+ ...(typeof value.model === "string" ? { model: value.model } : {}),
55
+ ...(typeof value.preferences === "boolean" ? { preferences: value.preferences } : {}),
56
+ ...(mode ? { mode } : {}),
57
+ ...(steering !== undefined ? { showSteering: steering } : {}),
58
+ };
60
59
  }
61
60
 
62
61
  function simplifyState(value: unknown): SimplifyState {
63
62
  if (!isRecord(value)) return {};
64
- const result = modalResult(value.result);
65
- if (value.result !== undefined && !result?.source) return {};
63
+ const result = simplifyResult(value.result);
64
+ if (value.result !== undefined && !result) return {};
66
65
  return {
67
- ...(result ? { result: result as SimplifyState["result"] } : {}),
66
+ ...(result ? { result } : {}),
68
67
  ...(value.view === "result" || value.view === "help" || value.view === "empty" ? { view: value.view } : {}),
69
68
  ...(typeof value.draft === "string" ? { draft: value.draft } : {}),
70
69
  ...(typeof value.error === "string" ? { error: value.error } : {}),
@@ -72,19 +71,38 @@ function simplifyState(value: unknown): SimplifyState {
72
71
  }
73
72
 
74
73
  /** Last matching entry on the active branch wins. A cleared state cannot resurrect. */
75
- export function restorePrivateBroState(branch: readonly SessionEntry[]): PrivateBroSessionState {
74
+ export function restorePrivateBroState(branch: readonly SessionEntry[], snapshots?: Map<string, string>): PrivateBroSessionState {
76
75
  const restored: PrivateBroSessionState = { simplify: {} };
76
+ let hasSimplifySnapshot = false;
77
77
  for (const entry of branch) {
78
78
  if (entry.type !== "custom" || !isRecord(entry.data)) continue;
79
79
  const value = entry.data;
80
80
  switch (entry.customType) {
81
- case BTW_SESSION_ENTRY: restored.btw = btwThread(value.thread); break;
82
- case GRILL_SESSION_ENTRY: restored.grill = grillThread(value.thread); break;
83
- case SIMPLIFY_SESSION_ENTRY: restored.simplify = simplifyState(value.state); break;
84
- case LAST_RESULT_SESSION_ENTRY:
85
- restored.lastResult = modalResult(value.result);
86
- restored.lastShowSteering = typeof value.steering === "string" ? value.steering : undefined;
81
+ case BTW_SESSION_ENTRY:
82
+ restored.btw = btwThread(value.thread);
83
+ snapshots?.set(entry.customType, JSON.stringify(value));
84
+ break;
85
+ case GRILL_SESSION_ENTRY:
86
+ restored.grill = grillThread(value.thread);
87
+ snapshots?.set(entry.customType, JSON.stringify(value));
88
+ break;
89
+ case SIMPLIFY_SESSION_ENTRY:
90
+ hasSimplifySnapshot = true;
91
+ restored.simplify = simplifyState(value.state);
92
+ snapshots?.set(entry.customType, JSON.stringify(value));
93
+ break;
94
+ case LAST_RESULT_SESSION_ENTRY: {
95
+ // Show and old `/bro open` retries wrote only this entry. An old Explain
96
+ // can also be a stale copy, so it must not override a cleared snapshot.
97
+ const steering = typeof value.steering === "string" ? value.steering : undefined;
98
+ if (steering === undefined && hasSimplifySnapshot && !restored.simplify.result) break;
99
+ const result = simplifyResult(value.result, steering);
100
+ if (result && JSON.stringify(result) !== JSON.stringify(restored.simplify.result)) {
101
+ restored.simplify = { result, view: "result", draft: restored.simplify.draft };
102
+ snapshots?.delete(SIMPLIFY_SESSION_ENTRY);
103
+ }
87
104
  break;
105
+ }
88
106
  }
89
107
  }
90
108
  return restored;
package/src/settings.ts CHANGED
@@ -6,10 +6,12 @@ import {
6
6
  type BackendSelection,
7
7
  agySelection,
8
8
  CLAUDE_EFFORTS,
9
+ getPiHostContext,
9
10
  GROK_EFFORTS,
10
11
  CODEX_EFFORTS,
11
12
  MUSE_EFFORTS,
12
13
  PI_EFFORTS,
14
+ piPhysicalModel,
13
15
  } from "./backend.ts";
14
16
  import { type BroMode, DEFAULT_BRO_MODE, MAX_PREFERENCES_CHARS, parseBroMode } from "./prompt.ts";
15
17
  import { errorMessage, isRecord } from "./util.ts";
@@ -507,10 +509,16 @@ export async function ensureSettingsFile(): Promise<void> {
507
509
  await mkdir(getAgentDir(), { recursive: true });
508
510
  try {
509
511
  const envModel = process.env.PI_BRO_MODEL?.trim();
510
- const defaultModel = envModel || "gemini-3.7-flash";
512
+ const host = getPiHostContext();
513
+ const active = host?.model;
514
+ // PiG can report a placeholder when no model is configured; only bootstrap from a catalog model.
515
+ const pair: ModelEffortPair = envModel
516
+ ? { model: envModel, effort: "default" }
517
+ : active && piPhysicalModel(host?.modelRegistry, active.provider, active.id)
518
+ ? { backend: "pi", model: piModelValue(active.provider, active.id), effort: "default" }
519
+ : { model: "gemini-3.7-flash", effort: "low" };
511
520
  const initial: BroSettings = {
512
- model: defaultModel,
513
- effort: envModel ? "default" : "low",
521
+ ...pair,
514
522
  mode: DEFAULT_BRO_MODE,
515
523
  showTurns: DEFAULT_SHOW_TURNS,
516
524
  overrides: {},
@@ -1,37 +1,63 @@
1
- /** Pure command parser for the one-source-at-a-time Simplify modal. */
2
- export type SimplifyAction =
3
- | { kind: "latest" | "copy" | "clear" | "help" | "retry" }
1
+ import { parseShowArguments } from "./show.ts";
2
+
3
+ export type SimplifyRequest =
4
+ | { kind: "latest" }
4
5
  | { kind: "url" | "text" | "file"; input: string }
5
- | { kind: "invalid"; message: string };
6
+ | { kind: "show"; turns?: number; steering: string };
7
+
8
+ type Invalid = { kind: "invalid"; message: string };
9
+ export type SimplifyAction = SimplifyRequest | Invalid | { kind: "copy" | "clear" | "help" | "retry" };
10
+
11
+ export const SIMPLIFY_INPUTS = ["latest", "text", "file", "url", "show"] as const;
12
+
13
+ // The modal and one-shot entry share source grammar, not viewer actions.
14
+ export function parseSimplifyRequest(command: string, value: string): SimplifyRequest | Invalid {
15
+ switch (command) {
16
+ case "latest": return value ? { kind: "invalid", message: "Use /bro simplify latest without arguments." } : { kind: "latest" };
17
+ case "text":
18
+ case "file":
19
+ case "url":
20
+ return value ? { kind: command, input: value } : {
21
+ kind: "invalid", message: `Use /bro simplify ${command} <${command === "file" ? "path" : command}>.`,
22
+ };
23
+ case "show": {
24
+ const parsed = parseShowArguments(value);
25
+ return parsed.invalid ? { kind: "invalid", message: "Use /bro simplify show [n-turns] [query]." } : {
26
+ kind: "show", turns: parsed.requested === undefined ? undefined : Number(parsed.requested), steering: parsed.steering,
27
+ };
28
+ }
29
+ default: return { kind: "invalid", message: "Use /bro simplify [latest | text <text> | file <path> | url <url> | show [n-turns] [query]]." };
30
+ }
31
+ }
6
32
 
7
33
  export function parseSimplifyAction(input: string): SimplifyAction {
8
- const trimmed = input.trim();
9
- if (!trimmed) return { kind:"invalid", message:"Enter /simplify, /url, /text, /file, /copy, /clear or /help." };
10
- const i=trimmed.indexOf(" ");
11
- const cmd=(i<0?trimmed:trimmed.slice(0,i)).toLowerCase();
12
- const value=i<0?"":trimmed.slice(i+1).trim();
13
- if (["/simplify","/copy","/clear","/help","/retry"].includes(cmd)) {
14
- if(value) return {kind:"invalid",message:cmd+" takes no arguments."};
15
- return {kind:({"/simplify":"latest","/copy":"copy","/clear":"clear","/help":"help","/retry":"retry"} as Record<string,"latest"|"copy"|"clear"|"help"|"retry">)[cmd]!};
34
+ const [token = ""] = input.trim().split(/\s+/, 1);
35
+ const command = token.toLowerCase();
36
+ const value = input.trim().slice(token.length).trim();
37
+ if (command === "/simplify") return value ? { kind: "invalid", message: "/simplify takes no arguments." } : { kind: "latest" };
38
+ if (command === "/copy" || command === "/clear" || command === "/help" || command === "/retry") {
39
+ return value ? { kind: "invalid", message: `${command} takes no arguments.` } : { kind: command.slice(1) as "copy" | "clear" | "help" | "retry" };
16
40
  }
17
- for (const kind of ["url","text","file"] as const) {
18
- if(cmd==="/"+kind) return value ? {kind,input:value} : {kind:"invalid",message:"Use /"+kind+" <"+(kind==="url"?"url":kind==="file"?"path":"text")+">."};
41
+ if (command === "/text" || command === "/file" || command === "/url" || command === "/show") {
42
+ const parsed = parseSimplifyRequest(command.slice(1), value);
43
+ return parsed.kind === "invalid" ? { ...parsed, message: parsed.message.replace("/bro simplify ", "/") } : parsed;
19
44
  }
20
- return {kind:"invalid",message:"Unknown Simplify command. Use /help. Ordinary chat belongs to /bro btw."};
45
+ return { kind: "invalid", message: "Use /help for Simplify commands. Ordinary chat belongs to /bro btw." };
21
46
  }
22
47
 
23
48
  export const SIMPLIFY_MODAL_HELP = [
24
49
  "## Simplify · Commands",
25
50
  "",
26
- "Bro explains one source in plain language. Every new explanation replaces the last one. This is not a chat.",
51
+ "Understand one source at a time, in plain words or as a diagram. Each new result replaces the last. This is not a chat.",
27
52
  "",
28
- "- \`/simplify\` — explain the latest completed assistant reply",
29
- "- \`/url <url>\` — explain a public webpage",
30
- "- \`/text <text>\` — explain pasted text",
31
- "- \`/file <path>\` — explain a local document (any readable path)",
32
- "- \`/copy\` — copy the current explanation",
33
- "- \`/clear\` — clear the explanation and source",
34
- "- \`/help\` — show these commands",
53
+ "- `/simplify` — explain the latest completed assistant reply",
54
+ "- `/text <text>` — explain pasted text",
55
+ "- `/file <path>` — explain a local document (any readable path)",
56
+ "- `/url <url>` — explain a public webpage",
57
+ "- `/show [n-turns] [query]` — draw recent conversation text, optionally focused by a query",
58
+ "- `/copy` — copy the current result",
59
+ "- `/clear` — clear the result and its source",
60
+ "- `/help` — show these commands",
35
61
  "",
36
- "With an empty composer, **M** changes explanation mode and re-explains the captured source; **R** retries. Both keep the backend configured for Explain. **Esc** returns from help to your saved explanation; if there is none, or you are already reading it, **Esc** closes. /bro simplify reopens this view in the current Pi session.",
62
+ "With an empty composer, **M** changes the explanation mode, **O** opens a diagram when available, and **R** reruns the captured source. **Esc** returns from help to the saved result, or closes.",
37
63
  ].join("\n");