@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
@@ -1,563 +1,707 @@
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
+ import type { Diagnostic, ProjectServerInfo } from "@mrclrchtr/supi-lsp/api";
15
16
  import type {
16
- Diagnostic,
17
- OutstandingDiagnosticSummaryEntry,
18
- ProjectServerInfo,
19
- } from "@mrclrchtr/supi-lsp/api";
20
- import type { CapabilityWarningReport } from "../analysis/capability/capability-warnings.ts";
17
+ DiagnosticCheckFile,
18
+ WorkspaceDiagnosticCheckReport,
19
+ } from "../analysis/health/check.ts";
21
20
  import {
22
21
  countProjectServerRouteStatuses,
23
- formatProjectServerOperationSupport,
22
+ formatProjectServerCompiler,
24
23
  formatProjectServerRoot,
25
24
  formatProjectServerStatusReason,
26
25
  } from "../analysis/health/server-status.ts";
26
+ import type { WorkspaceStatusSnapshot } from "../analysis/health/status.ts";
27
+ import type { HealthDiagnosticEntry } from "../session/health-types.ts";
27
28
  import { diagnosticMessageString } from "../substrate/lsp/utils.ts";
28
29
 
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;
30
+ /** Passive health facts plus the session's active tool surface. */
31
+ export interface CiStatusData extends WorkspaceStatusSnapshot {
32
+ readonly activeTools: readonly string[];
33
+ readonly diagnosticCheck?: WorkspaceDiagnosticCheckReport;
38
34
  }
39
35
 
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;
36
+ /** Full error/warning messages retain freshness independently from the summary. */
37
+ export interface CiDiagnosticDetails {
38
+ readonly current: boolean;
39
+ readonly entries: readonly {
40
+ readonly file: string;
41
+ readonly diagnostics: readonly Diagnostic[];
42
+ }[];
60
43
  }
61
44
 
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
-
45
+ /** Dependencies owned by one terminal interaction. Reload is passive, not LSP recovery. */
69
46
  export interface CiStatusDialogDeps {
70
- theme: CiDialogTheme;
47
+ theme: Pick<Theme, "fg" | "bold">;
71
48
  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>;
49
+ tui: { terminal: { rows: number }; requestRender: () => void };
50
+ keybindings?: KeybindingsManager;
51
+ fetchDetailedDiagnostics?: () => CiDiagnosticDetails | Promise<CiDiagnosticDetails>;
52
+ onRefresh?: (signal: AbortSignal) => Promise<CiStatusData>;
53
+ onCheck?: (signal: AbortSignal) => Promise<CiStatusData>;
77
54
  }
78
55
 
79
- const MAX_FILES_IN_LIST = 10;
56
+ type DiagnosticFile = DiagnosticCheckFile & HealthDiagnosticEntry;
57
+
58
+ type DetailState =
59
+ | { kind: "loading" }
60
+ | { kind: "ready"; diagnostics: readonly Diagnostic[]; current: boolean }
61
+ | { kind: "error"; message: string };
80
62
  const MAX_INLINE_MESSAGES = 5;
81
63
  const MAX_OPEN_FILES_SHOWN = 3;
