dirac-lang 0.1.45 → 0.1.46

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-DIDPRJUP.js";
3
+ } from "./chunk-TXL3RV74.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -460,12 +460,12 @@ async function executeIf(session, element) {
460
460
  const condition = await evaluatePredicate(session, conditionElement);
461
461
  if (condition) {
462
462
  if (thenElement) {
463
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
463
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
464
464
  await integrateChildren2(session, thenElement);
465
465
  }
466
466
  } else {
467
467
  if (elseElement) {
468
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
468
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
469
469
  await integrateChildren2(session, elseElement);
470
470
  }
471
471
  }
@@ -478,7 +478,7 @@ async function evaluatePredicate(session, predicateElement) {
478
478
  return await evaluateCondition(session, predicateElement);
479
479
  }
480
480
  const outputLengthBefore = session.output.length;
481
- const { integrate: integrate2 } = await import("./interpreter-NAUTRIK2.js");
481
+ const { integrate: integrate2 } = await import("./interpreter-XH3RFKVP.js");
482
482
  await integrate2(session, predicateElement);
483
483
  const newOutputChunks = session.output.slice(outputLengthBefore);
484
484
  const result = newOutputChunks.join("").trim();
@@ -501,11 +501,11 @@ async function evaluateCondition(session, condElement) {
501
501
  }
502
502
  const outputLengthBefore = session.output.length;
503
503
  const args = [];
