@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,232 @@
1
+ import { StringEnum } from "@earendil-works/pi-ai";
2
+ import { type Static, type TSchema, Type } from "typebox";
3
+ import type { InspectObservation } from "../../session/inspect-types.ts";
4
+ import { ConfidenceSchema, EvidenceListSchema, RecoveryRangeSchema } from "../result/structured.ts";
5
+ import type { InspectResultAssembly } from "./result.ts";
6
+
7
+ const PositionRange = {
8
+ startLine: Type.Integer(),
9
+ startCharacter: Type.Integer(),
10
+ endLine: Type.Integer(),
11
+ endCharacter: Type.Integer(),
12
+ };
13
+ const NodeSchema = Type.Object(
14
+ {
15
+ type: Type.String(),
16
+ text: Type.String(),
17
+ ...PositionRange,
18
+ ancestry: Type.Array(
19
+ Type.Object({ type: Type.String(), ...PositionRange }, { additionalProperties: false }),
20
+ ),
21
+ },
22
+ { additionalProperties: false },
23
+ );
24
+ const SymbolSchema = Type.Object(
25
+ {
26
+ name: Type.String(),
27
+ kind: Type.String(),
28
+ nativeKind: Type.Optional(Type.String()),
29
+ ...PositionRange,
30
+ },
31
+ { additionalProperties: false },
32
+ );
33
+ const DefinitionSchema = Type.Object(
34
+ { file: Type.String(), line: Type.Integer(), character: Type.Integer() },
35
+ { additionalProperties: false },
36
+ );
37
+ const DiagnosticSchema = Type.Object(
38
+ {
39
+ line: Type.Integer(),
40
+ character: Type.Integer(),
41
+ endLine: Type.Integer(),
42
+ endCharacter: Type.Integer(),
43
+ severity: Type.Number(),
44
+ message: Type.String(),
45
+ },
46
+ { additionalProperties: false },
47
+ );
48
+ const ProvenanceSchema = Type.Object(
49
+ { source: StringEnum(["semantic", "structural"]), capability: Type.String() },
50
+ { additionalProperties: false },
51
+ );
52
+
53
+ function observationSchema<T extends TSchema>(data: T) {
54
+ return Type.Union([
55
+ Type.Object({ kind: Type.Literal("completed"), data }, { additionalProperties: false }),
56
+ Type.Object(
57
+ {
58
+ kind: Type.Literal("partial"),
59
+ data,
60
+ reason: Type.String(),
61
+ recovery: Type.Optional(
62
+ Type.Object(
63
+ { file: Type.String(), errorRanges: Type.Array(RecoveryRangeSchema) },
64
+ { additionalProperties: false },
65
+ ),
66
+ ),
67
+ },
68
+ { additionalProperties: false },
69
+ ),
70
+ Type.Object(
71
+ { kind: Type.Literal("unavailable"), reason: Type.String() },
72
+ { additionalProperties: false },
73
+ ),
74
+ ]);
75
+ }
76
+
77
+ /** Point facts use one-based UTF-16 coordinates; syntax recovery ranges remain zero-based. */
78
+ export const InspectOutputSchema = Type.Union([
79
+ Type.Object(
80
+ {
81
+ kind: Type.Literal("completed"),
82
+ point: Type.Object(
83
+ { file: Type.String(), line: Type.Integer(), character: Type.Integer() },
84
+ { additionalProperties: false },
85
+ ),
86
+ confidence: ConfidenceSchema,
87
+ diagnosticWindow: Type.Object(
88
+ { startLine: Type.Integer(), endLine: Type.Integer() },
89
+ { additionalProperties: false },
90
+ ),
91
+ sections: Type.Object(
92
+ {
93
+ node: observationSchema(Type.Union([NodeSchema, Type.Null()])),
94
+ enclosingSymbol: observationSchema(Type.Union([SymbolSchema, Type.Null()])),
95
+ hover: observationSchema(Type.Union([Type.String(), Type.Null()])),
96
+ definition: observationSchema(Type.Array(DefinitionSchema)),
97
+ diagnostics: observationSchema(Type.Array(DiagnosticSchema)),
98
+ },
99
+ { additionalProperties: false },
100
+ ),
101
+ evidenceLists: Type.Array(EvidenceListSchema),
102
+ provenance: Type.Array(ProvenanceSchema),
103
+ nextQueries: Type.Array(Type.String()),
104
+ },
105
+ { additionalProperties: false },
106
+ ),
107
+ Type.Object(
108
+ {
109
+ kind: Type.Literal("invalid-input"),
110
+ message: Type.String(),
111
+ nextQueries: Type.Array(Type.String()),
112
+ },
113
+ { additionalProperties: false },
114
+ ),
115
+ ]);
116
+
117
+ function observation<T, U>(value: InspectObservation<T>, project: (data: T) => U) {
118
+ if (value.kind === "unavailable") return { kind: value.kind, reason: value.reason };
119
+ if (value.kind === "completed") return { kind: value.kind, data: project(value.data) };
120
+ return {
121
+ kind: value.kind,
122
+ data: project(value.data),
123
+ reason: value.reason,
124
+ ...(value.recovery
125
+ ? {
126
+ recovery: {
127
+ file: value.recovery.file,
128
+ errorRanges: value.recovery.errorRanges.map(({ start, end }) => ({
129
+ start: { line: start.line, character: start.character },
130
+ end: { line: end.line, character: end.character },
131
+ })),
132
+ },
133
+ }
134
+ : {}),
135
+ };
136
+ }
137
+
138
+ /** Assemble script data from the same bounded evidence as direct inspection, never UI text. */
139
+ export function structuredInspectResult(
140
+ assembly: InspectResultAssembly,
141
+ ): Static<typeof InspectOutputSchema> {
142
+ const { data, assembled } = assembly;
143
+ return {
144
+ kind: "completed",
145
+ point: { file: data.relPath, line: data.line, character: data.character },
146
+ confidence: data.confidence,
147
+ diagnosticWindow: {
148
+ startLine: data.diagnosticWindow.startLine,
149
+ endLine: data.diagnosticWindow.endLine,
150
+ },
151
+ sections: {
152
+ node: observation(data.sections.node, (node) =>
153
+ node
154
+ ? {
155
+ type: node.type,
156
+ text: node.text,
157
+ startLine: node.startLine,
158
+ startCharacter: node.startCharacter,
159
+ endLine: node.endLine,
160
+ endCharacter: node.endCharacter,
161
+ ancestry: node.ancestry.map(
162
+ ({ type, startLine, startCharacter, endLine, endCharacter }) => ({
163
+ type,
164
+ startLine,
165
+ startCharacter,
166
+ endLine,
167
+ endCharacter,
168
+ }),
169
+ ),
170
+ }
171
+ : null,
172
+ ),
173
+ enclosingSymbol: observation(data.sections.enclosingSymbol, (symbol) =>
174
+ symbol
175
+ ? {
176
+ name: symbol.name,
177
+ kind: symbol.kind,
178
+ ...(symbol.nativeKind === undefined ? {} : { nativeKind: symbol.nativeKind }),
179
+ startLine: symbol.startLine,
180
+ startCharacter: symbol.startCharacter,
181
+ endLine: symbol.endLine,
182
+ endCharacter: symbol.endCharacter,
183
+ }
184
+ : null,
185
+ ),
186
+ hover: observation(data.sections.hover, (hover) => hover),
187
+ definition: observation(data.sections.definition, () =>
188
+ assembly.displayedDefinitions.map(({ file, line, character }) => ({
189
+ file,
190
+ line,
191
+ character,
192
+ })),
193
+ ),
194
+ diagnostics: observation(data.sections.diagnostics, () =>
195
+ assembly.displayedDiagnostics.map(
196
+ ({ line, character, endLine, endCharacter, severity, message }) => ({
197
+ line,
198
+ character,
199
+ endLine,
200
+ endCharacter,
201
+ severity,
202
+ message,
203
+ }),
204
+ ),
205
+ ),
206
+ },
207
+ evidenceLists: assembled.evidenceLists.map(
208
+ ({
209
+ key,
210
+ totalCount,
211
+ shownCount,
212
+ omittedCount,
213
+ partialReason,
214
+ partialMessage,
215
+ invalidLocationCount,
216
+ }) => ({
217
+ key,
218
+ totalCount,
219
+ shownCount,
220
+ omittedCount,
221
+ partialReason,
222
+ ...(partialMessage === undefined ? {} : { partialMessage }),
223
+ ...(invalidLocationCount === undefined ? {} : { invalidLocationCount }),
224
+ }),
225
+ ),
226
+ provenance: assembled.provenance.map(({ source, capability }) => ({
227
+ source: source as "semantic" | "structural",
228
+ capability: capability ?? "",
229
+ })),
230
+ nextQueries: [...assembly.details.nextQueries],
231
+ };
232
+ }
@@ -0,0 +1,66 @@
1
+ import type {
2
+ OrientationResultData,
3
+ OrientationSectionData,
4
+ } from "../../session/orientation-types.ts";
5
+
6
+ const INLINE_SECTIONS = new Set([
7
+ "instructions",
8
+ "workspace.directories",
9
+ "workspace.files",
10
+ "workspace.issues",
11
+ ]);
12
+
13
+ /** Keep the immediate directory map and all collection problems inline; defer ancillary facts. */
14
+ export function selectDirectoryNavigation(data: OrientationResultData): OrientationResultData {
15
+ if (!data.workspace?.focus || data.workspace.overview) return data;
16
+ const workspaceRoot = data.workspace.focus === data.workspace.observation.root;
17
+ const inline = (section: OrientationSectionData): boolean =>
18
+ INLINE_SECTIONS.has(section.key) ||
19
+ section.key.startsWith("gradle.") ||
20
+ (workspaceRoot &&
21
+ (section.key === "workspace.projects" || section.key === "workspace.memberships")) ||
22
+ section.status !== "complete" ||
23
+ section.evidenceLists.some((list) => list.totalCount === null || list.partialReason !== null);
24
+ const sections = data.sections.filter(inline);
25
+ const deferred = data.sections.filter((section) => !inline(section));
26
+ const total = deferred.reduce(
27
+ (sum, section) =>
28
+ sum + section.evidenceLists.reduce((count, list) => count + (list.totalCount ?? 0), 0),
29
+ 0,
30
+ );
31
+ if (total > 0) {
32
+ sections.push({
33
+ key: "workspace.captured",
34
+ title: "Captured navigation",
35
+ status: "complete",
36
+ reason: null,
37
+ confidence: "unavailable",
38
+ provenance: [],
39
+ evidenceLists: [
40
+ {
41
+ key: "workspace.captured",
42
+ totalCount: total,
43
+ shownCount: 0,
44
+ omittedCount: total,
45
+ partialReason: null,
46
+ },
47
+ ],
48
+ items: [
49
+ {
50
+ kind: "paragraph",
51
+ text: `Ancillary sections are in the captured details: ${deferred.map((section) => section.title).join("; ")}.`,
52
+ },
53
+ ],
54
+ });
55
+ }
56
+ return {
57
+ ...data,
58
+ sections,
59
+ renderedSections: sections.map((section) => section.key),
60
+ omittedCount: sections.reduce(
61
+ (sum, section) =>
62
+ sum + section.evidenceLists.reduce((count, list) => count + (list.omittedCount ?? 0), 0),
63
+ 0,
64
+ ),
65
+ };
66
+ }
@@ -0,0 +1,68 @@
1
+ import type { GradleObservation } from "../../analysis/gradle/types.ts";
2
+ import type { OrientationSectionData } from "../../session/orientation-types.ts";
3
+ import { code, tableSection } from "./workspace-format.ts";
4
+
5
+ /** Project identities and runtime provenance stay separate from parsed Project declarations. */
6
+ export function gradleSections(
7
+ observation: GradleObservation | undefined,
8
+ limit: number,
9
+ ): OrientationSectionData[] {
10
+ if (!observation) return [];
11
+ const attempted = observation.status === "complete" || observation.stage === "query";
12
+ const uncertain = observation.status !== "complete" && observation.stage === "unknown";
13
+ let queryStatement = "Model query was not run";
14
+ if (attempted) queryStatement = "Model query was attempted";
15
+ if (uncertain) queryStatement = "Model query execution is unknown";
16
+ const detail = `Selected build ${observation.selectedRoot}; requested model ${observation.query}; ${queryStatement}${observation.gradleVersion ? `; Gradle ${observation.gradleVersion}` : ""}${observation.runtime ? `; ${observation.runtime.kind} from ${observation.runtime.source}` : ""}`;
17
+ const source = attempted || uncertain ? "runtime" : "configuration";
18
+ const capability = uncertain ? "Gradle collection" : observation.query;
19
+ const provenance = [{ source, capability, detail }] as const;
20
+ const common: OrientationSectionData = {
21
+ key: "gradle.observation",
22
+ title: "Gradle model observation",
23
+ status: observation.status === "complete" ? "complete" : "unavailable",
24
+ reason:
25
+ observation.status === "complete" ? null : `${observation.status}: ${observation.reason}`,
26
+ confidence: "unavailable",
27
+ provenance,
28
+ evidenceLists: [],
29
+ items: [
30
+ {
31
+ kind: "paragraph",
32
+ text: `Selected build: ${code(observation.selectedRoot)}. Requested model: ${code(observation.query)}. ${observation.gradleVersion ? `Gradle ${code(observation.gradleVersion)}. ` : ""}${observation.status === "complete" ? "Runtime-reported facts, not parsed Project declarations. Included-build trees are not expanded. Directories do not establish source ownership, dependency resolution, or runtime architecture." : `${queryStatement}. This does not establish that the build has no projects.`}`,
33
+ },
34
+ ],
35
+ };
36
+ if (observation.status !== "complete") return [common];
37
+ const projects = tableSection("gradle.projects", "Gradle-reported projects", {
38
+ headers: [
39
+ "Build identity (root directory)",
40
+ "Logical project path",
41
+ "Name",
42
+ "Parent path",
43
+ "Actual project directory",
44
+ ],
45
+ rows: observation.projects.map((project) => [
46
+ code(project.buildRoot),
47
+ code(project.path),
48
+ code(project.name),
49
+ project.parentPath === null ? "—" : code(project.parentPath),
50
+ code(project.directory),
51
+ ]),
52
+ limit,
53
+ source: "runtime",
54
+ detail,
55
+ });
56
+ const included = tableSection(
57
+ "gradle.included-builds",
58
+ "Gradle included-build references (not expanded)",
59
+ {
60
+ headers: ["Build identity (root directory)"],
61
+ rows: observation.includedBuilds.map((build) => [code(build.buildRoot)]),
62
+ limit,
63
+ source: "runtime",
64
+ detail,
65
+ },
66
+ );
67
+ return [common, { ...projects, provenance }, { ...included, provenance }];
68
+ }
@@ -7,6 +7,7 @@ import type {
7
7
  } from "../../session/orientation-types.ts";
