Merge branch 'AutoMaker-Org:main' into feat/claude-usage-clean

This commit is contained in:
Mohamad Yahia
2025-12-21 09:18:13 +04:00
committed by GitHub
183 changed files with 9233 additions and 2472 deletions

View File

@@ -14,7 +14,7 @@ import { createServer } from "http";
import dotenv from "dotenv";
import { createEventEmitter, type EventEmitter } from "./lib/events.js";
import { initAllowedPaths } from "./lib/security.js";
import { initAllowedPaths } from "@automaker/platform";
import { authMiddleware, getAuthStatus } from "./lib/auth.js";
import { createFsRoutes } from "./routes/fs/index.js";
import { createHealthRoutes } from "./routes/health/index.js";

View File

@@ -5,121 +5,9 @@
* app specifications to ensure consistency across the application.
*/
/**
* TypeScript interface for structured spec output
*/
export interface SpecOutput {
project_name: string;
overview: string;
technology_stack: string[];
core_capabilities: string[];
implemented_features: Array<{
name: string;
description: string;
file_locations?: string[];
}>;
additional_requirements?: string[];
development_guidelines?: string[];
implementation_roadmap?: Array<{
phase: string;
status: "completed" | "in_progress" | "pending";
description: string;
}>;
}
/**
* JSON Schema for structured spec output
* Used with Claude's structured output feature for reliable parsing
*/
export const specOutputSchema = {
type: "object",
properties: {
project_name: {
type: "string",
description: "The name of the project",
},
overview: {
type: "string",
description:
"A comprehensive description of what the project does, its purpose, and key goals",
},
technology_stack: {
type: "array",
items: { type: "string" },
description:
"List of all technologies, frameworks, libraries, and tools used",
},
core_capabilities: {
type: "array",
items: { type: "string" },
description: "List of main features and capabilities the project provides",
},
implemented_features: {
type: "array",
items: {
type: "object",
properties: {
name: {
type: "string",
description: "Name of the implemented feature",
},
description: {
type: "string",
description: "Description of what the feature does",
},
file_locations: {
type: "array",
items: { type: "string" },
description: "File paths where this feature is implemented",
},
},
required: ["name", "description"],
},
description: "Features that have been implemented based on code analysis",
},
additional_requirements: {
type: "array",
items: { type: "string" },
description: "Any additional requirements or constraints",
},
development_guidelines: {
type: "array",
items: { type: "string" },
description: "Development standards and practices",
},
implementation_roadmap: {
type: "array",
items: {
type: "object",
properties: {
phase: {
type: "string",
description: "Name of the implementation phase",
},
status: {
type: "string",
enum: ["completed", "in_progress", "pending"],
description: "Current status of this phase",
},
description: {
type: "string",
description: "Description of what this phase involves",
},
},
required: ["phase", "status", "description"],
},
description: "Phases or roadmap items for implementation",
},
},
required: [
"project_name",
"overview",
"technology_stack",
"core_capabilities",
"implemented_features",
],
additionalProperties: false,
};
// Import and re-export spec types from shared package
export type { SpecOutput } from "@automaker/types";
export { specOutputSchema } from "@automaker/types";
/**
* Escape special XML characters
@@ -136,7 +24,7 @@ function escapeXml(str: string): string {
/**
* Convert structured spec output to XML format
*/
export function specToXml(spec: SpecOutput): string {
export function specToXml(spec: import("@automaker/types").SpecOutput): string {
const indent = " ";
let xml = `<?xml version="1.0" encoding="UTF-8"?>

View File

@@ -1,216 +0,0 @@
/**
* Automaker Paths - Utilities for managing automaker data storage
*
* Provides functions to construct paths for:
* - Project-level data stored in {projectPath}/.automaker/
* - Global user data stored in app userData directory
*
* All returned paths are absolute and ready to use with fs module.
* Directory creation is handled separately by ensure* functions.
*/
import * as secureFs from "./secure-fs.js";
import path from "path";
/**
* Get the automaker data directory root for a project
*
* All project-specific automaker data is stored under {projectPath}/.automaker/
* This directory is created when needed via ensureAutomakerDir().
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker
*/
export function getAutomakerDir(projectPath: string): string {
return path.join(projectPath, ".automaker");
}
/**
* Get the features directory for a project
*
* Contains subdirectories for each feature, keyed by featureId.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/features
*/
export function getFeaturesDir(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "features");
}
/**
* Get the directory for a specific feature
*
* Contains feature-specific data like generated code, tests, and logs.
*
* @param projectPath - Absolute path to project directory
* @param featureId - Feature identifier
* @returns Absolute path to {projectPath}/.automaker/features/{featureId}
*/
export function getFeatureDir(projectPath: string, featureId: string): string {
return path.join(getFeaturesDir(projectPath), featureId);
}
/**
* Get the images directory for a feature
*
* Stores screenshots, diagrams, or other images related to the feature.
*
* @param projectPath - Absolute path to project directory
* @param featureId - Feature identifier
* @returns Absolute path to {projectPath}/.automaker/features/{featureId}/images
*/
export function getFeatureImagesDir(
projectPath: string,
featureId: string
): string {
return path.join(getFeatureDir(projectPath, featureId), "images");
}
/**
* Get the board directory for a project
*
* Contains board-related data like background images and customization files.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/board
*/
export function getBoardDir(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "board");
}
/**
* Get the general images directory for a project
*
* Stores project-level images like background images or shared assets.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/images
*/
export function getImagesDir(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "images");
}
/**
* Get the context files directory for a project
*
* Stores user-uploaded context files for reference during generation.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/context
*/
export function getContextDir(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "context");
}
/**
* Get the worktrees metadata directory for a project
*
* Stores information about git worktrees associated with the project.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/worktrees
*/
export function getWorktreesDir(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "worktrees");
}
/**
* Get the app spec file path for a project
*
* Stores the application specification document used for generation.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/app_spec.txt
*/
export function getAppSpecPath(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "app_spec.txt");
}
/**
* Get the branch tracking file path for a project
*
* Stores JSON metadata about active git branches and worktrees.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/active-branches.json
*/
export function getBranchTrackingPath(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "active-branches.json");
}
/**
* Create the automaker directory structure for a project if it doesn't exist
*
* Creates {projectPath}/.automaker with all subdirectories recursively.
* Safe to call multiple times - uses recursive: true.
*
* @param projectPath - Absolute path to project directory
* @returns Promise resolving to the created automaker directory path
*/
export async function ensureAutomakerDir(projectPath: string): Promise<string> {
const automakerDir = getAutomakerDir(projectPath);
await secureFs.mkdir(automakerDir, { recursive: true });
return automakerDir;
}
// ============================================================================
// Global Settings Paths (stored in DATA_DIR from app.getPath('userData'))
// ============================================================================
/**
* Get the global settings file path
*
* Stores user preferences, keyboard shortcuts, AI profiles, and project history.
* Located in the platform-specific userData directory.
*
* Default locations:
* - macOS: ~/Library/Application Support/automaker
* - Windows: %APPDATA%\automaker
* - Linux: ~/.config/automaker
*
* @param dataDir - User data directory (from app.getPath('userData'))
* @returns Absolute path to {dataDir}/settings.json
*/
export function getGlobalSettingsPath(dataDir: string): string {
return path.join(dataDir, "settings.json");
}
/**
* Get the credentials file path
*
* Stores sensitive API keys separately from other settings for security.
* Located in the platform-specific userData directory.
*
* @param dataDir - User data directory (from app.getPath('userData'))
* @returns Absolute path to {dataDir}/credentials.json
*/
export function getCredentialsPath(dataDir: string): string {
return path.join(dataDir, "credentials.json");
}
/**
* Get the project settings file path
*
* Stores project-specific settings that override global settings.
* Located within the project's .automaker directory.
*
* @param projectPath - Absolute path to project directory
* @returns Absolute path to {projectPath}/.automaker/settings.json
*/
export function getProjectSettingsPath(projectPath: string): string {
return path.join(getAutomakerDir(projectPath), "settings.json");
}
/**
* Create the global data directory if it doesn't exist
*
* Creates the userData directory for storing global settings and credentials.
* Safe to call multiple times - uses recursive: true.
*
* @param dataDir - User data directory path to create
* @returns Promise resolving to the created data directory path
*/
export async function ensureDataDir(dataDir: string): Promise<string> {
await secureFs.mkdir(dataDir, { recursive: true });
return dataDir;
}

View File

@@ -1,97 +0,0 @@
/**
* Conversation history utilities for processing message history
*
* Provides standardized conversation history handling:
* - Extract text from content (string or array format)
* - Normalize content blocks to array format
* - Format history as plain text for CLI-based providers
* - Convert history to Claude SDK message format
*/
import type { ConversationMessage } from "../providers/types.js";
/**
* Extract plain text from message content (handles both string and array formats)
*
* @param content - Message content (string or array of content blocks)
* @returns Extracted text content
*/
export function extractTextFromContent(
content: string | Array<{ type: string; text?: string; source?: object }>
): string {
if (typeof content === "string") {
return content;
}
// Extract text blocks only
return content
.filter((block) => block.type === "text")
.map((block) => block.text || "")
.join("\n");
}
/**
* Normalize message content to array format
*
* @param content - Message content (string or array)
* @returns Content as array of blocks
*/
export function normalizeContentBlocks(
content: string | Array<{ type: string; text?: string; source?: object }>
): Array<{ type: string; text?: string; source?: object }> {
if (Array.isArray(content)) {
return content;
}
return [{ type: "text", text: content }];
}
/**
* Format conversation history as plain text for CLI-based providers
*
* @param history - Array of conversation messages
* @returns Formatted text with role labels
*/
export function formatHistoryAsText(history: ConversationMessage[]): string {
if (history.length === 0) {
return "";
}
let historyText = "Previous conversation:\n\n";
for (const msg of history) {
const contentText = extractTextFromContent(msg.content);
const role = msg.role === "user" ? "User" : "Assistant";
historyText += `${role}: ${contentText}\n\n`;
}
historyText += "---\n\n";
return historyText;
}
/**
* Convert conversation history to Claude SDK message format
*
* @param history - Array of conversation messages
* @returns Array of Claude SDK formatted messages
*/
export function convertHistoryToMessages(
history: ConversationMessage[]
): Array<{
type: "user" | "assistant";
session_id: string;
message: {
role: "user" | "assistant";
content: Array<{ type: string; text?: string; source?: object }>;
};
parent_tool_use_id: null;
}> {
return history.map((historyMsg) => ({
type: historyMsg.role,
session_id: "",
message: {
role: historyMsg.role,
content: normalizeContentBlocks(historyMsg.content),
},
parent_tool_use_id: null,
}));
}

View File

@@ -1,221 +0,0 @@
/**
* Dependency Resolution Utility (Server-side)
*
* Provides topological sorting and dependency analysis for features.
* Uses a modified Kahn's algorithm that respects both dependencies and priorities.
*/
import type { Feature } from "../services/feature-loader.js";
export interface DependencyResolutionResult {
orderedFeatures: Feature[]; // Features in dependency-aware order
circularDependencies: string[][]; // Groups of IDs forming cycles
missingDependencies: Map<string, string[]>; // featureId -> missing dep IDs
blockedFeatures: Map<string, string[]>; // featureId -> blocking dep IDs (incomplete dependencies)
}
/**
* Resolves feature dependencies using topological sort with priority-aware ordering.
*
* Algorithm:
* 1. Build dependency graph and detect missing/blocked dependencies
* 2. Apply Kahn's algorithm for topological sort
* 3. Within same dependency level, sort by priority (1=high, 2=medium, 3=low)
* 4. Detect circular dependencies for features that can't be ordered
*
* @param features - Array of features to order
* @returns Resolution result with ordered features and dependency metadata
*/
export function resolveDependencies(features: Feature[]): DependencyResolutionResult {
const featureMap = new Map<string, Feature>(features.map(f => [f.id, f]));
const inDegree = new Map<string, number>();
const adjacencyList = new Map<string, string[]>(); // dependencyId -> [dependentIds]
const missingDependencies = new Map<string, string[]>();
const blockedFeatures = new Map<string, string[]>();
// Initialize graph structures
for (const feature of features) {
inDegree.set(feature.id, 0);
adjacencyList.set(feature.id, []);
}
// Build dependency graph and detect missing/blocked dependencies
for (const feature of features) {
const deps = feature.dependencies || [];
for (const depId of deps) {
if (!featureMap.has(depId)) {
// Missing dependency - track it
if (!missingDependencies.has(feature.id)) {
missingDependencies.set(feature.id, []);
}
missingDependencies.get(feature.id)!.push(depId);
} else {
// Valid dependency - add edge to graph
adjacencyList.get(depId)!.push(feature.id);
inDegree.set(feature.id, (inDegree.get(feature.id) || 0) + 1);
// Check if dependency is incomplete (blocking)
const depFeature = featureMap.get(depId)!;
if (depFeature.status !== 'completed' && depFeature.status !== 'verified') {
if (!blockedFeatures.has(feature.id)) {
blockedFeatures.set(feature.id, []);
}
blockedFeatures.get(feature.id)!.push(depId);
}
}
}
}
// Kahn's algorithm with priority-aware selection
const queue: Feature[] = [];
const orderedFeatures: Feature[] = [];
// Helper to sort features by priority (lower number = higher priority)
const sortByPriority = (a: Feature, b: Feature) =>
(a.priority ?? 2) - (b.priority ?? 2);
// Start with features that have no dependencies (in-degree 0)
for (const [id, degree] of inDegree) {
if (degree === 0) {
queue.push(featureMap.get(id)!);
}
}
// Sort initial queue by priority
queue.sort(sortByPriority);
// Process features in topological order
while (queue.length > 0) {
// Take highest priority feature from queue
const current = queue.shift()!;
orderedFeatures.push(current);
// Process features that depend on this one
for (const dependentId of adjacencyList.get(current.id) || []) {
const currentDegree = inDegree.get(dependentId);
if (currentDegree === undefined) {
throw new Error(`In-degree not initialized for feature ${dependentId}`);
}
const newDegree = currentDegree - 1;
inDegree.set(dependentId, newDegree);
if (newDegree === 0) {
queue.push(featureMap.get(dependentId)!);
// Re-sort queue to maintain priority order
queue.sort(sortByPriority);
}
}
}
// Detect circular dependencies (features not in output = part of cycle)
const circularDependencies: string[][] = [];
const processedIds = new Set(orderedFeatures.map(f => f.id));
if (orderedFeatures.length < features.length) {
// Find cycles using DFS
const remaining = features.filter(f => !processedIds.has(f.id));
const cycles = detectCycles(remaining, featureMap);
circularDependencies.push(...cycles);
// Add remaining features at end (part of cycles)
orderedFeatures.push(...remaining);
}
return {
orderedFeatures,
circularDependencies,
missingDependencies,
blockedFeatures
};
}
/**
* Detects circular dependencies using depth-first search
*
* @param features - Features that couldn't be topologically sorted (potential cycles)
* @param featureMap - Map of all features by ID
* @returns Array of cycles, where each cycle is an array of feature IDs
*/
function detectCycles(
features: Feature[],
featureMap: Map<string, Feature>
): string[][] {
const cycles: string[][] = [];
const visited = new Set<string>();
const recursionStack = new Set<string>();
const currentPath: string[] = [];
function dfs(featureId: string): boolean {
visited.add(featureId);
recursionStack.add(featureId);
currentPath.push(featureId);
const feature = featureMap.get(featureId);
if (feature) {
for (const depId of feature.dependencies || []) {
if (!visited.has(depId)) {
if (dfs(depId)) return true;
} else if (recursionStack.has(depId)) {
// Found cycle - extract it
const cycleStart = currentPath.indexOf(depId);
cycles.push(currentPath.slice(cycleStart));
return true;
}
}
}
currentPath.pop();
recursionStack.delete(featureId);
return false;
}
for (const feature of features) {
if (!visited.has(feature.id)) {
dfs(feature.id);
}
}
return cycles;
}
/**
* Checks if a feature's dependencies are satisfied (all complete or verified)
*
* @param feature - Feature to check
* @param allFeatures - All features in the project
* @returns true if all dependencies are satisfied, false otherwise
*/
export function areDependenciesSatisfied(
feature: Feature,
allFeatures: Feature[]
): boolean {
if (!feature.dependencies || feature.dependencies.length === 0) {
return true; // No dependencies = always ready
}
return feature.dependencies.every((depId: string) => {
const dep = allFeatures.find(f => f.id === depId);
return dep && (dep.status === 'completed' || dep.status === 'verified');
});
}
/**
* Gets the blocking dependencies for a feature (dependencies that are incomplete)
*
* @param feature - Feature to check
* @param allFeatures - All features in the project
* @returns Array of feature IDs that are blocking this feature
*/
export function getBlockingDependencies(
feature: Feature,
allFeatures: Feature[]
): string[] {
if (!feature.dependencies || feature.dependencies.length === 0) {
return [];
}
return feature.dependencies.filter((depId: string) => {
const dep = allFeatures.find(f => f.id === depId);
return dep && dep.status !== 'completed' && dep.status !== 'verified';
});
}

View File

@@ -1,456 +1,25 @@
/**
* Enhancement Prompts Library - AI-powered text enhancement for task descriptions
* Enhancement Prompts - Re-exported from @automaker/prompts
*
* Provides prompt templates and utilities for enhancing user-written task descriptions:
* - Improve: Transform vague requests into clear, actionable tasks
* - Technical: Add implementation details and technical specifications
* - Simplify: Make verbose descriptions concise and focused
* - Acceptance: Add testable acceptance criteria
*
* Uses chain-of-thought prompting with few-shot examples for consistent results.
* This file now re-exports enhancement prompts from the shared @automaker/prompts package
* to maintain backward compatibility with existing imports in the server codebase.
*/
/**
* Available enhancement modes for transforming task descriptions
*/
export type EnhancementMode = "improve" | "technical" | "simplify" | "acceptance";
/**
* Example input/output pair for few-shot learning
*/
export interface EnhancementExample {
input: string;
output: string;
}
/**
* System prompt for the "improve" enhancement mode.
* Transforms vague or unclear requests into clear, actionable task descriptions.
*/
export const IMPROVE_SYSTEM_PROMPT = `You are an expert at transforming vague, unclear, or incomplete task descriptions into clear, actionable specifications.
Your task is to take a user's rough description and improve it by:
1. ANALYZE the input:
- Identify the core intent behind the request
- Note any ambiguities or missing details
- Determine what success would look like
2. CLARIFY the scope:
- Define clear boundaries for the task
- Identify implicit requirements
- Add relevant context that may be assumed
3. STRUCTURE the output:
- Write a clear, actionable title
- Provide a concise description of what needs to be done
- Break down into specific sub-tasks if appropriate
4. ENHANCE with details:
- Add specific, measurable outcomes where possible
- Include edge cases to consider
- Note any dependencies or prerequisites
Output ONLY the improved task description. Do not include explanations, markdown formatting, or meta-commentary about your changes.`;
/**
* System prompt for the "technical" enhancement mode.
* Adds implementation details and technical specifications.
*/
export const TECHNICAL_SYSTEM_PROMPT = `You are a senior software engineer skilled at adding technical depth to feature descriptions.
Your task is to enhance a task description with technical implementation details:
1. ANALYZE the requirement:
- Understand the functional goal
- Identify the technical domain (frontend, backend, database, etc.)
- Consider the likely tech stack based on context
2. ADD technical specifications:
- Suggest specific technologies, libraries, or patterns
- Define API contracts or data structures if relevant
- Note performance considerations
- Identify security implications
3. OUTLINE implementation approach:
- Break down into technical sub-tasks
- Suggest file structure or component organization
- Note integration points with existing systems
4. CONSIDER edge cases:
- Error handling requirements
- Loading and empty states
- Boundary conditions
Output ONLY the enhanced technical description. Keep it concise but comprehensive. Do not include explanations about your reasoning.`;
/**
* System prompt for the "simplify" enhancement mode.
* Makes verbose descriptions concise and focused.
*/
export const SIMPLIFY_SYSTEM_PROMPT = `You are an expert editor who excels at making verbose text concise without losing meaning.
Your task is to simplify a task description while preserving essential information:
1. IDENTIFY the core message:
- Extract the primary goal or requirement
- Note truly essential details
- Separate nice-to-have from must-have information
2. ELIMINATE redundancy:
- Remove repeated information
- Cut unnecessary qualifiers and hedging language
- Remove filler words and phrases
3. CONSOLIDATE related points:
- Merge overlapping requirements
- Group related items together
- Use concise language
4. PRESERVE critical details:
- Keep specific technical requirements
- Retain important constraints
- Maintain actionable specifics
Output ONLY the simplified description. Aim for 30-50% reduction in length while keeping all essential information. Do not explain your changes.`;
/**
* System prompt for the "acceptance" enhancement mode.
* Adds testable acceptance criteria to task descriptions.
*/
export const ACCEPTANCE_SYSTEM_PROMPT = `You are a QA specialist skilled at defining testable acceptance criteria for software features.
Your task is to enhance a task description by adding clear acceptance criteria:
1. UNDERSTAND the feature:
- Identify all user-facing behaviors
- Note system state changes
- Consider different user roles or scenarios
2. DEFINE acceptance criteria using Given-When-Then format:
- Given: The initial context or preconditions
- When: The action or trigger
- Then: The expected outcome
3. COVER key scenarios:
- Happy path (successful completion)
- Edge cases (boundary conditions)
- Error scenarios (what should NOT happen)
- Performance requirements if relevant
4. MAKE criteria testable:
- Use specific, measurable outcomes
- Avoid vague terms like "quickly" or "easily"
- Include specific values where applicable
Output the original description followed by a clear "Acceptance Criteria:" section with numbered, testable criteria. Do not include explanations about your process.`;
/**
* Few-shot examples for the "improve" enhancement mode
*/
export const IMPROVE_EXAMPLES: EnhancementExample[] = [
{
input: "add dark mode",
output: `Add Dark Mode Theme Support
Implement a dark mode option that allows users to switch between light and dark themes throughout the application.
Requirements:
- Add a theme toggle switch in the settings area
- Store user's theme preference persistently
- Apply dark theme colors to all UI components
- Respect system preference as default if user hasn't set a preference
- Ensure smooth transition when switching themes`,
},
{
input: "fix the login bug",
output: `Fix Login Authentication Flow
Investigate and resolve issues preventing users from successfully logging in to the application.
Requirements:
- Identify the specific failure point in the login process
- Ensure proper credential validation
- Handle error states with clear user feedback
- Verify session token is correctly stored after successful login
- Test with various credential combinations (valid, invalid, edge cases)`,
},
{
input: "make it faster",
output: `Improve Application Performance
Optimize application loading and response times to enhance user experience.
Requirements:
- Profile current performance to identify bottlenecks
- Implement code splitting and lazy loading for routes/components
- Optimize database queries and add appropriate indexes
- Add caching for frequently accessed data
- Set performance budget targets (e.g., LCP < 2.5s, FID < 100ms)
- Measure and document improvements`,
},
];
/**
* Few-shot examples for the "technical" enhancement mode
*/
export const TECHNICAL_EXAMPLES: EnhancementExample[] = [
{
input: "Add user profile page",
output: `Add User Profile Page
Create a dedicated profile page for viewing and editing user information.
Technical Implementation:
- Frontend: React component at /profile route with form validation
- API Endpoint: GET/PUT /api/users/:id for fetching and updating profile
- Data Model: Extend User schema with profile fields (avatar, bio, preferences)
- File Upload: Integrate cloud storage for avatar images with client-side resizing
- State Management: Use optimistic updates for better UX
- Validation: Server-side validation matching client-side rules
Components:
- ProfileHeader (avatar, name, edit button)
- ProfileForm (editable fields with validation)
- AvatarUploader (drag-drop with preview)
Security: Ensure users can only edit their own profile (auth middleware)`,
},
{
input: "Add search functionality",
output: `Add Search Functionality
Implement full-text search across application content.
Technical Implementation:
- Search Engine: Use Elasticsearch or PostgreSQL full-text search
- API: GET /api/search?q={query}&type={type}&page={page}
- Indexing: Create search index with relevant fields, update on content changes
- Frontend: Debounced search input (300ms) with typeahead suggestions
- Results: Paginated results with highlighted matching text
Architecture:
- SearchService class handling query building and execution
- SearchIndex worker for background indexing
- SearchResults component with filtering and sorting
Performance:
- Implement search result caching (Redis, 5-minute TTL)
- Limit results per page (20 items)
- Add query complexity limits to prevent abuse`,
},
];
/**
* Few-shot examples for the "simplify" enhancement mode
*/
export const SIMPLIFY_EXAMPLES: EnhancementExample[] = [
{
input: `We need to implement a feature that would allow our users to be able to export their data in various different formats. The formats we are thinking about supporting include CSV which is commonly used for spreadsheet applications, and also JSON which is good for developers, and possibly PDF for people who want a printable version. The user should be able to go somewhere in the UI and select which format they want and then download their data in that format. We should probably also show some kind of progress indicator while the export is happening since it might take a while for large datasets.`,
output: `Add Data Export Feature
Allow users to export their data in CSV, JSON, or PDF format.
Requirements:
- Add export button/menu in the UI
- Support three formats: CSV (spreadsheets), JSON (developers), PDF (printing)
- Show progress indicator during export
- Handle large datasets gracefully`,
},
{
input: `The current notification system is not working very well and users are complaining about it. Sometimes they don't receive notifications at all, and other times they receive too many notifications and feel overwhelmed. We also have had reports that the notifications are not appearing correctly on mobile devices. Additionally, some users have requested the ability to customize which types of notifications they receive. We should look into all of these issues and make the notification system work better overall.`,
output: `Fix and Improve Notification System
Address reliability issues and add user controls for notifications.
Issues to fix:
- Missing notifications (delivery reliability)
- Notification overload (implement batching/digest)
- Mobile display problems
Enhancements:
- Add notification preferences (per-type controls)
- Test across devices and platforms`,
},
];
/**
* Few-shot examples for the "acceptance" enhancement mode
*/
export const ACCEPTANCE_EXAMPLES: EnhancementExample[] = [
{
input: "Add password reset functionality",
output: `Add Password Reset Functionality
Allow users to reset their password via email when they forget it.
Acceptance Criteria:
1. Given a user is on the login page, when they click "Forgot Password", then they should see a password reset form requesting their email.
2. Given a user enters a valid registered email, when they submit the form, then they should receive a password reset email within 2 minutes.
3. Given a user clicks the reset link in their email, when the link is less than 1 hour old, then they should see a form to enter a new password.
4. Given a user enters a new valid password (min 8 chars, 1 number, 1 special char), when they submit, then their password should be updated and they should be redirected to login.
5. Given a user enters an unregistered email, when they submit the reset form, then they should see the same success message (security: don't reveal which emails exist).
6. Given a reset link older than 1 hour, when a user clicks it, then they should see an expiration message with option to request a new link.`,
},
{
input: "Shopping cart checkout",
output: `Shopping Cart Checkout
Implement the checkout flow for purchasing items in the shopping cart.
Acceptance Criteria:
1. Given a user has items in their cart, when they click "Checkout", then they should see an order summary with item details and total price.
2. Given a user is on the checkout page, when they enter valid shipping information, then the form should validate in real-time and show estimated delivery date.
3. Given valid shipping info is entered, when the user proceeds to payment, then they should see available payment methods (credit card, PayPal).
4. Given valid payment details are entered, when the user confirms the order, then the payment should be processed and order confirmation displayed within 5 seconds.
5. Given a successful order, when confirmation is shown, then the user should receive an email receipt and their cart should be emptied.
6. Given a payment failure, when the error occurs, then the user should see a clear error message and their cart should remain intact.
7. Given the user closes the browser during checkout, when they return, then their cart contents should still be available.`,
},
];
/**
* Map of enhancement modes to their system prompts
*/
const SYSTEM_PROMPTS: Record<EnhancementMode, string> = {
improve: IMPROVE_SYSTEM_PROMPT,
technical: TECHNICAL_SYSTEM_PROMPT,
simplify: SIMPLIFY_SYSTEM_PROMPT,
acceptance: ACCEPTANCE_SYSTEM_PROMPT,
};
/**
* Map of enhancement modes to their few-shot examples
*/
const EXAMPLES: Record<EnhancementMode, EnhancementExample[]> = {
improve: IMPROVE_EXAMPLES,
technical: TECHNICAL_EXAMPLES,
simplify: SIMPLIFY_EXAMPLES,
acceptance: ACCEPTANCE_EXAMPLES,
};
/**
* Enhancement prompt configuration returned by getEnhancementPrompt
*/
export interface EnhancementPromptConfig {
/** System prompt for the enhancement mode */
systemPrompt: string;
/** Description of what this mode does */
description: string;
}
/**
* Descriptions for each enhancement mode
*/
const MODE_DESCRIPTIONS: Record<EnhancementMode, string> = {
improve: "Transform vague requests into clear, actionable task descriptions",
technical: "Add implementation details and technical specifications",
simplify: "Make verbose descriptions concise and focused",
acceptance: "Add testable acceptance criteria to task descriptions",
};
/**
* Get the enhancement prompt configuration for a given mode
*
* @param mode - The enhancement mode (falls back to 'improve' if invalid)
* @returns The enhancement prompt configuration
*/
export function getEnhancementPrompt(mode: string): EnhancementPromptConfig {
const normalizedMode = mode.toLowerCase() as EnhancementMode;
const validMode = normalizedMode in SYSTEM_PROMPTS ? normalizedMode : "improve";
return {
systemPrompt: SYSTEM_PROMPTS[validMode],
description: MODE_DESCRIPTIONS[validMode],
};
}
/**
* Get the system prompt for a specific enhancement mode
*
* @param mode - The enhancement mode to get the prompt for
* @returns The system prompt string
*/
export function getSystemPrompt(mode: EnhancementMode): string {
return SYSTEM_PROMPTS[mode];
}
/**
* Get the few-shot examples for a specific enhancement mode
*
* @param mode - The enhancement mode to get examples for
* @returns Array of input/output example pairs
*/
export function getExamples(mode: EnhancementMode): EnhancementExample[] {
return EXAMPLES[mode];
}
/**
* Build a user prompt for enhancement with optional few-shot examples
*
* @param mode - The enhancement mode
* @param text - The text to enhance
* @param includeExamples - Whether to include few-shot examples (default: true)
* @returns The formatted user prompt string
*/
export function buildUserPrompt(
mode: EnhancementMode,
text: string,
includeExamples: boolean = true
): string {
const examples = includeExamples ? getExamples(mode) : [];
if (examples.length === 0) {
return `Please enhance the following task description:\n\n${text}`;
}
// Build few-shot examples section
const examplesSection = examples
.map(
(example, index) =>
`Example ${index + 1}:\nInput: ${example.input}\nOutput: ${example.output}`
)
.join("\n\n---\n\n");
return `Here are some examples of how to enhance task descriptions:
${examplesSection}
---
Now, please enhance the following task description:
${text}`;
}
/**
* Check if a mode is a valid enhancement mode
*
* @param mode - The mode to check
* @returns True if the mode is valid
*/
export function isValidEnhancementMode(mode: string): mode is EnhancementMode {
return mode in SYSTEM_PROMPTS;
}
/**
* Get all available enhancement modes
*
* @returns Array of available enhancement mode names
*/
export function getAvailableEnhancementModes(): EnhancementMode[] {
return Object.keys(SYSTEM_PROMPTS) as EnhancementMode[];
}
export {
IMPROVE_SYSTEM_PROMPT,
TECHNICAL_SYSTEM_PROMPT,
SIMPLIFY_SYSTEM_PROMPT,
ACCEPTANCE_SYSTEM_PROMPT,
IMPROVE_EXAMPLES,
TECHNICAL_EXAMPLES,
SIMPLIFY_EXAMPLES,
ACCEPTANCE_EXAMPLES,
getEnhancementPrompt,
getSystemPrompt,
getExamples,
buildUserPrompt,
isValidEnhancementMode,
getAvailableEnhancementModes,
} from '@automaker/prompts';
export type { EnhancementMode, EnhancementExample } from '@automaker/prompts';

