isomorphic-jj 1.0.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +971 -0
  3. package/dist/index.cjs +12609 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.mjs +12600 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +90 -0
  8. package/src/api/repository.js +6885 -0
  9. package/src/backend/isomorphic-git-backend.js +687 -0
  10. package/src/backend/lazy-git-backend.js +180 -0
  11. package/src/browser/helpers.js +189 -0
  12. package/src/browser/index.d.ts +174 -0
  13. package/src/browser/index.js +12 -0
  14. package/src/core/background-ops.js +272 -0
  15. package/src/core/bookmark-store.js +232 -0
  16. package/src/core/change-graph.js +285 -0
  17. package/src/core/conflict-model.js +505 -0
  18. package/src/core/jj-checkout.js +78 -0
  19. package/src/core/jj-operation-store.js +120 -0
  20. package/src/core/jj-tree-state.js +94 -0
  21. package/src/core/jj-view-store.js +105 -0
  22. package/src/core/merge-driver-registry.js +432 -0
  23. package/src/core/operation-log.js +272 -0
  24. package/src/core/revset-engine.js +1081 -0
  25. package/src/core/storage-manager.js +207 -0
  26. package/src/core/tag-store.js +167 -0
  27. package/src/core/user-config.js +142 -0
  28. package/src/core/working-copy.js +314 -0
  29. package/src/core/workspace-manager.js +283 -0
  30. package/src/drivers/built-in-drivers.js +296 -0
  31. package/src/index.js +15 -0
  32. package/src/protos/local_working_copy.proto +76 -0
  33. package/src/protos/simple_op_store.proto +147 -0
  34. package/src/types.d.ts +1129 -0
  35. package/src/utils/errors.js +21 -0
  36. package/src/utils/id-generation.js +54 -0
  37. package/src/utils/validation.js +124 -0