82
- const SPINNER_INTERVAL_MS = 80;
83
-
64
+ const FRAME_ROWS = 6;
65
+ const STATUS_ACTIONS = [
66
+ "tui.select.cancel",
67
+ "tui.select.up",
68
+ "tui.select.down",
69
+ "tui.select.confirm",
70
+ "tui.select.pageUp",
71
+ "tui.select.pageDown",
72
+ "tui.input.tab",
73
+ ] as const;
74
+
75
+ /** A bounded inspector with file-keyed selection and interaction-local asynchronous work. */
84
76
  export class CiStatusDialog {
85
- private selectedFileIdx = 0;
86
- private expandedFileIdx: number | null = null;
87
- private expandedDiagnostics: Diagnostic[] | null = null;
77
+ private files: readonly DiagnosticFile[];
78
+ private selectedFile: string | undefined;
79
+ private expandedFile: string | undefined;
80
+ private details: DetailState | undefined;
81
+ private detailGeneration = 0;
82
+ private refreshGeneration = 0;
83
+ private refreshing = false;
84
+ private refreshError: string | undefined;
85
+ private refreshAction: "reload" | "check" = "reload";
86
+ private refreshController: AbortController | undefined;
87
+ private disposed = false;
88
+ private spinner: ReturnType<typeof setInterval> | undefined;
89
+ private spinnerFrame = 0;
88
90
  private cachedWidth: number | undefined;
91
+ private cachedHeight: number | undefined;
89
92
  private cachedLines: string[] | undefined;
90
- private spinnerInterval: ReturnType<typeof setInterval> | null = null;
91
- private spinnerFrame = 0;
92
- private loading = false;
93
+ private bodyLines: string[] = [];
94
+ private selectedRow = 0;
95
+ private expandedRows = 1;
96
+ private revealSelection = false;
97
+ private followingSelection = false;
98
+ // A late check may update data, but must not replace newer navigation intent.
99
+ private navigationGeneration = 0;
100
+ private readonly scroll = new ScrollView({ render: () => this.bodyLines, invalidate() {} });
101
+ private readonly keybindings: KeybindingsManager;
93
102
 
94
103
  constructor(
95
104
  private data: CiStatusData,
96
- deps: CiStatusDialogDeps,
105
+ private readonly deps: CiStatusDialogDeps,
97
106
  ) {
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;
107
+ this.files = diagnosticFiles(data);
108
+ this.selectedFile = this.files[0]?.file;
109
+ this.keybindings = deps.keybindings ?? getKeybindings();
103
110
  }
104
111
 
105
- /** Called by pi-tui when the overlay is removed. */
112
+ /** Invalidate in-flight work before releasing the spinner and terminal interaction. */
106
113
  dispose(): void {
114
+ this.disposed = true;
115
+ this.detailGeneration++;
116
+ this.refreshGeneration++;
117
+ this.refreshController?.abort();
107
118
  this.stopSpinner();
108
119
  }
109
120
 
110
121
  render(width: number): string[] {
111
- if (this.cachedLines && this.cachedWidth === width) {
122
+ const height = Math.max(1, Math.floor(this.deps.tui.terminal.rows * 0.85));
123
+ if (this.cachedLines && this.cachedWidth === width && this.cachedHeight === height)
112
124
  return this.cachedLines;
125
+ if (height <= FRAME_ROWS)
126
+ return [truncateToWidth(`CI · ${this.keyLabel("tui.select.cancel")} close`, width)];
127
+ const bodyHeight = height - FRAME_ROWS;
128
+ const resized =
129
+ this.cachedHeight !== undefined &&
130
+ (this.cachedHeight !== height || this.cachedWidth !== width);
131
+ this.bodyLines = this.renderBody(width);
132
+ this.scroll.updateLayout(this.bodyLines.length, bodyHeight, () =>
133
+ this.deps.tui.requestRender(),
134
+ );
135
+ if (this.revealSelection || (resized && this.followingSelection)) {
136
+ const end = this.selectedRow + Math.min(this.expandedRows, bodyHeight) - 1;
137
+ if (this.selectedRow < this.scroll.scrollTop) this.scroll.scrollTo(this.selectedRow);
138
+ else if (end >= this.scroll.scrollTop + bodyHeight)
139
+ this.scroll.scrollTo(end - bodyHeight + 1);
113
140
  }
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));
141
+ this.revealSelection = false;
142
+ const t = this.deps.theme;
143
+ const border = new DynamicBorder((s) => t.fg("accent", s)).render(width)[0] ?? "";
144
+ const position =
145
+ this.bodyLines.length > bodyHeight
146
+ ? ` · ${this.scroll.scrollTop + 1}–${Math.min(this.scroll.scrollTop + bodyHeight, this.bodyLines.length)}/${this.bodyLines.length}`
147
+ : "";
148
+ // Pi's overlay adapter only calls render(width), not the fullscreen layout engine.
149
+ // ScrollView owns offsets/clamping; apply its viewport explicitly for this adapter.
150
+ const lines = [
151
+ border,
152
+ t.fg("accent", t.bold("◆ Code Intelligence")) + t.fg("dim", " · /supi-ci-status"),
153
+ this.summaryLine(),
154
+ ...this.scroll.render(width).slice(this.scroll.scrollTop, this.scroll.scrollTop + bodyHeight),
155
+ t.fg("dim", this.controlHints()),
156
+ t.fg(
157
+ "dim",
158
+ `${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}`,
159
+ ),
160
+ border,
161
+ ].map((line) => truncateToWidth(line, width));
131
162
  this.cachedWidth = width;
163
+ this.cachedHeight = height;
132
164
  this.cachedLines = lines;
133
165
  return lines;
134
166
  }
135
167
 
136
168
  invalidate(): void {
137
- this.cachedWidth = undefined;
138
169
  this.cachedLines = undefined;
139
170
  }
