@calcit/procs 0.12.56 → 0.12.57

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 (155) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/build.rs +36 -2
  3. package/editing-history/202608011759-issue-routing-in-agent-guide.md +17 -0
  4. package/editing-history/202608011833-schema-type-symbols.md +20 -0
  5. package/editing-history/202608011852-wasm-dynamic-string-tag.md +7 -0
  6. package/editing-history/202608011908-consolidate-history.md +6 -0
  7. package/editing-history/202608012022-consolidate-cli-and-test-duplication.md +28 -0
  8. package/editing-history/202608012123-review-follow-up.md +18 -0
  9. package/editing-history/202608012320-release-0.12.57.md +5 -0
  10. package/editing-history/ARCHIVE.md +15 -0
  11. package/editing-history/README.md +21 -0
  12. package/lib/package.json +1 -1
  13. package/package.json +1 -1
  14. package/editing-history/2026-02-13-1841-trait-origin-structural-eq.md +0 -91
  15. package/editing-history/2026-02-14-2050-js-codegen-recursion-tag-migration.md +0 -39
  16. package/editing-history/2026-02-14-2358-emit-js-modularization-shift-left.md +0 -63
  17. package/editing-history/2026-02-15-0000-diagnostics-consolidated.md +0 -35
  18. package/editing-history/2026-02-15-1941-macro-diagnostics-refinement.md +0 -39
  19. package/editing-history/2026-02-16-2043-core-api-docs-cleanup.md +0 -40
  20. package/editing-history/2026-02-23-0834-migrate-to-defstruct.md +0 -91
  21. package/editing-history/2026-02-23-2321-ns-imports-code-fixes.md +0 -42
  22. package/editing-history/2026-02-25-0002-language-behavior-eval-mode.md +0 -93
  23. package/editing-history/2026-02-25-0111-guidebook-no-check-block-upgrades.md +0 -52
  24. package/editing-history/2026-02-25-0113-runtime-type-validation-and-macro-quoting.md +0 -41
  25. package/editing-history/2026-02-25-1131-check-md-eval-improvements.md +0 -13
  26. package/editing-history/2026-02-26-1324-check-md-inprocess-cache-and-path-labels.md +0 -7
  27. package/editing-history/2026-02-27-1640-unify-markdown-readers.md +0 -16
  28. package/editing-history/2026-02-27-1958-tree-rewrite-command-and-reference-model.md +0 -18
  29. package/editing-history/2026-02-27-2200-split-def-command.md +0 -29
  30. package/editing-history/2026-02-27-2212-tree-raise-wrap.md +0 -33
  31. package/editing-history/2026-02-27-2223-calcit-agent-docs-optimize.md +0 -41
  32. package/editing-history/2026-03-01-0212-query-search-entry-and-ffi-warning.md +0 -53
  33. package/editing-history/2026-03-03-1934-check-types-and-core-annotations.md +0 -17
  34. package/editing-history/2026-03-04-0000-generics-fn-typevar-identity.md +0 -30
  35. package/editing-history/2026-03-04-1331-tag-call-warning-and-dot-access-migration.md +0 -28
  36. package/editing-history/2026-03-04-1548-impl-new-dot-method-input-and-doc-hints.md +0 -33
  37. package/editing-history/2026-03-04-1645-calcit-eq-contract-refactor-and-macro-tests.md +0 -28
  38. package/editing-history/2026-03-04-2200-assert-type-assert-traits-composable-runtime-checks.md +0 -18
  39. package/editing-history/2026-03-05-0042-type-inference-argtypes-and-core-hints.md +0 -54
  40. package/editing-history/2026-03-05-0115-calcit-core-generic-refinements.md +0 -57
  41. package/editing-history/2026-03-05-1930-schema-migration-cr-edit.md +0 -30
  42. package/editing-history/2026-03-05-1939-query-schema-adaptation.md +0 -42
  43. package/editing-history/2026-03-06-0120-schema-hint-migration-batch.md +0 -38
  44. package/editing-history/2026-03-06-1416-core-macro-schema-migration.md +0 -20
  45. package/editing-history/2026-03-06-1552-core-schema-and-hintfn-migration.md +0 -63
  46. package/editing-history/2026-03-06-1936-schema-normalization-and-preprocess-preload.md +0 -12
  47. package/editing-history/2026-03-07-0000-migrate-hint-fn-to-schema.md +0 -29
  48. package/editing-history/2026-03-07-0000-remove-enum-prototype-field.md +0 -43
  49. package/editing-history/2026-03-07-0000-schema-args-type-enforcement.md +0 -66
  50. package/editing-history/2026-03-07-0142-unit-type-and-builtin-schemas.md +0 -82
  51. package/editing-history/2026-03-07-1652-decouple-snapshot-schema-to-calcit-type.md +0 -112
  52. package/editing-history/2026-03-07-1821-snapshot-schema-validation.md +0 -6
  53. package/editing-history/2026-03-07-1959-schema-def-kind-arity-validation.md +0 -96
  54. package/editing-history/2026-03-08-0031-schema-generics-quote-normalization.md +0 -35
  55. package/editing-history/2026-03-08-1905-schema-typeref-and-assert-migration.md +0 -34
  56. package/editing-history/2026-03-08-2033-schema-wrapper-migration.md +0 -45
  57. package/editing-history/2026-03-08-2315-late-schema-cleanup-and-warning-compat.md +0 -27
  58. package/editing-history/2026-03-09-1753-schema-type-fail-tests.md +0 -17
  59. package/editing-history/2026-03-10-1040-edit-schema-primitive-tag-support.md +0 -42
  60. package/editing-history/2026-03-10-1754-ns-entry-snapshot-migration.md +0 -66
  61. package/editing-history/2026-03-13-2216-validate-struct-type-arg-arity.md +0 -24
  62. package/editing-history/2026-03-16-2353-runtime-boundary-cleanup.md +0 -14
  63. package/editing-history/2026-03-17-0150-runtime-boundary-lookup-cleanup.md +0 -28
  64. package/editing-history/2026-03-20-0116-json-builtins-and-runtime-docs.md +0 -48
  65. package/editing-history/2026-03-26-2013-docs-frontmatter-and-module-search.md +0 -58
  66. package/editing-history/2026-04-07-1550-path-format-at-prefix-migration.md +0 -46
  67. package/editing-history/2026-04-12-1524-js-codegen-map-to-record.md +0 -26
  68. package/editing-history/2026-04-12-1549-map-to-record-field-validation.md +0 -29
  69. package/editing-history/2026-04-13-1600-tuple-to-enum-rewrite.md +0 -13
  70. package/editing-history/2026-04-13-2309-typeslot-enum-compile-safety.md +0 -45
  71. package/editing-history/2026-04-14-1500-loose-record-syntax.md +0 -32
  72. package/editing-history/2026-04-14-2259-bidir-type-check-refactor.md +0 -63
  73. package/editing-history/2026-04-15-0120-match-syntax-exhaustiveness.md +0 -20
  74. package/editing-history/2026-04-15-1211-record-nth-optimization.md +0 -44
  75. package/editing-history/2026-04-16-1936-predicate-narrowing-expansion.md +0 -31
  76. package/editing-history/2026-04-17-0132-monomorphize-map-filter.md +0 -50
  77. package/editing-history/2026-04-17-0135-monomorphize-includes-reverse.md +0 -31
  78. package/editing-history/2026-04-17-0140-fold-type-predicates.md +0 -44
  79. package/editing-history/2026-04-17-0154-generic-dispatch-records-tuples.md +0 -52
  80. package/editing-history/2026-04-17-0520-simplify-generic-defns-via-method-dispatch.md +0 -49
  81. package/editing-history/2026-05-21-0055-tree-show-cr-config-and-edit-cleanup.md +0 -81
  82. package/editing-history/2026-05-31-2052-macro-schema-roundtrip-and-weak-types.md +0 -6
  83. package/editing-history/2026-05-31-2105-map-generic-weak-types-followup.md +0 -15
  84. package/editing-history/2026-06-01-0003-update-callback-field-specialization.md +0 -19
  85. package/editing-history/2026-06-01-2317-data-definition-where-bounds.md +0 -6
  86. package/editing-history/2026-06-02-0114-data-definition-where-macro-followup.md +0 -21
  87. package/editing-history/2026-06-03-0000-check-md-edn-errors.md +0 -5
  88. package/editing-history/2026-06-03-1600-check-md-entry-modules.md +0 -6
  89. package/editing-history/2026-06-04-0000-check-md-app-main-init.md +0 -6
  90. package/editing-history/2026-06-04-2218-compiled-executable-runtime-backfill.md +0 -6
  91. package/editing-history/2026-06-09-0000-with-type-slot-scoped-binding.md +0 -83
  92. package/editing-history/2026-06-09-1241-remove-bind-type.md +0 -64
  93. package/editing-history/2026-06-09-1800-core-effect-tags.md +0 -57
  94. package/editing-history/2026-06-10-1200-get-def-doc-schema-builtin.md +0 -7
  95. package/editing-history/2026-06-15-1500-effects-graph-mvp.md +0 -30
  96. package/editing-history/2026-06-16-1700-effects-graph-ste-tree.md +0 -84
  97. package/editing-history/2026-06-27-0052-cli-improvements.md +0 -41
  98. package/editing-history/2026-06-27-0202-docs-indexing-improvements.md +0 -22
  99. package/editing-history/2026-06-27-0315-file-splits.md +0 -17
  100. package/editing-history/2026-06-27-0416-agent-advanced-split.md +0 -15
  101. package/editing-history/archived/2025-04-12-1453-map-to-record-rewrite.md +0 -33
  102. package/editing-history/archived/2025-04-16-0117-wasm-codegen-and-catalog-update.md +0 -40
  103. package/editing-history/archived/2025-07-16-0207-wasm-encoder-migration.md +0 -48
  104. package/editing-history/archived/2025-07-16-1633-wasm-data-structures.md +0 -61
  105. package/editing-history/archived/2026-02-13-1926-docs-tests-followup.md +0 -33
  106. package/editing-history/archived/2026-02-16-2128-docs-smoke-and-trait-errors.md +0 -20
  107. package/editing-history/archived/2026-02-25-1234-watch-mode-default-once.md +0 -5
  108. package/editing-history/archived/2026-03-07-1302-calcit-agent-docs-update.md +0 -32
  109. package/editing-history/archived/2026-03-09-1819-add-test-fail-script.md +0 -5
  110. package/editing-history/archived/2026-03-09-1944-split-type-fail-tests.md +0 -8
  111. package/editing-history/archived/2026-03-16-1449-profiling-tools-reorg.md +0 -13
  112. package/editing-history/archived/2026-03-17-2026-afternoon-runtime-boundary-optimization-summary.md +0 -87
  113. package/editing-history/archived/2026-03-18-1802-tips-level-and-overwrite-schema-preservation.md +0 -26
  114. package/editing-history/archived/2026-03-20-1229-query-window-3-with-parent-preview.md +0 -72
  115. package/editing-history/archived/2026-03-23-1137-command-echo-tool-output-cleanup.md +0 -71
  116. package/editing-history/archived/2026-04-10-0011-snapshot-empty-version-pipe-marker.md +0 -23
  117. package/editing-history/archived/2026-04-16-0131-wasm-math-and-test-integration.md +0 -28
  118. package/editing-history/archived/2026-04-16-1507-wasm-data-structures-and-rfc-rename.md +0 -27
  119. package/editing-history/archived/2026-04-16-1520-wasm-bitwise-and-match.md +0 -21
  120. package/editing-history/archived/2026-04-16-1542-wasm-cross-ns-host-imports.md +0 -38
  121. package/editing-history/archived/2026-04-17-0026-wasm-rest-args.md +0 -62
  122. package/editing-history/archived/2026-04-17-0048-wasm-type-of.md +0 -70
  123. package/editing-history/archived/2026-04-17-0051-wasm-derived-predicates.md +0 -34
  124. package/editing-history/archived/2026-04-17-2316-wasm-do-println-fixes.md +0 -41
  125. package/editing-history/archived/2026-04-18-1208-split-emit-wasm-and-bump-version.md +0 -15
  126. package/editing-history/archived/2026-04-18-1430-wasm-list-match-and-method-dispatch.md +0 -5
  127. package/editing-history/archived/2026-04-18-2041-cr-wasm-split-and-runtime-stability.md +0 -18
  128. package/editing-history/archived/2026-04-18-2045-v0.12.23-ci-wasm-fix.md +0 -13
  129. package/editing-history/archived/2026-04-21-1818-wasm-string-ops-v2.md +0 -57
  130. package/editing-history/archived/2026-04-21-2332-split-emit-wasm.md +0 -45
  131. package/editing-history/archived/2026-04-22-0114-wasm-hof-intercepts-and-set-intersection.md +0 -82
  132. package/editing-history/archived/2026-04-22-0136-wasm-enum-tuple-bool-str-fixes.md +0 -68
  133. package/editing-history/archived/2026-04-22-1340-wasm-map-diff-new-and-let-intercept.md +0 -53
  134. package/editing-history/archived/2026-04-23-1419-v0.12.26-wasm-bisection-fixes.md +0 -7
  135. package/editing-history/archived/2026-04-23-1645-release-conventions.md +0 -14
  136. package/editing-history/archived/2026-04-25-1940-wasm-suite-multi-module-entry.md +0 -53
  137. package/editing-history/archived/2026-04-25-2003-wasm-method-includes-string-and-set-refactor.md +0 -71
  138. package/editing-history/archived/2026-04-25-2010-wasm-suite-add-fn-lens-edn.md +0 -43
  139. package/editing-history/archived/2026-04-25-2051-display-by.md +0 -39
  140. package/editing-history/archived/2026-04-28-1728-fix-gensym-stable.md +0 -31
  141. package/editing-history/archived/2026-04-29-1400-fix-bind-type-precompile.md +0 -38
  142. package/editing-history/archived/2026-05-26-0957-match-docs-check-md.md +0 -24
  143. package/editing-history/archived/2026-05-31-2059-ci-docs-test-and-fn-helper-tightening.md +0 -3
  144. package/editing-history/archived/2026-06-01-0005-release-0.12.36.md +0 -16
  145. package/editing-history/archived/2026-06-01-2230-enum-struct-payload-docs.md +0 -4
  146. package/editing-history/archived/2026-06-03-1620-release-0.12.38.md +0 -6
  147. package/editing-history/archived/2026-06-04-0000-release-0.12.39.md +0 -4
  148. package/editing-history/archived/2026-06-04-2230-release-0.12.40.md +0 -5
  149. package/editing-history/archived/2026-06-12-1525-weak-types-dots-format.md +0 -15
  150. package/editing-history/archived/2026-06-13-1200-primitive_schema_tags.md +0 -9
  151. package/editing-history/archived/2026-06-20-1142-ts-declaration-d-mts.md +0 -5
  152. package/editing-history/archived/2026-06-29-0117-upgrade-doc-snapshot-migration.md +0 -2
  153. package/editing-history/archived/2026-06-29-calcit-cli.md +0 -80
  154. package/editing-history/archived/2026-06-29-typed-calcit-cli-schemas.md +0 -23
  155. package/editing-history/archived/20260630-duplication-analysis.md +0 -116
