lsh-framework 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +40 -3
  2. package/dist/cli.js +104 -486
  3. package/dist/commands/doctor.js +427 -0
  4. package/dist/commands/init.js +371 -0
  5. package/dist/constants/api.js +94 -0
  6. package/dist/constants/commands.js +64 -0
  7. package/dist/constants/config.js +56 -0
  8. package/dist/constants/database.js +21 -0
  9. package/dist/constants/errors.js +79 -0
  10. package/dist/constants/index.js +28 -0
  11. package/dist/constants/paths.js +28 -0
  12. package/dist/constants/ui.js +73 -0
  13. package/dist/constants/validation.js +124 -0
  14. package/dist/daemon/lshd.js +11 -32
  15. package/dist/lib/daemon-client-helper.js +7 -4
  16. package/dist/lib/daemon-client.js +9 -2
  17. package/dist/lib/format-utils.js +163 -0
  18. package/dist/lib/job-manager.js +2 -1
  19. package/dist/lib/platform-utils.js +211 -0
  20. package/dist/lib/secrets-manager.js +11 -1
  21. package/dist/lib/string-utils.js +128 -0
  22. package/dist/services/daemon/daemon-registrar.js +3 -2
  23. package/dist/services/secrets/secrets.js +54 -30
  24. package/package.json +10 -74
  25. package/dist/app.js +0 -33
  26. package/dist/cicd/analytics.js +0 -261
  27. package/dist/cicd/auth.js +0 -269
  28. package/dist/cicd/cache-manager.js +0 -172
  29. package/dist/cicd/data-retention.js +0 -305
  30. package/dist/cicd/performance-monitor.js +0 -224
  31. package/dist/cicd/webhook-receiver.js +0 -640
  32. package/dist/commands/api.js +0 -346
  33. package/dist/commands/theme.js +0 -261
  34. package/dist/commands/zsh-import.js +0 -240
  35. package/dist/components/App.js +0 -1
  36. package/dist/components/Divider.js +0 -29
  37. package/dist/components/REPL.js +0 -43
  38. package/dist/components/Terminal.js +0 -232
  39. package/dist/components/UserInput.js +0 -30
  40. package/dist/daemon/api-server.js +0 -316
  41. package/dist/daemon/monitoring-api.js +0 -220
  42. package/dist/lib/api-error-handler.js +0 -185
  43. package/dist/lib/associative-arrays.js +0 -285
  44. package/dist/lib/base-api-server.js +0 -290
  45. package/dist/lib/brace-expansion.js +0 -160
  46. package/dist/lib/builtin-commands.js +0 -439
  47. package/dist/lib/executors/builtin-executor.js +0 -52
  48. package/dist/lib/extended-globbing.js +0 -411
  49. package/dist/lib/extended-parameter-expansion.js +0 -227
  50. package/dist/lib/interactive-shell.js +0 -460
  51. package/dist/lib/job-builtins.js +0 -582
  52. package/dist/lib/pathname-expansion.js +0 -216
  53. package/dist/lib/script-runner.js +0 -226
  54. package/dist/lib/shell-executor.js +0 -2504
  55. package/dist/lib/shell-parser.js +0 -958
  56. package/dist/lib/shell-types.js +0 -6
  57. package/dist/lib/shell.lib.js +0 -40
  58. package/dist/lib/theme-manager.js +0 -476
  59. package/dist/lib/variable-expansion.js +0 -385
  60. package/dist/lib/zsh-compatibility.js +0 -659
  61. package/dist/lib/zsh-import-manager.js +0 -707
  62. package/dist/lib/zsh-options.js +0 -328
  63. package/dist/pipeline/job-tracker.js +0 -491
  64. package/dist/pipeline/mcli-bridge.js +0 -309
  65. package/dist/pipeline/pipeline-service.js +0 -1119
  66. package/dist/pipeline/workflow-engine.js +0 -870
  67. package/dist/services/api/api.js +0 -58
  68. package/dist/services/api/auth.js +0 -35
  69. package/dist/services/api/config.js +0 -7
  70. package/dist/services/api/file.js +0 -22
  71. package/dist/services/shell/shell.js +0 -28
  72. package/dist/services/zapier.js +0 -16
  73. package/dist/simple-api-server.js +0 -148
