dirac-lang 0.1.92 → 0.1.94

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.
@@ -2,8 +2,8 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-HKCQJKQC.js";
6
- import "./chunk-ZRYXVVUV.js";
5
+ } from "./chunk-3MD2NFUM.js";
6
+ import "./chunk-6CVWLZYL.js";
7
7
  import "./chunk-ECAW4X46.js";
8
8
  import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-ZRYXVVUV.js";
3
+ } from "./chunk-6CVWLZYL.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./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-WRW3KH2U.js");
490
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
491
491
  await integrateChildren2(session, thenElement);
492
492
  }
493
493
  } else {
494
494
  if (elseElement) {
495
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WRW3KH2U.js");
495
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.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-WRW3KH2U.js");
508
+ const { integrate: integrate2 } = await import("./interpreter-QR2YWK6R.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-WRW3KH2U.js");
531
+ const { integrate: integrate2 } = await import("./interpreter-QR2YWK6R.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-WRW3KH2U.js");
535
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
536
536
  await integrateChildren2(session, child);
537
537
  const newChunks = session.output.slice(argOutputStart);
538
538
  const argValue = newChunks.join("");
@@ -722,6 +722,37 @@ function serializeElement(element, prompt) {
722
722
  serialize(element);
723
723
  return lines.join("\n");
724
724
  }
725
+ function serializeSimple(el, indent, lines) {
726
+ if (el.text && !el.tag) {
727
+ const trimmed = el.text.trim();
728
+ if (trimmed) {
729
+ lines.push(indent + trimmed);
730
+ }
731
+ return;
732
+ }
733
+ if (!el.tag) return;
734
+ let tag = `${indent}<${el.tag}`;
735
+ if (el.attributes) {
736
+ for (const [key, value] of Object.entries(el.attributes)) {
737
+ tag += ` ${key}="${value.replace(/"/g, "&quot;")}"`;
738
+ }
739
+ }
740
+ if (!el.children || el.children.length === 0) {
741
+ if (el.text) {
742
+ lines.push(tag + ">");
743
+ lines.push(indent + " " + el.text);
744
+ lines.push(`${indent}</${el.tag}>`);
745
+ } else {
746
+ lines.push(tag + " />");
747
+ }
748
+ } else {
749
+ lines.push(tag + ">");
750
+ for (const child of el.children) {
751
+ serializeSimple(child, indent + " ", lines);
752
+ }
753
+ lines.push(`${indent}</${el.tag}>`);
754
+ }
755
+ }
725
756
  async function executeLLM(session, element) {
726
757
  if (!session.llmClient) {
727
758
  throw new Error("<llm> tag requires LLM configuration. Set LLM_PROVIDER (ollama/anthropic/openai/custom) and appropriate API keys in environment or config.yml");
@@ -1021,6 +1052,7 @@ ${result}
1021
1052
  const autocorrect = element.attributes["autocorrect"] === "true";
1022
1053
  const maxRetries = parseInt(element.attributes["max-retries"] || "0", 10);
1023
1054
  const feedbackMode = element.attributes["feedback"] === "true";
1055
+ console.error(`[LLM] Execute mode - validate: ${validateTags}, autocorrect: ${autocorrect}, feedback: ${feedbackMode}, debug: ${session.debug}`);
1024
1056
  const maxIterationsAttr = substituteAttribute(session, element.attributes["max-iterations"] || "3");
1025
1057
  const maxIterations = parseInt(maxIterationsAttr, 10);
1026
1058
  const replaceTick = element.attributes["replace-tick"] === "true";
@@ -1041,6 +1073,7 @@ ${result}
1041
1073
  if (session.debug && feedbackMode) {
1042
1074
  console.error(`[LLM] Feedback iteration ${iteration}/${maxIterations}`);
1043
1075
  }
1076
+ let correctionMessages = [];
1044
1077
  let diracCode = result.trim();
1045
1078
  if (replaceTick && diracCode.startsWith("```")) {
1046
1079
  const match = diracCode.match(/^```(\w+)?\n?/m);
@@ -1057,8 +1090,42 @@ ${result}
1057
1090
  const parser = new DiracParser();
1058
1091
  let dynamicAST = parser.parse(diracCode);
1059
1092
  if (validateTags) {
1060
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-TSD3CDMQ.js");
1093
+ if (session.debug) {
1094
+ console.error(`[LLM] Validation enabled, autocorrect: ${autocorrect}`);
1095
+ }
1096
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-D7FH7P5F.js");
1061
1097
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
1098
+ if (session.debug) {
1099
+ console.error(`[LLM] Validation result: valid=${validation.valid}, results count=${validation.results.length}`);
1100
+ if (validation.results.length > 0) {
1101
+ console.error(`[LLM] Validation details:`, validation.results.map((r) => ({
1102
+ tag: r.tagName,
1103
+ originalTag: r.originalTag,
1104
+ corrected: r.corrected,
1105
+ attrCorrections: r.attributeCorrections,
1106
+ warnings: r.warnings
1107
+ })));
1108
+ }
1109
+ }
1110
+ if (autocorrect) {
1111
+ console.error(`[LLM] Applying corrections from initial ${validation.results.length} validation results`);
1112
+ for (const result2 of validation.results) {
1113
+ if (result2.corrected) {
1114
+ correctionMessages.push(`Auto-corrected: <${result2.originalTag}> \u2192 <${result2.tagName}> (similarity: ${result2.similarity?.toFixed(2)})`);
1115
+ }
1116
+ if (result2.warnings.length > 0) {
1117
+ correctionMessages.push(...result2.warnings);
1118
+ }
1119
+ }
1120
+ console.error("[LLM] Initial correction messages collected:", correctionMessages.length);
1121
+ if (correctionMessages.length > 0) {
1122
+ console.error("[LLM] Corrections:", correctionMessages.join("; "));
1123
+ }
1124
+ dynamicAST = applyCorrectedTags(dynamicAST, validation.results);
1125
+ console.error("[LLM] Applied initial auto-corrections to AST");
1126
+ validation = await validateDiracCode(session, dynamicAST, { autocorrect: false });
1127
+ console.error(`[LLM] Re-validation after corrections: valid=${validation.valid}`);
1128
+ }
1062
1129
  let retryCount = 0;
1063
1130
  while (!validation.valid && retryCount < maxRetries) {
1064
1131
  retryCount++;
@@ -1126,10 +1193,26 @@ ${result}
1126
1193
  throw new Error(`Tag validation failed after ${maxRetries} retries:
1127
1194
  ${validation.errorMessages.join("\n")}`);
1128
1195
  }
1129
- if (autocorrect) {
1130
- dynamicAST = applyCorrectedTags(dynamicAST, validation.results);
1131
- if (session.debug) {
1132
- console.error("[LLM] Applied auto-corrections to tags");
1196
+ if (correctionMessages.length > 0 && feedbackMode) {
1197
+ const correctedCodeLines = [];
1198
+ for (const child of dynamicAST.children) {
1199
+ if (child.tag && child.tag !== "DIRAC-ROOT") {
1200
+ serializeSimple(child, "", correctedCodeLines);
1201
+ }
1202
+ }
1203
+ const correctedCode = correctedCodeLines.join("\n");
1204
+ const correctionFeedback = `System: Auto-corrections applied:
1205
+ ${correctionMessages.join("\n")}
1206
+
1207
+ Actual code executed:
1208
+ \`\`\`xml
1209
+ ${correctedCode}
1210
+ \`\`\``;
1211
+ dialogHistory.push({ role: "user", content: correctionFeedback });
1212
+ if (contextVar) {
1213
+ setVariable(session, contextVar, JSON.stringify(dialogHistory), true);
1214
+ } else if (saveDialog) {
1215
+ setVariable(session, "__llm_dialog__", JSON.stringify(dialogHistory), true);
1133
1216
  }
1134
1217
  }
1135
1218
  }
@@ -1788,7 +1871,7 @@ async function executeTagCheck(session, element) {
1788
1871
  const executeTag = correctedTag || tagName;
1789
1872
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1790
1873
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1791
- const { integrate: integrate2 } = await import("./interpreter-WRW3KH2U.js");
1874
+ const { integrate: integrate2 } = await import("./interpreter-QR2YWK6R.js");
1792
1875
  await integrate2(session, elementToExecute);
1793
1876
  }
1794
1877
  }
@@ -1797,7 +1880,7 @@ async function executeTagCheck(session, element) {
1797
1880
  // src/tags/throw.ts
1798
1881
  async function executeThrow(session, element) {
1799
1882
  const exceptionName = element.attributes?.name || "exception";
1800
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WRW3KH2U.js");
1883
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
1801
1884
  const exceptionDom = {
1802
1885
  tag: "exception-content",
1803
1886
  attributes: { name: exceptionName },
@@ -1810,7 +1893,7 @@ async function executeThrow(session, element) {
1810
1893
  // src/tags/try.ts
1811
1894
  async function executeTry(session, element) {
1812
1895
  setExceptionBoundary(session);
1813
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WRW3KH2U.js");
1896
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
1814
1897
  await integrateChildren2(session, element);
1815
1898
  unsetExceptionBoundary(session);
1816
1899
  }
@@ -1820,7 +1903,7 @@ async function executeCatch(session, element) {
1820
1903
  const exceptionName = element.attributes?.name || "exception";
1821
1904
  const caughtCount = lookupException(session, exceptionName);
1822
1905
  if (caughtCount > 0) {
1823
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WRW3KH2U.js");
1906
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
1824
1907
  await integrateChildren2(session, element);
1825
1908
  }
1826
1909
  flushCurrentException(session);
@@ -1829,7 +1912,7 @@ async function executeCatch(session, element) {
1829
1912
  // src/tags/exception.ts
1830
1913
  async function executeException(session, element) {
1831
1914
  const exceptions = getCurrentExceptions(session);
1832
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WRW3KH2U.js");
1915
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-QR2YWK6R.js");
1833
1916
  for (const exceptionDom of exceptions) {
1834
1917
  await integrateChildren2(session, exceptionDom);
1835
1918
  }
@@ -2030,7 +2113,7 @@ async function executeLoadContext(session, element) {
2030
2113
  query = element.text.trim();
2031
2114
  }
2032
2115
  if (!query && element.children.length > 0) {
2033
- const { integrate: integrate2 } = await import("./interpreter-WRW3KH2U.js");
2116
+ const { integrate: integrate2 } = await import("./interpreter-QR2YWK6R.js");
2034
2117
  const beforeOutput = session.output.length;
2035
2118
  for (const child of element.children) {
2036
2119
  await integrate2(session, child);
@@ -2874,7 +2957,7 @@ async function executeForeach(session, element) {
2874
2957
  const parser2 = new DiracParser2();
2875
2958
  try {
2876
2959
  const fromElement = parser2.parse(fromAttr);
2877
- const { integrate: integrate2 } = await import("./interpreter-WRW3KH2U.js");
2960
+ const { integrate: integrate2 } = await import("./interpreter-QR2YWK6R.js");
2878
2961
  await integrate2(session, fromElement);
2879
2962
  } catch (e) {
2880
2963
  session.output = savedOutput;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-ZRYXVVUV.js";
3
+ } from "./chunk-6CVWLZYL.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execute
4
- } from "./chunk-OHHVPQEJ.js";
4
+ } from "./chunk-LHNUYXML.js";
5
5
  import {
6
6
  BraKetParser
7
- } from "./chunk-ZRYXVVUV.js";
7
+ } from "./chunk-6CVWLZYL.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.92",
19
+ version: "0.1.94",
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-MGGRRK5F.js");
153
+ const { DiracShell } = await import("./shell-3FJRBNSJ.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-ZYONE5JH.js");
202
+ const { runAgentDaemon } = await import("./agent-L6C3Z2YG.js");
203
203
  await runAgentDaemon();
204
204
  return;
205
205
  }
206
- const { AgentCLI } = await import("./agent-ZYONE5JH.js");
206
+ const { AgentCLI } = await import("./agent-L6C3Z2YG.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-MGGRRK5F.js");
234
- const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-Y2RLLKSF.js");
233
+ const { DiracShell } = await import("./shell-3FJRBNSJ.js");
234
+ const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-H6P4IXUF.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-Y2RLLKSF.js");
280
+ const { SessionServer } = await import("./session-server-H6P4IXUF.js");
281
281
  const server = new SessionServer();
282
282
  await server.start();
283
283
  console.log("Session daemon started");
@@ -3,7 +3,7 @@ import {
3
3
  listCronJobs,
4
4
  stopAllCronJobs,
5
5
  stopCronJob
6
- } from "./chunk-ZRYXVVUV.js";
6
+ } from "./chunk-6CVWLZYL.js";
7
7
  import "./chunk-ECAW4X46.js";
8
8
  import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-OHHVPQEJ.js";
5
+ } from "./chunk-LHNUYXML.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-ZRYXVVUV.js";
8
+ } from "./chunk-6CVWLZYL.js";
9
9
  import "./chunk-ECAW4X46.js";
10
10
  import "./chunk-SLGJRZ3P.js";
11
11
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-ZRYXVVUV.js";
4
+ } from "./chunk-6CVWLZYL.js";
5
5
  import "./chunk-ECAW4X46.js";
6
6
  import "./chunk-SLGJRZ3P.js";
7
7
  import "./chunk-HRHAMPOB.js";
@@ -3,7 +3,7 @@ import {
3
3
  cancelScheduledRun,
4
4
  executeRunAt,
5
5
  listScheduledRuns
6
- } from "./chunk-ZRYXVVUV.js";
6
+ } from "./chunk-6CVWLZYL.js";
7
7
  import "./chunk-ECAW4X46.js";
8
8
  import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
@@ -3,7 +3,7 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-ZRYXVVUV.js";
6
+ } from "./chunk-6CVWLZYL.js";
7
7
  import "./chunk-ECAW4X46.js";
8
8
  import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
@@ -2,8 +2,8 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-HKCQJKQC.js";
6
- import "./chunk-ZRYXVVUV.js";
5
+ } from "./chunk-3MD2NFUM.js";
6
+ import "./chunk-6CVWLZYL.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-ZRYXVVUV.js";
5
+ } from "./chunk-6CVWLZYL.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-6EIX67FE.js").then(({ stopAllScheduledTasks }) => {
361
+ import("./schedule-5SRRRO6K.js").then(({ stopAllScheduledTasks }) => {
362
362
  stopAllScheduledTasks();
363
363
  console.log("\nGoodbye!");
364
364
  process.exit(0);
@@ -763,7 +763,7 @@ Examples:
763
763
  break;
764
764
  case "tasks":
765
765
  try {
766
- const { listScheduledTasks } = await import("./schedule-6EIX67FE.js");
766
+ const { listScheduledTasks } = await import("./schedule-5SRRRO6K.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-6EIX67FE.js");
785
+ const { stopScheduledTask } = await import("./schedule-5SRRRO6K.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-6EIX67FE.js");
800
+ const { stopAllScheduledTasks } = await import("./schedule-5SRRRO6K.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-TEN2VZLP.js");
809
+ const { listCronJobs } = await import("./cron-CI4QNHTO.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-TEN2VZLP.js");
829
+ const { stopCronJob } = await import("./cron-CI4QNHTO.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-TEN2VZLP.js");
844
+ const { stopAllCronJobs } = await import("./cron-CI4QNHTO.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-EVMKFRM2.js");
853
+ const { listScheduledRuns } = await import("./run-at-IDE7KGHV.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-EVMKFRM2.js");
873
+ const { cancelScheduledRun } = await import("./run-at-IDE7KGHV.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-EVMKFRM2.js");
888
+ const { cancelAllScheduledRuns } = await import("./run-at-IDE7KGHV.js");
889
889
  cancelAllScheduledRuns();
890
890
  console.log("All scheduled runs cancelled.");
891
891
  } catch (error) {
@@ -49,6 +49,7 @@ async function getBestTagMatch(candidate, allowed) {
49
49
  }
50
50
  async function validateTag(session, element, options = {}) {
51
51
  const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF } = options;
52
+ console.error(`[VALIDATE] Tag: <${element.tag}>, autocorrect: ${autocorrect}, attributes:`, Object.keys(element.attributes));
52
53
  const { getAvailableSubroutines } = await import("./session-IH5LO7FS.js");
53
54
  const subroutines = getAvailableSubroutines(session);
54
55
  const allowed = new Set(subroutines.map((s) => s.name));
@@ -59,12 +60,15 @@ async function validateTag(session, element, options = {}) {
59
60
  originalTag: tagName,
60
61
  corrected: false,
61
62
  errors: [],
62
- warnings: []
63
+ warnings: [],
64
+ attributeCorrections: {}
63
65
  };
64
66
  if (allowed.has(tagName)) {
67
+ console.error(`[VALIDATE] Tag <${tagName}> is valid`);
65
68
  const sub = subroutines.find((s) => s.name === tagName);
66
69
  if (sub && Array.isArray(sub.parameters)) {
67
70
  const paramNames = sub.parameters.map((p) => p.name);
71
+ console.error(`[VALIDATE] Tag <${tagName}> has ${paramNames.length} parameters:`, paramNames);
68
72
  for (const param of sub.parameters) {
69
73
  if (param.required && !(param.name in element.attributes)) {
70
74
  result.errors.push(`Missing required parameter: ${param.name}`);
@@ -72,7 +76,36 @@ async function validateTag(session, element, options = {}) {
72
76
  }
73
77
  for (const attr in element.attributes) {
74
78
  if (!paramNames.includes(attr)) {
75
- result.warnings.push(`Unknown attribute: ${attr}`);
79
+ console.error(`[VALIDATE] Unknown attribute '${attr}' on <${tagName}>`);
80
+ if (autocorrect && paramNames.length > 0) {
81
+ let correctedAttr = null;
82
+ let similarityScore = 0;
83
+ if (paramNames.length === 1) {
84
+ correctedAttr = paramNames[0];
85
+ similarityScore = 1;
86
+ result.attributeCorrections[attr] = correctedAttr;
87
+ result.corrected = true;
88
+ result.warnings.push(`Auto-corrected attribute: ${attr}="${element.attributes[attr]}" \u2192 ${correctedAttr}="${element.attributes[attr]}" (only parameter available)`);
89
+ console.error(`[VALIDATE] Auto-corrected (single param): ${attr} \u2192 ${correctedAttr}`);
90
+ } else {
91
+ console.error(`[VALIDATE] Checking similarity for '${attr}' against:`, paramNames);
92
+ const best = await getBestTagMatch(attr, paramNames);
93
+ console.error(`[VALIDATE] Best match: ${best.tag} with score ${best.score.toFixed(2)}, cutoff: ${similarityCutoff}`);
94
+ if (best.score >= similarityCutoff) {
95
+ correctedAttr = best.tag;
96
+ similarityScore = best.score;
97
+ result.attributeCorrections[attr] = correctedAttr;
98
+ result.corrected = true;
99
+ result.warnings.push(`Auto-corrected attribute: ${attr}="${element.attributes[attr]}" \u2192 ${correctedAttr}="${element.attributes[attr]}" (similarity: ${similarityScore.toFixed(2)})`);
100
+ console.error(`[VALIDATE] Auto-corrected (similarity): ${attr} \u2192 ${correctedAttr}`);
101
+ } else {
102
+ result.warnings.push(`Unknown attribute: ${attr} (no similar match found, best: ${best.tag} with score ${best.score.toFixed(2)})`);
103
+ console.error(`[VALIDATE] No correction (score too low): ${attr}, best was ${best.tag} (${best.score.toFixed(2)})`);
104
+ }
105
+ }
106
+ } else {
107
+ result.warnings.push(`Unknown attribute: ${attr}`);
108
+ }
76
109
  }
77
110
  }
78
111
  }
@@ -95,7 +128,22 @@ async function validateTag(session, element, options = {}) {
95
128
  }
96
129
  for (const attr in element.attributes) {
97
130
  if (!paramNames.includes(attr)) {
98
- result.warnings.push(`Unknown attribute: ${attr}`);
131
+ if (paramNames.length > 0) {
132
+ if (paramNames.length === 1) {
133
+ result.attributeCorrections[attr] = paramNames[0];
134
+ result.warnings.push(`Auto-corrected attribute: ${attr}="${element.attributes[attr]}" \u2192 ${paramNames[0]}="${element.attributes[attr]}" (only parameter available)`);
135
+ } else {
136
+ const attrBest = await getBestTagMatch(attr, paramNames);
137
+ if (attrBest.score >= similarityCutoff) {
138
+ result.attributeCorrections[attr] = attrBest.tag;
139
+ result.warnings.push(`Auto-corrected attribute: ${attr}="${element.attributes[attr]}" \u2192 ${attrBest.tag}="${element.attributes[attr]}" (similarity: ${attrBest.score.toFixed(2)})`);
140
+ } else {
141
+ result.warnings.push(`Unknown attribute: ${attr} (no similar match found, best: ${attrBest.tag} with score ${attrBest.score.toFixed(2)})`);
142
+ }
143
+ }
144
+ } else {
145
+ result.warnings.push(`Unknown attribute: ${attr}`);
146
+ }
99
147
  }
100
148
  }
101
149
  }
@@ -134,10 +182,25 @@ async function validateDiracCode(session, ast, options = {}) {
134
182
  function applyCorrectedTags(ast, results) {
135
183
  let resultIndex = 0;
136
184
  function correctElement(element) {
137
- if (element.tag && element.tag !== "dirac" && element.tag !== "") {
185
+ if (element.tag && element.tag !== "dirac" && element.tag !== "DIRAC-ROOT" && element.tag.trim() !== "") {
138
186
  const result = results[resultIndex++];
139
- if (result && result.corrected) {
140
- element = { ...element, tag: result.tagName };
187
+ if (result) {
188
+ if (result.corrected && result.tagName !== element.tag) {
189
+ console.error(`[APPLY-CORRECTION] Tag: ${element.tag} \u2192 ${result.tagName}`);
190
+ element = { ...element, tag: result.tagName };
191
+ }
192
+ if (result.attributeCorrections && Object.keys(result.attributeCorrections).length > 0) {
193
+ console.error(`[APPLY-CORRECTION] Attributes on <${element.tag}>:`, result.attributeCorrections);
194
+ const newAttributes = {};
195
+ for (const [oldAttr, value] of Object.entries(element.attributes)) {
196
+ const newAttr = result.attributeCorrections[oldAttr] || oldAttr;
197
+ if (newAttr !== oldAttr) {
198
+ console.error(`[APPLY-CORRECTION] ${oldAttr}="${value}" \u2192 ${newAttr}="${value}"`);
199
+ }
200
+ newAttributes[newAttr] = value;
201
+ }
202
+ element = { ...element, attributes: newAttributes };
203
+ }
141
204
  }
142
205
  }
143
206
  return {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-ZRYXVVUV.js";
3
+ } from "./chunk-6CVWLZYL.js";
4
4
  import "./chunk-ECAW4X46.js";
5
5
  import "./chunk-SLGJRZ3P.js";
6
6
  import {
package/lib/ai.di CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
- <llm execute="true" save-dialog="true" show="boundary" feedback="true">
35
+ <llm execute="true" save-dialog="true" show="boundary" feedback="true" validate="true" autocorrect="true">
36
36
 
37
37
 
38
38
 
@@ -18,6 +18,7 @@
18
18
  ============================================================ -->
19
19
 
20
20
  <subroutine name="defvar"
21
+ meta-hide-from-llm="true"
21
22
  description="Define a new variable with optional visibility"
22
23
  param-name="string:required:Variable name"
23
24
  param-value="string:optional:Initial value (or use children/text)"
@@ -27,6 +28,7 @@
27
28
  </subroutine>
28
29
 
29
30
  <subroutine name="assign"
31
+ meta-hide-from-llm="true"
30
32
  description="Assign new value to existing variable"
31
33
  param-name="string:required:Variable name to update"
32
34
  param-value="string:optional:New value (or use children/text)"
@@ -37,12 +39,14 @@
37
39
  </subroutine>
38
40
 
39
41
  <subroutine name="variable"
42
+ meta-hide-from-llm="true"
40
43
  description="Retrieve and output variable value"
41
44
  param-name="string:required:Variable name to retrieve">
42
45
  <!-- Use $varname in attributes or ${varname} in text for substitution -->
43
46
  </subroutine>
44
47
 
45
48
  <subroutine name="environment"
49
+ meta-hide-from-llm="true"
46
50
  description="Read environment variable value"
47
51
  param-name="string:required:Environment variable name">
48
52
  </subroutine>
@@ -52,12 +56,14 @@
52
56
  ============================================================ -->
53
57
 
54
58
  <subroutine name="output"
59
+ meta-hide-from-llm="true"
55
60
  description="Emit content to stdout or file"
56
61
  param-file="string:optional:File path for writing output">
57
62
  <!-- Children are executed and output captured -->
58
63
  </subroutine>
59
64
 
60
65
  <subroutine name="input"
66
+ meta-hide-from-llm="true"
61
67
  description="Read from stdin or file"
62
68
  param-source="string:required:Input source|stdin|file"
63
69
  param-mode="string:optional:Reading mode (default: all)|all|line"
@@ -70,6 +76,7 @@
70
76
  ============================================================ -->
71
77
 
72
78
  <subroutine name="if"
79
+ meta-hide-from-llm="true"
73
80
  description="Conditional execution with cond/then/else children"
74
81
  visible="subroutine">
75
82
  <!-- <if> -->
@@ -81,6 +88,7 @@
81
88
  </subroutine>
82
89
 
83
90
  <subroutine name="test-if"
91
+ meta-hide-from-llm="true"
84
92
  description="Attribute-based conditional execution"
85
93
  param-test="string:required:Value or expression to test"
86
94
  param-eq="string:optional:Compare equal to value"
@@ -93,6 +101,7 @@
93
101
  </subroutine>
94
102
 
95
103
  <subroutine name="loop"
104
+ meta-hide-from-llm="true"
96
105
  description="Iterate fixed number of times"
97
106
  param-count="string:required:Number of iterations (supports variable substitution)"
98
107
  param-var="string:optional:Loop counter variable name (default: i)">
@@ -101,6 +110,7 @@
101
110
  </subroutine>
102
111
 
103
112
  <subroutine name="foreach"
113
+ meta-hide-from-llm="true"
104
114
  description="Iterate over XML elements"
105
115
  param-from="string:required:XML content or variable (starts with $ or &lt;)"
106
116
  param-as="string:optional:Iterator variable name (default: item)"
@@ -108,6 +118,7 @@
108
118
  </subroutine>
109
119
 
110
120
  <subroutine name="break"
121
+ meta-hide-from-llm="true"
111
122
  description="Exit current loop or foreach iteration">
112
123
  <!-- Use with conditionals for while-loop behavior -->
113
124
  </subroutine>
@@ -117,6 +128,7 @@
117
128
  ============================================================ -->
118
129
 
119
130
  <subroutine name="expr"
131
+ meta-hide-from-llm="true"
120
132
  description="Arithmetic and logical operations"
121
133
  param-eval="string:required:Operation to perform"
122
134
  param-op="string:optional:Alias for eval attribute">
@@ -125,6 +137,7 @@
125
137
  </subroutine>
126
138
 
127
139
  <subroutine name="eval"
140
+ meta-hide-from-llm="true"
128
141
  description="Evaluate JavaScript expression with full context"
129
142
  param-name="string:optional:Variable name to store result"
130
143
  param-expr="string:optional:JavaScript code (or use text content)">
@@ -138,6 +151,7 @@
138
151
  ============================================================ -->
139
152
 
140
153
  <subroutine name="subroutine"
154
+ meta-hide-from-llm="true"
141
155
  description="Define reusable code block"
142
156
  param-name="string:required:Subroutine name"
143
157
  param-description="string:optional:Human-readable description"
@@ -153,6 +167,7 @@
153
167
  </subroutine>
154
168
 
155
169
  <subroutine name="call"
170
+ meta-hide-from-llm="true"
156
171
  description="Invoke defined subroutine"
157
172
  param-name="string:required:Subroutine name to call"
158
173
  param-subroutine="string:optional:Alias for name attribute">
@@ -161,6 +176,7 @@
161
176
  </subroutine>
162
177
 
163
178
  <subroutine name="parameters"
179
+ meta-hide-from-llm="true"
164
180
  description="Access parameters passed to subroutine"
165
181
  param-select="string:required:Parameter selector">
166
182
  <!-- select="*" : All child elements (returns output) -->
@@ -169,11 +185,13 @@
169
185
  </subroutine>
170
186
 
171
187
  <subroutine name="available-subroutines"
188
+ meta-hide-from-llm="true"
172
189
  description="List all registered subroutines as XML">
173
190
  <!-- Useful with <foreach> to iterate over subroutines -->
174
191
  </subroutine>
175
192
 
176
193
  <subroutine name="list-subroutines"
194
+ meta-hide-from-llm="true"
177
195
  description="List subroutines in specified format"
178
196
  param-format="string:optional:Output format (default: text)|text|json|xml"
179
197
  param-output="string:optional:Variable name to store result">
@@ -181,6 +199,7 @@
181
199
  </subroutine>
182
200
 
183
201
  <subroutine name="save-subroutine"
202
+ meta-hide-from-llm="true"
184
203
  description="Save subroutine definition to disk"
185
204
  param-name="string:required:Subroutine name to save"
186
205
  param-file="string:optional:Explicit file path"
@@ -197,6 +216,7 @@
197
216
  </subroutine>
198
217
 
199
218
  <subroutine name="edit-subroutine"
219
+ meta-hide-from-llm="true"
200
220
  description="Edit subroutine definition in external editor"
201
221
  param-name="string:required:Subroutine name to edit"
202
222
  param-editor="string:optional:Editor command (default: $EDITOR or vi)">
@@ -207,6 +227,7 @@
207
227
  </subroutine>
208
228
 
209
229
  <subroutine name="subroutine-index"
230
+ meta-hide-from-llm="true"
210
231
  description="Search and manage subroutine knowledge base"
211
232
  param-path="string:optional:Directory to index or search"
212
233
  param-query="string:optional:Natural language search query"
@@ -217,6 +238,7 @@
217
238
  </subroutine>
218
239
 
219
240
  <subroutine name="index-subroutines"
241
+ meta-hide-from-llm="true"
220
242
  description="Index subroutines from files or directories for later search"
221
243
  param-path="string:required:File or directory path to index">
222
244
  <!-- Recursively scans .di files and extracts subroutine definitions -->
@@ -225,6 +247,7 @@
225
247
  </subroutine>
226
248
 
227
249
  <subroutine name="search-subroutines"
250
+ meta-hide-from-llm="true"
228
251
  description="Search indexed subroutines by name or description"
229
252
  param-query="string:required:Search query (name or description keywords)"
230
253
  param-limit="string:optional:Maximum results to return (default: 10)"
@@ -240,6 +263,7 @@
240
263
  ============================================================ -->
241
264
 
242
265
  <subroutine name="execute"
266
+ meta-hide-from-llm="true"
243
267
  description="Execute dynamically generated DIRAC code"
244
268
  param-source="string:optional:Variable containing DIRAC code">
245
269
  <!-- Strips markdown code blocks if present -->
@@ -247,6 +271,7 @@
247
271
  </subroutine>
248
272
 
249
273
  <subroutine name="system"
274
+ meta-hide-from-llm="true"
250
275
  description="Execute shell commands"
251
276
  param-background="string:optional:Run in background without waiting|true|false">
252
277
  <!-- Command built from text content or children -->
@@ -258,6 +283,7 @@
258
283
  ============================================================ -->
259
284
 
260
285
  <subroutine name="import"
286
+ meta-hide-from-llm="true"
261
287
  description="Import subroutines from other DIRAC files"
262
288
  param-src="string:required:File path or package name">
263
289
  <!-- Supports ./ ../ / for paths, otherwise searches node_modules -->
@@ -266,6 +292,7 @@
266
292
  </subroutine>
267
293
 
268
294
  <subroutine name="require_module"
295
+ meta-hide-from-llm="true"
269
296
  description="Load Node.js module into variable"
270
297
  param-name="string:required:Module name to import"
271
298
  param-var="string:optional:Variable name to store module (defaults to name)">
@@ -278,6 +305,7 @@
278
305
  ============================================================ -->
279
306
 
280
307
  <subroutine name="llm"
308
+ meta-hide-from-llm="true"
281
309
  description="Invoke Large Language Model with validation"
282
310
  param-provider="string:optional:LLM provider for this call|anthropic|openai|ollama|custom"
283
311
  param-model="string:optional:Model name or use DEFAULT_MODEL env var"
@@ -308,6 +336,7 @@
308
336
  </subroutine>
309
337
 
310
338
  <subroutine name="load-context"
339
+ meta-hide-from-llm="true"
311
340
  description="Load subroutine definitions as LLM context"
312
341
  param-limit="string:optional:Maximum subroutines to include"
313
342
  param-import="string:optional:Also import subroutines (default: true)|true|false"
@@ -323,6 +352,7 @@
323
352
  ============================================================ -->
324
353
 
325
354
  <subroutine name="try"
355
+ meta-hide-from-llm="true"
326
356
  description="Establish exception boundary">
327
357
  <!-- <try> -->
328
358
  <!-- <defvar name="x" value="${undefined}" /> -->
@@ -332,12 +362,14 @@
332
362
  </subroutine>
333
363
 
334
364
  <subroutine name="catch"
365
+ meta-hide-from-llm="true"
335
366
  description="Catch exceptions by name"
336
367
  param-name="string:optional:Exception name to catch (default: exception)">
337
368
  <!-- Catches exceptions between current position and last <try> boundary -->
338
369
  </subroutine>
339
370
 
340
371
  <subroutine name="throw"
372
+ meta-hide-from-llm="true"
341
373
  description="Throw named exception"
342
374
  param-name="string:optional:Exception name (default: exception)">
343
375
  <!-- Children become exception payload -->
@@ -345,6 +377,7 @@
345
377
  </subroutine>
346
378
 
347
379
  <subroutine name="exception"
380
+ meta-hide-from-llm="true"
348
381
  description="Access caught exception content"
349
382
  param-name="string:optional:Exception variable name">
350
383
  </subroutine>
@@ -354,6 +387,7 @@
354
387
  ============================================================ -->
355
388
 
356
389
  <subroutine name="attr"
390
+ meta-hide-from-llm="true"
357
391
  description="Extract attribute from XML element"
358
392
  param-name="string:required:Attribute name to extract"
359
393
  param-from="string:required:Variable containing XML element">
@@ -366,6 +400,7 @@
366
400
  ============================================================ -->
367
401
 
368
402
  <subroutine name="schedule"
403
+ meta-hide-from-llm="true"
369
404
  description="Run tasks on interval without blocking"
370
405
  param-interval="string:required:Seconds between executions"
371
406
  param-name="string:optional:Task identifier for logging">
@@ -375,6 +410,7 @@
375
410
  </subroutine>
376
411
 
377
412
  <subroutine name="cron"
413
+ meta-hide-from-llm="true"
378
414
  description="Run tasks on cron schedule without blocking"
379
415
  param-time="string:required:Cron expression (minute hour day month weekday)"
380
416
  param-name="string:optional:Job identifier for logging">
@@ -389,6 +425,7 @@
389
425
  </subroutine>
390
426
 
391
427
  <subroutine name="run-at"
428
+ meta-hide-from-llm="true"
392
429
  description="Run task once at future time without blocking"
393
430
  param-time="string:required:When to execute"
394
431
  param-name="string:optional:Run identifier for logging">
@@ -410,6 +447,7 @@
410
447
  ============================================================ -->
411
448
 
412
449
  <subroutine name="mongodb"
450
+ meta-hide-from-llm="true"
413
451
  description="MongoDB database operations"
414
452
  param-connection="string:required:MongoDB connection string"
415
453
  param-database="string:required:Database name"
@@ -426,6 +464,7 @@
426
464
  ============================================================ -->
427
465
 
428
466
  <subroutine name="tag-check"
467
+ meta-hide-from-llm="true"
429
468
  description="Validate tag name availability">
430
469
  <!-- Used during subroutine validation -->
431
470
  </subroutine>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.92",
3
+ "version": "0.1.94",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",