Skip to content

Commit 87dfe48

Browse files
feat(intuition): 直觉模块偏差治理 + 校准/追踪回归修复(v0.1.14)
直觉偏差治理(方案 A–H,schema 4.15): - verdict_log/calibration_map 落库,弃权四道门(弱共振/假共振/证据稀疏/冲突), 基率锚定先验、校准映射、离散度塑形 confidence、provenance 切断自我强化。 - recall session_only 语义:daemon 只取 trace_id 不写 selected/retrieved; 空召回落 known_none/discarded,不入 open 池。repair_traces 一次性清污。 本轮回归修复(7 项): 1. 校准映射域不匹配:verdict_calibration_samples 返回 (strength,conf,hit), curate 重算改按 emitted_strength 分桶(与 calibrate_confidence 查表键域一致), inspect ECE 仍按 conf。 2/5. neutral/mixed verdict 排除出校准样本,避免「没表态」被算成「预测失败」。 3. repair_traces 退役条件同时要求 selected:[] 且 sparks:[],不再误退仅含 spark 的召回。 4. 反事实审查落地:RecordParams.verdict_heeded 贯通 core/CLI/MCP/Python/TS SDK, 被采纳的警告回填 counterfactual_censored,不计校准。 6. 死列 emitted_strength 现作为映射键域被读取。 7. insert_verdict_log 改普通 INSERT,反映「每次 appraise 恰一行」不变式。 新增回归测试锁定 #2/#4/#5;cargo test 169 passed;clippy 仅既有告警; Python/TS SDK 编译通过。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fb46589 commit 87dfe48

54 files changed

Lines changed: 2928 additions & 236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.autoforge/project.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "fcc28e8c-8009-4480-a0bc-245895686445",
3+
"name": "Innate",
4+
"created_at": "2026-06-20T02:34:51Z"
5+
}

.autoforge/specs/api.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# API 契约
2+
3+
## MCP 工具集
4+
5+
MCP 暴露 15 个工具:innate_recall、innate_record、innate_appraise、innate_add、innate_spark、innate_inspect、innate_evolve、innate_approve、innate_archive、innate_invalidate、innate_restore、innate_mature_spark、innate_promote_spark、innate_drop_spark、innate_backup。
6+
7+
---
8+
9+
## REST API 端点
10+
11+
Web API 路径前缀 /api/:GET inspect、GET chunks(支持 state/origin/limit/offset 查询)、GET governance、GET llm-traces、GET chunk/:id、POST chunk/:id/{approve|restore|archive|invalidate}。
12+
13+
---
14+
15+
## API 安全机制
16+
17+
非 loopback 绑定时所有 /api/ 读端点需 x-innate-token 头认证;写端点额外校验 Origin 头防 CSRF;loopback 绑定时读端点免认证以便本地 UI 浏览。
18+
19+
---
20+
21+
## CLI JSON 契约
22+
23+
CLI 所有子命令(recall/record/add/inspect/evolve 等)以 --format json 输出结构化 JSON 到 stdout,stderr 仅用于错误信息;SDK 通过解析 stdout JSON 获取结果。
24+
25+
---
26+
27+
## SDK 接口一致性
28+
29+
Python/TypeScript SDK 暴露与 CLI 子命令一一对应的方法(recall/record/add/inspect/evolve 等),参数命名与 CLI flag 保持一致,返回类型使用 dataclass/interface 强类型定义。

.autoforge/specs/architecture.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 架构约束
2+
3+
## 单二进制 + lib 分层
4+
5+
项目产出单一二进制 innate(main.rs)和库 innate_core(lib.rs);CLI、MCP、Web、Daemon 均为 lib 模块的薄封装层。
6+
7+
---
8+
9+
## 可插拔 Provider 架构
10+
11+
KnowledgeBase 通过 Arc<dyn Trait> 注入五个扩展点:EmbeddingProvider、Refiner、Distiller、Curator、Sanitizer;open_with() 接受 Option,缺省回退到 Dummy/Heuristic/Null 实现。
12+
13+
---
14+
15+
## 三层知识模型
16+
17+
系统管理程序性知识,分 Memory(经验蒸馏+置信EMA+时间衰减)、Skill(可安装 kind=skill chunk)、Intuition(appraise 评审)三层协作;chunk origin 限定为 installed/distilled/captured/spark。
18+
19+
---
20+
21+
## 韧性蒸馏管线
22+
23+
ResilientDistiller 包装 LLM Distiller + HeuristicDistiller,LLM 优先尝试 2 次后回退确定性蒸馏,确保知识创建不依赖 LLM 可用性。
24+
25+
---
26+
27+
## SDK 架构
28+
29+
Python/TypeScript SDK 均通过 subprocess 调用 innate 二进制(CLI 模式),TypeScript 额外支持 MCP stdio 客户端模式;SDK 不直接操作数据库。

.autoforge/specs/coding.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 编码规范
2+
3+
## 错误处理规范
4+
5+
统一使用 thiserror 定义 InnateError 枚举,模块级 pub type Result<T> = std::result::Result<T, InnateError>;外部错误通过 #[from] 自动转换,业务错误用 Other(String) 或专用变体。
6+
7+
---
8+
9+
## 纯函数可测性
10+
11+
IO 与逻辑分离:Web 路由 route() 为纯函数(无 socket),handle() 仅做 tiny_http 胶水;便于无网络单元测试。
12+
13+
---
14+
15+
## 常量调参约定
16+
17+
召回权重、阈值等调参默认值定义为模块级 const(如 W_CONTENT=0.55),KnowledgeBase 初始化时从 meta 表加载覆盖值,运行时可通过 settings 调整。
18+
19+
---
20+
21+
## 向量维度守卫
22+
23+
所有向量写入必须通过 store_vec_content/store_vec_trigger,在写入前校验维度与 EmbeddingProvider 配置一致,不匹配则 fail-closed 返回 InvalidState 错误。
24+
25+
---
26+
27+
## Schema 迁移
28+
29+
数据库迁移使用增量 SQL 文件(如 4.13_to_4.14.sql),由 migrate.rs 按 schema_version 顺序执行;新迁移必须向后兼容且可重复执行(IF NOT EXISTS)。