@@ -1,460 +0,0 @@
1
- /**
2
- * Interactive Shell Implementation
3
- * Provides ZSH-like interactive shell experience
4
- */
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import * as os from 'os';
8
- import { ShellExecutor } from './shell-executor.js';
9
- import { parseShellCommand } from './shell-parser.js';
10
- export class InteractiveShell {
11
- executor;
12
- options;
13
- isRunning = false;
14
- currentLine = '';
15
- cursorPosition = 0;
16
- historyIndex = -1;
17
- completionIndex = -1;
18
- currentCompletions = [];
19
- constructor(options = {}) {
20
- this.options = {
21
- prompt: '%n@%m:%~$ ',
22
- rprompt: '%T',
23
- historyFile: path.join(os.homedir(), '.lsh_history'),
24
- rcFile: path.join(os.homedir(), '.lshrc'),
25
- verbose: false,
26
- debug: false,
27
- ...options,
28
- };
29
- this.executor = new ShellExecutor();
30
- this.setupShell();
31
- }
32
- /**
33
- * Start interactive shell
34
- */
35
- async start() {
36
- this.isRunning = true;
37
- // Load configuration
38
- await this.loadConfiguration();
39
- // Show welcome message
40
- this.showWelcome();
41
- // Main interactive loop
42
- await this.interactiveLoop();
43
- }
44
- /**
45
- * Stop interactive shell
46
- */
47
- stop() {
48
- this.isRunning = false;
49
- // Restore terminal to normal mode
50
- if (process.stdin.isTTY && process.stdin.setRawMode) {
51
- process.stdin.setRawMode(false);
52
- process.stdin.pause();
53
- process.stdin.removeAllListeners('data');
54
- }
55
- // Write newline and goodbye message
56
- process.stdout.write('\nGoodbye!\n');
57
- // Give terminal time to restore before exiting
58
- setImmediate(() => {
59
- process.exit(0);
60
- });
61
- }
62
- /**
63
- * Setup shell environment
64
- */
65
- setupShell() {
66
- // Set up terminal for raw input
67
- if (process.stdin.isTTY) {
68
- process.stdin.setRawMode(true);
69
- process.stdin.resume();
70
- process.stdin.setEncoding('utf8');
71
- }
72
- // Handle process signals
73
- process.on('SIGINT', () => {
74
- this.handleSigInt();
75
- });
76
- process.on('SIGTERM', () => {
77
- this.stop();
78
- });
79
- // Set up completion system
80
- this.setupCompletion();
81
- }
82
- /**
83
- * Load shell configuration from .lshrc
84
- */
85
- async loadConfiguration() {
86
- const rcFile = this.options.rcFile;
87
- if (fs.existsSync(rcFile)) {
88
- try {
89
- const rcContent = fs.readFileSync(rcFile, 'utf8');
90
- await this.executeConfiguration(rcContent);
91
- if (this.options.verbose) {
92
- console.log(`Loaded configuration from ${rcFile}`);
93
- }
94
- }
95
- catch (error) {
96
- console.error(`Error loading ${rcFile}: ${error.message}`);
97
- }
98
- }
99
- else {
100
- // Create default .lshrc if it doesn't exist
101
- this.createDefaultRcFile(rcFile);
102
- }
103
- }
104
- /**
105
- * Execute configuration commands
106
- */
107
- async executeConfiguration(config) {
108
- const lines = config.split('\n');
109
- for (const line of lines) {
110
- const trimmed = line.trim();
111
- // Skip comments and empty lines
112
- if (trimmed.startsWith('#') || trimmed === '') {
113
- continue;
114
- }
115
- try {
116
- const ast = parseShellCommand(trimmed);
117
- await this.executor.execute(ast);
118
- }
119
- catch (error) {
120
- if (this.options.debug) {
121
- console.error(`Config error: ${error.message}`);
122
- }
123
- }
124
- }
125
- }
126
- /**
127
- * Create default .lshrc file
128
- */
129
- createDefaultRcFile(rcFile) {
130
- const defaultConfig = `# LSH Configuration File
131
- # This file is executed when LSH starts in interactive mode
132
-
133
- # Enable ZSH features
134
- setopt EXTENDED_GLOB
135
- setopt AUTO_CD
136
- setopt SHARE_HISTORY
137
- setopt HIST_IGNORE_DUPS
138
-
139
- # Set prompt
140
- export PROMPT='%n@%m:%~$ '
141
- export RPROMPT='%T'
142
-
143
- # Set history options
144
- export HISTSIZE=10000
145
- export HISTFILE=~/.lsh_history
146
-
147
- # Aliases
148
- alias ll='ls -la'
149
- alias la='ls -A'
150
- alias l='ls -CF'
151
- alias ..='cd ..'
152
- alias ...='cd ../..'
153
-
154
- # Functions
155
- greet() {
156
- echo "Hello from LSH!"
157
- }
158
-
159
- # Welcome message
160
- echo "LSH interactive shell loaded. Type 'help' for commands."
161
- `;
162
- try {
163
- fs.writeFileSync(rcFile, defaultConfig, 'utf8');
164
- if (this.options.verbose) {
165
- console.log(`Created default configuration: ${rcFile}`);
166
- }
167
- }
168
- catch (error) {
169
- console.error(`Failed to create ${rcFile}: ${error.message}`);
170
- }
171
- }
172
- /**
173
- * Show welcome message
174
- */
175
- showWelcome() {
176
- console.log('🐚 LSH Interactive Shell');
177
- console.log('========================');
178
- console.log('Type "help" for available commands');
179
- console.log('Type "exit" or press Ctrl+D to quit');
180
- console.log('');
181
- }
182
- /**
183
- * Main interactive loop
184
- */
185
- async interactiveLoop() {
186
- while (this.isRunning) {
187
- try {
188
- // Show prompt
189
- const prompt = this.getPrompt();
190
- process.stdout.write(prompt);
191
- // Read input
192
- const input = await this.readLine();
193
- if (input === null) {
194
- // EOF (Ctrl+D)
195
- this.stop();
196
- break;
197
- }
198
- if (input.trim() === '') {
199
- continue;
200
- }
201
- // Add to history
202
- this.executor.addToHistory(input);
203
- // Execute command
204
- await this.executeCommand(input);
205
- }
206
- catch (error) {
207
- console.error(`Shell error: ${error.message}`);
208
- }
209
- }
210
- }
211
- /**
212
- * Read a line from stdin
213
- */
214
- readLine() {
215
- return new Promise((resolve) => {
216
- let input = '';
217
- const onData = (data) => {
218
- const char = data;
219
- switch (char) {
220
- case '\r':
221
- case '\n':
222
- process.stdin.removeListener('data', onData);
223
- resolve(input);
224
- break;
225
- case '\u0003': // Ctrl+C
226
- process.stdin.removeListener('data', onData);
227
- console.log('^C');
228
- resolve('');
229
- break;
230
- case '\u0004': // Ctrl+D (EOF)
231
- process.stdin.removeListener('data', onData);
232
- console.log(''); // Add newline
233
- resolve(null);
234
- break;
235
- case '\u007f': // Backspace
236
- if (input.length > 0) {
237
- input = input.slice(0, -1);
238
- process.stdout.write('\b \b');
239
- }
240
- break;
241
- case '\t': // Tab completion
242
- this.handleTabCompletion(input);
243
- break;
244
- case '\u001b[A': // Up arrow - history
245
- this.handleHistoryUp();
246
- break;
247
- case '\u001b[B': // Down arrow - history
248
- this.handleHistoryDown();
249
- break;
250
- default:
251
- if (char >= ' ') {
252
- input += char;
253
- process.stdout.write(char);
254
- }
255
- break;
256
- }
257
- };
258
- process.stdin.on('data', onData);
259
- });
260
- }
261
- /**
262
- * Handle tab completion
263
- */
264
- async handleTabCompletion(input) {
265
- try {
266
- const completions = await this.executor.getCompletions('command', // This would be parsed from input
267
- [], input, 0);
268
- if (completions.length > 0) {
269
- this.currentCompletions = completions;
270
- this.completionIndex = 0;
271
- // Show first completion
272
- const completion = completions[0];
273
- const remaining = completion.substring(input.length);
274
- process.stdout.write(remaining);
275
- input += remaining;
276
- }
277
- }
278
- catch (_error) {
279
- // Ignore completion errors
280
- }
281
- }
282
- /**
283
- * Handle history up
284
- */
285
- handleHistoryUp() {
286
- const history = this.executor.getHistoryEntries();
287
- if (history.length > 0 && this.historyIndex < history.length - 1) {
288
- this.historyIndex++;
289
- const entry = history[history.length - 1 - this.historyIndex];
290
- // Clear current line
291
- process.stdout.write('\r' + ' '.repeat(process.stdout.columns) + '\r');
292
- // Show history entry
293
- this.currentLine = entry.command;
294
- process.stdout.write(this.getPrompt() + this.currentLine);
295
- }
296
- }
297
- /**
298
- * Handle history down
299
- */
300
- handleHistoryDown() {
301
- if (this.historyIndex > 0) {
302
- this.historyIndex--;
303
- const history = this.executor.getHistoryEntries();
304
- const entry = history[history.length - 1 - this.historyIndex];
305
- // Clear current line
306
- process.stdout.write('\r' + ' '.repeat(process.stdout.columns) + '\r');
307
- // Show history entry
308
- this.currentLine = entry.command;
309
- process.stdout.write(this.getPrompt() + this.currentLine);
310
- }
311
- else if (this.historyIndex === 0) {
312
- this.historyIndex = -1;
313
- // Clear current line
314
- process.stdout.write('\r' + ' '.repeat(process.stdout.columns) + '\r');
315
- // Show empty line
316
- this.currentLine = '';
317
- process.stdout.write(this.getPrompt());
318
- }
319
- }
320
- /**
321
- * Handle SIGINT (Ctrl+C)
322
- */
323
- handleSigInt() {
324
- console.log('\n^C');
325
- this.currentLine = '';
326
- this.historyIndex = -1;
327
- this.completionIndex = -1;
328
- this.currentCompletions = [];
329
- }
330
- /**
331
- * Execute a command
332
- */
333
- async executeCommand(command) {
334
- try {
335
- // Handle special commands
336
- if (command.trim() === 'exit' || command.trim() === 'quit') {
337
- this.stop();
338
- return;
339
- }
340
- if (command.trim() === 'help') {
341
- this.showHelp();
342
- return;
343
- }
344
- if (command.trim() === 'clear') {
345
- console.clear();
346
- return;
347
- }
348
- if (command.trim() === 'history') {
349
- this.showHistory();
350
- return;
351
- }
352
- // Parse and execute command
353
- const ast = parseShellCommand(command);
354
- const result = await this.executor.execute(ast);
355
- // Display output
356
- if (result.stdout) {
357
- console.log(result.stdout);
358
- }
359
- if (result.stderr) {
360
- console.error(result.stderr);
361
- }
362
- // Update history with exit code
363
- this.executor.addToHistory(command, result.exitCode);
364
- }
365
- catch (error) {
366
- console.error(`Command error: ${error.message}`);
367
- }
368
- }
369
- /**
370
- * Get current prompt
371
- */
372
- getPrompt() {
373
- return this.executor.getPrompt();
374
- }
375
- /**
376
- * Show help information
377
- */
378
- showHelp() {
379
- console.log('LSH Interactive Shell Help');
380
- console.log('==========================');
381
- console.log('');
382
- console.log('Shell Commands:');
383
- console.log(' help - Show this help');
384
- console.log(' exit - Exit the shell');
385
- console.log(' clear - Clear the screen');
386
- console.log(' history - Show command history');
387
- console.log('');
388
- console.log('CLI Commands (exit shell first):');
389
- console.log(' lsh repl - JavaScript REPL (Node.js interactive)');
390
- console.log(' lsh self update - Update LSH to latest version');
391
- console.log(' lsh self version - Show version information');
392
- console.log(' lsh self info - Show installation info');
393
- console.log('');
394
- console.log(' lsh daemon start - Start LSH daemon');
395
- console.log(' lsh daemon stop - Stop LSH daemon');
396
- console.log(' lsh daemon status - Check daemon status');
397
- console.log(' lsh daemon restart - Restart daemon');
398
- console.log('');
399
- console.log(' lsh daemon job list - List all jobs');
400
- console.log(' lsh daemon job create - Create new job');
401
- console.log(' lsh daemon job trigger - Run job immediately');
402
- console.log(' lsh daemon job delete - Delete a job');
403
- console.log('');
404
- console.log(' lsh cron reports - View cron job reports');
405
- console.log(' lsh cron list - List all cron jobs');
406
- console.log('');
407
- console.log(' lsh api start - Start API server');
408
- console.log(' lsh api stop - Stop API server');
409
- console.log(' lsh api key - Generate API key');
410
- console.log(' lsh api test - Test API connection');
411
- console.log('');
412
- console.log(' lsh config --init - Initialize config file');
413
- console.log(' lsh config --show - Show current config');
414
- console.log('');
415
- console.log('Key Bindings:');
416
- console.log(' Tab - Command completion');
417
- console.log(' Up/Down - Command history');
418
- console.log(' Ctrl+C - Interrupt current command');
419
- console.log(' Ctrl+D - Exit shell');
420
- console.log('');
421
- console.log('Features:');
422
- console.log(' - Full POSIX shell compatibility');
423
- console.log(' - ZSH-style features (arrays, globbing, etc.)');
424
- console.log(' - Advanced job management');
425
- console.log(' - Command history and completion');
426
- console.log(' - Configuration via ~/.lshrc');
427
- console.log('');
428
- console.log('For complete documentation: lsh --help');
429
- console.log('');
430
- }
431
- /**
432
- * Show command history
433
- */
434
- showHistory() {
435
- const history = this.executor.getHistoryEntries();
436
- if (history.length === 0) {
437
- console.log('No command history');
438
- return;
439
- }
440
- console.log('Command History:');
441
- console.log('================');
442
- history.forEach((entry, index) => {
443
- const timestamp = new Date(entry.timestamp).toLocaleString();
444
- const exitCode = entry.exitCode !== undefined ? ` [${entry.exitCode}]` : '';
445
- console.log(`${index + 1} ${entry.command}${exitCode}`);
446
- if (this.options.verbose) {
447
- console.log(` ${timestamp}`);
448
- }
449
- });
450
- console.log('');
451
- }
452
- /**
453
- * Setup completion system
454
- */
455
- setupCompletion() {
456
- // Completion is already set up in the executor
457
- // This method can be extended for additional completion setup
458
- }
459
- }
460
- export default InteractiveShell;