@aexol/spectral 0.9.221 → 0.9.223

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 (166) hide show
  1. package/dist/agent/index.d.ts +20 -3
  2. package/dist/agent/index.d.ts.map +1 -1
  3. package/dist/agent/index.js +286 -80
  4. package/dist/extensions/aexol-backend-client.d.ts +85 -0
  5. package/dist/extensions/aexol-backend-client.d.ts.map +1 -0
  6. package/dist/extensions/aexol-backend-client.js +159 -0
  7. package/dist/extensions/aexol-mcp.d.ts +10 -6
  8. package/dist/extensions/aexol-mcp.d.ts.map +1 -1
  9. package/dist/extensions/aexol-mcp.js +21 -106
  10. package/dist/extensions/logic-trace-backend-draft.d.ts +68 -0
  11. package/dist/extensions/logic-trace-backend-draft.d.ts.map +1 -0
  12. package/dist/extensions/logic-trace-backend-draft.js +171 -0
  13. package/dist/extensions/logic-trace-validate.d.ts +33 -0
  14. package/dist/extensions/logic-trace-validate.d.ts.map +1 -0
  15. package/dist/extensions/logic-trace-validate.js +73 -0
  16. package/dist/extensions/logic-trace.d.ts +213 -0
  17. package/dist/extensions/logic-trace.d.ts.map +1 -0
  18. package/dist/extensions/logic-trace.js +1098 -0
  19. package/dist/generated/parser/lexer.d.ts +148 -0
  20. package/dist/generated/parser/lexer.d.ts.map +1 -0
  21. package/dist/generated/parser/lexer.js +877 -0
  22. package/dist/generated/parser/mod.d.ts +26 -0
  23. package/dist/generated/parser/mod.d.ts.map +1 -0
  24. package/dist/generated/parser/mod.js +30 -0
  25. package/dist/generated/parser/parser.d.ts +161 -0
  26. package/dist/generated/parser/parser.d.ts.map +1 -0
  27. package/dist/generated/parser/parser.js +754 -0
  28. package/dist/generated/parser/tokenizer.d.ts +107 -0
  29. package/dist/generated/parser/tokenizer.d.ts.map +1 -0
  30. package/dist/generated/parser/tokenizer.js +202 -0
  31. package/dist/generated/parser/validator.d.ts +45 -0
  32. package/dist/generated/parser/validator.d.ts.map +1 -0
  33. package/dist/generated/parser/validator.js +202 -0
  34. package/dist/generated/zeus/const.d.ts.map +1 -1
  35. package/dist/generated/zeus/const.js +4 -170
  36. package/dist/generated/zeus/index.d.ts +8 -873
  37. package/dist/generated/zeus/index.d.ts.map +1 -1
  38. package/dist/generated/zeus/index.js +0 -7
  39. package/dist/mcp/ui-stream-types.d.ts +2 -2
  40. package/dist/memory/tools/share-project-observation.js +1 -1
  41. package/dist/memory/tools/write-project-observation.d.ts.map +1 -1
  42. package/dist/memory/tools/write-project-observation.js +4 -3
  43. package/dist/sdk/agent-core/agent-loop.d.ts.map +1 -1
  44. package/dist/sdk/agent-core/agent-loop.js +2 -4
  45. package/dist/sdk/agent-core/harness/types.d.ts +0 -1
  46. package/dist/sdk/agent-core/harness/types.d.ts.map +1 -1
  47. package/dist/sdk/agent-core/index.d.ts +0 -8
  48. package/dist/sdk/agent-core/index.d.ts.map +1 -1
  49. package/dist/sdk/agent-core/index.js +0 -9
  50. package/dist/sdk/ai/index.d.ts +1 -0
  51. package/dist/sdk/ai/index.d.ts.map +1 -1
  52. package/dist/sdk/ai/index.js +1 -0
  53. package/dist/sdk/ai/utils/transient-error.d.ts +28 -0
  54. package/dist/sdk/ai/utils/transient-error.d.ts.map +1 -0
  55. package/dist/sdk/ai/utils/transient-error.js +55 -0
  56. package/dist/sdk/coding-agent/core/agent-session.d.ts.map +1 -1
  57. package/dist/sdk/coding-agent/core/agent-session.js +7 -3
  58. package/dist/sdk/coding-agent/core/extensions/index.d.ts +1 -1
  59. package/dist/sdk/coding-agent/core/extensions/index.d.ts.map +1 -1
  60. package/dist/sdk/coding-agent/core/extensions/native-extensions.js +2 -2
  61. package/dist/sdk/coding-agent/core/extensions/types.d.ts +20 -1
  62. package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -1
  63. package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts +9 -4
  64. package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  65. package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.js +15 -2
  66. package/dist/sdk/coding-agent/index.d.ts +1 -1
  67. package/dist/sdk/coding-agent/index.d.ts.map +1 -1
  68. package/dist/server/agent-bridge/headless-ui.d.ts +20 -0
  69. package/dist/server/agent-bridge/headless-ui.d.ts.map +1 -0
  70. package/dist/server/agent-bridge/headless-ui.js +85 -0
  71. package/dist/server/agent-bridge/pricing.d.ts +54 -0
  72. package/dist/server/agent-bridge/pricing.d.ts.map +1 -0
  73. package/dist/server/agent-bridge/pricing.js +226 -0
  74. package/dist/server/agent-bridge/rehydrate.d.ts +35 -0
  75. package/dist/server/agent-bridge/rehydrate.d.ts.map +1 -0
  76. package/dist/server/agent-bridge/rehydrate.js +122 -0
  77. package/dist/server/agent-bridge/synthetic-model.d.ts +27 -0
  78. package/dist/server/agent-bridge/synthetic-model.d.ts.map +1 -0
  79. package/dist/server/agent-bridge/synthetic-model.js +92 -0
  80. package/dist/server/agent-bridge.d.ts +17 -1
  81. package/dist/server/agent-bridge.d.ts.map +1 -1
  82. package/dist/server/agent-bridge.js +81 -496
  83. package/dist/server/error-humanizer.d.ts +11 -3
  84. package/dist/server/error-humanizer.d.ts.map +1 -1
  85. package/dist/server/error-humanizer.js +11 -3
  86. package/dist/server/session-stream/compaction-events.d.ts +13 -0
  87. package/dist/server/session-stream/compaction-events.d.ts.map +1 -0
  88. package/dist/server/session-stream/compaction-events.js +32 -0
  89. package/dist/server/session-stream/history-prune.d.ts +35 -0
  90. package/dist/server/session-stream/history-prune.d.ts.map +1 -0
  91. package/dist/server/session-stream/history-prune.js +182 -0
  92. package/dist/server/session-stream/memory.d.ts +48 -0
  93. package/dist/server/session-stream/memory.d.ts.map +1 -0
  94. package/dist/server/session-stream/memory.js +136 -0
  95. package/dist/server/session-stream/replay-tail.d.ts +4 -0
  96. package/dist/server/session-stream/replay-tail.d.ts.map +1 -0
  97. package/dist/server/session-stream/replay-tail.js +39 -0
  98. package/dist/server/session-stream/turn-events.d.ts +33 -0
  99. package/dist/server/session-stream/turn-events.d.ts.map +1 -0
  100. package/dist/server/session-stream/turn-events.js +65 -0
  101. package/dist/server/session-stream/turn-silence.d.ts +8 -0
  102. package/dist/server/session-stream/turn-silence.d.ts.map +1 -0
  103. package/dist/server/session-stream/turn-silence.js +72 -0
  104. package/dist/server/session-stream.d.ts +137 -36
  105. package/dist/server/session-stream.d.ts.map +1 -1
  106. package/dist/server/session-stream.js +18 -509
  107. package/dist/server/storage/observation-ranking.d.ts +14 -0
  108. package/dist/server/storage/observation-ranking.d.ts.map +1 -0
  109. package/dist/server/storage/observation-ranking.js +37 -0
  110. package/dist/server/storage/preflight.d.ts +20 -0
  111. package/dist/server/storage/preflight.d.ts.map +1 -0
  112. package/dist/server/storage/preflight.js +22 -0
  113. package/dist/server/storage/project-binding.d.ts +5 -0
  114. package/dist/server/storage/project-binding.d.ts.map +1 -0
  115. package/dist/server/storage/project-binding.js +32 -0
  116. package/dist/server/storage/rows.d.ts +104 -0
  117. package/dist/server/storage/rows.d.ts.map +1 -0
  118. package/dist/server/storage/rows.js +2 -0
  119. package/dist/server/storage/schema.d.ts +20 -0
  120. package/dist/server/storage/schema.d.ts.map +1 -0
  121. package/dist/server/storage/schema.js +134 -0
  122. package/dist/server/storage/types.d.ts +66 -0
  123. package/dist/server/storage/types.d.ts.map +1 -0
  124. package/dist/server/storage/types.js +1 -0
  125. package/dist/server/storage.d.ts +7 -94
  126. package/dist/server/storage.d.ts.map +1 -1
  127. package/dist/server/storage.js +6 -224
  128. package/dist/server/wire.d.ts +19 -0
  129. package/dist/server/wire.d.ts.map +1 -1
  130. package/package.json +2 -1
  131. package/dist/sdk/agent-core/harness/agent-harness.d.ts +0 -92
  132. package/dist/sdk/agent-core/harness/agent-harness.d.ts.map +0 -1
  133. package/dist/sdk/agent-core/harness/agent-harness.js +0 -899
  134. package/dist/sdk/agent-core/harness/env/nodejs.d.ts +0 -51
  135. package/dist/sdk/agent-core/harness/env/nodejs.d.ts.map +0 -1
  136. package/dist/sdk/agent-core/harness/env/nodejs.js +0 -485
  137. package/dist/sdk/agent-core/harness/prompt-templates.d.ts +0 -48
  138. package/dist/sdk/agent-core/harness/prompt-templates.d.ts.map +0 -1
  139. package/dist/sdk/agent-core/harness/prompt-templates.js +0 -229
  140. package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts +0 -26
  141. package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts.map +0 -1
  142. package/dist/sdk/agent-core/harness/session/jsonl-repo.js +0 -100
  143. package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts +0 -33
  144. package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts.map +0 -1
  145. package/dist/sdk/agent-core/harness/session/jsonl-storage.js +0 -230
  146. package/dist/sdk/agent-core/harness/session/memory-repo.d.ts +0 -18
  147. package/dist/sdk/agent-core/harness/session/memory-repo.d.ts.map +0 -1
  148. package/dist/sdk/agent-core/harness/session/memory-repo.js +0 -41
  149. package/dist/sdk/agent-core/harness/session/memory-storage.d.ts +0 -25
  150. package/dist/sdk/agent-core/harness/session/memory-storage.d.ts.map +0 -1
  151. package/dist/sdk/agent-core/harness/session/memory-storage.js +0 -113
  152. package/dist/sdk/agent-core/harness/session/repo-utils.d.ts +0 -11
  153. package/dist/sdk/agent-core/harness/session/repo-utils.d.ts.map +0 -1
  154. package/dist/sdk/agent-core/harness/session/repo-utils.js +0 -38
  155. package/dist/sdk/agent-core/harness/skills.d.ts +0 -44
  156. package/dist/sdk/agent-core/harness/skills.d.ts.map +0 -1
  157. package/dist/sdk/agent-core/harness/skills.js +0 -310
  158. package/dist/sdk/agent-core/harness/utils/shell-output.d.ts +0 -14
  159. package/dist/sdk/agent-core/harness/utils/shell-output.d.ts.map +0 -1
  160. package/dist/sdk/agent-core/harness/utils/shell-output.js +0 -125
  161. package/dist/sdk/agent-core/node.d.ts +0 -3
  162. package/dist/sdk/agent-core/node.d.ts.map +0 -1
  163. package/dist/sdk/agent-core/node.js +0 -2
  164. package/dist/sdk/agent-core/proxy.d.ts +0 -69
  165. package/dist/sdk/agent-core/proxy.d.ts.map +0 -1
  166. package/dist/sdk/agent-core/proxy.js +0 -297
