pi-bro 0.37.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +18 -22
- package/docs/README.md +7 -7
- package/docs/elevate.md +10 -93
- package/docs/examples.md +1 -1
- package/docs/feature-map.md +33 -0
- package/docs/features/architecture.md +1 -1
- package/docs/features/elevate.md +122 -0
- package/docs/features/explain.md +16 -20
- package/docs/features/grill-me.md +65 -0
- package/docs/features/guided-review.md +150 -0
- package/docs/features/overthink.md +66 -0
- package/docs/features/remember-me.md +92 -0
- package/docs/features/show.md +9 -15
- package/docs/getting-started.md +5 -5
- package/docs/grill-me.md +5 -51
- package/docs/guided-review.md +14 -113
- package/docs/overthink.md +7 -46
- package/docs/piG-agent-shell-qualification.md +3 -3
- package/docs/pig-compatibility.md +1 -1
- package/docs/reference/commands.md +18 -33
- package/docs/reference/data-and-permissions.md +9 -9
- package/docs/reference/settings.md +8 -8
- package/docs/reference/troubleshooting.md +3 -3
- package/docs/remember-me.md +6 -75
- package/docs/user-guide.md +4 -4
- package/package.json +6 -4
- package/src/advisor.ts +1 -1
- package/src/architecture.ts +1 -1
- package/src/backend.ts +1 -0
- package/src/bro.ts +47 -189
- package/src/btw.ts +10 -199
- package/src/composer-modal.ts +197 -0
- package/src/explain-modal.ts +28 -79
- package/src/grill.ts +3 -2
- package/src/overthink-state.ts +3 -3
- package/src/overthink.ts +2 -2
- package/src/remember.ts +3 -2
- package/src/session-state.ts +46 -28
- package/src/settings.ts +11 -3
- package/src/simplify-engine.ts +50 -24
- package/src/simplify-ui.ts +165 -126
- package/src/sources.ts +3 -3
package/src/simplify-ui.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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?:
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
state
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
state.
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if(!
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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:
|
|
94
|
-
if(
|
|
95
|
-
const attempt=new AbortController();
|
|
96
|
-
controller=attempt;
|
|
97
|
-
modal.setRunning(true);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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("
|
|
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(
|
|
153
|
-
const action=parseSimplifyAction(raw);
|
|
154
|
-
if(action.kind==="invalid"){modal.setNotice(action.message,"warning");return;}
|
|
155
|
-
modal.clearComposer();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
void run(action,undefined,undefined,raw);
|
|
190
|
+
state.error = undefined;
|
|
191
|
+
display();
|
|
163
192
|
}
|
|
164
|
-
modal.onKey=
|
|
165
|
-
if(!
|
|
166
|
-
state.view="result";
|
|
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
|
|
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.");
|