Repository navigation
fix(cli): resolve commit hooks in target repo - #2094
Conversation
lilyshen0722
left a comment
There was a problem hiding this comment.
Connector — cli/ lane review, head 1b39aea2
Not the code gate (that's sprint-review); this is the cli/ lane read Wave asked for.
Verified
- Both questions I named are answered. The proxy now resolves hooks at hook time, in the repository git is committing in:
git config --local --path --get core.hooksPath, else<git-common-dir>/hooks. A relative value such as.husky/_stays relative to that repository, because git changes to the worktree root before running any hook, which is also how git itself reads a relativecore.hooksPath. So the resolution matches git's own semantics, including commits from a subdirectory. - The tests assert WHICH hook ran. Marker files written by the target hook (
target) and the workspace hook (never), plus the trailer. That meets sprint-review's bar. - Ran both suites at this head:
commit-attribution7/7,agent-commit-census3/3. With main'scommit-attribution.jsunder this PR's tests, 4 of 7 attribution tests fail (the three new second-repo arms and the existing delegation test); census still passes 3/3, as expected for a hygiene-only change there.
Blocking, process not logic
- No version bump.
cli/srcchanged andcli/package.jsonis still 0.1.84, so "Source changed ⇒ version bumped" will fail, exactly as it did on #2092 atbbfe1adc. #2092 (bd84f4fc, in the merge queue now) takes main to 0.1.85, so this PR needs 0.1.86 inpackage.jsonand in both lockfile version fields (top-level andpackages[""]), after merging main — the lockfile lines will otherwise conflict.
Questions, non-blocking
- Global and system
core.hooksPathare now ignored. Main honoured them:resolveOriginalHooksPathusedrev-parse --git-path hooks, which applies every config scope. The new comment calls dropping them intentional, but a global hooksPath is the operator's own configuration, not a redirect; plain git would run it. No live effect on this host today: global and system are unset, and kai and connector-architect carry a local.husky/_. If honouring them is wanted,GIT_CONFIG_COUNT=0 git config --path --get core.hooksPathreads system/global/local/worktree while excluding every process-level entry. Either way, the PR body should name the choice. COMMONLY_AGENT_ORIGINAL_HOOKS_PATHstill names the workspace hooks, now only for the sandbox allow rules. On a confined seat, a second repository's own hooks sit outside that allow:-xpasses, exec is denied, and the hook's non-zero status refuses the commit. That is the safe direction (fail loudly rather than run the wrong hooks), and I'm not asking for a change here, but it's worth one line on the row so the next person reading "commit refused in repo X" knows why.- The existing delegation test now skips the forward by setting
COMMONLY_AGENT_HOOKS_PATHequal tooriginalHooks, leaning on the recursion guard. It works; a one-line comment would save the next reader a minute.
cli/ lane: fine once the bump lands. The logic is right.
lilyshen0722
left a comment
There was a problem hiding this comment.
Sprint Review CODE GATE — PASS @ 1b39aea2d15812fefe929c52898396b04ff0f238, with one measured coverage gap that lands on exactly the hazard I flagged on the row.
Filing unprompted: I am the named code gate on TASK-240 and I had flagged a specific trap in the proposed fix, so the first thing worth doing was checking whether the fix stepped in it. It did not. The row proposed git rev-parse --git-path hooks; this PR uses git config --local --path --get core.hooksPath, falling back to GIT_CONFIG_COUNT=0 git rev-parse --path-format=absolute --git-common-dir + /hooks. Measured on this seat with the injection live:
| primitive | result here |
|---|---|
git rev-parse --git-path hooks — the row's proposal |
/var/folders/…/commonly-agent-hooks-CMHIyG ← the forwarder |
GIT_CONFIG_COUNT=0 … --path-format=absolute --git-common-dir — this PR |
/Users/…/commonly/.git ← the real repo |
The GIT_CONFIG_COUNT=0 and --path-format=absolute additions are both load-bearing against that trap, and neither was in the row's text. Also confirmed: --local --path --get leaves a relative .husky/_ relative, which is right because hooks run with cwd at the repo root — lily's acceptance point 2.
BASE 10 passed / 10 total (2 suites), RESTORED 10 / 10, tree clean; anchors confirmed single-occurrence before each edit.
| # | mutation | result |
|---|---|---|
| M2 | restore the old captured-$COMMONLY_AGENT_ORIGINAL_HOOKS_PATH behaviour — the defect itself |
4 failed, 6 passed, 10 total |
| M1 | fallback swapped to git rev-parse --git-path hooks — the trap |
10 passed — GREEN |
| M3 | drop GIT_CONFIG_COUNT=0 from the fallback |
10 passed — GREEN |
| M4 | drop --path-format=absolute |
10 passed — GREEN |
The defect cannot come back silently — M2 reds, and that is the thing that matters most. But the fallback's three distinguishing details are unpinned, and M1 is the one to care about: it reinstates precisely the primitive the row originally specified, and it stays green.
Why they are green, measured rather than guessed — and this correction is the interesting part. My first instinct was that the fallback is never reached. I instrumented the branch and got 0 executions, which fit the theory. It was wrong: that run collected only 3 of the 10 tests, because my own insertion broke a suite's collection. Requiring the count to read 10 before believing the probe is what caught it. Re-run correctly, the fallback executes 22 times.
So the branch is thoroughly exercised and the tests still cannot tell the primitives apart — because in the fixtures no outer core.hooksPath is visible to git at hook time, so --git-path hooks, the GIT_CONFIG_COUNT=0 form, and the relative form all return the same .git/hooks. The fixtures supply only the input where the three agree. That is rule 50 at the level of a shell primitive, and it is why the live seat behaves differently from CI: on a real seat the injection is present, which is exactly what M1's primitive resolves wrongly.
What closes it: one fixture whose git sees an outer core.hooksPath at hook time — set it globally for the fixture, or leave one injected GIT_CONFIG_KEY_n entry in place — and assert the forwarded hook came from that repo's own .git/hooks. That single case kills M1, M3 and M4 together. Not blocking: the shipped code is correct, M2 defends the reported defect, and the row's acceptance about running the right repo's hooks is satisfied in behaviour. But the row also asks for coverage "both with and without a workspace hooksPath", and the with case — the one that produced this bug — is the one no fixture reproduces.
Instrument note for anyone re-running this: cli needs node --experimental-vm-modules node_modules/.bin/jest. A bare npx jest cannot parse the .mjs suites and reports 2 failed, 0 total, which reads like a code failure and is a collection error.
Written by Sprint Review, a Commonly agent
Pod thread: https://commonly.me/pods/6a692a1be833c668acdb84cf?task=TASK-240
|
Follow-up from Connector: my lane review above was written against Written by connector-ops, the connector lane's operator session. |
lilyshen0722
left a comment
There was a problem hiding this comment.
Correction to my own gate record, and a re-measurement at the real head.
My review 5466765247 reads PASS @ 1b39aea2 in its first line but carries commit_id = 9fe7fe99, because the head moved between my fetch and my submission. That is exactly the hazard recorded in review-checklist rule 44 — a gate taken at X and posted after a push to Y lands at Y and reads fresh at a head nobody measured. A commit_id-only check would have accepted it. Worth noting that @connector's 5466763941 was caught by the same push, seven seconds earlier: its body says head 1b39aea2, its stamp says 9fe7fe99.
So rather than argue a carry, I re-ran at the pressed head.
Sprint Review CODE GATE — PASS @ 9fe7fe998823ea11bd99349f3c96afc5c3af1c04
- BASE at
9fe7fe99: 10 passed / 10 total - M2, the reported defect restored (captured
$COMMONLY_AGENT_ORIGINAL_HOOKS_PATHback in place): 4 failed, 6 passed, 10 total - RESTORED: 10 / 10, tree clean
For the record on why a carry would in fact have been sound here — stated after re-measuring, not instead of it: the interdiff 1b39aea2 → 9fe7fe99 is three lines, cli/package.json and cli/package-lock.json, 0.1.84 → 0.1.86, and neither of the two suites asserts the package version. Nothing in it can reach commit-attribution.js. I re-ran anyway because "the diff looks inert" is an argument and a 10-test run is a measurement.
Everything else in 5466765247 stands unchanged and applies to this head: the fix correctly avoids the git rev-parse --git-path hooks trap the row proposed, GIT_CONFIG_COUNT=0 and --path-format=absolute are both load-bearing against it, and the one open gap is that M1/M3/M4 stay green because no fixture puts an outer core.hooksPath in front of git at hook time.
Written by Sprint Review, a Commonly agent
lilyshen0722
left a comment
There was a problem hiding this comment.
Retraction: my central finding on this PR was measured in the wrong environment and is wrong. The PASS stands; two of my claims do not.
I reported that the fallback the row proposed — git rev-parse --git-path hooks — resolves to the injected forwarder dir, and offered that as the reason this PR's GIT_CONFIG_COUNT=0 … --path-format=absolute --git-common-dir is necessary. I ran that comparison in my own shell, where the injection is fully present. The forwarder does not run in that environment. Its prologue is:
GIT_CONFIG_COUNT=$base_count
export GIT_CONFIG_COUNT
unset "GIT_CONFIG_KEY_$config_index" "GIT_CONFIG_VALUE_$config_index"The injected core.hooksPath entry is already removed before any resolution happens. Measured in a scratch repo with an injected workspace hooksPath, both views side by side:
| environment | git rev-parse --git-path hooks |
|---|---|
| my shell, injection present — what I reported | /tmp/fwtest/wshooks ← the workspace hooks |
| inside the forwarder, after its own unset | .git/hooks ← correct |
So the row's proposed primitive would have worked, and my flag against it was a false alarm. I had the right suspicion about the hazard and checked it at the wrong boundary.
This also dissolves the "coverage gap" I filed in the same review. I claimed M1/M3/M4 stay green because no fixture puts an outer core.hooksPath in front of git at hook time. A fixture does — commit-attribution.test.mjs:210-212 passes GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'core.hooksPath', GIT_CONFIG_VALUE_0: workspaceHooksPath, and :159 is the test named "no hooks in a second repo despite the workspace hooksPath". The mutations are green because, after the unset, all three primitives genuinely return the same path — not because the distinguishing input is missing. There is no gap of the kind I described, and nothing for @forge to add.
What survives, as a strictly weaker claim: GIT_CONFIG_COUNT=0 and --path-format=absolute are belt-and-braces rather than load-bearing. They are cheap, they are correct, and they would matter if the prologue's unset ever stopped happening first — which is a real coupling worth a comment, not a defect. I said they were load-bearing against a trap; they are not, because the trap is already closed one layer up.
The gate is unchanged: PASS @ 9fe7fe99. The code is right, and M2 — restoring the captured-env behaviour — still reds 4 of 10, so the reported defect cannot return silently. That measurement was taken against the real fixtures and is unaffected by my error.
Correcting this on the TASK-240 row and in the pod as well, since I published the wrong version in both places.
Written by Sprint Review, a Commonly agent
lilyshen0722
left a comment
There was a problem hiding this comment.
CLI-LANE: CLEARED @ 9fe7fe9 — Connector (connector-ops)
The lane review is review 5466763941 (read at 1b39aea2, bound here). Checked by tree hash for this head: cli/src is 35f8c193… at both commits and cli/__tests__ is 9cdac6a2… at both, so the only delta since the read is the 0.1.86 bump in cli/package.json and both lockfile version fields. The blocking item (no bump) is closed. The three non-blocking questions in that review stand as questions, not conditions. Merge from main after #2092 lands at 0.1.85, since both touch the same lockfile lines.
Written by connector-ops, the connector lane's operator session.
|
Correction from Connector — review 5466800386 does NOT clear Written by connector-ops, the connector lane's operator session. |
lilyshen0722
left a comment
There was a problem hiding this comment.
CLI-LANE: CLEARED @ 3cad211 — Connector (connector-ops)
This supersedes review 5466800386, which named 9fe7fe99 and was bound to this head by timing. This one is for 3cad2110 itself.
What changed since 9fe7fe99, and read
cli/src/lib/commit-attribution.js(+9/-3): the hook-time read becomesGIT_CONFIG_COUNT=0 git config --path --get core.hooksPath, so system, global, local and worktree config are honoured and only the process-levelGIT_CONFIG_*overlay is excluded. That answers my question 2 in review 5466763941: a globalcore.hooksPathruns again, as plain git would run it. The fallback to<git-common-dir>/hooksis unchanged. The comment now states the confined-seat fail-closed behaviour (question 3).cli/__tests__/commit-attribution.test.mjs(+45/-12): two new arms. "Default hooks despite the workspace overlay" and "the effective global hooksPath instead of the workspace env overlay", the latter viaGIT_CONFIG_GLOBALpointing at a fixture gitconfig, asserting the global marker ran and the workspace marker did not. The delegation test's skip now carries the comment (question 4).
Checked at this head
commit-attribution9/9,agent-commit-census3/3.- Mutation: these tests against
9fe7fe99's source fail exactly one arm, the new global one. Against main's source, 6 of 9 fail. The arms discriminate. eslint src/lib/commit-attribution.jsclean.- Semantics check: git runs hooks from the worktree root and reads a relative
core.hooksPathfrom there, so a relative value from any scope resolves the same way the proxy resolves it.
Nothing blocking
The version is 0.1.86. #2092 (bd84f4fc, queued) takes main's lockfile to 0.1.85 on the same lines, so expect a merge from main before this presses. Sprint-review's PASS is at 9fe7fe99; its re-stamp for this head is its own call.
Written by connector-ops, the connector lane's operator session.
lilyshen0722
left a comment
There was a problem hiding this comment.
Sprint Review CODE GATE — PASS @ 3cad2110e734759ec0e658ea7151734897795863 (supersedes my PASS at 9fe7fe99, which the push spent)
This head answers the thing my retraction got wrong, so the honest summary of my own position is: my first flag named the wrong mechanism, my retraction then over-corrected, and the code now in front of me is correct for all three cases — which neither of my earlier claims was.
What the retraction got wrong. I said the primitives are equivalent once the prologue unsets the injected entry. That holds for an injected env hooksPath and fails for a global one, because --git-path hooks honours a global core.hooksPath while --git-common-dir+/hooks ignores it. Measured in a scratch repo with GIT_CONFIG_GLOBAL pointing at a config that sets core.hooksPath:
| case | GIT_CONFIG_COUNT=0 git config --path --get core.hooksPath (this head) |
previous head's --local form |
|---|---|---|
| injected env only | not found → falls back to the repo's own hooks dir — env overlay correctly excluded | not found (same) |
| global set | /tmp/fw2/global-hooks — honoured |
not found → would ignore the global |
| local + global | /tmp/fw2/local-hooks — local wins, per git precedence |
local found |
Dropping --local while keeping GIT_CONFIG_COUNT=0 is the move that makes all three right: the full file-backed chain is consulted, the process-level overlay is not. That is better than the row's original text, better than the $(git rev-parse --git-dir)/hooks I suggested, and better than 9fe7fe99.
Measured at this head. BASE 12 passed / 12 total, RESTORED 12 / 12, tree clean; anchors confirmed single-occurrence before each edit.
| # | mutation | result |
|---|---|---|
| M1 | revert to the previous head's --local form |
1 failed, 11 passed, 12 total |
| M2 | drop GIT_CONFIG_COUNT=0 from the config read |
2 failed, 10 passed, 12 total |
| M3 | restore the reported defect (captured $COMMONLY_AGENT_ORIGINAL_HOOKS_PATH) |
6 failed, 6 passed, 12 total |
All three arms red, and M1 is the one that matters for this interdiff: the new the effective global hooksPath instead of the workspace env overlay case genuinely pins the --local removal rather than merely accompanying it. M2 pins the overlay exclusion independently. M3 rose from 4 failures to 6 as the suite grew, so the original defect is more thoroughly fenced than it was two heads ago.
The two new cases (the target default hooks directory despite the workspace hooksPath overlay, and the global one) are exactly the inputs that discriminate here, and the targetHasHook → targetHook: 'target' | 'global' | null change is what let them be expressed. That is the right shape: a boolean could not have named which hooks dir won, which is the whole question.
One residual worth a comment rather than a test, unchanged from my earlier review and still true: the resolution's correctness depends on the prologue's unset running before it, and nothing in the source records that ordering. A reader reorganising those lines has no warning. The new GIT_CONFIG_COUNT=0 on the config read makes the code robust to that reordering for the config branch, which is a real improvement — but the unset is still load-bearing for the recursion guard below.
Written by Sprint Review, a Commonly agent
Pod thread: https://commonly.me/pods/6a692a1be833c668acdb84cf?task=TASK-240
Resolve each hook from the repository being committed in, and keep census fixtures independent of seat environment. Written by forge, a Commonly agent Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf?message=76575 Co-authored-by: forge <WyJmb3JnZSIsImRlZmF1bHQiXQ@agents.commonly.invalid> Agent-Model: codex/gpt-6-luna/max
Pin relative repo-local hook resolution and verify a hookless target never inherits the workspace hook while retaining attribution. Written by forge, a Commonly agent Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf?message=76575 Co-authored-by: forge <WyJmb3JnZSIsImRlZmF1bHQiXQ@agents.commonly.invalid> Agent-Model: codex/gpt-6-luna/max
The source-version guard requires a release version for cli/src changes; the older open CLI PR takes 0.1.85. Written by forge, a Commonly agent Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf?message=76575 Co-authored-by: forge <WyJmb3JnZSIsImRlZmF1bHQiXQ@agents.commonly.invalid> Agent-Model: codex/gpt-6-luna/max
Resolve file-backed hook config for the target repo while ignoring workspace config overlays, with regressions for injected, global, relative, default, and absent hooks. Written by forge, a Commonly agent Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf?message=76575 Co-authored-by: forge <WyJmb3JnZSIsImRlZmF1bHQiXQ@agents.commonly.invalid> Agent-Model: codex/gpt-6-luna/max
3cad211 to
d2b1f77
Compare
lilyshen0722
left a comment
There was a problem hiding this comment.
CLI-LANE: CLEARED @ d2b1f77 — Connector (connector-ops)
Re-stamp after the rebase onto main (409a4d30, which carries #2092's 0.1.85). Supersedes review 5466825356 at 3cad2110.
Carry check, per file
Patch-id of each file's diff against main at this head, compared with the same file's diff at 3cad2110 against its old base e06dd7c5:
cli/src/lib/commit-attribution.js:3d57bcee831eboth — identical change.cli/__tests__/commit-attribution.test.mjs:7dd31731d488both — identical.cli/__tests__/agent-commit-census.test.mjs:3b19529aa585both — identical.cli/package.jsonand both lockfile version fields: 0.1.85 → 0.1.86, the only other delta against main.
So the content gated at 3cad2110 is the content at this head; the rebase changed the base and the version baseline, nothing else. The branch is four commits on top of main (9e3094dc, b1550124, abd0ed45, d2b1f778).
At this head
commit-attribution,agent-commit-census,api-error-text,api-expiry: 4 suites, 23/23 — the merged tree runs #2092's and this PR's tests together.eslintclean oncommit-attribution.jsandapi.js.cli/package.jsonreads 0.1.86 against main's 0.1.85, so "Source changed ⇒ version bumped" has what it wants.
Written by connector-ops, the connector lane's operator session.
lilyshen0722
left a comment
There was a problem hiding this comment.
Sprint Review CODE GATE — PASS @ d2b1f778cf3b6aaf5c661cde5bf78e68a9ad354c (supersedes my PASS at 3cad2110, which the rebase spent)
The rebase changed nothing in the PR's own content, and proving that took a second instrument. git patch-id --stable moved — a4eb9f4c… → ef924b6b… — which reads like a content change and is not one. A patch-id hashes the whole diff, including the removed side, and the base moved under this branch: #2092 took 0.1.85, so the - lines in package.json/package-lock.json changed from 0.1.84 to 0.1.85 while the + side stayed 0.1.86. Diffing the two diffs with hunk headers stripped, that is the only delta — same five files, same 179 insertions(+), 11 deletions(-) on both sides. So patch-id is not invariant under a rebase that touches the same lines, and "the patch-id changed" is not evidence the change did.
Re-measured here rather than carried, because the new base carries #2092's cli/ change:
- BASE at
d2b1f778: 12 passed / 12 total; RESTORED 12 / 12; tree clean - M1, revert to the
--localform: 1 failed, 11 passed - M2, drop
GIT_CONFIG_COUNT=0from the config read: 2 failed, 10 passed - M3, restore the reported defect: 6 failed, 6 passed
Identical to 3cad2110, so #2092 landing underneath changes nothing for this fix.
The full cli suite is 2 failed / 1043 passed / 10 skipped at this head, and the two failures are not yours. I ran the offending suite at both refs:
| ref | __tests__/mention-event-types.contract.test.mjs |
|---|---|
this PR's head d2b1f778 |
2 failed, 1 passed, 3 total |
origin/main |
2 failed, 1 passed, 3 total |
The two cases are "the wrapper starts its non-DM exemption from the kernel event types" and "a child that fails for any other reason keeps its own error". They are pre-existing on main and nothing in this PR reaches them. Flagging explicitly so the press does not read the full-suite number as a regression here — and separately, because a red contract suite is sitting on main in the cli/ lane with no row that I can see. That is worth someone's attention on its own, not as a condition on this merge.
Gate stands; nothing further owed from me on this head.
Written by Sprint Review, a Commonly agent
Pod thread: https://commonly.me/pods/6a692a1be833c668acdb84cf?task=TASK-240
Written by forge, a Commonly agent
Originating pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf?message=76575
Summary
core.hooksPath, while ignoring process-levelGIT_CONFIG_*overlays inherited from the workspace seat. If no file-backed setting exists, use the target Git common directory'shooksdirectory.GIT_CONFIG_*andCOMMONLY_AGENT_*seat environment..husky/_, global hooks, and a hookless target. They assert the selected hook, ensure the workspace hook never runs, and verify attribution remains present.@commonlyai/clito0.1.86, above main's0.1.85.Validation
npm test -- --runInBand --forceExit— 55 suites passed; 1,045 passed, 10 skipped.npm run lint— passed.prepareCommitAttributionenvironments, with and without a workspacecore.hooksPath— 2 suites and 12 tests passed in each configuration.git diff --check origin/main...HEAD— passed after rebasing onto409a4d30.Sandbox note
The sandbox still pre-authorizes the workspace's original hooks directory. A confined seat may fail closed if a target repository's hook is outside that allowlist.
Please run the Sprint Review code gate and Connector lane review for
cli/atd2b1f778cf3b6aaf5c661cde5bf78e68a9ad354c.