@oh-my-pi/pi-natives 18.0.8 → 18.0.9

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
@@ -331,6 +331,201 @@ export declare class TtyWriter {
331
331
  stop(flushTimeoutMs: number): void
332
332
  }
333
333
 
334
+ /** In-process Git repository handle. */
335
+ export declare class VcsGitRepo {
336
+ /** Repository metadata. */
337
+ info(): VcsGitRepoInfo
338
+ /** Primary checkout root. */
339
+ primaryRoot(): string
340
+ /** Linked-worktree metadata. */
341
+ linkedWorktree(): VcsLinkedWorktree | null
342
+ /** Resolve HEAD synchronously. */
343
+ headSync(): VcsHeadState
344
+ /** Worktree-relative prefix of a directory. */
345
+ prefixOf(dir: string): string | null
346
+ /** Resolve HEAD. */
347
+ head(signal?: unknown | undefined | null): Promise<VcsHeadState>
348
+ /** Resolve HEAD SHA. */
349
+ headSha(signal?: unknown | undefined | null): Promise<string | undefined | null>
350
+ /** Current branch. */
351
+ currentBranch(signal?: unknown | undefined | null): Promise<string | undefined | null>
352
+ /** Default remote branch. */
353
+ defaultBranch(signal?: unknown | undefined | null): Promise<string | undefined | null>
354
+ /** Resolve a revision. */
355
+ resolveRef(name: string, signal?: unknown | undefined | null): Promise<string | undefined | null>
356
+ /** Test revision existence. */
357
+ refExists(name: string, signal?: unknown | undefined | null): Promise<boolean>
358
+ /** Tags pointing at a revision. */
359
+ tagsAt(rev: string, signal?: unknown | undefined | null): Promise<Array<string>>
360
+ /** List branches. */
361
+ listBranches(all: boolean, signal?: unknown | undefined | null): Promise<Array<string>>
362
+ /**
363
+ * Whether default porcelain status reports a staged, unstaged, or untracked
364
+ * change.
365
+ */
366
+ isDirty(signal?: unknown | undefined | null): Promise<boolean>
367
+ /** Porcelain status. */
368
+ statusPorcelain(options: VcsStatusOptions, signal?: unknown | undefined | null): Promise<string>
369
+ /** Status counts. */
370
+ statusSummary(signal?: unknown | undefined | null): Promise<VcsStatusSummary>
371
+ /** Read config. */
372
+ configGet(key: string, signal?: unknown | undefined | null): Promise<string | undefined | null>
373
+ /** Set config. */
374
+ configSet(key: string, value: string, signal?: unknown | undefined | null): Promise<undefined>
375
+ /** List remotes. */
376
+ remoteList(signal?: unknown | undefined | null): Promise<Array<string>>
377
+ /** Remote URL. */
378
+ remoteUrl(name: string, signal?: unknown | undefined | null): Promise<string | undefined | null>
379
+ /** Add remote. */
380
+ remoteAdd(name: string, url: string, signal?: unknown | undefined | null): Promise<undefined>
381
+ /** List worktrees. */
382
+ worktrees(signal?: unknown | undefined | null): Promise<Array<VcsWorktreeEntry>>
383
+ /** Add worktree. */
384
+ worktreeAdd(path: string, refName: string, detach: boolean, signal?: unknown | undefined | null): Promise<undefined>
385
+ /** Remove worktree. */
386
+ worktreeRemove(path: string, force: boolean, signal?: unknown | undefined | null): Promise<boolean>
387
+ /** Prune worktrees. */
388
+ worktreePrune(signal?: unknown | undefined | null): Promise<undefined>
389
+ /** Recent subjects. */
390
+ logSubjects(count: number, signal?: unknown | undefined | null): Promise<Array<string>>
391
+ /** Recent one-line commits. */
392
+ logOnelines(count: number, signal?: unknown | undefined | null): Promise<Array<string>>
393
+ /** Commits in a range. */
394
+ revListRange(base: string, head: string, signal?: unknown | undefined | null): Promise<Array<string>>
395
+ /** Commits touching a file. */
396
+ revListTouching(rev: string, file: string, limit: number, signal?: unknown | undefined | null): Promise<Array<string>>
397
+ /** Commit details. */
398
+ commitDetails(rev: string, signal?: unknown | undefined | null): Promise<VcsCommitDetails>
399
+ /** List index or untracked paths. */
400
+ lsFiles(others: boolean, excludeStandard: boolean, signal?: unknown | undefined | null): Promise<Array<string>>
401
+ /** List tree paths. */
402
+ lsTree(rev: string, paths: Array<string>, signal?: unknown | undefined | null): Promise<Array<string>>
403
+ /** List submodule paths. */
404
+ submodulePaths(signal?: unknown | undefined | null): Promise<Array<string>>
405
+ /** Read blob bytes. */
406
+ showBlob(spec: string, maxBytes?: number | undefined | null, signal?: unknown | undefined | null): Promise<VcsShowResult>
407
+ /** Read commit and patch bytes. */
408
+ showCommit(rev: string, maxBytes?: number | undefined | null, signal?: unknown | undefined | null): Promise<VcsShowResult>
409
+ /** Local LFS media directory. */
410
+ lfsMediaDir(signal?: unknown | undefined | null): Promise<string | undefined | null>
411
+ /** Render a patch. */
412
+ diffText(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<string>
413
+ /** Render a no-index patch between two filesystem paths. */
414
+ diffNoIndex(left: string, right: string, binary: boolean, signal?: unknown | undefined | null): Promise<string>
415
+ /** Changed paths. */
416
+ changedFiles(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<Array<string>>
417
+ /** Per-file line counts. */
418
+ numstat(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<Array<VcsNumstatEntry>>
419
+ /** Test for a diff. */
420
+ hasDiff(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<boolean>
421
+ /** Diff two trees. */
422
+ diffTree(base: string, head: string, binary: boolean, signal?: unknown | undefined | null): Promise<string>
423
+ /** Stage paths. */
424
+ stageFiles(files: Array<string>, signal?: unknown | undefined | null): Promise<undefined>
425
+ /** Unstage paths. */
426
+ unstage(files: Array<string>, signal?: unknown | undefined | null): Promise<undefined>
427
+ /** Stage selected hunks. */
428
+ stageHunks(selections: Array<VcsHunkSelection>, rawDiff?: string | undefined | null, signal?: unknown | undefined | null): Promise<undefined>
429
+ /** Create commit. */
430
+ commitCreate(message: string, options: VcsCommitOptions, signal?: unknown | undefined | null): Promise<string>
431
+ /** Checkout revision. */
432
+ checkout(rev: string, signal?: unknown | undefined | null): Promise<undefined>
433
+ /** Create branch. */
434
+ createBranch(name: string, start: string, force: boolean, signal?: unknown | undefined | null): Promise<undefined>
435
+ /** Delete branch. */
436
+ deleteBranch(name: string, force: boolean, signal?: unknown | undefined | null): Promise<boolean>
437
+ /** Create and checkout branch. */
438
+ checkoutNewBranch(name: string, signal?: unknown | undefined | null): Promise<undefined>
439
+ /** Restore paths. */
440
+ restore(options: VcsRestoreOptions, signal?: unknown | undefined | null): Promise<undefined>
441
+ /** Reset repository state. */
442
+ reset(mode: string, target?: string | undefined | null, signal?: unknown | undefined | null): Promise<undefined>
443
+ /** Clean untracked paths. */
444
+ clean(options: VcsCleanOptions, signal?: unknown | undefined | null): Promise<undefined>
445
+ /** Read tree into index. */
446
+ readTree(treeish: string, indexPath?: string | undefined | null, signal?: unknown | undefined | null): Promise<undefined>
447
+ /** Write index tree. */
448
+ writeTree(indexPath?: string | undefined | null, signal?: unknown | undefined | null): Promise<string>
449
+ /** Apply patch. */
450
+ applyPatch(patch: string, options: VcsApplyOptions, signal?: unknown | undefined | null): Promise<undefined>
451
+ /** Check patch applicability. */
452
+ canApplyPatch(patch: string, options: VcsApplyOptions, signal?: unknown | undefined | null): Promise<boolean>
453
+ /** Cherry-pick commit. */
454
+ cherryPick(rev: string, signal?: unknown | undefined | null): Promise<undefined>
455
+ /** Abort cherry-pick. */
456
+ cherryPickAbort(signal?: unknown | undefined | null): Promise<undefined>
457
+ /** Skip cherry-pick. */
458
+ cherryPickSkip(signal?: unknown | undefined | null): Promise<undefined>
459
+ /** Push stash. */
460
+ stashPush(message?: string | undefined | null, signal?: unknown | undefined | null): Promise<boolean>
461
+ /** Pop stash if cleanly applicable. */
462
+ stashTryPop(reinstateIndex: boolean, signal?: unknown | undefined | null): Promise<boolean>
463
+ /** Push via Git CLI. */
464
+ push(options: VcsPushOptions, signal?: unknown | undefined | null): Promise<void>
465
+ /** Fetch a refspec via Git CLI. */
466
+ fetch(remote: string, source: string, target: string, timeoutMs?: number | undefined | null, signal?: unknown | undefined | null): Promise<void>
467
+ }
468
+
469
+ /** In-process Jujutsu workspace handle. */
470
+ export declare class VcsJjWorkspace {
471
+ /** Workspace root. */
472
+ root(): string
473
+ /** Shared store directory. */
474
+ storeDir(): string
475
+ /** Working-copy label. */
476
+ workingCopyLabel(signal?: unknown | undefined | null): Promise<string | undefined | null>
477
+ /** Status counts. */
478
+ statusSummary(signal?: unknown | undefined | null): Promise<VcsStatusSummary>
479
+ /** Render working-copy patch. */
480
+ diffText(files: Array<string>, snapshot: boolean, signal?: unknown | undefined | null): Promise<string>
481
+ /** List changed paths. */
482
+ changedFiles(files: Array<string>, snapshot: boolean, signal?: unknown | undefined | null): Promise<Array<string>>
483
+ }
484
+
485
+ /** Backend-agnostic repository handle for portable VCS reads. */
486
+ export declare class VcsRepo {
487
+ /** Backend kind (`"git"` or `"jj"`). */
488
+ kind(): string
489
+ /** Checkout or workspace root. */
490
+ root(): string
491
+ /** Primary checkout or default workspace root. */
492
+ primaryRoot(): string
493
+ /** Worktree-relative prefix of a directory. */
494
+ prefixOf(dir: string): string | null
495
+ /** Filesystem target to watch for repository-head changes. */
496
+ watchTarget(): string
497
+ /** Whether this backend implements a portable feature. */
498
+ supports(feature: string): boolean
499
+ /** Git-specific handle when this repository is backed by Git. */
500
+ asGit(): VcsGitRepo | null
501
+ /** Jujutsu-specific handle when this repository is backed by Jujutsu. */
502
+ asJj(): VcsJjWorkspace | null
503
+ /** Human label for the working copy. */
504
+ label(signal?: unknown | undefined | null): Promise<string | undefined | null>
505
+ /** Working-copy commit id. */
506
+ headId(signal?: unknown | undefined | null): Promise<string | undefined | null>
507
+ /** Status counts. */
508
+ statusSummary(signal?: unknown | undefined | null): Promise<VcsStatusSummary>
509
+ /** Porcelain status. */
510
+ statusPorcelain(options: VcsStatusOptions, signal?: unknown | undefined | null): Promise<string>
511
+ /** Render a patch. */
512
+ diffText(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<string>
513
+ /** Changed paths. */
514
+ changedFiles(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<Array<string>>
515
+ /** Per-file line counts. */
516
+ numstat(options: VcsDiffOptions, signal?: unknown | undefined | null): Promise<Array<VcsNumstatEntry>>
517
+ /** Every working-copy change since the last commit. */
518
+ uncommittedDiff(files: Array<string>, signal?: unknown | undefined | null): Promise<string>
519
+ /** Recent subjects. */
520
+ logSubjects(count: number, signal?: unknown | undefined | null): Promise<Array<string>>
521
+ /** Recent one-line commits. */
522
+ logOnelines(count: number, signal?: unknown | undefined | null): Promise<Array<string>>
523
+ /** Commit details. */
524
+ commitDetails(rev: string, signal?: unknown | undefined | null): Promise<VcsCommitDetails>
525
+ /** List tracked or untracked paths. */
526
+ lsFiles(others: boolean, excludeStandard: boolean, signal?: unknown | undefined | null): Promise<Array<string>>
527
+ }
528
+
334
529
  /**
335
530
  * Install the bounded Tokio runtime napi-rs adopts for async exports and the
336
531
  * bounded Rayon global pool used by native parallel iterators.
@@ -376,7 +571,7 @@ export declare function __ompInstallTokioRuntime(): void
376
571
  * `packages/natives/native/index.js` (which derives the name from
377
572
  * `package.json#version`).
378
573
  */
379
- export declare function __piNativesV18_0_8(): void
574
+ export declare function __piNativesV18_0_9(): void
380
575
 
381
576
  /**
382
577
  * Apply ast-grep rewrite rules to matching files; honors `dryRun` and returns
@@ -2213,6 +2408,177 @@ export declare function supportsLanguage(lang: string): boolean
2213
2408
  */
2214
2409
  export declare function truncateToWidth(text: string, maxWidth: number, ellipsisKind: Ellipsis | undefined | null, pad: boolean | undefined | null, tabWidth: number): string
2215
2410
 
2411
+ /** Patch application options. */
2412
+ export interface VcsApplyOptions {
2413
+ cached?: boolean
2414
+ indexPath?: string
2415
+ reverse?: boolean
2416
+ threeWay?: boolean
2417
+ }
2418
+
2419
+ /** Clean options. */
2420
+ export interface VcsCleanOptions {
2421
+ ignoredOnly?: boolean
2422
+ includeIgnored?: boolean
2423
+ paths?: Array<string>
2424
+ }
2425
+
2426
+ /** Clone options. */
2427
+ export interface VcsCloneOptions {
2428
+ refName?: string
2429
+ sha?: string
2430
+ timeoutMs?: number
2431
+ }
2432
+
2433
+ /** Commit author identity. */
2434
+ export interface VcsCommitAuthor {
2435
+ name: string
2436
+ email: string
2437
+ date?: string
2438
+ }
2439
+
2440
+ /** Commit metadata. */
2441
+ export interface VcsCommitDetails {
2442
+ sha: string
2443
+ parents: Array<string>
2444
+ author: VcsCommitAuthor
2445
+ message: string
2446
+ }
2447
+
2448
+ /** Commit creation options. */
2449
+ export interface VcsCommitOptions {
2450
+ author?: VcsCommitAuthor
2451
+ allowEmpty?: boolean
2452
+ amend?: boolean
2453
+ files?: Array<string>
2454
+ }
2455
+
2456
+ /** Detach copied Git metadata. */
2457
+ export declare function vcsDetachGitDir(worktreeRoot: string, sourceCommonDir: string, signal?: unknown | undefined | null): Promise<string>
2458
+
2459
+ /** Diff generation options. */
2460
+ export interface VcsDiffOptions {
2461
+ cached?: boolean
2462
+ base?: string
2463
+ head?: string
2464
+ files?: Array<string>
2465
+ context?: number
2466
+ binary?: boolean
2467
+ }
2468
+
2469
+ /** Discover the repository owning a directory. */
2470
+ export declare function vcsDiscover(dir: string): VcsRepo | null
2471
+
2472
+ /** Clone a Git repository. */
2473
+ export declare function vcsGitClone(url: string, target: string, options: VcsCloneOptions, signal?: unknown | undefined | null): Promise<void>
2474
+
2475
+ /** Discover the Git checkout containing a directory. */
2476
+ export declare function vcsGitDiscover(dir: string): VcsGitRepo | null
2477
+
2478
+ /** Discover Git metadata without opening the repository. */
2479
+ export declare function vcsGitRepoInfo(dir: string): VcsGitRepoInfo | null
2480
+
2481
+ /** Discovered Git repository paths. */
2482
+ export interface VcsGitRepoInfo {
2483
+ repoRoot: string
2484
+ gitEntryPath: string
2485
+ gitDir: string
2486
+ commonDir: string
2487
+ headPath: string
2488
+ isReftable: boolean
2489
+ }
2490
+
2491
+ /** Resolved HEAD state. */
2492
+ export interface VcsHeadState {
2493
+ kind: string
2494
+ refName?: string
2495
+ branch?: string
2496
+ commit?: string
2497
+ }
2498
+
2499
+ /** Selected hunks or line range for a path. */
2500
+ export interface VcsHunkSelection {
2501
+ path: string
2502
+ kind: string
2503
+ indices?: Array<number>
2504
+ start?: number
2505
+ end?: number
2506
+ }
2507
+
2508
+ /** Invalid hunk selection. */
2509
+ export interface VcsHunkSelectionError {
2510
+ path: string
2511
+ message: string
2512
+ }
2513
+
2514
+ /** Test whether a directory is a pure jj workspace. */
2515
+ export declare function vcsIsPureJj(dir: string): boolean
2516
+
2517
+ /** Discover a Jujutsu workspace. */
2518
+ export declare function vcsJjDiscover(dir: string): VcsJjWorkspace | null
2519
+
2520
+ /** Join patch fragments. */
2521
+ export declare function vcsJoinPatches(parts: Array<string>): string
2522
+
2523
+ /** Linked worktree metadata. */
2524
+ export interface VcsLinkedWorktree {
2525
+ root: string
2526
+ primaryRoot: string
2527
+ }
2528
+
2529
+ /** Per-file line counts. */
2530
+ export interface VcsNumstatEntry {
2531
+ path: string
2532
+ added?: number
2533
+ removed?: number
2534
+ }
2535
+
2536
+ /** Push options. */
2537
+ export interface VcsPushOptions {
2538
+ remote?: string
2539
+ refspec?: string
2540
+ forceWithLease?: boolean
2541
+ }
2542
+
2543
+ /** Restore options. */
2544
+ export interface VcsRestoreOptions {
2545
+ source?: string
2546
+ staged?: boolean
2547
+ worktree?: boolean
2548
+ files?: Array<string>
2549
+ }
2550
+
2551
+ /** Bounded object contents. */
2552
+ export interface VcsShowResult {
2553
+ data: Buffer
2554
+ truncated: boolean
2555
+ }
2556
+
2557
+ /** Status query options. */
2558
+ export interface VcsStatusOptions {
2559
+ untracked?: string
2560
+ pathspecs?: Array<string>
2561
+ nulTerminated?: boolean
2562
+ }
2563
+
2564
+ /** Git status counts. */
2565
+ export interface VcsStatusSummary {
2566
+ staged: number
2567
+ unstaged: number
2568
+ untracked: number
2569
+ }
2570
+
2571
+ /** Validate hunk selections. */
2572
+ export declare function vcsValidateHunkSelections(rawDiff: string, selections: Array<VcsHunkSelection>): Array<VcsHunkSelectionError>
2573
+
2574
+ /** One worktree listing row. */
2575
+ export interface VcsWorktreeEntry {
2576
+ path: string
2577
+ head?: string
2578
+ branch?: string
2579
+ detached: boolean
2580
+ }
2581
+
2216
2582
  /**
2217
2583
  * Score every row of a normalized `f32` matrix against `query` and return
2218
2584
  * the top `limit` rows.
package/native/index.js CHANGED
@@ -30,10 +30,13 @@ export const Process = nativeBindings.Process;
30
30
  export const PtySession = nativeBindings.PtySession;
31
31
  export const Shell = nativeBindings.Shell;
32
32
  export const TtyWriter = nativeBindings.TtyWriter;
33
+ export const VcsGitRepo = nativeBindings.VcsGitRepo;
34
+ export const VcsJjWorkspace = nativeBindings.VcsJjWorkspace;
35
+ export const VcsRepo = nativeBindings.VcsRepo;
33
36
 
34
37
  // functions
35
38
  export const __ompInstallTokioRuntime = nativeBindings.__ompInstallTokioRuntime;
36
- export const __piNativesV18_0_8 = nativeBindings.__piNativesV18_0_8;
39
+ export const __piNativesV18_0_9 = nativeBindings.__piNativesV18_0_9;
37
40
  export const astEdit = nativeBindings.astEdit;
38
41
  export const astGrep = nativeBindings.astGrep;
39
42
  export const astMatch = nativeBindings.astMatch;
@@ -91,6 +94,15 @@ export const structuredPatchHunks = nativeBindings.structuredPatchHunks;
91
94
  export const summarizeCode = nativeBindings.summarizeCode;
92
95
  export const supportsLanguage = nativeBindings.supportsLanguage;
93
96
  export const truncateToWidth = nativeBindings.truncateToWidth;
97
+ export const vcsDetachGitDir = nativeBindings.vcsDetachGitDir;
98
+ export const vcsDiscover = nativeBindings.vcsDiscover;
99
+ export const vcsGitClone = nativeBindings.vcsGitClone;
100
+ export const vcsGitDiscover = nativeBindings.vcsGitDiscover;
101
+ export const vcsGitRepoInfo = nativeBindings.vcsGitRepoInfo;
102
+ export const vcsIsPureJj = nativeBindings.vcsIsPureJj;
103
+ export const vcsJjDiscover = nativeBindings.vcsJjDiscover;
104
+ export const vcsJoinPatches = nativeBindings.vcsJoinPatches;
105
+ export const vcsValidateHunkSelections = nativeBindings.vcsValidateHunkSelections;
94
106
  export const vectorIndexTopK = nativeBindings.vectorIndexTopK;
95
107
  export const visibleWidth = nativeBindings.visibleWidth;
96
108
  export const warmHighlighter = nativeBindings.warmHighlighter;
@@ -0,0 +1,94 @@
1
+ import type {
2
+ VcsCloneOptions,
3
+ VcsGitRepo,
4
+ VcsGitRepoInfo,
5
+ VcsHunkSelection,
6
+ VcsHunkSelectionError,
7
+ VcsJjWorkspace,
8
+ VcsRepo,
9
+ } from "./index.js";
10
+ /** Portable capabilities that differ between Git and Jujutsu. */
11
+ export type VcsFeature = "stagedDiff" | "revDiff";
12
+
13
+ /**
14
+ * A native VCS failure: a real `Error` constructed by the Rust layer on the
15
+ * JS thread, carrying a machine-readable `code` and the CLI result fields.
16
+ * Non-CLI failures synthesize `exitCode: 1` and mirror `message` into
17
+ * `stderr`. Identify with {@link isVcsError} — `instanceof` cannot work for
18
+ * foreign-constructed errors.
19
+ */
20
+ export interface VcsError extends Error {
21
+ name: "VcsError";
22
+ code:
23
+ | "NotARepository"
24
+ | "RefNotFound"
25
+ | "ObjectNotFound"
26
+ | "EmptyCherryPick"
27
+ | "Conflict"
28
+ | "PatchFailed"
29
+ | "Cli"
30
+ | "CliTimeout"
31
+ | "Io"
32
+ | "Backend"
33
+ | "Canceled"
34
+ | "Unsupported";
35
+ exitCode: number;
36
+ stdout: string;
37
+ stderr: string;
38
+ }
39
+
40
+ /** True when `error` is a native VCS failure. */
41
+ export declare function isVcsError(error: unknown): error is VcsError;
42
+
43
+ /** True when a cherry-pick failed because the commit is already applied. */
44
+ export declare function isEmptyCherryPick(error: unknown): error is VcsError & { code: "EmptyCherryPick" };
45
+
46
+ /** Discover the git repository containing `dir`; `null` outside any checkout. */
47
+ export declare function git(dir: string): VcsGitRepo | null;
48
+ /** Discover the repository owning `dir`; `null` outside any repository. */
49
+ export declare function repo(dir: string): VcsRepo | null;
50
+
51
+ /** Like {@link repo}, asserting any requested backend capabilities. */
52
+ export declare function require(dir: string, ...features: VcsFeature[]): VcsRepo;
53
+
54
+ /** Like {@link git}, but throws a `NotARepository` {@link VcsError}. */
55
+ export declare function requireGit(dir: string): VcsGitRepo;
56
+
57
+ /** Repository metadata only (cheap fs walk) — for synchronous render paths. */
58
+ export declare function gitInfo(dir: string): VcsGitRepoInfo | null;
59
+
60
+ /** Discover the Jujutsu workspace containing `dir`; `null` when absent. */
61
+ export declare function jj(dir: string): VcsJjWorkspace | null;
62
+
63
+ /** Whether jj is the nearest VCS ancestor, making git automation unsafe. */
64
+ export declare function isPureJj(dir: string): boolean;
65
+
66
+ /** Clone a repository (git CLI under the hood for credential parity). */
67
+ export declare function clone(
68
+ url: string,
69
+ target: string,
70
+ options?: VcsCloneOptions,
71
+ signal?: AbortSignal,
72
+ ): Promise<void>;
73
+
74
+ /** Sever a copied working tree from shared git metadata. */
75
+ export declare function detachGitDir(
76
+ worktreeRoot: string,
77
+ sourceCommonDir: string,
78
+ signal?: AbortSignal,
79
+ ): Promise<"no-git" | "independent" | "detached">;
80
+
81
+ /** Join patch fragments, preserving each part's trailing newline. */
82
+ export declare function joinPatches(parts: string[]): string;
83
+
84
+ /** Validate hunk selections against a raw diff. */
85
+ export declare function validateHunkSelections(
86
+ rawDiff: string,
87
+ selections: VcsHunkSelection[],
88
+ ): VcsHunkSelectionError[];
89
+
90
+ /** Stat-poll interval for {@link watch}. */
91
+ export declare const HEAD_WATCH_INTERVAL_MS: number;
92
+
93
+ /** Watch a repository for head changes; returns a disposer. */
94
+ export declare function watch(repo: VcsRepo, onChange: () => void, intervalMs?: number): () => void;
package/native/vcs.js ADDED
@@ -0,0 +1,119 @@
1
+ import * as fs from "node:fs";
2
+ import { loadNative } from "./loader-state.js";
3
+
4
+ let native;
5
+ function api() {
6
+ native ??= loadNative();
7
+ return native;
8
+ }
9
+ function vcsError(code, message) {
10
+ const error = new Error(message);
11
+ error.name = "VcsError";
12
+ error.code = code;
13
+ error.exitCode = 1;
14
+ error.stdout = "";
15
+ error.stderr = message;
16
+ return error;
17
+ }
18
+
19
+ /**
20
+ * True when `error` is a native VCS failure. The native layer constructs these
21
+ * on the JS thread as real `Error` objects with `name: "VcsError"`, a
22
+ * machine-readable `code`, and `exitCode`/`stdout`/`stderr` properties — an
23
+ * `instanceof` check is impossible for foreign-constructed errors, so identity
24
+ * rides on `name`.
25
+ */
26
+ export function isVcsError(error) {
27
+ return error instanceof Error && error.name === "VcsError";
28
+ }
29
+
30
+ /** True when a cherry-pick failed because the commit is already applied. */
31
+ export function isEmptyCherryPick(error) {
32
+ return isVcsError(error) && error.code === "EmptyCherryPick";
33
+ }
34
+
35
+ /** Discover the git repository containing `dir`; `null` outside any checkout. */
36
+ export function git(dir) {
37
+ return api().vcsGitDiscover(dir);
38
+ }
39
+ /** Discover the repository owning `dir`; `null` outside any repository. */
40
+ export function repo(dir) {
41
+ return api().vcsDiscover(dir);
42
+ }
43
+
44
+ /** Like {@link repo}, asserting any requested backend capabilities. */
45
+ export function require(dir, ...features) {
46
+ const discovered = repo(dir);
47
+ if (!discovered) throw vcsError("NotARepository", `not a repository: ${dir}`);
48
+ for (const feature of features) {
49
+ if (!discovered.supports(feature)) {
50
+ throw vcsError(
51
+ "Unsupported",
52
+ `\`${feature}\` is not supported on a ${discovered.kind()} repository`,
53
+ );
54
+ }
55
+ }
56
+ return discovered;
57
+ }
58
+
59
+ /** Like {@link git}, but throws a `NotARepository` VcsError. */
60
+ export function requireGit(dir) {
61
+ const repo = git(dir);
62
+ if (!repo) {
63
+ throw vcsError("NotARepository", `not a repository: ${dir}`);
64
+ }
65
+ return repo;
66
+ }
67
+
68
+ /** Repository metadata only (cheap fs walk) — for synchronous render paths. */
69
+ export function gitInfo(dir) {
70
+ return api().vcsGitRepoInfo(dir);
71
+ }
72
+
73
+ /** Discover the Jujutsu workspace containing `dir`; `null` when absent. */
74
+ export function jj(dir) {
75
+ return api().vcsJjDiscover(dir);
76
+ }
77
+
78
+ /** Whether jj is the nearest VCS ancestor, making git automation unsafe. */
79
+ export function isPureJj(dir) {
80
+ return api().vcsIsPureJj(dir);
81
+ }
82
+
83
+ /** Clone a repository (git CLI under the hood for credential parity). */
84
+ export function clone(url, target, options = {}, signal) {
85
+ return api().vcsGitClone(url, target, options, signal);
86
+ }
87
+
88
+ /** Sever a copied working tree from shared git metadata. */
89
+ export function detachGitDir(worktreeRoot, sourceCommonDir, signal) {
90
+ return api().vcsDetachGitDir(worktreeRoot, sourceCommonDir, signal);
91
+ }
92
+
93
+ /** Join patch fragments, preserving each part's trailing newline. */
94
+ export function joinPatches(parts) {
95
+ return api().vcsJoinPatches(parts);
96
+ }
97
+
98
+ /** Validate hunk selections against a raw diff. */
99
+ export function validateHunkSelections(rawDiff, selections) {
100
+ return api().vcsValidateHunkSelections(rawDiff, selections);
101
+ }
102
+
103
+ /** Stat-poll interval for {@link watch}. */
104
+ export const HEAD_WATCH_INTERVAL_MS = 1000;
105
+
106
+ /**
107
+ * Watch a repository for head changes; returns a disposer.
108
+ *
109
+ * Stat-polls via `fs.watchFile` instead of `fs.watch`: backends may atomically
110
+ * replace the watched entry, permanently silencing inotify-backed watchers.
111
+ */
112
+ export function watch(repo, onChange, intervalMs = HEAD_WATCH_INTERVAL_MS) {
113
+ const target = repo.watchTarget();
114
+ const listener = (curr, prev) => {
115
+ if (curr.mtimeMs !== prev.mtimeMs || curr.ino !== prev.ino || curr.size !== prev.size) onChange();
116
+ };
117
+ fs.watchFile(target, { interval: intervalMs }, listener).unref();
118
+ return () => fs.unwatchFile(target, listener);
119
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-natives",
3
- "version": "18.0.8",
3
+ "version": "18.0.9",
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",
@@ -72,6 +72,8 @@
72
72
  "native/desktop-adapter.d.ts",
73
73
  "native/loader-state.js",
74
74
  "native/loader-state.d.ts",
75
+ "native/vcs.js",
76
+ "native/vcs.d.ts",
75
77
  "native/embedded-addon.js",
76
78
  "README.md",
77
79
  "LICENSE",
@@ -89,13 +91,17 @@
89
91
  "./clipboard": {
90
92
  "types": "./native/clipboard.d.ts",
91
93
  "import": "./native/clipboard.js"
94
+ },
95
+ "./vcs": {
96
+ "types": "./native/vcs.d.ts",
97
+ "import": "./native/vcs.js"
92
98
  }
93
99
  },
94
100
  "optionalDependencies": {
95
- "@oh-my-pi/pi-natives-linux-x64": "18.0.8",
96
- "@oh-my-pi/pi-natives-linux-arm64": "18.0.8",
97
- "@oh-my-pi/pi-natives-darwin-x64": "18.0.8",
98
- "@oh-my-pi/pi-natives-darwin-arm64": "18.0.8",
99
- "@oh-my-pi/pi-natives-win32-x64": "18.0.8"
101
+ "@oh-my-pi/pi-natives-linux-x64": "18.0.9",
102
+ "@oh-my-pi/pi-natives-linux-arm64": "18.0.9",
103
+ "@oh-my-pi/pi-natives-darwin-x64": "18.0.9",
104
+ "@oh-my-pi/pi-natives-darwin-arm64": "18.0.9",
105
+ "@oh-my-pi/pi-natives-win32-x64": "18.0.9"
100
106
  }
101
107
  }