@av-pi-studio/server 0.0.100 → 0.0.101

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.
@@ -668,6 +668,10 @@ export function startDaemon(opts) {
668
668
  serverId,
669
669
  hostname: opts.host,
670
670
  version: "1.0.0",
671
+ // Same value the direct-WS handshake reports (`ws/ws-server.ts`): the DAEMON's home
672
+ // dir, which a relay-remote client (different machine, possibly different OS) has no
673
+ // other way to learn.
674
+ homeDir: homedir(),
671
675
  capabilities: {},
672
676
  features: Object.fromEntries(Object.values(SERVER_FEATURES).map((k) => [k, true])),
673
677
  });
@@ -2,12 +2,18 @@ import { randomUUID } from "node:crypto";
2
2
  import { chmod, lstat, mkdir, open, readdir, realpath, rename, rm, stat, writeFile as writeFileFs, } from "node:fs/promises";
3
3
  import { basename, dirname, extname, join, resolve } from "node:path";
4
4
  import { MAX_INLINE_FILE_READ_BYTES } from "./limits.js";
5
+ import { expandHome } from "./resolve-path.js";
5
6
  /**
6
7
  * File explorer: directory listing + file preview with server-side path normalization and symlink
7
8
  * resolution (features/file-explorer-transfer.md § Behavior (listOrPreview), § Trust boundary;
8
9
  * architecture/auth-security.md § Trust model). Connected clients are trusted operators — a preview
9
10
  * may read any regular file the daemon can read; workspace-relative paths are a UI convenience, not a
10
11
  * security boundary. Normalization/symlink checks stay server-side.
12
+ *
13
+ * Every client-supplied path goes through `expandHome` first (root `AGENTS.md` invariant 7), so a
14
+ * `~`/`~/…` path resolves against the DAEMON's home directory — the same expansion `file_read`,
15
+ * `file_watch`, and the download-token handler already do. Without it `resolve("~")` would silently
16
+ * produce `<daemon cwd>/~`, which is why the web UI's home-directory browsing looked broken.
11
17
  */
12
18
  const DEFAULT_PREVIEW_BYTES = 256 * 1024;
13
19
  const BINARY_SNIFF_BYTES = 8192;
@@ -63,7 +69,7 @@ export class FileExplorerService {
63
69
  }
64
70
  let resolvedParent;
65
71
  try {
66
- resolvedParent = await realpath(resolve(parentPath));
72
+ resolvedParent = await realpath(resolve(expandHome(parentPath)));
67
73
  }
