dirac-lang 0.1.58 → 0.1.60

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.
@@ -264,7 +264,8 @@ function getAvailableSubroutines(session) {
264
264
  name: sub.name,
265
265
  description: sub.description,
266
266
  parameters: sub.parameters,
267
- meta: sub.meta
267
+ meta: sub.meta,
268
+ boundary: sub.boundary
268
269
  }));
269
270
  }
270
271
  function throwException(session, name, dom) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-WQ2KRQAR.js";
3
+ } from "./chunk-ZAA6R2TC.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -8,7 +8,7 @@ import {
8
8
  createSession,
9
9
  getAvailableSubroutines,
10
10
  getOutput
11
- } from "./chunk-IN55WRFB.js";
11
+ } from "./chunk-3UW6GWYQ.js";
12
12
 
13
13
  // src/utils/llm-adapter.ts
14
14
  function createLLMAdapter(session) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerSubroutine
3
- } from "./chunk-IN55WRFB.js";
3
+ } from "./chunk-3UW6GWYQ.js";
4
4
 
5
5
  // src/tags/subroutine.ts
6
6
  function executeSubroutine(session, element) {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-HRHAMPOB.js";
4
4
  import {
5
5
  executeSubroutine
6
- } from "./chunk-WX7VHQYL.js";
6
+ } from "./chunk-NKA6ZJDV.js";
7
7
  import {
8
8
  CustomLLMProvider,
9
9
  OllamaProvider,
@@ -28,7 +28,7 @@ import {
28
28
  substituteVariables,
29
29
  throwException,
30
30
  unsetExceptionBoundary
31
- } from "./chunk-IN55WRFB.js";
31
+ } from "./chunk-3UW6GWYQ.js";
32
32
 
33
33
  // src/tags/parameters.ts
34
34
  async function executeParameters(session, element) {
@@ -284,7 +284,7 @@ async function executeCall(session, element) {
284
284
  }
285
285
  }
