@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,328 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import {
4
- acquireTerminalTitleGuard,
5
- buildTerminalTitleSequence,
6
- computeTerminalTitle,
7
- deriveTerminalTitle,
8
- formatTerminalTitleLabel,
9
- getIntendedTerminalTitle,
10
- normalizeTerminalTitle,
11
- reassertTerminalTitle,
12
- reassertIntendedTerminalTitle,
13
- sanitizeTerminalTitle,
14
- setIntendedTerminalTitle,
15
- setTerminalTitle,
16
- startTerminalTitleStartupGuard,
17
- beginColdStartSequence,
18
- createTerminalTitleSequenceStripper,
19
- stripTerminalTitleSequences,
20
- stripTerminalTitleSequencesFromChunk,
21
- traceTerminalTitleSequences,
22
- writeCodexaTerminalTitle,
23
- writeGuardedTerminalOutput,
24
- __resetTerminalTitleCache,
25
- } from "./terminalTitle.js";
26
-
27
- function sleep(ms: number): Promise<void> {
28
- return new Promise((resolve) => setTimeout(resolve, ms));
29
- }
30
-
31
- test("buildTerminalTitleSequence emits OSC 0 and OSC 2 with sanitized title text", () => {
32
- const sequence = buildTerminalTitleSequence("Codexa\u0007!");
33
- assert.equal(sequence, "\x1b]0;Codexa !\x07\x1b]2;Codexa !\x07");
34
- assert.equal(sanitizeTerminalTitle(" Codexa "), "Codexa");
35
- });
36
-
37
- test("title normalization never exposes raw Windows paths", () => {
38
- assert.equal(normalizeTerminalTitle("C:\\WINDOWS\\system"), "Codexa");
39
- assert.equal(normalizeTerminalTitle("c:/Users/example"), "Codexa");
40
- assert.equal(normalizeTerminalTitle("\\\\server\\share"), "Codexa");
41
- assert.equal(buildTerminalTitleSequence("C:\\WINDOWS\\system"), buildTerminalTitleSequence("Codexa"));
42
- });
43
-
44
- test("stripTerminalTitleSequences removes OSC 0 title sequences with BEL terminator", () => {
45
- assert.equal(
46
- stripTerminalTitleSequences("hello\x1b]0;C:\\WINDOWS\\system\x07world"),
47
- "helloworld",
48
- );
49
- });
50
-
51
- test("stripTerminalTitleSequences removes OSC 2 title sequences with BEL terminator", () => {
52
- assert.equal(
53
- stripTerminalTitleSequences("hello\x1b]2;Codex\x07world"),
54
- "helloworld",
55
- );
56
- });
57
-
58
- test("stripTerminalTitleSequences preserves normal ANSI SGR colour sequences", () => {
59
- const input = "\x1b[31mred\x1b[0m";
60
- assert.equal(stripTerminalTitleSequences(input), input);
61
- });
62
-
63
- test("stripTerminalTitleSequences removes title OSC from mixed output while preserving SGR", () => {
64
- assert.equal(
65
- stripTerminalTitleSequences("start\x1b]0;C:\\WINDOWS\\system\x07middle\x1b[32mok\x1b[0mend"),
66
- "startmiddle\x1b[32mok\x1b[0mend",
67
- );
68
- });
69
-
70
- test("stripTerminalTitleSequences removes OSC title sequences with ST terminator", () => {
71
- assert.equal(
72
- stripTerminalTitleSequences("hello\x1b]0;C:\\WINDOWS\\system\x1b\\world"),
73
- "helloworld",
74
- );
75
- });
76
-
77
- test("stripTerminalTitleSequencesFromChunk handles Buffer input", () => {
78
- assert.equal(
79
- stripTerminalTitleSequencesFromChunk(Buffer.from("hello\x1b]0;C:\\WINDOWS\\system\x07world", "utf8")),
80
- "helloworld",
81
- );
82
- });
83
-
84
- test("createTerminalTitleSequenceStripper removes title sequences split across chunks", () => {
85
- const stripper = createTerminalTitleSequenceStripper({
86
- source: "test",
87
- stream: "stdout",
88
- origin: "child",
89
- });
90
-
91
- assert.equal(stripper.process("hello\x1b]0;C:\\WINDOWS"), "hello");
92
- assert.equal(stripper.process("\\system\x07world"), "world");
93
- assert.equal(stripper.flush(), "");
94
- });
95
-
96
- test("formatTerminalTitleLabel follows the workspace leaf and app-name rules", () => {
97
- assert.equal(
98
- formatTerminalTitleLabel("C:\\Development\\1-JavaScript\\13-Custom-CLI-Normal", "dir"),
99
- "13-Custom-CLI-Normal",
100
- );
101
- assert.equal(
102
- formatTerminalTitleLabel("C:\\Development\\1-JavaScript\\13-Custom-CLI-Normal", "name"),
103
- "Codexa",
104
- );
105
- assert.equal(
106
- formatTerminalTitleLabel("C:\\Development\\1-JavaScript\\13-Custom-CLI-Normal", "simple"),
107
- "Codexa",
108
- );
109
- });
110
-
111
- test("deriveTerminalTitle follows terminal title mode on startup", () => {
112
- const workspaceRoot = "C:\\Development\\1-JavaScript\\13-Custom-CLI-Normal";
113
-
114
- assert.equal(deriveTerminalTitle(workspaceRoot, "dir"), "13-Custom-CLI-Normal");
115
- assert.equal(deriveTerminalTitle(workspaceRoot, "name"), "Codexa");
116
- assert.equal(deriveTerminalTitle(workspaceRoot, "simple"), "Codexa");
117
- });
118
-
119
- test("computeTerminalTitle follows the requested mapping", () => {
120
- const workspaceName = "13-Custom-CLI-Normal";
121
- assert.equal(computeTerminalTitle({ terminalTitleMode: "dir", workspaceName }), "13-Custom-CLI-Normal");
122
- assert.equal(computeTerminalTitle({ terminalTitleMode: "name" }), "Codexa");
123
- assert.equal(computeTerminalTitle({ terminalTitleMode: "simple" }), "Codexa");
124
- assert.equal(computeTerminalTitle({ terminalTitleMode: "dir", appName: "Other" }), "Other");
125
- });
126
-
127
- test("reassertTerminalTitle writes both title sequences without mutating process title", () => {
128
- const writes: string[] = [];
129
- const originalTitle = process.title;
130
-
131
- try {
132
- reassertTerminalTitle("Codexa", (chunk) => {
133
- writes.push(chunk);
134
- });
135
-
136
- assert.equal(process.title, originalTitle);
137
- assert.deepEqual(writes, [buildTerminalTitleSequence("Codexa")]);
138
- } finally {
139
- process.title = originalTitle;
140
- }
141
- });
142
-
143
- test("acquireTerminalTitleGuard asserts immediately, ticks while active, and reasserts on release", async () => {
144
- let calls = 0;
145
- const release = acquireTerminalTitleGuard(10, () => {
146
- calls += 1;
147
- });
148
-
149
- await sleep(35);
150
- release();
151
-
152
- const callsAfterRelease = calls;
153
- await sleep(20);
154
-
155
- assert.ok(callsAfterRelease >= 3, `expected at least 3 title assertions, got ${callsAfterRelease}`);
156
- assert.equal(calls, callsAfterRelease);
157
- });
158
-
159
- test("acquireTerminalTitleGuard release is idempotent", () => {
160
- let calls = 0;
161
- const release = acquireTerminalTitleGuard(50, () => {
162
- calls += 1;
163
- });
164
-
165
- release();
166
- const callsAfterFirstRelease = calls;
167
- release();
168
-
169
- assert.equal(callsAfterFirstRelease, 2);
170
- assert.equal(calls, callsAfterFirstRelease);
171
- });
172
-
173
- test("setTerminalTitle deduplicates identical title writes", () => {
174
- const writes: string[] = [];
175
- __resetTerminalTitleCache();
176
-
177
- setTerminalTitle("Codexa", { write: (chunk) => writes.push(chunk) });
178
- setTerminalTitle("Codexa", { write: (chunk) => writes.push(chunk) });
179
- setTerminalTitle("Other", { write: (chunk) => writes.push(chunk) });
180
-
181
- assert.equal(writes.length, 2);
182
- assert.equal(writes[0], buildTerminalTitleSequence("Codexa"));
183
- assert.equal(writes[1], buildTerminalTitleSequence("Other"));
184
- });
185
-
186
- test("writeCodexaTerminalTitle delegates to central title writer with force support", () => {
187
- const writes: string[] = [];
188
- __resetTerminalTitleCache();
189
-
190
- writeCodexaTerminalTitle("Codexa", { force: true, reason: "test", write: (chunk) => writes.push(chunk) });
191
-
192
- assert.deepEqual(writes, [buildTerminalTitleSequence("Codexa")]);
193
- });
194
-
195
- test("intended terminal title fallback is safe and later replaced by workspace title", () => {
196
- const writes: string[] = [];
197
- __resetTerminalTitleCache();
198
-
199
- setIntendedTerminalTitle("C:\\WINDOWS\\system", {
200
- force: true,
201
- reason: "test-fallback",
202
- write: (chunk) => writes.push(chunk),
203
- });
204
- assert.equal(getIntendedTerminalTitle(), "Codexa");
205
- assert.equal(writes.at(-1), buildTerminalTitleSequence("Codexa"));
206
-
207
- setIntendedTerminalTitle("13-Custom-CLI-Normal", {
208
- force: true,
209
- reason: "test-workspace",
210
- write: (chunk) => writes.push(chunk),
211
- });
212
- assert.equal(getIntendedTerminalTitle(), "13-Custom-CLI-Normal");
213
- assert.equal(writes.at(-1), buildTerminalTitleSequence("13-Custom-CLI-Normal"));
214
- });
215
-
216
- test("busy idle reassertion keeps the same intended title", () => {
217
- const writes: string[] = [];
218
- __resetTerminalTitleCache();
219
-
220
- setIntendedTerminalTitle("13-Custom-CLI-Normal", {
221
- force: true,
222
- write: (chunk) => writes.push(chunk),
223
- });
224
- reassertIntendedTerminalTitle({ reason: "busy-start", write: (chunk) => writes.push(chunk) });
225
- reassertIntendedTerminalTitle({ reason: "busy-end", write: (chunk) => writes.push(chunk) });
226
-
227
- assert.equal(getIntendedTerminalTitle(), "13-Custom-CLI-Normal");
228
- assert.deepEqual(writes, [
229
- buildTerminalTitleSequence("13-Custom-CLI-Normal"),
230
- buildTerminalTitleSequence("13-Custom-CLI-Normal"),
231
- buildTerminalTitleSequence("13-Custom-CLI-Normal"),
232
- ]);
233
- });
234
-
235
- test("writeGuardedTerminalOutput strips external title OSC and preserves SGR", () => {
236
- const writes: string[] = [];
237
- const result = writeGuardedTerminalOutput(
238
- (chunk) => {
239
- writes.push(chunk);
240
- return true;
241
- },
242
- "start\x1b]0;C:\\WINDOWS\\system\x07middle\x1b[32mok\x1b[0mend",
243
- { source: "test", stream: "stdout", origin: "child" },
244
- );
245
-
246
- assert.equal(result, true);
247
- assert.deepEqual(writes, ["startmiddle\x1b[32mok\x1b[0mend"]);
248
- });
249
-
250
- test("setTerminalTitle force option bypasses dedup", () => {
251
- const writes: string[] = [];
252
- __resetTerminalTitleCache();
253
-
254
- setTerminalTitle("Codexa", { write: (chunk) => writes.push(chunk) });
255
- setTerminalTitle("Codexa", { force: true, write: (chunk) => writes.push(chunk) });
256
- setTerminalTitle("Codexa", { force: true, write: (chunk) => writes.push(chunk) });
257
-
258
- assert.equal(writes.length, 3);
259
- writes.forEach((w) => assert.equal(w, buildTerminalTitleSequence("Codexa")));
260
- });
261
-
262
- test("beginColdStartSequence writes immediately then retries", async () => {
263
- const writes: string[] = [];
264
- __resetTerminalTitleCache();
265
-
266
- const cancel = beginColdStartSequence("Codexa", { write: (chunk) => writes.push(chunk) });
267
-
268
- assert.equal(writes.length, 1, "should write immediately");
269
-
270
- await sleep(60);
271
- assert.equal(writes.length, 2, "should have retried at 50ms");
272
-
273
- cancel();
274
- await sleep(300);
275
- assert.equal(writes.length, 2, "should not have retried further after cancel");
276
- });
277
-
278
- test("startup guard reasserts intended title until cancelled", async () => {
279
- const writes: string[] = [];
280
- __resetTerminalTitleCache();
281
-
282
- setIntendedTerminalTitle("13-Custom-CLI-Normal", {
283
- force: true,
284
- write: (chunk) => writes.push(chunk),
285
- });
286
- const cancel = startTerminalTitleStartupGuard({
287
- intervalMs: 10,
288
- durationMs: 100,
289
- write: (chunk) => writes.push(chunk),
290
- });
291
-
292
- await sleep(25);
293
- cancel();
294
- const writesAfterCancel = writes.length;
295
- await sleep(25);
296
-
297
- assert.ok(writesAfterCancel >= 3, `expected guard to reassert title, got ${writesAfterCancel} writes`);
298
- assert.equal(writes.length, writesAfterCancel);
299
- assert.ok(writes.every((chunk) => chunk === buildTerminalTitleSequence("13-Custom-CLI-Normal")));
300
- });
301
-
302
- test("stripTerminalTitleSequences handles very long unterminated OSC without hanging", () => {
303
- const long = "\x1b]0;" + "A".repeat(100_000);
304
- const start = Date.now();
305
- const result = stripTerminalTitleSequences(long);
306
- assert.ok(Date.now() - start < 100, "must complete in under 100 ms");
307
- assert.ok(result.includes("\x1b]0;"), "unterminated sequence passes through unchanged");
308
- });
309
-
310
- test("stripTerminalTitleSequences strips OSC sequence with empty title", () => {
311
- assert.equal(stripTerminalTitleSequences("pre\x1b]0;\x07post"), "prepost");
312
- assert.equal(stripTerminalTitleSequences("pre\x1b]2;\x1b\\post"), "prepost");
313
- });
314
-
315
- test("createTerminalTitleSequenceStripper handles OSC split across chunks with ST terminator", () => {
316
- const stripper = createTerminalTitleSequenceStripper({ source: "test", stream: "stdout", origin: "child" });
317
- assert.equal(stripper.process("hello\x1b]2;MyTitle"), "hello");
318
- assert.equal(stripper.process("\x1b\\world"), "world");
319
- assert.equal(stripper.flush(), "");
320
- });
321
-
322
- test("traceTerminalTitleSequences does not hang on crafted adversarial input", () => {
323
- const crafted = "\x1b]0;" + "X".repeat(10_000) + "\x1b]2;" + "Y".repeat(10_000);
324
- const start = Date.now();
325
- const found = traceTerminalTitleSequences(crafted, { source: "test", stream: "stdout", origin: "child" });
326
- assert.ok(Date.now() - start < 100, "must complete in under 100 ms");
327
- assert.equal(found, false, "no complete sequences in adversarial input");
328
- });
@@ -1,194 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import {
4
- CODEXA_NPM_REGISTRY_URL,
5
- CODEXA_UPDATE_COMMAND,
6
- checkForUpdates,
7
- compareSemver,
8
- formatUpdateInstructions,
9
- isNewerVersion,
10
- type NpmRegistryMetadata,
11
- } from "./updateCheck.js";
12
- import { isCacheValid, type UpdateCheckCache } from "../config/updateCheckCache.js";
13
-
14
- function metadata(version: string): NpmRegistryMetadata {
15
- return { "dist-tags": { latest: version } };
16
- }
17
-
18
- test("checkForUpdates returns update-available when installed version is lower than npm latest", async () => {
19
- const result = await checkForUpdates(
20
- {},
21
- {
22
- currentVersion: "1.0.1",
23
- fetchNpmMetadataFn: async (url) => {
24
- assert.equal(url, CODEXA_NPM_REGISTRY_URL);
25
- return metadata("1.0.2");
26
- },
27
- },
28
- );
29
-
30
- assert.equal(result.status, "update-available");
31
- assert.equal(result.currentVersion, "1.0.1");
32
- assert.equal(result.latestVersion, "1.0.2");
33
- });
34
-
35
- test("checkForUpdates returns up-to-date when installed version equals npm latest", async () => {
36
- const result = await checkForUpdates(
37
- {},
38
- {
39
- currentVersion: "1.0.2",
40
- fetchNpmMetadataFn: async () => metadata("1.0.2"),
41
- },
42
- );
43
-
44
- assert.equal(result.status, "up-to-date");
45
- });
46
-
47
- test("checkForUpdates does not show update available when installed version is higher than npm latest", async () => {
48
- const result = await checkForUpdates(
49
- {},
50
- {
51
- currentVersion: "1.0.3",
52
- fetchNpmMetadataFn: async () => metadata("1.0.2"),
53
- },
54
- );
55
-
56
- assert.equal(result.status, "up-to-date");
57
- });
58
-
59
- test("checkForUpdates returns error status instead of throwing when npm request fails", async () => {
60
- const result = await checkForUpdates(
61
- {},
62
- {
63
- currentVersion: "1.0.1",
64
- fetchNpmMetadataFn: async () => {
65
- throw new Error("network unavailable");
66
- },
67
- },
68
- );
69
-
70
- assert.equal(result.status, "error");
71
- assert.match(result.errorMessage ?? "", /network unavailable/);
72
- });
73
-
74
- test("checkForUpdates returns error when npm latest is missing", async () => {
75
- const result = await checkForUpdates(
76
- {},
77
- {
78
- currentVersion: "1.0.1",
79
- fetchNpmMetadataFn: async () => ({ "dist-tags": {} }),
80
- },
81
- );
82
-
83
- assert.equal(result.status, "error");
84
- assert.match(result.errorMessage ?? "", /dist-tags\.latest/);
85
- });
86
-
87
- test("checkForUpdates returns unknown immediately when enabled=false", async () => {
88
- let called = false;
89
- const result = await checkForUpdates(
90
- { enabled: false },
91
- {
92
- currentVersion: "1.0.1",
93
- fetchNpmMetadataFn: async () => {
94
- called = true;
95
- return metadata("1.0.2");
96
- },
97
- },
98
- );
99
-
100
- assert.equal(result.status, "unknown");
101
- assert.equal(called, false, "should not call npm when disabled");
102
- });
103
-
104
- test("semver comparison handles numeric and prerelease ordering", () => {
105
- assert.equal(isNewerVersion("1.0.10", "1.0.2"), true);
106
- assert.equal(isNewerVersion("1.0.2", "1.0.10"), false);
107
- assert.equal(compareSemver("1.0.2", "1.0.2"), 0);
108
- assert.equal(isNewerVersion("1.0.2", "1.0.2-beta.1"), true);
109
- assert.equal(isNewerVersion("1.0.2-beta.1", "1.0.2"), false);
110
- });
111
-
112
- test("isCacheValid returns true when cache is within the interval", () => {
113
- const cache: UpdateCheckCache = {
114
- lastChecked: Date.now() - 1000 * 60 * 30,
115
- currentVersion: "1.0.1",
116
- latestVersion: "1.0.1",
117
- updateAvailable: false,
118
- };
119
- assert.equal(isCacheValid(cache, 6), true);
120
- });
121
-
122
- test("isCacheValid returns false when cache is older than the interval", () => {
123
- const cache: UpdateCheckCache = {
124
- lastChecked: Date.now() - 1000 * 60 * 60 * 7,
125
- currentVersion: "1.0.1",
126
- latestVersion: "1.0.1",
127
- updateAvailable: false,
128
- };
129
- assert.equal(isCacheValid(cache, 6), false);
130
- });
131
-
132
- test("formatUpdateInstructions formats update-available npm status", () => {
133
- const result = formatUpdateInstructions({
134
- status: "update-available",
135
- currentVersion: "1.0.1",
136
- latestVersion: "1.0.2",
137
- checkedAt: Date.now(),
138
- });
139
-
140
- assert.match(result, /Current installed version: 1\.0\.1/);
141
- assert.match(result, /npm latest version:\s+1\.0\.2/);
142
- assert.match(result, /Update available: Codexa 1\.0\.2 is available\. You are using 1\.0\.1\./);
143
- assert.match(result, new RegExp(`Run: ${CODEXA_UPDATE_COMMAND.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
144
- });
145
-
146
- test("formatUpdateInstructions formats up-to-date npm status", () => {
147
- const result = formatUpdateInstructions({
148
- status: "up-to-date",
149
- currentVersion: "1.0.2",
150
- latestVersion: "1.0.2",
151
- checkedAt: Date.now(),
152
- });
153
-
154
- assert.match(result, /Already up to date/);
155
- assert.match(result, /npm install -g @golba98\/codexa@latest/);
156
- });
157
-
158
- test("formatUpdateInstructions formats manual npm errors", () => {
159
- const result = formatUpdateInstructions({
160
- status: "error",
161
- currentVersion: "1.0.1",
162
- latestVersion: null,
163
- errorMessage: "Connection timed out",
164
- checkedAt: Date.now(),
165
- });
166
-
167
- assert.match(result, /Error checking npm update status: Connection timed out/);
168
- });
169
-
170
- test("/update check path bypasses cache by performing a fresh npm check", async () => {
171
- const validCache: UpdateCheckCache = {
172
- lastChecked: Date.now(),
173
- currentVersion: "1.0.1",
174
- latestVersion: "1.0.1",
175
- updateAvailable: false,
176
- };
177
- assert.equal(isCacheValid(validCache, 6), true);
178
-
179
- let calls = 0;
180
- const result = await checkForUpdates(
181
- { enabled: true },
182
- {
183
- currentVersion: validCache.currentVersion,
184
- fetchNpmMetadataFn: async () => {
185
- calls += 1;
186
- return metadata("1.0.2");
187
- },
188
- },
189
- );
190
-
191
- assert.equal(calls, 1);
192
- assert.equal(result.status, "update-available");
193
- assert.equal(result.latestVersion, "1.0.2");
194
- });
@@ -1,172 +0,0 @@
1
- import { APP_VERSION } from "../config/settings.js";
2
-
3
- export type UpdateStatus = "up-to-date" | "update-available" | "unknown" | "error";
4
-
5
- export interface UpdateCheckResult {
6
- status: UpdateStatus;
7
- currentVersion: string;
8
- latestVersion: string | null;
9
- errorMessage?: string;
10
- checkedAt: number;
11
- }
12
-
13
- export interface NpmRegistryMetadata {
14
- "dist-tags"?: {
15
- latest?: unknown;
16
- };
17
- }
18
-
19
- export interface UpdateCheckOverrides {
20
- fetchNpmMetadataFn?: (url: string, init: RequestInit) => Promise<NpmRegistryMetadata>;
21
- currentVersion?: string;
22
- now?: () => number;
23
- }
24
-
25
- export const CODEXA_NPM_PACKAGE = "@golba98/codexa";
26
- export const CODEXA_NPM_REGISTRY_URL = "https://registry.npmjs.org/@golba98%2Fcodexa";
27
- export const CODEXA_UPDATE_COMMAND = "npm install -g @golba98/codexa@latest";
28
-
29
- const REMOTE_TIMEOUT_MS = 3000;
30
-
31
- interface ParsedSemver {
32
- major: number;
33
- minor: number;
34
- patch: number;
35
- prerelease: string[];
36
- }
37
-
38
- function parseSemver(version: string): ParsedSemver | null {
39
- const match = version.trim().match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);
40
- if (!match) return null;
41
-
42
- return {
43
- major: Number(match[1]),
44
- minor: Number(match[2]),
45
- patch: Number(match[3]),
46
- prerelease: match[4]?.split(".") ?? [],
47
- };
48
- }
49
-
50
- function comparePrerelease(left: string[], right: string[]): number {
51
- if (left.length === 0 && right.length === 0) return 0;
52
- if (left.length === 0) return 1;
53
- if (right.length === 0) return -1;
54
-
55
- const max = Math.max(left.length, right.length);
56
- for (let index = 0; index < max; index += 1) {
57
- const a = left[index];
58
- const b = right[index];
59
- if (a === undefined) return -1;
60
- if (b === undefined) return 1;
61
- if (a === b) continue;
62
-
63
- const aNumeric = /^\d+$/.test(a);
64
- const bNumeric = /^\d+$/.test(b);
65
- if (aNumeric && bNumeric) return Number(a) > Number(b) ? 1 : -1;
66
- if (aNumeric) return -1;
67
- if (bNumeric) return 1;
68
- return a > b ? 1 : -1;
69
- }
70
-
71
- return 0;
72
- }
73
-
74
- export function compareSemver(leftVersion: string, rightVersion: string): number {
75
- const left = parseSemver(leftVersion);
76
- const right = parseSemver(rightVersion);
77
- if (!left || !right) {
78
- throw new Error(`Invalid semver version: ${!left ? leftVersion : rightVersion}`);
79
- }
80
-
81
- for (const key of ["major", "minor", "patch"] as const) {
82
- if (left[key] !== right[key]) return left[key] > right[key] ? 1 : -1;
83
- }
84
-
85
- return comparePrerelease(left.prerelease, right.prerelease);
86
- }
87
-
88
- export function isNewerVersion(latestVersion: string, currentVersion: string): boolean {
89
- return compareSemver(latestVersion, currentVersion) > 0;
90
- }
91
-
92
- async function fetchNpmMetadata(url: string, init: RequestInit): Promise<NpmRegistryMetadata> {
93
- const res = await fetch(url, init);
94
- if (!res.ok) {
95
- throw new Error(`npm registry responded with HTTP ${res.status}`);
96
- }
97
- return await res.json() as NpmRegistryMetadata;
98
- }
99
-
100
- export async function getNpmLatestVersion(
101
- fetchMetadata: (url: string, init: RequestInit) => Promise<NpmRegistryMetadata> = fetchNpmMetadata,
102
- ): Promise<string> {
103
- const controller = new AbortController();
104
- const timer = setTimeout(() => controller.abort(), REMOTE_TIMEOUT_MS);
105
- try {
106
- const data = await fetchMetadata(CODEXA_NPM_REGISTRY_URL, {
107
- signal: controller.signal,
108
- headers: { "User-Agent": "Codexa-Update-Checker/1.0" },
109
- });
110
- const latest = data?.["dist-tags"]?.latest;
111
- if (typeof latest !== "string" || !latest.trim()) {
112
- throw new Error("npm registry response did not include dist-tags.latest");
113
- }
114
- return latest.trim();
115
- } finally {
116
- clearTimeout(timer);
117
- }
118
- }
119
-
120
- export async function checkForUpdates(
121
- opts?: { enabled?: boolean },
122
- overrides?: UpdateCheckOverrides,
123
- ): Promise<UpdateCheckResult> {
124
- const now = overrides?.now ?? Date.now;
125
- const currentVersion = overrides?.currentVersion ?? APP_VERSION;
126
-
127
- if (opts?.enabled === false) {
128
- return { status: "unknown", currentVersion, latestVersion: null, checkedAt: now() };
129
- }
130
-
131
- try {
132
- const latestVersion = await getNpmLatestVersion(overrides?.fetchNpmMetadataFn);
133
- return {
134
- status: isNewerVersion(latestVersion, currentVersion) ? "update-available" : "up-to-date",
135
- currentVersion,
136
- latestVersion,
137
- checkedAt: now(),
138
- };
139
- } catch (err) {
140
- return {
141
- status: "error",
142
- currentVersion,
143
- latestVersion: null,
144
- errorMessage: err instanceof Error ? err.message : String(err),
145
- checkedAt: now(),
146
- };
147
- }
148
- }
149
-
150
- export function formatUpdateInstructions(result: UpdateCheckResult | null): string {
151
- const current = result?.currentVersion ?? APP_VERSION;
152
- const latest = result?.latestVersion ?? "unknown";
153
-
154
- let statusLine: string;
155
- if (result?.status === "update-available" && result.latestVersion) {
156
- statusLine = `Update available: Codexa ${result.latestVersion} is available. You are using ${current}.`;
157
- } else if (result?.status === "up-to-date") {
158
- statusLine = "Already up to date.";
159
- } else if (result?.status === "error") {
160
- statusLine = `Error checking npm update status: ${result.errorMessage || "unknown error"}`;
161
- } else {
162
- statusLine = "Status unknown - could not read npm latest version.";
163
- }
164
-
165
- return [
166
- `Current installed version: ${current}`,
167
- `npm latest version: ${latest}`,
168
- `Status: ${statusLine}`,
169
- "",
170
- `Run: ${CODEXA_UPDATE_COMMAND}`,
171
- ].join("\n");
172
- }