chore: cleanup and apply requested changes

This commit is contained in:
Ralph Khreish
2025-08-27 23:32:35 +02:00
parent 86d9c4b194
commit 5ed3f2f16b
18 changed files with 165 additions and 231 deletions

View File

@@ -1,37 +1,37 @@
{
"models": {
"main": {
"provider": "anthropic",
"modelId": "claude-3-7-sonnet-20250219",
"maxTokens": 120000,
"temperature": 0.2
},
"research": {
"provider": "perplexity",
"modelId": "sonar",
"maxTokens": 8700,
"temperature": 0.1
},
"fallback": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet-20241022",
"maxTokens": 8192,
"temperature": 0.2
}
},
"global": {
"logLevel": "info",
"debug": false,
"defaultNumTasks": 10,
"defaultSubtasks": 5,
"defaultPriority": "medium",
"projectName": "Taskmaster",
"ollamaBaseURL": "http://localhost:11434/api",
"bedrockBaseURL": "https://bedrock.us-east-1.amazonaws.com",
"responseLanguage": "English",
"userId": "1234567890",
"azureBaseURL": "https://your-endpoint.azure.com/",
"defaultTag": "master"
},
"claudeCode": {}
}
"models": {
"main": {
"provider": "anthropic",
"modelId": "claude-3-7-sonnet-20250219",
"maxTokens": 120000,
"temperature": 0.2
},
"research": {
"provider": "perplexity",
"modelId": "sonar",
"maxTokens": 8700,
"temperature": 0.1
},
"fallback": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet-20241022",
"maxTokens": 8192,
"temperature": 0.2
}
},
"global": {
"logLevel": "info",
"debug": false,
"defaultNumTasks": 10,
"defaultSubtasks": 5,
"defaultPriority": "medium",
"projectName": "Taskmaster",
"ollamaBaseURL": "http://localhost:11434/api",
"bedrockBaseURL": "https://bedrock.us-east-1.amazonaws.com",
"responseLanguage": "English",
"userId": "1234567890",
"azureBaseURL": "https://your-endpoint.azure.com/",
"defaultTag": "master"
},
"claudeCode": {}
}

View File

@@ -1,9 +1,9 @@
{
"currentTag": "master",
"lastSwitched": "2025-08-27T21:03:20.550Z",
"branchTagMapping": {
"v017-adds": "v017-adds",
"next": "next"
},
"migrationNoticeShown": true
}
"currentTag": "master",
"lastSwitched": "2025-08-27T21:03:20.550Z",
"branchTagMapping": {
"v017-adds": "v017-adds",
"next": "next"
},
"migrationNoticeShown": true
}

View File

@@ -1,7 +0,0 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"extends": ["../../biome.json"],
"files": {
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
}

View File

@@ -93,7 +93,10 @@ export class ListTasksCommand extends Command {
this.displayResults(result, options);
}
} catch (error: any) {
console.error(chalk.red(`Error: ${error.message}`));
const msg = error?.getSanitizedDetails?.() ?? {
message: error?.message ?? String(error)
};
console.error(chalk.red(`Error: ${msg.message || 'Unexpected error'}`));
if (error.stack && process.env.DEBUG) {
console.error(chalk.gray(error.stack));
}

7
package-lock.json generated
View File

@@ -77,7 +77,8 @@
"prettier": "^3.5.3",
"supertest": "^7.1.0",
"tsup": "^8.5.0",
"tsx": "^4.16.2"
"tsx": "^4.16.2",
"typescript": "^5.9.2"
},
"engines": {
"node": ">=18.0.0"
@@ -24783,7 +24784,9 @@
}
},
"node_modules/typescript": {
"version": "5.8.3",
"version": "5.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz",
"integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
"dev": true,
"license": "Apache-2.0",
"bin": {

View File

@@ -136,6 +136,7 @@
"prettier": "^3.5.3",
"supertest": "^7.1.0",
"tsup": "^8.5.0",
"tsx": "^4.16.2"
"tsx": "^4.16.2",
"typescript": "^5.9.2"
}
}

View File

