dirac-lang 0.1.45 → 0.1.47
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-ZKJVGWKK.js → chunk-TISVDOGD.js} +1 -1
- package/dist/{chunk-DIDPRJUP.js → chunk-TXL3RV74.js} +166 -63
- package/dist/cli.js +4 -4
- package/dist/index.js +2 -2
- package/dist/{interpreter-NAUTRIK2.js → interpreter-XH3RFKVP.js} +1 -1
- package/dist/{schedule-WPGXPI26.js → schedule-5HZCREEP.js} +1 -1
- package/dist/{shell-LMUSTGDX.js → shell-TNQMOYFR.js} +47 -11
- package/dist/test-runner.js +1 -1
- package/package.json +1 -1
|
@@ -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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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, "-->")}`);
|
|
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, """)}"`;
|
|
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:
|
|
1000
|
-
const { default:
|
|
1088
|
+
const { default: fs6 } = await import("fs");
|
|
1089
|
+
const { default: path4 } = await import("path");
|
|
1001
1090
|
const { fileURLToPath } = await import("url");
|
|
1002
|
-
context.fs =
|
|
1003
|
-
context.path =
|
|
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
|
|
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 =
|
|
1067
|
-
if (
|
|
1068
|
-
const packageJsonPath =
|
|
1069
|
-
if (
|
|
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 =
|
|
1074
|
-
if (
|
|
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
|
-
|
|
1082
|
-
|
|
1170
|
+
join2(nodeModulesPath, "lib", "index.di"),
|
|
1171
|
+
join2(nodeModulesPath, "index.di")
|
|
1083
1172
|
];
|
|
1084
1173
|
for (const fallback of fallbacks) {
|
|
1085
|
-
if (
|
|
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
|
|
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(
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
|
1685
|
-
import * as
|
|
1686
|
-
import * as
|
|
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 ||
|
|
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 (
|
|
1787
|
+
if (fs4.existsSync(this.indexPath)) {
|
|
1699
1788
|
try {
|
|
1700
|
-
const data =
|
|
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 =
|
|
1716
|
-
if (!
|
|
1717
|
-
|
|
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
|
-
|
|
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 =
|
|
1817
|
+
const entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
1729
1818
|
for (const entry of entries) {
|
|
1730
|
-
const fullPath =
|
|
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 =
|
|
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-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
2058
|
-
|
|
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-
|
|
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
|
|
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
|
|
2466
|
+
const path4 = substituteAttribute(session, pathAttr);
|
|
2364
2467
|
if (mode === "all") {
|
|
2365
|
-
value =
|
|
2468
|
+
value = fs5.readFileSync(path4, "utf-8");
|
|
2366
2469
|
} else if (mode === "line") {
|
|
2367
|
-
value = await readLineFromFile(
|
|
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(
|
|
2425
|
-
if (!fileReaders.has(
|
|
2426
|
-
const fileStream =
|
|
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(
|
|
2432
|
-
fileIterators.set(
|
|
2534
|
+
fileReaders.set(path4, rl);
|
|
2535
|
+
fileIterators.set(path4, rl[Symbol.asyncIterator]());
|
|
2433
2536
|
}
|
|
2434
|
-
const iterator = fileIterators.get(
|
|
2537
|
+
const iterator = fileIterators.get(path4);
|
|
2435
2538
|
const result = await iterator.next();
|
|
2436
2539
|
if (result.done) {
|
|
2437
|
-
const reader = fileReaders.get(
|
|
2540
|
+
const reader = fileReaders.get(path4);
|
|
2438
2541
|
reader.close();
|
|
2439
|
-
fileReaders.delete(
|
|
2440
|
-
fileIterators.delete(
|
|
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-
|
|
8
|
-
import "./chunk-
|
|
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.
|
|
19
|
+
version: "0.1.47",
|
|
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-
|
|
99
|
+
const { DiracShell } = await import("./shell-TNQMOYFR.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-
|
|
5
|
+
} from "./chunk-TISVDOGD.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TXL3RV74.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-UEFKQRYN.js";
|
|
5
5
|
import {
|
|
6
6
|
integrate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TXL3RV74.js";
|
|
8
8
|
import {
|
|
9
9
|
DiracParser
|
|
10
10
|
} from "./chunk-HRHAMPOB.js";
|
|
@@ -39,11 +39,33 @@ var DiracShell = class {
|
|
|
39
39
|
input: process.stdin,
|
|
40
40
|
output: process.stdout,
|
|
41
41
|
prompt: "> ",
|
|
42
|
-
historySize: MAX_HISTORY
|
|
42
|
+
historySize: MAX_HISTORY,
|
|
43
|
+
completer: this.completer.bind(this)
|
|
43
44
|
});
|
|
44
45
|
this.loadHistory();
|
|
45
46
|
this.setupHandlers();
|
|
46
47
|
}
|
|
48
|
+
completer(line) {
|
|
49
|
+
const braketMatch = line.match(/\|([a-z0-9_-]*)$/i);
|
|
50
|
+
if (braketMatch) {
|
|
51
|
+
const partial = braketMatch[1];
|
|
52
|
+
const subroutineNames = this.session.subroutines.map((sub) => sub.name);
|
|
53
|
+
const matches = subroutineNames.filter(
|
|
54
|
+
(name) => name.toLowerCase().startsWith(partial.toLowerCase())
|
|
55
|
+
);
|
|
56
|
+
const completions = matches.map((name) => `|${name}>`);
|
|
57
|
+
return [completions, braketMatch[0]];
|
|
58
|
+
}
|
|
59
|
+
const commandMatch = line.match(/:([a-z]*)$/i);
|
|
60
|
+
if (commandMatch) {
|
|
61
|
+
const partial = commandMatch[1];
|
|
62
|
+
const commands = ["help", "quit", "exit", "vars", "subs", "clear", "history", "save", "debug", "llm"];
|
|
63
|
+
const matches = commands.filter((cmd) => cmd.startsWith(partial.toLowerCase()));
|
|
64
|
+
const completions = matches.map((cmd) => `:${cmd}`);
|
|
65
|
+
return [completions, commandMatch[0]];
|
|
66
|
+
}
|
|
67
|
+
return [[], line];
|
|
68
|
+
}
|
|
47
69
|
loadHistory() {
|
|
48
70
|
try {
|
|
49
71
|
if (fs.existsSync(HISTORY_FILE)) {
|
|
@@ -66,7 +88,7 @@ var DiracShell = class {
|
|
|
66
88
|
});
|
|
67
89
|
this.rl.on("close", () => {
|
|
68
90
|
this.saveHistory();
|
|
69
|
-
import("./schedule-
|
|
91
|
+
import("./schedule-5HZCREEP.js").then(({ stopAllScheduledTasks }) => {
|
|
70
92
|
stopAllScheduledTasks();
|
|
71
93
|
console.log("\nGoodbye!");
|
|
72
94
|
process.exit(0);
|
|
@@ -195,7 +217,7 @@ Commands:
|
|
|
195
217
|
:index <path> Index subroutines from directory
|
|
196
218
|
:search <query> Search indexed subroutines
|
|
197
219
|
:load <query> Load context (search and import subroutines)
|
|
198
|
-
:save <name>
|
|
220
|
+
:save <name> [file] Save subroutine (default: ~/.dirac/lib/TIMESTAMP/name.di)
|
|
199
221
|
:stats Show registry statistics
|
|
200
222
|
:tasks List all scheduled tasks
|
|
201
223
|
:stop <name> Stop a scheduled task
|
|
@@ -335,13 +357,27 @@ Examples:
|
|
|
335
357
|
}
|
|
336
358
|
break;
|
|
337
359
|
case "save":
|
|
338
|
-
if (args.length
|
|
339
|
-
console.log("Usage: :save <subroutine-name>
|
|
360
|
+
if (args.length === 0) {
|
|
361
|
+
console.log("Usage: :save <subroutine-name> [file]");
|
|
362
|
+
console.log(" If file is omitted, saves to ~/.dirac/lib/TIMESTAMP/NAME.di");
|
|
363
|
+
console.log("Examples:");
|
|
364
|
+
console.log(" :save greet # saves to ~/.dirac/lib/TIMESTAMP/greet.di");
|
|
365
|
+
console.log(" :save greet ./my-lib/greet.di # saves to specific file");
|
|
366
|
+
console.log(" :save greet utils # saves to ~/.dirac/lib/utils/greet.di");
|
|
340
367
|
} else {
|
|
341
368
|
const subName = args[0];
|
|
342
|
-
const fileName = args[1];
|
|
369
|
+
const fileName = args.length > 1 ? args[1] : void 0;
|
|
343
370
|
try {
|
|
344
|
-
|
|
371
|
+
let xml;
|
|
372
|
+
if (fileName) {
|
|
373
|
+
if (fileName.includes("/") || fileName.includes(".di")) {
|
|
374
|
+
xml = `<save-subroutine name="${subName}" file="${fileName}" format="xml" />`;
|
|
375
|
+
} else {
|
|
376
|
+
xml = `<save-subroutine name="${subName}" path="${fileName}" format="xml" />`;
|
|
377
|
+
}
|
|
378
|
+
} else {
|
|
379
|
+
xml = `<save-subroutine name="${subName}" format="xml" />`;
|
|
380
|
+
}
|
|
345
381
|
const ast = this.xmlParser.parse(xml);
|
|
346
382
|
await integrate(this.session, ast);
|
|
347
383
|
if (this.session.output.length > 0) {
|
|
@@ -366,7 +402,7 @@ Examples:
|
|
|
366
402
|
break;
|
|
367
403
|
case "tasks":
|
|
368
404
|
try {
|
|
369
|
-
const { listScheduledTasks } = await import("./schedule-
|
|
405
|
+
const { listScheduledTasks } = await import("./schedule-5HZCREEP.js");
|
|
370
406
|
const tasks = listScheduledTasks();
|
|
371
407
|
if (tasks.length === 0) {
|
|
372
408
|
console.log("No scheduled tasks running.");
|
|
@@ -385,7 +421,7 @@ Examples:
|
|
|
385
421
|
console.log("Usage: :stop <task-name>");
|
|
386
422
|
} else {
|
|
387
423
|
try {
|
|
388
|
-
const { stopScheduledTask } = await import("./schedule-
|
|
424
|
+
const { stopScheduledTask } = await import("./schedule-5HZCREEP.js");
|
|
389
425
|
const taskName = args[0];
|
|
390
426
|
const stopped = stopScheduledTask(taskName);
|
|
391
427
|
if (stopped) {
|
|
@@ -400,7 +436,7 @@ Examples:
|
|
|
400
436
|
break;
|
|
401
437
|
case "stopall":
|
|
402
438
|
try {
|
|
403
|
-
const { stopAllScheduledTasks } = await import("./schedule-
|
|
439
|
+
const { stopAllScheduledTasks } = await import("./schedule-5HZCREEP.js");
|
|
404
440
|
stopAllScheduledTasks();
|
|
405
441
|
console.log("All scheduled tasks stopped.");
|
|
406
442
|
} catch (error) {
|
package/dist/test-runner.js
CHANGED