@cydm/happy-elves 0.1.0-beta.46 → 0.1.0-beta.47

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.
@@ -1,10 +1,11 @@
1
1
  import fs from "node:fs/promises";
2
+ import os from "node:os";
2
3
  import path from "node:path";
3
4
  import { claimCommandRequest, sendCommandResponse } from "../relay/send.js";
4
- import { assertPathInsideWorkspace, pathInsideRoot, workspaceRealRoots } from "./workspace-paths.js";
5
+ import { isUncPath, workspaceRealRoots } from "./workspace-paths.js";
5
6
  const directoryEntryLimit = 500;
6
7
  const directoryStatConcurrency = 16;
7
- async function findRepoRoot(startPath, workspaceRoots) {
8
+ async function findRepoRoot(startPath) {
8
9
  let current = startPath;
9
10
  while (true) {
10
11
  try {
@@ -15,16 +16,42 @@ async function findRepoRoot(startPath, workspaceRoots) {
15
16
  const parent = path.dirname(current);
16
17
  if (parent === current)
17
18
  return null;
18
- if (!workspaceRoots.some((root) => pathInsideRoot(root, parent)))
19
- return null;
20
19
  current = parent;
21
20
  }
22
21
  }
23
22
  }
23
+ async function directoryRoots(workspaceRoots, currentPath) {
24
+ const roots = [];
25
+ const seen = new Set();
26
+ async function add(candidate, label) {
27
+ if (!candidate || isUncPath(candidate))
28
+ return;
29
+ try {
30
+ const real = await fs.realpath(path.resolve(candidate));
31
+ if (seen.has(real))
32
+ return;
33
+ seen.add(real);
34
+ roots.push({ name: (label ?? path.basename(real)) || real, path: real });
35
+ }
36
+ catch {
37
+ // Optional navigation shortcuts should not break directory listing.
38
+ }
39
+ }
40
+ for (const root of workspaceRoots)
41
+ await add(root);
42
+ await add(os.homedir(), "home");
43
+ await add(path.parse(currentPath).root);
44
+ const homeRoot = path.parse(os.homedir()).root;
45
+ if (homeRoot !== path.parse(currentPath).root)
46
+ await add(homeRoot);
47
+ return roots;
48
+ }
24
49
  export async function buildDirectoryList(config, requestedPath) {
50
+ if (requestedPath && isUncPath(requestedPath)) {
51
+ throw Object.assign(new Error("UNC paths are not supported for directory browsing."), { code: "DIRECTORY_UNSUPPORTED_PATH" });
52
+ }
25
53
  const resolvedPath = path.resolve(requestedPath || process.cwd());
26
54
  const realPath = await fs.realpath(resolvedPath);
27
- await assertPathInsideWorkspace(realPath);
28
55
  const workspaceRoots = await workspaceRealRoots();
29
56
  const entries = [];
30
57
  let truncated = false;
@@ -66,13 +93,12 @@ export async function buildDirectoryList(config, requestedPath) {
66
93
  return a.name.localeCompare(b.name);
67
94
  });
68
95
  const parentPath = path.dirname(realPath);
69
- const parentInsideWorkspace = parentPath !== realPath && workspaceRoots.some((root) => pathInsideRoot(root, parentPath));
70
96
  return {
71
97
  machineId: config.machineId,
72
98
  path: realPath,
73
- parentPath: parentInsideWorkspace ? parentPath : null,
74
- repoRoot: await findRepoRoot(realPath, workspaceRoots),
75
- roots: workspaceRoots.map((root) => ({ name: path.basename(root) || root, path: root })),
99
+ parentPath: parentPath !== realPath ? parentPath : null,
100
+ repoRoot: await findRepoRoot(realPath),
101
+ roots: await directoryRoots(workspaceRoots, realPath),
76
102
  entries: sortedEntries,
77
103
  truncated,
78
104
  entryLimit: directoryEntryLimit,
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { appendAudit } from "../audit.js";
4
4
  import { claimCommandRequest, sendCommandResponse } from "../relay/send.js";
5
- import { assertRootInsideWorkspace, isUncPath, pathInsideRoot } from "./workspace-paths.js";
5
+ import { isUncPath, pathInsideRoot } from "./workspace-paths.js";
6
6
  const textLimitBytes = 256 * 1024;
7
7
  const textHardLimitBytes = 1024 * 1024;
8
8
  const imageLimitBytes = 16 * 1024 * 1024;
@@ -60,7 +60,6 @@ export async function buildFilePreview(config, rootPath, requestedPath, mode = "
60
60
  ? requestedPath
61
61
  : path.resolve(rootAbsolutePath, requestedPath);
62
62
  const rootRealPath = await fs.realpath(rootAbsolutePath);
63
- await assertRootInsideWorkspace(rootRealPath);
64
63
  const targetRealPath = await fs.realpath(targetPath);
65
64
  assertInsideRoot(rootRealPath, targetRealPath);
66
65
  const stat = await fs.stat(targetRealPath);
@@ -1,5 +1,3 @@
1
1
  export declare function workspaceRealRoots(): Promise<string[]>;
2
- export declare function assertPathInsideWorkspace(realPath: string): Promise<void>;
3
- export declare function assertRootInsideWorkspace(rootRealPath: string): Promise<void>;
4
2
  export declare function pathInsideRoot(rootPath: string, targetPath: string): boolean;
5
3
  export declare function isUncPath(input: string): boolean;
@@ -16,23 +16,11 @@ export async function workspaceRealRoots() {
16
16
  roots.push(real);
17
17
  }
18
18
  catch {
19
- // A stale session cwd should not widen or break the daemon workspace boundary.
19
+ // A stale session cwd should not break directory root shortcuts.
20
20
  }
21
21
  }
22
22
  return roots;
23
23
  }
24
- export async function assertPathInsideWorkspace(realPath) {
25
- const roots = await workspaceRealRoots();
26
- if (roots.some((root) => pathInsideRoot(root, realPath)))
27
- return;
28
- throw Object.assign(new Error("Path must stay inside a known workspace."), { code: "WORKSPACE_PATH_FORBIDDEN" });
29
- }
30
- export async function assertRootInsideWorkspace(rootRealPath) {
31
- const roots = await workspaceRealRoots();
32
- if (roots.some((root) => pathInsideRoot(root, rootRealPath)))
33
- return;
34
- throw Object.assign(new Error("Root path must stay inside a known workspace."), { code: "WORKSPACE_ROOT_FORBIDDEN" });
35
- }
36
24
  export function pathInsideRoot(rootPath, targetPath) {
37
25
  const relative = path.relative(rootPath, targetPath);
38
26
  return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/happy-elves-daemon",
3
- "version": "0.1.0-beta.46",
3
+ "version": "0.1.0-beta.47",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@cydm/happy-elves",
3
- "version": "0.1.0-beta.46",
3
+ "version": "0.1.0-beta.47",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@cydm/happy-elves",
9
- "version": "0.1.0-beta.46",
9
+ "version": "0.1.0-beta.47",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@fastify/cors": "11.2.0",
@@ -799,9 +799,9 @@
799
799
  }
800
800
  },
801
801
  "node_modules/bare-os": {
802
- "version": "3.9.1",
803
- "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.9.1.tgz",
804
- "integrity": "sha512-6M5XjcnsygQNPMCMPXSK379xrJFiZ/AEMNBmFEmQW8d/789VQATvriyi5r0HYTL9TkQ26rn3kgdTG3aisbrXkQ==",
802
+ "version": "3.9.3",
803
+ "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.9.3.tgz",
804
+ "integrity": "sha512-fF4Q7QsyKVF5Rj0qvI8BgUNjqzC2JvQlpTaPLjVJVxYVUX5Zr9un+y3w1HmA4nNKdFmRBT8z/WmrjvXzXVerKQ==",
805
805
  "license": "Apache-2.0",
806
806
  "engines": {
807
807
  "bare": ">=1.14.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/happy-elves",
3
- "version": "0.1.0-beta.46",
3
+ "version": "0.1.0-beta.47",
4
4
  "description": "Remote controller for local coding agents with hosted or self-hosted relay support.",
5
5
  "type": "module",
6
6
  "bin": {