patchwarden 0.4.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/PatchWarden.cmd +51 -0
  2. package/README.en.md +1022 -0
  3. package/README.md +897 -358
  4. package/dist/assessments/agentAssessor.d.ts +15 -0
  5. package/dist/assessments/agentAssessor.js +293 -0
  6. package/dist/assessments/assessmentStore.d.ts +133 -0
  7. package/dist/assessments/assessmentStore.js +238 -0
  8. package/dist/assessments/confirmCli.d.ts +9 -0
  9. package/dist/assessments/confirmCli.js +26 -0
  10. package/dist/config.d.ts +22 -1
  11. package/dist/config.js +156 -3
  12. package/dist/direct/directAudit.d.ts +23 -0
  13. package/dist/direct/directAudit.js +309 -0
  14. package/dist/direct/directGuards.d.ts +20 -0
  15. package/dist/direct/directGuards.js +137 -0
  16. package/dist/direct/directPatch.d.ts +17 -0
  17. package/dist/direct/directPatch.js +113 -0
  18. package/dist/direct/directSessionStore.d.ts +63 -0
  19. package/dist/direct/directSessionStore.js +192 -0
  20. package/dist/direct/directVerification.d.ts +12 -0
  21. package/dist/direct/directVerification.js +96 -0
  22. package/dist/doctor.js +73 -5
  23. package/dist/logging.d.ts +52 -0
  24. package/dist/logging.js +123 -0
  25. package/dist/runner/agentInvocation.d.ts +23 -0
  26. package/dist/runner/agentInvocation.js +106 -0
  27. package/dist/runner/changeCapture.d.ts +70 -0
  28. package/dist/runner/changeCapture.js +278 -6
  29. package/dist/runner/runTask.js +271 -65
  30. package/dist/runner/simpleProcess.d.ts +21 -0
  31. package/dist/runner/simpleProcess.js +206 -0
  32. package/dist/runner/watch.js +17 -2
  33. package/dist/security/commandGuard.d.ts +2 -1
  34. package/dist/security/commandGuard.js +25 -3
  35. package/dist/security/riskEngine.d.ts +27 -0
  36. package/dist/security/riskEngine.js +118 -0
  37. package/dist/security/runtimeGuard.d.ts +6 -0
  38. package/dist/security/runtimeGuard.js +28 -0
  39. package/dist/smoke-test.js +1353 -7
  40. package/dist/test/unit/android-doctor.test.d.ts +1 -0
  41. package/dist/test/unit/android-doctor.test.js +118 -0
  42. package/dist/test/unit/chinese-path.test.d.ts +1 -0
  43. package/dist/test/unit/chinese-path.test.js +91 -0
  44. package/dist/test/unit/command-guard.test.d.ts +1 -0
  45. package/dist/test/unit/command-guard.test.js +160 -0
  46. package/dist/test/unit/direct-guards.test.d.ts +1 -0
  47. package/dist/test/unit/direct-guards.test.js +213 -0
  48. package/dist/test/unit/logging.test.d.ts +1 -0
  49. package/dist/test/unit/logging.test.js +275 -0
  50. package/dist/test/unit/path-guard.test.d.ts +1 -0
  51. package/dist/test/unit/path-guard.test.js +109 -0
  52. package/dist/test/unit/safe-status.test.d.ts +1 -0
  53. package/dist/test/unit/safe-status.test.js +165 -0
  54. package/dist/test/unit/sensitive-guard.test.d.ts +1 -0
  55. package/dist/test/unit/sensitive-guard.test.js +104 -0
  56. package/dist/test/unit/sync-file.test.d.ts +1 -0
  57. package/dist/test/unit/sync-file.test.js +154 -0
  58. package/dist/test/unit/watcher-status.test.d.ts +1 -0
  59. package/dist/test/unit/watcher-status.test.js +169 -0
  60. package/dist/tools/androidDoctor.d.ts +38 -0
  61. package/dist/tools/androidDoctor.js +391 -0
  62. package/dist/tools/applyPatch.d.ts +16 -0
  63. package/dist/tools/applyPatch.js +41 -0
  64. package/dist/tools/auditSession.d.ts +5 -0
  65. package/dist/tools/auditSession.js +12 -0
  66. package/dist/tools/auditTask.d.ts +7 -0
  67. package/dist/tools/auditTask.js +105 -7
  68. package/dist/tools/createDirectSession.d.ts +14 -0
  69. package/dist/tools/createDirectSession.js +54 -0
  70. package/dist/tools/createTask.d.ts +48 -1
  71. package/dist/tools/createTask.js +298 -47
  72. package/dist/tools/finalizeDirectSession.d.ts +19 -0
  73. package/dist/tools/finalizeDirectSession.js +84 -0
  74. package/dist/tools/getTaskSummary.d.ts +50 -0
  75. package/dist/tools/getTaskSummary.js +79 -2
  76. package/dist/tools/healthCheck.d.ts +27 -12
  77. package/dist/tools/healthCheck.js +44 -6
  78. package/dist/tools/readWorkspaceFile.d.ts +7 -1
  79. package/dist/tools/readWorkspaceFile.js +48 -2
  80. package/dist/tools/registry.js +270 -19
  81. package/dist/tools/runVerification.d.ts +16 -0
  82. package/dist/tools/runVerification.js +32 -0
  83. package/dist/tools/safeStatus.d.ts +19 -0
  84. package/dist/tools/safeStatus.js +72 -0
  85. package/dist/tools/savePlan.d.ts +1 -0
  86. package/dist/tools/savePlan.js +38 -7
  87. package/dist/tools/searchWorkspace.d.ts +19 -0
  88. package/dist/tools/searchWorkspace.js +205 -0
  89. package/dist/tools/syncFile.d.ts +18 -0
  90. package/dist/tools/syncFile.js +65 -0
  91. package/dist/tools/taskOutputs.d.ts +2 -2
  92. package/dist/tools/taskTemplates.js +2 -1
  93. package/dist/tools/toolCatalog.d.ts +4 -3
  94. package/dist/tools/toolCatalog.js +34 -5
  95. package/dist/tools/waitForTask.d.ts +2 -2
  96. package/dist/tools/waitForTask.js +1 -1
  97. package/dist/version.d.ts +2 -2
  98. package/dist/version.js +2 -2
  99. package/dist/watcherStatus.d.ts +1 -0
  100. package/dist/watcherStatus.js +96 -4
  101. package/docs/chatgpt-usage.md +101 -0
  102. package/docs/performance-notes.md +55 -0
  103. package/docs/release-checklist.md +14 -0
  104. package/docs/release-v0.6.0.md +71 -0
  105. package/docs/release-v0.6.1.md +75 -0
  106. package/examples/config.example.json +5 -0
  107. package/examples/openai-tunnel/README.md +11 -4
  108. package/examples/openai-tunnel/chatgpt-test-prompt.md +18 -14
  109. package/examples/openai-tunnel/tunnel-client.example.yaml +8 -0
  110. package/package.json +13 -8
  111. package/scripts/brand-check.js +58 -12
  112. package/scripts/control-smoke.js +206 -0
  113. package/scripts/http-mcp-smoke.js +10 -2
  114. package/scripts/launchers/Check-PatchWarden-Health.cmd +6 -0
  115. package/scripts/launchers/Reset-PatchWarden-Tunnel-Key.cmd +6 -0
  116. package/scripts/launchers/Restart-PatchWarden.cmd +6 -0
  117. package/scripts/launchers/Start-PatchWarden-Direct-Tunnel.cmd +7 -0
  118. package/scripts/launchers/Start-PatchWarden-Tunnel.cmd +7 -0
  119. package/scripts/lifecycle-smoke.js +402 -8
  120. package/scripts/manage-patchwarden.ps1 +639 -0
  121. package/scripts/mcp-manifest-check.js +123 -58
  122. package/scripts/mcp-smoke.js +160 -2
  123. package/scripts/pack-clean.js +160 -5
  124. package/scripts/package-manifest-check.js +78 -0
  125. package/scripts/patchwarden-mcp-direct.cmd +7 -0
  126. package/scripts/patchwarden-mcp-stdio.cmd +1 -1
  127. package/scripts/restart-patchwarden.ps1 +5 -4
  128. package/scripts/start-patchwarden-tunnel.ps1 +261 -30
  129. package/scripts/tunnel-supervisor-smoke.js +36 -4
  130. package/scripts/unit-tests.js +36 -0
  131. package/scripts/watcher-supervisor-smoke.js +10 -6
  132. package/src/assessments/agentAssessor.ts +324 -0
  133. package/src/assessments/assessmentStore.ts +426 -0
  134. package/src/assessments/confirmCli.ts +29 -0
  135. package/src/config.ts +178 -4
  136. package/src/direct/directAudit.ts +400 -0
  137. package/src/direct/directGuards.ts +279 -0
  138. package/src/direct/directPatch.ts +258 -0
  139. package/src/direct/directSessionStore.ts +345 -0
  140. package/src/direct/directVerification.ts +138 -0
  141. package/src/doctor.ts +103 -7
  142. package/src/logging.ts +152 -0
  143. package/src/runner/agentInvocation.ts +125 -0
  144. package/src/runner/changeCapture.ts +352 -6
  145. package/src/runner/runTask.ts +279 -63
  146. package/src/runner/simpleProcess.ts +223 -0
  147. package/src/runner/watch.ts +18 -2
  148. package/src/security/commandGuard.ts +46 -4
  149. package/src/security/riskEngine.ts +160 -0
  150. package/src/security/runtimeGuard.ts +41 -0
  151. package/src/smoke-test.ts +1291 -4
  152. package/src/test/unit/android-doctor.test.ts +158 -0
  153. package/src/test/unit/chinese-path.test.ts +106 -0
  154. package/src/test/unit/command-guard.test.ts +221 -0
  155. package/src/test/unit/direct-guards.test.ts +297 -0
  156. package/src/test/unit/logging.test.ts +325 -0
  157. package/src/test/unit/path-guard.test.ts +150 -0
  158. package/src/test/unit/safe-status.test.ts +187 -0
  159. package/src/test/unit/sensitive-guard.test.ts +124 -0
  160. package/src/test/unit/sync-file.test.ts +231 -0
  161. package/src/test/unit/watcher-status.test.ts +190 -0
  162. package/src/tools/androidDoctor.ts +424 -0
  163. package/src/tools/applyPatch.ts +86 -0
  164. package/src/tools/auditSession.ts +28 -0
  165. package/src/tools/auditTask.ts +111 -7
  166. package/src/tools/createDirectSession.ts +113 -0
  167. package/src/tools/createTask.ts +405 -55
  168. package/src/tools/finalizeDirectSession.ts +144 -0
  169. package/src/tools/getTaskSummary.ts +133 -2
  170. package/src/tools/healthCheck.ts +45 -6
  171. package/src/tools/readWorkspaceFile.ts +85 -2
  172. package/src/tools/registry.ts +305 -19
  173. package/src/tools/runVerification.ts +58 -0
  174. package/src/tools/safeStatus.ts +96 -0
  175. package/src/tools/savePlan.ts +57 -7
  176. package/src/tools/searchWorkspace.ts +275 -0
  177. package/src/tools/syncFile.ts +122 -0
  178. package/src/tools/taskTemplates.ts +2 -1
  179. package/src/tools/toolCatalog.ts +37 -6
  180. package/src/tools/waitForTask.ts +3 -3
  181. package/src/version.ts +2 -2
  182. package/src/watcherStatus.ts +101 -4
  183. package/tsconfig.json +18 -17
  184. package/Check-PatchWarden-Health.cmd +0 -6
  185. package/Reset-PatchWarden-Tunnel-Key.cmd +0 -6
  186. package/Restart-PatchWarden.cmd +0 -19
  187. package/Start-PatchWarden-Tunnel.cmd +0 -7
  188. package/docs/release-v0.3.0.md +0 -43
  189. package/docs/release-v0.4.0.md +0 -74