286
286
  async function registerExtendChain(session, subroutine, currentName) {
287
- const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-RBTBNR2T.js");
287
+ const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-WJU6SDRC.js");
288
288
  const extendsAttr = subroutine.attributes.extends;
289
289
  let parentName;
290
290
  if (extendsAttr) {
@@ -474,12 +474,12 @@ async function executeIf(session, element) {
474
474
  const condition = await evaluatePredicate(session, conditionElement);
475
475
  if (condition) {
476
476
  if (thenElement) {
477
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
477
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
478
478
  await integrateChildren2(session, thenElement);
479
479
  }
480
480
  } else {
481
481
  if (elseElement) {
482
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
482
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
483
483
  await integrateChildren2(session, elseElement);
484
484
  }
485
485
  }
@@ -492,7 +492,7 @@ async function evaluatePredicate(session, predicateElement) {
492
492
  return await evaluateCondition(session, predicateElement);
493
493
  }
494
494
  const outputLengthBefore = session.output.length;
495
- const { integrate: integrate2 } = await import("./interpreter-WVPCPGVL.js");
495
+ const { integrate: integrate2 } = await import("./interpreter-NPXTWPHN.js");
496
496
  await integrate2(session, predicateElement);
497
497
  const newOutputChunks = session.output.slice(outputLengthBefore);
498
498
  const result = newOutputChunks.join("").trim();
@@ -515,11 +515,11 @@ async function evaluateCondition(session, condElement) {
515
515
  }
516
516
  const outputLengthBefore = session.output.length;
517
517
  const args = [];
518
- const { integrate: integrate2 } = await import("./interpreter-WVPCPGVL.js");
518
+ const { integrate: integrate2 } = await import("./interpreter-NPXTWPHN.js");
519
519
  for (const child of condElement.children) {
520
520
  if (child.tag.toLowerCase() === "arg") {
521
521
  const argOutputStart = session.output.length;
522
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
522
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
523
523
  await integrateChildren2(session, child);
524
524
  const newChunks = session.output.slice(argOutputStart);
525
525
  const argValue = newChunks.join("");
@@ -735,6 +735,7 @@ async function executeLLM(session, element) {
735
735
  const executeMode = element.attributes.execute === "true";
736
736
  const temperature = parseFloat(element.attributes.temperature || "1.0");
737
737
  const maxTokens = parseInt(element.attributes.maxTokens || "4096", 10);
738
+ const showMode = element.attributes.show || "all";
738
739
  let userPrompt = "";
739
740
  if (element.children.length > 0) {
740
741
  const beforeOutput = session.output.length;
@@ -784,9 +785,26 @@ async function executeLLM(session, element) {
784
785
  let systemPrompt = "";
785
786
  let currentUserPrompt = userPrompt;
786
787
  if (!noExtra) {
787
- const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-MRU57VMJ.js");
788
+ const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-AZIX6ILU.js");
788
789
  const allSubroutines = getAvailableSubroutines2(session);
789
- const subroutines = allSubroutines.filter((sub) => {
790
+ let boundaryFilteredSubroutines = allSubroutines;
791
+ if (showMode === "boundary") {
792
+ const currentBoundary = session.subBoundary;
793
+ if (session.debug) {
794
+ console.error(`[LLM] Current boundary: ${currentBoundary}`);
795
+ console.error(
796
+ `[LLM] All subroutines before boundary filter:`,
797
+ allSubroutines.map((s) => ({ name: s.name, boundary: s.boundary }))
798
+ );
799
+ }
800
+ boundaryFilteredSubroutines = allSubroutines.filter((sub) => {
801
+ return sub.boundary >= currentBoundary;
802
+ });
803
+ if (session.debug && allSubroutines.length !== boundaryFilteredSubroutines.length) {
804
+ console.error(`[LLM] Filtered to boundary ${currentBoundary}: ${boundaryFilteredSubroutines.length}/${allSubroutines.length} subroutines visible`);
805
+ }
806
+ }
807
+ const subroutines = boundaryFilteredSubroutines.filter((sub) => {
790
808
  const hideMeta = sub.meta?.["hide-from-llm"];
791
809
  return hideMeta !== "true" && hideMeta !== true;
792
810
  });
@@ -796,7 +814,7 @@ async function executeLLM(session, element) {
796
814
  subroutines.map((s) => ({ name: s.name, description: s.description, parameters: s.parameters }))
797
815
  );
798
816
  if (allSubroutines.length !== subroutines.length) {
799
- console.error(`[LLM] Filtered out ${allSubroutines.length - subroutines.length} subroutine(s) with hide-from-llm metadata`);
817
+ console.error(`[LLM] Filtered out ${allSubroutines.length - subroutines.length} subroutine(s) (boundary + hide-from-llm)`);
800
818
  }
801
819
  }
802
820
  if (hasExistingDialog && (contextVar || saveDialog)) {
@@ -963,7 +981,7 @@ ${result}
963
981
  const parser = new DiracParser();
964
982
  let dynamicAST = parser.parse(diracCode);
965
983
  if (validateTags) {
966
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-BTBNFPJD.js");
984
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-PEBTT5HJ.js");
967
985
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
968
986
  let retryCount = 0;
969
987
  while (!validation.valid && retryCount < maxRetries) {
@@ -1574,7 +1592,7 @@ async function getBestTagMatch(candidate, allowed) {
1574
1592
  return { tag: allowed[bestIdx], score: bestScore };
1575
1593
  }
1576
1594
  async function executeTagCheck(session, element) {
1577
- const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-MRU57VMJ.js");
1595
+ const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-AZIX6ILU.js");
1578
1596
  const subroutines = getAvailableSubroutines2(session);
1579
1597
  const allowed = new Set(subroutines.map((s) => s.name));
1580
1598
  console.error("[tag-check] Allowed subroutines:", Array.from(allowed));
@@ -1667,7 +1685,7 @@ async function executeTagCheck(session, element) {
1667
1685
  const executeTag = correctedTag || tagName;
1668
1686
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1669
1687
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1670
- const { integrate: integrate2 } = await import("./interpreter-WVPCPGVL.js");
1688
+ const { integrate: integrate2 } = await import("./interpreter-NPXTWPHN.js");
1671
1689
  await integrate2(session, elementToExecute);
1672
1690
  }
1673
1691
  }
@@ -1676,7 +1694,7 @@ async function executeTagCheck(session, element) {
1676
1694
  // src/tags/throw.ts
1677
1695
  async function executeThrow(session, element) {
1678
1696
  const exceptionName = element.attributes?.name || "exception";
1679
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
1697
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
1680
1698
  const exceptionDom = {
1681
1699
  tag: "exception-content",
1682
1700
  attributes: { name: exceptionName },
@@ -1689,7 +1707,7 @@ async function executeThrow(session, element) {
1689
1707
  // src/tags/try.ts
1690
1708
  async function executeTry(session, element) {
1691
1709
  setExceptionBoundary(session);
1692
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
1710
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
1693
1711
  await integrateChildren2(session, element);
1694
1712
  unsetExceptionBoundary(session);
1695
1713
  }
@@ -1699,7 +1717,7 @@ async function executeCatch(session, element) {
1699
1717
  const exceptionName = element.attributes?.name || "exception";
1700
1718
  const caughtCount = lookupException(session, exceptionName);
1701
1719
  if (caughtCount > 0) {
1702
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
1720
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
1703
1721
  await integrateChildren2(session, element);
1704
1722
  }
1705
1723
  flushCurrentException(session);
@@ -1708,7 +1726,7 @@ async function executeCatch(session, element) {
1708
1726
  // src/tags/exception.ts
1709
1727
  async function executeException(session, element) {
1710
1728
  const exceptions = getCurrentExceptions(session);
1711
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WVPCPGVL.js");
1729
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-NPXTWPHN.js");
1712
1730
  for (const exceptionDom of exceptions) {
1713
1731
  await integrateChildren2(session, exceptionDom);
1714
1732
  }
@@ -2176,7 +2194,7 @@ async function executeLoadContext(session, element) {
2176
2194
  query = element.text.trim();
2177
2195
  }
2178
2196
  if (!query && element.children.length > 0) {
2179
- const { integrate: integrate2 } = await import("./interpreter-WVPCPGVL.js");
2197
+ const { integrate: integrate2 } = await import("./interpreter-NPXTWPHN.js");
2180
2198
  const beforeOutput = session.output.length;
2181
2199
  for (const child of element.children) {
2182
2200
  await integrate2(session, child);
@@ -2245,7 +2263,7 @@ async function executeLoadContext(session, element) {
2245
2263
  parameters: s.parameters.map((p) => p.name),
2246
2264
  filePath: s.filePath
2247
2265
  }));
2248
- const { setVariable: setVariable2 } = await import("./session-MRU57VMJ.js");
2266
+ const { setVariable: setVariable2 } = await import("./session-AZIX6ILU.js");
2249
2267
  setVariable2(session, outputVar, JSON.stringify(summary, null, 2), false);
2250
2268
  }
2251
2269
  }
@@ -2429,7 +2447,7 @@ async function executeForeach(session, element) {
2429
2447
  const parser2 = new DiracParser2();
2430
2448
  try {
2431
2449
  const fromElement = parser2.parse(fromAttr);
2432
- const { integrate: integrate2 } = await import("./interpreter-WVPCPGVL.js");
2450
+ const { integrate: integrate2 } = await import("./interpreter-NPXTWPHN.js");
2433
2451
  await integrate2(session, fromElement);
2434
2452
  } catch (e) {
2435
2453
  session.output = savedOutput;
@@ -2684,6 +2702,206 @@ async function readLineFromFile(path4) {
2684
2702
  return result.value;
2685
2703
  }
2686
2704
 
2705
+ // src/tags/cron.ts
2706
+ import cron from "node-cron";
2707
+ var cronJobs = /* @__PURE__ */ new Map();
2708
+ async function executeCron(session, element) {
2709
+ const timeAttr = element.attributes.time;
2710
+ const name = element.attributes.name || `cron-${Date.now()}`;
2711
+ if (!timeAttr) {
2712
+ throw new Error("<cron> requires time attribute (cron expression)");
2713
+ }
2714
+ const cronExpression = substituteAttribute(session, timeAttr);
2715
+ if (!cron.validate(cronExpression)) {
2716
+ throw new Error(`Invalid cron expression: ${cronExpression}
2717
+ Format: minute hour day month weekday
2718
+ Example: "0 9 * * *" (daily at 9 AM)`);
2719
+ }
2720
+ if (cronJobs.has(name)) {
2721
+ const existing = cronJobs.get(name);
2722
+ existing.task.stop();
2723
+ console.log(`[cron] Stopped existing job: ${name}`);
2724
+ }
2725
+ console.log(`[cron] Starting job "${name}" (${cronExpression})`);
2726
+ let isRunning = false;
2727
+ const task = cron.schedule(cronExpression, async () => {
2728
+ await executeJob(session, element, name, () => isRunning, (value) => {
2729
+ isRunning = value;
2730
+ });
2731
+ }, {
2732
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
2733
+ // Use system timezone
2734
+ });
2735
+ cronJobs.set(name, {
2736
+ name,
2737
+ task,
2738
+ cronExpression,
2739
+ isRunning: false
2740
+ });
2741
+ }
2742
+ async function executeJob(session, element, name, getIsRunning, setIsRunning) {
2743
+ if (getIsRunning()) {
2744
+ console.log(`[cron] Skipping job "${name}" - previous execution still running`);
2745
+ return;
2746
+ }
2747
+ setIsRunning(true);
2748
+ console.log(`[cron] Executing job: ${name}`);
2749
+ try {
2750
+ session.output = [];
2751
+ await integrateChildren(session, element);
2752
+ if (session.output.length > 0) {
2753
+ console.log(session.output.join(""));
2754
+ }
2755
+ } catch (error) {
2756
+ console.error(`[cron] Job "${name}" failed:`, error.message);
2757
+ } finally {
2758
+ setIsRunning(false);
2759
+ }
2760
+ }
2761
+ function stopCronJob(name) {
2762
+ const job = cronJobs.get(name);
2763
+ if (!job) {
2764
+ return false;
2765
+ }
2766
+ job.task.stop();
2767
+ cronJobs.delete(name);
2768
+ console.log(`[cron] Stopped job: ${name}`);
2769
+ return true;
2770
+ }
2771
+ function stopAllCronJobs() {
2772
+ for (const [name, job] of cronJobs) {
2773
+ job.task.stop();
2774
+ console.log(`[cron] Stopped job: ${name}`);
2775
+ }
2776
+ cronJobs.clear();
2777
+ }
2778
+ function listCronJobs() {
2779
+ return Array.from(cronJobs.values()).map((job) => ({
2780
+ name: job.name,
2781
+ cronExpression: job.cronExpression,
2782
+ isRunning: job.isRunning
2783
+ }));
2784
+ }
2785
+
2786
+ // src/tags/run-at.ts
2787
+ var scheduledRuns = /* @__PURE__ */ new Map();
2788
+ async function executeRunAt(session, element) {
2789
+ const timeAttr = element.attributes.time;
2790
+ const name = element.attributes.name || `run-${Date.now()}`;
2791
+ if (!timeAttr) {
2792
+ throw new Error("<run-at> requires time attribute");
2793
+ }
2794
+ const timeStr = substituteAttribute(session, timeAttr);
2795
+ const targetTime = parseTimeExpression(timeStr);
2796
+ if (isNaN(targetTime.getTime())) {
2797
+ throw new Error(`Invalid time expression: ${timeStr}`);
2798
+ }
2799
+ const now = /* @__PURE__ */ new Date();
2800
+ const delayMs = targetTime.getTime() - now.getTime();
2801
+ if (delayMs < 0) {
2802
+ throw new Error(`Time is in the past: ${targetTime.toISOString()} (current: ${now.toISOString()})`);
2803
+ }
2804
+ if (scheduledRuns.has(name)) {
2805
+ const existing = scheduledRuns.get(name);
2806
+ clearTimeout(existing.timeoutId);
2807
+ console.log(`[run-at] Cancelled existing run: ${name}`);
2808
+ }
2809
+ console.log(`[run-at] Scheduled "${name}" for ${targetTime.toLocaleString()} (in ${formatDuration(delayMs)})`);
2810
+ const timeoutId = setTimeout(async () => {
2811
+ await executeScheduledRun(session, element, name);
2812
+ scheduledRuns.delete(name);
2813
+ }, delayMs);
2814
+ scheduledRuns.set(name, {
2815
+ name,
2816
+ timeoutId,
2817
+ scheduledTime: targetTime,
2818
+ isRunning: false
2819
+ });
2820
+ }
2821
+ async function executeScheduledRun(session, element, name) {
2822
+ const run = scheduledRuns.get(name);
2823
+ if (!run) return;
2824
+ run.isRunning = true;
2825
+ console.log(`[run-at] Executing: ${name}`);
2826
+ try {
2827
+ session.output = [];
2828
+ await integrateChildren(session, element);
2829
+ if (session.output.length > 0) {
2830
+ console.log(session.output.join(""));
2831
+ }
2832
+ } catch (error) {
2833
+ console.error(`[run-at] Run "${name}" failed:`, error.message);
2834
+ } finally {
2835
+ run.isRunning = false;
2836
+ }
2837
+ }
2838
+ function parseTimeExpression(expr) {
2839
+ expr = expr.trim();
2840
+ const relativeMatch = expr.match(/^\+(\d+)(s|m|h|d)?$/);
2841
+ if (relativeMatch) {
2842
+ const value = parseInt(relativeMatch[1], 10);
2843
+ const unit = relativeMatch[2] || "s";
2844
+ const now = Date.now();
2845
+ let offsetMs;
2846
+ switch (unit) {
2847
+ case "s":
2848
+ offsetMs = value * 1e3;
2849
+ break;
2850
+ case "m":
2851
+ offsetMs = value * 60 * 1e3;
2852
+ break;
2853
+ case "h":
2854
+ offsetMs = value * 60 * 60 * 1e3;
2855
+ break;
2856
+ case "d":
2857
+ offsetMs = value * 24 * 60 * 60 * 1e3;
2858
+ break;
2859
+ default:
2860
+ offsetMs = value * 1e3;
2861
+ }
2862
+ return new Date(now + offsetMs);
2863
+ }
2864
+ if (/^\d+$/.test(expr)) {
2865
+ const timestamp = parseInt(expr, 10);
2866
+ return new Date(timestamp);
2867
+ }
2868
+ return new Date(expr);
2869
+ }
2870
+ function formatDuration(ms) {
2871
+ const seconds = Math.floor(ms / 1e3);
2872
+ const minutes = Math.floor(seconds / 60);
2873
+ const hours = Math.floor(minutes / 60);
2874
+ const days = Math.floor(hours / 24);
2875
+ if (days > 0) return `${days}d ${hours % 24}h`;
2876
+ if (hours > 0) return `${hours}h ${minutes % 60}m`;
2877
+ if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
2878
+ return `${seconds}s`;
2879
+ }
2880
+ function cancelScheduledRun(name) {
2881
+ const run = scheduledRuns.get(name);
2882
+ if (!run) {
2883
+ return false;
2884
+ }
2885
+ clearTimeout(run.timeoutId);
2886
+ scheduledRuns.delete(name);
2887
+ console.log(`[run-at] Cancelled: ${name}`);
2888
+ return true;
2889
+ }
2890
+ function cancelAllScheduledRuns() {
2891
+ for (const [name, run] of scheduledRuns) {
2892
+ clearTimeout(run.timeoutId);
2893
+ console.log(`[run-at] Cancelled: ${name}`);
2894
+ }
2895
+ scheduledRuns.clear();
2896
+ }
2897
+ function listScheduledRuns() {
2898
+ return Array.from(scheduledRuns.values()).map((run) => ({
2899
+ name: run.name,
2900
+ scheduledTime: run.scheduledTime,
2901
+ isRunning: run.isRunning
2902
+ }));
2903
+ }
2904
+
2687
2905
  // src/runtime/interpreter.ts
2688
2906
  async function integrate(session, element) {
2689
2907
  if (session.limits.currentDepth >= session.limits.maxDepth) {
@@ -2806,6 +3024,12 @@ async function integrate(session, element) {
2806
3024
  case "schedule":
2807
3025
  await executeSchedule(session, element);
2808
3026
  break;
3027
+ case "cron":
3028
+ await executeCron(session, element);
3029
+ break;
3030
+ case "run-at":
3031
+ await executeRunAt(session, element);
3032
+ break;
2809
3033
  case "require_module":
2810
3034
  await executeRequireModule(session, element);
2811
3035
  break;
@@ -2919,6 +3143,14 @@ export {
2919
3143
  stopScheduledTask,
2920
3144
  stopAllScheduledTasks,
2921
3145
  listScheduledTasks,
3146
+ executeCron,
3147
+ stopCronJob,
3148
+ stopAllCronJobs,
3149
+ listCronJobs,
3150
+ executeRunAt,
3151
+ cancelScheduledRun,
3152
+ cancelAllScheduledRuns,
3153
+ listScheduledRuns,
2922
3154
  integrate,
2923
3155
  integrateChildren
2924
3156
  };
package/dist/cli.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  execute
7
- } from "./chunk-5FKZ3N7C.js";
8
- import "./chunk-WQ2KRQAR.js";
7
+ } from "./chunk-BMKPKK7M.js";
8
+ import "./chunk-ZAA6R2TC.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-WX7VHQYL.js";
11
- import "./chunk-IN55WRFB.js";
10
+ import "./chunk-NKA6ZJDV.js";
11
+ import "./chunk-3UW6GWYQ.js";
12
12
 
13
13
  // src/cli.ts
14
14
  import "dotenv/config";
@@ -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.57",
19
+ version: "0.1.60",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
@@ -46,16 +46,19 @@ var package_default = {
46
46
  license: "MIT",
47
47
  dependencies: {
48
48
  "@anthropic-ai/sdk": "^0.30.1",
49
+ "dirac-lang": "^0.1.59",
49
50
  "dirac-stdlib": "^0.1.0",
50
51
  dotenv: "^17.2.3",
51
52
  "fast-xml-parser": "^4.3.5",
52
53
  "js-yaml": "^4.1.1",
53
54
  mongodb: "^7.0.0",
55
+ "node-cron": "^4.2.1",
54
56
  openai: "^6.16.0"
55
57
  },
56
58
  devDependencies: {
57
59
  "@types/js-yaml": "^4.0.9",
58
60
  "@types/node": "^20.11.0",
61
+ "@types/node-cron": "^3.0.11",
59
62
  tsup: "^8.0.1",
60
63
  tsx: "^4.7.0",
61
64
  typescript: "^5.3.3",
@@ -96,7 +99,7 @@ async function main() {
96
99
  process.exit(0);
97
100
  }
98
101
  if (args[0] === "shell") {
99
- const { DiracShell } = await import("./shell-QA7NY73L.js");
102
+ const { DiracShell } = await import("./shell-WFLXZW3I.js");
100
103
  const shellConfig = { debug: false };
101
104
  for (let i = 1; i < args.length; i++) {
102
105
  const arg = args[i];
@@ -0,0 +1,15 @@
1
+ import {
2
+ executeCron,
3
+ listCronJobs,
4
+ stopAllCronJobs,
5
+ stopCronJob
6
+ } from "./chunk-ZAA6R2TC.js";
7
+ import "./chunk-HRHAMPOB.js";
8
+ import "./chunk-NKA6ZJDV.js";
9
+ import "./chunk-3UW6GWYQ.js";
10
+ export {
11
+ executeCron,
12
+ listCronJobs,
13
+ stopAllCronJobs,
14
+ stopCronJob
15
+ };
package/dist/index.js CHANGED
@@ -2,19 +2,19 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-5FKZ3N7C.js";
5
+ } from "./chunk-BMKPKK7M.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-WQ2KRQAR.js";
8
+ } from "./chunk-ZAA6R2TC.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
12
- import "./chunk-WX7VHQYL.js";
12
+ import "./chunk-NKA6ZJDV.js";
13
13
  import {
14
14
  createSession,
15
15
  getAvailableSubroutines,
16
16
  getOutput
17
- } from "./chunk-IN55WRFB.js";
17
+ } from "./chunk-3UW6GWYQ.js";
18
18
  export {
19
19
  DiracParser,
20
20
  createLLMAdapter,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-WQ2KRQAR.js";
4
+ } from "./chunk-ZAA6R2TC.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
- import "./chunk-WX7VHQYL.js";
7
- import "./chunk-IN55WRFB.js";
6
+ import "./chunk-NKA6ZJDV.js";
7
+ import "./chunk-3UW6GWYQ.js";
8
8
  export {
9
9
  integrate,
10
10
  integrateChildren
@@ -0,0 +1,15 @@
1
+ import {
2
+ cancelAllScheduledRuns,
3
+ cancelScheduledRun,
4
+ executeRunAt,
5
+ listScheduledRuns
6
+ } from "./chunk-ZAA6R2TC.js";
7
+ import "./chunk-HRHAMPOB.js";
8
+ import "./chunk-NKA6ZJDV.js";
9
+ import "./chunk-3UW6GWYQ.js";
10
+ export {
11
+ cancelAllScheduledRuns,
12
+ cancelScheduledRun,
13
+ executeRunAt,
14
+ listScheduledRuns
15
+ };
@@ -3,10 +3,10 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-WQ2KRQAR.js";
6
+ } from "./chunk-ZAA6R2TC.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-WX7VHQYL.js";
9
- import "./chunk-IN55WRFB.js";
8
+ import "./chunk-NKA6ZJDV.js";
9
+ import "./chunk-3UW6GWYQ.js";
10
10
  export {
11
11
  executeSchedule,
12
12
  listScheduledTasks,
@@ -26,7 +26,7 @@ import {
26
26
  substituteVariables,
27
27
  throwException,
28
28
  unsetExceptionBoundary
29
- } from "./chunk-IN55WRFB.js";
29
+ } from "./chunk-3UW6GWYQ.js";
30
30
  export {
31
31
  cleanSubroutinesToBoundary,
32
32
  cleanToBoundary,
@@ -4,14 +4,14 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  integrate
7
- } from "./chunk-WQ2KRQAR.js";
7
+ } from "./chunk-ZAA6R2TC.js";
8
8
  import {
9
9
  DiracParser
10
10
  } from "./chunk-HRHAMPOB.js";
11
- import "./chunk-WX7VHQYL.js";
11
+ import "./chunk-NKA6ZJDV.js";
12
12
  import {
13
13
  createSession
14
- } from "./chunk-IN55WRFB.js";
14
+ } from "./chunk-3UW6GWYQ.js";
15
15
 
16
16
  // src/shell.ts
17
17
  import * as readline from "readline";
@@ -150,7 +150,7 @@ var DiracShell = class {
150
150
  });
151
151
  this.rl.on("close", () => {
152
152
  this.saveHistory();
153
- import("./schedule-VYFEIUQE.js").then(({ stopAllScheduledTasks }) => {
153
+ import("./schedule-QZ5U3YBS.js").then(({ stopAllScheduledTasks }) => {
154
154
  stopAllScheduledTasks();
155
155
  console.log("\nGoodbye!");
156
156
  process.exit(0);
@@ -291,6 +291,12 @@ Commands:
291
291
  :tasks List all scheduled tasks
292
292
  :stop <name> Stop a scheduled task
293
293
  :stopall Stop all scheduled tasks
294
+ :crons List all cron jobs
295
+ :stopcron <name> Stop a cron job
296
+ :stopallcrons Stop all cron jobs
297
+ :scheduled List all scheduled runs (run-at)
298
+ :cancel <name> Cancel a scheduled run
299
+ :cancelall Cancel all scheduled runs
294
300
  :exit Exit shell
295
301
 
296
302
  Syntax:
@@ -471,7 +477,7 @@ Examples:
471
477
  break;
472
478
  case "tasks":
473
479
  try {
474
- const { listScheduledTasks } = await import("./schedule-VYFEIUQE.js");
480
+ const { listScheduledTasks } = await import("./schedule-QZ5U3YBS.js");
475
481
  const tasks = listScheduledTasks();
476
482
  if (tasks.length === 0) {
477
483
  console.log("No scheduled tasks running.");
@@ -490,7 +496,7 @@ Examples:
490
496
  console.log("Usage: :stop <task-name>");
491
497
  } else {
492
498
  try {
493
- const { stopScheduledTask } = await import("./schedule-VYFEIUQE.js");
499
+ const { stopScheduledTask } = await import("./schedule-QZ5U3YBS.js");
494
500
  const taskName = args[0];
495
501
  const stopped = stopScheduledTask(taskName);
496
502
  if (stopped) {
@@ -505,13 +511,101 @@ Examples:
505
511
  break;
506
512
  case "stopall":
507
513
  try {
508
- const { stopAllScheduledTasks } = await import("./schedule-VYFEIUQE.js");
514
+ const { stopAllScheduledTasks } = await import("./schedule-QZ5U3YBS.js");
509
515
  stopAllScheduledTasks();
510
516
  console.log("All scheduled tasks stopped.");
511
517
  } catch (error) {
512
518
  console.error("Error stopping tasks:", error instanceof Error ? error.message : String(error));
513
519
  }
514
520
  break;
521
+ case "crons":
522
+ try {
523
+ const { listCronJobs } = await import("./cron-BQIWLGQY.js");
524
+ const jobs = listCronJobs();
525
+ if (jobs.length === 0) {
526
+ console.log("No cron jobs running.");
527
+ } else {
528
+ console.log("\nCron Jobs:");
529
+ for (const job of jobs) {
530
+ const status = job.isRunning ? "(running)" : "";
531
+ console.log(` - ${job.name}: ${job.cronExpression} ${status}`);
532
+ }
533
+ }
534
+ } catch (error) {
535
+ console.error("Error listing cron jobs:", error instanceof Error ? error.message : String(error));
536
+ }
537
+ break;
538
+ case "stopcron":
539
+ if (args.length === 0) {
540
+ console.log("Usage: :stopcron <job-name>");
541
+ } else {
542
+ try {
543
+ const { stopCronJob } = await import("./cron-BQIWLGQY.js");
544
+ const jobName = args[0];
545
+ const stopped = stopCronJob(jobName);
546
+ if (stopped) {
547
+ console.log(`Stopped cron job: ${jobName}`);
548
+ } else {
549
+ console.log(`Cron job not found: ${jobName}`);
550
+ }
551
+ } catch (error) {
552
+ console.error("Error stopping cron job:", error instanceof Error ? error.message : String(error));
553
+ }
554
+ }
555
+ break;
556
+ case "stopallcrons":
557
+ try {
558
+ const { stopAllCronJobs } = await import("./cron-BQIWLGQY.js");
559
+ stopAllCronJobs();
560
+ console.log("All cron jobs stopped.");
561
+ } catch (error) {
562
+ console.error("Error stopping cron jobs:", error instanceof Error ? error.message : String(error));
563
+ }
564
+ break;
565
+ case "scheduled":
566
+ try {
567
+ const { listScheduledRuns } = await import("./run-at-KDJYTEOD.js");
568
+ const runs = listScheduledRuns();
569
+ if (runs.length === 0) {
570
+ console.log("No scheduled runs pending.");
571
+ } else {
572
+ console.log("\nScheduled Runs:");
573
+ for (const run of runs) {
574
+ const status = run.isRunning ? "(running)" : "";
575
+ console.log(` - ${run.name}: ${run.scheduledTime.toLocaleString()} ${status}`);
576
+ }
577
+ }
578
+ } catch (error) {
579
+ console.error("Error listing scheduled runs:", error instanceof Error ? error.message : String(error));
580
+ }
581
+ break;
582
+ case "cancel":
583
+ if (args.length === 0) {
584
+ console.log("Usage: :cancel <run-name>");
585
+ } else {
586
+ try {
587
+ const { cancelScheduledRun } = await import("./run-at-KDJYTEOD.js");
588
+ const runName = args[0];
589
+ const cancelled = cancelScheduledRun(runName);
590
+ if (cancelled) {
591
+ console.log(`Cancelled scheduled run: ${runName}`);
592
+ } else {
593
+ console.log(`Scheduled run not found: ${runName}`);
594
+ }
595
+ } catch (error) {
596
+ console.error("Error cancelling run:", error instanceof Error ? error.message : String(error));
597
+ }
598
+ }
599
+ break;
600
+ case "cancelall":
601
+ try {
602
+ const { cancelAllScheduledRuns } = await import("./run-at-KDJYTEOD.js");
603
+ cancelAllScheduledRuns();
604
+ console.log("All scheduled runs cancelled.");
605
+ } catch (error) {
606
+ console.error("Error cancelling runs:", error instanceof Error ? error.message : String(error));
607
+ }
608
+ break;
515
609
  case "exit":
516
610
  case "quit":
517
611
  this.rl.close();
@@ -542,6 +636,7 @@ Examples:
542
636
  }
543
637
  /**
544
638
  * Execute a Unix shell command
639
+ * If command is not found, fallback to treating it as an AI query
545
640
  */
546
641
  async executeShellCommand(command) {
547
642
  const trimmed = command.trim();
@@ -558,14 +653,29 @@ Examples:
558
653
  }
559
654
  const { spawn } = await import("child_process");
560
655
  this.rl.pause();
561
- return new Promise((resolve2) => {
656
+ return new Promise(async (resolve2) => {
562
657
  const shell = process.env.SHELL || "/bin/sh";
563
658
  const child = spawn(shell, ["-c", command], {
564
- stdio: "inherit",
659
+ stdio: ["inherit", "inherit", "pipe"],
565
660
  cwd: process.cwd()
566
661
  });
567
- child.on("close", () => {
662
+ let stderrData = "";
663
+ child.stderr?.on("data", (data) => {
664
+ stderrData += data.toString();
665
+ process.stderr.write(data);
666
+ });
667
+ child.on("close", async (code) => {
568
668
  this.rl.resume();
669
+ const commandNotFound = code === 127 || stderrData.includes("command not found");
670
+ if (commandNotFound) {
671
+ console.log(`\u{1F4A1} Command not found, trying as AI query...`);
672
+ if (this.config.debug) {
673
+ console.log(`[executing: |ai>${trimmed}]`);
674
+ }
675
+ const aiInput = `|ai>${trimmed}`;
676
+ this.inputBuffer = [aiInput];
677
+ await this.executeBuffer();
678
+ }
569
679
  resolve2();
570
680
  });
571
681
  child.on("error", (err) => {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  executeSubroutine
3
- } from "./chunk-WX7VHQYL.js";
4
- import "./chunk-IN55WRFB.js";
3
+ } from "./chunk-NKA6ZJDV.js";
4
+ import "./chunk-3UW6GWYQ.js";
5
5
  export {
6
6
  executeSubroutine
7
7
  };
@@ -49,7 +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
- const { getAvailableSubroutines } = await import("./session-MRU57VMJ.js");
52
+ const { getAvailableSubroutines } = await import("./session-AZIX6ILU.js");
53
53
  const subroutines = getAvailableSubroutines(session);
54
54
  const allowed = new Set(subroutines.map((s) => s.name));
55
55
  const tagName = element.tag;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-WQ2KRQAR.js";
3
+ } from "./chunk-ZAA6R2TC.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
7
- import "./chunk-WX7VHQYL.js";
7
+ import "./chunk-NKA6ZJDV.js";
8
8
  import {
9
9
  createSession,
10
10
  getOutput
11
- } from "./chunk-IN55WRFB.js";
11
+ } from "./chunk-3UW6GWYQ.js";
12
12
 
13
13
  // src/test-runner.ts
14
14
  import fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,16 +30,19 @@
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
32
  "@anthropic-ai/sdk": "^0.30.1",
33
+ "dirac-lang": "^0.1.59",
33
34
  "dirac-stdlib": "^0.1.0",
34
35
  "dotenv": "^17.2.3",
35
36
  "fast-xml-parser": "^4.3.5",
36
37
  "js-yaml": "^4.1.1",
37
38
  "mongodb": "^7.0.0",
39
+ "node-cron": "^4.2.1",
38
40
  "openai": "^6.16.0"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@types/js-yaml": "^4.0.9",
42
44
  "@types/node": "^20.11.0",
45
+ "@types/node-cron": "^3.0.11",
43
46
  "tsup": "^8.0.1",
44
47
  "tsx": "^4.7.0",
45
48
  "typescript": "^5.3.3",