dirac-lang 0.1.75 → 0.1.77
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/{agent-TC34E2DB.js → agent-VAFUNYDM.js} +4 -3
- package/dist/{chunk-KIIETJFM.js → chunk-CLGQYGHT.js} +1 -1
- package/dist/chunk-FPDW535D.js +305 -0
- package/dist/{chunk-YCUHRNXQ.js → chunk-TYIDNAZ7.js} +63 -324
- package/dist/{chunk-2EUVDYHX.js → chunk-VUMS53GF.js} +1 -1
- package/dist/cli.js +11 -10
- package/dist/{cron-M5HO2H5T.js → cron-RWSM6IBB.js} +3 -2
- package/dist/index.js +4 -3
- package/dist/{interpreter-QVHRO4LN.js → interpreter-X5V2FFGI.js} +3 -2
- package/dist/{run-at-GP5XZP5W.js → run-at-3QL4C4UD.js} +3 -2
- package/dist/{schedule-FWAU6HDT.js → schedule-4B3KUC7T.js} +3 -2
- package/dist/{session-server-K6OZRYTZ.js → session-server-IDEV4CXY.js} +4 -3
- package/dist/{shell-63M4JYYI.js → shell-IUWCSKPG.js} +15 -12
- package/dist/subroutine-index-7B5YXKAA.js +14 -0
- package/dist/test-runner.js +3 -2
- package/package.json +1 -1
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-HRHAMPOB.js";
|
|
5
|
+
} from "./chunk-CLGQYGHT.js";
|
|
6
|
+
import "./chunk-TYIDNAZ7.js";
|
|
8
7
|
import "./chunk-VC23AJJJ.js";
|
|
8
|
+
import "./chunk-FPDW535D.js";
|
|
9
|
+
import "./chunk-HRHAMPOB.js";
|
|
9
10
|
import "./chunk-M57VI7KL.js";
|
|
10
11
|
|
|
11
12
|
// src/agent.ts
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DiracParser
|
|
3
|
+
} from "./chunk-HRHAMPOB.js";
|
|
4
|
+
import {
|
|
5
|
+
emit,
|
|
6
|
+
setVariable
|
|
7
|
+
} from "./chunk-M57VI7KL.js";
|
|
8
|
+
|
|
9
|
+
// src/runtime/subroutine-registry.ts
|
|
10
|
+
import * as fs from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import * as os from "os";
|
|
13
|
+
var SubroutineRegistry = class {
|
|
14
|
+
indexPath;
|
|
15
|
+
index;
|
|
16
|
+
constructor(indexPath) {
|
|
17
|
+
this.indexPath = indexPath || path.join(os.homedir(), ".dirac", "subroutine-index.json");
|
|
18
|
+
this.index = this.loadIndex();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load index from disk
|
|
22
|
+
*/
|
|
23
|
+
loadIndex() {
|
|
24
|
+
if (fs.existsSync(this.indexPath)) {
|
|
25
|
+
try {
|
|
26
|
+
const data = fs.readFileSync(this.indexPath, "utf-8");
|
|
27
|
+
return JSON.parse(data);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error("Error loading subroutine index:", err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
subroutines: [],
|
|
34
|
+
lastUpdated: Date.now()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Save index to disk
|
|
39
|
+
*/
|
|
40
|
+
saveIndex() {
|
|
41
|
+
const dir = path.dirname(this.indexPath);
|
|
42
|
+
if (!fs.existsSync(dir)) {
|
|
43
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
this.index.lastUpdated = Date.now();
|
|
46
|
+
fs.writeFileSync(this.indexPath, JSON.stringify(this.index, null, 2), "utf-8");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Scan a directory for .di files and index all subroutines
|
|
50
|
+
*/
|
|
51
|
+
async indexDirectory(dirPath) {
|
|
52
|
+
let count = 0;
|
|
53
|
+
const absoluteDirPath = path.isAbsolute(dirPath) ? dirPath : path.resolve(process.cwd(), dirPath);
|
|
54
|
+
const scanDir = (dir) => {
|
|
55
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
const fullPath = path.join(dir, entry.name);
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
scanDir(fullPath);
|
|
60
|
+
} else if (entry.isFile() && entry.name.endsWith(".di")) {
|
|
61
|
+
count += this.indexFile(fullPath);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
scanDir(absoluteDirPath);
|
|
66
|
+
this.saveIndex();
|
|
67
|
+
return count;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Index a single .di file
|
|
71
|
+
*/
|
|
72
|
+
indexFile(filePath) {
|
|
73
|
+
try {
|
|
74
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
75
|
+
const parser = new DiracParser();
|
|
76
|
+
const ast = parser.parse(content);
|
|
77
|
+
this.index.subroutines = this.index.subroutines.filter((s) => s.filePath !== filePath);
|
|
78
|
+
const subroutines = this.extractSubroutines(ast, filePath);
|
|
79
|
+
this.index.subroutines.push(...subroutines);
|
|
80
|
+
this.saveIndex();
|
|
81
|
+
return subroutines.length;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (process.env.DEBUG_REGISTRY === "1") {
|
|
84
|
+
console.error(`Error indexing ${filePath}:`, err);
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extract subroutines from AST
|
|
91
|
+
*/
|
|
92
|
+
extractSubroutines(element, filePath) {
|
|
93
|
+
const subroutines = [];
|
|
94
|
+
if (element.tag === "subroutine") {
|
|
95
|
+
const name = element.attributes.name;
|
|
96
|
+
if (name) {
|
|
97
|
+
const metadata = {
|
|
98
|
+
name,
|
|
99
|
+
description: element.attributes.description,
|
|
100
|
+
parameters: [],
|
|
101
|
+
filePath
|
|
102
|
+
};
|
|
103
|
+
for (const [attrName, attrValue] of Object.entries(element.attributes)) {
|
|
104
|
+
if (attrName.startsWith("param-")) {
|
|
105
|
+
const paramName = attrName.substring(6);
|
|
106
|
+
const parts = attrValue.split(":");
|
|
107
|
+
metadata.parameters.push({
|
|
108
|
+
name: paramName,
|
|
109
|
+
type: parts[0] || "any",
|
|
110
|
+
required: parts[1] === "required",
|
|
111
|
+
description: parts[2]
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
subroutines.push(metadata);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (element.children) {
|
|
119
|
+
for (const child of element.children) {
|
|
120
|
+
subroutines.push(...this.extractSubroutines(child, filePath));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return subroutines;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Simple text search (will be replaced with vector search)
|
|
127
|
+
* Supports multi-word queries by tokenizing and matching individual words
|
|
128
|
+
*/
|
|
129
|
+
search(query, limit = 10) {
|
|
130
|
+
const lowerQuery = query.toLowerCase();
|
|
131
|
+
const queryTokens = lowerQuery.split(/[\s\-_]+/).filter((t) => t.length > 0);
|
|
132
|
+
const results = this.index.subroutines.map((sub) => {
|
|
133
|
+
let score = 0;
|
|
134
|
+
const lowerName = sub.name.toLowerCase();
|
|
135
|
+
const lowerDesc = (sub.description || "").toLowerCase();
|
|
136
|
+
const nameTokens = lowerName.split(/[\s\-_]+/);
|
|
137
|
+
if (lowerName === lowerQuery) {
|
|
138
|
+
score += 100;
|
|
139
|
+
} else if (lowerName.includes(lowerQuery)) {
|
|
140
|
+
score += 50;
|
|
141
|
+
} else if (lowerDesc.includes(lowerQuery)) {
|
|
142
|
+
score += 30;
|
|
143
|
+
}
|
|
144
|
+
let tokenMatchCount = 0;
|
|
145
|
+
for (const queryToken of queryTokens) {
|
|
146
|
+
if (queryToken.length <= 2) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (nameTokens.some((nt) => nt === queryToken)) {
|
|
150
|
+
score += 40;
|
|
151
|
+
tokenMatchCount++;
|
|
152
|
+
} else if (nameTokens.some((nt) => nt.startsWith(queryToken))) {
|
|
153
|
+
score += 20;
|
|
154
|
+
tokenMatchCount++;
|
|
155
|
+
}
|
|
156
|
+
const descWords = lowerDesc.split(/[\s\-_]+/);
|
|
157
|
+
if (descWords.some((w) => w === queryToken || w.startsWith(queryToken))) {
|
|
158
|
+
score += 15;
|
|
159
|
+
tokenMatchCount++;
|
|
160
|
+
}
|
|
161
|
+
for (const param of sub.parameters) {
|
|
162
|
+
const lowerParamName = param.name.toLowerCase();
|
|
163
|
+
if (lowerParamName === queryToken) {
|
|
164
|
+
score += 10;
|
|
165
|
+
tokenMatchCount++;
|
|
166
|
+
} else if (lowerParamName.startsWith(queryToken)) {
|
|
167
|
+
score += 5;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (queryTokens.length > 1 && tokenMatchCount >= queryTokens.length * 0.5) {
|
|
172
|
+
score += 25;
|
|
173
|
+
}
|
|
174
|
+
return { sub, score };
|
|
175
|
+
}).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, limit).map((r) => r.sub);
|
|
176
|
+
return results;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get all subroutines
|
|
180
|
+
*/
|
|
181
|
+
getAll() {
|
|
182
|
+
return this.index.subroutines;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get statistics
|
|
186
|
+
*/
|
|
187
|
+
getStats() {
|
|
188
|
+
const files = new Set(this.index.subroutines.map((s) => s.filePath));
|
|
189
|
+
return {
|
|
190
|
+
totalSubroutines: this.index.subroutines.length,
|
|
191
|
+
totalFiles: files.size,
|
|
192
|
+
lastUpdated: new Date(this.index.lastUpdated)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Auto-index stdlib if index is empty (first run)
|
|
197
|
+
* Returns true if indexing was performed
|
|
198
|
+
*/
|
|
199
|
+
async autoIndexStdlib() {
|
|
200
|
+
if (this.index.subroutines.length > 0) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const { createRequire } = await import("module");
|
|
205
|
+
const require2 = createRequire(import.meta.url);
|
|
206
|
+
const stdlibPackagePath = require2.resolve("dirac-stdlib/package.json");
|
|
207
|
+
const stdlibLibPath = path.join(path.dirname(stdlibPackagePath), "lib");
|
|
208
|
+
if (fs.existsSync(stdlibLibPath)) {
|
|
209
|
+
console.log("First run detected. Indexing standard library...");
|
|
210
|
+
const count = await this.indexDirectory(stdlibLibPath);
|
|
211
|
+
console.log(`Indexed ${count} subroutines from dirac-stdlib`);
|
|
212
|
+
console.log("You can now use |load-context> to find and load subroutines!\n");
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
} catch (err) {
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// src/tags/subroutine-index.ts
|
|
222
|
+
var registry = new SubroutineRegistry();
|
|
223
|
+
async function executeIndexSubroutines(session, element) {
|
|
224
|
+
const pathAttr = element.attributes.path;
|
|
225
|
+
if (!pathAttr) {
|
|
226
|
+
throw new Error("<index-subroutines> requires path attribute");
|
|
227
|
+
}
|
|
228
|
+
const count = await registry.indexDirectory(pathAttr);
|
|
229
|
+
if (session.debug) {
|
|
230
|
+
emit(session, `Indexed ${count} subroutines from ${pathAttr}
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function executeSearchSubroutines(session, element) {
|
|
235
|
+
const query = element.attributes.query;
|
|
236
|
+
const limitAttr = element.attributes.limit;
|
|
237
|
+
const outputVar = element.attributes.output;
|
|
238
|
+
const format = element.attributes.format || "text";
|
|
239
|
+
if (!query) {
|
|
240
|
+
throw new Error("<search-subroutines> requires query attribute");
|
|
241
|
+
}
|
|
242
|
+
const limit = limitAttr ? parseInt(limitAttr, 10) : 10;
|
|
243
|
+
const results = registry.search(query, limit);
|
|
244
|
+
let output = "";
|
|
245
|
+
switch (format) {
|
|
246
|
+
case "json":
|
|
247
|
+
output = JSON.stringify(results, null, 2);
|
|
248
|
+
break;
|
|
249
|
+
case "xml":
|
|
250
|
+
output = "<subroutines>\n";
|
|
251
|
+
for (const sub of results) {
|
|
252
|
+
const params = sub.parameters.map((p) => `param-${p.name}="${p.type}"`).join(" ");
|
|
253
|
+
output += ` <subroutine name="${sub.name}" ${params} file="${sub.filePath}"/>
|
|
254
|
+
`;
|
|
255
|
+
if (sub.description) {
|
|
256
|
+
output += ` <!-- ${sub.description} -->
|
|
257
|
+
`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
output += "</subroutines>";
|
|
261
|
+
break;
|
|
262
|
+
case "text":
|
|
263
|
+
default:
|
|
264
|
+
if (results.length === 0) {
|
|
265
|
+
output = "No subroutines found.\n";
|
|
266
|
+
} else {
|
|
267
|
+
output = `Found ${results.length} subroutine(s):
|
|
268
|
+
|
|
269
|
+
`;
|
|
270
|
+
for (const sub of results) {
|
|
271
|
+
output += `${sub.name}(${sub.parameters.map((p) => p.name).join(", ")})
|
|
272
|
+
`;
|
|
273
|
+
if (sub.description) {
|
|
274
|
+
output += ` ${sub.description}
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
output += ` File: ${sub.filePath}
|
|
278
|
+
|
|
279
|
+
`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
if (outputVar) {
|
|
285
|
+
setVariable(session, outputVar, output, false);
|
|
286
|
+
} else {
|
|
287
|
+
emit(session, output);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function executeRegistryStats(session, element) {
|
|
291
|
+
const stats = registry.getStats();
|
|
292
|
+
const output = `Subroutine Registry Statistics:
|
|
293
|
+
Total Subroutines: ${stats.totalSubroutines}
|
|
294
|
+
Total Files: ${stats.totalFiles}
|
|
295
|
+
Last Updated: ${stats.lastUpdated.toLocaleString()}
|
|
296
|
+
`;
|
|
297
|
+
emit(session, output);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export {
|
|
301
|
+
registry,
|
|
302
|
+
executeIndexSubroutines,
|
|
303
|
+
executeSearchSubroutines,
|
|
304
|
+
executeRegistryStats
|
|
305
|
+
};
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DiracParser
|
|
3
|
-
} from "./chunk-HRHAMPOB.js";
|
|
4
1
|
import {
|
|
5
2
|
executeSubroutine
|
|
6
3
|
} from "./chunk-VC23AJJJ.js";
|
|
4
|
+
import {
|
|
5
|
+
executeIndexSubroutines,
|
|
6
|
+
executeRegistryStats,
|
|
7
|
+
executeSearchSubroutines,
|
|
8
|
+
registry
|
|
9
|
+
} from "./chunk-FPDW535D.js";
|
|
10
|
+
import {
|
|
11
|
+
DiracParser
|
|
12
|
+
} from "./chunk-HRHAMPOB.js";
|
|
7
13
|
import {
|
|
8
14
|
CustomLLMProvider,
|
|
9
15
|
OllamaProvider,
|
|
@@ -481,12 +487,12 @@ async function executeIf(session, element) {
|
|
|
481
487
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
482
488
|
if (condition) {
|
|
483
489
|
if (thenElement) {
|
|
484
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
490
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
485
491
|
await integrateChildren2(session, thenElement);
|
|
486
492
|
}
|
|
487
493
|
} else {
|
|
488
494
|
if (elseElement) {
|
|
489
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
495
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
490
496
|
await integrateChildren2(session, elseElement);
|
|
491
497
|
}
|
|
492
498
|
}
|
|
@@ -499,7 +505,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
499
505
|
return await evaluateCondition(session, predicateElement);
|
|
500
506
|
}
|
|
501
507
|
const outputLengthBefore = session.output.length;
|
|
502
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
508
|
+
const { integrate: integrate2 } = await import("./interpreter-X5V2FFGI.js");
|
|
503
509
|
await integrate2(session, predicateElement);
|
|
504
510
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
505
511
|
const result = newOutputChunks.join("").trim();
|
|
@@ -522,11 +528,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
522
528
|
}
|
|
523
529
|
const outputLengthBefore = session.output.length;
|
|
524
530
|
const args = [];
|
|
525
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
531
|
+
const { integrate: integrate2 } = await import("./interpreter-X5V2FFGI.js");
|
|
526
532
|
for (const child of condElement.children) {
|
|
527
533
|
if (child.tag.toLowerCase() === "arg") {
|
|
528
534
|
const argOutputStart = session.output.length;
|
|
529
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
535
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
530
536
|
await integrateChildren2(session, child);
|
|
531
537
|
const newChunks = session.output.slice(argOutputStart);
|
|
532
538
|
const argValue = newChunks.join("");
|
|
@@ -1232,11 +1238,11 @@ ${expr}
|
|
|
1232
1238
|
for (const v of session.variables) {
|
|
1233
1239
|
context[v.name] = v.value;
|
|
1234
1240
|
}
|
|
1235
|
-
const { default:
|
|
1236
|
-
const { default:
|
|
1241
|
+
const { default: fs5 } = await import("fs");
|
|
1242
|
+
const { default: path3 } = await import("path");
|
|
1237
1243
|
const { fileURLToPath } = await import("url");
|
|
1238
|
-
context.fs =
|
|
1239
|
-
context.path =
|
|
1244
|
+
context.fs = fs5;
|
|
1245
|
+
context.path = path3;
|
|
1240
1246
|
context.__dirname = process.cwd();
|
|
1241
1247
|
context.getParams = () => {
|
|
1242
1248
|
const params = session.parameterStack[session.parameterStack.length - 1];
|
|
@@ -1307,7 +1313,7 @@ import { readFileSync, existsSync as existsSync3 } from "fs";
|
|
|
1307
1313
|
import { resolve, dirname as dirname2, join as join2 } from "path";
|
|
1308
1314
|
import { homedir as homedir2 } from "os";
|
|
1309
1315
|
function resolveImportPath(src, currentDir, libraryPaths = []) {
|
|
1310
|
-
const ensureDiExtension = (
|
|
1316
|
+
const ensureDiExtension = (path3) => path3.endsWith(".di") ? path3 : path3 + ".di";
|
|
1311
1317
|
const tryResolveInBase = (basePath, modulePath) => {
|
|
1312
1318
|
const fullPath = join2(basePath, modulePath);
|
|
1313
1319
|
const withExtension = ensureDiExtension(fullPath);
|
|
@@ -1750,7 +1756,7 @@ async function executeTagCheck(session, element) {
|
|
|
1750
1756
|
const executeTag = correctedTag || tagName;
|
|
1751
1757
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1752
1758
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1753
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1759
|
+
const { integrate: integrate2 } = await import("./interpreter-X5V2FFGI.js");
|
|
1754
1760
|
await integrate2(session, elementToExecute);
|
|
1755
1761
|
}
|
|
1756
1762
|
}
|
|
@@ -1759,7 +1765,7 @@ async function executeTagCheck(session, element) {
|
|
|
1759
1765
|
// src/tags/throw.ts
|
|
1760
1766
|
async function executeThrow(session, element) {
|
|
1761
1767
|
const exceptionName = element.attributes?.name || "exception";
|
|
1762
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1768
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
1763
1769
|
const exceptionDom = {
|
|
1764
1770
|
tag: "exception-content",
|
|
1765
1771
|
attributes: { name: exceptionName },
|
|
@@ -1772,7 +1778,7 @@ async function executeThrow(session, element) {
|
|
|
1772
1778
|
// src/tags/try.ts
|
|
1773
1779
|
async function executeTry(session, element) {
|
|
1774
1780
|
setExceptionBoundary(session);
|
|
1775
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1781
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
1776
1782
|
await integrateChildren2(session, element);
|
|
1777
1783
|
unsetExceptionBoundary(session);
|
|
1778
1784
|
}
|
|
@@ -1782,7 +1788,7 @@ async function executeCatch(session, element) {
|
|
|
1782
1788
|
const exceptionName = element.attributes?.name || "exception";
|
|
1783
1789
|
const caughtCount = lookupException(session, exceptionName);
|
|
1784
1790
|
if (caughtCount > 0) {
|
|
1785
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1791
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
1786
1792
|
await integrateChildren2(session, element);
|
|
1787
1793
|
}
|
|
1788
1794
|
flushCurrentException(session);
|
|
@@ -1791,7 +1797,7 @@ async function executeCatch(session, element) {
|
|
|
1791
1797
|
// src/tags/exception.ts
|
|
1792
1798
|
async function executeException(session, element) {
|
|
1793
1799
|
const exceptions = getCurrentExceptions(session);
|
|
1794
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1800
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-X5V2FFGI.js");
|
|
1795
1801
|
for (const exceptionDom of exceptions) {
|
|
1796
1802
|
await integrateChildren2(session, exceptionDom);
|
|
1797
1803
|
}
|
|
@@ -1985,273 +1991,6 @@ function formatAsText(subroutines) {
|
|
|
1985
1991
|
return lines.join("\n");
|
|
1986
1992
|
}
|
|
1987
1993
|
|
|
1988
|
-
// src/runtime/subroutine-registry.ts
|
|
1989
|
-
import * as fs4 from "fs";
|
|
1990
|
-
import * as path3 from "path";
|
|
1991
|
-
import * as os2 from "os";
|
|
1992
|
-
var SubroutineRegistry = class {
|
|
1993
|
-
indexPath;
|
|
1994
|
-
index;
|
|
1995
|
-
constructor(indexPath) {
|
|
1996
|
-
this.indexPath = indexPath || path3.join(os2.homedir(), ".dirac", "subroutine-index.json");
|
|
1997
|
-
this.index = this.loadIndex();
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Load index from disk
|
|
2001
|
-
*/
|
|
2002
|
-
loadIndex() {
|
|
2003
|
-
if (fs4.existsSync(this.indexPath)) {
|
|
2004
|
-
try {
|
|
2005
|
-
const data = fs4.readFileSync(this.indexPath, "utf-8");
|
|
2006
|
-
return JSON.parse(data);
|
|
2007
|
-
} catch (err) {
|
|
2008
|
-
console.error("Error loading subroutine index:", err);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
return {
|
|
2012
|
-
subroutines: [],
|
|
2013
|
-
lastUpdated: Date.now()
|
|
2014
|
-
};
|
|
2015
|
-
}
|
|
2016
|
-
/**
|
|
2017
|
-
* Save index to disk
|
|
2018
|
-
*/
|
|
2019
|
-
saveIndex() {
|
|
2020
|
-
const dir = path3.dirname(this.indexPath);
|
|
2021
|
-
if (!fs4.existsSync(dir)) {
|
|
2022
|
-
fs4.mkdirSync(dir, { recursive: true });
|
|
2023
|
-
}
|
|
2024
|
-
this.index.lastUpdated = Date.now();
|
|
2025
|
-
fs4.writeFileSync(this.indexPath, JSON.stringify(this.index, null, 2), "utf-8");
|
|
2026
|
-
}
|
|
2027
|
-
/**
|
|
2028
|
-
* Scan a directory for .di files and index all subroutines
|
|
2029
|
-
*/
|
|
2030
|
-
async indexDirectory(dirPath) {
|
|
2031
|
-
let count = 0;
|
|
2032
|
-
const absoluteDirPath = path3.isAbsolute(dirPath) ? dirPath : path3.resolve(process.cwd(), dirPath);
|
|
2033
|
-
const scanDir = (dir) => {
|
|
2034
|
-
const entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
2035
|
-
for (const entry of entries) {
|
|
2036
|
-
const fullPath = path3.join(dir, entry.name);
|
|
2037
|
-
if (entry.isDirectory()) {
|
|
2038
|
-
scanDir(fullPath);
|
|
2039
|
-
} else if (entry.isFile() && entry.name.endsWith(".di")) {
|
|
2040
|
-
count += this.indexFile(fullPath);
|
|
2041
|
-
}
|
|
2042
|
-
}
|
|
2043
|
-
};
|
|
2044
|
-
scanDir(absoluteDirPath);
|
|
2045
|
-
this.saveIndex();
|
|
2046
|
-
return count;
|
|
2047
|
-
}
|
|
2048
|
-
/**
|
|
2049
|
-
* Index a single .di file
|
|
2050
|
-
*/
|
|
2051
|
-
indexFile(filePath) {
|
|
2052
|
-
try {
|
|
2053
|
-
const content = fs4.readFileSync(filePath, "utf-8");
|
|
2054
|
-
const parser = new DiracParser();
|
|
2055
|
-
const ast = parser.parse(content);
|
|
2056
|
-
this.index.subroutines = this.index.subroutines.filter((s) => s.filePath !== filePath);
|
|
2057
|
-
const subroutines = this.extractSubroutines(ast, filePath);
|
|
2058
|
-
this.index.subroutines.push(...subroutines);
|
|
2059
|
-
this.saveIndex();
|
|
2060
|
-
return subroutines.length;
|
|
2061
|
-
} catch (err) {
|
|
2062
|
-
if (process.env.DEBUG_REGISTRY === "1") {
|
|
2063
|
-
console.error(`Error indexing ${filePath}:`, err);
|
|
2064
|
-
}
|
|
2065
|
-
return 0;
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
/**
|
|
2069
|
-
* Extract subroutines from AST
|
|
2070
|
-
*/
|
|
2071
|
-
extractSubroutines(element, filePath) {
|
|
2072
|
-
const subroutines = [];
|
|
2073
|
-
if (element.tag === "subroutine") {
|
|
2074
|
-
const name = element.attributes.name;
|
|
2075
|
-
if (name) {
|
|
2076
|
-
const metadata = {
|
|
2077
|
-
name,
|
|
2078
|
-
description: element.attributes.description,
|
|
2079
|
-
parameters: [],
|
|
2080
|
-
filePath
|
|
2081
|
-
};
|
|
2082
|
-
for (const [attrName, attrValue] of Object.entries(element.attributes)) {
|
|
2083
|
-
if (attrName.startsWith("param-")) {
|
|
2084
|
-
const paramName = attrName.substring(6);
|
|
2085
|
-
const parts = attrValue.split(":");
|
|
2086
|
-
metadata.parameters.push({
|
|
2087
|
-
name: paramName,
|
|
2088
|
-
type: parts[0] || "any",
|
|
2089
|
-
required: parts[1] === "required",
|
|
2090
|
-
description: parts[2]
|
|
2091
|
-
});
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
subroutines.push(metadata);
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
if (element.children) {
|
|
2098
|
-
for (const child of element.children) {
|
|
2099
|
-
subroutines.push(...this.extractSubroutines(child, filePath));
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
return subroutines;
|
|
2103
|
-
}
|
|
2104
|
-
/**
|
|
2105
|
-
* Simple text search (will be replaced with vector search)
|
|
2106
|
-
* Supports multi-word queries by tokenizing and matching individual words
|
|
2107
|
-
*/
|
|
2108
|
-
search(query, limit = 10) {
|
|
2109
|
-
const lowerQuery = query.toLowerCase();
|
|
2110
|
-
const queryTokens = lowerQuery.split(/[\s\-_]+/).filter((t) => t.length > 0);
|
|
2111
|
-
const results = this.index.subroutines.map((sub) => {
|
|
2112
|
-
let score = 0;
|
|
2113
|
-
const lowerName = sub.name.toLowerCase();
|
|
2114
|
-
const lowerDesc = (sub.description || "").toLowerCase();
|
|
2115
|
-
const nameTokens = lowerName.split(/[\s\-_]+/);
|
|
2116
|
-
if (lowerName === lowerQuery) {
|
|
2117
|
-
score += 100;
|
|
2118
|
-
} else if (lowerName.includes(lowerQuery)) {
|
|
2119
|
-
score += 50;
|
|
2120
|
-
} else if (lowerDesc.includes(lowerQuery)) {
|
|
2121
|
-
score += 30;
|
|
2122
|
-
}
|
|
2123
|
-
let tokenMatchCount = 0;
|
|
2124
|
-
for (const queryToken of queryTokens) {
|
|
2125
|
-
if (queryToken.length <= 2) {
|
|
2126
|
-
continue;
|
|
2127
|
-
}
|
|
2128
|
-
if (nameTokens.some((nt) => nt === queryToken)) {
|
|
2129
|
-
score += 40;
|
|
2130
|
-
tokenMatchCount++;
|
|
2131
|
-
} else if (nameTokens.some((nt) => nt.startsWith(queryToken))) {
|
|
2132
|
-
score += 20;
|
|
2133
|
-
tokenMatchCount++;
|
|
2134
|
-
}
|
|
2135
|
-
const descWords = lowerDesc.split(/[\s\-_]+/);
|
|
2136
|
-
if (descWords.some((w) => w === queryToken || w.startsWith(queryToken))) {
|
|
2137
|
-
score += 15;
|
|
2138
|
-
tokenMatchCount++;
|
|
2139
|
-
}
|
|
2140
|
-
for (const param of sub.parameters) {
|
|
2141
|
-
const lowerParamName = param.name.toLowerCase();
|
|
2142
|
-
if (lowerParamName === queryToken) {
|
|
2143
|
-
score += 10;
|
|
2144
|
-
tokenMatchCount++;
|
|
2145
|
-
} else if (lowerParamName.startsWith(queryToken)) {
|
|
2146
|
-
score += 5;
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
if (queryTokens.length > 1 && tokenMatchCount >= queryTokens.length * 0.5) {
|
|
2151
|
-
score += 25;
|
|
2152
|
-
}
|
|
2153
|
-
return { sub, score };
|
|
2154
|
-
}).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, limit).map((r) => r.sub);
|
|
2155
|
-
return results;
|
|
2156
|
-
}
|
|
2157
|
-
/**
|
|
2158
|
-
* Get all subroutines
|
|
2159
|
-
*/
|
|
2160
|
-
getAll() {
|
|
2161
|
-
return this.index.subroutines;
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Get statistics
|
|
2165
|
-
*/
|
|
2166
|
-
getStats() {
|
|
2167
|
-
const files = new Set(this.index.subroutines.map((s) => s.filePath));
|
|
2168
|
-
return {
|
|
2169
|
-
totalSubroutines: this.index.subroutines.length,
|
|
2170
|
-
totalFiles: files.size,
|
|
2171
|
-
lastUpdated: new Date(this.index.lastUpdated)
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
};
|
|
2175
|
-
|
|
2176
|
-
// src/tags/subroutine-index.ts
|
|
2177
|
-
var registry = new SubroutineRegistry();
|
|
2178
|
-
async function executeIndexSubroutines(session, element) {
|
|
2179
|
-
const pathAttr = element.attributes.path;
|
|
2180
|
-
if (!pathAttr) {
|
|
2181
|
-
throw new Error("<index-subroutines> requires path attribute");
|
|
2182
|
-
}
|
|
2183
|
-
const count = await registry.indexDirectory(pathAttr);
|
|
2184
|
-
if (session.debug) {
|
|
2185
|
-
emit(session, `Indexed ${count} subroutines from ${pathAttr}
|
|
2186
|
-
`);
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
async function executeSearchSubroutines(session, element) {
|
|
2190
|
-
const query = element.attributes.query;
|
|
2191
|
-
const limitAttr = element.attributes.limit;
|
|
2192
|
-
const outputVar = element.attributes.output;
|
|
2193
|
-
const format = element.attributes.format || "text";
|
|
2194
|
-
if (!query) {
|
|
2195
|
-
throw new Error("<search-subroutines> requires query attribute");
|
|
2196
|
-
}
|
|
2197
|
-
const limit = limitAttr ? parseInt(limitAttr, 10) : 10;
|
|
2198
|
-
const results = registry.search(query, limit);
|
|
2199
|
-
let output = "";
|
|
2200
|
-
switch (format) {
|
|
2201
|
-
case "json":
|
|
2202
|
-
output = JSON.stringify(results, null, 2);
|
|
2203
|
-
break;
|
|
2204
|
-
case "xml":
|
|
2205
|
-
output = "<subroutines>\n";
|
|
2206
|
-
for (const sub of results) {
|
|
2207
|
-
const params = sub.parameters.map((p) => `param-${p.name}="${p.type}"`).join(" ");
|
|
2208
|
-
output += ` <subroutine name="${sub.name}" ${params} file="${sub.filePath}"/>
|
|
2209
|
-
`;
|
|
2210
|
-
if (sub.description) {
|
|
2211
|
-
output += ` <!-- ${sub.description} -->
|
|
2212
|
-
`;
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
output += "</subroutines>";
|
|
2216
|
-
break;
|
|
2217
|
-
case "text":
|
|
2218
|
-
default:
|
|
2219
|
-
if (results.length === 0) {
|
|
2220
|
-
output = "No subroutines found.\n";
|
|
2221
|
-
} else {
|
|
2222
|
-
output = `Found ${results.length} subroutine(s):
|
|
2223
|
-
|
|
2224
|
-
`;
|
|
2225
|
-
for (const sub of results) {
|
|
2226
|
-
output += `${sub.name}(${sub.parameters.map((p) => p.name).join(", ")})
|
|
2227
|
-
`;
|
|
2228
|
-
if (sub.description) {
|
|
2229
|
-
output += ` ${sub.description}
|
|
2230
|
-
`;
|
|
2231
|
-
}
|
|
2232
|
-
output += ` File: ${sub.filePath}
|
|
2233
|
-
|
|
2234
|
-
`;
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
|
-
break;
|
|
2238
|
-
}
|
|
2239
|
-
if (outputVar) {
|
|
2240
|
-
setVariable(session, outputVar, output, false);
|
|
2241
|
-
} else {
|
|
2242
|
-
emit(session, output);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
async function executeRegistryStats(session, element) {
|
|
2246
|
-
const stats = registry.getStats();
|
|
2247
|
-
const output = `Subroutine Registry Statistics:
|
|
2248
|
-
Total Subroutines: ${stats.totalSubroutines}
|
|
2249
|
-
Total Files: ${stats.totalFiles}
|
|
2250
|
-
Last Updated: ${stats.lastUpdated.toLocaleString()}
|
|
2251
|
-
`;
|
|
2252
|
-
emit(session, output);
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
1994
|
// src/tags/load-context.ts
|
|
2256
1995
|
async function executeLoadContext(session, element) {
|
|
2257
1996
|
let query = element.attributes.query;
|
|
@@ -2259,7 +1998,7 @@ async function executeLoadContext(session, element) {
|
|
|
2259
1998
|
query = element.text.trim();
|
|
2260
1999
|
}
|
|
2261
2000
|
if (!query && element.children.length > 0) {
|
|
2262
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
2001
|
+
const { integrate: integrate2 } = await import("./interpreter-X5V2FFGI.js");
|
|
2263
2002
|
const beforeOutput = session.output.length;
|
|
2264
2003
|
for (const child of element.children) {
|
|
2265
2004
|
await integrate2(session, child);
|
|
@@ -2301,8 +2040,8 @@ async function executeLoadContext(session, element) {
|
|
|
2301
2040
|
if (shouldImport) {
|
|
2302
2041
|
for (const filePath of fileMap.keys()) {
|
|
2303
2042
|
try {
|
|
2304
|
-
const { resolve:
|
|
2305
|
-
const absolutePath = filePath.startsWith("/") ? filePath :
|
|
2043
|
+
const { resolve: resolve3 } = await import("path");
|
|
2044
|
+
const absolutePath = filePath.startsWith("/") ? filePath : resolve3(process.cwd(), filePath);
|
|
2306
2045
|
const importElement = {
|
|
2307
2046
|
tag: "import",
|
|
2308
2047
|
attributes: { src: absolutePath },
|
|
@@ -2334,9 +2073,9 @@ async function executeLoadContext(session, element) {
|
|
|
2334
2073
|
}
|
|
2335
2074
|
|
|
2336
2075
|
// src/tags/save-subroutine.ts
|
|
2337
|
-
import { writeFileSync as
|
|
2338
|
-
import { resolve as
|
|
2339
|
-
import { homedir as
|
|
2076
|
+
import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, existsSync as existsSync4 } from "fs";
|
|
2077
|
+
import { resolve as resolve2, dirname as dirname3, join as join3 } from "path";
|
|
2078
|
+
import { homedir as homedir3 } from "os";
|
|
2340
2079
|
async function executeSaveSubroutine(session, element) {
|
|
2341
2080
|
const name = element.attributes.name;
|
|
2342
2081
|
const file = element.attributes.file;
|
|
@@ -2363,21 +2102,21 @@ async function executeSaveSubroutine(session, element) {
|
|
|
2363
2102
|
}
|
|
2364
2103
|
let filePath;
|
|
2365
2104
|
if (file) {
|
|
2366
|
-
filePath =
|
|
2367
|
-
} else if (subroutine.sourcePath &&
|
|
2105
|
+
filePath = resolve2(process.cwd(), file);
|
|
2106
|
+
} else if (subroutine.sourcePath && existsSync4(dirname3(subroutine.sourcePath))) {
|
|
2368
2107
|
filePath = subroutine.sourcePath;
|
|
2369
2108
|
} else if (pathAttr) {
|
|
2370
|
-
const targetDir =
|
|
2371
|
-
filePath =
|
|
2109
|
+
const targetDir = join3(homedir3(), ".dirac", "lib", pathAttr);
|
|
2110
|
+
filePath = join3(targetDir, `${name}.di`);
|
|
2372
2111
|
} else {
|
|
2373
|
-
const defaultDir =
|
|
2374
|
-
filePath =
|
|
2112
|
+
const defaultDir = join3(homedir3(), ".dirac", "lib", "user");
|
|
2113
|
+
filePath = join3(defaultDir, `${name}.di`);
|
|
2375
2114
|
}
|
|
2376
|
-
const dir =
|
|
2377
|
-
if (!
|
|
2378
|
-
|
|
2115
|
+
const dir = dirname3(filePath);
|
|
2116
|
+
if (!existsSync4(dir)) {
|
|
2117
|
+
mkdirSync3(dir, { recursive: true });
|
|
2379
2118
|
}
|
|
2380
|
-
|
|
2119
|
+
writeFileSync3(filePath, content, "utf-8");
|
|
2381
2120
|
emit(session, `Subroutine '${name}' saved to: ${filePath}
|
|
2382
2121
|
`);
|
|
2383
2122
|
const savedSub = session.subroutines.find((s) => s.name === name);
|
|
@@ -2509,9 +2248,9 @@ function escapeXml3(text) {
|
|
|
2509
2248
|
}
|
|
2510
2249
|
|
|
2511
2250
|
// src/tags/edit-subroutine.ts
|
|
2512
|
-
import { writeFileSync as
|
|
2251
|
+
import { writeFileSync as writeFileSync4, readFileSync as readFileSync2, unlinkSync, existsSync as existsSync5 } from "fs";
|
|
2513
2252
|
import { tmpdir } from "os";
|
|
2514
|
-
import { join as
|
|
2253
|
+
import { join as join4 } from "path";
|
|
2515
2254
|
import { spawnSync } from "child_process";
|
|
2516
2255
|
async function executeEditSubroutine(session, element) {
|
|
2517
2256
|
const name = element.attributes.name;
|
|
@@ -2530,9 +2269,9 @@ async function executeEditSubroutine(session, element) {
|
|
|
2530
2269
|
throw new Error(`Subroutine '${name}' not found in session`);
|
|
2531
2270
|
}
|
|
2532
2271
|
let xml;
|
|
2533
|
-
if (subroutine.sourcePath &&
|
|
2272
|
+
if (subroutine.sourcePath && existsSync5(subroutine.sourcePath)) {
|
|
2534
2273
|
try {
|
|
2535
|
-
const sourceContent =
|
|
2274
|
+
const sourceContent = readFileSync2(subroutine.sourcePath, "utf-8");
|
|
2536
2275
|
const match = sourceContent.match(
|
|
2537
2276
|
new RegExp(`<subroutine\\s+name="${name}"[\\s\\S]*?<\\/subroutine>`, "i")
|
|
2538
2277
|
);
|
|
@@ -2559,8 +2298,8 @@ async function executeEditSubroutine(session, element) {
|
|
|
2559
2298
|
console.error(`[edit-subroutine] No source file, serializing from AST`);
|
|
2560
2299
|
}
|
|
2561
2300
|
}
|
|
2562
|
-
const tempFile =
|
|
2563
|
-
|
|
2301
|
+
const tempFile = join4(tmpdir(), `dirac-edit-${name}-${Date.now()}.di`);
|
|
2302
|
+
writeFileSync4(tempFile, xml, "utf-8");
|
|
2564
2303
|
if (session.debug) {
|
|
2565
2304
|
console.error(`[edit-subroutine] Wrote '${name}' to temp file: ${tempFile}`);
|
|
2566
2305
|
console.error(`[edit-subroutine] Opening with editor: ${editor}`);
|
|
@@ -2578,7 +2317,7 @@ async function executeEditSubroutine(session, element) {
|
|
|
2578
2317
|
unlinkSync(tempFile);
|
|
2579
2318
|
throw new Error(`Editor exited with code ${result.status}`);
|
|
2580
2319
|
}
|
|
2581
|
-
const editedContent =
|
|
2320
|
+
const editedContent = readFileSync2(tempFile, "utf-8");
|
|
2582
2321
|
unlinkSync(tempFile);
|
|
2583
2322
|
if (session.debug) {
|
|
2584
2323
|
console.error(`[edit-subroutine] Editor closed, re-importing subroutine`);
|
|
@@ -2690,7 +2429,7 @@ async function executeForeach(session, element) {
|
|
|
2690
2429
|
const parser2 = new DiracParser2();
|
|
2691
2430
|
try {
|
|
2692
2431
|
const fromElement = parser2.parse(fromAttr);
|
|
2693
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
2432
|
+
const { integrate: integrate2 } = await import("./interpreter-X5V2FFGI.js");
|
|
2694
2433
|
await integrate2(session, fromElement);
|
|
2695
2434
|
} catch (e) {
|
|
2696
2435
|
session.output = savedOutput;
|
|
@@ -2838,7 +2577,7 @@ async function executeEnvironment(session, element) {
|
|
|
2838
2577
|
}
|
|
2839
2578
|
|
|
2840
2579
|
// src/tags/input.ts
|
|
2841
|
-
import * as
|
|
2580
|
+
import * as fs4 from "fs";
|
|
2842
2581
|
import * as readline from "readline";
|
|
2843
2582
|
var fileReaders = /* @__PURE__ */ new Map();
|
|
2844
2583
|
var fileIterators = /* @__PURE__ */ new Map();
|
|
@@ -2862,11 +2601,11 @@ async function executeInput(session, element) {
|
|
|
2862
2601
|
throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
|
|
2863
2602
|
}
|
|
2864
2603
|
} else if (source === "file") {
|
|
2865
|
-
const
|
|
2604
|
+
const path3 = substituteAttribute(session, pathAttr);
|
|
2866
2605
|
if (mode === "all") {
|
|
2867
|
-
value =
|
|
2606
|
+
value = fs4.readFileSync(path3, "utf-8");
|
|
2868
2607
|
} else if (mode === "line") {
|
|
2869
|
-
value = await readLineFromFile(
|
|
2608
|
+
value = await readLineFromFile(path3);
|
|
2870
2609
|
} else {
|
|
2871
2610
|
throw new Error(`<input> invalid mode: ${mode}. Use 'all' or 'line'`);
|
|
2872
2611
|
}
|
|
@@ -2879,7 +2618,7 @@ async function readAllStdin() {
|
|
|
2879
2618
|
process.stdin.removeAllListeners("data");
|
|
2880
2619
|
process.stdin.removeAllListeners("end");
|
|
2881
2620
|
process.stdin.removeAllListeners("error");
|
|
2882
|
-
return new Promise((
|
|
2621
|
+
return new Promise((resolve3, reject) => {
|
|
2883
2622
|
const chunks = [];
|
|
2884
2623
|
const onData = (chunk) => {
|
|
2885
2624
|
chunks.push(chunk);
|
|
@@ -2889,7 +2628,7 @@ async function readAllStdin() {
|
|
|
2889
2628
|
process.stdin.removeListener("data", onData);
|
|
2890
2629
|
process.stdin.removeListener("end", onEnd);
|
|
2891
2630
|
process.stdin.removeListener("error", onError);
|
|
2892
|
-
|
|
2631
|
+
resolve3(result);
|
|
2893
2632
|
};
|
|
2894
2633
|
const onError = (err) => {
|
|
2895
2634
|
process.stdin.removeListener("data", onData);
|
|
@@ -2923,23 +2662,23 @@ async function readLineStdin() {
|
|
|
2923
2662
|
}
|
|
2924
2663
|
return result.value;
|
|
2925
2664
|
}
|
|
2926
|
-
async function readLineFromFile(
|
|
2927
|
-
if (!fileReaders.has(
|
|
2928
|
-
const fileStream =
|
|
2665
|
+
async function readLineFromFile(path3) {
|
|
2666
|
+
if (!fileReaders.has(path3)) {
|
|
2667
|
+
const fileStream = fs4.createReadStream(path3);
|
|
2929
2668
|
const rl = readline.createInterface({
|
|
2930
2669
|
input: fileStream,
|
|
2931
2670
|
crlfDelay: Infinity
|
|
2932
2671
|
});
|
|
2933
|
-
fileReaders.set(
|
|
2934
|
-
fileIterators.set(
|
|
2672
|
+
fileReaders.set(path3, rl);
|
|
2673
|
+
fileIterators.set(path3, rl[Symbol.asyncIterator]());
|
|
2935
2674
|
}
|
|
2936
|
-
const iterator = fileIterators.get(
|
|
2675
|
+
const iterator = fileIterators.get(path3);
|
|
2937
2676
|
const result = await iterator.next();
|
|
2938
2677
|
if (result.done) {
|
|
2939
|
-
const reader = fileReaders.get(
|
|
2678
|
+
const reader = fileReaders.get(path3);
|
|
2940
2679
|
reader.close();
|
|
2941
|
-
fileReaders.delete(
|
|
2942
|
-
fileIterators.delete(
|
|
2680
|
+
fileReaders.delete(path3);
|
|
2681
|
+
fileIterators.delete(path3);
|
|
2943
2682
|
return "";
|
|
2944
2683
|
}
|
|
2945
2684
|
return result.value;
|
package/dist/cli.js
CHANGED
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
} from "./chunk-AJSYOXXZ.js";
|
|
5
5
|
import {
|
|
6
6
|
execute
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-HRHAMPOB.js";
|
|
7
|
+
} from "./chunk-VUMS53GF.js";
|
|
8
|
+
import "./chunk-TYIDNAZ7.js";
|
|
10
9
|
import "./chunk-VC23AJJJ.js";
|
|
10
|
+
import "./chunk-FPDW535D.js";
|
|
11
|
+
import "./chunk-HRHAMPOB.js";
|
|
11
12
|
import "./chunk-M57VI7KL.js";
|
|
12
13
|
|
|
13
14
|
// src/cli.ts
|
|
@@ -16,7 +17,7 @@ import "dotenv/config";
|
|
|
16
17
|
// package.json
|
|
17
18
|
var package_default = {
|
|
18
19
|
name: "dirac-lang",
|
|
19
|
-
version: "0.1.
|
|
20
|
+
version: "0.1.76",
|
|
20
21
|
description: "LLM-Augmented Declarative Execution",
|
|
21
22
|
type: "module",
|
|
22
23
|
main: "dist/index.js",
|
|
@@ -138,7 +139,7 @@ async function main() {
|
|
|
138
139
|
const args = process.argv.slice(2);
|
|
139
140
|
const calledAs = process.argv[1];
|
|
140
141
|
if (calledAs && calledAs.endsWith("/dish")) {
|
|
141
|
-
const { DiracShell } = await import("./shell-
|
|
142
|
+
const { DiracShell } = await import("./shell-IUWCSKPG.js");
|
|
142
143
|
const shellConfig = loadShellConfig(args);
|
|
143
144
|
const shell = new DiracShell(shellConfig);
|
|
144
145
|
await shell.start();
|
|
@@ -187,11 +188,11 @@ async function main() {
|
|
|
187
188
|
if (args[0] === "agent") {
|
|
188
189
|
const subcommand = args[1];
|
|
189
190
|
if (subcommand === "daemon") {
|
|
190
|
-
const { runAgentDaemon } = await import("./agent-
|
|
191
|
+
const { runAgentDaemon } = await import("./agent-VAFUNYDM.js");
|
|
191
192
|
await runAgentDaemon();
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
194
|
-
const { AgentCLI } = await import("./agent-
|
|
195
|
+
const { AgentCLI } = await import("./agent-VAFUNYDM.js");
|
|
195
196
|
const agent = new AgentCLI();
|
|
196
197
|
switch (subcommand) {
|
|
197
198
|
case "start":
|
|
@@ -218,8 +219,8 @@ async function main() {
|
|
|
218
219
|
return;
|
|
219
220
|
}
|
|
220
221
|
if (args[0] === "shell") {
|
|
221
|
-
const { DiracShell } = await import("./shell-
|
|
222
|
-
const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-
|
|
222
|
+
const { DiracShell } = await import("./shell-IUWCSKPG.js");
|
|
223
|
+
const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-IDEV4CXY.js");
|
|
223
224
|
const { SessionClient } = await import("./session-client-3VTC5MLO.js");
|
|
224
225
|
const daemonMode = args.includes("--daemon") || args.includes("-d");
|
|
225
226
|
const agentMode = args.includes("--agent") || args.includes("-a");
|
|
@@ -265,7 +266,7 @@ async function main() {
|
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
267
268
|
if (args[0] === "daemon") {
|
|
268
|
-
const { SessionServer } = await import("./session-server-
|
|
269
|
+
const { SessionServer } = await import("./session-server-IDEV4CXY.js");
|
|
269
270
|
const server = new SessionServer();
|
|
270
271
|
await server.start();
|
|
271
272
|
console.log("Session daemon started");
|
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
listCronJobs,
|
|
4
4
|
stopAllCronJobs,
|
|
5
5
|
stopCronJob
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-HRHAMPOB.js";
|
|
6
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
8
7
|
import "./chunk-VC23AJJJ.js";
|
|
8
|
+
import "./chunk-FPDW535D.js";
|
|
9
|
+
import "./chunk-HRHAMPOB.js";
|
|
9
10
|
import "./chunk-M57VI7KL.js";
|
|
10
11
|
export {
|
|
11
12
|
executeCron,
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,15 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VUMS53GF.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
9
|
+
import "./chunk-VC23AJJJ.js";
|
|
10
|
+
import "./chunk-FPDW535D.js";
|
|
9
11
|
import {
|
|
10
12
|
DiracParser
|
|
11
13
|
} from "./chunk-HRHAMPOB.js";
|
|
12
|
-
import "./chunk-VC23AJJJ.js";
|
|
13
14
|
import {
|
|
14
15
|
createSession,
|
|
15
16
|
getAvailableSubroutines,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
integrate,
|
|
3
3
|
integrateChildren
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-HRHAMPOB.js";
|
|
4
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
6
5
|
import "./chunk-VC23AJJJ.js";
|
|
6
|
+
import "./chunk-FPDW535D.js";
|
|
7
|
+
import "./chunk-HRHAMPOB.js";
|
|
7
8
|
import "./chunk-M57VI7KL.js";
|
|
8
9
|
export {
|
|
9
10
|
integrate,
|
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
cancelScheduledRun,
|
|
4
4
|
executeRunAt,
|
|
5
5
|
listScheduledRuns
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-HRHAMPOB.js";
|
|
6
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
8
7
|
import "./chunk-VC23AJJJ.js";
|
|
8
|
+
import "./chunk-FPDW535D.js";
|
|
9
|
+
import "./chunk-HRHAMPOB.js";
|
|
9
10
|
import "./chunk-M57VI7KL.js";
|
|
10
11
|
export {
|
|
11
12
|
cancelAllScheduledRuns,
|
|
@@ -3,9 +3,10 @@ import {
|
|
|
3
3
|
listScheduledTasks,
|
|
4
4
|
stopAllScheduledTasks,
|
|
5
5
|
stopScheduledTask
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-HRHAMPOB.js";
|
|
6
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
8
7
|
import "./chunk-VC23AJJJ.js";
|
|
8
|
+
import "./chunk-FPDW535D.js";
|
|
9
|
+
import "./chunk-HRHAMPOB.js";
|
|
9
10
|
import "./chunk-M57VI7KL.js";
|
|
10
11
|
export {
|
|
11
12
|
executeSchedule,
|
|
@@ -2,10 +2,11 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-HRHAMPOB.js";
|
|
5
|
+
} from "./chunk-CLGQYGHT.js";
|
|
6
|
+
import "./chunk-TYIDNAZ7.js";
|
|
8
7
|
import "./chunk-VC23AJJJ.js";
|
|
8
|
+
import "./chunk-FPDW535D.js";
|
|
9
|
+
import "./chunk-HRHAMPOB.js";
|
|
9
10
|
import "./chunk-M57VI7KL.js";
|
|
10
11
|
export {
|
|
11
12
|
SessionServer,
|
|
@@ -4,11 +4,12 @@ import {
|
|
|
4
4
|
} from "./chunk-AJSYOXXZ.js";
|
|
5
5
|
import {
|
|
6
6
|
integrate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
8
|
+
import "./chunk-VC23AJJJ.js";
|
|
9
|
+
import "./chunk-FPDW535D.js";
|
|
8
10
|
import {
|
|
9
11
|
DiracParser
|
|
10
12
|
} from "./chunk-HRHAMPOB.js";
|
|
11
|
-
import "./chunk-VC23AJJJ.js";
|
|
12
13
|
import {
|
|
13
14
|
createSession
|
|
14
15
|
} from "./chunk-M57VI7KL.js";
|
|
@@ -359,7 +360,7 @@ var DiracShell = class {
|
|
|
359
360
|
if (this.client) {
|
|
360
361
|
this.client.disconnect();
|
|
361
362
|
}
|
|
362
|
-
import("./schedule-
|
|
363
|
+
import("./schedule-4B3KUC7T.js").then(({ stopAllScheduledTasks }) => {
|
|
363
364
|
stopAllScheduledTasks();
|
|
364
365
|
console.log("\nGoodbye!");
|
|
365
366
|
process.exit(0);
|
|
@@ -752,7 +753,7 @@ Examples:
|
|
|
752
753
|
break;
|
|
753
754
|
case "tasks":
|
|
754
755
|
try {
|
|
755
|
-
const { listScheduledTasks } = await import("./schedule-
|
|
756
|
+
const { listScheduledTasks } = await import("./schedule-4B3KUC7T.js");
|
|
756
757
|
const tasks = listScheduledTasks();
|
|
757
758
|
if (tasks.length === 0) {
|
|
758
759
|
console.log("No scheduled tasks running.");
|
|
@@ -771,7 +772,7 @@ Examples:
|
|
|
771
772
|
console.log("Usage: :stop <task-name>");
|
|
772
773
|
} else {
|
|
773
774
|
try {
|
|
774
|
-
const { stopScheduledTask } = await import("./schedule-
|
|
775
|
+
const { stopScheduledTask } = await import("./schedule-4B3KUC7T.js");
|
|
775
776
|
const taskName = args[0];
|
|
776
777
|
const stopped = stopScheduledTask(taskName);
|
|
777
778
|
if (stopped) {
|
|
@@ -786,7 +787,7 @@ Examples:
|
|
|
786
787
|
break;
|
|
787
788
|
case "stopall":
|
|
788
789
|
try {
|
|
789
|
-
const { stopAllScheduledTasks } = await import("./schedule-
|
|
790
|
+
const { stopAllScheduledTasks } = await import("./schedule-4B3KUC7T.js");
|
|
790
791
|
stopAllScheduledTasks();
|
|
791
792
|
console.log("All scheduled tasks stopped.");
|
|
792
793
|
} catch (error) {
|
|
@@ -795,7 +796,7 @@ Examples:
|
|
|
795
796
|
break;
|
|
796
797
|
case "crons":
|
|
797
798
|
try {
|
|
798
|
-
const { listCronJobs } = await import("./cron-
|
|
799
|
+
const { listCronJobs } = await import("./cron-RWSM6IBB.js");
|
|
799
800
|
const jobs = listCronJobs();
|
|
800
801
|
if (jobs.length === 0) {
|
|
801
802
|
console.log("No cron jobs running.");
|
|
@@ -815,7 +816,7 @@ Examples:
|
|
|
815
816
|
console.log("Usage: :stopcron <job-name>");
|
|
816
817
|
} else {
|
|
817
818
|
try {
|
|
818
|
-
const { stopCronJob } = await import("./cron-
|
|
819
|
+
const { stopCronJob } = await import("./cron-RWSM6IBB.js");
|
|
819
820
|
const jobName = args[0];
|
|
820
821
|
const stopped = stopCronJob(jobName);
|
|
821
822
|
if (stopped) {
|
|
@@ -830,7 +831,7 @@ Examples:
|
|
|
830
831
|
break;
|
|
831
832
|
case "stopallcrons":
|
|
832
833
|
try {
|
|
833
|
-
const { stopAllCronJobs } = await import("./cron-
|
|
834
|
+
const { stopAllCronJobs } = await import("./cron-RWSM6IBB.js");
|
|
834
835
|
stopAllCronJobs();
|
|
835
836
|
console.log("All cron jobs stopped.");
|
|
836
837
|
} catch (error) {
|
|
@@ -839,7 +840,7 @@ Examples:
|
|
|
839
840
|
break;
|
|
840
841
|
case "scheduled":
|
|
841
842
|
try {
|
|
842
|
-
const { listScheduledRuns } = await import("./run-at-
|
|
843
|
+
const { listScheduledRuns } = await import("./run-at-3QL4C4UD.js");
|
|
843
844
|
const runs = listScheduledRuns();
|
|
844
845
|
if (runs.length === 0) {
|
|
845
846
|
console.log("No scheduled runs pending.");
|
|
@@ -859,7 +860,7 @@ Examples:
|
|
|
859
860
|
console.log("Usage: :cancel <run-name>");
|
|
860
861
|
} else {
|
|
861
862
|
try {
|
|
862
|
-
const { cancelScheduledRun } = await import("./run-at-
|
|
863
|
+
const { cancelScheduledRun } = await import("./run-at-3QL4C4UD.js");
|
|
863
864
|
const runName = args[0];
|
|
864
865
|
const cancelled = cancelScheduledRun(runName);
|
|
865
866
|
if (cancelled) {
|
|
@@ -874,7 +875,7 @@ Examples:
|
|
|
874
875
|
break;
|
|
875
876
|
case "cancelall":
|
|
876
877
|
try {
|
|
877
|
-
const { cancelAllScheduledRuns } = await import("./run-at-
|
|
878
|
+
const { cancelAllScheduledRuns } = await import("./run-at-3QL4C4UD.js");
|
|
878
879
|
cancelAllScheduledRuns();
|
|
879
880
|
console.log("All scheduled runs cancelled.");
|
|
880
881
|
} catch (error) {
|
|
@@ -971,6 +972,8 @@ Examples:
|
|
|
971
972
|
console.log("Set ANTHROPIC_API_KEY or OPENAI_API_KEY environment variable,");
|
|
972
973
|
console.log("or create ~/.dirac/config.yml with llmProvider and llmModel.\n");
|
|
973
974
|
}
|
|
975
|
+
const { registry } = await import("./subroutine-index-7B5YXKAA.js");
|
|
976
|
+
await registry.autoIndexStdlib();
|
|
974
977
|
if (this.config.initScript) {
|
|
975
978
|
await this.runInitScript(this.config.initScript);
|
|
976
979
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeIndexSubroutines,
|
|
3
|
+
executeRegistryStats,
|
|
4
|
+
executeSearchSubroutines,
|
|
5
|
+
registry
|
|
6
|
+
} from "./chunk-FPDW535D.js";
|
|
7
|
+
import "./chunk-HRHAMPOB.js";
|
|
8
|
+
import "./chunk-M57VI7KL.js";
|
|
9
|
+
export {
|
|
10
|
+
executeIndexSubroutines,
|
|
11
|
+
executeRegistryStats,
|
|
12
|
+
executeSearchSubroutines,
|
|
13
|
+
registry
|
|
14
|
+
};
|
package/dist/test-runner.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
integrate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TYIDNAZ7.js";
|
|
4
|
+
import "./chunk-VC23AJJJ.js";
|
|
5
|
+
import "./chunk-FPDW535D.js";
|
|
4
6
|
import {
|
|
5
7
|
DiracParser
|
|
6
8
|
} from "./chunk-HRHAMPOB.js";
|
|
7
|
-
import "./chunk-VC23AJJJ.js";
|
|
8
9
|
import {
|
|
9
10
|
createSession,
|
|
10
11
|
getOutput
|