@mrclrchtr/supi-code-intelligence 11.1.0 → 11.3.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 (199) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +41 -6
  3. package/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  4. package/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  5. package/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  6. package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  7. package/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  8. package/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  9. package/node_modules/@mrclrchtr/supi-lsp/README.md +81 -7
  10. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  11. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  12. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  13. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  14. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  15. package/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  16. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/LICENSE +15 -0
  17. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/README.md +680 -0
  18. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/bin/semver.js +195 -0
  19. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/comparator.js +143 -0
  20. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/index.js +7 -0
  21. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/range.js +577 -0
  22. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/classes/semver.js +350 -0
  23. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/clean.js +8 -0
  24. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/cmp.js +54 -0
  25. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/coerce.js +62 -0
  26. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-build.js +9 -0
  27. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare-loose.js +5 -0
  28. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/compare.js +7 -0
  29. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/diff.js +60 -0
  30. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/eq.js +5 -0
  31. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gt.js +5 -0
  32. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/gte.js +5 -0
  33. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/inc.js +21 -0
  34. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lt.js +5 -0
  35. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/lte.js +5 -0
  36. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/major.js +5 -0
  37. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/minor.js +5 -0
  38. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/neq.js +5 -0
  39. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/parse.js +18 -0
  40. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/patch.js +5 -0
  41. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/prerelease.js +8 -0
  42. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rcompare.js +5 -0
  43. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/rsort.js +5 -0
  44. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/satisfies.js +12 -0
  45. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/sort.js +5 -0
  46. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/truncate.js +48 -0
  47. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/functions/valid.js +8 -0
  48. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/index.js +93 -0
  49. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/constants.js +37 -0
  50. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/debug.js +11 -0
  51. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/identifiers.js +29 -0
  52. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/lrucache.js +42 -0
  53. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/parse-options.js +17 -0
  54. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/internal/re.js +223 -0
  55. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/package.json +78 -0
  56. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/preload.js +4 -0
  57. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/range.bnf +17 -0
  58. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/gtr.js +6 -0
  59. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/intersects.js +9 -0
  60. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/ltr.js +6 -0
  61. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/max-satisfying.js +27 -0
  62. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-satisfying.js +26 -0
  63. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/min-version.js +63 -0
  64. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/outside.js +82 -0
  65. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/simplify.js +49 -0
  66. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/subset.js +249 -0
  67. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/to-comparators.js +10 -0
  68. package/node_modules/@mrclrchtr/supi-lsp/node_modules/semver/ranges/valid.js +13 -0
  69. package/node_modules/@mrclrchtr/supi-lsp/package.json +5 -3
  70. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostic-collection.ts +11 -4
  71. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-diagnostics.ts +77 -6
  72. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-input-admission.ts +149 -0
  73. package/node_modules/@mrclrchtr/supi-lsp/src/client/client-typescript-project.ts +40 -0
  74. package/node_modules/@mrclrchtr/supi-lsp/src/client/client.ts +174 -49
  75. package/node_modules/@mrclrchtr/supi-lsp/src/config/config.ts +53 -2
  76. package/node_modules/@mrclrchtr/supi-lsp/src/config/operation-support.ts +19 -4
  77. package/node_modules/@mrclrchtr/supi-lsp/src/config/server-config.ts +22 -0
  78. package/node_modules/@mrclrchtr/supi-lsp/src/config/typescript-launch.ts +276 -0
  79. package/node_modules/@mrclrchtr/supi-lsp/src/diagnostics/evidence.ts +2 -2
  80. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-project-info.ts +22 -10
  81. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager-workspace-symbol.ts +157 -23
  82. package/node_modules/@mrclrchtr/supi-lsp/src/manager/manager.ts +306 -75
  83. package/node_modules/@mrclrchtr/supi-lsp/src/provider/refactor-planning.ts +4 -3
  84. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-controller.ts +2 -2
  85. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-registry.ts +19 -2
  86. package/node_modules/@mrclrchtr/supi-lsp/src/session/runtime-rename.ts +1 -0
  87. package/node_modules/@mrclrchtr/supi-lsp/src/session/scanner.ts +27 -15
  88. package/node_modules/@mrclrchtr/supi-lsp/src/session/workspace-lsp-runtime.ts +5 -1
  89. package/node_modules/@mrclrchtr/supi-tree-sitter/README.md +2 -2
  90. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +1 -1
  91. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/capability/types.ts +3 -1
  92. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/src/query-result.ts +9 -0
  93. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +1 -1
  94. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/child-web-tools.ts +110 -0
  95. package/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/session.ts +11 -0
  96. package/node_modules/@mrclrchtr/supi-tree-sitter/package.json +3 -3
  97. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm +0 -0
  98. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/tsx/tree-sitter-tsx.wasm.json +5 -1
  99. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm +0 -0
  100. package/node_modules/@mrclrchtr/supi-tree-sitter/resources/grammars/typescript/tree-sitter-typescript.wasm.json +5 -1
  101. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/call-sites.ts +40 -25
  102. package/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/callees.ts +2 -0
  103. package/node_modules/@mrclrchtr/supi-tree-sitter/src/worker/call-context.ts +44 -0
  104. package/package.json +6 -5
  105. package/src/analysis/capability/capability-warnings.ts +18 -12
  106. package/src/analysis/health/check.ts +115 -0
  107. package/src/analysis/health/diagnostics.ts +3 -0
  108. package/src/analysis/health/file-scope.ts +2 -3
  109. package/src/analysis/health/semantic-state.ts +38 -0
  110. package/src/analysis/health/server-status.ts +14 -2
  111. package/src/analysis/health/signals.ts +2 -0
  112. package/src/analysis/health/status.ts +82 -0
  113. package/src/analysis/refactor/apply.ts +17 -8
  114. package/src/analysis/search/exclusions.ts +47 -0
  115. package/src/analysis/search/paths.ts +32 -9
  116. package/src/analysis/target/anchored-structural.ts +3 -8
  117. package/src/analysis/target/anchored.ts +4 -20
  118. package/src/analysis/target/identity.ts +1 -1
  119. package/src/analysis/target/latex-label-container.ts +6 -6
  120. package/src/analysis/target/latex-section-anchor.ts +6 -6
  121. package/src/analysis/target/resolution.ts +18 -0
  122. package/src/analysis/target/symbol.ts +39 -11
  123. package/src/analysis/target/types.ts +6 -1
  124. package/src/extension.ts +17 -11
  125. package/src/session/graph/collect.ts +1 -10
  126. package/src/session/graph-types.ts +2 -0
  127. package/src/session/graph-workflow.ts +1 -0
  128. package/src/session/health-types.ts +7 -0
  129. package/src/session/health-workflow.ts +8 -43
  130. package/src/session/inspect/collect.ts +8 -2
  131. package/src/session/inspect/file-point.ts +2 -3
  132. package/src/session/inspect-workflow.ts +1 -1
  133. package/src/session/orientation/collect.ts +184 -20
  134. package/src/session/orientation/context-facts.ts +27 -2
  135. package/src/session/orientation/context-sections.ts +49 -3
  136. package/src/session/orientation/facts.ts +132 -0
  137. package/src/session/orientation/gather.ts +98 -11
  138. package/src/session/orientation/workspace-context.ts +16 -6
  139. package/src/session/orientation-types.ts +8 -0
  140. package/src/session/orientation-workflow.ts +20 -6
  141. package/src/session/refactor-identity.ts +76 -0
  142. package/src/session/refactor-plans.ts +5 -2
  143. package/src/session/refactor-workflow.ts +15 -17
  144. package/src/session/target-store.ts +3 -18
  145. package/src/session/target-workflow.ts +33 -16
  146. package/src/substrate/lsp/recovery.ts +5 -5
  147. package/src/tool/code_find/guidance.ts +1 -1
  148. package/src/tool/code_find/render.ts +8 -4
  149. package/src/tool/code_find/result.ts +78 -6
  150. package/src/tool/code_find/spec.ts +4 -3
  151. package/src/tool/code_find/structured.ts +25 -9
  152. package/src/tool/code_graph/details.ts +1 -0
  153. package/src/tool/code_graph/display.ts +1 -1
  154. package/src/tool/code_graph/guidance.ts +1 -1
  155. package/src/tool/code_graph/markdown.ts +11 -6
  156. package/src/tool/code_graph/read-next.ts +38 -9
  157. package/src/tool/code_graph/reference-selection.ts +30 -0
  158. package/src/tool/code_graph/result.ts +25 -118
  159. package/src/tool/code_graph/section.ts +133 -0
  160. package/src/tool/code_graph/spec.ts +3 -3
  161. package/src/tool/code_graph/structured.ts +17 -6
  162. package/src/tool/code_health/display-paths.ts +92 -0
  163. package/src/tool/code_health/file-scope-markdown.ts +3 -2
  164. package/src/tool/code_health/markdown.ts +12 -2
  165. package/src/tool/code_health/result.ts +18 -3
  166. package/src/tool/code_health/spec.ts +5 -3
  167. package/src/tool/code_health/structured-schema.ts +250 -0
  168. package/src/tool/code_health/structured.ts +256 -0
  169. package/src/tool/code_inspect/result.ts +11 -5
  170. package/src/tool/code_inspect/spec.ts +7 -1
  171. package/src/tool/code_inspect/structured.ts +231 -0
  172. package/src/tool/code_orientation/execute.ts +1 -1
  173. package/src/tool/code_orientation/result.ts +31 -8
  174. package/src/tool/code_orientation/spec.ts +2 -0
  175. package/src/tool/code_orientation/structured-schema.ts +617 -0
  176. package/src/tool/code_orientation/structured-workspace.ts +194 -0
  177. package/src/tool/code_orientation/structured.ts +189 -0
  178. package/src/tool/code_orientation/workspace-format.ts +2 -5
  179. package/src/tool/code_orientation/workspace-observations.ts +81 -0
  180. package/src/tool/code_orientation/workspace-output.ts +5 -0
  181. package/src/tool/code_orientation/workspace-projects.ts +16 -31
  182. package/src/tool/code_orientation/workspace-sections.ts +46 -32
  183. package/src/tool/code_refactor_apply/execute.ts +1 -1
  184. package/src/tool/code_refactor_apply/result.ts +14 -6
  185. package/src/tool/code_refactor_apply/spec.ts +2 -0
  186. package/src/tool/code_refactor_apply/structured.ts +49 -0
  187. package/src/tool/code_refactor_plan/result.ts +18 -9
  188. package/src/tool/code_refactor_plan/spec.ts +2 -0
  189. package/src/tool/code_refactor_plan/structured.ts +127 -0
  190. package/src/tool/code_resolve/markdown.ts +6 -30
  191. package/src/tool/code_resolve/result.ts +24 -11
  192. package/src/tool/code_resolve/structured.ts +7 -9
  193. package/src/tool/result/refactor.ts +8 -5
  194. package/src/tool/result/structured.ts +8 -5
  195. package/src/tool/result/types.ts +18 -14
  196. package/src/tool/schemas.ts +12 -6
  197. package/src/ui/status-command.ts +147 -322
  198. package/src/ui/status-overlay.ts +584 -421
  199. package/src/ui/status-presentation.ts +108 -0
@@ -1,563 +1,726 @@
1
- // Code Intelligence status dialog — toggleable center overlay showing LSP + Tree-sitter
2
- // status, expandable per-file diagnostics, and active code_* tool surface.
3
-
4
- import { DynamicBorder } from "@earendil-works/pi-coding-agent";
1
+ import { relative, resolve } from "node:path";
2
+ import { DynamicBorder, type Theme } from "@earendil-works/pi-coding-agent";
5
3
  import {
6
4
  Container,
5
+ getKeybindings,
7
6
  Key,
7
+ type KeybindingsManager,
8
8
  matchesKey,
9
+ ScrollView,
9
10
  Spacer,
10
11
  Text,
11
12
  truncateToWidth,
12
- visibleWidth,
13
13
  } from "@earendil-works/pi-tui";
14
14
  import { BRAILLE_SPINNER_FRAMES } from "@mrclrchtr/supi-core/spinner-frames";
15
15
  import type {
16
16
  Diagnostic,
17
- OutstandingDiagnosticSummaryEntry,
17
+ DiagnosticEvidenceSummary,
18
18
  ProjectServerInfo,
19
19
  } from "@mrclrchtr/supi-lsp/api";
20
- import type { CapabilityWarningReport } from "../analysis/capability/capability-warnings.ts";
20
+ import type {
21
+ DiagnosticCheckFile,
22
+ WorkspaceDiagnosticCheckReport,
23
+ } from "../analysis/health/check.ts";
21
24
  import {
22
25
  countProjectServerRouteStatuses,
23
- formatProjectServerOperationSupport,
26
+ formatProjectServerCompiler,
24
27
  formatProjectServerRoot,
25
28
  formatProjectServerStatusReason,
26
29
  } from "../analysis/health/server-status.ts";
30
+ import type { WorkspaceStatusSnapshot } from "../analysis/health/status.ts";
31
+ import type { HealthDiagnosticEntry } from "../session/health-types.ts";
27
32
  import { diagnosticMessageString } from "../substrate/lsp/utils.ts";
