@calcit/procs 0.12.35 → 0.12.37

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.
Files changed (37) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/README.md +44 -40
  3. package/{rfc → RFCs}/03-05-function-schema-dual-track-rfc.md +11 -12
  4. package/RFCs/05-31-generic-where-bounds-mfs.md +124 -0
  5. package/RFCs/06-01-generic-binding-unification-rfc.md +608 -0
  6. package/{rfc → RFCs}/README.md +1 -0
  7. package/build.rs +74 -1
  8. package/editing-history/2026-0526-0957-match-docs-check-md.md +24 -0
  9. package/editing-history/2026-0601-0003-update-callback-field-specialization.md +19 -0
  10. package/editing-history/2026-0601-0005-release-0.12.36.md +16 -0
  11. package/editing-history/2026-0601-2230-enum-struct-payload-docs.md +4 -0
  12. package/editing-history/2026-0601-2317-data-definition-where-bounds.md +6 -0
  13. package/editing-history/2026-0602-0114-data-definition-where-macro-followup.md +21 -0
  14. package/editing-history/202605210055-tree-show-cr-config-and-edit-cleanup.md +81 -0
  15. package/editing-history/202605312052-macro-schema-roundtrip-and-weak-types.md +6 -0
  16. package/editing-history/202605312059-ci-docs-test-and-fn-helper-tightening.md +3 -0
  17. package/editing-history/202605312105-map-generic-weak-types-followup.md +15 -0
  18. package/lib/calcit.procs.mjs +60 -3
  19. package/lib/js-record.mjs +1 -1
  20. package/lib/package.json +1 -1
  21. package/package.json +1 -1
  22. package/ts-src/calcit.procs.mts +65 -4
  23. package/ts-src/js-record.mts +1 -1
  24. /package/{rfc → RFCs}/02-04-runtime-traits-plan.md +0 -0
  25. /package/{rfc → RFCs}/02-14-project-modernization-roadmap.md +0 -0
  26. /package/{rfc → RFCs}/02-17-register-platform-api-rfc.md +0 -0
  27. /package/{rfc → RFCs}/02-18-language-theory-evolution-plan.md +0 -0
  28. /package/{rfc → RFCs}/02-23-optional-record-macro-plan.md +0 -0
  29. /package/{rfc → RFCs}/03-16-runtime-boundary-refactor-plan.md +0 -0
  30. /package/{rfc → RFCs}/03-18-query-def-tree-show-chunked-display-plan.md +0 -0
  31. /package/{rfc → RFCs}/04-13-call-arg-literal-rewrite-rfc.md +0 -0
  32. /package/{rfc → RFCs}/04-13-type-slot-mechanism-rfc.md +0 -0
  33. /package/{rfc → RFCs}/04-15-match-syntax-rfc.md +0 -0
  34. /package/{rfc → RFCs}/04-15-type-directed-optimization-catalog.md +0 -0
  35. /package/{rfc → RFCs}/04-15-wasm-compilation-feasibility.md +0 -0
  36. /package/{rfc → RFCs}/04-16-wasm-data-structures.md +0 -0
  37. /package/{rfcs → RFCs}/05-12-program-diff-rfc.md +0 -0
Binary file
package/README.md CHANGED
@@ -12,11 +12,17 @@ Core design:
12
12
 
13
13
  - Interpreter runs on Rust, extensible with Rust FFI
14
14
  - Persistent Data Structure
15
- - Structural Editor(with indentation-based syntax as a fallback)
15
+ - Indentation-based Cirru syntax, friendly to plain text editing
16
16
  - Lisp macros, functional style
17
17
  - Compiles to JavaScript in ES Modules, JavaScript Interop
18
18
  - Hot code swapping friendly
19
19
 
20
+ Current direction:
21
+
22
+ - `calcit.cirru` is the primary source snapshot; legacy `compact.cirru` is still compatible
23
+ - CLI-first development with `cr` and `caps`, designed to work well with AI agents in terminal workflows
24
+ - Better CLI editing and validation for CI, docs lookup, module management, and incremental updates
25
+
20
26
  ### Install ![GitHub Release](https://img.shields.io/github/v/release/calcit-lang/calcit)
21
27
 
22
28
  Build and install with Rust:
