dirac-lang 0.1.68 → 0.1.70

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,11 +2,11 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-XVAUVQZU.js";
6
- import "./chunk-GAGWNYD4.js";
5
+ } from "./chunk-2SJHHQ5D.js";
6
+ import "./chunk-WW2OXQZN.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-NKA6ZJDV.js";
9
- import "./chunk-3UW6GWYQ.js";
8
+ import "./chunk-VC23AJJJ.js";
9
+ import "./chunk-M57VI7KL.js";
10
10
 
11
11
  // src/agent.ts
12
12
  import fs from "fs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-GAGWNYD4.js";
3
+ } from "./chunk-WW2OXQZN.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
7
7
  import {
8
8
  createSession
9
- } from "./chunk-3UW6GWYQ.js";
9
+ } from "./chunk-M57VI7KL.js";
10
10
 
11
11
  // src/session-server.ts
12
12
  import net from "net";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-GAGWNYD4.js";
3
+ } from "./chunk-WW2OXQZN.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-3UW6GWYQ.js";
11
+ } from "./chunk-M57VI7KL.js";
12
12
 
13
13
  // src/utils/llm-adapter.ts
14
14
  function createLLMAdapter(session) {
@@ -190,7 +190,7 @@ function cleanToBoundary(session) {
190
190
  session.variables = kept;
191
191
  session.varBoundary = kept.length;
192
192
  }
193
- function registerSubroutine(session, name, element, description, parameters, meta, visible) {
193
+ function registerSubroutine(session, name, element, description, parameters, meta, visible, sourcePath) {
194
194
  session.subroutines.push({
195
195
  name,
196
196
  element,
@@ -198,7 +198,8 @@ function registerSubroutine(session, name, element, description, parameters, met
198
198
  visible,
199
199
  description,
200
200
  parameters,
201
- meta
201
+ meta,
202
+ sourcePath
202
203
  });
203
204
  }
204
205
  function getSubroutine(session, name) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerSubroutine
3
- } from "./chunk-3UW6GWYQ.js";
3
+ } from "./chunk-M57VI7KL.js";
4
4
 
5
5
  // src/tags/subroutine.ts
6
6
  function executeSubroutine(session, element) {
@@ -58,7 +58,8 @@ function executeSubroutine(session, element) {
58
58
  description,
59
59
  parameters.length > 0 ? parameters : void 0,
60
60
  Object.keys(meta).length > 0 ? meta : void 0,
61
- visible
61
+ visible,
62
+ session.currentFile
62
63
  );
63
64
  }
64
65
 
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-HRHAMPOB.js";
4
4
  import {
5
5
  executeSubroutine
6
- } from "./chunk-NKA6ZJDV.js";
6
+ } from "./chunk-VC23AJJJ.js";
7
7
  import {
8
8
  CustomLLMProvider,
9
9
  OllamaProvider,
@@ -28,7 +28,7 @@ import {
28
28
  substituteVariables,
29
29
  throwException,
30
30
  unsetExceptionBoundary
31
- } from "./chunk-3UW6GWYQ.js";
31
+ } from "./chunk-M57VI7KL.js";
32
32
 
33
33
  // src/tags/parameters.ts
34
34
  async function executeParameters(session, element) {
@@ -284,7 +284,7 @@ async function executeCall(session, element) {
284
284
  }
285
285
  }