View File

@@ -1,125 +0,0 @@
/**
* Error handling utilities for standardized error classification
*
* Provides utilities for:
* - Detecting abort/cancellation errors
* - Detecting authentication errors
* - Classifying errors by type
* - Generating user-friendly error messages
*/
/**
* Check if an error is an abort/cancellation error
*
* @param error - The error to check
* @returns True if the error is an abort error
*/
export function isAbortError(error: unknown): boolean {
return (
error instanceof Error &&
(error.name === "AbortError" || error.message.includes("abort"))
);
}
/**
* Check if an error is a user-initiated cancellation
*
* @param errorMessage - The error message to check
* @returns True if the error is a user-initiated cancellation
*/
export function isCancellationError(errorMessage: string): boolean {
const lowerMessage = errorMessage.toLowerCase();
return (
lowerMessage.includes("cancelled") ||
lowerMessage.includes("canceled") ||
lowerMessage.includes("stopped") ||
lowerMessage.includes("aborted")
);
}
/**
* Check if an error is an authentication/API key error
*
* @param errorMessage - The error message to check
* @returns True if the error is authentication-related
*/
export function isAuthenticationError(errorMessage: string): boolean {
return (
errorMessage.includes("Authentication failed") ||
errorMessage.includes("Invalid API key") ||
errorMessage.includes("authentication_failed") ||
errorMessage.includes("Fix external API key")
);
}
/**
* Error type classification
*/
export type ErrorType = "authentication" | "cancellation" | "abort" | "execution" | "unknown";
/**
* Classified error information
*/
export interface ErrorInfo {
type: ErrorType;
message: string;
isAbort: boolean;
isAuth: boolean;
isCancellation: boolean;
originalError: unknown;
}
/**
* Classify an error into a specific type
*
* @param error - The error to classify
* @returns Classified error information
*/
export function classifyError(error: unknown): ErrorInfo {
const message = error instanceof Error ? error.message : String(error || "Unknown error");
const isAbort = isAbortError(error);
const isAuth = isAuthenticationError(message);
const isCancellation = isCancellationError(message);
let type: ErrorType;
if (isAuth) {
type = "authentication";
} else if (isAbort) {
type = "abort";
} else if (isCancellation) {
type = "cancellation";
} else if (error instanceof Error) {
type = "execution";
} else {
type = "unknown";
}
return {
type,
message,
isAbort,
isAuth,
isCancellation,
originalError: error,
};
}
/**
* Get a user-friendly error message
*
* @param error - The error to convert
* @returns User-friendly error message
*/
export function getUserFriendlyErrorMessage(error: unknown): string {
const info = classifyError(error);
if (info.isAbort) {
return "Operation was cancelled";
}
if (info.isAuth) {
return "Authentication failed. Please check your API key.";
}
return info.message;
}

View File

