fluffy-context 0.5.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -9
- package/dist/src/agent/api.d.ts +5 -1
- package/dist/src/agent/api.js +41 -12
- package/dist/src/agent/index.d.ts +3 -1
- package/dist/src/agent/index.js +1 -0
- package/dist/src/agent/types.d.ts +21 -0
- package/dist/src/cli/main.js +150 -12
- package/dist/src/cognition/feedback.d.ts +9 -0
- package/dist/src/cognition/feedback.js +30 -0
- package/dist/src/cognition/filesystem-observer.d.ts +41 -0
- package/dist/src/cognition/filesystem-observer.js +164 -0
- package/dist/src/cognition/git-observer.d.ts +1 -0
- package/dist/src/cognition/git-observer.js +3 -2
- package/dist/src/cognition/journal.d.ts +4 -1
- package/dist/src/cognition/journal.js +83 -4
- package/dist/src/cognition/migration-v1.js +13 -11
- package/dist/src/cognition/orient.d.ts +4 -0
- package/dist/src/cognition/orient.js +14 -4
- package/dist/src/cognition/policy.d.ts +4 -0
- package/dist/src/cognition/policy.js +49 -0
- package/dist/src/cognition/projections.js +0 -0
- package/dist/src/cognition/retrieval.d.ts +26 -0
- package/dist/src/cognition/retrieval.js +273 -0
- package/dist/src/cognition/runtime.d.ts +20 -1
- package/dist/src/cognition/runtime.js +229 -53
- package/dist/src/cognition/types.d.ts +55 -1
- package/dist/src/cognition/v1-bridge.js +13 -4
- package/dist/src/compiler/activity.d.ts +3 -0
- package/dist/src/compiler/activity.js +79 -0
- package/dist/src/compiler/compile.d.ts +2 -0
- package/dist/src/compiler/compile.js +330 -0
- package/dist/src/compiler/sources.d.ts +19 -0
- package/dist/src/compiler/sources.js +130 -0
- package/dist/src/compiler/types.d.ts +187 -0
- package/dist/src/compiler/types.js +1 -0
- package/dist/src/hooks/claude-code.js +7 -15
- package/dist/src/mcp/main.js +2 -0
- package/dist/src/mcp/server.js +2 -0
- package/dist/src/runtime/knowledge.d.ts +2 -0
- package/dist/src/runtime/knowledge.js +63 -0
- package/dist/src/runtime/types.d.ts +19 -0
- package/dist/src/storage/layout.d.ts +2 -0
- package/dist/src/storage/layout.js +6 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +2 -2
- package/skills/fluffy-context/SKILL.md +2 -1
package/README.md
CHANGED
|
@@ -1,10 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# fluffy-context
|
|
2
2
|
|
|
3
|
-
`fluffy-context`
|
|
3
|
+
`fluffy-context` 是一个本地优先、Agent 无关的 Context 与 Knowledge Runtime。它帮助 AI 编程 Agent 在新会话中恢复任务状态、检索已验证共识、避开已验证死路,并将结果编译成有界、可追溯的上下文。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```text
|
|
6
|
+
项目代码与 Git → Context Runtime → Context Compiler → Agent / MCP / Hook
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
它不替代 Git、Issue 系统、项目文档、`CLAUDE.md`、`AGENTS.md` 或宿主 Skills:Git 仍是代码和文件变更的权威,文档仍负责设计,`fluffy-context` 只维护任务认知及其来源。
|
|
10
|
+
|
|
11
|
+
## 你可以用它做什么
|
|
12
|
+
|
|
13
|
+
- 保存和恢复进行中的任务、进度、待办、决策与风险。
|
|
14
|
+
- 让 Agent 只读取已验证的 Knowledge 和 Deadend,减少重复试错。
|
|
15
|
+
- 使用 `ctx compile` 生成带 provenance、纳入/排除原因和字符预算的 provider-neutral Manifest。
|
|
16
|
+
- 通过 MCP 或 Claude Code Hook 在会话开始时注入有界上下文。
|
|
17
|
+
- 可选记录经过 `.contextignored` 过滤的文件变化 metadata;默认关闭,不记录文件内容或 diff。
|
|
18
|
+
|
|
19
|
+
0.6.0 在 branch-aware 注入闭环上补齐了可治理的确定性检索:迁移并启用 Runtime 后,Orient 从 v2 journal 的可重建索引检索已验证、适用的 Knowledge 与 Deadend,并返回有界的选择、排除与截断说明。v1 的 checkpoint、Note、Knowledge 与 Deadend 写入仍会最佳努力镜像为 v2 事件;Runtime 也会协调检测到的外部 v1 变更。自动产物默认仍仅进入 Candidate,Verified Knowledge 仍需治理确认。0.6.6 已在此基础上完成无感 Runtime 生命周期的首个闭环:已迁移项目默认自动启动,Claude Hook、MCP 与 CLI Orient 可幂等唤醒 Runtime,显式 disable 仍保持永久禁用,启动失败继续 fail-open。
|
|
20
|
+
|
|
21
|
+
## 版本演进
|
|
22
|
+
|
|
23
|
+
| 版本 | 主要能力 | 关键特点 |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| 0.1.0 | 本地 Context CLI、baseline/patch Snapshot、resume、Note、Candidate Knowledge/Deadend | Git 继续作为代码权威;Context 只保存有界任务状态,不复制项目文件;checkpoint 显式触发且支持 no-op、限流与敏感路径过滤。 |
|
|
26
|
+
| 0.2.0 | 确定性 Knowledge Discovery、Agent TypeScript API、可安装 Skill | Candidate 与 Verified 分离;默认只注入已验证共识;不依赖向量库、模型或远端服务。 |
|
|
27
|
+
| 0.3.x | MCP `context_orient`、Claude Code Hook 与集成配置生成 | 通过 stdio MCP 和 fail-open Hook 降低 Agent 主动调用成本;集成安装仅在 `--apply` 时写入项目配置。 |
|
|
28
|
+
| 0.4.0 | v2 事件 journal、v1 显式迁移、可重建投影、本地 Runtime、Git 观察 | v2 与 v1 并存;NDJSON hash chain 是 v2 权威;Runtime 仅监听 loopback 并记录分支、ref 与 HEAD 元数据。 |
|
|
29
|
+
| 0.5.0 | branch-aware Orient、v1 写入镜像、Runtime 协调、宿主事件捕获 | Context 按当前 worktree/ref 选择,避免跨分支任务状态泄漏;稳定宿主 ID 才会写入限长、脱敏后的 session/prompt intent。 |
|
|
30
|
+
| 0.6.0 | journal 派生的确定性检索、治理终态、可解释 Orient、显式使用反馈 | 启用 v2 后直接从可重建索引检索已验证且适用的共识;使用反馈只影响稳定排序,绝不自动验证或提升 Candidate。 |
|
|
31
|
+
| 0.6.5 | Runtime 活跃度修复与 Hook 保活 | Git 真实状态变化、宿主 Hook 活动和认证 IPC 会刷新 Runtime;heartbeat 与无变化轮询不会伪装成活跃,Runtime 在不可用时保持 fail-open。 |
|
|
32
|
+
| 0.6.6 | 无感 Runtime 生命周期 | 通过 `ensureRuntimeForSession()` 在已迁移项目的首次会话、Claude Hook、MCP 握手或 CLI Orient 时幂等拉起 Runtime;显式 disable 保持禁用,启动失败继续 fail-open。 |
|
|
33
|
+
| 0.7.0 | Context Compiler 与文件活动基础能力 | 提供 `compileContext()`、`ctx compile`、provider-neutral `ContextManifest`、确定性候选排序、来源 provenance、纳入/排除说明、字符预算、v1/v2 来源和默认关闭的文件活动观察器。 |
|
|
34
|
+
| 0.7.1 | Correctness hardening 与显式文件监听开关 | 强化 policy 校验、journal schema/hash/幂等性验证、Runtime 清理、候选 ID 稳定性,并提供 `ctx filesystem enable|disable|status`;文件观察严格复用 `.contextignored` 过滤规则。 |
|
|
35
|
+
| 0.7.2 | 文件活动进入 Context Compiler | 将当前 branch/worktree/ref 的 `workspace.paths.changed` 活动作为有界 `activity` section 编译;支持 `--activity-limit`,再次执行 `.contextignored` 和内置敏感路径过滤,不记录内容或 diff。 |
|
|
36
|
+
|
|
37
|
+
所有版本均保持本地优先、显式治理与 fail-open 集成原则。v1 数据不会在迁移过程中被重写;当 v2 未启用、不可用、损坏或尚未同步时,支持回退的读取接口会回退到兼容的 v1 行为。0.7.x 的 `ctx compile`、journal verify 和 Runtime 文件观察均保留明确的来源、验证或过滤边界。
|
|
38
|
+
|
|
39
|
+
## 产品愿景与 1.0 前路线图
|
|
40
|
+
|
|
41
|
+
`fluffy-context` 的目标不是成为另一套规则、Memory 或 Agent 能力系统,而是成为本地优先、Agent 无关的 **Context Orchestrator(上下文编排层)**:在理解当前任务、项目、worktree/ref、工作状态与 Token Budget 后,选择并编译最适合当前 Agent 的有界上下文。
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
project → knowledge runtime → context compiler → LLM
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Git 继续是代码与文件变更的权威,Issue 系统继续负责工作项,项目文档继续承载设计;`AGENTS.md`、`CLAUDE.md`、`.cursor/rules`、宿主 Memory、Skills 与 MCP 工具也继续由各自宿主和原生格式维护。`fluffy-context` 不复制、改写或同步这些外部主体;它只维护任务感知的选择所需元数据、引用与按输出需要截取的有界片段,并给出来源、优先级、纳入/排除原因与 Token 分配。
|
|
48
|
+
|
|
49
|
+
CLI 是 Runtime 面向用户的 console pane / frontend:它用于初始化、检视、治理、诊断与调试编译结果,而非产品认知本体。Claude、Cursor、MCP 和未来 IDE/Agent 集成同样只是可选适配器,不应成为核心 Runtime 的依赖。
|
|
50
|
+
|
|
51
|
+
| 计划版本 | 核心目标 | 主要能力 | 明确边界 |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| 0.7.0 | Context Compiler 基础 | 提供版本化 `ContextSourceDescriptor`、`ContextIntent`、`ContextManifest`,将当前 Context、checkpoint、Note、v2 journal 派生来源和已验证 Knowledge/Deadend 统一编译为可追溯输入;按字符预算确定性选择、排序、截断并生成纳入/排除理由。 | 不自动把原始事件提炼为 Verified Knowledge;不重写、合并或同步外部规则;不做模型调用、向量/Embedding、远程注册表或 provider-specific Renderer。 |
|
|
54
|
+
| 0.8.0 | Decision Graph | 将 Decision 升级为可治理、可追溯的一等 journal 对象,记录结果、理由、备选方案、证据、适用性与生命周期;通过 `depends-on`、`supersedes`、`contradicts`、`supported-by`、`rejected-alternative`、`implemented-by` 等边构成确定性投影图;Compiler 只注入当前任务所需的有界决策子图。 | 不自动从代码或模型输出推断决策;不自动解决冲突;不自动提升 Candidate。 |
|
|
55
|
+
| 0.9.0 | Knowledge Evolution | 以受治理事件支持 Knowledge 的合并、拆分、替代、适用范围收窄/扩展、退役、归档,以及作为新记录的复活;根据 Git/path 事件、source anchor、Decision Graph 依赖、重复/冲突和适用性漂移生成确定性的 `review-needed` 信号;Compiler 优先选择新鲜、适用且已验证的认知。 | 自动机制只能提出待审查候选,不能自动验证、降级、归档或作出真实性结论;不引入远程同步、团队权限、强制模型提供方或语义向量依赖。 |
|
|
56
|
+
|
|
57
|
+
### 0.6.6 Runtime 生命周期
|
|
58
|
+
|
|
59
|
+
0.6.6 的目标是消除用户反复执行 `ctx runtime start` 的负担。Runtime 已成为本地后台基础设施,而不是用户或 Agent 必须理解和操作的功能。核心 Runtime 保持 Agent 无关;Claude Code、MCP、CLI、IDE Extension 和其他宿主都只能通过可选 adapter 发出统一的活动信号。
|
|
60
|
+
|
|
61
|
+
已迁移项目默认启用自动启动。首次会话、Claude Hook、MCP 握手或 CLI Orient 到达时,会通过幂等的 `ensureRuntimeForSession()` 检查 v2 policy 与有效 lease,复用启动锁避免重复进程,并在严格短超时内尽力拉起 Runtime。启动失败、宿主没有对应 hook 或 Runtime 暂时不可用时,宿主工作流仍继续,保持 fail-open;后续用户或 Agent 活动可再次唤醒,而不要求手动重复启动。显式执行 `ctx runtime disable` 会持久化禁用状态,直到再次执行 `ctx runtime enable`。
|
|
62
|
+
|
|
63
|
+
当前 Runtime 使用 `active` 与 inactivity stop 的轻量模型:认证 IPC、Hook、MCP、CLI 和真实 Git 状态变化会刷新活跃度;heartbeat 与无变化轮询只维护健康状态,不会伪装成用户活动。更完整的 `limited`、`idle`、`sleep`、`destroyed` 生命周期状态机,以及统一的 session、tool、file 和 explicit-end 信号,属于后续版本设计。
|
|
64
|
+
|
|
65
|
+
生命周期适配器不绑定某个 Agent 的内部实现:适配器只负责归一化宿主事件,Runtime 核心不把 inactivity 超时推断当作可靠的 agent-end 事实。当前可可靠捕获的 Claude 事件仍受宿主提供的 Hook 和稳定标识限制。
|
|
66
|
+
|
|
67
|
+
低开销、隐私优先的 Git/file activity summary 仍属于后续版本范围:只记录经过过滤的相对路径、计数、状态变化和摘要 metadata,不记录原始命令、stdout、diff 或文件内容;事件必须 debounce/coalesce,并作为后续 Context Compiler 的候选证据,而不是自动验证的 Knowledge。
|
|
6
68
|
|
|
7
|
-
|
|
69
|
+
### 1.0 发布门槛
|
|
70
|
+
|
|
71
|
+
1. **稳定契约**:Context Source Descriptor、Context Manifest/Compiler、Decision Graph、Knowledge Evolution、只读 MCP 与 Agent API 具有明确的版本化兼容契约。
|
|
72
|
+
2. **正确性与恢复**:编译与 journal replay 可确定性复现;hash chain 验证、投影 rebuild/repair、迁移一致性、损坏回退与 Windows/macOS/Linux 支持完善。
|
|
73
|
+
3. **治理与隐私**:外部来源始终保持原生权威;持久化和输出前均应用敏感信息过滤;每个注入的项目认知都可追溯、适用且具有受治理生命周期。
|
|
74
|
+
4. **集成中立**:Claude、Cursor 与未来宿主均为可选适配器;核心不依赖特定模型、IDE、SaaS、网络或向量数据库。
|
|
75
|
+
5. **运行质量**:延迟与存储有界,Runtime 健康状态可观测,选择与截断可解释,适配器不可用时保持 fail-open。
|
|
76
|
+
6. **产品表达一致**:文档与 API 明确 `ctx` 是 Runtime 的前端;`fluffy-context` 是对上下文进行编排的 Runtime,而不是仓库规则、Memory、Skills 或 MCP 能力的替代品。
|
|
77
|
+
|
|
78
|
+
上述路线图描述的是 `0.6.6` 及之后的演进方向。0.6.5 提供 Runtime 活跃度修复与 Hook 保活;0.6.6 已提供已迁移项目的无感自动启动与 fail-open 唤醒。更完整的生命周期状态机、Git/file activity summary 和被动学习仍属于后续版本范围。
|
|
8
79
|
|
|
9
80
|
## 适用场景
|
|
10
81
|
|
|
@@ -66,6 +137,39 @@ ctx orient
|
|
|
66
137
|
ctx orient --context <context-id> --note-limit 10
|
|
67
138
|
```
|
|
68
139
|
|
|
140
|
+
### 0.7.x Context Compiler
|
|
141
|
+
|
|
142
|
+
`ctx orient` 面向快速恢复,`ctx compile` 面向需要结构化输入的 Agent 或适配器。Compiler 只读当前 Context、Snapshot、open Note、已验证 Knowledge/Deadend 及可用的 v2 来源,返回 JSON Manifest:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
ctx compile "修复支付回调" --max-chars 4000
|
|
146
|
+
ctx compile "验证签名逻辑" --scenario verification --paths src/auth.ts
|
|
147
|
+
ctx compile "查看最近修改" --activity-limit 10 --max-chars 4000
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Manifest 包含 `intent`、`selected`、`sections`、`excluded`、`provenance`、`budget` 和最终 `text`。`maxChars` 使用 JavaScript UTF-16 字符串长度;Compiler 不调用模型、不写入 Context 或 journal,重复输入会得到确定性结果。普通查询默认只纳入已验证 Knowledge 和 Deadend,Candidate、deprecated、rejected、obsolete 等记录会明确排除。
|
|
151
|
+
|
|
152
|
+
0.7.2 新增的 `activity` section 来自已记录的 `workspace.paths.changed` 事件,只包含近期当前 branch/worktree/ref 的相对路径和有限 metadata。它表示“观察到文件发生变化”,不表示文件已被读取、理解或测试;不包含内容、diff、命令或输出。`--activity-limit 0` 可在单次编译中关闭 activity 候选,且不会修改 Runtime 的文件监听策略。v1 fallback 没有等价的文件活动来源,因此返回空的 `activity` section。
|
|
153
|
+
|
|
154
|
+
### 文件变化观察
|
|
155
|
+
|
|
156
|
+
文件监听是可选能力,默认关闭。要显式开启:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
ctx filesystem enable
|
|
160
|
+
ctx filesystem status
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
关闭监听:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
ctx filesystem disable
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
如果 Runtime 已在运行,enable/disable 会自动按新策略重启 Runtime;如果 Runtime 尚未运行,只更新 policy。观察器只记录项目相对路径、文件类型、大小和修改时间等有限 metadata,不记录文件内容、diff、命令或输出。
|
|
170
|
+
|
|
171
|
+
文件路径会经过与 Context 关联文件相同的 `.contextignored` 规则过滤。被 `.contextignored` 排除的文件,即使发生创建、修改或删除,也不会写入 `workspace.paths.changed` 事件;即使历史事件中存在这类路径,Compiler 也会再次过滤。内置保护规则仍然优先排除 `.context/`、`.git/`、依赖/构建目录、环境变量、密钥和越界路径。
|
|
172
|
+
|
|
69
173
|
## Agent 工作流
|
|
70
174
|
|
|
71
175
|
推荐阶段:
|
|
@@ -93,7 +197,11 @@ ctx note add "测试环境缺少回调凭据" --kind problem --context <context-
|
|
|
93
197
|
ctx activity --context <context-id> --open
|
|
94
198
|
ctx knowledge discover "支付回调"
|
|
95
199
|
ctx knowledge verify <knowledge-id>
|
|
200
|
+
ctx knowledge deprecate <knowledge-id> --reason "已被新的结论取代"
|
|
96
201
|
ctx deadend verify <deadend-id>
|
|
202
|
+
ctx deadend obsolete <deadend-id> --reason "当前架构已不再适用"
|
|
203
|
+
ctx feedback use knowledge <knowledge-id> --event-id <stable-id>
|
|
204
|
+
ctx journal verify
|
|
97
205
|
ctx migrate v1 --dry-run
|
|
98
206
|
ctx migrate v1 --apply
|
|
99
207
|
ctx migrate verify
|
|
@@ -115,7 +223,7 @@ ctx migrate v1 --apply
|
|
|
115
223
|
ctx migrate verify
|
|
116
224
|
```
|
|
117
225
|
|
|
118
|
-
|
|
226
|
+
迁移成功后,Runtime 默认已启用自动启动;以下命令用于显式诊断、手动控制或持久化选择退出:
|
|
119
227
|
|
|
120
228
|
```bash
|
|
121
229
|
ctx runtime enable
|
|
@@ -127,9 +235,9 @@ ctx runtime disable
|
|
|
127
235
|
|
|
128
236
|
Runtime 是单项目、按需启动的本地守护进程。它只绑定 `127.0.0.1` 的动态端口,并要求存储在项目本地 `.context/v2/runtime/secret` 中的能力令牌;令牌不会显示在 CLI 状态输出或写入事件日志。启动后,Runtime 持续观察当前 worktree 的 Git 状态:初始状态会记录 `git.state.observed`,分支/ref 切换记录 `git.branch.changed`,HEAD 更新记录 `git.head.changed`。这些事件会重建 branch workspace 投影,但不会自动创建 checkpoint 或将候选信息提升为已验证共识。
|
|
129
237
|
|
|
130
|
-
|
|
238
|
+
完成迁移且未显式 disable 时,`ctx orient`、MCP `context_orient` 与 Claude Hook 会在严格短超时内幂等确保 Runtime 可用,并优先选择当前 worktree/ref 的 v2 workspace;它不会借用其他分支的 Context。v2 可用时,Knowledge 与 Deadend 由 journal 重放出的确定性倒排索引直接检索,默认仅返回已验证且适用的记录;无匹配 workspace、v2 状态不可用、journal 损坏、v1 尚未同步或 Runtime 已禁用时,接口会安全回退到既有 v1 选择逻辑。Runtime 停止时仍可读取已验证的 v2 状态,但运行中的 Runtime 负责持续 Git 观察和 v1 写入镜像。
|
|
131
239
|
|
|
132
|
-
Claude Hook 仅在宿主提供稳定的 session 与 event 标识时记录 `host.session.started` 或 `host.prompt.submitted`。提示只保存按 `promptIntentMaxChars` 截断并经过敏感值脱敏后的 intent
|
|
240
|
+
Claude Hook 仅在宿主提供稳定的 session 与 event 标识时记录 `host.session.started` 或 `host.prompt.submitted`。提示只保存按 `promptIntentMaxChars` 截断并经过敏感值脱敏后的 intent,绝不保存原始提示;缺少稳定标识时不写入事件。SessionStart 与 UserPromptSubmit 都会在严格短超时内尽力确保已迁移、未显式 disable 的项目 Runtime 可用;稳定标识仅影响宿主事件是否写入。启动或读取失败始终 fail open,不阻塞宿主工作流。
|
|
133
241
|
|
|
134
242
|
### `ctx checkpoint` 和 `ctx resume`
|
|
135
243
|
|
|
@@ -141,7 +249,11 @@ Claude Hook 仅在宿主提供稳定的 session 与 event 标识时记录 `host.
|
|
|
141
249
|
|
|
142
250
|
### Knowledge 与 Deadend
|
|
143
251
|
|
|
144
|
-
`ctx learn` 和 `ctx deadend` 默认创建 `candidate` 项。普通发现与 `ctx orient` 只使用已验证项目共识;候选项需要通过 `ctx knowledge verify` 或 `ctx deadend verify` 显式确认,或以 `--all`
|
|
252
|
+
`ctx learn` 和 `ctx deadend` 默认创建 `candidate` 项。普通发现与 `ctx orient` 只使用已验证项目共识;候选项需要通过 `ctx knowledge verify` 或 `ctx deadend verify` 显式确认,或以 `--all` 审查。验证后的 Knowledge 可用 `ctx knowledge deprecate` 退役,候选项可用 `ctx knowledge reject` 拒绝;验证后的 Deadend 可用 `ctx deadend obsolete` 退役,候选项可用 `ctx deadend reject` 拒绝。终态记录保留证据与治理原因,但不会被默认注入。
|
|
253
|
+
|
|
254
|
+
新记录默认具有 `global` 适用性。需要限制到当前 worktree/ref 时,可使用 `--branch-mode exact`;`--paths` 只保存精确项目相对路径约束,当前版本不会推断目录前缀、Git 祖先关系、依赖关系或语义相似路径。`ctx orient` 的 `explanation` 字段会有界地给出 v2/v1 选择方式、排除计数和各类别截断原因。
|
|
255
|
+
|
|
256
|
+
`ctx feedback use knowledge|deadend ... --event-id <stable-id>` 只记录一个幂等的 v2 使用信号。它只作为同等词法相关性结果的确定性排序因素,永不改变验证状态、confidence、evidence 或适用性;Orient、MCP 与 Hook 不会隐式写入该信号。
|
|
145
257
|
|
|
146
258
|
```bash
|
|
147
259
|
ctx learn "订单取消后不能再次进入支付中状态" --scope project
|
|
@@ -222,6 +334,6 @@ npm pack --dry-run --json
|
|
|
222
334
|
|
|
223
335
|
## 当前范围
|
|
224
336
|
|
|
225
|
-
0.
|
|
337
|
+
0.6.0 聚焦单项目、本地优先、可治理的 branch-aware Knowledge Runtime MVP:有界且可解释的 Orient、显式 checkpoint、journal 派生的确定性 Knowledge/Deadend 检索、终态治理、显式使用反馈、MCP `context_orient`、可选 Claude Code Hook,以及 v1 到 v2 的显式事件日志迁移和 Git-aware 本地 Runtime。完成迁移并启用 Runtime 后,Orient、MCP 与 Hook 使用当前 worktree/ref 的 workspace 选择分支正确的 Context,并在 v2 不可用时保持 v1 回退;Runtime 负责可靠捕获生命周期、Git 元数据与后续 v1 写入镜像。带稳定宿主标识的 Hook 事件仅以脱敏、限长 intent 进入 journal。
|
|
226
338
|
|
|
227
339
|
远程同步、多人协作、复杂语义检索、自动模型总结、自动 checkpoint、Context merge、自动验证候选共识,以及更多状态变更型 MCP 工具不属于当前版本范围。
|
package/dist/src/agent/api.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { AgentLoadOptions, AgentLoadResult, AgentSaveResult, CheckpointInput, ContextSearchOptions, ContextSearchResult } from '../runtime/types.js';
|
|
2
|
-
import type { ContextOrientOptions, ContextOrientResult } from './types.js';
|
|
2
|
+
import type { ContextOrientOptions, ContextOrientResult, ContextUseInput } from './types.js';
|
|
3
3
|
export declare function saveContext(startPath: string | undefined, input: CheckpointInput, options?: {
|
|
4
4
|
minSaveIntervalMs?: number;
|
|
5
5
|
}): Promise<AgentSaveResult>;
|
|
6
6
|
export declare function loadContext(startPath: string | undefined, options?: AgentLoadOptions): Promise<AgentLoadResult>;
|
|
7
7
|
export declare function contextOrient(startPath: string | undefined, options?: ContextOrientOptions): Promise<ContextOrientResult>;
|
|
8
|
+
export declare function recordContextUse(startPath: string | undefined, input: ContextUseInput): Promise<{
|
|
9
|
+
recorded: boolean;
|
|
10
|
+
eventId: string;
|
|
11
|
+
}>;
|
|
8
12
|
export declare function searchContext(startPath: string | undefined, query: string, options?: ContextSearchOptions): Promise<ContextSearchResult>;
|
package/dist/src/agent/api.js
CHANGED
|
@@ -3,7 +3,9 @@ import { resolveProjectRoot } from '../project/project-resolver.js';
|
|
|
3
3
|
import { contextsRoot, contextMetadataPath } from '../storage/layout.js';
|
|
4
4
|
import { isRecord, readJson } from '../storage/json-store.js';
|
|
5
5
|
import { checkpoint, rebuildSnapshot, resume, resumeSnapshot } from '../runtime/runtime.js';
|
|
6
|
+
import { recordUse } from '../cognition/feedback.js';
|
|
6
7
|
import { selectV2Orientation } from '../cognition/orient.js';
|
|
8
|
+
import { discoverV2Deadends, discoverV2Knowledge } from '../cognition/retrieval.js';
|
|
7
9
|
import { discoverDeadends, discoverKnowledge, listDeadends } from '../runtime/knowledge.js';
|
|
8
10
|
import { listNotes } from '../runtime/notes.js';
|
|
9
11
|
function normalized(value) {
|
|
@@ -176,6 +178,12 @@ export async function contextOrient(startPath, options = {}) {
|
|
|
176
178
|
deadends: emptyDeadends(query ?? ''),
|
|
177
179
|
notes: [],
|
|
178
180
|
truncated: false,
|
|
181
|
+
explanation: {
|
|
182
|
+
mode: 'v1-fallback',
|
|
183
|
+
selection: 'v1',
|
|
184
|
+
retrieval: { knowledge: {}, deadends: {} },
|
|
185
|
+
truncation: { summary: false, knowledge: false, deadends: false, notes: false },
|
|
186
|
+
},
|
|
179
187
|
};
|
|
180
188
|
}
|
|
181
189
|
throw error;
|
|
@@ -187,26 +195,30 @@ export async function contextOrient(startPath, options = {}) {
|
|
|
187
195
|
limit: v2 ? Number.MAX_SAFE_INTEGER : options.noteLimit ?? 20,
|
|
188
196
|
maxChars: options.maxChars ?? 4000,
|
|
189
197
|
})).filter((note) => !v2 || v2.noteIds.has(note.noteId)).slice(0, options.noteLimit ?? 20);
|
|
190
|
-
const
|
|
198
|
+
const v2Knowledge = query === null || !v2 ? null : discoverV2Knowledge(v2.retrieval, query, v2.currentGit, {
|
|
199
|
+
scope: options.scope,
|
|
200
|
+
limit: options.knowledgeLimit ?? 10,
|
|
201
|
+
maxChars: options.maxChars ?? 4000,
|
|
202
|
+
});
|
|
203
|
+
const v2Deadends = query === null || !v2 ? null : discoverV2Deadends(v2.retrieval, query, v2.currentGit, {
|
|
204
|
+
scope: options.scope,
|
|
205
|
+
limit: options.deadendLimit ?? 10,
|
|
206
|
+
maxChars: options.maxChars ?? 4000,
|
|
207
|
+
});
|
|
208
|
+
const applicableKnowledge = query === null
|
|
191
209
|
? emptyKnowledge('')
|
|
192
|
-
: await discoverKnowledge(projectRoot, query, {
|
|
210
|
+
: v2Knowledge?.result ?? await discoverKnowledge(projectRoot, query, {
|
|
193
211
|
scope: options.scope,
|
|
194
|
-
limit:
|
|
212
|
+
limit: options.knowledgeLimit ?? 10,
|
|
195
213
|
maxChars: options.maxChars ?? 4000,
|
|
196
214
|
});
|
|
197
|
-
const
|
|
215
|
+
const applicableDeadends = query === null
|
|
198
216
|
? emptyDeadends('')
|
|
199
|
-
: await discoverDeadends(projectRoot, query, {
|
|
217
|
+
: v2Deadends?.result ?? await discoverDeadends(projectRoot, query, {
|
|
200
218
|
scope: options.scope,
|
|
201
|
-
limit:
|
|
219
|
+
limit: options.deadendLimit ?? 10,
|
|
202
220
|
maxChars: options.maxChars ?? 4000,
|
|
203
221
|
});
|
|
204
|
-
const applicableKnowledge = v2
|
|
205
|
-
? { ...knowledge, total: knowledge.hits.filter((hit) => v2.knowledgeIds.has(hit.knowledge.knowledgeId)).length, hits: knowledge.hits.filter((hit) => v2.knowledgeIds.has(hit.knowledge.knowledgeId)).slice(0, options.knowledgeLimit ?? 10) }
|
|
206
|
-
: knowledge;
|
|
207
|
-
const applicableDeadends = v2
|
|
208
|
-
? { ...deadends, total: deadends.hits.filter((hit) => v2.deadendIds.has(hit.deadend.deadendId)).length, hits: deadends.hits.filter((hit) => v2.deadendIds.has(hit.deadend.deadendId)).slice(0, options.deadendLimit ?? 10) }
|
|
209
|
-
: deadends;
|
|
210
222
|
const budget = { remaining: Math.max(0, options.maxChars ?? 4000) };
|
|
211
223
|
const resumeSummary = {
|
|
212
224
|
progressSummary: limited(loaded.resumeSummary.progressSummary, budget),
|
|
@@ -252,8 +264,25 @@ export async function contextOrient(startPath, options = {}) {
|
|
|
252
264
|
deadends: limitedDeadendResult.result,
|
|
253
265
|
notes: limitedNotesResult.notes,
|
|
254
266
|
truncated: resumeTruncated || limitedKnowledgeResult.truncated || limitedDeadendResult.truncated || limitedNotesResult.truncated,
|
|
267
|
+
explanation: {
|
|
268
|
+
mode: v2 ? 'v2' : 'v1-fallback',
|
|
269
|
+
selection: v2?.selection ?? 'v1',
|
|
270
|
+
retrieval: {
|
|
271
|
+
knowledge: v2Knowledge?.exclusions ?? {},
|
|
272
|
+
deadends: v2Deadends?.exclusions ?? {},
|
|
273
|
+
},
|
|
274
|
+
truncation: {
|
|
275
|
+
summary: resumeTruncated,
|
|
276
|
+
knowledge: limitedKnowledgeResult.truncated,
|
|
277
|
+
deadends: limitedDeadendResult.truncated,
|
|
278
|
+
notes: limitedNotesResult.truncated,
|
|
279
|
+
},
|
|
280
|
+
},
|
|
255
281
|
};
|
|
256
282
|
}
|
|
283
|
+
export async function recordContextUse(startPath, input) {
|
|
284
|
+
return recordUse(startPath, input);
|
|
285
|
+
}
|
|
257
286
|
export async function searchContext(startPath, query, options = {}) {
|
|
258
287
|
const projectRoot = await resolveProjectRoot(startPath);
|
|
259
288
|
const cleanQuery = query.trim();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export * from './api.js';
|
|
2
|
-
export type { ContextOrientContext, ContextOrientNoContextResult, ContextOrientOptions, ContextOrientReadyResult, ContextOrientResult, ContextOrientSnapshot, } from './types.js';
|
|
2
|
+
export type { ContextOrientContext, ContextUseInput, ContextOrientExplanation, ContextOrientNoContextResult, ContextOrientOptions, ContextOrientReadyResult, ContextOrientResult, ContextOrientSnapshot, } from './types.js';
|
|
3
3
|
export type { AgentLoadOptions, AgentLoadResult, AgentSaveResult, ContextSearchHit, ContextSearchOptions, ContextSearchResult, } from '../runtime/types.js';
|
|
4
|
+
export { compileContext } from '../compiler/compile.js';
|
|
5
|
+
export type { ContextActivityRecord, ContextAnchor, ContextBudget, ContextBudgetReport, ContextCandidate, ContextCandidateSection, ContextCompileOptions, ContextExclusion, ContextExclusionReason, ContextIntent, ContextIntentSignal, ContextManifest, ContextProvenance, ContextScenario, ContextSourceDescriptor, ContextTruncation, } from '../compiler/types.js';
|
package/dist/src/agent/index.js
CHANGED
|
@@ -23,6 +23,25 @@ export interface ContextOrientSnapshot {
|
|
|
23
23
|
branch: string | null;
|
|
24
24
|
commit: string | null;
|
|
25
25
|
}
|
|
26
|
+
export interface ContextUseInput {
|
|
27
|
+
entity: 'knowledge' | 'deadend';
|
|
28
|
+
entityId: string;
|
|
29
|
+
eventId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ContextOrientExplanation {
|
|
32
|
+
mode: 'v2' | 'v1-fallback';
|
|
33
|
+
selection: 'requested-context' | 'exact-worktree-ref' | 'legacy-ref-branch' | 'v1';
|
|
34
|
+
retrieval: {
|
|
35
|
+
knowledge: Record<'status_not_verified' | 'applicability_mismatch' | 'scope_mismatch' | 'query_no_match' | 'result_limit', number> | {};
|
|
36
|
+
deadends: Record<'status_not_verified' | 'applicability_mismatch' | 'scope_mismatch' | 'query_no_match' | 'result_limit', number> | {};
|
|
37
|
+
};
|
|
38
|
+
truncation: {
|
|
39
|
+
summary: boolean;
|
|
40
|
+
knowledge: boolean;
|
|
41
|
+
deadends: boolean;
|
|
42
|
+
notes: boolean;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
26
45
|
export interface ContextOrientReadyResult {
|
|
27
46
|
status: 'ready';
|
|
28
47
|
projectRoot: string;
|
|
@@ -34,6 +53,7 @@ export interface ContextOrientReadyResult {
|
|
|
34
53
|
deadends: DeadendDiscoveryResult;
|
|
35
54
|
notes: Note[];
|
|
36
55
|
truncated: boolean;
|
|
56
|
+
explanation: ContextOrientExplanation;
|
|
37
57
|
}
|
|
38
58
|
export interface ContextOrientNoContextResult {
|
|
39
59
|
status: 'no_context';
|
|
@@ -46,5 +66,6 @@ export interface ContextOrientNoContextResult {
|
|
|
46
66
|
deadends: DeadendDiscoveryResult;
|
|
47
67
|
notes: Note[];
|
|
48
68
|
truncated: false;
|
|
69
|
+
explanation: ContextOrientExplanation;
|
|
49
70
|
}
|
|
50
71
|
export type ContextOrientResult = ContextOrientReadyResult | ContextOrientNoContextResult;
|