dirac-lang 0.1.23 → 0.1.25

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 (226) hide show
  1. package/dist/{chunk-APWJJXNI.js → chunk-7OUYWIZV.js} +55 -14
  2. package/dist/{chunk-RGS2XK6T.js → chunk-OUMUIBK3.js} +1 -1
  3. package/dist/cli.js +15 -3
  4. package/dist/index.js +2 -2
  5. package/dist/{interpreter-UZDVASAW.js → interpreter-MTIIHIIQ.js} +1 -1
  6. package/dist/test-runner.js +1 -1
  7. package/lib/index.di +9 -0
  8. package/package.json +13 -1
  9. package/.env.example +0 -8
  10. package/COMMUNITY.md +0 -465
  11. package/CONDITIONAL-TAGS.md +0 -172
  12. package/EXCEPTION-HANDLING.md +0 -156
  13. package/LIBRARIES.md +0 -172
  14. package/LLM-VALIDATION.md +0 -128
  15. package/NAMESPACES.md +0 -366
  16. package/PROMOTION.md +0 -257
  17. package/QUICKSTART-LIBRARY.md +0 -93
  18. package/TEST-COVERAGE.md +0 -113
  19. package/TESTING.md +0 -162
  20. package/config.test.yml +0 -5
  21. package/dirac-http/examples/demo.di +0 -9
  22. package/dirac-http/lib/index.di +0 -12
  23. package/examples/add-demo.di +0 -74
  24. package/examples/add.bk +0 -11
  25. package/examples/advanced-math-demo.di +0 -53
  26. package/examples/calculator.di +0 -32
  27. package/examples/compact-test.di +0 -6
  28. package/examples/comprehensive.bk +0 -29
  29. package/examples/defvar-variable-demo.di +0 -18
  30. package/examples/direct-call.di +0 -17
  31. package/examples/disk-analysis.di +0 -16
  32. package/examples/exception-demo.di +0 -82
  33. package/examples/executable-hello.di +0 -7
  34. package/examples/execute-demo.di +0 -38
  35. package/examples/file-manager.di +0 -77
  36. package/examples/file-stats.di +0 -18
  37. package/examples/hello.bk +0 -1
  38. package/examples/hello.di +0 -5
  39. package/examples/if-comparison.di +0 -91
  40. package/examples/if-cstyle-test.di +0 -149
  41. package/examples/if-vs-testif.di +0 -56
  42. package/examples/import-demo.di +0 -31
  43. package/examples/inline-test.bk +0 -7
  44. package/examples/llm-agent.di +0 -32
  45. package/examples/llm-basic.di +0 -12
  46. package/examples/llm-command-more.di +0 -6
  47. package/examples/llm-command-no-exec.di +0 -13
  48. package/examples/llm-command.di +0 -6
  49. package/examples/llm-complex.di +0 -141
  50. package/examples/llm-feedback-debug.di +0 -30
  51. package/examples/llm-feedback-demo.di +0 -19
  52. package/examples/llm-feedback-math.di +0 -22
  53. package/examples/llm-feedback-simple.di +0 -16
  54. package/examples/llm-feedback-sub.di +0 -22
  55. package/examples/llm-no-feedback.di +0 -10
  56. package/examples/llm-recursive.di +0 -31
  57. package/examples/llm-reflection-test.di +0 -19
  58. package/examples/llm-simple-test.di +0 -12
  59. package/examples/llm-subs.di +0 -132
  60. package/examples/llm-use-subs.di +0 -6
  61. package/examples/llm-validate-test.di +0 -18
  62. package/examples/loop.di +0 -12
  63. package/examples/math-test.di +0 -22
  64. package/examples/minimal-test.di +0 -13
  65. package/examples/mongodb-context-test.di +0 -27
  66. package/examples/mongodb-count-events.di +0 -8
  67. package/examples/mongodb-import-demo.di +0 -25
  68. package/examples/mongodb-simple-test.di +0 -18
  69. package/examples/nl-agent.di +0 -47
  70. package/examples/parameters-demo.di +0 -68
  71. package/examples/params-meta-test.di +0 -17
  72. package/examples/params-test.di +0 -10
  73. package/examples/recipe-chain.di +0 -38
  74. package/examples/recursive-llm.di +0 -44
  75. package/examples/sample-library/README.md +0 -152
  76. package/examples/sample-library/examples/demo.di +0 -34
  77. package/examples/sample-library/lib/index.di +0 -65
  78. package/examples/sample-library/package.json +0 -31
  79. package/examples/scope-test-nested.di +0 -60
  80. package/examples/scope-test.di +0 -55
  81. package/examples/seamless.di +0 -45
  82. package/examples/shell-test.bk +0 -10
  83. package/examples/simple-import.di +0 -13
  84. package/examples/simple-recursive.di +0 -26
  85. package/examples/story-builder.di +0 -45
  86. package/examples/subroutine.di +0 -23
  87. package/examples/system-llm.di +0 -21
  88. package/examples/system-simple.di +0 -3
  89. package/examples/system-test.di +0 -8
  90. package/examples/tag-check-test.di +0 -139
  91. package/examples/task-assistant.di +0 -27
  92. package/examples/test-if-demo.di +0 -110
  93. package/examples/test-parameters.di +0 -50
  94. package/examples/try-catch-test.di +0 -118
  95. package/examples/two-styles.di +0 -28
  96. package/examples/var-debug.di +0 -6
  97. package/examples/var-inline.di +0 -4
  98. package/examples/var-test2.di +0 -6
  99. package/examples/variable-replace.di +0 -25
  100. package/examples/variable-simple.di +0 -16
  101. package/examples/variable-test.di +0 -22
  102. package/examples/whitespace-test.di +0 -24
  103. package/filePath +0 -1
  104. package/greeting.txt +0 -1
  105. package/src/cli.ts +0 -140
  106. package/src/index.ts +0 -33
  107. package/src/llm/ollama.ts +0 -58
  108. package/src/runtime/braket-parser.ts +0 -234
  109. package/src/runtime/interpreter.ts +0 -203
  110. package/src/runtime/parser.ts +0 -155
  111. package/src/runtime/session.ts +0 -325
  112. package/src/tags/assign.ts +0 -37
  113. package/src/tags/attr.ts +0 -64
  114. package/src/tags/available-subroutines.ts +0 -70
  115. package/src/tags/call.ts +0 -259
  116. package/src/tags/catch.ts +0 -24
  117. package/src/tags/defvar.ts +0 -115
  118. package/src/tags/environment.ts +0 -21
  119. package/src/tags/eval.ts +0 -71
  120. package/src/tags/exception.ts +0 -20
  121. package/src/tags/execute.ts +0 -52
  122. package/src/tags/expr.ts +0 -128
  123. package/src/tags/foreach.ts +0 -170
  124. package/src/tags/if.ts +0 -191
  125. package/src/tags/import.ts +0 -66
  126. package/src/tags/index.ts +0 -41
  127. package/src/tags/input.ts +0 -182
  128. package/src/tags/llm.ts +0 -415
  129. package/src/tags/loop.ts +0 -43
  130. package/src/tags/mongodb.ts +0 -70
  131. package/src/tags/output.ts +0 -53
  132. package/src/tags/parameters.ts +0 -81
  133. package/src/tags/require_module.ts +0 -19
  134. package/src/tags/subroutine.ts +0 -75
  135. package/src/tags/system.ts +0 -93
  136. package/src/tags/tag-check.ts +0 -176
  137. package/src/tags/test-if.ts +0 -112
  138. package/src/tags/throw.ts +0 -26
  139. package/src/tags/try.ts +0 -19
  140. package/src/tags/variable.ts +0 -25
  141. package/src/test-runner.ts +0 -300
  142. package/src/types/index.ts +0 -128
  143. package/src/utils/llm-adapter.ts +0 -113
  144. package/src/utils/tag-validator.ts +0 -231
  145. package/test-available-extends.di +0 -28
  146. package/test-available-simple.di +0 -12
  147. package/test-available-subroutines.di +0 -16
  148. package/test-call.di +0 -9
  149. package/test-extend-basic.di +0 -17
  150. package/test-extend-chain.di +0 -26
  151. package/test-extend-debug.di +0 -17
  152. package/test-extend-debug2.di +0 -15
  153. package/test-extend-person.di +0 -17
  154. package/test-extend-simple.di +0 -11
  155. package/test-extend-zhi.di +0 -23
  156. package/test-extend.di +0 -19
  157. package/test-extend2.di +0 -26
  158. package/test-extend3-fixed.di +0 -23
  159. package/test-extend3-trouble.di +0 -23
  160. package/test-extend3.di +0 -21
  161. package/test-factorial.di +0 -19
  162. package/test-input-debug.di +0 -19
  163. package/test-nested-debug.di +0 -7
  164. package/test-nested-debug2.di +0 -8
  165. package/test-no-extend.di +0 -16
  166. package/test-simple-call.di +0 -7
  167. package/test-simple.di +0 -6
  168. package/tests/README.md +0 -69
  169. package/tests/assign-basic.test.di +0 -7
  170. package/tests/assign-from-eval.test.di +0 -7
  171. package/tests/available-subroutines-foreach.test.di +0 -32
  172. package/tests/basic-output.test.di +0 -5
  173. package/tests/call-basic.test.di +0 -11
  174. package/tests/call-with-output.test.di +0 -10
  175. package/tests/comments-before-content.test.di +0 -6
  176. package/tests/defvar-multiple.test.di +0 -8
  177. package/tests/environment-basic.test.di +0 -22
  178. package/tests/environment-nonexistent.test.di +0 -5
  179. package/tests/environment-with-defvar.test.di +0 -15
  180. package/tests/eval-basic.test.di +0 -6
  181. package/tests/eval-with-variables.test.di +0 -8
  182. package/tests/exception-basic.test.di +0 -10
  183. package/tests/expr-basic.test.di +0 -11
  184. package/tests/extend-basic.test.di +0 -19
  185. package/tests/extend-inheritance-chain.test.di +0 -26
  186. package/tests/extend-multiple-nested.test.di +0 -24
  187. package/tests/extend-self.test.di +0 -19
  188. package/tests/extend-with-parameters.test.di +0 -14
  189. package/tests/generate-dirac.test.di +0 -22
  190. package/tests/if-conditional.test.di +0 -17
  191. package/tests/if-else.test.di +0 -11
  192. package/tests/if-with-variables.test.di +0 -8
  193. package/tests/import-basic.test.di +0 -6
  194. package/tests/input-file-all.test.di +0 -5
  195. package/tests/input-file-line.test.di +0 -15
  196. package/tests/input-file-loop.test.di +0 -12
  197. package/tests/input-stdin-all.test.di +0 -8
  198. package/tests/input-stdin-all.txt +0 -1
  199. package/tests/llm-validate.test.di +0 -17
  200. package/tests/loop-basic.test.di +0 -9
  201. package/tests/loop-nested.test.di +0 -10
  202. package/tests/loop-with-eval.test.di +0 -8
  203. package/tests/no-root-element.test.di +0 -6
  204. package/tests/output-file.test.di +0 -19
  205. package/tests/output-multiple.test.di +0 -9
  206. package/tests/parameters-basic.test.di +0 -6
  207. package/tests/require-module-basic.test.di +0 -7
  208. package/tests/subroutine-basic.test.di +0 -9
  209. package/tests/subroutine-multiple-params.test.di +0 -10
  210. package/tests/subroutine-nested-calls.test.di +0 -32
  211. package/tests/subroutine-sequential-calls.test.di +0 -36
  212. package/tests/system-background.test.di +0 -39
  213. package/tests/system-basic.test.di +0 -5
  214. package/tests/tag-check.test.di +0 -27
  215. package/tests/test-if-basic.test.di +0 -8
  216. package/tests/test-input.txt +0 -3
  217. package/tests/try-catch-basic.test.di +0 -10
  218. package/tests/try-catch-eval-error.test.di +0 -10
  219. package/tests/variable-basic.test.di +0 -6
  220. package/tests/variable-interpolation.test.di +0 -7
  221. package/tools/create-library.sh +0 -175
  222. package/tsconfig.json +0 -19
  223. /package/{examples/lib → lib}/advanced-math.di +0 -0
  224. /package/{examples/lib → lib}/fileops.di +0 -0
  225. /package/{examples/lib → lib}/math.di +0 -0
  226. /package/{examples/lib → lib}/mongodb.di +0 -0
