feat: Modernize package with ES modules and improve error handling
- Update to ES modules syntax throughout the codebase - Add fileURLToPath and dirname imports to handle __dirname in ES modules - Upgrade Anthropic SDK from 0.10.0 to 0.39.0 - Fix JSON parsing to handle responses wrapped in Markdown code blocks - Improve documentation with clearer installation instructions - Add important notes about ES modules and SDK requirements - Update environment examples with API key format and model recommendations - Include index.js in package files list - Bump version to 1.0.2
This commit is contained in:
@@ -34,6 +34,12 @@ This project uses the Claude Task Master system to manage development tasks in a
|
||||
npm run generate
|
||||
```
|
||||
|
||||
### Important Notes
|
||||
|
||||
1. This project uses ES modules. The package.json includes `"type": "module"`.
|
||||
2. The Anthropic SDK version should be 0.39.0 or higher.
|
||||
3. If you encounter JSON parsing errors, make sure your Anthropic API key is valid and your environment is set up correctly.
|
||||
|
||||
## Integrating with Cursor AI
|
||||
|
||||
This project includes Cursor AI integration through the `.cursor/rules/dev_workflow.mdc` file, which provides the AI with knowledge about the task management system.
|
||||
|
||||
@@ -42,6 +42,11 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Load environment variables from .env file
|
||||
dotenv.config();
|
||||
@@ -169,9 +174,17 @@ async function callClaude(prdContent, prdPath, numTasks) {
|
||||
log('debug', `Response length: ${textContent.length} characters`);
|
||||
|
||||
try {
|
||||
// Try to parse the response as JSON
|
||||
// Check if the response is wrapped in a Markdown code block and extract the JSON
|
||||
log('info', "Parsing response as JSON...");
|
||||
const parsedJson = JSON.parse(textContent);
|
||||
let jsonText = textContent;
|
||||
const codeBlockMatch = textContent.match(/```(?:json)?\s*([\s\S]*?)\s*```/);
|
||||
if (codeBlockMatch) {
|
||||
log('debug', "Detected JSON wrapped in Markdown code block, extracting...");
|
||||
jsonText = codeBlockMatch[1];
|
||||
}
|
||||
|
||||
// Try to parse the response as JSON
|
||||
const parsedJson = JSON.parse(jsonText);
|
||||
log('info', `Successfully parsed JSON with ${parsedJson.tasks?.length || 0} tasks`);
|
||||
return parsedJson;
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Required
|
||||
ANTHROPIC_API_KEY=your-api-key-here
|
||||
ANTHROPIC_API_KEY=your-api-key-here # Format: sk-ant-api03-...
|
||||
|
||||
# Optional - defaults shown
|
||||
MODEL=claude-3-7-sonnet-20250219
|
||||
MAX_TOKENS=4000
|
||||
TEMPERATURE=0.7
|
||||
DEBUG=false
|
||||
LOG_LEVEL=info
|
||||
DEFAULT_SUBTASKS=3
|
||||
DEFAULT_PRIORITY=medium
|
||||
PROJECT_NAME={{projectName}}
|
||||
PROJECT_VERSION={{projectVersion}}
|
||||
MODEL=claude-3-7-sonnet-20250219 # Recommended models: claude-3-7-sonnet-20250219, claude-3-opus-20240229
|
||||
MAX_TOKENS=4000 # Maximum tokens for model responses
|
||||
TEMPERATURE=0.7 # Temperature for model responses (0.0-1.0)
|
||||
DEBUG=false # Enable debug logging (true/false)
|
||||
LOG_LEVEL=info # Log level (debug, info, warn, error)
|
||||
DEFAULT_SUBTASKS=3 # Default number of subtasks when expanding
|
||||
DEFAULT_PRIORITY=medium # Default priority for generated tasks (high, medium, low)
|
||||
PROJECT_NAME={{projectName}} # Project name for tasks.json metadata
|
||||
PROJECT_VERSION={{projectVersion}} # Project version for tasks.json metadata
|
||||
Reference in New Issue
Block a user