@qodalis/cli-core 0.0.16 → 2.0.0-beta.10

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 (53) hide show
  1. package/README.md +610 -38
  2. package/package.json +16 -23
  3. package/public-api.d.mts +2771 -0
  4. package/public-api.d.ts +2771 -8
  5. package/public-api.js +3692 -0
  6. package/public-api.js.map +1 -0
  7. package/public-api.mjs +3635 -0
  8. package/public-api.mjs.map +1 -0
  9. package/esm2022/lib/constants/index.mjs +0 -8
  10. package/esm2022/lib/interfaces/command-hooks.mjs +0 -2
  11. package/esm2022/lib/interfaces/command-processor.mjs +0 -2
  12. package/esm2022/lib/interfaces/execution-context.mjs +0 -2
  13. package/esm2022/lib/interfaces/index.mjs +0 -6
  14. package/esm2022/lib/interfaces/progress-bars.mjs +0 -2
  15. package/esm2022/lib/interfaces/users.mjs +0 -2
  16. package/esm2022/lib/models/index.mjs +0 -175
  17. package/esm2022/lib/models/services.mjs +0 -2
  18. package/esm2022/lib/models/users.mjs +0 -2
  19. package/esm2022/lib/modules/index.mjs +0 -30
  20. package/esm2022/lib/themes/index.mjs +0 -221
  21. package/esm2022/lib/types/CancellablePromise.mjs +0 -28
  22. package/esm2022/lib/types/index.mjs +0 -2
  23. package/esm2022/lib/utils/delay.mjs +0 -4
  24. package/esm2022/lib/utils/index.mjs +0 -81
  25. package/esm2022/lib/utils/object-describer.mjs +0 -134
  26. package/esm2022/lib/utils/terminal-utils.mjs +0 -16
  27. package/esm2022/lib/utils/version-utils.mjs +0 -25
  28. package/esm2022/lib/version.mjs +0 -3
  29. package/esm2022/public-api.mjs +0 -12
  30. package/esm2022/qodalis-cli-core.mjs +0 -5
  31. package/fesm2022/qodalis-cli-core.mjs +0 -722
  32. package/fesm2022/qodalis-cli-core.mjs.map +0 -1
  33. package/index.d.ts +0 -5
  34. package/lib/constants/index.d.ts +0 -5
  35. package/lib/interfaces/command-hooks.d.ts +0 -5
  36. package/lib/interfaces/command-processor.d.ts +0 -151
  37. package/lib/interfaces/execution-context.d.ts +0 -109
  38. package/lib/interfaces/index.d.ts +0 -349
  39. package/lib/interfaces/progress-bars.d.ts +0 -72
  40. package/lib/interfaces/users.d.ts +0 -42
  41. package/lib/models/index.d.ts +0 -303
  42. package/lib/models/services.d.ts +0 -20
  43. package/lib/models/users.d.ts +0 -30
  44. package/lib/modules/index.d.ts +0 -6
  45. package/lib/themes/index.d.ts +0 -16
  46. package/lib/types/CancellablePromise.d.ts +0 -8
  47. package/lib/types/index.d.ts +0 -1
  48. package/lib/utils/delay.d.ts +0 -1
  49. package/lib/utils/index.d.ts +0 -25
  50. package/lib/utils/object-describer.d.ts +0 -12
  51. package/lib/utils/terminal-utils.d.ts +0 -7
  52. package/lib/utils/version-utils.d.ts +0 -9
  53. package/lib/version.d.ts +0 -1
