lsh-framework 0.5.4

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 (90) hide show
  1. package/.env.example +51 -0
  2. package/README.md +399 -0
  3. package/dist/app.js +33 -0
  4. package/dist/cicd/analytics.js +261 -0
  5. package/dist/cicd/auth.js +269 -0
  6. package/dist/cicd/cache-manager.js +172 -0
  7. package/dist/cicd/data-retention.js +305 -0
  8. package/dist/cicd/performance-monitor.js +224 -0
  9. package/dist/cicd/webhook-receiver.js +634 -0
  10. package/dist/cli.js +500 -0
  11. package/dist/commands/api.js +343 -0
  12. package/dist/commands/self.js +318 -0
  13. package/dist/commands/theme.js +257 -0
  14. package/dist/commands/zsh-import.js +240 -0
  15. package/dist/components/App.js +1 -0
  16. package/dist/components/Divider.js +29 -0
  17. package/dist/components/REPL.js +43 -0
  18. package/dist/components/Terminal.js +232 -0
  19. package/dist/components/UserInput.js +30 -0
  20. package/dist/daemon/api-server.js +315 -0
  21. package/dist/daemon/job-registry.js +554 -0
  22. package/dist/daemon/lshd.js +822 -0
  23. package/dist/daemon/monitoring-api.js +220 -0
  24. package/dist/examples/supabase-integration.js +106 -0
  25. package/dist/lib/api-error-handler.js +183 -0
  26. package/dist/lib/associative-arrays.js +285 -0
  27. package/dist/lib/base-api-server.js +290 -0
  28. package/dist/lib/base-command-registrar.js +286 -0
  29. package/dist/lib/base-job-manager.js +293 -0
  30. package/dist/lib/brace-expansion.js +160 -0
  31. package/dist/lib/builtin-commands.js +439 -0
  32. package/dist/lib/cloud-config-manager.js +347 -0
  33. package/dist/lib/command-validator.js +190 -0
  34. package/dist/lib/completion-system.js +344 -0
  35. package/dist/lib/cron-job-manager.js +364 -0
  36. package/dist/lib/daemon-client-helper.js +141 -0
  37. package/dist/lib/daemon-client.js +501 -0
  38. package/dist/lib/database-persistence.js +638 -0
  39. package/dist/lib/database-schema.js +259 -0
  40. package/dist/lib/enhanced-history-system.js +246 -0
  41. package/dist/lib/env-validator.js +265 -0
  42. package/dist/lib/executors/builtin-executor.js +52 -0
  43. package/dist/lib/extended-globbing.js +411 -0
  44. package/dist/lib/extended-parameter-expansion.js +227 -0
  45. package/dist/lib/floating-point-arithmetic.js +256 -0
  46. package/dist/lib/history-system.js +245 -0
  47. package/dist/lib/interactive-shell.js +460 -0
  48. package/dist/lib/job-builtins.js +580 -0
  49. package/dist/lib/job-manager.js +386 -0
  50. package/dist/lib/job-storage-database.js +156 -0
  51. package/dist/lib/job-storage-memory.js +73 -0
  52. package/dist/lib/logger.js +274 -0
  53. package/dist/lib/lshrc-init.js +177 -0
  54. package/dist/lib/pathname-expansion.js +216 -0
  55. package/dist/lib/prompt-system.js +328 -0
  56. package/dist/lib/script-runner.js +226 -0
  57. package/dist/lib/secrets-manager.js +193 -0
  58. package/dist/lib/shell-executor.js +2504 -0
  59. package/dist/lib/shell-parser.js +958 -0
  60. package/dist/lib/shell-types.js +6 -0
  61. package/dist/lib/shell.lib.js +40 -0
  62. package/dist/lib/supabase-client.js +58 -0
  63. package/dist/lib/theme-manager.js +476 -0
  64. package/dist/lib/variable-expansion.js +385 -0
  65. package/dist/lib/zsh-compatibility.js +658 -0
  66. package/dist/lib/zsh-import-manager.js +699 -0
  67. package/dist/lib/zsh-options.js +328 -0
  68. package/dist/pipeline/job-tracker.js +491 -0
  69. package/dist/pipeline/mcli-bridge.js +302 -0
  70. package/dist/pipeline/pipeline-service.js +1116 -0
  71. package/dist/pipeline/workflow-engine.js +867 -0
  72. package/dist/services/api/api.js +58 -0
  73. package/dist/services/api/auth.js +35 -0
  74. package/dist/services/api/config.js +7 -0
  75. package/dist/services/api/file.js +22 -0
  76. package/dist/services/cron/cron-registrar.js +235 -0
  77. package/dist/services/cron/cron.js +9 -0
  78. package/dist/services/daemon/daemon-registrar.js +565 -0
  79. package/dist/services/daemon/daemon.js +9 -0
  80. package/dist/services/lib/lib.js +86 -0
  81. package/dist/services/log-file-extractor.js +170 -0
  82. package/dist/services/secrets/secrets.js +94 -0
  83. package/dist/services/shell/shell.js +28 -0
  84. package/dist/services/supabase/supabase-registrar.js +367 -0
  85. package/dist/services/supabase/supabase.js +9 -0
  86. package/dist/services/zapier.js +16 -0
  87. package/dist/simple-api-server.js +148 -0
  88. package/dist/store/store.js +31 -0
  89. package/dist/util/lib.util.js +11 -0
  90. package/package.json +144 -0
