feat(account): add quota trend chart and multi-account risk gate

- Gate multi-account login, import, switch, backup quota polling, and vault controls behind explicit risk consent (accountSwitchRiskAccepted), restricting unaccepted sessions to active-account quota viewing
- Add collinear-compressed per-account quota history tracking and a full-bleed 184px AccountQuotaTrendCard supporting cycle, preset, all-time, and custom ranges with cycle-boundary pre-reset filtering and isolated impulse spike sanitization
- Unify Account tab controls onto shared SegmentedControl, CustomSelect, CustomDateTimePicker, .ctx-risk-mask, and global status/button primitives while removing bespoke .account-* CSS and balancing card padding
This commit is contained in:
fish
2026-11-25 03:42:33 +09:00
parent 1330b31ef7
commit e520efe84e
20 changed files with 4103 additions and 1235 deletions
+56 -3
View File
@@ -9,6 +9,10 @@
import { randomUUID } from 'node:crypto';
import { isDeepStrictEqual } from 'node:util';
import { BRIDGE_API_ROUTE_DEFS, LOCAL_ENDPOINT_ID } from '../shared/window-bridge-protocol.mjs';
import {
getAccountQuotaHistoryPayload,
getLatestRecordedHostEmail,
} from './account-quota-history.mjs';
import { handleAccountCredentialAction, warmAccountPublicListCache } from './account-switch.mjs';
import { issueAccountActionNonce, verifyAccountActionNonce } from './account-vault-crypto.mjs';
import {
@@ -644,6 +648,38 @@ export async function executeAccountCredentialAction(data, opts = {}) {
}
const cleanData = stripEndpointField(data);
const action = cleanData?.action || 'list';
const riskAccepted =
opts?.bypassRiskCheck === true || loadSettings().accountSwitchRiskAccepted === true;
if (!riskAccepted) {
if (action !== 'list') {
return {
status: 200,
contentType: 'application/json',
headers: { 'Cache-Control': 'no-store' },
body: JSON.stringify({
error: 'riskNotAccepted',
actionNonce: issueAccountActionNonce(),
}),
};
}
const hostEmail = getLatestRecordedHostEmail();
return {
status: 200,
contentType: 'application/json',
headers: { 'Cache-Control': 'no-store' },
body: JSON.stringify({
supported: process.platform === 'win32',
riskLocked: true,
accounts: [],
selectedEmail: '',
quotas: {},
quotaHistory: getAccountQuotaHistoryPayload({
allowedEmails: hostEmail ? [hostEmail] : [],
}),
actionNonce: issueAccountActionNonce(),
}),
};
}
if (NONCE_PROTECTED_ACCOUNT_ACTIONS.has(action) && !verifyAccountActionNonce(cleanData?.actionNonce)) {
return {
status: 200,
@@ -663,9 +699,25 @@ export async function executeAccountCredentialAction(data, opts = {}) {
if (action === 'switch' && !result?.error) {
clearTelemetryBuilderMemo(LOCAL_ENDPOINT_ID);
}
const hostEmail = getLatestRecordedHostEmail();
const allowedHistoryEmails = Array.isArray(result?.accounts)
? [...new Set([...result.accounts, ...(hostEmail ? [hostEmail] : [])])]
: hostEmail
? [hostEmail]
: null;
const enriched =
result && typeof result === 'object'
? { ...result, actionNonce: issueAccountActionNonce() }
? {
...result,
...(action === 'list' || Array.isArray(result.accounts)
? {
quotaHistory: getAccountQuotaHistoryPayload({
allowedEmails: allowedHistoryEmails,
}),
}
: {}),
actionNonce: issueAccountActionNonce(),
}
: result;
return {
status: 200,
@@ -904,8 +956,9 @@ export function bootWindowBridgeRuntime({ allowDynamicLs = false, onRestart = nu
if (lsRuntimeEndpoint.addr === 'test.invalid') return null;
if (!allowDynamicLs && !lsRuntimeEndpoint.addr) return null;
ensureCliStatusLineConfigured({ enabled: loadSettings().enableCliStatusLine !== false });
if (allowDynamicLs) {
const bootSettings = loadSettings();
ensureCliStatusLineConfigured({ enabled: bootSettings.enableCliStatusLine !== false });
if (allowDynamicLs && bootSettings.accountSwitchRiskAccepted === true) {
setTimeout(() => {
void warmAccountPublicListCache();
}, 80).unref?.();