@laoyuehanni/dsh-git-worktree 0.4.15 → 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/README.md +2 -1
- package/README.zh.md +2 -1
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/lib/client.js +2032 -509
- package/lib/deferred-worktree.d.ts +2 -1
- package/lib/deferred-worktree.js +2 -1
- package/lib/git.d.ts +76 -0
- package/lib/git.js +303 -0
- package/lib/index.js +45 -3
- package/lib/pr.d.ts +177 -0
- package/lib/pr.js +672 -0
- package/lib/routes.d.ts +30 -3
- package/lib/routes.js +392 -4
- package/lib/wire.d.ts +136 -0
- package/lib/wire.js +6 -0
- package/package.json +1 -1
package/lib/pr.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR/MR resolution, remote classification, and optional `ctx.forge` integration
|
|
3
|
+
* for isolating pull/merge requests into dedicated Git worktrees.
|
|
4
|
+
*/
|
|
5
|
+
import type { PrContextResult, PrErrorCode, PrProviderKind, PrRemoteInfo, PrResolveResult, WorktreeEntry } from './wire.js';
|
|
6
|
+
/** Minimal repository identity returned by `ctx.forge`. */
|
|
7
|
+
export interface ForgeRepositoryLike {
|
|
8
|
+
readonly forge: string;
|
|
9
|
+
readonly host: string;
|
|
10
|
+
readonly owner: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}
|
|
13
|
+
/** Minimal change request reference returned by `ctx.forge`. */
|
|
14
|
+
export interface ChangeRequestRefLike {
|
|
15
|
+
readonly repository: ForgeRepositoryLike;
|
|
16
|
+
readonly number: number;
|
|
17
|
+
}
|
|
18
|
+
/** Minimal change request snapshot shape from `ctx.forge.latest`. */
|
|
19
|
+
export interface ChangeRequestSnapshotLike {
|
|
20
|
+
readonly url: string;
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly state: 'open' | 'closed' | 'merged';
|
|
23
|
+
readonly draft: boolean;
|
|
24
|
+
readonly author: string | null;
|
|
25
|
+
readonly headBranch: string;
|
|
26
|
+
readonly baseBranch: string;
|
|
27
|
+
}
|
|
28
|
+
/** Minimal viewer list entry returned by `ctx.forge.listForViewer`. */
|
|
29
|
+
export interface ForgeViewerSummaryLike {
|
|
30
|
+
readonly ref: ChangeRequestRefLike;
|
|
31
|
+
readonly url: string;
|
|
32
|
+
readonly title: string;
|
|
33
|
+
readonly draft: boolean;
|
|
34
|
+
readonly author: {
|
|
35
|
+
readonly login: string;
|
|
36
|
+
} | null;
|
|
37
|
+
readonly checksRollup: 'none' | 'pending' | 'success' | 'failure';
|
|
38
|
+
readonly reviewDecision: 'approved' | 'changes-requested' | 'review-required' | 'none';
|
|
39
|
+
readonly updatedAt: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ForgeViewerListLike {
|
|
42
|
+
readonly viewer: string;
|
|
43
|
+
readonly items: readonly ForgeViewerSummaryLike[];
|
|
44
|
+
readonly total: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ForgeReadinessLike {
|
|
47
|
+
readonly state: 'ready' | 'unauthenticated' | 'unavailable';
|
|
48
|
+
readonly message: string | null;
|
|
49
|
+
readonly signIn?: {
|
|
50
|
+
readonly command: string;
|
|
51
|
+
} | null;
|
|
52
|
+
}
|
|
53
|
+
/** Minimal duck-typed contract matching `@deepseek-ai/dsh-experimental-forge` `ForgeService`. */
|
|
54
|
+
export interface ForgeServiceLike {
|
|
55
|
+
repositoryFromRemote(url: string): ForgeRepositoryLike | undefined;
|
|
56
|
+
changeRequestFromUrl(url: string): ChangeRequestRefLike | undefined;
|
|
57
|
+
changeRequestUrl(ref: ChangeRequestRefLike): string;
|
|
58
|
+
readiness(repository: ForgeRepositoryLike, signal: AbortSignal): Promise<ForgeReadinessLike>;
|
|
59
|
+
viewerSources?(): readonly {
|
|
60
|
+
readonly forge: string;
|
|
61
|
+
readonly hosts: readonly string[];
|
|
62
|
+
readonly filters: ReadonlySet<string>;
|
|
63
|
+
readonly maxItems: number;
|
|
64
|
+
}[];
|
|
65
|
+
listForViewer?(forge: string, query: {
|
|
66
|
+
readonly host: string;
|
|
67
|
+
readonly filter: 'review-requested' | 'authored' | 'involved';
|
|
68
|
+
readonly repository: {
|
|
69
|
+
readonly owner: string;
|
|
70
|
+
readonly name: string;
|
|
71
|
+
} | null;
|
|
72
|
+
readonly limit: number;
|
|
73
|
+
}, signal: AbortSignal): Promise<ForgeViewerListLike | {
|
|
74
|
+
readonly code: string;
|
|
75
|
+
readonly message: string;
|
|
76
|
+
}>;
|
|
77
|
+
latest?(ref: ChangeRequestRefLike): {
|
|
78
|
+
readonly snapshot?: ChangeRequestSnapshotLike;
|
|
79
|
+
} | undefined;
|
|
80
|
+
fetchChecks?(ref: ChangeRequestRefLike, signal: AbortSignal): Promise<ChangeRequestSnapshotLike | {
|
|
81
|
+
readonly code: string;
|
|
82
|
+
readonly message: string;
|
|
83
|
+
}>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Opportunistically fetch PR/MR metadata (title, author, state, draft, branches) from optional
|
|
87
|
+
* `ctx.forge` when not already cached in `forge.latest`. Failures and timeouts degrade silently
|
|
88
|
+
* to `undefined` so native Git checkout previews are never blocked.
|
|
89
|
+
*/
|
|
90
|
+
export declare function fetchPrMeta(forge: ForgeServiceLike | undefined, remote: PrRemoteInfo | undefined, provider: PrProviderKind, number: number, signal?: AbortSignal): Promise<PrResolveResult['meta'] | undefined>;
|
|
91
|
+
/** Runtime guard for optional `ctx.forge` service injection. */
|
|
92
|
+
export declare function isForgeServiceLike(value: unknown): value is ForgeServiceLike;
|
|
93
|
+
/** Parsed PR/MR user input (numeric ID or full web URL). */
|
|
94
|
+
export type ParsedPrInput = {
|
|
95
|
+
readonly kind: 'number';
|
|
96
|
+
readonly number: number;
|
|
97
|
+
readonly hintProvider?: PrProviderKind;
|
|
98
|
+
} | {
|
|
99
|
+
readonly kind: 'url';
|
|
100
|
+
readonly provider: PrProviderKind;
|
|
101
|
+
readonly host: string;
|
|
102
|
+
readonly owner: string;
|
|
103
|
+
readonly repo: string;
|
|
104
|
+
readonly number: number;
|
|
105
|
+
readonly canonicalUrl: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Parse a Git remote fetch URL (`https://`, `http://`, `ssh://`, `git://`, or `git@host:owner/repo.git`)
|
|
109
|
+
* into normalized host, owner/namespace, repository name, and heuristic provider kind.
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseRemoteUrl(url: string): {
|
|
112
|
+
host: string;
|
|
113
|
+
owner: string;
|
|
114
|
+
repo: string;
|
|
115
|
+
provider: PrProviderKind | null;
|
|
116
|
+
} | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Parse user input into a numeric PR/MR number (`42`, `#42`, `!42`) or a GitHub/GitLab web URL.
|
|
119
|
+
* Supports self-hosted instances, nested GitLab namespaces, and trailing URL paths (`/files`, `/commits`, query, hash).
|
|
120
|
+
*/
|
|
121
|
+
export declare function parsePrInput(input: string): ParsedPrInput | undefined;
|
|
122
|
+
/** Canonical local branch name with provider prefix to avoid multi-host collisions. */
|
|
123
|
+
export declare function formatPrBranchName(provider: PrProviderKind, number: number): string;
|
|
124
|
+
/**
|
|
125
|
+
* Concise PR/MR origin label stored in `<worktreeGitDir>/dsh-worktree-base` for
|
|
126
|
+
* sidebar hover cards (e.g. `PR #42`, `PR #42 → main`, `MR !17 → develop`).
|
|
127
|
+
*/
|
|
128
|
+
export declare function formatPrBaseLabel(provider: PrProviderKind, number: number, baseBranch?: string): string;
|
|
129
|
+
/** Git refspec fetched into a temporary ref (`refs/dsh-pr-tmp/<uuid>`) for a given provider and PR/MR number. */
|
|
130
|
+
export declare function prRefSpec(provider: PrProviderKind, number: number): string;
|
|
131
|
+
/** Build the canonical web URL for a PR/MR on a known remote, using `forge` when available. */
|
|
132
|
+
export declare function buildCanonicalPrUrl(remote: PrRemoteInfo, provider: PrProviderKind, number: number, forge?: ForgeServiceLike): string | null;
|
|
133
|
+
/** Classify repository remotes using optional `ctx.forge` first, falling back to built-in URL parsing. */
|
|
134
|
+
export declare function classifyRemotes(remotes: readonly {
|
|
135
|
+
name: string;
|
|
136
|
+
url: string;
|
|
137
|
+
}[], forge?: ForgeServiceLike): PrRemoteInfo[];
|
|
138
|
+
/** Choose default remote: recognized `upstream` > `origin` > first recognized remote > first remote. */
|
|
139
|
+
export declare function pickDefaultRemote(remotes: readonly PrRemoteInfo[]): string | null;
|
|
140
|
+
/** Error thrown when PR input is invalid or does not belong to the repository. */
|
|
141
|
+
export declare class PrResolutionError extends Error {
|
|
142
|
+
readonly code: PrErrorCode;
|
|
143
|
+
readonly params: Record<string, string | number> | undefined;
|
|
144
|
+
constructor(message: string, code: PrErrorCode, params?: Record<string, string | number>);
|
|
145
|
+
}
|
|
146
|
+
export interface ResolvePrTargetInput {
|
|
147
|
+
repoRoot: string;
|
|
148
|
+
input: string;
|
|
149
|
+
remotes: readonly PrRemoteInfo[];
|
|
150
|
+
worktrees: readonly WorktreeEntry[];
|
|
151
|
+
localBranches: readonly string[];
|
|
152
|
+
requestedRemote?: string;
|
|
153
|
+
requestedProvider?: PrProviderKind;
|
|
154
|
+
forge?: ForgeServiceLike;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve a PR/MR ID or URL against the repository's remotes, verifying repository ownership
|
|
158
|
+
* and reporting any existing isolated worktree or local branch collision.
|
|
159
|
+
*/
|
|
160
|
+
export declare function resolvePrTarget(args: ResolvePrTargetInput): PrResolveResult;
|
|
161
|
+
/**
|
|
162
|
+
* Assemble `/pr-context` payload: classified remotes + optional `ctx.forge` readiness &
|
|
163
|
+
* open PR/MR candidate lists scoped to the repository (or an explicitly selected remote).
|
|
164
|
+
* Failures or unauthenticated states degrade cleanly to `candidates: []` without blocking native Git checkout.
|
|
165
|
+
*/
|
|
166
|
+
export declare function loadPrContext(args: {
|
|
167
|
+
repoRoot: string;
|
|
168
|
+
repoName: string;
|
|
169
|
+
rawRemotes: readonly {
|
|
170
|
+
name: string;
|
|
171
|
+
url: string;
|
|
172
|
+
}[];
|
|
173
|
+
worktrees: readonly WorktreeEntry[];
|
|
174
|
+
requestedRemote?: string;
|
|
175
|
+
forge?: ForgeServiceLike;
|
|
176
|
+
signal?: AbortSignal;
|
|
177
|
+
}): Promise<PrContextResult>;
|