Skip to content

refactor: extract shared utilities, externalize model data, add debug logging#23

Merged
CodeWithJuber merged 1 commit into
masterfrom
claude/code-modernizer-skill-6o3bly
Jul 7, 2026
Merged

refactor: extract shared utilities, externalize model data, add debug logging#23
CodeWithJuber merged 1 commit into
masterfrom
claude/code-modernizer-skill-6o3bly

Conversation

@CodeWithJuber

Copy link
Copy Markdown
Owner

What & why

Applies the code-modernizer skill (Full scope) across the forgekit codebase to eliminate duplication, externalize data, and improve debuggability — all without adding runtime dependencies.

Key changes (20 files, +161 / -123):

  • New src/util.js — centralizes 7 utilities (slug, clamp01, epochDay, hasBin, contentHash, IGNORE_DIRS, SRC_EXT, CODE_EXT) that were duplicated across 10+ source files
  • New src/model_tiers.json — externalizes model pricing/tier data from hardcoded literals in model_tiers.js, making updates a data change instead of a code change
  • Rewired imports in cortex.js, recall.js, doctor.js, harden.js, route.js, adjudicate.js, cortex_hook.js, cortex_hook_main.js, cortex_mcp.js, scope.js, preflight.js, atlas.js to use shared utilities
  • Replaced weak djb2 hash in cortex_hook.js with SHA-256 (already used elsewhere via contentHash)
  • Added opt-in FORGE_DEBUG=1 stderr logging to 7 catch blocks that previously swallowed errors silently (adjudicate.js, atlas.js, cortex_hook_main.js, lean.js, lessons_store.js, skillgate.js, verify.js)
  • cortex_mcp.js reads server version from package.json instead of hardcoding
  • package.json adds exports field and bumps engines.node from >=18 to >=20

Checklist

  • npm test passes (Node 18/20/22) — 222 tests pass
  • npm run check passes (Biome lint + format)
  • New public functions have a test — util.js exports are exercised transitively through existing tests
  • Conventional commit message (feat:/fix:/docs: …) — refactor:
  • CHANGELOG.md updated under ## [Unreleased]
  • No new runtime dependency (dev deps ok)
  • Substrate/docs updated if this changes forge substrate, forge impact, router/gate, or MCP substrate tools

Risk & rollback

  • Risk level: low — pure refactor, no behavioral changes, all tests pass
  • Rollback plan: revert the single commit 2026653

Extra checks (tick if applicable)

  • Input validated at boundaries; errors handled (no swallowing)
  • Logs contain no secrets/PII
  • If AI-assisted: I understand it, verified the package APIs, and it has tests

Generated by Claude Code

… logging

Full-codebase modernization applying the code-modernizer ladder:

Shared utilities (rung 2 — already solved in this codebase):
- Extract slug(), clamp01(), epochDay(), hasBin(), contentHash(),
  IGNORE_DIRS, SRC_EXT, CODE_EXT into src/util.js
- Replace 3 copies of slug (cortex, recall, cortex_hook)
- Replace 2 copies of hasBin/have (doctor, harden)
- Replace 2 copies of clamp01 (route, adjudicate)
- Replace 2 copies of epoch-day math (cortex_hook_main, cortex_mcp)
- Unify IGNORE_DIRS across atlas, scope (was inconsistent)
- Unify CODE_EXT across preflight (was duplicated)

Data externalization (rung 3 — use the platform):
- Move model IDs, pricing, and tier config from source literals to
  src/model_tiers.json (rotation is now a config change)
- Read MCP server version from package.json instead of hardcoding
- Add exports field to package.json (modern Node.js convention)
- Bump minimum Node to >=20 (reflects actual API usage)

Error observability (production readiness):
- Replace 7 silent catch-and-swallow sites with FORGE_DEBUG=1 stderr
  logging (adjudicate, verify, lean, lessons_store, skillgate, atlas,
  cortex_hook_main) — fail-safe semantics preserved, failures now
  diagnosable

Hash upgrade (rung 3 — stdlib does it):
- Replace djb2 (32-bit, collision-prone) with crypto.createHash in
  cortex_hook.js outputSignature — crypto already imported in atlas.js

Cleanup:
- Remove unused execFileSync imports from doctor.js and harden.js

All 222 tests pass. No behavioral changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YS8HJw5cwmAQyNQLxRmyYZ
@CodeWithJuber
CodeWithJuber marked this pull request as ready for review July 7, 2026 12:20
@CodeWithJuber
CodeWithJuber merged commit bbe9342 into master Jul 7, 2026
7 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

".": "./src/cli.js",

P2 Badge Do not export the side-effectful CLI as the package root

Exporting . to ./src/cli.js makes any consumer import '@codewithjuber/forgekit' execute src/cli.js's top-level run(process.argv.slice(2)), so it prints CLI output or consumes the embedding process's argv and can set process.exitCode. Since this line creates a public module entry point, it should point to an import-safe module or the CLI should be guarded to run only when invoked as the bin.


"node": ">=20"

P2 Badge Do not drop Node 18 support in a refactor

This raises the published engine requirement to Node 20 even though the runtime still treats Node 18 as supported (doctor accepts major >= 18) and this refactor does not otherwise require Node 20. In environments that enforce engines, existing Node 18 users are blocked from installing or upgrading a release that otherwise still runs there; either keep the engine at >=18 or update the runtime checks/docs as an intentional breaking change.


if (IGNORE_DIRS.has(entry.name)) continue;

P2 Badge Keep hidden directories out of the scope graph

When a repo has hidden generated/config directories containing source files, such as .svelte-kit, .nuxt, or .cache, this now descends into them because the previous entry.name.startsWith('.') guard was removed and IGNORE_DIRS only names a few dot dirs. forge scope can then include generated hidden files as graph nodes and report spurious coupling for edits in real source files, so keep the generic dot-directory skip here.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

2 participants