@golba98/codexa 1.0.2 → 1.0.3

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 (150) hide show
  1. package/README.md +391 -94
  2. package/package.json +12 -7
  3. package/src/app.tsx +149 -117
  4. package/src/commands/handler.ts +4 -4
  5. package/src/config/buildInfo.ts +2 -2
  6. package/src/config/persistence.ts +10 -0
  7. package/src/config/settings.ts +7 -15
  8. package/src/config/updateCheckCache.ts +19 -1
  9. package/src/core/channel.ts +23 -0
  10. package/src/core/executables/codexExecutable.ts +1 -0
  11. package/src/core/executables/executableResolver.ts +61 -43
  12. package/src/core/launchContext.ts +33 -33
  13. package/src/core/process/processValidation.ts +9 -5
  14. package/src/core/providerLauncher/launcher.ts +59 -42
  15. package/src/core/updateCheck.ts +111 -95
  16. package/src/session/types.ts +2 -1
  17. package/src/ui/ActionRequiredBlock.tsx +5 -5
  18. package/src/ui/ActivityBars.tsx +3 -3
  19. package/src/ui/ActivityIndicator.tsx +6 -6
  20. package/src/ui/AgentBlock.tsx +6 -6
  21. package/src/ui/AnimatedStatusText.tsx +1 -1
  22. package/src/ui/AppShell.tsx +9 -24
  23. package/src/ui/AttachmentImportPanel.tsx +8 -8
  24. package/src/ui/AuthPanel.tsx +20 -20
  25. package/src/ui/BottomComposer.tsx +117 -78
  26. package/src/ui/DashCard.tsx +3 -3
  27. package/src/ui/Markdown.tsx +17 -17
  28. package/src/ui/ModelPickerScreen.tsx +10 -10
  29. package/src/ui/ModelReasoningPicker.tsx +14 -14
  30. package/src/ui/Panel.tsx +3 -3
  31. package/src/ui/PlanActionPicker.tsx +6 -6
  32. package/src/ui/PlanReviewPanel.tsx +8 -8
  33. package/src/ui/ProviderPicker.tsx +18 -18
  34. package/src/ui/RunFooter.tsx +3 -3
  35. package/src/ui/SelectionPanel.tsx +4 -4
  36. package/src/ui/SettingsPanel.tsx +8 -8
  37. package/src/ui/Spinner.tsx +1 -1
  38. package/src/ui/TextEntryPanel.tsx +10 -10
  39. package/src/ui/ThinkingBlock.tsx +8 -8
  40. package/src/ui/Timeline.tsx +21 -17
  41. package/src/ui/TopHeader.tsx +421 -293
  42. package/src/ui/TurnGroup.tsx +31 -31
  43. package/src/ui/UpdateAvailableCard.tsx +41 -0
  44. package/src/ui/UpdatePromptPanel.tsx +203 -0
  45. package/src/ui/focus.ts +3 -0
  46. package/src/ui/layout.ts +1 -1
  47. package/src/ui/logoVariants.ts +107 -0
  48. package/src/ui/modeDisplay.ts +12 -12
  49. package/src/ui/runtimeDisplay.ts +100 -0
  50. package/src/ui/theme.tsx +274 -395
  51. package/src/ui/timelineMeasure.ts +29 -19
  52. package/scripts/audit-codexa-capabilities.mjs +0 -466
  53. package/scripts/gen-build-info.mjs +0 -33
  54. package/scripts/smoke-terminal-bench.mjs +0 -35
  55. package/src/appRenderStability.test.ts +0 -131
  56. package/src/commands/handler.test.ts +0 -655
  57. package/src/config/launchArgs.test.ts +0 -189
  58. package/src/config/layeredConfig.test.ts +0 -143
  59. package/src/config/persistence.test.ts +0 -114
  60. package/src/config/runtimeConfig.test.ts +0 -218
  61. package/src/config/settings.test.ts +0 -155
  62. package/src/config/trustStore.test.ts +0 -29
  63. package/src/core/attachments.test.ts +0 -155
  64. package/src/core/auth/codexAuth.test.ts +0 -68
  65. package/src/core/cleanupFastFail.test.ts +0 -76
  66. package/src/core/codexExecArgs.test.ts +0 -195
  67. package/src/core/codexLaunch.test.ts +0 -205
  68. package/src/core/codexPrompt.test.ts +0 -252
  69. package/src/core/executables/codexExecutable.test.ts +0 -212
  70. package/src/core/executables/executableResolver.test.ts +0 -129
  71. package/src/core/executables/geminiExecutable.test.ts +0 -116
  72. package/src/core/executables/pathSanityScan.test.ts +0 -47
  73. package/src/core/githubDiagnostics.test.ts +0 -92
  74. package/src/core/hollowResponseFormat.test.ts +0 -58
  75. package/src/core/launchContext.test.ts +0 -157
  76. package/src/core/models/codexCapabilities.test.ts +0 -45
  77. package/src/core/models/codexModelCapabilities.test.ts +0 -246
  78. package/src/core/models/modelSpecs.test.ts +0 -283
  79. package/src/core/perf/renderDebug.test.ts +0 -230
  80. package/src/core/planStorage.test.ts +0 -143
  81. package/src/core/process/CommandRunner.test.ts +0 -105
  82. package/src/core/projectInstructions.test.ts +0 -50
  83. package/src/core/providerLauncher/launcher.test.ts +0 -238
  84. package/src/core/providerLauncher/registry.test.ts +0 -324
  85. package/src/core/providerLauncher/workspaceConfig.test.ts +0 -638
  86. package/src/core/providerRuntime/anthropic.test.ts +0 -1120
  87. package/src/core/providerRuntime/capabilityProfile.test.ts +0 -311
  88. package/src/core/providerRuntime/contextMetadata.test.ts +0 -468
  89. package/src/core/providerRuntime/gemini.test.ts +0 -437
  90. package/src/core/providerRuntime/lmstudio.test.ts +0 -168
  91. package/src/core/providerRuntime/local.test.ts +0 -787
  92. package/src/core/providerRuntime/registry.test.ts +0 -233
  93. package/src/core/providers/codexJsonStream.test.ts +0 -148
  94. package/src/core/providers/codexSubprocess.test.ts +0 -68
  95. package/src/core/providers/codexTranscript.test.ts +0 -284
  96. package/src/core/terminal/startupClear.test.ts +0 -55
  97. package/src/core/terminal/terminalCapabilities.test.ts +0 -93
  98. package/src/core/terminal/terminalControl.test.ts +0 -75
  99. package/src/core/terminal/terminalSanitize.test.ts +0 -22
  100. package/src/core/terminal/terminalSelection.test.ts +0 -42
  101. package/src/core/terminal/terminalTitle.test.ts +0 -328
  102. package/src/core/updateCheck.test.ts +0 -194
  103. package/src/core/workspaceActivity.test.ts +0 -163
  104. package/src/core/workspaceGuard.test.ts +0 -151
  105. package/src/core/workspaceRoot.test.ts +0 -23
  106. package/src/exec.test.ts +0 -13
  107. package/src/headless/execArgs.test.ts +0 -147
  108. package/src/headless/execRunner.test.ts +0 -436
  109. package/src/index.test.tsx +0 -620
  110. package/src/session/appSession.test.ts +0 -897
  111. package/src/session/chatLifecycle.test.ts +0 -64
  112. package/src/session/liveRenderScheduler.test.ts +0 -201
  113. package/src/session/planFlow.test.ts +0 -103
  114. package/src/session/planTranscript.test.ts +0 -65
  115. package/src/session/promptRunSchedule.test.ts +0 -36
  116. package/src/ui/ActivityIndicator.test.tsx +0 -58
  117. package/src/ui/AgentBlock.test.ts +0 -6
  118. package/src/ui/AnimatedStatusText.test.ts +0 -16
  119. package/src/ui/AppShell.test.tsx +0 -1776
  120. package/src/ui/AttachmentImportPanel.test.tsx +0 -204
  121. package/src/ui/BottomComposer.test.ts +0 -674
  122. package/src/ui/CodexLogo.tsx +0 -55
  123. package/src/ui/Markdown.test.ts +0 -157
  124. package/src/ui/ModelPickerProviderScope.test.tsx +0 -411
  125. package/src/ui/ModelPickerScreen.test.tsx +0 -99
  126. package/src/ui/ModelPickerState.test.tsx +0 -151
  127. package/src/ui/ModelReasoningPicker.test.tsx +0 -447
  128. package/src/ui/PlanReviewPanel.test.tsx +0 -267
  129. package/src/ui/PromptCardBorder.test.tsx +0 -161
  130. package/src/ui/ProviderPicker.test.tsx +0 -289
  131. package/src/ui/ProviderShortcut.test.tsx +0 -143
  132. package/src/ui/SettingsPanel.test.tsx +0 -233
  133. package/src/ui/Timeline.test.ts +0 -2067
  134. package/src/ui/TimelineNavigation.test.tsx +0 -201
  135. package/src/ui/TopHeader.test.tsx +0 -254
  136. package/src/ui/TurnGroup.test.tsx +0 -365
  137. package/src/ui/busyStatusAnimation.test.ts +0 -30
  138. package/src/ui/commandNormalize.test.ts +0 -142
  139. package/src/ui/diffRenderer.test.ts +0 -102
  140. package/src/ui/focusFlow.test.tsx +0 -1098
  141. package/src/ui/inputBuffer.test.ts +0 -151
  142. package/src/ui/layout.test.ts +0 -146
  143. package/src/ui/modeDisplay.test.ts +0 -42
  144. package/src/ui/runActivityView.test.ts +0 -89
  145. package/src/ui/runLifecycleView.test.tsx +0 -237
  146. package/src/ui/statusRenderIsolation.test.tsx +0 -654
  147. package/src/ui/terminalAnswerFormat.test.ts +0 -19
  148. package/src/ui/textLayout.test.ts +0 -18
  149. package/src/ui/themeFlow.test.ts +0 -53
  150. package/src/ui/timelineMeasureCache.test.ts +0 -986
