dirac-lang 0.1.30 → 0.1.32

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.
@@ -107,7 +107,9 @@ function createSession(config = {}) {
107
107
  isReturn: false,
108
108
  isBreak: false,
109
109
  skipSubroutineRegistration: false,
110
- debug: config.debug || false
110
+ debug: config.debug || false,
111
+ currentFile: config.filePath
112
+ // Set current file from config for proper relative import resolution
111
113
  };
112
114
  }
113
115
  function setVariable(session, name, value, visible = false) {
@@ -151,11 +153,12 @@ function cleanToBoundary(session) {
151
153
  session.variables = kept;
152
154
  session.varBoundary = kept.length;
153
155
  }
154
- function registerSubroutine(session, name, element, description, parameters, meta) {
156
+ function registerSubroutine(session, name, element, description, parameters, meta, visible) {
155
157
  session.subroutines.push({
156
158
  name,
157
159
  element,
158
160
  boundary: session.subBoundary,
161
+ visible,
159
162
  description,
160
163
  parameters,
161
164
  meta
@@ -193,8 +196,13 @@ function setSubroutineBoundary(session) {
193
196
  function popSubroutinesToBoundary(session) {
194
197
  session.subroutines = session.subroutines.slice(0, session.subBoundary);
195
198
  }
196
- function cleanSubroutinesToBoundary(session) {
197
- popSubroutinesToBoundary(session);
199
+ function cleanSubroutinesToBoundary(session, callerSubroutine) {
200
+ const keepNested = callerSubroutine?.attributes.visible === "subroutine" || callerSubroutine?.attributes.visible === "both";
201
+ if (keepNested) {
202
+ session.subBoundary = session.subroutines.length;
203
+ } else {
204
+ session.subroutines = session.subroutines.slice(0, session.subBoundary);
205
+ }
198
206
  }
199
207
  function substituteVariables(session, text) {
200
208
  return text.replace(/&#10;/g, "\n").replace(/&#13;/g, "\r").replace(/&#9;/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerSubroutine
3
- } from "./chunk-BSQV77YM.js";
3
+ } from "./chunk-JIWLKB5O.js";
4
4
 
5
5
  // src/tags/subroutine.ts
6
6
  function executeSubroutine(session, element) {
@@ -12,6 +12,7 @@ function executeSubroutine(session, element) {
12
12
  throw new Error("<subroutine> requires name attribute");
13
13
  }
14
14
  const description = element.attributes.description;
15
+ const visible = element.attributes.visible === "subroutine" || element.attributes.visible === "both";
15
16
  const parameters = [];
16
17
  const meta = {};
17
18
  function parseMetaField(metaString) {
@@ -56,7 +57,8 @@ function executeSubroutine(session, element) {
56
57
  subroutine,
57
58
  description,
58
59
  parameters.length > 0 ? parameters : void 0,
59
- Object.keys(meta).length > 0 ? meta : void 0
60
+ Object.keys(meta).length > 0 ? meta : void 0,
61
+ visible
60
62
  );
61
63
  }
62
64
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-Y57EPVOA.js";
3
+ } from "./chunk-YRJ3SODI.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -8,7 +8,7 @@ import {
8
8
  createSession,
9
9
  getAvailableSubroutines,
10
10
  getOutput
11
- } from "./chunk-BSQV77YM.js";
11
+ } from "./chunk-JIWLKB5O.js";
12
12
 
13
13
  // src/utils/llm-adapter.ts
14
14
  function createLLMAdapter(session) {
@@ -3,8 +3,9 @@ import {
3
3
  } from "./chunk-HRHAMPOB.js";
4
4
  import {
5
5
  executeSubroutine
6
- } from "./chunk-LXF5PGUX.js";
6
+ } from "./chunk-JMUUPZZA.js";
7
7
  import {
8
+ cleanSubroutinesToBoundary,
8
9
  cleanToBoundary,
9
10
  emit,
10
11
  flushCurrentException,
@@ -18,12 +19,13 @@ import {
18
19
  pushParameters,
19
20
  setBoundary,
20
21
  setExceptionBoundary,
22
+ setSubroutineBoundary,
21
23
  setVariable,
22
24
  substituteAttribute,
23
25
  substituteVariables,
24
26
  throwException,
25
27
  unsetExceptionBoundary
26
- } from "./chunk-BSQV77YM.js";
28
+ } from "./chunk-JIWLKB5O.js";
27
29
 
28
30
  // src/tags/parameters.ts
29
31
  async function executeParameters(session, element) {
@@ -255,7 +257,7 @@ async function executeCall(session, element) {
255
257
  }
256
258
  }
257
259
  async function registerExtendChain(session, subroutine, currentName) {
258
- const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-GG66UT4D.js");
260
+ const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-I5XXJMFL.js");
259
261
  const extendsAttr = subroutine.attributes.extends;
260
262
  let parentName;
261
263
  if (extendsAttr) {
@@ -289,6 +291,7 @@ async function registerExtendChain(session, subroutine, currentName) {
289
291
  }
290
292
  async function executeCallInternal(session, subroutine, callElement, isExtendExecution = false) {
291
293
  const oldBoundary = setBoundary(session);
294
+ const oldSubBoundary = setSubroutineBoundary(session);
292
295
  const wasReturn = session.isReturn;
293
296
  session.isReturn = false;
294
297
  const oldSubroutineName = session.currentSubroutineName;
@@ -334,7 +337,9 @@ async function executeCallInternal(session, subroutine, callElement, isExtendExe
334
337
  session.skipSubroutineRegistration = oldSkipFlag;
335
338
  popParameters(session);
336
339
  cleanToBoundary(session);
340
+ cleanSubroutinesToBoundary(session, subroutine);
337
341
  session.varBoundary = oldBoundary;
342
+ session.subBoundary = oldSubBoundary;
338
343
  session.isReturn = wasReturn;
339
344
  }
340
345
  }
@@ -420,12 +425,12 @@ async function executeIf(session, element) {
420
425
  const condition = await evaluatePredicate(session, conditionElement);
421
426
  if (condition) {
422
427
  if (thenElement) {
423
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
428
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
424
429
  await integrateChildren2(session, thenElement);
425
430
  }
426
431
  } else {
427
432
  if (elseElement) {
428
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
433
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
429
434
  await integrateChildren2(session, elseElement);
430
435
  }
431
436
  }
@@ -438,7 +443,7 @@ async function evaluatePredicate(session, predicateElement) {
438
443
  return await evaluateCondition(session, predicateElement);
439
444
  }
440
445
  const outputLengthBefore = session.output.length;
441
- const { integrate: integrate2 } = await import("./interpreter-NNPKC43F.js");
446
+ const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
442
447
  await integrate2(session, predicateElement);
443
448
  const newOutputChunks = session.output.slice(outputLengthBefore);
444
449
  const result = newOutputChunks.join("").trim();
@@ -461,11 +466,11 @@ async function evaluateCondition(session, condElement) {
461
466
  }
462
467
  const outputLengthBefore = session.output.length;
463
468
  const args = [];
464
- const { integrate: integrate2 } = await import("./interpreter-NNPKC43F.js");
469
+ const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
465
470
  for (const child of condElement.children) {
466
471
  if (child.tag.toLowerCase() === "arg") {
467
472
  const argOutputStart = session.output.length;
468
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
473
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
469
474
  await integrateChildren2(session, child);
470
475
  const newChunks = session.output.slice(argOutputStart);
471
476
  const argValue = newChunks.join("");
@@ -574,7 +579,7 @@ async function executeLLM(session, element) {
574
579
  console.error("[LLM] Full prompt sent to LLM (noextra):\n" + prompt + "\n");
575
580
  }
576
581
  } else {
577
- const { getAvailableSubroutines } = await import("./session-QXKZY7G2.js");
582
+ const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
578
583
  const subroutines = getAvailableSubroutines(session);
579
584
  if (session.debug) {
580
585
  console.error(
@@ -701,7 +706,7 @@ ${result}
701
706
  const parser = new DiracParser();
702
707
  let dynamicAST = parser.parse(diracCode);
703
708
  if (validateTags) {
704
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-ANTK7UTG.js");
709
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-QX47WU2J.js");
705
710
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
706
711
  let retryCount = 0;
707
712
  while (!validation.valid && retryCount < maxRetries) {
@@ -982,10 +987,11 @@ function resolveImportPath(src, currentDir) {
982
987
  return resolved.endsWith(".di") ? resolved : resolved + ".di";
983
988
  }
984
989
  async function executeImport(session, element) {
985
- const src = element.attributes.src;
986
- if (!src) {
990
+ const srcAttr = element.attributes.src;
991
+ if (!srcAttr) {
987
992
  throw new Error("<import> requires src attribute");
988
993
  }
994
+ const src = substituteAttribute(session, srcAttr);
989
995
  const currentDir = session.currentFile ? dirname2(session.currentFile) : process.cwd();
990
996
  const importPath = resolveImportPath(src, currentDir);
991
997
  if (session.debug) {
@@ -1231,7 +1237,7 @@ async function getBestTagMatch(candidate, allowed) {
1231
1237
  return { tag: allowed[bestIdx], score: bestScore };
1232
1238
  }
1233
1239
  async function executeTagCheck(session, element) {
1234
- const { getAvailableSubroutines } = await import("./session-QXKZY7G2.js");
1240
+ const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
1235
1241
  const subroutines = getAvailableSubroutines(session);
1236
1242
  const allowed = new Set(subroutines.map((s) => s.name));
1237
1243
  console.error("[tag-check] Allowed subroutines:", Array.from(allowed));
@@ -1324,7 +1330,7 @@ async function executeTagCheck(session, element) {
1324
1330
  const executeTag = correctedTag || tagName;
1325
1331
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1326
1332
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1327
- const { integrate: integrate2 } = await import("./interpreter-NNPKC43F.js");
1333
+ const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
1328
1334
  await integrate2(session, elementToExecute);
1329
1335
  }
1330
1336
  }
@@ -1333,7 +1339,7 @@ async function executeTagCheck(session, element) {
1333
1339
  // src/tags/throw.ts
1334
1340
  async function executeThrow(session, element) {
1335
1341
  const exceptionName = element.attributes?.name || "exception";
1336
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
1342
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1337
1343
  const exceptionDom = {
1338
1344
  tag: "exception-content",
1339
1345
  attributes: { name: exceptionName },
@@ -1346,7 +1352,7 @@ async function executeThrow(session, element) {
1346
1352
  // src/tags/try.ts
1347
1353
  async function executeTry(session, element) {
1348
1354
  setExceptionBoundary(session);
1349
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
1355
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1350
1356
  await integrateChildren2(session, element);
1351
1357
  unsetExceptionBoundary(session);
1352
1358
  }
@@ -1356,7 +1362,7 @@ async function executeCatch(session, element) {
1356
1362
  const exceptionName = element.attributes?.name || "exception";
1357
1363
  const caughtCount = lookupException(session, exceptionName);
1358
1364
  if (caughtCount > 0) {
1359
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
1365
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1360
1366
  await integrateChildren2(session, element);
1361
1367
  }
1362
1368
  flushCurrentException(session);
@@ -1365,7 +1371,7 @@ async function executeCatch(session, element) {
1365
1371
  // src/tags/exception.ts
1366
1372
  async function executeException(session, element) {
1367
1373
  const exceptions = getCurrentExceptions(session);
1368
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NNPKC43F.js");
1374
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1369
1375
  for (const exceptionDom of exceptions) {
1370
1376
  await integrateChildren2(session, exceptionDom);
1371
1377
  }
@@ -1454,7 +1460,7 @@ function evaluateCondition2(session, test) {
1454
1460
  // src/tags/available-subroutines.ts
1455
1461
  async function executeAvailableSubroutines(session, element) {
1456
1462
  const availableSubroutines = /* @__PURE__ */ new Map();
1457
- const currentSubroutineName = session.subBoundary < session.subroutines.length ? session.subroutines[session.subBoundary].name : null;
1463
+ const currentSubroutineName = session.subBoundary > 0 && session.subBoundary <= session.subroutines.length ? session.subroutines[session.subBoundary - 1].name : null;
1458
1464
  for (let i = session.subroutines.length - 1; i >= session.subBoundary; i--) {
1459
1465
  const sub = session.subroutines[i];
1460
1466
  if (sub.name === currentSubroutineName) {
@@ -1505,7 +1511,7 @@ async function executeForeach(session, element) {
1505
1511
  const parser2 = new DiracParser2();
1506
1512
  try {
1507
1513
  const fromElement = parser2.parse(fromAttr);
1508
- const { integrate: integrate2 } = await import("./interpreter-NNPKC43F.js");
1514
+ const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
1509
1515
  await integrate2(session, fromElement);
1510
1516
  } catch (e) {
1511
1517
  session.output = savedOutput;
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execute
4
- } from "./chunk-QPYWRBBT.js";
5
- import "./chunk-Y57EPVOA.js";
4
+ } from "./chunk-UYDP4ZFS.js";
5
+ import "./chunk-YRJ3SODI.js";
6
6
  import "./chunk-HRHAMPOB.js";
7
- import "./chunk-LXF5PGUX.js";
8
- import "./chunk-BSQV77YM.js";
7
+ import "./chunk-JMUUPZZA.js";
8
+ import "./chunk-JIWLKB5O.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import "dotenv/config";
@@ -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.29",
16
+ version: "0.1.32",
17
17
  description: "LLM-Augmented Declarative Execution",
18
18
  type: "module",
19
19
  main: "dist/index.js",
package/dist/index.d.ts CHANGED
@@ -53,6 +53,7 @@ interface Subroutine {
53
53
  element: DiracElement;
54
54
  boundary: number;
55
55
  extends?: string;
56
+ visible?: boolean;
56
57
  description?: string;
57
58
  parameters?: ParameterMetadata[];
58
59
  meta?: Record<string, string>;
package/dist/index.js CHANGED
@@ -2,19 +2,19 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-QPYWRBBT.js";
5
+ } from "./chunk-UYDP4ZFS.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-Y57EPVOA.js";
8
+ } from "./chunk-YRJ3SODI.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
12
- import "./chunk-LXF5PGUX.js";
12
+ import "./chunk-JMUUPZZA.js";
13
13
  import {
14
14
  createSession,
15
15
  getAvailableSubroutines,
16
16
  getOutput
17
- } from "./chunk-BSQV77YM.js";
17
+ } from "./chunk-JIWLKB5O.js";
18
18
  export {
19
19
  DiracParser,
20
20
  createLLMAdapter,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-Y57EPVOA.js";
4
+ } from "./chunk-YRJ3SODI.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
- import "./chunk-LXF5PGUX.js";
7
- import "./chunk-BSQV77YM.js";
6
+ import "./chunk-JMUUPZZA.js";
7
+ import "./chunk-JIWLKB5O.js";
8
8
  export {
9
9
  integrate,
10
10
  integrateChildren
@@ -26,7 +26,7 @@ import {
26
26
  substituteVariables,
27
27
  throwException,
28
28
  unsetExceptionBoundary
29
- } from "./chunk-BSQV77YM.js";
29
+ } from "./chunk-JIWLKB5O.js";
30
30
  export {
31
31
  cleanSubroutinesToBoundary,
32
32
  cleanToBoundary,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  executeSubroutine
3
- } from "./chunk-LXF5PGUX.js";
4
- import "./chunk-BSQV77YM.js";
3
+ } from "./chunk-JMUUPZZA.js";
4
+ import "./chunk-JIWLKB5O.js";
5
5
  export {
6
6
  executeSubroutine
7
7
  };
@@ -49,7 +49,7 @@ async function getBestTagMatch(candidate, allowed) {
49
49
  }
50
50
  async function validateTag(session, element, options = {}) {
51
51
  const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF } = options;
52
- const { getAvailableSubroutines } = await import("./session-QXKZY7G2.js");
52
+ const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
53
53
  const subroutines = getAvailableSubroutines(session);
54
54
  const allowed = new Set(subroutines.map((s) => s.name));
55
55
  const tagName = element.tag;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-Y57EPVOA.js";
3
+ } from "./chunk-YRJ3SODI.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
7
- import "./chunk-LXF5PGUX.js";
7
+ import "./chunk-JMUUPZZA.js";
8
8
  import {
9
9
  createSession,
10
10
  getOutput
11
- } from "./chunk-BSQV77YM.js";
11
+ } from "./chunk-JIWLKB5O.js";
12
12
 
13
13
  // src/test-runner.ts
14
14
  import fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",