@aigne/ash 0.0.1 → 0.0.2-beta.1

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 (66) hide show
  1. package/dist/ast.d.cts +13 -5
  2. package/dist/ast.d.cts.map +1 -1
  3. package/dist/ast.d.mts +13 -5
  4. package/dist/ast.d.mts.map +1 -1
  5. package/dist/compiler.cjs +27 -0
  6. package/dist/compiler.d.cts.map +1 -1
  7. package/dist/compiler.d.mts.map +1 -1
  8. package/dist/compiler.mjs +27 -0
  9. package/dist/compiler.mjs.map +1 -1
  10. package/dist/lexer.cjs +2 -1
  11. package/dist/lexer.d.cts +1 -1
  12. package/dist/lexer.d.cts.map +1 -1
  13. package/dist/lexer.d.mts +1 -1
  14. package/dist/lexer.d.mts.map +1 -1
  15. package/dist/lexer.mjs +2 -1
  16. package/dist/lexer.mjs.map +1 -1
  17. package/dist/parser.cjs +75 -1
  18. package/dist/parser.d.cts.map +1 -1
  19. package/dist/parser.d.mts.map +1 -1
  20. package/dist/parser.mjs +75 -1
  21. package/dist/parser.mjs.map +1 -1
  22. package/dist/type-checker.cjs +6 -0
  23. package/dist/type-checker.d.cts.map +1 -1
  24. package/dist/type-checker.d.mts.map +1 -1
  25. package/dist/type-checker.mjs +6 -0
  26. package/dist/type-checker.mjs.map +1 -1
  27. package/package.json +7 -1
  28. package/DESIGN.md +0 -41
  29. package/src/ai-dev-loop/ash-run-result.test.ts +0 -113
  30. package/src/ai-dev-loop/ash-run-result.ts +0 -46
  31. package/src/ai-dev-loop/ash-typed-error.test.ts +0 -136
  32. package/src/ai-dev-loop/ash-typed-error.ts +0 -50
  33. package/src/ai-dev-loop/ash-validate.test.ts +0 -54
  34. package/src/ai-dev-loop/ash-validate.ts +0 -34
  35. package/src/ai-dev-loop/dev-loop.test.ts +0 -364
  36. package/src/ai-dev-loop/dev-loop.ts +0 -156
  37. package/src/ai-dev-loop/dry-run.test.ts +0 -107
  38. package/src/ai-dev-loop/e2e-multi-fix.test.ts +0 -473
  39. package/src/ai-dev-loop/e2e.test.ts +0 -324
  40. package/src/ai-dev-loop/index.ts +0 -15
  41. package/src/ai-dev-loop/invariants.test.ts +0 -253
  42. package/src/ai-dev-loop/live-mode.test.ts +0 -63
  43. package/src/ai-dev-loop/live-mode.ts +0 -33
  44. package/src/ai-dev-loop/meta-tools.test.ts +0 -120
  45. package/src/ai-dev-loop/meta-tools.ts +0 -142
  46. package/src/ai-dev-loop/structured-runner.test.ts +0 -159
  47. package/src/ai-dev-loop/structured-runner.ts +0 -209
  48. package/src/ai-dev-loop/system-prompt.test.ts +0 -102
  49. package/src/ai-dev-loop/system-prompt.ts +0 -81
  50. package/src/ast.ts +0 -186
  51. package/src/compiler.test.ts +0 -2933
  52. package/src/compiler.ts +0 -1103
  53. package/src/e2e.test.ts +0 -552
  54. package/src/index.ts +0 -16
  55. package/src/lexer.test.ts +0 -538
  56. package/src/lexer.ts +0 -222
  57. package/src/parser.test.ts +0 -1024
  58. package/src/parser.ts +0 -835
  59. package/src/reference.test.ts +0 -166
  60. package/src/reference.ts +0 -125
  61. package/src/template.test.ts +0 -210
  62. package/src/template.ts +0 -139
  63. package/src/type-checker.test.ts +0 -1494
  64. package/src/type-checker.ts +0 -785
  65. package/tsconfig.json +0 -9
  66. package/tsdown.config.ts +0 -12
