dirac-lang 0.1.24 → 0.1.26

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 (221) hide show
  1. package/dist/cli.js +13 -1
  2. package/lib/index.di +9 -0
  3. package/{examples/lib → lib}/math.di +3 -3
  4. package/package.json +13 -1
  5. package/.env.example +0 -8
  6. package/COMMUNITY.md +0 -465
  7. package/CONDITIONAL-TAGS.md +0 -172
  8. package/EXCEPTION-HANDLING.md +0 -156
  9. package/LIBRARIES.md +0 -172
  10. package/LLM-VALIDATION.md +0 -128
  11. package/NAMESPACES.md +0 -366
  12. package/PROMOTION.md +0 -257
  13. package/QUICKSTART-LIBRARY.md +0 -93
  14. package/TEST-COVERAGE.md +0 -113
  15. package/TESTING.md +0 -162
  16. package/config.test.yml +0 -5
  17. package/dirac-http/examples/demo.di +0 -9
  18. package/dirac-http/lib/index.di +0 -12
  19. package/examples/add-demo.di +0 -74
  20. package/examples/add.bk +0 -11
  21. package/examples/advanced-math-demo.di +0 -53
  22. package/examples/calculator.di +0 -32
  23. package/examples/compact-test.di +0 -6
  24. package/examples/comprehensive.bk +0 -29
  25. package/examples/defvar-variable-demo.di +0 -18
  26. package/examples/direct-call.di +0 -17
  27. package/examples/disk-analysis.di +0 -16
  28. package/examples/exception-demo.di +0 -82
  29. package/examples/executable-hello.di +0 -7
  30. package/examples/execute-demo.di +0 -38
  31. package/examples/file-manager.di +0 -77
  32. package/examples/file-stats.di +0 -18
  33. package/examples/hello.bk +0 -1
  34. package/examples/hello.di +0 -5
  35. package/examples/if-comparison.di +0 -91
  36. package/examples/if-cstyle-test.di +0 -149
  37. package/examples/if-vs-testif.di +0 -56
  38. package/examples/import-demo.di +0 -31
  39. package/examples/inline-test.bk +0 -7
  40. package/examples/llm-agent.di +0 -32
  41. package/examples/llm-basic.di +0 -12
  42. package/examples/llm-command-more.di +0 -6
  43. package/examples/llm-command-no-exec.di +0 -13
  44. package/examples/llm-command.di +0 -6
  45. package/examples/llm-complex.di +0 -141
  46. package/examples/llm-feedback-debug.di +0 -30
  47. package/examples/llm-feedback-demo.di +0 -19
  48. package/examples/llm-feedback-math.di +0 -22
  49. package/examples/llm-feedback-simple.di +0 -16
  50. package/examples/llm-feedback-sub.di +0 -22
  51. package/examples/llm-no-feedback.di +0 -10
  52. package/examples/llm-recursive.di +0 -31
  53. package/examples/llm-reflection-test.di +0 -19
  54. package/examples/llm-simple-test.di +0 -12
  55. package/examples/llm-subs.di +0 -132
  56. package/examples/llm-use-subs.di +0 -6
  57. package/examples/llm-validate-test.di +0 -18
  58. package/examples/loop.di +0 -12
  59. package/examples/math-test.di +0 -22
  60. package/examples/minimal-test.di +0 -13
  61. package/examples/mongodb-context-test.di +0 -27
  62. package/examples/mongodb-count-events.di +0 -8
  63. package/examples/mongodb-import-demo.di +0 -25
  64. package/examples/mongodb-simple-test.di +0 -18
  65. package/examples/nl-agent.di +0 -47
  66. package/examples/parameters-demo.di +0 -68
  67. package/examples/params-meta-test.di +0 -17
  68. package/examples/params-test.di +0 -10
  69. package/examples/recipe-chain.di +0 -38
  70. package/examples/recursive-llm.di +0 -44
  71. package/examples/sample-library/README.md +0 -152
  72. package/examples/sample-library/examples/demo.di +0 -34
  73. package/examples/sample-library/lib/index.di +0 -65
  74. package/examples/sample-library/package.json +0 -31
  75. package/examples/scope-test-nested.di +0 -60
  76. package/examples/scope-test.di +0 -55
  77. package/examples/seamless.di +0 -45
  78. package/examples/shell-test.bk +0 -10
  79. package/examples/simple-import.di +0 -13
  80. package/examples/simple-recursive.di +0 -26
  81. package/examples/story-builder.di +0 -45
  82. package/examples/subroutine.di +0 -23
  83. package/examples/system-llm.di +0 -21
  84. package/examples/system-simple.di +0 -3
  85. package/examples/system-test.di +0 -8
  86. package/examples/tag-check-test.di +0 -139
  87. package/examples/task-assistant.di +0 -27
  88. package/examples/test-if-demo.di +0 -110
  89. package/examples/test-parameters.di +0 -50
  90. package/examples/try-catch-test.di +0 -118
  91. package/examples/two-styles.di +0 -28
  92. package/examples/var-debug.di +0 -6
  93. package/examples/var-inline.di +0 -4
  94. package/examples/var-test2.di +0 -6
  95. package/examples/variable-replace.di +0 -25
  96. package/examples/variable-simple.di +0 -16
  97. package/examples/variable-test.di +0 -22
  98. package/examples/whitespace-test.di +0 -24
  99. package/filePath +0 -1
  100. package/greeting.txt +0 -1
  101. package/src/cli.ts +0 -140
  102. package/src/index.ts +0 -33
  103. package/src/llm/ollama.ts +0 -58
  104. package/src/runtime/braket-parser.ts +0 -234
  105. package/src/runtime/interpreter.ts +0 -203
  106. package/src/runtime/parser.ts +0 -155
  107. package/src/runtime/session.ts +0 -325
  108. package/src/tags/assign.ts +0 -37
  109. package/src/tags/attr.ts +0 -64
  110. package/src/tags/available-subroutines.ts +0 -70
  111. package/src/tags/call.ts +0 -259
  112. package/src/tags/catch.ts +0 -24
  113. package/src/tags/defvar.ts +0 -115
  114. package/src/tags/environment.ts +0 -21
  115. package/src/tags/eval.ts +0 -71
  116. package/src/tags/exception.ts +0 -20
  117. package/src/tags/execute.ts +0 -52
  118. package/src/tags/expr.ts +0 -128
  119. package/src/tags/foreach.ts +0 -170
  120. package/src/tags/if.ts +0 -191
  121. package/src/tags/import.ts +0 -135
  122. package/src/tags/index.ts +0 -41
  123. package/src/tags/input.ts +0 -182
  124. package/src/tags/llm.ts +0 -415
  125. package/src/tags/loop.ts +0 -43
  126. package/src/tags/mongodb.ts +0 -70
  127. package/src/tags/output.ts +0 -53
  128. package/src/tags/parameters.ts +0 -81
  129. package/src/tags/require_module.ts +0 -19
  130. package/src/tags/subroutine.ts +0 -75
  131. package/src/tags/system.ts +0 -93
  132. package/src/tags/tag-check.ts +0 -176
  133. package/src/tags/test-if.ts +0 -112
  134. package/src/tags/throw.ts +0 -26
  135. package/src/tags/try.ts +0 -19
  136. package/src/tags/variable.ts +0 -25
  137. package/src/test-runner.ts +0 -300
  138. package/src/types/index.ts +0 -128
  139. package/src/utils/llm-adapter.ts +0 -113
  140. package/src/utils/tag-validator.ts +0 -231
  141. package/test-available-extends.di +0 -28
  142. package/test-available-simple.di +0 -12
  143. package/test-available-subroutines.di +0 -16
  144. package/test-call.di +0 -9
  145. package/test-extend-basic.di +0 -17
  146. package/test-extend-chain.di +0 -26
  147. package/test-extend-debug.di +0 -17
  148. package/test-extend-debug2.di +0 -15
  149. package/test-extend-person.di +0 -17
  150. package/test-extend-simple.di +0 -11
  151. package/test-extend-zhi.di +0 -23
  152. package/test-extend.di +0 -19
  153. package/test-extend2.di +0 -26
  154. package/test-extend3-fixed.di +0 -23
  155. package/test-extend3-trouble.di +0 -23
  156. package/test-extend3.di +0 -21
  157. package/test-factorial.di +0 -19
  158. package/test-input-debug.di +0 -19
  159. package/test-nested-debug.di +0 -7
  160. package/test-nested-debug2.di +0 -8
  161. package/test-no-extend.di +0 -16
  162. package/test-simple-call.di +0 -7
  163. package/test-simple.di +0 -6
  164. package/tests/README.md +0 -69
  165. package/tests/assign-basic.test.di +0 -7
  166. package/tests/assign-from-eval.test.di +0 -7
  167. package/tests/available-subroutines-foreach.test.di +0 -32
  168. package/tests/basic-output.test.di +0 -5
  169. package/tests/call-basic.test.di +0 -11
  170. package/tests/call-with-output.test.di +0 -10
  171. package/tests/comments-before-content.test.di +0 -6
  172. package/tests/defvar-multiple.test.di +0 -8
  173. package/tests/environment-basic.test.di +0 -22
  174. package/tests/environment-nonexistent.test.di +0 -5
  175. package/tests/environment-with-defvar.test.di +0 -15
  176. package/tests/eval-basic.test.di +0 -6
  177. package/tests/eval-with-variables.test.di +0 -8
  178. package/tests/exception-basic.test.di +0 -10
  179. package/tests/expr-basic.test.di +0 -11
  180. package/tests/extend-basic.test.di +0 -19
  181. package/tests/extend-inheritance-chain.test.di +0 -26
  182. package/tests/extend-multiple-nested.test.di +0 -24
  183. package/tests/extend-self.test.di +0 -19
  184. package/tests/extend-with-parameters.test.di +0 -14
  185. package/tests/generate-dirac.test.di +0 -22
  186. package/tests/if-conditional.test.di +0 -17
  187. package/tests/if-else.test.di +0 -11
  188. package/tests/if-with-variables.test.di +0 -8
  189. package/tests/import-basic.test.di +0 -6
  190. package/tests/input-file-all.test.di +0 -5
  191. package/tests/input-file-line.test.di +0 -15
  192. package/tests/input-file-loop.test.di +0 -12
  193. package/tests/input-stdin-all.test.di +0 -8
  194. package/tests/input-stdin-all.txt +0 -1
  195. package/tests/llm-validate.test.di +0 -17
  196. package/tests/loop-basic.test.di +0 -9
  197. package/tests/loop-nested.test.di +0 -10
  198. package/tests/loop-with-eval.test.di +0 -8
  199. package/tests/no-root-element.test.di +0 -6
  200. package/tests/output-file.test.di +0 -19
  201. package/tests/output-multiple.test.di +0 -9
  202. package/tests/parameters-basic.test.di +0 -6
  203. package/tests/require-module-basic.test.di +0 -7
  204. package/tests/subroutine-basic.test.di +0 -9
  205. package/tests/subroutine-multiple-params.test.di +0 -10
  206. package/tests/subroutine-nested-calls.test.di +0 -32
  207. package/tests/subroutine-sequential-calls.test.di +0 -36
  208. package/tests/system-background.test.di +0 -39
  209. package/tests/system-basic.test.di +0 -5
  210. package/tests/tag-check.test.di +0 -27
  211. package/tests/test-if-basic.test.di +0 -8
  212. package/tests/test-input.txt +0 -3
  213. package/tests/try-catch-basic.test.di +0 -10
  214. package/tests/try-catch-eval-error.test.di +0 -10
  215. package/tests/variable-basic.test.di +0 -6
  216. package/tests/variable-interpolation.test.di +0 -7
  217. package/tools/create-library.sh +0 -175
  218. package/tsconfig.json +0 -19
  219. /package/{examples/lib → lib}/advanced-math.di +0 -0
  220. /package/{examples/lib → lib}/fileops.di +0 -0
  221. /package/{examples/lib → lib}/mongodb.di +0 -0
