pi-odd-worktree 3.3.0 → 3.5.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/README.md +6 -2
- package/extensions/odd-worktree-tools.ts +39 -0
- package/lib/bash-design.js +8 -2
- package/lib/depth-launch.js +70 -0
- package/lib/depth-prompt/depth.md +53 -0
- package/lib/depth-task.js +76 -0
- package/lib/file-card-resolver.js +4 -0
- package/lib/file-card.js +8 -0
- package/lib/jobs-card-resolver.js +139 -0
- package/lib/jobs-card.js +220 -0
- package/package.json +1 -1
- package/tools/bash-design.test.js +8 -8
- package/tools/depth-command.test.js +66 -0
- package/tools/depth-launch.test.js +123 -0
- package/tools/depth-task.test.js +76 -0
- package/tools/files-bridge.test.js +2 -2
- package/tools/files-command.test.js +1 -1
- package/tools/jobs-card.test.js +292 -0
- package/tools/package-surface.test.js +2 -2
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The jobs card: `bash_background`, `monitor`, `job_stop` and `job_list` are registered by
|
|
3
|
+
// Gentle Shell with no renderer of their own, so Pi draws its plain default box and the
|
|
4
|
+
// conversation's card style never reaches them. While the bridge's `Card tags` line answers
|
|
5
|
+
// `activity` for the tool being drawn, this package draws them on its own card substrate
|
|
6
|
+
// (`lib/shell-card.js`), in whichever style the shell has chosen. Any other answer — and the
|
|
7
|
+
// absence of an answer — leaves Pi's own drawing exactly as it was.
|
|
8
|
+
//
|
|
9
|
+
// Every case goes through the public surface: the resolver, the slots it returns and the
|
|
10
|
+
// rows a component draws for a width. The text seam and the themes are the fakes
|
|
11
|
+
// `tools/file-card.test.js` uses; the bridge is the published object a process-wide slot holds.
|
|
12
|
+
const assert = require('node:assert/strict');
|
|
13
|
+
const { after, afterEach, beforeEach, test } = require('node:test');
|
|
14
|
+
|
|
15
|
+
const { JOB_TOOLS } = require('../lib/jobs-card.js');
|
|
16
|
+
const { createJobsCardResolver, registerJobsCard } = require('../lib/jobs-card-resolver.js');
|
|
17
|
+
const { applyBashActivityHeading, toolsActivityDesign } = require('../lib/bash-design.js');
|
|
18
|
+
const { CARD_CONTENT, CARD_CONTENT_SLOT } = require('../lib/card-content.js');
|
|
19
|
+
const { CARD_STYLE, CARD_STYLE_SLOT } = require('../lib/card-style.js');
|
|
20
|
+
|
|
21
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
22
|
+
const stripAnsi = (value) => value.replace(ANSI, '');
|
|
23
|
+
const chars = (value) => [...stripAnsi(value)];
|
|
24
|
+
|
|
25
|
+
const metrics = {
|
|
26
|
+
visibleWidth: (value) => chars(value).length,
|
|
27
|
+
truncateToWidth(value, width, ellipsis = '') {
|
|
28
|
+
if (width <= 0) return '';
|
|
29
|
+
if (this.visibleWidth(value) <= width) return value;
|
|
30
|
+
const tail = ellipsis ?? '';
|
|
31
|
+
return chars(value).slice(0, Math.max(0, width - [...tail].length)).join('') + tail;
|
|
32
|
+
},
|
|
33
|
+
wrapTextWithAnsi(value, width) {
|
|
34
|
+
const text = stripAnsi(value);
|
|
35
|
+
if (width <= 0) return [text];
|
|
36
|
+
return text.split('\n').flatMap((line) => {
|
|
37
|
+
const lines = [];
|
|
38
|
+
let current = '';
|
|
39
|
+
for (const word of line.split(' ')) {
|
|
40
|
+
const candidate = current === '' ? word : `${current} ${word}`;
|
|
41
|
+
if ([...candidate].length <= width) { current = candidate; continue; }
|
|
42
|
+
if (current !== '') { lines.push(current); current = ''; }
|
|
43
|
+
const rest = [...word];
|
|
44
|
+
while (rest.length > width) lines.push(rest.splice(0, width).join(''));
|
|
45
|
+
current = rest.join('');
|
|
46
|
+
}
|
|
47
|
+
lines.push(current);
|
|
48
|
+
return lines;
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const plainTheme = { fg: (_role, value) => value };
|
|
54
|
+
const taggedTheme = { fg: (role, value) => `<${role}>${value}</${role}>` };
|
|
55
|
+
const bandTheme = { fg: (_role, value) => value, bg: (_role, value) => `\x1b[48;5;240m${value}\x1b[49m` };
|
|
56
|
+
const unpaint = (value) => stripAnsi(value).replace(/<\/?[a-zA-Z][a-zA-Z0-9]*>/g, '');
|
|
57
|
+
|
|
58
|
+
const BRIDGE_API_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
|
|
59
|
+
const ACTIVITY = Object.freeze({ kind: 'design', design: { id: 'odd-worktree.bash-activity' } });
|
|
60
|
+
|
|
61
|
+
beforeEach(() => {
|
|
62
|
+
globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
|
|
63
|
+
delete globalThis[CARD_CONTENT_SLOT];
|
|
64
|
+
delete globalThis[BRIDGE_API_SLOT];
|
|
65
|
+
});
|
|
66
|
+
afterEach(() => { delete globalThis[BRIDGE_API_SLOT]; });
|
|
67
|
+
after(() => {
|
|
68
|
+
delete globalThis[CARD_STYLE_SLOT];
|
|
69
|
+
delete globalThis[CARD_CONTENT_SLOT];
|
|
70
|
+
delete globalThis[BRIDGE_API_SLOT];
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function publishBridge(selection, asked) {
|
|
74
|
+
const api = {
|
|
75
|
+
schema: 'gentle-shell-bridge/api',
|
|
76
|
+
version: 1,
|
|
77
|
+
VERSION: '0.10.0',
|
|
78
|
+
registerToolDesign: () => () => {},
|
|
79
|
+
resolveToolDesignSelection(tool) {
|
|
80
|
+
if (asked !== undefined) asked.push(tool);
|
|
81
|
+
if (typeof selection === 'function') return selection(tool);
|
|
82
|
+
return selection;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
globalThis[BRIDGE_API_SLOT] = api;
|
|
86
|
+
return api;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function jobsResolver(options) {
|
|
90
|
+
const registered = [];
|
|
91
|
+
const cards = createJobsCardResolver({ metrics, theme: plainTheme, registerToolRenderer: (resolver) => registered.push(resolver), ...options });
|
|
92
|
+
assert.equal(cards.registered, true);
|
|
93
|
+
assert.equal(registered.length, 1);
|
|
94
|
+
return registered[0];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// What Pi would have drawn for a tool with no renderer of its own: whatever `next()` says.
|
|
98
|
+
const PI_DEFAULT = Object.freeze({ marker: 'pi default' });
|
|
99
|
+
|
|
100
|
+
const COMMAND = 'sleep 20; until [ "$(gh run list --repo acme/api)" ]; do sleep 1; done';
|
|
101
|
+
const LABEL = 'Release runs for 1.9.1';
|
|
102
|
+
const STARTED = [
|
|
103
|
+
'Started background job job-2 ("Release runs for 1.9.1").',
|
|
104
|
+
'Output: /tmp/gentle-jobs-1018kZ/job-2.log',
|
|
105
|
+
'You will be notified once when it exits; keep working or end your turn. Stop it with job_stop.',
|
|
106
|
+
].join('\n');
|
|
107
|
+
|
|
108
|
+
const slots = (resolver, tool) => resolver(tool, () => PI_DEFAULT);
|
|
109
|
+
const callRows = (resolver, tool, args, theme, width = 70, context = { isPartial: false }) =>
|
|
110
|
+
slots(resolver, tool).renderCall(args, theme, { args, ...context }).render(width);
|
|
111
|
+
const resultRows = (resolver, tool, args, text, options = { isPartial: false }, theme = plainTheme, width = 70, context = {}) =>
|
|
112
|
+
slots(resolver, tool).renderResult({ content: [{ type: 'text', text }], details: {} }, options, theme, { args, state: {}, ...context }).render(width);
|
|
113
|
+
|
|
114
|
+
function assertFramed(rows, width) {
|
|
115
|
+
for (const row of rows) assert.equal(metrics.visibleWidth(unpaint(row)), width, `"${unpaint(row)}" is not ${width} wide`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ---- the one switch ----
|
|
119
|
+
|
|
120
|
+
test('the card is drawn only while the Card tags line answers activity; every other answer leaves Pi\'s own drawing', () => {
|
|
121
|
+
const answers = [
|
|
122
|
+
['no bridge published', undefined],
|
|
123
|
+
['the bridge\'s native answer', { kind: 'native' }],
|
|
124
|
+
['a tool the line does not cover', { kind: 'not-covered' }],
|
|
125
|
+
['a design that has left the line', { kind: 'missing' }],
|
|
126
|
+
['another plugin\'s design', { kind: 'design', design: { id: 'acme.tools' } }],
|
|
127
|
+
['an answer nothing can read', 'garbage'],
|
|
128
|
+
];
|
|
129
|
+
for (const [name, answer] of answers) {
|
|
130
|
+
if (answer !== undefined) publishBridge(answer);
|
|
131
|
+
for (const tool of JOB_TOOLS) assert.equal(slots(jobsResolver(), tool), PI_DEFAULT, `${name}: ${tool}`);
|
|
132
|
+
delete globalThis[BRIDGE_API_SLOT];
|
|
133
|
+
}
|
|
134
|
+
// A bridge too old to carry the reader, and one whose reader throws, are no answer either.
|
|
135
|
+
globalThis[BRIDGE_API_SLOT] = { schema: 'gentle-shell-bridge/api', version: 1, VERSION: '0.6.0', registerToolDesign: () => () => {} };
|
|
136
|
+
assert.equal(slots(jobsResolver(), 'bash_background'), PI_DEFAULT);
|
|
137
|
+
publishBridge(() => { throw new Error('boom'); });
|
|
138
|
+
assert.equal(slots(jobsResolver(), 'bash_background'), PI_DEFAULT);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('while activity is selected the four job tools get a self-framed card and the bridge is asked per tool', () => {
|
|
142
|
+
const asked = [];
|
|
143
|
+
publishBridge(ACTIVITY, asked);
|
|
144
|
+
const resolver = jobsResolver();
|
|
145
|
+
for (const tool of JOB_TOOLS) {
|
|
146
|
+
const drawn = slots(resolver, tool);
|
|
147
|
+
assert.notEqual(drawn, PI_DEFAULT, tool);
|
|
148
|
+
assert.equal(drawn.renderShell, 'self', `${tool} frames itself`);
|
|
149
|
+
assert.equal(typeof drawn.renderCall, 'function');
|
|
150
|
+
assert.equal(typeof drawn.renderResult, 'function');
|
|
151
|
+
}
|
|
152
|
+
assert.deepEqual(asked, [...JOB_TOOLS]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('no other tool is ever claimed: bash, the file tools and an unknown tool come back as the chain resolved them', () => {
|
|
156
|
+
publishBridge(ACTIVITY);
|
|
157
|
+
const resolver = jobsResolver();
|
|
158
|
+
for (const tool of ['bash', 'read', 'write', 'edit', 'grep', 'codemode', 'job_unknown']) {
|
|
159
|
+
assert.equal(slots(resolver, tool), PI_DEFAULT, tool);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// ---- the call ----
|
|
164
|
+
|
|
165
|
+
test('a background job heads with its mark, its label and nothing it did not state', () => {
|
|
166
|
+
publishBridge(ACTIVITY);
|
|
167
|
+
const rows = callRows(jobsResolver(), 'bash_background', { command: COMMAND, label: LABEL }, taggedTheme);
|
|
168
|
+
assert.equal(rows.length, 1, 'collapsed, a finished call is one rule');
|
|
169
|
+
const text = unpaint(rows[0]);
|
|
170
|
+
assert.match(text, /^╭─ ⧗ background · Release runs for 1\.9\.1 /u, text);
|
|
171
|
+
assert.match(text, /╮$/u);
|
|
172
|
+
assert.ok(rows[0].includes('<bashMode>⧗</bashMode>'), 'the mark wears the identity role');
|
|
173
|
+
assert.doesNotMatch(text, /sleep 20/u, 'the command waits for the expanded view');
|
|
174
|
+
assertFramed(rows, 70);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('without a label the first line of the command names the job; the other tools name their target', () => {
|
|
178
|
+
publishBridge(ACTIVITY);
|
|
179
|
+
const resolver = jobsResolver();
|
|
180
|
+
assert.match(unpaint(callRows(resolver, 'bash_background', { command: '\n npm test --silent\nnpm run lint' }, plainTheme)[0]), /⧗ background · npm test --silent/u);
|
|
181
|
+
assert.match(unpaint(callRows(resolver, 'monitor', { command: 'tail -f app.log', label: 'app log', timeout_seconds: 60 }, plainTheme)[0]), /◉ monitor · app log/u);
|
|
182
|
+
assert.match(unpaint(callRows(resolver, 'job_stop', { job_id: 'job-2' }, plainTheme)[0]), /■ stop · job-2/u);
|
|
183
|
+
assert.match(unpaint(callRows(resolver, 'job_list', {}, plainTheme)[0]), /≡ jobs · this session/u);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('expanded, the whole command is stated below the heading, every line of it', () => {
|
|
187
|
+
publishBridge(ACTIVITY);
|
|
188
|
+
const rows = callRows(jobsResolver(), 'bash_background', { command: 'sleep 20\n\ngh run list --repo acme/api', label: LABEL }, plainTheme, 70, { isPartial: false, expanded: true }).map(unpaint);
|
|
189
|
+
const joined = rows.join('\n');
|
|
190
|
+
assert.match(joined, /Release runs for 1\.9\.1/u);
|
|
191
|
+
assert.match(joined, /│ sleep 20 +│/u);
|
|
192
|
+
assert.match(joined, /│ gh run list --repo acme\/api +│/u);
|
|
193
|
+
assertFramed(rows, 70);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('a call still waiting for its result closes its own frame; once the result exists the result closes it', () => {
|
|
197
|
+
publishBridge(ACTIVITY);
|
|
198
|
+
const resolver = jobsResolver();
|
|
199
|
+
const state = {};
|
|
200
|
+
const running = slots(resolver, 'bash_background').renderCall({ command: COMMAND }, plainTheme, { isPartial: true, state }).render(70).map(unpaint);
|
|
201
|
+
assert.match(running.join('\n'), /running/iu);
|
|
202
|
+
assert.match(running.at(-1), /^╰/u, 'the running call closes itself');
|
|
203
|
+
const settled = callRows(resolver, 'bash_background', { command: COMMAND }, plainTheme, 70, { isPartial: false }).map(unpaint);
|
|
204
|
+
assert.doesNotMatch(settled.join('\n'), /^╰/mu, 'the result owns the closing rule');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// ---- the result ----
|
|
208
|
+
|
|
209
|
+
test('the result previews the first rows collapsed, everything expanded, and always closes the frame', () => {
|
|
210
|
+
publishBridge(ACTIVITY);
|
|
211
|
+
const resolver = jobsResolver();
|
|
212
|
+
const collapsed = resultRows(resolver, 'bash_background', { command: COMMAND }, `${STARTED}\nextra line four`).map(unpaint);
|
|
213
|
+
assert.match(collapsed.join('\n'), /Started background job job-2/u);
|
|
214
|
+
assert.doesNotMatch(collapsed.join('\n'), /extra line four/u, 'only the preview budget is drawn collapsed');
|
|
215
|
+
assert.match(collapsed.at(-1), /^╰/u);
|
|
216
|
+
const expanded = resultRows(resolver, 'bash_background', { command: COMMAND }, `${STARTED}\nextra line four`, { isPartial: false, expanded: true }).map(unpaint);
|
|
217
|
+
assert.match(expanded.join('\n'), /extra line four/u);
|
|
218
|
+
assert.match(expanded.at(-1), /^╰/u);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('the minimal card content level draws the call alone, but a failure still says why', () => {
|
|
222
|
+
publishBridge(ACTIVITY);
|
|
223
|
+
globalThis[CARD_CONTENT_SLOT] = CARD_CONTENT.MINIMAL;
|
|
224
|
+
const resolver = jobsResolver();
|
|
225
|
+
const quiet = resultRows(resolver, 'bash_background', { command: COMMAND }, STARTED).map(unpaint);
|
|
226
|
+
assert.doesNotMatch(quiet.join('\n'), /Started background job/u);
|
|
227
|
+
assert.match(quiet.at(-1), /^╰/u, 'the frame still closes');
|
|
228
|
+
const failed = resultRows(resolver, 'job_stop', { job_id: 'job-9' }, 'No background job job-9 in this session.', { isPartial: false }, plainTheme, 70, { isError: true }).map(unpaint);
|
|
229
|
+
assert.match(failed.join('\n'), /No background job job-9 in this session\./u);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// ---- the style and the width ----
|
|
233
|
+
|
|
234
|
+
test('neon draws the outlined frame and float the borderless rail, whichever tool is drawn', () => {
|
|
235
|
+
publishBridge(ACTIVITY);
|
|
236
|
+
const resolver = jobsResolver();
|
|
237
|
+
for (const tool of JOB_TOOLS) {
|
|
238
|
+
const args = tool === 'job_stop' ? { job_id: 'job-2' } : tool === 'job_list' ? {} : { command: COMMAND, label: LABEL };
|
|
239
|
+
globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
|
|
240
|
+
const neon = [...callRows(resolver, tool, args, bandTheme), ...resultRows(resolver, tool, args, STARTED, { isPartial: false }, bandTheme)].map(unpaint);
|
|
241
|
+
assert.match(neon[0], /^╭/u, `${tool} neon`);
|
|
242
|
+
assert.match(neon.at(-1), /^╰/u);
|
|
243
|
+
globalThis[CARD_STYLE_SLOT] = CARD_STYLE.FLOAT;
|
|
244
|
+
const float = [...callRows(resolver, tool, args, bandTheme), ...resultRows(resolver, tool, args, STARTED, { isPartial: false }, bandTheme)].map(unpaint);
|
|
245
|
+
assert.doesNotMatch(float.join('\n'), /[╭╮╰╯]/u, `${tool} float draws no box`);
|
|
246
|
+
assert.match(float.join('\n'), /▎/u);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('every row fits the width the host asked for, at narrow and wide terminals', () => {
|
|
251
|
+
publishBridge(ACTIVITY);
|
|
252
|
+
const resolver = jobsResolver();
|
|
253
|
+
for (const style of [CARD_STYLE.NEON, CARD_STYLE.FLOAT]) {
|
|
254
|
+
globalThis[CARD_STYLE_SLOT] = style;
|
|
255
|
+
for (const width of [24, 40, 70, 120]) {
|
|
256
|
+
const rows = [
|
|
257
|
+
...callRows(resolver, 'bash_background', { command: COMMAND, label: LABEL }, bandTheme, width),
|
|
258
|
+
...callRows(resolver, 'bash_background', { command: COMMAND, label: LABEL }, bandTheme, width, { isPartial: false, expanded: true }),
|
|
259
|
+
...resultRows(resolver, 'bash_background', { command: COMMAND }, STARTED, { isPartial: false, expanded: true }, bandTheme, width),
|
|
260
|
+
];
|
|
261
|
+
assertFramed(rows, width);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ---- the wiring ----
|
|
267
|
+
|
|
268
|
+
test('registerJobsCard hands one resolver to the host hook and reports a host that has none', () => {
|
|
269
|
+
const handed = [];
|
|
270
|
+
const outcome = registerJobsCard({ registerToolRenderer: (resolver) => handed.push(resolver) }, { metrics });
|
|
271
|
+
assert.equal(outcome.registered, true);
|
|
272
|
+
assert.equal(handed.length, 1);
|
|
273
|
+
assert.deepEqual(registerJobsCard({}, { metrics }), { registered: false, resolver: undefined });
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('the Card tags line covers the four job tools, so the bridge can answer for them', () => {
|
|
277
|
+
for (const scopes of [true, false]) {
|
|
278
|
+
const design = toolsActivityDesign({ scopes });
|
|
279
|
+
for (const tool of JOB_TOOLS) assert.ok(design.tools.includes(tool), `${tool} (scopes: ${scopes})`);
|
|
280
|
+
for (const tool of ['bash', 'grep', 'find', 'ls', 'read', 'write']) assert.ok(design.tools.includes(tool), `${tool} stays covered`);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('declaring the job tools on the line changes nothing the activity design draws: their rows come back exactly as given', () => {
|
|
285
|
+
const rows = ['\x1b[2m bash_background command="sleep 20" \x1b[22m', ' Started background job job-2. '];
|
|
286
|
+
for (const tool of JOB_TOOLS) {
|
|
287
|
+
for (const part of ['call', 'result']) {
|
|
288
|
+
const drawn = applyBashActivityHeading(rows, { width: 60, tool, theme: plainTheme, part, render: { args: { command: 'sleep 20' }, isPartial: false } });
|
|
289
|
+
assert.deepEqual(drawn, rows, `${tool} ${part}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
@@ -83,11 +83,11 @@ describe('manifest', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
describe('registration', () => {
|
|
86
|
-
test('registers /warp, /odd, /files, /issues and the two worktree tools', async () => {
|
|
86
|
+
test('registers /warp, /odd, /files, /issues, /depth and the two worktree tools', async () => {
|
|
87
87
|
delete process.env.GENTLE_WORKTREE_THREAD;
|
|
88
88
|
const { commands, tools, messageRenderers } = await loadExtension({});
|
|
89
89
|
const registered = [...commands.keys()].sort();
|
|
90
|
-
assert.deepEqual(registered, ['files', 'issues', 'odd', 'warp'], 'the command list is exactly the four panels');
|
|
90
|
+
assert.deepEqual(registered, ['depth', 'files', 'issues', 'odd', 'warp'], 'the command list is exactly the four panels and /depth');
|
|
91
91
|
assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'exactly two agent tools');
|
|
92
92
|
assert.deepEqual([...messageRenderers.keys()], ['worktree-warp']);
|
|
93
93
|
});
|