@o-lang/olang 1.0.10 → 1.0.12

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.
Files changed (3) hide show
  1. package/cli.js +12 -0
  2. package/package.json +1 -1
  3. package/src/parser.js +30 -26
package/cli.js CHANGED
@@ -68,6 +68,8 @@ async function builtInMathResolver(action, context) {
68
68
 
69
69
  return null;
70
70
  }
71
+ // Add resolver metadata so workflow policy recognizes it
72
+ builtInMathResolver.resolverName = 'builtInMathResolver';
71
73
 
72
74
  /**
73
75
  * Resolver chaining with verbose + context logging
@@ -164,7 +166,17 @@ program
164
166
  const content = fs.readFileSync(file, 'utf8');
165
167
  const workflow = parse(content);
166
168
 
169
+ if (!workflow || typeof workflow !== 'object') {
170
+ console.error('❌ Error: Parsed workflow is invalid or empty');
171
+ process.exit(1);
172
+ }
173
+
174
+ if (options.verbose) {
175
+ console.log('📄 Parsed Workflow:', JSON.stringify(workflow, null, 2));
176
+ }
177
+
167
178
  const resolver = loadResolverChain(options.resolver, options.verbose);
179
+
168
180
  const result = await execute(workflow, options.input, resolver, options.verbose);
169
181
 
170
182
  console.log('\n=== Workflow Result ===');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/olang",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "author": "Olalekan Ogundipe <info@workfily.com>",
5
5
  "description": "O-Lang: A governance language for user-directed, rule-enforced agent workflows",
6
6
  "main": "./src/index.js",
package/src/parser.js CHANGED
@@ -1,7 +1,6 @@
1
1
  // src/parser.js
2
2
 
3
3
  function parse(code, fileName = null) {
4
- // --- Enforce .ol extension if filename provided ---
5
4
  if (fileName && !fileName.endsWith(".ol")) {
6
5
  throw new Error(`Expected .ol workflow, got: ${fileName}`);
7
6
  }
@@ -19,7 +18,6 @@ function parse(code, fileName = null) {
19
18
  returnValues: [],
20
19
  allowedResolvers: [],
21
20
 
22
- // --- NEW: formal resolver policy ---
23
21
  resolverPolicy: {
24
22
  declared: [],
25
23
  autoInjected: [],
@@ -27,10 +25,7 @@ function parse(code, fileName = null) {
27
25
  warnings: []
28
26
  },
29
27
 
30
- // --- NEW: parser warnings (non-fatal) ---
31
28
  __warnings: [],
32
-
33
- // --- NEW: feature detection flags ---
34
29
  __requiresMath: false
35
30
  };
36
31
 
@@ -39,9 +34,6 @@ function parse(code, fileName = null) {
39
34
  while (i < lines.length) {
40
35
  let line = lines[i];
41
36
 
42
- // ---------------------------
43
- // Resolver policy declaration
44
- // ---------------------------
45
37
  const allowMatch = line.match(/^Allow resolvers\s*:\s*$/i);
46
38
  if (allowMatch) {
47
39
  i++;
@@ -56,9 +48,6 @@ function parse(code, fileName = null) {
56
48
  continue;
57
49
  }
58
50
 
59
- // ============================
60
- // Math operations (detected)
61
- // ============================
62
51
  let mathAdd = line.match(/^Add\s+\{(.+?)\}\s+and\s+\{(.+?)\}\s+Save as\s+(.+)$/i);
63
52
  if (mathAdd) {
64
53
  workflow.__requiresMath = true;
@@ -107,9 +96,6 @@ function parse(code, fileName = null) {
107
96
  continue;
108
97
  }
109
98
 
110
- // ---------------------------
111
- // Workflow definition
112
- // ---------------------------
113
99
  const wfMatch = line.match(/^Workflow\s+"([^"]+)"(?:\s+with\s+(.+))?/i);
114
100
  if (wfMatch) {
115
101
  workflow.name = wfMatch[1];
@@ -121,24 +107,50 @@ function parse(code, fileName = null) {
121
107
  }
122
108
 
123
109
  // ---------------------------
124
- // Steps
110
+ // Return statement (smart math detection)
111
+ // ---------------------------
112
+ const returnMatch = line.match(/^Return\s+(.+)$/i);
113
+ if (returnMatch) {
114
+ workflow.returnValues = returnMatch[1].split(',').map(v => v.trim());
115
+ workflow.returnValues.forEach(v => {
116
+ if (v.match(/[A-Z][A-Za-z0-9_]*/)) workflow.__requiresMath = true;
117
+ });
118
+ i++;
119
+ continue;
120
+ }
121
+
122
+ // ---------------------------
123
+ // Steps (smart math detection)
125
124
  // ---------------------------
126
125
  const stepMatch = line.match(/^Step\s+(\d+)\s*:\s*(.+)$/i);
127
126
  if (stepMatch) {
128
- workflow.steps.push({
127
+ const step = {
129
128
  type: 'action',
130
129
  stepNumber: parseInt(stepMatch[1], 10),
131
130
  actionRaw: stepMatch[2].trim(),
132
131
  saveAs: null,
133
132
  constraints: {}
134
- });
133
+ };
134
+
135
+ workflow.steps.push(step);
136
+
137
+ if (step.actionRaw.match(/\{[A-Za-z_][A-Za-z0-9_]*\}/)) {
138
+ workflow.__requiresMath = true;
139
+ }
140
+
135
141
  i++;
136
142
  continue;
137
143
  }
138
144
 
139
145
  const saveMatch = line.match(/^Save as\s+(.+)$/i);
140
146
  if (saveMatch && workflow.steps.length > 0) {
141
- workflow.steps[workflow.steps.length - 1].saveAs = saveMatch[1].trim();
147
+ const lastStep = workflow.steps[workflow.steps.length - 1];
148
+ lastStep.saveAs = saveMatch[1].trim();
149
+
150
+ if (lastStep.saveAs.match(/[A-Z][A-Za-z0-9_]*/)) {
151
+ workflow.__requiresMath = true;
152
+ }
153
+
142
154
  i++;
143
155
  continue;
144
156
  }
@@ -169,26 +181,18 @@ function parse(code, fileName = null) {
169
181
  continue;
170
182
  }
171
183
 
172
- // ---------------------------
173
- // (ALL remaining blocks unchanged)
174
- // If, Parallel, Connect, Agent, Debrief, Evolve,
175
- // Prompt, Persist, Emit, Return, Use, Ask
176
- // ---------------------------
177
-
178
184
  i++;
179
185
  }
180
186
 
181
187
  // ============================
182
188
  // LINT & POLICY FINALIZATION
183
189
  // ============================
184
-
185
190
  if (workflow.__requiresMath) {
186
191
  workflow.resolverPolicy.used.push('builtInMathResolver');
187
192
 
188
193
  if (!workflow.resolverPolicy.declared.includes('builtInMathResolver')) {
189
194
  workflow.resolverPolicy.autoInjected.push('builtInMathResolver');
190
195
  workflow.allowedResolvers.unshift('builtInMathResolver');
191
-
192
196
  workflow.__warnings.push(
193
197
  'Math operations detected. builtInMathResolver auto-injected.'
194
198
  );