@@ -2,31 +2,10 @@
* Event emitter for streaming events to WebSocket clients
*/
export type EventType =
| "agent:stream"
| "auto-mode:event"
| "auto-mode:started"
| "auto-mode:stopped"
| "auto-mode:idle"
| "auto-mode:error"
| "feature:started"
| "feature:completed"
| "feature:stopped"
| "feature:error"
| "feature:progress"
| "feature:tool-use"
| "feature:follow-up-started"
| "feature:follow-up-completed"
| "feature:verified"
| "feature:committed"
| "project:analysis-started"
| "project:analysis-progress"
| "project:analysis-completed"
| "project:analysis-error"
| "suggestions:event"
| "spec-regeneration:event";
import type { EventType, EventCallback } from "@automaker/types";
export type EventCallback = (type: EventType, payload: unknown) => void;
// Re-export event types from shared package
export type { EventType, EventCallback };
export interface EventEmitter {
emit: (type: EventType, payload: unknown) => void;

View File

@@ -1,67 +0,0 @@
/**
* File system utilities that handle symlinks safely
*/
import * as secureFs from "./secure-fs.js";
import path from "path";
/**
* Create a directory, handling symlinks safely to avoid ELOOP errors.
* If the path already exists as a directory or symlink, returns success.
*/
export async function mkdirSafe(dirPath: string): Promise<void> {
const resolvedPath = path.resolve(dirPath);
// Check if path already exists using lstat (doesn't follow symlinks)
try {
const stats = await secureFs.lstat(resolvedPath);
// Path exists - if it's a directory or symlink, consider it success
if (stats.isDirectory() || stats.isSymbolicLink()) {
return;
}
// It's a file - can't create directory
throw new Error(`Path exists and is not a directory: ${resolvedPath}`);
} catch (error: any) {
// ENOENT means path doesn't exist - we should create it
if (error.code !== "ENOENT") {
// Some other error (could be ELOOP in parent path)
// If it's ELOOP, the path involves symlinks - don't try to create
if (error.code === "ELOOP") {
console.warn(`[fs-utils] Symlink loop detected at ${resolvedPath}, skipping mkdir`);
return;
}
throw error;
}
}
// Path doesn't exist, create it
try {
await secureFs.mkdir(resolvedPath, { recursive: true });
} catch (error: any) {
// Handle race conditions and symlink issues
if (error.code === "EEXIST" || error.code === "ELOOP") {
return;
}
throw error;
}
}
/**
* Check if a path exists, handling symlinks safely.
* Returns true if the path exists as a file, directory, or symlink.
*/
export async function existsSafe(filePath: string): Promise<boolean> {
try {
await secureFs.lstat(filePath);
return true;
} catch (error: any) {
if (error.code === "ENOENT") {
return false;
}
// ELOOP or other errors - path exists but is problematic
if (error.code === "ELOOP") {
return true; // Symlink exists, even if looping
}
throw error;
}
}

View File

@@ -1,135 +0,0 @@
/**
* Image handling utilities for processing image files
*
* Provides utilities for:
* - MIME type detection based on file extensions
* - Base64 encoding of image files
* - Content block generation for Claude SDK format
* - Path resolution (relative/absolute)
*/
import * as secureFs from "./secure-fs.js";
import path from "path";
/**
* MIME type mapping for image file extensions
*/
const IMAGE_MIME_TYPES: Record<string, string> = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
} as const;
/**
* Image data with base64 encoding and metadata
*/
export interface ImageData {
base64: string;
mimeType: string;
filename: string;
originalPath: string;
}
/**
* Content block for image (Claude SDK format)
*/
export interface ImageContentBlock {
type: "image";
source: {
type: "base64";
media_type: string;
data: string;
};
}
/**
* Get MIME type for an image file based on extension
*
* @param imagePath - Path to the image file
* @returns MIME type string (defaults to "image/png" for unknown extensions)
*/
export function getMimeTypeForImage(imagePath: string): string {
const ext = path.extname(imagePath).toLowerCase();
return IMAGE_MIME_TYPES[ext] || "image/png";
}
/**
* Read an image file and convert to base64 with metadata
*
* @param imagePath - Path to the image file
* @returns Promise resolving to image data with base64 encoding
* @throws Error if file cannot be read
*/
export async function readImageAsBase64(imagePath: string): Promise<ImageData> {
const imageBuffer = await secureFs.readFile(imagePath) as Buffer;
const base64Data = imageBuffer.toString("base64");
const mimeType = getMimeTypeForImage(imagePath);
return {
base64: base64Data,
mimeType,
filename: path.basename(imagePath),
originalPath: imagePath,
};
}
/**
* Convert image paths to content blocks (Claude SDK format)
* Handles both relative and absolute paths
*
* @param imagePaths - Array of image file paths
* @param workDir - Optional working directory for resolving relative paths
* @returns Promise resolving to array of image content blocks
*/
export async function convertImagesToContentBlocks(
imagePaths: string[],
workDir?: string
): Promise<ImageContentBlock[]> {
const blocks: ImageContentBlock[] = [];
for (const imagePath of imagePaths) {
try {
// Resolve to absolute path if needed
const absolutePath = workDir && !path.isAbsolute(imagePath)
? path.join(workDir, imagePath)
: imagePath;
const imageData = await readImageAsBase64(absolutePath);
blocks.push({
type: "image",
source: {
type: "base64",
media_type: imageData.mimeType,
data: imageData.base64,
},
});
} catch (error) {
console.error(`[ImageHandler] Failed to load image ${imagePath}:`, error);
// Continue processing other images
}
}
return blocks;
}
/**
* Build a list of image paths for text prompts
* Formats image paths as a bulleted list for inclusion in text prompts
*
* @param imagePaths - Array of image file paths
* @returns Formatted string with image paths, or empty string if no images
*/
export function formatImagePathsForPrompt(imagePaths: string[]): string {
if (imagePaths.length === 0) {
return "";
}
let text = "\n\nAttached images:\n";
for (const imagePath of imagePaths) {
text += `- ${imagePath}\n`;
}
return text;
}

View File

@@ -1,75 +0,0 @@
/**
* Simple logger utility with log levels
* Configure via LOG_LEVEL environment variable: error, warn, info, debug
* Defaults to 'info' if not set
*/
export enum LogLevel {
ERROR = 0,
WARN = 1,
INFO = 2,
DEBUG = 3,
}
const LOG_LEVEL_NAMES: Record<string, LogLevel> = {
error: LogLevel.ERROR,
warn: LogLevel.WARN,
info: LogLevel.INFO,
debug: LogLevel.DEBUG,
};
let currentLogLevel: LogLevel = LogLevel.INFO;
// Initialize log level from environment variable
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase();
if (envLogLevel && LOG_LEVEL_NAMES[envLogLevel] !== undefined) {
currentLogLevel = LOG_LEVEL_NAMES[envLogLevel];
}
/**
* Create a logger instance with a context prefix
*/
export function createLogger(context: string) {
const prefix = `[${context}]`;
return {
error: (...args: unknown[]): void => {
if (currentLogLevel >= LogLevel.ERROR) {
console.error(prefix, ...args);
}
},
warn: (...args: unknown[]): void => {
if (currentLogLevel >= LogLevel.WARN) {
console.warn(prefix, ...args);
}
},
info: (...args: unknown[]): void => {
if (currentLogLevel >= LogLevel.INFO) {
console.log(prefix, ...args);
}
},
debug: (...args: unknown[]): void => {
if (currentLogLevel >= LogLevel.DEBUG) {
console.log(prefix, "[DEBUG]", ...args);
}
},
};
}
/**
* Get the current log level
*/
export function getLogLevel(): LogLevel {
return currentLogLevel;
}
/**
* Set the log level programmatically (useful for testing)
*/
export function setLogLevel(level: LogLevel): void {
currentLogLevel = level;
}

View File

@@ -1,79 +0,0 @@
/**
* Model resolution utilities for handling model string mapping
*
* Provides centralized model resolution logic:
* - Maps Claude model aliases to full model strings
* - Provides default models per provider
* - Handles multiple model sources with priority
*/
/**
* Model alias mapping for Claude models
*/
export const CLAUDE_MODEL_MAP: Record<string, string> = {
haiku: "claude-haiku-4-5",
sonnet: "claude-sonnet-4-20250514",
opus: "claude-opus-4-5-20251101",
} as const;
/**
* Default models per provider
*/
export const DEFAULT_MODELS = {
claude: "claude-opus-4-5-20251101",
} as const;
/**
* Resolve a model key/alias to a full model string
*
* @param modelKey - Model key (e.g., "opus", "gpt-5.2", "claude-sonnet-4-20250514")
* @param defaultModel - Fallback model if modelKey is undefined
* @returns Full model string
*/
export function resolveModelString(
modelKey?: string,
defaultModel: string = DEFAULT_MODELS.claude
): string {
// No model specified - use default
if (!modelKey) {
return defaultModel;
}
// Full Claude model string - pass through unchanged
if (modelKey.includes("claude-")) {
console.log(`[ModelResolver] Using full Claude model string: ${modelKey}`);
return modelKey;
}
// Look up Claude model alias
const resolved = CLAUDE_MODEL_MAP[modelKey];
if (resolved) {
console.log(
`[ModelResolver] Resolved model alias: "${modelKey}" -> "${resolved}"`
);
return resolved;
}
// Unknown model key - use default
console.warn(
`[ModelResolver] Unknown model key "${modelKey}", using default: "${defaultModel}"`
);
return defaultModel;
}
/**
* Get the effective model from multiple sources
* Priority: explicit model > session model > default
*
* @param explicitModel - Explicitly provided model (highest priority)
* @param sessionModel - Model from session (medium priority)
* @param defaultModel - Fallback default model (lowest priority)
* @returns Resolved model string
*/
export function getEffectiveModel(
explicitModel?: string,
sessionModel?: string,
defaultModel?: string
): string {
return resolveModelString(explicitModel || sessionModel, defaultModel);
}

View File

@@ -1,79 +0,0 @@
/**
* Prompt building utilities for constructing prompts with images
*
* Provides standardized prompt building that:
* - Combines text prompts with image attachments
* - Handles content block array generation
* - Optionally includes image paths in text
* - Supports both vision and non-vision models
*/
import { convertImagesToContentBlocks, formatImagePathsForPrompt } from "./image-handler.js";
/**
* Content that can be either simple text or structured blocks
*/
export type PromptContent = string | Array<{
type: string;
text?: string;
source?: object;
}>;
/**
* Result of building a prompt with optional images
*/
export interface PromptWithImages {
content: PromptContent;
hasImages: boolean;
}
/**
* Build a prompt with optional image attachments
*
* @param basePrompt - The text prompt
* @param imagePaths - Optional array of image file paths
* @param workDir - Optional working directory for resolving relative paths
* @param includeImagePaths - Whether to append image paths to the text (default: false)
* @returns Promise resolving to prompt content and metadata
*/
export async function buildPromptWithImages(
basePrompt: string,
imagePaths?: string[],
workDir?: string,
includeImagePaths: boolean = false
): Promise<PromptWithImages> {
// No images - return plain text
if (!imagePaths || imagePaths.length === 0) {
return { content: basePrompt, hasImages: false };
}
// Build text content with optional image path listing
let textContent = basePrompt;
if (includeImagePaths) {
textContent += formatImagePathsForPrompt(imagePaths);
}
// Build content blocks array
const contentBlocks: Array<{
type: string;
text?: string;
source?: object;
}> = [];
// Add text block if we have text
if (textContent.trim()) {
contentBlocks.push({ type: "text", text: textContent });
}
// Add image blocks
const imageBlocks = await convertImagesToContentBlocks(imagePaths, workDir);
contentBlocks.push(...imageBlocks);
// Return appropriate format
const content: PromptContent =
contentBlocks.length > 1 || contentBlocks[0]?.type === "image"
? contentBlocks
: textContent;
return { content, hasImages: true };
}

View File

@@ -12,11 +12,8 @@
*/
import type { Options } from "@anthropic-ai/claude-agent-sdk";
import {
resolveModelString,
DEFAULT_MODELS,
CLAUDE_MODEL_MAP,
} from "./model-resolver.js";
import { resolveModelString } from "@automaker/model-resolver";
import { DEFAULT_MODELS, CLAUDE_MODEL_MAP } from "@automaker/types";
/**
* Tool presets for different use cases

View File

@@ -1,168 +1,23 @@
/**
* Secure File System Adapter
*
* All file I/O operations must go through this adapter to enforce
* ALLOWED_ROOT_DIRECTORY restrictions at the actual access point,
* not just at the API layer. This provides defense-in-depth security.
* Re-export secure file system utilities from @automaker/platform
* This file exists for backward compatibility with existing imports
*/
import fs from "fs/promises";
import type { Dirent } from "fs";
import path from "path";
import { validatePath } from "./security.js";
import { secureFs } from "@automaker/platform";
/**
* Wrapper around fs.access that validates path first
*/
export async function access(filePath: string, mode?: number): Promise<void> {
const validatedPath = validatePath(filePath);
return fs.access(validatedPath, mode);
}
/**
* Wrapper around fs.readFile that validates path first
*/
export async function readFile(
filePath: string,
encoding?: BufferEncoding
): Promise<string | Buffer> {
const validatedPath = validatePath(filePath);
if (encoding) {
return fs.readFile(validatedPath, encoding);
}
return fs.readFile(validatedPath);
}
/**
* Wrapper around fs.writeFile that validates path first
*/
export async function writeFile(
filePath: string,
data: string | Buffer,
encoding?: BufferEncoding
): Promise<void> {
const validatedPath = validatePath(filePath);
return fs.writeFile(validatedPath, data, encoding);
}
/**
* Wrapper around fs.mkdir that validates path first
*/
export async function mkdir(
dirPath: string,
options?: { recursive?: boolean; mode?: number }
): Promise<string | undefined> {
const validatedPath = validatePath(dirPath);
return fs.mkdir(validatedPath, options);
}
/**
* Wrapper around fs.readdir that validates path first
*/
export async function readdir(
dirPath: string,
options?: { withFileTypes?: false; encoding?: BufferEncoding }
): Promise<string[]>;
export async function readdir(
dirPath: string,
options: { withFileTypes: true; encoding?: BufferEncoding }
): Promise<Dirent[]>;
export async function readdir(
dirPath: string,
options?: { withFileTypes?: boolean; encoding?: BufferEncoding }
): Promise<string[] | Dirent[]> {
const validatedPath = validatePath(dirPath);
if (options?.withFileTypes === true) {
return fs.readdir(validatedPath, { withFileTypes: true });
}
return fs.readdir(validatedPath);
}
/**
* Wrapper around fs.stat that validates path first
*/
export async function stat(filePath: string): Promise<any> {
const validatedPath = validatePath(filePath);
return fs.stat(validatedPath);
}
/**
* Wrapper around fs.rm that validates path first
*/
export async function rm(
filePath: string,
options?: { recursive?: boolean; force?: boolean }
): Promise<void> {
const validatedPath = validatePath(filePath);
return fs.rm(validatedPath, options);
}
/**
* Wrapper around fs.unlink that validates path first
*/
export async function unlink(filePath: string): Promise<void> {
const validatedPath = validatePath(filePath);
return fs.unlink(validatedPath);
}
/**
* Wrapper around fs.copyFile that validates both paths first
*/
export async function copyFile(
src: string,
dest: string,
mode?: number
): Promise<void> {
const validatedSrc = validatePath(src);
const validatedDest = validatePath(dest);
return fs.copyFile(validatedSrc, validatedDest, mode);
}
/**
* Wrapper around fs.appendFile that validates path first
*/
export async function appendFile(
filePath: string,
data: string | Buffer,
encoding?: BufferEncoding
): Promise<void> {
const validatedPath = validatePath(filePath);
return fs.appendFile(validatedPath, data, encoding);
}
/**
* Wrapper around fs.rename that validates both paths first
*/
export async function rename(
oldPath: string,
newPath: string
): Promise<void> {
const validatedOldPath = validatePath(oldPath);
const validatedNewPath = validatePath(newPath);
return fs.rename(validatedOldPath, validatedNewPath);
}
/**
* Wrapper around fs.lstat that validates path first
* Returns file stats without following symbolic links
*/
export async function lstat(filePath: string): Promise<any> {
const validatedPath = validatePath(filePath);
return fs.lstat(validatedPath);
}
/**
* Wrapper around path.join that returns resolved path
* Does NOT validate - use this for path construction, then pass to other operations
*/
export function joinPath(...pathSegments: string[]): string {
return path.join(...pathSegments);
}
/**
* Wrapper around path.resolve that returns resolved path
* Does NOT validate - use this for path construction, then pass to other operations
*/
export function resolvePath(...pathSegments: string[]): string {
return path.resolve(...pathSegments);
}
export const {
access,
readFile,
writeFile,
mkdir,
readdir,
stat,
rm,
unlink,
copyFile,
appendFile,
rename,
lstat,
joinPath,
resolvePath,
} = secureFs;

View File

