Commit 0d9470c
fix: ESM require() runtime bug + empty setup suggestions block
## Bug 1 — doctor.checkHook always reported "not found" in production
Root cause: three functions in src/doctor/report.ts, two in
src/setup/detect.ts, and one in src/setup/wizard.ts used bare
require() calls at runtime — but tsup bundles to ESM where require
is undefined. The ReferenceError was caught by each function's own
catch block and silently treated as "check failed," so:
- doctor reported "Sentinel hook not found" even after a successful
install-hook (verified live against a fresh tmp project)
- detect.ts's Claude Code detection reported configured=false even
when the hook was wired
- setup --user scope would hit "homedir is not a function"
Why tests passed: vitest's test runtime provides CommonJS interop so
require() works in test environment. The bundled CLI doesn't.
v2.0.1 shipped a similar "CI-passed, prod-broken" pattern for a
different reason; this is the same class of bug.
Fix: move every require() to a proper top-level ESM import.
- report.ts: import readFileSync + cachePath/isNewer at top
- detect.ts: import readFileSync at top
- wizard.ts: import readFileSync, writeFileSync, mkdirSync, dirname,
homedir at top
Verified live:
$ engram setup -y -p /tmp/fresh-project
✓ Sentinel hook installed
✓ hook Sentinel hook active (via /tmp/fresh-project/.claude/settings.local.json)
## Bug 2 — empty "Next steps for detected IDEs:" block
When only Claude Code was detected-but-unconfigured (and there's no
suggest entry for Claude Code because install-hook handles it in
step 2), the wizard printed "Next steps for detected IDEs:" with
no subsequent lines.
Fix: collect suggestions first. If the list is empty, either:
- skip with "Claude Code hook declined" if Claude Code is the
culprit (user declined hook install in step 2)
- done with "no additional adapters needed" otherwise
The header line only prints when there's at least one actionable
suggestion.
## Audit result
While auditing for this bug I grepped every new file for `require(`
and found 7 offenders across 3 files. All fixed in one commit.
No other ESM-interop issues found.
Verified: 746/746 tests still pass, lint clean, build clean, live
E2E test of setup → doctor → Bash auto-reindex all behave
correctly. Bash PostToolUse with ENGRAM_AUTO_REINDEX=1 successfully
prunes the graph when the underlying file is rm'd.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ecee8bd commit 0d9470c
3 files changed
Lines changed: 42 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
| |||
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
140 | | - | |
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | | - | |
| 119 | + | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
| |||
202 | 201 | | |
203 | 202 | | |
204 | 203 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
208 | 209 | | |
209 | 210 | | |
210 | | - | |
211 | | - | |
212 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
213 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
214 | 231 | | |
215 | 232 | | |
216 | 233 | | |
| |||
0 commit comments