Skip to content

fix(cli): keep pre-commit hooks on external installations - #789

Open
xinoai wants to merge 1 commit into
mainfrom
fix/external-hook-installation
Open

fix(cli): keep pre-commit hooks on external installations#789
xinoai wants to merge 1 commit into
mainfrom
fix/external-hook-installation

Conversation

@xinoai

@xinoai xinoai commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Generated pre-commit hooks need an installation that stays stable as the repository changes. Require the CLI installation and runtime to live outside the target worktree, and let users refresh previously generated hooks from that installation.

Changes

  • Resolve the Git worktree root and reject hook installation when the runtime, CLI entrypoint, or package root is inside it.
  • Mark generated hooks and recognize the complete previous generated format for migration, including quoted paths.
  • Preserve custom hooks and the existing severity threshold behavior.
  • Update command help and setup guidance, with regression coverage for local npm installations, local runtimes, and hook refresh across a branch checkout.

Testing

  • bun test --timeout 30000 tests-ts/cli.test.ts tests-ts/cli-launcher.test.ts: 159 passed.
  • pnpm run types: passed.
  • pnpm run format: passed.
  • pnpm run test --seed 12345 and pnpm run test: both passed on Linux (2,243 passed, 41 skipped in each run).
  • Full CI matrix, including native Windows tests: passed.

Risk and rollout

install-hook now returns exit code 2 for repository-local installations. Install the CLI and runtime outside the repository, then rerun install-hook with the existing severity threshold to refresh an old generated hook. Package updates alone do not rewrite hooks. No commands, flags, or defaults are added.

Public disclosure review

  • No customer, partner, prospect, or user identities, data, or identifying details are included.
  • No credentials, personal data, private source, scan findings, or nonpublic links or tickets are included.
  • I reviewed the branch name, title, description, commits, changes, comments, logs, screenshots, attachments, and links for public disclosure.

@github-actions github-actions Bot added the bug Something isn't working label Sep 2, 2026
@xinoai
xinoai marked this pull request as ready for review September 2, 2026 13:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T13:44:32.625782Z 570b1da Draft marked ready
🔒 Security Review Completed 2026-09-02T13:46:29.882595Z 570b1da Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 570b1daafc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/cli.ts
Comment on lines +3124 to +3125
[runtime, cli, installation].some(
(path) => !isOutsidePath(relative(worktree, path)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject installations inside sibling worktrees

When the target is a linked Git worktree, this checks only that worktree’s top-level path. An installation in another linked worktree therefore passes, while git rev-parse --git-path hooks/pre-commit resolves to the shared hook directory in the main worktree. The resulting shared hook is pinned to repository-controlled code that a checkout or deletion of the sibling worktree can replace or break, affecting commits in every linked worktree and recreating the vulnerability this change is intended to prevent. Check the installation and runtime against every path reported by git worktree list --porcelain, not only the target worktree.

AGENTS.md reference: sdk/typescript/AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The marker-less migration check is broad enough to overwrite a custom hook. Since the managed comment is optional and both captured paths only need to be absolute, a hook like exec '/abs/node' '/abs/custom-script' scan . --working-tree --fail-on-severity high is treated as generated and replaced. That changes the previous “leave custom hooks alone” behavior. Can we require stronger provenance for the marker-less case, e.g. identify the old Codex Security CLI/package path before overwriting?

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants