pi-odd-worktree 3.12.3 → 3.12.4

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 CHANGED
@@ -108,7 +108,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
108
108
  - **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` is refused in any cwd and pointed at `worktree_create`; in the principal checkout, a switch that would leave the branch it is on is refused while that branch is the repository's default, and creating a branch is not blocked. See [the guards](docs/reference.md#the-bash-guards).
109
109
  - **Two blocks in the system prompt.** `## ODD worktrees` tells the agent how worktrees and ODDs work. `## CodeGraph` tells a session that already holds a CodeGraph tool how to use it, with one text per role. Both are appended after the host's own text, and `ODD_WORKTREE_PROMPT=0` suppresses them. See [the prompt block](docs/reference.md#the--odd-worktrees-block-in-the-system-prompt).
110
110
  - **CodeGraph stays fresh, only when its CLI is installed.** At session start the package creates or syncs the checkout's index and warms its daemon, and makes sure your global `mcp.json` has the `codegraph` entry. It also syncs after a compaction, after a native `codegraph init` and after an `edit` or `write`, in the background and without ever blocking you. See [CodeGraph](docs/reference.md#codegraph-index-daemon-and-mcp-entry).
111
- - **Two reminders keep a session on the CodeGraph rule.** The first `grep`, `find`, `ls`, `read` or `bash` search in a checkout gets one sentence appended to its result: use `codegraph` first, or — for another checkout — call `mcp__codegraph__codegraph_explore` with that path as `projectPath`. Neither is ever a block. See [the reminders](docs/reference.md#the-two-codegraph-reminders).
111
+ - **Two reminders keep a session on the CodeGraph rule.** The first `grep`, `find`, `ls`, `read` or `bash` search in a checkout gets one sentence appended to its result: use `codegraph` first, or — for another checkout — call `mcp__codegraph__codegraph_explore` with that path as `projectPath`. Neither is ever a block, and a subagent child hears neither. See [the reminders](docs/reference.md#the-two-codegraph-reminders).
112
112
  - **Deliberately absent.** No customize panel of its own, no plugin-tools toggles, no companion-app integration and no worktree-to-issue association. There is nothing to configure here: the card designs are chosen on the bridge's own lines, so this package owns no preference of its own. See [deliberately absent](docs/reference.md#deliberately-absent).
113
113
 
114
114
  ## Documentation
@@ -3301,12 +3301,20 @@ function guardSkillReadBashCall(event) {
3301
3301
  // the identity and the default branch memoized per checkout, the current branch read
3302
3302
  // on demand, so the hot path costs one `Map` hit per call plus one git read for a
3303
3303
  // switch.
3304
+ // Worktree creation and the principal checkout's branch are the ORCHESTRATOR's actions: a subagent child is
3305
+ // handed the worktree it works in and never creates one or leaves the default branch, so neither worktree
3306
+ // guard judges a child (`GENTLE_PI_AGENTS_CHILD`, the signal the prompt blocks use).
3307
+ function oddChildSession() {
3308
+ return process.env.GENTLE_PI_AGENTS_CHILD === "1";
3309
+ }
3310
+
3304
3311
  function guardWorktreeBashCall(event, ctx) {
3305
3312
  try {
3306
3313
  // `ODD_WORKTREE_GUARD=0` turns the guards off for this process, the way
3307
3314
  // `ODD_WORKTREE_PROMPT=0` turns off the prompt blocks. Read per call: a guard is
3308
3315
  // cheap, and an escape hatch that needs a restart is not one.
3309
3316
  if (process.env.ODD_WORKTREE_GUARD === "0") return undefined;
3317
+ if (oddChildSession()) return undefined;
3310
3318
  if (!event || event.toolName !== "bash") return undefined;
3311
3319
  const guard = libRequire("worktree-guard.js");
3312
3320
  if (!guard || typeof guard.decideBashGuard !== "function") return undefined;
@@ -3348,6 +3356,7 @@ const WRITE_GUARD_TOOLS = new Set(["edit", "write"]);
3348
3356
  function guardWorktreeWriteCall(event, ctx) {
3349
3357
  try {
3350
3358
  if (process.env.ODD_WORKTREE_GUARD === "0") return undefined;
3359
+ if (oddChildSession()) return undefined;
3351
3360
  const toolName = oddToolNameOf(event);
3352
3361
  if (!WRITE_GUARD_TOOLS.has(toolName)) return undefined;
3353
3362
  const paths = oddTouchedPaths(oddArgsOf(event));
@@ -4,9 +4,9 @@
4
4
  // Guard 1 says a call went to ANOTHER checkout and points the session at
5
5
  // `mcp__codegraph__codegraph_explore` with that checkout as `projectPath`; it belongs to the primary
6
6
  // session and fires once per checkout per session. Guard 2 says to reach CodeGraph first inside the
7
- // session's OWN checkout; it belongs to the primary session and to every child except the `review-*`
8
- // agents, and it reminds once on the first search of a checkout, while the graph is unused in that
9
- // request, and then never again for that checkout in that request (S3, S7).
7
+ // session's OWN checkout; it belongs to the primary session too (a child is short-lived and its own rule
8
+ // text already says it), and it reminds once on the first search of a checkout, while the graph is unused
9
+ // in that request, and then never again for that checkout in that request (S3, S7).
10
10
  //
11
11
  // Both are precise: a checkout the session already explored with the MCP tool silences guard 1, and a
12
12
  // reminder that does not fire uses up no slot. A call that failed is no subject at all: the model got no
@@ -186,6 +186,9 @@ function createCodegraphGuard(deps = {}) {
186
186
  if (event.isError === true) return undefined;
187
187
  const cwd = sessionCwd(event, ctx);
188
188
  if (recordCodegraphUse(state, event, cwd)) return undefined;
189
+ // Both reminders are the primary session's: a child lives a message or two and its own section already
190
+ // states the rule, so a reminder there would only repeat it.
191
+ if (child()) return undefined;
189
192
  // The same gate as the prompt section: the session must hold a CodeGraph tool to be advised.
190
193
  const held = tools();
191
194
  if (!holdsCodegraph(held)) return undefined;
@@ -1,8 +1,7 @@
1
1
  ## CodeGraph
2
2
 
3
- Run one call to the CodeGraph tool you hold before you search or read code — `fd`, `find`, `rg`, `grep`,
4
- `read` or `cat` — when the task needs structure rather than a lookup: where something lives, who calls it,
5
- what a change reaches. Skip it only for an exact string or a file path you were given. The other tools stay
6
- available after the first call.
3
+ Before you search or read code — `fd`, `find`, `rg`, `grep`, `read` or `cat` — your first call is one call to
4
+ the CodeGraph tool you hold: where something lives, who calls it, what a change reaches. The one exemption is
5
+ an exact string or a file path you were given.
7
6
 
8
- The answer is a map, not proof: confirm it in the source, and read a file before editing it.
7
+ Then read the files it points at, and read a file before editing it.
@@ -1,12 +1,11 @@
1
1
  ## CodeGraph
2
2
 
3
3
  Before you `grep`, `rg`, `fd`, `find`, `read` or `cat` to answer where code lives, who calls it, how it
4
- works, or what a change reaches, call CodeGraph first: `codegraph` with `operation: "explore"` and
4
+ works, or what a change reaches, your first call is CodeGraph: `codegraph` with `operation: "explore"` and
5
5
  `query: "<symbols or the question>"` returns the source and the call paths in one call, and it is
6
6
  also what scope, size and any handoff depend on. Use `operation: "query"` only to find where one
7
- symbol is defined. Skip it only for an exact string or a file path the user gave you. The other tools stay for
8
- what the graph does not index. Its answer is a map: confirm it in the source, and a verdict comes
9
- from the source and from tests.
7
+ symbol is defined. The one exemption is an exact string or a file path the user gave you. Then read the
8
+ files it points at: a verdict comes from the source and from tests.
10
9
 
11
10
  `codegraph` answers only for the checkout the session runs in, and each worktree is its own workspace with
12
11
  its own index. An ODD works in its own worktree: when the session runs elsewhere, look at that worktree, at
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-odd-worktree",
3
- "version": "3.12.3",
3
+ "version": "3.12.4",
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",
@@ -87,16 +87,16 @@ test('neither sentence ends in ", if it applies" any more (S3)', async () => {
87
87
  }
88
88
  });
89
89
 
90
- test('an explore agent gets the native wording, every other child the MCP one', async () => {
90
+ test('a child gets no reminder: its own rule text already says it and it lives a message or two', async () => {
91
91
  const child = (agent, tools) => setup({
92
92
  env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: tools },
93
93
  argv: ['node', `/tmp/gentle-pi-subagent-${agent}-a1b2c3/bin.js`],
94
94
  tools: [],
95
95
  });
96
96
  const explorer = child('gentle-ai-explore', 'read,bash,codegraph');
97
- assert.equal(await explorer.guard.onToolResult(bash('cat src/a.ts'), explorer.ctx), NATIVE);
97
+ assert.equal(await explorer.guard.onToolResult(bash('cat src/a.ts'), explorer.ctx), undefined);
98
98
  const worker = child('gentle-ai-worker', 'read,bash,mcp__codegraph__codegraph_explore');
99
- assert.equal(await worker.guard.onToolResult(bash('cat src/a.ts'), worker.ctx), MCP);
99
+ assert.equal(await worker.guard.onToolResult(bash('cat src/a.ts'), worker.ctx), undefined);
100
100
  });
101
101
 
102
102
  // ---- who gets which guard (S1, S2) ----
@@ -36,7 +36,12 @@ describe('the seven texts on disk', () => {
36
36
  for (const binary of ['fd', 'find', 'rg', 'grep', 'read', 'cat']) {
37
37
  assert.ok(text.includes(`\`${binary}\``), `${variant} names ${binary}`);
38
38
  }
39
- assert.match(text, /other tools stay|may skip it/, `${variant} leaves the other tools available`);
39
+ // S1: the primary and the generic texts carry no permission sentence; the five role texts keep theirs.
40
+ if (variant === 'orchestrator' || variant === 'generic') {
41
+ assert.doesNotMatch(text, /other tools stay|rather than a lookup|answer is a map|not proof/i, `${variant} has no escape hatch`);
42
+ } else {
43
+ assert.match(text, /other tools stay|may skip it/, `${variant} leaves the other tools available`);
44
+ }
40
45
  }
41
46
  });
42
47
 
@@ -81,9 +86,10 @@ describe('the orchestrator and explore texts stay inside their role', () => {
81
86
 
82
87
  test('the orchestrator calls the graph first for a where/who/how/what-reaches question, with one exemption and one literal call', () => {
83
88
  const text = prose('orchestrator');
84
- assert.match(text, /to answer where code lives, who calls it, how it works, or what a change reaches, call CodeGraph first/, text);
89
+ assert.match(text, /to answer where code lives, who calls it, how it works, or what a change reaches, your first call is CodeGraph/, text);
85
90
  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');
91
+ assert.match(text, /The one exemption is an exact string or a file path the user gave you/, 'one exemption');
92
+ assert.equal((text.match(/exemption|skip/gi) || []).length, 1, 'and only one');
87
93
  assert.match(text, /what scope, size and any handoff depend on/, 'the sizing use is kept');
88
94
  });
89
95
 
@@ -338,6 +338,16 @@ test('a code read in the session checkout gets one reminder part appended, and t
338
338
  assert.deepEqual(patch.structuredContent, { output: 'source' }, 'the structured content of the result is kept');
339
339
  });
340
340
 
341
+ test('a child is not reminded', async () => {
342
+ const { run } = setup({
343
+ toplevel: checkoutMap(),
344
+ env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,grep,mcp__codegraph__codegraph_explore' },
345
+ argv: ['node', '/tmp/gentle-pi-subagent-gentle-ai-worker-ab12cd/instructions.md'],
346
+ });
347
+ await run('before_agent_start', { systemPromptOptions: { selectedTools: [] } });
348
+ assert.equal(await run('tool_result', readEvent('src/a.ts')), undefined);
349
+ });
350
+
341
351
  test('ODD_WORKTREE_PROMPT=0 silences the reminders too, because they cite the rule that variable suppresses', async () => {
342
352
  const { run } = setup({ toplevel: checkoutMap(), env: { ODD_WORKTREE_PROMPT: '0' } });
343
353
  await run('before_agent_start', SESSION_TOOLS);
@@ -400,14 +410,14 @@ test('a new request re-arms the one reminder of the checkout (S3, S7)', async ()
400
410
  assert.equal(next.content[1].text, NATIVE_REMINDER, 'the first search of the next request hears it again');
401
411
  });
402
412
 
403
- test('a worker child is told to call the MCP tool, and a review agent is told nothing', async () => {
413
+ test('a worker child and a review agent are told nothing', async () => {
404
414
  const worker = setup({
405
415
  env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,bash,mcp__codegraph__codegraph_explore' },
406
416
  argv: ['node', '/tmp/gentle-pi-subagent-gentle-ai-worker-a1b2c3/bin.js'],
407
417
  toplevel: checkoutMap(),
408
418
  });
409
419
  const workerPatch = await worker.run('tool_result', readEvent('src/a.ts'));
410
- assert.equal(workerPatch.content[1].text, MCP_REMINDER);
420
+ assert.equal(workerPatch, undefined);
411
421
 
412
422
  const reviewer = setup({
413
423
  env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,bash,mcp__codegraph__codegraph_explore' },
@@ -697,6 +697,26 @@ describe('the tool_call handler the extension registers', () => {
697
697
  }
698
698
  });
699
699
 
700
+ test('a subagent child is judged by neither worktree guard: they are the orchestrator\'s actions', async () => {
701
+ const before = process.env.GENTLE_PI_AGENTS_CHILD;
702
+ try {
703
+ process.env.GENTLE_PI_AGENTS_CHILD = '1';
704
+ assert.equal(await callTool(loaded.hooks, bash('git worktree add ../odd-b'), principal), undefined, 'worktree add');
705
+ assert.equal(await callTool(loaded.hooks, bash('git checkout -b feat/odd-b'), principal), undefined, 'branch switch');
706
+ const file = path.join(principal, 'src', 'a.js');
707
+ assert.equal(await callTool(loaded.hooks, { toolName: 'write', input: { path: file, content: 'x' } }, principal), undefined, 'write');
708
+ assert.equal(await callTool(loaded.hooks, { toolName: 'edit', input: { path: file, oldText: 'a', newText: 'b' } }, principal), undefined, 'edit');
709
+ } finally {
710
+ if (before === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
711
+ else process.env.GENTLE_PI_AGENTS_CHILD = before;
712
+ }
713
+ assert.deepEqual(
714
+ await callTool(loaded.hooks, bash('git worktree add ../odd-b'), principal),
715
+ { block: true, reason: WORKTREE_ADD_REFUSAL },
716
+ 'the primary session is still judged',
717
+ );
718
+ });
719
+
700
720
  test('refuses the switches that leave the principal checkout\'s default branch', async () => {
701
721
  const expected = [
702
722
  ['git checkout -b feat/odd-b', BRANCH_SWITCH_REFUSAL],