@@ -1,71 +0,0 @@
1
- # 202604252003 — WASM suite extended: .includes? string branch + uncommitted refactor consolidation
2
-
3
- ## Background
4
-
5
- In the previous session a multi-module WASM suite entry (`calcit/test-wasm-suite.cirru`) was added
6
- to gradually exercise more of the existing `calcit/test-*.cirru` programs against the WASM codegen.
7
- At that point a sizable in-progress refactor in `src/codegen/emit_wasm/{heap,hof,lists,runtime,sets}.rs`
8
- was left uncommitted alongside, and `test-string.cirru` was deferred because folding it into the
9
- suite triggered an `unreachable` trap.
10
-
11
- ## Findings this round
12
-
13
- When folding `test-string.main` into `test-wasm-suite.main/main!`, the runtime trap reproduced. By
14
- calling individual exports (new helper `scripts/test-wasm-call.mjs`) it was clear that:
15
-
16
- 1. `(.includes? "abc" "abc")` returned `0` (false) instead of `1`. Root cause:
17
- `methods::emit_method_includes` only handled `list/map/set` receivers; for any other type it
18
- emitted `f64_const(0.0)` as the fallback. Strings therefore never reached
19
- `__rt_str_find_index`.
20
- 2. After fixing #1, `test-includes` still trapped — the assertions
21
- `assert= true $ starts-with? :a/b :a/` and `assert= true $ starts-with? :a/b |a/` pass
22
- tags as arguments. Tags in WASM are encoded as small `f64` values equal to their tag-index id,
23
- so `__rt_str_starts_with` reads them as bogus heap pointers and silently returns 0. Adding tag→
24
- string conversion at runtime is a follow-up.
25
- 3. `test-bitwise` traps on `&number:display-by` (radix formatting) which is currently stubbed to
26
- return `0`.
27
-
28
- Because #2 and #3 require additional runtime helpers, `test-string.cirru` is left out of the suite
29
- for this commit. The `.includes?` regression is fixed in isolation; it also benefits any other
30
- program that calls `.includes?` on a string.
31
-
32
- ## Changes in this commit
33
-
34
- - `src/codegen/emit_wasm/methods.rs`: extend `emit_method_includes` with a string branch
35
- (`emit_str_includes_from_local`) that calls `__rt_str_find_index >= 0`.
36
- - `scripts/test-wasm-call.mjs`: minimal helper to invoke a single named export against the latest
37
- `js-out/program.wasm`, useful for bisecting which assertion in a `main!` traps.
38
-
39
- The commit also folds in the previously-uncommitted refactor that landed in
40
- `src/codegen/emit_wasm/{heap,hof,lists,runtime,sets}.rs`:
41
-
42
- - `sets.rs`: `emit_set_find_structural` replaces the pointer-only `__rt_set_find_elem` for
43
- `difference`/`intersection`/set-equality so identical-by-content elements are treated as equal.
44
- - `runtime.rs`: new `__rt_hash_list_or_set(ptr) -> i32` (XOR-based content hash) plus a couple of
45
- new helper-function indices.
46
- - `hof.rs`: `emit_copy_type_tag` so `map`/`filter` preserve the receiver tag (set→set, list→list).
47
- - `lists.rs`: `range start end step` 3-arg form.
48
- - `heap.rs`: smarter `emit_hash_proc` that detects heap pointers at runtime and dispatches to the
49
- list/set hash helper. The dead `emit_hash_expr_i32`/`emit_hash_mix` static helpers are removed.
50
- - `emit_wasm.rs`: `#[allow(private_interfaces)]` on `emit_equals_core` and
51
- `emit_equals_core_shallow` (both already returned a `pub(super)`-only opaque local index but are
52
- used from sibling modules through the `super::*` re-export).
53
-
54
- ## Verification
55
-
56
- ```bash
57
- bash scripts/cargo-with-sdk.sh clippy --bin cr-wasm -- -D warnings # clean
58
- bash scripts/cargo-with-sdk.sh build --bin cr-wasm --release # ok
59
- bash scripts/test-wasm-suite-extended.sh # PASS
60
- bash scripts/test-wasm-suite.sh # 6/10 (unchanged)
61
- ```
62
-
63
- `scripts/test-wasm-suite.sh` skips `test-fn`, `test-string`, `test-tuple`, `test-list` for the
64
- same reasons documented previously; that is independent of this commit.
65
-
66
- ## Follow-ups
67
-
68
- 1. Tag → string conversion at runtime so string procs accept tags (unblocks `test-string`).
69
- 2. `&number:display-by` radix formatting (unblocks the last 3 assertions in `test-bitwise`).
70
- 3. The other test-string skips (`&str:replace`, `parse-float`, `blank?`, `trim`,
71
- `get-char-code`, `format-to-cirru`, `&cirru-quote:to-list`).
@@ -1,43 +0,0 @@
1
- # 202604252010 — WASM suite extended: + test-fn / test-lens / test-edn
2
-
3
- ## Background
4
-
5
- After landing the `.includes?` string fix, this round adds three more `test-*.cirru` programs to
6
- `calcit/test-wasm-suite.cirru` to cover more of the WASM runtime surface. Goal: keep growing the
7
- "runs end-to-end in WASM" set without depending on Host FFI features.
8
-
9
- ## Process
10
-
11
- For each candidate module:
12
-
13
- 1. Inspect `cr-wasm <module>.cirru` standalone to enumerate `[wasm] skipping ...` lines (these are
14
- per-def errors that cause that def to be replaced with a `0.0`-returning stub).
15
- 2. Read the module's `main!` body to confirm trapping assertions can survive when the skipped
16
- helpers return `0`.
17
- 3. Add to the suite, rebuild, and run `bash scripts/test-wasm-suite-extended.sh`.
18
-
19
- ## Result
20
-
21
- Suite now covers (in addition to previous `test-cond/test-math/test-set/test-tuple`):
22
-
23
- - `test-fn` — only `&init-builtin-impls!` skipped; suite passes cleanly.
24
- - `test-lens` — `test-lens.main/test-lens` is skipped (`:::` rejects a quoted form arg) but other
25
- defs in the module compile; `main!` does not trip the stub.
26
- - `test-edn` — many sub-tests skipped (`parse-cirru-edn`, `trim`, `&extract-code-into-edn`), but
27
- the skipped fns return `0` instead of running their assertions, so `main!` completes.
28
-
29
- Modules tried but reverted:
30
-
31
- - `test-string` — assertions feed tags into `starts-with?`/`ends-with?`/`includes?`. Tags in WASM
32
- are encoded as small `f64` ids (their tag-index value), not heap string pointers, so the procs
33
- silently return `0` and the assertion traps. Needs a tag→string runtime helper.
34
- - `test-algebra` — `test-map` exercises `%{} AlgebraBox`, `assert-traits`, `.map` on records, and
35
- `:value` access; record/trait dispatch is not yet implemented in WASM.
36
- - `test-map` (the standalone, full map suite) — `test-pairs`/`test-keys` etc. compile but trap at
37
- runtime, likely from map iteration ordering or hash collision behavior. Needs deeper triage.
38
-
39
- ## Verification
40
-
41
- ```bash
42
- bash scripts/test-wasm-suite-extended.sh # PASS (8 modules including util)
43
- ```
@@ -1,39 +0,0 @@
1
- # `&number:display-by` WASM 实现
2
-
3
- ## 摘要
4
-
5
- 实现了 `&number:display-by` 和 `.display-by` 方法的 WASM codegen,支持二进制、八进制、十六进制格式化,并将 `test-string` 模块加入 WASM 扩展测试套件。
6
-
7
- ## 关键实现点
8
-
9
- ### `build_rt_display_by` (runtime.rs)
10
-
11
- - 函数签名: `(value: f64, radix: f64) -> f64` (返回字符串堆 ptr)
12
- - 算法:负数检测 → 计数位数(div 循环)→ 计算前缀长度(radix ∈ {2,8,16} → 2, else 0)→ 分配堆字符串 → 写前缀(`0b`/`0o`/`0x`)→ 从右往左写位数(`'0'..digit` 或 `'a'..digit-10`)
13
- - locals 索引 2-16,手动分配(非 RuntimeFnBuilder 风格)
14
- - 负数:先检测,计数时用 abs_i64,最后写 '-'
15
-
16
- ### 注意
17
-
18
- - 必须先用 `collect_strings_from_expr` 收集 tag 名称才能支持 tag→string(前一次提交已做)
19
- - local 参数:value=0, radix=1;其余 2..16 为局部变量
20
-
21
- ### 测试
22
-
23
- - `test-display-by-bin()` = 7 (17 → "0b10001")
24
- - `test-display-by-hex()` = 4 (17 → "0x11")
25
- - test-string 模块加入 test-wasm-suite(8个模块),全部 PASS
26
-
27
- ## 修改文件
28
-
29
- - `src/codegen/emit_wasm/runtime.rs` — 新增 `build_rt_display_by` + 注册 `__rt_display_by`
30
- - `src/codegen/emit_wasm.rs` — 分拆 `NativeNumberDisplayBy` 从 stub 到 `call_rt("__rt_display_by")`
31
- - `src/codegen/emit_wasm/methods.rs` — 新增 `.display-by` 方法分发
32
- - `calcit/test-wasm-suite.cirru` — 加入 `test-string`
33
- - `calcit/test-wasm.cirru` — 新增 `test-display-by-bin` / `test-display-by-hex`
34
- - `scripts/test-wasm.mjs` — 新增对应断言
35
-
36
- ## 后续计划
37
-
38
- - `trim`、`blank?`、`&str:replace`、`parse-float`、`get-char-code`
39
- - HOF closures-as-values (S1 fn-table)
@@ -1,31 +0,0 @@
1
- # Fix: Gensym 稳定性问题
2
-
3
- ## 问题描述
4
-
5
- `cr js` 每次运行会生成不同的 JS 文件,原因是 gensym 计数器不稳定(如 `v__1` 变成 `v__3`)。
6
-
7
- ## 根本原因
8
-
9
- Calcit 的 gensym 使用 `NS_SYMBOL_DICT: HashMap<Arc<str>, usize>` 记录计数器。由于 Rust 的 `HashMap` 每进程随机化迭代顺序,不同运行时的 def 编译顺序不同,导致 gensym 计数器累积值不一样。
10
-
11
- 有**两条**编译路径,只修了一条是不够的:
12
- 1. `ensure_ns_def_preprocessed` —— 正常编译路径,通过 `with_compiling_def` 重置 gensym 计数器(之前已修)
13
- 2. `compile_source_def_for_snapshot` —— 快照填充路径(JS codegen 时触发),**缺少 `with_compiling_def` 包装**,导致 `CURRENT_COMPILING_DEF` 为 `None`,gensym 退回到 `file_ns`(命名空间级 key),计数器跨 def 累积
14
-
15
- ## 修复方法
16
-
17
- 在 `src/runner/preprocess/mod.rs` 的 `compile_source_def_for_snapshot` 函数中,为 `preprocess_expr` 调用加上 `builtins::meta::with_compiling_def(ns, def, ...)` 包装,与 `ensure_ns_def_preprocessed` 保持一致。
18
-
19
- ## 已修改文件
20
-
21
- - `src/builtins/syntax.rs`: gensym key 改为 `CURRENT_COMPILING_DEF`(无 `file_ns` 前缀)
22
- - `src/builtins/meta.rs`: 新增 `CURRENT_COMPILING_DEF` thread_local + `with_compiling_def`(自动重置计数器)
23
- - `src/runner/preprocess/mod.rs`:
24
- - `ensure_ns_def_preprocessed`: 包 `with_compiling_def`(第一次修)
25
- - `compile_source_def_for_snapshot`: 包 `with_compiling_def`(本次修)
26
-
27
- ## 验证
28
-
29
- - `cr js` 连续 8 次运行,无任何文件变化
30
- - `cargo test` 67 passed
31
- - `yarn check-all` 全部通过
@@ -1,38 +0,0 @@
1
- # Fix: bind-type 类型槽预编译顺序问题
2
-
3
- ## 问题描述
4
-
5
- `cr js` 在 tiye-index 项目中,`reel.app.comp.todolist.mjs` 和 `respo.schema.mjs` 仍然不稳定——有时生成 `Op`-aware 版本(带 `import { Op }` 和 `$clt._PCT__$o__$o_(Op, ...)`),有时生成不带 Op 的版本(使用 `$clt._$o__$o_(...)`)。
6
-
7
- ## 根本原因
8
-
9
- `bind-type :dispatch-op Op` 在 `respo.main/main!` 函数体中,是一个预处理阶段的副作用操作:当 `preprocess_expr` 遇到 `bind-type` 调用时,立即执行 `bind_type_slot("dispatch-op", Op)`,使 `*dispatch-op` 类型槽指向 Op 枚举。
10
-
11
- 问题根源:`reel.app.comp.todolist` 等组件 def 会作为入口函数 `app.main/main!` 的传递依赖被提前编译。由于 HashMap 迭代顺序不确定,某些运行中 `todolist` 在 `respo.main/main!` 之前编译——此时 `*dispatch-op` 类型槽尚未绑定,导致 `d! $ :: :states cursor ...` 中的元组字面量无法被改写为 `%:: Op :states cursor ...`,生成结构上不同的 JS 代码。
12
-
13
- ## 修复方法
14
-
15
- **双重修复:**
16
-
17
- ### 1. 预处理阶段:`precompile_bind_type_defs` (主要修复)
18
-
19
- 在 `src/lib.rs` 的 `run_program_with_docs` 中,在开始主入口预处理之前,先扫描**所有**程序源代码,找出含有 `bind-type` 调用的 def,并提前编译它们。
20
-
21
- 这确保 `respo.main/main!`(含 `bind-type :dispatch-op Op`)在 `app.main/main!` 的依赖树遍历之前被编译,从而使 `:dispatch-op` 类型槽在所有组件编译前就已绑定。
22
-
23
- ### 2. 快照填充阶段:任务排序 (辅助修复)
24
-
25
- 在 `src/program.rs` 的 `collect_snapshot_fill_tasks` 中,对快照填充任务排序,确保含 `bind-type` 的 def 在快照阶段也优先处理,同时按 (ns, def) 字典序排序保证完全确定性。
26
-
27
- ## 已修改文件
28
-
29
- - `src/lib.rs`: 在 `run_program_with_docs` 中调用新增的 `precompile_bind_type_defs`
30
- - `src/runner/preprocess/mod.rs`: 新增 `precompile_bind_type_defs` 公开函数(扫描所有源 def,提前编译含 `bind-type` 的 def)
31
- - `src/program.rs`:
32
- - `calcit_contains_bind_type` 改为 `pub fn`(供 preprocess 模块使用)
33
- - `collect_snapshot_fill_tasks` 中对任务排序(bind-type 优先,其余按字典序)
34
-
35
- ## 验证
36
-
37
- - `cr js` 在 tiye-index 项目连续 8 次运行,第 1 次(旧输出重新生成)后无任何文件变化
38
- - `cargo test --lib` 179 tests passed
@@ -1,24 +0,0 @@
1
- # 2026-05-26 match 文档与 check-md 校验
2
-
3
- ## 修改内容
4
-
5
- - 将 `match` 的文档说明统一为同时适用于 enum tuple 和 plain tuple,不再把 `tag-match` 描述成 plain tuple 的唯一入口。
6
- - 更新 `features/enums.md`、`features/tuples.md`、`features/common-patterns.md`、`features.md`、`quick-reference.md`、`run/agent-advanced.md` 中的推荐表述与示例。
7
- - 为 `agent-advanced.md` 里无法独立运行的 DOM / 事件示意片段补上 `cirru.no-check`,使 `cr docs check-md` 只校验可执行代码块。
8
-
9
- ## 验证
10
-
11
- - `cargo run --bin cr -- eval $'match (:: :point 10 20)\n (:point x y) (+ x y)\n _ 0'`
12
- - `cargo run --bin cr -- docs check-md docs/features.md`
13
- - `cargo run --bin cr -- docs check-md docs/features/common-patterns.md`
14
- - `cargo run --bin cr -- docs check-md docs/features/enums.md`
15
- - `cargo run --bin cr -- docs check-md docs/features/error-handling.md`
16
- - `cargo run --bin cr -- docs check-md docs/features/traits.md`
17
- - `cargo run --bin cr -- docs check-md docs/features/tuples.md`
18
- - `cargo run --bin cr -- docs check-md docs/quick-reference.md`
19
- - `cargo run --bin cr -- docs check-md docs/run/agent-advanced.md`
20
-
21
- ## 知识点
22
-
23
- - 原生 `match` 可以直接匹配 plain tuple;它不只适用于带 `defenum` 类型信息的 tuple。
24
- - 文档里的示意片段如果依赖 DOM helper、事件桥接函数或其他未加载上下文,应优先标记为 `cirru.no-check`,否则会被 `check-md` 的 `eval` 阻断。
@@ -1,3 +0,0 @@
1
- - fixed docs query test to be stable both with and without ~/.config/calcit/docs configured, matching CI runner behavior
2
- - tightened calcit.core fn helper schemas for &fn:apply / &fn:bind / &fn:map to reduce nested schema-dynamic usage
3
- - validated with focused docs test, full cargo test, runtime cr calcit/test.cirru, weak-types analyze, and yarn check-all
@@ -1,16 +0,0 @@
1
- # 2026-06-01 00:05 release 0.12.36
2
-
3
- ## Summary
4
-
5
- - bumped crate and npm package version from `0.12.35` to `0.12.36`
6
- - kept `ts-src/package.json` aligned with the root npm package metadata
7
- - prepared the workspace for a release lockfile refresh and tag creation
8
-
9
- ## Why
10
-
11
- - this release publishes the `update` callback specialization and `not` proc typing fix after the PR checks passed
12
- - keeping repeated package metadata in sync avoids mismatched npm publish/version outputs during future packaging steps
13
-
14
- ## Validation
15
-
16
- - `cargo update --workspace`
@@ -1,4 +0,0 @@
1
- - Documented that `defenum` payloads can reference named structs and applied generic structs.
2
- - Added runnable examples in `docs/features/enums.md` for plain struct payloads and generic struct payloads.
3
- - Clarified that `%::` validates struct payload values and generic arity at runtime when constructing enum instances.
4
- - Validation: `cargo run --bin cr -- demos/calcit.cirru docs check-md docs/features/enums.md`
@@ -1,6 +0,0 @@
1
- # 2026-06-03 release 0.12.38
2
-
3
- - 在功能提交通过 PR Actions 后,执行版本升级为 `0.12.38`。
4
- - 同步更新 `Cargo.toml` 与 `package.json` 的版本号。
5
- - 执行 `cargo update --workspace`,更新 `Cargo.lock` 中工作区版本引用到 `0.12.38`。
6
- - 发布前置流程保持不变:等待升级提交再次通过 CI,再打 tag 与创建 GitHub release 触发发布。
@@ -1,4 +0,0 @@
1
- # 2026-06-04 release 0.12.39
2
-
3
- - 版本号:`Cargo.toml` / `package.json` → 0.12.39
4
- - 主要变更:check-md 入口 fail-fast、`app.main/main!` 注入、EDN 模块列表错误预览
@@ -1,5 +0,0 @@
1
- # 2026-06-04 release 0.12.40
2
-
3
- - 发布 `0.12.40`,包含 compiled executable runtime backfill 修复。
4
- - 该修复让 compiled `Fn`/`Macro` 首次 materialize 后回写 runtime-ready storage,避免重复 lookup 生成新函数 identity。
5
- - 直接收益是恢复 `memof` 这类按函数值做 cache key 的场景,`cr calcit.cirru` 再次通过既有测试。
@@ -1,15 +0,0 @@
1
- # 修改记录: cr analyze weak-types 路径打印格式优化使用点号 (2026-06-12)
2
-
3
- ## 知识点与变动树
4
-
5
- 1. **Weak-type 路径打印格式优化**:
6
- - 原本 `cr analyze weak-types` 命令输出 AST 节点和声明模式中的位置时会使用大量的方括号 `[` 和 `]`,如 `code[3][1][6]`。
7
- - 现将其重构并统一为标准点号 (`.`) 路径分隔法(如 `code.3.1.6`),以消除视觉冗余。
8
-
9
- 2. **具体实现 & 多位置对齐**:
10
- - `format_cirru_path`: 修改它的实现,将其内部的 `[idx]` 拼接机制替换成了 `.idx`,从而全局对齐了 Cirru 节点遍历的 dot 符号写法。
11
- - `scan_schema_dynamic_annotation`: 内部处理 Fn 类型的索引时,把 `{path}.args[{idx}]` 和 `{path}.type-arg[{idx}]` 修改为点号连接的 `{path}.args.{idx}`、`{path}.type-arg.{idx}`,并同步修改了 `schema.args.{idx}` 语法签名位置。
12
-
13
- 3. **测试与质量验证**:
14
- - 执行 `cargo test --bin cr` 通过了全部 85 项内置和回归测试(无测试报错)。
15
- - 实地重新构建 `cargo build --bin cr` 并对大规模项目 `termina/msg-buffer` 完美执行 `analyze weak-types` 分析,其输出完美显示为高清晰度的 `code.6.1.3` 及 `schema.args.0.item.item.value` 点号格式。
@@ -1,9 +0,0 @@
1
- # Calcit Type schema primitive tags support expansion
2
-
3
- ## Timestamp: 202606131200
4
-
5
- ## Modification Summary:
6
- - Expanded `PRIMITIVE_SCHEMA_TAGS` inside `/Users/chenyong/repo/calcit-lang/calcit/src/snapshot.rs` to include `"record"`, `"struct"`, `"enum"`, `"trait"`, `"impl"`.
7
- - This ensures schema annotations utilizing these tags (e.g., `:trait` or `:enum` in code entries) pass verification rather than raising an unrecognized primitive tag validation error.
8
- - Verified with the Calcit test suite which passed 223+85 integration and unit tests without error.
9
- - Updated `respo/alerts` annotations using these tags to enforce more precise typing rules in the codebase.
@@ -1,5 +0,0 @@
1
- - `tsconfig.json` 添加 `declaration: true`,使 `yarn compile` 生成 `.d.mts` 类型声明文件
2
- - `yarn compile` 后 `lib/` 中与 `.mjs` 一一对应生成 18 个 `.d.mts` 文件
3
- - `.npmignore` 不排除 `lib/`,这些声明文件在 npm publish 时会被包含
4
- - 对 hovenia-editor:移除手动 `calcit-procs.d.ts`,改用上游生成的 `.d.mts`
5
- - 本地验证:`cargo fmt` `cargo clippy` `yarn compile` `cargo test` `yarn check-all` 全部通过
@@ -1,2 +0,0 @@
1
- - docs/run/upgrade.md: added snapshot migration section — documents the transition from two-file setup (calcit.cirru snapshot + compact.cirru compact code) to single calcit.cirru with compact code only, no separate snapshot file needed
2
- - Recommended: delete old snapshot file, compact code saved directly in calcit.cirru for cr command to use directly
@@ -1,80 +0,0 @@
1
- # calcit.cli / cr exec 完整实现
2
-
3
- ## 概要
4
-
5
- 实现 `cr exec` + `calcit.cli/*` 内建函数(共 77 个),让 Agent 用 Cirru heredoc 调用常用 `cr query` / `edit` / `tree` / `analyze` / `docs` 能力,绕开 Shell 转义。RFC:`RFCs/06-29-cr-exec-cli-builtins-rfc.md`。
6
-
7
- ## 架构
8
-
9
- - **运行时**:`src/bin/injection/mod.rs` 注册 handler;**单一 options map 参数**(arity 1)
10
- - **参数解析**:`calcit_cli_args.rs` — `resolve_cli_args`、类型 coercion、默认值填充、command echo
11
- - **参数规格**:`calcit_cli_specs.rs` — 每个函数的 `CliArgSpec` 列表(语义化键名)
12
- - **元数据**:`src/cirru/calcit-core.cirru` 的 `|calcit.cli` — schema 为 `(:args $ [] (:: :map :tag :dynamic))`
13
- - **同步**:`python3 scripts/gen_calcit_cli_core.py`(从 mod.rs + calcit_cli_specs.rs 生成)
14
- - **约束**:`calcit_cli*` 不得依赖 `cli_handlers`(保证 `cr-wasm` 可编译)
15
-
16
- ### 调用约定(2026-06-29 重构)
17
-
18
- ```cirru
19
- calcit.cli/peek-def $ {} (:file-path |calcit.cirru) (:target |app.main/main!)
20
- ```
21
-
22
- - 唯一参数为 options map;键为 tag(`:file-path`、`:target`、`:lines` 等)
23
- - 省略的可选键由 Rust 侧默认值填充;非 quiet 模式下 stderr echo 展示完整调用(含默认值)
24
- - 位置参数已移除(breaking change)
25
-
26
- | 文件 | 职责 |
27
- |------|------|
28
- | `calcit_cli_args.rs` | map 解析、echo、docs_hint 生成 |
29
- | `calcit_cli_specs.rs` | 77 个函数的参数 spec 常量 |
30
- | `calcit_cli.rs` | 基础 query/write、snapshot 读写、`load_calcit_snapshot_with_deps` |
31
- | `calcit_cli_tree.rs` | AST 树变换(delete/insert/wrap/cp/mv…) |
32
- | `calcit_cli_extra.rs` | edit/config/cirru 工具、trigger-inc、semver bump |
33
- | `calcit_cli_program.rs` | 加载 snapshot+modules+core 并 preprocess(analyze/validate) |
34
- | `calcit_cli_analyze.rs` | call/effects/count + check-types/weak-types |
35
- | `calcit_cli_query.rs` | show-pkg/ns、list-defs-by-tag、validate-file、search-*、list-host-procs |
36
- | `calcit_cli_docs.rs` | docs-agents/read/sections |
37
- | `src/type_coverage.rs` | check-types / weak-types 共享逻辑(`cr analyze` 与 calcit.cli 共用) |
38
-
39
- ## 分批功能(合并记录)
40
-
41
- ### 第一批:树/定义/import 写操作(17)
42
-
43
- `tree-delete` `tree-insert` `tree-wrap` `tree-unwrap` `tree-raise` `tree-cp` `tree-mv` `rename-def` `rm-def` `mv-def` `split-def` `add-ns` `edit-doc` `edit-schema` `add-example` `rm-import` `show-error`
44
-
45
- 要点:`tree-wrap` 用 `self` leaf;`position` 同 CLI(`|before` `|after` 等)。
46
-
47
- ### 第二批:edit/config/cirru(20)
48
-
49
- `rm-ns` `set-imports` `format-file` `show-doc` `show-ns-doc` `list-tags` `set-tags` `rm-example` `clear-examples` `set-examples` `tree-replace-leaf` `tree-swap-*` `tree-batch-delete` `tree-rewrite` `set-config` `add/rm-module` `cirru-parse/format` `read-text-file`
50
-
51
- 修复:`build_ns_code` 对齐 `(ns name (:require ...))` 嵌套结构。
52
-
53
- ### 第三批:analyze / inc / docs 搜索(9)
54
-
55
- `trigger-inc` `cirru-parse-edn` `cirru-show-guide` `docs-search` `tree-replace-leaf-regex` `analyze-call-graph` `analyze-effects-graph` `analyze-count-calls`
56
-
57
- ### 第四批:P0–P3(15)
58
-
59
- - **P0**:`show-pkg` `show-ns` `list-defs-by-tag` `validate-file` `bump-version` `edit-ns-doc`
60
- - **P1**:`search-project` `search-def-regex` `search-expr` `list-host-procs`
61
- - **P2**:`analyze-check-types` `analyze-weak-types`(依赖 `type_coverage` 提取)
62
- - **P3**:`docs-agents` `docs-read` `docs-sections`
63
-
64
- ### Core 声明 + 预处理
65
-
66
- - core 可选参数 schema 用 `(:rest :dynamic)`,勿写 `:rest $ :dynamic`(EDN 解析失败)
67
- - 预处理:`is_registered_proc` 必须在 `has_def_code` 之前,避免 core 元数据 stub 被当作普通 def 编译(`preprocess/mod.rs`)
68
-
69
- ## 验证
70
-
71
- ```bash
72
- python3 scripts/gen_calcit_cli_core.py
73
- unset CARGO_TARGET_DIR && cargo fmt
74
- cargo clippy --all-targets -- -D warnings
75
- cargo test --bin cr
76
- ./target/debug/cr calcit/test.cirru exec << 'EOF'
77
- calcit.cli/show-pkg $ {} (:file-path |calcit/test.cirru)
78
- calcit.cli/validate-file $ {} (:file-path |calcit/test.cirru)
79
- EOF
80
- ```
@@ -1,23 +0,0 @@
1
- # calcit.cli 选项 map 类型化 schema(Rust spec 直检)
2
-
3
- ## 变更概要
4
-
5
- - 选项 spec 收敛到 `src/builtins/cli_options.rs`(Rust 单一来源),注册时写入 `RegisteredProcDescriptor.cli_options`。
6
- - preprocess 直接读 Rust spec 校验 options map,不再生成 defstruct / 不做 map→record 转换。
7
- - core 中 `:args` 仍由脚本生成 inline 类型 map(供 query/docs),校验走 Rust 而非 Calcit 类型系统。
8
-
9
- ## 后续优化(Rust spec 直检)
10
-
11
- - preprocess 热路径改用 `registered_proc_cli_options()`,不再 clone 整个 `RegisteredProcDescriptor`。
12
- - `registered_proc_has_tag` 同样改为只读 map 查询。
13
- - `check_cli_options_map` 与 `resolve_cli_args` 共用 `collect_validation_errors`,preprocess 侧用引用收集 map 条目,避免多余 clone。
14
- - Registered 调用检查复用已有的 `processed_args`,去掉重复 `ys.drop_left()` 和 `alias` clone。
15
-
16
- ## 验证案例(cr eval)
17
-
18
- | 案例 | 结果 |
19
- |------|------|
20
- | `:file-pth` 拼写错误 | `W_CLI_OPTION_UNKNOWN_KEY` |
21
- | 缺少 `:file-path` | `W_CLI_OPTION_MISSING_REQUIRED` |
22
- | `:lines \|bad` 类型错误 | `W_CLI_OPTION_TYPE_MISMATCH` |
23
- | 正确调用 | Check passed |
@@ -1,116 +0,0 @@
1
- # calcit.cli 与 CLI handlers 重复代码分析与重构方案
2
-
3
- 时间: 2026-06-30
4
- 作者: AI Agent
5
-
6
- ## 现状
7
-
8
- ### 两套独立实现
9
-
10
- | 方面 | `injection/calcit_cli*.rs` | `cli_handlers/*.rs` |
11
- |------|---------------------------|---------------------|
12
- | 代码量 | ~2714 行 | ~5967 行 |
13
- | 入口 | `fn(xs: Vec<Calcit>, _: &CallStackList) -> Result<Calcit, CalcitErr>` | `fn(opts: &SpecificCommandStruct, snapshot_file: &str) -> Result<(), String>` |
14
- | 参数解析 | `resolve_cli_args()` → `ResolvedCliArgs` (从 Calcit Map 中提取) | argh 自动解析 CLI 参数到结构体 |
15
- | 输出 | `Calcit::Str(...)` 返回给 Calcit 运行时 | `println!()` 直接输出 |
16
- | 快照加载 | `load_calcit_snapshot()` | `load_snapshot()` |
17
- | 快照保存 | `save_calcit_snapshot()` | `save_snapshot()` |
18
-
19
- ### 完全重复的辅助函数
20
-
21
- | 函数 | injection/ 位置 | cli_handlers/ 位置 |
22
- |------|----------------|-------------------|
23
- | load_snapshot | calcit_cli.rs:1155 | edit.rs:101 |
24
- | save_snapshot | calcit_cli.rs:1217 | edit.rs:109 |
25
- | parse_path | calcit_cli.rs:933 | common.rs:182 |
26
- | navigate_to_node | calcit_cli.rs:905 | edit.rs:1267 |
27
- | parse_target | calcit_cli_args.rs (复用 cli_options) | edit.rs:22 |
28
- | check_ns_editable | calcit_cli.rs:1033 | edit.rs:114 |
29
- | apply_operation_at_path | calcit_cli_tree.rs | edit.rs:1152 |
30
- | process_node_with_references | calcit_cli_tree.rs | edit.rs:1290 |
31
-
32
- ## 推荐的桥接方案
33
-
34
- ### 方案: 提取共享核心 + 让 calcit.cli 代理到 cli_handlers
35
-
36
- 不直接让 `calcit.cli` procs 调用 `cli_handlers`(因为接口类型不同),而是:
37
-
38
- 1. **将核心业务逻辑(load → modify → save)提取到共享函数**,放在 `snapshot.rs` 或新建 `src/snapshot_ops.rs`
39
- 2. **`cli_handlers` 调用共享函数**
40
- 3. **`calcit.cli` 内部转发到共享函数**,而不是自己再实现一遍
41
-
42
- ### 关键接口对齐
43
-
44
- calcit.cli proc 的处理流程:
45
- ```
46
- Vec<Calcit> → resolve_cli_args() → ResolvedCliArgs → 提取参数 → 业务逻辑 → Calcit
47
- ```
48
-
49
- CLI handler 的处理流程:
50
- ```
51
- CLI struct → 提取参数 → 业务逻辑 → println!
52
- ```
53
-
54
- 共同点: 都需要 `(file_path, target, path, code)` 等参数, 都调用 `load_snapshot` / `save_snapshot` / `navigate_to_path` / `apply_operation_at_path`
55
-
56
- ### 具体步骤
57
-
58
- 1. 把 `load_snapshot`, `save_snapshot`, `navigate_to_path`, `parse_path`, `check_ns_editable`, `apply_operation_at_path`, `process_node_with_references` 等辅助函数统一放到 `src/snapshot_ops.rs` (或 `src/bin/cli_handlers/ops.rs`)
59
- 2. 把每个业务操作(如 tree-replace、show-def、list-defs)提取为纯函数:
60
- ```rust
61
- pub fn op_tree_replace(snapshot: &mut Snapshot, ns: &str, def: &str, path: &[usize], new_node: &Cirru) -> Result<(), String>
62
- pub fn op_show_def(snapshot: &Snapshot, ns: &str, def: &str) -> Result<String, String>
63
- ```
64
- 3. `calcit.cli` 的每个 proc handler 变成薄薄的代理层:
65
- ```rust
66
- pub fn tree_replace(xs: Vec<Calcit>, _cs: &CallStackList) -> Result<Calcit, CalcitErr> {
67
- let args = resolve_cli_args("calcit.cli/tree-replace", &xs, TREE_REPLACE)?;
68
- let mut snapshot = load_snapshot(&args.file_path()?)?;
69
- let (ns, def) = args.target("target")?;
70
- let path = parse_path(&args.string("path")?, false)?;
71
- let code = args.cirru_quote("code")?;
72
- ops::op_tree_replace(&mut snapshot, &ns, &def, &path, &code)?;
73
- save_snapshot(&snapshot, &args.file_path()?)?;
74
- Ok(Calcit::Str(Arc::from("replaced")))
75
- }
76
- ```
77
- 4. CLI handlers 也变成薄代理:
78
- ```rust
79
- fn handle_replace(opts: &TreeReplaceCommand, snapshot_file: &str) -> Result<(), String> {
80
- let (ns, def) = parse_target(&opts.target)?;
81
- let path = parse_path(&opts.path)?;
82
- let code = parse_input_to_cirru(...)?;
83
- let mut snapshot = load_snapshot(snapshot_file)?;
84
- ops::op_tree_replace(&mut snapshot, ns, def, &path, &code)?;
85
- save_snapshot(&snapshot, snapshot_file)?;
86
- // print preview...
87
- }
88
- ```
89
-
90
- ### 收益
91
- - 消除 ~2000 行重复代码
92
- - 修复 bug 只需改一处
93
- - 新功能只需写一次共享逻辑
94
-
95
- ### 风险
96
- - 大规模重构需要充分测试
97
- - 需要迁移 `calcit_cli_tree.rs` 中的复杂逻辑(rewrite with references)
98
- - `calcit.cli` 的 `CalcitErr` 错误类型和 `cli_handlers` 的 `String` 错误类型需要对齐
99
-
100
- ## 代码规模统计
101
-
102
- ```
103
- src/bin/injection/
104
- calcit_cli.rs 1297 行 ← 需要拆解: 辅助函数 + proc handlers
105
- calcit_cli_extra.rs 846 行 ← 同上
106
- calcit_cli_tree.rs 232 行 ← 纯辅助函数, 可整体移出
107
- calcit_cli_args.rs 147 行 ← 桥接层, 保留
108
- calcit_cli_specs.rs 192 行 ← 参数规格定义, 保留
109
- mod.rs ~60 行 ← 注册代码, 保留
110
-
111
- src/bin/cli_handlers/
112
- edit.rs 2026 行 ← 辅助函数 + handler 逻辑
113
- tree.rs 1433 行 ← handler 逻辑
114
- query.rs 2135 行 ← handler 逻辑
115
- common.rs 373 行 ← 工具函数
116
- ```