@notrico/pi-fold 3.0.0 → 3.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/CHANGELOG.md +12 -0
- package/docs/renderer-reference.md +4 -2
- package/package.json +1 -1
- package/scripts/preview-actions.mjs +9 -0
- package/scripts/preview-inspection.mjs +9 -0
- package/scripts/preview-work-strip.mjs +39 -1
- package/scripts/preview.mjs +3 -1
- package/scripts/test.mjs +2 -1
- package/src/display-card.ts +2 -0
- package/src/modern-code-content.ts +8 -1
- package/src/modern-code-pane.ts +20 -6
- package/src/modern-thinking.ts +25 -3
- package/src/modern-tool-pane.ts +32 -17
- package/src/modern-tools.ts +35 -6
- package/src/modern-workflows.ts +9 -6
- package/src/work-strip-view.ts +13 -5
- package/tests/action-group-preview.test.mjs +43 -0
- package/tests/codemode.test.mjs +31 -6
- package/tests/fold-shortcut.test.mjs +1 -1
- package/tests/inspection-wheel.test.mjs +75 -0
- package/tests/mixed-action-groups.test.mjs +201 -0
- package/tests/mixed-thinking.test.mjs +63 -11
- package/tests/modern-tools.test.mjs +53 -0
- package/tests/modern-workflows.test.mjs +43 -1
- package/tests/preview-example.test.mjs +1 -1
- package/tests/reload-lifecycle.test.mjs +5 -5
- package/tests/test-runtime.mjs +3 -1
- package/tests/work-strip-final-surface.test.mjs +52 -2
- package/tests/work-strip-preview.test.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
+
## 3.0.2 — Mixed action groups
|
|
4
|
+
|
|
5
|
+
- Group successful completed codemode calls with adjacent bash and file actions. Count each outer call once and retain nested source, calls, and output on expansion.
|
|
6
|
+
- Keep running calls, failures, nested warnings, images, and unsupported records separate. Preserve visible conversation boundaries and native display when folding is disabled.
|
|
7
|
+
|
|
8
|
+
## 3.0.1 — Inspection paging and final thinking
|
|
9
|
+
|
|
10
|
+
- Make `more ↓` advance expanded tool, codemode, workflow, and thinking panes by one visible page. Preserve prompt typing after mouse inspection.
|
|
11
|
+
- Keep the overflow footer in place at the end as `more ↑`, so upward scrolling stays inside the pane. Clicking it pages backward.
|
|
12
|
+
- Keep leading thinking on a final answer with the preceding thinking rounds. Preserve visible-reply, error, and question boundaries.
|
|
13
|
+
- Preserve compact thinking while painting the final answer background and padding.
|
|
14
|
+
|
|
3
15
|
## 3.0.0 — Pi Fold
|
|
4
16
|
|
|
5
17
|
- Rename the public interface to Pi Fold and combine display mode, collapse/expand, and shortcut controls under `/fold`.
|
|
@@ -19,13 +19,13 @@ pi remove git:github.com/rrrrrrrrrricoxi/pi-fold@v3.0.0
|
|
|
19
19
|
## Display
|
|
20
20
|
|
|
21
21
|
- Questions use a bold purple heading, aligned with ordinary action headings, without a background or vertical rail. Recorded answers use a green checkmark inline with the options. Ordinary action headings stay blue. The `codemode` label uses native teal (`syntaxVariable`), while counts and timing stay muted; handled nested problems retain warning color; thinking headings stay muted and failures stay red. Expanded content remains unfilled. Keyboard focus has its own selection highlight. User prompts keep their blue surface. Subagent transcript activity uses the same compact headings and inspection controls.
|
|
22
|
-
- Running actions remain separate.
|
|
22
|
+
- Running actions remain separate. Successful completed bash, file, and codemode calls can share one action group within visible conversation boundaries. Each outer codemode call counts as one action; nested calls stay inside its inspectable content. Nested errors, cancellations, unresolved calls, images, and unsupported codemode records stay separate. Pure thinking does not split an action group; visible assistant replies and user messages do.
|
|
23
23
|
- Successful group headings use “4 actions”; singleton headings show only the operation. Shell interpreter scripts use labels such as “Run Node.js script,” with a literal script filename when reliably available. Inline source stays in Arguments. Known errors show a short category such as “Path too long”; exact errors stay in Output/Details. Labels describe recorded operations and do not infer a script’s purpose.
|
|
24
24
|
- Expanded source and diffs use Pi’s syntax colors. Recorded thinking and Markdown files use bounded Markdown rendering; shell stdout and unknown text remain literal. Formatting reads at most 2,048 source characters per block. Markdown uses one source line per block, so multiline tables, paragraphs, and cross-line inline formatting are not fully reconstructed. Very long code blocks can lose lexer context at block boundaries. The original recorded source remains unchanged.
|
|
25
25
|
- A single-action card opens directly to useful content without repeating a numbered action row. Successful native `write` actions show submitted content with syntax colors from the path. Only the exact standard acknowledgement is moved under Details. Reads and unknown tools keep their output visible. Known ordinary-tool OS diagnostics can show a short code/category while Details retains the exact error; unknown/custom failures keep full visible output. Status marks follow the title.
|
|
26
26
|
- Open a group to see tightly stacked actions without blank rows between siblings. Several actions and their inline Details can remain expanded independently in the same scrollable pane. Details contains exact arguments, secondary diagnostics, and any acknowledgement/error moved from the main content. Short scalar fields share a line; null and empty values remain explicit. Empty diagnostic objects do not add a section.
|
|
27
27
|
- Errors, cancellations, unanswered questions, and background notices stay separate. Expanded question cards show the full question, nonempty context, and tight option rows with descriptions inline. A checkmark, native success color, and bold text mark recorded selections; custom or unmatched answers remain visible on their own marked row. Only answered records receive answer marks. Other states appear once in the header, with meaningful diagnostics retained; the exact standard cancellation message is omitted. Question cards omit duplicate headings and raw Arguments/Details objects; stored transcripts retain the original data.
|
|
28
|
-
- Consecutive completed subagent guide lookups form a separate guide group, with each requested topic shown on expansion. Consecutive routine subagent calls and recognized asynchronous notices form one compact update group. Failures and pending decisions stay separate. A decision request, successful supervisor reply, and acknowledgement combine only when their explicit request identity matches within the same uninterrupted exchange. Expansion shows the question and highlights the supervisor reply; this is not attributed to the user. Visible assistant replies, user messages, unrelated decisions, errors, and other actions stop grouping. Launch acknowledgements, queued steering, decision requests, replies, and completion notices retain their recorded meanings. Decision requests use purple headings; failures use red headings. Expansion shows recorded content first; Details retains exact arguments and identifiers. Unknown notification shapes and compact mode off retain native rendering. Fleet, execution, scheduling, and steering controls remain native. codemode has its own collapsible card,
|
|
28
|
+
- Consecutive completed subagent guide lookups form a separate guide group, with each requested topic shown on expansion. Consecutive routine subagent calls and recognized asynchronous notices form one compact update group. Failures and pending decisions stay separate. A decision request, successful supervisor reply, and acknowledgement combine only when their explicit request identity matches within the same uninterrupted exchange. Expansion shows the question and highlights the supervisor reply; this is not attributed to the user. Visible assistant replies, user messages, unrelated decisions, errors, and other actions stop grouping. Launch acknowledgements, queued steering, decision requests, replies, and completion notices retain their recorded meanings. Decision requests use purple headings; failures use red headings. Expansion shows recorded content first; Details retains exact arguments and identifiers. Unknown notification shapes and compact mode off retain native rendering. Fleet, execution, scheduling, and steering controls remain native. A standalone codemode call has its own collapsible card. In a mixed action group, expand its action row to inspect the same recorded content. Its expanded body uses bounded chunks with native JavaScript colors, nested-call status colors, durations, and model cost in USD. Source, recorded call arguments/errors, output, and metadata remain scroll-accessible. Long multiline code can have different syntax colors across chunk boundaries. Shape validation and scalar call/count/cost aggregation run once per explicit update revision; they are separate from bounded viewport painting. Valid image results retain the compact codemode summary and bounded text inspection, with image counts. Image previews appear only when the compact block is expanded, using Pi's native image objects and terminal capability checks. See Inline images below. Unsupported shapes and compact mode off retain the stock native renderer. Standalone image reads stay separate and use one compact heading.
|
|
29
29
|
- Recorded thinking rounds can group across tools. Replies, questions, errors, and other visible boundaries separate groups. Each round has a short title taken from its recorded heading or first sentence and expands independently. The pane shows the full recorded text on demand; it does not generate summaries or make model calls.
|
|
30
30
|
- Recognized prompt templates show their command and authored description, or a bounded excerpt when no description is available. Expansion reveals the original text inline. Ordinary submitted prompts longer than eight rendered lines show a bounded opening and ending, separated by a muted “⋯ Show more” control. The opening stops at its first paragraph break; the ending uses the last paragraph. Long paragraphs use bounded excerpts. A blank row separates each excerpt from the control. Expansion preserves all recorded text and formatting and places “▴ Show less” at the bottom; short prompts stay open. Skill invocations share the blue prompt card, with click, `/inspect`, and native Ctrl+O expansion.
|
|
31
31
|
|
|
@@ -108,3 +108,5 @@ In compact mode, expanding an image read or image-bearing codemode reveals the r
|
|
|
108
108
|
The renderer respects Pi's show-images setting and terminal capability detection. Pi 1.3.0 supports Kitty images in compatible terminals and disables image protocols under tmux. On that route, or when images are disabled, the expanded block shows a short fallback. A direct image read retains its recorded path; Pi makes absolute paths clickable only when native hyperlink support is available. Remote paths still refer to the remote host. codemode does not invent a file path for an in-memory image.
|
|
109
109
|
|
|
110
110
|
Compact mode off preserves native image display and sizing. The image adapter is gated to Pi 1.3.0 and restores the native component's options after each compact paint. It does not alter image data, terminal settings, tmux settings, or saved transcripts.
|
|
111
|
+
|
|
112
|
+
To inspect mixed bash/codemode groups in the isolated fixture, run `node scripts/preview-actions.mjs`. The final work section includes both bash-led and codemode-led groups and a separate nested-error card. No tools or model run.
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Recorded mixed action groups in an isolated Pi session. No tools or model run.
|
|
3
|
+
import { createWorkStripPreview } from './preview-work-strip.mjs';
|
|
4
|
+
const preview = await createWorkStripPreview({ actionGroups: true });
|
|
5
|
+
let ui;
|
|
6
|
+
try {
|
|
7
|
+
ui = new preview.core.InteractiveMode(preview.runtime, { tuiMode: 'fullscreen' });
|
|
8
|
+
await ui.run();
|
|
9
|
+
} finally { ui?.stop(); await preview.cleanup(); }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Isolated recorded-content preview; no model or tool execution.
|
|
3
|
+
import { createWorkStripPreview } from './preview-work-strip.mjs';
|
|
4
|
+
const preview = await createWorkStripPreview({ inspection: true });
|
|
5
|
+
let ui;
|
|
6
|
+
try {
|
|
7
|
+
ui = new preview.core.InteractiveMode(preview.runtime, { tuiMode: 'fullscreen' });
|
|
8
|
+
await ui.run();
|
|
9
|
+
} finally { ui?.stop(); await preview.cleanup(); }
|
|
@@ -5,7 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { createPreview } from './preview.mjs';
|
|
7
7
|
|
|
8
|
-
export async function createWorkStripPreview({ stepMs = 1000 } = {}) {
|
|
8
|
+
export async function createWorkStripPreview({ stepMs = 1000, inspection = false, actionGroups = false } = {}) {
|
|
9
9
|
const old = process.env.PI_PREVIEW_WORK_STRIP;
|
|
10
10
|
process.env.PI_PREVIEW_WORK_STRIP = '1';
|
|
11
11
|
const preview = await createPreview();
|
|
@@ -32,6 +32,44 @@ export async function createWorkStripPreview({ stepMs = 1000 } = {}) {
|
|
|
32
32
|
'This is a display fixture. Do not execute tools or access any external data.',
|
|
33
33
|
].join('\n'),timestamp:Date.now()});
|
|
34
34
|
manager.appendMessage(assistant('This direct reply has no work strip. Expand the prompt above to inspect all ten recorded requirements.'));
|
|
35
|
+
if (inspection) {
|
|
36
|
+
manager.appendMessage({role:'user',content:'Inspection regression preview: expand the work, then click more in the recorded code output and the three-round thinking group.',timestamp:Date.now()});
|
|
37
|
+
const userId = manager.getBranch().at(-1).id;
|
|
38
|
+
for (let i = 1; i <= 2; i++) {
|
|
39
|
+
const name = i === 1 ? 'read' : 'codemode';
|
|
40
|
+
const args = i === 1 ? {path:'/fixture/recorded.txt'} : {code:'text(await tools.read({ path: "/fixture/recorded.txt" }));'};
|
|
41
|
+
const call = assistant(''); call.stopReason = 'toolUse';
|
|
42
|
+
call.content = [{type:'thinking',thinking:`Review recorded sample ${i}.\n\n` + Array.from({length:45},(_,n)=>`Round ${i}, recorded line ${n+1}. This is invented fixture text.`).join('\n')}, {type:'toolCall',id:`inspection-${i}`,name,arguments:args}];
|
|
43
|
+
manager.appendMessage(call);
|
|
44
|
+
manager.appendMessage({role:'toolResult',toolCallId:`inspection-${i}`,toolName:name,content:[{type:'text',text:Array.from({length:60},(_,n)=>`Recorded output ${n+1}`).join('\n')}],details:i===2?{calls:[{name:'read',args:JSON.stringify({path:'/fixture/recorded.txt'}),status:'ok',durationMs:1}]}:{},isError:false,timestamp:Date.now()});
|
|
45
|
+
}
|
|
46
|
+
const final = assistant('Inspection result: the final thinking belongs to the same three-round group. Clicking more advances the recorded output. This answer stays outside the group. No tools or model ran.');
|
|
47
|
+
final.content.unshift({type:'thinking',thinking:'Finalize the recorded result.\n\n' + Array.from({length:45},(_,n)=>`Final round, recorded line ${n+1}. This is invented fixture text.`).join('\n')});
|
|
48
|
+
manager.appendMessage(final);
|
|
49
|
+
const finalId = manager.getBranch().at(-1).id;
|
|
50
|
+
manager.appendCustomEntry('compact-renderer:work-settled:v1',{version:1,userId,finalId,endId:finalId,startedAt:base-90000,endedAt:base,outcome:'completed'});
|
|
51
|
+
}
|
|
52
|
+
if (actionGroups) {
|
|
53
|
+
manager.appendMessage({role:'user',content:'Compare mixed action groups: successful bash, codemode, and file calls belong together. Keep nested failures visible.',timestamp:Date.now()});
|
|
54
|
+
const userId = manager.getBranch().at(-1).id;
|
|
55
|
+
const recorded = (id, name, args, text, calls = []) => {
|
|
56
|
+
const call = assistant(''); call.stopReason = 'toolUse';
|
|
57
|
+
call.content = [{type:'toolCall',id,name,arguments:args}];
|
|
58
|
+
manager.appendMessage(call);
|
|
59
|
+
manager.appendMessage({role:'toolResult',toolCallId:id,toolName:name,content:[{type:'text',text}],details:name==='codemode'?{calls}:{},isError:false,durationMs:12,timestamp:Date.now()});
|
|
60
|
+
};
|
|
61
|
+
const code = (id, status = 'ok') => recorded(id, 'codemode', {code:'text(await tools.read({ path: "/fixture/units.txt" }));'}, 'Recorded units: kg/L. No file was read.', [{name:'read',args:'{"path":"/fixture/units.txt"}',status,durationMs:3,...(status==='error'?{error:'Invented missing-file warning, handled by the script.'}:{})}]);
|
|
62
|
+
recorded('mixed-bash', 'bash', {command:'printf "recorded sample"'}, 'Recorded shell output. No command ran.');
|
|
63
|
+
code('mixed-code-a'); code('mixed-code-b');
|
|
64
|
+
recorded('mixed-read', 'read', {path:'/fixture/summary.txt'}, 'Recorded summary.');
|
|
65
|
+
manager.appendMessage(assistant('The four calls above form one group. Each codemode counts once and retains its nested source, calls, and output. This reply separates the next group, which starts with codemode.'));
|
|
66
|
+
code('mixed-code-first');
|
|
67
|
+
recorded('mixed-write', 'write', {path:'/fixture/report.txt',content:'Recorded report.'}, 'Successfully wrote to /fixture/report.txt');
|
|
68
|
+
code('mixed-nested-warning', 'error');
|
|
69
|
+
manager.appendMessage(assistant('Mixed-action preview: expand the work, then the 4-action and 2-action groups. Open codemode to inspect its recorded content. The nested-error card stays separate. Test /fold collapse, Ctrl+Alt+W, /inspect, and Esc. All content is invented; no tool or model ran.'));
|
|
70
|
+
const finalId = manager.getBranch().at(-1).id;
|
|
71
|
+
manager.appendCustomEntry('compact-renderer:work-settled:v1',{version:1,userId,finalId,endId:finalId,startedAt:base-45000,endedAt:base,outcome:'completed'});
|
|
72
|
+
}
|
|
35
73
|
const emit = async event => {
|
|
36
74
|
if (stopped) return;
|
|
37
75
|
runtime.session._emit(event);
|
package/scripts/preview.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Actual Pi TUI with invented records and an isolated temporary home. No credentials or live services.
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import os from 'node:os';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ const source = fileURLToPath(new URL('../', import.meta.url));
|
|
|
9
10
|
export async function createPreview() {
|
|
10
11
|
const hostHome = os.homedir();
|
|
11
12
|
const runtimePath = path.resolve(process.env.PI_RUNTIME || path.join(hostHome, '.local/state/pi-config/current/runtime'));
|
|
13
|
+
const tuiPath = createRequire(path.join(runtimePath, 'node_modules/@earendil-works/pi-coding-agent/package.json')).resolve('@earendil-works/pi-tui');
|
|
12
14
|
const promptJump = process.env.PI_PROMPT_JUMP_PATH ? path.resolve(process.env.PI_PROMPT_JUMP_PATH) : undefined;
|
|
13
15
|
const questionCandidates = process.env.PI_QUESTIONS_PATH ? [path.resolve(process.env.PI_QUESTIONS_PATH)] : [
|
|
14
16
|
path.join(hostHome, '.local/state/pi-config/current/packages/pi-questions/index.ts'),
|
|
@@ -218,7 +220,7 @@ export async function createPreview() {
|
|
|
218
220
|
runtime = await core.createAgentSessionRuntime(factory, { cwd, agentDir, sessionManager: manager });
|
|
219
221
|
const diagnostics = runtime.services.resourceLoader.getExtensions().errors;
|
|
220
222
|
if (runtime.diagnostics.some(item => item.type === 'error') || diagnostics.length) throw new Error(JSON.stringify([...runtime.diagnostics, ...diagnostics]));
|
|
221
|
-
return { core, runtime, manager, temporary, agentDir, cwd, runtimePath, questionsPath, eventBus, cleanup };
|
|
223
|
+
return { core, runtime, manager, temporary, agentDir, cwd, runtimePath, tuiPath, questionsPath, eventBus, cleanup };
|
|
222
224
|
} catch (error) { await cleanup(); throw error; }
|
|
223
225
|
}
|
|
224
226
|
|
package/scripts/test.mjs
CHANGED
|
@@ -7,11 +7,12 @@ import { spawnSync } from 'node:child_process';
|
|
|
7
7
|
const directory = fileURLToPath(new URL('../tests/', import.meta.url));
|
|
8
8
|
const required = ['action-intent.test.mjs', 'modern-workflows.test.mjs', 'display-mode.test.mjs', 'modern-tools.test.mjs', 'modern-subagent-messages.test.mjs', 'subagent-spacing.test.mjs', 'modern-subagent-groups.test.mjs', 'modern-thinking.test.mjs', 'modern-prompts.test.mjs', 'permission-presentation.test.mjs', 'input-focus.test.mjs', 'inspection.test.mjs', 'codemode.test.mjs', 'preview-example.test.mjs'];
|
|
9
9
|
required.push('reload-lifecycle.test.mjs', 'ordinary-prompts.test.mjs', 'work-strip-hierarchy.test.mjs', 'work-strip-final-surface.test.mjs');
|
|
10
|
-
required.push('modern-skill-prompts.test.mjs');
|
|
10
|
+
required.push('modern-skill-prompts.test.mjs', 'inspection-wheel.test.mjs');
|
|
11
11
|
required.push('display-line-cache.test.mjs');
|
|
12
12
|
required.push('display-cache-lifecycle.test.mjs');
|
|
13
13
|
required.push('fold-command.test.mjs', 'fold-shortcut.test.mjs');
|
|
14
14
|
required.push('mixed-thinking.test.mjs', 'work-strip.test.mjs', 'work-strip-subagents.test.mjs', 'work-strip-preview.test.mjs', 'work-strip-spacing.test.mjs');
|
|
15
|
+
required.push('mixed-action-groups.test.mjs', 'action-group-preview.test.mjs');
|
|
15
16
|
for (const name of required) {
|
|
16
17
|
if (!fs.existsSync(path.join(directory, name))) throw new Error(`Missing required regression suite: ${name}`);
|
|
17
18
|
const result = spawnSync(process.execPath, [path.join(directory, name)], { cwd: directory, env: process.env, stdio: 'inherit' });
|
package/src/display-card.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { DisplayLineCache } from "./display-line-cache.ts";
|
|
|
3
3
|
|
|
4
4
|
const lines = new DisplayLineCache();
|
|
5
5
|
export const clearDisplayLineCache = () => lines.clear();
|
|
6
|
+
// Final reply projections retain native Markdown rather than workflow controls.
|
|
7
|
+
export const finalReplyRendering = Symbol.for("compact-renderer:final-reply-rendering:v1");
|
|
6
8
|
// Key the actual styling bytes, not theme identity: themes can change in place.
|
|
7
9
|
const memoLine = (kind: string, line: string, width: number, style: string, render: () => string) =>
|
|
8
10
|
line.length > 4096 ? render() : lines.get(JSON.stringify([kind, width, style, line]), render);
|
|
@@ -31,6 +31,8 @@ function* metadataValues(value: any, ancestors = new Set<object>()): Generator<s
|
|
|
31
31
|
* rendering visits bounded chunks and the nested calls reached by the viewport. */
|
|
32
32
|
export class CodeContent {
|
|
33
33
|
supported = true;
|
|
34
|
+
clean = true;
|
|
35
|
+
hasScriptHeader = false;
|
|
34
36
|
calls: any[] = [];
|
|
35
37
|
content: any[] = [];
|
|
36
38
|
code = "";
|
|
@@ -43,12 +45,15 @@ export class CodeContent {
|
|
|
43
45
|
private revision = -1;
|
|
44
46
|
update(args: any, result: any, revision: number) {
|
|
45
47
|
if (revision === this.revision) return false;
|
|
46
|
-
this.revision = revision; this.supported = true;
|
|
48
|
+
this.revision = revision; this.supported = true; this.clean = true; this.hasScriptHeader = false;
|
|
47
49
|
this.errors = this.cancelled = this.unresolved = this.priced = this.totalCost = this.images = 0;
|
|
48
50
|
const code = data(args, "code"), content = result ? data(result, "content") : [], details = result ? data(result, "details") : undefined;
|
|
49
51
|
const calls = details == null ? [] : data(details, "calls");
|
|
50
52
|
if (typeof code !== "string" || !Array.isArray(content) || details === missing || calls === missing || calls != null && !Array.isArray(calls)) { this.supported = false; return true; }
|
|
51
53
|
this.code = code; this.content = content; this.calls = calls ?? []; this.details = details; this.visibleContent = [];
|
|
54
|
+
const status = data(details, "status"), warning = data(details, "warning"), warnings = data(details, "warnings");
|
|
55
|
+
const hasWarnings = Array.isArray(warnings) ? warnings.length > 0 : !!warnings;
|
|
56
|
+
this.clean = !warning && !hasWarnings && (status === undefined || ["success", "ok", "completed"].includes(status));
|
|
52
57
|
for (let i = 0; i < content.length; i++) {
|
|
53
58
|
this.aggregateBlocks++;
|
|
54
59
|
const block = data(content, String(i));
|
|
@@ -56,6 +61,7 @@ export class CodeContent {
|
|
|
56
61
|
if (type === "image" && typeof data(block, "mimeType") === "string" && typeof data(block, "data") === "string") {
|
|
57
62
|
this.images++; this.visibleContent.push({ block, index: i });
|
|
58
63
|
} else if (type === "text" && typeof data(block, "text") === "string") {
|
|
64
|
+
if (i === 0) this.hasScriptHeader = data(block, "text").length < 160 && scriptHeader.test(data(block, "text"));
|
|
59
65
|
if (data(block, "text").length) this.visibleContent.push({ block, index: i });
|
|
60
66
|
} else { this.supported = false; return true; }
|
|
61
67
|
}
|
|
@@ -68,6 +74,7 @@ export class CodeContent {
|
|
|
68
74
|
if (status === "error") this.errors++;
|
|
69
75
|
if (status === "cancelled") this.cancelled++;
|
|
70
76
|
if (status === "running") this.unresolved++;
|
|
77
|
+
if (status !== "ok" || data(call, "error")) this.clean = false;
|
|
71
78
|
if (cost) { this.priced++; this.totalCost += cost; }
|
|
72
79
|
}
|
|
73
80
|
this.intent = codeIntent(args, this.calls);
|
package/src/modern-code-pane.ts
CHANGED
|
@@ -9,12 +9,14 @@ export class CodePane {
|
|
|
9
9
|
title = "codemode · Preparing"; theme?: any; tone = "syntaxVariable";
|
|
10
10
|
content = new CodeContent();
|
|
11
11
|
private rows: string[] = []; private iterator?: Iterator<string>; private done = false; private width = 0;
|
|
12
|
-
private lastWidth = 0; private lastHeight = 0;
|
|
12
|
+
private lastWidth = 0; private lastHeight = 0; private lastBodyHeight = 0; private lastMore = false;
|
|
13
13
|
private startedAt?: number; private endedAt?: number; private interval?: ReturnType<typeof setInterval>;
|
|
14
14
|
private themeKey = "";
|
|
15
15
|
private partial = false; private isError = false; private durationMs?: number;
|
|
16
|
+
private revision = -1;
|
|
16
17
|
paintedRows = 0;
|
|
17
18
|
constructor(private height: () => number) {}
|
|
19
|
+
get duration() { return this.durationMs; }
|
|
18
20
|
get clock() { return { startedAt: this.startedAt, endedAt: this.endedAt }; }
|
|
19
21
|
adoptClock(clock: { startedAt?: number; endedAt?: number }) { this.startedAt ??= clock.startedAt; this.endedAt ??= clock.endedAt; }
|
|
20
22
|
suspend() { if (this.interval !== undefined) clearInterval(this.interval); this.interval = undefined; }
|
|
@@ -24,11 +26,14 @@ export class CodePane {
|
|
|
24
26
|
setTheme(theme: any) {
|
|
25
27
|
const tokens = ["text", "toolTitle", "toolOutput", "mdCodeBlock", "muted", "dim", "warning", "error", "success", "syntaxKeyword", "syntaxString", "syntaxComment", "syntaxNumber", "syntaxFunction", "syntaxOperator", "syntaxPunctuation", "syntaxType", "syntaxVariable", "toolDiffAdded", "toolDiffRemoved"];
|
|
26
28
|
const key = tokens.map(token => theme?.fg(token, "x") ?? "x").join("") + (theme?.bg("selectedBg", "x") ?? "x") + (theme?.bold("x") ?? "x");
|
|
27
|
-
|
|
29
|
+
const changed = key !== this.themeKey;
|
|
30
|
+
if (changed) { this.themeKey = key; this.reset(); }
|
|
28
31
|
this.theme = theme;
|
|
32
|
+
return changed;
|
|
29
33
|
}
|
|
30
34
|
update(args: any, result: any, revision: number, context: any) {
|
|
31
|
-
|
|
35
|
+
this.content.update(args, result, revision);
|
|
36
|
+
if (revision !== this.revision) { this.revision = revision; this.reset(); }
|
|
32
37
|
if (context.executionStarted) this.startedAt ??= Date.now();
|
|
33
38
|
if (this.durationMs !== context.durationMs || this.isError !== context.isError) this.reset();
|
|
34
39
|
this.partial = context.isPartial; this.isError = context.isError; this.durationMs = context.durationMs;
|
|
@@ -46,6 +51,13 @@ export class CodePane {
|
|
|
46
51
|
}
|
|
47
52
|
return false;
|
|
48
53
|
}
|
|
54
|
+
*contentRows(width: number, theme = this.theme, grouped = false): Generator<string> {
|
|
55
|
+
if (grouped && this.durationMs !== undefined && !this.content.hasScriptHeader) {
|
|
56
|
+
const timing = `Took ${(this.durationMs / 1000).toFixed(2)}s`;
|
|
57
|
+
yield theme ? theme.fg("muted", timing) : timing;
|
|
58
|
+
}
|
|
59
|
+
yield* this.content.rows(width, theme, this.isError, !grouped && (this.durationMs !== undefined || this.startedAt !== undefined));
|
|
60
|
+
}
|
|
49
61
|
render(width: number): string[] {
|
|
50
62
|
this.lastWidth = width;
|
|
51
63
|
const contentWidth = cardContentWidth(width);
|
|
@@ -59,11 +71,11 @@ export class CodePane {
|
|
|
59
71
|
this.theme.fg(this.tone === "error" ? "error" : this.tone === "warning" && /^ · \d+ nested (?:errors?|cancelled|unresolved)$/.test(part) ? "warning" : "muted", part)).join("")
|
|
60
72
|
: title;
|
|
61
73
|
const header = activityRow(styled, width, this.theme, this.focused);
|
|
62
|
-
if (!this.open) { this.lastHeight = 1; return [header]; }
|
|
74
|
+
if (!this.open) { this.lastHeight = 1; this.lastBodyHeight = 0; this.lastMore = false; return [header]; }
|
|
63
75
|
const indent = contentWidth >= 4 ? " " : "";
|
|
64
76
|
const nativeWidth = Math.max(1, contentWidth - indent.length);
|
|
65
77
|
if (this.width !== nativeWidth) { this.reset(); this.width = nativeWidth; this.offset = 0; }
|
|
66
|
-
this.iterator ??= this.
|
|
78
|
+
this.iterator ??= this.contentRows(nativeWidth);
|
|
67
79
|
const bodyHeight = Math.max(1, Math.min(20, this.height()) - 2);
|
|
68
80
|
this.offset = Math.min(this.offset, this.rows.length);
|
|
69
81
|
while (!this.done && this.rows.length <= this.offset + bodyHeight) {
|
|
@@ -85,8 +97,9 @@ export class CodePane {
|
|
|
85
97
|
// heading so a narrow terminal does not lose the timing information.
|
|
86
98
|
if (!this.partial && this.durationMs !== undefined && visibleWidth(title) > contentWidth) timer = `Took ${duration(this.durationMs)}`;
|
|
87
99
|
else if (this.durationMs === undefined && this.startedAt !== undefined) timer = `${this.partial ? "Elapsed" : "Took"} ${duration((this.endedAt ?? Date.now()) - this.startedAt)}`;
|
|
88
|
-
const footer = [timer, this.focused ?
|
|
100
|
+
const footer = [more ? "more ↓" : this.offset > 0 ? "more ↑" : "", timer, this.focused ? "Enter collapse · ↑/↓ scroll · Home start · Esc release" : ""].filter(Boolean).join(" · ");
|
|
89
101
|
const visible = [header, ...body, ...(footer ? [activityRow(this.theme ? this.theme.fg("muted", truncateToWidth(footer, contentWidth)) : truncateToWidth(footer, contentWidth), width, this.theme)] : [])];
|
|
102
|
+
this.lastBodyHeight = body.length; this.lastMore = more;
|
|
90
103
|
this.lastHeight = visible.length; return visible;
|
|
91
104
|
}
|
|
92
105
|
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
@@ -95,6 +108,7 @@ export class CodePane {
|
|
|
95
108
|
if (event.type !== "click" || event.button !== "left") return undefined;
|
|
96
109
|
if (event.shift || event.alt || event.ctrl) return { handled: true, render: false };
|
|
97
110
|
if (event.y === 0) { this.open = !this.open; this.offset = 0; return { handled: true }; }
|
|
111
|
+
if (this.open && (this.lastMore || this.offset > 0) && event.y === this.lastHeight - 1) { this.offset = Math.max(0, this.offset + (this.lastMore ? 1 : -1) * Math.max(1, this.lastBodyHeight)); return { handled: true }; }
|
|
98
112
|
return { handled: true, render: false };
|
|
99
113
|
}
|
|
100
114
|
invalidate() { this.reset(); }
|
package/src/modern-thinking.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { hiddenThinkingShape, mixedThinkingRegion, installModernThinkingAdapter
|
|
|
5
5
|
import { recordedPaneHeight } from "./modern-recorded-pane.ts";
|
|
6
6
|
import { ToolPane, type PaneAction } from "./modern-tool-pane.ts";
|
|
7
7
|
|
|
8
|
-
type Round = { id: number; sources?: string[]; action?: PaneAction; message: any; hasThinking: boolean; component?: any; kind: "round" | "bridge" | "boundary"; group?: ThinkingGroup };
|
|
8
|
+
type Round = { id: number; sources?: string[]; action?: PaneAction; message: any; hasThinking: boolean; joinsPrevious: boolean; component?: any; kind: "round" | "bridge" | "boundary"; group?: ThinkingGroup };
|
|
9
9
|
type ThinkingGroup = { members: Round[]; pane: ToolPane; activeEpoch?: number; activeResult?: boolean };
|
|
10
10
|
/** The label is an extract from recorded text, never a generated summary.
|
|
11
11
|
* Limit work even when the first line has millions of characters. */
|
|
@@ -19,6 +19,21 @@ export function recordedThinkingLabel(sources: readonly string[]): string {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const hasThinking = (message: any) => (message?.content || []).some((b: any) => b.type === "thinking" && typeof b.thinking === "string" && b.thinking.trim());
|
|
22
|
+
// A leading run can join earlier rounds only before the first visible reply.
|
|
23
|
+
// Track this separately from the broad boundary kind during streaming updates.
|
|
24
|
+
const joinsPreviousThinking = (message: any): boolean => {
|
|
25
|
+
if (["error", "aborted", "length"].includes(message?.stopReason)) return false;
|
|
26
|
+
let runs = 0, inRun = false, firstVisible: string | undefined, hasText = false;
|
|
27
|
+
for (const block of message?.content || []) {
|
|
28
|
+
if (!["thinking", "text", "toolCall"].includes(block.type) || block.type === "toolCall" && ["ask_user_question", "question"].includes(block.name)) return false;
|
|
29
|
+
if (block.type !== "thinking") inRun = false;
|
|
30
|
+
if (block.type === "thinking" && block.thinking?.trim()) {
|
|
31
|
+
firstVisible ??= "thinking";
|
|
32
|
+
if (!inRun) { runs++; inRun = true; }
|
|
33
|
+
} else if (block.type === "text" && block.text?.trim()) { firstVisible ??= "text"; hasText = true; }
|
|
34
|
+
}
|
|
35
|
+
return hasText && firstVisible === "thinking" && runs === 1;
|
|
36
|
+
};
|
|
22
37
|
const supportedThinking = (component: any, message: any) => hiddenThinkingShape(component, message) || !!mixedThinkingRegion(component, message);
|
|
23
38
|
const classify = (message: any): Round["kind"] => {
|
|
24
39
|
if (["error", "aborted", "length"].includes(message?.stopReason) || (message?.content || []).some((b: any) => b.type === "text" && b.text?.trim() || b.type === "toolCall" && ["ask_user_question", "question"].includes(b.name))) return "boundary";
|
|
@@ -57,10 +72,12 @@ export class ModernThinkingGroups {
|
|
|
57
72
|
return;
|
|
58
73
|
}
|
|
59
74
|
let record = this.aliases.get(message) || (phase === "start" ? undefined : this.live);
|
|
60
|
-
if (!record) { record = { id: this.records.length, message, hasThinking: hasThinking(message), kind: classify(message) }; this.records.push(record); this.dirty = true; }
|
|
75
|
+
if (!record) { record = { id: this.records.length, message, hasThinking: hasThinking(message), joinsPrevious: joinsPreviousThinking(message), kind: classify(message) }; this.records.push(record); this.dirty = true; }
|
|
61
76
|
// Native streaming messages can share a mutated content array.
|
|
62
77
|
const thinking = hasThinking(message);
|
|
63
78
|
if (record.hasThinking !== thinking) { record.hasThinking = thinking; this.dirty = true; }
|
|
79
|
+
const joinsPrevious = joinsPreviousThinking(message);
|
|
80
|
+
if (record.joinsPrevious !== joinsPrevious) { record.joinsPrevious = joinsPrevious; this.dirty = true; }
|
|
64
81
|
record.message = message; this.aliases.set(message, record);
|
|
65
82
|
const kind = classify(message);
|
|
66
83
|
if (record.kind !== kind) { record.kind = kind; this.dirty = true; }
|
|
@@ -90,8 +107,13 @@ export class ModernThinkingGroups {
|
|
|
90
107
|
for (const record of this.records) {
|
|
91
108
|
if (record) record.group = undefined;
|
|
92
109
|
if (!record || record.kind === "boundary") {
|
|
110
|
+
const message = record?.message;
|
|
111
|
+
const mixed = record && hasThinking(message) && message.content.some((block: any) => block.type === "text" && block.text?.trim());
|
|
112
|
+
// Leading thinking precedes this reply boundary and belongs with the
|
|
113
|
+
// previous rounds. Text-first runs and failed/question messages stay separate.
|
|
114
|
+
if (!record?.joinsPrevious) flush();
|
|
115
|
+
if (mixed) members.push(record);
|
|
93
116
|
flush();
|
|
94
|
-
if (record && hasThinking(record.message) && record.message.content.some((block: any) => block.type === "text" && block.text?.trim())) { members.push(record); flush(); }
|
|
95
117
|
}
|
|
96
118
|
else if (record.kind === "round") members.push(record);
|
|
97
119
|
}
|
package/src/modern-tool-pane.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { activityRow, cardContentWidth } from "./display-card.ts";
|
|
|
5
5
|
|
|
6
6
|
type RowKind = "section" | "field" | "answer";
|
|
7
7
|
export type PaneContent = string | { text: string; kind?: RowKind; indent?: number; label?: string } & TextFormat;
|
|
8
|
-
export type PaneAction = { id: string; label: string; repeatedSummary?: string; sections: () => Iterable<PaneContent>; details?: () => Iterable<PaneContent> };
|
|
8
|
+
export type PaneAction = { id: string; label: string; repeatedSummary?: string; sections: () => Iterable<PaneContent>; rows?: (width: number, theme: any) => Iterable<string>; details?: () => Iterable<PaneContent> };
|
|
9
9
|
// Render only visited text chunks. Never split/highlight an entire result to paint a viewport.
|
|
10
10
|
export function* textRows(text: string, width: number): Generator<string> {
|
|
11
11
|
yield* richTextRows(text, width);
|
|
@@ -39,15 +39,19 @@ export class ToolPane {
|
|
|
39
39
|
private lastWidth = 0;
|
|
40
40
|
private lastHeight = 0;
|
|
41
41
|
private lastBodyHeight = 0;
|
|
42
|
+
private lastMore = false;
|
|
43
|
+
private contentFocused = false;
|
|
44
|
+
private preserveFocusLayout = false;
|
|
42
45
|
// Instrumentation also makes the large-output contract testable without wall-clock assertions.
|
|
43
46
|
paintedRows = 0;
|
|
44
47
|
constructor(public actions: PaneAction[], public title: string, private height = () => 12) {}
|
|
45
48
|
private get directDetails() { return this.directContent || this.itemName === "action" && this.actions.length === 1; }
|
|
46
|
-
reset() { this.anchor = Math.min(this.anchor, Math.max(0, this.actions.length - 1)); this.key = ""; this.rows = []; this.iterator = undefined; this.done = false; this.actionRows.clear(); this.detailsRows.clear(); this.rowKinds.clear(); }
|
|
49
|
+
reset() { this.preserveFocusLayout = false; this.anchor = Math.min(this.anchor, Math.max(0, this.actions.length - 1)); this.key = ""; this.rows = []; this.iterator = undefined; this.done = false; this.actionRows.clear(); this.detailsRows.clear(); this.rowKinds.clear(); }
|
|
47
50
|
collapse() { this.open = false; this.focused = false; this.selected = 0; this.anchor = 0; this.offset = 0; this.expanded.clear(); this.detailsExpanded.clear(); this.detailsFocused = false; this.reset(); }
|
|
48
51
|
releaseInspection() { if (this.detailsFocused) { this.detailsFocused = false; this.offset = 0; this.reset(); } }
|
|
52
|
+
select(index: number) { this.selected = Math.max(0, Math.min(index, this.actions.length - 1)); this.detailsFocused = false; this.anchor = this.selected; this.open = true; this.offset = 0; this.reset(); }
|
|
49
53
|
handle(data: string): boolean {
|
|
50
|
-
if (matchesKey(data, "home")) { this.
|
|
54
|
+
if (matchesKey(data, "home")) { this.select(0); return true; }
|
|
51
55
|
if (matchesKey(data, "enter")) {
|
|
52
56
|
const action = this.actions[this.selected];
|
|
53
57
|
if (this.detailsFocused && action?.details) {
|
|
@@ -65,8 +69,7 @@ export class ToolPane {
|
|
|
65
69
|
}
|
|
66
70
|
if (matchesKey(data, "right") || matchesKey(data, "tab") || matchesKey(data, "left") || matchesKey(data, "shift+tab")) {
|
|
67
71
|
const direction = matchesKey(data, "left") || matchesKey(data, "shift+tab") ? -1 : 1;
|
|
68
|
-
this.
|
|
69
|
-
this.detailsFocused = false; this.anchor = this.selected; this.open = true; this.offset = 0; this.reset(); return true;
|
|
72
|
+
this.select((this.selected + direction + this.actions.length) % Math.max(1, this.actions.length)); return true;
|
|
70
73
|
}
|
|
71
74
|
if (["up", "down", "pageUp", "pageDown"].some(key => matchesKey(data, key as any))) {
|
|
72
75
|
const distance = matchesKey(data, "pageUp") || matchesKey(data, "pageDown") ? Math.max(1, this.height() - 4) : 1;
|
|
@@ -107,17 +110,21 @@ export class ToolPane {
|
|
|
107
110
|
const emitRows = function* (this: ToolPane, rows: Iterable<{ text: string; kind?: RowKind }>) {
|
|
108
111
|
for (const row of rows) { if (row.kind) this.rowKinds.set(this.rows.length, row.kind); yield row.text; }
|
|
109
112
|
}.bind(this);
|
|
110
|
-
const fullLabel = this.directDetails ? `▾ ${this.expandedTitle ?? this.title}${this.
|
|
113
|
+
const fullLabel = this.directDetails ? `▾ ${this.expandedTitle ?? this.title}${this.contentFocused ? " · focused" : ""}` : prefix + action.label;
|
|
111
114
|
const summary = visibleWidth(fullLabel) <= width ? action.repeatedSummary : undefined;
|
|
115
|
+
const primaryRows = function* (this: ToolPane) {
|
|
116
|
+
if (action.rows) for (const row of action.rows(Math.max(1, width - detailsIndent.length), this.theme)) yield { text: detailsIndent + row };
|
|
117
|
+
else yield* sectionRows(action.sections(), summary);
|
|
118
|
+
}.bind(this);
|
|
112
119
|
if (this.detailsFocused && index === this.selected) {
|
|
113
120
|
// Keep short output inline; probe at most one viewport before anchoring at Details.
|
|
114
|
-
const primary =
|
|
115
|
-
const budget = Math.max(1, Math.min(20, this.height()) - (this.
|
|
121
|
+
const primary = primaryRows(), preview = [];
|
|
122
|
+
const budget = Math.max(1, Math.min(20, this.height()) - (this.contentFocused ? 2 : 1) - (this.directDetails ? 0 : 1) - 1);
|
|
116
123
|
let complete = false;
|
|
117
124
|
while (preview.length <= budget) { const row = primary.next(); if (row.done) { complete = true; break; } preview.push(row.value); }
|
|
118
125
|
if (complete) yield* emitRows(preview);
|
|
119
126
|
else { this.contentAnchoredAbove = true; yield detailsIndent + (this.theme ? this.theme.fg("dim", "content above ↑") : "content above ↑"); }
|
|
120
|
-
} else yield* emitRows(
|
|
127
|
+
} else yield* emitRows(primaryRows());
|
|
121
128
|
if (action.details) {
|
|
122
129
|
this.detailsRows.set(this.rows.length, index);
|
|
123
130
|
yield detailsIndent + `${this.detailsExpanded.has(action.id) ? "▾" : "▸"} Details`;
|
|
@@ -136,10 +143,14 @@ export class ToolPane {
|
|
|
136
143
|
return activityRow(line, outerWidth, this.theme, selected);
|
|
137
144
|
};
|
|
138
145
|
const header = this.styleHeader(`${this.open ? "▾" : "▸"} ${this.open ? this.expandedTitle ?? this.title : this.title}${this.focused ? " · focused" : ""}`);
|
|
139
|
-
if (!this.open) { this.lastHeight = 1; this.lastBodyHeight = 0; return [paint(truncateToWidth(header, width), this.focused && !this.detailsFocused)]; }
|
|
146
|
+
if (!this.open) { this.lastHeight = 1; this.lastBodyHeight = 0; this.lastMore = false; return [paint(truncateToWidth(header, width), this.focused && !this.detailsFocused)]; }
|
|
140
147
|
const height = Math.max(5, Math.min(20, this.height()));
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
if (this.focused || this.offset === 0) this.preserveFocusLayout = false;
|
|
149
|
+
// Mouse scrolling releases keyboard focus. Keep the already visited source layout
|
|
150
|
+
// so that release cannot reset its offset or reformat an unbounded prefix.
|
|
151
|
+
const contentFocused = this.preserveFocusLayout ? this.contentFocused : this.focused;
|
|
152
|
+
const key = `${width}:${contentFocused}:${this.expandedTitle ?? this.title}:${this.directDetails}:${this.anchor}:${this.selected}:${[...this.expanded].join("|")}:${[...this.detailsExpanded].join("|")}:${this.detailsFocused}`;
|
|
153
|
+
if (key !== this.key) { this.reset(); this.key = key; this.contentFocused = contentFocused; this.iterator = this.body(width); }
|
|
143
154
|
let bodyHeight = height - (this.focused ? 2 : 1);
|
|
144
155
|
// Clamp a seek to one viewport beyond visited content; a key press cannot scan unbounded data.
|
|
145
156
|
this.offset = Math.min(this.offset, this.rows.length);
|
|
@@ -148,14 +159,16 @@ export class ToolPane {
|
|
|
148
159
|
if (next.done) this.done = true;
|
|
149
160
|
else { this.rows.push(truncateToWidth(next.value, width)); this.paintedRows++; }
|
|
150
161
|
}
|
|
162
|
+
// Keep the footer and body height stable after paging to the end. Otherwise
|
|
163
|
+
// the pointer can leave the pane when the downward control disappears.
|
|
164
|
+
if (!this.focused && (!this.done || this.rows.length > bodyHeight)) bodyHeight--;
|
|
151
165
|
if (this.done) this.offset = Math.min(this.offset, Math.max(0, this.rows.length - bodyHeight));
|
|
152
|
-
|
|
153
|
-
if (!this.focused && more) { bodyHeight--; more = !this.done || this.offset + bodyHeight < this.rows.length; }
|
|
166
|
+
const more = !this.done || this.offset + bodyHeight < this.rows.length;
|
|
154
167
|
const selectedAction = this.actions[this.selected];
|
|
155
168
|
const detailsTarget = this.detailsFocused && !!selectedAction?.details;
|
|
156
169
|
const isExpanded = detailsTarget ? this.detailsExpanded.has(selectedAction.id) : this.directDetails || this.expanded.has(selectedAction?.id);
|
|
157
170
|
const controls = detailsTarget ? `Enter ${isExpanded ? "collapse" : "expand"} Details · Tab action` : `${this.directDetails ? "Enter collapse" : `←/→ ${this.itemName} · Enter ${isExpanded ? "collapse" : "expand"}`}${selectedAction?.details ? " · Tab Details" : ""}`;
|
|
158
|
-
const footer = this.focused ? `${controls} · ↑/↓ scroll · Esc release
|
|
171
|
+
const footer = [more ? "more ↓" : this.offset > 0 ? "more ↑" : "", this.focused ? `${controls} · ↑/↓ scroll · Esc release` : ""].filter(Boolean).join(" · ");
|
|
159
172
|
const body = this.rows.slice(this.offset, this.offset + bodyHeight).map((line, index) => {
|
|
160
173
|
const action = this.actionRows.get(this.offset + index);
|
|
161
174
|
const details = this.detailsRows.get(this.offset + index);
|
|
@@ -168,7 +181,7 @@ export class ToolPane {
|
|
|
168
181
|
return paint(line, selected);
|
|
169
182
|
});
|
|
170
183
|
const visible = [paint(truncateToWidth(header, width), this.focused && !this.detailsFocused), ...body, ...(footer ? [paint(truncateToWidth(this.theme ? this.theme.fg("dim", footer) : footer, width))] : [])];
|
|
171
|
-
this.lastBodyHeight = body.length;
|
|
184
|
+
this.lastBodyHeight = body.length; this.lastMore = more;
|
|
172
185
|
this.lastHeight = visible.length;
|
|
173
186
|
return visible;
|
|
174
187
|
}
|
|
@@ -176,6 +189,7 @@ export class ToolPane {
|
|
|
176
189
|
if (event.x < 0 || event.x >= this.lastWidth || event.y < 0 || event.y >= this.lastHeight) return undefined;
|
|
177
190
|
if (event.type === "wheel") {
|
|
178
191
|
if (!this.open || !Number.isFinite(event.wheelDelta) || !event.wheelDelta) return undefined;
|
|
192
|
+
this.preserveFocusLayout = true;
|
|
179
193
|
if (event.wheelDelta < 0 && this.contentAnchoredAbove && this.offset === 0) this.releaseInspection();
|
|
180
194
|
else this.offset = Math.max(0, this.offset + Math.max(-20, Math.min(20, Math.trunc(event.wheelDelta))));
|
|
181
195
|
return { handled: true };
|
|
@@ -183,7 +197,8 @@ export class ToolPane {
|
|
|
183
197
|
if (event.type !== "click" || event.button !== "left") return undefined;
|
|
184
198
|
// Keep text selection gestures and output clicks from falling through to native whole-row expansion.
|
|
185
199
|
if (event.shift || event.alt || event.ctrl) return { handled: true, render: false };
|
|
186
|
-
if (event.y === 0) { this.detailsFocused = false; this.open = !this.open; return { handled: true }; }
|
|
200
|
+
if (event.y === 0) { this.preserveFocusLayout = false; this.detailsFocused = false; this.open = !this.open; return { handled: true }; }
|
|
201
|
+
if (this.open && (this.lastMore || this.offset > 0) && event.y === this.lastHeight - 1) { this.preserveFocusLayout = true; this.offset = Math.max(0, this.offset + (this.lastMore ? 1 : -1) * Math.max(1, this.lastBodyHeight)); return { handled: true }; }
|
|
187
202
|
const details = this.detailsRows.get(this.offset + event.y - 1);
|
|
188
203
|
if (this.open && event.y >= 1 && event.y < 1 + this.lastBodyHeight && details !== undefined) {
|
|
189
204
|
const id = this.actions[details]?.id;
|