From d4fea6b29001df10444cae2ea95bc8259b22c763 Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Fri, 21 Aug 2026 22:25:55 +0300 Subject: [PATCH] feat(ops): expose read-only Tasker comment audit --- src/mcp/tool-runtime.comment-audit.test.ts | 105 +++++++++++++++++++++ src/mcp/tool-runtime.ts | 29 ++++++ src/routes/tools.ts | 23 +++++ src/tasker/client.ts | 31 ++++++ 4 files changed, 188 insertions(+) create mode 100644 src/mcp/tool-runtime.comment-audit.test.ts diff --git a/src/mcp/tool-runtime.comment-audit.test.ts b/src/mcp/tool-runtime.comment-audit.test.ts new file mode 100644 index 0000000..9cd0e26 --- /dev/null +++ b/src/mcp/tool-runtime.comment-audit.test.ts @@ -0,0 +1,105 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import type { AgentSessionRecord } from "../repositories/agents.js"; +import { TaskerClient } from "../tasker/client.js"; +import { executeMcpTool, getToolsForSession } from "./tool-runtime.js"; + +const session: AgentSessionRecord = { + agent: { + id: "agent-1", + ownerUserId: "owner-1", + ownerEmail: "owner@example.test", + displayName: "Codex Agent", + avatarUrl: null, + status: "active", + createdAt: "2026-08-21T00:00:00.000Z", + updatedAt: "2026-08-21T00:00:00.000Z", + }, + token: { + id: "token-1", + agentId: "agent-1", + name: "test", + status: "active", + grantScope: "agent", + tokenSuffix: "test", + expiresAt: null, + lastUsedAt: null, + createdAt: "2026-08-21T00:00:00.000Z", + }, + grants: [ + { + id: "grant-1", + agentId: "agent-1", + workspaceSlug: "nodedc", + projectId: "project-1", + scopes: ["issue:read"], + mode: "voluntary", + createdByUserId: "owner-1", + createdAt: "2026-08-21T00:00:00.000Z", + updatedAt: "2026-08-21T00:00:00.000Z", + }, + ], + grantSource: "agent", +}; + +test("tasker_audit_comments is read-only and forwards bounded inventory arguments", async () => { + const tool = getToolsForSession(session).find((candidate) => candidate.name === "tasker_audit_comments"); + assert.ok(tool); + assert.equal(tool.annotations?.readOnlyHint, true); + + const forwarded: unknown[] = []; + const taskerClient = new TaskerClient({ baseUrl: "http://tasker.test", internalAccessToken: "test" }); + taskerClient.auditComments = async (...args) => { + forwarded.push(args); + return { ok: true, inventory: { active_count: 3, deleted_count: 2 } }; + }; + + const result = await executeMcpTool( + session, + "tasker_audit_comments", + { + project_id: "project-1", + workspace_slug: "nodedc", + issue_id: "issue-1", + include_bodies: true, + offset: 10, + limit: 50, + }, + { taskerClient } + ); + + assert.deepEqual(forwarded, [ + [ + session, + { + project_id: "project-1", + workspace_slug: "nodedc", + issue_id: "issue-1", + include_bodies: true, + offset: 10, + limit: 50, + }, + ], + ]); + assert.deepEqual(result.structuredContent, { + ok: true, + inventory: { active_count: 3, deleted_count: 2 }, + }); +}); + +test("tasker_audit_comments rejects pages above the incident-response bound", async () => { + const taskerClient = new TaskerClient({ baseUrl: "http://tasker.test", internalAccessToken: "test" }); + + await assert.rejects( + executeMcpTool( + session, + "tasker_audit_comments", + { + project_id: "project-1", + limit: 501, + }, + { taskerClient } + ) + ); +}); diff --git a/src/mcp/tool-runtime.ts b/src/mcp/tool-runtime.ts index 1c904fe..83d5233 100644 --- a/src/mcp/tool-runtime.ts +++ b/src/mcp/tool-runtime.ts @@ -158,6 +158,24 @@ export const mcpRuntimeTools: McpToolRuntimeDefinition[] = [ }, annotations: { readOnlyHint: true }, }, + { + name: "tasker_audit_comments", + title: "NODE.DC Ops: Audit Comments", + description: + "Direct NODE.DC Ops MCP read-only incident tool. Count active and soft-deleted comments in a granted project, return per-card counts, and page through deleted comment metadata and deletion activities.", + requiredScopes: ["issue:read"], + inputSchema: { + ...projectInputSchema, + properties: { + ...projectInputSchema.properties, + issue_id: { type: "string" }, + include_bodies: { type: "boolean", default: false }, + offset: { type: "integer", minimum: 0, maximum: 1000000, default: 0 }, + limit: { type: "integer", minimum: 1, maximum: 500, default: 100 }, + }, + }, + annotations: { readOnlyHint: true }, + }, { name: "tasker_create_issue", title: "NODE.DC Ops: Create Card", @@ -345,6 +363,12 @@ const projectArgsSchema = z.object({ const searchIssuesArgsSchema = projectArgsSchema.extend({ query: z.string().min(1).optional(), }); +const auditCommentsArgsSchema = projectArgsSchema.extend({ + issue_id: z.string().min(1).optional(), + include_bodies: z.boolean().default(false), + offset: z.number().int().min(0).max(1_000_000).default(0), + limit: z.number().int().min(1).max(500).default(100), +}); const prioritySchema = z.enum(["none", "low", "medium", "high", "urgent"]); const createIssueArgsSchema = z.object({ project_id: z.string().min(1), @@ -503,6 +527,11 @@ async function executeMcpToolOnce( requireToolAccess(session, "issue:read", input.project_id, input.workspace_slug); return asToolResult(await deps.taskerClient.listIssues(session, input.project_id, input.workspace_slug, input.query)); } + case "tasker_audit_comments": { + const input = auditCommentsArgsSchema.parse(args); + requireToolAccess(session, "issue:read", input.project_id, input.workspace_slug); + return asToolResult(await deps.taskerClient.auditComments(session, input)); + } case "tasker_create_issue": { const input = createIssueArgsSchema.parse(args); requireToolAccess(session, "issue:create", input.project_id, input.workspace_slug); diff --git a/src/routes/tools.ts b/src/routes/tools.ts index fdf5093..201075b 100644 --- a/src/routes/tools.ts +++ b/src/routes/tools.ts @@ -34,6 +34,29 @@ export async function registerToolRoutes(app: FastifyInstance, deps: ToolRouteDe return result.structuredContent; }); + app.get("/api/v1/tools/projects/:projectId/comments/audit", async (request) => { + const session = await authenticateAgent(request, deps); + const params = request.params as { projectId: string }; + const query = request.query as { + workspace_slug?: string; + issue_id?: string; + include_bodies?: boolean; + offset?: number; + limit?: number; + }; + const result = await executeMcpTool( + session, + "tasker_audit_comments", + { + ...query, + project_id: params.projectId, + }, + deps, + toolOptions(request) + ); + return result.structuredContent; + }); + app.post("/api/v1/tools/projects/:projectId/labels/ensure", async (request) => { const session = await authenticateAgent(request, deps); const params = request.params as { projectId: string }; diff --git a/src/tasker/client.ts b/src/tasker/client.ts index 54144bf..5cd077c 100644 --- a/src/tasker/client.ts +++ b/src/tasker/client.ts @@ -77,6 +77,15 @@ export type CommentInput = { body: string; }; +export type AuditCommentsInput = { + project_id: string; + workspace_slug?: string | null; + issue_id?: string; + include_bodies?: boolean; + offset?: number; + limit?: number; +}; + export type SetLabelsInput = { project_id: string; workspace_slug?: string | null; @@ -194,6 +203,28 @@ export class TaskerClient { ); } + async auditComments(session: AgentSessionRecord, input: AuditCommentsInput): Promise { + const searchParams = new URLSearchParams(); + + if (input.workspace_slug) { + searchParams.set("workspace_slug", input.workspace_slug); + } + if (input.issue_id) { + searchParams.set("issue_id", input.issue_id); + } + searchParams.set("include_bodies", input.include_bodies ? "true" : "false"); + searchParams.set("offset", String(input.offset ?? 0)); + searchParams.set("limit", String(input.limit ?? 100)); + + return this.request( + `/api/internal/nodedc/agent/projects/${encodeURIComponent(input.project_id)}/comments/audit?${searchParams.toString()}`, + { + method: "GET", + session, + } + ); + } + async setLabels(session: AgentSessionRecord, issueId: string, input: SetLabelsInput): Promise { return this.request(`/api/internal/nodedc/agent/issues/${encodeURIComponent(issueId)}/labels`, { method: "PUT",