pi-bro 0.22.0 → 0.22.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.
@@ -0,0 +1,986 @@
1
+ # pi-bro user guide
2
+
3
+ The full reference for every Bro command. Start with the
4
+ [README](../README.md) for requirements, install and a quick tour; come back
5
+ here for details.
6
+
7
+ **Contents:**
8
+ [What Bro can explain](#what-bro-can-explain) ·
9
+ [Commands](#commands) ·
10
+ [Explanation modes](#explanation-modes) ·
11
+ [Guided Review](#guided-review) ·
12
+ [Bro btw](#bro-btw-side-conversation) ·
13
+ [Bro advisor](#bro-advisor) ·
14
+ [Bro show](#bro-show) ·
15
+ [Examples](#bro-in-action) ·
16
+ [Pasted text](#explain-pasted-text) ·
17
+ [Documents](#explain-a-document) ·
18
+ [Webpages](#explain-a-webpage) ·
19
+ [Doctor](#check-your-setup) ·
20
+ [Settings](#settings) ·
21
+ [Backends: access and retention](#backends-access-and-retention) ·
22
+ [Preferences](#preferences) ·
23
+ [Privacy and safety](#privacy-and-safety) ·
24
+ [Troubleshooting and limits](#troubleshooting-and-current-limits)
25
+
26
+ ## What Bro can explain
27
+
28
+ | Source | Command | What Bro does |
29
+ | --- | --- | --- |
30
+ | Latest assistant reply | `/bro` | Explains the latest completed reply without adding the result to the conversation. |
31
+ | Pasted text | `/bro text <text>` | Explains text supplied directly in the command. |
32
+ | Local document | `/bro file <path>` | Extracts text from a workspace-local Markdown, text, PDF, or DOCX file. |
33
+ | Public webpage | `/bro url <url>` | Fetches one public HTML page and extracts its main readable content. |
34
+ | Recent session turns | `/bro show` | Draws the last turns' conversation text as shapes instead of prose (tool calls, tool results, reasoning, and images are omitted). |
35
+ | Any of the above, auto-detected | `/bro <input>` | Routes a lone URL to the webpage reader, an existing workspace file with a supported extension to the document reader, and anything else to pasted text. |
36
+
37
+ Pressing **R** simplifies the captured source again in the mode shown, and
38
+ **M** re-simplifies it in the next mode. These commands capture a
39
+ new source: `/bro text`, `/bro file`, `/bro url`, and `/bro show`. Giving `/bro` a URL, path, or
40
+ text directly captures a new source the same way.
41
+
42
+ ## Commands
43
+
44
+ | Command | Description |
45
+ | --- | --- |
46
+ | `/bro`, `/bro simplify`, or `/bro text` | Explain the latest completed assistant response. |
47
+ | `/bro text <text>` | Explain pasted text. |
48
+ | `/bro <input>` | Explain it directly: a lone URL runs the webpage reader, an existing workspace file with a supported extension runs the document reader, and anything else is pasted text. A quoted path with spaces is routed too when the file exists. |
49
+ | `/bro file <path>` | Explain a workspace-local `.md`, `.markdown`, `.txt`, `.pdf`, or `.docx` file. |
50
+ | `/bro url <url>` | Explain one public, text-based webpage. |
51
+ | `/bro open` | Reopen the latest explanation without calling the simplifier again. |
52
+ | `/bro show [n-turns] [query]` | Draw recent session turns (default last 1) as shapes instead of prose, from user and assistant conversation text only — tool calls, tool results, reasoning, and images are omitted. An optional query steers what the shapes focus on, with or without a leading turn count. |
53
+ | `/bro doctor` | Check Bro's settings, preferences, and each selected backend, with the effective backend/model/effort per feature. |
54
+ | `/bro mode [brief\|balanced\|faithful]` | View or choose the explanation mode. |
55
+ | `/bro preferences` | View or edit what Bro knows about you and how you like answers; see [Preferences](#preferences). |
56
+ | `/bro config` | Open settings for the shared backend/model/effort, explain mode, show turns, and per-capability (explain/show/btw/advisor/review) overrides. |
57
+ | `/bro guided-review <PR number or URL>` | Automatically explain and assess a captured PR in local Pi, with source evidence and optional private questions. Opening the same PR restores its saved review. |
58
+ | `/bro guided-review` | List saved reviews; `resume` is an alias. |
59
+ | `/bro btw [question]` | Open a side conversation in a modal, seeded with recent main-session context. Starts conversation-only; type `/mode` inside to toggle full permission (read and edit the workspace) without losing the thread. |
60
+ | `/bro advisor` | Quick notice of whether the executor's `bro_advisor` tool is available right now, pointing at `/bro config`, `/bro advisor-steer`, and `/bro doctor`. |
61
+ | `/bro advisor-steer` | View, edit, save, or clear the one persistent steering brief the advisor always sees. |
62
+ | `/bro help` | Open the built-in quick reference. |
63
+
64
+ Giving `/bro` the input directly works the same way:
65
+
66
+ ```text
67
+ /bro https://example.com/article
68
+ /bro docs/report.pdf
69
+ /bro any other text is explained as pasted text
70
+ ```
71
+
72
+ ## Explanation modes
73
+
74
+ Bro treats the source as data, rejects embedded instructions, preserves its
75
+ language (unless your [preferences](#preferences) name another), and avoids
76
+ adding facts, advice, or conclusions in every mode. Choose
77
+ a persistent mode with `/bro mode`, or press **M** in an explanation to try the
78
+ next mode without saving it:
79
+
80
+ - **`brief`**: Uses the original audience-led ELI-simpleton prompt with no fixed
81
+ word target.
82
+ - **`balanced`**: The default. Keeps important details, conditions, warnings,
83
+ context, code, and formatting while trimming fluff and repetition.
84
+ - **`faithful`**: Simplifies the language while preserving every claim,
85
+ qualification, warning, number, command, code block, and formatting choice.
86
+
87
+ ### Modal controls
88
+
89
+ - **Mouse wheel / trackpad**: Scroll in regular or fullscreen mode
90
+ - **↑ / ↓**: Scroll in any mode
91
+ - **C**: Copy the complete explanation
92
+ - **R**: Simplify the captured source again in the mode shown, or run the
93
+ current Doctor check again
94
+ - **M**: Re-simplify the captured source in the next mode (brief → balanced →
95
+ faithful → brief). It applies to this explanation only and does not change
96
+ the mode saved by `/bro mode`; pressing it again while Bro is working skips
97
+ ahead
98
+ - **O**: Open the HTML diagram when a show reply contains one
99
+ - **Esc**: Close the modal, or cancel while Bro is working
100
+
101
+ The modal header shows the model and reasoning effort the explanation or
102
+ drawing used (`default` when the model's own effort applies), followed by the
103
+ explanation mode, and `prefs` when your [preferences](#preferences) shaped the
104
+ result; `/bro open` keeps the original labels, mode, and tag.
105
+
106
+ Bro temporarily captures mouse input while its modal is open. Native mouse
107
+ selection may be unavailable or visually extend outside the modal depending on
108
+ your terminal mode; press **C** to copy the complete explanation reliably.
109
+
110
+
111
+ ## Guided Review
112
+
113
+ **Open a PR → read and investigate → leave when satisfied.** Bro automatically
114
+ prepares an explanation and quality assessment with captured code, ranked
115
+ findings and suggested fixes/checks. Asking private questions is optional.
116
+ Nothing is automatically applied or posted to GitHub.
117
+
118
+ ```text
119
+ /bro guided-review https://github.com/OWNER/REPO/pull/123
120
+ ```
121
+
122
+ Local Pi interactive mode, Git, authenticated `gh`, and Claude or Muse configured for review
123
+ are required. A new review makes a model call using that backend's account.
124
+ Opening the same PR restores its saved review without another model call.
125
+ Bare `/bro guided-review` lists saved reviews (`resume` is an alias).
126
+
127
+ Contents holds Overview, topics, Findings, Coverage, Changed files and Your
128
+ questions. Enter opens an item or focuses contextual actions; Enter on a
129
+ highlighted action activates it. Tab changes focus. Esc goes back, then closes
130
+ from Contents. Your work is saved automatically; **Close** leaves normally,
131
+ and **Stop and close** cancels active work before saving and leaving.
132
+
133
+ Optional conveniences:
134
+ - **Copy finding** copies its text to the system clipboard; nothing is submitted.
135
+ - **Regenerate guide** makes a confirmed model call about the **same captured
136
+ revision**. Success replaces the guide while retaining original private
137
+ discussion context; failure keeps it. It does not fetch later commits.
138
+
139
+ Reopening also keeps the captured revision, even after the author pushes.
140
+ Findings are model suggestions, not approval; citations show real locations,
141
+ not proof of the conclusion. Review uses Claude or Muse file-only inspection: shell, writes and web tools are disabled. Agy/Grok/Codex review requests fail clearly; choose a review override in `/bro config`. Saved reviews remain readable with any selection. Repository text can still mislead the model; tool restrictions are not proof of its conclusions.
142
+ Use `pi --tui-mode fullscreen` for pane-local wheel scrolling.
143
+
144
+ See the [Guided Review guide](guided-review.md) for controls, calls and
145
+ costs, source freshness, access/privacy, local storage, recovery and current
146
+ scope. Notes, examination tracking, branch/update review and feedback delivery
147
+ are not implemented.
148
+
149
+ ## Bro btw (side conversation)
150
+
151
+ `/bro btw` opens a separate multi-turn conversation in a modal, so you can ask
152
+ a quick side question while the main agent keeps working. It runs through the
153
+ selected backend and never adds anything to Pi's conversation unless you
154
+ explicitly insert it into the editor. Bro writes for a tired reader: the point
155
+ first, in plain words, at a length that fits the question, in the language you
156
+ asked in.
157
+
158
+ - `/bro btw <question>` asks immediately; `/bro btw` opens an empty thread.
159
+ Reopening keeps the thread and its mode.
160
+ - **Two modes, toggled with `/mode`**: a new thread starts
161
+ **conversation-only**; type `/mode` in the modal to switch to **full
162
+ permission** (read and edit the workspace, run commands) and again to switch
163
+ back. The conversation is kept across switches. How conversation-only is
164
+ enforced depends on the backend — see
165
+ [Backends: access and retention](#backends-access-and-retention).
166
+ - Every new or cleared thread is seeded with up to the last 8 turns of
167
+ main-session user/assistant conversation text (40,000 characters max, with a
168
+ truncation notice). Later turns continue the backend's native session; in
169
+ full permission mode the side agent can also read the repo itself.
170
+ - **In the modal**: type a question and press Enter (empty Enter re-asks the
171
+ last question). Composer actions trigger only on these exact commands:
172
+ - `/mode`: toggles conversation-only / full permission, keeping the thread
173
+ - `/copy`: copies the latest answer to the system clipboard
174
+ - `/copy-all`: copies the full thread to the system clipboard
175
+ - `/insert`: inserts the latest answer into the main editor without submitting
176
+ - `/insert-all`: inserts the full thread into the main editor without submitting
177
+ - `/retry`: re-asks the last question (empty Enter does the same)
178
+ - `/clear`: resets the thread
179
+
180
+ `/insert` and `/insert-all` never replace an existing main-editor draft:
181
+ edit or clear it first. Any other text, including other slash-prefixed input
182
+ such as `/send`, is sent as a question. Esc closes the modal (or cancels a
183
+ running turn). The header shows the model and reasoning effort the latest
184
+ turn used (`default` when the model's own effort applies) and the current
185
+ mode.
186
+ - A turn is capped at 2 minutes in conversation-only mode and 10 minutes in
187
+ full permission mode.
188
+ - Bro's thread lives in memory only — it clears when you switch Pi sessions,
189
+ reload extensions, or quit Pi. Changing the BTW backend starts a fresh
190
+ thread; native session IDs never cross backends.
191
+
192
+ ## Bro advisor
193
+
194
+ `bro_advisor` is a tool the **executor agent** — not you — can voluntarily
195
+ call mid-task for a second opinion. Unlike `/bro btw`, which is a side
196
+ conversation for you, `bro_advisor` is a tool for the model you're working
197
+ with; it shows up as a normal tool call/result in the transcript, not a
198
+ modal. It is registered like any other tool when the extension loads and has
199
+ no on/off switch of its own — whether the executor can actually call it
200
+ depends entirely on this host's own tool restrictions.
201
+
202
+ `/bro advisor` is a quick notice of whether `bro_advisor` is available right
203
+ now, pointing at `/bro config`, `/bro advisor-steer`, and `/bro doctor`.
204
+ `/bro doctor` has the full diagnostic: whether this host exposes and
205
+ activates `bro_advisor`, its resolved backend/model/effort, steering
206
+ presence, and backend compatibility (for Agy, a minimum CLI version with an
207
+ `agy update` action when it is too old).
208
+
209
+ - **Automatic context, no prep needed**: the executor never assembles a
210
+ summary. Bro captures a harness-neutral snapshot — the executor's system
211
+ instructions, its active tools, and the conversation so far including tool
212
+ calls and results — and sends it, along with an optional `question` the
213
+ executor may pass, to a **fresh, standalone process of the selected
214
+ backend** for every consultation. Nothing is resumed or reused across calls,
215
+ including retries.
216
+ - **Instructed to investigate, not implement**: the advisor process has real
217
+ tool access in the workspace with permissions auto-approved — there is no
218
+ enforced read-only isolation. It is instructed to verify claims itself and
219
+ return advice, leaving edits to the executor, but that boundary is a
220
+ behavioral prompt instruction rather than an enforced sandbox constraint, so
221
+ treat its findings as advice to verify, not a guaranteed hands-off review.
222
+ - **Steering**: The advisor reads standing priorities from `~/.pi/agent/bro-advisor.md`
223
+ and session-specific priorities from `/bro advisor-steer`.
224
+ `/bro advisor-steer` opens an editor for one session steering brief — e.g. "quick
225
+ prototype; keep A and B careful, everything else minimal". Session steering takes
226
+ precedence over durable standing defaults where they conflict.
227
+ **Ctrl+S** saves and keeps the editor open; **Enter** or **Shift+Enter** inserts
228
+ a newline; **Ctrl+K** clears both the saved session brief and draft while staying open;
229
+ **Ctrl+C** copies the entire current draft, including unsaved edits; and **Esc**
230
+ closes without saving unsaved edits. Neither steering source is **ever added to Pi's
231
+ conversation or sent to the main model** — the advisor is the only thing that reads them.
232
+ - **Persistence**: standing defaults persist across all sessions in `~/.pi/agent/bro-advisor.md`.
233
+ The session steering brief persists with the Pi session as custom extension data in the
234
+ session file (`bro-advisor-steering`) and is restored on resume or reload. Forking a
235
+ session inherits session steering; edits made after the fork are independent of the
236
+ original branch. Clearing session steering leaves durable steering intact.
237
+ - **Retries**: on an invocation failure (not a completed answer — "I need
238
+ more evidence" is a normal result, not a failure), Bro retries with the
239
+ identical snapshot, steering, and question: once after 5 seconds, once more
240
+ after 10 seconds, then returns the backend's own diagnostic — including a
241
+ context-length error, verbatim — as the failure. Host-imposed deadlines and
242
+ cancellation are terminal: neither starts another attempt or a backoff wait.
243
+ The advisor CLI is asked to stop at 10 minutes; Bro's host deadline is 610
244
+ seconds plus bounded process cleanup. A CLI-reported error before that host
245
+ deadline remains an invocation failure and can be retried.
246
+ Cancelling the tool call skips any pending retry wait.
247
+ - **Progress and provenance**: while an attempt is running, Bro shows the last
248
+ thing the advisor actually reported — a tool name or a user-facing response
249
+ line, never hidden reasoning — and how long ago it arrived, e.g. `last
250
+ reported: Read src/app.ts (2s ago)`, or "awaiting first activity" before
251
+ anything arrives. Expanding a running consultation shows up to the last 4
252
+ reported activity lines; each retry starts the trail over. The returned
253
+ answer starts with backend, model, effort, attempt count, duration,
254
+ workspace, steering presence, snapshot size, and known omission/compaction
255
+ notes; the advisor's complete answer follows unchanged.
256
+ - **Model/effort**: resolved the same way as explain/show/btw, through
257
+ `/bro config` (shared default or per-capability override).
258
+
259
+ ## Bro show
260
+
261
+ Where the explanation modes rewrite dense prose in simpler words, `/bro show`
262
+ changes the form: it draws what you and the assistant said in the last few
263
+ session turns as a shape instead of paragraphs. Capture keeps only user and
264
+ assistant conversation text, including every intermediate assistant message in
265
+ a turn — tool calls, tool results, reasoning, and images never leave the
266
+ session. It runs the same backend-specific model call and shows the result
267
+ in the same modal, never touching your conversation. `/bro show` uses its own
268
+ draw prompt; the explanation modes do not affect it. Your
269
+ [preferences](#preferences) can change only its wording and language, never
270
+ which shapes it draws or its rules.
271
+
272
+ Because the draw model only ever sees conversation text, its shapes reflect
273
+ what was *reported* in the conversation — what the assistant said it did or
274
+ found — not an independent check against the actual code or system state.
275
+
276
+ Shapes are terminal-first: pseudocode, call trees, file trees, component
277
+ trees, diffs, and types and signatures. Bro picks the shape from what
278
+ happened in the session; there is no flag to request a specific one. When the source has no code structure
279
+ to draw, Bro falls back to a plain outline instead of forcing a diagram. A
280
+ reply that ends in one self-contained HTML block — layout, a state comparison,
281
+ anything where position itself carries meaning — is written to a file and
282
+ opened with **O**.
283
+
284
+ Pressing **R** redraws the same captured turns; running `/bro show` again
285
+ captures the latest turns afresh. `/bro show <n-turns>` overrides the default turn
286
+ count for a single run.
287
+
288
+ Add a query to steer what the shapes focus on, either after a turn count or on
289
+ its own: `/bro show what changed in the auth flow`, or `/bro show 3 what
290
+ changed in the auth flow`. The query is used as a lens on the captured turns,
291
+ not as additional evidence, and its casing is preserved as typed. Pressing
292
+ **R** retries with the same turn count and query.
293
+
294
+ Any leading whitespace-delimited word that looks like a number is treated as the
295
+ requested turn count: for example, `/bro show 3 what changed` captures 3 turns
296
+ and steers on "what changed", while `/bro show 404 handler` parses "404" as the
297
+ turn count and "handler" as the steering query. To steer on a phrase that starts
298
+ with digits while choosing a turn count, specify the turn count explicitly
299
+ first: `/bro show 1 404 handler` captures 1 turn and steers on "404 handler".
300
+ If the first word is not a number, the whole input is treated as the steering
301
+ query using the saved `showTurns` default.
302
+
303
+ ### A slow session-create, traced
304
+
305
+ The agent followed a two-second delay from the handler down to the worker.
306
+ `/bro show` drew the chain:
307
+
308
+ ```text
309
+ handleCreateSession(req)
310
+ ├── validateRequest(req)
311
+ ├── SessionStore.insert(req.body)
312
+ └── publish('session.created')
313
+ └── AgentWorker.run(sessionId)
314
+ ├── loadContext(sessionId)
315
+ ├── callModel(context)
316
+ └── persistResult(sessionId, result)
317
+ ```
318
+
319
+ ### The shape of code before it exists
320
+
321
+ A design discussion agreed on the data model ahead of implementation. `/bro
322
+ show` kept just the shape:
323
+
324
+ ```typescript
325
+ interface Item { id: ItemId; parentId: ItemId | null }
326
+ interface Cursor { position: ItemId; direction: 'up' | 'down' }
327
+ function resolveTarget(items: Item[], cursor: Cursor): ItemId | null
328
+ ```
329
+
330
+ ### A layout that collapses at narrow widths
331
+
332
+ Text can't show a before/after layout change at a glance, so Bro ends with one
333
+ self-contained HTML block and **O** opens it (the terminal first shows
334
+ `[HTML diagram saved — press O to open]`):
335
+
336
+ <p align="center">
337
+ <a href="https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-show-layout.png">
338
+ <img alt="A before/after dashboard grid" src="https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-show-layout.png" width="720">
339
+ </a>
340
+ </p>
341
+
342
+ <details>
343
+ <summary><strong>More shapes</strong></summary>
344
+
345
+ **Diff** — what changed in the save handler:
346
+
347
+ ```diff
348
+ on(save)
349
+ - write content
350
+ + if content is unchanged
351
+ + return cached result
352
+ + write new content
353
+ + invalidate cache
354
+ ```
355
+
356
+ **File layout** — where everything lives, for a refactor:
357
+
358
+ ```text
359
+ src/
360
+ ├── commands/ # user intents
361
+ │ ├── registry.ts
362
+ │ └── show-me.ts
363
+ ├── sessions/ # state and lifecycle
364
+ │ ├── events.ts
365
+ │ ├── store.ts
366
+ │ └── worker.ts
367
+ ├── transport/ # API
368
+ │ ├── client.ts
369
+ │ └── stream.ts
370
+ └── config.ts # root config
371
+ ```
372
+
373
+ **Component tree** — what the session page renders:
374
+
375
+ ```text
376
+ SessionPage (apps/example/src/routes/session.tsx)
377
+ ├── [hook] useSessionEvents
378
+ ├── SessionToolbar (packages/ui)
379
+ │ └── RunSkillButton
380
+ └── SessionTimeline (packages/ui)
381
+ └── SkillResultCard
382
+ ```
383
+
384
+ **Pseudocode** — how scroll capture and restore work:
385
+
386
+ ```text
387
+ capture(blocks, targetRect, scrollRect) -> Snapshot:
388
+ target = focusedBlock ?? firstBlockIntersectingViewportTop(blocks)
389
+ anchor = wholeBlockAnchor(blocks, target)
390
+ offset = targetRect.top - scrollRect.top
391
+ return { anchor, offset, scrollTop, revision + 1 }
392
+
393
+ restore(snapshot, blocks) -> number:
394
+ placement = resolveAnchor(blocks, snapshot.anchor)
395
+ if placement: return scrollRect.top + targetRect.top - snapshot.offset
396
+ return snapshot.scrollTop
397
+ ```
398
+
399
+ </details>
400
+
401
+ Prose in, outline out: a purely conversational session with no code to draw
402
+ degrades to a plain outline of the discussion — never a forced diagram.
403
+
404
+ ## Bro in action
405
+
406
+ ### Assistant response
407
+
408
+ **Before `/bro`: the original agent response**
409
+
410
+ [![A dense assistant response before Bro](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-response-before.png)](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-response-before.png)
411
+
412
+ **After `/bro`: the plain-language explanation**
413
+
414
+ [![The assistant response explained in the Bro modal](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-response-after.png)](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-response-after.png)
415
+
416
+ ### Local document
417
+
418
+ **Before: a complex PDF**
419
+
420
+ [![A complex PDF before Bro](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-file-before.png)](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-file-before.png)
421
+
422
+ **After `/bro file <path>`**
423
+
424
+ [![The PDF explained in the Bro modal](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-file-after.png)](https://raw.githubusercontent.com/tranhoangnguyen03/pi-bro/main/docs/images/bro-file-after.png)
425
+
426
+ Bro optimizes for understanding, not simply for fewer words. The written
427
+ examples below are synthetic and were run through Bro's default prompt. Click
428
+ a screenshot to see it at full size.
429
+
430
+ <details>
431
+ <summary><strong>Short:</strong> TypeScript says a value is <code>never</code></summary>
432
+
433
+ ### Before
434
+
435
+ > The diagnostic is not evidence that `result` is intrinsically uninhabitable; it is an artifact of TypeScript's intraprocedural control-flow graph. Because `result` is initialized to `null` and only assigned inside the `forEach` callback, the outer scope does not model that callback as definitely executing. After `if (!result) return`, the remaining branch therefore collapses to `never`, producing the property-access error. Replace the callback-driven mutation with a control-flow-visible loop: `for (const item of items) { if (matches(item)) { result = item; break; } }`. Alternatively, derive the value expressionally with `const result = items.find(matches);` and guard `if (!result) return;` before dereferencing it. Avoid an `as Result` assertion; it suppresses the symptom while preserving the unsound state transition that caused the narrowing anomaly.
436
+
437
+ ### After `/bro`
438
+
439
+ #### What happened
440
+
441
+ TypeScript showed an error saying your variable `result` cannot be used or
442
+ accessed.
443
+
444
+ This happened because `result` was set to `null` outside a `forEach` loop and
445
+ then modified inside the loop's helper function (callback). TypeScript tracks
446
+ code line by line. It cannot guarantee that code inside a `forEach` callback
447
+ will actually run.
448
+
449
+ #### What it means
450
+
451
+ Because TypeScript assumes the loop's callback might not run:
452
+
453
+ 1. It believes `result` might still be `null`.
454
+ 2. When you check `if (!result) return`, TypeScript thinks `result` can never
455
+ hold a valid value after that check.
456
+ 3. It sets the type of `result` to `never` (a special type meaning "impossible
457
+ value") and blocks you from reading its properties.
458
+
459
+ The error is a limitation in how TypeScript analyzes loops with callbacks.
460
+
461
+ #### What you should do next
462
+
463
+ Choose one of these two fixes:
464
+
465
+ **Option 1: Use a standard `for...of` loop**
466
+
467
+ ```ts
468
+ for (const item of items) {
469
+ if (matches(item)) {
470
+ result = item;
471
+ break;
472
+ }
473
+ }
474
+ ```
475
+
476
+ **Option 2: Use `Array.prototype.find`**
477
+
478
+ ```ts
479
+ const result = items.find(matches);
480
+ if (!result) return;
481
+ ```
482
+
483
+ Avoid using a type assertion like `as Result`. It only hides the warning
484
+ without fixing the underlying tracking issue.
485
+
486
+ </details>
487
+
488
+ <details>
489
+ <summary><strong>Medium:</strong> Login succeeds, but the user is still logged out</summary>
490
+
491
+ ### Before
492
+
493
+ > What you're observing is almost certainly not an authentication failure in the credential-validation layer; it is a post-authentication session persistence failure caused by an environment-dependent mismatch between Express's transport-security inference and the TLS termination topology in production.
494
+ >
495
+ > Locally, Express sees the request as plain HTTP and your development cookie configuration probably permits a non-secure session cookie. In production, however, the browser connects over HTTPS to Nginx, a load balancer, or an ingress controller, which terminates TLS and forwards the request to Node over HTTP. Unless Express trusts that intermediary, `req.secure` remains `false`, even when the proxy sends `X-Forwarded-Proto: https`. With `cookie.secure: true`, `express-session` can consequently decline to emit the cookie because it believes the originating request was insecure. The login route may still return `200`, making the credentials appear accepted, but the next request has no session identifier and is treated as anonymous.
496
+ >
497
+ > Configure proxy trust before registering session middleware, and make the cookie policy reflect whether the frontend and API are same-site or genuinely cross-site:
498
+ >
499
+ > ```js
500
+ > app.set("trust proxy", 1);
501
+ >
502
+ > app.use(session({
503
+ > secret: process.env.SESSION_SECRET,
504
+ > resave: false,
505
+ > saveUninitialized: false,
506
+ > proxy: true,
507
+ > cookie: {
508
+ > httpOnly: true,
509
+ > secure: true,
510
+ > sameSite: "lax",
511
+ > maxAge: 1000 * 60 * 60 * 24
512
+ > }
513
+ > }));
514
+ > ```
515
+ >
516
+ > Use `sameSite: "none"` instead of `"lax"` only when the browser must send the cookie in a cross-site context, such as a frontend and API on unrelated registrable domains. Browsers require `Secure` when `SameSite=None`, so that combination must remain HTTPS-only. Separate subdomains such as `app.example.com` and `api.example.com` are usually same-site, though they are still cross-origin.
517
+ >
518
+ > Also verify that the proxy explicitly forwards `X-Forwarded-Proto`, that the browser receives a `Set-Cookie` response header, and that frontend requests use `credentials: "include"` when crossing origins. If CORS is involved, the server must return the exact allowed origin plus `Access-Control-Allow-Credentials: true`; a wildcard origin is incompatible with credentialed requests.
519
+ >
520
+ > Avoid setting a cookie `domain` unless sharing across subdomains is intentional. A host-only cookie is safer and eliminates another production-only failure mode.
521
+
522
+ ### After `/bro`
523
+
524
+ #### What happened
525
+
526
+ Your username and password check succeeded, and the login route returned `200
527
+ OK`. However, the browser did not receive or return a usable session cookie in
528
+ production.
529
+
530
+ #### What it means
531
+
532
+ In production, secure web traffic (HTTPS) hits an intermediary, such as a load
533
+ balancer or Nginx, before reaching your Node/Express app as plain HTTP.
534
+
535
+ Because your session cookie requires HTTPS (`secure: true`), Express may withhold
536
+ it when it does not trust the proxy forwarding the request. The exact trust
537
+ setting must match your deployment's proxy topology.
538
+
539
+ #### What you should do next
540
+
541
+ 1. Configure Express to trust only your actual proxy topology. Put this before
542
+ the session setup. For example, use `1` only when there is exactly one trusted
543
+ proxy hop:
544
+
545
+ ```js
546
+ app.set("trust proxy", 1);
547
+
548
+ app.use(session({
549
+ secret: process.env.SESSION_SECRET,
550
+ resave: false,
551
+ saveUninitialized: false,
552
+ cookie: {
553
+ httpOnly: true,
554
+ secure: true,
555
+ sameSite: "lax",
556
+ maxAge: 1000 * 60 * 60 * 24
557
+ }
558
+ }));
559
+ ```
560
+
561
+ 2. Check your cookie settings:
562
+ - Keep `sameSite: "lax"` if your frontend and backend share the same main
563
+ domain, such as `app.example.com` and `api.example.com`.
564
+ - Use `sameSite: "none"` only when the cookie must be sent cross-site.
565
+ Browsers require `secure: true` with this setting.
566
+ - Avoid defining a custom cookie `domain` unless you deliberately need to
567
+ share cookies across subdomains.
568
+
569
+ 3. Verify the proxy, browser, and CORS settings:
570
+ - Ensure the proxy forwards the `X-Forwarded-Proto` header.
571
+ - Check that the response contains a `Set-Cookie` header.
572
+ - Include `credentials: "include"` in cross-origin frontend requests.
573
+ - Return the exact allowed origin with
574
+ `Access-Control-Allow-Credentials: true`. Do not use a wildcard (`*`) for
575
+ credentialed requests.
576
+
577
+ </details>
578
+
579
+ <details>
580
+ <summary><strong>Long:</strong> A CI build fails only when its cache is restored</summary>
581
+
582
+ ### Before
583
+
584
+ > The failure is not a nondeterministic pnpm installation problem, despite the misleading first error being emitted from the test runner immediately after dependency hydration. It is a state-contamination problem at the intersection of the repository cache, the package export map, and an incorrectly scoped cache key. The decisive observation is that the same commit succeeds in a clean checkout and in CI when cache restoration is disabled, but fails when the pre-build workspace cache is restored. That isolates the variable to files materialized outside Git rather than source, Node, or runner image drift.
585
+ >
586
+ > The affected package, `@acme/config`, was recently migrated from a dual CommonJS/ESM build to an ESM-oriented TypeScript output. Its root `package.json` declares `"type": "module"` and maps the `import` condition to `./dist/index.js`, while the legacy `require` condition still maps to `./dist/index.cjs`. The current compiler emits `index.js` but does not remove the previous build directory first. An older cached `dist` directory therefore contributes two files that no longer belong to the current build graph: `dist/index.cjs` and `dist/package.json`, the latter declaring `"type": "commonjs"`. The new compiler overlays `dist/index.js` but leaves both obsolete files intact. Because nested package boundaries override the root package type, Node interprets the newly emitted ESM `index.js` as CommonJS in that restored workspace and reports `Unexpected token 'export'`. Test processes entering through `require()` instead resolve the obsolete `index.cjs`, which references a removed chunk and can instead produce `MODULE_NOT_FOUND`. These apparently different errors are two projections of the same dirty-output condition.
587
+ >
588
+ > The cache configuration makes that contaminated state persistent. The workflow computes the key with `hashFiles('packages/**/pnpm-lock.yaml')`, but this workspace has only the root-level `pnpm-lock.yaml`. GitHub Actions consequently evaluates the hash expression to an empty value, yielding a key equivalent to `Linux-node20-workspace-`. A broad restore key then permits an archive produced before the module-format migration to satisfy the lookup. That archive combines the pnpm content-addressable store, Turborepo metadata, and every package's `dist` directory. Those data classes do not share valid invalidation semantics: pnpm store entries are immutable by content, Turborepo artifacts are task-hash addressed, and arbitrary build directories are mutable snapshots whose correctness depends on complete deletion or exact provenance. Treating them as one cache effectively elevates obsolete untracked files into undeclared build inputs.
589
+ >
590
+ > The evidence is visible by comparing the restored and clean workspaces before compilation. In the failing job, `packages/config/dist/package.json` exists with `"type":"commonjs"` and `packages/config/dist/index.cjs` has a timestamp and checksum predating the current commit. Neither file appears after `git clean -ffdx` followed by installation and build. The Actions cache log also shows the truncated key without a lockfile digest, while `git diff` remains empty because the problematic files are ignored. Finally, deleting only `packages/config/dist` before rerunning the unchanged test command converts the failure to a pass, which excludes dependency resolution and network variability as primary causes.
591
+ >
592
+ > The minimal durable remediation has three parts. First, stop caching package output directories. Cache the pnpm store separately, using a key that includes the actual root lockfile:
593
+ >
594
+ > ```yaml
595
+ > key: ${{ runner.os }}-node20-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
596
+ > restore-keys: |
597
+ > ${{ runner.os }}-node20-pnpm-
598
+ > ```
599
+ >
600
+ > A broad fallback is acceptable for the pnpm store because pnpm validates content-addressed entries; it is not acceptable for mutable `dist` snapshots. If remote or local Turborepo caching is retained, cache only `.turbo` and allow Turbo's task hash to govern artifact reuse rather than wrapping raw workspace outputs in a generic archive.
601
+ >
602
+ > Second, make every package build replace, rather than merge into, its output directory. `@acme/config` should delete `dist` before invoking `tsc`, `tsup`, or the existing bundler. The CI workflow should also run the repository's recursive clean target before the first build as a defense against future cache or runner reuse. This is not a substitute for fixing cache scope, but it restores the invariant that generated output is a function of the checked-out sources and declared toolchain.
603
+ >
604
+ > Third, make the export contract agree with emitted files. If `@acme/config` is intentionally ESM-only, remove the `require` condition and the obsolete CommonJS metadata. If CommonJS consumers remain supported, restore an explicit CJS build that deterministically emits `dist/index.cjs`; do not let a historical artifact impersonate that support. In either case, package publication should reject export targets that do not exist.
605
+ >
606
+ > Verification should exercise both cache states and both module entry paths. Run the full pipeline once with no cache, save only the corrected caches, and rerun the identical commit expecting a cache hit and the same result. Inspect the built package to confirm the nested CommonJS `package.json` and legacy chunks are absent unless intentionally generated. Add a lightweight smoke check using dynamic `import('@acme/config')`; if CommonJS remains supported, add a second check through `createRequire`. Finally, change the root lockfile and confirm the logged cache key changes. That matrix validates clean-build reproducibility, restored-cache reproducibility, export-map coherence, and dependency-cache invalidation independently rather than relying on a single green run.
607
+
608
+ ### After `/bro`
609
+
610
+ #### What happened
611
+
612
+ Your build failed because old files were left behind by a broken cache (a saved
613
+ snapshot of previous build files).
614
+
615
+ The package `@acme/config` recently switched its module format to modern
616
+ JavaScript (ESM). However, the build process did not delete the old output
617
+ folder (`dist`) before creating new files.
618
+
619
+ Because the GitHub Actions setting searches the wrong path
620
+ (`hashFiles('packages/**/pnpm-lock.yaml')`), GitHub could not find the root
621
+ `pnpm-lock.yaml`. It restored an outdated cache containing `dist/index.cjs` and
622
+ a `dist/package.json` configured for older JavaScript (CommonJS). The new build
623
+ wrote some files but left the old ones behind, confusing Node and causing errors
624
+ such as `Unexpected token 'export'` and `MODULE_NOT_FOUND`.
625
+
626
+ A clean checkout without the cache succeeds. This proves the problem is old
627
+ cached files, not your source code or dependencies.
628
+
629
+ #### What it means
630
+
631
+ - **Cache contamination:** The CI workflow restores mutable `dist` folders
632
+ alongside package-manager files, mixing obsolete files into new builds.
633
+ - **Mismatched module settings:** The package says it supports both modern
634
+ (`import`) and legacy (`require`) formats, but it only builds the modern one
635
+ while relying on leftover cached files for the legacy one.
636
+
637
+ #### What you should do next
638
+
639
+ 1. **Fix the GitHub Actions cache:** Stop caching `dist` folders. Cache only the
640
+ pnpm store, using the root lockfile:
641
+
642
+ ```yaml
643
+ key: ${{ runner.os }}-node20-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
644
+ restore-keys: |
645
+ ${{ runner.os }}-node20-pnpm-
646
+ ```
647
+
648
+ If you use Turborepo, cache only `.turbo`.
649
+
650
+ 2. **Clean output folders before building:** Make `@acme/config` delete `dist`
651
+ before running `tsc`, `tsup`, or the bundler. Run the repository's recursive
652
+ clean command before CI builds.
653
+
654
+ 3. **Update the package exports:**
655
+ - If `@acme/config` is ESM-only, remove the `require` entry and old CommonJS
656
+ metadata.
657
+ - If CommonJS is still needed, add a real build step for `dist/index.cjs`.
658
+
659
+ 4. **Verify the fix:**
660
+ - Delete the generated `packages/config/dist` folder, then run a clean build.
661
+ Do not use `git clean -ffdx` in a working copy with files you need.
662
+ - Run the workflow without a cache, save the new cache, and rerun the same
663
+ commit to verify that a cache hit also passes.
664
+ - Test `import('@acme/config')`, and test `createRequire` if CommonJS is
665
+ supported.
666
+
667
+ </details>
668
+
669
+ ## Explain pasted text
670
+
671
+ Paste text directly after the command:
672
+
673
+ ```text
674
+ /bro text OAuth refresh tokens are rotated after every successful use.
675
+ ```
676
+
677
+ Bro explains the pasted text instead of the latest assistant reply. With no text
678
+ after `/bro text`, it falls back to the latest completed reply. Press **R**
679
+ to simplify the same captured text again.
680
+
681
+ ## Explain a document
682
+
683
+ Use a path relative to Pi's current workspace, or an absolute path inside it:
684
+
685
+ ```text
686
+ /bro file "docs/incident review.pdf"
687
+ ```
688
+
689
+ Paths may contain spaces; matching single or double quotes are also accepted.
690
+ Bro extracts text locally, then sends that text through the same explanation
691
+ flow used by `/bro`. Pressing **R** retries the extracted snapshot; running a
692
+ new `/bro file <path>` command reads the file again.
693
+
694
+ Files are limited to 10 MiB and 100,000 extracted characters. Scanned PDFs are
695
+ not supported because Bro does not perform OCR.
696
+
697
+ ## Explain a webpage
698
+
699
+ Pass one public HTTP or HTTPS page:
700
+
701
+ ```text
702
+ /bro url https://example.com/complicated-article
703
+ ```
704
+
705
+ Bro fetches the page, extracts its main readable text locally, and sends only
706
+ that text through the existing explanation flow. The completed modal shows the
707
+ final website and page title. Pressing **R** retries the captured page without
708
+ fetching again; running a new `/bro url <url>` command fetches a fresh copy.
709
+
710
+ The first version is intentionally limited to one public, text-based page. It
711
+ does not use browser cookies, sign in, run page JavaScript, bypass paywalls or
712
+ bot protection, load complete discussion threads, follow pagination, or
713
+ understand images and video. Pages that depend on those features may fail.
714
+
715
+ If Bro cannot read a page, copy its content into a `.txt` or `.md` file, or save
716
+ it as a PDF, then use `/bro file <path>`.
717
+
718
+
719
+ ## Check your setup
720
+
721
+ Run `/bro doctor` when Bro is newly installed or something is not working. It
722
+ checks Bro's settings and preferences, then probes only the backends some feature
723
+ actually selects, and reports the effective backend/model/effort for each
724
+ feature. Failed checks explain what to fix.
725
+
726
+ - **Agy**: installed version, model catalog, and account access.
727
+ - **Claude Code**: installed version and configured authentication.
728
+ - **Grok**: installed version only; authentication and connectivity are not
729
+ verified.
730
+ - **Codex**: installed version and configured authentication.
731
+ - **Muse**: installed version only; authentication and connectivity are not
732
+ verified.
733
+
734
+ Doctor never sends source text or runs a model completion. A successful check
735
+ confirms the setup but cannot guarantee that a later provider request will
736
+ succeed.
737
+
738
+ ## Settings
739
+
740
+ Use `/bro config` to review or change the shared default backend/model/effort
741
+ and any per-capability (explain/show/btw/advisor/review) overrides, the explanation
742
+ mode, and the default show turn count. Changes save immediately. Esc inside a
743
+ picker cancels that pick; Esc on the settings screen closes it, keeping
744
+ whatever was already saved. A failed save (for example, a read-only file) is
745
+ shown inline. `/bro mode` changes the mode directly (**M** in an explanation
746
+ tries another mode without saving it), and `/bro help` shows the active settings
747
+ and file path.
748
+
749
+ Settings live in this user-editable file, created when the extension loads
750
+ (under `$PI_CODING_AGENT_DIR` instead when that is set):
751
+
752
+ ```text
753
+ ~/.pi/agent/bro-settings.json
754
+ ```
755
+
756
+ ```json
757
+ {
758
+ "version": 2,
759
+ "default": { "backend": "agy", "model": "gemini-3.7-flash", "effort": "low" },
760
+ "mode": "balanced",
761
+ "showTurns": 1,
762
+ "overrides": {
763
+ "explain": { "backend": "claude", "model": "sonnet", "effort": "medium" },
764
+ "advisor": { "backend": "grok", "model": "grok-4.7", "effort": "high" }
765
+ }
766
+ }
767
+ ```
768
+
769
+ Bro reads the file again before each request, so manual edits apply next time.
770
+
771
+ - Each selection is one atomic backend/model/effort choice. An override pins
772
+ its own complete selection and ignores the shared default, even when it
773
+ happens to match it; select **Default** in `/bro config` to inherit again.
774
+ Omitted overrides inherit `default`.
775
+ - `effort` must be one the backend offers (`default` omits it and lets the
776
+ model decide). Agy selections are normalized against Agy's installed model
777
+ catalog. Claude, Grok, Codex, and Muse accept seeded or custom model IDs; a model/effort
778
+ combination the account does not support fails with the backend's own error
779
+ instead of silently falling back.
780
+ - `mode` is `brief`, `balanced` (the default), or `faithful`. `showTurns` is
781
+ the default number of turns `/bro show` draws (default 1); `/bro show
782
+ <n-turns>` overrides it for one run.
783
+ - `PI_BRO_MODEL` picks the initial Agy model only when Bro creates a missing
784
+ settings file, for example `PI_BRO_MODEL=gemini-3.7-flash-low pi`.
785
+ - Older flat settings files (root `model`/`effort`) still load and mean Agy.
786
+
787
+ ## Backends: access and retention
788
+
789
+ Bro uses each CLI's own account and billing route, never Pi provider
790
+ credentials, and does not copy credentials or rewrite backend configuration.
791
+ Each backend and your model provider may retain sessions, logs, and request
792
+ data under their own settings and policies.
793
+
794
+ | | Explain / show | BTW conversation-only | BTW full permission | Advisor | Guided Review |
795
+ | --- | --- | --- | --- | --- | --- |
796
+ | **Agy** | Temporary directory, Agy sandbox | Temporary directory, Agy sandbox | Workspace, permissions bypassed | Fresh workspace process, permissions bypassed | Unavailable; choose Claude/Muse |
797
+ | **Claude Code** | Scratch directory, tools/MCP/skills disabled, no session persistence | Workspace, tools disabled | Workspace, permissions bypassed | Fresh workspace process, permissions bypassed | Restricted Read/Grep/Glob only; confined checkout, no persistence |
798
+ | **Grok** | Temporary directory, **prompt instruction only** | Workspace, **prompt instruction only** | Workspace, permissions bypassed | Fresh workspace process, permissions bypassed | Unavailable; choose Claude/Muse |
799
+ | **Codex** | Scratch directory, read-only sandbox, ephemeral session | Workspace, read-only sandbox | Workspace, approvals and sandbox bypassed | Fresh workspace process, approvals and sandbox bypassed | Unavailable; command execution is not allowed for review |
800
+ | **Muse** | Scratch directory, approval/write/shell disabled, no session log | Workspace, approval/write/shell disabled | Workspace, permissions bypassed (`--yolo`) | Fresh workspace process, permissions bypassed (`--yolo`) | Captured checkout; writes/shell/web disabled, no session log |
801
+
802
+ - Grok always runs with its sandbox off and permissions bypassed; its tools,
803
+ hooks, skills, plugins, and MCP may remain available. "Answer only from the
804
+ supplied context" is a request, not an enforced restriction.
805
+ - Codex's read-only sandbox is not a tool-free mode: workspace reads and
806
+ sandboxed commands remain available. Bro does not disable configured MCP
807
+ servers or web search; their access is governed by Codex configuration.
808
+ - Muse's restricted mode disables write and shell tools and approval prompts,
809
+ not all tools: workspace reads and web tools remain available without approval.
810
+ It is not a tool-free or network-isolated mode.
811
+ - Claude's restrictions are tool/configuration settings (with safe mode), not
812
+ an OS sandbox; built-in and managed Claude behavior can remain. Running a
813
+ permission-bypassing mode as root may be rejected by Claude.
814
+ - BTW continues natively: Agy by conversation ID, Claude and Grok by
815
+ `--resume`, Codex by `resume`, and Muse by `--session-id` of the same session,
816
+ including across `/mode` switches. An Agy conversation stays bound to the
817
+ workspace it started in, so after a `/mode` switch — or whenever a thread
818
+ has turns but no native session ID — Bro starts a fresh native session
819
+ seeded with the main-session context and every earlier turn.
820
+ - Cancellation, deadlines, and invalid output streams stop the backend's
821
+ process group on POSIX, escalating after a five-second grace period. On
822
+ Windows only the direct child is targeted. Detached shell work or external
823
+ services a backend started are not contained. Bro removes its private
824
+ temporary prompt files.
825
+
826
+ ### Configuration precedence
827
+
828
+ When resolving backend, model, and reasoning effort:
829
+ 1. **Per-capability override**: `overrides.<capability>` (`explain`, `show`, `btw`, `advisor`, or `review`) pins that capability's complete selection.
830
+ 2. **Shared default**: otherwise the capability inherits `default` (root `model`/`effort` in older flat files).
831
+ 3. **Agy catalog normalization**: for Agy selections, Bro maps suffixed variant IDs and handles fixed-effort models.
832
+ 4. **Initial file creation only**: `PI_BRO_MODEL` has no effect once the settings file exists.
833
+
834
+ When resolving turn count for `/bro show`:
835
+ 1. **Command argument**: an explicit count like `/bro show 3` or `/bro show 1 query` overrides for that run.
836
+ 2. **Saved setting**: `showTurns` (defaults to 1).
837
+
838
+ When shaping an answer, each part has one owner:
839
+
840
+ | Part | Decided by |
841
+ | --- | --- |
842
+ | Bro's source rules: quoted source treated as data, no added facts, Show's traceability rules, BTW access mode | Built in; nothing overrides them |
843
+ | How much of the source an explanation keeps | The mode: **M** for one explanation, otherwise the saved `mode` |
844
+ | What a Show drawing focuses on | The steering query |
845
+ | Who the answer is for: wording, tone, depth, and answer language | Your [preferences](#preferences), otherwise Bro's built-in defaults |
846
+
847
+ ## Preferences
848
+
849
+ Tell Bro about yourself and how you like answers. Bro adds what you write to
850
+ every explain, `/bro show`, `/bro btw`, and Guided Review prompt as a labelled section,
851
+ alongside its own instructions. It never replaces them: modes, **M**, and the
852
+ source rules keep working. The advisor never receives your preferences; use
853
+ `/bro advisor-steer` for it.
854
+
855
+ Run `/bro preferences` to edit them: **Ctrl+S** saves, **Ctrl+K** deletes the
856
+ file, **Ctrl+C** copies, and **Esc** closes without saving. The first time,
857
+ the editor opens with this starter text, which is not saved until you press
858
+ **Ctrl+S**:
859
+
860
+ ```md
861
+ ## About me
862
+ I'm an overworked white-collar worker, and so are my colleagues. By the end of a
863
+ hard day our brains are fried and we can only handle simple language, no matter
864
+ how sharp we are at our best.
865
+
866
+ ## How I like answers
867
+ - Explain it like I'm a simpleton: plain, everyday words.
868
+ - Go easy on analogies. No forced ones.
869
+ ```
870
+
871
+ You can also edit the file directly (under `$PI_CODING_AGENT_DIR` instead when
872
+ that is set):
873
+
874
+ ```text
875
+ ~/.pi/agent/bro-preferences.md
876
+ ```
877
+
878
+ - **Free-form**: no placeholder or structure is required. Bro re-reads the
879
+ file on every request, so edits apply next time. A missing or empty file
880
+ means no preferences, and Bro's prompts are then exactly the built-in ones.
881
+ - **What preferences can change**: wording, tone, technical depth, length in
882
+ BTW, and the answer language. If you name a language, code, commands, paths,
883
+ names, and numbers still stay exactly as written. In `/bro show`,
884
+ preferences only change wording and language. Guided Review also receives preferences for explanation/answer wording; they do not override its evidence or review rules. A per-run choice (the mode,
885
+ **M**, a Show steering query, or what a BTW/review question asks for) wins over a
886
+ standing preference.
887
+ - **Limit**: 4,000 characters, because the text goes with every request. A
888
+ longer file stops explain, Show, BTW, and Guided Review with an error until you trim it;
889
+ Bro never cuts it silently. `/bro doctor` reports the problem, and the
890
+ editor still opens the file so you can fix it.
891
+ - **BTW threads**: when your preferences change, the next side question starts
892
+ a fresh backend session that is caught up on the thread, so old preferences
893
+ don't linger.
894
+
895
+ `bro-prompt.md`, the full prompt template from earlier versions, is no longer
896
+ read. Move what you want to keep into `/bro preferences`, and choose
897
+ `/bro mode brief` for the original ELI-simpleton instruction.
898
+
899
+
900
+ ## Privacy and safety
901
+
902
+ - **External requests**: Bro sends the latest completed assistant response,
903
+ pasted text, extracted document text, extracted webpage text, or recent
904
+ session conversation text (tool calls, tool results, reasoning, and images
905
+ omitted) to the selected backend and its configured model provider.
906
+ - **Side conversation requests**: `/bro btw` sends your side questions and the
907
+ seeded main-session conversation text (plus earlier turns when a native
908
+ session is reseeded) to the selected backend. In full permission mode the
909
+ side agent can additionally read and edit the workspace.
910
+ - **Guided Review requests**: PR identity/description, captured diff, relevant private discussion and preferences go to the selected backend, which can inspect captured files using Claude/Muse read-only tools. Main-session context is not attached. Review shell/write/web tools are disabled; Claude file tools are confined with `--restricted`, Muse uses workspace-scoped inspection. Prompt injection can still corrupt conclusions or reveal captured content to the provider; this is not a general confidentiality guarantee. See [Guided Review access and storage](guided-review.md#access-privacy-and-storage).
911
+ - **Preferences**: `bro-preferences.md` is sent with every explain, Show,
912
+ BTW, and Guided Review request to the selected backend. It is never sent to the advisor or
913
+ to Pi's main model.
914
+ - **Advisor requests**: `bro_advisor` sends the executor agent's system
915
+ instructions, active tool list (excluding `bro_advisor`), ordered
916
+ conversation history including tool calls and tool results (unlike Show,
917
+ which omits them), your steering brief, and the executor's optional question
918
+ to the selected backend. Reasoning and image bodies are omitted with explicit
919
+ markers (`[reasoning omitted]`, `[image omitted]`). The advisor process runs
920
+ in your workspace with auto-approved permissions; its instruction to only
921
+ advise is behavioral, not an enforced boundary.
922
+ - **Access enforcement** differs by backend; see
923
+ [Backends: access and retention](#backends-access-and-retention). Prompt
924
+ instructions are not access enforcement.
925
+ - **Context isolation**: Bro does not add explanations, BTW answers, or the
926
+ steering brief to Pi's conversation history or main-agent context. BTW text
927
+ reaches the main editor only through `/insert` or `/insert-all`, and advisor
928
+ results appear as normal tool results in the executor's transcript.
929
+ - **Saved reviews**: Guided Review records, questions, drafts and captured Git source persist under the host's `getAgentDir()/bro-reviews/`. No automatic cleanup or sync is provided; see [storage and removal](guided-review.md#access-privacy-and-storage).
930
+ - **Memory**: the latest explanation (for `/bro open`) and the BTW thread live
931
+ only in process memory and clear when you switch Pi sessions, reload
932
+ extensions, or quit Pi. Backend-native sessions can persist independently.
933
+ Standing advisor priorities are stored in `~/.pi/agent/bro-advisor.md`, and
934
+ the session steering brief is stored as session-scoped extension data
935
+ (`bro-advisor-steering`) in the session file.
936
+ - **File safety**: `/bro file` reads only regular files whose resolved path is
937
+ inside Pi's current workspace, including after resolving symlinks. Bro's
938
+ extractor does not modify them.
939
+ - **Web requests**: `/bro url` connects directly to the target website. The site
940
+ sees your IP address and Bro's user agent. Bro sends no browser cookies,
941
+ authorization, or referrer information, and it refuses local, private, and
942
+ reserved network destinations, including redirects. Avoid private or signed
943
+ URLs whose query string contains secrets.
944
+ - **Web extraction**: Bro parses downloaded HTML locally without executing page
945
+ scripts or loading page subresources. It sends the extracted readable text,
946
+ including links preserved in that text, to the selected backend; it does not
947
+ separately send the requested URL or raw page HTML.
948
+ - **Show diagrams**: When a show reply ends in one self-contained HTML block,
949
+ Bro writes it to `pi-bro-<uid>/bro-show-<hash>.html` in your system temp folder with a restrictive
950
+ Content-Security-Policy, and opens it in your browser only when you press
951
+ **O**. **C** copies the full reply, including the HTML.
952
+ - **Clipboard**: **C**, `/copy`, `/copy-all`, and Guided Review's Copy finding copy text to your system
953
+ clipboard, where your operating system or clipboard manager may retain it.
954
+
955
+ ## Troubleshooting and current limits
956
+
957
+ If an explanation fails, run `/bro doctor` first. If a webpage cannot be
958
+ extracted, copy its content into a supported text file or save it as a PDF and
959
+ use `/bro file`. If a PDF contains only scanned images, run OCR with another
960
+ tool before giving it to Bro.
961
+
962
+ - An unsupported model, effort, or missing backend fails with that backend's
963
+ diagnostic; Bro never falls back to another backend.
964
+ - Document input supports `.md`, `.markdown`, `.txt`, `.pdf`, and `.docx` only;
965
+ it does not perform OCR.
966
+ - Webpage input supports one public HTML page, up to 5 MiB downloaded and
967
+ 100,000 extracted characters. JavaScript-only, authenticated, paywalled,
968
+ blocked, paginated, and media-first pages are not supported.
969
+ - Direct webpage fetching does not currently use `HTTP_PROXY`, `HTTPS_PROXY`,
970
+ or other proxy environment variables.
971
+ - `/bro btw` threads are memory-only and do not survive reloads or restarts.
972
+ - The Agy advisor requires Agy CLI `>=1.1.15`.
973
+ - Show captures only the conversation text of what already happened in the
974
+ current session — the last few turns' user and assistant messages, with
975
+ tool calls, tool results, reasoning, and images always omitted; its shapes
976
+ reflect what was reported in the conversation, not independent verification.
977
+ - HTML diagrams open in your default browser; pressing **O** on a remote or
978
+ headless session with no display reports the failure instead of opening
979
+ anything.
980
+ - Explain keeps only the latest result in memory and does not export directly to files. Guided Review separately persists review records and captured source.
981
+ - Guided Review is local-Pi interactive only, keeps its captured revision on reopen, and does not publish, review a branch or fetch later PR changes. See [review recovery and limits](guided-review.md#if-something-goes-wrong).
982
+ - Bro temporarily captures mouse input while its modal is open so mouse-wheel
983
+ and trackpad scrolling work in regular and fullscreen modes. Native mouse
984
+ selection may be unavailable or visually extend outside the Bro window;
985
+ press **C** to copy the full explanation instead.
986
+