| |
| |
| |
| |
| |
| |
|
|
| import * as fs from 'fs/promises'; |
| import * as path from 'path'; |
| import { createLogger } from '@automaker/utils'; |
| import { COPILOT_DISCONNECTED_MARKER_FILE } from '../routes/setup/common.js'; |
|
|
| const logger = createLogger('CopilotConnectionService'); |
|
|
| |
| |
| |
| function getMarkerPath(projectRoot?: string): string { |
| const root = projectRoot || process.cwd(); |
| const automakerDir = path.join(root, '.automaker'); |
| return path.join(automakerDir, COPILOT_DISCONNECTED_MARKER_FILE); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function connectCopilot(projectRoot?: string): Promise<void> { |
| const markerPath = getMarkerPath(projectRoot); |
|
|
| try { |
| await fs.unlink(markerPath); |
| logger.info('Copilot CLI connected to app (marker removed)'); |
| } catch (error) { |
| |
| if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { |
| logger.error('Failed to remove disconnected marker:', error); |
| throw error; |
| } |
| logger.debug('Copilot already connected (no marker file found)'); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function disconnectCopilot(projectRoot?: string): Promise<void> { |
| const root = projectRoot || process.cwd(); |
| const automakerDir = path.join(root, '.automaker'); |
| const markerPath = path.join(automakerDir, COPILOT_DISCONNECTED_MARKER_FILE); |
|
|
| |
| await fs.mkdir(automakerDir, { recursive: true }); |
|
|
| |
| await fs.writeFile(markerPath, 'Copilot CLI disconnected from app'); |
| logger.info('Copilot CLI disconnected from app (marker created)'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function isCopilotConnected(projectRoot?: string): Promise<boolean> { |
| const markerPath = getMarkerPath(projectRoot); |
|
|
| try { |
| await fs.access(markerPath); |
| return false; |
| } catch { |
| return true; |
| } |
| } |
|
|