openmagic 0.33.1 → 0.33.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/dist/cli.js +44 -9
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +3 -3
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -189,13 +189,14 @@ function writeFileSafe(filePath, content, roots) {
|
|
|
189
189
|
return { ok: false, error: `Failed to write file: ${e.message}` };
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
+
var MAX_LIST_ENTRIES = 2e3;
|
|
192
193
|
function listFiles(rootPath, roots, maxDepth = 4) {
|
|
193
194
|
if (!isPathSafe(rootPath, roots)) {
|
|
194
195
|
return [];
|
|
195
196
|
}
|
|
196
197
|
const entries = [];
|
|
197
198
|
function walk(dir, depth) {
|
|
198
|
-
if (depth > maxDepth) return;
|
|
199
|
+
if (depth > maxDepth || entries.length >= MAX_LIST_ENTRIES) return;
|
|
199
200
|
let items;
|
|
200
201
|
try {
|
|
201
202
|
items = readdirSync(dir);
|
|
@@ -203,6 +204,7 @@ function listFiles(rootPath, roots, maxDepth = 4) {
|
|
|
203
204
|
return;
|
|
204
205
|
}
|
|
205
206
|
for (const item of items) {
|
|
207
|
+
if (entries.length >= MAX_LIST_ENTRIES) return;
|
|
206
208
|
if (IGNORED_DIRS.has(item)) continue;
|
|
207
209
|
if (item.startsWith(".") && item !== ".env.example") continue;
|
|
208
210
|
const fullPath = join2(dir, item);
|
|
@@ -251,12 +253,15 @@ var GREP_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
251
253
|
".py",
|
|
252
254
|
".rb"
|
|
253
255
|
]);
|
|
256
|
+
var MAX_GREP_FILE_SIZE = 256 * 1024;
|
|
257
|
+
var MAX_GREP_FILES_SCANNED = 500;
|
|
254
258
|
function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
|
|
255
259
|
if (!isPathSafe(searchRoot, roots)) return [];
|
|
256
260
|
const results = [];
|
|
257
261
|
const lowerPattern = pattern.toLowerCase();
|
|
262
|
+
let filesScanned = 0;
|
|
258
263
|
function walk(dir, depth) {
|
|
259
|
-
if (depth >
|
|
264
|
+
if (depth > 6 || results.length >= maxResults || filesScanned >= MAX_GREP_FILES_SCANNED) return;
|
|
260
265
|
let items;
|
|
261
266
|
try {
|
|
262
267
|
items = readdirSync(dir);
|
|
@@ -264,7 +269,7 @@ function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
|
|
|
264
269
|
return;
|
|
265
270
|
}
|
|
266
271
|
for (const item of items) {
|
|
267
|
-
if (results.length >= maxResults) return;
|
|
272
|
+
if (results.length >= maxResults || filesScanned >= MAX_GREP_FILES_SCANNED) return;
|
|
268
273
|
if (IGNORED_DIRS.has(item) || item.startsWith(".") && item !== ".env.example") continue;
|
|
269
274
|
const fullPath = join2(dir, item);
|
|
270
275
|
let stat;
|
|
@@ -279,6 +284,8 @@ function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
|
|
|
279
284
|
} else if (stat.isFile()) {
|
|
280
285
|
const ext = extname(item).toLowerCase();
|
|
281
286
|
if (!GREP_EXTENSIONS.has(ext)) continue;
|
|
287
|
+
if (stat.size > MAX_GREP_FILE_SIZE) continue;
|
|
288
|
+
filesScanned++;
|
|
282
289
|
try {
|
|
283
290
|
const content = readFileSync2(fullPath, "utf-8");
|
|
284
291
|
const lines = content.split("\n");
|
|
@@ -1565,7 +1572,9 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
|
|
|
1565
1572
|
}
|
|
1566
1573
|
|
|
1567
1574
|
// src/server.ts
|
|
1568
|
-
|
|
1575
|
+
import { createRequire } from "module";
|
|
1576
|
+
var _require = createRequire(import.meta.url);
|
|
1577
|
+
var VERSION = _require("../package.json").version;
|
|
1569
1578
|
var __dirname = dirname2(fileURLToPath(import.meta.url));
|
|
1570
1579
|
var MAX_SERVER_LOGS = 200;
|
|
1571
1580
|
var serverLogs = [];
|
|
@@ -1922,6 +1931,12 @@ function createProxyServer(targetHost, targetPort, roots) {
|
|
|
1922
1931
|
const status = proxyRes.statusCode || 200;
|
|
1923
1932
|
if (!isHtml && status < 400) {
|
|
1924
1933
|
res.writeHead(status, proxyRes.headers);
|
|
1934
|
+
proxyRes.on("error", () => {
|
|
1935
|
+
try {
|
|
1936
|
+
res.end();
|
|
1937
|
+
} catch {
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1925
1940
|
proxyRes.pipe(res);
|
|
1926
1941
|
return;
|
|
1927
1942
|
}
|
|
@@ -1937,6 +1952,12 @@ function createProxyServer(targetHost, targetPort, roots) {
|
|
|
1937
1952
|
delete headers["last-modified"];
|
|
1938
1953
|
headers["cache-control"] = "no-store";
|
|
1939
1954
|
res.writeHead(status, headers);
|
|
1955
|
+
proxyRes.on("error", () => {
|
|
1956
|
+
try {
|
|
1957
|
+
res.end(buildInjectionScript(token));
|
|
1958
|
+
} catch {
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1940
1961
|
proxyRes.pipe(res, { end: false });
|
|
1941
1962
|
proxyRes.on("end", () => {
|
|
1942
1963
|
res.end(buildInjectionScript(token));
|
|
@@ -1944,7 +1965,19 @@ function createProxyServer(targetHost, targetPort, roots) {
|
|
|
1944
1965
|
return;
|
|
1945
1966
|
}
|
|
1946
1967
|
const chunks = [];
|
|
1947
|
-
|
|
1968
|
+
let totalSize = 0;
|
|
1969
|
+
proxyRes.on("data", (c) => {
|
|
1970
|
+
if (totalSize < 16384) {
|
|
1971
|
+
chunks.push(c);
|
|
1972
|
+
totalSize += c.length;
|
|
1973
|
+
}
|
|
1974
|
+
});
|
|
1975
|
+
proxyRes.on("error", () => {
|
|
1976
|
+
try {
|
|
1977
|
+
res.end();
|
|
1978
|
+
} catch {
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1948
1981
|
proxyRes.on("end", () => {
|
|
1949
1982
|
const body = Buffer.concat(chunks).toString("utf-8").slice(0, 2e3);
|
|
1950
1983
|
const toolbarScript = buildInjectionScript(token);
|
|
@@ -2223,6 +2256,7 @@ function checkDependenciesInstalled(cwd = process.cwd()) {
|
|
|
2223
2256
|
}
|
|
2224
2257
|
|
|
2225
2258
|
// src/cli.ts
|
|
2259
|
+
import { createRequire as createRequire2 } from "module";
|
|
2226
2260
|
var origEmitWarning = process.emitWarning;
|
|
2227
2261
|
process.emitWarning = function(warning, ...args) {
|
|
2228
2262
|
if (typeof warning === "string" && warning.includes("util._extend")) return;
|
|
@@ -2239,7 +2273,8 @@ process.on("uncaughtException", (err) => {
|
|
|
2239
2273
|
});
|
|
2240
2274
|
var childProcesses = [];
|
|
2241
2275
|
var lastDetectedPort = null;
|
|
2242
|
-
var
|
|
2276
|
+
var _require2 = createRequire2(import.meta.url);
|
|
2277
|
+
var VERSION2 = _require2("../package.json").version;
|
|
2243
2278
|
function ask(question) {
|
|
2244
2279
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
2245
2280
|
return new Promise((resolve4) => {
|
|
@@ -2670,9 +2705,9 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2670
2705
|
}
|
|
2671
2706
|
}, 3e3);
|
|
2672
2707
|
};
|
|
2673
|
-
process.
|
|
2674
|
-
process.
|
|
2675
|
-
process.
|
|
2708
|
+
process.once("exit", cleanup);
|
|
2709
|
+
process.once("SIGINT", cleanup);
|
|
2710
|
+
process.once("SIGTERM", cleanup);
|
|
2676
2711
|
console.log(
|
|
2677
2712
|
chalk.dim(` Waiting for dev server on port ${port}...`)
|
|
2678
2713
|
);
|