@@ -1,143 +0,0 @@
/**
* Security utilities for path validation
* Enforces ALLOWED_ROOT_DIRECTORY constraint with appData exception
*/
import path from "path";
/**
* Error thrown when a path is not allowed by security policy
*/
export class PathNotAllowedError extends Error {
constructor(filePath: string) {
super(
`Path not allowed: ${filePath}. Must be within ALLOWED_ROOT_DIRECTORY or DATA_DIR.`
);
this.name = "PathNotAllowedError";
}
}
// Allowed root directory - main security boundary
let allowedRootDirectory: string | null = null;
// Data directory - always allowed for settings/credentials
let dataDirectory: string | null = null;
/**
* Initialize security settings from environment variables
* - ALLOWED_ROOT_DIRECTORY: main security boundary
* - DATA_DIR: appData exception, always allowed
*/
export function initAllowedPaths(): void {
// Load ALLOWED_ROOT_DIRECTORY
const rootDir = process.env.ALLOWED_ROOT_DIRECTORY;
if (rootDir) {
allowedRootDirectory = path.resolve(rootDir);
console.log(
`[Security] ✓ ALLOWED_ROOT_DIRECTORY configured: ${allowedRootDirectory}`
);
} else {
console.log(
"[Security] ⚠️ ALLOWED_ROOT_DIRECTORY not set - allowing access to all paths"
);
}
// Load DATA_DIR (appData exception - always allowed)
const dataDir = process.env.DATA_DIR;
if (dataDir) {
dataDirectory = path.resolve(dataDir);
console.log(`[Security] ✓ DATA_DIR configured: ${dataDirectory}`);
}
}
/**
* Check if a path is allowed based on ALLOWED_ROOT_DIRECTORY
* Returns true if:
* - Path is within ALLOWED_ROOT_DIRECTORY, OR
* - Path is within DATA_DIR (appData exception), OR
* - No restrictions are configured (backward compatibility)
*/
export function isPathAllowed(filePath: string): boolean {
const resolvedPath = path.resolve(filePath);
// Always allow appData directory (settings, credentials)
if (dataDirectory && isPathWithinDirectory(resolvedPath, dataDirectory)) {
return true;
}
// If no ALLOWED_ROOT_DIRECTORY restriction is configured, allow all paths
// Note: DATA_DIR is checked above as an exception, but doesn't restrict other paths
if (!allowedRootDirectory) {
return true;
}
// Allow if within ALLOWED_ROOT_DIRECTORY
if (
allowedRootDirectory &&
isPathWithinDirectory(resolvedPath, allowedRootDirectory)
) {
return true;
}
// If restrictions are configured but path doesn't match, deny
return false;
}
/**
* Validate a path - resolves it and checks permissions
* Throws PathNotAllowedError if path is not allowed
*/
export function validatePath(filePath: string): string {
const resolvedPath = path.resolve(filePath);
if (!isPathAllowed(resolvedPath)) {
throw new PathNotAllowedError(filePath);
}
return resolvedPath;
}
/**
* Check if a path is within a directory, with protection against path traversal
* Returns true only if resolvedPath is within directoryPath
*/
export function isPathWithinDirectory(
resolvedPath: string,
directoryPath: string
): boolean {
// Get the relative path from directory to the target
const relativePath = path.relative(directoryPath, resolvedPath);
// If relative path starts with "..", it's outside the directory
// If relative path is absolute, it's outside the directory
// If relative path is empty or ".", it's the directory itself
return !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
}
/**
* Get the configured allowed root directory
*/
export function getAllowedRootDirectory(): string | null {
return allowedRootDirectory;
}
/**
* Get the configured data directory
*/
export function getDataDirectory(): string | null {
return dataDirectory;
}
/**
* Get list of allowed paths (for debugging)
*/
export function getAllowedPaths(): string[] {
const paths: string[] = [];
if (allowedRootDirectory) {
paths.push(allowedRootDirectory);
}
if (dataDirectory) {
paths.push(dataDirectory);
}
return paths;
}

View File

@@ -1,206 +0,0 @@
/**
* Subprocess management utilities for CLI providers
*/
import { spawn, type ChildProcess } from "child_process";
import readline from "readline";
export interface SubprocessOptions {
command: string;
args: string[];
cwd: string;
env?: Record<string, string>;
abortController?: AbortController;
timeout?: number; // Milliseconds of no output before timeout
}
export interface SubprocessResult {
stdout: string;
stderr: string;
exitCode: number | null;
}
/**
* Spawns a subprocess and streams JSONL output line-by-line
*/
export async function* spawnJSONLProcess(
options: SubprocessOptions
): AsyncGenerator<unknown> {
const { command, args, cwd, env, abortController, timeout = 30000 } = options;
const processEnv = {
...process.env,
...env,
};
console.log(`[SubprocessManager] Spawning: ${command} ${args.slice(0, -1).join(" ")}`);
console.log(`[SubprocessManager] Working directory: ${cwd}`);
const childProcess: ChildProcess = spawn(command, args, {
cwd,
env: processEnv,
stdio: ["ignore", "pipe", "pipe"],
});
let stderrOutput = "";
let lastOutputTime = Date.now();
let timeoutHandle: NodeJS.Timeout | null = null;
// Collect stderr for error reporting
if (childProcess.stderr) {
childProcess.stderr.on("data", (data: Buffer) => {
const text = data.toString();
stderrOutput += text;
console.error(`[SubprocessManager] stderr: ${text}`);
});
}
// Setup timeout detection
const resetTimeout = () => {
lastOutputTime = Date.now();
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
timeoutHandle = setTimeout(() => {
const elapsed = Date.now() - lastOutputTime;
if (elapsed >= timeout) {
console.error(
`[SubprocessManager] Process timeout: no output for ${timeout}ms`
);
childProcess.kill("SIGTERM");
}
}, timeout);
};
resetTimeout();
// Setup abort handling
if (abortController) {
abortController.signal.addEventListener("abort", () => {
console.log("[SubprocessManager] Abort signal received, killing process");
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
childProcess.kill("SIGTERM");
});
}
// Parse stdout as JSONL (one JSON object per line)
if (childProcess.stdout) {
const rl = readline.createInterface({
input: childProcess.stdout,
crlfDelay: Infinity,
});
try {
for await (const line of rl) {
resetTimeout();
if (!line.trim()) continue;
try {
const parsed = JSON.parse(line);
yield parsed;
} catch (parseError) {
console.error(
`[SubprocessManager] Failed to parse JSONL line: ${line}`,
parseError
);
// Yield error but continue processing
yield {
type: "error",
error: `Failed to parse output: ${line}`,
};
}
}
} catch (error) {
console.error("[SubprocessManager] Error reading stdout:", error);
throw error;
} finally {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
}
}
// Wait for process to exit
const exitCode = await new Promise<number | null>((resolve) => {
childProcess.on("exit", (code) => {
console.log(`[SubprocessManager] Process exited with code: ${code}`);
resolve(code);
});
childProcess.on("error", (error) => {
console.error("[SubprocessManager] Process error:", error);
resolve(null);
});
});
// Handle non-zero exit codes
if (exitCode !== 0 && exitCode !== null) {
const errorMessage = stderrOutput || `Process exited with code ${exitCode}`;
console.error(`[SubprocessManager] Process failed: ${errorMessage}`);
yield {
type: "error",
error: errorMessage,
};
}
// Process completed successfully
if (exitCode === 0 && !stderrOutput) {
console.log("[SubprocessManager] Process completed successfully");
}
}
/**
* Spawns a subprocess and collects all output
*/
export async function spawnProcess(
options: SubprocessOptions
): Promise<SubprocessResult> {
const { command, args, cwd, env, abortController } = options;
const processEnv = {
...process.env,
...env,
};
return new Promise((resolve, reject) => {
const childProcess = spawn(command, args, {
cwd,
env: processEnv,
stdio: ["ignore", "pipe", "pipe"],
});
let stdout = "";
let stderr = "";
if (childProcess.stdout) {
childProcess.stdout.on("data", (data: Buffer) => {
stdout += data.toString();
});
}
if (childProcess.stderr) {
childProcess.stderr.on("data", (data: Buffer) => {
stderr += data.toString();
});
}
// Setup abort handling
if (abortController) {
abortController.signal.addEventListener("abort", () => {
childProcess.kill("SIGTERM");
reject(new Error("Process aborted"));
});
}
childProcess.on("exit", (code) => {
resolve({ stdout, stderr, exitCode: code });
});
childProcess.on("error", (error) => {
reject(error);
});
});
}

View File

@@ -5,7 +5,7 @@
*/
import type { Request, Response, NextFunction } from "express";
import { validatePath, PathNotAllowedError } from "../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
/**
* Creates a middleware that validates specified path parameters in req.body

View File

@@ -2,7 +2,7 @@
* Common utilities for agent routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import { AgentService } from "../../../services/agent-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("Agent");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import { AgentService } from "../../../services/agent-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("Agent");

View File

@@ -2,7 +2,7 @@
* Common utilities and state management for spec regeneration
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
const logger = createLogger("SpecRegeneration");

View File

@@ -5,11 +5,11 @@
import { query } from "@anthropic-ai/claude-agent-sdk";
import fs from "fs/promises";
import type { EventEmitter } from "../../lib/events.js";
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { createFeatureGenerationOptions } from "../../lib/sdk-options.js";
import { logAuthStatus } from "./common.js";
import { parseAndCreateFeatures } from "./parse-and-create-features.js";
import { getAppSpecPath } from "../../lib/automaker-paths.js";
import { getAppSpecPath } from "@automaker/platform";
const logger = createLogger("SpecRegeneration");

View File

@@ -12,11 +12,11 @@ import {
getStructuredSpecPromptInstruction,
type SpecOutput,
} from "../../lib/app-spec-format.js";
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { createSpecGenerationOptions } from "../../lib/sdk-options.js";
import { logAuthStatus } from "./common.js";
import { generateFeaturesFromSpec } from "./generate-features-from-spec.js";
import { ensureAutomakerDir, getAppSpecPath } from "../../lib/automaker-paths.js";
import { ensureAutomakerDir, getAppSpecPath } from "@automaker/platform";
const logger = createLogger("SpecRegeneration");

View File

@@ -5,8 +5,8 @@
import path from "path";
import fs from "fs/promises";
import type { EventEmitter } from "../../lib/events.js";
import { createLogger } from "../../lib/logger.js";
import { getFeaturesDir } from "../../lib/automaker-paths.js";
import { createLogger } from "@automaker/utils";
import { getFeaturesDir } from "@automaker/platform";
const logger = createLogger("SpecRegeneration");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { EventEmitter } from "../../../lib/events.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getSpecRegenerationStatus,
setRunningState,

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { EventEmitter } from "../../../lib/events.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getSpecRegenerationStatus,
setRunningState,

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { EventEmitter } from "../../../lib/events.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getSpecRegenerationStatus,
setRunningState,

View File

@@ -2,7 +2,7 @@
* Common utilities for auto-mode routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { AutoModeService } from "../../../services/auto-mode-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("AutoMode");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { AutoModeService } from "../../../services/auto-mode-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("AutoMode");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { AutoModeService } from "../../../services/auto-mode-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("AutoMode");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { AutoModeService } from "../../../services/auto-mode-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("AutoMode");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { AutoModeService } from "../../../services/auto-mode-service.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
const logger = createLogger("AutoMode");

View File

@@ -2,368 +2,24 @@
* Common utilities shared across all route modules
*/
import { createLogger } from "../lib/logger.js";
import fs from "fs/promises";
import path from "path";
import { exec } from "child_process";
import { promisify } from "util";
import { createLogger } from "@automaker/utils";
// Re-export git utilities from shared package
export {
BINARY_EXTENSIONS,
GIT_STATUS_MAP,
type FileStatus,
isGitRepo,
parseGitStatus,
generateSyntheticDiffForNewFile,
appendUntrackedFileDiffs,
listAllFilesInDirectory,
generateDiffsForNonGitDirectory,
getGitRepositoryDiffs,
} from "@automaker/git-utils";
type Logger = ReturnType<typeof createLogger>;
const execAsync = promisify(exec);
const logger = createLogger("Common");
// Max file size for generating synthetic diffs (1MB)
const MAX_SYNTHETIC_DIFF_SIZE = 1024 * 1024;
// Binary file extensions to skip
const BINARY_EXTENSIONS = new Set([
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".webp", ".svg",
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
".zip", ".tar", ".gz", ".rar", ".7z",
".exe", ".dll", ".so", ".dylib",
".mp3", ".mp4", ".wav", ".avi", ".mov", ".mkv",
".ttf", ".otf", ".woff", ".woff2", ".eot",
".db", ".sqlite", ".sqlite3",
".pyc", ".pyo", ".class", ".o", ".obj",
]);
// Status map for git status codes
// Git porcelain format uses XY where X=staging area, Y=working tree
const GIT_STATUS_MAP: Record<string, string> = {
M: "Modified",
A: "Added",
D: "Deleted",
R: "Renamed",
C: "Copied",
U: "Updated",
"?": "Untracked",
"!": "Ignored",
" ": "Unmodified",
};
/**
* Get a readable status text from git status codes
* Handles both single character and XY format status codes
*/
function getStatusText(indexStatus: string, workTreeStatus: string): string {
// Untracked files
if (indexStatus === "?" && workTreeStatus === "?") {
return "Untracked";
}
// Ignored files
if (indexStatus === "!" && workTreeStatus === "!") {
return "Ignored";
}
// Prioritize staging area status, then working tree
const primaryStatus = indexStatus !== " " && indexStatus !== "?" ? indexStatus : workTreeStatus;
// Handle combined statuses
if (indexStatus !== " " && indexStatus !== "?" && workTreeStatus !== " " && workTreeStatus !== "?") {
// Both staging and working tree have changes
const indexText = GIT_STATUS_MAP[indexStatus] || "Changed";
const workText = GIT_STATUS_MAP[workTreeStatus] || "Changed";
if (indexText === workText) {
return indexText;
}
return `${indexText} (staged), ${workText} (unstaged)`;
}
return GIT_STATUS_MAP[primaryStatus] || "Changed";
}
/**
* File status interface for git status results
*/
export interface FileStatus {
status: string;
path: string;
statusText: string;
}
/**
* Check if a file is likely binary based on extension
*/
function isBinaryFile(filePath: string): boolean {
const ext = path.extname(filePath).toLowerCase();
return BINARY_EXTENSIONS.has(ext);
}
/**
* Check if a path is a git repository
*/
export async function isGitRepo(repoPath: string): Promise<boolean> {
try {
await execAsync("git rev-parse --is-inside-work-tree", { cwd: repoPath });
return true;
} catch {
return false;
}
}
/**
* Parse the output of `git status --porcelain` into FileStatus array
* Git porcelain format: XY PATH where X=staging area status, Y=working tree status
* For renamed files: XY ORIG_PATH -> NEW_PATH
*/
export function parseGitStatus(statusOutput: string): FileStatus[] {
return statusOutput
.split("\n")
.filter(Boolean)
.map((line) => {
// Git porcelain format uses two status characters: XY
// X = status in staging area (index)
// Y = status in working tree
const indexStatus = line[0] || " ";
const workTreeStatus = line[1] || " ";
// File path starts at position 3 (after "XY ")
let filePath = line.slice(3);
// Handle renamed files (format: "R old_path -> new_path")
if (indexStatus === "R" || workTreeStatus === "R") {
const arrowIndex = filePath.indexOf(" -> ");
if (arrowIndex !== -1) {
filePath = filePath.slice(arrowIndex + 4); // Use new path
}
}
// Determine the primary status character for backwards compatibility
// Prioritize staging area status, then working tree
let primaryStatus: string;
if (indexStatus === "?" && workTreeStatus === "?") {
primaryStatus = "?"; // Untracked
} else if (indexStatus !== " " && indexStatus !== "?") {
primaryStatus = indexStatus; // Staged change
} else {
primaryStatus = workTreeStatus; // Working tree change
}
return {
status: primaryStatus,
path: filePath,
statusText: getStatusText(indexStatus, workTreeStatus),
};
});
}
/**
* Generate a synthetic unified diff for an untracked (new) file
* This is needed because `git diff HEAD` doesn't include untracked files
*/
export async function generateSyntheticDiffForNewFile(
basePath: string,
relativePath: string
): Promise<string> {
const fullPath = path.join(basePath, relativePath);
try {
// Check if it's a binary file
if (isBinaryFile(relativePath)) {
return `diff --git a/${relativePath} b/${relativePath}
new file mode 100644
index 0000000..0000000
Binary file ${relativePath} added
`;
}
// Get file stats to check size
const stats = await fs.stat(fullPath);
if (stats.size > MAX_SYNTHETIC_DIFF_SIZE) {
const sizeKB = Math.round(stats.size / 1024);
return `diff --git a/${relativePath} b/${relativePath}
new file mode 100644
index 0000000..0000000
--- /dev/null
+++ b/${relativePath}
@@ -0,0 +1 @@
+[File too large to display: ${sizeKB}KB]
`;
}
// Read file content
const content = await fs.readFile(fullPath, "utf-8");
const hasTrailingNewline = content.endsWith("\n");
const lines = content.split("\n");
// Remove trailing empty line if the file ends with newline
if (lines.length > 0 && lines.at(-1) === "") {
lines.pop();
}
// Generate diff format
const lineCount = lines.length;
const addedLines = lines.map(line => `+${line}`).join("\n");
let diff = `diff --git a/${relativePath} b/${relativePath}
new file mode 100644
index 0000000..0000000
--- /dev/null
+++ b/${relativePath}
@@ -0,0 +1,${lineCount} @@
${addedLines}`;
// Add "No newline at end of file" indicator if needed
if (!hasTrailingNewline && content.length > 0) {
diff += "\n\\ No newline at end of file";
}
return diff + "\n";
} catch (error) {
// Log the error for debugging
logger.error(`Failed to generate synthetic diff for ${fullPath}:`, error);
// Return a placeholder diff
return `diff --git a/${relativePath} b/${relativePath}
new file mode 100644
index 0000000..0000000
--- /dev/null
+++ b/${relativePath}
@@ -0,0 +1 @@
+[Unable to read file content]
`;
}
}
/**
* Generate synthetic diffs for all untracked files and combine with existing diff
*/
export async function appendUntrackedFileDiffs(
basePath: string,
existingDiff: string,
files: Array<{ status: string; path: string }>
): Promise<string> {
// Find untracked files (status "?")
const untrackedFiles = files.filter(f => f.status === "?");
if (untrackedFiles.length === 0) {
return existingDiff;
}
// Generate synthetic diffs for each untracked file
const syntheticDiffs = await Promise.all(
untrackedFiles.map(f => generateSyntheticDiffForNewFile(basePath, f.path))
);
// Combine existing diff with synthetic diffs
const combinedDiff = existingDiff + syntheticDiffs.join("");
return combinedDiff;
}
/**
* List all files in a directory recursively (for non-git repositories)
* Excludes hidden files/folders and common build artifacts
*/
export async function listAllFilesInDirectory(
basePath: string,
relativePath: string = ""
): Promise<string[]> {
const files: string[] = [];
const fullPath = path.join(basePath, relativePath);
// Directories to skip
const skipDirs = new Set([
"node_modules", ".git", ".automaker", "dist", "build",
".next", ".nuxt", "__pycache__", ".cache", "coverage"
]);
try {
const entries = await fs.readdir(fullPath, { withFileTypes: true });
for (const entry of entries) {
// Skip hidden files/folders (except we want to allow some)
if (entry.name.startsWith(".") && entry.name !== ".env") {
continue;
}
const entryRelPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
if (entry.isDirectory()) {
if (!skipDirs.has(entry.name)) {
const subFiles = await listAllFilesInDirectory(basePath, entryRelPath);
files.push(...subFiles);
}
} else if (entry.isFile()) {
files.push(entryRelPath);
}
}
} catch (error) {
// Log the error to help diagnose file system issues
logger.error(`Error reading directory ${fullPath}:`, error);
}
return files;
}
/**
* Generate diffs for all files in a non-git directory
* Treats all files as "new" files
*/
export async function generateDiffsForNonGitDirectory(
basePath: string
): Promise<{ diff: string; files: FileStatus[] }> {
const allFiles = await listAllFilesInDirectory(basePath);
const files: FileStatus[] = allFiles.map(filePath => ({
status: "?",
path: filePath,
statusText: "New",
}));
// Generate synthetic diffs for all files
const syntheticDiffs = await Promise.all(
files.map(f => generateSyntheticDiffForNewFile(basePath, f.path))
);
return {
diff: syntheticDiffs.join(""),
files,
};
}
/**
* Get git repository diffs for a given path
* Handles both git repos and non-git directories
*/
export async function getGitRepositoryDiffs(
repoPath: string
): Promise<{ diff: string; files: FileStatus[]; hasChanges: boolean }> {
// Check if it's a git repository
const isRepo = await isGitRepo(repoPath);
if (!isRepo) {
// Not a git repo - list all files and treat them as new
const result = await generateDiffsForNonGitDirectory(repoPath);
return {
diff: result.diff,
files: result.files,
hasChanges: result.files.length > 0,
};
}
// Get git diff and status
const { stdout: diff } = await execAsync("git diff HEAD", {
cwd: repoPath,
maxBuffer: 10 * 1024 * 1024,
});
const { stdout: status } = await execAsync("git status --porcelain", {
cwd: repoPath,
});
const files = parseGitStatus(status);
// Generate synthetic diffs for untracked (new) files
const combinedDiff = await appendUntrackedFileDiffs(repoPath, diff, files);
return {
diff: combinedDiff,
files,
hasChanges: files.length > 0,
};
}
/**
* Get error message from error object
*/

