workos 0.12.0 → 0.12.2

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 (42) hide show
  1. package/dist/cli.config.d.ts +32 -0
  2. package/dist/cli.config.js +32 -0
  3. package/dist/cli.config.js.map +1 -1
  4. package/dist/integrations/dotnet/index.js +13 -1
  5. package/dist/integrations/dotnet/index.js.map +1 -1
  6. package/dist/integrations/elixir/index.js +1 -1
  7. package/dist/integrations/elixir/index.js.map +1 -1
  8. package/dist/integrations/go/index.js +1 -1
  9. package/dist/integrations/go/index.js.map +1 -1
  10. package/dist/integrations/kotlin/index.js +25 -0
  11. package/dist/integrations/kotlin/index.js.map +1 -1
  12. package/dist/integrations/python/index.js +1 -0
  13. package/dist/integrations/python/index.js.map +1 -1
  14. package/dist/integrations/ruby/index.js +1 -1
  15. package/dist/integrations/ruby/index.js.map +1 -1
  16. package/dist/lib/adapters/cli-adapter.js +24 -1
  17. package/dist/lib/adapters/cli-adapter.js.map +1 -1
  18. package/dist/lib/adapters/headless-adapter.js +23 -1
  19. package/dist/lib/adapters/headless-adapter.js.map +1 -1
  20. package/dist/lib/agent-interface.d.ts +3 -1
  21. package/dist/lib/agent-interface.js +49 -0
  22. package/dist/lib/agent-interface.js.map +1 -1
  23. package/dist/lib/agent-runner.js +3 -1
  24. package/dist/lib/agent-runner.js.map +1 -1
  25. package/dist/lib/env-writer.d.ts +10 -0
  26. package/dist/lib/env-writer.js +36 -6
  27. package/dist/lib/env-writer.js.map +1 -1
  28. package/dist/lib/framework-config.d.ts +11 -1
  29. package/dist/lib/framework-config.js.map +1 -1
  30. package/dist/lib/port-detection.js +124 -0
  31. package/dist/lib/port-detection.js.map +1 -1
  32. package/dist/lib/registry.d.ts +1 -2
  33. package/dist/lib/registry.js.map +1 -1
  34. package/dist/lib/run-with-core.d.ts +5 -0
  35. package/dist/lib/run-with-core.js +26 -3
  36. package/dist/lib/run-with-core.js.map +1 -1
  37. package/dist/lib/unclaimed-env-provision.js +2 -2
  38. package/dist/lib/unclaimed-env-provision.js.map +1 -1
  39. package/package.json +1 -1
  40. package/dist/lib/language-detection.d.ts +0 -20
  41. package/dist/lib/language-detection.js +0 -96
  42. package/dist/lib/language-detection.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cli-adapter.js","sourceRoot":"","sources":["../../../src/lib/adapters/cli-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAErE;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACZ,OAAO,CAAwB;IAChC,SAAS,CAA6B;IACtC,KAAK,CAAU;IACf,OAAO,GAA4C,IAAI,CAAC;IACxD,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IAEzC,mCAAmC;IAC3B,QAAQ,GAAG,IAAI,GAAG,EAAwC,CAAC;IAEnE,+DAA+D;IACvD,cAAc,GAAG,KAAK,CAAC;IACvB,WAAW,GAAsB,EAAE,CAAC;IAE5C,6BAA6B;IACrB,aAAa,GAAwB,IAAI,CAAC;IAElD,qCAAqC;IAC7B,mBAAmB,GAA0B,IAAI,CAAC;IAE1D,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;IACrC,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,KAAiB;QACpC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,CAA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GAAG,CAAC,EAAE,KAAK,EAA8C,EAAQ,EAAE;QACzF,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QAChC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEM,wBAAwB,GAAG,CAAC,EAAE,YAAY,EAAyC,EAAQ,EAAE;QACnG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC;CACH","sourcesContent":["import type { InstallerAdapter, AdapterConfig } from './types.js';\nimport type { InstallerEventEmitter, InstallerEvents } from '../events.js';\nimport clack from '../../utils/clack.js';\nimport chalk from 'chalk';\nimport { getConfig } from '../settings.js';\nimport { ProgressTracker } from '../progress-tracker.js';\nimport { renderCompletionSummary } from '../../utils/summary-box.js';\n\n/**\n * CLI adapter that renders wizard events via clack.\n *\n * Subscribes to InstallerEventEmitter and translates events into\n * clack UI operations (logs, spinners, prompts).\n */\nexport class CLIAdapter implements InstallerAdapter {\n readonly emitter: InstallerEventEmitter;\n private sendEvent: AdapterConfig['sendEvent'];\n private debug: boolean;\n private spinner: ReturnType<typeof clack.spinner> | null = null;\n private isStarted = false;\n private progress = new ProgressTracker();\n\n // Store bound handlers for cleanup\n private handlers = new Map<string, (...args: unknown[]) => void>();\n\n // Queue for logs while prompt is active (parallel state issue)\n private isPromptActive = false;\n private pendingLogs: Array<() => void> = [];\n\n // SIGINT handler for cleanup\n private sigIntHandler: (() => void) | null = null;\n\n // Long-running agent update interval\n private agentUpdateInterval: NodeJS.Timeout | null = null;\n\n constructor(config: AdapterConfig) {\n this.emitter = config.emitter;\n this.sendEvent = config.sendEvent;\n this.debug = config.debug ?? false;\n }\n\n /**\n * Queue a log call if a prompt is active, otherwise execute immediately.\n */\n private queueableLog(logFn: () => void): void {\n if (this.isPromptActive) {\n this.pendingLogs.push(logFn);\n } else {\n logFn();\n }\n }\n\n /**\n * Flush any queued logs after prompt completes.\n */\n private flushPendingLogs(): void {\n const logs = this.pendingLogs.splice(0);\n logs.forEach((fn) => fn());\n }\n\n async start(): Promise<void> {\n if (this.isStarted) return;\n this.isStarted = true;\n\n // Show intro\n const config = getConfig();\n if (config.branding.showAsciiArt) {\n const art = config.branding.useCompact ? config.branding.compactAsciiArt : config.branding.asciiArt;\n console.log(chalk.cyan(art));\n console.log();\n } else {\n clack.intro('Welcome to the WorkOS AuthKit installer');\n }\n\n // Handle Ctrl+C gracefully\n const handleSigInt = () => {\n if (this.spinner) {\n this.spinner.stop('Cancelled');\n this.spinner = null;\n }\n this.stopAgentUpdates();\n clack.log.warn('Installer cancelled');\n clack.outro('Your project was not modified');\n process.exit(0);\n };\n process.on('SIGINT', handleSigInt);\n this.sigIntHandler = handleSigInt;\n\n // Subscribe to state events for progress tracking\n this.subscribe('state:enter', this.handleStateEnter);\n this.subscribe('state:exit', this.handleStateExit);\n\n // Subscribe to events that require UI rendering\n this.subscribe('auth:success', this.handleAuthSuccess);\n this.subscribe('auth:failure', this.handleAuthFailure);\n this.subscribe('detection:complete', this.handleDetectionComplete);\n this.subscribe('detection:none', this.handleDetectionNone);\n this.subscribe('git:dirty', this.handleGitDirty);\n this.subscribe('credentials:found', this.handleCredentialsFound);\n this.subscribe('credentials:request', this.handleCredentialsRequest);\n this.subscribe('credentials:env:prompt', this.handleEnvScanPrompt);\n this.subscribe('device:started', this.handleDeviceStarted);\n this.subscribe('device:success', this.handleDeviceSuccess);\n this.subscribe('staging:fetching', this.handleStagingFetching);\n this.subscribe('staging:success', this.handleStagingSuccess);\n this.subscribe('credentials:env:found', this.handleEnvCredentialsFound);\n this.subscribe('config:complete', this.handleConfigComplete);\n this.subscribe('agent:start', this.handleAgentStart);\n this.subscribe('agent:progress', this.handleAgentProgress);\n this.subscribe('validation:start', this.handleValidationStart);\n this.subscribe('validation:issues', this.handleValidationIssues);\n this.subscribe('validation:complete', this.handleValidationComplete);\n this.subscribe('complete', this.handleComplete);\n this.subscribe('error', this.handleError);\n // Branch check events\n this.subscribe('branch:prompt', this.handleBranchPrompt);\n this.subscribe('branch:created', this.handleBranchCreated);\n\n // Post-install events\n this.subscribe('postinstall:changes', this.handlePostInstallChanges);\n this.subscribe('postinstall:commit:prompt', this.handleCommitPrompt);\n this.subscribe('postinstall:commit:generating', this.handleCommitGenerating);\n this.subscribe('postinstall:commit:success', this.handleCommitSuccess);\n this.subscribe('postinstall:commit:failed', this.handleCommitFailed);\n this.subscribe('postinstall:pr:prompt', this.handlePrPrompt);\n this.subscribe('postinstall:pr:generating', this.handlePrGenerating);\n this.subscribe('postinstall:pr:pushing', this.handlePrPushing);\n this.subscribe('postinstall:pr:success', this.handlePrSuccess);\n this.subscribe('postinstall:pr:failed', this.handlePrFailed);\n this.subscribe('postinstall:push:failed', this.handlePushFailed);\n this.subscribe('postinstall:manual', this.handleManualInstructions);\n }\n\n async stop(): Promise<void> {\n if (!this.isStarted) return;\n\n // Remove SIGINT handler\n if (this.sigIntHandler) {\n process.off('SIGINT', this.sigIntHandler);\n this.sigIntHandler = null;\n }\n\n // Stop agent updates\n this.stopAgentUpdates();\n\n // Unsubscribe from all events\n for (const [event, handler] of this.handlers) {\n this.emitter.off(event as keyof InstallerEvents, handler as never);\n }\n this.handlers.clear();\n\n // Stop any active spinner\n this.spinner?.stop();\n this.spinner = null;\n\n this.isStarted = false;\n }\n\n private stopAgentUpdates = (): void => {\n if (this.agentUpdateInterval) {\n clearInterval(this.agentUpdateInterval);\n this.agentUpdateInterval = null;\n }\n };\n\n private stopSpinner(message: string): void {\n if (this.spinner) {\n this.spinner.stop(message);\n this.spinner = null;\n }\n }\n\n /** Debug logging - only outputs when debug mode is enabled */\n private debugLog = (message: string): void => {\n if (this.debug) {\n console.log(chalk.dim(`[debug] ${message}`));\n }\n };\n\n /**\n * Helper to subscribe and track handlers for cleanup.\n */\n private subscribe<K extends keyof InstallerEvents>(\n event: K,\n handler: (payload: InstallerEvents[K]) => void | Promise<void>,\n ): void {\n const boundHandler = handler.bind(this);\n this.handlers.set(event, boundHandler as (...args: unknown[]) => void);\n this.emitter.on(event, boundHandler);\n }\n\n // ===== Event Handlers =====\n\n private handleStateEnter = ({ state }: InstallerEvents['state:enter']): void => {\n this.progress.enterPhase(state);\n };\n\n private handleStateExit = ({ state }: InstallerEvents['state:exit']): void => {\n this.progress.exitPhase(state);\n };\n\n private handleAuthSuccess = (): void => {\n clack.log.success('Authenticated');\n };\n\n private handleAuthFailure = ({ message }: InstallerEvents['auth:failure']): void => {\n clack.log.error(`Auth failed: ${message}`);\n clack.log.info('Visit https://dashboard.workos.com to verify your account');\n };\n\n private handleDetectionComplete = ({ integration }: InstallerEvents['detection:complete']): void => {\n this.queueableLog(() => clack.log.success(`Detected ${chalk.bold(integration)}`));\n };\n\n private handleDetectionNone = (): void => {\n this.queueableLog(() => clack.log.warn('Could not detect framework automatically'));\n };\n\n private handleCredentialsFound = (): void => {\n clack.log.success('Found existing WorkOS credentials in .env.local');\n };\n\n private handleEnvScanPrompt = async ({ files }: InstallerEvents['credentials:env:prompt']): Promise<void> => {\n this.isPromptActive = true;\n const fileList = files.length === 1 ? files[0] : files.slice(0, 2).join(', ');\n const confirmed = await clack.confirm({\n message: `Found ${fileList}. Check for existing WorkOS credentials?`,\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'ENV_SCAN_DECLINED' : 'ENV_SCAN_APPROVED',\n });\n };\n\n private handleDeviceStarted = ({ verificationUri, userCode }: InstallerEvents['device:started']): void => {\n clack.log.info(`\\nOpen this URL in your browser:\\n`);\n console.log(` ${chalk.cyan(verificationUri)}`);\n console.log(`\\nEnter code: ${chalk.bold(userCode)}\\n`);\n\n this.spinner = clack.spinner();\n this.spinner.start('Waiting for authentication...');\n };\n\n private handleDeviceSuccess = (): void => {\n // Spinner will be stopped by handleStagingFetching\n };\n\n private handleStagingFetching = (): void => {\n if (this.spinner) {\n this.spinner.stop('Authenticated');\n }\n this.spinner = clack.spinner();\n this.spinner.start('Fetching your WorkOS credentials...');\n };\n\n private handleStagingSuccess = (): void => {\n this.stopSpinner('Credentials fetched');\n clack.log.success('WorkOS credentials retrieved automatically');\n };\n\n private handleEnvCredentialsFound = ({ sourcePath }: InstallerEvents['credentials:env:found']): void => {\n clack.log.success(`Found existing WorkOS credentials in ${sourcePath}`);\n };\n\n private handleGitDirty = async ({ files }: InstallerEvents['git:dirty']): Promise<void> => {\n clack.log.warn('You have uncommitted or untracked files:');\n files.slice(0, 5).forEach((f) => clack.log.info(chalk.dim(` ${f}`)));\n if (files.length > 5) {\n clack.log.info(chalk.dim(` ... and ${files.length - 5} more`));\n }\n\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Continue anyway?',\n initialValue: false,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'GIT_CANCELLED' : 'GIT_CONFIRMED',\n });\n };\n\n private handleCredentialsRequest = async ({\n requiresApiKey,\n }: InstallerEvents['credentials:request']): Promise<void> => {\n clack.log.step(`Get your credentials from ${chalk.cyan('https://dashboard.workos.com')}`);\n\n const clientId = await clack.text({\n message: 'Enter your WorkOS Client ID:',\n placeholder: 'client_...',\n validate: (value) => {\n if (!value || value.trim().length === 0) {\n return 'Client ID is required';\n }\n if (!value.startsWith('client_')) {\n return 'Client ID should start with \"client_\"';\n }\n return undefined;\n },\n });\n\n if (clack.isCancel(clientId)) {\n this.sendEvent({ type: 'CANCEL' });\n return;\n }\n\n let apiKey = '';\n if (requiresApiKey) {\n clack.log.info(chalk.dim('ℹ️ Your API key will be hidden for security and saved to .env.local'));\n const apiKeyResult = await clack.password({\n message: 'Enter your WorkOS API Key:',\n validate: (value) => {\n if (!value || value.trim().length === 0) {\n return 'API Key is required';\n }\n if (!value.startsWith('sk_')) {\n return 'API Key should start with \"sk_\"';\n }\n return undefined;\n },\n });\n\n if (clack.isCancel(apiKeyResult)) {\n this.sendEvent({ type: 'CANCEL' });\n return;\n }\n apiKey = apiKeyResult as string;\n } else {\n clack.log.info(chalk.dim('ℹ️ Client-only SDK - API key not required'));\n }\n\n this.sendEvent({\n type: 'CREDENTIALS_SUBMITTED',\n apiKey,\n clientId: clientId as string,\n });\n };\n\n private handleConfigComplete = (): void => {\n clack.log.success('Environment configured');\n };\n\n private handleAgentStart = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Running AI agent...');\n\n // Periodic status updates for long-running operations\n let dots = 0;\n this.agentUpdateInterval = setInterval(() => {\n dots = (dots + 1) % 4;\n const dotStr = '.'.repeat(dots + 1);\n this.spinner?.message(`Running AI agent${dotStr}`);\n }, 2000);\n };\n\n private handleAgentProgress = ({ step, detail }: InstallerEvents['agent:progress']): void => {\n const message = detail ? `${step}: ${detail}` : step;\n this.spinner?.message(message);\n };\n\n private handleValidationStart = (): void => {\n this.stopAgentUpdates();\n this.stopSpinner('Agent completed');\n };\n\n private handleValidationIssues = ({ issues }: InstallerEvents['validation:issues']): void => {\n for (const issue of issues) {\n if (issue.severity === 'error') {\n clack.log.error(issue.message);\n } else {\n clack.log.warn(issue.message);\n }\n if (issue.hint) {\n clack.log.info(`Hint: ${issue.hint}`);\n }\n }\n };\n\n private handleValidationComplete = ({ passed, issueCount }: InstallerEvents['validation:complete']): void => {\n if (passed) {\n clack.log.success('Validation passed');\n } else {\n clack.log.warn(`Validation found ${issueCount} issue(s)`);\n }\n };\n\n private handleComplete = ({ success, summary }: InstallerEvents['complete']): void => {\n this.stopAgentUpdates();\n this.stopSpinner(success ? 'Done' : 'Failed');\n\n console.log('');\n console.log(renderCompletionSummary(success, summary));\n console.log('');\n };\n\n private handleError = ({ message, stack }: InstallerEvents['error']): void => {\n this.stopSpinner('Error');\n this.stopAgentUpdates();\n\n clack.log.error(message);\n\n // Add actionable hints for common errors\n if (message.includes('authentication') || message.includes('auth')) {\n clack.log.info('Try running: workos auth logout && workos install');\n }\n if (message.includes('ENOENT') || message.includes('not found')) {\n clack.log.info('Ensure you are in a project directory');\n }\n\n if (stack && this.debug) {\n this.debugLog(stack);\n }\n };\n\n private handleBranchPrompt = async ({ branch }: InstallerEvents['branch:prompt']): Promise<void> => {\n this.isPromptActive = true;\n const choice = await clack.select({\n message: `You are on ${chalk.bold(branch)}. Create a feature branch?`,\n options: [\n { value: 'create', label: 'Create feat/add-workos-authkit' },\n { value: 'continue', label: 'Continue on current branch' },\n { value: 'cancel', label: 'Cancel' },\n ],\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n if (clack.isCancel(choice) || choice === 'cancel') {\n this.sendEvent({ type: 'BRANCH_CANCEL' });\n } else if (choice === 'create') {\n this.sendEvent({ type: 'BRANCH_CREATE' });\n } else {\n this.sendEvent({ type: 'BRANCH_CONTINUE' });\n }\n };\n\n private handleBranchCreated = ({ branch }: InstallerEvents['branch:created']): void => {\n this.queueableLog(() => clack.log.success(`Created branch ${chalk.bold(branch)}`));\n };\n\n // ===== Post-install Event Handlers =====\n\n private handlePostInstallChanges = ({ files }: InstallerEvents['postinstall:changes']): void => {\n this.debugLog(`Post-install: ${files.length} changed files detected`);\n };\n\n private handleCommitPrompt = async (): Promise<void> => {\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Commit the changes?',\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'COMMIT_DECLINED' : 'COMMIT_APPROVED',\n });\n };\n\n private handleCommitGenerating = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Generating commit message...');\n };\n\n private handleCommitSuccess = ({ message }: InstallerEvents['postinstall:commit:success']): void => {\n this.stopSpinner('Committed');\n clack.log.success(`Committed: ${chalk.dim(message)}`);\n };\n\n private handleCommitFailed = ({ error }: InstallerEvents['postinstall:commit:failed']): void => {\n this.stopSpinner('Commit failed');\n clack.log.error(`Commit failed: ${error}`);\n };\n\n private handlePrPrompt = async (): Promise<void> => {\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Create a pull request?',\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'PR_DECLINED' : 'PR_APPROVED',\n });\n };\n\n private handlePrGenerating = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Generating PR description...');\n };\n\n private handlePrPushing = (): void => {\n if (this.spinner) {\n this.spinner.message('Pushing to remote...');\n } else {\n this.spinner = clack.spinner();\n this.spinner.start('Pushing to remote...');\n }\n };\n\n private handlePrSuccess = ({ url }: InstallerEvents['postinstall:pr:success']): void => {\n this.stopSpinner('PR created');\n clack.log.success(`Pull request created: ${chalk.cyan(url)}`);\n };\n\n private handlePrFailed = ({ error }: InstallerEvents['postinstall:pr:failed']): void => {\n this.stopSpinner('PR creation failed');\n clack.log.error(`PR creation failed: ${error}`);\n };\n\n private handlePushFailed = ({ error }: InstallerEvents['postinstall:push:failed']): void => {\n this.stopSpinner('Push failed');\n clack.log.error(`Push failed: ${error}`);\n };\n\n private handleManualInstructions = ({ instructions }: InstallerEvents['postinstall:manual']): void => {\n clack.log.info('GitHub CLI not found. Manual steps:');\n console.log(chalk.dim(instructions));\n };\n}\n"]}
1
+ {"version":3,"file":"cli-adapter.js","sourceRoot":"","sources":["../../../src/lib/adapters/cli-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAErE;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACZ,OAAO,CAAwB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,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,CAAC;IAEM,eAAe,GAAG,CAAC,EAAE,GAAG,EAA6C,EAAQ,EAAE;QACrF,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAC/B,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,yBAAyB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC;IAEM,cAAc,GAAG,CAAC,EAAE,KAAK,EAA4C,EAAQ,EAAE;QACrF,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;QACvC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC;IAEM,gBAAgB,GAAG,CAAC,EAAE,KAAK,EAA8C,EAAQ,EAAE;QACzF,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;QAChC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEM,wBAAwB,GAAG,CAAC,EAAE,YAAY,EAAyC,EAAQ,EAAE;QACnG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC;CACH","sourcesContent":["import type { InstallerAdapter, AdapterConfig } from './types.js';\nimport type { InstallerEventEmitter, InstallerEvents } from '../events.js';\nimport clack from '../../utils/clack.js';\nimport chalk from 'chalk';\nimport { getConfig } from '../settings.js';\nimport { ProgressTracker } from '../progress-tracker.js';\nimport { renderCompletionSummary } from '../../utils/summary-box.js';\n\n/**\n * CLI adapter that renders wizard events via clack.\n *\n * Subscribes to InstallerEventEmitter and translates events into\n * clack UI operations (logs, spinners, prompts).\n */\nexport class CLIAdapter implements InstallerAdapter {\n readonly emitter: InstallerEventEmitter;\n private sendEvent: AdapterConfig['sendEvent'];\n private debug: boolean;\n private spinner: ReturnType<typeof clack.spinner> | null = null;\n private isStarted = false;\n private progress = new ProgressTracker();\n\n // Store bound handlers for cleanup\n private handlers = new Map<string, (...args: unknown[]) => void>();\n\n // Queue for logs while prompt is active (parallel state issue)\n private isPromptActive = false;\n private pendingLogs: Array<() => void> = [];\n\n // SIGINT handler for cleanup\n private sigIntHandler: (() => void) | null = null;\n\n // Long-running agent update interval\n private agentUpdateInterval: NodeJS.Timeout | null = null;\n\n constructor(config: AdapterConfig) {\n this.emitter = config.emitter;\n this.sendEvent = config.sendEvent;\n this.debug = config.debug ?? false;\n }\n\n /**\n * Queue a log call if a prompt is active, otherwise execute immediately.\n */\n private queueableLog(logFn: () => void): void {\n if (this.isPromptActive) {\n this.pendingLogs.push(logFn);\n } else {\n logFn();\n }\n }\n\n /**\n * Flush any queued logs after prompt completes.\n */\n private flushPendingLogs(): void {\n const logs = this.pendingLogs.splice(0);\n logs.forEach((fn) => fn());\n }\n\n async start(): Promise<void> {\n if (this.isStarted) return;\n this.isStarted = true;\n\n // Show intro\n const config = getConfig();\n if (config.branding.showAsciiArt) {\n const art = config.branding.useCompact ? config.branding.compactAsciiArt : config.branding.asciiArt;\n console.log(chalk.cyan(art));\n console.log();\n } else {\n clack.intro('Welcome to the WorkOS AuthKit installer');\n }\n\n // Handle Ctrl+C gracefully\n const handleSigInt = () => {\n if (this.spinner) {\n this.spinner.stop('Cancelled');\n this.spinner = null;\n }\n this.stopAgentUpdates();\n clack.log.warn('Installer cancelled');\n clack.outro('Your project was not modified');\n process.exit(0);\n };\n process.on('SIGINT', handleSigInt);\n this.sigIntHandler = handleSigInt;\n\n // Subscribe to state events for progress tracking\n this.subscribe('state:enter', this.handleStateEnter);\n this.subscribe('state:exit', this.handleStateExit);\n\n // Subscribe to events that require UI rendering\n this.subscribe('auth:success', this.handleAuthSuccess);\n this.subscribe('auth:failure', this.handleAuthFailure);\n this.subscribe('detection:complete', this.handleDetectionComplete);\n this.subscribe('detection:none', this.handleDetectionNone);\n this.subscribe('git:dirty', this.handleGitDirty);\n this.subscribe('credentials:found', this.handleCredentialsFound);\n this.subscribe('credentials:request', this.handleCredentialsRequest);\n this.subscribe('credentials:env:prompt', this.handleEnvScanPrompt);\n this.subscribe('device:started', this.handleDeviceStarted);\n this.subscribe('device:success', this.handleDeviceSuccess);\n this.subscribe('staging:fetching', this.handleStagingFetching);\n this.subscribe('staging:success', this.handleStagingSuccess);\n this.subscribe('credentials:env:found', this.handleEnvCredentialsFound);\n this.subscribe('config:complete', this.handleConfigComplete);\n this.subscribe('agent:start', this.handleAgentStart);\n this.subscribe('agent:progress', this.handleAgentProgress);\n this.subscribe('validation:start', this.handleValidationStart);\n this.subscribe('validation:issues', this.handleValidationIssues);\n this.subscribe('validation:complete', this.handleValidationComplete);\n this.subscribe('complete', this.handleComplete);\n this.subscribe('error', this.handleError);\n // Branch check events\n this.subscribe('branch:prompt', this.handleBranchPrompt);\n this.subscribe('branch:created', this.handleBranchCreated);\n\n // Post-install events\n this.subscribe('postinstall:changes', this.handlePostInstallChanges);\n this.subscribe('postinstall:commit:prompt', this.handleCommitPrompt);\n this.subscribe('postinstall:commit:generating', this.handleCommitGenerating);\n this.subscribe('postinstall:commit:success', this.handleCommitSuccess);\n this.subscribe('postinstall:commit:failed', this.handleCommitFailed);\n this.subscribe('postinstall:pr:prompt', this.handlePrPrompt);\n this.subscribe('postinstall:pr:generating', this.handlePrGenerating);\n this.subscribe('postinstall:pr:pushing', this.handlePrPushing);\n this.subscribe('postinstall:pr:success', this.handlePrSuccess);\n this.subscribe('postinstall:pr:failed', this.handlePrFailed);\n this.subscribe('postinstall:push:failed', this.handlePushFailed);\n this.subscribe('postinstall:manual', this.handleManualInstructions);\n }\n\n async stop(): Promise<void> {\n if (!this.isStarted) return;\n\n // Remove SIGINT handler\n if (this.sigIntHandler) {\n process.off('SIGINT', this.sigIntHandler);\n this.sigIntHandler = null;\n }\n\n // Stop agent updates\n this.stopAgentUpdates();\n\n // Unsubscribe from all events\n for (const [event, handler] of this.handlers) {\n this.emitter.off(event as keyof InstallerEvents, handler as never);\n }\n this.handlers.clear();\n\n // Stop any active spinner\n this.spinner?.stop();\n this.spinner = null;\n\n this.isStarted = false;\n }\n\n private stopAgentUpdates = (): void => {\n if (this.agentUpdateInterval) {\n clearInterval(this.agentUpdateInterval);\n this.agentUpdateInterval = null;\n }\n };\n\n private stopSpinner(message: string): void {\n if (this.spinner) {\n this.spinner.stop(message);\n this.spinner = null;\n }\n }\n\n /** Debug logging - only outputs when debug mode is enabled */\n private debugLog = (message: string): void => {\n if (this.debug) {\n console.log(chalk.dim(`[debug] ${message}`));\n }\n };\n\n /**\n * Helper to subscribe and track handlers for cleanup.\n */\n private subscribe<K extends keyof InstallerEvents>(\n event: K,\n handler: (payload: InstallerEvents[K]) => void | Promise<void>,\n ): void {\n const boundHandler = handler.bind(this);\n this.handlers.set(event, boundHandler as (...args: unknown[]) => void);\n this.emitter.on(event, boundHandler);\n }\n\n // ===== Event Handlers =====\n\n private handleStateEnter = ({ state }: InstallerEvents['state:enter']): void => {\n this.progress.enterPhase(state);\n };\n\n private handleStateExit = ({ state }: InstallerEvents['state:exit']): void => {\n this.progress.exitPhase(state);\n };\n\n private handleAuthSuccess = (): void => {\n clack.log.success('Authenticated');\n };\n\n private handleAuthFailure = ({ message }: InstallerEvents['auth:failure']): void => {\n clack.log.error(`Auth failed: ${message}`);\n clack.log.info('Visit https://dashboard.workos.com to verify your account');\n };\n\n private handleDetectionComplete = ({ integration }: InstallerEvents['detection:complete']): void => {\n this.queueableLog(() => clack.log.success(`Detected ${chalk.bold(integration)}`));\n };\n\n private handleDetectionNone = (): void => {\n this.queueableLog(() => clack.log.warn('Could not detect framework automatically'));\n };\n\n private handleCredentialsFound = (): void => {\n clack.log.success('Found existing WorkOS credentials in .env.local');\n };\n\n private handleEnvScanPrompt = async ({ files }: InstallerEvents['credentials:env:prompt']): Promise<void> => {\n this.isPromptActive = true;\n const fileList = files.length === 1 ? files[0] : files.slice(0, 2).join(', ');\n const confirmed = await clack.confirm({\n message: `Found ${fileList}. Check for existing WorkOS credentials?`,\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'ENV_SCAN_DECLINED' : 'ENV_SCAN_APPROVED',\n });\n };\n\n private handleDeviceStarted = ({ verificationUri, userCode }: InstallerEvents['device:started']): void => {\n clack.log.info(`\\nOpen this URL in your browser:\\n`);\n console.log(` ${chalk.cyan(verificationUri)}`);\n console.log(`\\nEnter code: ${chalk.bold(userCode)}\\n`);\n\n this.spinner = clack.spinner();\n this.spinner.start('Waiting for authentication...');\n };\n\n private handleDeviceSuccess = (): void => {\n // Spinner will be stopped by handleStagingFetching\n };\n\n private handleStagingFetching = (): void => {\n if (this.spinner) {\n this.spinner.stop('Authenticated');\n }\n this.spinner = clack.spinner();\n this.spinner.start('Fetching your WorkOS credentials...');\n };\n\n private handleStagingSuccess = (): void => {\n this.stopSpinner('Credentials fetched');\n clack.log.success('WorkOS credentials retrieved automatically');\n };\n\n private handleEnvCredentialsFound = ({ sourcePath }: InstallerEvents['credentials:env:found']): void => {\n clack.log.success(`Found existing WorkOS credentials in ${sourcePath}`);\n };\n\n private handleGitDirty = async ({ files }: InstallerEvents['git:dirty']): Promise<void> => {\n clack.log.warn('You have uncommitted or untracked files:');\n files.slice(0, 5).forEach((f) => clack.log.info(chalk.dim(` ${f}`)));\n if (files.length > 5) {\n clack.log.info(chalk.dim(` ... and ${files.length - 5} more`));\n }\n\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Continue anyway?',\n initialValue: false,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'GIT_CANCELLED' : 'GIT_CONFIRMED',\n });\n };\n\n private handleCredentialsRequest = async ({\n requiresApiKey,\n }: InstallerEvents['credentials:request']): Promise<void> => {\n clack.log.step(`Get your credentials from ${chalk.cyan('https://dashboard.workos.com')}`);\n\n const clientId = await clack.text({\n message: 'Enter your WorkOS Client ID:',\n placeholder: 'client_...',\n validate: (value) => {\n if (!value || value.trim().length === 0) {\n return 'Client ID is required';\n }\n if (!value.startsWith('client_')) {\n return 'Client ID should start with \"client_\"';\n }\n return undefined;\n },\n });\n\n if (clack.isCancel(clientId)) {\n this.sendEvent({ type: 'CANCEL' });\n return;\n }\n\n let apiKey = '';\n if (requiresApiKey) {\n clack.log.info(chalk.dim('ℹ️ Your API key will be hidden for security and saved to .env.local'));\n const apiKeyResult = await clack.password({\n message: 'Enter your WorkOS API Key:',\n validate: (value) => {\n if (!value || value.trim().length === 0) {\n return 'API Key is required';\n }\n if (!value.startsWith('sk_')) {\n return 'API Key should start with \"sk_\"';\n }\n return undefined;\n },\n });\n\n if (clack.isCancel(apiKeyResult)) {\n this.sendEvent({ type: 'CANCEL' });\n return;\n }\n apiKey = apiKeyResult as string;\n } else {\n clack.log.info(chalk.dim('ℹ️ Client-only SDK - API key not required'));\n }\n\n this.sendEvent({\n type: 'CREDENTIALS_SUBMITTED',\n apiKey,\n clientId: clientId as string,\n });\n };\n\n private handleConfigComplete = (): void => {\n clack.log.success('Environment configured');\n };\n\n private handleAgentStart = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Running AI agent...');\n\n // Periodic status updates for long-running operations\n let dots = 0;\n this.agentUpdateInterval = setInterval(() => {\n dots = (dots + 1) % 4;\n const dotStr = '.'.repeat(dots + 1);\n this.spinner?.message(`Running AI agent${dotStr}`);\n }, 2000);\n };\n\n private handleAgentProgress = ({ step, detail }: InstallerEvents['agent:progress']): void => {\n const message = detail ? `${step}: ${detail}` : step;\n this.spinner?.message(message);\n };\n\n private handleValidationStart = (): void => {\n this.stopAgentUpdates();\n this.stopSpinner('Agent completed');\n };\n\n private handleValidationIssues = ({ issues }: InstallerEvents['validation:issues']): void => {\n for (const issue of issues) {\n if (issue.severity === 'error') {\n clack.log.error(issue.message);\n } else {\n clack.log.warn(issue.message);\n }\n if (issue.hint) {\n clack.log.info(`Hint: ${issue.hint}`);\n }\n }\n };\n\n private handleValidationComplete = ({ passed, issueCount }: InstallerEvents['validation:complete']): void => {\n if (passed) {\n clack.log.success('Validation passed');\n } else {\n clack.log.warn(`Validation found ${issueCount} issue(s)`);\n }\n };\n\n private handleComplete = ({ success, summary }: InstallerEvents['complete']): void => {\n this.stopAgentUpdates();\n this.stopSpinner(success ? 'Done' : 'Failed');\n\n console.log('');\n console.log(renderCompletionSummary(success, summary));\n console.log('');\n };\n\n private handleError = ({ message, stack }: InstallerEvents['error']): void => {\n this.stopSpinner('Error');\n this.stopAgentUpdates();\n\n // Rewrite raw API/SDK errors into user-friendly messages\n const isServiceError =\n /\\b50[0-9]\\b/.test(message) || /server_error|internal_error|overloaded|service.*unavailable/i.test(message);\n const isRateLimit = /\\b429\\b/.test(message) || /rate.limit/i.test(message);\n const isNetworkError = /ECONNREFUSED|ETIMEDOUT|ENOTFOUND|fetch failed/i.test(message);\n const isProcessExit = /process exited with code/i.test(message);\n\n if (isServiceError) {\n clack.log.error('The AI service is temporarily unavailable.');\n clack.log.info('This is usually resolved within a few minutes. Please try again shortly.');\n } else if (isRateLimit) {\n clack.log.error('The AI service is currently rate-limited.');\n clack.log.info('Please wait a minute and try again.');\n } else if (isNetworkError) {\n clack.log.error('Could not connect to the AI service.');\n clack.log.info('Check your internet connection and try again.');\n } else if (isProcessExit) {\n clack.log.error('The AI agent process exited unexpectedly.');\n clack.log.info('Try running again. If this persists, run with --debug for details.');\n } else {\n clack.log.error(message);\n }\n\n // Add actionable hints for common errors\n if (message.includes('authentication') || message.includes('auth')) {\n clack.log.info('Try running: workos auth logout && workos install');\n }\n if (message.includes('ENOENT') || message.includes('not found')) {\n clack.log.info('Ensure you are in a project directory');\n }\n\n if (stack && this.debug) {\n this.debugLog(stack);\n }\n };\n\n private handleBranchPrompt = async ({ branch }: InstallerEvents['branch:prompt']): Promise<void> => {\n this.isPromptActive = true;\n const choice = await clack.select({\n message: `You are on ${chalk.bold(branch)}. Create a feature branch?`,\n options: [\n { value: 'create', label: 'Create feat/add-workos-authkit' },\n { value: 'continue', label: 'Continue on current branch' },\n { value: 'cancel', label: 'Cancel' },\n ],\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n if (clack.isCancel(choice) || choice === 'cancel') {\n this.sendEvent({ type: 'BRANCH_CANCEL' });\n } else if (choice === 'create') {\n this.sendEvent({ type: 'BRANCH_CREATE' });\n } else {\n this.sendEvent({ type: 'BRANCH_CONTINUE' });\n }\n };\n\n private handleBranchCreated = ({ branch }: InstallerEvents['branch:created']): void => {\n this.queueableLog(() => clack.log.success(`Created branch ${chalk.bold(branch)}`));\n };\n\n // ===== Post-install Event Handlers =====\n\n private handlePostInstallChanges = ({ files }: InstallerEvents['postinstall:changes']): void => {\n this.debugLog(`Post-install: ${files.length} changed files detected`);\n };\n\n private handleCommitPrompt = async (): Promise<void> => {\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Commit the changes?',\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'COMMIT_DECLINED' : 'COMMIT_APPROVED',\n });\n };\n\n private handleCommitGenerating = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Generating commit message...');\n };\n\n private handleCommitSuccess = ({ message }: InstallerEvents['postinstall:commit:success']): void => {\n this.stopSpinner('Committed');\n clack.log.success(`Committed: ${chalk.dim(message)}`);\n };\n\n private handleCommitFailed = ({ error }: InstallerEvents['postinstall:commit:failed']): void => {\n this.stopSpinner('Commit failed');\n clack.log.error(`Commit failed: ${error}`);\n };\n\n private handlePrPrompt = async (): Promise<void> => {\n this.isPromptActive = true;\n const confirmed = await clack.confirm({\n message: 'Create a pull request?',\n initialValue: true,\n });\n this.isPromptActive = false;\n this.flushPendingLogs();\n\n this.sendEvent({\n type: clack.isCancel(confirmed) || !confirmed ? 'PR_DECLINED' : 'PR_APPROVED',\n });\n };\n\n private handlePrGenerating = (): void => {\n this.spinner = clack.spinner();\n this.spinner.start('Generating PR description...');\n };\n\n private handlePrPushing = (): void => {\n if (this.spinner) {\n this.spinner.message('Pushing to remote...');\n } else {\n this.spinner = clack.spinner();\n this.spinner.start('Pushing to remote...');\n }\n };\n\n private handlePrSuccess = ({ url }: InstallerEvents['postinstall:pr:success']): void => {\n this.stopSpinner('PR created');\n clack.log.success(`Pull request created: ${chalk.cyan(url)}`);\n };\n\n private handlePrFailed = ({ error }: InstallerEvents['postinstall:pr:failed']): void => {\n this.stopSpinner('PR creation failed');\n clack.log.error(`PR creation failed: ${error}`);\n };\n\n private handlePushFailed = ({ error }: InstallerEvents['postinstall:push:failed']): void => {\n this.stopSpinner('Push failed');\n clack.log.error(`Push failed: ${error}`);\n };\n\n private handleManualInstructions = ({ instructions }: InstallerEvents['postinstall:manual']): void => {\n clack.log.info('GitHub CLI not found. Manual steps:');\n console.log(chalk.dim(instructions));\n };\n}\n"]}
@@ -256,7 +256,29 @@ export class HeadlessAdapter {
256
256
  writeNDJSON({ type: 'complete', success, summary });
257
257
  };
258
258
  handleError = ({ message, stack }) => {
259
- writeNDJSON({ type: 'error', code: 'installer_error', message });
259
+ const isServiceError = /\b50[0-9]\b/.test(message) || /server_error|internal_error|overloaded|service.*unavailable/i.test(message);
260
+ const isRateLimit = /\b429\b/.test(message) || /rate.limit/i.test(message);
261
+ const isNetworkError = /ECONNREFUSED|ETIMEDOUT|ENOTFOUND|fetch failed/i.test(message);
262
+ const isProcessExit = /process exited with code/i.test(message);
263
+ let code = 'installer_error';
264
+ let displayMessage = message;
265
+ if (isServiceError) {
266
+ code = 'service_unavailable';
267
+ displayMessage = 'The AI service is temporarily unavailable. Please try again in a few minutes.';
268
+ }
269
+ else if (isRateLimit) {
270
+ code = 'rate_limited';
271
+ displayMessage = 'The AI service is currently rate-limited. Please wait a minute and try again.';
272
+ }
273
+ else if (isNetworkError) {
274
+ code = 'network_error';
275
+ displayMessage = 'Could not connect to the AI service. Check your internet connection and try again.';
276
+ }
277
+ else if (isProcessExit) {
278
+ code = 'process_error';
279
+ displayMessage = 'The AI agent process exited unexpectedly. Try running again with --debug for details.';
280
+ }
281
+ writeNDJSON({ type: 'error', code, message: displayMessage });
260
282
  this.debugLog(stack ?? '');
261
283
  };
262
284
  }
@@ -1 +1 @@
1
- {"version":3,"file":"headless-adapter.js","sourceRoot":"","sources":["../../../src/lib/adapters/headless-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAerD;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACjB,OAAO,CAAwB;IAChC,SAAS,CAA6B;IACtC,KAAK,CAAU;IACf,OAAO,CAAkB;IACzB,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAG,IAAI,GAAG,EAAwC,CAAC;IAEnE,YAAY,MAAoD;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,cAAc;QACd,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEvD,mBAAmB;QACnB,IAAI,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,EAAQ,EAAE;QACzF,WAAW,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEM,wBAAwB,GAAG,CAAC,EAAE,YAAY,EAAyC,EAAQ,EAAE;QACnG,WAAW,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC;IAEF,8BAA8B;IAEtB,cAAc,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAA+B,EAAQ,EAAE;QACnF,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;IAEM,WAAW,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,EAA4B,EAAQ,EAAE;QAC3E,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC;CACH","sourcesContent":["import type { InstallerAdapter, AdapterConfig } from './types.js';\nimport type { InstallerEventEmitter, InstallerEvents } from '../events.js';\nimport { writeNDJSON } from '../../utils/ndjson.js';\nimport { ExitCode } from '../../utils/exit-codes.js';\n\n/**\n * Options controlling headless adapter behavior.\n * Corresponds to CLI flags passed in non-interactive mode.\n */\nexport interface HeadlessOptions {\n apiKey?: string;\n clientId?: string;\n noBranch?: boolean;\n noCommit?: boolean;\n createPr?: boolean;\n noGitCheck?: boolean;\n}\n\n/**\n * Non-interactive adapter for CI/CD and agent consumption.\n *\n * Subscribes to the same installer events as CLIAdapter but never prompts.\n * All decisions are auto-resolved with sensible defaults (overridable via flags).\n * Progress is streamed as NDJSON to stdout.\n */\nexport class HeadlessAdapter implements InstallerAdapter {\n readonly emitter: InstallerEventEmitter;\n private sendEvent: AdapterConfig['sendEvent'];\n private debug: boolean;\n private options: HeadlessOptions;\n private isStarted = false;\n private handlers = new Map<string, (...args: unknown[]) => void>();\n\n constructor(config: AdapterConfig & { options: HeadlessOptions }) {\n this.emitter = config.emitter;\n this.sendEvent = config.sendEvent;\n this.debug = config.debug ?? false;\n this.options = config.options;\n }\n\n async start(): Promise<void> {\n if (this.isStarted) return;\n this.isStarted = true;\n\n // Auth events\n this.subscribe('auth:success', this.handleAuthSuccess);\n this.subscribe('auth:failure', this.handleAuthFailure);\n\n // Detection events\n this.subscribe('detection:complete', this.handleDetectionComplete);\n this.subscribe('detection:none', this.handleDetectionNone);\n\n // Git events — auto-resolve\n this.subscribe('git:dirty', this.handleGitDirty);\n\n // Credential events — auto-resolve\n this.subscribe('credentials:found', this.handleCredentialsFound);\n this.subscribe('credentials:request', this.handleCredentialsRequest);\n this.subscribe('credentials:env:prompt', this.handleEnvScanPrompt);\n this.subscribe('credentials:env:found', this.handleEnvCredentialsFound);\n\n // Device auth (should not happen in headless, but log if it does)\n this.subscribe('device:started', this.handleDeviceStarted);\n\n // Staging\n this.subscribe('staging:fetching', this.handleStagingFetching);\n this.subscribe('staging:success', this.handleStagingSuccess);\n\n // Config\n this.subscribe('config:complete', this.handleConfigComplete);\n\n // Agent progress\n this.subscribe('agent:start', this.handleAgentStart);\n this.subscribe('agent:progress', this.handleAgentProgress);\n\n // Validation\n this.subscribe('validation:start', this.handleValidationStart);\n this.subscribe('validation:issues', this.handleValidationIssues);\n this.subscribe('validation:complete', this.handleValidationComplete);\n\n // Branch — auto-resolve\n this.subscribe('branch:prompt', this.handleBranchPrompt);\n this.subscribe('branch:created', this.handleBranchCreated);\n\n // Post-install — auto-resolve\n this.subscribe('postinstall:changes', this.handlePostInstallChanges);\n this.subscribe('postinstall:commit:prompt', this.handleCommitPrompt);\n this.subscribe('postinstall:commit:success', this.handleCommitSuccess);\n this.subscribe('postinstall:commit:failed', this.handleCommitFailed);\n this.subscribe('postinstall:pr:prompt', this.handlePrPrompt);\n this.subscribe('postinstall:pr:success', this.handlePrSuccess);\n this.subscribe('postinstall:pr:failed', this.handlePrFailed);\n this.subscribe('postinstall:push:failed', this.handlePushFailed);\n this.subscribe('postinstall:manual', this.handleManualInstructions);\n\n // Terminal events\n this.subscribe('complete', this.handleComplete);\n this.subscribe('error', this.handleError);\n }\n\n async stop(): Promise<void> {\n if (!this.isStarted) return;\n\n for (const [event, handler] of this.handlers) {\n this.emitter.off(event as keyof InstallerEvents, handler as never);\n }\n this.handlers.clear();\n this.isStarted = false;\n }\n\n private subscribe<K extends keyof InstallerEvents>(\n event: K,\n handler: (payload: InstallerEvents[K]) => void | Promise<void>,\n ): void {\n const boundHandler = handler.bind(this);\n this.handlers.set(event, boundHandler as (...args: unknown[]) => void);\n this.emitter.on(event, boundHandler);\n }\n\n private debugLog(message: string): void {\n if (this.debug) {\n writeNDJSON({ type: 'debug', message });\n }\n }\n\n // ===== Auth Handlers =====\n\n private handleAuthSuccess = (): void => {\n writeNDJSON({ type: 'auth:success' });\n };\n\n private handleAuthFailure = ({ message }: InstallerEvents['auth:failure']): void => {\n writeNDJSON({ type: 'auth:required', message });\n process.exit(ExitCode.AUTH_REQUIRED);\n };\n\n // ===== Detection Handlers =====\n\n private handleDetectionComplete = ({ integration }: InstallerEvents['detection:complete']): void => {\n writeNDJSON({ type: 'detection:complete', integration });\n };\n\n private handleDetectionNone = (): void => {\n writeNDJSON({ type: 'detection:none' });\n };\n\n // ===== Git Handlers (auto-resolve) =====\n\n private handleGitDirty = ({ files }: InstallerEvents['git:dirty']): void => {\n writeNDJSON({ type: 'git:status', dirty: true, files });\n\n if (this.options.noGitCheck) {\n writeNDJSON({ type: 'git:decision', action: 'continue' });\n this.sendEvent({ type: 'GIT_CONFIRMED' });\n return;\n }\n\n writeNDJSON({\n type: 'error',\n code: 'git_dirty',\n message:\n 'Git working tree is dirty in non-interactive mode. ' +\n 'Commit or stash your changes, or rerun with --no-git-check to proceed.',\n });\n writeNDJSON({ type: 'git:decision', action: 'cancel' });\n this.sendEvent({ type: 'GIT_CANCELLED' });\n process.exit(ExitCode.GENERAL_ERROR);\n };\n\n // ===== Credential Handlers (auto-resolve) =====\n\n private handleCredentialsFound = (): void => {\n writeNDJSON({ type: 'credentials:found', source: 'env' });\n };\n\n private handleCredentialsRequest = ({ requiresApiKey }: InstallerEvents['credentials:request']): void => {\n if (!this.options.clientId) {\n writeNDJSON({\n type: 'error',\n code: 'missing_credentials',\n message: 'Client ID required in non-interactive mode. Pass --client-id flag.',\n });\n process.exit(ExitCode.GENERAL_ERROR);\n }\n\n if (requiresApiKey && !this.options.apiKey) {\n writeNDJSON({\n type: 'error',\n code: 'missing_credentials',\n message: 'API key required for this framework. Pass --api-key flag.',\n });\n process.exit(ExitCode.GENERAL_ERROR);\n }\n\n writeNDJSON({ type: 'credentials:provided', source: 'flag' });\n this.sendEvent({\n type: 'CREDENTIALS_SUBMITTED',\n apiKey: this.options.apiKey ?? '',\n clientId: this.options.clientId,\n });\n };\n\n private handleEnvScanPrompt = (): void => {\n writeNDJSON({ type: 'credentials:env:scanning' });\n this.sendEvent({ type: 'ENV_SCAN_APPROVED' });\n };\n\n private handleEnvCredentialsFound = ({ sourcePath }: InstallerEvents['credentials:env:found']): void => {\n writeNDJSON({ type: 'credentials:found', source: 'env', sourcePath });\n };\n\n // ===== Device Auth (should not occur in headless) =====\n\n private handleDeviceStarted = ({ verificationUri, userCode }: InstallerEvents['device:started']): void => {\n writeNDJSON({\n type: 'auth:device_required',\n verificationUri,\n userCode,\n message: 'Device auth cannot proceed in non-interactive mode',\n });\n };\n\n // ===== Staging =====\n\n private handleStagingFetching = (): void => {\n writeNDJSON({ type: 'staging:fetching' });\n };\n\n private handleStagingSuccess = (): void => {\n writeNDJSON({ type: 'staging:success' });\n };\n\n // ===== Config =====\n\n private handleConfigComplete = (): void => {\n writeNDJSON({ type: 'config:complete' });\n };\n\n // ===== Agent Progress =====\n\n private handleAgentStart = (): void => {\n writeNDJSON({ type: 'agent:start' });\n };\n\n private handleAgentProgress = ({ step, detail }: InstallerEvents['agent:progress']): void => {\n const message = detail ? `${step}: ${detail}` : step;\n writeNDJSON({ type: 'agent:progress', message });\n };\n\n // ===== Validation =====\n\n private handleValidationStart = ({ framework }: InstallerEvents['validation:start']): void => {\n writeNDJSON({ type: 'validation:start', framework });\n };\n\n private handleValidationIssues = ({ issues }: InstallerEvents['validation:issues']): void => {\n for (const issue of issues) {\n writeNDJSON({ type: 'validation:issue', severity: issue.severity, message: issue.message });\n }\n };\n\n private handleValidationComplete = ({ passed, issueCount }: InstallerEvents['validation:complete']): void => {\n writeNDJSON({ type: 'validation:complete', passed, issues: issueCount });\n };\n\n // ===== Branch (auto-resolve) =====\n\n private handleBranchPrompt = (): void => {\n if (this.options.noBranch) {\n writeNDJSON({ type: 'branch:skipped', reason: '--no-branch flag' });\n this.sendEvent({ type: 'BRANCH_CONTINUE' });\n } else {\n writeNDJSON({ type: 'branch:creating' });\n this.sendEvent({ type: 'BRANCH_CREATE' });\n }\n };\n\n private handleBranchCreated = ({ branch }: InstallerEvents['branch:created']): void => {\n writeNDJSON({ type: 'branch:created', name: branch });\n };\n\n // ===== Post-install (auto-resolve) =====\n\n private handlePostInstallChanges = ({ files }: InstallerEvents['postinstall:changes']): void => {\n writeNDJSON({ type: 'postinstall:changes', files, count: files.length });\n };\n\n private handleCommitPrompt = (): void => {\n if (this.options.noCommit) {\n writeNDJSON({ type: 'commit:skipped', reason: '--no-commit flag' });\n this.sendEvent({ type: 'COMMIT_DECLINED' });\n } else {\n writeNDJSON({ type: 'commit:auto' });\n this.sendEvent({ type: 'COMMIT_APPROVED' });\n }\n };\n\n private handleCommitSuccess = ({ message }: InstallerEvents['postinstall:commit:success']): void => {\n writeNDJSON({ type: 'commit:created', message });\n };\n\n private handleCommitFailed = ({ error }: InstallerEvents['postinstall:commit:failed']): void => {\n writeNDJSON({ type: 'commit:failed', error });\n };\n\n private handlePrPrompt = (): void => {\n if (this.options.createPr) {\n writeNDJSON({ type: 'pr:creating' });\n this.sendEvent({ type: 'PR_APPROVED' });\n } else {\n writeNDJSON({ type: 'pr:skipped', reason: '--create-pr not set' });\n this.sendEvent({ type: 'PR_DECLINED' });\n }\n };\n\n private handlePrSuccess = ({ url }: InstallerEvents['postinstall:pr:success']): void => {\n writeNDJSON({ type: 'pr:created', url });\n };\n\n private handlePrFailed = ({ error }: InstallerEvents['postinstall:pr:failed']): void => {\n writeNDJSON({ type: 'pr:failed', error });\n };\n\n private handlePushFailed = ({ error }: InstallerEvents['postinstall:push:failed']): void => {\n writeNDJSON({ type: 'push:failed', error });\n };\n\n private handleManualInstructions = ({ instructions }: InstallerEvents['postinstall:manual']): void => {\n writeNDJSON({ type: 'postinstall:manual', instructions });\n };\n\n // ===== Terminal Events =====\n\n private handleComplete = ({ success, summary }: InstallerEvents['complete']): void => {\n writeNDJSON({ type: 'complete', success, summary });\n };\n\n private handleError = ({ message, stack }: InstallerEvents['error']): void => {\n writeNDJSON({ type: 'error', code: 'installer_error', message });\n this.debugLog(stack ?? '');\n };\n}\n"]}
1
+ {"version":3,"file":"headless-adapter.js","sourceRoot":"","sources":["../../../src/lib/adapters/headless-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAerD;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACjB,OAAO,CAAwB;IAChC,SAAS,CAA6B;IACtC,KAAK,CAAU;IACf,OAAO,CAAkB;IACzB,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAG,IAAI,GAAG,EAAwC,CAAC;IAEnE,YAAY,MAAoD;QAC9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QACnC,IAAI,CAAC,O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AI,GAAG,iBAAiB,CAAC;QAC7B,IAAI,cAAc,GAAG,OAAO,CAAC;QAE7B,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,GAAG,qBAAqB,CAAC;YAC7B,cAAc,GAAG,+EAA+E,CAAC;QACnG,CAAC;aAAM,IAAI,WAAW,EAAE,CAAC;YACvB,IAAI,GAAG,cAAc,CAAC;YACtB,cAAc,GAAG,+EAA+E,CAAC;QACnG,CAAC;aAAM,IAAI,cAAc,EAAE,CAAC;YAC1B,IAAI,GAAG,eAAe,CAAC;YACvB,cAAc,GAAG,oFAAoF,CAAC;QACxG,CAAC;aAAM,IAAI,aAAa,EAAE,CAAC;YACzB,IAAI,GAAG,eAAe,CAAC;YACvB,cAAc,GAAG,uFAAuF,CAAC;QAC3G,CAAC;QAED,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC7B,CAAC,CAAC;CACH","sourcesContent":["import type { InstallerAdapter, AdapterConfig } from './types.js';\nimport type { InstallerEventEmitter, InstallerEvents } from '../events.js';\nimport { writeNDJSON } from '../../utils/ndjson.js';\nimport { ExitCode } from '../../utils/exit-codes.js';\n\n/**\n * Options controlling headless adapter behavior.\n * Corresponds to CLI flags passed in non-interactive mode.\n */\nexport interface HeadlessOptions {\n apiKey?: string;\n clientId?: string;\n noBranch?: boolean;\n noCommit?: boolean;\n createPr?: boolean;\n noGitCheck?: boolean;\n}\n\n/**\n * Non-interactive adapter for CI/CD and agent consumption.\n *\n * Subscribes to the same installer events as CLIAdapter but never prompts.\n * All decisions are auto-resolved with sensible defaults (overridable via flags).\n * Progress is streamed as NDJSON to stdout.\n */\nexport class HeadlessAdapter implements InstallerAdapter {\n readonly emitter: InstallerEventEmitter;\n private sendEvent: AdapterConfig['sendEvent'];\n private debug: boolean;\n private options: HeadlessOptions;\n private isStarted = false;\n private handlers = new Map<string, (...args: unknown[]) => void>();\n\n constructor(config: AdapterConfig & { options: HeadlessOptions }) {\n this.emitter = config.emitter;\n this.sendEvent = config.sendEvent;\n this.debug = config.debug ?? false;\n this.options = config.options;\n }\n\n async start(): Promise<void> {\n if (this.isStarted) return;\n this.isStarted = true;\n\n // Auth events\n this.subscribe('auth:success', this.handleAuthSuccess);\n this.subscribe('auth:failure', this.handleAuthFailure);\n\n // Detection events\n this.subscribe('detection:complete', this.handleDetectionComplete);\n this.subscribe('detection:none', this.handleDetectionNone);\n\n // Git events — auto-resolve\n this.subscribe('git:dirty', this.handleGitDirty);\n\n // Credential events — auto-resolve\n this.subscribe('credentials:found', this.handleCredentialsFound);\n this.subscribe('credentials:request', this.handleCredentialsRequest);\n this.subscribe('credentials:env:prompt', this.handleEnvScanPrompt);\n this.subscribe('credentials:env:found', this.handleEnvCredentialsFound);\n\n // Device auth (should not happen in headless, but log if it does)\n this.subscribe('device:started', this.handleDeviceStarted);\n\n // Staging\n this.subscribe('staging:fetching', this.handleStagingFetching);\n this.subscribe('staging:success', this.handleStagingSuccess);\n\n // Config\n this.subscribe('config:complete', this.handleConfigComplete);\n\n // Agent progress\n this.subscribe('agent:start', this.handleAgentStart);\n this.subscribe('agent:progress', this.handleAgentProgress);\n\n // Validation\n this.subscribe('validation:start', this.handleValidationStart);\n this.subscribe('validation:issues', this.handleValidationIssues);\n this.subscribe('validation:complete', this.handleValidationComplete);\n\n // Branch — auto-resolve\n this.subscribe('branch:prompt', this.handleBranchPrompt);\n this.subscribe('branch:created', this.handleBranchCreated);\n\n // Post-install — auto-resolve\n this.subscribe('postinstall:changes', this.handlePostInstallChanges);\n this.subscribe('postinstall:commit:prompt', this.handleCommitPrompt);\n this.subscribe('postinstall:commit:success', this.handleCommitSuccess);\n this.subscribe('postinstall:commit:failed', this.handleCommitFailed);\n this.subscribe('postinstall:pr:prompt', this.handlePrPrompt);\n this.subscribe('postinstall:pr:success', this.handlePrSuccess);\n this.subscribe('postinstall:pr:failed', this.handlePrFailed);\n this.subscribe('postinstall:push:failed', this.handlePushFailed);\n this.subscribe('postinstall:manual', this.handleManualInstructions);\n\n // Terminal events\n this.subscribe('complete', this.handleComplete);\n this.subscribe('error', this.handleError);\n }\n\n async stop(): Promise<void> {\n if (!this.isStarted) return;\n\n for (const [event, handler] of this.handlers) {\n this.emitter.off(event as keyof InstallerEvents, handler as never);\n }\n this.handlers.clear();\n this.isStarted = false;\n }\n\n private subscribe<K extends keyof InstallerEvents>(\n event: K,\n handler: (payload: InstallerEvents[K]) => void | Promise<void>,\n ): void {\n const boundHandler = handler.bind(this);\n this.handlers.set(event, boundHandler as (...args: unknown[]) => void);\n this.emitter.on(event, boundHandler);\n }\n\n private debugLog(message: string): void {\n if (this.debug) {\n writeNDJSON({ type: 'debug', message });\n }\n }\n\n // ===== Auth Handlers =====\n\n private handleAuthSuccess = (): void => {\n writeNDJSON({ type: 'auth:success' });\n };\n\n private handleAuthFailure = ({ message }: InstallerEvents['auth:failure']): void => {\n writeNDJSON({ type: 'auth:required', message });\n process.exit(ExitCode.AUTH_REQUIRED);\n };\n\n // ===== Detection Handlers =====\n\n private handleDetectionComplete = ({ integration }: InstallerEvents['detection:complete']): void => {\n writeNDJSON({ type: 'detection:complete', integration });\n };\n\n private handleDetectionNone = (): void => {\n writeNDJSON({ type: 'detection:none' });\n };\n\n // ===== Git Handlers (auto-resolve) =====\n\n private handleGitDirty = ({ files }: InstallerEvents['git:dirty']): void => {\n writeNDJSON({ type: 'git:status', dirty: true, files });\n\n if (this.options.noGitCheck) {\n writeNDJSON({ type: 'git:decision', action: 'continue' });\n this.sendEvent({ type: 'GIT_CONFIRMED' });\n return;\n }\n\n writeNDJSON({\n type: 'error',\n code: 'git_dirty',\n message:\n 'Git working tree is dirty in non-interactive mode. ' +\n 'Commit or stash your changes, or rerun with --no-git-check to proceed.',\n });\n writeNDJSON({ type: 'git:decision', action: 'cancel' });\n this.sendEvent({ type: 'GIT_CANCELLED' });\n process.exit(ExitCode.GENERAL_ERROR);\n };\n\n // ===== Credential Handlers (auto-resolve) =====\n\n private handleCredentialsFound = (): void => {\n writeNDJSON({ type: 'credentials:found', source: 'env' });\n };\n\n private handleCredentialsRequest = ({ requiresApiKey }: InstallerEvents['credentials:request']): void => {\n if (!this.options.clientId) {\n writeNDJSON({\n type: 'error',\n code: 'missing_credentials',\n message: 'Client ID required in non-interactive mode. Pass --client-id flag.',\n });\n process.exit(ExitCode.GENERAL_ERROR);\n }\n\n if (requiresApiKey && !this.options.apiKey) {\n writeNDJSON({\n type: 'error',\n code: 'missing_credentials',\n message: 'API key required for this framework. Pass --api-key flag.',\n });\n process.exit(ExitCode.GENERAL_ERROR);\n }\n\n writeNDJSON({ type: 'credentials:provided', source: 'flag' });\n this.sendEvent({\n type: 'CREDENTIALS_SUBMITTED',\n apiKey: this.options.apiKey ?? '',\n clientId: this.options.clientId,\n });\n };\n\n private handleEnvScanPrompt = (): void => {\n writeNDJSON({ type: 'credentials:env:scanning' });\n this.sendEvent({ type: 'ENV_SCAN_APPROVED' });\n };\n\n private handleEnvCredentialsFound = ({ sourcePath }: InstallerEvents['credentials:env:found']): void => {\n writeNDJSON({ type: 'credentials:found', source: 'env', sourcePath });\n };\n\n // ===== Device Auth (should not occur in headless) =====\n\n private handleDeviceStarted = ({ verificationUri, userCode }: InstallerEvents['device:started']): void => {\n writeNDJSON({\n type: 'auth:device_required',\n verificationUri,\n userCode,\n message: 'Device auth cannot proceed in non-interactive mode',\n });\n };\n\n // ===== Staging =====\n\n private handleStagingFetching = (): void => {\n writeNDJSON({ type: 'staging:fetching' });\n };\n\n private handleStagingSuccess = (): void => {\n writeNDJSON({ type: 'staging:success' });\n };\n\n // ===== Config =====\n\n private handleConfigComplete = (): void => {\n writeNDJSON({ type: 'config:complete' });\n };\n\n // ===== Agent Progress =====\n\n private handleAgentStart = (): void => {\n writeNDJSON({ type: 'agent:start' });\n };\n\n private handleAgentProgress = ({ step, detail }: InstallerEvents['agent:progress']): void => {\n const message = detail ? `${step}: ${detail}` : step;\n writeNDJSON({ type: 'agent:progress', message });\n };\n\n // ===== Validation =====\n\n private handleValidationStart = ({ framework }: InstallerEvents['validation:start']): void => {\n writeNDJSON({ type: 'validation:start', framework });\n };\n\n private handleValidationIssues = ({ issues }: InstallerEvents['validation:issues']): void => {\n for (const issue of issues) {\n writeNDJSON({ type: 'validation:issue', severity: issue.severity, message: issue.message });\n }\n };\n\n private handleValidationComplete = ({ passed, issueCount }: InstallerEvents['validation:complete']): void => {\n writeNDJSON({ type: 'validation:complete', passed, issues: issueCount });\n };\n\n // ===== Branch (auto-resolve) =====\n\n private handleBranchPrompt = (): void => {\n if (this.options.noBranch) {\n writeNDJSON({ type: 'branch:skipped', reason: '--no-branch flag' });\n this.sendEvent({ type: 'BRANCH_CONTINUE' });\n } else {\n writeNDJSON({ type: 'branch:creating' });\n this.sendEvent({ type: 'BRANCH_CREATE' });\n }\n };\n\n private handleBranchCreated = ({ branch }: InstallerEvents['branch:created']): void => {\n writeNDJSON({ type: 'branch:created', name: branch });\n };\n\n // ===== Post-install (auto-resolve) =====\n\n private handlePostInstallChanges = ({ files }: InstallerEvents['postinstall:changes']): void => {\n writeNDJSON({ type: 'postinstall:changes', files, count: files.length });\n };\n\n private handleCommitPrompt = (): void => {\n if (this.options.noCommit) {\n writeNDJSON({ type: 'commit:skipped', reason: '--no-commit flag' });\n this.sendEvent({ type: 'COMMIT_DECLINED' });\n } else {\n writeNDJSON({ type: 'commit:auto' });\n this.sendEvent({ type: 'COMMIT_APPROVED' });\n }\n };\n\n private handleCommitSuccess = ({ message }: InstallerEvents['postinstall:commit:success']): void => {\n writeNDJSON({ type: 'commit:created', message });\n };\n\n private handleCommitFailed = ({ error }: InstallerEvents['postinstall:commit:failed']): void => {\n writeNDJSON({ type: 'commit:failed', error });\n };\n\n private handlePrPrompt = (): void => {\n if (this.options.createPr) {\n writeNDJSON({ type: 'pr:creating' });\n this.sendEvent({ type: 'PR_APPROVED' });\n } else {\n writeNDJSON({ type: 'pr:skipped', reason: '--create-pr not set' });\n this.sendEvent({ type: 'PR_DECLINED' });\n }\n };\n\n private handlePrSuccess = ({ url }: InstallerEvents['postinstall:pr:success']): void => {\n writeNDJSON({ type: 'pr:created', url });\n };\n\n private handlePrFailed = ({ error }: InstallerEvents['postinstall:pr:failed']): void => {\n writeNDJSON({ type: 'pr:failed', error });\n };\n\n private handlePushFailed = ({ error }: InstallerEvents['postinstall:push:failed']): void => {\n writeNDJSON({ type: 'push:failed', error });\n };\n\n private handleManualInstructions = ({ instructions }: InstallerEvents['postinstall:manual']): void => {\n writeNDJSON({ type: 'postinstall:manual', instructions });\n };\n\n // ===== Terminal Events =====\n\n private handleComplete = ({ success, summary }: InstallerEvents['complete']): void => {\n writeNDJSON({ type: 'complete', success, summary });\n };\n\n private handleError = ({ message, stack }: InstallerEvents['error']): void => {\n const isServiceError =\n /\\b50[0-9]\\b/.test(message) || /server_error|internal_error|overloaded|service.*unavailable/i.test(message);\n const isRateLimit = /\\b429\\b/.test(message) || /rate.limit/i.test(message);\n const isNetworkError = /ECONNREFUSED|ETIMEDOUT|ENOTFOUND|fetch failed/i.test(message);\n const isProcessExit = /process exited with code/i.test(message);\n\n let code = 'installer_error';\n let displayMessage = message;\n\n if (isServiceError) {\n code = 'service_unavailable';\n displayMessage = 'The AI service is temporarily unavailable. Please try again in a few minutes.';\n } else if (isRateLimit) {\n code = 'rate_limited';\n displayMessage = 'The AI service is currently rate-limited. Please wait a minute and try again.';\n } else if (isNetworkError) {\n code = 'network_error';\n displayMessage = 'Could not connect to the AI service. Check your internet connection and try again.';\n } else if (isProcessExit) {\n code = 'process_error';\n displayMessage = 'The AI agent process exited unexpectedly. Try running again with --debug for details.';\n }\n\n writeNDJSON({ type: 'error', code, message: displayMessage });\n this.debugLog(stack ?? '');\n };\n}\n"]}
@@ -25,7 +25,9 @@ export declare enum AgentErrorType {
25
25
  /** Agent could not access the setup resource */
26
26
  RESOURCE_MISSING = "INSTALLER_RESOURCE_MISSING",
27
27
  /** Agent execution failed (API error, auth error, etc.) */
28
- EXECUTION_ERROR = "INSTALLER_EXECUTION_ERROR"
28
+ EXECUTION_ERROR = "INSTALLER_EXECUTION_ERROR",
29
+ /** AI service is unavailable (API 500, outage, etc.) */
30
+ SERVICE_UNAVAILABLE = "INSTALLER_SERVICE_UNAVAILABLE"
29
31
  }
30
32
  export type AgentConfig = {
31
33
  workingDirectory: string;
@@ -39,6 +39,10 @@ export const AgentSignals = {
39
39
  /** Signal emitted when the agent cannot access the setup resource */
40
40
  ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',
41
41
  };
42
+ /** Internal prefix used to tag service-unavailability errors from handleSDKMessage */
43
+ const SERVICE_UNAVAILABLE_PREFIX = '__SERVICE_UNAVAILABLE__';
44
+ /** Internal prefix used to tag rate-limit errors from handleSDKMessage */
45
+ const RATE_LIMITED_PREFIX = '__RATE_LIMITED__';
42
46
  /**
43
47
  * Error types that can be returned from agent execution.
44
48
  * These correspond to the error signals that the agent emits.
@@ -51,6 +55,8 @@ export var AgentErrorType;
51
55
  AgentErrorType["RESOURCE_MISSING"] = "INSTALLER_RESOURCE_MISSING";
52
56
  /** Agent execution failed (API error, auth error, etc.) */
53
57
  AgentErrorType["EXECUTION_ERROR"] = "INSTALLER_EXECUTION_ERROR";
58
+ /** AI service is unavailable (API 500, outage, etc.) */
59
+ AgentErrorType["SERVICE_UNAVAILABLE"] = "INSTALLER_SERVICE_UNAVAILABLE";
54
60
  })(AgentErrorType || (AgentErrorType = {}));
55
61
  /**
56
62
  * Package managers that can be used to run commands.
@@ -440,6 +446,10 @@ export async function runAgent(agentConfig, prompt, options, config, emitter, re
440
446
  // message arrives; the prompt generator awaits currentTurnDone between turns.
441
447
  let resolveCurrentTurn;
442
448
  let currentTurnDone;
449
+ // Set by the message loop when a fatal SDK error is detected (e.g. service
450
+ // unavailability). The prompt stream checks this before yielding retry
451
+ // prompts so we fail fast instead of burning minutes on hopeless retries.
452
+ let abortRetries = false;
443
453
  function resetTurnSignal() {
444
454
  currentTurnDone = new Promise((resolve) => {
445
455
  resolveCurrentTurn = resolve;
@@ -456,6 +466,11 @@ export async function runAgent(agentConfig, prompt, options, config, emitter, re
456
466
  if (retryConfig && maxRetries > 0) {
457
467
  while (retryCount < maxRetries) {
458
468
  await currentTurnDone;
469
+ // Don't send correction prompts when the service itself is down
470
+ if (abortRetries) {
471
+ logInfo('Skipping validation retries due to service error');
472
+ break;
473
+ }
459
474
  emitter?.emit('validation:retry:start', { attempt: retryCount + 1 });
460
475
  let validationPrompt;
461
476
  try {
@@ -520,6 +535,8 @@ export async function runAgent(agentConfig, prompt, options, config, emitter, re
520
535
  const messageError = handleSDKMessage(message, options, collectedText, emitter);
521
536
  if (messageError) {
522
537
  sdkError = messageError;
538
+ // Signal the prompt stream to stop yielding retry prompts
539
+ abortRetries = true;
523
540
  }
524
541
  if (message.type === 'result') {
525
542
  resolveCurrentTurn();
@@ -536,6 +553,22 @@ export async function runAgent(agentConfig, prompt, options, config, emitter, re
536
553
  // Check for SDK errors first (e.g., API errors, auth failures)
537
554
  // Return error type + message - caller decides whether to throw or emit events
538
555
  if (sdkError) {
556
+ if (sdkError.startsWith(SERVICE_UNAVAILABLE_PREFIX)) {
557
+ const detail = sdkError.slice(SERVICE_UNAVAILABLE_PREFIX.length);
558
+ logError('AI service unavailable:', detail);
559
+ return {
560
+ error: AgentErrorType.SERVICE_UNAVAILABLE,
561
+ errorMessage: 'The AI service is temporarily unavailable. Please try again in a few minutes.',
562
+ };
563
+ }
564
+ if (sdkError.startsWith(RATE_LIMITED_PREFIX)) {
565
+ const detail = sdkError.slice(RATE_LIMITED_PREFIX.length);
566
+ logError('AI service rate-limited:', detail);
567
+ return {
568
+ error: AgentErrorType.SERVICE_UNAVAILABLE,
569
+ errorMessage: 'The AI service is currently rate-limited. Please wait a minute and try again.',
570
+ };
571
+ }
539
572
  logError('Agent SDK error:', sdkError);
540
573
  return { error: AgentErrorType.EXECUTION_ERROR, errorMessage: sdkError };
541
574
  }
@@ -702,6 +735,22 @@ function handleSDKMessage(message, options, collectedText, emitter) {
702
735
  break;
703
736
  }
704
737
  case 'result': {
738
+ // The SDK may return subtype 'success' with is_error: true when API
739
+ // retries are exhausted (e.g., persistent 500s). Check is_error first.
740
+ const isResultError = message.is_error === true;
741
+ if (isResultError) {
742
+ const resultText = typeof message.result === 'string' ? message.result : '';
743
+ logError('Agent result marked as error:', resultText);
744
+ // Detect rate limiting (429) — check before 5xx so it gets distinct messaging
745
+ if (/\b429\b/.test(resultText) || /rate.limit/i.test(resultText)) {
746
+ return `${RATE_LIMITED_PREFIX}${resultText}`;
747
+ }
748
+ // Detect service unavailability (API 500, upstream outage)
749
+ if (/\b50[0-9]\b/.test(resultText) || /server_error|internal_error|overloaded/.test(resultText)) {
750
+ return `${SERVICE_UNAVAILABLE_PREFIX}${resultText}`;
751
+ }
752
+ return resultText || 'Agent execution failed';
753
+ }
705
754
  if (message.subtype === 'success') {
706
755
  logInfo('Agent completed successfully');
707
756
  if (typeof message.result === 'string') {