@opencode/util 0.0.0-dev-21132 → 0.0.0-dev-21134

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/fs-util.d.ts CHANGED
@@ -128,11 +128,15 @@ export declare namespace FSUtil {
128
128
  };
129
129
  export const layer: Layer.Layer<Service, never, FileSystem.FileSystem>;
130
130
  export const node: import("./effect/layer-node.js").Provider<Service, never, import("./effect/layer-node.js").Tag<"global">>;
131
+ /** Permission denial, including macOS sandbox and privacy denials that surface as Unknown with an EPERM cause. */
132
+ export function isAccessDenied(error: PlatformError): boolean;
131
133
  export function mimeType(p: string): string;
132
134
  export function normalizePath(p: string): string;
133
135
  export function normalizePathPattern(p: string): string;
134
136
  export function resolve(p: string): string;
135
137
  export function windowsPath(p: string): string;
138
+ export const ignoredDirectories: string[];
139
+ export const ignoreGlobs: string[];
136
140
  export function overlaps(a: string, b: string): boolean;
137
141
  export function contains(parent: string, child: string): boolean;
138
142
  export {};
package/dist/fs-util.js CHANGED
@@ -32,7 +32,9 @@ export var FSUtil;
32
32
  return yield* fs.exists(path).pipe(Effect.orElseSucceed(() => false));
33
33
  });
34
34
  const readFileStringSafe = Effect.fn("FileSystem.readFileStringSafe")(function* (path) {
35
- return yield* fs.readFileString(path).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.undefined), Effect.catchReason("PlatformError", "PermissionDenied", () => Effect.undefined));
35
+ return yield* fs
36
+ .readFileString(path)
37
+ .pipe(Effect.catchIf((error) => error.reason._tag === "NotFound" || isAccessDenied(error), () => Effect.undefined));
36
38
  });
37
39
  const isDir = Effect.fn("FileSystem.isDir")(function* (path) {
38
40
  const info = yield* fs.stat(path).pipe(Effect.catch(() => Effect.void));
@@ -56,7 +58,8 @@ export var FSUtil;
56
58
  });
57
59
  const resolve = Effect.fn("FileSystem.resolve")(function* (input) {
58
60
  const resolved = path.resolve(windowsPath(input));
59
- return yield* fs.realPath(resolved).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(resolved)), Effect.orDie);
61
+ // Sandboxes deny reads outside granted paths; canonicalize what we can see.
62
+ return yield* fs.realPath(resolved).pipe(Effect.catchIf((error) => error.reason._tag === "NotFound" || isAccessDenied(error), () => Effect.succeed(resolved)), Effect.orDie);
60
63
  });
61
64
  const readJson = Effect.fn("FileSystem.readJson")(function* (path) {
62
65
  const text = yield* fs.readFileString(path);
@@ -154,6 +157,17 @@ export var FSUtil;
154
157
  });
155
158
  }));
156
159
  FSUtil.node = makeGlobalNode({ service: Service, layer: FSUtil.layer, deps: [filesystem] });
160
+ /** Permission denial, including macOS sandbox and privacy denials that surface as Unknown with an EPERM cause. */
161
+ function isAccessDenied(error) {
162
+ if (error.reason._tag === "PermissionDenied")
163
+ return true;
164
+ const cause = error.reason.cause;
165
+ return (error.reason._tag === "Unknown" &&
166
+ cause instanceof globalThis.Error &&
167
+ "code" in cause &&
168
+ cause.code === "EPERM");
169
+ }
170
+ FSUtil.isAccessDenied = isAccessDenied;
157
171
  // Pure helpers that don't need Effect (path manipulation, sync operations)
158
172
  function mimeType(p) {
159
173
  return lookup(p) || "application/octet-stream";
@@ -189,7 +203,7 @@ export var FSUtil;
189
203
  return normalizePath(realpathSync(resolved));
190
204
  }
191
205
  catch (e) {
192
- if (e?.code === "ENOENT" || e?.code === "ENOTDIR")
206
+ if (["ENOENT", "ENOTDIR", "EPERM", "EACCES"].includes(e?.code))
193
207
  return normalizePath(resolved);
194
208
  throw e;
195
209
  }
@@ -205,6 +219,8 @@ export var FSUtil;
205
219
  .replace(/^\/mnt\/([a-zA-Z])(?:\/|$)/, (_, drive) => `${drive.toUpperCase()}:/`);
206
220
  }
207
221
  FSUtil.windowsPath = windowsPath;
222
+ FSUtil.ignoredDirectories = ["node_modules", ".git", ".venv", "venv", "__pycache__"];
223
+ FSUtil.ignoreGlobs = [...FSUtil.ignoredDirectories, `**/{${FSUtil.ignoredDirectories.join(",")}}/**`];
208
224
  function overlaps(a, b) {
209
225
  return contains(a, b) || contains(b, a);
210
226
  }
package/dist/glob.d.ts CHANGED
@@ -5,6 +5,7 @@ export declare namespace Glob {
5
5
  include?: "file" | "all";
6
6
  dot?: boolean;
7
7
  symlink?: boolean;
8
+ ignore?: string[];
8
9
  }
9
10
  function scan(pattern: string, options?: Options): Promise<string[]>;
10
11
  function scanSync(pattern: string, options?: Options): string[];
package/dist/glob.js CHANGED
@@ -9,6 +9,7 @@ export var Glob;
9
9
  dot: options.dot,
10
10
  follow: options.symlink ?? false,
11
11
  nodir: options.include !== "all",
12
+ ignore: options.ignore,
12
13
  };
13
14
  }
14
15
  async function scan(pattern, options = {}) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/util",
4
- "version": "0.0.0-dev-21132",
4
+ "version": "0.0.0-dev-21134",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {