dirac-lang 0.1.39 → 0.1.41

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.
@@ -448,12 +448,12 @@ async function executeIf(session, element) {
448
448
  const condition = await evaluatePredicate(session, conditionElement);
449
449
  if (condition) {
450
450
  if (thenElement) {
451
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
451
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
452
452
  await integrateChildren2(session, thenElement);
453
453
  }
454
454
  } else {
455
455
  if (elseElement) {
456
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
456
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
457
457
  await integrateChildren2(session, elseElement);
458
458
  }
459
459
  }
@@ -466,7 +466,7 @@ async function evaluatePredicate(session, predicateElement) {
466
466
  return await evaluateCondition(session, predicateElement);
467
467
  }
468
468
  const outputLengthBefore = session.output.length;
469
- const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
469
+ const { integrate: integrate2 } = await import("./interpreter-ZG23OYGG.js");
470
470
  await integrate2(session, predicateElement);
471
471
  const newOutputChunks = session.output.slice(outputLengthBefore);
472
472
  const result = newOutputChunks.join("").trim();
@@ -489,11 +489,11 @@ async function evaluateCondition(session, condElement) {
489
489
  }
490
490
  const outputLengthBefore = session.output.length;
491
491
  const args = [];
492
- const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
492
+ const { integrate: integrate2 } = await import("./interpreter-ZG23OYGG.js");
493
493
  for (const child of condElement.children) {
494
494
  if (child.tag.toLowerCase() === "arg") {
495
495
  const argOutputStart = session.output.length;
496
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
496
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
497
497
  await integrateChildren2(session, child);
498
498
  const newChunks = session.output.slice(argOutputStart);
499
499
  const argValue = newChunks.join("");
@@ -1378,7 +1378,7 @@ async function executeTagCheck(session, element) {
1378
1378
  const executeTag = correctedTag || tagName;
1379
1379
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1380
1380
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1381
- const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
1381
+ const { integrate: integrate2 } = await import("./interpreter-ZG23OYGG.js");
1382
1382
  await integrate2(session, elementToExecute);
1383
1383
  }
1384
1384
  }
@@ -1387,7 +1387,7 @@ async function executeTagCheck(session, element) {
1387
1387
  // src/tags/throw.ts
1388
1388
  async function executeThrow(session, element) {
1389
1389
  const exceptionName = element.attributes?.name || "exception";
1390
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
1390
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
1391
1391
  const exceptionDom = {
1392
1392
  tag: "exception-content",
1393
1393
  attributes: { name: exceptionName },
@@ -1400,7 +1400,7 @@ async function executeThrow(session, element) {
1400
1400
  // src/tags/try.ts
1401
1401
  async function executeTry(session, element) {
1402
1402
  setExceptionBoundary(session);
1403
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
1403
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
1404
1404
  await integrateChildren2(session, element);
1405
1405
  unsetExceptionBoundary(session);
1406
1406
  }
@@ -1410,7 +1410,7 @@ async function executeCatch(session, element) {
1410
1410
  const exceptionName = element.attributes?.name || "exception";
1411
1411
  const caughtCount = lookupException(session, exceptionName);
1412
1412
  if (caughtCount > 0) {
1413
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
1413
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
1414
1414
  await integrateChildren2(session, element);
1415
1415
  }
1416
1416
  flushCurrentException(session);
@@ -1419,7 +1419,7 @@ async function executeCatch(session, element) {
1419
1419
  // src/tags/exception.ts
1420
1420
  async function executeException(session, element) {
1421
1421
  const exceptions = getCurrentExceptions(session);
1422
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
1422
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-ZG23OYGG.js");
1423
1423
  for (const exceptionDom of exceptions) {
1424
1424
  await integrateChildren2(session, exceptionDom);
1425
1425
  }
@@ -1882,7 +1882,7 @@ async function executeLoadContext(session, element) {
1882
1882
  query = element.text.trim();
1883
1883
  }
1884
1884
  if (!query && element.children.length > 0) {
1885
- const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
1885
+ const { integrate: integrate2 } = await import("./interpreter-ZG23OYGG.js");
1886
1886
  const beforeOutput = session.output.length;
1887
1887
  for (const child of element.children) {
1888
1888
  await integrate2(session, child);
@@ -1924,8 +1924,8 @@ async function executeLoadContext(session, element) {
1924
1924
  if (shouldImport) {
1925
1925
  for (const filePath of fileMap.keys()) {
1926
1926
  try {
1927
- const { resolve: resolve2 } = await import("path");
1928
- const absolutePath = filePath.startsWith("/") ? filePath : resolve2(process.cwd(), filePath);
1927
+ const { resolve: resolve3 } = await import("path");
1928
+ const absolutePath = filePath.startsWith("/") ? filePath : resolve3(process.cwd(), filePath);
1929
1929
  const importElement = {
1930
1930
  tag: "import",
1931
1931
  attributes: { src: absolutePath },
@@ -1956,6 +1956,151 @@ async function executeLoadContext(session, element) {
1956
1956
  }
1957
1957
  }
1958
1958
 
1959
+ // src/tags/save-subroutine.ts
1960
+ import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync3 } from "fs";
1961
+ import { resolve as resolve2, dirname as dirname4 } from "path";
1962
+ async function executeSaveSubroutine(session, element) {
1963
+ const name = element.attributes.name;
1964
+ const file = element.attributes.file;
1965
+ const format = element.attributes.format || "xml";
1966
+ if (!name) {
1967
+ throw new Error("<save-subroutine> requires name attribute");
1968
+ }
1969
+ if (!file) {
1970
+ throw new Error("<save-subroutine> requires file attribute");
1971
+ }
1972
+ let subroutine = void 0;
1973
+ for (let i = session.subroutines.length - 1; i >= 0; i--) {
1974
+ if (session.subroutines[i].name === name) {
1975
+ subroutine = session.subroutines[i];
1976
+ break;
1977
+ }
1978
+ }
1979
+ if (!subroutine) {
1980
+ throw new Error(`Subroutine '${name}' not found in session`);
1981
+ }
1982
+ let content;
1983
+ if (format === "braket") {
1984
+ content = generateBraKetNotation(subroutine);
1985
+ } else {
1986
+ content = generateXMLNotation(subroutine);
1987
+ }
1988
+ const filePath = resolve2(process.cwd(), file);
1989
+ const dir = dirname4(filePath);
1990
+ mkdirSync3(dir, { recursive: true });
1991
+ writeFileSync2(filePath, content, "utf-8");
1992
+ emit(session, `Subroutine '${name}' saved to: ${filePath}
1993
+ `);
1994
+ }
1995
+ function generateXMLNotation(subroutine) {
1996
+ let xml = "<!-- Exported subroutine -->\n\n";
1997
+ xml += `<subroutine name="${subroutine.name}"`;
1998
+ if (subroutine.description) {
1999
+ xml += `
2000
+ description="${escapeXml3(subroutine.description)}"`;
2001
+ }
2002
+ if (subroutine.parameters && subroutine.parameters.length > 0) {
2003
+ for (const param of subroutine.parameters) {
2004
+ xml += `
2005
+ param-${param.name}="${param.type || "any"}`;
2006
+ if (param.required) {
2007
+ xml += ":required";
2008
+ }
2009
+ if (param.description) {
2010
+ xml += `:${escapeXml3(param.description)}`;
2011
+ }
2012
+ xml += '"';
2013
+ }
2014
+ }
2015
+ xml += ">\n";
2016
+ if (subroutine.element && subroutine.element.children && subroutine.element.children.length > 0) {
2017
+ xml += serializeChildren(subroutine.element.children, 2);
2018
+ } else {
2019
+ xml += " <!-- Subroutine body not available -->\n";
2020
+ }
2021
+ xml += "</subroutine>\n";
2022
+ return xml;
2023
+ }
2024
+ function generateBraKetNotation(subroutine) {
2025
+ let braket = "";
2026
+ braket += `<${subroutine.name}|`;
2027
+ if (subroutine.description) {
2028
+ braket += ` description="${escapeXml3(subroutine.description)}"`;
2029
+ }
2030
+ if (subroutine.parameters && subroutine.parameters.length > 0) {
2031
+ for (const param of subroutine.parameters) {
2032
+ braket += ` ${param.name}=${param.type || "any"}`;
2033
+ }
2034
+ }
2035
+ braket += "\n";
2036
+ if (subroutine.element && subroutine.element.children) {
2037
+ braket += serializeChildrenBraKet(subroutine.element.children, 2);
2038
+ } else if (subroutine.body) {
2039
+ braket += ` ${subroutine.body}
2040
+ `;
2041
+ } else {
2042
+ braket += " # Subroutine body not available\n";
2043
+ }
2044
+ return braket;
2045
+ }
2046
+ function serializeChildren(children, indent) {
2047
+ let xml = "";
2048
+ const indentStr = " ".repeat(indent);
2049
+ for (const child of children) {
2050
+ if (child.text && !child.tag) {
2051
+ xml += indentStr + escapeXml3(child.text) + "\n";
2052
+ } else if (child.tag) {
2053
+ xml += indentStr + `<${child.tag}`;
2054
+ if (child.attributes) {
2055
+ for (const [key, value] of Object.entries(child.attributes)) {
2056
+ xml += ` ${key}="${escapeXml3(String(value))}"`;
2057
+ }
2058
+ }
2059
+ if (child.children && child.children.length > 0) {
2060
+ xml += ">\n";
2061
+ xml += serializeChildren(child.children, indent + 2);
2062
+ xml += indentStr + `</${child.tag}>
2063
+ `;
2064
+ } else if (child.text) {
2065
+ xml += `>${escapeXml3(child.text)}</${child.tag}>
2066
+ `;
2067
+ } else {
2068
+ xml += " />\n";
2069
+ }
2070
+ }
2071
+ }
2072
+ return xml;
2073
+ }
2074
+ function serializeChildrenBraKet(children, indent) {
2075
+ let braket = "";
2076
+ const indentStr = " ".repeat(indent);
2077
+ for (const child of children) {
2078
+ if (child.text && !child.tag) {
2079
+ braket += indentStr + child.text + "\n";
2080
+ } else if (child.tag) {
2081
+ braket += indentStr + `|${child.tag}`;
2082
+ if (child.attributes) {
2083
+ for (const [key, value] of Object.entries(child.attributes)) {
2084
+ braket += ` ${key}="${escapeXml3(String(value))}"`;
2085
+ }
2086
+ }
2087
+ if (child.text) {
2088
+ braket += `>${child.text}
2089
+ `;
2090
+ } else if (child.children && child.children.length > 0) {
2091
+ braket += ">\n";
2092
+ braket += serializeChildrenBraKet(child.children, indent + 2);
2093
+ } else {
2094
+ braket += ">\n";
2095
+ }
2096
+ }
2097
+ }
2098
+ return braket;
2099
+ }
2100
+ function escapeXml3(text) {
2101
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
2102
+ }
2103
+
1959
2104
  // src/tags/foreach.ts
1960
2105
  import { XMLParser } from "fast-xml-parser";
1961
2106
  async function executeForeach(session, element) {
@@ -1976,7 +2121,7 @@ async function executeForeach(session, element) {
1976
2121
  const parser2 = new DiracParser2();
1977
2122
  try {
1978
2123
  const fromElement = parser2.parse(fromAttr);
1979
- const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
2124
+ const { integrate: integrate2 } = await import("./interpreter-ZG23OYGG.js");
1980
2125
  await integrate2(session, fromElement);
1981
2126
  } catch (e) {
1982
2127
  session.output = savedOutput;
@@ -2165,7 +2310,7 @@ async function readAllStdin() {
2165
2310
  process.stdin.removeAllListeners("data");
2166
2311
  process.stdin.removeAllListeners("end");
2167
2312
  process.stdin.removeAllListeners("error");
2168
- return new Promise((resolve2, reject) => {
2313
+ return new Promise((resolve3, reject) => {
2169
2314
  const chunks = [];
2170
2315
  const onData = (chunk) => {
2171
2316
  chunks.push(chunk);
@@ -2175,7 +2320,7 @@ async function readAllStdin() {
2175
2320
  process.stdin.removeListener("data", onData);
2176
2321
  process.stdin.removeListener("end", onEnd);
2177
2322
  process.stdin.removeListener("error", onError);
2178
- resolve2(result);
2323
+ resolve3(result);
2179
2324
  };
2180
2325
  const onError = (err) => {
2181
2326
  process.stdin.removeListener("data", onData);
@@ -2335,6 +2480,9 @@ async function integrate(session, element) {
2335
2480
  case "load-context":
2336
2481
  await executeLoadContext(session, element);
2337
2482
  break;
2483
+ case "save-subroutine":
2484
+ await executeSaveSubroutine(session, element);
2485
+ break;
2338
2486
  case "foreach":
2339
2487
  await executeForeach(session, element);
2340
2488
  break;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-NWGHO23V.js";
3
+ } from "./chunk-3DUTURSM.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  } from "./chunk-UEFKQRYN.js";
5
5
  import {
6
6
  execute
7
- } from "./chunk-W6BEEC5D.js";
8
- import "./chunk-NWGHO23V.js";
7
+ } from "./chunk-G2XVIAV5.js";
8
+ import "./chunk-3DUTURSM.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
10
  import "./chunk-4QLTSCDG.js";
11
11
  import "./chunk-GLXVY235.js";
@@ -16,7 +16,7 @@ import "dotenv/config";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "dirac-lang",
19
- version: "0.1.38",
19
+ version: "0.1.40",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
@@ -96,7 +96,7 @@ async function main() {
96
96
  process.exit(0);
97
97
  }
98
98
  if (args[0] === "shell") {
99
- const { DiracShell } = await import("./shell-T5G3PTPT.js");
99
+ const { DiracShell } = await import("./shell-Z7QXHZYV.js");
100
100
  const shellConfig = { debug: false };
101
101
  for (let i = 1; i < args.length; i++) {
102
102
  const arg = args[i];
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-W6BEEC5D.js";
5
+ } from "./chunk-G2XVIAV5.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-NWGHO23V.js";
8
+ } from "./chunk-3DUTURSM.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-NWGHO23V.js";
4
+ } from "./chunk-3DUTURSM.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
6
  import "./chunk-4QLTSCDG.js";
7
7
  import "./chunk-GLXVY235.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-UEFKQRYN.js";
5
5
  import {
6
6
  integrate
7
- } from "./chunk-NWGHO23V.js";
7
+ } from "./chunk-3DUTURSM.js";
8
8
  import {
9
9
  DiracParser
10
10
  } from "./chunk-HRHAMPOB.js";
@@ -185,9 +185,11 @@ Commands:
185
185
  :clear Clear session (reset variables and subroutines)
186
186
  :debug Toggle debug mode
187
187
  :config Show current configuration
188
+ :reload Reload config.yml and reinitialize LLM
188
189
  :index <path> Index subroutines from directory
189
190
  :search <query> Search indexed subroutines
190
191
  :load <query> Load context (search and import subroutines)
192
+ :save <name> <file> Save subroutine to file
191
193
  :stats Show registry statistics
192
194
  :exit Exit shell
193
195
 
@@ -259,6 +261,19 @@ Examples:
259
261
  console.log(` Custom LLM URL: ${this.config.customLLMUrl}`);
260
262
  }
261
263
  break;
264
+ case "reload":
265
+ try {
266
+ await this.reloadConfig();
267
+ console.log("Configuration reloaded successfully");
268
+ console.log(` LLM Provider: ${this.config.llmProvider || "none"}`);
269
+ console.log(` LLM Model: ${this.config.llmModel || "default"}`);
270
+ if (this.config.customLLMUrl) {
271
+ console.log(` Custom LLM URL: ${this.config.customLLMUrl}`);
272
+ }
273
+ } catch (error) {
274
+ console.error("Error reloading config:", error instanceof Error ? error.message : String(error));
275
+ }
276
+ break;
262
277
  case "index":
263
278
  if (args.length === 0) {
264
279
  console.log("Usage: :index <path>");
@@ -310,6 +325,24 @@ Examples:
310
325
  }
311
326
  }
312
327
  break;
328
+ case "save":
329
+ if (args.length < 2) {
330
+ console.log("Usage: :save <subroutine-name> <file>");
331
+ } else {
332
+ const subName = args[0];
333
+ const fileName = args[1];
334
+ try {
335
+ const xml = `<save-subroutine name="${subName}" file="${fileName}" format="xml" />`;
336
+ const ast = this.xmlParser.parse(xml);
337
+ await integrate(this.session, ast);
338
+ if (this.session.output.length > 0) {
339
+ console.log(this.session.output.join(""));
340
+ }
341
+ } catch (error) {
342
+ console.error("Error saving subroutine:", error instanceof Error ? error.message : String(error));
343
+ }
344
+ }
345
+ break;
313
346
  case "stats":
314
347
  try {
315
348
  const xml = "<registry-stats />";
@@ -368,7 +401,7 @@ Examples:
368
401
  }
369
402
  const { spawn } = await import("child_process");
370
403
  this.rl.pause();
371
- return new Promise((resolve) => {
404
+ return new Promise((resolve2) => {
372
405
  const shell = process.env.SHELL || "/bin/sh";
373
406
  const child = spawn(shell, ["-c", command], {
374
407
  stdio: "inherit",
@@ -376,12 +409,12 @@ Examples:
376
409
  });
377
410
  child.on("close", () => {
378
411
  this.rl.resume();
379
- resolve();
412
+ resolve2();
380
413
  });
381
414
  child.on("error", (err) => {
382
415
  console.error(`Shell error: ${err.message}`);
383
416
  this.rl.resume();
384
- resolve();
417
+ resolve2();
385
418
  });
386
419
  });
387
420
  }
@@ -419,6 +452,26 @@ Examples:
419
452
  `);
420
453
  }
421
454
  }
455
+ /**
456
+ * Reload configuration from config.yml
457
+ */
458
+ async reloadConfig() {
459
+ const configPath = path.resolve(process.cwd(), "config.yml");
460
+ if (!fs.existsSync(configPath)) {
461
+ throw new Error("config.yml not found in current directory");
462
+ }
463
+ const configData = yaml.load(fs.readFileSync(configPath, "utf-8"));
464
+ this.config.llmProvider = configData.llmProvider || process.env.LLM_PROVIDER;
465
+ this.config.llmModel = configData.llmModel || process.env.LLM_MODEL;
466
+ this.config.customLLMUrl = configData.customLLMUrl || process.env.CUSTOM_LLM_URL;
467
+ const oldVariables = this.session.variables;
468
+ const oldSubroutines = this.session.subroutines;
469
+ const oldImportedFiles = this.session.importedFiles;
470
+ this.session = createSession(this.config);
471
+ this.session.variables = oldVariables;
472
+ this.session.subroutines = oldSubroutines;
473
+ this.session.importedFiles = oldImportedFiles;
474
+ }
422
475
  };
423
476
  async function main() {
424
477
  let config = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-NWGHO23V.js";
3
+ } from "./chunk-3DUTURSM.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",