mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-18 10:23:07 +00:00
fix: Remove unused vars and improve type safety. Improve task recovery
This commit is contained in:
@@ -8,9 +8,6 @@ import { spawn, execSync } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { createLogger } from '@automaker/utils';
|
||||
|
||||
const logger = createLogger('CliDetection');
|
||||
|
||||
export interface CliInfo {
|
||||
name: string;
|
||||
@@ -86,7 +83,7 @@ export async function detectCli(
|
||||
options: CliDetectionOptions = {}
|
||||
): Promise<CliDetectionResult> {
|
||||
const config = CLI_CONFIGS[provider];
|
||||
const { timeout = 5000, includeWsl = false, wslDistribution } = options;
|
||||
const { timeout = 5000 } = options;
|
||||
const issues: string[] = [];
|
||||
|
||||
const cliInfo: CliInfo = {
|
||||
|
||||
@@ -40,7 +40,7 @@ export interface ErrorClassification {
|
||||
suggestedAction?: string;
|
||||
retryable: boolean;
|
||||
provider?: string;
|
||||
context?: Record<string, any>;
|
||||
context?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ErrorPattern {
|
||||
@@ -180,7 +180,7 @@ const ERROR_PATTERNS: ErrorPattern[] = [
|
||||
export function classifyError(
|
||||
error: unknown,
|
||||
provider?: string,
|
||||
context?: Record<string, any>
|
||||
context?: Record<string, unknown>
|
||||
): ErrorClassification {
|
||||
const errorText = getErrorText(error);
|
||||
|
||||
@@ -281,18 +281,19 @@ function getErrorText(error: unknown): string {
|
||||
|
||||
if (typeof error === 'object' && error !== null) {
|
||||
// Handle structured error objects
|
||||
const errorObj = error as any;
|
||||
const errorObj = error as Record<string, unknown>;
|
||||
|
||||
if (errorObj.message) {
|
||||
if (typeof errorObj.message === 'string') {
|
||||
return errorObj.message;
|
||||
}
|
||||
|
||||
if (errorObj.error?.message) {
|
||||
return errorObj.error.message;
|
||||
const nestedError = errorObj.error;
|
||||
if (typeof nestedError === 'object' && nestedError !== null && 'message' in nestedError) {
|
||||
return String((nestedError as Record<string, unknown>).message);
|
||||
}
|
||||
|
||||
if (errorObj.error) {
|
||||
return typeof errorObj.error === 'string' ? errorObj.error : JSON.stringify(errorObj.error);
|
||||
if (nestedError) {
|
||||
return typeof nestedError === 'string' ? nestedError : JSON.stringify(nestedError);
|
||||
}
|
||||
|
||||
return JSON.stringify(error);
|
||||
@@ -307,7 +308,7 @@ function getErrorText(error: unknown): string {
|
||||
export function createErrorResponse(
|
||||
error: unknown,
|
||||
provider?: string,
|
||||
context?: Record<string, any>
|
||||
context?: Record<string, unknown>
|
||||
): {
|
||||
success: false;
|
||||
error: string;
|
||||
@@ -335,7 +336,7 @@ export function logError(
|
||||
error: unknown,
|
||||
provider?: string,
|
||||
operation?: string,
|
||||
additionalContext?: Record<string, any>
|
||||
additionalContext?: Record<string, unknown>
|
||||
): void {
|
||||
const classification = classifyError(error, provider, {
|
||||
operation,
|
||||
|
||||
@@ -12,11 +12,18 @@ export interface PermissionCheckResult {
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
/** Minimal shape of a Cursor tool call used for permission checking */
|
||||
interface CursorToolCall {
|
||||
shellToolCall?: { args?: { command: string } };
|
||||
readToolCall?: { args?: { path: string } };
|
||||
writeToolCall?: { args?: { path: string } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a tool call is allowed based on permissions
|
||||
*/
|
||||
export function checkToolCallPermission(
|
||||
toolCall: any,
|
||||
toolCall: CursorToolCall,
|
||||
permissions: CursorCliConfigFile | null
|
||||
): PermissionCheckResult {
|
||||
if (!permissions || !permissions.permissions) {
|
||||
@@ -152,7 +159,11 @@ function matchesRule(toolName: string, rule: string): boolean {
|
||||
/**
|
||||
* Log permission violations
|
||||
*/
|
||||
export function logPermissionViolation(toolCall: any, reason: string, sessionId?: string): void {
|
||||
export function logPermissionViolation(
|
||||
toolCall: CursorToolCall,
|
||||
reason: string,
|
||||
sessionId?: string
|
||||
): void {
|
||||
const sessionIdStr = sessionId ? ` [${sessionId}]` : '';
|
||||
|
||||
if (toolCall.shellToolCall?.args?.command) {
|
||||
|
||||
@@ -78,7 +78,7 @@ export async function readWorktreeMetadata(
|
||||
const metadataPath = getWorktreeMetadataPath(projectPath, branch);
|
||||
const content = (await secureFs.readFile(metadataPath, 'utf-8')) as string;
|
||||
return JSON.parse(content) as WorktreeMetadata;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// File doesn't exist or can't be read
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user