@linxiraos/pi-tui 1.4.7 → 1.4.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/CHANGELOG.md +154 -231
- package/README.md +7 -1
- package/dist/types/app-keybindings.d.ts +5 -0
- package/dist/types/charts/table-data.d.ts +4 -2
- package/dist/types/chat/bash-execution.d.ts +4 -1
- package/dist/types/chat/eval-execution.d.ts +2 -0
- package/dist/types/chat/execution-shared.d.ts +14 -8
- package/dist/types/chat/figure-markdown.d.ts +2 -0
- package/dist/types/chat/svg-figure.d.ts +5 -0
- package/dist/types/chat/table-chart.d.ts +2 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
- package/dist/types/chrome/dynamic-border.d.ts +6 -0
- package/dist/types/chrome/transcript-status.d.ts +2 -2
- package/dist/types/components/editor.d.ts +15 -6
- package/dist/types/components/image.d.ts +6 -0
- package/dist/types/components/loader.d.ts +2 -0
- package/dist/types/keybinding-matchers.d.ts +7 -0
- package/dist/types/native/describe.d.ts +4 -2
- package/dist/types/native/node.d.ts +2 -3
- package/dist/types/native/overlay.d.ts +42 -2
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/btw-history-panel.d.ts +15 -0
- package/dist/types/overlays/btw-history.d.ts +24 -0
- package/dist/types/overlays/btw-inject.d.ts +22 -0
- package/dist/types/overlays/btw-panel.d.ts +7 -0
- package/dist/types/overlays/hook-editor.d.ts +2 -0
- package/dist/types/overlays/jobs-panel.d.ts +4 -0
- package/dist/types/overlays/model-browser.d.ts +1 -1
- package/dist/types/overlays/session-selector.d.ts +11 -2
- package/dist/types/prompt/composer.d.ts +13 -5
- package/dist/types/render/render-utils.d.ts +23 -1
- package/dist/types/setup/scenes/language.d.ts +3 -0
- package/dist/types/setup/scenes/types.d.ts +5 -0
- package/dist/types/setup/setup-version.d.ts +1 -1
- package/dist/types/setup/wizard.d.ts +1 -1
- package/dist/types/status-line/startup.d.ts +0 -15
- package/dist/types/terminal-capabilities.d.ts +1 -1
- package/dist/types/theme/symbols.d.ts +3 -1
- package/dist/types/theme/theme-class.d.ts +1 -0
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +2 -0
- package/dist/types/thinking.d.ts +8 -6
- package/dist/types/tools/ast-grep.d.ts +2 -0
- package/dist/types/tools/eval.d.ts +2 -0
- package/dist/types/tools/find.d.ts +1 -1
- package/dist/types/tools/grouped-file-output.d.ts +100 -19
- package/dist/types/tools/hashline-format.d.ts +5 -0
- package/dist/types/tools/native-view.d.ts +2 -0
- package/dist/types/tools/output-meta.d.ts +27 -0
- package/dist/types/tools/read.d.ts +14 -4
- package/dist/types/tools/task.d.ts +4 -3
- package/dist/types/tools/wait.d.ts +2 -0
- package/dist/types/tui.d.ts +12 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +9 -9
- package/src/app-keybindings.d.ts +5 -0
- package/src/app-keybindings.ts +5 -0
- package/src/apps/git/git-tui.ts +10 -17
- package/src/apps/git/sidebar.ts +21 -35
- package/src/apps/ps-top.ts +4 -12
- package/src/charts/chart-plan.ts +0 -29
- package/src/charts/table-data.d.ts +4 -2
- package/src/charts/table-data.ts +55 -6
- package/src/chat/bash-execution.d.ts +4 -1
- package/src/chat/bash-execution.ts +20 -9
- package/src/chat/chat-transcript-builder.ts +5 -2
- package/src/chat/eval-execution.d.ts +2 -0
- package/src/chat/eval-execution.ts +14 -7
- package/src/chat/execution-shared.d.ts +14 -8
- package/src/chat/execution-shared.ts +39 -18
- package/src/chat/figure-markdown.d.ts +2 -0
- package/src/chat/figure-markdown.ts +6 -4
- package/src/chat/read-tool-group.ts +56 -36
- package/src/chat/svg-figure.d.ts +5 -0
- package/src/chat/svg-figure.ts +55 -16
- package/src/chat/table-chart.d.ts +2 -0
- package/src/chat/table-chart.ts +19 -2
- package/src/chat/transcript-render-helpers.d.ts +11 -3
- package/src/chat/transcript-render-helpers.ts +70 -22
- package/src/chrome/dynamic-border.d.ts +6 -0
- package/src/chrome/dynamic-border.ts +28 -2
- package/src/chrome/transcript-status.d.ts +2 -2
- package/src/chrome/transcript-status.ts +5 -3
- package/src/components/editor.d.ts +15 -6
- package/src/components/editor.ts +123 -24
- package/src/components/image.d.ts +6 -0
- package/src/components/image.ts +13 -0
- package/src/components/key-value-list.ts +9 -9
- package/src/components/loader.d.ts +2 -0
- package/src/components/loader.ts +7 -0
- package/src/components/section.ts +1 -9
- package/src/components/table.ts +1 -9
- package/src/keybinding-matchers.d.ts +7 -0
- package/src/keybinding-matchers.ts +13 -0
- package/src/native/backend.ts +7 -3
- package/src/native/describe.d.ts +4 -2
- package/src/native/describe.ts +9 -4
- package/src/native/node.d.ts +2 -3
- package/src/native/node.ts +2 -3
- package/src/native/overlay.d.ts +42 -2
- package/src/native/overlay.ts +124 -16
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +25 -5
- package/src/overlays/btw-history-panel.ts +106 -14
- package/src/overlays/btw-history.ts +65 -0
- package/src/overlays/btw-inject.ts +91 -0
- package/src/overlays/btw-panel.ts +53 -12
- package/src/overlays/extensions/extension-dashboard.ts +7 -8
- package/src/overlays/hook-editor.ts +6 -0
- package/src/overlays/jobs-panel.ts +82 -22
- package/src/overlays/login-dialog.ts +8 -26
- package/src/overlays/model-browser.ts +69 -10
- package/src/overlays/session-selector.ts +25 -5
- package/src/overlays/settings-defs.ts +2 -2
- package/src/overlays/settings-selector.ts +113 -11
- package/src/overlays/tree-selector.ts +83 -27
- package/src/overlays/usage-dashboard.ts +4 -6
- package/src/prompt/composer.ts +17 -5
- package/src/render/code-cell.ts +1 -1
- package/src/render/file-list.ts +4 -7
- package/src/render/render-utils.d.ts +23 -1
- package/src/render/render-utils.ts +38 -6
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/setup/scenes/language.ts +122 -0
- package/src/setup/scenes/types.ts +6 -0
- package/src/setup/setup-version.ts +1 -1
- package/src/setup/wizard.ts +2 -0
- package/src/status-line/startup.ts +36 -70
- package/src/terminal-capabilities.d.ts +1 -1
- package/src/terminal-capabilities.ts +5 -0
- package/src/theme/symbols.d.ts +3 -1
- package/src/theme/symbols.ts +16 -9
- package/src/theme/theme-class.d.ts +1 -0
- package/src/theme/theme-class.ts +15 -3
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +1 -0
- package/src/theme/tui-adapters.d.ts +2 -0
- package/src/theme/tui-adapters.ts +8 -3
- package/src/thinking.d.ts +8 -6
- package/src/thinking.ts +17 -11
- package/src/tmux.ts +1 -0
- package/src/tools/agent-tree.ts +13 -11
- package/src/tools/ask.ts +24 -37
- package/src/tools/ast-edit.ts +48 -93
- package/src/tools/ast-grep.d.ts +2 -0
- package/src/tools/ast-grep.ts +31 -67
- package/src/tools/bash.ts +7 -0
- package/src/tools/default-renderer.ts +1 -1
- package/src/tools/edit.ts +50 -43
- package/src/tools/eval.d.ts +2 -0
- package/src/tools/eval.ts +2 -0
- package/src/tools/fetch.ts +2 -1
- package/src/tools/find.d.ts +1 -1
- package/src/tools/find.ts +13 -5
- package/src/tools/github.ts +14 -46
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +47 -277
- package/src/tools/grouped-file-output.d.ts +100 -19
- package/src/tools/grouped-file-output.ts +414 -103
- package/src/tools/hashline-format.d.ts +5 -0
- package/src/tools/hashline-format.ts +5 -0
- package/src/tools/json-tree.ts +1 -5
- package/src/tools/lsp.ts +210 -32
- package/src/tools/native-view.d.ts +2 -0
- package/src/tools/native-view.ts +11 -5
- package/src/tools/output-meta.d.ts +27 -0
- package/src/tools/output-meta.ts +68 -4
- package/src/tools/proc-render.ts +3 -3
- package/src/tools/read.d.ts +14 -4
- package/src/tools/read.ts +20 -5
- package/src/tools/task.d.ts +4 -3
- package/src/tools/task.ts +41 -81
- package/src/tools/vibe.ts +4 -4
- package/src/tools/wait.d.ts +2 -0
- package/src/tools/wait.ts +8 -5
- package/src/tools/write.ts +17 -27
- package/src/tools/yield.ts +1 -1
- package/src/tui.d.ts +12 -0
- package/src/tui.ts +91 -9
- package/src/utils.d.ts +4 -0
- package/src/utils.ts +10 -0
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
getBtwLatestTurn,
|
|
19
19
|
getBtwTopicLabel,
|
|
20
20
|
getBtwTurns,
|
|
21
|
+
type BtwInjectParts,
|
|
22
|
+
splitBtwInject,
|
|
21
23
|
} from "./btw-history";
|
|
24
|
+
import { BtwInjectAnswer, type BtwInjectState, describeBtwInjectAnswer } from "./btw-inject";
|
|
22
25
|
import { compactImageMarkers, formatVisionMarker } from "../prompt/composer-attachments";
|
|
23
26
|
import { extractImagePastePathsFromText } from "../prompt/custom-editor";
|
|
24
27
|
import { BracketedPasteHandler } from "../bracketed-paste";
|
|
@@ -29,6 +32,8 @@ import {
|
|
|
29
32
|
matchesSelectPageDown,
|
|
30
33
|
matchesSelectPageUp,
|
|
31
34
|
matchesSelectUp,
|
|
35
|
+
appBtwInjectKey,
|
|
36
|
+
matchesAppBtwInject,
|
|
32
37
|
} from "../keybinding-matchers";
|
|
33
38
|
import type { SpaceHoldHandler } from "../space-hold";
|
|
34
39
|
import { sanitizeErrorLine } from "../chrome/error-block";
|
|
@@ -77,6 +82,25 @@ interface BtwHistoryPanelOptions {
|
|
|
77
82
|
* first. For a host with no inline panel to fall back to (Tern).
|
|
78
83
|
*/
|
|
79
84
|
escapeHides?: boolean;
|
|
85
|
+
/** `btw.inject` hooks, given only while it is on for this view. */
|
|
86
|
+
inject?: BtwHistoryInject;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface BtwHistoryInject {
|
|
90
|
+
/**
|
|
91
|
+
* How a finished turn's closed `<inject>` block shows: apart from its prose while pending or
|
|
92
|
+
* sent, plain text when `undefined`. A streaming turn always shows its block.
|
|
93
|
+
*/
|
|
94
|
+
state: (record: BtwHistoryRecord, turnIndex: number) => BtwInjectState | undefined;
|
|
95
|
+
/** Whether the inject key may send the record's latest block now. */
|
|
96
|
+
canSend: (record: BtwHistoryRecord) => boolean;
|
|
97
|
+
send: (record: BtwHistoryRecord) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A turn's `<inject>` block as displayed apart from its prose. */
|
|
101
|
+
interface InjectBlock {
|
|
102
|
+
parts: BtwInjectParts;
|
|
103
|
+
state: BtwInjectState;
|
|
80
104
|
}
|
|
81
105
|
|
|
82
106
|
interface FollowUpComposer {
|
|
@@ -95,6 +119,8 @@ interface RenderedTurn {
|
|
|
95
119
|
turn: BtwHistoryTurn;
|
|
96
120
|
question: Markdown;
|
|
97
121
|
answer: Markdown;
|
|
122
|
+
/** How the answer's `<inject>` block showed; `undefined` when it rendered as plain text. */
|
|
123
|
+
block: BtwInjectState | undefined;
|
|
98
124
|
lines: readonly string[];
|
|
99
125
|
width: number;
|
|
100
126
|
}
|
|
@@ -110,6 +136,8 @@ interface BtwHistoryNativeMemo {
|
|
|
110
136
|
followUpPending: boolean;
|
|
111
137
|
canFollowUp: boolean;
|
|
112
138
|
copied: boolean;
|
|
139
|
+
canInject: boolean;
|
|
140
|
+
latestInject: BtwInjectState | undefined;
|
|
113
141
|
scroll: NativeScroll | undefined;
|
|
114
142
|
node: NativeNode;
|
|
115
143
|
}
|
|
@@ -150,6 +178,7 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
150
178
|
#listScroll = 0;
|
|
151
179
|
#listHeight = 1;
|
|
152
180
|
#focused = false;
|
|
181
|
+
#useTerminalCursor = false;
|
|
153
182
|
#composer: FollowUpComposer | undefined;
|
|
154
183
|
readonly #pasteHandler = new BracketedPasteHandler();
|
|
155
184
|
#followUpPending = false;
|
|
@@ -225,6 +254,12 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
225
254
|
this.#focused = value;
|
|
226
255
|
}
|
|
227
256
|
|
|
257
|
+
/** Keep the follow-up input's cursor mode aligned so the hardware cursor (and IME preedit) lands on its caret. */
|
|
258
|
+
setUseTerminalCursor(useTerminalCursor: boolean): void {
|
|
259
|
+
this.#useTerminalCursor = useTerminalCursor;
|
|
260
|
+
this.#composer?.input.setUseTerminalCursor(useTerminalCursor);
|
|
261
|
+
}
|
|
262
|
+
|
|
228
263
|
update(records: readonly BtwHistoryRecord[]): void {
|
|
229
264
|
this.#records = records;
|
|
230
265
|
this.#detailDirty = true;
|
|
@@ -329,6 +364,7 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
329
364
|
const input = new Input();
|
|
330
365
|
input.prompt = theme.fg("accent", "Follow up: ");
|
|
331
366
|
input.placeholder = "Ask about this answer…";
|
|
367
|
+
input.setUseTerminalCursor(this.#useTerminalCursor);
|
|
332
368
|
if (this.#options.spaceHoldKeys !== undefined) input.spaceHold.keys = this.#options.spaceHoldKeys;
|
|
333
369
|
input.spaceHold.handler = this.#options.spaceHold?.(input);
|
|
334
370
|
const composer: FollowUpComposer = {
|
|
@@ -504,6 +540,10 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
504
540
|
if (record && getBtwCopyText(record) !== undefined) this.#options.onCopy(record);
|
|
505
541
|
return;
|
|
506
542
|
}
|
|
543
|
+
if (this.#options.inject && matchesAppBtwInject(data)) {
|
|
544
|
+
this.#sendInject(record);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
507
547
|
// Legacy terminals deliver Ctrl+/ (and Ctrl+_) as US without Kitty protocol.
|
|
508
548
|
if (
|
|
509
549
|
matchesKey(data, "tab") ||
|
|
@@ -568,6 +608,8 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
568
608
|
const composer = this.#composer;
|
|
569
609
|
const canFollowUp = record !== undefined && this.#canFollowUp(record);
|
|
570
610
|
const copied = record !== undefined && this.#isCopied(record);
|
|
611
|
+
const canInject = record !== undefined && this.#options.inject?.canSend(record) === true;
|
|
612
|
+
const latestInject = record && this.#options.inject?.state(record, getBtwTurns(record).length - 1);
|
|
571
613
|
const memo = this.#native;
|
|
572
614
|
if (
|
|
573
615
|
memo?.records === this.#records &&
|
|
@@ -579,6 +621,8 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
579
621
|
memo.followUpPending === this.#followUpPending &&
|
|
580
622
|
memo.canFollowUp === canFollowUp &&
|
|
581
623
|
memo.copied === copied &&
|
|
624
|
+
memo.canInject === canInject &&
|
|
625
|
+
memo.latestInject === latestInject &&
|
|
582
626
|
memo.scroll === this.#scroll
|
|
583
627
|
) {
|
|
584
628
|
return memo.node;
|
|
@@ -604,7 +648,7 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
604
648
|
} else {
|
|
605
649
|
children.push(this.#describeEmpty());
|
|
606
650
|
}
|
|
607
|
-
children.push(this.#describeActions(record, canFollowUp, copied));
|
|
651
|
+
children.push(this.#describeActions(record, canFollowUp, copied, canInject));
|
|
608
652
|
// The sheet is the frame (`nativeOverlay`); its last row is the pinned footer.
|
|
609
653
|
const described = col(children, { gap: "none" });
|
|
610
654
|
this.#native = {
|
|
@@ -617,6 +661,8 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
617
661
|
followUpPending: this.#followUpPending,
|
|
618
662
|
canFollowUp,
|
|
619
663
|
copied,
|
|
664
|
+
canInject,
|
|
665
|
+
latestInject,
|
|
620
666
|
scroll: this.#scroll,
|
|
621
667
|
node: described,
|
|
622
668
|
};
|
|
@@ -633,6 +679,9 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
633
679
|
case "copy-answer":
|
|
634
680
|
if (record && getBtwCopyText(record) !== undefined) this.#options.onCopy(record);
|
|
635
681
|
break;
|
|
682
|
+
case "inject":
|
|
683
|
+
this.#sendInject(record);
|
|
684
|
+
break;
|
|
636
685
|
case "follow-up":
|
|
637
686
|
if (record) this.openFollowUp(record.id);
|
|
638
687
|
break;
|
|
@@ -690,12 +739,31 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
690
739
|
/** The selected side question as a short document: the asked question titles each answer. */
|
|
691
740
|
#describeThread(record: BtwHistoryRecord): NativeNode {
|
|
692
741
|
const turns = getDisplayTurns(record);
|
|
693
|
-
const children: NativeChild[] = turns.map((turn, index) =>
|
|
742
|
+
const children: NativeChild[] = turns.map((turn, index) =>
|
|
743
|
+
this.#describeTurn(turn, index, `turn-${index}`, this.#injectBlock(record, turn, index)),
|
|
744
|
+
);
|
|
694
745
|
if (this.#composer) children.push(this.#describeComposer(this.#composer));
|
|
695
746
|
return node("col", { role: "zeta.btw.thread" }, children, "thread");
|
|
696
747
|
}
|
|
697
748
|
|
|
698
|
-
#
|
|
749
|
+
#sendInject(record: BtwHistoryRecord | undefined): void {
|
|
750
|
+
const inject = this.#options.inject;
|
|
751
|
+
if (!record || !inject?.canSend(record)) return;
|
|
752
|
+
inject.send(record);
|
|
753
|
+
this.#detailDirty = true;
|
|
754
|
+
this.#options.requestRender();
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** The turn's `<inject>` block to show apart from its prose, if any (see {@link BtwHistoryInject.state}). */
|
|
758
|
+
#injectBlock(record: BtwHistoryRecord, turn: BtwHistoryTurn, index: number): InjectBlock | undefined {
|
|
759
|
+
const inject = this.#options.inject;
|
|
760
|
+
const parts = inject ? splitBtwInject(turn.answer) : undefined;
|
|
761
|
+
if (!inject || !parts) return undefined;
|
|
762
|
+
const state = turn.status === "running" ? "pending" : parts.closed ? inject.state(record, index) : undefined;
|
|
763
|
+
return state && { parts, state };
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
#describeTurn(turn: BtwHistoryTurn, index: number, key: string, block: InjectBlock | undefined): NativeNode {
|
|
699
767
|
const meta: TspSpan[] =
|
|
700
768
|
index === 0
|
|
701
769
|
? [span(this.#dateFormat.format(turn.createdAt))]
|
|
@@ -709,11 +777,12 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
709
777
|
];
|
|
710
778
|
// A failed turn with no text says only why it failed.
|
|
711
779
|
if (turn.answer.trim() || !turn.error) {
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
})
|
|
780
|
+
const stream = turn.status === "running";
|
|
781
|
+
const answer = block
|
|
782
|
+
? describeBtwInjectAnswer(block.parts, block.state === "sent", stream)
|
|
783
|
+
: turn.answer.trim()
|
|
784
|
+
? md(sanitizeDisplayText(turn.answer), { stream })
|
|
785
|
+
: text([span(stream ? "Thinking…" : "No answer text.", "dim")], { role: "zeta.btw.pending" });
|
|
717
786
|
children.push(node("col", { role: "zeta.btw.answer" }, [answer], "answer"));
|
|
718
787
|
}
|
|
719
788
|
if (turn.error) {
|
|
@@ -764,7 +833,12 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
764
833
|
* primary action (Follow up, or Send while composing) in the corner. Keys
|
|
765
834
|
* live in the buttons' tooltips.
|
|
766
835
|
*/
|
|
767
|
-
#describeActions(
|
|
836
|
+
#describeActions(
|
|
837
|
+
record: BtwHistoryRecord | undefined,
|
|
838
|
+
canFollowUp: boolean,
|
|
839
|
+
copied: boolean,
|
|
840
|
+
canInject: boolean,
|
|
841
|
+
): NativeNode {
|
|
768
842
|
if (this.#composer) {
|
|
769
843
|
return actionBar([
|
|
770
844
|
null,
|
|
@@ -776,6 +850,7 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
776
850
|
const hides = this.#options.escapeHides === true;
|
|
777
851
|
const buttons: (NativeNode | null)[] = [];
|
|
778
852
|
if (running) buttons.push(actionButton("Stop answer", "stop", { keys: hides ? "x" : "escape" }));
|
|
853
|
+
if (canInject) buttons.push(actionButton("Inject into main", "inject", { keys: appBtwInjectKey() }));
|
|
779
854
|
if (record && getBtwCopyText(record) !== undefined) {
|
|
780
855
|
buttons.push(actionButton(copied ? "Copy again" : "Copy answer", "copy-answer", { keys: "c" }));
|
|
781
856
|
if (copied) buttons.push(text([span("✓ Copied", "success")], { role: "zeta.btw.copied" }));
|
|
@@ -839,7 +914,12 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
839
914
|
});
|
|
840
915
|
}
|
|
841
916
|
|
|
842
|
-
#renderTurn(
|
|
917
|
+
#renderTurn(
|
|
918
|
+
turn: BtwHistoryTurn,
|
|
919
|
+
cached: RenderedTurn | undefined,
|
|
920
|
+
width: number,
|
|
921
|
+
block: InjectBlock | undefined,
|
|
922
|
+
): RenderedTurn {
|
|
843
923
|
const previous = cached?.turn;
|
|
844
924
|
if (
|
|
845
925
|
cached &&
|
|
@@ -848,14 +928,16 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
848
928
|
turn.answer === previous?.answer &&
|
|
849
929
|
turn.status === previous?.status &&
|
|
850
930
|
turn.error === previous?.error &&
|
|
851
|
-
turn.createdAt === previous?.createdAt
|
|
931
|
+
turn.createdAt === previous?.createdAt &&
|
|
932
|
+
block?.state === cached.block
|
|
852
933
|
) {
|
|
853
934
|
return cached;
|
|
854
935
|
}
|
|
855
936
|
const question = cached?.question ?? new Markdown("", 0, 0, getMarkdownTheme());
|
|
856
937
|
const answer = cached?.answer ?? new Markdown("", 0, 0, getMarkdownTheme());
|
|
857
938
|
if (turn.question !== previous?.question) question.setText(sanitizeDisplayText(turn.question));
|
|
858
|
-
|
|
939
|
+
// A block's state can change while the answer stays the same, so the plain text is reset on every miss.
|
|
940
|
+
if (!block) answer.setText(sanitizeDisplayText(turn.answer));
|
|
859
941
|
const status = STATUS[turn.status];
|
|
860
942
|
const lines = [
|
|
861
943
|
...wrapTextWithAnsi(
|
|
@@ -868,7 +950,8 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
868
950
|
"",
|
|
869
951
|
theme.bold(theme.fg("accent", "Answer")),
|
|
870
952
|
];
|
|
871
|
-
if (
|
|
953
|
+
if (block) lines.push(...new BtwInjectAnswer(block.parts, block.state === "sent").render(width));
|
|
954
|
+
else if (turn.answer.trim()) lines.push(...answer.render(width));
|
|
872
955
|
else
|
|
873
956
|
lines.push(
|
|
874
957
|
...wrapTextWithAnsi(
|
|
@@ -890,6 +973,7 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
890
973
|
},
|
|
891
974
|
question,
|
|
892
975
|
answer,
|
|
976
|
+
block: block?.state,
|
|
893
977
|
lines,
|
|
894
978
|
width,
|
|
895
979
|
};
|
|
@@ -907,7 +991,12 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
907
991
|
if (record) {
|
|
908
992
|
const turns = getDisplayTurns(record);
|
|
909
993
|
for (let index = 0; index < turns.length; index++) {
|
|
910
|
-
const cached = this.#renderTurn(
|
|
994
|
+
const cached = this.#renderTurn(
|
|
995
|
+
turns[index]!,
|
|
996
|
+
this.#turns[index],
|
|
997
|
+
inner,
|
|
998
|
+
this.#injectBlock(record, turns[index]!, index),
|
|
999
|
+
);
|
|
911
1000
|
this.#turns[index] = cached;
|
|
912
1001
|
if (index > 0) lines.push("", theme.fg("dim", theme.boxRound.horizontal.repeat(inner)), "");
|
|
913
1002
|
lines.push(...cached.lines);
|
|
@@ -967,6 +1056,9 @@ export class BtwHistoryPanel implements Component, Focusable {
|
|
|
967
1056
|
];
|
|
968
1057
|
if (!composer) {
|
|
969
1058
|
if (record && this.#canFollowUp(record)) actions.push(rawKeyHint(["f", "enter"], "follow up"));
|
|
1059
|
+
const injectKey = appBtwInjectKey();
|
|
1060
|
+
if (injectKey && record && this.#options.inject?.canSend(record))
|
|
1061
|
+
actions.push(rawKeyHint(injectKey, "inject"));
|
|
970
1062
|
if (record && getBtwCopyText(record) !== undefined) {
|
|
971
1063
|
if (this.#isCopied(record))
|
|
972
1064
|
actions.push(theme.fg("success", `✓ copied · ${formatKeyHint("c")} to copy again`));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ImageContent } from "@linxiraos/pi-ai";
|
|
2
|
+
import { sanitizeDisplayText } from "./extensions/display-text";
|
|
2
3
|
|
|
3
4
|
export interface BtwHistoryTurn {
|
|
4
5
|
question: string;
|
|
@@ -32,6 +33,11 @@ export function getBtwTurns(record: BtwHistoryRecord): readonly BtwHistoryTurn[]
|
|
|
32
33
|
return [record, ...(record.followUps ?? [])];
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/** Identifies one turn of a topic, its latest by default: a follow-up gets a new key, so per-answer marks reset. */
|
|
37
|
+
export function getBtwTurnKey(record: BtwHistoryRecord, turnIndex = record.followUps?.length ?? 0): string {
|
|
38
|
+
return `${record.id}:${turnIndex}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
/** Copy the most recent nonblank answer, preserving its original whitespace. */
|
|
36
42
|
export function getBtwCopyText(record: BtwHistoryRecord): string | undefined {
|
|
37
43
|
if (record.followUps) {
|
|
@@ -42,3 +48,62 @@ export function getBtwCopyText(record: BtwHistoryRecord): string | undefined {
|
|
|
42
48
|
}
|
|
43
49
|
return record.answer.trim() ? record.answer : undefined;
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
const INJECT_OPEN = "<inject>";
|
|
53
|
+
const INJECT_CLOSE = "</inject>";
|
|
54
|
+
|
|
55
|
+
/** An answer around its `<inject>` block: the steering prompt a side answer drafted for the main session. */
|
|
56
|
+
export interface BtwInjectParts {
|
|
57
|
+
before: string;
|
|
58
|
+
inject: string;
|
|
59
|
+
after: string;
|
|
60
|
+
/** False while no opener has a close: the block may still be streaming, so it runs to the end. */
|
|
61
|
+
closed: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Split an answer at its last closed `<inject>` block: the last opener that has a close
|
|
66
|
+
* after it, paired with the first close after it. A tag merely mentioned in prose,
|
|
67
|
+
* before or after the block, cannot capture it. Without a closed block, the last opener
|
|
68
|
+
* runs to the end (`closed: false`); display it only while the answer still streams.
|
|
69
|
+
* Linear: the last opener before the last close is the last one with any close after it.
|
|
70
|
+
*/
|
|
71
|
+
export function splitBtwInject(answer: string): BtwInjectParts | undefined {
|
|
72
|
+
const lastClose = answer.lastIndexOf(INJECT_CLOSE);
|
|
73
|
+
const open = lastClose === -1 ? -1 : answer.lastIndexOf(INJECT_OPEN, lastClose - INJECT_OPEN.length);
|
|
74
|
+
if (open !== -1) {
|
|
75
|
+
const close = answer.indexOf(INJECT_CLOSE, open + INJECT_OPEN.length);
|
|
76
|
+
return {
|
|
77
|
+
before: answer.slice(0, open),
|
|
78
|
+
inject: answer.slice(open + INJECT_OPEN.length, close),
|
|
79
|
+
after: answer.slice(close + INJECT_CLOSE.length),
|
|
80
|
+
closed: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const streaming = answer.lastIndexOf(INJECT_OPEN);
|
|
84
|
+
if (streaming === -1) return undefined;
|
|
85
|
+
return {
|
|
86
|
+
before: answer.slice(0, streaming),
|
|
87
|
+
inject: answer.slice(streaming + INJECT_OPEN.length),
|
|
88
|
+
after: "",
|
|
89
|
+
closed: false,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A block's text as shown and as sent: control sequences stripped, tabs expanded, trimmed. */
|
|
94
|
+
export function formatBtwInjectText(inject: string): string {
|
|
95
|
+
return sanitizeDisplayText(inject).trim();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The steering prompt to send, exactly as the block shows it; undefined while unclosed or blank. */
|
|
99
|
+
export function getBtwInject(answer: string): string | undefined {
|
|
100
|
+
const parts = splitBtwInject(answer);
|
|
101
|
+
const text = parts?.closed ? formatBtwInjectText(parts.inject) : "";
|
|
102
|
+
return text || undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A topic's steering prompt: only its latest turn's, once that turn completed. */
|
|
106
|
+
export function getBtwRecordInject(record: BtwHistoryRecord): string | undefined {
|
|
107
|
+
const latest = getBtwLatestTurn(record);
|
|
108
|
+
return latest.status === "complete" ? getBtwInject(latest.answer) : undefined;
|
|
109
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type Component, Markdown, visibleWidth, wrapTextWithAnsi } from "../index";
|
|
2
|
+
import { getMarkdownTheme, theme } from "../theme/theme";
|
|
3
|
+
import { card, col, md, span, text } from "../native/describe";
|
|
4
|
+
import type { NativeNode } from "../native/node";
|
|
5
|
+
import { type BtwInjectParts, formatBtwInjectText } from "./btw-history";
|
|
6
|
+
import { sanitizeDisplayText } from "./extensions/display-text";
|
|
7
|
+
|
|
8
|
+
/** Labels a steering prompt that has not been sent yet. */
|
|
9
|
+
export const BTW_INJECT_LABEL = "Inject into main session";
|
|
10
|
+
/** Labels a sent steering prompt. */
|
|
11
|
+
export const BTW_INJECTED_LABEL = "Injected into main session";
|
|
12
|
+
|
|
13
|
+
/** A displayed `<inject>` block: still sendable, or sent. Blocks in neither state render as plain text. */
|
|
14
|
+
export type BtwInjectState = "pending" | "sent";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Terminal lines for an `<inject>` block: every wrapped line behind a gutter of the `btw.rail`
|
|
18
|
+
* (pink while pending, green once sent) and the send arrow (`nav.selected`) or blanks as wide,
|
|
19
|
+
* then the label on the row below. Both states take the same rows and text column, so sending
|
|
20
|
+
* recolours the block in place.
|
|
21
|
+
*/
|
|
22
|
+
function renderBlockLines(inject: string, width: number, sent: boolean): string[] {
|
|
23
|
+
const arrow = theme.nav.selected;
|
|
24
|
+
const color = sent ? "success" : "customMessageLabel";
|
|
25
|
+
const marker = sent ? arrow : " ".repeat(visibleWidth(arrow));
|
|
26
|
+
const prefix = `${theme.fg(color, theme.symbol("btw.rail"))} ${theme.bold(marker)} `;
|
|
27
|
+
const inner = Math.max(1, width - visibleWidth(prefix));
|
|
28
|
+
const body = formatBtwInjectText(inject)
|
|
29
|
+
.split("\n")
|
|
30
|
+
.flatMap(line => (line.trim() ? wrapTextWithAnsi(line, inner) : [""]))
|
|
31
|
+
.map(line => `${prefix}${line}`);
|
|
32
|
+
return [...body, `${prefix}${theme.fg(color, sent ? BTW_INJECTED_LABEL : BTW_INJECT_LABEL)}`];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Text-mode answer split around its `<inject>` block: prose, the railed block, prose, a blank row apart. */
|
|
36
|
+
export class BtwInjectAnswer implements Component {
|
|
37
|
+
readonly #inject: string;
|
|
38
|
+
readonly #sent: boolean;
|
|
39
|
+
readonly #before: Markdown | undefined;
|
|
40
|
+
readonly #after: Markdown | undefined;
|
|
41
|
+
|
|
42
|
+
constructor(parts: BtwInjectParts, sent: boolean) {
|
|
43
|
+
this.#inject = parts.inject;
|
|
44
|
+
this.#sent = sent;
|
|
45
|
+
this.#before = prose(parts.before);
|
|
46
|
+
this.#after = prose(parts.after);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
render(width: number): string[] {
|
|
50
|
+
return [
|
|
51
|
+
...(this.#before ? [...this.#before.render(width), ""] : []),
|
|
52
|
+
...renderBlockLines(this.#inject, width, this.#sent),
|
|
53
|
+
...(this.#after ? ["", ...this.#after.render(width)] : []),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
invalidate(): void {
|
|
58
|
+
this.#before?.invalidate();
|
|
59
|
+
this.#after?.invalidate();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function prose(text: string): Markdown | undefined {
|
|
64
|
+
const trimmed = text.trim();
|
|
65
|
+
return trimmed ? new Markdown(sanitizeDisplayText(trimmed), 0, 0, getMarkdownTheme()) : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The same answer for native surfaces. They wrap text themselves, so a per-row gutter cannot
|
|
70
|
+
* follow wrapped lines: a card toned like the rail (`user` pending, `success` sent) marks the
|
|
71
|
+
* whole block instead, with the label as its last row.
|
|
72
|
+
*/
|
|
73
|
+
export function describeBtwInjectAnswer(parts: BtwInjectParts, sent: boolean, stream: boolean): NativeNode {
|
|
74
|
+
const before = parts.before.trim();
|
|
75
|
+
const after = parts.after.trim();
|
|
76
|
+
const label = sent ? `${theme.nav.selected} ${BTW_INJECTED_LABEL}` : BTW_INJECT_LABEL;
|
|
77
|
+
const block = card({ role: "zeta.btw.inject", tone: sent ? "success" : "user" }, [
|
|
78
|
+
...formatBtwInjectText(parts.inject)
|
|
79
|
+
.split("\n")
|
|
80
|
+
.map(line => text(line, { wrap: "word" })),
|
|
81
|
+
text([span(label, sent ? "success" : "customMessageLabel")]),
|
|
82
|
+
]);
|
|
83
|
+
return col(
|
|
84
|
+
[
|
|
85
|
+
...(before ? [md(sanitizeDisplayText(before), { stream })] : []),
|
|
86
|
+
block,
|
|
87
|
+
...(after ? [md(sanitizeDisplayText(after), { stream })] : []),
|
|
88
|
+
],
|
|
89
|
+
{ gap: "sm" },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -5,10 +5,13 @@ import { sanitizeErrorLine } from "../chrome/error-block";
|
|
|
5
5
|
import { OverlayPanel } from "../chrome/overlay-box";
|
|
6
6
|
import { StreamingPanelContent } from "../chrome/streaming-panel";
|
|
7
7
|
import { boundKeys, interruptKey } from "../chrome/keybinding-hints";
|
|
8
|
-
import { formatKeyHint } from "../app-keybindings";
|
|
8
|
+
import { formatKeyHint, type KeyId } from "../app-keybindings";
|
|
9
9
|
import type { NativeNode } from "../native/node";
|
|
10
10
|
import { col, md, node, span, text } from "../native/describe";
|
|
11
11
|
import { hintsRow, type NativeHint, statusHintsRow } from "../native/overlay";
|
|
12
|
+
import { appBtwInjectKey } from "../keybinding-matchers";
|
|
13
|
+
import { type BtwInjectParts, splitBtwInject } from "./btw-history";
|
|
14
|
+
import { BtwInjectAnswer, describeBtwInjectAnswer } from "./btw-inject";
|
|
12
15
|
|
|
13
16
|
type BtwPanelState = "running" | "complete" | "branching" | "aborted" | "error";
|
|
14
17
|
|
|
@@ -19,21 +22,28 @@ interface BtwPanelComponentOptions {
|
|
|
19
22
|
tui: TUI;
|
|
20
23
|
canBranch?: () => boolean;
|
|
21
24
|
canFollowUp?: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Given only while `btw.inject` is on: the answer's `<inject>` block shows apart from its
|
|
27
|
+
* prose, and the inject key (`app.btw.inject`) is offered while this returns true.
|
|
28
|
+
*/
|
|
29
|
+
canInject?: () => boolean;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export class BtwPanelComponent extends OverlayPanel {
|
|
25
33
|
#tui: TUI;
|
|
26
34
|
#canBranch: (() => boolean) | undefined;
|
|
27
35
|
#canFollowUp: (() => boolean) | undefined;
|
|
36
|
+
#canInject: (() => boolean) | undefined;
|
|
28
37
|
#state: BtwPanelState = "running";
|
|
29
38
|
#answer = "";
|
|
30
39
|
#errorMessage: string | undefined;
|
|
31
40
|
#visibleAnswer = "";
|
|
32
41
|
#closed = false;
|
|
33
42
|
#copied = false;
|
|
43
|
+
#injected = false;
|
|
34
44
|
#baseTitle: string;
|
|
35
45
|
readonly #content: StreamingPanelContent;
|
|
36
|
-
#native: { node: NativeNode; canFollowUp: boolean; canBranch: boolean } | undefined;
|
|
46
|
+
#native: { node: NativeNode; canFollowUp: boolean; canBranch: boolean; injectKey: KeyId | undefined } | undefined;
|
|
37
47
|
|
|
38
48
|
constructor(options: BtwPanelComponentOptions) {
|
|
39
49
|
const baseTitle = replaceTabs(options.title ?? `/btw ${options.question}`);
|
|
@@ -42,8 +52,9 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
42
52
|
this.#tui = options.tui;
|
|
43
53
|
this.#canBranch = options.canBranch;
|
|
44
54
|
this.#canFollowUp = options.canFollowUp;
|
|
55
|
+
this.#canInject = options.canInject;
|
|
45
56
|
this.#content = new StreamingPanelContent(() => ({
|
|
46
|
-
sections:
|
|
57
|
+
sections: this.#contentSections(),
|
|
47
58
|
footer: () => this.#footerLine(),
|
|
48
59
|
}));
|
|
49
60
|
this.addChild(this.#content);
|
|
@@ -81,6 +92,13 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
81
92
|
this.#rebuild();
|
|
82
93
|
}
|
|
83
94
|
|
|
95
|
+
/** Shows the answer's steering prompt as sent (send arrows, green), or back to pending when a send failed. */
|
|
96
|
+
setInjected(injected: boolean): void {
|
|
97
|
+
if (this.#closed || this.#injected === injected) return;
|
|
98
|
+
this.#injected = injected;
|
|
99
|
+
this.#rebuild();
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
#setCopied(copied: boolean): void {
|
|
85
103
|
this.#copied = copied;
|
|
86
104
|
this.title = copied ? `${this.#baseTitle} ✓ Copied` : this.#baseTitle;
|
|
@@ -123,6 +141,20 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
123
141
|
return this.#visibleAnswer;
|
|
124
142
|
}
|
|
125
143
|
|
|
144
|
+
/**
|
|
145
|
+
* The answer around its `<inject>` block, which displays apart from the prose only while
|
|
146
|
+
* streaming or once the tag closed: an unclosed block in a finished answer stays plain text.
|
|
147
|
+
*/
|
|
148
|
+
#injectParts(): BtwInjectParts | undefined {
|
|
149
|
+
const parts = this.#canInject ? splitBtwInject(this.#visibleAnswer) : undefined;
|
|
150
|
+
return parts && (parts.closed || this.#state === "running") ? parts : undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The bound inject key while it can send the answer's steering prompt. */
|
|
154
|
+
#injectKey(): KeyId | undefined {
|
|
155
|
+
return this.#canInject?.() ? appBtwInjectKey() : undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
126
158
|
close(): void {
|
|
127
159
|
this.#closed = true;
|
|
128
160
|
}
|
|
@@ -135,8 +167,10 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
135
167
|
override describe(): NativeNode {
|
|
136
168
|
const canFollowUp = this.#canFollowUp?.() ?? false;
|
|
137
169
|
const canBranch = this.#canBranch?.() ?? this.isBranchable();
|
|
170
|
+
const injectKey = this.#injectKey();
|
|
138
171
|
const memo = this.#native;
|
|
139
|
-
if (memo && memo.canFollowUp === canFollowUp && memo.canBranch === canBranch
|
|
172
|
+
if (memo && memo.canFollowUp === canFollowUp && memo.canBranch === canBranch && memo.injectKey === injectKey)
|
|
173
|
+
return memo.node;
|
|
140
174
|
// Inline in the dock, styled as a sheet by role: a borderless column headed by the question.
|
|
141
175
|
// The command word is the accent; the rest of the heading is the question or arguments.
|
|
142
176
|
const space = this.#baseTitle.indexOf(" ");
|
|
@@ -148,12 +182,12 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
148
182
|
...(live ? [node("spinner", {})] : []),
|
|
149
183
|
title,
|
|
150
184
|
]);
|
|
151
|
-
const described = col([head, this.#describeBody(), this.#describeFooter(canFollowUp, canBranch)], {
|
|
185
|
+
const described = col([head, this.#describeBody(), this.#describeFooter(canFollowUp, canBranch, injectKey)], {
|
|
152
186
|
role: this.nativeRole,
|
|
153
187
|
gap: "sm",
|
|
154
188
|
tone: this.#state === "error" ? "error" : this.#state === "aborted" ? "warning" : undefined,
|
|
155
189
|
});
|
|
156
|
-
this.#native = { node: described, canFollowUp, canBranch };
|
|
190
|
+
this.#native = { node: described, canFollowUp, canBranch, injectKey };
|
|
157
191
|
return described;
|
|
158
192
|
}
|
|
159
193
|
|
|
@@ -162,18 +196,22 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
162
196
|
return text([span(sanitizeErrorLine(this.#errorMessage ?? "Unknown error"), "error")], { wrap: "word" });
|
|
163
197
|
}
|
|
164
198
|
const answer = this.#visibleAnswer;
|
|
165
|
-
|
|
199
|
+
const parts = this.#injectParts();
|
|
200
|
+
const stream = this.#state === "running";
|
|
201
|
+
if (parts) return describeBtwInjectAnswer(parts, this.#injected, stream);
|
|
202
|
+
if (answer) return md(answer, { stream });
|
|
166
203
|
const waiting = this.#state === "running" ? `${theme.status.pending} Waiting for response…` : "No text returned.";
|
|
167
204
|
return text([span(waiting, "dim")]);
|
|
168
205
|
}
|
|
169
206
|
|
|
170
|
-
#describeFooter(canFollowUp: boolean, canBranch: boolean): NativeNode {
|
|
207
|
+
#describeFooter(canFollowUp: boolean, canBranch: boolean, injectKey: KeyId | undefined): NativeNode {
|
|
171
208
|
const esc: NativeHint = { keys: boundKeys("app.interrupt", ["escape"]).slice(0, 1), label: "to close" };
|
|
172
209
|
switch (this.#state) {
|
|
173
210
|
case "running":
|
|
174
211
|
return hintsRow([{ ...esc, label: "to cancel" }]);
|
|
175
212
|
case "complete": {
|
|
176
213
|
const hints: NativeHint[] = [];
|
|
214
|
+
if (injectKey) hints.push({ keys: [injectKey], label: "to inject" });
|
|
177
215
|
if (this.isCopyable()) hints.push({ keys: ["c"], label: this.#copied ? "to copy again" : "to copy" });
|
|
178
216
|
if (canFollowUp) hints.push({ keys: ["f"], label: "to follow up" });
|
|
179
217
|
if (canBranch) hints.push({ keys: ["b"], label: "to branch" });
|
|
@@ -209,6 +247,8 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
209
247
|
case "complete": {
|
|
210
248
|
const actions: string[] = [];
|
|
211
249
|
const copyKey = formatKeyHint("c");
|
|
250
|
+
const injectKey = this.#injectKey();
|
|
251
|
+
if (injectKey) actions.push(`${formatKeyHint(injectKey)} to inject`);
|
|
212
252
|
if (this.isCopyable()) actions.push(this.#copied ? `${copyKey} to copy again` : `${copyKey} to copy`);
|
|
213
253
|
if (this.#canFollowUp?.()) actions.push(`${formatKeyHint("f")} to follow up`);
|
|
214
254
|
if (this.#canBranch?.() ?? this.isBranchable()) actions.push(`${formatKeyHint("b")} to branch`);
|
|
@@ -227,16 +267,17 @@ export class BtwPanelComponent extends OverlayPanel {
|
|
|
227
267
|
}
|
|
228
268
|
}
|
|
229
269
|
|
|
230
|
-
#
|
|
270
|
+
#contentSections(): Component[] {
|
|
231
271
|
if (this.#state === "error") {
|
|
232
|
-
return new Text(theme.fg("error", sanitizeErrorLine(this.#errorMessage ?? "Unknown error")), 0, 0);
|
|
272
|
+
return [new Text(theme.fg("error", sanitizeErrorLine(this.#errorMessage ?? "Unknown error")), 0, 0)];
|
|
233
273
|
}
|
|
234
274
|
const text = this.#visibleAnswer;
|
|
235
275
|
if (!text) {
|
|
236
276
|
const waiting =
|
|
237
277
|
this.#state === "running" ? `${theme.status.pending} Waiting for response…` : "No text returned.";
|
|
238
|
-
return new Text(theme.fg("dim", waiting), 0, 0);
|
|
278
|
+
return [new Text(theme.fg("dim", waiting), 0, 0)];
|
|
239
279
|
}
|
|
240
|
-
|
|
280
|
+
const parts = this.#injectParts();
|
|
281
|
+
return [parts ? new BtwInjectAnswer(parts, this.#injected) : new Markdown(text, 0, 0, getMarkdownTheme())];
|
|
241
282
|
}
|
|
242
283
|
}
|
|
@@ -23,7 +23,7 @@ import type { Component } from "../../tui";
|
|
|
23
23
|
import { col, keyed, node, span, text } from "../../native/describe";
|
|
24
24
|
import { Memo } from "../../native/memo";
|
|
25
25
|
import type { DescribeContext, NativeNode, NativeScroll, NativeUiEvent } from "../../native/node";
|
|
26
|
-
import { actionBar, actionButton } from "../../native/overlay";
|
|
26
|
+
import { actionBar, actionButton, iconButton } from "../../native/overlay";
|
|
27
27
|
import { CLOSE_ACTION, type PickerEvent, picker, pickerAction, pickerEvent } from "../../native/picker";
|
|
28
28
|
import { type KeyId, matchesKey } from "../../keys";
|
|
29
29
|
import { parseSgrMouse } from "../../mouse";
|
|
@@ -711,13 +711,12 @@ export class ExtensionDashboard implements Component {
|
|
|
711
711
|
text(DASHBOARD_TITLE, { role: "zeta.app.title" }),
|
|
712
712
|
text([span(query ? `${shown} of ${total}` : `${total} extensions`, "muted")], { truncate: "end" }),
|
|
713
713
|
]),
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
aria: "Close",
|
|
719
|
-
|
|
720
|
-
}),
|
|
714
|
+
iconButton(
|
|
715
|
+
"x",
|
|
716
|
+
"close",
|
|
717
|
+
`Close ${formatTooltipKey(boundKeys("app.interrupt", ["escape"])[0] ?? "escape")}`,
|
|
718
|
+
{ aria: "Close" },
|
|
719
|
+
),
|
|
721
720
|
],
|
|
722
721
|
"head",
|
|
723
722
|
);
|
|
@@ -407,6 +407,12 @@ export class HookEditorComponent extends OverlayPanel implements Focusable {
|
|
|
407
407
|
else this.#editor.pasteText(text);
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
+
/** Replace the draft, as Ctrl+R history search does for the main composer. */
|
|
411
|
+
setText(text: string): void {
|
|
412
|
+
if (this.#disposed) return;
|
|
413
|
+
this.#editor.setText(text);
|
|
414
|
+
}
|
|
415
|
+
|
|
410
416
|
/**
|
|
411
417
|
* Prompt-style: raw Enter submits; Editor owns newline-producing sequences.
|
|
412
418
|
* The follow-up chord (`app.message.followUp` → Ctrl+Q / Ctrl+Enter) also
|