Skip to content

Decompose json-helper.cjs god module #197

Description

@dean0x

Context

scripts/hooks/json-helper.cjs is 1,837 lines with 29 switch cases. PR #193 extracted sidecar-ops.cjs as the first domain module using the handle(command, args, cwd) => boolean pattern.

Pattern

Each extraction follows the established routing pattern:

// In json-helper.cjs — lazy-loaded, routed before the main switch
if (op === 'some-operation') {
  const someOps = require('./lib/some-ops.cjs');
  if (someOps.handle(op, args, process.cwd())) {
    process.exit(0);
  }
}

Extraction Candidates

Logical groupings by domain:

  • Learning operationsprocess-observations, render-ready, reconcile-manifest, merge-observation, temporal-decay, filter-observations, learning-created, learning-new
  • Knowledge operationsknowledge-append, read-sidecar (done)
  • Session/memory operationssession-output, prompt-output, backup-construct
  • JSON utilitiesget-field, get-field-file, validate, compact, update-field, update-fields, construct

Acceptance Criteria

  • Each extracted module follows handle(command, args, cwd) => boolean
  • Lazy-loaded via conditional require() — no eager top-level imports
  • All existing tests pass without modification
  • json-helper.cjs shrinks proportionally with each extraction

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions