@golba98/codexa 1.0.2 → 1.0.4

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 (206) hide show
  1. package/README.md +396 -100
  2. package/bin/codexa.js +62 -144
  3. package/package.json +14 -8
  4. package/src/app.tsx +596 -306
  5. package/src/commands/handler.ts +6 -6
  6. package/src/config/buildInfo.ts +2 -2
  7. package/src/config/layeredConfig.ts +1 -1
  8. package/src/config/persistence.ts +10 -0
  9. package/src/config/runtimeConfig.ts +1 -1
  10. package/src/config/settings.ts +8 -16
  11. package/src/config/trustStore.ts +1 -1
  12. package/src/config/updateCheckCache.ts +19 -1
  13. package/src/core/README.md +52 -0
  14. package/src/core/agent/loop.ts +282 -0
  15. package/src/core/agent/protocol.ts +211 -0
  16. package/src/core/agent/tools.ts +414 -0
  17. package/src/core/{codexExecArgs.ts → codex/codexExecArgs.ts} +2 -2
  18. package/src/core/{codexLaunch.ts → codex/codexLaunch.ts} +3 -3
  19. package/src/core/{codexPrompt.ts → codex/codexPrompt.ts} +3 -3
  20. package/src/core/debug/modelStateDebug.ts +34 -0
  21. package/src/core/executables/antigravityExecutable.ts +48 -0
  22. package/src/core/executables/codexExecutable.ts +1 -0
  23. package/src/core/executables/executableResolver.ts +65 -43
  24. package/src/core/perf/renderDebug.ts +10 -6
  25. package/src/core/process/processValidation.ts +9 -5
  26. package/src/core/providerLauncher/launcher.ts +59 -42
  27. package/src/core/providerLauncher/registry.ts +30 -14
  28. package/src/core/providerLauncher/types.ts +11 -9
  29. package/src/core/providerLauncher/workspaceConfig.ts +41 -26
  30. package/src/core/providerRuntime/anthropic.ts +7 -1
  31. package/src/core/providerRuntime/antigravity.ts +305 -0
  32. package/src/core/providerRuntime/claudeCodeDiscovery.ts +268 -22
  33. package/src/core/providerRuntime/claudeCodeDiscoveryDebug.ts +55 -0
  34. package/src/core/providerRuntime/contextMetadata.ts +12 -24
  35. package/src/core/providerRuntime/local.ts +129 -51
  36. package/src/core/providerRuntime/models.ts +22 -11
  37. package/src/core/providerRuntime/registry.ts +58 -31
  38. package/src/core/providerRuntime/types.ts +19 -14
  39. package/src/core/providers/codexSubprocess.ts +2 -2
  40. package/src/core/providers/types.ts +1 -1
  41. package/src/core/{attachments.ts → shared/attachments.ts} +27 -4
  42. package/src/core/{cleanupFastFail.ts → shared/cleanupFastFail.ts} +1 -1
  43. package/src/core/{hollowResponseFormat.ts → shared/hollowResponseFormat.ts} +1 -1
  44. package/src/core/terminal/clearFrameBoundary.ts +814 -0
  45. package/src/core/terminal/frameLock.ts +109 -0
  46. package/src/core/terminal/inkRenderReset.ts +123 -0
  47. package/src/core/terminal/terminalControl.ts +22 -0
  48. package/src/core/terminal/terminalTitle.ts +16 -102
  49. package/src/core/version/channel.ts +23 -0
  50. package/src/core/version/updateCheck.ts +193 -0
  51. package/src/core/{launchContext.ts → workspace/launchContext.ts} +32 -39
  52. package/src/core/{planStorage.ts → workspace/planStorage.ts} +2 -2
  53. package/src/core/{workspaceGuard.ts → workspace/workspaceGuard.ts} +97 -13
  54. package/src/headless/execRunner.ts +2 -2
  55. package/src/index.tsx +43 -89
  56. package/src/session/appSession.ts +10 -7
  57. package/src/session/chatLifecycle.ts +1 -1
  58. package/src/session/liveRenderScheduler.ts +1 -1
  59. package/src/session/types.ts +3 -2
  60. package/src/ui/ActionRequiredBlock.tsx +5 -5
  61. package/src/ui/ActivityBars.tsx +3 -3
  62. package/src/ui/ActivityIndicator.tsx +6 -6
  63. package/src/ui/AgentBlock.tsx +6 -6
  64. package/src/ui/AnimatedStatusText.tsx +1 -1
  65. package/src/ui/AppShell.tsx +670 -719
  66. package/src/ui/AttachmentImportPanel.tsx +8 -8
  67. package/src/ui/AuthPanel.tsx +20 -20
  68. package/src/ui/BottomComposer.tsx +158 -118
  69. package/src/ui/DashCard.tsx +3 -3
  70. package/src/ui/Markdown.tsx +17 -17
  71. package/src/ui/ModelPickerScreen.tsx +222 -42
  72. package/src/ui/ModelReasoningPicker.tsx +15 -15
  73. package/src/ui/Panel.tsx +3 -3
  74. package/src/ui/PlanActionPicker.tsx +6 -6
  75. package/src/ui/PlanReviewPanel.tsx +9 -9
  76. package/src/ui/ProviderPicker.tsx +735 -321
  77. package/src/ui/RunFooter.tsx +3 -3
  78. package/src/ui/RuntimeStatusBar.tsx +108 -0
  79. package/src/ui/SelectionPanel.tsx +8 -4
  80. package/src/ui/SettingsPanel.tsx +9 -9
  81. package/src/ui/Spinner.tsx +1 -1
  82. package/src/ui/TextEntryPanel.tsx +11 -11
  83. package/src/ui/ThinkingBlock.tsx +8 -8
  84. package/src/ui/Timeline.tsx +1625 -1472
  85. package/src/ui/TopHeader.tsx +437 -293
  86. package/src/ui/TranscriptShell.tsx +322 -0
  87. package/src/ui/TurnGroup.tsx +33 -33
  88. package/src/ui/UpdateAvailableCard.tsx +41 -0
  89. package/src/ui/UpdatePromptPanel.tsx +197 -0
  90. package/src/ui/focus.ts +3 -0
  91. package/src/ui/layout.ts +299 -25
  92. package/src/ui/layoutListWindow.ts +145 -0
  93. package/src/ui/logoVariants.ts +103 -0
  94. package/src/ui/modeDisplay.ts +12 -12
  95. package/src/ui/runtimeDisplay.ts +112 -0
  96. package/src/ui/textLayout.ts +15 -4
  97. package/src/ui/theme.tsx +274 -395
  98. package/src/ui/timelineMeasure.ts +218 -136
  99. package/scripts/audit-codexa-capabilities.mjs +0 -466
  100. package/scripts/gen-build-info.mjs +0 -33
  101. package/scripts/smoke-terminal-bench.mjs +0 -35
  102. package/src/appRenderStability.test.ts +0 -131
  103. package/src/commands/handler.test.ts +0 -655
  104. package/src/config/launchArgs.test.ts +0 -189
  105. package/src/config/layeredConfig.test.ts +0 -143
  106. package/src/config/persistence.test.ts +0 -114
  107. package/src/config/runtimeConfig.test.ts +0 -218
  108. package/src/config/settings.test.ts +0 -155
  109. package/src/config/trustStore.test.ts +0 -29
  110. package/src/core/attachments.test.ts +0 -155
  111. package/src/core/auth/codexAuth.test.ts +0 -68
  112. package/src/core/cleanupFastFail.test.ts +0 -76
  113. package/src/core/codex.ts +0 -124
  114. package/src/core/codexExecArgs.test.ts +0 -195
  115. package/src/core/codexLaunch.test.ts +0 -205
  116. package/src/core/codexPrompt.test.ts +0 -252
  117. package/src/core/executables/codexExecutable.test.ts +0 -212
  118. package/src/core/executables/executableResolver.test.ts +0 -129
  119. package/src/core/executables/geminiExecutable.test.ts +0 -116
  120. package/src/core/executables/pathSanityScan.test.ts +0 -47
  121. package/src/core/githubDiagnostics.test.ts +0 -92
  122. package/src/core/hollowResponseFormat.test.ts +0 -58
  123. package/src/core/launchContext.test.ts +0 -157
  124. package/src/core/models/codexCapabilities.test.ts +0 -45
  125. package/src/core/models/codexModelCapabilities.test.ts +0 -246
  126. package/src/core/models/modelSpecs.test.ts +0 -283
  127. package/src/core/perf/renderDebug.test.ts +0 -230
  128. package/src/core/planStorage.test.ts +0 -143
  129. package/src/core/process/CommandRunner.test.ts +0 -105
  130. package/src/core/projectInstructions.test.ts +0 -50
  131. package/src/core/providerLauncher/launcher.test.ts +0 -238
  132. package/src/core/providerLauncher/registry.test.ts +0 -324
  133. package/src/core/providerLauncher/workspaceConfig.test.ts +0 -638
  134. package/src/core/providerRuntime/anthropic.test.ts +0 -1120
  135. package/src/core/providerRuntime/capabilityProfile.test.ts +0 -311
  136. package/src/core/providerRuntime/contextMetadata.test.ts +0 -468
  137. package/src/core/providerRuntime/gemini.test.ts +0 -437
  138. package/src/core/providerRuntime/lmstudio.test.ts +0 -168
  139. package/src/core/providerRuntime/local.test.ts +0 -787
  140. package/src/core/providerRuntime/registry.test.ts +0 -233
  141. package/src/core/providers/codexJsonStream.test.ts +0 -148
  142. package/src/core/providers/codexSubprocess.test.ts +0 -68
  143. package/src/core/providers/codexTranscript.test.ts +0 -284
  144. package/src/core/terminal/startupClear.test.ts +0 -55
  145. package/src/core/terminal/terminalCapabilities.test.ts +0 -93
  146. package/src/core/terminal/terminalControl.test.ts +0 -75
  147. package/src/core/terminal/terminalSanitize.test.ts +0 -22
  148. package/src/core/terminal/terminalSelection.test.ts +0 -42
  149. package/src/core/terminal/terminalTitle.test.ts +0 -328
  150. package/src/core/updateCheck.test.ts +0 -194
  151. package/src/core/updateCheck.ts +0 -172
  152. package/src/core/workspaceActivity.test.ts +0 -163
  153. package/src/core/workspaceGuard.test.ts +0 -151
  154. package/src/core/workspaceRoot.test.ts +0 -23
  155. package/src/exec.test.ts +0 -13
  156. package/src/headless/execArgs.test.ts +0 -147
  157. package/src/headless/execRunner.test.ts +0 -436
  158. package/src/index.test.tsx +0 -620
  159. package/src/session/appSession.test.ts +0 -897
  160. package/src/session/chatLifecycle.test.ts +0 -64
  161. package/src/session/liveRenderScheduler.test.ts +0 -201
  162. package/src/session/planFlow.test.ts +0 -103
  163. package/src/session/planTranscript.test.ts +0 -65
  164. package/src/session/promptRunSchedule.test.ts +0 -36
  165. package/src/ui/ActivityIndicator.test.tsx +0 -58
  166. package/src/ui/AgentBlock.test.ts +0 -6
  167. package/src/ui/AnimatedStatusText.test.ts +0 -16
  168. package/src/ui/AppShell.test.tsx +0 -1776
  169. package/src/ui/AttachmentImportPanel.test.tsx +0 -204
  170. package/src/ui/BottomComposer.test.ts +0 -674
  171. package/src/ui/CodexLogo.tsx +0 -55
  172. package/src/ui/Markdown.test.ts +0 -157
  173. package/src/ui/ModelPickerProviderScope.test.tsx +0 -411
  174. package/src/ui/ModelPickerScreen.test.tsx +0 -99
  175. package/src/ui/ModelPickerState.test.tsx +0 -151
  176. package/src/ui/ModelReasoningPicker.test.tsx +0 -447
  177. package/src/ui/PlanReviewPanel.test.tsx +0 -267
  178. package/src/ui/PromptCardBorder.test.tsx +0 -161
  179. package/src/ui/ProviderPicker.test.tsx +0 -289
  180. package/src/ui/ProviderShortcut.test.tsx +0 -143
  181. package/src/ui/SettingsPanel.test.tsx +0 -233
  182. package/src/ui/StaticTranscriptItem.tsx +0 -56
  183. package/src/ui/Timeline.test.ts +0 -2067
  184. package/src/ui/TimelineNavigation.test.tsx +0 -201
  185. package/src/ui/TopHeader.test.tsx +0 -254
  186. package/src/ui/TurnGroup.test.tsx +0 -365
  187. package/src/ui/busyStatusAnimation.test.ts +0 -30
  188. package/src/ui/commandNormalize.test.ts +0 -142
  189. package/src/ui/diffRenderer.test.ts +0 -102
  190. package/src/ui/focusFlow.test.tsx +0 -1098
  191. package/src/ui/inputBuffer.test.ts +0 -151
  192. package/src/ui/layout.test.ts +0 -146
  193. package/src/ui/modeDisplay.test.ts +0 -42
  194. package/src/ui/runActivityView.test.ts +0 -89
  195. package/src/ui/runLifecycleView.test.tsx +0 -237
  196. package/src/ui/statusRenderIsolation.test.tsx +0 -654
  197. package/src/ui/terminalAnswerFormat.test.ts +0 -19
  198. package/src/ui/textLayout.test.ts +0 -18
  199. package/src/ui/themeFlow.test.ts +0 -53
  200. package/src/ui/timelineMeasureCache.test.ts +0 -986
  201. /package/src/core/{inputDebug.ts → debug/inputDebug.ts} +0 -0
  202. /package/src/core/{clipboard.ts → shared/clipboard.ts} +0 -0
  203. /package/src/core/{githubDiagnostics.ts → shared/githubDiagnostics.ts} +0 -0
  204. /package/src/core/{projectInstructions.ts → workspace/projectInstructions.ts} +0 -0
  205. /package/src/core/{workspaceActivity.ts → workspace/workspaceActivity.ts} +0 -0
  206. /package/src/core/{workspaceRoot.ts → workspace/workspaceRoot.ts} +0 -0