@@ -1,267 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import React from "react";
4
- import { PassThrough } from "node:stream";
5
- import { Box, Text, render } from "ink";
6
- import { PlanActionPicker } from "./PlanActionPicker.js";
7
- import { normalizePlanReviewMarkdown } from "../core/planStorage.js";
8
- import {
9
- buildPlanReviewDisplayRows,
10
- buildPlanReviewRows,
11
- PlanReviewPanel,
12
- } from "./PlanReviewPanel.js";
13
- import { ThemeProvider } from "./theme.js";
14
-
15
- class TestInput extends PassThrough {
16
- readonly isTTY = true;
17
-
18
- setRawMode(): this {
19
- return this;
20
- }
21
-
22
- override resume(): this {
23
- return this;
24
- }
25
-
26
- override pause(): this {
27
- return this;
28
- }
29
-
30
- ref(): this {
31
- return this;
32
- }
33
-
34
- unref(): this {
35
- return this;
36
- }
37
- }
38
-
39
- class TestOutput extends PassThrough {
40
- readonly isTTY = true;
41
- columns = 80;
42
- rows = 24;
43
- }
44
-
45
- function stripAnsi(value: string): string {
46
- return value.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "");
47
- }
48
-
49
- function sleep(ms = 50): Promise<void> {
50
- return new Promise((resolve) => setTimeout(resolve, ms));
51
- }
52
-
53
- async function renderPlanPanel(planText: string, cols = 80): Promise<string> {
54
- const stdin = new TestInput();
55
- const stdout = new TestOutput();
56
- stdout.columns = cols;
57
- let output = "";
58
-
59
- stdout.on("data", (chunk) => {
60
- output += chunk.toString();
61
- });
62
-
63
- const instance = render(
64
- <ThemeProvider theme="purple">
65
- <PlanReviewPanel
66
- planText={planText}
67
- cols={cols}
68
- workspaceRoot="C:\\Development\\Project"
69
- />
70
- </ThemeProvider>,
71
- {
72
- stdin: stdin as unknown as NodeJS.ReadStream,
73
- stdout: stdout as unknown as NodeJS.WriteStream,
74
- stderr: stdout as unknown as NodeJS.WriteStream,
75
- debug: true,
76
- exitOnCtrlC: false,
77
- patchConsole: false,
78
- },
79
- );
80
-
81
- await sleep(80);
82
- instance.cleanup();
83
- await sleep(20);
84
- return stripAnsi(output);
85
- }
86
-
87
- function createInkHarness(node: React.ReactElement) {
88
- const stdin = new TestInput();
89
- const stdout = new TestOutput();
90
- let output = "";
91
-
92
- stdout.on("data", (chunk) => {
93
- output += chunk.toString();
94
- });
95
-
96
- const instance = render(node, {
97
- stdin: stdin as unknown as NodeJS.ReadStream,
98
- stdout: stdout as unknown as NodeJS.WriteStream,
99
- stderr: stdout as unknown as NodeJS.WriteStream,
100
- debug: true,
101
- exitOnCtrlC: false,
102
- patchConsole: false,
103
- });
104
-
105
- return {
106
- stdin,
107
- getOutput() {
108
- return stripAnsi(output);
109
- },
110
- async cleanup() {
111
- instance.cleanup();
112
- await sleep(20);
113
- },
114
- };
115
- }
116
-
117
- function makeLongPlan(itemCount = 40): string {
118
- return [
119
- "Files:",
120
- ...Array.from({ length: itemCount }, (_, index) =>
121
- `- src/file-${index + 1}.ts Description for item ${index + 1}.`,
122
- ),
123
- "",
124
- "Steps:",
125
- ...Array.from({ length: itemCount }, (_, index) =>
126
- `${index + 1}. Complete implementation step ${index + 1}.`,
127
- ),
128
- ].join("\n");
129
- }
130
-
131
- function PlanActionHarness() {
132
- const [selection, setSelection] = React.useState("none");
133
- const [cancelCount, setCancelCount] = React.useState(0);
134
-
135
- return (
136
- <ThemeProvider theme="purple">
137
- <Box flexDirection="column">
138
- <PlanActionPicker
139
- onSelect={(value) => setSelection(value)}
140
- onCancel={() => setCancelCount((count) => count + 1)}
141
- />
142
- <Text>{`selection:${selection}`}</Text>
143
- <Text>{`cancel:${cancelCount}`}</Text>
144
- </Box>
145
- </ThemeProvider>
146
- );
147
- }
148
-
149
- test("plan review markdown normalization converts bold section labels into headings", () => {
150
- const normalized = normalizePlanReviewMarkdown("**Files**\n- src/app.tsx\n\n**Steps**\n1. Wire the panel");
151
-
152
- assert.match(normalized, /## Files/);
153
- assert.match(normalized, /## Steps/);
154
- assert.doesNotMatch(normalized, /\*\*Files\*\*/);
155
- assert.doesNotMatch(normalized, /\*\*Steps\*\*/);
156
- });
157
-
158
- test("plan review rows hide workspace-root filesystem details", () => {
159
- const rows = buildPlanReviewRows(
160
- "**Files**\n- C:\\Development\\Project\\src\\app.tsx\n\nSteps:\n1. Keep the saved plan internal.",
161
- "C:\\Development\\Project",
162
- );
163
- const joined = JSON.stringify(rows);
164
-
165
- assert.match(joined, /src\/app\.tsx/);
166
- assert.doesNotMatch(joined, /C:\\\\Development/);
167
- assert.doesNotMatch(joined, /Path:/);
168
- });
169
-
170
- test("plan review display rows wrap long lines inside the panel width", () => {
171
- const longText = "This line should wrap cleanly inside the review panel instead of clipping horizontally past the right border where it would become unreadable.";
172
- const semanticRows = buildPlanReviewRows(`Files:\n- src/core/board.py ${longText}`);
173
- const displayRows = buildPlanReviewDisplayRows(semanticRows, 34);
174
- const joined = displayRows.map((row) => row.text).join("\n");
175
-
176
- assert.match(joined, /This line/);
177
- assert.match(joined, /should wrap cleanly/);
178
- assert.match(joined, /instead of clipping/);
179
- assert.ok(
180
- displayRows.every((row) => row.text.length <= 34),
181
- "wrapped rows should stay within the requested content width",
182
- );
183
- });
184
-
185
- test("plan review panel renders the full long plan instead of a clipped row range", async () => {
186
- const output = await renderPlanPanel(makeLongPlan(40), 100);
187
-
188
- assert.match(output, /Plan/);
189
- assert.match(output, /src\/file-1\.ts/);
190
- assert.match(output, /src\/file-20\.ts/);
191
- assert.match(output, /src\/file-40\.ts/);
192
- assert.match(output, /40\. Complete implementation step 40\./);
193
- assert.doesNotMatch(output, /Plan \d+[-–]\d+ of \d+/);
194
- assert.doesNotMatch(output, /PageUp\/PageDown scroll plan/);
195
- assert.doesNotMatch(output, /C:\\Development/);
196
- });
197
-
198
- test("plan action picker keeps simple menu navigation and enter selection", async () => {
199
- const harness = createInkHarness(<PlanActionHarness />);
200
-
201
- try {
202
- await sleep(80);
203
- harness.stdin.write("u");
204
- await sleep(80);
205
-
206
- const output = harness.getOutput();
207
- assert.match(output, /Plan ready/);
208
- assert.match(output, /\[I\] Implement changes/);
209
- assert.match(output, /\[U\] Update plan/);
210
- assert.doesNotMatch(output, /╭── Plan ready/);
211
- assert.doesNotMatch(output, /I\s\sImplement changes/);
212
- assert.doesNotMatch(output, /U\s\sUpdate plan/);
213
- assert.doesNotMatch(output, /Cancel/);
214
- assert.doesNotMatch(output, /Request changes/);
215
- assert.doesNotMatch(output, /Add constraints/);
216
- assert.doesNotMatch(output, /type a decision/);
217
- assert.match(output, /selection:revise/);
218
- } finally {
219
- await harness.cleanup();
220
- }
221
- });
222
-
223
- test("plan action picker supports focused hotkeys and escape cancellation", async () => {
224
- const harness = createInkHarness(<PlanActionHarness />);
225
-
226
- try {
227
- await sleep(80);
228
- harness.stdin.write("u");
229
- await sleep(80);
230
- harness.stdin.write("\u001b");
231
- await sleep(80);
232
-
233
- const output = harness.getOutput();
234
- assert.match(output, /selection:revise/);
235
- assert.match(output, /cancel:1/);
236
- } finally {
237
- await harness.cleanup();
238
- }
239
- });
240
-
241
- test("plan action picker implements with hotkey", async () => {
242
- const harness = createInkHarness(<PlanActionHarness />);
243
- try {
244
- await sleep(80);
245
- harness.stdin.write("i");
246
- await sleep(80);
247
- const output = harness.getOutput();
248
- assert.match(output, /selection:implement/);
249
- } finally {
250
- await harness.cleanup();
251
- }
252
- });
253
-
254
- test("plan action picker selects focused action with enter", async () => {
255
- const harness = createInkHarness(<PlanActionHarness />);
256
- try {
257
- await sleep(80);
258
- harness.stdin.write("\u001b[B");
259
- await sleep(80);
260
- harness.stdin.write("\r");
261
- await sleep(80);
262
- const output = harness.getOutput();
263
- assert.match(output, /selection:revise/);
264
- } finally {
265
- await harness.cleanup();
266
- }
267
- });
@@ -1,161 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import React from "react";
4
- import { PassThrough } from "node:stream";
5
- import { render } from "ink";
6
- import type { RunEvent, UserPromptEvent } from "../session/types.js";
7
- import { TEST_RUNTIME } from "../test/runtimeTestUtils.js";
8
- import { ThemeProvider } from "./theme.js";
9
- import { TurnGroup } from "./TurnGroup.js";
10
-
11
- class TestInput extends PassThrough {
12
- readonly isTTY = true;
13
-
14
- setRawMode(): this {
15
- return this;
16
- }
17
-
18
- override resume(): this {
19
- return this;
20
- }
21
-
22
- override pause(): this {
23
- return this;
24
- }
25
-
26
- ref(): this {
27
- return this;
28
- }
29
-
30
- unref(): this {
31
- return this;
32
- }
33
- }
34
-
35
- class TestOutput extends PassThrough {
36
- readonly isTTY = true;
37
- columns = 120;
38
- rows = 40;
39
- }
40
-
41
- function stripAnsi(value: string): string {
42
- return value.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "");
43
- }
44
-
45
- function sleep(ms = 50): Promise<void> {
46
- return new Promise((resolve) => setTimeout(resolve, ms));
47
- }
48
-
49
- function makeRunningRun(turnId: number): RunEvent {
50
- return {
51
- id: 2,
52
- type: "run",
53
- createdAt: 2,
54
- startedAt: 2,
55
- durationMs: null,
56
- backendId: "codex-subprocess",
57
- backendLabel: "Codexa",
58
- runtime: TEST_RUNTIME,
59
- prompt: "Do work",
60
- progressEntries: [],
61
- status: "running",
62
- summary: "Running",
63
- truncatedOutput: false,
64
- toolActivities: [],
65
- activity: [],
66
- touchedFileCount: 0,
67
- errorMessage: null,
68
- turnId,
69
- };
70
- }
71
-
72
- function makeUser(turnId: number): UserPromptEvent {
73
- return {
74
- id: 1,
75
- type: "user",
76
- createdAt: 1,
77
- prompt: "Do work",
78
- turnId,
79
- };
80
- }
81
-
82
- function renderTurnGroup(node: React.ReactElement) {
83
- const stdin = new TestInput();
84
- const stdout = new TestOutput();
85
- let output = "";
86
- stdout.on("data", (chunk) => {
87
- output += chunk.toString();
88
- });
89
- const instance = render(node, {
90
- stdin: stdin as unknown as NodeJS.ReadStream,
91
- stdout: stdout as unknown as NodeJS.WriteStream,
92
- stderr: stdout as unknown as NodeJS.WriteStream,
93
- debug: true,
94
- exitOnCtrlC: false,
95
- });
96
-
97
- return {
98
- instance,
99
- readOutput: () => stripAnsi(output),
100
- resetOutput: () => {
101
- output = "";
102
- },
103
- };
104
- }
105
-
106
- test("prompt card top border stays closed at the top-right corner across rerenders", async () => {
107
- const turnId = 14;
108
- const user = makeUser(turnId);
109
- const run = makeRunningRun(turnId);
110
-
111
- const harness = renderTurnGroup(
112
- <ThemeProvider theme="purple">
113
- <TurnGroup
114
- cols={80}
115
- turnIndex={1}
116
- user={user}
117
- run={run}
118
- assistant={null}
119
- opacity="active"
120
- question={null}
121
- runPhase="thinking"
122
- streamPreviewRows={8}
123
- streamMode="assistant-first"
124
- />
125
- </ThemeProvider>,
126
- );
127
-
128
- await sleep();
129
- let frame = harness.readOutput();
130
- let topBorder = frame.split("\n").find((line) => line.includes("╭── PROMPT"));
131
- assert.ok(topBorder, "expected prompt top border line");
132
- assert.match(topBorder!, /──╮$/);
133
- assert.doesNotMatch(topBorder!, / ──╮$/);
134
-
135
- harness.resetOutput();
136
- harness.instance.rerender(
137
- <ThemeProvider theme="purple">
138
- <TurnGroup
139
- cols={56}
140
- turnIndex={1}
141
- user={user}
142
- run={run}
143
- assistant={null}
144
- opacity="active"
145
- question={null}
146
- runPhase="thinking"
147
- streamPreviewRows={8}
148
- streamMode="assistant-first"
149
- />
150
- </ThemeProvider>,
151
- );
152
-
153
- await sleep();
154
- frame = harness.readOutput();
155
- topBorder = frame.split("\n").find((line) => line.includes("╭── PROMPT"));
156
- assert.ok(topBorder, "expected prompt top border line after resize rerender");
157
- assert.match(topBorder!, /──╮$/);
158
- assert.doesNotMatch(topBorder!, / ──╮$/);
159
-
160
- harness.instance.unmount();
161
- });
@@ -1,289 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { PassThrough } from "node:stream";
3
- import test from "node:test";
4
- import React from "react";
5
- import { Box, Text, render } from "ink";
6
- import { buildProviderRegistry } from "../core/providerLauncher/registry.js";
7
- import type { ProviderId, ProviderPickerAction } from "../core/providerLauncher/types.js";
8
- import { createLayoutSnapshot } from "./layout.js";
9
- import { ProviderPicker } from "./ProviderPicker.js";
10
- import { ThemeProvider } from "./theme.js";
11
-
12
- class TestInput extends PassThrough {
13
- readonly isTTY = true;
14
-
15
- setRawMode(): this {
16
- return this;
17
- }
18
-
19
- override resume(): this {
20
- return this;
21
- }
22
-
23
- override pause(): this {
24
- return this;
25
- }
26
-
27
- ref(): this {
28
- return this;
29
- }
30
-
31
- unref(): this {
32
- return this;
33
- }
34
- }
35
-
36
- class TestOutput extends PassThrough {
37
- readonly isTTY = true;
38
- columns = 120;
39
- rows = 40;
40
- }
41
-
42
- function stripAnsi(value: string): string {
43
- return value.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "");
44
- }
45
-
46
- function sleep(ms = 50): Promise<void> {
47
- return new Promise((resolve) => setTimeout(resolve, ms));
48
- }
49
-
50
- function createInkHarness(node: React.ReactElement) {
51
- const stdin = new TestInput();
52
- const stdout = new TestOutput();
53
- let output = "";
54
-
55
- stdout.on("data", (chunk) => {
56
- output += chunk.toString();
57
- });
58
-
59
- const instance = render(node, {
60
- stdin: stdin as unknown as NodeJS.ReadStream,
61
- stdout: stdout as unknown as NodeJS.WriteStream,
62
- stderr: stdout as unknown as NodeJS.WriteStream,
63
- debug: true,
64
- exitOnCtrlC: false,
65
- patchConsole: false,
66
- });
67
-
68
- return {
69
- stdin,
70
- getOutput(): string {
71
- return stripAnsi(output);
72
- },
73
- async cleanup() {
74
- instance.cleanup();
75
- await sleep(20);
76
- },
77
- };
78
- }
79
-
80
- function ProviderPickerHarness() {
81
- const [action, setAction] = React.useState("none");
82
- const providers = buildProviderRegistry({
83
- activeModel: "gpt-5.4",
84
- workspaceConfig: { workspaceDefaultProviderId: "openai" },
85
- });
86
-
87
- return (
88
- <ThemeProvider theme="purple">
89
- <Box flexDirection="column">
90
- <ProviderPicker
91
- layout={createLayoutSnapshot(120, 40)}
92
- providers={providers}
93
- onAction={(providerId: ProviderId, nextAction: ProviderPickerAction) => {
94
- setAction(`${providerId}:${nextAction}`);
95
- }}
96
- onCancel={() => setAction("cancel")}
97
- />
98
- <Text>{`action:${action}`}</Text>
99
- </Box>
100
- </ThemeProvider>
101
- );
102
- }
103
-
104
- test("provider picker renders compact aligned provider rows", async () => {
105
- const harness = createInkHarness(<ProviderPickerHarness />);
106
-
107
- try {
108
- await sleep(80);
109
- const output = harness.getOutput();
110
- assert.match(output, /Providers/);
111
- assert.match(output, /Enter = select, U = use, S = set default, Esc = cancel/);
112
- assert.match(output, /OpenAI/);
113
- assert.match(output, /Anthropic/);
114
- assert.match(output, /Google/);
115
- assert.match(output, /Local/);
116
- assert.doesNotMatch(output, /Antigravity/);
117
- assert.match(output, /Context/);
118
- assert.match(output, /Tool/);
119
- assert.match(output, /Strm/);
120
- assert.match(output, /Unknown/);
121
- assert.match(output, /\?/);
122
- assert.match(output, /Disabled/);
123
- assert.doesNotMatch(output, /0\/unknown/);
124
- } finally {
125
- await harness.cleanup();
126
- }
127
- });
128
-
129
- test("provider picker stays readable in a cramped terminal layout", async () => {
130
- const providers = buildProviderRegistry({ activeModel: "gpt-5.4-mini" });
131
- const harness = createInkHarness(
132
- <ThemeProvider theme="purple">
133
- <ProviderPicker
134
- layout={createLayoutSnapshot(44, 18)}
135
- providers={providers}
136
- onAction={() => {}}
137
- onCancel={() => {}}
138
- />
139
- </ThemeProvider>,
140
- );
141
-
142
- try {
143
- await sleep(80);
144
- const output = harness.getOutput();
145
- assert.match(output, /Providers/);
146
- assert.match(output, /Enter select/);
147
- assert.doesNotMatch(output, /Gemini CLIEnabled/);
148
- assert.match(output, /OpenAI/);
149
- assert.match(output, /Local/);
150
- assert.match(output, /Disabled/);
151
- assert.doesNotMatch(output, /undefined/);
152
- } finally {
153
- await harness.cleanup();
154
- }
155
- });
156
-
157
- test("provider picker supports setting default with S", async () => {
158
- const harness = createInkHarness(<ProviderPickerHarness />);
159
-
160
- try {
161
- await sleep(80);
162
- harness.stdin.write("\u001b[B");
163
- await sleep(40);
164
- harness.stdin.write("s");
165
- await sleep(80);
166
-
167
- assert.match(harness.getOutput(), /action:anthropic:set-default/);
168
- } finally {
169
- await harness.cleanup();
170
- }
171
- });
172
-
173
- test("provider picker opens action menu and selects launch", async () => {
174
- const harness = createInkHarness(<ProviderPickerHarness />);
175
-
176
- try {
177
- await sleep(80);
178
- harness.stdin.write("\u001b[B");
179
- await sleep(40);
180
- harness.stdin.write("\r");
181
- await sleep(40);
182
- assert.match(harness.getOutput(), /Provider action: Anthropic/);
183
- assert.match(harness.getOutput(), /Use in Codexa/);
184
- assert.match(harness.getOutput(), /Launch external CLI/);
185
- harness.stdin.write("\u001b[B");
186
- await sleep(40);
187
- harness.stdin.write("\u001b[B");
188
- await sleep(40);
189
- harness.stdin.write("\u001b[B");
190
- await sleep(40);
191
- harness.stdin.write("\r");
192
- await sleep(80);
193
-
194
- assert.match(harness.getOutput(), /action:anthropic:launch/);
195
- } finally {
196
- await harness.cleanup();
197
- }
198
- });
199
-
200
- test("provider picker reports Anthropic in-Codexa route actions without launching", async () => {
201
- const harness = createInkHarness(<ProviderPickerHarness />);
202
-
203
- try {
204
- await sleep(80);
205
- harness.stdin.write("\u001b[B");
206
- await sleep(40);
207
- harness.stdin.write("\r");
208
- await sleep(40);
209
- harness.stdin.write("\r");
210
- await sleep(80);
211
-
212
- assert.match(harness.getOutput(), /action:anthropic:use-in-codexa/);
213
- } finally {
214
- await harness.cleanup();
215
- }
216
- });
217
-
218
- test("provider picker exposes Gemini diagnostics action", async () => {
219
- const harness = createInkHarness(<ProviderPickerHarness />);
220
-
221
- try {
222
- await sleep(80);
223
- harness.stdin.write("\u001b[B");
224
- await sleep(40);
225
- harness.stdin.write("\u001b[B");
226
- await sleep(40);
227
- harness.stdin.write("\r");
228
- await sleep(40);
229
- assert.match(harness.getOutput(), /Provider action: Google/);
230
- assert.match(harness.getOutput(), /Run Gemini diagnostics/);
231
- harness.stdin.write("\u001b[B");
232
- await sleep(40);
233
- harness.stdin.write("\u001b[B");
234
- await sleep(40);
235
- harness.stdin.write("\u001b[B");
236
- await sleep(40);
237
- harness.stdin.write("\r");
238
- await sleep(80);
239
-
240
- assert.match(harness.getOutput(), /action:google:run-diagnostics/);
241
- } finally {
242
- await harness.cleanup();
243
- }
244
- });
245
-
246
- test("provider picker cancels from provider list with Esc", async () => {
247
- const harness = createInkHarness(<ProviderPickerHarness />);
248
-
249
- try {
250
- await sleep(80);
251
- harness.stdin.write("\u001b");
252
- await sleep(80);
253
-
254
- assert.match(harness.getOutput(), /action:cancel/);
255
- } finally {
256
- await harness.cleanup();
257
- }
258
- });
259
-
260
- test('pressing U fires use-in-codexa for the selected provider', async () => {
261
- const harness = createInkHarness(<ProviderPickerHarness />);
262
-
263
- try {
264
- await sleep(80);
265
- harness.stdin.write('u');
266
- await sleep(80);
267
-
268
- assert.match(harness.getOutput(), /action:openai:use-in-codexa/);
269
- } finally {
270
- await harness.cleanup();
271
- }
272
- });
273
-
274
- test('pressing U after navigating down fires use-in-codexa for the selected provider', async () => {
275
- const harness = createInkHarness(<ProviderPickerHarness />);
276
-
277
- try {
278
- await sleep(80);
279
- harness.stdin.write('j'); // down to Anthropic
280
- await sleep(40);
281
- harness.stdin.write('u');
282
- await sleep(80);
283
-
284
- assert.match(harness.getOutput(), /action:anthropic:use-in-codexa/);
285
- } finally {
286
- await harness.cleanup();
287
- }
288
- });
289
-