@cerbur/clutch-dsh-worktree 0.1.3 → 0.1.5
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 +261 -107
- package/README.zh.md +309 -0
- package/lib/client/WorktreeContext.d.ts.map +1 -1
- package/lib/client/WorktreeContext.js.map +1 -1
- package/lib/client/WorktreeHeroContext.d.ts.map +1 -1
- package/lib/client/WorktreeHeroContext.js +9 -4
- package/lib/client/WorktreeHeroContext.js.map +1 -1
- package/lib/client/WorktreeSurface.d.ts +2 -30
- package/lib/client/WorktreeSurface.d.ts.map +1 -1
- package/lib/client/WorktreeSurface.js +31 -320
- package/lib/client/WorktreeSurface.js.map +1 -1
- package/lib/client/locales.d.ts +4 -0
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +4 -0
- package/lib/client/locales.js.map +1 -1
- package/lib/client/worktree-context-store.d.ts.map +1 -1
- package/lib/client/worktree-context-store.js +51 -11
- package/lib/client/worktree-context-store.js.map +1 -1
- package/lib/client/worktree-error-copy.d.ts.map +1 -1
- package/lib/client/worktree-error-copy.js +2 -0
- package/lib/client/worktree-error-copy.js.map +1 -1
- package/lib/client/worktree-surface-dialogs.d.ts +7 -0
- package/lib/client/worktree-surface-dialogs.d.ts.map +1 -0
- package/lib/client/worktree-surface-dialogs.js +89 -0
- package/lib/client/worktree-surface-dialogs.js.map +1 -0
- package/lib/client/worktree-surface-rows.d.ts +9 -0
- package/lib/client/worktree-surface-rows.d.ts.map +1 -0
- package/lib/client/worktree-surface-rows.js +223 -0
- package/lib/client/worktree-surface-rows.js.map +1 -0
- package/lib/client/worktree-surface-selectors.d.ts +9 -0
- package/lib/client/worktree-surface-selectors.d.ts.map +1 -0
- package/lib/client/worktree-surface-selectors.js +28 -0
- package/lib/client/worktree-surface-selectors.js.map +1 -0
- package/lib/client/worktree-surface-types.d.ts +233 -0
- package/lib/client/worktree-surface-types.d.ts.map +1 -0
- package/lib/client/worktree-surface-types.js +2 -0
- package/lib/client/worktree-surface-types.js.map +1 -0
- package/lib/client/worktree-view-actions.d.ts +34 -0
- package/lib/client/worktree-view-actions.d.ts.map +1 -0
- package/lib/client/worktree-view-actions.js +69 -0
- package/lib/client/worktree-view-actions.js.map +1 -0
- package/lib/client/worktree-view-errors.d.ts +20 -0
- package/lib/client/worktree-view-errors.d.ts.map +1 -0
- package/lib/client/worktree-view-errors.js +65 -0
- package/lib/client/worktree-view-errors.js.map +1 -0
- package/lib/client/worktree-view-read.d.ts +51 -0
- package/lib/client/worktree-view-read.d.ts.map +1 -0
- package/lib/client/worktree-view-read.js +139 -0
- package/lib/client/worktree-view-read.js.map +1 -0
- package/lib/client/worktree-view.d.ts +4 -97
- package/lib/client/worktree-view.d.ts.map +1 -1
- package/lib/client/worktree-view.js +4 -263
- package/lib/client/worktree-view.js.map +1 -1
- package/lib/client.js +490 -361
- package/lib/client.js.map +1 -1
- package/lib/contract/index.d.ts +1 -1
- package/lib/contract/index.d.ts.map +1 -1
- package/lib/contract/index.js +1 -0
- package/lib/contract/index.js.map +1 -1
- package/lib/manage/manager-context.d.ts +11 -0
- package/lib/manage/manager-context.d.ts.map +1 -0
- package/lib/manage/manager-context.js +2 -0
- package/lib/manage/manager-context.js.map +1 -0
- package/lib/manage/manager-sessions.d.ts +18 -0
- package/lib/manage/manager-sessions.d.ts.map +1 -0
- package/lib/manage/manager-sessions.js +91 -0
- package/lib/manage/manager-sessions.js.map +1 -0
- package/lib/manage/manager-support.d.ts +18 -0
- package/lib/manage/manager-support.d.ts.map +1 -0
- package/lib/manage/manager-support.js +174 -0
- package/lib/manage/manager-support.js.map +1 -0
- package/lib/manage/manager-worktrees.d.ts +27 -0
- package/lib/manage/manager-worktrees.d.ts.map +1 -0
- package/lib/manage/manager-worktrees.js +259 -0
- package/lib/manage/manager-worktrees.js.map +1 -0
- package/lib/manage/manager.d.ts +23 -65
- package/lib/manage/manager.d.ts.map +1 -1
- package/lib/manage/manager.js +32 -565
- package/lib/manage/manager.js.map +1 -1
- package/lib/provider/git.d.ts +6 -0
- package/lib/provider/git.d.ts.map +1 -1
- package/lib/provider/git.js +34 -10
- package/lib/provider/git.js.map +1 -1
- package/lib/provider/sidecar-persistence.d.ts +18 -0
- package/lib/provider/sidecar-persistence.d.ts.map +1 -0
- package/lib/provider/sidecar-persistence.js +162 -0
- package/lib/provider/sidecar-persistence.js.map +1 -0
- package/lib/provider/sidecar-schema.d.ts +6 -0
- package/lib/provider/sidecar-schema.d.ts.map +1 -0
- package/lib/provider/sidecar-schema.js +123 -0
- package/lib/provider/sidecar-schema.js.map +1 -0
- package/lib/provider/sidecar.d.ts +10 -67
- package/lib/provider/sidecar.d.ts.map +1 -1
- package/lib/provider/sidecar.js +21 -346
- package/lib/provider/sidecar.js.map +1 -1
- package/lib/typert.host.js +7 -7
- package/lib/typert.remote-client.js +7 -7
- package/package.json +1 -1
|
@@ -1,264 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
details;
|
|
6
|
-
sessionId;
|
|
7
|
-
cause;
|
|
8
|
-
constructor(sessionId, cause) {
|
|
9
|
-
const candidate = typeof cause === 'object' && cause !== null
|
|
10
|
-
? cause
|
|
11
|
-
: undefined;
|
|
12
|
-
const reason = cause instanceof Error
|
|
13
|
-
? cause.message
|
|
14
|
-
: typeof candidate?.message === 'string'
|
|
15
|
-
? candidate.message
|
|
16
|
-
: String(cause);
|
|
17
|
-
super(reason);
|
|
18
|
-
this.name = 'WorktreeSessionBindingError';
|
|
19
|
-
const conflict = candidate?.code === 'SESSION_ALREADY_BOUND';
|
|
20
|
-
this.code = conflict ? 'SESSION_ALREADY_BOUND' : 'SESSION_BINDING_FAILED';
|
|
21
|
-
this.retryable = conflict ? false : candidate?.retryable !== false;
|
|
22
|
-
this.details = typeof candidate?.details === 'object' && candidate.details !== null
|
|
23
|
-
&& !Array.isArray(candidate.details)
|
|
24
|
-
? candidate.details
|
|
25
|
-
: {};
|
|
26
|
-
this.sessionId = sessionId;
|
|
27
|
-
this.cause = cause;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** Reuse the previous ID snapshot when DSH republishes equivalent Workspace items. */
|
|
31
|
-
export function stableWorkspaceIds(previous, next) {
|
|
32
|
-
if (previous.length !== next.length)
|
|
33
|
-
return next;
|
|
34
|
-
for (let index = 0; index < previous.length; index += 1) {
|
|
35
|
-
if (previous[index] !== next[index])
|
|
36
|
-
return next;
|
|
37
|
-
}
|
|
38
|
-
return previous;
|
|
39
|
-
}
|
|
40
|
-
/** Keep only the most recently started Worktree surface refresh authoritative. */
|
|
41
|
-
export function createWorktreeRefreshGuard() {
|
|
42
|
-
let latestGeneration = 0;
|
|
43
|
-
const begin = () => {
|
|
44
|
-
latestGeneration += 1;
|
|
45
|
-
return latestGeneration;
|
|
46
|
-
};
|
|
47
|
-
const isCurrent = (generation) => generation === latestGeneration;
|
|
48
|
-
const invalidate = () => {
|
|
49
|
-
latestGeneration += 1;
|
|
50
|
-
};
|
|
51
|
-
return {
|
|
52
|
-
begin,
|
|
53
|
-
isCurrent,
|
|
54
|
-
invalidate,
|
|
55
|
-
async run(load, onSuccess, onError) {
|
|
56
|
-
const generation = begin();
|
|
57
|
-
let value;
|
|
58
|
-
try {
|
|
59
|
-
value = await load();
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
if (!isCurrent(generation))
|
|
63
|
-
return;
|
|
64
|
-
onError(error);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!isCurrent(generation))
|
|
68
|
-
return;
|
|
69
|
-
onSuccess(value);
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/** Prefer the branch checked out by the DSH Workspace, then fall back to any local branch. */
|
|
74
|
-
export function selectDefaultBaseBranch(branches) {
|
|
75
|
-
return branches.find((branch) => branch.isCurrent)?.name ?? branches[0]?.name ?? '';
|
|
76
|
-
}
|
|
77
|
-
/** Keep a valid user choice across branch-list refreshes, otherwise choose the current branch. */
|
|
78
|
-
export function reconcileBaseBranchSelection(selectedBranch, branches) {
|
|
79
|
-
if (branches.some((branch) => branch.name === selectedBranch))
|
|
80
|
-
return selectedBranch;
|
|
81
|
-
return selectDefaultBaseBranch(branches);
|
|
82
|
-
}
|
|
83
|
-
/** Return copyable, read-only setup commands for a Git readiness state. */
|
|
84
|
-
export function worktreeSetupCommands(status) {
|
|
85
|
-
switch (status) {
|
|
86
|
-
case 'noRepository':
|
|
87
|
-
return [
|
|
88
|
-
'git init',
|
|
89
|
-
'printf "# README\\n" > README.md',
|
|
90
|
-
'git add README.md',
|
|
91
|
-
'git commit -m "Initial commit"',
|
|
92
|
-
];
|
|
93
|
-
case 'noInitialCommit':
|
|
94
|
-
return [
|
|
95
|
-
'printf "# README\\n" > README.md',
|
|
96
|
-
'git add README.md',
|
|
97
|
-
'git commit -m "Initial commit"',
|
|
98
|
-
];
|
|
99
|
-
case 'noLocalBranch':
|
|
100
|
-
return ['git switch -c main'];
|
|
101
|
-
case 'ready':
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function browserRandomUuid() {
|
|
106
|
-
const randomUUID = globalThis.crypto?.randomUUID;
|
|
107
|
-
if (typeof randomUUID === 'function')
|
|
108
|
-
return randomUUID.call(globalThis.crypto);
|
|
109
|
-
return `${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`;
|
|
110
|
-
}
|
|
111
|
-
/** Generate a short, editable default branch name without colliding with known local names. */
|
|
112
|
-
export function createDefaultWorktreeName(existingNames, randomUuid = browserRandomUuid) {
|
|
113
|
-
const usedNames = new Set([...existingNames].map((name) => name.trim()));
|
|
114
|
-
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
115
|
-
const suffix = randomUuid().replace(/[^a-z0-9]/gi, '').slice(0, 8).toLowerCase();
|
|
116
|
-
if (suffix.length < 8)
|
|
117
|
-
continue;
|
|
118
|
-
const candidate = `dsh/${suffix}`;
|
|
119
|
-
if (!usedNames.has(candidate))
|
|
120
|
-
return candidate;
|
|
121
|
-
}
|
|
122
|
-
throw new Error('Unable to generate an available default Worktree name.');
|
|
123
|
-
}
|
|
124
|
-
/** Hide DSH-archived Sessions from the browser-local Worktree projection. */
|
|
125
|
-
export function filterArchivedSessionIds(sessionIds, archivedSessionIds) {
|
|
126
|
-
return sessionIds.filter((sessionId) => !archivedSessionIds.includes(sessionId));
|
|
127
|
-
}
|
|
128
|
-
function readinessFromBranchError(error) {
|
|
129
|
-
const viewError = toWorktreeViewError(error);
|
|
130
|
-
if (viewError.code === 'WORKSPACE_NOT_GIT_REPOSITORY') {
|
|
131
|
-
return { status: 'noRepository', error: viewError };
|
|
132
|
-
}
|
|
133
|
-
if (viewError.code === 'WORKTREE_REQUIRES_INITIAL_COMMIT') {
|
|
134
|
-
return { status: 'noInitialCommit', error: viewError };
|
|
135
|
-
}
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
/** Read all three Worktree projections needed by the surface in one refresh. */
|
|
139
|
-
export async function loadWorktreeView(manager, workspaceId) {
|
|
140
|
-
const [worktreesResult, branchesResult, bindingsResult] = await Promise.allSettled([
|
|
141
|
-
manager.listWorktrees({ workspaceId }),
|
|
142
|
-
manager.listBranches({ workspaceId }),
|
|
143
|
-
manager.listBindings({ workspaceId }),
|
|
144
|
-
]);
|
|
145
|
-
if (worktreesResult.status === 'rejected')
|
|
146
|
-
throw worktreesResult.reason;
|
|
147
|
-
if (bindingsResult.status === 'rejected')
|
|
148
|
-
throw bindingsResult.reason;
|
|
149
|
-
if (branchesResult.status === 'rejected') {
|
|
150
|
-
const readiness = readinessFromBranchError(branchesResult.reason);
|
|
151
|
-
if (readiness !== undefined) {
|
|
152
|
-
return {
|
|
153
|
-
worktrees: worktreesResult.value,
|
|
154
|
-
branches: [],
|
|
155
|
-
bindings: bindingsResult.value,
|
|
156
|
-
readiness,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
throw branchesResult.reason;
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
worktrees: worktreesResult.value,
|
|
163
|
-
branches: branchesResult.value,
|
|
164
|
-
bindings: bindingsResult.value,
|
|
165
|
-
readiness: branchesResult.value.length > 0
|
|
166
|
-
? { status: 'ready' }
|
|
167
|
-
: { status: 'noLocalBranch' },
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/** Load one independent projection per DSH Workspace for the flat sidebar hierarchy. */
|
|
171
|
-
export async function loadWorktreeViews(manager, workspaceIds, options = {}) {
|
|
172
|
-
const views = await Promise.all(workspaceIds.map(async (workspaceId) => ({
|
|
173
|
-
workspaceId,
|
|
174
|
-
...(await loadWorktreeView(manager, workspaceId)),
|
|
175
|
-
})));
|
|
176
|
-
if (options.invalidateContext !== false) {
|
|
177
|
-
await options.invalidateWorktreeContext?.();
|
|
178
|
-
}
|
|
179
|
-
return views;
|
|
180
|
-
}
|
|
181
|
-
/** Resolve a row-half drop target to native-style optional before-anchor semantics. */
|
|
182
|
-
export function resolveWorktreeMove(worktreeIds, sourceWorktreeId, targetWorktreeId, half) {
|
|
183
|
-
const sourceIndex = worktreeIds.indexOf(sourceWorktreeId);
|
|
184
|
-
const targetIndex = worktreeIds.indexOf(targetWorktreeId);
|
|
185
|
-
if (sourceIndex === -1 || targetIndex === -1)
|
|
186
|
-
return undefined;
|
|
187
|
-
const beforeWorktreeId = half === 'before'
|
|
188
|
-
? targetWorktreeId
|
|
189
|
-
: worktreeIds[targetIndex + 1];
|
|
190
|
-
if (beforeWorktreeId === sourceWorktreeId)
|
|
191
|
-
return undefined;
|
|
192
|
-
const anchorIndex = beforeWorktreeId === undefined
|
|
193
|
-
? worktreeIds.length
|
|
194
|
-
: worktreeIds.indexOf(beforeWorktreeId);
|
|
195
|
-
if (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1)
|
|
196
|
-
return undefined;
|
|
197
|
-
return beforeWorktreeId === undefined ? {} : { beforeWorktreeId };
|
|
198
|
-
}
|
|
199
|
-
/** Keep mutation routing in the browser Consumer while leaving wire details to the adapter. */
|
|
200
|
-
export async function executeWorktreeAction(manager, action) {
|
|
201
|
-
if (action.type === 'createWorktree') {
|
|
202
|
-
return manager.createWorktree(action.input);
|
|
203
|
-
}
|
|
204
|
-
if (action.type === 'removeWorktree') {
|
|
205
|
-
await manager.removeWorktree(action.input);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Create a normal DSH Session at a Worktree cwd, then add the external binding.
|
|
211
|
-
* A binding failure deliberately leaves the DSH-created Session intact.
|
|
212
|
-
*/
|
|
213
|
-
export async function createSessionForWorktree(input) {
|
|
214
|
-
const sessionId = await input.createSession({ cwd: input.cwd });
|
|
215
|
-
try {
|
|
216
|
-
await input.manager.bindSession({
|
|
217
|
-
workspaceId: input.workspaceId,
|
|
218
|
-
worktreeId: input.worktreeId,
|
|
219
|
-
sessionId,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
throw new WorktreeSessionBindingError(sessionId, error);
|
|
224
|
-
}
|
|
225
|
-
input.beforeOpen?.(sessionId);
|
|
226
|
-
input.openSession(sessionId);
|
|
227
|
-
return sessionId;
|
|
228
|
-
}
|
|
229
|
-
function recordDetails(value) {
|
|
230
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
231
|
-
return undefined;
|
|
232
|
-
const details = value.details;
|
|
233
|
-
if (typeof details !== 'object' || details === null || Array.isArray(details))
|
|
234
|
-
return undefined;
|
|
235
|
-
return details;
|
|
236
|
-
}
|
|
237
|
-
/** Convert any adapter/Gateway failure into renderable, retry-aware UI data. */
|
|
238
|
-
export function toWorktreeViewError(error) {
|
|
239
|
-
if (typeof error === 'object' && error !== null) {
|
|
240
|
-
const candidate = error;
|
|
241
|
-
const details = error instanceof WorktreeSessionBindingError
|
|
242
|
-
? { ...(recordDetails(error) ?? {}), sessionId: error.sessionId }
|
|
243
|
-
: recordDetails(error);
|
|
244
|
-
return {
|
|
245
|
-
code: typeof candidate.code === 'string' ? candidate.code : 'WORKTREE_VIEW_FAILED',
|
|
246
|
-
message: typeof candidate.message === 'string' ? candidate.message : '',
|
|
247
|
-
retryable: candidate.retryable !== false,
|
|
248
|
-
...(details === undefined ? {} : { details }),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
code: 'WORKTREE_VIEW_FAILED',
|
|
253
|
-
message: '',
|
|
254
|
-
retryable: true,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
/** Keep ordering mutation/refresh failures reachable from the surface Retry control. */
|
|
258
|
-
export function toRetryableWorktreeOrderError(error) {
|
|
259
|
-
return {
|
|
260
|
-
...toWorktreeViewError(error),
|
|
261
|
-
retryable: true,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
1
|
+
/** Compatibility barrel for the existing browser Worktree view helper imports. */
|
|
2
|
+
export * from './worktree-view-actions.js';
|
|
3
|
+
export * from './worktree-view-errors.js';
|
|
4
|
+
export * from './worktree-view-read.js';
|
|
264
5
|
//# sourceMappingURL=worktree-view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worktree-view.js","sourceRoot":"","sources":["../../src/client/worktree-view.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worktree-view.js","sourceRoot":"","sources":["../../src/client/worktree-view.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC"}
|