@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
@@ -19,6 +19,7 @@ const ANTHROPIC_MAX_TOKENS = 1024;
19
19
  const ANTHROPIC_TIMEOUT_MS = 120_000;
20
20
  const ANTHROPIC_AUTH_CHECK_TIMEOUT_MS = 10_000;
21
21
  const ANTHROPIC_ROUTE_VALIDATION_TIMEOUT_MS = 15_000;
22
+ const DISCOVERY_FAILURE_MESSAGE = "Claude Code model version discovery failed; using fallback aliases with unknown versions.";
22
23
  export const ANTHROPIC_ROUTE_SETUP_MESSAGE = "Anthropic/Claude is not configured for in-Codexa routing.\nSign in with Claude Code or set ANTHROPIC_API_KEY.";
23
24
  export { parseClaudeAuthStatus } from "./claudeCodeDiscovery.js";
24
25
 
@@ -498,6 +499,9 @@ export const anthropicRuntime: ProviderRuntime = {
498
499
  providerId: "anthropic",
499
500
  backendKind: getAnthropicRuntimeBackendKind(),
500
501
  models: getActiveAnthropicModels(),
502
+ message: (claudeCapabilityDiscovery?.modelSource ?? "fallback") === "fallback"
503
+ ? DISCOVERY_FAILURE_MESSAGE
504
+ : undefined,
501
505
  diagnostics: claudeCapabilityDiscovery ? {
502
506
  resolvedCommand: claudeCapabilityDiscovery.resolvedCommand,
503
507
  modelSource: claudeCapabilityDiscovery.modelSource,
@@ -534,7 +538,9 @@ export const anthropicRuntime: ProviderRuntime = {
534
538
  providerId: "anthropic",
535
539
  backendKind: getAnthropicRuntimeBackendKind(),
536
540
  models: discoveredAnthropicModels,
537
- message: `Refreshed Claude capabilities (${discovery.modelSource}).`,
541
+ message: discovery.modelSource === "fallback"
542
+ ? DISCOVERY_FAILURE_MESSAGE
543
+ : `Refreshed Claude capabilities (${discovery.modelSource}).`,
538
544
  diagnostics: {
539
545
  resolvedCommand: discovery.resolvedCommand,
540
546
  modelSource: discovery.modelSource,
@@ -0,0 +1,305 @@
1
+ import { runCommand } from "../process/CommandRunner.js";
2
+ import { sanitizeTerminalOutput } from "../terminal/terminalSanitize.js";
3
+ import type { ReasoningEffortCapability } from "../models/codexModelCapabilities.js";
4
+ import type { BackendRunHandlers } from "../providers/types.js";
5
+ import type {
6
+ ProviderBackendKind,
7
+ ProviderChatRequest,
8
+ ProviderModel,
9
+ ProviderModelDiscoveryResult,
10
+ ProviderRouteValidationResult,
11
+ ProviderRuntime,
12
+ } from "./types.js";
13
+ import {
14
+ resolveAgyExecutable,
15
+ resetAgyExecutableCacheForTests,
16
+ } from "../executables/antigravityExecutable.js";
17
+ import { buildSpawnSpec } from "../executables/executableResolver.js";
18
+
19
+ export { resetAgyExecutableCacheForTests };
20
+
21
+ const ANTIGRAVITY_TIMEOUT_MS = 120_000;
22
+ const ANTIGRAVITY_VALIDATION_TIMEOUT_MS = 10_000;
23
+ const ANTIGRAVITY_ROUTE_SETUP_MESSAGE =
24
+ "`agy` command not found. Install Antigravity CLI or set AGY_EXECUTABLE to the full path.";
25
+
26
+ export const ANTIGRAVITY_DEFAULT_MODEL_ID = "gemini-3.5-flash";
27
+ export const ANTIGRAVITY_DEFAULT_REASONING = "high";
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Effort levels for Antigravity Gemini models
31
+ // ---------------------------------------------------------------------------
32
+
33
+ const AGY_LOW: ReasoningEffortCapability = { id: "low", label: "Low", description: null };
34
+ const AGY_MEDIUM: ReasoningEffortCapability = { id: "medium", label: "Medium", description: null };
35
+ const AGY_HIGH: ReasoningEffortCapability = { id: "high", label: "High", description: null };
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // Model definitions
39
+ // ---------------------------------------------------------------------------
40
+
41
+ export const ANTIGRAVITY_MODELS: readonly ProviderModel[] = [
42
+ {
43
+ id: "gemini-3.5-flash",
44
+ modelId: "gemini-3.5-flash",
45
+ label: "Gemini 3.5 Flash",
46
+ description: "Antigravity-routed Gemini 3.5 Flash. Select effort with ←/→.",
47
+ defaultReasoningLevel: "high",
48
+ supportedReasoningLevels: [AGY_LOW, AGY_MEDIUM, AGY_HIGH],
49
+ source: "fallback",
50
+ },
51
+ {
52
+ id: "gemini-3.1-pro",
53
+ modelId: "gemini-3.1-pro",
54
+ label: "Gemini 3.1 Pro",
55
+ description: "Antigravity-routed Gemini 3.1 Pro. Select effort with ←/→.",
56
+ defaultReasoningLevel: "high",
57
+ supportedReasoningLevels: [AGY_LOW, AGY_HIGH],
58
+ source: "fallback",
59
+ },
60
+ {
61
+ id: "claude-sonnet-4-6-think",
62
+ modelId: "claude-sonnet-4-6-think",
63
+ label: "Claude Sonnet 4.6 (Thinking)",
64
+ description: "Antigravity-routed Claude Sonnet 4.6 with extended thinking.",
65
+ defaultReasoningLevel: null,
66
+ supportedReasoningLevels: null,
67
+ source: "fallback",
68
+ },
69
+ {
70
+ id: "claude-opus-4-6-think",
71
+ modelId: "claude-opus-4-6-think",
72
+ label: "Claude Opus 4.6 (Thinking)",
73
+ description: "Antigravity-routed Claude Opus 4.6 with extended thinking.",
74
+ defaultReasoningLevel: null,
75
+ supportedReasoningLevels: null,
76
+ source: "fallback",
77
+ },
78
+ {
79
+ id: "gpt-oss-120b",
80
+ modelId: "gpt-oss-120b",
81
+ label: "GPT-OSS 120B",
82
+ description: "Antigravity-routed GPT-OSS 120B.",
83
+ defaultReasoningLevel: null,
84
+ supportedReasoningLevels: null,
85
+ source: "fallback",
86
+ },
87
+ ];
88
+
89
+ // ---------------------------------------------------------------------------
90
+ // AGY_MODEL env mapping
91
+ // ---------------------------------------------------------------------------
92
+
93
+ /**
94
+ * Maps Codexa model IDs to the AGY_MODEL env value passed to the agy subprocess.
95
+ *
96
+ * Verified:
97
+ * gemini-3.5-flash → "gemini-3.5-flash" (confirmed via: AGY_MODEL=gemini-3.5-flash agy -p "say hello back")
98
+ *
99
+ * Unverified (same pattern, not independently smoke-tested):
100
+ * gemini-3.1-pro → "gemini-3.1-pro"
101
+ */
102
+ const AGY_MODEL_ENV_MAP: Readonly<Record<string, string>> = {
103
+ "gemini-3.5-flash": "gemini-3.5-flash",
104
+ "gemini-3.1-pro": "gemini-3.1-pro",
105
+ };
106
+
107
+ export function getAgyModelEnvValue(modelId: string): string | null {
108
+ return AGY_MODEL_ENV_MAP[modelId] ?? null;
109
+ }
110
+
111
+ export function buildAgyEnv(modelId: string, _reasoning?: string): NodeJS.ProcessEnv {
112
+ // _reasoning is stored in route state and surfaced in the footer UI, but agy
113
+ // has no verified CLI flag or env var for passing effort level to the subprocess.
114
+ // TODO: wire _reasoning here once Antigravity exposes a stable mechanism.
115
+ const envValue = getAgyModelEnvValue(modelId);
116
+ return envValue ? { ...process.env, AGY_MODEL: envValue } : { ...process.env };
117
+ }
118
+
119
+ export function getAntigravityModelLabel(modelId: string): string {
120
+ return ANTIGRAVITY_MODELS.find((m) => m.id === modelId)?.label ?? modelId;
121
+ }
122
+
123
+ // ---------------------------------------------------------------------------
124
+ // Legacy model ID migration
125
+ // ---------------------------------------------------------------------------
126
+
127
+ /**
128
+ * Migrates legacy compound Antigravity model IDs (from feat/antigravity-cli-provider)
129
+ * to the new family + reasoning format.
130
+ *
131
+ * Old IDs encoded effort in the model ID (e.g., "gemini-3.5-flash-high").
132
+ * New IDs use the base family ("gemini-3.5-flash") with reasoning stored separately.
133
+ */
134
+ export function migrateAntigravityLegacyModelId(modelId: string): { modelId: string; reasoning?: string } {
135
+ const legacy: Record<string, { modelId: string; reasoning?: string }> = {
136
+ "gemini-3.5-flash-high": { modelId: "gemini-3.5-flash", reasoning: "high" },
137
+ "gemini-3.5-flash-medium": { modelId: "gemini-3.5-flash", reasoning: "medium" },
138
+ "gemini-3.5-flash-low": { modelId: "gemini-3.5-flash", reasoning: "low" },
139
+ "gemini-3.1-pro-high": { modelId: "gemini-3.1-pro", reasoning: "high" },
140
+ "gemini-3.1-pro-low": { modelId: "gemini-3.1-pro", reasoning: "low" },
141
+ "gpt-oss-120b-medium": { modelId: "gpt-oss-120b" },
142
+ };
143
+ return legacy[modelId] ?? { modelId };
144
+ }
145
+
146
+ // ---------------------------------------------------------------------------
147
+ // Module-level state
148
+ // ---------------------------------------------------------------------------
149
+
150
+ let agyRouteValidated = false;
151
+ let resolvedAgyExecutable: string = "agy";
152
+
153
+ export function isAntigravityRouteConfigured(): boolean {
154
+ return agyRouteValidated;
155
+ }
156
+
157
+ export function resetAntigravityRouteValidationCacheForTests(): void {
158
+ agyRouteValidated = false;
159
+ resolvedAgyExecutable = "agy";
160
+ resetAgyExecutableCacheForTests();
161
+ }
162
+
163
+ // ---------------------------------------------------------------------------
164
+ // Route validation
165
+ // ---------------------------------------------------------------------------
166
+
167
+ export async function validateAntigravityRoute(options: {
168
+ cwd?: string;
169
+ configuredPath?: string | null;
170
+ runCommandImpl?: typeof runCommand;
171
+ platform?: NodeJS.Platform;
172
+ }): Promise<ProviderRouteValidationResult> {
173
+ let resolved: string;
174
+ try {
175
+ resolved = await resolveAgyExecutable({
176
+ cwd: options.cwd,
177
+ configuredPath: options.configuredPath,
178
+ runCommandImpl: options.runCommandImpl,
179
+ });
180
+ } catch {
181
+ return {
182
+ status: "not-configured",
183
+ providerId: "antigravity",
184
+ backendKind: "unavailable",
185
+ message: ANTIGRAVITY_ROUTE_SETUP_MESSAGE,
186
+ diagnostics: { resolvedCommand: null },
187
+ };
188
+ }
189
+
190
+ // Probe the binary to confirm it's actually installed. Running --help has no
191
+ // auth side effects and exits 0 when agy is present. buildSpawnSpec wraps
192
+ // .cmd/.bat shims in `cmd.exe /d /s /c call` on Windows (no-op elsewhere) so
193
+ // the probe can actually launch the resolved executable.
194
+ const runCommandImpl = options.runCommandImpl ?? runCommand;
195
+ const probeSpec = buildSpawnSpec(resolved, ["--help"], options.platform ?? process.platform);
196
+ const probe = runCommandImpl({
197
+ executable: probeSpec.executable,
198
+ args: probeSpec.args,
199
+ cwd: options.cwd ?? process.cwd(),
200
+ timeoutMs: ANTIGRAVITY_VALIDATION_TIMEOUT_MS,
201
+ });
202
+ const probeResult = await probe.result;
203
+
204
+ if (probeResult.status === "spawn_error") {
205
+ return {
206
+ status: "not-configured",
207
+ providerId: "antigravity",
208
+ backendKind: "unavailable",
209
+ message: ANTIGRAVITY_ROUTE_SETUP_MESSAGE,
210
+ diagnostics: { resolvedCommand: resolved },
211
+ };
212
+ }
213
+
214
+ resolvedAgyExecutable = resolved;
215
+ agyRouteValidated = true;
216
+
217
+ return {
218
+ status: "ready",
219
+ providerId: "antigravity",
220
+ backendKind: "antigravity-cli-auth",
221
+ message: `Antigravity CLI found at: ${resolved}`,
222
+ diagnostics: { resolvedCommand: resolved },
223
+ };
224
+ }
225
+
226
+ // ---------------------------------------------------------------------------
227
+ // run()
228
+ // ---------------------------------------------------------------------------
229
+
230
+ export function runAntigravityWithRunner(
231
+ request: ProviderChatRequest,
232
+ handlers: BackendRunHandlers,
233
+ runCommandImpl: typeof runCommand = runCommand,
234
+ executable: string = resolvedAgyExecutable,
235
+ platform: NodeJS.Platform = process.platform,
236
+ ): () => void {
237
+ const spawnSpec = buildSpawnSpec(executable, ["-p", request.prompt], platform);
238
+ const env = buildAgyEnv(request.route.modelId, request.route.reasoning);
239
+
240
+ const runner = runCommandImpl(
241
+ {
242
+ executable: spawnSpec.executable,
243
+ args: spawnSpec.args,
244
+ cwd: request.workspaceRoot,
245
+ env,
246
+ timeoutMs: ANTIGRAVITY_TIMEOUT_MS,
247
+ },
248
+ );
249
+
250
+ runner.result.then((result) => {
251
+ if (result.status === "canceled") return;
252
+
253
+ if (result.status !== "completed" || result.exitCode !== 0) {
254
+ const message = result.userMessage || result.stderr || "Antigravity CLI execution failed.";
255
+ handlers.onError(message, `agy command: ${JSON.stringify([spawnSpec.executable, ...spawnSpec.args])}`);
256
+ return;
257
+ }
258
+
259
+ const text = sanitizeTerminalOutput(result.stdout).trim();
260
+ if (text) {
261
+ handlers.onAssistantDelta?.(text);
262
+ }
263
+ handlers.onFinalAnswerObserved?.(text);
264
+ handlers.onResponse(text);
265
+ }).catch((error) => {
266
+ const message = error instanceof Error ? error.message : "Antigravity CLI execution failed.";
267
+ handlers.onError(message);
268
+ });
269
+
270
+ return runner.cancel;
271
+ }
272
+
273
+ // ---------------------------------------------------------------------------
274
+ // Runtime
275
+ // ---------------------------------------------------------------------------
276
+
277
+ export const antigravityRuntime: ProviderRuntime = {
278
+ providerId: "antigravity",
279
+ label: "Antigravity CLI",
280
+ modelPickerLabel: "Antigravity",
281
+ backendKind: "antigravity-cli-auth",
282
+ routeAvailable: true,
283
+ routeStatus: "Routes through the Antigravity CLI (`agy`) when installed.",
284
+ routeSetupMessage: ANTIGRAVITY_ROUTE_SETUP_MESSAGE,
285
+ launchAvailable: true,
286
+ isRouteConfigured: isAntigravityRouteConfigured,
287
+ validateRoute: async ({ workspaceRoot, antigravityCommandPath }) => validateAntigravityRoute({
288
+ cwd: workspaceRoot,
289
+ configuredPath: antigravityCommandPath ?? null,
290
+ }),
291
+ discoverModels: (): ProviderModelDiscoveryResult => ({
292
+ status: "ready",
293
+ providerId: "antigravity",
294
+ backendKind: "antigravity-cli-auth",
295
+ models: ANTIGRAVITY_MODELS,
296
+ }),
297
+ run: (request: ProviderChatRequest, handlers: BackendRunHandlers) => {
298
+ handlers.onProgress?.({
299
+ id: "antigravity-route",
300
+ source: "stdout",
301
+ text: "Starting Antigravity CLI",
302
+ });
303
+ return runAntigravityWithRunner(request, handlers);
304
+ },
305
+ };