@@ -29,12 +35,12 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
29
35
  cargo install calcit
30
36
  ```
31
37
 
32
- 4 binaries are installed:
38
+ Installed binaries:
33
39
 
34
40
  - `calcit`, the runtime and js compiler
35
41
  - `cr-wasm`, standalone WASM codegen tool
36
42
  - `caps`, for downloading dependencies declared in `deps.cirru`
37
- - `bundle_calcit`, bundle code if you don't want to use Calcit Editor
43
+ - `bundle_calcit`, bundle code for distribution
38
44
 
39
45
  When installing from source, explicitly include both runners:
40
46
 
@@ -44,9 +50,9 @@ cargo install --path . --bin cr --bin cr-wasm --bin caps --bin bundle_calcit
44
50
 
45
51
  To use Calcit in GitHub Actions, try [setup-cr](https://github.com/calcit-lang/setup-cr).
46
52
 
47
- ### Usage
53
+ ### Quick Start
48
54
 
49
- Snippets evaluating:
55
+ Evaluate snippets:
50
56
 
51
57
  ```bash
52
58
  cr eval 'range 100'
@@ -54,7 +60,7 @@ cr eval 'range 100'
54
60
  cr eval 'thread-first 100 range (map $ \ * % %)'
55
61
  ```
56
62
 
57
- Run with a runtime snapshot such as [calcit.cirru](https://github.com/calcit-lang/lilac/blob/main/compact.cirru) (legacy filename: `compact.cirru`):
63
+ Run with a runtime snapshot such as `calcit.cirru` (legacy filename: `compact.cirru`):
58
64
 
59
65
  ```bash
60
66
  cr calcit.cirru # run once (default)
@@ -65,13 +71,13 @@ cr # by default, it picks `calcit.cirru`, then falls back to `compact.cirru`
65
71
  cr -w # watch mode (explicit flag required)
66
72
  ```
67
73
 
68
- By default Calcit reads `:init-fn` and `:reload-fn` inside `calcit.cirru` configs (falling back to `compact.cirru`). You may also specify functions,
74
+ By default Calcit reads `:init-fn` and `:reload-fn` from `calcit.cirru` configs (falling back to `compact.cirru`). You may also specify functions:
69
75
 
70
76
  ```bash
71
77
  cr --init-fn='app.main/main!' --reload-fn='app.main/reload!'
72
78
  ```
73
79
 
74
- and even configure `:entries` in `calcit.cirru`:
80
+ You may also configure `:entries` in `calcit.cirru`:
75
81
 
76
82
  ```bash
77
83
  cr --entry server
@@ -79,7 +85,7 @@ cr --entry server
79
85
 
80
86
  ### JavaScript codegen
81
87
 
82
- It compiles to JavaScript and runs in consistet semantics. However it might require a lot of JavaScript interop.
88
+ Calcit compiles to JavaScript with consistent semantics. In browser or Node projects, JavaScript interop is still expected.
83
89
 
84
90
  ```bash
85
91
  cr js # compile to js, also picks `calcit.cirru` by default
@@ -93,40 +99,28 @@ import { main_$x_, reload_$x_ } from "./js-out/app.main.mjs";
93
99
  main_$x_(); // which corresponds to `main!` function in calcit
94
100
  ```
95
101
 