@@ -1,104 +0,0 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true,
"defaultBranch": "main"
},
"files": {
"include": ["src/**/*.ts", "tests/**/*.ts", "*.ts", "*.js", "*.json"],
"ignore": [
"**/node_modules",
"**/dist",
"**/.git",
"**/coverage",
"**/*.d.ts"
]
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"useConst": "error",
"useImportType": "warn",
"useTemplate": "warn",
"noUselessElse": "warn",
"noVar": "error"
},
"correctness": {
"noUnusedVariables": "warn",
"noUnusedImports": "error",
"useExhaustiveDependencies": "warn"
},
"complexity": {
"noBannedTypes": "error",
"noForEach": "off",
"noStaticOnlyClass": "warn",
"noUselessConstructor": "error",
"noUselessTypeConstraint": "error",
"useArrowFunction": "off"
},
"suspicious": {
"noExplicitAny": "warn",
"noImplicitAnyLet": "error",
"noArrayIndexKey": "warn",
"noAsyncPromiseExecutor": "error",
"noDoubleEquals": "warn",
"noRedundantUseStrict": "error"
},
"security": {
"noGlobalEval": "error"
},
"performance": {
"noAccumulatingSpread": "warn",
"noDelete": "warn"
},
"a11y": {
"recommended": false
}
}
},
"javascript": {
"formatter": {
"enabled": true,
"quoteStyle": "single",
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false
},
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
},
"json": {
"formatter": {
"enabled": true,
"indentStyle": "tab",
"lineWidth": 100,
"trailingCommas": "none"
},
"parser": {
"allowComments": true,
"allowTrailingCommas": false
}
}
}

View File

@@ -3,6 +3,15 @@
* This file exports all custom error types and error handling utilities
*/
// Export the main TaskMasterError class
export {
TaskMasterError,
ERROR_CODES,
type ErrorCode,
type ErrorContext,
type SerializableError
} from './task-master-error.js';
// Error implementations will be defined here
// export * from './task-errors.js';
// export * from './storage-errors.js';

View File

@@ -32,7 +32,10 @@ export class FileOperations {
/**
* Write JSON file with atomic operation and locking
*/
async writeJson(filePath: string, data: FileStorageData | any): Promise<void> {
async writeJson(
filePath: string,
data: FileStorageData | any
): Promise<void> {
// Use file locking to prevent concurrent writes
const lockKey = filePath;
const existingLock = this.fileLocks.get(lockKey);
@@ -109,7 +112,9 @@ export class FileOperations {
try {
await fs.mkdir(dirPath, { recursive: true });
} catch (error: any) {
throw new Error(`Failed to create directory ${dirPath}: ${error.message}`);
throw new Error(
`Failed to create directory ${dirPath}: ${error.message}`
);
}
}
@@ -133,7 +138,9 @@ export class FileOperations {
try {
await fs.rename(oldPath, newPath);
} catch (error: any) {
throw new Error(`Failed to move file from ${oldPath} to ${newPath}: ${error.message}`);
throw new Error(
`Failed to move file from ${oldPath} to ${newPath}: ${error.message}`
);
}
}
@@ -144,7 +151,9 @@ export class FileOperations {
try {
await fs.copyFile(srcPath, destPath);
} catch (error: any) {
throw new Error(`Failed to copy file from ${srcPath} to ${destPath}: ${error.message}`);
throw new Error(
`Failed to copy file from ${srcPath} to ${destPath}: ${error.message}`
);
}
}
@@ -158,4 +167,4 @@ export class FileOperations {
}
this.fileLocks.clear();
}
}
}

View File