504
- const { integrate: integrate2 } = await import("./interpreter-NAUTRIK2.js");
504
+ const { integrate: integrate2 } = await import("./interpreter-XH3RFKVP.js");
505
505
  for (const child of condElement.children) {
506
506
  if (child.tag.toLowerCase() === "arg") {
507
507
  const argOutputStart = session.output.length;
508
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
508
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
509
509
  await integrateChildren2(session, child);
510
510
  const newChunks = session.output.slice(argOutputStart);
511
511
  const argValue = newChunks.join("");
@@ -564,6 +564,92 @@ function evaluateConditionType(evalType, args) {
564
564
  }
565
565
 
566
566
  // src/tags/llm.ts
567
+ import * as fs2 from "fs";
568
+ import * as path2 from "path";
569
+ import * as os from "os";
570
+ function dumpGeneratedSubroutines(session, diracCode, userPrompt) {
571
+ try {
572
+ let findSubroutines2 = function(element) {
573
+ if (element.tag === "subroutine") {
574
+ subroutines.push(element);
575
+ }
576
+ if (element.children) {
577
+ for (const child of element.children) {
578
+ findSubroutines2(child);
579
+ }
580
+ }
581
+ };
582
+ var findSubroutines = findSubroutines2;
583
+ const parser = new DiracParser();
584
+ const ast = parser.parse(diracCode);
585
+ const subroutines = [];
586
+ findSubroutines2(ast);
587
+ if (subroutines.length === 0) {
588
+ return;
589
+ }
590
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, -5);
591
+ const dumpDir = path2.join(os.homedir(), ".dirac", "lib", timestamp);
592
+ if (!fs2.existsSync(dumpDir)) {
593
+ fs2.mkdirSync(dumpDir, { recursive: true });
594
+ }
595
+ for (const sub of subroutines) {
596
+ const subName = sub.attributes.name || "unnamed";
597
+ const filePath = path2.join(dumpDir, `${subName}.di`);
598
+ const xml = serializeElement(sub, userPrompt);
599
+ fs2.writeFileSync(filePath, xml, "utf-8");
600
+ if (session.debug) {
601
+ console.error(`[LLM] Dumped subroutine '${subName}' to: ${filePath}`);
602
+ }
603
+ }
604
+ if (session.debug) {
605
+ console.error(`[LLM] Dumped ${subroutines.length} subroutine(s) to: ${dumpDir}`);
606
+ }
607
+ } catch (error) {
608
+ if (session.debug) {
609
+ console.error(`[LLM] Failed to dump subroutines: ${error}`);
610
+ }
611
+ }
612
+ }
613
+ function serializeElement(element, prompt) {
614
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
615
+ const lines = [];
616
+ lines.push("<!--");
617
+ lines.push(` Created: ${timestamp}`);
618
+ lines.push(` Generated by: LLM`);
619
+ lines.push(` Prompt: ${prompt.replace(/-->/g, "--&gt;")}`);
620
+ lines.push("-->");
621
+ lines.push("");
622
+ function serialize(el, indent = "") {
623
+ if (el.text && !el.tag) {
624
+ lines.push(indent + el.text);
625
+ return;
626
+ }
627
+ if (!el.tag) return;
628
+ let tag = `${indent}<${el.tag}`;
629
+ if (el.attributes) {
630
+ for (const [key, value] of Object.entries(el.attributes)) {
631
+ tag += ` ${key}="${value.replace(/"/g, "&quot;")}"`;
632
+ }
633
+ }
634
+ if (!el.children || el.children.length === 0) {
635
+ if (el.text) {
636
+ lines.push(tag + ">");
637
+ lines.push(indent + " " + el.text);
638
+ lines.push(`${indent}</${el.tag}>`);
639
+ } else {
640
+ lines.push(tag + " />");
641
+ }
642
+ } else {
643
+ lines.push(tag + ">");
644
+ for (const child of el.children) {
645
+ serialize(child, indent + " ");
646
+ }
647
+ lines.push(`${indent}</${el.tag}>`);
648
+ }
649
+ }
650
+ serialize(element);
651
+ return lines.join("\n");
652
+ }
567
653
  async function executeLLM(session, element) {
568
654
  if (!session.llmClient) {
569
655
  throw new Error("<llm> tag requires LLM configuration. Set LLM_PROVIDER (ollama/anthropic/openai/custom) and appropriate API keys in environment or config.yml");
@@ -888,6 +974,9 @@ ${validation.errorMessages.join("\n")}`);
888
974
  }
889
975
  }
890
976
  await integrate(session, dynamicAST);
977
+ if (iteration === 1) {
978
+ dumpGeneratedSubroutines(session, diracCode, userPrompt);
979
+ }
891
980
  if (feedbackMode) {
892
981
  const outputAfter = session.output.slice();
893
982
  const executionOutput = outputAfter.slice(outputBefore.length).join("");
@@ -996,11 +1085,11 @@ ${expr}
996
1085
  for (const v of session.variables) {
997
1086
  context[v.name] = v.value;
998
1087
  }
999
- const { default: fs5 } = await import("fs");
1000
- const { default: path3 } = await import("path");
1088
+ const { default: fs6 } = await import("fs");
1089
+ const { default: path4 } = await import("path");
1001
1090
  const { fileURLToPath } = await import("url");
1002
- context.fs = fs5;
1003
- context.path = path3;
1091
+ context.fs = fs6;
1092
+ context.path = path4;
1004
1093
  context.__dirname = process.cwd();
1005
1094
  context.getParams = () => {
1006
1095
  const params = session.parameterStack[session.parameterStack.length - 1];
@@ -1054,8 +1143,8 @@ ${diracCode}
1054
1143
  }
1055
1144
 
1056
1145
  // src/tags/import.ts
1057
- import { readFileSync, existsSync as existsSync2 } from "fs";
1058
- import { resolve, dirname as dirname2, join } from "path";
1146
+ import { readFileSync, existsSync as existsSync3 } from "fs";
1147
+ import { resolve, dirname as dirname2, join as join2 } from "path";
1059
1148
  function resolveImportPath(src, currentDir) {
1060
1149
  if (src.startsWith("./") || src.startsWith("../") || src.startsWith("/")) {
1061
1150
  const resolved2 = resolve(currentDir, src);
@@ -1063,26 +1152,26 @@ function resolveImportPath(src, currentDir) {
1063
1152
  }
1064
1153
  let searchDir = currentDir;
1065
1154
  while (true) {
1066
- const nodeModulesPath = join(searchDir, "node_modules", src);
1067
- if (existsSync2(nodeModulesPath)) {
1068
- const packageJsonPath = join(nodeModulesPath, "package.json");
1069
- if (existsSync2(packageJsonPath)) {
1155
+ const nodeModulesPath = join2(searchDir, "node_modules", src);
1156
+ if (existsSync3(nodeModulesPath)) {
1157
+ const packageJsonPath = join2(nodeModulesPath, "package.json");
1158
+ if (existsSync3(packageJsonPath)) {
1070
1159
  try {
1071
1160
  const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
1072
1161
  const mainFile = packageJson.main || "lib/index.di";
1073
- const entryPath = join(nodeModulesPath, mainFile);
1074
- if (existsSync2(entryPath)) {
1162
+ const entryPath = join2(nodeModulesPath, mainFile);
1163
+ if (existsSync3(entryPath)) {
1075
1164
  return entryPath;
1076
1165
  }
1077
1166
  } catch (err) {
1078
1167
  }
1079
1168
  }
1080
1169
  const fallbacks = [
1081
- join(nodeModulesPath, "lib", "index.di"),
1082
- join(nodeModulesPath, "index.di")
1170
+ join2(nodeModulesPath, "lib", "index.di"),
1171
+ join2(nodeModulesPath, "index.di")
1083
1172
  ];
1084
1173
  for (const fallback of fallbacks) {
1085
- if (existsSync2(fallback)) {
1174
+ if (existsSync3(fallback)) {
1086
1175
  return fallback;
1087
1176
  }
1088
1177
  }
@@ -1303,13 +1392,13 @@ async function executeRequireModule(session, element) {
1303
1392
  }
1304
1393
 
1305
1394
  // src/tags/tag-check.ts
1306
- import fs2 from "fs";
1395
+ import fs3 from "fs";
1307
1396
  import yaml from "js-yaml";
1308
1397
  var SIMILARITY_CUTOFF = 0.75;
1309
1398
  function getEmbeddingServerConfig() {
1310
1399
  try {
1311
1400
  const configPath = process.env.DIRAC_CONFIG || "config.yml";
1312
- const config = yaml.load(fs2.readFileSync(configPath, "utf8"));
1401
+ const config = yaml.load(fs3.readFileSync(configPath, "utf8"));
1313
1402
  const host = config.embeddingServer?.host || "localhost";
1314
1403
  const port = config.embeddingServer?.port || 11434;
1315
1404
  const model = config.embeddingServer?.model || "embeddinggemma";
@@ -1445,7 +1534,7 @@ async function executeTagCheck(session, element) {
1445
1534
  const executeTag = correctedTag || tagName;
1446
1535
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1447
1536
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1448
- const { integrate: integrate2 } = await import("./interpreter-NAUTRIK2.js");
1537
+ const { integrate: integrate2 } = await import("./interpreter-XH3RFKVP.js");
1449
1538
  await integrate2(session, elementToExecute);
1450
1539
  }
1451
1540
  }
@@ -1454,7 +1543,7 @@ async function executeTagCheck(session, element) {
1454
1543
  // src/tags/throw.ts
1455
1544
  async function executeThrow(session, element) {
1456
1545
  const exceptionName = element.attributes?.name || "exception";
1457
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
1546
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
1458
1547
  const exceptionDom = {
1459
1548
  tag: "exception-content",
1460
1549
  attributes: { name: exceptionName },
@@ -1467,7 +1556,7 @@ async function executeThrow(session, element) {
1467
1556
  // src/tags/try.ts
1468
1557
  async function executeTry(session, element) {
1469
1558
  setExceptionBoundary(session);
1470
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
1559
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
1471
1560
  await integrateChildren2(session, element);
1472
1561
  unsetExceptionBoundary(session);
1473
1562
  }
@@ -1477,7 +1566,7 @@ async function executeCatch(session, element) {
1477
1566
  const exceptionName = element.attributes?.name || "exception";
1478
1567
  const caughtCount = lookupException(session, exceptionName);
1479
1568
  if (caughtCount > 0) {
1480
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
1569
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
1481
1570
  await integrateChildren2(session, element);
1482
1571
  }
1483
1572
  flushCurrentException(session);
@@ -1486,7 +1575,7 @@ async function executeCatch(session, element) {
1486
1575
  // src/tags/exception.ts
1487
1576
  async function executeException(session, element) {
1488
1577
  const exceptions = getCurrentExceptions(session);
1489
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-NAUTRIK2.js");
1578
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-XH3RFKVP.js");
1490
1579
  for (const exceptionDom of exceptions) {
1491
1580
  await integrateChildren2(session, exceptionDom);
1492
1581
  }
@@ -1681,23 +1770,23 @@ function formatAsText(subroutines) {
1681
1770
  }
1682
1771
 
1683
1772
  // src/runtime/subroutine-registry.ts
1684
- import * as fs3 from "fs";
1685
- import * as path2 from "path";
1686
- import * as os from "os";
1773
+ import * as fs4 from "fs";
1774
+ import * as path3 from "path";
1775
+ import * as os2 from "os";
1687
1776
  var SubroutineRegistry = class {
1688
1777
  indexPath;
1689
1778
  index;
1690
1779
  constructor(indexPath) {
1691
- this.indexPath = indexPath || path2.join(os.homedir(), ".dirac", "subroutine-index.json");
1780
+ this.indexPath = indexPath || path3.join(os2.homedir(), ".dirac", "subroutine-index.json");
1692
1781
  this.index = this.loadIndex();
1693
1782
  }
1694
1783
  /**
1695
1784
  * Load index from disk
1696
1785
  */
1697
1786
  loadIndex() {
1698
- if (fs3.existsSync(this.indexPath)) {
1787
+ if (fs4.existsSync(this.indexPath)) {
1699
1788
  try {
1700
- const data = fs3.readFileSync(this.indexPath, "utf-8");
1789
+ const data = fs4.readFileSync(this.indexPath, "utf-8");
1701
1790
  return JSON.parse(data);
1702
1791
  } catch (err) {
1703
1792
  console.error("Error loading subroutine index:", err);
@@ -1712,12 +1801,12 @@ var SubroutineRegistry = class {
1712
1801
  * Save index to disk
1713
1802
  */
1714
1803
  saveIndex() {
1715
- const dir = path2.dirname(this.indexPath);
1716
- if (!fs3.existsSync(dir)) {
1717
- fs3.mkdirSync(dir, { recursive: true });
1804
+ const dir = path3.dirname(this.indexPath);
1805
+ if (!fs4.existsSync(dir)) {
1806
+ fs4.mkdirSync(dir, { recursive: true });
1718
1807
  }
1719
1808
  this.index.lastUpdated = Date.now();
1720
- fs3.writeFileSync(this.indexPath, JSON.stringify(this.index, null, 2), "utf-8");
1809
+ fs4.writeFileSync(this.indexPath, JSON.stringify(this.index, null, 2), "utf-8");
1721
1810
  }
1722
1811
  /**
1723
1812
  * Scan a directory for .di files and index all subroutines
@@ -1725,9 +1814,9 @@ var SubroutineRegistry = class {
1725
1814
  async indexDirectory(dirPath) {
1726
1815
  let count = 0;
1727
1816
  const scanDir = (dir) => {
1728
- const entries = fs3.readdirSync(dir, { withFileTypes: true });
1817
+ const entries = fs4.readdirSync(dir, { withFileTypes: true });
1729
1818
  for (const entry of entries) {
1730
- const fullPath = path2.join(dir, entry.name);
1819
+ const fullPath = path3.join(dir, entry.name);
1731
1820
  if (entry.isDirectory()) {
1732
1821
  scanDir(fullPath);
1733
1822
  } else if (entry.isFile() && entry.name.endsWith(".di")) {
@@ -1744,7 +1833,7 @@ var SubroutineRegistry = class {
1744
1833
  */
1745
1834
  indexFile(filePath) {
1746
1835
  try {
1747
- const content = fs3.readFileSync(filePath, "utf-8");
1836
+ const content = fs4.readFileSync(filePath, "utf-8");
1748
1837
  const parser = new DiracParser();
1749
1838
  const ast = parser.parse(content);
1750
1839
  this.index.subroutines = this.index.subroutines.filter((s) => s.filePath !== filePath);
@@ -1949,7 +2038,7 @@ async function executeLoadContext(session, element) {
1949
2038
  query = element.text.trim();
1950
2039
  }
1951
2040
  if (!query && element.children.length > 0) {
1952
- const { integrate: integrate2 } = await import("./interpreter-NAUTRIK2.js");
2041
+ const { integrate: integrate2 } = await import("./interpreter-XH3RFKVP.js");
1953
2042
  const beforeOutput = session.output.length;
1954
2043
  for (const child of element.children) {
1955
2044
  await integrate2(session, child);
@@ -2024,18 +2113,17 @@ async function executeLoadContext(session, element) {
2024
2113
  }
2025
2114
 
2026
2115
  // src/tags/save-subroutine.ts
2027
- import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync3 } from "fs";
2028
- import { resolve as resolve2, dirname as dirname4 } from "path";
2116
+ import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync4, existsSync as existsSync5 } from "fs";
2117
+ import { resolve as resolve2, dirname as dirname4, join as join4 } from "path";
2118
+ import { homedir as homedir3 } from "os";
2029
2119
  async function executeSaveSubroutine(session, element) {
2030
2120
  const name = element.attributes.name;
2031
2121
  const file = element.attributes.file;
2122
+ const pathAttr = element.attributes.path;
2032
2123
  const format = element.attributes.format || "xml";
2033
2124
  if (!name) {
2034
2125
  throw new Error("<save-subroutine> requires name attribute");
2035
2126
  }
2036
- if (!file) {
2037
- throw new Error("<save-subroutine> requires file attribute");
2038
- }
2039
2127
  let subroutine = void 0;
2040
2128
  for (let i = session.subroutines.length - 1; i >= 0; i--) {
2041
2129
  if (session.subroutines[i].name === name) {
@@ -2052,12 +2140,27 @@ async function executeSaveSubroutine(session, element) {
2052
2140
  } else {
2053
2141
  content = generateXMLNotation(subroutine);
2054
2142
  }
2055
- const filePath = resolve2(process.cwd(), file);
2143
+ let filePath;
2144
+ if (file) {
2145
+ filePath = resolve2(process.cwd(), file);
2146
+ } else if (pathAttr) {
2147
+ const targetDir = join4(homedir3(), ".dirac", "lib", pathAttr);
2148
+ filePath = join4(targetDir, `${name}.di`);
2149
+ } else {
2150
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, -5);
2151
+ const defaultDir = join4(homedir3(), ".dirac", "lib", timestamp);
2152
+ filePath = join4(defaultDir, `${name}.di`);
2153
+ }
2056
2154
  const dir = dirname4(filePath);
2057
- mkdirSync3(dir, { recursive: true });
2058
- writeFileSync2(filePath, content, "utf-8");
2155
+ if (!existsSync5(dir)) {
2156
+ mkdirSync4(dir, { recursive: true });
2157
+ }
2158
+ writeFileSync3(filePath, content, "utf-8");
2059
2159
  emit(session, `Subroutine '${name}' saved to: ${filePath}
2060
2160
  `);
2161
+ if (session.debug) {
2162
+ console.error(`[save-subroutine] Saved '${name}' to: ${filePath}`);
2163
+ }
2061
2164
  }
2062
2165
  function generateXMLNotation(subroutine) {
2063
2166
  let xml = "<!-- Exported subroutine -->\n\n";
@@ -2188,7 +2291,7 @@ async function executeForeach(session, element) {
2188
2291
  const parser2 = new DiracParser2();
2189
2292
  try {
2190
2293
  const fromElement = parser2.parse(fromAttr);
2191
- const { integrate: integrate2 } = await import("./interpreter-NAUTRIK2.js");
2294
+ const { integrate: integrate2 } = await import("./interpreter-XH3RFKVP.js");
2192
2295
  await integrate2(session, fromElement);
2193
2296
  } catch (e) {
2194
2297
  session.output = savedOutput;
@@ -2336,7 +2439,7 @@ async function executeEnvironment(session, element) {
2336
2439
  }
2337
2440
 
2338
2441
  // src/tags/input.ts
2339
- import * as fs4 from "fs";
2442
+ import * as fs5 from "fs";
2340
2443
  import * as readline from "readline";
2341
2444
  var fileReaders = /* @__PURE__ */ new Map();
2342
2445
  var fileIterators = /* @__PURE__ */ new Map();
@@ -2360,11 +2463,11 @@ async function executeInput(session, element) {
2360
2463
  throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
2361
2464
  }
2362
2465
  } else if (source === "file") {
2363
- const path3 = substituteAttribute(session, pathAttr);
2466
+ const path4 = substituteAttribute(session, pathAttr);
2364
2467
  if (mode === "all") {
2365
- value = fs4.readFileSync(path3, "utf-8");
2468
+ value = fs5.readFileSync(path4, "utf-8");
2366
2469
  } else if (mode === "line") {
2367
- value = await readLineFromFile(path3);
2470
+ value = await readLineFromFile(path4);
2368
2471
  } else {
2369
2472
  throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
2370
2473
  }
@@ -2421,23 +2524,23 @@ async function readLineStdin() {
2421
2524
  }
2422
2525
  return result.value;
2423
2526
  }
2424
- async function readLineFromFile(path3) {
2425
- if (!fileReaders.has(path3)) {
2426
- const fileStream = fs4.createReadStream(path3);
2527
+ async function readLineFromFile(path4) {
2528
+ if (!fileReaders.has(path4)) {
2529
+ const fileStream = fs5.createReadStream(path4);
2427
2530
  const rl = readline.createInterface({
2428
2531
  input: fileStream,
2429
2532
  crlfDelay: Infinity
2430
2533
  });
2431
- fileReaders.set(path3, rl);
2432
- fileIterators.set(path3, rl[Symbol.asyncIterator]());
2534
+ fileReaders.set(path4, rl);
2535
+ fileIterators.set(path4, rl[Symbol.asyncIterator]());
2433
2536
  }
2434
- const iterator = fileIterators.get(path3);
2537
+ const iterator = fileIterators.get(path4);
2435
2538
  const result = await iterator.next();
2436
2539
  if (result.done) {
2437
- const reader = fileReaders.get(path3);
2540
+ const reader = fileReaders.get(path4);
2438
2541
  reader.close();
2439
- fileReaders.delete(path3);
2440
- fileIterators.delete(path3);
2542
+ fileReaders.delete(path4);
2543
+ fileIterators.delete(path4);
2441
2544
  return "";
2442
2545
  }
2443
2546
  return result.value;
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-ZKJVGWKK.js";
8
- import "./chunk-DIDPRJUP.js";
7
+ } from "./chunk-TISVDOGD.js";
8
+ import "./chunk-TXL3RV74.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.45",
19
+ version: "0.1.46",
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-LMUSTGDX.js");
99
+ const { DiracShell } = await import("./shell-LGNPK4GO.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-ZKJVGWKK.js";
5
+ } from "./chunk-TISVDOGD.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-DIDPRJUP.js";
8
+ } from "./chunk-TXL3RV74.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-DIDPRJUP.js";
4
+ } from "./chunk-TXL3RV74.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
6
  import "./chunk-4QLTSCDG.js";
7
7
  import "./chunk-GLXVY235.js";
@@ -3,7 +3,7 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-DIDPRJUP.js";
6
+ } from "./chunk-TXL3RV74.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-4QLTSCDG.js";
9
9
  import "./chunk-GLXVY235.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-UEFKQRYN.js";
5
5
  import {
6
6
  integrate
7
- } from "./chunk-DIDPRJUP.js";
7
+ } from "./chunk-TXL3RV74.js";
8
8
  import {
9
9
  DiracParser
10
10
  } from "./chunk-HRHAMPOB.js";
@@ -66,7 +66,7 @@ var DiracShell = class {
66
66
  });
67
67
  this.rl.on("close", () => {
68
68
  this.saveHistory();
69
- import("./schedule-WPGXPI26.js").then(({ stopAllScheduledTasks }) => {
69
+ import("./schedule-5HZCREEP.js").then(({ stopAllScheduledTasks }) => {
70
70
  stopAllScheduledTasks();
71
71
  console.log("\nGoodbye!");
72
72
  process.exit(0);
@@ -195,7 +195,7 @@ Commands:
195
195
  :index <path> Index subroutines from directory
196
196
  :search <query> Search indexed subroutines
197
197
  :load <query> Load context (search and import subroutines)
198
- :save <name> <file> Save subroutine to file
198
+ :save <name> [file] Save subroutine (default: ~/.dirac/lib/TIMESTAMP/name.di)
199
199
  :stats Show registry statistics
200
200
  :tasks List all scheduled tasks
201
201
  :stop <name> Stop a scheduled task
@@ -335,13 +335,27 @@ Examples:
335
335
  }
336
336
  break;
337
337
  case "save":
338
- if (args.length < 2) {
339
- console.log("Usage: :save <subroutine-name> <file>");
338
+ if (args.length === 0) {
339
+ console.log("Usage: :save <subroutine-name> [file]");
340
+ console.log(" If file is omitted, saves to ~/.dirac/lib/TIMESTAMP/NAME.di");
341
+ console.log("Examples:");
342
+ console.log(" :save greet # saves to ~/.dirac/lib/TIMESTAMP/greet.di");
343
+ console.log(" :save greet ./my-lib/greet.di # saves to specific file");
344
+ console.log(" :save greet utils # saves to ~/.dirac/lib/utils/greet.di");
340
345
  } else {
341
346
  const subName = args[0];
342
- const fileName = args[1];
347
+ const fileName = args.length > 1 ? args[1] : void 0;
343
348
  try {
344
- const xml = `<save-subroutine name="${subName}" file="${fileName}" format="xml" />`;
349
+ let xml;
350
+ if (fileName) {
351
+ if (fileName.includes("/") || fileName.includes(".di")) {
352
+ xml = `<save-subroutine name="${subName}" file="${fileName}" format="xml" />`;
353
+ } else {
354
+ xml = `<save-subroutine name="${subName}" path="${fileName}" format="xml" />`;
355
+ }
356
+ } else {
357
+ xml = `<save-subroutine name="${subName}" format="xml" />`;
358
+ }
345
359
  const ast = this.xmlParser.parse(xml);
346
360
  await integrate(this.session, ast);
347
361
  if (this.session.output.length > 0) {
@@ -366,7 +380,7 @@ Examples:
366
380
  break;
367
381
  case "tasks":
368
382
  try {
369
- const { listScheduledTasks } = await import("./schedule-WPGXPI26.js");
383
+ const { listScheduledTasks } = await import("./schedule-5HZCREEP.js");
370
384
  const tasks = listScheduledTasks();
371
385
  if (tasks.length === 0) {
372
386
  console.log("No scheduled tasks running.");
@@ -385,7 +399,7 @@ Examples:
385
399
  console.log("Usage: :stop <task-name>");
386
400
  } else {
387
401
  try {
388
- const { stopScheduledTask } = await import("./schedule-WPGXPI26.js");
402
+ const { stopScheduledTask } = await import("./schedule-5HZCREEP.js");
389
403
  const taskName = args[0];
390
404
  const stopped = stopScheduledTask(taskName);
391
405
  if (stopped) {
@@ -400,7 +414,7 @@ Examples:
400
414
  break;
401
415
  case "stopall":
402
416
  try {
403
- const { stopAllScheduledTasks } = await import("./schedule-WPGXPI26.js");
417
+ const { stopAllScheduledTasks } = await import("./schedule-5HZCREEP.js");
404
418
  stopAllScheduledTasks();
405
419
  console.log("All scheduled tasks stopped.");
406
420
  } catch (error) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-DIDPRJUP.js";
3
+ } from "./chunk-TXL3RV74.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.45",
3
+ "version": "0.1.46",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",