pi-render-btw 0.6.8 → 0.6.10
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/README.md +1 -0
- package/extensions/btw-transcript.test.ts +37 -1
- package/extensions/btw.ts +46 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,6 +94,7 @@ pi install /path/to/pi-render-btw
|
|
|
94
94
|
- `Alt+/` toggles focus between BTW and the main editor without closing the overlay
|
|
95
95
|
- `Ctrl+Alt+W` is a fallback focus toggle for terminals that do not deliver `Alt+/` as a usable shortcut
|
|
96
96
|
- `Ctrl+G` opens the current BTW draft in `$VISUAL`/`$EDITOR` (falling back to `nano`) and reads it back when the editor exits successfully
|
|
97
|
+
- the composer uses Pi's native editor behavior for undo, paste, prompt history, and Tab file-path completion (including `@` prefixes) relative to the BTW working directory
|
|
97
98
|
- `Esc` still dismisses BTW immediately while the overlay is focused
|
|
98
99
|
- BTW opens top-centered so the main session remains visible underneath it
|
|
99
100
|
|
|
@@ -10,8 +10,10 @@ const theme = {
|
|
|
10
10
|
|
|
11
11
|
const keybindings = { matches: () => false } as any;
|
|
12
12
|
const tui = {
|
|
13
|
-
terminal: { write: () => {} },
|
|
13
|
+
terminal: { write: () => {}, rows: 30 },
|
|
14
14
|
requestRender: () => {},
|
|
15
|
+
start: () => {},
|
|
16
|
+
stop: () => {},
|
|
15
17
|
} as any;
|
|
16
18
|
|
|
17
19
|
function transcriptLines(entries: unknown[]): string[] {
|
|
@@ -120,6 +122,24 @@ describe("BTW transcript message layout", () => {
|
|
|
120
122
|
expect(component.render(80).join("\n")).toContain("q:exit");
|
|
121
123
|
});
|
|
122
124
|
|
|
125
|
+
it("setDraft/getDraft round-trips through editor getText/setText", () => {
|
|
126
|
+
const component = new BtwOverlayComponent(
|
|
127
|
+
tui,
|
|
128
|
+
theme,
|
|
129
|
+
keybindings,
|
|
130
|
+
() => [],
|
|
131
|
+
() => null,
|
|
132
|
+
() => "contextual",
|
|
133
|
+
() => {},
|
|
134
|
+
() => {},
|
|
135
|
+
() => {},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const testValue = "hello from the editor";
|
|
139
|
+
component.setDraft(testValue);
|
|
140
|
+
expect(component.getDraft()).toBe(testValue);
|
|
141
|
+
});
|
|
142
|
+
|
|
123
143
|
it("routes Ctrl+G to the external-editor callback", () => {
|
|
124
144
|
let opened = 0;
|
|
125
145
|
const externalKeybindings = {
|
|
@@ -145,4 +165,20 @@ describe("BTW transcript message layout", () => {
|
|
|
145
165
|
expect(opened).toBe(1);
|
|
146
166
|
expect(component.getDraft()).toBe("draft prompt");
|
|
147
167
|
});
|
|
168
|
+
|
|
169
|
+
it("configures fd-backed completion for @ path suggestions", () => {
|
|
170
|
+
const component = new BtwOverlayComponent(
|
|
171
|
+
tui,
|
|
172
|
+
theme,
|
|
173
|
+
keybindings,
|
|
174
|
+
() => [],
|
|
175
|
+
() => null,
|
|
176
|
+
() => "contextual",
|
|
177
|
+
() => {},
|
|
178
|
+
() => {},
|
|
179
|
+
() => {},
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect((component as any).input.autocompleteProvider.fdPath).toBeTruthy();
|
|
183
|
+
});
|
|
148
184
|
});
|
package/extensions/btw.ts
CHANGED
|
@@ -32,7 +32,8 @@ import {
|
|
|
32
32
|
type OverlayHandle,
|
|
33
33
|
type TUI,
|
|
34
34
|
} from "@earendil-works/pi-tui";
|
|
35
|
-
import {
|
|
35
|
+
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
36
|
+
import { CombinedAutocompleteProvider, type EditorTheme } from "@earendil-works/pi-tui";
|
|
36
37
|
import {
|
|
37
38
|
buildPeekBlocks,
|
|
38
39
|
createPeekState,
|
|
@@ -56,6 +57,18 @@ function matchesBtwFocusShortcut(data: string): boolean {
|
|
|
56
57
|
return BTW_FOCUS_SHORTCUTS.some((shortcut) => matchesKey(data, shortcut));
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
function findFdPath(): string | null {
|
|
61
|
+
const lookup = process.platform === "win32" ? "where" : "which";
|
|
62
|
+
for (const candidate of process.platform === "win32" ? ["fd.exe", "fd"] : ["fd", "fdfind"]) {
|
|
63
|
+
const result = spawnSync(lookup, [candidate], { encoding: "utf8" });
|
|
64
|
+
if (result.status === 0) {
|
|
65
|
+
const resolved = String(result.stdout ?? "").split(/\r?\n/).find(Boolean)?.trim();
|
|
66
|
+
if (resolved) return resolved;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
59
72
|
const BTW_SYSTEM_PROMPT = [
|
|
60
73
|
"You are having an aside conversation with the user, separate from their main working session.",
|
|
61
74
|
"If main session messages are provided, they are for context only — that work is being handled by another agent.",
|
|
@@ -1038,7 +1051,7 @@ function buildTranscriptBadge(
|
|
|
1038
1051
|
}
|
|
1039
1052
|
|
|
1040
1053
|
export class BtwOverlayComponent extends Container implements Focusable {
|
|
1041
|
-
private readonly input:
|
|
1054
|
+
private readonly input: CustomEditor;
|
|
1042
1055
|
private readonly transcript: Container;
|
|
1043
1056
|
private readonly statusText: Text;
|
|
1044
1057
|
private readonly modeText: Text;
|
|
@@ -1092,6 +1105,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1092
1105
|
onDismiss: () => void,
|
|
1093
1106
|
onUnfocus: () => void,
|
|
1094
1107
|
onExternalEditor?: () => void,
|
|
1108
|
+
cwd?: string,
|
|
1095
1109
|
) {
|
|
1096
1110
|
super();
|
|
1097
1111
|
this.tui = tui;
|
|
@@ -1109,8 +1123,22 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1109
1123
|
this.transcript = new Container();
|
|
1110
1124
|
this.statusText = new Text("", 1, 0);
|
|
1111
1125
|
|
|
1112
|
-
|
|
1126
|
+
const editorTheme: EditorTheme = {
|
|
1127
|
+
borderColor: (text: string) => theme.fg("borderMuted", text),
|
|
1128
|
+
selectList: {
|
|
1129
|
+
selectedPrefix: (text: string) => theme.fg("accent", text),
|
|
1130
|
+
selectedText: (text: string) => theme.fg("accent", text),
|
|
1131
|
+
description: (text: string) => theme.fg("muted", text),
|
|
1132
|
+
scrollInfo: (text: string) => theme.fg("muted", text),
|
|
1133
|
+
noMatch: (text: string) => theme.fg("muted", text),
|
|
1134
|
+
},
|
|
1135
|
+
};
|
|
1136
|
+
// Pi may expose KeybindingsManager from a different installed package copy;
|
|
1137
|
+
// both variants provide the runtime `matches()` interface CustomEditor uses.
|
|
1138
|
+
const editorKeybindings = keybindings as unknown as ConstructorParameters<typeof CustomEditor>[2];
|
|
1139
|
+
this.input = new CustomEditor(tui, editorTheme, editorKeybindings);
|
|
1113
1140
|
this.input.onSubmit = (value) => {
|
|
1141
|
+
this.input.addToHistory(value);
|
|
1114
1142
|
this.followTranscript = true;
|
|
1115
1143
|
this.onSubmitCallback(value);
|
|
1116
1144
|
};
|
|
@@ -1118,6 +1146,11 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1118
1146
|
this.onDismissCallback();
|
|
1119
1147
|
};
|
|
1120
1148
|
|
|
1149
|
+
// Wire up autocomplete (file-path completion only, no commands)
|
|
1150
|
+
const cwdPath = cwd ?? process.cwd();
|
|
1151
|
+
const autocompleteProvider = new CombinedAutocompleteProvider([], cwdPath, findFdPath());
|
|
1152
|
+
this.input.setAutocompleteProvider(autocompleteProvider);
|
|
1153
|
+
|
|
1121
1154
|
this.peekState = createPeekState();
|
|
1122
1155
|
this.hintsText = new Text("", 1, 0);
|
|
1123
1156
|
this.mdTheme = getMarkdownTheme();
|
|
@@ -1137,19 +1170,16 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1137
1170
|
}
|
|
1138
1171
|
|
|
1139
1172
|
// app.clear with non-empty input → clear input
|
|
1140
|
-
if (keybindings.matches(data, "app.clear") && this.input.
|
|
1141
|
-
this.input.
|
|
1173
|
+
if (keybindings.matches(data, "app.clear") && this.input.getText().length > 0) {
|
|
1174
|
+
this.input.setText("");
|
|
1142
1175
|
this.tui.requestRender();
|
|
1143
1176
|
return;
|
|
1144
1177
|
}
|
|
1145
1178
|
|
|
1146
1179
|
// Everything else (including Escape → dismiss, Enter → submit,
|
|
1147
|
-
// Ctrl+Enter → newline) goes to
|
|
1180
|
+
// Ctrl+Enter → newline) goes to CustomEditor's own handler
|
|
1181
|
+
// (CustomEditor delegates app keybindings, then Editor).
|
|
1148
1182
|
originalHandleInput(data);
|
|
1149
|
-
|
|
1150
|
-
// After TextArea processed the key, check if Escape was pressed
|
|
1151
|
-
// (TextArea calls onEscape which calls onDismissCallback).
|
|
1152
|
-
// tui.select.cancel is handled by TextArea internally.
|
|
1153
1183
|
};
|
|
1154
1184
|
|
|
1155
1185
|
this.refresh();
|
|
@@ -1165,7 +1195,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1165
1195
|
const filePath = path.join(dir, "prompt.md");
|
|
1166
1196
|
|
|
1167
1197
|
try {
|
|
1168
|
-
writeFileSync(filePath, this.input.
|
|
1198
|
+
writeFileSync(filePath, this.input.getText(), "utf8");
|
|
1169
1199
|
this.tui.stop();
|
|
1170
1200
|
process.stdout.write(`Launching external editor: ${editorCommand}\nPi will resume when the editor exits.\n`);
|
|
1171
1201
|
|
|
@@ -1179,7 +1209,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1179
1209
|
});
|
|
1180
1210
|
|
|
1181
1211
|
if (status === 0) {
|
|
1182
|
-
this.input.
|
|
1212
|
+
this.input.setText(readFileSync(filePath, "utf8").replace(/\n$/, ""));
|
|
1183
1213
|
}
|
|
1184
1214
|
} finally {
|
|
1185
1215
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -1467,12 +1497,12 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1467
1497
|
}
|
|
1468
1498
|
|
|
1469
1499
|
setDraft(value: string): void {
|
|
1470
|
-
this.input.
|
|
1500
|
+
this.input.setText(value);
|
|
1471
1501
|
this.tui.requestRender();
|
|
1472
1502
|
}
|
|
1473
1503
|
|
|
1474
1504
|
getDraft(): string {
|
|
1475
|
-
return this.input.
|
|
1505
|
+
return this.input.getText();
|
|
1476
1506
|
}
|
|
1477
1507
|
|
|
1478
1508
|
getTranscriptEntries(): BtwTranscript {
|
|
@@ -2368,6 +2398,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
2368
2398
|
overlayRuntime?.handle?.unfocus();
|
|
2369
2399
|
overlayRuntime?.refresh?.();
|
|
2370
2400
|
},
|
|
2401
|
+
undefined,
|
|
2402
|
+
ctx.cwd,
|
|
2371
2403
|
);
|
|
2372
2404
|
|
|
2373
2405
|
overlay.focused = runtime.handle?.isFocused() ?? true;
|
package/package.json
CHANGED