pi-bro 0.37.1 → 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.
@@ -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");
@@ -1,180 +1,219 @@
1
- /** Source-focused Simplify modal. No chat thread, durable draft or new backend boundary. */
2
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
3
2
  import { stripVTControlCharacters } from "node:util";
4
3
  import { copyToClipboard } from "@earendil-works/pi-coding-agent";
5
4
  import { matchesKey } from "@earendil-works/pi-tui";
6
- import { BtwModal } from "./btw.ts";
5
+ import { ComposerModal } from "./composer-modal.ts";
7
6
  import { latestAssistant, simplify, type BroResult } from "./explain-modal.ts";
8
7
  import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
9
8
  import { nextBroMode, type BroMode } from "./prompt.ts";
10
9
  import { readSettings } from "./settings.ts";
11
10
  import { extractDocumentText, extractWebPage, type BroSource } from "./sources.ts";
11
+ import { captureShowTranscript, openShowHtml, runShowExplanation, showDiagramPath, stripShowDiagramFence } from "./show.ts";
12
12
  import { hasBroCustomUi } from "./ui-capabilities.ts";
13
13
  import { errorMessage, unquote } from "./util.ts";
14
- import { parseSimplifyAction, SIMPLIFY_MODAL_HELP, type SimplifyAction } from "./simplify-engine.ts";
14
+ import { parseSimplifyAction, SIMPLIFY_MODAL_HELP, type SimplifyRequest } from "./simplify-engine.ts";
15
15
 
16
+ // A blank steering string still marks a Show result. Only captured input and text are persisted.
17
+ export type SimplifyResult = BroResult & { showSteering?: string };
16
18
  export type SimplifyState = {
17
- result?: BroResult;
19
+ result?: SimplifyResult;
18
20
  view?: "result" | "help" | "empty";
19
21
  draft?: string;
20
22
  error?: string;
21
23
  };
22
- export type SimplifyStart =
23
- | { kind:"resume" }
24
- | { kind:"latest" }
25
- | { kind:"text"|"file"|"url"; input:string };
26
24
 
