dirac-lang 0.1.89 → 0.1.91

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.
@@ -72,13 +72,24 @@ var CustomLLMClient = class {
72
72
  this.baseUrl = baseUrl;
73
73
  }
74
74
  async chat({ messages }) {
75
- const prompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
76
75
  const res = await fetch(`${this.baseUrl}/chat`, {
77
76
  method: "POST",
78
77
  headers: { "Content-Type": "application/json" },
79
- body: JSON.stringify({ message: prompt })
78
+ body: JSON.stringify({ messages })
80
79
  });
80
+ if (!res.ok) {
81
+ const text = await res.text();
82
+ throw new Error(`Custom LLM server error (${res.status}): ${text.substring(0, 200)}`);
83
+ }
84
+ const contentType = res.headers.get("content-type");
85
+ if (!contentType || !contentType.includes("application/json")) {
86
+ const text = await res.text();
87
+ throw new Error(`Custom LLM server returned non-JSON response (${contentType}): ${text.substring(0, 200)}`);
88
+ }
81
89
  const data = await res.json();
90
+ if (!data || typeof data.response !== "string") {
91
+ throw new Error(`Custom LLM server returned invalid response structure: ${JSON.stringify(data)}`);
92
+ }
82
93
  return data.response;
83
94
  }
84
95
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-QGEYKDIA.js";
3
+ } from "./chunk-PKLOBITC.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-2VFQ2YBT.js";
11
+ } from "./chunk-PPH7KYKH.js";
12
12
 
13
13
  // src/utils/llm-adapter.ts
14
14
  function createLLMAdapter(session) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  emit,
6
6
  setVariable
7
- } from "./chunk-2VFQ2YBT.js";
7
+ } from "./chunk-PPH7KYKH.js";
8
8
 
9
9
  // src/runtime/subroutine-registry.ts
10
10
  import * as fs from "fs";
package/dist/cli.js CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- BraKetParser
4
- } from "./chunk-AJSYOXXZ.js";
5
2
  import {
6
3
  execute
7
- } from "./chunk-B5OYG2NX.js";
8
- import "./chunk-QGEYKDIA.js";
9
- import "./chunk-HJSHCEK4.js";
10
- import "./chunk-BGG2SULN.js";
4
+ } from "./chunk-R42DSFUB.js";
5
+ import {
6
+ BraKetParser
7
+ } from "./chunk-PKLOBITC.js";
8
+ import "./chunk-ECAW4X46.js";
9
+ import "./chunk-SLGJRZ3P.js";
11
10
  import "./chunk-HRHAMPOB.js";
12
- import "./chunk-2VFQ2YBT.js";
11
+ import "./chunk-PPH7KYKH.js";
13
12
 
14
13
  // src/cli.ts
15
14
  import "dotenv/config";
@@ -17,7 +16,7 @@ import "dotenv/config";
17
16
  // package.json
