Skip to content

update-graph.sh hook skips .mjs/.cjs files, leaving graph.db stale after edits #1736

Description

@carlos-alm

Bug

`.claude/hooks/update-graph.sh` (PostToolUse hook for Edit/Write) only triggers an incremental `codegraph build` for a hardcoded extension allowlist:

```bash
case "$FILE_PATH" in
.js|.ts|.tsx|.jsx|.py|.go|.rs|.java|.cs|.php|.rb|.tf|*.hcl)
;;
*)
exit 0
;;
esac
```

This list is missing `.mjs` and `.cjs`, even though both are registered JavaScript extensions in `LANGUAGE_REGISTRY` (`src/domain/parser.ts`) and `EXTENSIONS` (`src/shared/constants.ts`) — confirmed by `codegraph build` itself successfully parsing `.mjs` files once run manually.

Repro

  1. Edit any `.mjs` file in the repo (e.g. `scripts/*.mjs`) via Claude Code's Edit/Write tool.
  2. The PostToolUse hook fires but silently `exit 0`s without rebuilding, because the extension isn't in the allowlist.
  3. `.codegraph/graph.db` mtime stays older than the edited file.
  4. Subsequent `codegraph complexity --file <edited.mjs>`, `codegraph fn-impact`, etc. return stale pre-edit results with no warning.

Observed during Titan Paradigm FORGE phase 4 (extracting `scripts/lib/name-map.mjs` from `scripts/import-jelly-micro.mjs` + `scripts/compare-tools.mjs`): after editing all three `.mjs` files, `.codegraph/graph.db` mtime (03:52) predated the edits (04:07). `codegraph complexity --file scripts/compare-tools.mjs --health` still reported the deleted `buildNameMap`/`buildAcgNameLookup` functions at their old line ranges until a manual `codegraph build` was run.

Fix

Sync the hook's extension allowlist with `EXTENSIONS` in `src/shared/constants.ts` (or better: derive it from that constant instead of hardcoding a second copy) so `.mjs`/`.cjs` — and any future registry additions — don't silently go stale.

Impact

Silent, not fail-fast: no error is surfaced, so agents/users get incorrect complexity/impact/dependency data for any `.mjs`/`.cjs` file edited in a session, unless they happen to notice the DB mtime is stale or manually rebuild.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions