kumi 0.0.25 → 0.0.27

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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/CLAUDE.md +4 -0
  4. data/README.md +86 -78
  5. data/data/functions/agg/boolean.yaml +6 -2
  6. data/data/functions/agg/numeric.yaml +32 -16
  7. data/data/functions/agg/string.yaml +4 -3
  8. data/data/functions/core/arithmetic.yaml +62 -14
  9. data/data/functions/core/boolean.yaml +12 -6
  10. data/data/functions/core/comparison.yaml +25 -13
  11. data/data/functions/core/constructor.yaml +16 -8
  12. data/data/functions/core/conversion.yaml +32 -0
  13. data/data/functions/core/select.yaml +3 -1
  14. data/data/functions/core/stencil.yaml +14 -5
  15. data/data/functions/core/string.yaml +9 -4
  16. data/data/kernels/javascript/core/coercion.yaml +20 -0
  17. data/data/kernels/ruby/agg/numeric.yaml +1 -1
  18. data/data/kernels/ruby/core/coercion.yaml +20 -0
  19. data/docs/ARCHITECTURE.md +277 -0
  20. data/docs/DEVELOPMENT.md +62 -0
  21. data/docs/FUNCTIONS.md +955 -0
  22. data/docs/SYNTAX.md +8 -0
  23. data/docs/UNSAT_DETECTION.md +83 -0
  24. data/docs/VSCODE_EXTENSION.md +114 -0
  25. data/docs/functions-reference.json +1821 -0
  26. data/golden/array_element/expected/nast.txt +1 -1
  27. data/golden/array_element/expected/schema_ruby.rb +1 -1
  28. data/golden/array_index/expected/nast.txt +7 -7
  29. data/golden/array_index/expected/schema_ruby.rb +1 -1
  30. data/golden/array_operations/expected/nast.txt +2 -2
  31. data/golden/array_operations/expected/schema_ruby.rb +1 -1
  32. data/golden/array_operations/expected/snast.txt +3 -3
  33. data/golden/cascade_logic/expected/schema_ruby.rb +1 -1
  34. data/golden/cascade_logic/expected/snast.txt +2 -2
  35. data/golden/chained_fusion/expected/nast.txt +2 -2
  36. data/golden/chained_fusion/expected/schema_ruby.rb +1 -1
  37. data/golden/decimal_explicit/expected/ast.txt +38 -0
  38. data/golden/decimal_explicit/expected/input_plan.txt +3 -0
  39. data/golden/decimal_explicit/expected/lir_00_unoptimized.txt +30 -0
  40. data/golden/decimal_explicit/expected/lir_01_hoist_scalar_references.txt +30 -0
  41. data/golden/decimal_explicit/expected/lir_02_inlined.txt +44 -0
  42. data/golden/decimal_explicit/expected/lir_03_cse.txt +40 -0
  43. data/golden/decimal_explicit/expected/lir_04_1_loop_fusion.txt +40 -0
  44. data/golden/decimal_explicit/expected/lir_04_loop_invcm.txt +40 -0
  45. data/golden/decimal_explicit/expected/lir_06_const_prop.txt +40 -0
  46. data/golden/decimal_explicit/expected/nast.txt +30 -0
  47. data/golden/decimal_explicit/expected/schema_javascript.mjs +31 -0
  48. data/golden/decimal_explicit/expected/schema_ruby.rb +57 -0
  49. data/golden/decimal_explicit/expected/snast.txt +30 -0
  50. data/golden/decimal_explicit/expected.json +1 -0
  51. data/golden/decimal_explicit/input.json +5 -0
  52. data/golden/decimal_explicit/schema.kumi +14 -0
  53. data/golden/element_arrays/expected/nast.txt +2 -2
  54. data/golden/element_arrays/expected/schema_ruby.rb +1 -1
  55. data/golden/element_arrays/expected/snast.txt +1 -1
  56. data/golden/empty_and_null_inputs/expected/nast.txt +3 -3
  57. data/golden/empty_and_null_inputs/expected/schema_ruby.rb +1 -1
  58. data/golden/function_overload/expected/ast.txt +29 -0
  59. data/golden/function_overload/expected/input_plan.txt +4 -0
  60. data/golden/function_overload/expected/lir_00_unoptimized.txt +18 -0
  61. data/golden/function_overload/expected/lir_01_hoist_scalar_references.txt +18 -0
  62. data/golden/function_overload/expected/lir_02_inlined.txt +20 -0
  63. data/golden/function_overload/expected/lir_03_cse.txt +20 -0
  64. data/golden/function_overload/expected/lir_04_1_loop_fusion.txt +20 -0
  65. data/golden/function_overload/expected/lir_04_loop_invcm.txt +20 -0
  66. data/golden/function_overload/expected/lir_06_const_prop.txt +20 -0
  67. data/golden/function_overload/expected/nast.txt +22 -0
  68. data/golden/function_overload/expected/schema_javascript.mjs +12 -0
  69. data/golden/function_overload/expected/schema_ruby.rb +39 -0
  70. data/golden/function_overload/expected/snast.txt +22 -0
  71. data/golden/function_overload/input.json +8 -0
  72. data/golden/function_overload/schema.kumi +19 -0
  73. data/golden/game_of_life/expected/lir_00_unoptimized.txt +4 -4
  74. data/golden/game_of_life/expected/lir_01_hoist_scalar_references.txt +4 -4
  75. data/golden/game_of_life/expected/lir_02_inlined.txt +16 -16
  76. data/golden/game_of_life/expected/lir_03_cse.txt +20 -16
  77. data/golden/game_of_life/expected/lir_04_1_loop_fusion.txt +20 -16
  78. data/golden/game_of_life/expected/lir_04_loop_invcm.txt +20 -16
  79. data/golden/game_of_life/expected/lir_06_const_prop.txt +20 -16
  80. data/golden/game_of_life/expected/nast.txt +4 -4
  81. data/golden/game_of_life/expected/schema_javascript.mjs +4 -2
  82. data/golden/game_of_life/expected/schema_ruby.rb +5 -3
  83. data/golden/game_of_life/expected/snast.txt +10 -10
  84. data/golden/hash_keys/expected/schema_ruby.rb +1 -1
  85. data/golden/hash_value/expected/nast.txt +1 -1
  86. data/golden/hash_value/expected/schema_ruby.rb +1 -1
  87. data/golden/hash_value/expected/snast.txt +1 -1
  88. data/golden/hierarchical_complex/expected/nast.txt +3 -3
  89. data/golden/hierarchical_complex/expected/schema_ruby.rb +1 -1
  90. data/golden/hierarchical_complex/expected/snast.txt +3 -3
  91. data/golden/inline_rename_scope_leak/expected/nast.txt +3 -3
  92. data/golden/inline_rename_scope_leak/expected/schema_ruby.rb +1 -1
  93. data/golden/input_reference/expected/nast.txt +2 -2
  94. data/golden/input_reference/expected/schema_ruby.rb +1 -1
  95. data/golden/interleaved_fusion/expected/nast.txt +2 -2
  96. data/golden/interleaved_fusion/expected/schema_ruby.rb +1 -1
  97. data/golden/let_inline/expected/nast.txt +4 -4
  98. data/golden/let_inline/expected/schema_ruby.rb +1 -1
  99. data/golden/loop_fusion/expected/nast.txt +1 -1
  100. data/golden/loop_fusion/expected/schema_ruby.rb +1 -1
  101. data/golden/min_reduce_scope/expected/nast.txt +3 -3
  102. data/golden/min_reduce_scope/expected/schema_ruby.rb +1 -1
  103. data/golden/min_reduce_scope/expected/snast.txt +1 -1
  104. data/golden/mixed_dimensions/expected/nast.txt +2 -2
  105. data/golden/mixed_dimensions/expected/schema_ruby.rb +1 -1
  106. data/golden/multirank_hoisting/expected/nast.txt +7 -7
  107. data/golden/multirank_hoisting/expected/schema_ruby.rb +1 -1
  108. data/golden/nested_hash/expected/nast.txt +1 -1
  109. data/golden/nested_hash/expected/schema_ruby.rb +1 -1
  110. data/golden/reduction_broadcast/expected/nast.txt +3 -3
  111. data/golden/reduction_broadcast/expected/schema_ruby.rb +1 -1
  112. data/golden/reduction_broadcast/expected/snast.txt +1 -1
  113. data/golden/roll/expected/schema_ruby.rb +1 -1
  114. data/golden/shift/expected/schema_ruby.rb +1 -1
  115. data/golden/shift_2d/expected/schema_ruby.rb +1 -1
  116. data/golden/simple_math/expected/lir_00_unoptimized.txt +1 -1
  117. data/golden/simple_math/expected/lir_01_hoist_scalar_references.txt +1 -1
  118. data/golden/simple_math/expected/lir_02_inlined.txt +1 -1
  119. data/golden/simple_math/expected/lir_03_cse.txt +1 -1
  120. data/golden/simple_math/expected/lir_04_1_loop_fusion.txt +1 -1
  121. data/golden/simple_math/expected/lir_04_loop_invcm.txt +1 -1
  122. data/golden/simple_math/expected/lir_06_const_prop.txt +1 -1
  123. data/golden/simple_math/expected/nast.txt +5 -5
  124. data/golden/simple_math/expected/schema_ruby.rb +1 -1
  125. data/golden/simple_math/expected/snast.txt +2 -2
  126. data/golden/streaming_basics/expected/nast.txt +8 -8
  127. data/golden/streaming_basics/expected/schema_ruby.rb +1 -1
  128. data/golden/streaming_basics/expected/snast.txt +1 -1
  129. data/golden/tuples/expected/lir_00_unoptimized.txt +5 -5
  130. data/golden/tuples/expected/lir_01_hoist_scalar_references.txt +5 -5
  131. data/golden/tuples/expected/lir_02_inlined.txt +5 -5
  132. data/golden/tuples/expected/lir_03_cse.txt +5 -5
  133. data/golden/tuples/expected/lir_04_1_loop_fusion.txt +5 -5
  134. data/golden/tuples/expected/lir_04_loop_invcm.txt +5 -5
  135. data/golden/tuples/expected/lir_06_const_prop.txt +5 -5
  136. data/golden/tuples/expected/nast.txt +4 -4
  137. data/golden/tuples/expected/schema_ruby.rb +1 -1
  138. data/golden/tuples/expected/snast.txt +6 -6
  139. data/golden/tuples_and_arrays/expected/lir_00_unoptimized.txt +1 -1
  140. data/golden/tuples_and_arrays/expected/lir_01_hoist_scalar_references.txt +1 -1
  141. data/golden/tuples_and_arrays/expected/lir_02_inlined.txt +2 -2
  142. data/golden/tuples_and_arrays/expected/lir_03_cse.txt +2 -2
  143. data/golden/tuples_and_arrays/expected/lir_04_1_loop_fusion.txt +2 -2
  144. data/golden/tuples_and_arrays/expected/lir_04_loop_invcm.txt +2 -2
  145. data/golden/tuples_and_arrays/expected/lir_06_const_prop.txt +2 -2
  146. data/golden/tuples_and_arrays/expected/nast.txt +3 -3
  147. data/golden/tuples_and_arrays/expected/schema_ruby.rb +1 -1
  148. data/golden/tuples_and_arrays/expected/snast.txt +2 -2
  149. data/golden/us_tax_2024/expected/ast.txt +63 -670
  150. data/golden/us_tax_2024/expected/input_plan.txt +8 -45
  151. data/golden/us_tax_2024/expected/lir_00_unoptimized.txt +253 -863
  152. data/golden/us_tax_2024/expected/lir_01_hoist_scalar_references.txt +253 -863
  153. data/golden/us_tax_2024/expected/lir_02_inlined.txt +1215 -5139
  154. data/golden/us_tax_2024/expected/lir_03_cse.txt +587 -2460
  155. data/golden/us_tax_2024/expected/lir_04_1_loop_fusion.txt +632 -2480
  156. data/golden/us_tax_2024/expected/lir_04_loop_invcm.txt +587 -2460
  157. data/golden/us_tax_2024/expected/lir_06_const_prop.txt +587 -2460
  158. data/golden/us_tax_2024/expected/nast.txt +123 -826
  159. data/golden/us_tax_2024/expected/schema_javascript.mjs +127 -581
  160. data/golden/us_tax_2024/expected/schema_ruby.rb +135 -610
  161. data/golden/us_tax_2024/expected/snast.txt +155 -858
  162. data/golden/us_tax_2024/expected.json +120 -1
  163. data/golden/us_tax_2024/input.json +18 -9
  164. data/golden/us_tax_2024/schema.kumi +48 -178
  165. data/golden/with_constants/expected/lir_00_unoptimized.txt +1 -1
  166. data/golden/with_constants/expected/lir_01_hoist_scalar_references.txt +1 -1
  167. data/golden/with_constants/expected/lir_02_inlined.txt +1 -1
  168. data/golden/with_constants/expected/lir_03_cse.txt +1 -1
  169. data/golden/with_constants/expected/lir_04_1_loop_fusion.txt +1 -1
  170. data/golden/with_constants/expected/lir_04_loop_invcm.txt +1 -1
  171. data/golden/with_constants/expected/lir_06_const_prop.txt +1 -1
  172. data/golden/with_constants/expected/nast.txt +2 -2
  173. data/golden/with_constants/expected/schema_ruby.rb +1 -1
  174. data/golden/with_constants/expected/snast.txt +2 -2
  175. data/lib/kumi/analyzer.rb +12 -12
  176. data/lib/kumi/configuration.rb +6 -0
  177. data/lib/kumi/core/analyzer/passes/formal_constraint_propagator.rb +236 -0
  178. data/lib/kumi/core/analyzer/passes/input_collector.rb +22 -4
  179. data/lib/kumi/core/analyzer/passes/nast_dimensional_analyzer_pass.rb +64 -18
  180. data/lib/kumi/core/analyzer/passes/normalize_to_nast_pass.rb +9 -4
  181. data/lib/kumi/core/analyzer/passes/snast_pass.rb +3 -1
  182. data/lib/kumi/core/analyzer/passes/unsat_detector.rb +172 -198
  183. data/lib/kumi/core/error_reporter.rb +36 -1
  184. data/lib/kumi/core/errors.rb +33 -1
  185. data/lib/kumi/core/functions/function_spec.rb +5 -4
  186. data/lib/kumi/core/functions/loader.rb +17 -1
  187. data/lib/kumi/core/functions/overload_resolver.rb +164 -0
  188. data/lib/kumi/core/functions/type_error_reporter.rb +118 -0
  189. data/lib/kumi/core/functions/type_rules.rb +155 -35
  190. data/lib/kumi/core/input/type_matcher.rb +8 -1
  191. data/lib/kumi/core/ruby_parser/input_builder.rb +2 -2
  192. data/lib/kumi/core/types/inference.rb +29 -22
  193. data/lib/kumi/core/types/normalizer.rb +30 -45
  194. data/lib/kumi/core/types/validator.rb +17 -28
  195. data/lib/kumi/core/types/value_objects.rb +116 -0
  196. data/lib/kumi/core/types.rb +45 -37
  197. data/lib/kumi/dev/golden/reporter.rb +9 -0
  198. data/lib/kumi/dev/golden/result.rb +3 -1
  199. data/lib/kumi/dev/golden/runtime_test.rb +25 -0
  200. data/lib/kumi/dev/golden/suite.rb +4 -4
  201. data/lib/kumi/dev/golden/value_normalizer.rb +80 -0
  202. data/lib/kumi/dev/golden.rb +21 -12
  203. data/lib/kumi/doc_generator/formatters/json.rb +39 -0
  204. data/lib/kumi/doc_generator/formatters/markdown.rb +175 -0
  205. data/lib/kumi/doc_generator/loader.rb +37 -0
  206. data/lib/kumi/doc_generator/merger.rb +54 -0
  207. data/lib/kumi/doc_generator.rb +4 -0
  208. data/lib/kumi/registry_v2/loader.rb +90 -0
  209. data/lib/kumi/registry_v2.rb +18 -1
  210. data/lib/kumi/version.rb +1 -1
  211. data/vscode-extension/.gitignore +4 -0
  212. data/vscode-extension/README.md +59 -0
  213. data/vscode-extension/TESTING.md +151 -0
  214. data/vscode-extension/package.json +51 -0
  215. data/vscode-extension/src/extension.ts +295 -0
  216. data/vscode-extension/tsconfig.json +15 -0
  217. metadata +57 -7
  218. data/lib/kumi/core/analyzer/unsat_constant_evaluator.rb +0 -59
  219. data/lib/kumi/core/atom_unsat_solver.rb +0 -396
  220. data/lib/kumi/core/constraint_relationship_solver.rb +0 -641
  221. data/lib/kumi/core/types/builder.rb +0 -23
  222. data/lib/kumi/core/types/compatibility.rb +0 -96
  223. data/lib/kumi/core/types/formatter.rb +0 -26
@@ -2,6 +2,8 @@ functions:
2
2
  - id: __select__
3
3
  kind: elementwise
4
4
  params: [{ name: condition_mask }, { name: value_when_true }, { name: value_when_false }]
5
- dtype: "same_as(value_when_true)"
5
+ dtype:
6
+ rule: same_as
7
+ param: value_when_true
6
8
  aliases: ["select", "if"]
7
9
  folding_class_method: select
@@ -1,8 +1,10 @@
1
1
  functions:
2
2
  - id: roll
3
3
  kind: elementwise
4
- params: [{ name: source }, { name: offset }]
5
- dtype: "same_as(source)"
4
+ params: [{ name: source }, { name: offset }]
5
+ dtype:
6
+ rule: same_as
7
+ param: source
6
8
  options:
7
9
  policy: wrap # wrap|clamp
8
10
  axis_offset: 0
@@ -10,12 +12,19 @@ functions:
10
12
  - id: shift
11
13
  kind: elementwise
12
14
  params: [{ name: source }, { name: offset }]
13
- dtype: "same_as(source)"
15
+ dtype:
16
+ rule: same_as
17
+ param: source
14
18
  options:
15
19
  policy: zero # zero|clamp
16
20
  axis_offset: 0
21
+ constraint_semantics:
22
+ domain_effect: NONE
23
+ pure_combiner: false
17
24
 
18
25
  - id: index
19
26
  kind: elementwise
20
- params: [{name: index_name, dtype: string }]
21
- dtype: integer
27
+ params: [{ name: index_name, dtype: string }]
28
+ dtype:
29
+ rule: scalar
30
+ kind: integer
@@ -2,18 +2,23 @@ functions:
2
2
  - id: core.concat
3
3
  kind: elementwise
4
4
  params: [{ name: left_string }, { name: right_string }]
5
- dtype: "string"
5
+ dtype:
6
+ rule: scalar
7
+ kind: string
6
8
  aliases: ["concat"]
7
9
 
8
10
  - id: core.upcase
9
11
  kind: elementwise
10
12
  params: [{ name: string }]
11
- dtype: "string"
13
+ dtype:
14
+ rule: scalar
15
+ kind: string
12
16
  aliases: ["upcase"]
13
17
 
14
18
  - id: core.downcase
15
19
  kind: elementwise
16
20
  params: [{ name: string }]
17
- dtype: "string"
21
+ dtype:
22
+ rule: scalar
23
+ kind: string
18
24
  aliases: ["downcase"]
19
-
@@ -0,0 +1,20 @@
1
+ kernels:
2
+ - id: to_decimal:javascript:v1
3
+ fn: core.to_decimal
4
+ inline: "= typeof $0 === 'string' ? parseFloat($0) : Number($0)"
5
+ impl: "(value) {\n if (typeof value === 'string') return parseFloat(value);\n return Number(value);\n}"
6
+
7
+ - id: to_integer:javascript:v1
8
+ fn: core.to_integer
9
+ inline: "= parseInt($0)"
10
+ impl: "(value) { return parseInt(value); }"
11
+
12
+ - id: to_float:javascript:v1
13
+ fn: core.to_float
14
+ inline: "= parseFloat($0)"
15
+ impl: "(value) { return parseFloat(value); }"
16
+
17
+ - id: to_string:javascript:v1
18
+ fn: core.to_string
19
+ inline: "= String($0)"
20
+ impl: "(value) { return String(value); }"
@@ -4,7 +4,7 @@ kernels:
4
4
  inline: "+= $1"
