dirac-lang 0.1.16 → 0.1.18

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-CP4YCRBG.js";
3
+ } from "./chunk-VZEKPMWN.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -310,8 +310,8 @@ async function executeCallInternal(session, subroutine, callElement, isExtendExe
310
310
  } finally {
311
311
  session.skipSubroutineRegistration = oldSkipFlag;
312
312
  popParameters(session);
313
- session.varBoundary = oldBoundary;
314
313
  cleanToBoundary(session);
314
+ session.varBoundary = oldBoundary;
315
315
  session.isReturn = wasReturn;
316
316
  }
317
317
  }
@@ -396,12 +396,12 @@ async function executeIf(session, element) {
396
396
  const condition = await evaluatePredicate(session, conditionElement);
397
397
  if (condition) {
398
398
  if (thenElement) {
399
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
399
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
400
400
  await integrateChildren2(session, thenElement);
401
401
  }
402
402
  } else {
403
403
  if (elseElement) {
404
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
404
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
405
405
  await integrateChildren2(session, elseElement);
406
406
  }
407
407
  }
@@ -414,7 +414,7 @@ async function evaluatePredicate(session, predicateElement) {
414
414
  return await evaluateCondition(session, predicateElement);
415
415
  }
416
416
  const outputLengthBefore = session.output.length;
417
- const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
417
+ const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
418
418
  await integrate2(session, predicateElement);
419
419
  const newOutputChunks = session.output.slice(outputLengthBefore);
420
420
  const result = newOutputChunks.join("").trim();
@@ -437,11 +437,11 @@ async function evaluateCondition(session, condElement) {
437
437
  }
438
438
  const outputLengthBefore = session.output.length;
439
439
  const args = [];
440
- const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
440
+ const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
441
441
  for (const child of condElement.children) {
442
442
  if (child.tag.toLowerCase() === "arg") {
443
443
  const argOutputStart = session.output.length;
444
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
444
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
445
445
  await integrateChildren2(session, child);
446
446
  const newChunks = session.output.slice(argOutputStart);
447
447
  const argValue = newChunks.join("");
@@ -677,7 +677,7 @@ ${result}
677
677
  const parser = new DiracParser();
678
678
  let dynamicAST = parser.parse(diracCode);
679
679
  if (validateTags) {
680
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-CLYGULLQ.js");
680
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-HBCGQV6F.js");
681
681
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
682
682
  let retryCount = 0;
683
683
  while (!validation.valid && retryCount < maxRetries) {
@@ -1244,7 +1244,7 @@ async function executeTagCheck(session, element) {
1244
1244
  const executeTag = correctedTag || tagName;
1245
1245
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1246
1246
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1247
- const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
1247
+ const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
1248
1248
  await integrate2(session, elementToExecute);
1249
1249
  }
1250
1250
  }
@@ -1253,7 +1253,7 @@ async function executeTagCheck(session, element) {
1253
1253
  // src/tags/throw.ts
1254
1254
  async function executeThrow(session, element) {
1255
1255
  const exceptionName = element.attributes?.name || "exception";
1256
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1256
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
1257
1257
  const exceptionDom = {
1258
1258
  tag: "exception-content",
1259
1259
  attributes: { name: exceptionName },
@@ -1266,7 +1266,7 @@ async function executeThrow(session, element) {
1266
1266
  // src/tags/try.ts
1267
1267
  async function executeTry(session, element) {
1268
1268
  setExceptionBoundary(session);
1269
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1269
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
1270
1270
  await integrateChildren2(session, element);
1271
1271
  unsetExceptionBoundary(session);
1272
1272
  }
@@ -1276,7 +1276,7 @@ async function executeCatch(session, element) {
1276
1276
  const exceptionName = element.attributes?.name || "exception";
1277
1277
  const caughtCount = lookupException(session, exceptionName);
1278
1278
  if (caughtCount > 0) {
1279
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1279
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
1280
1280
  await integrateChildren2(session, element);
1281
1281
  }
1282
1282
  flushCurrentException(session);
@@ -1285,7 +1285,7 @@ async function executeCatch(session, element) {
1285
1285
  // src/tags/exception.ts
1286
1286
  async function executeException(session, element) {
1287
1287
  const exceptions = getCurrentExceptions(session);
1288
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1288
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-MCDR5L7R.js");
1289
1289
  for (const exceptionDom of exceptions) {
1290
1290
  await integrateChildren2(session, exceptionDom);
1291
1291
  }
@@ -1425,7 +1425,7 @@ async function executeForeach(session, element) {
1425
1425
  const parser2 = new DiracParser2();
1426
1426
  try {
1427
1427
  const fromElement = parser2.parse(fromAttr);
1428
- const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
1428
+ const { integrate: integrate2 } = await import("./interpreter-MCDR5L7R.js");
1429
1429
  await integrate2(session, fromElement);
1430
1430
  } catch (e) {
1431
1431
  session.output = savedOutput;
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execute
4
- } from "./chunk-FEOBVBSI.js";
5
- import "./chunk-CP4YCRBG.js";
4
+ } from "./chunk-E2MR7FMI.js";
5
+ import "./chunk-VZEKPMWN.js";
6
6
  import "./chunk-HRHAMPOB.js";
7
7
  import "./chunk-E7PWEMZA.js";
8
8
  import "./chunk-52ED23DR.js";
@@ -13,7 +13,7 @@ import "dotenv/config";
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "dirac-lang",
16
- version: "0.1.16",
16
+ version: "0.1.18",
17
17
  description: "LLM-Augmented Declarative Execution",
18
18
  type: "module",
19
19
  main: "dist/index.js",
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-FEOBVBSI.js";
5
+ } from "./chunk-E2MR7FMI.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-CP4YCRBG.js";
8
+ } from "./chunk-VZEKPMWN.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-CP4YCRBG.js";
4
+ } from "./chunk-VZEKPMWN.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
6
  import "./chunk-E7PWEMZA.js";
7
7
  import "./chunk-52ED23DR.js";
@@ -113,7 +113,7 @@ async function validateDiracCode(session, ast, options = {}) {
113
113
  const results = [];
114
114
  const errorMessages = [];
115
115
  async function validateElement(element) {
116
- if (element.tag && element.tag !== "dirac" && element.tag.trim() !== "") {
116
+ if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
117
117
  const result = await validateTag(session, element, options);
118
118
  results.push(result);
119
119
  if (!result.valid) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-CP4YCRBG.js";
3
+ } from "./chunk-VZEKPMWN.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -2,5 +2,5 @@
2
2
  <subroutine name="background" description="set the background color." param-color="string:required:color name" >
3
3
  this is my color: <variable name="color" />
4
4
  </subroutine>
5
- <llm execute="true">set the background color to red</llm>
5
+ <llm execute="true" validate="true">set the background color to red</llm>
6
6
  </dirac>
@@ -0,0 +1,60 @@
1
+ <!-- Test nested subroutine calls with variable scope -->
2
+ <dirac>
3
+ <output>
4
+ ============ Test: Nested Subroutine Calls with Variable Scope ============
5
+ </output>
6
+
7
+ <!-- Define main scope variables -->
8
+ <eval name="a">return "value-a"</eval>
9
+ <eval name="b">return "value-b"</eval>
10
+ <eval name="c">return "value-c"</eval>
11
+
12
+ <output>
13
+ Main scope: a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
14
+ </output>
15
+
16
+ <!-- Subroutine that calls another subroutine -->
17
+ <subroutine name="outer-sub" param-x="type:string:" param-y="type:string:">
18
+ <output> Outer subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
19
+
20
+ <!-- Define local variable in outer sub -->
21
+ <eval name="outer_local">return "outer-value"</eval>
22
+ <output> Outer local: <variable name="outer_local" /></output>
23
+
24
+ <!-- Call inner subroutine -->
25
+ <call name="inner-sub" p="$x" q="$y"/>
26
+
27
+ <!-- Check outer variables still exist after inner call -->
28
+ <output> After inner call - x: <variable name="x" />, y: <variable name="y" />, outer_local: <variable name="outer_local" /></output>
29
+ </subroutine>
30
+
31
+ <!-- Inner subroutine -->
32
+ <subroutine name="inner-sub" param-p="type:string:" param-q="type:string:">
33
+ <output> Inner subroutine - p: <variable name="p" />, q: <variable name="q" /></output>
34
+ <eval name="inner_local">return "inner-value"</eval>
35
+ <output> Inner local: <variable name="inner_local" /></output>
36
+ </subroutine>
37
+
38
+ <output>
39
+ Calling outer-sub with a and b...
40
+ </output>
41
+ <call name="outer-sub" x="$a" y="$b"/>
42
+
43
+ <output>
44
+ After outer-sub, checking main scope:
45
+ a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
46
+ </output>
47
+
48
+ <!-- Call outer-sub again to ensure no cumulative scope pollution -->
49
+ <output>
50
+ Calling outer-sub AGAIN with b and c...
51
+ </output>
52
+ <call name="outer-sub" x="$b" y="$c"/>
53
+
54
+ <output>
55
+ After second outer-sub call:
56
+ a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
57
+
58
+ ============ Test Complete ============
59
+ </output>
60
+ </dirac>
@@ -0,0 +1,55 @@
1
+ <dirac>
2
+ <!-- Test library with two simple subroutines -->
3
+ <subroutine name="first-sub"
4
+ param-x="string"
5
+ param-y="string">
6
+ <output>First subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
7
+ </subroutine>
8
+
9
+ <subroutine name="second-sub"
10
+ param-x="string"
11
+ param-y="string"
12
+ param-z="string">
13
+ <output>Second subroutine - x: <variable name="x" />, y: <variable name="y" />, z: <variable name="z" /></output>
14
+ </subroutine>
15
+
16
+ <!-- Main execution -->
17
+ <output>============ Test: Sequential Subroutine Calls ============</output>
18
+ <output></output>
19
+
20
+ <!-- Define variables in main scope -->
21
+ <defvar name="x" trim="true">value-x</defvar>
22
+ <defvar name="y" trim="true">value-y</defvar>
23
+ <defvar name="z" trim="true">value-z</defvar>
24
+
25
+ <output>Variables defined in main scope:</output>
26
+ <output> x = <variable name="x" /></output>
27
+ <output> y = <variable name="y" /></output>
28
+ <output> z = <variable name="z" /></output>
29
+ <output></output>
30
+
31
+ <!-- Call first subroutine -->
32
+ <output>Calling first-sub with x="$x" y="$y"</output>
33
+ <first-sub x="$x" y="$y" />
34
+ <output></output>
35
+
36
+ <!-- Check if variables still exist after first call -->
37
+ <output>After first-sub, checking main scope variables:</output>
38
+ <output> x = <variable name="x" /></output>
39
+ <output> y = <variable name="y" /></output>
40
+ <output> z = <variable name="z" /></output>
41
+ <output></output>
42
+
43
+ <!-- Call second subroutine -->
44
+ <output>Calling second-sub with x="$x" y="$y" z="$z"</output>
45
+ <second-sub x="$x" y="$y" z="$z" />
46
+ <output></output>
47
+
48
+ <output>After second-sub, checking main scope variables:</output>
49
+ <output> x = <variable name="x" /></output>
50
+ <output> y = <variable name="y" /></output>
51
+ <output> z = <variable name="z" /></output>
52
+ <output></output>
53
+
54
+ <output>============ Test Complete ============</output>
55
+ </dirac>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/tags/call.ts CHANGED
@@ -200,9 +200,9 @@ async function executeCallInternal(
200
200
  // Pop parameter stack
201
201
  popParameters(session);
202
202
 
203
- // Clean up scope (keep visible variables)
204
- session.varBoundary = oldBoundary;
203
+ // Clean up scope (keep visible variables) BEFORE restoring boundary
205
204
  cleanToBoundary(session);
205
+ session.varBoundary = oldBoundary;
206
206
  session.isReturn = wasReturn;
207
207
  }
208
208
  }
@@ -182,8 +182,8 @@ export async function validateDiracCode(
182
182
 
183
183
  // Recursively validate all elements
184
184
  async function validateElement(element: DiracElement) {
185
- // Skip text nodes and whitespace-only tags
186
- if (element.tag && element.tag !== 'dirac' && element.tag.trim() !== '') {
185
+ // Skip text nodes, whitespace-only tags, and root wrapper tags
186
+ if (element.tag && element.tag !== 'dirac' && element.tag !== 'DIRAC-ROOT' && element.tag.trim() !== '') {
187
187
  const result = await validateTag(session, element, options);
188
188
  results.push(result);
189
189
 
package/test-eval.di ADDED
@@ -0,0 +1,4 @@
1
+ <dirac>
2
+ <eval name="test">"hello"</eval>
3
+ <output>test=$test</output>
4
+ </dirac>
@@ -0,0 +1,17 @@
1
+ <!-- TEST: llm_execute_with_validation -->
2
+ <!-- EXPECT: Background color is: blue -->
3
+
4
+ <dirac>
5
+ <subroutine name="set-color"
6
+ description="Set a background color"
7
+ param-color="string:required:Color name">
8
+ <parameters select="@color"/>
9
+ <output>Background color is: <variable name="color" /></output>
10
+ </subroutine>
11
+
12
+ <!-- Test: LLM with execute=true and validate=true should work -->
13
+ <!-- This tests that DIRAC-ROOT wrapper tag is properly skipped during validation -->
14
+ <llm execute="true" validate="true" maxTokens="100">
15
+ Set the background color to blue
16
+ </llm>
17
+ </dirac>
@@ -0,0 +1,32 @@
1
+ <!-- TEST: subroutine_nested_calls_preserve_scope -->
2
+ <!-- EXPECT: main: a=x b=y c=z
3
+ outer: p=x q=y
4
+ inner: r=x s=y
5
+ outer after inner: p=x q=y
6
+ main after outer: a=x b=y c=z -->
7
+ <dirac>
8
+ <!-- Inner subroutine -->
9
+ <subroutine name="inner" param-r="string" param-s="string">
10
+ <output>inner: r=<variable name="r" /> s=<variable name="s" /></output>
11
+ </subroutine>
12
+
13
+ <!-- Outer subroutine that calls inner -->
14
+ <subroutine name="outer" param-p="string" param-q="string">
15
+ <output>outer: p=<variable name="p" /> q=<variable name="q" /></output>
16
+ <inner r="$p" s="$q" />
17
+ <output>outer after inner: p=<variable name="p" /> q=<variable name="q" /></output>
18
+ </subroutine>
19
+
20
+ <!-- Define main scope variables -->
21
+ <defvar name="a" trim="true">x</defvar>
22
+ <defvar name="b" trim="true">y</defvar>
23
+ <defvar name="c" trim="true">z</defvar>
24
+
25
+ <output>main: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
26
+
27
+ <!-- Call outer which calls inner -->
28
+ <outer p="$a" q="$b" />
29
+
30
+ <!-- Verify main scope variables preserved -->
31
+ <output>main after outer: a=<variable name="a" /> b=<variable name="b" /> c=<variable name="c" /></output>
32
+ </dirac>
@@ -0,0 +1,36 @@
1
+ <!-- TEST: subroutine_sequential_calls_preserve_scope -->
2
+ <!-- EXPECT: x=a y=b z=c
3
+ first: x=a y=b
4
+ x=a y=b z=c
5
+ second: x=a y=b z=c
6
+ x=a y=b z=c -->
7
+ <dirac>
8
+ <!-- Define subroutines -->
9
+ <subroutine name="first-sub" param-x="string" param-y="string">
10
+ <output>first: x=<variable name="x" /> y=<variable name="y" /></output>
11
+ </subroutine>
12
+
13
+ <subroutine name="second-sub" param-x="string" param-y="string" param-z="string">
14
+ <output>second: x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
15
+ </subroutine>
16
+
17
+ <!-- Define main scope variables -->
18
+ <defvar name="x" trim="true">a</defvar>
19
+ <defvar name="y" trim="true">b</defvar>
20
+ <defvar name="z" trim="true">c</defvar>
21
+
22
+ <!-- Verify initial state -->
23
+ <output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
24
+
25
+ <!-- First call -->
26
+ <first-sub x="$x" y="$y" />
27
+
28
+ <!-- Verify variables still exist after first call -->
29
+ <output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
30
+
31
+ <!-- Second call - this would fail with the bug -->
32
+ <second-sub x="$x" y="$y" z="$z" />
33
+
34
+ <!-- Verify variables still exist after second call -->
35
+ <output>x=<variable name="x" /> y=<variable name="y" /> z=<variable name="z" /></output>
36
+ </dirac>