chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,62 +1,62 @@
|
||||
import { app } from "electron/main";
|
||||
import { app } from 'electron/main'
|
||||
|
||||
import { getProjectedAccountHealth } from "./account-health";
|
||||
import { getProcessMetricsSnapshot } from "./process-metrics";
|
||||
import { getCircuitBreakerState } from "./circuit-breaker";
|
||||
import { collectRecoverySnapshot } from "./crash-recovery";
|
||||
import { getKeepAlivePlan } from "./keep-alive";
|
||||
import { getLeaseManagerSnapshot } from "./lease-manager";
|
||||
import { getMonitorSchedulerSnapshot } from "./monitor-scheduler";
|
||||
import { getPublishSchedulerSnapshot } from "./publish-scheduler";
|
||||
import { getObservedRequestSnapshot } from "./network-observer";
|
||||
import { getHiddenPlaywrightSnapshot } from "./playwright-cdp";
|
||||
import { getRateLimiterSnapshot } from "./rate-limiter";
|
||||
import { getRuntimeControllerSnapshot } from "./runtime-controller";
|
||||
import { getSchedulerState } from "./scheduler";
|
||||
import { getSessionHandle, listSessionHandleSnapshots } from "./session-registry";
|
||||
import { getTransportSnapshot } from "./transport/api-client";
|
||||
import { describeVaultBackend } from "./vault";
|
||||
import { getHotViewPoolPolicy, listHotViews } from "./view-pool";
|
||||
import { normalizeAccountPlatformUid } from "../shared/account-identity";
|
||||
import { normalizeAccountPlatformUid } from '../shared/account-identity'
|
||||
import { getProjectedAccountHealth } from './account-health'
|
||||
import { getCircuitBreakerState } from './circuit-breaker'
|
||||
import { collectRecoverySnapshot } from './crash-recovery'
|
||||
import { getKeepAlivePlan } from './keep-alive'
|
||||
import { getLeaseManagerSnapshot } from './lease-manager'
|
||||
import { getMonitorSchedulerSnapshot } from './monitor-scheduler'
|
||||
import { getObservedRequestSnapshot } from './network-observer'
|
||||
import { getHiddenPlaywrightSnapshot } from './playwright-cdp'
|
||||
import { getProcessMetricsSnapshot } from './process-metrics'
|
||||
import { getPublishSchedulerSnapshot } from './publish-scheduler'
|
||||
import { getRateLimiterSnapshot } from './rate-limiter'
|
||||
import { getRuntimeControllerSnapshot } from './runtime-controller'
|
||||
import { getSchedulerState } from './scheduler'
|
||||
import { getSessionHandle, listSessionHandleSnapshots } from './session-registry'
|
||||
import { getTransportSnapshot } from './transport/api-client'
|
||||
import { describeVaultBackend } from './vault'
|
||||
import { getHotViewPoolPolicy, listHotViews } from './view-pool'
|
||||
|
||||
function minutesAhead(now: number, minutes: number): number {
|
||||
return now + minutes * 60_000;
|
||||
return now + minutes * 60_000
|
||||
}
|
||||
|
||||
function parseTimestamp(value: string | null | undefined): number | null {
|
||||
if (!value) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
const timestamp = Date.parse(value);
|
||||
return Number.isNaN(timestamp) ? null : timestamp;
|
||||
const timestamp = Date.parse(value)
|
||||
return Number.isNaN(timestamp) ? null : timestamp
|
||||
}
|
||||
|
||||
type RuntimeControllerSnapshot = ReturnType<typeof getRuntimeControllerSnapshot>;
|
||||
type RuntimeControllerAccount = RuntimeControllerSnapshot["accounts"][number];
|
||||
type RuntimeControllerSnapshot = ReturnType<typeof getRuntimeControllerSnapshot>
|
||||
type RuntimeControllerAccount = RuntimeControllerSnapshot['accounts'][number]
|
||||
|
||||
function createRuntimeAccountView(
|
||||
controller: RuntimeControllerSnapshot,
|
||||
account: RuntimeControllerAccount,
|
||||
context: {
|
||||
hotViews: ReturnType<typeof listHotViews>;
|
||||
primaryClientId: string;
|
||||
clientOnline: boolean;
|
||||
lastAccountsSyncAt: number;
|
||||
now: number;
|
||||
hotViews: ReturnType<typeof listHotViews>
|
||||
primaryClientId: string
|
||||
clientOnline: boolean
|
||||
lastAccountsSyncAt: number
|
||||
now: number
|
||||
},
|
||||
) {
|
||||
const sessionHandle = getSessionHandle(account.id);
|
||||
const isHot = context.hotViews.some((item) => item.accountId === account.id);
|
||||
const accountQueueDepth = controller.tasks.filter((task) =>
|
||||
task.accountId === account.id && ["queued", "in_progress"].includes(task.status),
|
||||
).length;
|
||||
const sessionHandle = getSessionHandle(account.id)
|
||||
const isHot = context.hotViews.some((item) => item.accountId === account.id)
|
||||
const accountQueueDepth = controller.tasks.filter(
|
||||
(task) => task.accountId === account.id && ['queued', 'in_progress'].includes(task.status),
|
||||
).length
|
||||
const projected = getProjectedAccountHealth({
|
||||
accountId: account.id,
|
||||
platform: account.platform,
|
||||
health: account.health,
|
||||
verifiedAt: account.verified_at,
|
||||
});
|
||||
})
|
||||
|
||||
return {
|
||||
id: account.id,
|
||||
@@ -72,31 +72,29 @@ function createRuntimeAccountView(
|
||||
syncVersion: account.sync_version,
|
||||
clientId: account.client_id ?? context.primaryClientId,
|
||||
partition: projected.partition || sessionHandle?.partition || `persist:acc-${account.id}`,
|
||||
sessionState: isHot ? "hot" : sessionHandle ? "warm" : "cold",
|
||||
lastSyncAt:
|
||||
context.lastAccountsSyncAt
|
||||
|| parseTimestamp(account.verified_at)
|
||||
|| context.now,
|
||||
sessionState: isHot ? 'hot' : sessionHandle ? 'warm' : 'cold',
|
||||
lastSyncAt: context.lastAccountsSyncAt || parseTimestamp(account.verified_at) || context.now,
|
||||
lastVerifiedAt: projected.lastVerifiedAt,
|
||||
lastProbeAt: projected.lastProbeAt,
|
||||
nextProbeAt: projected.nextProbeAt,
|
||||
queueDepth: accountQueueDepth,
|
||||
online: context.clientOnline,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function createRuntimeSnapshot() {
|
||||
return createLiveRuntimeSnapshot(getRuntimeControllerSnapshot());
|
||||
return createLiveRuntimeSnapshot(getRuntimeControllerSnapshot())
|
||||
}
|
||||
|
||||
export function createRuntimeAccountSnapshot(accountId: string) {
|
||||
const controller = getRuntimeControllerSnapshot();
|
||||
const now = Date.now();
|
||||
const primaryClientId = controller.client?.id ?? controller.session?.desktop_client?.id ?? "desktop-self";
|
||||
const clientOnline = controller.running && controller.lastHeartbeatStatus !== "failed";
|
||||
const account = controller.accounts.find((item) => item.id === accountId);
|
||||
const controller = getRuntimeControllerSnapshot()
|
||||
const now = Date.now()
|
||||
const primaryClientId =
|
||||
controller.client?.id ?? controller.session?.desktop_client?.id ?? 'desktop-self'
|
||||
const clientOnline = controller.running && controller.lastHeartbeatStatus !== 'failed'
|
||||
const account = controller.accounts.find((item) => item.id === accountId)
|
||||
if (!account) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
return createRuntimeAccountView(controller, account, {
|
||||
@@ -105,42 +103,44 @@ export function createRuntimeAccountSnapshot(accountId: string) {
|
||||
clientOnline,
|
||||
lastAccountsSyncAt: controller.lastAccountsSyncAt,
|
||||
now,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function createLiveRuntimeSnapshot(controller: RuntimeControllerSnapshot) {
|
||||
const now = Date.now();
|
||||
const now = Date.now()
|
||||
// Electron Session instances are not safe to ship across IPC to the renderer.
|
||||
const sessions = listSessionHandleSnapshots();
|
||||
const hotViews = listHotViews();
|
||||
const leaseManager = getLeaseManagerSnapshot();
|
||||
const rateLimiter = getRateLimiterSnapshot();
|
||||
const scheduler = getSchedulerState();
|
||||
const transport = getTransportSnapshot();
|
||||
const sessions = listSessionHandleSnapshots()
|
||||
const hotViews = listHotViews()
|
||||
const leaseManager = getLeaseManagerSnapshot()
|
||||
const rateLimiter = getRateLimiterSnapshot()
|
||||
const scheduler = getSchedulerState()
|
||||
const transport = getTransportSnapshot()
|
||||
|
||||
const primaryClientId = controller.client?.id ?? controller.session?.desktop_client?.id ?? "desktop-self";
|
||||
const primaryClientId =
|
||||
controller.client?.id ?? controller.session?.desktop_client?.id ?? 'desktop-self'
|
||||
const lastSeenAt =
|
||||
controller.lastHeartbeatAt
|
||||
|| parseTimestamp(controller.client?.last_seen_at)
|
||||
|| now;
|
||||
const clientOnline = controller.running && controller.lastHeartbeatStatus !== "failed";
|
||||
controller.lastHeartbeatAt || parseTimestamp(controller.client?.last_seen_at) || now
|
||||
const clientOnline = controller.running && controller.lastHeartbeatStatus !== 'failed'
|
||||
const queueDepth = controller.tasks.filter((task) =>
|
||||
["queued", "in_progress"].includes(task.status),
|
||||
).length;
|
||||
['queued', 'in_progress'].includes(task.status),
|
||||
).length
|
||||
|
||||
const clients = [
|
||||
{
|
||||
id: primaryClientId,
|
||||
label: "This device",
|
||||
deviceName: controller.client?.device_name ?? controller.session?.desktop_client?.device_name ?? "Current Desktop",
|
||||
label: 'This device',
|
||||
deviceName:
|
||||
controller.client?.device_name ??
|
||||
controller.session?.desktop_client?.device_name ??
|
||||
'Current Desktop',
|
||||
os: controller.client?.os ?? process.platform,
|
||||
status: clientOnline ? "online" : "offline",
|
||||
status: clientOnline ? 'online' : 'offline',
|
||||
lastSeenAt,
|
||||
queueDepth,
|
||||
heartbeat: clientOnline ? "healthy" : "stale",
|
||||
channel: controller.client?.channel ?? "dev",
|
||||
heartbeat: clientOnline ? 'healthy' : 'stale',
|
||||
channel: controller.client?.channel ?? 'dev',
|
||||
},
|
||||
] as const;
|
||||
] as const
|
||||
|
||||
const accounts = controller.accounts.map((account) =>
|
||||
createRuntimeAccountView(controller, account, {
|
||||
@@ -150,42 +150,44 @@ function createLiveRuntimeSnapshot(controller: RuntimeControllerSnapshot) {
|
||||
lastAccountsSyncAt: controller.lastAccountsSyncAt,
|
||||
now,
|
||||
}),
|
||||
);
|
||||
)
|
||||
|
||||
const tasks = controller.tasks.map((task) => ({ ...task }));
|
||||
const tasks = controller.tasks.map((task) => ({ ...task }))
|
||||
|
||||
const healthCounts = accounts.reduce<Record<string, number>>((acc, item) => {
|
||||
acc[item.health] = (acc[item.health] ?? 0) + 1;
|
||||
return acc;
|
||||
}, {});
|
||||
acc[item.health] = (acc[item.health] ?? 0) + 1
|
||||
return acc
|
||||
}, {})
|
||||
const blockingAccountCount = accounts.filter((item) =>
|
||||
["expired", "revoked", "challenge_required"].includes(item.authState),
|
||||
).length;
|
||||
['expired', 'revoked', 'challenge_required'].includes(item.authState),
|
||||
).length
|
||||
|
||||
return {
|
||||
generatedAt: now,
|
||||
app: {
|
||||
name: "省心推",
|
||||
name: '省心推',
|
||||
version: app.getVersion(),
|
||||
channel: process.env.NODE_ENV === "development" ? "dev" : "release",
|
||||
channel: process.env.NODE_ENV === 'development' ? 'dev' : 'release',
|
||||
platform: process.platform,
|
||||
sessionCount: sessions.length,
|
||||
hotViewCount: hotViews.length,
|
||||
},
|
||||
workspace: {
|
||||
id: `ws-${controller.client?.workspace_id ?? controller.session?.desktop_client?.workspace_id ?? "current"}`,
|
||||
name: `Workspace #${controller.client?.workspace_id ?? controller.session?.desktop_client?.workspace_id ?? "current"}`,
|
||||
strategy: controller.dispatchConnected ? "websocket-first / db-fallback" : "db-fallback / heartbeat recovery",
|
||||
id: `ws-${controller.client?.workspace_id ?? controller.session?.desktop_client?.workspace_id ?? 'current'}`,
|
||||
name: `Workspace #${controller.client?.workspace_id ?? controller.session?.desktop_client?.workspace_id ?? 'current'}`,
|
||||
strategy: controller.dispatchConnected
|
||||
? 'websocket-first / db-fallback'
|
||||
: 'db-fallback / heartbeat recovery',
|
||||
nextSweepAt: scheduler.nextPullAt ?? minutesAhead(now, 1),
|
||||
lastFullSyncAt: controller.lastAccountsSyncAt || now,
|
||||
},
|
||||
summary: {
|
||||
onlineClients: clients.filter((item) => item.status === "online").length,
|
||||
onlineClients: clients.filter((item) => item.status === 'online').length,
|
||||
accountsBound: accounts.length,
|
||||
queuedTasks: tasks.filter((item) => item.status === "queued").length,
|
||||
queuedTasks: tasks.filter((item) => item.status === 'queued').length,
|
||||
issuesOpen:
|
||||
tasks.filter((item) => ["unknown", "failed"].includes(item.status)).length
|
||||
+ blockingAccountCount,
|
||||
tasks.filter((item) => ['unknown', 'failed'].includes(item.status)).length +
|
||||
blockingAccountCount,
|
||||
healthCounts,
|
||||
},
|
||||
clients,
|
||||
@@ -222,5 +224,5 @@ function createLiveRuntimeSnapshot(controller: RuntimeControllerSnapshot) {
|
||||
processMetrics: getProcessMetricsSnapshot(),
|
||||
vault: describeVaultBackend(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user