Merge main into massive-terminal-upgrade

Resolves merge conflicts:
- apps/server/src/routes/terminal/common.ts: Keep randomBytes import, use @automaker/utils for createLogger
- apps/ui/eslint.config.mjs: Use main's explicit globals list with XMLHttpRequest and MediaQueryListEvent additions
- apps/ui/src/components/views/terminal-view.tsx: Keep our terminal improvements (killAllSessions, beforeunload, better error handling)
- apps/ui/src/config/terminal-themes.ts: Keep our search highlight colors for all themes
- apps/ui/src/store/app-store.ts: Keep our terminal settings persistence improvements (merge function)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
SuperComboGamer
2025-12-21 20:27:44 -05:00
393 changed files with 32473 additions and 17974 deletions

257
libs/prompts/README.md Normal file
View File

@@ -0,0 +1,257 @@
# @automaker/prompts
AI prompt templates for text enhancement and other AI-powered features in AutoMaker.
## Overview
This package provides professionally-crafted prompt templates for enhancing user-written task descriptions using Claude. It includes system prompts, few-shot examples, and utility functions for different enhancement modes: improve, technical, simplify, and acceptance.
## Installation
```bash
npm install @automaker/prompts
```
## Exports
### Enhancement Modes
Four modes are available, each optimized for a specific enhancement task:
- **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
### System Prompts
Direct access to system prompts for each mode:
```typescript
import {
IMPROVE_SYSTEM_PROMPT,
TECHNICAL_SYSTEM_PROMPT,
SIMPLIFY_SYSTEM_PROMPT,
ACCEPTANCE_SYSTEM_PROMPT,
} from '@automaker/prompts';
console.log(IMPROVE_SYSTEM_PROMPT); // Full system prompt for improve mode
```
### Helper Functions
#### `getEnhancementPrompt(mode, description)`
Get complete prompt (system + user) for an enhancement mode:
```typescript
import { getEnhancementPrompt } from '@automaker/prompts';
const result = getEnhancementPrompt('improve', 'make app faster');
console.log(result.systemPrompt); // System instructions for improve mode
console.log(result.userPrompt); // User prompt with examples and input
```
#### `getSystemPrompt(mode)`
Get only the system prompt for a mode:
```typescript
import { getSystemPrompt } from '@automaker/prompts';
const systemPrompt = getSystemPrompt('technical');
```
#### `getExamples(mode)`
Get few-shot examples for a mode:
```typescript
import { getExamples } from '@automaker/prompts';
const examples = getExamples('simplify');
// Returns array of { input, output } pairs
```
#### `buildUserPrompt(description, mode)`
Build user prompt with examples:
```typescript
import { buildUserPrompt } from '@automaker/prompts';
const userPrompt = buildUserPrompt('add login page', 'improve');
// Includes examples + user's description
```
#### `isValidEnhancementMode(mode)`
Check if a mode is valid:
```typescript
import { isValidEnhancementMode } from '@automaker/prompts';
if (isValidEnhancementMode('improve')) {
// Mode is valid
}
```
#### `getAvailableEnhancementModes()`
Get list of all available modes:
```typescript
import { getAvailableEnhancementModes } from '@automaker/prompts';
const modes = getAvailableEnhancementModes();
// Returns: ['improve', 'technical', 'simplify', 'acceptance']
```
## Usage Examples
### Basic Enhancement
```typescript
import { getEnhancementPrompt } from '@automaker/prompts';
async function enhanceDescription(description: string, mode: string) {
const { systemPrompt, userPrompt } = getEnhancementPrompt(mode, description);
const response = await claude.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: systemPrompt,
messages: [{ role: 'user', content: userPrompt }],
});
return response.content[0].text;
}
// Example usage
const improved = await enhanceDescription('make app faster', 'improve');
// → "Optimize application performance by profiling bottlenecks..."
const technical = await enhanceDescription('add search', 'technical');
// → "Implement full-text search with the following components:..."
```
### Mode Validation
```typescript
import { isValidEnhancementMode, getAvailableEnhancementModes } from '@automaker/prompts';
function validateAndEnhance(mode: string, description: string) {
if (!isValidEnhancementMode(mode)) {
const available = getAvailableEnhancementModes().join(', ');
throw new Error(`Invalid mode "${mode}". Available: ${available}`);
}
return enhanceDescription(description, mode);
}
```
### Custom Prompt Building
```typescript
import { getSystemPrompt, buildUserPrompt, getExamples } from '@automaker/prompts';
// Get components separately for custom workflows
const systemPrompt = getSystemPrompt('simplify');
const examples = getExamples('simplify');
const userPrompt = buildUserPrompt(userInput, 'simplify');
// Use with custom processing
const response = await processWithClaude(systemPrompt, userPrompt);
```
### Server Route Example
```typescript
import { getEnhancementPrompt, isValidEnhancementMode } from '@automaker/prompts';
import { createLogger } from '@automaker/utils';
const logger = createLogger('EnhancementRoute');
app.post('/api/enhance', async (req, res) => {
const { description, mode } = req.body;
if (!isValidEnhancementMode(mode)) {
return res.status(400).json({ error: 'Invalid enhancement mode' });
}
try {
const { systemPrompt, userPrompt } = getEnhancementPrompt(mode, description);
const result = await claude.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: systemPrompt,
messages: [{ role: 'user', content: userPrompt }],
});
logger.info(`Enhanced with mode: ${mode}`);
res.json({ enhanced: result.content[0].text });
} catch (error) {
logger.error('Enhancement failed:', error);
res.status(500).json({ error: 'Enhancement failed' });
}
});
```
## Enhancement Mode Details
### Improve Mode
Transforms vague or unclear requests into clear, actionable specifications.
**Before:** "make app faster"
**After:** "Optimize application performance by:
1. Profiling code to identify bottlenecks
2. Implementing caching for frequently accessed data
3. Optimizing database queries..."
### Technical Mode
Adds implementation details and technical specifications.
**Before:** "add search"
**After:** "Implement full-text search using:
- Backend: Elasticsearch or PostgreSQL full-text search
- Frontend: Debounced search input with loading states
- API: GET /api/search endpoint with pagination..."
### Simplify Mode
Makes verbose descriptions concise while preserving essential information.
**Before:** "We really need to make sure that the application has the capability to allow users to be able to search for various items..."
**After:** "Add search functionality for items with filters and results display."
### Acceptance Mode
Adds testable acceptance criteria to feature descriptions.
**Before:** "user login"
**After:** "User login feature
- User can enter email and password
- System validates credentials
- On success: redirect to dashboard
- On failure: show error message
- Remember me option persists login..."
## Dependencies
- `@automaker/types` - Type definitions for EnhancementMode and EnhancementExample
## Used By
- `@automaker/server` - Enhancement API routes
- Future packages requiring AI-powered text enhancement
## License
SEE LICENSE IN LICENSE

