dirac-lang 0.1.95 → 0.1.97
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-SVKTURXE.js → agent-MJSTQERB.js} +2 -2
- package/dist/{chunk-NUNYBLVJ.js → chunk-4TBIVB4X.js} +38 -17
- package/dist/{chunk-LGFNVEHY.js → chunk-CDTZNFCJ.js} +1 -1
- package/dist/{chunk-IFBJYN2F.js → chunk-KFMG6CZW.js} +1 -1
- package/dist/cli.js +9 -9
- package/dist/{cron-YIBSPTLT.js → cron-2J3SEPZW.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/{interpreter-WNHDVVDD.js → interpreter-4CIWAOBY.js} +1 -1
- package/dist/{run-at-H7RN6DOD.js → run-at-MHURF5PL.js} +1 -1
- package/dist/{schedule-JY54UROJ.js → schedule-KMBLI46W.js} +1 -1
- package/dist/{session-server-GPITH5QY.js → session-server-TQPJVLA4.js} +2 -2
- package/dist/{shell-SUNLGPOM.js → shell-CY5XIPQC.js} +116 -17
- package/dist/{tag-validator-D7FH7P5F.js → tag-validator-REN6XLMT.js} +77 -3
- package/dist/test-runner.js +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-KFMG6CZW.js";
|
|
6
|
+
import "./chunk-4TBIVB4X.js";
|
|
7
7
|
import "./chunk-ECAW4X46.js";
|
|
8
8
|
import "./chunk-SLGJRZ3P.js";
|
|
9
9
|
import "./chunk-HRHAMPOB.js";
|
|
@@ -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-4CIWAOBY.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-4CIWAOBY.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-4CIWAOBY.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-4CIWAOBY.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-4CIWAOBY.js");
|
|
536
536
|
await integrateChildren2(session, child);
|
|
537
537
|
const newChunks = session.output.slice(argOutputStart);
|
|
538
538
|
const argValue = newChunks.join("");
|
|
@@ -1094,8 +1094,8 @@ ${result}
|
|
|
1094
1094
|
if (session.debug) {
|
|
1095
1095
|
console.error(`[LLM] Validation enabled, autocorrect: ${autocorrect}`);
|
|
1096
1096
|
}
|
|
1097
|
-
const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-
|
|
1098
|
-
let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
|
|
1097
|
+
const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-REN6XLMT.js");
|
|
1098
|
+
let validation = await validateDiracCode(session, dynamicAST, { autocorrect, deepValidation: true });
|
|
1099
1099
|
if (session.debug) {
|
|
1100
1100
|
console.error(`[LLM] Validation result: valid=${validation.valid}, results count=${validation.results.length}`);
|
|
1101
1101
|
if (validation.results.length > 0) {
|
|
@@ -1124,7 +1124,7 @@ ${result}
|
|
|
1124
1124
|
}
|
|
1125
1125
|
dynamicAST = applyCorrectedTags(dynamicAST, validation.results);
|
|
1126
1126
|
console.error("[LLM] Applied initial auto-corrections to AST");
|
|
1127
|
-
validation = await validateDiracCode(session, dynamicAST, { autocorrect: false });
|
|
1127
|
+
validation = await validateDiracCode(session, dynamicAST, { autocorrect: false, deepValidation: true });
|
|
1128
1128
|
console.error(`[LLM] Re-validation after corrections: valid=${validation.valid}`);
|
|
1129
1129
|
}
|
|
1130
1130
|
let retryCount = 0;
|
|
@@ -1188,7 +1188,7 @@ ${result}
|
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
1190
|
dynamicAST = parser.parse(diracCode);
|
|
1191
|
-
validation = await validateDiracCode(session, dynamicAST, { autocorrect });
|
|
1191
|
+
validation = await validateDiracCode(session, dynamicAST, { autocorrect, deepValidation: true });
|
|
1192
1192
|
}
|
|
1193
1193
|
if (!validation.valid) {
|
|
1194
1194
|
throw new Error(`Tag validation failed after ${maxRetries} retries:
|
|
@@ -1272,7 +1272,28 @@ ${correctedCode}
|
|
|
1272
1272
|
}
|
|
1273
1273
|
}
|
|
1274
1274
|
}
|
|
1275
|
-
|
|
1275
|
+
let executionError = null;
|
|
1276
|
+
try {
|
|
1277
|
+
await integrate(session, dynamicAST);
|
|
1278
|
+
} catch (execError) {
|
|
1279
|
+
executionError = execError instanceof Error ? execError.message : String(execError);
|
|
1280
|
+
console.error(`[LLM] Execution error: ${executionError}`);
|
|
1281
|
+
if (feedbackMode && iteration < maxIterations) {
|
|
1282
|
+
const errorFeedback = `System: Your code executed but encountered a runtime error:
|
|
1283
|
+
${executionError}
|
|
1284
|
+
|
|
1285
|
+
Please fix the error and try again.`;
|
|
1286
|
+
dialogHistory.push({ role: "user", content: errorFeedback });
|
|
1287
|
+
if (contextVar) {
|
|
1288
|
+
setVariable(session, contextVar, JSON.stringify(dialogHistory), true);
|
|
1289
|
+
} else if (saveDialog) {
|
|
1290
|
+
setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
|
|
1291
|
+
}
|
|
1292
|
+
continue;
|
|
1293
|
+
} else {
|
|
1294
|
+
throw execError;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1276
1297
|
if (iteration === 1) {
|
|
1277
1298
|
dumpGeneratedSubroutines(session, diracCode, userPrompt);
|
|
1278
1299
|
}
|
|
@@ -1927,7 +1948,7 @@ async function executeTagCheck(session, element) {
|
|
|
1927
1948
|
const executeTag = correctedTag || tagName;
|
|
1928
1949
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1929
1950
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1930
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1951
|
+
const { integrate: integrate2 } = await import("./interpreter-4CIWAOBY.js");
|
|
1931
1952
|
await integrate2(session, elementToExecute);
|
|
1932
1953
|
}
|
|
1933
1954
|
}
|
|
@@ -1936,7 +1957,7 @@ async function executeTagCheck(session, element) {
|
|
|
1936
1957
|
// src/tags/throw.ts
|
|
1937
1958
|
async function executeThrow(session, element) {
|
|
1938
1959
|
const exceptionName = element.attributes?.name || "exception";
|
|
1939
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1960
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-4CIWAOBY.js");
|
|
1940
1961
|
const exceptionDom = {
|
|
1941
1962
|
tag: "exception-content",
|
|
1942
1963
|
attributes: { name: exceptionName },
|
|
@@ -1949,7 +1970,7 @@ async function executeThrow(session, element) {
|
|
|
1949
1970
|
// src/tags/try.ts
|
|
1950
1971
|
async function executeTry(session, element) {
|
|
1951
1972
|
setExceptionBoundary(session);
|
|
1952
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1973
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-4CIWAOBY.js");
|
|
1953
1974
|
await integrateChildren2(session, element);
|
|
1954
1975
|
unsetExceptionBoundary(session);
|
|
1955
1976
|
}
|
|
@@ -1959,7 +1980,7 @@ async function executeCatch(session, element) {
|
|
|
1959
1980
|
const exceptionName = element.attributes?.name || "exception";
|
|
1960
1981
|
const caughtCount = lookupException(session, exceptionName);
|
|
1961
1982
|
if (caughtCount > 0) {
|
|
1962
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1983
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-4CIWAOBY.js");
|
|
1963
1984
|
await integrateChildren2(session, element);
|
|
1964
1985
|
}
|
|
1965
1986
|
flushCurrentException(session);
|
|
@@ -1968,7 +1989,7 @@ async function executeCatch(session, element) {
|
|
|
1968
1989
|
// src/tags/exception.ts
|
|
1969
1990
|
async function executeException(session, element) {
|
|
1970
1991
|
const exceptions = getCurrentExceptions(session);
|
|
1971
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1992
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-4CIWAOBY.js");
|
|
1972
1993
|
for (const exceptionDom of exceptions) {
|
|
1973
1994
|
await integrateChildren2(session, exceptionDom);
|
|
1974
1995
|
}
|
|
@@ -2169,7 +2190,7 @@ async function executeLoadContext(session, element) {
|
|
|
2169
2190
|
query = element.text.trim();
|
|
2170
2191
|
}
|
|
2171
2192
|
if (!query && element.children.length > 0) {
|
|
2172
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
2193
|
+
const { integrate: integrate2 } = await import("./interpreter-4CIWAOBY.js");
|
|
2173
2194
|
const beforeOutput = session.output.length;
|
|
2174
2195
|
for (const child of element.children) {
|
|
2175
2196
|
await integrate2(session, child);
|
|
@@ -3013,7 +3034,7 @@ async function executeForeach(session, element) {
|
|
|
3013
3034
|
const parser2 = new DiracParser2();
|
|
3014
3035
|
try {
|
|
3015
3036
|
const fromElement = parser2.parse(fromAttr);
|
|
3016
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
3037
|
+
const { integrate: integrate2 } = await import("./interpreter-4CIWAOBY.js");
|
|
3017
3038
|
await integrate2(session, fromElement);
|
|
3018
3039
|
} catch (e) {
|
|
3019
3040
|
session.output = savedOutput;
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-CDTZNFCJ.js";
|
|
5
5
|
import {
|
|
6
6
|
BraKetParser
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4TBIVB4X.js";
|
|
8
8
|
import "./chunk-ECAW4X46.js";
|
|
9
9
|
import "./chunk-SLGJRZ3P.js";
|
|
10
10
|
import "./chunk-HRHAMPOB.js";
|
|
@@ -16,7 +16,7 @@ import "dotenv/config";
|
|
|
16
16
|
// package.json
|
|
17
17
|
var package_default = {
|
|
18
18
|
name: "dirac-lang",
|
|
19
|
-
version: "0.1.
|
|
19
|
+
version: "0.1.96",
|
|
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-CY5XIPQC.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-MJSTQERB.js");
|
|
203
203
|
await runAgentDaemon();
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
|
-
const { AgentCLI } = await import("./agent-
|
|
206
|
+
const { AgentCLI } = await import("./agent-MJSTQERB.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-CY5XIPQC.js");
|
|
234
|
+
const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-TQPJVLA4.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-TQPJVLA4.js");
|
|
281
281
|
const server = new SessionServer();
|
|
282
282
|
await server.start();
|
|
283
283
|
console.log("Session daemon started");
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CDTZNFCJ.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-4TBIVB4X.js";
|
|
9
9
|
import "./chunk-ECAW4X46.js";
|
|
10
10
|
import "./chunk-SLGJRZ3P.js";
|
|
11
11
|
import {
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
SessionServer,
|
|
3
3
|
getSocketPath,
|
|
4
4
|
isSessionRunning
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-KFMG6CZW.js";
|
|
6
|
+
import "./chunk-4TBIVB4X.js";
|
|
7
7
|
import "./chunk-ECAW4X46.js";
|
|
8
8
|
import "./chunk-SLGJRZ3P.js";
|
|
9
9
|
import "./chunk-HRHAMPOB.js";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
BraKetParser,
|
|
4
4
|
integrate
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4TBIVB4X.js";
|
|
6
6
|
import "./chunk-ECAW4X46.js";
|
|
7
7
|
import "./chunk-SLGJRZ3P.js";
|
|
8
8
|
import {
|
|
@@ -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-KMBLI46W.js").then(({ stopAllScheduledTasks }) => {
|
|
362
362
|
stopAllScheduledTasks();
|
|
363
363
|
console.log("\nGoodbye!");
|
|
364
364
|
process.exit(0);
|
|
@@ -542,7 +542,7 @@ Commands:
|
|
|
542
542
|
:scheduled List all scheduled runs (run-at)
|
|
543
543
|
:cancel <name> Cancel a scheduled run
|
|
544
544
|
:cancelall Cancel all scheduled runs
|
|
545
|
-
:save-training Save LLM dialog as training data (opens in editor)
|
|
545
|
+
:save-training [mode=full|pruned|both] Save LLM dialog as training data (opens in editor)
|
|
546
546
|
:exit Exit shell
|
|
547
547
|
|
|
548
548
|
Syntax:
|
|
@@ -763,7 +763,7 @@ Examples:
|
|
|
763
763
|
break;
|
|
764
764
|
case "tasks":
|
|
765
765
|
try {
|
|
766
|
-
const { listScheduledTasks } = await import("./schedule-
|
|
766
|
+
const { listScheduledTasks } = await import("./schedule-KMBLI46W.js");
|
|
767
767
|
const tasks = listScheduledTasks();
|
|
768
768
|
if (tasks.length === 0) {
|
|
769
769
|
console.log("No scheduled tasks running.");
|
|
@@ -782,7 +782,7 @@ Examples:
|
|
|
782
782
|
console.log("Usage: :stop <task-name>");
|
|
783
783
|
} else {
|
|
784
784
|
try {
|
|
785
|
-
const { stopScheduledTask } = await import("./schedule-
|
|
785
|
+
const { stopScheduledTask } = await import("./schedule-KMBLI46W.js");
|
|
786
786
|
const taskName = args[0];
|
|
787
787
|
const stopped = stopScheduledTask(taskName);
|
|
788
788
|
if (stopped) {
|
|
@@ -797,7 +797,7 @@ Examples:
|
|
|
797
797
|
break;
|
|
798
798
|
case "stopall":
|
|
799
799
|
try {
|
|
800
|
-
const { stopAllScheduledTasks } = await import("./schedule-
|
|
800
|
+
const { stopAllScheduledTasks } = await import("./schedule-KMBLI46W.js");
|
|
801
801
|
stopAllScheduledTasks();
|
|
802
802
|
console.log("All scheduled tasks stopped.");
|
|
803
803
|
} catch (error) {
|
|
@@ -806,7 +806,7 @@ Examples:
|
|
|
806
806
|
break;
|
|
807
807
|
case "crons":
|
|
808
808
|
try {
|
|
809
|
-
const { listCronJobs } = await import("./cron-
|
|
809
|
+
const { listCronJobs } = await import("./cron-2J3SEPZW.js");
|
|
810
810
|
const jobs = listCronJobs();
|
|
811
811
|
if (jobs.length === 0) {
|
|
812
812
|
console.log("No cron jobs running.");
|
|
@@ -826,7 +826,7 @@ Examples:
|
|
|
826
826
|
console.log("Usage: :stopcron <job-name>");
|
|
827
827
|
} else {
|
|
828
828
|
try {
|
|
829
|
-
const { stopCronJob } = await import("./cron-
|
|
829
|
+
const { stopCronJob } = await import("./cron-2J3SEPZW.js");
|
|
830
830
|
const jobName = args[0];
|
|
831
831
|
const stopped = stopCronJob(jobName);
|
|
832
832
|
if (stopped) {
|
|
@@ -841,7 +841,7 @@ Examples:
|
|
|
841
841
|
break;
|
|
842
842
|
case "stopallcrons":
|
|
843
843
|
try {
|
|
844
|
-
const { stopAllCronJobs } = await import("./cron-
|
|
844
|
+
const { stopAllCronJobs } = await import("./cron-2J3SEPZW.js");
|
|
845
845
|
stopAllCronJobs();
|
|
846
846
|
console.log("All cron jobs stopped.");
|
|
847
847
|
} catch (error) {
|
|
@@ -850,7 +850,7 @@ Examples:
|
|
|
850
850
|
break;
|
|
851
851
|
case "scheduled":
|
|
852
852
|
try {
|
|
853
|
-
const { listScheduledRuns } = await import("./run-at-
|
|
853
|
+
const { listScheduledRuns } = await import("./run-at-MHURF5PL.js");
|
|
854
854
|
const runs = listScheduledRuns();
|
|
855
855
|
if (runs.length === 0) {
|
|
856
856
|
console.log("No scheduled runs pending.");
|
|
@@ -870,7 +870,7 @@ Examples:
|
|
|
870
870
|
console.log("Usage: :cancel <run-name>");
|
|
871
871
|
} else {
|
|
872
872
|
try {
|
|
873
|
-
const { cancelScheduledRun } = await import("./run-at-
|
|
873
|
+
const { cancelScheduledRun } = await import("./run-at-MHURF5PL.js");
|
|
874
874
|
const runName = args[0];
|
|
875
875
|
const cancelled = cancelScheduledRun(runName);
|
|
876
876
|
if (cancelled) {
|
|
@@ -885,7 +885,7 @@ Examples:
|
|
|
885
885
|
break;
|
|
886
886
|
case "cancelall":
|
|
887
887
|
try {
|
|
888
|
-
const { cancelAllScheduledRuns } = await import("./run-at-
|
|
888
|
+
const { cancelAllScheduledRuns } = await import("./run-at-MHURF5PL.js");
|
|
889
889
|
cancelAllScheduledRuns();
|
|
890
890
|
console.log("All scheduled runs cancelled.");
|
|
891
891
|
} catch (error) {
|
|
@@ -894,6 +894,21 @@ Examples:
|
|
|
894
894
|
break;
|
|
895
895
|
case "save-training":
|
|
896
896
|
try {
|
|
897
|
+
const fullCommand = cmd.slice(1);
|
|
898
|
+
const saveArgs = fullCommand.split(/\s+/).slice(1);
|
|
899
|
+
let saveMode = "full";
|
|
900
|
+
console.error(`[DEBUG] Full command: "${fullCommand}"`);
|
|
901
|
+
console.error(`[DEBUG] Args:`, saveArgs);
|
|
902
|
+
for (const arg of saveArgs) {
|
|
903
|
+
if (arg.startsWith("mode=")) {
|
|
904
|
+
saveMode = arg.split("=")[1];
|
|
905
|
+
console.error(`[DEBUG] Set mode to: ${saveMode}`);
|
|
906
|
+
} else if (arg === "prune=true") {
|
|
907
|
+
saveMode = "pruned";
|
|
908
|
+
console.error(`[DEBUG] Set mode to pruned`);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
console.error(`[DEBUG] Final saveMode: ${saveMode}`);
|
|
897
912
|
const dialogVar = this.client ? (await this.client.getState()).variables.find((v) => v.name === "__llm_dialog__") : this.session.variables.find((v) => v.name === "__llm_dialog__");
|
|
898
913
|
if (!dialogVar || !dialogVar.value) {
|
|
899
914
|
console.log("No LLM dialog to save");
|
|
@@ -904,10 +919,64 @@ Examples:
|
|
|
904
919
|
console.log("Dialog is empty");
|
|
905
920
|
break;
|
|
906
921
|
}
|
|
907
|
-
const
|
|
922
|
+
const pruneCorrections = (msgs) => {
|
|
923
|
+
const pruned = [];
|
|
924
|
+
let skipNext = false;
|
|
925
|
+
let correctionCount = 0;
|
|
926
|
+
for (let i = 0; i < msgs.length; i++) {
|
|
927
|
+
const msg = msgs[i];
|
|
928
|
+
if (msg.role === "system") {
|
|
929
|
+
pruned.push(msg);
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
if (skipNext) {
|
|
933
|
+
skipNext = false;
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (msg.role === "user" && (msg.content.includes("System: Your submitted code had errors") || msg.content.includes("System: Auto-corrections applied"))) {
|
|
937
|
+
correctionCount++;
|
|
938
|
+
console.error(`[PRUNE] Found correction message at index ${i}`);
|
|
939
|
+
if (pruned.length > 0 && pruned[pruned.length - 1].role === "assistant") {
|
|
940
|
+
console.error(`[PRUNE] Removing wrong assistant response`);
|
|
941
|
+
pruned.pop();
|
|
942
|
+
}
|
|
943
|
+
if (i + 1 < msgs.length && msgs[i + 1].role === "assistant") {
|
|
944
|
+
console.error(`[PRUNE] Keeping corrected assistant response`);
|
|
945
|
+
pruned.push(msgs[i + 1]);
|
|
946
|
+
skipNext = true;
|
|
947
|
+
}
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
pruned.push(msg);
|
|
951
|
+
}
|
|
952
|
+
console.error(`[PRUNE] Processed ${msgs.length} messages, found ${correctionCount} corrections, result has ${pruned.length} messages`);
|
|
953
|
+
return pruned;
|
|
954
|
+
};
|
|
955
|
+
const fullExample = { messages: dialog };
|
|
956
|
+
const prunedExample = { messages: pruneCorrections(dialog) };
|
|
957
|
+
console.log(`
|
|
958
|
+
Mode: ${saveMode}`);
|
|
959
|
+
if (saveMode === "full" || saveMode === "both") {
|
|
960
|
+
console.log(`Full dialog: ${dialog.length} messages`);
|
|
961
|
+
}
|
|
962
|
+
if (saveMode === "pruned" || saveMode === "both") {
|
|
963
|
+
console.log(`Pruned dialog: ${prunedExample.messages.length} messages (removed ${dialog.length - prunedExample.messages.length} correction messages)`);
|
|
964
|
+
}
|
|
908
965
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0] + "-" + Date.now();
|
|
909
966
|
const tempFile = path.join(os.tmpdir(), `dirac-training-${timestamp}.jsonl`);
|
|
910
|
-
|
|
967
|
+
let tempContent;
|
|
968
|
+
if (saveMode === "both") {
|
|
969
|
+
tempContent = `// FULL VERSION (with corrections)
|
|
970
|
+
${JSON.stringify(fullExample, null, 2)}
|
|
971
|
+
|
|
972
|
+
// PRUNED VERSION (mistakes removed)
|
|
973
|
+
${JSON.stringify(prunedExample, null, 2)}`;
|
|
974
|
+
} else if (saveMode === "pruned") {
|
|
975
|
+
tempContent = JSON.stringify(prunedExample, null, 2);
|
|
976
|
+
} else {
|
|
977
|
+
tempContent = JSON.stringify(fullExample, null, 2);
|
|
978
|
+
}
|
|
979
|
+
fs.writeFileSync(tempFile, tempContent, "utf-8");
|
|
911
980
|
console.log("Opening in editor...");
|
|
912
981
|
const editor = process.env.EDITOR || process.env.VISUAL || "vi";
|
|
913
982
|
const { spawnSync } = await import("child_process");
|
|
@@ -944,10 +1013,40 @@ Examples:
|
|
|
944
1013
|
savePath = path.join(trainingDir, answer.endsWith(".jsonl") ? answer : `${answer}.jsonl`);
|
|
945
1014
|
}
|
|
946
1015
|
const editedContent = fs.readFileSync(tempFile, "utf-8");
|
|
947
|
-
|
|
948
|
-
|
|
1016
|
+
if (saveMode === "both") {
|
|
1017
|
+
const lines = editedContent.split("\n");
|
|
1018
|
+
let fullJson = "";
|
|
1019
|
+
let prunedJson = "";
|
|
1020
|
+
let inFull = false;
|
|
1021
|
+
let inPruned = false;
|
|
1022
|
+
let braceCount = 0;
|
|
1023
|
+
for (const line of lines) {
|
|
1024
|
+
if (line.includes("// FULL VERSION")) {
|
|
1025
|
+
inFull = true;
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
if (line.includes("// PRUNED VERSION")) {
|
|
1029
|
+
inFull = false;
|
|
1030
|
+
inPruned = true;
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
if (inFull) {
|
|
1034
|
+
fullJson += line + "\n";
|
|
1035
|
+
} else if (inPruned) {
|
|
1036
|
+
prunedJson += line + "\n";
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
const fullData = JSON.parse(fullJson.trim());
|
|
1040
|
+
const prunedData = JSON.parse(prunedJson.trim());
|
|
1041
|
+
fs.appendFileSync(savePath, JSON.stringify(fullData) + "\n");
|
|
1042
|
+
fs.appendFileSync(savePath, JSON.stringify(prunedData) + "\n");
|
|
1043
|
+
console.log(`\u2713 Saved 2 training examples (full + pruned) to ${savePath}`);
|
|
1044
|
+
} else {
|
|
1045
|
+
const editedData = JSON.parse(editedContent);
|
|
1046
|
+
fs.appendFileSync(savePath, JSON.stringify(editedData) + "\n");
|
|
1047
|
+
console.log(`\u2713 Saved training example (${saveMode}) to ${savePath}`);
|
|
1048
|
+
}
|
|
949
1049
|
fs.unlinkSync(tempFile);
|
|
950
|
-
console.log(`\u2713 Saved training example to ${savePath}`);
|
|
951
1050
|
} catch (error) {
|
|
952
1051
|
console.error("Error saving training data:", error instanceof Error ? error.message : String(error));
|
|
953
1052
|
}
|
|
@@ -47,8 +47,52 @@ async function getBestTagMatch(candidate, allowed) {
|
|
|
47
47
|
});
|
|
48
48
|
return { tag: allowed[bestIdx], score: bestScore };
|
|
49
49
|
}
|
|
50
|
+
function validateParameterType(paramName, value, expectedType) {
|
|
51
|
+
if (!expectedType) {
|
|
52
|
+
return { valid: true };
|
|
53
|
+
}
|
|
54
|
+
const type = expectedType.split(":")[0].toLowerCase();
|
|
55
|
+
switch (type) {
|
|
56
|
+
case "boolean":
|
|
57
|
+
if (value !== "true" && value !== "false" && value !== "") {
|
|
58
|
+
return {
|
|
59
|
+
valid: false,
|
|
60
|
+
error: `Parameter '${paramName}' expects boolean (true/false), got: ${value}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case "number":
|
|
65
|
+
case "integer":
|
|
66
|
+
if (value !== "" && isNaN(Number(value))) {
|
|
67
|
+
return {
|
|
68
|
+
valid: false,
|
|
69
|
+
error: `Parameter '${paramName}' expects number, got: ${value}`
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case "string":
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
return { valid: true };
|
|
79
|
+
}
|
|
80
|
+
async function validateNestedTags(session, element, options = {}) {
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const child of element.children) {
|
|
83
|
+
if (child.tag && child.tag.trim() !== "") {
|
|
84
|
+
const result = await validateTag(session, child, options);
|
|
85
|
+
results.push(result);
|
|
86
|
+
if (child.children && child.children.length > 0) {
|
|
87
|
+
const nestedResults = await validateNestedTags(session, child, options);
|
|
88
|
+
results.push(...nestedResults);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
50
94
|
async function validateTag(session, element, options = {}) {
|
|
51
|
-
const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF } = options;
|
|
95
|
+
const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF, deepValidation = false } = options;
|
|
52
96
|
console.error(`[VALIDATE] Tag: <${element.tag}>, autocorrect: ${autocorrect}, attributes:`, Object.keys(element.attributes));
|
|
53
97
|
const { getAvailableSubroutines } = await import("./session-IH5LO7FS.js");
|
|
54
98
|
const subroutines = getAvailableSubroutines(session);
|
|
@@ -61,7 +105,9 @@ async function validateTag(session, element, options = {}) {
|
|
|
61
105
|
corrected: false,
|
|
62
106
|
errors: [],
|
|
63
107
|
warnings: [],
|
|
64
|
-
attributeCorrections: {}
|
|
108
|
+
attributeCorrections: {},
|
|
109
|
+
typeErrors: [],
|
|
110
|
+
nestedValidation: []
|
|
65
111
|
};
|
|
66
112
|
if (allowed.has(tagName)) {
|
|
67
113
|
console.error(`[VALIDATE] Tag <${tagName}> is valid`);
|
|
@@ -75,6 +121,10 @@ async function validateTag(session, element, options = {}) {
|
|
|
75
121
|
}
|
|
76
122
|
}
|
|
77
123
|
for (const attr in element.attributes) {
|
|
124
|
+
if (tagName === "subroutine" && (attr.startsWith("param-") || attr.startsWith("meta-"))) {
|
|
125
|
+
console.error(`[VALIDATE] Skipping validation for wildcard attribute '${attr}' on <subroutine>`);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
78
128
|
if (!paramNames.includes(attr)) {
|
|
79
129
|
console.error(`[VALIDATE] Unknown attribute '${attr}' on <${tagName}>`);
|
|
80
130
|
if (autocorrect && paramNames.length > 0) {
|
|
@@ -108,6 +158,25 @@ async function validateTag(session, element, options = {}) {
|
|
|
108
158
|
}
|
|
109
159
|
}
|
|
110
160
|
}
|
|
161
|
+
for (const attr in element.attributes) {
|
|
162
|
+
const param = sub.parameters.find((p) => p.name === attr);
|
|
163
|
+
if (param && param.type) {
|
|
164
|
+
const typeCheck = validateParameterType(attr, element.attributes[attr], param.type);
|
|
165
|
+
if (!typeCheck.valid && typeCheck.error) {
|
|
166
|
+
result.typeErrors.push(typeCheck.error);
|
|
167
|
+
result.errors.push(typeCheck.error);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (deepValidation && tagName === "subroutine" && element.children && element.children.length > 0) {
|
|
172
|
+
console.error(`[VALIDATE] Deep validation of <subroutine name="${element.attributes.name}">`);
|
|
173
|
+
result.nestedValidation = await validateNestedTags(session, element, options);
|
|
174
|
+
for (const nestedResult of result.nestedValidation) {
|
|
175
|
+
if (!nestedResult.valid) {
|
|
176
|
+
result.warnings.push(`Nested tag <${nestedResult.originalTag}>: ${nestedResult.errors.join(", ")}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
111
180
|
}
|
|
112
181
|
result.valid = result.errors.length === 0;
|
|
113
182
|
} else {
|
|
@@ -160,6 +229,7 @@ async function validateTag(session, element, options = {}) {
|
|
|
160
229
|
async function validateDiracCode(session, ast, options = {}) {
|
|
161
230
|
const results = [];
|
|
162
231
|
const errorMessages = [];
|
|
232
|
+
const typeErrors = [];
|
|
163
233
|
async function validateElement(element) {
|
|
164
234
|
if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
|
|
165
235
|
const result = await validateTag(session, element, options);
|
|
@@ -167,6 +237,9 @@ async function validateDiracCode(session, ast, options = {}) {
|
|
|
167
237
|
if (!result.valid) {
|
|
168
238
|
errorMessages.push(`<${result.originalTag}>: ${result.errors.join(", ")}`);
|
|
169
239
|
}
|
|
240
|
+
if (result.typeErrors && result.typeErrors.length > 0) {
|
|
241
|
+
typeErrors.push(...result.typeErrors);
|
|
242
|
+
}
|
|
170
243
|
}
|
|
171
244
|
for (const child of element.children) {
|
|
172
245
|
await validateElement(child);
|
|
@@ -176,7 +249,8 @@ async function validateDiracCode(session, ast, options = {}) {
|
|
|
176
249
|
return {
|
|
177
250
|
valid: errorMessages.length === 0,
|
|
178
251
|
results,
|
|
179
|
-
errorMessages
|
|
252
|
+
errorMessages,
|
|
253
|
+
typeErrors
|
|
180
254
|
};
|
|
181
255
|
}
|
|
182
256
|
function applyCorrectedTags(ast, results) {
|
package/dist/test-runner.js
CHANGED