codex-lens 0.1.13 → 0.1.15

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/build.js CHANGED
@@ -20,7 +20,6 @@ async function buildAll() {
20
20
  'src/aggregator.js',
21
21
  'src/watcher.js',
22
22
  'src/pty-manager.js',
23
- 'src/snapshot-manager.js',
24
23
  'src/lib/sse-parser.js',
25
24
  'src/lib/diff-builder.js',
26
25
  'src/lib/log-manager.js',
@@ -28,9 +27,14 @@ async function buildAll() {
28
27
  ];
29
28
 
30
29
  for (const file of backendFiles) {
30
+ const fullPath = resolve(__dirname, file);
31
+ if (!existsSync(fullPath)) {
32
+ console.log(`Skipping (not found): ${file}`);
33
+ continue;
34
+ }
31
35
  try {
32
36
  await esbuildBuild({
33
- entryPoints: [resolve(__dirname, file)],
37
+ entryPoints: [fullPath],
34
38
  outfile: resolve(__dirname, file.replace('src/', 'dist/')),
35
39
  bundle: false,
36
40
  platform: 'node',
@@ -8,7 +8,6 @@ import { createProxyServer } from "./proxy.js";
8
8
  import { FileWatcher, scanDirectory } from "./watcher.js";
9
9
  import { createLogger } from "./lib/logger.js";
10
10
  import { spawnCodex, writeToPty, resizePty, killPty, onPtyData, onPtyExit, getPtyState, getOutputBuffer } from "./pty-manager.js";
11
- import { SnapshotManager } from "./snapshot-manager.js";
12
11
  import path from "path";
13
12
  import { fileURLToPath } from "url";
14
13
  import { readFileSync, existsSync } from "fs";
@@ -51,9 +50,6 @@ class Aggregator {
51
50
  this.proxyServer = null;
52
51
  this.fileWatcher = null;
53
52
  this.ptyProcess = null;
54
- this.snapshotManager = new SnapshotManager();
55
- this.currentTaskId = null;
56
- this.taskStatus = "idle";
57
53
  }
58
54
  async start(proxyPort) {
59
55
  await fetchLatestVersion();
@@ -214,103 +210,7 @@ class Aggregator {
214
210
  }
215
211
  }));
216
212
  }
217
- } else if (data.type === "start_task") {
218
- this.handleStartTask(ws);
219
- } else if (data.type === "rollback_task") {
220
- this.handleRollbackTask(ws);
221
- } else if (data.type === "complete_task") {
222
- this.handleCompleteTask(ws);
223
- } else if (data.type === "get_task_status") {
224
- ws.send(JSON.stringify({
225
- type: "task_status",
226
- data: {
227
- status: this.taskStatus,
228
- taskId: this.currentTaskId
229
- }
230
- }));
231
- }
232
- }
233
- async handleStartTask(ws) {
234
- if (this.taskStatus === "running") {
235
- ws.send(JSON.stringify({ type: "error", message: "Task already running" }));
236
- return;
237
- }
238
- this.currentTaskId = Date.now().toString();
239
- this.taskStatus = "running";
240
- const result = await this.snapshotManager.createSnapshot(this.projectRoot, this.currentTaskId);
241
- if (result.success) {
242
- logger.info(`Task started: ${this.currentTaskId}, ${result.filesCount} files snapshotted`);
243
- this.broadcast({
244
- type: "task_status",
245
- data: {
246
- status: this.taskStatus,
247
- taskId: this.currentTaskId,
248
- filesCount: result.filesCount
249
- }
250
- });
251
- ws.send(JSON.stringify({
252
- type: "task_started",
253
- data: {
254
- taskId: this.currentTaskId,
255
- filesCount: result.filesCount
256
- }
257
- }));
258
- } else {
259
- this.taskStatus = "idle";
260
- this.currentTaskId = null;
261
- ws.send(JSON.stringify({ type: "error", message: "Failed to create snapshot: " + result.error }));
262
- }
263
- }
264
- async handleRollbackTask(ws) {
265
- if (!this.currentTaskId || this.taskStatus !== "running") {
266
- ws.send(JSON.stringify({ type: "error", message: "No active task to rollback" }));
267
- return;
268
213
  }
269
- const taskId = this.currentTaskId;
270
- const result = await this.snapshotManager.restoreSnapshot(taskId);
271
- if (result.success) {
272
- await this.snapshotManager.deleteSnapshot(taskId);
273
- logger.info(`Task rolled back: ${taskId}, ${result.restoredCount} files restored`);
274
- this.taskStatus = "idle";
275
- this.currentTaskId = null;
276
- this.broadcast({
277
- type: "task_status",
278
- data: {
279
- status: this.taskStatus,
280
- taskId: null
281
- }
282
- });
283
- ws.send(JSON.stringify({
284
- type: "task_rolled_back",
285
- data: {
286
- restoredCount: result.restoredCount
287
- }
288
- }));
289
- } else {
290
- ws.send(JSON.stringify({ type: "error", message: "Failed to rollback: " + result.error }));
291
- }
292
- }
293
- async handleCompleteTask(ws) {
294
- if (!this.currentTaskId || this.taskStatus !== "running") {
295
- ws.send(JSON.stringify({ type: "error", message: "No active task to complete" }));
296
- return;
297
- }
298
- const taskId = this.currentTaskId;
299
- await this.snapshotManager.deleteSnapshot(taskId);
300
- logger.info(`Task completed: ${taskId}`);
301
- this.taskStatus = "idle";
302
- this.currentTaskId = null;
303
- this.broadcast({
304
- type: "task_status",
305
- data: {
306
- status: this.taskStatus,
307
- taskId: null
308
- }
309
- });
310
- ws.send(JSON.stringify({
311
- type: "task_completed",
312
- data: {}
313
- }));
314
214
  }
