@narumitw/pi-btw 0.63.3 → 0.63.5

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.
@@ -0,0 +1,328 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ showBtwCustomPreservingEditor
5
+ } from "./chunk-TPDBHPLD.ts";
6
+ import "./chunk-E4LBFYRH.ts";
7
+ import {
8
+ sanitizeSingleLine
9
+ } from "./chunk-FWW662MW.ts";
10
+
11
+ // src/main-tree-picker.ts
12
+ import {
13
+ copyToClipboard,
14
+ TreeSelectorComponent
15
+ } from "@earendil-works/pi-coding-agent";
16
+ import { Key, matchesKey } from "@earendil-works/pi-tui";
17
+ var MainThreadTreePickerComponent = class {
18
+ constructor(selector, onClose) {
19
+ this.selector = selector;
20
+ this.onClose = onClose;
21
+ }
22
+ selector;
23
+ onClose;
24
+ get focused() {
25
+ return this.selector.focused;
26
+ }
27
+ set focused(value) {
28
+ this.selector.focused = value;
29
+ }
30
+ get wantsKeyRelease() {
31
+ return this.selector.wantsKeyRelease;
32
+ }
33
+ render(width) {
34
+ return this.selector.render(width);
35
+ }
36
+ handleInput(data) {
37
+ if (matchesKey(data, Key.ctrl("c"))) {
38
+ this.onClose();
39
+ return;
40
+ }
41
+ this.selector.handleInput?.(data);
42
+ }
43
+ invalidate() {
44
+ this.selector.invalidate();
45
+ }
46
+ dispose() {
47
+ this.selector.dispose?.();
48
+ this.onClose();
49
+ }
50
+ };
51
+ async function pickMainEntry(pi, ctx, dependencies = {}) {
52
+ let rawTree;
53
+ let currentLeafId;
54
+ try {
55
+ rawTree = ctx.sessionManager.getTree();
56
+ currentLeafId = ctx.sessionManager.getLeafId();
57
+ } catch {
58
+ return { kind: "closed" };
59
+ }
60
+ if (rawTree.length === 0) {
61
+ notifySafely(ctx, "No main-thread entries are available", "warning");
62
+ return { kind: "back" };
63
+ }
64
+ const tree = sanitizeTreeForDisplay(rawTree);
65
+ const rawCopyText = collectRawCopyText(rawTree);
66
+ const savedLabels = collectSavedLabels(rawTree);
67
+ const createSelector = dependencies.createSelector ?? createNativeTreeSelector;
68
+ const copy = dependencies.copyToClipboard ?? copyText;
69
+ const copyControllers = /* @__PURE__ */ new Set();
70
+ const copyTasks = /* @__PURE__ */ new Set();
71
+ const abortCopies = () => {
72
+ for (const controller of copyControllers) {
73
+ controller.abort(new Error("The main-thread tree picker closed"));
74
+ }
75
+ };
76
+ const result = await showBtwCustomPreservingEditor(ctx, (tui, _theme, _keybindings, done) => {
77
+ let settled = false;
78
+ let selector;
79
+ const finish = (value) => {
80
+ if (settled) return;
81
+ settled = true;
82
+ abortCopies();
83
+ done(value);
84
+ };
85
+ const onCopy = (entryId, displayText) => {
86
+ if (settled) return;
87
+ const text = entryId ? rawCopyText.get(entryId) : displayText;
88
+ if (!text) {
89
+ notifySafely(ctx, "Selected entry has no text to copy", "warning");
90
+ return;
91
+ }
92
+ const controller = new AbortController();
93
+ copyControllers.add(controller);
94
+ let operation;
95
+ try {
96
+ operation = copy(text, controller.signal);
97
+ } catch (error) {
98
+ operation = Promise.reject(error);
99
+ }
100
+ let task;
101
+ task = operation.then(() => {
102
+ if (!settled) notifySafely(ctx, "Copied selected message", "info");
103
+ }).catch((error) => {
104
+ if (!settled && !controller.signal.aborted) {
105
+ notifySafely(ctx, `Could not copy selected message: ${formatError(error)}`, "error");
106
+ }
107
+ }).finally(() => {
108
+ copyControllers.delete(controller);
109
+ copyTasks.delete(task);
110
+ });
111
+ copyTasks.add(task);
112
+ };
113
+ const restoreLabel = (entryId) => {
114
+ const previous = savedLabels.get(entryId);
115
+ selector?.setViewLabel?.(entryId, previous?.label, previous?.labelTimestamp);
116
+ tui.requestRender();
117
+ };
118
+ const onLabelChange = (entryId, label) => {
119
+ if (settled) return;
120
+ try {
121
+ if (!ctx.sessionManager.getEntry(entryId)) {
122
+ restoreLabel(entryId);
123
+ notifySafely(ctx, "The selected main-thread entry is no longer available", "warning");
124
+ return;
125
+ }
126
+ const persistedLabel = label === void 0 ? void 0 : sanitizeSingleLine(label);
127
+ pi.setLabel(entryId, persistedLabel);
128
+ savedLabels.set(entryId, { label: persistedLabel });
129
+ selector?.setViewLabel?.(entryId, persistedLabel);
130
+ tui.requestRender();
131
+ } catch (error) {
132
+ restoreLabel(entryId);
133
+ notifySafely(ctx, `Could not update tree label: ${formatError(error)}`, "error");
134
+ }
135
+ };
136
+ selector = createSelector({
137
+ tree,
138
+ currentLeafId,
139
+ terminalRows: tui.terminal.rows,
140
+ onSelect: (entryId) => finish({ kind: "selected", entryId }),
141
+ onCancel: () => finish({ kind: "back" }),
142
+ onCopy,
143
+ onLabelChange
144
+ });
145
+ return new MainThreadTreePickerComponent(selector, () => finish({ kind: "closed" }));
146
+ });
147
+ abortCopies();
148
+ await Promise.allSettled([...copyTasks]);
149
+ return result ?? { kind: "closed" };
150
+ }
151
+ function createNativeTreeSelector(options) {
152
+ const selector = new TreeSelectorComponent(
153
+ options.tree,
154
+ options.currentLeafId,
155
+ options.terminalRows,
156
+ options.onSelect,
157
+ options.onCancel,
158
+ options.onLabelChange
159
+ );
160
+ selector.onCopy = (displayText) => options.onCopy(selector.getTreeList().getSelectedNode()?.entry.id, displayText);
161
+ const result = selector;
162
+ result.setViewLabel = (entryId, label, labelTimestamp) => selector.getTreeList().updateNodeLabel(entryId, label, labelTimestamp);
163
+ return result;
164
+ }
165
+ function sanitizeTreeForDisplay(tree) {
166
+ return tree.map((node) => {
167
+ const result = {
168
+ entry: sanitizeEntryForDisplay(node.entry),
169
+ children: sanitizeTreeForDisplay(node.children)
170
+ };
171
+ if (node.label !== void 0) result.label = sanitizeSingleLine(node.label);
172
+ if (node.labelTimestamp !== void 0) {
173
+ result.labelTimestamp = sanitizeSingleLine(node.labelTimestamp);
174
+ }
175
+ return result;
176
+ });
177
+ }
178
+ function sanitizeEntryForDisplay(entry) {
179
+ switch (entry.type) {
180
+ case "message": {
181
+ const message = { ...entry.message };
182
+ if ("content" in entry.message) message.content = sanitizeDisplayContent(entry.message.content);
183
+ for (const key of ["role", "errorMessage", "command", "toolName"]) {
184
+ const value = message[key];
185
+ if (typeof value === "string") message[key] = sanitizeSingleLine(value);
186
+ }
187
+ return { ...entry, message };
188
+ }
189
+ case "custom_message":
190
+ return {
191
+ ...entry,
192
+ customType: sanitizeSingleLine(entry.customType),
193
+ content: sanitizeDisplayContent(entry.content)
194
+ };
195
+ case "compaction":
196
+ return { ...entry, summary: sanitizeSingleLine(entry.summary) };
197
+ case "branch_summary":
198
+ return { ...entry, summary: sanitizeSingleLine(entry.summary) };
199
+ case "model_change":
200
+ return {
201
+ ...entry,
202
+ provider: sanitizeSingleLine(entry.provider),
203
+ modelId: sanitizeSingleLine(entry.modelId)
204
+ };
205
+ case "thinking_level_change":
206
+ return { ...entry, thinkingLevel: sanitizeSingleLine(entry.thinkingLevel) };
207
+ case "custom":
208
+ return { ...entry, customType: sanitizeSingleLine(entry.customType) };
209
+ case "context_edit":
210
+ return { ...entry, targetId: sanitizeSingleLine(entry.targetId) };
211
+ case "label":
212
+ return {
213
+ ...entry,
214
+ label: entry.label === void 0 ? void 0 : sanitizeSingleLine(entry.label)
215
+ };
216
+ case "session_info":
217
+ return {
218
+ ...entry,
219
+ name: entry.name === void 0 ? void 0 : sanitizeSingleLine(entry.name)
220
+ };
221
+ case "usage":
222
+ return {
223
+ ...entry,
224
+ kind: sanitizeSingleLine(entry.kind),
225
+ provider: sanitizeSingleLine(entry.provider),
226
+ model: sanitizeSingleLine(entry.model),
227
+ note: entry.note === void 0 ? void 0 : sanitizeSingleLine(entry.note)
228
+ };
229
+ }
230
+ }
231
+ function sanitizeDisplayContent(content) {
232
+ if (typeof content === "string") return sanitizeSingleLine(content);
233
+ if (!Array.isArray(content)) return content;
234
+ return content.map((block) => {
235
+ if (block === null || typeof block !== "object" || !("type" in block)) return block;
236
+ if (block.type === "text" && "text" in block && typeof block.text === "string") {
237
+ return { ...block, text: sanitizeSingleLine(block.text) };
238
+ }
239
+ if (block.type === "toolCall") {
240
+ const copy = { ...block };
241
+ if (typeof copy.name === "string") copy.name = sanitizeSingleLine(copy.name);
242
+ copy.arguments = sanitizeToolArguments(copy.arguments, /* @__PURE__ */ new WeakMap());
243
+ return copy;
244
+ }
245
+ return block;
246
+ });
247
+ }
248
+ function sanitizeToolArguments(value, seen) {
249
+ if (typeof value === "string") return sanitizeSingleLine(value);
250
+ if (value === null || typeof value !== "object") return value;
251
+ const existing = seen.get(value);
252
+ if (existing !== void 0) return existing;
253
+ if (Array.isArray(value)) {
254
+ const result2 = [];
255
+ seen.set(value, result2);
256
+ for (const item of value) result2.push(sanitizeToolArguments(item, seen));
257
+ return result2;
258
+ }
259
+ const result = {};
260
+ seen.set(value, result);
261
+ for (const [key, item] of Object.entries(value)) {
262
+ result[key] = sanitizeToolArguments(item, seen);
263
+ }
264
+ return result;
265
+ }
266
+ function collectRawCopyText(tree) {
267
+ const result = /* @__PURE__ */ new Map();
268
+ const visit = (nodes) => {
269
+ for (const node of nodes) {
270
+ const text = getRawCopyText(node.entry);
271
+ if (text !== void 0) result.set(node.entry.id, text);
272
+ visit(node.children);
273
+ }
274
+ };
275
+ visit(tree);
276
+ return result;
277
+ }
278
+ function getRawCopyText(entry) {
279
+ let text;
280
+ if (entry.type === "message") {
281
+ if (entry.message.role === "bashExecution") text = entry.message.command;
282
+ else if ("content" in entry.message) {
283
+ text = extractRawText(entry.message.content);
284
+ if (!text && entry.message.role === "assistant") text = entry.message.errorMessage;
285
+ }
286
+ } else if (entry.type === "custom_message") text = extractRawText(entry.content);
287
+ else if (entry.type === "compaction" || entry.type === "branch_summary") text = entry.summary;
288
+ return text?.trim() ? text : void 0;
289
+ }
290
+ function extractRawText(content) {
291
+ if (typeof content === "string") return content;
292
+ if (!Array.isArray(content)) return "";
293
+ return content.filter(
294
+ (block) => block !== null && typeof block === "object" && "type" in block && block.type === "text" && "text" in block && typeof block.text === "string"
295
+ ).map((block) => block.text).join("");
296
+ }
297
+ function collectSavedLabels(tree) {
298
+ const result = /* @__PURE__ */ new Map();
299
+ const visit = (nodes) => {
300
+ for (const node of nodes) {
301
+ result.set(node.entry.id, {
302
+ label: node.label === void 0 ? void 0 : sanitizeSingleLine(node.label),
303
+ labelTimestamp: node.labelTimestamp === void 0 ? void 0 : sanitizeSingleLine(node.labelTimestamp)
304
+ });
305
+ visit(node.children);
306
+ }
307
+ };
308
+ visit(tree);
309
+ return result;
310
+ }
311
+ async function copyText(text, signal) {
312
+ signal.throwIfAborted();
313
+ await copyToClipboard(text);
314
+ signal.throwIfAborted();
315
+ }
316
+ function notifySafely(ctx, message, level) {
317
+ try {
318
+ ctx.ui.notify(sanitizeSingleLine(message), level);
319
+ } catch {
320
+ }
321
+ }
322
+ function formatError(error) {
323
+ return error instanceof Error ? error.message : String(error);
324
+ }
325
+ export {
326
+ pickMainEntry
327
+ };
328
+ //# sourceMappingURL=main-tree-picker-WHRN26NJ.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/main-tree-picker.ts"],
4
+ "sourcesContent": ["import {\n copyToClipboard,\n type ExtensionAPI,\n type ExtensionCommandContext,\n type SessionEntry,\n type SessionTreeNode,\n TreeSelectorComponent,\n} from \"@earendil-works/pi-coding-agent\";\nimport { type Component, type Focusable, Key, matchesKey } from \"@earendil-works/pi-tui\";\nimport { showBtwCustomPreservingEditor } from \"./menu.js\";\nimport { sanitizeSingleLine } from \"./text.js\";\n\nexport type MainEntryPickResult = { kind: \"selected\"; entryId: string } | { kind: \"back\" } | { kind: \"closed\" };\n\nexport interface MainThreadTreeSelector extends Component, Focusable {\n onCopy?: (text: string | undefined) => void;\n setViewLabel?(entryId: string, label: string | undefined, labelTimestamp?: string): void;\n dispose?(): void;\n}\n\nexport interface MainThreadTreeSelectorOptions {\n tree: SessionTreeNode[];\n currentLeafId: string | null;\n terminalRows: number;\n onSelect: (entryId: string) => void;\n onCancel: () => void;\n onCopy: (entryId: string | undefined, displayText: string | undefined) => void;\n onLabelChange: (entryId: string, label: string | undefined) => void;\n}\n\nexport interface MainThreadTreePickerDependencies {\n createSelector?: (options: MainThreadTreeSelectorOptions) => MainThreadTreeSelector;\n copyToClipboard?: (text: string, signal: AbortSignal) => Promise<void>;\n}\n\nclass MainThreadTreePickerComponent implements Component, Focusable {\n constructor(\n private readonly selector: MainThreadTreeSelector,\n private readonly onClose: () => void,\n ) {}\n\n get focused(): boolean {\n return this.selector.focused;\n }\n\n set focused(value: boolean) {\n this.selector.focused = value;\n }\n\n get wantsKeyRelease(): boolean | undefined {\n return this.selector.wantsKeyRelease;\n }\n\n render(width: number): string[] {\n return this.selector.render(width);\n }\n\n handleInput(data: string): void {\n if (matchesKey(data, Key.ctrl(\"c\"))) {\n this.onClose();\n return;\n }\n this.selector.handleInput?.(data);\n }\n\n invalidate(): void {\n this.selector.invalidate();\n }\n\n dispose(): void {\n this.selector.dispose?.();\n this.onClose();\n }\n}\n\nexport async function pickMainEntry(\n pi: ExtensionAPI,\n ctx: ExtensionCommandContext,\n dependencies: MainThreadTreePickerDependencies = {},\n): Promise<MainEntryPickResult> {\n let rawTree: SessionTreeNode[];\n let currentLeafId: string | null;\n try {\n rawTree = ctx.sessionManager.getTree();\n currentLeafId = ctx.sessionManager.getLeafId();\n } catch {\n return { kind: \"closed\" };\n }\n\n if (rawTree.length === 0) {\n notifySafely(ctx, \"No main-thread entries are available\", \"warning\");\n return { kind: \"back\" };\n }\n\n const tree = sanitizeTreeForDisplay(rawTree);\n const rawCopyText = collectRawCopyText(rawTree);\n const savedLabels = collectSavedLabels(rawTree);\n const createSelector = dependencies.createSelector ?? createNativeTreeSelector;\n const copy = dependencies.copyToClipboard ?? copyText;\n const copyControllers = new Set<AbortController>();\n const copyTasks = new Set<Promise<void>>();\n const abortCopies = () => {\n for (const controller of copyControllers) {\n controller.abort(new Error(\"The main-thread tree picker closed\"));\n }\n };\n const result = await showBtwCustomPreservingEditor<MainEntryPickResult>(ctx, (tui, _theme, _keybindings, done) => {\n let settled = false;\n let selector: MainThreadTreeSelector | undefined;\n const finish = (value: MainEntryPickResult) => {\n if (settled) return;\n settled = true;\n abortCopies();\n done(value);\n };\n const onCopy = (entryId: string | undefined, displayText: string | undefined) => {\n if (settled) return;\n const text = entryId ? rawCopyText.get(entryId) : displayText;\n if (!text) {\n notifySafely(ctx, \"Selected entry has no text to copy\", \"warning\");\n return;\n }\n const controller = new AbortController();\n copyControllers.add(controller);\n let operation: Promise<void>;\n try {\n operation = copy(text, controller.signal);\n } catch (error: unknown) {\n operation = Promise.reject(error);\n }\n let task!: Promise<void>;\n task = operation\n .then(() => {\n if (!settled) notifySafely(ctx, \"Copied selected message\", \"info\");\n })\n .catch((error: unknown) => {\n if (!settled && !controller.signal.aborted) {\n notifySafely(ctx, `Could not copy selected message: ${formatError(error)}`, \"error\");\n }\n })\n .finally(() => {\n copyControllers.delete(controller);\n copyTasks.delete(task);\n });\n copyTasks.add(task);\n };\n const restoreLabel = (entryId: string) => {\n const previous = savedLabels.get(entryId);\n selector?.setViewLabel?.(entryId, previous?.label, previous?.labelTimestamp);\n tui.requestRender();\n };\n const onLabelChange = (entryId: string, label: string | undefined) => {\n if (settled) return;\n try {\n if (!ctx.sessionManager.getEntry(entryId)) {\n restoreLabel(entryId);\n notifySafely(ctx, \"The selected main-thread entry is no longer available\", \"warning\");\n return;\n }\n const persistedLabel = label === undefined ? undefined : sanitizeSingleLine(label);\n pi.setLabel(entryId, persistedLabel);\n savedLabels.set(entryId, { label: persistedLabel });\n selector?.setViewLabel?.(entryId, persistedLabel);\n tui.requestRender();\n } catch (error: unknown) {\n restoreLabel(entryId);\n notifySafely(ctx, `Could not update tree label: ${formatError(error)}`, \"error\");\n }\n };\n selector = createSelector({\n tree,\n currentLeafId,\n terminalRows: tui.terminal.rows,\n onSelect: (entryId) => finish({ kind: \"selected\", entryId }),\n onCancel: () => finish({ kind: \"back\" }),\n onCopy,\n onLabelChange,\n });\n return new MainThreadTreePickerComponent(selector, () => finish({ kind: \"closed\" }));\n });\n abortCopies();\n await Promise.allSettled([...copyTasks]);\n\n return result ?? { kind: \"closed\" };\n}\n\nfunction createNativeTreeSelector(options: MainThreadTreeSelectorOptions): MainThreadTreeSelector {\n const selector = new TreeSelectorComponent(\n options.tree,\n options.currentLeafId,\n options.terminalRows,\n options.onSelect,\n options.onCancel,\n options.onLabelChange,\n );\n selector.onCopy = (displayText) => options.onCopy(selector.getTreeList().getSelectedNode()?.entry.id, displayText);\n const result = selector as MainThreadTreeSelector;\n result.setViewLabel = (entryId, label, labelTimestamp) =>\n selector.getTreeList().updateNodeLabel(entryId, label, labelTimestamp);\n return result;\n}\n\nfunction sanitizeTreeForDisplay(tree: readonly SessionTreeNode[]): SessionTreeNode[] {\n return tree.map((node) => {\n const result: SessionTreeNode = {\n entry: sanitizeEntryForDisplay(node.entry),\n children: sanitizeTreeForDisplay(node.children),\n };\n if (node.label !== undefined) result.label = sanitizeSingleLine(node.label);\n if (node.labelTimestamp !== undefined) {\n result.labelTimestamp = sanitizeSingleLine(node.labelTimestamp);\n }\n return result;\n });\n}\n\nfunction sanitizeEntryForDisplay(entry: SessionEntry): SessionEntry {\n switch (entry.type) {\n case \"message\": {\n const message = { ...entry.message } as Record<string, unknown>;\n if (\"content\" in entry.message) message.content = sanitizeDisplayContent(entry.message.content);\n for (const key of [\"role\", \"errorMessage\", \"command\", \"toolName\"] as const) {\n const value = message[key];\n if (typeof value === \"string\") message[key] = sanitizeSingleLine(value);\n }\n return { ...entry, message } as unknown as SessionEntry;\n }\n case \"custom_message\":\n return {\n ...entry,\n customType: sanitizeSingleLine(entry.customType),\n content: sanitizeDisplayContent(entry.content) as typeof entry.content,\n };\n case \"compaction\":\n return { ...entry, summary: sanitizeSingleLine(entry.summary) };\n case \"branch_summary\":\n return { ...entry, summary: sanitizeSingleLine(entry.summary) };\n case \"model_change\":\n return {\n ...entry,\n provider: sanitizeSingleLine(entry.provider),\n modelId: sanitizeSingleLine(entry.modelId),\n };\n case \"thinking_level_change\":\n return { ...entry, thinkingLevel: sanitizeSingleLine(entry.thinkingLevel) };\n case \"custom\":\n return { ...entry, customType: sanitizeSingleLine(entry.customType) };\n case \"context_edit\":\n return { ...entry, targetId: sanitizeSingleLine(entry.targetId) };\n case \"label\":\n return {\n ...entry,\n label: entry.label === undefined ? undefined : sanitizeSingleLine(entry.label),\n };\n case \"session_info\":\n return {\n ...entry,\n name: entry.name === undefined ? undefined : sanitizeSingleLine(entry.name),\n };\n case \"usage\":\n return {\n ...entry,\n kind: sanitizeSingleLine(entry.kind),\n provider: sanitizeSingleLine(entry.provider),\n model: sanitizeSingleLine(entry.model),\n note: entry.note === undefined ? undefined : sanitizeSingleLine(entry.note),\n };\n }\n}\n\nfunction sanitizeDisplayContent(content: unknown): unknown {\n if (typeof content === \"string\") return sanitizeSingleLine(content);\n if (!Array.isArray(content)) return content;\n return content.map((block) => {\n if (block === null || typeof block !== \"object\" || !(\"type\" in block)) return block;\n if (block.type === \"text\" && \"text\" in block && typeof block.text === \"string\") {\n return { ...block, text: sanitizeSingleLine(block.text) };\n }\n if (block.type === \"toolCall\") {\n const copy = { ...block } as Record<string, unknown>;\n if (typeof copy.name === \"string\") copy.name = sanitizeSingleLine(copy.name);\n copy.arguments = sanitizeToolArguments(copy.arguments, new WeakMap());\n return copy;\n }\n return block;\n });\n}\n\nfunction sanitizeToolArguments(value: unknown, seen: WeakMap<object, unknown>): unknown {\n if (typeof value === \"string\") return sanitizeSingleLine(value);\n if (value === null || typeof value !== \"object\") return value;\n const existing = seen.get(value);\n if (existing !== undefined) return existing;\n if (Array.isArray(value)) {\n const result: unknown[] = [];\n seen.set(value, result);\n for (const item of value) result.push(sanitizeToolArguments(item, seen));\n return result;\n }\n const result: Record<string, unknown> = {};\n seen.set(value, result);\n for (const [key, item] of Object.entries(value)) {\n result[key] = sanitizeToolArguments(item, seen);\n }\n return result;\n}\n\nfunction collectRawCopyText(tree: readonly SessionTreeNode[]): Map<string, string> {\n const result = new Map<string, string>();\n const visit = (nodes: readonly SessionTreeNode[]) => {\n for (const node of nodes) {\n const text = getRawCopyText(node.entry);\n if (text !== undefined) result.set(node.entry.id, text);\n visit(node.children);\n }\n };\n visit(tree);\n return result;\n}\n\nfunction getRawCopyText(entry: SessionEntry): string | undefined {\n let text: string | undefined;\n if (entry.type === \"message\") {\n if (entry.message.role === \"bashExecution\") text = entry.message.command;\n else if (\"content\" in entry.message) {\n text = extractRawText(entry.message.content);\n if (!text && entry.message.role === \"assistant\") text = entry.message.errorMessage;\n }\n } else if (entry.type === \"custom_message\") text = extractRawText(entry.content);\n else if (entry.type === \"compaction\" || entry.type === \"branch_summary\") text = entry.summary;\n return text?.trim() ? text : undefined;\n}\n\nfunction extractRawText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .filter(\n (block): block is { type: \"text\"; text: string } =>\n block !== null &&\n typeof block === \"object\" &&\n \"type\" in block &&\n block.type === \"text\" &&\n \"text\" in block &&\n typeof block.text === \"string\",\n )\n .map((block) => block.text)\n .join(\"\");\n}\n\ninterface SavedLabel {\n label: string | undefined;\n labelTimestamp?: string;\n}\n\nfunction collectSavedLabels(tree: readonly SessionTreeNode[]): Map<string, SavedLabel> {\n const result = new Map<string, SavedLabel>();\n const visit = (nodes: readonly SessionTreeNode[]) => {\n for (const node of nodes) {\n result.set(node.entry.id, {\n label: node.label === undefined ? undefined : sanitizeSingleLine(node.label),\n labelTimestamp: node.labelTimestamp === undefined ? undefined : sanitizeSingleLine(node.labelTimestamp),\n });\n visit(node.children);\n }\n };\n visit(tree);\n return result;\n}\n\nasync function copyText(text: string, signal: AbortSignal): Promise<void> {\n signal.throwIfAborted();\n await copyToClipboard(text);\n signal.throwIfAborted();\n}\n\nfunction notifySafely(\n ctx: ExtensionCommandContext,\n message: string,\n level: Parameters<ExtensionCommandContext[\"ui\"][\"notify\"]>[1],\n): void {\n try {\n ctx.ui.notify(sanitizeSingleLine(message), level);\n } catch {\n // The command context may have been replaced while the selector was open.\n }\n}\n\nfunction formatError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EAKA;AAAA,OACK;AACP,SAAyC,KAAK,kBAAkB;AA2BhE,IAAM,gCAAN,MAAoE;AAAA,EAClE,YACmB,UACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGnB,IAAI,UAAmB;AACrB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,IAAI,QAAQ,OAAgB;AAC1B,SAAK,SAAS,UAAU;AAAA,EAC1B;AAAA,EAEA,IAAI,kBAAuC;AACzC,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,OAAO,OAAyB;AAC9B,WAAO,KAAK,SAAS,OAAO,KAAK;AAAA,EACnC;AAAA,EAEA,YAAY,MAAoB;AAC9B,QAAI,WAAW,MAAM,IAAI,KAAK,GAAG,CAAC,GAAG;AACnC,WAAK,QAAQ;AACb;AAAA,IACF;AACA,SAAK,SAAS,cAAc,IAAI;AAAA,EAClC;AAAA,EAEA,aAAmB;AACjB,SAAK,SAAS,WAAW;AAAA,EAC3B;AAAA,EAEA,UAAgB;AACd,SAAK,SAAS,UAAU;AACxB,SAAK,QAAQ;AAAA,EACf;AACF;AAEA,eAAsB,cACpB,IACA,KACA,eAAiD,CAAC,GACpB;AAC9B,MAAI;AACJ,MAAI;AACJ,MAAI;AACF,cAAU,IAAI,eAAe,QAAQ;AACrC,oBAAgB,IAAI,eAAe,UAAU;AAAA,EAC/C,QAAQ;AACN,WAAO,EAAE,MAAM,SAAS;AAAA,EAC1B;AAEA,MAAI,QAAQ,WAAW,GAAG;AACxB,iBAAa,KAAK,wCAAwC,SAAS;AACnE,WAAO,EAAE,MAAM,OAAO;AAAA,EACxB;AAEA,QAAM,OAAO,uBAAuB,OAAO;AAC3C,QAAM,cAAc,mBAAmB,O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SAAS,aACP,KACA,SACA,OACM;AACN,MAAI;AACF,QAAI,GAAG,OAAO,mBAAmB,OAAO,GAAG,KAAK;AAAA,EAClD,QAAQ;AAAA,EAER;AACF;AAEA,SAAS,YAAY,OAAwB;AAC3C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;",
6
+ "names": ["result"]
7
+ }
@@ -0,0 +1,15 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ runBtwMenuPreservingEditor,
5
+ showBtwCommandMenu,
6
+ showBtwCustomPreservingEditor
7
+ } from "./chunk-TPDBHPLD.ts";
8
+ import "./chunk-E4LBFYRH.ts";
9
+ import "./chunk-FWW662MW.ts";
10
+ export {
11
+ runBtwMenuPreservingEditor,
12
+ showBtwCommandMenu,
13
+ showBtwCustomPreservingEditor
14
+ };
15
+ //# sourceMappingURL=menu-SYMLQYWC.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }