dirac-lang 0.1.63 → 0.1.65

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,13 +16,14 @@ import "dotenv/config";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "dirac-lang",
19
- version: "0.1.62",
19
+ version: "0.1.64",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
23
23
  types: "dist/index.d.ts",
24
24
  bin: {
25
- dirac: "dist/cli.js"
25
+ dirac: "dist/cli.js",
26
+ dish: "dist/cli.js"
26
27
  },
27
28
  exports: {
28
29
  ".": "./dist/index.js"
@@ -70,11 +71,54 @@ var package_default = {
70
71
  import fs from "fs";
71
72
  import yaml from "js-yaml";
72
73
  import { resolve, extname } from "path";
74
+ function loadShellConfig(args = []) {
75
+ const shellConfig = { debug: false };
76
+ for (let i = 0; i < args.length; i++) {
77
+ const arg = args[i];
78
+ if (arg === "--debug") {
79
+ shellConfig.debug = true;
80
+ } else if ((arg === "-f" || arg === "--config") && i + 1 < args.length) {
81
+ const configPath = resolve(args[++i]);
82
+ if (fs.existsSync(configPath)) {
83
+ const configData = yaml.load(fs.readFileSync(configPath, "utf-8"));
84
+ Object.assign(shellConfig, {
85
+ llmProvider: configData.llmProvider,
86
+ llmModel: configData.llmModel,
87
+ customLLMUrl: configData.customLLMUrl,
88
+ initScript: configData.initScript
89
+ });
90
+ }
91
+ }
92
+ }
93
+ if (!shellConfig.llmProvider) {
94
+ const defaultConfigPath = resolve(process.cwd(), "config.yml");
95
+ if (fs.existsSync(defaultConfigPath)) {
96
+ try {
97
+ const configData = yaml.load(fs.readFileSync(defaultConfigPath, "utf-8"));
98
+ shellConfig.llmProvider = shellConfig.llmProvider || configData.llmProvider;
99
+ shellConfig.llmModel = shellConfig.llmModel || configData.llmModel;
100
+ shellConfig.customLLMUrl = shellConfig.customLLMUrl || configData.customLLMUrl;
101
+ shellConfig.initScript = shellConfig.initScript || configData.initScript;
102
+ } catch (err) {
103
+ }
104
+ }
105
+ }
106
+ return shellConfig;
107
+ }
73
108
  async function main() {
74
109
  const args = process.argv.slice(2);
110
+ const calledAs = process.argv[1];
111
+ if (calledAs && calledAs.endsWith("/dish")) {
112
+ const { DiracShell } = await import("./shell-6NG7WK5Z.js");
113
+ const shellConfig = loadShellConfig(args);
114
+ const shell = new DiracShell(shellConfig);
115
+ await shell.start();
116
+ return;
117
+ }
75
118
  if (args.includes("--help") || args.includes("-h")) {
76
119
  console.log("Usage: dirac <file.di|file.bk>");
77
120
  console.log(" dirac shell [options]");
121
+ console.log(" dish Start interactive shell (short alias)");
78
122
  console.log(" dirac agent <command>");
79
123
  console.log("");
80
124
  console.log("Commands:");
@@ -145,46 +189,14 @@ async function main() {
145
189
  return;
146
190
  }
147
191
  if (args[0] === "shell") {
148
- const { DiracShell } = await import("./shell-SN7XYIDA.js");
192
+ const { DiracShell } = await import("./shell-6NG7WK5Z.js");
149
193
  const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-GEISBLMU.js");
150
194
  const { SessionClient } = await import("./session-client-3VTC5MLO.js");
151
195
  const daemonMode = args.includes("--daemon") || args.includes("-d");
152
196
  const agentMode = args.includes("--agent") || args.includes("-a");
153
- const shellConfig = { debug: false };
154
- for (let i = 1; i < args.length; i++) {
155
- const arg = args[i];
156
- if (arg === "--debug") {
157
- shellConfig.debug = true;
158
- } else if (arg === "--daemon" || arg === "-d") {
159
- continue;
160
- } else if (arg === "--agent" || arg === "-a") {
161
- continue;
162
- } else if ((arg === "-f" || arg === "--config") && i + 1 < args.length) {
163
- const configPath = resolve(args[++i]);
164
- if (fs.existsSync(configPath)) {
165
- const configData = yaml.load(fs.readFileSync(configPath, "utf-8"));
166
- Object.assign(shellConfig, {
167
- llmProvider: configData.llmProvider,
168
- llmModel: configData.llmModel,
169
- customLLMUrl: configData.customLLMUrl,
170
- initScript: configData.initScript
171
- });
172
- }
173
- }
174
- }
175
- if (!shellConfig.llmProvider) {
176
- const defaultConfigPath = resolve(process.cwd(), "config.yml");
177
- if (fs.existsSync(defaultConfigPath)) {
178
- try {
179
- const configData = yaml.load(fs.readFileSync(defaultConfigPath, "utf-8"));
180
- shellConfig.llmProvider = shellConfig.llmProvider || configData.llmProvider;
181
- shellConfig.llmModel = shellConfig.llmModel || configData.llmModel;
182
- shellConfig.customLLMUrl = shellConfig.customLLMUrl || configData.customLLMUrl;
183
- shellConfig.initScript = shellConfig.initScript || configData.initScript;
184
- } catch (err) {
185
- }
186
- }
187
- }
197
+ const shellConfig = loadShellConfig(args.slice(1).filter(
198
+ (arg) => arg !== "--daemon" && arg !== "-d" && arg !== "--agent" && arg !== "-a"
199
+ ));
188
200
  if (agentMode) {
189
201
  if (!isSessionRunning()) {
190
202
  console.error("Error: No agent is running");
@@ -68,6 +68,65 @@ var DiracShell = class {
68
68
  }
69
69
  completer(line) {
70
70
  const subroutines = this.client ? this.cachedSubroutines : this.session.subroutines;
71
+ const varMatch = line.match(/\$([a-zA-Z0-9_-]*)$/);
72
+ if (varMatch) {
73
+ const partial = varMatch[1];
74
+ const varNames = Object.keys(this.session.variables || {});
75
+ const commonEnvVars = [
76
+ "HOME",
77
+ "PATH",
78
+ "USER",
79
+ "SHELL",
80
+ "PWD",
81
+ "OLDPWD",
82
+ "TERM",
83
+ "LANG",
84
+ "EDITOR",
85
+ "TMPDIR",
86
+ "PS1"
87
+ ];
88
+ const envVarNames = Object.keys(process.env).filter(
89
+ (name) => commonEnvVars.includes(name) || name.startsWith("DIRAC_") || name.startsWith("TELEGRAM_")
90
+ );
91
+ const allVars = [...varNames, ...envVarNames];
92
+ const matches = allVars.filter(
93
+ (name) => name.toLowerCase().startsWith(partial.toLowerCase())
94
+ );
95
+ const completions = matches.map((name) => `$${name}`);
96
+ return [completions, varMatch[0]];
97
+ }
98
+ const pathMatch = line.match(/((?:\.\.?\/|~\/|\/)[^\s]*)$/);
99
+ if (pathMatch) {
100
+ const partial = pathMatch[1];
101
+ try {
102
+ let searchPath = partial;
103
+ if (searchPath.startsWith("~/")) {
104
+ searchPath = path.join(os.homedir(), searchPath.slice(2));
105
+ }
106
+ const dirPath = path.dirname(searchPath);
107
+ const filePrefix = path.basename(searchPath);
108
+ if (fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()) {
109
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
110
+ const matches = entries.filter((entry) => entry.name.startsWith(filePrefix)).map((entry) => {
111
+ const fullPath = path.join(dirPath, entry.name);
112
+ let displayPath = fullPath;
113
+ if (partial.startsWith("~/")) {
114
+ displayPath = "~/" + path.relative(os.homedir(), fullPath);
115
+ } else if (partial.startsWith("./") || partial.startsWith("../")) {
116
+ displayPath = path.relative(process.cwd(), fullPath);
117
+ if (!displayPath.startsWith(".")) {
118
+ displayPath = "./" + displayPath;
119
+ }
120
+ }
121
+ return entry.isDirectory() ? displayPath + "/" : displayPath;
122
+ });
123
+ if (matches.length > 0) {
124
+ return [matches, pathMatch[0]];
125
+ }
126
+ }
127
+ } catch (error) {
128
+ }
129
+ }
71
130
  const attrMatch = line.match(/\|([a-z0-9_-]+)\s+.*?([a-z0-9_-]*)$/i);
72
131
  if (attrMatch) {
73
132
  const tagName = attrMatch[1];
@@ -143,11 +202,57 @@ var DiracShell = class {
143
202
  const commandMatch = line.match(/:([a-z]*)$/i);
144
203
  if (commandMatch) {
145
204
  const partial = commandMatch[1];
146
- const commands = ["help", "quit", "exit", "vars", "subs", "clear", "history", "save", "debug", "llm"];
205
+ const commands = ["help", "quit", "exit", "vars", "subs", "clear", "history", "save", "debug", "llm", "index"];
147
206
  const matches = commands.filter((cmd) => cmd.startsWith(partial.toLowerCase()));
148
207
  const completions = matches.map((cmd) => `:${cmd}`);
149
208
  return [completions, commandMatch[0]];
150
209
  }
210
+ if (line.includes("<system>") || line.includes("|system>")) {
211
+ const systemMatch = line.match(/(?:<system>|\\|system>)\s*([a-z]*)$/i);
212
+ if (systemMatch) {
213
+ const partial = systemMatch[1];
214
+ const commonCommands = [
215
+ "ls",
216
+ "cd",
217
+ "pwd",
218
+ "cat",
219
+ "grep",
220
+ "find",
221
+ "echo",
222
+ "cp",
223
+ "mv",
224
+ "rm",
225
+ "mkdir",
226
+ "touch",
227
+ "git",
228
+ "npm",
229
+ "node",
230
+ "python",
231
+ "curl",
232
+ "wget",
233
+ "ssh",
234
+ "scp",
235
+ "tar",
236
+ "gzip",
237
+ "diff",
238
+ "ps",
239
+ "top",
240
+ "kill",
241
+ "chmod",
242
+ "chown",
243
+ "ln",
244
+ "du",
245
+ "df",
246
+ "which",
247
+ "man",
248
+ "history"
249
+ ];
250
+ const matches = commonCommands.filter((cmd) => cmd.startsWith(partial.toLowerCase()));
251
+ if (matches.length > 0) {
252
+ return [matches, partial];
253
+ }
254
+ }
255
+ }
151
256
  return [[], line];
152
257
  }
153
258
  loadHistory() {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.63",
3
+ "version": "0.1.65",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "bin": {
9
- "dirac": "dist/cli.js"
9
+ "dirac": "dist/cli.js",
10
+ "dish": "dist/cli.js"
10
11
  },
11
12
  "exports": {
12
13
  ".": "./dist/index.js"