dirac-lang 0.1.95 → 0.1.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -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.94",
19
+ version: "0.1.95",
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-SUNLGPOM.js");
153
+ const { DiracShell } = await import("./shell-N3TM23ZB.js");
154
154
  const shellConfig = loadShellConfig(args);
155
155
  const shell = new DiracShell(shellConfig);
156
156
  await shell.start();
@@ -230,7 +230,7 @@ async function main() {
230
230
  return;
231
231
  }
232
232
  if (args[0] === "shell") {
233
- const { DiracShell } = await import("./shell-SUNLGPOM.js");
233
+ const { DiracShell } = await import("./shell-N3TM23ZB.js");
234
234
  const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-GPITH5QY.js");
235
235
  const { SessionClient } = await import("./session-client-3VTC5MLO.js");
236
236
  const daemonMode = args.includes("--daemon") || args.includes("-d");
@@ -542,7 +542,7 @@ Commands:
542
542
  :scheduled List all scheduled runs (run-at)
543
543
  :cancel <name> Cancel a scheduled run
544
544
  :cancelall Cancel all scheduled runs
545
- :save-training Save LLM dialog as training data (opens in editor)
545
+ :save-training [mode=full|pruned|both] Save LLM dialog as training data (opens in editor)
546
546
  :exit Exit shell
547
547
 
548
548
  Syntax:
@@ -894,6 +894,21 @@ Examples:
894
894
  break;
895
895
  case "save-training":
896
896
  try {
897
+ const fullCommand = cmd.slice(1);
898
+ const saveArgs = fullCommand.split(/\s+/).slice(1);
899
+ let saveMode = "full";
900
+ console.error(`[DEBUG] Full command: "${fullCommand}"`);
901
+ console.error(`[DEBUG] Args:`, saveArgs);
902
+ for (const arg of saveArgs) {
903
+ if (arg.startsWith("mode=")) {
904
+ saveMode = arg.split("=")[1];
905
+ console.error(`[DEBUG] Set mode to: ${saveMode}`);
906
+ } else if (arg === "prune=true") {
907
+ saveMode = "pruned";
908
+ console.error(`[DEBUG] Set mode to pruned`);
909
+ }
910
+ }
911
+ console.error(`[DEBUG] Final saveMode: ${saveMode}`);
897
912
  const dialogVar = this.client ? (await this.client.getState()).variables.find((v) => v.name === "__llm_dialog__") : this.session.variables.find((v) => v.name === "__llm_dialog__");
898
913
  if (!dialogVar || !dialogVar.value) {
899
914
  console.log("No LLM dialog to save");
@@ -904,10 +919,64 @@ Examples:
904
919
  console.log("Dialog is empty");
905
920
  break;
906
921
  }
907
- const trainingExample = { messages: dialog };
922
+ const pruneCorrections = (msgs) => {
923
+ const pruned = [];
924
+ let skipNext = false;
925
+ let correctionCount = 0;
926
+ for (let i = 0; i < msgs.length; i++) {
927
+ const msg = msgs[i];
928
+ if (msg.role === "system") {
929
+ pruned.push(msg);
930
+ continue;
931
+ }
932
+ if (skipNext) {
933
+ skipNext = false;
934
+ continue;
935
+ }
936
+ if (msg.role === "user" && (msg.content.includes("System: Your submitted code had errors") || msg.content.includes("System: Auto-corrections applied"))) {
937
+ correctionCount++;
938
+ console.error(`[PRUNE] Found correction message at index ${i}`);
939
+ if (pruned.length > 0 && pruned[pruned.length - 1].role === "assistant") {
940
+ console.error(`[PRUNE] Removing wrong assistant response`);
941
+ pruned.pop();
942
+ }
943
+ if (i + 1 < msgs.length && msgs[i + 1].role === "assistant") {
944
+ console.error(`[PRUNE] Keeping corrected assistant response`);
945
+ pruned.push(msgs[i + 1]);
946
+ skipNext = true;
947
+ }
948
+ continue;
949
+ }
950
+ pruned.push(msg);
951
+ }
952
+ console.error(`[PRUNE] Processed ${msgs.length} messages, found ${correctionCount} corrections, result has ${pruned.length} messages`);
953
+ return pruned;
954
+ };
955
+ const fullExample = { messages: dialog };
956
+ const prunedExample = { messages: pruneCorrections(dialog) };
957
+ console.log(`
958
+ Mode: ${saveMode}`);
959
+ if (saveMode === "full" || saveMode === "both") {
960
+ console.log(`Full dialog: ${dialog.length} messages`);
961
+ }
962
+ if (saveMode === "pruned" || saveMode === "both") {
963
+ console.log(`Pruned dialog: ${prunedExample.messages.length} messages (removed ${dialog.length - prunedExample.messages.length} correction messages)`);
964
+ }
908
965
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0] + "-" + Date.now();
909
966
  const tempFile = path.join(os.tmpdir(), `dirac-training-${timestamp}.jsonl`);
910
- fs.writeFileSync(tempFile, JSON.stringify(trainingExample, null, 2), "utf-8");
967
+ let tempContent;
968
+ if (saveMode === "both") {
969
+ tempContent = `// FULL VERSION (with corrections)
970
+ ${JSON.stringify(fullExample, null, 2)}
971
+
972
+ // PRUNED VERSION (mistakes removed)
973
+ ${JSON.stringify(prunedExample, null, 2)}`;
974
+ } else if (saveMode === "pruned") {
975
+ tempContent = JSON.stringify(prunedExample, null, 2);
976
+ } else {
977
+ tempContent = JSON.stringify(fullExample, null, 2);
978
+ }
979
+ fs.writeFileSync(tempFile, tempContent, "utf-8");
911
980
  console.log("Opening in editor...");
912
981
  const editor = process.env.EDITOR || process.env.VISUAL || "vi";
913
982
  const { spawnSync } = await import("child_process");
@@ -944,10 +1013,40 @@ Examples:
944
1013
  savePath = path.join(trainingDir, answer.endsWith(".jsonl") ? answer : `${answer}.jsonl`);
945
1014
  }