package/src/types.d.ts ADDED
@@ -0,0 +1,1129 @@
1
+ /**
2
+ * TypeScript type definitions for isomorphic-jj
3
+ *
4
+ * This file provides type safety for the isomorphic-jj API.
5
+ */
6
+
7
+ // ============================================================================
8
+ // Core Types
9
+ // ============================================================================
10
+
11
+ /**
12
+ * Unique identifier for a change (stable across rewrites)
13
+ */
14
+ export type ChangeID = string;
15
+
16
+ /**
17
+ * Git commit hash (mutable, changes on rewrite)
18
+ */
19
+ export type CommitID = string;
20
+
21
+ /**
22
+ * Unique identifier for an operation in the operation log
23
+ */
24
+ export type OperationID = string;
25
+
26
+ /**
27
+ * Git tree hash reference
28
+ */
29
+ export type TreeRef = string;
30
+
31
+ /**
32
+ * Revset expression for querying changes
33
+ */
34
+ export type Revset = string;
35
+
36
+ // ============================================================================
37
+ // User and Author Types
38
+ // ============================================================================
39
+
40
+ /**
41
+ * User information for commits and operations
42
+ */
43
+ export interface User {
44
+ name: string;
45
+ email: string;
46
+ }
47
+
48
+ /**
49
+ * Author information with timestamp
50
+ */
51
+ export interface Author extends User {
52
+ timestamp: Date;
53
+ }
54
+
55
+ /**
56
+ * User information for operation log
57
+ */
58
+ export interface OperationUser extends User {
59
+ hostname: string;
60
+ }
61
+
62
+ // ============================================================================
63
+ // Change and Commit Types
64
+ // ============================================================================
65
+
66
+ /**
67
+ * A change in the repository
68
+ */
69
+ export interface Change {
70
+ changeId: ChangeID;
71
+ commitId: CommitID;
72
+ parents: ChangeID[];
73
+ tree: TreeRef;
74
+ author: Author;
75
+ committer: Author;
76
+ description: string;
77
+ timestamp: Date;
78
+ fileSnapshot?: Record<string, FileSnapshot>;
79
+ }
80
+
81
+ /**
82
+ * File snapshot data for undo operations
83
+ */
84
+ export interface FileSnapshot {
85
+ content: Uint8Array | string;
86
+ mode: number;
87
+ }
88
+
89
+ /**
90
+ * Log entry with additional metadata
91
+ */
92
+ export interface LogEntry {
93
+ change: Change;
94
+ children: ChangeID[];
95
+ bookmarks: string[];
96
+ remoteBookmarks: Map<string, string[]>;
97
+ isWorkingCopy: boolean;
98
+ hasConflicts: boolean;
99
+ }
100
+
101
+ // ============================================================================
102
+ // Operation Log Types
103
+ // ============================================================================
104
+
105
+ /**
106
+ * An operation in the operation log
107
+ */
108
+ export interface Operation {
109
+ id: OperationID;
110
+ timestamp: Date;
111
+ user: OperationUser;
112
+ description: string;
113
+ parents: OperationID[];
114
+ view: View;
115
+ fileSnapshot?: Record<string, FileSnapshot>;
116
+ }
117
+
118
+ /**
119
+ * Repository view at a specific operation
120
+ */
121
+ export interface View {
122
+ bookmarks: Map<string, ChangeID>;
123
+ remoteBookmarks: Map<string, Map<string, ChangeID>>;
124
+ heads: Set<ChangeID>;
125
+ workingCopy: ChangeID;
126
+ }
127
+
128
+ // ============================================================================
129
+ // Bookmark Types
130
+ // ============================================================================
131
+
132
+ /**
133
+ * A bookmark (named pointer to a change)
134
+ */
135
+ export interface Bookmark {
136
+ name: string;
137
+ target: ChangeID;
138
+ remote?: string;
139
+ }
140
+
141
+ // ============================================================================
142
+ // Conflict Types
143
+ // ============================================================================
144
+
145
+ /**
146
+ * Types of conflicts
147
+ */
148
+ export type ConflictType = 'content' | 'add-add' | 'delete-modify' | 'modify-delete';
149
+
150
+ /**
151
+ * A conflict in the repository
152
+ */
153
+ export interface Conflict {
154
+ conflictId: string;
155
+ path: string;
156
+ type: ConflictType;
157
+ base?: TreeRef;
158
+ sides: TreeRef[];
159
+ resolved: boolean;
160
+ }
161
+
162
+ /**
163
+ * Conflict resolution
164
+ */
165
+ export type ConflictResolution =
166
+ | { side: 'ours' | 'theirs' | 'base' }
167
+ | { content: Uint8Array | string };
168
+
169
+ // ============================================================================
170
+ // Workspace Types
171
+ // ============================================================================
172
+
173
+ /**
174
+ * A workspace (working copy)
175
+ */
176
+ export interface Workspace {
177
+ id: string;
178
+ path: string;
179
+ name: string;
180
+ changeId: ChangeID;
181
+ active: boolean;
182
+ }
183
+
184
+ // ============================================================================
185
+ // File Operation Types
186
+ // ============================================================================
187
+
188
+ /**
189
+ * File metadata
190
+ */
191
+ export interface FileInfo {
192
+ path: string;
193
+ size: number;
194
+ mode: number;
195
+ mtime: number;
196
+ type: 'file' | 'symlink' | 'directory';
197
+ }
198
+
199
+ /**
200
+ * Working copy status
201
+ */
202
+ export interface Status {
203
+ workingCopy: Change;
204
+ modified: string[];
205
+ added: string[];
206
+ removed: string[];
207
+ conflicts: string[];
208
+ }
209
+
210
+ /**
211
+ * Repository statistics
212
+ */
213
+ export interface RepositoryStats {
214
+ changes: {
215
+ total: number;
216
+ mine: number;
217
+ merges: number;
218
+ empty: number;
219
+ };
220
+ files: {
221
+ total: number;
222
+ modified: number;
223
+ added: number;
224
+ removed: number;
225
+ };
226
+ authors: {
227
+ total: number;
228
+ list: Array<{ name: string; email: string; count: number }>;
229
+ };
230
+ bookmarks: {
231
+ local: number;
232
+ remote: number;
233
+ };
234
+ }
235
+
236
+ // ============================================================================
237
+ // Configuration and Options Types
238
+ // ============================================================================
239
+
240
+ /**
241
+ * Filesystem interface (Node fs or LightningFS compatible)
242
+ */
243
+ export interface FileSystem {
244
+ promises: {
245
+ readFile(path: string, encoding?: string): Promise<string | Uint8Array>;
246
+ writeFile(path: string, data: string | Uint8Array): Promise<void>;
247
+ mkdir(path: string, options?: { recursive?: boolean }): Promise<void>;
248
+ readdir(path: string): Promise<string[]>;
249
+ stat(path: string): Promise<{ size: number; mtime: Date; isDirectory(): boolean }>;
250
+ unlink(path: string): Promise<void>;
251
+ rmdir(path: string, options?: { recursive?: boolean }): Promise<void>;
252
+ };
253
+ }
254
+
255
+ /**
256
+ * HTTP client interface for network operations
257
+ */
258
+ export interface HttpClient {
259
+ (args: any): Promise<any>;
260
+ }
261
+
262
+ /**
263
+ * Event hook context
264
+ */
265
+ export interface HookContext {
266
+ operation: string;
267
+ changeId?: ChangeID;
268
+ change?: Change;
269
+ user?: User;
270
+ }
271
+
272
+ /**
273
+ * Event hooks configuration
274
+ */
275
+ export interface Hooks {
276
+ preCommit?: (context: HookContext) => Promise<void>;
277
+ postCommit?: (context: HookContext) => Promise<void>;
278
+ }
279
+
280
+ /**
281
+ * JJ repository creation options
282
+ */
283
+ export interface CreateJJOptions {
284
+ /** Filesystem implementation (Node fs, LightningFS, etc.) */
285
+ fs: FileSystem;
286
+ /** Repository directory path */
287
+ dir: string;
288
+ /** isomorphic-git instance (enables Git backend) */
289
+ git?: any;
290
+ /** HTTP client for network operations */
291
+ http?: HttpClient;
292
+ /** Backend name or instance */
293
+ backend?: string | any;
294
+ /** Event hooks */
295
+ hooks?: Hooks;
296
+ }
297
+
298
+ /**
299
+ * Repository initialization options
300
+ */
301
+ export interface InitOptions {
302
+ userName?: string;
303
+ userEmail?: string;
304
+ colocate?: boolean;
305
+ defaultRemote?: string;
306
+ }
307
+
308
+ /**
309
+ * Write file arguments
310
+ */
311
+ export interface WriteArgs {
312
+ path: string;
313
+ data: Uint8Array | string;
314
+ }
315
+
316
+ /**
317
+ * Read file arguments
318
+ */
319
+ export interface ReadArgs {
320
+ path: string;
321
+ changeId?: ChangeID;
322
+ encoding?: 'utf-8' | 'binary';
323
+ }
324
+
325
+ /**
326
+ * Move file arguments
327
+ */
328
+ export interface MoveFileArgs {
329
+ from: string;
330
+ to: string;
331
+ }
332
+
333
+ /**
334
+ * Remove file arguments
335
+ */
336
+ export interface RemoveArgs {
337
+ path: string;
338
+ }
339
+
340
+ /**
341
+ * List files arguments
342
+ */
343
+ export interface ListFilesArgs {
344
+ changeId?: ChangeID;
345
+ }
346
+
347
+ /**
348
+ * Read stream arguments (Node.js only)
349
+ */
350
+ export interface ReadStreamArgs {
351
+ path: string;
352
+ changeId?: ChangeID;
353
+ encoding?: string;
354
+ }
355
+
356
+ /**
357
+ * Write stream arguments (Node.js only)
358
+ */
359
+ export interface WriteStreamArgs {
360
+ path: string;
361
+ encoding?: string;
362
+ }
363
+
364
+ /**
365
+ * Describe change arguments
366
+ */
367
+ export interface DescribeArgs {
368
+ message?: string;
369
+ author?: User;
370
+ }
371
+
372
+ /**
373
+ * Create new change arguments
374
+ */
375
+ export interface NewArgs {
376
+ message?: string;
377
+ parents?: ChangeID | ChangeID[];
378
+ from?: Revset;
379
+ insertAfter?: ChangeID;
380
+ insertBefore?: ChangeID;
381
+ }
382
+
383
+ /**
384
+ * Amend change arguments
385
+ */
386
+ export interface AmendArgs {
387
+ message?: string;
388
+ }
389
+
390
+ /**
391
+ * Commit change arguments (describe + new)
392
+ */
393
+ export interface CommitArgs {
394
+ message?: string;
395
+ author?: User;
396
+ nextMessage?: string;
397
+ }
398
+
399
+ /**
400
+ * Edit change arguments
401
+ */
402
+ export interface EditArgs {
403
+ changeId: Revset;
404
+ }
405
+
406
+ /**
407
+ * Squash changes arguments
408
+ */
409
+ export interface SquashArgs {
410
+ source?: ChangeID;
411
+ dest?: ChangeID;
412
+ into?: ChangeID;
413
+ }
414
+
415
+ /**
416
+ * Split change arguments
417
+ */
418
+ export interface SplitArgs {
419
+ changeId: ChangeID;
420
+ description1: string;
421
+ description2: string;
422
+ paths?: string[];
423
+ }
424
+
425
+ /**
426
+ * Move change arguments
427
+ */
428
+ export interface MoveChangeArgs {
429
+ from: Revset;
430
+ to: Revset;
431
+ paths?: string[];
432
+ }
433
+
434
+ /**
435
+ * Rebase change arguments (matches `jj rebase`)
436
+ */
437
+ export interface RebaseArgs {
438
+ changeId: ChangeID;
439
+ newParent: ChangeID;
440
+ paths?: string[];
441
+ }
442
+
443
+ /**
444
+ * Abandon change arguments
445
+ */
446
+ export interface AbandonArgs {
447
+ changeId?: ChangeID;
448
+ }
449
+
450
+ /**
451
+ * Un-abandon change arguments
452
+ */
453
+ export interface UnabandonArgs {
454
+ changeId: ChangeID;
455
+ }
456
+
457
+ /**
458
+ * Log query options
459
+ */
460
+ export interface LogOptions {
461
+ revset?: Revset;
462
+ limit?: number;
463
+ }
464
+
465
+ /**
466
+ * Show change arguments
467
+ */
468
+ export interface ShowArgs {
469
+ change: Revset;
470
+ }
471
+
472
+ /**
473
+ * Obslog options
474
+ */
475
+ export interface ObslogOptions {
476
+ change?: Revset;
477
+ limit?: number;
478
+ }
479
+
480
+ /**
481
+ * Undo options
482
+ */
483
+ export interface UndoOptions {
484
+ count?: number;
485
+ }
486
+
487
+ /**
488
+ * Resolve conflict arguments
489
+ */
490
+ export interface ResolveConflictArgs {
491
+ change: Revset;
492
+ path: string;
493
+ resolution: ConflictResolution;
494
+ }
495
+
496
+ /**
497
+ * Merge arguments
498
+ */
499
+ export interface MergeArgs {
500
+ source: Revset;
501
+ dest?: Revset;
502
+ message?: string;
503
+ }
504
+
505
+ /**
506
+ * Bookmark set arguments
507
+ */
508
+ export interface BookmarkSetArgs {
509
+ name: string;
510
+ changeId: ChangeID;
511
+ }
512
+
513
+ /**
514
+ * Bookmark create arguments
515
+ */
516
+ export interface BookmarkCreateArgs {
517
+ name: string;
518
+ changeId: ChangeID;
519
+ }
520
+
521
+ /**
522
+ * Bookmark move arguments
523
+ */
524
+ export interface BookmarkMoveArgs {
525
+ name: string;
526
+ to: ChangeID;
527
+ }
528
+
529
+ /**
530
+ * Bookmark delete arguments
531
+ */
532
+ export interface BookmarkDeleteArgs {
533
+ name: string;
534
+ }
535
+
536
+ /**
537
+ * Bookmark rename arguments (matches `jj bookmark rename`)
538
+ */
539
+ export interface BookmarkRenameArgs {
540
+ oldName: string;
541
+ newName: string;
542
+ }
543
+
544
+ /**
545
+ * Bookmark track arguments (matches `jj bookmark track`)
546
+ */
547
+ export interface BookmarkTrackArgs {
548
+ name: string;
549
+ remote?: string;
550
+ }
551
+
552
+ /**
553
+ * Bookmark untrack arguments (matches `jj bookmark untrack`)
554
+ */
555
+ export interface BookmarkUntrackArgs {
556
+ name: string;
557
+ }
558
+
559
+ /**
560
+ * Bookmark forget arguments (matches `jj bookmark forget`)
561
+ */
562
+ export interface BookmarkForgetArgs {
563
+ name: string;
564
+ remote?: string;
565
+ }
566
+
567
+ /**
568
+ * Remote add arguments
569
+ */
570
+ export interface RemoteAddArgs {
571
+ name: string;
572
+ url: string;
573
+ }
574
+
575
+ /**
576
+ * Remote remove arguments
577
+ */
578
+ export interface RemoteRemoveArgs {
579
+ name: string;
580
+ }
581
+
582
+ /**
583
+ * Remote rename arguments
584
+ */
585
+ export interface RemoteRenameArgs {
586
+ oldName: string;
587
+ newName: string;
588
+ }
589
+
590
+ /**
591
+ * Remote setUrl arguments
592
+ */
593
+ export interface RemoteSetUrlArgs {
594
+ name: string;
595
+ url: string;
596
+ }
597
+
598
+ /**
599
+ * Remote fetch arguments
600
+ */
601
+ export interface RemoteFetchArgs {
602
+ remote?: string;
603
+ refs?: string[];
604
+ depth?: number;
605
+ singleBranch?: boolean;
606
+ noTags?: boolean;
607
+ relative?: boolean;
608
+ }
609
+
610
+ /**
611
+ * Remote push arguments
612
+ */
613
+ export interface RemotePushArgs {
614
+ remote?: string;
615
+ refs?: string[];
616
+ force?: boolean;
617
+ }
618
+
619
+ /**
620
+ * Git export arguments
621
+ */
622
+ export interface GitExportArgs {
623
+ bookmark?: string;
624
+ }
625
+
626
+ /**
627
+ * Git clone arguments (matches `jj git clone`)
628
+ */
629
+ export interface GitCloneArgs {
630
+ url: string;
631
+ dir?: string;
632
+ depth?: number;
633
+ singleBranch?: boolean;
634
+ noTags?: boolean;
635
+ ref?: string;
636
+ onProgress?: (event: any) => void;
637
+ onAuth?: () => Promise<any>;
638
+ }
639
+
640
+ /**
641
+ * Diff arguments (matches `jj diff`)
642
+ */
643
+ export interface DiffArgs {
644
+ from?: Revset;
645
+ to?: Revset;
646
+ paths?: string[];
647
+ }
648
+
649
+ /**
650
+ * Next arguments (matches `jj next`)
651
+ */
652
+ export interface NextArgs {
653
+ offset?: number;
654
+ }
655
+
656
+ /**
657
+ * Prev arguments (matches `jj prev`)
658
+ */
659
+ export interface PrevArgs {
660
+ offset?: number;
661
+ }
662
+
663
+ /**
664
+ * Duplicate arguments (matches `jj duplicate`)
665
+ */
666
+ export interface DuplicateArgs {
667
+ changes?: ChangeID[];
668
+ destination?: Revset;
669
+ }
670
+
671
+ /**
672
+ * Restore arguments (matches `jj restore`)
673
+ */
674
+ export interface RestoreArgs {
675
+ from?: Revset;
676
+ to?: Revset;
677
+ paths?: string[];
678
+ }
679
+
680
+ /**
681
+ * File annotate arguments (matches `jj file annotate`)
682
+ */
683
+ export interface FileAnnotateArgs {
684
+ path: string;
685
+ changeId?: ChangeID;
686
+ }
687
+
688
+ /**
689
+ * Operation show arguments (matches `jj operation show`)
690
+ */
691
+ export interface OperationShowArgs {
692
+ operation: OperationID;
693
+ }
694
+
695
+ /**
696
+ * Operation diff arguments (matches `jj operation diff`)
697
+ */
698
+ export interface OperationDiffArgs {
699
+ from: OperationID;
700
+ to: OperationID;
701
+ }
702
+
703
+ /**
704
+ * Operation restore arguments (matches `jj operation restore`)
705
+ */
706
+ export interface OperationRestoreArgs {
707
+ operation: OperationID;
708
+ }
709
+
710
+ /**
711
+ * Config get arguments (matches `jj config get`)
712
+ */
713
+ export interface ConfigGetArgs {
714
+ name: string;
715
+ }
716
+
717
+ /**
718
+ * Config set arguments (matches `jj config set`)
719
+ */
720
+ export interface ConfigSetArgs {
721
+ name: string;
722
+ value: any;
723
+ }
724
+
725
+ /**
726
+ * Workspace add arguments
727
+ */
728
+ export interface WorkspaceAddArgs {
729
+ path: string;
730
+ name: string;
731
+ changeId?: ChangeID;
732
+ }
733
+
734
+ /**
735
+ * Workspace remove arguments
736
+ */
737
+ export interface WorkspaceRemoveArgs {
738
+ id: string;
739
+ }
740
+
741
+ /**
742
+ * Workspace forget arguments (matches `jj workspace forget`)
743
+ */
744
+ export interface WorkspaceForgetArgs {
745
+ id: string;
746
+ }
747
+
748
+ /**
749
+ * Workspace rename arguments (matches `jj workspace rename`)
750
+ */
751
+ export interface WorkspaceRenameArgs {
752
+ workspace: string;
753
+ newName: string;
754
+ }
755
+
756
+ /**
757
+ * File chmod arguments (Node.js only)
758
+ */
759
+ export interface FileChmodArgs {
760
+ path: string;
761
+ mode: number | string;
762
+ }
763
+
764
+ /**
765
+ * File track arguments (stub - throws error)
766
+ */
767
+ export interface FileTrackArgs {
768
+ path: string;
769
+ }
770
+
771
+ /**
772
+ * File untrack arguments (stub - throws error)
773
+ */
774
+ export interface FileUntrackArgs {
775
+ path: string;
776
+ }
777
+
778
+ /**
779
+ * Parallelize arguments (matches `jj parallelize`)
780
+ */
781
+ export interface ParallelizeArgs {
782
+ changes: ChangeID[];
783
+ parent?: ChangeID;
784
+ }
785
+
786
+ /**
787
+ * Operation revert arguments (matches `jj operation revert`)
788
+ */
789
+ export interface OperationRevertArgs {
790
+ operation: OperationID;
791
+ }
792
+
793
+ /**
794
+ * Operation abandon arguments (matches `jj operation abandon`)
795
+ */
796
+ export interface OperationAbandonArgs {
797
+ operation: OperationID;
798
+ }
799
+
800
+ /**
801
+ * Background operation options
802
+ */
803
+ export interface BackgroundOptions {
804
+ debounceMs?: number;
805
+ }
806
+
807
+ // ============================================================================
808
+ // Return Types
809
+ // ============================================================================
810
+
811
+ /**
812
+ * Write operation result
813
+ */
814
+ export interface WriteResult extends FileInfo {}
815
+
816
+ /**
817
+ * Move operation result
818
+ */
819
+ export interface MoveResult {
820
+ from: string;
821
+ to: string;
822
+ }
823
+
824
+ /**
825
+ * Remove operation result
826
+ */
827
+ export interface RemoveResult extends FileInfo {}
828
+
829
+ /**
830
+ * Undo operation result
831
+ */
832
+ export interface UndoResult {
833
+ undoneOperation: {
834
+ description: string;
835
+ timestamp: Date;
836
+ };
837
+ restoredState: {
838
+ workingCopy: ChangeID;
839
+ filesRestored: number;
840
+ };
841
+ }
842
+
843
+ /**
844
+ * Split operation result
845
+ */
846
+ export interface SplitResult {
847
+ original: Change;
848
+ new: Change;
849
+ }
850
+
851
+ /**
852
+ * Merge operation result
853
+ */
854
+ export interface MergeResult {
855
+ merged: boolean;
856
+ conflicts: Conflict[];
857
+ }
858
+
859
+ // ============================================================================
860
+ // Main JJ Repository Interface
861
+ // ============================================================================
862
+
863
+ /**
864
+ * Main JJ repository instance
865
+ */
866
+ export interface JJ {
867
+ // Core components (exposed for advanced usage)
868
+ graph: any;
869
+ workingCopy: any;
870
+ oplog: any;
871
+ bookmarks: any;
872
+ conflicts: any;
873
+ workspaces: any;
874
+ userConfig: any;
875
+ revset: any;
876
+ gitBackend?: any;
877
+ backgroundOps?: any;
878
+
879
+ // Repository lifecycle
880
+ init(opts?: InitOptions): Promise<void>;
881
+
882
+ // File operations
883
+ write(args: WriteArgs): Promise<WriteResult>;
884
+ read(args: ReadArgs): Promise<string | Uint8Array>;
885
+ cat(args: ReadArgs): Promise<string | Uint8Array>;
886
+ move(args: MoveFileArgs): Promise<MoveResult>;
887
+ remove(args: RemoveArgs): Promise<RemoveResult>;
888
+ listFiles(args?: ListFilesArgs): Promise<string[]>;
889
+ readStream(args: ReadStreamArgs): Promise<any>;
890
+ writeStream(args: WriteStreamArgs): Promise<any>;
891
+
892
+ // Change operations
893
+ describe(args?: DescribeArgs): Promise<Change>;
894
+ new(args?: NewArgs): Promise<Change>;
895
+ amend(args?: AmendArgs): Promise<Change>;
896
+ commit(args?: CommitArgs): Promise<Change>;
897
+ edit(args: EditArgs): Promise<void>;
898
+ status(): Promise<Status>;
899
+ stats(): Promise<RepositoryStats>;
900
+
901
+ // History editing
902
+ squash(args: SquashArgs): Promise<void>;
903
+ split(args: SplitArgs): Promise<SplitResult>;
904
+ rebase(args: RebaseArgs): Promise<Change>;
905
+ abandon(args: AbandonArgs): Promise<void>;
906
+ unabandon(args: UnabandonArgs): Promise<void>;
907
+
908
+ // Queries
909
+ log(opts?: LogOptions): Promise<LogEntry[]>;
910
+ show(args: ShowArgs): Promise<Change>;
911
+ obslog(opts?: ObslogOptions): Promise<Operation[]>;
912
+
913
+ // Operations
914
+ undo(opts?: UndoOptions): Promise<UndoResult>;
915
+ operations: {
916
+ list(opts?: { limit?: number }): Promise<Operation[]>;
917
+ at(args: { operation: OperationID }): Promise<JJ>;
918
+ show(args: OperationShowArgs): Promise<Operation & { changes: Change[] }>;
919
+ diff(args: OperationDiffArgs): Promise<{
920
+ from: OperationID;
921
+ to: OperationID;
922
+ addedHeads: ChangeID[];
923
+ removedHeads: ChangeID[];
924
+ bookmarkChanges: Record<string, { from?: ChangeID; to?: ChangeID }>;
925
+ workingCopyChanged: boolean;
926
+ }>;
927
+ restore(args: OperationRestoreArgs): Promise<{
928
+ restoredTo: OperationID;
929
+ timestamp: Date;
930
+ description: string;
931
+ }>;
932
+ revert(args: OperationRevertArgs): Promise<{
933
+ reverted: OperationID;
934
+ inverseChanges: {
935
+ bookmarks: Record<string, { action: string; from?: ChangeID; to?: ChangeID }>;
936
+ heads: ChangeID[];
937
+ };
938
+ description: string;
939
+ }>;
940
+ abandon(args: OperationAbandonArgs): Promise<{
941
+ abandoned: OperationID;
942
+ description: string;
943
+ relinkedChildren: Array<{
944
+ operationId: OperationID;
945
+ oldParents: OperationID[];
946
+ newParents: OperationID[];
947
+ }>;
948
+ newHead: OperationID | null;
949
+ }>;
950
+ };
951
+
952
+ // Conflicts
953
+ merge(args: MergeArgs): Promise<MergeResult>;
954
+
955
+ /**
956
+ * Interactive conflict resolution (stub - throws error)
957
+ *
958
+ * This method always throws an error explaining that interactive
959
+ * conflict resolution is not supported in JavaScript environments.
960
+ * Use the programmatic conflicts API instead.
961
+ *
962
+ * @throws {JJError} Always throws UNSUPPORTED_OPERATION
963
+ */
964
+ resolve(): Promise<never>;
965
+
966
+ // Bookmarks
967
+ bookmark: {
968
+ list(): Promise<Bookmark[]>;
969
+ set(args: BookmarkSetArgs): Promise<{ name: string; changeId: ChangeID }>;
970
+ create(args: BookmarkCreateArgs): Promise<{ name: string; changeId: ChangeID }>;
971
+ move(args: BookmarkMoveArgs): Promise<{ name: string; from: ChangeID; to: ChangeID }>;
972
+ delete(args: BookmarkDeleteArgs): Promise<{ deleted: string }>;
973
+ rename(args: BookmarkRenameArgs): Promise<{ oldName: string; newName: string; changeId: ChangeID }>;
974
+ track(args: BookmarkTrackArgs): Promise<{ name: string; remote: string; tracking: boolean }>;
975
+ untrack(args: BookmarkUntrackArgs): Promise<{ name: string; tracking: boolean; wasTracking: boolean }>;
976
+ forget(args: BookmarkForgetArgs): Promise<{ name: string; remote: string; forgotten: boolean }>;
977
+ };
978
+
979
+ // Git operations (only available with Git backend)
980
+ git?: {
981
+ init(opts?: InitOptions): Promise<void>;
982
+ fetch(args?: RemoteFetchArgs): Promise<void>;
983
+ push(args?: RemotePushArgs): Promise<void>;
984
+ import(): Promise<{ imported: string[] }>;
985
+ export(args?: GitExportArgs): Promise<{ exported: string[] }>;
986
+ clone(args: GitCloneArgs): Promise<{ url: string; directory: string; ref: string }>;
987
+ root(): Promise<{ root: string; gitDir: string }>;
988
+ remote: {
989
+ list(): Promise<Array<{ name: string; url: string }>>;
990
+ add(args: RemoteAddArgs): Promise<{ name: string; url: string }>;
991
+ remove(args: RemoteRemoveArgs): Promise<{ removed: string }>;
992
+ rename(args: RemoteRenameArgs): Promise<{ oldName: string; newName: string; url: string }>;
993
+ setUrl(args: RemoteSetUrlArgs): Promise<{ name: string; url: string }>;
994
+ };
995
+ };
996
+
997
+ // Remote operations
998
+ remote: {
999
+ add(args: RemoteAddArgs): Promise<void>;
1000
+ fetch(args?: RemoteFetchArgs): Promise<void>;
1001
+ push(args?: RemotePushArgs): Promise<void>;
1002
+ };
1003
+
1004
+ // File operations (matches JJ CLI file commands)
1005
+ file: {
1006
+ show(args: ReadArgs): Promise<string | Uint8Array>;
1007
+ list(args?: ListFilesArgs): Promise<string[]>;
1008
+ write(args: WriteArgs): Promise<WriteResult>;
1009
+ move(args: MoveFileArgs): Promise<MoveResult>;
1010
+ remove(args: RemoveArgs): Promise<RemoveResult>;
1011
+ annotate(args: FileAnnotateArgs): Promise<Array<{
1012
+ lineNumber: number;
1013
+ changeId: ChangeID;
1014
+ author: Author;
1015
+ timestamp: Date;
1016
+ content: string;
1017
+ }>>;
1018
+ chmod(args: FileChmodArgs): Promise<{
1019
+ path: string;
1020
+ mode: number;
1021
+ modeOctal: string;
1022
+ }>;
1023
+ /**
1024
+ * Track files (stub - throws error)
1025
+ *
1026
+ * This method always throws an error explaining that explicit
1027
+ * file tracking is not needed in JavaScript environments.
1028
+ *
1029
+ * @throws {JJError} Always throws UNSUPPORTED_OPERATION
1030
+ */
1031
+ track(args: FileTrackArgs): Promise<never>;
1032
+ /**
1033
+ * Untrack files (stub - throws error)
1034
+ *
1035
+ * This method always throws an error explaining that explicit
1036
+ * file untracking is not needed in JavaScript environments.
1037
+ *
1038
+ * @throws {JJError} Always throws UNSUPPORTED_OPERATION
1039
+ */
1040
+ untrack(args: FileUntrackArgs): Promise<never>;
1041
+ };
1042
+
1043
+ // Workspaces
1044
+ workspace: {
1045
+ add(args: WorkspaceAddArgs): Promise<Workspace>;
1046
+ list(): Promise<Workspace[]>;
1047
+ remove(args: WorkspaceRemoveArgs): Promise<void>;
1048
+ forget(args: WorkspaceForgetArgs): Promise<{ forgotten: boolean }>;
1049
+ get(args: { id: string }): Promise<Workspace | null>;
1050
+ rename(args: WorkspaceRenameArgs): Promise<Workspace>;
1051
+ root(args?: { workspace?: string }): Promise<string>;
1052
+ updateStale(args?: { workspace?: string }): Promise<{ updated: number; workspaces: Array<{ id: string; name: string }> }>;
1053
+ };
1054
+
1055
+ // Background operations (only available in Node.js)
1056
+ background?: {
1057
+ start(): Promise<{ started: boolean }>;
1058
+ stop(): Promise<{ stopped: boolean }>;
1059
+ enableAutoSnapshot(opts?: BackgroundOptions): Promise<void>;
1060
+ disableAutoSnapshot(): Promise<void>;
1061
+ queue<T>(fn: () => Promise<T>): Promise<{ promise: Promise<T>; id: string }>;
1062
+ watch(path: string, callback: (event: string, filename: string) => void): Promise<string>;
1063
+ unwatch(id: string): Promise<void>;
1064
+ };
1065
+
1066
+ // Configuration management
1067
+ config: {
1068
+ get(args: ConfigGetArgs): Promise<any>;
1069
+ set(args: ConfigSetArgs): Promise<{ name: string; value: any }>;
1070
+ list(): Promise<Record<string, any>>;
1071
+ };
1072
+
1073
+ // Diff operation
1074
+ diff(args?: DiffArgs): Promise<{
1075
+ from: ChangeID | null;
1076
+ to: ChangeID;
1077
+ files: Array<{
1078
+ path: string;
1079
+ status: 'added' | 'modified' | 'deleted';
1080
+ fromContent: string;
1081
+ toContent: string;
1082
+ }>;
1083
+ }>;
1084
+
1085
+ // Navigation operations
1086
+ next(args?: NextArgs): Promise<{ from: ChangeID; to: ChangeID; offset: number }>;
1087
+ prev(args?: PrevArgs): Promise<{ from: ChangeID; to: ChangeID; offset: number }>;
1088
+
1089
+ // Advanced change operations
1090
+ duplicate(args?: DuplicateArgs): Promise<{
1091
+ duplicated: Array<{ original: ChangeID; duplicate: ChangeID }>;
1092
+ }>;
1093
+ restore(args?: RestoreArgs): Promise<{
1094
+ from: ChangeID;
1095
+ to: ChangeID;
1096
+ restoredPaths: string[];
1097
+ }>;
1098
+ parallelize(args: ParallelizeArgs): Promise<{
1099
+ parallelized: Array<{
1100
+ changeId: ChangeID;
1101
+ oldParents?: ChangeID[];
1102
+ newParent?: ChangeID;
1103
+ alreadyParallel?: boolean;
1104
+ }>;
1105
+ parent: ChangeID;
1106
+ }>;
1107
+ }
1108
+
1109
+ // ============================================================================
1110
+ // Main Export Function
1111
+ // ============================================================================
1112
+
1113
+ /**
1114
+ * Create and initialize a JJ repository instance
1115
+ *
1116
+ * @param options - Configuration options
1117
+ * @returns Initialized JJ repository instance
1118
+ */
1119
+ export function createJJ(options: CreateJJOptions): Promise<JJ>;
1120
+
1121
+ /**
1122
+ * JJ error class
1123
+ */
1124
+ export class JJError extends Error {
1125
+ code: string;
1126
+ suggestion?: string;
1127
+
1128
+ constructor(code: string, message: string, details?: { suggestion?: string });
1129
+ }