patchwarden 0.6.0 → 0.6.4

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.
Files changed (134) hide show
  1. package/PatchWarden-Control-Tray.cmd +11 -0
  2. package/PatchWarden-Control.cmd +6 -0
  3. package/PatchWarden-Desktop.cmd +5 -0
  4. package/PatchWarden.cmd +1 -1
  5. package/README.en.md +106 -18
  6. package/README.md +30 -19
  7. package/Restart-PatchWarden-Control.cmd +6 -0
  8. package/Stop-PatchWarden.cmd +11 -0
  9. package/dist/controlCenter.d.ts +14 -0
  10. package/dist/controlCenter.js +2002 -0
  11. package/dist/doctor.js +4 -4
  12. package/dist/logging.d.ts +52 -0
  13. package/dist/logging.js +123 -0
  14. package/dist/runner/changeCapture.d.ts +41 -0
  15. package/dist/runner/changeCapture.js +171 -1
  16. package/dist/runner/runTask.js +204 -24
  17. package/dist/smoke-test.js +8 -8
  18. package/dist/test/unit/android-doctor.test.d.ts +1 -0
  19. package/dist/test/unit/android-doctor.test.js +118 -0
  20. package/dist/test/unit/chinese-path.test.d.ts +1 -0
  21. package/dist/test/unit/chinese-path.test.js +91 -0
  22. package/dist/test/unit/command-guard.test.d.ts +1 -0
  23. package/dist/test/unit/command-guard.test.js +160 -0
  24. package/dist/test/unit/direct-guards.test.d.ts +1 -0
  25. package/dist/test/unit/direct-guards.test.js +213 -0
  26. package/dist/test/unit/logging.test.d.ts +1 -0
  27. package/dist/test/unit/logging.test.js +275 -0
  28. package/dist/test/unit/path-guard.test.d.ts +1 -0
  29. package/dist/test/unit/path-guard.test.js +109 -0
  30. package/dist/test/unit/safe-status.test.d.ts +1 -0
  31. package/dist/test/unit/safe-status.test.js +165 -0
  32. package/dist/test/unit/sensitive-guard.test.d.ts +1 -0
  33. package/dist/test/unit/sensitive-guard.test.js +104 -0
  34. package/dist/test/unit/sync-file.test.d.ts +1 -0
  35. package/dist/test/unit/sync-file.test.js +154 -0
  36. package/dist/test/unit/watcher-status.test.d.ts +1 -0
  37. package/dist/test/unit/watcher-status.test.js +169 -0
  38. package/dist/tools/androidDoctor.d.ts +38 -0
  39. package/dist/tools/androidDoctor.js +391 -0
  40. package/dist/tools/auditTask.js +11 -5
  41. package/dist/tools/getTaskSummary.d.ts +3 -0
  42. package/dist/tools/getTaskSummary.js +15 -1
  43. package/dist/tools/healthCheck.d.ts +5 -0
  44. package/dist/tools/healthCheck.js +21 -0
  45. package/dist/tools/registry.js +53 -0
  46. package/dist/tools/safeStatus.d.ts +19 -0
  47. package/dist/tools/safeStatus.js +72 -0
  48. package/dist/tools/syncFile.d.ts +18 -0
  49. package/dist/tools/syncFile.js +65 -0
  50. package/dist/tools/taskOutputs.d.ts +2 -2
  51. package/dist/tools/toolCatalog.d.ts +2 -2
  52. package/dist/tools/toolCatalog.js +2 -0
  53. package/dist/version.d.ts +2 -2
  54. package/dist/version.js +2 -2
  55. package/dist/watcherStatus.d.ts +1 -0
  56. package/dist/watcherStatus.js +96 -4
  57. package/docs/control-center/README.md +33 -0
  58. package/docs/control-center/control-center-daily-driver.md +211 -0
  59. package/docs/control-center/control-center-mvp.md +205 -0
  60. package/docs/control-center/control-center-phase2.md +159 -0
  61. package/docs/demo.md +3 -0
  62. package/docs/performance-notes.md +55 -0
  63. package/docs/release-v0.6.1.md +75 -0
  64. package/docs/release-v0.6.4.md +45 -0
  65. package/examples/openai-tunnel/README.md +5 -5
  66. package/examples/openai-tunnel/tunnel-client.example.yaml +3 -3
  67. package/package.json +23 -14
  68. package/scripts/README.md +47 -0
  69. package/scripts/{brand-check.js → checks/brand-check.js} +2 -2
  70. package/scripts/checks/control-center-smoke.js +1098 -0
  71. package/scripts/{control-smoke.js → checks/control-smoke.js} +17 -3
  72. package/scripts/{doctor-smoke.js → checks/doctor-smoke.js} +1 -1
  73. package/scripts/{http-mcp-smoke.js → checks/http-mcp-smoke.js} +12 -4
  74. package/scripts/{lifecycle-smoke.js → checks/lifecycle-smoke.js} +347 -13
  75. package/scripts/{mcp-manifest-check.js → checks/mcp-manifest-check.js} +32 -9
  76. package/scripts/{mcp-smoke.js → checks/mcp-smoke.js} +14 -9
  77. package/scripts/{package-manifest-check.js → checks/package-manifest-check.js} +2 -1
  78. package/scripts/{tunnel-supervisor-smoke.js → checks/tunnel-supervisor-smoke.js} +2 -2
  79. package/scripts/checks/unit-tests.js +36 -0
  80. package/scripts/{watcher-supervisor-smoke.js → checks/watcher-supervisor-smoke.js} +11 -5
  81. package/scripts/control/control-center-tray.ps1 +281 -0
  82. package/scripts/{get-patchwarden-health.ps1 → control/get-patchwarden-health.ps1} +3 -3
  83. package/scripts/{manage-patchwarden.ps1 → control/manage-patchwarden.ps1} +30 -4
  84. package/scripts/control/restart-control-center.ps1 +173 -0
  85. package/scripts/{restart-patchwarden.ps1 → control/restart-patchwarden.ps1} +1 -1
  86. package/scripts/control/start-control-center.ps1 +263 -0
  87. package/scripts/{start-patchwarden-tunnel.ps1 → control/start-patchwarden-tunnel.ps1} +48 -6
  88. package/scripts/control/stop-patchwarden.ps1 +114 -0
  89. package/scripts/launchers/Check-PatchWarden-Health.cmd +1 -1
  90. package/scripts/launchers/Reset-PatchWarden-Tunnel-Key.cmd +1 -1
  91. package/scripts/launchers/Restart-PatchWarden.cmd +1 -1
  92. package/scripts/launchers/Start-PatchWarden-Direct-Tunnel.cmd +1 -1
  93. package/scripts/launchers/Start-PatchWarden-Tunnel.cmd +1 -1
  94. package/scripts/{patchwarden-mcp-direct.cmd → mcp/patchwarden-mcp-direct.cmd} +1 -1
  95. package/scripts/{patchwarden-mcp-stdio.cmd → mcp/patchwarden-mcp-stdio.cmd} +1 -1
  96. package/scripts/release/pack-clean.js +305 -0
  97. package/src/controlCenter.ts +2152 -0
  98. package/src/doctor.ts +5 -5
  99. package/src/logging.ts +152 -0
  100. package/src/runner/changeCapture.ts +212 -1
  101. package/src/runner/runTask.ts +220 -22
  102. package/src/smoke-test.ts +5 -5
  103. package/src/test/unit/android-doctor.test.ts +158 -0
  104. package/src/test/unit/chinese-path.test.ts +106 -0
  105. package/src/test/unit/command-guard.test.ts +221 -0
  106. package/src/test/unit/direct-guards.test.ts +297 -0
  107. package/src/test/unit/logging.test.ts +325 -0
  108. package/src/test/unit/path-guard.test.ts +150 -0
  109. package/src/test/unit/safe-status.test.ts +187 -0
  110. package/src/test/unit/sensitive-guard.test.ts +124 -0
  111. package/src/test/unit/sync-file.test.ts +231 -0
  112. package/src/test/unit/watcher-status.test.ts +190 -0
  113. package/src/tools/androidDoctor.ts +424 -0
  114. package/src/tools/auditTask.ts +11 -5
  115. package/src/tools/getTaskSummary.ts +22 -1
  116. package/src/tools/healthCheck.ts +22 -0
  117. package/src/tools/registry.ts +63 -0
  118. package/src/tools/safeStatus.ts +96 -0
  119. package/src/tools/syncFile.ts +122 -0
  120. package/src/tools/toolCatalog.ts +2 -0
  121. package/src/version.ts +2 -2
  122. package/src/watcherStatus.ts +101 -4
  123. package/ui/colors_and_type.css +141 -0
  124. package/ui/pages/audit.html +743 -0
  125. package/ui/pages/dashboard.html +1154 -0
  126. package/ui/pages/direct-sessions.html +652 -0
  127. package/ui/pages/logs.html +502 -0
  128. package/ui/pages/task-detail.html +1229 -0
  129. package/ui/pages/tasks.html +702 -0
  130. package/ui/pages/workspace.html +947 -0
  131. package/ui/partials/project-shell.html +362 -0
  132. package/ui/vendor/lucide.js +12 -0
  133. package/ui/vendor/tailwindcss-browser.js +947 -0
  134. package/scripts/pack-clean.js +0 -141