@@ -1,156 +0,0 @@
1
- # Exception Handling in Dirac
2
-
3
- Dirac implements exception handling using `<try>`, `<catch>`, `<throw>`, and `<exception>` tags, based on the MASK C implementation.
4
-
5
- ## Tags
6
-
7
- ### `<throw>`
8
- Throws an exception that can be caught by a matching `<catch>` block.
9
-
10
- **Attributes:**
11
- - `name` (optional): The exception name. Defaults to "exception" if not specified.
12
-
13
- **Example:**
14
- ```xml
15
- <throw name="myerror">
16
- <output>Error message here</output>
17
- </throw>
18
- ```
19
-
20
- ### `<try>`
21
- Establishes an exception boundary. Exceptions thrown within a `<try>` block can be caught by subsequent `<catch>` blocks.
22
-
23
- **Example:**
24
- ```xml
25
- <try>
26
- <output>Code that might throw</output>
27
- <throw name="error1">
28
- <output>Something went wrong</output>
29
- </throw>
30
- </try>
31
- ```
32
-
33
- ### `<catch>`
34
- Catches exceptions with a matching name that were thrown in the preceding `<try>` block.
35
-
36
- **Attributes:**
37
- - `name` (optional): The exception name to catch. Defaults to "exception" if not specified.
38
-
39
- **Example:**
40
- ```xml
41
- <catch name="error1">
42
- <output>Handling the error: </output>
43
- <exception/>
44
- </catch>
45
- ```
46
-
47
- ### `<exception>`
48
- Outputs the content of caught exceptions. Must be used inside a `<catch>` block.
49
-
50
- **Example:**
51
- ```xml
52
- <catch name="myerror">
53
- <output>Error details: </output>
54
- <exception/>
55
- </catch>
56
- ```
57
-
58
- ## How It Works
59
-
60
- 1. **Exception Stack**: All thrown exceptions are added to a global exception stack
61
- 2. **Boundaries**: `<try>` blocks create boundaries in the exception stack
62
- 3. **Name Matching**: `<catch>` blocks look for exceptions with matching names between the current position and the last boundary
63
- 4. **Multiple Catches**: Multiple exceptions with the same name can be caught together
64
-
65
- ## Examples
66
-
67
- ### Basic Usage
68
- ```xml
69
- <try>
70
- <throw name="error">
71
- <output>An error occurred</output>
72
- </throw>
73
- </try>
74
-
75
- <catch name="error">
76
- <output>Caught: </output>
77
- <exception/>
78
- </catch>
79
- ```
80
-
81
- ### Multiple Exception Types
82
- ```xml
83
- <try>
84
- <throw name="warning">
85
- <output>Warning: low memory</output>
86
- </throw>
87
- <throw name="error">
88
- <output>Error: file not found</output>
89
- </throw>
90
- </try>
91
-
92
- <catch name="warning">
93
- <output>Warnings: </output>
94
- <exception/>
95
- </catch>
96
-
97
- <catch name="error">
98
- <output>Errors: </output>
99
- <exception/>
100
- </catch>
101
- ```
102
-
103
- ### With Variables
104
- ```xml
105
- <defvar name="errorCode" value="404"/>
106
-
107
- <try>
108
- <throw name="httperror">
109
- <output>HTTP Error </output>
110
- <variable name="errorCode"/>
111
- </throw>
112
- </try>
113
-
114
- <catch name="httperror">
115
- <exception/>
116
- </catch>
117
- ```
118
-
119
- ### Nested Try/Catch
120
- ```xml
121
- <try>
122
- <output>Outer try</output>
123
- <try>
124
- <throw name="inner">
125
- <output>Inner exception</output>
126
- </throw>
127
- </try>
128
- <catch name="inner">
129
- <output>Caught in inner: </output>
130
- <exception/>
131
- </catch>
132
- </try>
133
- ```
134
-
135
- ### Default Exception Name
136
- Both throw and catch default to "exception" if no name is specified:
137
-
138
- ```xml
139
- <try>
140
- <throw>
141
- <output>Default exception</output>
142
- </throw>
143
- </try>
144
-
145
- <catch>
146
- <exception/>
147
- </catch>
148
- ```
149
-
150
- ## Implementation Notes
151
-
152
- - Based on the MASK C implementation (`exception.c`, `mask_integrate.c`)
153
- - Exceptions use a boundary-based scoping system
154
- - Multiple exceptions with the same name can be caught together
155
- - Exception content is stored as DOM elements
156
- - The `<exception>` tag outputs all caught exceptions with the matching name
package/LIBRARIES.md DELETED
@@ -1,172 +0,0 @@
1
- # Dirac Library Ecosystem
2
-
3
- ## Philosophy
4
-
5
- Dirac follows the UNIX philosophy: **composition over complexity**. Complex operations should be implemented as reusable libraries that users can import and use with clean, declarative syntax.
6
-
7
- ## Library Architecture
8
-
9
- ### Pattern: JavaScript → Dirac Tags
10
-
11
- 1. **Implement complexity in `<eval>`** - Use JavaScript's full power for complex algorithms
12
- 2. **Wrap in `<subroutine>`** - Expose as a clean Dirac tag
13
- 3. **Distribute as `.di` files** - Share via `<import>`
14
- 4. **Use like built-in tags** - `<SQRT n="16"/>` not `eval(...)`
15
-
16
- ### Example: Square Root
17
-
18
- **Implementation** (in library):
19
- ```xml
20
- <subroutine name="SQRT">
21
- <eval>
22
- const caller = getParams();
23
- const n = parseFloat(caller.attributes.n || 0);
24
- let x = n, prev;
25
- do {
26
- prev = x;
27
- x = (x + n / x) / 2;
28
- } while (Math.abs(x - prev) &lt; 1e-10);
29
- console.log(x);
30
- </eval>
31
- </subroutine>
32
- ```
33
-
34
- **Usage** (by end user):
35
- ```xml
36
- <import src="./lib/advanced-math.di"/>
37
- <SQRT n="16"/> <!-- Clean, declarative -->
38
- ```
39
-
40
- ## Current Libraries
41
-
42
- ### `lib/math.di` - Basic Math
43
- - `SQUARE` - Square a number
44
- - `ADD` - Add two numbers
45
- - `FACTORIAL` - Calculate factorial
46
-
47
- ### `lib/fileops.di` - File Operations
48
- - `LIST_FILES` - List directory contents
49
- - `COUNT_FILES` - Count files in directory
50
-
51
- ### `lib/advanced-math.di` - Advanced Math
52
- - `SQRT` - Square root (Newton's method)
53
- - `FACTORIAL` - Factorial (recursive)
54
- - `GCD` - Greatest common divisor
55
- - `PRIME` - Primality test
56
- - `STATS` - Statistical analysis
57
- - `RANDOM` - Random number generation
58
-
59
- ## Publishing Libraries
60
-
61
- ### Option 1: GitHub
62
- ```bash
63
- # Create a dirac-libs repository
64
- mkdir dirac-libs
65
- cd dirac-libs
66
- git init
67
- # Add your .di library files
68
- git add lib/
69
- git commit -m "Add math libraries"
70
- git push
71
- ```
72
-
73
- Users import via URL or local clone.
74
-
75
- ### Option 2: npm Package
76
- ```json
77
- {
78
- "name": "dirac-stdlib",
79
- "version": "1.0.0",
80
- "description": "Standard library for Dirac",
81
- "main": "index.js",
82
- "files": ["lib/**/*.di"],
83
- "keywords": ["dirac", "mask", "xml", "dsl"]
84
- }
85
- ```
86
-
87
- Users:
88
- ```bash
89
- npm install dirac-stdlib
90
- ```
91
-
92
- ```xml
93
- <import src="./node_modules/dirac-stdlib/lib/math.di"/>
94
- ```
95
-
96
- ### Option 3: Central Registry
97
- Future: Create a Dirac package registry like PyPI/npm specifically for `.di` libraries.
98
-
99
- ## Best Practices
100
-
101
- ### 1. Use XML Entities for Operators
102
- ```xml
103
- <eval>
104
- if (x &lt; 5) ... <!-- Use &lt; not < -->
105
- if (x &gt; 10) ... <!-- Use &gt; not > -->
106
- if (x &lt;= 5) ... <!-- Use &lt;= -->
107
- </eval>
108
- ```
109
-
110
- ### 2. Use getParams() for Attributes
111
- ```xml
112
- <subroutine name="FOO">
113
- <eval>
114
- const caller = getParams();
115
- const x = caller.attributes.x;
116
- const children = caller.children;
117
- </eval>
118
- </subroutine>
119
- ```
120
-
121
- ### 3. Handle Edge Cases
122
- ```javascript
123
- const n = parseFloat(caller.attributes.n || 0);
124
- if (n < 0) { console.log('NaN'); return; }
125
- ```
126
-
127
- ### 4. Document Your Library
128
- ```xml
129
- <!--
130
- SQRT - Square Root Calculator
131
-
132
- Usage: <SQRT n="16"/>
133
- Returns: Square root using Newton's method
134
- Attributes:
135
- - n: Number to find square root of (required)
136
- -->
137
- <subroutine name="SQRT">
138
- ...
139
- </subroutine>
140
- ```
141
-
142
- ## Future Libraries
143
-
144
- Ideas for community-contributed libraries:
145
-
146
- - **dirac-crypto** - Hashing, encryption (`<SHA256>`, `<AES>`)
147
- - **dirac-http** - HTTP client (`<GET>`, `<POST>`)
148
- - **dirac-db** - Database operations (`<SQL>`, `<QUERY>`)
149
- - **dirac-ml** - Machine learning (`<PREDICT>`, `<TRAIN>`)
150
- - **dirac-dsp** - Signal processing (`<FFT>`, `<FILTER>`)
151
- - **dirac-viz** - Data visualization (`<CHART>`, `<PLOT>`)
152
- - **dirac-nlp** - Natural language (`<TOKENIZE>`, `<SENTIMENT>`)
153
-
154
- ## Contributing
155
-
156
- To contribute a library:
157
-
158
- 1. Create `.di` file with subroutines
159
- 2. Test thoroughly
160
- 3. Document all tags
161
- 4. Submit PR or publish to npm
162
- 5. Add to Dirac wiki/registry
163
-
164
- ## Philosophy: Why This Works
165
-
166
- This approach follows McCarthy's insight about homoiconicity:
167
- - **Code as data**: Subroutines are XML, same as the code using them
168
- - **Composition**: Complex tags built from simple ones
169
- - **Distribution**: Libraries are just more Dirac files
170
- - **No special cases**: `<SQRT>` works exactly like `<output>`
171
-
172
- The entire ecosystem grows organically through composition, not by modifying the interpreter.
package/LLM-VALIDATION.md DELETED
@@ -1,128 +0,0 @@
1
- # LLM Tag Validation
2
-
3
- The `<llm>` tag now supports automatic validation and correction of generated Dirac code when using `execute="true"`.
4
-
5
- ## Attributes
6
-
7
- ### Execution Mode
8
- - `execute="true"` - Parse and execute the LLM response as Dirac code (existing feature)
9
-
10
- ### Tag Validation (New)
11
- - `validate="true"` - Enable tag validation for LLM-generated code
12
- - `autocorrect="true"` - Automatically correct similar tag names using semantic matching
13
- - `max-retries="N"` - Maximum number of retry attempts if validation fails (default: 0)
14
-
15
- ## How It Works
16
-
17
- When `validate="true"` is enabled:
18
-
19
- 1. **Parse**: LLM response is parsed as Dirac XML
20
- 2. **Validate**: Each tag is checked against available subroutines
21
- - Verifies tag names exist
22
- - Checks required parameters are present
23
- - Warns about unknown attributes
24
- 3. **Semantic Matching**: If a tag doesn't exist, finds the closest match using embeddings
25
- 4. **Auto-correct**: If `autocorrect="true"` and similarity >= 0.75, replaces tag with best match
26
- 5. **Retry**: If validation fails and `max-retries > 0`, sends error feedback to LLM and retries
27
- 6. **Execute**: Once validation passes, executes the (possibly corrected) code
28
-
29
- ## Examples
30
-
31
- ### Basic Validation
32
-
33
- ```xml
34
- <dirac>
35
- <subroutine name="greet" param-name="string:required">
36
- <output>Hello, <variable name="name" />!</output>
37
- </subroutine>
38
-
39
- <llm execute="true" validate="true">
40
- Greet Alice
41
- </llm>
42
- </dirac>
43
- ```
44
-
45
- If the LLM generates `<greeting name="Alice" />` instead of `<greet name="Alice" />`, validation will fail with an error.
46
-
47
- ### With Auto-correction
48
-
49
- ```xml
50
- <dirac>
51
- <subroutine name="greet" param-name="string:required">
52
- <output>Hello, <variable name="name" />!</output>
53
- </subroutine>
54
-
55
- <llm execute="true" validate="true" autocorrect="true">
56
- Greet Alice
57
- </llm>
58
- </dirac>
59
- ```
60
-
61
- If the LLM generates `<greeting name="Alice" />`, and `greeting` is semantically similar to `greet` (similarity >= 0.75), it will be auto-corrected to `<greet name="Alice" />`.
62
-
63
- ### With Retry
64
-
65
- ```xml
66
- <dirac>
67
- <subroutine name="calculate" param-expression="string:required">
68
- <eval><variable name="expression" /></eval>
69
- </subroutine>
70
-
71
- <llm execute="true" validate="true" max-retries="3">
72
- Calculate 2 + 2
73
- </llm>
74
- </dirac>
75
- ```
76
-
77
- If validation fails:
78
- 1. LLM receives feedback: "Your previous response had the following errors: <compute>: Missing required parameter: expression"
79
- 2. LLM generates a new response
80
- 3. Process repeats up to 3 times until validation passes
81
-
82
- ### Combined Approach
83
-
84
- ```xml
85
- <llm execute="true" validate="true" autocorrect="true" max-retries="2">
86
- Generate a greeting for Bob
87
- </llm>
88
- ```
89
-
90
- This combines auto-correction with retry:
91
- - First tries to auto-correct similar tag names
92
- - If that doesn't fix all errors, retries with LLM feedback
93
- - Maximum 2 retry attempts
94
-
95
- ## Error Messages
96
-
97
- Validation can detect:
98
-
99
- - **Missing tags**: `Tag <xyz> does not exist and no similar tag was found.`
100
- - **Similar tags**: `Tag <greeting> does not exist. Did you mean <greet>? (similarity: 0.85)`
101
- - **Missing parameters**: `<greet>: Missing required parameter: name`
102
- - **Unknown attributes**: `<greet>: Unknown attribute: person`
103
-
104
- ## Requirements
105
-
106
- - Requires embedding server for semantic matching (Ollama with embeddinggemma model)
107
- - Configure in `config.yml`:
108
- ```yaml
109
- embeddingServer:
110
- host: localhost
111
- port: 11435
112
- ```
113
-
114
- ## Performance Notes
115
-
116
- - Validation adds latency due to embedding calls
117
- - Each tag requires an embedding API call
118
- - Consider using `validate="true"` only when necessary
119
- - Auto-correction is faster than retries
120
-
121
- ## Best Practices
122
-
123
- 1. **Start without validation** for simple prompts
124
- 2. **Add validation** when LLM frequently generates incorrect tags
125
- 3. **Use autocorrect** for typos and similar names
126
- 4. **Use retry** for more complex validation errors
127
- 5. **Limit retries** to 2-3 to avoid excessive API calls
128
- 6. **Monitor debug output** with `DIRAC_DEBUG=1` to see validation details