pi-bro 0.38.1 → 0.40.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 +23 -0
- package/README.md +4 -9
- package/docs/README.md +1 -1
- package/docs/feature-map.md +3 -3
- package/docs/features/architecture.md +1 -1
- package/docs/features/btw.md +1 -3
- package/docs/features/elevate.md +1 -1
- package/docs/features/grill-me.md +1 -1
- package/docs/features/guided-review.md +5 -5
- package/docs/features/overthink.md +36 -34
- package/docs/features/remember-me.md +0 -2
- package/docs/overthink.md +2 -2
- package/docs/reference/commands.md +2 -2
- package/docs/reference/data-and-permissions.md +7 -18
- package/docs/reference/settings.md +7 -5
- package/docs/reference/troubleshooting.md +0 -4
- package/package.json +1 -5
- package/src/advisor.ts +1 -1
- package/src/architecture.ts +2 -2
- package/src/backend.ts +12 -31
- package/src/backends/agy.ts +4 -4
- package/src/backends/cli-process.ts +5 -11
- package/src/backends/contract.ts +4 -7
- package/src/bro.ts +1 -1
- package/src/btw.ts +1 -1
- package/src/config-navigation-ui.ts +0 -2
- package/src/config-navigation.ts +3 -6
- package/src/config-ui.ts +34 -19
- package/src/doctor.ts +68 -34
- package/src/explain-modal.ts +2 -2
- package/src/grill.ts +1 -1
- package/src/overthink-state.ts +566 -140
- package/src/overthink.ts +338 -162
- package/src/remember-engine.ts +0 -4
- package/src/settings.ts +98 -81
- package/src/backends/grok.ts +0 -204
- package/src/backends/muse.ts +0 -173
- package/src/overthink-questions-ui.ts +0 -131
package/src/backends/muse.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { withDoctor } from "../util.ts";
|
|
5
|
-
import { checkedBtwContinuation, cliExitFailure, finishCliAttempt, startCliAttempt, stoppedCliOutcome } from "./cli-process.ts";
|
|
6
|
-
import { btwToolName, type BackendOnProgress, type BackendOutcome, type BackendRequest } from "./contract.ts";
|
|
7
|
-
|
|
8
|
-
type MuseEnvelope = {
|
|
9
|
-
schema_version?: unknown;
|
|
10
|
-
payload_type?: unknown;
|
|
11
|
-
stream?: { kind?: unknown; id?: unknown };
|
|
12
|
-
payload?: {
|
|
13
|
-
kind?: unknown;
|
|
14
|
-
command_id?: unknown;
|
|
15
|
-
run_stream?: { kind?: unknown; id?: unknown };
|
|
16
|
-
text?: unknown;
|
|
17
|
-
reason?: unknown;
|
|
18
|
-
correlation_facts?: { tool_name?: unknown };
|
|
19
|
-
event?: { message?: unknown };
|
|
20
|
-
command?: unknown;
|
|
21
|
-
path?: unknown;
|
|
22
|
-
file_path?: unknown;
|
|
23
|
-
query?: unknown;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export async function executeMuse(
|
|
28
|
-
request: BackendRequest,
|
|
29
|
-
selection: { model: string; effort?: string },
|
|
30
|
-
signal: AbortSignal,
|
|
31
|
-
onProgress: BackendOnProgress | undefined,
|
|
32
|
-
killEscalationMs: number,
|
|
33
|
-
deadlineMs: number,
|
|
34
|
-
): Promise<BackendOutcome> {
|
|
35
|
-
const isAdvisor = request.feature === "advisor";
|
|
36
|
-
const isBtw = request.feature === "btw";
|
|
37
|
-
const inspect = request.feature === "review";
|
|
38
|
-
const full = request.access === "workspace-full";
|
|
39
|
-
const action = request.feature === "review" ? "complete the guided review request" : isAdvisor ? "complete the advisor consultation" : isBtw ? "answer the side question" : "simplify the response";
|
|
40
|
-
const timeoutVerb = request.feature === "review" ? "during the guided review request" : isAdvisor ? "during the advisor consultation" : isBtw ? "during the side conversation" : "while simplifying the response";
|
|
41
|
-
const emptyTextMessage = request.feature === "review" ? "Muse returned no response for Guided Review." : isAdvisor ? "Muse returned no advice." : isBtw ? "Muse returned no answer for the side question." : "Muse returned no final explanation.";
|
|
42
|
-
|
|
43
|
-
if (signal.aborted) return { status: "cancelled", message: "Canceled." };
|
|
44
|
-
const promptDirectory = await mkdtemp(join(tmpdir(), "pi-bro-muse-"));
|
|
45
|
-
let runDirectory: string | undefined;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
if (signal.aborted) return { status: "cancelled", message: "Canceled." };
|
|
49
|
-
const promptFile = join(promptDirectory, "prompt.txt");
|
|
50
|
-
await writeFile(promptFile, request.prompt, { encoding: "utf8", mode: 0o600 });
|
|
51
|
-
if (!full && !isBtw && !inspect) runDirectory = await mkdtemp(join(tmpdir(), "pi-bro-"));
|
|
52
|
-
if (signal.aborted) return { status: "cancelled", message: "Canceled." };
|
|
53
|
-
const workspace = runDirectory ?? request.cwd!;
|
|
54
|
-
|
|
55
|
-
const args = [
|
|
56
|
-
"exec",
|
|
57
|
-
"--json",
|
|
58
|
-
"--provider", "meta",
|
|
59
|
-
"--workspace", workspace,
|
|
60
|
-
...(!isBtw ? ["--no-session-log"] : []),
|
|
61
|
-
...(full ? ["--yolo"] : ["--disable-approval", "--disable-write", "--disable-shell"]),
|
|
62
|
-
...(inspect ? ["--disable-web-tools", "--no-foreign-personal-context"] : []),
|
|
63
|
-
...(isBtw && request.continuation ? ["--session-id", request.continuation.id] : []),
|
|
64
|
-
"--model", selection.model,
|
|
65
|
-
...(selection.effort ? ["--reasoning-effort", selection.effort] : []),
|
|
66
|
-
"--prompt-file", promptFile,
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const { child, attempt, diagnostics } = startCliAttempt("muse", args, {
|
|
70
|
-
cwd: workspace,
|
|
71
|
-
stdio: ["ignore", "pipe", "pipe"] }, signal, deadlineMs, killEscalationMs);
|
|
72
|
-
|
|
73
|
-
let partial = "";
|
|
74
|
-
let rootCommandId: string | undefined;
|
|
75
|
-
let rootRunId: string | undefined;
|
|
76
|
-
let sessionId: string | undefined;
|
|
77
|
-
let final: string | undefined;
|
|
78
|
-
let sawTerminal = false;
|
|
79
|
-
let terminalError: string | undefined;
|
|
80
|
-
|
|
81
|
-
const handleLine = (line: string) => {
|
|
82
|
-
if (!line.trim() || attempt.causeOf()) return;
|
|
83
|
-
let envelope: MuseEnvelope;
|
|
84
|
-
try {
|
|
85
|
-
envelope = JSON.parse(line) as MuseEnvelope;
|
|
86
|
-
} catch {
|
|
87
|
-
throw new Error("Muse emitted invalid JSON output.");
|
|
88
|
-
}
|
|
89
|
-
const payload = envelope.payload;
|
|
90
|
-
if (envelope.stream?.kind === "session" && typeof envelope.stream.id === "string") {
|
|
91
|
-
if (!sessionId) sessionId = envelope.stream.id;
|
|
92
|
-
}
|
|
93
|
-
if (envelope.payload_type === "runtime.command.accepted") {
|
|
94
|
-
if (!rootCommandId && typeof payload?.command_id === "string") {
|
|
95
|
-
rootCommandId = payload.command_id;
|
|
96
|
-
}
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (!rootRunId && (envelope.payload_type === "session.run.linked" || envelope.payload_type === "run.lifecycle.started")) {
|
|
100
|
-
const runStream = payload?.run_stream;
|
|
101
|
-
if (runStream?.kind === "run" && typeof runStream.id === "string") {
|
|
102
|
-
if (rootCommandId === undefined || payload?.command_id === rootCommandId) {
|
|
103
|
-
rootRunId = runStream.id;
|
|
104
|
-
if (envelope.stream?.kind === "session" && typeof envelope.stream.id === "string") {
|
|
105
|
-
sessionId = envelope.stream.id;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const runStream = payload?.run_stream;
|
|
112
|
-
const isRoot = rootRunId !== undefined && runStream?.kind === "run" && runStream.id === rootRunId;
|
|
113
|
-
|
|
114
|
-
if (isAdvisor || isBtw || (inspect && request.reportReviewTools)) {
|
|
115
|
-
if (envelope.payload_type === "tool.result") {
|
|
116
|
-
const facts = payload?.correlation_facts as { tool_name?: unknown } | undefined;
|
|
117
|
-
const toolName = typeof facts?.tool_name === "string" && facts.tool_name ? facts.tool_name : "tool";
|
|
118
|
-
const candidate = [payload?.text, payload?.command, payload?.path, payload?.file_path, payload?.query]
|
|
119
|
-
.find((v) => typeof v === "string" && v.trim());
|
|
120
|
-
const preview = typeof candidate === "string" ? candidate.replace(/\s+/g, " ").trim() : "";
|
|
121
|
-
const tool = btwToolName(toolName);
|
|
122
|
-
const label = (isBtw || (inspect && request.reportReviewTools)) ? tool : `${toolName}${preview ? ` ${preview}` : ""}`;
|
|
123
|
-
if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
|
|
124
|
-
} else if (isAdvisor && envelope.payload_type === "task.lifecycle.status") {
|
|
125
|
-
const event = payload?.event as { message?: unknown } | undefined;
|
|
126
|
-
if (typeof event?.message === "string" && event.message.trim()) {
|
|
127
|
-
onProgress?.({ kind: "activity", label: event.message.trim(), timestamp: Date.now() });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (!isAdvisor && isRoot && envelope.payload_type === "run.output.delta") {
|
|
132
|
-
if (typeof payload?.text === "string" && payload.text) {
|
|
133
|
-
partial += payload.text;
|
|
134
|
-
onProgress?.({ kind: "text", text: partial });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (!isRoot) return;
|
|
139
|
-
if (envelope.payload_type === "run.terminal.completed") {
|
|
140
|
-
sawTerminal = true;
|
|
141
|
-
if (typeof payload?.text === "string") {
|
|
142
|
-
final = payload.text;
|
|
143
|
-
}
|
|
144
|
-
} else if (envelope.payload_type === "run.terminal.failed") {
|
|
145
|
-
sawTerminal = true;
|
|
146
|
-
const reason = typeof payload?.reason === "string" && payload.reason.trim() ? payload.reason.trim() : "run did not complete";
|
|
147
|
-
terminalError ??= `Muse failed: ${reason}`;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const finished = await finishCliAttempt(child, attempt, "Muse", handleLine);
|
|
152
|
-
const code = finished.code!;
|
|
153
|
-
const stopped = stoppedCliOutcome("Muse", attempt, finished, diagnostics,
|
|
154
|
-
`Muse timed out ${timeoutVerb}. Run \`/bro doctor\` for setup help.`, partial);
|
|
155
|
-
if (stopped) return stopped;
|
|
156
|
-
const partialText = partial ? { partialText: partial } : {};
|
|
157
|
-
if (terminalError) return { status: "failure", message: withDoctor(terminalError), ...partialText };
|
|
158
|
-
if (code !== 0) return { status: "failure", message: cliExitFailure("Muse", action, diagnostics.stderr), ...partialText };
|
|
159
|
-
if (!sawTerminal) {
|
|
160
|
-
return { status: "failure", message: withDoctor(`Muse exited without a terminal result event${diagnostics.stderr.trim() ? `: ${diagnostics.stderr.trim()}` : "."}`), ...partialText };
|
|
161
|
-
}
|
|
162
|
-
const text = final?.trim();
|
|
163
|
-
if (!text) return { status: "failure", message: withDoctor(emptyTextMessage), ...partialText };
|
|
164
|
-
if (!isBtw) return { status: "success", text };
|
|
165
|
-
const continuation = checkedBtwContinuation("Muse", request.continuation, { id: sessionId });
|
|
166
|
-
if ("error" in continuation)
|
|
167
|
-
return { status: "failure", message: withDoctor(continuation.error), ...partialText };
|
|
168
|
-
return { status: "success", text, continuation };
|
|
169
|
-
} finally {
|
|
170
|
-
if (runDirectory) await rm(runDirectory, { recursive: true, force: true });
|
|
171
|
-
await rm(promptDirectory, { recursive: true, force: true });
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/** One question list editor for global defaults and session snapshots. */
|
|
2
|
-
import { Input, matchesKey, truncateToWidth, type Component, type TUI } from "@earendil-works/pi-tui";
|
|
3
|
-
import { modalHeight, openBroOverlay, renderFrame, Scroller, formatNotice, type Theme } from "./modal-kit.ts";
|
|
4
|
-
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { checkQuestions, MAX_OVERTHINK_QUESTIONS, MAX_OVERTHINK_QUESTION_CHARS } from "./overthink-state.ts";
|
|
6
|
-
import { errorMessage } from "./util.ts";
|
|
7
|
-
|
|
8
|
-
type EditorOptions = {
|
|
9
|
-
title: string; questions: string[]; reset: () => Promise<string[]>;
|
|
10
|
-
save: (questions: string[]) => Promise<void> | void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function createOverthinkQuestionEditor(options: EditorOptions) {
|
|
14
|
-
return (tui: TUI, theme: Theme, _keys: unknown, done: (value?: void) => void): Component => {
|
|
15
|
-
let questions = [...options.questions];
|
|
16
|
-
let saved = JSON.stringify(questions);
|
|
17
|
-
let cursor = 0;
|
|
18
|
-
let mode: "list" | "edit" = "list";
|
|
19
|
-
let input = new Input();
|
|
20
|
-
let editingIndex = -1;
|
|
21
|
-
let pending = false;
|
|
22
|
-
let closed = false;
|
|
23
|
-
let resetArmed = false;
|
|
24
|
-
let discardArmed = false;
|
|
25
|
-
let notice = "";
|
|
26
|
-
const scroller = new Scroller(() => tui.requestRender());
|
|
27
|
-
const dirty = () => JSON.stringify(questions) !== saved;
|
|
28
|
-
const warn = (message: string, tone: "info" | "success" | "error" | "warning" = "info") => {
|
|
29
|
-
notice = formatNotice(theme, message, tone); tui.requestRender();
|
|
30
|
-
};
|
|
31
|
-
const beginEdit = (index: number) => {
|
|
32
|
-
mode = "edit"; editingIndex = index;
|
|
33
|
-
input = new Input();
|
|
34
|
-
input.setValue(questions[index] ?? "");
|
|
35
|
-
input.onSubmit = (value: string) => {
|
|
36
|
-
const trimmed = value.trim();
|
|
37
|
-
if (!trimmed || trimmed.length > MAX_OVERTHINK_QUESTION_CHARS || /[\r\n]/.test(trimmed)) {
|
|
38
|
-
warn("Enter one nonempty question (max " + MAX_OVERTHINK_QUESTION_CHARS + " characters).", "warning"); return;
|
|
39
|
-
}
|
|
40
|
-
if (editingIndex === questions.length) questions.push(trimmed);
|
|
41
|
-
else questions[editingIndex] = trimmed;
|
|
42
|
-
mode = "list"; cursor = editingIndex; resetArmed = false;
|
|
43
|
-
discardArmed = false; notice = ""; tui.requestRender();
|
|
44
|
-
};
|
|
45
|
-
tui.requestRender();
|
|
46
|
-
};
|
|
47
|
-
const save = async () => {
|
|
48
|
-
if (pending) return;
|
|
49
|
-
let clean: string[];
|
|
50
|
-
try { clean = checkQuestions(questions); }
|
|
51
|
-
catch (error) { warn(errorMessage(error), "error"); return; }
|
|
52
|
-
pending = true; tui.requestRender();
|
|
53
|
-
try { await options.save(clean); saved = JSON.stringify(clean); questions = clean; warn("Questions saved.", "success"); }
|
|
54
|
-
catch (error) { warn("Save failed: " + errorMessage(error), "error"); }
|
|
55
|
-
finally { pending = false; tui.requestRender(); }
|
|
56
|
-
};
|
|
57
|
-
const reset = async () => {
|
|
58
|
-
pending = true; tui.requestRender();
|
|
59
|
-
try {
|
|
60
|
-
questions = checkQuestions(await options.reset());
|
|
61
|
-
cursor = 0; scroller.toStart(); resetArmed = false; discardArmed = false;
|
|
62
|
-
warn("Reset in editor. Ctrl+S to save.", "warning");
|
|
63
|
-
} catch (error) { warn("Reset failed: " + errorMessage(error), "error"); }
|
|
64
|
-
finally { pending = false; tui.requestRender(); }
|
|
65
|
-
};
|
|
66
|
-
return {
|
|
67
|
-
render(width: number) {
|
|
68
|
-
const height = modalHeight(tui);
|
|
69
|
-
const list = questions.length ? questions.map((question, index) =>
|
|
70
|
-
(index === cursor ? theme.fg("accent", "> ") : " ") +
|
|
71
|
-
theme.fg(index === cursor ? "accent" : "text", truncateToWidth(String(index + 1) + ". " + question, Math.max(8, width - 6), "…"))
|
|
72
|
-
) : [theme.fg("muted", "No questions. Add one, or save an empty list to disable checks.")];
|
|
73
|
-
return renderFrame(theme, width, height, {
|
|
74
|
-
header: () => theme.fg("accent", theme.bold(options.title)) + (dirty() ? " *" : ""),
|
|
75
|
-
body: (rows, inner) => mode === "edit"
|
|
76
|
-
? ["Edit question:", ...input.render(inner)].slice(0, rows)
|
|
77
|
-
: scroller.view(list, rows),
|
|
78
|
-
notice,
|
|
79
|
-
hints: mode === "edit" ? "Enter apply · Esc cancel edit" :
|
|
80
|
-
"↑/↓ select · Enter edit · Ctrl+N add · Ctrl+X delete · Ctrl+↑/↓ move · Ctrl+D reset · Ctrl+S save · Esc close",
|
|
81
|
-
fill: true,
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
invalidate() {},
|
|
85
|
-
handleInput(data: string) {
|
|
86
|
-
if (pending || closed) return;
|
|
87
|
-
if (mode === "edit") {
|
|
88
|
-
if (matchesKey(data, "escape")) { mode = "list"; notice = ""; tui.requestRender(); return; }
|
|
89
|
-
input.handleInput(data); tui.requestRender(); return;
|
|
90
|
-
}
|
|
91
|
-
if (matchesKey(data, "escape")) {
|
|
92
|
-
if (resetArmed) { resetArmed = false; warn("Reset cancelled."); return; }
|
|
93
|
-
if (dirty() && !discardArmed) { discardArmed = true; warn("Unsaved questions. Esc again to discard, Ctrl+S to save.", "warning"); return; }
|
|
94
|
-
closed = true; done(); return;
|
|
95
|
-
}
|
|
96
|
-
discardArmed = false;
|
|
97
|
-
if (matchesKey(data, "ctrl+s")) { void save(); return; }
|
|
98
|
-
if (matchesKey(data, "ctrl+n")) {
|
|
99
|
-
if (questions.length >= MAX_OVERTHINK_QUESTIONS) { warn("Maximum " + MAX_OVERTHINK_QUESTIONS + " questions.", "warning"); return; }
|
|
100
|
-
beginEdit(questions.length); return;
|
|
101
|
-
}
|
|
102
|
-
if (matchesKey(data, "ctrl+d")) {
|
|
103
|
-
if (!resetArmed) { resetArmed = true; warn("Ctrl+D again to reset this list, then Ctrl+S to save.", "warning"); return; }
|
|
104
|
-
void reset(); return;
|
|
105
|
-
}
|
|
106
|
-
resetArmed = false;
|
|
107
|
-
if (matchesKey(data, "ctrl+x") && questions.length) {
|
|
108
|
-
questions.splice(cursor, 1); cursor = Math.min(cursor, Math.max(0, questions.length - 1));
|
|
109
|
-
warn("Question removed from draft. Ctrl+S to save."); return;
|
|
110
|
-
}
|
|
111
|
-
if (matchesKey(data, "ctrl+up") && cursor > 0) {
|
|
112
|
-
[questions[cursor - 1], questions[cursor]] = [questions[cursor]!, questions[cursor - 1]!];
|
|
113
|
-
cursor--; tui.requestRender(); return;
|
|
114
|
-
}
|
|
115
|
-
if (matchesKey(data, "ctrl+down") && cursor < questions.length - 1) {
|
|
116
|
-
[questions[cursor + 1], questions[cursor]] = [questions[cursor]!, questions[cursor + 1]!];
|
|
117
|
-
cursor++; tui.requestRender(); return;
|
|
118
|
-
}
|
|
119
|
-
if (matchesKey(data, "up")) { cursor = Math.max(0, cursor - 1); scroller.by(-1); tui.requestRender(); return; }
|
|
120
|
-
if (matchesKey(data, "down")) { cursor = Math.min(questions.length - 1, cursor + 1); scroller.by(1); tui.requestRender(); return; }
|
|
121
|
-
if (matchesKey(data, "return") || matchesKey(data, "enter")) {
|
|
122
|
-
if (questions.length) beginEdit(cursor);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function openOverthinkQuestionEditor(ctx: ExtensionCommandContext, options: EditorOptions): Promise<void> {
|
|
130
|
-
await openBroOverlay<void>(ctx, createOverthinkQuestionEditor(options));
|
|
131
|
-
}
|