68
74
  catch {
69
75
  return { ok: false, error: "not_found" };
@@ -107,9 +113,14 @@ export class FileExplorerService {
107
113
  async moveEntry(inputPath, inputDestination) {
108
114
  if (!inputPath || !inputDestination)
109
115
  return { ok: false, error: "empty_path" };
116
+ // `~` is expanded before any `dirname`/`basename` split (root `AGENTS.md` invariant 7):
117
+ // splitting first would leave a bare `~` as the parent path, which `resolve()` would then
118
+ // join onto the daemon's own cwd instead of the home directory.
119
+ const sourceInput = expandHome(inputPath);
120
+ const destinationInput = expandHome(inputDestination);
110
121
  let source;
111
122
  try {
112
- source = join(await realpath(resolve(dirname(inputPath))), basename(inputPath));
123
+ source = join(await realpath(resolve(dirname(sourceInput))), basename(sourceInput));
113
124
  }
114
125
  catch {
115
126
  return { ok: false, error: "not_found" };
@@ -120,9 +131,9 @@ export class FileExplorerService {
120
131
  // would validate as `foo.txt` but land on disk with the trailing space. Trim once and use
121
132
  // the trimmed value for BOTH the join and the guard, matching `createEntry` (which trims
122
133
  // its `rawName` before validating and joining).
123
- const destName = basename(inputDestination).trim();
134
+ const destName = basename(destinationInput).trim();
124
135
  try {
125
- destinationParent = await realpath(resolve(dirname(inputDestination)));
136
+ destinationParent = await realpath(resolve(dirname(destinationInput)));
126
137
  destination = join(destinationParent, destName);
127
138
  }
128
139
  catch {
@@ -191,7 +202,7 @@ export class FileExplorerService {
191
202
  }
192
203
  let resolvedPath;
193
204
  try {
194
- resolvedPath = await realpath(resolve(inputPath));
205
+ resolvedPath = await realpath(resolve(expandHome(inputPath)));
195
206
  }
196
207
  catch {
197
208
  return { ok: false, error: "not_found" };
@@ -227,7 +238,7 @@ export class FileExplorerService {
227
238
  async listOrPreview(inputPath) {
228
239
  if (!inputPath)
229
240
  return { ok: false, error: "empty_path" };
230
- const normalized = resolve(inputPath);
241
+ const normalized = resolve(expandHome(inputPath));
231
242
  let resolvedPath;
232
243
  try {
233
244
  resolvedPath = await realpath(normalized); // server-side symlink resolution
@@ -266,7 +277,7 @@ export class FileExplorerService {
266
277
  return { ok: false, error: "empty_path" };
267
278
  let resolvedPath;
268
279
  try {
269
- resolvedPath = await realpath(resolve(inputPath));
280
+ resolvedPath = await realpath(resolve(expandHome(inputPath)));
270
281
  }
271
282
  catch {
272
283
  return { ok: false, error: "not_found" };
@@ -362,7 +373,7 @@ export class FileExplorerService {
362
373
  if (!base)
363
374
  return [];
364
375
  try {
365
- const resolved = await realpath(resolve(base));
376
+ const resolved = await realpath(resolve(expandHome(base)));
366
377
  const dirents = await readdir(resolved, { withFileTypes: true });
367
378
  return dirents
368
379
  .filter((d) => d.isDirectory() && !d.name.startsWith("."))
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { homedir } from "node:os";
2
3
  import { helloSchema, SERVER_FEATURES, serverInfoPayloadSchema, statusSchema, } from "@av-pi-studio/protocol";
3
4
  import { WebSocketServer } from "ws";
4
5
  import { WS_BEARER_SUBPROTOCOL_PREFIX } from "../auth/password-auth.js";
@@ -79,6 +80,11 @@ export function createWebSocketServer(httpServer, deps) {
79
80
  serverId: deps.serverId,
80
81
  ...(deps.hostname ? { hostname: deps.hostname } : {}),
81
82
  ...(deps.version ? { version: deps.version } : {}),
83
+ // The daemon host's home dir, so a client can expand `~` paths against the machine that
84
+ // actually owns them instead of guessing from its own platform (root `AGENTS.md`
85
+ // invariant 7's client-side half). A process fact, not injected config — same posture as
86
+ // the `randomUUID()` session id above.
87
+ homeDir: homedir(),
82
88
  capabilities: deps.serverCapabilities ?? {},
83
89
  features: deps.features ?? defaultFeatures(),
84
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@av-pi-studio/server",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "bin": {
5
5
  "pi-studio-daemon": "dist/daemon/main.js"
6
6
  },
@@ -24,9 +24,9 @@
24
24
  "clean": "rm -rf dist *.tsbuildinfo"
25
25
  },
26
26
  "dependencies": {
27
- "@av-pi-studio/highlight": "^0.0.100",
28
- "@av-pi-studio/protocol": "^0.0.100",
29
- "@av-pi-studio/relay": "^0.0.100",
27
+ "@av-pi-studio/highlight": "^0.0.101",
28
+ "@av-pi-studio/protocol": "^0.0.101",
29
+ "@av-pi-studio/relay": "^0.0.101",
30
30
  "@earendil-works/pi-coding-agent": "^0.84.1",
31
31
  "@xterm/addon-serialize": "^0.14.0",
32
32
  "@xterm/headless": "^6.0.0",