Skip to content

fix(hooks): read the XDG global config in the code-simplifier Stop hook - #4160

Merged
Yeachan-Heo merged 7 commits into
Yeachan-Heo:devfrom
JayOfTheKeyboard:fix/code-simplifier-xdg-config
Sep 29, 2026
Merged

Yeachan-Heo merged 7 commits into
Yeachan-Heo:devfrom
JayOfTheKeyboard:fix/code-simplifier-xdg-config

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown
Contributor

Problem

docs/REFERENCE.md says to enable the code-simplifier in the global OMC config, and gives the Linux/Unix default as ${XDG_CONFIG_HOME:-~/.config}/omc/config.json. The TypeScript hook (src/hooks/code-simplifier/index.ts) reads that path through getGlobalOmcConfigCandidates, which #1898 added. The hooks that actually run were not ported, though. scripts/code-simplifier.mjs (the plugin's Stop hook) and templates/hooks/code-simplifier.mjs (the standalone install) still read only ~/.omc/config.json.

I fed a Stop payload to scripts/code-simplifier.mjs on dev at 2db31f9. The setup was a scratch HOME, a git repo with one modified a.ts, and {"codeSimplifier":{"enabled":true}} in the config file named in each row:

Config location Expected (TS hook / docs) scripts/code-simplifier.mjs on dev
~/.config/omc/config.json block, delegate a.ts {"continue":true}, nothing happens
$XDG_CONFIG_HOME/omc/config.json block {"continue":true}, nothing happens
$OMC_HOME/config.json block {"continue":true}, nothing happens
XDG says enabled:false, legacy says true continue (XDG wins) block (legacy wins)
~/.omc/config.json only block block

So on Linux, a user who follows the docs gets no simplifier and no error. The template copy behaves the same way.

Fix

Both .mjs copies now inline a mirror of getGlobalOmcConfigCandidates('config.json'):

  • $OMC_HOME/config.json alone when OMC_HOME is set;
  • otherwise ${XDG_CONFIG_HOME:-~/.config}/omc/config.json on Linux/Unix, then the legacy ~/.omc/config.json;
  • legacy only on Windows and macOS;
  • the first file that exists wins.

It's inlined rather than imported from dist/, so the hooks stay build-independent, the same way scripts/lib/agent-model-config.mjs mirrors getConfigDir. The template copy can only import its own lib/. The header comment in each file now names the real lookup.

The inventory graph is regenerated in a separate commit, as before.

Not changed

  • scripts/persistent-mode.mjs getIdleCooldownSeconds (and the unregistered scripts/persistent-mode.cjs) still read notificationCooldown.sessionIdleSeconds from ~/.omc/config.json only. Fix XDG-aware global OMC config/state paths on Unix #1898 also moved that read to the XDG helper on the TS side. It's the same one-function change, but its only effect is the idle-notification cooldown, which I couldn't test cleanly through the script. I'm happy to add it here or send it separately.
  • persistent-mode.mjs also uses ~/.omc/state for its global state dir, where the TS side uses getGlobalOmcStateRoot. That's state, not config, so I left it alone.

Test

New file: src/hooks/code-simplifier/__tests__/global-config-path.test.ts. It runs both scripts/code-simplifier.mjs and templates/hooks/code-simplifier.mjs as subprocesses, with a scratch HOME and a temp git repo holding one modified .ts file. There are 6 cases per script, 12 in all. The three XDG cases are skipped on win32 and darwin.

  • On the parent (2db31f9, and again on e3f9661 after rebasing onto it), 8 fail and 4 pass. For each script, the XDG, ~/.config and OMC_HOME cases fail with expected undefined to be 'block', which means the hook returned {"continue":true}. The "XDG wins over legacy" case fails because the hook blocked from the legacy file. The legacy-only and no-config cases pass on the parent too; they guard against regressions.
  • With the fix, all 12 pass, and so does the rest of src/hooks/code-simplifier/ (18 tests across 2 files). The test clears OMC_HOME, OMC_STATE_DIR, XDG_CONFIG_HOME, GIT_DIR and GIT_WORK_TREE from the child environment, so it doesn't write into a developer's real state dir.
  • Mutations, each applied to each copy separately:
Mutation Red
No XDG candidate (legacy only) 3 (XDG, ~/.config, XDG-over-legacy)
No OMC_HOME branch 1
Legacy checked before XDG 1
XDG_CONFIG_HOME ignored (always ~/.config) 1
No legacy fallback 1

Validation

  • npx vitest run src/hooks/code-simplifier/: all pass
  • Full npx vitest run on Linux: FILL_IN (branch) against FILL_IN (dev 2db31f9, run the same way)
  • npx tsc --noEmit and npm run lint are clean, and npm run generate:inventory:verify passes
  • No dist/ or bridge/ changes

JayOfTheKeyboard and others added 5 commits September 29, 2026 14:36
The shipped code-simplifier hooks (scripts/ for the plugin, templates/hooks/
for the standalone install) only read ~/.omc/config.json. The TypeScript
hook and docs/REFERENCE.md use getGlobalOmcConfigCandidates: $OMC_HOME,
else ${XDG_CONFIG_HOME:-~/.config}/omc/config.json on Linux/Unix, then the
legacy ~/.omc fallback. A Linux user who enables codeSimplifier where the
docs say got no simplifier at all.

Mirror that lookup in both .mjs copies.
These hook scripts legitimately construct global OMC config paths
(~/.omc/config.json), which are per-user and not workspace-scoped.
The gate should not flag global config path construction.
# Conflicts:
#	inventory/inventory-graph.json
@Yeachan-Heo

Copy link
Copy Markdown
Owner

Pushed two commits on top of your branch:

  • 7ab2143fd adds scripts/code-simplifier.mjs and templates/hooks/code-simplifier.mjs to the file whitelist in scripts/ci/check-multirepo-paths.mjs. The legacy fallback join(home, '.omc', 'config.json') is a per-user global path, but the gate only exempts join(homedir(), '.omc', ...). Here the first argument is the HOME/USERPROFILE-aware variable, which mirrors getUserHomeDir() in src/utils/paths.ts, so the gate can't tell it's global. The other hook entrypoints that resolve global config are already on that list.
  • 03deb5f395 merges current dev (which picked up fix(rules-injector): let **/ match zero directories in rule globs #4161) and regenerates inventory/inventory-graph.json.

Your commits are unchanged. Locally the multirepo gate is OK, the inventory verify passes, and 29/29 pass across the code-simplifier and inventory-drift tests. We'll merge once CI is green on this head.

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

@Yeachan-Heo
Yeachan-Heo merged commit 6184bad into Yeachan-Heo:dev Sep 29, 2026
20 checks passed
@Yeachan-Heo

Copy link
Copy Markdown
Owner

Thanks @JayOfTheKeyboard! 🚀

Merge Details:

  • Merge Commit: 6184bad
  • Method: Squash merge
  • All Checks: ✅ Passed
    • Lint & Type Check
    • Test
    • Test (Windows path suite)
    • better-sqlite3 Node 26 (ubuntu-latest)
    • better-sqlite3 Node 26 (windows-2022)
    • omc update + session-start hook
    • PreCompact restore (macos-latest)
    • PreCompact restore (windows-2022)
    • npm pack + install test
    • Base Branch Check
    • Size Check
    • Draft PR Check
    • Authorize generated artifacts from base trust root
    • No Committed Build Artifacts

—
[repo owner's gaebal-gajae (clawdbot) 🦞]

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.

2 participants