pi-odd-worktree 3.1.1 → 3.3.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 +2 -1
- package/extensions/odd-worktree-tools.ts +83 -3
- package/lib/bash-activity.js +405 -32
- package/lib/bash-inline-script.js +314 -0
- package/lib/codegraph-guard.js +36 -19
- package/lib/codegraph-prompt/generic.md +1 -1
- package/lib/codegraph-prompt/orchestrator.md +7 -7
- package/lib/codegraph-session.js +10 -2
- package/lib/odd-prompt/odd-worktrees-child.md +3 -0
- package/lib/odd-prompt/odd-worktrees.md +11 -7
- package/lib/odd-worktrees-prompt.js +68 -14
- package/lib/skill-read-guard.js +397 -0
- package/lib/worktree-guard.js +205 -5
- package/package.json +1 -1
- package/tools/bash-activity.test.js +400 -35
- package/tools/codegraph-guard.test.js +109 -11
- package/tools/codegraph-rules.test.js +8 -8
- package/tools/codegraph-session.test.js +45 -3
- package/tools/odd-worktrees-prompt.test.js +98 -11
- package/tools/package-surface.test.js +15 -1
- package/tools/skill-read-guard.test.js +316 -0
- package/tools/worktree-write-guard.test.js +516 -0
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// T1 (S1, S2, S5, S6, S7): the decision core of the two CodeGraph reminders. From one
|
|
3
|
-
// call, the session's own checkout, the role and what the
|
|
4
|
-
// none, keeps the once-per-key state,
|
|
5
|
-
// toplevel map here: no child, no network, no
|
|
2
|
+
// T1 (S1, S2, S5, S6, S7) and T6 (S3): the decision core of the two CodeGraph reminders. From one
|
|
3
|
+
// finished tool call, the session's own checkout, the role and what the request already used, it decides
|
|
4
|
+
// one text or none, keeps the once-per-key state, re-arms guard 2 at every new request, and forgets
|
|
5
|
+
// everything on a compaction or a new session. Git is a fake toplevel map here: no child, no network, no
|
|
6
|
+
// real agent directory.
|
|
6
7
|
const { test } = require('node:test');
|
|
7
8
|
const assert = require('node:assert/strict');
|
|
8
9
|
const { createCodegraphGuard } = require('../lib/codegraph-guard.js');
|
|
9
10
|
|
|
10
|
-
// The approved texts of S1 and S2, written out so a reworded reminder fails here.
|
|
11
|
+
// The approved texts of S1 and S2, written out so a reworded reminder fails here. S3 took the trailing
|
|
12
|
+
// ", if it applies" off both sentences.
|
|
11
13
|
const ANOTHER = (root) => `This call went to ${root}, another checkout. Follow the CodeGraph rule: call \`mcp__codegraph__codegraph_explore\` with \`projectPath\` set to ${root} first.`;
|
|
12
|
-
const NATIVE = 'Follow the CodeGraph rule: run `codegraph` `query` or `explore` first
|
|
13
|
-
const MCP = 'Follow the CodeGraph rule: call `mcp__codegraph__codegraph_explore` first
|
|
14
|
+
const NATIVE = 'Follow the CodeGraph rule: run `codegraph` `query` or `explore` first.';
|
|
15
|
+
const MCP = 'Follow the CodeGraph rule: call `mcp__codegraph__codegraph_explore` first.';
|
|
14
16
|
|
|
15
17
|
const ROOTS = {
|
|
16
18
|
'/repo': '/repo',
|
|
@@ -74,6 +76,17 @@ test('a session holding only the MCP tool is pointed at the MCP call instead', a
|
|
|
74
76
|
assert.equal(await guard.onToolResult(grep(), ctx), MCP);
|
|
75
77
|
});
|
|
76
78
|
|
|
79
|
+
test('neither sentence ends in ", if it applies" any more (S3)', async () => {
|
|
80
|
+
const native = setup();
|
|
81
|
+
const mcp = setup({ tools: ['grep', 'mcp__codegraph__codegraph_explore'] });
|
|
82
|
+
const texts = [await native.guard.onToolResult(grep(), native.ctx), await mcp.guard.onToolResult(grep(), mcp.ctx)];
|
|
83
|
+
assert.deepEqual(texts, [NATIVE, MCP]);
|
|
84
|
+
for (const text of texts) {
|
|
85
|
+
assert.ok(!text.includes('if it applies'), text);
|
|
86
|
+
assert.ok(text.endsWith(' first.'), text);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
77
90
|
test('an explore agent gets the native wording, every other child the MCP one', async () => {
|
|
78
91
|
const child = (agent, tools) => setup({
|
|
79
92
|
env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: tools },
|
|
@@ -144,7 +157,7 @@ test('a path with no git checkout triggers nothing, and uses up no slot', async
|
|
|
144
157
|
|
|
145
158
|
// ---- guard 2's key is the session's own checkout (S7) ----
|
|
146
159
|
|
|
147
|
-
test('guard 2
|
|
160
|
+
test('guard 2 reminds on the first search of a checkout, and a warp to another checkout re-arms it', async () => {
|
|
148
161
|
const { guard, ctx } = setup();
|
|
149
162
|
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
|
|
150
163
|
assert.equal(await guard.onToolResult(grep(), ctx), undefined);
|
|
@@ -152,6 +165,91 @@ test('guard 2 is once per session, and a warp to another checkout re-arms it', a
|
|
|
152
165
|
assert.equal(await guard.onToolResult(read('/third/a.ts'), warped), NATIVE, 'the new checkout has not been reminded');
|
|
153
166
|
});
|
|
154
167
|
|
|
168
|
+
// ---- guard 2 reminds once per checkout per request (S3, S7) ----
|
|
169
|
+
|
|
170
|
+
const use = (toolName) => ({ toolName, input: { operation: 'query' }, isError: false, content: [] });
|
|
171
|
+
|
|
172
|
+
/** The texts the guard answered over `count` back-to-back searches in one checkout. */
|
|
173
|
+
async function row(guard, ctx, count) {
|
|
174
|
+
const texts = [];
|
|
175
|
+
for (let call = 0; call < count; call += 1) texts.push(await guard.onToolResult(grep(), ctx));
|
|
176
|
+
return texts;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const silent = (count) => Array(count).fill(undefined);
|
|
180
|
+
|
|
181
|
+
test('one reminder per request, whatever the number of searches after it (S3, S7)', async () => {
|
|
182
|
+
const { guard, ctx } = setup();
|
|
183
|
+
// One first search plus 8, 9 and 17 more: the searches at 8, 9 and 17 since the reminder earn nothing.
|
|
184
|
+
const texts = [await guard.onToolResult(grep(), ctx)];
|
|
185
|
+
for (const count of [8, 9, 17]) texts.push(...await row(guard, ctx, count));
|
|
186
|
+
const reminded = texts.map((text, index) => (text === undefined ? undefined : index + 1)).filter((at) => at !== undefined);
|
|
187
|
+
assert.deepEqual(reminded, [1], 'only the first search of the checkout is reminded, never the 8th, 9th or 17th after it');
|
|
188
|
+
assert.deepEqual(texts.filter((text) => text !== undefined), [NATIVE]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('a CodeGraph use neither earns a reminder nor re-arms the one already given (S3)', async () => {
|
|
192
|
+
const forUse = setup();
|
|
193
|
+
assert.equal(await forUse.guard.onToolResult(grep(), forUse.ctx), NATIVE, 'the first reminder');
|
|
194
|
+
assert.deepEqual(await row(forUse.guard, forUse.ctx, 4), silent(4));
|
|
195
|
+
assert.equal(await forUse.guard.onToolResult(use('codegraph'), forUse.ctx), undefined, 'a use is no search call');
|
|
196
|
+
assert.deepEqual(await row(forUse.guard, forUse.ctx, 9), silent(9), 'the checkout already had its one reminder');
|
|
197
|
+
|
|
198
|
+
const forExplore = setup();
|
|
199
|
+
assert.equal(await forExplore.guard.onToolResult(grep(), forExplore.ctx), NATIVE);
|
|
200
|
+
await forExplore.guard.onToolResult(explore('/repo'), forExplore.ctx);
|
|
201
|
+
assert.deepEqual(await row(forExplore.guard, forExplore.ctx, 17), silent(17), 'the MCP explore call re-arms nothing either');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('each checkout hears its own one reminder in a request (S3)', async () => {
|
|
205
|
+
const { guard, ctx } = setup();
|
|
206
|
+
const warped = { cwd: '/third' };
|
|
207
|
+
assert.equal(await guard.onToolResult(read('src/a.ts'), ctx), NATIVE, 'the /repo checkout reminds on its first search');
|
|
208
|
+
assert.deepEqual(await row(guard, ctx, 17), silent(17), 'and never again in this request');
|
|
209
|
+
assert.equal(await guard.onToolResult(read('/third/a.ts'), warped), NATIVE, 'a warp to /third has its own reminder');
|
|
210
|
+
assert.deepEqual(await row(guard, warped, 17), silent(17), 'once, and then never again either');
|
|
211
|
+
assert.deepEqual(await row(guard, ctx, 17), silent(17), 'and /repo stays silent');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// ---- a new request re-arms guard 2 (S7) ----
|
|
215
|
+
//
|
|
216
|
+
// Each new request forgets guard 2's first-search slots and its `used` flag, so the first search of every
|
|
217
|
+
// request is reminded again; guard 1's slots and the explored checkouts stay per session.
|
|
218
|
+
|
|
219
|
+
test('a new request reminds its first search again (S7)', async () => {
|
|
220
|
+
const { guard, ctx } = setup();
|
|
221
|
+
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the first search of the request reminds');
|
|
222
|
+
assert.deepEqual(await row(guard, ctx, 17), silent(17), 'and no later search of it does');
|
|
223
|
+
guard.onNewRequest();
|
|
224
|
+
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the next request is reminded on its first search');
|
|
225
|
+
assert.deepEqual(await row(guard, ctx, 17), silent(17), 'it hears it once too');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('a CodeGraph use in the previous request does not silence the first search of the next (S7)', async () => {
|
|
229
|
+
const { guard, ctx } = setup();
|
|
230
|
+
await guard.onToolResult(use('codegraph'), ctx);
|
|
231
|
+
assert.equal(await guard.onToolResult(grep(), ctx), undefined, 'the graph was already used in this request');
|
|
232
|
+
guard.onNewRequest();
|
|
233
|
+
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'a new request starts with the graph unused');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('a new request keeps guard 1 once per other checkout across requests (S7)', async () => {
|
|
237
|
+
const { guard, ctx } = setup();
|
|
238
|
+
assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
|
|
239
|
+
guard.onNewRequest();
|
|
240
|
+
assert.equal(await guard.onToolResult(read('/other/b.ts'), ctx), undefined, 'a new request is no new checkout');
|
|
241
|
+
assert.equal(await guard.onToolResult(read('/third/a.ts'), ctx), ANOTHER('/third'), 'an unseen checkout still gets its reminder');
|
|
242
|
+
guard.onNewRequest();
|
|
243
|
+
assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined, 'and it stays once per session');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('a new request does not forget the checkouts the session already explored (S7)', async () => {
|
|
247
|
+
const { guard, ctx } = setup();
|
|
248
|
+
assert.equal(await guard.onToolResult(explore('/other'), ctx), undefined, 'an explore call is no search call');
|
|
249
|
+
guard.onNewRequest();
|
|
250
|
+
assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined, 'guard 1 stays satisfied by that explore');
|
|
251
|
+
});
|
|
252
|
+
|
|
155
253
|
// ---- precision (S5) ----
|
|
156
254
|
|
|
157
255
|
test('guard 1 stays silent for a checkout this session already explored, without using its slot', async () => {
|
|
@@ -168,12 +266,12 @@ test('guard 1 understands an explore aimed at a directory inside that checkout',
|
|
|
168
266
|
assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
|
|
169
267
|
});
|
|
170
268
|
|
|
171
|
-
test('
|
|
269
|
+
test('a session that used CodeGraph before its first search is not reminded on that first search', async () => {
|
|
172
270
|
const { guard, ctx } = setup();
|
|
173
|
-
await guard.onToolResult(
|
|
271
|
+
await guard.onToolResult(use('codegraph'), ctx);
|
|
174
272
|
assert.equal(await guard.onToolResult(grep(), ctx), undefined, 'the graph was already used');
|
|
175
273
|
guard.onCompacted();
|
|
176
|
-
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the
|
|
274
|
+
assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the first-search reminder was never consumed');
|
|
177
275
|
});
|
|
178
276
|
|
|
179
277
|
test('a call that failed earns no reminder and spends no slot', async () => {
|
|
@@ -32,7 +32,7 @@ describe('the seven texts on disk', () => {
|
|
|
32
32
|
for (const variant of rules.VARIANTS) {
|
|
33
33
|
const text = file(variant).replace(/\s+/g, ' ');
|
|
34
34
|
assert.ok(text.startsWith('## CodeGraph'), variant);
|
|
35
|
-
assert.match(text, /before you search or read code
|
|
35
|
+
assert.match(text, /before you (search or read code|`grep`, `rg`, `fd`, `find`, `read` or `cat`)/i, `${variant} gates searching and reading code`);
|
|
36
36
|
for (const binary of ['fd', 'find', 'rg', 'grep', 'read', 'cat']) {
|
|
37
37
|
assert.ok(text.includes(`\`${binary}\``), `${variant} names ${binary}`);
|
|
38
38
|
}
|
|
@@ -47,9 +47,8 @@ describe('the seven texts on disk', () => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('only the roles holding the native tool name its operations; the MCP tool is named in full', () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
50
|
+
assert.match(file('explore'), /`codegraph` `query`/, 'explore');
|
|
51
|
+
assert.match(file('orchestrator'), /`codegraph` with `operation: "explore"`[\s\S]*`operation: "query"`/, 'orchestrator');
|
|
53
52
|
for (const variant of ['verify', 'worker', 'fix', 'judge']) {
|
|
54
53
|
const text = file(variant);
|
|
55
54
|
assert.ok(text.includes(`\`${MCP}\``), variant);
|
|
@@ -80,11 +79,12 @@ describe('the seven texts on disk', () => {
|
|
|
80
79
|
describe('the orchestrator and explore texts stay inside their role', () => {
|
|
81
80
|
const prose = (variant) => file(variant).replace(/\s+/g, ' ');
|
|
82
81
|
|
|
83
|
-
test('the orchestrator
|
|
82
|
+
test('the orchestrator calls the graph first for a where/who/how/what-reaches question, with one exemption and one literal call', () => {
|
|
84
83
|
const text = prose('orchestrator');
|
|
85
|
-
assert.match(text, /
|
|
86
|
-
assert.match(text,
|
|
87
|
-
assert.match(text, /
|
|
84
|
+
assert.match(text, /to answer where code lives, who calls it, how it works, or what a change reaches, call CodeGraph first/, text);
|
|
85
|
+
assert.match(text, /`codegraph` with `operation: "explore"` and `query: "<symbols or the question>"`/, 'the literal call');
|
|
86
|
+
assert.match(text, /Skip it only for an exact string or a file path the user gave you/, 'one exemption');
|
|
87
|
+
assert.match(text, /what scope, size and any handoff depend on/, 'the sizing use is kept');
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
test('the orchestrator looks at the ODD\'s own worktree through projectPath when the session runs elsewhere', () => {
|
|
@@ -334,8 +334,8 @@ test('the work a synchronous handler starts still runs after it has answered the
|
|
|
334
334
|
// session's tools come from `before_agent_start` (the only source), the checkouts from one cached fake
|
|
335
335
|
// git toplevel, and the texts are the approved ones, written out here.
|
|
336
336
|
|
|
337
|
-
const NATIVE_REMINDER = 'Follow the CodeGraph rule: run `codegraph` `query` or `explore` first
|
|
338
|
-
const MCP_REMINDER = 'Follow the CodeGraph rule: call `mcp__codegraph__codegraph_explore` first
|
|
337
|
+
const NATIVE_REMINDER = 'Follow the CodeGraph rule: run `codegraph` `query` or `explore` first.';
|
|
338
|
+
const MCP_REMINDER = 'Follow the CodeGraph rule: call `mcp__codegraph__codegraph_explore` first.';
|
|
339
339
|
const anotherReminder = (root) => `This call went to ${root}, another checkout. Follow the CodeGraph rule: call \`mcp__codegraph__codegraph_explore\` with \`projectPath\` set to ${root} first.`;
|
|
340
340
|
|
|
341
341
|
const SESSION_TOOLS = { systemPromptOptions: { selectedTools: ['read', 'grep', 'bash', 'codegraph'] } };
|
|
@@ -417,6 +417,21 @@ test('a new session start re-arms it, and a /reload is not a new session', async
|
|
|
417
417
|
assert.ok(await run('tool_result', readEvent('src/a.ts')), 'a new session forgets it');
|
|
418
418
|
});
|
|
419
419
|
|
|
420
|
+
test('a new request re-arms the one reminder of the checkout (S3, S7)', async () => {
|
|
421
|
+
const { run } = setup({ toplevel: checkoutMap() });
|
|
422
|
+
await run('before_agent_start', SESSION_TOOLS);
|
|
423
|
+
const texts = [];
|
|
424
|
+
for (let call = 0; call < 17; call += 1) {
|
|
425
|
+
const patch = await run('tool_result', readEvent('src/a.ts'));
|
|
426
|
+
texts.push(patch === undefined ? undefined : patch.content[1].text);
|
|
427
|
+
}
|
|
428
|
+
assert.deepEqual(texts.filter((text) => text !== undefined), [NATIVE_REMINDER], '17 searches of one request hear it once');
|
|
429
|
+
assert.equal(texts[0], NATIVE_REMINDER, 'and on the first of them, not at 8, 9 or 17');
|
|
430
|
+
await run('before_agent_start', SESSION_TOOLS);
|
|
431
|
+
const next = await run('tool_result', readEvent('src/a.ts'));
|
|
432
|
+
assert.equal(next.content[1].text, NATIVE_REMINDER, 'the first search of the next request hears it again');
|
|
433
|
+
});
|
|
434
|
+
|
|
420
435
|
test('a worker child is told to call the MCP tool, and a review agent is told nothing', async () => {
|
|
421
436
|
const worker = setup({
|
|
422
437
|
env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,bash,mcp__codegraph__codegraph_explore' },
|
|
@@ -447,7 +462,7 @@ test('a git read that throws never fails the tool result', async () => {
|
|
|
447
462
|
});
|
|
448
463
|
|
|
449
464
|
test('the guard is one injected collaborator, driven by the host events', async () => {
|
|
450
|
-
const seen = { tools: [], results: [], compacted: 0, sessions: 0 };
|
|
465
|
+
const seen = { tools: [], results: [], compacted: 0, sessions: 0, requests: 0 };
|
|
451
466
|
const { run } = setup({
|
|
452
467
|
impl: {
|
|
453
468
|
createCodegraphGuard: (options) => {
|
|
@@ -464,6 +479,9 @@ test('the guard is one injected collaborator, driven by the host events', async
|
|
|
464
479
|
onNewSession: () => {
|
|
465
480
|
seen.sessions += 1;
|
|
466
481
|
},
|
|
482
|
+
onNewRequest: () => {
|
|
483
|
+
seen.requests += 1;
|
|
484
|
+
},
|
|
467
485
|
};
|
|
468
486
|
},
|
|
469
487
|
},
|
|
@@ -476,10 +494,34 @@ test('the guard is one injected collaborator, driven by the host events', async
|
|
|
476
494
|
assert.deepEqual(seen.tools, [SESSION_TOOLS.systemPromptOptions.selectedTools]);
|
|
477
495
|
assert.equal(seen.compacted, 1);
|
|
478
496
|
assert.equal(seen.sessions, 2, 'the startup and the new session both reset');
|
|
497
|
+
assert.equal(seen.requests, 1, 'one new request, no more');
|
|
479
498
|
assert.deepEqual(seen.results, ['grep']);
|
|
480
499
|
assert.deepEqual(patch.content, [{ type: 'text', text: 'REMINDER' }], 'the reminder rides the result as one more part');
|
|
481
500
|
});
|
|
482
501
|
|
|
502
|
+
test('S7: every new request re-arms guard 2, and a finished call does not', async () => {
|
|
503
|
+
let requests = 0;
|
|
504
|
+
const { run } = setup({
|
|
505
|
+
impl: {
|
|
506
|
+
createCodegraphGuard: () => ({
|
|
507
|
+
observeTools: () => {},
|
|
508
|
+
onToolResult: async () => undefined,
|
|
509
|
+
onCompacted: () => {},
|
|
510
|
+
onNewSession: () => {},
|
|
511
|
+
onNewRequest: () => {
|
|
512
|
+
requests += 1;
|
|
513
|
+
},
|
|
514
|
+
}),
|
|
515
|
+
},
|
|
516
|
+
});
|
|
517
|
+
await run('tool_result', { toolName: 'grep', input: { pattern: 'x' }, isError: false, content: [] });
|
|
518
|
+
assert.equal(requests, 0, 'a finished tool call is no new request');
|
|
519
|
+
await run('before_agent_start', SESSION_TOOLS);
|
|
520
|
+
assert.equal(requests, 1, 'the prompt of a new request re-arms it');
|
|
521
|
+
await run('before_agent_start', SESSION_TOOLS);
|
|
522
|
+
assert.equal(requests, 2, 'each new request, not each session');
|
|
523
|
+
});
|
|
524
|
+
|
|
483
525
|
// ---- S2: the bounded join on the pre-execution hook (T6) ----
|
|
484
526
|
//
|
|
485
527
|
// Before a CodeGraph search runs, the index work this process already has in flight for that checkout is
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// S7: the `## ODD worktrees` section and its append-only injection. The
|
|
3
|
-
// the contract, so it is asserted verbatim. There is exactly ONE
|
|
4
|
-
//
|
|
2
|
+
// S7 and (T3) S5: the `## ODD worktrees` section and its append-only injection. The
|
|
3
|
+
// text is the contract, so it is asserted verbatim. There is exactly ONE primary
|
|
4
|
+
// section, plus the one short block a child that WRITES gets (S5): the same heading,
|
|
5
|
+
// its own file, and only for the three kinds of writing child.
|
|
5
6
|
const { test, describe, after } = require('node:test');
|
|
6
7
|
const assert = require('node:assert/strict');
|
|
7
8
|
const os = require('node:os');
|
|
@@ -15,6 +16,19 @@ const PROMPT_DIR = path.resolve(__dirname, '..', 'lib', 'odd-prompt');
|
|
|
15
16
|
const SECTION_FILE = path.join(PROMPT_DIR, 'odd-worktrees.md');
|
|
16
17
|
const SECTION = fs.readFileSync(SECTION_FILE, 'utf8').trim();
|
|
17
18
|
|
|
19
|
+
// S5: the one-line block a CHILD that writes gets. It lives in its own file, so it is
|
|
20
|
+
// read here the way it is read on disk; a file that is gone fails the cases below.
|
|
21
|
+
const CHILD_FILE = path.join(PROMPT_DIR, 'odd-worktrees-child.md');
|
|
22
|
+
const childSection = () => fs.readFileSync(CHILD_FILE, 'utf8').trim();
|
|
23
|
+
|
|
24
|
+
// The argv a subagent child really runs with: one directory named after the agent.
|
|
25
|
+
function childArgv(agent) {
|
|
26
|
+
if (typeof agent !== 'string') return ['node', path.join(os.tmpdir(), 'plain-agent', 'instructions.md')];
|
|
27
|
+
return ['node', path.join(os.tmpdir(), `gentle-pi-subagent-${agent}-ab12cd`, 'instructions.md')];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const CHILD_ENV = { GENTLE_PI_AGENTS_CHILD: '1' };
|
|
31
|
+
|
|
18
32
|
const savedEnv = { ...process.env };
|
|
19
33
|
after(() => {
|
|
20
34
|
for (const key of Object.keys(process.env)) {
|
|
@@ -90,12 +104,13 @@ describe('session gating', () => {
|
|
|
90
104
|
}
|
|
91
105
|
});
|
|
92
106
|
|
|
93
|
-
test('a GENTLE_PI_AGENTS_CHILD
|
|
107
|
+
test('a GENTLE_PI_AGENTS_CHILD session gets the child block, never the primary one', () => {
|
|
94
108
|
clearEnv();
|
|
95
109
|
process.env.GENTLE_PI_AGENTS_CHILD = '1';
|
|
96
110
|
const options = {};
|
|
97
111
|
run(primaryEvent(options), { env: process.env });
|
|
98
|
-
assert.equal(options.appendSystemPrompt,
|
|
112
|
+
assert.equal(options.appendSystemPrompt, childSection(), 'a child whose name cannot be read is the generic child');
|
|
113
|
+
assert.notEqual(options.appendSystemPrompt, SECTION);
|
|
99
114
|
});
|
|
100
115
|
|
|
101
116
|
test('ODD_WORKTREE_PROMPT=0 suppresses the block entirely', () => {
|
|
@@ -127,6 +142,77 @@ describe('extension wiring (T3)', () => {
|
|
|
127
142
|
});
|
|
128
143
|
});
|
|
129
144
|
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
// S5: the child block — one short line, and only for a child that writes.
|
|
147
|
+
// ---------------------------------------------------------------------------
|
|
148
|
+
describe('S5: a child that writes gets one short block', () => {
|
|
149
|
+
test('the block lives in its own file, opens with the idempotency heading and states the rule in two sentences at most', () => {
|
|
150
|
+
const text = childSection();
|
|
151
|
+
assert.ok(text.startsWith('## ODD worktrees'), text.split('\n')[0]);
|
|
152
|
+
assert.match(text.replace(/\s+/g, ' '), /work only under the worktree of your workspace root/i);
|
|
153
|
+
assert.match(text.replace(/\s+/g, ' '), /primary checkout on the default branch/i);
|
|
154
|
+
assert.match(text.replace(/\s+/g, ' '), /stop and report/i);
|
|
155
|
+
assert.match(text.replace(/\s+/g, ' '), /instead of writing/i);
|
|
156
|
+
const sentences = (text.replace(/\s+/g, ' ').match(/[.!?](\s|$)/g) || []).length;
|
|
157
|
+
assert.ok(sentences <= 2, `two sentences at most, got ${sentences}`);
|
|
158
|
+
assert.notEqual(text, SECTION, 'the child block is not the primary block');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('gentle-ai-worker, jd-fix-agent and a child whose agent name cannot be read get it', () => {
|
|
162
|
+
for (const agent of ['gentle-ai-worker', 'jd-fix-agent', undefined]) {
|
|
163
|
+
const options = {};
|
|
164
|
+
run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv(agent) });
|
|
165
|
+
assert.equal(options.appendSystemPrompt, childSection(), String(agent));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('a child whose name is outside the table is the generic child, and gets it too', () => {
|
|
170
|
+
const options = {};
|
|
171
|
+
run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('some-unknown-agent') });
|
|
172
|
+
assert.equal(options.appendSystemPrompt, childSection());
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('explore, verify, the two judges and every review-* child get nothing', () => {
|
|
176
|
+
for (const agent of ['gentle-ai-explore', 'gentle-ai-verify', 'jd-judge-a', 'jd-judge-b', 'review-a', 'review-verify']) {
|
|
177
|
+
const options = {};
|
|
178
|
+
run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv(agent) });
|
|
179
|
+
assert.equal(options.appendSystemPrompt, undefined, agent);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('a child block is appended after the harness text and is idempotent', () => {
|
|
184
|
+
const harness = 'You are Pi.\n\nUse the tools.';
|
|
185
|
+
const options = { appendSystemPrompt: harness };
|
|
186
|
+
run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('gentle-ai-worker') });
|
|
187
|
+
assert.ok(options.appendSystemPrompt.startsWith(harness), 'existing text is the prefix');
|
|
188
|
+
assert.equal(options.appendSystemPrompt, `${harness}\n\n${childSection()}`);
|
|
189
|
+
const once = options.appendSystemPrompt;
|
|
190
|
+
run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('gentle-ai-worker') });
|
|
191
|
+
assert.equal(options.appendSystemPrompt, once, 'a second call adds nothing');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('ODD_WORKTREE_PROMPT=0 suppresses the child block too', () => {
|
|
195
|
+
const options = {};
|
|
196
|
+
run(primaryEvent(options), { env: { ...CHILD_ENV, ODD_WORKTREE_PROMPT: '0' }, argv: childArgv('gentle-ai-worker') });
|
|
197
|
+
assert.equal(options.appendSystemPrompt, undefined);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('the primary session keeps its own block, unchanged', () => {
|
|
201
|
+
const options = {};
|
|
202
|
+
run(primaryEvent(options), { env: {}, argv: childArgv('gentle-ai-worker') });
|
|
203
|
+
assert.equal(options.appendSystemPrompt, SECTION, 'a primary session gets the primary block');
|
|
204
|
+
assert.notEqual(SECTION, childSection());
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('a missing child file falls back to the heading alone, never a crash', () => {
|
|
208
|
+
const missing = path.join(os.tmpdir(), `odd-prompt-missing-${process.pid}`, 'odd-worktrees-child.md');
|
|
209
|
+
assert.equal(prompt.readPromptFile(missing), null);
|
|
210
|
+
assert.equal(prompt.sectionFromFile(missing, prompt.CHILD_FALLBACK), prompt.CHILD_FALLBACK);
|
|
211
|
+
assert.equal(prompt.CHILD_FALLBACK.trim(), '## ODD worktrees');
|
|
212
|
+
assert.equal(prompt.CHILD_SECTION, childSection());
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
130
216
|
describe('the section is prose on disk', () => {
|
|
131
217
|
test('the section lives in its own Markdown file and is what gets injected', () => {
|
|
132
218
|
assert.ok(fs.existsSync(SECTION_FILE), 'the section file exists');
|
|
@@ -166,20 +252,21 @@ describe('the section states the worktree policy', () => {
|
|
|
166
252
|
|
|
167
253
|
test('the work happens in the ODD\'s worktree, never in the primary checkout or on the default branch', () => {
|
|
168
254
|
const text = prose();
|
|
169
|
-
assert.match(text, /
|
|
255
|
+
assert.match(text, /Every write goes in a worktree, whatever the size of the task, a one-line fix included\. Never write in the primary checkout or on the default branch/, text);
|
|
256
|
+
assert.doesNotMatch(text, /An ODD writes/, 'no task size decides whether the rule applies');
|
|
170
257
|
assert.match(text, /Reading anywhere is fine, and a request that stays read-only needs no worktree/, text);
|
|
171
258
|
// The rule is the premise: it opens the section, before the worktree is described.
|
|
172
|
-
assert.ok(text.indexOf('
|
|
259
|
+
assert.ok(text.indexOf('Never write in the primary checkout') < text.indexOf('A worktree lives at'), text);
|
|
173
260
|
});
|
|
174
261
|
|
|
175
262
|
test('a worktree is the ODD: find the assignment, resume it, create it, carry pending work', () => {
|
|
176
263
|
const text = prose();
|
|
177
264
|
assert.match(text, /A worktree lives at `/, text);
|
|
178
265
|
assert.match(text, /directory IS the ODD/, text);
|
|
179
|
-
assert.match(text, /Before
|
|
180
|
-
assert.match(text, /
|
|
181
|
-
assert.match(text, /
|
|
182
|
-
assert.match(text,
|
|
266
|
+
assert.match(text, /Before your first `edit` or `write`: 1\. Run `worktree_list`\./, text);
|
|
267
|
+
assert.match(text, /2\. If the ODD has a worktree, work there\./, text);
|
|
268
|
+
assert.match(text, /3\. If not, run `worktree_create`/, text);
|
|
269
|
+
assert.match(text, /`copy_changes: true` if the pending changes of the current checkout belong to that work/, text);
|
|
183
270
|
});
|
|
184
271
|
|
|
185
272
|
test('one ODD, one worktree', () => {
|
|
@@ -73,7 +73,7 @@ describe('manifest', () => {
|
|
|
73
73
|
// their own four modules — a classifier, the card, its resolver and the document
|
|
74
74
|
// body Pi's Markdown draws — and own no preference at all (S1): they are gated by
|
|
75
75
|
// the bridge's `Card tags` line, which is the bridge's, not ours.
|
|
76
|
-
for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'bash-activity.js', 'bash-design.js', 'bash-frame.js', 'diff-design.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
|
|
76
|
+
for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'skill-read-guard.js', 'bash-activity.js', 'bash-inline-script.js', 'bash-design.js', 'bash-frame.js', 'diff-design.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
|
|
77
77
|
assert.ok(shipped.includes(kept), `lib/${kept} is shipped`);
|
|
78
78
|
}
|
|
79
79
|
for (const gone of ['card-files-mode.js', 'cards-customize.js']) {
|
|
@@ -137,6 +137,20 @@ describe('registration', () => {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
test('the skill-read guard is one more bash hook and adds no name (invariant 22)', async () => {
|
|
141
|
+
// invariant 22: the skill-read guard is one more `bash` observation, so the `tool_call`
|
|
142
|
+
// hooks stay the naming handler, the worktree bash and write guards and this one — a
|
|
143
|
+
// fifth would be a surface nobody asked for.
|
|
144
|
+
const source = stubbedSource();
|
|
145
|
+
assert.equal(source.split('pi.on("tool_call"').length - 1, 4, 'the naming handler, the worktree bash and write guards and the skill-read guard');
|
|
146
|
+
assert.ok(source.includes('libRequire("skill-read-guard.js")'), 'the decision comes from lib/skill-read-guard.js');
|
|
147
|
+
const { commands, tools } = await loadExtension({});
|
|
148
|
+
for (const gone of ['skill-read', 'skill_read', 'skill-read-guard']) {
|
|
149
|
+
assert.equal(commands.has(gone), false, `the guard adds no /${gone} command`);
|
|
150
|
+
assert.equal(tools.has(gone), false, `the guard adds no ${gone} tool`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
140
154
|
test('both Card rows are registered once each, observed through the bridge\'s own object', async () => {
|
|
141
155
|
// S2/S6: what a caller observes is the REGISTRATION, not a spelling in the source. A bridge
|
|
142
156
|
// that publishes the release both lines need sees one design per line, each with its own id and
|