durable-chat 1.0.0 → 1.0.2
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 +95 -17
- package/dist/config.js +10 -1
- package/dist/jobs.js +34 -1
- package/dist/tool.js +5 -27
- package/dist/tui/app.js +294 -165
- package/dist/tui/clipboard.js +78 -0
- package/dist/tui/composer.js +53 -0
- package/dist/tui/format.js +40 -16
- package/dist/tui/markdown-copy.js +97 -0
- package/dist/tui/selection.js +44 -4
- package/dist/tui/transcript.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import childProcess from "node:child_process";
|
|
3
|
+
import { getNativeClipboard } from "@earendil-works/pi-tui";
|
|
4
|
+
function pbcopy(text, env) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const child = childProcess.spawn("/usr/bin/pbcopy", [], {
|
|
7
|
+
shell: false,
|
|
8
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
9
|
+
timeout: 3000,
|
|
10
|
+
// pbcopy decodes stdin using the locale, not necessarily UTF-8 by default.
|
|
11
|
+
env: { ...env, LC_ALL: "en_US.UTF-8" },
|
|
12
|
+
});
|
|
13
|
+
let inputError;
|
|
14
|
+
child.on("error", reject);
|
|
15
|
+
child.stdin.on("error", (error) => { inputError = error; });
|
|
16
|
+
child.on("close", (code, signal) => {
|
|
17
|
+
if (code === 0 && !signal && !inputError)
|
|
18
|
+
resolve();
|
|
19
|
+
else
|
|
20
|
+
reject(inputError ?? new Error("pbcopy failed"));
|
|
21
|
+
});
|
|
22
|
+
// Transcript content is only stdin data: never shell source or process arguments.
|
|
23
|
+
child.stdin.end(text, "utf8");
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Shared by transcript selection and keyboard answer copy. Never reads the clipboard. */
|
|
27
|
+
export function createTextCopier(options = {}) {
|
|
28
|
+
const copy = async (text) => {
|
|
29
|
+
const env = options.env ?? process.env;
|
|
30
|
+
const platform = options.platform ?? process.platform;
|
|
31
|
+
const remote = Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY);
|
|
32
|
+
try {
|
|
33
|
+
if (!(options.isTTY ?? process.stdout.isTTY))
|
|
34
|
+
return "Copy unavailable: no terminal clipboard transport.";
|
|
35
|
+
// Local tmux still shares the Mac pasteboard. Over SSH, native helpers would
|
|
36
|
+
// write to the remote host instead of the terminal user's clipboard.
|
|
37
|
+
if (platform === "darwin" && !remote) {
|
|
38
|
+
try {
|
|
39
|
+
const clipboard = (options.nativeClipboard ?? getNativeClipboard)();
|
|
40
|
+
if (clipboard?.setText) {
|
|
41
|
+
await clipboard.setText(text);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch { /* Fall back when the optional native helper cannot load or write. */ }
|
|
46
|
+
await pbcopy(text, env);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (env.TERM_PROGRAM === "Apple_Terminal")
|
|
50
|
+
return "Copy unavailable: Apple Terminal does not support OSC 52. Use native terminal selection.";
|
|
51
|
+
let sequence = `\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`;
|
|
52
|
+
if (env.TMUX)
|
|
53
|
+
sequence = `\x1bPtmux;${sequence.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
|
|
54
|
+
await (options.write ?? ((data) => new Promise((resolve, reject) => {
|
|
55
|
+
process.stdout.write(data, (error) => error ? reject(error) : resolve());
|
|
56
|
+
})))(sequence);
|
|
57
|
+
return { status: "sent" };
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return "Copy failed: clipboard transport unavailable.";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Selection and keyboard copies share this queue. Keep native writes and their
|
|
64
|
+
// fallback together so an older completion cannot overwrite a newer request.
|
|
65
|
+
let pending = Promise.resolve();
|
|
66
|
+
return (text) => {
|
|
67
|
+
const result = pending.then(() => copy(text));
|
|
68
|
+
pending = result.then(() => undefined, () => undefined);
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function copyNotice(result) {
|
|
73
|
+
if (result === true)
|
|
74
|
+
return { text: "copied to clipboard", kind: "info" };
|
|
75
|
+
if (typeof result === "object")
|
|
76
|
+
return { text: "Copy sent via OSC 52 (unconfirmed)", kind: "info" };
|
|
77
|
+
return { text: typeof result === "string" ? result : "Copy failed", kind: "error" };
|
|
78
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CURSOR_MARKER, Editor, matchesKey } from "@earendil-works/pi-tui";
|
|
2
|
+
import { dim } from "./format.js";
|
|
3
|
+
/** Newline gestures must be checked before Enter: legacy Ctrl-J also matches Enter. */
|
|
4
|
+
export function isComposerNewline(data) {
|
|
5
|
+
return matchesKey(data, "ctrl+j") || matchesKey(data, "shift+enter")
|
|
6
|
+
|| matchesKey(data, "alt+enter") || data === "\x1b\r" || data === "\x1b[13;2~";
|
|
7
|
+
}
|
|
8
|
+
/** Command/Super+Shift+Enter is one-shot follow-up, only when CSI-u reports it.
|
|
9
|
+
* xterm modifyOtherKeys has no distinct Super modifier (its bit 8 is Meta).
|
|
10
|
+
*/
|
|
11
|
+
export function isComposerQueue(data) {
|
|
12
|
+
return data.endsWith("u") && matchesKey(data, "super+shift+enter");
|
|
13
|
+
}
|
|
14
|
+
/** Toolkit editing/paste/undo semantics, embedded in the dashboard's own layout. */
|
|
15
|
+
export class Composer extends Editor {
|
|
16
|
+
constructor(rows, requestRender) {
|
|
17
|
+
// Editor only uses these two host services (no terminal IO or overlays).
|
|
18
|
+
// The dashboard, rather than a second TUI renderer, owns focus and layout.
|
|
19
|
+
const host = { terminal: { get rows() { return rows(); } }, requestRender };
|
|
20
|
+
super(host, {
|
|
21
|
+
borderColor: dim,
|
|
22
|
+
selectList: { selectedPrefix: dim, selectedText: dim, description: dim, scrollInfo: dim, noMatch: dim },
|
|
23
|
+
});
|
|
24
|
+
// Dashboard owns submission/validation, including preserving outer newlines.
|
|
25
|
+
this.disableSubmit = true;
|
|
26
|
+
}
|
|
27
|
+
getValue() { return this.getExpandedText(); }
|
|
28
|
+
setValue(value) { this.setText(value); }
|
|
29
|
+
renderTopBorder(width, hidden) {
|
|
30
|
+
return hidden > 0 ? super.renderTopBorder(width, hidden) : "";
|
|
31
|
+
}
|
|
32
|
+
renderBottomBorder(width, hidden) {
|
|
33
|
+
return hidden > 0 ? super.renderBottomBorder(width, hidden) : "";
|
|
34
|
+
}
|
|
35
|
+
render(width, maxContentRows = Number.POSITIVE_INFINITY) {
|
|
36
|
+
// The toolkit scrolls at 30% of terminal height but has a five-line minimum.
|
|
37
|
+
// On short terminals crop that viewport around the cursor so panes still fit.
|
|
38
|
+
const focused = this.focused;
|
|
39
|
+
this.focused = true;
|
|
40
|
+
const lines = super.render(width);
|
|
41
|
+
this.focused = focused;
|
|
42
|
+
const content = lines.slice(1, -1);
|
|
43
|
+
const count = Math.max(1, Math.min(content.length, maxContentRows));
|
|
44
|
+
const cursor = Math.max(0, content.findIndex((line) => line.includes(CURSOR_MARKER)));
|
|
45
|
+
const start = Math.max(0, Math.min(cursor - count + 1, content.length - count));
|
|
46
|
+
const result = [
|
|
47
|
+
start > 0 ? super.renderTopBorder(width, start) : lines[0],
|
|
48
|
+
...content.slice(start, start + count),
|
|
49
|
+
start + count < content.length ? super.renderBottomBorder(width, content.length - start - count) : lines.at(-1),
|
|
50
|
+
];
|
|
51
|
+
return focused ? result : result.map((line) => line.replaceAll(CURSOR_MARKER, ""));
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/tui/format.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { isAbsolute, relative, sep } from "node:path";
|
|
3
|
-
import { backgroundAnsi, indexedColor,
|
|
3
|
+
import { backgroundAnsi, indexedColor, styleText, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
4
4
|
import { formatDuration } from "../format.js";
|
|
5
|
+
import { renderCopyableMarkdown } from "./markdown-copy.js";
|
|
5
6
|
/** Display paths beneath home with `~`, keeping sibling directories and other roots absolute. */
|
|
6
7
|
export function shortenHome(path, home = homedir()) {
|
|
7
8
|
const suffix = relative(home, path);
|
|
@@ -73,6 +74,9 @@ function blockText(content) {
|
|
|
73
74
|
}).join("\n");
|
|
74
75
|
}
|
|
75
76
|
const TRANSCRIPT_MARKDOWN_THEME = {
|
|
77
|
+
// The transcript already has a speaker gutter; don't add the toolkit's two
|
|
78
|
+
// decorative code columns on top of source indentation (or copy them out).
|
|
79
|
+
codeBlockIndent: "",
|
|
76
80
|
heading: (text) => fg(text, TEXT),
|
|
77
81
|
link: (text) => fg(text, ACCENT),
|
|
78
82
|
linkUrl: dim,
|
|
@@ -88,20 +92,34 @@ const TRANSCRIPT_MARKDOWN_THEME = {
|
|
|
88
92
|
strikethrough: (text) => styleText(text, { strikethrough: true }, MODE),
|
|
89
93
|
underline: (text) => styleText(text, { underline: true }, MODE),
|
|
90
94
|
};
|
|
95
|
+
export function transcriptLine(text, copyStart = 0) {
|
|
96
|
+
return { text, copyStart, copyEnd: visibleWidth(stripTerminalSequences(text).replace(/ +$/u, "")) };
|
|
97
|
+
}
|
|
91
98
|
function prefixLines(text, prefix, width, color) {
|
|
92
99
|
const inner = Math.max(1, width - visibleWidth(prefix));
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const pad = " ".repeat(
|
|
97
|
-
return lines.map((line, index) =>
|
|
100
|
+
const rendered = renderCopyableMarkdown(text, inner, TRANSCRIPT_MARKDOWN_THEME, { color: (value) => fg(value, color) });
|
|
101
|
+
const lines = rendered.length === 0 ? [{ text: "" }] : rendered;
|
|
102
|
+
const gutter = visibleWidth(prefix);
|
|
103
|
+
const pad = " ".repeat(gutter);
|
|
104
|
+
return lines.map((line, index) => {
|
|
105
|
+
const row = transcriptLine(fg(index === 0 ? prefix : pad, color) + line.text,
|
|
106
|
+
// Keep visible speaker labels, but not the blank continuation gutter.
|
|
107
|
+
index === 0 && prefix.trim() !== "" ? prefix.length - prefix.trimStart().length : gutter);
|
|
108
|
+
if (line.copyStart !== undefined && line.copyEnd !== undefined) {
|
|
109
|
+
row.code = line.code;
|
|
110
|
+
row.copyStart = gutter + line.copyStart;
|
|
111
|
+
row.copyEnd = gutter + line.copyEnd;
|
|
112
|
+
}
|
|
113
|
+
row.copySkip = line.copySkip;
|
|
114
|
+
return row;
|
|
115
|
+
});
|
|
98
116
|
}
|
|
99
117
|
function rule(label, width) {
|
|
100
118
|
const text = `── ${label} `;
|
|
101
119
|
return fg(truncateToWidth(text, width, ""), BORDER);
|
|
102
120
|
}
|
|
103
121
|
function ruleWithText(label, body, width, color = MUTED) {
|
|
104
|
-
const lines = [rule(label, width)];
|
|
122
|
+
const lines = [transcriptLine(rule(label, width))];
|
|
105
123
|
if (body.trim().length > 0)
|
|
106
124
|
lines.push(...prefixLines(body.trimEnd(), " ", width, color));
|
|
107
125
|
return lines;
|
|
@@ -113,23 +131,26 @@ function toolResultLines(message, width, expanded) {
|
|
|
113
131
|
const body = blockText(message.content).replace(/\s+/g, " ").trim();
|
|
114
132
|
const summary = body.length > 140 ? `${body.slice(0, 139)}…` : body;
|
|
115
133
|
const head = fg(` ↳ ${mark} ${name}${ms}`, message.isError === true ? RED : GREEN);
|
|
116
|
-
const lines = [truncateToWidth(`${head}${summary.length === 0 ? "" : dim(` ${summary}`)}`, width, "")];
|
|
134
|
+
const lines = [transcriptLine(truncateToWidth(`${head}${summary.length === 0 ? "" : dim(` ${summary}`)}`, width, ""), 6)];
|
|
117
135
|
if (expanded) {
|
|
118
136
|
const indent = " ".repeat(Math.min(10, width - 1));
|
|
119
137
|
const full = blockText(message.content).trimEnd();
|
|
120
138
|
const shown = full.split("\n").slice(0, 12);
|
|
121
139
|
for (const line of shown) {
|
|
122
140
|
for (const wrapped of wrapTextWithAnsi(line, width - indent.length)) {
|
|
123
|
-
lines.push(dim(`${indent}${wrapped}`));
|
|
141
|
+
lines.push(transcriptLine(dim(`${indent}${wrapped}`), indent.length));
|
|
124
142
|
}
|
|
125
143
|
}
|
|
126
144
|
if (full.split("\n").length > shown.length)
|
|
127
|
-
lines.push(dim(`${indent}…`));
|
|
145
|
+
lines.push(transcriptLine(dim(`${indent}…`), indent.length));
|
|
128
146
|
}
|
|
129
147
|
return lines;
|
|
130
148
|
}
|
|
131
149
|
/** One immutable transcript entry to display lines. */
|
|
132
150
|
export function formatEntry(entry, options) {
|
|
151
|
+
return formatEntryLines(entry, options).map((line) => line.text);
|
|
152
|
+
}
|
|
153
|
+
export function formatEntryLines(entry, options) {
|
|
133
154
|
const width = Math.max(8, options.width);
|
|
134
155
|
const messages = (entry.model ?? []);
|
|
135
156
|
if (entry.kind === "pi.user") {
|
|
@@ -142,7 +163,7 @@ export function formatEntry(entry, options) {
|
|
|
142
163
|
if (text.length > 0)
|
|
143
164
|
lines.push(...prefixLines(text, " ai ", width, GREEN));
|
|
144
165
|
if (message.stopReason === "aborted" && text.length === 0)
|
|
145
|
-
lines.push(fg(" [aborted attempt]", MUTED, { dim: true }));
|
|
166
|
+
lines.push(transcriptLine(fg(" [aborted attempt]", MUTED, { dim: true }), 6));
|
|
146
167
|
}
|
|
147
168
|
return lines;
|
|
148
169
|
}
|
|
@@ -158,7 +179,7 @@ export function formatEntry(entry, options) {
|
|
|
158
179
|
return ruleWithText("compacted context", options.toolsExpanded ? summary : "summary retained in history", width, MUTED);
|
|
159
180
|
}
|
|
160
181
|
if (entry.kind === "pi.system") {
|
|
161
|
-
return options.showSystem === true ? [dim(truncateToWidth("── system prompt updated", width, ""))] : [];
|
|
182
|
+
return options.showSystem === true ? [transcriptLine(dim(truncateToWidth("── system prompt updated", width, "")))] : [];
|
|
162
183
|
}
|
|
163
184
|
if (entry.kind === "app.job-handoff") {
|
|
164
185
|
const data = entry.data;
|
|
@@ -170,15 +191,18 @@ export function formatEntry(entry, options) {
|
|
|
170
191
|
const body = messages.map((message) => blockText(message.content)).join(" ").replace(/^\[host\]\s*/, "").trim();
|
|
171
192
|
const lines = ruleWithText(`host · job #${data?.taskId ?? "?"} ${data?.phase ?? "notice"}`, body, width, MUTED);
|
|
172
193
|
if (body.length > 0)
|
|
173
|
-
lines.splice(1, 0, "");
|
|
194
|
+
lines.splice(1, 0, transcriptLine(""));
|
|
174
195
|
return lines;
|
|
175
196
|
}
|
|
176
197
|
if (entry.kind.startsWith("app."))
|
|
177
198
|
return [];
|
|
178
|
-
return options.showSystem === true ? [dim(truncateToWidth(`── ${entry.kind}`, width, ""))] : [];
|
|
199
|
+
return options.showSystem === true ? [transcriptLine(dim(truncateToWidth(`── ${entry.kind}`, width, "")))] : [];
|
|
179
200
|
}
|
|
180
201
|
/** Streaming partial answer and tool slots below the committed transcript. */
|
|
181
202
|
export function formatLive(live, width) {
|
|
203
|
+
return formatLiveLines(live, width).map((line) => line.text);
|
|
204
|
+
}
|
|
205
|
+
export function formatLiveLines(live, width) {
|
|
182
206
|
if (live === undefined)
|
|
183
207
|
return [];
|
|
184
208
|
const lines = [];
|
|
@@ -189,11 +213,11 @@ export function formatLive(live, width) {
|
|
|
189
213
|
const active = (live.tools ?? []).filter((slot) => slot.status !== "done").slice(0, 8);
|
|
190
214
|
for (const slot of active) {
|
|
191
215
|
const status = slot.status ?? "pending";
|
|
192
|
-
lines.push(fg(` ${status === "running" ? "▸" : "·"} ${slot.name ?? "tool"} ${status}`, YELLOW));
|
|
216
|
+
lines.push(transcriptLine(fg(` ${status === "running" ? "▸" : "·"} ${slot.name ?? "tool"} ${status}`, YELLOW), 2));
|
|
193
217
|
}
|
|
194
218
|
if (live.runFailure !== undefined) {
|
|
195
219
|
const detail = live.runFailure.detail === undefined ? "" : `: ${live.runFailure.detail}`;
|
|
196
|
-
lines.push(fg(` run failed: ${live.runFailure.reason ?? "unknown"}${detail}`, RED));
|
|
220
|
+
lines.push(transcriptLine(fg(` run failed: ${live.runFailure.reason ?? "unknown"}${detail}`, RED), 2));
|
|
197
221
|
}
|
|
198
222
|
return lines;
|
|
199
223
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Markdown, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
const osc8 = /\x1b\]8;[^;\x1b\x07]*;([^\x1b\x07]*)(?:\x1b\\|\x07)/g;
|
|
4
|
+
/**
|
|
5
|
+
* Theme callbacks identify actual code, not characters that happen to look like rails.
|
|
6
|
+
* OSC 8 annotations survive the toolkit's nested wrapping (including quotes/lists).
|
|
7
|
+
* Real OSC 8 events inside them travel as opaque APC markers: otherwise a real link
|
|
8
|
+
* would replace the annotation in the toolkit's single (NOT stacked) hyperlink state,
|
|
9
|
+
* and its empty close would be indistinguishable from the annotation's close.
|
|
10
|
+
* Both transports are consumed BEFORE rows reach display or link hit testing.
|
|
11
|
+
*/
|
|
12
|
+
export function renderCopyableMarkdown(text, width, theme, style) {
|
|
13
|
+
// No user-authored URL or control sequence can be mistaken for this render's metadata.
|
|
14
|
+
let namespace;
|
|
15
|
+
do {
|
|
16
|
+
namespace = `dchat-internal-code:${randomUUID()}:`;
|
|
17
|
+
} while (text.includes(namespace));
|
|
18
|
+
const sources = [];
|
|
19
|
+
const annotations = new Map();
|
|
20
|
+
const links = new Map();
|
|
21
|
+
const annotate = (value, rendered, border = false) => {
|
|
22
|
+
const id = sources.push({ text: stripTerminalSequences(value), border }) - 1;
|
|
23
|
+
const url = `${namespace}${id}`;
|
|
24
|
+
annotations.set(url, id);
|
|
25
|
+
const shielded = rendered.replace(osc8, (sequence, url) => {
|
|
26
|
+
const marker = `\x1b_${namespace}link:${links.size}\x1b\\`;
|
|
27
|
+
links.set(marker, { sequence, close: url ? `\x1b]8;;${sequence.endsWith("\x07") ? "\x07" : "\x1b\\"}` : undefined });
|
|
28
|
+
return marker;
|
|
29
|
+
});
|
|
30
|
+
return `\x1b]8;;${url}\x1b\\${shielded}\x1b]8;;\x1b\\`;
|
|
31
|
+
};
|
|
32
|
+
const markdown = new Markdown(text, 0, 0, {
|
|
33
|
+
...theme,
|
|
34
|
+
codeBlock: (value) => annotate(value, theme.codeBlock(value)),
|
|
35
|
+
codeBlockBorder: (value) => annotate(value, theme.codeBlockBorder(value), true),
|
|
36
|
+
}, style, { renderLatex: false });
|
|
37
|
+
let previous;
|
|
38
|
+
let link;
|
|
39
|
+
return markdown.render(width).map((line) => {
|
|
40
|
+
let code;
|
|
41
|
+
let copyStart;
|
|
42
|
+
let copyEnd;
|
|
43
|
+
let copySkip = false;
|
|
44
|
+
let active;
|
|
45
|
+
let cleaned = "";
|
|
46
|
+
let cursor = 0;
|
|
47
|
+
for (const match of line.matchAll(/\x1b(?:\]8;[^;\x1b\x07]*;([^\x1b\x07]*)|_[^\x1b\x07]*)(?:\x1b\\|\x07)/g)) {
|
|
48
|
+
cleaned += line.slice(cursor, match.index);
|
|
49
|
+
const id = annotations.get(match[1]);
|
|
50
|
+
const original = links.get(match[0]);
|
|
51
|
+
if (id !== undefined) {
|
|
52
|
+
active = { id, column: visibleWidth(cleaned), offset: cleaned.length };
|
|
53
|
+
if (previous?.id !== id)
|
|
54
|
+
link = undefined;
|
|
55
|
+
// Reopen only inside code bounds, never over the quote/list rail.
|
|
56
|
+
if (link)
|
|
57
|
+
cleaned += link.sequence;
|
|
58
|
+
}
|
|
59
|
+
else if (active && original) {
|
|
60
|
+
cleaned += original.sequence;
|
|
61
|
+
link = original.close ? { sequence: original.sequence, close: original.close } : undefined;
|
|
62
|
+
}
|
|
63
|
+
else if (active && match[1] === "") {
|
|
64
|
+
const source = sources[active.id];
|
|
65
|
+
const fragment = stripTerminalSequences(cleaned.slice(active.offset));
|
|
66
|
+
const continues = previous?.id === active.id;
|
|
67
|
+
const start = source.text.indexOf(fragment, continues ? previous.end : 0);
|
|
68
|
+
if (source.border)
|
|
69
|
+
copySkip = true;
|
|
70
|
+
else {
|
|
71
|
+
copyStart = active.column;
|
|
72
|
+
copyEnd = copyStart + visibleWidth(fragment);
|
|
73
|
+
// If the toolkit transforms a fragment unexpectedly, retain code-only
|
|
74
|
+
// bounds but fall back to rendered rows instead of guessing a source range.
|
|
75
|
+
if (start >= 0)
|
|
76
|
+
code = { source: source.text, start, end: start + fragment.length, continues };
|
|
77
|
+
}
|
|
78
|
+
previous = source.border || start < 0 ? undefined : { id: active.id, end: start + fragment.length };
|
|
79
|
+
// The toolkit closed the annotation, not the shielded user hyperlink.
|
|
80
|
+
// Balance the latter on each physical row; retain its logical state for wraps.
|
|
81
|
+
if (link)
|
|
82
|
+
cleaned += link.close;
|
|
83
|
+
active = undefined;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
cleaned += match[0];
|
|
87
|
+
}
|
|
88
|
+
cursor = match.index + match[0].length;
|
|
89
|
+
}
|
|
90
|
+
cleaned += line.slice(cursor);
|
|
91
|
+
if (!code) {
|
|
92
|
+
previous = undefined;
|
|
93
|
+
link = undefined;
|
|
94
|
+
}
|
|
95
|
+
return { text: cleaned, code, copyStart, copyEnd, copySkip };
|
|
96
|
+
});
|
|
97
|
+
}
|
package/dist/tui/selection.js
CHANGED
|
@@ -28,7 +28,14 @@ export class TranscriptSelection {
|
|
|
28
28
|
update(frame) {
|
|
29
29
|
const old = this.frame;
|
|
30
30
|
if (!old || !frame || old.source !== frame.source || old.x !== frame.x || old.y !== frame.y || old.width !== frame.width
|
|
31
|
-
|| old.lines.length !== frame.lines.length || old.lines.some((line, index) => line !== frame.lines[index])
|
|
31
|
+
|| old.lines.length !== frame.lines.length || old.lines.some((line, index) => line !== frame.lines[index])
|
|
32
|
+
|| old.copyBounds.length !== frame.copyBounds.length
|
|
33
|
+
|| old.copyBounds.some((bounds, index) => {
|
|
34
|
+
const next = frame.copyBounds[index];
|
|
35
|
+
return bounds.copyStart !== next?.copyStart || bounds.copyEnd !== next?.copyEnd || bounds.copySkip !== next?.copySkip
|
|
36
|
+
|| bounds.code?.source !== next?.code?.source || bounds.code?.start !== next?.code?.start
|
|
37
|
+
|| bounds.code?.end !== next?.code?.end || bounds.code?.continues !== next?.code?.continues;
|
|
38
|
+
}))
|
|
32
39
|
this.reset();
|
|
33
40
|
this.frame = frame;
|
|
34
41
|
}
|
|
@@ -70,10 +77,43 @@ export class TranscriptSelection {
|
|
|
70
77
|
}) ?? [];
|
|
71
78
|
}
|
|
72
79
|
async copySelection() {
|
|
73
|
-
|
|
80
|
+
let text = "";
|
|
81
|
+
let selectedRows = 0;
|
|
82
|
+
let previousCodeEnd;
|
|
83
|
+
for (const [row, line] of this.frame.lines.entries()) {
|
|
74
84
|
const columns = this.columns(row);
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
if (!columns)
|
|
86
|
+
continue;
|
|
87
|
+
const bounds = this.frame.copyBounds[row];
|
|
88
|
+
if (bounds?.copySkip) {
|
|
89
|
+
previousCodeEnd = undefined;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const start = Math.max(bounds?.copyStart ?? 0, Math.min(columns.start, bounds?.copyEnd ?? 0));
|
|
93
|
+
const end = Math.max(start, Math.min(columns.end, bounds?.copyEnd ?? 0));
|
|
94
|
+
const fragment = stripTerminalSequences(sliceByColumn(line, start, end - start));
|
|
95
|
+
const code = bounds?.code;
|
|
96
|
+
if (code) {
|
|
97
|
+
const offset = stripTerminalSequences(sliceByColumn(line, bounds.copyStart, start - bounds.copyStart)).length;
|
|
98
|
+
const sourceStart = code.start + offset;
|
|
99
|
+
const sourceEnd = sourceStart + fragment.length;
|
|
100
|
+
// Only semantic continuations join. Restore whitespace dropped by word wrapping
|
|
101
|
+
// from the toolkit's code source, never by guessing from rail characters.
|
|
102
|
+
if (code.continues && previousCodeEnd !== undefined)
|
|
103
|
+
text += code.source.slice(previousCodeEnd, sourceStart);
|
|
104
|
+
else if (selectedRows > 0)
|
|
105
|
+
text += "\n";
|
|
106
|
+
text += code.source.slice(sourceStart, sourceEnd);
|
|
107
|
+
previousCodeEnd = sourceEnd;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (selectedRows > 0)
|
|
111
|
+
text += "\n";
|
|
112
|
+
text += fragment;
|
|
113
|
+
previousCodeEnd = undefined;
|
|
114
|
+
}
|
|
115
|
+
selectedRows++;
|
|
116
|
+
}
|
|
77
117
|
if (!text)
|
|
78
118
|
return;
|
|
79
119
|
const version = this.version;
|
package/dist/tui/transcript.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatEntryLines, formatLiveLines, transcriptLine } from "./format.js";
|
|
2
2
|
import { estimateContextTokens } from "../context-usage.js";
|
|
3
3
|
const INITIAL_ENTRIES = 80;
|
|
4
4
|
const OLDER_ENTRIES = 60;
|
|
@@ -124,16 +124,16 @@ export class Transcript {
|
|
|
124
124
|
}
|
|
125
125
|
const lines = [];
|
|
126
126
|
for (const entry of this.entries) {
|
|
127
|
-
const formatted =
|
|
127
|
+
const formatted = formatEntryLines(entry, { width, toolsExpanded });
|
|
128
128
|
if (formatted.length > 0) {
|
|
129
|
-
lines.push(...formatted, "");
|
|
129
|
+
lines.push(...formatted, transcriptLine(""));
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
this.cache = { version: this.version, width, tools: toolsExpanded, lines };
|
|
133
133
|
return lines;
|
|
134
134
|
}
|
|
135
135
|
liveLines(width) {
|
|
136
|
-
return
|
|
136
|
+
return formatLiveLines(this.live, width);
|
|
137
137
|
}
|
|
138
138
|
get modelCount() {
|
|
139
139
|
const usage = this.usage;
|
package/package.json
CHANGED