pi-bro 0.36.3 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  All notable changes to pi-bro are documented here.
4
4
 
5
+ ## [0.37.0] - 2026-11-18
6
+
7
+ ### Highlights
8
+
9
+ - Open `/bro` or `/bro simplify` to read the saved explanation, or help if none exists, without a model call, starting at the top of the view.
10
+ - Press Esc from Simplify help to return to the saved explanation without losing your unfinished input.
11
+ - Explain supported local documents outside the workspace using relative paths, absolute paths or symlinks.
12
+
13
+ ### Breaking
14
+
15
+ - Bare `/bro` no longer generates an explanation of the latest assistant reply. Open `/bro`, then run `/simplify` inside, or use `/bro text` without text to generate it directly. Headless callers must use `/bro text` instead of `/bro`.
16
+ - Replaced the exported `isWorkspaceFile` helper with `isDocumentFile`.
17
+
5
18
  ## [0.36.3] - 2026-11-10
6
19
 
7
20
  ### Improved
package/README.md CHANGED
@@ -46,7 +46,7 @@ For a first success, type this in Pi after setting up a backend:
46
46
 
47
47
  | After that | What happens |
48
48
  | --- | --- |
49
- | `/bro` | Explains the agent's latest completed reply (requires one) |
49
+ | `/bro` | Shows the saved explanation, or help if none exists. Run `/simplify` inside to explain the latest reply again. |
50
50
  | `/bro copy` | Edit and preview the raw Markdown of the last assistant reply before copying |
51
51
  | `/bro btw What is a race condition?` | Asks a private side question |
52
52
  | `/bro show` | Draws the current session's recent conversation, if any |
@@ -2,6 +2,8 @@
2
2
 
3
3
  [Docs home](../README.md) · [All commands](../reference/commands.md) · [Safety and permissions](../reference/data-and-permissions.md)
4
4
 
5
+ Opening `/bro` or `/bro simplify` shows your saved explanation, or command help if none exists. It does not call the model. Run `/simplify` inside the modal to explain the latest completed assistant reply again.
6
+
5
7
  ## Explanation modes
6
8
 
7
9
  Bro treats quoted source as data and asks the model to ignore embedded
@@ -31,7 +33,7 @@ next mode without saving it:
31
33
  the mode saved by `/bro mode`; pressing it again while Bro is working skips
32
34
  ahead
33
35
  - **O**: Open the diagram (an HTML layout or a rendered sequence diagram) when a show reply contains one
34
- - **Esc**: Close the modal, or cancel while Bro is working
36
+ - **Esc**: From `/help`, return to the saved explanation without rerunning it. If there is no saved explanation, or you are already reading it, close the modal. While Bro is working, cancel and close.
35
37
 
36
38
  The modal header shows the model and reasoning effort the explanation or
37
39
  drawing used (`default` when the model's own effort applies), followed by the
@@ -56,7 +58,7 @@ to simplify the same captured text again.
56
58
 
57
59
  ## Explain a document
58
60
 
59
- Use a path relative to Pi's current workspace, or an absolute path inside it:
61
+ Use a relative or absolute path, including files outside Pi's current workspace. Symlinks are followed; normal OS file permissions apply:
60
62
 
61
63
  ```text
62
64
  /bro file "docs/incident review.pdf"
@@ -34,10 +34,10 @@ This step makes a **real model call**, which may use your backend account's quot
34
34
 
35
35
  | I want to… | Command |
36
36
  | --- | --- |
37
- | Understand the last agent answer | `/bro` (after the main agent has replied) |
37
+ | Understand the last agent answer | Open `/bro`, then run `/simplify` inside |
38
38
  | Ask a side question | `/bro btw What is a race condition?` |
39
39
  | Visualize what we discussed | `/bro show` (after at least one user turn) |
40
- | Explain a file in my workspace | `/bro file docs/my-report.md` (**replace with an existing path**) |
40
+ | Explain a local file | `/bro file docs/my-report.md` (**replace with an existing path**) |
41
41
  | Explain an actual public webpage | `/bro url https://your-public-page.example` (**replace with a real URL**) |
42
42
 
43
43
  See the [docs home](README.md) for detailed workflows.
@@ -6,12 +6,12 @@
6
6
 
7
7
  | Source | Command | What Bro does |
8
8
  | --- | --- | --- |
9
- | Latest assistant reply | `/bro` | Opens Simplify and explains the latest completed reply without inserting the result into Pi's conversation. |
9
+ | Latest assistant reply | `/simplify` inside `/bro`, or `/bro text` | Explains the latest completed reply without inserting the result into Pi's conversation. Opening `/bro` itself shows the saved explanation, or help if none exists. |
10
10
  | Pasted text | `/bro text <text>` | Explains text supplied directly in the command. |
11
- | Local document | `/bro file <path>` | Extracts text from a workspace-local Markdown, text, PDF, or DOCX file. |
11
+ | Local document | `/bro file <path>` | Extracts text from a local Markdown, text, PDF, or DOCX file. |
12
12
  | Public webpage | `/bro url <url>` | Fetches one public HTML page and extracts its main readable content. |
13
13
  | 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). |
