Skip to content

refactor: package code organization wave 10 - #2328

Merged
gsxdsm merged 5 commits into
mainfrom
feature/code-organization-wave10
Jul 19, 2026
Merged

refactor: package code organization wave 10#2328
gsxdsm merged 5 commits into
mainfrom
feature/code-organization-wave10

Conversation

@gsxdsm

@gsxdsm gsxdsm commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Wave 10 of package code organization (plan: docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md), after #2274.

Peels

New module Parent
types/agents.ts types.ts (permissions, Agent entity, ratings, reflections, heartbeat run types)
app/api/missions.ts legacy.ts (hierarchy, assertions, validation, autopilot)
app/api/messaging.ts legacy.ts (mailbox, approvals, reflections/ratings, budget)
app/api/plugins-and-skills.ts legacy.ts
app/api/todo.ts legacy.ts
app/api/insights.ts legacy.ts
app/api/system-panel.ts legacy.ts
task-store/workflow-definitions.ts rename of remaining-ops-8

Mission interview SSE streams stay in legacy.ts until createResilientEventSource is shared.

Public paths stay stable via re-exports.

LOC

  • types.ts ~7101 → ~6165
  • legacy.ts ~10273 → ~8913

Shims

  • types.tstypes/agents.ts (delete-when: consumers import agents domain directly)
  • legacy.ts → peels above (delete-when: dashboard imports domain modules)
  • remaining-ops-8workflow-definitions (rename complete)

Test plan

  • @fusion/core typecheck
  • eslint on peeled dashboard API modules
  • pnpm check:line-count
  • agent-permissions + agent-permission-policy tests
  • plugin-setup-api tests
  • CI merge gate

Summary by CodeRabbit

  • New Features
    • Added typed dashboard API support for missions, milestones/features, validation loops, and autopilot.
    • Added insights browsing and management, including run triggering.
    • Added messaging/mailboxes and approvals, plus agent reflections, ratings, and budget controls.
    • Added plugins & skills management and discovery.
    • Added todo lists and items with reordering.
    • Added system monitoring controls: rebuilds/restarts, logs, and research finding promotion.
  • Improvements
    • Centralized agent-related type contracts for safer browser consumption.
    • Enhanced legacy API compatibility and improved AI session deletion error handling.

…ow-definitions