View File

@@ -7,14 +7,15 @@
import type { Request, Response } from "express";
import { query } from "@anthropic-ai/claude-agent-sdk";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { resolveModelString } from "@automaker/model-resolver";
import { CLAUDE_MODEL_MAP } from "@automaker/types";
import {
getSystemPrompt,
buildUserPrompt,
isValidEnhancementMode,
type EnhancementMode,
} from "../../../lib/enhancement-prompts.js";
import { resolveModelString, CLAUDE_MODEL_MAP } from "../../../lib/model-resolver.js";
const logger = createLogger("EnhancePrompt");

View File

@@ -2,7 +2,7 @@
* Common utilities for features routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -3,10 +3,8 @@
*/
import type { Request, Response } from "express";
import {
FeatureLoader,
type Feature,
} from "../../../services/feature-loader.js";
import { FeatureLoader } from "../../../services/feature-loader.js";
import type { Feature } from "@automaker/types";
import { getErrorMessage, logError } from "../common.js";
export function createCreateHandler(featureLoader: FeatureLoader) {
@@ -18,12 +16,10 @@ export function createCreateHandler(featureLoader: FeatureLoader) {
};
if (!projectPath || !feature) {
res
.status(400)
.json({
success: false,
error: "projectPath and feature are required",
});
res.status(400).json({
success: false,
error: "projectPath and feature are required",
});
return;
}

View File

@@ -6,8 +6,8 @@
import type { Request, Response } from "express";
import { query } from "@anthropic-ai/claude-agent-sdk";
import { createLogger } from "../../../lib/logger.js";
import { CLAUDE_MODEL_MAP } from "../../../lib/model-resolver.js";
import { createLogger } from "@automaker/utils";
import { CLAUDE_MODEL_MAP } from "@automaker/model-resolver";
const logger = createLogger("GenerateTitle");

View File

@@ -3,10 +3,8 @@
*/
import type { Request, Response } from "express";
import {
FeatureLoader,
type Feature,
} from "../../../services/feature-loader.js";
import { FeatureLoader } from "../../../services/feature-loader.js";
import type { Feature } from "@automaker/types";
import { getErrorMessage, logError } from "../common.js";
export function createUpdateHandler(featureLoader: FeatureLoader) {

View File

@@ -2,7 +2,7 @@
* Common utilities for fs routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -10,7 +10,7 @@ import {
getAllowedRootDirectory,
isPathAllowed,
PathNotAllowedError,
} from "../../../lib/security.js";
} from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createBrowseHandler() {

View File

@@ -6,7 +6,7 @@ import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { getErrorMessage, logError } from "../common.js";
import { getBoardDir } from "../../../lib/automaker-paths.js";
import { getBoardDir } from "@automaker/platform";
export function createDeleteBoardBackgroundHandler() {
return async (req: Request, res: Response): Promise<void> => {

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import { validatePath, PathNotAllowedError } from "../../../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createDeleteHandler() {

View File

@@ -5,7 +5,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { isPathAllowed, PathNotAllowedError } from "../../../lib/security.js";
import { isPathAllowed, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createExistsHandler() {

View File

@@ -6,7 +6,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { isPathAllowed, PathNotAllowedError } from "../../../lib/security.js";
import { isPathAllowed, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createMkdirHandler() {

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import { validatePath, PathNotAllowedError } from "../../../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
// Optional files that are expected to not exist in new projects

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import { validatePath, PathNotAllowedError } from "../../../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createReaddirHandler() {

View File

@@ -6,7 +6,7 @@ import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { getErrorMessage, logError } from "../common.js";
import { getBoardDir } from "../../../lib/automaker-paths.js";
import { getBoardDir } from "@automaker/platform";
export function createSaveBoardBackgroundHandler() {
return async (req: Request, res: Response): Promise<void> => {

View File

@@ -6,7 +6,7 @@ import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { getErrorMessage, logError } from "../common.js";
import { getImagesDir } from "../../../lib/automaker-paths.js";
import { getImagesDir } from "@automaker/platform";
export function createSaveImageHandler() {
return async (req: Request, res: Response): Promise<void> => {

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import { validatePath, PathNotAllowedError } from "../../../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createStatHandler() {

View File

@@ -5,7 +5,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { isPathAllowed } from "../../../lib/security.js";
import { isPathAllowed } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createValidatePathHandler() {

View File

@@ -5,9 +5,9 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { validatePath, PathNotAllowedError } from "../../../lib/security.js";
import { validatePath, PathNotAllowedError } from "@automaker/platform";
import { mkdirSafe } from "@automaker/utils";
import { getErrorMessage, logError } from "../common.js";
import { mkdirSafe } from "../../../lib/fs-utils.js";
export function createWriteHandler() {
return async (req: Request, res: Response): Promise<void> => {

View File

@@ -2,7 +2,7 @@
* Common utilities for git routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -2,7 +2,7 @@
* Common utilities for health routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -2,7 +2,7 @@
* Common utilities for models routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -2,7 +2,7 @@
* Common utilities for running-agents routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -2,7 +2,7 @@
* Common utilities for sessions routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -5,7 +5,7 @@
* Re-exports error handling helpers from the parent routes module.
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -2,7 +2,7 @@
* Common utilities and state for setup routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import path from "path";
import fs from "fs/promises";
import {

View File

@@ -3,7 +3,7 @@
*/
import type { Request, Response } from "express";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import path from "path";
import fs from "fs/promises";

View File

@@ -9,7 +9,7 @@ import {
getErrorMessage,
logError,
} from "../common.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
const logger = createLogger("Setup");

View File

@@ -5,7 +5,7 @@
import type { Request, Response } from "express";
import { query } from "@anthropic-ai/claude-agent-sdk";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { getApiKey } from "../common.js";
const logger = createLogger("Setup");

View File

@@ -2,7 +2,7 @@
* Common utilities and state for suggestions routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -4,7 +4,7 @@
import { query } from "@anthropic-ai/claude-agent-sdk";
import type { EventEmitter } from "../../lib/events.js";
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { createSuggestionsOptions } from "../../lib/sdk-options.js";
const logger = createLogger("Suggestions");

View File

@@ -4,7 +4,7 @@
import type { Request, Response } from "express";
import type { EventEmitter } from "../../../lib/events.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getSuggestionsStatus,
setRunningState,

View File

@@ -2,7 +2,7 @@
* Common utilities for templates routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -6,7 +6,7 @@ import type { Request, Response } from "express";
import { spawn } from "child_process";
import path from "path";
import fs from "fs/promises";
import { isPathAllowed, PathNotAllowedError } from "../../../lib/security.js";
import { isPathAllowed } from "@automaker/platform";
import { logger, getErrorMessage, logError } from "../common.js";
export function createCloneHandler() {

View File

@@ -2,7 +2,7 @@
* Common utilities and state for terminal routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import type { Request, Response, NextFunction } from "express";
import { getTerminalService } from "../../services/terminal-service.js";

View File

@@ -6,7 +6,7 @@
import type { Request, Response } from "express";
import { getTerminalService } from "../../../services/terminal-service.js";
import { getErrorMessage, logError } from "../common.js";
import { createLogger } from "../../../lib/logger.js";
import { createLogger } from "@automaker/utils";
const logger = createLogger("Terminal");

View File

@@ -2,7 +2,7 @@
* Common utilities for workspace routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import {
getErrorMessage as getErrorMessageShared,
createLogError,

View File

@@ -8,7 +8,7 @@ import path from "path";
import {
getAllowedRootDirectory,
getDataDirectory,
} from "../../../lib/security.js";
} from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createConfigHandler() {

View File

@@ -5,7 +5,7 @@
import type { Request, Response } from "express";
import fs from "fs/promises";
import path from "path";
import { getAllowedRootDirectory } from "../../../lib/security.js";
import { getAllowedRootDirectory } from "@automaker/platform";
import { getErrorMessage, logError } from "../common.js";
export function createDirectoriesHandler() {
@@ -35,7 +35,9 @@ export function createDirectoriesHandler() {
}
// Read directory contents
const entries = await fs.readdir(resolvedWorkspaceDir, { withFileTypes: true });
const entries = await fs.readdir(resolvedWorkspaceDir, {
withFileTypes: true,
});
// Filter to directories only and map to result format
const directories = entries

View File

@@ -2,7 +2,7 @@
* Common utilities for worktree routes
*/
import { createLogger } from "../../lib/logger.js";
import { createLogger } from "@automaker/utils";
import { exec } from "child_process";
import { promisify } from "util";
import path from "path";

View File

@@ -10,7 +10,7 @@ import path from "path";
import {
getBranchTrackingPath,
ensureAutomakerDir,
} from "../../../lib/automaker-paths.js";
} from "@automaker/platform";
export interface TrackedBranch {
name: string;

View File

@@ -5,7 +5,8 @@
import type { Request, Response } from "express";
import { exec } from "child_process";
import { promisify } from "util";
import { isGitRepo, getErrorMessage, logError } from "../common.js";
import { isGitRepo } from "@automaker/git-utils";
import { getErrorMessage, logError } from "../common.js";
const execAsync = promisify(exec);

View File

@@ -9,7 +9,8 @@ import type { Request, Response } from "express";
import { exec } from "child_process";
import { promisify } from "util";
import { existsSync } from "fs";
import { isGitRepo, getErrorMessage, logError, normalizePath } from "../common.js";
import { isGitRepo } from "@automaker/git-utils";
import { getErrorMessage, logError, normalizePath } from "../common.js";
import { readAllWorktreeMetadata, type WorktreePRInfo } from "../../../lib/worktree-metadata.js";
const execAsync = promisify(exec);

View File

@@ -6,7 +6,7 @@
*/
import type { Request, Response } from "express";
import { getAutomakerDir } from "../../../lib/automaker-paths.js";
import { getAutomakerDir } from "@automaker/platform";
export function createMigrateHandler() {
return async (req: Request, res: Response): Promise<void> => {

View File

@@ -3,17 +3,18 @@
* Manages conversation sessions and streams responses via WebSocket
*/
import { AbortError } from "@anthropic-ai/claude-agent-sdk";
import path from "path";
import * as secureFs from "../lib/secure-fs.js";
import type { EventEmitter } from "../lib/events.js";
import type { ExecuteOptions } from "@automaker/types";
import {
readImageAsBase64,
buildPromptWithImages,
isAbortError,
} from "@automaker/utils";
import { ProviderFactory } from "../providers/provider-factory.js";
import type { ExecuteOptions } from "../providers/types.js";
import { readImageAsBase64 } from "../lib/image-handler.js";
import { buildPromptWithImages } from "../lib/prompt-builder.js";
import { createChatOptions } from "../lib/sdk-options.js";
import { isAbortError } from "../lib/error-handler.js";
import { isPathAllowed, PathNotAllowedError } from "../lib/security.js";
import { isPathAllowed, PathNotAllowedError } from "@automaker/platform";
interface Message {
id: string;
@@ -87,7 +88,9 @@ export class AgentService {
// Validate that the working directory is allowed
if (!isPathAllowed(resolvedWorkingDirectory)) {
throw new PathNotAllowedError(effectiveWorkingDirectory);
throw new Error(
`Working directory ${effectiveWorkingDirectory} is not allowed`
);
}
this.sessions.set(sessionId, {
@@ -401,7 +404,7 @@ export class AgentService {
const sessionFile = path.join(this.stateDir, `${sessionId}.json`);
try {
const data = await secureFs.readFile(sessionFile, "utf-8") as string;
const data = (await secureFs.readFile(sessionFile, "utf-8")) as string;
return JSON.parse(data);
} catch {
return [];
@@ -425,7 +428,10 @@ export class AgentService {
async loadMetadata(): Promise<Record<string, SessionMetadata>> {
try {
const data = await secureFs.readFile(this.metadataFile, "utf-8") as string;
const data = (await secureFs.readFile(
this.metadataFile,
"utf-8"
)) as string;
return JSON.parse(data);
} catch {
return {};
@@ -472,7 +478,8 @@ export class AgentService {
const metadata = await this.loadMetadata();
// Determine the effective working directory
const effectiveWorkingDirectory = workingDirectory || projectPath || process.cwd();
const effectiveWorkingDirectory =
workingDirectory || projectPath || process.cwd();
const resolvedWorkingDirectory = path.resolve(effectiveWorkingDirectory);
// Validate that the working directory is allowed

View File

@@ -10,37 +10,47 @@
*/
import { ProviderFactory } from "../providers/provider-factory.js";
import type { ExecuteOptions } from "../providers/types.js";
import type { ExecuteOptions, Feature } from "@automaker/types";
import {
buildPromptWithImages,
isAbortError,
classifyError,
} from "@automaker/utils";
import { resolveModelString, DEFAULT_MODELS } from "@automaker/model-resolver";
import {
resolveDependencies,
areDependenciesSatisfied,
} from "@automaker/dependency-resolver";
import {
getFeatureDir,
getAutomakerDir,
getFeaturesDir,
getContextDir,
} from "@automaker/platform";
import { exec } from "child_process";
import { promisify } from "util";
import path from "path";
import * as secureFs from "../lib/secure-fs.js";
import type { EventEmitter } from "../lib/events.js";
import { buildPromptWithImages } from "../lib/prompt-builder.js";
import { resolveModelString, DEFAULT_MODELS } from "../lib/model-resolver.js";
import { createAutoModeOptions } from "../lib/sdk-options.js";
import { isAbortError, classifyError } from "../lib/error-handler.js";
import { resolveDependencies, areDependenciesSatisfied } from "../lib/dependency-resolver.js";
import type { Feature } from "./feature-loader.js";
import { FeatureLoader } from "./feature-loader.js";
import { getFeatureDir, getAutomakerDir, getFeaturesDir, getContextDir } from "../lib/automaker-paths.js";
import { isPathAllowed, PathNotAllowedError } from "../lib/security.js";
import { isPathAllowed, PathNotAllowedError } from "@automaker/platform";
const execAsync = promisify(exec);
// Planning mode types for spec-driven development
type PlanningMode = 'skip' | 'lite' | 'spec' | 'full';
type PlanningMode = "skip" | "lite" | "spec" | "full";
interface ParsedTask {
id: string; // e.g., "T001"
id: string; // e.g., "T001"
description: string; // e.g., "Create user model"
filePath?: string; // e.g., "src/models/user.ts"
phase?: string; // e.g., "Phase 1: Foundation" (for full mode)
status: 'pending' | 'in_progress' | 'completed' | 'failed';
filePath?: string; // e.g., "src/models/user.ts"
phase?: string; // e.g., "Phase 1: Foundation" (for full mode)
status: "pending" | "in_progress" | "completed" | "failed";
}
interface PlanSpec {
status: 'pending' | 'generating' | 'generated' | 'approved' | 'rejected';
status: "pending" | "generating" | "generated" | "approved" | "rejected";
content?: string;
version: number;
generatedAt?: string;
@@ -205,7 +215,7 @@ When approved, execute tasks SEQUENTIALLY by phase. For each task:
After completing all tasks in a phase, output:
"[PHASE_COMPLETE] Phase N complete"
This allows real-time progress tracking during implementation.`
This allows real-time progress tracking during implementation.`,
};
/**
@@ -236,7 +246,7 @@ function parseTasksFromSpec(specContent: string): ParsedTask[] {
}
const tasksContent = tasksBlockMatch[1];
const lines = tasksContent.split('\n');
const lines = tasksContent.split("\n");
let currentPhase: string | undefined;
@@ -251,7 +261,7 @@ function parseTasksFromSpec(specContent: string): ParsedTask[] {
}
// Check for task line
if (trimmedLine.startsWith('- [ ]')) {
if (trimmedLine.startsWith("- [ ]")) {
const parsed = parseTaskLine(trimmedLine, currentPhase);
if (parsed) {
tasks.push(parsed);
@@ -268,7 +278,9 @@ function parseTasksFromSpec(specContent: string): ParsedTask[] {
*/
function parseTaskLine(line: string, currentPhase?: string): ParsedTask | null {
// Match pattern: - [ ] T###: Description | File: path
const taskMatch = line.match(/- \[ \] (T\d{3}):\s*([^|]+)(?:\|\s*File:\s*(.+))?$/);
const taskMatch = line.match(
/- \[ \] (T\d{3}):\s*([^|]+)(?:\|\s*File:\s*(.+))?$/
);
if (!taskMatch) {
// Try simpler pattern without file
const simpleMatch = line.match(/- \[ \] (T\d{3}):\s*(.+)$/);
@@ -277,7 +289,7 @@ function parseTaskLine(line: string, currentPhase?: string): ParsedTask | null {
id: simpleMatch[1],
description: simpleMatch[2].trim(),
phase: currentPhase,
status: 'pending',
status: "pending",
};
}
return null;
@@ -288,7 +300,7 @@ function parseTaskLine(line: string, currentPhase?: string): ParsedTask | null {
description: taskMatch[2].trim(),
filePath: taskMatch[3]?.trim(),
phase: currentPhase,
status: 'pending',
status: "pending",
};
}
@@ -318,7 +330,11 @@ interface AutoLoopState {
}
interface PendingApproval {
resolve: (result: { approved: boolean; editedPlan?: string; feedback?: string }) => void;
resolve: (result: {
approved: boolean;
editedPlan?: string;
feedback?: string;
}) => void;
reject: (error: Error) => void;
featureId: string;
projectPath: string;
@@ -576,7 +592,9 @@ export class AutoModeService {
// Continuation prompt is used when recovering from a plan approval
// The plan was already approved, so skip the planning phase
prompt = options.continuationPrompt;
console.log(`[AutoMode] Using continuation prompt for feature ${featureId}`);
console.log(
`[AutoMode] Using continuation prompt for feature ${featureId}`
);
} else {
// Normal flow: build prompt with planning phase
const featurePrompt = this.buildFeaturePrompt(feature);
@@ -584,11 +602,11 @@ export class AutoModeService {
prompt = planningPrefix + featurePrompt;
// Emit planning mode info
if (feature.planningMode && feature.planningMode !== 'skip') {
this.emitAutoModeEvent('planning_started', {
if (feature.planningMode && feature.planningMode !== "skip") {
this.emitAutoModeEvent("planning_started", {
featureId: feature.id,
mode: feature.planningMode,
message: `Starting ${feature.planningMode} planning phase`
message: `Starting ${feature.planningMode} planning phase`,
});
}
}
@@ -658,8 +676,12 @@ export class AutoModeService {
});
}
} finally {
console.log(`[AutoMode] Feature ${featureId} execution ended, cleaning up runningFeatures`);
console.log(`[AutoMode] Pending approvals at cleanup: ${Array.from(this.pendingApprovals.keys()).join(', ') || 'none'}`);
console.log(
`[AutoMode] Feature ${featureId} execution ended, cleaning up runningFeatures`
);
console.log(
`[AutoMode] Pending approvals at cleanup: ${Array.from(this.pendingApprovals.keys()).join(", ") || "none"}`
);
this.runningFeatures.delete(featureId);
}
}
@@ -706,7 +728,7 @@ export class AutoModeService {
if (hasContext) {
// Load previous context and continue
const context = await secureFs.readFile(contextPath, "utf-8") as string;
const context = (await secureFs.readFile(contextPath, "utf-8")) as string;
return this.executeFeatureWithContext(
projectPath,
featureId,
@@ -766,7 +788,10 @@ export class AutoModeService {
const contextPath = path.join(featureDir, "agent-output.md");
let previousContext = "";
try {
previousContext = await secureFs.readFile(contextPath, "utf-8") as string;
previousContext = (await secureFs.readFile(
contextPath,
"utf-8"
)) as string;
} catch {
// No previous context
}
@@ -883,7 +908,10 @@ Address the follow-up instructions above. Review the previous work and make the
const featurePath = path.join(featureDirForSave, "feature.json");
try {
await secureFs.writeFile(featurePath, JSON.stringify(feature, null, 2));
await secureFs.writeFile(
featurePath,
JSON.stringify(feature, null, 2)
);
} catch (error) {
console.error(`[AutoMode] Failed to save feature.json:`, error);
}
@@ -903,7 +931,7 @@ Address the follow-up instructions above. Review the previous work and make the
model,
{
projectPath,
planningMode: 'skip', // Follow-ups don't require approval
planningMode: "skip", // Follow-ups don't require approval
previousContent: previousContext || undefined,
systemPrompt: contextFiles || undefined,
}
@@ -1130,7 +1158,7 @@ Address the follow-up instructions above. Review the previous work and make the
for (const file of textFiles) {
// Use path.join for cross-platform path construction
const filePath = path.join(contextDir, file);
const content = await secureFs.readFile(filePath, "utf-8") as string;
const content = (await secureFs.readFile(filePath, "utf-8")) as string;
contents.push(`## ${file}\n\n${content}`);
}
@@ -1249,7 +1277,6 @@ Format your response as a structured markdown document.`;
}
}
/**
* Get current status
*/
@@ -1290,8 +1317,12 @@ Format your response as a structured markdown document.`;
featureId: string,
projectPath: string
): Promise<{ approved: boolean; editedPlan?: string; feedback?: string }> {
console.log(`[AutoMode] Registering pending approval for feature ${featureId}`);
console.log(`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(', ') || 'none'}`);
console.log(
`[AutoMode] Registering pending approval for feature ${featureId}`
);
console.log(
`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(", ") || "none"}`
);
return new Promise((resolve, reject) => {
this.pendingApprovals.set(featureId, {
resolve,
@@ -1299,7 +1330,9 @@ Format your response as a structured markdown document.`;
featureId,
projectPath,
});
console.log(`[AutoMode] Pending approval registered for feature ${featureId}`);
console.log(
`[AutoMode] Pending approval registered for feature ${featureId}`
);
});
}
@@ -1314,61 +1347,89 @@ Format your response as a structured markdown document.`;
feedback?: string,
projectPathFromClient?: string
): Promise<{ success: boolean; error?: string }> {
console.log(`[AutoMode] resolvePlanApproval called for feature ${featureId}, approved=${approved}`);
console.log(`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(', ') || 'none'}`);
console.log(
`[AutoMode] resolvePlanApproval called for feature ${featureId}, approved=${approved}`
);
console.log(
`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(", ") || "none"}`
);
const pending = this.pendingApprovals.get(featureId);
if (!pending) {
console.log(`[AutoMode] No pending approval in Map for feature ${featureId}`);
console.log(
`[AutoMode] No pending approval in Map for feature ${featureId}`
);
// RECOVERY: If no pending approval but we have projectPath from client,
// check if feature's planSpec.status is 'generated' and handle recovery
if (projectPathFromClient) {
console.log(`[AutoMode] Attempting recovery with projectPath: ${projectPathFromClient}`);
const feature = await this.loadFeature(projectPathFromClient, featureId);
console.log(
`[AutoMode] Attempting recovery with projectPath: ${projectPathFromClient}`
);
const feature = await this.loadFeature(
projectPathFromClient,
featureId
);
if (feature?.planSpec?.status === 'generated') {
console.log(`[AutoMode] Feature ${featureId} has planSpec.status='generated', performing recovery`);
if (feature?.planSpec?.status === "generated") {
console.log(
`[AutoMode] Feature ${featureId} has planSpec.status='generated', performing recovery`
);
if (approved) {
// Update planSpec to approved
await this.updateFeaturePlanSpec(projectPathFromClient, featureId, {
status: 'approved',
status: "approved",
approvedAt: new Date().toISOString(),
reviewedByUser: true,
content: editedPlan || feature.planSpec.content,
});
// Build continuation prompt and re-run the feature
const planContent = editedPlan || feature.planSpec.content || '';
const planContent = editedPlan || feature.planSpec.content || "";
let continuationPrompt = `The plan/specification has been approved. `;
if (feedback) {
continuationPrompt += `\n\nUser feedback: ${feedback}\n\n`;
}
continuationPrompt += `Now proceed with the implementation as specified in the plan:\n\n${planContent}\n\nImplement the feature now.`;
console.log(`[AutoMode] Starting recovery execution for feature ${featureId}`);
console.log(
`[AutoMode] Starting recovery execution for feature ${featureId}`
);
// Start feature execution with the continuation prompt (async, don't await)
// Pass undefined for providedWorktreePath, use options for continuation prompt
this.executeFeature(projectPathFromClient, featureId, true, false, undefined, {
continuationPrompt,
})
.catch((error) => {
console.error(`[AutoMode] Recovery execution failed for feature ${featureId}:`, error);
});
this.executeFeature(
projectPathFromClient,
featureId,
true,
false,
undefined,
{
continuationPrompt,
}
).catch((error) => {
console.error(
`[AutoMode] Recovery execution failed for feature ${featureId}:`,
error
);
});
return { success: true };
} else {
// Rejected - update status and emit event
await this.updateFeaturePlanSpec(projectPathFromClient, featureId, {
status: 'rejected',
status: "rejected",
reviewedByUser: true,
});
await this.updateFeatureStatus(projectPathFromClient, featureId, 'backlog');
await this.updateFeatureStatus(
projectPathFromClient,
featureId,
"backlog"
);
this.emitAutoModeEvent('plan_rejected', {
this.emitAutoModeEvent("plan_rejected", {
featureId,
projectPath: projectPathFromClient,
feedback,
@@ -1379,16 +1440,23 @@ Format your response as a structured markdown document.`;
}
}
console.log(`[AutoMode] ERROR: No pending approval found for feature ${featureId} and recovery not possible`);
return { success: false, error: `No pending approval for feature ${featureId}` };
console.log(
`[AutoMode] ERROR: No pending approval found for feature ${featureId} and recovery not possible`
);
return {
success: false,
error: `No pending approval for feature ${featureId}`,
};
}
console.log(`[AutoMode] Found pending approval for feature ${featureId}, proceeding...`);
console.log(
`[AutoMode] Found pending approval for feature ${featureId}, proceeding...`
);
const { projectPath } = pending;
// Update feature's planSpec status
await this.updateFeaturePlanSpec(projectPath, featureId, {
status: approved ? 'approved' : 'rejected',
status: approved ? "approved" : "rejected",
approvedAt: approved ? new Date().toISOString() : undefined,
reviewedByUser: true,
content: editedPlan, // Update content if user provided an edited version
@@ -1397,7 +1465,7 @@ Format your response as a structured markdown document.`;
// If rejected with feedback, we can store it for the user to see
if (!approved && feedback) {
// Emit event so client knows the rejection reason
this.emitAutoModeEvent('plan_rejected', {
this.emitAutoModeEvent("plan_rejected", {
featureId,
projectPath,
feedback,
@@ -1415,15 +1483,25 @@ Format your response as a structured markdown document.`;
* Cancel a pending plan approval (e.g., when feature is stopped).
*/
cancelPlanApproval(featureId: string): void {
console.log(`[AutoMode] cancelPlanApproval called for feature ${featureId}`);
console.log(`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(', ') || 'none'}`);
console.log(
`[AutoMode] cancelPlanApproval called for feature ${featureId}`
);
console.log(
`[AutoMode] Current pending approvals: ${Array.from(this.pendingApprovals.keys()).join(", ") || "none"}`
);
const pending = this.pendingApprovals.get(featureId);
if (pending) {
console.log(`[AutoMode] Found and cancelling pending approval for feature ${featureId}`);
pending.reject(new Error('Plan approval cancelled - feature was stopped'));
console.log(
`[AutoMode] Found and cancelling pending approval for feature ${featureId}`
);
pending.reject(
new Error("Plan approval cancelled - feature was stopped")
);
this.pendingApprovals.delete(featureId);
} else {
console.log(`[AutoMode] No pending approval to cancel for feature ${featureId}`);
console.log(
`[AutoMode] No pending approval to cancel for feature ${featureId}`
);
}
}
@@ -1436,7 +1514,6 @@ Format your response as a structured markdown document.`;
// Private helpers
/**
* Find an existing worktree for a given branch by checking git worktree list
*/
@@ -1498,7 +1575,7 @@ Format your response as a structured markdown document.`;
const featurePath = path.join(featureDir, "feature.json");
try {
const data = await secureFs.readFile(featurePath, "utf-8") as string;
const data = (await secureFs.readFile(featurePath, "utf-8")) as string;
return JSON.parse(data);
} catch {
return null;
@@ -1515,7 +1592,7 @@ Format your response as a structured markdown document.`;
const featurePath = path.join(featureDir, "feature.json");
try {
const data = await secureFs.readFile(featurePath, "utf-8") as string;
const data = (await secureFs.readFile(featurePath, "utf-8")) as string;
const feature = JSON.parse(data);
feature.status = status;
feature.updatedAt = new Date().toISOString();
@@ -1550,13 +1627,13 @@ Format your response as a structured markdown document.`;
);
try {
const data = await secureFs.readFile(featurePath, "utf-8") as string;
const data = (await secureFs.readFile(featurePath, "utf-8")) as string;
const feature = JSON.parse(data);
// Initialize planSpec if it doesn't exist
if (!feature.planSpec) {
feature.planSpec = {
status: 'pending',
status: "pending",
version: 1,
reviewedByUser: false,
};
@@ -1573,7 +1650,10 @@ Format your response as a structured markdown document.`;
feature.updatedAt = new Date().toISOString();
await secureFs.writeFile(featurePath, JSON.stringify(feature, null, 2));
} catch (error) {
console.error(`[AutoMode] Failed to update planSpec for ${featureId}:`, error);
console.error(
`[AutoMode] Failed to update planSpec for ${featureId}:`,
error
);
}
}
@@ -1582,7 +1662,9 @@ Format your response as a structured markdown document.`;
const featuresDir = getFeaturesDir(projectPath);
try {
const entries = await secureFs.readdir(featuresDir, { withFileTypes: true });
const entries = await secureFs.readdir(featuresDir, {
withFileTypes: true,
});
const allFeatures: Feature[] = [];
const pendingFeatures: Feature[] = [];
@@ -1595,7 +1677,10 @@ Format your response as a structured markdown document.`;
"feature.json"
);
try {
const data = await secureFs.readFile(featurePath, "utf-8") as string;
const data = (await secureFs.readFile(
featurePath,
"utf-8"
)) as string;
const feature = JSON.parse(data);
allFeatures.push(feature);
@@ -1617,7 +1702,7 @@ Format your response as a structured markdown document.`;
const { orderedFeatures } = resolveDependencies(pendingFeatures);
// Filter to only features with satisfied dependencies
const readyFeatures = orderedFeatures.filter(feature =>
const readyFeatures = orderedFeatures.filter((feature: Feature) =>
areDependenciesSatisfied(feature, allFeatures)
);
@@ -1649,24 +1734,25 @@ Format your response as a structured markdown document.`;
* Get the planning prompt prefix based on feature's planning mode
*/
private getPlanningPromptPrefix(feature: Feature): string {
const mode = feature.planningMode || 'skip';
const mode = feature.planningMode || "skip";
if (mode === 'skip') {
return ''; // No planning phase
if (mode === "skip") {
return ""; // No planning phase
}
// For lite mode, use the approval variant if requirePlanApproval is true
let promptKey: string = mode;
if (mode === 'lite' && feature.requirePlanApproval === true) {
promptKey = 'lite_with_approval';
if (mode === "lite" && feature.requirePlanApproval === true) {
promptKey = "lite_with_approval";
}
const planningPrompt = PLANNING_PROMPTS[promptKey as keyof typeof PLANNING_PROMPTS];
const planningPrompt =
PLANNING_PROMPTS[promptKey as keyof typeof PLANNING_PROMPTS];
if (!planningPrompt) {
return '';
return "";
}
return planningPrompt + '\n\n---\n\n## Feature Request\n\n';
return planningPrompt + "\n\n---\n\n## Feature Request\n\n";
}
private buildFeaturePrompt(feature: Feature): string {
@@ -1760,17 +1846,18 @@ This helps parse your summary correctly in the output logs.`;
}
): Promise<void> {
const finalProjectPath = options?.projectPath || projectPath;
const planningMode = options?.planningMode || 'skip';
const planningMode = options?.planningMode || "skip";
const previousContent = options?.previousContent;
// Check if this planning mode can generate a spec/plan that needs approval
// - spec and full always generate specs
// - lite only generates approval-ready content when requirePlanApproval is true
const planningModeRequiresApproval =
planningMode === 'spec' ||
planningMode === 'full' ||
(planningMode === 'lite' && options?.requirePlanApproval === true);
const requiresApproval = planningModeRequiresApproval && options?.requirePlanApproval === true;
planningMode === "spec" ||
planningMode === "full" ||
(planningMode === "lite" && options?.requirePlanApproval === true);
const requiresApproval =
planningModeRequiresApproval && options?.requirePlanApproval === true;
// CI/CD Mock Mode: Return early with mock response when AUTOMAKER_MOCK_AGENT is set
// This prevents actual API calls during automated testing
@@ -1953,11 +2040,15 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
scheduleWrite();
// Check for [SPEC_GENERATED] marker in planning modes (spec or full)
if (planningModeRequiresApproval && !specDetected && responseText.includes('[SPEC_GENERATED]')) {
if (
planningModeRequiresApproval &&
!specDetected &&
responseText.includes("[SPEC_GENERATED]")
) {
specDetected = true;
// Extract plan content (everything before the marker)
const markerIndex = responseText.indexOf('[SPEC_GENERATED]');
const markerIndex = responseText.indexOf("[SPEC_GENERATED]");
const planContent = responseText.substring(0, markerIndex).trim();
// Parse tasks from the generated spec (for spec and full modes)
@@ -1965,14 +2056,18 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
let parsedTasks = parseTasksFromSpec(planContent);
const tasksTotal = parsedTasks.length;
console.log(`[AutoMode] Parsed ${tasksTotal} tasks from spec for feature ${featureId}`);
console.log(
`[AutoMode] Parsed ${tasksTotal} tasks from spec for feature ${featureId}`
);
if (parsedTasks.length > 0) {
console.log(`[AutoMode] Tasks: ${parsedTasks.map(t => t.id).join(', ')}`);
console.log(
`[AutoMode] Tasks: ${parsedTasks.map((t) => t.id).join(", ")}`
);
}
// Update planSpec status to 'generated' and save content with parsed tasks
await this.updateFeaturePlanSpec(projectPath, featureId, {
status: 'generated',
status: "generated",
content: planContent,
version: 1,
generatedAt: new Date().toISOString(),
@@ -1996,13 +2091,18 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
let planApproved = false;
while (!planApproved) {
console.log(`[AutoMode] Spec v${planVersion} generated for feature ${featureId}, waiting for approval`);
console.log(
`[AutoMode] Spec v${planVersion} generated for feature ${featureId}, waiting for approval`
);
// CRITICAL: Register pending approval BEFORE emitting event
const approvalPromise = this.waitForPlanApproval(featureId, projectPath);
const approvalPromise = this.waitForPlanApproval(
featureId,
projectPath
);
// Emit plan_approval_required event
this.emitAutoModeEvent('plan_approval_required', {
this.emitAutoModeEvent("plan_approval_required", {
featureId,
projectPath,
planContent: currentPlanContent,
@@ -2016,15 +2116,21 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
if (approvalResult.approved) {
// User approved the plan
console.log(`[AutoMode] Plan v${planVersion} approved for feature ${featureId}`);
console.log(
`[AutoMode] Plan v${planVersion} approved for feature ${featureId}`
);
planApproved = true;
// If user provided edits, use the edited version
if (approvalResult.editedPlan) {
approvedPlanContent = approvalResult.editedPlan;
await this.updateFeaturePlanSpec(projectPath, featureId, {
content: approvalResult.editedPlan,
});
await this.updateFeaturePlanSpec(
projectPath,
featureId,
{
content: approvalResult.editedPlan,
}
);
} else {
approvedPlanContent = currentPlanContent;
}
@@ -2033,30 +2139,37 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
userFeedback = approvalResult.feedback;
// Emit approval event
this.emitAutoModeEvent('plan_approved', {
this.emitAutoModeEvent("plan_approved", {
featureId,
projectPath,
hasEdits: !!approvalResult.editedPlan,
planVersion,
});
} else {
// User rejected - check if they provided feedback for revision
const hasFeedback = approvalResult.feedback && approvalResult.feedback.trim().length > 0;
const hasEdits = approvalResult.editedPlan && approvalResult.editedPlan.trim().length > 0;
const hasFeedback =
approvalResult.feedback &&
approvalResult.feedback.trim().length > 0;
const hasEdits =
approvalResult.editedPlan &&
approvalResult.editedPlan.trim().length > 0;
if (!hasFeedback && !hasEdits) {
// No feedback or edits = explicit cancel
console.log(`[AutoMode] Plan rejected without feedback for feature ${featureId}, cancelling`);
throw new Error('Plan cancelled by user');
console.log(
`[AutoMode] Plan rejected without feedback for feature ${featureId}, cancelling`
);
throw new Error("Plan cancelled by user");
}
// User wants revisions - regenerate the plan
console.log(`[AutoMode] Plan v${planVersion} rejected with feedback for feature ${featureId}, regenerating...`);
console.log(
`[AutoMode] Plan v${planVersion} rejected with feedback for feature ${featureId}, regenerating...`
);
planVersion++;
// Emit revision event
this.emitAutoModeEvent('plan_revision_requested', {
this.emitAutoModeEvent("plan_revision_requested", {
featureId,
projectPath,
feedback: approvalResult.feedback,
@@ -2071,7 +2184,7 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set.
${hasEdits ? approvalResult.editedPlan : currentPlanContent}
## User Feedback
${approvalResult.feedback || 'Please revise the plan based on the edits above.'}
${approvalResult.feedback || "Please revise the plan based on the edits above."}
## Instructions
Please regenerate the specification incorporating the user's feedback.
@@ -2082,7 +2195,7 @@ After generating the revised spec, output:
// Update status to regenerating
await this.updateFeaturePlanSpec(projectPath, featureId, {
status: 'generating',
status: "generating",
version: planVersion,
});
@@ -2109,27 +2222,38 @@ After generating the revised spec, output:
}
}
} else if (msg.type === "error") {
throw new Error(msg.error || "Error during plan revision");
} else if (msg.type === "result" && msg.subtype === "success") {
throw new Error(
msg.error || "Error during plan revision"
);
} else if (
msg.type === "result" &&
msg.subtype === "success"
) {
revisionText += msg.result || "";
}
}
// Extract new plan content
const markerIndex = revisionText.indexOf('[SPEC_GENERATED]');
const markerIndex =
revisionText.indexOf("[SPEC_GENERATED]");
if (markerIndex > 0) {
currentPlanContent = revisionText.substring(0, markerIndex).trim();
currentPlanContent = revisionText
.substring(0, markerIndex)
.trim();
} else {
currentPlanContent = revisionText.trim();
}
// Re-parse tasks from revised plan
const revisedTasks = parseTasksFromSpec(currentPlanContent);
console.log(`[AutoMode] Revised plan has ${revisedTasks.length} tasks`);
const revisedTasks =
parseTasksFromSpec(currentPlanContent);
console.log(
`[AutoMode] Revised plan has ${revisedTasks.length} tasks`
);
// Update planSpec with revised content
await this.updateFeaturePlanSpec(projectPath, featureId, {
status: 'generated',
status: "generated",
content: currentPlanContent,
version: planVersion,
tasks: revisedTasks,
@@ -2142,21 +2266,23 @@ After generating the revised spec, output:
responseText += revisionText;
}
} catch (error) {
if ((error as Error).message.includes('cancelled')) {
if ((error as Error).message.includes("cancelled")) {
throw error;
}
throw new Error(`Plan approval failed: ${(error as Error).message}`);
throw new Error(
`Plan approval failed: ${(error as Error).message}`
);
}
}
} else {
// Auto-approve: requirePlanApproval is false, just continue without pausing
console.log(`[AutoMode] Spec generated for feature ${featureId}, auto-approving (requirePlanApproval=false)`);
console.log(
`[AutoMode] Spec generated for feature ${featureId}, auto-approving (requirePlanApproval=false)`
);
// Emit info event for frontend
this.emitAutoModeEvent('plan_auto_approved', {
this.emitAutoModeEvent("plan_auto_approved", {
featureId,
projectPath,
planContent,
@@ -2168,11 +2294,13 @@ After generating the revised spec, output:
// CRITICAL: After approval, we need to make a second call to continue implementation
// The agent is waiting for "approved" - we need to send it and continue
console.log(`[AutoMode] Making continuation call after plan approval for feature ${featureId}`);
console.log(
`[AutoMode] Making continuation call after plan approval for feature ${featureId}`
);
// Update planSpec status to approved (handles both manual and auto-approval paths)
await this.updateFeaturePlanSpec(projectPath, featureId, {
status: 'approved',
status: "approved",
approvedAt: new Date().toISOString(),
reviewedByUser: requiresApproval,
});
@@ -2183,19 +2311,27 @@ After generating the revised spec, output:
// ========================================
if (parsedTasks.length > 0) {
console.log(`[AutoMode] Starting multi-agent execution: ${parsedTasks.length} tasks for feature ${featureId}`);
console.log(
`[AutoMode] Starting multi-agent execution: ${parsedTasks.length} tasks for feature ${featureId}`
);
// Execute each task with a separate agent
for (let taskIndex = 0; taskIndex < parsedTasks.length; taskIndex++) {
for (
let taskIndex = 0;
taskIndex < parsedTasks.length;
taskIndex++
) {
const task = parsedTasks[taskIndex];
// Check for abort
if (abortController.signal.aborted) {
throw new Error('Feature execution aborted');
throw new Error("Feature execution aborted");
}
// Emit task started
console.log(`[AutoMode] Starting task ${task.id}: ${task.description}`);
console.log(
`[AutoMode] Starting task ${task.id}: ${task.description}`
);
this.emitAutoModeEvent("auto_mode_task_started", {
featureId,
projectPath,
@@ -2211,7 +2347,13 @@ After generating the revised spec, output:
});
// Build focused prompt for this specific task
const taskPrompt = this.buildTaskPrompt(task, parsedTasks, taskIndex, approvedPlanContent, userFeedback);
const taskPrompt = this.buildTaskPrompt(
task,
parsedTasks,
taskIndex,
approvedPlanContent,
userFeedback
);
// Execute task with dedicated agent
const taskStream = provider.executeQuery({
@@ -2245,15 +2387,22 @@ After generating the revised spec, output:
}
}
} else if (msg.type === "error") {
throw new Error(msg.error || `Error during task ${task.id}`);
} else if (msg.type === "result" && msg.subtype === "success") {
throw new Error(
msg.error || `Error during task ${task.id}`
);
} else if (
msg.type === "result" &&
msg.subtype === "success"
) {
taskOutput += msg.result || "";
responseText += msg.result || "";
}
}
// Emit task completed
console.log(`[AutoMode] Task ${task.id} completed for feature ${featureId}`);
console.log(
`[AutoMode] Task ${task.id} completed for feature ${featureId}`
);
this.emitAutoModeEvent("auto_mode_task_complete", {
featureId,
projectPath,
@@ -2284,13 +2433,17 @@ After generating the revised spec, output:
}
}
console.log(`[AutoMode] All ${parsedTasks.length} tasks completed for feature ${featureId}`);
console.log(
`[AutoMode] All ${parsedTasks.length} tasks completed for feature ${featureId}`
);
} else {
// No parsed tasks - fall back to single-agent execution
console.log(`[AutoMode] No parsed tasks, using single-agent execution for feature ${featureId}`);
console.log(
`[AutoMode] No parsed tasks, using single-agent execution for feature ${featureId}`
);
const continuationPrompt = `The plan/specification has been approved. Now implement it.
${userFeedback ? `\n## User Feedback\n${userFeedback}\n` : ''}
${userFeedback ? `\n## User Feedback\n${userFeedback}\n` : ""}
## Approved Plan
${approvedPlanContent}
@@ -2326,14 +2479,21 @@ Implement all the changes described in the plan above.`;
}
}
} else if (msg.type === "error") {
throw new Error(msg.error || "Unknown error during implementation");
} else if (msg.type === "result" && msg.subtype === "success") {
throw new Error(
msg.error || "Unknown error during implementation"
);
} else if (
msg.type === "result" &&
msg.subtype === "success"
) {
responseText += msg.result || "";
}
}
}
console.log(`[AutoMode] Implementation completed for feature ${featureId}`);
console.log(
`[AutoMode] Implementation completed for feature ${featureId}`
);
// Exit the original stream loop since continuation is done
break streamLoop;
}
@@ -2410,9 +2570,16 @@ ${context}
## Instructions
Review the previous work and continue the implementation. If the feature appears complete, verify it works correctly.`;
return this.executeFeature(projectPath, featureId, useWorktrees, false, undefined, {
continuationPrompt: prompt,
});
return this.executeFeature(
projectPath,
featureId,
useWorktrees,
false,
undefined,
{
continuationPrompt: prompt,
}
);
}
/**
@@ -2437,8 +2604,8 @@ You are executing a specific task as part of a larger feature implementation.
**Task ID:** ${task.id}
**Description:** ${task.description}
${task.filePath ? `**Primary File:** ${task.filePath}` : ''}
${task.phase ? `**Phase:** ${task.phase}` : ''}
${task.filePath ? `**Primary File:** ${task.filePath}` : ""}
${task.phase ? `**Phase:** ${task.phase}` : ""}
## Context
@@ -2447,7 +2614,7 @@ ${task.phase ? `**Phase:** ${task.phase}` : ''}
// Show what's already done
if (completedTasks.length > 0) {
prompt += `### Already Completed (${completedTasks.length} tasks)
${completedTasks.map(t => `- [x] ${t.id}: ${t.description}`).join('\n')}
${completedTasks.map((t) => `- [x] ${t.id}: ${t.description}`).join("\n")}
`;
}
@@ -2455,8 +2622,11 @@ ${completedTasks.map(t => `- [x] ${t.id}: ${t.description}`).join('\n')}
// Show remaining tasks
if (remainingTasks.length > 0) {
prompt += `### Coming Up Next (${remainingTasks.length} tasks remaining)
${remainingTasks.slice(0, 3).map(t => `- [ ] ${t.id}: ${t.description}`).join('\n')}
${remainingTasks.length > 3 ? `... and ${remainingTasks.length - 3} more tasks` : ''}
${remainingTasks
.slice(0, 3)
.map((t) => `- [ ] ${t.id}: ${t.description}`)
.join("\n")}
${remainingTasks.length > 3 ? `... and ${remainingTasks.length - 3} more tasks` : ""}
`;
}

View File

@@ -4,49 +4,20 @@
*/
import path from "path";
import type { Feature } from "@automaker/types";
import { createLogger } from "@automaker/utils";
import * as secureFs from "../lib/secure-fs.js";
import {
getFeaturesDir,
getFeatureDir,
getFeatureImagesDir,
ensureAutomakerDir,
} from "../lib/automaker-paths.js";
} from "@automaker/platform";
export interface Feature {
id: string;
title?: string;
titleGenerating?: boolean;
category: string;
description: string;
steps?: string[];
passes?: boolean;
priority?: number;
status?: string;
dependencies?: string[];
spec?: string;
model?: string;
imagePaths?: Array<string | { path: string; [key: string]: unknown }>;
// Branch info - worktree path is derived at runtime from branchName
branchName?: string; // Name of the feature branch (undefined = use current worktree)
skipTests?: boolean;
thinkingLevel?: string;
planningMode?: 'skip' | 'lite' | 'spec' | 'full';
requirePlanApproval?: boolean;
planSpec?: {
status: 'pending' | 'generating' | 'generated' | 'approved' | 'rejected';
content?: string;
version: number;
generatedAt?: string;
approvedAt?: string;
reviewedByUser: boolean;
tasksCompleted?: number;
tasksTotal?: number;
};
error?: string;
summary?: string;
startedAt?: string;
[key: string]: unknown; // Keep catch-all for extensibility
}
const logger = createLogger("FeatureLoader");
// Re-export Feature type for convenience
export type { Feature };
export class FeatureLoader {
/**
@@ -68,8 +39,12 @@ export class FeatureLoader {
*/
private async deleteOrphanedImages(
projectPath: string,
oldPaths: Array<string | { path: string; [key: string]: unknown }> | undefined,
newPaths: Array<string | { path: string; [key: string]: unknown }> | undefined
oldPaths:
| Array<string | { path: string; [key: string]: unknown }>
| undefined,
newPaths:
| Array<string | { path: string; [key: string]: unknown }>
| undefined
): Promise<void> {
if (!oldPaths || oldPaths.length === 0) {
return;
@@ -92,7 +67,7 @@ export class FeatureLoader {
console.log(`[FeatureLoader] Deleted orphaned image: ${oldPath}`);
} catch (error) {
// Ignore errors when deleting (file may already be gone)
console.warn(
logger.warn(
`[FeatureLoader] Failed to delete image: ${oldPath}`,
error
);
@@ -118,8 +93,9 @@ export class FeatureLoader {
const featureImagesDir = this.getFeatureImagesDir(projectPath, featureId);
await secureFs.mkdir(featureImagesDir, { recursive: true });
const updatedPaths: Array<string | { path: string; [key: string]: unknown }> =
[];
const updatedPaths: Array<
string | { path: string; [key: string]: unknown }
> = [];
for (const imagePath of imagePaths) {
try {
@@ -141,7 +117,7 @@ export class FeatureLoader {
try {
await secureFs.access(fullOriginalPath);
} catch {
console.warn(
logger.warn(
`[FeatureLoader] Image not found, skipping: ${fullOriginalPath}`
);
continue;
@@ -171,9 +147,10 @@ export class FeatureLoader {
updatedPaths.push({ ...imagePath, path: newPath });
}
} catch (error) {
console.error(`[FeatureLoader] Failed to migrate image:`, error);
// Keep original path if migration fails
updatedPaths.push(imagePath);
logger.error(`Failed to migrate image:`, error);
// Rethrow error to let caller decide how to handle it
// Keeping original path could lead to broken references
throw error;
}
}
@@ -191,14 +168,20 @@ export class FeatureLoader {
* Get the path to a feature's feature.json file
*/
getFeatureJsonPath(projectPath: string, featureId: string): string {
return path.join(this.getFeatureDir(projectPath, featureId), "feature.json");
return path.join(
this.getFeatureDir(projectPath, featureId),
"feature.json"
);
}
/**
* Get the path to a feature's agent-output.md file
*/
getAgentOutputPath(projectPath: string, featureId: string): string {
return path.join(this.getFeatureDir(projectPath, featureId), "agent-output.md");
return path.join(
this.getFeatureDir(projectPath, featureId),
"agent-output.md"
);
}
/**
@@ -223,7 +206,9 @@ export class FeatureLoader {
}
// Read all feature directories
const entries = await secureFs.readdir(featuresDir, { withFileTypes: true }) as any[];
const entries = (await secureFs.readdir(featuresDir, {
withFileTypes: true,
})) as any[];
const featureDirs = entries.filter((entry) => entry.isDirectory());
// Load each feature
@@ -233,11 +218,14 @@ export class FeatureLoader {
const featureJsonPath = this.getFeatureJsonPath(projectPath, featureId);
try {
const content = await secureFs.readFile(featureJsonPath, "utf-8") as string;
const content = (await secureFs.readFile(
featureJsonPath,
"utf-8"
)) as string;
const feature = JSON.parse(content);
if (!feature.id) {
console.warn(
logger.warn(
`[FeatureLoader] Feature ${featureId} missing required 'id' field, skipping`
);
continue;
@@ -248,11 +236,11 @@ export class FeatureLoader {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
continue;
} else if (error instanceof SyntaxError) {
console.warn(
logger.warn(
`[FeatureLoader] Failed to parse feature.json for ${featureId}: ${error.message}`
);
} else {
console.error(
logger.error(
`[FeatureLoader] Failed to load feature ${featureId}:`,
(error as Error).message
);
@@ -269,7 +257,7 @@ export class FeatureLoader {
return features;
} catch (error) {
console.error("[FeatureLoader] Failed to get all features:", error);
logger.error("Failed to get all features:", error);
return [];
}
}
@@ -280,13 +268,16 @@ export class FeatureLoader {
async get(projectPath: string, featureId: string): Promise<Feature | null> {
try {
const featureJsonPath = this.getFeatureJsonPath(projectPath, featureId);
const content = await secureFs.readFile(featureJsonPath, "utf-8") as string;
const content = (await secureFs.readFile(
featureJsonPath,
"utf-8"
)) as string;
return JSON.parse(content);
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
return null;
}
console.error(
logger.error(
`[FeatureLoader] Failed to get feature ${featureId}:`,
error
);
@@ -334,7 +325,7 @@ export class FeatureLoader {
"utf-8"
);
console.log(`[FeatureLoader] Created feature ${featureId}`);
logger.info(`Created feature ${featureId}`);
return feature;
}
@@ -386,7 +377,7 @@ export class FeatureLoader {
"utf-8"
);
console.log(`[FeatureLoader] Updated feature ${featureId}`);
logger.info(`Updated feature ${featureId}`);
return updatedFeature;
}
@@ -400,7 +391,7 @@ export class FeatureLoader {
console.log(`[FeatureLoader] Deleted feature ${featureId}`);
return true;
} catch (error) {
console.error(
logger.error(
`[FeatureLoader] Failed to delete feature ${featureId}:`,
error
);
@@ -417,13 +408,16 @@ export class FeatureLoader {
): Promise<string | null> {
try {
const agentOutputPath = this.getAgentOutputPath(projectPath, featureId);
const content = await secureFs.readFile(agentOutputPath, "utf-8") as string;
const content = (await secureFs.readFile(
agentOutputPath,
"utf-8"
)) as string;
return content;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
return null;
}
console.error(
logger.error(
`[FeatureLoader] Failed to get agent output for ${featureId}:`,
error
);

View File

@@ -7,15 +7,16 @@
* - Per-project settings ({projectPath}/.automaker/settings.json)
*/
import { createLogger } from "@automaker/utils";
import * as secureFs from "../lib/secure-fs.js";
import { createLogger } from "../lib/logger.js";
import {
getGlobalSettingsPath,
getCredentialsPath,
getProjectSettingsPath,
ensureDataDir,
ensureAutomakerDir,
} from "../lib/automaker-paths.js";
} from "@automaker/platform";
import type {
GlobalSettings,
Credentials,
@@ -64,7 +65,7 @@ async function atomicWriteJson(filePath: string, data: unknown): Promise<void> {
*/
async function readJsonFile<T>(filePath: string, defaultValue: T): Promise<T> {
try {
const content = await secureFs.readFile(filePath, "utf-8") as string;
const content = (await secureFs.readFile(filePath, "utf-8")) as string;
return JSON.parse(content) as T;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
@@ -231,9 +232,7 @@ export class SettingsService {
* @param updates - Partial Credentials (usually just apiKeys)
* @returns Promise resolving to complete updated Credentials object
*/
async updateCredentials(
updates: Partial<Credentials>
): Promise<Credentials> {
async updateCredentials(updates: Partial<Credentials>): Promise<Credentials> {
await ensureDataDir(this.dataDir);
const credentialsPath = getCredentialsPath(this.dataDir);
@@ -495,10 +494,14 @@ export class SettingsService {
if (appState.apiKeys) {
const apiKeys = appState.apiKeys as {
anthropic?: string;
google?: string;
openai?: string;
};
await this.updateCredentials({
apiKeys: {
anthropic: apiKeys.anthropic || "",
google: apiKeys.google || "",
openai: apiKeys.openai || "",
},
});
migratedCredentials = true;
@@ -548,8 +551,7 @@ export class SettingsService {
// Get theme from project object
const project = projects.find((p) => p.path === projectPath);
if (project?.theme) {
projectSettings.theme =
project.theme as ProjectSettings["theme"];
projectSettings.theme = project.theme as ProjectSettings["theme"];
}
if (boardBackgroundByProject?.[projectPath]) {
@@ -571,7 +573,9 @@ export class SettingsService {
migratedProjectCount++;
}
} catch (e) {
errors.push(`Failed to migrate project settings for ${projectPath}: ${e}`);
errors.push(
`Failed to migrate project settings for ${projectPath}: ${e}`
);
}
}

View File

@@ -1,422 +1,35 @@
/**
* Settings Types - Shared types for file-based settings storage
* Settings Types - Re-exported from @automaker/types
*
* Defines the structure for global settings, credentials, and per-project settings
* that are persisted to disk in JSON format. These types are used by both the server
* (for file I/O via SettingsService) and the UI (for state management and sync).
* This file now re-exports settings types from the shared @automaker/types package
* to maintain backward compatibility with existing imports in the server codebase.
*/
/**
* ThemeMode - Available color themes for the UI
*
* Includes system theme and multiple color schemes:
* - System: Respects OS dark/light mode preference
* - Light/Dark: Basic light and dark variants
* - Color Schemes: Retro, Dracula, Nord, Monokai, Tokyo Night, Solarized, Gruvbox,
* Catppuccin, OneDark, Synthwave, Red, Cream, Sunset, Gray
*/
export type ThemeMode =
| "light"
| "dark"
| "system"
| "retro"
| "dracula"
| "nord"
| "monokai"
| "tokyonight"
| "solarized"
| "gruvbox"
| "catppuccin"
| "onedark"
| "synthwave"
| "red"
| "cream"
| "sunset"
| "gray";
export type {
ThemeMode,
KanbanCardDetailLevel,
AgentModel,
PlanningMode,
ThinkingLevel,
ModelProvider,
KeyboardShortcuts,
AIProfile,
ProjectRef,
TrashedProjectRef,
ChatSessionRef,
GlobalSettings,
Credentials,
BoardBackgroundSettings,
WorktreeInfo,
ProjectSettings,
} from "@automaker/types";
/** KanbanCardDetailLevel - Controls how much information is displayed on kanban cards */
export type KanbanCardDetailLevel = "minimal" | "standard" | "detailed";
/** AgentModel - Available Claude models for feature generation and planning */
export type AgentModel = "opus" | "sonnet" | "haiku";
/** PlanningMode - Planning levels for feature generation workflows */
export type PlanningMode = "skip" | "lite" | "spec" | "full";
/** ThinkingLevel - Extended thinking levels for Claude models (reasoning intensity) */
export type ThinkingLevel = "none" | "low" | "medium" | "high" | "ultrathink";
/** ModelProvider - AI model provider for credentials and API key management */
export type ModelProvider = "claude";
/**
* KeyboardShortcuts - User-configurable keyboard bindings for common actions
*
* Each property maps an action to a keyboard shortcut string
* (e.g., "Ctrl+K", "Alt+N", "Shift+P")
*/
export interface KeyboardShortcuts {
/** Open board view */
board: string;
/** Open agent panel */
agent: string;
/** Open feature spec editor */
spec: string;
/** Open context files panel */
context: string;
/** Open settings */
settings: string;
/** Open AI profiles */
profiles: string;
/** Open terminal */
terminal: string;
/** Toggle sidebar visibility */
toggleSidebar: string;
/** Add new feature */
addFeature: string;
/** Add context file */
addContextFile: string;
/** Start next feature generation */
startNext: string;
/** Create new chat session */
newSession: string;
/** Open project picker */
openProject: string;
/** Open project picker (alternate) */
projectPicker: string;
/** Cycle to previous project */
cyclePrevProject: string;
/** Cycle to next project */
cycleNextProject: string;
/** Add new AI profile */
addProfile: string;
/** Split terminal right */
splitTerminalRight: string;
/** Split terminal down */
splitTerminalDown: string;
/** Close current terminal */
closeTerminal: string;
}
/**
* AIProfile - Configuration for an AI model with specific parameters
*
* Profiles can be built-in defaults or user-created. They define which model to use,
* thinking level, and other parameters for feature generation tasks.
*/
export interface AIProfile {
/** Unique identifier for the profile */
id: string;
/** Display name for the profile */
name: string;
/** User-friendly description */
description: string;
/** Which Claude model to use (opus, sonnet, haiku) */
model: AgentModel;
/** Extended thinking level for reasoning-based tasks */
thinkingLevel: ThinkingLevel;
/** Provider (currently only "claude") */
provider: ModelProvider;
/** Whether this is a built-in default profile */
isBuiltIn: boolean;
/** Optional icon identifier or emoji */
icon?: string;
}
/**
* ProjectRef - Minimal reference to a project stored in global settings
*
* Used for the projects list and project history. Full project data is loaded separately.
*/
export interface ProjectRef {
/** Unique identifier */
id: string;
/** Display name */
name: string;
/** Absolute filesystem path to project directory */
path: string;
/** ISO timestamp of last time project was opened */
lastOpened?: string;
/** Project-specific theme override (or undefined to use global) */
theme?: string;
}
/**
* TrashedProjectRef - Reference to a project in the trash/recycle bin
*
* Extends ProjectRef with deletion metadata. User can permanently delete or restore.
*/
export interface TrashedProjectRef extends ProjectRef {
/** ISO timestamp when project was moved to trash */
trashedAt: string;
/** Whether project folder was deleted from disk */
deletedFromDisk?: boolean;
}
/**
* ChatSessionRef - Minimal reference to a chat session
*
* Used for session lists and history. Full session content is stored separately.
*/
export interface ChatSessionRef {
/** Unique session identifier */
id: string;
/** User-given or AI-generated title */
title: string;
/** Project that session belongs to */
projectId: string;
/** ISO timestamp of creation */
createdAt: string;
/** ISO timestamp of last message */
updatedAt: string;
/** Whether session is archived */
archived: boolean;
}
/**
* GlobalSettings - User preferences and state stored globally in {DATA_DIR}/settings.json
*
* This is the main settings file that persists user preferences across sessions.
* Includes theme, UI state, feature defaults, keyboard shortcuts, AI profiles, and projects.
* Format: JSON with version field for migration support.
*/
export interface GlobalSettings {
/** Version number for schema migration */
version: number;
// Theme Configuration
/** Currently selected theme */
theme: ThemeMode;
// UI State Preferences
/** Whether sidebar is currently open */
sidebarOpen: boolean;
/** Whether chat history panel is open */
chatHistoryOpen: boolean;
/** How much detail to show on kanban cards */
kanbanCardDetailLevel: KanbanCardDetailLevel;
// Feature Generation Defaults
/** Max features to generate concurrently */
maxConcurrency: number;
/** Default: skip tests during feature generation */
defaultSkipTests: boolean;
/** Default: enable dependency blocking */
enableDependencyBlocking: boolean;
/** Default: use git worktrees for feature branches */
useWorktrees: boolean;
/** Default: only show AI profiles (hide other settings) */
showProfilesOnly: boolean;
/** Default: planning approach (skip/lite/spec/full) */
defaultPlanningMode: PlanningMode;
/** Default: require manual approval before generating */
defaultRequirePlanApproval: boolean;
/** ID of currently selected AI profile (null = use built-in) */
defaultAIProfileId: string | null;
// Audio Preferences
/** Mute completion notification sound */
muteDoneSound: boolean;
// AI Model Selection
/** Which model to use for feature name/description enhancement */
enhancementModel: AgentModel;
// Input Configuration
/** User's keyboard shortcut bindings */
keyboardShortcuts: KeyboardShortcuts;
// AI Profiles
/** User-created AI profiles */
aiProfiles: AIProfile[];
// Project Management
/** List of active projects */
projects: ProjectRef[];
/** Projects in trash/recycle bin */
trashedProjects: TrashedProjectRef[];
/** History of recently opened project IDs */
projectHistory: string[];
/** Current position in project history for navigation */
projectHistoryIndex: number;
// File Browser and UI Preferences
/** Last directory opened in file picker */
lastProjectDir?: string;
/** Recently accessed folders for quick access */
recentFolders: string[];
/** Whether worktree panel is collapsed in current view */
worktreePanelCollapsed: boolean;
// Session Tracking
/** Maps project path -> last selected session ID in that project */
lastSelectedSessionByProject: Record<string, string>;
}
/**
* Credentials - API keys stored in {DATA_DIR}/credentials.json
*
* Sensitive data stored separately from general settings.
* Keys should never be exposed in UI or logs.
*/
export interface Credentials {
/** Version number for schema migration */
version: number;
/** API keys for various providers */
apiKeys: {
/** Anthropic Claude API key */
anthropic: string;
};
}
/**
* BoardBackgroundSettings - Kanban board appearance customization
*
* Controls background images, opacity, borders, and visual effects for the board.
*/
export interface BoardBackgroundSettings {
/** Path to background image file (null = no image) */
imagePath: string | null;
/** Version/timestamp of image for cache busting */
imageVersion?: number;
/** Opacity of cards (0-1) */
cardOpacity: number;
/** Opacity of columns (0-1) */
columnOpacity: number;
/** Show border around columns */
columnBorderEnabled: boolean;
/** Apply glassmorphism effect to cards */
cardGlassmorphism: boolean;
/** Show border around cards */
cardBorderEnabled: boolean;
/** Opacity of card borders (0-1) */
cardBorderOpacity: number;
/** Hide scrollbar in board view */
hideScrollbar: boolean;
}
/**
* WorktreeInfo - Information about a git worktree
*
* Tracks worktree location, branch, and dirty state for project management.
*/
export interface WorktreeInfo {
/** Absolute path to worktree directory */
path: string;
/** Branch checked out in this worktree */
branch: string;
/** Whether this is the main worktree */
isMain: boolean;
/** Whether worktree has uncommitted changes */
hasChanges?: boolean;
/** Number of files with changes */
changedFilesCount?: number;
}
/**
* ProjectSettings - Project-specific overrides stored in {projectPath}/.automaker/settings.json
*
* Allows per-project customization without affecting global settings.
* All fields are optional - missing values fall back to global settings.
*/
export interface ProjectSettings {
/** Version number for schema migration */
version: number;
// Theme Configuration (project-specific override)
/** Project theme (undefined = use global setting) */
theme?: ThemeMode;
// Worktree Management
/** Project-specific worktree preference override */
useWorktrees?: boolean;
/** Current worktree being used in this project */
currentWorktree?: { path: string | null; branch: string };
/** List of worktrees available in this project */
worktrees?: WorktreeInfo[];
// Board Customization
/** Project-specific board background settings */
boardBackground?: BoardBackgroundSettings;
// Session Tracking
/** Last chat session selected in this project */
lastSelectedSessionId?: string;
}
/**
* Default values and constants
*/
/** Default keyboard shortcut bindings */
export const DEFAULT_KEYBOARD_SHORTCUTS: KeyboardShortcuts = {
board: "K",
agent: "A",
spec: "D",
context: "C",
settings: "S",
profiles: "M",
terminal: "T",
toggleSidebar: "`",
addFeature: "N",
addContextFile: "N",
startNext: "G",
newSession: "N",
openProject: "O",
projectPicker: "P",
cyclePrevProject: "Q",
cycleNextProject: "E",
addProfile: "N",
splitTerminalRight: "Alt+D",
splitTerminalDown: "Alt+S",
closeTerminal: "Alt+W",
};
/** Default global settings used when no settings file exists */
export const DEFAULT_GLOBAL_SETTINGS: GlobalSettings = {
version: 1,
theme: "dark",
sidebarOpen: true,
chatHistoryOpen: false,
kanbanCardDetailLevel: "standard",
maxConcurrency: 3,
defaultSkipTests: true,
enableDependencyBlocking: true,
useWorktrees: false,
showProfilesOnly: false,
defaultPlanningMode: "skip",
defaultRequirePlanApproval: false,
defaultAIProfileId: null,
muteDoneSound: false,
enhancementModel: "sonnet",
keyboardShortcuts: DEFAULT_KEYBOARD_SHORTCUTS,
aiProfiles: [],
projects: [],
trashedProjects: [],
projectHistory: [],
projectHistoryIndex: -1,
lastProjectDir: undefined,
recentFolders: [],
worktreePanelCollapsed: false,
lastSelectedSessionByProject: {},
};
/** Default credentials (empty strings - user must provide API keys) */
export const DEFAULT_CREDENTIALS: Credentials = {
version: 1,
apiKeys: {
anthropic: "",
},
};
/** Default project settings (empty - all settings are optional and fall back to global) */
export const DEFAULT_PROJECT_SETTINGS: ProjectSettings = {
version: 1,
};
/** Current version of the global settings schema */
export const SETTINGS_VERSION = 1;
/** Current version of the credentials schema */
export const CREDENTIALS_VERSION = 1;
/** Current version of the project settings schema */
export const PROJECT_SETTINGS_VERSION = 1;
export {
DEFAULT_KEYBOARD_SHORTCUTS,
DEFAULT_GLOBAL_SETTINGS,
DEFAULT_CREDENTIALS,
DEFAULT_PROJECT_SETTINGS,
SETTINGS_VERSION,
CREDENTIALS_VERSION,
PROJECT_SETTINGS_VERSION,
} from "@automaker/types";