140
171
 
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();
172
+ handleInput(input: string): boolean {
173
+ if (this.disposed) return false;
174
+ if (this.keybindings.matches(input, "tui.select.cancel")) {
175
+ this.dispose();
176
+ this.deps.done();
147
177
  return true;
148
178
  }
179
+ return (
180
+ this.handleScrollInput(input) ||
181
+ this.handleFileInput(input) ||
182
+ this.handleShortcutInput(input)
183
+ );
184
+ }
149
185
 
150
- if (data === "a") {
151
- this.expandedFileIdx = null;
152
- this.expandedDiagnostics = null;
153
- this.stopSpinner();
154
- this.invalidate();
155
- this.tui.requestRender();
186
+ private handleShortcutInput(input: string): boolean {
187
+ if (
188
+ this.deps.onCheck &&
189
+ (input === "c" || matchesKey(input, "f5")) &&
190
+ !this.hasConfiguredAction(input)
191
+ ) {
192
+ void this.reload(true);
156
193
  return true;
157
194
  }
158
-
159
- if (data === "r" && this.onRefresh) {
160
- void this.handleRefresh();
195
+ if (input === "r" && this.deps.onRefresh) {
196
+ void this.reload();
161
197
  return true;
162
198
  }
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();
199
+ if (input === "a") {
200
+ this.collapse();
201
+ this.changed();
171
202
  return true;
172
203
  }
204
+ if (input === "j" || input === "k") {
205
+ this.scroll.scrollBy(input === "k" ? -1 : 1);
206
+ } else if (matchesKey(input, Key.home)) this.scroll.scrollToStart();
207
+ else if (matchesKey(input, Key.end)) this.scroll.scrollToEnd();
208
+ else return false;
209
+ this.scrolled();
210
+ return true;
211
+ }
173
212
 
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
- }
213
+ private handleScrollInput(input: string): boolean {
214
+ const page = Math.max(1, this.scroll.viewportHeight - 1);
215
+ let lines: number;
216
+ if (this.keybindings.matches(input, "tui.select.up")) lines = -1;
217
+ else if (this.keybindings.matches(input, "tui.select.down")) lines = 1;
218
+ else if (this.keybindings.matches(input, "tui.select.pageUp")) lines = -page;
219
+ else if (this.keybindings.matches(input, "tui.select.pageDown")) lines = page;
220
+ else return false;
221
+ this.scroll.scrollBy(lines);
222
+ this.scrolled();
223
+ return true;
224
+ }
180
225
 
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
- }
226
+ /** Manual scrolling owns the viewport until diagnostic-file navigation resumes. */
227
+ private scrolled(): void {
228
+ this.navigationGeneration++;
229
+ this.followingSelection = false;
230
+ this.revealSelection = false;
231
+ this.changed();
232
+ }
198
233
 
234
+ private handleFileInput(input: string): boolean {
235
+ if (this.keybindings.matches(input, "tui.select.confirm")) return this.expandSelection();
236
+ if (this.keybindings.matches(input, "tui.input.tab")) return this.moveSelection(1);
237
+ if (matchesKey(input, Key.shift("tab"))) return this.moveSelection(-1);
238
+ if (matchesKey(input, Key.space)) return this.expandSelection();
199
239
  return false;
200
240
  }
201
241
 
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);
242
+ private expandSelection(): boolean {
243
+ if (!this.selectedFile) return true;
244
+ this.navigationGeneration++;
245
+ if (this.expandedFile === this.selectedFile) this.collapse();
246
+ else {
247
+ this.collapse();
248
+ this.expandedFile = this.selectedFile;
249
+ void this.loadDetails(this.selectedFile);
250
+ }
251
+ this.followingSelection = true;
252
+ this.revealSelection = true;
253
+ this.changed();
254
+ return true;
213
255
  }
214
256
 
215
- private stopSpinner(): void {
216
- if (this.spinnerInterval) {
217
- clearInterval(this.spinnerInterval);
218
- this.spinnerInterval = null;
219
- }
220
- this.loading = false;
257
+ private moveSelection(direction: number): boolean {
258
+ this.navigationGeneration++;
259
+ const files = this.files;
260
+ const index = files.findIndex((entry) => entry.file === this.selectedFile);
261
+ const next = files[Math.max(0, Math.min(files.length - 1, index + direction))];
262
+ if (next) this.selectedFile = next.file;
263
+ this.followingSelection = true;
264
+ this.revealSelection = true;
265
+ this.changed();
266
+ return true;
221
267
  }
222
268
 
223
- // ── Async data loading ─────────────────────────────────────────────
269
+ private collapse(): void {
270
+ this.detailGeneration++;
271
+ this.expandedFile = undefined;
272
+ this.details = undefined;
273
+ this.updateSpinner();
274
+ }
224
275
 
225
- private async handleRefresh(): Promise<void> {
226
- if (!this.onRefresh) return;
227
- this.startSpinner();
276
+ private async loadDetails(file: string): Promise<void> {
277
+ const fetch = this.deps.fetchDetailedDiagnostics;
278
+ if (!fetch) {
279
+ this.details = { kind: "error", message: "Diagnostic details are unavailable" };
280
+ return;
281
+ }
282
+ const generation = ++this.detailGeneration;
283
+ this.details = { kind: "loading" };
284
+ this.changed();
228
285
  try {
229
- this.data = await this.onRefresh();
230
- } finally {
231
- this.stopSpinner();
286
+ const result = await fetch();
287
+ if (this.disposed || generation !== this.detailGeneration) return;
288
+ const entry = result.entries.find(
289
+ (entry) =>
290
+ resolve(this.data.workspaceRoot, entry.file) === resolve(this.data.workspaceRoot, file),
291
+ );
292
+ this.details = {
293
+ kind: "ready",
294
+ diagnostics: entry?.diagnostics ?? [],
295
+ current: result.current,
296
+ };
297
+ } catch (error) {
298
+ if (this.disposed || generation !== this.detailGeneration) return;
299
+ this.details = { kind: "error", message: errorText(error) };
232
300
  }
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();
301
+ if (!this.disposed && generation === this.detailGeneration) this.changed();
241
302
  }
242
303
 
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();
304
+ private async reload(check = false): Promise<void> {
305
+ const collect = check ? this.deps.onCheck : this.deps.onRefresh;
306
+ if (this.refreshing || !collect) return;
307
+ const generation = ++this.refreshGeneration;
308
+ const navigation = this.navigationGeneration;
309
+ this.refreshController = new AbortController();
310
+ this.refreshAction = check ? "check" : "reload";
311
+ this.refreshing = true;
312
+ this.refreshError = undefined;
313
+ this.collapse();
314
+ this.changed();
248
315
  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();
316
+ const data = await collect(this.refreshController.signal);
317
+ if (this.disposed || generation !== this.refreshGeneration) return;
318
+ this.acceptSnapshot(data, check && navigation === this.navigationGeneration);
319
+ } catch (error) {
320
+ if (this.disposed || generation !== this.refreshGeneration) return;
321
+ this.refreshError = errorText(error);
322
+ }
323
+ if (!this.disposed && generation === this.refreshGeneration) {
324
+ this.refreshing = false;
325
+ this.refreshController = undefined;
326
+ this.changed();
256
327
  }
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
328
  }
268
329
 
269
- private renderKeyHints(): string {
270
- return this.theme.fg("dim", " r refresh · a collapse all · esc close");
330
+ private acceptSnapshot(data: CiStatusData, check: boolean): void {
331
+ this.data = data;
332
+ this.files = diagnosticFiles(data);
333
+ if (!this.files.some((entry) => entry.file === this.selectedFile))
334
+ this.selectedFile = this.files[0]?.file;
335
+ // Collection closed the previous expansion at start; any current one is newer user intent.
336
+ const expanded = this.expandedFile;
337
+ this.collapse();
338
+ if (expanded && this.files.some((entry) => entry.file === expanded)) {
339
+ this.expandedFile = expanded;
340
+ void this.loadDetails(expanded);
341
+ }
342
+ if (check) {
343
+ const firstChecked = data.diagnosticCheck?.files[0];
344
+ if (firstChecked) this.selectedFile = resolve(data.workspaceRoot, firstChecked.file);
345
+ this.followingSelection = true;
346
+ }
347
+ this.revealSelection = this.followingSelection;
271
348
  }
272
349
 
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);
350
+ private changed(): void {
351
+ if (this.disposed) return;
352
+ this.updateSpinner();
353
+ this.invalidate();
354
+ this.deps.tui.requestRender();
285
355
  }
286
356
 
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
- : [];
357
+ private updateSpinner(): void {
358
+ if (this.disposed || (!this.refreshing && this.details?.kind !== "loading")) {
359
+ this.stopSpinner();
360
+ return;
361
+ }
362
+ if (this.spinner) return;
363
+ this.spinner = setInterval(() => {
364
+ this.spinnerFrame++;
365
+ this.invalidate();
366
+ this.deps.tui.requestRender();
367
+ }, 80);
292
368
  }
293
369
 
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);
370
+ private stopSpinner(): void {
371
+ if (this.spinner) clearInterval(this.spinner);
372
+ this.spinner = undefined;
303
373
  }
304
374
 
