refactor: package code organization (god-file peels, wave 1)#2139
Conversation
|
Warning Review limit reached
Next review available in: 26 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis change documents a multi-wave package refactor, splits core type contracts into domain modules, extracts heartbeat prompts and executor helpers, updates TaskStore imports, adds executor edge-case tests, and refreshes line-count baselines while retaining compatibility re-exports. ChangesPackage organization refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md (1)
43-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSpecify the required FNXC comment format.
As per coding guidelines, FNXC comments must begin with
FNXC:Area-of-productand include the change date inyyyy-MM-dd-hh:mmformat. It would be helpful to explicitly mention this format here to ensure implementers adhere to it during extraction.📝 Proposed update
-- R4. FNXC requirement comments move with the owning behavior (dated, greppable). Facades must not keep the only copy of requirement text after extraction. +- R4. FNXC requirement comments move with the owning behavior (must begin with `FNXC:Area-of-product` and include the date in `yyyy-MM-dd-hh:mm` format). Facades must not keep the only copy of requirement text after extraction.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md` around lines 43 - 44, Update the R4 requirement in the refactor plan to specify that moved FNXC comments must begin with “FNXC:Area-of-product” and include the change date in yyyy-MM-dd-hh:mm format, while retaining the requirement that comments move with their owning behavior and facades do not retain the only copy.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/engine/src/agent-heartbeat.ts`:
- Around line 457-470: Remove the unused constants from the import block in
agent-heartbeat.ts, including HEARTBEAT_CRITICAL_RULES,
HEARTBEAT_SYSTEM_PROMPT_NO_TASK, and HEARTBEAT_PROCEDURE, while retaining only
imports referenced locally in the file.
In `@packages/engine/src/executor.ts`:
- Around line 287-293: Remove the unused local imports
AGENT_BROWSER_NAVIGATION_SKILL_ID, probeAgentBrowserAvailability, and
formatAgentBrowserAvailabilityLog from the executor.ts import block, while
preserving the public re-exports and the still-used
augmentSessionSkillsForBrowserStep import.
In `@packages/engine/src/executor/requeue-loop.ts`:
- Around line 69-94: Update isTransientMissingTaskJsonError and
TRANSIENT_WORKTREE_TASK_JSON_ENOENT_PATTERN to support both POSIX and Windows
path separators when matching task.json ENOENT messages. Replace the hard-coded
`${normalizedWorktree}/` prefix check with separator-agnostic path containment,
preferably using path.relative(), while preserving task ID and worktree
validation.
---
Nitpick comments:
In `@docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md`:
- Around line 43-44: Update the R4 requirement in the refactor plan to specify
that moved FNXC comments must begin with “FNXC:Area-of-product” and include the
change date in yyyy-MM-dd-hh:mm format, while retaining the requirement that
comments move with their owning behavior and facades do not retain the only
copy.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fb30d568-dbbb-4778-8a1c-f76da165fe44
📒 Files selected for processing (17)
docs/plans/2026-07-14-001-refactor-package-code-organization-plan.mdpackages/core/src/store.tspackages/core/src/task-store/task-commit-associations.tspackages/core/src/types.tspackages/core/src/types/board.tspackages/core/src/types/execution-and-ui.tspackages/core/src/types/merge-policy.tspackages/core/src/types/merge-queue.tspackages/core/src/types/workflow-steps.tspackages/engine/src/agent-heartbeat-prompts.tspackages/engine/src/agent-heartbeat.tspackages/engine/src/executor.tspackages/engine/src/executor/browser-probe.tspackages/engine/src/executor/pseudo-pause.tspackages/engine/src/executor/requeue-loop.tspackages/engine/src/executor/workflow-step-failures.tsscripts/line-count-baseline.json
c1eb39c to
2e6ce0a
Compare
Add multi-wave god-file organization plan. U1 baseline hygiene: prune graduated/stale ceilings (db.ts), tighten store.ts to live thin-facade size, and one-time re-ratchet organic growth so check:line-count is truthful.
Extract board, merge-queue, execution/UI, merge-policy, and workflow-step domains while keeping types.ts as the browser-safe @fusion/core Vite alias with local imports so residual interfaces still resolve. Ratchet types.ts ceiling to live LOC.
Move browser probe, requeue-loop signatures, pseudo-pause/handoff detectors, and clearTerminalWorkflowStepFailures into executor/* satellites with re-exports from executor.ts for stable test imports.
Rename task-store/remaining-ops-9 to task-commit-associations (U3 first domain migration). Extract agent-heartbeat system prompts/procedures into agent-heartbeat-prompts.ts with stable re-exports (U6 slice).
Remove dual-home monofile body so executor imports the satellite module as the sole implementation, matching browser/requeue/pseudo-pause peels.
ESLint no-unused-vars failed on symbols imported only for re-export. Keep export-from for public API; import only symbols used in monofile bodies.
2e6ce0a to
a911eb1
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/engine/src/executor/requeue-loop.ts (1)
18-26: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrevent implicit
TypeErrorduring JSON parsing.If
signatureis the string"null",JSON.parsereturnsnull. Accessing.terminalStepCountonnullthrows aTypeError, which is then implicitly caught by the block to returnnull. While functionally correct, explicitly checking fornullor non-object types is safer and avoids relying on exceptions for normal control flow.♻️ Proposed refactor
function parseExecuteRequeueLoopProgressSignature(signature: string | null | undefined): { terminalStepCount: number; totalSteps: number } | null { if (!signature) return null; try { - const parsed = JSON.parse(signature) as { terminalStepCount?: unknown; totalSteps?: unknown }; + const parsed = JSON.parse(signature) as Record<string, unknown> | null; + if (!parsed || typeof parsed !== "object") return null; if (typeof parsed.terminalStepCount !== "number" || typeof parsed.totalSteps !== "number") return null; return { terminalStepCount: parsed.terminalStepCount,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/engine/src/executor/requeue-loop.ts` around lines 18 - 26, Update parseExecuteRequeueLoopProgressSignature to validate that the JSON.parse result is a non-null object before accessing terminalStepCount or totalSteps; return null for primitive, array, or null results, while preserving the existing numeric-field validation and parsed progress return.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/engine/src/executor/requeue-loop.ts`:
- Around line 18-26: Update parseExecuteRequeueLoopProgressSignature to validate
that the JSON.parse result is a non-null object before accessing
terminalStepCount or totalSteps; return null for primitive, array, or null
results, while preserving the existing numeric-field validation and parsed
progress return.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: eb9ff444-35c0-48f5-9e5f-843fc51c4205
📒 Files selected for processing (18)
docs/plans/2026-07-14-001-refactor-package-code-organization-plan.mdpackages/core/src/store.tspackages/core/src/task-store/task-commit-associations.tspackages/core/src/types.tspackages/core/src/types/board.tspackages/core/src/types/execution-and-ui.tspackages/core/src/types/merge-policy.tspackages/core/src/types/merge-queue.tspackages/core/src/types/workflow-steps.tspackages/engine/src/__tests__/executor-missing-task-json-transient.test.tspackages/engine/src/agent-heartbeat-prompts.tspackages/engine/src/agent-heartbeat.tspackages/engine/src/executor.tspackages/engine/src/executor/browser-probe.tspackages/engine/src/executor/pseudo-pause.tspackages/engine/src/executor/requeue-loop.tspackages/engine/src/executor/workflow-step-failures.tsscripts/line-count-baseline.json
🚧 Files skipped from review as they are similar to previous changes (12)
- packages/core/src/store.ts
- packages/core/src/types/board.ts
- packages/core/src/task-store/task-commit-associations.ts
- scripts/line-count-baseline.json
- packages/core/src/types/execution-and-ui.ts
- packages/core/src/types/merge-queue.ts
- packages/engine/src/executor/workflow-step-failures.ts
- packages/engine/src/executor.ts
- packages/core/src/types.ts
- packages/core/src/types/merge-policy.ts
- packages/engine/src/agent-heartbeat.ts
- packages/core/src/types/workflow-steps.ts
…llites (#2143) ## Summary Wave 2 of package code organization (follows merged #2139): peel pure/satellite clusters out of `packages/engine/src/merger.ts` while keeping `merger.js` import paths stable for tests and production. - **`merger-glob.ts`** — `ConflictType`, `LOCKFILE_PATTERNS`, `GENERATED_PATTERNS`, `matchGlob` - **`merger-workspace-test-commands.ts`** — pnpm workspace package mapping + `inferDefaultTestCommand` / scoped + file-scoped test command derivation - **`merger-file-scope.ts`** — `parseDiffStat`, `extractFileScope` / `matchesScope`, squash file-scope invariant (`FileScopeViolationError`, assert/enforce with main’s `status` audit semantics and merge-trait modes) - Re-exports from `merger.ts`; baseline ratchet for `merger.ts` (~12.5k → ~11.8k) ## Test plan - [x] `pnpm --filter @fusion/engine exec tsc --noEmit` - [x] eslint on merger + satellites - [x] `merger-file-scope-invariant.test.ts` (18 tests) - [x] focused conflict-resolution pattern tests - [ ] CI merge gate ## Plan Continues `docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md` (U6 merger satellites). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added file-scope validation for merge operations, with strict and warning-only enforcement options. * Added automatic classification of lockfile and generated-file conflicts. * Added workspace-aware test selection based on changed packages and files. * Added support for inferring test commands across pnpm, Yarn, Bun, and npm projects. * **Refactor** * Organized merge, conflict-resolution, file-scope, and test-inference functionality into dedicated modules without changing existing public access paths. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Summary Waves 3–5 of package code organization (plan: `docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md`). Behavior-preserving peels after #2139 and #2143. ### Wave 3 — Merger + heartbeat recovery - **`merger-errors.ts`** — verification/abort error classes - **`merger-owned-landed.ts`** — ownership classification + `Fusion-Task-Id` trailer - **`merger-conflict-resolution.ts`** — conflict classify/auto-resolve - **`agent-heartbeat-error-recovery.ts`** — durable error-recovery budget helpers ### Wave 4 — Self-healing + dashboard API - **`self-healing-constants.ts`** — public timing/budget constants - **`self-healing-branch.ts`** — `isBranchAheadOfBase` - **`app/api/client.ts`** — `api` / `ApiRequestError` / `buildApiUrl` / `proxyApi` - **`app/api/health.ts`** — health, engine status, updates + `withProjectId` ### Wave 5 — Types tracking + merger parse + task CRUD - **`types/task-tracking.ts`** — PR/issue/GitHub/GitLab tracking contracts - **`merger-git-parse.ts`** — `parseFailingFilesFromOutput`, `parsePorcelainZ`, `parseShortstatSummary` - **`app/api/tasks.ts`** — task list/detail/create/update/move client surface - Line-count baselines ratcheted down for `merger.ts`, `types.ts`, `legacy.ts` Public import paths stay on parent modules / `legacy.ts` / package barrels via re-exports. ## Test plan - [x] core/engine/dashboard typecheck (including `tsconfig.app.json`) - [x] eslint on touched modules - [x] `parse-porcelain-z` + merger parseFailing/getBranchChanged tests - [x] dashboard `api-tasks` + legacy-prinfo/pr-types (69) - [ ] CI merge gate <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added dashboard API support for task listing/detail, archiving, creation, review updates, duplicate detection, bulk model updates, moving tasks, and overlap repair. - Added health/engine status and refresh/start controls, plus update checking. - **Bug Fixes** - Improved dashboard API handling for non-JSON/HTML responses with clearer errors, better URL routing for remote nodes, and project-scoped queries. - Strengthened automated recovery for heartbeat error/model-unavailable scenarios and safer merge-conflict classification/auto-resolution. - **Tests** - Updated merge-conflict resolution and lifecycle test mocks to match the updated git command behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
First wave of package-internal code organization: split oversized modules into domain-named files/folders while preserving public import paths via re-exports, and refresh the line-count ratchet scoreboard.
docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md(multi-wave program; this PR lands U1–U4 + first U3/U6 slices)types.tsintotypes/{board,merge-queue,execution-and-ui,merge-policy,workflow-steps}.tswith browser-safe Vite alias preservedremaining-ops-9→task-commit-associations(domain-named, not ordinal dump)executor/{browser-probe,requeue-loop,pseudo-pause,workflow-step-failures}.tsagent-heartbeat-prompts.tsDeferred to follow-up PRs (plan U5, U7–U9 + remaining waves)
legacy.ts/ routes / UI monofilesTest plan
pnpm --filter @fusion/core exec tsc --noEmitpnpm --filter @fusion/engine exec tsc --noEmitdetect-pseudo-pause,executor-browser-verification,clear-terminal-workflow-step-failuresnode scripts/check-file-line-count.mjsclean against updated baselineResidual Review Findings
None. Review autofix applied dual-home wiring for
clearTerminalWorkflowStepFailuresonly.Summary by CodeRabbit