18
17
  var package_default = {
19
18
  name: "dirac-lang",
20
- version: "0.1.88",
19
+ version: "0.1.91",
21
20
  description: "LLM-Augmented Declarative Execution",
22
21
  type: "module",
23
22
  main: "dist/index.js",
@@ -151,7 +150,7 @@ async function main() {
151
150
  const args = process.argv.slice(2);
152
151
  const calledAs = process.argv[1];
153
152
  if (calledAs && calledAs.endsWith("/dish")) {
154
- const { DiracShell } = await import("./shell-5IR72NFQ.js");
153
+ const { DiracShell } = await import("./shell-U5L7KXSV.js");
155
154
  const shellConfig = loadShellConfig(args);
156
155
  const shell = new DiracShell(shellConfig);
157
156
  await shell.start();
@@ -200,11 +199,11 @@ async function main() {
200
199
  if (args[0] === "agent") {
201
200
  const subcommand = args[1];
202
201
  if (subcommand === "daemon") {
203
- const { runAgentDaemon } = await import("./agent-BWFKP5AW.js");
202
+ const { runAgentDaemon } = await import("./agent-OP5VWQN3.js");
204
203
  await runAgentDaemon();
205
204
  return;
206
205
  }
207
- const { AgentCLI } = await import("./agent-BWFKP5AW.js");
206
+ const { AgentCLI } = await import("./agent-OP5VWQN3.js");
208
207
  const agent = new AgentCLI();
209
208
  switch (subcommand) {
210
209
  case "start":
@@ -231,8 +230,8 @@ async function main() {
231
230
  return;
232
231
  }
233
232
  if (args[0] === "shell") {
234
- const { DiracShell } = await import("./shell-5IR72NFQ.js");
235
- const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-IAC5KFJC.js");
233
+ const { DiracShell } = await import("./shell-U5L7KXSV.js");
234
+ const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-6Z2THFHB.js");
236
235
  const { SessionClient } = await import("./session-client-3VTC5MLO.js");
237
236
  const daemonMode = args.includes("--daemon") || args.includes("-d");
238
237
  const agentMode = args.includes("--agent") || args.includes("-a");
@@ -278,7 +277,7 @@ async function main() {
278
277
  return;
279
278
  }
280
279
  if (args[0] === "daemon") {
281
- const { SessionServer } = await import("./session-server-IAC5KFJC.js");
280
+ const { SessionServer } = await import("./session-server-6Z2THFHB.js");
282
281
  const server = new SessionServer();
283
282
  await server.start();
284
283
  console.log("Session daemon started");
@@ -3,11 +3,11 @@ import {
3
3
  listCronJobs,
4
4
  stopAllCronJobs,
5
5
  stopCronJob
6
- } from "./chunk-QGEYKDIA.js";
7
- import "./chunk-HJSHCEK4.js";
8
- import "./chunk-BGG2SULN.js";
6
+ } from "./chunk-PKLOBITC.js";
7
+ import "./chunk-ECAW4X46.js";
8
+ import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-2VFQ2YBT.js";
10
+ import "./chunk-PPH7KYKH.js";
11
11
  export {
12
12
  executeCron,
13
13
  listCronJobs,
package/dist/index.js CHANGED
@@ -2,12 +2,12 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-B5OYG2NX.js";
5
+ } from "./chunk-R42DSFUB.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-QGEYKDIA.js";
9
- import "./chunk-HJSHCEK4.js";
10
- import "./chunk-BGG2SULN.js";
8
+ } from "./chunk-PKLOBITC.js";
9
+ import "./chunk-ECAW4X46.js";
10
+ import "./chunk-SLGJRZ3P.js";
11
11
  import {
12
12
  DiracParser
13
13
  } from "./chunk-HRHAMPOB.js";
@@ -15,7 +15,7 @@ import {
15
15
  createSession,
16
16
  getAvailableSubroutines,
17
17
  getOutput
18
- } from "./chunk-2VFQ2YBT.js";
18
+ } from "./chunk-PPH7KYKH.js";
19
19
  export {
20
20
  DiracParser,
21
21
  createLLMAdapter,
@@ -0,0 +1,12 @@
1
+ import {
2
+ integrate,
3
+ integrateChildren
4
+ } from "./chunk-PKLOBITC.js";
5
+ import "./chunk-ECAW4X46.js";
6
+ import "./chunk-SLGJRZ3P.js";
7
+ import "./chunk-HRHAMPOB.js";
8
+ import "./chunk-PPH7KYKH.js";
9
+ export {
10
+ integrate,
11
+ integrateChildren
12
+ };
@@ -3,11 +3,11 @@ import {
3
3
  cancelScheduledRun,
4
4
  executeRunAt,
5
5
  listScheduledRuns
6
- } from "./chunk-QGEYKDIA.js";
7
- import "./chunk-HJSHCEK4.js";
8
- import "./chunk-BGG2SULN.js";
6
+ } from "./chunk-PKLOBITC.js";
7
+ import "./chunk-ECAW4X46.js";
8
+ import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-2VFQ2YBT.js";
10
+ import "./chunk-PPH7KYKH.js";
11
11
  export {
12
12
  cancelAllScheduledRuns,
13
13
  cancelScheduledRun,
@@ -3,11 +3,11 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-QGEYKDIA.js";
7
- import "./chunk-HJSHCEK4.js";
8
- import "./chunk-BGG2SULN.js";
6
+ } from "./chunk-PKLOBITC.js";
7
+ import "./chunk-ECAW4X46.js";
8
+ import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-2VFQ2YBT.js";
10
+ import "./chunk-PPH7KYKH.js";
11
11
  export {
12
12
  executeSchedule,
13
13
  listScheduledTasks,
@@ -26,7 +26,7 @@ import {
26
26
  substituteVariables,
27
27
  throwException,
28
28
  unsetExceptionBoundary
29
- } from "./chunk-2VFQ2YBT.js";
29
+ } from "./chunk-PPH7KYKH.js";
30
30
  export {
31
31
  cleanSubroutinesToBoundary,
32
32
  cleanToBoundary,
@@ -2,12 +2,12 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-ZVWMNAEP.js";
6
- import "./chunk-QGEYKDIA.js";
7
- import "./chunk-HJSHCEK4.js";
8
- import "./chunk-BGG2SULN.js";
5
+ } from "./chunk-B7KLVI42.js";
6
+ import "./chunk-PKLOBITC.js";
7
+ import "./chunk-ECAW4X46.js";
8
+ import "./chunk-SLGJRZ3P.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-2VFQ2YBT.js";
10
+ import "./chunk-PPH7KYKH.js";
11
11
  export {
12
12
  SessionServer,
13
13
  getSocketPath,
@@ -1,18 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- BraKetParser
4
- } from "./chunk-AJSYOXXZ.js";
5
- import {
3
+ BraKetParser,
6
4
  integrate
7
- } from "./chunk-QGEYKDIA.js";
8
- import "./chunk-HJSHCEK4.js";
9
- import "./chunk-BGG2SULN.js";
5
+ } from "./chunk-PKLOBITC.js";
6
+ import "./chunk-ECAW4X46.js";
7
+ import "./chunk-SLGJRZ3P.js";
10
8
  import {
11
9
  DiracParser
12
10
  } from "./chunk-HRHAMPOB.js";
13
11
  import {
14
12
  createSession
15
- } from "./chunk-2VFQ2YBT.js";
13
+ } from "./chunk-PPH7KYKH.js";
16
14
 
17
15
  // src/shell.ts
18
16
  import * as readline from "readline";
@@ -360,7 +358,7 @@ var DiracShell = class {
360
358
  if (this.client) {
361
359
  this.client.disconnect();
362
360
  }
363
- import("./schedule-QRJ6IYKM.js").then(({ stopAllScheduledTasks }) => {
361
+ import("./schedule-FMQJKZ4Z.js").then(({ stopAllScheduledTasks }) => {
364
362
  stopAllScheduledTasks();
365
363
  console.log("\nGoodbye!");
366
364
  process.exit(0);
@@ -544,6 +542,7 @@ Commands:
544
542
  :scheduled List all scheduled runs (run-at)
545
543
  :cancel <name> Cancel a scheduled run
546
544
  :cancelall Cancel all scheduled runs
545
+ :save-training Save LLM dialog as training data (opens in editor)
547
546
  :exit Exit shell
548
547
 
549
548
  Syntax:
@@ -764,7 +763,7 @@ Examples:
764
763
  break;
765
764
  case "tasks":
766
765
  try {
767
- const { listScheduledTasks } = await import("./schedule-QRJ6IYKM.js");
766
+ const { listScheduledTasks } = await import("./schedule-FMQJKZ4Z.js");
768
767
  const tasks = listScheduledTasks();
769
768
  if (tasks.length === 0) {
770
769
  console.log("No scheduled tasks running.");
@@ -783,7 +782,7 @@ Examples:
783
782
  console.log("Usage: :stop <task-name>");
784
783
  } else {
785
784
  try {
786
- const { stopScheduledTask } = await import("./schedule-QRJ6IYKM.js");
785
+ const { stopScheduledTask } = await import("./schedule-FMQJKZ4Z.js");
787
786
  const taskName = args[0];
788
787
  const stopped = stopScheduledTask(taskName);
789
788
  if (stopped) {
@@ -798,7 +797,7 @@ Examples:
798
797
  break;
799
798
  case "stopall":
800
799
  try {
801
- const { stopAllScheduledTasks } = await import("./schedule-QRJ6IYKM.js");
800
+ const { stopAllScheduledTasks } = await import("./schedule-FMQJKZ4Z.js");
802
801
  stopAllScheduledTasks();
803
802
  console.log("All scheduled tasks stopped.");
804
803
  } catch (error) {
@@ -807,7 +806,7 @@ Examples:
807
806
  break;
808
807
  case "crons":
809
808
  try {
810
- const { listCronJobs } = await import("./cron-M6QJMAUB.js");
809
+ const { listCronJobs } = await import("./cron-QRAJN2S2.js");
811
810
  const jobs = listCronJobs();
812
811
  if (jobs.length === 0) {
813
812
  console.log("No cron jobs running.");
@@ -827,7 +826,7 @@ Examples:
827
826
  console.log("Usage: :stopcron <job-name>");
828
827
  } else {
829
828
  try {
830
- const { stopCronJob } = await import("./cron-M6QJMAUB.js");
829
+ const { stopCronJob } = await import("./cron-QRAJN2S2.js");
831
830
  const jobName = args[0];
832
831
  const stopped = stopCronJob(jobName);
833
832
  if (stopped) {
@@ -842,7 +841,7 @@ Examples:
842
841
  break;
843
842
  case "stopallcrons":
844
843
  try {
845
- const { stopAllCronJobs } = await import("./cron-M6QJMAUB.js");
844
+ const { stopAllCronJobs } = await import("./cron-QRAJN2S2.js");
846
845
  stopAllCronJobs();
847
846
  console.log("All cron jobs stopped.");
848
847
  } catch (error) {
@@ -851,7 +850,7 @@ Examples:
851
850
  break;
852
851
  case "scheduled":
853
852
  try {
854
- const { listScheduledRuns } = await import("./run-at-I5ZV3QBL.js");
853
+ const { listScheduledRuns } = await import("./run-at-THEZWPTK.js");
855
854
  const runs = listScheduledRuns();
856
855
  if (runs.length === 0) {
857
856
  console.log("No scheduled runs pending.");
@@ -871,7 +870,7 @@ Examples:
871
870
  console.log("Usage: :cancel <run-name>");
872
871
  } else {
873
872
  try {
874
- const { cancelScheduledRun } = await import("./run-at-I5ZV3QBL.js");
873
+ const { cancelScheduledRun } = await import("./run-at-THEZWPTK.js");
875
874
  const runName = args[0];
876
875
  const cancelled = cancelScheduledRun(runName);
877
876
  if (cancelled) {
@@ -886,13 +885,73 @@ Examples:
886
885
  break;
887
886
  case "cancelall":
888
887
  try {
889
- const { cancelAllScheduledRuns } = await import("./run-at-I5ZV3QBL.js");
888
+ const { cancelAllScheduledRuns } = await import("./run-at-THEZWPTK.js");
890
889
  cancelAllScheduledRuns();
891
890
  console.log("All scheduled runs cancelled.");
892
891
  } catch (error) {
893
892
  console.error("Error cancelling runs:", error instanceof Error ? error.message : String(error));
894
893
  }
895
894
  break;
895
+ case "save-training":
896
+ try {
897
+ const dialogVar = this.client ? (await this.client.getState()).variables.find((v) => v.name === "__llm_dialog__") : this.session.variables.find((v) => v.name === "__llm_dialog__");
898
+ if (!dialogVar || !dialogVar.value) {
899
+ console.log("No LLM dialog to save");
900
+ break;
901
+ }
902
+ const dialog = typeof dialogVar.value === "string" ? JSON.parse(dialogVar.value) : dialogVar.value;
903
+ if (!Array.isArray(dialog) || dialog.length === 0) {
904
+ console.log("Dialog is empty");
905
+ break;
906
+ }
907
+ const trainingExample = { messages: dialog };
908
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0] + "-" + Date.now();
909
+ const tempFile = path.join(os.tmpdir(), `dirac-training-${timestamp}.jsonl`);
910
+ fs.writeFileSync(tempFile, JSON.stringify(trainingExample, null, 2), "utf-8");
911
+ console.log("Opening in editor...");
912
+ const editor = process.env.EDITOR || process.env.VISUAL || "vi";
913
+ const { spawnSync } = await import("child_process");
914
+ const result = spawnSync(editor, [tempFile], {
915
+ stdio: "inherit",
916
+ shell: true
917
+ });
918
+ if (result.error) {
919
+ fs.unlinkSync(tempFile);
920
+ console.error(`Failed to open editor: ${result.error.message}`);
921
+ break;
922
+ }
923
+ if (result.status !== 0) {
924
+ fs.unlinkSync(tempFile);
925
+ console.error(`Editor exited with code ${result.status}`);
926
+ break;
927
+ }
928
+ const answer = await new Promise((resolve2) => {
929
+ this.rl.question("Save to file (or press Enter to cancel): ", resolve2);
930
+ });
931
+ if (!answer.trim()) {
932
+ fs.unlinkSync(tempFile);
933
+ console.log("Cancelled");
934
+ break;
935
+ }
936
+ let savePath;
937
+ if (answer.startsWith("/") || answer.startsWith("~")) {
938
+ savePath = answer.replace(/^~/, os.homedir());
939
+ } else if (answer.includes("/")) {
940
+ savePath = path.resolve(answer);
941
+ } else {
942
+ const trainingDir = path.join(os.homedir(), ".dirac", "training");
943
+ fs.mkdirSync(trainingDir, { recursive: true });
944
+ savePath = path.join(trainingDir, answer.endsWith(".jsonl") ? answer : `${answer}.jsonl`);
945
+ }
946
+ const editedContent = fs.readFileSync(tempFile, "utf-8");
947
+ const editedData = JSON.parse(editedContent);
948
+ fs.appendFileSync(savePath, JSON.stringify(editedData) + "\n");
949
+ fs.unlinkSync(tempFile);
950
+ console.log(`\u2713 Saved training example to ${savePath}`);
951
+ } catch (error) {
952
+ console.error("Error saving training data:", error instanceof Error ? error.message : String(error));
953
+ }
954
+ break;
896
955
  case "exit":
897
956
  case "quit":
898
957
  this.rl.close();
@@ -995,7 +1054,7 @@ Examples:
995
1054
  console.log("Set ANTHROPIC_API_KEY or OPENAI_API_KEY environment variable,");
996
1055
  console.log("or create ~/.dirac/config.yml with llmProvider and llmModel.\n");
997
1056
  }
998
- const { registry } = await import("./subroutine-index-E6XE6XNL.js");
1057
+ const { registry } = await import("./subroutine-index-RVJSWWJ7.js");
999
1058
  const wasIndexed = await registry.autoIndexStdlib();
1000
1059
  await this.loadEssentialSubroutines();
1001
1060
  if (this.config.initScript) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  executeSubroutine
3
- } from "./chunk-HJSHCEK4.js";
4
- import "./chunk-2VFQ2YBT.js";
3
+ } from "./chunk-ECAW4X46.js";
4
+ import "./chunk-PPH7KYKH.js";
5
5
  export {
6
6
  executeSubroutine
7
7
  };
@@ -3,9 +3,9 @@ import {
3
3
  executeRegistryStats,
4
4
  executeSearchSubroutines,
5
5
  registry
6
- } from "./chunk-BGG2SULN.js";
6
+ } from "./chunk-SLGJRZ3P.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-2VFQ2YBT.js";
8
+ import "./chunk-PPH7KYKH.js";
9
9
  export {
10
10
  executeIndexSubroutines,
11
11
  executeRegistryStats,
@@ -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-YZHVQ4XN.js");
52
+ const { getAvailableSubroutines } = await import("./session-IH5LO7FS.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,15 +1,15 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-QGEYKDIA.js";
4
- import "./chunk-HJSHCEK4.js";
5
- import "./chunk-BGG2SULN.js";
3
+ } from "./chunk-PKLOBITC.js";
4
+ import "./chunk-ECAW4X46.js";
5
+ import "./chunk-SLGJRZ3P.js";
6
6
  import {
7
7
  DiracParser
8
8
  } from "./chunk-HRHAMPOB.js";
9
9
  import {
10
10
  createSession,
11
11
  getOutput
12
- } from "./chunk-2VFQ2YBT.js";
12
+ } from "./chunk-PPH7KYKH.js";
13
13
 
14
14
  // src/test-runner.ts
15
15
  import fs from "fs";
package/lib/ai.di CHANGED
@@ -1,7 +1,8 @@
1
1
  <!-- Exported subroutine -->
2
2
 
3
3
  <subroutine name="ai"
4
- description="AI assistant with context loading (internal wrapper - use llm tag directly instead)">
4
+ description="AI assistant with context loading (internal wrapper - use llm tag directly instead)"
5
+ visible="subroutine" >
5
6
 
6
7
 
7
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.89",
3
+ "version": "0.1.91",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",