Skip to content

refactor(shared): apply ensure-directory utility to production code#1859

Open
iyoda wants to merge 8 commits intocode-yeongyu:devfrom
iyoda:refactor/pr8-apply-ensure-directory
Open

refactor(shared): apply ensure-directory utility to production code#1859
iyoda wants to merge 8 commits intocode-yeongyu:devfrom
iyoda:refactor/pr8-apply-ensure-directory

Conversation

@iyoda
Copy link
Contributor

@iyoda iyoda commented Feb 15, 2026

Summary

Apply the ensureDirectory utility (from #1858) to 13 production files, replacing raw mkdirSync(path, { recursive: true }) calls and removing redundant existsSync guards before directory creation.

Changes

Updated 13 production files across shared/, features/, cli/, and hooks/:

  • src/cli/config-manager/ensure-config-directory-exists.ts
  • src/features/boulder-state/storage.ts
  • src/features/claude-tasks/storage.ts
  • src/features/hook-message-injector/injector.ts
  • src/features/mcp-oauth/storage.ts
  • src/hooks/claude-code-hooks/todo.ts
  • src/hooks/claude-code-hooks/transcript.ts
  • src/hooks/ralph-loop/storage.ts
  • src/hooks/session-recovery/storage/text-part-injector.ts
  • src/hooks/session-recovery/storage/thinking-prepend.ts
  • src/shared/binary-downloader.ts
  • src/shared/json-cache.ts
  • src/shared/session-injected-paths.ts

Also added barrel export in src/shared/index.ts.

Net: -14 lines (semantic improvement, redundant guards removed)

Verification

  • bun run typecheck
  • bun test ✅ (2693 pass, 0 fail)
  • bun run build

PR Stack

This is PR 8 of 9 in the code deduplication refactor series. Depends on #1858.

# PR Description
0 #1852 Delete dead code in modules/
2 #1853 Consolidate formatDuration (4→1)
3 #1854 Consolidate getMessageDir (7→1)
4 #1855 Unify fuzzyMatchModel
5 #1856 Add json-cache utility
6 #1857 Apply json-cache to consumers
7 #1858 Add ensure-directory utility
8 This PR Apply ensure-directory to production
9 (next) Consolidate ToolContextWithMetadata

Summary by cubic

Standardized directory creation with ensureDirectory and centralized JSON IO, message dir lookup, and duration formatting. Removed duplicate modules and switched consumers to shared helpers with no behavior changes.

  • Refactors
    • Applied ensureDirectory across config, storage, and hooks; removed existsSync guards.
    • Added json-cache and refactored consumers to use readJsonFile/writeJsonFile (with ensureDir); added tests.
    • Consolidated getMessageDir into shared/session-utils; removed per-tool duplicates and updated imports.
    • Consolidated formatDuration into tools/background-task/time-format; removed duplicates and updated imports.
    • Unified fuzzyMatchModel in model-name-matcher (exported normalizeModelName) with backward-compatible re-exports; deleted unused background-task modules.

Written for commit 495dc6f. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 56 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Large changes with 56 files and 1789 lines changed; no guarantee of zero regressions despite no issues found by AI.

@iyoda iyoda force-pushed the refactor/pr8-apply-ensure-directory branch from 1e64b0a to 68af2ef Compare February 15, 2026 08:52
iyoda and others added 6 commits February 15, 2026 17:55
- Make model-name-matcher.ts the canonical source for fuzzyMatchModel and normalizeModelName
- Export normalizeModelName from model-name-matcher.ts (was internal)
- Remove duplicate implementations from model-availability.ts
- Add re-exports in model-availability.ts for backward compatibility
- All existing consumers continue to work via their import paths
- Tests pass, typecheck clean, build succeeds
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Replace inline existsSync + readFileSync + JSON.parse + try/catch patterns with readJsonFile<T>(), and replace writeFileSync(path, JSON.stringify(data, null, 2)) with writeJsonFile(path, data, { ensureDir: true }). Consumers retain domain-specific logging and type conversions. Removes ensureCacheDir() helper from connected-providers-cache.ts as writeJsonFile handles directory creation.

Affected modules:
- src/shared/connected-providers-cache.ts (4 functions refactored)
- src/hooks/rules-injector/storage.ts (2 functions refactored)
- src/hooks/agent-usage-reminder/storage.ts (2 functions refactored)
- src/hooks/interactive-bash-session/storage.ts (2 functions refactored)
- src/shared/index.ts (added json-cache barrel export)

Net: -64 lines (removed 112, added 48)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- Replace mkdirSync(path, { recursive: true }) with ensureDirectory(path)
- Remove redundant existsSync guards before directory creation
- Add barrel export to src/shared/index.ts
- Updated 13 production files across shared/, features/, cli/, and hooks/
- All tests, typecheck, and build pass
@iyoda iyoda force-pushed the refactor/pr8-apply-ensure-directory branch from 68af2ef to 495dc6f Compare February 15, 2026 08:57
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

Comments