package/.env.example ADDED
@@ -0,0 +1,51 @@
1
+ # LSH Shell - Environment Configuration
2
+ # Copy this file to .env and update with your actual values
3
+
4
+ # Core Configuration
5
+ USER=your_username
6
+ HOME=/home/your_username
7
+ HOSTNAME=localhost
8
+ NODE_ENV=development
9
+
10
+ # Daemon & API Configuration
11
+ LSH_API_ENABLED=false
12
+ LSH_API_PORT=3030
13
+ LSH_API_KEY=
14
+ LSH_JWT_SECRET=
15
+ LSH_ENABLE_WEBHOOKS=false
16
+ WEBHOOK_PORT=3033
17
+ MONITORING_API_PORT=3031
18
+
19
+ # Command Security
20
+ # WARNING: Only enable if you fully trust all job sources
21
+ LSH_ALLOW_DANGEROUS_COMMANDS=false
22
+
23
+ # Webhook Secrets (REQUIRED in production if webhooks enabled)
24
+ GITHUB_WEBHOOK_SECRET=
25
+ GITLAB_WEBHOOK_SECRET=
26
+ JENKINS_WEBHOOK_SECRET=
27
+
28
+ # Database Configuration
29
+ DATABASE_URL=postgresql://localhost:5432/cicd
30
+
31
+ # Supabase (Optional)
32
+ SUPABASE_URL=
33
+ SUPABASE_ANON_KEY=
34
+
35
+ # Redis (Optional)
36
+ REDIS_URL=redis://localhost:6379
37
+
38
+ # MCLI Integration
39
+ MCLI_URL=http://localhost:8000
40
+ MCLI_API_KEY=
41
+
42
+ # Data Archival (Optional)
43
+ ENABLE_ARCHIVE=false
44
+ ARCHIVE_S3_BUCKET=
45
+ ARCHIVE_LOCAL_PATH=/var/backups/cicd
46
+
47
+ # Security Notes:
48
+ # - Generate secrets: openssl rand -hex 32
49
+ # - Never commit .env file
50
+ # - Webhook secrets mandatory in production
51
+ # - Rotate keys regularly
package/README.md ADDED
@@ -0,0 +1,399 @@
1
+ # LSH - Enhanced Shell with Job Management
2
+
3
+ `lsh` is an extensible CLI shell with advanced job management, CI/CD integration, and persistent daemon for reliable job execution. Built with TypeScript, it provides POSIX-compatible shell features with modern enhancements for automation and pipeline orchestration.
4
+
5
+ ## Features
6
+
7
+ ### Core Shell Features
8
+ - **POSIX Shell Compatibility** - Standard shell syntax and builtins
9
+ - **ZSH-Compatible Features** - Extended globbing, parameter expansion, associative arrays
10
+ - **Interactive Terminal UI** - Built with React/Ink for rich terminal experiences
11
+ - **Command History** - Persistent history with search and replay
12
+ - **Tab Completion** - Intelligent completion system
13
+
14
+ ### Job Management
15
+ - **Persistent Job Daemon** - Background daemon for reliable job execution
16
+ - **Cron-Style Scheduling** - Schedule jobs with cron expressions
17
+ - **Job Control** - Start, stop, monitor, and manage background jobs
18
+ - **Job Registry** - Centralized job tracking and persistence
19
+
20
+ ### CI/CD Integration
21
+ - **Webhook Receiver** - GitHub, GitLab, and Jenkins webhook support
22
+ - **Pipeline Orchestration** - Workflow engine for complex pipelines
23
+ - **Build Analytics** - Track build metrics and performance
24
+ - **Cache Management** - Intelligent caching for faster builds
25
+
26
+ ### Security
27
+ - **Command Validation** - Prevents command injection attacks
28
+ - **Environment Variable Validation** - Validates configuration at startup
29
+ - **Webhook Signature Verification** - HMAC verification for webhooks
30
+ - **Secure Defaults** - Fail-safe configuration in production
31
+
32
+ ### API & Integration
33
+ - **RESTful API** - HTTP API for job control and monitoring
34
+ - **JWT Authentication** - Secure API access with token-based auth
35
+ - **ML Pipeline Support** - Integration with machine learning workflows
36
+ - **Database Persistence** - PostgreSQL/Supabase for data storage
37
+
38
+ ## Installation
39
+
40
+ ### Prerequisites
41
+ - Node.js 18.0.0 or higher
42
+ - npm 8.0.0 or higher
43
+ - PostgreSQL (optional, for persistence features)
44
+ - Redis (optional, for caching)
45
+
46
+ ### Quick Start
47
+
48
+ **Install from npm:**
49
+
50
+ ```bash
51
+ npm install -g gwicho38-lsh
52
+ ```
53
+
54
+ **Verify installation:**
55
+
56
+ ```bash
57
+ lsh --version
58
+ lsh self version
59
+ ```
60
+
61
+ For detailed installation options, see [INSTALL.md](INSTALL.md).
62
+
63
+ ### From Source
64
+
65
+ ```bash
66
+ # Clone the repository
67
+ git clone https://github.com/gwicho38/lsh.git
68
+ cd lsh
69
+
70
+ # Install dependencies
71
+ npm install
72
+
73
+ # Build TypeScript
74
+ npm run build
75
+
76
+ # Link globally (optional)
77
+ npm link
78
+
79
+ # Run
80
+ lsh
81
+ ```
82
+
83
+ ## Quick Start
84
+
85
+ ### Interactive Shell
86
+
87
+ ```bash
88
+ # Start interactive shell
89
+ lsh
90
+
91
+ # Execute commands
92
+ lsh> ls -la
93
+ lsh> echo "Hello, LSH!"
94
+ lsh> cd /tmp && pwd
95
+ ```
96
+
97
+ ### Daemon Mode
98
+
99
+ ```bash
100
+ # Start the persistent daemon
101
+ lsh daemon start
102
+
103
+ # Check daemon status
104
+ lsh daemon status
105
+
106
+ # Stop the daemon
107
+ lsh daemon stop
108
+ ```
109
+
110
+ ### Job Management
111
+
112
+ ```bash
113
+ # Add a scheduled job (runs every day at midnight)
114
+ lsh cron add --name "daily-backup" --schedule "0 0 * * *" --command "backup.sh"
115
+
116
+ # List all jobs
117
+ lsh cron list
118
+
119
+ # Trigger a job manually
120
+ lsh cron trigger daily-backup
121
+
122
+ # Remove a job
123
+ lsh cron remove daily-backup
124
+ ```
125
+
126
+ ### API Server
127
+
128
+ ```bash
129
+ # Start API server
130
+ lsh api start --port 3030
131
+
132
+ # With authentication
133
+ LSH_API_KEY=your_secret_key lsh api start
134
+ ```
135
+
136
+ ## Configuration
137
+
138
+ ### Environment Variables
139
+
140
+ Copy `.env.example` to `.env` and configure:
141
+
142
+ ```bash
143
+ # Core Configuration
144
+ NODE_ENV=development # Environment mode
145
+ LSH_API_ENABLED=true # Enable API server
146
+ LSH_API_PORT=3030 # API server port
147
+
148
+ # Security (REQUIRED in production)
149
+ LSH_API_KEY=<generate-32-char-key> # API authentication key
150
+ LSH_JWT_SECRET=<generate-32-char-secret> # JWT signing secret
151
+ LSH_ALLOW_DANGEROUS_COMMANDS=false # Allow risky commands (use with caution)
152
+
153
+ # Webhooks
154
+ LSH_ENABLE_WEBHOOKS=true # Enable webhook receiver
155
+ WEBHOOK_PORT=3033 # Webhook receiver port
156
+ GITHUB_WEBHOOK_SECRET=<your-secret> # GitHub webhook secret
157
+ GITLAB_WEBHOOK_SECRET=<your-secret> # GitLab webhook secret
158
+ JENKINS_WEBHOOK_SECRET=<your-secret> # Jenkins webhook secret
159
+
160
+ # Database (Optional)
161
+ DATABASE_URL=postgresql://localhost:5432/cicd
162
+ SUPABASE_URL=https://your-project.supabase.co
163
+ SUPABASE_ANON_KEY=<your-anon-key>
164
+
165
+ # Caching (Optional)
166
+ REDIS_URL=redis://localhost:6379
167
+
168
+ # Monitoring
169
+ MONITORING_API_PORT=3031 # Monitoring API port
170
+ ```
171
+
172
+ ### Security Best Practices
173
+
174
+ **🔒 Production Deployment:**
175
+
176
+ 1. **Always set secrets** - API keys and JWT secrets are mandatory in production
177
+ 2. **Generate strong keys** - Use `openssl rand -hex 32` for secrets
178
+ 3. **Enable webhook verification** - Set webhook secrets when using webhooks
179
+ 4. **Review dangerous commands** - Keep `LSH_ALLOW_DANGEROUS_COMMANDS=false`
180
+ 5. **Use environment variables** - Never commit `.env` to version control
181
+
182
+ **Environment Validation:**
183
+
184
+ LSH validates environment variables at startup and fails fast in production if:
185
+ - Required secrets are missing or too short
186
+ - Invalid URL formats
187
+ - Dangerous commands enabled in production
188
+
189
+ ## Development
190
+
191
+ ### Building
192
+
193
+ ```bash
194
+ # Build TypeScript
195
+ npm run build
196
+
197
+ # Watch mode for development
198
+ npm run watch
199
+
200
+ # Type checking only
201
+ npm run typecheck
202
+ ```
203
+
204
+ ### Testing
205
+
206
+ ```bash
207
+ # Run all tests
208
+ npm test
209
+
210
+ # Run tests with coverage
211
+ npm run test:coverage
212
+
213
+ # Run integration tests
214
+ npm run test:integration
215
+
216
+ # Lint code
217
+ npm run lint
218
+
219
+ # Auto-fix lint issues
220
+ npm run lint:fix
221
+ ```
222
+
223
+ **Current Test Coverage:** ~1.5% (baseline established, actively improving)
224
+
225
+ **Well-tested modules:**
226
+ - `command-validator.ts` - 100% coverage
227
+ - `env-validator.ts` - 74% coverage
228
+
229
+ ### Electron App
230
+
231
+ ```bash
232
+ # Run as desktop application
233
+ npm run electron
234
+
235
+ # Development mode
236
+ npm run electron-dev
237
+
238
+ # Access dashboards
239
+ npm run dashboard
240
+ ```
241
+
242
+ ## Architecture
243
+
244
+ ### Core Components
245
+
246
+ - **`src/lib/shell-executor.ts`** - Main shell command executor
247
+ - **`src/lib/job-manager.ts`** - Job lifecycle management
248
+ - **`src/daemon/lshd.ts`** - Persistent background daemon
249
+ - **`src/daemon/api-server.ts`** - RESTful API server
250
+ - **`src/cicd/webhook-receiver.ts`** - CI/CD webhook integration
251
+
252
+ ### Data Flow
253
+
254
+ ```
255
+ User Command → Parser → AST → Executor → Output
256
+
257
+ Job Manager
258
+
259
+ Daemon (persistent)
260
+
261
+ Database/Redis
262
+ ```
263
+
264
+ ### Security Architecture
265
+
266
+ ```
267
+ API Request → JWT Validation → Command Validation → Execution
268
+ Webhook → HMAC Verification → Event Processing → Job Trigger
269
+ Daemon Startup → Env Validation → Fail Fast if Invalid
270
+ ```
271
+
272
+ ## API Reference
273
+
274
+ ### Authentication
275
+
276
+ ```bash
277
+ # Include API key in header
278
+ curl -H "X-API-Key: your_api_key" http://localhost:3030/api/status
279
+ ```
280
+
281
+ ### Endpoints
282
+
283
+ **Job Management:**
284
+ - `GET /api/jobs` - List all jobs
285
+ - `POST /api/jobs` - Create a new job
286
+ - `GET /api/jobs/:id` - Get job details
287
+ - `POST /api/jobs/:id/trigger` - Trigger job execution
288
+ - `DELETE /api/jobs/:id` - Remove a job
289
+
290
+ **Daemon Control:**
291
+ - `GET /api/status` - Daemon status
292
+ - `GET /api/metrics` - System metrics
293
+
294
+ **Webhooks:**
295
+ - `POST /webhooks/github` - GitHub webhook endpoint
296
+ - `POST /webhooks/gitlab` - GitLab webhook endpoint
297
+ - `POST /webhooks/jenkins` - Jenkins webhook endpoint
298
+
299
+ ## Troubleshooting
300
+
301
+ ### Common Issues
302
+
303
+ **Daemon won't start:**
304
+ ```bash
305
+ # Check if already running
306
+ ps aux | grep lshd
307
+
308
+ # Check PID file
309
+ cat /tmp/lsh-job-daemon-$USER.pid
310
+
311
+ # Remove stale PID file
312
+ rm /tmp/lsh-job-daemon-$USER.pid
313
+ ```
314
+
315
+ **Tests failing:**
316
+ ```bash
317
+ # Clear Jest cache
318
+ npm test -- --clearCache
319
+
320
+ # Check Node version
321
+ node --version # Should be 18+
322
+ ```
323
+
324
+ **Environment validation errors:**
325
+ ```bash
326
+ # Check your .env file matches .env.example
327
+ cp .env.example .env
328
+ # Edit .env with your values
329
+
330
+ # Generate secrets
331
+ openssl rand -hex 32
332
+ ```
333
+
334
+ **Lint errors:**
335
+ ```bash
336
+ # Auto-fix what's possible
337
+ npm run lint:fix
338
+
339
+ # Check specific file
340
+ npx eslint src/your-file.ts
341
+ ```
342
+
343
+ ## Contributing
344
+
345
+ Contributions are welcome! Please:
346
+
347
+ 1. **Fork the repository**
348
+ 2. **Create a feature branch** - `git checkout -b feature/your-feature`
349
+ 3. **Make your changes**
350
+ 4. **Add tests** - Ensure tests pass with `npm test`
351
+ 5. **Lint your code** - Run `npm run lint:fix`
352
+ 6. **Commit your changes** - Follow conventional commit format
353
+ 7. **Push to your fork** - `git push origin feature/your-feature`
354
+ 8. **Create a Pull Request**
355
+
356
+ ### Code Style
357
+
358
+ - Use TypeScript with proper types (avoid `any`)
359
+ - Prefix unused variables with `_` (e.g., `_unusedVar`)
360
+ - Add tests for new features
361
+ - Follow existing code structure
362
+ - Update documentation for user-facing changes
363
+
364
+ ### Running in Development
365
+
366
+ ```bash
367
+ # Terminal 1: Watch TypeScript compilation
368
+ npm run watch
369
+
370
+ # Terminal 2: Run tests in watch mode
371
+ npm test -- --watch
372
+
373
+ # Terminal 3: Run the shell
374
+ node dist/cli.js
375
+ ```
376
+
377
+ ## License
378
+
379
+ ISC
380
+
381
+ ## Project Status
382
+
383
+ **Active Development** - This project is under active development. Features and APIs may change.
384
+
385
+ **Current Focus:**
386
+ - Improving test coverage (target: 70%)
387
+ - Reducing lint errors
388
+ - Adding comprehensive documentation
389
+ - Refactoring large modules
390
+
391
+ ## Credits
392
+
393
+ - [awesome-micro-npm](https://github.com/parro-it/awesome-micro-npm-packages)
394
+
395
+ ## Support
396
+
397
+ For issues, questions, or contributions:
398
+ - **Issues**: https://github.com/gwicho38/lsh/issues
399
+ - **Discussions**: https://github.com/gwicho38/lsh/discussions
package/dist/app.js ADDED
@@ -0,0 +1,33 @@
1
+ import { Command } from 'commander';
2
+ import { init_lib } from './services/lib/lib.js';
3
+ import { init_ishell } from './services/shell/shell.js';
4
+ import { init_supabase } from './services/supabase/supabase.js';
5
+ import { init_daemon } from './services/daemon/daemon.js';
6
+ import { init_cron } from './services/cron/cron.js';
7
+ const program = new Command();
8
+ program
9
+ .version('0.0.0')
10
+ .description('lsh | extensible cli client.')
11
+ .name('lsh');
12
+ init_ishell(program);
13
+ init_lib(program);
14
+ init_supabase(program);
15
+ init_daemon(program);
16
+ init_cron(program);
17
+ // Show help without error when no command is provided
18
+ program.configureHelp({
19
+ showGlobalOptions: true,
20
+ });
21
+ // Set exitOverride to prevent Commander from calling process.exit
22
+ program.exitOverride((err) => {
23
+ // If showing help, exit cleanly
24
+ if (err.code === 'commander.helpDisplayed' || err.code === 'commander.help') {
25
+ process.exit(0);
26
+ }
27
+ throw err;
28
+ });
29
+ program.parse(process.argv);
30
+ // If no command was provided, show help and exit cleanly
31
+ if (process.argv.length <= 2) {
32
+ program.help({ error: false });
33
+ }