Skip to content

fix(aidd-refine): the turn-end hook answers a committed shadow report in a new git worktree #1444

Backlog

Description

@Prunil62

Description

At the end of a turn that ran a shell command, the turn-end artifact check answers a committed shadow report that git worktree add checks out below the project, although the worktree holds committed content only (git status --porcelain is empty there) and the session wrote nothing in it. A turn that ran no shell command is not affected.

Steps to reproduce, in a checkout of this repository on next (git switch next) or on the tag (git checkout cli-v5.8.0). They need git and node 22.18+, 24.11+ or 26+, and no dependency install.

  1. Paste the block below in a terminal, at the root of the checkout. It adds one test and one helper to scripts/__tests__/artifact-hook.test.js, then runs that file alone, with the wrapper that aidd_docs/memory/testing.md prescribes for the scripts/__tests__ suite.
  2. Undo it with git checkout scripts/__tests__/artifact-hook.test.js.
Block to paste
git apply <<'END_OF_PATCH'
diff --git a/scripts/__tests__/artifact-hook.test.js b/scripts/__tests__/artifact-hook.test.js
index 07dd15f36..aa61995c8 100644
--- a/scripts/__tests__/artifact-hook.test.js
+++ b/scripts/__tests__/artifact-hook.test.js
@@ -319,6 +319,29 @@ test("a compaction's second start keeps the reference: a shell write before it i
   assert.ok(lines(s.stop()).every((line) => line.startsWith(`${STORY}:`)));
 });
 
+/** git as a test sets a repository up: identity by -c, and ENV carries no GIT_* variable. */
+function git(cwd, ...args) {
+  const config = ["user.name=t", "user.email=t@t", "commit.gpgsign=false", "core.hooksPath=/dev/null"];
+  const result = spawnSync("git", [...config.flatMap((c) => ["-c", c]), ...args], { cwd, env: ENV, encoding: "utf8" });
+  assert.equal(result.status, 0, `git ${args.join(" ")}: ${result.stderr}`);
+  return result.stdout;
+}
+
+test("a shell turn is silent on a committed file that a new git worktree checks out below the project", () => {
+  const report = "aidd_docs/tasks/x/x-shadow-report.md";
+  const s = session("aidd-refine", "claude", { [report]: "# nope\n" });
+  git(s.root, "init", "--quiet");
+  git(s.root, "add", report);
+  git(s.root, "commit", "--quiet", "-m", "an old broken report");
+  past(path.join(s.root, report), 3600);
+  s.start();
+  // another session or the user adds a worktree: git copies the committed report into it
+  git(s.root, "worktree", "add", "--quiet", ".worktrees/w");
+  assert.equal(git(path.join(s.root, ".worktrees/w"), "status", "--porcelain"), "", "the worktree holds committed content only");
+  s.shell();
+  assert.equal(s.stop(), "", "the turn end answers a file this session did not write");
+});
+
 test("a bad entry in scope does not silence the turn: a dangling link, an unreadable folder", (t) => {
   const s = session("aidd-dev", "claude", { [PLAN]: "# Plan\n", [PHASE]: "# nope\n" });
   try {
END_OF_PATCH
node scripts/check-tests-leave-git-alone.js -- node --test --test-reporter=spec scripts/__tests__/artifact-hook.test.js

Affected file(s)

scripts/check/engine/hook.cjs:187 on next (b94a5d0), line 210 on cli-v5.8.0, in modifiedSince; scripts/check/engine/sync.cjs generates plugins/*/hooks/artifacts.cjs from this file, in four plugins. It keeps every in-scope file whose modification time is after the session's reference time, whoever wrote it. plugins/aidd-refine/skills/03-shadow-areas/scripts/contract.json:5 on cli-v5.8.0 (line 4 on next) sets the scope **/*-shadow-report.md: of the 13 hook contracts under plugins/*/hooks/lib/contracts/ on cli-v5.8.0 (14 on next), the only one that does not start from a fixed folder, so the only one that reaches a worktree under .worktrees/ or .claude/worktrees/. No fix is proposed. Counter-test: when the added test sets the modification time of the worktree copy back one hour before s.shell(), it passes on both references.

Expected behaviour

A shell turn stays silent on a committed shadow report that a new git worktree, added by another session or by the user, checks out unchanged below the project. The added test states it. Whether the hook should also stay silent when a shell command of the session itself adds the worktree is left to the maintainers.

Finding shell writes by modification time is the intended design (section shell writes: found by mtime of the test file), and this report does not ask to change it. A fix keeps the existing test a shell turn answers the in-scope files modified after the session start, never older ones passing: that test moves a file's modification time after the session start, as a shell write of the session does, and the file is still answered.

A fix also keeps the existing test a broken file in scope that no PostToolUse named is not reported passing: a turn without a shell command stays silent on a broken file that no write tool call named.

Observed behaviour

The test command exits 1: the added test fails, and every existing test passes, 49 on cli-v5.8.0 (df94d99) and 52 on next (b94a5d0).

✖ a shell turn is silent on a committed file that a new git worktree checks out below the project
  AssertionError [ERR_ASSERTION]: the turn end answers a file this session did not write
ℹ tests 50
ℹ pass 49
ℹ fail 1

These lines come from the run on cli-v5.8.0; the duration, the stack and the other counters are left out. Under the failure, the actual value is the hook's answer: a "decision":"block" that lists SHADOW findings on a file the session did not write, .worktrees/w/aidd_docs/tasks/x/x-shadow-report.md. The identical original at the project root is not answered.

AI tool

Claude Code

aidd-cli version

5.8.0, with the plugins aidd-refine 3.3.0 and aidd-dev 2.9.0.

OS

Linux

Additional context

  • Tested on Fedora Linux 44, git 2.56.1, node v22.23.1.
  • Seen in real use on 2026-11-28, in Claude Code sessions sharing one project: 16 turn ends in 9 sessions were blocked by the aidd-refine hook on the SHADOW findings of one report, in five worktrees under .worktrees/. In 11 of the 16, another session had added the worktree.
  • That report was committed on 2026-11-02, before its contract existed: plugins/aidd-refine/skills/03-shadow-areas/scripts/contract.json was added on 2026-11-26 (4d34d93).
  • Claude Code creates its worktrees under .claude/worktrees/<name>/ at the repository root by default, with tracked files only (https://code.claude.com/docs/en/worktrees); this repository ignores that folder (.gitignore:33). With .claude/worktrees/w in place of .worktrees/w, the added test fails the same way on both references.
  • The engine already has "shell": false (scripts/check/engine/hook.cjs:5-7), which three aidd-context contracts set: after a shell turn, such a contract checks only the files that a command of the turn names. With it in plugins/aidd-refine/hooks/lib/contracts/03-shadow-areas/scripts/contract.json, the added test passes on next; a shadow report that a shell command writes without naming it would then go unchecked.

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions