@rcrsr/rill 0.5.0 → 0.6.1

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 (240) hide show
  1. package/README.md +88 -162
  2. package/dist/generated/introspection-data.d.ts +1 -1
  3. package/dist/generated/introspection-data.d.ts.map +1 -1
  4. package/dist/generated/introspection-data.js +107 -186
  5. package/dist/generated/introspection-data.js.map +1 -1
  6. package/dist/generated/version-data.d.ts +1 -1
  7. package/dist/generated/version-data.js +4 -4
  8. package/dist/generated/version-data.js.map +1 -1
  9. package/dist/highlight-map.d.ts +4 -0
  10. package/dist/highlight-map.d.ts.map +1 -0
  11. package/dist/highlight-map.js +71 -0
  12. package/dist/highlight-map.js.map +1 -0
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/lexer/errors.d.ts.map +1 -1
  18. package/dist/lexer/errors.js +9 -3
  19. package/dist/lexer/errors.js.map +1 -1
  20. package/dist/lexer/operators.js +1 -1
  21. package/dist/lexer/tokenizer.d.ts.map +1 -1
  22. package/dist/lexer/tokenizer.js +0 -14
  23. package/dist/lexer/tokenizer.js.map +1 -1
  24. package/dist/parser/helpers.d.ts +8 -0
  25. package/dist/parser/helpers.d.ts.map +1 -1
  26. package/dist/parser/helpers.js +4 -4
  27. package/dist/parser/helpers.js.map +1 -1
  28. package/dist/parser/index.d.ts.map +1 -1
  29. package/dist/parser/index.js +1 -1
  30. package/dist/parser/index.js.map +1 -1
  31. package/dist/parser/parser-collect.js +1 -1
  32. package/dist/parser/parser-collect.js.map +1 -1
  33. package/dist/parser/parser-control.js +4 -4
  34. package/dist/parser/parser-control.js.map +1 -1
  35. package/dist/parser/parser-expr.js +32 -10
  36. package/dist/parser/parser-expr.js.map +1 -1
  37. package/dist/parser/parser-extract.js +7 -3
  38. package/dist/parser/parser-extract.js.map +1 -1
  39. package/dist/parser/parser-functions.d.ts.map +1 -1
  40. package/dist/parser/parser-functions.js +7 -18
  41. package/dist/parser/parser-functions.js.map +1 -1
  42. package/dist/parser/parser-literals.js +15 -15
  43. package/dist/parser/parser-literals.js.map +1 -1
  44. package/dist/parser/parser-script.js +3 -3
  45. package/dist/parser/parser-script.js.map +1 -1
  46. package/dist/parser/parser-variables.js +4 -4
  47. package/dist/parser/parser-variables.js.map +1 -1
  48. package/dist/parser/state.d.ts +1 -1
  49. package/dist/parser/state.d.ts.map +1 -1
  50. package/dist/parser/state.js +2 -2
  51. package/dist/parser/state.js.map +1 -1
  52. package/dist/runtime/core/callable.d.ts +20 -0
  53. package/dist/runtime/core/callable.d.ts.map +1 -1
  54. package/dist/runtime/core/callable.js +30 -7
  55. package/dist/runtime/core/callable.js.map +1 -1
  56. package/dist/runtime/core/context.d.ts +21 -0
  57. package/dist/runtime/core/context.d.ts.map +1 -1
  58. package/dist/runtime/core/context.js +75 -4
  59. package/dist/runtime/core/context.js.map +1 -1
  60. package/dist/runtime/core/eval/base.d.ts.map +1 -1
  61. package/dist/runtime/core/eval/base.js +3 -3
  62. package/dist/runtime/core/eval/base.js.map +1 -1
  63. package/dist/runtime/core/eval/index.d.ts.map +1 -1
  64. package/dist/runtime/core/eval/index.js +2 -0
  65. package/dist/runtime/core/eval/index.js.map +1 -1
  66. package/dist/runtime/core/eval/mixins/annotations.js +3 -3
  67. package/dist/runtime/core/eval/mixins/annotations.js.map +1 -1
  68. package/dist/runtime/core/eval/mixins/closures.d.ts.map +1 -1
  69. package/dist/runtime/core/eval/mixins/closures.js +69 -40
  70. package/dist/runtime/core/eval/mixins/closures.js.map +1 -1
  71. package/dist/runtime/core/eval/mixins/collections.js +15 -15
  72. package/dist/runtime/core/eval/mixins/collections.js.map +1 -1
  73. package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +1 -1
  74. package/dist/runtime/core/eval/mixins/control-flow.js +12 -12
  75. package/dist/runtime/core/eval/mixins/control-flow.js.map +1 -1
  76. package/dist/runtime/core/eval/mixins/core.d.ts.map +1 -1
  77. package/dist/runtime/core/eval/mixins/core.js +12 -13
  78. package/dist/runtime/core/eval/mixins/core.js.map +1 -1
  79. package/dist/runtime/core/eval/mixins/expressions.js +9 -9
  80. package/dist/runtime/core/eval/mixins/expressions.js.map +1 -1
  81. package/dist/runtime/core/eval/mixins/extraction.d.ts.map +1 -1
  82. package/dist/runtime/core/eval/mixins/extraction.js +15 -15
  83. package/dist/runtime/core/eval/mixins/extraction.js.map +1 -1
  84. package/dist/runtime/core/eval/mixins/literals.js +22 -22
  85. package/dist/runtime/core/eval/mixins/literals.js.map +1 -1
  86. package/dist/runtime/core/eval/mixins/types.js +4 -4
  87. package/dist/runtime/core/eval/mixins/types.js.map +1 -1
  88. package/dist/runtime/core/eval/mixins/variables.js +34 -34
  89. package/dist/runtime/core/eval/mixins/variables.js.map +1 -1
  90. package/dist/runtime/core/execute.js +3 -3
  91. package/dist/runtime/core/execute.js.map +1 -1
  92. package/dist/runtime/core/introspection.d.ts +30 -1
  93. package/dist/runtime/core/introspection.d.ts.map +1 -1
  94. package/dist/runtime/core/introspection.js +47 -1
  95. package/dist/runtime/core/introspection.js.map +1 -1
  96. package/dist/runtime/core/types.d.ts +11 -0
  97. package/dist/runtime/core/types.d.ts.map +1 -1
  98. package/dist/runtime/core/types.js.map +1 -1
  99. package/dist/runtime/ext/builtins.js +22 -22
  100. package/dist/runtime/ext/builtins.js.map +1 -1
  101. package/dist/runtime/ext/extensions.d.ts +1 -1
  102. package/dist/runtime/ext/extensions.d.ts.map +1 -1
  103. package/dist/runtime/ext/extensions.js +4 -5
  104. package/dist/runtime/ext/extensions.js.map +1 -1
  105. package/dist/runtime/index.d.ts +6 -4
  106. package/dist/runtime/index.d.ts.map +1 -1
  107. package/dist/runtime/index.js +3 -2
  108. package/dist/runtime/index.js.map +1 -1
  109. package/dist/types.d.ts +36 -37
  110. package/dist/types.d.ts.map +1 -1
  111. package/dist/types.js +440 -120
  112. package/dist/types.js.map +1 -1
  113. package/package.json +7 -66
  114. package/dist/check/config.d.ts +0 -20
  115. package/dist/check/config.d.ts.map +0 -1
  116. package/dist/check/config.js +0 -151
  117. package/dist/check/config.js.map +0 -1
  118. package/dist/check/fixer.d.ts +0 -39
  119. package/dist/check/fixer.d.ts.map +0 -1
  120. package/dist/check/fixer.js +0 -119
  121. package/dist/check/fixer.js.map +0 -1
  122. package/dist/check/index.d.ts +0 -10
  123. package/dist/check/index.d.ts.map +0 -1
  124. package/dist/check/index.js +0 -21
  125. package/dist/check/index.js.map +0 -1
  126. package/dist/check/rules/anti-patterns.d.ts +0 -65
  127. package/dist/check/rules/anti-patterns.d.ts.map +0 -1
  128. package/dist/check/rules/anti-patterns.js +0 -481
  129. package/dist/check/rules/anti-patterns.js.map +0 -1
  130. package/dist/check/rules/closures.d.ts +0 -66
  131. package/dist/check/rules/closures.d.ts.map +0 -1
  132. package/dist/check/rules/closures.js +0 -370
  133. package/dist/check/rules/closures.js.map +0 -1
  134. package/dist/check/rules/collections.d.ts +0 -90
  135. package/dist/check/rules/collections.d.ts.map +0 -1
  136. package/dist/check/rules/collections.js +0 -373
  137. package/dist/check/rules/collections.js.map +0 -1
  138. package/dist/check/rules/conditionals.d.ts +0 -41
  139. package/dist/check/rules/conditionals.d.ts.map +0 -1
  140. package/dist/check/rules/conditionals.js +0 -134
  141. package/dist/check/rules/conditionals.js.map +0 -1
  142. package/dist/check/rules/flow.d.ts +0 -46
  143. package/dist/check/rules/flow.d.ts.map +0 -1
  144. package/dist/check/rules/flow.js +0 -206
  145. package/dist/check/rules/flow.js.map +0 -1
  146. package/dist/check/rules/formatting.d.ts +0 -133
  147. package/dist/check/rules/formatting.d.ts.map +0 -1
  148. package/dist/check/rules/formatting.js +0 -648
  149. package/dist/check/rules/formatting.js.map +0 -1
  150. package/dist/check/rules/helpers.d.ts +0 -26
  151. package/dist/check/rules/helpers.d.ts.map +0 -1
  152. package/dist/check/rules/helpers.js +0 -66
  153. package/dist/check/rules/helpers.js.map +0 -1
  154. package/dist/check/rules/index.d.ts +0 -21
  155. package/dist/check/rules/index.d.ts.map +0 -1
  156. package/dist/check/rules/index.js +0 -78
  157. package/dist/check/rules/index.js.map +0 -1
  158. package/dist/check/rules/loops.d.ts +0 -77
  159. package/dist/check/rules/loops.d.ts.map +0 -1
  160. package/dist/check/rules/loops.js +0 -310
  161. package/dist/check/rules/loops.js.map +0 -1
  162. package/dist/check/rules/naming.d.ts +0 -21
  163. package/dist/check/rules/naming.d.ts.map +0 -1
  164. package/dist/check/rules/naming.js +0 -174
  165. package/dist/check/rules/naming.js.map +0 -1
  166. package/dist/check/rules/strings.d.ts +0 -28
  167. package/dist/check/rules/strings.d.ts.map +0 -1
  168. package/dist/check/rules/strings.js +0 -79
  169. package/dist/check/rules/strings.js.map +0 -1
  170. package/dist/check/rules/types.d.ts +0 -41
  171. package/dist/check/rules/types.d.ts.map +0 -1
  172. package/dist/check/rules/types.js +0 -167
  173. package/dist/check/rules/types.js.map +0 -1
  174. package/dist/check/types.d.ts +0 -112
  175. package/dist/check/types.d.ts.map +0 -1
  176. package/dist/check/types.js +0 -6
  177. package/dist/check/types.js.map +0 -1
  178. package/dist/check/validator.d.ts +0 -18
  179. package/dist/check/validator.d.ts.map +0 -1
  180. package/dist/check/validator.js +0 -110
  181. package/dist/check/validator.js.map +0 -1
  182. package/dist/check/visitor.d.ts +0 -33
  183. package/dist/check/visitor.d.ts.map +0 -1
  184. package/dist/check/visitor.js +0 -259
  185. package/dist/check/visitor.js.map +0 -1
  186. package/dist/cli-check.d.ts +0 -43
  187. package/dist/cli-check.d.ts.map +0 -1
  188. package/dist/cli-check.js +0 -368
  189. package/dist/cli-check.js.map +0 -1
  190. package/dist/cli-eval.d.ts +0 -15
  191. package/dist/cli-eval.d.ts.map +0 -1
  192. package/dist/cli-eval.js +0 -116
  193. package/dist/cli-eval.js.map +0 -1
  194. package/dist/cli-exec.d.ts +0 -49
  195. package/dist/cli-exec.d.ts.map +0 -1
  196. package/dist/cli-exec.js +0 -183
  197. package/dist/cli-exec.js.map +0 -1
  198. package/dist/cli-module-loader.d.ts +0 -19
  199. package/dist/cli-module-loader.d.ts.map +0 -1
  200. package/dist/cli-module-loader.js +0 -83
  201. package/dist/cli-module-loader.js.map +0 -1
  202. package/dist/cli-shared.d.ts +0 -44
  203. package/dist/cli-shared.d.ts.map +0 -1
  204. package/dist/cli-shared.js +0 -108
  205. package/dist/cli-shared.js.map +0 -1
  206. package/dist/cli.d.ts +0 -13
  207. package/dist/cli.d.ts.map +0 -1
  208. package/dist/cli.js +0 -62
  209. package/dist/cli.js.map +0 -1
  210. package/dist/runtime/core/introspection-data.d.ts +0 -2
  211. package/dist/runtime/core/introspection-data.d.ts.map +0 -1
  212. package/dist/runtime/core/introspection-data.js +0 -618
  213. package/dist/runtime/core/introspection-data.js.map +0 -1
  214. package/dist/runtime/core/version-data.d.ts +0 -18
  215. package/dist/runtime/core/version-data.d.ts.map +0 -1
  216. package/dist/runtime/core/version-data.js +0 -16
  217. package/dist/runtime/core/version-data.js.map +0 -1
  218. package/docs/00_INDEX.md +0 -67
  219. package/docs/01_guide.md +0 -390
  220. package/docs/02_types.md +0 -504
  221. package/docs/03_variables.md +0 -324
  222. package/docs/04_operators.md +0 -629
  223. package/docs/05_control-flow.md +0 -692
  224. package/docs/06_closures.md +0 -787
  225. package/docs/07_collections.md +0 -688
  226. package/docs/08_iterators.md +0 -330
  227. package/docs/09_strings.md +0 -205
  228. package/docs/10_parsing.md +0 -366
  229. package/docs/11_reference.md +0 -600
  230. package/docs/12_examples.md +0 -748
  231. package/docs/13_modules.md +0 -519
  232. package/docs/14_host-integration.md +0 -985
  233. package/docs/15_grammar.ebnf +0 -773
  234. package/docs/16_conventions.md +0 -695
  235. package/docs/17_cli-tools.md +0 -184
  236. package/docs/18_design-principles.md +0 -247
  237. package/docs/19_cookbook.md +0 -628
  238. package/docs/88_errors.md +0 -902
  239. package/docs/99_llm-reference.txt +0 -614
  240. package/docs/assets/logo.png +0 -0
@@ -1,748 +0,0 @@
1
- # rill Core Examples
2
-
3
- Examples demonstrating core language features for workflow orchestration.
4
-
5
- > **Note:** These examples use `app::` prefix for host-provided functions (`app::prompt()`, `app::fetch()`, etc.). Built-in functions (`log`, `parse_json`, `range`) need no prefix. Frontmatter is opaque to rill; the host parses it and provides named variables to the script context.
6
-
7
- ## Feature Implementation Workflow
8
-
9
- Validates requirements, creates spec, iterates on review, then implements.
10
-
11
- ```text
12
- ---
13
- timeout: 00:10:00
14
- args: requirements: string
15
- ---
16
-
17
- # Phase 1: Validate requirements
18
- """
19
- Review the requirements document at {$requirements}.
20
- Check for completeness and clarity.
21
- Output READY if complete, or list missing elements.
22
- """ -> app::prompt() :> $validation
23
-
24
- $validation -> .contains("READY") -> !$ ? {
25
- error "Requirements incomplete: {$validation}"
26
- }
27
-
28
- # Phase 2: Create specification
29
- """
30
- Create a technical specification from {$requirements}.
31
- Include API design, data models, and component structure.
32
- """ -> app::prompt() :> $spec
33
-
34
- "Specification created" -> log
35
-
36
- # Phase 3: Review loop - iterate until approved
37
- ($spec -> .contains("REVISION")) @ {
38
- """
39
- Review this specification for issues:
40
- {$}
41
-
42
- Output APPROVED if ready, or REVISION REQUIRED with feedback.
43
- """ -> app::prompt() :> $review
44
-
45
- $review -> ?(.contains("APPROVED")) { break }
46
-
47
- # Apply feedback and continue
48
- """
49
- Update the specification based on this feedback:
50
- {$review}
51
-
52
- Original spec:
53
- {$}
54
- """ -> app::prompt()} :> $approved_spec
55
-
56
- # Phase 4: Implementation
57
- """
58
- Implement the approved specification:
59
- {$approved_spec}
60
-
61
- Create the necessary files and tests.
62
- """ -> app::prompt() :> $implementation
63
-
64
- # Phase 5: Verify
65
- app::prompt("Run tests and verify implementation") :> $verification
66
-
67
- $verification -> ?(.contains("PASS")) {
68
- [0, "Workflow complete"]
69
- } ! {
70
- [1, "Verification failed: {$verification}"]
71
- }
72
- ```
73
-
74
- ## Document-Driven Task Loop
75
-
76
- Works through a checklist until complete.
77
-
78
- ```text
79
- ---
80
- args: plan: string
81
- ---
82
-
83
- # Initial check
84
- app::prompt("Read {$plan} and find the first unchecked item (- [ ])") :> $status
85
-
86
- # Work loop
87
- $status -> (!.contains("ALL COMPLETE")) @ {
88
- """
89
- Based on this status:
90
- {$}
91
-
92
- 1. Implement the identified unchecked item
93
- 2. Mark it complete in {$plan}
94
- 3. Check if any unchecked items remain
95
- 4. Output ALL COMPLETE if done, or describe next item
96
- """ -> app::prompt()
97
- } :> $final
98
-
99
- "Plan complete: {$final}" -> log
100
- ```
101
-
102
- ## Test-Fix Loop
103
-
104
- Runs tests, fixes failures, repeats until passing.
105
-
106
- ```rill
107
- ---
108
- args: target: string
109
- ---
110
-
111
- # Run tests
112
- app::prompt("Run tests for {$target} and report results") :> $result
113
-
114
- # Fix loop
115
- $result -> @(.contains("FAIL")) {
116
- "Fixing failures..." -> log
117
-
118
- """
119
- Fix these test failures:
120
- {$}
121
-
122
- Make minimal changes. Then run tests again and report results.
123
- """ -> app::prompt()} :> $final
124
-
125
- $final -> ?(.contains("PASS")) {
126
- "All tests passing"
127
- } ! {
128
- error "Could not fix all tests"
129
- }
130
- ```
131
-
132
- ## Code Review
133
-
134
- Reviews code against multiple criteria.
135
-
136
- ```rill
137
- ---
138
- args: file: string
139
- ---
140
-
141
- # Get file summary
142
- app::prompt("Read and summarize {$file}") :> $summary
143
-
144
- # Security check
145
- """
146
- Evaluate for SECURITY issues:
147
- {$summary}
148
-
149
- Output PASS, WARN, or FAIL with explanation.
150
- """ -> app::prompt() :> $security
151
-
152
- # Performance check
153
- """
154
- Evaluate for PERFORMANCE issues:
155
- {$summary}
156
-
157
- Output PASS, WARN, or FAIL with explanation.
158
- """ -> app::prompt() :> $performance
159
-
160
- # Check results
161
- $security -> .contains("FAIL") -> ? {
162
- error "Security review failed: {$security}"
163
- }
164
-
165
- $performance -> .contains("FAIL") -> ? {
166
- error "Performance review failed: {$performance}"
167
- }
168
-
169
- "Code review passed"
170
- ```
171
-
172
- ## Environment-Aware Deployment
173
-
174
- Deploys based on environment configuration.
175
-
176
- ```text
177
- ---
178
- args: service: string
179
- ---
180
-
181
- # Validate environment
182
- $ENV.DEPLOY_ENV -> ?(.empty()) {
183
- error "DEPLOY_ENV not set"
184
- }
185
-
186
- # Environment-specific deployment
187
- ($ENV.DEPLOY_ENV == "production") ? {
188
- """
189
- Deploy {$service} to production.
190
- - Run full test suite first
191
- - Enable monitoring
192
- - Use blue-green deployment
193
- """ -> app::prompt()} ! ($ENV.DEPLOY_ENV == "staging") ? {
194
- """
195
- Deploy {$service} to staging.
196
- - Run smoke tests
197
- - Enable debug logging
198
- """ -> app::prompt()} ! {
199
- app::prompt("Deploy {$service} to development environment")
200
- } :> $result
201
-
202
- "Deployment complete" -> log
203
- [0, "Deployed {$service} to {$ENV.DEPLOY_ENV}"]
204
- ```
205
-
206
- ## Retry Pattern
207
-
208
- Retries an operation until success or max attempts. Use do-while since you always want at least one attempt:
209
-
210
- ```rill
211
- ---
212
- args: operation: string
213
- ---
214
-
215
- # Do-while: body runs first, then condition checked
216
- ^(limit: 5) @ {
217
- """
218
- Perform: {$operation}
219
-
220
- Output SUCCESS, RETRY, or FAILED.
221
- """ -> app::prompt()
222
- } ? (.contains("RETRY")) :> $result
223
-
224
- # Loop exits when result doesn't contain RETRY
225
- $result -> .contains("SUCCESS") ? [0, "Succeeded"] ! [1, "Failed: {$result}"]
226
- ```
227
-
228
- The do-while form eliminates the separate first-attempt code since the body always executes at least once.
229
-
230
- ## Inline Capture Pattern
231
-
232
- Captures mid-chain for debugging or later reference while data continues flowing.
233
-
234
- ```rill
235
- ---
236
- args: file: string
237
- ---
238
-
239
- # Inline capture: value flows through $raw to log to conditional
240
- app::prompt("Read {$file}") :> $raw -> log -> .contains("ERROR") -> ? {
241
- error "Failed to read: {$raw}"
242
- }
243
-
244
- # Continue with $raw available for later use
245
- app::prompt("Analyze this content:\n{$raw}") :> $analysis -> log -> .empty -> ? {
246
- error "Analysis produced no output"
247
- }
248
-
249
- # Both $raw and $analysis available
250
- """
251
- Compare the original:
252
- {$raw}
253
-
254
- With the analysis:
255
- {$analysis}
256
- """ -> app::prompt()
257
- ```
258
-
259
- Semantically, `:> $var ->` is `:> $var.set($) ->` — the capture acts like `log`, storing the value while passing it through unchanged.
260
-
261
- ## Type-Safe Variables
262
-
263
- Uses type annotations to prevent accidental type changes during script execution.
264
-
265
- ```rill
266
- ---
267
- args: file: string
268
- ---
269
-
270
- # Define a typed helper closure
271
- |input: string| {
272
- app::prompt("Validate: {$input}") -> ?(.contains("VALID")) { true } ! { false }
273
- } :> $validate:closure
274
-
275
- # Capture with explicit type locks the variable
276
- "processing" :> $status:string
277
- "checking {$file}" :> $status # OK: same type
278
- # 42 :> $status # ERROR: cannot assign number to string
279
-
280
- # Closures are type-locked too
281
- # "oops" :> $validate # ERROR: cannot assign string to closure
282
-
283
- # Inline type annotation in pipe chain
284
- app::prompt("Check {$file}") :> $result:string -> log -> ?(.contains("ERROR")) {
285
- error $result
286
- }
287
-
288
- # Type annotations catch mistakes early
289
- app::prompt("Analyze {$file}") :> $analysis:string
290
-
291
- ?(.contains("FAIL")) {
292
- error "Analysis failed: {$analysis}"
293
- }
294
-
295
- [0, "Processing complete"]
296
- ```
297
-
298
- ## Pattern Extraction
299
-
300
- Extracts specific information from responses.
301
-
302
- ```rill
303
- ---
304
- args: logfile: string
305
- ---
306
-
307
- app::prompt("Read {$logfile} and find all ERROR lines") :> $errors
308
-
309
- $errors -> .empty -> ? {
310
- "No errors found"
311
- } ! {
312
- """
313
- Analyze these errors and categorize them:
314
- {$errors}
315
-
316
- For each unique error type, suggest a fix.
317
- """ -> app::prompt() :> $analysis
318
-
319
- "Error analysis complete" -> log
320
- $analysis
321
- }
322
- ```
323
-
324
- ## Multi-Phase Pipeline with Bailout
325
-
326
- Each phase can halt the pipeline on failure.
327
-
328
- ```rill
329
- ---
330
- args: file: string
331
- ---
332
-
333
- # Multi-phase pipeline with early exit on errors
334
- "content of {$file}" :> $content
335
-
336
- $content -> .contains("ERROR") ? {
337
- "Read failed" -> return
338
- }
339
-
340
- "analyzed: {$content}" :> $analysis
341
-
342
- $analysis -> .contains("FAIL") ? {
343
- "Analysis failed" -> return
344
- }
345
-
346
- "Pipeline complete: {$analysis}"
347
- ```
348
-
349
- ## Arithmetic in Loops
350
-
351
- Uses bar-delimited arithmetic for calculations within workflow logic.
352
-
353
- ```text
354
- ---
355
- args: items: string
356
- ---
357
-
358
- # Count items and calculate batch sizes
359
- app::prompt("Count items in {$items}") -> .match("(\\d+) items") :> $m
360
-
361
- $m -> .empty -> ? {
362
- error "Could not parse item count"
363
- }
364
-
365
- $m.groups[0] -> .num :> $count
366
-
367
- # Calculate batches: ceil(count / 10)
368
- (($count + 9) / 10) :> $batches
369
-
370
- "Processing {$count} items in {$batches} batches" -> log
371
-
372
- # Process each batch using range
373
- range(1, $batches + 1) -> each {
374
- $ :> $batch_num
375
- (($batch_num - 1) * 10) :> $start
376
- ($start + 10) :> $end
377
-
378
- """
379
- Process batch {$batch_num} of {$batches}
380
- Items {$start} through {$end}
381
- """ -> app::prompt()}
382
-
383
- [0, "Processed all batches"]
384
- ```
385
-
386
- ## Signal-Based Workflow
387
-
388
- Uses explicit signals for workflow control.
389
-
390
- ```text
391
- ---
392
- args: task: string
393
- exceptions:
394
- - ":::BLOCKED:::"
395
- - ":::NEEDS_HUMAN:::"
396
- ---
397
-
398
- """
399
- Work on this task: {$task}
400
-
401
- Rules:
402
- - Output :::BLOCKED::: if you need information you don't have
403
- - Output :::NEEDS_HUMAN::: if human judgment is required
404
- - Output :::DONE::: when complete
405
- """ -> app::prompt() :> $result
406
-
407
- $result -> (!.contains(":::DONE:::")) @ {
408
- """
409
- Continue working on: {$task}
410
-
411
- Previous progress:
412
- {$}
413
-
414
- Remember the signal rules.
415
- """ -> app::prompt()
416
- } :> $final
417
-
418
- "Task complete: {$final}" -> log
419
- ```
420
-
421
- ## Extraction Operators
422
-
423
- Demonstrates destructuring, slicing, and enumeration.
424
-
425
- ### Destructuring Function Results
426
-
427
- ```rill
428
- # Destructure list results into named variables
429
- ["test output", 0] -> *<$out, $code>
430
-
431
- $code -> .gt(0) ? {
432
- "Tests failed:\n{$out}" -> log
433
- }
434
-
435
- "All tests passed" -> log
436
- ```
437
-
438
- ### Processing Structured Data
439
-
440
- ```rill
441
- # Process list of [file, mode] pairs
442
- [
443
- ["src/auth.ts", "security"],
444
- ["src/api.ts", "performance"],
445
- ["src/db.ts", "security"]
446
- ] -> each {
447
- $ -> *<$f, $mode>
448
- "Review {$f} for {$mode} issues" -> log
449
- }
450
- ```
451
-
452
- ### Enumerated Progress
453
-
454
- ```rill
455
- # ...
456
- # enumerate($tasks) -> each {
457
- # "[{$.index + 1}/{$tasks.len}] Processing: {$.value}" -> log()
458
- # app::prompt("Complete task: {$.value}")
459
- # }
460
- ```
461
-
462
- ### Slicing Results
463
-
464
- ```rill
465
- # Get first 3 items
466
- ["a", "b", "c", "d", "e"] -> /<:3>
467
- # ["a", "b", "c"]
468
- ```
469
-
470
- ```rill
471
- # Process in reverse order
472
- ["a", "b", "c"] -> /<::-1>
473
- # ["c", "b", "a"]
474
- ```
475
-
476
- ### Dict Iteration
477
-
478
- ```rill
479
- # Use .entries to iterate over dict key-value pairs
480
- [host: "localhost", port: 8080] -> .entries -> each {
481
- "{$[0]}={$[1]}"
482
- } -> .join("\n")
483
- ```
484
-
485
- ## Args Type and Strict Invocation
486
-
487
- Explicit argument unpacking with validation.
488
-
489
- ### Positional Args
490
-
491
- ```rill
492
- # Define a function
493
- |a, b, c| { "{$a}-{$b}-{$c}" } :> $fmt
494
-
495
- # Create args from tuple and invoke
496
- *[1, 2, 3] -> $fmt() # "1-2-3"
497
-
498
- # Store args for later use
499
- *[1, 2, 3] :> $myArgs
500
- $myArgs -> $fmt() # "1-2-3"
501
- ```
502
-
503
- ### Named Args
504
-
505
- ```rill
506
- # Named args match by parameter name, order doesn't matter
507
- |width, height|($width * $height) :> $area
508
-
509
- *[height: 20, width: 10] -> $area() # 200
510
- ```
511
-
512
- ### Parameter Defaults
513
-
514
- ```rill
515
- # Defaults provide opt-in leniency
516
- |x, y = 10, z = 20|($x + $y + $z) :> $fn
517
-
518
- *[5] -> $fn() # 35 (5 + 10 + 20)
519
- *[x: 5, z: 30] -> $fn() # 45 (5 + 10 + 30)
520
- ```
521
-
522
- ### Type Checking with Global Functions
523
-
524
- ```rill
525
- # Use type() to inspect values
526
- 42 -> type # "number"
527
- "hello" -> type # "string"
528
- [1, 2] -> type # "list"
529
- *[1, 2] -> type # "tuple"
530
- [a: 1] -> type # "dict"
531
-
532
- # Use json() to serialize
533
- [name: "test", count: 42] -> json
534
- # '{"name":"test","count":42}'
535
-
536
- # Use log() to debug while continuing pipe
537
- "processing" -> log -> .len # logs "processing", returns 10
538
- ```
539
-
540
- ## Parsing LLM Output
541
-
542
- Built-in functions for extracting structured data from LLM responses.
543
-
544
- ### Auto-Detect with `parse_auto`
545
-
546
- ```rill
547
- # parse_auto detects and extracts structured content
548
- "{{\"status\": \"ok\", \"count\": 42}}" -> parse_auto :> $result
549
-
550
- $result.type -> log # "json"
551
- $result.data.status -> log # "ok"
552
- ```
553
-
554
- For XML content, use `parse_xml` for more precise extraction:
555
-
556
- ```rill
557
- "<response>200</response>" -> parse_xml("response")
558
- # "200"
559
- ```
560
-
561
- ### Extract JSON from Fenced Blocks
562
-
563
- ```rill
564
- # LLM returns: "Here's the config:\n```json\n{...}\n```"
565
- app::prompt("Generate JSON config") -> parse_fence("json") -> parse_json :> $config
566
-
567
- # Access parsed data
568
- $config.host -> log
569
- $config.port -> log
570
- ```
571
-
572
- ### Extract XML Tags (Claude-Style)
573
-
574
- ```rill
575
- # LLM returns: "<thinking>...</thinking><answer>...</answer>"
576
- app::prompt("Analyze step by step") :> $response
577
-
578
- # Extract thinking for logging
579
- $response -> parse_xml("thinking") -> log
580
-
581
- # Extract and parse answer
582
- $response -> parse_xml("answer") -> parse_json :> $answer
583
- ```
584
-
585
- ### Parse Tool Calls
586
-
587
- ```rill
588
- """
589
- What function should I call?
590
- Return in format: <tool><name>func</name><args>{...}</args></tool>
591
- """ -> app::prompt() :> $response
592
-
593
- $response -> parse_xml("tool") :> $tool
594
- $tool -> parse_xml("name") :> $fn_name
595
- $tool -> parse_xml("args") -> parse_json :> $fn_args
596
-
597
- # Call the function
598
- call($fn_name, $fn_args)
599
- ```
600
-
601
- ### Process Checklists
602
-
603
- ```rill
604
- # parse_checklist extracts checkbox items as [done, text] pairs
605
- "- [ ] Deploy to staging\n- [x] Run tests\n- [ ] Update docs" -> parse_checklist :> $tasks
606
-
607
- # Filter incomplete tasks
608
- $tasks -> filter |task| { !$task.at(0) } -> each |task| {
609
- "TODO: " -> log
610
- $task.at(1) -> log
611
- }
612
- ```
613
-
614
- ### Parse Frontmatter Documents
615
-
616
- ```rill
617
- # parse_frontmatter extracts YAML header and body
618
- "---\ntitle: Guide\nstatus: draft\n---\nContent here" -> parse_frontmatter :> $doc
619
-
620
- $doc.meta.title -> log # "Guide"
621
- $doc.body -> log # "Content here"
622
- ```
623
-
624
- ### Multi-Block Extraction
625
-
626
- ```rill
627
- # parse_fences extracts all fenced code blocks
628
- "```python\nprint(1)\n```\n```js\nconsole.log(1)\n```" -> parse_fences -> each {
629
- $.lang -> log
630
- $.content -> log
631
- }
632
- ```
633
-
634
- ### Structured Response Validation
635
-
636
- ```rill
637
- # Validate parsed content before use
638
- "{{\"status\": \"ok\", \"items\": [1, 2, 3]}}" -> parse_auto :> $result
639
-
640
- ($result.type != "json") ? {
641
- "Expected JSON" -> log
642
- }
643
-
644
- $result.data.status -> log # "ok"
645
- $result.data.items -> each { $ -> log }
646
- ```
647
-
648
- ## Collection Operations
649
-
650
- Pipeline operators for map, reduce, find, and aggregate patterns.
651
-
652
- ### Map with Parallel Spread
653
-
654
- ```rill
655
- # Define closure first, then use it
656
- |x| { $x * 2 } :> $double
657
- [1, 2, 3, 4, 5] -> map $double
658
- # [2, 4, 6, 8, 10]
659
-
660
- # Map with inline block
661
- ["alice", "bob", "carol"] -> map { "Hello, {$}!" }
662
- # ["Hello, alice!", "Hello, bob!", "Hello, carol!"]
663
- ```
664
-
665
- ### Filter with Parallel Filter
666
-
667
- ```rill
668
- # Keep elements matching condition (block form)
669
- [1, 2, 3, 4, 5] -> filter { .gt(2) }
670
- # [3, 4, 5]
671
-
672
- # Filter with closure predicate
673
- |x| { $x % 2 == 0 } :> $even
674
- [1, 2, 3, 4, 5, 6] -> filter $even
675
- # [2, 4, 6]
676
-
677
- # Filter non-empty strings
678
- ["hello", "", "world", ""] -> filter { !.empty }
679
- # ["hello", "world"]
680
-
681
- # Chain filter and map
682
- |x| { $x * 2 } :> $dbl
683
- [1, 2, 3, 4, 5] -> filter { .gt(2) } -> map $dbl
684
- # [6, 8, 10]
685
-
686
- # Filter structured data
687
- [
688
- [name: "alice", age: 30],
689
- [name: "bob", age: 17],
690
- [name: "carol", age: 25]
691
- ] -> filter { $.age -> .ge(18) }
692
- # [[name: "alice", age: 30], [name: "carol", age: 25]]
693
- ```
694
-
695
- ### Reduce with Sequential Spread
696
-
697
- ```rill
698
- # Chain transformations
699
- |s|"{$s} -> validated" :> $validate
700
- |s|"{$s} -> processed" :> $process
701
- |s|"{$s} -> complete" :> $complete
702
-
703
- "input" -> @[$validate, $process, $complete]
704
- # "input -> validated -> processed -> complete"
705
-
706
- # Numeric reduction
707
- |x|($x + 10) :> $add10
708
- |x|($x * 2) :> $double
709
-
710
- 5 -> @[$add10, $double, $add10]
711
- # ((5 + 10) * 2) + 10 = 40
712
- ```
713
-
714
- ### Find First Match
715
-
716
- ```rill
717
- # Find first element matching condition
718
- [1, 2, 3, 4, 5] -> each {
719
- .gt(3) ? { $ -> break }
720
- } :> $found
721
- # 4
722
-
723
- # Find with default
724
- [1, 2, 3] -> each {
725
- .gt(10) ? { $ -> break }
726
- } :> $result
727
- $result -> .empty ? { "not found" } ! { "found: {$result}" }
728
- ```
729
-
730
- ### Aggregate/Sum
731
-
732
- ```rill
733
- # Sum numbers using fold
734
- [10, 20, 30, 40] -> fold(0) { $@ + $ }
735
- # 100
736
-
737
- # Count matching elements using filter
738
- $items -> filter { .contains("error") } -> .len :> $count
739
- "Found {$count} errors" -> log
740
- ```
741
-
742
- ### Transform and Collect
743
-
744
- ```rill
745
- # Process items, collect results using map
746
- ["file1.txt", "file2.txt", "file3.txt"] -> map { "analyzed: {$}" } -> .join("\n")
747
- # "analyzed: file1.txt\nanalyzed: file2.txt\nanalyzed: file3.txt"
748
- ```