305
- private routeSummaryParts(): string[] {
375
+ private summaryLine(): string {
376
+ const t = this.deps.theme;
377
+ if (this.refreshError) return t.fg("error", this.refreshFailure());
378
+ const ready = this.data.servers.filter(
379
+ (server) => server.status === "running" && server.ready,
380
+ ).length;
381
+ const starting = this.data.servers.filter(
382
+ (server) => server.status === "running" && !server.ready,
383
+ ).length;
306
384
  const counts = countProjectServerRouteStatuses(this.data.servers);
385
+ const entries = this.data.diagnostics.entries;
386
+ const errors = entries.reduce((sum, entry) => sum + entry.errors, 0);
387
+ const warnings = entries.reduce((sum, entry) => sum + entry.warnings, 0);
307
388
  return [
308
- counts.recovering > 0
309
- ? this.theme.fg(
389
+ `${ready} ready${starting ? ` · ${starting} starting` : ""}`,
390
+ errors ? t.fg("error", countLabel(errors, "error")) : "",
391
+ warnings ? t.fg("warning", countLabel(warnings, "warning")) : "",
392
+ counts.recovering
393
+ ? t.fg(
310
394
  "warning",
311
395
  `${counts.recovering} route${counts.recovering === 1 ? "" : "s"} recovering`,
312
396
  )
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`,
397
+ : "",
398
+ counts.error ? t.fg("error", countLabel(counts.error, "route error")) : "",
399
+ counts.unavailable ? t.fg("warning", `${counts.unavailable} routes unavailable`) : "",
400
+ this.data.diagnostics.kind === "partial" ? t.fg("warning", "partial snapshot") : "",
401
+ this.refreshing
402
+ ? t.fg(
403
+ "accent",
404
+ `${this.frame()} ${this.refreshAction === "check" ? "checking" : "reloading"}…`,
321
405
  )
322
- : null,
323
- ].filter((part): part is string => part !== null);
406
+ : "",
407
+ ]
408
+ .filter(Boolean)
409
+ .join(t.fg("dim", " · "));
324
410
  }
325
411
 
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");
412
+ private renderBody(width: number): string[] {
413
+ const t = this.deps.theme;
414
+ const body = new Container();
415
+ const text = (value: string) => body.addChild(new Text(value, 0, 0));
416
+ const heading = (value: string) => text(t.fg("accent", t.bold(value)));
417
+ heading("Capabilities");
418
+ this.addCapabilities(text);
419
+ body.addChild(new Spacer(1));
420
+ heading("Diagnostic files · tracked-file snapshot (not a workspace-wide check)");
421
+ this.addProblems(body, width, text);
422
+ body.addChild(new Spacer(1));
423
+ heading("Servers");
424
+ this.addServers(text);
425
+ if (this.data.capabilityWarnings?.hasWarnings) {
426
+ body.addChild(new Spacer(1));
427
+ heading("Capability Warnings");
428
+ this.addWarnings(text);
429
+ }
430
+ if (this.data.activeTools.length) {
431
+ body.addChild(new Spacer(1));
432
+ heading("Tools");
433
+ text(this.data.activeTools.join(", "));
434
+ }
435
+ return body.render(width);
331
436
  }
332
437
 
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;
438
+ private addCapabilities(text: (value: string) => void): void {
439
+ const t = this.deps.theme;
440
+ for (const [label, state] of Object.entries(this.data.capabilities)) {
441
+ const color =
442
+ state.kind === "ready" ? "success" : state.kind === "unavailable" ? "error" : "dim";
443
+ const reason = "reason" in state ? ` — ${state.reason}` : "";
444
+ text(
445
+ t.fg(
446
+ color,
447
+ ` ${label === "semantic" ? "Semantic" : "Structural"}: ${state.kind}${reason}`,
448
+ ),
449
+ );
450
+ }
451
+ text(t.fg("dim", " Refactor: negotiated per route; see Servers"));
452
+ }
453
+
454
+ private addProblems(body: Container, width: number, text: (value: string) => void): void {
455
+ this.selectedRow = body.render(width).length;
456
+ this.addDiagnosticEvidence(text);
457
+ const check = this.data.diagnosticCheck;
458
+ if (check) {
459
+ const range = check.files.length
460
+ ? `${check.startOffset + 1}–${check.startOffset + check.files.length}`
461
+ : "none";
462
+ text(
463
+ ` Check: files ${range} of ${check.total ?? "unknown"} eligible · ${check.remaining ?? "unknown"} remaining in pass`,
464
+ );
465
+ if (check.reason) text(this.deps.theme.fg("warning", ` ${check.reason}`));
339
466
  }
340
- for (const server of this.data.servers) {
341
- this.addServerRow(container, server);
467
+ if (this.refreshError) text(this.deps.theme.fg("error", this.refreshFailure()));
468
+ this.expandedRows = Math.max(1, body.render(width).length - this.selectedRow);
469
+ for (const entry of this.files) this.addProblemRow(entry, body, width);
470
+ }
471
+
472
+ private addProblemRow(entry: DiagnosticFile, body: Container, width: number): void {
473
+ const text = (value: string) => body.addChild(new Text(value, 0, 0));
474
+ if (entry.file === this.selectedFile) this.selectedRow = body.render(width).length;
475
+ const indicator =
476
+ entry.file === this.expandedFile ? "▼" : entry.file === this.selectedFile ? "▶" : " ";
477
+ const label = relative(
478
+ this.data.workspaceRoot,
479
+ resolve(this.data.workspaceRoot, entry.file),
480
+ ).replaceAll("\\", "/");
481
+ const counts = problemCounts(entry);
482
+ const status =
483
+ entry.status === "confirmed" && this.data.diagnostics.kind === "completed"
484
+ ? counts
485
+ ? ""
486
+ : "no errors or warnings (confirmed)"
487
+ : entry.status;
488
+ text(`${indicator} ${label} ${[counts, status, entry.reason].filter(Boolean).join(" · ")}`);
489
+ if (entry.file === this.selectedFile)
490
+ this.expandedRows = body.render(width).length - this.selectedRow;
491
+ if (entry.file === this.expandedFile) {
492
+ const start = body.render(width).length;
493
+ this.addDetails(text);
494
+ if (entry.file === this.selectedFile) this.expandedRows += body.render(width).length - start;
342
495
  }
343
496
  }
344
497
 
345
- private addEmptyServerRow(container: Container): void {
346
- const t = this.theme;
498
+ private addServers(text: (value: string) => void): void {
499
+ const t = this.deps.theme;
347
500
  if (!this.data.serverInventoryAvailable) {
348
- container.addChild(new Text(t.fg("dim", " server inventory unavailable"), 1, 0));
349
- return;
501
+ text(t.fg("dim", " server inventory unavailable"));
502
+ } else if (!this.data.servers.length) {
503
+ text(
504
+ t.fg(
505
+ "dim",
506
+ this.data.capabilities.semantic.kind === "disabled"
507
+ ? " all language servers disabled"
508
+ : " no active project servers; routes may start lazily",
509
+ ),
510
+ );
350
511
  }
351
- if (this.data.capabilities.semantic.kind === "disabled") {
352
- container.addChild(new Text(t.fg("dim", " all language servers disabled"), 1, 0));
353
- return;
512
+ for (const server of this.data.servers) this.addServer(server, text);
513
+ }
514
+
515
+ private addWarnings(text: (value: string) => void): void {
516
+ for (const warning of this.data.capabilityWarnings?.warnings ?? []) {
517
+ const language = warning.language ? `${warning.language}: ` : "";
518
+ const detail = warning.detail ? ` — ${warning.detail}` : "";
519
+ text(this.deps.theme.fg("warning", `⚠ ${language}${warning.message}${detail}`));
354
520
  }
355
- container.addChild(
356
- new Text(t.fg("dim", " no active project servers; routes may start lazily"), 1, 0),
357
- );
358
521
  }
359
522
 
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,
523
+ private addDiagnosticEvidence(text: (value: string) => void): void {
524
+ const observation = this.data.diagnostics;
525
+ const t = this.deps.theme;
526
+ if (observation.kind === "not-requested") return;
527
+ const evidence = observation.evidence;
528
+ text(
529
+ t.fg(
530
+ "dim",
531
+ ` ${evidence.confirmed}/${evidence.requested} confirmed tracked files · ${evidence.unconfirmed} unconfirmed · ${evidence.failed} failed · ${evidence.removed} removed`,
376
532
  ),
377
533
  );
534
+ if (observation.kind === "unavailable")
535
+ text(t.fg("warning", ` diagnostics unavailable — ${observation.reason}`));
536
+ else if (observation.kind === "partial")
537
+ text(t.fg("warning", ` diagnostic snapshot is stale or incomplete — ${observation.reason}`));
538
+ else if (evidence.confirmed === 0)
539
+ text(
540
+ t.fg(
541
+ "dim",
542
+ ` No confirmed tracked files; an empty result does not establish a clean workspace.${this.deps.onCheck ? ` Use ${this.checkShortcut()?.label ?? "the check action"} to check diagnostics.` : ""}`,
543
+ ),
544
+ );
545
+ else if (!observation.entries.length)
546
+ text(t.fg("success", ` ✓ no issues in ${evidence.confirmed} confirmed tracked files`));
547
+ }
378
548
 
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));
549
+ private addDetails(text: (value: string) => void): void {
550
+ const t = this.deps.theme;
551
+ const details = this.details;
552
+ if (!details) return;
553
+ if (details.kind === "loading") {
554
+ text(t.fg("accent", ` ${this.frame()} loading…`));
555
+ return;
385
556
  }
386
- const operationSupport = formatProjectServerOperationSupport(server.operationSupport);
387
- if (operationSupport) {
388
- container.addChild(new Text(t.fg("dim", ` ${operationSupport}`), 0, 0));
557
+ if (details.kind === "error") {
558
+ text(t.fg("error", ` Details unavailable: ${details.message}`));
559
+ return;
389
560
  }
390
-
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));
561
+ if (!details.current) text(t.fg("warning", " Diagnostic details are stale"));
562
+ if (!details.diagnostics.length)
563
+ text(t.fg("dim", " No error or warning messages in this snapshot"));
564
+ for (const diagnostic of details.diagnostics.slice(0, MAX_INLINE_MESSAGES)) {
565
+ text(
566
+ t.fg(
567
+ diagnostic.severity === 1 ? "error" : "warning",
568
+ ` ${diagnostic.range.start.line + 1}:${diagnostic.range.start.character + 1} ${diagnosticMessageString(diagnostic)}`,
569
+ ),
570
+ );
398
571
  }
572
+ if (details.diagnostics.length > MAX_INLINE_MESSAGES)
573
+ text(t.fg("dim", ` +${details.diagnostics.length - MAX_INLINE_MESSAGES} more messages`));
399
574
  }
400
575
 
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;
407
- }
408
- container.addChild(
409
- new Text(t.fg("dim", " ↑↓ navigate · enter to expand · single-expand"), 1, 0),
576
+ private addServer(server: ProjectServerInfo, text: (value: string) => void): void {
577
+ const t = this.deps.theme;
578
+ const state =
579
+ server.status === "running" ? (server.ready ? "ready" : "starting") : server.status;
580
+ text(
581
+ t.fg(
582
+ state === "ready" ? "success" : state === "error" ? "error" : "warning",
583
+ ` ${server.name}: ${state} · root: ${formatProjectServerRoot(this.data.workspaceRoot, server.root)}`,
584
+ ),
410
585
  );
586
+ text(
587
+ t.fg("dim", ` files: ${server.fileTypes.map((type) => `.${type}`).join(" ") || "(none)"}`),
588
+ );
589
+ const compiler = formatProjectServerCompiler(server.typescript);
590
+ if (compiler) text(t.fg("dim", ` ${compiler}`));
591
+ if (server.failureMessage) text(t.fg("warning", ` ${server.failureMessage}`));
592
+ const reason = formatProjectServerStatusReason(server.statusReason);
593
+ if (reason) text(t.fg("warning", ` ${reason}`));
594
+ const shown = server.openFiles.slice(0, MAX_OPEN_FILES_SHOWN);
595
+ text(
596
+ t.fg(
597
+ "dim",
598
+ ` open: ${shown.join(", ") || "(none)"}${server.openFiles.length > shown.length ? ` +${server.openFiles.length - shown.length} more` : ""}`,
599
+ ),
600
+ );
601
+ this.addOperationSupport(server, text);
602
+ }
411
603
 
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
- });
416
-
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),
604
+ private addOperationSupport(server: ProjectServerInfo, text: (value: string) => void): void {
605
+ const t = this.deps.theme;
606
+ if (!server.operationSupport || !Object.keys(server.operationSupport).length)
607
+ text(t.fg("dim", " Refactor support: not negotiated"));
608
+ for (const [operation, support] of Object.entries(server.operationSupport ?? {})) {
609
+ text(
610
+ t.fg(
611
+ "dim",
612
+ ` ${operation}: server ${support.server}; SuPi ${support.supi}${support.reason ? ` — ${support.reason}` : ""}`,
613
+ ),
421
614
  );
422
615
  }
423
616
  }
424
617
 
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));
433
- }
618
+ private hasConfiguredAction(input: string): boolean {
619
+ return STATUS_ACTIONS.some((action) => this.keybindings.matches(input, action));
434
620
  }
435
621
 
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
- }
622
+ private fileNavigationHint(): string {
623
+ const previous = this.hasConfiguredAction("\x1b[Z") ? "" : "/⇧tab";
624
+ return `${this.keyLabel("tui.input.tab")}${previous} files`;
462
625
  }
463
626
 
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));
469
- return;
470
- }
471
- if (this.expandedDiagnostics === null) {
472
- container.addChild(new Text(t.fg("dim", " └ no diagnostics available"), 0, 0));
473
- return;
474
- }
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));
487
- }
627
+ private checkShortcut() {
628
+ return (
629
+ [
630
+ { input: "c", label: "c" },
631
+ { input: "\x1b[15~", label: "F5" },
632
+ ] as const
633
+ ).find(({ input }) => !this.hasConfiguredAction(input));
488
634
  }
489
635
 
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),
499
- );
636
+ private refreshFailure(): string {
637
+ return `${this.refreshAction === "check" ? "Check" : "Reload"} failed: ${this.refreshError}`;
500
638
  }
501
639
 
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
- );
640
+ private controlHints(): string {
641
+ const checkKey = this.checkShortcut();
642
+ return [
643
+ `${this.keyLabel("tui.select.cancel")} close`,
644
+ this.deps.onCheck ? `${checkKey?.label ?? "unbound"} check` : "",
645
+ `${this.keyLabel("tui.select.confirm")} expand`,
646
+ this.deps.onRefresh && !this.hasConfiguredAction("r") ? "r reload" : "",
647
+ !this.hasConfiguredAction("a") ? "a collapse" : "",
648
+ ]
649
+ .filter(Boolean)
650
+ .join(" · ");
515
651
  }
516
652
 
517
- private addCapabilityWarningsSection(container: Container): void {
518
- const warnings = this.data.capabilityWarnings;
519
- if (!warnings?.hasWarnings) return;
520
-
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));
653
+ private keyLabel(action: Parameters<KeybindingsManager["getKeys"]>[0]): string {
654
+ const key = this.keybindings.getKeys(action)[0];
655
+ const labels: Record<string, string> = {
656
+ escape: "esc",
657
+ up: "↑",
658
+ down: "↓",
659
+ pageUp: "PgUp",
660
+ pageDown: "PgDn",
661
+ };
662
+ return key ? (labels[key] ?? key) : "unbound";
663
+ }
524
664
 
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));
665
+ private frame(): string {
666
+ return BRAILLE_SPINNER_FRAMES[this.spinnerFrame % BRAILLE_SPINNER_FRAMES.length] ?? "…";
533
667
  }
668
+ }
534
669
 
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));
670
+ /** Join per-file evidence with problem counts; an absent problem row does not prove clean. */
671
+ function diagnosticFiles(data: CiStatusData): DiagnosticFile[] {
672
+ const rows = new Map<string, DiagnosticFile>();
673
+ const add = (entry: DiagnosticCheckFile, counts?: HealthDiagnosticEntry) => {
674
+ const file = resolve(data.workspaceRoot, entry.file);
675
+ const existing = rows.get(file);
676
+ rows.set(file, { errors: 0, warnings: 0, ...existing, ...counts, ...entry, file });
677
+ };
678
+ for (const entry of data.diagnostics.entries)
679
+ add({ file: entry.file, status: "unconfirmed" }, entry);
680
+ if (data.diagnostics.kind !== "not-requested") {
681
+ for (const document of data.diagnostics.evidence.documents) add(document);
544
682
  }
683
+ for (const entry of data.diagnosticCheck?.files ?? []) add(entry);
684
+ return [...rows.values()];
685
+ }
686
+
687
+ function problemCounts(entry: HealthDiagnosticEntry): string {
688
+ return [
689
+ entry.errors ? countLabel(entry.errors, "error") : "",
690
+ entry.warnings ? countLabel(entry.warnings, "warning") : "",
691
+ ]
692
+ .filter(Boolean)
693
+ .join(" · ");
694
+ }
545
695
 
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>;
696
+ function countLabel(count: number, label: string): string {
697
+ return `${count} ${label}${count === 1 ? "" : "s"}`;
551
698
  }
552
699
 
553
- function truncateTextForInline(text: string, maxWidth: number): string {
554
- if (visibleWidth(text) <= maxWidth) return text;
555
- return truncateToWidth(text, Math.max(8, maxWidth), "…");
700
+ function errorText(error: unknown): string {
701
+ return error instanceof Error ? error.message : String(error);
556
702
  }
557
703
 
558
- /**
559
- * Factory for use with `ctx.ui.custom()`.
560
- */
704
+ /** Construct a fresh, disposable inspector for ctx.ui.custom(). */
561
705
  export function createCiStatusDialog(data: CiStatusData, deps: CiStatusDialogDeps): CiStatusDialog {
562
706
  return new CiStatusDialog(data, deps);
563
707
  }