package/src/lexer.ts DELETED
@@ -1,222 +0,0 @@
1
- export type TokenType =
2
- | "JOB" | "FIND" | "WHERE" | "MAP" | "SAVE" | "PUBLISH" | "TEE" | "FANOUT" | "INPUT" | "OUTPUT"
3
- | "ACTION" | "ROUTE" | "LOOKUP" | "ARROW"
4
- | "PLUS" | "MINUS" | "STAR" | "SLASH"
5
- | "PIPE" | "ASSIGN" | "DOT" | "COMMA" | "COLON"
6
- | "LPAREN" | "RPAREN" | "LBRACKET" | "RBRACKET" | "LBRACE" | "RBRACE"
7
- | "IDENTIFIER" | "STRING" | "NUMBER" | "PATH" | "AT"
8
- | "GT" | "LT" | "GTE" | "LTE" | "EQ" | "NEQ"
9
- | "LET" | "PARAM" | "ON" | "DOLLAR" | "COUNT" | "GROUP_BY"
10
- | "NEWLINE" | "EOF";
11
-
12
- export interface Token {
13
- type: TokenType;
14
- value: string;
15
- line: number;
16
- column: number;
17
- }
18
-
19
- const KEYWORDS: Record<string, TokenType> = {
20
- job: "JOB",
21
- find: "FIND",
22
- where: "WHERE",
23
- map: "MAP",
24
- save: "SAVE",
25
- publish: "PUBLISH",
26
- tee: "TEE",
27
- fanout: "FANOUT",
28
- input: "INPUT",
29
- output: "OUTPUT",
30
- let: "LET",
31
- count: "COUNT",
32
- action: "ACTION",
33
- route: "ROUTE",
34
- lookup: "LOOKUP",
35
- param: "PARAM",
36
- on: "ON",
37
- };
38
-
39
- export class AshLexer {
40
- tokenize(source: string): Token[] {
41
- const tokens: Token[] = [];
42
- let pos = 0;
43
- let line = 1;
44
- let col = 1;
45
-
46
- while (pos < source.length) {
47
- const ch = source[pos];
48
-
49
- // Newline
50
- if (ch === "\n" || ch === "\r") {
51
- if (ch === "\r" && source[pos + 1] === "\n") pos++;
52
- tokens.push({ type: "NEWLINE", value: "\\n", line, column: col });
53
- pos++;
54
- line++;
55
- col = 1;
56
- continue;
57
- }
58
-
59
- // Whitespace (skip)
60
- if (ch === " " || ch === "\t") {
61
- pos++;
62
- col++;
63
- continue;
64
- }
65
-
66
- // Comment: # to end of line
67
- if (ch === "#") {
68
- while (pos < source.length && source[pos] !== "\n" && source[pos] !== "\r") {
69
- pos++;
70
- col++;
71
- }
72
- continue;
73
- }
74
-
75
- // String literal
76
- if (ch === '"') {
77
- const startCol = col;
78
- pos++; col++;
79
- let value = "";
80
- while (pos < source.length && source[pos] !== '"') {
81
- if (source[pos] === "\\") {
82
- pos++; col++;
83
- if (pos >= source.length) break;
84
- const escaped = source[pos];
85
- if (escaped === '"') value += '"';
86
- else if (escaped === "\\") value += "\\";
87
- else if (escaped === "n") value += "\n";
88
- else if (escaped === "t") value += "\t";
89
- else if (escaped === "$") value += "\\$"; // preserve for template escape detection
90
- else value += escaped;
91
- } else {
92
- if (source[pos] === "\n") {
93
- throw new Error(`Unterminated string at line ${line}, column ${startCol}`);
94
- }
95
- value += source[pos];
96
- }
97
- pos++; col++;
98
- }
99
- if (pos >= source.length) {
100
- throw new Error(`Unterminated string at line ${line}, column ${startCol}`);
101
- }
102
- pos++; col++; // closing quote
103
- tokens.push({ type: "STRING", value, line, column: startCol });
104
- continue;
105
- }
106
-
107
- // Number
108
- if (ch >= "0" && ch <= "9") {
109
- const startCol = col;
110
- let num = "";
111
- while (pos < source.length && ((source[pos] >= "0" && source[pos] <= "9") || source[pos] === ".")) {
112
- num += source[pos];
113
- pos++; col++;
114
- }
115
- tokens.push({ type: "NUMBER", value: num, line, column: startCol });
116
- continue;
117
- }
118
-
119
- // Path or SLASH: `/` followed by a letter, `.`, `_`, or `/` starts a PATH; otherwise SLASH
120
- if (ch === "/") {
121
- const next = source[pos + 1];
122
- if (next !== undefined && ((next >= "a" && next <= "z") || (next >= "A" && next <= "Z") || next === "_" || next === "." || next === "/")) {
123
- const startCol = col;
124
- let path = "";
125
- while (pos < source.length && source[pos] !== " " && source[pos] !== "\t" && source[pos] !== "\n" && source[pos] !== "\r" && source[pos] !== "|" && source[pos] !== "}" && source[pos] !== ")" && source[pos] !== "," && source[pos] !== ":") {
126
- // Handle ${...} template blocks atomically — don't stop at } inside template
127
- if (source[pos] === "$" && pos + 1 < source.length && source[pos + 1] === "{") {
128
- path += source[pos]; pos++; col++; // $
129
- path += source[pos]; pos++; col++; // {
130
- while (pos < source.length && source[pos] !== "}") {
131
- path += source[pos]; pos++; col++;
132
- }
133
- if (pos < source.length) {
134
- path += source[pos]; pos++; col++; // closing }
135
- }
136
- continue;
137
- }
138
- path += source[pos];
139
- pos++; col++;
140
- }
141
- tokens.push({ type: "PATH", value: path, line, column: startCol });
142
- continue;
143
- }
144
- tokens.push({ type: "SLASH", value: "/", line, column: col }); pos++; col++; continue;
145
- }
146
-
147
- // Identifier / keyword
148
- if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || ch === "_") {
149
- const startCol = col;
150
- let ident = "";
151
- while (pos < source.length && ((source[pos] >= "a" && source[pos] <= "z") || (source[pos] >= "A" && source[pos] <= "Z") || (source[pos] >= "0" && source[pos] <= "9") || source[pos] === "_")) {
152
- ident += source[pos];
153
- pos++; col++;
154
- }
155
- // Handle compound keyword: group-by
156
- if (ident === "group" && pos < source.length && source[pos] === "-") {
157
- const rest = source.slice(pos + 1, pos + 3);
158
- if (rest === "by") {
159
- pos += 3; col += 3;
160
- tokens.push({ type: "GROUP_BY", value: "group-by", line, column: startCol });
161
- continue;
162
- }
163
- }
164
- const kw = Object.hasOwn(KEYWORDS, ident) ? KEYWORDS[ident] : undefined;
165
- tokens.push({ type: kw ?? "IDENTIFIER", value: ident, line, column: startCol });
166
- continue;
167
- }
168
-
169
- // Operators and punctuation
170
- // Arithmetic operators
171
- if (ch === "+") { tokens.push({ type: "PLUS", value: "+", line, column: col }); pos++; col++; continue; }
172
- if (ch === "-") {
173
- if (source[pos + 1] === ">") {
174
- tokens.push({ type: "ARROW", value: "->", line, column: col }); pos += 2; col += 2; continue;
175
- }
176
- tokens.push({ type: "MINUS", value: "-", line, column: col }); pos++; col++; continue;
177
- }
178
- if (ch === "*") { tokens.push({ type: "STAR", value: "*", line, column: col }); pos++; col++; continue; }
179
-
180
- if (ch === "|") { tokens.push({ type: "PIPE", value: "|", line, column: col }); pos++; col++; continue; }
181
- if (ch === "=") {
182
- if (source[pos + 1] === "=") {
183
- tokens.push({ type: "EQ", value: "==", line, column: col }); pos += 2; col += 2; continue;
184
- }
185
- tokens.push({ type: "ASSIGN", value: "=", line, column: col }); pos++; col++; continue;
186
- }
187
- if (ch === "!") {
188
- if (source[pos + 1] === "=") {
189
- tokens.push({ type: "NEQ", value: "!=", line, column: col }); pos += 2; col += 2; continue;
190
- }
191
- }
192
- if (ch === ">") {
193
- if (source[pos + 1] === "=") {
194
- tokens.push({ type: "GTE", value: ">=", line, column: col }); pos += 2; col += 2; continue;
195
- }
196
- tokens.push({ type: "GT", value: ">", line, column: col }); pos++; col++; continue;
197
- }
198
- if (ch === "<") {
199
- if (source[pos + 1] === "=") {
200
- tokens.push({ type: "LTE", value: "<=", line, column: col }); pos += 2; col += 2; continue;
201
- }
202
- tokens.push({ type: "LT", value: "<", line, column: col }); pos++; col++; continue;
203
- }
204
- if (ch === ".") { tokens.push({ type: "DOT", value: ".", line, column: col }); pos++; col++; continue; }
205
- if (ch === ",") { tokens.push({ type: "COMMA", value: ",", line, column: col }); pos++; col++; continue; }
206
- if (ch === "(") { tokens.push({ type: "LPAREN", value: "(", line, column: col }); pos++; col++; continue; }
207
- if (ch === ")") { tokens.push({ type: "RPAREN", value: ")", line, column: col }); pos++; col++; continue; }
208
- if (ch === "[") { tokens.push({ type: "LBRACKET", value: "[", line, column: col }); pos++; col++; continue; }
209
- if (ch === "]") { tokens.push({ type: "RBRACKET", value: "]", line, column: col }); pos++; col++; continue; }
210
- if (ch === "{") { tokens.push({ type: "LBRACE", value: "{", line, column: col }); pos++; col++; continue; }
211
- if (ch === "}") { tokens.push({ type: "RBRACE", value: "}", line, column: col }); pos++; col++; continue; }
212
- if (ch === "@") { tokens.push({ type: "AT", value: "@", line, column: col }); pos++; col++; continue; }
213
- if (ch === "$") { tokens.push({ type: "DOLLAR", value: "$", line, column: col }); pos++; col++; continue; }
214
- if (ch === ":") { tokens.push({ type: "COLON", value: ":", line, column: col }); pos++; col++; continue; }
215
-
216
- throw new Error(`Unrecognized character '${ch}' at line ${line}, column ${col}`);
217
- }
218
-
219
- tokens.push({ type: "EOF", value: "", line, column: col });
220
- return tokens;
221
- }
222
- }