286
286
  async function registerExtendChain(session, subroutine, currentName) {
287
- const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-WJU6SDRC.js");
287
+ const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-OQJ3AY27.js");
288
288
  const extendsAttr = subroutine.attributes.extends;
289
289
  let parentName;
290
290
  if (extendsAttr) {
@@ -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-KV56UTCS.js");
477
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
478
478
  await integrateChildren2(session, thenElement);
479
479
  }
480
480
  } else {
481
481
  if (elseElement) {
482
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-KV56UTCS.js");
482
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.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-KV56UTCS.js");
495
+ const { integrate: integrate2 } = await import("./interpreter-TKNNX6UX.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-KV56UTCS.js");
518
+ const { integrate: integrate2 } = await import("./interpreter-TKNNX6UX.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-KV56UTCS.js");
522
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
523
523
  await integrateChildren2(session, child);
524
524
  const newChunks = session.output.slice(argOutputStart);
525
525
  const argValue = newChunks.join("");
@@ -808,7 +808,7 @@ async function executeLLM(session, element) {
808
808
  let systemPrompt = "";
809
809
  let currentUserPrompt = userPrompt;
810
810
  if (!noExtra) {
811
- const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-AZIX6ILU.js");
811
+ const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-OL5ARO6Q.js");
812
812
  const allSubroutines = getAvailableSubroutines2(session);
813
813
  if (session.debug) {
814
814
  console.error(`[LLM] Total subroutines from session: ${allSubroutines.length}`);
@@ -1012,7 +1012,7 @@ ${result}
1012
1012
  const parser = new DiracParser();
1013
1013
  let dynamicAST = parser.parse(diracCode);
1014
1014
  if (validateTags) {
1015
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-PEBTT5HJ.js");
1015
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-JZVMOKGK.js");
1016
1016
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
1017
1017
  let retryCount = 0;
1018
1018
  while (!validation.valid && retryCount < maxRetries) {
@@ -1647,7 +1647,7 @@ async function getBestTagMatch(candidate, allowed) {
1647
1647
  return { tag: allowed[bestIdx], score: bestScore };
1648
1648
  }
1649
1649
  async function executeTagCheck(session, element) {
1650
- const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-AZIX6ILU.js");
1650
+ const { getAvailableSubroutines: getAvailableSubroutines2 } = await import("./session-OL5ARO6Q.js");
1651
1651
  const subroutines = getAvailableSubroutines2(session);
1652
1652
  const allowed = new Set(subroutines.map((s) => s.name));
1653
1653
  console.error("[tag-check] Allowed subroutines:", Array.from(allowed));
@@ -1740,7 +1740,7 @@ async function executeTagCheck(session, element) {
1740
1740
  const executeTag = correctedTag || tagName;
1741
1741
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1742
1742
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1743
- const { integrate: integrate2 } = await import("./interpreter-KV56UTCS.js");
1743
+ const { integrate: integrate2 } = await import("./interpreter-TKNNX6UX.js");
1744
1744
  await integrate2(session, elementToExecute);
1745
1745
  }
1746
1746
  }
@@ -1749,7 +1749,7 @@ async function executeTagCheck(session, element) {
1749
1749
  // src/tags/throw.ts
1750
1750
  async function executeThrow(session, element) {
1751
1751
  const exceptionName = element.attributes?.name || "exception";
1752
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-KV56UTCS.js");
1752
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
1753
1753
  const exceptionDom = {
1754
1754
  tag: "exception-content",
1755
1755
  attributes: { name: exceptionName },
@@ -1762,7 +1762,7 @@ async function executeThrow(session, element) {
1762
1762
  // src/tags/try.ts
1763
1763
  async function executeTry(session, element) {
1764
1764
  setExceptionBoundary(session);
1765
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-KV56UTCS.js");
1765
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
1766
1766
  await integrateChildren2(session, element);
1767
1767
  unsetExceptionBoundary(session);
1768
1768
  }
@@ -1772,7 +1772,7 @@ async function executeCatch(session, element) {
1772
1772
  const exceptionName = element.attributes?.name || "exception";
1773
1773
  const caughtCount = lookupException(session, exceptionName);
1774
1774
  if (caughtCount > 0) {
1775
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-KV56UTCS.js");
1775
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
1776
1776
  await integrateChildren2(session, element);
1777
1777
  }
1778
1778
  flushCurrentException(session);
@@ -1781,7 +1781,7 @@ async function executeCatch(session, element) {
1781
1781
  // src/tags/exception.ts
1782
1782
  async function executeException(session, element) {
1783
1783
  const exceptions = getCurrentExceptions(session);
1784
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-KV56UTCS.js");
1784
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-TKNNX6UX.js");
1785
1785
  for (const exceptionDom of exceptions) {
1786
1786
  await integrateChildren2(session, exceptionDom);
1787
1787
  }
@@ -2046,6 +2046,7 @@ var SubroutineRegistry = class {
2046
2046
  this.index.subroutines = this.index.subroutines.filter((s) => s.filePath !== filePath);
2047
2047
  const subroutines = this.extractSubroutines(ast, filePath);
2048
2048
  this.index.subroutines.push(...subroutines);
2049
+ this.saveIndex();
2049
2050
  return subroutines.length;
2050
2051
  } catch (err) {
2051
2052
  if (process.env.DEBUG_REGISTRY === "1") {
@@ -2242,14 +2243,13 @@ async function executeRegistryStats(session, element) {
2242
2243
  }
2243
2244
 
2244
2245
  // src/tags/load-context.ts
2245
- var registry2 = new SubroutineRegistry();
2246
2246
  async function executeLoadContext(session, element) {
2247
2247
  let query = element.attributes.query;
2248
2248
  if (!query && element.text) {
2249
2249
  query = element.text.trim();
2250
2250
  }
2251
2251
  if (!query && element.children.length > 0) {
2252
- const { integrate: integrate2 } = await import("./interpreter-KV56UTCS.js");
2252
+ const { integrate: integrate2 } = await import("./interpreter-TKNNX6UX.js");
2253
2253
  const beforeOutput = session.output.length;
2254
2254
  for (const child of element.children) {
2255
2255
  await integrate2(session, child);
@@ -2264,14 +2264,14 @@ async function executeLoadContext(session, element) {
2264
2264
  const limitAttr = element.attributes.limit;
2265
2265
  const shouldImport = element.attributes.import !== "false";
2266
2266
  const outputVar = element.attributes.output;
2267
- const stats = registry2.getStats();
2267
+ const stats = registry.getStats();
2268
2268
  if (stats.totalSubroutines === 0) {
2269
2269
  emit(session, `[load-context] Registry is empty. Use :index <path> or <index-subroutines path="..."> first.
2270
2270
  `);
2271
2271
  return;
2272
2272
  }
2273
2273
  const limit = limitAttr ? parseInt(limitAttr, 10) : 5;
2274
- const results = registry2.search(query, limit);
2274
+ const results = registry.search(query, limit);
2275
2275
  if (results.length === 0) {
2276
2276
  emit(session, `[load-context] No subroutines found for query: "${query}". Try indexing more libraries.
2277
2277
  `);
@@ -2318,7 +2318,7 @@ async function executeLoadContext(session, element) {
2318
2318
  parameters: s.parameters.map((p) => p.name),
2319
2319
  filePath: s.filePath
2320
2320
  }));
2321
- const { setVariable: setVariable2 } = await import("./session-AZIX6ILU.js");
2321
+ const { setVariable: setVariable2 } = await import("./session-OL5ARO6Q.js");
2322
2322
  setVariable2(session, outputVar, JSON.stringify(summary, null, 2), false);
2323
2323
  }
2324
2324
  }
@@ -2358,8 +2358,7 @@ async function executeSaveSubroutine(session, element) {
2358
2358
  const targetDir = join4(homedir4(), ".dirac", "lib", pathAttr);
2359
2359
  filePath = join4(targetDir, `${name}.di`);
2360
2360
  } else {
2361
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, -5);
2362
- const defaultDir = join4(homedir4(), ".dirac", "lib", timestamp);
2361
+ const defaultDir = join4(homedir4(), ".dirac", "lib", "user");
2363
2362
  filePath = join4(defaultDir, `${name}.di`);
2364
2363
  }
2365
2364
  const dir = dirname4(filePath);
@@ -2372,6 +2371,16 @@ async function executeSaveSubroutine(session, element) {
2372
2371
  if (session.debug) {
2373
2372
  console.error(`[save-subroutine] Saved '${name}' to: ${filePath}`);
2374
2373
  }
2374
+ try {
2375
+ const count = registry.indexFile(filePath);
2376
+ if (session.debug) {
2377
+ console.error(`[save-subroutine] Re-indexed ${filePath}: ${count} subroutine(s)`);
2378
+ }
2379
+ } catch (error) {
2380
+ if (session.debug) {
2381
+ console.error(`[save-subroutine] Warning: Failed to re-index: ${error}`);
2382
+ }
2383
+ }
2375
2384
  }
2376
2385
  function generateXMLNotation(subroutine) {
2377
2386
  let xml = "<!-- Exported subroutine -->\n\n";
@@ -2482,6 +2491,100 @@ function escapeXml3(text) {
2482
2491
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
2483
2492
  }
2484
2493
 
2494
+ // src/tags/edit-subroutine.ts
2495
+ import { writeFileSync as writeFileSync5, readFileSync as readFileSync3, unlinkSync } from "fs";
2496
+ import { tmpdir } from "os";
2497
+ import { join as join5 } from "path";
2498
+ import { spawnSync } from "child_process";
2499
+ async function executeEditSubroutine(session, element) {
2500
+ const name = element.attributes.name;
2501
+ const editor = element.attributes.editor || process.env.EDITOR || process.env.VISUAL || "vi";
2502
+ if (!name) {
2503
+ throw new Error("<edit-subroutine> requires name attribute");
2504
+ }
2505
+ let subroutine = void 0;
2506
+ for (let i = session.subroutines.length - 1; i >= 0; i--) {
2507
+ if (session.subroutines[i].name === name) {
2508
+ subroutine = session.subroutines[i];
2509
+ break;
2510
+ }
2511
+ }
2512
+ if (!subroutine) {
2513
+ throw new Error(`Subroutine '${name}' not found in session`);
2514
+ }
2515
+ const xml = serializeSubroutineToXML(subroutine);
2516
+ const tempFile = join5(tmpdir(), `dirac-edit-${name}-${Date.now()}.di`);
2517
+ writeFileSync5(tempFile, xml, "utf-8");
2518
+ if (session.debug) {
2519
+ console.error(`[edit-subroutine] Wrote '${name}' to temp file: ${tempFile}`);
2520
+ console.error(`[edit-subroutine] Opening with editor: ${editor}`);
2521
+ }
2522
+ const result = spawnSync(editor, [tempFile], {
2523
+ stdio: "inherit",
2524
+ // Pass through stdin/stdout/stderr
2525
+ shell: true
2526
+ });
2527
+ if (result.error) {
2528
+ unlinkSync(tempFile);
2529
+ throw new Error(`Failed to open editor: ${result.error.message}`);
2530
+ }
2531
+ if (result.status !== 0) {
2532
+ unlinkSync(tempFile);
2533
+ throw new Error(`Editor exited with code ${result.status}`);
2534
+ }
2535
+ const editedContent = readFileSync3(tempFile, "utf-8");
2536
+ unlinkSync(tempFile);
2537
+ if (session.debug) {
2538
+ console.error(`[edit-subroutine] Editor closed, re-importing subroutine`);
2539
+ }
2540
+ const parser = new DiracParser();
2541
+ const ast = parser.parse(editedContent);
2542
+ await integrate(session, ast);
2543
+ emit(session, `Subroutine '${name}' updated in session (use save-subroutine to persist)
2544
+ `);
2545
+ }
2546
+ function serializeSubroutineToXML(sub) {
2547
+ const lines = [];
2548
+ lines.push("<!-- Editing subroutine: " + sub.name + " -->");
2549
+ lines.push("");
2550
+ serializeElement2(sub.element, lines, "");
2551
+ return lines.join("\n");
2552
+ }
2553
+ function serializeElement2(el, lines, indent) {
2554
+ if (!el || !el.tag) {
2555
+ if (el && typeof el === "string") {
2556
+ lines.push(indent + el);
2557
+ }
2558
+ return;
2559
+ }
2560
+ let tag = `${indent}<${el.tag}`;
2561
+ if (el.attributes) {
2562
+ for (const [key, value] of Object.entries(el.attributes)) {
2563
+ if (typeof value === "string") {
2564
+ tag += ` ${key}="${value.replace(/"/g, "&quot;")}"`;
2565
+ }
2566
+ }
2567
+ }
2568
+ const hasChildren = el.children && el.children.length > 0;
2569
+ const hasText = el.text && el.text.trim();
2570
+ if (!hasChildren && !hasText) {
2571
+ lines.push(tag + " />");
2572
+ } else if (hasText && !hasChildren) {
2573
+ lines.push(tag + ">" + el.text + `</${el.tag}>`);
2574
+ } else {
2575
+ lines.push(tag + ">");
2576
+ if (hasText) {
2577
+ lines.push(indent + " " + el.text);
2578
+ }
2579
+ if (hasChildren) {
2580
+ for (const child of el.children) {
2581
+ serializeElement2(child, lines, indent + " ");
2582
+ }
2583
+ }
2584
+ lines.push(`${indent}</${el.tag}>`);
2585
+ }
2586
+ }
2587
+
2485
2588
  // src/tags/foreach.ts
2486
2589
  import { XMLParser } from "fast-xml-parser";
2487
2590
  async function executeForeach(session, element) {
@@ -2502,7 +2605,7 @@ async function executeForeach(session, element) {
2502
2605
  const parser2 = new DiracParser2();
2503
2606
  try {
2504
2607
  const fromElement = parser2.parse(fromAttr);
2505
- const { integrate: integrate2 } = await import("./interpreter-KV56UTCS.js");
2608
+ const { integrate: integrate2 } = await import("./interpreter-TKNNX6UX.js");
2506
2609
  await integrate2(session, fromElement);
2507
2610
  } catch (e) {
2508
2611
  session.output = savedOutput;
@@ -3064,6 +3167,9 @@ async function integrate(session, element) {
3064
3167
  case "save-subroutine":
3065
3168
  await executeSaveSubroutine(session, element);
3066
3169
  break;
3170
+ case "edit-subroutine":
3171
+ await executeEditSubroutine(session, element);
3172
+ break;
3067
3173
  case "foreach":
3068
3174
  await executeForeach(session, element);
3069
3175
  break;
package/dist/cli.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  execute
7
- } from "./chunk-74SZ3727.js";
8
- import "./chunk-GAGWNYD4.js";
7
+ } from "./chunk-3YGHR3R7.js";
8
+ import "./chunk-WW2OXQZN.js";
9
9
  import "./chunk-HRHAMPOB.js";
10
- import "./chunk-NKA6ZJDV.js";
11
- import "./chunk-3UW6GWYQ.js";
10
+ import "./chunk-VC23AJJJ.js";
11
+ import "./chunk-M57VI7KL.js";
12
12
 
13
13
  // src/cli.ts
14
14
  import "dotenv/config";
@@ -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.67",
19
+ version: "0.1.69",
20
20
  description: "LLM-Augmented Declarative Execution",
21
21
  type: "module",
22
22
  main: "dist/index.js",
@@ -109,7 +109,7 @@ async function main() {
109
109
  const args = process.argv.slice(2);
110
110
  const calledAs = process.argv[1];
111
111
  if (calledAs && calledAs.endsWith("/dish")) {
112
- const { DiracShell } = await import("./shell-6Z45ETUO.js");
112
+ const { DiracShell } = await import("./shell-GYZYKP7V.js");
113
113
  const shellConfig = loadShellConfig(args);
114
114
  const shell = new DiracShell(shellConfig);
115
115
  await shell.start();
@@ -158,11 +158,11 @@ async function main() {
158
158
  if (args[0] === "agent") {
159
159
  const subcommand = args[1];
160
160
  if (subcommand === "daemon") {
161
- const { runAgentDaemon } = await import("./agent-VBGWVB6G.js");
161
+ const { runAgentDaemon } = await import("./agent-YEC64Z37.js");
162
162
  await runAgentDaemon();
163
163
  return;
164
164
  }
165
- const { AgentCLI } = await import("./agent-VBGWVB6G.js");
165
+ const { AgentCLI } = await import("./agent-YEC64Z37.js");
166
166
  const agent = new AgentCLI();
167
167
  switch (subcommand) {
168
168
  case "start":
@@ -189,8 +189,8 @@ async function main() {
189
189
  return;
190
190
  }
191
191
  if (args[0] === "shell") {
192
- const { DiracShell } = await import("./shell-6Z45ETUO.js");
193
- const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-C63QPABR.js");
192
+ const { DiracShell } = await import("./shell-GYZYKP7V.js");
193
+ const { SessionServer, isSessionRunning, getSocketPath } = await import("./session-server-QQGWVEOL.js");
194
194
  const { SessionClient } = await import("./session-client-3VTC5MLO.js");
195
195
  const daemonMode = args.includes("--daemon") || args.includes("-d");
196
196
  const agentMode = args.includes("--agent") || args.includes("-a");
@@ -236,7 +236,7 @@ async function main() {
236
236
  return;
237
237
  }
238
238
  if (args[0] === "daemon") {
239
- const { SessionServer } = await import("./session-server-C63QPABR.js");
239
+ const { SessionServer } = await import("./session-server-QQGWVEOL.js");
240
240
  const server = new SessionServer();
241
241
  await server.start();
242
242
  console.log("Session daemon started");
@@ -3,10 +3,10 @@ import {
3
3
  listCronJobs,
4
4
  stopAllCronJobs,
5
5
  stopCronJob
6
- } from "./chunk-GAGWNYD4.js";
6
+ } from "./chunk-WW2OXQZN.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-NKA6ZJDV.js";
9
- import "./chunk-3UW6GWYQ.js";
8
+ import "./chunk-VC23AJJJ.js";
9
+ import "./chunk-M57VI7KL.js";
10
10
  export {
11
11
  executeCron,
12
12
  listCronJobs,
package/dist/index.d.ts CHANGED
@@ -57,6 +57,7 @@ interface Subroutine {
57
57
  description?: string;
58
58
  parameters?: ParameterMetadata[];
59
59
  meta?: Record<string, string>;
60
+ sourcePath?: string;
60
61
  }
61
62
  /**
62
63
  * Execution context - maps to MaskSession in MASK
package/dist/index.js CHANGED
@@ -2,19 +2,19 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-74SZ3727.js";
5
+ } from "./chunk-3YGHR3R7.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-GAGWNYD4.js";
8
+ } from "./chunk-WW2OXQZN.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
12
- import "./chunk-NKA6ZJDV.js";
12
+ import "./chunk-VC23AJJJ.js";
13
13
  import {
14
14
  createSession,
15
15
  getAvailableSubroutines,
16
16
  getOutput
17
- } from "./chunk-3UW6GWYQ.js";
17
+ } from "./chunk-M57VI7KL.js";
18
18
  export {
19
19
  DiracParser,
20
20
  createLLMAdapter,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-GAGWNYD4.js";
4
+ } from "./chunk-WW2OXQZN.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
- import "./chunk-NKA6ZJDV.js";
7
- import "./chunk-3UW6GWYQ.js";
6
+ import "./chunk-VC23AJJJ.js";
7
+ import "./chunk-M57VI7KL.js";
8
8
  export {
9
9
  integrate,
10
10
  integrateChildren
@@ -3,10 +3,10 @@ import {
3
3
  cancelScheduledRun,
4
4
  executeRunAt,
5
5
  listScheduledRuns
6
- } from "./chunk-GAGWNYD4.js";
6
+ } from "./chunk-WW2OXQZN.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-NKA6ZJDV.js";
9
- import "./chunk-3UW6GWYQ.js";
8
+ import "./chunk-VC23AJJJ.js";
9
+ import "./chunk-M57VI7KL.js";
10
10
  export {
11
11
  cancelAllScheduledRuns,
12
12
  cancelScheduledRun,
@@ -3,10 +3,10 @@ import {
3
3
  listScheduledTasks,
4
4
  stopAllScheduledTasks,
5
5
  stopScheduledTask
6
- } from "./chunk-GAGWNYD4.js";
6
+ } from "./chunk-WW2OXQZN.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-NKA6ZJDV.js";
9
- import "./chunk-3UW6GWYQ.js";
8
+ import "./chunk-VC23AJJJ.js";
9
+ import "./chunk-M57VI7KL.js";
10
10
  export {
11
11
  executeSchedule,
12
12
  listScheduledTasks,
@@ -26,7 +26,7 @@ import {
26
26
  substituteVariables,
27
27
  throwException,
28
28
  unsetExceptionBoundary
29
- } from "./chunk-3UW6GWYQ.js";
29
+ } from "./chunk-M57VI7KL.js";
30
30
  export {
31
31
  cleanSubroutinesToBoundary,
32
32
  cleanToBoundary,
@@ -2,11 +2,11 @@ import {
2
2
  SessionServer,
3
3
  getSocketPath,
4
4
  isSessionRunning
5
- } from "./chunk-XVAUVQZU.js";
6
- import "./chunk-GAGWNYD4.js";
5
+ } from "./chunk-2SJHHQ5D.js";
6
+ import "./chunk-WW2OXQZN.js";
7
7
  import "./chunk-HRHAMPOB.js";
8
- import "./chunk-NKA6ZJDV.js";
9
- import "./chunk-3UW6GWYQ.js";
8
+ import "./chunk-VC23AJJJ.js";
9
+ import "./chunk-M57VI7KL.js";
10
10
  export {
11
11
  SessionServer,
12
12
  getSocketPath,
@@ -4,14 +4,14 @@ import {
4
4
  } from "./chunk-AJSYOXXZ.js";
5
5
  import {
6
6
  integrate
7
- } from "./chunk-GAGWNYD4.js";
7
+ } from "./chunk-WW2OXQZN.js";
8
8
  import {
9
9
  DiracParser
10
10
  } from "./chunk-HRHAMPOB.js";
11
- import "./chunk-NKA6ZJDV.js";
11
+ import "./chunk-VC23AJJJ.js";
12
12
  import {
13
13
  createSession
14
- } from "./chunk-3UW6GWYQ.js";
14
+ } from "./chunk-M57VI7KL.js";
15
15
 
16
16
  // src/shell.ts
17
17
  import * as readline from "readline";
@@ -271,23 +271,123 @@ var DiracShell = class {
271
271
  } catch (err) {
272
272
  }
273
273
  }
274
+ getUnsavedSubroutines() {
275
+ const unsaved = [];
276
+ const excludePaths = [
277
+ path.join(os.homedir(), ".dirac", "lib"),
278
+ // System library
279
+ "/tmp/"
280
+ // Temp files
281
+ ];
282
+ for (const sub of this.session.subroutines) {
283
+ if (sub.meta && sub.meta["hide-from-llm"] === "true") {
284
+ continue;
285
+ }
286
+ if (!sub.sourcePath) {
287
+ unsaved.push(sub.name);
288
+ } else {
289
+ const isExcluded = excludePaths.some(
290
+ (excludePath) => sub.sourcePath.startsWith(excludePath)
291
+ );
292
+ if (isExcluded) {
293
+ continue;
294
+ }
295
+ }
296
+ }
297
+ return unsaved;
298
+ }
299
+ async promptSaveUnsaved(unsaved) {
300
+ console.log("\n\u26A0\uFE0F Warning: You have unsaved subroutines created in this session:");
301
+ for (const name of unsaved) {
302
+ console.log(` - ${name}`);
303
+ }
304
+ console.log("\nOptions:");
305
+ console.log(" a - Save all and exit");
306
+ console.log(" n - Exit without saving");
307
+ console.log(" c - Cancel (return to shell)");
308
+ return new Promise((resolve2) => {
309
+ const confirmRl = readline.createInterface({
310
+ input: process.stdin,
311
+ output: process.stdout
312
+ });
313
+ confirmRl.question("\nYour choice [a/n/c]: ", async (answer) => {
314
+ confirmRl.close();
315
+ const choice = answer.trim().toLowerCase();
316
+ if (choice === "a") {
317
+ console.log("\nSaving all unsaved subroutines...\n");
318
+ for (const name of unsaved) {
319
+ try {
320
+ const xml = `<save-subroutine name="${name}" format="xml" />`;
321
+ const ast = this.xmlParser.parse(xml);
322
+ await integrate(this.session, ast);
323
+ if (this.session.output.length > 0) {
324
+ console.log(this.session.output.join(""));
325
+ this.session.output = [];
326
+ }
327
+ } catch (error) {
328
+ console.error(`Error saving ${name}:`, error instanceof Error ? error.message : String(error));
329
+ }
330
+ }
331
+ resolve2(true);
332
+ } else if (choice === "n") {
333
+ resolve2(true);
334
+ } else {
335
+ console.log("\n(Exit canceled - returning to shell)\n");
336
+ resolve2(false);
337
+ }
338
+ });
339
+ });
340
+ }
341
+ countSubroutinesInAST(element) {
342
+ let count = 0;
343
+ if (element.tag === "subroutine") {
344
+ count = 1;
345
+ }
346
+ if (element.children) {
347
+ for (const child of element.children) {
348
+ count += this.countSubroutinesInAST(child);
349
+ }
350
+ }
351
+ return count;
352
+ }
353
+ finalizeExit() {
354
+ this.saveHistory();
355
+ if (this.client) {
356
+ this.client.disconnect();
357
+ }
358
+ import("./schedule-G6ZSSQ5W.js").then(({ stopAllScheduledTasks }) => {
359
+ stopAllScheduledTasks();
360
+ console.log("\nGoodbye!");
361
+ process.exit(0);
362
+ }).catch(() => {
363
+ console.log("\nGoodbye!");
364
+ process.exit(0);
365
+ });
366
+ }
274
367
  setupHandlers() {
275
368
  this.rl.on("line", async (input) => {
276
369
  await this.handleInput(input);
277
370
  });
278
- this.rl.on("close", () => {
279
- this.saveHistory();
280
- if (this.client) {
281
- this.client.disconnect();
371
+ this.rl.on("close", async () => {
372
+ const unsaved = this.getUnsavedSubroutines();
373
+ if (unsaved.length > 0) {
374
+ const shouldExit = await this.promptSaveUnsaved(unsaved);
375
+ if (shouldExit) {
376
+ this.finalizeExit();
377
+ } else {
378
+ this.rl = readline.createInterface({
379
+ input: process.stdin,
380
+ output: process.stdout,
381
+ prompt: "> ",
382
+ historySize: MAX_HISTORY,
383
+ completer: this.completer.bind(this)
384
+ });
385
+ this.setupHandlers();
386
+ this.rl.prompt();
387
+ }
388
+ } else {
389
+ this.finalizeExit();
282
390
  }
283
- import("./schedule-R7CRCLH6.js").then(({ stopAllScheduledTasks }) => {
284
- stopAllScheduledTasks();
285
- console.log("\nGoodbye!");
286
- process.exit(0);
287
- }).catch(() => {
288
- console.log("\nGoodbye!");
289
- process.exit(0);
290
- });
291
391
  });
292
392
  this.rl.on("SIGINT", () => {
293
393
  if (this.inputBuffer.length > 0) {
@@ -646,7 +746,7 @@ Examples:
646
746
  break;
647
747
  case "tasks":
648
748
  try {
649
- const { listScheduledTasks } = await import("./schedule-R7CRCLH6.js");
749
+ const { listScheduledTasks } = await import("./schedule-G6ZSSQ5W.js");
650
750
  const tasks = listScheduledTasks();
651
751
  if (tasks.length === 0) {
652
752
  console.log("No scheduled tasks running.");
@@ -665,7 +765,7 @@ Examples:
665
765
  console.log("Usage: :stop <task-name>");
666
766
  } else {
667
767
  try {
668
- const { stopScheduledTask } = await import("./schedule-R7CRCLH6.js");
768
+ const { stopScheduledTask } = await import("./schedule-G6ZSSQ5W.js");
669
769
  const taskName = args[0];
670
770
  const stopped = stopScheduledTask(taskName);
671
771
  if (stopped) {
@@ -680,7 +780,7 @@ Examples:
680
780
  break;
681
781
  case "stopall":
682
782
  try {
683
- const { stopAllScheduledTasks } = await import("./schedule-R7CRCLH6.js");
783
+ const { stopAllScheduledTasks } = await import("./schedule-G6ZSSQ5W.js");
684
784
  stopAllScheduledTasks();
685
785
  console.log("All scheduled tasks stopped.");
686
786
  } catch (error) {
@@ -689,7 +789,7 @@ Examples:
689
789
  break;
690
790
  case "crons":
691
791
  try {
692
- const { listCronJobs } = await import("./cron-36B7PK6H.js");
792
+ const { listCronJobs } = await import("./cron-GZ5XXDBY.js");
693
793
  const jobs = listCronJobs();
694
794
  if (jobs.length === 0) {
695
795
  console.log("No cron jobs running.");
@@ -709,7 +809,7 @@ Examples:
709
809
  console.log("Usage: :stopcron <job-name>");
710
810
  } else {
711
811
  try {
712
- const { stopCronJob } = await import("./cron-36B7PK6H.js");
812
+ const { stopCronJob } = await import("./cron-GZ5XXDBY.js");
713
813
  const jobName = args[0];
714
814
  const stopped = stopCronJob(jobName);
715
815
  if (stopped) {
@@ -724,7 +824,7 @@ Examples:
724
824
  break;
725
825
  case "stopallcrons":
726
826
  try {
727
- const { stopAllCronJobs } = await import("./cron-36B7PK6H.js");
827
+ const { stopAllCronJobs } = await import("./cron-GZ5XXDBY.js");
728
828
  stopAllCronJobs();
729
829
  console.log("All cron jobs stopped.");
730
830
  } catch (error) {
@@ -733,7 +833,7 @@ Examples:
733
833
  break;
734
834
  case "scheduled":
735
835
  try {
736
- const { listScheduledRuns } = await import("./run-at-SRHVN4IW.js");
836
+ const { listScheduledRuns } = await import("./run-at-ZYUWD64S.js");
737
837
  const runs = listScheduledRuns();
738
838
  if (runs.length === 0) {
739
839
  console.log("No scheduled runs pending.");
@@ -753,7 +853,7 @@ Examples:
753
853
  console.log("Usage: :cancel <run-name>");
754
854
  } else {
755
855
  try {
756
- const { cancelScheduledRun } = await import("./run-at-SRHVN4IW.js");
856
+ const { cancelScheduledRun } = await import("./run-at-ZYUWD64S.js");
757
857
  const runName = args[0];
758
858
  const cancelled = cancelScheduledRun(runName);
759
859
  if (cancelled) {
@@ -768,7 +868,7 @@ Examples:
768
868
  break;
769
869
  case "cancelall":
770
870
  try {
771
- const { cancelAllScheduledRuns } = await import("./run-at-SRHVN4IW.js");
871
+ const { cancelAllScheduledRuns } = await import("./run-at-ZYUWD64S.js");
772
872
  cancelAllScheduledRuns();
773
873
  console.log("All scheduled runs cancelled.");
774
874
  } catch (error) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  executeSubroutine
3
- } from "./chunk-NKA6ZJDV.js";
4
- import "./chunk-3UW6GWYQ.js";
3
+ } from "./chunk-VC23AJJJ.js";
4
+ import "./chunk-M57VI7KL.js";
5
5
  export {
6
6
  executeSubroutine
7
7
  };
@@ -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-AZIX6ILU.js");
52
+ const { getAvailableSubroutines } = await import("./session-OL5ARO6Q.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,14 +1,14 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-GAGWNYD4.js";
3
+ } from "./chunk-WW2OXQZN.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
7
- import "./chunk-NKA6ZJDV.js";
7
+ import "./chunk-VC23AJJJ.js";
8
8
  import {
9
9
  createSession,
10
10
  getOutput
11
- } from "./chunk-3UW6GWYQ.js";
11
+ } from "./chunk-M57VI7KL.js";
12
12
 
13
13
  // src/test-runner.ts
14
14
  import fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",