P0 会话可靠性收口(根治"模型思考着会话就停止"): - P0-1 finish_reason 全链路贯通:DONE 事件与 IterationStep 新增 finishReason,OpenAI 共享 SSE / Anthropic message_delta.stop_reason / Ollama done_reason 三路采集,TRACE 层弃用硬编码 'stop' 记录真值 - P0-2 空响应守卫 + 降级重试:零产出流→可重试错误走退避;思考耗尽输出预算(reasoning-only + length)→自动关闭思考降级重试一次;仍失败→OUTPUT_LENGTH_EXCEEDED 结构化错误 + 故障转移;附带根治 abort 恰逢零工具调用轮被 COMPLETED 抢占的真实缺陷 - P0-3 思考×能力×预算三对齐:DeepSeek/MiMo/Agnes/Ollama 四家 supportsThinking=false 强制不发思考参数;小输出预算告警;设置页联动提示 - P0-4 渲染层可见性:截断/空完成/友好错误三类提示,i18n 全部出层 - P0-5 回归四件套:reasoning-only 终止判定、集成级空闲超时、504 引擎重试归类、思考中 abort→USER_INTERRUPT、P4-2 强制收尾路径 FEAT-1:LLM 设置新增「最大输出上限」——Provider 支持矩阵显隐 + 模型上限钳制提示 + 超限保存警告 + llm.maxTokens 热生效 P1 修复面收口: - 渲染层三缺陷根治:后台会话回放缓冲(2000 条/4MB 有界 + agent:getReplayState + 事件总线)+ abort 双层自愈 + sendMessage 收尾兜底 + 中断卡片清扫 - 工具 abort 信号全覆盖:web_search/web_fetch/http_request/code_search/git 系列/delegate_task 全部接入引擎中断;web_search 时间预算收敛(720s→≤240s);移除伪造 ToolExecutionContext 与死代码 - 安全:本地 Pinned CONNECT 代理根治浏览器通道 DNS rebinding(校验期 IP pinning,可注入 resolver 表测);配置 URL 域名解析深校验(DeepCheckSoftFailure 软失败);SSE 空 error 帧防御修复;Ollama generate/embed AbortSignal.any 合并 - 缺陷清单:UTF-16 BOM 读取、tmp 同毫秒碰撞(nanoid 后缀)、code_search JS 回退参数对称(case_sensitive/前后文独立)、list_directory include_node_modules、崩溃自愈退避(60s 窗 ≥3 次停 reload)、MemoryViewer/Sidebar i18n 收口 P2 能力演进: - 会话回收站:SCHEMA_VERSION 3 + 迁移 10(deleted_at,存在性守卫),软删除/恢复/彻底删除/30 天自动清理(启动+24h),searchMessages 聚合剔除,Sidebar 回收站面板 - 会话回放播放器:sessions:listRecordings/readRecording(白名单+目录边界+20MB 上限),SessionReplayPlayer 时间轴/步进/变速,Trace 面板入口 - electron-updater 自动更新:双轨(手动 feed 比对保留),生产环境启动静默检查 + update:status 广播 + app:updateInstall + LogsSettings UpdatePanel + builder publish 配置 - @ 文件提及:workspace.listFiles/readFileClip(边界/512KB/NUL 拒绝/MEMORY.md 保护),ChatInput Fuse 联想+键盘导航+附件管线注入 - MCP Resources/Prompts 发现:可选能力 try/catch 降级,mcp:listServerContents,MCPSettings 展开视图 - 文档对齐:内部 API 标准 HTML(Adapter 清单补 MiMo/已实现注记/STREAM_RESET/DONE.finishReason/ repetition_truncation 映射);README v0.8.0 亮点表 P3 测试基建: - 新增 4 个测试文件:engine-stream-contract(6)、engine-stream-reliability(4:集成空闲超时/504 重试/思考中 abort/P4-2 强制收尾)、thinking-capability-gate(7)、pinned-proxy(9,含深校验 5)、session-trash(5,DB 域)、use-agent-stream hook 级(5)、agent.test 回放缓冲(2) - 契约更新:orchestrator 被中断 SubAgent success=false(abort 优先级修复语义)、SSE 空 error 帧、UTF-16 正常读取、DeepSeek 未配置思考显式 disabled、迁移矩阵 v2→3 - 弱断言根治:registry WEBP 单向断言、hooks-contracts 自比恒真、memory 空 token 补强 全量验证:typecheck 0 错误 / lint 0 问题 / 系统 Node 2144 通过(301 DB 用例按 ABI 跳过)/ Electron ABI 2445/2445 全量通过 0 跳过
200 lines
7.4 KiB
TypeScript
200 lines
7.4 KiB
TypeScript
/**
|
||
* UpdateService — 轻量自动更新检查(v0.6.4 P4-2 引入,v0.8.0 P2-3 接入 electron-updater)
|
||
*
|
||
* 双轨设计:
|
||
* 1. 手动检查(check()):feed 比对式 —— 拉取版本清单 JSON 与当前版本比较,
|
||
* 结果经 IPC 直接返回(不依赖 electron-updater,dev 模式同样可用)。
|
||
* 2. 自动更新(startAutoUpdater,v0.8.0 P2-3):生产环境接入 electron-updater
|
||
* (generic provider),启动 5s 后静默检查;available → 广播 update:status +
|
||
* 系统通知;用户触发下载安装(app:updateInstall)→ downloadAndInstall 后重启。
|
||
* 未配置 feed / dev 模式 / electron-updater 不可用时静默禁用(可用性优先)。
|
||
*/
|
||
|
||
import log from 'electron-log';
|
||
|
||
export interface UpdateFeedInfo {
|
||
version: string;
|
||
url?: string;
|
||
notes?: string;
|
||
}
|
||
|
||
export type UpdateCheckResult =
|
||
| { status: 'disabled'; message: string }
|
||
| { status: 'error'; message: string }
|
||
| { status: 'up-to-date'; latestVersion: string }
|
||
| { status: 'available'; latestVersion: string; downloadUrl?: string; notes?: string };
|
||
|
||
/** v0.8.0 P2-3: 广播给渲染层的更新状态事件(update:status 通道载荷) */
|
||
export type UpdateStatusEvent =
|
||
| { status: 'checking' }
|
||
| { status: 'available'; latestVersion: string; notes?: string }
|
||
| { status: 'not-available'; latestVersion: string }
|
||
| { status: 'downloading'; percent: number }
|
||
| { status: 'downloaded' }
|
||
| { status: 'error'; message: string };
|
||
|
||
/**
|
||
* 语义化版本比较(仅支持 Major.Minor.Patch 与可选的预发布后缀忽略策略:
|
||
* 带预发布标签视为小于同号正式版)。非法输入返回 false(宁可不提示升级)。
|
||
*/
|
||
export function isNewerVersion(candidate: string, current: string): boolean {
|
||
const parse = (v: string): number[] | null => {
|
||
if (typeof v !== 'string') return null;
|
||
const m = /^v?(\d+)\.(\d+)\.(\d+)/.exec(v.trim());
|
||
if (!m) return null;
|
||
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
||
};
|
||
const a = parse(candidate);
|
||
const b = parse(current);
|
||
if (!a || !b) return false;
|
||
// 预发布标记(如 1.2.3-beta)小于同号正式版
|
||
const preA = /-/.test(candidate.trim());
|
||
const preB = /-/.test(current.trim());
|
||
for (let i = 0; i < 3; i++) {
|
||
if (a[i] !== b[i]) return a[i] > b[i];
|
||
}
|
||
if (a.join('.') === b.join('.')) {
|
||
// 同号:pre-release < stable
|
||
return !preA && preB;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
export class UpdateService {
|
||
constructor(
|
||
private readonly getCurrentVersion: () => string,
|
||
private readonly getFeedUrl: () => string | null,
|
||
) {}
|
||
|
||
async check(): Promise<UpdateCheckResult> {
|
||
const feedUrl = this.getFeedUrl();
|
||
if (!feedUrl) {
|
||
return { status: 'disabled', message: '未配置更新源(app.updateFeedUrl)' };
|
||
}
|
||
|
||
try {
|
||
const response = await fetch(feedUrl, {
|
||
signal: AbortSignal.timeout(10_000),
|
||
headers: { Accept: 'application/json' },
|
||
});
|
||
if (!response.ok) {
|
||
return { status: 'error', message: `更新源响应异常(HTTP ${response.status})` };
|
||
}
|
||
const feed = (await response.json()) as Partial<UpdateFeedInfo>;
|
||
const latestVersion = typeof feed.version === 'string' ? feed.version : '';
|
||
if (!latestVersion) {
|
||
return { status: 'error', message: '更新源缺少 version 字段' };
|
||
}
|
||
|
||
const current = this.getCurrentVersion();
|
||
if (!isNewerVersion(latestVersion, current)) {
|
||
return { status: 'up-to-date', latestVersion };
|
||
}
|
||
return {
|
||
status: 'available',
|
||
latestVersion,
|
||
downloadUrl:
|
||
typeof feed.url === 'string' && /^https?:\/\//i.test(feed.url) ? feed.url : undefined,
|
||
notes: typeof feed.notes === 'string' ? feed.notes : undefined,
|
||
};
|
||
} catch (err) {
|
||
return { status: 'error', message: `检查失败:${(err as Error).message}` };
|
||
}
|
||
}
|
||
}
|
||
|
||
// ===== v0.8.0 P2-3: electron-updater 集成(生产环境自动更新) =====
|
||
|
||
/** AutoUpdater 句柄(IPC 层消费;null = 未启用/dev 模式/未配置 feed) */
|
||
export interface AutoUpdaterHandle {
|
||
checkForUpdates: () => Promise<void>;
|
||
downloadAndInstall: () => Promise<void>;
|
||
}
|
||
|
||
let activeHandle: AutoUpdaterHandle | null = null;
|
||
|
||
/** 获取已启动的 AutoUpdater 句柄(app:updateInstall 消费;未启用时返回 null) */
|
||
export function getAutoUpdaterHandle(): AutoUpdaterHandle | null {
|
||
return activeHandle;
|
||
}
|
||
|
||
/**
|
||
* 启动 electron-updater 自动更新(生产环境专用)。
|
||
*
|
||
* @param feedUrl 更新源根目录(generic provider;app.updateFeedUrl 配置)
|
||
* @param onEvent 状态事件回调(主进程广播 update:status 给渲染层)
|
||
* @param autoCheckDelayMs 启动后延迟检查时间(默认 5s,让窗口先就绪)
|
||
* @returns 句柄(未启用时返回 null —— dev / electron-updater 加载失败)
|
||
*/
|
||
export async function startAutoUpdater(
|
||
feedUrl: string,
|
||
onEvent: (event: UpdateStatusEvent) => void,
|
||
autoCheckDelayMs = 5_000,
|
||
): Promise<AutoUpdaterHandle | null> {
|
||
if (!feedUrl) {
|
||
log.info('[Update] auto-updater disabled: no feed URL configured');
|
||
return null;
|
||
}
|
||
try {
|
||
// 动态导入:dev 模式(未打包)下 electron-updater 无法工作(无 app-update.yml),
|
||
// 加载失败时静默禁用,保持可用性
|
||
const { autoUpdater } = await import('electron-updater');
|
||
autoUpdater.autoDownload = false; // 下载需用户触发(app:updateInstall)
|
||
autoUpdater.autoInstallOnAppQuit = true;
|
||
autoUpdater.logger = null; // 事件统一经 onEvent 广播,避免双通道日志噪声
|
||
|
||
autoUpdater.on('checking-for-update', () => onEvent({ status: 'checking' }));
|
||
autoUpdater.on('update-available', (info) => {
|
||
onEvent({ status: 'available', latestVersion: String(info.version ?? ''), notes: undefined });
|
||
});
|
||
autoUpdater.on('update-not-available', (info) => {
|
||
onEvent({ status: 'not-available', latestVersion: String(info.version ?? '') });
|
||
});
|
||
autoUpdater.on('download-progress', (progress) => {
|
||
onEvent({ status: 'downloading', percent: Math.round(progress.percent ?? 0) });
|
||
});
|
||
autoUpdater.on('update-downloaded', () => onEvent({ status: 'downloaded' }));
|
||
autoUpdater.on('error', (err) => {
|
||
onEvent({ status: 'error', message: (err as Error).message });
|
||
});
|
||
|
||
// generic provider feed(app-update.yml 缺失时显式 setFeedURL 兜底)
|
||
autoUpdater.setFeedURL({ provider: 'generic', url: feedUrl });
|
||
|
||
const handle: AutoUpdaterHandle = {
|
||
checkForUpdates: async () => {
|
||
try {
|
||
await autoUpdater.checkForUpdates();
|
||
} catch (err) {
|
||
onEvent({ status: 'error', message: (err as Error).message });
|
||
}
|
||
},
|
||
downloadAndInstall: async () => {
|
||
try {
|
||
await autoUpdater.downloadUpdate();
|
||
onEvent({ status: 'downloaded' });
|
||
autoUpdater.quitAndInstall();
|
||
} catch (err) {
|
||
onEvent({ status: 'error', message: (err as Error).message });
|
||
}
|
||
},
|
||
};
|
||
activeHandle = handle;
|
||
|
||
// 启动 5s 后静默检查(不阻塞窗口就绪)
|
||
const timer = setTimeout(() => {
|
||
void handle.checkForUpdates();
|
||
}, autoCheckDelayMs);
|
||
timer.unref?.();
|
||
|
||
log.info(`[Update] auto-updater started (feed=${feedUrl})`);
|
||
return handle;
|
||
} catch (err) {
|
||
log.warn(
|
||
'[Update] electron-updater unavailable, auto-update disabled:',
|
||
(err as Error).message,
|
||
);
|
||
return null;
|
||
}
|
||
}
|