@vee-stack/delta-cli 2.0.8 → 2.0.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 (183) hide show
  1. package/dist/adapters/analysis.adapter.d.ts +29 -0
  2. package/dist/analyzer/commands/analyze.d.ts +14 -0
  3. package/dist/analyzer/commands/config.d.ts +12 -0
  4. package/dist/analyzer/commands/report.d.ts +11 -0
  5. package/dist/analyzer/generators/report.generator.d.ts +43 -0
  6. package/dist/analyzer/index.d.ts +8 -0
  7. package/dist/analyzer/scanners/project.scanner.d.ts +29 -0
  8. package/dist/analyzer/validators/contracts.validator.d.ts +27 -0
  9. package/dist/analyzer/validators/maintainability.validator.d.ts +27 -0
  10. package/dist/analyzer/validators/observability.validator.d.ts +27 -0
  11. package/dist/analyzer/validators/performance.validator.d.ts +27 -0
  12. package/dist/analyzer/validators/security.validator.d.ts +27 -0
  13. package/dist/analyzer/validators/soc.validator.d.ts +27 -0
  14. package/dist/auth/device-auth.d.ts +18 -0
  15. package/dist/auth/secure-auth.d.ts +35 -0
  16. package/dist/bundle.mjs +422 -0
  17. package/dist/commands/analyze.d.ts +12 -0
  18. package/dist/commands/auth-new.d.ts +6 -0
  19. package/dist/commands/auth.d.ts +17 -0
  20. package/dist/commands/config.d.ts +8 -0
  21. package/dist/commands/deploy.d.ts +5 -0
  22. package/dist/commands/init.d.ts +7 -0
  23. package/dist/commands/logout.d.ts +2 -0
  24. package/dist/commands/plugins.d.ts +7 -0
  25. package/dist/commands/status.d.ts +5 -0
  26. package/dist/commands/sync.d.ts +5 -0
  27. package/dist/commands/whoami.d.ts +4 -0
  28. package/dist/components/Dashboard.d.ts +8 -0
  29. package/dist/components/DeltaApp.d.ts +13 -0
  30. package/dist/components/UnifiedManager.d.ts +10 -0
  31. package/dist/core/audit.d.ts +60 -0
  32. package/dist/core/completion.d.ts +79 -0
  33. package/dist/core/contracts.d.ts +127 -0
  34. package/dist/core/engine.d.ts +26 -0
  35. package/dist/core/exit-codes.d.ts +19 -0
  36. package/dist/core/hooks.d.ts +50 -0
  37. package/dist/{apps/cli/src/core/index.js → core/index.d.ts} +1 -1
  38. package/dist/core/policy.d.ts +24 -0
  39. package/dist/core/profiles.d.ts +45 -0
  40. package/dist/core/wizard.d.ts +28 -0
  41. package/dist/interactive/index.d.ts +5 -0
  42. package/dist/plugins/GitStatusPlugin.d.ts +25 -0
  43. package/dist/providers/ai-provider.d.ts +21 -0
  44. package/dist/providers/local-provider.d.ts +21 -0
  45. package/dist/providers/remote-provider.d.ts +15 -0
  46. package/dist/telemetry/wrapper.d.ts +18 -0
  47. package/dist/types/api.d.ts +46 -0
  48. package/dist/ui.d.ts +52 -0
  49. package/dist/welcome.d.ts +8 -0
  50. package/package.json +8 -8
  51. package/dist/analyzer/commands/analyze.js +0 -260
  52. package/dist/analyzer/commands/config.js +0 -83
  53. package/dist/analyzer/commands/report.js +0 -38
  54. package/dist/analyzer/generators/report.generator.js +0 -123
  55. package/dist/analyzer/index.js +0 -44
  56. package/dist/analyzer/scanners/project.scanner.js +0 -92
  57. package/dist/analyzer/validators/contracts.validator.js +0 -42
  58. package/dist/analyzer/validators/maintainability.validator.js +0 -40
  59. package/dist/analyzer/validators/observability.validator.js +0 -39
  60. package/dist/analyzer/validators/performance.validator.js +0 -42
  61. package/dist/analyzer/validators/security.validator.js +0 -66
  62. package/dist/analyzer/validators/soc.validator.js +0 -75
  63. package/dist/apps/cli/src/analyzer/commands/analyze.js +0 -256
  64. package/dist/apps/cli/src/analyzer/commands/config.js +0 -83
  65. package/dist/apps/cli/src/analyzer/commands/report.js +0 -38
  66. package/dist/apps/cli/src/analyzer/generators/report.generator.js +0 -123
  67. package/dist/apps/cli/src/analyzer/index.js +0 -44
  68. package/dist/apps/cli/src/analyzer/scanners/project.scanner.js +0 -92
  69. package/dist/apps/cli/src/analyzer/validators/contracts.validator.js +0 -42
  70. package/dist/apps/cli/src/analyzer/validators/maintainability.validator.js +0 -40
  71. package/dist/apps/cli/src/analyzer/validators/observability.validator.js +0 -39
  72. package/dist/apps/cli/src/analyzer/validators/performance.validator.js +0 -42
  73. package/dist/apps/cli/src/analyzer/validators/security.validator.js +0 -66
  74. package/dist/apps/cli/src/analyzer/validators/soc.validator.js +0 -75
  75. package/dist/apps/cli/src/auth/secure-auth.js +0 -312
  76. package/dist/apps/cli/src/commands/analyze.js +0 -286
  77. package/dist/apps/cli/src/commands/auth-new.js +0 -37
  78. package/dist/apps/cli/src/commands/auth.js +0 -122
  79. package/dist/apps/cli/src/commands/config.js +0 -49
  80. package/dist/apps/cli/src/commands/deploy.js +0 -6
  81. package/dist/apps/cli/src/commands/init.js +0 -47
  82. package/dist/apps/cli/src/commands/logout.js +0 -23
  83. package/dist/apps/cli/src/commands/plugins.js +0 -21
  84. package/dist/apps/cli/src/commands/status.js +0 -80
  85. package/dist/apps/cli/src/commands/sync.js +0 -6
  86. package/dist/apps/cli/src/commands/whoami.js +0 -115
  87. package/dist/apps/cli/src/components/Dashboard.js +0 -168
  88. package/dist/apps/cli/src/components/DeltaApp.js +0 -56
  89. package/dist/apps/cli/src/components/UnifiedManager.js +0 -324
  90. package/dist/apps/cli/src/core/audit.js +0 -184
  91. package/dist/apps/cli/src/core/completion.js +0 -294
  92. package/dist/apps/cli/src/core/contracts.js +0 -6
  93. package/dist/apps/cli/src/core/engine.js +0 -124
  94. package/dist/apps/cli/src/core/exit-codes.js +0 -71
  95. package/dist/apps/cli/src/core/hooks.js +0 -181
  96. package/dist/apps/cli/src/core/policy.js +0 -115
  97. package/dist/apps/cli/src/core/profiles.js +0 -161
  98. package/dist/apps/cli/src/core/wizard.js +0 -203
  99. package/dist/apps/cli/src/index.js +0 -636
  100. package/dist/apps/cli/src/interactive/index.js +0 -11
  101. package/dist/apps/cli/src/plugins/GitStatusPlugin.js +0 -99
  102. package/dist/apps/cli/src/providers/ai-provider.js +0 -74
  103. package/dist/apps/cli/src/providers/local-provider.js +0 -302
  104. package/dist/apps/cli/src/providers/remote-provider.js +0 -100
  105. package/dist/apps/cli/src/types/api.js +0 -3
  106. package/dist/apps/cli/src/ui.js +0 -219
  107. package/dist/apps/cli/src/welcome.js +0 -81
  108. package/dist/auth/secure-auth.js +0 -372
  109. package/dist/bundle.js +0 -504
  110. package/dist/commands/analyze.js +0 -390
  111. package/dist/commands/auth-new.js +0 -37
  112. package/dist/commands/auth.js +0 -134
  113. package/dist/commands/config.js +0 -51
  114. package/dist/commands/deploy.js +0 -6
  115. package/dist/commands/init.js +0 -47
  116. package/dist/commands/logout.js +0 -31
  117. package/dist/commands/plugins.js +0 -21
  118. package/dist/commands/status.js +0 -82
  119. package/dist/commands/sync.js +0 -6
  120. package/dist/commands/whoami.js +0 -72
  121. package/dist/components/Dashboard.js +0 -169
  122. package/dist/components/DeltaApp.js +0 -57
  123. package/dist/components/UnifiedManager.js +0 -344
  124. package/dist/core/audit.js +0 -184
  125. package/dist/core/completion.js +0 -294
  126. package/dist/core/contracts.js +0 -6
  127. package/dist/core/engine.js +0 -124
  128. package/dist/core/exit-codes.js +0 -71
  129. package/dist/core/hooks.js +0 -181
  130. package/dist/core/index.js +0 -7
  131. package/dist/core/policy.js +0 -115
  132. package/dist/core/profiles.js +0 -161
  133. package/dist/core/wizard.js +0 -203
  134. package/dist/index.js +0 -387
  135. package/dist/interactive/index.js +0 -11
  136. package/dist/packages/domain/src/constitution/contracts/index.js +0 -43
  137. package/dist/packages/domain/src/constitution/contracts/ts.rules.js +0 -268
  138. package/dist/packages/domain/src/constitution/index.js +0 -139
  139. package/dist/packages/domain/src/constitution/maintainability/index.js +0 -43
  140. package/dist/packages/domain/src/constitution/maintainability/ts.rules.js +0 -344
  141. package/dist/packages/domain/src/constitution/observability/index.js +0 -43
  142. package/dist/packages/domain/src/constitution/observability/ts.rules.js +0 -307
  143. package/dist/packages/domain/src/constitution/performance/index.js +0 -43
  144. package/dist/packages/domain/src/constitution/performance/ts.rules.js +0 -325
  145. package/dist/packages/domain/src/constitution/security/index.js +0 -50
  146. package/dist/packages/domain/src/constitution/security/ts.rules.js +0 -267
  147. package/dist/packages/domain/src/constitution/soc/index.js +0 -43
  148. package/dist/packages/domain/src/constitution/soc/ts.rules.js +0 -360
  149. package/dist/packages/domain/src/contracts/analysis.contract.js +0 -18
  150. package/dist/packages/domain/src/contracts/index.js +0 -7
  151. package/dist/packages/domain/src/contracts/projects.contract.js +0 -18
  152. package/dist/packages/domain/src/control/registry/rules.registry.js +0 -29
  153. package/dist/packages/domain/src/control/schemas/policies.js +0 -6
  154. package/dist/packages/domain/src/core/analysis/discovery.js +0 -163
  155. package/dist/packages/domain/src/core/analysis/engine.contract.js +0 -298
  156. package/dist/packages/domain/src/core/analysis/engine.js +0 -77
  157. package/dist/packages/domain/src/core/analysis/index.js +0 -14
  158. package/dist/packages/domain/src/core/analysis/orchestrator.js +0 -242
  159. package/dist/packages/domain/src/core/comparison/engine.js +0 -29
  160. package/dist/packages/domain/src/core/comparison/index.js +0 -5
  161. package/dist/packages/domain/src/core/documentation/index.js +0 -5
  162. package/dist/packages/domain/src/core/documentation/pipeline.js +0 -41
  163. package/dist/packages/domain/src/core/fs/adapter.js +0 -111
  164. package/dist/packages/domain/src/core/fs/index.js +0 -5
  165. package/dist/packages/domain/src/core/parser/unified-parser.js +0 -166
  166. package/dist/packages/domain/src/index.js +0 -33
  167. package/dist/packages/domain/src/plugin/registry.js +0 -195
  168. package/dist/packages/domain/src/plugin/types.js +0 -6
  169. package/dist/packages/domain/src/ports/analysis.engine.js +0 -7
  170. package/dist/packages/domain/src/ports/audit.logger.js +0 -7
  171. package/dist/packages/domain/src/ports/project.repository.js +0 -7
  172. package/dist/packages/domain/src/rules/index.js +0 -134
  173. package/dist/packages/domain/src/types/analysis.js +0 -6
  174. package/dist/packages/domain/src/types/errors.js +0 -53
  175. package/dist/packages/domain/src/types/fs.js +0 -6
  176. package/dist/packages/domain/src/types/index.js +0 -7
  177. package/dist/plugins/GitStatusPlugin.js +0 -93
  178. package/dist/providers/ai-provider.js +0 -74
  179. package/dist/providers/local-provider.js +0 -304
  180. package/dist/providers/remote-provider.js +0 -100
  181. package/dist/types/api.js +0 -3
  182. package/dist/ui.js +0 -219
  183. package/dist/welcome.js +0 -81