5
5
  impl: "(a,b)\n a + b"
6
6
  fold_inline: "= $0.sum"
7
- identity:
7
+ identity:
8
8
  float: 0.0
9
9
  integer: 0
10
10
 
@@ -0,0 +1,20 @@
1
+ kernels:
2
+ - id: to_decimal:ruby:v1
3
+ fn: core.to_decimal
4
+ inline: "= $0.is_a?(BigDecimal) ? $0 : BigDecimal($0.to_s)"
5
+ impl: "(value)\n case value\n when BigDecimal then value\n when String then BigDecimal(value)\n when Numeric then BigDecimal(value.to_s)\n else raise TypeError, \"Cannot coerce #{value.class} to Decimal\"\n end"
6
+
7
+ - id: to_integer:ruby:v1
8
+ fn: core.to_integer
9
+ inline: "= $0.to_i"
10
+ impl: "(value)\n value.to_i"
11
+
12
+ - id: to_float:ruby:v1
13
+ fn: core.to_float
14
+ inline: "= $0.to_f"
15
+ impl: "(value)\n value.to_f"
16
+
17
+ - id: to_string:ruby:v1
18
+ fn: core.to_string
19
+ inline: "= $0.to_s"
20
+ impl: "(value)\n value.to_s"
@@ -0,0 +1,277 @@
1
+ # Kumi Documentation & IDE Architecture
2
+
3
+ ## Overview
4
+
5
+ This document describes the automatic documentation generation system and IDE support infrastructure for Kumi functions and kernels.
6
+
7
+ ## System Architecture
8
+
9
+ ```
10
+ ┌─────────────────────────────────────┐
11
+ │ Function & Kernel Definitions │
12
+ ├─────────────────────────────────────┤
13
+ │ data/functions/*.yaml │
14
+ │ data/kernels/**/*.yaml │
15
+ └──────────────┬──────────────────────┘
16
+
17
+ ┌──────▼──────┐
18
+ │ bin/kumi- │
19
+ │ doc-gen │
20
+ └──────┬──────┘
21
+
22
+ ┌────────┴────────┐
23
+ │ │
24
+ ┌──▼───┐ ┌─────▼──────┐
25
+ │ JSON │ │ Markdown │
26
+ │ Data │ │ Reference │
27
+ └──┬───┘ └─────┬──────┘
28
+ │ │
29
+ ┌───▼──────────┐ ┌───▼─────────────────┐
30
+ │ IDE Tools │ │ Developers/Docs │
31
+ ├──────────────┤ ├─────────────────────┤
32
+ │ VSCode │ │ docs/FUNCTIONS.md │
33
+ │ Monaco │ │ GitHub Reference │
34
+ │ LSP Servers │ │ API Documentation │
35
+ └──────────────┘ └─────────────────────┘
36
+ ```
37
+
38
+ ## Core Components
39
+
40
+ ### 1. Data Sources
41
+
42
+ **Function Definitions** (`data/functions/*.yaml`)
43
+ ```yaml
44
+ functions:
45
+ - id: agg.sum
46
+ kind: reduce
47
+ params: [{ name: source_value }]
48
+ dtype: { rule: same_as, param: source_value }
49
+ reduction_strategy: identity # KEY: Identity-based reducer
50
+ aliases: ["sum"]
51
+
52
+ - id: agg.min
53
+ kind: reduce
54
+ params: [{ name: source_value }]
55
+ dtype: { rule: element_of, param: source_value }
56
+ reduction_strategy: first_element # KEY: First-element reducer
57
+ aliases: ["min"]
58
+ ```
59
+
60
+ **Kernel Implementations** (`data/kernels/ruby/*.yaml`)
61
+ ```yaml
62
+ kernels:
63
+ - id: agg.sum:ruby:v1
64
+ fn: agg.sum
65
+ inline: "+= $1"
66
+ impl: "(a,b)\n a + b"
67
+ fold_inline: "= $0.sum"
68
+ identity:
69
+ float: 0.0
70
+ integer: 0
71
+ ```
72
+
73
+ ### 2. Doc Generator Module
74
+
75
+ **Location:** `lib/kumi/doc_generator/`
76
+
77
+ #### Loader
78
+ - Parses YAML files from `data/functions/` and `data/kernels/`
79
+ - Returns raw function and kernel definitions
80
+ - No transformation or filtering
81
+
82
+ #### Merger
83
+ - Combines function definitions with kernel implementations
84
+ - Creates entries indexed by function aliases (so `sum`, `add`, `sub` all resolvable)
85
+ - Extracts important metadata:
86
+ - `reduction_strategy` - How the reducer initializes
87
+ - `dtype` - Type inference rules
88
+ - `arity` - Parameter count
89
+ - `kernels` - Available implementations
90
+
91
+ #### Formatters
92
+
93
+ **Json Formatter**
94
+ - Output: `docs/functions-reference.json`
95
+ - Consumer: IDE plugins (VSCode, Monaco, etc.)
96
+ - Data:
97
+ - Function ID and aliases
98
+ - Arity and parameter info
99
+ - Type information
100
+ - Kernel availability
101
+ - **Reduction strategy** (for reducer distinction)
102
+
103
+ **Markdown Formatter**
104
+ - Output: `docs/FUNCTIONS.md`
105
+ - Consumer: Developers, documentation sites
106
+ - Presentation:
107
+ - Human-readable function descriptions
108
+ - Inline operations (`$0 = accumulator, $1 = element`)
109
+ - Actual implementation code
110
+ - Fold strategies
111
+ - Identity values (when applicable)
112
+ - **Reduction semantics** (monoid vs first-element)
113
+
114
+ ### 3. VSCode Extension
115
+
116
+ **Location:** `vscode-extension/`
117
+
118
+ **Features:**
119
+ - Autocomplete for functions when typing `fn(:`
120
+ - Hover tooltips with signatures
121
+ - Schema block context detection (Ruby files only)
122
+ - Works with `.kumi` and `.rb` files
123
+
124
+ **Components:**
125
+ - `FunctionCompletionProvider` - Offers suggestions
126
+ - `FunctionHoverProvider` - Shows detailed information
127
+ - `isInSchemaBlock()` - Detects if inside `schema do...end` block (Ruby files)
128
+
129
+ ## Key Design Decisions
130
+
131
+ ### 1. Reduction Strategy Distinction
132
+
133
+ **Problem:** Min/Max don't have identity values like Sum/Count do.
134
+
135
+ **Solution:** Capture `reduction_strategy` from YAML:
136
+ - `identity` → Monoid operation, can use identity element
137
+ - `first_element` → First array element initializes accumulator
138
+
139
+ **Display:**
140
+ - Markdown shows: "Monoid operation with identity element" or "First element is initial value"
141
+ - JSON includes: `"reduction_strategy": "identity" | "first_element"`
142
+
143
+ ### 2. Kernel Implementation Visibility
144
+
145
+ **Decision:** Show actual kernel code inline in markdown.
146
+
147
+ **Benefits:**
148
+ - Developers see what the function actually does
149
+ - Inline operations (`+= $1` vs `= $1 if $1 < $0`) show the pattern
150
+ - Implementation code is actual Ruby/JavaScript
151
+
152
+ **Format:**
153
+ ```markdown
154
+ **Inline:** `+= $1` ($0 = accumulator, $1 = element)
155
+ **Implementation:**
156
+ ```ruby
157
+ (a,b)
158
+ a + b
159
+ ```
160
+ **Fold:** `= $0.sum`
161
+ **Identity:** float: 0.0, integer: 0
162
+ ```
163
+
164
+ ### 3. Single Source of Truth
165
+
166
+ **Flow:**
167
+ ```
168
+ YAML definitions
169
+
170
+ bin/kumi-doc-gen (one command)
171
+
172
+ ├→ docs/FUNCTIONS.md (auto-generated)
173
+ ├→ docs/functions-reference.json (auto-generated)
174
+ └→ IDE/Tools consume JSON
175
+ ```
176
+
177
+ Changes to function definitions automatically flow to:
178
+ - IDE completions
179
+ - Markdown reference
180
+ - JSON API
181
+
182
+ ### 4. Context-Aware IDE Support
183
+
184
+ **Ruby files:** Only offer completions inside `schema do...end` blocks
185
+ - Prevents noise from unrelated `fn(:` calls
186
+ - Tracks brace nesting to detect context
187
+
188
+ **Kumi files:** Always available
189
+ - Native language file type
190
+
191
+ ## Data Model
192
+
193
+ ### Function Entry (After Merge)
194
+ ```json
195
+ {
196
+ "id": "agg.sum",
197
+ "kind": "reduce",
198
+ "arity": 1,
199
+ "params": [{ "name": "source_value" }],
200
+ "dtype": { "rule": "same_as", "param": "source_value" },
201
+ "aliases": ["sum"],
202
+ "reduction_strategy": "identity",
203
+ "kernels": {
204
+ "ruby": {
205
+ "id": "agg.sum:ruby:v1",
206
+ "inline": "+= $1",
207
+ "impl": "(a,b)\n a + b",
208
+ "fold_inline": "= $0.sum",
209
+ "identity": { "float": 0.0, "integer": 0 }
210
+ }
211
+ }
212
+ }
213
+ ```
214
+
215
+ ## Usage Workflows
216
+
217
+ ### For End Users
218
+
219
+ **View function reference:**
220
+ ```bash
221
+ # Markdown documentation
222
+ open docs/FUNCTIONS.md
223
+
224
+ # IDE support (VSCode)
225
+ cd vscode-extension && npm install && npm run compile
226
+ # Press F5 in VSCode
227
+ ```
228
+
229
+ ### For Developers
230
+
231
+ **Modify functions:**
232
+ 1. Update `data/functions/category/*.yaml`
233
+ 2. Run `bin/kumi-doc-gen`
234
+ 3. Commit both YAML and generated files
235
+
236
+ **Add new reducer:**
237
+ ```yaml
238
+ - id: agg.product
239
+ kind: reduce
240
+ params: [{ name: source_value }]
241
+ reduction_strategy: identity
242
+ aliases: ["product"]
243
+ ```
244
+ Add kernel in `data/kernels/ruby/agg/numeric.yaml`, then regenerate docs.
245
+
246
+ ## Extension Points
247
+
248
+ The architecture supports adding:
249
+
250
+ 1. **New formatters** (HTML, PDF, LSP protocol)
251
+ 2. **New generators** (TypeScript definitions, GraphQL schema)
252
+ 3. **New IDE support** (Neovim, Emacs plugins via LSP)
253
+ 4. **Validation** (against declared types/arity)
254
+
255
+ All through the same YAML source data.
256
+
257
+ ## Testing
258
+
259
+ - 8 comprehensive tests for doc generation
260
+ - All 944 existing Kumi tests pass
261
+ - No regression in core functionality
262
+
263
+ ## Performance
264
+
265
+ - **Generation time:** <100ms for all functions
266
+ - **File sizes:**
267
+ - FUNCTIONS.md: ~950 lines
268
+ - functions-reference.json: ~1800 lines
269
+ - **IDE load time:** Instant (JSON loaded once on activation)
270
+
271
+ ## Future Improvements
272
+
273
+ 1. **LSP Server**: Standalone language server for any editor
274
+ 2. **Type validation**: Check function call arity at compile time
275
+ 3. **IDE diagnostics**: Show type mismatches as you type
276
+ 4. **Documentation linking**: Cross-reference related functions
277
+ 5. **Kernel visualization**: Show kernel implementations side-by-side
@@ -0,0 +1,62 @@
1
+ # Kumi Development Guide
2
+
3
+ This document covers common development tasks and tools.
4
+
5
+ ## Documentation Generation
6
+
7
+ ### Generating Function Reference
8
+
9
+ Kumi automatically generates documentation for functions and kernels from YAML definitions:
10
+
11
+ ```bash
12
+ bin/kumi-doc-gen
13
+ ```
14
+
15
+ This generates:
16
+ - **JSON:** `docs/functions-reference.json` - IDE-friendly format with function signatures, parameters, and kernel mappings
17
+ - **Markdown:** `docs/FUNCTIONS.md` - Human-readable function reference
18
+
19
+ The generated docs can be used by:
20
+ - IDEs (VSCode, Monaco) for autocomplete and hover information
21
+ - API documentation sites
22
+ - LSP servers for language features
23
+ - Custom tooling
24
+
25
+ Run this whenever you modify function definitions in `data/functions/` or kernels in `data/kernels/`.
26
+
27
+ ### Module: `Kumi::DocGenerator`
28
+
29
+ Located in `lib/kumi/doc_generator/`, this module provides:
30
+
31
+ - **`Loader`** - Load function and kernel definitions from YAML
32
+ - **`Merger`** - Combine function metadata with kernel implementations
33
+ - **`Formatters::Json`** - Generate IDE-consumable JSON
34
+ - **`Formatters::Markdown`** - Generate markdown documentation
35
+
36
+ The module is decoupled from the analyzer and compilation pipeline, making it suitable for independent use.
37
+
38
+ ## IDE Integration
39
+
40
+ ### VSCode Extension
41
+
42
+ The `vscode-extension/` directory contains a VSCode extension that provides:
43
+ - Autocomplete for Kumi functions
44
+ - Hover tooltips with function signatures
45
+ - Type information and arity display
46
+
47
+ See [VSCODE_EXTENSION.md](VSCODE_EXTENSION.md) for setup and usage.
48
+
49
+ Quick start:
50
+ ```bash
51
+ cd vscode-extension && npm install && npm run compile
52
+ # Then open in VSCode and press F5
53
+ ```
54
+
55
+ The extension reads from `docs/functions-reference.json`, so always regenerate docs after function changes:
56
+ ```bash
57
+ bin/kumi-doc-gen
58
+ ```
59
+
60
+ ---
61
+
62
+ *More development guides coming soon.*