dsh-git-desk 0.18.1 → 0.19.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.
- package/README.md +11 -0
- package/client.js +5 -4847
- package/dist/contract.js +5 -0
- package/{index.js → dist/host/index.js} +4 -5
- package/dist/host/lib/ai.js +266 -0
- package/dist/host/lib/exec.js +193 -0
- package/dist/host/lib/git.js +1317 -0
- package/dist/host/lib/http.js +168 -0
- package/dist/host/lib/parse.js +381 -0
- package/dist/host/lib/rpc.js +316 -0
- package/dist/host/lib/types.js +1 -0
- package/package.json +18 -4
- package/lib/ai.js +0 -187
- package/lib/exec.js +0 -168
- package/lib/git.js +0 -1037
- package/lib/http.js +0 -139
- package/lib/parse.js +0 -319
- package/lib/rpc.js +0 -266
package/lib/rpc.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { preferences, writeCommitMessage } from './ai.js';
|
|
2
|
-
import { GitError } from './exec.js';
|
|
3
|
-
import {
|
|
4
|
-
applyBlocks,
|
|
5
|
-
branches,
|
|
6
|
-
checkout,
|
|
7
|
-
cherryPickCommit,
|
|
8
|
-
commit,
|
|
9
|
-
commitDetail,
|
|
10
|
-
createBranch,
|
|
11
|
-
createBranchAndCommit,
|
|
12
|
-
discoverRepositories,
|
|
13
|
-
diff,
|
|
14
|
-
fetch,
|
|
15
|
-
findRepository,
|
|
16
|
-
initRepository,
|
|
17
|
-
log,
|
|
18
|
-
pull,
|
|
19
|
-
push,
|
|
20
|
-
recentSubjects,
|
|
21
|
-
resetToCommit,
|
|
22
|
-
resolveConflict,
|
|
23
|
-
resolveRepository,
|
|
24
|
-
revertCommit,
|
|
25
|
-
stagePaths,
|
|
26
|
-
stagedPatch,
|
|
27
|
-
stashApply,
|
|
28
|
-
stashDrop,
|
|
29
|
-
stashList,
|
|
30
|
-
stashPush,
|
|
31
|
-
status,
|
|
32
|
-
undoCommit,
|
|
33
|
-
unstagePaths,
|
|
34
|
-
} from './git.js';
|
|
35
|
-
|
|
36
|
-
function workspaceOf(ctx, payload) {
|
|
37
|
-
const id = payload !== null && typeof payload === 'object' ? payload.workspaceId : undefined;
|
|
38
|
-
if (typeof id !== 'string' || id === '') {
|
|
39
|
-
throw new GitError('git/no-workspace', 'Choose a workspace first.');
|
|
40
|
-
}
|
|
41
|
-
const workspace = ctx.workspaceRegistry.get(id);
|
|
42
|
-
if (workspace === undefined) {
|
|
43
|
-
throw new GitError('git/no-workspace', 'That workspace is no longer registered.');
|
|
44
|
-
}
|
|
45
|
-
return workspace;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function repoOf(runtime, workspace, payload) {
|
|
49
|
-
const requested = valueOf(payload, 'repo');
|
|
50
|
-
if (typeof requested === 'string' && requested !== '') {
|
|
51
|
-
return resolveRepository(runtime, workspace.path, requested);
|
|
52
|
-
}
|
|
53
|
-
const root = await findRepository(runtime, workspace.path);
|
|
54
|
-
if (root === null) {
|
|
55
|
-
throw new GitError('git/not-repo', 'This workspace is not a Git repository.', {
|
|
56
|
-
path: workspace.path,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return root;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function workspaceInfo(workspace) {
|
|
63
|
-
return { id: workspace.id, title: workspace.title, path: workspace.path };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function valueOf(payload, key) {
|
|
67
|
-
return payload !== null && typeof payload === 'object' ? payload[key] : undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function dispatch(ctx, runtime, endpoint, payload) {
|
|
71
|
-
if (endpoint === 'preferences') return preferences(ctx);
|
|
72
|
-
const workspace = workspaceOf(ctx, payload);
|
|
73
|
-
if (endpoint === 'status' || endpoint === 'init') {
|
|
74
|
-
if (endpoint === 'init') {
|
|
75
|
-
const snapshot = await initRepository(runtime, workspace.path);
|
|
76
|
-
return {
|
|
77
|
-
...snapshot,
|
|
78
|
-
repos: await discoverRepositories(runtime, workspace.path),
|
|
79
|
-
selected: snapshot.root,
|
|
80
|
-
workspace: workspaceInfo(workspace),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const requested = valueOf(payload, 'repo');
|
|
84
|
-
if (typeof requested === 'string' && requested !== '') {
|
|
85
|
-
const root = await resolveRepository(runtime, workspace.path, requested);
|
|
86
|
-
const snapshot = await status(runtime, root);
|
|
87
|
-
return {
|
|
88
|
-
...snapshot,
|
|
89
|
-
selected: root,
|
|
90
|
-
workspace: workspaceInfo(workspace),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const repos = await discoverRepositories(runtime, workspace.path);
|
|
94
|
-
const workspaceRepo = await findRepository(runtime, workspace.path);
|
|
95
|
-
if (workspaceRepo !== null) {
|
|
96
|
-
const snapshot = await status(runtime, workspaceRepo);
|
|
97
|
-
return {
|
|
98
|
-
...snapshot,
|
|
99
|
-
repos,
|
|
100
|
-
selected: workspaceRepo,
|
|
101
|
-
workspace: workspaceInfo(workspace),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
repo: false,
|
|
106
|
-
root: null,
|
|
107
|
-
branch: {
|
|
108
|
-
oid: null,
|
|
109
|
-
name: null,
|
|
110
|
-
upstream: null,
|
|
111
|
-
ahead: 0,
|
|
112
|
-
behind: 0,
|
|
113
|
-
detached: false,
|
|
114
|
-
initial: true,
|
|
115
|
-
},
|
|
116
|
-
entries: [],
|
|
117
|
-
merging: false,
|
|
118
|
-
rebasing: false,
|
|
119
|
-
conflicts: [],
|
|
120
|
-
repos,
|
|
121
|
-
selected: null,
|
|
122
|
-
workspace: workspaceInfo(workspace),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const root = await repoOf(runtime, workspace, payload);
|
|
127
|
-
|
|
128
|
-
switch (endpoint) {
|
|
129
|
-
case 'diff':
|
|
130
|
-
return diff(runtime, root, {
|
|
131
|
-
path: valueOf(payload, 'path'),
|
|
132
|
-
side: valueOf(payload, 'side'),
|
|
133
|
-
commit: valueOf(payload, 'commit'),
|
|
134
|
-
parent: valueOf(payload, 'parent'),
|
|
135
|
-
});
|
|
136
|
-
case 'stage':
|
|
137
|
-
return stagePaths(runtime, root, Array.isArray(valueOf(payload, 'paths')) ? valueOf(payload, 'paths') : []);
|
|
138
|
-
case 'unstage':
|
|
139
|
-
return unstagePaths(runtime, root, Array.isArray(valueOf(payload, 'paths')) ? valueOf(payload, 'paths') : []);
|
|
140
|
-
case 'applyBlocks':
|
|
141
|
-
return applyBlocks(runtime, root, {
|
|
142
|
-
path: valueOf(payload, 'path'),
|
|
143
|
-
side: valueOf(payload, 'side'),
|
|
144
|
-
blocks: valueOf(payload, 'blocks'),
|
|
145
|
-
baseHash: valueOf(payload, 'baseHash'),
|
|
146
|
-
targetHash: valueOf(payload, 'targetHash'),
|
|
147
|
-
confirm: valueOf(payload, 'confirm'),
|
|
148
|
-
});
|
|
149
|
-
case 'commit':
|
|
150
|
-
return commit(runtime, root, {
|
|
151
|
-
message: valueOf(payload, 'message'),
|
|
152
|
-
amend: valueOf(payload, 'amend') === true,
|
|
153
|
-
});
|
|
154
|
-
case 'createBranchAndCommit':
|
|
155
|
-
return createBranchAndCommit(runtime, root, {
|
|
156
|
-
name: valueOf(payload, 'name'),
|
|
157
|
-
message: valueOf(payload, 'message'),
|
|
158
|
-
});
|
|
159
|
-
case 'push':
|
|
160
|
-
return push(runtime, root);
|
|
161
|
-
case 'pull':
|
|
162
|
-
return pull(runtime, root);
|
|
163
|
-
case 'fetch':
|
|
164
|
-
return fetch(runtime, root);
|
|
165
|
-
case 'log':
|
|
166
|
-
return log(runtime, root);
|
|
167
|
-
case 'commitDetail':
|
|
168
|
-
return commitDetail(runtime, root, { hash: valueOf(payload, 'hash') });
|
|
169
|
-
case 'undoCommit':
|
|
170
|
-
return undoCommit(runtime, root, { hash: valueOf(payload, 'hash') });
|
|
171
|
-
case 'revertCommit':
|
|
172
|
-
return revertCommit(runtime, root, { hash: valueOf(payload, 'hash') });
|
|
173
|
-
case 'cherryPickCommit':
|
|
174
|
-
return cherryPickCommit(runtime, root, { hash: valueOf(payload, 'hash') });
|
|
175
|
-
case 'resetToCommit':
|
|
176
|
-
return resetToCommit(runtime, root, {
|
|
177
|
-
hash: valueOf(payload, 'hash'),
|
|
178
|
-
mode: valueOf(payload, 'mode'),
|
|
179
|
-
confirm: valueOf(payload, 'confirm') === true,
|
|
180
|
-
});
|
|
181
|
-
case 'branches':
|
|
182
|
-
return branches(runtime, root);
|
|
183
|
-
case 'createBranch':
|
|
184
|
-
return createBranch(runtime, root, { name: valueOf(payload, 'name') });
|
|
185
|
-
case 'checkout':
|
|
186
|
-
return checkout(runtime, root, {
|
|
187
|
-
branch: valueOf(payload, 'branch'),
|
|
188
|
-
remote: valueOf(payload, 'remote') === true,
|
|
189
|
-
});
|
|
190
|
-
case 'stashList':
|
|
191
|
-
return stashList(runtime, root);
|
|
192
|
-
case 'stashPush':
|
|
193
|
-
return stashPush(runtime, root, {
|
|
194
|
-
message: valueOf(payload, 'message'),
|
|
195
|
-
paths: Array.isArray(valueOf(payload, 'paths')) ? valueOf(payload, 'paths') : [],
|
|
196
|
-
includeUntracked: valueOf(payload, 'includeUntracked') === true,
|
|
197
|
-
});
|
|
198
|
-
case 'stashApply':
|
|
199
|
-
return stashApply(runtime, root, {
|
|
200
|
-
ref: valueOf(payload, 'ref'),
|
|
201
|
-
pop: valueOf(payload, 'pop') === true,
|
|
202
|
-
});
|
|
203
|
-
case 'stashDrop':
|
|
204
|
-
return stashDrop(runtime, root, { ref: valueOf(payload, 'ref') });
|
|
205
|
-
case 'resolve':
|
|
206
|
-
return resolveConflict(runtime, root, {
|
|
207
|
-
path: valueOf(payload, 'path'),
|
|
208
|
-
side: valueOf(payload, 'side'),
|
|
209
|
-
});
|
|
210
|
-
case 'aiMessage': {
|
|
211
|
-
const patch = await stagedPatch(runtime, root);
|
|
212
|
-
if (patch.trim() === '') {
|
|
213
|
-
throw new GitError('git/nothing-staged', 'Stage at least one file before asking AI for a message.');
|
|
214
|
-
}
|
|
215
|
-
const recent = await recentSubjects(runtime, root, 5);
|
|
216
|
-
return writeCommitMessage(ctx, {
|
|
217
|
-
patch,
|
|
218
|
-
recent,
|
|
219
|
-
signal: AbortSignal.timeout(60_000),
|
|
220
|
-
model: valueOf(payload, 'model'),
|
|
221
|
-
instruction: valueOf(payload, 'instruction'),
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
default:
|
|
225
|
-
throw new GitError('git/unknown-method', `Unknown Git action: ${endpoint}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function createHandler(ctx, runtime) {
|
|
230
|
-
return async function handler(endpoint, payload, signal, peer) {
|
|
231
|
-
if (peer === undefined || peer.principal?.kind !== 'owner') {
|
|
232
|
-
return {
|
|
233
|
-
ok: false,
|
|
234
|
-
error: {
|
|
235
|
-
code: 'git/forbidden',
|
|
236
|
-
message: 'Git actions are available only to the local user.',
|
|
237
|
-
details: {},
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
const value = await dispatch(ctx, runtime, endpoint, payload);
|
|
243
|
-
return { ok: true, value };
|
|
244
|
-
} catch (error) {
|
|
245
|
-
if (error instanceof GitError) {
|
|
246
|
-
return {
|
|
247
|
-
ok: false,
|
|
248
|
-
error: {
|
|
249
|
-
code: error.code,
|
|
250
|
-
message: error.message,
|
|
251
|
-
details: error.details ?? {},
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
256
|
-
return {
|
|
257
|
-
ok: false,
|
|
258
|
-
error: {
|
|
259
|
-
code: signal?.aborted ? 'git/cancelled' : 'git/internal',
|
|
260
|
-
message: message === '' ? 'The Git action failed.' : message,
|
|
261
|
-
details: {},
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
}
|