Skip to content

feat(shared): add json-cache utility for generic JSON file read/write#1856

Open
iyoda wants to merge 5 commits intocode-yeongyu:devfrom
iyoda:refactor/pr5-add-json-cache
Open

feat(shared): add json-cache utility for generic JSON file read/write#1856
iyoda wants to merge 5 commits intocode-yeongyu:devfrom
iyoda:refactor/pr5-add-json-cache

Conversation

@iyoda
Copy link
Contributor

@iyoda iyoda commented Feb 15, 2026

Summary

Add a generic json-cache utility (readJsonFile / writeJsonFile) that encapsulates the common pattern of reading/writing JSON files with proper error handling and optional directory creation.

Changes

  • New: src/shared/json-cache.ts (23 lines) — readJsonFile<T>() and writeJsonFile()
  • New: src/shared/json-cache.test.ts (223 lines) — 13 comprehensive tests

API

readJsonFile<T>(path: string): T | null           // Returns null on missing/invalid
writeJsonFile(path: string, data: unknown, opts?)  // opts.ensureDir auto-creates parent

Verification

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

PR Stack

This is PR 5 of 9 in the code deduplication refactor series. Depends on #1855. This PR adds the utility; the next PR (6) applies it to existing consumers.

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

Summary by cubic

Adds a shared json-cache utility to safely read/write JSON files with optional directory creation, and consolidates duplicate helpers while deleting dead background-task modules. This standardizes common behavior and trims unused code.

  • Refactors
    • Centralized getMessageDir in shared/session-utils; removed duplicates and updated imports across features/tools.
    • Centralized formatDuration in tools/background-task/time-format; removed old copies and deleted the background-task/modules directory.
    • Unified fuzzyMatchModel and normalizeModelName in model-name-matcher, with re-exports from model-availability for backward compatibility.

Written for commit 3e976bd. 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 37 files

Confidence score: 2/5

  • High risk: package.json declares a self-dependency (oh-my-opencode depends on itself), which is very likely to break installs at runtime.
  • This is a concrete, user-facing failure path, so merge confidence is low until the circular dependency is removed.
  • 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: Package has a self-dependency (oh-my-opencode depends on itself) which creates a circular dependency. This will cause installation failures.</violation>
</file>

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

package.json Outdated
"detect-libc": "^2.0.0",
"js-yaml": "^4.1.1",
"jsonc-parser": "^3.3.1",
"oh-my-opencode": "^3.5.5",
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: Package has a self-dependency (oh-my-opencode depends on itself) which creates a circular dependency. This will cause installation failures.

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>Package has a self-dependency (oh-my-opencode depends on itself) which creates a circular dependency. This will cause installation failures.</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/pr5-add-json-cache branch from 60eb995 to 0222f4a Compare February 15, 2026 08:52
iyoda and others added 3 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>
@iyoda iyoda force-pushed the refactor/pr5-add-json-cache branch from 0222f4a to 3e976bd 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