Skip to content

feat(doctor,init): one hook channel per checkout — doctor fails when repo hooks and a sequant plugin are both active; init/update skip the hooks group when the plugin is enabled #1603

Closed

Description

@admarble

Epic: graph-2026-10-ergonomics Tier: mechanical Execution: sequant_run Blocked by: #1602

Problem

Sequant delivers its guard hooks two ways: sequant init writes .claude/hooks/*.sh and registers them in .claude/settings.json, and the plugin ships the same scripts in hooks/hooks.json. Nothing arbitrates. On 2026-10-26 both channels were active in both inspected checkouts (sequant itself and matcha-maps): the timing logs show the same tool call logged twice at the same second, costing 70–120 ms (pre) plus ~40 ms (post) per call. doctor checks 4–5 only look for .claude/hooks and its mode bits; init.ts never reads enabledPlugins. §3 of the founding doc.

Decisions

ID Decision Rejected alternative
D-1.1 doctor gains a Hook channels check reading project settings.json hooks plus enabledPlugins in ~/.claude/settings.json and .claude/settings.local.json; each enabled plugin is resolved to its install path through ~/.claude/plugins/installed_plugins.json and counts as a channel only if its hooks/hooks.json registers pre-tool.sh; fail when a repo registration and such a plugin coexist; message names both sources and both fixes matching on the plugin name (a dev plugin without a hooks/ dir would false-positive); runtime dedupe in the hook scripts (no tool-use id in the payload; identical consecutive calls would skip a guard)
D-1.2 init and update skip the hooks group when such a plugin is enabled and record "hooks": "plugin" in .sequant-manifest.json; one printed line says so asking at init (OQ-1; owner may override)

Acceptance Criteria

  • AC-1: doctor reports fail for a checkout whose .claude/settings.json registers pre-tool.sh while an enabled plugin's resolved install path carries a hooks/hooks.json registering pre-tool.sh, and pass otherwise. Evidence: npx vitest run src/commands/doctor.test.ts -t "Hook channels" → ≥ 4 passed, 0 failed (fixtures: both active → fail naming both paths; repo only → pass; plugin only → pass; plugin enabled but its install path has no hooks/hooks.json → pass)
  • AC-2: init with a sequant plugin enabled writes no .claude/hooks/ and no hook entries in .claude/settings.json, and the manifest carries "hooks": "plugin". Evidence: npx vitest run src/commands/init.test.ts -t "plugin channel" → ≥ 2 passed, 0 failed
  • AC-3: update on a manifest with "hooks": "plugin" leaves hooks absent instead of adding them. Evidence: npx vitest run src/commands/update.test.ts -t "hooks: plugin" → ≥ 1 passed, 0 failed
  • AC-4: The plugin-distribution doc states the one-channel rule and names the doctor check. Evidence: grep -c 'Hook channels' docs/features/plugin-distribution.md → ≥ 1
  • AC-5: No skill-directory edits. Evidence: git diff --name-only $(git merge-base origin/main HEAD)..HEAD | grep -cE '^(plugin/|\.claude/skills/|templates/skills/)' → 0 (constraint)

May touch

src/commands/doctor.ts, src/commands/init.ts, src/commands/update.ts, the manifest reader/writer, their tests, docs/features/plugin-distribution.md, CHANGELOG.

Non-Goals

  • Changing the hook scripts or hooks/hooks.json.
  • Deduplicating at runtime.

Done when

A user with the plugin installed who runs sequant init gets one set of hooks, and a user who already has both learns it from sequant doctor with the fix spelled out.

Activity

  1. added
    graph-2026-10-ergonomics
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 27, 2026
  3. admarble commented on Oct 27, 2026

    @admarble
    ContributorAuthor

    Runner context (2026-10-26, before the W0 launch). For the spec, exec and qa phases.

    • The founding doc is on main: docs/internal/graph-2026-10-ergonomics/PROJECT-DISCUSSION.md (the §N citations in this issue point there) and phase0-evidence.md. Read the cited section before planning; D-rows there are decisions, not suggestions. If implementing shows a D-row is wrong, say so in the PR body rather than quietly deviating.
    • Plugin freeze (C-1): do not edit .claude/skills/**, templates/skills/** or plugin/**. Skill-side changes belong to feat(skills): the human-surface reference — decisions via AskUserQuestion, waiting per mode, completion with a link; skills call sequant comment render and sequant mutation … instead of hand-rendering #1606.
    • Test suite, exec phase and qa phase both: run the full npm test at most once, in the foreground, with timeout 1500, and only after a WIP commit. Prefer targeted npx vitest run <file> while iterating. Each phase has a hard 30-minute wall; the suite takes 10–13 minutes.
    • Gate tests follow the repo CLAUDE.md rule: a mutation-verified record in the PR body, failedTest starting with the test file path. A mutation must still type-check (delete the block, never false &&).

    Issue-specific: §3 D-1.1 is the contract: detect a hook channel by resolving each enabled plugin's install path (via ~/.claude/plugins/installed_plugins.json) and checking for hooks/hooks.json, never by matching the plugin name. The doctor check uses the existing Check {name,status,message,fix?} shape in src/commands/doctor.ts. Before adding a new reader of the plugin registry, grep for existing ones; if a second producer or an earlier fix of the same artifact turns up, name the owner in the PR and stop rather than patch locally.

  4. admarble commented on Oct 27, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (5 ACs, 3 directories)

    AC Quality Check

    The linter passes all 5 ACs (5/5, 0 flagged). Every AC has one line and an Evidence: clause. Vacuity check against main (d6d66a9): AC-1, AC-2 and AC-3 name -t cases that do not exist yet, and grep -c 'Hook channels' docs/features/plugin-distribution.md returns 0 today, so AC-1 to AC-4 all fail today. AC-5 is a constraint, so it passes today by design.

    Scope Assessment

    Non-Goals: do not change the hook scripts or hooks/hooks.json; no runtime dedupe.

    • Feature count: 2 (doctor detection, install-time skip) ⚠️
    • AC items: 5 ✅
    • Directory spread: 3 (src/commands, src/lib, docs/features) ⚠️

    Verdict: ⚠️ SCOPE_WARNING. Both features share one detector, so a split would duplicate it. Keep it as one issue.

    Acceptance Criteria

    AC-1: doctor Hook channels. Verification: Unit Test. Given a temp home whose installed_plugins.json maps an enabled plugin to an install path, and a project .claude/settings.json → When doctor checks run → Then fail (the message names both paths and both fixes) only when both channels register pre-tool.sh. Four fixtures, as the AC lists. Assumption: enabledPlugins values are booleans, and a local false overrides a user true. This checkout shows that today: sequant@sequant is true in user settings and false in .claude/settings.local.json.

    AC-2: init with the plugin channel. Verification: Unit Test. Given a detector that reports a plugin hook channel → When init runs → Then there is no .claude/hooks/, no .claude/settings.json hook entries, the manifest has "hooks": "plugin", and one line is printed.

    AC-3: update honours "hooks": "plugin". Verification: Unit Test. Given such a manifest → When update runs → Then applySet contains no .claude/hooks/** and no .claude/settings.json.

    AC-4: Docs. Verification: grep. The plugin-distribution doc states the one-channel rule and names Hook channels. Line 74 ("Hooks … Yes (via sequant init)") must also stop implying both channels.

    AC-5: No skill-directory edits. Verification: diff grep (C-1 freeze).

    Implementation Plan

    Phase 1: One detector (one producer, C-3)

    1. Add a new src/lib/hook-channels.ts that exports detectHookChannels({ cwd, home }) → { repo: string | null, plugins: { id, installPath, hooksJson }[] }. It merges enabledPlugins in Claude Code's precedence order: user ~/.claude/settings.json < project .claude/settings.json < local .claude/settings.local.json. Only ids whose final value is true count.
      • Install path: resolve each id through installed_plugins.json (v2: plugins[id] is an array of entries). Pick the entry with scope local/project whose projectPath equals the checkout, otherwise the user entry. Local-scope entries are per project; this machine has 60+ sequant-dev@my-mods entries, one per checkout.
      • Channel test: a plugin counts only if <installPath>/hooks/hooks.json parses and some command string contains pre-tool.sh. Never match on the plugin name (D-1.1).
      • Errors: missing or unreadable files mean "no channel", never a throw.
      • Testability: inject home the same way checkShadowingLocalSequant does (doctor.ts:194).
    2. Add hooks?: "plugin" to Manifest in src/lib/manifest.ts, plus a createManifest option. Add one path predicate, isHookChannelPath(p) (.claude/hooks/**, .claude/settings.json), so every filter below uses it.

    Phase 2: Consumers

    1. doctor: add the Hook channels check to collectInstallChecks using the Check shape. When the manifest says "hooks": "plugin", checks 4–5 (Hooks, Settings) report pass with "hooks come from plugin " instead of the current "No hooks directory" / "No settings.json" warns.
    2. init: call the detector before copyTemplates. On a hit, pass a new skipHooks option that skips the hooks copy and the settings.json write. The template holds only hooks, so skipping the whole file is correct. Write hooks: "plugin" and print one line. Apply this only when --agent is claude: codex's .codex/config.toml wraps .claude/hooks/*.sh.
    3. update: filter allChanges with isHookChannelPath when manifest.hooks === "plugin". updateManifest must preserve the field.

    Phase 3: Docs and changelog

    1. Update docs/features/plugin-distribution.md (one-channel rule and the Hook channels check), add a CHANGELOG entry, and add an ADR (see below).

    Design Review

    1. Where does it belong? Detection belongs in src/lib/hook-channels.ts, because three commands consume it and none of them should own it. The scope field belongs in manifest.ts, next to groups (fix(sync): a --only skills install warns 'N file(s) differ' forever, and the suggested sync --force overwrites the repo's constitution #1409).
    2. Simplest correct approach: a read-only detector plus a manifest field. Rejected: name matching and runtime dedupe (D-1.1, D-1.3). Also rejected: adding "hooks" to InstallGroup/groups. update refuses every partial scope (update.ts:204), so that approach would block update for exactly these users.
    3. Pattern and re-patch history: this follows the fix(sync): a --only skills install warns 'N file(s) differ' forever, and the suggested sync --force overwrites the repo's constitution #1409/fix(sync): plain sync and doctor still steer a skills-only install into a full install — sync ignores the recorded scope, doctor names bare sync #1485 install-scope pattern (getInstallScope + filter). git log -S enabledPlugins shows no earlier fix in src, and no existing reader of installed_plugins.json exists outside the upstream tests. 0 prior fixes, so this is not a recurrence.
    4. Senior challenge: "Why not just read enabledPlugins for sequant*?" Because sequant-dev@my-mods may have no hooks/ dir (§3 D-1.1), and a local false disables a user true. "Why skip all of settings.json?" Because the template holds only hooks, and users extend it through settings.local.json (templates.ts:317 ruling).
    5. Producers and consumers of the hook registration (whole-repo grep):
      • Producers: copyTemplates (used by init and sync), update applySet (computeTemplateChanges), and provisionCodex (wrapper only).
      • Consumers of the scope: update.ts, sync.ts (filterToInstallScope and drift pre-flight) and doctor.ts (drift message).
      • Gap: sync (full) is a third producer the issue does not list. Without a fix, sequant sync re-adds the hooks, and the drift scan reports the absent hook files as new drift on every run (templates.ts:862). Every site uses the same isHookChannelPath predicate (derived AC-6).

    ADR required. The plan chooses a manifest field over an install group (Q2). The exec PR adds docs/adr/NNNN-hook-channel-manifest-field.md.

    Feature Quality Planning

    • Error paths: malformed installed_plugins.json or hooks.json gives "no plugin channel" and never crashes doctor or init. Needs a unit test.
    • Out of scope: the founding doc's warn case (neither channel present while the manifest expects hooks) has no AC. Leave it out unless it costs one branch.
    • Gate tests: AC-1 to AC-3 need a Mutation-verified: record whose failedTest starts with the test file path (e.g. delete the plugin branch in detectHookChannels and confirm the "both active" case fails).

    Derived ACs

    • AC-6 (from Q5 producers, High): sync and the drift scan honour "hooks": "plugin". They write no hook files and report none as drift. Evidence: npx vitest run src/commands/sync.test.ts -t "hooks: plugin" → ≥ 1 passed.
    • AC-7 (from error handling, Medium): a malformed registry gives pass with no throw. Covered in hook-channels.test.ts.

    Open Questions

    1. Read project .claude/settings.json enabledPlugins too? Recommendation: yes; Claude Code merges all three. Impact if wrong: a plugin enabled at project scope goes undetected.
    2. Include sync (AC-6) here? It is outside "May touch". Recommendation: yes; without it the next sequant sync undoes AC-2. Impact if wrong: AC-2 only lasts until the next sync.
    3. OQ-1 (founding doc): skip hooks silently and print one line, versus prompting. Recommendation: the D-1.2 default (print one line).

    Recommended Workflow

    Phases: spec → testgen → exec → qa
    Quality Loop: disabled
    Reasoning: AC-1 to AC-3 declare vitest evidence (unit_test), so testgen stubs the named -t cases. The scope warning comes from the shared detector, not from size.

    Label Review

    Current: graph-2026-10-ergonomics. Recommended: add enhancement, planned. No UI files, so no test phase.

  5. added
    planned
    enhancement
    on Oct 27, 2026
  6. admarble commented on Oct 27, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    Gaps:

    • Required test check had not finished when QA ran
    • init --force on a checkout that already has repo hooks, with a hook-shipping plugin enabled, records hooks:plugin but leaves both channels active without a message; doctor's Hook channels check does catch it
  7. added 3 commits that reference this issue on Oct 27, 2026
  8. added a commit that references this issue on Oct 28, 2026
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

    enhancementgraph-2026-10-ergonomicsplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions