@mrclrchtr/supi-code-intelligence 11.1.0 → 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 (123) hide show
  1. package/README.md +29 -4
  2. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  3. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-lsp/README.md +42 -5
  5. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  6. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  7. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/LICENSE +15 -0
  8. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/README.md +680 -0
  9. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/bin/semver.js +195 -0
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/comparator.js +143 -0
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/index.js +7 -0
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +577 -0
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/semver.js +350 -0
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/clean.js +8 -0
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/cmp.js +54 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/coerce.js +62 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-build.js +9 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-loose.js +5 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare.js +7 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/diff.js +60 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/eq.js +5 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gt.js +5 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gte.js +5 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/inc.js +21 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lt.js +5 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lte.js +5 -0
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/major.js +5 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/minor.js +5 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/neq.js +5 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/parse.js +18 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/patch.js +5 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/prerelease.js +8 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rcompare.js +5 -0
  34. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rsort.js +5 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/satisfies.js +12 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/sort.js +5 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/truncate.js +48 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/valid.js +8 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/index.js +93 -0
  40. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +37 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/debug.js +11 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/identifiers.js +29 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/lrucache.js +42 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/parse-options.js +17 -0
  45. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/re.js +223 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +78 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/preload.js +4 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/range.bnf +17 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/gtr.js +6 -0
  50. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/intersects.js +9 -0
  51. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/ltr.js +6 -0
  52. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/max-satisfying.js +27 -0
  53. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-satisfying.js +26 -0
  54. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-version.js +63 -0
  55. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/outside.js +82 -0
  56. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/simplify.js +49 -0
  57. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/subset.js +249 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/to-comparators.js +10 -0
  59. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/valid.js +13 -0
  60. package/node_modules/@mrclrchtr/supi-lsp/package.json +5 -3
  61. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +23 -5
  62. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +53 -2
  63. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +19 -4
  64. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +22 -0
  65. package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-launch.ts +276 -0
  66. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +22 -10
  67. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +52 -19
  68. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +4 -3
  69. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +2 -2
  70. package/node_modules/@mrclrchtr/supi-lsp/src/session/scanner.ts +27 -15
  71. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  72. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  73. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  74. package/package.json +5 -5
  75. package/src/analysis/capability/capability-warnings.ts +18 -12
  76. package/src/analysis/health/check.ts +115 -0
  77. package/src/analysis/health/diagnostics.ts +3 -0
  78. package/src/analysis/health/file-scope.ts +2 -3
  79. package/src/analysis/health/semantic-state.ts +38 -0
  80. package/src/analysis/health/server-status.ts +8 -0
  81. package/src/analysis/health/signals.ts +2 -0
  82. package/src/analysis/health/status.ts +82 -0
  83. package/src/analysis/refactor/apply.ts +17 -8
  84. package/src/session/health-types.ts +7 -0
  85. package/src/session/health-workflow.ts +8 -43
  86. package/src/session/orientation/collect.ts +138 -12
  87. package/src/session/orientation/context-facts.ts +27 -2
  88. package/src/session/orientation/context-sections.ts +47 -0
  89. package/src/session/orientation/facts.ts +124 -0
  90. package/src/session/orientation/gather.ts +98 -11
  91. package/src/session/orientation/workspace-context.ts +16 -6
  92. package/src/session/orientation-types.ts +5 -0
  93. package/src/session/orientation-workflow.ts +3 -2
  94. package/src/session/refactor-plans.ts +5 -2
  95. package/src/session/refactor-workflow.ts +4 -3
  96. package/src/tool/code_find/guidance.ts +1 -1
  97. package/src/tool/code_health/markdown.ts +12 -2
  98. package/src/tool/code_health/result.ts +15 -2
  99. package/src/tool/code_health/spec.ts +2 -0
  100. package/src/tool/code_health/structured-schema.ts +250 -0
  101. package/src/tool/code_health/structured.ts +256 -0
  102. package/src/tool/code_inspect/result.ts +11 -5
  103. package/src/tool/code_inspect/spec.ts +2 -0
  104. package/src/tool/code_inspect/structured.ts +232 -0
  105. package/src/tool/code_orientation/result.ts +10 -4
  106. package/src/tool/code_orientation/spec.ts +2 -0
  107. package/src/tool/code_orientation/structured-schema.ts +607 -0
  108. package/src/tool/code_orientation/structured-workspace.ts +193 -0
  109. package/src/tool/code_orientation/structured.ts +195 -0
  110. package/src/tool/code_orientation/workspace-observations.ts +81 -0
  111. package/src/tool/code_orientation/workspace-output.ts +5 -0
  112. package/src/tool/code_orientation/workspace-projects.ts +16 -31
  113. package/src/tool/code_orientation/workspace-sections.ts +43 -30
  114. package/src/tool/code_refactor_apply/execute.ts +1 -1
  115. package/src/tool/code_refactor_apply/result.ts +13 -5
  116. package/src/tool/code_refactor_apply/spec.ts +2 -0
  117. package/src/tool/code_refactor_apply/structured.ts +49 -0
  118. package/src/tool/code_refactor_plan/result.ts +16 -8
  119. package/src/tool/code_refactor_plan/spec.ts +2 -0
  120. package/src/tool/code_refactor_plan/structured.ts +128 -0
  121. package/src/tool/schemas.ts +7 -1
  122. package/src/ui/status-command.ts +110 -321
  123. package/src/ui/status-overlay.ts +564 -420
