dirac-lang 0.1.97 → 0.1.98
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-MJSTQERB.js → agent-5Q5MQOV2.js} +3 -3
- package/dist/{chunk-KFMG6CZW.js → chunk-33DMGFRM.js} +1 -1
- package/dist/{chunk-4TBIVB4X.js → chunk-LAEYP4OQ.js} +137 -24
- package/dist/{chunk-CDTZNFCJ.js → chunk-MYWEN36N.js} +1 -1
- package/dist/cli.js +10 -10
- package/dist/{cron-2J3SEPZW.js → cron-VCUFU2WU.js} +2 -2
- package/dist/index.js +3 -3
- package/dist/{interpreter-4CIWAOBY.js → interpreter-D6ZF3OJA.js} +2 -2
- package/dist/{run-at-MHURF5PL.js → run-at-P43PK5JU.js} +2 -2
- package/dist/{schedule-KMBLI46W.js → schedule-3EJJHG3B.js} +2 -2
- package/dist/scope-validator-TVQIOEAI.js +171 -0
- package/dist/{session-server-TQPJVLA4.js → session-server-N53QIJO5.js} +3 -3
- package/dist/{shell-CY5XIPQC.js → shell-KNEQHL3Y.js} +21 -12
- package/dist/{tag-validator-REN6XLMT.js → tag-validator-DS7OCXCG.js} +109 -18
- package/dist/test-runner.js +2 -2
- package/package.json +1 -1
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-ECAW4X46.js";
|
|
5
|
+
} from "./chunk-33DMGFRM.js";
|
|
6
|
+
import "./chunk-LAEYP4OQ.js";
|
|
8
7
|
import "./chunk-SLGJRZ3P.js";
|
|
9
8
|
import "./chunk-HRHAMPOB.js";
|
|
9
|
+
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-PPH7KYKH.js";
|
|
11
11
|
|
|
12
12
|
// src/agent.ts
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeSubroutine
|
|
3
|
-
} from "./chunk-ECAW4X46.js";
|
|
4
1
|
import {
|
|
5
2
|
executeIndexSubroutines,
|
|
6
3
|
executeRegistryStats,
|
|
@@ -10,6 +7,9 @@ import {
|
|
|
10
7
|
import {
|
|
11
8
|
DiracParser
|
|
12
9
|
} from "./chunk-HRHAMPOB.js";
|
|
10
|
+
import {
|
|
11
|
+
executeSubroutine
|
|
12
|
+
} from "./chunk-ECAW4X46.js";
|
|
13
13
|
import {
|
|
14
14
|
CustomLLMProvider,
|
|
15
15
|
OllamaProvider,
|
|
@@ -487,12 +487,12 @@ async function executeIf(session, element) {
|
|
|
487
487
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
488
488
|
if (condition) {
|
|
489
489
|
if (thenElement) {
|
|
490
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
490
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
491
491
|
await integrateChildren2(session, thenElement);
|
|
492
492
|
}
|
|
493
493
|
} else {
|
|
494
494
|
if (elseElement) {
|
|
495
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
495
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
496
496
|
await integrateChildren2(session, elseElement);
|
|
497
497
|
}
|
|
498
498
|
}
|
|
@@ -505,7 +505,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
505
505
|
return await evaluateCondition(session, predicateElement);
|
|
506
506
|
}
|
|
507
507
|
const outputLengthBefore = session.output.length;
|
|
508
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
508
|
+
const { integrate: integrate2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
509
509
|
await integrate2(session, predicateElement);
|
|
510
510
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
511
511
|
const result = newOutputChunks.join("").trim();
|
|
@@ -528,11 +528,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
528
528
|
}
|
|
529
529
|
const outputLengthBefore = session.output.length;
|
|
530
530
|
const args = [];
|
|
531
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
531
|
+
const { integrate: integrate2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
532
532
|
for (const child of condElement.children) {
|
|
533
533
|
if (child.tag.toLowerCase() === "arg") {
|
|
534
534
|
const argOutputStart = session.output.length;
|
|
535
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
535
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
536
536
|
await integrateChildren2(session, child);
|
|
537
537
|
const newChunks = session.output.slice(argOutputStart);
|
|
538
538
|
const argValue = newChunks.join("");
|
|
@@ -1075,6 +1075,7 @@ ${result}
|
|
|
1075
1075
|
console.error(`[LLM] Feedback iteration ${iteration}/${maxIterations}`);
|
|
1076
1076
|
}
|
|
1077
1077
|
let correctionMessages = [];
|
|
1078
|
+
let hasTagCorrections = false;
|
|
1078
1079
|
let diracCode = result.trim();
|
|
1079
1080
|
if (replaceTick && diracCode.startsWith("```")) {
|
|
1080
1081
|
const match = diracCode.match(/^```(\w+)?\n?/m);
|
|
@@ -1086,16 +1087,20 @@ ${result}
|
|
|
1086
1087
|
diracCode = diracCode.replace(/^```(?:xml|html|dirac)?\n?/m, "").replace(/\n?```$/m, "").trim();
|
|
1087
1088
|
}
|
|
1088
1089
|
}
|
|
1089
|
-
const outputBefore =
|
|
1090
|
+
const outputBefore = session.output.length;
|
|
1090
1091
|
try {
|
|
1092
|
+
console.error(`[LLM] Iteration ${iteration}: Parsing LLM response`);
|
|
1091
1093
|
const parser = new DiracParser();
|
|
1092
1094
|
let dynamicAST = parser.parse(diracCode);
|
|
1095
|
+
console.error(`[LLM] Iteration ${iteration}: Parse successful`);
|
|
1093
1096
|
if (validateTags) {
|
|
1097
|
+
console.error(`[LLM] Iteration ${iteration}: Starting validation (autocorrect: ${autocorrect}, deepValidation: true)`);
|
|
1094
1098
|
if (session.debug) {
|
|
1095
1099
|
console.error(`[LLM] Validation enabled, autocorrect: ${autocorrect}`);
|
|
1096
1100
|
}
|
|
1097
|
-
const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-
|
|
1101
|
+
const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-DS7OCXCG.js");
|
|
1098
1102
|
let validation = await validateDiracCode(session, dynamicAST, { autocorrect, deepValidation: true });
|
|
1103
|
+
console.error(`[LLM] Iteration ${iteration}: Validation complete - valid: ${validation.valid}, errors: ${validation.errorMessages.length}`);
|
|
1099
1104
|
if (session.debug) {
|
|
1100
1105
|
console.error(`[LLM] Validation result: valid=${validation.valid}, results count=${validation.results.length}`);
|
|
1101
1106
|
if (validation.results.length > 0) {
|
|
@@ -1112,10 +1117,15 @@ ${result}
|
|
|
1112
1117
|
console.error(`[LLM] Applying corrections from initial ${validation.results.length} validation results`);
|
|
1113
1118
|
for (const result2 of validation.results) {
|
|
1114
1119
|
if (result2.corrected) {
|
|
1120
|
+
hasTagCorrections = true;
|
|
1115
1121
|
correctionMessages.push(`Auto-corrected: <${result2.originalTag}> \u2192 <${result2.tagName}> (similarity: ${result2.similarity?.toFixed(2)})`);
|
|
1116
1122
|
}
|
|
1117
1123
|
if (result2.warnings.length > 0) {
|
|
1118
|
-
|
|
1124
|
+
const nonScopeWarnings = result2.warnings.filter((w) => !w.startsWith("Scope:"));
|
|
1125
|
+
if (nonScopeWarnings.length > 0) {
|
|
1126
|
+
hasTagCorrections = true;
|
|
1127
|
+
correctionMessages.push(...nonScopeWarnings);
|
|
1128
|
+
}
|
|
1119
1129
|
}
|
|
1120
1130
|
}
|
|
1121
1131
|
console.error("[LLM] Initial correction messages collected:", correctionMessages.length);
|
|
@@ -1128,8 +1138,10 @@ ${result}
|
|
|
1128
1138
|
console.error(`[LLM] Re-validation after corrections: valid=${validation.valid}`);
|
|
1129
1139
|
}
|
|
1130
1140
|
let retryCount = 0;
|
|
1141
|
+
console.error(`[LLM] Iteration ${iteration}: Entering retry loop (validation.valid: ${validation.valid}, maxRetries: ${maxRetries})`);
|
|
1131
1142
|
while (!validation.valid && retryCount < maxRetries) {
|
|
1132
1143
|
retryCount++;
|
|
1144
|
+
console.error(`[LLM] Iteration ${iteration}: Retry ${retryCount}/${maxRetries} - validation failed with errors:`, validation.errorMessages);
|
|
1133
1145
|
if (session.debug) {
|
|
1134
1146
|
console.error(`[LLM] Validation failed (attempt ${retryCount}/${maxRetries}):`, validation.errorMessages);
|
|
1135
1147
|
}
|
|
@@ -1191,10 +1203,13 @@ ${result}
|
|
|
1191
1203
|
validation = await validateDiracCode(session, dynamicAST, { autocorrect, deepValidation: true });
|
|
1192
1204
|
}
|
|
1193
1205
|
if (!validation.valid) {
|
|
1206
|
+
console.error(`[LLM] Iteration ${iteration}: VALIDATION FAILED after ${maxRetries} retries. Throwing error.`);
|
|
1194
1207
|
throw new Error(`Tag validation failed after ${maxRetries} retries:
|
|
1195
1208
|
${validation.errorMessages.join("\n")}`);
|
|
1196
1209
|
}
|
|
1197
|
-
|
|
1210
|
+
console.error(`[LLM] Iteration ${iteration}: Validation passed, checking for corrections (hasTagCorrections: ${hasTagCorrections}, correctionMessages: ${correctionMessages.length})`);
|
|
1211
|
+
if (hasTagCorrections && correctionMessages.length > 0 && feedbackMode) {
|
|
1212
|
+
console.error(`[LLM] Iteration ${iteration}: Has tag corrections, preparing feedback (confirmCorrections: ${confirmCorrections})`);
|
|
1198
1213
|
const correctedCodeLines = [];
|
|
1199
1214
|
for (const child of dynamicAST.children) {
|
|
1200
1215
|
if (child.tag && child.tag !== "DIRAC-ROOT") {
|
|
@@ -1272,11 +1287,18 @@ ${correctedCode}
|
|
|
1272
1287
|
}
|
|
1273
1288
|
}
|
|
1274
1289
|
}
|
|
1290
|
+
console.error(`[LLM] Iteration ${iteration}: About to execute code`);
|
|
1275
1291
|
let executionError = null;
|
|
1276
1292
|
try {
|
|
1293
|
+
console.error(`[LLM] Iteration ${iteration}: Calling integrate()`);
|
|
1277
1294
|
await integrate(session, dynamicAST);
|
|
1295
|
+
console.error(`[LLM] Iteration ${iteration}: integrate() completed successfully`);
|
|
1296
|
+
if (session.output.length === outputBefore) {
|
|
1297
|
+
setVariable(session, "__llm_silent_execution__", result, false);
|
|
1298
|
+
}
|
|
1278
1299
|
} catch (execError) {
|
|
1279
1300
|
executionError = execError instanceof Error ? execError.message : String(execError);
|
|
1301
|
+
console.error(`[LLM] Iteration ${iteration}: EXECUTION ERROR: ${executionError}`);
|
|
1280
1302
|
console.error(`[LLM] Execution error: ${executionError}`);
|
|
1281
1303
|
if (feedbackMode && iteration < maxIterations) {
|
|
1282
1304
|
const errorFeedback = `System: Your code executed but encountered a runtime error:
|
|
@@ -1289,6 +1311,38 @@ Please fix the error and try again.`;
|
|
|
1289
1311
|
} else if (saveDialog) {
|
|
1290
1312
|
setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
|
|
1291
1313
|
}
|
|
1314
|
+
if (isOpenAI) {
|
|
1315
|
+
const response = await llmClient.chat.completions.create({
|
|
1316
|
+
model,
|
|
1317
|
+
max_tokens: maxTokens,
|
|
1318
|
+
temperature,
|
|
1319
|
+
messages: dialogHistory
|
|
1320
|
+
});
|
|
1321
|
+
result = response.choices[0]?.message?.content || "";
|
|
1322
|
+
} else if (isOllama) {
|
|
1323
|
+
const ollamaPrompt = dialogHistory.map((m) => `${m.role.charAt(0).toUpperCase() + m.role.slice(1)}: ${m.content}`).join("\n");
|
|
1324
|
+
result = await llmClient.complete(ollamaPrompt, {
|
|
1325
|
+
model,
|
|
1326
|
+
temperature,
|
|
1327
|
+
max_tokens: maxTokens
|
|
1328
|
+
});
|
|
1329
|
+
} else if (isCustom) {
|
|
1330
|
+
const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
1331
|
+
result = await llmClient.complete(customPrompt, {
|
|
1332
|
+
model,
|
|
1333
|
+
temperature,
|
|
1334
|
+
max_tokens: maxTokens,
|
|
1335
|
+
messages: dialogHistory
|
|
1336
|
+
});
|
|
1337
|
+
} else {
|
|
1338
|
+
result = await callAnthropic(llmClient, model, maxTokens, temperature, dialogHistory);
|
|
1339
|
+
}
|
|
1340
|
+
dialogHistory.push({ role: "assistant", content: result });
|
|
1341
|
+
if (contextVar) {
|
|
1342
|
+
setVariable(session, contextVar, JSON.stringify(dialogHistory), true);
|
|
1343
|
+
} else if (saveDialog) {
|
|
1344
|
+
setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
|
|
1345
|
+
}
|
|
1292
1346
|
continue;
|
|
1293
1347
|
} else {
|
|
1294
1348
|
throw execError;
|
|
@@ -1321,7 +1375,7 @@ Please fix the error and try again.`;
|
|
|
1321
1375
|
}
|
|
1322
1376
|
if (feedbackMode) {
|
|
1323
1377
|
const outputAfter = session.output.slice();
|
|
1324
|
-
const executionOutput = outputAfter.slice(outputBefore
|
|
1378
|
+
const executionOutput = outputAfter.slice(outputBefore).join("");
|
|
1325
1379
|
if (executionOutput) {
|
|
1326
1380
|
process.stdout.write(executionOutput);
|
|
1327
1381
|
}
|
|
@@ -1391,13 +1445,72 @@ ${result}
|
|
|
1391
1445
|
break;
|
|
1392
1446
|
}
|
|
1393
1447
|
} catch (parseError) {
|
|
1394
|
-
|
|
1395
|
-
|
|
1448
|
+
console.error(`[LLM] Iteration ${iteration}: ERROR CAUGHT: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
1449
|
+
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
|
|
1450
|
+
const isValidationError = errorMsg.includes("Tag validation failed") || errorMsg.includes("Attribute") || errorMsg.includes("contains <variable> tag");
|
|
1451
|
+
if (isValidationError && feedbackMode && iteration < maxIterations) {
|
|
1452
|
+
console.error(`[LLM] Iteration ${iteration}: VALIDATION ERROR - sending to LLM for correction`);
|
|
1453
|
+
const errorFeedback = `System: Your code had validation errors:
|
|
1454
|
+
${errorMsg}
|
|
1455
|
+
|
|
1456
|
+
Please fix these errors and generate valid Dirac XML code. Remember:
|
|
1457
|
+
- Use \${varname} syntax in attributes instead of <variable name="..." /> tags
|
|
1458
|
+
- Only use allowed tags and attributes`;
|
|
1459
|
+
dialogHistory.push({ role: "user", content: errorFeedback });
|
|
1460
|
+
if (contextVar) {
|
|
1461
|
+
setVariable(session, contextVar, JSON.stringify(dialogHistory), true);
|
|
1462
|
+
} else if (saveDialog) {
|
|
1463
|
+
setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
|
|
1464
|
+
}
|
|
1465
|
+
if (isOpenAI) {
|
|
1466
|
+
const response = await llmClient.chat.completions.create({
|
|
1467
|
+
model,
|
|
1468
|
+
max_tokens: maxTokens,
|
|
1469
|
+
temperature,
|
|
1470
|
+
messages: dialogHistory
|
|
1471
|
+
});
|
|
1472
|
+
result = response.choices[0]?.message?.content || "";
|
|
1473
|
+
} else if (isOllama) {
|
|
1474
|
+
const ollamaPrompt = dialogHistory.map((m) => `${m.role.charAt(0).toUpperCase() + m.role.slice(1)}: ${m.content}`).join("\n");
|
|
1475
|
+
result = await llmClient.complete(ollamaPrompt, {
|
|
1476
|
+
model,
|
|
1477
|
+
temperature,
|
|
1478
|
+
max_tokens: maxTokens
|
|
1479
|
+
});
|
|
1480
|
+
} else if (isCustom) {
|
|
1481
|
+
const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
1482
|
+
result = await llmClient.complete(customPrompt, {
|
|
1483
|
+
model,
|
|
1484
|
+
temperature,
|
|
1485
|
+
max_tokens: maxTokens,
|
|
1486
|
+
messages: dialogHistory
|
|
1487
|
+
});
|
|
1488
|
+
} else {
|
|
1489
|
+
result = await callAnthropic(llmClient, model, maxTokens, temperature, dialogHistory);
|
|
1490
|
+
}
|
|
1491
|
+
dialogHistory.push({ role: "assistant", content: result });
|
|
1492
|
+
if (contextVar) {
|
|
1493
|
+
setVariable(session, contextVar, JSON.stringify(dialogHistory), true);
|
|
1494
|
+
} else if (saveDialog) {
|
|
1495
|
+
setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
|
|
1496
|
+
}
|
|
1497
|
+
if (session.debug) {
|
|
1498
|
+
console.error(`[LLM] LLM correction response:
|
|
1499
|
+
${result}
|
|
1500
|
+
`);
|
|
1501
|
+
}
|
|
1502
|
+
continue;
|
|
1503
|
+
} else {
|
|
1504
|
+
console.error(`[LLM] Iteration ${iteration}: PARSE ERROR (or no feedback): ${errorMsg}`);
|
|
1505
|
+
if (session.debug) {
|
|
1506
|
+
console.error(`[LLM] Failed to parse as Dirac, treating as text: ${parseError}`);
|
|
1507
|
+
}
|
|
1508
|
+
emit(session, result);
|
|
1509
|
+
break;
|
|
1396
1510
|
}
|
|
1397
|
-
emit(session, result);
|
|
1398
|
-
break;
|
|
1399
1511
|
}
|
|
1400
1512
|
}
|
|
1513
|
+
console.error(`[LLM] Exited feedback loop after ${iteration} iterations`);
|
|
1401
1514
|
} else {
|
|
1402
1515
|
emit(session, result);
|
|
1403
1516
|
}
|
|
@@ -1948,7 +2061,7 @@ async function executeTagCheck(session, element) {
|
|
|
1948
2061
|
const executeTag = correctedTag || tagName;
|
|
1949
2062
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1950
2063
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1951
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
2064
|
+
const { integrate: integrate2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
1952
2065
|
await integrate2(session, elementToExecute);
|
|
1953
2066
|
}
|
|
1954
2067
|
}
|
|
@@ -1957,7 +2070,7 @@ async function executeTagCheck(session, element) {
|
|
|
1957
2070
|
// src/tags/throw.ts
|
|
1958
2071
|
async function executeThrow(session, element) {
|
|
1959
2072
|
const exceptionName = element.attributes?.name || "exception";
|
|
1960
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
2073
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
1961
2074
|
const exceptionDom = {
|
|
1962
2075
|
tag: "exception-content",
|
|
1963
2076
|
attributes: { name: exceptionName },
|
|
@@ -1970,7 +2083,7 @@ async function executeThrow(session, element) {
|
|
|
1970
2083
|
// src/tags/try.ts
|
|
1971
2084
|
async function executeTry(session, element) {
|
|
1972
2085
|
setExceptionBoundary(session);
|
|
1973
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
2086
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
1974
2087
|
await integrateChildren2(session, element);
|
|
1975
2088
|
unsetExceptionBoundary(session);
|
|
1976
2089
|
}
|
|
@@ -1980,7 +2093,7 @@ async function executeCatch(session, element) {
|
|
|
1980
2093
|
const exceptionName = element.attributes?.name || "exception";
|
|
1981
2094
|
const caughtCount = lookupException(session, exceptionName);
|
|
1982
2095
|
if (caughtCount > 0) {
|
|
1983
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
2096
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
1984
2097
|
await integrateChildren2(session, element);
|
|
1985
2098
|
}
|
|
1986
2099
|
flushCurrentException(session);
|
|
@@ -1989,7 +2102,7 @@ async function executeCatch(session, element) {
|
|
|
1989
2102
|
// src/tags/exception.ts
|
|
1990
2103
|
async function executeException(session, element) {
|
|
1991
2104
|
const exceptions = getCurrentExceptions(session);
|
|
1992
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
2105
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
1993
2106
|
for (const exceptionDom of exceptions) {
|
|
1994
2107
|
await integrateChildren2(session, exceptionDom);
|
|
1995
2108
|
}
|
|
@@ -2190,7 +2303,7 @@ async function executeLoadContext(session, element) {
|
|
|
2190
2303
|
query = element.text.trim();
|
|
2191
2304
|
}
|
|
2192
2305
|
if (!query && element.children.length > 0) {
|
|
2193
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
2306
|
+
const { integrate: integrate2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
2194
2307
|
const beforeOutput = session.output.length;
|
|
2195
2308
|
for (const child of element.children) {
|
|
2196
2309
|
await integrate2(session, child);
|
|
@@ -3034,7 +3147,7 @@ async function executeForeach(session, element) {
|
|
|
3034
3147
|
const parser2 = new DiracParser2();
|
|
3035
3148
|
try {
|
|
3036
3149
|
const fromElement = parser2.parse(fromAttr);
|
|
3037
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
3150
|
+
const { integrate: integrate2 } = await import("./interpreter-D6ZF3OJA.js");
|
|
3038
3151
|
await integrate2(session, fromElement);
|
|
3039
3152
|
} catch (e) {
|
|
3040
3153
|
session.output = savedOutput;
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-MYWEN36N.js";
|
|
5
5
|
import {
|
|
6
6
|
BraKetParser
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-ECAW4X46.js";
|
|
7
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
9
8
|
import "./chunk-SLGJRZ3P.js";
|
|
10
9
|
import "./chunk-HRHAMPOB.js";
|
|
10
|
+
import "./chunk-ECAW4X46.js";
|
|
11
11
|
import "./chunk-PPH7KYKH.js";
|
|
12
12
|
|
|
13
13
|
// src/cli.ts
|
|
@@ -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.98",
|
|
20
20
|
description: "LLM-Augmented Declarative Execution",
|
|
21
21
|
type: "module",
|
|
22
22
|
main: "dist/index.js",
|
|
@@ -150,7 +150,7 @@ async function main() {
|
|
|
150
150
|
const args = process.argv.slice(2);
|
|
151
151
|
const calledAs = process.argv[1];
|
|
152
152
|
if (calledAs && calledAs.endsWith("/dish")) {
|
|
153
|
-
const { DiracShell } = await import("./shell-
|
|
153
|
+
const { DiracShell } = await import("./shell-KNEQHL3Y.js");
|
|
154
154
|
const shellConfig = loadShellConfig(args);
|
|
155
155
|
const shell = new DiracShell(shellConfig);
|
|
156
156
|
await shell.start();
|
|
@@ -199,11 +199,11 @@ async function main() {
|
|
|
199
199
|
if (args[0] === "agent") {
|
|
200
200
|
const subcommand = args[1];
|
|
201
201
|
if (subcommand === "daemon") {
|
|
202
|
-
const { runAgentDaemon } = await import("./agent-
|
|
202
|
+
const { runAgentDaemon } = await import("./agent-5Q5MQOV2.js");
|
|
203
203
|
await runAgentDaemon();
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
|
-
const { AgentCLI } = await import("./agent-
|
|
206
|
+
const { AgentCLI } = await import("./agent-5Q5MQOV2.js");
|
|
207
207
|
const agent = new AgentCLI();
|
|
208
208
|
switch (subcommand) {
|
|
209
209
|
case "start":
|
|
@@ -230,8 +230,8 @@ async function main() {
|
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
if (args[0] === "shell") {
|
|
233
|
-
const { DiracShell } = await import("./shell-
|
|
234
|
-
const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-
|
|
233
|
+
const { DiracShell } = await import("./shell-KNEQHL3Y.js");
|
|
234
|
+
const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-N53QIJO5.js");
|
|
235
235
|
const { SessionClient } = await import("./session-client-3VTC5MLO.js");
|
|
236
236
|
const daemonMode = args.includes("--daemon") || args.includes("-d");
|
|
237
237
|
const agentMode = args.includes("--agent") || args.includes("-a");
|
|
@@ -277,7 +277,7 @@ async function main() {
|
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
279
|
if (args[0] === "daemon") {
|
|
280
|
-
const { SessionServer } = await import("./session-server-
|
|
280
|
+
const { SessionServer } = await import("./session-server-N53QIJO5.js");
|
|
281
281
|
const server = new SessionServer();
|
|
282
282
|
await server.start();
|
|
283
283
|
console.log("Session daemon started");
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
listCronJobs,
|
|
4
4
|
stopAllCronJobs,
|
|
5
5
|
stopCronJob
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-ECAW4X46.js";
|
|
6
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
8
7
|
import "./chunk-SLGJRZ3P.js";
|
|
9
8
|
import "./chunk-HRHAMPOB.js";
|
|
9
|
+
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-PPH7KYKH.js";
|
|
11
11
|
export {
|
|
12
12
|
executeCron,
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MYWEN36N.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-ECAW4X46.js";
|
|
8
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
10
9
|
import "./chunk-SLGJRZ3P.js";
|
|
11
10
|
import {
|
|
12
11
|
DiracParser
|
|
13
12
|
} from "./chunk-HRHAMPOB.js";
|
|
13
|
+
import "./chunk-ECAW4X46.js";
|
|
14
14
|
import {
|
|
15
15
|
createSession,
|
|
16
16
|
getAvailableSubroutines,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
integrate,
|
|
3
3
|
integrateChildren
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-ECAW4X46.js";
|
|
4
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
6
5
|
import "./chunk-SLGJRZ3P.js";
|
|
7
6
|
import "./chunk-HRHAMPOB.js";
|
|
7
|
+
import "./chunk-ECAW4X46.js";
|
|
8
8
|
import "./chunk-PPH7KYKH.js";
|
|
9
9
|
export {
|
|
10
10
|
integrate,
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
cancelScheduledRun,
|
|
4
4
|
executeRunAt,
|
|
5
5
|
listScheduledRuns
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-ECAW4X46.js";
|
|
6
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
8
7
|
import "./chunk-SLGJRZ3P.js";
|
|
9
8
|
import "./chunk-HRHAMPOB.js";
|
|
9
|
+
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-PPH7KYKH.js";
|
|
11
11
|
export {
|
|
12
12
|
cancelAllScheduledRuns,
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
listScheduledTasks,
|
|
4
4
|
stopAllScheduledTasks,
|
|
5
5
|
stopScheduledTask
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-ECAW4X46.js";
|
|
6
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
8
7
|
import "./chunk-SLGJRZ3P.js";
|
|
9
8
|
import "./chunk-HRHAMPOB.js";
|
|
9
|
+
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-PPH7KYKH.js";
|
|
11
11
|
export {
|
|
12
12
|
executeSchedule,
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/utils/scope-validator.ts
|
|
2
|
+
function extractParameterNames(element) {
|
|
3
|
+
const params = [];
|
|
4
|
+
for (const attr in element.attributes) {
|
|
5
|
+
if (attr.startsWith("param-")) {
|
|
6
|
+
const paramName = attr.slice(6);
|
|
7
|
+
params.push(paramName);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return params;
|
|
11
|
+
}
|
|
12
|
+
function extractVariableReferences(text) {
|
|
13
|
+
const pattern = /\$\{([a-zA-Z_][a-zA-Z0-9_-]*)\}/g;
|
|
14
|
+
const matches = [];
|
|
15
|
+
let match;
|
|
16
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
17
|
+
matches.push(match[1]);
|
|
18
|
+
}
|
|
19
|
+
return matches;
|
|
20
|
+
}
|
|
21
|
+
var ScopeContext = class {
|
|
22
|
+
parameters;
|
|
23
|
+
// Declared parameters
|
|
24
|
+
declaredVariables;
|
|
25
|
+
// Variables declared with <defvar>
|
|
26
|
+
referencedVariables;
|
|
27
|
+
// Variables referenced with <variable> or ${}
|
|
28
|
+
referencedParameters;
|
|
29
|
+
// Parameters actually used
|
|
30
|
+
constructor(parameters) {
|
|
31
|
+
this.parameters = new Set(parameters);
|
|
32
|
+
this.declaredVariables = /* @__PURE__ */ new Set();
|
|
33
|
+
this.referencedVariables = /* @__PURE__ */ new Set();
|
|
34
|
+
this.referencedParameters = /* @__PURE__ */ new Set();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if a name is available in current scope
|
|
38
|
+
* Priority: parameters -> declared variables
|
|
39
|
+
*/
|
|
40
|
+
isInScope(name) {
|
|
41
|
+
return this.parameters.has(name) || this.declaredVariables.has(name);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Record a variable declaration
|
|
45
|
+
*/
|
|
46
|
+
declareVariable(name) {
|
|
47
|
+
this.declaredVariables.add(name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record a variable/parameter reference
|
|
51
|
+
*/
|
|
52
|
+
referenceVariable(name) {
|
|
53
|
+
this.referencedVariables.add(name);
|
|
54
|
+
if (this.parameters.has(name)) {
|
|
55
|
+
this.referencedParameters.add(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function validateScope(element, scope, errors, warnings) {
|
|
60
|
+
if (element.tag === "defvar") {
|
|
61
|
+
const varName = element.attributes.name;
|
|
62
|
+
if (varName) {
|
|
63
|
+
scope.declareVariable(varName);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (element.tag === "variable") {
|
|
67
|
+
const varName = element.attributes.name;
|
|
68
|
+
if (varName) {
|
|
69
|
+
scope.referenceVariable(varName);
|
|
70
|
+
if (!scope.isInScope(varName)) {
|
|
71
|
+
warnings.push(
|
|
72
|
+
`Variable reference '${varName}' not found in local scope (may be from parent scope)`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (element.tag === "parameters") {
|
|
78
|
+
const select = element.attributes.select;
|
|
79
|
+
if (select && select.startsWith("@")) {
|
|
80
|
+
const paramName = select.slice(1);
|
|
81
|
+
scope.referenceVariable(paramName);
|
|
82
|
+
if (!scope.isInScope(paramName)) {
|
|
83
|
+
warnings.push(
|
|
84
|
+
`Parameter reference '${paramName}' not found in subroutine parameters`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const [attrName, attrValue] of Object.entries(element.attributes)) {
|
|
90
|
+
if (typeof attrValue === "string") {
|
|
91
|
+
const varRefs = extractVariableReferences(attrValue);
|
|
92
|
+
for (const varRef of varRefs) {
|
|
93
|
+
scope.referenceVariable(varRef);
|
|
94
|
+
if (!scope.isInScope(varRef)) {
|
|
95
|
+
warnings.push(
|
|
96
|
+
`Variable substitution '\${${varRef}}' in attribute not found in local scope (may be from parent scope)`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const dollarVarPattern = /\$([a-zA-Z_][a-zA-Z0-9_-]*)/g;
|
|
101
|
+
let dollarMatch;
|
|
102
|
+
while ((dollarMatch = dollarVarPattern.exec(attrValue)) !== null) {
|
|
103
|
+
const varName = dollarMatch[1];
|
|
104
|
+
scope.referenceVariable(varName);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const child of element.children) {
|
|
109
|
+
validateScope(child, scope, errors, warnings);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function validateSubroutineScope(subroutine) {
|
|
113
|
+
const errors = [];
|
|
114
|
+
const warnings = [];
|
|
115
|
+
const parameters = extractParameterNames(subroutine);
|
|
116
|
+
const scope = new ScopeContext(parameters);
|
|
117
|
+
for (const child of subroutine.children) {
|
|
118
|
+
validateScope(child, scope, errors, warnings);
|
|
119
|
+
}
|
|
120
|
+
const unusedParameters = parameters.filter((p) => !scope.referencedParameters.has(p));
|
|
121
|
+
if (unusedParameters.length > 0) {
|
|
122
|
+
warnings.push(
|
|
123
|
+
`Unused parameters: ${unusedParameters.join(", ")}`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const unusedVariables = Array.from(scope.declaredVariables).filter(
|
|
127
|
+
(v) => !scope.referencedVariables.has(v)
|
|
128
|
+
);
|
|
129
|
+
if (unusedVariables.length > 0) {
|
|
130
|
+
warnings.push(
|
|
131
|
+
`Unused variables: ${unusedVariables.join(", ")}`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
const undefinedReferences = Array.from(scope.referencedVariables).filter(
|
|
135
|
+
(v) => !scope.isInScope(v)
|
|
136
|
+
);
|
|
137
|
+
const undefinedParameters = undefinedReferences.filter(
|
|
138
|
+
(v) => !scope.declaredVariables.has(v)
|
|
139
|
+
);
|
|
140
|
+
const undefinedVariables = undefinedReferences.filter(
|
|
141
|
+
(v) => scope.declaredVariables.has(v)
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
valid: errors.length === 0,
|
|
145
|
+
errors,
|
|
146
|
+
warnings,
|
|
147
|
+
undefinedParameters,
|
|
148
|
+
undefinedVariables,
|
|
149
|
+
unusedParameters,
|
|
150
|
+
unusedVariables
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function validateAllSubroutineScopes(ast) {
|
|
154
|
+
const results = /* @__PURE__ */ new Map();
|
|
155
|
+
function findSubroutines(element) {
|
|
156
|
+
if (element.tag === "subroutine") {
|
|
157
|
+
const name = element.attributes.name || "anonymous";
|
|
158
|
+
const result = validateSubroutineScope(element);
|
|
159
|
+
results.set(name, result);
|
|
160
|
+
}
|
|
161
|
+
for (const child of element.children) {
|
|
162
|
+
findSubroutines(child);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
findSubroutines(ast);
|
|
166
|
+
return results;
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
validateAllSubroutineScopes,
|
|
170
|
+
validateSubroutineScope
|
|
171
|
+
};
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-ECAW4X46.js";
|
|
5
|
+
} from "./chunk-33DMGFRM.js";
|
|
6
|
+
import "./chunk-LAEYP4OQ.js";
|
|
8
7
|
import "./chunk-SLGJRZ3P.js";
|
|
9
8
|
import "./chunk-HRHAMPOB.js";
|
|
9
|
+
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-PPH7KYKH.js";
|
|
11
11
|
export {
|
|
12
12
|
SessionServer,
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
BraKetParser,
|
|
4
4
|
integrate
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-ECAW4X46.js";
|
|
5
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
7
6
|
import "./chunk-SLGJRZ3P.js";
|
|
8
7
|
import {
|
|
9
8
|
DiracParser
|
|
10
9
|
} from "./chunk-HRHAMPOB.js";
|
|
10
|
+
import "./chunk-ECAW4X46.js";
|
|
11
11
|
import {
|
|
12
12
|
createSession
|
|
13
13
|
} from "./chunk-PPH7KYKH.js";
|
|
@@ -358,7 +358,7 @@ var DiracShell = class {
|
|
|
358
358
|
if (this.client) {
|
|
359
359
|
this.client.disconnect();
|
|
360
360
|
}
|
|
361
|
-
import("./schedule-
|
|
361
|
+
import("./schedule-3EJJHG3B.js").then(({ stopAllScheduledTasks }) => {
|
|
362
362
|
stopAllScheduledTasks();
|
|
363
363
|
console.log("\nGoodbye!");
|
|
364
364
|
process.exit(0);
|
|
@@ -504,6 +504,15 @@ var DiracShell = class {
|
|
|
504
504
|
if (this.session.output.length > 0) {
|
|
505
505
|
console.log(this.session.output.join(""));
|
|
506
506
|
}
|
|
507
|
+
const silentExecution = this.session.variables.find((v) => v.name === "__llm_silent_execution__");
|
|
508
|
+
if (silentExecution?.value) {
|
|
509
|
+
console.error(`
|
|
510
|
+
[LLM generated]
|
|
511
|
+
${silentExecution.value}
|
|
512
|
+
`);
|
|
513
|
+
const idx = this.session.variables.findIndex((v) => v.name === "__llm_silent_execution__");
|
|
514
|
+
if (idx !== -1) this.session.variables.splice(idx, 1);
|
|
515
|
+
}
|
|
507
516
|
} catch (error) {
|
|
508
517
|
console.error("Error:", error instanceof Error ? error.message : String(error));
|
|
509
518
|
if (this.config.debug && error instanceof Error && error.stack) {
|
|
@@ -763,7 +772,7 @@ Examples:
|
|
|
763
772
|
break;
|
|
764
773
|
case "tasks":
|
|
765
774
|
try {
|
|
766
|
-
const { listScheduledTasks } = await import("./schedule-
|
|
775
|
+
const { listScheduledTasks } = await import("./schedule-3EJJHG3B.js");
|
|
767
776
|
const tasks = listScheduledTasks();
|
|
768
777
|
if (tasks.length === 0) {
|
|
769
778
|
console.log("No scheduled tasks running.");
|
|
@@ -782,7 +791,7 @@ Examples:
|
|
|
782
791
|
console.log("Usage: :stop <task-name>");
|
|
783
792
|
} else {
|
|
784
793
|
try {
|
|
785
|
-
const { stopScheduledTask } = await import("./schedule-
|
|
794
|
+
const { stopScheduledTask } = await import("./schedule-3EJJHG3B.js");
|
|
786
795
|
const taskName = args[0];
|
|
787
796
|
const stopped = stopScheduledTask(taskName);
|
|
788
797
|
if (stopped) {
|
|
@@ -797,7 +806,7 @@ Examples:
|
|
|
797
806
|
break;
|
|
798
807
|
case "stopall":
|
|
799
808
|
try {
|
|
800
|
-
const { stopAllScheduledTasks } = await import("./schedule-
|
|
809
|
+
const { stopAllScheduledTasks } = await import("./schedule-3EJJHG3B.js");
|
|
801
810
|
stopAllScheduledTasks();
|
|
802
811
|
console.log("All scheduled tasks stopped.");
|
|
803
812
|
} catch (error) {
|
|
@@ -806,7 +815,7 @@ Examples:
|
|
|
806
815
|
break;
|
|
807
816
|
case "crons":
|
|
808
817
|
try {
|
|
809
|
-
const { listCronJobs } = await import("./cron-
|
|
818
|
+
const { listCronJobs } = await import("./cron-VCUFU2WU.js");
|
|
810
819
|
const jobs = listCronJobs();
|
|
811
820
|
if (jobs.length === 0) {
|
|
812
821
|
console.log("No cron jobs running.");
|
|
@@ -826,7 +835,7 @@ Examples:
|
|
|
826
835
|
console.log("Usage: :stopcron <job-name>");
|
|
827
836
|
} else {
|
|
828
837
|
try {
|
|
829
|
-
const { stopCronJob } = await import("./cron-
|
|
838
|
+
const { stopCronJob } = await import("./cron-VCUFU2WU.js");
|
|
830
839
|
const jobName = args[0];
|
|
831
840
|
const stopped = stopCronJob(jobName);
|
|
832
841
|
if (stopped) {
|
|
@@ -841,7 +850,7 @@ Examples:
|
|
|
841
850
|
break;
|
|
842
851
|
case "stopallcrons":
|
|
843
852
|
try {
|
|
844
|
-
const { stopAllCronJobs } = await import("./cron-
|
|
853
|
+
const { stopAllCronJobs } = await import("./cron-VCUFU2WU.js");
|
|
845
854
|
stopAllCronJobs();
|
|
846
855
|
console.log("All cron jobs stopped.");
|
|
847
856
|
} catch (error) {
|
|
@@ -850,7 +859,7 @@ Examples:
|
|
|
850
859
|
break;
|
|
851
860
|
case "scheduled":
|
|
852
861
|
try {
|
|
853
|
-
const { listScheduledRuns } = await import("./run-at-
|
|
862
|
+
const { listScheduledRuns } = await import("./run-at-P43PK5JU.js");
|
|
854
863
|
const runs = listScheduledRuns();
|
|
855
864
|
if (runs.length === 0) {
|
|
856
865
|
console.log("No scheduled runs pending.");
|
|
@@ -870,7 +879,7 @@ Examples:
|
|
|
870
879
|
console.log("Usage: :cancel <run-name>");
|
|
871
880
|
} else {
|
|
872
881
|
try {
|
|
873
|
-
const { cancelScheduledRun } = await import("./run-at-
|
|
882
|
+
const { cancelScheduledRun } = await import("./run-at-P43PK5JU.js");
|
|
874
883
|
const runName = args[0];
|
|
875
884
|
const cancelled = cancelScheduledRun(runName);
|
|
876
885
|
if (cancelled) {
|
|
@@ -885,7 +894,7 @@ Examples:
|
|
|
885
894
|
break;
|
|
886
895
|
case "cancelall":
|
|
887
896
|
try {
|
|
888
|
-
const { cancelAllScheduledRuns } = await import("./run-at-
|
|
897
|
+
const { cancelAllScheduledRuns } = await import("./run-at-P43PK5JU.js");
|
|
889
898
|
cancelAllScheduledRuns();
|
|
890
899
|
console.log("All scheduled runs cancelled.");
|
|
891
900
|
} catch (error) {
|
|
@@ -77,6 +77,21 @@ function validateParameterType(paramName, value, expectedType) {
|
|
|
77
77
|
}
|
|
78
78
|
return { valid: true };
|
|
79
79
|
}
|
|
80
|
+
function validateAttributeValue(attrName, value) {
|
|
81
|
+
if (value.includes("<variable")) {
|
|
82
|
+
return {
|
|
83
|
+
valid: false,
|
|
84
|
+
error: `Attribute '${attrName}' contains <variable> tag - use \${varname} syntax in attributes instead`
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (/<[a-zA-Z]/.test(value) && !value.includes("${")) {
|
|
88
|
+
return {
|
|
89
|
+
valid: false,
|
|
90
|
+
warning: `Attribute '${attrName}' appears to contain XML tags - attribute values should use \${} syntax for variables`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return { valid: true };
|
|
94
|
+
}
|
|
80
95
|
async function validateNestedTags(session, element, options = {}) {
|
|
81
96
|
const results = [];
|
|
82
97
|
for (const child of element.children) {
|
|
@@ -107,7 +122,8 @@ async function validateTag(session, element, options = {}) {
|
|
|
107
122
|
warnings: [],
|
|
108
123
|
attributeCorrections: {},
|
|
109
124
|
typeErrors: [],
|
|
110
|
-
nestedValidation: []
|
|
125
|
+
nestedValidation: [],
|
|
126
|
+
scopeValidation: void 0
|
|
111
127
|
};
|
|
112
128
|
if (allowed.has(tagName)) {
|
|
113
129
|
console.error(`[VALIDATE] Tag <${tagName}> is valid`);
|
|
@@ -160,8 +176,16 @@ async function validateTag(session, element, options = {}) {
|
|
|
160
176
|
}
|
|
161
177
|
for (const attr in element.attributes) {
|
|
162
178
|
const param = sub.parameters.find((p) => p.name === attr);
|
|
179
|
+
const attrValue = element.attributes[attr];
|
|
180
|
+
const attrValueCheck = validateAttributeValue(attr, attrValue);
|
|
181
|
+
if (!attrValueCheck.valid && attrValueCheck.error) {
|
|
182
|
+
result.errors.push(attrValueCheck.error);
|
|
183
|
+
}
|
|
184
|
+
if (attrValueCheck.warning) {
|
|
185
|
+
result.warnings.push(attrValueCheck.warning);
|
|
186
|
+
}
|
|
163
187
|
if (param && param.type) {
|
|
164
|
-
const typeCheck = validateParameterType(attr,
|
|
188
|
+
const typeCheck = validateParameterType(attr, attrValue, param.type);
|
|
165
189
|
if (!typeCheck.valid && typeCheck.error) {
|
|
166
190
|
result.typeErrors.push(typeCheck.error);
|
|
167
191
|
result.errors.push(typeCheck.error);
|
|
@@ -176,6 +200,22 @@ async function validateTag(session, element, options = {}) {
|
|
|
176
200
|
result.warnings.push(`Nested tag <${nestedResult.originalTag}>: ${nestedResult.errors.join(", ")}`);
|
|
177
201
|
}
|
|
178
202
|
}
|
|
203
|
+
const { validateSubroutineScope } = await import("./scope-validator-TVQIOEAI.js");
|
|
204
|
+
result.scopeValidation = validateSubroutineScope(element);
|
|
205
|
+
console.error(`[VALIDATE] Scope validation for <subroutine name="${element.attributes.name}">:`, {
|
|
206
|
+
errors: result.scopeValidation.errors.length,
|
|
207
|
+
warnings: result.scopeValidation.warnings.length,
|
|
208
|
+
undefinedParams: result.scopeValidation.undefinedParameters,
|
|
209
|
+
undefinedVars: result.scopeValidation.undefinedVariables,
|
|
210
|
+
unusedParams: result.scopeValidation.unusedParameters,
|
|
211
|
+
unusedVars: result.scopeValidation.unusedVariables
|
|
212
|
+
});
|
|
213
|
+
if (result.scopeValidation.warnings.length > 0) {
|
|
214
|
+
result.warnings.push(...result.scopeValidation.warnings.map((w) => `Scope: ${w}`));
|
|
215
|
+
}
|
|
216
|
+
if (result.scopeValidation.errors.length > 0) {
|
|
217
|
+
result.errors.push(...result.scopeValidation.errors.map((e) => `Scope: ${e}`));
|
|
218
|
+
}
|
|
179
219
|
}
|
|
180
220
|
}
|
|
181
221
|
result.valid = result.errors.length === 0;
|
|
@@ -230,6 +270,49 @@ async function validateDiracCode(session, ast, options = {}) {
|
|
|
230
270
|
const results = [];
|
|
231
271
|
const errorMessages = [];
|
|
232
272
|
const typeErrors = [];
|
|
273
|
+
const localSubroutineNames = /* @__PURE__ */ new Set();
|
|
274
|
+
const localSubroutineElements = /* @__PURE__ */ new Map();
|
|
275
|
+
function extractLocalSubroutines(element) {
|
|
276
|
+
if (element.tag === "subroutine" && element.attributes.name) {
|
|
277
|
+
localSubroutineNames.add(element.attributes.name);
|
|
278
|
+
localSubroutineElements.set(element.attributes.name, element);
|
|
279
|
+
}
|
|
280
|
+
for (const child of element.children) {
|
|
281
|
+
extractLocalSubroutines(child);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
extractLocalSubroutines(ast);
|
|
285
|
+
if (localSubroutineNames.size > 0) {
|
|
286
|
+
console.error(`[VALIDATE] Found ${localSubroutineNames.size} local subroutine definitions:`, Array.from(localSubroutineNames));
|
|
287
|
+
}
|
|
288
|
+
const tempSubroutines = [];
|
|
289
|
+
for (const subName of localSubroutineNames) {
|
|
290
|
+
const subElement = localSubroutineElements.get(subName);
|
|
291
|
+
const parameters = [];
|
|
292
|
+
for (const attr in subElement.attributes) {
|
|
293
|
+
if (attr.startsWith("param-")) {
|
|
294
|
+
const paramName = attr.slice(6);
|
|
295
|
+
const paramSpec = subElement.attributes[attr];
|
|
296
|
+
const parts = paramSpec.split(":");
|
|
297
|
+
parameters.push({
|
|
298
|
+
name: paramName,
|
|
299
|
+
type: parts[0] || "string",
|
|
300
|
+
required: parts[1] === "required",
|
|
301
|
+
description: parts[2] || "",
|
|
302
|
+
example: parts[3] || ""
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
console.error(`[VALIDATE] Temp subroutine '${subName}' has ${parameters.length} parameters:`, parameters.map((p) => p.name));
|
|
307
|
+
const tempSub = {
|
|
308
|
+
name: subName,
|
|
309
|
+
element: subElement,
|
|
310
|
+
boundary: session.variables.length,
|
|
311
|
+
parameters
|
|
312
|
+
};
|
|
313
|
+
session.subroutines.push(tempSub);
|
|
314
|
+
tempSubroutines.push(tempSub);
|
|
315
|
+
}
|
|
233
316
|
async function validateElement(element) {
|
|
234
317
|
if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
|
|
235
318
|
const result = await validateTag(session, element, options);
|
|
@@ -246,6 +329,12 @@ async function validateDiracCode(session, ast, options = {}) {
|
|
|
246
329
|
}
|
|
247
330
|
}
|
|
248
331
|
await validateElement(ast);
|
|
332
|
+
for (const tempSub of tempSubroutines) {
|
|
333
|
+
const index = session.subroutines.indexOf(tempSub);
|
|
334
|
+
if (index > -1) {
|
|
335
|
+
session.subroutines.splice(index, 1);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
249
338
|
return {
|
|
250
339
|
valid: errorMessages.length === 0,
|
|
251
340
|
results,
|
|
@@ -256,26 +345,28 @@ async function validateDiracCode(session, ast, options = {}) {
|
|
|
256
345
|
function applyCorrectedTags(ast, results) {
|
|
257
346
|
let resultIndex = 0;
|
|
258
347
|
function correctElement(element) {
|
|
259
|
-
|
|
348
|
+
const shouldProcess = element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "";
|
|
349
|
+
if (shouldProcess && resultIndex < results.length) {
|
|
260
350
|
const result = results[resultIndex++];
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
newAttributes[newAttr] = value;
|
|
351
|
+
console.error(`[APPLY-CORRECTION] Processing <${element.tag}> with result #${resultIndex - 1} for <${result.originalTag}>, corrected: ${result.corrected}`);
|
|
352
|
+
if (result.corrected && result.tagName !== element.tag) {
|
|
353
|
+
console.error(`[APPLY-CORRECTION] Tag: ${element.tag} \u2192 ${result.tagName}`);
|
|
354
|
+
element = { ...element, tag: result.tagName };
|
|
355
|
+
}
|
|
356
|
+
if (result.attributeCorrections && Object.keys(result.attributeCorrections).length > 0) {
|
|
357
|
+
console.error(`[APPLY-CORRECTION] Attributes on <${element.tag}>:`, result.attributeCorrections);
|
|
358
|
+
const newAttributes = {};
|
|
359
|
+
for (const [oldAttr, value] of Object.entries(element.attributes)) {
|
|
360
|
+
const newAttr = result.attributeCorrections[oldAttr] || oldAttr;
|
|
361
|
+
if (newAttr !== oldAttr) {
|
|
362
|
+
console.error(`[APPLY-CORRECTION] ${oldAttr}="${value}" \u2192 ${newAttr}="${value}"`);
|
|
275
363
|
}
|
|
276
|
-
|
|
364
|
+
newAttributes[newAttr] = value;
|
|
277
365
|
}
|
|
366
|
+
element = { ...element, attributes: newAttributes };
|
|
278
367
|
}
|
|
368
|
+
} else if (shouldProcess) {
|
|
369
|
+
console.error(`[APPLY-CORRECTION] WARNING: No result for <${element.tag}> at index ${resultIndex} (total results: ${results.length})`);
|
|
279
370
|
}
|
|
280
371
|
return {
|
|
281
372
|
...element,
|
package/dist/test-runner.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
integrate
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-ECAW4X46.js";
|
|
3
|
+
} from "./chunk-LAEYP4OQ.js";
|
|
5
4
|
import "./chunk-SLGJRZ3P.js";
|
|
6
5
|
import {
|
|
7
6
|
DiracParser
|
|
8
7
|
} from "./chunk-HRHAMPOB.js";
|
|
8
|
+
import "./chunk-ECAW4X46.js";
|
|
9
9
|
import {
|
|
10
10
|
createSession,
|
|
11
11
|
getOutput
|