codex-lens 0.1.1 → 0.1.3
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 +9 -16
- package/dist/pty-manager.js +182 -0
- package/dist/public/assets/main-B86_1Kr6.js +50 -0
- package/dist/public/assets/main-CPDV3aMv.css +32 -0
- package/dist/public/index.html +13 -0
- package/dist/snapshot-manager.js +208 -0
- package/package.json +1 -1
- package/vite.config.js +1 -1
- package/dist/main.css +0 -658
- package/dist/main.js +0 -31446
package/build.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { build } from 'esbuild';
|
|
1
|
+
import { build as esbuildBuild } from 'esbuild';
|
|
2
|
+
import { build as viteBuild } from 'vite';
|
|
2
3
|
import { rmSync, existsSync, mkdirSync, cpSync } from 'fs';
|
|
3
4
|
import { resolve, dirname } from 'path';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
@@ -18,6 +19,8 @@ async function buildAll() {
|
|
|
18
19
|
'src/proxy.js',
|
|
19
20
|
'src/aggregator.js',
|
|
20
21
|
'src/watcher.js',
|
|
22
|
+
'src/pty-manager.js',
|
|
23
|
+
'src/snapshot-manager.js',
|
|
21
24
|
'src/lib/sse-parser.js',
|
|
22
25
|
'src/lib/diff-builder.js',
|
|
23
26
|
'src/lib/log-manager.js',
|
|
@@ -26,7 +29,7 @@ async function buildAll() {
|
|
|
26
29
|
|
|
27
30
|
for (const file of backendFiles) {
|
|
28
31
|
try {
|
|
29
|
-
await
|
|
32
|
+
await esbuildBuild({
|
|
30
33
|
entryPoints: [resolve(__dirname, file)],
|
|
31
34
|
outfile: resolve(__dirname, file.replace('src/', 'dist/')),
|
|
32
35
|
bundle: false,
|
|
@@ -43,21 +46,11 @@ async function buildAll() {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bundle: true,
|
|
50
|
-
platform: 'browser',
|
|
51
|
-
target: 'es2020',
|
|
52
|
-
format: 'esm',
|
|
53
|
-
jsx: 'automatic',
|
|
54
|
-
loader: {
|
|
55
|
-
'.js': 'jsx',
|
|
56
|
-
'.jsx': 'jsx',
|
|
57
|
-
},
|
|
58
|
-
external: [],
|
|
49
|
+
console.log('Building frontend with Vite...');
|
|
50
|
+
await viteBuild({
|
|
51
|
+
configFile: resolve(__dirname, 'vite.config.js'),
|
|
59
52
|
});
|
|
60
|
-
console.log('Built:
|
|
53
|
+
console.log('Built: frontend -> dist/public/');
|
|
61
54
|
|
|
62
55
|
if (existsSync(resolve(__dirname, 'public'))) {
|
|
63
56
|
cpSync(resolve(__dirname, 'public'), resolve(outDir, 'public'), { recursive: true });
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
4
|
+
import { platform, arch } from "node:os";
|
|
5
|
+
import { chmodSync, statSync } from "node:fs";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
8
|
+
let ptyProcess = null;
|
|
9
|
+
let dataListeners = [];
|
|
10
|
+
let exitListeners = [];
|
|
11
|
+
let lastExitCode = null;
|
|
12
|
+
let outputBuffer = "";
|
|
13
|
+
let lastPtyCols = 120;
|
|
14
|
+
let lastPtyRows = 30;
|
|
15
|
+
const MAX_BUFFER = 2e5;
|
|
16
|
+
let batchBuffer = "";
|
|
17
|
+
let batchScheduled = false;
|
|
18
|
+
async function getPty() {
|
|
19
|
+
const ptyMod = await import("node-pty");
|
|
20
|
+
return ptyMod.default || ptyMod;
|
|
21
|
+
}
|
|
22
|
+
function findSafeSliceStart(buf, rawStart) {
|
|
23
|
+
const scanLimit = Math.min(rawStart + 64, buf.length);
|
|
24
|
+
let i = rawStart;
|
|
25
|
+
while (i < scanLimit) {
|
|
26
|
+
const ch = buf.charCodeAt(i);
|
|
27
|
+
if (ch === 27) {
|
|
28
|
+
let j = i + 1;
|
|
29
|
+
while (j < scanLimit && !(buf.charCodeAt(j) >= 64 && buf.charCodeAt(j) <= 126 && j > i + 1)) {
|
|
30
|
+
j++;
|
|
31
|
+
}
|
|
32
|
+
if (j < scanLimit) {
|
|
33
|
+
return j + 1;
|
|
34
|
+
}
|
|
35
|
+
i = j;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (ch >= 32 && ch <= 63) {
|
|
39
|
+
i++;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
return i < buf.length ? i : rawStart;
|
|
45
|
+
}
|
|
46
|
+
function flushBatch() {
|
|
47
|
+
batchScheduled = false;
|
|
48
|
+
if (!batchBuffer) return;
|
|
49
|
+
const chunk = batchBuffer;
|
|
50
|
+
batchBuffer = "";
|
|
51
|
+
for (const cb of dataListeners) {
|
|
52
|
+
try {
|
|
53
|
+
cb(chunk);
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function fixSpawnHelperPermissions() {
|
|
59
|
+
try {
|
|
60
|
+
const os = platform();
|
|
61
|
+
const cpu = arch();
|
|
62
|
+
const helperPath = join(__dirname, "node_modules", "node-pty", "prebuilds", `${os}-${cpu}`, "spawn-helper");
|
|
63
|
+
const stat = statSync(helperPath);
|
|
64
|
+
if (!(stat.mode & 73)) {
|
|
65
|
+
chmodSync(helperPath, stat.mode | 493);
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function spawnCodex(codexBinary, projectRoot, proxyPort) {
|
|
71
|
+
if (ptyProcess) {
|
|
72
|
+
killPty();
|
|
73
|
+
}
|
|
74
|
+
const pty = await getPty();
|
|
75
|
+
fixSpawnHelperPermissions();
|
|
76
|
+
const shell = platform() === "win32" ? "powershell.exe" : "bash";
|
|
77
|
+
const args = platform() === "win32" ? ["-NoExit", "-Command", `Set-Location "${projectRoot}"; & "${codexBinary}"`] : [];
|
|
78
|
+
const env = { ...process.env };
|
|
79
|
+
env.OPENAI_BASE_URL = `http://127.0.0.1:${proxyPort}`;
|
|
80
|
+
if (platform() === "win32") {
|
|
81
|
+
env.WINPTY = "1";
|
|
82
|
+
}
|
|
83
|
+
lastExitCode = null;
|
|
84
|
+
outputBuffer = "";
|
|
85
|
+
ptyProcess = pty.spawn(shell, args, {
|
|
86
|
+
name: "xterm-256color",
|
|
87
|
+
cols: lastPtyCols,
|
|
88
|
+
rows: lastPtyRows,
|
|
89
|
+
cwd: projectRoot,
|
|
90
|
+
env,
|
|
91
|
+
useConpty: false
|
|
92
|
+
});
|
|
93
|
+
ptyProcess.onData((data) => {
|
|
94
|
+
outputBuffer += data;
|
|
95
|
+
if (outputBuffer.length > MAX_BUFFER) {
|
|
96
|
+
const rawStart = outputBuffer.length - MAX_BUFFER;
|
|
97
|
+
const safeStart = findSafeSliceStart(outputBuffer, rawStart);
|
|
98
|
+
outputBuffer = outputBuffer.slice(safeStart);
|
|
99
|
+
}
|
|
100
|
+
batchBuffer += data;
|
|
101
|
+
if (!batchScheduled) {
|
|
102
|
+
batchScheduled = true;
|
|
103
|
+
setImmediate(flushBatch);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
ptyProcess.onExit(({ exitCode }) => {
|
|
107
|
+
flushBatch();
|
|
108
|
+
lastExitCode = exitCode;
|
|
109
|
+
ptyProcess = null;
|
|
110
|
+
for (const cb of exitListeners) {
|
|
111
|
+
try {
|
|
112
|
+
cb(exitCode);
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return ptyProcess;
|
|
118
|
+
}
|
|
119
|
+
function writeToPty(data) {
|
|
120
|
+
if (ptyProcess) {
|
|
121
|
+
ptyProcess.write(data);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
function resizePty(cols, rows) {
|
|
127
|
+
lastPtyCols = cols;
|
|
128
|
+
lastPtyRows = rows;
|
|
129
|
+
if (ptyProcess) {
|
|
130
|
+
try {
|
|
131
|
+
ptyProcess.resize(cols, rows);
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function killPty() {
|
|
137
|
+
if (ptyProcess) {
|
|
138
|
+
flushBatch();
|
|
139
|
+
batchBuffer = "";
|
|
140
|
+
batchScheduled = false;
|
|
141
|
+
try {
|
|
142
|
+
ptyProcess.kill();
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
ptyProcess = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function onPtyData(cb) {
|
|
149
|
+
dataListeners.push(cb);
|
|
150
|
+
return () => {
|
|
151
|
+
dataListeners = dataListeners.filter((l) => l !== cb);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function onPtyExit(cb) {
|
|
155
|
+
exitListeners.push(cb);
|
|
156
|
+
return () => {
|
|
157
|
+
exitListeners = exitListeners.filter((l) => l !== cb);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function getPtyPid() {
|
|
161
|
+
return ptyProcess ? ptyProcess.pid : null;
|
|
162
|
+
}
|
|
163
|
+
function getPtyState() {
|
|
164
|
+
return {
|
|
165
|
+
running: !!ptyProcess,
|
|
166
|
+
exitCode: lastExitCode
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function getOutputBuffer() {
|
|
170
|
+
return outputBuffer;
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
getOutputBuffer,
|
|
174
|
+
getPtyPid,
|
|
175
|
+
getPtyState,
|
|
176
|
+
killPty,
|
|
177
|
+
onPtyData,
|
|
178
|
+
onPtyExit,
|
|
179
|
+
resizePty,
|
|
180
|
+
spawnCodex,
|
|
181
|
+
writeToPty
|
|
182
|
+
};
|