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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PatchOperation } from "../direct/directPatch.js";
|
|
2
|
+
export interface ApplyPatchInput {
|
|
3
|
+
session_id: string;
|
|
4
|
+
path: string;
|
|
5
|
+
expected_sha256: string;
|
|
6
|
+
operations: PatchOperation[];
|
|
7
|
+
}
|
|
8
|
+
export interface ApplyPatchOutput {
|
|
9
|
+
path: string;
|
|
10
|
+
before_sha256: string;
|
|
11
|
+
after_sha256: string;
|
|
12
|
+
operations_applied: number;
|
|
13
|
+
bytes_changed: number;
|
|
14
|
+
next_action: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function applyPatch(input: ApplyPatchInput): ApplyPatchOutput;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getConfig } from "../config.js";
|
|
2
|
+
import { readDirectSession, appendDirectSessionOperation, } from "../direct/directSessionStore.js";
|
|
3
|
+
import { guardDirectSessionActive, guardDirectWritePath, guardDirectPatchSize, } from "../direct/directGuards.js";
|
|
4
|
+
import { applyPatchOperations, validateExpectedSha256, computeFileSha256, } from "../direct/directPatch.js";
|
|
5
|
+
export function applyPatch(input) {
|
|
6
|
+
const config = getConfig();
|
|
7
|
+
// 1. Read session and guard active (not expired, not finalized)
|
|
8
|
+
const session = readDirectSession(input.session_id);
|
|
9
|
+
guardDirectSessionActive(session);
|
|
10
|
+
// 2. Guard write path (inside repo, not sensitive, not binary,
|
|
11
|
+
// not node_modules/release/dist)
|
|
12
|
+
const resolvedPath = guardDirectWritePath(input.path, session.resolved_repo_path, config.workspaceRoot);
|
|
13
|
+
// 3. Calculate patch size and guard against directMaxPatchBytes
|
|
14
|
+
const patchBytes = JSON.stringify(input.operations).length;
|
|
15
|
+
guardDirectPatchSize(patchBytes);
|
|
16
|
+
// 4. Validate expected_sha256 matches current file hash
|
|
17
|
+
const beforeSha256 = validateExpectedSha256(resolvedPath, input.expected_sha256);
|
|
18
|
+
// 5. Apply patch operations
|
|
19
|
+
const patchResult = applyPatchOperations(resolvedPath, input.operations);
|
|
20
|
+
// Re-read the file from disk to compute the authoritative after_sha256
|
|
21
|
+
const afterSha256 = computeFileSha256(resolvedPath);
|
|
22
|
+
// 6. Append operation record to session
|
|
23
|
+
appendDirectSessionOperation(input.session_id, {
|
|
24
|
+
index: session.operations.length,
|
|
25
|
+
timestamp: new Date().toISOString(),
|
|
26
|
+
path: input.path,
|
|
27
|
+
before_sha256: beforeSha256,
|
|
28
|
+
after_sha256: afterSha256,
|
|
29
|
+
operations_applied: patchResult.operations_applied,
|
|
30
|
+
bytes_changed: patchResult.bytes_changed,
|
|
31
|
+
});
|
|
32
|
+
// 7. Return result
|
|
33
|
+
return {
|
|
34
|
+
path: input.path,
|
|
35
|
+
before_sha256: beforeSha256,
|
|
36
|
+
after_sha256: afterSha256,
|
|
37
|
+
operations_applied: patchResult.operations_applied,
|
|
38
|
+
bytes_changed: patchResult.bytes_changed,
|
|
39
|
+
next_action: "Call run_verification to test the changes, or apply_patch for more edits.",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { auditDirectSession, } from "../direct/directAudit.js";
|
|
2
|
+
import { updateDirectSession } from "../direct/directSessionStore.js";
|
|
3
|
+
// ── Main function ──────────────────────────────────────────────────
|
|
4
|
+
export function auditSession(input) {
|
|
5
|
+
const { session_id } = input;
|
|
6
|
+
// 1. Perform independent audit (16 audit checks)
|
|
7
|
+
const output = auditDirectSession(session_id);
|
|
8
|
+
// 2. Mark session as audited
|
|
9
|
+
updateDirectSession(session_id, { audited: true });
|
|
10
|
+
// 3. Return the audit output
|
|
11
|
+
return output;
|
|
12
|
+
}
|
|
@@ -13,6 +13,13 @@ export interface AuditTaskOutput {
|
|
|
13
13
|
summary: string;
|
|
14
14
|
checks: AuditCheck[];
|
|
15
15
|
risks: AuditRisk[];
|
|
16
|
+
confirmed_failures: AuditCheck[];
|
|
17
|
+
possible_false_positives: Array<{
|
|
18
|
+
check: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}>;
|
|
21
|
+
manual_verification_required: boolean;
|
|
22
|
+
manual_verification_items: string[];
|
|
16
23
|
recommended_next_actions: string[];
|
|
17
24
|
}
|
|
18
25
|
export declare function auditTask(taskId: string): AuditTaskOutput;
|
package/dist/tools/auditTask.js
CHANGED
|
@@ -55,6 +55,17 @@ export function auditTask(taskId) {
|
|
|
55
55
|
const checks = [];
|
|
56
56
|
const risks = [];
|
|
57
57
|
const actions = [];
|
|
58
|
+
const possibleFalsePositives = [];
|
|
59
|
+
const manualVerificationItems = [];
|
|
60
|
+
const addManualVerification = (item) => {
|
|
61
|
+
if (!manualVerificationItems.includes(item))
|
|
62
|
+
manualVerificationItems.push(item);
|
|
63
|
+
};
|
|
64
|
+
const addPossibleFalsePositive = (check, reason) => {
|
|
65
|
+
if (!possibleFalsePositives.some((item) => item.check === check && item.reason === reason)) {
|
|
66
|
+
possibleFalsePositives.push({ check, reason });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
58
69
|
// ── 1. Task status ──
|
|
59
70
|
const taskStatus = statusData.status || "unknown";
|
|
60
71
|
const failedStatuses = new Set(["failed", "failed_verification", "failed_scope_violation", "failed_policy_violation", "canceled"]);
|
|
@@ -63,6 +74,9 @@ export function auditTask(taskId) {
|
|
|
63
74
|
result: taskStatus === "done" ? "pass" : failedStatuses.has(taskStatus) ? "fail" : "warn",
|
|
64
75
|
detail: `Task status is "${taskStatus}".`,
|
|
65
76
|
});
|
|
77
|
+
if (taskStatus !== "done" && !failedStatuses.has(taskStatus)) {
|
|
78
|
+
addManualVerification(`Task status is "${taskStatus}"; audit evidence may be incomplete until terminal state.`);
|
|
79
|
+
}
|
|
66
80
|
// ── 2. result.md ──
|
|
67
81
|
const resultFile = join(taskDir, "result.md");
|
|
68
82
|
const hasResult = existsSync(resultFile);
|
|
@@ -85,6 +99,9 @@ export function auditTask(taskId) {
|
|
|
85
99
|
result: existsSync(verifyJsonFile) ? "pass" : "warn",
|
|
86
100
|
detail: existsSync(verifyJsonFile) ? "verify.json found." : "verify.json is missing.",
|
|
87
101
|
});
|
|
102
|
+
if (!existsSync(verifyJsonFile)) {
|
|
103
|
+
addManualVerification("verify.json is missing; determine whether independent verification was expected.");
|
|
104
|
+
}
|
|
88
105
|
if (existsSync(verifyJsonFile)) {
|
|
89
106
|
try {
|
|
90
107
|
const verify = JSON.parse(readFileSync(verifyJsonFile, "utf-8"));
|
|
@@ -106,6 +123,43 @@ export function auditTask(taskId) {
|
|
|
106
123
|
? `${outOfScope.length} out-of-scope change(s) detected.`
|
|
107
124
|
: "No out-of-scope changes recorded.",
|
|
108
125
|
});
|
|
126
|
+
const changedFilesFile = join(taskDir, "changed-files.json");
|
|
127
|
+
if (existsSync(changedFilesFile)) {
|
|
128
|
+
try {
|
|
129
|
+
const changeEvidence = JSON.parse(readFileSync(changedFilesFile, "utf-8"));
|
|
130
|
+
const hygiene = changeEvidence.artifact_hygiene;
|
|
131
|
+
if (hygiene?.counts) {
|
|
132
|
+
const trackedArtifacts = Number(hygiene.counts.tracked_build_artifacts || 0);
|
|
133
|
+
const ignoredArtifacts = Number(hygiene.counts.ignored_untracked_artifacts || 0);
|
|
134
|
+
const runtimeFiles = Number(hygiene.counts.runtime_generated_files || 0);
|
|
135
|
+
const suspicious = Number(hygiene.counts.suspicious_changes || 0);
|
|
136
|
+
checks.push({
|
|
137
|
+
name: "artifact_hygiene",
|
|
138
|
+
result: suspicious > 0 ? "warn" : "pass",
|
|
139
|
+
detail: suspicious > 0
|
|
140
|
+
? `${suspicious} generated or artifact-like change(s) are tracked or not ignored and require review.`
|
|
141
|
+
: `${ignoredArtifacts} ignored artifact change(s) and ${runtimeFiles} runtime-generated change(s) are classified separately from source risk.`,
|
|
142
|
+
});
|
|
143
|
+
if (trackedArtifacts > 0) {
|
|
144
|
+
risks.push({ severity: "medium", description: `${trackedArtifacts} tracked build artifact change(s) require intentional source-control review.` });
|
|
145
|
+
addPossibleFalsePositive("artifact_hygiene", "Tracked build outputs may be intentional release assets rather than accidental source changes.");
|
|
146
|
+
}
|
|
147
|
+
if (suspicious > 0) {
|
|
148
|
+
actions.push("Review artifact_hygiene.suspicious_changes before accepting the task; add generated paths to Git ignore rules when appropriate.");
|
|
149
|
+
addPossibleFalsePositive("artifact_hygiene", "Artifact-like path classification is heuristic and may include intentionally maintained files.");
|
|
150
|
+
addManualVerification("Review artifact_hygiene.suspicious_changes and decide whether each path is intentional.");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
checks.push({ name: "artifact_hygiene", result: "warn", detail: "Change evidence uses the legacy format without artifact classification." });
|
|
155
|
+
addManualVerification("Legacy changed-files evidence has no artifact classification; inspect changed paths manually.");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
checks.push({ name: "artifact_hygiene", result: "warn", detail: "changed-files.json could not be parsed for artifact classification." });
|
|
160
|
+
addManualVerification("changed-files.json could not be parsed; inspect repository changes directly.");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
109
163
|
// ── 3. test.log ──
|
|
110
164
|
const testLogFile = join(taskDir, "test.log");
|
|
111
165
|
const hasTestLog = existsSync(testLogFile);
|
|
@@ -114,6 +168,8 @@ export function auditTask(taskId) {
|
|
|
114
168
|
result: hasTestLog ? "pass" : "warn",
|
|
115
169
|
detail: hasTestLog ? "test.log found." : "test.log is missing.",
|
|
116
170
|
});
|
|
171
|
+
if (!hasTestLog)
|
|
172
|
+
addManualVerification("test.log is missing; confirm whether the task required an agent-side test run.");
|
|
117
173
|
// ── 4. git.diff ──
|
|
118
174
|
const diffFile = join(taskDir, "git.diff");
|
|
119
175
|
checks.push({
|
|
@@ -121,6 +177,8 @@ export function auditTask(taskId) {
|
|
|
121
177
|
result: existsSync(diffFile) ? "pass" : "warn",
|
|
122
178
|
detail: existsSync(diffFile) ? "git.diff found." : "git.diff is missing.",
|
|
123
179
|
});
|
|
180
|
+
if (!existsSync(diffFile))
|
|
181
|
+
addManualVerification("git.diff is missing; inspect repository state before accepting code changes.");
|
|
124
182
|
// ── 5. repo_path consistency — use resolved_repo_path, NOT resolve() ──
|
|
125
183
|
let repoPathSafe = "";
|
|
126
184
|
let repoConsistent = false;
|
|
@@ -167,6 +225,7 @@ export function auditTask(taskId) {
|
|
|
167
225
|
}
|
|
168
226
|
catch {
|
|
169
227
|
checks.push({ name: "package_json_scripts", result: "warn", detail: "package.json exists but could not be read (may be sensitive)." });
|
|
228
|
+
addManualVerification("package.json could not be read, so documented commands were not fully cross-checked.");
|
|
170
229
|
}
|
|
171
230
|
}
|
|
172
231
|
// ── 7. Scan all docs (result.md, README.md, docs/**/*.md) ──
|
|
@@ -220,6 +279,8 @@ export function auditTask(taskId) {
|
|
|
220
279
|
description: `Command "npm run ${scriptName}" referenced in docs but not found in package.json scripts.`,
|
|
221
280
|
});
|
|
222
281
|
actions.push(`Verify whether "npm run ${scriptName}" should exist or if the agent fabricated it.`);
|
|
282
|
+
addPossibleFalsePositive(`npm_script_${scriptName}`, "Documentation may describe another package, historical version, or example command rather than the current package.json.");
|
|
283
|
+
addManualVerification(`Check whether documented command "npm run ${scriptName}" belongs to another package or should be added here.`);
|
|
223
284
|
}
|
|
224
285
|
}
|
|
225
286
|
if (allNpmRunRefs.size > 0 && pkgScripts.length > 0) {
|
|
@@ -244,6 +305,7 @@ export function auditTask(taskId) {
|
|
|
244
305
|
description: `${allReleaseClaims.length} remote publish/release/deploy claim(s) found in docs. PatchWarden cannot independently verify npm/GitHub actions. Manual confirmation required.`,
|
|
245
306
|
});
|
|
246
307
|
actions.push("Manually verify all npm publish / GitHub release / git tag claims before accepting the task as complete.");
|
|
308
|
+
addManualVerification("Verify remote npm, GitHub Release, and Git tag claims against authoritative remote services.");
|
|
247
309
|
}
|
|
248
310
|
// ── 9. test.log Exit code check ──
|
|
249
311
|
if (hasTestLog) {
|
|
@@ -254,6 +316,7 @@ export function auditTask(taskId) {
|
|
|
254
316
|
}
|
|
255
317
|
else if (statusData.test_command) {
|
|
256
318
|
checks.push({ name: "test_command_in_log", result: "warn", detail: `test.log does not clearly show "${statusData.test_command}".` });
|
|
319
|
+
addManualVerification("Confirm that test.log belongs to the configured test command.");
|
|
257
320
|
}
|
|
258
321
|
// Extract Exit code
|
|
259
322
|
const exitMatch = testLogContent.match(/Exit\s*code:\s*(\d+)/i);
|
|
@@ -271,6 +334,7 @@ export function auditTask(taskId) {
|
|
|
271
334
|
else if (statusData.test_command) {
|
|
272
335
|
checks.push({ name: "test_exit_code", result: "warn", detail: "test.log does not contain 'Exit code:' line — cannot verify test result." });
|
|
273
336
|
risks.push({ severity: "medium", description: "Test command was configured but test.log has no exit code." });
|
|
337
|
+
addManualVerification("The configured test command has no recorded exit code; rerun or inspect verification evidence.");
|
|
274
338
|
}
|
|
275
339
|
}
|
|
276
340
|
// ── 10. Summarize ──
|
|
@@ -278,8 +342,10 @@ export function auditTask(taskId) {
|
|
|
278
342
|
const warnCount = checks.filter((c) => c.result === "warn").length;
|
|
279
343
|
const passCount = checks.filter((c) => c.result === "pass").length;
|
|
280
344
|
const verdict = failCount > 0 ? "fail" : warnCount > 0 ? "warn" : "pass";
|
|
345
|
+
const confirmedFailures = checks.filter((check) => check.result === "fail");
|
|
281
346
|
let summary = `Audit complete: ${passCount} pass, ${warnCount} warn, ${failCount} fail across ${checks.length} checks. `;
|
|
282
|
-
summary += risks.length > 0 ? `${risks.length} risk(s) identified
|
|
347
|
+
summary += risks.length > 0 ? `${risks.length} risk(s) identified. ` : "No risks identified. ";
|
|
348
|
+
summary += `${confirmedFailures.length} confirmed failure(s), ${possibleFalsePositives.length} possible false-positive warning(s), and ${manualVerificationItems.length} manual verification item(s).`;
|
|
283
349
|
if (actions.length === 0) {
|
|
284
350
|
actions.push("No specific actions recommended.");
|
|
285
351
|
}
|
|
@@ -299,9 +365,35 @@ export function auditTask(taskId) {
|
|
|
299
365
|
"## Risks",
|
|
300
366
|
...risks.map((r) => `- [${r.severity}] ${r.description}`),
|
|
301
367
|
"",
|
|
368
|
+
"## Confirmed Failures",
|
|
369
|
+
...(confirmedFailures.length > 0
|
|
370
|
+
? confirmedFailures.map((check) => `- **${check.name}**: ${check.detail}`)
|
|
371
|
+
: ["- None."]),
|
|
372
|
+
"",
|
|
373
|
+
"## Possible False Positives",
|
|
374
|
+
...(possibleFalsePositives.length > 0
|
|
375
|
+
? possibleFalsePositives.map((item) => `- **${item.check}**: ${item.reason}`)
|
|
376
|
+
: ["- None identified."]),
|
|
377
|
+
"",
|
|
378
|
+
"## Manual Verification Required",
|
|
379
|
+
...(manualVerificationItems.length > 0
|
|
380
|
+
? manualVerificationItems.map((item) => `- ${item}`)
|
|
381
|
+
: ["- No additional manual verification identified by this audit."]),
|
|
382
|
+
"",
|
|
302
383
|
"## Recommended Actions",
|
|
303
384
|
...actions.map((a) => `- ${a}`),
|
|
304
385
|
].join("\n");
|
|
305
386
|
writeFileSync(join(taskDir, "independent-review.md"), reviewMd, "utf-8");
|
|
306
|
-
return {
|
|
387
|
+
return {
|
|
388
|
+
task_id: taskId,
|
|
389
|
+
verdict,
|
|
390
|
+
summary,
|
|
391
|
+
checks,
|
|
392
|
+
risks,
|
|
393
|
+
confirmed_failures: confirmedFailures,
|
|
394
|
+
possible_false_positives: possibleFalsePositives,
|
|
395
|
+
manual_verification_required: manualVerificationItems.length > 0,
|
|
396
|
+
manual_verification_items: manualVerificationItems,
|
|
397
|
+
recommended_next_actions: actions,
|
|
398
|
+
};
|
|
307
399
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CreateDirectSessionInput {
|
|
2
|
+
repo_path: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CreateDirectSessionOutput {
|
|
6
|
+
session_id: string;
|
|
7
|
+
repo_path: string;
|
|
8
|
+
resolved_repo_path: string;
|
|
9
|
+
workspace_clean: boolean;
|
|
10
|
+
allowed_commands: string[];
|
|
11
|
+
expires_at: string;
|
|
12
|
+
next_action: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createDirectSession(input: CreateDirectSessionInput): CreateDirectSessionOutput;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { getConfig } from "../config.js";
|
|
3
|
+
import { PatchWardenError } from "../errors.js";
|
|
4
|
+
import { guardWorkspacePath } from "../security/pathGuard.js";
|
|
5
|
+
import { guardRuntimeSelfModification } from "../security/runtimeGuard.js";
|
|
6
|
+
import { captureRepoSnapshot } from "../runner/changeCapture.js";
|
|
7
|
+
import { createDirectSession as createDirectSessionRecord, } from "../direct/directSessionStore.js";
|
|
8
|
+
// ── Tool implementation ────────────────────────────────────────────
|
|
9
|
+
export function createDirectSession(input) {
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
// ── Validate repo_path ───────────────────────────────────────────
|
|
12
|
+
if (!input.repo_path || input.repo_path.trim() === "") {
|
|
13
|
+
throw new PatchWardenError("invalid_input", "repo_path is required and must be a non-empty string.", "Provide a repository path inside the configured workspaceRoot.", true, { operation: "create_direct_session" });
|
|
14
|
+
}
|
|
15
|
+
const resolvedRepoPath = guardWorkspacePath(input.repo_path, config.workspaceRoot);
|
|
16
|
+
// ── Verify existence ─────────────────────────────────────────────
|
|
17
|
+
if (!existsSync(resolvedRepoPath)) {
|
|
18
|
+
throw new PatchWardenError("repo_not_found", `repo_path "${input.repo_path}" does not exist (resolved: "${resolvedRepoPath}").`, "Provide a valid repository path inside the configured workspaceRoot.", true, {
|
|
19
|
+
repo_path: input.repo_path,
|
|
20
|
+
resolved_repo_path: resolvedRepoPath,
|
|
21
|
+
operation: "create_direct_session",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// ── Verify it is a directory ─────────────────────────────────────
|
|
25
|
+
const stat = statSync(resolvedRepoPath);
|
|
26
|
+
if (!stat.isDirectory()) {
|
|
27
|
+
throw new PatchWardenError("repo_not_directory", `repo_path "${input.repo_path}" is not a directory.`, "Provide a directory path, not a file path.", true, {
|
|
28
|
+
repo_path: input.repo_path,
|
|
29
|
+
resolved_repo_path: resolvedRepoPath,
|
|
30
|
+
operation: "create_direct_session",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// ── Runtime self-modification protection ─────────────────────────
|
|
34
|
+
guardRuntimeSelfModification(resolvedRepoPath);
|
|
35
|
+
// ── Capture repo snapshot ────────────────────────────────────────
|
|
36
|
+
const snapshot = captureRepoSnapshot(resolvedRepoPath);
|
|
37
|
+
// ── Create session record ────────────────────────────────────────
|
|
38
|
+
const session = createDirectSessionRecord({
|
|
39
|
+
repo_path: input.repo_path,
|
|
40
|
+
resolved_repo_path: resolvedRepoPath,
|
|
41
|
+
title: input.title,
|
|
42
|
+
snapshot,
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
session_id: session.session_id,
|
|
46
|
+
repo_path: session.repo_path,
|
|
47
|
+
resolved_repo_path: session.resolved_repo_path,
|
|
48
|
+
workspace_clean: !snapshot.workspace_dirty,
|
|
49
|
+
allowed_commands: session.allowed_commands,
|
|
50
|
+
expires_at: session.expires_at,
|
|
51
|
+
next_action: "Use search_workspace/read_workspace_file, then apply_patch to make file changes within this session. " +
|
|
52
|
+
"After editing, call run_verification, finalize_direct_session, and audit_session.",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -9,12 +9,56 @@ export interface CreateTaskInput {
|
|
|
9
9
|
template?: TaskTemplateName;
|
|
10
10
|
goal?: string;
|
|
11
11
|
source_task_id?: string;
|
|
12
|
-
agent
|
|
12
|
+
agent?: string;
|
|
13
13
|
repo_path?: string;
|
|
14
14
|
test_command?: string;
|
|
15
15
|
verify_commands?: string[];
|
|
16
16
|
timeout_seconds?: number;
|
|
17
|
+
execution_mode?: "assess_only" | "execute";
|
|
18
|
+
assessment_id?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AssessOnlyOutput {
|
|
21
|
+
assessment_id: string;
|
|
22
|
+
assessment_short_id: string;
|
|
23
|
+
decision: "allow" | "needs_confirm" | "blocked";
|
|
24
|
+
risk_level: "low" | "medium" | "high";
|
|
25
|
+
risk_hints: string[];
|
|
26
|
+
hard_rule_hits: string[];
|
|
27
|
+
reason_codes: string[];
|
|
28
|
+
expires_at: string;
|
|
29
|
+
requires_confirm: boolean;
|
|
30
|
+
workspace_snapshot_summary: {
|
|
31
|
+
head: string | null;
|
|
32
|
+
file_count: number;
|
|
33
|
+
workspace_dirty: boolean;
|
|
34
|
+
snapshot_truncated: boolean;
|
|
35
|
+
};
|
|
36
|
+
next_action: string;
|
|
37
|
+
next_tool_call?: {
|
|
38
|
+
name: "create_task";
|
|
39
|
+
arguments: {
|
|
40
|
+
execution_mode: "execute";
|
|
41
|
+
assessment_id: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
local_confirmation: {
|
|
45
|
+
required: boolean;
|
|
46
|
+
command: "patchwarden-confirm" | null;
|
|
47
|
+
arguments: string[];
|
|
48
|
+
};
|
|
49
|
+
suggestion?: string;
|
|
50
|
+
agent_assessment?: {
|
|
51
|
+
status: string;
|
|
52
|
+
merged_risk: string;
|
|
53
|
+
merged_decision: string;
|
|
54
|
+
confidence: number | null;
|
|
55
|
+
notes: string | null;
|
|
56
|
+
read_only_violation: boolean;
|
|
57
|
+
stdout_truncated: boolean;
|
|
58
|
+
stderr_truncated: boolean;
|
|
59
|
+
} | null;
|
|
17
60
|
}
|
|
61
|
+
export type CreateTaskResult = CreateTaskOutput | AssessOnlyOutput;
|
|
18
62
|
export interface CreateTaskOutput {
|
|
19
63
|
task_id: string;
|
|
20
64
|
plan_id: string;
|
|
@@ -39,4 +83,7 @@ export interface CreateTaskOutput {
|
|
|
39
83
|
arguments: Record<string, unknown>;
|
|
40
84
|
};
|
|
41
85
|
}
|
|
86
|
+
export declare function createTask(input: CreateTaskInput & {
|
|
87
|
+
execution_mode: "assess_only";
|
|
88
|
+
}): AssessOnlyOutput;
|
|
42
89
|
export declare function createTask(input: CreateTaskInput): CreateTaskOutput;
|