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
package/lib/jobs-card.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The jobs card: `bash_background`, `monitor`, `job_stop` and `job_list` drawn on this
|
|
3
|
+
// package's card substrate (`lib/shell-card.js`), in whichever style the shell has chosen.
|
|
4
|
+
//
|
|
5
|
+
// Gentle Shell registers those four tools with no renderer of their own, so Pi draws its
|
|
6
|
+
// plain default box and the conversation's card style (neon or float) never reaches them.
|
|
7
|
+
// This module is the drawing half; `lib/jobs-card-resolver.js` decides WHEN it is used — only
|
|
8
|
+
// while the bridge's `Card tags` line answers `activity` for the tool being drawn.
|
|
9
|
+
//
|
|
10
|
+
// It is shaped exactly like `lib/file-card.js` and shares its helpers (tone, expand hint,
|
|
11
|
+
// theme fallback, result text, the bounded body preview), so the two cards read as one family.
|
|
12
|
+
//
|
|
13
|
+
// What the card never decides:
|
|
14
|
+
// * COLOUR. Every cell is a theme role handed to the injected `theme.fg`; no palette and no
|
|
15
|
+
// raw escape sequence is written here, and the frame keeps the TONE's role whenever the
|
|
16
|
+
// tone owns the box, so a running or failed call is never painted in an identity colour.
|
|
17
|
+
// * MEASUREMENT. The substrate clips, wraps and pads plain text and paints it afterwards.
|
|
18
|
+
// * STATE. The tone follows the host's own flags (`isPartial`, `isError`), the expanded view
|
|
19
|
+
// is the host's own `expanded`, the elapsed time its own `durationMs`.
|
|
20
|
+
// * THE TOOL. Nothing is registered, executed or shadowed: the arguments are only read.
|
|
21
|
+
// * THE CONTENT LEVEL. The `minimal` card content level draws the call alone while collapsed;
|
|
22
|
+
// a failure still says why. It is read on every paint.
|
|
23
|
+
//
|
|
24
|
+
// Rendering never throws: a theme or an argument that fails draws no rows instead of breaking
|
|
25
|
+
// the session's transcript.
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
cardAwaitingResult,
|
|
29
|
+
cardBodyRows,
|
|
30
|
+
cardBottom,
|
|
31
|
+
cardElapsed,
|
|
32
|
+
cardInnerWidth,
|
|
33
|
+
cardRunningLine,
|
|
34
|
+
cardTopLine,
|
|
35
|
+
cardTopRows,
|
|
36
|
+
floatRows,
|
|
37
|
+
markCardResult,
|
|
38
|
+
} = require('./shell-card.js');
|
|
39
|
+
const { PREVIEW_ROWS, cardTone, component, expandHint, fileResultRows, optionFlag, resultText, themeFor } = require('./file-card.js');
|
|
40
|
+
// The one reader of text as a card draws it: no terminal sequences, however the model wrote it.
|
|
41
|
+
const { cardText } = require('./codegraph-card-preview.js');
|
|
42
|
+
|
|
43
|
+
/** The four tools this card owns, in the order the bridge's `Card tags` line declares them. */
|
|
44
|
+
const JOB_TOOLS = Object.freeze(['bash_background', 'monitor', 'job_stop', 'job_list']);
|
|
45
|
+
|
|
46
|
+
// Each tool's mark, its one-word label and the theme role the heading wears.
|
|
47
|
+
const IDENTITY = Object.freeze({
|
|
48
|
+
bash_background: { glyph: '⧗', title: 'background', titleRole: 'bashMode' },
|
|
49
|
+
monitor: { glyph: '◉', title: 'monitor', titleRole: 'mdLink' },
|
|
50
|
+
job_stop: { glyph: '■', title: 'stop', titleRole: 'warning' },
|
|
51
|
+
job_list: { glyph: '≡', title: 'jobs', titleRole: 'syntaxFunction' },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const SUBTITLE_ROLE = 'accent';
|
|
55
|
+
const COMMAND_ROLE = 'dim';
|
|
56
|
+
const FALLBACK = Object.freeze({ bash_background: 'shell command', monitor: 'shell command', job_stop: 'a background job', job_list: 'this session' });
|
|
57
|
+
|
|
58
|
+
const asObject = (value) => (value !== null && typeof value === 'object' ? value : {});
|
|
59
|
+
// A model-written string as one plain line: terminal sequences gone, whitespace collapsed.
|
|
60
|
+
const oneLine = (value) => (typeof value === 'string' ? cardText(value).replace(/\s+/gu, ' ').trim() : '');
|
|
61
|
+
|
|
62
|
+
/** The command's lines as drawn: sequences gone, no blank rows around it, trailing space dropped. */
|
|
63
|
+
function commandLines(args) {
|
|
64
|
+
const command = asObject(args).command;
|
|
65
|
+
if (typeof command !== 'string') return [];
|
|
66
|
+
const lines = cardText(command).replace(/\r\n/g, '\n').split('\n').map((line) => line.trimEnd());
|
|
67
|
+
while (lines.length > 0 && lines[0].trim() === '') lines.shift();
|
|
68
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === '') lines.pop();
|
|
69
|
+
return lines;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* What names one call: a job's label, else the first line of its command; a stop its job id;
|
|
74
|
+
* a listing its own scope. Never the JSON of the arguments.
|
|
75
|
+
*/
|
|
76
|
+
function jobSubtitle(tool, args) {
|
|
77
|
+
const call = asObject(args);
|
|
78
|
+
if (tool === 'job_stop') return oneLine(call.job_id) || FALLBACK.job_stop;
|
|
79
|
+
if (tool === 'job_list') return FALLBACK.job_list;
|
|
80
|
+
const label = oneLine(call.label);
|
|
81
|
+
if (label !== '') return label;
|
|
82
|
+
const first = commandLines(args).find((line) => line.trim() !== '');
|
|
83
|
+
return first === undefined ? FALLBACK[tool] : oneLine(first);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The heading one call wears, or undefined for a tool this card does not own. */
|
|
87
|
+
function jobCardHeading(tool, args) {
|
|
88
|
+
const identity = IDENTITY[tool];
|
|
89
|
+
if (identity === undefined) return undefined;
|
|
90
|
+
const subtitle = jobSubtitle(tool, args);
|
|
91
|
+
return {
|
|
92
|
+
glyph: identity.glyph,
|
|
93
|
+
title: identity.title,
|
|
94
|
+
titleRole: identity.titleRole,
|
|
95
|
+
subtitle,
|
|
96
|
+
collapsed: subtitle,
|
|
97
|
+
labelBold: true,
|
|
98
|
+
subtitleSegments: [{ text: subtitle, role: SUBTITLE_ROLE }],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The rows of a call card: the mark and the name of the job, and — expanded — the whole
|
|
104
|
+
* command below it, every line. Plain rows built for one width, rebuilt on every frame.
|
|
105
|
+
*/
|
|
106
|
+
function jobCallRows(tool, args, context, paint, metrics, width) {
|
|
107
|
+
const ctx = asObject(context);
|
|
108
|
+
const heading = jobCardHeading(tool, args);
|
|
109
|
+
if (heading === undefined) return [];
|
|
110
|
+
const expanded = ctx.expanded === true;
|
|
111
|
+
const pending = ctx.isPartial !== false;
|
|
112
|
+
const failed = ctx.isError === true;
|
|
113
|
+
const tone = cardTone(failed, pending);
|
|
114
|
+
// A running or failed call offers no expand affordance: nothing settled is behind it.
|
|
115
|
+
const hint = pending || failed ? undefined : expandHint(ctx, expanded);
|
|
116
|
+
const card = {
|
|
117
|
+
glyph: heading.glyph,
|
|
118
|
+
title: heading.title,
|
|
119
|
+
subtitle: heading.subtitle,
|
|
120
|
+
subtitleSegments: heading.subtitleSegments,
|
|
121
|
+
labelBold: heading.labelBold,
|
|
122
|
+
tone,
|
|
123
|
+
titleRole: heading.titleRole,
|
|
124
|
+
railRole: heading.titleRole,
|
|
125
|
+
};
|
|
126
|
+
return floatRows(tone, paint, width, (inner) => {
|
|
127
|
+
const head = expanded
|
|
128
|
+
? cardTopRows(card, paint, inner, hint, metrics)
|
|
129
|
+
: [cardTopLine(card, paint, inner, hint, () => heading.collapsed, metrics)];
|
|
130
|
+
const command = expanded ? commandLines(args) : [];
|
|
131
|
+
const body = [
|
|
132
|
+
...(command.length > 0 ? cardBodyRows(command, tone, paint, inner, { expanded: true, role: COMMAND_ROLE }, metrics) : []),
|
|
133
|
+
...(pending && !failed ? [cardRunningLine(tone, paint, inner, metrics)] : []),
|
|
134
|
+
];
|
|
135
|
+
// The result that follows owns the closing rule; a call still waiting for it closes its own.
|
|
136
|
+
const bottom = cardAwaitingResult(ctx) ? cardBottom(tone, paint, inner, undefined, metrics) : undefined;
|
|
137
|
+
return { head, body, bottom };
|
|
138
|
+
}, card.railRole);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The call slot. The seams are read on every frame, so a measurement seam that arrives late
|
|
143
|
+
* is used by the next paint rather than never.
|
|
144
|
+
*/
|
|
145
|
+
function jobCallSlot(tool, seams) {
|
|
146
|
+
return (args, theme, context) => {
|
|
147
|
+
try {
|
|
148
|
+
const ctx = asObject(context);
|
|
149
|
+
const callArgs = args === undefined ? ctx.args : args;
|
|
150
|
+
const paint = themeFor(theme, seams.theme);
|
|
151
|
+
return component((width) => {
|
|
152
|
+
const metrics = seams.metrics();
|
|
153
|
+
return metrics === undefined ? [] : jobCallRows(tool, callArgs, ctx, paint, metrics, width);
|
|
154
|
+
});
|
|
155
|
+
} catch {
|
|
156
|
+
return { render: () => [], invalidate() {} };
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The result slot: the job's own answer — a bounded preview collapsed, everything expanded —
|
|
163
|
+
* under the call, closing the frame the call left open.
|
|
164
|
+
*/
|
|
165
|
+
function jobResultSlot(tool, seams) {
|
|
166
|
+
return (result, options, theme, context) => {
|
|
167
|
+
try {
|
|
168
|
+
const ctx = asObject(context);
|
|
169
|
+
const args = ctx.args;
|
|
170
|
+
const paint = themeFor(theme, seams.theme);
|
|
171
|
+
const failed = asObject(result).isError === true || optionFlag(options, ctx, 'isError');
|
|
172
|
+
const partial = optionFlag(options, ctx, 'isPartial');
|
|
173
|
+
const identity = IDENTITY[tool] ?? IDENTITY.bash_background;
|
|
174
|
+
return component((width) => {
|
|
175
|
+
const metrics = seams.metrics();
|
|
176
|
+
if (metrics === undefined) return [];
|
|
177
|
+
const expanded = optionFlag(options, ctx, 'expanded');
|
|
178
|
+
const tone = cardTone(failed, partial);
|
|
179
|
+
// One frame: from here on the call above is a heading and this card closes it.
|
|
180
|
+
markCardResult(ctx.state);
|
|
181
|
+
return floatRows(tone, paint, width, (inner) => {
|
|
182
|
+
const rows = fileResultRows({
|
|
183
|
+
text: resultText(result),
|
|
184
|
+
expanded,
|
|
185
|
+
failed,
|
|
186
|
+
content: seams.content(),
|
|
187
|
+
width: cardInnerWidth(inner),
|
|
188
|
+
theme: paint,
|
|
189
|
+
});
|
|
190
|
+
const role = rows.length > 0 ? rows[0].role : undefined;
|
|
191
|
+
const body = rows.length === 0
|
|
192
|
+
? []
|
|
193
|
+
: cardBodyRows(
|
|
194
|
+
rows.map((row) => row.text),
|
|
195
|
+
tone,
|
|
196
|
+
paint,
|
|
197
|
+
inner,
|
|
198
|
+
expanded ? { expanded: true, role } : { previewRows: PREVIEW_ROWS, role },
|
|
199
|
+
metrics,
|
|
200
|
+
);
|
|
201
|
+
// A streamed result is not finished: the closing rule belongs to the final one.
|
|
202
|
+
const bottom = partial ? undefined : cardBottom(tone, paint, inner, cardElapsed(ctx.durationMs), metrics);
|
|
203
|
+
return { body, bottom, afterHeading: true };
|
|
204
|
+
}, identity.titleRole);
|
|
205
|
+
});
|
|
206
|
+
} catch {
|
|
207
|
+
return { render: () => [], invalidate() {} };
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
module.exports = {
|
|
213
|
+
JOB_TOOLS,
|
|
214
|
+
commandLines,
|
|
215
|
+
jobCallRows,
|
|
216
|
+
jobCallSlot,
|
|
217
|
+
jobCardHeading,
|
|
218
|
+
jobResultSlot,
|
|
219
|
+
jobSubtitle,
|
|
220
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -846,7 +846,7 @@ describe('the Card tags line', () => {
|
|
|
846
846
|
// answers `undefined` for both (`computeActivity` knows only bash and the three read-only
|
|
847
847
|
// shell marks), so their rows come back byte for byte and the host's own card is never lost.
|
|
848
848
|
const design = designFor('0.6.0');
|
|
849
|
-
assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write']);
|
|
849
|
+
assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
|
|
850
850
|
const answer = (tool) => (design.tools.includes(tool) ? { kind: 'design', design } : { kind: 'not-covered' });
|
|
851
851
|
assert.equal(answer('write').kind, 'design', 'a write is covered by the line');
|
|
852
852
|
assert.equal(answer('write').design.id, BASH_DESIGN_ID);
|
|
@@ -866,7 +866,7 @@ describe('the Card tags line', () => {
|
|
|
866
866
|
test('a 0.6.0 bridge gets ONE grouped registration over bash and the read-only tools', () => {
|
|
867
867
|
const design = designFor('0.6.0');
|
|
868
868
|
assert.equal(design.line, 'tags', 'the row the bridge derives is `Card tags` (S10)');
|
|
869
|
-
assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write']);
|
|
869
|
+
assert.deepEqual(design.tools, ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
|
|
870
870
|
assert.equal(Object.hasOwn(design, 'tool'), false, 'never both shapes');
|
|
871
871
|
assert.equal(design.id, BASH_DESIGN_ID);
|
|
872
872
|
assert.equal(design.label, BASH_DESIGN_LABEL);
|
|
@@ -1239,7 +1239,7 @@ describe('the scoped claim', () => {
|
|
|
1239
1239
|
|
|
1240
1240
|
test('the line gains edit, and every other tool keeps its whole claim', () => {
|
|
1241
1241
|
const design = toolsActivityDesign();
|
|
1242
|
-
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'edit']);
|
|
1242
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list', 'edit']);
|
|
1243
1243
|
for (const tool of ['bash', 'grep', 'find', 'ls', 'read']) {
|
|
1244
1244
|
assert.equal(Object.hasOwn(design.scopes, tool), false, `${tool} is claimed for every call`);
|
|
1245
1245
|
}
|
|
@@ -1273,7 +1273,7 @@ describe('the scoped claim', () => {
|
|
|
1273
1273
|
assert.equal(design.scopes.write, design.scopes.edit, version);
|
|
1274
1274
|
continue;
|
|
1275
1275
|
}
|
|
1276
|
-
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], `${version}: today's tools`);
|
|
1276
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], `${version}: today's tools`);
|
|
1277
1277
|
assert.deepEqual(
|
|
1278
1278
|
Object.keys(design).sort(),
|
|
1279
1279
|
['apply', 'description', 'id', 'label', 'line', 'name', 'preview', 'tools'],
|
|
@@ -1293,7 +1293,7 @@ describe('the scoped claim', () => {
|
|
|
1293
1293
|
const design = calls.at(-1);
|
|
1294
1294
|
assert.equal(design.line, 'tags', version);
|
|
1295
1295
|
assert.equal(design.scopes, undefined, `${version}: a prerelease of 0.9.0 does not meet the 0.9.0 cutoff`);
|
|
1296
|
-
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], version);
|
|
1296
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], version);
|
|
1297
1297
|
}
|
|
1298
1298
|
});
|
|
1299
1299
|
|
|
@@ -1303,7 +1303,7 @@ describe('the scoped claim', () => {
|
|
|
1303
1303
|
assert.equal(calls[0].id, 'odd-worktree.capability-probe', 'the grouped shape is still probed');
|
|
1304
1304
|
const design = calls.at(-1);
|
|
1305
1305
|
assert.equal(design.scopes, undefined, 'an unreadable release never takes a scoped registration');
|
|
1306
|
-
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write']);
|
|
1306
|
+
assert.deepEqual([...design.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list']);
|
|
1307
1307
|
});
|
|
1308
1308
|
});
|
|
1309
1309
|
|
|
@@ -1331,7 +1331,7 @@ describe('the release rule is semver order, on both lines at once (S6)', () => {
|
|
|
1331
1331
|
try {
|
|
1332
1332
|
assert.deepEqual(registration.seen.map((design) => design.line), ['tags'], `${version}: the grouped line, and no diff line`);
|
|
1333
1333
|
assert.equal(registration.tags.scopes, undefined, `${version}: below 0.9.0, so no scope`);
|
|
1334
|
-
assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write'], `${version}:
|
|
1334
|
+
assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list'], `${version}: ten tools, no edit`);
|
|
1335
1335
|
assert.equal(registration.diff, undefined, `${version}: nothing is offered for a row the bridge would refuse`);
|
|
1336
1336
|
} finally {
|
|
1337
1337
|
registration.dispose();
|
|
@@ -1345,7 +1345,7 @@ describe('the release rule is semver order, on both lines at once (S6)', () => {
|
|
|
1345
1345
|
try {
|
|
1346
1346
|
assert.deepEqual(registration.seen.map((design) => design.line), ['tags', 'diff'], `${version}: both lines`);
|
|
1347
1347
|
assert.equal(registration.tags.scopes.write, registration.tags.scopes.edit, `${version}: the scope is on the line`);
|
|
1348
|
-
assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'edit'], `${version}:
|
|
1348
|
+
assert.deepEqual([...registration.tags.tools], ['bash', 'grep', 'find', 'ls', 'read', 'write', 'bash_background', 'monitor', 'job_stop', 'job_list', 'edit'], `${version}: eleven tools`);
|
|
1349
1349
|
assert.equal(registration.diff.id, 'odd-worktree.diff', version);
|
|
1350
1350
|
assert.equal(registration.diff.label, 'color', version);
|
|
1351
1351
|
assert.deepEqual([...registration.diff.tools], ['write', 'edit'], version);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth` through the registered command (S4, S5, S6): the extension's one new command starts the explorer by itself,
|
|
3
|
+
// through the host's `subagent_run` tool, and answers with one notice. The launch rules are in tools/depth-launch.test.js;
|
|
4
|
+
// this suite proves the command is wired to them in the loaded extension, behind the same gate as the others.
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { loadExtension } = require('./fixtures/load-extension.js');
|
|
8
|
+
|
|
9
|
+
function makeCtx({ tools = [{ name: 'subagent_run' }], outcome = { content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task t-1.' }] } } = {}) {
|
|
10
|
+
const calls = [];
|
|
11
|
+
const notes = [];
|
|
12
|
+
const ctx = {
|
|
13
|
+
tools,
|
|
14
|
+
executeTool: async (name, args) => {
|
|
15
|
+
calls.push({ name, args });
|
|
16
|
+
return outcome;
|
|
17
|
+
},
|
|
18
|
+
ui: { notify: (message, level) => notes.push({ message, level }) },
|
|
19
|
+
};
|
|
20
|
+
return { ctx, calls, notes };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('/depth is a registered command that says what it does', async () => {
|
|
24
|
+
const { commands } = await loadExtension({});
|
|
25
|
+
const depth = commands.get('depth');
|
|
26
|
+
assert.ok(depth, '/depth is registered');
|
|
27
|
+
assert.equal(typeof depth.handler, 'function');
|
|
28
|
+
assert.match(depth.description, /background/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('/depth <request> starts one background explorer with the request verbatim and says so', async () => {
|
|
32
|
+
const { commands } = await loadExtension({});
|
|
33
|
+
const { ctx, calls, notes } = makeCtx();
|
|
34
|
+
await commands.get('depth').handler(' make the error messages clearer ', ctx);
|
|
35
|
+
|
|
36
|
+
assert.equal(calls.length, 1);
|
|
37
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
38
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
39
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
40
|
+
assert.ok(calls[0].args.task.endsWith('## Request\n\nmake the error messages clearer'));
|
|
41
|
+
assert.deepEqual(notes, [
|
|
42
|
+
{ message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.', level: 'info' },
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('/depth with no request starts nothing and shows the usage as an error', async () => {
|
|
47
|
+
const { commands } = await loadExtension({});
|
|
48
|
+
const { ctx, calls, notes } = makeCtx();
|
|
49
|
+
await commands.get('depth').handler('', ctx);
|
|
50
|
+
assert.equal(calls.length, 0);
|
|
51
|
+
assert.equal(notes.length, 1);
|
|
52
|
+
assert.equal(notes[0].level, 'error');
|
|
53
|
+
assert.match(notes[0].message, /^\/depth needs a request: \/depth <request>\./);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('/depth without the host tool says so, and a context with no ui does not throw', async () => {
|
|
57
|
+
const { commands } = await loadExtension({});
|
|
58
|
+
const { ctx, calls, notes } = makeCtx({ tools: [] });
|
|
59
|
+
await commands.get('depth').handler('fix the login', ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.match(notes[0].message, /subagent_run/);
|
|
62
|
+
assert.equal(notes[0].level, 'error');
|
|
63
|
+
|
|
64
|
+
await assert.doesNotReject(commands.get('depth').handler('fix the login', { tools: [], executeTool: async () => ({}) }));
|
|
65
|
+
await assert.doesNotReject(commands.get('depth').handler(undefined, undefined));
|
|
66
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth`'s launch (S4, S5, S8): the command starts ONE background `gentle-ai-explore` through the host's own
|
|
3
|
+
// `subagent_run` tool, with the Depth task and nothing else. Progress, cancellation and the delivery of the handoff are
|
|
4
|
+
// gentle-agents', so this module has no widget, no timer and no message of its own; it only decides whether the launch can
|
|
5
|
+
// happen and says in one sentence what did or did not.
|
|
6
|
+
const { test } = require('node:test');
|
|
7
|
+
const assert = require('node:assert/strict');
|
|
8
|
+
const { launchDepth, DEPTH_AGENT, DEPTH_TOOL } = require('../lib/depth-launch.js');
|
|
9
|
+
const { DEPTH_RETURN_HEADINGS } = require('../lib/depth-task.js');
|
|
10
|
+
|
|
11
|
+
const STARTED = {
|
|
12
|
+
content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task abc-1.' }],
|
|
13
|
+
details: {},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function host({ outcome = STARTED, tools = [{ name: 'subagent_run' }, { name: 'job_list' }], throws } = {}) {
|
|
17
|
+
const calls = [];
|
|
18
|
+
const ctx = {
|
|
19
|
+
tools,
|
|
20
|
+
executeTool: async (name, args) => {
|
|
21
|
+
calls.push({ name, args });
|
|
22
|
+
if (throws) throw throws;
|
|
23
|
+
return outcome;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return { ctx, calls };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('the names the launch depends on are the host agent and tool', () => {
|
|
30
|
+
assert.equal(DEPTH_AGENT, 'gentle-ai-explore');
|
|
31
|
+
assert.equal(DEPTH_TOOL, 'subagent_run');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('it starts one background explorer, with exactly the arguments the host tool accepts', async () => {
|
|
35
|
+
const { ctx, calls } = host();
|
|
36
|
+
const request = 'make the error messages clearer\n\n- keep «exactly» this';
|
|
37
|
+
const result = await launchDepth(request, ctx);
|
|
38
|
+
|
|
39
|
+
assert.equal(calls.length, 1);
|
|
40
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
41
|
+
// `subagent_run` rejects any other key (additionalProperties: false), so the set is closed.
|
|
42
|
+
assert.deepEqual(Object.keys(calls[0].args).sort(), ['agent', 'label', 'mode', 'task']);
|
|
43
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
44
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
45
|
+
assert.equal(calls[0].args.label, 'depth: make the error messages clearer');
|
|
46
|
+
assert.ok(calls[0].args.task.endsWith(`## Request\n\n${request}`), 'the request goes in verbatim, last');
|
|
47
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(calls[0].args.task.includes(heading), heading);
|
|
48
|
+
|
|
49
|
+
assert.deepEqual(result, {
|
|
50
|
+
ok: true,
|
|
51
|
+
level: 'info',
|
|
52
|
+
message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a blank request starts nothing and says how to use the command', async () => {
|
|
57
|
+
for (const blank of ['', ' \n', undefined, null]) {
|
|
58
|
+
const { ctx, calls } = host();
|
|
59
|
+
const result = await launchDepth(blank, ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.equal(result.ok, false);
|
|
62
|
+
assert.equal(result.level, 'error');
|
|
63
|
+
assert.match(result.message, /^\/depth needs a request: \/depth <request>\./);
|
|
64
|
+
assert.match(result.message, /does not see this chat/);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('without the host tool nothing starts, and the sentence names the tool', async () => {
|
|
69
|
+
const noTool = { executeTool: async () => assert.fail('must not be called') };
|
|
70
|
+
const cases = [
|
|
71
|
+
{ ...noTool },
|
|
72
|
+
{ ...noTool, tools: [] },
|
|
73
|
+
{ ...noTool, tools: [{ name: 'job_list' }] },
|
|
74
|
+
{ ...noTool, tools: 'subagent_run' },
|
|
75
|
+
{ tools: [{ name: 'subagent_run' }] },
|
|
76
|
+
undefined,
|
|
77
|
+
null,
|
|
78
|
+
];
|
|
79
|
+
for (const ctx of cases) {
|
|
80
|
+
const result = await launchDepth('fix the login', ctx);
|
|
81
|
+
assert.equal(result.ok, false);
|
|
82
|
+
assert.equal(result.level, 'error');
|
|
83
|
+
assert.match(result.message, /subagent_run/);
|
|
84
|
+
assert.match(result.message, /does not offer it/);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a refusal from the host tool is shown with its own words', async () => {
|
|
89
|
+
const { ctx, calls } = host({ outcome: { isError: true, content: [{ type: 'text', text: 'Background subagents need an interactive session.' }] } });
|
|
90
|
+
const result = await launchDepth('fix the login', ctx);
|
|
91
|
+
assert.equal(calls.length, 1);
|
|
92
|
+
assert.deepEqual(result, {
|
|
93
|
+
ok: false,
|
|
94
|
+
level: 'error',
|
|
95
|
+
message: "/depth couldn't start the explorer: Background subagents need an interactive session.",
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a refusal with no text, a thrown error and an empty answer each become one sentence', async () => {
|
|
100
|
+
const silent = await launchDepth('x', host({ outcome: { isError: true, content: [] } }).ctx);
|
|
101
|
+
assert.equal(silent.message, "/depth couldn't start the explorer: the subagent_run tool reported an error.");
|
|
102
|
+
|
|
103
|
+
const thrown = await launchDepth('x', host({ throws: new Error('boom') }).ctx);
|
|
104
|
+
assert.equal(thrown.ok, false);
|
|
105
|
+
assert.equal(thrown.message, "/depth couldn't start the explorer: boom");
|
|
106
|
+
|
|
107
|
+
// `null`, not `undefined`: the double's default parameter would turn `undefined` into a successful start.
|
|
108
|
+
const empty = await launchDepth('x', host({ outcome: null }).ctx);
|
|
109
|
+
assert.equal(empty.ok, false);
|
|
110
|
+
assert.match(empty.message, /^\/depth couldn't start the explorer:/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a hostile context never makes it throw', async () => {
|
|
114
|
+
const hostile = {
|
|
115
|
+
get tools() {
|
|
116
|
+
throw new Error('no tools for you');
|
|
117
|
+
},
|
|
118
|
+
executeTool: async () => STARTED,
|
|
119
|
+
};
|
|
120
|
+
const result = await launchDepth('fix the login', hostile);
|
|
121
|
+
assert.equal(result.ok, false);
|
|
122
|
+
assert.match(result.message, /subagent_run/);
|
|
123
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The task `/depth` hands the explorer: the instructions of `lib/depth-prompt/depth.md`, then the request exactly as the
|
|
3
|
+
// person typed it (S1, S3, S8). The explorer has no chat, so the request is the only thing it will ever know of the
|
|
4
|
+
// person's words, and it comes back first in the handoff (S8, L8).
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { buildDepthTask, depthLabel, DEPTH_RETURN_HEADINGS, DEPTH_BANNER, DEPTH_FOR_PARENT } = require('../lib/depth-task.js');
|
|
8
|
+
|
|
9
|
+
const REQUEST = 'make the error messages clearer\n\n- keep «exactly» this: `/x failed:`\n- no retries';
|
|
10
|
+
|
|
11
|
+
test('the task is the instructions, then the request exactly as typed', () => {
|
|
12
|
+
const task = buildDepthTask(REQUEST, { read: () => 'INSTRUCTIONS' });
|
|
13
|
+
assert.ok(task.startsWith('INSTRUCTIONS'), 'the instructions lead');
|
|
14
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`), 'the request closes the task, byte for byte');
|
|
15
|
+
assert.equal(task.split('## Request').length - 1, 1, 'one request section');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('only the ends of the request are trimmed, never its inside', () => {
|
|
19
|
+
const task = buildDepthTask('\n a\n\n b \n\n', { read: () => 'I' });
|
|
20
|
+
assert.ok(task.endsWith('## Request\n\na\n\n b'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('a blank or non-string request builds no task', () => {
|
|
24
|
+
for (const blank of ['', ' ', '\n\t\n', undefined, null, 5, {}]) {
|
|
25
|
+
assert.equal(buildDepthTask(blank, { read: () => 'I' }), null);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('a missing or empty instructions file still gives a task that names every section', () => {
|
|
30
|
+
const unreadable = () => {
|
|
31
|
+
throw new Error('ENOENT');
|
|
32
|
+
};
|
|
33
|
+
for (const read of [unreadable, () => '', () => ' \n', () => undefined]) {
|
|
34
|
+
const task = buildDepthTask(REQUEST, { read });
|
|
35
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`));
|
|
36
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(task.includes(heading), `fallback names ${heading}`);
|
|
37
|
+
assert.match(task, /Never carry the request out/);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the shipped instructions name the return sections in order, and the parent closes them', () => {
|
|
42
|
+
const task = buildDepthTask('x');
|
|
43
|
+
let at = -1;
|
|
44
|
+
for (const heading of DEPTH_RETURN_HEADINGS) {
|
|
45
|
+
const next = task.indexOf(`\n${heading}\n`, at + 1);
|
|
46
|
+
assert.ok(next > at, `${heading} appears after the previous section`);
|
|
47
|
+
at = next;
|
|
48
|
+
}
|
|
49
|
+
assert.equal(DEPTH_RETURN_HEADINGS[0], '## Original request', 'the verbatim request leads the handoff');
|
|
50
|
+
assert.equal(DEPTH_RETURN_HEADINGS.at(-1), '## For the parent', 'the line for the parent closes it');
|
|
51
|
+
assert.match(task, /Do not implement/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the label is one short line that starts with the command', () => {
|
|
55
|
+
assert.equal(depthLabel('fix the login'), 'depth: fix the login');
|
|
56
|
+
const long = depthLabel(`${'x'.repeat(200)}\nsecond line`);
|
|
57
|
+
assert.ok(long.startsWith('depth: xxx') && long.endsWith('…') && !long.includes('\n'));
|
|
58
|
+
assert.ok(long.length <= 60, `short enough, got ${long.length}`);
|
|
59
|
+
assert.equal(depthLabel('first\nsecond'), 'depth: first');
|
|
60
|
+
for (const blank of ['', ' ', undefined, 5]) assert.equal(depthLabel(blank), 'depth');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the parent is guarded at both ends: an opening line and the closing paragraph, in the shipped file and in the fallback', () => {
|
|
64
|
+
// The parent wakes on the handoff alone and may start implementing, so the instruction not to must not depend on one
|
|
65
|
+
// section a cheap model can drop (a real run dropped `## For the parent` and translated the headings).
|
|
66
|
+
assert.equal(typeof DEPTH_BANNER, 'string');
|
|
67
|
+
assert.equal(typeof DEPTH_FOR_PARENT, 'string');
|
|
68
|
+
assert.match(DEPTH_BANNER, /nothing was implemented/);
|
|
69
|
+
assert.match(DEPTH_FOR_PARENT, /^Do not implement this request\./);
|
|
70
|
+
for (const read of [undefined, () => '']) {
|
|
71
|
+
const task = buildDepthTask('x', read === undefined ? {} : { read });
|
|
72
|
+
assert.ok(task.includes(DEPTH_BANNER), 'the opening line is asked for');
|
|
73
|
+
assert.ok(task.includes(DEPTH_FOR_PARENT), 'the closing paragraph is given');
|
|
74
|
+
assert.match(task, /character for character/);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
@@ -433,8 +433,8 @@ test('S18/S19 (T14): the ready announcement registers the whole surface, exactly
|
|
|
433
433
|
const bridge = installBridge();
|
|
434
434
|
for (const entry of ready) entry.handler();
|
|
435
435
|
|
|
436
|
-
assert.deepEqual([...loaded.commands.keys()].sort(), ['files', 'issues', 'odd', 'warp'],
|
|
437
|
-
'the
|
|
436
|
+
assert.deepEqual([...loaded.commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp'],
|
|
437
|
+
'the five commands arrive with the bridge');
|
|
438
438
|
assert.deepEqual([...loaded.tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the two tools');
|
|
439
439
|
assert.deepEqual([...loaded.messageRenderers.keys()], ['worktree-warp'], 'the message renderer');
|
|
440
440
|
assert.deepEqual([...loaded.entryRenderers.keys()].sort(), ['odd-worktree-issues-refusal', 'odd-worktree-warp-queue'],
|
|
@@ -244,7 +244,7 @@ const agentStub = {
|
|
|
244
244
|
describe('/files registration (S17)', () => {
|
|
245
245
|
test('the file picker is registered beside the other three panels', async () => {
|
|
246
246
|
const { commands } = await loadExtension({});
|
|
247
|
-
assert.deepEqual([...commands.keys()].sort(), ['files', 'issues', 'odd', 'warp']);
|
|
247
|
+
assert.deepEqual([...commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp']);
|
|
248
248
|
const files = commands.get('files');
|
|
249
249
|
assert.equal(typeof files.handler, 'function', 'the command carries its handler');
|
|
250
250
|
assert.ok(files.description.includes('files'), 'the description says what it browses');
|