946
1015
  const editedContent = fs.readFileSync(tempFile, "utf-8");
947
- const editedData = JSON.parse(editedContent);
948
- fs.appendFileSync(savePath, JSON.stringify(editedData) + "\n");
1016
+ if (saveMode === "both") {
1017
+ const lines = editedContent.split("\n");
1018
+ let fullJson = "";
1019
+ let prunedJson = "";
1020
+ let inFull = false;
1021
+ let inPruned = false;
1022
+ let braceCount = 0;
1023
+ for (const line of lines) {
1024
+ if (line.includes("// FULL VERSION")) {
1025
+ inFull = true;
1026
+ continue;
1027
+ }
1028
+ if (line.includes("// PRUNED VERSION")) {
1029
+ inFull = false;
1030
+ inPruned = true;
1031
+ continue;
1032
+ }
1033
+ if (inFull) {
1034
+ fullJson += line + "\n";
1035
+ } else if (inPruned) {
1036
+ prunedJson += line + "\n";
1037
+ }
1038
+ }
1039
+ const fullData = JSON.parse(fullJson.trim());
1040
+ const prunedData = JSON.parse(prunedJson.trim());
1041
+ fs.appendFileSync(savePath, JSON.stringify(fullData) + "\n");
1042
+ fs.appendFileSync(savePath, JSON.stringify(prunedData) + "\n");
1043
+ console.log(`\u2713 Saved 2 training examples (full + pruned) to ${savePath}`);
1044
+ } else {
1045
+ const editedData = JSON.parse(editedContent);
1046
+ fs.appendFileSync(savePath, JSON.stringify(editedData) + "\n");
1047
+ console.log(`\u2713 Saved training example (${saveMode}) to ${savePath}`);
1048
+ }
949
1049
  fs.unlinkSync(tempFile);
950
- console.log(`\u2713 Saved training example to ${savePath}`);
951
1050
  } catch (error) {
952
1051
  console.error("Error saving training data:", error instanceof Error ? error.message : String(error));
953
1052
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.95",
3
+ "version": "0.1.96",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",