@vite-hub/shell 0.6.1 → 0.8.0

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/README.md CHANGED
@@ -81,7 +81,7 @@ Shell policy can bound calls, processes, output size, and timeouts. A declared b
81
81
 
82
82
  Custom drivers can return Shell Observations as class instances. Sessions preserve every declared observation field, including fields exposed through getters.
83
83
 
84
- The Workspace filesystem has a virtual root at `/workspace`. Root existence checks return true. On a writable filesystem, recursive directory creation at the root succeeds without changing the Workspace. Creating the root without `recursive` fails because it already exists.
84
+ The Workspace filesystem has a virtual root at `/workspace`. Root existence checks return true. On a writable filesystem, recursive directory creation at the root succeeds without changing the Workspace. Creating the root without `recursive` fails because it already exists. `/dev/null` is the only path outside `/workspace` that commands can use: reads return nothing, writes are discarded on read-only and writable filesystems, and directory operations on it are rejected.
85
85
 
86
86
  Directory paths may end in `/`. Listing or copying `models/` preserves each child's full name, just as `models` does.
87
87
 
package/dist/workspace.js CHANGED
@@ -5,6 +5,7 @@ import { Buffer } from "node:buffer";
5
5
  import { posix } from "node:path";
6
6
  // src/workspace/filesystem.ts
7
7
  const workspaceMountPoint = "/workspace";
8
+ const devNullPath = "/dev/null";
8
9
  function createEscapeError(path) {
9
10
  return shellErrorDiagnostics.SHELL_R0013({ message: `[vitehub] Workspace path escapes the workspace root: "${path}".` });
10
11
  }
