@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,148 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { core, loadSource, themeModule, tui, stripAnsi } from './test-runtime.mjs';
|
|
3
|
+
const { registerWorkStrip } = await loadSource('./work-strip.ts');
|
|
4
|
+
const { createDisplayMode } = await loadSource('./display-mode.ts');
|
|
5
|
+
const { workEvidenceType, projectedChildren, recordedWorkEvidence } = await loadSource('./work-strip-view.ts');
|
|
6
|
+
const hooks = new Map(), bus = new Map(), inputs = new Set();
|
|
7
|
+
const subscribe = (map, name, fn) => { if (!map.has(name)) map.set(name, new Set()); map.get(name).add(fn); return () => map.get(name).delete(fn); };
|
|
8
|
+
let manager = core.SessionManager.inMemory('/synthetic-work'), provider = false, childrenActive = 0;
|
|
9
|
+
let ownership;
|
|
10
|
+
const pi = {
|
|
11
|
+
on: (name, fn) => subscribe(hooks, name, fn),
|
|
12
|
+
events: { on: (name, fn) => subscribe(bus, name, fn), emit: (name, value) => { for (const fn of [...(bus.get(name) || [])]) fn(value); } },
|
|
13
|
+
getAllTools: () => provider ? [{name:'subagent'}] : [],
|
|
14
|
+
appendEntry: (kind, data) => manager.appendCustomEntry(kind, data),
|
|
15
|
+
};
|
|
16
|
+
pi.events.on('compact-renderer:work-strip:v1', value => { ownership = value.ownsExecutionStatus; });
|
|
17
|
+
pi.events.on('subagents:rpc:v1:request', request => pi.events.emit(`subagents:rpc:v1:reply:${request.requestId}`, {version:1, requestId:request.requestId, method:'status', success:true, data:{fleet:{totalActive:childrenActive}}}));
|
|
18
|
+
const mode = createDisplayMode();
|
|
19
|
+
let controls = registerWorkStrip(pi, mode);
|
|
20
|
+
let dispose = controls.dispose;
|
|
21
|
+
let ownedRow, nestedOpen = true, nestedResets = 0;
|
|
22
|
+
pi.events.on('compact-renderer:disclosures:v1', request => request.add(component => component === ownedRow, nestedOpen, () => { nestedOpen = false; nestedResets++; }));
|
|
23
|
+
const ui = { isFollowingOutput: true, requestRender() {}, theme: themeModule.theme, onTerminalInput(fn) { inputs.add(fn); return () => inputs.delete(fn); } };
|
|
24
|
+
const ctx = {mode:'tui', hasUI:true, ui, get sessionManager(){return manager;}, isIdle:()=>true};
|
|
25
|
+
const event = (name, value={}) => { for (const fn of [...(hooks.get(name) || [])]) fn(value, ctx); };
|
|
26
|
+
const display = {
|
|
27
|
+
chatContainer:new tui.Container(), ui, pendingTools:new Map(), outputPad:1, toolOutputExpanded:false, hideThinkingBlock:true,
|
|
28
|
+
get sessionManager(){return manager;},
|
|
29
|
+
session:{extensionRunner:{getMessageRenderer(){}}},
|
|
30
|
+
getUserMessageText:message=>message.content,
|
|
31
|
+
getMarkdownThemeWithSettings:()=>themeModule.getMarkdownTheme(), getMarkdownTransformers:()=>[],
|
|
32
|
+
editor:{addToHistory(){}},
|
|
33
|
+
};
|
|
34
|
+
const paint = () => stripAnsi(display.chatContainer.render(100).join('\n'));
|
|
35
|
+
const add = (message) => {
|
|
36
|
+
message.timestamp ??= Date.now() + manager.getBranch().length;
|
|
37
|
+
manager.appendMessage(message);
|
|
38
|
+
core.InteractiveMode.prototype.addMessageToChat.call(display, message);
|
|
39
|
+
return message;
|
|
40
|
+
};
|
|
41
|
+
const assistant = (value, stopReason='stop') => add({role:'assistant', content:[{type:'text',text:value}],stopReason});
|
|
42
|
+
const tool = (name, result, args={}) => {
|
|
43
|
+
const row = new core.ToolExecutionComponent(name,`tool-${manager.getBranch().length}`,args,{outputPad:1},undefined,ui,'/synthetic-work');
|
|
44
|
+
row.setArgsComplete(); row.updateResult({content:[{type:'text',text:result}],isError:false});
|
|
45
|
+
display.chatContainer.addChild(row); return row;
|
|
46
|
+
};
|
|
47
|
+
const wait = () => new Promise(resolve=>setTimeout(resolve,130));
|
|
48
|
+
const choices = () => { const items=[]; pi.events.emit('compact-renderer:inspect:v1',{add:c=>items.push(c)}); return items; };
|
|
49
|
+
const keys = data => { for(const fn of inputs){const result=fn(data); if(result?.consume)return true;} return false; };
|
|
50
|
+
try {
|
|
51
|
+
event('session_start');
|
|
52
|
+
event('agent_start'); add({role:'user',content:'Inspect invented samples.'}); assistant('Checking the sample names.');
|
|
53
|
+
const read = tool('read','EXACT_HIDDEN_RESULT');
|
|
54
|
+
const question = tool('ask_user_question','CHOSEN_BETA',{question:'Choose a sample.'});
|
|
55
|
+
assistant('FINAL_VISIBLE_RESULT');
|
|
56
|
+
assert.match(paint(),/Working/); assert.match(paint(),/Checking the sample names/);
|
|
57
|
+
ownedRow = read; controls.setExpanded(false);
|
|
58
|
+
assert.equal(nestedOpen, true, 'explicit collapse preserves a manually opened working pane');
|
|
59
|
+
assert.equal(nestedResets, 0);
|
|
60
|
+
assert.match(paint(), /Working/);
|
|
61
|
+
const original = display.chatContainer.children.slice();
|
|
62
|
+
const messages = JSON.stringify(manager.getBranch().filter(e=>e.type==='message'));
|
|
63
|
+
event('agent_settled'); await wait();
|
|
64
|
+
assert.match(paint(),/▸ Worked for/); assert.match(paint(),/FINAL_VISIBLE_RESULT/);
|
|
65
|
+
assert.doesNotMatch(paint(),/Checking the sample names|EXACT_HIDDEN_RESULT/);
|
|
66
|
+
assert.match(paint(),/CHOSEN_BETA/);
|
|
67
|
+
assert.deepEqual(display.chatContainer.children,original,'canonical children retained');
|
|
68
|
+
assert.equal(JSON.stringify(manager.getBranch().filter(e=>e.type==='message')),messages,'messages untouched');
|
|
69
|
+
assert.equal(ownership,true);
|
|
70
|
+
assert.equal(recordedWorkEvidence(manager.getBranch()).size,1);
|
|
71
|
+
assert.equal(nestedOpen, true, 'automatic completion folding preserves nested manual state');
|
|
72
|
+
controls.setExpanded(false); assert.equal(nestedOpen, false, 'explicit collapse resets the completed owner');
|
|
73
|
+
assert.equal(nestedResets, 1);
|
|
74
|
+
choices().find(c=>c.kind==='Work').focus();
|
|
75
|
+
assert.match(paint(),/▾ Worked for/); assert.match(paint(),/EXACT_HIDDEN_RESULT/);
|
|
76
|
+
assert.equal(keys('\r'),true); assert.doesNotMatch(paint(),/EXACT_HIDDEN_RESULT/);
|
|
77
|
+
assert.equal(keys('\u001b'),true); assert.equal(keys('x'),false);
|
|
78
|
+
// Nested /inspect expands the owning fold before the viewport is revealed.
|
|
79
|
+
pi.events.emit('compact-renderer:focus:v1',{owner:'tools',target:c=>c===read});
|
|
80
|
+
assert.match(paint(),/EXACT_HIDDEN_RESULT/); assert.match(paint(),/▾ Worked for/);
|
|
81
|
+
// Compact off is exact native tree, including messages and tool results.
|
|
82
|
+
mode.setEnabled(false); assert.equal(ownership,false); assert.doesNotMatch(paint(),/Worked for/); assert.match(paint(),/EXACT_HIDDEN_RESULT/);
|
|
83
|
+
mode.setEnabled(true); paint(); assert.equal(ownership,true);
|
|
84
|
+
// A reader in scrollback is not displaced at settlement.
|
|
85
|
+
event('agent_start'); add({role:'user',content:'Second sample.'}); assistant('SECOND_INTERMEDIATE'); tool('read','SECOND_TOOL'); assistant('SECOND_FINAL');
|
|
86
|
+
ui.isFollowingOutput=false; paint(); event('agent_settled'); await wait();
|
|
87
|
+
assert.match(paint(),/SECOND_INTERMEDIATE/);
|
|
88
|
+
ui.isFollowingOutput=true; assert.doesNotMatch(paint(),/SECOND_INTERMEDIATE/); assert.match(paint(),/SECOND_FINAL/);
|
|
89
|
+
// Explicit user expansion during execution wins over completion.
|
|
90
|
+
event('agent_start'); add({role:'user',content:'Third sample.'}); assistant('THIRD_INTERMEDIATE'); tool('read','THIRD_TOOL'); paint();
|
|
91
|
+
choices().filter(c=>c.kind==='Work').at(-1).focus(); assistant('THIRD_FINAL'); event('agent_settled'); await wait();
|
|
92
|
+
assert.match(paint(),/THIRD_INTERMEDIATE/);
|
|
93
|
+
// Background children keep the current turn open after parent settlement.
|
|
94
|
+
provider=true; childrenActive=1;
|
|
95
|
+
event('agent_start'); add({role:'user',content:'Fourth sample.'}); assistant('FOURTH_INTERMEDIATE'); ownedRow = tool('read','FOURTH_TOOL'); nestedOpen = true; assistant('FOURTH_FINAL'); paint();
|
|
96
|
+
pi.events.emit('subagent:async-started',{id:'fourth-root'});
|
|
97
|
+
event('agent_settled'); await wait(); assert.match(paint(),/Waiting/); assert.match(paint(),/FOURTH_INTERMEDIATE/);
|
|
98
|
+
const waitingResets = nestedResets; controls.setExpanded(false);
|
|
99
|
+
assert.equal(nestedOpen, true, 'explicit collapse preserves a manually opened waiting pane');
|
|
100
|
+
assert.equal(nestedResets, waitingResets);
|
|
101
|
+
assert.match(paint(), /Waiting/);
|
|
102
|
+
childrenActive=0; pi.events.emit('subagent:async-complete',{runId:'fourth-root',state:'complete',success:true}); await wait(); await wait();
|
|
103
|
+
assert.doesNotMatch(paint(),/FOURTH_INTERMEDIATE/); assert.match(paint(),/FOURTH_FINAL/);
|
|
104
|
+
// An earlier turn can finish after a later prompt. Unrelated children cannot hold the later reply open.
|
|
105
|
+
childrenActive=1;
|
|
106
|
+
event('agent_start'); add({role:'user',content:'Fifth sample.'}); assistant('FIFTH_INTERMEDIATE'); tool('read', 'FIFTH_TOOL'); assistant('FIFTH_FINAL'); paint();
|
|
107
|
+
pi.events.emit('subagent:async-started',{id:'fifth-root'}); event('agent_settled'); await wait();
|
|
108
|
+
event('agent_start'); add({role:'user',content:'Sixth sample.'}); assistant('SIXTH_INTERMEDIATE'); tool('read','SIXTH_TOOL'); assistant('SIXTH_FINAL'); paint();
|
|
109
|
+
event('agent_settled'); await wait();
|
|
110
|
+
assert.match(paint(),/FIFTH_INTERMEDIATE/); assert.doesNotMatch(paint(),/SIXTH_INTERMEDIATE/);
|
|
111
|
+
childrenActive=0; pi.events.emit('subagent:async-complete',{runId:'fifth-root',state:'complete',success:true}); await wait(); await wait();
|
|
112
|
+
assert.doesNotMatch(paint(),/FIFTH_INTERMEDIATE/); assert.match(paint(),/FIFTH_FINAL/);
|
|
113
|
+
// Reloaded completed work must not reopen between agent_start and the next user.
|
|
114
|
+
event('session_start',{reason:'reload'}); paint(); event('agent_start'); assert.doesNotMatch(paint(),/FIFTH_INTERMEDIATE/);
|
|
115
|
+
add({role:'user',content:'Seventh sample.'}); assistant('SEVENTH_INTERMEDIATE'); tool('read','SEVENTH_TOOL'); paint();
|
|
116
|
+
// A steering message during the same agent run still owns its own strip.
|
|
117
|
+
add({role:'user',content:'Eighth sample.'}); assistant('EIGHTH_INTERMEDIATE'); tool('read','EIGHTH_TOOL'); assistant('EIGHTH_FINAL'); paint();
|
|
118
|
+
event('agent_settled'); await wait();
|
|
119
|
+
assert.doesNotMatch(paint(),/EIGHTH_INTERMEDIATE/); assert.match(paint(),/EIGHTH_FINAL/);
|
|
120
|
+
// An empty terminal response must not promote earlier commentary to 'final'.
|
|
121
|
+
event('agent_start'); add({role:'user',content:'Ninth sample.'}); assistant('NINTH_INTERMEDIATE'); tool('read','NINTH_TOOL'); assistant(''); paint();
|
|
122
|
+
const evidenceBefore=manager.getBranch().filter(e=>e.customType===workEvidenceType).length;
|
|
123
|
+
event('agent_settled'); await wait(); assert.match(paint(),/NINTH_INTERMEDIATE/); assert.match(paint(),/NINTH_TOOL/);
|
|
124
|
+
assert.match(paint(),/Stopped/); assert.equal(manager.getBranch().filter(e=>e.customType===workEvidenceType).length,evidenceBefore);
|
|
125
|
+
// A valid continuation clears the earlier incomplete state.
|
|
126
|
+
event('agent_start');
|
|
127
|
+
const continuation={role:'assistant',content:[{type:'text',text:'NINTH_VALID_FINAL'}],stopReason:'stop'};
|
|
128
|
+
event('message_start',{message:continuation}); add(continuation); paint(); event('agent_settled'); await wait();
|
|
129
|
+
assert.match(paint(),/NINTH_VALID_FINAL/); assert.doesNotMatch(paint(),/NINTH_INTERMEDIATE|NINTH_TOOL/);
|
|
130
|
+
// Unknown DDD severity stays outside; full text opens via shared inspection.
|
|
131
|
+
add({role:'custom',customType:'ddd',display:true,content:'Five maintenance reminders.\nDETAILS_REMAIN_AVAILABLE'}); paint();
|
|
132
|
+
assert.match(paint(),/DDD · Five maintenance reminders/); assert.doesNotMatch(paint(),/DETAILS_REMAIN_AVAILABLE/);
|
|
133
|
+
choices().find(c=>c.kind==='Hook').focus(); assert.match(paint(),/DETAILS_REMAIN_AVAILABLE/);
|
|
134
|
+
keys('\u001b');
|
|
135
|
+
// Resume uses explicit presentation metadata, never an invented completion.
|
|
136
|
+
event('session_start',{reason:'reload'}); assert.match(paint(),/▸ Worked for/);
|
|
137
|
+
assert.doesNotMatch(paint(),/SECOND_INTERMEDIATE/);
|
|
138
|
+
const native = (()=>{mode.setEnabled(false);return paint();})(); mode.setEnabled(true);
|
|
139
|
+
dispose(); assert.equal(paint(),native); assert.equal(ownership,false);
|
|
140
|
+
assert.equal(display.chatContainer[projectedChildren],undefined);
|
|
141
|
+
assert.equal(inputs.size,0);
|
|
142
|
+
dispose=registerWorkStrip(pi,mode).dispose; event('session_start');
|
|
143
|
+
// Fresh adapter mounts on the first replay callback; not stale rows from previous session.
|
|
144
|
+
core.InteractiveMode.prototype.addMessageToChat.call(display,{role:'custom',display:false});
|
|
145
|
+
assert.match(paint(),/FINAL_VISIBLE_RESULT/);
|
|
146
|
+
assert.equal(JSON.stringify(manager.getBranch().filter(e=>e.type==='message')).includes('DETAILS_REMAIN_AVAILABLE'),true);
|
|
147
|
+
console.log('Work strip native grouping, settlement, scrollback, decisions, nested inspection, children, replay, fallback and disposal passed');
|
|
148
|
+
} finally {dispose();}
|