@calcit/procs 0.12.33 → 0.12.35
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/.yarn/install-state.gz +0 -0
- package/README.md +16 -15
- package/editing-history/2026-0223-2321-ns-imports-code-fixes.md +1 -1
- package/editing-history/2026-0227-1958-tree-rewrite-command-and-reference-model.md +1 -1
- package/editing-history/2026-0304-1548-impl-new-dot-method-input-and-doc-hints.md +2 -2
- package/editing-history/2026-0306-1552-core-schema-and-hintfn-migration.md +1 -1
- package/editing-history/2026-0307-1302-calcit-agent-docs-update.md +1 -1
- package/editing-history/2026-0320-1229-query-window-3-with-parent-preview.md +7 -7
- package/editing-history/2026-0323-1137-command-echo-tool-output-cleanup.md +2 -2
- package/editing-history/2026-0410-0011-snapshot-empty-version-pipe-marker.md +1 -1
- package/editing-history/202604182041-cr-wasm-split-and-runtime-stability.md +1 -1
- package/lib/package.json +3 -3
- package/package.json +3 -3
- package/rfc/03-05-function-schema-dual-track-rfc.md +2 -2
- package/rfcs/05-12-program-diff-rfc.md +204 -0
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/README.md
CHANGED
|
@@ -54,23 +54,24 @@ cr eval 'range 100'
|
|
|
54
54
|
cr eval 'thread-first 100 range (map $ \ * % %)'
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
Run with a [
|
|
57
|
+
Run with a runtime snapshot such as [calcit.cirru](https://github.com/calcit-lang/lilac/blob/main/compact.cirru) (legacy filename: `compact.cirru`):
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
cr
|
|
60
|
+
cr calcit.cirru # run once (default)
|
|
61
|
+
cr compact.cirru # legacy filename still works
|
|
61
62
|
|
|
62
|
-
cr # by default, it picks `compact.cirru`
|
|
63
|
+
cr # by default, it picks `calcit.cirru`, then falls back to `compact.cirru`
|
|
63
64
|
|
|
64
65
|
cr -w # watch mode (explicit flag required)
|
|
65
66
|
```
|
|
66
67
|
|
|
67
|
-
By default Calcit reads `:init-fn` and `:reload-fn` inside `
|
|
68
|
+
By default Calcit reads `:init-fn` and `:reload-fn` inside `calcit.cirru` configs (falling back to `compact.cirru`). You may also specify functions,
|
|
68
69
|
|
|
69
70
|
```bash
|
|
70
71
|
cr --init-fn='app.main/main!' --reload-fn='app.main/reload!'
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
and even configure `:entries` in `
|
|
74
|
+
and even configure `:entries` in `calcit.cirru`:
|
|
74
75
|
|
|
75
76
|
```bash
|
|
76
77
|
cr --entry server
|
|
@@ -81,7 +82,7 @@ cr --entry server
|
|
|
81
82
|
It compiles to JavaScript and runs in consistet semantics. However it might require a lot of JavaScript interop.
|
|
82
83
|
|
|
83
84
|
```bash
|
|
84
|
-
cr js # compile to js, also picks `
|
|
85
|
+
cr js # compile to js, also picks `calcit.cirru` by default
|
|
85
86
|
cr js --emit-path=out/ # compile to js and save in `out/`
|
|
86
87
|
```
|
|
87
88
|
|
|
@@ -95,7 +96,7 @@ main_$x_(); // which corresponds to `main!` function in calcit
|
|
|
95
96
|
### Calcit Editor & Bundler
|
|
96
97
|
|
|
97
98
|
Install [Calcit Editor](https://github.com/calcit-lang/editor) and run `ct` to launch editor server,
|
|
98
|
-
which writes `
|
|
99
|
+
which writes `calcit.cirru` and `.compact-inc.cirru` on saving. Legacy `compact.cirru` remains compatible. Try launching example by cloning [Calcit Workflow](https://github.com/calcit-lang/calcit-workflow).
|
|
99
100
|
|
|
100
101
|
Read more in [Minimal Calcit](https://github.com/calcit-lang/minimal-calcit/blob/main/README.md) to learn how to code Calcit with a plain text editor.
|
|
101
102
|
|
|
@@ -116,10 +117,10 @@ When using the Calcit Runner through MCP:
|
|
|
116
117
|
|
|
117
118
|
1. **Start Runner**: Use `start_calcit_runner` to launch the background process. This automatically:
|
|
118
119
|
- Creates a `.calcit-tmp/` directory
|
|
119
|
-
- Copies the current `compact.cirru` as a temporary baseline
|
|
120
|
+
- Copies the current runtime snapshot (`calcit.cirru`, or legacy `compact.cirru`) as a temporary baseline
|
|
120
121
|
|
|
121
122
|
2. **Generate Incremental Updates**: After making changes to your code, use `generate_calcit_incremental` to:
|
|
122
|
-
- Compare current
|
|
123
|
+
- Compare current runtime snapshot with the temporary baseline
|
|
123
124
|
- Generate a `.compact-inc.cirru` file with only the changes
|
|
124
125
|
- Apply incremental updates to the running process
|
|
125
126
|
|
|
@@ -143,17 +144,17 @@ Run `caps` to download. Sources are downloaded into `~/.config/calcit/modules/`.
|
|
|
143
144
|
|
|
144
145
|
`:calcit-version` helps in check version, and provides hints in [CI](https://github.com/calcit-lang/setup-cr) environment.
|
|
145
146
|
|
|
146
|
-
To load modules, use `:modules` configuration and `
|
|
147
|
+
To load modules, use `:modules` configuration and the runtime snapshot file `calcit.cirru` (legacy: `compact.cirru`):
|
|
147
148
|
|
|
148
149
|
```cirru
|
|
149
150
|
:configs $ {}
|
|
150
|
-
:modules $ [] |memof/
|
|
151
|
+
:modules $ [] |memof/calcit.cirru |lilac/
|
|
151
152
|
```
|
|
152
153
|
|
|
153
154
|
Paths defined in `:modules` field are just loaded as files from `~/.config/calcit/modules/`,
|
|
154
|
-
i.e. `~/.config/calcit/modules/memof/
|
|
155
|
+
i.e. `~/.config/calcit/modules/memof/calcit.cirru`.
|
|
155
156
|
|
|
156
|
-
Modules that ends with `/`s are automatically suffixed `
|
|
157
|
+
Modules that ends with `/`s are automatically suffixed `calcit.cirru`, and still fall back to `compact.cirru` for compatibility.
|
|
157
158
|
|
|
158
159
|
### Development
|
|
159
160
|
|
|
@@ -169,13 +170,13 @@ cargo run --bin cr -- calcit/test.cirru js && yarn try-js
|
|
|
169
170
|
# run snippet
|
|
170
171
|
cargo run --bin cr -- eval 'range 100'
|
|
171
172
|
|
|
172
|
-
cr
|
|
173
|
+
cr calcit.cirru ir # compiles intermediate representation into program-ir.cirru
|
|
173
174
|
|
|
174
175
|
cr-wasm calcit/test-wasm.cirru # compile standalone wasm target to js-out/program.wasm
|
|
175
176
|
```
|
|
176
177
|
|
|
177
178
|
- [Cirru Parser](https://github.com/Cirru/parser.rs) for indentation-based syntax parsing.
|
|
178
|
-
- [Cirru EDN](https://github.com/Cirru/cirru-edn.rs) for `
|
|
179
|
+
- [Cirru EDN](https://github.com/Cirru/cirru-edn.rs) for runtime snapshot file parsing (`calcit.cirru` / legacy `compact.cirru`).
|
|
179
180
|
- [Ternary Tree](https://github.com/calcit-lang/ternary-tree.rs) for immutable list data structure.
|
|
180
181
|
|
|
181
182
|
Other tools:
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
- `tree` handler:将 `handle_structural` 更名为 `handle_rewrite`,并更新输出提示与错误信息。
|
|
13
13
|
- 结构引用处理:在 `tree` 中统一使用 `parse_with_references` + `process_node_with_references`。
|
|
14
14
|
- 文档更新:`docs/CalcitAgent.md` 与 `Agents.md` 全部改用 `tree rewrite` 与 `--with` 示例。
|
|
15
|
-
- 真实命令验证(基于 `demos/
|
|
15
|
+
- 真实命令验证(基于 `demos/calcit.cirru`):
|
|
16
16
|
- `tree replace` 可执行普通替换;
|
|
17
17
|
- `tree rewrite` 无 `--with` 会按预期报错;
|
|
18
18
|
- `tree rewrite` 携带 `--with` 可按预期执行。
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
- `yarn compile`
|
|
28
28
|
- `cargo test`
|
|
29
29
|
- `yarn check-all`
|
|
30
|
-
- `cargo run --bin cr -- demos/
|
|
31
|
-
- `cargo run --bin cr -- demos/
|
|
30
|
+
- `cargo run --bin cr -- demos/calcit.cirru query examples 'calcit.core/&impl::new'`
|
|
31
|
+
- `cargo run --bin cr -- demos/calcit.cirru query examples 'calcit.core/&impl:get'`
|
|
32
32
|
|
|
33
33
|
以上在本次改动后均通过。
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
- `cr --no-tips <subcommand> ...` - 隐藏所有编辑/查询命令输出的 "Tips:" 提示行(适合脚本/Agent 使用)
|
|
11
|
-
- 示例:`cr --no-tips demos/
|
|
11
|
+
- 示例:`cr --no-tips demos/calcit.cirru query def calcit.core/foldl`
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
**背景**:`aa21b3a` 提交新增了 `--no-tips` 全局开关(`TIPS_SUPPRESSED: AtomicBool`,通过 `suppress_tips()` 设置),文档中缺少记录。
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
## 验证
|
|
57
57
|
|
|
58
58
|
- `cargo check --bin cr` 通过。
|
|
59
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
59
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query find --help`
|
|
60
60
|
- 可见 `--detail-offset` 参数。
|
|
61
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
61
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search --help`
|
|
62
62
|
- `--start-path` 示例为点号格式。
|
|
63
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
63
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state -f respo.app.comp.todolist/comp-todolist --detail-offset 5`
|
|
64
64
|
- 输出降噪,路径为点号,窗口外压缩。
|
|
65
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
65
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state -f respo.app.comp.todolist/comp-todolist --detail-offset 0`
|
|
66
66
|
- 详情窗口为 `[0, 3)`,每条命中仅展示一行(优先父节点预览)。
|
|
67
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
67
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search state -f respo.app.comp.todolist/comp-todolist --detail-offset 0 --exact`
|
|
68
68
|
- 精确命中不再把 `states` 视觉误判为 `state`;且不显示“add --exact”提示。
|
|
69
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
69
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search-expr state -f respo.app.comp.todolist/comp-todolist --detail-offset 0`
|
|
70
70
|
- 输出样式一致(单行预览)。
|
|
71
|
-
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/
|
|
71
|
+
- `cargo run --bin cr -- /Users/jon.chen/repo/respo/respo/calcit.cirru query search-expr state -f respo.app.comp.todolist/comp-todolist --detail-offset 0 --exact`
|
|
72
72
|
- 结果为 `No matches found`,符合结构精确匹配预期。
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
- `cargo run --bin cr -- calcit/test.cirru query find render`
|
|
63
63
|
- `cargo run --bin cr -- calcit/test.cirru tree show app.main/test-json -p ''`
|
|
64
64
|
- `cargo run --bin cr -- calcit/test.cirru docs search chunk -f agent-advanced.md`
|
|
65
|
-
- `cargo run --bin cr -- demos/
|
|
66
|
-
- `cargo run --bin cr -- /tmp/calcit-cli-demo/
|
|
65
|
+
- `cargo run --bin cr -- demos/calcit.cirru docs check-md docs/CalcitAgent.md`
|
|
66
|
+
- `cargo run --bin cr -- /tmp/calcit-cli-demo/calcit.cirru tree replace ...` 多次人工检查 replace 输出形态
|
|
67
67
|
|
|
68
68
|
## 经验
|
|
69
69
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 背景
|
|
4
4
|
|
|
5
|
-
PR `snapshot-format` 新增了空 `configs.version` 的回归测试,但 GitHub Actions
|
|
5
|
+
PR `snapshot-format` 新增了空 `configs.version` 的回归测试,但 GitHub Actions 上加载运行时快照文件(`calcit.cirru` / legacy `compact.cirru`)时,`(:version ||)` 会解析成字符串 `"|"`,没有命中原先仅检查空白字符串的校验。
|
|
6
6
|
|
|
7
7
|
## 知识点
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## 经验与注意事项
|
|
13
13
|
|
|
14
|
-
-
|
|
14
|
+
- 对运行时快照文件(`calcit.cirru` / legacy `compact.cirru`)的修改必须通过 `cr edit`/`cr tree` 完成,避免文本直接编辑破坏结构。
|
|
15
15
|
- 在多项目联动(calcit + recollect)场景下,发布前验证至少应覆盖:
|
|
16
16
|
- calcit: `yarn check-all`
|
|
17
17
|
- recollect: `yarn test:cr`、`yarn test:js`、`yarn test:wasm`
|
package/lib/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.35",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/node": "^25.0
|
|
7
|
-
"typescript": "^6.0.
|
|
6
|
+
"@types/node": "^25.7.0",
|
|
7
|
+
"typescript": "^6.0.3"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"compile": "rm -rf lib && tsc",
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.35",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/node": "^25.0
|
|
7
|
-
"typescript": "^6.0.
|
|
6
|
+
"@types/node": "^25.7.0",
|
|
7
|
+
"typescript": "^6.0.3"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"compile": "rm -rf lib && tsc",
|
|
@@ -105,13 +105,13 @@
|
|
|
105
105
|
主示例:
|
|
106
106
|
|
|
107
107
|
```bash
|
|
108
|
-
cr demos/
|
|
108
|
+
cr demos/calcit.cirru cirru parse-edn "(:: :fn ({} (:generics ([] 'T 'U)) (:args ([] 'T :number)) (:rest :number) (:return (:: :tuple :ok 'U)) (:where ([] (:: 'Eq 'T)))))"
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
运行时数据验证:
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
|
-
cr demos/
|
|
114
|
+
cr demos/calcit.cirru eval "let ((schema (:: :fn ({} (:generics ([] 'T 'U)) (:args ([] 'T :number)) (:rest :number) (:return (:: :tuple :ok 'U)) (:where ([] (:: 'Eq 'T))))))) (println schema) (println (type-of schema)) , schema"
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
## 顶层定义与局部定义的分工
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# RFC: `cr analyze program-diff <GIT REF>`
|
|
2
|
+
|
|
3
|
+
状态:Draft
|
|
4
|
+
日期:2026-05-12
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. 概要
|
|
9
|
+
|
|
10
|
+
新增命令:
|
|
11
|
+
|
|
12
|
+
- `cr analyze program-diff <GIT REF>`
|
|
13
|
+
|
|
14
|
+
该命令从 Git 中读取指定版本的完整运行时快照文件(默认沿用当前 `cr` 的输入文件路径,优先 `calcit.cirru`,兼容旧文件名 `compact.cirru`),确保**历史版本**与**当前工作区版本**都能被正确解析为 Calcit snapshot,然后做**结构化 diff**。
|
|
15
|
+
|
|
16
|
+
输出目标不是纯文本行 diff,而是面向程序结构的树形 diff:
|
|
17
|
+
|
|
18
|
+
- 顶层展示 `package/configs/entries/files` 等结构;
|
|
19
|
+
- 文件层展示 `ns/defs`;
|
|
20
|
+
- definition 层展示 `doc/schema/examples/code`;
|
|
21
|
+
- `code/examples/ns.code` 内部继续深入到 Cirru 表达式节点级别;
|
|
22
|
+
- 无变化分支允许灰色折叠;
|
|
23
|
+
- 变更分支默认展开;
|
|
24
|
+
- 增加、删除、修改分别用不同符号和颜色表示。
|
|
25
|
+
|
|
26
|
+
## 2. 动机
|
|
27
|
+
|
|
28
|
+
当前针对运行时快照文件的版本对比主要依赖 Git 行 diff,但它有几个明显问题:
|
|
29
|
+
|
|
30
|
+
1. **对结构不友好**:`calcit.cirru`(兼容旧文件名 `compact.cirru`)是机器生成的 snapshot,行 diff 容易受格式、字段顺序和长表达式影响;
|
|
31
|
+
2. **对表达式内部变化不友好**:definition 代码改动往往是局部子树变化,行 diff 很难快速看出 AST 层面的增删改;
|
|
32
|
+
3. **对 LLM / CLI 阅读不友好**:调用 `git diff` 后很难一眼区分“只是某个 def 变了”还是“整个 namespace 被搬动了”;
|
|
33
|
+
4. **缺少 parse guard**:历史版本文件如果本身损坏,应该先明确报解析失败,而不是直接进入错误 diff。
|
|
34
|
+
|
|
35
|
+
因此需要一个基于 Calcit 自身 snapshot/Cirru 结构的 diff 命令。
|
|
36
|
+
|
|
37
|
+
## 3. 命令定义
|
|
38
|
+
|
|
39
|
+
```/dev/null/rfc.txt#L1-2
|
|
40
|
+
cr analyze program-diff <GIT REF>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
语义:
|
|
44
|
+
|
|
45
|
+
- `<GIT REF>` 可以是 `HEAD~1`、tag、branch、commit SHA 等;
|
|
46
|
+
- 当前侧使用 `cr` 输入路径(默认优先 `calcit.cirru`,兼容旧文件名 `compact.cirru`);
|
|
47
|
+
- 历史侧使用 `git show <ref>:<repo-relative-input-path>` 读取文件内容;
|
|
48
|
+
- 两边都必须先经过:
|
|
49
|
+
1. `cirru_edn::parse`
|
|
50
|
+
2. `snapshot::load_snapshot_data`
|
|
51
|
+
- 任一侧失败都直接返回错误并停止 diff。
|
|
52
|
+
|
|
53
|
+
## 4. 输出设计
|
|
54
|
+
|
|
55
|
+
### 4.1 总体结构
|
|
56
|
+
|
|
57
|
+
输出分 2 段:
|
|
58
|
+
|
|
59
|
+
1. Summary
|
|
60
|
+
2. Tree Diff
|
|
61
|
+
|
|
62
|
+
Summary 示例:
|
|
63
|
+
|
|
64
|
+
```/dev/null/rfc.txt#L1-6
|
|
65
|
+
# Program Diff
|
|
66
|
+
- ref: HEAD~1
|
|
67
|
+
- file: calcit.cirru
|
|
68
|
+
- parsed: ok / ok
|
|
69
|
+
- changes: ~12 +3 -1
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4.2 树形 diff 约定
|
|
73
|
+
|
|
74
|
+
参考 `cr analyze call-graph` 的树形展示风格,继续使用:
|
|
75
|
+
|
|
76
|
+
- `├──`
|
|
77
|
+
- `└──`
|
|
78
|
+
- `│`
|
|
79
|
+
|
|
80
|
+
在此基础上增加状态符号:
|
|
81
|
+
|
|
82
|
+
- `=` unchanged(灰色)
|
|
83
|
+
- `~` modified(黄色)
|
|
84
|
+
- `+` added(绿色)
|
|
85
|
+
- `-` removed(红色)
|
|
86
|
+
|
|
87
|
+
### 4.3 折叠策略
|
|
88
|
+
|
|
89
|
+
- `Unchanged` 子树默认只显示一行概要,并灰色折叠;
|
|
90
|
+
- `Modified` / `Added` / `Removed` 子树默认展开;
|
|
91
|
+
- root 总是展开;
|
|
92
|
+
- 叶子节点直接显示 old/new 摘要。
|
|
93
|
+
|
|
94
|
+
### 4.4 表达式内部 diff
|
|
95
|
+
|
|
96
|
+
对于 `code/examples/ns.code` 内部的 `Cirru`:
|
|
97
|
+
|
|
98
|
+
- 叶子变更显示 old/new;
|
|
99
|
+
- list 节点按子节点序列做结构化比对;
|
|
100
|
+
- 插入/删除节点要保留索引位置和节点摘要;
|
|
101
|
+
- 同位置替换优先显示为 `modified`,而不是简单拆成 delete+add;
|
|
102
|
+
- 整棵新增/删除表达式应继续展开其子结构。
|
|
103
|
+
|
|
104
|
+
## 5. 范围
|
|
105
|
+
|
|
106
|
+
本次只在 `calcit` 当前仓库内实现,不先抽到 `cirru_parser`:
|
|
107
|
+
|
|
108
|
+
- 先满足 CLI 工作流;
|
|
109
|
+
- diff 数据结构先放在当前项目中,便于快速迭代;
|
|
110
|
+
- 后续如果算法稳定,再考虑抽取成 Cirru parser / edn 侧通用模块。
|
|
111
|
+
|
|
112
|
+
## 6. 实现方案
|
|
113
|
+
|
|
114
|
+
### 6.1 新模块
|
|
115
|
+
|
|
116
|
+
新增库模块:
|
|
117
|
+
|
|
118
|
+
- `src/program_diff.rs`
|
|
119
|
+
|
|
120
|
+
职责:
|
|
121
|
+
|
|
122
|
+
1. 读取当前 snapshot 文件;
|
|
123
|
+
2. 从 git ref 读取历史 snapshot 文件;
|
|
124
|
+
3. 校验两边都能 parse/load;
|
|
125
|
+
4. 构建结构化 diff tree;
|
|
126
|
+
5. 生成适合终端的彩色树形输出。
|
|
127
|
+
|
|
128
|
+
### 6.2 CLI 接入
|
|
129
|
+
|
|
130
|
+
- `src/cli_args.rs`
|
|
131
|
+
- 为 `AnalyzeSubcommand` 增加 `ProgramDiff`;
|
|
132
|
+
- `src/bin/cr.rs`
|
|
133
|
+
- 将该命令作为 standalone analyze 命令优先处理;
|
|
134
|
+
- `src/bin/cli_handlers/command_echo.rs`
|
|
135
|
+
- 增加 command echo 渲染;
|
|
136
|
+
- `src/bin/cli_handlers/mod.rs`
|
|
137
|
+
- 导出 handler。
|
|
138
|
+
|
|
139
|
+
### 6.3 Git 文件读取
|
|
140
|
+
|
|
141
|
+
流程:
|
|
142
|
+
|
|
143
|
+
1. 用 `git rev-parse --show-toplevel` 找 repo root;
|
|
144
|
+
2. 将当前 `input` 解析成 repo-relative path;
|
|
145
|
+
3. 用 `git show <ref>:<relative-path>` 读取历史内容;
|
|
146
|
+
4. 若文件不存在、ref 不存在、或命令失败,则直接返回错误。
|
|
147
|
+
|
|
148
|
+
### 6.4 Diff 层级
|
|
149
|
+
|
|
150
|
+
优先按 snapshot 语义层比较:
|
|
151
|
+
|
|
152
|
+
1. `package`
|
|
153
|
+
2. `about`
|
|
154
|
+
3. `configs`
|
|
155
|
+
4. `entries`
|
|
156
|
+
5. `files`
|
|
157
|
+
6. `file.ns`
|
|
158
|
+
7. `file.defs`
|
|
159
|
+
8. `def.doc`
|
|
160
|
+
9. `def.schema`
|
|
161
|
+
10. `def.examples`
|
|
162
|
+
11. `def.code`
|
|
163
|
+
12. `Cirru` 子树
|
|
164
|
+
|
|
165
|
+
这样可以避免直接把整个运行时快照文件当作匿名 EDN 树来比,输出会更稳定、更可读。
|
|
166
|
+
|
|
167
|
+
### 6.5 Cirru 序列 diff
|
|
168
|
+
|
|
169
|
+
list 内部子节点对比采用“带替换代价的序列对齐”策略:
|
|
170
|
+
|
|
171
|
+
- 完全相等 => `match`
|
|
172
|
+
- 不相等但对位更合理 => `replace`
|
|
173
|
+
- 仅旧侧存在 => `remove`
|
|
174
|
+
- 仅新侧存在 => `insert`
|
|
175
|
+
|
|
176
|
+
这比单纯按索引逐位比较更适合表达式中间插入/删除节点的场景。
|
|
177
|
+
|
|
178
|
+
## 7. 预期收益
|
|
179
|
+
|
|
180
|
+
- 更适合 review `calcit.cirru`(兼容旧文件名 `compact.cirru`)的语义变化;
|
|
181
|
+
- 更容易理解大型 definition 的局部 AST 改动;
|
|
182
|
+
- 对 agent/LLM 更友好,能直接拿到层级化变化;
|
|
183
|
+
- 为后续抽象成 Cirru diff 模块提供实现样本。
|
|
184
|
+
|
|
185
|
+
## 8. 暂不处理
|
|
186
|
+
|
|
187
|
+
本 RFC 本轮不覆盖:
|
|
188
|
+
|
|
189
|
+
- 三方 merge;
|
|
190
|
+
- patch 应用;
|
|
191
|
+
- HTML/TUI 交互界面;
|
|
192
|
+
- 抽取到 `cirru_parser` crate;
|
|
193
|
+
- 和 `cr tree show` / `cr query def` 的统一 chunk/diff UI。
|
|
194
|
+
|
|
195
|
+
## 9. 后续可能扩展
|
|
196
|
+
|
|
197
|
+
后续可考虑继续增加:
|
|
198
|
+
|
|
199
|
+
- `--format json`
|
|
200
|
+
- `--no-color`
|
|
201
|
+
- `--expand-all`
|
|
202
|
+
- `--only <path-prefix>`
|
|
203
|
+
- `--git-path <path>`(脱离当前 input)
|
|
204
|
+
- 将 Cirru diff 算法下沉到 parser 层
|