@vee-stack/delta-cli 2.0.4 → 2.0.5

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 (135) hide show
  1. package/dist/analyzer/commands/analyze.js +260 -0
  2. package/dist/analyzer/commands/config.js +83 -0
  3. package/dist/analyzer/commands/report.js +38 -0
  4. package/dist/analyzer/generators/report.generator.js +123 -0
  5. package/dist/analyzer/index.js +44 -0
  6. package/dist/analyzer/scanners/project.scanner.js +92 -0
  7. package/dist/analyzer/validators/contracts.validator.js +42 -0
  8. package/dist/analyzer/validators/maintainability.validator.js +40 -0
  9. package/dist/analyzer/validators/observability.validator.js +39 -0
  10. package/dist/analyzer/validators/performance.validator.js +42 -0
  11. package/dist/analyzer/validators/security.validator.js +66 -0
  12. package/dist/analyzer/validators/soc.validator.js +75 -0
  13. package/dist/apps/cli/src/analyzer/commands/analyze.js +256 -0
  14. package/dist/apps/cli/src/analyzer/commands/config.js +83 -0
  15. package/dist/apps/cli/src/analyzer/commands/report.js +38 -0
  16. package/dist/apps/cli/src/analyzer/generators/report.generator.js +123 -0
  17. package/dist/apps/cli/src/analyzer/index.js +44 -0
  18. package/dist/apps/cli/src/analyzer/scanners/project.scanner.js +92 -0
  19. package/dist/apps/cli/src/analyzer/validators/contracts.validator.js +42 -0
  20. package/dist/apps/cli/src/analyzer/validators/maintainability.validator.js +40 -0
  21. package/dist/apps/cli/src/analyzer/validators/observability.validator.js +39 -0
  22. package/dist/apps/cli/src/analyzer/validators/performance.validator.js +42 -0
  23. package/dist/apps/cli/src/analyzer/validators/security.validator.js +66 -0
  24. package/dist/apps/cli/src/analyzer/validators/soc.validator.js +75 -0
  25. package/dist/apps/cli/src/auth/secure-auth.js +312 -0
  26. package/dist/apps/cli/src/commands/analyze.js +286 -0
  27. package/dist/apps/cli/src/commands/auth-new.js +37 -0
  28. package/dist/apps/cli/src/commands/auth.js +122 -0
  29. package/dist/apps/cli/src/commands/config.js +49 -0
  30. package/dist/apps/cli/src/commands/deploy.js +6 -0
  31. package/dist/apps/cli/src/commands/init.js +47 -0
  32. package/dist/apps/cli/src/commands/logout.js +23 -0
  33. package/dist/apps/cli/src/commands/plugins.js +21 -0
  34. package/dist/apps/cli/src/commands/status.js +80 -0
  35. package/dist/apps/cli/src/commands/sync.js +6 -0
  36. package/dist/apps/cli/src/commands/whoami.js +115 -0
  37. package/dist/apps/cli/src/components/Dashboard.js +168 -0
  38. package/dist/apps/cli/src/components/DeltaApp.js +56 -0
  39. package/dist/apps/cli/src/components/UnifiedManager.js +324 -0
  40. package/dist/apps/cli/src/core/audit.js +184 -0
  41. package/dist/apps/cli/src/core/completion.js +294 -0
  42. package/dist/apps/cli/src/core/contracts.js +6 -0
  43. package/dist/apps/cli/src/core/engine.js +124 -0
  44. package/dist/apps/cli/src/core/exit-codes.js +71 -0
  45. package/dist/apps/cli/src/core/hooks.js +181 -0
  46. package/dist/apps/cli/src/core/index.js +7 -0
  47. package/dist/apps/cli/src/core/policy.js +115 -0
  48. package/dist/apps/cli/src/core/profiles.js +161 -0
  49. package/dist/apps/cli/src/core/wizard.js +203 -0
  50. package/dist/apps/cli/src/index.js +636 -0
  51. package/dist/apps/cli/src/interactive/index.js +11 -0
  52. package/dist/apps/cli/src/plugins/GitStatusPlugin.js +99 -0
  53. package/dist/apps/cli/src/providers/ai-provider.js +74 -0
  54. package/dist/apps/cli/src/providers/local-provider.js +302 -0
  55. package/dist/apps/cli/src/providers/remote-provider.js +100 -0
  56. package/dist/apps/cli/src/types/api.js +3 -0
  57. package/dist/apps/cli/src/ui.js +219 -0
  58. package/dist/apps/cli/src/welcome.js +81 -0
  59. package/dist/auth/secure-auth.js +418 -0
  60. package/dist/bundle.js +45 -45
  61. package/dist/commands/analyze.js +363 -0
  62. package/dist/commands/auth-new.js +37 -0
  63. package/dist/commands/auth.js +133 -0
  64. package/dist/commands/config.js +50 -0
  65. package/dist/commands/deploy.js +6 -0
  66. package/dist/commands/init.js +47 -0
  67. package/dist/commands/logout.js +30 -0
  68. package/dist/commands/plugins.js +21 -0
  69. package/dist/commands/status.js +82 -0
  70. package/dist/commands/sync.js +6 -0
  71. package/dist/commands/whoami.js +71 -0
  72. package/dist/components/Dashboard.js +169 -0
  73. package/dist/components/DeltaApp.js +57 -0
  74. package/dist/components/UnifiedManager.js +344 -0
  75. package/dist/core/audit.js +184 -0
  76. package/dist/core/completion.js +294 -0
  77. package/dist/core/contracts.js +6 -0
  78. package/dist/core/engine.js +124 -0
  79. package/dist/core/exit-codes.js +71 -0
  80. package/dist/core/hooks.js +181 -0
  81. package/dist/core/index.js +7 -0
  82. package/dist/core/policy.js +115 -0
  83. package/dist/core/profiles.js +161 -0
  84. package/dist/core/wizard.js +203 -0
  85. package/dist/index.js +387 -0
  86. package/dist/interactive/index.js +11 -0
  87. package/dist/packages/domain/src/constitution/contracts/index.js +43 -0
  88. package/dist/packages/domain/src/constitution/contracts/ts.rules.js +268 -0
  89. package/dist/packages/domain/src/constitution/index.js +139 -0
  90. package/dist/packages/domain/src/constitution/maintainability/index.js +43 -0
  91. package/dist/packages/domain/src/constitution/maintainability/ts.rules.js +344 -0
  92. package/dist/packages/domain/src/constitution/observability/index.js +43 -0
  93. package/dist/packages/domain/src/constitution/observability/ts.rules.js +307 -0
  94. package/dist/packages/domain/src/constitution/performance/index.js +43 -0
  95. package/dist/packages/domain/src/constitution/performance/ts.rules.js +325 -0
  96. package/dist/packages/domain/src/constitution/security/index.js +50 -0
  97. package/dist/packages/domain/src/constitution/security/ts.rules.js +267 -0
  98. package/dist/packages/domain/src/constitution/soc/index.js +43 -0
  99. package/dist/packages/domain/src/constitution/soc/ts.rules.js +360 -0
  100. package/dist/packages/domain/src/contracts/analysis.contract.js +18 -0
  101. package/dist/packages/domain/src/contracts/index.js +7 -0
  102. package/dist/packages/domain/src/contracts/projects.contract.js +18 -0
  103. package/dist/packages/domain/src/control/registry/rules.registry.js +29 -0
  104. package/dist/packages/domain/src/control/schemas/policies.js +6 -0
  105. package/dist/packages/domain/src/core/analysis/discovery.js +163 -0
  106. package/dist/packages/domain/src/core/analysis/engine.contract.js +298 -0
  107. package/dist/packages/domain/src/core/analysis/engine.js +77 -0
  108. package/dist/packages/domain/src/core/analysis/index.js +14 -0
  109. package/dist/packages/domain/src/core/analysis/orchestrator.js +242 -0
  110. package/dist/packages/domain/src/core/comparison/engine.js +29 -0
  111. package/dist/packages/domain/src/core/comparison/index.js +5 -0
  112. package/dist/packages/domain/src/core/documentation/index.js +5 -0
  113. package/dist/packages/domain/src/core/documentation/pipeline.js +41 -0
  114. package/dist/packages/domain/src/core/fs/adapter.js +111 -0
  115. package/dist/packages/domain/src/core/fs/index.js +5 -0
  116. package/dist/packages/domain/src/core/parser/unified-parser.js +166 -0
  117. package/dist/packages/domain/src/index.js +33 -0
  118. package/dist/packages/domain/src/plugin/registry.js +195 -0
  119. package/dist/packages/domain/src/plugin/types.js +6 -0
  120. package/dist/packages/domain/src/ports/analysis.engine.js +7 -0
  121. package/dist/packages/domain/src/ports/audit.logger.js +7 -0
  122. package/dist/packages/domain/src/ports/project.repository.js +7 -0
  123. package/dist/packages/domain/src/rules/index.js +134 -0
  124. package/dist/packages/domain/src/types/analysis.js +6 -0
  125. package/dist/packages/domain/src/types/errors.js +53 -0
  126. package/dist/packages/domain/src/types/fs.js +6 -0
  127. package/dist/packages/domain/src/types/index.js +7 -0
  128. package/dist/plugins/GitStatusPlugin.js +93 -0
  129. package/dist/providers/ai-provider.js +74 -0
  130. package/dist/providers/local-provider.js +304 -0
  131. package/dist/providers/remote-provider.js +100 -0
  132. package/dist/types/api.js +3 -0
  133. package/dist/ui.js +219 -0
  134. package/dist/welcome.js +81 -0
  135. package/package.json +18 -18
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Tab Autocomplete System for Delta CLI
3
+ * Provides shell completion for commands, flags, and options
4
+ */
5
+ // Completion items database
6
+ export const completionDatabase = {
7
+ commands: [
8
+ { name: 'help', alias: ['/?', '/h'], desc: 'Show help' },
9
+ { name: 'analyze', alias: ['/a', '/analyze'], desc: 'Code analysis' },
10
+ { name: 'init', alias: ['/i', '/init'], desc: 'Initialize project' },
11
+ { name: 'status', alias: ['/st', '/status'], desc: 'Check status' },
12
+ { name: 'login', alias: ['/login'], desc: 'Authenticate' },
13
+ { name: 'logout', alias: ['/logout'], desc: 'Sign out' },
14
+ { name: 'whoami', alias: ['/me', '/whoami'], desc: 'User info' },
15
+ { name: 'config', alias: ['/config'], desc: 'Configuration' },
16
+ { name: 'dashboard', alias: ['/ui', '/dashboard'], desc: 'Interactive UI' },
17
+ { name: 'sync', alias: ['/sync'], desc: 'Cloud sync' },
18
+ { name: 'deploy', alias: ['/deploy'], desc: 'Deploy project' },
19
+ { name: 'plugins', alias: ['/plugins'], desc: 'Manage plugins' },
20
+ ],
21
+ globalFlags: [
22
+ { name: '--json', desc: 'Output as JSON' },
23
+ { name: '--provider', values: ['local', 'remote', 'ai'], desc: 'Execution provider' },
24
+ { name: '--theme', values: ['delta', 'cyber', 'sunset', 'neon', 'ocean', 'fire'], desc: 'Color theme' },
25
+ { name: '--verbose', desc: 'Verbose logging' },
26
+ { name: '--no-color', desc: 'Disable colors' },
27
+ { name: '--interactive', alias: '-i', desc: 'Interactive mode' },
28
+ { name: '--version', alias: '-v', desc: 'Show version' },
29
+ { name: '--help', alias: '-h', desc: 'Show help' },
30
+ ],
31
+ commandFlags: {
32
+ analyze: [
33
+ { name: '--format', values: ['json', 'html', 'markdown', 'sarif'], desc: 'Output format' },
34
+ { name: '--output', values: ['./delta-reports'], desc: 'Output directory' },
35
+ { name: '--include', desc: 'Include patterns' },
36
+ { name: '--exclude', desc: 'Exclude patterns' },
37
+ { name: '--max-size', desc: 'Max file size' },
38
+ { name: '--upload', desc: 'Upload to cloud' },
39
+ { name: '--share', desc: 'Generate shareable link' },
40
+ { name: '--project-name', desc: 'Project name' },
41
+ { name: '--ai-insights', desc: 'AI insights' },
42
+ { name: '--security-scan', desc: 'Security scan' },
43
+ { name: '--performance', desc: 'Performance analysis' },
44
+ ],
45
+ init: [
46
+ { name: '--template', values: ['default', 'nextjs', 'react', 'node', 'python'], desc: 'Project template' },
47
+ { name: '--force', alias: '-f', desc: 'Overwrite existing' },
48
+ { name: '--git', desc: 'Initialize git' },
49
+ ],
50
+ status: [
51
+ { name: '--diagnostics', desc: 'Full diagnostics' },
52
+ { name: '--fix', desc: 'Auto-fix issues' },
53
+ ],
54
+ login: [
55
+ { name: '--method', values: ['oauth', 'pat', 'github', 'google'], desc: 'Auth method' },
56
+ { name: '--token', desc: 'PAT token' },
57
+ ],
58
+ config: [
59
+ { name: '--get', desc: 'Get config value' },
60
+ { name: '--set', desc: 'Set config value' },
61
+ { name: '--list', alias: '-l', desc: 'List all config' },
62
+ { name: '--reset', desc: 'Reset to default' },
63
+ ],
64
+ },
65
+ };
66
+ // Generate shell completion script
67
+ export function generateCompletionScript(shell) {
68
+ const cliName = 'delta';
69
+ switch (shell) {
70
+ case 'bash':
71
+ return generateBashCompletion(cliName);
72
+ case 'zsh':
73
+ return generateZshCompletion(cliName);
74
+ case 'fish':
75
+ return generateFishCompletion(cliName);
76
+ case 'powershell':
77
+ return generatePowershellCompletion(cliName);
78
+ default:
79
+ throw new Error(`Unsupported shell: ${shell}`);
80
+ }
81
+ }
82
+ function generateBashCompletion(cliName) {
83
+ const commands = completionDatabase.commands.map(c => c.name).join(' ');
84
+ const slashCommands = completionDatabase.commands.flatMap(c => c.alias).filter(a => a.startsWith('/')).join(' ');
85
+ return `#!/bin/bash
86
+ # Delta CLI Bash Completion
87
+ # Source this file: source <(delta completion bash)
88
+
89
+ _${cliName}_completions() {
90
+ local cur prev opts
91
+ COMPREPLY=()
92
+ cur="\${COMP_WORDS[COMP_CWORD]}"
93
+ prev="\${COMP_WORDS[COMP_CWORD-1]}"
94
+
95
+ # Commands list
96
+ local commands="${commands} ${slashCommands}"
97
+ local global_flags="--json --provider --theme --verbose --no-color --interactive --version --help -i -v -h"
98
+
99
+ # Complete commands
100
+ if [[ \${COMP_CWORD} -eq 1 ]]; then
101
+ COMPREPLY=( $(compgen -W "\${commands} \${global_flags}" -- \${cur}) )
102
+ return 0
103
+ fi
104
+
105
+ # Complete flags based on command
106
+ case "\${COMP_WORDS[1]}" in
107
+ analyze|/a|/analyze)
108
+ opts="--format --output --include --exclude --max-size --upload --share --project-name --ai-insights --security-scan --performance --json --provider"
109
+ ;;
110
+ init|/i|/init)
111
+ opts="--template --force --git --json --provider -f"
112
+ ;;
113
+ status|/st|/status)
114
+ opts="--diagnostics --fix --json"
115
+ ;;
116
+ login|/login)
117
+ opts="--method --token --json"
118
+ ;;
119
+ config|/config)
120
+ opts="--get --set --list --reset -l --json"
121
+ ;;
122
+ *)
123
+ opts="\${global_flags}"
124
+ ;;
125
+ esac
126
+
127
+ # Complete flag values
128
+ case "\${prev}" in
129
+ --provider)
130
+ COMPREPLY=( $(compgen -W "local remote ai" -- \${cur}) )
131
+ return 0
132
+ ;;
133
+ --theme)
134
+ COMPREPLY=( $(compgen -W "delta cyber sunset neon ocean fire" -- \${cur}) )
135
+ return 0
136
+ ;;
137
+ --format)
138
+ COMPREPLY=( $(compgen -W "json html markdown sarif" -- \${cur}) )
139
+ return 0
140
+ ;;
141
+ --template)
142
+ COMPREPLY=( $(compgen -W "default nextjs react node python" -- \${cur}) )
143
+ return 0
144
+ ;;
145
+ --method)
146
+ COMPREPLY=( $(compgen -W "oauth pat github google" -- \${cur}) )
147
+ return 0
148
+ ;;
149
+ esac
150
+
151
+ COMPREPLY=( $(compgen -W "\${opts}" -- \${cur}) )
152
+ return 0
153
+ }
154
+
155
+ complete -F _${cliName}_completions ${cliName}
156
+ `;
157
+ }
158
+ function generateZshCompletion(cliName) {
159
+ return `#compdef ${cliName}
160
+ # Delta CLI Zsh Completion
161
+
162
+ _${cliName}() {
163
+ local curcontext="$curcontext" state line
164
+ typeset -A opt_args
165
+
166
+ _arguments -C \\
167
+ '(-h --help)'{-h,--help}'[Show help]' \\
168
+ '(-v --version)'{-v,--version}'[Show version]' \\
169
+ '(-i --interactive)'{-i,--interactive}'[Interactive mode]' \\
170
+ '--json[Output as JSON]' \\
171
+ '--provider[Execution provider]:provider:(local remote ai)' \\
172
+ '--theme[Color theme]:theme:(delta cyber sunset neon ocean fire)' \\
173
+ '--verbose[Verbose logging]' \\
174
+ '--no-color[Disable colors]' \\
175
+ '1: :->command' \\
176
+ '*:: :->args'
177
+
178
+ case "$state" in
179
+ command)
180
+ _values 'commands' \\
181
+ 'help[Show help]' \\
182
+ 'analyze[Code analysis]' \\
183
+ 'init[Initialize project]' \\
184
+ 'status[Check status]' \\
185
+ 'login[Authenticate]' \\
186
+ 'logout[Sign out]' \\
187
+ 'whoami[User info]' \\
188
+ 'config[Configuration]' \\
189
+ 'dashboard[Interactive UI]' \\
190
+ 'sync[Cloud sync]' \\
191
+ 'deploy[Deploy project]' \\
192
+ 'plugins[Manage plugins]'
193
+ ;;
194
+ args)
195
+ case "$line[1]" in
196
+ analyze)
197
+ _arguments \\
198
+ '--format[Output format]:format:(json html markdown sarif)' \\
199
+ '--output[Output directory]' \\
200
+ '--include[Include patterns]' \\
201
+ '--exclude[Exclude patterns]' \\
202
+ '--upload[Upload to cloud]' \\
203
+ '--share[Generate shareable link]' \\
204
+ '--project-name[Project name]'
205
+ ;;
206
+ init)
207
+ _arguments \\
208
+ '--template[Project template]:template:(default nextjs react node python)' \\
209
+ '(-f --force)'{-f,--force}'[Overwrite existing]' \\
210
+ '--git[Initialize git]'
211
+ ;;
212
+ status)
213
+ _arguments \\
214
+ '--diagnostics[Full diagnostics]' \\
215
+ '--fix[Auto-fix issues]'
216
+ ;;
217
+ esac
218
+ ;;
219
+ esac
220
+ }
221
+
222
+ _${cliName} "$@"
223
+ `;
224
+ }
225
+ function generateFishCompletion(cliName) {
226
+ return `# Delta CLI Fish Completion
227
+
228
+ # Commands
229
+ complete -c ${cliName} -f
230
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'help' -d 'Show help'
231
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'analyze' -d 'Code analysis'
232
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'init' -d 'Initialize project'
233
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'status' -d 'Check status'
234
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'login' -d 'Authenticate'
235
+ complete -c ${cliName} -n '__fish_use_subcommand' -a 'logout' -d 'Sign out'
236
+
237
+ # Global flags
238
+ complete -c ${cliName} -l json -d 'Output as JSON'
239
+ complete -c ${cliName} -l provider -d 'Execution provider' -xa 'local remote ai'
240
+ complete -c ${cliName} -l theme -d 'Color theme' -xa 'delta cyber sunset neon ocean fire'
241
+ complete -c ${cliName} -l verbose -d 'Verbose logging'
242
+ complete -c ${cliName} -l no-color -d 'Disable colors'
243
+ complete -c ${cliName} -s i -l interactive -d 'Interactive mode'
244
+ complete -c ${cliName} -s v -l version -d 'Show version'
245
+ complete -c ${cliName} -s h -l help -d 'Show help'
246
+ `;
247
+ }
248
+ function generatePowershellCompletion(cliName) {
249
+ return `# Delta CLI PowerShell Completion
250
+ # Add to $PROFILE: . delta completion powershell | Out-String | Invoke-Expression
251
+
252
+ Register-ArgumentCompleter -Native -CommandName ${cliName} -ScriptBlock {
253
+ param($wordToComplete, $commandAst, $cursorPosition)
254
+
255
+ $commands = @('help', 'analyze', 'init', 'status', 'login', 'logout', 'whoami', 'config', 'dashboard', 'sync', 'deploy', 'plugins')
256
+ $slashCommands = @('/help', '/h', '/analyze', '/a', '/init', '/i', '/status', '/st', '/login', '/logout', '/me', '/whoami', '/config', '/ui', '/sync', '/deploy', '/plugins')
257
+
258
+ $command = $commandAst.CommandElements[1].Value
259
+
260
+ if ($commandAst.CommandElements.Count -eq 1 -or
261
+ ($commandAst.CommandElements.Count -eq 2 -and $wordToComplete -ne '')) {
262
+ $commands + $slashCommands | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
263
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
264
+ }
265
+ return
266
+ }
267
+
268
+ switch ($command) {
269
+ { $_ -in 'analyze', '/a', '/analyze' } {
270
+ $flags = @('--format', '--output', '--include', '--exclude', '--upload', '--share', '--json', '--provider')
271
+ $flags | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
272
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterName', $_)
273
+ }
274
+ }
275
+ { $_ -in 'init', '/i', '/init' } {
276
+ $flags = @('--template', '--force', '--git', '--json')
277
+ $flags | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
278
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterName', $_)
279
+ }
280
+ }
281
+ }
282
+ }
283
+ `;
284
+ }
285
+ // Install completion for current shell
286
+ export async function installCompletion(shell) {
287
+ const detectedShell = shell || process.env.SHELL?.split('/').pop() || 'bash';
288
+ console.log(`Installing completion for ${detectedShell}...\n`);
289
+ const script = generateCompletionScript(detectedShell);
290
+ console.log('Add this to your shell config:\n');
291
+ console.log(script);
292
+ console.log('\nOr run: eval "$(delta completion ' + detectedShell + ')"');
293
+ }
294
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Core Contracts - Interface definitions for Delta CLI
3
+ * AI-Ready Architecture: Separate CLI from Business Logic
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Delta Engine - Core Execution Engine
3
+ * Mediator between CLI and Execution Providers
4
+ */
5
+ import { ExitCode, getExitCode } from './exit-codes.js';
6
+ export class DeltaEngine {
7
+ providers = new Map();
8
+ config;
9
+ policy;
10
+ listeners = [];
11
+ version = '2.0.0';
12
+ constructor(config, policy) {
13
+ this.config = config;
14
+ this.policy = policy;
15
+ }
16
+ // Register an execution provider
17
+ registerProvider(provider) {
18
+ this.providers.set(provider.name, provider);
19
+ }
20
+ // Get registered provider
21
+ getProvider(name) {
22
+ return this.providers.get(name);
23
+ }
24
+ // Execute a task through the engine
25
+ async execute(request) {
26
+ const startTime = Date.now();
27
+ // Emit start event
28
+ this.emit({ type: 'task:start', request });
29
+ try {
30
+ // Validate request with policy (includes capability check)
31
+ const validation = this.policy.validate(request);
32
+ if (!validation.valid) {
33
+ const exitCode = validation.exitCode || ExitCode.VALIDATION_ERROR;
34
+ throw Object.assign(new Error(validation.reason || 'Task validation failed'), { code: exitCode === ExitCode.POLICY_BLOCKED ? 'POLICY_BLOCKED' : 'VALIDATION_ERROR', exitCode });
35
+ }
36
+ // Transform request if needed (includes non-TTY detection)
37
+ const transformedRequest = this.policy.transform?.(request) || request;
38
+ // Select appropriate provider using policy
39
+ const provider = this.policy.selectProvider(transformedRequest, this.providers);
40
+ if (!provider) {
41
+ throw Object.assign(new Error(`No provider available for task type '${transformedRequest.type}'`), { code: 'NO_PROVIDER', exitCode: ExitCode.POLICY_BLOCKED });
42
+ }
43
+ // Check provider availability
44
+ const available = await provider.isAvailable();
45
+ if (!available) {
46
+ throw Object.assign(new Error(`Provider '${provider.name}' is not available`), { code: 'PROVIDER_UNAVAILABLE', exitCode: ExitCode.NETWORK_ERROR });
47
+ }
48
+ // Execute task
49
+ this.emit({ type: 'task:progress', request: transformedRequest, progress: 0.5 });
50
+ const response = await provider.execute(transformedRequest);
51
+ // Enrich response with engine metadata
52
+ const enrichedResponse = {
53
+ ...response,
54
+ meta: {
55
+ ...response.meta,
56
+ command: request.command,
57
+ duration: Date.now() - startTime,
58
+ timestamp: new Date().toISOString(),
59
+ version: this.version,
60
+ coldStart: Date.now() - startTime - response.meta.duration,
61
+ provider: provider.name,
62
+ },
63
+ };
64
+ // Emit completion
65
+ this.emit({
66
+ type: 'task:complete',
67
+ request: transformedRequest,
68
+ response: enrichedResponse
69
+ });
70
+ return enrichedResponse;
71
+ }
72
+ catch (error) {
73
+ // Emit error
74
+ this.emit({
75
+ type: 'task:error',
76
+ request,
77
+ error: error instanceof Error ? error : new Error(String(error))
78
+ });
79
+ return {
80
+ success: false,
81
+ exitCode: getExitCode(error),
82
+ meta: {
83
+ command: request.command,
84
+ duration: Date.now() - startTime,
85
+ timestamp: new Date().toISOString(),
86
+ version: this.version,
87
+ provider: 'engine',
88
+ },
89
+ error: {
90
+ code: error instanceof Error && 'code' in error
91
+ ? error.code
92
+ : 'EXECUTION_ERROR',
93
+ message: error instanceof Error ? error.message : String(error),
94
+ },
95
+ };
96
+ }
97
+ }
98
+ // Subscribe to engine events
99
+ on(_event, listener) {
100
+ this.listeners.push(listener);
101
+ }
102
+ // Emit event to all listeners
103
+ emit(event) {
104
+ this.listeners.forEach(listener => listener(event));
105
+ }
106
+ // Get engine status
107
+ getStatus() {
108
+ return {
109
+ version: this.version,
110
+ providers: Array.from(this.providers.keys()),
111
+ defaultProvider: this.config.defaultProvider,
112
+ };
113
+ }
114
+ }
115
+ // Singleton instance
116
+ let engineInstance = null;
117
+ export function createEngine(config, policy) {
118
+ engineInstance = new DeltaEngine(config, policy);
119
+ return engineInstance;
120
+ }
121
+ export function getEngine() {
122
+ return engineInstance;
123
+ }
124
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Exit Code Contract - Enterprise-grade error classification
3
+ * Critical for CI/CD integration and automation
4
+ */
5
+ export var ExitCode;
6
+ (function (ExitCode) {
7
+ ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
8
+ ExitCode[ExitCode["VALIDATION_ERROR"] = 1] = "VALIDATION_ERROR";
9
+ ExitCode[ExitCode["NETWORK_ERROR"] = 2] = "NETWORK_ERROR";
10
+ ExitCode[ExitCode["AUTH_ERROR"] = 3] = "AUTH_ERROR";
11
+ ExitCode[ExitCode["POLICY_BLOCKED"] = 4] = "POLICY_BLOCKED";
12
+ ExitCode[ExitCode["EXECUTION_ERROR"] = 5] = "EXECUTION_ERROR";
13
+ ExitCode[ExitCode["UNKNOWN_ERROR"] = 6] = "UNKNOWN_ERROR";
14
+ })(ExitCode || (ExitCode = {}));
15
+ // Error to Exit Code mapping
16
+ export function getExitCode(error) {
17
+ const errorStr = typeof error === 'string'
18
+ ? error
19
+ : error instanceof Error
20
+ ? error.message
21
+ : error.message || String(error);
22
+ const errorCode = typeof error === 'object' && 'code' in error ? error.code : undefined;
23
+ // Check error codes first
24
+ if (errorCode) {
25
+ switch (errorCode) {
26
+ case 'VALIDATION_ERROR':
27
+ case 'INVALID_INPUT':
28
+ case 'MISSING_ARGUMENT':
29
+ return ExitCode.VALIDATION_ERROR;
30
+ case 'AUTH_ERROR':
31
+ case 'UNAUTHORIZED':
32
+ case 'TOKEN_EXPIRED':
33
+ return ExitCode.AUTH_ERROR;
34
+ case 'NETWORK_ERROR':
35
+ case 'CONNECTION_FAILED':
36
+ case 'TIMEOUT':
37
+ return ExitCode.NETWORK_ERROR;
38
+ case 'POLICY_BLOCKED':
39
+ case 'QUOTA_EXCEEDED':
40
+ case 'PERMISSION_DENIED':
41
+ return ExitCode.POLICY_BLOCKED;
42
+ case 'EXECUTION_ERROR':
43
+ return ExitCode.EXECUTION_ERROR;
44
+ }
45
+ }
46
+ // Check error messages
47
+ if (errorStr.includes('validation') || errorStr.includes('invalid') || errorStr.includes('required')) {
48
+ return ExitCode.VALIDATION_ERROR;
49
+ }
50
+ if (errorStr.includes('auth') || errorStr.includes('token') || errorStr.includes('unauthorized')) {
51
+ return ExitCode.AUTH_ERROR;
52
+ }
53
+ if (errorStr.includes('network') || errorStr.includes('connection') || errorStr.includes('timeout')) {
54
+ return ExitCode.NETWORK_ERROR;
55
+ }
56
+ if (errorStr.includes('policy') || errorStr.includes('quota') || errorStr.includes('permission')) {
57
+ return ExitCode.POLICY_BLOCKED;
58
+ }
59
+ return ExitCode.EXECUTION_ERROR;
60
+ }
61
+ // Human-readable exit code descriptions
62
+ export const ExitCodeDescription = {
63
+ [ExitCode.SUCCESS]: 'Success',
64
+ [ExitCode.VALIDATION_ERROR]: 'Validation error - check your input',
65
+ [ExitCode.NETWORK_ERROR]: 'Network error - check your connection',
66
+ [ExitCode.AUTH_ERROR]: 'Authentication error - please login',
67
+ [ExitCode.POLICY_BLOCKED]: 'Policy blocked - insufficient permissions or quota',
68
+ [ExitCode.EXECUTION_ERROR]: 'Execution error - task failed during execution',
69
+ [ExitCode.UNKNOWN_ERROR]: 'Unknown error - please report this issue',
70
+ };
71
+ //# sourceMappingURL=exit-codes.js.map
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Hooks & Notifications System
3
+ * Post-command hooks for Slack, Teams, Webhooks
4
+ * Enterprise CI/CD integration
5
+ */
6
+ import { promises as fs } from 'fs';
7
+ import { homedir } from 'os';
8
+ import { join } from 'path';
9
+ const HOOKS_FILE = join(homedir(), '.delta', 'hooks.json');
10
+ export class HookManager {
11
+ hooks = [];
12
+ loaded = false;
13
+ async load() {
14
+ if (this.loaded)
15
+ return;
16
+ try {
17
+ const data = await fs.readFile(HOOKS_FILE, 'utf-8');
18
+ this.hooks = JSON.parse(data);
19
+ }
20
+ catch {
21
+ this.hooks = [];
22
+ }
23
+ this.loaded = true;
24
+ }
25
+ async save() {
26
+ await fs.mkdir(join(homedir(), '.delta'), { recursive: true });
27
+ await fs.writeFile(HOOKS_FILE, JSON.stringify(this.hooks, null, 2), 'utf-8');
28
+ }
29
+ async addHook(hook) {
30
+ const newHook = {
31
+ ...hook,
32
+ id: `hook-${Date.now()}`,
33
+ };
34
+ this.hooks.push(newHook);
35
+ await this.save();
36
+ return newHook;
37
+ }
38
+ async removeHook(id) {
39
+ this.hooks = this.hooks.filter(h => h.id !== id);
40
+ await this.save();
41
+ }
42
+ async listHooks() {
43
+ await this.load();
44
+ return this.hooks;
45
+ }
46
+ async toggleHook(id) {
47
+ const hook = this.hooks.find(h => h.id === id);
48
+ if (hook) {
49
+ hook.enabled = !hook.enabled;
50
+ await this.save();
51
+ }
52
+ }
53
+ async executeHooks(type, command, response, startTime) {
54
+ await this.load();
55
+ const matchingHooks = this.hooks.filter(h => h.enabled && h.type === type && (!h.command || h.command === command));
56
+ const payload = {
57
+ command,
58
+ success: response.success,
59
+ exitCode: response.exitCode || (response.success ? 0 : 1),
60
+ duration: Date.now() - startTime,
61
+ timestamp: new Date().toISOString(),
62
+ project: process.env.DELTA_PROJECT,
63
+ user: process.env.USER || process.env.USERNAME,
64
+ error: response.error?.message,
65
+ summary: this.generateSummary(command, response),
66
+ };
67
+ // Execute hooks in parallel
68
+ await Promise.all(matchingHooks.map(hook => this.sendNotification(hook, payload).catch(() => { })));
69
+ }
70
+ async sendNotification(hook, payload) {
71
+ const body = hook.payload
72
+ ? this.renderTemplate(hook.payload, payload)
73
+ : JSON.stringify(payload);
74
+ const response = await fetch(hook.url, {
75
+ method: hook.method,
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ ...hook.headers,
79
+ },
80
+ body: hook.method === 'POST' ? body : undefined,
81
+ });
82
+ if (!response.ok) {
83
+ throw new Error(`Hook failed: ${response.status}`);
84
+ }
85
+ }
86
+ renderTemplate(template, payload) {
87
+ return template
88
+ .replace(/\{\{command\}\}/g, payload.command)
89
+ .replace(/\{\{success\}\}/g, payload.success ? 'success' : 'failed')
90
+ .replace(/\{\{exitCode\}\}/g, String(payload.exitCode))
91
+ .replace(/\{\{duration\}\}/g, String(payload.duration))
92
+ .replace(/\{\{project\}\}/g, payload.project || 'unknown')
93
+ .replace(/\{\{user\}\}/g, payload.user || 'unknown');
94
+ }
95
+ generateSummary(command, response) {
96
+ switch (command) {
97
+ case 'analyze':
98
+ return response.success
99
+ ? `Analyzed ${response.data?.filesAnalyzed || 0} files, found ${response.data?.findings || 0} issues`
100
+ : 'Analysis failed';
101
+ case 'deploy':
102
+ return response.success ? 'Deployment successful' : 'Deployment failed';
103
+ default:
104
+ return response.success ? 'Command completed' : 'Command failed';
105
+ }
106
+ }
107
+ }
108
+ // Predefined templates for common services
109
+ export const hookTemplates = {
110
+ slack: (webhookUrl) => ({
111
+ name: 'Slack Notifications',
112
+ type: 'post-always',
113
+ url: webhookUrl,
114
+ method: 'POST',
115
+ headers: {},
116
+ payload: JSON.stringify({
117
+ text: 'Delta CLI: {{command}} {{success}}',
118
+ blocks: [
119
+ {
120
+ type: 'section',
121
+ text: {
122
+ type: 'mrkdwn',
123
+ text: '*Delta CLI Notification*',
124
+ },
125
+ },
126
+ {
127
+ type: 'section',
128
+ fields: [
129
+ { type: 'mrkdwn', text: `*Command:*\n{{command}}` },
130
+ { type: 'mrkdwn', text: `*Status:*\n{{success}}` },
131
+ { type: 'mrkdwn', text: `*Duration:*\n{{duration}}ms` },
132
+ { type: 'mrkdwn', text: `*Project:*\n{{project}}` },
133
+ ],
134
+ },
135
+ ],
136
+ }),
137
+ enabled: true,
138
+ }),
139
+ teams: (webhookUrl) => ({
140
+ name: 'Teams Notifications',
141
+ type: 'post-always',
142
+ url: webhookUrl,
143
+ method: 'POST',
144
+ headers: {},
145
+ payload: JSON.stringify({
146
+ '@type': 'MessageCard',
147
+ '@context': 'https://schema.org/extensions',
148
+ summary: 'Delta CLI {{command}}',
149
+ themeColor: '{{#if success}}00FF00{{else}}FF0000{{/if}}',
150
+ sections: [
151
+ {
152
+ activityTitle: 'Delta CLI Notification',
153
+ facts: [
154
+ { name: 'Command', value: '{{command}}' },
155
+ { name: 'Status', value: '{{success}}' },
156
+ { name: 'Duration', value: '{{duration}}ms' },
157
+ { name: 'Project', value: '{{project}}' },
158
+ ],
159
+ },
160
+ ],
161
+ }),
162
+ enabled: true,
163
+ }),
164
+ generic: (url) => ({
165
+ name: 'Webhook',
166
+ type: 'post-always',
167
+ url,
168
+ method: 'POST',
169
+ headers: {},
170
+ enabled: true,
171
+ }),
172
+ };
173
+ // Singleton instance
174
+ let hookManager = null;
175
+ export function getHookManager() {
176
+ if (!hookManager) {
177
+ hookManager = new HookManager();
178
+ }
179
+ return hookManager;
180
+ }
181
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Core Module - Export all core components
3
+ */
4
+ export * from './contracts.js';
5
+ export * from './engine.js';
6
+ export * from './policy.js';
7
+ //# sourceMappingURL=index.js.map