@@ -0,0 +1,2771 @@
1
+ import { ITerminalOptions, ITerminalInitOnlyOptions, Terminal, ITheme } from '@xterm/xterm';
2
+ import { Subject, Observable, Subscription } from 'rxjs';
3
+
4
+ type CliProcessCommand = {
5
+ /**
6
+ * The command that was entered
7
+ */
8
+ command: string;
9
+ /**
10
+ * Pipeline data passed from the previous command in a pipe chain.
11
+ * When commands are piped (e.g. `cmd1 | cmd2`), the output of `cmd1`
12
+ * is captured and passed here as input to `cmd2`. The shape depends
13
+ * on what the upstream command produced (string, JSON object, array, etc.).
14
+ */
15
+ data?: any;
16
+ /**
17
+ * The chain of commands that were entered
18
+ */
19
+ chainCommands: string[];
20
+ /**
21
+ * The raw command that was entered
22
+ */
23
+ rawCommand: string;
24
+ /**
25
+ * The value of the command
26
+ */
27
+ value?: string;
28
+ /**
29
+ * The arguments that were entered
30
+ */
31
+ args: Record<string, any>;
32
+ };
33
+
34
+ declare enum CliForegroundColor {
35
+ Black = "\u001B[30m",
36
+ Red = "\u001B[31m",
37
+ Green = "\u001B[32m",
38
+ Yellow = "\u001B[33m",
39
+ Blue = "\u001B[34m",
40
+ Magenta = "\u001B[35m",
41
+ Cyan = "\u001B[36m",
42
+ White = "\u001B[37m",
43
+ Reset = "\u001B[0m"
44
+ }
45
+ declare enum CliBackgroundColor {
46
+ Black = "\u001B[40m",
47
+ Red = "\u001B[41m",
48
+ Green = "\u001B[42m",
49
+ Yellow = "\u001B[43m",
50
+ Blue = "\u001B[44m",
51
+ Magenta = "\u001B[45m",
52
+ Cyan = "\u001B[46m",
53
+ White = "\u001B[47m"
54
+ }
55
+
56
+ declare enum CliIcon {
57
+ CheckIcon = "\u2714",// Success, completion
58
+ CrossIcon = "\u2718",// Failure, error
59
+ InfoIcon = "\u2139",// Information
60
+ WarningIcon = "\u26A0",// Warning
61
+ QuestionMark = "?",// Help or unknown state
62
+ Exclamation = "\u2757",// Emphasis or alert
63
+ Ellipsis = "\u2026",// Loading or truncated text
64
+ Dot = "\u2022",// List item
65
+ Bullet = "\u2023",// Alternate bullet point
66
+ ArrowRight = "\u2192",// Navigation or next step
67
+ ArrowLeft = "\u2190",// Previous step or navigation
68
+ ArrowUp = "\u2191",// Up direction
69
+ ArrowDown = "\u2193",// Down direction
70
+ ArrowRightFilled = "\u25B6",// Navigation or next step (filled)
71
+ ArrowLeftFilled = "\u25C0",// Previous step or navigation (filled)
72
+ ArrowUpFilled = "\u25B2",// Up direction (filled)
73
+ ArrowDownFilled = "\u25BC",// Down direction (filled)
74
+ DoubleArrowRight = "\u00BB",// Fast forward or next
75
+ DoubleArrowLeft = "\u00AB",// Rewind or previous
76
+ Star = "\u2605",// Highlight or favorite (filled)
77
+ StarEmpty = "\u2606",// Highlight or favorite (empty)
78
+ Plus = "+",// Addition or increment
79
+ Minus = "-",// Subtraction or decrement
80
+ Progress = "\u23F3",// Indicating progress
81
+ Success = "\u2705",// Success (alternative to CheckIcon)
82
+ Failure = "\u274C",// Failure (alternative to CrossIcon)
83
+ Clock = "\u23F0",// Time-related
84
+ Timer = "\u23F1",// Stopwatch or timer
85
+ Alarm = "\uD83D\uDD14",// Alarm or alert
86
+ Calendar = "\uD83D\uDCC5",// Calendar or date
87
+ Folder = "\uD83D\uDCC1",// Directory or file grouping
88
+ FolderOpen = "\uD83D\uDCC2",// Open folder
89
+ File = "\uD83D\uDCC4",// File or document
90
+ Archive = "\uD83D\uDDC3",// Archive or file grouping
91
+ Link = "\uD83D\uDD17",// Hyperlink or connection
92
+ Chain = "\u26D3",// Chain or linked
93
+ Bookmark = "\uD83D\uDD16",// Bookmark or save
94
+ Edit = "\u270F",// Edit or modify
95
+ Trash = "\uD83D\uDDD1",// Deletion or removal
96
+ Add = "\u2795",// Add user or item
97
+ Remove = "\u2796",// Remove user or item
98
+ Reload = "\uD83D\uDD04",// Refresh or reload
99
+ Save = "\uD83D\uDCBE",// Save or store
100
+ Undo = "\u21A9",// Undo action
101
+ Redo = "\u21AA",// Redo action
102
+ Play = "\u25B6",// Start or play
103
+ Pause = "\u23F8",// Pause or stop temporarily
104
+ Stop = "\u23F9",// Stop or end
105
+ Cancel = "\u274E",// Cancel or close
106
+ User = "\uD83D\uDC64",// User or profile
107
+ Group = "\uD83D\uDC65",// Group or team
108
+ Lock = "\uD83D\uDD12",// Secured or locked
109
+ Unlock = "\uD83D\uDD13",// Unlocked or accessible
110
+ Help = "\u2753",// Help or support
111
+ Key = "\uD83D\uDD11",// Authentication or key
112
+ Shield = "\uD83D\uDEE1",// Security or protection
113
+ Gear = "\u2699",// Settings or configuration
114
+ Settings = "\u2699\uFE0F",// Settings (alternative)
115
+ Theme = "\uD83C\uDFA8",// Theme or appearance
116
+ Light = "\uD83D\uDCA1",// Light mode
117
+ Bug = "\uD83D\uDC1E",// Bug or issue
118
+ Wrench = "\uD83D\uDD27",// Maintenance or tools
119
+ Hammer = "\uD83D\uDD28",// Build or fix
120
+ Terminal = "\uD83D\uDCBB",// Terminal or command line
121
+ Database = "\uD83D\uDDC4",// Database or storage
122
+ Server = "\uD83D\uDDA5",// Server or host
123
+ Cloud = "\u2601",// Cloud or remote
124
+ Network = "\uD83C\uDF10",// Network or connection
125
+ Monitor = "\uD83D\uDCFA",// Monitor or display
126
+ Printer = "\uD83D\uDDA8",// Printer or output
127
+ USB = "\uD83D\uDD0C",// USB or connection
128
+ Speaker = "\uD83D\uDD0A",// Speaker or audio
129
+ Microphone = "\uD83C\uDF99",// Microphone or input
130
+ Camera = "\uD83D\uDCF7",// Camera or video
131
+ Video = "\uD83C\uDFA5",// Video or media
132
+ Music = "\uD83C\uDFB5",// Music or audio
133
+ Phone = "\uD83D\uDCDE",// Phone or communication
134
+ Package = "\uD83D\uDCE6",// Package or bundle
135
+ Plugin = "\uD83E\uDDE9",// Plugin or extension
136
+ Extension = "\uD83D\uDD0C",// Extension or connection
137
+ Module = "\uD83E\uDDF1",// Module or package
138
+ Evaluate = "\uD83D\uDD0D",// Evaluate or search
139
+ Variable = "\uD835\uDC65",// Variable or setting
140
+ Script = "\uD83D\uDCDC",// Script or code
141
+ Code = "\uD83D\uDCDD",// Code or file
142
+ Logs = "\uD83D\uDCCB",// Logs or history
143
+ Power = "\u23FB",// On/Off state
144
+ Heart = "\u2764",// Love or favorite
145
+ Flame = "\uD83D\uDD25",// Trending or hot
146
+ Growth = "\uD83D\uDCC8",// Growth or increase
147
+ Decline = "\uD83D\uDCC9",// Decline or decrease
148
+ WarningFilled = "\u26A0\uFE0F",// Warning (filled)
149
+ Sun = "\u2600",// Brightness or day
150
+ Moon = "\uD83C\uDF19",// Night or dark mode
151
+ Rain = "\uD83C\uDF27",// Rain or bad weather
152
+ Snow = "\u2744",// Snow or cold
153
+ Lightning = "\u26A1",// Lightning or danger
154
+ Tree = "\uD83C\uDF32",// Nature or environment
155
+ Smile = "\uD83D\uDE0A",// Happiness or positive state
156
+ Sad = "\uD83D\uDE22",// Sadness or negative state
157
+ Angry = "\uD83D\uDE21",// Anger or frustration
158
+ Clap = "\uD83D\uDC4F",// Applause or celebration
159
+ ThumbsUp = "\uD83D\uDC4D",// Approval or success
160
+ ThumbsDown = "\uD83D\uDC4E",// Disapproval or failure
161
+ Rocket = "\uD83D\uDE80",// Launch or deploy
162
+ Globe = "\uD83C\uDF0D",// Earth or international
163
+ Medal = "\uD83C\uDFC5",// Achievement or award
164
+ Trophy = "\uD83C\uDFC6",// Winner or champion
165
+ Flag = "\uD83D\uDEA9",// Mark or flag
166
+ StarFilled = "\u2B50",// Highlight or favorite
167
+ StarOutline = "\u2729",// Alternate star icon
168
+ Fireworks = "\uD83C\uDF86",// Celebration
169
+ Balloon = "\uD83C\uDF88",// Party or fun
170
+ Gift = "\uD83C\uDF81"
171
+ }
172
+
173
+ /**
174
+ * Configuration for a remote CLI server
175
+ */
176
+ type CliServerConfig = {
177
+ /** Unique identifier, used for namespacing commands */
178
+ name: string;
179
+ /** Base URL of the server, e.g. "https://api.example.com" */
180
+ url: string;
181
+ /** Whether this server is enabled. @default true */
182
+ enabled?: boolean;
183
+ /** Custom headers sent with every request (e.g. auth tokens) */
184
+ headers?: Record<string, string>;
185
+ /** Request timeout in milliseconds. @default 30000 */
186
+ timeout?: number;
187
+ };
188
+ /**
189
+ * A single output item in a server response
190
+ */
191
+ type CliServerOutput = {
192
+ type: 'text';
193
+ value: string;
194
+ style?: 'success' | 'error' | 'info' | 'warning';
195
+ } | {
196
+ type: 'table';
197
+ headers: string[];
198
+ rows: string[][];
199
+ } | {
200
+ type: 'list';
201
+ items: string[];
202
+ ordered?: boolean;
203
+ } | {
204
+ type: 'json';
205
+ value: any;
206
+ } | {
207
+ type: 'key-value';
208
+ entries: {
209
+ key: string;
210
+ value: string;
211
+ }[];
212
+ };
213
+ /**
214
+ * Structured response from a server command execution
215
+ */
216
+ type CliServerResponse = {
217
+ exitCode: number;
218
+ outputs: CliServerOutput[];
219
+ };
220
+ /**
221
+ * Metadata about a remote command processor, returned by GET /api/qcli/commands
222
+ */
223
+ type CliServerCommandDescriptor = {
224
+ command: string;
225
+ description?: string;
226
+ version?: string;
227
+ parameters?: {
228
+ name: string;
229
+ aliases?: string[];
230
+ description: string;
231
+ required: boolean;
232
+ type: string;
233
+ defaultValue?: any;
234
+ }[];
235
+ processors?: CliServerCommandDescriptor[];
236
+ };
237
+ /**
238
+ * Server capabilities returned by GET /api/qcli/capabilities
239
+ */
240
+ type CliServerCapabilities = {
241
+ /** Whether this server supports remote shell access */
242
+ shell: boolean;
243
+ /** Server operating system (e.g. "linux", "win32", "darwin") */
244
+ os?: string;
245
+ /** Path to the shell binary on the server */
246
+ shellPath?: string;
247
+ /** Server version string */
248
+ version?: string;
249
+ /** Whether this server supports SSE streaming execution */
250
+ streaming?: boolean;
251
+ };
252
+
253
+ /**
254
+ * Represents a package source for the CLI package manager
255
+ */
256
+ interface CliPackageSource {
257
+ /**
258
+ * The name of the source, e.g. 'local', 'unpkg', 'jsdelivr'
259
+ */
260
+ name: string;
261
+ /**
262
+ * The base URL for fetching package files, e.g. 'http://localhost:3000/'
263
+ */
264
+ url: string;
265
+ /**
266
+ * The kind of source.
267
+ * - 'registry': npm-compatible registry with search API (e.g. npmjs.org, Verdaccio)
268
+ * - 'file': static file server, packages are discovered by probing known paths
269
+ * @default 'file'
270
+ */
271
+ kind?: 'registry' | 'file';
272
+ }
273
+ /**
274
+ * Represents a log level for the CLI
275
+ */
276
+ declare enum CliLogLevel {
277
+ None = 0,
278
+ DEBUG = 1,
279
+ LOG = 2,
280
+ INFO = 3,
281
+ WARN = 4,
282
+ ERROR = 5
283
+ }
284
+ /**
285
+ * Options for the CLI
286
+ */
287
+ type CliOptions = Record<string, any> & {
288
+ /**
289
+ * Custom terminal options
290
+ */
291
+ terminalOptions?: ITerminalOptions & ITerminalInitOnlyOptions;
292
+ /**
293
+ * The minimum log level to display
294
+ */
295
+ logLevel?: CliLogLevel;
296
+ /**
297
+ * Custom package sources for the package manager.
298
+ * Built-in sources (unpkg, jsdelivr) are always available.
299
+ */
300
+ packageSources?: {
301
+ /**
302
+ * Name of the primary source. Defaults to 'unpkg'.
303
+ */
304
+ primary?: string;
305
+ /**
306
+ * Additional custom sources
307
+ */
308
+ sources?: CliPackageSource[];
309
+ };
310
+ /**
311
+ * Remote CLI servers to connect to.
312
+ * Commands from each server are discovered and registered as proxy processors.
313
+ */
314
+ servers?: CliServerConfig[];
315
+ /**
316
+ * Whether the `eval` / `js` / `calc` command is enabled.
317
+ * Disabled by default because it runs arbitrary JavaScript via `eval()`
318
+ * in the host page context — a security risk in multi-tenant or
319
+ * user-facing deployments.
320
+ * @default false
321
+ */
322
+ allowEval?: boolean;
323
+ };
324
+ /**
325
+ * Represents a package that can be installed
326
+ */
327
+ interface Package {
328
+ /**
329
+ * The name of the package
330
+ */
331
+ name: string;
332
+ /**
333
+ * The global name used to access the package
334
+ */
335
+ globalName?: string;
336
+ /**
337
+ * The version of the package
338
+ */
339
+ version: string;
340
+ /**
341
+ * The unpkg url to the package
342
+ */
343
+ url: string;
344
+ /**
345
+ * The dependencies for the module
346
+ */
347
+ dependencies?: Package[];
348
+ }
349
+ /**
350
+ * Represents command processor metadata
351
+ */
352
+ type CliProcessorMetadata = Record<string, any> & {
353
+ /**
354
+ * If true, the processor is sealed and cannot be replaced or removed.
355
+ * Sealed processors can still be extended (wrapped) by processors with `extendsProcessor = true`.
356
+ */
357
+ sealed?: boolean;
358
+ /**
359
+ * If true, the processor requires the server to be running
360
+ */
361
+ requireServer?: boolean;
362
+ /**
363
+ * The module the processor belongs to
364
+ */
365
+ module?: string;
366
+ /**
367
+ * An icon to display for the processor
368
+ */
369
+ icon?: CliIcon | string;
370
+ /**
371
+ * The minimum required version of @qodalis/cli-core for this processor.
372
+ * If the installed core version is lower, the processor will be skipped during boot.
373
+ */
374
+ requiredCoreVersion?: string;
375
+ /**
376
+ * The minimum required version of @qodalis/cli for this processor.
377
+ * If the installed CLI version is lower, the processor will be skipped during boot.
378
+ */
379
+ requiredCliVersion?: string;
380
+ /**
381
+ * If true, the processor is hidden from the help command listing.
382
+ * The command still works when typed directly and `help <command>` still shows its details.
383
+ */
384
+ hidden?: boolean;
385
+ };
386
+ /**
387
+ * Represents a state configuration for the CLI processor
388
+ */
389
+ type CliStateConfiguration = {
390
+ /**
391
+ * The initial state for the processor
392
+ */
393
+ initialState: Record<string, any>;
394
+ /**
395
+ * The store identifier for the processor, if any
396
+ * @remarks If the store identifier is not set, the processor command name is used
397
+ */
398
+ storeName?: string;
399
+ };
400
+ type CliState = Record<string, any>;
401
+ /**
402
+ * Position of the CLI panel relative to the viewport edge.
403
+ * - `'bottom'` — anchored to the bottom (default)
404
+ * - `'top'` — anchored to the top
405
+ * - `'left'` — anchored to the left (vertical layout)
406
+ * - `'right'` — anchored to the right (vertical layout)
407
+ */
408
+ type CliPanelPosition = 'bottom' | 'top' | 'left' | 'right';
409
+ /**
410
+ * Alignment of the hidden-mode tab along its viewport edge.
411
+ * - `'start'` — left for horizontal panels, top for vertical panels
412
+ * - `'center'` — centered along the edge (default)
413
+ * - `'end'` — right for horizontal panels, bottom for vertical panels
414
+ */
415
+ type CliPanelHideAlignment = 'start' | 'center' | 'end';
416
+ /**
417
+ * Configuration for the CLI panel component.
418
+ */
419
+ interface CliPanelConfig {
420
+ /**
421
+ * Whether the CLI should be collapsed by default.
422
+ * @default true
423
+ */
424
+ isCollapsed?: boolean;
425
+ /**
426
+ * Whether the panel starts hidden (showing only the small tab/arrow).
427
+ * @default false
428
+ */
429
+ isHidden?: boolean;
430
+ /**
431
+ * Position of the panel relative to the viewport.
432
+ * @default 'bottom'
433
+ */
434
+ position?: CliPanelPosition;
435
+ /**
436
+ * Whether the close button is shown.
437
+ * @default true
438
+ */
439
+ closable?: boolean;
440
+ /**
441
+ * Whether the panel can be resized by dragging.
442
+ * @default true
443
+ */
444
+ resizable?: boolean;
445
+ /**
446
+ * Whether the hide button is shown. When hidden, the panel collapses
447
+ * to a small tab at the viewport edge.
448
+ * @default true
449
+ */
450
+ hideable?: boolean;
451
+ /**
452
+ * Alignment of the hide tab along the panel's viewport edge.
453
+ * For bottom/top: 'start' = left, 'center', 'end' = right.
454
+ * For left/right: 'start' = top, 'center', 'end' = bottom.
455
+ * @default 'center'
456
+ */
457
+ hideAlignment?: CliPanelHideAlignment;
458
+ /**
459
+ * When true, the panel's chrome (header, border, background) automatically
460
+ * syncs its colors with the active terminal theme. CSS custom properties
461
+ * are derived from the xterm theme and applied as inline styles.
462
+ * @default false
463
+ */
464
+ syncTheme?: boolean;
465
+ }
466
+
467
+ type MultiServices = {
468
+ /**
469
+ * When true, injector returns an array of instances. This is useful to allow multiple
470
+ * providers spread across many files to provide configuration information to a common token.
471
+ */
472
+ multi?: boolean;
473
+ };
474
+ type CliValueProvider = MultiServices & {
475
+ useValue: any;
476
+ };
477
+ type CliTypeProvider = MultiServices & {
478
+ useClass: any;
479
+ };
480
+ type CliFactoryProvider = MultiServices & {
481
+ useFactory: Function;
482
+ };
483
+ type CliProvider = {
484
+ provide: any;
485
+ } & (CliValueProvider | CliTypeProvider | CliFactoryProvider) & Record<string, any>;
486
+
487
+ /**
488
+ * Represents a user in the CLI
489
+ */
490
+ interface ICliUser {
491
+ /** Unique user identifier */
492
+ id: string;
493
+ /** Login name (unique) */
494
+ name: string;
495
+ /** Email address (unique) */
496
+ email: string;
497
+ /** Group IDs this user belongs to */
498
+ groups: string[];
499
+ /** Virtual home directory path, e.g. /home/root */
500
+ homeDir?: string;
501
+ /** Account creation timestamp */
502
+ createdAt: number;
503
+ /** Last modification timestamp */
504
+ updatedAt: number;
505
+ /** Whether the account is locked */
506
+ disabled?: boolean;
507
+ }
508
+ /**
509
+ * Represents user credentials (shadow pattern — stored separately from ICliUser)
510
+ */
511
+ interface ICliUserCredentials {
512
+ /** The user ID this credential belongs to */
513
+ userId: string;
514
+ /** SHA-256 hash of salt + password */
515
+ passwordHash: string;
516
+ /** Random salt for this user */
517
+ salt: string;
518
+ /** Timestamp of last password change */
519
+ lastChanged: number;
520
+ }
521
+ /**
522
+ * Represents a group in the CLI
523
+ */
524
+ interface ICliGroup {
525
+ /** Unique group identifier */
526
+ id: string;
527
+ /** Group name (unique) */
528
+ name: string;
529
+ /** Optional group description */
530
+ description?: string;
531
+ /** Group creation timestamp */
532
+ createdAt: number;
533
+ }
534
+ /**
535
+ * Represents an active user session
536
+ */
537
+ interface ICliUserSession {
538
+ /** The user associated with this session */
539
+ user: ICliUser;
540
+ /** Pre-computed display name for the prompt (set by users module) */
541
+ displayName?: string;
542
+ /** Timestamp when the session started */
543
+ loginTime: number;
544
+ /** Timestamp of last activity */
545
+ lastActivity: number;
546
+ /** Extensible data (tokens, metadata, etc.) */
547
+ data?: Record<string, any>;
548
+ }
549
+ /** Fields required to create a new user */
550
+ type CliAddUser = Omit<ICliUser, 'id' | 'createdAt' | 'updatedAt'>;
551
+ /** Fields that can be updated on a user */
552
+ type CliUpdateUser = Partial<Omit<ICliUser, 'id' | 'createdAt'>>;
553
+
554
+ /** Ownership metadata attached to files, directories, or other resources */
555
+ interface ICliOwnership {
556
+ /** User ID of the owner */
557
+ uid: string;
558
+ /** Primary group name */
559
+ gid: string;
560
+ }
561
+ /** Default file permissions: rw-r--r-- (644) */
562
+ declare const DEFAULT_FILE_PERMISSIONS = "rw-r--r--";
563
+ /** Default directory permissions: rwxr-xr-x (755) */
564
+ declare const DEFAULT_DIR_PERMISSIONS = "rwxr-xr-x";
565
+
566
+ declare const enums: {
567
+ CliForegroundColor: typeof CliForegroundColor;
568
+ CliBackgroundColor: typeof CliBackgroundColor;
569
+ CliIcon: typeof CliIcon;
570
+ CliLogLevel: typeof CliLogLevel;
571
+ };
572
+
573
+ interface CliTableOptions {
574
+ /** Expand columns to fill the full terminal width. Default: false */
575
+ fullWidth?: boolean;
576
+ }
577
+ interface ICliTerminalWriter {
578
+ /**
579
+ * Write text to the terminal
580
+ * @param text The text to write
581
+ */
582
+ write(text: string): void;
583
+ /**
584
+ * Write text to the terminal followed by a newline
585
+ * @param text The text to write
586
+ */
587
+ writeln(text?: string): void;
588
+ /**
589
+ * Write a success message to the terminal
590
+ * @param message The message to write
591
+ */
592
+ writeSuccess(message: string): void;
593
+ /**
594
+ * Write an info message to the terminal
595
+ * @param message The message to write
596
+ */
597
+ writeInfo(message: string): void;
598
+ /**
599
+ * Write an error message to the terminal
600
+ * @param message The message to write
601
+ */
602
+ writeError(message: string): void;
603
+ /**
604
+ * Write a warning message to the terminal
605
+ * @param message The message to write
606
+ */
607
+ writeWarning(message: string): void;
608
+ /**
609
+ * Wrap text in the specified foreground color.
610
+ * @param text The text to wrap
611
+ * @param color The foreground color to apply
612
+ * @returns The text wrapped in ANSI color codes
613
+ */
614
+ wrapInColor(text: string, color: CliForegroundColor): string;
615
+ /**
616
+ * Wrap text in the specified background color.
617
+ * @param text The text to wrap
618
+ * @param color The background color to apply
619
+ * @returns The text wrapped in ANSI background color codes
620
+ */
621
+ wrapInBackgroundColor(text: string, color: CliBackgroundColor): string;
622
+ /**
623
+ * Write a JSON object to the terminal
624
+ * @param json The JSON object to write
625
+ */
626
+ writeJson(json: any): void;
627
+ /**
628
+ * Write content to a file (triggers a browser download)
629
+ * @param fileName The name of the file to download
630
+ * @param content The content to write to the file
631
+ */
632
+ writeToFile(fileName: string, content: string): void;
633
+ /**
634
+ * Write an object array as a table to the terminal
635
+ * @param objects The objects to write to the table
636
+ */
637
+ writeObjectsAsTable(objects: any[]): void;
638
+ /**
639
+ * Write a table to the terminal
640
+ * @param headers The headers of the table
641
+ * @param rows The rows of the table
642
+ * @param options Optional table rendering options
643
+ */
644
+ writeTable(headers: string[], rows: string[][], options?: CliTableOptions): void;
645
+ /**
646
+ * Write a divider to the terminal
647
+ * @param options Optional: color, length, character
648
+ */
649
+ writeDivider(options?: {
650
+ color?: CliForegroundColor;
651
+ length?: number;
652
+ char?: string;
653
+ }): void;
654
+ /**
655
+ * Write a list of items to the terminal with bullet, numbered, or custom prefix.
656
+ * @param items The list items to display
657
+ * @param options Optional: ordered (numbered), prefix (custom marker), color
658
+ */
659
+ writeList(items: string[], options?: {
660
+ ordered?: boolean;
661
+ prefix?: string;
662
+ color?: CliForegroundColor;
663
+ }): void;
664
+ /**
665
+ * Write aligned key-value pairs to the terminal.
666
+ * @param entries Key-value pairs as a Record or array of tuples
667
+ * @param options Optional: separator string, key color
668
+ */
669
+ writeKeyValue(entries: Record<string, string> | [string, string][], options?: {
670
+ separator?: string;
671
+ keyColor?: CliForegroundColor;
672
+ }): void;
673
+ /**
674
+ * Write items in a multi-column layout.
675
+ * @param items The items to arrange in columns
676
+ * @param options Optional: number of columns, padding between columns
677
+ */
678
+ writeColumns(items: string[], options?: {
679
+ columns?: number;
680
+ padding?: number;
681
+ }): void;
682
+ /**
683
+ * Write a clickable hyperlink using OSC 8 escape sequences.
684
+ * In terminals that support OSC 8, the text is clickable. In others,
685
+ * it falls back to displaying "text (url)".
686
+ * @param text The visible link text
687
+ * @param url The URL to link to
688
+ */
689
+ writeLink(text: string, url: string): void;
690
+ /**
691
+ * Write text inside a bordered box.
692
+ * Useful for callouts, notices, and highlighted information.
693
+ * @param content The content lines to display inside the box
694
+ * @param options Optional: title, border color, padding
695
+ */
696
+ writeBox(content: string | string[], options?: {
697
+ title?: string;
698
+ borderColor?: CliForegroundColor;
699
+ padding?: number;
700
+ }): void;
701
+ /**
702
+ * Write text with a specified indentation level.
703
+ * Each level adds 2 spaces of indentation.
704
+ * @param text The text to write
705
+ * @param level The indentation level (default: 1)
706
+ */
707
+ writeIndented(text: string, level?: number): void;
708
+ }
709
+
710
+ /**
711
+ * Represents a clipboard for the CLI
712
+ */
713
+ interface ICliClipboard {
714
+ /**
715
+ * Write text to the clipboard
716
+ * @param text The text to write to the clipboard
717
+ * @returns void
718
+ */
719
+ write: (text: string) => Promise<void>;
720
+ /**
721
+ * Read text from the clipboard
722
+ * @returns The text read from the clipboard
723
+ */
724
+ read: () => Promise<string>;
725
+ }
726
+
727
+ /**
728
+ * Token for the CLI user session service.
729
+ */
730
+ declare const ICliUserSessionService_TOKEN = "cli-user-session-service";
731
+ /**
732
+ * Token for the CLI users store service.
733
+ */
734
+ declare const ICliUsersStoreService_TOKEN = "cli-users-store-service";
735
+ /**
736
+ * Token for the CLI groups store service.
737
+ */
738
+ declare const ICliGroupsStoreService_TOKEN = "cli-groups-store-service";
739
+ /**
740
+ * Token for the CLI auth service.
741
+ */
742
+ declare const ICliAuthService_TOKEN = "cli-auth-service";
743
+ /**
744
+ * Token for registering completion providers via module services (multi: true).
745
+ */
746
+ declare const ICliCompletionProvider_TOKEN = "cli-completion-provider";
747
+ /**
748
+ * Token for the drag-and-drop service.
749
+ */
750
+ declare const ICliDragDropService_TOKEN = "cli-drag-drop-service";
751
+ /**
752
+ * Token for the file transfer service.
753
+ */
754
+ declare const ICliFileTransferService_TOKEN = "cli-file-transfer-service";
755
+ /**
756
+ * Token for the translation service.
757
+ */
758
+ declare const ICliTranslationService_TOKEN = "cli-translation-service";
759
+ /**
760
+ * Token for the permission service.
761
+ */
762
+ declare const ICliPermissionService_TOKEN = "cli-permission-service";
763
+ /**
764
+ * Token for the file picker provider.
765
+ */
766
+ declare const ICliFilePickerProvider_TOKEN = "cli-file-picker-provider";
767
+
768
+ /**
769
+ * Options for readFile file picker.
770
+ */
771
+ interface CliFilePickerOptions {
772
+ /** Allow selecting multiple files. Default: false. */
773
+ multiple?: boolean;
774
+ /**
775
+ * File type filter. Accepts MIME types (e.g. 'image/*') or extensions
776
+ * (e.g. '.json,.txt'). Maps to the HTML accept attribute in browsers
777
+ * and file filter in Electron.
778
+ */
779
+ accept?: string;
780
+ /**
781
+ * When true, pick a directory instead of files. Default: false.
782
+ * Cannot be combined with `multiple` — if both are set, `directory` takes precedence
783
+ * and a single directory is returned.
784
+ */
785
+ directory?: boolean;
786
+ /**
787
+ * How to read file content. Default: 'text'.
788
+ * - 'text': Read as UTF-8 string (suitable for text files)
789
+ * - 'arraybuffer': Read as ArrayBuffer (suitable for binary files like images)
790
+ */
791
+ readAs?: 'text' | 'arraybuffer';
792
+ }
793
+ /**
794
+ * Result returned by readFile for each selected file.
795
+ */
796
+ interface CliFileResult {
797
+ /** File name without path (e.g. 'config.json') */
798
+ name: string;
799
+ /** Full file path. Available in Electron, undefined in browser. */
800
+ path?: string;
801
+ /**
802
+ * File content. Type depends on `CliFilePickerOptions.readAs`:
803
+ * - 'text' (default): `string` (UTF-8 decoded)
804
+ * - 'arraybuffer': `ArrayBuffer` (raw bytes)
805
+ */
806
+ content: string | ArrayBuffer;
807
+ /** File size in bytes */
808
+ size: number;
809
+ /** MIME type (e.g. 'application/json', 'image/png') */
810
+ type: string;
811
+ }
812
+ /**
813
+ * Abstraction for environment-specific file picking.
814
+ * Implementations handle the actual dialog interaction for their environment.
815
+ */
816
+ interface ICliFilePickerProvider {
817
+ /** Whether file picking is supported in this environment */
818
+ readonly isSupported: boolean;
819
+ /**
820
+ * Open a file picker dialog and return selected files.
821
+ * @returns Array of selected files, or null if the user cancelled
822
+ */
823
+ pickFiles(options?: CliFilePickerOptions): Promise<CliFileResult[] | null>;
824
+ /**
825
+ * Open a directory picker dialog and return the selected directory.
826
+ * @returns The selected directory, or null if the user cancelled
827
+ */
828
+ pickDirectory(): Promise<CliFileResult | null>;
829
+ }
830
+
831
+ /**
832
+ * Represents an option for the readSelect and readSelectInline prompts.
833
+ */
834
+ interface CliSelectOption {
835
+ /** Display text shown to the user */
836
+ label: string;
837
+ /** Value returned when this option is selected */
838
+ value: string;
839
+ /** Optional description shown as dimmed italic text after the label */
840
+ description?: string;
841
+ /** Group name — options sharing the same group are displayed under a group header */
842
+ group?: string;
843
+ /** When true, the option is visible but cannot be selected (rendered dimmed) */
844
+ disabled?: boolean;
845
+ }
846
+ /**
847
+ * Represents an option for the readMultiSelect prompt.
848
+ */
849
+ interface CliMultiSelectOption extends CliSelectOption {
850
+ /** Whether the option is pre-selected */
851
+ checked?: boolean;
852
+ }
853
+ /**
854
+ * Options for readLine input.
855
+ */
856
+ interface CliLineOptions {
857
+ /**
858
+ * Pre-filled default value. Shown in the buffer when the prompt opens.
859
+ * The cursor starts at the end of the default text.
860
+ */
861
+ default?: string;
862
+ /**
863
+ * Validation function called on Enter.
864
+ * Return an error message string to reject the input and display the error.
865
+ * Return null to accept the input.
866
+ */
867
+ validate?: (value: string) => string | null;
868
+ /** Placeholder text shown dimmed when the buffer is empty */
869
+ placeholder?: string;
870
+ }
871
+ /**
872
+ * Options for readSelect and readSelectInline.
873
+ */
874
+ interface CliSelectOptions {
875
+ /** Pre-select an option by its value */
876
+ default?: string;
877
+ /** Enable type-to-filter. When true, printable keystrokes filter the option list. Default: false. */
878
+ searchable?: boolean;
879
+ /** Callback invoked each time the highlighted option changes */
880
+ onChange?: (value: string) => void;
881
+ }
882
+ /**
883
+ * Options for readMultiSelect.
884
+ */
885
+ interface CliMultiSelectOptions {
886
+ /** Enable type-to-filter. When true, printable keystrokes filter the option list. Default: false. */
887
+ searchable?: boolean;
888
+ /** Callback invoked each time the set of checked options changes */
889
+ onChange?: (values: string[]) => void;
890
+ }
891
+ /**
892
+ * Options for readNumber input.
893
+ */
894
+ interface CliNumberOptions {
895
+ /** Minimum allowed value */
896
+ min?: number;
897
+ /** Maximum allowed value */
898
+ max?: number;
899
+ /** Pre-filled default value */
900
+ default?: number;
901
+ }
902
+ /**
903
+ * Options for readDate input.
904
+ */
905
+ interface CliDateOptions {
906
+ /**
907
+ * Date format string. Supported tokens: YYYY (4-digit year), MM (2-digit month),
908
+ * DD (2-digit day). Separators can be `-`, `/`, or `.`.
909
+ * @default 'YYYY-MM-DD'
910
+ */
911
+ format?: string;
912
+ /** Minimum allowed date in the same format as `format` */
913
+ min?: string;
914
+ /** Maximum allowed date in the same format as `format` */
915
+ max?: string;
916
+ /** Pre-filled default value */
917
+ default?: string;
918
+ }
919
+ /**
920
+ * Provides interactive input reading from the terminal.
921
+ * All methods resolve with `null` when the user aborts (Ctrl+C or Escape).
922
+ */
923
+ interface ICliInputReader {
924
+ /**
925
+ * Read a line of text input.
926
+ * @param prompt - The prompt text displayed to the user
927
+ * @param options - Optional configuration for default value, validation, and placeholder
928
+ * @returns The entered text, or null if aborted
929
+ */
930
+ readLine(prompt: string, options?: CliLineOptions): Promise<string | null>;
931
+ /**
932
+ * Read a password (masked input).
933
+ * @param prompt - The prompt text displayed to the user
934
+ * @returns The entered password, or null if aborted
935
+ */
936
+ readPassword(prompt: string): Promise<string | null>;
937
+ /**
938
+ * Read a yes/no confirmation.
939
+ * @param prompt - The prompt text displayed to the user
940
+ * @param defaultValue - Default value when Enter is pressed without input
941
+ * @returns true for yes, false for no, or null if aborted
942
+ */
943
+ readConfirm(prompt: string, defaultValue?: boolean): Promise<boolean | null>;
944
+ /**
945
+ * Read a selection from a vertical list of options.
946
+ * @param prompt - The prompt text displayed to the user
947
+ * @param options - Array of options to choose from
948
+ * @param selectOptions - Optional configuration for default, search, onChange
949
+ * @returns The selected option's value, or null if aborted
950
+ */
951
+ readSelect(prompt: string, options: CliSelectOption[], selectOptions?: CliSelectOptions): Promise<string | null>;
952
+ /**
953
+ * Read a selection from an inline horizontal list.
954
+ * @param prompt - The prompt text displayed to the user
955
+ * @param options - Array of options to choose from
956
+ * @param selectOptions - Optional configuration for default, search, onChange
957
+ * @returns The selected option's value, or null if aborted
958
+ */
959
+ readSelectInline(prompt: string, options: CliSelectOption[], selectOptions?: CliSelectOptions): Promise<string | null>;
960
+ /**
961
+ * Read multiple selections from a checkbox list.
962
+ * @param prompt - The prompt text displayed to the user
963
+ * @param options - Array of options with optional pre-checked state
964
+ * @param selectOptions - Optional configuration for search, onChange
965
+ * @returns Array of selected option values, or null if aborted
966
+ */
967
+ readMultiSelect(prompt: string, options: CliMultiSelectOption[], selectOptions?: CliMultiSelectOptions): Promise<string[] | null>;
968
+ /**
969
+ * Read a number input.
970
+ * @param prompt - The prompt text displayed to the user
971
+ * @param options - Optional configuration for min, max, and default value
972
+ * @returns The entered number, or null if aborted
973
+ */
974
+ readNumber(prompt: string, options?: CliNumberOptions): Promise<number | null>;
975
+ /**
976
+ * Read a date input with format validation.
977
+ * @param prompt - The prompt text displayed to the user
978
+ * @param options - Optional configuration for format, min/max range, default
979
+ * @returns The date string in the specified format, or null if aborted
980
+ */
981
+ readDate(prompt: string, options?: CliDateOptions): Promise<string | null>;
982
+ /**
983
+ * Read file(s) via the environment's file picker dialog.
984
+ * @param prompt - The prompt text displayed to the user
985
+ * @param options - Optional configuration for multiple, accept filter, directory mode
986
+ * @returns Array of selected files with content, or null if cancelled/unsupported
987
+ */
988
+ readFile(prompt: string, options?: CliFilePickerOptions): Promise<CliFileResult[] | null>;
989
+ }
990
+
991
+ /**
992
+ * Background service lifecycle type.
993
+ * - `'daemon'` — Long-running service whose `onStart` blocks until the abort signal
994
+ * fires. Suitable for event loops, polling, or WebSocket connections. Can be
995
+ * stopped and restarted.
996
+ * - `'job'` — Run-to-completion task whose `onStart` resolves when the work is done.
997
+ * Automatically transitions to `'done'` status on success. Cannot be restarted.
998
+ */
999
+ type CliBackgroundServiceType = 'daemon' | 'job';
1000
+ /**
1001
+ * Lifecycle status of a background service.
1002
+ */
1003
+ type CliBackgroundServiceStatus = 'pending' | 'running' | 'stopped' | 'failed' | 'done';
1004
+ /**
1005
+ * Where the service code is executing.
1006
+ */
1007
+ type CliServiceExecutionMode = 'main-thread' | 'worker';
1008
+ /**
1009
+ * An event emitted by a background service.
1010
+ * Services control terminal notification visibility by setting `data.notify: true`.
1011
+ */
1012
+ interface ICliServiceEvent {
1013
+ /** Name of the service that emitted this event */
1014
+ source: string;
1015
+ /** Event type — services define their own, registry emits lifecycle events */
1016
+ type: string;
1017
+ /** Arbitrary payload */
1018
+ data?: unknown;
1019
+ /** Set automatically by the registry */
1020
+ timestamp?: Date;
1021
+ }
1022
+ /**
1023
+ * Handler function for service events.
1024
+ */
1025
+ type CliServiceEventHandler = (event: ICliServiceEvent) => void;
1026
+ /**
1027
+ * Log severity level for background service messages.
1028
+ * Shared by `ICliServiceLogEntry`, `ICliServiceContext.log()`,
1029
+ * and `WorkerServiceContext.log()`.
1030
+ */
1031
+ type CliServiceLogLevel = 'info' | 'warn' | 'error';
1032
+ /**
1033
+ * A single log entry from a background service.
1034
+ */
1035
+ interface ICliServiceLogEntry {
1036
+ timestamp: Date;
1037
+ level: CliServiceLogLevel;
1038
+ message: string;
1039
+ }
1040
+ /**
1041
+ * Per-service runtime context.
1042
+ * Each background service receives its own context with an independent abort signal
1043
+ * and scoped timers (not shared with the full-screen timer set).
1044
+ */
1045
+ interface ICliServiceContext {
1046
+ /** AbortSignal scoped to this service — independent of Ctrl+C */
1047
+ signal: AbortSignal;
1048
+ /** Emit an event from this service */
1049
+ emit(event: ICliServiceEvent): void;
1050
+ /** Log a message to this service's private log buffer */
1051
+ log(message: string, level?: CliServiceLogLevel): void;
1052
+ /** Create an interval scoped to this service (auto-cleared on stop) */
1053
+ createInterval(callback: () => void, ms: number): ICliManagedInterval;
1054
+ /** Create a timeout scoped to this service (auto-cleared on stop) */
1055
+ createTimeout(callback: () => void, ms: number): ICliManagedTimer;
1056
+ /** Access the shared state store */
1057
+ state: ICliStateStore;
1058
+ /** Access the shared service container */
1059
+ services: ICliServiceProvider;
1060
+ }
1061
+ /**
1062
+ * A background service that can run as a daemon or job.
1063
+ */
1064
+ interface ICliBackgroundService {
1065
+ /** Unique name for this service */
1066
+ name: string;
1067
+ /** Human-readable description */
1068
+ description?: string;
1069
+ /** 'daemon' for long-running, 'job' for run-to-completion */
1070
+ type: CliBackgroundServiceType;
1071
+ /** Whether this service can run in a Web Worker */
1072
+ workerCompatible?: boolean;
1073
+ /** Factory that creates the Worker instance (when workerCompatible) */
1074
+ workerFactory?: () => Worker;
1075
+ /** Called when the service starts */
1076
+ onStart(context: ICliServiceContext): Promise<void>;
1077
+ /** Called for graceful shutdown */
1078
+ onStop?(context: ICliServiceContext): Promise<void>;
1079
+ /**
1080
+ * Called when the service throws an unrecoverable error.
1081
+ * Use this hook for logging or cleanup; throwing from `onError` itself
1082
+ * is safe — the registry catches it and marks the service as failed.
1083
+ */
1084
+ onError?(error: Error, context: ICliServiceContext): void;
1085
+ }
1086
+ /**
1087
+ * Read-only snapshot of a background service's current state.
1088
+ */
1089
+ interface ICliBackgroundServiceInfo {
1090
+ /** Process ID assigned by the process registry */
1091
+ pid?: number;
1092
+ name: string;
1093
+ description?: string;
1094
+ type: CliBackgroundServiceType;
1095
+ status: CliBackgroundServiceStatus;
1096
+ executionMode: CliServiceExecutionMode;
1097
+ startedAt?: Date;
1098
+ stoppedAt?: Date;
1099
+ error?: string;
1100
+ /** Uptime in milliseconds (only when running) */
1101
+ uptime?: number;
1102
+ }
1103
+ /**
1104
+ * Registry that manages background service lifecycle.
1105
+ * Exposed on `ICliExecutionContext.backgroundServices`.
1106
+ */
1107
+ interface ICliBackgroundServiceRegistry {
1108
+ register(service: ICliBackgroundService): void;
1109
+ start(name: string): Promise<void>;
1110
+ stop(name: string): Promise<void>;
1111
+ restart(name: string): Promise<void>;
1112
+ startJob(name: string, task: (context: ICliServiceContext) => Promise<void>, options?: {
1113
+ workerCompatible?: boolean;
1114
+ }): Promise<void>;
1115
+ getStatus(name: string): ICliBackgroundServiceInfo | undefined;
1116
+ list(): ICliBackgroundServiceInfo[];
1117
+ getLogs(name: string, limit?: number): ICliServiceLogEntry[];
1118
+ on(handler: CliServiceEventHandler, filter?: {
1119
+ source?: string;
1120
+ type?: string;
1121
+ }): () => void;
1122
+ destroyAll(): Promise<void>;
1123
+ }
1124
+
1125
+ /**
1126
+ * A managed timer handle returned by createInterval/createTimeout.
1127
+ * Managed timers are automatically cleared when full-screen mode exits
1128
+ * or the CLI component is destroyed.
1129
+ */
1130
+ interface ICliManagedTimer {
1131
+ /** Clear this timer immediately. */
1132
+ readonly clear: () => void;
1133
+ }
1134
+ /**
1135
+ * A managed interval handle with the ability to change the delay.
1136
+ */
1137
+ interface ICliManagedInterval extends ICliManagedTimer {
1138
+ /** Change the interval delay. Restarts the interval with the new delay. */
1139
+ readonly setDelay: (ms: number) => void;
1140
+ }
1141
+ /**
1142
+ * Options for entering full-screen mode.
1143
+ */
1144
+ interface CliFullScreenOptions {
1145
+ /**
1146
+ * Whether to show the terminal cursor. Defaults to `false` (cursor hidden).
1147
+ * Set to `true` for REPL / input-line interfaces where the user types text.
1148
+ */
1149
+ showCursor?: boolean;
1150
+ }
1151
+ /**
1152
+ * Represents the context in which a command is executed
1153
+ */
1154
+ interface ICliExecutionContext {
1155
+ /**
1156
+ * The current user session
1157
+ */
1158
+ userSession?: ICliUserSession;
1159
+ /**
1160
+ * The spinner to use for showing/hiding the loader
1161
+ */
1162
+ spinner?: ICliSpinner;
1163
+ /**
1164
+ * The text animator to use for showing/hiding text
1165
+ */
1166
+ textAnimator?: ICliTextAnimator;
1167
+ /**
1168
+ * The progress bar to use for showing progress
1169
+ */
1170
+ progressBar: ICliPercentageProgressBar;
1171
+ /**
1172
+ * A subject that emits when the command is aborted
1173
+ */
1174
+ onAbort: Subject<void>;
1175
+ /**
1176
+ * Abort signal for the current command. Fires when the command is
1177
+ * cancelled via Ctrl+C or killed. Commands should check this signal
1178
+ * or listen to onAbort for cooperative cancellation.
1179
+ */
1180
+ signal?: AbortSignal;
1181
+ /**
1182
+ * The terminal to use for writing
1183
+ */
1184
+ terminal: Terminal;
1185
+ /**
1186
+ * The writer to use for writing to the terminal
1187
+ */
1188
+ writer: ICliTerminalWriter;
1189
+ /**
1190
+ * The reader to use for interactive input prompts (text, password, confirm, select)
1191
+ */
1192
+ reader: ICliInputReader;
1193
+ /**
1194
+ * The command executor to use for executing commands
1195
+ */
1196
+ executor: ICliCommandExecutorService;
1197
+ /**
1198
+ * The clipboard to use for copying/pasting
1199
+ */
1200
+ clipboard: ICliClipboard;
1201
+ /**
1202
+ * The state store to use for storing state
1203
+ */
1204
+ state: ICliStateStore;
1205
+ /**
1206
+ * The options for the CLI
1207
+ */
1208
+ options?: CliOptions;
1209
+ /**
1210
+ * Prints the prompt to the terminal.
1211
+ */
1212
+ showPrompt: (options?: {
1213
+ reset?: boolean;
1214
+ newLine?: boolean;
1215
+ keepCurrentLine?: boolean;
1216
+ }) => void;
1217
+ /**
1218
+ * Set the current processor as the context processor, i.e. the processor that will handle the command
1219
+ * @param processor The processor to set
1220
+ * @param silent Indicates if the setting should be silent, i.e. not write to the terminal
1221
+ * @param fullScreen When true, Ctrl+C is passed through to the processor (full-screen apps manage their own exit)
1222
+ */
1223
+ setContextProcessor: (processor: ICliCommandProcessor | undefined, silent?: boolean, fullScreen?: boolean) => void;
1224
+ /**
1225
+ * The number of visible characters the prompt occupies on the current line.
1226
+ */
1227
+ promptLength: number;
1228
+ /**
1229
+ * The current user input text on the active line.
1230
+ */
1231
+ readonly currentLine: string;
1232
+ /**
1233
+ * Sets the current line text.
1234
+ * @param line The new line content
1235
+ */
1236
+ setCurrentLine: (line: string) => void;
1237
+ /**
1238
+ * The cursor position within the current line.
1239
+ */
1240
+ cursorPosition: number;
1241
+ /**
1242
+ * Clears the current terminal line, including content that wraps across multiple rows.
1243
+ * Uses promptLength + currentLine.length to determine how many rows to clear.
1244
+ */
1245
+ clearLine: () => void;
1246
+ /**
1247
+ * Clears the current line content and reprints the prompt.
1248
+ */
1249
+ clearCurrentLine: () => void;
1250
+ /**
1251
+ * Refreshes the display of the current line (clears and redraws prompt + input).
1252
+ */
1253
+ refreshCurrentLine: () => void;
1254
+ /**
1255
+ * The process to use for exiting the CLI
1256
+ */
1257
+ process: ICliExecutionProcess;
1258
+ /**
1259
+ * The logger to use for logging
1260
+ */
1261
+ logger: ICliLogger;
1262
+ /**
1263
+ * The services to use for the CLI context
1264
+ */
1265
+ services: ICliServiceProvider;
1266
+ /**
1267
+ * The translation service for i18n string resolution.
1268
+ * Use `translator.t(key, defaultValue)` to get translated strings.
1269
+ */
1270
+ translator: ICliTranslationService;
1271
+ /**
1272
+ * Optional callback that returns the current path to display in the prompt.
1273
+ * Any plugin can set this to customize the path segment of the prompt
1274
+ * (e.g. a filesystem plugin showing the current working directory).
1275
+ * When set, the returned path replaces the default `~` in the prompt.
1276
+ * Return null to fall back to the default `~`.
1277
+ */
1278
+ promptPathProvider?: () => string | null;
1279
+ /**
1280
+ * Enter full-screen mode: switches to the alternate screen buffer,
1281
+ * positions the cursor at row 1 col 1, and sets the given processor
1282
+ * as the context processor so that all terminal input is routed to
1283
+ * its `onData` method.
1284
+ *
1285
+ * By default the cursor is hidden (suitable for games / editors that
1286
+ * manage their own cursor). Pass `{ showCursor: true }` to keep it
1287
+ * visible (suitable for REPL / input-line interfaces).
1288
+ *
1289
+ * @param processor The processor that will handle all input in full-screen mode
1290
+ * @param options Optional settings for full-screen mode
1291
+ */
1292
+ enterFullScreenMode: (processor: ICliCommandProcessor, options?: CliFullScreenOptions) => void;
1293
+ /**
1294
+ * Exit full-screen mode: restores the cursor, leaves the alternate screen buffer,
1295
+ * clears the context processor, and re-displays the prompt.
1296
+ */
1297
+ exitFullScreenMode: () => void;
1298
+ /**
1299
+ * Creates a managed interval that is automatically cleared when full-screen
1300
+ * mode exits or the CLI component is destroyed.
1301
+ * @param callback The function to call on each interval tick
1302
+ * @param ms The interval delay in milliseconds
1303
+ * @returns A managed interval handle with clear() and setDelay() methods
1304
+ */
1305
+ createInterval: (callback: () => void, ms: number) => ICliManagedInterval;
1306
+ /**
1307
+ * Creates a managed timeout that is automatically cleared when full-screen
1308
+ * mode exits or the CLI component is destroyed.
1309
+ * @param callback The function to call when the timeout fires
1310
+ * @param ms The timeout delay in milliseconds
1311
+ * @returns A managed timer handle with a clear() method
1312
+ */
1313
+ createTimeout: (callback: () => void, ms: number) => ICliManagedTimer;
1314
+ /**
1315
+ * Registry for managing background services and jobs.
1316
+ * Each CLI session owns its own isolated registry. Services registered here
1317
+ * are scoped to this session and destroyed when the engine shuts down.
1318
+ */
1319
+ backgroundServices: ICliBackgroundServiceRegistry;
1320
+ }
1321
+
1322
+ interface ICliProcessorHook {
1323
+ when: 'before' | 'after';
1324
+ execute: (context: ICliExecutionContext) => Promise<void>;
1325
+ }
1326
+
1327
+ interface ICliCommandAuthor {
1328
+ /**
1329
+ * The name of the author
1330
+ */
1331
+ name: string;
1332
+ /**
1333
+ * The email of the author
1334
+ */
1335
+ email: string;
1336
+ }
1337
+ /**
1338
+ * Represents a command parameter
1339
+ */
1340
+ interface ICliCommandParameterDescriptor {
1341
+ /**
1342
+ * The name of the parameter
1343
+ */
1344
+ name: string;
1345
+ /**
1346
+ * Aliases for the parameter
1347
+ */
1348
+ aliases?: string[];
1349
+ /**
1350
+ * A description of the parameter
1351
+ */
1352
+ description: string;
1353
+ /**
1354
+ * If true, the parameter is required
1355
+ */
1356
+ required: boolean;
1357
+ /**
1358
+ * The type of the parameter
1359
+ */
1360
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object' | string;
1361
+ /**
1362
+ * The default value of the parameter
1363
+ */
1364
+ defaultValue?: any;
1365
+ /**
1366
+ * A validator function that validates the value of the parameter
1367
+ * @param value The value to validate
1368
+ * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
1369
+ */
1370
+ validator?: (value: any) => {
1371
+ /**
1372
+ * Indicates if the value is valid
1373
+ */
1374
+ valid: boolean;
1375
+ /**
1376
+ * An optional message to display if the value is not valid
1377
+ */
1378
+ message?: string;
1379
+ };
1380
+ }
1381
+ /**
1382
+ * Represents a configuration option that a command processor exposes
1383
+ * for management via the `configure` command.
1384
+ */
1385
+ interface ICliConfigurationOption {
1386
+ /**
1387
+ * The key used to store and retrieve this option, e.g. 'maxItems'
1388
+ */
1389
+ key: string;
1390
+ /**
1391
+ * Human-readable label shown in the interactive menu
1392
+ */
1393
+ label: string;
1394
+ /**
1395
+ * Description of what this option controls
1396
+ */
1397
+ description: string;
1398
+ /**
1399
+ * The data type of the option
1400
+ */
1401
+ type: 'string' | 'number' | 'boolean' | 'select';
1402
+ /**
1403
+ * The default value when no configuration has been set
1404
+ */
1405
+ defaultValue: any;
1406
+ /**
1407
+ * Available choices for 'select' type options
1408
+ */
1409
+ options?: {
1410
+ label: string;
1411
+ value: any;
1412
+ }[];
1413
+ /**
1414
+ * Optional validator function
1415
+ */
1416
+ validator?: (value: any) => {
1417
+ valid: boolean;
1418
+ message?: string;
1419
+ };
1420
+ /**
1421
+ * Override the category grouping (defaults to the processor command name)
1422
+ */
1423
+ category?: string;
1424
+ }
1425
+ /**
1426
+ * Represents a command processor
1427
+ */
1428
+ interface ICliCommandProcessor {
1429
+ /**
1430
+ * The command that this processor handles
1431
+ */
1432
+ command: string;
1433
+ /**
1434
+ * Alternative names for the command
1435
+ */
1436
+ aliases?: string[];
1437
+ /**
1438
+ * A description of the command
1439
+ */
1440
+ description?: string;
1441
+ /**
1442
+ * The author of the command
1443
+ */
1444
+ author?: ICliCommandAuthor;
1445
+ /**
1446
+ * If true, the processor accepts raw text input after the command name as its value.
1447
+ * The captured text is available via `command.value` in `processCommand`.
1448
+ * @default false
1449
+ * @remarks When true, any text following the command name is extracted as the command value
1450
+ * rather than being interpreted as sub-commands. Use `valueRequired` instead if the value is mandatory.
1451
+ */
1452
+ acceptsRawInput?: boolean;
1453
+ /**
1454
+ * If true, the command requires some form of input before it can execute.
1455
+ *
1456
+ * The requirement is satisfied by **any** of:
1457
+ * - A positional value (text after the command name, available via `command.value`)
1458
+ * - Piped data from a previous command (available via `command.data`)
1459
+ * - Named arguments (e.g. `--server=node --path=/app`)
1460
+ *
1461
+ * When set, `command.value` is automatically extracted from the raw input
1462
+ * (equivalent to setting `acceptsRawInput`).
1463
+ *
1464
+ * Additionally, when positional input is present the engine skips
1465
+ * required-parameter validation — the processor is responsible for
1466
+ * parsing positional text into individual values. Required-parameter
1467
+ * checks still apply when the user provides only named arguments.
1468
+ *
1469
+ * @default false
1470
+ */
1471
+ valueRequired?: boolean;
1472
+ /**
1473
+ * The version of the command processor
1474
+ * @default '1.0.0'
1475
+ */
1476
+ version?: string;
1477
+ /**
1478
+ * The metadata for the command processor
1479
+ */
1480
+ metadata?: CliProcessorMetadata;
1481
+ /**
1482
+ * Processors that are nested under this processor
1483
+ */
1484
+ processors?: ICliCommandChildProcessor[];
1485
+ /**
1486
+ * Parameters that the command accepts
1487
+ */
1488
+ parameters?: ICliCommandParameterDescriptor[];
1489
+ /**
1490
+ * Hooks that are executed before and after the command is processed
1491
+ */
1492
+ hooks?: ICliProcessorHook[];
1493
+ /**
1494
+ * Represents the state configuration for the command processor
1495
+ * @remarks The state configuration is used to store and retrieve state information for the command processor
1496
+ * @remarks State configuration is optional and can be used to store and retrieve state information for the command processor
1497
+ * @remarks The state configuration is used only for root command processors and not for child command processors
1498
+ */
1499
+ stateConfiguration?: CliStateConfiguration;
1500
+ /**
1501
+ * Configuration options exposed by this processor for the `configure` command.
1502
+ * When defined, these options appear in the interactive configuration menu
1503
+ * and can be managed via `configure get/set` subcommands.
1504
+ */
1505
+ configurationOptions?: ICliConfigurationOption[];
1506
+ /**
1507
+ * When true, this processor extends (wraps) an existing processor with the same
1508
+ * command name instead of replacing it. The registry sets `originalProcessor`
1509
+ * to the previous processor so this one can delegate to it.
1510
+ */
1511
+ extendsProcessor?: boolean;
1512
+ /**
1513
+ * Reference to the original processor that this one extends.
1514
+ * Set automatically by the registry — do not set manually.
1515
+ * Call `this.originalProcessor.processCommand(command, context)` to delegate.
1516
+ */
1517
+ originalProcessor?: ICliCommandProcessor;
1518
+ /**
1519
+ * Process the command
1520
+ * @param command The command to process
1521
+ * @param context The context in which the command is executed
1522
+ */
1523
+ processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
1524
+ /**
1525
+ * Write the description of the command
1526
+ * @param context The context in which the command is executed
1527
+ */
1528
+ writeDescription?(context: ICliExecutionContext): void;
1529
+ /**
1530
+ * A function that validates the command before execution
1531
+ * @param value The value to validate
1532
+ * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
1533
+ */
1534
+ validateBeforeExecution?: (command: CliProcessCommand, context: ICliExecutionContext) => {
1535
+ valid: boolean;
1536
+ message?: string;
1537
+ };
1538
+ /**
1539
+ * Initialize the command processor
1540
+ * @param context The context in which the command is executed
1541
+ */
1542
+ initialize?(context: ICliExecutionContext): Promise<void>;
1543
+ /**
1544
+ * Handle raw terminal data when this processor is the active context processor.
1545
+ * When implemented, ALL terminal input is routed here instead of normal CLI input handling.
1546
+ * Used for full-screen interactive modes (editors, pagers, etc.).
1547
+ * @param data The raw terminal data string (escape sequences, control chars, printable text)
1548
+ * @param context The execution context
1549
+ */
1550
+ onData?(data: string, context: ICliExecutionContext): Promise<void>;
1551
+ /**
1552
+ * Called when the terminal is resized while this processor is the active
1553
+ * full-screen context processor. Allows processors to adapt their rendering
1554
+ * to the new terminal dimensions.
1555
+ * @param cols The new number of columns
1556
+ * @param rows The new number of rows
1557
+ * @param context The execution context
1558
+ */
1559
+ onResize?(cols: number, rows: number, context: ICliExecutionContext): void;
1560
+ /**
1561
+ * Called when the processor is being disposed — either because full-screen
1562
+ * mode ended, the terminal disconnected, or the CLI component is being
1563
+ * destroyed. Use this to clean up resources (timers, subscriptions, etc.).
1564
+ * @param context The execution context
1565
+ */
1566
+ onDispose?(context: ICliExecutionContext): void;
1567
+ }
1568
+ /**
1569
+ * Represents a child command processor
1570
+ */
1571
+ interface ICliCommandChildProcessor extends ICliCommandProcessor {
1572
+ /**
1573
+ * The parent processor, it is populated by the processor manager
1574
+ */
1575
+ parent?: ICliCommandProcessor;
1576
+ }
1577
+
1578
+ /**
1579
+ * Describes a global parameter (e.g. --help, --version) together with
1580
+ * the handler that executes when the parameter is present.
1581
+ *
1582
+ * Global parameters are checked for every command before the command
1583
+ * processor's own `processCommand` runs. If the handler returns `true`,
1584
+ * command execution is halted (the parameter "consumed" the invocation).
1585
+ */
1586
+ interface ICliGlobalParameterHandler {
1587
+ /**
1588
+ * The parameter descriptor shown in help output and used for tab-completion.
1589
+ */
1590
+ parameter: ICliCommandParameterDescriptor;
1591
+ /**
1592
+ * Execution priority — lower values run first.
1593
+ * @default 0
1594
+ */
1595
+ priority?: number;
1596
+ /**
1597
+ * Evaluate and optionally handle the parameter.
1598
+ * @returns `true` to halt command execution, `false` to continue.
1599
+ */
1600
+ handle(args: Record<string, any>, processor: ICliCommandProcessor, command: CliProcessCommand, context: ICliExecutionContext): boolean | Promise<boolean>;
1601
+ }
1602
+
1603
+ /**
1604
+ * Represents a service that executes commands
1605
+ */
1606
+ interface ICliCommandExecutorService {
1607
+ /**
1608
+ * Display the help output for a command, including its description,
1609
+ * sub-commands, and parameters.
1610
+ * @param command The parsed command to show help for
1611
+ * @param context The execution context
1612
+ */
1613
+ showHelp(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
1614
+ /**
1615
+ * Execute a command
1616
+ * @param command The command to execute
1617
+ * @param context The context in which the command is executed
1618
+ */
1619
+ executeCommand(command: string, context: ICliExecutionContext): Promise<void>;
1620
+ /**
1621
+ * Register a global parameter handler.
1622
+ * Global parameters (e.g. --help, --version) are evaluated for every
1623
+ * command before the processor's own processCommand runs.
1624
+ * @param handler The global parameter handler to register
1625
+ */
1626
+ registerGlobalParameter(handler: ICliGlobalParameterHandler): void;
1627
+ /**
1628
+ * Returns the descriptors of all registered global parameters.
1629
+ * Used by help output and tab-completion.
1630
+ */
1631
+ getGlobalParameters(): ICliCommandParameterDescriptor[];
1632
+ }
1633
+
1634
+ /**
1635
+ * Represents a registry for command processors
1636
+ */
1637
+ interface ICliCommandProcessorRegistry {
1638
+ /**
1639
+ * The processors registered with the registry
1640
+ */
1641
+ readonly processors: ICliCommandProcessor[];
1642
+ /**
1643
+ * Find a processor for a command
1644
+ * @param mainCommand
1645
+ * @param chainCommands
1646
+ */
1647
+ findProcessor(mainCommand: string, chainCommands: string[]): ICliCommandProcessor | undefined;
1648
+ /**
1649
+ * Recursively searches for a processor matching the given command.
1650
+ * @param mainCommand The main command name.
1651
+ * @param chainCommands The remaining chain commands (if any).
1652
+ * @param processors The list of available processors.
1653
+ * @returns The matching processor or undefined if not found.
1654
+ */
1655
+ findProcessorInCollection(mainCommand: string, chainCommands: string[], processors: ICliCommandProcessor[]): ICliCommandProcessor | undefined;
1656
+ /**
1657
+ * Get the root processor for a child processor
1658
+ * @param child The child processor
1659
+ */
1660
+ getRootProcessor(child: ICliCommandChildProcessor): ICliCommandProcessor;
1661
+ /**
1662
+ * Register a processor
1663
+ * @param processor
1664
+ */
1665
+ registerProcessor(processor: ICliCommandProcessor): void;
1666
+ /**
1667
+ * Unregister a processor
1668
+ * @param processor
1669
+ */
1670
+ unregisterProcessor(processor: ICliCommandProcessor): void;
1671
+ }
1672
+ /**
1673
+ * Represents a tracked CLI process entry
1674
+ */
1675
+ interface ICliProcessEntry {
1676
+ pid: number;
1677
+ /** Display name (service name for bg services, command text for commands) */
1678
+ name: string;
1679
+ /** Process type */
1680
+ type: 'command' | 'daemon' | 'job' | 'service';
1681
+ command: string;
1682
+ startTime: number;
1683
+ status: 'running' | 'completed' | 'failed' | 'killed';
1684
+ exitCode?: number;
1685
+ }
1686
+ /** Options for registering a process */
1687
+ interface ICliProcessRegisterOptions {
1688
+ /** Display name (defaults to command) */
1689
+ name?: string;
1690
+ /** Process type (defaults to 'command') */
1691
+ type?: 'command' | 'daemon' | 'job' | 'service';
1692
+ /** Custom kill handler (e.g. for background services) */
1693
+ onKill?: () => Promise<void> | void;
1694
+ }
1695
+ /**
1696
+ * Registry for tracking CLI processes
1697
+ */
1698
+ interface ICliProcessRegistry {
1699
+ /** Register a new process, returns assigned PID */
1700
+ register(command: string, options?: ICliProcessRegisterOptions): {
1701
+ pid: number;
1702
+ abortController: AbortController;
1703
+ };
1704
+ /** Mark process as completed */
1705
+ complete(pid: number, exitCode: number): void;
1706
+ /** Mark process as failed */
1707
+ fail(pid: number): void;
1708
+ /** Kill a process by PID */
1709
+ kill(pid: number): boolean;
1710
+ /** List all processes (running + recent completed) */
1711
+ list(): ICliProcessEntry[];
1712
+ /** Get the current foreground process PID */
1713
+ readonly currentPid: number | undefined;
1714
+ }
1715
+
1716
+ interface ICliExecutionProcess {
1717
+ /**
1718
+ * Indicates if the process has exited
1719
+ */
1720
+ exited?: boolean;
1721
+ /**
1722
+ * The exit code of the process
1723
+ */
1724
+ exitCode?: number;
1725
+ /**
1726
+ * Indicates if the process is running
1727
+ */
1728
+ running: boolean;
1729
+ /**
1730
+ * The data of the process
1731
+ */
1732
+ data: any | undefined;
1733
+ /**
1734
+ * Exit the process
1735
+ * @param code The exit code
1736
+ * @returns void
1737
+ */
1738
+ exit: (
1739
+ /**
1740
+ * The exit code
1741
+ */
1742
+ code?: number,
1743
+ /**
1744
+ * Options for exiting the process
1745
+ */
1746
+ options?: {
1747
+ /**
1748
+ * Indicates if the exit should be silent, i.e. not throw an error
1749
+ */
1750
+ silent?: boolean;
1751
+ }) => void;
1752
+ /**
1753
+ * Output data from the process
1754
+ * @param data The data to output
1755
+ */
1756
+ output(data: any): void;
1757
+ }
1758
+
1759
+ /**
1760
+ * Represents a key-value store for the CLI
1761
+ */
1762
+ interface ICliKeyValueStore {
1763
+ /**
1764
+ * Retrieves a value by key.
1765
+ * @param key - The key to retrieve the value for.
1766
+ * @returns A promise resolving to the value or undefined if not found.
1767
+ */
1768
+ get<T = any>(key: string): Promise<T | undefined>;
1769
+ /**
1770
+ * Sets a key-value pair in the store.
1771
+ * @param key - The key to set.
1772
+ * @param value - The value to store.
1773
+ * @returns A promise resolving when the value is stored.
1774
+ */
1775
+ set(key: string, value: any): Promise<void>;
1776
+ /**
1777
+ * Removes a key-value pair by key.
1778
+ * @param key - The key to remove.
1779
+ * @returns A promise resolving when the key is removed.
1780
+ */
1781
+ remove(key: string): Promise<void>;
1782
+ /**
1783
+ * Clears all key-value pairs from the store.
1784
+ * @returns A promise resolving when the store is cleared.
1785
+ */
1786
+ clear(): Promise<void>;
1787
+ }
1788
+ /**
1789
+ * Reactive state store scoped to a command processor or module.
1790
+ *
1791
+ * State is a plain object (`Record<string, any>`). Updates are shallow-merged
1792
+ * (top-level keys are replaced, nested objects are not deep-merged).
1793
+ * `getState()` returns a snapshot — mutating the returned object has no effect;
1794
+ * always use `updateState()` to change state.
1795
+ */
1796
+ interface ICliStateStore {
1797
+ /**
1798
+ * Get a snapshot of the current state.
1799
+ * @returns A shallow copy of the state object
1800
+ */
1801
+ getState<T extends CliState = CliState>(): T;
1802
+ /**
1803
+ * Shallow-merge new values into the current state.
1804
+ * Only the provided keys are updated; other keys are preserved.
1805
+ * Triggers subscribers and persists if a storage backend is configured.
1806
+ * @param newState Partial state to merge with the current state
1807
+ */
1808
+ updateState(newState: Partial<CliState>): void;
1809
+ /**
1810
+ * Select a specific property or computed value from the state.
1811
+ * @param selector A function to project a slice of the state.
1812
+ * @returns Observable of the selected value.
1813
+ */
1814
+ select<K>(selector: (state: CliState) => K): Observable<K>;
1815
+ /**
1816
+ * Subscribe to state changes.
1817
+ * @param callback Callback function to handle state changes.
1818
+ * @returns Subscription object to manage the subscription.
1819
+ */
1820
+ subscribe(callback: (state: CliState) => void): Subscription;
1821
+ /**
1822
+ * Reset the state to its initial value.
1823
+ */
1824
+ reset(): void;
1825
+ /**
1826
+ * Persist the state to storage.
1827
+ */
1828
+ persist(): Promise<void>;
1829
+ /**
1830
+ * Initialize the state from storage.
1831
+ */
1832
+ initialize(): Promise<void>;
1833
+ }
1834
+
1835
+ /**
1836
+ * Represents a service that pings the server
1837
+ */
1838
+ interface ICliPingServerService {
1839
+ /**
1840
+ * Pings the server
1841
+ */
1842
+ ping(): Promise<void>;
1843
+ }
1844
+ /**
1845
+ * Represents a module for the web CLI (frontend).
1846
+ *
1847
+ * This interface is for **web/frontend plugins only** — browser-side modules
1848
+ * that extend the CLI terminal UI (e.g. `@qodalis/cli-guid`, `@qodalis/cli-tetris`).
1849
+ *
1850
+ * It is **not** related to backend server processors (Node/Python/.NET).
1851
+ * Backend command processors implement their own `ICliCommandProcessor` interfaces
1852
+ * in their respective server packages and do not use `apiVersion`.
1853
+ */
1854
+ interface ICliModule {
1855
+ /**
1856
+ * The web plugin API version this module targets.
1857
+ *
1858
+ * This is a **frontend-only** concept used by the browser CLI runtime
1859
+ * to ensure plugin compatibility. It has no relation to backend server
1860
+ * API versioning (e.g. `/api/v1/qcli/`).
1861
+ *
1862
+ * Modules with `apiVersion` less than the runtime's `API_VERSION` are
1863
+ * rejected with a warning at boot time.
1864
+ *
1865
+ * Use the `API_VERSION` constant exported from `@qodalis/cli-core` to
1866
+ * target the current runtime version.
1867
+ */
1868
+ apiVersion: number;
1869
+ /** Unique module identifier, e.g. '@qodalis/cli-guid' */
1870
+ name: string;
1871
+ /** Semver version string */
1872
+ version?: string;
1873
+ /** Human-readable description */
1874
+ description?: string;
1875
+ /** Module names this module depends on (resolved before this module boots) */
1876
+ dependencies?: string[];
1877
+ /** Boot priority — lower values boot first (default: 0) */
1878
+ priority?: number;
1879
+ /** Command processors provided by this module */
1880
+ processors?: ICliCommandProcessor[];
1881
+ /** Services registered into the shared service container */
1882
+ services?: CliProvider[];
1883
+ /** Module configuration, set via configure() */
1884
+ config?: Record<string, any>;
1885
+ /**
1886
+ * Per-locale translation maps shipped by this module.
1887
+ * Keyed by locale code (e.g. 'es', 'fr'), each value is a flat
1888
+ * key-value map of translation keys to translated strings.
1889
+ *
1890
+ * These are automatically registered with the translation service
1891
+ * during module boot — no manual onInit() code required.
1892
+ *
1893
+ * @example
1894
+ * translations: {
1895
+ * es: { 'cli.guid.description': 'Generar y validar UUIDs' },
1896
+ * fr: { 'cli.guid.description': 'Générer et valider des UUIDs' },
1897
+ * }
1898
+ */
1899
+ translations?: Record<string, Record<string, string>>;
1900
+ /**
1901
+ * Returns a configured copy of this module.
1902
+ * Modules should narrow the config type via a module-specific interface.
1903
+ */
1904
+ configure?(config: any): ICliModule;
1905
+ /** Called after services are registered and before processors are initialized */
1906
+ onInit?(context: ICliExecutionContext): Promise<void>;
1907
+ /**
1908
+ * Optional first-run setup flow. Called during boot if the module
1909
+ * has not been set up yet (determined by a persisted flag in the
1910
+ * key-value store). Use context.reader to prompt the user for
1911
+ * initial configuration.
1912
+ *
1913
+ * @returns true to mark setup as complete; false/throw to abort
1914
+ * (module still loads, setup re-triggers next boot).
1915
+ */
1916
+ onSetup?(context: ICliExecutionContext): Promise<boolean>;
1917
+ /** Called after all modules have booted and the terminal is interactive */
1918
+ onAfterBoot?(context: ICliExecutionContext): Promise<void>;
1919
+ /** Called when the module is being torn down */
1920
+ onDestroy?(context: ICliExecutionContext): Promise<void>;
1921
+ }
1922
+ /**
1923
+ * A module that accepts typed configuration via `configure()`.
1924
+ * Extend this instead of `ICliModule` when your module has a config type.
1925
+ *
1926
+ * @example
1927
+ * ```ts
1928
+ * interface MyModuleConfig { verbose?: boolean }
1929
+ * const myModule: ICliConfigurableModule<MyModuleConfig> = {
1930
+ * configure(config) { return { ...this, config }; },
1931
+ * // ...
1932
+ * };
1933
+ * ```
1934
+ */
1935
+ interface ICliConfigurableModule<T extends Record<string, any> = Record<string, any>> extends ICliModule {
1936
+ configure(config: T): ICliModule;
1937
+ }
1938
+ /**
1939
+ * @deprecated Use ICliModule instead
1940
+ */
1941
+ type ICliUmdModule = ICliModule;
1942
+ /**
1943
+ * Represents a logger for the CLI
1944
+ */
1945
+ interface ICliLogger {
1946
+ /**
1947
+ * Set the log level of the logger
1948
+ * @param level The log level to set
1949
+ * @returns void
1950
+ * @default CliLogLevel.ERROR
1951
+ */
1952
+ setCliLogLevel(level: CliLogLevel): void;
1953
+ /**
1954
+ * Log a general message (LOG level)
1955
+ * @param args The arguments to log
1956
+ */
1957
+ log(...args: any[]): void;
1958
+ /**
1959
+ * Log an informational message (INFO level)
1960
+ * @param args The arguments to log
1961
+ */
1962
+ info(...args: any[]): void;
1963
+ /**
1964
+ * Log a warning message (WARN level)
1965
+ * @param args The arguments to log
1966
+ */
1967
+ warn(...args: any[]): void;
1968
+ /**
1969
+ * Log an error message (ERROR level)
1970
+ * @param args The arguments to log
1971
+ */
1972
+ error(...args: any[]): void;
1973
+ /**
1974
+ * Log a debug message (DEBUG level)
1975
+ * @param args The arguments to log
1976
+ */
1977
+ debug(...args: any[]): void;
1978
+ }
1979
+
1980
+ /**
1981
+ * Provides internationalization (i18n) support for CLI strings.
1982
+ */
1983
+ interface ICliTranslationService {
1984
+ /**
1985
+ * Translate a key to the current locale.
1986
+ * @param key The translation key (e.g. 'cli.echo.description')
1987
+ * @param defaultValue The English fallback string (returned if no translation found)
1988
+ * @param params Optional interpolation parameters for `{param}` placeholders
1989
+ */
1990
+ t(key: string, defaultValue: string, params?: Record<string, string | number>): string;
1991
+ /**
1992
+ * Get the current locale code (e.g. 'en', 'es', 'fr').
1993
+ */
1994
+ getLocale(): string;
1995
+ /**
1996
+ * Set the active locale.
1997
+ * @param locale The locale code to switch to
1998
+ */
1999
+ setLocale(locale: string): void;
2000
+ /**
2001
+ * Register translations for a locale.
2002
+ * Can be called multiple times — translations are merged, with later calls overriding earlier ones.
2003
+ * @param locale The locale code
2004
+ * @param translations Flat key-value map of translation keys to translated strings
2005
+ */
2006
+ addTranslations(locale: string, translations: Record<string, string>): void;
2007
+ /**
2008
+ * Get all locale codes that have at least one registered translation.
2009
+ */
2010
+ getAvailableLocales(): string[];
2011
+ }
2012
+ /**
2013
+ * Dependency injection container for CLI services.
2014
+ * Services are registered with string tokens and retrieved by type.
2015
+ */
2016
+ interface ICliServiceProvider {
2017
+ /**
2018
+ * Retrieve a service by its injection token.
2019
+ * @param service The token (typically a `*_TOKEN` constant) identifying the service
2020
+ * @returns The service instance, cast to `T`
2021
+ * @throws If no service is registered for the given token
2022
+ */
2023
+ get<T = unknown>(service: any): T;
2024
+ /**
2025
+ * Register one or more service definitions.
2026
+ * @param definition A single provider or an array of providers to register
2027
+ */
2028
+ set(definition: CliProvider | CliProvider[]): void;
2029
+ }
2030
+
2031
+ /**
2032
+ * Abstract permission service for checking rwx permissions on resources.
2033
+ * The default implementation lives in @qodalis/cli-users; consumers can
2034
+ * replace it via the DI container.
2035
+ */
2036
+ interface ICliPermissionService {
2037
+ /**
2038
+ * Check whether a user may perform an action on a resource.
2039
+ * @param user The acting user.
2040
+ * @param action The requested operation.
2041
+ * @param ownership Owner/group of the resource.
2042
+ * @param permissions Permission string (e.g. "rwxr-xr-x").
2043
+ * @returns true if allowed.
2044
+ */
2045
+ check(user: ICliUser, action: 'read' | 'write' | 'execute', ownership: ICliOwnership, permissions: string): boolean;
2046
+ /** Parse octal (e.g. "755") to a permission string (e.g. "rwxr-xr-x"). */
2047
+ parseOctal(octal: string): string;
2048
+ /** Convert a permission string (e.g. "rwxr-xr-x") to octal (e.g. "755"). */
2049
+ toOctal(permissions: string): string;
2050
+ }
2051
+
2052
+ /**
2053
+ * Context passed to completion providers describing the current input state.
2054
+ */
2055
+ interface ICliCompletionContext {
2056
+ /** Full current line text */
2057
+ input: string;
2058
+ /** Cursor position in the line */
2059
+ cursor: number;
2060
+ /** The token (word) being completed at the cursor position */
2061
+ token: string;
2062
+ /** Start index of the token in the input string */
2063
+ tokenStart: number;
2064
+ /** Index of the token among all tokens (0 = command, 1+ = arguments) */
2065
+ tokenIndex: number;
2066
+ /** All tokens parsed from the input */
2067
+ tokens: string[];
2068
+ }
2069
+ /**
2070
+ * Provides tab-completion candidates for CLI input.
2071
+ * Plugins can register providers to extend completion (e.g. file paths, custom values).
2072
+ */
2073
+ interface ICliCompletionProvider {
2074
+ /**
2075
+ * Priority order. Lower values are checked first.
2076
+ * Built-in defaults: 100 (commands), 200 (parameters).
2077
+ * Plugins should use lower values (e.g. 50) to take precedence for specific commands.
2078
+ */
2079
+ priority: number;
2080
+ /**
2081
+ * Return completion candidates for the current input context.
2082
+ * Return an empty array if this provider does not apply.
2083
+ */
2084
+ getCompletions(context: ICliCompletionContext): string[] | Promise<string[]>;
2085
+ }
2086
+
2087
+ interface ICliProgressBar {
2088
+ /**
2089
+ * Indicates if the progress bar is running
2090
+ */
2091
+ isRunning: boolean;
2092
+ /**
2093
+ * Show the progress bar
2094
+ */
2095
+ show: (text?: string) => void;
2096
+ /**
2097
+ * Hide the progress bar
2098
+ */
2099
+ hide: () => void;
2100
+ }
2101
+ /**
2102
+ * Represents a spinner for the CLI
2103
+ */
2104
+ interface ICliSpinner extends ICliProgressBar {
2105
+ /**
2106
+ * Set the text of the spinner
2107
+ * @param text The text to set
2108
+ */
2109
+ setText: (text: string) => void;
2110
+ }
2111
+ type CliPercentageProgressBarUpdateValueOptions = {
2112
+ /**
2113
+ * The type of update to perform
2114
+ * @default 'replace'
2115
+ */
2116
+ type?: 'replace' | 'increment';
2117
+ };
2118
+ /**
2119
+ * Represents a progress bar for the CLI
2120
+ */
2121
+ interface ICliPercentageProgressBar extends ICliProgressBar {
2122
+ /**
2123
+ * Update the progress of the progress bar.
2124
+ * @param progress The progress value (0–100). Values outside this range are clamped.
2125
+ * @param options Optional: update type ('replace' or 'increment')
2126
+ */
2127
+ update: (progress: number, options?: CliPercentageProgressBarUpdateValueOptions) => void;
2128
+ /**
2129
+ * Complete the progress bar
2130
+ * @returns void
2131
+ */
2132
+ complete: () => void;
2133
+ /**
2134
+ * Set the text of the spinner
2135
+ * @param text The text to set
2136
+ */
2137
+ setText: (text: string) => void;
2138
+ }
2139
+ type CliTextAnimatorOptions = {
2140
+ /**
2141
+ * The speed of the animation
2142
+ * @default 100
2143
+ */
2144
+ speed?: number;
2145
+ /**
2146
+ * The text will be removed after typing
2147
+ */
2148
+ removeAfterTyping?: boolean;
2149
+ };
2150
+ interface ICliTextAnimator extends ICliProgressBar {
2151
+ /**
2152
+ * Show animated text in a typing and erasing effect.
2153
+ * @param text The text to animate
2154
+ * @param options Optional: speed (ms per character), removeAfterTyping
2155
+ * @returns A promise that resolves when the animation completes
2156
+ */
2157
+ showText: (text: string, options?: CliTextAnimatorOptions) => Promise<void>;
2158
+ }
2159
+
2160
+ /**
2161
+ * Represents a service that manages user sessions in the CLI
2162
+ */
2163
+ interface ICliUserSessionService {
2164
+ /** Gets the current user session as a reactive stream */
2165
+ getUserSession(): Observable<ICliUserSession | undefined>;
2166
+ /** Sets the current user session */
2167
+ setUserSession(session: ICliUserSession): Promise<void>;
2168
+ /** Clears the current session (logout) */
2169
+ clearSession(): Promise<void>;
2170
+ /** Persists the current session to storage */
2171
+ persistSession(): Promise<void>;
2172
+ /** Restores a session from storage (called on boot) */
2173
+ restoreSession(): Promise<ICliUserSession | undefined>;
2174
+ }
2175
+ /**
2176
+ * Represents a service that manages users in the CLI
2177
+ */
2178
+ interface ICliUsersStoreService {
2179
+ /** Gets users with optional filtering and pagination */
2180
+ getUsers(options?: {
2181
+ query?: string;
2182
+ skip?: number;
2183
+ take?: number;
2184
+ }): Observable<ICliUser[]>;
2185
+ /** Creates a new user */
2186
+ createUser(user: CliAddUser): Promise<ICliUser>;
2187
+ /** Gets a user by id, name, or email */
2188
+ getUser(id: string): Observable<ICliUser | undefined>;
2189
+ /** Updates an existing user */
2190
+ updateUser(id: string, updates: CliUpdateUser): Promise<ICliUser>;
2191
+ /** Deletes a user by id */
2192
+ deleteUser(id: string): Promise<void>;
2193
+ }
2194
+ /**
2195
+ * Represents a service that manages groups in the CLI
2196
+ */
2197
+ interface ICliGroupsStoreService {
2198
+ /** Gets all groups */
2199
+ getGroups(): Observable<ICliGroup[]>;
2200
+ /** Gets a group by id or name */
2201
+ getGroup(id: string): Observable<ICliGroup | undefined>;
2202
+ /** Creates a new group */
2203
+ createGroup(name: string, description?: string): Promise<ICliGroup>;
2204
+ /** Deletes a group by id */
2205
+ deleteGroup(id: string): Promise<void>;
2206
+ /** Gets all users that belong to a group */
2207
+ getGroupMembers(groupId: string): Observable<ICliUser[]>;
2208
+ }
2209
+ /**
2210
+ * Represents a service that handles authentication in the CLI
2211
+ */
2212
+ interface ICliAuthService {
2213
+ /** Authenticates a user and returns a session */
2214
+ login(username: string, password: string): Promise<ICliUserSession>;
2215
+ /** Ends the current session */
2216
+ logout(): Promise<void>;
2217
+ /** Sets or updates a user's password */
2218
+ setPassword(userId: string, password: string): Promise<void>;
2219
+ /** Verifies a password against stored credentials */
2220
+ verifyPassword(userId: string, password: string): Promise<boolean>;
2221
+ /** Hashes a password with a salt using Web Crypto SHA-256 */
2222
+ hashPassword(password: string, salt: string): Promise<string>;
2223
+ }
2224
+
2225
+ /**
2226
+ * Represents a serialized snapshot of a CLI engine's state.
2227
+ * Used to duplicate terminal tabs with full state preservation.
2228
+ */
2229
+ interface CliEngineSnapshot {
2230
+ /** Schema version for forward compatibility */
2231
+ version: 1;
2232
+ /** Timestamp (ms since epoch) when the snapshot was taken */
2233
+ timestamp: number;
2234
+ /** Serialized terminal state */
2235
+ terminal: {
2236
+ /** Terminal buffer serialized via @xterm/addon-serialize */
2237
+ serializedBuffer: string;
2238
+ /** Terminal column count at time of snapshot */
2239
+ cols: number;
2240
+ /** Terminal row count at time of snapshot */
2241
+ rows: number;
2242
+ };
2243
+ /** Command history entries (most recent last) */
2244
+ commandHistory: string[];
2245
+ /** Named state store entries */
2246
+ stateStores: Array<{
2247
+ name: string;
2248
+ state: Record<string, any>;
2249
+ }>;
2250
+ }
2251
+
2252
+ /**
2253
+ * Messages sent from the main thread to a background service Worker.
2254
+ */
2255
+ type CliWorkerInboundMessage = {
2256
+ type: 'start';
2257
+ config?: Record<string, unknown>;
2258
+ } | {
2259
+ type: 'stop';
2260
+ } | {
2261
+ type: 'abort';
2262
+ };
2263
+ /**
2264
+ * Messages sent from a background service Worker to the main thread.
2265
+ */
2266
+ type CliWorkerOutboundMessage = {
2267
+ type: 'log';
2268
+ level: 'info' | 'warn' | 'error';
2269
+ message: string;
2270
+ } | {
2271
+ type: 'event';
2272
+ event: Omit<ICliServiceEvent, 'timestamp'>;
2273
+ } | {
2274
+ type: 'state-update';
2275
+ patch: Record<string, unknown>;
2276
+ } | {
2277
+ type: 'status';
2278
+ status: CliBackgroundServiceStatus;
2279
+ } | {
2280
+ type: 'error';
2281
+ message: string;
2282
+ stack?: string;
2283
+ };
2284
+
2285
+ /**
2286
+ * Represents an entry in a file listing.
2287
+ */
2288
+ interface ICliFileEntry {
2289
+ name: string;
2290
+ type: 'file' | 'directory';
2291
+ size: number;
2292
+ modified: string;
2293
+ }
2294
+
2295
+ /**
2296
+ * Abstraction for file transfer operations.
2297
+ * Default implementation uses browser-native APIs (file picker, download dialog).
2298
+ * @qodalis/cli-files overrides with virtual FS backed by IndexedDB.
2299
+ */
2300
+ interface ICliFileTransferService {
2301
+ readFile(path: string): Promise<string | null>;
2302
+ writeFile(path: string, content: string): Promise<void>;
2303
+ listFiles(path: string): Promise<ICliFileEntry[]>;
2304
+ exists(path: string): Promise<boolean>;
2305
+ downloadToBrowser(filename: string, content: string | Blob): void;
2306
+ uploadFromBrowser(accept?: string): Promise<{
2307
+ name: string;
2308
+ content: string;
2309
+ } | null>;
2310
+ }
2311
+
2312
+ interface ICliDragDropService {
2313
+ /** Emits an array of dropped File objects each time files are dropped onto the terminal */
2314
+ readonly onFileDrop: Observable<File[]>;
2315
+ }
2316
+
2317
+ /**
2318
+ * Opaque state value carried between lines during syntax highlighting.
2319
+ * Encodes context such as "inside a multi-line string" or "inside a block comment"
2320
+ * so the highlighter can resume correctly on the next line.
2321
+ * `0` typically represents the default/root state.
2322
+ */
2323
+ type LineState = number;
2324
+ interface ISyntaxHighlightRule {
2325
+ pattern: RegExp;
2326
+ tokenType: string;
2327
+ captureGroup?: number;
2328
+ }
2329
+ interface ISyntaxHighlighter {
2330
+ id: string;
2331
+ /** Human-readable language name (e.g. 'TypeScript'). Falls back to `id` when absent. */
2332
+ name?: string;
2333
+ extensions: string[];
2334
+ initialState: LineState;
2335
+ getRules(state: LineState): ISyntaxHighlightRule[];
2336
+ getNextLineState(line: string, currentState: LineState): LineState;
2337
+ }
2338
+ interface ISyntaxTheme {
2339
+ name: string;
2340
+ colors: Record<string, string>;
2341
+ }
2342
+
2343
+ /**
2344
+ * Registry that tracks loaded web CLI modules (frontend plugins) and dispatches
2345
+ * boot handlers when new modules are registered (including dynamically via UMD).
2346
+ *
2347
+ * This registry is for **browser-side web plugins only**. Backend server
2348
+ * processors (Node/Python/.NET) have their own registries and do not use
2349
+ * this class or the `apiVersion` gating mechanism.
2350
+ */
2351
+ declare class CliModuleRegistry {
2352
+ private readonly modules;
2353
+ private readonly bootHandlers;
2354
+ /** Optional warning callback — set by the engine to route through ICliLogger */
2355
+ onWarn?: (message: string) => void;
2356
+ /**
2357
+ * Register a handler that is called whenever a new module is registered.
2358
+ */
2359
+ onModuleBoot(handler: (module: ICliModule) => Promise<void>): void;
2360
+ /**
2361
+ * Register a web plugin module and notify all boot handlers.
2362
+ * Modules whose `apiVersion` is below the runtime's `API_VERSION` are
2363
+ * skipped with a warning — this ensures only compatible frontend plugins load.
2364
+ */
2365
+ register(module: ICliModule): Promise<void>;
2366
+ /**
2367
+ * Get a module by name.
2368
+ */
2369
+ getModule(name: string): ICliModule | undefined;
2370
+ /**
2371
+ * Get all registered modules.
2372
+ */
2373
+ getAll(): ICliModule[];
2374
+ /**
2375
+ * Track a module without triggering boot handlers.
2376
+ * Used by the boot service for statically-provided modules that are
2377
+ * already being booted through the normal pipeline.
2378
+ */
2379
+ track(module: ICliModule): void;
2380
+ /**
2381
+ * Check if a module is registered.
2382
+ */
2383
+ has(name: string): boolean;
2384
+ }
2385
+
2386
+ declare const initializeBrowserEnvironment: ({ context, registry, }: {
2387
+ context: ICliExecutionContext;
2388
+ registry: CliModuleRegistry;
2389
+ }) => void;
2390
+ /**
2391
+ * Boot a CLI module by registering it with the global module registry.
2392
+ * Used by UMD entrypoints to register themselves when loaded dynamically.
2393
+ */
2394
+ declare const bootCliModule: (module: ICliModule) => Promise<void>;
2395
+ /**
2396
+ * @deprecated Use bootCliModule instead
2397
+ */
2398
+ declare const bootUmdModule: (module: ICliModule) => Promise<void>;
2399
+
2400
+ declare class ObjectDescriber {
2401
+ static describe(obj: any, options?: {
2402
+ filter?: (o: {
2403
+ funcName: string;
2404
+ func: any;
2405
+ args: string[];
2406
+ }) => boolean;
2407
+ }): ICliCommandProcessor[];
2408
+ static supportsDynamicArgs(func: any): boolean;
2409
+ static getFunctionArguments(func: any): string[];
2410
+ }
2411
+
2412
+ /**
2413
+ * Token for the configure command's state store.
2414
+ */
2415
+ declare const CLI_CONFIGURE_STORE_NAME = "configure";
2416
+ /**
2417
+ * Retrieves a configuration value for a given category and key
2418
+ * from a configuration state store.
2419
+ *
2420
+ * @param state The state store to read from (should be the 'configure' store)
2421
+ * @param category The category (processor command name or 'system')
2422
+ * @param key The configuration key
2423
+ * @param defaultValue Fallback value if not configured
2424
+ * @returns The configured value or the default
2425
+ */
2426
+ declare function getConfigValue<T = any>(state: ICliStateStore, category: string, key: string, defaultValue: T): T;
2427
+ /**
2428
+ * Retrieves a plugin configuration value from the execution context.
2429
+ * This is a convenience wrapper for plugins — handles store lookup internally.
2430
+ *
2431
+ * @param context The execution context
2432
+ * @param category The category (usually the processor's command name)
2433
+ * @param key The configuration key
2434
+ * @param defaultValue Fallback value if not configured
2435
+ * @returns The configured value or the default
2436
+ */
2437
+ declare function getPluginConfigValue<T = any>(context: ICliExecutionContext, category: string, key: string, defaultValue: T): T;
2438
+ /**
2439
+ * Resolves all configuration options from registered processors,
2440
+ * grouped by category.
2441
+ */
2442
+ declare function resolveConfigurationCategories(registry: ICliCommandProcessorRegistry): Map<string, {
2443
+ processorCommand: string;
2444
+ options: ICliConfigurationOption[];
2445
+ }>;
2446
+
2447
+ /**
2448
+ * Returns a promise that resolves after the given number of milliseconds.
2449
+ * @param ms Delay duration in milliseconds
2450
+ */
2451
+ declare const delay: (ms: number) => Promise<void>;
2452
+
2453
+ /**
2454
+ * Clears the current line in the terminal, accounting for text that wraps across multiple lines.
2455
+ * @param terminal The xterm terminal instance
2456
+ * @param contentLength The total visible character count on the line (prompt + text)
2457
+ */
2458
+ declare const clearTerminalLine: (terminal: Terminal, contentLength: number) => void;
2459
+
2460
+ /**
2461
+ * Compares two dotted version strings.
2462
+ * Returns -1 if a < b, 0 if equal, 1 if a > b.
2463
+ */
2464
+ declare function compareVersions(a: string, b: string): -1 | 0 | 1;
2465
+ /**
2466
+ * Returns true if the installed version satisfies the minimum required version.
2467
+ */
2468
+ declare function satisfiesMinVersion(installed: string, required: string): boolean;
2469
+ /**
2470
+ * Returns true if the installed version satisfies the given semver range.
2471
+ * If range is undefined/empty, returns true (no constraint).
2472
+ * If range looks like a plain version (no operators), treats it as >= that version.
2473
+ */
2474
+ declare function satisfiesVersionRange(installed: string, range: string | undefined): boolean;
2475
+
2476
+ /**
2477
+ * Describes the version information returned by a CLI server's discovery endpoint.
2478
+ */
2479
+ interface ServerVersionInfo {
2480
+ supportedVersions: number[];
2481
+ preferredVersion: number;
2482
+ serverVersion: string;
2483
+ }
2484
+ /**
2485
+ * Negotiates the API version between a frontend CLI client and a backend server.
2486
+ *
2487
+ * Flow:
2488
+ * 1. Client calls `discover(baseUrl)` which hits `GET ${VERSIONS_ENDPOINT}`
2489
+ * 2. Server returns supported versions
2490
+ * 3. Client picks the highest mutually supported version
2491
+ * 4. All subsequent calls use `/api/v{n}/qcli/*`
2492
+ */
2493
+ declare class ServerVersionNegotiator {
2494
+ private static readonly CLIENT_SUPPORTED_VERSIONS;
2495
+ /**
2496
+ * Given a server's version info, pick the highest mutually compatible version.
2497
+ * Returns null if no compatible version exists.
2498
+ */
2499
+ static negotiate(serverInfo: ServerVersionInfo): number | null;
2500
+ /**
2501
+ * Discover the server's supported versions and negotiate the best match.
2502
+ * Returns the negotiated API version and the base path for all subsequent calls,
2503
+ * or null if the server is unreachable or incompatible.
2504
+ */
2505
+ static discover(baseUrl: string): Promise<{
2506
+ apiVersion: number;
2507
+ basePath: string;
2508
+ } | null>;
2509
+ }
2510
+
2511
+ /**
2512
+ * Derives CLI panel CSS custom property values from an xterm ITheme object.
2513
+ * Used when `syncTheme` is enabled on the panel config.
2514
+ */
2515
+ interface ThemeLike {
2516
+ background?: string;
2517
+ foreground?: string;
2518
+ cursor?: string;
2519
+ cyan?: string;
2520
+ blue?: string;
2521
+ magenta?: string;
2522
+ selectionBackground?: string;
2523
+ }
2524
+ /**
2525
+ * Derive CSS custom properties for the CLI panel from the active xterm theme.
2526
+ * Returns a record of property name → value that can be applied as inline styles.
2527
+ */
2528
+ declare function derivePanelThemeStyles(theme: ThemeLike): Record<string, string>;
2529
+
2530
+ /**
2531
+ * Load the user's saved panel position from localStorage.
2532
+ * Returns null if no preference is saved or localStorage is unavailable.
2533
+ */
2534
+ declare function loadPanelPosition(): CliPanelPosition | null;
2535
+ /**
2536
+ * Save the user's panel position preference to localStorage.
2537
+ */
2538
+ declare function savePanelPosition(position: CliPanelPosition): void;
2539
+ /**
2540
+ * Get the next position in the cycle: bottom -> right -> top -> left -> bottom
2541
+ */
2542
+ declare function nextPanelPosition(current: CliPanelPosition): CliPanelPosition;
2543
+
2544
+ /**
2545
+ * Strip all ANSI escape sequences from a string.
2546
+ * @param text The text potentially containing ANSI codes
2547
+ * @returns The text with all ANSI codes removed
2548
+ */
2549
+ declare function stripAnsi(text: string): string;
2550
+ /**
2551
+ * Return the visible length of a string, ignoring ANSI escape codes.
2552
+ * Useful for padding/alignment calculations in terminal output.
2553
+ * @param text The text potentially containing ANSI codes
2554
+ * @returns The number of visible characters
2555
+ */
2556
+ declare function visibleLength(text: string): number;
2557
+
2558
+ /**
2559
+ * Retrieve a parameter's value from the parsed arguments, checking aliases.
2560
+ * @param p The parameter descriptor
2561
+ * @param args The parsed command arguments
2562
+ * @returns The matched value, or `undefined` if not found
2563
+ */
2564
+ declare const getParameterValue: (p: ICliCommandParameterDescriptor, args: Record<string, any>) => unknown;
2565
+ /**
2566
+ * Pretty-print a JSON value with ANSI color highlighting.
2567
+ * @param json The value to format
2568
+ * @returns A colorized, indented string suitable for terminal output
2569
+ */
2570
+ declare const formatJson: (json: any) => string;
2571
+ /**
2572
+ * Apply ANSI color codes to a JSON string using token-based scanning.
2573
+ * Handles keys, strings, numbers, booleans, null, and structural characters.
2574
+ * @param jsonString The raw JSON string to colorize
2575
+ * @returns The colorized string
2576
+ */
2577
+ declare const colorizeJson: (jsonString: string) => string;
2578
+ /**
2579
+ * Convert a key-value object to a URL query string. Arrays produce repeated keys.
2580
+ * @param params The parameters to encode
2581
+ * @returns The encoded query string (without leading `?`)
2582
+ */
2583
+ declare const toQueryString: (params: Record<string, any>) => string;
2584
+ /**
2585
+ * Highlight regex matches in text using an ANSI background color.
2586
+ * @param text The source text
2587
+ * @param pattern The regex pattern to highlight
2588
+ * @param bgColor The background color to apply (default: Yellow)
2589
+ * @returns The text with matching segments wrapped in ANSI background color codes
2590
+ */
2591
+ declare const highlightTextWithBg: (text: string, pattern: RegExp, bgColor?: CliBackgroundColor) => string;
2592
+ /**
2593
+ * Extract the substring to the right of a given word in a command string.
2594
+ * @param command The full command string
2595
+ * @param word The word to search for
2596
+ * @returns The trimmed text after the word, or `undefined` if not found
2597
+ */
2598
+ declare const getRightOfWord: (command: string, word: string) => string | undefined;
2599
+ /**
2600
+ * Apply a color function to the first word of a text string, preserving leading whitespace.
2601
+ * @param text The text to process
2602
+ * @param colorFunction A function that wraps a word in ANSI color codes
2603
+ * @returns The text with only the first word colorized
2604
+ */
2605
+ declare const colorFirstWord: (text: string, colorFunction: (word: string) => string) => string;
2606
+
2607
+ declare const utils: {
2608
+ getParameterValue: (p: ICliCommandParameterDescriptor, args: Record<string, any>) => unknown;
2609
+ formatJson: (json: any) => string;
2610
+ colorizeJson: (jsonString: string) => string;
2611
+ toQueryString: (params: Record<string, any>) => string;
2612
+ highlightTextWithBg: (text: string, pattern: RegExp, bgColor?: CliBackgroundColor) => string;
2613
+ getRightOfWord: (command: string, word: string) => string | undefined;
2614
+ colorFirstWord: (text: string, colorFunction: (word: string) => string) => string;
2615
+ ObjectDescriber: typeof ObjectDescriber;
2616
+ delay: (ms: number) => Promise<void>;
2617
+ getConfigValue: typeof getConfigValue;
2618
+ getPluginConfigValue: typeof getPluginConfigValue;
2619
+ resolveConfigurationCategories: typeof resolveConfigurationCategories;
2620
+ CLI_CONFIGURE_STORE_NAME: string;
2621
+ };
2622
+
2623
+ declare const DefaultLibraryAuthor: ICliCommandAuthor;
2624
+ declare const constants: {
2625
+ DefaultLibraryAuthor: ICliCommandAuthor;
2626
+ };
2627
+
2628
+ /** Error message used when a `CancellablePromise` is cancelled. */
2629
+ declare const CANCELLATION_ERROR_MESSAGE = "Promise cancelled";
2630
+ /**
2631
+ * A promise wrapper that supports cooperative cancellation.
2632
+ *
2633
+ * Create with an executor (like `new Promise`), then call `execute()` to run.
2634
+ * Call `cancel()` to reject with a cancellation error and prevent further
2635
+ * resolve/reject callbacks from firing.
2636
+ *
2637
+ * @example
2638
+ * ```ts
2639
+ * const cp = new CancellablePromise<string>((resolve) => {
2640
+ * setTimeout(() => resolve('done'), 5000);
2641
+ * });
2642
+ * cp.execute().catch(e => console.log(e.message)); // 'Promise cancelled'
2643
+ * cp.cancel();
2644
+ * ```
2645
+ */
2646
+ declare class CancellablePromise<T> {
2647
+ private executor;
2648
+ private hasCancelled;
2649
+ private abortController;
2650
+ constructor(executor: (resolve: (value: T) => void, reject: (reason?: any) => void) => void);
2651
+ /**
2652
+ * Run the executor and return a promise for its result.
2653
+ * If `cancel()` has been called, the promise rejects immediately.
2654
+ */
2655
+ execute(): Promise<T>;
2656
+ /**
2657
+ * Cancel the promise. The executing promise rejects with
2658
+ * `Error('Promise cancelled')` and subsequent resolve/reject calls are ignored.
2659
+ */
2660
+ cancel(): void;
2661
+ }
2662
+
2663
+ type CliTheme = ITheme;
2664
+ type DefaultThemesType = {
2665
+ default: CliTheme;
2666
+ classic: CliTheme;
2667
+ dracula: CliTheme;
2668
+ monokai: CliTheme;
2669
+ solarizedDark: CliTheme;
2670
+ solarizedLight: CliTheme;
2671
+ gruvboxDark: CliTheme;
2672
+ gruvboxLight: CliTheme;
2673
+ nord: CliTheme;
2674
+ oneDark: CliTheme;
2675
+ material: CliTheme;
2676
+ highContrastLight: CliTheme;
2677
+ tokyoNight: CliTheme;
2678
+ catppuccinMocha: CliTheme;
2679
+ catppuccinFrappe: CliTheme;
2680
+ rosePine: CliTheme;
2681
+ kanagawa: CliTheme;
2682
+ everforestDark: CliTheme;
2683
+ ayuDark: CliTheme;
2684
+ catppuccinLatte: CliTheme;
2685
+ rosePineDawn: CliTheme;
2686
+ everforestLight: CliTheme;
2687
+ githubLight: CliTheme;
2688
+ cyberpunk: CliTheme;
2689
+ retroGreen: CliTheme;
2690
+ retroAmber: CliTheme;
2691
+ matrix: CliTheme;
2692
+ synthwave: CliTheme;
2693
+ highContrastDark: CliTheme;
2694
+ yellow: CliTheme;
2695
+ [key: string]: CliTheme;
2696
+ };
2697
+
2698
+ declare const DefaultThemes: DefaultThemesType;
2699
+
2700
+ type CliThemeCategory = 'dark' | 'light';
2701
+ interface CliThemeInfo {
2702
+ theme: ITheme;
2703
+ category: CliThemeCategory;
2704
+ tags: string[];
2705
+ description: string;
2706
+ }
2707
+
2708
+ declare const DefaultThemeInfos: Record<string, CliThemeInfo>;
2709
+
2710
+ declare const LIBRARY_VERSION = "2.0.0-beta.10";
2711
+ declare const API_VERSION = 2;
2712
+
2713
+ /**
2714
+ * Context provided to worker service handlers inside a Web Worker.
2715
+ */
2716
+ interface WorkerServiceContext {
2717
+ /** Emit an event to the main thread */
2718
+ emit(event: Omit<ICliServiceEvent, 'timestamp'>): void;
2719
+ /** Log a message (forwarded to the main-thread log buffer) */
2720
+ log(message: string, level?: CliServiceLogLevel): void;
2721
+ /** Update state on the main thread */
2722
+ updateState(patch: Record<string, unknown>): void;
2723
+ /** Create an interval that is auto-cleared on stop */
2724
+ createInterval(callback: () => void, ms: number): ICliManagedInterval;
2725
+ /** Create a timeout that is auto-cleared on stop */
2726
+ createTimeout(callback: () => void, ms: number): ICliManagedTimer;
2727
+ /** AbortSignal scoped to this service */
2728
+ signal: AbortSignal;
2729
+ }
2730
+ /**
2731
+ * Lightweight helper for authoring worker-compatible background services.
2732
+ * Call this at the top level of your worker script.
2733
+ */
2734
+ declare function createWorkerService(handlers: {
2735
+ onStart(ctx: WorkerServiceContext): Promise<void>;
2736
+ onStop?(): Promise<void>;
2737
+ }): void;
2738
+
2739
+ /**
2740
+ * Browser-based file transfer service using native browser APIs.
2741
+ *
2742
+ * This is the default implementation when no virtual filesystem is available.
2743
+ * `readFile` and `uploadFromBrowser` open a file picker dialog.
2744
+ * `writeFile` and `downloadToBrowser` trigger a browser download.
2745
+ *
2746
+ * **Limitations:** `listFiles()` and `exists()` are not supported in the
2747
+ * browser environment and always return empty/false respectively.
2748
+ * Use `@qodalis/cli-files` for full filesystem capabilities.
2749
+ */
2750
+ declare class BrowserFileTransferService implements ICliFileTransferService {
2751
+ readFile(_path: string): Promise<string | null>;
2752
+ writeFile(path: string, content: string): Promise<void>;
2753
+ /**
2754
+ * Not supported in browser — always returns an empty array.
2755
+ * Use `@qodalis/cli-files` for directory listing.
2756
+ */
2757
+ listFiles(_path: string): Promise<ICliFileEntry[]>;
2758
+ /**
2759
+ * Not supported in browser — always returns `false`.
2760
+ * Use `@qodalis/cli-files` for file existence checks.
2761
+ */
2762
+ exists(_path: string): Promise<boolean>;
2763
+ downloadToBrowser(filename: string, content: string | Blob): void;
2764
+ uploadFromBrowser(accept?: string): Promise<{
2765
+ name: string;
2766
+ content: string;
2767
+ } | null>;
2768
+ private _pickFile;
2769
+ }
2770
+
2771
+ export { API_VERSION, BrowserFileTransferService, CANCELLATION_ERROR_MESSAGE, CLI_CONFIGURE_STORE_NAME, CancellablePromise, type CliAddUser, CliBackgroundColor, type CliBackgroundServiceStatus, type CliBackgroundServiceType, type CliDateOptions, type CliEngineSnapshot, type CliFactoryProvider, type CliFilePickerOptions, type CliFileResult, CliForegroundColor, type CliFullScreenOptions, CliIcon, type CliLineOptions, CliLogLevel, CliModuleRegistry, type CliMultiSelectOption, type CliMultiSelectOptions, type CliNumberOptions, type CliOptions, type CliPackageSource, type CliPanelConfig, type CliPanelHideAlignment, type CliPanelPosition, type CliPercentageProgressBarUpdateValueOptions, type CliProcessCommand, type CliProcessorMetadata, type CliProvider, type CliSelectOption, type CliSelectOptions, type CliServerCapabilities, type CliServerCommandDescriptor, type CliServerConfig, type CliServerOutput, type CliServerResponse, type CliServiceEventHandler, type CliServiceExecutionMode, type CliServiceLogLevel, type CliState, type CliStateConfiguration, type CliTableOptions, type CliTextAnimatorOptions, type CliTheme, type CliThemeCategory, type CliThemeInfo, type CliTypeProvider, type CliUpdateUser, type CliValueProvider, type CliWorkerInboundMessage, type CliWorkerOutboundMessage, DEFAULT_DIR_PERMISSIONS, DEFAULT_FILE_PERMISSIONS, DefaultLibraryAuthor, DefaultThemeInfos, DefaultThemes, type DefaultThemesType, type ICliAuthService, ICliAuthService_TOKEN, type ICliBackgroundService, type ICliBackgroundServiceInfo, type ICliBackgroundServiceRegistry, type ICliClipboard, type ICliCommandAuthor, type ICliCommandChildProcessor, type ICliCommandExecutorService, type ICliCommandParameterDescriptor, type ICliCommandProcessor, type ICliCommandProcessorRegistry, type ICliCompletionContext, type ICliCompletionProvider, ICliCompletionProvider_TOKEN, type ICliConfigurableModule, type ICliConfigurationOption, type ICliDragDropService, ICliDragDropService_TOKEN, type ICliExecutionContext, type ICliExecutionProcess, type ICliFileEntry, type ICliFilePickerProvider, ICliFilePickerProvider_TOKEN, type ICliFileTransferService, ICliFileTransferService_TOKEN, type ICliGlobalParameterHandler, type ICliGroup, type ICliGroupsStoreService, ICliGroupsStoreService_TOKEN, type ICliInputReader, type ICliKeyValueStore, type ICliLogger, type ICliManagedInterval, type ICliManagedTimer, type ICliModule, type ICliOwnership, type ICliPercentageProgressBar, type ICliPermissionService, ICliPermissionService_TOKEN, type ICliPingServerService, type ICliProcessEntry, type ICliProcessRegisterOptions, type ICliProcessRegistry, type ICliProcessorHook, type ICliProgressBar, type ICliServiceContext, type ICliServiceEvent, type ICliServiceLogEntry, type ICliServiceProvider, type ICliSpinner, type ICliStateStore, type ICliTerminalWriter, type ICliTextAnimator, type ICliTranslationService, ICliTranslationService_TOKEN, type ICliUmdModule, type ICliUser, type ICliUserCredentials, type ICliUserSession, type ICliUserSessionService, ICliUserSessionService_TOKEN, type ICliUsersStoreService, ICliUsersStoreService_TOKEN, type ISyntaxHighlightRule, type ISyntaxHighlighter, type ISyntaxTheme, LIBRARY_VERSION, type LineState, ObjectDescriber, type Package, type ServerVersionInfo, ServerVersionNegotiator, type WorkerServiceContext, bootCliModule, bootUmdModule, clearTerminalLine, colorFirstWord, colorizeJson, compareVersions, constants, createWorkerService, delay, derivePanelThemeStyles, enums, formatJson, getConfigValue, getParameterValue, getPluginConfigValue, getRightOfWord, highlightTextWithBg, initializeBrowserEnvironment, loadPanelPosition, nextPanelPosition, resolveConfigurationCategories, satisfiesMinVersion, satisfiesVersionRange, savePanelPosition, stripAnsi, toQueryString, utils, visibleLength };