@nordsym/apiclaw 1.3.7 → 1.3.9

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 (203) hide show
  1. package/README.md +436 -200
  2. package/convex/_generated/api.d.ts +4 -0
  3. package/convex/agents.ts +403 -0
  4. package/convex/directCall.ts +80 -0
  5. package/convex/earnProgress.ts +753 -0
  6. package/convex/logs.ts +17 -0
  7. package/convex/providerKeys.ts +82 -2
  8. package/convex/schema.ts +71 -2
  9. package/convex/workspaces.ts +84 -2
  10. package/dist/adapters/base.d.ts +112 -0
  11. package/dist/adapters/base.d.ts.map +1 -0
  12. package/dist/adapters/base.js +247 -0
  13. package/dist/adapters/base.js.map +1 -0
  14. package/dist/adapters/claude-desktop.d.ts +12 -0
  15. package/dist/adapters/claude-desktop.d.ts.map +1 -0
  16. package/dist/adapters/claude-desktop.js +36 -0
  17. package/dist/adapters/claude-desktop.js.map +1 -0
  18. package/dist/adapters/cline.d.ts +20 -0
  19. package/dist/adapters/cline.d.ts.map +1 -0
  20. package/dist/adapters/cline.js +77 -0
  21. package/dist/adapters/cline.js.map +1 -0
  22. package/dist/adapters/continue.d.ts +26 -0
  23. package/dist/adapters/continue.d.ts.map +1 -0
  24. package/dist/adapters/continue.js +68 -0
  25. package/dist/adapters/continue.js.map +1 -0
  26. package/dist/adapters/cursor.d.ts +12 -0
  27. package/dist/adapters/cursor.d.ts.map +1 -0
  28. package/dist/adapters/cursor.js +38 -0
  29. package/dist/adapters/cursor.js.map +1 -0
  30. package/dist/adapters/custom.d.ts +47 -0
  31. package/dist/adapters/custom.d.ts.map +1 -0
  32. package/dist/adapters/custom.js +146 -0
  33. package/dist/adapters/custom.js.map +1 -0
  34. package/dist/adapters/detect.d.ts +69 -0
  35. package/dist/adapters/detect.d.ts.map +1 -0
  36. package/dist/adapters/detect.js +158 -0
  37. package/dist/adapters/detect.js.map +1 -0
  38. package/dist/adapters/index.d.ts +21 -0
  39. package/dist/adapters/index.d.ts.map +1 -0
  40. package/dist/adapters/index.js +23 -0
  41. package/dist/adapters/index.js.map +1 -0
  42. package/dist/adapters/windsurf.d.ts +12 -0
  43. package/dist/adapters/windsurf.d.ts.map +1 -0
  44. package/dist/adapters/windsurf.js +39 -0
  45. package/dist/adapters/windsurf.js.map +1 -0
  46. package/dist/bin.d.ts +9 -0
  47. package/dist/bin.d.ts.map +1 -0
  48. package/dist/bin.js +19 -0
  49. package/dist/bin.js.map +1 -0
  50. package/dist/cli/commands/doctor.d.ts +34 -0
  51. package/dist/cli/commands/doctor.d.ts.map +1 -0
  52. package/dist/cli/commands/doctor.js +312 -0
  53. package/dist/cli/commands/doctor.js.map +1 -0
  54. package/dist/cli/commands/index.d.ts +9 -0
  55. package/dist/cli/commands/index.d.ts.map +1 -0
  56. package/dist/cli/commands/index.js +9 -0
  57. package/dist/cli/commands/index.js.map +1 -0
  58. package/dist/cli/commands/mcp-install.d.ts +14 -0
  59. package/dist/cli/commands/mcp-install.d.ts.map +1 -0
  60. package/dist/cli/commands/mcp-install.js +246 -0
  61. package/dist/cli/commands/mcp-install.js.map +1 -0
  62. package/dist/cli/commands/restore.d.ts +50 -0
  63. package/dist/cli/commands/restore.d.ts.map +1 -0
  64. package/dist/cli/commands/restore.js +260 -0
  65. package/dist/cli/commands/restore.js.map +1 -0
  66. package/dist/cli/commands/setup.d.ts +19 -0
  67. package/dist/cli/commands/setup.d.ts.map +1 -0
  68. package/dist/cli/commands/setup.js +206 -0
  69. package/dist/cli/commands/setup.js.map +1 -0
  70. package/dist/cli/commands/uninstall.d.ts +37 -0
  71. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  72. package/dist/cli/commands/uninstall.js +189 -0
  73. package/dist/cli/commands/uninstall.js.map +1 -0
  74. package/dist/cli/index.d.ts +7 -0
  75. package/dist/cli/index.d.ts.map +1 -0
  76. package/dist/cli/index.js +105 -0
  77. package/dist/cli/index.js.map +1 -0
  78. package/dist/discovery.d.ts +6 -2
  79. package/dist/discovery.d.ts.map +1 -1
  80. package/dist/discovery.js +296 -2
  81. package/dist/discovery.js.map +1 -1
  82. package/dist/enterprise/env.d.ts +56 -0
  83. package/dist/enterprise/env.d.ts.map +1 -0
  84. package/dist/enterprise/env.js +124 -0
  85. package/dist/enterprise/env.js.map +1 -0
  86. package/dist/enterprise/index.d.ts +7 -0
  87. package/dist/enterprise/index.d.ts.map +1 -0
  88. package/dist/enterprise/index.js +7 -0
  89. package/dist/enterprise/index.js.map +1 -0
  90. package/dist/enterprise/script-generator.d.ts +32 -0
  91. package/dist/enterprise/script-generator.d.ts.map +1 -0
  92. package/dist/enterprise/script-generator.js +461 -0
  93. package/dist/enterprise/script-generator.js.map +1 -0
  94. package/dist/execute.d.ts +21 -0
  95. package/dist/execute.d.ts.map +1 -1
  96. package/dist/execute.js +231 -0
  97. package/dist/execute.js.map +1 -1
  98. package/dist/index.js +79 -7
  99. package/dist/index.js.map +1 -1
  100. package/dist/stripe.d.ts +1 -1
  101. package/dist/stripe.js +1 -1
  102. package/dist/stripe.js.map +1 -1
  103. package/dist/types.d.ts +29 -0
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/ui/colors.d.ts +111 -0
  106. package/dist/ui/colors.d.ts.map +1 -0
  107. package/dist/ui/colors.js +185 -0
  108. package/dist/ui/colors.js.map +1 -0
  109. package/dist/ui/errors.d.ts +69 -0
  110. package/dist/ui/errors.d.ts.map +1 -0
  111. package/dist/ui/errors.js +334 -0
  112. package/dist/ui/errors.js.map +1 -0
  113. package/dist/ui/index.d.ts +10 -0
  114. package/dist/ui/index.d.ts.map +1 -0
  115. package/dist/ui/index.js +14 -0
  116. package/dist/ui/index.js.map +1 -0
  117. package/dist/ui/prompts.d.ts +88 -0
  118. package/dist/ui/prompts.d.ts.map +1 -0
  119. package/dist/ui/prompts.js +295 -0
  120. package/dist/ui/prompts.js.map +1 -0
  121. package/dist/ui/spinner.d.ts +112 -0
  122. package/dist/ui/spinner.d.ts.map +1 -0
  123. package/dist/ui/spinner.js +229 -0
  124. package/dist/ui/spinner.js.map +1 -0
  125. package/dist/utils/backup.d.ts +48 -0
  126. package/dist/utils/backup.d.ts.map +1 -0
  127. package/dist/utils/backup.js +182 -0
  128. package/dist/utils/backup.js.map +1 -0
  129. package/dist/utils/config.d.ts +80 -0
  130. package/dist/utils/config.d.ts.map +1 -0
  131. package/dist/utils/config.js +221 -0
  132. package/dist/utils/config.js.map +1 -0
  133. package/dist/utils/os.d.ts +45 -0
  134. package/dist/utils/os.d.ts.map +1 -0
  135. package/dist/utils/os.js +106 -0
  136. package/dist/utils/os.js.map +1 -0
  137. package/dist/utils/paths.d.ts +38 -0
  138. package/dist/utils/paths.d.ts.map +1 -0
  139. package/dist/utils/paths.js +160 -0
  140. package/dist/utils/paths.js.map +1 -0
  141. package/docs/PRD-BILLING.md +226 -0
  142. package/docs/PRD-EARN-SYSTEM.md +261 -0
  143. package/docs/PRD-MCP-AUTO-SETUP.md +623 -0
  144. package/docs/enterprise-deployment.md +728 -0
  145. package/landing/next.config.mjs +14 -0
  146. package/landing/public/book/index.html +24 -5
  147. package/landing/public/demo-product.jpg +0 -0
  148. package/landing/public/stats.json +4 -2
  149. package/landing/scripts/generate-stats.js +13 -0
  150. package/landing/src/app/api/og/route.tsx +1 -3
  151. package/landing/src/app/api/workspace-auth/magic-link/route.ts +6 -3
  152. package/landing/src/app/auth/verify/page.tsx +11 -4
  153. package/landing/src/app/docs/page.tsx +1 -1
  154. package/landing/src/app/join/page.tsx +49 -0
  155. package/landing/src/app/layout.tsx +1 -1
  156. package/landing/src/app/login/page.tsx +7 -1
  157. package/landing/src/app/page.tsx +50 -38
  158. package/landing/src/app/providers/register/page.tsx +1 -1
  159. package/landing/src/app/workspace/page.tsx +484 -806
  160. package/landing/src/components/CheckoutButton.tsx +1 -1
  161. package/landing/src/components/EarnCreditsTab.tsx +842 -0
  162. package/landing/src/components/HeroTabs.tsx +2 -2
  163. package/landing/src/components/demo/PhoneDemo.tsx +423 -0
  164. package/landing/src/components/demo/index.ts +1 -0
  165. package/landing/src/lib/stats.json +3 -1
  166. package/landing/tailwind.config.ts +10 -0
  167. package/package.json +9 -2
  168. package/src/adapters/base.ts +363 -0
  169. package/src/adapters/claude-desktop.ts +41 -0
  170. package/src/adapters/cline.ts +88 -0
  171. package/src/adapters/continue.ts +91 -0
  172. package/src/adapters/cursor.ts +43 -0
  173. package/src/adapters/custom.ts +188 -0
  174. package/src/adapters/detect.ts +202 -0
  175. package/src/adapters/index.ts +47 -0
  176. package/src/adapters/windsurf.ts +44 -0
  177. package/src/bin.ts +19 -0
  178. package/src/cli/commands/doctor.ts +367 -0
  179. package/src/cli/commands/index.ts +9 -0
  180. package/src/cli/commands/mcp-install.ts +291 -0
  181. package/src/cli/commands/restore.ts +333 -0
  182. package/src/cli/commands/setup.ts +276 -0
  183. package/src/cli/commands/uninstall.ts +240 -0
  184. package/src/cli/index.ts +116 -0
  185. package/src/discovery.ts +328 -3
  186. package/src/enterprise/env.ts +156 -0
  187. package/src/enterprise/index.ts +7 -0
  188. package/src/enterprise/script-generator.ts +481 -0
  189. package/src/execute.ts +256 -0
  190. package/src/index.ts +85 -7
  191. package/src/stripe.ts +1 -1
  192. package/src/types.ts +32 -0
  193. package/src/ui/colors.ts +219 -0
  194. package/src/ui/errors.ts +394 -0
  195. package/src/ui/index.ts +17 -0
  196. package/src/ui/prompts.ts +390 -0
  197. package/src/ui/spinner.ts +325 -0
  198. package/src/utils/backup.ts +224 -0
  199. package/src/utils/config.ts +315 -0
  200. package/src/utils/os.ts +124 -0
  201. package/src/utils/paths.ts +203 -0
  202. package/STATUS.md +0 -160
  203. package/landing/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,390 @@