@@ -0,0 +1,424 @@
1
+ /**
2
+ * PatchWarden Android Doctor — read-only Android build environment diagnostics.
3
+ *
4
+ * Inspects a repository for an `android_app` directory and reports whether the
5
+ * local environment can build an APK. The module is strictly read-only: it never
6
+ * auto-downloads the Android SDK, never modifies system environment variables,
7
+ * and never installs global dependencies. It only runs `java -version` (read-only)
8
+ * and inspects files/directories/env vars that already exist.
9
+ */
10
+
11
+ import { execSync } from "node:child_process";
12
+ import { existsSync, readFileSync, statSync } from "node:fs";
13
+ import { join } from "node:path";
14
+
15
+ // ── Types ──────────────────────────────────────────────────────────
16
+
17
+ export type AndroidCheckStatus = "ok" | "warn" | "fail" | "skip";
18
+
19
+ export interface AndroidDiagnosticItem {
20
+ check: string;
21
+ status: AndroidCheckStatus;
22
+ reason: string;
23
+ suggested_fix: string;
24
+ }
25
+
26
+ export interface AndroidBuildDiagnosticReport {
27
+ status: "ok" | "warn" | "fail";
28
+ repo_path: string;
29
+ android_app_path: string;
30
+ checks: AndroidDiagnosticItem[];
31
+ checked_at: string;
32
+ }
33
+
34
+ export type AndroidBuildDiagnostic =
35
+ | { status: "skip"; reason: string }
36
+ | AndroidBuildDiagnosticReport;
37
+
38
+ // ── Constants ──────────────────────────────────────────────────────
39
+
40
+ /**
41
+ * Required explanatory sentence emitted whenever the Android SDK is missing.
42
+ * Callers rely on this exact wording to detect the "SDK missing" condition.
43
+ */
44
+ const SDK_MISSING_REASON =
45
+ "Android project exists, APK not built because Android SDK is missing.";
46
+
47
+ // ── Helpers ────────────────────────────────────────────────────────
48
+
49
+ /**
50
+ * Run a shell command and return its trimmed combined stdout/stderr output.
51
+ * Returns an empty string when the command is missing or fails so callers can
52
+ * treat absence gracefully. A timeout guards against hanging processes.
53
+ */
54
+ function runCmd(cmdStr: string): string {
55
+ try {
56
+ return execSync(cmdStr, {
57
+ encoding: "utf-8",
58
+ timeout: 8000,
59
+ stdio: ["ignore", "pipe", "ignore"],
60
+ }).trim();
61
+ } catch {
62
+ return "";
63
+ }
64
+ }
65
+
66
+ /** True when `path` exists and is a directory. Never throws. */
67
+ function isDirectory(path: string): boolean {
68
+ try {
69
+ return existsSync(path) && statSync(path).isDirectory();
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ /** Extract the quoted version token from `java -version` output. */
76
+ function parseJavaVersion(output: string): string | null {
77
+ const match = output.match(/version "([^"]+)"/);
78
+ return match ? match[1] : null;
79
+ }
80
+
81
+ /**
82
+ * Convert a Java version string to its major version number.
83
+ * "17.0.1" -> 17, "21" -> 21, "1.8.0_292" -> 8 (legacy 1.x scheme).
84
+ */
85
+ function parseJavaMajor(version: string): number | null {
86
+ const match = version.match(/^(\d+)(?:\.(\d+))?/);
87
+ if (!match) return null;
88
+ const major = parseInt(match[1], 10);
89
+ if (major === 1 && match[2]) return parseInt(match[2], 10);
90
+ return major;
91
+ }
92
+
93
+ /** Safely read a UTF-8 file, returning null on any error. */
94
+ function readTextFile(path: string): string | null {
95
+ try {
96
+ return readFileSync(path, "utf-8");
97
+ } catch {
98
+ return null;
99
+ }
100
+ }
101
+
102
+ // ── Public API ─────────────────────────────────────────────────────
103
+
104
+ /**
105
+ * Diagnose the Android build readiness for the repository at `repoPath`.
106
+ *
107
+ * - If `<repoPath>/android_app` does not exist, returns a skip result.
108
+ * - Otherwise runs 10 read-only checks and returns a structured report with an
109
+ * overall status: "fail" if any check failed, "warn" if any warned, else "ok".
110
+ *
111
+ * This function performs no mutations: it does not download the SDK, change env
112
+ * vars, or install dependencies.
113
+ */
114
+ export function diagnoseAndroidBuild(repoPath: string): AndroidBuildDiagnostic {
115
+ const androidAppPath = join(repoPath, "android_app");
116
+ if (!isDirectory(androidAppPath)) {
117
+ return { status: "skip", reason: "No android_app directory found" };
118
+ }
119
+
120
+ const checks: AndroidDiagnosticItem[] = [];
121
+ const checkedAt = new Date().toISOString();
122
+
123
+ // Resolve the Android SDK location. ANDROID_HOME is preferred; ANDROID_SDK_ROOT
124
+ // is a legacy fallback that some tools still honor.
125
+ const androidHomeEnv = process.env.ANDROID_HOME || "";
126
+ const androidSdkRootEnv = process.env.ANDROID_SDK_ROOT || "";
127
+ const sdkRoot = androidHomeEnv || androidSdkRootEnv;
128
+ const sdkExists = sdkRoot !== "" && isDirectory(sdkRoot);
129
+
130
+ // 1. java -version ------------------------------------------------------
131
+ // `java -version` writes to stderr; redirect with 2>&1 so execSync captures it.
132
+ const javaOutput = runCmd("java -version 2>&1");
133
+ const javaVersion = parseJavaVersion(javaOutput);
134
+ if (javaVersion) {
135
+ const major = parseJavaMajor(javaVersion);
136
+ if (major !== null && major < 17) {
137
+ checks.push({
138
+ check: "java -version",
139
+ status: "warn",
140
+ reason: `Java ${javaVersion} found. Modern Android Gradle Plugin (8.x) requires JDK 17+.`,
141
+ suggested_fix:
142
+ "Install JDK 17 or newer and place it first on PATH (or point JAVA_HOME at it).",
143
+ });
144
+ } else {
145
+ checks.push({
146
+ check: "java -version",
147
+ status: "ok",
148
+ reason: `Java ${javaVersion} is available on PATH.`,
149
+ suggested_fix: "",
150
+ });
151
+ }
152
+ } else {
153
+ checks.push({
154
+ check: "java -version",
155
+ status: "fail",
156
+ reason: "java command not found or did not report a version.",
157
+ suggested_fix:
158
+ "Install a JDK (17+ recommended for modern Android) and add its bin directory to PATH.",
159
+ });
160
+ }
161
+
162
+ // 2. JAVA_HOME ----------------------------------------------------------
163
+ const javaHome = process.env.JAVA_HOME || "";
164
+ if (javaHome && isDirectory(javaHome)) {
165
+ checks.push({
166
+ check: "JAVA_HOME",
167
+ status: "ok",
168
+ reason: `JAVA_HOME is set to ${javaHome}.`,
169
+ suggested_fix: "",
170
+ });
171
+ } else if (javaHome) {
172
+ checks.push({
173
+ check: "JAVA_HOME",
174
+ status: "warn",
175
+ reason: `JAVA_HOME is set to "${javaHome}" but that directory does not exist.`,
176
+ suggested_fix: "Point JAVA_HOME at a valid JDK installation directory.",
177
+ });
178
+ } else {
179
+ checks.push({
180
+ check: "JAVA_HOME",
181
+ status: "warn",
182
+ reason: "JAVA_HOME is not set. Gradle may be unable to locate the JDK.",
183
+ suggested_fix:
184
+ "Set JAVA_HOME to your JDK installation (e.g. C:\\Program Files\\Java\\jdk-17).",
185
+ });
186
+ }
187
+
188
+ // 3. ANDROID_HOME -------------------------------------------------------
189
+ if (!androidHomeEnv) {
190
+ if (!sdkExists) {
191
+ checks.push({
192
+ check: "ANDROID_HOME",
193
+ status: "fail",
194
+ reason: `ANDROID_HOME is not set. ${SDK_MISSING_REASON}`,
195
+ suggested_fix:
196
+ "Install the Android SDK and set ANDROID_HOME to its root directory " +
197
+ "(e.g. C:\\Users\\<you>\\AppData\\Local\\Android\\Sdk).",
198
+ });
199
+ } else {
200
+ checks.push({
201
+ check: "ANDROID_HOME",
202
+ status: "warn",
203
+ reason:
204
+ "ANDROID_HOME is not set. ANDROID_SDK_ROOT points at an SDK, but ANDROID_HOME is the preferred variable.",
205
+ suggested_fix: "Set ANDROID_HOME to the same value as ANDROID_SDK_ROOT.",
206
+ });
207
+ }
208
+ } else if (!isDirectory(androidHomeEnv)) {
209
+ checks.push({
210
+ check: "ANDROID_HOME",
211
+ status: "fail",
212
+ reason:
213
+ `ANDROID_HOME is set to "${androidHomeEnv}" but that directory does not exist.` +
214
+ (sdkExists ? "" : ` ${SDK_MISSING_REASON}`),
215
+ suggested_fix:
216
+ "Install the Android SDK at the ANDROID_HOME path, or correct the variable to point at an existing SDK.",
217
+ });
218
+ } else {
219
+ checks.push({
220
+ check: "ANDROID_HOME",
221
+ status: "ok",
222
+ reason: `ANDROID_HOME is set to ${androidHomeEnv}.`,
223
+ suggested_fix: "",
224
+ });
225
+ }
226
+
227
+ // 4. ANDROID_SDK_ROOT ---------------------------------------------------
228
+ if (androidSdkRootEnv && isDirectory(androidSdkRootEnv)) {
229
+ checks.push({
230
+ check: "ANDROID_SDK_ROOT",
231
+ status: "ok",
232
+ reason: `ANDROID_SDK_ROOT is set to ${androidSdkRootEnv}.`,
233
+ suggested_fix: "",
234
+ });
235
+ } else if (androidSdkRootEnv) {
236
+ checks.push({
237
+ check: "ANDROID_SDK_ROOT",
238
+ status: "warn",
239
+ reason: `ANDROID_SDK_ROOT is set to "${androidSdkRootEnv}" but that directory does not exist.`,
240
+ suggested_fix: "Point ANDROID_SDK_ROOT at a valid Android SDK directory.",
241
+ });
242
+ } else {
243
+ checks.push({
244
+ check: "ANDROID_SDK_ROOT",
245
+ status: "warn",
246
+ reason:
247
+ "ANDROID_SDK_ROOT is not set. Some tools fall back to ANDROID_HOME, but setting both is recommended.",
248
+ suggested_fix: "Set ANDROID_SDK_ROOT to the same value as ANDROID_HOME.",
249
+ });
250
+ }
251
+
252
+ // 5. Android SDK platform ----------------------------------------------
253
+ if (!sdkExists) {
254
+ checks.push({
255
+ check: "Android SDK platform",
256
+ status: "skip",
257
+ reason: `Skipped: Android SDK not available. ${SDK_MISSING_REASON}`,
258
+ suggested_fix: "Install the Android SDK and a platform via sdkmanager.",
259
+ });
260
+ } else {
261
+ const platformsDir = join(sdkRoot, "platforms");
262
+ if (isDirectory(platformsDir)) {
263
+ checks.push({
264
+ check: "Android SDK platform",
265
+ status: "ok",
266
+ reason: `Android SDK platforms directory found at ${platformsDir}.`,
267
+ suggested_fix: "",
268
+ });
269
+ } else {
270
+ checks.push({
271
+ check: "Android SDK platform",
272
+ status: "warn",
273
+ reason: `No platforms directory found at ${platformsDir}. No Android platform is installed.`,
274
+ suggested_fix: 'Run: sdkmanager "platforms;android-34"',
275
+ });
276
+ }
277
+ }
278
+
279
+ // 6. Android build-tools ------------------------------------------------
280
+ if (!sdkExists) {
281
+ checks.push({
282
+ check: "Android build-tools",
283
+ status: "skip",
284
+ reason: `Skipped: Android SDK not available. ${SDK_MISSING_REASON}`,
285
+ suggested_fix: "Install the Android SDK and build-tools via sdkmanager.",
286
+ });
287
+ } else {
288
+ const buildToolsDir = join(sdkRoot, "build-tools");
289
+ if (isDirectory(buildToolsDir)) {
290
+ checks.push({
291
+ check: "Android build-tools",
292
+ status: "ok",
293
+ reason: `Android build-tools directory found at ${buildToolsDir}.`,
294
+ suggested_fix: "",
295
+ });
296
+ } else {
297
+ checks.push({
298
+ check: "Android build-tools",
299
+ status: "warn",
300
+ reason: `No build-tools directory found at ${buildToolsDir}.`,
301
+ suggested_fix: 'Run: sdkmanager "build-tools;34.0.0"',
302
+ });
303
+ }
304
+ }
305
+
306
+ // 7. Gradle wrapper -----------------------------------------------------
307
+ const gradlewUnix = join(androidAppPath, "gradlew");
308
+ const gradlewWin = join(androidAppPath, "gradlew.bat");
309
+ const wrapperProps = join(androidAppPath, "gradle", "wrapper", "gradle-wrapper.properties");
310
+ let gradleVersion: string | null = null;
311
+ const propsContent = readTextFile(wrapperProps);
312
+ if (propsContent) {
313
+ const match = propsContent.match(/gradle-([\d.]+)-/);
314
+ gradleVersion = match ? match[1] : null;
315
+ }
316
+ if (existsSync(gradlewUnix) || existsSync(gradlewWin)) {
317
+ checks.push({
318
+ check: "Gradle wrapper",
319
+ status: "ok",
320
+ reason: gradleVersion
321
+ ? `Gradle wrapper found in android_app (Gradle ${gradleVersion}).`
322
+ : "Gradle wrapper found in android_app.",
323
+ suggested_fix: "",
324
+ });
325
+ } else {
326
+ checks.push({
327
+ check: "Gradle wrapper",
328
+ status: "warn",
329
+ reason: "No gradlew or gradlew.bat found in android_app.",
330
+ suggested_fix:
331
+ "Generate the wrapper inside android_app with: gradle wrapper (or copy gradlew/gradlew.bat/gradle-wrapper.jar from an existing project).",
332
+ });
333
+ }
334
+
335
+ // 8. settings.gradle.kts -----------------------------------------------
336
+ const settingsGradleKts = join(androidAppPath, "settings.gradle.kts");
337
+ const settingsGradleGroovy = join(androidAppPath, "settings.gradle");
338
+ if (existsSync(settingsGradleKts)) {
339
+ checks.push({
340
+ check: "android_app/settings.gradle.kts",
341
+ status: "ok",
342
+ reason: "settings.gradle.kts found in android_app.",
343
+ suggested_fix: "",
344
+ });
345
+ } else if (existsSync(settingsGradleGroovy)) {
346
+ checks.push({
347
+ check: "android_app/settings.gradle.kts",
348
+ status: "warn",
349
+ reason: "settings.gradle.kts not found, but settings.gradle (Groovy DSL) is present.",
350
+ suggested_fix: "Kotlin DSL is preferred; consider migrating settings.gradle to settings.gradle.kts.",
351
+ });
352
+ } else {
353
+ checks.push({
354
+ check: "android_app/settings.gradle.kts",
355
+ status: "warn",
356
+ reason: "settings.gradle.kts not found in android_app.",
357
+ suggested_fix: "Create android_app/settings.gradle.kts declaring the project modules.",
358
+ });
359
+ }
360
+
361
+ // 9. app/build.gradle.kts ----------------------------------------------
362
+ const appBuildGradleKts = join(androidAppPath, "app", "build.gradle.kts");
363
+ const appBuildGradleGroovy = join(androidAppPath, "app", "build.gradle");
364
+ if (existsSync(appBuildGradleKts)) {
365
+ checks.push({
366
+ check: "android_app/app/build.gradle.kts",
367
+ status: "ok",
368
+ reason: "app/build.gradle.kts found.",
369
+ suggested_fix: "",
370
+ });
371
+ } else if (existsSync(appBuildGradleGroovy)) {
372
+ checks.push({
373
+ check: "android_app/app/build.gradle.kts",
374
+ status: "warn",
375
+ reason: "app/build.gradle.kts not found, but app/build.gradle (Groovy DSL) is present.",
376
+ suggested_fix: "Kotlin DSL is preferred; consider migrating app/build.gradle to app/build.gradle.kts.",
377
+ });
378
+ } else {
379
+ checks.push({
380
+ check: "android_app/app/build.gradle.kts",
381
+ status: "warn",
382
+ reason: "app/build.gradle.kts not found in android_app/app.",
383
+ suggested_fix: "Create android_app/app/build.gradle.kts with the Android application plugin and build config.",
384
+ });
385
+ }
386
+
387
+ // 10. APK output path ---------------------------------------------------
388
+ const apkDir = join(androidAppPath, "app", "build", "outputs", "apk");
389
+ if (!sdkExists) {
390
+ checks.push({
391
+ check: "APK output path",
392
+ status: "skip",
393
+ reason: SDK_MISSING_REASON,
394
+ suggested_fix: "Install the Android SDK, then build with: cd android_app && ./gradlew assembleDebug",
395
+ });
396
+ } else if (isDirectory(apkDir)) {
397
+ checks.push({
398
+ check: "APK output path",
399
+ status: "ok",
400
+ reason: `APK output directory found at ${apkDir}.`,
401
+ suggested_fix: "",
402
+ });
403
+ } else {
404
+ checks.push({
405
+ check: "APK output path",
406
+ status: "warn",
407
+ reason: "APK output directory not found. The project has not been built yet.",
408
+ suggested_fix: "Build the APK: cd android_app && ./gradlew assembleDebug",
409
+ });
410
+ }
411
+
412
+ // Overall status: fail dominates warn dominates ok.
413
+ const hasFail = checks.some((c) => c.status === "fail");
414
+ const hasWarn = checks.some((c) => c.status === "warn");
415
+ const overall: "ok" | "warn" | "fail" = hasFail ? "fail" : hasWarn ? "warn" : "ok";
416
+
417
+ return {
418
+ status: overall,
419
+ repo_path: repoPath,
420
+ android_app_path: androidAppPath,
421
+ checks,
422
+ checked_at: checkedAt,
423
+ };
424
+ }
@@ -147,13 +147,19 @@ export function auditTask(taskId: string): AuditTaskOutput {
147
147
  }
148
148
  }
149
149
 
150
- const outOfScope = Array.isArray(statusData.out_of_scope_changes) ? statusData.out_of_scope_changes : [];
150
+ // Phase 4: Use new_out_of_scope_changes (task-caused) instead of out_of_scope_changes (all)
151
+ // Pre-existing external dirty files that didn't change during the task should NOT fail audit.
152
+ const newOutOfScope = Array.isArray(statusData.new_out_of_scope_changes)
153
+ ? statusData.new_out_of_scope_changes
154
+ : Array.isArray(statusData.out_of_scope_changes)
155
+ ? statusData.out_of_scope_changes
156
+ : [];
151
157
  checks.push({
152
158
  name: "scope_changes",
153
- result: outOfScope.length > 0 ? "fail" : "pass",
154
- detail: outOfScope.length > 0
155
- ? `${outOfScope.length} out-of-scope change(s) detected.`
156
- : "No out-of-scope changes recorded.",
159
+ result: newOutOfScope.length > 0 ? "fail" : "pass",
160
+ detail: newOutOfScope.length > 0
161
+ ? `${newOutOfScope.length} new out-of-scope change(s) detected during task execution.`
162
+ : "No new out-of-scope changes recorded.",
157
163
  });
158
164
 
159
165
  const changedFilesFile = join(taskDir, "changed-files.json");