@@ -58,10 +59,14 @@ function statFromEntry(entry) {
58
59
  function isMissingWorkspacePath(error) {
59
60
  return error instanceof Error && /Workspace (?:path|file) does not exist:/.test(error.message);
60
61
  }
62
+ const storedFileReadOptions = {
63
+ encoding: "binary",
64
+ [Symbol.for("vitehub.workspace.stored-file-read")]: true
65
+ };
61
66
  async function copyWorkspacePath(workspace, from, to, missingDirectory) {
62
67
  if ((await workspace.stat(from)).type === "file") {
63
68
  if (missingDirectory) throw missingDirectory();
64
- await workspace.writeFile(to, await workspace.readFile(from, { encoding: "binary" }));
69
+ await workspace.writeFile(to, await workspace.readFile(from, storedFileReadOptions));
65
70
  return;
66
71
  }
67
72
  const entries = await workspace.list(from, { recursive: true });
@@ -74,7 +79,7 @@ async function copyWorkspacePath(workspace, from, to, missingDirectory) {
74
79
  }
75
80
  for (const entry of files) {
76
81
  const relativePath = from ? entry.path.slice(from.length + 1) : entry.path;
77
- await workspace.writeFile(posix.join(to, relativePath), await workspace.readFile(entry.path, { encoding: "binary" }));
82
+ await workspace.writeFile(posix.join(to, relativePath), await workspace.readFile(entry.path, storedFileReadOptions));
78
83
  }
79
84
  }
80
85
  var WorkspaceFileSystem = class {
@@ -91,16 +96,19 @@ var WorkspaceFileSystem = class {
91
96
  return decodeContent(await this.readFileBuffer(path), typeof options === "string" ? options : options?.encoding);
92
97
  }
93
98
  async readFileBuffer(path) {
99
+ if (this.#isDevNull(path)) return /* @__PURE__ */ new Uint8Array();
94
100
  const relativePath = this.#toRelativePath(path);
95
101
  return toShellContent(await this.workspace.readFile(relativePath, { encoding: "binary" }));
96
102
  }
97
103
  async writeFile(path, content, options) {
104
+ if (this.#isDevNull(path)) return;
98
105
  const workspace = this.#requireWritable();
99
106
  const encoding = typeof options === "string" ? options : options?.encoding;
100
107
  await workspace.writeFile(this.#toRelativePath(path), encoding ? toShellContent(content, encoding) : content);
101
108
  await this.#refreshPaths();
102
109
  }
103
110
  async appendFile(path, content, options) {
111
+ if (this.#isDevNull(path)) return;
104
112
  const workspace = this.#requireWritable();
105
113
  const relativePath = this.#toRelativePath(path);
106
114
  const current = toShellContent(await workspace.readFile(relativePath, { encoding: "binary" }).catch(async (error) => {
@@ -116,6 +124,7 @@ var WorkspaceFileSystem = class {
116
124
  }
117
125
  async exists(path) {
118
126
  try {
127
+ if (this.#isDevNull(path)) return true;
119
128
  const relativePath = this.#toRelativePath(path);
120
129
  if (!relativePath) return true;
121
130
  return await this.workspace.exists(relativePath);
@@ -124,6 +133,14 @@ var WorkspaceFileSystem = class {
124
133
  }
125
134
  }
126
135
  async stat(path) {
136
+ if (this.#isDevNull(path)) return {
137
+ isDirectory: false,
138
+ isFile: false,
139
+ isSymbolicLink: false,
140
+ mode: 8630,
141
+ mtime: /* @__PURE__ */ new Date(0),
142
+ size: 0
143
+ };
127
144
  const relativePath = this.#toRelativePath(path);
128
145
  if (!relativePath) return statFromEntry({
129
146
  path: "",
@@ -197,7 +214,7 @@ var WorkspaceFileSystem = class {
197
214
  const normalizedBase = this.#resolveAbsolute(base);
198
215
  if (normalizedInput === ".." && normalizedBase === "/workspace") return workspaceMountPoint;
199
216
  const absolute = normalizedInput.startsWith("/") ? normalizeAbsolutePath(normalizedInput) : normalizeAbsolutePath(posix.join(normalizedBase, normalizedInput));
200
- if (absolute === "/workspace" || absolute.startsWith(`/workspace/`)) return absolute;
217
+ if (absolute === "/workspace" || absolute.startsWith(`/workspace/`) || absolute === "/dev/null") return absolute;
201
218
  throw createEscapeError(path);
202
219
  }
203
220
  getAllPaths() {
@@ -242,8 +259,12 @@ var WorkspaceFileSystem = class {
242
259
  if (!path.endsWith("/")) return void 0;
243
260
  return () => shellErrorDiagnostics.SHELL_PATH_NOT_FOUND({ message: `[vitehub] ENOTDIR: not a directory, '${this.#resolveFromRoot(path)}'` });
244
261
  }
262
+ #isDevNull(path) {
263
+ return this.#resolveFromRoot(path) === devNullPath;
264
+ }
245
265
  #toRelativePath(path) {
246
266
  const absolutePath = this.#resolveFromRoot(path);
267
+ if (absolutePath === "/dev/null") throw createEscapeError(path);
247
268
  if (absolutePath === "/workspace") return "";
248
269
  return absolutePath.slice(`${workspaceMountPoint}/`.length).replace(/\/$/, "");
249
270
  }
@@ -676,7 +697,9 @@ async function preflightMissingWorkspacePath(command, segments, fs, cwd = worksp
676
697
  throwIfAborted(signal);
677
698
  for (const path of segment.paths) {
678
699
  if (!isConcreteWorkspacePath(path)) continue;
679
- const resolvedPath = resolveWorkspaceShellPath(segmentCwd, path);
700
+ const absolutePath = resolvedWorkspaceCwd(segmentCwd, path);
701
+ if (posix.normalize(absolutePath) === "/dev/null") continue;
702
+ const resolvedPath = cleanWorkspaceShellPath(absolutePath);
680
703
  const exists = await fs.exists(resolvedPath);
681
704
  throwIfAborted(signal);
682
705
  if (exists) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/shell",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "Unified shell runtimes for ViteHub.",
5
5
  "keywords": [
6
6
  "bash",
@@ -45,7 +45,7 @@
45
45
  "./package.json": "./package.json"
46
46
  },
47
47
  "dependencies": {
48
- "@vite-hub/runtime": "0.6.1",
48
+ "@vite-hub/runtime": "0.8.0",
49
49
  "just-bash": "^3.6.1",
50
50
  "nostics": "1.4.0",
51
51
  "sh-syntax": "0.8.7"