29
libs/prompts/package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "@automaker/prompts",
"version": "1.0.0",
"type": "module",
"description": "AI prompt templates for AutoMaker",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"test": "vitest run",
"test:watch": "vitest"
},
"keywords": [
"automaker",
"prompts",
"ai"
],
"author": "AutoMaker Team",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@automaker/types": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22.10.5",
"typescript": "^5.7.3",
"vitest": "^4.0.16"
}
}

View File

@@ -0,0 +1,448 @@
/**
* Enhancement Prompts Library - AI-powered text enhancement for task descriptions
*
* 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.
*/
import type { EnhancementMode, EnhancementExample } from '@automaker/types';
// Re-export enhancement types from shared package
export type { EnhancementMode, EnhancementExample } from '@automaker/types';
/**
* 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[];
}

25
libs/prompts/src/index.ts Normal file
View File

@@ -0,0 +1,25 @@
/**
* @automaker/prompts
* AI prompt templates for AutoMaker
*/
// Enhancement prompts
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 './enhancement.js';
// Re-export types from @automaker/types
export type { EnhancementMode, EnhancementExample } from '@automaker/types';

View File

@@ -0,0 +1,525 @@
import { describe, it, expect } from 'vitest';
import {
getEnhancementPrompt,
getSystemPrompt,
getExamples,
buildUserPrompt,
isValidEnhancementMode,
getAvailableEnhancementModes,
IMPROVE_SYSTEM_PROMPT,
TECHNICAL_SYSTEM_PROMPT,
SIMPLIFY_SYSTEM_PROMPT,
ACCEPTANCE_SYSTEM_PROMPT,
IMPROVE_EXAMPLES,
TECHNICAL_EXAMPLES,
SIMPLIFY_EXAMPLES,
ACCEPTANCE_EXAMPLES,
} from '../src/enhancement.js';
describe('enhancement.ts', () => {
describe('System Prompt Constants', () => {
it('should export IMPROVE_SYSTEM_PROMPT', () => {
expect(IMPROVE_SYSTEM_PROMPT).toBeDefined();
expect(typeof IMPROVE_SYSTEM_PROMPT).toBe('string');
expect(IMPROVE_SYSTEM_PROMPT).toContain('vague, unclear');
expect(IMPROVE_SYSTEM_PROMPT).toContain('actionable');
});
it('should export TECHNICAL_SYSTEM_PROMPT', () => {
expect(TECHNICAL_SYSTEM_PROMPT).toBeDefined();
expect(typeof TECHNICAL_SYSTEM_PROMPT).toBe('string');
expect(TECHNICAL_SYSTEM_PROMPT).toContain('technical');
expect(TECHNICAL_SYSTEM_PROMPT).toContain('implementation');
});
it('should export SIMPLIFY_SYSTEM_PROMPT', () => {
expect(SIMPLIFY_SYSTEM_PROMPT).toBeDefined();
expect(typeof SIMPLIFY_SYSTEM_PROMPT).toBe('string');
expect(SIMPLIFY_SYSTEM_PROMPT).toContain('verbose');
expect(SIMPLIFY_SYSTEM_PROMPT).toContain('concise');
});
it('should export ACCEPTANCE_SYSTEM_PROMPT', () => {
expect(ACCEPTANCE_SYSTEM_PROMPT).toBeDefined();
expect(typeof ACCEPTANCE_SYSTEM_PROMPT).toBe('string');
expect(ACCEPTANCE_SYSTEM_PROMPT).toContain('acceptance criteria');
expect(ACCEPTANCE_SYSTEM_PROMPT).toContain('testable');
});
});
describe('Examples Constants', () => {
it('should export IMPROVE_EXAMPLES with valid structure', () => {
expect(IMPROVE_EXAMPLES).toBeDefined();
expect(Array.isArray(IMPROVE_EXAMPLES)).toBe(true);
expect(IMPROVE_EXAMPLES.length).toBeGreaterThan(0);
IMPROVE_EXAMPLES.forEach((example) => {
expect(example).toHaveProperty('input');
expect(example).toHaveProperty('output');
expect(typeof example.input).toBe('string');
expect(typeof example.output).toBe('string');
});
});
it('should export TECHNICAL_EXAMPLES with valid structure', () => {
expect(TECHNICAL_EXAMPLES).toBeDefined();
expect(Array.isArray(TECHNICAL_EXAMPLES)).toBe(true);
expect(TECHNICAL_EXAMPLES.length).toBeGreaterThan(0);
TECHNICAL_EXAMPLES.forEach((example) => {
expect(example).toHaveProperty('input');
expect(example).toHaveProperty('output');
expect(typeof example.input).toBe('string');
expect(typeof example.output).toBe('string');
});
});
it('should export SIMPLIFY_EXAMPLES with valid structure', () => {
expect(SIMPLIFY_EXAMPLES).toBeDefined();
expect(Array.isArray(SIMPLIFY_EXAMPLES)).toBe(true);
expect(SIMPLIFY_EXAMPLES.length).toBeGreaterThan(0);
SIMPLIFY_EXAMPLES.forEach((example) => {
expect(example).toHaveProperty('input');
expect(example).toHaveProperty('output');
expect(typeof example.input).toBe('string');
expect(typeof example.output).toBe('string');
});
});
it('should export ACCEPTANCE_EXAMPLES with valid structure', () => {
expect(ACCEPTANCE_EXAMPLES).toBeDefined();
expect(Array.isArray(ACCEPTANCE_EXAMPLES)).toBe(true);
expect(ACCEPTANCE_EXAMPLES.length).toBeGreaterThan(0);
ACCEPTANCE_EXAMPLES.forEach((example) => {
expect(example).toHaveProperty('input');
expect(example).toHaveProperty('output');
expect(typeof example.input).toBe('string');
expect(typeof example.output).toBe('string');
});
});
it('should have shorter outputs in SIMPLIFY_EXAMPLES', () => {
SIMPLIFY_EXAMPLES.forEach((example) => {
// Simplify examples should have shorter output than input
// (though not always strictly enforced, it's the general pattern)
expect(example.output).toBeDefined();
expect(example.output.length).toBeGreaterThan(0);
});
});
});
describe('getEnhancementPrompt', () => {
it("should return prompt config for 'improve' mode", () => {
const result = getEnhancementPrompt('improve');
expect(result).toHaveProperty('systemPrompt');
expect(result).toHaveProperty('description');
expect(result.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
expect(result.description).toContain('vague');
expect(result.description).toContain('actionable');
});
it("should return prompt config for 'technical' mode", () => {
const result = getEnhancementPrompt('technical');
expect(result).toHaveProperty('systemPrompt');
expect(result).toHaveProperty('description');
expect(result.systemPrompt).toBe(TECHNICAL_SYSTEM_PROMPT);
expect(result.description).toContain('implementation');
});
it("should return prompt config for 'simplify' mode", () => {
const result = getEnhancementPrompt('simplify');
expect(result).toHaveProperty('systemPrompt');
expect(result).toHaveProperty('description');
expect(result.systemPrompt).toBe(SIMPLIFY_SYSTEM_PROMPT);
expect(result.description).toContain('verbose');
});
it("should return prompt config for 'acceptance' mode", () => {
const result = getEnhancementPrompt('acceptance');
expect(result).toHaveProperty('systemPrompt');
expect(result).toHaveProperty('description');
expect(result.systemPrompt).toBe(ACCEPTANCE_SYSTEM_PROMPT);
expect(result.description).toContain('acceptance');
});
it('should handle uppercase mode', () => {
const result = getEnhancementPrompt('IMPROVE');
expect(result.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
});
it('should handle mixed case mode', () => {
const result = getEnhancementPrompt('TeChnIcaL');
expect(result.systemPrompt).toBe(TECHNICAL_SYSTEM_PROMPT);
});
it("should fall back to 'improve' for invalid mode", () => {
const result = getEnhancementPrompt('invalid-mode');
expect(result.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
expect(result.description).toContain('vague');
});
it("should fall back to 'improve' for empty string", () => {
const result = getEnhancementPrompt('');
expect(result.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
});
});
describe('getSystemPrompt', () => {
it("should return IMPROVE_SYSTEM_PROMPT for 'improve'", () => {
const result = getSystemPrompt('improve');
expect(result).toBe(IMPROVE_SYSTEM_PROMPT);
});
it("should return TECHNICAL_SYSTEM_PROMPT for 'technical'", () => {
const result = getSystemPrompt('technical');
expect(result).toBe(TECHNICAL_SYSTEM_PROMPT);
});
it("should return SIMPLIFY_SYSTEM_PROMPT for 'simplify'", () => {
const result = getSystemPrompt('simplify');
expect(result).toBe(SIMPLIFY_SYSTEM_PROMPT);
});
it("should return ACCEPTANCE_SYSTEM_PROMPT for 'acceptance'", () => {
const result = getSystemPrompt('acceptance');
expect(result).toBe(ACCEPTANCE_SYSTEM_PROMPT);
});
});
describe('getExamples', () => {
it("should return IMPROVE_EXAMPLES for 'improve'", () => {
const result = getExamples('improve');
expect(result).toBe(IMPROVE_EXAMPLES);
expect(result.length).toBeGreaterThan(0);
});
it("should return TECHNICAL_EXAMPLES for 'technical'", () => {
const result = getExamples('technical');
expect(result).toBe(TECHNICAL_EXAMPLES);
expect(result.length).toBeGreaterThan(0);
});
it("should return SIMPLIFY_EXAMPLES for 'simplify'", () => {
const result = getExamples('simplify');
expect(result).toBe(SIMPLIFY_EXAMPLES);
expect(result.length).toBeGreaterThan(0);
});
it("should return ACCEPTANCE_EXAMPLES for 'acceptance'", () => {
const result = getExamples('acceptance');
expect(result).toBe(ACCEPTANCE_EXAMPLES);
expect(result.length).toBeGreaterThan(0);
});
});
describe('buildUserPrompt', () => {
const testText = 'Add a login feature';
describe('with examples (default)', () => {
it("should include examples by default for 'improve' mode", () => {
const result = buildUserPrompt('improve', testText);
expect(result).toContain('Here are some examples');
expect(result).toContain('Example 1:');
expect(result).toContain(IMPROVE_EXAMPLES[0].input);
expect(result).toContain(IMPROVE_EXAMPLES[0].output);
expect(result).toContain(testText);
});
it("should include examples by default for 'technical' mode", () => {
const result = buildUserPrompt('technical', testText);
expect(result).toContain('Here are some examples');
expect(result).toContain('Example 1:');
expect(result).toContain(TECHNICAL_EXAMPLES[0].input);
expect(result).toContain(testText);
});
it('should include examples when explicitly set to true', () => {
const result = buildUserPrompt('improve', testText, true);
expect(result).toContain('Here are some examples');
expect(result).toContain(testText);
});
it('should format all examples with numbered labels', () => {
const result = buildUserPrompt('improve', testText);
IMPROVE_EXAMPLES.forEach((_, index) => {
expect(result).toContain(`Example ${index + 1}:`);
});
});
it('should separate examples with dividers', () => {
const result = buildUserPrompt('improve', testText);
// Count dividers (---) - should be (examples.length) + 1
const dividerCount = (result.match(/---/g) || []).length;
expect(dividerCount).toBe(IMPROVE_EXAMPLES.length);
});
it("should include 'Now, please enhance' before user text", () => {
const result = buildUserPrompt('improve', testText);
expect(result).toContain('Now, please enhance the following');
expect(result).toContain(testText);
});
});
describe('without examples', () => {
it('should not include examples when includeExamples is false', () => {
const result = buildUserPrompt('improve', testText, false);
expect(result).not.toContain('Here are some examples');
expect(result).not.toContain('Example 1:');
expect(result).not.toContain(IMPROVE_EXAMPLES[0].input);
});
it('should have simple prompt without examples', () => {
const result = buildUserPrompt('improve', testText, false);
expect(result).toBe(`Please enhance the following task description:\n\n${testText}`);
});
it('should preserve user text without examples', () => {
const result = buildUserPrompt('technical', testText, false);
expect(result).toContain(testText);
expect(result).toContain('Please enhance');
});
});
describe('text formatting', () => {
it('should preserve multiline text', () => {
const multilineText = 'Line 1\nLine 2\nLine 3';
const result = buildUserPrompt('improve', multilineText);
expect(result).toContain(multilineText);
});
it('should handle empty text', () => {
const result = buildUserPrompt('improve', '');
// With examples by default, it should contain "Now, please enhance"
expect(result).toContain('Now, please enhance');
expect(result).toContain('Here are some examples');
});
it('should handle whitespace-only text', () => {
const result = buildUserPrompt('improve', ' ');
expect(result).toContain(' ');
});
it('should handle special characters in text', () => {
const specialText = 'Test <html> & "quotes" \'apostrophes\'';
const result = buildUserPrompt('improve', specialText);
expect(result).toContain(specialText);
});
});
describe('all modes', () => {
it('should work for all valid enhancement modes', () => {
const modes: Array<'improve' | 'technical' | 'simplify' | 'acceptance'> = [
'improve',
'technical',
'simplify',
'acceptance',
];
modes.forEach((mode) => {
const result = buildUserPrompt(mode, testText);
expect(result).toBeDefined();
expect(result).toContain(testText);
expect(result.length).toBeGreaterThan(testText.length);
});
});
});
});
describe('isValidEnhancementMode', () => {
it("should return true for 'improve'", () => {
expect(isValidEnhancementMode('improve')).toBe(true);
});
it("should return true for 'technical'", () => {
expect(isValidEnhancementMode('technical')).toBe(true);
});
it("should return true for 'simplify'", () => {
expect(isValidEnhancementMode('simplify')).toBe(true);
});
it("should return true for 'acceptance'", () => {
expect(isValidEnhancementMode('acceptance')).toBe(true);
});
it('should return false for invalid mode', () => {
expect(isValidEnhancementMode('invalid')).toBe(false);
});
it('should return false for empty string', () => {
expect(isValidEnhancementMode('')).toBe(false);
});
it('should return false for uppercase mode', () => {
// Should be case-sensitive since we check object keys directly
expect(isValidEnhancementMode('IMPROVE')).toBe(false);
});
it('should return false for mixed case mode', () => {
expect(isValidEnhancementMode('ImProve')).toBe(false);
});
it('should return false for partial mode names', () => {
expect(isValidEnhancementMode('impro')).toBe(false);
expect(isValidEnhancementMode('tech')).toBe(false);
});
it('should return false for mode with extra characters', () => {
expect(isValidEnhancementMode('improve ')).toBe(false);
expect(isValidEnhancementMode(' improve')).toBe(false);
});
});
describe('getAvailableEnhancementModes', () => {
it('should return array of all enhancement modes', () => {
const modes = getAvailableEnhancementModes();
expect(Array.isArray(modes)).toBe(true);
expect(modes.length).toBe(4);
});
it('should include all valid modes', () => {
const modes = getAvailableEnhancementModes();
expect(modes).toContain('improve');
expect(modes).toContain('technical');
expect(modes).toContain('simplify');
expect(modes).toContain('acceptance');
});
it('should return modes in consistent order', () => {
const modes1 = getAvailableEnhancementModes();
const modes2 = getAvailableEnhancementModes();
expect(modes1).toEqual(modes2);
});
it('should return all valid modes that pass isValidEnhancementMode', () => {
const modes = getAvailableEnhancementModes();
modes.forEach((mode) => {
expect(isValidEnhancementMode(mode)).toBe(true);
});
});
});
describe('Integration tests', () => {
it('should work together: getEnhancementPrompt + buildUserPrompt', () => {
const mode = 'improve';
const text = 'Add search feature';
const { systemPrompt, description } = getEnhancementPrompt(mode);
const userPrompt = buildUserPrompt(mode, text);
expect(systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
expect(description).toBeDefined();
expect(userPrompt).toContain(text);
});
it('should handle complete enhancement workflow', () => {
const availableModes = getAvailableEnhancementModes();
expect(availableModes.length).toBeGreaterThan(0);
availableModes.forEach((mode) => {
const isValid = isValidEnhancementMode(mode);
expect(isValid).toBe(true);
const systemPrompt = getSystemPrompt(mode);
expect(systemPrompt).toBeDefined();
expect(systemPrompt.length).toBeGreaterThan(0);
const examples = getExamples(mode);
expect(Array.isArray(examples)).toBe(true);
expect(examples.length).toBeGreaterThan(0);
const userPrompt = buildUserPrompt(mode, 'test description');
expect(userPrompt).toContain('test description');
});
});
it('should provide consistent data across functions', () => {
const mode = 'technical';
const promptConfig = getEnhancementPrompt(mode);
const systemPrompt = getSystemPrompt(mode);
const examples = getExamples(mode);
expect(promptConfig.systemPrompt).toBe(systemPrompt);
expect(examples).toBe(TECHNICAL_EXAMPLES);
});
});
describe('Examples content validation', () => {
it('IMPROVE_EXAMPLES should demonstrate improvement', () => {
IMPROVE_EXAMPLES.forEach((example) => {
// Output should be longer and more detailed than input
expect(example.output.length).toBeGreaterThan(example.input.length);
// Input should be brief/vague
expect(example.input.length).toBeLessThan(100);
});
});
it('TECHNICAL_EXAMPLES should contain technical terms', () => {
const technicalTerms = [
'API',
'endpoint',
'component',
'database',
'frontend',
'backend',
'validation',
'schema',
'React',
'GET',
'PUT',
'POST',
];
TECHNICAL_EXAMPLES.forEach((example) => {
const hasAnyTechnicalTerm = technicalTerms.some((term) => example.output.includes(term));
expect(hasAnyTechnicalTerm).toBe(true);
});
});
it('ACCEPTANCE_EXAMPLES should contain acceptance criteria format', () => {
ACCEPTANCE_EXAMPLES.forEach((example) => {
// Should contain numbered criteria or Given-When-Then format
const hasAcceptanceCriteria =
example.output.includes('Acceptance Criteria') || example.output.match(/\d+\./g);
expect(hasAcceptanceCriteria).toBeTruthy();
// Should contain Given-When-Then format
const hasGWT =
example.output.includes('Given') &&
example.output.includes('when') &&
example.output.includes('then');
expect(hasGWT).toBe(true);
});
});
});
});

View File

@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}

View File

@@ -0,0 +1,21 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['tests/**/*.test.ts'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
include: ['src/**/*.ts'],
exclude: ['src/**/*.d.ts', 'src/index.ts'],
thresholds: {
lines: 90,
functions: 95,
branches: 85,
statements: 90,
},
},
},
});