@oh-my-pi/pi-natives 18.2.0 → 18.2.1

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/native/index.d.ts CHANGED
@@ -648,7 +648,7 @@ export declare function __ompInstallTokioRuntime(): void
648
648
  * `packages/natives/native/index.js` (which derives the name from
649
649
  * `package.json#version`).
650
650
  */
651
- export declare function __piNativesV18_2_0(): void
651
+ export declare function __piNativesV18_2_1(): void
652
652
 
653
653
  /**
654
654
  * Apply ast-grep rewrite rules to matching files; honors `dryRun` and returns
@@ -1753,6 +1753,9 @@ export declare function hashlineFormatHeader(path: string, tag: string): string
1753
1753
  /** `N:line` numbered display rows starting at `startLine` (default 1). */
1754
1754
  export declare function hashlineFormatNumberedLines(text: string, startLine?: number | undefined | null): string
1755
1755
 
1756
+ /** Whether a row is a truncation notice emitted by `read`. */
1757
+ export declare function hashlineIsReadTruncationNotice(line: string): boolean
1758
+
1756
1759
  /** Count of one canonical hashline op header shape in a payload. */
1757
1760
  export interface HashlineOpCount {
1758
1761
  label: string
@@ -2773,11 +2776,24 @@ export interface VcsDiffOptions {
2773
2776
  files?: Array<string>
2774
2777
  context?: number
2775
2778
  binary?: boolean
2779
+ /**
2780
+ * Fail with an `OutputTooLarge` `VcsError` once the rendered patch exceeds
2781
+ * this many bytes, instead of buffering an arbitrarily large string.
2782
+ * Carried as a double so a budget past 2^32 reaches the renderer intact
2783
+ * (a `u32` field would wrap it); values beyond `usize` saturate.
2784
+ */
2785
+ maxBytes?: number
2776
2786
  }
2777
2787
 
2778
2788
  /** Discover the repository owning a directory. */
2779
2789
  export declare function vcsDiscover(dir: string): VcsRepo | null
2780
2790
 
2791
+ /**
2792
+ * Discover the repository presenting a directory: equal-root jj+git ties
2793
+ * prefer Jujutsu. Git-safe automation must keep using [`vcs_discover`].
2794
+ */
2795
+ export declare function vcsDiscoverForDisplay(dir: string): VcsRepo | null
2796
+
2781
2797
  /** Clone a Git repository. */
2782
2798
  export declare function vcsGitClone(url: string, target: string, options: VcsCloneOptions, signal?: unknown | undefined | null): Promise<void>
2783
2799
 
package/native/index.js CHANGED
@@ -39,7 +39,7 @@ export const VcsRepo = nativeBindings.VcsRepo;
39
39
 
40
40
  // functions
41
41
  export const __ompInstallTokioRuntime = nativeBindings.__ompInstallTokioRuntime;
42
- export const __piNativesV18_2_0 = nativeBindings.__piNativesV18_2_0;
42
+ export const __piNativesV18_2_1 = nativeBindings.__piNativesV18_2_1;
43
43
  export const astEdit = nativeBindings.astEdit;
44
44
  export const astGrep = nativeBindings.astGrep;
45
45
  export const astMatch = nativeBindings.astMatch;
@@ -73,6 +73,7 @@ export const hashlineCountOps = nativeBindings.hashlineCountOps;
73
73
  export const hashlineFileHash = nativeBindings.hashlineFileHash;
74
74
  export const hashlineFormatHeader = nativeBindings.hashlineFormatHeader;
75
75
  export const hashlineFormatNumberedLines = nativeBindings.hashlineFormatNumberedLines;
76
+ export const hashlineIsReadTruncationNotice = nativeBindings.hashlineIsReadTruncationNotice;
76
77
  export const hashlineStripPrefixes = nativeBindings.hashlineStripPrefixes;
77
78
  export const hasMatch = nativeBindings.hasMatch;
78
79
  export const highlightCode = nativeBindings.highlightCode;
@@ -113,6 +114,7 @@ export const supportsLanguage = nativeBindings.supportsLanguage;
113
114
  export const truncateToWidth = nativeBindings.truncateToWidth;
114
115
  export const vcsDetachGitDir = nativeBindings.vcsDetachGitDir;
115
116
  export const vcsDiscover = nativeBindings.vcsDiscover;
117
+ export const vcsDiscoverForDisplay = nativeBindings.vcsDiscoverForDisplay;
116
118
  export const vcsGitClone = nativeBindings.vcsGitClone;
117
119
  export const vcsGitDiscover = nativeBindings.vcsGitDiscover;
118
120
  export const vcsGitRepoInfo = nativeBindings.vcsGitRepoInfo;
@@ -6,6 +6,7 @@ import * as path from "node:path";
6
6
  import * as zlib from "node:zlib";
7
7
  import packageJson from "../package.json" with { type: "json" };
8
8
  import { embeddedAddon } from "./embedded-addon.js";
9
+ import { containsVersionSentinel, versionSentinelFor } from "./version-sentinel.js";
9
10
 
10
11
  /**
11
12
  * Native addon loader for `@oh-my-pi/pi-natives`.
@@ -703,7 +704,7 @@ export function validateLoadedBindings(ctx, bindings, candidate) {
703
704
  // the current sentinel; otherwise a restart would simply reload stale disk.
704
705
  let diskHasExpectedSentinel = false;
705
706
  try {
706
- diskHasExpectedSentinel = fs.readFileSync(candidate).includes(ctx.versionSentinelExport);
707
+ diskHasExpectedSentinel = containsVersionSentinel(fs.readFileSync(candidate), ctx.versionSentinelExport);
707
708
  } catch {
708
709
  // The successful require above normally guarantees readability. If the
709
710
  // file disappears concurrently, retain the safe reinstall diagnosis.
@@ -837,7 +838,7 @@ export function initLoaderContext(overrides = {}) {
837
838
  // physically cannot expose the symbol this loader is looking for. That
838
839
  // turns the silent `<sym> is not a function` crash from a Windows
839
840
  // locked-file update into an actionable load-time error.
840
- const versionSentinelExport = `__piNativesV${packageVersion.replace(/[^A-Za-z0-9]/g, "_")}`;
841
+ const versionSentinelExport = versionSentinelFor(packageVersion);
841
842
 
842
843
  return {
843
844
  platformTag,
package/native/vcs.d.ts CHANGED
@@ -31,7 +31,8 @@ export interface VcsError extends Error {
31
31
  | "Io"
32
32
  | "Backend"
33
33
  | "Canceled"
34
- | "Unsupported";
34
+ | "Unsupported"
35
+ | "OutputTooLarge";
35
36
  exitCode: number;
36
37
  stdout: string;
37
38
  stderr: string;
@@ -47,6 +48,8 @@ export declare function isEmptyCherryPick(error: unknown): error is VcsError & {
47
48
  export declare function git(dir: string): VcsGitRepo | null;
48
49
  /** Discover the repository owning `dir`; `null` outside any repository. */
49
50
  export declare function repo(dir: string): VcsRepo | null;
51
+ /** Like {@link repo}, but equal-root jj+git ties prefer Jujutsu for display. Git-safe automation must keep using {@link repo}. */
52
+ export declare function repoForDisplay(dir: string): VcsRepo | null;
50
53
 
51
54
  /** Like {@link repo}, asserting any requested backend capabilities. */
52
55
  export declare function require(dir: string, ...features: VcsFeature[]): VcsRepo;
package/native/vcs.js CHANGED
@@ -41,6 +41,11 @@ export function repo(dir) {
41
41
  return api().vcsDiscover(dir);
42
42
  }
43
43
 
44
+ /** Like {@link repo}, but equal-root jj+git ties prefer Jujutsu for display. Git-safe automation must keep using {@link repo}. */
45
+ export function repoForDisplay(dir) {
46
+ return api().vcsDiscoverForDisplay(dir);
47
+ }
48
+
44
49
  /** Like {@link repo}, asserting any requested backend capabilities. */
45
50
  export function require(dir, ...features) {
46
51
  const discovered = repo(dir);
@@ -0,0 +1,5 @@
1
+ /** Return the native-addon export expected for a package version. */
2
+ export function versionSentinelFor(packageVersion: string): string;
3
+
4
+ /** Check whether addon bytes contain the exact expected version sentinel. */
5
+ export function containsVersionSentinel(bytes: Buffer, expected: string): boolean;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Version-sentinel helpers shared by the native loader and the embed pipeline.
3
+ *
4
+ * Kept in its own module so `scripts/embed-native.ts` can reuse the exact-match
5
+ * logic without importing `loader-state.js` — which pulls in the generated
6
+ * `embedded-addon.js` and its `with { type: "file" }` archive import. That
7
+ * chain fails to resolve when the archive is missing, which would break
8
+ * `gen:native:reset` on an inconsistent tree (populated manifest, deleted
9
+ * archive) before it can restore the checked-in null stub.
10
+ */
11
+
12
+ /**
13
+ * Return the version sentinel exported by an addon built for `packageVersion`.
14
+ * @param {string} packageVersion
15
+ * @returns {string}
16
+ */
17
+ export function versionSentinelFor(packageVersion) {
18
+ return `__piNativesV${packageVersion.replace(/[^A-Za-z0-9]/g, "_")}`;
19
+ }
20
+
21
+ /**
22
+ * Check for an exact version sentinel rather than a longer sentinel with the
23
+ * expected value as its prefix (e.g. `__piNativesV18_1_10` must not satisfy a
24
+ * lookup for `__piNativesV18_1_1`).
25
+ * @param {Buffer} bytes
26
+ * @param {string} expected
27
+ * @returns {boolean}
28
+ */
29
+ export function containsVersionSentinel(bytes, expected) {
30
+ if (expected.length === 0) return false;
31
+ let offset = 0;
32
+ while (offset < bytes.length) {
33
+ const index = bytes.indexOf(expected, offset);
34
+ if (index === -1) return false;
35
+ const next = bytes[index + expected.length];
36
+ const isIdentifierByte =
37
+ next === 95 || (next >= 48 && next <= 57) || (next >= 65 && next <= 90) || (next >= 97 && next <= 122);
38
+ if (!isIdentifierByte) return true;
39
+ offset = index + expected.length;
40
+ }
41
+ return false;
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-natives",
3
- "version": "18.2.0",
3
+ "version": "18.2.1",
4
4
  "description": "Native Rust bindings for PDF conversion, audio, WebRTC, grep, clipboard, image processing, syntax highlighting, PTY, and shell operations via N-API",
5
5
  "type": "module",
6
6
  "homepage": "https://omp.sh",
@@ -70,6 +70,8 @@
70
70
  "native/desktop.d.ts",
71
71
  "native/desktop-adapter.js",
72
72
  "native/desktop-adapter.d.ts",
73
+ "native/version-sentinel.js",
74
+ "native/version-sentinel.d.ts",
73
75
  "native/loader-state.js",
74
76
  "native/loader-state.d.ts",
75
77
  "native/vcs.js",
@@ -98,11 +100,11 @@
98
100
  }
99
101
  },
100
102
  "optionalDependencies": {
101
- "@oh-my-pi/pi-natives-linux-x64": "18.2.0",
102
- "@oh-my-pi/pi-natives-linux-arm64": "18.2.0",
103
- "@oh-my-pi/pi-natives-darwin-x64": "18.2.0",
104
- "@oh-my-pi/pi-natives-darwin-arm64": "18.2.0",
105
- "@oh-my-pi/pi-natives-win32-x64": "18.2.0",
106
- "@oh-my-pi/pi-natives-win32-arm64": "18.2.0"
103
+ "@oh-my-pi/pi-natives-linux-x64": "18.2.1",
104
+ "@oh-my-pi/pi-natives-linux-arm64": "18.2.1",
105
+ "@oh-my-pi/pi-natives-darwin-x64": "18.2.1",
106
+ "@oh-my-pi/pi-natives-darwin-arm64": "18.2.1",
107
+ "@oh-my-pi/pi-natives-win32-x64": "18.2.1",
108
+ "@oh-my-pi/pi-natives-win32-arm64": "18.2.1"
107
109
  }
108
110
  }