@mrclrchtr/supi-code-intelligence 11.0.1 → 11.2.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.
Files changed (200) hide show
  1. package/README.md +68 -6
  2. package/gradle-helper/README.md +48 -0
  3. package/gradle-helper/build.sh +73 -0
  4. package/gradle-helper/lib/gradle-tooling-api-9.4.0.jar +0 -0
  5. package/gradle-helper/lib/slf4j-api-2.0.17.jar +0 -0
  6. package/gradle-helper/lib/slf4j-simple-2.0.17.jar +0 -0
  7. package/gradle-helper/lib/supi-gradle-observation.jar +0 -0
  8. package/gradle-helper/licenses/DEPENDENCIES.md +11 -0
  9. package/gradle-helper/licenses/LICENSE-gradle-tooling-api.txt +422 -0
  10. package/gradle-helper/licenses/LICENSE-slf4j.txt +21 -0
  11. package/gradle-helper/licenses/NOTICE-gradle.txt +21 -0
  12. package/gradle-helper/src/GradleObservation.java +597 -0
  13. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  15. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  16. package/node_modules/@mrclrchtr/supi-lsp/README.md +43 -6
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/LICENSE +15 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/README.md +680 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/bin/semver.js +195 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/comparator.js +143 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/index.js +7 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +577 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/semver.js +350 -0
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/clean.js +8 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/cmp.js +54 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/coerce.js +62 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-build.js +9 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-loose.js +5 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare.js +7 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/diff.js +60 -0
  34. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/eq.js +5 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gt.js +5 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gte.js +5 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/inc.js +21 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lt.js +5 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lte.js +5 -0
  40. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/major.js +5 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/minor.js +5 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/neq.js +5 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/parse.js +18 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/patch.js +5 -0
  45. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/prerelease.js +8 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rcompare.js +5 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rsort.js +5 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/satisfies.js +12 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/sort.js +5 -0
  50. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/truncate.js +48 -0
  51. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/valid.js +8 -0
  52. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/index.js +93 -0
  53. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +37 -0
  54. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/debug.js +11 -0
  55. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/identifiers.js +29 -0
  56. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/lrucache.js +42 -0
  57. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/parse-options.js +17 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/re.js +223 -0
  59. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +78 -0
  60. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/preload.js +4 -0
  61. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/range.bnf +17 -0
  62. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/gtr.js +6 -0
  63. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/intersects.js +9 -0
  64. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/ltr.js +6 -0
  65. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/max-satisfying.js +27 -0
  66. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-satisfying.js +26 -0
  67. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-version.js +63 -0
  68. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/outside.js +82 -0
  69. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/simplify.js +49 -0
  70. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/subset.js +249 -0
  71. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/to-comparators.js +10 -0
  72. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/valid.js +13 -0
  73. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/README.md +5 -0
  74. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/browser/ril.js +8 -0
  75. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/connection.js +7 -2
  76. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/common/ral.d.ts +8 -0
  77. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.d.ts +14 -0
  78. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/main.js +6 -4
  79. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/lib/node/ril.js +5 -1
  80. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-jsonrpc/package.json +4 -2
  81. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-protocol/package.json +4 -3
  82. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/esm/main.js +2 -2
  83. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/lib/umd/main.js +2 -2
  84. package/node_modules/@mrclrchtr/supi-lsp/node_modules/vscode-languageserver-types/package.json +2 -1
  85. package/node_modules/@mrclrchtr/supi-lsp/package.json +8 -6
  86. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +44 -5
  87. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +53 -2
  88. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +19 -4
  89. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +22 -0
  90. package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-launch.ts +276 -0
  91. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +22 -10
  92. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +53 -20
  93. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +4 -3
  94. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +2 -2
  95. package/node_modules/@mrclrchtr/supi-lsp/src/session/scanner.ts +27 -15
  96. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -0
  97. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  98. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  99. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +41 -1
  100. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +5 -3
  101. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/LICENSE +21 -0
  102. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  103. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +19 -2
  104. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/LICENSE +21 -0
  105. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  106. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +19 -2
  107. package/node_modules/ignore/README.md +36 -10
  108. package/node_modules/ignore/index.d.ts +3 -2
  109. package/node_modules/ignore/index.js +57 -53
  110. package/node_modules/ignore/legacy.js +50 -46
  111. package/node_modules/ignore/package.json +1 -1
  112. package/package.json +11 -6
  113. package/src/analysis/capability/capability-warnings.ts +18 -12
  114. package/src/analysis/gradle/query.ts +273 -0
  115. package/src/analysis/gradle/runtime.ts +173 -0
  116. package/src/analysis/gradle/types.ts +65 -0
  117. package/src/analysis/health/check.ts +115 -0
  118. package/src/analysis/health/diagnostics.ts +3 -0
  119. package/src/analysis/health/file-scope.ts +2 -3
  120. package/src/analysis/health/semantic-state.ts +38 -0
  121. package/src/analysis/health/server-status.ts +8 -0
  122. package/src/analysis/health/signals.ts +2 -0
  123. package/src/analysis/health/status.ts +82 -0
  124. package/src/analysis/read-next.ts +1 -4
  125. package/src/analysis/refactor/apply.ts +19 -10
  126. package/src/analysis/refactor/mutation-authority.ts +4 -1
  127. package/src/analysis/search/ast-scan.ts +143 -18
  128. package/src/analysis/workspace/safe-path.ts +14 -2
  129. package/src/analysis/workspace/types.ts +2 -0
  130. package/src/extension.ts +10 -1
  131. package/src/gradle/consent.ts +279 -0
  132. package/src/headless.ts +3 -0
  133. package/src/overview/collect.ts +11 -3
  134. package/src/session/health-types.ts +7 -0
  135. package/src/session/health-workflow.ts +8 -43
  136. package/src/session/orientation/collect.ts +138 -12
  137. package/src/session/orientation/context-facts.ts +27 -2
  138. package/src/session/orientation/context-sections.ts +47 -0
  139. package/src/session/orientation/facts.ts +124 -0
  140. package/src/session/orientation/gather.ts +98 -11
  141. package/src/session/orientation/workspace-context.ts +59 -28
  142. package/src/session/orientation-types.ts +16 -1
  143. package/src/session/orientation-workflow.ts +5 -2
  144. package/src/session/refactor-plans.ts +5 -2
  145. package/src/session/refactor-workflow.ts +4 -3
  146. package/src/session/session.ts +8 -0
  147. package/src/tool/code_find/execute.ts +1 -1
  148. package/src/tool/code_find/guidance.ts +1 -1
  149. package/src/tool/code_find/markdown.ts +24 -17
  150. package/src/tool/code_find/result.ts +18 -5
  151. package/src/tool/code_find/spec.ts +2 -0
  152. package/src/tool/code_find/structured.ts +161 -0
  153. package/src/tool/code_graph/result.ts +32 -15
  154. package/src/tool/code_graph/spec.ts +2 -0
  155. package/src/tool/code_graph/structured.ts +142 -0
  156. package/src/tool/code_health/markdown.ts +17 -17
  157. package/src/tool/code_health/result.ts +15 -2
  158. package/src/tool/code_health/spec.ts +2 -0
  159. package/src/tool/code_health/structured-schema.ts +250 -0
  160. package/src/tool/code_health/structured.ts +256 -0
  161. package/src/tool/code_inspect/markdown.ts +19 -11
  162. package/src/tool/code_inspect/result.ts +12 -5
  163. package/src/tool/code_inspect/spec.ts +2 -0
  164. package/src/tool/code_inspect/structured.ts +232 -0
  165. package/src/tool/code_orientation/directory-navigation.ts +66 -0
  166. package/src/tool/code_orientation/gradle-sections.ts +68 -0
  167. package/src/tool/code_orientation/markdown.ts +19 -8
  168. package/src/tool/code_orientation/result.ts +95 -11
  169. package/src/tool/code_orientation/spec.ts +2 -0
  170. package/src/tool/code_orientation/structured-schema.ts +607 -0
  171. package/src/tool/code_orientation/structured-workspace.ts +193 -0
  172. package/src/tool/code_orientation/structured.ts +195 -0
  173. package/src/tool/code_orientation/workspace-format.ts +2 -1
  174. package/src/tool/code_orientation/workspace-observations.ts +81 -0
  175. package/src/tool/code_orientation/workspace-output.ts +45 -13
  176. package/src/tool/code_orientation/workspace-projects.ts +180 -75
  177. package/src/tool/code_orientation/workspace-sections.ts +46 -31
  178. package/src/tool/code_refactor_apply/execute.ts +1 -1
  179. package/src/tool/code_refactor_apply/result.ts +13 -5
  180. package/src/tool/code_refactor_apply/spec.ts +2 -0
  181. package/src/tool/code_refactor_apply/structured.ts +49 -0
  182. package/src/tool/code_refactor_plan/result.ts +16 -8
  183. package/src/tool/code_refactor_plan/spec.ts +2 -0
  184. package/src/tool/code_refactor_plan/structured.ts +128 -0
  185. package/src/tool/code_resolve/markdown.ts +4 -10
  186. package/src/tool/code_resolve/result.ts +2 -0
  187. package/src/tool/code_resolve/spec.ts +2 -0
  188. package/src/tool/code_resolve/structured.ts +103 -0
  189. package/src/tool/infra/truncate.ts +12 -4
  190. package/src/tool/register.ts +10 -6
  191. package/src/tool/result/display.ts +17 -0
  192. package/src/tool/result/model-budget.ts +195 -0
  193. package/src/tool/result/structured.ts +62 -0
  194. package/src/tool/result/types.ts +10 -2
  195. package/src/tool/schemas.ts +7 -1
  196. package/src/tool/specs.ts +2 -0
  197. package/src/types/execution.ts +5 -1
  198. package/src/ui/status-command.ts +110 -321
  199. package/src/ui/status-overlay.ts +564 -420
  200. package/src/ui/tui/display.ts +10 -4