28
-
29
- /**
30
- * Minimal theme contract used by the dialog. Matches the public `theme.fg()` /
31
- * `theme.bold()` shape exposed by `@earendil-works/pi-tui` — the full Theme
32
- * type is internal to pi-coding-agent and not re-exported.
33
- */
34
- export interface CiDialogTheme {
35
- fg: (color: string, text: string) => string;
36
- bg?: (color: string, text: string) => string;
37
- bold: (text: string) => string;
33
+ import {
34
+ CiHealthRefreshError,
35
+ presentDiagnosticDetails,
36
+ presentDiagnosticEvidence,
37
+ } from "./status-presentation.ts";
38
+
39
+ /** Passive health facts plus the session's active tool surface. */
40
+ export interface CiStatusData extends WorkspaceStatusSnapshot {
41
+ readonly activeTools: readonly string[];
42
+ readonly diagnosticCheck?: WorkspaceDiagnosticCheckReport;
43
+ /** Compact outcome of the latest health action, never a source of current evidence. */
44
+ readonly healthRefresh?: readonly string[];
38
45
  }
39
46
 
40
- export interface CiStatusData {
41
- /** Canonical workspace root used to display LSP route roots. */
42
- workspaceRoot: string;
43
- servers: ProjectServerInfo[];
44
- /** Whether the server list is complete status evidence. */
45
- serverInventoryAvailable: boolean;
46
- /** Whether diagnostics and semantic absence claims are currently supported. */
47
- semanticAvailable: boolean;
48
- /** Whether tracked-file diagnostic counts prove the current document and workspace state. */
49
- diagnosticSnapshotCurrent: boolean;
50
- /** Sorted: errors desc, then warnings desc, then info desc, then hints desc. */
51
- diagnostics: OutstandingDiagnosticSummaryEntry[];
52
- capabilities: {
53
- semantic: { kind: string; reason?: string; providerAvailable: boolean };
54
- structural: { kind: string; reason?: string; providerAvailable: boolean };
55
- refactorAvailable: boolean;
56
- };
57
- activeTools: string[];
58
- /** Supplemental Capability Warnings. Undefined when fully healthy. */
59
- capabilityWarnings?: CapabilityWarningReport;
47
+ /** Full messages and file-specific evidence from one passive diagnostic snapshot. */
48
+ export interface CiDiagnosticDetails {
49
+ readonly evidence: DiagnosticEvidenceSummary;
50
+ readonly entries: readonly {
51
+ readonly file: string;
52
+ readonly diagnostics: readonly Diagnostic[];
53
+ }[];
60
54
  }
61
55
 
62
- /** Fetcher for full diagnostic details when a file row is expanded. */
63
- export type DiagFetcher = (
64
- maxSeverity: number,
65
- ) =>
66
- | Array<{ file: string; diagnostics: Diagnostic[] }>
67
- | Promise<Array<{ file: string; diagnostics: Diagnostic[] }>>;
68
-
56
+ /** Dependencies owned by one terminal interaction. Reload is passive, not LSP recovery. */
69
57
  export interface CiStatusDialogDeps {
70
- theme: CiDialogTheme;
58
+ theme: Pick<Theme, "fg" | "bold">;
71
59
  done: () => void;
72
- tui: { requestRender: () => void };
73
- /** Async fetcher for full diagnostics on expand. Optional. */
74
- fetchDetailedDiagnostics?: DiagFetcher;
75
- /** Refresh callback — re-fetches data when 'r' is pressed. */
76
- onRefresh?: () => Promise<CiStatusData>;
60
+ tui: { terminal: { rows: number }; requestRender: () => void };
61
+ keybindings?: KeybindingsManager;
62
+ fetchDetailedDiagnostics?: () => CiDiagnosticDetails | Promise<CiDiagnosticDetails>;
63
+ onRefresh?: (signal: AbortSignal) => Promise<CiStatusData>;
64
+ onCheck?: (signal: AbortSignal) => Promise<CiStatusData>;
65
+ onHealth?: (signal: AbortSignal) => Promise<CiStatusData>;
77
66
  }
78
67
 
79
- const MAX_FILES_IN_LIST = 10;
68
+ type DiagnosticFile = DiagnosticCheckFile & HealthDiagnosticEntry;
69
+
70
+ type DetailState =
71
+ | { kind: "loading" }
72
+ | { kind: "ready"; diagnostics: readonly Diagnostic[]; evidenceLabel: string }
73
+ | { kind: "error"; message: string };
80
74
  const MAX_INLINE_MESSAGES = 5;
81
75
  const MAX_OPEN_FILES_SHOWN = 3;
82
- const SPINNER_INTERVAL_MS = 80;
83
-
76
+ const FRAME_ROWS = 6;
77
+ const ACTION_LABELS = {
78
+ reload: { name: "Reload", progress: "reloading" },
79
+ check: { name: "Check", progress: "checking" },
80
+ health: { name: "Refresh health", progress: "refreshing health" },
81
+ };
82
+ const STATUS_ACTIONS = [
83
+ "tui.select.cancel",
84
+ "tui.select.up",
85
+ "tui.select.down",
86
+ "tui.select.confirm",
87
+ "tui.select.pageUp",
88
+ "tui.select.pageDown",
89
+ "tui.input.tab",
90
+ ] as const;
91
+
92
+ /** A bounded inspector with file-keyed selection and interaction-local asynchronous work. */
84
93
  export class CiStatusDialog {
85
- private selectedFileIdx = 0;
86
- private expandedFileIdx: number | null = null;
87
- private expandedDiagnostics: Diagnostic[] | null = null;
94
+ private files: readonly DiagnosticFile[];
95
+ private selectedFile: string | undefined;
96
+ private expandedFile: string | undefined;
97
+ private details: DetailState | undefined;
98
+ private detailGeneration = 0;
99
+ private refreshGeneration = 0;
100
+ private refreshing = false;
101
+ private refreshError: string | undefined;
102
+ private healthRefresh: readonly string[] | undefined;
103
+ private refreshAction: "reload" | "check" | "health" = "reload";
104
+ private refreshController: AbortController | undefined;
105
+ private disposed = false;
106
+ private spinner: ReturnType<typeof setInterval> | undefined;
107
+ private spinnerFrame = 0;
88
108
  private cachedWidth: number | undefined;
109
+ private cachedHeight: number | undefined;
89
110
  private cachedLines: string[] | undefined;
90
- private spinnerInterval: ReturnType<typeof setInterval> | null = null;
91
- private spinnerFrame = 0;
92
- private loading = false;
111
+ private bodyLines: string[] = [];
112
+ private selectedRow = 0;
113
+ private expandedRows = 1;
114
+ private revealSelection = false;
115
+ private followingSelection = false;
116
+ // A late check may update data, but must not replace newer navigation intent.
117
+ private navigationGeneration = 0;
118
+ private readonly scroll = new ScrollView({ render: () => this.bodyLines, invalidate() {} });
119
+ private readonly keybindings: KeybindingsManager;
93
120
 
94
121
  constructor(
95
122
  private data: CiStatusData,
96
- deps: CiStatusDialogDeps,
123
+ private readonly deps: CiStatusDialogDeps,
97
124
  ) {
98
- this.theme = deps.theme;
99
- this.done = deps.done;
100
- this.tui = deps.tui;
101
- this.fetchDetailedDiagnostics = deps.fetchDetailedDiagnostics;
102
- this.onRefresh = deps.onRefresh;
125
+ this.files = diagnosticFiles(data);
126
+ this.healthRefresh = data.healthRefresh;
127
+ this.selectedFile = this.files[0]?.file;
128
+ this.keybindings = deps.keybindings ?? getKeybindings();
103
129
  }
104
130
 
105
- /** Called by pi-tui when the overlay is removed. */
131
+ /** Invalidate in-flight work before releasing the spinner and terminal interaction. */
106
132
  dispose(): void {
133
+ this.disposed = true;
134
+ this.detailGeneration++;
135
+ this.refreshGeneration++;
136
+ this.refreshController?.abort();
107
137
  this.stopSpinner();
108
138
  }
109
139
 
110
140
  render(width: number): string[] {
111
- if (this.cachedLines && this.cachedWidth === width) {
141
+ const height = Math.max(1, Math.floor(this.deps.tui.terminal.rows * 0.85));
142
+ if (this.cachedLines && this.cachedWidth === width && this.cachedHeight === height)
112
143
  return this.cachedLines;
144
+ if (height <= FRAME_ROWS)
145
+ return [truncateToWidth(`CI · ${this.keyLabel("tui.select.cancel")} close`, width)];
146
+ const bodyHeight = height - FRAME_ROWS;
147
+ const resized =
148
+ this.cachedHeight !== undefined &&
149
+ (this.cachedHeight !== height || this.cachedWidth !== width);
150
+ this.bodyLines = this.renderBody(width);
151
+ this.scroll.updateLayout(this.bodyLines.length, bodyHeight, () =>
152
+ this.deps.tui.requestRender(),
153
+ );
154
+ if (this.revealSelection || (resized && this.followingSelection)) {
155
+ const end = this.selectedRow + Math.min(this.expandedRows, bodyHeight) - 1;
156
+ if (this.selectedRow < this.scroll.scrollTop) this.scroll.scrollTo(this.selectedRow);
157
+ else if (end >= this.scroll.scrollTop + bodyHeight)
158
+ this.scroll.scrollTo(end - bodyHeight + 1);
113
159
  }
114
- const container = new Container();
115
- container.addChild(new DynamicBorder((s: string) => this.theme.fg("accent", s)));
116
- container.addChild(new Text(this.renderHeader(), 1, 0));
117
- container.addChild(new Spacer(1));
118
- container.addChild(new Text(this.renderSummaryLine(width), 1, 0));
119
- container.addChild(new Spacer(1));
120
- this.addServerSection(container);
121
- container.addChild(new Spacer(1));
122
- this.addProblemsSection(container, width);
123
- container.addChild(new Spacer(1));
124
- this.addCapabilitiesSection(container);
125
- this.addCapabilityWarningsSection(container);
126
- this.addToolsSection(container, width);
127
- container.addChild(new Text(this.renderKeyHints(), 1, 0));
128
- container.addChild(new DynamicBorder((s: string) => this.theme.fg("accent", s)));
129
-
130
- const lines = container.render(width).map((line) => truncateToWidth(line, width));
160
+ this.revealSelection = false;
161
+ const t = this.deps.theme;
162
+ const border = new DynamicBorder((s) => t.fg("accent", s)).render(width)[0] ?? "";
163
+ const position =
164
+ this.bodyLines.length > bodyHeight
165
+ ? ` · ${this.scroll.scrollTop + 1}–${Math.min(this.scroll.scrollTop + bodyHeight, this.bodyLines.length)}/${this.bodyLines.length}`
166
+ : "";
167
+ // Pi's overlay adapter only calls render(width), not the fullscreen layout engine.
168
+ // ScrollView owns offsets/clamping; apply its viewport explicitly for this adapter.
169
+ const lines = [
170
+ border,
171
+ t.fg("accent", t.bold("◆ Code Intelligence")) + t.fg("dim", " · /supi-ci-status"),
172
+ this.summaryLine(),
173
+ ...this.scroll.render(width).slice(this.scroll.scrollTop, this.scroll.scrollTop + bodyHeight),
174
+ t.fg("dim", this.controlHints()),
175
+ t.fg(
176
+ "dim",
177
+ `${this.keyLabel("tui.select.up")}/${this.keyLabel("tui.select.down")} scroll · ${this.fileNavigationHint()} · ${this.keyLabel("tui.select.pageUp")}/${this.keyLabel("tui.select.pageDown")} page · home/end${position}`,
178
+ ),
179
+ border,
180
+ ].map((line) => truncateToWidth(line, width));
131
181
  this.cachedWidth = width;
182
+ this.cachedHeight = height;
132
183
  this.cachedLines = lines;
133
184
  return lines;
134
185
  }
135
186
 
136
187
  invalidate(): void {
137
- this.cachedWidth = undefined;
138
188
  this.cachedLines = undefined;
139
189
  }
140
190
 
141
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: single handler dispatching keyboard shortcuts
142
- handleInput(data: string): boolean {
143
- // ── Global actions ───────────────────────────────────────────────
144
- if (matchesKey(data, Key.ctrl("c")) || matchesKey(data, Key.escape)) {
145
- this.stopSpinner();
146
- this.done();
191
+ handleInput(input: string): boolean {
192
+ if (this.disposed) return false;
193
+ if (this.keybindings.matches(input, "tui.select.cancel")) {
194
+ this.dispose();
195
+ this.deps.done();
147
196
  return true;
148
197
  }
198
+ return (
199
+ this.handleScrollInput(input) ||
200
+ this.handleFileInput(input) ||
201
+ this.handleDiagnosticActionInput(input) ||
202
+ this.handleShortcutInput(input)
203
+ );
204
+ }
149
205
 
150
- if (data === "a") {
151
- this.expandedFileIdx = null;
152
- this.expandedDiagnostics = null;
153
- this.stopSpinner();
154
- this.invalidate();
155
- this.tui.requestRender();
156
- return true;
157
- }
206
+ private handleDiagnosticActionInput(input: string): boolean {
207
+ if (this.hasConfiguredAction(input)) return false;
208
+ let action: "check" | "health";
209
+ if (input === "c" || matchesKey(input, "f5")) action = "check";
210
+ else if (input === "h" || matchesKey(input, "f6")) action = "health";
211
+ else return false;
212
+ if (!(action === "check" ? this.deps.onCheck : this.deps.onHealth)) return false;
213
+ void this.reload(action);
214
+ return true;
215
+ }
158
216
 
159
- if (data === "r" && this.onRefresh) {
160
- void this.handleRefresh();
217
+ private handleShortcutInput(input: string): boolean {
218
+ if (input === "r" && this.deps.onRefresh) {
219
+ void this.reload();
161
220
  return true;
162
221
  }
163
-
164
- // ── Navigation ───────────────────────────────────────────────────
165
- const fileCount = this.data.diagnostics.length;
166
-
167
- if ((matchesKey(data, Key.up) || data === "k") && this.selectedFileIdx > 0) {
168
- this.selectedFileIdx--;
169
- this.invalidate();
170
- this.tui.requestRender();
222
+ if (input === "a") {
223
+ this.collapse();
224
+ this.changed();
171
225
  return true;
172
226
  }
227
+ if (input === "j" || input === "k") {
228
+ this.scroll.scrollBy(input === "k" ? -1 : 1);
229
+ } else if (matchesKey(input, Key.home)) this.scroll.scrollToStart();
230
+ else if (matchesKey(input, Key.end)) this.scroll.scrollToEnd();
231
+ else return false;
232
+ this.scrolled();
233
+ return true;
234
+ }
173
235
 
174
- if ((matchesKey(data, Key.down) || data === "j") && this.selectedFileIdx < fileCount - 1) {
175
- this.selectedFileIdx++;
176
- this.invalidate();
177
- this.tui.requestRender();
178
- return true;
179
- }
236
+ private handleScrollInput(input: string): boolean {
237
+ const page = Math.max(1, this.scroll.viewportHeight - 1);
238
+ let lines: number;
239
+ if (this.keybindings.matches(input, "tui.select.up")) lines = -1;
240
+ else if (this.keybindings.matches(input, "tui.select.down")) lines = 1;
241
+ else if (this.keybindings.matches(input, "tui.select.pageUp")) lines = -page;
242
+ else if (this.keybindings.matches(input, "tui.select.pageDown")) lines = page;
243
+ else return false;
244
+ this.scroll.scrollBy(lines);
245
+ this.scrolled();
246
+ return true;
247
+ }
180
248
 
181
- if (
182
- (matchesKey(data, Key.enter) || matchesKey(data, Key.space) || data === " ") &&
183
- fileCount > 0
184
- ) {
185
- if (this.expandedFileIdx === this.selectedFileIdx) {
186
- this.expandedFileIdx = null;
187
- this.expandedDiagnostics = null;
188
- this.stopSpinner();
189
- } else {
190
- this.expandedFileIdx = this.selectedFileIdx;
191
- this.expandedDiagnostics = null;
192
- void this.loadDetailedDiagnostics();
193
- }
194
- this.invalidate();
195
- this.tui.requestRender();
196
- return true;
197
- }
249
+ /** Manual scrolling owns the viewport until diagnostic-file navigation resumes. */
250
+ private scrolled(): void {
251
+ this.navigationGeneration++;
252
+ this.followingSelection = false;
253
+ this.revealSelection = false;
254
+ this.changed();
255
+ }
198
256
 
257
+ private handleFileInput(input: string): boolean {
258
+ if (this.keybindings.matches(input, "tui.select.confirm")) return this.expandSelection();
259
+ if (this.keybindings.matches(input, "tui.input.tab")) return this.moveSelection(1);
260
+ if (matchesKey(input, Key.shift("tab"))) return this.moveSelection(-1);
261
+ if (matchesKey(input, Key.space)) return this.expandSelection();
199
262
  return false;
200
263
  }
201
264
 
202
- // ── Spinner ───────────────────────────────────────────────────────
203
-
204
- private startSpinner(): void {
205
- if (this.spinnerInterval) return;
206
- this.loading = true;
207
- this.spinnerFrame = 0;
208
- this.spinnerInterval = setInterval(() => {
209
- this.spinnerFrame = (this.spinnerFrame + 1) % BRAILLE_SPINNER_FRAMES.length;
210
- this.invalidate();
211
- this.tui.requestRender();
212
- }, SPINNER_INTERVAL_MS);
265
+ private expandSelection(): boolean {
266
+ if (!this.selectedFile) return true;
267
+ this.navigationGeneration++;
268
+ if (this.expandedFile === this.selectedFile) this.collapse();
269
+ else {
270
+ this.collapse();
271
+ this.expandedFile = this.selectedFile;
272
+ void this.loadDetails(this.selectedFile);
273
+ }
274
+ this.followingSelection = true;
275
+ this.revealSelection = true;
276
+ this.changed();
277
+ return true;
213
278
  }
214
279
 
215
- private stopSpinner(): void {
216
- if (this.spinnerInterval) {
217
- clearInterval(this.spinnerInterval);
218
- this.spinnerInterval = null;
219
- }
220
- this.loading = false;
280
+ private moveSelection(direction: number): boolean {
281
+ this.navigationGeneration++;
282
+ const files = this.files;
283
+ const index = files.findIndex((entry) => entry.file === this.selectedFile);
284
+ const next = files[Math.max(0, Math.min(files.length - 1, index + direction))];
285
+ if (next) this.selectedFile = next.file;
286
+ this.followingSelection = true;
287
+ this.revealSelection = true;
288
+ this.changed();
289
+ return true;
221
290
  }
222
291
 
223
- // ── Async data loading ─────────────────────────────────────────────
292
+ private collapse(): void {
293
+ this.detailGeneration++;
294
+ this.expandedFile = undefined;
295
+ this.details = undefined;
296
+ this.updateSpinner();
297
+ }
224
298
 
225
- private async handleRefresh(): Promise<void> {
226
- if (!this.onRefresh) return;
227
- this.startSpinner();
299
+ private async loadDetails(file: string): Promise<void> {
300
+ const fetch = this.deps.fetchDetailedDiagnostics;
301
+ if (!fetch) {
302
+ this.details = { kind: "error", message: "Diagnostic details are unavailable" };
303
+ return;
304
+ }
305
+ const generation = ++this.detailGeneration;
306
+ this.details = { kind: "loading" };
307
+ this.changed();
228
308
  try {
229
- this.data = await this.onRefresh();
230
- } finally {
231
- this.stopSpinner();
309
+ const result = await fetch();
310
+ if (this.disposed || generation !== this.detailGeneration) return;
311
+ const entry = result.entries.find(
312
+ (entry) =>
313
+ resolve(this.data.workspaceRoot, entry.file) === resolve(this.data.workspaceRoot, file),
314
+ );
315
+ this.details = {
316
+ kind: "ready",
317
+ diagnostics: entry?.diagnostics ?? [],
318
+ evidenceLabel: presentDiagnosticDetails(result.evidence, this.data.workspaceRoot, file),
319
+ };
320
+ } catch (error) {
321
+ if (this.disposed || generation !== this.detailGeneration) return;
322
+ this.details = { kind: "error", message: errorText(error) };
232
323
  }
233
- this.selectedFileIdx = Math.min(
234
- this.selectedFileIdx,
235
- Math.max(0, this.data.diagnostics.length - 1),
236
- );
237
- this.expandedFileIdx = null;
238
- this.expandedDiagnostics = null;
239
- this.invalidate();
240
- this.tui.requestRender();
324
+ if (!this.disposed && generation === this.detailGeneration) this.changed();
241
325
  }
242
326
 
243
- private async loadDetailedDiagnostics(): Promise<void> {
244
- if (!this.fetchDetailedDiagnostics || this.expandedFileIdx === null) return;
245
- const fileName = this.data.diagnostics[this.expandedFileIdx]?.file;
246
- if (!fileName) return;
247
- this.startSpinner();
327
+ private async reload(action: "reload" | "check" | "health" = "reload"): Promise<void> {
328
+ const collect = {
329
+ check: this.deps.onCheck,
330
+ health: this.deps.onHealth,
331
+ reload: this.deps.onRefresh,
332
+ }[action];
333
+ if (this.refreshing || !collect) return;
334
+ const generation = ++this.refreshGeneration;
335
+ const navigation = this.navigationGeneration;
336
+ this.refreshController = new AbortController();
337
+ this.refreshAction = action;
338
+ this.refreshing = true;
339
+ this.refreshError = undefined;
340
+ this.healthRefresh = undefined;
341
+ this.collapse();
342
+ this.changed();
248
343
  try {
249
- const detailed = await this.fetchDetailedDiagnostics(1);
250
- const entry = detailed.find((d) => d.file === fileName);
251
- this.expandedDiagnostics = entry?.diagnostics ?? [];
252
- } catch {
253
- this.expandedDiagnostics = [];
254
- } finally {
255
- this.stopSpinner();
344
+ const data = await collect(this.refreshController.signal);
345
+ if (this.disposed || generation !== this.refreshGeneration) return;
346
+ this.acceptSnapshot(data, action === "check" && navigation === this.navigationGeneration);
347
+ } catch (error) {
348
+ if (this.disposed || generation !== this.refreshGeneration) return;
349
+ this.refreshError = errorText(error);
350
+ if (error instanceof CiHealthRefreshError) this.healthRefresh = error.healthRefresh;
351
+ }
352
+ if (!this.disposed && generation === this.refreshGeneration) {
353
+ this.refreshing = false;
354
+ this.refreshController = undefined;
355
+ this.changed();
256
356
  }
257
- this.invalidate();
258
- this.tui.requestRender();
259
- }
260
-
261
- // ── Section builders ──────────────────────────────────────────────
262
-
263
- private renderHeader(): string {
264
- const accent = this.theme.fg("accent", this.theme.bold("◆ Code Intelligence"));
265
- const hint = this.theme.fg("dim", " /supi-ci-status toggles · ↑↓ nav · enter expand");
266
- return truncateToWidth(accent + hint, 1000);
267
357
  }
268
358
 
269
- private renderKeyHints(): string {
270
- return this.theme.fg("dim", " r refresh · a collapse all · esc close");
359
+ private acceptSnapshot(data: CiStatusData, check: boolean): void {
360
+ this.data = data;
361
+ this.healthRefresh = data.healthRefresh;
362
+ this.files = diagnosticFiles(data);
363
+ if (!this.files.some((entry) => entry.file === this.selectedFile))
364
+ this.selectedFile = this.files[0]?.file;
365
+ // Collection closed the previous expansion at start; any current one is newer user intent.
366
+ const expanded = this.expandedFile;
367
+ this.collapse();
368
+ if (expanded && this.files.some((entry) => entry.file === expanded)) {
369
+ this.expandedFile = expanded;
370
+ void this.loadDetails(expanded);
371
+ }
372
+ if (check) {
373
+ const firstChecked = data.diagnosticCheck?.files[0];
374
+ if (firstChecked) this.selectedFile = resolve(data.workspaceRoot, firstChecked.file);
375
+ this.followingSelection = true;
376
+ }
377
+ this.revealSelection = this.followingSelection;
271
378
  }
272
379
 
273
- private renderSummaryLine(width: number): string {
274
- const parts = [
275
- ...this.serverSummaryParts(),
276
- ...this.diagnosticSummaryParts(),
277
- ...this.routeSummaryParts(),
278
- this.structuralSummaryPart(),
279
- ];
280
- const joined =
281
- parts.length > 0
282
- ? parts.join(this.theme.fg("dim", " · "))
283
- : this.theme.fg("dim", "(no data)");
284
- return truncateToWidth(joined, width);
380
+ private changed(): void {
381
+ if (this.disposed) return;
382
+ this.updateSpinner();
383
+ this.invalidate();
384
+ this.deps.tui.requestRender();
285
385
  }
286
386
 
287
- private serverSummaryParts(): string[] {
288
- const running = this.data.servers.filter((server) => server.status === "running").length;
289
- return running > 0
290
- ? [this.theme.fg("text", `${running} server${running === 1 ? "" : "s"}`)]
291
- : [];
387
+ private updateSpinner(): void {
388
+ if (this.disposed || (!this.refreshing && this.details?.kind !== "loading")) {
389
+ this.stopSpinner();
390
+ return;
391
+ }
392
+ if (this.spinner) return;
393
+ this.spinner = setInterval(() => {
394
+ this.spinnerFrame++;
395
+ this.invalidate();
396
+ this.deps.tui.requestRender();
397
+ }, 80);
292
398
  }
293
399
 
294
- private diagnosticSummaryParts(): string[] {
295
- const errors = this.data.diagnostics.reduce((sum, entry) => sum + entry.errors, 0);
296
- const warnings = this.data.diagnostics.reduce((sum, entry) => sum + entry.warnings, 0);
297
- return [
298
- errors > 0 ? this.theme.fg("error", `${errors} error${errors === 1 ? "" : "s"}`) : null,
299
- warnings > 0
300
- ? this.theme.fg("warning", `${warnings} warning${warnings === 1 ? "" : "s"}`)
301
- : null,
302
- ].filter((part): part is string => part !== null);
400
+ private stopSpinner(): void {
401
+ if (this.spinner) clearInterval(this.spinner);
402
+ this.spinner = undefined;
303
403
  }
304
404
 
305
- private routeSummaryParts(): string[] {
405
+ private summaryLine(): string {
406
+ const t = this.deps.theme;
407
+ if (this.refreshError) return t.fg("error", this.refreshFailure());
408
+ const ready = this.data.servers.filter(
409
+ (server) => server.status === "running" && server.ready,
410
+ ).length;
411
+ const starting = this.data.servers.filter(
412
+ (server) => server.status === "running" && !server.ready,
413
+ ).length;
306
414
  const counts = countProjectServerRouteStatuses(this.data.servers);
415
+ const entries = this.data.diagnostics.entries;
416
+ const errors = entries.reduce((sum, entry) => sum + entry.errors, 0);
417
+ const warnings = entries.reduce((sum, entry) => sum + entry.warnings, 0);
307
418
  return [
308
- counts.recovering > 0
309
- ? this.theme.fg(
419
+ `${ready} ready${starting ? ` · ${starting} starting` : ""}`,
420
+ errors ? t.fg("error", countLabel(errors, "error")) : "",
421
+ warnings ? t.fg("warning", countLabel(warnings, "warning")) : "",
422
+ counts.recovering
423
+ ? t.fg(
310
424
  "warning",
311
425
  `${counts.recovering} route${counts.recovering === 1 ? "" : "s"} recovering`,
312
426
  )
313
- : null,
314
- counts.error > 0
315
- ? this.theme.fg("error", `${counts.error} route error${counts.error === 1 ? "" : "s"}`)
316
- : null,
317
- counts.unavailable > 0
318
- ? this.theme.fg(
319
- "warning",
320
- `${counts.unavailable} route${counts.unavailable === 1 ? "" : "s"} unavailable`,
321
- )
322
- : null,
323
- ].filter((part): part is string => part !== null);
324
- }
325
-
326
- private structuralSummaryPart(): string {
327
- const kind = this.data.capabilities.structural.kind;
328
- if (kind === "ready") return this.theme.fg("success", "✓ ts ready");
329
- if (kind === "pending") return this.theme.fg("dim", "ts pending…");
330
- return this.theme.fg("error", "ts unavailable");
427
+ : "",
428
+ counts.error ? t.fg("error", countLabel(counts.error, "route error")) : "",
429
+ counts.unavailable ? t.fg("warning", `${counts.unavailable} routes unavailable`) : "",
430
+ this.data.diagnostics.kind === "partial" ? t.fg("warning", "partial snapshot") : "",
431
+ this.refreshing
432
+ ? t.fg("accent", `${this.frame()} ${ACTION_LABELS[this.refreshAction].progress}…`)
433
+ : "",
434
+ ]
435
+ .filter(Boolean)
436
+ .join(t.fg("dim", " · "));
331
437
  }
332
438
 
333
- private addServerSection(container: Container): void {
334
- const t = this.theme;
335
- container.addChild(new Text(t.fg("accent", t.bold(" Servers")), 1, 0));
336
- if (this.data.servers.length === 0) {
337
- this.addEmptyServerRow(container);
338
- return;
439
+ private renderBody(width: number): string[] {
440
+ const t = this.deps.theme;
441
+ const body = new Container();
442
+ const text = (value: string) => body.addChild(new Text(value, 0, 0));
443
+ const heading = (value: string) => text(t.fg("accent", t.bold(value)));
444
+ heading("Capabilities");
445
+ this.addCapabilities(text);
446
+ body.addChild(new Spacer(1));
447
+ if (this.healthRefresh) {
448
+ heading("Health action outcome");
449
+ for (const line of this.healthRefresh) text(` ${line}`);
450
+ body.addChild(new Spacer(1));
339
451
  }
340
- for (const server of this.data.servers) {
341
- this.addServerRow(container, server);
452
+ heading("Diagnostic files · tracked-file snapshot (not a workspace-wide check)");
453
+ this.addProblems(body, width, text);
454
+ body.addChild(new Spacer(1));
455
+ heading("Servers");
456
+ this.addServers(text);
457
+ if (this.data.capabilityWarnings?.hasWarnings) {
458
+ body.addChild(new Spacer(1));
459
+ heading("Capability Warnings");
460
+ this.addWarnings(text);
342
461
  }
343
- }
344
-
345
- private addEmptyServerRow(container: Container): void {
346
- const t = this.theme;
347
- if (!this.data.serverInventoryAvailable) {
348
- container.addChild(new Text(t.fg("dim", " server inventory unavailable"), 1, 0));
349
- return;
350
- }
351
- if (this.data.capabilities.semantic.kind === "disabled") {
352
- container.addChild(new Text(t.fg("dim", " all language servers disabled"), 1, 0));
353
- return;
462
+ if (this.data.activeTools.length) {
463
+ body.addChild(new Spacer(1));
464
+ heading("Tools");
465
+ text(this.data.activeTools.join(", "));
354
466
  }
355
- container.addChild(
356
- new Text(t.fg("dim", " no active project servers; routes may start lazily"), 1, 0),
357
- );
467
+ return body.render(width);
358
468
  }
359
469
 
360
- private addServerRow(container: Container, server: ProjectServerInfo): void {
361
- const t = this.theme;
362
- const statusColor =
363
- server.status === "running" ? "success" : server.status === "error" ? "error" : "warning";
364
- const icon = server.status === "running" ? "✓" : server.status === "error" ? "✗" : "?";
365
-
366
- container.addChild(
367
- new Text(
368
- t.fg("accent", " ▸ ") +
369
- t.fg("text", server.name) +
370
- " " +
371
- t.fg(statusColor, icon) +
372
- " " +
373
- t.fg("dim", `root: ${formatProjectServerRoot(this.data.workspaceRoot, server.root)}`),
374
- 0,
375
- 0,
376
- ),
377
- );
378
-
379
- const fileTypes = server.fileTypes.map((f) => `.${f}`).join(" ");
380
- container.addChild(new Text(t.fg("dim", ` files: ${fileTypes || "(none)"}`), 0, 0));
381
-
382
- const statusReason = formatProjectServerStatusReason(server.statusReason);
383
- if (statusReason) {
384
- container.addChild(new Text(t.fg("warning", ` ${statusReason}`), 0, 0));
385
- }
386
- const operationSupport = formatProjectServerOperationSupport(server.operationSupport);
387
- if (operationSupport) {
388
- container.addChild(new Text(t.fg("dim", ` ${operationSupport}`), 0, 0));
470
+ private addCapabilities(text: (value: string) => void): void {
471
+ const t = this.deps.theme;
472
+ for (const [label, state] of Object.entries(this.data.capabilities)) {
473
+ const color =
474
+ state.kind === "ready" ? "success" : state.kind === "unavailable" ? "error" : "dim";
475
+ const reason = "reason" in state ? ` — ${state.reason}` : "";
476
+ text(
477
+ t.fg(
478
+ color,
479
+ ` ${label === "semantic" ? "Semantic" : "Structural"}: ${state.kind}${reason}`,
480
+ ),
481
+ );
389
482
  }
483
+ text(t.fg("dim", " Refactor: negotiated per route; see Servers"));
484
+ }
390
485
 
391
- if (server.openFiles.length > 0) {
392
- const shown = server.openFiles.slice(0, MAX_OPEN_FILES_SHOWN);
393
- const remaining = server.openFiles.length - shown.length;
394
- const suffix = remaining > 0 ? t.fg("dim", ` +${remaining}`) : "";
395
- container.addChild(new Text(t.fg("dim", ` open: ${shown.join(", ")}`) + suffix, 0, 0));
396
- } else {
397
- container.addChild(new Text(t.fg("dim", " open: (none)"), 0, 0));
486
+ private addProblems(body: Container, width: number, text: (value: string) => void): void {
487
+ this.selectedRow = body.render(width).length;
488
+ this.addDiagnosticEvidence(text);
489
+ const check = this.data.diagnosticCheck;
490
+ if (check) {
491
+ const range = check.files.length
492
+ ? `${check.startOffset + 1}–${check.startOffset + check.files.length}`
493
+ : "none";
494
+ text(
495
+ ` Check: files ${range} of ${check.total ?? "unknown"} eligible · ${check.remaining ?? "unknown"} remaining in pass`,
496
+ );
497
+ if (check.reason) text(this.deps.theme.fg("warning", ` ${check.reason}`));
398
498
  }
499
+ if (this.refreshError) text(this.deps.theme.fg("error", this.refreshFailure()));
500
+ this.expandedRows = Math.max(1, body.render(width).length - this.selectedRow);
501
+ for (const entry of this.files) this.addProblemRow(entry, body, width);
399
502
  }
400
503
 
401
- private addProblemsSection(container: Container, width: number): void {
402
- const t = this.theme;
403
- container.addChild(new Text(t.fg("accent", t.bold(" Problems")), 1, 0));
404
- if (this.data.diagnostics.length === 0) {
405
- this.addEmptyProblemsRow(container);
406
- return;
504
+ private addProblemRow(entry: DiagnosticFile, body: Container, width: number): void {
505
+ const text = (value: string) => body.addChild(new Text(value, 0, 0));
506
+ if (entry.file === this.selectedFile) this.selectedRow = body.render(width).length;
507
+ const indicator =
508
+ entry.file === this.expandedFile ? "▼" : entry.file === this.selectedFile ? "▶" : " ";
509
+ const label = relative(
510
+ this.data.workspaceRoot,
511
+ resolve(this.data.workspaceRoot, entry.file),
512
+ ).replaceAll("\\", "/");
513
+ const counts = problemCounts(entry);
514
+ const status =
515
+ entry.status === "confirmed" && !counts ? "no errors or warnings (confirmed)" : entry.status;
516
+ text(`${indicator} ${label} ${[counts, status, entry.reason].filter(Boolean).join(" · ")}`);
517
+ if (entry.file === this.selectedFile)
518
+ this.expandedRows = body.render(width).length - this.selectedRow;
519
+ if (entry.file === this.expandedFile) {
520
+ const start = body.render(width).length;
521
+ this.addDetails(text);
522
+ if (entry.file === this.selectedFile) this.expandedRows += body.render(width).length - start;
407
523
  }
408
- container.addChild(
409
- new Text(t.fg("dim", " ↑↓ navigate · enter to expand · single-expand"), 1, 0),
410
- );
411
-
412
- const visible = this.data.diagnostics.slice(0, MAX_FILES_IN_LIST);
413
- visible.forEach((entry, idx) => {
414
- this.addProblemRow(container, entry, idx, width);
415
- });
524
+ }
416
525
 
417
- const remaining = this.data.diagnostics.length - visible.length;
418
- if (remaining > 0) {
419
- container.addChild(
420
- new Text(t.fg("dim", ` ↳ +${remaining} more file${remaining === 1 ? "" : "s"}`), 1, 0),
526
+ private addServers(text: (value: string) => void): void {
527
+ const t = this.deps.theme;
528
+ if (!this.data.serverInventoryAvailable) {
529
+ text(t.fg("dim", " server inventory unavailable"));
530
+ } else if (!this.data.servers.length) {
531
+ text(
532
+ t.fg(
533
+ "dim",
534
+ this.data.capabilities.semantic.kind === "disabled"
535
+ ? " all language servers disabled"
536
+ : " no active project servers; routes may start lazily",
537
+ ),
421
538
  );
422
539
  }
540
+ for (const server of this.data.servers) this.addServer(server, text);
423
541
  }
424
542
 
425
- private addEmptyProblemsRow(container: Container): void {
426
- const t = this.theme;
427
- if (!this.data.semanticAvailable) {
428
- container.addChild(new Text(t.fg("dim", " (diagnostics unavailable)"), 1, 0));
429
- } else if (!this.data.diagnosticSnapshotCurrent) {
430
- container.addChild(new Text(t.fg("warning", " diagnostic snapshot is stale"), 1, 0));
431
- } else {
432
- container.addChild(new Text(t.fg("success", " ✓ no issues"), 1, 0));
543
+ private addWarnings(text: (value: string) => void): void {
544
+ for (const warning of this.data.capabilityWarnings?.warnings ?? []) {
545
+ const language = warning.language ? `${warning.language}: ` : "";
546
+ const detail = warning.detail ? ` — ${warning.detail}` : "";
547
+ text(this.deps.theme.fg("warning", `⚠ ${language}${warning.message}${detail}`));
433
548
  }
434
549
  }
435
550
 
436
- private addProblemRow(
437
- container: Container,
438
- entry: OutstandingDiagnosticSummaryEntry,
439
- idx: number,
440
- width: number,
441
- ): void {
442
- const t = this.theme;
443
- const isSelected = idx === this.selectedFileIdx;
444
- const isExpanded = idx === this.expandedFileIdx;
445
-
446
- const counts: string[] = [];
447
- if (entry.errors > 0) {
448
- counts.push(t.fg("error", `${entry.errors} error${entry.errors === 1 ? "" : "s"}`));
449
- }
450
- if (entry.warnings > 0) {
451
- counts.push(t.fg("warning", `${entry.warnings} warning${entry.warnings === 1 ? "" : "s"}`));
452
- }
453
- const countsText = counts.length > 0 ? ` ${counts.join(" ")}` : "";
454
- const indicator = isExpanded ? t.fg("accent", "▼") : isSelected ? t.fg("accent", "▶") : " ";
455
- const fileColor = isSelected ? "accent" : "muted";
456
- const line = `${indicator} ${t.fg(fileColor, entry.file)}${countsText}`;
457
- container.addChild(new Text(truncateToWidth(line, width), 0, 0));
458
-
459
- if (isExpanded) {
460
- this.addInlineDiagnostics(container, width);
461
- }
551
+ private addDiagnosticEvidence(text: (value: string) => void): void {
552
+ const presentation = presentDiagnosticEvidence(this.data.diagnostics);
553
+ const t = this.deps.theme;
554
+ if (presentation.counts) text(t.fg("dim", ` ${presentation.counts}`));
555
+ text(t.fg(presentation.tone, ` ${presentation.summary}`));
462
556
  }
463
557
 
464
- private addInlineDiagnostics(container: Container, width: number): void {
465
- const t = this.theme;
466
- if (this.loading) {
467
- const frame = BRAILLE_SPINNER_FRAMES[this.spinnerFrame] ?? BRAILLE_SPINNER_FRAMES[0];
468
- container.addChild(new Text(t.fg("accent", ` └ ${frame} loading…`), 0, 0));
558
+ private addDetails(text: (value: string) => void): void {
559
+ const t = this.deps.theme;
560
+ const details = this.details;
561
+ if (!details) return;
562
+ if (details.kind === "loading") {
563
+ text(t.fg("accent", ` ${this.frame()} loading…`));
469
564
  return;
470
565
  }
471
- if (this.expandedDiagnostics === null) {
472
- container.addChild(new Text(t.fg("dim", " └ no diagnostics available"), 0, 0));
566
+ if (details.kind === "error") {
567
+ text(t.fg("error", ` Details unavailable: ${details.message}`));
473
568
  return;
474
569
  }
475
- const messages = this.expandedDiagnostics;
476
- for (const diag of messages.slice(0, MAX_INLINE_MESSAGES)) {
477
- const lineNum = diag.range.start.line + 1;
478
- const colNum = diag.range.start.character + 1;
479
- const sevColor = diag.severity === 1 ? "error" : "warning";
480
- const messageText = truncateTextForInline(diagnosticMessageString(diag), width - 14);
481
- const msg = ` ${t.fg(sevColor, "└")} ${lineNum}:${colNum} ${t.fg("dim", messageText)}`;
482
- container.addChild(new Text(msg, 0, 0));
483
- }
484
- const remaining = messages.length - MAX_INLINE_MESSAGES;
485
- if (remaining > 0) {
486
- container.addChild(new Text(t.fg("dim", ` └ +${remaining} more`), 0, 0));
570
+ text(t.fg("dim", ` Details: ${details.evidenceLabel}`));
571
+ if (!details.diagnostics.length)
572
+ text(t.fg("dim", " No error or warning messages in this snapshot"));
573
+ for (const diagnostic of details.diagnostics.slice(0, MAX_INLINE_MESSAGES)) {
574
+ text(
575
+ t.fg(
576
+ diagnostic.severity === 1 ? "error" : "warning",
577
+ ` ${diagnostic.range.start.line + 1}:${diagnostic.range.start.character + 1} ${diagnosticMessageString(diagnostic)}`,
578
+ ),
579
+ );
487
580
  }
581
+ if (details.diagnostics.length > MAX_INLINE_MESSAGES)
582
+ text(t.fg("dim", ` +${details.diagnostics.length - MAX_INLINE_MESSAGES} more messages`));
488
583
  }
489
584
 
490
- private addCapabilitiesSection(container: Container): void {
491
- const t = this.theme;
492
- container.addChild(new Text(t.fg("accent", t.bold(" Capabilities")), 1, 0));
493
- this.addCapabilityRow(container, "Semantic ", this.data.capabilities.semantic);
494
- this.addCapabilityRow(container, "Structural ", this.data.capabilities.structural);
495
- const refLabel = this.data.capabilities.refactorAvailable ? "✓ available" : "✗ unavailable";
496
- const refColor = this.data.capabilities.refactorAvailable ? "success" : "error";
497
- container.addChild(
498
- new Text(` ${t.fg("text", "Refactor ")} ${t.fg(refColor, refLabel)}`, 0, 0),
585
+ private addServer(server: ProjectServerInfo, text: (value: string) => void): void {
586
+ const t = this.deps.theme;
587
+ const state =
588
+ server.status === "running" ? (server.ready ? "ready" : "starting") : server.status;
589
+ text(
590
+ t.fg(
591
+ state === "ready" ? "success" : state === "error" ? "error" : "warning",
592
+ ` ${server.name}: ${state} · root: ${formatProjectServerRoot(this.data.workspaceRoot, server.root)}`,
593
+ ),
594
+ );
595
+ text(
596
+ t.fg("dim", ` files: ${server.fileTypes.map((type) => `.${type}`).join(" ") || "(none)"}`),
499
597
  );
598
+ const compiler = formatProjectServerCompiler(server.typescript);
599
+ if (compiler) text(t.fg("dim", ` ${compiler}`));
600
+ if (server.failureMessage) text(t.fg("warning", ` ${server.failureMessage}`));
601
+ const reason = formatProjectServerStatusReason(server.statusReason);
602
+ if (reason) text(t.fg("warning", ` ${reason}`));
603
+ const shown = server.openFiles.slice(0, MAX_OPEN_FILES_SHOWN);
604
+ text(
605
+ t.fg(
606
+ "dim",
607
+ ` open: ${shown.join(", ") || "(none)"}${server.openFiles.length > shown.length ? ` +${server.openFiles.length - shown.length} more` : ""}`,
608
+ ),
609
+ );
610
+ this.addOperationSupport(server, text);
500
611
  }
501
612
 
502
- private addCapabilityRow(
503
- container: Container,
504
- label: string,
505
- cap: { kind: string; reason?: string },
506
- ): void {
507
- const t = this.theme;
508
- const capLabel =
509
- cap.kind === "ready" ? "✓ ready" : cap.kind === "pending" ? "⏳ pending" : "✗ unavailable";
510
- const capColor = cap.kind === "ready" ? "success" : cap.kind === "pending" ? "dim" : "error";
511
- const reason = cap.reason ? t.fg("dim", ` — ${cap.reason}`) : "";
512
- container.addChild(
513
- new Text(` ${t.fg("text", label)} ${t.fg(capColor, capLabel)}${reason}`, 0, 0),
514
- );
613
+ private addOperationSupport(server: ProjectServerInfo, text: (value: string) => void): void {
614
+ const t = this.deps.theme;
615
+ if (!server.operationSupport || !Object.keys(server.operationSupport).length)
616
+ text(t.fg("dim", " Refactor support: not negotiated"));
617
+ for (const [operation, support] of Object.entries(server.operationSupport ?? {})) {
618
+ text(
619
+ t.fg(
620
+ "dim",
621
+ ` ${operation}: server ${support.server}; SuPi ${support.supi}${support.reason ? ` — ${support.reason}` : ""}`,
622
+ ),
623
+ );
624
+ }
515
625
  }
516
626
 
517
- private addCapabilityWarningsSection(container: Container): void {
518
- const warnings = this.data.capabilityWarnings;
519
- if (!warnings?.hasWarnings) return;
627
+ private hasConfiguredAction(input: string): boolean {
628
+ return STATUS_ACTIONS.some((action) => this.keybindings.matches(input, action));
629
+ }
520
630
 
521
- const t = this.theme;
522
- container.addChild(new Spacer(1));
523
- container.addChild(new Text(t.fg("error", t.bold(" Capability Warnings")), 1, 0));
631
+ private fileNavigationHint(): string {
632
+ const previous = this.hasConfiguredAction("\x1b[Z") ? "" : "/⇧tab";
633
+ return `${this.keyLabel("tui.input.tab")}${previous} files`;
634
+ }
524
635
 
525
- for (const w of warnings.warnings) {
526
- const lang = w.language ? `${t.fg("accent", w.language)} ` : "";
527
- const detail = w.detail ? t.fg("dim", ` — ${w.detail}`) : "";
528
- container.addChild(
529
- new Text(` ${t.fg("warning", "⚠")} ${lang}${t.fg("dim", w.message)}${detail}`, 0, 0),
530
- );
531
- }
532
- container.addChild(new Spacer(1));
636
+ private checkShortcut() {
637
+ return (
638
+ [
639
+ { input: "c", label: "c" },
640
+ { input: "\x1b[15~", label: "F5" },
641
+ ] as const
642
+ ).find(({ input }) => !this.hasConfiguredAction(input));
643
+ }
644
+
645
+ private healthShortcut() {
646
+ return (
647
+ [
648
+ { input: "h", label: "h" },
649
+ { input: "\x1b[17~", label: "F6" },
650
+ ] as const
651
+ ).find(({ input }) => !this.hasConfiguredAction(input));
533
652
  }
534
653
 
535
- private addToolsSection(container: Container, width: number): void {
536
- const t = this.theme;
537
- if (this.data.activeTools.length === 0) return;
538
- container.addChild(new Spacer(1));
539
- container.addChild(new Text(t.fg("accent", t.bold(" Tools")), 1, 0));
540
- const label = ` ${this.data.activeTools.map((tool) => t.fg("text", tool)).join(t.fg("dim", ", "))}`;
541
- const truncated = truncateTextForInline(label, width - 4);
542
- container.addChild(new Text(truncated, 0, 0));
543
- container.addChild(new Spacer(1));
654
+ private refreshFailure(): string {
655
+ return `${ACTION_LABELS[this.refreshAction].name} failed: ${this.refreshError}`;
544
656
  }
545
657
 
546
- private readonly theme: CiDialogTheme;
547
- private readonly done: () => void;
548
- private readonly tui: { requestRender: () => void };
549
- private readonly fetchDetailedDiagnostics?: DiagFetcher;
550
- private readonly onRefresh?: () => Promise<CiStatusData>;
658
+ private controlHints(): string {
659
+ const checkKey = this.checkShortcut();
660
+ return [
661
+ `${this.keyLabel("tui.select.cancel")} close`,
662
+ this.deps.onCheck ? `${checkKey?.label ?? "unbound"} check` : "",
663
+ this.deps.onHealth ? `${this.healthShortcut()?.label ?? "unbound"} Refresh health` : "",
664
+ `${this.keyLabel("tui.select.confirm")} expand`,
665
+ this.deps.onRefresh && !this.hasConfiguredAction("r") ? "r reload" : "",
666
+ !this.hasConfiguredAction("a") ? "a collapse" : "",
667
+ ]
668
+ .filter(Boolean)
669
+ .join(" · ");
670
+ }
671
+
672
+ private keyLabel(action: Parameters<KeybindingsManager["getKeys"]>[0]): string {
673
+ const key = this.keybindings.getKeys(action)[0];
674
+ const labels: Record<string, string> = {
675
+ escape: "esc",
676
+ up: "↑",
677
+ down: "↓",
678
+ pageUp: "PgUp",
679
+ pageDown: "PgDn",
680
+ };
681
+ return key ? (labels[key] ?? key) : "unbound";
682
+ }
683
+
684
+ private frame(): string {
685
+ return BRAILLE_SPINNER_FRAMES[this.spinnerFrame % BRAILLE_SPINNER_FRAMES.length] ?? "…";
686
+ }
687
+ }
688
+
689
+ /** Join per-file evidence with problem counts; an absent problem row does not prove clean. */
690
+ function diagnosticFiles(data: CiStatusData): DiagnosticFile[] {
691
+ const rows = new Map<string, DiagnosticFile>();
692
+ const add = (entry: DiagnosticCheckFile, counts?: HealthDiagnosticEntry) => {
693
+ const file = resolve(data.workspaceRoot, entry.file);
694
+ const existing = rows.get(file);
695
+ rows.set(file, { errors: 0, warnings: 0, ...existing, ...counts, ...entry, file });
696
+ };
697
+ for (const entry of data.diagnostics.entries)
698
+ add({ file: entry.file, status: "unconfirmed" }, entry);
699
+ if (data.diagnostics.kind !== "not-requested") {
700
+ for (const document of data.diagnostics.evidence.documents) add(document);
701
+ }
702
+ for (const entry of data.diagnosticCheck?.files ?? []) add(entry);
703
+ return [...rows.values()];
704
+ }
705
+
706
+ function problemCounts(entry: HealthDiagnosticEntry): string {
707
+ return [
708
+ entry.errors ? countLabel(entry.errors, "error") : "",
709
+ entry.warnings ? countLabel(entry.warnings, "warning") : "",
710
+ ]
711
+ .filter(Boolean)
712
+ .join(" · ");
713
+ }
714
+
715
+ function countLabel(count: number, label: string): string {
716
+ return `${count} ${label}${count === 1 ? "" : "s"}`;
551
717
  }
552
718
 
553
- function truncateTextForInline(text: string, maxWidth: number): string {
554
- if (visibleWidth(text) <= maxWidth) return text;
555
- return truncateToWidth(text, Math.max(8, maxWidth), "…");
719
+ function errorText(error: unknown): string {
720
+ return error instanceof Error ? error.message : String(error);
556
721
  }
557
722
 
558
- /**
559
- * Factory for use with `ctx.ui.custom()`.
560
- */
723
+ /** Construct a fresh, disposable inspector for ctx.ui.custom(). */
561
724
  export function createCiStatusDialog(data: CiStatusData, deps: CiStatusDialogDeps): CiStatusDialog {
562
725
  return new CiStatusDialog(data, deps);
563
726
  }