Behavior-preserving package organization after wave 9 (#2274):
- types/agents.ts: agent permissions, entity, ratings, reflections, heartbeat runs
- app/api: missions, messaging, plugins-and-skills, todo, insights, system-panel
- rename remaining-ops-8 → task-store/workflow-definitions.ts
Ratchet types.ts and legacy.ts line-count ceilings downward.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ca2a1ce1-70cb-45ca-8ea9-25e11657ca87

📥 Commits

Reviewing files that changed from the base of the PR and between 8c9f192 and 8bcad7c.

📒 Files selected for processing (1)
  • packages/dashboard/app/types/html2canvas.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/dashboard/app/types/html2canvas.d.ts

📝 Walkthrough

Walkthrough

The change extracts agent contracts and dashboard API domains into dedicated modules, preserves legacy exports through re-exports, rewires workflow-definition imports, adds typed clients for missions, insights, messaging, plugins, system operations, and todos, and updates supporting declarations and line-count baselines.

Changes

Core contract and workflow organization

Layer / File(s) Summary
Dedicated agent contracts
packages/core/src/types/agents.ts, packages/core/src/types.ts
Agent permissions, approvals, runtime configuration, asset helpers, configuration revisions, reflections, and performance models move into types/agents.ts; types.ts re-exports them.
Workflow-definition import wiring
packages/core/src/store.ts, packages/core/src/task-store/*
Workflow-definition operations and purge helpers now resolve from workflow-definitions.js, whose domain annotation is updated.

Dashboard API extraction

Layer / File(s) Summary
Mission and todo clients
packages/dashboard/app/api/missions.ts, packages/dashboard/app/api/todo.ts
Typed mission lifecycle, hierarchy, validation, assertion, triage, autopilot, and todo endpoints are implemented in satellite modules.
Insights client extraction
packages/dashboard/app/api/insights.ts
Insight and run retrieval, mutation, status, generation, and task-creation helpers are added.
Messaging, plugin, skill, and system clients
packages/dashboard/app/api/messaging.ts, packages/dashboard/app/api/plugins-and-skills.ts, packages/dashboard/app/api/system-panel.ts
Typed wrappers cover messaging, approvals, agent reflections and budgets, plugin and skill management, system controls, rebuilds, logs, and research-finding promotion.
Legacy API compatibility
packages/dashboard/app/api/legacy.ts
Existing exports are routed to satellite modules, mission interview APIs remain local, and AI-session deletion adds response-content validation and structured server errors.

Supporting updates

Layer / File(s) Summary
Type declarations and baselines
packages/dashboard/app/types/html2canvas.d.ts, scripts/line-count-baseline.json
Ambient html2canvas typings are added, and baseline counts are updated for affected core, dashboard, and engine files and tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • Runfusion/Fusion#2253: Related backend workflow-definition store changes in remaining-ops-8.ts and corresponding task-store behavior.
  • Runfusion/Fusion#2273: Overlaps with the workflow-selection and orphan-cleanup paths rewired here.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the refactor theme and accurately reflects the wave 10 package organization changes.
Docstring Coverage ✅ Passed Docstring coverage is 84.38% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/code-organization-wave10

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Wave 10 of the package code organization refactor: splits legacy.ts (~10k LOC → ~8.9k) and types.ts (~7.1k → ~6.2k) by extracting six new dashboard API domain modules and a new types/agents.ts file. remaining-ops-8.ts is also renamed to workflow-definitions.ts. All removed exports are preserved as re-exports (shims) so public paths remain stable.

  • packages/core/src/types/agents.ts — new 1126-line file holding agent permissions, entity, approval-request, and heartbeat types moved from types.ts; types.ts re-exports every value and type binding, preserving the @fusion/core surface.
  • Six new packages/dashboard/app/api/ modules (missions, messaging, plugins-and-skills, todo, insights, system-panel) — functions lifted verbatim from legacy.ts, which becomes a pure re-export barrel for each.
  • packages/dashboard/app/types/html2canvas.d.ts — ambient module declaration added to fix TS2307 resolution failures with moduleResolution: "bundler", intentionally omitting the upstream catch-all index signature to surface typos.

Confidence Score: 5/5

Safe to merge — this is a pure structural refactor with no logic changes, no new behavior, and complete re-export shims preserving all public paths.

Every moved function and type has a matching re-export in the originating file; value bindings and type-only bindings are correctly separated with export vs export type. The remaining-ops-8.ts rename is reflected in all four import sites. types/agents.ts imports only from ./agent-state.js, avoiding any circular dependency through types.ts.

No files require special attention.

Important Files Changed

Filename Overview
packages/dashboard/app/api/legacy.ts Converted from implementation file to shim barrel: strips ~1360 LOC of function bodies and re-exports them from six new domain modules. All removed exports have matching re-export blocks; SSE streams and AI-session helpers remain implemented inline as noted.
packages/core/src/types/agents.ts New file containing agent permissions, entity types, approval request types, and heartbeat types extracted from types.ts. Imports only from ./agent-state.js (no circular dep). All 1126 lines are pure type/const declarations moved verbatim from types.ts.
packages/core/src/types.ts Reduced ~936 LOC by moving agent-domain declarations into types/agents.ts. Replaces them with import + export and import type + export type re-exports, correctly separating runtime values (consts/functions) from pure types. Public API unchanged.
packages/core/src/task-store/workflow-definitions.ts Rename of remaining-ops-8.ts (R099 — 99% similarity). Content is identical; only the filename and module comment were updated. All four import sites (store.ts, remaining-ops-1/2/5.ts) updated to the new path.
packages/dashboard/app/api/missions.ts New file with 665 LOC of mission hierarchy, contract assertions, validation loop, and autopilot API functions lifted verbatim from legacy.ts. MilestoneValidationTelemetry is imported from mission-types.ts rather than @fusion/core, matching the original import path.
packages/dashboard/app/api/messaging.ts New file with 326 LOC for mailbox, approvals, reflections/ratings, and budget APIs peeled from legacy.ts. ApprovalRequestStatus is correctly sourced from @fusion/core (now in types/agents.ts via re-export).
packages/dashboard/app/types/html2canvas.d.ts New ambient module declaration for html2canvas to fix TS2307 resolution failures with moduleResolution: bundler. Correctly narrows Options to an explicit subset (no catch-all index signature) to prevent typo-hiding.
packages/core/src/store.ts Single-line change: import path updated from remaining-ops-8.js to workflow-definitions.js.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph consumers["Consumers"]
        DASH["Dashboard components"]
        ENGINE["@fusion/engine"]
    end

    subgraph legacy["Shim Layer (legacy.ts)"]
        LEGTS["legacy.ts\n(re-exports only)"]
    end

    subgraph newapi["New Dashboard API Modules"]
        MISSIONS["missions.ts"]
        MESSAGING["messaging.ts"]
        PLUGINS["plugins-and-skills.ts"]
        TODO["todo.ts"]
        INSIGHTS["insights.ts"]
        SYSPANEL["system-panel.ts"]
    end

    subgraph core["@fusion/core"]
        TYPES["types.ts\n(re-exports)"]
        AGENTST["types/agents.ts\n(permissions, Agent, ratings,\nreflections, heartbeat)"]
        WFD["task-store/workflow-definitions.ts\n(renamed from remaining-ops-8)"]
        STORE["store.ts"]
        ROP1["remaining-ops-1.ts"]
        ROP2["remaining-ops-2.ts"]
        ROP5["remaining-ops-5.ts"]
    end

    DASH --> LEGTS
    LEGTS --> MISSIONS
    LEGTS --> MESSAGING
    LEGTS --> PLUGINS
    LEGTS --> TODO
    LEGTS --> INSIGHTS
    LEGTS --> SYSPANEL

    MISSIONS --> AGENTST
    MESSAGING --> AGENTST
    TYPES --> AGENTST

    STORE --> WFD
    ROP1 --> WFD
    ROP2 --> WFD
    ROP5 --> WFD

    ENGINE --> TYPES
    TYPES -.->|"re-exports all\n(stable public API)"| AGENTST
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    subgraph consumers["Consumers"]
        DASH["Dashboard components"]
        ENGINE["@fusion/engine"]
    end

    subgraph legacy["Shim Layer (legacy.ts)"]
        LEGTS["legacy.ts\n(re-exports only)"]
    end

    subgraph newapi["New Dashboard API Modules"]
        MISSIONS["missions.ts"]
        MESSAGING["messaging.ts"]
        PLUGINS["plugins-and-skills.ts"]
        TODO["todo.ts"]
        INSIGHTS["insights.ts"]
        SYSPANEL["system-panel.ts"]
    end

    subgraph core["@fusion/core"]
        TYPES["types.ts\n(re-exports)"]
        AGENTST["types/agents.ts\n(permissions, Agent, ratings,\nreflections, heartbeat)"]
        WFD["task-store/workflow-definitions.ts\n(renamed from remaining-ops-8)"]
        STORE["store.ts"]
        ROP1["remaining-ops-1.ts"]
        ROP2["remaining-ops-2.ts"]
        ROP5["remaining-ops-5.ts"]
    end

    DASH --> LEGTS
    LEGTS --> MISSIONS
    LEGTS --> MESSAGING
    LEGTS --> PLUGINS
    LEGTS --> TODO
    LEGTS --> INSIGHTS
    LEGTS --> SYSPANEL

    MISSIONS --> AGENTST
    MESSAGING --> AGENTST
    TYPES --> AGENTST

    STORE --> WFD
    ROP1 --> WFD
    ROP2 --> WFD
    ROP5 --> WFD

    ENGINE --> TYPES
    TYPES -.->|"re-exports all\n(stable public API)"| AGENTST
Loading

Reviews (5): Last reviewed commit: "fix: drop html2canvas Options index sign..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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/dashboard/app/api/legacy.ts`:
- Around line 6844-6873: Import MissionWithHierarchy as a local type binding at
the top level of legacy.ts, while retaining its existing re-export in the export
type block. Update createMissionFromInterview to resolve its return type through
that local import.

In `@packages/dashboard/app/api/messaging.ts`:
- Around line 5-14: Add ParticipantType, MessageType, and MessageMetadata to the
existing type import from `@fusion/core` in messaging.ts, alongside the other
message-related contracts, so the module’s existing usages typecheck.

In `@packages/dashboard/app/api/plugins-and-skills.ts`:
- Around line 190-194: Import the dedupe helper from "./dedupe.js" in the module
containing fetchPluginUiSlots, so its existing dedupe(path, ...) call resolves
correctly without changing the function’s behavior.

In `@packages/dashboard/app/api/todo.ts`:
- Around line 21-60: Import TodoListCreateInput, TodoListUpdateInput,
TodoItemCreateInput, and TodoItemUpdateInput from `@fusion/core` in the todo API
module so the request payload annotations used by createTodoList,
updateTodoList, createTodoItem, and updateTodoItem resolve correctly.
🪄 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: babb012d-4e94-4fb8-9ef0-ea3e24f5dc73

📥 Commits

Reviewing files that changed from the base of the PR and between c95e08e and 72d2b4d.

📒 Files selected for processing (15)
  • packages/core/src/store.ts
  • packages/core/src/task-store/remaining-ops-1.ts
  • packages/core/src/task-store/remaining-ops-2.ts
  • packages/core/src/task-store/remaining-ops-5.ts
  • packages/core/src/task-store/workflow-definitions.ts
  • packages/core/src/types.ts
  • packages/core/src/types/agents.ts
  • packages/dashboard/app/api/insights.ts
  • packages/dashboard/app/api/legacy.ts
  • packages/dashboard/app/api/messaging.ts
  • packages/dashboard/app/api/missions.ts
  • packages/dashboard/app/api/plugins-and-skills.ts
  • packages/dashboard/app/api/system-panel.ts
  • packages/dashboard/app/api/todo.ts
  • scripts/line-count-baseline.json

Comment thread packages/dashboard/app/api/legacy.ts
Comment thread packages/dashboard/app/api/messaging.ts
Comment thread packages/dashboard/app/api/plugins-and-skills.ts
Comment thread packages/dashboard/app/api/todo.ts
gsxdsm added 3 commits July 18, 2026 17:10
- Import MissionWithHierarchy locally for createMissionFromInterview
- Import message contract types in messaging.ts
- Import dedupe for fetchPluginUiSlots
- Import todo create/update input types in todo.ts
export type re-exports from missions.ts do not create local bindings;
milestone/slice interview apply/skip handlers need the imports for typecheck.
Dashboard app typecheck failed with TS2307 on html2canvas under bundler
resolution on CI. Ship an ambient module under app/types so capture-screenshot
typechecks without relying on package typings resolution.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/dashboard/app/types/html2canvas.d.ts`:
- Around line 9-16: Remove the `[key: string]: unknown` index signature from the
`Options` type in the html2canvas declarations, leaving only the explicitly
supported option properties so typos and unsupported configuration keys are
rejected while optional fields remain supported.
🪄 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: 6f10cbf7-bb01-43ab-a70f-85d4f7f7cd56

📥 Commits

Reviewing files that changed from the base of the PR and between b0a1670 and 8c9f192.

📒 Files selected for processing (2)
  • packages/dashboard/app/api/legacy.ts
  • packages/dashboard/app/types/html2canvas.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/dashboard/app/api/legacy.ts

Comment thread packages/dashboard/app/types/html2canvas.d.ts Outdated
@gsxdsm

gsxdsm commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator Author

Automated fix: removed Options index signature from html2canvas ambient types per CodeRabbit.

@gsxdsm
gsxdsm merged commit 3bf7f92 into main Jul 19, 2026
7 checks passed
@gsxdsm
gsxdsm deleted the feature/code-organization-wave10 branch July 19, 2026 16:48
gsxdsm added a commit that referenced this pull request Jul 19, 2026
## Summary

Wave 11 of package code organization (continues #2328 / wave 10), after
syncing main into the wave10 stack.

### Peels

| New module | Parent |
|---|---|
| `app/api/event-source.ts` | resilient `EventSource` reconnect +
pagehide cleanup |
| `app/api/chat.ts` | chat sessions / rooms / streaming |
| `app/api/projects.ts` | multi-project management client |
| `app/api/agents.ts` | agent CRUD / soul / memory |
| `app/api/workflows.ts` | workflow definition client |
| `app/api/scheduling.ts` | automations + routines |
| `app/api/ai-text.ts` | text refine / import translate / subtasks |
| `app/api/ai-sessions.ts` | AI / planning session client +
`startKeepAlive` |
| `app/api/research.ts` | research + evals client |
| `task-store/branch-and-pr-entities.ts` | rename of `remaining-ops-6` |

Public paths stay stable via `legacy.ts` re-exports (`app/api.ts` →
`legacy`).

### LOC

- `legacy.ts` ~8921 → ~5670

### Shims

- `legacy.ts` → peels above (delete-when: dashboard imports domain
modules)
- `remaining-ops-6` → `branch-and-pr-entities` (rename complete)

## Test plan

- [x] eslint on peeled API modules + legacy
- [x] dashboard app typecheck (`app/api/*` clean)
- [x] core typecheck
- [x] `plugin-setup-api` tests
- [ ] CI merge gate

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Expanded dashboard APIs for agents, AI sessions, chat rooms/sessions,
research runs, projects, workflows, routines/automations, and
scheduling.
* Added AI text refinement/translation, planning title regeneration, and
streamed subtask breakdown with task creation.
* Introduced resilient server-sent-events streaming for chat and other
live updates.
* Added workflow export/import and workflow design support, plus scripts
and workflow configuration controls.
* Added research export and ability to attach research outputs to tasks.

* **Enhancements**
* Missions support clearing an auto-merge override back to project
defaults.
  * Subtasks can now include an optional priority when creating tasks.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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