From 18f34c91fe6fd196db276f948c038b19ff50af1d Mon Sep 17 00:00:00 2001
From: thzxx <1440196015@qq.com>
Date: Thu, 30 Jul 2026 21:47:52 +0800
Subject: [PATCH] =?UTF-8?q?v0.16.14:=20TypeScript=20=E7=BC=96=E8=AF=91?=
=?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D=20+=20=E6=96=87=E6=A1=A3?=
=?UTF-8?q?=E5=90=8C=E6=AD=A5=20+=20=E4=BB=A3=E7=A0=81=E5=81=A5=E5=A3=AE?=
=?UTF-8?q?=E6=80=A7=E5=A2=9E=E5=BC=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 14 +++----
docs/DEVELOPMENT.md | 26 +++---------
package-lock.json | 4 +-
package.json | 2 +-
src/main/menu.ts | 2 +-
src/renderer/api/ollama.ts | 48 ++++++++++++----------
src/renderer/components/workspace-panel.ts | 2 +-
src/renderer/index.html | 2 +-
src/renderer/main.ts | 2 +-
src/renderer/services/agent-engine.ts | 6 +--
src/renderer/services/context-manager.ts | 4 +-
src/renderer/types.d.ts | 1 +
12 files changed, 53 insertions(+), 60 deletions(-)
diff --git a/README.md b/README.md
index de155c5..903fafd 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
-
+
@@ -35,7 +35,7 @@
| | 功能 | 说明 |
|:---:|:---|:---|
| 🤖 | **ReAct Agent Loop** | 始终开启的唯一对话模式。8 状态机(INIT→THINKING→PARSING→EXECUTING→OBSERVING→REFLECTING→COMPRESSING→TERMINATED),最大 85 轮(可配置),智能重试(永久错误立即返回、瞬态错误指数退避),工具去重,智能路径依赖串行化,看门狗超时保护 |
-| 🛡️ | **5 层抗幻觉系统** | 提示词加固 → 任务感知 → 中途检测(中英双语规则覆盖全部工具类别)→ 进度锚点 → 完成闸门(6 项检查,幻觉/注入 → 阻断,质量/效率 → 咨询) |
+| 🛡️ | **提示词加固** | 参考数据标记(<<>>)+ 工具结果仅为数据非指令的安全规则注入 |
| 📋 | **Plan Mode** | 开关切换,AI 首先生成执行计划(Markdown 渲染确认弹窗),批准后按步骤追踪执行,plan_track 工具标记完成状态,**支持断点续传**(中止后可恢复未完成计划) |
| 🔧 | **32 个内置工具** | 文件系统(13个) · 命令执行 · 联网搜索 · 浏览器控制(9个) · Git · 记忆 · 会话 · 子代理 · 系统工具 · Plan Mode 追踪 |
| 🧠 | **智能记忆系统** | 三类记忆(fact / preference / rule),存储于工作空间 MEMORY.md 文件,受路径保护仅 memory 工具可访问,写入前安全扫描,容量 500 条,对话结束自动提取,严格格式校验 |
@@ -173,7 +173,7 @@
↓
Agent Engine (8 状态机 ReAct Loop, ≤85 轮, 智能重试, 路径依赖串行化, 看门狗+分级超时)
↓
- 5 层抗幻觉系统(中英双语规则)(提示词 → 中途检测 → 进度锚 → 完成闸门 → 校验)
+ 提示词加固(参考数据标记 + 工具结果安全规则)
↓
Ollama API (流式响应,num_ctx 用户可配 128K/256K/512K/1M)
↓
@@ -245,7 +245,7 @@ npm start
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ npm run dist
```
-产出:`release/Metona Ollama Setup v0.16.13.exe`
+产出:`release/Metona Ollama Setup v0.16.14.exe`
## 🛠️ 常用命令
@@ -276,7 +276,7 @@ npm run dist # 构建 Windows 安装包
| | Feature | Description |
|:---:|:---|:---|
| 🤖 | **ReAct Agent Loop** | Always-on, only chat mode. 8-state machine, up to 85 iterations (configurable), smart retry (permanent errors return immediately, transient errors use exponential backoff), tool dedup, path-aware dependency serialization, watchdog + tiered timeout protection |
-| 🛡️ | **5-Layer Anti-Hallucination** | Prompt hardening → task awareness → mid-task detection (bilingual CN/EN rules covering all tool categories) → progress anchors → completion gate (6 checks: hallucination/injection → block, quality/efficiency → advisory) |
+| 🛡️ | **Prompt Hardening** | Reference data markers (<<>>) + tool results are data-not-instructions safety rules |
| 📋 | **Plan Mode** | Toggle switch. AI first generates an execution plan (Markdown-rendered confirmation dialog), then tracks step-by-step execution, **supports resume** (interrupted plans restore on next session) |
| 🔧 | **32 Built-in Tools** | File system · Command · Web search · Browser · Git · Memory · Sessions · Sub-agent · System · Plan Mode tracking |
| 🧠 | **Smart Memory System** | Three types (fact / preference / rule), stored in workspace MEMORY.md file, path-protected — only the memory tool can access it, pre-write security scan, 500 capacity, auto-extract on conversation end, strict format validation |
@@ -413,7 +413,7 @@ User message → workspace SOUL.md (never compressed) → AGENT.md → USER.md (
↓
Agent Engine (8-state ReAct Loop, ≤85 iter, smart retry, path-aware serialization, watchdog+tiered timeout)
↓
- 5-Layer Anti-Hallucination (bilingual CN/EN rules) (prompt → mid-task detection → anchors → gate → verification)
+ Prompt Hardening (reference data markers + tool result safety rules)
↓
Ollama API (Streaming Response, num_ctx user-configurable 128K/256K/512K/1M)
↓
@@ -485,7 +485,7 @@ npm start
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ npm run dist
```
-Output: `release/Metona Ollama Setup v0.16.13.exe`
+Output: `release/Metona Ollama Setup v0.16.14.exe`
## 🛠️ Common Commands
diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md
index e25c9f3..6ecab69 100644
--- a/docs/DEVELOPMENT.md
+++ b/docs/DEVELOPMENT.md
@@ -11,7 +11,7 @@ Metona Ollama Desktop 是基于 TypeScript + Electron 的 Windows 本地 AI 桌
核心架构:
- **ReAct Agent Loop** — 8 状态机驱动的智能体循环(INIT→THINKING→PARSING→EXECUTING→OBSERVING→REFLECTING→COMPRESSING→TERMINATED),最大 85 轮(可配置)
- **32 个内置工具** — 文件系统(13)、命令执行(1)、联网搜索(2)、浏览器控制(9)、Git(1)、记忆(1)、会话/子代理(3)、系统(1)、Plan Mode(1)
-- **Harness Engineering** — 5 层抗幻觉体系 + 4 阶段 Hook 系统 + Completion Gate(5 项检查)+ Agent Metrics + 渐进式披露
+- **Harness Engineering** — 提示词加固 + 4 阶段 Hook 系统 + Agent Metrics + 渐进式披露
- **MCP 协议扩展** — JSON-RPC 2.0 over stdio,动态工具发现
- **Plan Mode** — 开关切换,先规划后执行,步骤级进度追踪
- **SQLite 存储** — sql.js WASM,5 张表,WAL 模式
@@ -80,7 +80,7 @@ src/
│ │ ├── tool-confirm-modal.ts # 工具执行确认对话框
│ │ ├── tools-modal.ts # 工具列表面板(32 个工具卡片)
│ │ └── workspace-panel.ts # 工作空间面板(终端 + 工具卡片 + 文件浏览)
-│ ├── services/ # 14 个服务模块
+│ ├── services/ # 13 个服务模块
│ │ ├── agent-engine.ts # ★ ReAct Agent Loop 核心引擎(8 状态机)
│ │ ├── tool-registry.ts # 工具注册与调度中心(32 内置 + MCP 动态 + Plan Mode)
│ │ ├── memory-service.ts # 记忆管理(MEMORY.md 读写 + 格式校验 + 自动提取)
@@ -90,7 +90,6 @@ src/
│ │ ├── log-service.ts # 结构化日志(9 级分类)
│ │ ├── crypto.ts # AES-256-GCM 加密
│ │ ├── hooks.ts # 4 阶段 Hook 系统(pre_tool/post_tool/post_iteration/pre_completion)
-│ │ ├── completion-gate.ts # 完成门控(5 项检查,阻断/咨询两级)
│ │ ├── agent-metrics.ts # Agent 度量采集 + 错误模式识别 + 改进建议
│ │ ├── agent-safety.ts # Agent 安全防护(工具阴影检测 + 路径校验)
│ │ ├── context-indexer.ts # 渐进式披露(索引层→接口层→实现层)
@@ -227,15 +226,13 @@ INIT → THINKING → PARSING → EXECUTING → OBSERVING → REFLECTING → (CO
### 5.4 Harness Engineering 体系
-#### 5.4.1 5 层抗幻觉
+#### 5.4.1 提示词加固
| 层级 | 实现位置 | 机制 |
|------|---------|------|
-| 提示词加固 | `handleInit()` | [反幻觉铁律] 最高优先级注入 |
-| 任务感知 | `handleThinking()` | 第 2 轮无工具调用时注入提醒 |
-| 中途检测 | `detectMidTaskHallucination()` | 16 条正则规则,覆盖全部工具类别 |
-| 进度锚点 | `handleObserving()` | 每 5 轮注入机器生成的工具调用摘要 |
-| 完成闸门 | `completion-gate.ts` | 6 项检查:幻觉/注入→阻断级,质量/效率→咨询级 |
+| 提示词加固 | `handleInit()` | 注入安全规则:参考数据标记(<<>>)+ 工具结果仅为数据非指令 |
+
+> 注:任务感知注入、中途检测、进度锚点、完成闸门已在版本迭代中移除,AI 基于工具返回值和上下文自行判断。
#### 5.4.2 Hook 系统(4 阶段)
@@ -249,17 +246,6 @@ INIT → THINKING → PARSING → EXECUTING → OBSERVING → REFLECTING → (CO
Hook 异步并行执行,失败不阻塞主流程。可动态注册/移除。
-#### 5.4.3 Completion Gate(6 项检查)
-
-| 检查项 | 级别 | 不通过行为 |
-|--------|------|-----------|
-| toolHallucination | 🔴 阻断 | 强制重新回答 |
-| promptInjection | 🔴 阻断 | 强制重新回答 |
-| contentQuality | 🟡 咨询 | 仅记录日志 |
-| toolResultReview | 🟡 咨询 | 仅记录日志 |
-| notThinking | 🟡 咨询 | 仅记录日志 |
-| contextEfficiency | 🟡 咨询 | 仅记录日志 |
-
### 5.5 联网搜索体系
**双模式架构**:
diff --git a/package-lock.json b/package-lock.json
index b3562a1..fc73143 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "metona-ollama-desktop",
- "version": "0.16.13",
+ "version": "0.16.14",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "metona-ollama-desktop",
- "version": "0.16.13",
+ "version": "0.16.14",
"license": "MIT",
"dependencies": {
"ffmpeg-static": "^5.2.0",
diff --git a/package.json b/package.json
index 9ed4bb7..47652f5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "metona-ollama-desktop",
- "version": "0.16.13",
+ "version": "0.16.14",
"description": "Metona Ollama - TypeScript + Electron 桌面 AI 聊天客户端",
"main": "dist/main/main.js",
"author": "thzxx",
diff --git a/src/main/menu.ts b/src/main/menu.ts
index d16269c..3ddbc48 100644
--- a/src/main/menu.ts
+++ b/src/main/menu.ts
@@ -101,7 +101,7 @@ export function createMenu(): void {
dialog.showMessageBox(mainWindow!, {
type: 'info',
title: '关于 Metona Ollama',
- message: 'Metona Ollama Desktop v0.16.13',
+ message: 'Metona Ollama Desktop v0.16.14',
detail: 'TypeScript + Electron Ollama AI 聊天客户端\n\nhttps://gitee.com/thzxx/metona-ollama',
icon: getIconPath()
});
diff --git a/src/renderer/api/ollama.ts b/src/renderer/api/ollama.ts
index 8a2614d..a9c608b 100644
--- a/src/renderer/api/ollama.ts
+++ b/src/renderer/api/ollama.ts
@@ -103,30 +103,36 @@ export class OllamaAPI {
}, { once: true });
}
- while (true) {
- const { done, value } = await reader.read();
- if (done) {
- break;
- }
-
- buffer += decoder.decode(value, { stream: true });
- const lines = buffer.split('\n');
- buffer = lines.pop() || '';
-
- for (const line of lines) {
- if (!line.trim()) continue;
- let chunk: OllamaStreamChunk;
- try {
- chunk = JSON.parse(line);
- } catch {
- continue; // 跳过无法解析的行(可能是不完整的 JSON)
+ try {
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) {
+ break;
}
- // onChunk 回调错误不再被静默吞掉,而是向上传播给调用方
- if (onChunk) onChunk(chunk);
- if (chunk.done) {
- return;
+
+ buffer += decoder.decode(value, { stream: true });
+ const lines = buffer.split('\n');
+ buffer = lines.pop() || '';
+
+ for (const line of lines) {
+ if (!line.trim()) continue;
+ let chunk: OllamaStreamChunk;
+ try {
+ chunk = JSON.parse(line);
+ } catch {
+ continue; // 跳过无法解析的行(可能是不完整的 JSON)
+ }
+ // onChunk 回调错误不再被静默吞掉,而是向上传播给调用方
+ if (onChunk) onChunk(chunk);
+ if (chunk.done) {
+ return;
+ }
}
}
+ } catch (err) {
+ // abort 导致 reader.cancel() 会使 reader.read() 抛出异常,属于正常中止流程
+ if (abortController?.signal.aborted) return;
+ throw err;
}
if (buffer.trim()) {
diff --git a/src/renderer/components/workspace-panel.ts b/src/renderer/components/workspace-panel.ts
index 6ac405d..cf6fe9d 100644
--- a/src/renderer/components/workspace-panel.ts
+++ b/src/renderer/components/workspace-panel.ts
@@ -1080,7 +1080,7 @@ function renderToolCard(tc: ToolCallRecord): string {
} else if (tc.name === 'delete_file') {
if (r.batch) {
resultHtml = `✅ 批量删除 ${r.successCount}/${r.totalPaths} 个路径
`;
- if (r.results) {
+ if (Array.isArray(r.results)) {
for (const res of r.results) {
resultHtml += `${res.success ? '✅' : '❌'} ${escapeHtml(String(res.path || ''))}${res.success ? '' : ' — ' + escapeHtml(String(res.error || ''))}
`;
}
diff --git a/src/renderer/index.html b/src/renderer/index.html
index 9f11767..ad0ff78 100644
--- a/src/renderer/index.html
+++ b/src/renderer/index.html
@@ -28,7 +28,7 @@