@@ -101,6 +101,9 @@ export interface CompactTaskSummaryOutput {
101
101
  max_items: number;
102
102
  truncated: boolean;
103
103
  };
104
+ release_artifacts_count: number;
105
+ release_artifact_paths: string[];
106
+ artifact_status: string | null;
104
107
  verification_summary: TaskSummaryOutput["verification_summary"];
105
108
  summary: string;
106
109
  warnings: string[];
@@ -136,7 +139,14 @@ export function getTaskSummary(taskId: string, options: GetTaskSummaryOptions =
136
139
  const result = resultRead.data;
137
140
  const verify = verifyRead.data;
138
141
  const terminal = TERMINAL_STATUSES.has(String(status.status));
139
- const outOfScope = asArray(result.out_of_scope_changes ?? status.out_of_scope_changes);
142
+ // Phase 4: Use new_out_of_scope_changes (task-caused) for acceptance status.
143
+ // Pre-existing external dirty files that didn't change should NOT fail acceptance.
144
+ const outOfScope = asArray(
145
+ result.new_out_of_scope_changes
146
+ ?? status.new_out_of_scope_changes
147
+ ?? result.out_of_scope_changes
148
+ ?? status.out_of_scope_changes
149
+ );
140
150
  const verifyStatus = String(verify.status ?? result.verify_status ?? result.verify?.status ?? status.verify_status ?? "not_available");
141
151
  const errors = [status.error, ...asArray(result.errors), ...asArray(result.known_issues)]
142
152
  .filter((value): value is string => typeof value === "string" && value.trim() !== "");
@@ -300,6 +310,14 @@ function buildCompactSummary(output: Record<string, any>, maxItems: number): Com
300
310
  ] as const;
301
311
  const groups = Object.fromEntries(groupNames.map((name) => [name, asArray(hygiene[name]).slice(0, maxItems)]));
302
312
  const truncated = groupNames.some((name) => asArray(hygiene[name]).length > maxItems);
313
+
314
+ // Phase 6: Read artifact_manifest.json for release artifact info
315
+ const taskDir = resolve(getTasksDir(getConfig()), String(output.task_id));
316
+ const manifestRead = tryReadJson(join(taskDir, "artifact_manifest.json"));
317
+ const manifest = asRecord(manifestRead.data);
318
+ const releaseArtifacts = asArray(manifest.artifacts);
319
+ const releaseArtifactPaths = releaseArtifacts.map((a: any) => String(a.path || "")).slice(0, maxItems);
320
+
303
321
  const compact = {
304
322
  view: "compact" as const,
305
323
  task_id: String(output.task_id),
@@ -316,6 +334,9 @@ function buildCompactSummary(output: Record<string, any>, maxItems: number): Com
316
334
  max_items: maxItems,
317
335
  truncated,
318
336
  },
337
+ release_artifacts_count: releaseArtifacts.length,
338
+ release_artifact_paths: releaseArtifactPaths,
339
+ artifact_status: String(output.artifact_status || manifest.status || "collected"),
319
340
  verification_summary: output.verification_summary,