@@ -0,0 +1,173 @@
1
+ import { constants, promises as fs } from "node:fs";
2
+ import * as path from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import { assertUnlinkedPath } from "../workspace/safe-path.ts";
5
+ import type { GradleRuntime } from "./types.ts";
6
+
7
+ /** A missing/incompatible prerequisite is evidence, not an empty Gradle build. */
8
+ export class GradlePrerequisiteError extends Error {
9
+ constructor(
10
+ readonly status: "unavailable" | "unsupported",
11
+ message: string,
12
+ options?: ErrorOptions,
13
+ ) {
14
+ super(message, options);
15
+ }
16
+ }
17
+
18
+ /** Require a settings file at exactly this root; never search ancestors or follow links. */
19
+ export async function hasGradleSettings(root: string): Promise<boolean> {
20
+ for (const name of ["settings.gradle", "settings.gradle.kts"]) {
21
+ try {
22
+ await assertUnlinkedPath(root, name, true);
23
+ if ((await fs.lstat(path.join(root, name))).isFile()) return true;
24
+ } catch (error) {
25
+ if (!isMissing(error)) throw error;
26
+ }
27
+ }
28
+ return false;
29
+ }
30
+
31
+ /** Select the wrapper distribution first, or a real PATH installation, without executing scripts. */
32
+ export async function selectGradleRuntime(
33
+ root: string,
34
+ searchPath = process.env.PATH ?? "",
35
+ ): Promise<GradleRuntime> {
36
+ return (await wrapperRuntime(root)) ?? pathRuntime(searchPath);
37
+ }
38
+
39
+ async function wrapperRuntime(root: string): Promise<GradleRuntime | undefined> {
40
+ const relative = "gradle/wrapper/gradle-wrapper.properties";
41
+ const properties = path.join(root, relative);
42
+ try {
43
+ await assertUnlinkedPath(root, relative, true);
44
+ const info = await fs.lstat(properties);
45
+ if (!info.isFile() || info.size > 1_048_576)
46
+ throw new GradlePrerequisiteError(
47
+ "unavailable",
48
+ "Wrapper properties must be a regular file no larger than 1 MiB.",
49
+ );
50
+ const values = parseProperties(await fs.readFile(properties, "latin1"));
51
+ const distribution = values.get("distributionUrl");
52
+ if (!distribution)
53
+ throw new GradlePrerequisiteError(
54
+ "unavailable",
55
+ "Wrapper properties have no distributionUrl; no PATH substitution was attempted.",
56
+ );
57
+ let url: URL;
58
+ try {
59
+ url = new URL(distribution, pathToFileURL(properties));
60
+ } catch (error) {
61
+ // biome-ignore lint/style/useErrorCause: This typed error accepts ErrorOptions as its third argument.
62
+ throw new GradlePrerequisiteError("unavailable", "Wrapper distributionUrl is unresolvable.", {
63
+ cause: error,
64
+ });
65
+ }
66
+ if (!["https:", "http:", "file:"].includes(url.protocol))
67
+ throw new GradlePrerequisiteError(
68
+ "unavailable",
69
+ "Wrapper distribution protocol is unsupported.",
70
+ );
71
+ const version = decodeURIComponent(url.pathname).match(
72
+ /(?:^|\/)gradle-(\d+\.\d+(?:\.\d+)?(?:-[A-Za-z0-9.-]+)?)-(?:bin|all)\.zip$/,
73
+ )?.[1];
74
+ if (!version)
75
+ throw new GradlePrerequisiteError(
76
+ "unavailable",
77
+ "Wrapper distribution version cannot be established from its URL; no fallback was used.",
78
+ );
79
+ requireGradle9(version);
80
+ if (url.protocol === "file:") await fs.access(fileURLToPath(url));
81
+ return { kind: "distribution", value: url.href, source: properties, version };
82
+ } catch (error) {
83
+ if (!isMissing(error)) throw error;
84
+ // A missing archive is not the same as missing wrapper properties.
85
+ if (await fs.lstat(properties).catch(() => null))
86
+ // biome-ignore lint/style/useErrorCause: This typed error accepts ErrorOptions as its third argument.
87
+ throw new GradlePrerequisiteError(
88
+ "unavailable",
89
+ "Wrapper distribution archive is missing; no fallback was used.",
90
+ { cause: error },
91
+ );
92
+ return undefined;
93
+ }
94
+ }
95
+
96
+ async function pathRuntime(searchPath: string): Promise<GradleRuntime> {
97
+ const executable = await findExecutable("gradle", searchPath);
98
+ if (!executable)
99
+ throw new GradlePrerequisiteError(
100
+ "unavailable",
101
+ "No wrapper properties or Gradle installation on PATH.",
102
+ );
103
+ const real = await fs.realpath(executable);
104
+ const home = path.dirname(path.dirname(real));
105
+ if (path.basename(path.dirname(real)) !== "bin")
106
+ throw new GradlePrerequisiteError(
107
+ "unavailable",
108
+ `PATH Gradle is not a resolvable installation: ${executable}. Put the selected installation's bin directory on PATH; shims are not executed.`,
109
+ );
110
+ const libs = await fs.readdir(path.join(home, "lib")).catch(() => []);
111
+ const versions = libs.flatMap((name) => name.match(/^gradle-launcher-(.+)\.jar$/)?.[1] ?? []);
112
+ if (versions.length !== 1)
113
+ throw new GradlePrerequisiteError(
114
+ "unavailable",
115
+ `PATH Gradle installation cannot be resolved: ${executable}. Version-manager shims are not executed.`,
116
+ );
117
+ requireGradle9(versions[0]);
118
+ return { kind: "installation", value: home, source: executable, version: versions[0] };
119
+ }
120
+
121
+ /** Resolve only existing executable files, preserving PATH precedence. */
122
+ export async function findExecutable(
123
+ name: string,
124
+ searchPath = process.env.PATH ?? "",
125
+ ): Promise<string | undefined> {
126
+ for (const directory of searchPath.split(path.delimiter)) {
127
+ if (!directory) continue;
128
+ const candidate = path.resolve(directory, process.platform === "win32" ? `${name}.exe` : name);
129
+ try {
130
+ await fs.access(candidate, constants.X_OK);
131
+ if ((await fs.stat(candidate)).isFile()) return candidate;
132
+ } catch {
133
+ /* Try the next PATH entry. */
134
+ }
135
+ }
136
+ return undefined;
137
+ }
138
+
139
+ /** Only Gradle 9 is supported, including when an explicit wrapper names another major. */
140
+ export function requireGradle9(version: string): void {
141
+ if (!/^9\./.test(version))
142
+ throw new GradlePrerequisiteError(
143
+ "unsupported",
144
+ `Gradle ${version} is unsupported; only Gradle 9 is supported. No fallback was used.`,
145
+ );
146
+ }
147
+
148
+ function isMissing(error: unknown): boolean {
149
+ return (error as NodeJS.ErrnoException).code === "ENOENT";
150
+ }
151
+
152
+ /** Java properties escapes and continuations, not a Groovy/Kotlin settings interpreter. */
153
+ function parseProperties(text: string): Map<string, string> {
154
+ const values = new Map<string, string>();
155
+ const lines = text.replace(/\r\n?/g, "\n").split("\n");
156
+ const decode = (value: string) =>
157
+ value.replace(
158
+ /\\u([0-9a-fA-F]{4})|\\(.)/g,
159
+ (_match, hex: string | undefined, escaped: string) =>
160
+ hex
161
+ ? String.fromCharCode(Number.parseInt(hex, 16))
162
+ : ({ t: "\t", r: "\r", n: "\n", f: "\f" }[escaped] ?? escaped),
163
+ );
164
+ for (let i = 0; i < lines.length; i++) {
165
+ let line = lines[i].trimStart();
166
+ if (/^[#!]/.test(line)) continue;
167
+ while ((line.match(/\\+$/)?.[0].length ?? 0) % 2 === 1 && i + 1 < lines.length)
168
+ line = line.slice(0, -1) + lines[++i].trimStart();
169
+ const match = line.match(/^((?:\\.|[^\s:=\\])+)(?:\s*[:=]\s*|\s+)?(.*)$/);
170
+ if (match) values.set(decode(match[1]), decode(match[2]));
171
+ }
172
+ return values;
173
+ }
@@ -0,0 +1,65 @@
1
+ import type { CodeRequestControl } from "@mrclrchtr/supi-code-runtime/api";
2
+
3
+ /** Explicitly selected runtime; the Tooling API client must never pick a fallback. */
4
+ export interface GradleRuntime {
5
+ readonly kind: "distribution" | "installation";
6
+ readonly value: string;
7
+ readonly source: string;
8
+ readonly version: string;
9
+ }
10
+
11
+ /** Gradle-reported identity, independent of a project's possibly duplicate name. */
12
+ export interface GradleProjectObservation {
13
+ readonly buildRoot: string;
14
+ readonly path: string;
15
+ readonly name: string;
16
+ readonly directory: string;
17
+ readonly parentPath: string | null;
18
+ }
19
+
20
+ /**
21
+ * Phase that established a limitation. Query confirms an attempted model request;
22
+ * unknown means collection failed without evidence of whether a request started.
23
+ */
24
+ export type GradleFailureStage = "authorization" | "prerequisites" | "query" | "unknown";
25
+
26
+ /** One selected-build query, not a parsed Project declaration or a filesystem inventory. */
27
+ export type GradleObservation = {
28
+ readonly selectedRoot: string;
29
+ readonly query: "GradleBuild/BasicGradleProject";
30
+ readonly runtime?: GradleRuntime;
31
+ } & (
32
+ | {
33
+ readonly status: "complete";
34
+ readonly gradleVersion: string;
35
+ readonly buildRoot: string;
36
+ readonly projects: readonly GradleProjectObservation[];
37
+ readonly includedBuilds: readonly { readonly buildRoot: string }[];
38
+ }
39
+ | {
40
+ readonly status:
41
+ | "blocked"
42
+ | "unavailable"
43
+ | "unsupported"
44
+ | "failed"
45
+ | "interrupted"
46
+ | "timeout"
47
+ | "oversized";
48
+ readonly reason: string;
49
+ readonly stage: GradleFailureStage;
50
+ /** Actual runtime version obtained before failure, not the declared distribution version. */
51
+ readonly gradleVersion?: string;
52
+ }
53
+ );
54
+
55
+ /** Owned query boundary shared by Overview and directory/workspace Orientation. */
56
+ export interface GradleObserver {
57
+ observe(root: string, control?: CodeRequestControl): Promise<GradleObservation | undefined>;
58
+ }
59
+
60
+ /** JVM process boundary; tests can supply a controlled process without simulating Gradle internals. */
61
+ export type GradleModelQuery = (
62
+ root: string,
63
+ runtime: GradleRuntime,
64
+ control?: CodeRequestControl,
65
+ ) => Promise<GradleObservation>;
@@ -0,0 +1,115 @@
1
+ import {
2
+ type CodeRequestControl,
3
+ isCodeRequestInterruption,
4
+ throwIfCodeRequestInterrupted,
5
+ } from "@mrclrchtr/supi-code-runtime/api";
6
+ import type {
7
+ BulkTrackFileOutcome,
8
+ DiagnosticEvidenceDocument,
9
+ WorkspaceLspRuntime,
10
+ } from "@mrclrchtr/supi-lsp/api";
11
+ import { collectScopedFileDiagnostics } from "./file-scope.ts";
12
+
13
+ /** Maximum eligible source files selected by one explicit inspector check. */
14
+ export const DIAGNOSTIC_CHECK_BATCH_SIZE = 32;
15
+
16
+ /** One selected source file, including candidates that could not be checked. */
17
+ export interface DiagnosticCheckFile {
18
+ readonly file: string;
19
+ readonly status: DiagnosticEvidenceDocument["status"] | "skipped" | "unavailable";
20
+ readonly reason?: string;
21
+ }
22
+
23
+ /** Bounded check coverage, separate from the runtime's tracked-file snapshot. */
24
+ export interface WorkspaceDiagnosticCheckReport {
25
+ readonly kind: "completed" | "partial";
26
+ readonly files: readonly DiagnosticCheckFile[];
27
+ /** Null when source discovery did not establish a complete inventory. */
28
+ readonly total: number | null;
29
+ readonly startOffset: number;
30
+ /** Continuation within the sorted inventory; zero starts another pass. */
31
+ readonly nextOffset: number;
32
+ readonly remaining: number | null;
33
+ readonly reason?: string;
34
+ }
35
+
36
+ /** Discover policy-eligible sources and request diagnostics for one bounded batch. */
37
+ export async function checkWorkspaceDiagnostics(options: {
38
+ readonly runtime: WorkspaceLspRuntime;
39
+ readonly cwd: string;
40
+ readonly offset: number;
41
+ readonly control: CodeRequestControl;
42
+ }): Promise<WorkspaceDiagnosticCheckReport> {
43
+ const { runtime, cwd, control } = options;
44
+ let total: number | null = null;
45
+ let startOffset = options.offset;
46
+ const files: DiagnosticCheckFile[] = [];
47
+ const report = (
48
+ kind: WorkspaceDiagnosticCheckReport["kind"],
49
+ reason?: string,
50
+ ): WorkspaceDiagnosticCheckReport => {
51
+ const end = startOffset + files.length;
52
+ return {
53
+ kind,
54
+ files,
55
+ total,
56
+ startOffset,
57
+ nextOffset: total !== null && end >= total ? 0 : end,
58
+ remaining: total === null ? null : Math.max(0, total - end),
59
+ ...(reason ? { reason } : {}),
60
+ };
61
+ };
62
+ try {
63
+ throwIfCodeRequestInterrupted(control);
64
+ const inventory = await runtime.scanWorkspaceSources(control);
65
+ throwIfCodeRequestInterrupted(control);
66
+ if (inventory.status !== "complete") {
67
+ return report(
68
+ "partial",
69
+ `Source discovery incomplete: ${inventory.reason} (${inventory.observedFileCount} files observed).`,
70
+ );
71
+ }
72
+ total = inventory.files.length;
73
+ startOffset = options.offset >= 0 && options.offset < total ? options.offset : 0;
74
+ const selected = inventory.files.slice(startOffset, startOffset + DIAGNOSTIC_CHECK_BATCH_SIZE);
75
+ const batch = await runtime.bulkTrackFiles(selected, control);
76
+ for (const outcome of batch.outcomes) {
77
+ throwIfCodeRequestInterrupted(control);
78
+ files.push(await checkFile(outcome, runtime, cwd, control));
79
+ }
80
+ throwIfCodeRequestInterrupted(control);
81
+ return report("completed");
82
+ } catch (error) {
83
+ if (control.signal?.aborted || !isCodeRequestInterruption(error, control)) throw error;
84
+ return report(
85
+ "partial",
86
+ "Check time limit reached; remaining files were not checked. Run Check again to continue.",
87
+ );
88
+ }
89
+ }
90
+
91
+ async function checkFile(
92
+ outcome: BulkTrackFileOutcome,
93
+ runtime: WorkspaceLspRuntime,
94
+ cwd: string,
95
+ control: CodeRequestControl,
96
+ ): Promise<DiagnosticCheckFile> {
97
+ if (outcome.kind === "skipped" || outcome.kind === "unavailable") {
98
+ return { file: outcome.file, status: outcome.kind, reason: outcome.reason };
99
+ }
100
+ const result = await collectScopedFileDiagnostics({
101
+ service: runtime,
102
+ scope: { kind: "file", path: outcome.file },
103
+ cwd,
104
+ requestControl: control,
105
+ });
106
+ if (result.kind === "not-requested")
107
+ throw new Error("Diagnostic check did not request diagnostics.");
108
+ return {
109
+ file: outcome.file,
110
+ status: result.evidence.documents[0]?.status ?? "failed",
111
+ ...(result.kind === "partial" || result.kind === "unavailable"
112
+ ? { reason: result.reason }
113
+ : {}),
114
+ };
115
+ }
@@ -310,6 +310,9 @@ function evidenceIsComplete(
310
310
  }
311
311
 
312
312
  function diagnosticEvidenceReason(evidence: DiagnosticEvidenceSummary): string {
313
+ if (evidence.requested === 0) {
314
+ return "No document-level diagnostic evidence was collected for this scope. An empty result does not establish that the scope is clean. Request diagnostics for an exact file.";
315
+ }
313
316
  let reason = `Diagnostic evidence is partial: ${evidence.requested} requested, ${evidence.confirmed} confirmed, ${evidence.unconfirmed} unconfirmed, ${evidence.failed} failed, ${evidence.removed} removed.`;
314
317
  if (evidence.unconfirmed > 0) {
315
318
  reason += " Unconfirmed documents have no request-based confirmation.";
@@ -26,6 +26,7 @@ import type {
26
26
  HealthDiagnosticObservation,
27
27
  HealthDiagnosticScope,
28
28
  } from "../../session/health-types.ts";
29
+ import { HEALTH_DIAGNOSTIC_MESSAGE_LIMIT } from "../../session/health-types.ts";
29
30
 
30
31
  /** Collect a live per-file diagnostic pull with an applicable config scope decision. */
31
32
  export async function collectScopedFileDiagnostics(options: {
@@ -114,8 +115,6 @@ export function toFileDiagnosticEntries(
114
115
 
115
116
  // ── Message extraction ────────────────────────────────────────────────
116
117
 
117
- const MAX_MESSAGES_PER_FILE = 3;
118
-
119
118
  function extractMessages(
120
119
  diagnostics: ReadonlyArray<Pick<Diagnostic, "severity" | "message" | "source" | "range">>,
121
120
  ): HealthDiagnosticMessage[] {
@@ -125,7 +124,7 @@ function extractMessages(
125
124
  (a, b) => (a.severity ?? 1) - (b.severity ?? 1) || a.range.start.line - b.range.start.line,
126
125
  );
127
126
 
128
- return errorsAndWarnings.slice(0, MAX_MESSAGES_PER_FILE).map((d) => ({
127
+ return errorsAndWarnings.slice(0, HEALTH_DIAGNOSTIC_MESSAGE_LIMIT).map((d) => ({
129
128
  line: d.range.start.line + 1,
130
129
  severity: (d.severity ?? 1) === 1 ? ("error" as const) : ("warning" as const),
131
130
  message: typeof d.message === "string" ? d.message : d.message.value,
@@ -0,0 +1,38 @@
1
+ import type { CapabilityState } from "@mrclrchtr/supi-code-runtime/api";
2
+ import type { ProjectServerInfo, WorkspaceLspRuntimeState } from "@mrclrchtr/supi-lsp/api";
3
+ import type { SemanticHealthState } from "../../session/health-types.ts";
4
+
5
+ /** Derive passive workspace readiness; a runtime owner alone is not a ready server. */
6
+ export function deriveWorkspaceSemanticHealthState(
7
+ lspState: WorkspaceLspRuntimeState,
8
+ capabilityState: CapabilityState,
9
+ servers: readonly Pick<ProjectServerInfo, "status" | "ready">[],
10
+ ): SemanticHealthState {
11
+ if (
12
+ lspState.kind === "ready" &&
13
+ servers.some((server) => server.status === "running" && server.ready)
14
+ ) {
15
+ return { kind: "ready" };
16
+ }
17
+ switch (lspState.kind) {
18
+ case "pending":
19
+ return { kind: "pending", reason: "LSP is starting" };
20
+ case "inactive":
21
+ return { kind: "inactive", reason: "Inactive on the current session branch" };
22
+ case "disabled":
23
+ return { kind: "disabled", reason: "Disabled by configuration" };
24
+ case "unavailable":
25
+ return { kind: "unavailable", reason: lspState.reason };
26
+ case "ready":
27
+ switch (capabilityState.kind) {
28
+ case "inactive":
29
+ return { kind: "inactive", reason: "Inactive on the current session branch" };
30
+ case "disabled":
31
+ return { kind: "disabled", reason: "Disabled by configuration" };
32
+ case "unavailable":
33
+ return { kind: "unavailable", reason: capabilityState.reason };
34
+ default:
35
+ return { kind: "pending", reason: "No active, ready project servers" };
36
+ }
37
+ }
38
+ }
@@ -67,6 +67,14 @@ export function formatProjectServerStatusReason(
67
67
  }
68
68
  }
69
69
 
70
+ /** Render the selected compiler without confusing a wrapper version with its implementation. */
71
+ export function formatProjectServerCompiler(
72
+ selection: ProjectServerInfo["typescript"],
73
+ ): string | null {
74
+ if (!selection) return null;
75
+ return `${selection.backend}: TypeScript ${selection.compilerVersion ?? "(unknown version)"} via ${selection.packageName}${selection.wrapperVersion ? ` (wrapper ${selection.wrapperVersion})` : ""}`;
76
+ }
77
+
70
78
  /** Render operation support without hiding server limits or SuPi limits. */
71
79
  export function formatProjectServerOperationSupport(
72
80
  support: ServerOperationSupportMap | undefined,
@@ -16,6 +16,8 @@ export function collectServers(
16
16
  fileTypes: server.fileTypes,
17
17
  status: server.status,
18
18
  ...(server.statusReason ? { statusReason: server.statusReason } : {}),
19
+ ...(server.typescript ? { typescript: server.typescript } : {}),
20
+ ...(server.failureMessage ? { failureMessage: server.failureMessage } : {}),
19
21
  ready: server.ready,
20
22
  ...(server.operationSupport ? { operationSupport: server.operationSupport } : {}),
21
23
  }));
@@ -0,0 +1,82 @@
1
+ import type { CapabilityState } from "@mrclrchtr/supi-code-runtime/api";
2
+ import type {
3
+ AutomaticLspPathPolicy,
4
+ ProjectServerInfo,
5
+ WorkspaceLspRuntimeState,
6
+ } from "@mrclrchtr/supi-lsp/api";
7
+ import type {
8
+ HealthDiagnosticObservation,
9
+ SemanticHealthState,
10
+ } from "../../session/health-types.ts";
11
+ import {
12
+ type CapabilityWarningMissingServerSource,
13
+ type CapabilityWarningReport,
14
+ evaluateCapabilityWarnings,
15
+ gatherCapabilityWarningInput,
16
+ } from "../capability/capability-warnings.ts";
17
+ import { collectDiagnostics } from "./diagnostics.ts";
18
+ import { deriveWorkspaceSemanticHealthState } from "./semantic-state.ts";
19
+
20
+ /** Passive status facts. No maintenance, recovery, or document tracking is performed. */
21
+ export interface WorkspaceStatusSnapshot {
22
+ readonly workspaceRoot: string;
23
+ readonly servers: readonly ProjectServerInfo[];
24
+ readonly serverInventoryAvailable: boolean;
25
+ readonly diagnostics: HealthDiagnosticObservation;
26
+ readonly capabilities: {
27
+ readonly semantic: SemanticHealthState;
28
+ readonly structural: CapabilityState;
29
+ };
30
+ readonly capabilityWarnings?: CapabilityWarningReport;
31
+ }
32
+
33
+ /** Runtime facts and trusted configuration needed for one passive observation. */
34
+ export interface WorkspaceStatusOptions {
35
+ readonly cwd: string;
36
+ readonly lspState: WorkspaceLspRuntimeState;
37
+ readonly semanticState: CapabilityState;
38
+ readonly structuralState: CapabilityState;
39
+ readonly projectTrusted: boolean;
40
+ readonly homeDir?: string;
41
+ readonly lspController?: CapabilityWarningMissingServerSource | null;
42
+ readonly automaticPathPolicy?: AutomaticLspPathPolicy | null;
43
+ }
44
+
45
+ /** Use the same readiness and diagnostic evidence policy as code_health, without refreshing it. */
46
+ export async function observeWorkspaceStatus(
47
+ options: WorkspaceStatusOptions,
48
+ ): Promise<WorkspaceStatusSnapshot> {
49
+ const { cwd, lspState } = options;
50
+ const runtime = lspState.kind === "ready" ? lspState.runtime : null;
51
+ const servers = runtime?.getProjectServers() ?? [];
52
+ const semantic = deriveWorkspaceSemanticHealthState(lspState, options.semanticState, servers);
53
+ const diagnostics = await collectDiagnostics({
54
+ service: semantic.kind === "ready" ? runtime : null,
55
+ evidenceService:
56
+ lspState.kind === "ready" || lspState.kind === "inactive" ? lspState.runtime : null,
57
+ included: ["diagnostics"],
58
+ scope: { kind: "tracked-files", filter: null },
59
+ cwd,
60
+ unavailableReason: semantic.kind === "ready" ? "Diagnostics unavailable" : semantic.reason,
61
+ });
62
+ const warnings = evaluateCapabilityWarnings(
63
+ gatherCapabilityWarningInput(cwd, options.lspController ?? null, {
64
+ projectTrusted: options.projectTrusted,
65
+ homeDir: options.homeDir,
66
+ automaticPathPolicy: options.automaticPathPolicy ?? undefined,
67
+ }),
68
+ );
69
+ return {
70
+ workspaceRoot: cwd,
71
+ servers,
72
+ serverInventoryAvailable: lspState.kind === "ready" || lspState.kind === "disabled",
73
+ diagnostics: {
74
+ ...diagnostics,
75
+ entries: [...diagnostics.entries].sort(
76
+ (a, b) => b.errors - a.errors || b.warnings - a.warnings || a.file.localeCompare(b.file),
77
+ ),
78
+ },
79
+ capabilities: { semantic, structural: options.structuralState },
80
+ capabilityWarnings: warnings.hasWarnings ? warnings : undefined,
81
+ };
82
+ }
@@ -49,10 +49,7 @@ export function renderReadNextSection(items: ReadNextItem[], maxItems = 3): stri
49
49
 
50
50
  const lines = ["## Read Next"];
51
51
  for (const item of visible) {
52
- const lineCount = item.endLine - item.startLine + 1;
53
- lines.push(
54
- `- \`${item.file}\` ${formatLineRange(item)} — ${item.reason} (\`read\` offset ${item.startLine}, limit ${lineCount})`,
55
- );
52
+ lines.push(`- \`${item.file}\` ${formatLineRange(item)} — ${item.reason}`);
56
53
  }
57
54
  lines.push("");
58
55
  return lines;
@@ -16,6 +16,7 @@ import { readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:
16
16
  import { basename, dirname, join } from "node:path";
17
17
  import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
18
18
  import type { FileEdit, WorkspaceEdit } from "@mrclrchtr/supi-code-runtime/api";
19
+ import { toDisplayPath } from "../search/paths.ts";
19
20
  import { revalidateMutationAuthority } from "./mutation-authority.ts";
20
21
  import { compareCodePositions, createLogicalLineIndex } from "./position.ts";
21
22
  import { validateEditAgainstFiles } from "./safety.ts";
@@ -25,6 +26,8 @@ export type ApplyResult =
25
26
  | { kind: "error"; reason: string };
26
27
 
27
28
  export interface ApplyOptions {
29
+ /** Workspace root for relative error paths; omitted roots retain absolute paths. */
30
+ cwd?: string;
28
31
  /** Canonical roots authorized by the semantic provider that made the plan. */
29
32
  authorizedMutationRoots: readonly string[];
30
33
  /** Expected SHA-256 fingerprints per file, validated after queue acquisition. */
@@ -57,7 +60,7 @@ export async function applyWorkspaceEdit(
57
60
  options: ApplyOptions,
58
61
  ): Promise<ApplyResult> {
59
62
  const grouped = groupEditsByFile(edit.edits);
60
- const files = [...grouped.keys()].sort();
63
+ const files = [...grouped.keys()].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
61
64
  return withAllMutationQueues(files, async () => {
62
65
  const authority = revalidateMutationAuthority(files, options.authorizedMutationRoots);
63
66
  if (authority.kind === "unavailable") {
@@ -65,7 +68,7 @@ export async function applyWorkspaceEdit(
65
68
  }
66
69
 
67
70
  if (options.expectedFingerprints) {
68
- const freshness = validateFingerprints(files, options.expectedFingerprints);
71
+ const freshness = validateFingerprints(files, options.expectedFingerprints, options.cwd);
69
72
  if (!freshness.ok) return { kind: "error", reason: freshness.reason };
70
73
  }
71
74
 
@@ -73,6 +76,7 @@ export async function applyWorkspaceEdit(
73
76
  edit,
74
77
  options.getOpenDocumentVersion,
75
78
  options.expectedFingerprints,
79
+ options.cwd,
76
80
  );
77
81
  if (!documentState.ok) return { kind: "error", reason: documentState.reason };
78
82
 
@@ -97,6 +101,7 @@ function validateDocumentPreconditions(
97
101
  edit: WorkspaceEdit,
98
102
  getOpenDocumentVersion: ApplyOptions["getOpenDocumentVersion"],
99
103
  expectedFingerprints: ApplyOptions["expectedFingerprints"],
104
+ cwd: ApplyOptions["cwd"],
100
105
  ): { ok: true } | { ok: false; reason: string } {
101
106
  const preconditions = edit.documentPreconditions ?? [];
102
107
  if (preconditions.length === 0) return { ok: true };
@@ -112,6 +117,7 @@ function validateDocumentPreconditions(
112
117
  precondition,
113
118
  getOpenDocumentVersion,
114
119
  expectedFingerprints,
120
+ cwd,
115
121
  );
116
122
  if (reason) return { ok: false, reason };
117
123
  }
@@ -122,21 +128,23 @@ function validateDocumentPrecondition(
122
128
  precondition: NonNullable<WorkspaceEdit["documentPreconditions"]>[number],
123
129
  getOpenDocumentVersion: NonNullable<ApplyOptions["getOpenDocumentVersion"]>,
124
130
  expectedFingerprints: ApplyOptions["expectedFingerprints"],
131
+ cwd: ApplyOptions["cwd"],
125
132
  ): string | null {
133
+ const file = cwd ? toDisplayPath(cwd, precondition.file) : precondition.file;
126
134
  const currentVersion = getOpenDocumentVersion(precondition.file);
127
135
  if (precondition.kind === "disk-content") {
128
136
  return currentVersion === null
129
137
  ? null
130
- : `File ${precondition.file} is now open and no longer uses disk content as its master.`;
138
+ : `File ${file} is now open and no longer uses disk content as its master.`;
131
139
  }
132
140
  if (currentVersion !== precondition.version) {
133
- return `File ${precondition.file} open document version has changed since the plan was generated.`;
141
+ return `File ${file} open document version has changed since the plan was generated.`;
134
142
  }
135
143
  if (
136
144
  precondition.kind === "open-document-content" &&
137
145
  expectedFingerprints?.get(precondition.file) !== precondition.fingerprint
138
146
  ) {
139
- return `File ${precondition.file} synchronized content fingerprint does not match the stored plan.`;
147
+ return `File ${file} synchronized content fingerprint does not match the stored plan.`;
140
148
  }
141
149
  return null;
142
150
  }
@@ -144,6 +152,7 @@ function validateDocumentPrecondition(
144
152
  function validateFingerprints(
145
153
  files: string[],
146
154
  expected: ReadonlyMap<string, string>,
155
+ cwd: ApplyOptions["cwd"],
147
156
  ): { ok: true } | { ok: false; reason: string } {
148
157
  for (const file of files) {
149
158
  const expectedFingerprint = expected.get(file);
@@ -152,9 +161,9 @@ function validateFingerprints(
152
161
  try {
153
162
  actual = sha256File(file);
154
163
  } catch {
155
- return stalePlanError(file);
164
+ return stalePlanError(file, cwd);
156
165
  }
157
- if (actual !== expectedFingerprint) return stalePlanError(file);
166
+ if (actual !== expectedFingerprint) return stalePlanError(file, cwd);
158
167
  }
159
168
  return { ok: true };
160
169
  }
@@ -163,10 +172,10 @@ function sha256File(file: string): string {
163
172
  return createHash("sha256").update(readFileSync(file, "utf-8")).digest("hex");
164
173
  }
165
174
 
166
- function stalePlanError(file: string): { ok: false; reason: string } {
175
+ function stalePlanError(file: string, cwd: ApplyOptions["cwd"]): { ok: false; reason: string } {
167
176
  return {
168
177
  ok: false,
169
- reason: `File ${file} has changed since the plan was generated. Regenerate with code_refactor_plan.`,
178
+ reason: `File ${cwd ? toDisplayPath(cwd, file) : file} has changed since the plan was generated. Regenerate with code_refactor_plan.`,
170
179
  };
171
180
  }
172
181
 
@@ -198,7 +207,7 @@ function readOriginalContents(
198
207
  const contents = new Map<string, string>();
199
208
 
200
209
  try {
201
- for (const file of [...grouped.keys()].sort()) {
210
+ for (const file of [...grouped.keys()].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))) {
202
211
  contents.set(file, readFileSync(file, "utf-8"));
203
212
  }
204
213
  } catch (error) {