@laoyuehanni/dsh-git-worktree 0.4.14 → 0.4.16

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/lib/wire.d.ts CHANGED
@@ -107,6 +107,23 @@ export declare const ROUTE_WORKTREES_ALL = "/plugin/git-worktree/worktrees-all";
107
107
  /** POST ROUTE_PREFIX/purge — delete a NON-git directory sitting DIRECTLY in
108
108
  * the storage root (an orphaned leftover whose .git is already gone). */
109
109
  export declare const ROUTE_PURGE = "/plugin/git-worktree/purge";
110
+ /** POST ROUTE_PREFIX/session-cwd — move an active blank session's working
111
+ * directory to a worktree directory via the host `workingDirectory` service. */
112
+ export declare const ROUTE_SESSION_CWD = "/plugin/git-worktree/session-cwd";
113
+ /** GET ROUTE_PREFIX/deferred?sessionId=<id> — read a session's deferred worktree state. */
114
+ export declare const ROUTE_DEFERRED = "/plugin/git-worktree/deferred";
115
+ /** GET ROUTE_PREFIX/deferred/events?sessionId=<id> — SSE stream of deferred worktree updates. */
116
+ export declare const ROUTE_DEFERRED_EVENTS = "/plugin/git-worktree/deferred/events";
117
+ /** POST ROUTE_PREFIX/deferred/arm — arm a deferred worktree creation for a blank session. */
118
+ export declare const ROUTE_DEFERRED_ARM = "/plugin/git-worktree/deferred/arm";
119
+ /** POST ROUTE_PREFIX/deferred/action — cancel, retry, or withdraw a deferred worktree. */
120
+ export declare const ROUTE_DEFERRED_ACTION = "/plugin/git-worktree/deferred/action";
121
+ /** POST ROUTE_PREFIX/pr-context — remotes, optional forge readiness, and open PR/MR candidates. */
122
+ export declare const ROUTE_PR_CONTEXT = "/plugin/git-worktree/pr-context";
123
+ /** POST ROUTE_PREFIX/pr-resolve — resolve a PR/MR ID or URL to its fetch ref, branch, and path. */
124
+ export declare const ROUTE_PR_RESOLVE = "/plugin/git-worktree/pr-resolve";
125
+ /** POST ROUTE_PREFIX/pr-checkout — stream PR/MR fetch + isolated worktree creation. */
126
+ export declare const ROUTE_PR_CHECKOUT = "/plugin/git-worktree/pr-checkout";
110
127
  /** One selectable branch row. */