320
341
  summary: String(output.summary).slice(0, 1000),
321
342
  warnings: asArray(output.warnings).slice(0, maxItems),
@@ -122,6 +122,7 @@ export function healthCheck(catalog?: ToolCatalogSnapshot, input: HealthCheckInp
122
122
  uptime_seconds: Math.round((Date.now() - SERVER_STARTED_AT) / 1000),
123
123
  checked_at: new Date().toISOString(),
124
124
  },
125
+ path_encoding: checkPathEncoding(),
125
126
  watcher,
126
127
  workspace_root: workspace,
127
128
  tasks_dir: tasks,
@@ -249,3 +250,24 @@ function readTunnelStatus(): Record<string, unknown> & { last_error: string | nu
249
250
  function safeText(value: unknown, maxLength: number): string {
250
251
  return typeof value === "string" ? value.replace(/[\r\n]+/g, " ").slice(0, maxLength) : "";
251
252
  }
253
+
254
+ function checkPathEncoding(): { encoding: string; warnings: string[] } {
255
+ const warnings: string[] = [];
256
+ // Node.js always uses UTF-8 for fs operations, but on Windows the console
257
+ // codepage can cause display issues. We check if the environment is likely
258
+ // to cause problems with non-ASCII paths.
259
+ if (process.platform === "win32") {
260
+ // Check if the system locale uses a codepage that might not support UTF-8
261
+ const lang = process.env.LANG || process.env.LC_ALL || "";
262
+ const chcp = process.env.PATCHWARDEN_CHCP || "";
263
+ if (chcp && !chcp.includes("65001") && !chcp.includes("utf")) {
264
+ warnings.push(`Windows codepage "${chcp}" may cause display issues with non-ASCII paths. Consider setting codepage to 65001 (UTF-8).`);
265
+ }
266
+ }
267
+ // Verify that Node.js fs operations use UTF-8 by default
268
+ // This is always true in Node.js >= 18
269
+ return {
270
+ encoding: "utf-8",
271
+ warnings,
272
+ };
273
+ }
@@ -28,6 +28,8 @@ import { getTaskSummary } from "../tools/getTaskSummary.js";
28
28
  import { waitForTask } from "../tools/waitForTask.js";
29
29
  import { errorPayload, PatchWardenError } from "../errors.js";
30
30
  import { auditTask } from "../tools/auditTask.js";
31
+ import { safeStatus } from "../tools/safeStatus.js";
32
+ import { logger } from "../logging.js";
31
33
  import { runTask } from "../runner/runTask.js";
32
34
  import { createDirectSession } from "../tools/createDirectSession.js";
33
35
  import { searchWorkspace } from "../tools/searchWorkspace.js";
@@ -35,6 +37,7 @@ import { applyPatch } from "../tools/applyPatch.js";
35
37
  import { runVerification } from "../tools/runVerification.js";
36
38
  import { finalizeDirectSession } from "../tools/finalizeDirectSession.js";
37
39
  import { auditSession } from "../tools/auditSession.js";
40
+ import { syncFile } from "../tools/syncFile.js";
38
41
  import { TASK_TEMPLATE_NAMES } from "./taskTemplates.js";
39
42
  import {
40
43
  buildToolCatalogSnapshot,
@@ -415,6 +418,18 @@ export function getToolDefs(): ToolDef[] {
415
418
  required: ["task_id"],
416
419
  },
417
420
  },
421
+ {
422
+ name: "safe_status",
423
+ description:
424
+ "Return minimal task lifecycle status without exposing diff, log content, file contents, or sensitive paths. Use this when only task state is needed and content-bearing tools may be blocked by upper-layer security.",
425
+ inputSchema: {
426
+ type: "object",
427
+ properties: {
428
+ task_id: { type: "string", description: "Task ID to check" },
429
+ },
430
+ required: ["task_id"],
431
+ },
432
+ },
418
433
  ];
