@hasna/todos 0.11.81 → 0.11.83

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
@@ -23220,6 +23220,7 @@ function createLocalSqliteTodosStorageAdapter(options = {}) {
23220
23220
  audit: {
23221
23221
  logTaskChange: (taskId, action, field2, oldValue, newValue, agentId) => logTaskChange(taskId, action, field2, oldValue, newValue, agentId, database()),
23222
23222
  addComment: (input) => addComment(input, database()),
23223
+ getComments: (taskId) => listComments(taskId, database()),
23223
23224
  getTaskHistory: (taskId) => getTaskHistory(taskId, database()),
23224
23225
  getRecentActivity: (limit) => getRecentActivity(limit, database())
23225
23226
  },
@@ -23524,7 +23525,18 @@ function createPostgresTodosStorageAdapter(options) {
23524
23525
  claimNext: (agentId, filters) => claimNextTask2(agentId, filters, store),
23525
23526
  getNext: (_agentId, filters) => getNextTask2(filters, store),
23526
23527
  getActiveWork: (filters) => getActiveWork2(filters, store),
23527
- getChangedSince: (since, filters) => getChangedSince(since, filters, store)
23528
+ getChangedSince: (since, filters) => getChangedSince(since, filters, store),
23529
+ lock: (id, agentId) => lockTask2(id, agentId, store),
23530
+ unlock: (id, agentId) => unlockTask2(id, agentId, store)
23531
+ },
23532
+ dependencies: {
23533
+ add: (taskId, dependsOn, context) => addDependency2(taskId, dependsOn, store, context),
23534
+ remove: (taskId, dependsOn) => removeDependency2(taskId, dependsOn, store),
23535
+ list: (taskId) => listDependencies(taskId, store)
23536
+ },
23537
+ verifications: {
23538
+ add: (input, context) => addVerification(input, store, context),
23539
+ list: (taskId) => listVerifications(taskId, store)
23528
23540
  },
23529
23541
  projects: {
23530
23542
  create: (input, context) => createProject2(input, store, context),
@@ -23570,6 +23582,7 @@ function createPostgresTodosStorageAdapter(options) {
23570
23582
  audit: {
23571
23583
  logTaskChange: (taskId, action, field2, oldValue, newValue, agentId, context) => logTaskChange2(taskId, action, field2, oldValue, newValue, agentId, store, context),
23572
23584
  addComment: (input, context) => addComment2(input, store, context),
23585
+ getComments: async (taskId) => (await store.list("comments")).filter((comment) => comment.task_id === taskId).sort((a, b) => a.created_at.localeCompare(b.created_at)),
23573
23586
  getTaskHistory: async (taskId) => (await store.list("audit_history")).filter((entry2) => entry2.task_id === taskId).sort((a, b) => a.created_at.localeCompare(b.created_at)),
23574
23587
  getRecentActivity: async (limit = 20) => (await store.list("audit_history")).sort((a, b) => b.created_at.localeCompare(a.created_at)).slice(0, limit)
23575
23588
  },
@@ -23978,6 +23991,104 @@ async function patchTask(task2, patch, store) {
23978
23991
  await store.upsert("tasks", updated);
23979
23992
  return updated;
23980
23993
  }
23994
+ var CLOUD_LOCK_EXPIRY_MINUTES = 30;
23995
+ function cloudLockExpired(lockedAt) {
23996
+ if (!lockedAt)
23997
+ return true;
23998
+ return new Date(lockedAt).getTime() + CLOUD_LOCK_EXPIRY_MINUTES * 60 * 1000 < Date.now();
23999
+ }
24000
+ function cloudLockExpiresAt(lockedAt) {
24001
+ return new Date(new Date(lockedAt).getTime() + CLOUD_LOCK_EXPIRY_MINUTES * 60 * 1000).toISOString();
24002
+ }
24003
+ async function lockTask2(id, agentId, store) {
24004
+ const task2 = await requireRecord("tasks", id, store);
24005
+ if (task2.status === "completed" || task2.status === "cancelled") {
24006
+ return { success: false, error: `Task is ${task2.status} and cannot be locked` };
24007
+ }
24008
+ if (task2.locked_by && task2.locked_by !== agentId && !cloudLockExpired(task2.locked_at)) {
24009
+ return { success: false, locked_by: task2.locked_by, locked_at: task2.locked_at ?? undefined, error: `Task is locked by ${task2.locked_by}` };
24010
+ }
24011
+ const timestamp2 = new Date().toISOString();
24012
+ await patchTask(task2, { locked_by: agentId, locked_at: timestamp2 }, store);
24013
+ return { success: true, locked_by: agentId, locked_at: timestamp2, expires_at: cloudLockExpiresAt(timestamp2) };
24014
+ }
24015
+ async function unlockTask2(id, agentId, store) {
24016
+ const task2 = await requireRecord("tasks", id, store);
24017
+ if (agentId && task2.locked_by && task2.locked_by !== agentId) {
24018
+ throw new Error(`Task ${id} is locked by ${task2.locked_by}, not ${agentId}`);
24019
+ }
24020
+ await patchTask(task2, { locked_by: null, locked_at: null }, store);
24021
+ return true;
24022
+ }
24023
+ function dependencyId(taskId, dependsOn) {
24024
+ return `${taskId}::${dependsOn}`;
24025
+ }
24026
+ async function addDependency2(taskId, dependsOn, store, context) {
24027
+ if (taskId === dependsOn)
24028
+ throw new Error("A task cannot depend on itself");
24029
+ if (!await store.get("tasks", taskId))
24030
+ throw new Error(`Task not found: ${taskId}`);
24031
+ if (!await store.get("tasks", dependsOn))
24032
+ throw new Error(`Task not found: ${dependsOn}`);
24033
+ const edges = await store.list("dependencies");
24034
+ const adjacency = new Map;
24035
+ for (const edge of edges) {
24036
+ if (!adjacency.has(edge.task_id))
24037
+ adjacency.set(edge.task_id, []);
24038
+ adjacency.get(edge.task_id).push(edge.depends_on);
24039
+ }
24040
+ const queue = [dependsOn];
24041
+ const seen = new Set;
24042
+ while (queue.length) {
24043
+ const node = queue.shift();
24044
+ if (node === taskId)
24045
+ throw new Error(`Adding dependency ${taskId} -> ${dependsOn} would create a cycle`);
24046
+ if (seen.has(node))
24047
+ continue;
24048
+ seen.add(node);
24049
+ for (const next of adjacency.get(node) ?? [])
24050
+ queue.push(next);
24051
+ }
24052
+ const timestamp2 = new Date().toISOString();
24053
+ const record = { id: dependencyId(taskId, dependsOn), task_id: taskId, depends_on: dependsOn, created_at: timestamp2, updated_at: timestamp2 };
24054
+ await store.upsert("dependencies", record, context);
24055
+ return { task_id: taskId, depends_on: dependsOn };
24056
+ }
24057
+ async function removeDependency2(taskId, dependsOn, store) {
24058
+ const existing = await store.get("dependencies", dependencyId(taskId, dependsOn));
24059
+ if (!existing)
24060
+ return false;
24061
+ await store.delete("dependencies", dependencyId(taskId, dependsOn));
24062
+ return true;
24063
+ }
24064
+ async function listDependencies(taskId, store) {
24065
+ const edges = await store.list("dependencies");
24066
+ return {
24067
+ dependencies: edges.filter((edge) => edge.task_id === taskId).map((edge) => ({ task_id: edge.task_id, depends_on: edge.depends_on })),
24068
+ blocked_by: edges.filter((edge) => edge.depends_on === taskId).map((edge) => ({ task_id: edge.task_id, depends_on: edge.depends_on }))
24069
+ };
24070
+ }
24071
+ async function addVerification(input, store, context) {
24072
+ if (!await store.get("tasks", input.task_id))
24073
+ throw new Error(`Task not found: ${input.task_id}`);
24074
+ const timestamp2 = new Date().toISOString();
24075
+ const verification = {
24076
+ id: randomUUID3(),
24077
+ task_id: input.task_id,
24078
+ command: input.command,
24079
+ status: input.status ?? "unknown",
24080
+ output_summary: input.output_summary ?? null,
24081
+ artifact_path: input.artifact_path ?? null,
24082
+ agent_id: input.agent_id ?? context?.agentId ?? null,
24083
+ run_at: timestamp2,
24084
+ created_at: timestamp2
24085
+ };
24086
+ await store.upsert("verifications", { ...verification, updated_at: timestamp2 }, context);
24087
+ return verification;
24088
+ }
24089
+ async function listVerifications(taskId, store) {
24090
+ return (await store.list("verifications")).filter((verification) => verification.task_id === taskId).sort((a, b) => b.run_at.localeCompare(a.run_at));
24091
+ }
23981
24092
  var TASK_ORDER_BY = "ORDER BY CASE payload->>'priority' WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 ELSE 4 END ASC, payload->>'created_at' ASC, payload->>'id' ASC";
23982
24093
  function toFilterArray(value) {
23983
24094
  return Array.isArray(value) ? value : [value];
@@ -31781,13 +31892,13 @@ function importTodosMarkdown(markdown, options = {}, db) {
31781
31892
  if (!taskId)
31782
31893
  continue;
31783
31894
  for (const dependencyTitle of item.depends_on_titles) {
31784
- const dependencyId = taskByTitle.get(dependencyTitle);
31785
- if (!dependencyId) {
31895
+ const dependencyId2 = taskByTitle.get(dependencyTitle);
31896
+ if (!dependencyId2) {
31786
31897
  skipped.task_dependencies++;
31787
31898
  issues.push(`missing dependency task: ${dependencyTitle}`);
31788
31899
  continue;
31789
31900
  }
31790
- addDependency(taskId, dependencyId, d);
31901
+ addDependency(taskId, dependencyId2, d);
31791
31902
  inserted.task_dependencies++;
31792
31903
  }
31793
31904
  }
package/dist/mcp/index.js CHANGED
@@ -22837,6 +22837,23 @@ async function cloudGetStats(client) {
22837
22837
  const raw = await client.transport.get("/stats");
22838
22838
  return raw ?? {};
22839
22839
  }
22840
+ async function cloudListAgents(client) {
22841
+ const res = await client.list("agents");
22842
+ const envelope = res.raw;
22843
+ return Array.isArray(envelope?.agents) ? envelope.agents : res.items;
22844
+ }
22845
+ async function cloudListProjects(client) {
22846
+ const res = await client.list("projects");
22847
+ const envelope = res.raw;
22848
+ return Array.isArray(envelope?.projects) ? envelope.projects : res.items;
22849
+ }
22850
+ async function cloudAddComment(client, taskId, input) {
22851
+ const raw = await client.transport.post(`/tasks/${encodeURIComponent(taskId)}/comments`, input);
22852
+ if (raw && typeof raw === "object" && "comment" in raw) {
22853
+ return raw.comment;
22854
+ }
22855
+ return raw;
22856
+ }
22840
22857
  async function cloudCountTasks(client, filter = {}) {
22841
22858
  const { limit: _drop, offset: _o, ...rest } = filter;
22842
22859
  const res = await client.list("tasks", { query: { ...toListQuery(rest), limit: 1 } });
@@ -22846,6 +22863,13 @@ async function cloudCountTasks(client, filter = {}) {
22846
22863
  const tasks = await cloudListTasks(client, rest);
22847
22864
  return tasks.length;
22848
22865
  }
22866
+ async function cloudRegisterAgent(client, input) {
22867
+ const raw = await client.transport.post("/agents", input);
22868
+ if (raw && typeof raw === "object" && "agent" in raw) {
22869
+ return raw.agent;
22870
+ }
22871
+ return raw;
22872
+ }
22849
22873
  var _cache;
22850
22874
  var init_cloud_router = __esm(() => {
22851
22875
  init_storage();
@@ -30183,6 +30207,11 @@ Tasks:` : null,
30183
30207
  author: exports_external.string().optional().describe("Author agent ID or name")
30184
30208
  }, async ({ task_id, body, author }) => {
30185
30209
  try {
30210
+ const cloud = getTodosCloudClient();
30211
+ if (cloud) {
30212
+ await cloudAddComment(cloud, task_id, { content: body, agent_id: author });
30213
+ return { content: [{ type: "text", text: `Comment added to ${task_id.slice(0, 8)}: ${body.slice(0, 50)}${body.length > 50 ? "..." : ""}` }] };
30214
+ }
30186
30215
  const resolvedId = resolveId(task_id);
30187
30216
  const resolvedAuthor = author ? resolveId(author, "agents") : undefined;
30188
30217
  const comment = addComment({ task_id: resolvedId, content: body, agent_id: resolvedAuthor });
@@ -31093,6 +31122,56 @@ function registerTaskWorkflowTools(server, ctx) {
31093
31122
  max_description_chars: exports_external.number().optional().describe("Max task description chars in compact mode (default: 180)")
31094
31123
  }, async ({ agent_id, project_id, task_list_id, explain_blocked, detail, max_description_chars }) => {
31095
31124
  try {
31125
+ const cloud = getTodosCloudClient();
31126
+ if (cloud) {
31127
+ const baseFilter = {};
31128
+ if (project_id)
31129
+ baseFilter.project_id = project_id;
31130
+ if (task_list_id)
31131
+ baseFilter.task_list_id = task_list_id;
31132
+ const [stats, pending, in_progress, completed, activeTasks, nextTasks] = await Promise.all([
31133
+ cloudGetStats(cloud),
31134
+ cloudCountTasks(cloud, { ...baseFilter, status: "pending" }),
31135
+ cloudCountTasks(cloud, { ...baseFilter, status: "in_progress" }),
31136
+ cloudCountTasks(cloud, { ...baseFilter, status: "completed" }),
31137
+ cloudListTasks(cloud, { ...baseFilter, status: "in_progress", limit: 5 }),
31138
+ cloudListTasks(cloud, { ...baseFilter, status: "pending", limit: 1 })
31139
+ ]);
31140
+ const cloudStatus = {
31141
+ source: "cloud",
31142
+ total: stats.tasks ?? pending + in_progress + completed,
31143
+ pending,
31144
+ in_progress,
31145
+ completed,
31146
+ active_work: activeTasks,
31147
+ next_task: nextTasks[0] ?? null,
31148
+ stale_count: 0,
31149
+ overdue_recurring: 0
31150
+ };
31151
+ const next_task2 = nextTasks[0] ?? null;
31152
+ const payload2 = {
31153
+ status: cloudStatus,
31154
+ next_task: next_task2,
31155
+ overdue_count: 0,
31156
+ latest_handoff: null,
31157
+ as_of: new Date().toISOString()
31158
+ };
31159
+ if (detail === "full") {
31160
+ return { content: [{ type: "text", text: JSON.stringify(payload2, null, 2) }] };
31161
+ }
31162
+ return {
31163
+ content: [{
31164
+ type: "text",
31165
+ text: compactJson({
31166
+ status: compactStatus(cloudStatus),
31167
+ next_task: next_task2 ? compactTask(next_task2, max_description_chars || 180) : null,
31168
+ overdue_count: 0,
31169
+ latest_handoff: null,
31170
+ as_of: payload2.as_of
31171
+ })
31172
+ }]
31173
+ };
31174
+ }
31096
31175
  const { getStatus: getStatus2, getNextTask: getNextTask2, getOverdueTasks: getOverdueTasks2 } = (init_tasks(), __toCommonJS(exports_tasks));
31097
31176
  const { getLatestHandoff: getLatestHandoff2 } = (init_handoffs(), __toCommonJS(exports_handoffs));
31098
31177
  const filters = {};
@@ -31922,6 +32001,27 @@ ${lines.join(`
31922
32001
  if (shouldRegisterTool("get_health")) {
31923
32002
  server.tool("get_health", "Get system health: task counts by status, active agents, project summary.", async () => {
31924
32003
  try {
32004
+ const cloud = getTodosCloudClient();
32005
+ if (cloud) {
32006
+ const [stats, pending2, inProgress2, completed2, cancelled2, projects2, agents2] = await Promise.all([
32007
+ cloudGetStats(cloud),
32008
+ cloudCountTasks(cloud, { status: "pending" }),
32009
+ cloudCountTasks(cloud, { status: "in_progress" }),
32010
+ cloudCountTasks(cloud, { status: "completed" }),
32011
+ cloudCountTasks(cloud, { status: "cancelled" }),
32012
+ cloudListProjects(cloud),
32013
+ cloudListAgents(cloud)
32014
+ ]);
32015
+ const projectCount = stats.projects ?? projects2.length;
32016
+ const lines2 = [
32017
+ `=== System Health (cloud) ===`,
32018
+ `Tasks: ${pending2} pending | ${inProgress2} in progress | ${completed2} completed | ${cancelled2} cancelled`,
32019
+ `Projects: ${projectCount} total`,
32020
+ `Agents: ${agents2.length} registered`
32021
+ ];
32022
+ return { content: [{ type: "text", text: lines2.join(`
32023
+ `) }] };
32024
+ }
31925
32025
  const { countTasks: countTasks2 } = (init_tasks(), __toCommonJS(exports_tasks));
31926
32026
  const { listProjects: listProjects2 } = (init_projects(), __toCommonJS(exports_projects));
31927
32027
  const { listAgents: listAgents2 } = (init_agents(), __toCommonJS(exports_agents));
@@ -31960,6 +32060,7 @@ ${lines.join(`
31960
32060
  }
31961
32061
  var init_task_auto_tools = __esm(() => {
31962
32062
  init_zod();
32063
+ init_cloud_router();
31963
32064
  });
31964
32065
 
31965
32066
  // src/lib/context-packs.ts
@@ -33282,6 +33383,11 @@ No blocked tasks.`,
33282
33383
  author: exports_external.string().optional().describe("Author agent ID or name")
33283
33384
  }, async ({ task_id, body, author }) => {
33284
33385
  try {
33386
+ const cloud = getTodosCloudClient();
33387
+ if (cloud) {
33388
+ await cloudAddComment(cloud, task_id, { content: body, agent_id: author });
33389
+ return { content: [{ type: "text", text: `Comment added to ${task_id.slice(0, 8)}` }] };
33390
+ }
33285
33391
  const { addComment: addComment2 } = (init_comments(), __toCommonJS(exports_comments));
33286
33392
  const resolvedId = resolveId(task_id);
33287
33393
  const resolvedAuthor = author ? resolveId(author, "agents") : undefined;
@@ -44096,6 +44202,33 @@ function registerAgentTools(server, { shouldRegisterTool, resolveId, formatError
44096
44202
  force: exports_external.boolean().optional().describe("Force takeover of an active agent's name. Use with caution \u2014 only when you know the previous session is dead.")
44097
44203
  }, async ({ name, description, role, title, level, permissions, capabilities, session_id, working_dir, force }) => {
44098
44204
  try {
44205
+ const cloud = getTodosCloudClient();
44206
+ if (cloud) {
44207
+ const agent2 = await cloudRegisterAgent(cloud, {
44208
+ name,
44209
+ description,
44210
+ role,
44211
+ title,
44212
+ level,
44213
+ permissions,
44214
+ capabilities,
44215
+ session_id,
44216
+ working_dir,
44217
+ force
44218
+ });
44219
+ return {
44220
+ content: [{
44221
+ type: "text",
44222
+ text: `Agent registered:
44223
+ ID: ${agent2.id}
44224
+ Name: ${agent2.name}${agent2.description ? `
44225
+ Description: ${agent2.description}` : ""}
44226
+ Session: ${agent2.session_id ?? "unbound"}
44227
+ Created: ${agent2.created_at}
44228
+ Last seen: ${agent2.last_seen_at}`
44229
+ }]
44230
+ };
44231
+ }
44099
44232
  const pool = getAgentPoolForProject(working_dir);
44100
44233
  const result = registerAgent({ name, description, role, title, level, permissions, capabilities, session_id, working_dir, force, pool: pool || undefined });
44101
44234
  if (isAgentConflict(result)) {
@@ -44189,7 +44322,8 @@ No names available. Wait for an active agent to go stale (30min timeout).`
44189
44322
  include_archived: exports_external.boolean().optional().describe("Include archived agents in the list (default: false)")
44190
44323
  }, async ({ include_archived }) => {
44191
44324
  try {
44192
- const agents = listAgents({ include_archived: include_archived ?? false });
44325
+ const cloud = getTodosCloudClient();
44326
+ const agents = cloud ? await cloudListAgents(cloud) : listAgents({ include_archived: include_archived ?? false });
44193
44327
  if (agents.length === 0) {
44194
44328
  return { content: [{ type: "text", text: "No agents registered." }] };
44195
44329
  }
@@ -44409,6 +44543,7 @@ var init_agents2 = __esm(() => {
44409
44543
  init_agents();
44410
44544
  init_config2();
44411
44545
  init_database();
44546
+ init_cloud_router();
44412
44547
  });
44413
44548
 
44414
44549
  // src/db/builtin-templates.ts
@@ -46022,6 +46157,7 @@ function createLocalSqliteTodosStorageAdapter(options = {}) {
46022
46157
  audit: {
46023
46158
  logTaskChange: (taskId, action, field, oldValue, newValue, agentId) => logTaskChange(taskId, action, field, oldValue, newValue, agentId, database()),
46024
46159
  addComment: (input) => addComment(input, database()),
46160
+ getComments: (taskId) => listComments(taskId, database()),
46025
46161
  getTaskHistory: (taskId) => getTaskHistory(taskId, database()),
46026
46162
  getRecentActivity: (limit) => getRecentActivity(limit, database())
46027
46163
  },
@@ -47992,7 +48128,18 @@ function createPostgresTodosStorageAdapter(options) {
47992
48128
  claimNext: (agentId, filters) => claimNextTask2(agentId, filters, store),
47993
48129
  getNext: (_agentId, filters) => getNextTask2(filters, store),
47994
48130
  getActiveWork: (filters) => getActiveWork2(filters, store),
47995
- getChangedSince: (since, filters) => getChangedSince(since, filters, store)
48131
+ getChangedSince: (since, filters) => getChangedSince(since, filters, store),
48132
+ lock: (id, agentId) => lockTask2(id, agentId, store),
48133
+ unlock: (id, agentId) => unlockTask2(id, agentId, store)
48134
+ },
48135
+ dependencies: {
48136
+ add: (taskId, dependsOn, context) => addDependency2(taskId, dependsOn, store, context),
48137
+ remove: (taskId, dependsOn) => removeDependency2(taskId, dependsOn, store),
48138
+ list: (taskId) => listDependencies(taskId, store)
48139
+ },
48140
+ verifications: {
48141
+ add: (input, context) => addVerification(input, store, context),
48142
+ list: (taskId) => listVerifications(taskId, store)
47996
48143
  },
47997
48144
  projects: {
47998
48145
  create: (input, context) => createProject2(input, store, context),
@@ -48038,6 +48185,7 @@ function createPostgresTodosStorageAdapter(options) {
48038
48185
  audit: {
48039
48186
  logTaskChange: (taskId, action, field, oldValue, newValue, agentId, context) => logTaskChange2(taskId, action, field, oldValue, newValue, agentId, store, context),
48040
48187
  addComment: (input, context) => addComment2(input, store, context),
48188
+ getComments: async (taskId) => (await store.list("comments")).filter((comment) => comment.task_id === taskId).sort((a, b) => a.created_at.localeCompare(b.created_at)),
48041
48189
  getTaskHistory: async (taskId) => (await store.list("audit_history")).filter((entry2) => entry2.task_id === taskId).sort((a, b) => a.created_at.localeCompare(b.created_at)),
48042
48190
  getRecentActivity: async (limit = 20) => (await store.list("audit_history")).sort((a, b) => b.created_at.localeCompare(a.created_at)).slice(0, limit)
48043
48191
  },
@@ -48446,6 +48594,103 @@ async function patchTask(task2, patch, store) {
48446
48594
  await store.upsert("tasks", updated);
48447
48595
  return updated;
48448
48596
  }
48597
+ function cloudLockExpired(lockedAt) {
48598
+ if (!lockedAt)
48599
+ return true;
48600
+ return new Date(lockedAt).getTime() + CLOUD_LOCK_EXPIRY_MINUTES * 60 * 1000 < Date.now();
48601
+ }
48602
+ function cloudLockExpiresAt(lockedAt) {
48603
+ return new Date(new Date(lockedAt).getTime() + CLOUD_LOCK_EXPIRY_MINUTES * 60 * 1000).toISOString();
48604
+ }
48605
+ async function lockTask2(id, agentId, store) {
48606
+ const task2 = await requireRecord("tasks", id, store);
48607
+ if (task2.status === "completed" || task2.status === "cancelled") {
48608
+ return { success: false, error: `Task is ${task2.status} and cannot be locked` };
48609
+ }
48610
+ if (task2.locked_by && task2.locked_by !== agentId && !cloudLockExpired(task2.locked_at)) {
48611
+ return { success: false, locked_by: task2.locked_by, locked_at: task2.locked_at ?? undefined, error: `Task is locked by ${task2.locked_by}` };
48612
+ }
48613
+ const timestamp3 = new Date().toISOString();
48614
+ await patchTask(task2, { locked_by: agentId, locked_at: timestamp3 }, store);
48615
+ return { success: true, locked_by: agentId, locked_at: timestamp3, expires_at: cloudLockExpiresAt(timestamp3) };
48616
+ }
48617
+ async function unlockTask2(id, agentId, store) {
48618
+ const task2 = await requireRecord("tasks", id, store);
48619
+ if (agentId && task2.locked_by && task2.locked_by !== agentId) {
48620
+ throw new Error(`Task ${id} is locked by ${task2.locked_by}, not ${agentId}`);
48621
+ }
48622
+ await patchTask(task2, { locked_by: null, locked_at: null }, store);
48623
+ return true;
48624
+ }
48625
+ function dependencyId(taskId, dependsOn) {
48626
+ return `${taskId}::${dependsOn}`;
48627
+ }
48628
+ async function addDependency2(taskId, dependsOn, store, context) {
48629
+ if (taskId === dependsOn)
48630
+ throw new Error("A task cannot depend on itself");
48631
+ if (!await store.get("tasks", taskId))
48632
+ throw new Error(`Task not found: ${taskId}`);
48633
+ if (!await store.get("tasks", dependsOn))
48634
+ throw new Error(`Task not found: ${dependsOn}`);
48635
+ const edges = await store.list("dependencies");
48636
+ const adjacency = new Map;
48637
+ for (const edge of edges) {
48638
+ if (!adjacency.has(edge.task_id))
48639
+ adjacency.set(edge.task_id, []);
48640
+ adjacency.get(edge.task_id).push(edge.depends_on);
48641
+ }
48642
+ const queue = [dependsOn];
48643
+ const seen = new Set;
48644
+ while (queue.length) {
48645
+ const node = queue.shift();
48646
+ if (node === taskId)
48647
+ throw new Error(`Adding dependency ${taskId} -> ${dependsOn} would create a cycle`);
48648
+ if (seen.has(node))
48649
+ continue;
48650
+ seen.add(node);
48651
+ for (const next of adjacency.get(node) ?? [])
48652
+ queue.push(next);
48653
+ }
48654
+ const timestamp3 = new Date().toISOString();
48655
+ const record = { id: dependencyId(taskId, dependsOn), task_id: taskId, depends_on: dependsOn, created_at: timestamp3, updated_at: timestamp3 };
48656
+ await store.upsert("dependencies", record, context);
48657
+ return { task_id: taskId, depends_on: dependsOn };
48658
+ }
48659
+ async function removeDependency2(taskId, dependsOn, store) {
48660
+ const existing = await store.get("dependencies", dependencyId(taskId, dependsOn));
48661
+ if (!existing)
48662
+ return false;
48663
+ await store.delete("dependencies", dependencyId(taskId, dependsOn));
48664
+ return true;
48665
+ }
48666
+ async function listDependencies(taskId, store) {
48667
+ const edges = await store.list("dependencies");
48668
+ return {
48669
+ dependencies: edges.filter((edge) => edge.task_id === taskId).map((edge) => ({ task_id: edge.task_id, depends_on: edge.depends_on })),
48670
+ blocked_by: edges.filter((edge) => edge.depends_on === taskId).map((edge) => ({ task_id: edge.task_id, depends_on: edge.depends_on }))
48671
+ };
48672
+ }
48673
+ async function addVerification(input, store, context) {
48674
+ if (!await store.get("tasks", input.task_id))
48675
+ throw new Error(`Task not found: ${input.task_id}`);
48676
+ const timestamp3 = new Date().toISOString();
48677
+ const verification = {
48678
+ id: randomUUID3(),
48679
+ task_id: input.task_id,
48680
+ command: input.command,
48681
+ status: input.status ?? "unknown",
48682
+ output_summary: input.output_summary ?? null,
48683
+ artifact_path: input.artifact_path ?? null,
48684
+ agent_id: input.agent_id ?? context?.agentId ?? null,
48685
+ run_at: timestamp3,
48686
+ created_at: timestamp3
48687
+ };
48688
+ await store.upsert("verifications", { ...verification, updated_at: timestamp3 }, context);
48689
+ return verification;
48690
+ }
48691
+ async function listVerifications(taskId, store) {
48692
+ return (await store.list("verifications")).filter((verification) => verification.task_id === taskId).sort((a, b) => b.run_at.localeCompare(a.run_at));
48693
+ }
48449
48694
  function toFilterArray(value) {
48450
48695
  return Array.isArray(value) ? value : [value];
48451
48696
  }
@@ -48819,7 +49064,7 @@ function compareClock(left, right) {
48819
49064
  function numberValue3(value) {
48820
49065
  return typeof value === "number" && Number.isSafeInteger(value) ? value : null;
48821
49066
  }
48822
- var TASK_ORDER_BY = "ORDER BY CASE payload->>'priority' WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 ELSE 4 END ASC, payload->>'created_at' ASC, payload->>'id' ASC";
49067
+ var CLOUD_LOCK_EXPIRY_MINUTES = 30, TASK_ORDER_BY = "ORDER BY CASE payload->>'priority' WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 ELSE 4 END ASC, payload->>'created_at' ASC, payload->>'id' ASC";
48823
49068
  var init_postgres_adapter = () => {};
48824
49069
 
48825
49070
  // src/server/cloud.ts
@@ -49317,6 +49562,7 @@ async function handleV1Request(req, url) {
49317
49562
  const resource = segments[1];
49318
49563
  const id = segments[2];
49319
49564
  const action = segments[3];
49565
+ const subId = segments[4];
49320
49566
  try {
49321
49567
  if (resource === "tasks") {
49322
49568
  if (id === "exists" && !action) {
@@ -49367,6 +49613,114 @@ async function handleV1Request(req, url) {
49367
49613
  return error(405, `method ${method} not allowed on /v1/tasks`);
49368
49614
  }
49369
49615
  if (action) {
49616
+ if (action === "comments") {
49617
+ if (method === "GET") {
49618
+ const comments = await store.audit.getComments(id);
49619
+ return json2({ comments, count: comments.length });
49620
+ }
49621
+ if (method === "POST") {
49622
+ const body2 = await readJson(req) ?? {};
49623
+ if (typeof body2.content !== "string" || !body2.content.trim()) {
49624
+ return error(400, "content is required");
49625
+ }
49626
+ const target = await store.tasks.get(id);
49627
+ if (!target)
49628
+ return error(404, "task not found");
49629
+ const comment = await store.audit.addComment({
49630
+ task_id: id,
49631
+ content: body2.content,
49632
+ agent_id: body2.agent_id ?? principal.agent ?? undefined,
49633
+ session_id: body2.session_id,
49634
+ type: body2.type,
49635
+ progress_pct: body2.progress_pct
49636
+ }, contextFromPrincipal(principal, body2));
49637
+ return json2({ comment }, 201);
49638
+ }
49639
+ return error(405, `method ${method} not allowed on /v1/tasks/:id/comments`);
49640
+ }
49641
+ if (action === "lock" || action === "unlock") {
49642
+ if (method !== "POST")
49643
+ return error(405, `method ${method} not allowed on /v1/tasks/:id/${action}`);
49644
+ if (typeof store.tasks.lock !== "function" || typeof store.tasks.unlock !== "function") {
49645
+ return error(501, "task locking is not supported by this storage backend");
49646
+ }
49647
+ const body2 = await readJson(req) ?? {};
49648
+ if (!await store.tasks.get(id))
49649
+ return error(404, "task not found");
49650
+ if (action === "lock") {
49651
+ const agentId2 = body2.agent_id || principal.agent || "todos-serve";
49652
+ return json2({ result: await store.tasks.lock(id, agentId2) });
49653
+ }
49654
+ const released = await store.tasks.unlock(id, body2.agent_id || principal.agent || undefined);
49655
+ return json2({ success: released });
49656
+ }
49657
+ if (action === "dependencies") {
49658
+ if (!store.dependencies)
49659
+ return error(501, "dependencies are not supported by this storage backend");
49660
+ if (method === "GET") {
49661
+ if (!await store.tasks.get(id))
49662
+ return error(404, "task not found");
49663
+ const edges = await store.dependencies.list(id);
49664
+ return json2(edges);
49665
+ }
49666
+ if (method === "POST") {
49667
+ const body2 = await readJson(req) ?? {};
49668
+ if (typeof body2.depends_on !== "string" || !body2.depends_on.trim()) {
49669
+ return error(400, "depends_on is required");
49670
+ }
49671
+ try {
49672
+ const dependency = await store.dependencies.add(id, body2.depends_on, contextFromPrincipal(principal));
49673
+ return json2({ dependency }, 201);
49674
+ } catch (e) {
49675
+ const msg = e.message || "";
49676
+ if (msg.includes("not found"))
49677
+ return error(404, msg);
49678
+ if (msg.includes("cycle") || msg.includes("itself"))
49679
+ return error(409, msg);
49680
+ throw e;
49681
+ }
49682
+ }
49683
+ if (method === "DELETE") {
49684
+ if (!subId)
49685
+ return error(400, "dependency target id is required (/v1/tasks/:id/dependencies/:dep)");
49686
+ const removed = await store.dependencies.remove(id, subId);
49687
+ return json2({ removed });
49688
+ }
49689
+ return error(405, `method ${method} not allowed on /v1/tasks/:id/dependencies`);
49690
+ }
49691
+ if (action === "verifications") {
49692
+ if (!store.verifications)
49693
+ return error(501, "verifications are not supported by this storage backend");
49694
+ if (method === "GET") {
49695
+ if (!await store.tasks.get(id))
49696
+ return error(404, "task not found");
49697
+ const verifications = await store.verifications.list(id);
49698
+ return json2({ verifications, count: verifications.length });
49699
+ }
49700
+ if (method === "POST") {
49701
+ const body2 = await readJson(req) ?? {};
49702
+ if (typeof body2.command !== "string" || !body2.command.trim()) {
49703
+ return error(400, "command is required");
49704
+ }
49705
+ try {
49706
+ const verification = await store.verifications.add({
49707
+ task_id: id,
49708
+ command: body2.command,
49709
+ status: body2.status,
49710
+ output_summary: body2.output_summary,
49711
+ artifact_path: body2.artifact_path,
49712
+ agent_id: body2.agent_id
49713
+ }, contextFromPrincipal(principal, body2));
49714
+ return json2({ verification }, 201);
49715
+ } catch (e) {
49716
+ const msg = e.message || "";
49717
+ if (msg.includes("not found"))
49718
+ return error(404, msg);
49719
+ throw e;
49720
+ }
49721
+ }
49722
+ return error(405, `method ${method} not allowed on /v1/tasks/:id/verifications`);
49723
+ }
49370
49724
  const body = await readJson(req) ?? {};
49371
49725
  const agentId = body.agent_id || principal.agent || "todos-serve";
49372
49726
  if (action === "start" && method === "POST") {
@@ -49471,10 +49825,13 @@ async function handleV1Request(req, url) {
49471
49825
  }
49472
49826
  if (!id && method === "POST") {
49473
49827
  const body = await readJson(req);
49474
- if (!body || typeof body.name !== "string")
49828
+ if (!body || typeof body.name !== "string" || !body.name.trim())
49475
49829
  return error(400, "name is required");
49476
- const agent = await store.agents.register(body, contextFromPrincipal(principal));
49477
- return json2({ agent }, 201);
49830
+ const result = await store.agents.register(body, contextFromPrincipal(principal));
49831
+ if (result && typeof result === "object" && "conflict" in result) {
49832
+ return error(409, result.message ?? "agent name conflict", { conflict: true });
49833
+ }
49834
+ return json2({ agent: result }, 201);
49478
49835
  }
49479
49836
  if (id && method === "GET") {
49480
49837
  const agent = await store.agents.get(id);
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KA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,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACvC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAC;CAC5D,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,EAAE,OAAO,GAAG,IAAI,CA6cjJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"task-adv-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/task-adv-tools.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAIjD,UAAU,cAAc;IACtB,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9C,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACzD,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACxC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;IACnC,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,mBAAmB,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACvE,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CAC3F;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,cAAc,QA8mB1E"}
1
+ {"version":3,"file":"task-adv-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/task-adv-tools.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,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