dirac-lang 0.1.38 → 0.1.40
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-DGWZB2VC.js → chunk-NWGHO23V.js} +383 -28
- package/dist/{chunk-MEATHM35.js → chunk-W6BEEC5D.js} +1 -1
- package/dist/cli.js +4 -4
- package/dist/index.js +2 -2
- package/dist/{interpreter-FJ52HYZC.js → interpreter-UCWBT6KP.js} +1 -1
- package/dist/{shell-HKCK2KIM.js → shell-Z7RZRFTV.js} +105 -4
- package/dist/test-runner.js +1 -1
- package/package.json +1 -1
|
@@ -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-
|
|
451
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
|
|
452
452
|
await integrateChildren2(session, thenElement);
|
|
453
453
|
}
|
|
454
454
|
} else {
|
|
455
455
|
if (elseElement) {
|
|
456
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
456
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.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-
|
|
469
|
+
const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.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-
|
|
492
|
+
const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.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-
|
|
496
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
|
|
497
497
|
await integrateChildren2(session, child);
|
|
498
498
|
const newChunks = session.output.slice(argOutputStart);
|
|
499
499
|
const argValue = newChunks.join("");
|
|
@@ -933,11 +933,11 @@ ${expr}
|
|
|
933
933
|
for (const v of session.variables) {
|
|
934
934
|
context[v.name] = v.value;
|
|
935
935
|
}
|
|
936
|
-
const { default:
|
|
937
|
-
const { default:
|
|
936
|
+
const { default: fs5 } = await import("fs");
|
|
937
|
+
const { default: path3 } = await import("path");
|
|
938
938
|
const { fileURLToPath } = await import("url");
|
|
939
|
-
context.fs =
|
|
940
|
-
context.path =
|
|
939
|
+
context.fs = fs5;
|
|
940
|
+
context.path = path3;
|
|
941
941
|
context.__dirname = process.cwd();
|
|
942
942
|
context.getParams = () => {
|
|
943
943
|
const params = session.parameterStack[session.parameterStack.length - 1];
|
|
@@ -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-
|
|
1381
|
+
const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.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-
|
|
1390
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.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-
|
|
1403
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.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-
|
|
1413
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.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-
|
|
1422
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-UCWBT6KP.js");
|
|
1423
1423
|
for (const exceptionDom of exceptions) {
|
|
1424
1424
|
await integrateChildren2(session, exceptionDom);
|
|
1425
1425
|
}
|
|
@@ -1613,6 +1613,349 @@ function formatAsText(subroutines) {
|
|
|
1613
1613
|
return lines.join("\n");
|
|
1614
1614
|
}
|
|
1615
1615
|
|
|
1616
|
+
// src/runtime/subroutine-registry.ts
|
|
1617
|
+
import * as fs3 from "fs";
|
|
1618
|
+
import * as path2 from "path";
|
|
1619
|
+
import * as os from "os";
|
|
1620
|
+
var SubroutineRegistry = class {
|
|
1621
|
+
indexPath;
|
|
1622
|
+
index;
|
|
1623
|
+
constructor(indexPath) {
|
|
1624
|
+
this.indexPath = indexPath || path2.join(os.homedir(), ".dirac", "subroutine-index.json");
|
|
1625
|
+
this.index = this.loadIndex();
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Load index from disk
|
|
1629
|
+
*/
|
|
1630
|
+
loadIndex() {
|
|
1631
|
+
if (fs3.existsSync(this.indexPath)) {
|
|
1632
|
+
try {
|
|
1633
|
+
const data = fs3.readFileSync(this.indexPath, "utf-8");
|
|
1634
|
+
return JSON.parse(data);
|
|
1635
|
+
} catch (err) {
|
|
1636
|
+
console.error("Error loading subroutine index:", err);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
return {
|
|
1640
|
+
subroutines: [],
|
|
1641
|
+
lastUpdated: Date.now()
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Save index to disk
|
|
1646
|
+
*/
|
|
1647
|
+
saveIndex() {
|
|
1648
|
+
const dir = path2.dirname(this.indexPath);
|
|
1649
|
+
if (!fs3.existsSync(dir)) {
|
|
1650
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
1651
|
+
}
|
|
1652
|
+
this.index.lastUpdated = Date.now();
|
|
1653
|
+
fs3.writeFileSync(this.indexPath, JSON.stringify(this.index, null, 2), "utf-8");
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Scan a directory for .di files and index all subroutines
|
|
1657
|
+
*/
|
|
1658
|
+
async indexDirectory(dirPath) {
|
|
1659
|
+
let count = 0;
|
|
1660
|
+
const scanDir = (dir) => {
|
|
1661
|
+
const entries = fs3.readdirSync(dir, { withFileTypes: true });
|
|
1662
|
+
for (const entry of entries) {
|
|
1663
|
+
const fullPath = path2.join(dir, entry.name);
|
|
1664
|
+
if (entry.isDirectory()) {
|
|
1665
|
+
scanDir(fullPath);
|
|
1666
|
+
} else if (entry.isFile() && entry.name.endsWith(".di")) {
|
|
1667
|
+
count += this.indexFile(fullPath);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
scanDir(dirPath);
|
|
1672
|
+
this.saveIndex();
|
|
1673
|
+
return count;
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Index a single .di file
|
|
1677
|
+
*/
|
|
1678
|
+
indexFile(filePath) {
|
|
1679
|
+
try {
|
|
1680
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
1681
|
+
const parser = new DiracParser();
|
|
1682
|
+
const ast = parser.parse(content);
|
|
1683
|
+
this.index.subroutines = this.index.subroutines.filter((s) => s.filePath !== filePath);
|
|
1684
|
+
const subroutines = this.extractSubroutines(ast, filePath);
|
|
1685
|
+
this.index.subroutines.push(...subroutines);
|
|
1686
|
+
return subroutines.length;
|
|
1687
|
+
} catch (err) {
|
|
1688
|
+
if (process.env.DEBUG_REGISTRY === "1") {
|
|
1689
|
+
console.error(`Error indexing ${filePath}:`, err);
|
|
1690
|
+
}
|
|
1691
|
+
return 0;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Extract subroutines from AST
|
|
1696
|
+
*/
|
|
1697
|
+
extractSubroutines(element, filePath) {
|
|
1698
|
+
const subroutines = [];
|
|
1699
|
+
if (element.tag === "subroutine") {
|
|
1700
|
+
const name = element.attributes.name;
|
|
1701
|
+
if (name) {
|
|
1702
|
+
const metadata = {
|
|
1703
|
+
name,
|
|
1704
|
+
description: element.attributes.description,
|
|
1705
|
+
parameters: [],
|
|
1706
|
+
filePath
|
|
1707
|
+
};
|
|
1708
|
+
for (const [attrName, attrValue] of Object.entries(element.attributes)) {
|
|
1709
|
+
if (attrName.startsWith("param-")) {
|
|
1710
|
+
const paramName = attrName.substring(6);
|
|
1711
|
+
const parts = attrValue.split(":");
|
|
1712
|
+
metadata.parameters.push({
|
|
1713
|
+
name: paramName,
|
|
1714
|
+
type: parts[0] || "any",
|
|
1715
|
+
required: parts[1] === "required",
|
|
1716
|
+
description: parts[2]
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
subroutines.push(metadata);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
if (element.children) {
|
|
1724
|
+
for (const child of element.children) {
|
|
1725
|
+
subroutines.push(...this.extractSubroutines(child, filePath));
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return subroutines;
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Simple text search (will be replaced with vector search)
|
|
1732
|
+
* Supports multi-word queries by tokenizing and matching individual words
|
|
1733
|
+
*/
|
|
1734
|
+
search(query, limit = 10) {
|
|
1735
|
+
const lowerQuery = query.toLowerCase();
|
|
1736
|
+
const queryTokens = lowerQuery.split(/[\s\-_]+/).filter((t) => t.length > 0);
|
|
1737
|
+
const results = this.index.subroutines.map((sub) => {
|
|
1738
|
+
let score = 0;
|
|
1739
|
+
const lowerName = sub.name.toLowerCase();
|
|
1740
|
+
const lowerDesc = (sub.description || "").toLowerCase();
|
|
1741
|
+
const nameTokens = lowerName.split(/[\s\-_]+/);
|
|
1742
|
+
if (lowerName === lowerQuery) {
|
|
1743
|
+
score += 100;
|
|
1744
|
+
} else if (lowerName.includes(lowerQuery)) {
|
|
1745
|
+
score += 50;
|
|
1746
|
+
} else if (lowerDesc.includes(lowerQuery)) {
|
|
1747
|
+
score += 30;
|
|
1748
|
+
}
|
|
1749
|
+
let tokenMatchCount = 0;
|
|
1750
|
+
for (const queryToken of queryTokens) {
|
|
1751
|
+
if (nameTokens.some((nt) => nt === queryToken)) {
|
|
1752
|
+
score += 40;
|
|
1753
|
+
tokenMatchCount++;
|
|
1754
|
+
} else if (nameTokens.some((nt) => nt.includes(queryToken))) {
|
|
1755
|
+
score += 20;
|
|
1756
|
+
tokenMatchCount++;
|
|
1757
|
+
}
|
|
1758
|
+
if (lowerDesc.includes(queryToken)) {
|
|
1759
|
+
score += 15;
|
|
1760
|
+
tokenMatchCount++;
|
|
1761
|
+
}
|
|
1762
|
+
for (const param of sub.parameters) {
|
|
1763
|
+
const lowerParamName = param.name.toLowerCase();
|
|
1764
|
+
if (lowerParamName === queryToken) {
|
|
1765
|
+
score += 10;
|
|
1766
|
+
tokenMatchCount++;
|
|
1767
|
+
} else if (lowerParamName.includes(queryToken)) {
|
|
1768
|
+
score += 5;
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
if (queryTokens.length > 1 && tokenMatchCount >= queryTokens.length * 0.5) {
|
|
1773
|
+
score += 25;
|
|
1774
|
+
}
|
|
1775
|
+
return { sub, score };
|
|
1776
|
+
}).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, limit).map((r) => r.sub);
|
|
1777
|
+
return results;
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Get all subroutines
|
|
1781
|
+
*/
|
|
1782
|
+
getAll() {
|
|
1783
|
+
return this.index.subroutines;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Get statistics
|
|
1787
|
+
*/
|
|
1788
|
+
getStats() {
|
|
1789
|
+
const files = new Set(this.index.subroutines.map((s) => s.filePath));
|
|
1790
|
+
return {
|
|
1791
|
+
totalSubroutines: this.index.subroutines.length,
|
|
1792
|
+
totalFiles: files.size,
|
|
1793
|
+
lastUpdated: new Date(this.index.lastUpdated)
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
// src/tags/subroutine-index.ts
|
|
1799
|
+
var registry = new SubroutineRegistry();
|
|
1800
|
+
async function executeIndexSubroutines(session, element) {
|
|
1801
|
+
const pathAttr = element.attributes.path;
|
|
1802
|
+
if (!pathAttr) {
|
|
1803
|
+
throw new Error("<index-subroutines> requires path attribute");
|
|
1804
|
+
}
|
|
1805
|
+
const count = await registry.indexDirectory(pathAttr);
|
|
1806
|
+
if (session.debug) {
|
|
1807
|
+
emit(session, `Indexed ${count} subroutines from ${pathAttr}
|
|
1808
|
+
`);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
async function executeSearchSubroutines(session, element) {
|
|
1812
|
+
const query = element.attributes.query;
|
|
1813
|
+
const limitAttr = element.attributes.limit;
|
|
1814
|
+
const outputVar = element.attributes.output;
|
|
1815
|
+
const format = element.attributes.format || "text";
|
|
1816
|
+
if (!query) {
|
|
1817
|
+
throw new Error("<search-subroutines> requires query attribute");
|
|
1818
|
+
}
|
|
1819
|
+
const limit = limitAttr ? parseInt(limitAttr, 10) : 10;
|
|
1820
|
+
const results = registry.search(query, limit);
|
|
1821
|
+
let output = "";
|
|
1822
|
+
switch (format) {
|
|
1823
|
+
case "json":
|
|
1824
|
+
output = JSON.stringify(results, null, 2);
|
|
1825
|
+
break;
|
|
1826
|
+
case "xml":
|
|
1827
|
+
output = "<subroutines>\n";
|
|
1828
|
+
for (const sub of results) {
|
|
1829
|
+
const params = sub.parameters.map((p) => `param-${p.name}="${p.type}"`).join(" ");
|
|
1830
|
+
output += ` <subroutine name="${sub.name}" ${params} file="${sub.filePath}"/>
|
|
1831
|
+
`;
|
|
1832
|
+
if (sub.description) {
|
|
1833
|
+
output += ` <!-- ${sub.description} -->
|
|
1834
|
+
`;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
output += "</subroutines>";
|
|
1838
|
+
break;
|
|
1839
|
+
case "text":
|
|
1840
|
+
default:
|
|
1841
|
+
if (results.length === 0) {
|
|
1842
|
+
output = "No subroutines found.\n";
|
|
1843
|
+
} else {
|
|
1844
|
+
output = `Found ${results.length} subroutine(s):
|
|
1845
|
+
|
|
1846
|
+
`;
|
|
1847
|
+
for (const sub of results) {
|
|
1848
|
+
output += `${sub.name}(${sub.parameters.map((p) => p.name).join(", ")})
|
|
1849
|
+
`;
|
|
1850
|
+
if (sub.description) {
|
|
1851
|
+
output += ` ${sub.description}
|
|
1852
|
+
`;
|
|
1853
|
+
}
|
|
1854
|
+
output += ` File: ${sub.filePath}
|
|
1855
|
+
|
|
1856
|
+
`;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
if (outputVar) {
|
|
1862
|
+
setVariable(session, outputVar, output, false);
|
|
1863
|
+
} else {
|
|
1864
|
+
emit(session, output);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
async function executeRegistryStats(session, element) {
|
|
1868
|
+
const stats = registry.getStats();
|
|
1869
|
+
const output = `Subroutine Registry Statistics:
|
|
1870
|
+
Total Subroutines: ${stats.totalSubroutines}
|
|
1871
|
+
Total Files: ${stats.totalFiles}
|
|
1872
|
+
Last Updated: ${stats.lastUpdated.toLocaleString()}
|
|
1873
|
+
`;
|
|
1874
|
+
emit(session, output);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
// src/tags/load-context.ts
|
|
1878
|
+
var registry2 = new SubroutineRegistry();
|
|
1879
|
+
async function executeLoadContext(session, element) {
|
|
1880
|
+
let query = element.attributes.query;
|
|
1881
|
+
if (!query && element.text) {
|
|
1882
|
+
query = element.text.trim();
|
|
1883
|
+
}
|
|
1884
|
+
if (!query && element.children.length > 0) {
|
|
1885
|
+
const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
|
|
1886
|
+
const beforeOutput = session.output.length;
|
|
1887
|
+
for (const child of element.children) {
|
|
1888
|
+
await integrate2(session, child);
|
|
1889
|
+
}
|
|
1890
|
+
const childOutput = session.output.slice(beforeOutput);
|
|
1891
|
+
query = childOutput.join("").trim();
|
|
1892
|
+
session.output = session.output.slice(0, beforeOutput);
|
|
1893
|
+
}
|
|
1894
|
+
if (!query) {
|
|
1895
|
+
throw new Error("<load-context> requires query attribute or text content");
|
|
1896
|
+
}
|
|
1897
|
+
const limitAttr = element.attributes.limit;
|
|
1898
|
+
const shouldImport = element.attributes.import !== "false";
|
|
1899
|
+
const outputVar = element.attributes.output;
|
|
1900
|
+
const stats = registry2.getStats();
|
|
1901
|
+
if (stats.totalSubroutines === 0) {
|
|
1902
|
+
emit(session, `[load-context] Registry is empty. Use :index <path> or <index-subroutines path="..."> first.
|
|
1903
|
+
`);
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
const limit = limitAttr ? parseInt(limitAttr, 10) : 5;
|
|
1907
|
+
const results = registry2.search(query, limit);
|
|
1908
|
+
if (results.length === 0) {
|
|
1909
|
+
emit(session, `[load-context] No subroutines found for query: "${query}". Try indexing more libraries.
|
|
1910
|
+
`);
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
emit(session, `[load-context] Found ${results.length} subroutine(s): ${results.map((s) => s.name).join(", ")}
|
|
1914
|
+
`);
|
|
1915
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
1916
|
+
for (const sub of results) {
|
|
1917
|
+
if (!fileMap.has(sub.filePath)) {
|
|
1918
|
+
fileMap.set(sub.filePath, []);
|
|
1919
|
+
}
|
|
1920
|
+
fileMap.get(sub.filePath).push(sub);
|
|
1921
|
+
}
|
|
1922
|
+
emit(session, `[load-context] Importing ${fileMap.size} file(s)...
|
|
1923
|
+
`);
|
|
1924
|
+
if (shouldImport) {
|
|
1925
|
+
for (const filePath of fileMap.keys()) {
|
|
1926
|
+
try {
|
|
1927
|
+
const { resolve: resolve2 } = await import("path");
|
|
1928
|
+
const absolutePath = filePath.startsWith("/") ? filePath : resolve2(process.cwd(), filePath);
|
|
1929
|
+
const importElement = {
|
|
1930
|
+
tag: "import",
|
|
1931
|
+
attributes: { src: absolutePath },
|
|
1932
|
+
children: [],
|
|
1933
|
+
text: ""
|
|
1934
|
+
};
|
|
1935
|
+
await executeImport(session, importElement);
|
|
1936
|
+
emit(session, `[load-context] \u2713 Imported: ${filePath}
|
|
1937
|
+
`);
|
|
1938
|
+
} catch (error) {
|
|
1939
|
+
emit(session, `[load-context] \u2717 Failed to import ${filePath}: ${error}
|
|
1940
|
+
`);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
} else {
|
|
1944
|
+
emit(session, `[load-context] (import=false, not loading files)
|
|
1945
|
+
`);
|
|
1946
|
+
}
|
|
1947
|
+
if (outputVar) {
|
|
1948
|
+
const summary = results.map((s) => ({
|
|
1949
|
+
name: s.name,
|
|
1950
|
+
description: s.description,
|
|
1951
|
+
parameters: s.parameters.map((p) => p.name),
|
|
1952
|
+
filePath: s.filePath
|
|
1953
|
+
}));
|
|
1954
|
+
const { setVariable: setVariable2 } = await import("./session-UBATJEND.js");
|
|
1955
|
+
setVariable2(session, outputVar, JSON.stringify(summary, null, 2), false);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1616
1959
|
// src/tags/foreach.ts
|
|
1617
1960
|
import { XMLParser } from "fast-xml-parser";
|
|
1618
1961
|
async function executeForeach(session, element) {
|
|
@@ -1633,7 +1976,7 @@ async function executeForeach(session, element) {
|
|
|
1633
1976
|
const parser2 = new DiracParser2();
|
|
1634
1977
|
try {
|
|
1635
1978
|
const fromElement = parser2.parse(fromAttr);
|
|
1636
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1979
|
+
const { integrate: integrate2 } = await import("./interpreter-UCWBT6KP.js");
|
|
1637
1980
|
await integrate2(session, fromElement);
|
|
1638
1981
|
} catch (e) {
|
|
1639
1982
|
session.output = savedOutput;
|
|
@@ -1781,7 +2124,7 @@ async function executeEnvironment(session, element) {
|
|
|
1781
2124
|
}
|
|
1782
2125
|
|
|
1783
2126
|
// src/tags/input.ts
|
|
1784
|
-
import * as
|
|
2127
|
+
import * as fs4 from "fs";
|
|
1785
2128
|
import * as readline from "readline";
|
|
1786
2129
|
var fileReaders = /* @__PURE__ */ new Map();
|
|
1787
2130
|
var fileIterators = /* @__PURE__ */ new Map();
|
|
@@ -1805,11 +2148,11 @@ async function executeInput(session, element) {
|
|
|
1805
2148
|
throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
|
|
1806
2149
|
}
|
|
1807
2150
|
} else if (source === "file") {
|
|
1808
|
-
const
|
|
2151
|
+
const path3 = substituteAttribute(session, pathAttr);
|
|
1809
2152
|
if (mode === "all") {
|
|
1810
|
-
value =
|
|
2153
|
+
value = fs4.readFileSync(path3, "utf-8");
|
|
1811
2154
|
} else if (mode === "line") {
|
|
1812
|
-
value = await readLineFromFile(
|
|
2155
|
+
value = await readLineFromFile(path3);
|
|
1813
2156
|
} else {
|
|
1814
2157
|
throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
|
|
1815
2158
|
}
|
|
@@ -1866,23 +2209,23 @@ async function readLineStdin() {
|
|
|
1866
2209
|
}
|
|
1867
2210
|
return result.value;
|
|
1868
2211
|
}
|
|
1869
|
-
async function readLineFromFile(
|
|
1870
|
-
if (!fileReaders.has(
|
|
1871
|
-
const fileStream =
|
|
2212
|
+
async function readLineFromFile(path3) {
|
|
2213
|
+
if (!fileReaders.has(path3)) {
|
|
2214
|
+
const fileStream = fs4.createReadStream(path3);
|
|
1872
2215
|
const rl = readline.createInterface({
|
|
1873
2216
|
input: fileStream,
|
|
1874
2217
|
crlfDelay: Infinity
|
|
1875
2218
|
});
|
|
1876
|
-
fileReaders.set(
|
|
1877
|
-
fileIterators.set(
|
|
2219
|
+
fileReaders.set(path3, rl);
|
|
2220
|
+
fileIterators.set(path3, rl[Symbol.asyncIterator]());
|
|
1878
2221
|
}
|
|
1879
|
-
const iterator = fileIterators.get(
|
|
2222
|
+
const iterator = fileIterators.get(path3);
|
|
1880
2223
|
const result = await iterator.next();
|
|
1881
2224
|
if (result.done) {
|
|
1882
|
-
const reader = fileReaders.get(
|
|
2225
|
+
const reader = fileReaders.get(path3);
|
|
1883
2226
|
reader.close();
|
|
1884
|
-
fileReaders.delete(
|
|
1885
|
-
fileIterators.delete(
|
|
2227
|
+
fileReaders.delete(path3);
|
|
2228
|
+
fileIterators.delete(path3);
|
|
1886
2229
|
return "";
|
|
1887
2230
|
}
|
|
1888
2231
|
return result.value;
|
|
@@ -1980,6 +2323,18 @@ async function integrate(session, element) {
|
|
|
1980
2323
|
case "list-subroutines":
|
|
1981
2324
|
await executeListSubroutines(session, element);
|
|
1982
2325
|
break;
|
|
2326
|
+
case "index-subroutines":
|
|
2327
|
+
await executeIndexSubroutines(session, element);
|
|
2328
|
+
break;
|
|
2329
|
+
case "search-subroutines":
|
|
2330
|
+
await executeSearchSubroutines(session, element);
|
|
2331
|
+
break;
|
|
2332
|
+
case "registry-stats":
|
|
2333
|
+
await executeRegistryStats(session, element);
|
|
2334
|
+
break;
|
|
2335
|
+
case "load-context":
|
|
2336
|
+
await executeLoadContext(session, element);
|
|
2337
|
+
break;
|
|
1983
2338
|
case "foreach":
|
|
1984
2339
|
await executeForeach(session, element);
|
|
1985
2340
|
break;
|
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-W6BEEC5D.js";
|
|
8
|
+
import "./chunk-NWGHO23V.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.39",
|
|
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-Z7RZRFTV.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-W6BEEC5D.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NWGHO23V.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-NWGHO23V.js";
|
|
8
8
|
import {
|
|
9
9
|
DiracParser
|
|
10
10
|
} from "./chunk-HRHAMPOB.js";
|
|
@@ -185,6 +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
|
|
189
|
+
:index <path> Index subroutines from directory
|
|
190
|
+
:search <query> Search indexed subroutines
|
|
191
|
+
:load <query> Load context (search and import subroutines)
|
|
192
|
+
:stats Show registry statistics
|
|
188
193
|
:exit Exit shell
|
|
189
194
|
|
|
190
195
|
Syntax:
|
|
@@ -255,6 +260,82 @@ Examples:
|
|
|
255
260
|
console.log(` Custom LLM URL: ${this.config.customLLMUrl}`);
|
|
256
261
|
}
|
|
257
262
|
break;
|
|
263
|
+
case "reload":
|
|
264
|
+
try {
|
|
265
|
+
await this.reloadConfig();
|
|
266
|
+
console.log("Configuration reloaded successfully");
|
|
267
|
+
console.log(` LLM Provider: ${this.config.llmProvider || "none"}`);
|
|
268
|
+
console.log(` LLM Model: ${this.config.llmModel || "default"}`);
|
|
269
|
+
if (this.config.customLLMUrl) {
|
|
270
|
+
console.log(` Custom LLM URL: ${this.config.customLLMUrl}`);
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error("Error reloading config:", error instanceof Error ? error.message : String(error));
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
case "index":
|
|
277
|
+
if (args.length === 0) {
|
|
278
|
+
console.log("Usage: :index <path>");
|
|
279
|
+
} else {
|
|
280
|
+
const indexPath = args[0];
|
|
281
|
+
try {
|
|
282
|
+
const xml = `<index-subroutines path="${indexPath}" />`;
|
|
283
|
+
const ast = this.xmlParser.parse(xml);
|
|
284
|
+
await integrate(this.session, ast);
|
|
285
|
+
if (this.session.output.length > 0) {
|
|
286
|
+
console.log(this.session.output.join(""));
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error("Error indexing:", error instanceof Error ? error.message : String(error));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
case "search":
|
|
294
|
+
if (args.length === 0) {
|
|
295
|
+
console.log("Usage: :search <query>");
|
|
296
|
+
} else {
|
|
297
|
+
const query = args.join(" ");
|
|
298
|
+
try {
|
|
299
|
+
const xml = `<search-subroutines query="${query}" format="text" />`;
|
|
300
|
+
const ast = this.xmlParser.parse(xml);
|
|
301
|
+
await integrate(this.session, ast);
|
|
302
|
+
if (this.session.output.length > 0) {
|
|
303
|
+
console.log(this.session.output.join(""));
|
|
304
|
+
}
|
|
305
|
+
} catch (error) {
|
|
306
|
+
console.error("Error searching:", error instanceof Error ? error.message : String(error));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
case "load":
|
|
311
|
+
if (args.length === 0) {
|
|
312
|
+
console.log("Usage: :load <query>");
|
|
313
|
+
} else {
|
|
314
|
+
const query = args.join(" ");
|
|
315
|
+
try {
|
|
316
|
+
const xml = `<load-context query="${query}" limit="5" import="true" />`;
|
|
317
|
+
const ast = this.xmlParser.parse(xml);
|
|
318
|
+
await integrate(this.session, ast);
|
|
319
|
+
if (this.session.output.length > 0) {
|
|
320
|
+
console.log(this.session.output.join(""));
|
|
321
|
+
}
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error("Error loading context:", error instanceof Error ? error.message : String(error));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
case "stats":
|
|
328
|
+
try {
|
|
329
|
+
const xml = "<registry-stats />";
|
|
330
|
+
const ast = this.xmlParser.parse(xml);
|
|
331
|
+
await integrate(this.session, ast);
|
|
332
|
+
if (this.session.output.length > 0) {
|
|
333
|
+
console.log(this.session.output.join(""));
|
|
334
|
+
}
|
|
335
|
+
} catch (error) {
|
|
336
|
+
console.error("Error getting stats:", error instanceof Error ? error.message : String(error));
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
258
339
|
case "exit":
|
|
259
340
|
case "quit":
|
|
260
341
|
this.rl.close();
|
|
@@ -301,7 +382,7 @@ Examples:
|
|
|
301
382
|
}
|
|
302
383
|
const { spawn } = await import("child_process");
|
|
303
384
|
this.rl.pause();
|
|
304
|
-
return new Promise((
|
|
385
|
+
return new Promise((resolve2) => {
|
|
305
386
|
const shell = process.env.SHELL || "/bin/sh";
|
|
306
387
|
const child = spawn(shell, ["-c", command], {
|
|
307
388
|
stdio: "inherit",
|
|
@@ -309,12 +390,12 @@ Examples:
|
|
|
309
390
|
});
|
|
310
391
|
child.on("close", () => {
|
|
311
392
|
this.rl.resume();
|
|
312
|
-
|
|
393
|
+
resolve2();
|
|
313
394
|
});
|
|
314
395
|
child.on("error", (err) => {
|
|
315
396
|
console.error(`Shell error: ${err.message}`);
|
|
316
397
|
this.rl.resume();
|
|
317
|
-
|
|
398
|
+
resolve2();
|
|
318
399
|
});
|
|
319
400
|
});
|
|
320
401
|
}
|
|
@@ -352,6 +433,26 @@ Examples:
|
|
|
352
433
|
`);
|
|
353
434
|
}
|
|
354
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Reload configuration from config.yml
|
|
438
|
+
*/
|
|
439
|
+
async reloadConfig() {
|
|
440
|
+
const configPath = path.resolve(process.cwd(), "config.yml");
|
|
441
|
+
if (!fs.existsSync(configPath)) {
|
|
442
|
+
throw new Error("config.yml not found in current directory");
|
|
443
|
+
}
|
|
444
|
+
const configData = yaml.load(fs.readFileSync(configPath, "utf-8"));
|
|
445
|
+
this.config.llmProvider = configData.llmProvider || process.env.LLM_PROVIDER;
|
|
446
|
+
this.config.llmModel = configData.llmModel || process.env.LLM_MODEL;
|
|
447
|
+
this.config.customLLMUrl = configData.customLLMUrl || process.env.CUSTOM_LLM_URL;
|
|
448
|
+
const oldVariables = this.session.variables;
|
|
449
|
+
const oldSubroutines = this.session.subroutines;
|
|
450
|
+
const oldImportedFiles = this.session.importedFiles;
|
|
451
|
+
this.session = createSession(this.config);
|
|
452
|
+
this.session.variables = oldVariables;
|
|
453
|
+
this.session.subroutines = oldSubroutines;
|
|
454
|
+
this.session.importedFiles = oldImportedFiles;
|
|
455
|
+
}
|
|
355
456
|
};
|
|
356
457
|
async function main() {
|
|
357
458
|
let config = {
|
package/dist/test-runner.js
CHANGED