patchwarden 0.4.0 → 0.6.0
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/PatchWarden.cmd +51 -0
- package/README.en.md +1022 -0
- package/README.md +897 -358
- package/dist/assessments/agentAssessor.d.ts +15 -0
- package/dist/assessments/agentAssessor.js +293 -0
- package/dist/assessments/assessmentStore.d.ts +133 -0
- package/dist/assessments/assessmentStore.js +238 -0
- package/dist/assessments/confirmCli.d.ts +9 -0
- package/dist/assessments/confirmCli.js +26 -0
- package/dist/config.d.ts +22 -1
- package/dist/config.js +156 -3
- package/dist/direct/directAudit.d.ts +23 -0
- package/dist/direct/directAudit.js +309 -0
- package/dist/direct/directGuards.d.ts +20 -0
- package/dist/direct/directGuards.js +137 -0
- package/dist/direct/directPatch.d.ts +17 -0
- package/dist/direct/directPatch.js +113 -0
- package/dist/direct/directSessionStore.d.ts +63 -0
- package/dist/direct/directSessionStore.js +192 -0
- package/dist/direct/directVerification.d.ts +12 -0
- package/dist/direct/directVerification.js +96 -0
- package/dist/doctor.js +73 -5
- package/dist/runner/agentInvocation.d.ts +23 -0
- package/dist/runner/agentInvocation.js +106 -0
- package/dist/runner/changeCapture.d.ts +29 -0
- package/dist/runner/changeCapture.js +107 -5
- package/dist/runner/runTask.js +70 -44
- package/dist/runner/simpleProcess.d.ts +21 -0
- package/dist/runner/simpleProcess.js +206 -0
- package/dist/runner/watch.js +17 -2
- package/dist/security/commandGuard.d.ts +2 -1
- package/dist/security/commandGuard.js +25 -3
- package/dist/security/riskEngine.d.ts +27 -0
- package/dist/security/riskEngine.js +118 -0
- package/dist/security/runtimeGuard.d.ts +6 -0
- package/dist/security/runtimeGuard.js +28 -0
- package/dist/smoke-test.js +1353 -7
- package/dist/tools/applyPatch.d.ts +16 -0
- package/dist/tools/applyPatch.js +41 -0
- package/dist/tools/auditSession.d.ts +5 -0
- package/dist/tools/auditSession.js +12 -0
- package/dist/tools/auditTask.d.ts +7 -0
- package/dist/tools/auditTask.js +94 -2
- package/dist/tools/createDirectSession.d.ts +14 -0
- package/dist/tools/createDirectSession.js +54 -0
- package/dist/tools/createTask.d.ts +48 -1
- package/dist/tools/createTask.js +298 -47
- package/dist/tools/finalizeDirectSession.d.ts +19 -0
- package/dist/tools/finalizeDirectSession.js +84 -0
- package/dist/tools/getTaskSummary.d.ts +47 -0
- package/dist/tools/getTaskSummary.js +64 -1
- package/dist/tools/healthCheck.d.ts +22 -12
- package/dist/tools/healthCheck.js +23 -6
- package/dist/tools/readWorkspaceFile.d.ts +7 -1
- package/dist/tools/readWorkspaceFile.js +48 -2
- package/dist/tools/registry.js +217 -19
- package/dist/tools/runVerification.d.ts +16 -0
- package/dist/tools/runVerification.js +32 -0
- package/dist/tools/savePlan.d.ts +1 -0
- package/dist/tools/savePlan.js +38 -7
- package/dist/tools/searchWorkspace.d.ts +19 -0
- package/dist/tools/searchWorkspace.js +205 -0
- package/dist/tools/taskTemplates.js +2 -1
- package/dist/tools/toolCatalog.d.ts +3 -2
- package/dist/tools/toolCatalog.js +32 -5
- package/dist/tools/waitForTask.d.ts +2 -2
- package/dist/tools/waitForTask.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/docs/chatgpt-usage.md +101 -0
- package/docs/release-checklist.md +14 -0
- package/docs/release-v0.6.0.md +71 -0
- package/examples/config.example.json +5 -0
- package/examples/openai-tunnel/README.md +11 -4
- package/examples/openai-tunnel/chatgpt-test-prompt.md +18 -14
- package/examples/openai-tunnel/tunnel-client.example.yaml +8 -0
- package/package.json +12 -8
- package/scripts/brand-check.js +58 -12
- package/scripts/control-smoke.js +206 -0
- package/scripts/launchers/Check-PatchWarden-Health.cmd +6 -0
- package/scripts/launchers/Reset-PatchWarden-Tunnel-Key.cmd +6 -0
- package/scripts/launchers/Restart-PatchWarden.cmd +6 -0
- package/scripts/launchers/Start-PatchWarden-Direct-Tunnel.cmd +7 -0
- package/scripts/launchers/Start-PatchWarden-Tunnel.cmd +7 -0
- package/scripts/lifecycle-smoke.js +66 -6
- package/scripts/manage-patchwarden.ps1 +639 -0
- package/scripts/mcp-manifest-check.js +100 -58
- package/scripts/mcp-smoke.js +157 -2
- package/scripts/pack-clean.js +3 -4
- package/scripts/package-manifest-check.js +78 -0
- package/scripts/patchwarden-mcp-direct.cmd +7 -0
- package/scripts/patchwarden-mcp-stdio.cmd +1 -1
- package/scripts/restart-patchwarden.ps1 +5 -4
- package/scripts/start-patchwarden-tunnel.ps1 +261 -30
- package/scripts/tunnel-supervisor-smoke.js +36 -4
- package/scripts/watcher-supervisor-smoke.js +10 -6
- package/src/assessments/agentAssessor.ts +324 -0
- package/src/assessments/assessmentStore.ts +426 -0
- package/src/assessments/confirmCli.ts +29 -0
- package/src/config.ts +178 -4
- package/src/direct/directAudit.ts +400 -0
- package/src/direct/directGuards.ts +279 -0
- package/src/direct/directPatch.ts +258 -0
- package/src/direct/directSessionStore.ts +345 -0
- package/src/direct/directVerification.ts +138 -0
- package/src/doctor.ts +103 -7
- package/src/runner/agentInvocation.ts +125 -0
- package/src/runner/changeCapture.ts +140 -5
- package/src/runner/runTask.ts +61 -43
- package/src/runner/simpleProcess.ts +223 -0
- package/src/runner/watch.ts +18 -2
- package/src/security/commandGuard.ts +46 -4
- package/src/security/riskEngine.ts +160 -0
- package/src/security/runtimeGuard.ts +41 -0
- package/src/smoke-test.ts +1291 -4
- package/src/tools/applyPatch.ts +86 -0
- package/src/tools/auditSession.ts +28 -0
- package/src/tools/auditTask.ts +100 -2
- package/src/tools/createDirectSession.ts +113 -0
- package/src/tools/createTask.ts +405 -55
- package/src/tools/finalizeDirectSession.ts +144 -0
- package/src/tools/getTaskSummary.ts +111 -1
- package/src/tools/healthCheck.ts +23 -6
- package/src/tools/readWorkspaceFile.ts +85 -2
- package/src/tools/registry.ts +242 -19
- package/src/tools/runVerification.ts +58 -0
- package/src/tools/savePlan.ts +57 -7
- package/src/tools/searchWorkspace.ts +275 -0
- package/src/tools/taskTemplates.ts +2 -1
- package/src/tools/toolCatalog.ts +35 -6
- package/src/tools/waitForTask.ts +3 -3
- package/src/version.ts +2 -2
- package/tsconfig.json +18 -17
- package/Check-PatchWarden-Health.cmd +0 -6
- package/Reset-PatchWarden-Tunnel-Key.cmd +0 -6
- package/Restart-PatchWarden.cmd +0 -19
- package/Start-PatchWarden-Tunnel.cmd +0 -7
- package/docs/release-v0.3.0.md +0 -43
- package/docs/release-v0.4.0.md +0 -74
package/dist/tools/registry.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Used by both stdio (index.ts) and HTTP (httpServer.ts) transports.
|
|
4
4
|
*/
|
|
5
5
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
-
import { getConfig } from "../config.js";
|
|
6
|
+
import { getAllConfiguredTestCommands, getAllConfiguredDirectCommands, getConfig } from "../config.js";
|
|
7
7
|
import { savePlan } from "../tools/savePlan.js";
|
|
8
8
|
import { getPlan } from "../tools/getPlan.js";
|
|
9
9
|
import { createTask } from "../tools/createTask.js";
|
|
@@ -24,6 +24,12 @@ import { waitForTask } from "../tools/waitForTask.js";
|
|
|
24
24
|
import { errorPayload, PatchWardenError } from "../errors.js";
|
|
25
25
|
import { auditTask } from "../tools/auditTask.js";
|
|
26
26
|
import { runTask } from "../runner/runTask.js";
|
|
27
|
+
import { createDirectSession } from "../tools/createDirectSession.js";
|
|
28
|
+
import { searchWorkspace } from "../tools/searchWorkspace.js";
|
|
29
|
+
import { applyPatch } from "../tools/applyPatch.js";
|
|
30
|
+
import { runVerification } from "../tools/runVerification.js";
|
|
31
|
+
import { finalizeDirectSession } from "../tools/finalizeDirectSession.js";
|
|
32
|
+
import { auditSession } from "../tools/auditSession.js";
|
|
27
33
|
import { TASK_TEMPLATE_NAMES } from "./taskTemplates.js";
|
|
28
34
|
import { buildToolCatalogSnapshot, getLastToolCatalogSnapshot, resolveToolProfile, selectToolsForProfile, } from "./toolCatalog.js";
|
|
29
35
|
export function getToolDefs() {
|
|
@@ -32,18 +38,18 @@ export function getToolDefs() {
|
|
|
32
38
|
const agentDescription = agentNames.length > 0
|
|
33
39
|
? `Configured local agent name. Available agents: ${agentNames.map((name) => JSON.stringify(name)).join(", ")}`
|
|
34
40
|
: "Configured local agent name. No agents are currently configured.";
|
|
35
|
-
const testCommands =
|
|
41
|
+
const testCommands = getAllConfiguredTestCommands(config).sort();
|
|
36
42
|
const tools = [
|
|
37
43
|
{
|
|
38
44
|
name: "save_plan",
|
|
39
|
-
description: "Save an execution plan — ChatGPT writes the plan, PatchWarden stores it for local agent execution.",
|
|
45
|
+
description: "Save an execution plan — ChatGPT writes the plan, PatchWarden stores it for local agent execution. Supports plan_ref to load a plan file already placed inside .patchwarden/plans.",
|
|
40
46
|
inputSchema: {
|
|
41
47
|
type: "object",
|
|
42
48
|
properties: {
|
|
43
|
-
title: { type: "string", description: "Plan title" },
|
|
44
|
-
content: { type: "string", description: "Plan content in Markdown" },
|
|
49
|
+
title: { type: "string", description: "Plan title. Defaults to 'Inline plan' or 'Plan from file' when omitted." },
|
|
50
|
+
content: { type: "string", description: "Plan content in Markdown. Required unless plan_ref is provided." },
|
|
51
|
+
plan_ref: { type: "string", description: "Relative path to a plan file already inside .patchwarden/plans. When provided, the file content is loaded and title defaults to 'Plan from file' if title is empty." },
|
|
45
52
|
},
|
|
46
|
-
required: ["title", "content"],
|
|
47
53
|
},
|
|
48
54
|
},
|
|
49
55
|
{
|
|
@@ -82,7 +88,7 @@ export function getToolDefs() {
|
|
|
82
88
|
},
|
|
83
89
|
{
|
|
84
90
|
name: "create_task",
|
|
85
|
-
description: "Create a repo-scoped task from exactly one source. A stale watcher preserves the task but returns execution_blocked and directs the client to health_check; otherwise call wait_for_task until terminal.",
|
|
91
|
+
description: "Create a repo-scoped task from exactly one source. For ChatGPT, prefer the guarded inspect_only, feature_small, or fix_tests template when it fits. A stale watcher preserves the task but returns execution_blocked and directs the client to health_check; otherwise call wait_for_task until terminal. Use execution_mode=assess_only to pre-assess risk and get an assessment_id without creating a task; then invoke the returned next_tool_call using only execution_mode=execute and the full assessment_id.",
|
|
86
92
|
inputSchema: {
|
|
87
93
|
type: "object",
|
|
88
94
|
properties: {
|
|
@@ -92,7 +98,7 @@ export function getToolDefs() {
|
|
|
92
98
|
template: {
|
|
93
99
|
type: "string",
|
|
94
100
|
enum: [...TASK_TEMPLATE_NAMES],
|
|
95
|
-
description: "Built-in guarded task template. Use with goal; rollback_scope_violation also requires source_task_id.",
|
|
101
|
+
description: "Built-in guarded task template. ChatGPT should prefer inspect_only for diagnosis, feature_small for a scoped change, and fix_tests for known failing verification. Use with goal; rollback_scope_violation also requires source_task_id.",
|
|
96
102
|
},
|
|
97
103
|
goal: { type: "string", description: "Required task goal when template is supplied." },
|
|
98
104
|
source_task_id: { type: "string", description: "Required source task for rollback_scope_violation review." },
|
|
@@ -119,7 +125,7 @@ export function getToolDefs() {
|
|
|
119
125
|
type: "string",
|
|
120
126
|
...(testCommands.length > 0 ? { enum: testCommands } : {}),
|
|
121
127
|
},
|
|
122
|
-
description: "Recommended
|
|
128
|
+
description: "Recommended exact-match commands PatchWarden runs independently after the agent exits. Repository-scoped commands are re-authorized after repo_path is resolved.",
|
|
123
129
|
},
|
|
124
130
|
timeout_seconds: {
|
|
125
131
|
type: "integer",
|
|
@@ -128,8 +134,18 @@ export function getToolDefs() {
|
|
|
128
134
|
default: config.defaultTaskTimeoutSeconds,
|
|
129
135
|
description: `Total task timeout in seconds (default ${config.defaultTaskTimeoutSeconds}, max ${config.maxTaskTimeoutSeconds})`,
|
|
130
136
|
},
|
|
137
|
+
execution_mode: {
|
|
138
|
+
type: "string",
|
|
139
|
+
enum: ["assess_only", "execute"],
|
|
140
|
+
default: "execute",
|
|
141
|
+
description: "assess_only: run deterministic risk checks and return an assessment_id without creating a task. execute (default): create and queue the task. When combined with assessment_id, the task parameters are loaded from the assessment record and freshness is revalidated.",
|
|
142
|
+
},
|
|
143
|
+
assessment_id: {
|
|
144
|
+
type: "string",
|
|
145
|
+
description: "Assessment ID from a prior assess_only call. When provided with execution_mode=execute, task parameters are loaded from the assessment record and locked to it. The full 128-bit ID (32 hex chars) must be provided; short IDs are display-only.",
|
|
146
|
+
},
|
|
131
147
|
},
|
|
132
|
-
required: [
|
|
148
|
+
required: [],
|
|
133
149
|
},
|
|
134
150
|
},
|
|
135
151
|
{
|
|
@@ -202,13 +218,17 @@ export function getToolDefs() {
|
|
|
202
218
|
},
|
|
203
219
|
{
|
|
204
220
|
name: "read_workspace_file",
|
|
205
|
-
description: "Read a file within the workspace. Sensitive files (secrets, keys, tokens) are blocked.",
|
|
221
|
+
description: "Read a file within the workspace. Sensitive files (secrets, keys, tokens) are blocked. In Direct mode (with session_id), reads are scoped to the session's repo_path and return sha256.",
|
|
206
222
|
inputSchema: {
|
|
207
223
|
type: "object",
|
|
208
224
|
properties: {
|
|
209
225
|
path: {
|
|
210
226
|
type: "string",
|
|
211
|
-
description: "Relative path to a file inside the workspace",
|
|
227
|
+
description: "Relative path to a file inside the workspace or session repo",
|
|
228
|
+
},
|
|
229
|
+
session_id: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: "Optional Direct session ID. When provided, read scope is limited to the session's repo_path and sha256 is returned.",
|
|
212
232
|
},
|
|
213
233
|
},
|
|
214
234
|
required: ["path"],
|
|
@@ -333,18 +353,20 @@ export function getToolDefs() {
|
|
|
333
353
|
},
|
|
334
354
|
{
|
|
335
355
|
name: "get_task_summary",
|
|
336
|
-
description: "Return
|
|
356
|
+
description: "Return structured acceptance evidence. Use view=compact first for bounded counts and risk excerpts; use standard only when full changed-file and log-tail detail is required.",
|
|
337
357
|
inputSchema: {
|
|
338
358
|
type: "object",
|
|
339
359
|
properties: {
|
|
340
360
|
task_id: { type: "string", description: "Task ID" },
|
|
361
|
+
view: { type: "string", enum: ["compact", "standard"], default: "standard", description: "Compact returns bounded acceptance evidence; standard preserves the full legacy summary." },
|
|
362
|
+
max_items: { type: "integer", minimum: 1, maximum: 50, default: 8, description: "Maximum entries per compact evidence group." },
|
|
341
363
|
},
|
|
342
364
|
required: ["task_id"],
|
|
343
365
|
},
|
|
344
366
|
},
|
|
345
367
|
{
|
|
346
368
|
name: "audit_task",
|
|
347
|
-
description: "Independently audit a task's outputs. Verifies status, result.md, test.log, git.diff, repo_path consistency, cross-references agent claims with package.json scripts, and flags unverified release/publish claims. Writes independent-review.md to the task directory.",
|
|
369
|
+
description: "Independently audit a task's outputs. Verifies status, result.md, test.log, git.diff, repo_path consistency, cross-references agent claims with package.json scripts, and flags unverified release/publish claims. Evidence-backed failures, possible heuristic false positives, and manual-verification items are returned separately. Writes independent-review.md to the task directory.",
|
|
348
370
|
inputSchema: {
|
|
349
371
|
type: "object",
|
|
350
372
|
properties: {
|
|
@@ -354,6 +376,111 @@ export function getToolDefs() {
|
|
|
354
376
|
},
|
|
355
377
|
},
|
|
356
378
|
];
|
|
379
|
+
// Direct session tools
|
|
380
|
+
const directCommands = getAllConfiguredDirectCommands(config);
|
|
381
|
+
tools.push({
|
|
382
|
+
name: "create_direct_session",
|
|
383
|
+
description: "Create a Direct editing session for ChatGPT to apply patches directly. Requires enableDirectProfile: true in config.",
|
|
384
|
+
inputSchema: {
|
|
385
|
+
type: "object",
|
|
386
|
+
properties: {
|
|
387
|
+
repo_path: {
|
|
388
|
+
type: "string",
|
|
389
|
+
description: "Repository path inside workspaceRoot (e.g., 'my-project')",
|
|
390
|
+
},
|
|
391
|
+
title: {
|
|
392
|
+
type: "string",
|
|
393
|
+
description: "Optional title describing the session's purpose",
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
required: ["repo_path"],
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
tools.push({
|
|
400
|
+
name: "search_workspace",
|
|
401
|
+
description: "Search file contents (grep-like) within a Direct session's repo_path. Skips .git, node_modules, dist, release, and sensitive files.",
|
|
402
|
+
inputSchema: {
|
|
403
|
+
type: "object",
|
|
404
|
+
properties: {
|
|
405
|
+
session_id: { type: "string", description: "Session ID from create_direct_session" },
|
|
406
|
+
query: { type: "string", description: "Search query string" },
|
|
407
|
+
max_results: { type: "number", description: "Max results (default 20)" },
|
|
408
|
+
case_sensitive: { type: "boolean", description: "Case sensitive search (default false)" },
|
|
409
|
+
max_preview_chars: { type: "number", description: "Max preview chars per match (default 200)" },
|
|
410
|
+
include_globs: {
|
|
411
|
+
type: "array",
|
|
412
|
+
items: { type: "string" },
|
|
413
|
+
description: "Optional file name glob patterns to include (e.g., ['*.ts', '*.js'])",
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
required: ["session_id", "query"],
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
tools.push({
|
|
420
|
+
name: "apply_patch",
|
|
421
|
+
description: "Apply JSON patch operations to a file within a Direct session's repo_path. Validates expected_sha256 before applying. Supports replace_exact, insert_before, insert_after, replace_whole_file.",
|
|
422
|
+
inputSchema: {
|
|
423
|
+
type: "object",
|
|
424
|
+
properties: {
|
|
425
|
+
session_id: { type: "string", description: "Session ID" },
|
|
426
|
+
path: { type: "string", description: "Relative file path within the session repo" },
|
|
427
|
+
expected_sha256: { type: "string", description: "Expected SHA-256 hash of the current file content" },
|
|
428
|
+
operations: {
|
|
429
|
+
type: "array",
|
|
430
|
+
items: {
|
|
431
|
+
type: "object",
|
|
432
|
+
properties: {
|
|
433
|
+
type: { type: "string", enum: ["replace_exact", "insert_before", "insert_after", "replace_whole_file"] },
|
|
434
|
+
old_text: { type: "string", description: "Text to find (required for replace_exact, insert_before, insert_after)" },
|
|
435
|
+
new_text: { type: "string", description: "Replacement or insertion text" },
|
|
436
|
+
occurrence: { type: "string", enum: ["first", "all", "exactly_once"], description: "Match mode for replace_exact (default first)" },
|
|
437
|
+
},
|
|
438
|
+
required: ["type", "new_text"],
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
required: ["session_id", "path", "expected_sha256", "operations"],
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
tools.push({
|
|
446
|
+
name: "run_verification",
|
|
447
|
+
description: "Run a whitelisted verification command within a Direct session. Command must be in the Direct allowlist.",
|
|
448
|
+
inputSchema: {
|
|
449
|
+
type: "object",
|
|
450
|
+
properties: {
|
|
451
|
+
session_id: { type: "string", description: "Session ID" },
|
|
452
|
+
command: {
|
|
453
|
+
type: "string",
|
|
454
|
+
description: "Verification command to run",
|
|
455
|
+
...(directCommands.length > 0 ? { enum: directCommands } : {}),
|
|
456
|
+
},
|
|
457
|
+
timeout_seconds: { type: "number", description: "Timeout in seconds (default 120)" },
|
|
458
|
+
},
|
|
459
|
+
required: ["session_id", "command"],
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
tools.push({
|
|
463
|
+
name: "finalize_direct_session",
|
|
464
|
+
description: "Finalize a Direct session: capture after snapshot, generate diff/summary/change artifacts, mark session as finalized. Must be called before audit_session.",
|
|
465
|
+
inputSchema: {
|
|
466
|
+
type: "object",
|
|
467
|
+
properties: {
|
|
468
|
+
session_id: { type: "string", description: "Session ID to finalize" },
|
|
469
|
+
},
|
|
470
|
+
required: ["session_id"],
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
tools.push({
|
|
474
|
+
name: "audit_session",
|
|
475
|
+
description: "Independently audit a Direct session's changes. Performs 16 deterministic checks and returns pass/warn/fail decision. Requires session to be finalized first.",
|
|
476
|
+
inputSchema: {
|
|
477
|
+
type: "object",
|
|
478
|
+
properties: {
|
|
479
|
+
session_id: { type: "string", description: "Session ID to audit" },
|
|
480
|
+
},
|
|
481
|
+
required: ["session_id"],
|
|
482
|
+
},
|
|
483
|
+
});
|
|
357
484
|
// run_task: only available when explicitly enabled
|
|
358
485
|
if (config.enableRunTaskTool === true) {
|
|
359
486
|
tools.push({
|
|
@@ -369,7 +496,7 @@ export function getToolDefs() {
|
|
|
369
496
|
});
|
|
370
497
|
}
|
|
371
498
|
const profile = resolveToolProfile(config.toolProfile);
|
|
372
|
-
const selected = selectToolsForProfile(tools, profile);
|
|
499
|
+
const selected = selectToolsForProfile(tools, profile, config.enableDirectProfile);
|
|
373
500
|
buildToolCatalogSnapshot(selected, profile);
|
|
374
501
|
return selected;
|
|
375
502
|
}
|
|
@@ -379,12 +506,19 @@ export function getToolCatalogSnapshot() {
|
|
|
379
506
|
return buildToolCatalogSnapshot(tools, resolveToolProfile(config.toolProfile));
|
|
380
507
|
}
|
|
381
508
|
// ── Request handler ───────────────────────────────────────────────
|
|
509
|
+
function guardDirectProfileEnabled() {
|
|
510
|
+
const config = getConfig();
|
|
511
|
+
if (!config.enableDirectProfile) {
|
|
512
|
+
throw new PatchWardenError("direct_profile_disabled", "Direct profile is disabled by local config.", "Set enableDirectProfile: true in patchwarden.config.json to use Direct session tools.", true, { operation: "direct_tool_call" });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
382
515
|
export async function handleToolCall(name, args) {
|
|
383
516
|
switch (name) {
|
|
384
517
|
case "save_plan": {
|
|
385
518
|
return toResult(savePlan({
|
|
386
519
|
title: String(args?.title ?? ""),
|
|
387
|
-
content: String(args
|
|
520
|
+
content: args?.content !== undefined ? String(args.content) : "",
|
|
521
|
+
plan_ref: args?.plan_ref ? String(args.plan_ref) : undefined,
|
|
388
522
|
}));
|
|
389
523
|
}
|
|
390
524
|
case "get_plan": {
|
|
@@ -407,6 +541,8 @@ export async function handleToolCall(name, args) {
|
|
|
407
541
|
timeout_seconds: args?.timeout_seconds !== undefined
|
|
408
542
|
? Number(args.timeout_seconds)
|
|
409
543
|
: undefined,
|
|
544
|
+
execution_mode: args?.execution_mode === "assess_only" ? "assess_only" : "execute",
|
|
545
|
+
assessment_id: args?.assessment_id ? String(args.assessment_id) : undefined,
|
|
410
546
|
}));
|
|
411
547
|
}
|
|
412
548
|
case "get_task_status": {
|
|
@@ -428,7 +564,11 @@ export async function handleToolCall(name, args) {
|
|
|
428
564
|
return toResult(listWorkspace(args?.path ? String(args.path) : undefined));
|
|
429
565
|
}
|
|
430
566
|
case "read_workspace_file": {
|
|
431
|
-
|
|
567
|
+
const sessionId = args?.session_id ? String(args.session_id) : undefined;
|
|
568
|
+
return toResult(readWorkspaceFile({
|
|
569
|
+
path: String(args?.path ?? ""),
|
|
570
|
+
session_id: sessionId,
|
|
571
|
+
}));
|
|
432
572
|
}
|
|
433
573
|
case "list_tasks": {
|
|
434
574
|
return toResult(listTasks({
|
|
@@ -472,7 +612,10 @@ export async function handleToolCall(name, args) {
|
|
|
472
612
|
return toResult(await waitForTask(String(args?.task_id ?? ""), waitSeconds));
|
|
473
613
|
}
|
|
474
614
|
case "get_task_summary": {
|
|
475
|
-
return toResult(getTaskSummary(String(args?.task_id ?? "")
|
|
615
|
+
return toResult(getTaskSummary(String(args?.task_id ?? ""), {
|
|
616
|
+
view: normalizeSummaryView(args?.view),
|
|
617
|
+
max_items: args?.max_items !== undefined ? Number(args.max_items) : undefined,
|
|
618
|
+
}));
|
|
476
619
|
}
|
|
477
620
|
case "audit_task": {
|
|
478
621
|
return toResult(auditTask(String(args?.task_id ?? "")));
|
|
@@ -486,6 +629,53 @@ export async function handleToolCall(name, args) {
|
|
|
486
629
|
const result = await runTask(taskId);
|
|
487
630
|
return toResult(result);
|
|
488
631
|
}
|
|
632
|
+
case "create_direct_session": {
|
|
633
|
+
guardDirectProfileEnabled();
|
|
634
|
+
return toResult(createDirectSession({
|
|
635
|
+
repo_path: String(args?.repo_path ?? ""),
|
|
636
|
+
title: args?.title ? String(args.title) : undefined,
|
|
637
|
+
}));
|
|
638
|
+
}
|
|
639
|
+
case "search_workspace": {
|
|
640
|
+
guardDirectProfileEnabled();
|
|
641
|
+
return toResult(searchWorkspace({
|
|
642
|
+
session_id: String(args?.session_id ?? ""),
|
|
643
|
+
query: String(args?.query ?? ""),
|
|
644
|
+
max_results: args?.max_results ? Number(args.max_results) : undefined,
|
|
645
|
+
case_sensitive: args?.case_sensitive !== undefined ? Boolean(args.case_sensitive) : undefined,
|
|
646
|
+
max_preview_chars: args?.max_preview_chars ? Number(args.max_preview_chars) : undefined,
|
|
647
|
+
include_globs: Array.isArray(args?.include_globs) ? args.include_globs.map(String) : undefined,
|
|
648
|
+
}));
|
|
649
|
+
}
|
|
650
|
+
case "apply_patch": {
|
|
651
|
+
guardDirectProfileEnabled();
|
|
652
|
+
return toResult(applyPatch({
|
|
653
|
+
session_id: String(args?.session_id ?? ""),
|
|
654
|
+
path: String(args?.path ?? ""),
|
|
655
|
+
expected_sha256: String(args?.expected_sha256 ?? ""),
|
|
656
|
+
operations: Array.isArray(args?.operations) ? args.operations : [],
|
|
657
|
+
}));
|
|
658
|
+
}
|
|
659
|
+
case "run_verification": {
|
|
660
|
+
guardDirectProfileEnabled();
|
|
661
|
+
return toResult(await runVerification({
|
|
662
|
+
session_id: String(args?.session_id ?? ""),
|
|
663
|
+
command: String(args?.command ?? ""),
|
|
664
|
+
timeout_seconds: args?.timeout_seconds ? Number(args.timeout_seconds) : undefined,
|
|
665
|
+
}));
|
|
666
|
+
}
|
|
667
|
+
case "finalize_direct_session": {
|
|
668
|
+
guardDirectProfileEnabled();
|
|
669
|
+
return toResult(finalizeDirectSession({
|
|
670
|
+
session_id: String(args?.session_id ?? ""),
|
|
671
|
+
}));
|
|
672
|
+
}
|
|
673
|
+
case "audit_session": {
|
|
674
|
+
guardDirectProfileEnabled();
|
|
675
|
+
return toResult(auditSession({
|
|
676
|
+
session_id: String(args?.session_id ?? ""),
|
|
677
|
+
}));
|
|
678
|
+
}
|
|
489
679
|
default:
|
|
490
680
|
throw new Error(`Unknown tool: ${name}`);
|
|
491
681
|
}
|
|
@@ -499,6 +689,14 @@ function normalizeWaitSeconds(args) {
|
|
|
499
689
|
const value = preferred ?? legacy;
|
|
500
690
|
return value === undefined ? undefined : Number(value);
|
|
501
691
|
}
|
|
692
|
+
function normalizeSummaryView(value) {
|
|
693
|
+
if (value === undefined)
|
|
694
|
+
return "standard";
|
|
695
|
+
if (value !== "compact" && value !== "standard") {
|
|
696
|
+
throw new Error('view must be "compact" or "standard".');
|
|
697
|
+
}
|
|
698
|
+
return value;
|
|
699
|
+
}
|
|
502
700
|
function toResult(data) {
|
|
503
701
|
return {
|
|
504
702
|
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
@@ -547,7 +745,7 @@ export function registerTools(server) {
|
|
|
547
745
|
arguments: { detail: "self_diagnostic" },
|
|
548
746
|
},
|
|
549
747
|
connector_refresh_steps: [
|
|
550
|
-
"1. Run
|
|
748
|
+
"1. Run PatchWarden.cmd health locally to confirm the active profile and manifest hash.",
|
|
551
749
|
"2. In ChatGPT Platform, refresh or reconnect the Connector (do not reuse an old session).",
|
|
552
750
|
"3. Open a NEW ChatGPT conversation; old conversations retain their cached tool catalog.",
|
|
553
751
|
"4. Call health_check in the new conversation and verify tool_manifest_sha256 matches the local report.",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface RunVerificationInput {
|
|
2
|
+
session_id: string;
|
|
3
|
+
command: string;
|
|
4
|
+
timeout_seconds?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RunVerificationOutput {
|
|
7
|
+
command: string;
|
|
8
|
+
exit_code: number | null;
|
|
9
|
+
passed: boolean;
|
|
10
|
+
timed_out: boolean;
|
|
11
|
+
stdout_tail: string;
|
|
12
|
+
stderr_tail: string;
|
|
13
|
+
log_path: string;
|
|
14
|
+
next_action: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runVerification(input: RunVerificationInput): Promise<RunVerificationOutput>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readDirectSession, appendDirectSessionVerificationRun, } from "../direct/directSessionStore.js";
|
|
2
|
+
import { guardDirectSessionActive } from "../direct/directGuards.js";
|
|
3
|
+
import { runDirectVerification } from "../direct/directVerification.js";
|
|
4
|
+
export async function runVerification(input) {
|
|
5
|
+
// 1. Read session and guard active
|
|
6
|
+
const session = readDirectSession(input.session_id);
|
|
7
|
+
guardDirectSessionActive(session);
|
|
8
|
+
// 2. Call runDirectVerification with command, resolvedRepoPath,
|
|
9
|
+
// sessionId, and timeoutSeconds
|
|
10
|
+
const timeoutSeconds = input.timeout_seconds ?? 120;
|
|
11
|
+
const result = await runDirectVerification({
|
|
12
|
+
command: input.command,
|
|
13
|
+
resolvedRepoPath: session.resolved_repo_path,
|
|
14
|
+
sessionId: input.session_id,
|
|
15
|
+
timeoutSeconds,
|
|
16
|
+
});
|
|
17
|
+
// 3. Append verification run to session
|
|
18
|
+
appendDirectSessionVerificationRun(input.session_id, result.run);
|
|
19
|
+
// 4. Return result
|
|
20
|
+
return {
|
|
21
|
+
command: result.run.command,
|
|
22
|
+
exit_code: result.run.exit_code,
|
|
23
|
+
passed: result.run.passed,
|
|
24
|
+
timed_out: result.run.timed_out,
|
|
25
|
+
stdout_tail: result.run.stdout_tail,
|
|
26
|
+
stderr_tail: result.run.stderr_tail,
|
|
27
|
+
log_path: result.run.log_path,
|
|
28
|
+
next_action: result.run.passed
|
|
29
|
+
? "Call finalize_direct_session to complete the session."
|
|
30
|
+
: "Review the verification output and apply_patch to fix issues.",
|
|
31
|
+
};
|
|
32
|
+
}
|
package/dist/tools/savePlan.d.ts
CHANGED
package/dist/tools/savePlan.js
CHANGED
|
@@ -1,24 +1,55 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { resolve, join } from "node:path";
|
|
1
|
+
import { mkdirSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve, join, relative } from "node:path";
|
|
3
3
|
import { getPlansDir, getConfig } from "../config.js";
|
|
4
4
|
import { guardPath } from "../security/pathGuard.js";
|
|
5
5
|
import { guardPlanContent } from "../security/planGuard.js";
|
|
6
|
+
import { PatchWardenError } from "../errors.js";
|
|
6
7
|
export function savePlan(input) {
|
|
7
8
|
const config = getConfig();
|
|
8
9
|
const plansDir = getPlansDir(config);
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
let content = input.content || "";
|
|
11
|
+
let title = input.title || "";
|
|
12
|
+
if (input.plan_ref) {
|
|
13
|
+
// 收缩 #3: plan_ref 只能读取 .patchwarden/plans 内文件,禁止任意路径
|
|
14
|
+
// plan_ref is relative to plansDir, not workspaceRoot
|
|
15
|
+
const targetPath = resolve(plansDir, input.plan_ref);
|
|
16
|
+
// Guard: must stay inside workspace and inside plansDir
|
|
17
|
+
guardPath(targetPath, config.workspaceRoot, config.plansDir);
|
|
18
|
+
const relativeToPlans = relative(plansDir, targetPath);
|
|
19
|
+
if (relativeToPlans.startsWith("..")) {
|
|
20
|
+
throw new PatchWardenError("plan_ref_outside_plans_dir", `plan_ref must point to a file inside .patchwarden/plans.`, "Use a path relative to .patchwarden/plans/.", true, { plan_ref: input.plan_ref, resolved: targetPath });
|
|
21
|
+
}
|
|
22
|
+
if (!existsSync(targetPath)) {
|
|
23
|
+
throw new PatchWardenError("plan_ref_not_found", `plan_ref file not found: "${input.plan_ref}".`, "Place the plan file under .patchwarden/plans/ first, then reference it.", true, { plan_ref: input.plan_ref });
|
|
24
|
+
}
|
|
25
|
+
content = readFileSync(targetPath, "utf-8");
|
|
26
|
+
if (!title || title.trim() === "") {
|
|
27
|
+
title = "Plan from file";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Without plan_ref, content is required
|
|
32
|
+
if (!content || content.trim() === "") {
|
|
33
|
+
throw new PatchWardenError("plan_content_required", "save_plan requires content or plan_ref.", "Pass content with the plan text, or use plan_ref to load a file from .patchwarden/plans.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Default title when empty
|
|
37
|
+
if (!title || title.trim() === "") {
|
|
38
|
+
title = "Inline plan";
|
|
39
|
+
}
|
|
40
|
+
guardPlanContent(title, content);
|
|
41
|
+
const planId = `plan_${Date.now()}_${sanitizeTitle(title)}`;
|
|
11
42
|
const planDir = resolve(plansDir, planId);
|
|
12
43
|
// Guards: plan dir & file must stay inside workspace
|
|
13
44
|
guardPath(planDir, config.workspaceRoot, config.plansDir);
|
|
14
45
|
mkdirSync(planDir, { recursive: true });
|
|
15
46
|
const planFile = join(planDir, "plan.md");
|
|
16
|
-
const header = `# ${
|
|
17
|
-
writeFileSync(planFile, header +
|
|
47
|
+
const header = `# ${title}\n\n> Plan ID: ${planId}\n> Created: ${new Date().toISOString()}\n\n`;
|
|
48
|
+
writeFileSync(planFile, header + content, "utf-8");
|
|
18
49
|
return {
|
|
19
50
|
plan_id: planId,
|
|
20
51
|
path: planFile,
|
|
21
|
-
title:
|
|
52
|
+
title: title,
|
|
22
53
|
};
|
|
23
54
|
}
|
|
24
55
|
function sanitizeTitle(title) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface SearchWorkspaceInput {
|
|
2
|
+
session_id: string;
|
|
3
|
+
query: string;
|
|
4
|
+
max_results?: number;
|
|
5
|
+
case_sensitive?: boolean;
|
|
6
|
+
max_preview_chars?: number;
|
|
7
|
+
include_globs?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface SearchMatch {
|
|
10
|
+
path: string;
|
|
11
|
+
line: number;
|
|
12
|
+
preview: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SearchWorkspaceOutput {
|
|
15
|
+
results: SearchMatch[];
|
|
16
|
+
total_matches: number;
|
|
17
|
+
truncated: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function searchWorkspace(input: SearchWorkspaceInput): SearchWorkspaceOutput;
|