@golba98/codexa 1.0.3 → 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.
- package/README.md +17 -18
- package/bin/codexa.js +62 -144
- package/package.json +4 -3
- package/src/app.tsx +533 -275
- package/src/commands/handler.ts +2 -2
- package/src/config/buildInfo.ts +2 -2
- package/src/config/layeredConfig.ts +1 -1
- package/src/config/runtimeConfig.ts +1 -1
- package/src/config/settings.ts +1 -1
- package/src/config/trustStore.ts +1 -1
- package/src/core/README.md +52 -0
- package/src/core/agent/loop.ts +282 -0
- package/src/core/agent/protocol.ts +211 -0
- package/src/core/agent/tools.ts +414 -0
- package/src/core/{codexExecArgs.ts → codex/codexExecArgs.ts} +2 -2
- package/src/core/{codexLaunch.ts → codex/codexLaunch.ts} +3 -3
- package/src/core/{codexPrompt.ts → codex/codexPrompt.ts} +3 -3
- package/src/core/debug/modelStateDebug.ts +34 -0
- package/src/core/executables/antigravityExecutable.ts +48 -0
- package/src/core/executables/executableResolver.ts +5 -1
- package/src/core/perf/renderDebug.ts +10 -6
- package/src/core/providerLauncher/registry.ts +30 -14
- package/src/core/providerLauncher/types.ts +11 -9
- package/src/core/providerLauncher/workspaceConfig.ts +41 -26
- package/src/core/providerRuntime/anthropic.ts +7 -1
- package/src/core/providerRuntime/antigravity.ts +305 -0
- package/src/core/providerRuntime/claudeCodeDiscovery.ts +268 -22
- package/src/core/providerRuntime/claudeCodeDiscoveryDebug.ts +55 -0
- package/src/core/providerRuntime/contextMetadata.ts +12 -24
- package/src/core/providerRuntime/local.ts +129 -51
- package/src/core/providerRuntime/models.ts +22 -11
- package/src/core/providerRuntime/registry.ts +58 -31
- package/src/core/providerRuntime/types.ts +19 -14
- package/src/core/providers/codexSubprocess.ts +2 -2
- package/src/core/providers/types.ts +1 -1
- package/src/core/{attachments.ts → shared/attachments.ts} +27 -4
- package/src/core/{cleanupFastFail.ts → shared/cleanupFastFail.ts} +1 -1
- package/src/core/{hollowResponseFormat.ts → shared/hollowResponseFormat.ts} +1 -1
- package/src/core/terminal/clearFrameBoundary.ts +814 -0
- package/src/core/terminal/frameLock.ts +109 -0
- package/src/core/terminal/inkRenderReset.ts +123 -0
- package/src/core/terminal/terminalControl.ts +22 -0
- package/src/core/terminal/terminalTitle.ts +16 -102
- package/src/core/{channel.ts → version/channel.ts} +1 -1
- package/src/core/{updateCheck.ts → version/updateCheck.ts} +10 -5
- package/src/core/{launchContext.ts → workspace/launchContext.ts} +9 -16
- package/src/core/{planStorage.ts → workspace/planStorage.ts} +2 -2
- package/src/core/{workspaceGuard.ts → workspace/workspaceGuard.ts} +97 -13
- package/src/headless/execRunner.ts +2 -2
- package/src/index.tsx +43 -89
- package/src/session/appSession.ts +10 -7
- package/src/session/chatLifecycle.ts +1 -1
- package/src/session/liveRenderScheduler.ts +1 -1
- package/src/session/types.ts +1 -1
- package/src/ui/AppShell.tsx +672 -706
- package/src/ui/AttachmentImportPanel.tsx +2 -2
- package/src/ui/BottomComposer.tsx +145 -144
- package/src/ui/ModelPickerScreen.tsx +216 -36
- package/src/ui/ModelReasoningPicker.tsx +1 -1
- package/src/ui/PlanReviewPanel.tsx +1 -1
- package/src/ui/ProviderPicker.tsx +735 -321
- package/src/ui/RuntimeStatusBar.tsx +108 -0
- package/src/ui/SelectionPanel.tsx +4 -0
- package/src/ui/SettingsPanel.tsx +1 -1
- package/src/ui/TextEntryPanel.tsx +1 -1
- package/src/ui/Timeline.tsx +1619 -1470
- package/src/ui/TopHeader.tsx +46 -30
- package/src/ui/TranscriptShell.tsx +322 -0
- package/src/ui/TurnGroup.tsx +2 -2
- package/src/ui/UpdateAvailableCard.tsx +3 -3
- package/src/ui/UpdatePromptPanel.tsx +16 -22
- package/src/ui/layout.ts +298 -24
- package/src/ui/layoutListWindow.ts +145 -0
- package/src/ui/logoVariants.ts +4 -8
- package/src/ui/runtimeDisplay.ts +15 -3
- package/src/ui/textLayout.ts +15 -4
- package/src/ui/timelineMeasure.ts +194 -122
- package/src/core/codex.ts +0 -124
- package/src/ui/StaticTranscriptItem.tsx +0 -56
- /package/src/core/{inputDebug.ts → debug/inputDebug.ts} +0 -0
- /package/src/core/{clipboard.ts → shared/clipboard.ts} +0 -0
- /package/src/core/{githubDiagnostics.ts → shared/githubDiagnostics.ts} +0 -0
- /package/src/core/{projectInstructions.ts → workspace/projectInstructions.ts} +0 -0
- /package/src/core/{workspaceActivity.ts → workspace/workspaceActivity.ts} +0 -0
- /package/src/core/{workspaceRoot.ts → workspace/workspaceRoot.ts} +0 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import type { ResolvedRuntimeConfig } from "../../config/runtimeConfig.js";
|
|
5
|
+
import { runShellCommand, summarizeCommandResult } from "../process/CommandRunner.js";
|
|
6
|
+
import { sanitizeTerminalOutput } from "../terminal/terminalSanitize.js";
|
|
7
|
+
import {
|
|
8
|
+
getShellWorkspaceGuardMessage,
|
|
9
|
+
isPathInsideAllowedRoots,
|
|
10
|
+
resolveWorkspacePath,
|
|
11
|
+
} from "../workspace/workspaceGuard.js";
|
|
12
|
+
import type { AgentToolName } from "./protocol.js";
|
|
13
|
+
|
|
14
|
+
export interface AgentToolContext {
|
|
15
|
+
workspaceRoot: string;
|
|
16
|
+
runtime: ResolvedRuntimeConfig;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AgentToolResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
tool: AgentToolName;
|
|
23
|
+
path?: string;
|
|
24
|
+
command?: string;
|
|
25
|
+
paths?: string[];
|
|
26
|
+
output?: string;
|
|
27
|
+
stdout?: string;
|
|
28
|
+
stderr?: string;
|
|
29
|
+
exitCode?: number | null;
|
|
30
|
+
durationMs?: number;
|
|
31
|
+
summary?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MAX_FILE_BYTES = 128 * 1024;
|
|
36
|
+
const MAX_OUTPUT_CHARS = 4_000;
|
|
37
|
+
const MAX_OUTPUT_LINES = 80;
|
|
38
|
+
const SHELL_TIMEOUT_MS = 30_000;
|
|
39
|
+
|
|
40
|
+
const DANGEROUS_SHELL_PATTERNS: RegExp[] = [
|
|
41
|
+
/\brm\s+-[^\n;|&]*r[f]?\b/i,
|
|
42
|
+
/\bsudo\b/i,
|
|
43
|
+
/\bdoas\b/i,
|
|
44
|
+
/\bdd\s+.*\bof=/i,
|
|
45
|
+
/\bmkfs(?:\.[a-z0-9]+)?\b/i,
|
|
46
|
+
/\bshutdown\b/i,
|
|
47
|
+
/\breboot\b/i,
|
|
48
|
+
/\bpoweroff\b/i,
|
|
49
|
+
/\bchmod\s+-R\s+777\b/i,
|
|
50
|
+
/:\(\)\s*\{\s*:\|:\s*&\s*\}\s*;/,
|
|
51
|
+
/>\s*\/dev\/(?:sd|hd|nvme|disk)/i,
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
function preview(text: string, maxChars = MAX_OUTPUT_CHARS): string {
|
|
55
|
+
const sanitized = sanitizeTerminalOutput(text);
|
|
56
|
+
return sanitized.length > maxChars ? `${sanitized.slice(0, maxChars)}\n...[truncated]` : sanitized;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function trimOutputLines(text: string, preferTail: boolean): string {
|
|
60
|
+
const sanitized = sanitizeTerminalOutput(text).replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
61
|
+
const lines = sanitized.split("\n");
|
|
62
|
+
if (lines.at(-1) === "") lines.pop();
|
|
63
|
+
if (lines.length <= MAX_OUTPUT_LINES) return sanitized;
|
|
64
|
+
const visible = preferTail ? lines.slice(-MAX_OUTPUT_LINES) : lines.slice(0, MAX_OUTPUT_LINES);
|
|
65
|
+
const hidden = lines.length - visible.length;
|
|
66
|
+
const marker = `[...${hidden} line${hidden === 1 ? "" : "s"} truncated; showing ${preferTail ? "last" : "first"} ${MAX_OUTPUT_LINES} lines...]`;
|
|
67
|
+
return preferTail
|
|
68
|
+
? [marker, ...visible].join("\n")
|
|
69
|
+
: [...visible, marker].join("\n");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function stringArg(args: Record<string, unknown>, key: string): string | null {
|
|
73
|
+
const value = args[key];
|
|
74
|
+
return typeof value === "string" && value.trim() ? value : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isReadOnly(runtime: ResolvedRuntimeConfig): boolean {
|
|
78
|
+
return runtime.policy.sandboxMode === "read-only";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function canWrite(runtime: ResolvedRuntimeConfig): boolean {
|
|
82
|
+
return runtime.policy.sandboxMode === "workspace-write"
|
|
83
|
+
|| runtime.policy.sandboxMode === "danger-full-access";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function relativeDisplay(workspaceRoot: string, absolutePath: string): string {
|
|
87
|
+
const relative = path.relative(workspaceRoot, absolutePath).split(path.sep).join("/");
|
|
88
|
+
return relative || ".";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function hasCargoManifest(workspaceRoot: string): boolean {
|
|
92
|
+
return existsSync(path.join(workspaceRoot, "Cargo.toml"));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function rustCommandGuard(command: string, context: AgentToolContext): string | null {
|
|
96
|
+
if (!hasCargoManifest(context.workspaceRoot)) return null;
|
|
97
|
+
const normalized = command.trim().replace(/\s+/g, " ");
|
|
98
|
+
const rustcMatch = /^rustc(?:\s+--?[^\s]+)*\s+([^\s]+\.rs)\b/.exec(normalized);
|
|
99
|
+
if (!rustcMatch) return null;
|
|
100
|
+
const target = rustcMatch[1]!;
|
|
101
|
+
const resolved = path.resolve(context.workspaceRoot, target);
|
|
102
|
+
const rootMain = path.join(context.workspaceRoot, "main.rs");
|
|
103
|
+
if (resolved !== rootMain || !existsSync(rootMain)) {
|
|
104
|
+
return "This workspace has Cargo.toml. Use `cargo check` to validate or `cargo run` to run instead of compiling a Rust source file directly with rustc.";
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function resolveAllowedPath(rawPath: string, context: AgentToolContext): { ok: true; absolutePath: string; relativePath: string } | { ok: false; error: string } {
|
|
110
|
+
if (!isPathInsideAllowedRoots(rawPath, context.workspaceRoot, context.runtime.policy.writableRoots)) {
|
|
111
|
+
return { ok: false, error: `Path is outside the workspace: ${rawPath}` };
|
|
112
|
+
}
|
|
113
|
+
const absolutePath = resolveWorkspacePath(rawPath, context.workspaceRoot);
|
|
114
|
+
return {
|
|
115
|
+
ok: true,
|
|
116
|
+
absolutePath,
|
|
117
|
+
relativePath: relativeDisplay(context.workspaceRoot, absolutePath),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function listFiles(args: Record<string, unknown>, context: AgentToolContext): Promise<AgentToolResult> {
|
|
122
|
+
const rawPath = stringArg(args, "path") ?? ".";
|
|
123
|
+
const resolved = resolveAllowedPath(rawPath, context);
|
|
124
|
+
if (!resolved.ok) return { success: false, tool: "list_files", path: rawPath, error: resolved.error };
|
|
125
|
+
|
|
126
|
+
const entries = await readdir(resolved.absolutePath, { withFileTypes: true });
|
|
127
|
+
const names = entries
|
|
128
|
+
.filter((entry) => ![".git", "node_modules", "dist", "build", "coverage"].includes(entry.name))
|
|
129
|
+
.map((entry) => `${entry.name}${entry.isDirectory() ? "/" : ""}`)
|
|
130
|
+
.sort();
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
tool: "list_files",
|
|
134
|
+
path: resolved.relativePath,
|
|
135
|
+
output: names.slice(0, 200).join("\n"),
|
|
136
|
+
summary: `Listed ${names.length} item${names.length === 1 ? "" : "s"}.`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function readFileTool(args: Record<string, unknown>, context: AgentToolContext): Promise<AgentToolResult> {
|
|
141
|
+
const rawPath = stringArg(args, "path");
|
|
142
|
+
if (!rawPath) return { success: false, tool: "read_file", error: "Missing path." };
|
|
143
|
+
const resolved = resolveAllowedPath(rawPath, context);
|
|
144
|
+
if (!resolved.ok) return { success: false, tool: "read_file", path: rawPath, error: resolved.error };
|
|
145
|
+
|
|
146
|
+
const fileStat = await stat(resolved.absolutePath);
|
|
147
|
+
if (fileStat.size > MAX_FILE_BYTES) {
|
|
148
|
+
return { success: false, tool: "read_file", path: resolved.relativePath, error: "File is too large to read through the agent tool." };
|
|
149
|
+
}
|
|
150
|
+
const content = await readFile(resolved.absolutePath, "utf8");
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
tool: "read_file",
|
|
154
|
+
path: resolved.relativePath,
|
|
155
|
+
output: content,
|
|
156
|
+
summary: `Read ${resolved.relativePath}.`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function writeFileTool(args: Record<string, unknown>, context: AgentToolContext): Promise<AgentToolResult> {
|
|
161
|
+
if (!canWrite(context.runtime)) {
|
|
162
|
+
return { success: false, tool: "write_file", error: "write_file is blocked by read-only runtime policy." };
|
|
163
|
+
}
|
|
164
|
+
const rawPath = stringArg(args, "path");
|
|
165
|
+
const content = stringArg(args, "content");
|
|
166
|
+
if (!rawPath) return { success: false, tool: "write_file", error: "Missing path." };
|
|
167
|
+
if (content === null) return { success: false, tool: "write_file", path: rawPath, error: "Missing content." };
|
|
168
|
+
const resolved = resolveAllowedPath(rawPath, context);
|
|
169
|
+
if (!resolved.ok) return { success: false, tool: "write_file", path: rawPath, error: resolved.error };
|
|
170
|
+
|
|
171
|
+
await mkdir(path.dirname(resolved.absolutePath), { recursive: true });
|
|
172
|
+
await writeFile(resolved.absolutePath, content, "utf8");
|
|
173
|
+
return {
|
|
174
|
+
success: true,
|
|
175
|
+
tool: "write_file",
|
|
176
|
+
path: resolved.relativePath,
|
|
177
|
+
paths: [resolved.relativePath],
|
|
178
|
+
summary: `Wrote ${resolved.relativePath}.`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function parseApplyPatchPaths(patch: string): string[] {
|
|
183
|
+
const paths: string[] = [];
|
|
184
|
+
for (const line of patch.split(/\r?\n/)) {
|
|
185
|
+
const marker = /^(?:\*\*\* (?:Add|Update|Delete) File:|--- a\/|\+\+\+ b\/)\s*(.+)$/.exec(line);
|
|
186
|
+
if (marker?.[1] && marker[1] !== "/dev/null") {
|
|
187
|
+
paths.push(marker[1].trim());
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return [...new Set(paths)];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function applyPatchFormatToContent(before: string, patchLines: string[]): string {
|
|
194
|
+
let contentLines = before.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
195
|
+
if (contentLines.at(-1) === "") contentLines = contentLines.slice(0, -1);
|
|
196
|
+
let cursor = 0;
|
|
197
|
+
let index = 0;
|
|
198
|
+
|
|
199
|
+
while (index < patchLines.length) {
|
|
200
|
+
if (!patchLines[index]?.startsWith("@@")) {
|
|
201
|
+
index += 1;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
index += 1;
|
|
205
|
+
const oldLines: string[] = [];
|
|
206
|
+
const newLines: string[] = [];
|
|
207
|
+
while (index < patchLines.length && !patchLines[index]?.startsWith("@@") && !patchLines[index]?.startsWith("*** ")) {
|
|
208
|
+
const line = patchLines[index] ?? "";
|
|
209
|
+
if (line.startsWith(" ")) {
|
|
210
|
+
oldLines.push(line.slice(1));
|
|
211
|
+
newLines.push(line.slice(1));
|
|
212
|
+
} else if (line.startsWith("-")) {
|
|
213
|
+
oldLines.push(line.slice(1));
|
|
214
|
+
} else if (line.startsWith("+")) {
|
|
215
|
+
newLines.push(line.slice(1));
|
|
216
|
+
}
|
|
217
|
+
index += 1;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let matchAt = -1;
|
|
221
|
+
for (let candidate = cursor; candidate <= contentLines.length - oldLines.length; candidate += 1) {
|
|
222
|
+
const matches = oldLines.every((line, offset) => contentLines[candidate + offset] === line);
|
|
223
|
+
if (matches) {
|
|
224
|
+
matchAt = candidate;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (matchAt < 0) {
|
|
229
|
+
throw new Error("Patch context did not match the target file.");
|
|
230
|
+
}
|
|
231
|
+
contentLines.splice(matchAt, oldLines.length, ...newLines);
|
|
232
|
+
cursor = matchAt + newLines.length;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return `${contentLines.join("\n")}\n`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function applyPatchFormat(patch: string, context: AgentToolContext): Promise<AgentToolResult> {
|
|
239
|
+
const lines = patch.split(/\r?\n/);
|
|
240
|
+
const changedPaths: string[] = [];
|
|
241
|
+
let index = 0;
|
|
242
|
+
|
|
243
|
+
while (index < lines.length) {
|
|
244
|
+
const add = /^\*\*\* Add File:\s*(.+)$/.exec(lines[index] ?? "");
|
|
245
|
+
const update = /^\*\*\* Update File:\s*(.+)$/.exec(lines[index] ?? "");
|
|
246
|
+
const del = /^\*\*\* Delete File:\s*(.+)$/.exec(lines[index] ?? "");
|
|
247
|
+
|
|
248
|
+
if (add) {
|
|
249
|
+
const resolved = resolveAllowedPath(add[1]!, context);
|
|
250
|
+
if (!resolved.ok) return { success: false, tool: "apply_patch", path: add[1], error: resolved.error };
|
|
251
|
+
index += 1;
|
|
252
|
+
const content: string[] = [];
|
|
253
|
+
while (index < lines.length && !lines[index]?.startsWith("*** ")) {
|
|
254
|
+
const line = lines[index] ?? "";
|
|
255
|
+
if (line.startsWith("+")) content.push(line.slice(1));
|
|
256
|
+
index += 1;
|
|
257
|
+
}
|
|
258
|
+
await mkdir(path.dirname(resolved.absolutePath), { recursive: true });
|
|
259
|
+
await writeFile(resolved.absolutePath, `${content.join("\n")}\n`, "utf8");
|
|
260
|
+
changedPaths.push(resolved.relativePath);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (update) {
|
|
265
|
+
const resolved = resolveAllowedPath(update[1]!, context);
|
|
266
|
+
if (!resolved.ok) return { success: false, tool: "apply_patch", path: update[1], error: resolved.error };
|
|
267
|
+
index += 1;
|
|
268
|
+
const patchLines: string[] = [];
|
|
269
|
+
while (index < lines.length && !/^\*\*\* (?:Add|Update|Delete|End)/.test(lines[index] ?? "")) {
|
|
270
|
+
patchLines.push(lines[index] ?? "");
|
|
271
|
+
index += 1;
|
|
272
|
+
}
|
|
273
|
+
const before = await readFile(resolved.absolutePath, "utf8");
|
|
274
|
+
await writeFile(resolved.absolutePath, applyPatchFormatToContent(before, patchLines), "utf8");
|
|
275
|
+
changedPaths.push(resolved.relativePath);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (del) {
|
|
280
|
+
const resolved = resolveAllowedPath(del[1]!, context);
|
|
281
|
+
if (!resolved.ok) return { success: false, tool: "apply_patch", path: del[1], error: resolved.error };
|
|
282
|
+
await rm(resolved.absolutePath, { force: true });
|
|
283
|
+
changedPaths.push(resolved.relativePath);
|
|
284
|
+
index += 1;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
index += 1;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (changedPaths.length === 0) {
|
|
292
|
+
return { success: false, tool: "apply_patch", error: "No supported patch operations were found." };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
success: true,
|
|
297
|
+
tool: "apply_patch",
|
|
298
|
+
paths: changedPaths,
|
|
299
|
+
summary: `Patched ${changedPaths.join(", ")}.`,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function applyPatchTool(args: Record<string, unknown>, context: AgentToolContext): Promise<AgentToolResult> {
|
|
304
|
+
if (!canWrite(context.runtime)) {
|
|
305
|
+
return { success: false, tool: "apply_patch", error: "apply_patch is blocked by read-only runtime policy." };
|
|
306
|
+
}
|
|
307
|
+
const patch = stringArg(args, "patch");
|
|
308
|
+
if (!patch) return { success: false, tool: "apply_patch", error: "Missing patch." };
|
|
309
|
+
|
|
310
|
+
const explicitPath = stringArg(args, "path");
|
|
311
|
+
const paths = explicitPath ? [explicitPath] : parseApplyPatchPaths(patch);
|
|
312
|
+
for (const patchPath of paths) {
|
|
313
|
+
const resolved = resolveAllowedPath(patchPath, context);
|
|
314
|
+
if (!resolved.ok) return { success: false, tool: "apply_patch", path: patchPath, error: resolved.error };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!patch.trimStart().startsWith("*** Begin Patch")) {
|
|
318
|
+
return { success: false, tool: "apply_patch", error: "Only *** Begin Patch format is supported by this agent tool." };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return applyPatchFormat(patch, context);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function runShellTool(args: Record<string, unknown>, context: AgentToolContext): Promise<AgentToolResult> {
|
|
325
|
+
if (!canWrite(context.runtime) || isReadOnly(context.runtime)) {
|
|
326
|
+
return { success: false, tool: "run_shell", error: "run_shell is blocked by read-only runtime policy." };
|
|
327
|
+
}
|
|
328
|
+
const command = stringArg(args, "command");
|
|
329
|
+
if (!command) return { success: false, tool: "run_shell", error: "Missing command." };
|
|
330
|
+
|
|
331
|
+
if (DANGEROUS_SHELL_PATTERNS.some((pattern) => pattern.test(command))) {
|
|
332
|
+
return { success: false, tool: "run_shell", command, error: "Shell command blocked as dangerous." };
|
|
333
|
+
}
|
|
334
|
+
const rustGuard = rustCommandGuard(command, context);
|
|
335
|
+
if (rustGuard) {
|
|
336
|
+
return { success: false, tool: "run_shell", command, exitCode: null, durationMs: 0, stdout: "", stderr: "", error: rustGuard };
|
|
337
|
+
}
|
|
338
|
+
const workspaceGuard = getShellWorkspaceGuardMessage(command, context.workspaceRoot, context.runtime.policy.writableRoots);
|
|
339
|
+
if (workspaceGuard) {
|
|
340
|
+
return { success: false, tool: "run_shell", command, error: workspaceGuard };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const runner = runShellCommand(command, {
|
|
344
|
+
cwd: context.workspaceRoot,
|
|
345
|
+
timeoutMs: SHELL_TIMEOUT_MS,
|
|
346
|
+
});
|
|
347
|
+
const cancel = () => runner.cancel();
|
|
348
|
+
context.signal?.addEventListener("abort", cancel, { once: true });
|
|
349
|
+
try {
|
|
350
|
+
const result = await runner.result;
|
|
351
|
+
const success = result.status === "completed" && result.exitCode === 0;
|
|
352
|
+
const stdout = trimOutputLines(result.stdout, !success);
|
|
353
|
+
const stderr = trimOutputLines(result.stderr, !success);
|
|
354
|
+
const output = preview([stdout, stderr].filter(Boolean).join("\n"));
|
|
355
|
+
return {
|
|
356
|
+
success,
|
|
357
|
+
tool: "run_shell",
|
|
358
|
+
command,
|
|
359
|
+
exitCode: result.exitCode,
|
|
360
|
+
durationMs: result.durationMs,
|
|
361
|
+
stdout,
|
|
362
|
+
stderr,
|
|
363
|
+
output,
|
|
364
|
+
summary: summarizeCommandResult(command, result),
|
|
365
|
+
error: success ? undefined : result.userMessage,
|
|
366
|
+
};
|
|
367
|
+
} finally {
|
|
368
|
+
context.signal?.removeEventListener("abort", cancel);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function getWorkspaceInfo(context: AgentToolContext): Promise<AgentToolResult> {
|
|
373
|
+
return {
|
|
374
|
+
success: true,
|
|
375
|
+
tool: "get_workspace_info",
|
|
376
|
+
path: ".",
|
|
377
|
+
output: JSON.stringify({
|
|
378
|
+
workspaceRoot: context.workspaceRoot,
|
|
379
|
+
sandboxMode: context.runtime.policy.sandboxMode,
|
|
380
|
+
writableRoots: context.runtime.policy.writableRoots,
|
|
381
|
+
packageJson: existsSync(path.join(context.workspaceRoot, "package.json")),
|
|
382
|
+
}),
|
|
383
|
+
summary: "Returned workspace info.",
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export async function executeAgentTool(
|
|
388
|
+
name: AgentToolName,
|
|
389
|
+
args: Record<string, unknown>,
|
|
390
|
+
context: AgentToolContext,
|
|
391
|
+
): Promise<AgentToolResult> {
|
|
392
|
+
try {
|
|
393
|
+
switch (name) {
|
|
394
|
+
case "list_files":
|
|
395
|
+
return await listFiles(args, context);
|
|
396
|
+
case "read_file":
|
|
397
|
+
return await readFileTool(args, context);
|
|
398
|
+
case "write_file":
|
|
399
|
+
return await writeFileTool(args, context);
|
|
400
|
+
case "apply_patch":
|
|
401
|
+
return await applyPatchTool(args, context);
|
|
402
|
+
case "run_shell":
|
|
403
|
+
return await runShellTool(args, context);
|
|
404
|
+
case "get_workspace_info":
|
|
405
|
+
return await getWorkspaceInfo(context);
|
|
406
|
+
}
|
|
407
|
+
} catch (error) {
|
|
408
|
+
return {
|
|
409
|
+
success: false,
|
|
410
|
+
tool: name,
|
|
411
|
+
error: error instanceof Error ? error.message : String(error),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ResolvedRuntimeConfig } from "
|
|
2
|
-
import type { CodexCliCapabilities } from "
|
|
1
|
+
import type { ResolvedRuntimeConfig } from "../../config/runtimeConfig.js";
|
|
2
|
+
import type { CodexCliCapabilities } from "../models/codexCapabilities.js";
|
|
3
3
|
|
|
4
4
|
export interface BuildCodexExecArgsOptions {
|
|
5
5
|
runtime: ResolvedRuntimeConfig;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { fileURLToPath } from "url";
|
|
2
2
|
import { buildCodexExecArgs, type BuildCodexExecArgsOptions, type BuildCodexExecArgsResult } from "./codexExecArgs.js";
|
|
3
|
-
import { getCodexCliCapabilities, type CodexCliCapabilities } from "
|
|
4
|
-
import { resolveCodexExecutable } from "
|
|
5
|
-
import * as perf from "
|
|
3
|
+
import { getCodexCliCapabilities, type CodexCliCapabilities } from "../models/codexCapabilities.js";
|
|
4
|
+
import { resolveCodexExecutable } from "../executables/codexExecutable.js";
|
|
5
|
+
import * as perf from "../perf/profiler.js";
|
|
6
6
|
|
|
7
7
|
// Assumed capability set when probeCapabilities is false — avoids a slow help-output probe on every run.
|
|
8
8
|
const MODERN_CODEX_CLI_CAPABILITIES: CodexCliCapabilities = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AvailableMode } from "
|
|
2
|
-
import type { ResolvedRuntimeConfig } from "
|
|
3
|
-
import type { ProjectInstructions } from "
|
|
1
|
+
import type { AvailableMode } from "../../config/settings.js";
|
|
2
|
+
import type { ResolvedRuntimeConfig } from "../../config/runtimeConfig.js";
|
|
3
|
+
import type { ProjectInstructions } from "../workspace/projectInstructions.js";
|
|
4
4
|
|
|
5
5
|
// ─── Write-intent detection ───────────────────────────────────────────────────
|
|
6
6
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
|
|
4
|
+
type ModelStateDebugDetails = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
let sequence = 0;
|
|
7
|
+
|
|
8
|
+
export function isModelStateDebugEnabled(): boolean {
|
|
9
|
+
return process.env.CODEXA_RENDER_DEBUG === "1" || process.env.CODEXA_DEBUG_MODEL_STATE === "1";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getModelStateDebugLogPath(): string {
|
|
13
|
+
return process.env.CODEXA_RENDER_DEBUG_FILE?.trim()
|
|
14
|
+
|| process.env.CODEXA_DEBUG_MODEL_STATE_LOG?.trim()
|
|
15
|
+
|| join(process.cwd(), ".codexa", "debug", "render-status.log");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function traceModelStateDebug(event: string, details: ModelStateDebugDetails = {}): void {
|
|
19
|
+
if (!isModelStateDebugEnabled()) return;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const entry = {
|
|
23
|
+
ts: new Date().toISOString(),
|
|
24
|
+
seq: ++sequence,
|
|
25
|
+
event,
|
|
26
|
+
...details,
|
|
27
|
+
};
|
|
28
|
+
const logPath = getModelStateDebugLogPath();
|
|
29
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
30
|
+
appendFileSync(logPath, `${JSON.stringify(entry)}\n`, "utf8");
|
|
31
|
+
} catch {
|
|
32
|
+
// Debug logging must never affect the TUI.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { runCommand } from "../process/CommandRunner.js";
|
|
2
|
+
import { resolveExecutable } from "./executableResolver.js";
|
|
3
|
+
|
|
4
|
+
type CommandRunner = typeof runCommand;
|
|
5
|
+
|
|
6
|
+
let cachedExecutable: string | null = null;
|
|
7
|
+
|
|
8
|
+
export function resetAgyExecutableCacheForTests(): void {
|
|
9
|
+
cachedExecutable = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the resolved Antigravity CLI executable (full path or bare name).
|
|
14
|
+
*
|
|
15
|
+
* Priority:
|
|
16
|
+
* 1. Configured path override (antigravityCommandPath)
|
|
17
|
+
* 2. AGY_EXECUTABLE env var
|
|
18
|
+
* 3. Windows PATH lookup for real files: agy.exe, agy.cmd, agy.bat, agy
|
|
19
|
+
* 4. Bare name fallback "agy" (Unix PATH resolution)
|
|
20
|
+
*/
|
|
21
|
+
export async function resolveAgyExecutable(options?: {
|
|
22
|
+
runCommandImpl?: CommandRunner;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
configuredPath?: string | null;
|
|
25
|
+
}): Promise<string> {
|
|
26
|
+
if (!options?.configuredPath && !options?.runCommandImpl && cachedExecutable !== null) {
|
|
27
|
+
return cachedExecutable;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const result = await resolveExecutable({
|
|
31
|
+
runCommandImpl: options?.runCommandImpl,
|
|
32
|
+
cwd: options?.cwd,
|
|
33
|
+
configuredPath: options?.configuredPath,
|
|
34
|
+
envOverrides: ["AGY_EXECUTABLE"],
|
|
35
|
+
commandNames: process.platform === "win32"
|
|
36
|
+
? ["agy.exe", "agy.cmd", "agy.bat", "agy"]
|
|
37
|
+
: ["agy"],
|
|
38
|
+
knownPathDirectories: [],
|
|
39
|
+
knownFilePaths: [],
|
|
40
|
+
label: "antigravity",
|
|
41
|
+
allowBareFallback: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (!options?.configuredPath && !options?.runCommandImpl) {
|
|
45
|
+
cachedExecutable = result;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
@@ -139,13 +139,17 @@ export async function resolveExecutable(options: ExecutableResolverOptions): Pro
|
|
|
139
139
|
/**
|
|
140
140
|
* Builds the spawn spec for a resolved executable.
|
|
141
141
|
* .cmd and .bat files must be invoked via `cmd.exe /d /s /c` on Windows.
|
|
142
|
+
*
|
|
143
|
+
* `platform` defaults to the host platform; it is injectable so the Windows
|
|
144
|
+
* wrapping branch can be unit-tested from any OS.
|
|
142
145
|
*/
|
|
143
146
|
export function buildSpawnSpec(
|
|
144
147
|
executable: string,
|
|
145
148
|
args: string[],
|
|
149
|
+
platform: NodeJS.Platform = process.platform,
|
|
146
150
|
): { executable: string; args: string[] } {
|
|
147
151
|
const validatedExecutable = validateResolvedExecutable(executable, "Executable", process.cwd());
|
|
148
|
-
if (
|
|
152
|
+
if (platform === "win32") {
|
|
149
153
|
const lower = validatedExecutable.toLowerCase();
|
|
150
154
|
if (lower.endsWith(".cmd") || lower.endsWith(".bat")) {
|
|
151
155
|
validateWindowsBatchExecutableForCmd(validatedExecutable, "Windows batch executable");
|
|
@@ -4,14 +4,14 @@ import { useEffect, useRef } from "react";
|
|
|
4
4
|
|
|
5
5
|
type DebugEnv = Record<string, string | undefined>;
|
|
6
6
|
|
|
7
|
-
// Global debug state — populated lazily on first check, or eagerly via configureRenderDebug().
|
|
7
|
+
// Global debug state — populated lazily on first check, or eagerly via configureRenderDebug().
|
|
8
8
|
let configured = false;
|
|
9
9
|
let enabled = false;
|
|
10
10
|
let renderTraceEnabled = false;
|
|
11
11
|
let lifecycleEnabled = false;
|
|
12
12
|
let flickerEnabled = false;
|
|
13
13
|
let plainActionsEnabled = false;
|
|
14
|
-
let logPath = join(process.cwd(), ".codexa
|
|
14
|
+
let logPath = join(process.cwd(), ".codexa", "debug", "render-status.log");
|
|
15
15
|
let sessionId = `${Date.now()}-${process.pid}`;
|
|
16
16
|
const counters = new Map<string, number>();
|
|
17
17
|
|
|
@@ -19,13 +19,17 @@ function configureFromEnv(env: DebugEnv = process.env): void {
|
|
|
19
19
|
renderTraceEnabled = env["CODEXA_DEBUG_RENDER_TRACE"] === "1";
|
|
20
20
|
// Both CODEXA_RENDER_DEBUG and CODEXA_DEBUG_RENDER activate render debugging —
|
|
21
21
|
// two names exist for historical reasons; either one is sufficient.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
// CODEXA_TERMINAL_TRACE is a focused alias for diagnosing terminal/clear/resize
|
|
23
|
+
// render-state issues; it lights up the same `terminal` trace channel.
|
|
24
|
+
enabled = env["CODEXA_RENDER_DEBUG"] === "1"
|
|
25
|
+
|| env["CODEXA_DEBUG_MODEL_STATE"] === "1"
|
|
26
|
+
|| env["CODEXA_DEBUG_RENDER"] === "1"
|
|
27
|
+
|| env["CODEXA_TERMINAL_TRACE"] === "1"
|
|
28
|
+
|| renderTraceEnabled;
|
|
25
29
|
lifecycleEnabled = env["CODEXA_DEBUG_LIFECYCLE"] === "1";
|
|
26
30
|
flickerEnabled = env["CODEXA_DEBUG_FLICKER"] === "1";
|
|
27
31
|
plainActionsEnabled = env["CODEXA_DEBUG_PLAIN_ACTIONS"] === "1";
|
|
28
|
-
logPath = env["CODEXA_RENDER_DEBUG_FILE"]?.trim() || join(process.cwd(), ".codexa
|
|
32
|
+
logPath = env["CODEXA_RENDER_DEBUG_FILE"]?.trim() || join(process.cwd(), ".codexa", "debug", "render-status.log");
|
|
29
33
|
sessionId = `${Date.now()}-${process.pid}`;
|
|
30
34
|
configured = true;
|
|
31
35
|
}
|
|
@@ -14,12 +14,16 @@ import {
|
|
|
14
14
|
isProviderRoutableInCodexa,
|
|
15
15
|
isProviderRouteConfigured,
|
|
16
16
|
} from "../providerRuntime/registry.js";
|
|
17
|
-
import { normalizeGeminiModelId } from "../providerRuntime/models.js";
|
|
18
|
-
import {
|
|
17
|
+
import { normalizeGeminiModelId } from "../providerRuntime/models.js";
|
|
18
|
+
import { ANTIGRAVITY_DEFAULT_MODEL_ID } from "../providerRuntime/antigravity.js";
|
|
19
|
+
import { setLocalProviderConfig } from "../providerRuntime/local.js";
|
|
19
20
|
import { formatContextLength, resolveModelContextLengthCached } from "../providerRuntime/contextMetadata.js";
|
|
20
21
|
import { resolveModelCapabilityProfileCached } from "../providerRuntime/capabilityProfile.js";
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
// Google/Gemini remains a recognized legacy config value so existing workspace
|
|
24
|
+
// files can be migrated, but it is no longer a selectable Codexa provider.
|
|
25
|
+
const PROVIDER_ORDER: readonly ProviderId[] = ["openai", "anthropic", "local", "antigravity"];
|
|
26
|
+
const KNOWN_PROVIDER_IDS: readonly ProviderId[] = ["openai", "anthropic", "google", "local", "antigravity"];
|
|
23
27
|
|
|
24
28
|
const DEFAULT_PROVIDER_ID: ProviderId = "openai";
|
|
25
29
|
|
|
@@ -63,8 +67,8 @@ const DEFAULT_PROVIDERS: Record<ProviderId, ProviderDefault> = {
|
|
|
63
67
|
isActiveRoute: false,
|
|
64
68
|
routeUnavailableReason: null,
|
|
65
69
|
},
|
|
66
|
-
local: {
|
|
67
|
-
id: "local",
|
|
70
|
+
local: {
|
|
71
|
+
id: "local",
|
|
68
72
|
displayName: "Local",
|
|
69
73
|
currentModel: () => "Local default",
|
|
70
74
|
backendType: "local-openai-compatible",
|
|
@@ -72,12 +76,23 @@ const DEFAULT_PROVIDERS: Record<ProviderId, ProviderDefault> = {
|
|
|
72
76
|
enabled: false,
|
|
73
77
|
launchCommand: null,
|
|
74
78
|
isActiveRoute: false,
|
|
75
|
-
routeUnavailableReason: "Local provider unavailable. Start LM Studio, load a model, and enable the local server.",
|
|
76
|
-
},
|
|
77
|
-
|
|
79
|
+
routeUnavailableReason: "Local provider unavailable. Start LM Studio, load a model, and enable the local server.",
|
|
80
|
+
},
|
|
81
|
+
antigravity: {
|
|
82
|
+
id: "antigravity",
|
|
83
|
+
displayName: "Antigravity",
|
|
84
|
+
currentModel: () => ANTIGRAVITY_DEFAULT_MODEL_ID,
|
|
85
|
+
backendType: "antigravity-cli-auth",
|
|
86
|
+
routeMode: "in-codexa",
|
|
87
|
+
enabled: true,
|
|
88
|
+
launchCommand: { executable: "agy", args: [] },
|
|
89
|
+
isActiveRoute: false,
|
|
90
|
+
routeUnavailableReason: null,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
78
93
|
|
|
79
|
-
function isProviderId(value: unknown): value is ProviderId {
|
|
80
|
-
return typeof value === "string" &&
|
|
94
|
+
function isProviderId(value: unknown): value is ProviderId {
|
|
95
|
+
return typeof value === "string" && KNOWN_PROVIDER_IDS.includes(value as ProviderId);
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
function normalizeLaunchCommand(value: ProviderWorkspaceOverride["command"] | undefined): ProviderLaunchCommand | null | undefined {
|
|
@@ -128,13 +143,14 @@ function applyOverride(
|
|
|
128
143
|
};
|
|
129
144
|
}
|
|
130
145
|
|
|
131
|
-
export function getDefaultProviderId(config: ProviderWorkspaceConfig | null | undefined): ProviderId {
|
|
132
|
-
|
|
133
|
-
|
|
146
|
+
export function getDefaultProviderId(config: ProviderWorkspaceConfig | null | undefined): ProviderId {
|
|
147
|
+
const providerId = config?.workspaceDefaultProviderId;
|
|
148
|
+
return isProviderId(providerId) && providerId !== "google" ? providerId : DEFAULT_PROVIDER_ID;
|
|
149
|
+
}
|
|
134
150
|
|
|
135
151
|
export function getActiveRouteProviderId(config: ProviderWorkspaceConfig | null | undefined): ProviderId {
|
|
136
152
|
const providerId = config?.activeRoute?.providerId;
|
|
137
|
-
return isProviderId(providerId) && isProviderRoutableInCodexa(providerId)
|
|
153
|
+
return isProviderId(providerId) && providerId !== "google" && isProviderRoutableInCodexa(providerId)
|
|
138
154
|
? providerId
|
|
139
155
|
: DEFAULT_PROVIDER_ID;
|
|
140
156
|
}
|