@agent-dock/cli 0.3.22 → 0.3.24

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 CHANGED
@@ -24062,7 +24062,7 @@ init_src2();
24062
24062
  import { createReadStream, realpathSync as realpathSync3 } from "node:fs";
24063
24063
  import { readdir as readdir3, readFile as readFile11, stat as stat5 } from "node:fs/promises";
24064
24064
  import { homedir as homedir13 } from "node:os";
24065
- import { basename as basename7, isAbsolute as isAbsolute7, join as join19, relative, sep as sep2 } from "node:path";
24065
+ import { basename as basename7, dirname as dirname11, isAbsolute as isAbsolute7, join as join19, relative, sep as sep2 } from "node:path";
24066
24066
 
24067
24067
  // src/fs-paths.ts
24068
24068
  import { existsSync as existsSync8, realpathSync as realpathSync2 } from "node:fs";
@@ -24305,6 +24305,10 @@ function mediaMimeForName(name) {
24305
24305
  }
24306
24306
 
24307
24307
  // src/fs-routes.ts
24308
+ var DEFAULT_MAX_DIR_ENTRIES = 500;
24309
+ function compareEntryName(left, right) {
24310
+ return left.localeCompare(right, void 0, { numeric: true, sensitivity: "base" });
24311
+ }
24308
24312
  function badPath(error) {
24309
24313
  if (error instanceof RuntimeError) throw error;
24310
24314
  if (error instanceof WorkspacePathError) throw new RuntimeError("INVALID_PATH", error.message, 400);
@@ -24378,36 +24382,36 @@ async function registerFsRoutes(app, runtime, options = {}) {
24378
24382
  }
24379
24383
  const userPath = request.query.path;
24380
24384
  if (!userPath) throw new RuntimeError("INVALID_PATH", "\u7F3A\u5C11 path \u53C2\u6570", 400);
24381
- const expandedPath = userPath.startsWith("~/") ? join19(options.homeDir ?? homedir13(), userPath.slice(2)) : userPath;
24385
+ const homeDir = options.homeDir ?? homedir13();
24386
+ const expandedPath = userPath === "~" ? homeDir : userPath.startsWith("~/") ? join19(homeDir, userPath.slice(2)) : userPath;
24382
24387
  if (isSensitivePath(userPath) || isSensitivePath(expandedPath)) {
24383
24388
  throw new RuntimeError("SENSITIVE_FILE_BLOCKED", "\u7981\u6B62\u9884\u89C8\u6216\u4E0B\u8F7D\u654F\u611F\u6587\u4EF6", 403);
24384
24389
  }
24385
24390
  const claim = request.webClaim;
24386
24391
  const role = claim?.kind === "session" ? "session" : "master";
24392
+ const sessionRoots = role === "session" ? allowedReadRoots({
24393
+ role,
24394
+ cwd: session.cwd,
24395
+ sessionId: request.params.id,
24396
+ ...options.homeDir ? { homeDir: options.homeDir } : {},
24397
+ ...options.tempDir ? { tempDir: options.tempDir } : {},
24398
+ ...options.extraMasterRoots ? { extraMasterRoots: options.extraMasterRoots } : {}
24399
+ }) : void 0;
24400
+ let realCwd;
24401
+ try {
24402
+ realCwd = realpathSync3(session.cwd);
24403
+ } catch {
24404
+ }
24387
24405
  let resolved;
24388
24406
  try {
24389
24407
  if (isAbsolute7(expandedPath)) {
24390
24408
  const realTarget = realpathSync3(expandedPath);
24391
- if (role === "session") {
24392
- const roots = allowedReadRoots({
24393
- role,
24394
- cwd: session.cwd,
24395
- sessionId: request.params.id,
24396
- ...options.homeDir ? { homeDir: options.homeDir } : {},
24397
- ...options.tempDir ? { tempDir: options.tempDir } : {},
24398
- ...options.extraMasterRoots ? { extraMasterRoots: options.extraMasterRoots } : {}
24399
- });
24400
- if (!isRealPathWithinRoots(realTarget, roots)) {
24401
- throw new RuntimeError("FORBIDDEN", "\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5\u53EA\u80FD\u9884\u89C8\u8BE5\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u53CA\u4E0A\u4F20\u76EE\u5F55\u5185\u7684\u6587\u4EF6", 403);
24402
- }
24409
+ if (role === "session" && !isRealPathWithinRoots(realTarget, sessionRoots ?? [])) {
24410
+ throw new RuntimeError("FORBIDDEN", "\u4F1A\u8BDD\u5206\u4EAB\u94FE\u63A5\u53EA\u80FD\u9884\u89C8\u8BE5\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u53CA\u4E0A\u4F20\u76EE\u5F55\u5185\u7684\u6587\u4EF6", 403);
24403
24411
  }
24404
24412
  let rel = expandedPath;
24405
- try {
24406
- const realCwd = realpathSync3(session.cwd);
24407
- if (realTarget === realCwd || realTarget.startsWith(`${realCwd}${sep2}`)) {
24408
- rel = relative(realCwd, realTarget);
24409
- }
24410
- } catch {
24413
+ if (realCwd && (realTarget === realCwd || realTarget.startsWith(`${realCwd}${sep2}`))) {
24414
+ rel = relative(realCwd, realTarget);
24411
24415
  }
24412
24416
  resolved = { absolute: realTarget, relative: rel };
24413
24417
  } else {
@@ -24425,10 +24429,96 @@ async function registerFsRoutes(app, runtime, options = {}) {
24425
24429
  } catch (error) {
24426
24430
  badPath(error);
24427
24431
  }
24432
+ const wantDownload = request.query.download === "1" || request.query.download === "true";
24433
+ if (info.isDirectory()) {
24434
+ if (wantDownload) {
24435
+ throw new RuntimeError("NOT_A_FILE", "\u76EE\u5F55\u4E0D\u652F\u6301\u76F4\u63A5\u4E0B\u8F7D", 400);
24436
+ }
24437
+ const includeHidden = request.query.hidden === "1" || request.query.hidden === "true";
24438
+ let dirents;
24439
+ try {
24440
+ dirents = await readdir3(resolved.absolute, { withFileTypes: true });
24441
+ } catch (error) {
24442
+ badPath(error);
24443
+ }
24444
+ let hiddenCount = 0;
24445
+ const candidates = [];
24446
+ for (const dirent of dirents) {
24447
+ if (dirent.name === ".DS_Store") continue;
24448
+ const isHidden = dirent.name.startsWith(".");
24449
+ if (isHidden) {
24450
+ hiddenCount++;
24451
+ if (!includeHidden) continue;
24452
+ }
24453
+ candidates.push(dirent);
24454
+ }
24455
+ candidates.sort((left, right) => {
24456
+ const leftDir = left.isDirectory();
24457
+ const rightDir = right.isDirectory();
24458
+ if (leftDir !== rightDir) return leftDir ? -1 : 1;
24459
+ return compareEntryName(left.name, right.name);
24460
+ });
24461
+ const limit = Math.max(1, options.maxDirEntries ?? DEFAULT_MAX_DIR_ENTRIES);
24462
+ const totalCount = candidates.length;
24463
+ const sliced = candidates.slice(0, limit);
24464
+ const useAbsoluteEntryPath = !realCwd || !(resolved.absolute === realCwd || resolved.absolute.startsWith(`${realCwd}${sep2}`));
24465
+ const entries = [];
24466
+ await Promise.all(sliced.map(async (dirent) => {
24467
+ const entryAbs = join19(resolved.absolute, dirent.name);
24468
+ const entryPath = useAbsoluteEntryPath ? entryAbs : resolved.relative ? `${resolved.relative}/${dirent.name}` : dirent.name;
24469
+ try {
24470
+ const entryStat = await stat5(entryAbs);
24471
+ entries.push({
24472
+ name: dirent.name,
24473
+ path: entryPath,
24474
+ kind: entryStat.isDirectory() ? "directory" : "file",
24475
+ size: entryStat.isDirectory() ? 0 : entryStat.size,
24476
+ mtime: entryStat.mtime.toISOString()
24477
+ });
24478
+ } catch {
24479
+ if (!dirent.isSymbolicLink()) {
24480
+ entries.push({
24481
+ name: dirent.name,
24482
+ path: entryPath,
24483
+ kind: dirent.isDirectory() ? "directory" : "file",
24484
+ size: 0,
24485
+ mtime: ""
24486
+ });
24487
+ }
24488
+ }
24489
+ }));
24490
+ entries.sort((left, right) => {
24491
+ if (left.kind !== right.kind) return left.kind === "directory" ? -1 : 1;
24492
+ return compareEntryName(left.name, right.name);
24493
+ });
24494
+ const parentAbs = dirname11(resolved.absolute);
24495
+ let parentPath = null;
24496
+ if (parentAbs !== resolved.absolute && !isSensitivePath(parentAbs)) {
24497
+ const parentAllowed = role === "master" || isRealPathWithinRoots(parentAbs, sessionRoots ?? []);
24498
+ if (parentAllowed) {
24499
+ if (realCwd && (parentAbs === realCwd || parentAbs.startsWith(`${realCwd}${sep2}`))) {
24500
+ parentPath = relative(realCwd, parentAbs) || realCwd;
24501
+ } else {
24502
+ parentPath = parentAbs;
24503
+ }
24504
+ }
24505
+ }
24506
+ return {
24507
+ kind: "directory",
24508
+ cwd: session.cwd,
24509
+ path: resolved.relative || resolved.absolute,
24510
+ absolutePath: resolved.absolute,
24511
+ parentPath,
24512
+ entries,
24513
+ totalCount,
24514
+ truncated: totalCount > entries.length,
24515
+ hiddenCount,
24516
+ includeHidden
24517
+ };
24518
+ }
24428
24519
  if (!info.isFile()) throw new RuntimeError("NOT_A_FILE", "\u76EE\u6807\u4E0D\u662F\u6587\u4EF6", 400);
24429
24520
  const filename = basename7(resolved.absolute);
24430
24521
  const isSvg = filename.toLowerCase().endsWith(".svg");
24431
- const wantDownload = request.query.download === "1" || request.query.download === "true";
24432
24522
  const wantText = request.query.format === "text";
24433
24523
  if (wantDownload) {
24434
24524
  const contentType = imageMimeForName(filename) ?? mediaMimeForName(filename) ?? (filename.toLowerCase().endsWith(".pdf") ? "application/pdf" : "application/octet-stream");
@@ -24487,7 +24577,7 @@ async function registerFsRoutes(app, runtime, options = {}) {
24487
24577
  if (isBinaryBuffer(buffer)) {
24488
24578
  throw new RuntimeError("BINARY_FILE", "\u68C0\u6D4B\u5230\u4E8C\u8FDB\u5236\u6587\u4EF6\u5185\u5BB9\uFF0C\u6682\u4E0D\u652F\u6301\u6587\u672C\u9884\u89C8\uFF0C\u8BF7\u4E0B\u8F7D\u67E5\u770B", 415);
24489
24579
  }
24490
- return { cwd: session.cwd, path: resolved.relative, size: info.size, content: buffer.toString("utf8") };
24580
+ return { kind: "file", cwd: session.cwd, path: resolved.relative, size: info.size, content: buffer.toString("utf8") };
24491
24581
  });
24492
24582
  }
24493
24583
 
@@ -25280,7 +25370,7 @@ function registerJsonCompression(app, threshold = JSON_COMPRESSION_THRESHOLD) {
25280
25370
  import { randomBytes as randomBytes3, scryptSync, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
25281
25371
  import { chmodSync as chmodSync2, existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "node:fs";
25282
25372
  import { homedir as homedir15 } from "node:os";
25283
- import { dirname as dirname11, join as join21 } from "node:path";
25373
+ import { dirname as dirname12, join as join21 } from "node:path";
25284
25374
  var webPasswordFileName = "web-password";
25285
25375
  var SCRYPT_N = 16384;
25286
25376
  var SCRYPT_R = 8;
@@ -25322,7 +25412,7 @@ function webPasswordEnabled(path5 = webPasswordPath()) {
25322
25412
  }
25323
25413
  function setWebPassword(password, path5 = webPasswordPath()) {
25324
25414
  if (password.length < minWebPasswordLength) throw new Error(`\u5BC6\u7801\u81F3\u5C11 ${minWebPasswordLength} \u4F4D\u3002`);
25325
- mkdirSync5(dirname11(path5), { recursive: true, mode: 448 });
25415
+ mkdirSync5(dirname12(path5), { recursive: true, mode: 448 });
25326
25416
  writeFileSync4(path5, `${hashWebPassword(password)}
25327
25417
  `, { mode: 384 });
25328
25418
  chmodSync2(path5, 384);
@@ -34705,7 +34795,7 @@ async function runLarkAvatarReactionRoute(options) {
34705
34795
  import { spawn as spawn13 } from "node:child_process";
34706
34796
  import { readFileSync as readFileSync11 } from "node:fs";
34707
34797
  import { createRequire as createRequire3 } from "node:module";
34708
- import { dirname as dirname12, resolve as resolve13 } from "node:path";
34798
+ import { dirname as dirname13, resolve as resolve13 } from "node:path";
34709
34799
  function acpxPassThroughArgs(argv) {
34710
34800
  return argv[2] === "acpx" ? argv.slice(3) : void 0;
34711
34801
  }
@@ -34715,7 +34805,7 @@ function resolveAcpxLauncher(moduleUrl = import.meta.url) {
34715
34805
  const manifestPath = require2.resolve("acpx/package.json");
34716
34806
  const manifest = JSON.parse(readFileSync11(manifestPath, "utf8"));
34717
34807
  const relative2 = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.acpx;
34718
- if (relative2) return { command: process.execPath, args: [resolve13(dirname12(manifestPath), relative2)] };
34808
+ if (relative2) return { command: process.execPath, args: [resolve13(dirname13(manifestPath), relative2)] };
34719
34809
  } catch {
34720
34810
  return { command: "acpx", args: [] };
34721
34811
  }
@@ -35133,14 +35223,14 @@ init_session_cli();
35133
35223
  import { spawnSync as spawnSync3 } from "node:child_process";
35134
35224
  import { chmodSync as chmodSync3, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync13, rmSync as rmSync4, writeFileSync as writeFileSync5 } from "node:fs";
35135
35225
  import { createServer } from "node:net";
35136
- import { delimiter as delimiter2, dirname as dirname13, join as join24, resolve as resolve15 } from "node:path";
35226
+ import { delimiter as delimiter2, dirname as dirname14, join as join24, resolve as resolve15 } from "node:path";
35137
35227
  init_daemon();
35138
35228
  var SANDBOX_FILE = "sandbox.json";
35139
35229
  function findRepoRoot(start = process.cwd()) {
35140
35230
  let dir = resolve15(start);
35141
35231
  for (; ; ) {
35142
35232
  if (existsSync12(join24(dir, "apps", "server", "package.json")) && existsSync12(join24(dir, "pnpm-workspace.yaml"))) return dir;
35143
- const parent = dirname13(dir);
35233
+ const parent = dirname14(dir);
35144
35234
  if (parent === dir) throw new Error("\u627E\u4E0D\u5230 agent-dock \u6E90\u7801\u4ED3\u5E93\u3002\u8BF7\u5728\u4ED3\u5E93\u76EE\u5F55\u4E0B\u8FD0\u884C agent-dock dev\uFF0C\u6216\u7528 --repo \u6307\u5B9A\u3002");
35145
35235
  dir = parent;
35146
35236
  }