Files
oh-my-claudecode/scripts/lib/config-dir.mjs
Bellman 707b3357e0 Fix update-check cache path consistency (#3112)
* Keep update-check cache under Claude config

Route HUD and hook update-cache access through the same CLAUDE_CONFIG_DIR-aware helper so Windows and custom config roots do not split writer and reader state.

Constraint: Scope limited to update-check path consistency for issue #3109.

Rejected: Moving the cache to ~/.omc | That would preserve the HUD-only path and diverge from existing CLAUDE_CONFIG_DIR-aware updater/config storage.

Confidence: high

Scope-risk: narrow

Directive: Keep future update-check readers and writers on getUpdateCheckCachePath().

Tested: npm test -- --run src/__tests__/update-check-path.test.ts src/__tests__/config-dir.test.ts; npx eslint src/utils/config-dir.ts src/hud/index.ts src/__tests__/update-check-path.test.ts; npm run build

Not-tested: Full test suite

* Keep session-start template helper in sync

Expose the update-check cache helper from the template-local config-dir module so direct template execution has the same helper that session-start imports.

Constraint: Scope limited to the update-check path/template regression from PR #3112 CI.

Rejected: Changing session-start error handling | The failure was missing helper propagation, not restore-context behavior.

Confidence: high

Scope-risk: narrow

Directive: Keep templates/hooks/lib/config-dir.mjs aligned with update-check helpers used by templates/hooks/session-start.mjs.

Tested: npm test -- --run src/installer/__tests__/session-start-template.test.ts src/__tests__/update-check-path.test.ts src/__tests__/config-dir.test.ts; npm run build; git diff --check

Not-tested: Full test suite

---------

Co-authored-by: Codex Review <codex-review@example.com>
2026-05-26 00:00:48 +08:00

38 lines
902 B
JavaScript

import { homedir } from 'node:os';
import { join, normalize, parse, sep } from 'node:path';
function stripTrailingSep(p) {
if (!p.endsWith(sep)) {
return p;
}
return p === parse(p).root ? p : p.slice(0, -1);
}
export function getClaudeConfigDir() {
const home = homedir();
const configured = process.env.CLAUDE_CONFIG_DIR?.trim();
if (!configured) {
return stripTrailingSep(normalize(join(home, '.claude')));
}
if (configured === '~') {
return stripTrailingSep(normalize(home));
}
if (configured.startsWith('~/') || configured.startsWith('~\\')) {
return stripTrailingSep(normalize(join(home, configured.slice(2))));
}
return stripTrailingSep(normalize(configured));
}
export function getOmcConfigDir() {
return join(getClaudeConfigDir(), '.omc');
}
export function getUpdateCheckCachePath() {
return join(getOmcConfigDir(), 'update-check.json');
}