@@ -1,219 +0,0 @@
1
- /**
2
- * Professional UI Components for Delta CLI
3
- */
4
- import chalk from 'chalk';
5
- import ora from 'ora';
6
- import Table from 'cli-table3';
7
- import prompts from 'prompts';
8
- // Icons and symbols
9
- export const icons = {
10
- success: chalk.green('✔'),
11
- error: chalk.red('✖'),
12
- warning: chalk.yellow('⚠'),
13
- info: chalk.blue('ℹ'),
14
- arrow: chalk.cyan('→'),
15
- bullet: chalk.dim('•'),
16
- star: chalk.yellow('★'),
17
- check: chalk.green('✓'),
18
- cross: chalk.red('✗'),
19
- loading: chalk.cyan('⏳'),
20
- rocket: chalk.magenta('🚀'),
21
- lock: chalk.yellow('🔒'),
22
- user: chalk.blue('👤'),
23
- package: chalk.cyan('📦'),
24
- chart: chalk.green('📊'),
25
- folder: chalk.yellow('📁'),
26
- gear: chalk.gray('⚙️'),
27
- link: chalk.blue('🔗'),
28
- sparkles: chalk.yellow('✨'),
29
- dot: chalk.cyan('⏵'),
30
- };
31
- // Spinner management
32
- let currentSpinner = null;
33
- export function startSpinner(text) {
34
- if (currentSpinner) {
35
- currentSpinner.stop();
36
- }
37
- currentSpinner = ora({
38
- text: chalk.cyan(text),
39
- spinner: 'dots',
40
- color: 'cyan',
41
- }).start();
42
- return currentSpinner;
43
- }
44
- export function stopSpinner(success = true, text) {
45
- if (currentSpinner) {
46
- if (success) {
47
- currentSpinner.succeed(text ? chalk.green(text) : undefined);
48
- }
49
- else {
50
- currentSpinner.fail(text ? chalk.red(text) : undefined);
51
- }
52
- currentSpinner = null;
53
- }
54
- }
55
- export function updateSpinnerText(text) {
56
- if (currentSpinner) {
57
- currentSpinner.text = chalk.cyan(text);
58
- }
59
- }
60
- // Headers and sections
61
- export function printHeader(title) {
62
- console.log();
63
- console.log(chalk.bold(chalk.cyan(` ${icons.rocket} ${title}`)));
64
- console.log(chalk.dim(' ' + '─'.repeat(title.length + 4)));
65
- }
66
- export function printSection(title) {
67
- console.log();
68
- console.log(chalk.bold(chalk.white(` ${icons.dot} ${title}`)));
69
- }
70
- export function printSubSection(title) {
71
- console.log(chalk.dim(` ${icons.bullet} ${title}`));
72
- }
73
- // Success/Error/Warning messages
74
- export function printSuccess(message) {
75
- console.log(` ${icons.success} ${chalk.green(message)}`);
76
- }
77
- export function printError(message, details) {
78
- console.log(` ${icons.error} ${chalk.red(message)}`);
79
- if (details) {
80
- console.log(chalk.dim(` ${details}`));
81
- }
82
- }
83
- export function printWarning(message) {
84
- console.log(` ${icons.warning} ${chalk.yellow(message)}`);
85
- }
86
- export function printInfo(message) {
87
- console.log(` ${icons.info} ${chalk.blue(message)}`);
88
- }
89
- // Key-value pairs
90
- export function printKeyValue(key, value, keyColor = chalk.gray) {
91
- console.log(` ${keyColor(key.padEnd(20))} ${chalk.white(value)}`);
92
- }
93
- // Table creation
94
- export function createTable(headers) {
95
- return new Table({
96
- head: headers.map(h => chalk.bold(chalk.cyan(h))),
97
- style: {
98
- head: [],
99
- border: [chalk.dim('gray')],
100
- },
101
- chars: {
102
- top: '─',
103
- 'top-mid': '┬',
104
- 'top-left': '┌',
105
- 'top-right': '┐',
106
- bottom: '─',
107
- 'bottom-mid': '┴',
108
- 'bottom-left': '└',
109
- 'bottom-right': '┘',
110
- left: '│',
111
- 'left-mid': '├',
112
- mid: '─',
113
- 'mid-mid': '┼',
114
- right: '│',
115
- 'right-mid': '┤',
116
- middle: '│',
117
- },
118
- });
119
- }
120
- // Interactive prompts wrapper
121
- export async function confirm(message, initial = true) {
122
- const response = await prompts({
123
- type: 'confirm',
124
- name: 'value',
125
- message: chalk.cyan(message),
126
- initial,
127
- });
128
- return response.value ?? false;
129
- }
130
- export async function select(message, choices) {
131
- const response = await prompts({
132
- type: 'select',
133
- name: 'value',
134
- message: chalk.cyan(message),
135
- choices: choices.map(c => ({
136
- title: c.title,
137
- value: c.value,
138
- description: c.description,
139
- })),
140
- });
141
- return response.value ?? null;
142
- }
143
- export async function input(message, initial, validate) {
144
- const response = await prompts({
145
- type: 'text',
146
- name: 'value',
147
- message: chalk.cyan(message),
148
- initial,
149
- validate,
150
- });
151
- return response.value ?? null;
152
- }
153
- export async function password(message) {
154
- const response = await prompts({
155
- type: 'password',
156
- name: 'value',
157
- message: chalk.cyan(message),
158
- });
159
- return response.value ?? null;
160
- }
161
- // Progress bar for file operations
162
- export function printProgress(current, total, prefix = 'Progress') {
163
- const percentage = Math.round((current / total) * 100);
164
- const filled = Math.round((current / total) * 20);
165
- const empty = 20 - filled;
166
- const bar = chalk.green('█'.repeat(filled)) + chalk.gray('░'.repeat(empty));
167
- process.stdout.write(`\r ${chalk.cyan(prefix)} ${bar} ${chalk.white(`${percentage}%`)} (${current}/${total})`);
168
- if (current === total) {
169
- process.stdout.write('\n');
170
- }
171
- }
172
- // Box drawing
173
- export function printBox(title, lines) {
174
- const maxLength = Math.max(title.length, ...lines.map(l => l.length));
175
- const width = maxLength + 4;
176
- console.log(chalk.cyan(' ┌' + '─'.repeat(width - 2) + '┐'));
177
- console.log(chalk.cyan(` │ ${chalk.bold(title).padEnd(width - 3)}│`));
178
- console.log(chalk.cyan(' ├' + '─'.repeat(width - 2) + '┤'));
179
- lines.forEach(line => {
180
- console.log(chalk.cyan(` │ ${line.padEnd(width - 3)}│`));
181
- });
182
- console.log(chalk.cyan(' └' + '─'.repeat(width - 2) + '┘'));
183
- }
184
- // Format bytes
185
- export function formatBytes(bytes) {
186
- if (bytes === 0)
187
- return '0 B';
188
- const k = 1024;
189
- const sizes = ['B', 'KB', 'MB', 'GB'];
190
- const i = Math.floor(Math.log(bytes) / Math.log(k));
191
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
192
- }
193
- // Format duration
194
- export function formatDuration(ms) {
195
- if (ms < 1000)
196
- return `${ms}ms`;
197
- if (ms < 60000)
198
- return `${(ms / 1000).toFixed(1)}s`;
199
- return `${(ms / 60000).toFixed(1)}m`;
200
- }
201
- // Command hint
202
- export function printCommandHint(command, description) {
203
- console.log(` ${chalk.dim('$')} ${chalk.cyan(command)} ${chalk.gray(description)}`);
204
- }
205
- // Divider
206
- export function printDivider() {
207
- console.log(chalk.dim(' ' + '─'.repeat(60)));
208
- }
209
- // Welcome message
210
- export function printWelcome() {
211
- console.log();
212
- console.log(chalk.cyan(' ╭──────────────────────────────────────────────╮'));
213
- console.log(chalk.cyan(' │') + ' ' + chalk.bold(chalk.magenta('🚀 Delta CLI')) + chalk.dim(' - Code Analysis & Documentation ') + chalk.cyan('│'));
214
- console.log(chalk.cyan(' ├──────────────────────────────────────────────┤'));
215
- console.log(chalk.cyan(' │') + ' ' + chalk.gray('Local-first analysis with cloud power ') + chalk.cyan('│'));
216
- console.log(chalk.cyan(' ╰──────────────────────────────────────────────╯'));
217
- console.log();
218
- }
219
- //# sourceMappingURL=ui.js.map
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env node
2
- import gradient from 'gradient-string';
3
- import figlet from 'figlet';
4
- import updateNotifier from 'update-notifier';
5
- import chalk from 'chalk';
6
- import { readFileSync } from 'fs';
7
- import { fileURLToPath } from 'url';
8
- import { dirname, join } from 'path';
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
- // Read package.json for version info
12
- const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
13
- // Check for updates
14
- const notifier = updateNotifier({
15
- pkg,
16
- updateCheckInterval: 1000 * 60 * 60 // 1 hour
17
- });
18
- // Define gradient themes
19
- export const gradients = {
20
- delta: gradient(['#00d4ff', '#7b2cbf', '#ff006e']),
21
- cyber: gradient(['#00f5ff', '#0080ff', '#8000ff']),
22
- sunset: gradient(['#ff4e50', '#fca311', '#e85d04']),
23
- neon: gradient(['#39ff14', '#00ffff', '#ff00ff']),
24
- ocean: gradient(['#0066ff', '#00ccff', '#66ffff']),
25
- fire: gradient(['#ff4e00', '#ff9500', '#ffcc00']),
26
- };
27
- // Print animated logo
28
- export function printLogo(variant = 'delta') {
29
- const text = figlet.textSync('DELTA', {
30
- font: 'Big Money-nw',
31
- horizontalLayout: 'default',
32
- verticalLayout: 'default',
33
- });
34
- console.log('\n' + gradients[variant](text) + '\n');
35
- }
36
- // Print minimal logo
37
- export function printMinimalLogo() {
38
- const text = figlet.textSync('Δ', {
39
- font: 'ANSI Shadow',
40
- horizontalLayout: 'default',
41
- });
42
- console.log(gradients.delta(text));
43
- }
44
- // Print welcome screen
45
- export function printWelcome() {
46
- console.clear();
47
- printLogo();
48
- console.log(chalk.dim(' ═══════════════════════════════════════════════════════════════'));
49
- console.log();
50
- console.log(chalk.white.bold(' 🚀 Delta CLI v2.0') + chalk.gray(' — Next-gen code analysis & documentation'));
51
- console.log();
52
- console.log(chalk.gray(' Local-first architecture with ') + chalk.cyan('cloud power') + chalk.gray(' & ') + chalk.magenta('AI intelligence'));
53
- console.log();
54
- console.log(chalk.dim(' ═══════════════════════════════════════════════════════════════'));
55
- console.log();
56
- // Update notification
57
- if (notifier.update) {
58
- console.log(chalk.yellow.bold(' ⚡ Update Available!'));
59
- console.log(chalk.gray(` ${notifier.update.current} → ${notifier.update.latest}`));
60
- console.log(chalk.cyan(` Run: npm install -g ${pkg.name}`));
61
- console.log();
62
- }
63
- }
64
- // Print tips
65
- export function printTips() {
66
- const tips = [
67
- { cmd: 'delta login', desc: 'Authenticate with your account' },
68
- { cmd: 'delta analyze', desc: 'Run code analysis on current project' },
69
- { cmd: 'delta dashboard', desc: 'Open interactive dashboard' },
70
- { cmd: 'delta --help', desc: 'Show all available commands' },
71
- ];
72
- console.log(chalk.bold.cyan(' Quick Start:'));
73
- console.log();
74
- tips.forEach(({ cmd, desc }) => {
75
- console.log(chalk.gray(' • ') + chalk.cyan(cmd) + chalk.gray(` — ${desc}`));
76
- });
77
- console.log();
78
- console.log(chalk.dim(' Press ') + chalk.bold('Ctrl+T') + chalk.dim(' for variants • ') + chalk.bold('Tab') + chalk.dim(' for agents • ') + chalk.bold('Ctrl+P') + chalk.dim(' for commands'));
79
- console.log();
80
- }
81
- //# sourceMappingURL=welcome.js.map
@@ -1,372 +0,0 @@
1
- /**
2
- * Secure Authentication System with OAuth2 + Keychain Integration
3
- * Features:
4
- * - OAuth2 PKCE flow
5
- * - Secure token storage in OS keychain
6
- * - Automatic token refresh
7
- * - Session management
8
- * - PAT (Personal Access Token) support for CI/CD
9
- */
10
- import * as fs from 'fs/promises';
11
- import * as path from 'path';
12
- import * as os from 'os';
13
- import fetch from 'node-fetch';
14
- import open from 'open';
15
- import { createServer } from 'http';
16
- import { URL } from 'url';
17
- import crypto from 'crypto';
18
- import chalk from 'chalk';
19
- import { printSuccess, printError, printInfo, printWarning, startSpinner, stopSpinner } from '../ui.js';
20
- const CONFIG_DIR = path.join(os.homedir(), '.delta');
21
- const TOKEN_FILE = path.join(CONFIG_DIR, 'tokens.enc');
22
- const KEY_FILE = path.join(CONFIG_DIR, '.key');
23
- // Derive encryption key from machine-specific data
24
- async function getEncryptionKey() {
25
- try {
26
- const keyData = await fs.readFile(KEY_FILE, 'utf-8').catch(() => null);
27
- if (keyData) {
28
- return Buffer.from(keyData, 'hex');
29
- }
30
- }
31
- catch {
32
- // File doesn't exist, generate new key
33
- }
34
- const machineId = `${os.userInfo().username}@${os.hostname()}`;
35
- const salt = 'delta-cli-v2-fixed-salt';
36
- const key = crypto.pbkdf2Sync(machineId, salt, 100000, 32, 'sha256');
37
- await fs.mkdir(CONFIG_DIR, { recursive: true });
38
- await fs.writeFile(KEY_FILE, key.toString('hex'), { mode: 0o600 });
39
- return key;
40
- }
41
- // Encrypt data
42
- async function encrypt(data) {
43
- const key = await getEncryptionKey();
44
- const iv = crypto.randomBytes(16);
45
- const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
46
- let encrypted = cipher.update(data, 'utf-8', 'hex');
47
- encrypted += cipher.final('hex');
48
- const authTag = cipher.getAuthTag();
49
- return `${iv.toString('hex')}:${authTag.toString('hex')}:${encrypted}`;
50
- }
51
- // Decrypt data
52
- async function decrypt(encryptedData) {
53
- try {
54
- const key = await getEncryptionKey();
55
- const parts = encryptedData.split(':');
56
- if (parts.length !== 3)
57
- return null;
58
- const iv = Buffer.from(parts[0], 'hex');
59
- const authTag = Buffer.from(parts[1], 'hex');
60
- const encrypted = parts[2];
61
- const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
62
- decipher.setAuthTag(authTag);
63
- let decrypted = decipher.update(encrypted, 'hex', 'utf-8');
64
- decrypted += decipher.final('utf-8');
65
- return decrypted;
66
- }
67
- catch {
68
- return null;
69
- }
70
- }
71
- // PKCE Code Generator
72
- function generatePKCE() {
73
- const verifier = crypto.randomBytes(32).toString('base64url');
74
- const challenge = crypto
75
- .createHash('sha256')
76
- .update(verifier)
77
- .digest('base64url');
78
- return { verifier, challenge };
79
- }
80
- // Secure Token Storage using encrypted file
81
- export class SecureTokenStore {
82
- static async saveTokens(tokens) {
83
- await fs.mkdir(CONFIG_DIR, { recursive: true });
84
- const data = JSON.stringify({
85
- access: tokens.access || null,
86
- refresh: tokens.refresh || null,
87
- updatedAt: new Date().toISOString(),
88
- });
89
- const encrypted = await encrypt(data);
90
- await fs.writeFile(TOKEN_FILE, encrypted, { mode: 0o600 });
91
- }
92
- static async loadTokens() {
93
- try {
94
- const encrypted = await fs.readFile(TOKEN_FILE, 'utf-8');
95
- const decrypted = await decrypt(encrypted);
96
- if (!decrypted)
97
- return { access: null, refresh: null };
98
- const data = JSON.parse(decrypted);
99
- return {
100
- access: data.access || null,
101
- refresh: data.refresh || null,
102
- };
103
- }
104
- catch {
105
- return { access: null, refresh: null };
106
- }
107
- }
108
- static async saveAccessToken(token) {
109
- const tokens = await this.loadTokens();
110
- await this.saveTokens({ access: token, refresh: tokens.refresh ?? undefined });
111
- }
112
- static async getAccessToken() {
113
- const tokens = await this.loadTokens();
114
- return tokens.access;
115
- }
116
- static async saveRefreshToken(token) {
117
- const tokens = await this.loadTokens();
118
- await this.saveTokens({ refresh: token, access: tokens.access ?? undefined });
119
- }
120
- static async getRefreshToken() {
121
- const tokens = await this.loadTokens();
122
- return tokens.refresh;
123
- }
124
- static async clearTokens() {
125
- try {
126
- await fs.unlink(TOKEN_FILE);
127
- }
128
- catch {
129
- // File may not exist
130
- }
131
- }
132
- static async hasTokens() {
133
- const token = await this.getAccessToken();
134
- return !!token;
135
- }
136
- }
137
- // OAuth2 Flow Handler - Uses configurable API URL for local development
138
- export async function startOAuthFlow(method = 'oauth') {
139
- startSpinner('Starting OAuth2 authentication flow...');
140
- try {
141
- // Get API URL from environment or use default
142
- const apiUrl = process.env.DELTA_API_URL || 'http://localhost:3000';
143
- const { verifier, challenge } = generatePKCE();
144
- const state = crypto.randomBytes(16).toString('hex');
145
- // Start local server FIRST to capture callback and get actual port
146
- const { authCode, redirectUri } = await new Promise((resolve, reject) => {
147
- const server = createServer(async (req, res) => {
148
- const url = new URL(req.url || '/', `http://localhost:${redirectPort}`);
149
- if (url.pathname === '/callback') {
150
- const code = url.searchParams.get('code');
151
- const returnedState = url.searchParams.get('state');
152
- const error = url.searchParams.get('error');
153
- if (error) {
154
- res.writeHead(400, { 'Content-Type': 'text/html' });
155
- res.end(`<html><body><h1>❌ Authentication Failed</h1><p>${error}</p></body></html>`);
156
- reject(new Error(error));
157
- server.close();
158
- return;
159
- }
160
- if (!code || returnedState !== state) {
161
- res.writeHead(400, { 'Content-Type': 'text/html' });
162
- res.end(`<html><body><h1>❌ Invalid Response</h1></body></html>`);
163
- reject(new Error('Invalid OAuth response'));
164
- server.close();
165
- return;
166
- }
167
- res.writeHead(200, { 'Content-Type': 'text/html' });
168
- res.end(`<html><body style="text-align:center;padding:50px;"><h1>✓ Successfully Signed In!</h1><p>You can close this window.</p></body></html>`);
169
- const address = server.address();
170
- const actualPort = typeof address === 'object' && address ? address.port : 3456;
171
- resolve({ authCode: code, redirectUri: `http://localhost:${actualPort}/callback` });
172
- server.close();
173
- }
174
- });
175
- let redirectPort = 3456;
176
- // Try to listen on port 3456
177
- server.listen(3456, '127.0.0.1', () => {
178
- console.log(chalk.dim(` Waiting for authentication on port ${redirectPort}...`));
179
- });
180
- // Handle port in use error by trying random port
181
- server.on('error', (err) => {
182
- if (err.code === 'EADDRINUSE') {
183
- printWarning('Port 3456 is busy, trying alternative port...');
184
- redirectPort = 0; // Let OS assign
185
- server.listen(0, '127.0.0.1', () => {
186
- const address = server.address();
187
- const actualPort = typeof address === 'object' && address ? address.port : 3456;
188
- redirectPort = actualPort;
189
- console.log(chalk.dim(` Waiting for authentication on port ${actualPort}...`));
190
- });
191
- }
192
- else {
193
- reject(err);
194
- }
195
- });
196
- // Timeout after 5 minutes
197
- setTimeout(() => {
198
- server.close();
199
- reject(new Error('Authentication timeout'));
200
- }, 5 * 60 * 1000);
201
- });
202
- // NOW build OAuth URL with correct redirect_uri
203
- const oauthUrl = new URL(`${apiUrl}/api/auth/authorize`);
204
- oauthUrl.searchParams.set('response_type', 'code');
205
- oauthUrl.searchParams.set('client_id', 'delta-cli');
206
- oauthUrl.searchParams.set('redirect_uri', redirectUri);
207
- oauthUrl.searchParams.set('code_challenge', challenge);
208
- oauthUrl.searchParams.set('code_challenge_method', 'S256');
209
- oauthUrl.searchParams.set('state', state);
210
- oauthUrl.searchParams.set('scope', 'read write analyze');
211
- if (method === 'github') {
212
- oauthUrl.searchParams.set('provider', 'github');
213
- }
214
- else if (method === 'google') {
215
- oauthUrl.searchParams.set('provider', 'google');
216
- }
217
- stopSpinner(true, 'OAuth server ready');
218
- // Open browser with correct URL
219
- printInfo(`Opening browser for authentication...`);
220
- printInfo(`Full URL: ${oauthUrl.toString()}`);
221
- await open(oauthUrl.toString());
222
- // Wait for authCode (already resolved above)
223
- // Exchange code for tokens
224
- startSpinner('Exchanging authorization code...');
225
- const tokenResponse = await fetch(`${apiUrl}/api/auth/token`, {
226
- method: 'POST',
227
- headers: { 'Content-Type': 'application/json' },
228
- body: JSON.stringify({
229
- grant_type: 'authorization_code',
230
- code: authCode,
231
- redirect_uri: redirectUri,
232
- client_id: 'delta-cli',
233
- code_verifier: verifier,
234
- }),
235
- });
236
- if (!tokenResponse.ok) {
237
- throw new Error('Failed to exchange authorization code');
238
- }
239
- const tokens = await tokenResponse.json();
240
- // Store tokens securely
241
- await SecureTokenStore.saveAccessToken(tokens.access_token);
242
- await SecureTokenStore.saveRefreshToken(tokens.refresh_token);
243
- stopSpinner(true, 'Authentication successful!');
244
- printSuccess('Successfully authenticated with Delta Cloud');
245
- printInfo(`Token expires in ${tokens.expires_in} seconds`);
246
- return true;
247
- }
248
- catch (error) {
249
- stopSpinner(false, 'Authentication failed');
250
- printError('OAuth2 authentication failed', error.message);
251
- return false;
252
- }
253
- }
254
- // PAT Authentication for CI/CD - Uses configurable API URL
255
- export async function authenticateWithPAT(token) {
256
- startSpinner('Validating Personal Access Token...');
257
- try {
258
- const apiUrl = process.env.DELTA_API_URL || 'http://localhost:3000';
259
- // Validate token
260
- const response = await fetch(`${apiUrl}/api/auth/verify`, {
261
- headers: {
262
- 'Authorization': `Bearer ${token}`,
263
- },
264
- });
265
- if (!response.ok) {
266
- throw new Error('Invalid token');
267
- }
268
- const data = await response.json();
269
- // Store token
270
- await SecureTokenStore.saveAccessToken(token);
271
- stopSpinner(true, 'Token validated');
272
- printSuccess(`Authenticated as ${data.user.email}`);
273
- return true;
274
- }
275
- catch (error) {
276
- stopSpinner(false, 'Token validation failed');
277
- printError('PAT authentication failed', error.message);
278
- return false;
279
- }
280
- }
281
- // Token Refresh - Uses configurable API URL
282
- export async function refreshAccessToken() {
283
- const refreshToken = await SecureTokenStore.getRefreshToken();
284
- if (!refreshToken) {
285
- printError('No refresh token available');
286
- return false;
287
- }
288
- try {
289
- const apiUrl = process.env.DELTA_API_URL || 'http://localhost:3000';
290
- const response = await fetch(`${apiUrl}/api/auth/refresh`, {
291
- method: 'POST',
292
- headers: { 'Content-Type': 'application/json' },
293
- body: JSON.stringify({
294
- grant_type: 'refresh_token',
295
- refresh_token: refreshToken,
296
- client_id: 'delta-cli',
297
- }),
298
- });
299
- if (!response.ok) {
300
- throw new Error('Token refresh failed');
301
- }
302
- const tokens = await response.json();
303
- await SecureTokenStore.saveAccessToken(tokens.access_token);
304
- if (tokens.refresh_token) {
305
- await SecureTokenStore.saveRefreshToken(tokens.refresh_token);
306
- }
307
- return true;
308
- }
309
- catch (error) {
310
- printError('Failed to refresh token', error.message);
311
- return false;
312
- }
313
- }
314
- // Logout
315
- export async function logout() {
316
- startSpinner('Clearing credentials...');
317
- try {
318
- await SecureTokenStore.clearTokens();
319
- stopSpinner(true, 'Logged out');
320
- printSuccess('Successfully logged out');
321
- }
322
- catch (error) {
323
- stopSpinner(false, 'Logout failed');
324
- printError('Failed to clear credentials', error.message);
325
- }
326
- }
327
- // Auth Status - Uses configurable API URL
328
- export async function getAuthStatus() {
329
- const token = await SecureTokenStore.getAccessToken();
330
- if (!token) {
331
- return { authenticated: false };
332
- }
333
- try {
334
- const apiUrl = process.env.DELTA_API_URL || 'http://localhost:3000';
335
- const response = await fetch(`${apiUrl}/api/auth/me`, {
336
- headers: {
337
- 'Authorization': `Bearer ${token}`,
338
- },
339
- });
340
- if (!response.ok) {
341
- // Try to refresh token
342
- const refreshed = await refreshAccessToken();
343
- if (!refreshed) {
344
- return { authenticated: false };
345
- }
346
- // Retry with new token
347
- const newToken = await SecureTokenStore.getAccessToken();
348
- const retryResponse = await fetch(`${apiUrl}/api/auth/me`, {
349
- headers: {
350
- 'Authorization': `Bearer ${newToken}`,
351
- },
352
- });
353
- if (!retryResponse.ok) {
354
- return { authenticated: false };
355
- }
356
- const userData = await retryResponse.json();
357
- return {
358
- authenticated: true,
359
- user: userData,
360
- };
361
- }
362
- const userData = await response.json();
363
- return {
364
- authenticated: true,
365
- user: userData,
366
- };
367
- }
368
- catch {
369
- return { authenticated: false };
370
- }
371
- }
372
- //# sourceMappingURL=secure-auth.js.map