@@ -0,0 +1,877 @@
1
+ // GENERATED by cli-node/scripts/vendor-parser.mjs — do not edit; regenerate with `node scripts/vendor-parser.mjs`; source: packages/parser/
2
+ /**
3
+ * Aexol Language Lexer
4
+ *
5
+ * Tokenizes Aexol source code into a stream of tokens.
6
+ * Handles keywords, identifiers, operators, strings, and whitespace.
7
+ */
8
+ export var TokenType;
9
+ (function (TokenType) {
10
+ // Literals
11
+ TokenType["IDENTIFIER"] = "IDENTIFIER";
12
+ TokenType["STRING"] = "STRING";
13
+ TokenType["NUMBER"] = "NUMBER";
14
+ // Keywords
15
+ TokenType["VISITOR"] = "VISITOR";
16
+ TokenType["AND"] = "AND";
17
+ TokenType["OR"] = "OR";
18
+ TokenType["NOT"] = "NOT";
19
+ TokenType["IF"] = "IF";
20
+ TokenType["WHEN"] = "WHEN";
21
+ TokenType["WHILE"] = "WHILE";
22
+ TokenType["FOR"] = "FOR";
23
+ TokenType["IN"] = "IN";
24
+ TokenType["OF"] = "OF";
25
+ TokenType["AS"] = "AS";
26
+ TokenType["WITH"] = "WITH";
27
+ TokenType["WITHOUT"] = "WITHOUT";
28
+ TokenType["REQUIRE"] = "REQUIRE";
29
+ TokenType["IMPORT"] = "IMPORT";
30
+ TokenType["FROM"] = "FROM";
31
+ TokenType["DEFINE"] = "DEFINE";
32
+ TokenType["TYPE"] = "TYPE";
33
+ TokenType["ENUM"] = "ENUM";
34
+ TokenType["INTERFACE"] = "INTERFACE";
35
+ TokenType["AGENT"] = "AGENT";
36
+ TokenType["WORKFLOW"] = "WORKFLOW";
37
+ TokenType["ROLE"] = "ROLE";
38
+ TokenType["PERMISSION"] = "PERMISSION";
39
+ TokenType["ACTION"] = "ACTION";
40
+ TokenType["STATE"] = "STATE";
41
+ TokenType["TRANSITION"] = "TRANSITION";
42
+ // Execution Plan Keywords
43
+ TokenType["EXECUTION_PLAN"] = "EXECUTION_PLAN";
44
+ TokenType["TASK"] = "TASK";
45
+ TokenType["SUBTASK"] = "SUBTASK";
46
+ TokenType["SUBTASKS"] = "SUBTASKS";
47
+ TokenType["DEPENDENCIES"] = "DEPENDENCIES";
48
+ TokenType["PARALLEL_WITH"] = "PARALLEL_WITH";
49
+ TokenType["EXECUTION_GRAPH"] = "EXECUTION_GRAPH";
50
+ TokenType["PHASE"] = "PHASE";
51
+ TokenType["CONTEXT"] = "CONTEXT";
52
+ // Agent/Task Properties
53
+ TokenType["CAPABILITIES"] = "CAPABILITIES";
54
+ TokenType["SKILLS"] = "SKILLS";
55
+ TokenType["MODEL"] = "MODEL";
56
+ TokenType["MAX_CONCURRENT"] = "MAX_CONCURRENT";
57
+ TokenType["ESTIMATED_DURATION"] = "ESTIMATED_DURATION";
58
+ TokenType["DESCRIPTION"] = "DESCRIPTION";
59
+ TokenType["SPEC_REFERENCE"] = "SPEC_REFERENCE";
60
+ TokenType["GENERATED_FROM"] = "GENERATED_FROM";
61
+ TokenType["GENERATED_AT"] = "GENERATED_AT";
62
+ TokenType["GENERATED_BY"] = "GENERATED_BY";
63
+ TokenType["INITIAL"] = "INITIAL";
64
+ TokenType["FINAL"] = "FINAL";
65
+ TokenType["TRUE"] = "TRUE";
66
+ TokenType["FALSE"] = "FALSE";
67
+ TokenType["NULL"] = "NULL";
68
+ TokenType["RETURN"] = "RETURN";
69
+ TokenType["YIELD"] = "YIELD";
70
+ TokenType["ASYNC"] = "ASYNC";
71
+ TokenType["AWAIT"] = "AWAIT";
72
+ TokenType["THROW"] = "THROW";
73
+ TokenType["TRY"] = "TRY";
74
+ TokenType["CATCH"] = "CATCH";
75
+ TokenType["FINALLY"] = "FINALLY";
76
+ // Operators
77
+ TokenType["LPAREN"] = "LPAREN";
78
+ TokenType["RPAREN"] = "RPAREN";
79
+ TokenType["LBRACE"] = "LBRACE";
80
+ TokenType["RBRACE"] = "RBRACE";
81
+ TokenType["LBRACKET"] = "LBRACKET";
82
+ TokenType["RBRACKET"] = "RBRACKET";
83
+ TokenType["DOT"] = "DOT";
84
+ TokenType["COMMA"] = "COMMA";
85
+ TokenType["COLON"] = "COLON";
86
+ TokenType["SEMICOLON"] = "SEMICOLON";
87
+ TokenType["ARROW"] = "ARROW";
88
+ TokenType["FAT_ARROW"] = "FAT_ARROW";
89
+ TokenType["EQUALS"] = "EQUALS";
90
+ TokenType["PLUS_EQUALS"] = "PLUS_EQUALS";
91
+ TokenType["MINUS_EQUALS"] = "MINUS_EQUALS";
92
+ TokenType["MULT_EQUALS"] = "MULT_EQUALS";
93
+ TokenType["DIV_EQUALS"] = "DIV_EQUALS";
94
+ TokenType["PLUS"] = "PLUS";
95
+ TokenType["MINUS"] = "MINUS";
96
+ TokenType["MULT"] = "MULT";
97
+ TokenType["DIV"] = "DIV";
98
+ TokenType["MOD"] = "MOD";
99
+ TokenType["POWER"] = "POWER";
100
+ TokenType["EQ"] = "EQ";
101
+ TokenType["NEQ"] = "NEQ";
102
+ TokenType["LT"] = "LT";
103
+ TokenType["LTE"] = "LTE";
104
+ TokenType["GT"] = "GT";
105
+ TokenType["GTE"] = "GTE";
106
+ TokenType["AMPERSAND"] = "AMPERSAND";
107
+ TokenType["PIPE"] = "PIPE";
108
+ TokenType["CARET"] = "CARET";
109
+ TokenType["TILDE"] = "TILDE";
110
+ TokenType["QUESTION"] = "QUESTION";
111
+ TokenType["EXCLAMATION"] = "EXCLAMATION";
112
+ TokenType["AT"] = "AT";
113
+ TokenType["DOLLAR"] = "DOLLAR";
114
+ TokenType["HASH"] = "HASH";
115
+ TokenType["BACKSLASH"] = "BACKSLASH";
116
+ // Special
117
+ TokenType["NEWLINE"] = "NEWLINE";
118
+ TokenType["INDENT"] = "INDENT";
119
+ TokenType["DEDENT"] = "DEDENT";
120
+ TokenType["EOF"] = "EOF";
121
+ TokenType["COMMENT"] = "COMMENT";
122
+ TokenType["WHITESPACE"] = "WHITESPACE";
123
+ TokenType["PROMPT"] = "PROMPT";
124
+ })(TokenType || (TokenType = {}));
125
+ const KEYWORDS = {
126
+ visitor: TokenType.VISITOR,
127
+ and: TokenType.AND,
128
+ or: TokenType.OR,
129
+ not: TokenType.NOT,
130
+ if: TokenType.IF,
131
+ when: TokenType.WHEN,
132
+ while: TokenType.WHILE,
133
+ for: TokenType.FOR,
134
+ in: TokenType.IN,
135
+ of: TokenType.OF,
136
+ as: TokenType.AS,
137
+ with: TokenType.WITH,
138
+ without: TokenType.WITHOUT,
139
+ require: TokenType.REQUIRE,
140
+ import: TokenType.IMPORT,
141
+ from: TokenType.FROM,
142
+ define: TokenType.DEFINE,
143
+ type: TokenType.TYPE,
144
+ enum: TokenType.ENUM,
145
+ interface: TokenType.INTERFACE,
146
+ agent: TokenType.AGENT,
147
+ workflow: TokenType.WORKFLOW,
148
+ role: TokenType.ROLE,
149
+ permission: TokenType.PERMISSION,
150
+ action: TokenType.ACTION,
151
+ state: TokenType.STATE,
152
+ transition: TokenType.TRANSITION,
153
+ // Execution Plan Keywords
154
+ execution_plan: TokenType.EXECUTION_PLAN,
155
+ task: TokenType.TASK,
156
+ subtask: TokenType.SUBTASK,
157
+ subtasks: TokenType.SUBTASKS,
158
+ dependencies: TokenType.DEPENDENCIES,
159
+ parallel_with: TokenType.PARALLEL_WITH,
160
+ execution_graph: TokenType.EXECUTION_GRAPH,
161
+ phase: TokenType.PHASE,
162
+ context: TokenType.CONTEXT,
163
+ // Agent/Task Properties
164
+ capabilities: TokenType.CAPABILITIES,
165
+ skills: TokenType.SKILLS,
166
+ model: TokenType.MODEL,
167
+ max_concurrent: TokenType.MAX_CONCURRENT,
168
+ estimated_duration: TokenType.ESTIMATED_DURATION,
169
+ description: TokenType.DESCRIPTION,
170
+ spec_reference: TokenType.SPEC_REFERENCE,
171
+ generated_from: TokenType.GENERATED_FROM,
172
+ generated_at: TokenType.GENERATED_AT,
173
+ generated_by: TokenType.GENERATED_BY,
174
+ initial: TokenType.INITIAL,
175
+ final: TokenType.FINAL,
176
+ true: TokenType.TRUE,
177
+ false: TokenType.FALSE,
178
+ null: TokenType.NULL,
179
+ return: TokenType.RETURN,
180
+ yield: TokenType.YIELD,
181
+ async: TokenType.ASYNC,
182
+ await: TokenType.AWAIT,
183
+ throw: TokenType.THROW,
184
+ try: TokenType.TRY,
185
+ catch: TokenType.CATCH,
186
+ finally: TokenType.FINALLY,
187
+ };
188
+ export class Lexer {
189
+ source;
190
+ position = 0;
191
+ line = 1;
192
+ column = 1;
193
+ tokens = [];
194
+ indentStack = [0];
195
+ constructor(source) {
196
+ this.source = source;
197
+ }
198
+ peek(offset = 0) {
199
+ const pos = this.position + offset;
200
+ return pos < this.source.length ? this.source[pos] : "\0";
201
+ }
202
+ advance() {
203
+ const char = this.source[this.position];
204
+ this.position++;
205
+ if (char === "\n") {
206
+ this.line++;
207
+ this.column = 1;
208
+ }
209
+ else {
210
+ this.column++;
211
+ }
212
+ return char;
213
+ }
214
+ skipWhitespace() {
215
+ while (this.peek() === " " || this.peek() === "\t" || this.peek() === "\r") {
216
+ this.advance();
217
+ }
218
+ }
219
+ skipCommentIfNeeded() {
220
+ const char = this.peek();
221
+ // Shell-style comments starting with '#'
222
+ if (char === "#") {
223
+ const start = this.position;
224
+ const startLine = this.line;
225
+ const startColumn = this.column;
226
+ while (this.peek() !== "\n" && this.peek() !== "\0") {
227
+ this.advance();
228
+ }
229
+ const value = this.source.substring(start, this.position);
230
+ this.tokens.push({
231
+ type: TokenType.COMMENT,
232
+ value,
233
+ location: { line: startLine, column: startColumn, offset: start },
234
+ raw: value,
235
+ });
236
+ return true;
237
+ }
238
+ // Line comments starting with '//' (common in plans)
239
+ if (char === "/" && this.peek(1) === "/") {
240
+ const start = this.position;
241
+ const startLine = this.line;
242
+ const startColumn = this.column;
243
+ // Skip the leading '//'
244
+ this.advance();
245
+ this.advance();
246
+ while (this.peek() !== "\n" && this.peek() !== "\0") {
247
+ this.advance();
248
+ }
249
+ const value = this.source.substring(start, this.position);
250
+ this.tokens.push({
251
+ type: TokenType.COMMENT,
252
+ value,
253
+ location: { line: startLine, column: startColumn, offset: start },
254
+ raw: value,
255
+ });
256
+ return true;
257
+ }
258
+ // Block comments starting with '/*' and ending with '*/'
259
+ if (char === "/" && this.peek(1) === "*") {
260
+ const start = this.position;
261
+ const startLine = this.line;
262
+ const startColumn = this.column;
263
+ // Skip the leading '/*'
264
+ this.advance();
265
+ this.advance();
266
+ while (this.peek() !== "\0" && !(this.peek() === "*" && this.peek(1) === "/")) {
267
+ this.advance();
268
+ }
269
+ // Consume the closing '*/' if present
270
+ if (this.peek() === "*" && this.peek(1) === "/") {
271
+ this.advance();
272
+ this.advance();
273
+ }
274
+ const value = this.source.substring(start, this.position);
275
+ this.tokens.push({
276
+ type: TokenType.COMMENT,
277
+ value,
278
+ location: { line: startLine, column: startColumn, offset: start },
279
+ raw: value,
280
+ });
281
+ return true;
282
+ }
283
+ return false;
284
+ }
285
+ readString(quote) {
286
+ const start = this.position;
287
+ const startLine = this.line;
288
+ const startColumn = this.column;
289
+ this.advance(); // Skip opening quote
290
+ let value = "";
291
+ while (this.peek() !== quote && this.peek() !== "\0") {
292
+ if (this.peek() === "\\") {
293
+ this.advance();
294
+ const escaped = this.peek();
295
+ switch (escaped) {
296
+ case "n":
297
+ value += "\n";
298
+ break;
299
+ case "t":
300
+ value += "\t";
301
+ break;
302
+ case "r":
303
+ value += "\r";
304
+ break;
305
+ case "\\":
306
+ value += "\\";
307
+ break;
308
+ case '"':
309
+ value += '"';
310
+ break;
311
+ case "'":
312
+ value += "'";
313
+ break;
314
+ default:
315
+ value += escaped;
316
+ }
317
+ this.advance();
318
+ }
319
+ else {
320
+ value += this.advance();
321
+ }
322
+ }
323
+ if (this.peek() === quote) {
324
+ this.advance(); // Skip closing quote
325
+ }
326
+ return {
327
+ type: TokenType.STRING,
328
+ value,
329
+ location: { line: startLine, column: startColumn, offset: start },
330
+ raw: this.source.substring(start, this.position),
331
+ };
332
+ }
333
+ readNumber() {
334
+ const start = this.position;
335
+ const startLine = this.line;
336
+ const startColumn = this.column;
337
+ while (/[0-9]/.test(this.peek())) {
338
+ this.advance();
339
+ }
340
+ if (this.peek() === "." && /[0-9]/.test(this.peek(1))) {
341
+ this.advance(); // Skip dot
342
+ while (/[0-9]/.test(this.peek())) {
343
+ this.advance();
344
+ }
345
+ }
346
+ const raw = this.source.substring(start, this.position);
347
+ return {
348
+ type: TokenType.NUMBER,
349
+ value: raw,
350
+ location: { line: startLine, column: startColumn, offset: start },
351
+ raw,
352
+ };
353
+ }
354
+ readIdentifier() {
355
+ const start = this.position;
356
+ const startLine = this.line;
357
+ const startColumn = this.column;
358
+ while (/[a-zA-Z0-9_-]/.test(this.peek())) {
359
+ this.advance();
360
+ }
361
+ const raw = this.source.substring(start, this.position);
362
+ const lower = raw.toLowerCase();
363
+ const type = KEYWORDS[lower] || TokenType.IDENTIFIER;
364
+ return {
365
+ type,
366
+ value: raw,
367
+ location: { line: startLine, column: startColumn, offset: start },
368
+ raw,
369
+ };
370
+ }
371
+ readPromptString() {
372
+ const start = this.position;
373
+ const startLine = this.line;
374
+ const startColumn = this.column;
375
+ // Skip opening '''
376
+ this.advance();
377
+ this.advance();
378
+ this.advance();
379
+ let value = "";
380
+ while (this.position < this.source.length) {
381
+ if (this.peek() === "'" && this.peek(1) === "'" && this.peek(2) === "'") {
382
+ this.advance();
383
+ this.advance();
384
+ this.advance();
385
+ break;
386
+ }
387
+ value += this.advance();
388
+ }
389
+ // Trim leading/trailing whitespace
390
+ value = value.trim();
391
+ return {
392
+ type: TokenType.PROMPT,
393
+ value,
394
+ location: { line: startLine, column: startColumn, offset: start },
395
+ raw: this.source.substring(start, this.position),
396
+ };
397
+ }
398
+ handleIndentation() {
399
+ const lineStart = this.position;
400
+ let spaces = 0;
401
+ while (this.peek() === " " || this.peek() === "\t") {
402
+ spaces += this.peek() === "\t" ? 4 : 1;
403
+ this.advance();
404
+ }
405
+ // Skip empty lines and comments
406
+ if (this.peek() === "\n" || this.peek() === "#" || this.peek() === "\0") {
407
+ return;
408
+ }
409
+ const currentIndent = this.indentStack[this.indentStack.length - 1];
410
+ if (spaces > currentIndent) {
411
+ this.indentStack.push(spaces);
412
+ this.tokens.push({
413
+ type: TokenType.INDENT,
414
+ value: " ".repeat(spaces),
415
+ location: { line: this.line, column: 1, offset: lineStart },
416
+ raw: " ".repeat(spaces),
417
+ });
418
+ }
419
+ else if (spaces < currentIndent) {
420
+ while (this.indentStack.length > 1 &&
421
+ this.indentStack[this.indentStack.length - 1] > spaces) {
422
+ this.indentStack.pop();
423
+ this.tokens.push({
424
+ type: TokenType.DEDENT,
425
+ value: "",
426
+ location: { line: this.line, column: 1, offset: lineStart },
427
+ raw: "",
428
+ });
429
+ }
430
+ }
431
+ }
432
+ tokenize() {
433
+ this.tokens = [];
434
+ while (this.position < this.source.length) {
435
+ const char = this.peek();
436
+ // Handle newline
437
+ if (char === "\n") {
438
+ const start = this.position;
439
+ const startLine = this.line;
440
+ const startColumn = this.column;
441
+ this.advance();
442
+ // Check if next line has content
443
+ let peekPos = this.position;
444
+ while (peekPos < this.source.length &&
445
+ (this.source[peekPos] === " " || this.source[peekPos] === "\t")) {
446
+ peekPos++;
447
+ }
448
+ // Only emit newline if not followed by EOF or only whitespace
449
+ if (peekPos < this.source.length && this.source[peekPos] !== "\n" &&
450
+ this.source[peekPos] !== "#") {
451
+ this.tokens.push({
452
+ type: TokenType.NEWLINE,
453
+ value: "\n",
454
+ location: { line: startLine, column: startColumn, offset: start },
455
+ raw: "\n",
456
+ });
457
+ this.handleIndentation();
458
+ }
459
+ continue;
460
+ }
461
+ // Handle comments (supports '#', '//', and '/* */')
462
+ if (this.skipCommentIfNeeded()) {
463
+ continue;
464
+ }
465
+ // Skip whitespace (spaces, tabs)
466
+ if (char === " " || char === "\t") {
467
+ this.skipWhitespace();
468
+ continue;
469
+ }
470
+ // Handle triple single-quote strings (descriptions/prompts)
471
+ if (char === "'" && this.peek(1) === "'" && this.peek(2) === "'") {
472
+ this.tokens.push(this.readPromptString());
473
+ continue;
474
+ }
475
+ // Handle strings
476
+ if (char === '"' || char === "'") {
477
+ this.tokens.push(this.readString(char));
478
+ continue;
479
+ }
480
+ // Handle numbers
481
+ if (/[0-9]/.test(char)) {
482
+ this.tokens.push(this.readNumber());
483
+ continue;
484
+ }
485
+ // Handle identifiers and keywords
486
+ if (/[a-zA-Z_]/.test(char)) {
487
+ this.tokens.push(this.readIdentifier());
488
+ continue;
489
+ }
490
+ // Handle operators and punctuation
491
+ const start = this.position;
492
+ const startLine = this.line;
493
+ const startColumn = this.column;
494
+ if (char === "(" && this.peek(1) !== ")") {
495
+ this.advance();
496
+ this.tokens.push({
497
+ type: TokenType.LPAREN,
498
+ value: "(",
499
+ location: { line: startLine, column: startColumn, offset: start },
500
+ raw: "(",
501
+ });
502
+ }
503
+ else if (char === ")") {
504
+ this.advance();
505
+ this.tokens.push({
506
+ type: TokenType.RPAREN,
507
+ value: ")",
508
+ location: { line: startLine, column: startColumn, offset: start },
509
+ raw: ")",
510
+ });
511
+ }
512
+ else if (char === "{") {
513
+ this.advance();
514
+ this.tokens.push({
515
+ type: TokenType.LBRACE,
516
+ value: "{",
517
+ location: { line: startLine, column: startColumn, offset: start },
518
+ raw: "{",
519
+ });
520
+ }
521
+ else if (char === "}") {
522
+ this.advance();
523
+ this.tokens.push({
524
+ type: TokenType.RBRACE,
525
+ value: "}",
526
+ location: { line: startLine, column: startColumn, offset: start },
527
+ raw: "}",
528
+ });
529
+ }
530
+ else if (char === "[") {
531
+ this.advance();
532
+ this.tokens.push({
533
+ type: TokenType.LBRACKET,
534
+ value: "[",
535
+ location: { line: startLine, column: startColumn, offset: start },
536
+ raw: "[",
537
+ });
538
+ }
539
+ else if (char === "]") {
540
+ this.advance();
541
+ this.tokens.push({
542
+ type: TokenType.RBRACKET,
543
+ value: "]",
544
+ location: { line: startLine, column: startColumn, offset: start },
545
+ raw: "]",
546
+ });
547
+ }
548
+ else if (char === "." && !/[0-9]/.test(this.peek(1))) {
549
+ this.advance();
550
+ this.tokens.push({
551
+ type: TokenType.DOT,
552
+ value: ".",
553
+ location: { line: startLine, column: startColumn, offset: start },
554
+ raw: ".",
555
+ });
556
+ }
557
+ else if (char === ",") {
558
+ this.advance();
559
+ this.tokens.push({
560
+ type: TokenType.COMMA,
561
+ value: ",",
562
+ location: { line: startLine, column: startColumn, offset: start },
563
+ raw: ",",
564
+ });
565
+ }
566
+ else if (char === ":" && this.peek(1) !== "=") {
567
+ this.advance();
568
+ this.tokens.push({
569
+ type: TokenType.COLON,
570
+ value: ":",
571
+ location: { line: startLine, column: startColumn, offset: start },
572
+ raw: ":",
573
+ });
574
+ }
575
+ else if (char === ";") {
576
+ this.advance();
577
+ this.tokens.push({
578
+ type: TokenType.SEMICOLON,
579
+ value: ";",
580
+ location: { line: startLine, column: startColumn, offset: start },
581
+ raw: ";",
582
+ });
583
+ }
584
+ else if (char === "-" && this.peek(1) === ">") {
585
+ this.advance();
586
+ this.advance();
587
+ this.tokens.push({
588
+ type: TokenType.ARROW,
589
+ value: "->",
590
+ location: { line: startLine, column: startColumn, offset: start },
591
+ raw: "->",
592
+ });
593
+ }
594
+ else if (char === "=" && this.peek(1) === ">") {
595
+ this.advance();
596
+ this.advance();
597
+ this.tokens.push({
598
+ type: TokenType.FAT_ARROW,
599
+ value: "=>",
600
+ location: { line: startLine, column: startColumn, offset: start },
601
+ raw: "=>",
602
+ });
603
+ }
604
+ else if (char === "=" && this.peek(1) === "=") {
605
+ this.advance();
606
+ this.advance();
607
+ this.tokens.push({
608
+ type: TokenType.EQ,
609
+ value: "==",
610
+ location: { line: startLine, column: startColumn, offset: start },
611
+ raw: "==",
612
+ });
613
+ }
614
+ else if (char === "!" && this.peek(1) === "=") {
615
+ this.advance();
616
+ this.advance();
617
+ this.tokens.push({
618
+ type: TokenType.NEQ,
619
+ value: "!=",
620
+ location: { line: startLine, column: startColumn, offset: start },
621
+ raw: "!=",
622
+ });
623
+ }
624
+ else if (char === "<" && this.peek(1) === "=") {
625
+ this.advance();
626
+ this.advance();
627
+ this.tokens.push({
628
+ type: TokenType.LTE,
629
+ value: "<=",
630
+ location: { line: startLine, column: startColumn, offset: start },
631
+ raw: "<=",
632
+ });
633
+ }
634
+ else if (char === ">" && this.peek(1) === "=") {
635
+ this.advance();
636
+ this.advance();
637
+ this.tokens.push({
638
+ type: TokenType.GTE,
639
+ value: ">=",
640
+ location: { line: startLine, column: startColumn, offset: start },
641
+ raw: ">=",
642
+ });
643
+ }
644
+ else if (char === "+") {
645
+ this.advance();
646
+ if (this.peek() === "=") {
647
+ this.advance();
648
+ this.tokens.push({
649
+ type: TokenType.PLUS_EQUALS,
650
+ value: "+=",
651
+ location: { line: startLine, column: startColumn, offset: start },
652
+ raw: "+=",
653
+ });
654
+ }
655
+ else {
656
+ this.tokens.push({
657
+ type: TokenType.PLUS,
658
+ value: "+",
659
+ location: { line: startLine, column: startColumn, offset: start },
660
+ raw: "+",
661
+ });
662
+ }
663
+ }
664
+ else if (char === "-") {
665
+ this.advance();
666
+ if (this.peek() === "=") {
667
+ this.advance();
668
+ this.tokens.push({
669
+ type: TokenType.MINUS_EQUALS,
670
+ value: "-=",
671
+ location: { line: startLine, column: startColumn, offset: start },
672
+ raw: "-=",
673
+ });
674
+ }
675
+ else {
676
+ this.tokens.push({
677
+ type: TokenType.MINUS,
678
+ value: "-",
679
+ location: { line: startLine, column: startColumn, offset: start },
680
+ raw: "-",
681
+ });
682
+ }
683
+ }
684
+ else if (char === "*") {
685
+ this.advance();
686
+ if (this.peek() === "*") {
687
+ this.advance();
688
+ this.tokens.push({
689
+ type: TokenType.POWER,
690
+ value: "**",
691
+ location: { line: startLine, column: startColumn, offset: start },
692
+ raw: "**",
693
+ });
694
+ }
695
+ else if (this.peek() === "=") {
696
+ this.advance();
697
+ this.tokens.push({
698
+ type: TokenType.MULT_EQUALS,
699
+ value: "*=",
700
+ location: { line: startLine, column: startColumn, offset: start },
701
+ raw: "*=",
702
+ });
703
+ }
704
+ else {
705
+ this.tokens.push({
706
+ type: TokenType.MULT,
707
+ value: "*",
708
+ location: { line: startLine, column: startColumn, offset: start },
709
+ raw: "*",
710
+ });
711
+ }
712
+ }
713
+ else if (char === "/") {
714
+ this.advance();
715
+ if (this.peek() === "=") {
716
+ this.advance();
717
+ this.tokens.push({
718
+ type: TokenType.DIV_EQUALS,
719
+ value: "/=",
720
+ location: { line: startLine, column: startColumn, offset: start },
721
+ raw: "/=",
722
+ });
723
+ }
724
+ else {
725
+ this.tokens.push({
726
+ type: TokenType.DIV,
727
+ value: "/",
728
+ location: { line: startLine, column: startColumn, offset: start },
729
+ raw: "/",
730
+ });
731
+ }
732
+ }
733
+ else if (char === "%") {
734
+ this.advance();
735
+ this.tokens.push({
736
+ type: TokenType.MOD,
737
+ value: "%",
738
+ location: { line: startLine, column: startColumn, offset: start },
739
+ raw: "%",
740
+ });
741
+ }
742
+ else if (char === "=") {
743
+ this.advance();
744
+ this.tokens.push({
745
+ type: TokenType.EQUALS,
746
+ value: "=",
747
+ location: { line: startLine, column: startColumn, offset: start },
748
+ raw: "=",
749
+ });
750
+ }
751
+ else if (char === "<") {
752
+ this.advance();
753
+ this.tokens.push({
754
+ type: TokenType.LT,
755
+ value: "<",
756
+ location: { line: startLine, column: startColumn, offset: start },
757
+ raw: "<",
758
+ });
759
+ }
760
+ else if (char === ">") {
761
+ this.advance();
762
+ this.tokens.push({
763
+ type: TokenType.GT,
764
+ value: ">",
765
+ location: { line: startLine, column: startColumn, offset: start },
766
+ raw: ">",
767
+ });
768
+ }
769
+ else if (char === "&") {
770
+ this.advance();
771
+ this.tokens.push({
772
+ type: TokenType.AMPERSAND,
773
+ value: "&",
774
+ location: { line: startLine, column: startColumn, offset: start },
775
+ raw: "&",
776
+ });
777
+ }
778
+ else if (char === "|") {
779
+ this.advance();
780
+ this.tokens.push({
781
+ type: TokenType.PIPE,
782
+ value: "|",
783
+ location: { line: startLine, column: startColumn, offset: start },
784
+ raw: "|",
785
+ });
786
+ }
787
+ else if (char === "^") {
788
+ this.advance();
789
+ this.tokens.push({
790
+ type: TokenType.CARET,
791
+ value: "^",
792
+ location: { line: startLine, column: startColumn, offset: start },
793
+ raw: "^",
794
+ });
795
+ }
796
+ else if (char === "~") {
797
+ this.advance();
798
+ this.tokens.push({
799
+ type: TokenType.TILDE,
800
+ value: "~",
801
+ location: { line: startLine, column: startColumn, offset: start },
802
+ raw: "~",
803
+ });
804
+ }
805
+ else if (char === "?") {
806
+ this.advance();
807
+ this.tokens.push({
808
+ type: TokenType.QUESTION,
809
+ value: "?",
810
+ location: { line: startLine, column: startColumn, offset: start },
811
+ raw: "?",
812
+ });
813
+ }
814
+ else if (char === "!") {
815
+ this.advance();
816
+ this.tokens.push({
817
+ type: TokenType.EXCLAMATION,
818
+ value: "!",
819
+ location: { line: startLine, column: startColumn, offset: start },
820
+ raw: "!",
821
+ });
822
+ }
823
+ else if (char === "@") {
824
+ this.advance();
825
+ this.tokens.push({
826
+ type: TokenType.AT,
827
+ value: "@",
828
+ location: { line: startLine, column: startColumn, offset: start },
829
+ raw: "@",
830
+ });
831
+ }
832
+ else if (char === "$") {
833
+ this.advance();
834
+ this.tokens.push({
835
+ type: TokenType.DOLLAR,
836
+ value: "$",
837
+ location: { line: startLine, column: startColumn, offset: start },
838
+ raw: "$",
839
+ });
840
+ }
841
+ else if (char === "\\") {
842
+ this.advance();
843
+ this.tokens.push({
844
+ type: TokenType.BACKSLASH,
845
+ value: "\\",
846
+ location: { line: startLine, column: startColumn, offset: start },
847
+ raw: "\\",
848
+ });
849
+ }
850
+ else {
851
+ // Unknown character, skip it
852
+ this.advance();
853
+ }
854
+ }
855
+ // Handle remaining dedents
856
+ while (this.indentStack.length > 1) {
857
+ this.indentStack.pop();
858
+ this.tokens.push({
859
+ type: TokenType.DEDENT,
860
+ value: "",
861
+ location: { line: this.line, column: 1, offset: this.position },
862
+ raw: "",
863
+ });
864
+ }
865
+ // Add EOF token
866
+ this.tokens.push({
867
+ type: TokenType.EOF,
868
+ value: "",
869
+ location: { line: this.line, column: this.column, offset: this.position },
870
+ raw: "",
871
+ });
872
+ return this.tokens;
873
+ }
874
+ getTokens() {
875
+ return this.tokens;
876
+ }
877
+ }