dirac-lang 0.1.36 → 0.1.37

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.36",
19
+ version: "0.1.37",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
@@ -95,7 +95,7 @@ async function main() {
95
95
  process.exit(0);
96
96
  }
97
97
  if (args[0] === "shell") {
98
- const { DiracShell } = await import("./shell-ILGAOLMJ.js");
98
+ const { DiracShell } = await import("./shell-B5RBRWK2.js");
99
99
  const shellConfig = { debug: false };
100
100
  for (let i = 1; i < args.length; i++) {
101
101
  const arg = args[i];
@@ -88,6 +88,11 @@ var DiracShell = class {
88
88
  this.rl.prompt();
89
89
  return;
90
90
  }
91
+ if (this.inputBuffer.length === 0 && !this.isDiracSyntax(input)) {
92
+ await this.executeShellCommand(input);
93
+ this.rl.prompt();
94
+ return;
95
+ }
91
96
  const indent = this.getIndent(input);
92
97
  if (this.inputBuffer.length === 0) {
93
98
  this.inputBuffer.push(input);
@@ -258,6 +263,61 @@ Examples:
258
263
  console.log(`Unknown command: ${command}. Type :help for available commands.`);
259
264
  }
260
265
  }
266
+ /**
267
+ * Check if input contains Dirac bra-ket syntax
268
+ * Must be careful not to match shell redirects (>, <, <<, >>)
269
+ */
270
+ isDiracSyntax(input) {
271
+ const trimmed = input.trim();
272
+ if (trimmed.match(/^<[a-zA-Z_][a-zA-Z0-9_-]*[^<>]*\|$/)) {
273
+ return true;
274
+ }
275
+ if (trimmed.match(/^\|[a-zA-Z_][a-zA-Z0-9_-]*[^|]*>/)) {
276
+ return true;
277
+ }
278
+ if (trimmed.match(/^<\/[a-zA-Z_][a-zA-Z0-9_-]*>$/)) {
279
+ return true;
280
+ }
281
+ if (trimmed.match(/^<(output|variable|defvar|llm|call|subroutine|if|foreach|test-if)\b/)) {
282
+ return true;
283
+ }
284
+ return false;
285
+ }
286
+ /**
287
+ * Execute a Unix shell command
288
+ */
289
+ async executeShellCommand(command) {
290
+ const trimmed = command.trim();
291
+ const cdMatch = trimmed.match(/^cd\s+(.*)$/);
292
+ if (cdMatch) {
293
+ const targetDir = cdMatch[1].trim() || process.env.HOME || "~";
294
+ try {
295
+ const expandedDir = targetDir.startsWith("~") ? targetDir.replace(/^~/, process.env.HOME || "~") : targetDir;
296
+ process.chdir(expandedDir);
297
+ } catch (err) {
298
+ console.error(`cd: ${err.message}`);
299
+ }
300
+ return;
301
+ }
302
+ const { spawn } = await import("child_process");
303
+ this.rl.pause();
304
+ return new Promise((resolve) => {
305
+ const shell = process.env.SHELL || "/bin/sh";
306
+ const child = spawn(shell, ["-c", command], {
307
+ stdio: "inherit",
308
+ cwd: process.cwd()
309
+ });
310
+ child.on("close", () => {
311
+ this.rl.resume();
312
+ resolve();
313
+ });
314
+ child.on("error", (err) => {
315
+ console.error(`Shell error: ${err.message}`);
316
+ this.rl.resume();
317
+ resolve();
318
+ });
319
+ });
320
+ }
261
321
  start() {
262
322
  console.log("Dirac Shell v0.1.0");
263
323
  console.log("Type :help for commands, :exit to quit\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",