419
434
 
420
435
  // Direct session tools
@@ -534,6 +549,23 @@ export function getToolDefs(): ToolDef[] {
534
549
  },
535
550
  });
536
551
 
552
+ tools.push({
553
+ name: "sync_file",
554
+ description:
555
+ "Copy a file from source to target within the same Direct session repo. Both paths must be inside the session repo_path. Returns before/after sha256 hashes and whether the target changed.",
556
+ inputSchema: {
557
+ type: "object",
558
+ properties: {
559
+ session_id: { type: "string", description: "Direct session ID" },
560
+ source_path: { type: "string", description: "Relative path to source file within repo" },
561
+ target_path: { type: "string", description: "Relative path to target file within repo" },
562
+ expected_source_sha256: { type: "string", description: "Optional: expected sha256 of source file" },
563
+ expected_target_sha256: { type: "string", description: "Optional: expected sha256 of target file before copy" },
564
+ },
565
+ required: ["session_id", "source_path", "target_path"],
566
+ },
567
+ });
568
+
537
569
  // run_task: only available when explicitly enabled
538
570
  if ((config as any).enableRunTaskTool === true) {
539
571
  tools.push({
@@ -578,6 +610,20 @@ function guardDirectProfileEnabled(): void {
578
610
  }
579
611
 
580
612
  export async function handleToolCall(name: string, args: Record<string, unknown> | undefined) {
613
+ const startTime = Date.now();
614
+ const taskId = args?.task_id ? String(args.task_id) : args?.session_id ? String(args.session_id) : undefined;
615
+ try {
616
+ const result = await handleToolCallInternal(name, args);
617
+ logger.audit(name, true, Date.now() - startTime, undefined, taskId);
618
+ return result;
619
+ } catch (err) {
620
+ const errorReason = err instanceof Error ? err.message : String(err);
621
+ logger.audit(name, false, Date.now() - startTime, errorReason, taskId);
622
+ throw err;
623
+ }
624
+ }
625
+
626
+ async function handleToolCallInternal(name: string, args: Record<string, unknown> | undefined) {
581
627
  switch (name) {
582
628
  case "save_plan": {
583
629
  return toResult(
@@ -725,6 +771,10 @@ export async function handleToolCall(name: string, args: Record<string, unknown>
725
771
  return toResult(auditTask(String(args?.task_id ?? "")));
726
772
  }
727
773
 
774
+ case "safe_status": {
775
+ return toResult(safeStatus(String(args?.task_id ?? "")));
776
+ }
777
+
728
778
  case "run_task": {
729
779
  const config = getConfig();
730
780
  if ((config as any).enableRunTaskTool !== true) {
@@ -790,6 +840,19 @@ export async function handleToolCall(name: string, args: Record<string, unknown>
790
840
  }));
791
841
  }
792
842
 
843
+ case "sync_file": {
844
+ guardDirectProfileEnabled();
845
+ return toResult(syncFile(
846
+ String(args?.session_id ?? ""),
847
+ String(args?.source_path ?? ""),
848
+ String(args?.target_path ?? ""),
849
+ {
850
+ expected_source_sha256: args?.expected_source_sha256 ? String(args.expected_source_sha256) : undefined,
851
+ expected_target_sha256: args?.expected_target_sha256 ? String(args.expected_target_sha256) : undefined,
852
+ }
853
+ ));
854
+ }
855
+
793
856
  default:
794
857
  throw new Error(`Unknown tool: ${name}`);
795
858
  }