@juicesharp/rpiv-btw 1.14.7 → 1.16.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/btw-ui.ts +15 -15
- package/btw.ts +18 -22
- package/package.json +1 -1
package/btw-ui.ts
CHANGED
|
@@ -37,15 +37,15 @@ import {
|
|
|
37
37
|
} from "@earendil-works/pi-tui";
|
|
38
38
|
import { type BtwTurn, userMessageText } from "./btw.js";
|
|
39
39
|
|
|
40
|
+
const BTW_MAX_HEIGHT_RATIO = 0.85;
|
|
41
|
+
|
|
40
42
|
const BTW_OVERLAY_OPTIONS: OverlayOptions = {
|
|
41
43
|
anchor: "bottom-center",
|
|
42
44
|
width: "100%",
|
|
43
|
-
maxHeight:
|
|
45
|
+
maxHeight: `${BTW_MAX_HEIGHT_RATIO * 100}%`,
|
|
44
46
|
margin: { left: 0, right: 0, bottom: 0 },
|
|
45
47
|
};
|
|
46
48
|
|
|
47
|
-
const BTW_MAX_HEIGHT_RATIO = 0.85;
|
|
48
|
-
|
|
49
49
|
const SIDE_PAD = " "; // 2-col left gutter for history, echo, footer
|
|
50
50
|
const ANSWER_PAD = " "; // 4-col left gutter for answer body (double of SIDE_PAD)
|
|
51
51
|
const BTW_LITERAL = "/btw";
|
|
@@ -187,6 +187,16 @@ export class BtwOverlayController implements Component {
|
|
|
187
187
|
return `${SIDE_PAD + this.theme.fg("accent", BTW_LITERAL)} ${this.theme.fg("muted", qTrunc)}`;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
private wrapBodyLines(text: string, bodyWidth: number, colorFn?: (s: string) => string): string[] {
|
|
191
|
+
const out: string[] = [];
|
|
192
|
+
for (const ln of text.split("\n")) {
|
|
193
|
+
const src = ln.length === 0 ? " " : ln;
|
|
194
|
+
const colored = colorFn ? colorFn(src) : src;
|
|
195
|
+
out.push(...wrapTextWithAnsi(colored, bodyWidth));
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
190
200
|
private renderAnswer(width: number): string[] {
|
|
191
201
|
const bodyWidth = Math.max(1, width - ANSWER_PAD.length);
|
|
192
202
|
const indent = (lines: string[]) => lines.map((l) => ANSWER_PAD + l);
|
|
@@ -195,19 +205,9 @@ export class BtwOverlayController implements Component {
|
|
|
195
205
|
return indent([this.theme.fg("warning", PENDING_GLYPH)]);
|
|
196
206
|
}
|
|
197
207
|
if (this.mode === "error") {
|
|
198
|
-
|
|
199
|
-
for (const ln of this.error.split("\n")) {
|
|
200
|
-
const src = ln.length === 0 ? " " : ln;
|
|
201
|
-
out.push(...wrapTextWithAnsi(this.theme.fg("error", src), bodyWidth));
|
|
202
|
-
}
|
|
203
|
-
return indent(out);
|
|
204
|
-
}
|
|
205
|
-
const out: string[] = [];
|
|
206
|
-
for (const ln of this.answer.split("\n")) {
|
|
207
|
-
const src = ln.length === 0 ? " " : ln;
|
|
208
|
-
out.push(...wrapTextWithAnsi(src, bodyWidth));
|
|
208
|
+
return indent(this.wrapBodyLines(this.error, bodyWidth, (s) => this.theme.fg("error", s)));
|
|
209
209
|
}
|
|
210
|
-
return indent(
|
|
210
|
+
return indent(this.wrapBodyLines(this.answer, bodyWidth));
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
package/btw.ts
CHANGED
|
@@ -65,11 +65,18 @@ export interface BtwTurn {
|
|
|
65
65
|
assistantMessage: AssistantMessage;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
interface BtwState {
|
|
69
69
|
histories: Map<string, BtwTurn[]>;
|
|
70
70
|
snapshots: Map<string, { messages: Message[] }>;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function branchToMessages(branch: SessionEntry[]): Message[] {
|
|
74
|
+
const agentMessages = branch
|
|
75
|
+
.filter((e): e is SessionEntry & { type: "message" } => e.type === "message")
|
|
76
|
+
.map((e) => e.message);
|
|
77
|
+
return convertToLlm(agentMessages);
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
// ---------------------------------------------------------------------------
|
|
74
81
|
// System prompt — loaded once at module init from prompts/btw-system.txt
|
|
75
82
|
// ---------------------------------------------------------------------------
|
|
@@ -169,25 +176,17 @@ function getCrossSessionHint(): string {
|
|
|
169
176
|
// Modeled after rpiv-advisor/advisor.ts:225-336
|
|
170
177
|
// ---------------------------------------------------------------------------
|
|
171
178
|
|
|
172
|
-
export
|
|
173
|
-
ok:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
assistantMessage?: AssistantMessage;
|
|
177
|
-
error?: string;
|
|
178
|
-
stopReason?: StopReason;
|
|
179
|
-
aborted?: boolean;
|
|
180
|
-
}
|
|
179
|
+
export type BtwExecResult =
|
|
180
|
+
| { ok: true; answer: string; userMessage: UserMessage; assistantMessage: AssistantMessage; stopReason: StopReason }
|
|
181
|
+
| { ok: false; error: string; stopReason?: StopReason }
|
|
182
|
+
| { ok: false; aborted: true; stopReason: StopReason };
|
|
181
183
|
|
|
182
184
|
function readBranchMessages(ctx: ExtensionContext): Message[] {
|
|
183
185
|
const cached = getSnapshot(ctx);
|
|
184
186
|
if (cached) return cached.messages;
|
|
185
187
|
// Cold start (no message_end fired yet) — fall back to live read
|
|
186
188
|
const branch = ctx.sessionManager.getBranch() as SessionEntry[];
|
|
187
|
-
|
|
188
|
-
.filter((e): e is SessionEntry & { type: "message" } => e.type === "message")
|
|
189
|
-
.map((e) => e.message);
|
|
190
|
-
return convertToLlm(agentMessages);
|
|
189
|
+
return branchToMessages(branch);
|
|
191
190
|
}
|
|
192
191
|
|
|
193
192
|
function buildBtwMessages(ctx: ExtensionContext, userMessage: UserMessage): Message[] {
|
|
@@ -267,7 +266,7 @@ export async function executeBtw(
|
|
|
267
266
|
} catch (err) {
|
|
268
267
|
const message = err instanceof Error ? err.message : String(err);
|
|
269
268
|
if (controller.signal.aborted) {
|
|
270
|
-
return { ok: false, aborted: true };
|
|
269
|
+
return { ok: false, aborted: true, stopReason: "aborted" as const };
|
|
271
270
|
}
|
|
272
271
|
return { ok: false, error: errCallThrew(message) };
|
|
273
272
|
}
|
|
@@ -283,10 +282,7 @@ export function registerMessageEndSnapshot(pi: ExtensionAPI): void {
|
|
|
283
282
|
if (msg.role !== "assistant") return;
|
|
284
283
|
if ((msg as AssistantMessage).stopReason === "toolUse") return;
|
|
285
284
|
const branch = ctx.sessionManager.getBranch() as SessionEntry[];
|
|
286
|
-
|
|
287
|
-
.filter((e): e is SessionEntry & { type: "message" } => e.type === "message")
|
|
288
|
-
.map((e) => e.message);
|
|
289
|
-
setSnapshot(ctx, { messages: convertToLlm(agentMessages) });
|
|
285
|
+
setSnapshot(ctx, { messages: branchToMessages(branch) });
|
|
290
286
|
});
|
|
291
287
|
}
|
|
292
288
|
|
|
@@ -331,16 +327,16 @@ async function handleBtwCommand(_pi: ExtensionAPI, args: string, ctx: ExtensionC
|
|
|
331
327
|
const overlayCtl = await controllerReady;
|
|
332
328
|
const result = await executeBtw(question, ctx, controller);
|
|
333
329
|
|
|
334
|
-
if (result.ok
|
|
330
|
+
if (result.ok) {
|
|
335
331
|
overlayCtl.setAnswer(result.answer);
|
|
336
332
|
pushSessionTurn(ctx, {
|
|
337
333
|
userMessage: result.userMessage,
|
|
338
334
|
assistantMessage: result.assistantMessage,
|
|
339
335
|
});
|
|
340
336
|
// No disk persistence — process-scoped only (Decision 4)
|
|
341
|
-
} else if (result
|
|
337
|
+
} else if ("aborted" in result) {
|
|
342
338
|
// User Esc'd — overlay already dismissed via done(); no further action
|
|
343
|
-
} else
|
|
339
|
+
} else {
|
|
344
340
|
overlayCtl.setError(result.error);
|
|
345
341
|
}
|
|
346
342
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-btw",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Pi extension. The /btw slash command, for putting a one-off side question to the same primary model without polluting the main conversation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|