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.
- package/dist/{chunk-APWJJXNI.js → chunk-7OUYWIZV.js} +55 -14
- package/dist/{chunk-RGS2XK6T.js → chunk-OUMUIBK3.js} +1 -1
- package/dist/cli.js +15 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-UZDVASAW.js → interpreter-MTIIHIIQ.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/lib/index.di +9 -0
- package/package.json +13 -1
- package/.env.example +0 -8
- package/COMMUNITY.md +0 -465
- package/CONDITIONAL-TAGS.md +0 -172
- package/EXCEPTION-HANDLING.md +0 -156
- package/LIBRARIES.md +0 -172
- package/LLM-VALIDATION.md +0 -128
- package/NAMESPACES.md +0 -366
- package/PROMOTION.md +0 -257
- package/QUICKSTART-LIBRARY.md +0 -93
- package/TEST-COVERAGE.md +0 -113
- package/TESTING.md +0 -162
- package/config.test.yml +0 -5
- package/dirac-http/examples/demo.di +0 -9
- package/dirac-http/lib/index.di +0 -12
- package/examples/add-demo.di +0 -74
- package/examples/add.bk +0 -11
- package/examples/advanced-math-demo.di +0 -53
- package/examples/calculator.di +0 -32
- package/examples/compact-test.di +0 -6
- package/examples/comprehensive.bk +0 -29
- package/examples/defvar-variable-demo.di +0 -18
- package/examples/direct-call.di +0 -17
- package/examples/disk-analysis.di +0 -16
- package/examples/exception-demo.di +0 -82
- package/examples/executable-hello.di +0 -7
- package/examples/execute-demo.di +0 -38
- package/examples/file-manager.di +0 -77
- package/examples/file-stats.di +0 -18
- package/examples/hello.bk +0 -1
- package/examples/hello.di +0 -5
- package/examples/if-comparison.di +0 -91
- package/examples/if-cstyle-test.di +0 -149
- package/examples/if-vs-testif.di +0 -56
- package/examples/import-demo.di +0 -31
- package/examples/inline-test.bk +0 -7
- package/examples/llm-agent.di +0 -32
- package/examples/llm-basic.di +0 -12
- package/examples/llm-command-more.di +0 -6
- package/examples/llm-command-no-exec.di +0 -13
- package/examples/llm-command.di +0 -6
- package/examples/llm-complex.di +0 -141
- package/examples/llm-feedback-debug.di +0 -30
- package/examples/llm-feedback-demo.di +0 -19
- package/examples/llm-feedback-math.di +0 -22
- package/examples/llm-feedback-simple.di +0 -16
- package/examples/llm-feedback-sub.di +0 -22
- package/examples/llm-no-feedback.di +0 -10
- package/examples/llm-recursive.di +0 -31
- package/examples/llm-reflection-test.di +0 -19
- package/examples/llm-simple-test.di +0 -12
- package/examples/llm-subs.di +0 -132
- package/examples/llm-use-subs.di +0 -6
- package/examples/llm-validate-test.di +0 -18
- package/examples/loop.di +0 -12
- package/examples/math-test.di +0 -22
- package/examples/minimal-test.di +0 -13
- package/examples/mongodb-context-test.di +0 -27
- package/examples/mongodb-count-events.di +0 -8
- package/examples/mongodb-import-demo.di +0 -25
- package/examples/mongodb-simple-test.di +0 -18
- package/examples/nl-agent.di +0 -47
- package/examples/parameters-demo.di +0 -68
- package/examples/params-meta-test.di +0 -17
- package/examples/params-test.di +0 -10
- package/examples/recipe-chain.di +0 -38
- package/examples/recursive-llm.di +0 -44
- package/examples/sample-library/README.md +0 -152
- package/examples/sample-library/examples/demo.di +0 -34
- package/examples/sample-library/lib/index.di +0 -65
- package/examples/sample-library/package.json +0 -31
- package/examples/scope-test-nested.di +0 -60
- package/examples/scope-test.di +0 -55
- package/examples/seamless.di +0 -45
- package/examples/shell-test.bk +0 -10
- package/examples/simple-import.di +0 -13
- package/examples/simple-recursive.di +0 -26
- package/examples/story-builder.di +0 -45
- package/examples/subroutine.di +0 -23
- package/examples/system-llm.di +0 -21
- package/examples/system-simple.di +0 -3
- package/examples/system-test.di +0 -8
- package/examples/tag-check-test.di +0 -139
- package/examples/task-assistant.di +0 -27
- package/examples/test-if-demo.di +0 -110
- package/examples/test-parameters.di +0 -50
- package/examples/try-catch-test.di +0 -118
- package/examples/two-styles.di +0 -28
- package/examples/var-debug.di +0 -6
- package/examples/var-inline.di +0 -4
- package/examples/var-test2.di +0 -6
- package/examples/variable-replace.di +0 -25
- package/examples/variable-simple.di +0 -16
- package/examples/variable-test.di +0 -22
- package/examples/whitespace-test.di +0 -24
- package/filePath +0 -1
- package/greeting.txt +0 -1
- package/src/cli.ts +0 -140
- package/src/index.ts +0 -33
- package/src/llm/ollama.ts +0 -58
- package/src/runtime/braket-parser.ts +0 -234
- package/src/runtime/interpreter.ts +0 -203
- package/src/runtime/parser.ts +0 -155
- package/src/runtime/session.ts +0 -325
- package/src/tags/assign.ts +0 -37
- package/src/tags/attr.ts +0 -64
- package/src/tags/available-subroutines.ts +0 -70
- package/src/tags/call.ts +0 -259
- package/src/tags/catch.ts +0 -24
- package/src/tags/defvar.ts +0 -115
- package/src/tags/environment.ts +0 -21
- package/src/tags/eval.ts +0 -71
- package/src/tags/exception.ts +0 -20
- package/src/tags/execute.ts +0 -52
- package/src/tags/expr.ts +0 -128
- package/src/tags/foreach.ts +0 -170
- package/src/tags/if.ts +0 -191
- package/src/tags/import.ts +0 -66
- package/src/tags/index.ts +0 -41
- package/src/tags/input.ts +0 -182
- package/src/tags/llm.ts +0 -415
- package/src/tags/loop.ts +0 -43
- package/src/tags/mongodb.ts +0 -70
- package/src/tags/output.ts +0 -53
- package/src/tags/parameters.ts +0 -81
- package/src/tags/require_module.ts +0 -19
- package/src/tags/subroutine.ts +0 -75
- package/src/tags/system.ts +0 -93
- package/src/tags/tag-check.ts +0 -176
- package/src/tags/test-if.ts +0 -112
- package/src/tags/throw.ts +0 -26
- package/src/tags/try.ts +0 -19
- package/src/tags/variable.ts +0 -25
- package/src/test-runner.ts +0 -300
- package/src/types/index.ts +0 -128
- package/src/utils/llm-adapter.ts +0 -113
- package/src/utils/tag-validator.ts +0 -231
- package/test-available-extends.di +0 -28
- package/test-available-simple.di +0 -12
- package/test-available-subroutines.di +0 -16
- package/test-call.di +0 -9
- package/test-extend-basic.di +0 -17
- package/test-extend-chain.di +0 -26
- package/test-extend-debug.di +0 -17
- package/test-extend-debug2.di +0 -15
- package/test-extend-person.di +0 -17
- package/test-extend-simple.di +0 -11
- package/test-extend-zhi.di +0 -23
- package/test-extend.di +0 -19
- package/test-extend2.di +0 -26
- package/test-extend3-fixed.di +0 -23
- package/test-extend3-trouble.di +0 -23
- package/test-extend3.di +0 -21
- package/test-factorial.di +0 -19
- package/test-input-debug.di +0 -19
- package/test-nested-debug.di +0 -7
- package/test-nested-debug2.di +0 -8
- package/test-no-extend.di +0 -16
- package/test-simple-call.di +0 -7
- package/test-simple.di +0 -6
- package/tests/README.md +0 -69
- package/tests/assign-basic.test.di +0 -7
- package/tests/assign-from-eval.test.di +0 -7
- package/tests/available-subroutines-foreach.test.di +0 -32
- package/tests/basic-output.test.di +0 -5
- package/tests/call-basic.test.di +0 -11
- package/tests/call-with-output.test.di +0 -10
- package/tests/comments-before-content.test.di +0 -6
- package/tests/defvar-multiple.test.di +0 -8
- package/tests/environment-basic.test.di +0 -22
- package/tests/environment-nonexistent.test.di +0 -5
- package/tests/environment-with-defvar.test.di +0 -15
- package/tests/eval-basic.test.di +0 -6
- package/tests/eval-with-variables.test.di +0 -8
- package/tests/exception-basic.test.di +0 -10
- package/tests/expr-basic.test.di +0 -11
- package/tests/extend-basic.test.di +0 -19
- package/tests/extend-inheritance-chain.test.di +0 -26
- package/tests/extend-multiple-nested.test.di +0 -24
- package/tests/extend-self.test.di +0 -19
- package/tests/extend-with-parameters.test.di +0 -14
- package/tests/generate-dirac.test.di +0 -22
- package/tests/if-conditional.test.di +0 -17
- package/tests/if-else.test.di +0 -11
- package/tests/if-with-variables.test.di +0 -8
- package/tests/import-basic.test.di +0 -6
- package/tests/input-file-all.test.di +0 -5
- package/tests/input-file-line.test.di +0 -15
- package/tests/input-file-loop.test.di +0 -12
- package/tests/input-stdin-all.test.di +0 -8
- package/tests/input-stdin-all.txt +0 -1
- package/tests/llm-validate.test.di +0 -17
- package/tests/loop-basic.test.di +0 -9
- package/tests/loop-nested.test.di +0 -10
- package/tests/loop-with-eval.test.di +0 -8
- package/tests/no-root-element.test.di +0 -6
- package/tests/output-file.test.di +0 -19
- package/tests/output-multiple.test.di +0 -9
- package/tests/parameters-basic.test.di +0 -6
- package/tests/require-module-basic.test.di +0 -7
- package/tests/subroutine-basic.test.di +0 -9
- package/tests/subroutine-multiple-params.test.di +0 -10
- package/tests/subroutine-nested-calls.test.di +0 -32
- package/tests/subroutine-sequential-calls.test.di +0 -36
- package/tests/system-background.test.di +0 -39
- package/tests/system-basic.test.di +0 -5
- package/tests/tag-check.test.di +0 -27
- package/tests/test-if-basic.test.di +0 -8
- package/tests/test-input.txt +0 -3
- package/tests/try-catch-basic.test.di +0 -10
- package/tests/try-catch-eval-error.test.di +0 -10
- package/tests/variable-basic.test.di +0 -6
- package/tests/variable-interpolation.test.di +0 -7
- package/tools/create-library.sh +0 -175
- package/tsconfig.json +0 -19
- /package/{examples/lib → lib}/advanced-math.di +0 -0
- /package/{examples/lib → lib}/fileops.di +0 -0
- /package/{examples/lib → lib}/math.di +0 -0
- /package/{examples/lib → lib}/mongodb.di +0 -0
package/EXCEPTION-HANDLING.md
DELETED
|
@@ -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) < 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 < 5) ... <!-- Use < not < -->
|
|
105
|
-
if (x > 10) ... <!-- Use > not > -->
|
|
106
|
-
if (x <= 5) ... <!-- Use <= -->
|
|
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
|