14
- | 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. |
14
+ | Any of the above, auto-detected | `/bro <input>` | Routes a lone URL to the webpage reader, an existing local file with a supported extension to the document reader, and anything else to pasted text. |
15
15
 
16
16
  Pressing **R** simplifies the captured source again in the mode shown, and
17
17
  **M** re-simplifies it in the next mode. These commands capture a
@@ -26,12 +26,12 @@ Typing `/bro ` displays ten task-level suggestions: `simplify`, `show`, `btw`, `
26
26
 
27
27
  | Command | Description |
28
28
  | --- | --- |
29
- | `/bro` | Open Simplify and explain the latest completed assistant reply. |
29
+ | `/bro` | Show the saved explanation, or help if none exists. No model call; run `/simplify` inside to explain the latest reply again. |
30
30
  | `/bro simplify` | Reopen the last Simplify screen within this Pi session, without a new model call. |
31
31
  | `/bro copy` | Edit and preview the latest completed assistant reply as raw Markdown. Ctrl+D switches views; Ctrl+C copies Markdown; F1 opens Help. No backend call or saved draft. Native Pi `/copy` copies immediately. [Guide](../features/copy.md). |
32
- | `/bro text <text>` | Explain pasted text. |
33
- | `/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. |
34
- | `/bro file <path>` | Explain a workspace-local `.md`, `.markdown`, `.txt`, `.pdf`, or `.docx` file. |
32
+ | `/bro text [text]` | Explain pasted text, or the latest completed assistant reply when text is omitted. |
33
+ | `/bro <input>` | Explain it directly: a lone URL runs the webpage reader, an existing local 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. |
34
+ | `/bro file <path>` | Explain a local `.md`, `.markdown`, `.txt`, `.pdf`, or `.docx` file. |
35
35
  | `/bro url <url>` | Explain one public, text-based webpage. |
36
36
  | `/bro open` | Legacy compatibility shortcut to the last result. No `/open` command inside Simplify. |