@@ -0,0 +1,250 @@
1
+ import { StringEnum } from "@earendil-works/pi-ai";
2
+ import { Type } from "typebox";
3
+ import { HEALTH_DIAGNOSTIC_MESSAGE_LIMIT } from "../../session/health-types.ts";
4
+
5
+ const object = <T extends import("typebox").TProperties>(properties: T) =>
6
+ Type.Object(properties, { additionalProperties: false });
7
+ const nullableString = Type.Union([Type.String(), Type.Null()]);
8
+ const scope = Type.Union([
9
+ object({ kind: Type.Literal("file"), path: Type.String() }),
10
+ object({ kind: Type.Literal("tracked-files"), filter: nullableString }),
11
+ ]);
12
+ const evidence = object({
13
+ requested: Type.Integer(),
14
+ confirmed: Type.Integer(),
15
+ unconfirmed: Type.Integer(),
16
+ failed: Type.Integer(),
17
+ removed: Type.Integer(),
18
+ documents: Type.Array(
19
+ object({
20
+ file: Type.String(),
21
+ status: StringEnum(["confirmed", "unconfirmed", "failed", "removed"]),
22
+ }),
23
+ ),
24
+ });
25
+ const scopeStatus = object({
26
+ status: StringEnum(["included", "excluded", "no-config", "out-of-tree"]),
27
+ basis: Type.Union([
28
+ StringEnum([
29
+ "fileNames",
30
+ "explicit",
31
+ "include-pattern",
32
+ "default-include",
33
+ "exclude-pattern",
34
+ "extension",
35
+ ]),
36
+ Type.Null(),
37
+ ]),
38
+ configPath: nullableString,
39
+ caseSensitiveFileNames: Type.Boolean(),
40
+ });
41
+ const diagnosticEntry = object({
42
+ file: Type.String(),
43
+ errors: Type.Integer(),
44
+ warnings: Type.Integer(),
45
+ messages: Type.Optional(
46
+ Type.Array(
47
+ object({
48
+ line: Type.Integer({ description: "1-based line." }),
49
+ severity: StringEnum(["error", "warning"]),
50
+ message: Type.String(),
51
+ source: Type.Optional(Type.String()),
52
+ }),
53
+ ),
54
+ ),
55
+ });
56
+ const diagnostics = Type.Union([
57
+ object({ kind: Type.Literal("not-requested"), entries: Type.Array(diagnosticEntry) }),
58
+ object({
59
+ kind: Type.Literal("completed"),
60
+ scope,
61
+ entries: Type.Array(diagnosticEntry),
62
+ evidence,
63
+ scopeStatus: Type.Optional(scopeStatus),
64
+ }),
65
+ object({
66
+ kind: StringEnum(["partial", "unavailable"]),
67
+ scope,
68
+ entries: Type.Array(diagnosticEntry),
69
+ evidence,
70
+ reason: Type.String(),
71
+ scopeStatus: Type.Optional(scopeStatus),
72
+ }),
73
+ ]);
74
+ const operation = object({
75
+ server: StringEnum(["advertised", "not-advertised", "unknown"]),
76
+ supi: StringEnum(["supported", "limited", "unsupported"]),
77
+ reason: Type.Optional(Type.String()),
78
+ });
79
+ const support = object({
80
+ rename_symbol: Type.Optional(operation),
81
+ prepare_rename: Type.Optional(operation),
82
+ extract_function: Type.Optional(operation),
83
+ extract_variable: Type.Optional(operation),
84
+ update_imports: Type.Optional(operation),
85
+ delete_dead_code: Type.Optional(operation),
86
+ code_action_resolve: Type.Optional(operation),
87
+ });
88
+ const server = object({
89
+ name: Type.String(),
90
+ root: Type.String(),
91
+ fileTypes: Type.Array(Type.String()),
92
+ status: StringEnum(["running", "error", "unavailable"]),
93
+ statusReason: Type.Optional(
94
+ StringEnum([
95
+ "process-crashed",
96
+ "process-crash-recovery-pending",
97
+ "process-crash-recovery-exhausted",
98
+ ]),
99
+ ),
100
+ ready: Type.Boolean(),
101
+ operationSupport: Type.Optional(support),
102
+ typescript: Type.Optional(
103
+ object({
104
+ backend: Type.Union([Type.Literal("tsserver"), Type.Literal("native")]),
105
+ packageName: Type.String(),
106
+ compilerVersion: Type.Optional(Type.String()),
107
+ wrapperVersion: Type.Optional(Type.String()),
108
+ }),
109
+ ),
110
+ failureMessage: Type.Optional(Type.String()),
111
+ });
112
+ const stale = object({
113
+ scope: StringEnum(["file", "workspace"]),
114
+ suspected: Type.Union([Type.Boolean(), Type.Null()]),
115
+ matchedFileCount: Type.Integer(),
116
+ warning: nullableString,
117
+ });
118
+ const recoveryEntry = object({
119
+ name: Type.String(),
120
+ root: Type.String(),
121
+ outcome: StringEnum([
122
+ "recovered",
123
+ "skipped-no-retained-file",
124
+ "recovery-failed",
125
+ "recovery-exhausted",
126
+ ]),
127
+ nextAction: Type.Optional(StringEnum(["use-exact-file", "refresh"])),
128
+ failureMessage: Type.Optional(Type.String()),
129
+ });
130
+ const crashRecovery = object({
131
+ recoveredRoutes: Type.Integer(),
132
+ skippedRoutes: Type.Integer(),
133
+ failedRoutes: Type.Integer(),
134
+ exhaustedRoutes: Type.Integer(),
135
+ entries: Type.Array(recoveryEntry),
136
+ omittedEntries: Type.Integer(),
137
+ });
138
+ const startupRetry = object({
139
+ recoveredRoutes: Type.Integer(),
140
+ failedRoutes: Type.Integer(),
141
+ entries: Type.Array(
142
+ object({
143
+ name: Type.String(),
144
+ root: Type.String(),
145
+ outcome: StringEnum(["recovered", "retry-failed"]),
146
+ nextAction: Type.Optional(Type.Literal("refresh")),
147
+ failureMessage: Type.Optional(Type.String()),
148
+ }),
149
+ ),
150
+ omittedEntries: Type.Integer(),
151
+ });
152
+ const tracking = object({
153
+ status: StringEnum(["complete", "limited"]),
154
+ reason: Type.Union([StringEnum(["file-limit", "filesystem-error"]), Type.Null()]),
155
+ observedFileCount: Type.Integer(),
156
+ discovered: Type.Array(Type.String()),
157
+ tracked: Type.Array(Type.String()),
158
+ skipped: Type.Array(Type.String()),
159
+ unavailable: Type.Array(Type.String()),
160
+ deferred: Type.Integer(),
161
+ });
162
+ const attemptFields = {
163
+ attemptedAt: Type.Number(),
164
+ elapsedMs: Type.Number(),
165
+ requestedDiagnosticScope: scope,
166
+ operationScope: StringEnum(["file-runtime", "workspace-runtime"]),
167
+ attemptedActiveClients: Type.Optional(Type.Integer()),
168
+ restartedClients: Type.Optional(Type.Integer()),
169
+ fileReadiness: Type.Optional(StringEnum(["ready", "pending", "unavailable"])),
170
+ staleAssessment: Type.Optional(stale),
171
+ diagnosticEvidence: Type.Optional(evidence),
172
+ processCrashRecovery: Type.Optional(crashRecovery),
173
+ startupRetry: Type.Optional(startupRetry),
174
+ sourceTracking: Type.Optional(tracking),
175
+ };
176
+ const completedAttemptFields = {
177
+ ...attemptFields,
178
+ attemptedActiveClients: Type.Integer(),
179
+ restartedClients: Type.Integer(),
180
+ staleAssessment: stale,
181
+ processCrashRecovery: crashRecovery,
182
+ };
183
+ const attempt = Type.Union([
184
+ object({
185
+ kind: Type.Literal("completed"),
186
+ ...completedAttemptFields,
187
+ operationScope: Type.Literal("workspace-runtime"),
188
+ diagnosticEvidence: evidence,
189
+ }),
190
+ object({
191
+ kind: Type.Literal("completed"),
192
+ ...completedAttemptFields,
193
+ operationScope: Type.Literal("file-runtime"),
194
+ }),
195
+ object({ kind: Type.Literal("failed"), ...attemptFields, reason: Type.String() }),
196
+ ]);
197
+ const refresh = Type.Union([
198
+ attempt,
199
+ object({
200
+ kind: StringEnum(["not-requested", "not-attempted"]),
201
+ reason: Type.String(),
202
+ lastAttempt: Type.Union([attempt, Type.Null()]),
203
+ }),
204
+ ]);
205
+ const warningReport = object({
206
+ hasWarnings: Type.Boolean(),
207
+ warnings: Type.Array(
208
+ object({
209
+ type: StringEnum([
210
+ "language-disabled",
211
+ "missing-server",
212
+ "structural-unavailable",
213
+ "configuration-error",
214
+ ]),
215
+ message: Type.String(),
216
+ language: Type.Optional(Type.String()),
217
+ detail: Type.Optional(Type.String()),
218
+ }),
219
+ ),
220
+ });
221
+
222
+ /** Complete collected health facts; diagnostic observations never imply workspace-wide coverage. */
223
+ export const HealthOutputSchema = Type.Union([
224
+ object({ kind: Type.Literal("invalid-input"), message: Type.String() }),
225
+ object({
226
+ kind: Type.Literal("completed"),
227
+ level: StringEnum(["summary", "detailed"]),
228
+ includedSections: Type.Array(StringEnum(["diagnostics", "servers"])),
229
+ semanticState: Type.Union([
230
+ object({ kind: Type.Literal("ready") }),
231
+ object({
232
+ kind: StringEnum(["pending", "inactive", "disabled", "unavailable"]),
233
+ reason: Type.String(),
234
+ }),
235
+ Type.Null(),
236
+ ]),
237
+ structuralAvailable: Type.Optional(Type.Boolean()),
238
+ structuralStatus: Type.Optional(Type.String()),
239
+ diagnostics,
240
+ diagnosticMessageLimitPerFile: Type.Literal(HEALTH_DIAGNOSTIC_MESSAGE_LIMIT, {
241
+ description:
242
+ "Detailed diagnostics include at most three error/warning messages per file; line numbers are 1-based.",
243
+ }),
244
+ serverInventoryScope: Type.Literal("workspace"),
245
+ serverInventoryAvailable: Type.Boolean(),
246
+ servers: Type.Array(server),
247
+ refresh,
248
+ capabilityWarnings: Type.Optional(warningReport),
249
+ }),
250
+ ]);
@@ -0,0 +1,256 @@
1
+ import type { DiagnosticEvidenceSummary } from "@mrclrchtr/supi-lsp/api";
2
+ import type { Static } from "typebox";
3
+ import type {
4
+ HealthData,
5
+ HealthDiagnosticScope,
6
+ HealthRefreshAttempt,
7
+ HealthRefreshState,
8
+ } from "../../session/health-types.ts";
9
+ import { HEALTH_DIAGNOSTIC_MESSAGE_LIMIT } from "../../session/health-types.ts";
10
+ import type { HealthOutputSchema } from "./structured-schema.ts";
11
+
12
+ type Output = Static<typeof HealthOutputSchema>;
13
+
14
+ // Explicitly copy public fields; provider and session-owned objects must not cross this seam.
15
+ function copyEvidence(value: DiagnosticEvidenceSummary) {
16
+ return {
17
+ requested: value.requested,
18
+ confirmed: value.confirmed,
19
+ unconfirmed: value.unconfirmed,
20
+ failed: value.failed,
21
+ removed: value.removed,
22
+ documents: value.documents.map(({ file, status }) => ({ file, status })),
23
+ };
24
+ }
25
+ function copyScope(value: HealthDiagnosticScope) {
26
+ return value.kind === "file"
27
+ ? { kind: value.kind, path: value.path }
28
+ : { kind: value.kind, filter: value.filter };
29
+ }
30
+ function copyAttempt(value: HealthRefreshAttempt) {
31
+ const {
32
+ kind,
33
+ attemptedAt,
34
+ elapsedMs,
35
+ requestedDiagnosticScope,
36
+ operationScope,
37
+ attemptedActiveClients,
38
+ restartedClients,
39
+ fileReadiness,
40
+ staleAssessment,
41
+ processCrashRecovery,
42
+ startupRetry: retry,
43
+ sourceTracking,
44
+ } = value;
45
+ const diagnosticEvidence = "diagnosticEvidence" in value ? value.diagnosticEvidence : undefined;
46
+ return {
47
+ kind,
48
+ attemptedAt,
49
+ elapsedMs,
50
+ requestedDiagnosticScope: copyScope(requestedDiagnosticScope),
51
+ operationScope,
52
+ ...(attemptedActiveClients === undefined ? {} : { attemptedActiveClients }),
53
+ ...(restartedClients === undefined ? {} : { restartedClients }),
54
+ ...(fileReadiness === undefined ? {} : { fileReadiness }),
55
+ ...(staleAssessment
56
+ ? {
57
+ staleAssessment: {
58
+ scope: staleAssessment.scope,
59
+ suspected: staleAssessment.suspected,
60
+ matchedFileCount: staleAssessment.matchedFileCount,
61
+ warning: staleAssessment.warning,
62
+ },
63
+ }
64
+ : {}),
65
+ ...(diagnosticEvidence ? { diagnosticEvidence: copyEvidence(diagnosticEvidence) } : {}),
66
+ ...(processCrashRecovery
67
+ ? {
68
+ processCrashRecovery: {
69
+ recoveredRoutes: processCrashRecovery.recoveredRoutes,
70
+ skippedRoutes: processCrashRecovery.skippedRoutes,
71
+ failedRoutes: processCrashRecovery.failedRoutes,
72
+ exhaustedRoutes: processCrashRecovery.exhaustedRoutes,
73
+ omittedEntries: processCrashRecovery.omittedEntries,
74
+ entries: processCrashRecovery.entries.map(
75
+ ({ name, root, outcome, nextAction, failureMessage }) => ({
76
+ name,
77
+ root,
78
+ outcome,
79
+ ...(nextAction === undefined ? {} : { nextAction }),
80
+ ...(failureMessage === undefined ? {} : { failureMessage }),
81
+ }),
82
+ ),
83
+ },
84
+ }
85
+ : {}),
86
+ ...(retry
87
+ ? {
88
+ startupRetry: {
89
+ recoveredRoutes: retry.recoveredRoutes,
90
+ failedRoutes: retry.failedRoutes,
91
+ omittedEntries: retry.omittedEntries,
92
+ entries: retry.entries.map(({ name, root, outcome, nextAction, failureMessage }) => ({
93
+ name,
94
+ root,
95
+ outcome,
96
+ ...(nextAction === undefined ? {} : { nextAction }),
97
+ ...(failureMessage === undefined ? {} : { failureMessage }),
98
+ })),
99
+ },
100
+ }
101
+ : {}),
102
+ ...(sourceTracking
103
+ ? {
104
+ sourceTracking: {
105
+ status: sourceTracking.status,
106
+ reason: sourceTracking.reason,
107
+ observedFileCount: sourceTracking.observedFileCount,
108
+ discovered: [...sourceTracking.discovered],
109
+ tracked: [...sourceTracking.tracked],
110
+ skipped: [...sourceTracking.skipped],
111
+ unavailable: [...sourceTracking.unavailable],
112
+ deferred: sourceTracking.deferred,
113
+ },
114
+ }
115
+ : {}),
116
+ ...(kind === "failed" ? { reason: value.reason } : {}),
117
+ };
118
+ }
119
+ function copyRefresh(value: HealthRefreshState) {
120
+ return value.kind === "not-requested" || value.kind === "not-attempted"
121
+ ? {
122
+ kind: value.kind,
123
+ reason: value.reason,
124
+ lastAttempt: value.lastAttempt ? copyAttempt(value.lastAttempt) : null,
125
+ }
126
+ : copyAttempt(value);
127
+ }
128
+ /** Project health workflow facts without including session state or text-preview limits. */
129
+ export function structuredHealthResult(data: HealthData): Output {
130
+ const observation = data.diagnostics;
131
+ const entries = observation.entries.map(({ file, errors, warnings, messages }) => ({
132
+ file,
133
+ errors,
134
+ warnings,
135
+ ...(messages
136
+ ? {
137
+ messages: messages.map(({ line, severity, message, source }) => ({
138
+ line,
139
+ severity,
140
+ message,
141
+ ...(source === undefined ? {} : { source }),
142
+ })),
143
+ }
144
+ : {}),
145
+ }));
146
+ const diagnosticResult =
147
+ observation.kind === "not-requested"
148
+ ? { kind: observation.kind, entries }
149
+ : {
150
+ kind: observation.kind,
151
+ entries,
152
+ scope: copyScope(observation.scope),
153
+ evidence: copyEvidence(observation.evidence),
154
+ ...(observation.kind === "completed" ? {} : { reason: observation.reason }),
155
+ ...(observation.scopeStatus
156
+ ? {
157
+ scopeStatus: {
158
+ status: observation.scopeStatus.status,
159
+ basis: observation.scopeStatus.basis,
160
+ configPath: observation.scopeStatus.configPath,
161
+ caseSensitiveFileNames: observation.scopeStatus.caseSensitiveFileNames,
162
+ },
163
+ }
164
+ : {}),
165
+ };
166
+ const operations = [
167
+ "rename_symbol",
168
+ "prepare_rename",
169
+ "extract_function",
170
+ "extract_variable",
171
+ "update_imports",
172
+ "delete_dead_code",
173
+ "code_action_resolve",
174
+ ] as const;
175
+ const servers = data.servers.map(
176
+ ({
177
+ name,
178
+ root,
179
+ fileTypes,
180
+ status,
181
+ statusReason,
182
+ ready,
183
+ operationSupport,
184
+ typescript,
185
+ failureMessage,
186
+ }) => ({
187
+ name,
188
+ root,
189
+ fileTypes: [...fileTypes],
190
+ status,
191
+ ready,
192
+ ...(statusReason === undefined ? {} : { statusReason }),
193
+ ...(typescript ? { typescript } : {}),
194
+ ...(failureMessage ? { failureMessage } : {}),
195
+ ...(operationSupport
196
+ ? {
197
+ operationSupport: Object.fromEntries(
198
+ operations.flatMap((key) => {
199
+ const item = operationSupport[key];
200
+ return item
201
+ ? [
202
+ [
203
+ key,
204
+ {
205
+ server: item.server,
206
+ supi: item.supi,
207
+ ...(item.reason === undefined ? {} : { reason: item.reason }),
208
+ },
209
+ ],
210
+ ]
211
+ : [];
212
+ }),
213
+ ),
214
+ }
215
+ : {}),
216
+ }),
217
+ );
218
+ const semanticState =
219
+ data.semanticState === null
220
+ ? null
221
+ : data.semanticState.kind === "ready"
222
+ ? { kind: "ready" as const }
223
+ : { kind: data.semanticState.kind, reason: data.semanticState.reason };
224
+ // The input types are discriminated more narrowly than the independently projected fields.
225
+ return {
226
+ kind: "completed",
227
+ level: data.level,
228
+ includedSections: [...data.includedSections],
229
+ semanticState,
230
+ ...(data.structuralAvailable === undefined
231
+ ? {}
232
+ : { structuralAvailable: data.structuralAvailable }),
233
+ ...(data.structuralStatus === undefined ? {} : { structuralStatus: data.structuralStatus }),
234
+ diagnostics: diagnosticResult,
235
+ diagnosticMessageLimitPerFile: HEALTH_DIAGNOSTIC_MESSAGE_LIMIT,
236
+ serverInventoryScope: "workspace",
237
+ serverInventoryAvailable: data.serverInventoryAvailable,
238
+ servers,
239
+ refresh: copyRefresh(data.refresh),
240
+ ...(data.capabilityWarnings
241
+ ? {
242
+ capabilityWarnings: {
243
+ hasWarnings: data.capabilityWarnings.hasWarnings,
244
+ warnings: data.capabilityWarnings.warnings.map(
245
+ ({ type, message, language, detail }) => ({
246
+ type,
247
+ message,
248
+ ...(language === undefined ? {} : { language }),
249
+ ...(detail === undefined ? {} : { detail }),
250
+ }),
251
+ ),
252
+ },
253
+ }
254
+ : {}),
255
+ } as Output;
256
+ }
@@ -328,6 +328,7 @@ function overallProvenance(data: InspectResultData): ResultProvenance[] {
328
328
  import type { CodeIntelResult, CodeIntelToolExecCtx } from "../../types/index.ts";
329
329
  import { inspectErrorResult } from "../result/errors.ts";
330
330
  import { renderInspectResult } from "./markdown.ts";
331
+ import { structuredInspectResult } from "./structured.ts";
331
332
 
332
333
  type InspectOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["inspect"]>>;
333
334
 
@@ -335,16 +336,21 @@ type InspectOutcome = Awaited<ReturnType<CodeIntelToolExecCtx["session"]["inspec
335
336
  export function finishInspectResult(outcome: InspectOutcome): CodeIntelResult {
336
337
  if (outcome.kind === "unavailable") throw new Error(outcome.reason);
337
338
  if (outcome.kind === "invalid-input") {
338
- return inspectErrorResult(`**Error:** ${outcome.message}`, {
339
- focusTarget: "invalid input",
340
- nextQueries: ["Provide an existing file and exact 1-based point"],
341
- message: outcome.message,
342
- });
339
+ const nextQueries = ["Provide an existing file and exact 1-based point"];
340
+ return {
341
+ ...inspectErrorResult(`**Error:** ${outcome.message}`, {
342
+ focusTarget: "invalid input",
343
+ nextQueries,
344
+ message: outcome.message,
345
+ }),
346
+ structuredContent: { kind: "invalid-input", message: outcome.message, nextQueries },
347
+ };
343
348
  }
344
349
 
345
350
  const assembly = assembleInspectResult(outcome.data, outcome.nextQueries);
346
351
  return {
347
352
  content: renderInspectResult(assembly),
353
+ structuredContent: structuredInspectResult(assembly),
348
354
  details: {
349
355
  type: "inspect",
350
356
  data: assembly.details,
@@ -2,6 +2,7 @@ import { Type } from "typebox";
2
2
  import type { CodeIntelToolExecCtx } from "../../types/index.ts";
3
3
  import { MaxResultsParam, SourcePointParam } from "../schemas.ts";
4
4
  import { executeInspectTool } from "./execute.ts";
5
+ import { InspectOutputSchema } from "./structured.ts";
5
6
  import { renderInspectCall, renderInspectResult } from "./tui.ts";
6
7
 
7
8
  export const CODE_INSPECT_TOOL_NAME = "code_inspect";
@@ -11,6 +12,7 @@ export const CODE_INSPECT_TOOL_LABEL = "Code Inspect";
11
12
  export const codeInspectSpec = {
12
13
  name: CODE_INSPECT_TOOL_NAME,
13
14
  label: CODE_INSPECT_TOOL_LABEL,
15
+ outputSchema: InspectOutputSchema,
14
16
  parameters: Type.Object(
15
17
  {
16
18
  point: SourcePointParam,