27
- async function resolveSource(ctx: ExtensionCommandContext, request: SimplifyStart | SimplifyAction,
28
- signal: AbortSignal, retained?: BroSource): Promise<BroSource> {
29
- if (retained) return retained;
25
+ type Attempt = SimplifyRequest | { kind: "retry"; result: SimplifyResult; mode?: BroMode };
26
+
27
+ async function resolveSource(ctx: ExtensionCommandContext, request: Exclude<SimplifyRequest, { kind: "show" }>, signal: AbortSignal): Promise<BroSource> {
30
28
  switch (request.kind) {
31
29
  case "latest": {
32
30
  await ctx.waitForIdle();
33
- if (signal.aborted) throw new Error("Cancelled.");
34
- const source=latestAssistant(ctx);
31
+ signal.throwIfAborted();
32
+ const source = latestAssistant(ctx);
35
33
  if (!source) throw new Error("No completed assistant reply to simplify.");
36
- return {text:source.text,label:"Latest assistant reply"};
34
+ return { text: source.text, label: "Latest assistant reply" };
37
35
  }
38
- case "text": return {text:request.input,label:"Pasted text"};
39
- case "file": return {text:await extractDocumentText(request.input,ctx.cwd,signal),label:unquote(request.input)};
40
- case "url": return await extractWebPage(request.input,signal);
41
- default: throw new Error("Choose a source with /simplify, /text, /file or /url.");
36
+ case "text": return { text: request.input, label: "Pasted text" };
37
+ case "file": return { text: await extractDocumentText(request.input, ctx.cwd, signal), label: unquote(request.input) };
38
+ case "url": return await extractWebPage(request.input, signal);
39
+ }
40
+ }
41
+
42
+ async function runSimplify(
43
+ ctx: ExtensionCommandContext, request: Attempt, signal: AbortSignal,
44
+ onWaiting?: (show: boolean) => void, onText?: (text: string) => void,
45
+ ): Promise<SimplifyResult> {
46
+ const saved = request.kind === "retry" ? request.result : undefined;
47
+ const steering = request.kind === "show" ? request.steering : saved?.showSteering;
48
+ const source = saved?.source ?? (request.kind === "show" || request.kind === "retry" ? undefined : await resolveSource(ctx, request, signal));
49
+ signal.throwIfAborted();
50
+ const settings = await readSettings();
51
+ signal.throwIfAborted();
52
+ if (steering !== undefined) {
53
+ const captured = source ?? captureShowTranscript(ctx, (request.kind === "show" ? request.turns : undefined) ?? settings.showTurns);
54
+ if (!captured?.text) throw new Error("Nothing to show yet. Start a conversation, then run /show again.");
55
+ onWaiting?.(true);
56
+ return { source: captured, showSteering: steering, ...await runShowExplanation(captured.text, steering, signal, settings, onText) };
42
57
  }
58
+ if (!source) throw new Error("Choose a source first.");
59
+ onWaiting?.(false);
60
+ return { source, ...await simplify(source.text, signal, settings, onText, request.kind === "retry" ? request.mode : undefined) };
43
61
  }
44
62
 
45
- /** The state belongs to the parent /bro extension instance and resets on session_start. */
46
- export async function openSimplifyWorkflow(
47
- ctx: ExtensionCommandContext,
48
- state: SimplifyState,
49
- initial: SimplifyStart,
50
- ): Promise<void> {
63
+ function showResult(state: SimplifyState, result: SimplifyResult): void {
64
+ state.result = result;
65
+ state.view = "result";
66
+ state.error = undefined;
67
+ }
68
+
69
+ /** Explicit sources can run headless; a viewer open never makes a model call. */
70
+ export async function openSimplifyWorkflow(ctx: ExtensionCommandContext, state: SimplifyState, initial?: SimplifyRequest, submitted?: string): Promise<void> {
51
71
  if (!hasBroCustomUi(ctx)) {
52
- if (initial.kind==="resume") { ctx.ui.notify("Simplify's interactive view requires Pi TUI.", "warning"); return; }
53
- const controller=new AbortController();
54
- const source=await resolveSource(ctx,initial,controller.signal);
55
- const result=await simplify(source.text,controller.signal,await readSettings());
56
- state.result={source,...result};
57
- state.view="result"; state.error=undefined;
72
+ if (!initial) {
73
+ ctx.ui.notify("Simplify's interactive view requires Pi TUI. Use /bro simplify latest, text, file, url, or show to run without it.", "warning");
74
+ return;
75
+ }
76
+ showResult(state, await runSimplify(ctx, initial, new AbortController().signal));
58
77
  return;
59
78
  }
60
79
 
61
- if (initial.kind === "resume") {
62
- state.view = state.result ? "result" : "help";
63
- if (!state.draft?.trim()) state.error = undefined;
64
- }
80
+ state.view = state.result ? "result" : "help";
81
+ if (!state.draft?.trim()) state.error = undefined;
82
+ // Rebuild from the saved answer, not a stale path from a previous process.
83
+ const prepareDiagram = (result: SimplifyResult | undefined) => result?.showSteering === undefined
84
+ ? undefined
85
+ : showDiagramPath(result.text, message => ctx.ui.notify(message, "warning"));
86
+ const restoredDiagram = prepareDiagram(state.result);
87
+ let htmlPath = restoredDiagram ? await restoredDiagram : undefined;
65
88
 
66
- await openBroOverlay<void>(ctx,(tui,theme,_keys,done)=>{
67
- let closed=false;
68
- let controller:AbortController|undefined;
69
- let stopProgress:(()=>void)|undefined;
70
- let running=false;
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);};
73
- const modal=new BtwModal(tui,theme,close,submit,()=>{
74
- if(!closed){closed=true;syncDraft();stopProgress?.();controller?.abort();}
75
- },{
76
- title:"Bro · simplify",
77
- commands:"",
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",
89
+ await openBroOverlay<void>(ctx, (tui, theme, _keys, done) => {
90
+ let closed = false;
91
+ let controller: AbortController | undefined;
92
+ let stopProgress: (() => void) | undefined;
93
+ const dispose = () => {
94
+ if (closed) return;
95
+ closed = true;
96
+ state.draft = modal.getComposerText();
97
+ if (!state.draft.trim()) state.error = undefined;
98
+ stopProgress?.();
99
+ controller?.abort();
100
+ };
101
+ const readingResult = () => state.view === "result" ? state.result : undefined;
102
+ const idleHint = () => {
103
+ const result = readingResult();
104
+ return `Enter run${result?.mode ? " · M change mode" : ""}${result && htmlPath ? " · O open diagram" : ""}${result ? " · R retry · /copy" : ""} · /help · Esc ${state.view === "help" && state.result ? "back" : "close"}`;
105
+ };
106
+ const modal = new ComposerModal(tui, theme, () => { dispose(); done(undefined); }, submit, dispose, {
107
+ title: "Bro · simplify",
108
+ inputLabel: "Simplify command · /simplify runs again on the latest reply",
109
+ idleHint,
80
110
  });
81
- const display=()=>{
82
- modal.setCustomMode(state.result?.mode ? state.result.mode+(state.result.preferences ? " · prefs" : "") : "one source · one explanation");
83
- modal.setModel(state.result?.model ?? "");
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
- );
89
- // Notices describe the currently shown state, not an earlier request.
90
- modal.setNotice(state.error ?? "",state.error ? "error" : "info");
111
+ const display = () => {
112
+ const result = readingResult();
113
+ const label = result?.source.label && stripVTControlCharacters(result.source.label).replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
114
+ const mode = result?.mode ?? (result?.showSteering !== undefined ? "diagram" : "one source");
115
+ modal.setCustomMode(mode + (result?.preferences ? " · prefs" : ""));
116
+ modal.setModel(result?.model ?? "");
117
+ modal.setText(result
118
+ ? (label ? `**Source:** ${label}\n\n---\n\n` : "") + (htmlPath ? stripShowDiagramFence(result.text) : result.text)
119
+ : SIMPLIFY_MODAL_HELP);
120
+ modal.setNotice(state.error ?? "", state.error ? "error" : "info");
91
121
  modal.scrollToStart();
92
122
  };
93
- const run=async (request:SimplifyStart|SimplifyAction, retained?:BroSource, mode?:BroMode, submitted?:string)=>{
94
- if(running||closed)return;
95
- const attempt=new AbortController();
96
- controller=attempt; running=true;
97
- modal.setRunning(true);modal.setNotice("");
98
- let phase=request.kind==="url" ? "Fetching page" : request.kind==="file" ? "Reading file"
99
- : request.kind==="latest" ? "Getting latest reply" : "Preparing source";
100
- const stop=startProgressClock(attempt.signal,seconds=>{
101
- if(!closed&&controller===attempt)modal.setProgress(`${phase} · ${seconds}s`);
123
+ const run = async (request: Attempt, command?: string) => {
124
+ if (controller || closed) return;
125
+ const attempt = new AbortController();
126
+ controller = attempt;
127
+ modal.setRunning(true);
128
+ modal.setNotice("");
129
+ let phase = request.kind === "url" ? "Fetching page" : request.kind === "file" ? "Reading file"
130
+ : request.kind === "latest" ? "Getting latest reply" : "Preparing source";
131
+ const stop = startProgressClock(attempt.signal, seconds => {
132
+ if (!closed) modal.setProgress(`${phase} · ${seconds}s`);
102
133
  });
103
- stopProgress=stop;
104
- const previous=state.result,previousView=state.view;
134
+ stopProgress = stop;
105
135
  try {
106
- const source=await resolveSource(ctx,request,attempt.signal,retained);
107
- if(closed||attempt.signal.aborted)return;
108
- const currentSettings=await readSettings();
109
- phase="Waiting for explanation";
110
- const result=await simplify(source.text,attempt.signal,currentSettings,text=>{
111
- if(!closed&&!attempt.signal.aborted){
112
- phase="Receiving explanation";
136
+ const result = await runSimplify(ctx, request, attempt.signal,
137
+ show => { phase = show ? "Drawing recent turns" : "Waiting for explanation"; },
138
+ text => {
139
+ if (closed) return;
140
+ phase = "Receiving output";
113
141
  modal.setText(text);
114
- }
115
- },mode);
116
- if(closed||attempt.signal.aborted)return;
117
- state.result={source,...result};
118
- state.view="result";state.error=undefined;
119
- display();
120
- if(mode && mode !== currentSettings.mode)modal.setNotice("Mode: "+mode+" (not saved)");
121
- } catch(error){
122
- if(closed||attempt.signal.aborted)return;
123
- state.result=previous;state.view=previousView;
124
- state.error=errorMessage(error);
142
+ });
143
+ if (closed) return;
144
+ const diagram = await prepareDiagram(result);
145
+ if (closed) return;
146
+ htmlPath = diagram;
147
+ showResult(state, result);
125
148
  display();
126
- // Failed replacement is editable and retryable. Do not overwrite text the user
127
- // entered while this request was running. Preserve it on modal close as well.
128
- if(submitted && !modal.getComposerText().trim()) {
129
- modal.setComposerText(submitted);
130
- state.draft=submitted;
149
+ if (request.kind === "retry" && request.mode !== undefined && request.mode !== request.result.mode) {
150
+ modal.setNotice(`Mode: ${request.mode} (not saved)`);
131
151
  }
152
+ } catch (error) {
153
+ if (closed) return;
154
+ state.error = (request.kind === "retry" ? "Retry failed: " : "") + errorMessage(error);
155
+ display();
156
+ // Retain failed input without overwriting a command typed while it ran.
157
+ if (command && !modal.getComposerText().trim()) modal.setComposerText(command);
132
158
  } finally {
133
159
  stop();
134
- if(stopProgress===stop)stopProgress=undefined;
135
- if(controller===attempt)controller=undefined;
136
- running=false;
137
- if(!closed)modal.setRunning(false);
160
+ stopProgress = undefined;
161
+ controller = undefined;
162
+ if (!closed) modal.setRunning(false);
138
163
  }
139
164
  };
140
- const retry=(switchMode=false)=>{
141
- if(running||!state.result)return;
142
- const next=switchMode?nextBroMode(state.result.mode??"balanced"):state.result.mode;
143
- void run({kind:"latest"},state.result.source,next);
165
+ const retry = (switchMode = false) => {
166
+ const result = state.result;
167
+ if (!result || (switchMode && !result.mode)) return;
168
+ const mode = switchMode && result.mode ? nextBroMode(result.mode) : result.mode;
169
+ void run({ kind: "retry", result, mode });
144
170
  };
145
- const copy=()=>{
146
- if(!state.result?.text){modal.setNotice("Nothing to copy yet.","warning");return;}
171
+ const copy = () => {
172
+ if (!state.result?.text) { modal.setNotice("Nothing to copy yet.", "warning"); return; }
147
173
  void copyToClipboard(state.result.text)
148
- .then(()=>{if(!closed)modal.setNotice("Explanation copied.","success");})
149
- .catch(error=>{if(!closed)modal.setNotice("Copy failed: "+errorMessage(error),"error");});
174
+ .then(() => { if (!closed) modal.setNotice("Result copied.", "success"); })
175
+ .catch(error => { if (!closed) modal.setNotice("Copy failed: " + errorMessage(error), "error"); });
150
176
  };
151
- function submit(raw:string):void {
152
- if(running||closed)return;
153
- const action=parseSimplifyAction(raw);
154
- if(action.kind==="invalid"){modal.setNotice(action.message,"warning");return;}
155
- modal.clearComposer();state.draft=undefined;
156
- if(action.kind==="copy"){copy();return;}
157
- if(action.kind==="clear"){
158
- state.result=undefined;state.view="empty";state.error=undefined;display();return;
177
+ function submit(raw: string): void {
178
+ if (controller || closed) return;
179
+ const action = parseSimplifyAction(raw);
180
+ if (action.kind === "invalid") { modal.setNotice(action.message, "warning"); return; }
181
+ modal.clearComposer();
182
+ state.draft = undefined;
183
+ switch (action.kind) {
184
+ case "copy": copy(); return;
185
+ case "clear": state.result = undefined; state.view = "empty"; htmlPath = undefined; break;
186
+ case "help": state.view = "help"; break;
187
+ case "retry": retry(); return;
188
+ default: void run(action, raw); return;
159
189
  }
160
- if(action.kind==="help"){state.view="help";state.error=undefined;display();return;}
161
- if(action.kind==="retry"){retry();return;}
162
- void run(action,undefined,undefined,raw);
190
+ state.error = undefined;
191
+ display();
163
192
  }
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;
193
+ modal.onKey = data => {
194
+ if (!controller && state.view === "help" && state.result && matchesKey(data, "escape")) {
195
+ state.view = "result";
196
+ state.error = undefined;
197
+ display();
198
+ return true;
199
+ }
200
+ if (controller || modal.getComposerText().trim()) return false;
201
+ const result = readingResult();
202
+ if (!result) return false;
203
+ const key = data.toLowerCase();
204
+ if (key === "m" && result.mode) { retry(true); return true; }
205
+ if (key === "r") { retry(); return true; }
206
+ if (key === "c") { copy(); return true; }
207
+ if (key === "o" && htmlPath) {
208
+ const opened = openShowHtml(htmlPath);
209
+ modal.setNotice(opened ? "Opening diagram" : `Could not open ${htmlPath}. Reopen Simplify to rebuild it.`, opened ? "info" : "error");
210
+ return true;
167
211
  }
168
- if(running||modal.getComposerText().trim())return false;
169
- if(matchesKey(data,"m")||matchesKey(data,"shift+m")){retry(true);return Boolean(state.result);}
170
- if(matchesKey(data,"r")||matchesKey(data,"shift+r")){retry();return Boolean(state.result);}
171
- if(matchesKey(data,"c")||matchesKey(data,"shift+c")){copy();return true;}
172
212
  return false;
173
213
  };
174
214
  display();
175
- if(state.draft)modal.setComposerText(state.draft);
176
- if(initial.kind!=="resume")queueMicrotask(()=>{if(!closed)void run(initial,undefined,undefined,
177
- initial.kind==="latest" ? "/simplify" : "/"+initial.kind+" "+initial.input);});
215
+ if (state.draft) modal.setComposerText(state.draft);
216
+ if (initial) queueMicrotask(() => { void run(initial, submitted); });
178
217
  return modal;
179
- },{mouse:true});
218
+ }, { mouse: true });
180
219
  }
package/src/sources.ts CHANGED
@@ -25,7 +25,7 @@ export const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
25
25
 
26
26
  export async function extractDocumentText(input: string, cwd: string, signal?: AbortSignal): Promise<string> {
27
27
  const requested = unquote(input.trim());
28
- if (!requested) throw new Error("Use /bro file <path>.");
28
+ if (!requested) throw new Error("Use /bro simplify file <path>.");
29
29
  if (signal?.aborted) throw new Error("Canceled.");
30
30
 
31
31
  let path: string;
@@ -143,13 +143,13 @@ export function isPublicWebAddress(address: string): boolean {
143
143
 
144
144
  export function parseWebUrl(input: string): URL {
145
145
  const requested = unquote(input.trim());
146
- if (!requested) throw new Error("Use /bro url <url>.");
146
+ if (!requested) throw new Error("Use /bro simplify url <url>.");
147
147
 
148
148
  let url: URL;
149
149
  try {
150
150
  url = new URL(requested);
151
151
  } catch {
152
- throw new Error("That is not a valid URL. Use /bro url https://example.com/article.");
152
+ throw new Error("That is not a valid URL. Use /bro simplify url https://example.com/article.");
153
153
  }
154
154
  if (url.protocol !== "http:" && url.protocol !== "https:") {
155
155
  throw new Error("Bro can read only public HTTP or HTTPS webpages.");