feat: v0.7.3 成本收口 · 状态一致 · 死账清理 — Prompt Cache 根治 + SSRF DNS Pinning + 87 用例扩充全量回归
P1 修复面收口: Prompt Cache 根治(日期/记忆/附件三类易变内容出 system 入用户消息 前置块 user-context.ts, system 跨 run 字节级稳定; Anthropic system 块数组化 + cache_control ephemeral 断言, DeepSeek 自动缓存前缀命中 — 多轮对话输入 token 成本降数量级); 编辑重发/重新生成幽灵 Trace 双侧根治(DB truncateMessagesAfter 同步过滤 metadata.traceSteps + 前端 trimTraceStepsByAnchor 镜像, 严格小于锚点 时间戳, 同毫秒等值判废); sessions:deleteMessage 死通道全链路删除(渲染层零调用 + message_count 漂移面); Ollama vision 能力门控全链路(MetonaModelInfo .supportsVision 贯穿 adapter/IPC/store/UI, model-capabilities.ts 三道判定纯函数, 未知保守放行); 记忆固化节流(consolidation-policy 纯函数: 总开关 + 内容门控 [回答>=200字符或存在成功工具调用] + 会话级 10 分钟频率窗口, 三 memory.* 配置键) P2 安全纵深: SSRF DNS Pinning 关闭 rebinding 窗口(ssrf-guard 重构 resolvePublicAddresses 单源; ssrf-dispatcher 以 undici Agent.connect.lookup 钉死校验 IP, TLS SNI 保持原域名, 一次性 dispatcher 用后即毁; 代理激活显式 退化为仅入口校验); web_fetch 重写手动逐跳重定向循环(每跳先校验后连接, 替代 redirect:follow 内核跟跳的中间跳裸奔, 上限 5 跳); http_request 换用 pinned fetch; web_search 可达性预检加固(私有 URL 零请求 + 不跟跳, 3xx 视为 可达); Agent 浏览器 CORS 通配收紧为 Origin 回显 + Vary: Origin; ConfirmationHook.forgetSession 会话终态清理(会话删除/abort 联动/SubAgent 终结三处接线, 根治 rememberedDecisions 泄漏) P3 架构还债: agent.enableReflection 死配置全链路接线(main→shared→引擎→ Orchestrator→设置开关, REFLECTING 状态真实可达); AgentLoopConfig.timeoutMs 死字段删除; MemoryManager.cleanupExpired 挂入健康检查周期(expires_at 回收 管道真实化); buildSafeEnv 收敛 utils/safe-env.ts 单源(run_command 与 MCP stdio 共用, 终结双实现漂移); Trace 生命周期治理(metadata 只保留最近 20 个 run — keepRecentRuns 纯函数; JSONL 录制启动自动清理保留 200 个 + 设置页 手动清理); SLO/健康快照可视化(app:healthSnapshot IPC + 设置页只读卡片 + 审计链一键校验) P4 能力演进: 会话标题 LLM 自动生成(TitleGenerator — 每会话幂等/并发重入复用 同一 Promise/自定义标题不覆盖/失败静默回退, Sidebar 经 config:changed 实时 刷新); MCP 自动重连(5s/15s/60s 退避最多 3 次, reconnecting 状态机, teardownConnection 内部拆除保留簿记 — 用户断开/开关关闭即时取消, 设置页 显示第 N/3 次); 死循环检测 ABAB 乒乓模式(最近4轮 A→B→A→B 交替判定, 补齐 docs 第五章"两状态反复切换"检测契约); i18n 第三阶段(ChatInput/LLMSettings/ OnboardingWizard/MemoryViewer 主链路文案出层, zh-CN + en-US 双字典补齐) 测试: 737 → 824 用例(+87, 新增 8 个测试文件 + 扩展 3 个)。新覆盖: user-context 分组/空值收缩/拼接契约、context-builder 字节级稳定性、Anthropic cache_control 四态、consolidation-policy 九路判定矩阵、ssrf-dispatcher(pinned lookup/重定向 解析/IP 校验)、forget-session 会话隔离、trace-lifecycle run 淘汰、 trace-trim 严格小于边界、safe-env 净化矩阵、mcp-reconnect 退避状态机 (fake timers)、title-generator 并发重入、SQLite 侧 truncate×TRACE 联动 (Electron ABI)。测试驱动修复: GIT_*/ 注释终止块注释、重连计数被自身重试 前置断开重置(拆 teardownConnection 保留簿记)、TitleGenerator 幂等占位与 并发去重的检查顺序竞态(去重先于幂等) 版本: 0.7.3; README 同步(配置表新增 agent.enableReflection/memory.*/mcp.autoReconnect) 回归: typecheck 双端 0 错误; ESLint 0/0; 系统 Node 771 通过 53 跳过 (better-sqlite3 ABI); Electron ABI 全量 824/824 零跳过
This commit is contained in:
@@ -27,8 +27,19 @@ import { ArrowRight, ArrowLeft, CheckCircle, Eye, EyeOff } from 'lucide-react';
|
||||
import { useUIStore } from '@renderer/stores/ui-store';
|
||||
import { useAgentStore } from '@renderer/stores/agent-store';
|
||||
import { PROVIDER_URLS } from '@renderer/components/settings/useConfig';
|
||||
// v0.7.3 P4-3: 文案出层(字典含注册副作用,须在 t() 使用前 import)
|
||||
import { t } from '@renderer/lib/i18n';
|
||||
import '@renderer/lib/i18n-strings';
|
||||
|
||||
const STEPS = ['欢迎', '配置 LLM', '自定义 Agent', '工作空间', '开始使用'];
|
||||
// v0.7.3 P4-3: 步骤文案渲染时求值(i18next 字典注册是异步的,模块顶层固化会拿到 key 本体)
|
||||
const STEP_KEYS = [
|
||||
'onboarding.step.welcome',
|
||||
'onboarding.step.llm',
|
||||
'onboarding.step.agent',
|
||||
'onboarding.step.workspace',
|
||||
'onboarding.step.done',
|
||||
] as const;
|
||||
const STEPS = STEP_KEYS.map((k) => k); // 供长度/索引判断
|
||||
|
||||
// #48 修复: Onboarding 进度持久化 key
|
||||
const ONBOARDING_PROGRESS_KEY = 'onboarding_progress';
|
||||
@@ -152,7 +163,7 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
if (r && !r.success) {
|
||||
console.error('[OnboardingWizard]', 'Batch config save failed:', r.error);
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(r.error ?? '配置保存失败,请重试'))
|
||||
.then((mod) => mod.default.error(r.error ?? t('onboarding.toast.saveFailed')))
|
||||
.catch(() => {});
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +188,11 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
console.error('[OnboardingWizard]', 'Failed to save configuration:', err);
|
||||
// 用户主动操作失败必须有反馈,否则向导不关闭、用户卡死
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(`保存配置失败:${(err as Error).message}`))
|
||||
.then((mod) =>
|
||||
mod.default.error(
|
||||
t('onboarding.toast.saveFailedWithReason', { message: (err as Error).message }),
|
||||
),
|
||||
)
|
||||
.catch(() => {});
|
||||
}
|
||||
};
|
||||
@@ -194,9 +209,9 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
alternativeLabel
|
||||
sx={{ '& .MuiStepLabel-label': { fontSize: 11 } }}
|
||||
>
|
||||
{STEPS.map((s) => (
|
||||
<Step key={s}>
|
||||
<StepLabel>{s}</StepLabel>
|
||||
{STEP_KEYS.map((key) => (
|
||||
<Step key={key}>
|
||||
<StepLabel>{t(key)}</StepLabel>
|
||||
</Step>
|
||||
))}
|
||||
</Stepper>
|
||||
@@ -219,21 +234,21 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
sx={{ width: 64, height: 64, mx: 'auto', mb: 2, borderRadius: 2 }}
|
||||
/>
|
||||
<Typography variant="h6" sx={{ mb: 1 }}>
|
||||
欢迎使用 MetonaAI Desktop
|
||||
{t('onboarding.welcome.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary', mb: 2 }}>
|
||||
生产级通用 AI Agent 智能体桌面应用,支持多轮对话、工具调用、记忆系统和 MCP 协议集成。
|
||||
{t('onboarding.welcome.body')}
|
||||
</Typography>
|
||||
<Typography variant="caption">让我们花 1 分钟完成初始配置。</Typography>
|
||||
<Typography variant="caption">{t('onboarding.welcome.hint')}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
{step === 1 && (
|
||||
<Box sx={{ width: '100%' }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
配置 LLM Provider
|
||||
{t('onboarding.llm.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary', mb: 2 }}>
|
||||
选择 Provider 并填写 API 信息。Base URL 和模型名称支持任意输入。
|
||||
{t('onboarding.llm.body')}
|
||||
</Typography>
|
||||
<Stack spacing={2}>
|
||||
<FormControl size="small">
|
||||
@@ -279,11 +294,11 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
/>
|
||||
<TextField
|
||||
size="small"
|
||||
label="API Key"
|
||||
label={t('llm.apiKey.label')}
|
||||
type={showKey ? 'text' : 'password'}
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
placeholder="sk-...(本地模型可留空)"
|
||||
placeholder={t('onboarding.llm.apiKey.placeholder')}
|
||||
slotProps={{
|
||||
input: {
|
||||
endAdornment: (
|
||||
@@ -299,7 +314,9 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
<TextField
|
||||
size="small"
|
||||
label={
|
||||
provider === 'ollama' ? '上下文长度 (num_ctx)' : '上下文窗口 (contextWindow)'
|
||||
provider === 'ollama'
|
||||
? t('onboarding.llm.ctx.ollama')
|
||||
: t('onboarding.llm.ctx.window')
|
||||
}
|
||||
type="number"
|
||||
value={contextWindow ?? ''}
|
||||
@@ -309,17 +326,17 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
}}
|
||||
placeholder={
|
||||
provider === 'ollama'
|
||||
? '默认由模型决定(如 2048、4096、128000)'
|
||||
: '如 64000、128000、1000000'
|
||||
? t('onboarding.llm.ctx.ollamaPlaceholder')
|
||||
: t('onboarding.llm.ctx.placeholder')
|
||||
}
|
||||
slotProps={{ htmlInput: { min: ctxMin, step: ctxMin } }}
|
||||
error={ctxError}
|
||||
helperText={
|
||||
ctxError
|
||||
? `最小值为 ${ctxMin}`
|
||||
? t('onboarding.llm.ctx.minError', { min: ctxMin })
|
||||
: provider === 'ollama'
|
||||
? ' '
|
||||
: '用于上下文压缩判断,不传给 API'
|
||||
: t('onboarding.llm.ctx.helper')
|
||||
}
|
||||
/>
|
||||
{/* v0.5.4: 多模态总开关 — 未开启时即使模型支持也不能上传图片 */}
|
||||
@@ -333,9 +350,9 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
}
|
||||
label={
|
||||
<Stack>
|
||||
<Typography variant="body2">启用多模态(图片输入)</Typography>
|
||||
<Typography variant="body2">{t('onboarding.llm.multimodal.label')}</Typography>
|
||||
<Typography variant="caption" sx={{ color: 'text.disabled' }}>
|
||||
开启后可在输入框上传图片;DeepSeek 需 vision 系列模型
|
||||
{t('onboarding.llm.multimodal.helper')}
|
||||
</Typography>
|
||||
</Stack>
|
||||
}
|
||||
@@ -347,10 +364,10 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
{step === 2 && (
|
||||
<Box sx={{ width: '100%' }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
自定义 Agent
|
||||
{t('onboarding.agent.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary', mb: 2 }}>
|
||||
编辑工作空间中的 SOUL.md 文件来定义 Agent 的身份和性格。
|
||||
{t('onboarding.agent.body')}
|
||||
</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
@@ -365,11 +382,10 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: '#e1e4ed' }}>SOUL.md</strong> — 定义 Agent
|
||||
的身份、性格、核心价值观
|
||||
<strong style={{ color: '#e1e4ed' }}>{t('onboarding.agent.soulLabel')}</strong>
|
||||
</div>
|
||||
<div style={{ marginTop: 8, fontSize: 11, opacity: 0.7 }}>
|
||||
此步骤可稍后在工作空间目录中完成。
|
||||
{t('onboarding.agent.soulHint')}
|
||||
</div>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -377,17 +393,17 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
{step === 3 && (
|
||||
<Box sx={{ width: '100%' }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
工作空间
|
||||
{t('onboarding.workspace.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary', mb: 2 }}>
|
||||
选择工作空间目录,或使用默认路径。
|
||||
{t('onboarding.workspace.body')}
|
||||
</Typography>
|
||||
<Stack direction="row" spacing={1} sx={{ mb: 2, alignItems: 'center' }}>
|
||||
<TextField
|
||||
size="small"
|
||||
value={workspacePath}
|
||||
onChange={(e) => setWorkspacePath(e.target.value)}
|
||||
placeholder="~/MetonaWorkspaces/default/"
|
||||
placeholder={t('onboarding.workspace.placeholder')}
|
||||
sx={{ flex: 1 }}
|
||||
/>
|
||||
<Button
|
||||
@@ -401,17 +417,17 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
} catch (err) {
|
||||
console.error('[OnboardingWizard]', err);
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error('选择文件夹失败'))
|
||||
.then((mod) => mod.default.error(t('onboarding.toast.folderFailed')))
|
||||
.catch(() => {});
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
选择文件夹
|
||||
{t('onboarding.workspace.pick')}
|
||||
</Button>
|
||||
</Stack>
|
||||
<Typography variant="caption" sx={{ color: 'text.secondary' }}>
|
||||
包含 SOUL.md、MEMORY.md 两个必需文件,首次打开时自动创建。
|
||||
{t('onboarding.workspace.helper')}
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
@@ -419,12 +435,12 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
<Box sx={{ textAlign: 'center' }}>
|
||||
<CheckCircle size={48} style={{ color: '#34d399', margin: '0 auto 16px' }} />
|
||||
<Typography variant="h6" sx={{ mb: 1 }}>
|
||||
配置完成!
|
||||
{t('onboarding.done.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ color: 'text.secondary', mb: 1 }}>
|
||||
MetonaAI Desktop 已准备就绪。开始与你的 AI Agent 对话吧!
|
||||
{t('onboarding.done.body')}
|
||||
</Typography>
|
||||
<Typography variant="caption">按 Ctrl+Enter 发送消息,输入 / 查看命令列表</Typography>
|
||||
<Typography variant="caption">{t('onboarding.done.hint')}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</DialogContent>
|
||||
@@ -445,7 +461,7 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
size="small"
|
||||
sx={{ color: 'text.secondary' }}
|
||||
>
|
||||
上一步
|
||||
{t('onboarding.prev')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
@@ -453,7 +469,7 @@ export function OnboardingWizard(): React.JSX.Element | null {
|
||||
onClick={handleNext}
|
||||
size="small"
|
||||
>
|
||||
{step === STEPS.length - 1 ? '开始使用' : '下一步'}
|
||||
{step === STEPS.length - 1 ? t('onboarding.finish') : t('onboarding.next')}
|
||||
</Button>
|
||||
</Box>
|
||||
</Dialog>
|
||||
|
||||
Reference in New Issue
Block a user