fluffy-context 0.6.0 → 0.7.6
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 +494 -115
- package/dist/src/agent/api.d.ts +2 -0
- package/dist/src/agent/api.js +5 -0
- package/dist/src/agent/index.d.ts +3 -0
- package/dist/src/agent/index.js +2 -0
- package/dist/src/cli/main.js +125 -6
- 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 +100 -4
- package/dist/src/cognition/migration-v1.js +1 -1
- package/dist/src/cognition/orient.js +4 -3
- package/dist/src/cognition/policy.d.ts +4 -0
- package/dist/src/cognition/policy.js +49 -0
- package/dist/src/cognition/projections.js +15 -1
- package/dist/src/cognition/runtime.d.ts +20 -1
- package/dist/src/cognition/runtime.js +229 -53
- package/dist/src/cognition/types.d.ts +16 -0
- package/dist/src/cognition/v1-bridge.js +3 -2
- 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 +353 -0
- package/dist/src/compiler/expand.d.ts +2 -0
- package/dist/src/compiler/expand.js +187 -0
- package/dist/src/compiler/identity.d.ts +6 -0
- package/dist/src/compiler/identity.js +36 -0
- package/dist/src/compiler/sources.d.ts +19 -0
- package/dist/src/compiler/sources.js +126 -0
- package/dist/src/compiler/types.d.ts +233 -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 +167 -11
- package/dist/src/runtime/runtime.js +10 -0
- package/dist/src/runtime/types.d.ts +1 -1
- package/dist/src/storage/layout.d.ts +1 -0
- package/dist/src/storage/layout.js +3 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
- package/skills/fluffy-context/SKILL.md +10 -3
package/README.md
CHANGED
|
@@ -1,225 +1,517 @@
|
|
|
1
|
-
#
|
|
1
|
+
# fluffy-context
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本地优先、Agent 无关的 Context 与 Knowledge Runtime,帮助 AI 编程 Agent 保存任务状态、恢复工作上下文、复用已验证共识,并生成有界且可追溯的上下文输入。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**当前版本:0.7.6**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```text
|
|
8
|
+
checkpoint → orient → compile → expand → feedback → Agent continues
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`compile` 先返回有界的 summary 候选;Agent 只对需要的候选调用 `expand` 获取 structured 或 evidence 层。`feedback` 仍必须由调用方显式记录。
|
|
12
|
+
|
|
13
|
+
`fluffy-context` 保存的是任务认知,不是项目代码备份。Git 仍是代码和文件变更的权威;Issue 系统、项目文档、`CLAUDE.md`、`AGENTS.md`、Skills 和 MCP 仍由各自系统维护。
|
|
8
14
|
|
|
9
|
-
##
|
|
15
|
+
## 30 秒了解
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
| --- | --- | --- |
|
|
13
|
-
| 0.1.0 | 本地 Context CLI、baseline/patch Snapshot、resume、Note、Candidate Knowledge/Deadend | Git 继续作为代码权威;Context 只保存有界任务状态,不复制项目文件;checkpoint 显式触发且支持 no-op、限流与敏感路径过滤。 |
|
|
14
|
-
| 0.2.0 | 确定性 Knowledge Discovery、Agent TypeScript API、可安装 Skill | Candidate 与 Verified 分离;默认只注入已验证共识;不依赖向量库、模型或远端服务。 |
|
|
15
|
-
| 0.3.x | MCP `context_orient`、Claude Code Hook 与集成配置生成 | 通过 stdio MCP 和 fail-open Hook 降低 Agent 主动调用成本;集成安装仅在 `--apply` 时写入项目配置。 |
|
|
16
|
-
| 0.4.0 | v2 事件 journal、v1 显式迁移、可重建投影、本地 Runtime、Git 观察 | v2 与 v1 并存;NDJSON hash chain 是 v2 权威;Runtime 仅监听 loopback 并记录分支、ref 与 HEAD 元数据。 |
|
|
17
|
-
| 0.5.0 | branch-aware Orient、v1 写入镜像、Runtime 协调、宿主事件捕获 | Context 按当前 worktree/ref 选择,避免跨分支任务状态泄漏;稳定宿主 ID 才会写入限长、脱敏后的 session/prompt intent。 |
|
|
18
|
-
| 0.6.0 | journal 派生的确定性检索、治理终态、可解释 Orient、显式使用反馈 | 启用 v2 后直接从可重建索引检索已验证且适用的共识;使用反馈只影响稳定排序,绝不自动验证或提升 Candidate。 |
|
|
17
|
+
最常用的四类操作:
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
- `ctx checkpoint`:保存进度、完成项、待办、决策、风险和关联文件。
|
|
20
|
+
- `ctx orient`:只读恢复当前任务,并检索匹配的已验证 Knowledge、Deadend 和 open Note。
|
|
21
|
+
- `ctx compile`:生成带预算、来源和排除原因的 provider-neutral Context Manifest。
|
|
22
|
+
- `ctx learn` / `ctx deadend`:记录可复用结论和失败方案,之后显式验证再用于普通检索。
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## 0.7.6 当前能力与边界
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
| 能力 | 当前支持 |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| Context | 初始化、结构化 checkpoint、baseline/patch Snapshot、resume |
|
|
29
|
+
| 检索 | `orient`、已验证 Knowledge/Deadend 检索、当前 Context 的 open Note |
|
|
30
|
+
| Compiler | 确定性排序、字符预算、截断信息、provenance、纳入/排除原因 |
|
|
31
|
+
| Manifest identity | `level`、`itemHash`、`manifestHash`、estimated token |
|
|
32
|
+
| 文件活动 | 可选记录经过过滤的文件 metadata,并编译为 `activity` section |
|
|
33
|
+
| Runtime | 本地 v2 Runtime、Git 观察、可选文件观察、自动唤醒和 fail-open 集成 |
|
|
34
|
+
| 治理 | Knowledge/Deadend 的 candidate、verify、deprecate/obsolete、reject |
|
|
35
|
+
| 集成 | Claude Code Hook、Claude Code 配置集成、MCP `context_orient`/`context_expand`、TypeScript Agent API |
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
以下能力**不属于 0.7.6**:
|
|
31
38
|
|
|
32
|
-
-
|
|
33
|
-
-
|
|
39
|
+
- 没有 `ctx clean` 或 `ctx report`。
|
|
40
|
+
- 不自动创建 checkpoint、Note、Knowledge 或 Deadend。
|
|
41
|
+
- 不自动把 Candidate 提升为 Verified。
|
|
42
|
+
- 不提供模型总结、Embedding/向量检索、远程同步、多人协作或 Context merge。
|
|
43
|
+
|
|
44
|
+
0.7.6 已支持 `context_expand`,用于按需取得已选候选的 `structured` 或 `evidence` 层;它是无状态、只读操作,不读取项目文件内容,也不自动记录 feedback。
|
|
45
|
+
|
|
46
|
+
## 快速开始
|
|
34
47
|
|
|
35
|
-
|
|
48
|
+
### 1. 安装
|
|
49
|
+
|
|
50
|
+
要求 Node.js `>=20.19.0`。Git 可选;在 Git 项目中,Runtime 会记录当前 branch、ref 和 commit 等 metadata。
|
|
36
51
|
|
|
37
52
|
```bash
|
|
38
53
|
npm install --global fluffy-context
|
|
39
|
-
ctx --
|
|
54
|
+
ctx --version
|
|
40
55
|
```
|
|
41
56
|
|
|
42
|
-
|
|
57
|
+
在源码工作树中开发时:
|
|
43
58
|
|
|
44
59
|
```bash
|
|
45
|
-
|
|
60
|
+
npm install
|
|
61
|
+
npm run build
|
|
62
|
+
npm install --global .
|
|
46
63
|
```
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
### 2. 初始化项目
|
|
49
66
|
|
|
50
|
-
|
|
67
|
+
在项目根目录运行:
|
|
51
68
|
|
|
52
69
|
```bash
|
|
53
70
|
ctx init
|
|
54
71
|
```
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
也可以显式指定路径:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
ctx init --path path/to/project
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
初始化会创建本地 `.context/` 存储和 `.contextignored` 规则文件。重复执行是幂等的,不会覆盖已有 Context 或忽略规则。
|
|
80
|
+
|
|
81
|
+
### 3. 保存第一个工作状态
|
|
57
82
|
|
|
58
83
|
```bash
|
|
59
84
|
ctx checkpoint \
|
|
60
|
-
--title "
|
|
61
|
-
--progress "
|
|
62
|
-
--completed "
|
|
63
|
-
--pending "
|
|
64
|
-
--decisions "
|
|
85
|
+
--title "支付回调修复" \
|
|
86
|
+
--progress "已定位签名校验失败原因" \
|
|
87
|
+
--completed "复现问题,确认失败边界" \
|
|
88
|
+
--pending "补充回归测试,运行集成测试" \
|
|
89
|
+
--decisions "在回调入口统一执行签名校验" \
|
|
65
90
|
--risks "第三方回调可能重复到达" \
|
|
66
|
-
--files "src/
|
|
91
|
+
--files "src/payment/callback.ts,test/payment/callback.test.ts"
|
|
67
92
|
```
|
|
68
93
|
|
|
69
|
-
|
|
94
|
+
第一次包含实际结构化内容的 checkpoint 会创建 baseline Snapshot;后续变化会创建 patch Snapshot。
|
|
95
|
+
|
|
96
|
+
- 内容没有变化时返回 `status: "no_change"`。
|
|
97
|
+
- 默认两次实际写入之间至少间隔约 10 秒;变化过快时返回 `status: "rate_limited"` 和 `retryAt`。
|
|
98
|
+
- 只有标题、没有实际结构化内容的 checkpoint 不会创建无意义 Snapshot。
|
|
99
|
+
- `--last-error ""`、空列表等显式输入可以清理已有字段。
|
|
100
|
+
|
|
101
|
+
查看当前状态:
|
|
70
102
|
|
|
71
103
|
```bash
|
|
72
|
-
ctx
|
|
104
|
+
ctx status
|
|
105
|
+
ctx resume --max-chars 2000
|
|
73
106
|
```
|
|
74
107
|
|
|
75
|
-
|
|
108
|
+
### 4. 在下一次会话开始时恢复
|
|
76
109
|
|
|
77
110
|
```bash
|
|
78
|
-
ctx orient
|
|
79
|
-
ctx orient --context <context-id> --note-limit 10
|
|
111
|
+
ctx orient "支付回调签名校验" --max-chars 4000
|
|
80
112
|
```
|
|
81
113
|
|
|
82
|
-
|
|
114
|
+
不带查询时只恢复当前任务和 open Note:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
ctx orient
|
|
118
|
+
```
|
|
83
119
|
|
|
84
|
-
|
|
120
|
+
## 推荐工作流
|
|
85
121
|
|
|
86
122
|
```text
|
|
87
123
|
Orient → Plan → Implement → Verify → Handoff
|
|
88
124
|
```
|
|
89
125
|
|
|
90
|
-
1. **Orient
|
|
91
|
-
2. **Plan
|
|
92
|
-
3. **Implement
|
|
93
|
-
4. **Verify
|
|
94
|
-
5. **Handoff
|
|
126
|
+
1. **Orient**:开始任务时读取当前 Context 和已验证共识。
|
|
127
|
+
2. **Plan**:先形成可执行的实现计划。
|
|
128
|
+
3. **Implement**:遇到重要观察、阻塞或临时决策时记录 Note。
|
|
129
|
+
4. **Verify**:运行适用的测试、构建或其他检查。
|
|
130
|
+
5. **Handoff**:阶段结束时显式执行一次 checkpoint,记录完成项、待办、决策和风险。
|
|
131
|
+
|
|
132
|
+
Hook 只提供有界、只读的阶段提示,不会自动创建 Note 或 checkpoint。Runtime 捕获文件和 Git metadata,也不能替代 Agent 主动记录任务认知。
|
|
95
133
|
|
|
96
|
-
##
|
|
134
|
+
## 核心命令
|
|
97
135
|
|
|
98
|
-
|
|
136
|
+
### `ctx orient`
|
|
137
|
+
|
|
138
|
+
`orient` 是新会话和新任务的快速恢复入口:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
ctx orient "身份认证回调" \
|
|
142
|
+
--scope project \
|
|
143
|
+
--max-chars 4000 \
|
|
144
|
+
--knowledge-limit 5 \
|
|
145
|
+
--deadend-limit 5 \
|
|
146
|
+
--note-limit 10
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
它返回:
|
|
150
|
+
|
|
151
|
+
- 当前 Context 和 Snapshot 的有限 metadata;
|
|
152
|
+
- 受字符预算限制的进度、错误、完成项、待办、决策、风险和关联文件;
|
|
153
|
+
- 匹配且适用的已验证 Knowledge 和 Deadend;
|
|
154
|
+
- 当前 Context 尚未吸收的 open Note;
|
|
155
|
+
- v1/v2 选择方式、排除计数和截断说明。
|
|
156
|
+
|
|
157
|
+
`orient` 是只读操作:不会创建 Snapshot、不会写入 Context、不会更新 `lastUsedAt`,也不会隐式记录 usage feedback。
|
|
158
|
+
|
|
159
|
+
返回 `status: "no_context"` 表示项目已初始化,但还没有可恢复的有效 Context;这不是系统错误。
|
|
160
|
+
|
|
161
|
+
### `ctx compile`
|
|
162
|
+
|
|
163
|
+
`compile` 面向需要结构化输入的 Agent、适配器和集成方,返回 provider-neutral JSON Manifest:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
ctx compile "修复支付回调" --max-chars 4000
|
|
167
|
+
ctx compile "验证签名逻辑" --scenario verification --paths src/payment/callback.ts
|
|
168
|
+
ctx compile "查看最近修改" --activity-limit 10 --max-chars 4000
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Manifest 主要包含:
|
|
172
|
+
|
|
173
|
+
- `intent`:规范化后的任务意图、场景、scope、paths 和预算;
|
|
174
|
+
- `selected`:最终纳入的候选项;
|
|
175
|
+
- `sections`:按 Context、Snapshot、Note、Knowledge、Deadend、Activity 等来源分组;
|
|
176
|
+
- `excluded`:未纳入项目及其原因;
|
|
177
|
+
- `provenance`:来源 Context、Snapshot、journal event 和读取状态;
|
|
178
|
+
- `budget`:请求、使用、剩余字符和 section 统计;
|
|
179
|
+
- `truncation`:预算或候选限制造成的截断说明;
|
|
180
|
+
- `identity`:Manifest hash、选中 item hash 和 estimated token;
|
|
181
|
+
- `text`:最终有界文本。
|
|
182
|
+
|
|
183
|
+
0.7.6 的候选项提供:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
level: signal | summary | structured | evidence
|
|
187
|
+
itemHash
|
|
188
|
+
tokenEstimate
|
|
189
|
+
expandable
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
当前实际生成的候选项默认是 `summary` 层。`itemHash`、`manifestHash` 和 estimated token 可用于缓存、去重、审计和结果校验;token 是按字符估算的 provider-neutral 数值,不是真实 Provider 计费结果。
|
|
193
|
+
|
|
194
|
+
### `ctx expand`
|
|
195
|
+
|
|
196
|
+
`expand` 只接受本次 `compile` 返回的 selected candidate,并重新使用原始编译参数校验 `manifestHash`。调用方至少提供 `--candidate-id` 或 `--item-hash`,并选择 `--level structured|evidence`:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
ctx compile "修复支付回调" --max-chars 4000 > manifest.json
|
|
200
|
+
ctx expand --manifest-hash <manifestHash> --candidate-id <candidateId> \
|
|
201
|
+
--level structured --compile-max-chars 4000 --query "修复支付回调"
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`--compile-max-chars` 必须与原始 compile 的预算一致;`--max-chars` 是独立的展开输出预算。展开返回 `complete` 时包含完整 structured content,超过预算则返回有界文本、`content: null` 和 `status: partial`。它不缓存 Manifest、不写入 Context/journal/projection、不执行 usage feedback,也不读取文件正文、diff、命令或 stdout/stderr。
|
|
205
|
+
|
|
206
|
+
Compiler 具有以下边界:
|
|
207
|
+
|
|
208
|
+
- 相同输入得到确定性的排序、截断和 hash;
|
|
209
|
+
- `maxChars` 使用 JavaScript UTF-16 字符串长度;
|
|
210
|
+
- 不调用模型;
|
|
211
|
+
- 不写入 Context 或 journal;
|
|
212
|
+
- 普通查询默认只纳入适用且已验证的 Knowledge 和 Deadend;
|
|
213
|
+
- `context_expand` 只读取已选候选的安全 metadata,不读取任意项目文件内容。
|
|
214
|
+
|
|
215
|
+
## Knowledge、Deadend 和 Note
|
|
216
|
+
|
|
217
|
+
### Knowledge:记录可复用认知
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
ctx learn "支付回调必须验证网关签名" \
|
|
221
|
+
--scope project \
|
|
222
|
+
--evidence "src/payment/callback.ts,回归测试"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
新记录默认是 `candidate`,不会进入普通检索。确认后才会进入默认发现:
|
|
99
226
|
|
|
100
227
|
```bash
|
|
101
|
-
ctx init
|
|
102
|
-
ctx checkpoint --title "修复支付回调" --progress "已定位签名校验失败原因"
|
|
103
|
-
ctx resume --max-chars 2000
|
|
104
|
-
ctx orient "支付回调" --knowledge-limit 5 --deadend-limit 3
|
|
105
|
-
ctx note add "测试环境缺少回调凭据" --kind problem --context <context-id>
|
|
106
|
-
ctx activity --context <context-id> --open
|
|
107
|
-
ctx knowledge discover "支付回调"
|
|
108
228
|
ctx knowledge verify <knowledge-id>
|
|
109
|
-
ctx knowledge
|
|
229
|
+
ctx knowledge discover "支付回调"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
治理已有记录:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
ctx knowledge deprecate <knowledge-id> --reason "已被新的签名校验流程取代"
|
|
236
|
+
ctx knowledge reject <knowledge-id> --reason "证据不足"
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
普通 `orient` 和 `discover` 默认只使用 `verified` 且适用的 Knowledge。需要审查候选或其他状态时,使用 `--all` 或显式 `--status`。
|
|
240
|
+
|
|
241
|
+
### Deadend:记录已验证不可行方案
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
ctx deadend \
|
|
245
|
+
--attempt "绕过回调签名验证" \
|
|
246
|
+
--reason "回归测试失败且会引入安全风险" \
|
|
247
|
+
--scope project \
|
|
248
|
+
--evidence "test/payment/callback.test.ts"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
确认和治理:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
110
254
|
ctx deadend verify <deadend-id>
|
|
111
255
|
ctx deadend obsolete <deadend-id> --reason "当前架构已不再适用"
|
|
112
|
-
ctx
|
|
113
|
-
ctx journal verify
|
|
114
|
-
ctx migrate v1 --dry-run
|
|
115
|
-
ctx migrate v1 --apply
|
|
116
|
-
ctx migrate verify
|
|
117
|
-
ctx runtime enable
|
|
118
|
-
ctx runtime start
|
|
119
|
-
ctx runtime status
|
|
120
|
-
ctx runtime stop
|
|
121
|
-
ctx status
|
|
122
|
-
ctx doctor
|
|
256
|
+
ctx deadend reject <deadend-id> --reason "失败证据不足"
|
|
123
257
|
```
|
|
124
258
|
|
|
125
|
-
|
|
259
|
+
Deadend 默认也是 `candidate`;只有 `verified` Deadend 才会进入普通检索。终态记录会保留治理原因,但不会默认注入。
|
|
260
|
+
|
|
261
|
+
### Note:低成本记录过程信息
|
|
126
262
|
|
|
127
|
-
|
|
263
|
+
Note 不创建 Snapshot,适合开发过程中记录短期观察、问题、行动和决策:
|
|
128
264
|
|
|
129
265
|
```bash
|
|
130
|
-
ctx
|
|
131
|
-
|
|
132
|
-
|
|
266
|
+
ctx note add "测试环境缺少回调凭据" \
|
|
267
|
+
--kind problem \
|
|
268
|
+
--context <context-id>
|
|
269
|
+
|
|
270
|
+
ctx note add "保留原始请求体后再执行验签" \
|
|
271
|
+
--kind decision \
|
|
272
|
+
--status resolved \
|
|
273
|
+
--context <context-id>
|
|
133
274
|
```
|
|
134
275
|
|
|
135
|
-
|
|
276
|
+
查看 Note 和只读 Activity:
|
|
136
277
|
|
|
137
278
|
```bash
|
|
138
|
-
ctx
|
|
139
|
-
ctx
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
279
|
+
ctx note list --context <context-id> --open
|
|
280
|
+
ctx activity --context <context-id> --open
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
阶段性 checkpoint 可以显式吸收当前 Context 的 open Note:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
ctx checkpoint \
|
|
287
|
+
--context <context-id> \
|
|
288
|
+
--progress "完成阶段排查" \
|
|
289
|
+
--absorb-notes
|
|
143
290
|
```
|
|
144
291
|
|
|
145
|
-
|
|
292
|
+
只有真正保存了新 Snapshot 时 Note 才会被标记为已吸收;`no_change` 和 `rate_limited` 不会改变 Note。
|
|
293
|
+
|
|
294
|
+
## CLI 能力地图
|
|
295
|
+
|
|
296
|
+
完整参数请使用 `ctx <command> --help`。常用命令按用途分组如下。
|
|
297
|
+
|
|
298
|
+
### 日常使用
|
|
146
299
|
|
|
147
|
-
|
|
300
|
+
| 命令 | 用途 |
|
|
301
|
+
| --- | --- |
|
|
302
|
+
| `ctx init` | 初始化 `.context/` |
|
|
303
|
+
| `ctx checkpoint` | 保存 Context Snapshot |
|
|
304
|
+
| `ctx resume` | 恢复完整 Context 详情 |
|
|
305
|
+
| `ctx orient` | 读取有界任务上下文 |
|
|
306
|
+
| `ctx compile` | 生成结构化 Context Manifest |
|
|
307
|
+
| `ctx note add/list` | 记录和查看 Note |
|
|
308
|
+
| `ctx activity` | 查看只读 Note/Snapshot 时间线 |
|
|
309
|
+
| `ctx status` | 查看项目和 Context 索引 |
|
|
310
|
+
| `ctx doctor` | 检查文件和 Snapshot 完整性 |
|
|
148
311
|
|
|
149
|
-
|
|
312
|
+
### Knowledge 与 Deadend 治理
|
|
313
|
+
|
|
314
|
+
```text
|
|
315
|
+
ctx learn
|
|
316
|
+
ctx knowledge
|
|
317
|
+
ctx knowledge discover
|
|
318
|
+
ctx knowledge verify
|
|
319
|
+
ctx knowledge deprecate
|
|
320
|
+
ctx knowledge reject
|
|
321
|
+
ctx deadend
|
|
322
|
+
ctx deadends
|
|
323
|
+
ctx deadend verify
|
|
324
|
+
ctx deadend obsolete
|
|
325
|
+
ctx deadend reject
|
|
326
|
+
ctx feedback use
|
|
327
|
+
```
|
|
150
328
|
|
|
151
|
-
|
|
329
|
+
`feedback use` 只记录显式的使用信号,用于确定性排序;不会改变 Knowledge/Deadend 的验证状态、confidence、证据或适用性。
|
|
152
330
|
|
|
153
|
-
|
|
331
|
+
### 集成入口
|
|
154
332
|
|
|
155
|
-
|
|
333
|
+
```text
|
|
334
|
+
ctx integrate claude inspect
|
|
335
|
+
ctx integrate claude install
|
|
336
|
+
ctx integrate claude install --apply
|
|
337
|
+
ctx hook claude-code session-start
|
|
338
|
+
ctx hook claude-code user-prompt
|
|
339
|
+
ctx agent serve
|
|
340
|
+
```
|
|
156
341
|
|
|
157
|
-
|
|
342
|
+
### 高级维护
|
|
158
343
|
|
|
159
|
-
|
|
344
|
+
```text
|
|
345
|
+
ctx migrate v1 --dry-run
|
|
346
|
+
ctx migrate v1 --apply
|
|
347
|
+
ctx migrate verify
|
|
348
|
+
ctx journal verify
|
|
349
|
+
ctx runtime enable
|
|
350
|
+
ctx runtime disable
|
|
351
|
+
ctx runtime start
|
|
352
|
+
ctx runtime stop
|
|
353
|
+
ctx runtime status
|
|
354
|
+
ctx filesystem enable
|
|
355
|
+
ctx filesystem disable
|
|
356
|
+
ctx filesystem status
|
|
357
|
+
```
|
|
160
358
|
|
|
161
|
-
|
|
359
|
+
CLI 业务命令默认输出 JSON;`--help` 是面向终端用户的纯文本;错误写入 stderr 并返回非零退出码;`ctx --version` 输出 JSON 字符串。
|
|
162
360
|
|
|
163
|
-
|
|
361
|
+
## 文件活动与 Runtime
|
|
164
362
|
|
|
165
|
-
|
|
363
|
+
文件观察默认关闭,需要显式开启:
|
|
166
364
|
|
|
167
365
|
```bash
|
|
168
|
-
ctx
|
|
169
|
-
ctx
|
|
170
|
-
ctx
|
|
366
|
+
ctx filesystem enable
|
|
367
|
+
ctx filesystem status
|
|
368
|
+
ctx filesystem disable
|
|
171
369
|
```
|
|
172
370
|
|
|
173
|
-
|
|
371
|
+
观察器只记录经过过滤的项目相对路径和有限 metadata,例如文件类型、大小和修改时间:
|
|
372
|
+
|
|
373
|
+
- 不记录文件内容、diff、命令或 stdout;
|
|
374
|
+
- 使用与 Context 关联文件相同的 `.contextignored` 和内置保护规则;
|
|
375
|
+
- `ctx compile` 的 `activity` 只表示“观察到文件发生变化”,不表示文件已被读取、理解或测试;
|
|
376
|
+
- `--activity-limit 0` 只关闭单次编译中的 activity 候选,不改变监听策略;
|
|
377
|
+
- v1 fallback 没有等价的文件活动来源,因此 activity section 可能为空。
|
|
174
378
|
|
|
175
|
-
|
|
379
|
+
完成 v1 迁移并启用 Runtime 后,Runtime 会服务于当前项目的 v2 journal、Git 观察和可选文件观察。常用控制命令:
|
|
176
380
|
|
|
177
381
|
```bash
|
|
178
|
-
ctx
|
|
382
|
+
ctx runtime status
|
|
383
|
+
ctx runtime enable
|
|
384
|
+
ctx runtime start
|
|
385
|
+
ctx runtime stop
|
|
386
|
+
ctx runtime disable
|
|
179
387
|
```
|
|
180
388
|
|
|
181
|
-
|
|
389
|
+
已启用项目的 CLI Orient、MCP 和 Claude Hook 会尽力自动唤醒 Runtime;启动失败不会阻塞基础读取流程。`runtime disable` 会持久化关闭自动启动,直到再次执行 `runtime enable`。
|
|
182
390
|
|
|
183
391
|
## Claude Code 集成
|
|
184
392
|
|
|
185
|
-
|
|
393
|
+
先检查当前项目:
|
|
186
394
|
|
|
187
395
|
```bash
|
|
188
396
|
ctx integrate claude inspect
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
默认安装命令只输出预览,不写文件:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
189
402
|
ctx integrate claude install
|
|
190
403
|
```
|
|
191
404
|
|
|
192
|
-
|
|
405
|
+
确认后显式应用:
|
|
193
406
|
|
|
194
407
|
```bash
|
|
195
408
|
ctx integrate claude install --apply
|
|
196
409
|
```
|
|
197
410
|
|
|
198
|
-
|
|
411
|
+
集成会幂等合并项目本地:
|
|
412
|
+
|
|
413
|
+
- `.claude/settings.json`:`SessionStart` 和 `UserPromptSubmit` Hook;
|
|
414
|
+
- `.mcp.json`:名为 `fluffy-context` 的 stdio MCP server。
|
|
415
|
+
|
|
416
|
+
它会保留无关的 Hook、权限和 MCP server;遇到无效 JSON、无效结构或同名冲突时拒绝覆盖。Hook 是 fail-open 的只读提示,不会自动创建 checkpoint 或 Note。
|
|
417
|
+
|
|
418
|
+
## MCP 集成
|
|
419
|
+
|
|
420
|
+
启动 MCP stdio server:
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
ctx agent serve
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
0.7.6 当前暴露以下工具:
|
|
427
|
+
|
|
428
|
+
```text
|
|
429
|
+
context_orient 只读、有界地获取任务上下文
|
|
430
|
+
context_expand 只读地展开 selected compiler candidate
|
|
431
|
+
context_compile 只读地生成确定性 Manifest
|
|
432
|
+
context_resume 恢复 Context(可能更新 lastUsedAt)
|
|
433
|
+
context_note_list 只读地列出 Note
|
|
434
|
+
context_note_add 显式新增 Note
|
|
435
|
+
context_checkpoint 显式保存 Context/Snapshot
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
输入字段与 CLI/Agent API 对齐:
|
|
439
|
+
|
|
440
|
+
- `context_orient`:`path`、`contextId`、`query`、`scope`、`maxChars` 和各 source limit;
|
|
441
|
+
- `context_compile`:编译选项及 `scenario`、`paths`、`activityLimit`、`trigger` 等字段;
|
|
442
|
+
- `context_expand`:`manifestHash`、`candidateId` 或 `itemHash`、`level`、独立 `maxChars` 和原始 `compile` 参数;
|
|
443
|
+
- `context_resume`:`contextId`、`maxChars`、`includeDetails`、`query`、`scope`;
|
|
444
|
+
- `context_note_list`:`contextId`、`openOnly`、`limit`、`maxChars`;
|
|
445
|
+
- `context_note_add`:必填 `message`,以及 Note 的 `kind`、`actor`、关联 Context/Snapshot、`relatedFiles` 和 `status`;
|
|
446
|
+
- `context_checkpoint`:Context 输入字段、`absorbNotes` 和可选的 `lastError`。
|
|
199
447
|
|
|
200
|
-
|
|
201
|
-
- `.mcp.json`:名为 `fluffy-context` 的 stdio MCP server,调用 `ctx agent serve`。
|
|
448
|
+
成功调用同时返回 JSON `content` 和 `structuredContent`。结果分别对应 CLI/Agent API 的 Manifest、load result、Note 列表、单个 Note 或 checkpoint result。Checkpoint 保留 `saved`、`no_change` 和 `rate_limited` 状态,MCP 不自动重试,也不暴露绕过限流的参数。
|
|
202
449
|
|
|
203
|
-
|
|
450
|
+
读写边界如下:
|
|
451
|
+
|
|
452
|
+
- `context_orient`、`context_expand`、`context_compile` 和 `context_note_list` 是只读操作;
|
|
453
|
+
- `context_resume` 使用现有 `loadContext` 语义,可能更新 `lastUsedAt`,但不会创建 Snapshot;
|
|
454
|
+
- `context_note_add` 会写入 Note,但不会创建 Snapshot;
|
|
455
|
+
- `context_checkpoint` 会创建或更新 Snapshot、Context metadata 和 index,并可显式吸收 Note;
|
|
456
|
+
- 任何工具都不会自动创建 Knowledge、Deadend、feedback 或重复 checkpoint;
|
|
457
|
+
- Knowledge/Deadend 的记录和治理暂不提供独立 MCP 工具,继续使用 CLI/Agent API。
|
|
458
|
+
|
|
459
|
+
MCP 的 stdin/stdout 属于协议通道,不能混入日志或交互文本。调用错误(包括输入验证、缺失 Context、空 Note message 和 stale Manifest hash)返回单次工具错误,server 继续运行。`context_expand` 与 CLI/Agent API 使用相同的无状态 Manifest hash 校验和 partial 预算语义。
|
|
204
460
|
|
|
205
461
|
## TypeScript Agent API
|
|
206
462
|
|
|
207
|
-
使用公开包入口,不要导入内部 `dist/...`
|
|
463
|
+
使用公开包入口,不要导入内部 `dist/...` 路径,也不要直接读写 `.context`:
|
|
208
464
|
|
|
209
465
|
```ts
|
|
210
|
-
import {
|
|
466
|
+
import {
|
|
467
|
+
contextOrient,
|
|
468
|
+
compileContext,
|
|
469
|
+
contextExpand,
|
|
470
|
+
saveContext,
|
|
471
|
+
loadContext,
|
|
472
|
+
searchContext,
|
|
473
|
+
} from 'fluffy-context';
|
|
211
474
|
|
|
212
475
|
const orientation = await contextOrient(process.cwd(), {
|
|
213
476
|
query: 'payment callback',
|
|
214
477
|
maxChars: 2400,
|
|
215
478
|
});
|
|
479
|
+
|
|
480
|
+
const manifest = await compileContext(process.cwd(), {
|
|
481
|
+
query: 'payment callback',
|
|
482
|
+
maxChars: 4000,
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
`fluffy-context/agent` 提供相同的公开入口。当前主要 API 包括:
|
|
487
|
+
|
|
488
|
+
```text
|
|
489
|
+
contextOrient
|
|
490
|
+
compileContext
|
|
491
|
+
contextExpand
|
|
492
|
+
saveContext
|
|
493
|
+
loadContext
|
|
494
|
+
searchContext
|
|
495
|
+
recordContextUse
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
Compiler identity 工具也通过公开入口导出:
|
|
499
|
+
|
|
500
|
+
```text
|
|
501
|
+
canonicalJson
|
|
502
|
+
contentHash
|
|
503
|
+
estimateTokens
|
|
504
|
+
rebuildManifestHash
|
|
505
|
+
validateManifestIdentity
|
|
216
506
|
```
|
|
217
507
|
|
|
218
|
-
`
|
|
508
|
+
存储布局不是公开兼容性承诺;调用方应根据返回结果处理 `status`、预算、截断和 fallback 信息。
|
|
219
509
|
|
|
220
|
-
##
|
|
510
|
+
## 安全与隐私边界
|
|
221
511
|
|
|
222
|
-
`.contextignored`
|
|
512
|
+
### `.contextignored`
|
|
513
|
+
|
|
514
|
+
`.contextignored` 使用接近 `.gitignore` 的规则排除不应作为关联文件保存的路径:
|
|
223
515
|
|
|
224
516
|
```gitignore
|
|
225
517
|
private/
|
|
@@ -227,9 +519,83 @@ private/
|
|
|
227
519
|
notes/draft-*
|
|
228
520
|
```
|
|
229
521
|
|
|
230
|
-
|
|
522
|
+
内置保护规则优先于项目规则,不能通过否定规则绕过。默认排除包括:
|
|
523
|
+
|
|
524
|
+
- `.context/`、`.git/`;
|
|
525
|
+
- `node_modules/`、`dist/`、`build/`、`coverage/` 等依赖和构建目录;
|
|
526
|
+
- `.env`、`.env.*`;
|
|
527
|
+
- `*.pem`、`*.key`、`*.p12`、`*.pfx`;
|
|
528
|
+
- 常见 credential、secret、token 文件;
|
|
529
|
+
- 绝对路径和 `..` 越界路径。
|
|
530
|
+
|
|
531
|
+
### 持久化边界
|
|
532
|
+
|
|
533
|
+
- checkpoint、Note、Knowledge 和 Deadend 会保存用户显式提供的结构化任务文本;
|
|
534
|
+
- 文件观察只保存过滤后的相对路径和 metadata,不保存内容或 diff;
|
|
535
|
+
- Claude Hook 不保存原始 prompt,只在具备稳定标识时保存限长、脱敏后的 intent;
|
|
536
|
+
- Runtime 仅绑定 `127.0.0.1`,使用项目本地能力令牌进行 IPC;令牌不会出现在状态输出或事件日志;
|
|
537
|
+
- 集成、Runtime 或 v2 读取失败时,支持回退的宿主流程保持 fail-open。
|
|
538
|
+
|
|
539
|
+
## v1 迁移
|
|
540
|
+
|
|
541
|
+
已有 v1 `.context/` 数据时,先只读检查,再显式导入:
|
|
542
|
+
|
|
543
|
+
```bash
|
|
544
|
+
ctx migrate v1 --dry-run
|
|
545
|
+
ctx migrate v1 --apply
|
|
546
|
+
ctx migrate verify
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
- `--dry-run` 只检查,不创建 v2 数据;
|
|
550
|
+
- `--apply` 才会追加 v1 provenance 事件;
|
|
551
|
+
- 迁移不会重写或修复 v1 文件;
|
|
552
|
+
- v1 与 v2 可以并存;
|
|
553
|
+
- v2 不可用、损坏或尚未同步时,支持回退的读取接口继续使用 v1 行为;
|
|
554
|
+
- `ctx journal verify` 可验证 v2 journal 的 hash chain 和记录完整性。
|
|
555
|
+
|
|
556
|
+
## 常见问题
|
|
231
557
|
|
|
232
|
-
|
|
558
|
+
### `ctx orient` 返回 `no_context`
|
|
559
|
+
|
|
560
|
+
项目已初始化,但还没有包含实际内容的有效 checkpoint。运行:
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
ctx checkpoint --title "当前任务" --progress "记录当前进度"
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### checkpoint 返回 `rate_limited`
|
|
567
|
+
|
|
568
|
+
这是默认写入保护,不是保存损坏。查看返回的 `retryAt`,完成更多阶段工作后再保存,不要循环重试。
|
|
569
|
+
|
|
570
|
+
### 为什么文件没有进入 Snapshot 的 `relatedFiles`
|
|
571
|
+
|
|
572
|
+
先检查 `.contextignored` 和内置保护规则。敏感、构建、依赖、绝对路径和越界路径会被排除,即使使用否定规则也不能绕过。
|
|
573
|
+
|
|
574
|
+
### Context 找不到怎么办
|
|
575
|
+
|
|
576
|
+
确认当前项目路径和 Context ID,然后运行:
|
|
577
|
+
|
|
578
|
+
```bash
|
|
579
|
+
ctx status --path path/to/project
|
|
580
|
+
ctx doctor --path path/to/project
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Git branch/ref 漂移通常是提示,不等于 Context 被删除。
|
|
584
|
+
|
|
585
|
+
### 为什么 `--help` 不能用 JSON.parse
|
|
586
|
+
|
|
587
|
+
输出类型不同:
|
|
588
|
+
|
|
589
|
+
- `ctx --help`:纯文本;
|
|
590
|
+
- `ctx --version`:JSON 字符串;
|
|
591
|
+
- 业务命令:格式化 JSON;
|
|
592
|
+
- 错误:stderr 和非零退出码。
|
|
593
|
+
|
|
594
|
+
### Windows 下从 Node 子进程调用 `ctx`
|
|
595
|
+
|
|
596
|
+
交互式终端通常可以直接运行 `ctx`。从 Node `spawn` 或其他程序调用时,Windows npm 可能需要使用 `ctx.cmd`;不要把未经转义的用户输入拼接进 shell 命令。
|
|
597
|
+
|
|
598
|
+
## 开发与验证
|
|
233
599
|
|
|
234
600
|
```bash
|
|
235
601
|
npm install
|
|
@@ -239,10 +605,23 @@ npm run pack:check
|
|
|
239
605
|
npm pack --dry-run --json
|
|
240
606
|
```
|
|
241
607
|
|
|
242
|
-
|
|
608
|
+
发布包通过 `fluffy-context` 和 `fluffy-context/agent` 提供公开 Agent API,并包含 CLI、类型声明、README、LICENSE 和 `skills/fluffy-context/SKILL.md`。
|
|
609
|
+
|
|
610
|
+
## 未来方向
|
|
611
|
+
|
|
612
|
+
以下方向属于后续版本,不是 0.7.6 的当前能力:
|
|
613
|
+
|
|
614
|
+
| 方向 | 目标 |
|
|
615
|
+
| --- | --- |
|
|
616
|
+
| Context expansion | 在现有 `context_expand` 基础上继续完善更丰富的分层内容 |
|
|
617
|
+
| Decision Graph | 将决策变成可治理、可追溯的一等对象 |
|
|
618
|
+
| Knowledge Evolution | 支持知识合并、替代、范围演化和 review-needed 信号 |
|
|
619
|
+
| Journal maintenance | 提供安全的清理、归档和长期运行维护能力 |
|
|
620
|
+
| Usage reporting | 统计估算 token、编译、展开、检索和反馈覆盖情况(`ctx report`) |
|
|
621
|
+
| 外部协作 | 远程同步、多人协作和团队权限 |
|
|
243
622
|
|
|
244
|
-
|
|
623
|
+
这些方向不会改变当前的边界:Git、项目文档和宿主规则继续由各自系统负责;Candidate 仍需要显式治理;模型调用和远程服务不是核心 Runtime 的隐式依赖。
|
|
245
624
|
|
|
246
|
-
|
|
625
|
+
## License
|
|
247
626
|
|
|
248
|
-
|
|
627
|
+
MIT
|