1
+ /**
2
+ * APIClaw MCP Auto-Setup - Interactive Prompts
3
+ *
4
+ * Inquirer-based prompts for the --wizard mode.
5
+ * Provides a guided, interactive setup experience.
6
+ */
7
+
8
+ import inquirer from 'inquirer';
9
+ import { colors, icons, header, box, codeBlock, added, bulletList } from './colors.js';
10
+
11
+ /**
12
+ * Detected client information
13
+ */
14
+ export interface DetectedClient {
15
+ id: string;
16
+ name: string;
17
+ detected: boolean;
18
+ configPath: string;
19
+ alreadyConfigured: boolean;
20
+ }
21
+
22
+ /**
23
+ * Configuration change preview
24
+ */
25
+ export interface ConfigChange {
26
+ clientId: string;
27
+ clientName: string;
28
+ configPath: string;
29
+ action: 'create' | 'update' | 'skip';
30
+ diff?: string;
31
+ }
32
+
33
+ /**
34
+ * Wizard result
35
+ */
36
+ export interface WizardResult {
37
+ selectedClients: string[];
38
+ workspace?: string;
39
+ confirmed: boolean;
40
+ dryRun: boolean;
41
+ }
42
+
43
+ /**
44
+ * Display welcome banner
45
+ */
46
+ export function showWelcome(): void {
47
+ console.log(header('APIClaw MCP Auto-Setup'));
48
+ console.log(colors.secondary('Configure APIClaw as an MCP server across your AI coding assistants.\n'));
49
+ }
50
+
51
+ /**
52
+ * Prompt for client selection
53
+ */
54
+ export async function selectClients(clients: DetectedClient[]): Promise<string[]> {
55
+ console.log(colors.info(`${icons.search} Detected MCP clients:\n`));
56
+
57
+ // Show detection results
58
+ for (const client of clients) {
59
+ if (client.detected) {
60
+ const status = client.alreadyConfigured
61
+ ? colors.warning(`(already configured)`)
62
+ : colors.success('(detected)');
63
+ console.log(` ${icons.success} ${colors.highlight(client.name)} ${status}`);
64
+ console.log(colors.muted(` ${client.configPath}`));
65
+ } else {
66
+ console.log(` ${icons.pending} ${colors.muted(client.name)} ${colors.muted('(not found)')}`);
67
+ }
68
+ }
69
+ console.log();
70
+
71
+ const detectedClients = clients.filter(c => c.detected);
72
+
73
+ if (detectedClients.length === 0) {
74
+ console.log(colors.warning('No MCP clients detected on this system.'));
75
+ console.log(colors.secondary('\nYou can still configure a custom path.\n'));
76
+ }
77
+
78
+ const choices = clients.map(client => ({
79
+ name: `${client.name}${client.detected ? '' : ' (not detected)'}${client.alreadyConfigured ? ' ⚠️ already configured' : ''}`,
80
+ value: client.id,
81
+ checked: client.detected && !client.alreadyConfigured,
82
+ disabled: !client.detected && client.id !== 'custom' ? 'Not installed' : false,
83
+ }));
84
+
85
+ // Add custom option
86
+ choices.push({
87
+ name: 'Custom config path...',
88
+ value: 'custom',
89
+ checked: false,
90
+ disabled: false,
91
+ });
92
+
93
+ const { selected } = await inquirer.prompt<{ selected: string[] }>([
94
+ {
95
+ type: 'checkbox',
96
+ name: 'selected',
97
+ message: 'Which clients do you want to configure?',
98
+ choices,
99
+ validate: (answer: string[]) => {
100
+ if (answer.length === 0) {
101
+ return 'Please select at least one client.';
102
+ }
103
+ return true;
104
+ },
105
+ },
106
+ ]);
107
+
108
+ return selected;
109
+ }
110
+
111
+ /**
112
+ * Prompt for custom config path
113
+ */
114
+ export async function promptCustomPath(): Promise<string> {
115
+ const { customPath } = await inquirer.prompt<{ customPath: string }>([
116
+ {
117
+ type: 'input',
118
+ name: 'customPath',
119
+ message: 'Enter the path to your MCP config file:',
120
+ validate: (input: string) => {
121
+ if (!input.trim()) {
122
+ return 'Please enter a valid path.';
123
+ }
124
+ if (!input.endsWith('.json')) {
125
+ return 'Config file should be a .json file.';
126
+ }
127
+ return true;
128
+ },
129
+ },
130
+ ]);
131
+
132
+ return customPath;
133
+ }
134
+
135
+ /**
136
+ * Prompt for workspace ID
137
+ */
138
+ export async function promptWorkspace(): Promise<string | undefined> {
139
+ const { hasWorkspace } = await inquirer.prompt<{ hasWorkspace: boolean }>([
140
+ {
141
+ type: 'confirm',
142
+ name: 'hasWorkspace',
143
+ message: 'Do you have an APIClaw workspace ID to link?',
144
+ default: false,
145
+ },
146
+ ]);
147
+
148
+ if (!hasWorkspace) {
149
+ return undefined;
150
+ }
151
+
152
+ const { workspace } = await inquirer.prompt<{ workspace: string }>([
153
+ {
154
+ type: 'input',
155
+ name: 'workspace',
156
+ message: 'Enter your workspace ID:',
157
+ validate: (input: string) => {
158
+ if (!input.trim()) {
159
+ return 'Please enter a workspace ID.';
160
+ }
161
+ if (!input.startsWith('ws_')) {
162
+ return 'Workspace ID should start with "ws_"';
163
+ }
164
+ return true;
165
+ },
166
+ },
167
+ ]);
168
+
169
+ return workspace;
170
+ }
171
+
172
+ /**
173
+ * Show preview of changes and confirm
174
+ */
175
+ export async function confirmChanges(
176
+ changes: ConfigChange[],
177
+ options: { dryRun?: boolean } = {}
178
+ ): Promise<boolean> {
179
+ console.log(header('Review Changes'));
180
+
181
+ for (const change of changes) {
182
+ const actionLabel = {
183
+ create: colors.success('CREATE'),
184
+ update: colors.warning('UPDATE'),
185
+ skip: colors.muted('SKIP'),
186
+ }[change.action];
187
+
188
+ console.log(`${actionLabel} ${colors.highlight(change.clientName)}`);
189
+ console.log(colors.muted(` ${change.configPath}\n`));
190
+
191
+ if (change.diff) {
192
+ console.log(codeBlock(change.diff));
193
+ console.log();
194
+ }
195
+ }
196
+
197
+ if (options.dryRun) {
198
+ console.log(box(
199
+ colors.info('Dry-run mode: No changes will be made.'),
200
+ { borderColor: colors.info }
201
+ ));
202
+ console.log();
203
+ return true;
204
+ }
205
+
206
+ const { confirmed } = await inquirer.prompt<{ confirmed: boolean }>([
207
+ {
208
+ type: 'confirm',
209
+ name: 'confirmed',
210
+ message: 'Apply these changes?',
211
+ default: true,
212
+ },
213
+ ]);
214
+
215
+ return confirmed;
216
+ }
217
+
218
+ /**
219
+ * Prompt for force overwrite
220
+ */
221
+ export async function confirmForce(clientName: string): Promise<boolean> {
222
+ const { force } = await inquirer.prompt<{ force: boolean }>([
223
+ {
224
+ type: 'confirm',
225
+ name: 'force',
226
+ message: `${clientName} already has APIClaw configured. Overwrite?`,
227
+ default: false,
228
+ },
229
+ ]);
230
+
231
+ return force;
232
+ }
233
+
234
+ /**
235
+ * Show success message with next steps
236
+ */
237
+ export function showSuccess(configuredClients: string[]): void {
238
+ console.log();
239
+ console.log(box(
240
+ `${icons.check} APIClaw configured successfully!\n\n` +
241
+ `Configured: ${configuredClients.join(', ')}`,
242
+ { title: 'Success', borderColor: colors.success }
243
+ ));
244
+
245
+ console.log(colors.secondary('\nNext steps:'));
246
+ console.log(bulletList([
247
+ `Restart ${configuredClients.join(' / ')}`,
248
+ 'Ask your agent: "List available APIs"',
249
+ ], 2));
250
+
251
+ console.log(colors.secondary('\nNeed help?'));
252
+ console.log(` ${colors.link('https://docs.apiclaw.com/setup')}\n`);
253
+ }
254
+
255
+ /**
256
+ * Show dry-run summary
257
+ */
258
+ export function showDryRunSummary(changes: ConfigChange[]): void {
259
+ console.log();
260
+ console.log(box(
261
+ `${icons.info} Dry-run complete\n\n` +
262
+ `Would configure: ${changes.filter(c => c.action !== 'skip').length} client(s)\n` +
263
+ `Would skip: ${changes.filter(c => c.action === 'skip').length} client(s)`,
264
+ { title: 'Dry Run', borderColor: colors.info }
265
+ ));
266
+
267
+ console.log(colors.secondary('\nTo apply changes, run:'));
268
+ console.log(colors.action(' npx @nordsym/apiclaw setup\n'));
269
+ }
270
+
271
+ /**
272
+ * Run the full interactive wizard
273
+ */
274
+ export async function runWizard(
275
+ clients: DetectedClient[],
276
+ options: { dryRun?: boolean } = {}
277
+ ): Promise<WizardResult> {
278
+ showWelcome();
279
+
280
+ // Select clients
281
+ const selectedClients = await selectClients(clients);
282
+
283
+ // Handle custom path if selected
284
+ const finalClients = [...selectedClients];
285
+ if (selectedClients.includes('custom')) {
286
+ const customPath = await promptCustomPath();
287
+ // Remove 'custom' placeholder and add actual path
288
+ const idx = finalClients.indexOf('custom');
289
+ finalClients[idx] = `custom:${customPath}`;
290
+ }
291
+
292
+ // Optionally link workspace
293
+ const workspace = await promptWorkspace();
294
+
295
+ // Build preview changes
296
+ const changes: ConfigChange[] = finalClients.map(clientId => {
297
+ const isCustom = clientId.startsWith('custom:');
298
+ const client = isCustom
299
+ ? { id: 'custom', name: 'Custom', configPath: clientId.replace('custom:', ''), alreadyConfigured: false }
300
+ : clients.find(c => c.id === clientId)!;
301
+
302
+ return {
303
+ clientId: client.id,
304
+ clientName: client.name,
305
+ configPath: client.configPath,
306
+ action: client.alreadyConfigured ? 'skip' : 'update',
307
+ diff: generateDiff(workspace),
308
+ };
309
+ });
310
+
311
+ // Confirm changes
312
+ const confirmed = await confirmChanges(changes, { dryRun: options.dryRun });
313
+
314
+ return {
315
+ selectedClients: finalClients,
316
+ workspace,
317
+ confirmed,
318
+ dryRun: options.dryRun || false,
319
+ };
320
+ }
321
+
322
+ /**
323
+ * Generate diff preview for config change
324
+ */
325
+ function generateDiff(workspace?: string): string {
326
+ const lines = [
327
+ added('"apiclaw": {'),
328
+ added(' "command": "npx",'),
329
+ added(' "args": ["-y", "@nordsym/apiclaw"]'),
330
+ ];
331
+
332
+ if (workspace) {
333
+ lines.splice(2, 0, added(` "env": { "APICLAW_WORKSPACE": "${workspace}" },`));
334
+ }
335
+
336
+ lines.push(added('}'));
337
+
338
+ return lines.join('\n');
339
+ }
340
+
341
+ /**
342
+ * Prompt for restore backup selection
343
+ */
344
+ export async function selectBackup(backups: { path: string; date: Date; client: string }[]): Promise<string | null> {
345
+ if (backups.length === 0) {
346
+ console.log(colors.warning('No backups found.'));
347
+ return null;
348
+ }
349
+
350
+ const choices = backups.map(b => ({
351
+ name: `${b.client} - ${b.date.toLocaleString()} (${b.path})`,
352
+ value: b.path,
353
+ }));
354
+
355
+ choices.push({
356
+ name: 'Cancel',
357
+ value: '',
358
+ });
359
+
360
+ const { backup } = await inquirer.prompt<{ backup: string }>([
361
+ {
362
+ type: 'list',
363
+ name: 'backup',
364
+ message: 'Select a backup to restore:',
365
+ choices,
366
+ },
367
+ ]);
368
+
369
+ return backup || null;
370
+ }
371
+
372
+ /**
373
+ * Confirm uninstall
374
+ */
375
+ export async function confirmUninstall(clients: string[]): Promise<boolean> {
376
+ console.log(colors.warning('\n⚠️ This will remove APIClaw from:\n'));
377
+ console.log(bulletList(clients, 2));
378
+ console.log();
379
+
380
+ const { confirmed } = await inquirer.prompt<{ confirmed: boolean }>([
381
+ {
382
+ type: 'confirm',
383
+ name: 'confirmed',
384
+ message: 'Are you sure you want to uninstall APIClaw?',
385
+ default: false,
386
+ },
387
+ ]);
388
+
389
+ return confirmed;
390
+ }
@@ -0,0 +1,325 @@
1
+ /**
2
+ * APIClaw MCP Auto-Setup - Spinner Utilities
3
+ *
4
+ * Ora-based spinner wrapper with consistent styling and state management.
5
+ * Provides a fluent API for progress indication during CLI operations.
6
+ */
7
+
8
+ import ora, { Ora, Options as OraOptions } from 'ora';
9
+ import { colors, icons } from './colors.js';
10
+
11
+ export interface SpinnerOptions {
12
+ /** Spinner text */
13
+ text?: string;
14
+ /** Prefix text before spinner */
15
+ prefix?: string;
16
+ /** Suffix text after spinner */
17
+ suffix?: string;
18
+ /** Whether to show spinner in CI environments */
19
+ showInCI?: boolean;
20
+ /** Custom spinner frames */
21
+ spinner?: OraOptions['spinner'];
22
+ }
23
+
24
+ export interface TaskSpinner {
25
+ /** Start the spinner with optional text */
26
+ start(text?: string): TaskSpinner;
27
+ /** Update spinner text */
28
+ text(text: string): TaskSpinner;
29
+ /** Mark as successful with optional message */
30
+ succeed(text?: string): TaskSpinner;
31
+ /** Mark as failed with optional message */
32
+ fail(text?: string): TaskSpinner;
33
+ /** Mark as warning with optional message */
34
+ warn(text?: string): TaskSpinner;
35
+ /** Show info message without stopping */
36
+ info(text?: string): TaskSpinner;
37
+ /** Stop spinner without status */
38
+ stop(): TaskSpinner;
39
+ /** Stop and clear spinner */
40
+ clear(): TaskSpinner;
41
+ /** Check if spinner is currently spinning */
42
+ isSpinning(): boolean;
43
+ /** Access underlying ora instance */
44
+ readonly ora: Ora;
45
+ }
46
+
47
+ /**
48
+ * Create a task spinner with APIClaw styling
49
+ */
50
+ export function createSpinner(options: SpinnerOptions = {}): TaskSpinner {
51
+ const {
52
+ text = '',
53
+ prefix = '',
54
+ suffix = '',
55
+ showInCI = false,
56
+ spinner = 'dots',
57
+ } = options;
58
+
59
+ const oraInstance = ora({
60
+ text,
61
+ prefixText: prefix,
62
+ suffixText: suffix,
63
+ spinner,
64
+ // Disable spinner in CI by default for cleaner logs
65
+ isEnabled: showInCI || !process.env.CI,
66
+ });
67
+
68
+ const wrapper: TaskSpinner = {
69
+ start(newText?: string) {
70
+ if (newText) oraInstance.text = newText;
71
+ oraInstance.start();
72
+ return wrapper;
73
+ },
74
+
75
+ text(newText: string) {
76
+ oraInstance.text = newText;
77
+ return wrapper;
78
+ },
79
+
80
+ succeed(newText?: string) {
81
+ oraInstance.succeed(newText);
82
+ return wrapper;
83
+ },
84
+
85
+ fail(newText?: string) {
86
+ oraInstance.fail(newText);
87
+ return wrapper;
88
+ },
89
+
90
+ warn(newText?: string) {
91
+ oraInstance.warn(newText);
92
+ return wrapper;
93
+ },
94
+
95
+ info(newText?: string) {
96
+ oraInstance.info(newText);
97
+ return wrapper;
98
+ },
99
+
100
+ stop() {
101
+ oraInstance.stop();
102
+ return wrapper;
103
+ },
104
+
105
+ clear() {
106
+ oraInstance.stopAndPersist({ symbol: '' });
107
+ return wrapper;
108
+ },
109
+
110
+ isSpinning() {
111
+ return oraInstance.isSpinning;
112
+ },
113
+
114
+ get ora() {
115
+ return oraInstance;
116
+ },
117
+ };
118
+
119
+ return wrapper;
120
+ }
121
+
122
+ /**
123
+ * Convenience function for common spinner patterns
124
+ */
125
+ export const spinner = {
126
+ /**
127
+ * Create and start a spinner in one call
128
+ */
129
+ start(text: string): TaskSpinner {
130
+ return createSpinner({ text }).start();
131
+ },
132
+
133
+ /**
134
+ * Run an async task with spinner, auto-succeed/fail
135
+ */
136
+ async task<T>(
137
+ text: string,
138
+ fn: (spinner: TaskSpinner) => Promise<T>,
139
+ options: {
140
+ successText?: string | ((result: T) => string);
141
+ failText?: string | ((error: Error) => string);
142
+ } = {}
143
+ ): Promise<T> {
144
+ const s = createSpinner({ text }).start();
145
+
146
+ try {
147
+ const result = await fn(s);
148
+ const successMsg = typeof options.successText === 'function'
149
+ ? options.successText(result)
150
+ : options.successText || text;
151
+ s.succeed(successMsg);
152
+ return result;
153
+ } catch (error) {
154
+ const failMsg = typeof options.failText === 'function'
155
+ ? options.failText(error as Error)
156
+ : options.failText || `${text} - Failed`;
157
+ s.fail(failMsg);
158
+ throw error;
159
+ }
160
+ },
161
+
162
+ /**
163
+ * Run multiple tasks in sequence with spinners
164
+ */
165
+ async sequence<T>(
166
+ tasks: Array<{
167
+ text: string;
168
+ task: () => Promise<T>;
169
+ successText?: string;
170
+ failText?: string;
171
+ }>
172
+ ): Promise<T[]> {
173
+ const results: T[] = [];
174
+
175
+ for (const { text, task, successText, failText } of tasks) {
176
+ const result = await this.task(text, task, { successText, failText });
177
+ results.push(result);
178
+ }
179
+
180
+ return results;
181
+ },
182
+ };
183
+
184
+ /**
185
+ * Progress tracker for multi-step operations
186
+ */
187
+ export class ProgressTracker {
188
+ private current = 0;
189
+ private readonly total: number;
190
+ private readonly items: string[];
191
+ private readonly taskSpinner: TaskSpinner;
192
+
193
+ constructor(items: string[]) {
194
+ this.items = items;
195
+ this.total = items.length;
196
+ this.taskSpinner = createSpinner();
197
+ }
198
+
199
+ /**
200
+ * Start tracking progress
201
+ */
202
+ start(): void {
203
+ this.current = 0;
204
+ this.updateText();
205
+ this.taskSpinner.start();
206
+ }
207
+
208
+ /**
209
+ * Move to next item
210
+ */
211
+ next(): void {
212
+ this.current++;
213
+ this.updateText();
214
+ }
215
+
216
+ /**
217
+ * Mark current item as done and move to next
218
+ */
219
+ done(message?: string): void {
220
+ this.taskSpinner.succeed(message || this.items[this.current - 1]);
221
+ if (this.current < this.total) {
222
+ this.taskSpinner.start(this.formatProgress());
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Mark as complete
228
+ */
229
+ complete(message: string): void {
230
+ this.taskSpinner.succeed(message);
231
+ }
232
+
233
+ /**
234
+ * Mark as failed
235
+ */
236
+ fail(message: string): void {
237
+ this.taskSpinner.fail(message);
238
+ }
239
+
240
+ private updateText(): void {
241
+ this.taskSpinner.text(this.formatProgress());
242
+ }
243
+
244
+ private formatProgress(): string {
245
+ const item = this.items[this.current] || 'Processing...';
246
+ return `[${this.current + 1}/${this.total}] ${item}`;
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Silent spinner for non-interactive/CI environments
252
+ * Logs plain text instead of animated spinners
253
+ */
254
+ export function createSilentSpinner(options: SpinnerOptions = {}): TaskSpinner {
255
+ const log = (symbol: string, text?: string) => {
256
+ if (text) {
257
+ console.log(`${symbol} ${text}`);
258
+ }
259
+ };
260
+
261
+ let currentText = options.text || '';
262
+
263
+ const wrapper: TaskSpinner = {
264
+ start(text?: string) {
265
+ currentText = text || currentText;
266
+ log(colors.muted('○'), currentText);
267
+ return wrapper;
268
+ },
269
+
270
+ text(text: string) {
271
+ currentText = text;
272
+ return wrapper;
273
+ },
274
+
275
+ succeed(text?: string) {
276
+ log(icons.success, text || currentText);
277
+ return wrapper;
278
+ },
279
+
280
+ fail(text?: string) {
281
+ log(icons.error, text || currentText);
282
+ return wrapper;
283
+ },
284
+
285
+ warn(text?: string) {
286
+ log(icons.warning, text || currentText);
287
+ return wrapper;
288
+ },
289
+
290
+ info(text?: string) {
291
+ log(icons.info, text || currentText);
292
+ return wrapper;
293
+ },
294
+
295
+ stop() {
296
+ return wrapper;
297
+ },
298
+
299
+ clear() {
300
+ return wrapper;
301
+ },
302
+
303
+ isSpinning() {
304
+ return false;
305
+ },
306
+
307
+ get ora(): Ora {
308
+ // Return a mock for compatibility
309
+ return {} as Ora;
310
+ },
311
+ };
312
+
313
+ return wrapper;
314
+ }
315
+
316
+ /**
317
+ * Get appropriate spinner based on environment
318
+ */
319
+ export function getSpinner(options: SpinnerOptions = {}): TaskSpinner {
320
+ // Use silent spinner in CI or when stdout is not a TTY
321
+ if (process.env.CI || !process.stdout.isTTY) {
322
+ return createSilentSpinner(options);
323
+ }
324
+ return createSpinner(options);
325
+ }