dirac-lang 0.1.20 → 0.1.21
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/{chunk-VA7VOLNV.js → chunk-JRNDLSQJ.js} +1 -1
- package/dist/{chunk-UXTK2GC2.js → chunk-OS7DII2I.js} +27 -13
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-X7EARER5.js → interpreter-WSRBK3KI.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/package.json +1 -1
- package/src/tags/system.ts +25 -2
- package/tests/system-background.test.di +39 -0
|
@@ -419,12 +419,12 @@ async function executeIf(session, element) {
|
|
|
419
419
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
420
420
|
if (condition) {
|
|
421
421
|
if (thenElement) {
|
|
422
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
422
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
423
423
|
await integrateChildren2(session, thenElement);
|
|
424
424
|
}
|
|
425
425
|
} else {
|
|
426
426
|
if (elseElement) {
|
|
427
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
427
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
428
428
|
await integrateChildren2(session, elseElement);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
@@ -437,7 +437,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
437
437
|
return await evaluateCondition(session, predicateElement);
|
|
438
438
|
}
|
|
439
439
|
const outputLengthBefore = session.output.length;
|
|
440
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
440
|
+
const { integrate: integrate2 } = await import("./interpreter-WSRBK3KI.js");
|
|
441
441
|
await integrate2(session, predicateElement);
|
|
442
442
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
443
443
|
const result = newOutputChunks.join("").trim();
|
|
@@ -460,11 +460,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
460
460
|
}
|
|
461
461
|
const outputLengthBefore = session.output.length;
|
|
462
462
|
const args = [];
|
|
463
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
463
|
+
const { integrate: integrate2 } = await import("./interpreter-WSRBK3KI.js");
|
|
464
464
|
for (const child of condElement.children) {
|
|
465
465
|
if (child.tag.toLowerCase() === "arg") {
|
|
466
466
|
const argOutputStart = session.output.length;
|
|
467
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
467
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
468
468
|
await integrateChildren2(session, child);
|
|
469
469
|
const newChunks = session.output.slice(argOutputStart);
|
|
470
470
|
const argValue = newChunks.join("");
|
|
@@ -1068,7 +1068,7 @@ async function executeExpr(session, element) {
|
|
|
1068
1068
|
}
|
|
1069
1069
|
|
|
1070
1070
|
// src/tags/system.ts
|
|
1071
|
-
import { exec } from "child_process";
|
|
1071
|
+
import { exec, spawn } from "child_process";
|
|
1072
1072
|
import { promisify } from "util";
|
|
1073
1073
|
var execAsync = promisify(exec);
|
|
1074
1074
|
async function executeSystem(session, element) {
|
|
@@ -1090,8 +1090,22 @@ async function executeSystem(session, element) {
|
|
|
1090
1090
|
if (!command.trim()) {
|
|
1091
1091
|
return;
|
|
1092
1092
|
}
|
|
1093
|
+
const backgroundAttr = element.attributes?.background;
|
|
1094
|
+
const isBackground = backgroundAttr === "true";
|
|
1093
1095
|
if (session.debug) {
|
|
1094
|
-
console.error(`[SYSTEM] Executing: ${command}`);
|
|
1096
|
+
console.error(`[SYSTEM] Executing${isBackground ? " (background)" : ""}: ${command}`);
|
|
1097
|
+
}
|
|
1098
|
+
if (isBackground) {
|
|
1099
|
+
const child = spawn(command, {
|
|
1100
|
+
detached: true,
|
|
1101
|
+
stdio: "ignore",
|
|
1102
|
+
shell: true
|
|
1103
|
+
});
|
|
1104
|
+
child.unref();
|
|
1105
|
+
if (session.debug) {
|
|
1106
|
+
console.error(`[SYSTEM] Background process started with PID: ${child.pid}`);
|
|
1107
|
+
}
|
|
1108
|
+
return;
|
|
1095
1109
|
}
|
|
1096
1110
|
try {
|
|
1097
1111
|
const { stdout, stderr } = await execAsync(command, {
|
|
@@ -1267,7 +1281,7 @@ async function executeTagCheck(session, element) {
|
|
|
1267
1281
|
const executeTag = correctedTag || tagName;
|
|
1268
1282
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1269
1283
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1270
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1284
|
+
const { integrate: integrate2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1271
1285
|
await integrate2(session, elementToExecute);
|
|
1272
1286
|
}
|
|
1273
1287
|
}
|
|
@@ -1276,7 +1290,7 @@ async function executeTagCheck(session, element) {
|
|
|
1276
1290
|
// src/tags/throw.ts
|
|
1277
1291
|
async function executeThrow(session, element) {
|
|
1278
1292
|
const exceptionName = element.attributes?.name || "exception";
|
|
1279
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1293
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1280
1294
|
const exceptionDom = {
|
|
1281
1295
|
tag: "exception-content",
|
|
1282
1296
|
attributes: { name: exceptionName },
|
|
@@ -1289,7 +1303,7 @@ async function executeThrow(session, element) {
|
|
|
1289
1303
|
// src/tags/try.ts
|
|
1290
1304
|
async function executeTry(session, element) {
|
|
1291
1305
|
setExceptionBoundary(session);
|
|
1292
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1306
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1293
1307
|
await integrateChildren2(session, element);
|
|
1294
1308
|
unsetExceptionBoundary(session);
|
|
1295
1309
|
}
|
|
@@ -1299,7 +1313,7 @@ async function executeCatch(session, element) {
|
|
|
1299
1313
|
const exceptionName = element.attributes?.name || "exception";
|
|
1300
1314
|
const caughtCount = lookupException(session, exceptionName);
|
|
1301
1315
|
if (caughtCount > 0) {
|
|
1302
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1316
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1303
1317
|
await integrateChildren2(session, element);
|
|
1304
1318
|
}
|
|
1305
1319
|
flushCurrentException(session);
|
|
@@ -1308,7 +1322,7 @@ async function executeCatch(session, element) {
|
|
|
1308
1322
|
// src/tags/exception.ts
|
|
1309
1323
|
async function executeException(session, element) {
|
|
1310
1324
|
const exceptions = getCurrentExceptions(session);
|
|
1311
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1325
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1312
1326
|
for (const exceptionDom of exceptions) {
|
|
1313
1327
|
await integrateChildren2(session, exceptionDom);
|
|
1314
1328
|
}
|
|
@@ -1448,7 +1462,7 @@ async function executeForeach(session, element) {
|
|
|
1448
1462
|
const parser2 = new DiracParser2();
|
|
1449
1463
|
try {
|
|
1450
1464
|
const fromElement = parser2.parse(fromAttr);
|
|
1451
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1465
|
+
const { integrate: integrate2 } = await import("./interpreter-WSRBK3KI.js");
|
|
1452
1466
|
await integrate2(session, fromElement);
|
|
1453
1467
|
} catch (e) {
|
|
1454
1468
|
session.output = savedOutput;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-JRNDLSQJ.js";
|
|
5
|
+
import "./chunk-OS7DII2I.js";
|
|
6
6
|
import "./chunk-HRHAMPOB.js";
|
|
7
7
|
import "./chunk-E7PWEMZA.js";
|
|
8
8
|
import "./chunk-52ED23DR.js";
|
|
@@ -13,7 +13,7 @@ import "dotenv/config";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "dirac-lang",
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.21",
|
|
17
17
|
description: "LLM-Augmented Declarative Execution",
|
|
18
18
|
type: "module",
|
|
19
19
|
main: "dist/index.js",
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-JRNDLSQJ.js";
|
|
6
6
|
import {
|
|
7
7
|
integrate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OS7DII2I.js";
|
|
9
9
|
import {
|
|
10
10
|
DiracParser
|
|
11
11
|
} from "./chunk-HRHAMPOB.js";
|
package/dist/test-runner.js
CHANGED
package/package.json
CHANGED
package/src/tags/system.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { DiracSession, DiracElement } from '../types/index.js';
|
|
7
7
|
import { substituteVariables, emit } from '../runtime/session.js';
|
|
8
|
-
import { exec } from 'child_process';
|
|
8
|
+
import { exec, spawn } from 'child_process';
|
|
9
9
|
import { promisify } from 'util';
|
|
10
10
|
import { integrate } from '../runtime/interpreter.js';
|
|
11
11
|
|
|
@@ -43,10 +43,33 @@ export async function executeSystem(session: DiracSession, element: DiracElement
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// Check for background attribute
|
|
47
|
+
const backgroundAttr = element.attributes?.background;
|
|
48
|
+
const isBackground = backgroundAttr === 'true';
|
|
49
|
+
|
|
46
50
|
if (session.debug) {
|
|
47
|
-
console.error(`[SYSTEM] Executing: ${command}`);
|
|
51
|
+
console.error(`[SYSTEM] Executing${isBackground ? ' (background)' : ''}: ${command}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Background mode - spawn and don't wait
|
|
55
|
+
if (isBackground) {
|
|
56
|
+
const child = spawn(command, {
|
|
57
|
+
detached: true,
|
|
58
|
+
stdio: 'ignore',
|
|
59
|
+
shell: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Unref so parent can exit without waiting
|
|
63
|
+
child.unref();
|
|
64
|
+
|
|
65
|
+
if (session.debug) {
|
|
66
|
+
console.error(`[SYSTEM] Background process started with PID: ${child.pid}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return;
|
|
48
70
|
}
|
|
49
71
|
|
|
72
|
+
// Foreground mode - wait for completion (original behavior)
|
|
50
73
|
try {
|
|
51
74
|
const { stdout, stderr } = await execAsync(command, {
|
|
52
75
|
encoding: 'utf-8',
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<output>Testing background processes with loop...</output>
|
|
3
|
+
|
|
4
|
+
<!-- Setup: Clean up old test files -->
|
|
5
|
+
<system>rm -f /tmp/dirac-bg-counter.txt</system>
|
|
6
|
+
|
|
7
|
+
<!-- Start a background process that writes incrementing numbers -->
|
|
8
|
+
<system background="true">(for i in 1 2 3 4 5; do echo "Count: $i"; sleep 1; done > /tmp/dirac-bg-counter.txt) &</system>
|
|
9
|
+
<output>✓ Background counter started</output>
|
|
10
|
+
|
|
11
|
+
<!-- This executes immediately without waiting -->
|
|
12
|
+
<output>✓ DIRAC continuing without blocking</output>
|
|
13
|
+
|
|
14
|
+
<!-- Wait a moment for background process to start writing -->
|
|
15
|
+
<system>sleep 2</system>
|
|
16
|
+
|
|
17
|
+
<!-- Read the results in a loop (3 times, showing progressive output) -->
|
|
18
|
+
<loop count="3">
|
|
19
|
+
<system>wc -l /tmp/dirac-bg-counter.txt 2>/dev/null || echo "0"</system>
|
|
20
|
+
<output>Check: Background file now has lines</output>
|
|
21
|
+
<system>sleep 1</system>
|
|
22
|
+
</loop>
|
|
23
|
+
|
|
24
|
+
<!-- Give background process time to finish all 5 counts -->
|
|
25
|
+
<system>sleep 2</system>
|
|
26
|
+
|
|
27
|
+
<!-- Verify final result contains all 5 counts -->
|
|
28
|
+
<system>wc -l /tmp/dirac-bg-counter.txt</system>
|
|
29
|
+
<output>✓ Background process completed</output>
|
|
30
|
+
|
|
31
|
+
<!-- Verify content -->
|
|
32
|
+
<system>grep -c "Count:" /tmp/dirac-bg-counter.txt</system>
|
|
33
|
+
<output>✓ Found all count entries</output>
|
|
34
|
+
|
|
35
|
+
<!-- Cleanup -->
|
|
36
|
+
<system>rm -f /tmp/dirac-bg-counter.txt</system>
|
|
37
|
+
|
|
38
|
+
<output>✓ Background process with loop test passed</output>
|
|
39
|
+
</dirac>
|