feat: v0.8.0 流语义补全 · 会话可靠 · 恢复力 — finish_reason 全链路贯通根治"思考中停止" · 2445 用例全量回归
CI / 类型检查 + Lint + 单元测试 (push) Failing after 9m16s
CI / 全量测试 (Electron ABI) (push) Failing after 6m4s
CI / 产物编译验证 (push) Successful in 11m1s

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 跳过
This commit is contained in:
2026-09-05 20:06:26 +08:00
parent 99d0c54129
commit 5b9d4d19b3
78 changed files with 5128 additions and 411 deletions
+71 -10
View File
@@ -38,6 +38,7 @@ import {
} from 'fs/promises';
import { join, relative, resolve, dirname } from 'path';
import { existsSync, realpathSync } from 'fs';
import { nanoid } from 'nanoid';
import type { IMetonaTool, ToolExecutionContext } from '../../types/metona-tool';
import type { MetonaToolDef } from '../../../harness/types';
import { MetonaToolCategory, MetonaRiskLevel } from '../../../harness/types';
@@ -61,6 +62,13 @@ import {
* v0.3.2 修复 FAIL: 使用 bytesRead 限制循环上界,而非 buffer.length。
* Buffer.alloc(8192) 初始化为全 0fd.read 只覆盖 [0, bytesRead) 区间,
* 若用 buffer.length 遍历会误判所有 < 8192 字节的纯文本文件为二进制。
*
* v0.8.0 P1-3.3 根治: UTF-16 文件(LE: FF FE / BE: FE FF BOM)几乎每个字符
* 都含 0x00 字节 —— NULL 字节启发式把一切 UTF-16 文本判为二进制并整体拒绝,
* 使 decodeBufferWithDetection 的 UTF-16 解码分支不可达(原缺陷被
* filesystem-tools.test.ts 锁定留档,本次随修复同步改约)。现先检测 UTF-16
* BOM:命中即视为文本(UTF-16 解码由 decodeBufferWithDetection 承担),
* 未命中 BOM 才走 NULL 字节启发式。
*/
async function isBinaryFile(filePath: string): Promise<boolean> {
// M-20 修复: 使用 finally 块确保文件句柄关闭,防止 fd 泄漏
@@ -69,6 +77,9 @@ async function isBinaryFile(filePath: string): Promise<boolean> {
const buffer = Buffer.alloc(8192);
fd = await open(filePath, 'r');
const { bytesRead } = await fd.read(buffer, 0, 8192, 0);
// v0.8.0 P1-3.3: UTF-16 LE/BE BOM → 文本(NUL 启发式对其无效)
if (bytesRead >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe) return false; // UTF-16 LE BOM
if (bytesRead >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff) return false; // UTF-16 BE BOM
// 仅检查实际读取的字节范围 [0, bytesRead)
// 含 NULL 字节 → 二进制;空文件(bytesRead=0)→ 非二进制
for (let i = 0; i < bytesRead; i++) {
@@ -346,7 +357,9 @@ export class WriteFileTool implements IMetonaTool {
}
// v0.3.2: overwrite 模式使用原子写入(临时文件 + rename,与 file_editor 一致)
const tmpPath = `${filePath}.tmp_${Date.now()}`;
// v0.8.0 P1-3.4: tmp 文件名追加 nanoid 随机段 —— 同毫秒并发写同一文件时
// Date.now() 精度的 tmp 名会互相覆盖(并行工具调用场景)
const tmpPath = `${filePath}.tmp_${Date.now()}_${nanoid(6)}`;
try {
await writeFile(tmpPath, content, 'utf-8');
await rename(tmpPath, filePath);
@@ -395,6 +408,11 @@ export class ListDirectoryTool implements IMetonaTool {
type: 'boolean',
description: 'Include hidden files/dirs starting with "." (default false)',
},
include_node_modules: {
type: 'boolean',
description:
'Include node_modules directories (default false — skipped for performance; set true to inspect dependency packages)',
},
},
},
category: MetonaToolCategory.FILESYSTEM,
@@ -411,6 +429,8 @@ export class ListDirectoryTool implements IMetonaTool {
const depth = Math.min(5, Math.max(1, (args.depth as number) ?? 1));
const glob = args.glob as string | undefined;
const includeHidden = (args.include_hidden as boolean) ?? false;
// v0.8.0 P1-3.6: node_modules 可选纳入(默认跳过保持兼容)
const includeNodeModules = (args.include_node_modules as boolean) ?? false;
// v0.3.2 修复 WARN-3: listDir 内部提前终止,避免大目录全量遍历
const MAX_ENTRIES = 1000;
@@ -421,7 +441,17 @@ export class ListDirectoryTool implements IMetonaTool {
size?: number;
modified?: string;
}> = [];
await this.listDir(dirPath, dirPath, depth, glob, includeHidden, 0, entries, MAX_ENTRIES);
await this.listDir(
dirPath,
dirPath,
depth,
glob,
includeHidden,
includeNodeModules,
0,
entries,
MAX_ENTRIES,
);
return {
entries,
count: entries.length,
@@ -439,6 +469,7 @@ export class ListDirectoryTool implements IMetonaTool {
maxDepth: number,
glob: string | undefined,
includeHidden: boolean,
includeNodeModules: boolean,
currentDepth: number,
results: Array<{ name: string; path: string; type: string; size?: number; modified?: string }>,
maxEntries: number,
@@ -453,8 +484,9 @@ export class ListDirectoryTool implements IMetonaTool {
if (results.length >= maxEntries) return;
// v0.3.2: include_hidden 参数控制隐藏文件
if (!includeHidden && entry.name.startsWith('.')) continue;
// node_modules 始终跳过(太大)
if (entry.name === 'node_modules') continue;
// v0.8.0 P1-3.6: node_modules 默认跳过(太大)include_node_modules=true
// 时纳入(分析依赖包场景;上限保护仍生效)
if (entry.name === 'node_modules' && !includeNodeModules) continue;
const fullPath = join(dirPath, entry.name);
// 相对路径始终以根请求目录为基准
@@ -470,6 +502,7 @@ export class ListDirectoryTool implements IMetonaTool {
maxDepth,
glob,
includeHidden,
includeNodeModules,
currentDepth + 1,
results,
maxEntries,
@@ -526,6 +559,19 @@ export class SearchFilesTool implements IMetonaTool {
description:
'Lines of context to show around content matches (default 0, max 5). Only for target="content".',
},
case_sensitive: {
type: 'boolean',
description:
'Case sensitive search (default false — v0.8.0 P1-3.5: previously hardcoded case-insensitive, breaking code_search fallback symmetry)',
},
context_before: {
type: 'number',
description: 'Lines of context before match (default = context_lines, max 5)',
},
context_after: {
type: 'number',
description: 'Lines of context after match (default = context_lines, max 5)',
},
include_hidden: {
type: 'boolean',
description: 'Include hidden files/dirs starting with "." (default false)',
@@ -549,6 +595,15 @@ export class SearchFilesTool implements IMetonaTool {
const fileGlob = args.file_glob as string | undefined;
const limit = Math.min(200, Math.max(1, (args.limit as number) ?? 50));
const contextLines = Math.min(5, Math.max(0, (args.context_lines as number) ?? 0));
// v0.8.0 P1-3.5: 与 code_search 参数对称 —— case_sensitive 此前被硬编码
// 'gi' 忽略;context_before/after 此前在 code_search JS 回退路径静默丢失。
// 缺省时回退 context_lines(向后兼容)。
const caseSensitive = (args.case_sensitive as boolean) ?? false;
const contextBefore = Math.min(
5,
Math.max(0, (args.context_before as number) ?? contextLines),
);
const contextAfter = Math.min(5, Math.max(0, (args.context_after as number) ?? contextLines));
const includeHidden = (args.include_hidden as boolean) ?? false;
if (target === 'files') {
@@ -566,7 +621,9 @@ export class SearchFilesTool implements IMetonaTool {
pattern,
fileGlob,
limit,
contextLines,
contextBefore,
contextAfter,
caseSensitive,
includeHidden,
context.workspacePath,
);
@@ -606,7 +663,9 @@ export class SearchFilesTool implements IMetonaTool {
pattern: string,
fileGlob: string | undefined,
limit: number,
contextLines: number,
contextBefore: number,
contextAfter: number,
caseSensitive: boolean,
includeHidden: boolean,
workspacePath: string,
): Promise<unknown> {
@@ -635,7 +694,8 @@ export class SearchFilesTool implements IMetonaTool {
}
let regex: RegExp;
try {
regex = new RegExp(pattern, 'gi');
// v0.8.0 P1-3.5: case_sensitive 参数生效(此前硬编码 'gi' 恒大小写不敏感)
regex = new RegExp(pattern, caseSensitive ? 'g' : 'gi');
} catch {
return { results: [], count: 0, error: `Invalid regex pattern: ${pattern}`, success: false };
}
@@ -668,10 +728,11 @@ export class SearchFilesTool implements IMetonaTool {
if (regex.test(lines[i])) {
const match = lines[i].trim().slice(0, 200);
// v0.3.2: context lines 支持
// v0.8.0 P1-3.5: 前后文行数独立(code_search 对称性)
let context: string[] | undefined;
if (contextLines > 0) {
const start = Math.max(0, i - contextLines);
const end = Math.min(lines.length - 1, i + contextLines);
if (contextBefore > 0 || contextAfter > 0) {
const start = Math.max(0, i - contextBefore);
const end = Math.min(lines.length - 1, i + contextAfter);
context = lines.slice(start, end + 1);
}
results.push({