patchwarden 1.1.0 → 1.5.1
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/README.en.md +83 -8
- package/README.md +78 -10
- package/dist/assessments/agentAssessor.d.ts +1 -1
- package/dist/assessments/agentAssessor.js +3 -3
- package/dist/assessments/assessmentStore.d.ts +1 -1
- package/dist/assessments/assessmentStore.js +2 -2
- package/dist/assessments/confirmCli.js +5 -4
- package/dist/config.d.ts +7 -0
- package/dist/config.js +34 -0
- package/dist/control/middleware/auth.d.ts +10 -0
- package/dist/control/middleware/auth.js +8 -0
- package/dist/control/middleware/static.d.ts +3 -0
- package/dist/control/middleware/static.js +65 -0
- package/dist/control/routes/audit.d.ts +15 -0
- package/dist/control/routes/audit.js +277 -0
- package/dist/control/routes/evidence.d.ts +4 -0
- package/dist/control/routes/evidence.js +96 -0
- package/dist/control/routes/lineage.d.ts +3 -0
- package/dist/control/routes/lineage.js +71 -0
- package/dist/control/routes/policy.d.ts +3 -0
- package/dist/control/routes/policy.js +81 -0
- package/dist/control/routes/process.d.ts +5 -0
- package/dist/control/routes/process.js +200 -0
- package/dist/control/routes/sessions.d.ts +22 -0
- package/dist/control/routes/sessions.js +224 -0
- package/dist/control/routes/status.d.ts +6 -0
- package/dist/control/routes/status.js +250 -0
- package/dist/control/routes/taskActions.d.ts +21 -0
- package/dist/control/routes/taskActions.js +233 -0
- package/dist/control/routes/tasks.d.ts +20 -0
- package/dist/control/routes/tasks.js +310 -0
- package/dist/control/routes/workspace.d.ts +15 -0
- package/dist/control/routes/workspace.js +193 -0
- package/dist/control/runtime.d.ts +91 -0
- package/dist/control/runtime.js +392 -0
- package/dist/control/server.d.ts +13 -0
- package/dist/control/server.js +479 -0
- package/dist/control/shared.d.ts +35 -0
- package/dist/control/shared.js +288 -0
- package/dist/controlCenter.d.ts +6 -0
- package/dist/controlCenter.js +7 -2001
- package/dist/direct/directGuards.js +30 -8
- package/dist/direct/directSessionStore.d.ts +2 -0
- package/dist/direct/directVerification.js +7 -0
- package/dist/doctor.d.ts +18 -1
- package/dist/doctor.js +579 -348
- package/dist/goal/goalReport.d.ts +54 -0
- package/dist/goal/goalReport.js +204 -0
- package/dist/goal/goalStatus.d.ts +6 -0
- package/dist/goal/specKitImport.d.ts +63 -0
- package/dist/goal/specKitImport.js +220 -0
- package/dist/goal/subgoalSync.js +2 -1
- package/dist/httpServer.js +15 -12
- package/dist/index.js +7 -4
- package/dist/logging.d.ts +7 -1
- package/dist/logging.js +8 -0
- package/dist/policy/projectPolicy.d.ts +55 -0
- package/dist/policy/projectPolicy.js +286 -0
- package/dist/runner/changeCapture.d.ts +3 -3
- package/dist/runner/changeCapture.js +63 -39
- package/dist/runner/cli.js +7 -6
- package/dist/runner/postTaskCleanup.js +26 -2
- package/dist/runner/runTask.js +245 -221
- package/dist/runner/simpleProcess.js +4 -4
- package/dist/runner/watch.js +17 -14
- package/dist/security/contentRedaction.d.ts +6 -0
- package/dist/security/contentRedaction.js +22 -0
- package/dist/smoke-test.js +261 -255
- package/dist/test/unit/apply-patch.test.d.ts +1 -0
- package/dist/test/unit/apply-patch.test.js +225 -0
- package/dist/test/unit/create-task.test.d.ts +1 -0
- package/dist/test/unit/create-task.test.js +197 -0
- package/dist/test/unit/direct-guards.test.js +124 -9
- package/dist/test/unit/evidence-pack.test.d.ts +1 -0
- package/dist/test/unit/evidence-pack.test.js +224 -0
- package/dist/test/unit/get-task-status.test.d.ts +1 -0
- package/dist/test/unit/get-task-status.test.js +174 -0
- package/dist/test/unit/get-task-summary.test.d.ts +1 -0
- package/dist/test/unit/get-task-summary.test.js +146 -0
- package/dist/test/unit/goal-report.test.d.ts +1 -0
- package/dist/test/unit/goal-report.test.js +159 -0
- package/dist/test/unit/goal-subgoal-task.test.js +6 -6
- package/dist/test/unit/goal-tools-registry.test.js +6 -4
- package/dist/test/unit/path-guard.test.js +24 -0
- package/dist/test/unit/project-policy-release-mode.test.d.ts +1 -0
- package/dist/test/unit/project-policy-release-mode.test.js +125 -0
- package/dist/test/unit/run-task-loop.test.d.ts +1 -0
- package/dist/test/unit/run-task-loop.test.js +380 -0
- package/dist/test/unit/schema-drift-check.test.js +10 -9
- package/dist/test/unit/spec-kit-import.test.d.ts +1 -0
- package/dist/test/unit/spec-kit-import.test.js +341 -0
- package/dist/test/unit/wait-for-task.test.d.ts +1 -0
- package/dist/test/unit/wait-for-task.test.js +144 -0
- package/dist/tools/auditTask.d.ts +8 -63
- package/dist/tools/auditTask.js +12 -8
- package/dist/tools/createDirectSession.d.ts +1 -1
- package/dist/tools/createDirectSession.js +2 -2
- package/dist/tools/createTask.d.ts +2 -2
- package/dist/tools/createTask.js +4 -4
- package/dist/tools/dispatch/coreDispatch.d.ts +9 -0
- package/dist/tools/dispatch/coreDispatch.js +282 -0
- package/dist/tools/dispatch/diagnosticDispatch.d.ts +14 -0
- package/dist/tools/dispatch/diagnosticDispatch.js +78 -0
- package/dist/tools/dispatch/directDispatch.d.ts +8 -0
- package/dist/tools/dispatch/directDispatch.js +115 -0
- package/dist/tools/dispatch/goalDispatch.d.ts +8 -0
- package/dist/tools/dispatch/goalDispatch.js +91 -0
- package/dist/tools/dispatch/releaseDispatch.d.ts +8 -0
- package/dist/tools/dispatch/releaseDispatch.js +45 -0
- package/dist/tools/dispatch/types.d.ts +23 -0
- package/dist/tools/dispatch/types.js +15 -0
- package/dist/tools/evidencePack.d.ts +45 -0
- package/dist/tools/evidencePack.js +375 -0
- package/dist/tools/finalizeDirectSession.d.ts +1 -1
- package/dist/tools/finalizeDirectSession.js +3 -3
- package/dist/tools/goalSubgoalTask.d.ts +1 -1
- package/dist/tools/goalSubgoalTask.js +2 -2
- package/dist/tools/healthCheck.js +3 -3
- package/dist/tools/recommendAgentForTask.d.ts +19 -0
- package/dist/tools/recommendAgentForTask.js +56 -0
- package/dist/tools/registry.d.ts +3 -3
- package/dist/tools/registry.js +333 -402
- package/dist/tools/releaseMode.d.ts +50 -0
- package/dist/tools/releaseMode.js +370 -0
- package/dist/tools/retryTask.d.ts +2 -2
- package/dist/tools/retryTask.js +2 -2
- package/dist/tools/runDirectVerificationBundle.d.ts +26 -0
- package/dist/tools/runDirectVerificationBundle.js +64 -0
- package/dist/tools/runTaskLoop.d.ts +57 -0
- package/dist/tools/runTaskLoop.js +417 -0
- package/dist/tools/runVerification.d.ts +4 -0
- package/dist/tools/runVerification.js +4 -0
- package/dist/tools/safeViews.d.ts +8 -2
- package/dist/tools/safeViews.js +4 -2
- package/dist/tools/taskLineage.d.ts +91 -0
- package/dist/tools/taskLineage.js +175 -0
- package/dist/tools/toolCatalog.d.ts +2 -2
- package/dist/tools/toolCatalog.js +6 -0
- package/dist/tools/toolRegistry.js +132 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/docs/CODE_WIKI.md +983 -0
- package/docs/agentseal-integration.md +150 -0
- package/docs/architecture.md +63 -0
- package/docs/assets/patchwarden-oss-demo.gif +0 -0
- package/docs/chatgpt-usage.md +31 -0
- package/docs/control-center/README.md +9 -0
- package/docs/dashboard-overview.md +86 -0
- package/docs/demo.md +8 -0
- package/docs/direct-session-workflow.md +98 -0
- package/docs/evidence-pack-schema.md +215 -0
- package/docs/execution-plan-2026-07-09.md +315 -0
- package/docs/lineage-evidence-pack-workflow.md +127 -0
- package/docs/mcp-inspector-testing.md +200 -0
- package/docs/open-source-application.md +162 -0
- package/docs/opencode-worker.md +151 -0
- package/docs/openhands-worker.md +181 -0
- package/docs/release-evidence.md +72 -0
- package/docs/roadmap-execution-and-acceptance.md +365 -0
- package/docs/spec-kit-integration.md +131 -0
- package/docs/task-safe-review-workflow.md +98 -0
- package/docs/threat-model.md +79 -0
- package/docs/user-feedback.md +40 -0
- package/docs/why-patchwarden.md +110 -0
- package/package.json +3 -3
- package/scripts/checks/control-center-smoke.js +443 -0
- package/scripts/checks/control-smoke.js +2 -2
- package/scripts/checks/lifecycle-smoke.js +29 -23
- package/scripts/checks/mcp-manifest-check.js +12 -0
- package/scripts/checks/mcp-smoke.js +33 -7
- package/scripts/checks/watcher-supervisor-smoke.js +1 -1
- package/scripts/generate-demo-gif.py +320 -0
- package/src/assessments/agentAssessor.ts +3 -3
- package/src/assessments/assessmentStore.ts +2 -2
- package/src/assessments/confirmCli.ts +5 -4
- package/src/config.ts +37 -0
- package/src/control/middleware/auth.ts +17 -0
- package/src/control/middleware/static.ts +71 -0
- package/src/control/routes/audit.ts +321 -0
- package/src/control/routes/evidence.ts +107 -0
- package/src/control/routes/lineage.ts +92 -0
- package/src/control/routes/policy.ts +81 -0
- package/src/control/routes/process.ts +204 -0
- package/src/control/routes/sessions.ts +251 -0
- package/src/control/routes/status.ts +325 -0
- package/src/control/routes/taskActions.ts +248 -0
- package/src/control/routes/tasks.ts +323 -0
- package/src/control/routes/workspace.ts +203 -0
- package/src/control/runtime.ts +472 -0
- package/src/control/server.ts +471 -0
- package/src/control/shared.ts +294 -0
- package/src/controlCenter.ts +7 -2150
- package/src/direct/directGuards.ts +28 -7
- package/src/direct/directSessionStore.ts +2 -0
- package/src/direct/directVerification.ts +7 -0
- package/src/doctor.ts +741 -481
- package/src/goal/goalReport.ts +271 -0
- package/src/goal/goalStatus.ts +6 -0
- package/src/goal/specKitImport.ts +355 -0
- package/src/goal/subgoalSync.ts +4 -2
- package/src/httpServer.ts +17 -14
- package/src/index.ts +7 -4
- package/src/logging.ts +10 -1
- package/src/policy/projectPolicy.ts +344 -0
- package/src/runner/changeCapture.ts +70 -42
- package/src/runner/cli.ts +7 -6
- package/src/runner/postTaskCleanup.ts +26 -2
- package/src/runner/runTask.ts +325 -223
- package/src/runner/simpleProcess.ts +4 -4
- package/src/runner/watch.ts +17 -14
- package/src/security/contentRedaction.ts +29 -0
- package/src/smoke-test.ts +254 -252
- package/src/test/unit/apply-patch.test.ts +293 -0
- package/src/test/unit/create-task.test.ts +255 -0
- package/src/test/unit/direct-guards.test.ts +178 -8
- package/src/test/unit/evidence-pack.test.ts +251 -0
- package/src/test/unit/get-task-status.test.ts +203 -0
- package/src/test/unit/get-task-summary.test.ts +173 -0
- package/src/test/unit/goal-report.test.ts +189 -0
- package/src/test/unit/goal-subgoal-task.test.ts +6 -6
- package/src/test/unit/goal-tools-registry.test.ts +7 -5
- package/src/test/unit/path-guard.test.ts +30 -0
- package/src/test/unit/project-policy-release-mode.test.ts +156 -0
- package/src/test/unit/run-task-loop.test.ts +425 -0
- package/src/test/unit/schema-drift-check.test.ts +11 -9
- package/src/test/unit/spec-kit-import.test.ts +429 -0
- package/src/test/unit/wait-for-task.test.ts +176 -0
- package/src/tools/auditTask.ts +99 -59
- package/src/tools/createDirectSession.ts +3 -3
- package/src/tools/createTask.ts +7 -7
- package/src/tools/dispatch/coreDispatch.ts +374 -0
- package/src/tools/dispatch/diagnosticDispatch.ts +101 -0
- package/src/tools/dispatch/directDispatch.ts +167 -0
- package/src/tools/dispatch/goalDispatch.ts +127 -0
- package/src/tools/dispatch/releaseDispatch.ts +65 -0
- package/src/tools/dispatch/types.ts +24 -0
- package/src/tools/evidencePack.ts +490 -0
- package/src/tools/finalizeDirectSession.ts +4 -4
- package/src/tools/goalSubgoalTask.ts +2 -2
- package/src/tools/healthCheck.ts +3 -3
- package/src/tools/listWorkspace.ts +71 -71
- package/src/tools/recommendAgentForTask.ts +79 -0
- package/src/tools/registry.ts +352 -509
- package/src/tools/releaseMode.ts +450 -0
- package/src/tools/retryTask.ts +2 -2
- package/src/tools/runDirectVerificationBundle.ts +98 -0
- package/src/tools/runTaskLoop.ts +526 -0
- package/src/tools/runVerification.ts +8 -0
- package/src/tools/safeViews.ts +4 -2
- package/src/tools/taskLineage.ts +300 -0
- package/src/tools/toolCatalog.ts +6 -0
- package/src/tools/toolRegistry.ts +132 -0
- package/src/version.ts +2 -2
- package/ui/pages/audit.html +192 -3
- package/ui/pages/dashboard.html +1070 -14
- package/ui/pages/direct-sessions.html +505 -53
- package/ui/pages/task-detail.html +456 -438
- package/ui/pages/tasks.html +598 -61
package/dist/tools/registry.js
CHANGED
|
@@ -4,58 +4,24 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
6
6
|
import { getAllConfiguredTestCommands, getAllConfiguredDirectCommands, getConfig } from "../config.js";
|
|
7
|
-
import { savePlan } from "../tools/savePlan.js";
|
|
8
|
-
import { getPlan } from "../tools/getPlan.js";
|
|
9
|
-
import { createTask } from "../tools/createTask.js";
|
|
10
|
-
import { getTaskStatus } from "../tools/getTaskStatus.js";
|
|
11
|
-
import { getResult, getResultJson, getDiff, getTestLog, getTaskLogTail } from "../tools/taskOutputs.js";
|
|
12
|
-
import { listWorkspace } from "../tools/listWorkspace.js";
|
|
13
|
-
import { readWorkspaceFile } from "../tools/readWorkspaceFile.js";
|
|
14
|
-
import { listTasks } from "../tools/listTasks.js";
|
|
15
|
-
import { cancelTask } from "../tools/cancelTask.js";
|
|
16
|
-
import { killTask } from "../tools/killTask.js";
|
|
17
|
-
import { retryTask } from "../tools/retryTask.js";
|
|
18
|
-
import { getTaskStdoutTail } from "../tools/getTaskStdoutTail.js";
|
|
19
|
-
import { getTaskProgress } from "../tools/getTaskProgress.js";
|
|
20
|
-
import { listAgents } from "../tools/listAgents.js";
|
|
21
|
-
import { healthCheck } from "../tools/healthCheck.js";
|
|
22
|
-
import { getTaskSummary } from "../tools/getTaskSummary.js";
|
|
23
|
-
import { waitForTask } from "../tools/waitForTask.js";
|
|
24
7
|
import { errorPayload, PatchWardenError } from "../errors.js";
|
|
25
|
-
import { auditTask } from "../tools/auditTask.js";
|
|
26
|
-
import { safeStatus } from "../tools/safeStatus.js";
|
|
27
|
-
import { safeAudit, safeAuditDirectSession, safeDiffSummary, safeDirectSummary, safeFinalizeDirectSession, safeResult, safeTestSummary, } from "../tools/safeViews.js";
|
|
28
|
-
import { diagnoseTask } from "../tools/diagnoseTask.js";
|
|
29
|
-
import { reconcileTasks } from "../tools/reconcileTasks.js";
|
|
30
|
-
import { discoverTools } from "../tools/discoverTools.js";
|
|
31
|
-
import { explainTool } from "../tools/explainTool.js";
|
|
32
|
-
import { invokeDiscoveredTool } from "./invokeDiscoveredTool.js";
|
|
33
8
|
import { logger } from "../logging.js";
|
|
34
|
-
import { runTask } from "../runner/runTask.js";
|
|
35
|
-
import { createDirectSession } from "../tools/createDirectSession.js";
|
|
36
|
-
import { searchWorkspace } from "../tools/searchWorkspace.js";
|
|
37
|
-
import { applyPatch } from "../tools/applyPatch.js";
|
|
38
|
-
import { runVerification } from "../tools/runVerification.js";
|
|
39
|
-
import { finalizeDirectSession } from "../tools/finalizeDirectSession.js";
|
|
40
|
-
import { auditSession } from "../tools/auditSession.js";
|
|
41
|
-
import { syncFile } from "../tools/syncFile.js";
|
|
42
|
-
import { createGoal, listGoals, readGoal, readGoalStatus } from "../goal/goalStore.js";
|
|
43
|
-
import { suggestNextSubgoal } from "../goal/goalGraph.js";
|
|
44
|
-
import { exportHandoff } from "../goal/handoffExport.js";
|
|
45
|
-
import { acceptSubgoal, rejectSubgoal, summarizeGoalProgress } from "../goal/goalProgress.js";
|
|
46
|
-
import { createSubgoalTask } from "./goalSubgoalTask.js";
|
|
47
|
-
import { checkReleaseGate } from "./checkReleaseGate.js";
|
|
48
|
-
import { mergeWorktreeTool } from "./mergeWorktree.js";
|
|
49
|
-
import { discardWorktreeTool } from "./discardWorktree.js";
|
|
50
9
|
import { TASK_TEMPLATE_NAMES } from "./taskTemplates.js";
|
|
51
10
|
import { buildToolCatalogSnapshot, getLastToolCatalogSnapshot, resolveToolProfile, selectToolsForProfile, } from "./toolCatalog.js";
|
|
11
|
+
import { coreHandlers, runTaskHandler } from "./dispatch/coreDispatch.js";
|
|
12
|
+
import { goalHandlers } from "./dispatch/goalDispatch.js";
|
|
13
|
+
import { directHandlers } from "./dispatch/directDispatch.js";
|
|
14
|
+
import { releaseHandlers } from "./dispatch/releaseDispatch.js";
|
|
15
|
+
import { diagnosticHandlers } from "./dispatch/diagnosticDispatch.js";
|
|
52
16
|
export function getToolDefs() {
|
|
53
17
|
const config = getConfig();
|
|
54
18
|
const agentNames = Object.keys(config.agents).sort();
|
|
19
|
+
const routableAgentNames = [...agentNames, "auto"];
|
|
55
20
|
const agentDescription = agentNames.length > 0
|
|
56
|
-
? `Configured local agent name. Available agents: ${agentNames.map((name) => JSON.stringify(name)).join(", ")}
|
|
21
|
+
? `Configured local agent name. Available agents: ${agentNames.map((name) => JSON.stringify(name)).join(", ")}. run_task_loop also accepts "auto" for bounded routing.`
|
|
57
22
|
: "Configured local agent name. No agents are currently configured.";
|
|
58
23
|
const testCommands = getAllConfiguredTestCommands(config).sort();
|
|
24
|
+
const directCommands = getAllConfiguredDirectCommands(config);
|
|
59
25
|
const tools = [
|
|
60
26
|
{
|
|
61
27
|
name: "save_plan",
|
|
@@ -165,6 +131,173 @@ export function getToolDefs() {
|
|
|
165
131
|
required: [],
|
|
166
132
|
},
|
|
167
133
|
},
|
|
134
|
+
{
|
|
135
|
+
name: "run_task_loop",
|
|
136
|
+
description: "Run a guarded PatchWarden task loop by composing create_task, wait_for_task, safe summaries, and audit_task. It does not bypass the watcher, command allow-list, workspace confinement, or confirmation boundaries. Returns only bounded structured lineage and final status.",
|
|
137
|
+
inputSchema: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
repo_path: {
|
|
141
|
+
type: "string",
|
|
142
|
+
description: "Required repository path inside workspaceRoot. No implicit workspace-root fallback is allowed.",
|
|
143
|
+
},
|
|
144
|
+
goal: { type: "string", description: "Task goal to execute through the guarded loop." },
|
|
145
|
+
verify_commands: {
|
|
146
|
+
type: "array",
|
|
147
|
+
minItems: 1,
|
|
148
|
+
maxItems: 20,
|
|
149
|
+
items: {
|
|
150
|
+
type: "string",
|
|
151
|
+
...(testCommands.length > 0 ? { enum: testCommands } : {}),
|
|
152
|
+
},
|
|
153
|
+
description: "Exact-match verification commands. The loop reuses create_task validation and will not run commands outside the allow-list.",
|
|
154
|
+
},
|
|
155
|
+
agent: {
|
|
156
|
+
type: "string",
|
|
157
|
+
description: agentDescription,
|
|
158
|
+
...(agentNames.length > 0 ? { enum: routableAgentNames } : {}),
|
|
159
|
+
},
|
|
160
|
+
template: {
|
|
161
|
+
type: "string",
|
|
162
|
+
enum: ["inspect_only", "feature_small", "release_check"],
|
|
163
|
+
default: "feature_small",
|
|
164
|
+
description: "Initial guarded task template. Follow-up repair tasks use fix_tests automatically when verification fails.",
|
|
165
|
+
},
|
|
166
|
+
max_iterations: {
|
|
167
|
+
type: "integer",
|
|
168
|
+
minimum: 1,
|
|
169
|
+
maximum: 5,
|
|
170
|
+
default: 3,
|
|
171
|
+
description: "Maximum total main/fix task attempts.",
|
|
172
|
+
},
|
|
173
|
+
task_timeout_seconds: {
|
|
174
|
+
type: "integer",
|
|
175
|
+
minimum: 1,
|
|
176
|
+
maximum: config.maxTaskTimeoutSeconds,
|
|
177
|
+
default: config.defaultTaskTimeoutSeconds,
|
|
178
|
+
description: `Per-task wait budget in seconds (default ${config.defaultTaskTimeoutSeconds}, max ${config.maxTaskTimeoutSeconds}).`,
|
|
179
|
+
},
|
|
180
|
+
auto_fix_tests: {
|
|
181
|
+
type: "boolean",
|
|
182
|
+
default: true,
|
|
183
|
+
description: "When true, create a fix_tests follow-up task after failed_verification until max_iterations is reached.",
|
|
184
|
+
},
|
|
185
|
+
auto_cleanup_artifacts: {
|
|
186
|
+
type: "boolean",
|
|
187
|
+
default: true,
|
|
188
|
+
description: "Records cleanup intent in lineage. Low-risk cleanup remains handled by runTask post-task cleanup.",
|
|
189
|
+
},
|
|
190
|
+
stop_on_high_risk: {
|
|
191
|
+
type: "boolean",
|
|
192
|
+
default: true,
|
|
193
|
+
description: "When true, stop immediately on non-policy high-risk audit evidence. Scope, policy, sensitive-path, release/publish, and confirmation boundaries always stop regardless of this flag.",
|
|
194
|
+
},
|
|
195
|
+
direct_verify: {
|
|
196
|
+
type: "boolean",
|
|
197
|
+
default: false,
|
|
198
|
+
description: "When true, run an independent Direct verification session after the guarded task/audit succeeds. Direct never patches files in this loop.",
|
|
199
|
+
},
|
|
200
|
+
direct_verify_commands: {
|
|
201
|
+
type: "array",
|
|
202
|
+
minItems: 1,
|
|
203
|
+
maxItems: 20,
|
|
204
|
+
items: {
|
|
205
|
+
type: "string",
|
|
206
|
+
...(directCommands.length > 0 ? { enum: directCommands } : {}),
|
|
207
|
+
},
|
|
208
|
+
description: "Optional Direct verification commands. Defaults to verify_commands and still must pass the Direct command allow-list.",
|
|
209
|
+
},
|
|
210
|
+
direct_verify_timeout_seconds: {
|
|
211
|
+
type: "integer",
|
|
212
|
+
minimum: 1,
|
|
213
|
+
maximum: Math.min(config.maxTaskTimeoutSeconds, config.directSessionTtlSeconds),
|
|
214
|
+
default: 120,
|
|
215
|
+
description: "Per-command timeout for Direct verification.",
|
|
216
|
+
},
|
|
217
|
+
scope_files: {
|
|
218
|
+
type: "array",
|
|
219
|
+
maxItems: 50,
|
|
220
|
+
items: { type: "string" },
|
|
221
|
+
description: "Optional bounded file scope used only for agent routing hints.",
|
|
222
|
+
},
|
|
223
|
+
isolation_mode: {
|
|
224
|
+
type: "string",
|
|
225
|
+
enum: ["current_repo", "worktree"],
|
|
226
|
+
default: "current_repo",
|
|
227
|
+
description: "Use current_repo by default. worktree creates an isolated git worktree for the task but never auto-merges it.",
|
|
228
|
+
},
|
|
229
|
+
worktree_base_branch: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: "Optional base-branch label recorded in lineage. v1.5 does not auto-checkout or merge this branch.",
|
|
232
|
+
},
|
|
233
|
+
worktree_cleanup: {
|
|
234
|
+
type: "string",
|
|
235
|
+
enum: ["keep", "archive", "delete_ignored_only"],
|
|
236
|
+
default: "keep",
|
|
237
|
+
description: "Cleanup intent recorded in lineage. v1.5 keeps worktrees by default and does not auto-delete them.",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
required: ["repo_path", "goal", "verify_commands"],
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "recommend_agent_for_task",
|
|
245
|
+
description: "Return a bounded read-only agent routing recommendation for a repo-scoped task. Does not start an agent, create a task, or read logs.",
|
|
246
|
+
inputSchema: {
|
|
247
|
+
type: "object",
|
|
248
|
+
properties: {
|
|
249
|
+
repo_path: { type: "string", description: "Repository path inside workspaceRoot." },
|
|
250
|
+
goal: { type: "string", description: "Task goal used for routing hints." },
|
|
251
|
+
scope_files: {
|
|
252
|
+
type: "array",
|
|
253
|
+
maxItems: 50,
|
|
254
|
+
items: { type: "string" },
|
|
255
|
+
description: "Optional bounded list of files or directories expected to be in scope.",
|
|
256
|
+
},
|
|
257
|
+
template: { type: "string", description: "Optional task template hint." },
|
|
258
|
+
risk_hint: { type: "string", description: "Optional compact risk hint text." },
|
|
259
|
+
},
|
|
260
|
+
required: ["repo_path", "goal"],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "get_task_lineage",
|
|
265
|
+
description: "Read a bounded safe summary for a run_task_loop lineage. Does not return full logs, diffs, stdout, stderr, or markdown artifacts.",
|
|
266
|
+
inputSchema: {
|
|
267
|
+
type: "object",
|
|
268
|
+
properties: {
|
|
269
|
+
lineage_id: { type: "string", description: "Lineage ID returned by run_task_loop." },
|
|
270
|
+
max_items: { type: "integer", minimum: 1, maximum: 50, default: 8, description: "Maximum rounds/tasks/warnings to return." },
|
|
271
|
+
},
|
|
272
|
+
required: ["lineage_id"],
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: "export_task_evidence_pack",
|
|
277
|
+
description: "Export a bounded evidence pack for a run_task_loop lineage. Writes evidence.json and EVIDENCE.md without stdout, stderr, full logs, full diff, or sensitive file contents.",
|
|
278
|
+
inputSchema: {
|
|
279
|
+
type: "object",
|
|
280
|
+
properties: {
|
|
281
|
+
lineage_id: { type: "string", description: "Lineage ID returned by run_task_loop." },
|
|
282
|
+
max_items: { type: "integer", minimum: 1, maximum: 50, default: 12, description: "Maximum rounds/tasks/warnings to include." },
|
|
283
|
+
},
|
|
284
|
+
required: ["lineage_id"],
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "get_project_policy",
|
|
289
|
+
description: "Read the bounded effective .patchwarden/project-policy.json summary for a repository. Missing policy returns safe defaults. Project policy never expands PatchWarden command allow-lists, workspace confinement, sensitive-path blocking, or watcher/audit boundaries.",
|
|
290
|
+
inputSchema: {
|
|
291
|
+
type: "object",
|
|
292
|
+
properties: {
|
|
293
|
+
repo_path: {
|
|
294
|
+
type: "string",
|
|
295
|
+
description: "Repository path inside workspaceRoot.",
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
required: ["repo_path"],
|
|
299
|
+
},
|
|
300
|
+
},
|
|
168
301
|
{
|
|
169
302
|
name: "get_task_status",
|
|
170
303
|
description: "Check task status, execution phase, watcher health, pending reason, current command, timeout, and change evidence.",
|
|
@@ -701,6 +834,29 @@ export function getToolDefs() {
|
|
|
701
834
|
required: ["goal_id"],
|
|
702
835
|
},
|
|
703
836
|
},
|
|
837
|
+
{
|
|
838
|
+
name: "export_goal_report",
|
|
839
|
+
description: "Export a structured final report for a Goal session, aggregating subgoal completion, task evidence, and risk summary.",
|
|
840
|
+
inputSchema: {
|
|
841
|
+
type: "object",
|
|
842
|
+
properties: {
|
|
843
|
+
goal_id: { type: "string", description: "The goal id to export report for." },
|
|
844
|
+
},
|
|
845
|
+
required: ["goal_id"],
|
|
846
|
+
},
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
name: "import_speckit_tasks",
|
|
850
|
+
description: "Import Spec Kit tasks into a Goal session as subgoals, mapping task files to scope hints and acceptance criteria.",
|
|
851
|
+
inputSchema: {
|
|
852
|
+
type: "object",
|
|
853
|
+
properties: {
|
|
854
|
+
goal_id: { type: "string", description: "The goal id to import tasks into." },
|
|
855
|
+
spec_kit_json: { type: "string", description: "Spec Kit JSON text containing spec, tasks[], and acceptance[] fields." },
|
|
856
|
+
},
|
|
857
|
+
required: ["goal_id", "spec_kit_json"],
|
|
858
|
+
},
|
|
859
|
+
},
|
|
704
860
|
{
|
|
705
861
|
name: "check_release_gate",
|
|
706
862
|
description: "v1.0.0: Verify release readiness across five sequential stages: local_ready → packed_ready → published_verified → github_release_verified → ci_verified. Remote stages (published/github/ci) query npm registry and GitHub API via node:https read-only GET; network errors return 'not_checked' (not 'failed'). Never claims release complete before published_verified passes. Does not execute shell commands for remote queries.",
|
|
@@ -721,6 +877,87 @@ export function getToolDefs() {
|
|
|
721
877
|
required: ["repo_path", "target_stage"],
|
|
722
878
|
},
|
|
723
879
|
},
|
|
880
|
+
{
|
|
881
|
+
name: "release_check",
|
|
882
|
+
description: "v1.3.0: Run a bounded release readiness check by wrapping the existing release gate. Local stages use existing guarded release-gate commands; remote stages are read-only. Does not publish, push, tag, or create a GitHub Release.",
|
|
883
|
+
inputSchema: {
|
|
884
|
+
type: "object",
|
|
885
|
+
properties: {
|
|
886
|
+
repo_path: { type: "string", description: "Repository path inside workspaceRoot." },
|
|
887
|
+
target_stage: {
|
|
888
|
+
type: "string",
|
|
889
|
+
enum: ["local_ready", "packed_ready", "published_verified", "github_release_verified", "ci_verified"],
|
|
890
|
+
default: "local_ready",
|
|
891
|
+
description: "Release gate stage to check. Defaults to local_ready.",
|
|
892
|
+
},
|
|
893
|
+
package_name: { type: "string", description: "npm package name for remote verification." },
|
|
894
|
+
version: { type: "string", description: "Version to verify. Defaults to project policy/package.json when omitted." },
|
|
895
|
+
github_repo: { type: "string", description: "GitHub repo in owner/repo form for release/CI verification." },
|
|
896
|
+
branch: { type: "string", default: "main", description: "Branch for CI verification." },
|
|
897
|
+
},
|
|
898
|
+
required: ["repo_path"],
|
|
899
|
+
},
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
name: "release_prepare",
|
|
903
|
+
description: "v1.3.0: Run project-policy release preparation commands only when each command is already accepted by the existing PatchWarden command guard. Returns command status only, never stdout/stderr. Does not publish, push, tag, or create a GitHub Release.",
|
|
904
|
+
inputSchema: {
|
|
905
|
+
type: "object",
|
|
906
|
+
properties: {
|
|
907
|
+
repo_path: { type: "string", description: "Repository path inside workspaceRoot." },
|
|
908
|
+
required_commands: {
|
|
909
|
+
type: "array",
|
|
910
|
+
maxItems: 10,
|
|
911
|
+
items: {
|
|
912
|
+
type: "string",
|
|
913
|
+
...(testCommands.length > 0 ? { enum: testCommands } : {}),
|
|
914
|
+
},
|
|
915
|
+
description: "Optional exact-match release preparation commands. Defaults to project policy release_mode.required_commands.",
|
|
916
|
+
},
|
|
917
|
+
timeout_seconds: {
|
|
918
|
+
type: "integer",
|
|
919
|
+
minimum: 1,
|
|
920
|
+
maximum: config.maxTaskTimeoutSeconds,
|
|
921
|
+
default: 300,
|
|
922
|
+
description: "Per-command timeout in seconds.",
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
required: ["repo_path"],
|
|
926
|
+
},
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
name: "release_verify",
|
|
930
|
+
description: "v1.3.0: Verify npm/GitHub/CI release facts with read-only HTTPS requests. Does not run local shell commands and does not publish, push, tag, or create a GitHub Release.",
|
|
931
|
+
inputSchema: {
|
|
932
|
+
type: "object",
|
|
933
|
+
properties: {
|
|
934
|
+
repo_path: { type: "string", description: "Repository path inside workspaceRoot." },
|
|
935
|
+
package_name: { type: "string", description: "npm package name. Defaults to package.json name." },
|
|
936
|
+
version: { type: "string", description: "Version to verify. Defaults to project policy/package.json." },
|
|
937
|
+
github_repo: { type: "string", description: "GitHub repo in owner/repo form. Defaults to package.json repository when available." },
|
|
938
|
+
branch: { type: "string", default: "main", description: "Branch for CI verification." },
|
|
939
|
+
},
|
|
940
|
+
required: ["repo_path"],
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
name: "release_cleanup",
|
|
945
|
+
description: "v1.3.0: Clean up release artifacts using project-policy auto_cleanup rules. Defaults to dry_run=true. Non-dry-run cleanup only removes low-risk ignored/untracked artifacts under repo_path and writes an audit summary.",
|
|
946
|
+
inputSchema: {
|
|
947
|
+
type: "object",
|
|
948
|
+
properties: {
|
|
949
|
+
repo_path: { type: "string", description: "Repository path inside workspaceRoot." },
|
|
950
|
+
dry_run: { type: "boolean", default: true, description: "Preview cleanup by default. Set false to remove eligible artifacts." },
|
|
951
|
+
patterns: {
|
|
952
|
+
type: "array",
|
|
953
|
+
maxItems: 20,
|
|
954
|
+
items: { type: "string" },
|
|
955
|
+
description: "Optional cleanup patterns. Defaults to project policy auto_cleanup.patterns.",
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
required: ["repo_path"],
|
|
959
|
+
},
|
|
960
|
+
},
|
|
724
961
|
{
|
|
725
962
|
name: "merge_worktree",
|
|
726
963
|
description: "v1.0.0: Merge an isolated git worktree's changes back into the main workspace. Use after a subgoal task (created with isolate_worktree=true) is accepted. Updates worktree_status.json to status='merged'. Merge failures do NOT delete the worktree (preserved for manual inspection).",
|
|
@@ -747,7 +984,6 @@ export function getToolDefs() {
|
|
|
747
984
|
},
|
|
748
985
|
];
|
|
749
986
|
// Direct session tools
|
|
750
|
-
const directCommands = getAllConfiguredDirectCommands(config);
|
|
751
987
|
tools.push({
|
|
752
988
|
name: "create_direct_session",
|
|
753
989
|
description: "Create a Direct editing session for ChatGPT to apply patches directly. Requires enableDirectProfile: true in config.",
|
|
@@ -829,6 +1065,28 @@ export function getToolDefs() {
|
|
|
829
1065
|
required: ["session_id", "command"],
|
|
830
1066
|
},
|
|
831
1067
|
});
|
|
1068
|
+
tools.push({
|
|
1069
|
+
name: "run_direct_verification_bundle",
|
|
1070
|
+
description: "Run multiple allowlisted Direct verification commands sequentially and return only bounded structured status. Omits stdout/stderr tails and log content.",
|
|
1071
|
+
inputSchema: {
|
|
1072
|
+
type: "object",
|
|
1073
|
+
properties: {
|
|
1074
|
+
session_id: { type: "string", description: "Direct session ID" },
|
|
1075
|
+
commands: {
|
|
1076
|
+
type: "array",
|
|
1077
|
+
minItems: 1,
|
|
1078
|
+
maxItems: 20,
|
|
1079
|
+
items: {
|
|
1080
|
+
type: "string",
|
|
1081
|
+
...(directCommands.length > 0 ? { enum: directCommands } : {}),
|
|
1082
|
+
},
|
|
1083
|
+
description: "Verification commands to run in order. Each command must be accepted by the existing Direct command guard.",
|
|
1084
|
+
},
|
|
1085
|
+
timeout_seconds: { type: "integer", minimum: 1, maximum: Math.min(config.maxTaskTimeoutSeconds, config.directSessionTtlSeconds), default: 120 },
|
|
1086
|
+
},
|
|
1087
|
+
required: ["session_id", "commands"],
|
|
1088
|
+
},
|
|
1089
|
+
});
|
|
832
1090
|
tools.push({
|
|
833
1091
|
name: "finalize_direct_session",
|
|
834
1092
|
description: "Finalize a Direct session: capture after snapshot, generate diff/summary/change artifacts, mark session as finalized. Must be called before audit_session.",
|
|
@@ -926,13 +1184,28 @@ export function getToolCatalogSnapshot() {
|
|
|
926
1184
|
const config = getConfig();
|
|
927
1185
|
return buildToolCatalogSnapshot(tools, resolveToolProfile(config.toolProfile));
|
|
928
1186
|
}
|
|
929
|
-
// ──
|
|
930
|
-
|
|
1187
|
+
// ── Dispatch map ─────────────────────────────────────────────────
|
|
1188
|
+
/**
|
|
1189
|
+
* Combined dispatch map assembled from all domain handler maps.
|
|
1190
|
+
* run_task is conditionally added when enableRunTaskTool is true,
|
|
1191
|
+
* mirroring the conditional registration in getToolDefs().
|
|
1192
|
+
*/
|
|
1193
|
+
function buildDispatchMap() {
|
|
931
1194
|
const config = getConfig();
|
|
932
|
-
|
|
933
|
-
|
|
1195
|
+
const map = {
|
|
1196
|
+
...coreHandlers,
|
|
1197
|
+
...goalHandlers,
|
|
1198
|
+
...directHandlers,
|
|
1199
|
+
...releaseHandlers,
|
|
1200
|
+
...diagnosticHandlers,
|
|
1201
|
+
};
|
|
1202
|
+
if (config.enableRunTaskTool === true) {
|
|
1203
|
+
map.run_task = runTaskHandler;
|
|
934
1204
|
}
|
|
1205
|
+
return map;
|
|
935
1206
|
}
|
|
1207
|
+
const dispatchMap = buildDispatchMap();
|
|
1208
|
+
// ── Request handler ───────────────────────────────────────────────
|
|
936
1209
|
export async function handleToolCall(name, args) {
|
|
937
1210
|
const startTime = Date.now();
|
|
938
1211
|
const taskId = args?.task_id ? String(args.task_id) : args?.session_id ? String(args.session_id) : undefined;
|
|
@@ -948,362 +1221,11 @@ export async function handleToolCall(name, args) {
|
|
|
948
1221
|
}
|
|
949
1222
|
}
|
|
950
1223
|
async function handleToolCallInternal(name, args) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
title: String(args?.title ?? ""),
|
|
955
|
-
content: args?.content !== undefined ? String(args.content) : "",
|
|
956
|
-
plan_ref: args?.plan_ref ? String(args.plan_ref) : undefined,
|
|
957
|
-
}));
|
|
958
|
-
}
|
|
959
|
-
case "get_plan": {
|
|
960
|
-
return toResult(getPlan({ plan_id: String(args?.plan_id ?? "") }));
|
|
961
|
-
}
|
|
962
|
-
case "create_task": {
|
|
963
|
-
return toResult(createTask({
|
|
964
|
-
plan_id: args?.plan_id ? String(args.plan_id) : undefined,
|
|
965
|
-
inline_plan: args?.inline_plan ? String(args.inline_plan) : undefined,
|
|
966
|
-
plan_title: args?.plan_title ? String(args.plan_title) : undefined,
|
|
967
|
-
template: args?.template ? String(args.template) : undefined,
|
|
968
|
-
goal: args?.goal ? String(args.goal) : undefined,
|
|
969
|
-
source_task_id: args?.source_task_id ? String(args.source_task_id) : undefined,
|
|
970
|
-
agent: String(args?.agent ?? ""),
|
|
971
|
-
repo_path: args?.repo_path ? String(args.repo_path) : undefined,
|
|
972
|
-
test_command: args?.test_command ? String(args.test_command) : undefined,
|
|
973
|
-
verify_commands: Array.isArray(args?.verify_commands)
|
|
974
|
-
? args.verify_commands.map((command) => String(command))
|
|
975
|
-
: undefined,
|
|
976
|
-
timeout_seconds: args?.timeout_seconds !== undefined
|
|
977
|
-
? Number(args.timeout_seconds)
|
|
978
|
-
: undefined,
|
|
979
|
-
execution_mode: args?.execution_mode === "assess_only" ? "assess_only" : "execute",
|
|
980
|
-
assessment_id: args?.assessment_id ? String(args.assessment_id) : undefined,
|
|
981
|
-
}));
|
|
982
|
-
}
|
|
983
|
-
case "get_task_status": {
|
|
984
|
-
return toResult(getTaskStatus(String(args?.task_id ?? "")));
|
|
985
|
-
}
|
|
986
|
-
case "get_result": {
|
|
987
|
-
return toResult(getResult(String(args?.task_id ?? "")));
|
|
988
|
-
}
|
|
989
|
-
case "get_result_json": {
|
|
990
|
-
return toResult(getResultJson(String(args?.task_id ?? "")));
|
|
991
|
-
}
|
|
992
|
-
case "get_diff": {
|
|
993
|
-
return toResult(getDiff(String(args?.task_id ?? "")));
|
|
994
|
-
}
|
|
995
|
-
case "get_test_log": {
|
|
996
|
-
return toResult(getTestLog(String(args?.task_id ?? "")));
|
|
997
|
-
}
|
|
998
|
-
case "list_workspace": {
|
|
999
|
-
return toResult(listWorkspace(args?.path ? String(args.path) : undefined));
|
|
1000
|
-
}
|
|
1001
|
-
case "read_workspace_file": {
|
|
1002
|
-
const sessionId = args?.session_id ? String(args.session_id) : undefined;
|
|
1003
|
-
return toResult(readWorkspaceFile({
|
|
1004
|
-
path: String(args?.path ?? ""),
|
|
1005
|
-
session_id: sessionId,
|
|
1006
|
-
}));
|
|
1007
|
-
}
|
|
1008
|
-
case "list_tasks": {
|
|
1009
|
-
return toResult(listTasks({
|
|
1010
|
-
status: args?.status ? String(args.status) : undefined,
|
|
1011
|
-
repo_path: args?.repo_path ? String(args.repo_path) : undefined,
|
|
1012
|
-
active_only: args?.active_only !== undefined ? Boolean(args.active_only) : undefined,
|
|
1013
|
-
limit: args?.limit ? Number(args.limit) : undefined,
|
|
1014
|
-
}));
|
|
1015
|
-
}
|
|
1016
|
-
case "list_agents": {
|
|
1017
|
-
return toResult(listAgents());
|
|
1018
|
-
}
|
|
1019
|
-
case "health_check": {
|
|
1020
|
-
return toResult(healthCheck(getToolCatalogSnapshot(), {
|
|
1021
|
-
detail: args?.detail === "self_diagnostic" ? "self_diagnostic" : "standard",
|
|
1022
|
-
}));
|
|
1023
|
-
}
|
|
1024
|
-
case "cancel_task": {
|
|
1025
|
-
return toResult(cancelTask(String(args?.task_id ?? "")));
|
|
1026
|
-
}
|
|
1027
|
-
case "kill_task": {
|
|
1028
|
-
return toResult(killTask(String(args?.task_id ?? "")));
|
|
1029
|
-
}
|
|
1030
|
-
case "retry_task": {
|
|
1031
|
-
return toResult(retryTask(String(args?.task_id ?? "")));
|
|
1032
|
-
}
|
|
1033
|
-
case "get_task_stdout_tail": {
|
|
1034
|
-
return toResult(getTaskStdoutTail(String(args?.task_id ?? ""), args?.lines ? Number(args.lines) : undefined));
|
|
1035
|
-
}
|
|
1036
|
-
case "get_task_log_tail": {
|
|
1037
|
-
return toResult(getTaskLogTail(String(args?.task_id ?? ""), args?.file || "stdout", {
|
|
1038
|
-
lines: args?.lines ? Number(args.lines) : undefined,
|
|
1039
|
-
redact: args?.redact !== undefined ? Boolean(args.redact) : undefined,
|
|
1040
|
-
}));
|
|
1041
|
-
}
|
|
1042
|
-
case "get_task_progress": {
|
|
1043
|
-
return toResult(getTaskProgress(String(args?.task_id ?? "")));
|
|
1044
|
-
}
|
|
1045
|
-
case "wait_for_task": {
|
|
1046
|
-
const waitSeconds = normalizeWaitSeconds(args);
|
|
1047
|
-
return toResult(await waitForTask(String(args?.task_id ?? ""), waitSeconds));
|
|
1048
|
-
}
|
|
1049
|
-
case "get_task_summary": {
|
|
1050
|
-
return toResult(getTaskSummary(String(args?.task_id ?? ""), {
|
|
1051
|
-
view: normalizeSummaryView(args?.view),
|
|
1052
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1053
|
-
}));
|
|
1054
|
-
}
|
|
1055
|
-
case "audit_task": {
|
|
1056
|
-
return toResult(auditTask(String(args?.task_id ?? "")));
|
|
1057
|
-
}
|
|
1058
|
-
case "safe_status": {
|
|
1059
|
-
return toResult(safeStatus(String(args?.task_id ?? "")));
|
|
1060
|
-
}
|
|
1061
|
-
case "safe_result": {
|
|
1062
|
-
return toResult(safeResult(String(args?.task_id ?? ""), {
|
|
1063
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1064
|
-
}));
|
|
1065
|
-
}
|
|
1066
|
-
case "safe_audit": {
|
|
1067
|
-
return toResult(safeAudit(String(args?.task_id ?? ""), {
|
|
1068
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1069
|
-
}));
|
|
1070
|
-
}
|
|
1071
|
-
case "safe_test_summary": {
|
|
1072
|
-
return toResult(safeTestSummary(String(args?.task_id ?? "")));
|
|
1073
|
-
}
|
|
1074
|
-
case "safe_diff_summary": {
|
|
1075
|
-
return toResult(safeDiffSummary(String(args?.task_id ?? ""), {
|
|
1076
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1077
|
-
}));
|
|
1078
|
-
}
|
|
1079
|
-
case "diagnose_task": {
|
|
1080
|
-
return toResult(diagnoseTask({
|
|
1081
|
-
task_id: String(args?.task_id ?? ""),
|
|
1082
|
-
include_logs: args?.include_logs !== undefined ? Boolean(args.include_logs) : undefined,
|
|
1083
|
-
}));
|
|
1084
|
-
}
|
|
1085
|
-
case "reconcile_tasks": {
|
|
1086
|
-
return toResult(reconcileTasks({
|
|
1087
|
-
mode: args?.mode === "safe_fix" ? "safe_fix" : "report_only",
|
|
1088
|
-
max_age_minutes: args?.max_age_minutes !== undefined ? Number(args.max_age_minutes) : undefined,
|
|
1089
|
-
include_done_candidates: args?.include_done_candidates !== undefined ? Boolean(args.include_done_candidates) : undefined,
|
|
1090
|
-
}));
|
|
1091
|
-
}
|
|
1092
|
-
case "discover_tools": {
|
|
1093
|
-
const profile = args?.profile === "full" || args?.profile === "chatgpt_core" || args?.profile === "chatgpt_direct" || args?.profile === "chatgpt_search"
|
|
1094
|
-
? args.profile : undefined;
|
|
1095
|
-
const mode = args?.mode === "delegate" || args?.mode === "direct" || args?.mode === "audit" || args?.mode === "release" || args?.mode === "diagnostic"
|
|
1096
|
-
? args.mode : undefined;
|
|
1097
|
-
const riskCeiling = ["readonly", "workspace_read_sensitive", "workspace_write", "command", "release", "credential_sensitive"]
|
|
1098
|
-
.includes(String(args?.riskCeiling ?? "")) ? String(args?.riskCeiling) : undefined;
|
|
1099
|
-
return toResult(discoverTools({
|
|
1100
|
-
query: String(args?.query ?? ""),
|
|
1101
|
-
profile,
|
|
1102
|
-
mode,
|
|
1103
|
-
maxResults: args?.maxResults !== undefined ? Number(args.maxResults) : undefined,
|
|
1104
|
-
riskCeiling,
|
|
1105
|
-
includeHighRisk: args?.includeHighRisk !== undefined ? Boolean(args.includeHighRisk) : undefined,
|
|
1106
|
-
}, getToolDefs()));
|
|
1107
|
-
}
|
|
1108
|
-
case "explain_tool": {
|
|
1109
|
-
return toResult(explainTool({
|
|
1110
|
-
name: String(args?.name ?? ""),
|
|
1111
|
-
includeSchema: args?.includeSchema !== undefined ? Boolean(args.includeSchema) : undefined,
|
|
1112
|
-
}, getToolDefs()));
|
|
1113
|
-
}
|
|
1114
|
-
case "invoke_discovered_tool": {
|
|
1115
|
-
const profile = resolveToolProfile(getConfig().toolProfile);
|
|
1116
|
-
const result = await invokeDiscoveredTool({
|
|
1117
|
-
toolName: String(args?.toolName ?? ""),
|
|
1118
|
-
arguments: (args?.arguments && typeof args.arguments === "object" ? args.arguments : {}),
|
|
1119
|
-
discoveryToken: String(args?.discoveryToken ?? ""),
|
|
1120
|
-
assessmentId: args?.assessmentId ? String(args.assessmentId) : undefined,
|
|
1121
|
-
}, {
|
|
1122
|
-
tools: getToolDefs(),
|
|
1123
|
-
profile,
|
|
1124
|
-
dispatch: async (name, dispatchArgs) => {
|
|
1125
|
-
return handleToolCall(name, dispatchArgs);
|
|
1126
|
-
},
|
|
1127
|
-
});
|
|
1128
|
-
return toResult(result);
|
|
1129
|
-
}
|
|
1130
|
-
case "run_task": {
|
|
1131
|
-
const config = getConfig();
|
|
1132
|
-
if (config.enableRunTaskTool !== true) {
|
|
1133
|
-
throw new Error("run_task is disabled. Set enableRunTaskTool: true in config to enable. Prefer using the local watcher (npm run watch).");
|
|
1134
|
-
}
|
|
1135
|
-
const taskId = String(args?.task_id ?? "");
|
|
1136
|
-
const result = await runTask(taskId);
|
|
1137
|
-
return toResult(result);
|
|
1138
|
-
}
|
|
1139
|
-
case "create_direct_session": {
|
|
1140
|
-
guardDirectProfileEnabled();
|
|
1141
|
-
return toResult(createDirectSession({
|
|
1142
|
-
repo_path: String(args?.repo_path ?? ""),
|
|
1143
|
-
title: args?.title ? String(args.title) : undefined,
|
|
1144
|
-
}));
|
|
1145
|
-
}
|
|
1146
|
-
case "search_workspace": {
|
|
1147
|
-
guardDirectProfileEnabled();
|
|
1148
|
-
return toResult(searchWorkspace({
|
|
1149
|
-
session_id: String(args?.session_id ?? ""),
|
|
1150
|
-
query: String(args?.query ?? ""),
|
|
1151
|
-
max_results: args?.max_results ? Number(args.max_results) : undefined,
|
|
1152
|
-
case_sensitive: args?.case_sensitive !== undefined ? Boolean(args.case_sensitive) : undefined,
|
|
1153
|
-
max_preview_chars: args?.max_preview_chars ? Number(args.max_preview_chars) : undefined,
|
|
1154
|
-
include_globs: Array.isArray(args?.include_globs) ? args.include_globs.map(String) : undefined,
|
|
1155
|
-
}));
|
|
1156
|
-
}
|
|
1157
|
-
case "apply_patch": {
|
|
1158
|
-
guardDirectProfileEnabled();
|
|
1159
|
-
return toResult(applyPatch({
|
|
1160
|
-
session_id: String(args?.session_id ?? ""),
|
|
1161
|
-
path: String(args?.path ?? ""),
|
|
1162
|
-
expected_sha256: String(args?.expected_sha256 ?? ""),
|
|
1163
|
-
operations: Array.isArray(args?.operations) ? args.operations : [],
|
|
1164
|
-
}));
|
|
1165
|
-
}
|
|
1166
|
-
case "run_verification": {
|
|
1167
|
-
guardDirectProfileEnabled();
|
|
1168
|
-
return toResult(await runVerification({
|
|
1169
|
-
session_id: String(args?.session_id ?? ""),
|
|
1170
|
-
command: String(args?.command ?? ""),
|
|
1171
|
-
timeout_seconds: args?.timeout_seconds ? Number(args.timeout_seconds) : undefined,
|
|
1172
|
-
}));
|
|
1173
|
-
}
|
|
1174
|
-
case "finalize_direct_session": {
|
|
1175
|
-
guardDirectProfileEnabled();
|
|
1176
|
-
return toResult(finalizeDirectSession({
|
|
1177
|
-
session_id: String(args?.session_id ?? ""),
|
|
1178
|
-
}));
|
|
1179
|
-
}
|
|
1180
|
-
case "audit_session": {
|
|
1181
|
-
guardDirectProfileEnabled();
|
|
1182
|
-
return toResult(auditSession({
|
|
1183
|
-
session_id: String(args?.session_id ?? ""),
|
|
1184
|
-
}));
|
|
1185
|
-
}
|
|
1186
|
-
case "safe_direct_summary": {
|
|
1187
|
-
guardDirectProfileEnabled();
|
|
1188
|
-
return toResult(safeDirectSummary(String(args?.session_id ?? ""), {
|
|
1189
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1190
|
-
}));
|
|
1191
|
-
}
|
|
1192
|
-
case "safe_finalize_direct_session": {
|
|
1193
|
-
guardDirectProfileEnabled();
|
|
1194
|
-
return toResult(safeFinalizeDirectSession(String(args?.session_id ?? ""), {
|
|
1195
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1196
|
-
}));
|
|
1197
|
-
}
|
|
1198
|
-
case "safe_audit_direct_session": {
|
|
1199
|
-
guardDirectProfileEnabled();
|
|
1200
|
-
return toResult(safeAuditDirectSession(String(args?.session_id ?? ""), {
|
|
1201
|
-
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
1202
|
-
}));
|
|
1203
|
-
}
|
|
1204
|
-
case "sync_file": {
|
|
1205
|
-
guardDirectProfileEnabled();
|
|
1206
|
-
return toResult(syncFile(String(args?.session_id ?? ""), String(args?.source_path ?? ""), String(args?.target_path ?? ""), {
|
|
1207
|
-
expected_source_sha256: args?.expected_source_sha256 ? String(args.expected_source_sha256) : undefined,
|
|
1208
|
-
expected_target_sha256: args?.expected_target_sha256 ? String(args.expected_target_sha256) : undefined,
|
|
1209
|
-
}));
|
|
1210
|
-
}
|
|
1211
|
-
case "create_goal": {
|
|
1212
|
-
return toResult(createGoal(String(args?.repo_path ?? ""), String(args?.title ?? ""), String(args?.goal_description ?? "")));
|
|
1213
|
-
}
|
|
1214
|
-
case "list_goals": {
|
|
1215
|
-
return toResult({ goals: listGoals() });
|
|
1216
|
-
}
|
|
1217
|
-
case "read_goal": {
|
|
1218
|
-
return toResult(readGoal(String(args?.goal_id ?? "")));
|
|
1219
|
-
}
|
|
1220
|
-
case "create_subgoal_task": {
|
|
1221
|
-
return toResult(createSubgoalTask({
|
|
1222
|
-
goal_id: String(args?.goal_id ?? ""),
|
|
1223
|
-
subgoal_title: String(args?.subgoal_title ?? ""),
|
|
1224
|
-
depends_on: Array.isArray(args?.depends_on) ? args.depends_on.map(String) : undefined,
|
|
1225
|
-
plan_id: args?.plan_id ? String(args.plan_id) : undefined,
|
|
1226
|
-
inline_plan: args?.inline_plan ? String(args.inline_plan) : undefined,
|
|
1227
|
-
plan_title: args?.plan_title ? String(args.plan_title) : undefined,
|
|
1228
|
-
template: args?.template ? String(args.template) : undefined,
|
|
1229
|
-
goal: args?.goal ? String(args.goal) : undefined,
|
|
1230
|
-
agent: args?.agent ? String(args.agent) : undefined,
|
|
1231
|
-
repo_path: String(args?.repo_path ?? ""),
|
|
1232
|
-
test_command: args?.test_command ? String(args.test_command) : undefined,
|
|
1233
|
-
verify_commands: Array.isArray(args?.verify_commands) ? args.verify_commands.map(String) : undefined,
|
|
1234
|
-
timeout_seconds: args?.timeout_seconds ? Number(args.timeout_seconds) : undefined,
|
|
1235
|
-
scope: Array.isArray(args?.scope) ? args.scope.map(String) : undefined,
|
|
1236
|
-
forbidden: Array.isArray(args?.forbidden) ? args.forbidden.map(String) : undefined,
|
|
1237
|
-
verification: Array.isArray(args?.verification) ? args.verification.map(String) : undefined,
|
|
1238
|
-
done_evidence: Array.isArray(args?.done_evidence) ? args.done_evidence.map(String) : undefined,
|
|
1239
|
-
isolate_worktree: args?.isolate_worktree === undefined ? undefined : Boolean(args.isolate_worktree),
|
|
1240
|
-
}));
|
|
1241
|
-
}
|
|
1242
|
-
case "accept_subgoal": {
|
|
1243
|
-
return toResult(acceptSubgoal(String(args?.goal_id ?? ""), String(args?.subgoal_id ?? "")));
|
|
1244
|
-
}
|
|
1245
|
-
case "reject_subgoal": {
|
|
1246
|
-
return toResult(rejectSubgoal(String(args?.goal_id ?? ""), String(args?.subgoal_id ?? ""), String(args?.reason ?? "")));
|
|
1247
|
-
}
|
|
1248
|
-
case "suggest_next_subgoal": {
|
|
1249
|
-
const goalStatus = readGoalStatus(String(args?.goal_id ?? ""));
|
|
1250
|
-
return toResult(suggestNextSubgoal(goalStatus));
|
|
1251
|
-
}
|
|
1252
|
-
case "summarize_goal_progress": {
|
|
1253
|
-
return toResult(summarizeGoalProgress(String(args?.goal_id ?? "")));
|
|
1254
|
-
}
|
|
1255
|
-
case "export_handoff": {
|
|
1256
|
-
const goalId = String(args?.goal_id ?? "");
|
|
1257
|
-
const goalStatus = readGoalStatus(goalId);
|
|
1258
|
-
return toResult(exportHandoff(goalId, goalStatus));
|
|
1259
|
-
}
|
|
1260
|
-
case "check_release_gate": {
|
|
1261
|
-
return toResult(await checkReleaseGate({
|
|
1262
|
-
repo_path: String(args?.repo_path ?? ""),
|
|
1263
|
-
target_stage: String(args?.target_stage ?? "local_ready"),
|
|
1264
|
-
package_name: args?.package_name ? String(args.package_name) : undefined,
|
|
1265
|
-
version: args?.version ? String(args.version) : undefined,
|
|
1266
|
-
github_repo: args?.github_repo ? String(args.github_repo) : undefined,
|
|
1267
|
-
branch: args?.branch ? String(args.branch) : undefined,
|
|
1268
|
-
}));
|
|
1269
|
-
}
|
|
1270
|
-
case "merge_worktree": {
|
|
1271
|
-
return toResult(mergeWorktreeTool({
|
|
1272
|
-
worktree_id: String(args?.worktree_id ?? ""),
|
|
1273
|
-
repo_path: String(args?.repo_path ?? ""),
|
|
1274
|
-
}));
|
|
1275
|
-
}
|
|
1276
|
-
case "discard_worktree": {
|
|
1277
|
-
return toResult(discardWorktreeTool({
|
|
1278
|
-
worktree_id: String(args?.worktree_id ?? ""),
|
|
1279
|
-
repo_path: String(args?.repo_path ?? ""),
|
|
1280
|
-
}));
|
|
1281
|
-
}
|
|
1282
|
-
default:
|
|
1283
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
1224
|
+
const handler = dispatchMap[name];
|
|
1225
|
+
if (!handler) {
|
|
1226
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
1284
1227
|
}
|
|
1285
|
-
|
|
1286
|
-
function normalizeWaitSeconds(args) {
|
|
1287
|
-
const legacy = args?.wait_seconds;
|
|
1288
|
-
const preferred = args?.timeout_seconds;
|
|
1289
|
-
if (legacy !== undefined && preferred !== undefined && Number(legacy) !== Number(preferred)) {
|
|
1290
|
-
throw new Error("wait_seconds and timeout_seconds must match when both are supplied.");
|
|
1291
|
-
}
|
|
1292
|
-
const value = preferred ?? legacy;
|
|
1293
|
-
return value === undefined ? undefined : Number(value);
|
|
1294
|
-
}
|
|
1295
|
-
function normalizeSummaryView(value) {
|
|
1296
|
-
if (value === undefined)
|
|
1297
|
-
return "standard";
|
|
1298
|
-
if (value !== "compact" && value !== "standard") {
|
|
1299
|
-
throw new Error('view must be "compact" or "standard".');
|
|
1300
|
-
}
|
|
1301
|
-
return value;
|
|
1302
|
-
}
|
|
1303
|
-
function toResult(data) {
|
|
1304
|
-
return {
|
|
1305
|
-
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
1306
|
-
};
|
|
1228
|
+
return handler(args);
|
|
1307
1229
|
}
|
|
1308
1230
|
// ── Register on MCP Server ────────────────────────────────────────
|
|
1309
1231
|
export function registerTools(server) {
|
|
@@ -1312,6 +1234,15 @@ export function registerTools(server) {
|
|
|
1312
1234
|
// tools/list and tools/call when the profile is reconfigured at runtime.
|
|
1313
1235
|
const activeTools = getToolDefs();
|
|
1314
1236
|
const activeNames = new Set(activeTools.map((tool) => tool.name));
|
|
1237
|
+
// Verify every registered tool has a dispatch handler.
|
|
1238
|
+
// The dispatch map may contain extra handlers for tools exposed under
|
|
1239
|
+
// other profiles (e.g. get_plan is only in the "full" profile), so we
|
|
1240
|
+
// only check the subset direction: every active tool must have a handler.
|
|
1241
|
+
for (const tool of activeTools) {
|
|
1242
|
+
if (!dispatchMap[tool.name]) {
|
|
1243
|
+
throw new Error(`Dispatch map is missing handler for registered tool "${tool.name}".`);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1315
1246
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
1316
1247
|
const catalog = getLastToolCatalogSnapshot();
|
|
1317
1248
|
return {
|