@@ -44,18 +44,18 @@ export class FileStorage implements IStorage {
*/
async getStats(): Promise<StorageStats> {
const filePath = this.pathResolver.getTasksPath();
try {
const stats = await this.fileOps.getStats(filePath);
const data = await this.fileOps.readJson(filePath);
const tags = this.formatHandler.extractTags(data);
let totalTasks = 0;
const tagStats = tags.map((tag) => {
const tasks = this.formatHandler.extractTasks(data, tag);
const taskCount = tasks.length;
totalTasks += taskCount;
return {
tag,
taskCount,
@@ -136,7 +136,12 @@ export class FileStorage implements IStorage {
const normalizedTasks = this.normalizeTaskIds(tasks);
// Update the specific tag in the existing data structure
if (this.formatHandler.detectFormat(existingData) === 'legacy' || Object.keys(existingData).some(key => key !== 'tasks' && key !== 'metadata')) {
if (
this.formatHandler.detectFormat(existingData) === 'legacy' ||
Object.keys(existingData).some(
(key) => key !== 'tasks' && key !== 'metadata'
)
) {
// Legacy format - update/add the tag
existingData[resolvedTag] = {
tasks: normalizedTasks,
@@ -152,7 +157,7 @@ export class FileStorage implements IStorage {
// Convert to legacy format when adding non-master tags
const masterTasks = existingData.tasks || [];
const masterMetadata = existingData.metadata || metadata;
existingData = {
master: {
tasks: masterTasks,
@@ -177,11 +182,12 @@ export class FileStorage implements IStorage {
...task,
id: String(task.id), // Task IDs are strings
dependencies: task.dependencies?.map((dep) => String(dep)) || [],
subtasks: task.subtasks?.map((subtask) => ({
...subtask,
id: Number(subtask.id), // Subtask IDs are numbers
parentId: String(subtask.parentId) // Parent ID is string (Task ID)
})) || []
subtasks:
task.subtasks?.map((subtask) => ({
...subtask,
id: Number(subtask.id), // Subtask IDs are numbers
parentId: String(subtask.parentId) // Parent ID is string (Task ID)
})) || []
}));
}
@@ -286,10 +292,10 @@ export class FileStorage implements IStorage {
*/
async deleteTag(tag: string): Promise<void> {
const filePath = this.pathResolver.getTasksPath();
try {
const existingData = await this.fileOps.readJson(filePath);
if (this.formatHandler.detectFormat(existingData) === 'legacy') {
// Legacy format - remove the tag key
if (tag in existingData) {
@@ -317,21 +323,21 @@ export class FileStorage implements IStorage {
*/
async renameTag(oldTag: string, newTag: string): Promise<void> {
const filePath = this.pathResolver.getTasksPath();
try {
const existingData = await this.fileOps.readJson(filePath);
if (this.formatHandler.detectFormat(existingData) === 'legacy') {
// Legacy format - rename the tag key
if (oldTag in existingData) {
existingData[newTag] = existingData[oldTag];
delete existingData[oldTag];
// Update metadata tags array
if (existingData[newTag].metadata) {
existingData[newTag].metadata.tags = [newTag];
}
await this.fileOps.writeJson(filePath, existingData);
} else {
throw new Error(`Tag ${oldTag} not found`);
@@ -340,14 +346,14 @@ export class FileStorage implements IStorage {
// Convert standard format to legacy when renaming master
const masterTasks = existingData.tasks || [];
const masterMetadata = existingData.metadata || {};
const newData = {
[newTag]: {
tasks: masterTasks,
metadata: { ...masterMetadata, tags: [newTag] }
}
};
await this.fileOps.writeJson(filePath, newData);
} else {
throw new Error(`Tag ${oldTag} not found in standard format`);
@@ -375,4 +381,4 @@ export class FileStorage implements IStorage {
}
// Export as default for convenience
export default FileStorage;
export default FileStorage;

View File

@@ -24,11 +24,13 @@ export class FormatHandler {
}
const keys = Object.keys(data);
// Check if this uses the legacy format with tag keys
// Legacy format has keys that are not 'tasks' or 'metadata'
const hasLegacyFormat = keys.some(key => key !== 'tasks' && key !== 'metadata');
const hasLegacyFormat = keys.some(
(key) => key !== 'tasks' && key !== 'metadata'
);
return hasLegacyFormat ? 'legacy' : 'standard';
}
@@ -41,11 +43,11 @@ export class FormatHandler {
}
const format = this.detectFormat(data);
if (format === 'legacy') {
return this.extractTasksFromLegacy(data, tag);
}
return this.extractTasksFromStandard(data);
}
@@ -60,7 +62,9 @@ export class FormatHandler {
}
// If we're looking for 'master' tag but it doesn't exist, try the first available tag
const availableKeys = Object.keys(data).filter(key => key !== 'tasks' && key !== 'metadata');
const availableKeys = Object.keys(data).filter(
(key) => key !== 'tasks' && key !== 'metadata'
);
if (tag === 'master' && availableKeys.length > 0) {
const firstTag = availableKeys[0];
const tagData = data[firstTag];
@@ -86,18 +90,21 @@ export class FormatHandler {
}
const format = this.detectFormat(data);
if (format === 'legacy') {
return this.extractMetadataFromLegacy(data, tag);
}
return this.extractMetadataFromStandard(data);
}
/**
* Extract metadata from legacy format
*/
private extractMetadataFromLegacy(data: any, tag: string): TaskMetadata | null {
private extractMetadataFromLegacy(
data: any,
tag: string
): TaskMetadata | null {
if (tag in data) {
const tagData = data[tag];
// Generate metadata if not present in legacy format
@@ -108,7 +115,9 @@ export class FormatHandler {
}
// If we're looking for 'master' tag but it doesn't exist, try the first available tag
const availableKeys = Object.keys(data).filter(key => key !== 'tasks' && key !== 'metadata');
const availableKeys = Object.keys(data).filter(
(key) => key !== 'tasks' && key !== 'metadata'
);
if (tag === 'master' && availableKeys.length > 0) {
const firstTag = availableKeys[0];
const tagData = data[firstTag];
@@ -137,13 +146,13 @@ export class FormatHandler {
}
const format = this.detectFormat(data);
if (format === 'legacy') {
// Return all tag keys from legacy format
const keys = Object.keys(data);
return keys.filter(key => key !== 'tasks' && key !== 'metadata');
return keys.filter((key) => key !== 'tasks' && key !== 'metadata');
}
// Standard format - just has 'master' tag
return ['master'];
}
@@ -152,21 +161,21 @@ export class FormatHandler {
* Convert tasks and metadata to the appropriate format for saving
*/
convertToSaveFormat(
tasks: Task[],
metadata: TaskMetadata,
existingData: any,
tasks: Task[],
metadata: TaskMetadata,
existingData: any,
tag: string
): any {
const resolvedTag = tag || 'master';
// Normalize task IDs to strings
const normalizedTasks = this.normalizeTasks(tasks);
// Check if existing file uses legacy format
if (existingData && this.detectFormat(existingData) === 'legacy') {
return this.convertToLegacyFormat(normalizedTasks, metadata, resolvedTag);
}
// Use standard format for new files
return this.convertToStandardFormat(normalizedTasks, metadata, tag);
}
@@ -175,8 +184,8 @@ export class FormatHandler {
* Convert to legacy format
*/
private convertToLegacyFormat(
tasks: Task[],
metadata: TaskMetadata,
tasks: Task[],
metadata: TaskMetadata,
tag: string
): any {
return {
@@ -194,8 +203,8 @@ export class FormatHandler {
* Convert to standard format
*/
private convertToStandardFormat(
tasks: Task[],
metadata: TaskMetadata,
tasks: Task[],
metadata: TaskMetadata,
tag?: string
): FileStorageData {
return {
@@ -215,11 +224,12 @@ export class FormatHandler {
...task,
id: String(task.id), // Task IDs are strings
dependencies: task.dependencies?.map((dep) => String(dep)) || [],
subtasks: task.subtasks?.map((subtask) => ({
...subtask,
id: Number(subtask.id), // Subtask IDs are numbers
parentId: String(subtask.parentId) // Parent ID is string (Task ID)
})) || []
subtasks:
task.subtasks?.map((subtask) => ({
...subtask,
id: Number(subtask.id), // Subtask IDs are numbers
parentId: String(subtask.parentId) // Parent ID is string (Task ID)
})) || []
}));
}
@@ -235,4 +245,4 @@ export class FormatHandler {
tags: [tag]
};
}
}
}

View File

@@ -2,9 +2,13 @@
* @fileoverview Exports for file storage components
*/
export { FormatHandler, type FileStorageData, type FileFormat } from './format-handler.js';
export {
FormatHandler,
type FileStorageData,
type FileFormat
} from './format-handler.js';
export { FileOperations } from './file-operations.js';
export { PathResolver } from './path-resolver.js';
// Main FileStorage class - primary export
export { FileStorage as default, FileStorage } from './file-storage.js';
export { FileStorage as default, FileStorage } from './file-storage.js';

View File

@@ -39,4 +39,4 @@ export class PathResolver {
getTasksPath(): string {
return this.tasksFilePath;
}
}
}

View File

@@ -28,12 +28,12 @@
"isolatedModules": true,
"paths": {
"@/*": ["./src/*"],
"@/types": ["./src/types/index"],
"@/providers": ["./src/providers/index"],
"@/storage": ["./src/storage/index"],
"@/parser": ["./src/parser/index"],
"@/utils": ["./src/utils/index"],
"@/errors": ["./src/errors/index"]
"@/types": ["./src/types"],
"@/providers": ["./src/providers"],
"@/storage": ["./src/storage"],
"@/parser": ["./src/parser"],
"@/utils": ["./src/utils"],
"@/errors": ["./src/errors"]
}
},
"include": ["src/**/*"],

View File

@@ -1,6 +1,11 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
// __dirname in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default defineConfig({
test: {
globals: true,
@@ -8,6 +13,7 @@ export default defineConfig({
include: [
'tests/**/*.test.ts',
'tests/**/*.spec.ts',
'tests/{unit,integration,e2e}/**/*.{test,spec}.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts'
],
@@ -22,7 +28,7 @@ export default defineConfig({
'**/*.test.ts',
'**/*.spec.ts',
'**/*.d.ts',
'**/index.ts'
'src/index.ts'
],
thresholds: {
branches: 80,

View File

@@ -3,6 +3,8 @@
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2022"],
"types": ["node"],
"allowJs": true,
"resolveJsonModule": true,
"esModuleInterop": true,
@@ -10,13 +12,7 @@
"strict": true,
"skipLibCheck": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"@tm/core": ["packages/tm-core/src/index.ts"],
"@tm/core/*": ["packages/tm-core/src/*"],
"@tm/cli": ["apps/cli/src/index.ts"],
"@tm/cli/*": ["apps/cli/src/*"]
}
"baseUrl": "."
},
"tsx": {
"tsconfig": {

View File

@@ -10,8 +10,6 @@ export default defineConfig({
splitting: false,
sourcemap: true,
clean: true,
shims: true,
dts: true,
bundle: true, // Bundle everything into one file
outDir: 'dist',
// Handle TypeScript imports transparently