@oh-my-pi/pi-utils 18.2.11 → 18.3.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
@@ -1,6 +1,6 @@
1
1
  # @oh-my-pi/pi-utils
2
2
 
3
- Shared utilities for [oh-my-pi](https://github.com/can1357/oh-my-pi) packages. Zero ceremony, Bun-first.
3
+ Shared utilities for [omp](https://github.com/can1357/oh-my-pi) packages. Zero ceremony, Bun-first.
4
4
 
5
5
  ## Notable modules
6
6
 
@@ -293,7 +293,7 @@ MIT License
293
293
  Copyright (c) 2026 Sander Land
294
294
  (measured tokenizer vocabulary data, reconstruction model, and reference
295
295
  implementation: https://github.com/sanderland/ctok)
296
- Copyright (c) 2026 Can Bölük and the Oh My Pi contributors
296
+ Copyright (c) 2026 Can Bölük and the omp contributors
297
297
  Copyright (c) 2026 Stencil Labs, Inc.
298
298
  (Rust implementation and the compact binary vocabulary encoding in
299
299
  crates/pi-natives/src/utok/claude)
@@ -206,8 +206,6 @@ export declare function getAutoQaDbPath(): string;
206
206
  export declare function hashPath(absPath: string): string;
207
207
  /** Get the path to a single worktree directory (~/.omp/wt/<segment>). */
208
208
  export declare function getWorktreeDir(segment: string): string;
209
- /** Get the GPU cache path (~/.omp/gpu_cache.json). */
210
- export declare function getGpuCachePath(): string;
211
209
  /**
212
210
  * Get the GitHub view cache database path (~/.omp/cache/github-cache.db).
213
211
  * Honors the `OMP_GITHUB_CACHE_DB` env var when set so tests can isolate the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "18.2.11",
3
+ "version": "18.3.0",
4
4
  "description": "Shared utilities for pi packages",
5
5
  "keywords": [
6
6
  "cli",
@@ -13,7 +13,10 @@
13
13
  "url": "https://github.com/can1357/oh-my-pi/issues"
14
14
  },
15
15
  "license": "MIT",
16
- "author": "Stencil Labs, Inc.",
16
+ "author": {
17
+ "name": "Stencil Labs, Inc.",
18
+ "url": "https://stencil.so"
19
+ },
17
20
  "repository": {
18
21
  "type": "git",
19
22
  "url": "git+https://github.com/can1357/oh-my-pi.git",
@@ -54,7 +57,7 @@
54
57
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
55
58
  },
56
59
  "dependencies": {
57
- "@oh-my-pi/pi-natives": "18.2.11"
60
+ "@oh-my-pi/pi-natives": "18.3.0"
58
61
  },
59
62
  "devDependencies": {
60
63
  "@types/bun": "^1.3.14"
package/src/dirs.ts CHANGED
@@ -752,11 +752,6 @@ export function getWorktreeDir(segment: string): string {
752
752
  return path.join(getWorktreesDir(), segment);
753
753
  }
754
754
 
755
- /** Get the GPU cache path (~/.omp/gpu_cache.json). */
756
- export function getGpuCachePath(): string {
757
- return dirs.rootSubdir("gpu_cache.json", "cache");
758
- }
759
-
760
755
  /**
761
756
  * Get the GitHub view cache database path (~/.omp/cache/github-cache.db).
762
757
  * Honors the `OMP_GITHUB_CACHE_DB` env var when set so tests can isolate the
@@ -1,5 +1,4 @@
1
1
  /** Behavior-compatible reimplementation of winston-daily-rotate-file's used surface. */
2
- import * as crypto from "node:crypto";
3
2
  import * as fs from "node:fs";
4
3
  import * as os from "node:os";
5
4
  import * as path from "node:path";
@@ -151,7 +150,7 @@ export class RotatingFileSink {
151
150
 
152
151
  #registerFile(filePath: string, date: number): void {
153
152
  if (this.#files.some(file => file.name === filePath)) return;
154
- const hash = crypto.createHash("sha256").update(`${filePath}LOG_FILE${date}`).digest("hex");
153
+ const hash = Bun.SHA256.hash(`${filePath}LOG_FILE${date}`, "hex");
155
154
  this.#files.push({ date, name: filePath, hash });
156
155
  while (this.#files.length > this.#maxFiles) {
157
156
  const removed = this.#files.shift();
@@ -172,9 +172,43 @@ function resolverRegistry(): ResolverRegistration[] {
172
172
  holder[REGISTRY] ??= [];
173
173
  return holder[REGISTRY];
174
174
  }
175
- function pathContains(root: string, candidate: string): boolean {
176
- const relative = path.relative(root, candidate);
177
- return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
175
+ /** Canonical form of a path, memoized: resolution is per module request, and roots repeat. */
176
+ const canonicalPaths = new Map<string, string>();
177
+
178
+ /**
179
+ * Canonical form of `target` for path comparison: symlinks and Windows
180
+ * junctions resolved, drive/segment casing folded on Windows. Non-existent
181
+ * paths fall back to `path.resolve`, which still normalizes separators.
182
+ *
183
+ * Comparisons must canonicalize because the two sides come from different
184
+ * worlds: the stock resolver hands back realpath-resolved filenames, while a
185
+ * registered runtime root is whatever the caller configured (a cache under a
186
+ * junctioned `F:\Programs\…`, a home directory symlinked onto another volume,
187
+ * macOS `/tmp` → `/private/tmp`).
188
+ */
189
+ function canonicalPath(target: string): string {
190
+ const cached = canonicalPaths.get(target);
191
+ if (cached !== undefined) return cached;
192
+ let canonical: string;
193
+ try {
194
+ canonical = fs.realpathSync.native(target);
195
+ } catch {
196
+ canonical = path.resolve(target);
197
+ }
198
+ if (process.platform === "win32") canonical = canonical.toLowerCase();
199
+ canonicalPaths.set(target, canonical);
200
+ return canonical;
201
+ }
202
+
203
+ /**
204
+ * Path of `candidate` relative to `root` when `candidate` is inside (or is)
205
+ * `root`, else `null`. Both sides are canonicalized, so a runtime cache
206
+ * reached through a link still matches the filenames the resolver reports.
207
+ */
208
+ function relativeWithin(root: string, candidate: string): string | null {
209
+ const relative = path.relative(canonicalPath(root), canonicalPath(candidate));
210
+ if (relative !== "" && (relative.startsWith("..") || path.isAbsolute(relative))) return null;
211
+ return relative;
178
212
  }
179
213
 
180
214
  function parentFilename(parent: unknown): string | null {
@@ -243,11 +277,12 @@ export function installRuntimeModuleResolver({ runtimeNodeModules, stubs = {} }:
243
277
  if (bare) {
244
278
  const parentFile = parentFilename(parent);
245
279
  for (const registration of resolverRegistry()) {
246
- const parentInRuntime = parentFile !== null && pathContains(registration.runtimeNodeModules, parentFile);
280
+ const parentInRuntime =
281
+ parentFile !== null && relativeWithin(registration.runtimeNodeModules, parentFile) !== null;
247
282
  if (parentInRuntime) {
248
283
  const stub = registration.stubs[request];
249
284
  if (stub) return stub;
250
- if (!stockResolved || !pathContains(registration.runtimeNodeModules, stockResolved)) {
285
+ if (!stockResolved || relativeWithin(registration.runtimeNodeModules, stockResolved) === null) {
251
286
  const fallback = resolveRuntimeModule(registration.runtimeNodeModules, request);
252
287
  if (fallback) return fallback;
253
288
  }
@@ -260,8 +295,9 @@ export function installRuntimeModuleResolver({ runtimeNodeModules, stubs = {} }:
260
295
  // it with the top-level instance would cross major versions.
261
296
  const { packageName } = splitBareSpecifier(request);
262
297
  const pkgDir = path.join(registration.runtimeNodeModules, ...packageName.split("/"));
263
- if (!stockResolved.startsWith(pkgDir + path.sep)) continue;
264
- if (path.relative(pkgDir, stockResolved).split(path.sep).includes("node_modules")) continue;
298
+ const relative = relativeWithin(pkgDir, stockResolved);
299
+ if (relative === null || relative === "") continue;
300
+ if (relative.split(path.sep).includes("node_modules")) continue;
265
301
  const expected = resolveRuntimeModule(registration.runtimeNodeModules, request);
266
302
  if (expected) return expected;
267
303
  } else {