## 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.ts` → `types/agents.ts` (delete-when: consumers import agents domain directly) - `legacy.ts` → peels above (delete-when: dashboard imports domain modules) - `remaining-ops-8` → `workflow-definitions` (rename complete) ## Test plan - [x] `@fusion/core` typecheck - [x] eslint on peeled dashboard API modules - [x] `pnpm check:line-count` - [x] `agent-permissions` + `agent-permission-policy` tests - [x] `plugin-setup-api` tests - [ ] CI merge gate <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
159 lines
5.0 KiB
TypeScript
159 lines
5.0 KiB
TypeScript
/**
|
|
* FNXC:CodeOrganization 2026-07-18-14:00:
|
|
* Command Center System panel client API peeled from legacy.ts.
|
|
*/
|
|
import { api } from "./client.js";
|
|
import { withProjectId } from "./health.js";
|
|
|
|
// ── System Panel (Command Center → System) ──────────────────────────────────
|
|
|
|
/*
|
|
FNXC:SystemPanel 2026-07-12-11:35:
|
|
Typed client for the /api/system operator controls: capability discovery,
|
|
in-place restart, rebuild jobs with streamed output, engine/agent restarts,
|
|
plugin reload, and the host-process log viewer.
|
|
*/
|
|
|
|
/*
|
|
FNXC:SystemPanelFnBinary 2026-07-15-09:54:
|
|
Job snapshots cover rebuild scopes and the fn-binary link-local / use-global
|
|
actions that stream into the same System panel log viewer.
|
|
*/
|
|
export interface SystemRebuildJobSnapshot {
|
|
id: string;
|
|
kind: "rebuild" | "fn-binary";
|
|
scope: "app" | "full" | "plugins" | "link-local" | "use-global";
|
|
restartAfter: boolean;
|
|
status: "running" | "succeeded" | "failed";
|
|
startedAt: number;
|
|
finishedAt?: number;
|
|
exitCode?: number | null;
|
|
error?: string;
|
|
restartScheduled?: boolean;
|
|
pluginsReloaded?: string[];
|
|
droppedLines: number;
|
|
lineCount: number;
|
|
lines?: SystemRebuildJobLine[];
|
|
}
|
|
|
|
export interface SystemRebuildJobLine {
|
|
i: number;
|
|
ts: number;
|
|
stream: "stdout" | "stderr" | "system";
|
|
text: string;
|
|
}
|
|
|
|
export interface SystemInfoResponse {
|
|
supervised: boolean;
|
|
restartSupported: boolean;
|
|
rebuildSupported: boolean;
|
|
/** True when the host is a Fusion source checkout (dev) — can build & link local fn. */
|
|
fnBinaryLinkLocalSupported?: boolean;
|
|
/** Always true when the route is wired; UI may still disable while a job runs. */
|
|
fnBinaryUseGlobalSupported?: boolean;
|
|
sourceWorkspaceRoot?: string;
|
|
logsSupported: boolean;
|
|
engineAvailable: boolean;
|
|
pluginReloadSupported: boolean;
|
|
pid: number;
|
|
uptimeSeconds: number;
|
|
nodeVersion: string;
|
|
platform: string;
|
|
arch: string;
|
|
memoryRssBytes: number;
|
|
activeRebuild: SystemRebuildJobSnapshot | null;
|
|
lastRebuild: SystemRebuildJobSnapshot | null;
|
|
}
|
|
|
|
export interface SystemLogEntryDto {
|
|
timestamp: string;
|
|
level: "info" | "warn" | "error";
|
|
message: string;
|
|
prefix?: string;
|
|
}
|
|
|
|
export function fetchSystemInfo(): Promise<SystemInfoResponse> {
|
|
return api<SystemInfoResponse>("/system/info");
|
|
}
|
|
|
|
export function requestSystemRestart(reason?: string): Promise<{ scheduled: boolean }> {
|
|
return api<{ scheduled: boolean }>("/system/restart", {
|
|
method: "POST",
|
|
body: JSON.stringify({ reason }),
|
|
});
|
|
}
|
|
|
|
export function startSystemRebuild(
|
|
scope: "app" | "full" | "plugins",
|
|
restart?: boolean,
|
|
): Promise<SystemRebuildJobSnapshot> {
|
|
return api<SystemRebuildJobSnapshot>("/system/rebuild", {
|
|
method: "POST",
|
|
body: JSON.stringify({ scope, restart }),
|
|
});
|
|
}
|
|
|
|
/*
|
|
FNXC:SystemPanelFnBinary 2026-07-15-09:54:
|
|
Client wrappers for System panel fn-binary actions. Both return a job snapshot
|
|
that the panel streams via /system/jobs/:id/stream (same path as rebuild).
|
|
*/
|
|
export function startFnBinaryLinkLocal(): Promise<SystemRebuildJobSnapshot> {
|
|
return api<SystemRebuildJobSnapshot>("/system/fn-binary/link-local", { method: "POST" });
|
|
}
|
|
|
|
export function startFnBinaryUseGlobal(): Promise<SystemRebuildJobSnapshot> {
|
|
return api<SystemRebuildJobSnapshot>("/system/fn-binary/use-global", { method: "POST" });
|
|
}
|
|
|
|
export function fetchCurrentSystemRebuild(): Promise<{ job: SystemRebuildJobSnapshot | null }> {
|
|
return api<{ job: SystemRebuildJobSnapshot | null }>("/system/rebuild/current");
|
|
}
|
|
|
|
export function restartSystemEngines(): Promise<{
|
|
restarted: string[];
|
|
failed: Array<{ projectId: string; error: string }>;
|
|
}> {
|
|
return api("/system/engine/restart", { method: "POST" });
|
|
}
|
|
|
|
export function restartAllSystemAgents(projectId?: string): Promise<{
|
|
restarted: string[];
|
|
failed: Array<{ agentId: string; error: string }>;
|
|
}> {
|
|
return api(withProjectId("/system/agents/restart-all", projectId), { method: "POST" });
|
|
}
|
|
|
|
export function reloadAllSystemPlugins(): Promise<{
|
|
reloaded: string[];
|
|
failed: Array<{ id: string; error: string }>;
|
|
}> {
|
|
return api("/system/plugins/reload-all", { method: "POST" });
|
|
}
|
|
|
|
export function fetchSystemLogs(limit?: number): Promise<{ entries: SystemLogEntryDto[] }> {
|
|
const suffix = limit ? `?limit=${limit}` : "";
|
|
return api<{ entries: SystemLogEntryDto[] }>(`/system/logs${suffix}`);
|
|
}
|
|
|
|
export type ResearchFindingPromotionInput = {
|
|
findingId: string;
|
|
sliceId: string;
|
|
title?: string;
|
|
description?: string;
|
|
acceptanceCriteria?: string;
|
|
triage?: boolean;
|
|
taskId?: string;
|
|
};
|
|
|
|
export function promoteResearchFinding(
|
|
runId: string,
|
|
input: ResearchFindingPromotionInput,
|
|
projectId?: string,
|
|
): Promise<{ runId: string; findingId: string; feature: { id: string; status: string; taskId?: string }; citations: string[]; reused: boolean }> {
|
|
return api(withProjectId(`/research/runs/${encodeURIComponent(runId)}/findings/${encodeURIComponent(input.findingId)}/promote`, projectId), {
|
|
method: "POST",
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|