← back to Designer Wallcoverings
DW-Agents/dw-agents/add-completed-tasks.ts
122 lines
/**
* Add completed purchasing agent tasks to Task Orchestrator
*/
import fs from 'fs';
import path from 'path';
const TASKS_DB_FILE = path.join(__dirname, 'tasks-database.json');
interface Task {
id: string;
title: string;
description: string;
status: string;
priority: string;
assignedAgent?: string;
createdAt: string;
startedAt?: string;
completedAt?: string;
autoGenerated: boolean;
subtasks: string[];
tags: string[];
metadata: Record<string, any>;
actionLog: Array<{
timestamp: string;
action: string;
agent?: string;
details?: string;
success: boolean;
}>;
}
function generateTaskId(): string {
return `task_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
function loadTasks(): Task[] {
try {
const data = fs.readFileSync(TASKS_DB_FILE, 'utf-8');
const parsed = JSON.parse(data);
return parsed.tasks || parsed || [];
} catch (e) {
return [];
}
}
function saveTasks(tasks: Task[]): void {
fs.writeFileSync(TASKS_DB_FILE, JSON.stringify({ tasks }, null, 2));
}
const completedTasks = [
{
title: "Fixed Find Best Price Network Error",
description: "Problem: API was returning HTML instead of JSON, causing 'Unexpected token <' error. Root cause: Session cookies expired, but requireAuth middleware was redirecting to /login (HTML) for API requests. Fix: Updated requireAuth middleware to return JSON error for API endpoints at /root/Projects/Designer-Wallcoverings/DW-Agents/purchasing-office-agent.ts:185-196",
priority: "high",
tags: ["purchasing", "bug-fix", "authentication", "error-handling"]
},
{
title: "Fixed Refresh Functionality",
description: "Problem: Refresh button appeared not to complete, showing old cached data. Root cause: Amazon blocking all scraping attempts (HTTP 503), but UI didn't communicate this. Fixes: Backend now detects Amazon blocking and includes amazonBlocked flag in response (lines 1413-1422), Frontend shows proper feedback with ⚠️ Amazon Blocked message (lines 868-879), Fixed double-response bug by moving clearTimeout() before responseSent check (line 1428)",
priority: "high",
tags: ["purchasing", "bug-fix", "ui-feedback", "amazon-scraping"]
},
{
title: "Added Better Error Handling for Purchasing Agent",
description: "Added 401 authentication detection in frontend with helpful message. Enhanced refresh button feedback for different scenarios: Amazon blocked → Shows warning, New deals found → Reloads page, No new deals → Shows 'Up to date', Error → Shows retry option",
priority: "medium",
tags: ["purchasing", "enhancement", "error-handling", "ux"]
},
{
title: "Added Purchasing Agent to Task Orchestrator",
description: "Updated agent capabilities in task orchestrator registry at /root/Projects/Designer-Wallcoverings/DW-Agents/task-orchestrator-agent.ts:81. Added comprehensive capabilities: office-supplies, amazon-personal, amazon-business, price-comparison, order-tracking, price-tracking, deals",
priority: "medium",
tags: ["task-orchestrator", "purchasing", "configuration", "agent-registry"]
}
];
const tasks = loadTasks();
const now = new Date().toISOString();
completedTasks.forEach((taskData) => {
const task: Task = {
id: generateTaskId(),
title: taskData.title,
description: taskData.description,
status: 'completed',
priority: taskData.priority as 'low' | 'medium' | 'high' | 'critical',
assignedAgent: 'purchasing',
createdAt: now,
startedAt: now,
completedAt: now,
autoGenerated: false,
subtasks: [],
tags: taskData.tags,
metadata: {
completedBy: 'claude-code',
source: 'manual-entry'
},
actionLog: [
{
timestamp: now,
action: 'created',
details: `Task created: ${taskData.title}`,
success: true
},
{
timestamp: now,
action: 'status_change',
agent: 'purchasing',
details: 'Task completed successfully',
success: true
}
]
};
tasks.push(task);
console.log(`✅ Added: ${task.title}`);
});
saveTasks(tasks);
console.log(`\n🎯 Successfully added ${completedTasks.length} completed tasks to Task Orchestrator`);