Skip to content

refactor(background-task): consolidate ToolContextWithMetadata and resolveToolCallID#1860

Open
iyoda wants to merge 9 commits intocode-yeongyu:devfrom
iyoda:refactor/pr9-consolidate-tool-context
Open

refactor(background-task): consolidate ToolContextWithMetadata and resolveToolCallID#1860
iyoda wants to merge 9 commits intocode-yeongyu:devfrom
iyoda:refactor/pr9-consolidate-tool-context

Conversation

@iyoda
Copy link
Contributor

@iyoda iyoda commented Feb 15, 2026

Summary

Consolidate duplicated ToolContextWithMetadata type definitions and extract a shared resolveToolCallID function within src/tools/background-task/.

Changes

  • Extended: src/tools/background-task/types.ts — Added callID and toolCallId fields to ToolContextWithMetadata
  • New: src/tools/background-task/resolve-tool-call-id.ts (8 lines) — Extracted resolveToolCallID helper
  • Simplified: create-background-task.ts — Removed inline type extension and duplicate resolution logic
  • Simplified: create-background-output.ts — Removed inline type extension and duplicate resolution logic

Net: -12 lines (removed 26, added 14)

Verification

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

PR Stack

This is PR 9 of 9 (final) in the code deduplication refactor series. Depends on #1859.

# 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 #1859 Apply ensure-directory to production
9 This PR Consolidate ToolContextWithMetadata

Series Total Impact

  • ~1,300+ lines deleted across the series
  • 16 duplicate files removed
  • 4 new shared utilities created (with tests)
  • Zero behavioral changes — all refactors are pure deduplication

Summary by cubic

Consolidates background-task tool context typing and call ID resolution, removes legacy modules, and centralizes shared utilities for duration formatting, message directory lookup, JSON I/O, and model matching. This removes duplicates and keeps behavior unchanged.

  • Refactors
    • Centralized ToolContextWithMetadata and extracted resolveToolCallID in src/tools/background-task/.
    • Deleted src/tools/background-task/modules/* and migrated duration formatting to tools/background-task/time-format; updated imports across features/tools/hooks.
    • Moved getMessageDir to shared/session-utils and removed local duplicates.
    • Added ensureDirectory and json-cache utilities; applied across storage/cache modules; added tests.
    • Made model-name-matcher the single source for fuzzyMatchModel and normalizeModelName; re-exported from model-availability.

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

2 issues found across 59 files

Confidence score: 2/5

  • High risk due to a severe package configuration problem: package.json has an invalid self-dependency with an unsatisfiable version constraint, which can break installs/builds.
  • There is some risk of runtime issues from missing error handling for malformed data types in src/hooks/rules-injector/storage.ts.
  • Pay close attention to package.json and src/hooks/rules-injector/storage.ts - dependency resolution failure and unhandled storage data types.
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: Invalid self-dependency with unsatisfiable version constraint in package.json</violation>
</file>

<file name="src/hooks/rules-injector/storage.ts">

<violation number="1" location="src/hooks/rules-injector/storage.ts:23">
P2: Missing error handling for potentially malformed data types in storage file</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: Invalid self-dependency with unsatisfiable version constraint in package.json

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>Invalid self-dependency with unsatisfiable version constraint in package.json</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/pr9-consolidate-tool-context branch from bd05332 to bd4c4cd Compare February 15, 2026 08:52
iyoda and others added 7 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
…solveToolCallID

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/pr9-consolidate-tool-context branch from bd4c4cd to 049c751 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