8
8
  import { assembledReadNext } from "../result/assembly.ts";
9
9
  import type { OrientationResultAssembly } from "./result.ts";
10
+ import { code } from "./workspace-format.ts";
10
11
 
11
12
  /**
12
13
  * Sole model-facing markdown adapter for Orientation.
@@ -93,29 +94,39 @@ function renderItems(
93
94
  }
94
95
  }
95
96
 
96
- /** Keep source-written fences inside the enclosing code block. */
97
- function codeFence(lines: readonly string[]): string {
98
- let size = 3;
97
+ /** Choose delimiters longer than any source-written backtick run. */
98
+ function codeFence(lines: readonly string[], minimum = 3): string {
99
+ let size = minimum;
99
100
  for (const line of lines)
100
101
  for (const match of line.matchAll(/`+/g)) size = Math.max(size, match[0].length + 1);
101
102
  return "`".repeat(size);
102
103
  }
103
104
 
105
+ function literalReason(reason: string): string {
106
+ const text = reason
107
+ .replace(/[\p{Cc}\p{Cf}\p{Z}]/gu, " ")
108
+ .replace(/\s+/gu, " ")
109
+ .trim();
110
+ const delimiter = codeFence([text], 1);
111
+ return `${delimiter} ${text} ${delimiter}`;
112
+ }
113
+
104
114
  function compactSectionNote(section: OrientationSectionData): string {
115
+ const facts = section.evidenceLists.map(evidenceSummary).join("; ");
105
116
  return [
106
- section.evidenceLists.map(evidenceSummary).join("; "),
107
- section.reason,
117
+ facts ? `${facts}${/[.!?…]$/.test(facts) ? "" : "."}` : null,
118
+ section.reason ? literalReason(section.reason) : null,
108
119
  section.provenance.map(formatProvenance).join(", "),
109
120
  ]
110
121
  .filter(Boolean)
111
- .join(". ");
122
+ .join(" ");
112
123
  }
113
124
 
114
125
  /** Render the same section status/provenance metadata stored in result details. */
115
126
  function formatSectionNote(section: OrientationSectionData): string {
116
127
  const facts = section.evidenceLists.map(evidenceSummary).join("; ");
117
128
  const provenance = section.provenance.map(formatProvenance).join(", ");
118
- return `_(status: ${section.status}; provenance: ${provenance || "none"}${section.reason ? `; ${section.reason}` : ""}${facts ? `; ${facts}` : ""})_`;
129
+ return `_(status: ${section.status}; provenance: ${provenance || "none"}${section.reason ? `; ${literalReason(section.reason)}` : ""}${facts ? `; ${facts}` : ""})_`;
119
130
  }
120
131
 
121
132
  function evidenceSummary(metadata: EvidenceListMetadata): string {
@@ -130,6 +141,6 @@ function evidenceSummary(metadata: EvidenceListMetadata): string {
130
141
  }
131
142
 
132
143
  function formatProvenance(provenance: OrientationProvenance): string {
133
- const detail = provenance.detail ? ` \`${provenance.detail}\`` : "";
144
+ const detail = provenance.detail ? ` ${code(provenance.detail)}` : "";
134
145
  return `${provenance.source}${provenance.capability ? ` (${provenance.capability})` : ""}${detail}`;
135
146
  }
@@ -19,7 +19,11 @@ import {
19
19
  type ToolResultAssembly,
20
20
  } from "../result/assembly.ts";
21
21
  import { formatCandidateRow, formatPartialCandidateDisclosure } from "../result/candidate-row.ts";
22
- import { createToolDisplaySection } from "../result/display.ts";
22
+ import {
23
+ createToolDisplaySection,
24
+ MAX_TUI_DISPLAY_ITEMS,
25
+ truncateDisplayText,
26
+ } from "../result/display.ts";
23
27
  import type {
24
28
  ContextDetails,
25
29
  OrientationSectionDetails,
@@ -131,17 +135,81 @@ export function assembleOrientationDetails(input: OrientationDetailsInput): Cont
131
135
 
132
136
  function orientationDisplaySection(section: OrientationSectionData): ToolDisplaySection {
133
137
  const items = section.items.filter((item) => item.kind !== "blank");
134
- return createToolDisplaySection({
138
+ const input = {
135
139
  key: `orientation.${section.key}`,
136
140
  title: section.title,
137
- items,
138
- totalCount: items.length,
139
- omittedCount: 0,
140
141
  partialReason:
141
142
  section.evidenceLists.find((evidence) => evidence.partialReason)?.partialReason ??
142
143
  (section.reason ? "provider-limited" : null),
143
144
  ...(section.reason ? { partialMessage: section.reason } : {}),
145
+ };
146
+ const evidence = section.evidenceLists.find((list) => list.key === section.tableEvidenceKey);
147
+ if (evidence) {
148
+ const rows = orientationTableRows(items);
149
+ const display = createToolDisplaySection({
150
+ ...input,
151
+ items: rows,
152
+ totalCount: evidence.totalCount,
153
+ omittedCount: evidence.omittedCount,
154
+ partialReason: evidence.partialReason ?? input.partialReason,
155
+ partialMessage: evidence.partialMessage ?? input.partialMessage,
156
+ format: (row) => row,
157
+ });
158
+ return rows.length
159
+ ? display
160
+ : {
161
+ ...display,
162
+ lines: items
163
+ .slice(0, MAX_TUI_DISPLAY_ITEMS)
164
+ .map((item) => truncateDisplayText(formatOrientationItem(item))),
165
+ };
166
+ }
167
+ const grouped = section.key === "workspace.memberships";
168
+ const summaries = section.evidenceLists.map((list) => {
169
+ const prefix = section.evidenceLists.length > 1 ? `${list.key}: ` : "";
170
+ return `${prefix}${orientationEvidenceSelection(list, grouped ? "memberships" : undefined)}`;
171
+ });
172
+ return createToolDisplaySection({
173
+ ...input,
174
+ items,
175
+ totalCount: items.length,
176
+ omittedCount: 0,
144
177
  format: formatOrientationItem,
178
+ preview: {
179
+ unit: grouped ? "group" : "block",
180
+ ...(summaries.length ? { evidenceSummary: summaries.join("; ") } : {}),
181
+ },
182
+ });
183
+ }
184
+
185
+ /** Describe canonical selection separately: a capped group preview need not show every atom. */
186
+ function orientationEvidenceSelection(list: EvidenceListMetadata, noun?: string): string {
187
+ const label = noun ? ` ${noun}` : "";
188
+ const explanation = list.partialMessage ? `; ${list.partialMessage}` : "";
189
+ if (list.totalCount === null) {
190
+ const omitted = list.omittedCount ? `; ${list.omittedCount} collected omitted` : "";
191
+ return `${list.shownCount}${label} selected${omitted}; more may exist — ${list.partialReason ?? "partial"}${explanation}`;
192
+ }
193
+ const partial = list.partialReason ? `; partial — ${list.partialReason}` : "";
194
+ if (list.omittedCount) {
195
+ return `${list.shownCount} of ${list.totalCount}${label} selected; ${list.omittedCount} omitted${partial}${explanation}`;
196
+ }
197
+ return `${list.totalCount}${label || " observed"}${partial}${explanation}`;
198
+ }
199
+
200
+ /** Keep table headers and group context with the first evidence row, outside its count. */
201
+ function orientationTableRows(items: readonly OrientationItem[]): string[] {
202
+ let framing: string[] = [];
203
+ return items.flatMap((item) => {
204
+ if (item.kind !== "table") {
205
+ framing.push(formatOrientationItem(item));
206
+ return [];
207
+ }
208
+ const rows = item.rows.map((row, index) =>
209
+ [...(index === 0 ? [...framing, item.headers.join(" | ")] : []), row.join(" | ")].join("\n"),
210
+ );
211
+ framing = [];
212
+ return rows;
145
213
  });
146
214
  }
147
215
 
@@ -199,6 +267,7 @@ function uniqueProvenance(sections: readonly OrientationSectionData[]) {
199
267
  import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
200
268
  import { contextErrorResult } from "../result/errors.ts";
201
269
  import { renderOrientationResult } from "./markdown.ts";
270
+ import { structuredOrientation } from "./structured.ts";
202
271
  import { prepareWorkspaceOutput } from "./workspace-output.ts";
203
272
 
204
273
  type OrientationOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["orient"]>>;
@@ -206,12 +275,7 @@ type OrientationOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["or
206
275
  /** Assemble the final model-visible code_orientation result for one workflow outcome. */
207
276
  export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelResult {
208
277
  if (outcome.kind === "unavailable") throw new Error(outcome.reason);
209
- if (outcome.kind === "invalid-input") {
210
- return contextErrorResult(`**Error:** ${outcome.message}`, {
211
- nextQueries: ["Choose an existing path, module, or precise target"],
212
- message: outcome.message,
213
- });
214
- }
278
+ if (outcome.kind === "invalid-input") return invalidOrientationResult(outcome);
215
279
  if (outcome.kind === "disambiguation" || outcome.kind === "kind-mismatch") {
216
280
  const candidates = outcome.candidates;
217
281
  const lines = [
@@ -249,6 +313,7 @@ export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelR
249
313
  });
250
314
  return {
251
315
  content: lines.join("\n"),
316
+ structuredContent: structuredOrientation(outcome),
252
317
  details: {
253
318
  type: "context",
254
319
  data: details,
@@ -261,15 +326,34 @@ export function finishOrientationResult(outcome: OrientationOutcome): CodeIntelR
261
326
  return finishCompletedOrientation(outcome.data);
262
327
  }
263
328
 
329
+ function invalidOrientationResult(
330
+ outcome: Extract<OrientationOutcome, { kind: "invalid-input" }>,
331
+ ): CodeIntelResult {
332
+ const rejection = outcome.symlinkRejection;
333
+ const recovery = "Resolve the requested path explicitly and retry with its canonical path.";
334
+ const message = rejection
335
+ ? `Requested focus ${JSON.stringify(rejection.requestedPath)} traverses a symbolic link: ${JSON.stringify(rejection.blockedPath)}. Orientation does not follow symbolic links.\n\n${recovery}`
336
+ : outcome.message;
337
+ return {
338
+ ...contextErrorResult(`**Error:** ${message}`, {
339
+ nextQueries: rejection ? [recovery] : ["Choose an existing path, module, or precise target"],
340
+ message,
341
+ }),
342
+ structuredContent: structuredOrientation(outcome),
343
+ };
344
+ }
345
+
264
346
  function finishCompletedOrientation(data: OrientationResultData): CodeIntelResult {
265
347
  const navigation = data.workspace ? prepareWorkspaceOutput(data) : null;
266
348
  const assembly = assembleOrientationResult(navigation?.data ?? data);
267
349
  return {
268
350
  content: navigation?.content ?? renderOrientationResult(assembly),
351
+ structuredContent: structuredOrientation({ kind: "completed", data }, navigation?.snapshotPath),
269
352
  details: {
270
353
  type: "context",
271
354
  data: assembly.details,
272
355
  budgetWarning: navigation?.warning,
356
+ ...(navigation ? { modelBudgetManaged: true } : {}),
273
357
  status: "completed",
274
358
  displaySections: assembly.displaySections,
275
359
  },
@@ -2,6 +2,7 @@ import { Type } from "typebox";
2
2
  import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
3
  import { MaxResultsParam, OrientationFocusParam } from "../schemas.ts";
4
4
  import { executeOrientationTool } from "./execute.ts";
5
+ import { OrientationOutputSchema } from "./structured-schema.ts";
5
6
  import { renderOrientationCall, renderOrientationResult } from "./tui.ts";
6
7
 
7
8
  export const CODE_ORIENTATION_TOOL_NAME = "code_orientation";
@@ -11,6 +12,7 @@ export const CODE_ORIENTATION_TOOL_LABEL = "Code Orientation";
11
12
  export const codeOrientationSpec = {
12
13
  name: CODE_ORIENTATION_TOOL_NAME,
13
14
  label: CODE_ORIENTATION_TOOL_LABEL,
15
+ outputSchema: OrientationOutputSchema,
14
16
  parameters: Type.Object(
15
17
  {
16
18
  focus: Type.Optional(OrientationFocusParam),