Skip to content

refactor(shared): apply json-cache utility to consumer modules#1857

Open
iyoda wants to merge 6 commits intocode-yeongyu:devfrom
iyoda:refactor/pr6-apply-json-cache
Open

refactor(shared): apply json-cache utility to consumer modules#1857
iyoda wants to merge 6 commits intocode-yeongyu:devfrom
iyoda:refactor/pr6-apply-json-cache

Conversation

@iyoda
Copy link
Contributor

@iyoda iyoda commented Feb 15, 2026

Summary

Apply the json-cache utility (from #1856) to 4 consumer modules, replacing inline existsSync + readFileSync + JSON.parse + try/catch and writeFileSync + JSON.stringify patterns.

Changes

  • src/shared/connected-providers-cache.ts — 4 functions refactored, removed ensureCacheDir() helper
  • 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)

Verification

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

PR Stack

This is PR 6 of 9 in the code deduplication refactor series. Depends on #1856.

# 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 This PR Apply json-cache to consumers
7 (next) Add ensure-directory utility
8 Apply ensure-directory to production
9 Consolidate ToolContextWithMetadata

Summary by cubic

Applied the shared json-cache utility and centralized helper functions across the codebase to reduce duplication and simplify imports. Unified getMessageDir, formatDuration, and model matching utilities, and removed dead background-task modules.

  • New Features

    • Added readJsonFile/writeJsonFile with optional ensureDir, plus unit tests.
    • Exported json-cache via shared/index.
  • Refactors

    • Adopted json-cache in connected-providers-cache and hook storages (rules-injector, agent-usage-reminder, interactive-bash-session).
    • Consolidated getMessageDir to shared/session-utils and formatDuration to tools/background-task/time-format; updated imports and removed duplicates.
    • Unified fuzzyMatchModel into shared/model-name-matcher; exported normalizeModelName and added re-exports in model-availability for compatibility.
    • Removed dead code under tools/background-task/modules and message-dir variants.

Written for commit b4f34f8. 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.

1 issue found across 42 files

Confidence score: 2/5

  • Critical issue: package.json declares oh-my-opencode as its own dependency, which can break installs or create dependency resolution loops
  • High severity (9/10) with high confidence makes this a likely merge-blocking problem
  • Pay close attention to package.json - remove the self-dependency to avoid install failures
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="package.json">

<violation number="1" location="package.json:65">
P0: Critical self-dependency detected: package lists 'oh-my-opencode' as its own dependency</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

package.json Outdated
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 15, 2026

Choose a reason for hiding this comment

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

P0: Critical self-dependency detected: package lists 'oh-my-opencode' as its own dependency

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At package.json, line 65:

<comment>Critical self-dependency detected: package lists 'oh-my-opencode' as its own dependency</comment>

<file context>
@@ -62,6 +62,7 @@
     "detect-libc": "^2.0.0",
     "js-yaml": "^4.1.1",
     "jsonc-parser": "^3.3.1",
+    "oh-my-opencode": "^3.5.5",
     "picocolors": "^1.1.1",
     "picomatch": "^4.0.2",
</file context>
Fix with Cubic

@iyoda iyoda force-pushed the refactor/pr6-apply-json-cache branch from 50bb0b4 to 80936b5 Compare February 15, 2026 08:52
iyoda and others added 4 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)
@iyoda iyoda force-pushed the refactor/pr6-apply-json-cache branch from 80936b5 to b4f34f8 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