@isl-lang/repl 0.0.1 → 0.1.0
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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/cli.js +1734 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1867 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +536 -0
- package/dist/index.d.ts +536 -0
- package/dist/index.js +1812 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -14
- package/index.js +0 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an ISL intent definition
|
|
3
|
+
*/
|
|
4
|
+
interface Intent {
|
|
5
|
+
name: string;
|
|
6
|
+
preconditions: Condition[];
|
|
7
|
+
postconditions: Condition[];
|
|
8
|
+
invariants: Condition[];
|
|
9
|
+
scenarios: Scenario[];
|
|
10
|
+
rawSource: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A condition (pre/post/invariant)
|
|
14
|
+
*/
|
|
15
|
+
interface Condition {
|
|
16
|
+
expression: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A scenario for testing
|
|
21
|
+
*/
|
|
22
|
+
interface Scenario {
|
|
23
|
+
name: string;
|
|
24
|
+
given: string[];
|
|
25
|
+
when: string;
|
|
26
|
+
then: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Session configuration
|
|
30
|
+
*/
|
|
31
|
+
interface SessionConfig {
|
|
32
|
+
colors?: boolean;
|
|
33
|
+
verbose?: boolean;
|
|
34
|
+
cwd?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Session state management for the ISL REPL
|
|
38
|
+
*/
|
|
39
|
+
declare class Session {
|
|
40
|
+
/** Defined intents in this session */
|
|
41
|
+
private intents;
|
|
42
|
+
/** Variables set during the session */
|
|
43
|
+
private variables;
|
|
44
|
+
/** Command history */
|
|
45
|
+
private history;
|
|
46
|
+
/** Last evaluation result */
|
|
47
|
+
private lastResult;
|
|
48
|
+
/** Loaded files */
|
|
49
|
+
private loadedFiles;
|
|
50
|
+
/** Session configuration */
|
|
51
|
+
private config;
|
|
52
|
+
constructor(config?: SessionConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Define a new intent
|
|
55
|
+
*/
|
|
56
|
+
defineIntent(intent: Intent): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get an intent by name
|
|
59
|
+
*/
|
|
60
|
+
getIntent(name: string): Intent | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Get all defined intents
|
|
63
|
+
*/
|
|
64
|
+
getAllIntents(): Intent[];
|
|
65
|
+
/**
|
|
66
|
+
* Check if an intent exists
|
|
67
|
+
*/
|
|
68
|
+
hasIntent(name: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Remove an intent
|
|
71
|
+
*/
|
|
72
|
+
removeIntent(name: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get intent names for completion
|
|
75
|
+
*/
|
|
76
|
+
getIntentNames(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Parse an intent definition from source code
|
|
79
|
+
*/
|
|
80
|
+
parseIntent(source: string): Intent | null;
|
|
81
|
+
/**
|
|
82
|
+
* Set a variable
|
|
83
|
+
*/
|
|
84
|
+
setVariable(name: string, value: unknown): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get a variable
|
|
87
|
+
*/
|
|
88
|
+
getVariable(name: string): unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Get all variables
|
|
91
|
+
*/
|
|
92
|
+
getAllVariables(): Map<string, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a variable exists
|
|
95
|
+
*/
|
|
96
|
+
hasVariable(name: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Set the last result (accessible as _)
|
|
99
|
+
*/
|
|
100
|
+
setLastResult(value: unknown): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get the last result
|
|
103
|
+
*/
|
|
104
|
+
getLastResult(): unknown;
|
|
105
|
+
/**
|
|
106
|
+
* Add to history
|
|
107
|
+
*/
|
|
108
|
+
addToHistory(entry: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Get history
|
|
111
|
+
*/
|
|
112
|
+
getHistory(count?: number): string[];
|
|
113
|
+
/**
|
|
114
|
+
* Load intents from an ISL file
|
|
115
|
+
*/
|
|
116
|
+
loadFile(filePath: string): Promise<{
|
|
117
|
+
intents: Intent[];
|
|
118
|
+
errors: string[];
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Parse a behavior block as an intent
|
|
122
|
+
*/
|
|
123
|
+
private parseBehaviorAsIntent;
|
|
124
|
+
/**
|
|
125
|
+
* Export session intents to a file
|
|
126
|
+
*/
|
|
127
|
+
exportToFile(filePath: string): Promise<{
|
|
128
|
+
success: boolean;
|
|
129
|
+
error?: string;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Clear all session state
|
|
133
|
+
*/
|
|
134
|
+
clear(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Get session summary
|
|
137
|
+
*/
|
|
138
|
+
getSummary(): {
|
|
139
|
+
intentCount: number;
|
|
140
|
+
variableCount: number;
|
|
141
|
+
loadedFileCount: number;
|
|
142
|
+
historyCount: number;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Get loaded files
|
|
146
|
+
*/
|
|
147
|
+
getLoadedFiles(): string[];
|
|
148
|
+
/**
|
|
149
|
+
* Get config
|
|
150
|
+
*/
|
|
151
|
+
getConfig(): SessionConfig;
|
|
152
|
+
/**
|
|
153
|
+
* Update config
|
|
154
|
+
*/
|
|
155
|
+
setConfig(config: Partial<SessionConfig>): void;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a new session
|
|
159
|
+
*/
|
|
160
|
+
declare function createSession(config?: SessionConfig): Session;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Command history manager with persistence
|
|
164
|
+
*/
|
|
165
|
+
declare class History {
|
|
166
|
+
private entries;
|
|
167
|
+
private position;
|
|
168
|
+
private maxSize;
|
|
169
|
+
private historyFile;
|
|
170
|
+
private unsavedCount;
|
|
171
|
+
private autoSaveThreshold;
|
|
172
|
+
constructor(options?: {
|
|
173
|
+
maxSize?: number;
|
|
174
|
+
historyFile?: string;
|
|
175
|
+
autoSaveThreshold?: number;
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* Get default history file path
|
|
179
|
+
*/
|
|
180
|
+
private getDefaultHistoryFile;
|
|
181
|
+
/**
|
|
182
|
+
* Load history from file
|
|
183
|
+
*/
|
|
184
|
+
load(): void;
|
|
185
|
+
/**
|
|
186
|
+
* Save history to file
|
|
187
|
+
*/
|
|
188
|
+
save(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Add entry to history
|
|
191
|
+
*/
|
|
192
|
+
add(entry: string): void;
|
|
193
|
+
/**
|
|
194
|
+
* Get previous entry (for up arrow)
|
|
195
|
+
*/
|
|
196
|
+
previous(): string | null;
|
|
197
|
+
/**
|
|
198
|
+
* Get next entry (for down arrow)
|
|
199
|
+
*/
|
|
200
|
+
next(): string | null;
|
|
201
|
+
/**
|
|
202
|
+
* Reset position to end
|
|
203
|
+
*/
|
|
204
|
+
resetPosition(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Search history for entries containing text
|
|
207
|
+
*/
|
|
208
|
+
search(text: string): string[];
|
|
209
|
+
/**
|
|
210
|
+
* Search backwards from current position
|
|
211
|
+
*/
|
|
212
|
+
searchBackward(text: string): string | null;
|
|
213
|
+
/**
|
|
214
|
+
* Search forward from current position
|
|
215
|
+
*/
|
|
216
|
+
searchForward(text: string): string | null;
|
|
217
|
+
/**
|
|
218
|
+
* Get all entries
|
|
219
|
+
*/
|
|
220
|
+
getAll(): string[];
|
|
221
|
+
/**
|
|
222
|
+
* Get recent entries
|
|
223
|
+
*/
|
|
224
|
+
getRecent(count: number): string[];
|
|
225
|
+
/**
|
|
226
|
+
* Clear history
|
|
227
|
+
*/
|
|
228
|
+
clear(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Get history size
|
|
231
|
+
*/
|
|
232
|
+
get size(): number;
|
|
233
|
+
/**
|
|
234
|
+
* Get current position
|
|
235
|
+
*/
|
|
236
|
+
get currentPosition(): number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* In-memory history (no persistence)
|
|
240
|
+
*/
|
|
241
|
+
declare class MemoryHistory extends History {
|
|
242
|
+
constructor(maxSize?: number);
|
|
243
|
+
load(): void;
|
|
244
|
+
save(): void;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface REPLOptions {
|
|
248
|
+
colors?: boolean;
|
|
249
|
+
verbose?: boolean;
|
|
250
|
+
historyFile?: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* ISL REPL - Interactive Read-Eval-Print Loop
|
|
254
|
+
*/
|
|
255
|
+
declare class ISLREPL {
|
|
256
|
+
private session;
|
|
257
|
+
private history;
|
|
258
|
+
private completionProvider;
|
|
259
|
+
private rl;
|
|
260
|
+
private buffer;
|
|
261
|
+
private braceCount;
|
|
262
|
+
private options;
|
|
263
|
+
private running;
|
|
264
|
+
constructor(options?: REPLOptions);
|
|
265
|
+
/**
|
|
266
|
+
* Start the REPL
|
|
267
|
+
*/
|
|
268
|
+
start(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Print the welcome banner
|
|
271
|
+
*/
|
|
272
|
+
private printBanner;
|
|
273
|
+
/**
|
|
274
|
+
* Handle a line of input
|
|
275
|
+
*/
|
|
276
|
+
private handleLine;
|
|
277
|
+
/**
|
|
278
|
+
* Handle a meta command (. prefix)
|
|
279
|
+
*/
|
|
280
|
+
private handleMetaCommand;
|
|
281
|
+
/**
|
|
282
|
+
* Handle an ISL command (: prefix)
|
|
283
|
+
*/
|
|
284
|
+
private handleISLCommand;
|
|
285
|
+
/**
|
|
286
|
+
* Evaluate ISL code
|
|
287
|
+
*/
|
|
288
|
+
private evaluate;
|
|
289
|
+
/**
|
|
290
|
+
* Evaluate an intent definition
|
|
291
|
+
*/
|
|
292
|
+
private evaluateIntent;
|
|
293
|
+
/**
|
|
294
|
+
* Print a parse error with location info
|
|
295
|
+
*/
|
|
296
|
+
private printParseError;
|
|
297
|
+
/**
|
|
298
|
+
* Print an error
|
|
299
|
+
*/
|
|
300
|
+
private printError;
|
|
301
|
+
/**
|
|
302
|
+
* Exit the REPL
|
|
303
|
+
*/
|
|
304
|
+
exit(): void;
|
|
305
|
+
/**
|
|
306
|
+
* Get the session
|
|
307
|
+
*/
|
|
308
|
+
getSession(): Session;
|
|
309
|
+
/**
|
|
310
|
+
* Get history
|
|
311
|
+
*/
|
|
312
|
+
getHistory(): History;
|
|
313
|
+
/**
|
|
314
|
+
* Execute a single command and return result (for testing)
|
|
315
|
+
*/
|
|
316
|
+
executeOnce(input: string): Promise<{
|
|
317
|
+
success: boolean;
|
|
318
|
+
output?: string;
|
|
319
|
+
error?: string;
|
|
320
|
+
}>;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Start the REPL
|
|
324
|
+
*/
|
|
325
|
+
declare function startREPL(options?: REPLOptions): ISLREPL;
|
|
326
|
+
|
|
327
|
+
interface REPL {
|
|
328
|
+
exit(): void;
|
|
329
|
+
getSession(): Session;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Command result
|
|
333
|
+
*/
|
|
334
|
+
interface CommandResult {
|
|
335
|
+
output?: string;
|
|
336
|
+
exit?: boolean;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Meta command definition (. prefix)
|
|
340
|
+
*/
|
|
341
|
+
interface MetaCommand {
|
|
342
|
+
name: string;
|
|
343
|
+
aliases: string[];
|
|
344
|
+
description: string;
|
|
345
|
+
usage: string;
|
|
346
|
+
handler: (args: string[], session: Session, repl: REPL) => CommandResult;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* ISL command definition (: prefix)
|
|
350
|
+
*/
|
|
351
|
+
interface ISLCommand {
|
|
352
|
+
name: string;
|
|
353
|
+
aliases: string[];
|
|
354
|
+
description: string;
|
|
355
|
+
usage: string;
|
|
356
|
+
handler: (args: string[], session: Session, repl: REPL) => CommandResult;
|
|
357
|
+
}
|
|
358
|
+
declare const metaCommands: MetaCommand[];
|
|
359
|
+
declare const islCommands: ISLCommand[];
|
|
360
|
+
/**
|
|
361
|
+
* Find a similar command name
|
|
362
|
+
*/
|
|
363
|
+
declare function findSimilarCommand(input: string, type: 'meta' | 'isl'): string | null;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Completion item
|
|
367
|
+
*/
|
|
368
|
+
interface CompletionItem {
|
|
369
|
+
text: string;
|
|
370
|
+
type: 'command' | 'intent' | 'keyword' | 'variable' | 'file';
|
|
371
|
+
description?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* ISL keywords
|
|
375
|
+
*/
|
|
376
|
+
declare const KEYWORDS: CompletionItem[];
|
|
377
|
+
/**
|
|
378
|
+
* Meta commands (. prefix)
|
|
379
|
+
*/
|
|
380
|
+
declare const META_COMMANDS: CompletionItem[];
|
|
381
|
+
/**
|
|
382
|
+
* ISL commands (: prefix)
|
|
383
|
+
*/
|
|
384
|
+
declare const ISL_COMMANDS: CompletionItem[];
|
|
385
|
+
/**
|
|
386
|
+
* All commands
|
|
387
|
+
*/
|
|
388
|
+
declare const COMMANDS: CompletionItem[];
|
|
389
|
+
/**
|
|
390
|
+
* Provides intelligent completions based on context
|
|
391
|
+
*/
|
|
392
|
+
declare class CompletionProvider {
|
|
393
|
+
private session;
|
|
394
|
+
constructor(session: Session);
|
|
395
|
+
/**
|
|
396
|
+
* Update the session reference
|
|
397
|
+
*/
|
|
398
|
+
setSession(session: Session): void;
|
|
399
|
+
/**
|
|
400
|
+
* Get completions for a line
|
|
401
|
+
*/
|
|
402
|
+
complete(line: string): [CompletionItem[], string];
|
|
403
|
+
/**
|
|
404
|
+
* Complete meta commands
|
|
405
|
+
*/
|
|
406
|
+
private completeMetaCommand;
|
|
407
|
+
/**
|
|
408
|
+
* Complete ISL commands
|
|
409
|
+
*/
|
|
410
|
+
private completeISLCommand;
|
|
411
|
+
/**
|
|
412
|
+
* Complete :gen command arguments
|
|
413
|
+
*/
|
|
414
|
+
private completeGenCommand;
|
|
415
|
+
/**
|
|
416
|
+
* Complete intent names
|
|
417
|
+
*/
|
|
418
|
+
private completeIntentName;
|
|
419
|
+
/**
|
|
420
|
+
* Complete file paths
|
|
421
|
+
*/
|
|
422
|
+
private completeFilePath;
|
|
423
|
+
/**
|
|
424
|
+
* Complete expressions
|
|
425
|
+
*/
|
|
426
|
+
private completeExpression;
|
|
427
|
+
/**
|
|
428
|
+
* Get all available completions (for help)
|
|
429
|
+
*/
|
|
430
|
+
getAllCompletions(): {
|
|
431
|
+
metaCommands: CompletionItem[];
|
|
432
|
+
islCommands: CompletionItem[];
|
|
433
|
+
keywords: CompletionItem[];
|
|
434
|
+
intents: CompletionItem[];
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Create a readline-compatible completer function
|
|
439
|
+
*/
|
|
440
|
+
declare function createCompleter(provider: CompletionProvider): (line: string) => [string[], string];
|
|
441
|
+
|
|
442
|
+
declare const colors: {
|
|
443
|
+
reset: string;
|
|
444
|
+
bold: string;
|
|
445
|
+
dim: string;
|
|
446
|
+
italic: string;
|
|
447
|
+
underline: string;
|
|
448
|
+
black: string;
|
|
449
|
+
red: string;
|
|
450
|
+
green: string;
|
|
451
|
+
yellow: string;
|
|
452
|
+
blue: string;
|
|
453
|
+
magenta: string;
|
|
454
|
+
cyan: string;
|
|
455
|
+
white: string;
|
|
456
|
+
gray: string;
|
|
457
|
+
brightRed: string;
|
|
458
|
+
brightGreen: string;
|
|
459
|
+
brightYellow: string;
|
|
460
|
+
brightBlue: string;
|
|
461
|
+
brightMagenta: string;
|
|
462
|
+
brightCyan: string;
|
|
463
|
+
brightWhite: string;
|
|
464
|
+
bgBlack: string;
|
|
465
|
+
bgRed: string;
|
|
466
|
+
bgGreen: string;
|
|
467
|
+
bgYellow: string;
|
|
468
|
+
bgBlue: string;
|
|
469
|
+
bgMagenta: string;
|
|
470
|
+
bgCyan: string;
|
|
471
|
+
bgWhite: string;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Format a success message
|
|
475
|
+
*/
|
|
476
|
+
declare function formatSuccess(message: string): string;
|
|
477
|
+
/**
|
|
478
|
+
* Format an error message
|
|
479
|
+
*/
|
|
480
|
+
declare function formatError(message: string): string;
|
|
481
|
+
/**
|
|
482
|
+
* Format a warning message
|
|
483
|
+
*/
|
|
484
|
+
declare function formatWarning(message: string): string;
|
|
485
|
+
/**
|
|
486
|
+
* Format an info message
|
|
487
|
+
*/
|
|
488
|
+
declare function formatInfo(message: string): string;
|
|
489
|
+
/**
|
|
490
|
+
* Format an intent for display
|
|
491
|
+
*/
|
|
492
|
+
declare function formatIntent(intent: Intent): string;
|
|
493
|
+
/**
|
|
494
|
+
* Format a condition
|
|
495
|
+
*/
|
|
496
|
+
declare function formatCondition(condition: Condition, type: 'pre' | 'post' | 'invariant'): string;
|
|
497
|
+
/**
|
|
498
|
+
* Highlight an ISL expression
|
|
499
|
+
*/
|
|
500
|
+
declare function highlightExpression(expr: string): string;
|
|
501
|
+
/**
|
|
502
|
+
* Highlight ISL source code
|
|
503
|
+
*/
|
|
504
|
+
declare function highlightISL(source: string): string;
|
|
505
|
+
/**
|
|
506
|
+
* Format a table
|
|
507
|
+
*/
|
|
508
|
+
declare function formatTable(headers: string[], rows: string[][], options?: {
|
|
509
|
+
colors?: boolean;
|
|
510
|
+
}): string;
|
|
511
|
+
/**
|
|
512
|
+
* Format a parse error with caret pointing to position
|
|
513
|
+
*/
|
|
514
|
+
declare function formatParseError(source: string, message: string, line: number, column: number): string;
|
|
515
|
+
/**
|
|
516
|
+
* Format a type error with expected vs actual
|
|
517
|
+
*/
|
|
518
|
+
declare function formatTypeError(message: string, expected: string, actual: string, context?: string): string;
|
|
519
|
+
/**
|
|
520
|
+
* Format a value for display
|
|
521
|
+
*/
|
|
522
|
+
declare function formatValue(value: unknown, indent?: number): string;
|
|
523
|
+
/**
|
|
524
|
+
* Strip ANSI color codes from a string
|
|
525
|
+
*/
|
|
526
|
+
declare function stripColors(str: string): string;
|
|
527
|
+
/**
|
|
528
|
+
* Wrap text to a maximum width
|
|
529
|
+
*/
|
|
530
|
+
declare function wrapText(text: string, maxWidth: number): string;
|
|
531
|
+
/**
|
|
532
|
+
* Draw a box around text
|
|
533
|
+
*/
|
|
534
|
+
declare function drawBox(lines: string[], title?: string): string;
|
|
535
|
+
|
|
536
|
+
export { COMMANDS, type CommandResult, type CompletionItem, CompletionProvider, type Condition, History, type ISLCommand, ISLREPL, ISL_COMMANDS, type Intent, KEYWORDS, META_COMMANDS, MemoryHistory, type MetaCommand, type REPLOptions, type Scenario, Session, type SessionConfig, colors, createCompleter, createSession, drawBox, findSimilarCommand, formatCondition, formatError, formatInfo, formatIntent, formatParseError, formatSuccess, formatTable, formatTypeError, formatValue, formatWarning, highlightExpression, highlightISL, islCommands, metaCommands, startREPL, stripColors, wrapText };
|