@dev-anywhere/proxy 0.4.13 → 0.4.14
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/serve.js +59 -41
- package/dist/serve.js.map +1 -1
- package/package.json +3 -3
package/dist/serve.js
CHANGED
|
@@ -817,13 +817,13 @@ var RelayConnection = class extends EventEmitter {
|
|
|
817
817
|
|
|
818
818
|
// src/serve/handlers/control-messages.ts
|
|
819
819
|
import { readdir as readdir2, mkdir } from "fs/promises";
|
|
820
|
-
import { join as join4, isAbsolute, normalize } from "path";
|
|
820
|
+
import { join as join4, isAbsolute as isAbsolute2, normalize } from "path";
|
|
821
821
|
|
|
822
822
|
// src/serve/session-history.ts
|
|
823
823
|
import { readdir, stat, access, open } from "fs/promises";
|
|
824
824
|
import { createReadStream } from "fs";
|
|
825
|
-
import { join as join2 } from "path";
|
|
826
|
-
import { homedir as homedir2 } from "os";
|
|
825
|
+
import { isAbsolute, join as join2, resolve, sep } from "path";
|
|
826
|
+
import { homedir as homedir2, tmpdir } from "os";
|
|
827
827
|
import { createInterface } from "readline";
|
|
828
828
|
var claudeProjectsDir = () => join2(homedir2(), ".claude", "projects");
|
|
829
829
|
var codexSessionsDir = () => join2(homedir2(), ".codex", "sessions");
|
|
@@ -851,11 +851,12 @@ var INTERNAL_TITLE_PATTERNS = [
|
|
|
851
851
|
/^codex agent history\b/i,
|
|
852
852
|
/^conversation summary\b/i
|
|
853
853
|
];
|
|
854
|
+
var TEMP_HISTORY_ROOTS = [tmpdir(), "/tmp", "/private/tmp", "/var/tmp"].map(normalizeAbsolutePath).filter((path) => path !== null);
|
|
854
855
|
async function scanSessionHistory(options = {}) {
|
|
855
856
|
const entries = applySessionHistoryMetadata(
|
|
856
857
|
[...await scanClaudeSessionHistory(), ...await scanCodexSessionHistory()],
|
|
857
858
|
readSessionHistoryMetadata(options.metadataPath)
|
|
858
|
-
);
|
|
859
|
+
).filter((entry) => !isTemporaryProjectDir(entry.projectDir));
|
|
859
860
|
entries.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
860
861
|
const seen = /* @__PURE__ */ new Set();
|
|
861
862
|
const uniqueEntries = entries.filter((e) => {
|
|
@@ -866,6 +867,23 @@ async function scanSessionHistory(options = {}) {
|
|
|
866
867
|
});
|
|
867
868
|
return uniqueEntries;
|
|
868
869
|
}
|
|
870
|
+
function normalizeAbsolutePath(path) {
|
|
871
|
+
const trimmed = path.trim();
|
|
872
|
+
if (!trimmed || !isAbsolute(trimmed)) return null;
|
|
873
|
+
let resolved = resolve(trimmed);
|
|
874
|
+
while (resolved.length > 1 && resolved.endsWith(sep)) {
|
|
875
|
+
resolved = resolved.slice(0, -1);
|
|
876
|
+
}
|
|
877
|
+
return resolved === sep ? null : resolved;
|
|
878
|
+
}
|
|
879
|
+
function isPathInsideOrEqual(path, root) {
|
|
880
|
+
return path === root || path.startsWith(`${root}${sep}`);
|
|
881
|
+
}
|
|
882
|
+
function isTemporaryProjectDir(projectDir) {
|
|
883
|
+
const normalized = normalizeAbsolutePath(projectDir);
|
|
884
|
+
if (!normalized) return false;
|
|
885
|
+
return TEMP_HISTORY_ROOTS.some((root) => isPathInsideOrEqual(normalized, root));
|
|
886
|
+
}
|
|
869
887
|
async function scanClaudeSessionHistory() {
|
|
870
888
|
const entries = [];
|
|
871
889
|
let projectDirs;
|
|
@@ -1138,7 +1156,7 @@ function extractConversationText(msg) {
|
|
|
1138
1156
|
return null;
|
|
1139
1157
|
}
|
|
1140
1158
|
async function extractTitleAndCwd(filePath) {
|
|
1141
|
-
return new Promise((
|
|
1159
|
+
return new Promise((resolve4) => {
|
|
1142
1160
|
const rl = createInterface({
|
|
1143
1161
|
input: createReadStream(filePath, { encoding: "utf-8" }),
|
|
1144
1162
|
crlfDelay: Infinity
|
|
@@ -1166,10 +1184,10 @@ async function extractTitleAndCwd(filePath) {
|
|
|
1166
1184
|
}
|
|
1167
1185
|
});
|
|
1168
1186
|
rl.on("close", () => {
|
|
1169
|
-
if (!resolved)
|
|
1170
|
-
else
|
|
1187
|
+
if (!resolved) resolve4({ title, cwd });
|
|
1188
|
+
else resolve4({ title, cwd });
|
|
1171
1189
|
});
|
|
1172
|
-
rl.on("error", () =>
|
|
1190
|
+
rl.on("error", () => resolve4({ title, cwd }));
|
|
1173
1191
|
});
|
|
1174
1192
|
}
|
|
1175
1193
|
async function collectJsonlFiles(root) {
|
|
@@ -1191,7 +1209,7 @@ async function collectJsonlFiles(root) {
|
|
|
1191
1209
|
return files;
|
|
1192
1210
|
}
|
|
1193
1211
|
async function extractCodexTitleAndCwd(filePath) {
|
|
1194
|
-
return new Promise((
|
|
1212
|
+
return new Promise((resolve4) => {
|
|
1195
1213
|
const rl = createInterface({
|
|
1196
1214
|
input: createReadStream(filePath, { encoding: "utf-8" }),
|
|
1197
1215
|
crlfDelay: Infinity
|
|
@@ -1215,8 +1233,8 @@ async function extractCodexTitleAndCwd(filePath) {
|
|
|
1215
1233
|
} catch {
|
|
1216
1234
|
}
|
|
1217
1235
|
});
|
|
1218
|
-
rl.on("close", () =>
|
|
1219
|
-
rl.on("error", () =>
|
|
1236
|
+
rl.on("close", () => resolve4({ id, title, cwd }));
|
|
1237
|
+
rl.on("error", () => resolve4({ id, title, cwd }));
|
|
1220
1238
|
});
|
|
1221
1239
|
}
|
|
1222
1240
|
function extractCodexUserText(payload) {
|
|
@@ -1414,7 +1432,7 @@ function classifyPathError(err) {
|
|
|
1414
1432
|
// src/serve/handlers/control-messages.ts
|
|
1415
1433
|
var COMMAND_REFRESH_MS = 6 * 60 * 60 * 1e3;
|
|
1416
1434
|
function isPathSafe(path) {
|
|
1417
|
-
if (!
|
|
1435
|
+
if (!isAbsolute2(path)) return false;
|
|
1418
1436
|
const normalized = normalize(path);
|
|
1419
1437
|
if (normalized.includes("..")) return false;
|
|
1420
1438
|
return true;
|
|
@@ -1801,7 +1819,7 @@ var WorkerRegistry = class {
|
|
|
1801
1819
|
return workerPid;
|
|
1802
1820
|
}
|
|
1803
1821
|
connect(sessionId, sockPath) {
|
|
1804
|
-
return new Promise((
|
|
1822
|
+
return new Promise((resolve4) => {
|
|
1805
1823
|
const sock = connect(sockPath);
|
|
1806
1824
|
sock.on("connect", () => {
|
|
1807
1825
|
this.sockets.set(sessionId, sock);
|
|
@@ -1817,9 +1835,9 @@ var WorkerRegistry = class {
|
|
|
1817
1835
|
);
|
|
1818
1836
|
sock.on("close", () => this.onDisconnect(sessionId));
|
|
1819
1837
|
sock.on("error", () => this.onDisconnect(sessionId));
|
|
1820
|
-
|
|
1838
|
+
resolve4(sock);
|
|
1821
1839
|
});
|
|
1822
|
-
sock.on("error", () =>
|
|
1840
|
+
sock.on("error", () => resolve4(null));
|
|
1823
1841
|
});
|
|
1824
1842
|
}
|
|
1825
1843
|
// 枚举 DATA_DIR 下所有 session 目录,尝试连接存活的 worker.sock;失败则清理 stale socket。
|
|
@@ -2211,10 +2229,10 @@ function terminateSessionByOwnership(deps, sessionId) {
|
|
|
2211
2229
|
|
|
2212
2230
|
// src/serve/clipboard-image-upload.ts
|
|
2213
2231
|
import { mkdirSync, writeFileSync } from "fs";
|
|
2214
|
-
import { tmpdir } from "os";
|
|
2232
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
2215
2233
|
import { join as join5 } from "path";
|
|
2216
2234
|
import { nanoid as nanoid3 } from "nanoid";
|
|
2217
|
-
var DEFAULT_DATA_DIR = join5(
|
|
2235
|
+
var DEFAULT_DATA_DIR = join5(tmpdir2(), "dev-anywhere");
|
|
2218
2236
|
var MAX_CLIPBOARD_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
2219
2237
|
var MAX_CLIPBOARD_IMAGE_BASE64_LENGTH = Math.ceil(MAX_CLIPBOARD_IMAGE_BYTES / 3) * 4;
|
|
2220
2238
|
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Map([
|
|
@@ -2270,7 +2288,7 @@ function saveClipboardImageUpload(request, options = {}) {
|
|
|
2270
2288
|
|
|
2271
2289
|
// src/serve/file-download.ts
|
|
2272
2290
|
import { readFileSync as readFileSync5, realpathSync, statSync } from "fs";
|
|
2273
|
-
import { extname, isAbsolute as
|
|
2291
|
+
import { extname, isAbsolute as isAbsolute3, resolve as resolve2 } from "path";
|
|
2274
2292
|
var MAX_FILE_DOWNLOAD_BYTES = 100 * 1024 * 1024;
|
|
2275
2293
|
var EXT_MIME_MAP = {
|
|
2276
2294
|
".png": "image/png",
|
|
@@ -2305,7 +2323,7 @@ function guessMimeType(filePath) {
|
|
|
2305
2323
|
return EXT_MIME_MAP[ext] ?? "application/octet-stream";
|
|
2306
2324
|
}
|
|
2307
2325
|
function resolveDownloadPath(rawPath, cwd) {
|
|
2308
|
-
const candidate =
|
|
2326
|
+
const candidate = isAbsolute3(rawPath) ? resolve2(rawPath) : resolve2(cwd, rawPath);
|
|
2309
2327
|
return realpathSync(candidate);
|
|
2310
2328
|
}
|
|
2311
2329
|
function errorCode(err) {
|
|
@@ -2359,10 +2377,10 @@ function loadFileDownload(request, options) {
|
|
|
2359
2377
|
|
|
2360
2378
|
// src/serve/file-upload.ts
|
|
2361
2379
|
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
2362
|
-
import { tmpdir as
|
|
2380
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
2363
2381
|
import { extname as extname2, join as join6 } from "path";
|
|
2364
2382
|
import { nanoid as nanoid4 } from "nanoid";
|
|
2365
|
-
var DEFAULT_DATA_DIR2 = join6(
|
|
2383
|
+
var DEFAULT_DATA_DIR2 = join6(tmpdir3(), "dev-anywhere");
|
|
2366
2384
|
var MAX_FILE_UPLOAD_BYTES = 100 * 1024 * 1024;
|
|
2367
2385
|
var MAX_FILE_UPLOAD_BASE64_LENGTH = Math.ceil(MAX_FILE_UPLOAD_BYTES / 3) * 4;
|
|
2368
2386
|
var SAFE_EXT_RE = /^[A-Za-z0-9]{1,6}$/;
|
|
@@ -2409,15 +2427,15 @@ async function saveFileUpload(request, options = {}) {
|
|
|
2409
2427
|
|
|
2410
2428
|
// src/serve/image-preview.ts
|
|
2411
2429
|
import { readFileSync as readFileSync6, realpathSync as realpathSync2, statSync as statSync2 } from "fs";
|
|
2412
|
-
import { tmpdir as
|
|
2413
|
-
import { isAbsolute as
|
|
2430
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
2431
|
+
import { isAbsolute as isAbsolute4, relative, resolve as resolve3 } from "path";
|
|
2414
2432
|
var MAX_IMAGE_PREVIEW_BYTES = 10 * 1024 * 1024;
|
|
2415
2433
|
function isInsideRoot(realFilePath, realRootPath) {
|
|
2416
2434
|
const rel = relative(realRootPath, realFilePath);
|
|
2417
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
2435
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
|
|
2418
2436
|
}
|
|
2419
2437
|
function allowedRoots(options) {
|
|
2420
|
-
return [options.cwd, options.tmpDir ??
|
|
2438
|
+
return [options.cwd, options.tmpDir ?? tmpdir4(), ...options.previewRoots ?? []].map((root) => root.trim()).filter(Boolean).flatMap((root) => {
|
|
2421
2439
|
try {
|
|
2422
2440
|
return [realpathSync2(root)];
|
|
2423
2441
|
} catch {
|
|
@@ -2426,7 +2444,7 @@ function allowedRoots(options) {
|
|
|
2426
2444
|
});
|
|
2427
2445
|
}
|
|
2428
2446
|
function resolvePreviewPath(rawPath, options) {
|
|
2429
|
-
const candidate =
|
|
2447
|
+
const candidate = isAbsolute4(rawPath) ? resolve3(rawPath) : resolve3(options.cwd, rawPath);
|
|
2430
2448
|
const realCandidate = realpathSync2(candidate);
|
|
2431
2449
|
if (!allowedRoots(options).some((root) => isInsideRoot(realCandidate, root))) {
|
|
2432
2450
|
throw Object.assign(new Error("\u56FE\u7247\u8DEF\u5F84\u4E0D\u5728\u5141\u8BB8\u9884\u89C8\u7684\u76EE\u5F55\u5185"), {
|
|
@@ -3099,7 +3117,7 @@ var RelayResourceHandlers = class {
|
|
|
3099
3117
|
|
|
3100
3118
|
// src/serve/relay-session-create-handler.ts
|
|
3101
3119
|
import { rmSync, statSync as statSync4 } from "fs";
|
|
3102
|
-
import { isAbsolute as
|
|
3120
|
+
import { isAbsolute as isAbsolute5 } from "path";
|
|
3103
3121
|
import { nanoid as nanoid5 } from "nanoid";
|
|
3104
3122
|
|
|
3105
3123
|
// src/serve/hosted-pty-registry.ts
|
|
@@ -3377,7 +3395,7 @@ function validateSessionCwd(cwd) {
|
|
|
3377
3395
|
return { message: "\u8BF7\u8F93\u5165\u5DE5\u4F5C\u76EE\u5F55", code: ControlErrorCode.INVALID_PATH };
|
|
3378
3396
|
}
|
|
3379
3397
|
const trimmed = cwd.trim();
|
|
3380
|
-
if (!
|
|
3398
|
+
if (!isAbsolute5(trimmed)) {
|
|
3381
3399
|
return { message: "\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84", code: ControlErrorCode.INVALID_PATH };
|
|
3382
3400
|
}
|
|
3383
3401
|
try {
|
|
@@ -3741,7 +3759,7 @@ function buildClaudeSpeechSummaryCommand({
|
|
|
3741
3759
|
}
|
|
3742
3760
|
var runClaudeSpeechSummary = ({ cwd, prompt, env, timeoutMs }) => {
|
|
3743
3761
|
const { command, args } = buildClaudeSpeechSummaryCommand({ env, prompt });
|
|
3744
|
-
return new Promise((
|
|
3762
|
+
return new Promise((resolve4, reject) => {
|
|
3745
3763
|
const child = spawn2(command, args, {
|
|
3746
3764
|
cwd,
|
|
3747
3765
|
env: { ...process.env, ...env },
|
|
@@ -3773,7 +3791,7 @@ var runClaudeSpeechSummary = ({ cwd, prompt, env, timeoutMs }) => {
|
|
|
3773
3791
|
clearTimeout(timer);
|
|
3774
3792
|
const stdout = Buffer.concat(stdoutChunks).toString("utf8").trim();
|
|
3775
3793
|
if (code === 0 && stdout.length > 0) {
|
|
3776
|
-
|
|
3794
|
+
resolve4(stdout);
|
|
3777
3795
|
return;
|
|
3778
3796
|
}
|
|
3779
3797
|
const stderr = Buffer.concat(stderrChunks).toString("utf8").trim();
|
|
@@ -4282,11 +4300,11 @@ var PermissionBroker = class {
|
|
|
4282
4300
|
if (this.pending.has(request.requestId)) {
|
|
4283
4301
|
return Promise.resolve(DUPLICATE_DECISION);
|
|
4284
4302
|
}
|
|
4285
|
-
return new Promise((
|
|
4303
|
+
return new Promise((resolve4) => {
|
|
4286
4304
|
this.pending.set(request.requestId, {
|
|
4287
4305
|
...request,
|
|
4288
4306
|
source: "hook",
|
|
4289
|
-
resolve:
|
|
4307
|
+
resolve: resolve4,
|
|
4290
4308
|
createdAt: Date.now()
|
|
4291
4309
|
});
|
|
4292
4310
|
});
|
|
@@ -4669,10 +4687,10 @@ import { existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
|
|
|
4669
4687
|
import { hostname } from "os";
|
|
4670
4688
|
import { connect as connect2 } from "net";
|
|
4671
4689
|
function tryConnectSocket(sockPath) {
|
|
4672
|
-
return new Promise((
|
|
4690
|
+
return new Promise((resolve4) => {
|
|
4673
4691
|
const s = connect2(sockPath);
|
|
4674
|
-
s.on("connect", () =>
|
|
4675
|
-
s.on("error", () =>
|
|
4692
|
+
s.on("connect", () => resolve4(s));
|
|
4693
|
+
s.on("error", () => resolve4(null));
|
|
4676
4694
|
});
|
|
4677
4695
|
}
|
|
4678
4696
|
function isProcessAlive(pid) {
|
|
@@ -5160,7 +5178,7 @@ var HookServer = class {
|
|
|
5160
5178
|
this.writeJson(res, 500, { error: "internal_error" });
|
|
5161
5179
|
});
|
|
5162
5180
|
});
|
|
5163
|
-
return new Promise((
|
|
5181
|
+
return new Promise((resolve4, reject) => {
|
|
5164
5182
|
const onError = (err) => {
|
|
5165
5183
|
this.server?.off("listening", onListening);
|
|
5166
5184
|
reject(err);
|
|
@@ -5168,7 +5186,7 @@ var HookServer = class {
|
|
|
5168
5186
|
const onListening = () => {
|
|
5169
5187
|
this.server?.off("error", onError);
|
|
5170
5188
|
serviceLogger.info({ host: this.host, port: this.options.port }, "Hook server listening");
|
|
5171
|
-
|
|
5189
|
+
resolve4();
|
|
5172
5190
|
};
|
|
5173
5191
|
this.server.once("error", onError);
|
|
5174
5192
|
this.server.once("listening", onListening);
|
|
@@ -5179,8 +5197,8 @@ var HookServer = class {
|
|
|
5179
5197
|
if (!this.server) return Promise.resolve();
|
|
5180
5198
|
const server = this.server;
|
|
5181
5199
|
this.server = null;
|
|
5182
|
-
return new Promise((
|
|
5183
|
-
server.close((err) => err ? reject(err) :
|
|
5200
|
+
return new Promise((resolve4, reject) => {
|
|
5201
|
+
server.close((err) => err ? reject(err) : resolve4());
|
|
5184
5202
|
});
|
|
5185
5203
|
}
|
|
5186
5204
|
getListeningPort() {
|
|
@@ -5294,7 +5312,7 @@ var HookServer = class {
|
|
|
5294
5312
|
this.writeJson(res, 200, payload);
|
|
5295
5313
|
}
|
|
5296
5314
|
readBody(req) {
|
|
5297
|
-
return new Promise((
|
|
5315
|
+
return new Promise((resolve4, reject) => {
|
|
5298
5316
|
let body = "";
|
|
5299
5317
|
let size = 0;
|
|
5300
5318
|
req.setEncoding("utf8");
|
|
@@ -5307,7 +5325,7 @@ var HookServer = class {
|
|
|
5307
5325
|
}
|
|
5308
5326
|
body += chunk;
|
|
5309
5327
|
});
|
|
5310
|
-
req.on("end", () =>
|
|
5328
|
+
req.on("end", () => resolve4(body));
|
|
5311
5329
|
req.on("error", reject);
|
|
5312
5330
|
});
|
|
5313
5331
|
}
|