Skip to content

refactor(framework): quality pass over the rest of the package#616

Merged
suleimansh merged 17 commits into
mainfrom
suleimansh/refactor/framework-whole-package
Jul 16, 2026
Merged

refactor(framework): quality pass over the rest of the package#616
suleimansh merged 17 commits into
mainfrom
suleimansh/refactor/framework-whole-package

Conversation

@suleimansh

Copy link
Copy Markdown
Member

Rom-method quality pass over the rest of @gemstack/framework, picking up where #615 (the big/complex files) left off. Every remaining file (~65) and every function was rated across 7 independent review slices before any edit; only the significant refactors were applied, one commit each, build + full suite green at each step (544 tests, 543 pass, 0 fail, unchanged from baseline). Behavior-preserving throughout: no public export removed, no user-facing string changed.

Net -17 lines across 36 files.

Duplication folded to one (DRY)

What was duplicated old -> new commit
The five *-preset.ts files: identical render body + params shape x5, now derived from one definePreset 4 -> 8 553c14b
The drivers' emit / signal-filter / framing-combine / readCode (copied across claude-code, codex, fake) -> driver/session-support.ts 6 -> 8 0f7b983
dashboard-rpc context accessors (4x try/getContext) + projectPath (defined 2x, inlined once) -> fromContext + resolveProjectPath 6 -> 8 ed380d4
reads.telefunc resolve+guard+catch skeleton (x8 uniform readers) -> withProject 7 -> 8 98c515f
Overview's private readLiveMeta was a byte copy of the store's 5 -> 8 69d69e5
Two static servers, two content-type maps that had drifted -> one table 7 -> 8 c66d0b0
Backlog loop's empty-finish written verbatim twice -> one finishEmpty 6 -> 8 a41756e
--vanilla built-in/docs decision spelled two ways -> one boolean 6 -> 8 500daa8

Seams (right side of the boundary)

Move old -> new commit
Terminal formatter + session-link plumbing out of events.ts (a data module now); the formatter is its own surface, paralleling run-view.ts 7 -> 8 316cf14
onEvents Channel lifecycle into stream-channel.ts (the file named for it); onEvents reads as "stream from this source" 6 -> 8 11ea07f
isSameOriginRequest down into its only caller + shared request/result types into a leaf dashboard/types.ts, breaking the server <-> telefunc-serve import cycle 8 -> 9 27b5b82

Altitude / simplify

Change old -> new commit
startDashboard: early-return the broken-install 503 stub, so the main path drops the triple clientBundleDir gate and the telefuncMount! non-null assertion 7 -> 8 30bd2a6
makeTelefuncMount: one request-context object instead of 7 positional args (callers no longer pass an undefined placeholder) 6 -> 8 00a4a67
Inline the single-call promptItem, dropping its re-declared deps type 5 -> 8 5ff2aa3
Drop the provably-dead LOGS.md existence re-check on install 7 -> 8 682345d

Coverage checklist

100% of the remaining package was rated before editing, in 7 slices. Each slice produced a per-file + per-function rating list and a tick list to prove nothing was skipped.

  • ✅ run / lifecycle: index, todo-loop, maintenance, control, agent, sandbox, preflight, host-exec
  • ✅ events / telemetry: events, relay, preview, logs, run-view, jsonl-tail
  • ✅ system-prompt / presets / config: system-prompt, system-prompt-file, prompt-template, presets, config, the five *-preset
  • ✅ quota / install / fs: quota-poller, consumption-guard, usage, update-check, install, project, fake-script, node-fs, client
  • driver/: claude-code, types, codex, claude-code-quota, fake, child-registry, index
  • dashboard/: server, dashboard, telefunc-serve, projects, overview, quota, docs, git-status, open-in-app, static, queue, file-status, github, bundle, index
  • dashboard-rpc/ + store/index: the 6 *.telefunc, context, register, stream-channel, events-tail, index

Ratings clustered 4-9 (the five preset files were the one 4). Nothing rated a lazy 10.

Considered, deliberately not done

Kept out to honor "significant only" and behavior-preserving:

  • nodeMaintenanceFs / the RegistryFs+MaintenanceFs merge: these fight the deliberate four-factory node-fs convention (refactor(framework): one node:fs adapter behind the four factories #584) and would couple two contracts that only happen to coincide today.
  • Relocating GitRunner out of project.ts: wide churn (7 importers) for low payoff.
  • Deleting the five unused *_PRESET_NAME exports: they are public API; folded into the definePreset table instead of removed.
  • Merging the two static servers into one flag-driven serveFile: their policies genuinely differ (SPA-fallback + immutable cache + buffered read vs 403 + streamed), so only the content-type table was shared.

Deferred: behavior-changing fixes (need changesets, separate PRs)

Surfaced by the review but out of scope for a behavior-preserving refactor:

  • relay.ts ingestBody decodes per-chunk (multibyte UTF-8 can corrupt at a chunk boundary) and caps on UTF-16 length, not bytes.
  • claude-code parseUsage sets costUsd: 0 when the line has usage but no cost, violating the DriverUsage contract ("omit, never 0") and diverging from codex.
  • runAgentCli emits a spurious error event after an abort already rejected the turn.
  • preferences savePreferences rejects on a failed write instead of returning the advertised { ok: false }.

No changeset: refactor only.

@suleimansh suleimansh self-assigned this Jul 16, 2026
@suleimansh
suleimansh merged commit e119136 into main Jul 16, 2026
2 checks passed
@suleimansh
suleimansh deleted the suleimansh/refactor/framework-whole-package branch July 16, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant