Skip to content

Start hooks through an .mjs launcher that enables Node's compile cache - #55

Merged
bguidolim merged 3 commits into
bruno/GH-50-edit-linked-memoriesfrom
bruno/hook-compile-cache
Oct 31, 2026
Merged

bguidolim merged 3 commits into
bruno/GH-50-edit-linked-memoriesfrom
bruno/hook-compile-cache

Conversation

@bguidolim

@bguidolim bguidolim commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Every hook start strips the TypeScript types before running, which costs about 30 ms regardless of file size. That cost is paid on every prompt, every Write/Edit, every memory retrieval and every Read. Each registered hook is now a small plain-JS launcher that enables Node's compile cache and then loads the TypeScript module, so stripping happens once per file version instead of on every start. Measured on an installed layout: 89 ms → 57 ms per run.

The TypeScript modules still install as before; only the registered entry points change from .mts to .mjs, and mcs sync replaces the old registrations.

Stacked on #54; review and merge that first.

Test plan

  • mcs sync, then mcs doctor → expect hooks registered as kb-gate.mjs, kb-usage.mjs and sync-memories.mjs, no leftover .mts registrations
  • Spawn a discovery sub-agent → expect the KB briefing as before
  • On Node 22, run a hook twice → expect no warning on stderr

@bguidolim
bguidolim force-pushed the bruno/hook-compile-cache branch from 4832a06 to 7320a12 Compare October 29, 2026 00:34
@bguidolim
bguidolim changed the base branch from main to bruno/GH-50-edit-linked-memories October 29, 2026 00:34
@bguidolim
bguidolim force-pushed the bruno/hook-compile-cache branch 2 times, most recently from 5870f12 to 65faaa7 Compare October 29, 2026 09:39
- Each registered hook runs a small .mjs that calls enableCompileCache and imports its .mts, cutting ~30 ms of type stripping per start
- The .mts modules install as plain file components; a contract test keeps every node registration on .mjs
@bguidolim
bguidolim force-pushed the bruno/hook-compile-cache branch from 65faaa7 to fe54e41 Compare October 30, 2026 00:06
@bguidolim
bguidolim added this pull request to stack #57 October 31, 2026 23:24
- Launchers feature-detect module.enableCompileCache, which Node added in 22.8
- Node 22.6 and 22.7 now load the hooks without the cache instead of failing to link
- Launcher comments and CLAUDE.md: Node 22 caches only the compile step
@bguidolim
bguidolim merged commit 3174e98 into main Oct 31, 2026
5 checks passed
@bguidolim
bguidolim deleted the bruno/hook-compile-cache branch October 31, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant