@notrico/pi-fold 0.0.0-stage → 3.0.0
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 +129 -0
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/docs/implementation.md +47 -0
- package/docs/performance.md +118 -0
- package/docs/renderer-reference.md +110 -0
- package/index.ts +53 -0
- package/package.json +55 -4
- package/scripts/performance-review.mjs +273 -0
- package/scripts/preview-work-strip.mjs +84 -0
- package/scripts/preview.mjs +232 -0
- package/scripts/retained-memory-review.mjs +46 -0
- package/scripts/test.mjs +21 -0
- package/src/action-intent.ts +93 -0
- package/src/display-card.ts +64 -0
- package/src/display-line-cache.ts +26 -0
- package/src/display-mode.ts +33 -0
- package/src/fold-command.ts +61 -0
- package/src/inspection.ts +87 -0
- package/src/modern-code-content.ts +131 -0
- package/src/modern-code-pane.ts +101 -0
- package/src/modern-native-tools.ts +79 -0
- package/src/modern-prompts-adapter.ts +41 -0
- package/src/modern-prompts.ts +185 -0
- package/src/modern-recorded-pane.ts +68 -0
- package/src/modern-rich-text.ts +48 -0
- package/src/modern-skill-prompts.ts +152 -0
- package/src/modern-subagent-groups.ts +158 -0
- package/src/modern-subagent-messages.ts +176 -0
- package/src/modern-subagent-spacing.ts +35 -0
- package/src/modern-subagents.ts +52 -0
- package/src/modern-thinking-adapter.ts +85 -0
- package/src/modern-thinking.ts +236 -0
- package/src/modern-tool-content.ts +28 -0
- package/src/modern-tool-images.ts +63 -0
- package/src/modern-tool-pane.ts +208 -0
- package/src/modern-tools.ts +509 -0
- package/src/modern-workflows.ts +209 -0
- package/src/native-method-chain.ts +31 -0
- package/src/permission-presentation.ts +280 -0
- package/src/recorded-summary.ts +13 -0
- package/src/work-strip-subagents.ts +221 -0
- package/src/work-strip-view.ts +104 -0
- package/src/work-strip.ts +443 -0
- package/tests/action-intent.test.mjs +44 -0
- package/tests/codemode.test.mjs +365 -0
- package/tests/display-cache-lifecycle.test.mjs +55 -0
- package/tests/display-line-cache.test.mjs +48 -0
- package/tests/display-mode.test.mjs +25 -0
- package/tests/fixtures/preview-fixture.ts +81 -0
- package/tests/fold-command.test.mjs +150 -0
- package/tests/fold-shortcut.test.mjs +143 -0
- package/tests/input-focus.test.mjs +95 -0
- package/tests/inspection.test.mjs +50 -0
- package/tests/mixed-thinking.test.mjs +319 -0
- package/tests/modern-prompts.test.mjs +84 -0
- package/tests/modern-skill-prompts.test.mjs +174 -0
- package/tests/modern-subagent-groups.test.mjs +132 -0
- package/tests/modern-subagent-messages.test.mjs +137 -0
- package/tests/modern-thinking.test.mjs +202 -0
- package/tests/modern-tools.test.mjs +908 -0
- package/tests/modern-workflows.test.mjs +147 -0
- package/tests/ordinary-prompts.test.mjs +167 -0
- package/tests/permission-presentation.test.mjs +257 -0
- package/tests/preview-example.test.mjs +171 -0
- package/tests/reload-lifecycle.test.mjs +161 -0
- package/tests/subagent-spacing.test.mjs +34 -0
- package/tests/test-runtime.mjs +58 -0
- package/tests/work-strip-final-surface.test.mjs +271 -0
- package/tests/work-strip-hierarchy.test.mjs +258 -0
- package/tests/work-strip-preview.test.mjs +120 -0
- package/tests/work-strip-spacing.test.mjs +208 -0
- package/tests/work-strip-subagents.test.mjs +236 -0
- package/tests/work-strip.test.mjs +148 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { loadSource, core, tui, themeModule, stripAnsi } from './test-runtime.mjs';
|
|
4
|
+
|
|
5
|
+
const { registerModernThinking } = await loadSource('./modern-thinking.ts');
|
|
6
|
+
const { createDisplayMode } = await loadSource('./display-mode.ts');
|
|
7
|
+
const { AssistantMessageComponent } = core;
|
|
8
|
+
const native = Object.fromEntries(['updateContent', 'render', 'handleMouse'].map(key => [key, AssistantMessageComponent.prototype[key]]));
|
|
9
|
+
const plain = lines => lines.map(stripAnsi).join('\n');
|
|
10
|
+
const thinking = text => ({ type: 'thinking', thinking: text });
|
|
11
|
+
const text = value => ({ type: 'text', text: value });
|
|
12
|
+
const tool = id => ({ type: 'toolCall', id, name: 'read', arguments: { path: '/synthetic' } });
|
|
13
|
+
const message = (content, extra = {}) => ({ role: 'assistant', content, stopReason: 'stop', ...extra });
|
|
14
|
+
const entry = value => ({ type: 'message', message: value });
|
|
15
|
+
const nativeCard = value => new AssistantMessageComponent(value, true, themeModule.getMarkdownTheme());
|
|
16
|
+
const subscribe = (map, key, fn) => {
|
|
17
|
+
const set = map.get(key) || new Set(); map.set(key, set); set.add(fn);
|
|
18
|
+
return () => set.delete(fn);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function fixture(messages) {
|
|
22
|
+
const listeners = new Map(), bus = new Map(), terminal = new Set(), cards = [];
|
|
23
|
+
const mode = createDisplayMode();
|
|
24
|
+
const pi = {
|
|
25
|
+
on: (event, fn) => subscribe(listeners, event, fn),
|
|
26
|
+
events: {
|
|
27
|
+
on: (event, fn) => subscribe(bus, event, fn),
|
|
28
|
+
emit: (event, data) => { for (const fn of [...bus.get(event) || []]) fn(data); },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const ctx = { mode: 'tui', sessionManager: { getBranch: () => messages.map(entry) }, ui: {
|
|
32
|
+
theme: themeModule.theme,
|
|
33
|
+
setHiddenThinkingLabel() { for (const card of cards) card.setHiddenThinkingLabel('Thinking...'); },
|
|
34
|
+
onTerminalInput(fn) { terminal.add(fn); return () => terminal.delete(fn); },
|
|
35
|
+
} };
|
|
36
|
+
const emit = (event, data = {}) => { for (const fn of [...listeners.get(event) || []]) fn(data, ctx); };
|
|
37
|
+
const dispose = registerModernThinking(pi, mode);
|
|
38
|
+
emit('session_start');
|
|
39
|
+
cards.push(...messages.map(nativeCard));
|
|
40
|
+
return {
|
|
41
|
+
cards, mode, emit, dispose, terminal,
|
|
42
|
+
key: data => [...terminal].some(fn => fn(data)?.consume),
|
|
43
|
+
choices() { const choices = []; pi.events.emit('compact-renderer:inspect:v1', { add: choice => choices.push(choice) }); return choices; },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function mouse(card, y, extra = {}, width = 80) {
|
|
48
|
+
const rows = card.render(width);
|
|
49
|
+
return card.handleMouse({ type: 'click', button: 'left', x: 3, y, screenX: 3, screenY: y,
|
|
50
|
+
width, height: rows.length, shift: false, alt: false, ctrl: false, ...extra });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function assertNativeReply(card, width = 80) {
|
|
54
|
+
const children = [...card.contentContainer.children];
|
|
55
|
+
const markdown = children.filter(child => child instanceof tui.Markdown);
|
|
56
|
+
const expected = markdown.map(child => child.render(width));
|
|
57
|
+
const rendered = card.render(width);
|
|
58
|
+
assert.deepEqual(card.contentContainer.children, children, 'render preserves native children');
|
|
59
|
+
markdown.forEach((child, index) => {
|
|
60
|
+
assert.ok(card.contentContainer.children.includes(child), 'native Markdown object survives compact rendering');
|
|
61
|
+
assert.ok(plain(rendered).includes(plain(expected[index])), 'native Markdown reply rows remain exact');
|
|
62
|
+
});
|
|
63
|
+
return rendered;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
test('pure singleton has a source summary, shared card alignment, and direct disclosure', () => {
|
|
67
|
+
const original = message([thinking('# Check the recorded fields\nExact second line.'), tool('pure')]);
|
|
68
|
+
const saved = JSON.stringify(original), f = fixture([original]);
|
|
69
|
+
try {
|
|
70
|
+
const card = f.cards[0], closed = card.render(80);
|
|
71
|
+
assert.equal(closed.length, 2);
|
|
72
|
+
assert.match(stripAnsi(closed[1]), /^ ▸ Thinking · Check the recorded fields/);
|
|
73
|
+
assert.doesNotMatch(plain(closed), /1 round|1\./);
|
|
74
|
+
assert.equal(mouse(card, 1)?.handled, true);
|
|
75
|
+
const opened = plain(card.render(80));
|
|
76
|
+
assert.match(opened, /Exact second line\./);
|
|
77
|
+
assert.doesNotMatch(opened, /1\. Check/);
|
|
78
|
+
assert.equal(f.key('\r'), false, 'mouse keeps Enter with the editor');
|
|
79
|
+
assert.equal(JSON.stringify(original), saved, 'recorded message stays exact');
|
|
80
|
+
} finally { f.dispose(); }
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('mixed singleton preserves native Markdown and OSC zones and expands directly', () => {
|
|
84
|
+
const original = message([thinking('Inspect the recorded path.\nExact private body.'), text('## Visible reply\n\nA **bold** reply with `code`.')]);
|
|
85
|
+
const saved = JSON.stringify(original), f = fixture([original]);
|
|
86
|
+
try {
|
|
87
|
+
const card = f.cards[0], closed = assertNativeReply(card);
|
|
88
|
+
assert.match(plain(closed), /Thinking · Inspect the recorded path\./);
|
|
89
|
+
assert.doesNotMatch(plain(closed), /Thinking\.\.\.|Exact private body|1 round/);
|
|
90
|
+
assert.ok(closed[0].startsWith('\x1b]133;A\x07'), 'native assistant zone starts');
|
|
91
|
+
assert.ok(closed.at(-1).includes('\x1b]133;B\x07\x1b]133;C\x07'), 'native assistant zone ends');
|
|
92
|
+
assert.equal(f.choices().length, 1);
|
|
93
|
+
f.choices()[0].focus();
|
|
94
|
+
const opened = assertNativeReply(card);
|
|
95
|
+
assert.match(plain(opened), /Exact private body\./);
|
|
96
|
+
assert.doesNotMatch(plain(opened), /1\. Inspect/);
|
|
97
|
+
assert.equal(f.key('\r'), true);
|
|
98
|
+
assert.doesNotMatch(plain(card.render(80)), /Exact private body/);
|
|
99
|
+
assert.equal(JSON.stringify(original), saved);
|
|
100
|
+
} finally { f.dispose(); }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('adjacent thinking blocks share one run and retain both original sources', () => {
|
|
104
|
+
const f = fixture([message([thinking('First source heading.\nFirst source body.'), thinking(' '), thinking('Second source body.'), text('Native answer')])]);
|
|
105
|
+
try {
|
|
106
|
+
assert.equal(f.choices().length, 1);
|
|
107
|
+
f.choices()[0].focus();
|
|
108
|
+
const rendered = plain(assertNativeReply(f.cards[0]));
|
|
109
|
+
assert.match(rendered, /First source body\./);
|
|
110
|
+
assert.match(rendered, /Second source body\./);
|
|
111
|
+
assert.equal((rendered.match(/Thinking ·/g) || []).length, 1);
|
|
112
|
+
} finally { f.dispose(); }
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('text before and after thinking retains native order and region-local mouse behavior', () => {
|
|
116
|
+
const f = fixture([message([text('Before the thinking region.\n\nAnother native paragraph.'), thinking('Local thinking summary.\nLocal body.'), text('After the thinking region.')])]);
|
|
117
|
+
try {
|
|
118
|
+
const card = f.cards[0];
|
|
119
|
+
let rows = assertNativeReply(card), p = plain(rows);
|
|
120
|
+
assert.ok(p.indexOf('Before the thinking') < p.indexOf('Thinking ·'));
|
|
121
|
+
assert.ok(p.indexOf('Thinking ·') < p.indexOf('After the thinking'));
|
|
122
|
+
const header = rows.findIndex(row => stripAnsi(row).includes('Thinking ·'));
|
|
123
|
+
assert.ok(header > 1, 'thinking is below native prose');
|
|
124
|
+
assert.equal(mouse(card, header)?.handled, true);
|
|
125
|
+
rows = assertNativeReply(card); p = plain(rows);
|
|
126
|
+
assert.match(p, /Local body\./);
|
|
127
|
+
const prose = rows.findIndex(row => stripAnsi(row).includes('After the thinking'));
|
|
128
|
+
assert.equal(mouse(card, prose)?.handled, undefined, 'native prose click does not hit pane');
|
|
129
|
+
assert.equal(f.key('\r'), false, 'mouse leaves keyboard focus with editor');
|
|
130
|
+
assert.equal(card.thinkingVisibilityOverrides.size, 0, 'pane clicks do not expand native thinking');
|
|
131
|
+
} finally { f.dispose(); }
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('multiple separated runs and unknown native child shapes keep the native fallback', () => {
|
|
135
|
+
const cases = [
|
|
136
|
+
message([thinking('First run'), text('Between'), thinking('Second run'), text('Reply')]),
|
|
137
|
+
message([thinking('Single run'), { type: 'futureContent', value: 'unknown' }, text('Reply')]),
|
|
138
|
+
];
|
|
139
|
+
for (const original of cases) {
|
|
140
|
+
const f = fixture([original]);
|
|
141
|
+
try {
|
|
142
|
+
const card = f.cards[0];
|
|
143
|
+
assert.match(plain(card.render(80)), /Thinking\.\.\./);
|
|
144
|
+
assert.doesNotMatch(plain(card.render(80)), /Thinking ·/);
|
|
145
|
+
assert.equal(f.choices().length, 0);
|
|
146
|
+
} finally { f.dispose(); }
|
|
147
|
+
}
|
|
148
|
+
const original = message([thinking('Single run'), text('Reply')]), f = fixture([original]);
|
|
149
|
+
try {
|
|
150
|
+
f.cards[0].contentContainer.addChild(new tui.Text('Unfamiliar native child', 1, 0));
|
|
151
|
+
const rendered = plain(f.cards[0].render(80));
|
|
152
|
+
assert.match(rendered, /Thinking\.\.\./);
|
|
153
|
+
assert.match(rendered, /Unfamiliar native child/);
|
|
154
|
+
assert.equal(f.choices().length, 0);
|
|
155
|
+
} finally { f.dispose(); }
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('mixed error, aborted, and length layouts retain native status rows', () => {
|
|
159
|
+
for (const stopReason of ['error', 'aborted', 'length']) {
|
|
160
|
+
const original = message([thinking('Recorded thinking'), text('Partial answer')], { stopReason, errorMessage: 'Synthetic failure' });
|
|
161
|
+
const expected = nativeCard(original).render(80), f = fixture([original]);
|
|
162
|
+
try {
|
|
163
|
+
assert.deepEqual(f.cards[0].render(80), expected);
|
|
164
|
+
assert.equal(f.choices().length, 0);
|
|
165
|
+
} finally { f.dispose(); }
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('pure failed tool calls and user questions retain native thinking fallback', () => {
|
|
170
|
+
const cases = [
|
|
171
|
+
message([thinking('Failed tool source'), tool('error')], { stopReason: 'error', errorMessage: 'Synthetic tool failure' }),
|
|
172
|
+
message([thinking('Aborted tool source'), tool('aborted')], { stopReason: 'aborted' }),
|
|
173
|
+
...['ask_user_question', 'question'].map(name => message([
|
|
174
|
+
thinking('Recorded question source'), { ...tool(name), name },
|
|
175
|
+
], { stopReason: 'toolUse' })),
|
|
176
|
+
];
|
|
177
|
+
for (const original of cases) {
|
|
178
|
+
const expected = nativeCard(original).render(80), f = fixture([original]);
|
|
179
|
+
try {
|
|
180
|
+
assert.deepEqual(f.cards[0].render(80), expected, `${original.stopReason}/${original.content[1].name} stays native`);
|
|
181
|
+
assert.match(plain(f.cards[0].render(80)), /Thinking\.\.\./);
|
|
182
|
+
assert.equal(f.choices().length, 0, 'native boundary has no compact inspection choice');
|
|
183
|
+
} finally { f.dispose(); }
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('mixed singleton isolates neighboring pure groups', () => {
|
|
188
|
+
const f = fixture([
|
|
189
|
+
message([thinking('Previous source'), tool('a')]),
|
|
190
|
+
message([thinking('Mixed source'), text('Visible reply')]),
|
|
191
|
+
message([thinking('Following source'), tool('b')]),
|
|
192
|
+
]);
|
|
193
|
+
try {
|
|
194
|
+
assert.equal(f.choices().length, 3);
|
|
195
|
+
f.cards.forEach(card => assert.match(plain(card.render(80)), /Thinking ·/));
|
|
196
|
+
assert.match(plain(f.cards[0].render(80)), /Previous source/);
|
|
197
|
+
assert.match(plain(f.cards[1].render(80)), /Mixed source/);
|
|
198
|
+
assert.match(plain(f.cards[2].render(80)), /Following source/);
|
|
199
|
+
} finally { f.dispose(); }
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('streaming pure thinking becomes an isolated mixed singleton', () => {
|
|
203
|
+
const prior = message([thinking('Previous tool round'), tool('prior')]);
|
|
204
|
+
const f = fixture([prior]);
|
|
205
|
+
try {
|
|
206
|
+
const start = message([thinking('Streaming source.\nOriginal streaming body.')]);
|
|
207
|
+
f.emit('message_start', { message: start });
|
|
208
|
+
const card = nativeCard(start); f.cards.push(card);
|
|
209
|
+
assert.equal(f.cards[0].render(80).length, 0);
|
|
210
|
+
assert.match(plain(card.render(80)), /Thinking · 2 rounds/);
|
|
211
|
+
const update = { ...start, content: [...start.content, text('Visible streaming answer')] };
|
|
212
|
+
f.emit('message_update', { message: update }); card.updateContent(update, true);
|
|
213
|
+
f.emit('message_end', { message: update });
|
|
214
|
+
assert.match(plain(f.cards[0].render(80)), /Thinking · Previous tool round/);
|
|
215
|
+
assert.match(plain(assertNativeReply(card)), /Thinking · Streaming source\./);
|
|
216
|
+
assert.equal(f.choices().length, 2);
|
|
217
|
+
} finally { f.dispose(); }
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('text-first streaming detects thinking added through the native shared content array', () => {
|
|
221
|
+
const f = fixture([]);
|
|
222
|
+
try {
|
|
223
|
+
const content = [text('Visible streaming preamble')], start = message(content);
|
|
224
|
+
f.emit('message_start', { message: start });
|
|
225
|
+
const card = nativeCard(start); f.cards.push(card);
|
|
226
|
+
assert.match(plain(card.render(80)), /Visible streaming preamble/);
|
|
227
|
+
assert.equal(f.choices().length, 0, 'initial text has no thinking group');
|
|
228
|
+
|
|
229
|
+
// Native agent-loop emits shallow message copies while providers mutate
|
|
230
|
+
// the shared content array and its blocks between streaming events.
|
|
231
|
+
content.push(thinking(''));
|
|
232
|
+
const thinkingStart = { ...start };
|
|
233
|
+
f.emit('message_update', { message: thinkingStart }); card.updateContent(thinkingStart, true);
|
|
234
|
+
card.render(80);
|
|
235
|
+
assert.equal(f.choices().length, 0, 'empty thinking does not create a group');
|
|
236
|
+
content[1].thinking = 'Late recorded source.\nLate recorded body.';
|
|
237
|
+
const update = { ...thinkingStart };
|
|
238
|
+
assert.equal(start.content, update.content);
|
|
239
|
+
f.emit('message_update', { message: update }); card.updateContent(update, true);
|
|
240
|
+
const rendered = plain(assertNativeReply(card));
|
|
241
|
+
assert.match(rendered, /Thinking · Late recorded source\./, 'first nonempty thinking update appears immediately');
|
|
242
|
+
assert.doesNotMatch(rendered, /Thinking\.\.\./);
|
|
243
|
+
assert.equal(f.choices().length, 1, 'streaming grouping does not need a session rebuild');
|
|
244
|
+
f.choices()[0].focus();
|
|
245
|
+
assert.match(plain(assertNativeReply(card)), /Late recorded body\./);
|
|
246
|
+
} finally { f.dispose(); }
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('mouse wheel stays inside the mixed thinking region and leaves prose unchanged', () => {
|
|
250
|
+
const f = fixture([message([text('Native prefix'), thinking('Bounded source.\n' + Array.from({ length: 80 }, (_, n) => `Recorded line ${n}`).join('\n')), text('Native suffix')])]);
|
|
251
|
+
try {
|
|
252
|
+
const card = f.cards[0], header = card.render(80).findIndex(row => stripAnsi(row).includes('Thinking ·'));
|
|
253
|
+
mouse(card, header);
|
|
254
|
+
const before = plain(assertNativeReply(card));
|
|
255
|
+
assert.equal(mouse(card, header + 2, { type: 'wheel', button: 'none', wheelDelta: 4 })?.handled, true);
|
|
256
|
+
const after = plain(assertNativeReply(card));
|
|
257
|
+
assert.notEqual(after, before, 'wheel moves the bounded thinking viewport');
|
|
258
|
+
assert.match(after, /Native prefix/); assert.match(after, /Native suffix/);
|
|
259
|
+
assert.equal(f.key('\r'), false);
|
|
260
|
+
} finally { f.dispose(); }
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('mode, native Ctrl+T expansion, per-run override, and disposal restore native behavior', () => {
|
|
264
|
+
const original = message([thinking('A source sentence.\nExact native body.'), text('Native reply')]);
|
|
265
|
+
const expected = nativeCard(original).render(80), f = fixture([original]);
|
|
266
|
+
try {
|
|
267
|
+
const card = f.cards[0];
|
|
268
|
+
f.mode.setEnabled(false); assert.deepEqual(card.render(80), expected);
|
|
269
|
+
f.mode.setEnabled(true); assert.match(plain(card.render(80)), /Thinking · A source sentence\./);
|
|
270
|
+
card.setHideThinkingBlock(false); assert.match(plain(card.render(80)), /Exact native body\./);
|
|
271
|
+
assert.equal(f.choices().length, 0);
|
|
272
|
+
card.setHideThinkingBlock(true); assert.match(plain(card.render(80)), /Thinking ·/);
|
|
273
|
+
card.thinkingVisibilityOverrides.set(0, false); card.updateContent(original);
|
|
274
|
+
assert.match(plain(card.render(80)), /Exact native body\./);
|
|
275
|
+
assert.equal(f.choices().length, 0);
|
|
276
|
+
card.setHideThinkingBlock(true);
|
|
277
|
+
f.choices()[0].focus(); assert.equal(f.key('\x14'), false, 'Ctrl+T reaches native handler');
|
|
278
|
+
f.dispose(); assert.deepEqual(card.render(80), expected);
|
|
279
|
+
assert.equal(f.terminal.size, 0);
|
|
280
|
+
for (const key of Object.keys(native)) assert.equal(AssistantMessageComponent.prototype[key], native[key]);
|
|
281
|
+
assert.equal(mouse(card, 1)?.handled, true, 'native thinking click works after disposal');
|
|
282
|
+
assert.match(plain(card.render(80)), /Exact native body\./);
|
|
283
|
+
} finally { f.dispose(); }
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('mixed tool-call messages retain native OSC policy', () => {
|
|
287
|
+
const f = fixture([message([thinking('Inspect tool inputs'), text('Visible preamble'), tool('mixed')], { stopReason: 'toolUse' })]);
|
|
288
|
+
try {
|
|
289
|
+
const rows = assertNativeReply(f.cards[0]);
|
|
290
|
+
assert.match(plain(rows), /Thinking · Inspect tool inputs/);
|
|
291
|
+
assert.ok(!rows.join('').includes('\x1b]133;'), 'tool-call component has no assistant OSC zones');
|
|
292
|
+
} finally { f.dispose(); }
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('large mixed thinking uses a bounded viewport across narrow widths', () => {
|
|
296
|
+
const original = message([thinking('Large recorded heading.\n' + 'Exact bounded line 行🙂\n'.repeat(100000)), text('Native reply')]);
|
|
297
|
+
const saved = JSON.stringify(original), f = fixture([original]);
|
|
298
|
+
const render = tui.Markdown.prototype.render;
|
|
299
|
+
let nativeThinkingPaints = 0;
|
|
300
|
+
tui.Markdown.prototype.render = function (...args) {
|
|
301
|
+
if (this !== f.cards[0].contentContainer.children.find(child => child instanceof tui.Markdown)) nativeThinkingPaints++;
|
|
302
|
+
return render.apply(this, args);
|
|
303
|
+
};
|
|
304
|
+
try {
|
|
305
|
+
assert.match(plain(f.cards[0].render(80)), /Thinking · Large recorded heading\./);
|
|
306
|
+
f.choices()[0].focus();
|
|
307
|
+
assert.ok(f.cards[0].render(80).length <= 20, 'thinking and native reply remain bounded');
|
|
308
|
+
assert.match(plain(f.cards[0].render(80)), /Exact bounded line/);
|
|
309
|
+
for (const width of [1, 2, 3, 8, 24, 70]) {
|
|
310
|
+
assertNativeReply(f.cards[0], width);
|
|
311
|
+
// Pi's unchanged Markdown outputPad can exceed a one/two-column width.
|
|
312
|
+
// The adapter owns only this hidden-thinking region's width contract.
|
|
313
|
+
const region = f.cards[0].contentContainer.children.find(child => child instanceof tui.MouseRegion);
|
|
314
|
+
for (const row of region.render(width)) assert.ok(tui.visibleWidth(row) <= width, `thinking row fits ${width} columns`);
|
|
315
|
+
}
|
|
316
|
+
assert.equal(nativeThinkingPaints, 0, 'large thinking does not use native full Markdown rendering');
|
|
317
|
+
assert.equal(JSON.stringify(original), saved);
|
|
318
|
+
} finally { tui.Markdown.prototype.render = render; f.dispose(); }
|
|
319
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdtempSync,writeFileSync,rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { loadSource,core,themeModule,stripAnsi } from './test-runtime.mjs';
|
|
6
|
+
const { registerModernPrompts,modernPromptTemplates,matchingModernPrompt,modernPromptSummary }=await loadSource('./modern-prompts.ts');
|
|
7
|
+
const { installModernPromptAdapter }=await loadSource('./modern-prompts-adapter.ts');
|
|
8
|
+
const { createDisplayMode }=await loadSource('./display-mode.ts');
|
|
9
|
+
const { UserMessageComponent }=core;
|
|
10
|
+
const dir=mkdtempSync(join(tmpdir(),'compact-prompts-'));
|
|
11
|
+
const path=join(dir,'fixture.md');
|
|
12
|
+
const prefix='These are the original long template instructions; keep every source character.\n\n';
|
|
13
|
+
const source=`---\ndescription: fixture\n---\n${prefix}Target: $1\n\nEnd of the original instructions.`;
|
|
14
|
+
writeFileSync(path,source);
|
|
15
|
+
const original=`${prefix}Target: sample 行🙂\n\nEnd of the original instructions.`;
|
|
16
|
+
const commands=[{source:'prompt',name:'fixture',description:'Inspect fixture cards and their keyboard controls.',sourceInfo:{path}}];
|
|
17
|
+
const listeners=new Map(),bus=new Map(),terminal=new Set(),transformers=[];
|
|
18
|
+
const subscribe=(map,key,fn)=>{const set=map.get(key)||new Set();map.set(key,set);set.add(fn);return()=>set.delete(fn);};
|
|
19
|
+
const pi={on:(event,fn)=>subscribe(listeners,event,fn),events:{on:(event,fn)=>subscribe(bus,event,fn),emit:(event,data)=>{for(const fn of [...bus.get(event)||[]])fn(data);}},getCommands:()=>commands,registerMarkdownTransformer:fn=>transformers.push(fn)};
|
|
20
|
+
const mode=createDisplayMode();let redraws=0;
|
|
21
|
+
const ctx={mode:'tui',ui:{setHiddenThinkingLabel(){redraws++;},onTerminalInput(fn){terminal.add(fn);return()=>terminal.delete(fn);}}};
|
|
22
|
+
const emit=(event,data={})=>{for(const fn of [...listeners.get(event)||[]])fn(data,ctx);};
|
|
23
|
+
const key=data=>[...terminal].some(fn=>fn(data)?.consume);
|
|
24
|
+
const plain=card=>card.render(100).map(stripAnsi).join('\n');
|
|
25
|
+
const native={render:UserMessageComponent.prototype.render,mouse:UserMessageComponent.prototype.handleMouse};
|
|
26
|
+
let dispose=registerModernPrompts(pi,mode);
|
|
27
|
+
try{
|
|
28
|
+
emit('session_start',{type:'session_start',reason:'startup'});
|
|
29
|
+
const card=new UserMessageComponent(original,themeModule.getMarkdownTheme(),1,transformers);
|
|
30
|
+
const ordinary=new UserMessageComponent('Ordinary visible user prompt',themeModule.getMarkdownTheme(),1,transformers);
|
|
31
|
+
assert.match(plain(card),/prompt · \/fixture/);assert.ok(!plain(card).includes('original long template'));
|
|
32
|
+
assert.match(plain(ordinary),/Ordinary visible user prompt/);
|
|
33
|
+
assert.match(plain(card),/Inspect fixture cards and their keyboard controls\./, 'collapsed template includes its authored description');
|
|
34
|
+
assert.equal(modernPromptSummary('First recorded sentence. More details.'), 'First recorded sentence.');
|
|
35
|
+
assert.equal(modernPromptSummary('ignored', 'Specific authored summary'), 'Specific authored summary');
|
|
36
|
+
assert.ok(modernPromptSummary('x'.repeat(1000000)).length <= 111, 'fallback excerpt is bounded');
|
|
37
|
+
assert.doesNotMatch(modernPromptSummary('\x1b[31m unsafe\u202e title'), /[\x1b\u202e]/);
|
|
38
|
+
const savedDescription=commands[0].description; commands[0].description='Use **literal** labels <tag> and `code`.';emit('session_tree');
|
|
39
|
+
assert.match(plain(card),/Use literal labels <tag> and code\./, 'summary uses native inline Markdown without adding escape characters');
|
|
40
|
+
commands[0].description=savedDescription;emit('session_tree');plain(card);
|
|
41
|
+
assert.equal(key('\r'),false);assert.equal(key('\x1bi'),true);assert.equal(key('\r'),true);
|
|
42
|
+
assert.match(plain(card),/original long template instructions/);assert.match(plain(card),/sample 行🙂/);
|
|
43
|
+
assert.equal(card.text,original,'native recorded source stays exact');
|
|
44
|
+
assert.equal(key('\x1b[B'),false,'native arrows remain available for expanded prompt scrolling');
|
|
45
|
+
assert.equal(key('\x1b'),false,'forwarded arrow releases prompt inspection');assert.equal(key('\r'),false);
|
|
46
|
+
card.handleMouse({type:'click',button:'left',y:1,x:2,width:100,height:20});assert.ok(!plain(card).includes('original long template'));
|
|
47
|
+
// Identical expanded templates remain independent cards.
|
|
48
|
+
const second=new UserMessageComponent(original,themeModule.getMarkdownTheme(),1,transformers);plain(second);
|
|
49
|
+
second.handleMouse({type:'click',button:'left',y:1,x:2,width:100,height:20});
|
|
50
|
+
assert.match(plain(second),/original long template/);assert.ok(!plain(card).includes('original long template'));
|
|
51
|
+
key('\x1bi');pi.events.emit('compact-renderer:focus:v1',{owner:'thinking'});assert.equal(key('\r'),false);
|
|
52
|
+
key('\x1bi');emit('ui_prompt_start');assert.equal(key('\r'),false);
|
|
53
|
+
mode.setEnabled(false);assert.match(plain(card),/original long template/);assert.ok(!plain(card).includes('prompt · /fixture'));
|
|
54
|
+
mode.setEnabled(true);assert.ok(!plain(card).includes('original long template'));
|
|
55
|
+
const staleChoices=[];pi.events.emit('compact-renderer:inspect:v1',{add:choice=>staleChoices.push(choice)});
|
|
56
|
+
emit('session_tree');plain(card);staleChoices[0].focus();
|
|
57
|
+
assert.equal(key('\r'),false,'a stale picker choice cannot capture Enter after rebuilding the same component');
|
|
58
|
+
const freshChoices=[];pi.events.emit('compact-renderer:inspect:v1',{add:choice=>freshChoices.push(choice)});
|
|
59
|
+
freshChoices[0].focus();assert.match(plain(card),/Esc returns/);assert.equal(key('\x1b'),true);
|
|
60
|
+
for(const event of ['session_tree','session_compact']){emit(event);assert.match(plain(card),/prompt · \/fixture/);assert.equal(terminal.size,1);}
|
|
61
|
+
for(const reason of ['reload','new','resume','fork','startup']){
|
|
62
|
+
emit('session_start',{type:'session_start',reason});assert.match(plain(card),/prompt · \/fixture/);assert.equal(terminal.size,1);
|
|
63
|
+
}
|
|
64
|
+
// Transformer alone cannot collapse a card with an unknown native shape.
|
|
65
|
+
const unknown=new UserMessageComponent(original,themeModule.getMarkdownTheme(),1,transformers);
|
|
66
|
+
assert.match(plain(unknown),/prompt · \/fixture/);
|
|
67
|
+
unknown.children.push({render:()=>[],invalidate(){}});assert.match(plain(unknown),/original long template/);
|
|
68
|
+
emit('session_shutdown');assert.equal(terminal.size,0);assert.match(plain(card),/original long template/,'shutdown restores the original content');
|
|
69
|
+
const resumedCard=new UserMessageComponent(original,themeModule.getMarkdownTheme(),1,transformers);
|
|
70
|
+
assert.match(plain(resumedCard),/original long template/,'a prebuilt card stays native before session_start');
|
|
71
|
+
emit('session_start',{type:'session_start',reason:'resume'});assert.match(plain(resumedCard),/prompt · \/fixture/,'initial resumed render invalidates prebuilt native Markdown');plain(card);assert.equal(terminal.size,1);
|
|
72
|
+
dispose();dispose();assert.equal(terminal.size,0);assert.deepEqual({render:UserMessageComponent.prototype.render,mouse:UserMessageComponent.prototype.handleMouse},native);
|
|
73
|
+
assert.match(plain(card),/original long template/);assert.equal(card.text,original);
|
|
74
|
+
dispose=registerModernPrompts(pi,mode);emit('session_start',{type:'session_start',reason:'startup'});assert.match(plain(card),/prompt · \/fixture/);
|
|
75
|
+
const staleDispose=dispose;dispose=registerModernPrompts(pi,mode);assert.equal(terminal.size,0,'replacement registration disposes the prior input listener');emit('session_start',{type:'session_start',reason:'startup'});assert.equal(terminal.size,1);staleDispose();assert.equal(terminal.size,1);
|
|
76
|
+
assert.match(plain(card),/prompt · \/fixture/);dispose();
|
|
77
|
+
assert.equal(installModernPromptAdapter({render(){},mouse(){}},'1.1.0'),undefined);
|
|
78
|
+
assert.equal(installModernPromptAdapter({render(){},mouse(){}},'9.0.0'),undefined);
|
|
79
|
+
const templates=modernPromptTemplates(commands);assert.equal(matchingModernPrompt(original,templates),'fixture');assert.equal(matchingModernPrompt('Unrelated prompt',templates),undefined);
|
|
80
|
+
assert.equal(modernPromptTemplates([...commands,{source:'extension',name:'fixture'}]).length,0);
|
|
81
|
+
assert.equal(modernPromptTemplates([{...commands[0],sourceInfo:{path:join(dir,'missing')}}]).length,0);
|
|
82
|
+
assert.equal(matchingModernPrompt('x'.repeat(200001),templates),undefined);
|
|
83
|
+
assert.ok(redraws>0);console.log('modern prompts: public display transformer, native inline expansion, keyboard, lifecycle, unknown-shape fallback, and exact sources passed');
|
|
84
|
+
}finally{dispose();rmSync(dir,{recursive:true,force:true});}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { core, jiti, runtime, loadSource, themeModule, tui, stripAnsi, assertCardBackground } from './test-runtime.mjs';
|
|
4
|
+
|
|
5
|
+
const { registerModernSkillPrompts } = await loadSource('./modern-skill-prompts.ts');
|
|
6
|
+
const { registerModernPrompts } = await loadSource('./modern-prompts.ts');
|
|
7
|
+
const { registerWorkStrip } = await loadSource('./work-strip.ts');
|
|
8
|
+
const { createDisplayMode } = await loadSource('./display-mode.ts');
|
|
9
|
+
const { projectedChildren, workEvidenceType } = await loadSource('./work-strip-view.ts');
|
|
10
|
+
const { collectPrompts } = await jiti.import(path.join(runtime, 'node_modules/pi-prompt-jump/navigation.ts'));
|
|
11
|
+
const body = '# Skill source\n\nRead the **recorded units**.\n\n- Keep missing values.\n- Preserve their original wording.\n\nSKILL_SOURCE_END';
|
|
12
|
+
const envelope = (user = 'Review the samples.') => `<skill name="fixture-review" location="/synthetic/SKILL.md">\n${body}\n</skill>${user ? '\n\n' + user : ''}`;
|
|
13
|
+
const removeOsc = line => line.replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)/g, '');
|
|
14
|
+
|
|
15
|
+
function fixture() {
|
|
16
|
+
const hooks = new Map(), bus = new Map(), inputs = new Set(), transformers = [], commands = new Map();
|
|
17
|
+
const subscribe = (map, event, fn) => { const set = map.get(event) || new Set(); map.set(event, set); set.add(fn); return () => set.delete(fn); };
|
|
18
|
+
const manager = core.SessionManager.inMemory('/synthetic-skill-prompts');
|
|
19
|
+
const pi = {
|
|
20
|
+
on: (name, fn) => subscribe(hooks, name, fn),
|
|
21
|
+
events: { on: (name, fn) => subscribe(bus, name, fn), emit(name, value) { for (const fn of [...bus.get(name) || []]) fn(value); } },
|
|
22
|
+
getCommands: () => [], getAllTools: () => [], registerMarkdownTransformer: fn => transformers.push(fn),
|
|
23
|
+
appendEntry: (kind, data) => manager.appendCustomEntry(kind, data), registerCommand: (name, definition) => commands.set(name, definition),
|
|
24
|
+
};
|
|
25
|
+
const mode = createDisplayMode();
|
|
26
|
+
const disposers = [registerModernPrompts(pi, mode), registerModernSkillPrompts(pi, mode), registerWorkStrip(pi, mode).dispose];
|
|
27
|
+
const ui = { theme: themeModule.theme, isFollowingOutput: true, requestRender() {}, setHiddenThinkingLabel() {}, onTerminalInput(fn) { inputs.add(fn); return () => inputs.delete(fn); } };
|
|
28
|
+
const ctx = { mode: 'tui', hasUI: true, ui, sessionManager: manager, isIdle: () => true };
|
|
29
|
+
const display = {
|
|
30
|
+
chatContainer: new tui.Container(), ui, pendingTools: new Map(), outputPad: 1,
|
|
31
|
+
toolOutputExpanded: false, hideThinkingBlock: true, sessionManager: manager,
|
|
32
|
+
session: { extensionRunner: { getMessageRenderer() {} } },
|
|
33
|
+
getUserMessageText: value => typeof value.content === 'string' ? value.content : value.content.filter(block => block.type === 'text').map(block => block.text).join('\n'),
|
|
34
|
+
getMarkdownThemeWithSettings: () => themeModule.getMarkdownTheme(), getMarkdownTransformers: () => transformers,
|
|
35
|
+
editor: { addToHistory() {} },
|
|
36
|
+
};
|
|
37
|
+
const event = (name, value = {}) => { for (const fn of [...hooks.get(name) || []]) fn(value, ctx); };
|
|
38
|
+
const add = message => {
|
|
39
|
+
message.timestamp ??= 1000 + manager.getBranch().length;
|
|
40
|
+
manager.appendMessage(message);
|
|
41
|
+
const before = display.chatContainer.children.length, entry = manager.getBranch().at(-1);
|
|
42
|
+
core.InteractiveMode.prototype.addMessageToChat.call(display, message);
|
|
43
|
+
return { entry, rows: display.chatContainer.children.slice(before), message };
|
|
44
|
+
};
|
|
45
|
+
const user = text => add({ role: 'user', content: text });
|
|
46
|
+
const assistant = text => add({ role: 'assistant', stopReason: 'stop', content: [{ type: 'text', text }] });
|
|
47
|
+
const tool = () => {
|
|
48
|
+
const row = new core.ToolExecutionComponent('read', 'read-skill', { path: '/synthetic/SKILL.md' }, { outputPad: 1 }, undefined, ui, '/synthetic-skill-prompts');
|
|
49
|
+
row.setArgsComplete(); row.updateResult({ content: [{ type: 'text', text: 'MODEL_READ_SKILL_TEXT' }], isError: false });
|
|
50
|
+
display.chatContainer.addChild(row); return row;
|
|
51
|
+
};
|
|
52
|
+
const paint = (width = 100) => display.chatContainer.render(width);
|
|
53
|
+
const choices = () => { paint(); const result = []; pi.events.emit('compact-renderer:inspect:v1', { add: item => result.push(item) }); return result; };
|
|
54
|
+
const key = data => { for (const fn of inputs) if (fn(data)?.consume) return true; return false; };
|
|
55
|
+
const dispose = () => { for (const cleanup of disposers.reverse()) cleanup(); mode.dispose(); };
|
|
56
|
+
return { pi, mode, manager, ui, ctx, display, event, add, user, assistant, tool, paint, choices, key, dispose, inputs, commands };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Actual native parsing creates the paired identities before session_start.
|
|
60
|
+
for (const appearance of ['dark', 'light']) for (const suffix of ['Review the samples.', '']) {
|
|
61
|
+
themeModule.initTheme(appearance, false);
|
|
62
|
+
const f = fixture();
|
|
63
|
+
try {
|
|
64
|
+
f.user('Earlier prompt.'); f.assistant('Earlier final.');
|
|
65
|
+
const submission = f.user(envelope(suffix));
|
|
66
|
+
const skill = submission.rows.find(row => row instanceof core.SkillInvocationMessageComponent);
|
|
67
|
+
const user = submission.rows.find(row => row instanceof core.UserMessageComponent);
|
|
68
|
+
const gap = user && submission.rows[submission.rows.indexOf(user) - 1];
|
|
69
|
+
const canonical = [...f.display.chatContainer.children], native = f.paint();
|
|
70
|
+
const transcript = JSON.stringify(f.manager.getBranch());
|
|
71
|
+
assert.ok(native.some(line => stripAnsi(line).includes('[skill]')));
|
|
72
|
+
f.event('session_start');
|
|
73
|
+
const rendered = skill.render(80), plain = rendered.map(stripAnsi);
|
|
74
|
+
assert.match(plain[1], /^ ▸ \/skill:fixture-review/);
|
|
75
|
+
assert.doesNotMatch(plain.join('\n'), /\[skill\]|Ctrl\+O|to expand|SKILL_SOURCE_END/);
|
|
76
|
+
assert.equal(plain.length, suffix ? 5 : 3, 'one top/bottom pad surrounds the command and optional original user text');
|
|
77
|
+
if (suffix) {
|
|
78
|
+
assert.equal(plain[2], ' '.repeat(80), 'one filled row separates command and user text');
|
|
79
|
+
assert.match(plain[3], /^ Review the samples\./);
|
|
80
|
+
assert.deepEqual(user.render(80), [], 'paired native user renders inside the combined skill anchor');
|
|
81
|
+
assert.deepEqual(gap.render(80), [], 'paired internal gap adds no outside separation');
|
|
82
|
+
assert.deepEqual(skill[projectedChildren], [user], 'inspection can find the native long-prompt identity');
|
|
83
|
+
}
|
|
84
|
+
assertCardBackground(rendered.map(removeOsc), 80, 'userMessageBg', f.ui.theme);
|
|
85
|
+
const anchors = collectPrompts(f.display.chatContainer, 100).anchors;
|
|
86
|
+
assert.equal(anchors.length, 2, 'prompt-jump retains one anchor per user envelope');
|
|
87
|
+
assert.equal(anchors.at(-1).text, '/skill:fixture-review');
|
|
88
|
+
assert.equal(anchors.at(-1).end - anchors.at(-1).row, skill.render(100).length, 'native skill anchor measures the complete combined card');
|
|
89
|
+
assert.equal(skill.handleMouse({ type: 'click', button: 'left', shift: true, x: 3, y: 1, width: 80, height: rendered.length }), undefined, 'modified clicks do not change skill disclosure');
|
|
90
|
+
assert.equal(skill.expanded, false);
|
|
91
|
+
assert.equal(skill.handleMouse({ type: 'click', button: 'left', x: 3, y: 1, width: 80, height: rendered.length })?.handled, true);
|
|
92
|
+
const expanded = skill.render(80);
|
|
93
|
+
assert.match(expanded.map(stripAnsi).join('\n'), /SKILL_SOURCE_END/);
|
|
94
|
+
assert.match(expanded.map(stripAnsi).join('\n'), /Read the recorded units\./);
|
|
95
|
+
assertCardBackground(expanded.map(removeOsc), 80, 'userMessageBg', f.ui.theme);
|
|
96
|
+
assert.equal(f.key('\r'), false, 'mouse expansion leaves editor Enter native');
|
|
97
|
+
skill.setExpanded(false); assert.doesNotMatch(skill.render(80).map(stripAnsi).join('\n'), /SKILL_SOURCE_END/, 'native Ctrl+O state remains authoritative');
|
|
98
|
+
const choice = f.choices().find(item => item.kind === 'Skill');
|
|
99
|
+
choice.focus(); assert.match(skill.render(80).map(stripAnsi).join('\n'), /SKILL_SOURCE_END/);
|
|
100
|
+
assert.equal(f.key('\r'), true); assert.doesNotMatch(skill.render(80).map(stripAnsi).join('\n'), /SKILL_SOURCE_END/);
|
|
101
|
+
assert.equal(f.key('\x1b'), true); assert.equal(f.key('\r'), false);
|
|
102
|
+
choice.focus(); assert.equal(f.key('x'), false); assert.equal(f.key('\r'), false, 'typing releases explicit skill inspection');
|
|
103
|
+
skill.setExpanded(false);
|
|
104
|
+
for (const width of [1, 2, 7, 24, 80]) {
|
|
105
|
+
const rows = skill.render(width);
|
|
106
|
+
assert.ok(rows.every(line => tui.visibleWidth(line) <= Math.max(width, 3)), `command wrapping retains native padding limits at width ${width}`);
|
|
107
|
+
}
|
|
108
|
+
skill.setExpanded(true);
|
|
109
|
+
for (const width of [1, 2, 7, 24, 80]) {
|
|
110
|
+
const rows = skill.render(width);
|
|
111
|
+
assert.ok(rows.every(line => tui.visibleWidth(line) <= Math.max(width, 3)), `full skill wrapping retains native padding limits at width ${width}`);
|
|
112
|
+
}
|
|
113
|
+
skill.setExpanded(false); f.mode.setEnabled(false);
|
|
114
|
+
assert.deepEqual(f.paint(), native, 'compact-off restores exact native skill, gap and user bytes');
|
|
115
|
+
assert.equal(skill[projectedChildren], undefined);
|
|
116
|
+
f.mode.setEnabled(true); f.paint();
|
|
117
|
+
assert.deepEqual(f.display.chatContainer.children, canonical);
|
|
118
|
+
assert.equal(JSON.stringify(f.manager.getBranch()), transcript, 'rendering never changes input or transcript entries');
|
|
119
|
+
} finally { f.dispose(); assert.equal(f.inputs.size, 0); }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The existing long-user disclosure renders inside the blue combined card;
|
|
123
|
+
// its mouse and inspection targets retain the original native user component.
|
|
124
|
+
{
|
|
125
|
+
const f = fixture();
|
|
126
|
+
try {
|
|
127
|
+
const long = 'OPENING_USER\n\n' + Array.from({ length: 12 }, (_, i) => `- ORIGINAL_MIDDLE_${i}`).join('\n') + '\n\nENDING_USER';
|
|
128
|
+
const submission = f.user(envelope(long));
|
|
129
|
+
const skill = submission.rows.find(row => row instanceof core.SkillInvocationMessageComponent);
|
|
130
|
+
const user = submission.rows.find(row => row instanceof core.UserMessageComponent);
|
|
131
|
+
f.event('session_start');
|
|
132
|
+
let rows = skill.render(80), plain = rows.map(stripAnsi);
|
|
133
|
+
assert.match(plain.join('\n'), /OPENING_USER[\s\S]*Show more[\s\S]*ENDING_USER/);
|
|
134
|
+
assert.doesNotMatch(plain.join('\n'), /ORIGINAL_MIDDLE_5/);
|
|
135
|
+
const y = plain.findIndex(line => line.includes('Show more'));
|
|
136
|
+
assert.equal(skill.handleMouse({ type: 'click', button: 'left', x: 3, y, width: 80, height: rows.length })?.handled, true, 'combined card translates the native user disclosure mouse coordinate');
|
|
137
|
+
assert.match(skill.render(80).map(stripAnsi).join('\n'), /ORIGINAL_MIDDLE_5/);
|
|
138
|
+
const promptChoice = f.choices().find(item => item.kind === 'Prompt');
|
|
139
|
+
promptChoice.focus(); assert.equal(f.key('\r'), true); assert.equal(f.key('\x1b'), true);
|
|
140
|
+
assert.equal(user.text, long);
|
|
141
|
+
assert.deepEqual(skill[projectedChildren], [user]);
|
|
142
|
+
// A custom attachment or unknown native shape must retain the whole native
|
|
143
|
+
// pair rather than disappear inside the supported combined presentation.
|
|
144
|
+
user.addChild(new tui.Text('UNKNOWN_ATTACHMENT', 0, 0));
|
|
145
|
+
rows = f.paint();
|
|
146
|
+
assert.match(rows.map(stripAnsi).join('\n'), /\[skill\][\s\S]*UNKNOWN_ATTACHMENT/);
|
|
147
|
+
assert.equal(skill[projectedChildren], undefined);
|
|
148
|
+
assert.ok(user.render(80).length > 0);
|
|
149
|
+
} finally { f.dispose(); }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Skill-only commands start their own work turn; model-initiated SKILL.md reads
|
|
153
|
+
// remain ordinary work and receive no submitted-command heading.
|
|
154
|
+
{
|
|
155
|
+
const f = fixture();
|
|
156
|
+
try {
|
|
157
|
+
const initial = f.user('Initial work.'); f.tool(); const first = f.assistant('FIRST_FINAL');
|
|
158
|
+
f.manager.appendCustomEntry(workEvidenceType, { version: 1, userId: initial.entry.id, finalId: first.entry.id, endId: first.entry.id, startedAt: 1000, endedAt: 2000, outcome: 'completed' });
|
|
159
|
+
const submission = f.user(envelope(''));
|
|
160
|
+
f.tool(); const final = f.assistant('SKILL_ONLY_FINAL');
|
|
161
|
+
f.manager.appendCustomEntry(workEvidenceType, { version: 1, userId: submission.entry.id, finalId: final.entry.id, endId: final.entry.id, startedAt: 2000, endedAt: 3000, outcome: 'completed' });
|
|
162
|
+
f.event('session_start'); f.paint();
|
|
163
|
+
const projected = f.display.chatContainer[projectedChildren];
|
|
164
|
+
assert.equal(projected.filter(row => row.constructor.name === 'WorkStripHeader').length, 2, 'skill-only envelope owns its own work fold');
|
|
165
|
+
assert.equal(f.choices().filter(item => item.kind === 'Skill').length, 1, 'model read tools do not create skill invocation controls');
|
|
166
|
+
const plain = f.paint().map(stripAnsi).join('\n');
|
|
167
|
+
assert.match(plain, /FIRST_FINAL[\s\S]*\/skill:fixture-review[\s\S]*SKILL_ONLY_FINAL/);
|
|
168
|
+
assert.doesNotMatch(plain, /MODEL_READ_SKILL_TEXT/);
|
|
169
|
+
const skill = submission.rows.find(row => row instanceof core.SkillInvocationMessageComponent);
|
|
170
|
+
assert.ok(projected.includes(skill), 'submitted command remains outside both work folds');
|
|
171
|
+
} finally { f.dispose(); }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log('Command-first skill prompts: native envelopes, one blue card, exact source, skill-only work boundaries, prompt-jump identity, long prompts, mouse/keyboard inspection, themes, narrow widths, fallback and compact-off passed');
|