@@ -0,0 +1,391 @@
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
+ import { execSync } from "node:child_process";
11
+ import { existsSync, readFileSync, statSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ // ── Constants ──────────────────────────────────────────────────────
14
+ /**
15
+ * Required explanatory sentence emitted whenever the Android SDK is missing.
16
+ * Callers rely on this exact wording to detect the "SDK missing" condition.
17
+ */
18
+ const SDK_MISSING_REASON = "Android project exists, APK not built because Android SDK is missing.";
19
+ // ── Helpers ────────────────────────────────────────────────────────
20
+ /**
21
+ * Run a shell command and return its trimmed combined stdout/stderr output.
22
+ * Returns an empty string when the command is missing or fails so callers can
23
+ * treat absence gracefully. A timeout guards against hanging processes.
24
+ */
25
+ function runCmd(cmdStr) {
26
+ try {
27
+ return execSync(cmdStr, {
28
+ encoding: "utf-8",
29
+ timeout: 8000,
30
+ stdio: ["ignore", "pipe", "ignore"],
31
+ }).trim();
32
+ }
33
+ catch {
34
+ return "";
35
+ }
36
+ }
37
+ /** True when `path` exists and is a directory. Never throws. */
38
+ function isDirectory(path) {
39
+ try {
40
+ return existsSync(path) && statSync(path).isDirectory();
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ }
46
+ /** Extract the quoted version token from `java -version` output. */
47
+ function parseJavaVersion(output) {
48
+ const match = output.match(/version "([^"]+)"/);
49
+ return match ? match[1] : null;
50
+ }
51
+ /**
52
+ * Convert a Java version string to its major version number.
53
+ * "17.0.1" -> 17, "21" -> 21, "1.8.0_292" -> 8 (legacy 1.x scheme).
54
+ */
55
+ function parseJavaMajor(version) {
56
+ const match = version.match(/^(\d+)(?:\.(\d+))?/);
57
+ if (!match)
58
+ return null;
59
+ const major = parseInt(match[1], 10);
60
+ if (major === 1 && match[2])
61
+ return parseInt(match[2], 10);
62
+ return major;
63
+ }
64
+ /** Safely read a UTF-8 file, returning null on any error. */
65
+ function readTextFile(path) {
66
+ try {
67
+ return readFileSync(path, "utf-8");
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ }
73
+ // ── Public API ─────────────────────────────────────────────────────
74
+ /**
75
+ * Diagnose the Android build readiness for the repository at `repoPath`.
76
+ *
77
+ * - If `<repoPath>/android_app` does not exist, returns a skip result.
78
+ * - Otherwise runs 10 read-only checks and returns a structured report with an
79
+ * overall status: "fail" if any check failed, "warn" if any warned, else "ok".
80
+ *
81
+ * This function performs no mutations: it does not download the SDK, change env
82
+ * vars, or install dependencies.
83
+ */
84
+ export function diagnoseAndroidBuild(repoPath) {
85
+ const androidAppPath = join(repoPath, "android_app");
86
+ if (!isDirectory(androidAppPath)) {
87
+ return { status: "skip", reason: "No android_app directory found" };
88
+ }
89
+ const checks = [];
90
+ const checkedAt = new Date().toISOString();
91
+ // Resolve the Android SDK location. ANDROID_HOME is preferred; ANDROID_SDK_ROOT
92
+ // is a legacy fallback that some tools still honor.
93
+ const androidHomeEnv = process.env.ANDROID_HOME || "";
94
+ const androidSdkRootEnv = process.env.ANDROID_SDK_ROOT || "";
95
+ const sdkRoot = androidHomeEnv || androidSdkRootEnv;
96
+ const sdkExists = sdkRoot !== "" && isDirectory(sdkRoot);
97
+ // 1. java -version ------------------------------------------------------
98
+ // `java -version` writes to stderr; redirect with 2>&1 so execSync captures it.
99
+ const javaOutput = runCmd("java -version 2>&1");
100
+ const javaVersion = parseJavaVersion(javaOutput);
101
+ if (javaVersion) {
102
+ const major = parseJavaMajor(javaVersion);
103
+ if (major !== null && major < 17) {
104
+ checks.push({
105
+ check: "java -version",
106
+ status: "warn",
107
+ reason: `Java ${javaVersion} found. Modern Android Gradle Plugin (8.x) requires JDK 17+.`,
108
+ suggested_fix: "Install JDK 17 or newer and place it first on PATH (or point JAVA_HOME at it).",
109
+ });
110
+ }
111
+ else {
112
+ checks.push({
113
+ check: "java -version",
114
+ status: "ok",
115
+ reason: `Java ${javaVersion} is available on PATH.`,
116
+ suggested_fix: "",
117
+ });
118
+ }
119
+ }
120
+ else {
121
+ checks.push({
122
+ check: "java -version",
123
+ status: "fail",
124
+ reason: "java command not found or did not report a version.",
125
+ suggested_fix: "Install a JDK (17+ recommended for modern Android) and add its bin directory to PATH.",
126
+ });
127
+ }
128
+ // 2. JAVA_HOME ----------------------------------------------------------
129
+ const javaHome = process.env.JAVA_HOME || "";
130
+ if (javaHome && isDirectory(javaHome)) {
131
+ checks.push({
132
+ check: "JAVA_HOME",
133
+ status: "ok",
134
+ reason: `JAVA_HOME is set to ${javaHome}.`,
135
+ suggested_fix: "",
136
+ });
137
+ }
138
+ else if (javaHome) {
139
+ checks.push({
140
+ check: "JAVA_HOME",
141
+ status: "warn",
142
+ reason: `JAVA_HOME is set to "${javaHome}" but that directory does not exist.`,
143
+ suggested_fix: "Point JAVA_HOME at a valid JDK installation directory.",
144
+ });
145
+ }
146
+ else {
147
+ checks.push({
148
+ check: "JAVA_HOME",
149
+ status: "warn",
150
+ reason: "JAVA_HOME is not set. Gradle may be unable to locate the JDK.",
151
+ suggested_fix: "Set JAVA_HOME to your JDK installation (e.g. C:\\Program Files\\Java\\jdk-17).",
152
+ });
153
+ }
154
+ // 3. ANDROID_HOME -------------------------------------------------------
155
+ if (!androidHomeEnv) {
156
+ if (!sdkExists) {
157
+ checks.push({
158
+ check: "ANDROID_HOME",
159
+ status: "fail",
160
+ reason: `ANDROID_HOME is not set. ${SDK_MISSING_REASON}`,
161
+ suggested_fix: "Install the Android SDK and set ANDROID_HOME to its root directory " +
162
+ "(e.g. C:\\Users\\<you>\\AppData\\Local\\Android\\Sdk).",
163
+ });
164
+ }
165
+ else {
166
+ checks.push({
167
+ check: "ANDROID_HOME",
168
+ status: "warn",
169
+ reason: "ANDROID_HOME is not set. ANDROID_SDK_ROOT points at an SDK, but ANDROID_HOME is the preferred variable.",
170
+ suggested_fix: "Set ANDROID_HOME to the same value as ANDROID_SDK_ROOT.",
171
+ });
172
+ }
173
+ }
174
+ else if (!isDirectory(androidHomeEnv)) {
175
+ checks.push({
176
+ check: "ANDROID_HOME",
177
+ status: "fail",
178
+ reason: `ANDROID_HOME is set to "${androidHomeEnv}" but that directory does not exist.` +
179
+ (sdkExists ? "" : ` ${SDK_MISSING_REASON}`),
180
+ suggested_fix: "Install the Android SDK at the ANDROID_HOME path, or correct the variable to point at an existing SDK.",
181
+ });
182
+ }
183
+ else {
184
+ checks.push({
185
+ check: "ANDROID_HOME",
186
+ status: "ok",
187
+ reason: `ANDROID_HOME is set to ${androidHomeEnv}.`,
188
+ suggested_fix: "",
189
+ });
190
+ }
191
+ // 4. ANDROID_SDK_ROOT ---------------------------------------------------
192
+ if (androidSdkRootEnv && isDirectory(androidSdkRootEnv)) {
193
+ checks.push({
194
+ check: "ANDROID_SDK_ROOT",
195
+ status: "ok",
196
+ reason: `ANDROID_SDK_ROOT is set to ${androidSdkRootEnv}.`,
197
+ suggested_fix: "",
198
+ });
199
+ }
200
+ else if (androidSdkRootEnv) {
201
+ checks.push({
202
+ check: "ANDROID_SDK_ROOT",
203
+ status: "warn",
204
+ reason: `ANDROID_SDK_ROOT is set to "${androidSdkRootEnv}" but that directory does not exist.`,
205
+ suggested_fix: "Point ANDROID_SDK_ROOT at a valid Android SDK directory.",
206
+ });
207
+ }
208
+ else {
209
+ checks.push({
210
+ check: "ANDROID_SDK_ROOT",
211
+ status: "warn",
212
+ reason: "ANDROID_SDK_ROOT is not set. Some tools fall back to ANDROID_HOME, but setting both is recommended.",
213
+ suggested_fix: "Set ANDROID_SDK_ROOT to the same value as ANDROID_HOME.",
214
+ });
215
+ }
216
+ // 5. Android SDK platform ----------------------------------------------
217
+ if (!sdkExists) {
218
+ checks.push({
219
+ check: "Android SDK platform",
220
+ status: "skip",
221
+ reason: `Skipped: Android SDK not available. ${SDK_MISSING_REASON}`,
222
+ suggested_fix: "Install the Android SDK and a platform via sdkmanager.",
223
+ });
224
+ }
225
+ else {
226
+ const platformsDir = join(sdkRoot, "platforms");
227
+ if (isDirectory(platformsDir)) {
228
+ checks.push({
229
+ check: "Android SDK platform",
230
+ status: "ok",
231
+ reason: `Android SDK platforms directory found at ${platformsDir}.`,
232
+ suggested_fix: "",
233
+ });
234
+ }
235
+ else {
236
+ checks.push({
237
+ check: "Android SDK platform",
238
+ status: "warn",
239
+ reason: `No platforms directory found at ${platformsDir}. No Android platform is installed.`,
240
+ suggested_fix: 'Run: sdkmanager "platforms;android-34"',
241
+ });
242
+ }
243
+ }
244
+ // 6. Android build-tools ------------------------------------------------
245
+ if (!sdkExists) {
246
+ checks.push({
247
+ check: "Android build-tools",
248
+ status: "skip",
249
+ reason: `Skipped: Android SDK not available. ${SDK_MISSING_REASON}`,
250
+ suggested_fix: "Install the Android SDK and build-tools via sdkmanager.",
251
+ });
252
+ }
253
+ else {
254
+ const buildToolsDir = join(sdkRoot, "build-tools");
255
+ if (isDirectory(buildToolsDir)) {
256
+ checks.push({
257
+ check: "Android build-tools",
258
+ status: "ok",
259
+ reason: `Android build-tools directory found at ${buildToolsDir}.`,
260
+ suggested_fix: "",
261
+ });
262
+ }
263
+ else {
264
+ checks.push({
265
+ check: "Android build-tools",
266
+ status: "warn",
267
+ reason: `No build-tools directory found at ${buildToolsDir}.`,
268
+ suggested_fix: 'Run: sdkmanager "build-tools;34.0.0"',
269
+ });
270
+ }
271
+ }
272
+ // 7. Gradle wrapper -----------------------------------------------------
273
+ const gradlewUnix = join(androidAppPath, "gradlew");
274
+ const gradlewWin = join(androidAppPath, "gradlew.bat");
275
+ const wrapperProps = join(androidAppPath, "gradle", "wrapper", "gradle-wrapper.properties");
276
+ let gradleVersion = null;
277
+ const propsContent = readTextFile(wrapperProps);
278
+ if (propsContent) {
279
+ const match = propsContent.match(/gradle-([\d.]+)-/);
280
+ gradleVersion = match ? match[1] : null;
281
+ }
282
+ if (existsSync(gradlewUnix) || existsSync(gradlewWin)) {
283
+ checks.push({
284
+ check: "Gradle wrapper",
285
+ status: "ok",
286
+ reason: gradleVersion
287
+ ? `Gradle wrapper found in android_app (Gradle ${gradleVersion}).`
288
+ : "Gradle wrapper found in android_app.",
289
+ suggested_fix: "",
290
+ });
291
+ }
292
+ else {
293
+ checks.push({
294
+ check: "Gradle wrapper",
295
+ status: "warn",
296
+ reason: "No gradlew or gradlew.bat found in android_app.",
297
+ suggested_fix: "Generate the wrapper inside android_app with: gradle wrapper (or copy gradlew/gradlew.bat/gradle-wrapper.jar from an existing project).",
298
+ });
299
+ }
300
+ // 8. settings.gradle.kts -----------------------------------------------
301
+ const settingsGradleKts = join(androidAppPath, "settings.gradle.kts");
302
+ const settingsGradleGroovy = join(androidAppPath, "settings.gradle");
303
+ if (existsSync(settingsGradleKts)) {
304
+ checks.push({
305
+ check: "android_app/settings.gradle.kts",
306
+ status: "ok",
307
+ reason: "settings.gradle.kts found in android_app.",
308
+ suggested_fix: "",
309
+ });
310
+ }
311
+ else if (existsSync(settingsGradleGroovy)) {
312
+ checks.push({
313
+ check: "android_app/settings.gradle.kts",
314
+ status: "warn",
315
+ reason: "settings.gradle.kts not found, but settings.gradle (Groovy DSL) is present.",
316
+ suggested_fix: "Kotlin DSL is preferred; consider migrating settings.gradle to settings.gradle.kts.",
317
+ });
318
+ }
319
+ else {
320
+ checks.push({
321
+ check: "android_app/settings.gradle.kts",
322
+ status: "warn",
323
+ reason: "settings.gradle.kts not found in android_app.",
324
+ suggested_fix: "Create android_app/settings.gradle.kts declaring the project modules.",
325
+ });
326
+ }
327
+ // 9. app/build.gradle.kts ----------------------------------------------
328
+ const appBuildGradleKts = join(androidAppPath, "app", "build.gradle.kts");
329
+ const appBuildGradleGroovy = join(androidAppPath, "app", "build.gradle");
330
+ if (existsSync(appBuildGradleKts)) {
331
+ checks.push({
332
+ check: "android_app/app/build.gradle.kts",
333
+ status: "ok",
334
+ reason: "app/build.gradle.kts found.",
335
+ suggested_fix: "",
336
+ });
337
+ }
338
+ else if (existsSync(appBuildGradleGroovy)) {
339
+ checks.push({
340
+ check: "android_app/app/build.gradle.kts",
341
+ status: "warn",
342
+ reason: "app/build.gradle.kts not found, but app/build.gradle (Groovy DSL) is present.",
343
+ suggested_fix: "Kotlin DSL is preferred; consider migrating app/build.gradle to app/build.gradle.kts.",
344
+ });
345
+ }
346
+ else {
347
+ checks.push({
348
+ check: "android_app/app/build.gradle.kts",
349
+ status: "warn",
350
+ reason: "app/build.gradle.kts not found in android_app/app.",
351
+ suggested_fix: "Create android_app/app/build.gradle.kts with the Android application plugin and build config.",
352
+ });
353
+ }
354
+ // 10. APK output path ---------------------------------------------------
355
+ const apkDir = join(androidAppPath, "app", "build", "outputs", "apk");
356
+ if (!sdkExists) {
357
+ checks.push({
358
+ check: "APK output path",
359
+ status: "skip",
360
+ reason: SDK_MISSING_REASON,
361
+ suggested_fix: "Install the Android SDK, then build with: cd android_app && ./gradlew assembleDebug",
362
+ });
363
+ }
364
+ else if (isDirectory(apkDir)) {
365
+ checks.push({
366
+ check: "APK output path",
367
+ status: "ok",
368
+ reason: `APK output directory found at ${apkDir}.`,
369
+ suggested_fix: "",
370
+ });
371
+ }
372
+ else {
373
+ checks.push({
374
+ check: "APK output path",
375
+ status: "warn",
376
+ reason: "APK output directory not found. The project has not been built yet.",
377
+ suggested_fix: "Build the APK: cd android_app && ./gradlew assembleDebug",
378
+ });
379
+ }
380
+ // Overall status: fail dominates warn dominates ok.
381
+ const hasFail = checks.some((c) => c.status === "fail");
382
+ const hasWarn = checks.some((c) => c.status === "warn");
383
+ const overall = hasFail ? "fail" : hasWarn ? "warn" : "ok";
384
+ return {
385
+ status: overall,
386
+ repo_path: repoPath,
387
+ android_app_path: androidAppPath,
388
+ checks,
389
+ checked_at: checkedAt,
390
+ };
391
+ }
@@ -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,5 @@
1
+ import { type DirectSessionAuditOutput } from "../direct/directAudit.js";
2
+ export interface AuditSessionInput {
3
+ session_id: string;
4
+ }
5
+ export declare function auditSession(input: AuditSessionInput): DirectSessionAuditOutput;
@@ -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;