111
128
  export interface BranchEntry {
112
129
  /** Display name: a bare local name (`main`) or `<remote>/<name>`. */
@@ -231,8 +248,12 @@ export interface CreateWorktreeBody {
231
248
  * worktree. The storage folder is named after the new branch. */
232
249
  cutout?: boolean;
233
250
  /** Cutout only: explicit name for the NEW branch. Default (absent):
234
- * derived `<branch>-wt`, suffixing past taken names. */
251
+ * derived `<branch>-wt`, suffixing past taken names (or random `<stem>-<4hex>`
252
+ * when `random` is true). */
235
253
  name?: string;
254
+ /** Cutout only (when `name` is omitted): generate a random `<stem>-<4hex>`
255
+ * branch name instead of the sequential `<branch>-wt` suffix. */
256
+ random?: boolean;
236
257
  }
237
258
  /** POST worktree response body. */
238
259
  export interface CreateWorktreeResult {
@@ -362,6 +383,9 @@ export type SyncEvent = {
362
383
  remote?: string;
363
384
  } | {
364
385
  type: 'merge';
386
+ } | {
387
+ type: 'stage';
388
+ stage: 'fetch' | 'worktree' | 'copy';
365
389
  };
366
390
  /**
367
391
  * One line of a streamed route response. The last line is always `done`,
@@ -376,6 +400,10 @@ export type SyncFrame = SyncEvent | {
376
400
  /** Error envelope every non-2xx response carries. */
377
401
  export interface RouteError {
378
402
  error: string;
403
+ /** Optional machine-readable error code for localized client presentation. */
404
+ code?: string;
405
+ /** Optional structured parameters accompanying `code`. */
406
+ params?: Record<string, string | number>;
379
407
  }
380
408
  /** Git belonging facts of one workspace directory; null = not a git repository. */
381
409
  export interface WorkspaceGitFacts {
@@ -387,6 +415,8 @@ export interface WorkspaceGitFacts {
387
415
  branch: string | null;
388
416
  /** True when this directory IS the main worktree (holds the shared .git). */
389
417
  main: boolean;
418
+ /** Optional base branch recorded when this linked worktree was created from another branch. */
419
+ baseBranch?: string;
390
420
  }
391
421
  /** POST group request body. */
392
422
  export interface GroupWorkspacesBody {
@@ -470,6 +500,9 @@ export interface WorktreesAllBody {
470
500
  export interface WorktreeScanEntry {
471
501
  /** Absolute directory path. */
472
502
  path: string;
503
+ /** Canonical main repository root directory; absent for unrecognized/orphan
504
+ * directories or older host builds. */
505
+ repoRoot?: string;
473
506
  /** Main repository directory basename; null = the directory is not inside
474
507
  * a git repository (an orphan or foreign folder — shown as unrecognized,
475
508
  * never deleted, never counted against the prune cap). */
@@ -479,8 +512,10 @@ export interface WorktreeScanEntry {
479
512
  branch: string | null;
480
513
  /** Where the directory lives: `project` = inside `<repo>/.dsh/gitworktree`
481
514
  * (the current layout, auto-nested under its repository by the workspace
482
- * tree), `legacy` = inside the historical central storage root. */
483
- source: 'legacy' | 'project';
515
+ * tree), `official` = inside `<repo>/.agents/worktrees` (when official
516
+ * worktree management is enabled), `legacy` = inside the historical central
517
+ * storage root. */
518
+ source: 'legacy' | 'project' | 'official';
484
519
  }
485
520
  /** POST worktrees-all response body — one entry per DIRECT child of each
486
521
  * scanned storage location; a missing location answers its half as an empty
@@ -512,3 +547,200 @@ export interface PurgeDirectoryResult {
512
547
  path: string;
513
548
  removed: boolean;
514
549
  }
550
+ /** POST session-cwd request body. */
551
+ export interface SetSessionDirectoryBody {
552
+ /** Target session id whose working directory should move. */
553
+ sessionId: string;
554
+ /** Existing absolute directory path (typically a created or reused worktree). */
555
+ path: string;
556
+ }
557
+ /** POST session-cwd response body. */
558
+ export interface SetSessionDirectoryResult {
559
+ /** Target session id. */
560
+ sessionId: string;
561
+ /** Canonical absolute directory committed by the host workingDirectory service. */
562
+ path: string;
563
+ }
564
+ /** Phases reported while a deferred worktree creation runs on the first user turn. */
565
+ export type DeferredWorktreePhase = 'fetch' | 'create' | 'copy' | 'switch';
566
+ /** PR/MR checkout payload attached to a deferred worktree request in shared-workspace mode. */
567
+ export interface DeferredPrCheckoutSpec {
568
+ readonly input: string;
569
+ readonly remote?: string;
570
+ readonly provider?: PrProviderKind;
571
+ readonly ifExists?: 'reuse' | 'update' | 'reset';
572
+ /** Canonical PR/MR web URL to track in host forge panel after completion, or null when auto-track was opted out. */
573
+ readonly canonicalUrl?: string | null;
574
+ }
575
+ /** Specification of a deferred worktree creation armed on a blank session. */
576
+ export interface DeferredWorktreeSpec {
577
+ /** Main repository path (or any path inside the repository). */
578
+ readonly repoPath: string;
579
+ /** Target branch or base branch (for cutout). */
580
+ readonly branch: string;
581
+ /** Whether to cut a new branch out of `branch`. */
582
+ readonly cutout: boolean;
583
+ /** Explicit new branch name (cutout only); absent when auto/random. */
584
+ readonly name?: string;
585
+ /** Generate a random `<stem>-<4hex>` branch name when `cutout` is true and `name` is absent. */
586
+ readonly random?: boolean;
587
+ /** Present when this deferred slot checks out or enters a PR/MR worktree on the first turn. */
588
+ readonly pr?: DeferredPrCheckoutSpec;
589
+ }
590
+ /** Live state of a deferred worktree for one session. */
591
+ export type DeferredWorktreeState = {
592
+ readonly kind: 'armed';
593
+ readonly spec: DeferredWorktreeSpec;
594
+ } | {
595
+ readonly kind: 'running';
596
+ readonly spec: DeferredWorktreeSpec;
597
+ readonly phase: DeferredWorktreePhase;
598
+ /** Resolved branch name once known. */
599
+ readonly resolvedBranch?: string;
600
+ } | {
601
+ readonly kind: 'failed';
602
+ readonly spec: DeferredWorktreeSpec;
603
+ readonly phase: DeferredWorktreePhase;
604
+ readonly message: string;
605
+ readonly resolvedBranch?: string;
606
+ };
607
+ /** One-shot completion notification emitted when a deferred creation succeeds. */
608
+ export interface DeferredWorktreeCompleted {
609
+ readonly path: string;
610
+ readonly branch: string;
611
+ readonly created: boolean;
612
+ readonly fetchWarning?: string;
613
+ readonly excludeWarning?: string;
614
+ readonly copyWarning?: string;
615
+ readonly trackPrUrl?: string;
616
+ }
617
+ /** Snapshot / SSE payload pushed for a session's deferred worktree. */
618
+ export interface DeferredWorktreeSnapshot {
619
+ readonly state: DeferredWorktreeState | null;
620
+ readonly completed?: DeferredWorktreeCompleted;
621
+ }
622
+ /** POST deferred/arm request body. */
623
+ export interface ArmDeferredWorktreeBody {
624
+ readonly sessionId: string;
625
+ readonly repoPath: string;
626
+ readonly branch: string;
627
+ readonly cutout?: boolean;
628
+ readonly name?: string;
629
+ readonly random?: boolean;
630
+ readonly pr?: DeferredPrCheckoutSpec;
631
+ }
632
+ /** POST deferred/action request body. */
633
+ export interface DeferredWorktreeActionBody {
634
+ readonly sessionId: string;
635
+ readonly action: 'cancel' | 'retry' | 'withdraw';
636
+ }
637
+ /** Supported code-hosting provider kinds for PR/MR checkout. */
638
+ export type PrProviderKind = 'github' | 'gitlab';
639
+ /** Machine-readable error codes emitted by PR/MR routes for localized UI handling. */
640
+ export type PrErrorCode = 'no_remotes' | 'empty_input' | 'invalid_input' | 'unsupported_provider' | 'url_repo_mismatch' | 'remote_not_found' | 'provider_undetected' | 'occupied_by_main' | 'worktree_dirty' | 'worktree_diverged' | 'pr_ref_not_found' | 'pr_auth_failed' | 'pr_timeout' | 'pr_network_failed';
641
+ /** One Git remote classified for PR/MR resolution. */
642
+ export interface PrRemoteInfo {
643
+ name: string;
644
+ url: string;
645
+ /** Classified provider kind (`github` or `gitlab`), or null when unrecognized. */
646
+ provider: PrProviderKind | null;
647
+ host: string | null;
648
+ owner: string | null;
649
+ repo: string | null;
650
+ }
651
+ /** One candidate PR/MR returned by optional host `ctx.forge` integration. */
652
+ export interface PrCandidateItem {
653
+ provider: PrProviderKind;
654
+ host: string;
655
+ owner: string;
656
+ repo: string;
657
+ number: number;
658
+ url: string;
659
+ title: string;
660
+ author: string | null;
661
+ draft: boolean;
662
+ checksRollup: 'none' | 'pending' | 'success' | 'failure';
663
+ reviewDecision: 'approved' | 'changes-requested' | 'review-required' | 'none';
664
+ filter: 'review-requested' | 'authored' | 'involved';
665
+ updatedAt: string;
666
+ remote: string;
667
+ localBranch: string;
668
+ existingWorktreePath?: string;
669
+ }
670
+ /** POST pr-context request body. */
671
+ export interface PrContextBody {
672
+ repoPath: string;
673
+ /** Optional explicit remote to scope optional Forge readiness & candidates. */
674
+ remote?: string;
675
+ }
676
+ /** POST pr-context response body. */
677
+ export interface PrContextResult {
678
+ repoRoot: string;
679
+ repoName: string;
680
+ remotes: PrRemoteInfo[];
681
+ defaultRemote: string | null;
682
+ forge: {
683
+ available: boolean;
684
+ readiness: 'ready' | 'unauthenticated' | 'unavailable' | 'unsupported';
685
+ signInCommand?: string;
686
+ message?: string;
687
+ /** True when the host `ctx.forge` service is ready but does not expose viewer PR list queries yet. */
688
+ listUnsupported?: boolean;
689
+ };
690
+ candidates: PrCandidateItem[];
691
+ }
692
+ /** POST pr-resolve request body. */
693
+ export interface PrResolveBody {
694
+ repoPath: string;
695
+ /** Numeric ID (`42`, `#42`, `!42`) or full PR/MR web URL. */
696
+ input: string;
697
+ remote?: string;
698
+ provider?: PrProviderKind;
699
+ /** Verify the target ref exists on the remote via `git ls-remote` (default: `true`). Pass `false` for items just picked from the live Forge candidate list. */
700
+ verifyRemote?: boolean;
701
+ }
702
+ /** POST pr-resolve response body. */
703
+ export interface PrResolveResult {
704
+ provider: PrProviderKind;
705
+ number: number;
706
+ remote: string;
707
+ refSpec: string;
708
+ localBranch: string;
709
+ targetPath: string;
710
+ canonicalUrl: string | null;
711
+ existingWorktreePath?: string;
712
+ existingBranch?: boolean;
713
+ /** True when the main checkout itself currently holds `localBranch` (blocks linked worktree creation). */
714
+ occupiedByMain?: boolean;
715
+ meta?: {
716
+ title: string;
717
+ author: string | null;
718
+ state: 'open' | 'closed' | 'merged';
719
+ draft: boolean;
720
+ headBranch: string;
721
+ baseBranch: string;
722
+ };
723
+ }
724
+ /** POST pr-checkout request body. */
725
+ export interface PrCheckoutBody {
726
+ repoPath: string;
727
+ input: string;
728
+ remote?: string;
729
+ provider?: PrProviderKind;
730
+ /** When the PR's worktree already exists: reuse immediately, fast-forward/safe-sync when clean, or force-reset after confirmation. */
731
+ ifExists?: 'reuse' | 'update' | 'reset';
732
+ }
733
+ /** POST pr-checkout response body. */
734
+ export interface PrCheckoutResult extends CreateWorktreeResult {
735
+ branch: string;
736
+ provider: PrProviderKind;
737
+ number: number;
738
+ canonicalUrl: string | null;
739
+ updated?: boolean;
740
+ /** True when remote PR history was force-pushed and the clean local PR worktree had no local commits so it was safely synced. */
741
+ forceUpdated?: boolean;
742
+ /** True when the user explicitly confirmed resetting a diverged local PR worktree to the latest remote PR tip. */
743
+ reset?: boolean;
744
+ /** True when an existing local branch with diverged local commits was preserved as-is. */
745
+ preservedLocalBranch?: boolean;
746
+ }
package/lib/wire.js CHANGED
@@ -59,5 +59,22 @@ export const ROUTE_WORKTREES_ALL = `${ROUTE_PREFIX}/worktrees-all`;
59
59
  /** POST ROUTE_PREFIX/purge — delete a NON-git directory sitting DIRECTLY in
60
60
  * the storage root (an orphaned leftover whose .git is already gone). */
61
61
  export const ROUTE_PURGE = `${ROUTE_PREFIX}/purge`;
62
+ /** POST ROUTE_PREFIX/session-cwd — move an active blank session's working
63
+ * directory to a worktree directory via the host `workingDirectory` service. */
64
+ export const ROUTE_SESSION_CWD = `${ROUTE_PREFIX}/session-cwd`;
65
+ /** GET ROUTE_PREFIX/deferred?sessionId=<id> — read a session's deferred worktree state. */
66
+ export const ROUTE_DEFERRED = `${ROUTE_PREFIX}/deferred`;
67
+ /** GET ROUTE_PREFIX/deferred/events?sessionId=<id> — SSE stream of deferred worktree updates. */
68
+ export const ROUTE_DEFERRED_EVENTS = `${ROUTE_PREFIX}/deferred/events`;
69
+ /** POST ROUTE_PREFIX/deferred/arm — arm a deferred worktree creation for a blank session. */
70
+ export const ROUTE_DEFERRED_ARM = `${ROUTE_PREFIX}/deferred/arm`;
71
+ /** POST ROUTE_PREFIX/deferred/action — cancel, retry, or withdraw a deferred worktree. */
72
+ export const ROUTE_DEFERRED_ACTION = `${ROUTE_PREFIX}/deferred/action`;
73
+ /** POST ROUTE_PREFIX/pr-context — remotes, optional forge readiness, and open PR/MR candidates. */
74
+ export const ROUTE_PR_CONTEXT = `${ROUTE_PREFIX}/pr-context`;
75
+ /** POST ROUTE_PREFIX/pr-resolve — resolve a PR/MR ID or URL to its fetch ref, branch, and path. */
76
+ export const ROUTE_PR_RESOLVE = `${ROUTE_PREFIX}/pr-resolve`;
77
+ /** POST ROUTE_PREFIX/pr-checkout — stream PR/MR fetch + isolated worktree creation. */
78
+ export const ROUTE_PR_CHECKOUT = `${ROUTE_PREFIX}/pr-checkout`;
62
79
  /** Content type of a streamed route: one JSON {@link SyncFrame} per line. */
63
80
  export const NDJSON_TYPE = 'application/x-ndjson';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laoyuehanni/dsh-git-worktree",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "description": "DSH plugin: branch visibility and git worktree isolation for Web UI sessions",
5
5
  "icon": "./icon.svg",
6
6
  "keywords": [