dirac-lang 0.1.62 → 0.1.63

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-WPEAYK2Q.js";
6
- import "./chunk-BAO2WV34.js";
5
+ } from "./chunk-6GYEZ3Z4.js";
6
+ import "./chunk-ER6DSG7W.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-NKA6ZJDV.js";
9
9
  import "./chunk-3UW6GWYQ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-BAO2WV34.js";
3
+ } from "./chunk-ER6DSG7W.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -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-UFWRGTCM.js");
477
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
478
478
  await integrateChildren2(session, thenElement);
479
479
  }
480
480
  } else {
481
481
  if (elseElement) {
482
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UFWRGTCM.js");
482
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.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-UFWRGTCM.js");
495
+ const { integrate: integrate2 } = await import("./interpreter-P7ZMLP32.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-UFWRGTCM.js");
518
+ const { integrate: integrate2 } = await import("./interpreter-P7ZMLP32.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-UFWRGTCM.js");
522
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
523
523
  await integrateChildren2(session, child);
524
524
  const newChunks = session.output.slice(argOutputStart);
525
525
  const argValue = newChunks.join("");
@@ -583,6 +583,29 @@ import OpenAI from "openai";
583
583
  import * as fs2 from "fs";
584
584
  import * as path2 from "path";
585
585
  import * as os from "os";
586
+ function pruneDialogForLLM(dialogHistory, keepRecentCount = 20) {
587
+ if (dialogHistory.length <= keepRecentCount) {
588
+ return dialogHistory;
589
+ }
590
+ const firstSystemMsg = dialogHistory.find((m) => m.role === "system");
591
+ const lastSystemMsg = dialogHistory.slice().reverse().find((m) => m.role === "system");
592
+ const recentMessages = dialogHistory.slice(-keepRecentCount);
593
+ const prunedRecent = recentMessages.filter((msg) => {
594
+ if (msg.role !== "system") return true;
595
+ return msg === lastSystemMsg;
596
+ });
597
+ const result = [];
598
+ if (firstSystemMsg && !prunedRecent.includes(firstSystemMsg)) {
599
+ result.push(firstSystemMsg);
600
+ }
601
+ result.push(...prunedRecent);
602
+ if (lastSystemMsg && lastSystemMsg !== result[result.length - 1]) {
603
+ const filtered = result.filter((m) => m !== lastSystemMsg);
604
+ filtered.push(lastSystemMsg);
605
+ return filtered;
606
+ }
607
+ return result;
608
+ }
586
609
  function createLLMClient(provider, model) {
587
610
  const anthropicKey = process.env.ANTHROPIC_API_KEY;
588
611
  const openaiKey = process.env.OPENAI_API_KEY;
@@ -787,6 +810,10 @@ async function executeLLM(session, element) {
787
810
  if (!noExtra) {
788
811
  const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-AZIX6ILU.js");
789
812
  const allSubroutines = getAvailableSubroutines2(session);
813
+ if (session.debug) {
814
+ console.error(`[LLM] Total subroutines from session: ${allSubroutines.length}`);
815
+ console.error(`[LLM] Has existing dialog: ${hasExistingDialog}`);
816
+ }
790
817
  let boundaryFilteredSubroutines = allSubroutines;
791
818
  if (showMode === "boundary") {
792
819
  const currentBoundary = session.subBoundary;
@@ -794,11 +821,11 @@ async function executeLLM(session, element) {
794
821
  console.error(`[LLM] Current boundary: ${currentBoundary}`);
795
822
  console.error(
796
823
  `[LLM] All subroutines before boundary filter:`,
797
- allSubroutines.map((s) => ({ name: s.name, boundary: s.boundary }))
824
+ allSubroutines.slice(0, 5).map((s) => ({ name: s.name, boundary: s.boundary }))
798
825
  );
799
826
  }
800
827
  boundaryFilteredSubroutines = allSubroutines.filter((sub) => {
801
- return sub.boundary >= currentBoundary;
828
+ return sub.boundary <= currentBoundary;
802
829
  });
803
830
  if (session.debug && allSubroutines.length !== boundaryFilteredSubroutines.length) {
804
831
  console.error(`[LLM] Filtered to boundary ${currentBoundary}: ${boundaryFilteredSubroutines.length}/${allSubroutines.length} subroutines visible`);
@@ -809,6 +836,7 @@ async function executeLLM(session, element) {
809
836
  return hideMeta !== "true" && hideMeta !== true;
810
837
  });
811
838
  if (session.debug) {
839
+ console.error(`[LLM] After hide-from-llm filter: ${subroutines.length} subroutines`);
812
840
  console.error(
813
841
  "[LLM] Subroutines available at prompt composition:",
814
842
  subroutines.map((s) => ({ name: s.name, description: s.description, parameters: s.parameters }))
@@ -893,9 +921,10 @@ CRITICAL: When defining parameters:
893
921
  }
894
922
  }
895
923
  dialogHistory.push({ role: "user", content: currentUserPrompt });
924
+ const prunedDialogHistory = pruneDialogForLLM(dialogHistory, 20);
896
925
  if (session.debug) {
897
926
  console.error(`[LLM] Calling ${model}`);
898
- console.error(`[LLM] Dialog history length: ${dialogHistory.length} messages`);
927
+ console.error(`[LLM] Dialog history length: ${dialogHistory.length} messages (full), ${prunedDialogHistory.length} messages (pruned)`);
899
928
  console.error(`[LLM] Has existing dialog: ${hasExistingDialog}`);
900
929
  }
901
930
  try {
@@ -905,26 +934,26 @@ CRITICAL: When defining parameters:
905
934
  model,
906
935
  max_tokens: maxTokens,
907
936
  temperature,
908
- messages: dialogHistory
937
+ messages: prunedDialogHistory
909
938
  });
910
939
  result = response.choices[0]?.message?.content || "";
911
940
  } else if (isOllama) {
912
- const ollamaPrompt = dialogHistory.map((m) => `${m.role.charAt(0).toUpperCase() + m.role.slice(1)}: ${m.content}`).join("\n");
941
+ const ollamaPrompt = prunedDialogHistory.map((m) => `${m.role.charAt(0).toUpperCase() + m.role.slice(1)}: ${m.content}`).join("\n");
913
942
  result = await llmClient.complete(ollamaPrompt, {
914
943
  model,
915
944
  temperature,
916
945
  max_tokens: maxTokens
917
946
  });
918
947
  } else if (isCustom) {
919
- const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
948
+ const customPrompt = prunedDialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
920
949
  result = await llmClient.complete(customPrompt, {
921
950
  model,
922
951
  temperature,
923
952
  max_tokens: maxTokens,
924
- messages: dialogHistory
953
+ messages: prunedDialogHistory
925
954
  });
926
955
  } else {
927
- result = await callAnthropic(llmClient, model, maxTokens, temperature, dialogHistory);
956
+ result = await callAnthropic(llmClient, model, maxTokens, temperature, prunedDialogHistory);
928
957
  }
929
958
  if (session.debug) {
930
959
  console.error(`[LLM] Response length: ${result.length}`);
@@ -1686,7 +1715,7 @@ async function executeTagCheck(session, element) {
1686
1715
  const executeTag = correctedTag || tagName;
1687
1716
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1688
1717
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1689
- const { integrate: integrate2 } = await import("./interpreter-UFWRGTCM.js");
1718
+ const { integrate: integrate2 } = await import("./interpreter-P7ZMLP32.js");
1690
1719
  await integrate2(session, elementToExecute);
1691
1720
  }
1692
1721
  }
@@ -1695,7 +1724,7 @@ async function executeTagCheck(session, element) {
1695
1724
  // src/tags/throw.ts
1696
1725
  async function executeThrow(session, element) {
1697
1726
  const exceptionName = element.attributes?.name || "exception";
1698
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UFWRGTCM.js");
1727
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
1699
1728
  const exceptionDom = {
1700
1729
  tag: "exception-content",
1701
1730
  attributes: { name: exceptionName },
@@ -1708,7 +1737,7 @@ async function executeThrow(session, element) {
1708
1737
  // src/tags/try.ts
1709
1738
  async function executeTry(session, element) {
1710
1739
  setExceptionBoundary(session);
1711
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UFWRGTCM.js");
1740
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
1712
1741
  await integrateChildren2(session, element);
1713
1742
  unsetExceptionBoundary(session);
1714
1743
  }
@@ -1718,7 +1747,7 @@ async function executeCatch(session, element) {
1718
1747
  const exceptionName = element.attributes?.name || "exception";
1719
1748
  const caughtCount = lookupException(session, exceptionName);
1720
1749
  if (caughtCount > 0) {
1721
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UFWRGTCM.js");
1750
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
1722
1751
  await integrateChildren2(session, element);
1723
1752
  }
1724
1753
  flushCurrentException(session);
@@ -1727,7 +1756,7 @@ async function executeCatch(session, element) {
1727
1756
  // src/tags/exception.ts
1728
1757
  async function executeException(session, element) {
1729
1758
  const exceptions = getCurrentExceptions(session);
1730
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-UFWRGTCM.js");
1759
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-P7ZMLP32.js");
1731
1760
  for (const exceptionDom of exceptions) {
1732
1761
  await integrateChildren2(session, exceptionDom);
1733
1762
  }
@@ -2195,7 +2224,7 @@ async function executeLoadContext(session, element) {
2195
2224
  query = element.text.trim();
2196
2225
  }
2197
2226
  if (!query && element.children.length > 0) {
2198
- const { integrate: integrate2 } = await import("./interpreter-UFWRGTCM.js");
2227
+ const { integrate: integrate2 } = await import("./interpreter-P7ZMLP32.js");
2199
2228
  const beforeOutput = session.output.length;
2200
2229
  for (const child of element.children) {
2201
2230
  await integrate2(session, child);
@@ -2448,7 +2477,7 @@ async function executeForeach(session, element) {
2448
2477
  const parser2 = new DiracParser2();
2449
2478
  try {
2450
2479
  const fromElement = parser2.parse(fromAttr);
2451
- const { integrate: integrate2 } = await import("./interpreter-UFWRGTCM.js");
2480
+ const { integrate: integrate2 } = await import("./interpreter-P7ZMLP32.js");
2452
2481
  await integrate2(session, fromElement);
2453
2482
  } catch (e) {
2454
2483
  session.output = savedOutput;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-BAO2WV34.js";
3
+ } from "./chunk-ER6DSG7W.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  execute
7
- } from "./chunk-SVB7OJDA.js";
8
- import "./chunk-BAO2WV34.js";
7
+ } from "./chunk-ZN52C2TW.js";
8
+ import "./chunk-ER6DSG7W.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
10
  import "./chunk-NKA6ZJDV.js";
11
11
  import "./chunk-3UW6GWYQ.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.61",
19
+ version: "0.1.62",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
@@ -114,11 +114,11 @@ async function main() {
114
114
  if (args[0] === "agent") {
115
115
  const subcommand = args[1];
116
116
  if (subcommand === "daemon") {
117
- const { runAgentDaemon } = await import("./agent-3VQNLFHO.js");
117
+ const { runAgentDaemon } = await import("./agent-HAYADDBF.js");
118
118
  await runAgentDaemon();
119
119
  return;
120
120
  }
121
- const { AgentCLI } = await import("./agent-3VQNLFHO.js");
121
+ const { AgentCLI } = await import("./agent-HAYADDBF.js");
122
122
  const agent = new AgentCLI();
123
123
  switch (subcommand) {
124
124
  case "start":
@@ -145,8 +145,8 @@ async function main() {
145
145
  return;
146
146
  }
147
147
  if (args[0] === "shell") {
148
- const { DiracShell } = await import("./shell-KGS3I6WX.js");
149
- const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-BQH56RCK.js");
148
+ const { DiracShell } = await import("./shell-SN7XYIDA.js");
149
+ const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-GEISBLMU.js");
150
150
  const { SessionClient } = await import("./session-client-3VTC5MLO.js");
151
151
  const daemonMode = args.includes("--daemon") || args.includes("-d");
152
152
  const agentMode = args.includes("--agent") || args.includes("-a");
@@ -224,7 +224,7 @@ async function main() {
224
224
  return;
225
225
  }
226
226
  if (args[0] === "daemon") {
227
- const { SessionServer } = await import("./session-server-BQH56RCK.js");
227
+ const { SessionServer } = await import("./session-server-GEISBLMU.js");
228
228
  const server = new SessionServer();
229
229
  await server.start();
230
230
  console.log("Session daemon started");
@@ -3,7 +3,7 @@ import {
3
3
  listCronJobs,
4
4
  stopAllCronJobs,
5
5
  stopCronJob
6
- } from "./chunk-BAO2WV34.js";
6
+ } from "./chunk-ER6DSG7W.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-NKA6ZJDV.js";
9
9
  import "./chunk-3UW6GWYQ.js";
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-SVB7OJDA.js";
5
+ } from "./chunk-ZN52C2TW.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-BAO2WV34.js";
8
+ } from "./chunk-ER6DSG7W.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-BAO2WV34.js";
4
+ } from "./chunk-ER6DSG7W.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
6
  import "./chunk-NKA6ZJDV.js";
7
7
  import "./chunk-3UW6GWYQ.js";
@@ -3,7 +3,7 @@ import {
3
3
  cancelScheduledRun,
4
4
  executeRunAt,
5
5
  listScheduledRuns
6
- } from "./chunk-BAO2WV34.js";
6
+ } from "./chunk-ER6DSG7W.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-NKA6ZJDV.js";
9
9
  import "./chunk-3UW6GWYQ.js";
@@ -3,7 +3,7 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-BAO2WV34.js";
6
+ } from "./chunk-ER6DSG7W.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-NKA6ZJDV.js";
9
9
  import "./chunk-3UW6GWYQ.js";
@@ -2,8 +2,8 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-WPEAYK2Q.js";
6
- import "./chunk-BAO2WV34.js";
5
+ } from "./chunk-6GYEZ3Z4.js";
6
+ import "./chunk-ER6DSG7W.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
8
  import "./chunk-NKA6ZJDV.js";
9
9
  import "./chunk-3UW6GWYQ.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  integrate
7
- } from "./chunk-BAO2WV34.js";
7
+ } from "./chunk-ER6DSG7W.js";
8
8
  import {
9
9
  DiracParser
10
10
  } from "./chunk-HRHAMPOB.js";
@@ -175,7 +175,7 @@ var DiracShell = class {
175
175
  if (this.client) {
176
176
  this.client.disconnect();
177
177
  }
178
- import("./schedule-F7JHVWEV.js").then(({ stopAllScheduledTasks }) => {
178
+ import("./schedule-VKPK4DWF.js").then(({ stopAllScheduledTasks }) => {
179
179
  stopAllScheduledTasks();
180
180
  console.log("\nGoodbye!");
181
181
  process.exit(0);
@@ -541,7 +541,7 @@ Examples:
541
541
  break;
542
542
  case "tasks":
543
543
  try {
544
- const { listScheduledTasks } = await import("./schedule-F7JHVWEV.js");
544
+ const { listScheduledTasks } = await import("./schedule-VKPK4DWF.js");
545
545
  const tasks = listScheduledTasks();
546
546
  if (tasks.length === 0) {
547
547
  console.log("No scheduled tasks running.");
@@ -560,7 +560,7 @@ Examples:
560
560
  console.log("Usage: :stop <task-name>");
561
561
  } else {
562
562
  try {
563
- const { stopScheduledTask } = await import("./schedule-F7JHVWEV.js");
563
+ const { stopScheduledTask } = await import("./schedule-VKPK4DWF.js");
564
564
  const taskName = args[0];
565
565
  const stopped = stopScheduledTask(taskName);
566
566
  if (stopped) {
@@ -575,7 +575,7 @@ Examples:
575
575
  break;
576
576
  case "stopall":
577
577
  try {
578
- const { stopAllScheduledTasks } = await import("./schedule-F7JHVWEV.js");
578
+ const { stopAllScheduledTasks } = await import("./schedule-VKPK4DWF.js");
579
579
  stopAllScheduledTasks();
580
580
  console.log("All scheduled tasks stopped.");
581
581
  } catch (error) {
@@ -584,7 +584,7 @@ Examples:
584
584
  break;
585
585
  case "crons":
586
586
  try {
587
- const { listCronJobs } = await import("./cron-SUYXFAW7.js");
587
+ const { listCronJobs } = await import("./cron-JAWTZUOM.js");
588
588
  const jobs = listCronJobs();
589
589
  if (jobs.length === 0) {
590
590
  console.log("No cron jobs running.");
@@ -604,7 +604,7 @@ Examples:
604
604
  console.log("Usage: :stopcron <job-name>");
605
605
  } else {
606
606
  try {
607
- const { stopCronJob } = await import("./cron-SUYXFAW7.js");
607
+ const { stopCronJob } = await import("./cron-JAWTZUOM.js");
608
608
  const jobName = args[0];
609
609
  const stopped = stopCronJob(jobName);
610
610
  if (stopped) {
@@ -619,7 +619,7 @@ Examples:
619
619
  break;
620
620
  case "stopallcrons":
621
621
  try {
622
- const { stopAllCronJobs } = await import("./cron-SUYXFAW7.js");
622
+ const { stopAllCronJobs } = await import("./cron-JAWTZUOM.js");
623
623
  stopAllCronJobs();
624
624
  console.log("All cron jobs stopped.");
625
625
  } catch (error) {
@@ -628,7 +628,7 @@ Examples:
628
628
  break;
629
629
  case "scheduled":
630
630
  try {
631
- const { listScheduledRuns } = await import("./run-at-BBMPAVED.js");
631
+ const { listScheduledRuns } = await import("./run-at-BMPXOIW4.js");
632
632
  const runs = listScheduledRuns();
633
633
  if (runs.length === 0) {
634
634
  console.log("No scheduled runs pending.");
@@ -648,7 +648,7 @@ Examples:
648
648
  console.log("Usage: :cancel <run-name>");
649
649
  } else {
650
650
  try {
651
- const { cancelScheduledRun } = await import("./run-at-BBMPAVED.js");
651
+ const { cancelScheduledRun } = await import("./run-at-BMPXOIW4.js");
652
652
  const runName = args[0];
653
653
  const cancelled = cancelScheduledRun(runName);
654
654
  if (cancelled) {
@@ -663,7 +663,7 @@ Examples:
663
663
  break;
664
664
  case "cancelall":
665
665
  try {
666
- const { cancelAllScheduledRuns } = await import("./run-at-BBMPAVED.js");
666
+ const { cancelAllScheduledRuns } = await import("./run-at-BMPXOIW4.js");
667
667
  cancelAllScheduledRuns();
668
668
  console.log("All scheduled runs cancelled.");
669
669
  } catch (error) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-BAO2WV34.js";
3
+ } from "./chunk-ER6DSG7W.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.62",
3
+ "version": "0.1.63",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",