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