.autoforge/specs/tech_stack.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 技术栈
2+
3+
## Rust 核心
4+
5+
核心使用 Rust edition 2021 编写,包名 innate,当前版本 0.1.14;release profile 启用 LTO、codegen-units=1、strip=true 以优化二进制体积。
6+
7+
---
8+
9+
## SQLite 存储
10+
11+
使用 rusqlite 0.32(bundled feature)作为唯一持久化引擎,schema 版本 4.15;向量相似度由 Rust 代码直接计算,不依赖 sqlite-vec 扩展。
12+
13+
---
14+
15+
## SDK 语言与版本
16+
17+
Python SDK(innate-py)要求 Python ≥3.10,零运行时依赖,dev 依赖 pytest≥7;TypeScript SDK(@innate/sdk)要求 Node ≥18、TypeScript ≥5,零运行时依赖。
18+
19+
---
20+
21+
## 关键依赖版本
22+
23+
clap 4(derive+env)、serde 1、serde_json 1、ureq 3(json feature)、tiny_http 0.12、thiserror 2、anyhow 1、uuid 1(v4)、chrono 0.4(serde)、sha2 0.11、hmac 0.13。
24+
25+
---
26+
27+
## 协议与接口
28+
29+
MCP 服务基于 JSON-RPC 2.0 over stdio;Web UI 使用 tiny_http 内嵌静态资源 + REST API;CLI 输出 JSON 供 SDK 解析。

.autoforge/specs/testing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 测试要求
2+
3+
## 集成测试模块
4+
5+
core/src/tests/ 下含 12 个测试模块(basics、distillation、eval、feedback、governance、intuition、intuition_optim、reliability、restoration 等),通过 tmp_kb() 创建临时 SQLite 文件隔离测试。其中 intuition_optim 锁定直觉模块偏差治理(弃权门 A、verdict_log B、provenance C、基率先验 D、校准映射 E、双通道 F、离散度 G)激活后的行为。
6+
7+
---
8+
9+
## Web 路由纯函数测试
10+
11+
web/tests.rs 直接调用 route() 纯函数,不启动 HTTP 服务器;覆盖 chunk 列表、状态过滤、inspect 开放访问、token 认证、CSRF 防御等场景。
12+
13+
---
14+
15+
## 测试辅助函数
16+
17+
tests/mod.rs 提供 attributed_trace()、record_down_as() 等辅助函数,封装 episodic_log 写入和 usage_trace 插入,降低测试样板代码。
18+
19+
---
20+
21+
## SDK 测试
22+
23+
Python SDK 使用 pytest(tests/test_client.py);TypeScript SDK 通过 tsc 编译验证类型正确性,package.json 定义 build 脚本。
24+
25+
---
26+
27+
## Daemon 测试
28+
29+
daemon/tests.rs 独立测试守护进程的文件监听逻辑;dev-dependencies 仅依赖 tempfile 3 用于创建临时文件/目录。

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ Source is split into focused module directories (the old monolithic `kb.rs` / `s
121121
| `install/{wizard,agents,skills,settings,path,ui,uninstall}.rs` | `innate install`/`uninstall` TUI — configures Claude/Codex/opencode MCP, skill, slash commands, Stop hook |
122122
| `backup/{mod,command}.rs` | Cloudflare R2 backup/restore/list/prune (S3-compatible + SigV4) |
123123
| `upgrade.rs` | `innate upgrade` — GitHub Releases self-update + SHA-256 verify + atomic swap |
124-
| `migrate.rs` | Schema migration chain 4.0 → 4.14, each step atomic |
124+
| `migrate.rs` | Schema migration chain 4.0 → 4.15, each step atomic |
125125
| `hook.rs` | `innate hook stop` — Claude Code Stop payload → session.log events |
126126
| `paths.rs` | Single source of truth for the `~/.innate` directory layout; `ensure_layout()` creates subdirs + migrates legacy flat files |
127127
| `utils.rs` | `utc_now_iso()`, `gen_uuid()`, `content_hash()`, `sanitize()`, cosine similarity |
128128
| `settings.rs` | `settings.json` parsing (LLM / Embedding / Daemon / Backup) |
129-
| `schema.sql` | Embedded schema (v4.14); `include_str!` at compile time |
129+
| `schema.sql` | Embedded schema (v4.15); `include_str!` at compile time |
130130

131131
### Filesystem layout (`~/.innate/`)
132132

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@
77
-->
88

99
@AGENTS.md
10+
11+
<!-- autoforge:specs:start -->
12+
## AutoForge 项目规格
13+
14+
以下为 AutoForge 管理的项目规格约束,AI 执行任务时必须遵守:
15+
16+
@.autoforge/specs/tech_stack.md
17+
@.autoforge/specs/architecture.md
18+
@.autoforge/specs/coding.md
19+
@.autoforge/specs/api.md
20+
@.autoforge/specs/testing.md
21+
<!-- autoforge:specs:end -->

core/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "innate"
3-
version = "0.1.13"
3+
version = "0.1.14"
44
edition = "2021"
55
license = "MIT"
66
authors = ["vima-tech"]

0 commit comments

Comments
 (0)