37
37
  | `/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. |
@@ -131,9 +131,9 @@ See [feature guide](../features/architecture.md).
131
131
  - **Private session continuity**: completed BTW and Grill Me turns, modes, drafts, the latest Simplify state and the last Show result are saved as Pi `custom` entries inside the current session file. They survive normal reload/restart and are never added to the main model or Advisor snapshot. A fork initially inherits earlier entries; later updates stay on its own branch. This is local disk storage, not a global memory store or an abrupt-crash guarantee. Backend-native sessions may persist independently.
132
132
  Standing Advisor priorities are stored in `~/.pi/agent/bro-advisor.md`, and
133
133
  the session steering brief uses another `custom` entry (`bro-advisor-steering`). Session entries remain readable to anyone with the session file; export/sharing may include them. The private boundary is model-context isolation, not encrypted storage or export redaction.
134
- - **File safety**: `/bro file` reads only regular files whose resolved path is
135
- inside Pi's current workspace, including after resolving symlinks. Bro's
136
- extractor does not modify them.
134
+ - **File access**: `/bro file` reads regular files at the selected relative or
135
+ absolute path, including outside Pi's current workspace and through symlinks.
136
+ Normal OS permissions apply. Bro's extractor does not modify the files.
137
137
  - **Web requests**: `/bro url` connects directly to the target website. The site
138
138
  sees your IP address and Bro's user agent. Bro sends no browser cookies,
139
139
  authorization, or referrer information, and it refuses local, private, and
@@ -166,7 +166,7 @@ See [Troubleshooting and current limits](reference/troubleshooting.md#troublesho
166
166
 
167
167
  ## Simplify modal
168
168
 
169
- `/bro` opens Simplify and explains the latest completed assistant reply. `/bro simplify` returns to the most recent Simplify screen without another model request. Inside, `/simplify`, `/text <text>`, `/file <path>` and `/url <url>` produce one explanation at a time; `/copy` copies the answer, `/clear` clears it, and `/help` shows controls. Press **M** with an empty composer to change the explanation mode and rerun; **R** retries. The saved default mode remains unchanged. The latest result is preserved in private Pi session entries across reload/restart and stays off the main model's context. Old `/bro text|file|url|open` forms remain callable for compatibility.
169
+ `/bro` and `/bro simplify` open the saved explanation, or help if none exists, without a model request. Run `/simplify` inside to explain the latest completed assistant reply. Inside, `/simplify`, `/text <text>`, `/file <path>` and `/url <url>` produce one explanation at a time; `/copy` copies the answer, `/clear` clears it, and `/help` shows controls. Press **M** with an empty composer to change the explanation mode and rerun; **R** retries. The saved default mode remains unchanged. The latest result is preserved in private Pi session entries across reload/restart and stays off the main model's context. Old `/bro text|file|url|open` forms remain callable for compatibility.
170
170
 
171
171
  ## Bro command discovery and Config navigation
172
172
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bro",
3
- "version": "0.36.3",
3
+ "version": "0.37.0",
4
4
  "description": "A sidekick for you and your Pi agent: plain-language explanations, side questions, diagrams, PR review and second opinions, without cluttering the agent's context.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/bro.ts CHANGED
@@ -46,7 +46,7 @@ import {
46
46
  } from "./show.ts";
47
47
  import {
48
48
  type BroSource,
49
- isWorkspaceFile,
49
+ isDocumentFile,
50
50
  looksLikeWebUrl,
51
51
  } from "./sources.ts";
52
52
  import { hasBroCustomUi } from "./ui-capabilities.ts";
@@ -189,13 +189,6 @@ export default async function bro(pi: ExtensionAPI) {
189
189
  let action = parts[0] ?? "";
190
190
  let value = raw.slice(raw.split(/\s+/, 1)[0]?.length ?? 0).trim();
191
191
 
192
- if (action === "simplify") {
193
- if (value) { ctx.ui.notify("Use /bro simplify to reopen the last Simplify view; use /text, /file or /url inside it.", "warning"); return; }
194
- try { await openSimplifyWorkflow(ctx, simplifyState, {kind:"resume"}); saveSimplify(); if (simplifyState.result) remember(simplifyState.result); }
195
- catch (error) { ctx.ui.notify(withDoctor(error), "error"); }
196
- return;
197
- }
198
-
199
192
  // Removed commands must never fall through to a paid text explanation.
200
193
  if (action === "model" || action === "effort") {
201
194
  ctx.ui.notify(`/bro ${action} was removed. Use /bro config to choose the shared default and per-capability ${action}; use /bro text <text> to explain text.`, "warning");
@@ -209,7 +202,7 @@ export default async function bro(pi: ExtensionAPI) {
209
202
  action = quoted || !/\s/.test(candidate)
210
203
  ? looksLikeWebUrl(candidate)
211
204
  ? "url"
212
- : (await isWorkspaceFile(candidate, ctx.cwd))
205
+ : (await isDocumentFile(candidate, ctx.cwd))
213
206
  ? "file"
214
207
  : "text"
215
208
  : "text";
@@ -218,12 +211,18 @@ export default async function bro(pi: ExtensionAPI) {
218
211
 
219
212
  // Source operations open the same single-purpose Simplify modal, not separate
220
213
  // top-level workflows. Old /bro text|file|url commands remain valid aliases.
221
- if (!action || action === "text" || action === "file" || action === "url") {
214
+ if (!action || action === "simplify" || action === "text" || action === "file" || action === "url") {
215
+ if (action === "simplify" && value) {
216
+ ctx.ui.notify("Use /bro simplify to reopen the last Simplify view; use /text, /file or /url inside it.", "warning");
217
+ return;
218
+ }
222
219
  if ((action === "file" || action === "url") && !value) {
223
220
  ctx.ui.notify(`Use /bro ${action} <${action === "file" ? "path" : "url"}>.`, "warning");
224
221
  return;
225
222
  }
226
- const initial = !action || (action === "text" && !value)
223
+ const initial = !action || action === "simplify"
224
+ ? {kind:"resume" as const}
225
+ : action === "text" && !value
227
226
  ? {kind:"latest" as const}
228
227
  : {kind:action as "text" | "file" | "url", input:value};
229
228
  try {
@@ -501,7 +500,7 @@ export default async function bro(pi: ExtensionAPI) {
501
500
  }
502
501
  if (!lastResult) {
503
502
  await showBroModal(ctx, {
504
- text: "# Nothing to open yet\n\nUse `/bro text <text>`, run `/bro` after an assistant response, use `/bro file <path>`, use `/bro url <url>`, or run `/bro show` to draw recent turns.",
503
+ text: "# Nothing to open yet\n\nUse `/bro text <text>`, run `/bro text` (or `/simplify` inside `/bro`) after an assistant response, use `/bro file <path>`, use `/bro url <url>`, or run `/bro show` to draw recent turns.",
505
504
  kind: "empty",
506
505
  });
507
506
  return;
package/src/btw.ts CHANGED
@@ -229,6 +229,12 @@ export class BtwModal implements Focusable {
229
229
  this.tui.requestRender();
230
230
  }
231
231
 
232
+ /** Start at the top of a static or single-document view. */
233
+ scrollToStart(): void {
234
+ this.scroller.toStart();
235
+ this.tui.requestRender();
236
+ }
237
+
232
238
  /** Show the newest text and keep following it while a reply streams. */
233
239
  scrollToEnd(): void {
234
240
  this.scroller.toEnd();
@@ -381,10 +381,10 @@ These are needs, not modes. Copied text does not enter Pi until you paste and su
381
381
 
382
382
  ## Explain and show
383
383
 
384
- - \`/bro\` — open Simplify and explain the latest completed assistant reply
384
+ - \`/bro\` — read the saved explanation, or help if none exists; /simplify inside runs again
385
385
  - \`/bro simplify\` — reopen the current Simplify screen without another model call
386
386
  - \`/bro text [text]\` — explain pasted text, or the latest reply when text is omitted
387
- - \`/bro file <path>\` — explain a workspace \`.md\`, \`.markdown\`, \`.txt\`, \`.pdf\`, or \`.docx\` file
387
+ - \`/bro file <path>\` — explain a local \`.md\`, \`.markdown\`, \`.txt\`, \`.pdf\`, or \`.docx\` file
388
388
  - \`/bro url <url>\` — explain one public webpage
389
389
  - \`/bro <input>\` — a lone URL, an existing supported file, or anything else as pasted text
390
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)
@@ -28,10 +28,10 @@ export const SIMPLIFY_MODAL_HELP = [
28
28
  "- \`/simplify\` — explain the latest completed assistant reply",
29
29
  "- \`/url <url>\` — explain a public webpage",
30
30
  "- \`/text <text>\` — explain pasted text",
31
- "- \`/file <path>\` — explain a workspace document",
31
+ "- \`/file <path>\` — explain a local document (any readable path)",
32
32
  "- \`/copy\` — copy the current explanation",
33
33
  "- \`/clear\` — clear the explanation and source",
34
34
  "- \`/help\` — show these commands",
35
35
  "",
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** closes; /bro simplify reopens this view in the current Pi session.",
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.",
37
37
  ].join("\n");
@@ -58,29 +58,37 @@ export async function openSimplifyWorkflow(
58
58
  return;
59
59
  }
60
60
 
61
+ if (initial.kind === "resume") {
62
+ state.view = state.result ? "result" : "help";
63
+ if (!state.draft?.trim()) state.error = undefined;
64
+ }
65
+
61
66
  await openBroOverlay<void>(ctx,(tui,theme,_keys,done)=>{
62
67
  let closed=false;
63
68
  let controller:AbortController|undefined;
64
69
  let stopProgress:(()=>void)|undefined;
65
70
  let running=false;
66
- const close=()=>{if(closed)return; closed=true;state.draft=modal.getComposerText();stopProgress?.();controller?.abort();done(undefined);};
71
+ const syncDraft=()=>{const draft=modal.getComposerText();state.draft=draft;if(!draft.trim())state.error=undefined;};
72
+ const close=()=>{if(closed)return; closed=true;syncDraft();stopProgress?.();controller?.abort();done(undefined);};
67
73
  const modal=new BtwModal(tui,theme,close,submit,()=>{
68
- closed=true;state.draft=modal.getComposerText();stopProgress?.();controller?.abort();
74
+ if(!closed){closed=true;syncDraft();stopProgress?.();controller?.abort();}
69
75
  },{
70
76
  title:"Bro · simplify",
71
77
  commands:"",
72
- inputLabel:"Simplify command",
73
- idleHint:"Enter run · M change mode · R retry · /copy · /help · Esc close",
78
+ inputLabel:"Simplify command · /simplify runs again on the latest reply",
79
+ idleHint:"Enter run · M change mode · R retry · /copy · /help · Esc back from help / close",
74
80
  });
75
81
  const display=()=>{
76
82
  modal.setCustomMode(state.result?.mode ? state.result.mode+(state.result.preferences ? " · prefs" : "") : "one source · one explanation");
77
83
  modal.setModel(state.result?.model ?? "");
78
- if(state.view==="help")modal.setText(SIMPLIFY_MODAL_HELP);
79
- else if(state.view==="result"&&state.result)modal.setText((state.result.source.label ? "**Source:** "+stripVTControlCharacters(state.result.source.label).replace(/[\r\n]/g," ")+"\n\n---\n\n" : "")+state.result.text);
80
- else modal.setText("## Simplify\n\nUse /simplify for the latest reply, /text, /file or /url for another source. Type /help for all commands.");
84
+ modal.setText(
85
+ state.view==="result"&&state.result
86
+ ? (state.result.source.label ? "**Source:** "+stripVTControlCharacters(state.result.source.label).replace(/[\r\n]/g," ")+"\n\n---\n\n" : "")+state.result.text
87
+ : SIMPLIFY_MODAL_HELP,
88
+ );
81
89
  // Notices describe the currently shown state, not an earlier request.
82
90
  modal.setNotice(state.error ?? "",state.error ? "error" : "info");
83
- modal.scrollToEnd();
91
+ modal.scrollToStart();
84
92
  };
85
93
  const run=async (request:SimplifyStart|SimplifyAction, retained?:BroSource, mode?:BroMode, submitted?:string)=>{
86
94
  if(running||closed)return;
@@ -154,6 +162,9 @@ export async function openSimplifyWorkflow(
154
162
  void run(action,undefined,undefined,raw);
155
163
  }
156
164
  modal.onKey=(data:string)=>{
165
+ if(!running && state.view==="help" && state.result && matchesKey(data,"escape")){
166
+ state.view="result";state.error=undefined;display();return true;
167
+ }
157
168
  if(running||modal.getComposerText().trim())return false;
158
169
  if(matchesKey(data,"m")||matchesKey(data,"shift+m")){retry(true);return Boolean(state.result);}
159
170
  if(matchesKey(data,"r")||matchesKey(data,"shift+r")){retry();return Boolean(state.result);}
package/src/sources.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile, stat, realpath } from "node:fs/promises";
2
- import { isAbsolute, relative, resolve, extname, sep } from "node:path";
2
+ import { resolve, extname } from "node:path";
3
3
  import { request as httpRequest, type IncomingMessage, type ClientRequest } from "node:http";
4
4
  import { request as httpsRequest } from "node:https";
5
5
  import { lookup } from "node:dns/promises";
@@ -28,20 +28,13 @@ export async function extractDocumentText(input: string, cwd: string, signal?: A
28
28
  if (!requested) throw new Error("Use /bro file <path>.");
29
29
  if (signal?.aborted) throw new Error("Canceled.");
30
30
 
31
- let root: string;
32
31
  let path: string;
33
32
  try {
34
- root = await realpath(cwd);
35
33
  path = await realpath(resolve(cwd, requested));
36
34
  } catch (error) {
37
35
  throw fileError(requested, error);
38
36
  }
39
37
 
40
- const fromRoot = relative(root, path);
41
- if (fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot)) {
42
- throw new Error("Bro can read only files inside the current workspace.");
43
- }
44
-
45
38
  let info;
46
39
  try {
47
40
  info = await stat(path);
@@ -86,14 +79,9 @@ export async function extractDocumentText(input: string, cwd: string, signal?: A
86
79
  return text;
87
80
  }
88
81
 
89
- export async function isWorkspaceFile(input: string, cwd: string): Promise<boolean> {
90
- // ponytail: duplicates extractDocumentText's workspace guard rather than sharing its error semantics.
82
+ export async function isDocumentFile(input: string, cwd: string): Promise<boolean> {
91
83
  try {
92
84
  const path = await realpath(resolve(cwd, input));
93
- const fromRoot = relative(await realpath(cwd), path);
94
- if (fromRoot === ".." || fromRoot.startsWith(`..${sep}`) || isAbsolute(fromRoot)) {
95
- return false;
96
- }
97
85
  const info = await stat(path);
98
86
  return info.isFile() && SNIFFABLE_FILE_EXTENSIONS.has(extname(path).toLowerCase());
99
87
  } catch {