96
- ### Calcit Editor & Bundler
97
-
98
- Install [Calcit Editor](https://github.com/calcit-lang/editor) and run `ct` to launch editor server,
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).
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.
102
-
103
- Read more in [Respo Calcit Workflow](https://github.com/calcit-lang/respo-calcit-workflow) to learn to create an MVC webpage with [Respo](http://respo-mvc.org/).
104
-
105
- ### MCP (Model Context Protocol) Support
106
-
107
- Calcit provides MCP server functionality for integration with AI assistants and development tools. The MCP server offers tools for:
102
+ ### CLI and Agent Workflow
108
103
 
109
- - **Code Management**: Read, write, and modify Calcit namespaces and definitions
110
- - **Project Operations**: Manage modules, dependencies, and configurations
111
- - **Calcit Runner**: Start/stop background runner processes with incremental updates
112
- - **Documentation**: Query API docs, reference materials, and dependency documentation
104
+ The recommended workflow is plain text editing plus CLI validation, often driven by an AI agent in terminal.
113
105
 
114
- #### Incremental File Processing
106
+ Common commands:
115
107
 
116
- When using the Calcit Runner through MCP:
117
-
118
- 1. **Start Runner**: Use `start_calcit_runner` to launch the background process. This automatically:
119
- - Creates a `.calcit-tmp/` directory
120
- - Copies the current runtime snapshot (`calcit.cirru`, or legacy `compact.cirru`) as a temporary baseline
108
+ ```bash
109
+ cr docs agents --full # read the current agent workflow guide
110
+ cr query search 'foo' # locate code by symbol or string
111
+ cr edit ... # structured edits for defs, imports, config, modules
112
+ cr js # compile once
113
+ cr js -w # watch mode
114
+ caps # install/update dependencies from deps.cirru
115
+ ```
121
116
 
122
- 2. **Generate Incremental Updates**: After making changes to your code, use `generate_calcit_incremental` to:
123
- - Compare current runtime snapshot with the temporary baseline
124
- - Generate a `.compact-inc.cirru` file with only the changes
125
- - Apply incremental updates to the running process
117
+ Calcit Editor is no longer the recommended path for everyday development. If you still need the older editor workflow, see [Calcit Editor](https://github.com/calcit-lang/editor).
126
118
 
127
- 3. **Check Results**: After generating the incremental file, always check the runner logs using `grab_calcit_runner_logs` to verify that updates were applied successfully.
119
+ Related examples and workflows:
128
120
 
129
- This workflow enables efficient hot-reloading during development without restarting the entire application.
121
+ - [Minimal Calcit](https://github.com/calcit-lang/minimal-calcit/blob/main/README.md)
122
+ - [Respo Calcit Workflow](https://github.com/calcit-lang/respo-calcit-workflow)
123
+ - [setup-cr](https://github.com/calcit-lang/setup-cr) for GitHub Actions
130
124
 
131
125
  ### Modules
132
126
 
@@ -142,7 +136,7 @@ This workflow enables efficient hot-reloading during development without restart
142
136
 
143
137
  Run `caps` to download. Sources are downloaded into `~/.config/calcit/modules/`. If a module contains `build.sh`, it will be executed mostly for compiling Rust dylibs.
144
138
 
145
- `:calcit-version` helps in check version, and provides hints in [CI](https://github.com/calcit-lang/setup-cr) environment.
139
+ `:calcit-version` helps with version checks and provides hints in [CI](https://github.com/calcit-lang/setup-cr).
146
140
 
147
141
  To load modules, use `:modules` configuration and the runtime snapshot file `calcit.cirru` (legacy: `compact.cirru`):
148
142
 
@@ -154,11 +148,11 @@ To load modules, use `:modules` configuration and the runtime snapshot file `cal
154
148
  Paths defined in `:modules` field are just loaded as files from `~/.config/calcit/modules/`,
155
149
  i.e. `~/.config/calcit/modules/memof/calcit.cirru`.
156
150
 
157
- Modules that ends with `/`s are automatically suffixed `calcit.cirru`, and still fall back to `compact.cirru` for compatibility.
151
+ Modules ending with `/` are automatically suffixed with `calcit.cirru`, and still fall back to `compact.cirru` for compatibility.
158
152
 
159
153
  ### Development
160
154
 
161
- I use these commands to run local examples:
155
+ Local validation commands:
162
156
 
163
157
  ```bash
164
158
  # run tests in Rust
@@ -175,6 +169,16 @@ cr calcit.cirru ir # compiles intermediate representation into program-ir.cirru
175
169
  cr-wasm calcit/test-wasm.cirru # compile standalone wasm target to js-out/program.wasm
176
170
  ```
177
171
 
172
+ For repository development, the usual validation flow is:
173
+
174
+ ```bash
175
+ cargo fmt
176
+ cargo clippy -- -D warnings
177
+ yarn compile
178
+ cargo test
179
+ yarn check-all
180
+ ```
181
+
178
182
  - [Cirru Parser](https://github.com/Cirru/parser.rs) for indentation-based syntax parsing.
179
183
  - [Cirru EDN](https://github.com/Cirru/cirru-edn.rs) for runtime snapshot file parsing (`calcit.cirru` / legacy `compact.cirru`).
180
184
  - [Ternary Tree](https://github.com/calcit-lang/ternary-tree.rs) for immutable list data structure.
@@ -28,8 +28,8 @@
28
28
  :args $ [] 'T :number
29
29
  :rest :number
30
30
  :return $ :: :tuple :ok 'U
31
- :where $ []
32
- :: 'Eq 'T
31
+ :where $ {}
32
+ 'T Eq
33
33
  ```
34
34
 
35
35
  说明:
@@ -83,20 +83,19 @@
83
83
 
84
84
  ## `:where` 约束
85
85
 
86
- 约束统一放在 `:where`,每条约束是一条 tuple:
86
+ 约束统一放在 `:where` map,key 是泛型变量,value 是单个 trait 或 trait 列表:
87
87
 
88
88
  ```cirru
89
- []
90
- :: 'Eq 'T
91
- :: 'Show 'T
92
- :: 'Ord 'U
89
+ {}
90
+ 'T $ [] Eq Show
91
+ 'U Ord
93
92
  ```
94
93
 
95
94
  约定:
96
95
 
97
- - 同一变量多条约束表示“且”;
98
- - 顺序不影响语义;
99
- - 若当前没有约束,直接写 `:where $ []`。
96
+ - 同一变量多个约束放在同一个 value 列表里,表示“且”;
97
+ - map 项顺序不影响语义;
98
+ - 若当前没有约束,直接省略 `:where`,或写空 map `:where $ {}`。
100
99
 
101
100
  ## parse 校验示例
102
101
 
@@ -105,13 +104,13 @@
105
104
  主示例:
106
105
 
107
106
  ```bash
108
- cr demos/calcit.cirru cirru parse-edn "(:: :fn ({} (:generics ([] 'T 'U)) (:args ([] 'T :number)) (:rest :number) (:return (:: :tuple :ok 'U)) (:where ([] (:: 'Eq 'T)))))"
107
+ cr demos/calcit.cirru cirru parse-edn "(:: :fn ({} (:generics ([] 'T 'U)) (:where ({} ('T Eq))) (:args ([] 'T :number)) (:rest :number) (:return (:: :tuple :ok 'U))))"
109
108
  ```
110
109
 
111
110
  运行时数据验证:
112
111
 
113
112
  ```bash
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"
113
+ cr demos/calcit.cirru eval "let ((schema (:: :fn ({} (:generics ([] 'T 'U)) (:where ({} ('T Eq))) (:args ([] 'T :number)) (:rest :number) (:return (:: :tuple :ok 'U)))))) (println schema) (println (type-of schema)) , schema"
115
114
  ```
116
115
 
117
116
  ## 顶层定义与局部定义的分工
@@ -0,0 +1,124 @@
1
+ # 泛型 `:where` 约束 MFS
2
+
3
+ 日期:2026-05-31
4
+
5
+ 状态:Draft
6
+
7
+ ## 目标
8
+
9
+ 在现有函数 schema 泛型链路上,增加最小可用的 trait 约束能力:
10
+
11
+ - schema / `hint-fn` 可以声明 `:where`;
12
+ - 调用点在泛型变量完成绑定后,检查绑定结果是否满足 trait 约束;
13
+ - 先走主链路,不引入完整 trait solver,不处理复杂的 transitive requires 推导。
14
+
15
+ ## 当前实现边界
16
+
17
+ 本轮只覆盖:
18
+
19
+ - `CalcitFnTypeAnnotation` 的 `:where` 解析与序列化;
20
+ - 顶层 `:schema` 注入 `hint-fn` 后,用户函数调用的 `:where` 检查;
21
+ - 局部函数 / 期望函数类型场景的 `:where` 检查;
22
+ - trait 约束当前以 preprocess warning 形式暴露。
23
+
24
+ 本轮不覆盖:
25
+
26
+ - trait `requires` 的递归满足性;
27
+ - 约束失败直接升级为 hard error;
28
+ - 基于 `:where` 的代码生成优化;
29
+ - 复杂多态分派或 impl 搜索策略调整。
30
+
31
+ ## Canonical Cirru EDN 形态
32
+
33
+ ### 顶层 wrapped schema
34
+
35
+ `CodeEntry.:schema` 在 snapshot / Cirru EDN 里的推荐形态:
36
+
37
+ ```cirru
38
+ %{} :CodeEntry
39
+ :doc |demo
40
+ :code $ quote
41
+ defn show-it (x)
42
+ .show x
43
+ :examples $ []
44
+ :schema $ :: :fn
45
+ {}
46
+ :generics $ [] 'T
47
+ :where $ {}
48
+ 'T Show
49
+ :args $ [] 'T
50
+ :return :string
51
+ ```
52
+
53
+ ### 多 trait 约束
54
+
55
+ 单个类型变量绑定多个 trait 时,值是一个列表:
56
+
57
+ ```cirru
58
+ :: :fn $ {}
59
+ :generics $ [] 'T 'U
60
+ :where $ {}
61
+ 'T $ [] Show Eq
62
+ 'U Ord
63
+ :args $ [] 'T 'U
64
+ :return 'T
65
+ ```
66
+
67
+ ### 一行 Cirru EDN 示例
68
+
69
+ ```cirru
70
+ (:: :fn ({} (:generics ([] 'T 'U)) (:where ({} ('T ([] Show Eq)) ('U Ord))) (:args ([] 'T 'U)) (:return 'T)))
71
+ ```
72
+
73
+ ## 约束格式结论
74
+
75
+ `:`where` 当前使用 map,而不是 list-of-tuples。这一点刻意对齐 Rust `where` 的分离式设计:泛型名字继续放在 `:generics`,trait 约束单独放在 `:where`,避免把“变量声明”和“约束条件”混在同一个位置里。
76
+
77
+ - key: 泛型变量,例如 `'T`
78
+ - value: 单个 trait,或 `[]` 列表中的多个 trait
79
+
80
+ 也就是:
81
+
82
+ ```cirru
83
+ :where $ {}
84
+ 'T Show
85
+ 'U $ [] Eq Ord
86
+ ```
87
+
88
+ 不要写成旧草案里的 tuple 形式。`:: 'Show 'T` / `:: 'Eq 'U` 这类写法已经废弃,不应再出现在任何新文档、示例或测试输入里。
89
+
90
+ 后者不要再作为新文档示例。
91
+
92
+ 在概念上可以把它理解成 Rust 里的:
93
+
94
+ - `fn f<T, U>(...) where T: Show + Eq, U: Ord`
95
+ - 在 Calcit 中对应为 `:generics $ [] 'T 'U` 与 `:where $ {} 'T $ [] Show Eq 'U Ord`
96
+
97
+ ## 与 EDN / 内部表示的关系
98
+
99
+ - Cirru 文本里写 `'T`;
100
+ - 进入 EDN 后,它仍然是 symbol,只是内部不会把前导 `'` 作为名字的一部分存储;
101
+ - trait 名称在 schema 里直接写定义名,例如 `Show`、`Eq`,不加 `:` 前缀。
102
+
103
+ ## 主链路开发步骤
104
+
105
+ 1. 文档先固定 canonical `:where` 形态,避免继续沿用旧 tuple 草案。
106
+ 2. schema parse / serialize 支持 `:where`。
107
+ 3. 用户函数与局部函数调用,在泛型绑定后做 trait 约束检查。
108
+ 4. 增加 parse / roundtrip / warning 级别测试。
109
+ 5. 视结果决定是否把 warning 升级成 error,并是否纳入 trait `requires`。
110
+
111
+ ## 当前测试最小集
112
+
113
+ 至少保留以下方向:
114
+
115
+ - `hint-fn` 里的 `:where` 能被提取;
116
+ - 顶层 schema roundtrip 后 `:where` 不丢失;
117
+ - 满足 trait 约束时无 warning;
118
+ - 不满足 trait 约束时出现明确 warning。
119
+
120
+ ## 下一步
121
+
122
+ - 先把 `03-05-function-schema-dual-track-rfc.md` 中旧的 `:where` tuple 示例替换掉;
123
+ - 再补 schema roundtrip 测试,确保文档与实际输出一致;
124
+ - 之后再决定是否把约束失败升级为 `E_GENERIC_WHERE_BOUND_MISMATCH`。