@@ -1,283 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { mkdtempSync, readFileSync, rmSync } from "fs";
4
- import { join } from "path";
5
- import { tmpdir } from "os";
6
- import {
7
- areModelSpecsEqual,
8
- createLoadingModelSpec,
9
- createModelSpecService,
10
- createUnknownModelSpec,
11
- extractModelSpecFromDocText,
12
- KNOWN_MODEL_SPECS,
13
- loadModelSpecCache,
14
- MODEL_SPEC_DOC_URLS,
15
- parseTokenCount,
16
- resolveModelSpec,
17
- saveModelSpecCache,
18
- stripHtmlToText,
19
- type ModelSpec,
20
- type VerifiedModelSpec,
21
- } from "./modelSpecs.js";
22
-
23
- test("parses token counts with commas and suffixes", () => {
24
- assert.equal(parseTokenCount("1,050,000"), 1_050_000);
25
- assert.equal(parseTokenCount("128,000"), 128_000);
26
- assert.equal(parseTokenCount("1.05M"), 1_050_000);
27
- assert.equal(parseTokenCount("400k"), 400_000);
28
- assert.equal(parseTokenCount("nope"), null);
29
- });
30
-
31
- test("extracts verified model specs from official-doc-like text", () => {
32
- const spec = extractModelSpecFromDocText(
33
- "gpt-5.4",
34
- "GPT-5.4 1,050,000 context window 128,000 max output tokens",
35
- 123,
36
- );
37
-
38
- assert.deepEqual(spec, {
39
- status: "verified",
40
- contextWindow: 1_050_000,
41
- maxOutputTokens: 128_000,
42
- sourceUrl: MODEL_SPEC_DOC_URLS["gpt-5.4"],
43
- verifiedAt: 123,
44
- });
45
- });
46
-
47
- test("returns null for ambiguous or incomplete model spec text", () => {
48
- assert.equal(
49
- extractModelSpecFromDocText("gpt-5.4-mini", "GPT-5.4 mini supports coding and agents.", 123),
50
- null,
51
- );
52
- assert.equal(
53
- extractModelSpecFromDocText("gpt-5.4-mini", "400,000 context window but no output limit", 123),
54
- null,
55
- );
56
- });
57
-
58
- test("strips HTML before parsing model specs", () => {
59
- const html = `
60
- <html>
61
- <body>
62
- <h1>GPT-5.3-Codex</h1>
63
- <div>400,000 <strong>context window</strong></div>
64
- <div>128,000 <em>max output tokens</em></div>
65
- </body>
66
- </html>
67
- `;
68
- const text = stripHtmlToText(html);
69
- assert.match(text, /400,000 context window/i);
70
- assert.match(text, /128,000 max output tokens/i);
71
- });
72
-
73
- test("cache round-trip preserves verified values", () => {
74
- const dir = mkdtempSync(join(tmpdir(), "codexa-model-specs-"));
75
- const cacheFile = join(dir, "model-specs.json");
76
-
77
- try {
78
- const cache = {
79
- "gpt-5.2": {
80
- status: "verified" as const,
81
- contextWindow: 400_000,
82
- maxOutputTokens: 128_000,
83
- sourceUrl: MODEL_SPEC_DOC_URLS["gpt-5.2"],
84
- verifiedAt: 456,
85
- },
86
- };
87
- saveModelSpecCache(cache, cacheFile);
88
-
89
- const loaded = loadModelSpecCache(cacheFile);
90
- assert.deepEqual(loaded, cache);
91
- } finally {
92
- rmSync(dir, { recursive: true, force: true });
93
- }
94
- });
95
-
96
- test("background refresh updates specs and dedupes concurrent requests", async () => {
97
- const dir = mkdtempSync(join(tmpdir(), "codexa-model-specs-"));
98
- const cacheFile = join(dir, "model-specs.json");
99
- let fetchCalls = 0;
100
- const service = createModelSpecService({
101
- cacheFile,
102
- now: () => 789,
103
- fetchImpl: async () => {
104
- fetchCalls += 1;
105
- return new Response("400,000 context window 128,000 max output tokens", { status: 200 });
106
- },
107
- });
108
-
109
- try {
110
- const [left, right] = await Promise.all([
111
- service.refreshSpec("gpt-5.2"),
112
- service.refreshSpec("gpt-5.2"),
113
- ]);
114
-
115
- assert.equal(fetchCalls, 1);
116
- assert.equal(left.status, "verified");
117
- assert.equal(right.status, "verified");
118
- assert.equal(left.contextWindow, 400_000);
119
- assert.equal(left.maxOutputTokens, 128_000);
120
-
121
- const persisted = JSON.parse(readFileSync(cacheFile, "utf-8")) as Record<string, ModelSpec>;
122
- assert.equal(persisted["gpt-5.2"]?.verifiedAt, 789);
123
- } finally {
124
- rmSync(dir, { recursive: true, force: true });
125
- }
126
- });
127
-
128
- test("refresh returns unknown when a fetch fails even if cache exists", async () => {
129
- const dir = mkdtempSync(join(tmpdir(), "codexa-model-specs-"));
130
- const cacheFile = join(dir, "model-specs.json");
131
- saveModelSpecCache({
132
- "gpt-5.3-codex": {
133
- status: "verified",
134
- contextWindow: 400_000,
135
- maxOutputTokens: 128_000,
136
- sourceUrl: MODEL_SPEC_DOC_URLS["gpt-5.3-codex"],
137
- verifiedAt: 123,
138
- },
139
- }, cacheFile);
140
-
141
- const service = createModelSpecService({
142
- cacheFile,
143
- fetchImpl: async () => new Response("broken page", { status: 200 }),
144
- });
145
-
146
- try {
147
- const spec = await service.refreshSpec("gpt-5.3-codex");
148
- assert.equal(spec.status, "unknown");
149
- assert.equal(spec.contextWindow, null);
150
- assert.equal(spec.maxOutputTokens, null);
151
- assert.equal(spec.error, "Unable to parse model spec for gpt-5.3-codex");
152
- } finally {
153
- rmSync(dir, { recursive: true, force: true });
154
- }
155
- });
156
-
157
- test("refresh returns unknown when there is no cache and verification fails", async () => {
158
- const dir = mkdtempSync(join(tmpdir(), "codexa-model-specs-"));
159
- const cacheFile = join(dir, "model-specs.json");
160
- const service = createModelSpecService({
161
- cacheFile,
162
- fetchImpl: async () => new Response("no token limits here", { status: 200 }),
163
- });
164
-
165
- try {
166
- const spec = await service.refreshSpec("gpt-5.2");
167
- assert.deepEqual(spec, createUnknownModelSpec("gpt-5.2", "Unable to parse model spec for gpt-5.2"));
168
- } finally {
169
- rmSync(dir, { recursive: true, force: true });
170
- }
171
- });
172
-
173
- test("resolveModelSpec prefers runtime discovery metadata", () => {
174
- const spec = resolveModelSpec("gpt-5.4", {
175
- runtimeContextWindow: 2_000_000,
176
- runtimeMaxOutputTokens: 256_000,
177
- cache: {
178
- "gpt-5.4": {
179
- status: "verified",
180
- contextWindow: 1_050_000,
181
- maxOutputTokens: 128_000,
182
- sourceUrl: MODEL_SPEC_DOC_URLS["gpt-5.4"]!,
183
- verifiedAt: 1,
184
- },
185
- },
186
- now: () => 999,
187
- });
188
-
189
- assert.equal(spec.status, "verified");
190
- assert.equal(spec.contextWindow, 2_000_000);
191
- assert.equal(spec.maxOutputTokens, 256_000);
192
- });
193
-
194
- test("resolveModelSpec falls back to persisted cache when runtime lacks context metadata", () => {
195
- const spec = resolveModelSpec("gpt-5.4", {
196
- cache: {
197
- "gpt-5.4": {
198
- status: "verified",
199
- contextWindow: 1_050_000,
200
- maxOutputTokens: 128_000,
201
- sourceUrl: MODEL_SPEC_DOC_URLS["gpt-5.4"]!,
202
- verifiedAt: 42,
203
- },
204
- },
205
- });
206
-
207
- assert.equal(spec.status, "verified");
208
- assert.equal(spec.contextWindow, 1_050_000);
209
- assert.equal(spec.verifiedAt, 42);
210
- });
211
-
212
- test("resolveModelSpec does not use static registry values when cache is empty", () => {
213
- const spec = resolveModelSpec("gpt-5.4-mini", { now: () => 11 });
214
- assert.equal(spec.status, "unknown");
215
- assert.equal(spec.contextWindow, null);
216
- assert.deepEqual(KNOWN_MODEL_SPECS, {});
217
- });
218
-
219
- test("resolveModelSpec returns loading while refresh is in-flight for unmapped models", () => {
220
- const spec = resolveModelSpec("gpt-future-9", { refreshInFlight: true });
221
- assert.equal(spec.status, "loading");
222
- assert.equal(spec.contextWindow, null);
223
- });
224
-
225
- test("resolveModelSpec returns unknown only when no source can supply context metadata", () => {
226
- const spec = resolveModelSpec("gpt-future-9");
227
- assert.equal(spec.status, "unknown");
228
- assert.equal(spec.contextWindow, null);
229
- });
230
-
231
- test("resolveModelSpec does not infer registry entries when switching between model names", () => {
232
- const specFour = resolveModelSpec("gpt-5.4");
233
- const specTwo = resolveModelSpec("gpt-5.2");
234
- assert.equal(specFour.contextWindow, null);
235
- assert.equal(specTwo.contextWindow, null);
236
- });
237
-
238
- test("reports equality across verified and unknown specs", () => {
239
- assert.equal(
240
- areModelSpecsEqual(
241
- createLoadingModelSpec("gpt-5.4"),
242
- createLoadingModelSpec("gpt-5.4"),
243
- ),
244
- true,
245
- );
246
- assert.equal(
247
- areModelSpecsEqual(
248
- createUnknownModelSpec("gpt-5.4", "a"),
249
- createUnknownModelSpec("gpt-5.4", "b"),
250
- ),
251
- false,
252
- );
253
- });
254
-
255
- test("resolveModelSpec returns unknown for claude-sonnet-4-6 without runtime/config context", () => {
256
- const spec = resolveModelSpec("claude-sonnet-4-6");
257
- assert.equal(spec.status, "unknown");
258
- assert.equal(spec.contextWindow, null);
259
- });
260
-
261
- test("resolveModelSpec returns unknown for anthropic short alias 'haiku'", () => {
262
- const spec = resolveModelSpec("haiku");
263
- assert.equal(spec.status, "unknown");
264
- assert.equal(spec.contextWindow, null);
265
- });
266
-
267
- test("resolveModelSpec returns unknown for gemini-2.5-flash without provider context metadata", () => {
268
- const spec = resolveModelSpec("gemini-2.5-flash");
269
- assert.equal(spec.status, "unknown");
270
- assert.equal(spec.contextWindow, null);
271
- });
272
-
273
- test("resolveModelSpec returns null contextWindow (not 0) for an unrecognized model", () => {
274
- const spec = resolveModelSpec("totally-unknown-model");
275
- assert.equal(spec.status, "unknown");
276
- assert.equal(spec.contextWindow, null);
277
- });
278
-
279
- test("resolveModelSpec does not estimate gemini-3-flash-preview", () => {
280
- const spec = resolveModelSpec("gemini-3-flash-preview");
281
- assert.equal(spec.status, "unknown");
282
- assert.equal(spec.contextWindow, null);
283
- });
@@ -1,230 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { existsSync, readFileSync, rmSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
- import test from "node:test";
6
- import {
7
- configureRenderDebug,
8
- getRenderDebugLogPath,
9
- traceBlankFrame,
10
- traceEvent,
11
- traceLayoutValidity,
12
- traceLifecycleEvent,
13
- traceLifecycleTransition,
14
- traceFlickerEvent,
15
- traceStatusTick,
16
- traceRender,
17
- traceTerminalWrite,
18
- } from "./renderDebug.js";
19
-
20
- function clean(path: string): void {
21
- rmSync(path, { force: true });
22
- }
23
-
24
- test("render debug stays quiet by default", () => {
25
- const logPath = join(tmpdir(), `codexa-render-debug-quiet-${process.pid}.jsonl`);
26
- clean(logPath);
27
-
28
- configureRenderDebug({ CODEXA_RENDER_DEBUG_FILE: logPath });
29
- traceEvent("test", "quiet");
30
- traceRender("QuietComponent", "test");
31
-
32
- assert.equal(existsSync(logPath), false);
33
- });
34
-
35
- test("render debug writes JSONL only when explicitly enabled", () => {
36
- const logPath = join(tmpdir(), `codexa-render-debug-enabled-${process.pid}.jsonl`);
37
- clean(logPath);
38
-
39
- try {
40
- configureRenderDebug({
41
- CODEXA_RENDER_DEBUG: "1",
42
- CODEXA_RENDER_DEBUG_FILE: logPath,
43
- });
44
- traceRender("EnabledComponent", "unit");
45
-
46
- assert.equal(getRenderDebugLogPath(), logPath);
47
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
48
- assert.equal(records[0]?.kind, "session");
49
- assert.equal(records[1]?.kind, "render");
50
- assert.equal(records[1]?.component, "EnabledComponent");
51
- assert.equal(records[1]?.reason, "unit");
52
- } finally {
53
- configureRenderDebug({});
54
- clean(logPath);
55
- }
56
- });
57
-
58
- test("render debug defaults to the repo-local diagnostic log path", () => {
59
- configureRenderDebug({});
60
- assert.equal(getRenderDebugLogPath(), join(process.cwd(), ".codexa-debug", "render-debug.log"));
61
- });
62
-
63
- test("render debug creates missing log directories", () => {
64
- const logPath = join(tmpdir(), `codexa-render-debug-nested-${process.pid}`, "render-debug.log");
65
- rmSync(join(tmpdir(), `codexa-render-debug-nested-${process.pid}`), { force: true, recursive: true });
66
-
67
- try {
68
- configureRenderDebug({
69
- CODEXA_RENDER_DEBUG: "1",
70
- CODEXA_RENDER_DEBUG_FILE: logPath,
71
- });
72
- assert.equal(existsSync(logPath), true);
73
- } finally {
74
- configureRenderDebug({});
75
- rmSync(join(tmpdir(), `codexa-render-debug-nested-${process.pid}`), { force: true, recursive: true });
76
- }
77
- });
78
-
79
- test("render debug records lifecycle, layout, and blank-frame diagnostics", () => {
80
- const logPath = join(tmpdir(), `codexa-render-diagnostics-${process.pid}.jsonl`);
81
- clean(logPath);
82
-
83
- try {
84
- configureRenderDebug({
85
- CODEXA_RENDER_DEBUG: "1",
86
- CODEXA_RENDER_DEBUG_FILE: logPath,
87
- });
88
- traceLifecycleEvent("Timeline", "mount", { viewportRows: 12 });
89
- traceLayoutValidity("Timeline", { viewportRows: 0, cols: 120 });
90
- traceBlankFrame("Timeline", { reason: "visible-rows-zero-with-events" });
91
-
92
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
93
- assert.equal(records[1]?.kind, "lifecycle");
94
- assert.equal(records[1]?.component, "Timeline");
95
- assert.equal(records[1]?.event, "mount");
96
- assert.equal(records[2]?.kind, "layout");
97
- assert.equal(records[2]?.event, "invalidLayout");
98
- assert.deepEqual(records[2]?.invalidValues, [{ key: "viewportRows", value: 0 }]);
99
- assert.equal(records[3]?.kind, "blankFrame");
100
- assert.equal(records[3]?.reason, "visible-rows-zero-with-events");
101
- } finally {
102
- configureRenderDebug({});
103
- clean(logPath);
104
- }
105
- });
106
-
107
- test("terminal writes are classified for clear and reset diagnosis", () => {
108
- const logPath = join(tmpdir(), `codexa-terminal-classification-${process.pid}.jsonl`);
109
- clean(logPath);
110
-
111
- try {
112
- configureRenderDebug({
113
- CODEXA_RENDER_DEBUG: "1",
114
- CODEXA_RENDER_DEBUG_FILE: logPath,
115
- });
116
- traceTerminalWrite(
117
- "stdout",
118
- "unit",
119
- "\x1b[2J\x1b[3J\x1b[H\x1bc\x1b[?1049h\x1b]0;CODEXA\x07\x1b[?2004h\x1b[?1000h",
120
- );
121
-
122
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
123
- assert.equal(records[1]?.kind, "stdout");
124
- assert.equal(records[1]?.containsViewportClear, true);
125
- assert.equal(records[1]?.containsScrollbackClear, true);
126
- assert.equal(records[1]?.containsCursorHome, true);
127
- assert.equal(records[1]?.containsTerminalReset, true);
128
- assert.equal(records[1]?.containsAlternateScreen, true);
129
- assert.equal(records[1]?.containsTitleSequence, true);
130
- assert.equal(records[1]?.containsBracketedPaste, true);
131
- assert.equal(records[1]?.containsMouseMode, true);
132
- } finally {
133
- configureRenderDebug({});
134
- clean(logPath);
135
- }
136
- });
137
-
138
- test("CODEXA_DEBUG_RENDER aliases render debug logging", () => {
139
- const logPath = join(tmpdir(), `codexa-debug-render-alias-${process.pid}.jsonl`);
140
- clean(logPath);
141
-
142
- try {
143
- configureRenderDebug({
144
- CODEXA_DEBUG_RENDER: "1",
145
- CODEXA_RENDER_DEBUG_FILE: logPath,
146
- });
147
- traceRender("AliasComponent", "unit");
148
-
149
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
150
- assert.equal(records[0]?.kind, "session");
151
- assert.equal(records[1]?.kind, "render");
152
- assert.equal(records[1]?.component, "AliasComponent");
153
- } finally {
154
- configureRenderDebug({});
155
- clean(logPath);
156
- }
157
- });
158
-
159
- test("render trace flag enables compact render diagnostics", () => {
160
- const logPath = join(tmpdir(), `codexa-render-trace-${process.pid}.jsonl`);
161
- clean(logPath);
162
-
163
- try {
164
- configureRenderDebug({
165
- CODEXA_DEBUG_RENDER_TRACE: "1",
166
- CODEXA_RENDER_DEBUG_FILE: logPath,
167
- });
168
- traceRender("TraceComponent", "unit");
169
- traceFlickerEvent("viewportSlice", { reason: "unit" });
170
-
171
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
172
- assert.equal(records[0]?.kind, "session");
173
- assert.equal(records[1]?.kind, "render");
174
- assert.equal(records[1]?.component, "TraceComponent");
175
- assert.equal(records[2]?.kind, "flicker");
176
- assert.equal(records[2]?.event, "viewportSlice");
177
- } finally {
178
- configureRenderDebug({});
179
- clean(logPath);
180
- }
181
- });
182
-
183
- test("lifecycle trace is gated by CODEXA_DEBUG_LIFECYCLE", () => {
184
- const logPath = join(tmpdir(), `codexa-lifecycle-debug-${process.pid}.jsonl`);
185
- clean(logPath);
186
-
187
- try {
188
- configureRenderDebug({
189
- CODEXA_DEBUG_LIFECYCLE: "1",
190
- CODEXA_RENDER_DEBUG_FILE: logPath,
191
- });
192
- traceLifecycleTransition({
193
- prevKind: "THINKING",
194
- nextKind: "IDLE",
195
- reason: "unit",
196
- });
197
-
198
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
199
- assert.equal(records.length, 1);
200
- assert.equal(records[0]?.kind, "lifecycle");
201
- assert.equal(records[0]?.reason, "unit");
202
- } finally {
203
- configureRenderDebug({});
204
- clean(logPath);
205
- }
206
- });
207
-
208
- test("flicker trace is gated by CODEXA_DEBUG_FLICKER", () => {
209
- const logPath = join(tmpdir(), `codexa-flicker-debug-${process.pid}.jsonl`);
210
- clean(logPath);
211
-
212
- try {
213
- configureRenderDebug({
214
- CODEXA_DEBUG_FLICKER: "1",
215
- CODEXA_RENDER_DEBUG_FILE: logPath,
216
- });
217
- traceFlickerEvent("timelineRender", { reason: "unit" });
218
- traceStatusTick({ owner: "Status", label: "Codex is thinking" });
219
-
220
- const records = readFileSync(logPath, "utf8").trim().split("\n").map((line) => JSON.parse(line));
221
- assert.equal(records.length, 2);
222
- assert.equal(records[0]?.kind, "flicker");
223
- assert.equal(records[0]?.event, "timelineRender");
224
- assert.equal(records[1]?.kind, "flicker");
225
- assert.equal(records[1]?.event, "statusTick");
226
- } finally {
227
- configureRenderDebug({});
228
- clean(logPath);
229
- }
230
- });
@@ -1,143 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test, { afterEach, beforeEach, describe } from "node:test";
3
- import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "fs";
4
- import { join } from "path";
5
- import { tmpdir } from "os";
6
- import { resolvePlanDir, savePlan, readPlan } from "./planStorage.js";
7
-
8
- describe("resolvePlanDir", () => {
9
- const savedEnv: Record<string, string | undefined> = {};
10
- const envKeys = ["CODEXA_PLAN_DIR", "LOCALAPPDATA", "APPDATA", "XDG_DATA_HOME"];
11
-
12
- beforeEach(() => {
13
- for (const key of envKeys) {
14
- savedEnv[key] = process.env[key];
15
- }
16
- });
17
-
18
- afterEach(() => {
19
- for (const key of envKeys) {
20
- if (savedEnv[key] === undefined) {
21
- delete process.env[key];
22
- } else {
23
- process.env[key] = savedEnv[key];
24
- }
25
- }
26
- });
27
-
28
- test("CODEXA_PLAN_DIR override takes priority", () => {
29
- process.env["CODEXA_PLAN_DIR"] = "/custom/plan/dir";
30
- assert.equal(resolvePlanDir(), "/custom/plan/dir");
31
- });
32
-
33
- test("Windows LOCALAPPDATA path resolution", () => {
34
- delete process.env["CODEXA_PLAN_DIR"];
35
- process.env["LOCALAPPDATA"] = "C:\\Users\\test\\AppData\\Local";
36
- const result = resolvePlanDir("win32");
37
- assert.ok(result.includes("Codexa"));
38
- assert.ok(result.includes("plans"));
39
- assert.ok(result.includes("AppData"));
40
- });
41
-
42
- test("Windows APPDATA fallback", () => {
43
- delete process.env["CODEXA_PLAN_DIR"];
44
- delete process.env["LOCALAPPDATA"];
45
- process.env["APPDATA"] = "C:\\Users\\test\\AppData\\Roaming";
46
- const result = resolvePlanDir("win32");
47
- assert.ok(result.includes("Codexa"));
48
- assert.ok(result.includes("plans"));
49
- assert.ok(result.includes("Roaming"));
50
- });
51
-
52
- test("macOS path", () => {
53
- delete process.env["CODEXA_PLAN_DIR"];
54
- const result = resolvePlanDir("darwin");
55
- assert.ok(result.includes("Library"));
56
- assert.ok(result.includes("Codexa"));
57
- assert.ok(result.includes("plans"));
58
- });
59
-
60
- test("Linux default path", () => {
61
- delete process.env["CODEXA_PLAN_DIR"];
62
- delete process.env["XDG_DATA_HOME"];
63
- const result = resolvePlanDir("linux");
64
- assert.ok(result.includes(".local"));
65
- assert.ok(result.includes("share"));
66
- assert.ok(result.includes("codexa"));
67
- assert.ok(result.includes("plans"));
68
- });
69
-
70
- test("Linux XDG_DATA_HOME override", () => {
71
- delete process.env["CODEXA_PLAN_DIR"];
72
- process.env["XDG_DATA_HOME"] = "/custom/xdg/data";
73
- const result = resolvePlanDir("linux");
74
- assert.ok(result.includes("custom"));
75
- assert.ok(result.includes("xdg"));
76
- assert.ok(result.includes("codexa"));
77
- assert.ok(result.includes("plans"));
78
- });
79
- });
80
-
81
- describe("savePlan", () => {
82
- let tempDir: string;
83
-
84
- beforeEach(() => {
85
- tempDir = join(tmpdir(), `planStorage-test-${Date.now()}`);
86
- mkdirSync(tempDir, { recursive: true });
87
- process.env["CODEXA_PLAN_DIR"] = tempDir;
88
- });
89
-
90
- afterEach(() => {
91
- delete process.env["CODEXA_PLAN_DIR"];
92
- rmSync(tempDir, { recursive: true, force: true });
93
- });
94
-
95
- test("safe filename format with timestamp and 8-hex-char hash", () => {
96
- const result = savePlan("# My Plan", "/some/workspace");
97
- assert.notEqual(result, null);
98
- const filename = result!.split(/[/\\]/).pop()!;
99
- assert.match(filename, /^plan-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}.*-[0-9a-f]{8}\.md$/);
100
- });
101
-
102
- test("written content can be read back", () => {
103
- const content = "# Test Plan\n\n- Step 1\n- Step 2\n";
104
- const result = savePlan(content, "/workspace");
105
- assert.notEqual(result, null);
106
- assert.ok(existsSync(result!));
107
- assert.equal(readPlan(result!), content);
108
- });
109
-
110
- test("write failure returns null", () => {
111
- process.env["CODEXA_PLAN_DIR"] = "/nonexistent\x00/bad/path";
112
- const result = savePlan("content", "/workspace");
113
- assert.equal(result, null);
114
- });
115
-
116
- test("does not write to process.cwd()", () => {
117
- const cwdPlanDir = join(process.cwd(), ".codexa");
118
- const beforeMarkdown = existsSync(cwdPlanDir)
119
- ? readdirSync(cwdPlanDir).filter((name) => name.endsWith(".md")).sort()
120
- : [];
121
- savePlan("# Plan", process.cwd());
122
- const afterMarkdown = existsSync(cwdPlanDir)
123
- ? readdirSync(cwdPlanDir).filter((name) => name.endsWith(".md")).sort()
124
- : [];
125
- assert.deepEqual(afterMarkdown, beforeMarkdown);
126
- });
127
- });
128
-
129
- describe("readPlan", () => {
130
- test("returns null for missing file", () => {
131
- assert.equal(readPlan("/nonexistent/file.md"), null);
132
- });
133
-
134
- test("reads existing file content", () => {
135
- const tempFile = join(tmpdir(), `plan-read-test-${Date.now()}.md`);
136
- writeFileSync(tempFile, "hello plan", "utf-8");
137
- try {
138
- assert.equal(readPlan(tempFile), "hello plan");
139
- } finally {
140
- rmSync(tempFile, { force: true });
141
- }
142
- });
143
- });