@@ -1,172 +0,0 @@
1
- # Conditional Tags in Dirac
2
-
3
- Dirac supports two styles of conditional execution:
4
-
5
- ## 1. C-Style `<if>` Tag (Based on C MASK)
6
-
7
- The `<if>` tag uses child elements for structure, following the C MASK pattern.
8
-
9
- ### Syntax
10
-
11
- ```xml
12
- <if>
13
- <cond eval="eq|ne|lt|gt|le|ge">
14
- <arg>value1</arg>
15
- <arg>value2</arg>
16
- </cond>
17
- <then>
18
- <!-- executed if condition is true -->
19
- </then>
20
- <else>
21
- <!-- executed if condition is false (optional) -->
22
- </else>
23
- </if>
24
- ```
25
-
26
- ### Supported Comparison Types
27
-
28
- - `eq`, `equal`, `same` - Equality comparison
29
- - `ne`, `notequal`, `different` - Not equal
30
- - `lt`, `less` - Less than (numeric)
31
- - `le`, `lessequal` - Less than or equal (numeric)
32
- - `gt`, `greater` - Greater than (numeric)
33
- - `ge`, `greaterequal` - Greater than or equal (numeric)
34
-
35
- ### Alternative Syntax
36
-
37
- You can use `<do>` instead of `<then>`.
38
-
39
- You can omit the `<cond>` wrapper and use any element as the predicate:
40
-
41
- ```xml
42
- <if>
43
- <variable name="x"/>
44
- <then>
45
- <output>x exists and is truthy</output>
46
- </then>
47
- </if>
48
- ```
49
-
50
- ### Examples
51
-
52
- ```xml
53
- <!-- Simple equality -->
54
- <defvar name="x" value="5"/>
55
- <if>
56
- <cond eval="eq">
57
- <arg><variable name="x"/></arg>
58
- <arg>5</arg>
59
- </cond>
60
- <then>
61
- <output>x equals 5</output>
62
- </then>
63
- <else>
64
- <output>x does not equal 5</output>
65
- </else>
66
- </if>
67
-
68
- <!-- Greater than -->
69
- <defvar name="age" value="25"/>
70
- <if>
71
- <cond eval="gt">
72
- <arg><variable name="age"/></arg>
73
- <arg>18</arg>
74
- </cond>
75
- <then>
76
- <output>Adult</output>
77
- </then>
78
- <else>
79
- <output>Minor</output>
80
- </else>
81
- </if>
82
-
83
- <!-- Simple predicate -->
84
- <defvar name="name" value="Alice"/>
85
- <if>
86
- <variable name="name"/>
87
- <then>
88
- <output>Name is: <variable name="name"/></output>
89
- </then>
90
- </if>
91
- ```
92
-
93
- ## 2. Attribute-Based `<test-if>` Tag (Original Dirac Style)
94
-
95
- The `<test-if>` tag uses attributes for conditions, providing a more compact syntax.
96
-
97
- ### Syntax
98
-
99
- ```xml
100
- <test-if test="$variable" [eq|ne|lt|gt|le|ge]="value">
101
- <!-- executed if condition is true -->
102
- </test-if>
103
- ```
104
-
105
- ### Supported Attributes
106
-
107
- - `test` (required) - The value or variable to test (use `$` prefix for variables)
108
- - `eq` - Equals comparison
109
- - `ne` - Not equals comparison
110
- - `lt` - Less than (numeric)
111
- - `gt` - Greater than (numeric)
112
- - `le` - Less than or equal (numeric)
113
- - `ge` - Greater than or equal (numeric)
114
-
115
- If no comparison attribute is provided, the test value is evaluated as a boolean (non-empty = true).
116
-
117
- ### Examples
118
-
119
- ```xml
120
- <!-- Simple boolean test -->
121
- <defvar name="x" value="5"/>
122
- <test-if test="$x">
123
- <output>x is truthy</output>
124
- </test-if>
125
-
126
- <!-- Equality test -->
127
- <defvar name="status" value="active"/>
128
- <test-if test="$status" eq="active">
129
- <output>Status is active</output>
130
- </test-if>
131
-
132
- <!-- Greater than test -->
133
- <defvar name="age" value="25"/>
134
- <test-if test="$age" gt="18">
135
- <output>Age is greater than 18</output>
136
- </test-if>
137
-
138
- <!-- Less than or equal -->
139
- <defvar name="price" value="50"/>
140
- <test-if test="$price" le="50">
141
- <output>Price is affordable</output>
142
- </test-if>
143
- ```
144
-
145
- ## Choosing Between `<if>` and `<test-if>`
146
-
147
- - Use **`<if>`** when:
148
- - You need an else clause
149
- - You're porting code from C MASK
150
- - You prefer explicit structure
151
- - You need complex predicates
152
-
153
- - Use **`<test-if>`** when:
154
- - You only need a then clause (no else)
155
- - You want compact, attribute-based syntax
156
- - You're doing simple comparisons
157
- - You prefer the original Dirac style
158
-
159
- ## Truthiness Evaluation
160
-
161
- Both tags evaluate values as follows:
162
-
163
- - **False**: Empty string, "0", "false"
164
- - **True**: "1", "true", any non-empty string
165
- - For numeric comparisons, values are parsed as floats
166
-
167
- ## Notes
168
-
169
- - Condition evaluation does not produce output (intermediate values are captured and removed)
170
- - Arguments in `<cond>` are evaluated and their outputs captured
171
- - Variable substitution in `<test-if>` uses `$varname` or `${varname}` syntax
172
- - Both tags support nested content including `<defvar>`, `<output>`, and other tags
@@ -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