@hasna/todos 0.9.19 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -836,6 +836,24 @@ function checkCompletionGuard(task, agentId, db, configOverride) {
836
836
  }
837
837
  }
838
838
 
839
+ // src/db/audit.ts
840
+ function logTaskChange(taskId, action, field, oldValue, newValue, agentId, db) {
841
+ const d = db || getDatabase();
842
+ const id = uuid();
843
+ const timestamp = now();
844
+ d.run(`INSERT INTO task_history (id, task_id, action, field, old_value, new_value, agent_id, created_at)
845
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [id, taskId, action, field || null, oldValue ?? null, newValue ?? null, agentId || null, timestamp]);
846
+ return { id, task_id: taskId, action, field: field || null, old_value: oldValue ?? null, new_value: newValue ?? null, agent_id: agentId || null, created_at: timestamp };
847
+ }
848
+ function getTaskHistory(taskId, db) {
849
+ const d = db || getDatabase();
850
+ return d.query("SELECT * FROM task_history WHERE task_id = ? ORDER BY created_at DESC").all(taskId);
851
+ }
852
+ function getRecentActivity(limit = 50, db) {
853
+ const d = db || getDatabase();
854
+ return d.query("SELECT * FROM task_history ORDER BY created_at DESC LIMIT ?").all(limit);
855
+ }
856
+
839
857
  // src/db/tasks.ts
840
858
  function rowToTask(row) {
841
859
  return {
@@ -1086,6 +1104,17 @@ function updateTask(id, input, db) {
1086
1104
  if (input.tags !== undefined) {
1087
1105
  replaceTaskTags(id, input.tags, d);
1088
1106
  }
1107
+ const agentId = task.assigned_to || task.agent_id || null;
1108
+ if (input.status !== undefined && input.status !== task.status)
1109
+ logTaskChange(id, "update", "status", task.status, input.status, agentId, d);
1110
+ if (input.priority !== undefined && input.priority !== task.priority)
1111
+ logTaskChange(id, "update", "priority", task.priority, input.priority, agentId, d);
1112
+ if (input.title !== undefined && input.title !== task.title)
1113
+ logTaskChange(id, "update", "title", task.title, input.title, agentId, d);
1114
+ if (input.assigned_to !== undefined && input.assigned_to !== task.assigned_to)
1115
+ logTaskChange(id, "update", "assigned_to", task.assigned_to, input.assigned_to, agentId, d);
1116
+ if (input.approved_by !== undefined)
1117
+ logTaskChange(id, "approve", "approved_by", null, input.approved_by, agentId, d);
1089
1118
  return getTask(id, d);
1090
1119
  }
1091
1120
  function deleteTask(id, db) {
@@ -1107,6 +1136,7 @@ function startTask(id, agentId, db) {
1107
1136
  throw new LockError(id, current.locked_by);
1108
1137
  }
1109
1138
  }
1139
+ logTaskChange(id, "start", "status", "pending", "in_progress", agentId, d);
1110
1140
  return getTask(id, d);
1111
1141
  }
1112
1142
  function completeTask(id, agentId, db) {
@@ -1121,6 +1151,7 @@ function completeTask(id, agentId, db) {
1121
1151
  const timestamp = now();
1122
1152
  d.run(`UPDATE tasks SET status = 'completed', locked_by = NULL, locked_at = NULL, completed_at = ?, version = version + 1, updated_at = ?
1123
1153
  WHERE id = ?`, [timestamp, timestamp, id]);
1154
+ logTaskChange(id, "complete", "status", task.status, "completed", agentId || null, d);
1124
1155
  return getTask(id, d);
1125
1156
  }
1126
1157
  function lockTask(id, agentId, db) {
@@ -1511,23 +1542,6 @@ function deleteSession(id, db) {
1511
1542
  const result = d.run("DELETE FROM sessions WHERE id = ?", [id]);
1512
1543
  return result.changes > 0;
1513
1544
  }
1514
- // src/db/audit.ts
1515
- function logTaskChange(taskId, action, field, oldValue, newValue, agentId, db) {
1516
- const d = db || getDatabase();
1517
- const id = uuid();
1518
- const timestamp = now();
1519
- d.run(`INSERT INTO task_history (id, task_id, action, field, old_value, new_value, agent_id, created_at)
1520
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [id, taskId, action, field || null, oldValue ?? null, newValue ?? null, agentId || null, timestamp]);
1521
- return { id, task_id: taskId, action, field: field || null, old_value: oldValue ?? null, new_value: newValue ?? null, agent_id: agentId || null, created_at: timestamp };
1522
- }
1523
- function getTaskHistory(taskId, db) {
1524
- const d = db || getDatabase();
1525
- return d.query("SELECT * FROM task_history WHERE task_id = ? ORDER BY created_at DESC").all(taskId);
1526
- }
1527
- function getRecentActivity(limit = 50, db) {
1528
- const d = db || getDatabase();
1529
- return d.query("SELECT * FROM task_history ORDER BY created_at DESC LIMIT ?").all(limit);
1530
- }
1531
1545
  // src/db/webhooks.ts
1532
1546
  function rowToWebhook(row) {
1533
1547
  return { ...row, events: JSON.parse(row.events || "[]"), active: !!row.active };