dirac-lang 0.1.15 → 0.1.16

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.
@@ -0,0 +1,5 @@
1
+ # Test configuration for verifying embedding config works
2
+ embeddingServer:
3
+ host: localhost
4
+ port: 11434
5
+ model: nomic-embed-text # Different model to test config loading
@@ -396,12 +396,12 @@ async function executeIf(session, element) {
396
396
  const condition = await evaluatePredicate(session, conditionElement);
397
397
  if (condition) {
398
398
  if (thenElement) {
399
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
399
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
400
400
  await integrateChildren2(session, thenElement);
401
401
  }
402
402
  } else {
403
403
  if (elseElement) {
404
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
404
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
405
405
  await integrateChildren2(session, elseElement);
406
406
  }
407
407
  }
@@ -414,7 +414,7 @@ async function evaluatePredicate(session, predicateElement) {
414
414
  return await evaluateCondition(session, predicateElement);
415
415
  }
416
416
  const outputLengthBefore = session.output.length;
417
- const { integrate: integrate2 } = await import("./interpreter-SE5I5ROB.js");
417
+ const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
418
418
  await integrate2(session, predicateElement);
419
419
  const newOutputChunks = session.output.slice(outputLengthBefore);
420
420
  const result = newOutputChunks.join("").trim();
@@ -437,11 +437,11 @@ async function evaluateCondition(session, condElement) {
437
437
  }
438
438
  const outputLengthBefore = session.output.length;
439
439
  const args = [];
440
- const { integrate: integrate2 } = await import("./interpreter-SE5I5ROB.js");
440
+ const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
441
441
  for (const child of condElement.children) {
442
442
  if (child.tag.toLowerCase() === "arg") {
443
443
  const argOutputStart = session.output.length;
444
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
444
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
445
445
  await integrateChildren2(session, child);
446
446
  const newChunks = session.output.slice(argOutputStart);
447
447
  const argValue = newChunks.join("");
@@ -677,7 +677,7 @@ ${result}
677
677
  const parser = new DiracParser();
678
678
  let dynamicAST = parser.parse(diracCode);
679
679
  if (validateTags) {
680
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-DYWFTEBE.js");
680
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-CLYGULLQ.js");
681
681
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
682
682
  let retryCount = 0;
683
683
  while (!validation.valid && retryCount < maxRetries) {
@@ -1106,18 +1106,24 @@ import fs from "fs";
1106
1106
  import yaml from "js-yaml";
1107
1107
  var SIMILARITY_CUTOFF = 0.75;
1108
1108
  function getEmbeddingServerConfig() {
1109
- const config = yaml.load(fs.readFileSync("config.yml", "utf8"));
1110
- const host = config.embeddingServer?.host || "localhost";
1111
- const port = config.embeddingServer?.port || 11435;
1112
- return { host, port };
1109
+ try {
1110
+ const configPath = process.env.DIRAC_CONFIG || "config.yml";
1111
+ const config = yaml.load(fs.readFileSync(configPath, "utf8"));
1112
+ const host = config.embeddingServer?.host || "localhost";
1113
+ const port = config.embeddingServer?.port || 11434;
1114
+ const model = config.embeddingServer?.model || "embeddinggemma";
1115
+ return { host, port, model };
1116
+ } catch (e) {
1117
+ return { host: "localhost", port: 11434, model: "embeddinggemma" };
1118
+ }
1113
1119
  }
1114
1120
  async function getEmbeddings(tags) {
1115
- const { host, port } = getEmbeddingServerConfig();
1121
+ const { host, port, model } = getEmbeddingServerConfig();
1116
1122
  return await Promise.all(tags.map(async (tag) => {
1117
1123
  const response = await fetch(`http://${host}:${port}/api/embeddings`, {
1118
1124
  method: "POST",
1119
1125
  headers: { "Content-Type": "application/json" },
1120
- body: JSON.stringify({ model: "embeddinggemma", prompt: tag })
1126
+ body: JSON.stringify({ model, prompt: tag })
1121
1127
  });
1122
1128
  const data = await response.json();
1123
1129
  return data.embedding;
@@ -1153,6 +1159,9 @@ async function executeTagCheck(session, element) {
1153
1159
  const shouldExecute = element.attributes?.execute === "true";
1154
1160
  for (const child of element.children) {
1155
1161
  const tagName = child.tag;
1162
+ if (!tagName || tagName.trim() === "") {
1163
+ continue;
1164
+ }
1156
1165
  console.error(`[tag-check] Checking tag: <${tagName}>`);
1157
1166
  let allValid = false;
1158
1167
  let correctedTag = null;
@@ -1235,7 +1244,7 @@ async function executeTagCheck(session, element) {
1235
1244
  const executeTag = correctedTag || tagName;
1236
1245
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1237
1246
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1238
- const { integrate: integrate2 } = await import("./interpreter-SE5I5ROB.js");
1247
+ const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
1239
1248
  await integrate2(session, elementToExecute);
1240
1249
  }
1241
1250
  }
@@ -1244,7 +1253,7 @@ async function executeTagCheck(session, element) {
1244
1253
  // src/tags/throw.ts
1245
1254
  async function executeThrow(session, element) {
1246
1255
  const exceptionName = element.attributes?.name || "exception";
1247
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
1256
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1248
1257
  const exceptionDom = {
1249
1258
  tag: "exception-content",
1250
1259
  attributes: { name: exceptionName },
@@ -1257,7 +1266,7 @@ async function executeThrow(session, element) {
1257
1266
  // src/tags/try.ts
1258
1267
  async function executeTry(session, element) {
1259
1268
  setExceptionBoundary(session);
1260
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
1269
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1261
1270
  await integrateChildren2(session, element);
1262
1271
  unsetExceptionBoundary(session);
1263
1272
  }
@@ -1267,7 +1276,7 @@ async function executeCatch(session, element) {
1267
1276
  const exceptionName = element.attributes?.name || "exception";
1268
1277
  const caughtCount = lookupException(session, exceptionName);
1269
1278
  if (caughtCount > 0) {
1270
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
1279
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1271
1280
  await integrateChildren2(session, element);
1272
1281
  }
1273
1282
  flushCurrentException(session);
@@ -1276,7 +1285,7 @@ async function executeCatch(session, element) {
1276
1285
  // src/tags/exception.ts
1277
1286
  async function executeException(session, element) {
1278
1287
  const exceptions = getCurrentExceptions(session);
1279
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-SE5I5ROB.js");
1288
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-GNO4J3HN.js");
1280
1289
  for (const exceptionDom of exceptions) {
1281
1290
  await integrateChildren2(session, exceptionDom);
1282
1291
  }
@@ -1416,7 +1425,7 @@ async function executeForeach(session, element) {
1416
1425
  const parser2 = new DiracParser2();
1417
1426
  try {
1418
1427
  const fromElement = parser2.parse(fromAttr);
1419
- const { integrate: integrate2 } = await import("./interpreter-SE5I5ROB.js");
1428
+ const { integrate: integrate2 } = await import("./interpreter-GNO4J3HN.js");
1420
1429
  await integrate2(session, fromElement);
1421
1430
  } catch (e) {
1422
1431
  session.output = savedOutput;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-74EQEVS6.js";
3
+ } from "./chunk-CP4YCRBG.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execute
4
- } from "./chunk-UO6QEXZV.js";
5
- import "./chunk-74EQEVS6.js";
4
+ } from "./chunk-FEOBVBSI.js";
5
+ import "./chunk-CP4YCRBG.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.15",
16
+ version: "0.1.16",
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-UO6QEXZV.js";
5
+ } from "./chunk-FEOBVBSI.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-74EQEVS6.js";
8
+ } from "./chunk-CP4YCRBG.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-74EQEVS6.js";
4
+ } from "./chunk-CP4YCRBG.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
6
  import "./chunk-E7PWEMZA.js";
7
7
  import "./chunk-52ED23DR.js";
@@ -4,21 +4,23 @@ import yaml from "js-yaml";
4
4
  var SIMILARITY_CUTOFF = 0.75;
5
5
  function getEmbeddingServerConfig() {
6
6
  try {
7
- const config = yaml.load(fs.readFileSync("config.yml", "utf8"));
7
+ const configPath = process.env.DIRAC_CONFIG || "config.yml";
8
+ const config = yaml.load(fs.readFileSync(configPath, "utf8"));
8
9
  const host = config.embeddingServer?.host || "localhost";
9
- const port = config.embeddingServer?.port || 11435;
10
- return { host, port };
11
- } catch {
12
- return { host: "localhost", port: 11435 };
10
+ const port = config.embeddingServer?.port || 11434;
11
+ const model = config.embeddingServer?.model || "embeddinggemma";
12
+ return { host, port, model };
13
+ } catch (e) {
14
+ return { host: "localhost", port: 11434, model: "embeddinggemma" };
13
15
  }
14
16
  }
15
17
  async function getEmbeddings(tags) {
16
- const { host, port } = getEmbeddingServerConfig();
18
+ const { host, port, model } = getEmbeddingServerConfig();
17
19
  return await Promise.all(tags.map(async (tag) => {
18
20
  const response = await fetch(`http://${host}:${port}/api/embeddings`, {
19
21
  method: "POST",
20
22
  headers: { "Content-Type": "application/json" },
21
- body: JSON.stringify({ model: "embeddinggemma", prompt: tag })
23
+ body: JSON.stringify({ model, prompt: tag })
22
24
  });
23
25
  const data = await response.json();
24
26
  return data.embedding;
@@ -111,7 +113,7 @@ async function validateDiracCode(session, ast, options = {}) {
111
113
  const results = [];
112
114
  const errorMessages = [];
113
115
  async function validateElement(element) {
114
- if (element.tag && element.tag !== "dirac" && element.tag !== "") {
116
+ if (element.tag && element.tag !== "dirac" && element.tag.trim() !== "") {
115
117
  const result = await validateTag(session, element, options);
116
118
  results.push(result);
117
119
  if (!result.valid) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-74EQEVS6.js";
3
+ } from "./chunk-CP4YCRBG.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -19,9 +19,8 @@ var TestRunner = class {
19
19
  config;
20
20
  constructor(testDir = "tests", configPath) {
21
21
  this.testDir = testDir;
22
- const defaultConfigPath = configPath || path.resolve(process.cwd(), "config.yml");
23
- if (fs.existsSync(defaultConfigPath)) {
24
- this.config = yaml.load(fs.readFileSync(defaultConfigPath, "utf8")) || {};
22
+ if (configPath && fs.existsSync(configPath)) {
23
+ this.config = yaml.load(fs.readFileSync(configPath, "utf8")) || {};
25
24
  } else {
26
25
  this.config = { llmProvider: "ollama", llmModel: "llama2" };
27
26
  }
@@ -0,0 +1,6 @@
1
+ <dirac>
2
+ <subroutine name="background" description="set the background color." param-color="string:required:color name" >
3
+ this is my color: <variable name="color" />
4
+ </subroutine>
5
+ <llm execute="true">what is the color of red mix with yellow and set the background color to that color</llm>
6
+ </dirac>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,20 +15,27 @@ const SIMILARITY_CUTOFF = 0.75;
15
15
 
16
16
  // Helper: get embedding server config from config.yml
17
17
  function getEmbeddingServerConfig() {
18
- const config = yaml.load(fs.readFileSync('config.yml', 'utf8')) as any;
19
- const host = config.embeddingServer?.host || 'localhost';
20
- const port = config.embeddingServer?.port || 11435;
21
- return { host, port };
18
+ try {
19
+ const configPath = process.env.DIRAC_CONFIG || 'config.yml';
20
+ const config = yaml.load(fs.readFileSync(configPath, 'utf8')) as any;
21
+ const host = config.embeddingServer?.host || 'localhost';
22
+ const port = config.embeddingServer?.port || 11434;
23
+ const model = config.embeddingServer?.model || 'embeddinggemma';
24
+ return { host, port, model };
25
+ } catch (e) {
26
+ // Fallback to defaults if config file not found
27
+ return { host: 'localhost', port: 11434, model: 'embeddinggemma' };
28
+ }
22
29
  }
23
30
 
24
31
  // Helper: call Ollama embedding API directly
25
32
  async function getEmbeddings(tags: string[]): Promise<number[][]> {
26
- const { host, port } = getEmbeddingServerConfig();
33
+ const { host, port, model } = getEmbeddingServerConfig();
27
34
  return await Promise.all(tags.map(async tag => {
28
35
  const response = await fetch(`http://${host}:${port}/api/embeddings`, {
29
36
  method: 'POST',
30
37
  headers: { 'Content-Type': 'application/json' },
31
- body: JSON.stringify({ model: 'embeddinggemma', prompt: tag })
38
+ body: JSON.stringify({ model, prompt: tag })
32
39
  });
33
40
  const data = await response.json();
34
41
  return data.embedding;
@@ -67,6 +74,12 @@ export async function executeTagCheck(session: DiracSession, element: DiracEleme
67
74
 
68
75
  for (const child of element.children) {
69
76
  const tagName = child.tag;
77
+
78
+ // Skip text nodes (empty tag names) and whitespace
79
+ if (!tagName || tagName.trim() === '') {
80
+ continue;
81
+ }
82
+
70
83
  console.error(`[tag-check] Checking tag: <${tagName}>`);
71
84
  let allValid = false;
72
85
  let correctedTag: string | null = null;
@@ -33,10 +33,10 @@ export class TestRunner {
33
33
  constructor(testDir: string = 'tests', configPath?: string) {
34
34
  this.testDir = testDir;
35
35
 
36
- // Load default config
37
- const defaultConfigPath = configPath || path.resolve(process.cwd(), 'config.yml');
38
- if (fs.existsSync(defaultConfigPath)) {
39
- this.config = yaml.load(fs.readFileSync(defaultConfigPath, 'utf8')) || {};
36
+ // For tests, always use ollama as the default provider (no API keys needed)
37
+ // Unless a specific test config is provided
38
+ if (configPath && fs.existsSync(configPath)) {
39
+ this.config = yaml.load(fs.readFileSync(configPath, 'utf8')) || {};
40
40
  } else {
41
41
  this.config = { llmProvider: 'ollama', llmModel: 'llama2' };
42
42
  }
@@ -23,23 +23,26 @@ export interface ValidationResult {
23
23
  // Helper: get embedding server config from config.yml
24
24
  function getEmbeddingServerConfig() {
25
25
  try {
26
- const config = yaml.load(fs.readFileSync('config.yml', 'utf8')) as any;
26
+ const configPath = process.env.DIRAC_CONFIG || 'config.yml';
27
+ const config = yaml.load(fs.readFileSync(configPath, 'utf8')) as any;
27
28
  const host = config.embeddingServer?.host || 'localhost';
28
- const port = config.embeddingServer?.port || 11435;
29
- return { host, port };
30
- } catch {
31
- return { host: 'localhost', port: 11435 };
29
+ const port = config.embeddingServer?.port || 11434;
30
+ const model = config.embeddingServer?.model || 'embeddinggemma';
31
+ return { host, port, model };
32
+ } catch (e) {
33
+ // Fallback to defaults if config file not found
34
+ return { host: 'localhost', port: 11434, model: 'embeddinggemma' };
32
35
  }
33
36
  }
34
37
 
35
38
  // Helper: call Ollama embedding API directly
36
39
  async function getEmbeddings(tags: string[]): Promise<number[][]> {
37
- const { host, port } = getEmbeddingServerConfig();
40
+ const { host, port, model } = getEmbeddingServerConfig();
38
41
  return await Promise.all(tags.map(async tag => {
39
42
  const response = await fetch(`http://${host}:${port}/api/embeddings`, {
40
43
  method: 'POST',
41
44
  headers: { 'Content-Type': 'application/json' },
42
- body: JSON.stringify({ model: 'embeddinggemma', prompt: tag })
45
+ body: JSON.stringify({ model, prompt: tag })
43
46
  });
44
47
  const data = await response.json();
45
48
  return data.embedding;
@@ -179,7 +182,8 @@ export async function validateDiracCode(
179
182
 
180
183
  // Recursively validate all elements
181
184
  async function validateElement(element: DiracElement) {
182
- if (element.tag && element.tag !== 'dirac' && element.tag !== '') {
185
+ // Skip text nodes and whitespace-only tags
186
+ if (element.tag && element.tag !== 'dirac' && element.tag.trim() !== '') {
183
187
  const result = await validateTag(session, element, options);
184
188
  results.push(result);
185
189
 
@@ -0,0 +1,27 @@
1
+ <!-- TEST: tag_check_autocorrect -->
2
+ <!-- EXPECT: The tag <background-set> was auto-corrected to <background> (similarity: 0.84)
3
+ Color changed to: red -->
4
+
5
+ <dirac>
6
+ <subroutine name="background"
7
+ description="Change the background color"
8
+ param-color="string:required:Background color:red|blue|green">
9
+ <parameters select="@color"/>
10
+ <output>Color changed to: <variable name="color" /></output>
11
+ </subroutine>
12
+
13
+ <subroutine name="foreground"
14
+ description="Change the foreground text color"
15
+ param-color="string:required:Text color:black|white|gray">
16
+ <parameters select="@color"/>
17
+ <output>Text color changed to: <variable name="color" /></output>
18
+ </subroutine>
19
+
20
+ <!-- Test: tag-check should auto-correct similar tag names and execute -->
21
+ <defvar name="result" trim="true">
22
+ <tag-check execute="true" autocorrect="true">
23
+ <background-set color="red" />
24
+ </tag-check>
25
+ </defvar>
26
+ <output><variable name="result" /></output>
27
+ </dirac>
package/config.yml DELETED
@@ -1,9 +0,0 @@
1
- # Dirac server configuration
2
- llmProvider: ollama
3
- llmModel: llama3.2:3b
4
-
5
- embeddingServer:
6
- host: "localhost"
7
- port: 11434
8
-
9
- MONGODB_URI: "mongodb://localhost:27017"
package/config.yml.bak DELETED
@@ -1,8 +0,0 @@
1
- # Dirac server configuration
2
- #llmProvider: ollama
3
- #llmModel: llama2
4
- llmProvider: OpenAI
5
- llmModel:gpt-4.1-2025-04-14
6
- # Add other config options as needed
7
-
8
- MONGODB_URI: "mongodb://localhost:27017"
package/config.yml.ollama DELETED
@@ -1,6 +0,0 @@
1
- # Dirac server configuration
2
- llmProvider: ollama
3
- llmModel: llama2
4
- # Add other config options as needed
5
-
6
- MONGODB_URI: "mongodb://localhost:27017"
package/config.yml.openai DELETED
@@ -1,6 +0,0 @@
1
- # Dirac server configuration
2
- llmProvider: openai
3
- llmModel: gpt-4.1-2025-04-14
4
- # Add other config options as needed
5
-
6
- MONGODB_URI: "mongodb://localhost:27017"