315
215
  broadcast(event) {
316
216
  const message = JSON.stringify(event);
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { join, dirname } from "node:path";
4
- import { platform, arch } from "node:os";
5
- import { chmodSync, statSync } from "node:fs";
4
+ import { platform, arch, homedir } from "node:os";
5
+ import { chmodSync, statSync, existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
6
6
  const __filename = fileURLToPath(import.meta.url);
7
7
  const __dirname = dirname(__filename);
8
8
  let ptyProcess = null;
@@ -67,16 +67,35 @@ function fixSpawnHelperPermissions() {
67
67
  } catch {
68
68
  }
69
69
  }
70
+ function setupCodexConfig(proxyPort) {
71
+ const codexDir = join(homedir(), ".codex");
72
+ const configPath = join(codexDir, "config.toml");
73
+ if (!existsSync(codexDir)) {
74
+ mkdirSync(codexDir, { recursive: true });
75
+ }
76
+ let config = "";
77
+ if (existsSync(configPath)) {
78
+ config = readFileSync(configPath, "utf-8");
79
+ }
80
+ const baseUrl = `http://127.0.0.1:${proxyPort}`;
81
+ const configLine = `openai_base_url = "${baseUrl}"`;
82
+ if (config.includes("openai_base_url")) {
83
+ config = config.replace(/openai_base_url\s*=\s*"[^"]*"/, configLine);
84
+ } else {
85
+ config = config.trimEnd() + "\n" + configLine + "\n";
86
+ }
87
+ writeFileSync(configPath, config);
88
+ }
70
89
  async function spawnCodex(codexBinary, projectRoot, proxyPort) {
71
90
  if (ptyProcess) {
72
91
  killPty();
73
92
  }
74
93
  const pty = await getPty();
75
94
  fixSpawnHelperPermissions();
95
+ setupCodexConfig(proxyPort);
76
96
  const shell = platform() === "win32" ? "powershell.exe" : "bash";
77
97
  const args = platform() === "win32" ? ["-NoExit", "-Command", `Set-Location "${projectRoot}"; & "${codexBinary}"`] : [];
78
98
  const env = { ...process.env };
79
- env.OPENAI_BASE_URL = `http://127.0.0.1:${proxyPort}`;
80
99
  if (platform() === "win32") {
81
100
  env.WINPTY = "1";
82
101
  }