@xi4z/dsh-utils 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +576 -2
- package/client.js +2330 -0
- package/cordis.patch.yml +101 -0
- package/icon.svg +21 -0
- package/lib/index.d.ts +69 -0
- package/lib/index.js +865 -0
- package/lib/index.js.map +1 -0
- package/lib/ui-host.d.ts +96 -0
- package/lib/ui-host.js +970 -0
- package/lib/ui-host.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +124 -3
- package/packages/approval-policy/lib/index.d.ts +297 -0
- package/packages/approval-policy/lib/index.js +425 -0
- package/packages/approval-policy/lib/index.js.map +1 -0
- package/packages/approval-policy/locale/en.json +6 -0
- package/packages/approval-policy/locale/zh.json +6 -0
- package/packages/notify/lib/index.d.ts +290 -0
- package/packages/notify/lib/index.js +915 -0
- package/packages/notify/lib/index.js.map +1 -0
- package/packages/notify/locale/en.json +6 -0
- package/packages/notify/locale/zh.json +6 -0
- package/packages/skill-panel/lib/index.d.ts +49 -0
- package/packages/skill-panel/lib/index.js +420 -0
- package/packages/skill-panel/lib/index.js.map +1 -0
- package/packages/skill-panel/locale/en.json +6 -0
- package/packages/skill-panel/locale/zh.json +6 -0
- package/packages/utils-agents/lib/git.d.ts +87 -0
- package/packages/utils-agents/lib/git.js +403 -0
- package/packages/utils-agents/lib/git.js.map +1 -0
- package/packages/utils-agents/lib/global-repo.d.ts +57 -0
- package/packages/utils-agents/lib/global-repo.js +301 -0
- package/packages/utils-agents/lib/global-repo.js.map +1 -0
- package/packages/utils-agents/lib/index.d.ts +80 -0
- package/packages/utils-agents/lib/index.js +435 -0
- package/packages/utils-agents/lib/index.js.map +1 -0
- package/packages/utils-agents/lib/legacy.d.ts +30 -0
- package/packages/utils-agents/lib/legacy.js +141 -0
- package/packages/utils-agents/lib/legacy.js.map +1 -0
- package/packages/utils-agents/lib/native.d.ts +74 -0
- package/packages/utils-agents/lib/native.js +232 -0
- package/packages/utils-agents/lib/native.js.map +1 -0
- package/packages/utils-agents/lib/presets.d.ts +34 -0
- package/packages/utils-agents/lib/presets.js +312 -0
- package/packages/utils-agents/lib/presets.js.map +1 -0
- package/packages/utils-agents/lib/shared.d.ts +105 -0
- package/packages/utils-agents/lib/shared.js +507 -0
- package/packages/utils-agents/lib/shared.js.map +1 -0
- package/packages/utils-agents/lib/update.d.ts +129 -0
- package/packages/utils-agents/lib/update.js +507 -0
- package/packages/utils-agents/lib/update.js.map +1 -0
- package/packages/utils-agents/lib/util.d.ts +215 -0
- package/packages/utils-agents/lib/util.js +475 -0
- package/packages/utils-agents/lib/util.js.map +1 -0
- package/packages/utils-agents/locale/en.json +6 -0
- package/packages/utils-agents/locale/zh.json +6 -0
- package/skills/dsh-approval-policy-config/SKILL.md +96 -0
- package/src/index.ts +933 -0
- package/src/ui-host.ts +1073 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared preset sources for the utils-agents panel.
|
|
3
|
+
*
|
|
4
|
+
* A skill repository may carry a ".dsh" directory that mirrors part of the DSH
|
|
5
|
+
* home, so presets can travel with the skills instead of being copied by hand.
|
|
6
|
+
* This module discovers those presets and copies them into
|
|
7
|
+
* "$DSH_HOME/.agent-presets"; the existing legacy bridge then registers the
|
|
8
|
+
* result as real Agent presets.
|
|
9
|
+
*
|
|
10
|
+
* Accepted layouts inside one repository root:
|
|
11
|
+
*
|
|
12
|
+
* - ".dsh/preset/<id>/" (canonical)
|
|
13
|
+
* - ".dsh/preset/" itself when it holds "preset.yml" or "agent.cordis.yml"
|
|
14
|
+
* - ".dsh/presets/<id>/" and ".dsh/.agent-presets/<id>/" (tolerated aliases)
|
|
15
|
+
* - ".dsh/<id>/" when the directory holds "preset.yml" or "agent.cordis.yml"
|
|
16
|
+
*
|
|
17
|
+
* Sources are read-only: the repository checkout is never modified. Writes are
|
|
18
|
+
* limited to the local preset home, and a removed source file is only deleted
|
|
19
|
+
* when the caller asks for a pruning sync.
|
|
20
|
+
*
|
|
21
|
+
* @module dsh-utils/utils-agents/shared
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from 'node:crypto';
|
|
24
|
+
import { lstat, mkdir, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
25
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
26
|
+
import { scanSkills } from './presets.js';
|
|
27
|
+
import { readRepoState, targetPath } from './git.js';
|
|
28
|
+
import { BODY_LIMIT_BYTES, IGNORED_DIRS, AgentsError, directoryOf, dshHome, errorMessage, exists, expandAbsolute, insideJoin, stringList, agentsStorageDir, } from './util.js';
|
|
29
|
+
/** Per-file copy ceiling; larger files are skipped, not truncated. */
|
|
30
|
+
const SHARED_MAX_BYTES = BODY_LIMIT_BYTES;
|
|
31
|
+
/** Directories never copied out of a source repository. */
|
|
32
|
+
const IGNORED_SHARED_DIRS = new Set([...IGNORED_DIRS, '.dsh-utils']);
|
|
33
|
+
/** Local-only trees that a pruning sync never deletes. */
|
|
34
|
+
const LOCAL_ONLY_DIRS = new Set(['.dsh-utils', '.git']);
|
|
35
|
+
/** Ids the panel reserves for its own pseudo target. */
|
|
36
|
+
const RESERVED_IDS = new Set(['__global__']);
|
|
37
|
+
/**
|
|
38
|
+
* Scan every known repository for ".dsh" presets.
|
|
39
|
+
* @param ctx - host context.
|
|
40
|
+
* @param options - normalized settings.
|
|
41
|
+
* @param preset - the selected preset, whose synced checkout is also a source.
|
|
42
|
+
* @returns the source roots with their preset rows.
|
|
43
|
+
*/
|
|
44
|
+
export async function sharedPresetView(ctx, options, preset) {
|
|
45
|
+
const localRoot = join(dshHome(), '.agent-presets');
|
|
46
|
+
const manifest = await readManifest();
|
|
47
|
+
const sources = [];
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
for (const source of await presetSources(options, preset)) {
|
|
50
|
+
const key = await canonicalPath(source.path);
|
|
51
|
+
if (seen.has(key))
|
|
52
|
+
continue;
|
|
53
|
+
seen.add(key);
|
|
54
|
+
if (!(await directoryOf(source.path))) {
|
|
55
|
+
sources.push({ path: source.path, kind: source.kind, exists: false, presets: [] });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
sources.push({
|
|
59
|
+
path: source.path,
|
|
60
|
+
kind: source.kind,
|
|
61
|
+
exists: true,
|
|
62
|
+
presets: await discoverSourcePresets(ctx, source.path, source.kind, manifest),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { localRoot, sources };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Copy the requested source presets into the DSH preset home.
|
|
69
|
+
* @param ctx - host context.
|
|
70
|
+
* @param options - normalized settings.
|
|
71
|
+
* @param preset - the selected preset, used to locate its repository checkout.
|
|
72
|
+
* @param body - request body with optional "ids" and "prune".
|
|
73
|
+
* @returns per-preset results plus the refreshed view.
|
|
74
|
+
*/
|
|
75
|
+
export async function syncSharedPresets(ctx, options, preset, body) {
|
|
76
|
+
const requested = stringList(body.ids);
|
|
77
|
+
const prune = body.prune === true;
|
|
78
|
+
const manifest = await readManifest();
|
|
79
|
+
const view = await sharedPresetView(ctx, options, preset);
|
|
80
|
+
const all = view.sources.flatMap((source) => source.presets);
|
|
81
|
+
const targets = requested.length === 0 ? all : all.filter((row) => requested.includes(row.id));
|
|
82
|
+
if (requested.length > 0 && targets.length === 0)
|
|
83
|
+
throw new AgentsError('没有找到要同步的预设:' + requested.join(', '), 404);
|
|
84
|
+
const results = [];
|
|
85
|
+
for (const row of targets) {
|
|
86
|
+
if (row.status === 'invalid') {
|
|
87
|
+
results.push({ id: row.id, status: row.status, written: 0, removed: 0, skipped: [], error: row.reason ?? '预设 id 不合法' });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const previous = manifest.presets[row.id]?.files ?? [];
|
|
92
|
+
const outcome = await copyPreset(ctx, row, prune, previous);
|
|
93
|
+
manifest.presets[row.id] = { source: row.sourceRoot, syncedAt: new Date().toISOString(), files: outcome.files };
|
|
94
|
+
results.push({ id: row.id, status: row.status, written: outcome.written, removed: outcome.removed, skipped: outcome.skipped });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const message = errorMessage(error);
|
|
98
|
+
ctx.logger.warn('utils-agents: cannot sync shared preset ' + row.id + ': ' + message);
|
|
99
|
+
results.push({ id: row.id, status: row.status, written: 0, removed: 0, skipped: [], error: message });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (results.some((result) => result.error === undefined))
|
|
103
|
+
await writeManifest(manifest);
|
|
104
|
+
return { results, view: await sharedPresetView(ctx, options, preset) };
|
|
105
|
+
}
|
|
106
|
+
/** The storage path of the shared-preset manifest. */
|
|
107
|
+
export function sharedManifestPath() {
|
|
108
|
+
return join(agentsStorageDir(), 'shared-presets.json');
|
|
109
|
+
}
|
|
110
|
+
/** Normalize one preset directory name into a safe id, or null. */
|
|
111
|
+
export function sharedPresetId(name) {
|
|
112
|
+
if (name === '' || name === '.' || name === '..')
|
|
113
|
+
return null;
|
|
114
|
+
if (name.startsWith('.') || RESERVED_IDS.has(name))
|
|
115
|
+
return null;
|
|
116
|
+
if (name.includes('/') || name.includes('\\') || name.includes(String.fromCharCode(0)))
|
|
117
|
+
return null;
|
|
118
|
+
return name;
|
|
119
|
+
}
|
|
120
|
+
/** Candidate directories inside one scanned repository. */
|
|
121
|
+
async function sharedLayouts(root) {
|
|
122
|
+
const candidates = [
|
|
123
|
+
join(root, '.dsh', 'preset'),
|
|
124
|
+
join(root, '.dsh', 'presets'),
|
|
125
|
+
join(root, '.dsh', '.agent-presets'),
|
|
126
|
+
join(root, '.dsh'),
|
|
127
|
+
];
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const candidate of candidates) {
|
|
130
|
+
if (await directoryOf(candidate))
|
|
131
|
+
out.push(candidate);
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/** Discover the presets inside one repository root. */
|
|
136
|
+
async function discoverSourcePresets(ctx, root, kind, manifest) {
|
|
137
|
+
const rows = [];
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
const seenPaths = new Set();
|
|
140
|
+
for (const layout of await sharedLayouts(root)) {
|
|
141
|
+
let entries;
|
|
142
|
+
try {
|
|
143
|
+
entries = await readdir(layout, { withFileTypes: true });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error.code !== 'ENOENT')
|
|
147
|
+
ctx.logger.debug('utils-agents: cannot read shared layout ' + layout + ': ' + errorMessage(error));
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
151
|
+
for (const entry of entries) {
|
|
152
|
+
if (!entry.isDirectory())
|
|
153
|
+
continue;
|
|
154
|
+
if (entry.name.startsWith('.'))
|
|
155
|
+
continue;
|
|
156
|
+
const sourcePath = join(layout, entry.name);
|
|
157
|
+
// Every candidate must carry the markers of a preset, so a skills/ tree
|
|
158
|
+
// inside the layout is not mistaken for a preset.
|
|
159
|
+
if (!(await looksLikePreset(sourcePath)))
|
|
160
|
+
continue;
|
|
161
|
+
const id = sharedPresetId(entry.name);
|
|
162
|
+
const pathKey = await canonicalPath(sourcePath);
|
|
163
|
+
if (id === null || seen.has(id) || seenPaths.has(pathKey))
|
|
164
|
+
continue;
|
|
165
|
+
seen.add(id);
|
|
166
|
+
seenPaths.add(pathKey);
|
|
167
|
+
rows.push(await describeSourcePreset(ctx, id, sourcePath, root, kind, manifest));
|
|
168
|
+
}
|
|
169
|
+
// ".dsh/preset/" may also be a single preset directory instead of a parent
|
|
170
|
+
// of preset directories; take its display id from preset.yml when present.
|
|
171
|
+
if (await looksLikePreset(layout)) {
|
|
172
|
+
const meta = await readSourceMeta(layout);
|
|
173
|
+
const id = sharedPresetId(meta.id === '' ? basename(layout) : meta.id);
|
|
174
|
+
const pathKey = await canonicalPath(layout);
|
|
175
|
+
if (id !== null && !seen.has(id) && !seenPaths.has(pathKey)) {
|
|
176
|
+
seen.add(id);
|
|
177
|
+
seenPaths.add(pathKey);
|
|
178
|
+
rows.push(await describeSourcePreset(ctx, id, layout, root, kind, manifest));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return rows;
|
|
183
|
+
}
|
|
184
|
+
/** Whether a directory holds the markers of a preset. */
|
|
185
|
+
async function looksLikePreset(path) {
|
|
186
|
+
return (await exists(join(path, 'preset.yml'))) || (await exists(join(path, 'agent.cordis.yml')));
|
|
187
|
+
}
|
|
188
|
+
/** Build one browser row for a source preset. */
|
|
189
|
+
async function describeSourcePreset(ctx, id, sourcePath, sourceRoot, kind, manifest) {
|
|
190
|
+
const meta = await readSourceMeta(sourcePath);
|
|
191
|
+
const skills = await scanSkills(ctx, sourcePath);
|
|
192
|
+
const files = await collectFiles(ctx, sourcePath);
|
|
193
|
+
const targetPath = join(dshHome(), '.agent-presets', id);
|
|
194
|
+
const managed = manifest.presets[id] !== undefined;
|
|
195
|
+
const status = await comparePreset(files, targetPath);
|
|
196
|
+
return {
|
|
197
|
+
id,
|
|
198
|
+
name: meta.name === '' ? id : meta.name,
|
|
199
|
+
description: meta.description,
|
|
200
|
+
status,
|
|
201
|
+
sourceKind: kind,
|
|
202
|
+
sourceRoot,
|
|
203
|
+
sourcePath,
|
|
204
|
+
targetPath,
|
|
205
|
+
skills: skills.filter((skill) => skill.enabled).length,
|
|
206
|
+
files: files.length,
|
|
207
|
+
managed,
|
|
208
|
+
lastSyncAt: managed ? manifest.presets[id].syncedAt : null,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/** Read the preset display metadata without a YAML dependency. */
|
|
212
|
+
async function readSourceMeta(presetPath) {
|
|
213
|
+
let text;
|
|
214
|
+
try {
|
|
215
|
+
text = await readFile(join(presetPath, 'preset.yml'), 'utf8');
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return { id: '', name: '', description: '' };
|
|
219
|
+
}
|
|
220
|
+
const values = {};
|
|
221
|
+
for (const line of text.split(/\r?\n/)) {
|
|
222
|
+
const match = /^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/.exec(line);
|
|
223
|
+
if (match === null)
|
|
224
|
+
continue;
|
|
225
|
+
const value = match[2].trim();
|
|
226
|
+
values[match[1]] = value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.endsWith(value[0])
|
|
227
|
+
? value.slice(1, -1)
|
|
228
|
+
: value;
|
|
229
|
+
}
|
|
230
|
+
return { id: values.id ?? '', name: values.name ?? '', description: values.description ?? '' };
|
|
231
|
+
}
|
|
232
|
+
/** Compare every source file with its local copy. */
|
|
233
|
+
async function comparePreset(files, targetPath) {
|
|
234
|
+
if (!(await directoryOf(targetPath)))
|
|
235
|
+
return 'new';
|
|
236
|
+
for (const file of files) {
|
|
237
|
+
const target = join(targetPath, file.rel);
|
|
238
|
+
let info;
|
|
239
|
+
try {
|
|
240
|
+
info = await lstat(target);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return 'update';
|
|
244
|
+
}
|
|
245
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size !== file.size)
|
|
246
|
+
return 'update';
|
|
247
|
+
if (await hashFile(target) !== await hashFile(file.path))
|
|
248
|
+
return 'update';
|
|
249
|
+
}
|
|
250
|
+
return 'same';
|
|
251
|
+
}
|
|
252
|
+
/** Every regular file under one source preset, relative to its root. */
|
|
253
|
+
async function collectFiles(ctx, root) {
|
|
254
|
+
const out = [];
|
|
255
|
+
await walkSource(root, root, ctx, out);
|
|
256
|
+
return out.sort((left, right) => left.rel.localeCompare(right.rel));
|
|
257
|
+
}
|
|
258
|
+
/** Recursively collect regular files, skipping symlinks and ignored trees. */
|
|
259
|
+
async function walkSource(root, dir, ctx, out) {
|
|
260
|
+
let entries;
|
|
261
|
+
try {
|
|
262
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error.code !== 'ENOENT')
|
|
266
|
+
ctx.logger.debug('utils-agents: cannot scan shared preset ' + dir + ': ' + errorMessage(error));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
270
|
+
for (const entry of entries) {
|
|
271
|
+
if (IGNORED_SHARED_DIRS.has(entry.name))
|
|
272
|
+
continue;
|
|
273
|
+
const path = join(dir, entry.name);
|
|
274
|
+
if (entry.isDirectory()) {
|
|
275
|
+
await walkSource(root, path, ctx, out);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (!entry.isFile())
|
|
279
|
+
continue;
|
|
280
|
+
let info;
|
|
281
|
+
try {
|
|
282
|
+
info = await lstat(path);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
288
|
+
continue;
|
|
289
|
+
if (info.size > SHARED_MAX_BYTES) {
|
|
290
|
+
ctx.logger.warn('utils-agents: skipping oversized shared preset file ' + path);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
out.push({ rel: relative(root, path).split(sep).join('/'), path, mode: info.mode & 0o777, size: info.size });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Copy one preset into $DSH_HOME/.agent-presets/<id>. */
|
|
297
|
+
async function copyPreset(ctx, row, prune, previous) {
|
|
298
|
+
if (sharedPresetId(row.id) === null)
|
|
299
|
+
throw new AgentsError('预设 id 不合法:' + row.id, 400);
|
|
300
|
+
const targetRoot = join(dshHome(), '.agent-presets', row.id);
|
|
301
|
+
await mkdir(targetRoot, { recursive: true, mode: 0o755 });
|
|
302
|
+
const files = await collectFiles(ctx, row.sourcePath);
|
|
303
|
+
const skipped = [];
|
|
304
|
+
let written = 0;
|
|
305
|
+
for (const file of files) {
|
|
306
|
+
const target = insideJoin(targetRoot, file.rel);
|
|
307
|
+
await mkdir(dirname(target), { recursive: true, mode: 0o755 });
|
|
308
|
+
if (await sameContent(file.path, target))
|
|
309
|
+
continue;
|
|
310
|
+
const content = await readFile(file.path);
|
|
311
|
+
await writeAtomic(target, content, file.mode);
|
|
312
|
+
written += 1;
|
|
313
|
+
}
|
|
314
|
+
const removed = prune ? await prunePreset(ctx, targetRoot, files, previous) : 0;
|
|
315
|
+
return { written, removed, skipped, files: files.map((file) => file.rel) };
|
|
316
|
+
}
|
|
317
|
+
/** Whether two files already carry identical bytes. */
|
|
318
|
+
async function sameContent(source, target) {
|
|
319
|
+
try {
|
|
320
|
+
const info = await lstat(target);
|
|
321
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
322
|
+
return false;
|
|
323
|
+
if (info.size !== (await lstat(source)).size)
|
|
324
|
+
return false;
|
|
325
|
+
return await hashFile(source) === await hashFile(target);
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/** Remove files this source owned before but no longer publishes. */
|
|
332
|
+
async function prunePreset(ctx, targetRoot, files, previous) {
|
|
333
|
+
const keep = new Set(files.map((file) => file.rel));
|
|
334
|
+
const removed = [];
|
|
335
|
+
for (const rel of previous) {
|
|
336
|
+
if (keep.has(rel))
|
|
337
|
+
continue;
|
|
338
|
+
if (LOCAL_ONLY_DIRS.has(rel.split('/')[0]))
|
|
339
|
+
continue;
|
|
340
|
+
try {
|
|
341
|
+
const info = await lstat(insideJoin(targetRoot, rel));
|
|
342
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
removed.push(rel);
|
|
349
|
+
}
|
|
350
|
+
for (const rel of removed)
|
|
351
|
+
await rm(insideJoin(targetRoot, rel), { force: true });
|
|
352
|
+
await removeEmptyDirs(ctx, targetRoot, targetRoot);
|
|
353
|
+
return removed.length;
|
|
354
|
+
}
|
|
355
|
+
/** Remove directories left empty by a pruning sync. */
|
|
356
|
+
async function removeEmptyDirs(ctx, root, dir) {
|
|
357
|
+
let entries;
|
|
358
|
+
try {
|
|
359
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
for (const entry of entries) {
|
|
365
|
+
if (!entry.isDirectory() || entry.name === '.git')
|
|
366
|
+
continue;
|
|
367
|
+
const path = join(dir, entry.name);
|
|
368
|
+
if (LOCAL_ONLY_DIRS.has(relative(root, path).split(sep)[0]))
|
|
369
|
+
continue;
|
|
370
|
+
await removeEmptyDirs(ctx, root, path);
|
|
371
|
+
}
|
|
372
|
+
if (dir === root)
|
|
373
|
+
return;
|
|
374
|
+
try {
|
|
375
|
+
const remaining = await readdir(dir);
|
|
376
|
+
if (remaining.length === 0)
|
|
377
|
+
await rm(dir, { recursive: true, force: true });
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
ctx.logger.debug('utils-agents: cannot remove empty shared preset directory ' + dir + ': ' + errorMessage(error));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/** Write one file through a temporary sibling, then rename. */
|
|
384
|
+
async function writeAtomic(target, content, mode) {
|
|
385
|
+
const temp = join(dirname(target), '.' + basename(target) + '.' + process.pid.toString(36) + Math.random().toString(36).slice(2, 8) + '.tmp');
|
|
386
|
+
try {
|
|
387
|
+
await writeFile(temp, content, { mode: mode === 0 ? 0o644 : mode, flag: 'wx' });
|
|
388
|
+
await rename(temp, target);
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
await rm(temp, { force: true });
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/** sha256 of one file. */
|
|
396
|
+
async function hashFile(path) {
|
|
397
|
+
const content = await readFile(path);
|
|
398
|
+
return createHash('sha256').update(content).digest('hex');
|
|
399
|
+
}
|
|
400
|
+
/** The checkout the legacy global skill-repository route syncs into. */
|
|
401
|
+
async function legacySkillRepoRoot() {
|
|
402
|
+
try {
|
|
403
|
+
const raw = JSON.parse(await readFile(join(dshHome(), 'storages', 'dsh-utils-ui.json'), 'utf8'));
|
|
404
|
+
const record = raw !== null && typeof raw === 'object' ? raw : {};
|
|
405
|
+
if (typeof record.targetDir === 'string' && record.targetDir.trim() !== '')
|
|
406
|
+
return expandAbsolute(record.targetDir);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
// Missing or malformed legacy state falls back to the shipped default.
|
|
410
|
+
}
|
|
411
|
+
return join(dshHome(), 'skills', 'herskill');
|
|
412
|
+
}
|
|
413
|
+
/** The repository roots to scan, in display order. */
|
|
414
|
+
async function presetSources(options, preset) {
|
|
415
|
+
const out = [];
|
|
416
|
+
if (preset !== null) {
|
|
417
|
+
try {
|
|
418
|
+
const state = await readRepoState(preset, options);
|
|
419
|
+
const target = targetPath(preset, state);
|
|
420
|
+
if (await directoryOf(target))
|
|
421
|
+
out.push({ path: target, kind: 'preset-repo' });
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
// A malformed repository configuration only hides that source.
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const legacy = await legacySkillRepoRoot();
|
|
428
|
+
if (legacy !== null && await directoryOf(legacy))
|
|
429
|
+
out.push({ path: legacy, kind: 'global-repo' });
|
|
430
|
+
const skills = join(dshHome(), 'skills');
|
|
431
|
+
out.push({ path: skills, kind: 'skills-home' });
|
|
432
|
+
// The legacy global repository may live one level below (for example
|
|
433
|
+
// $DSH_HOME/skills/herskill); treat any child that carries .dsh as a source.
|
|
434
|
+
try {
|
|
435
|
+
const entries = await readdir(skills, { withFileTypes: true });
|
|
436
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
437
|
+
for (const entry of entries) {
|
|
438
|
+
if (entry.name.startsWith('.'))
|
|
439
|
+
continue;
|
|
440
|
+
const child = join(skills, entry.name);
|
|
441
|
+
if (!entry.isDirectory() && !(entry.isSymbolicLink() && await directoryOf(child)))
|
|
442
|
+
continue;
|
|
443
|
+
if (await directoryOf(join(child, '.dsh')))
|
|
444
|
+
out.push({ path: child, kind: 'skills-home' });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
catch {
|
|
448
|
+
// A missing skills home simply contributes no per-repository sources.
|
|
449
|
+
}
|
|
450
|
+
for (const raw of options.presetSourceDirs) {
|
|
451
|
+
try {
|
|
452
|
+
out.push({ path: expandAbsolute(raw), kind: 'extra' });
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
// Invalid extras are ignored, matching the other path settings.
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return out;
|
|
459
|
+
}
|
|
460
|
+
/** Real path when it exists, resolved path otherwise. */
|
|
461
|
+
async function canonicalPath(path) {
|
|
462
|
+
try {
|
|
463
|
+
return await realpath(path);
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return resolve(path);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/** Read the sync manifest, tolerating a missing or broken file. */
|
|
470
|
+
export async function readManifest() {
|
|
471
|
+
let raw = null;
|
|
472
|
+
try {
|
|
473
|
+
raw = JSON.parse(await readFile(sharedManifestPath(), 'utf8'));
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
return { version: 1, presets: {} };
|
|
477
|
+
}
|
|
478
|
+
const record = raw !== null && typeof raw === 'object' ? raw : {};
|
|
479
|
+
const presets = {};
|
|
480
|
+
const source = record.presets !== null && typeof record.presets === 'object' ? record.presets : {};
|
|
481
|
+
for (const [id, value] of Object.entries(source)) {
|
|
482
|
+
if (value === null || typeof value !== 'object')
|
|
483
|
+
continue;
|
|
484
|
+
const entry = value;
|
|
485
|
+
presets[id] = {
|
|
486
|
+
source: typeof entry.source === 'string' ? entry.source : '',
|
|
487
|
+
syncedAt: typeof entry.syncedAt === 'string' ? entry.syncedAt : '',
|
|
488
|
+
files: Array.isArray(entry.files) ? entry.files.filter((file) => typeof file === 'string') : [],
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
return { version: 1, presets };
|
|
492
|
+
}
|
|
493
|
+
/** Persist the sync manifest. */
|
|
494
|
+
async function writeManifest(manifest) {
|
|
495
|
+
await mkdir(agentsStorageDir(), { recursive: true, mode: 0o700 });
|
|
496
|
+
const file = sharedManifestPath();
|
|
497
|
+
const temp = file + '.' + process.pid.toString(36) + Math.random().toString(36).slice(2, 8) + '.tmp';
|
|
498
|
+
try {
|
|
499
|
+
await writeFile(temp, JSON.stringify(manifest, null, 2) + '\n', { mode: 0o600, flag: 'wx' });
|
|
500
|
+
await rename(temp, file);
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
await rm(temp, { force: true });
|
|
504
|
+
throw error;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE3E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,OAAO,EACP,YAAY,EACZ,MAAM,EACN,cAAc,EACd,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,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Published-version checks for the dsh-utils bundle itself.
|
|
3
|
+
*
|
|
4
|
+
* The panel can tell the user whether a newer `@xi4z/dsh-utils` exists than the
|
|
5
|
+
* version this component runs from, and can install it automatically. Where it
|
|
6
|
+
* asks depends on how the bundle was installed in the profile:
|
|
7
|
+
*
|
|
8
|
+
* - a registry spec asks the npm `latest` document (one GET);
|
|
9
|
+
* - a GitHub spec reads the repository's `package.json` on that ref
|
|
10
|
+
* (`raw.githubusercontent.com`, no token needed for public repositories),
|
|
11
|
+
* and a branch/tag install is re-added by `pnpm add <spec>`;
|
|
12
|
+
* - a `link:`/`file:`/unknown install has no remote to install, so the npm
|
|
13
|
+
* answer is shown for reference only and nothing is ever installed.
|
|
14
|
+
*
|
|
15
|
+
* The automatic check runs shortly after activation and then every
|
|
16
|
+
* `updateCheckIntervalHours` (default 6). A manual "检查更新" asks immediately.
|
|
17
|
+
* With `updateAutoInstall` (default on) an available update is installed in the
|
|
18
|
+
* background, then reported as "installed, restart to apply": replacing a
|
|
19
|
+
* running plugin's files cannot take effect inside this process.
|
|
20
|
+
*
|
|
21
|
+
* The answer is cached in $DSH_HOME/storages/dsh-utils-agents/update.json so a
|
|
22
|
+
* restart shows the last known answer before the first network call, and a
|
|
23
|
+
* failed check never hides the last successfully read version.
|
|
24
|
+
*
|
|
25
|
+
* @module dsh-utils/utils-agents/update
|
|
26
|
+
*/
|
|
27
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
28
|
+
import { type Options } from './util.js';
|
|
29
|
+
/** Where the newest version is read from. */
|
|
30
|
+
export type UpdateSourceKind = 'npm' | 'git' | 'local';
|
|
31
|
+
/** The state of one automatic install attempt. */
|
|
32
|
+
export interface UpdateInstall {
|
|
33
|
+
/** idle: nothing to do; installing: pnpm is running; installed: restart to apply; failed: see message. */
|
|
34
|
+
readonly phase: 'idle' | 'installing' | 'installed' | 'failed';
|
|
35
|
+
/** The version being installed. */
|
|
36
|
+
readonly version: string | null;
|
|
37
|
+
/** Why the install failed, or the restart reminder after success. */
|
|
38
|
+
readonly message: string | null;
|
|
39
|
+
/** When the last phase change happened. */
|
|
40
|
+
readonly at: string | null;
|
|
41
|
+
}
|
|
42
|
+
/** The durable and returned shape of one update check. */
|
|
43
|
+
export interface UpdateStatus {
|
|
44
|
+
/** The version this component runs from; the bundle root package's version. */
|
|
45
|
+
readonly current: string;
|
|
46
|
+
/** The last successfully read remote version, if any. */
|
|
47
|
+
readonly latest: string | null;
|
|
48
|
+
/** Whether `latest` is newer than `current`. */
|
|
49
|
+
readonly updateAvailable: boolean;
|
|
50
|
+
/** Which remote the answer describes: npm, GitHub, or none for a local install. */
|
|
51
|
+
readonly source: UpdateSourceKind;
|
|
52
|
+
/** The exact remote the answer came from (registry base URL or raw GitHub URL). */
|
|
53
|
+
readonly origin: string;
|
|
54
|
+
/** When `latest` was read successfully. */
|
|
55
|
+
readonly checkedAt: string | null;
|
|
56
|
+
/** When the last attempt finished, successful or not. */
|
|
57
|
+
readonly attemptedAt: string | null;
|
|
58
|
+
/** Why the last check failed; null after a successful one. */
|
|
59
|
+
readonly error: string | null;
|
|
60
|
+
/** The last automatic install attempt. */
|
|
61
|
+
readonly install: UpdateInstall;
|
|
62
|
+
}
|
|
63
|
+
/** What the panel needs to describe the schedule. */
|
|
64
|
+
export interface UpdateSchedule {
|
|
65
|
+
readonly enabled: boolean;
|
|
66
|
+
readonly intervalHours: number;
|
|
67
|
+
readonly registry: string;
|
|
68
|
+
}
|
|
69
|
+
/** How this bundle was installed in the profile. */
|
|
70
|
+
interface InstallSource {
|
|
71
|
+
readonly kind: UpdateSourceKind;
|
|
72
|
+
/** The profile dependency spec, when it could be read. */
|
|
73
|
+
readonly spec: string | null;
|
|
74
|
+
/** A GitHub repository parsed from a Git spec. */
|
|
75
|
+
readonly git?: {
|
|
76
|
+
readonly owner: string;
|
|
77
|
+
readonly repo: string;
|
|
78
|
+
readonly ref: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** One install command for the profile. */
|
|
82
|
+
export interface InstallCommand {
|
|
83
|
+
/** The profile directory `pnpm add` runs in. */
|
|
84
|
+
readonly dir: string;
|
|
85
|
+
/** The package spec to add. */
|
|
86
|
+
readonly spec: string;
|
|
87
|
+
/** Whether to save an exact registry version. */
|
|
88
|
+
readonly exact: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** Runs one install; tests replace it. */
|
|
91
|
+
export type InstallRunner = (command: InstallCommand) => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Compare two semantic versions, ignoring build metadata.
|
|
94
|
+
* @returns negative when left is older, 0 when equal, positive when newer.
|
|
95
|
+
*/
|
|
96
|
+
export declare function compareVersions(left: string, right: string): number;
|
|
97
|
+
/**
|
|
98
|
+
* Read a GitHub repository out of a pnpm Git spec: `github:owner/repo`,
|
|
99
|
+
* `owner/repo`, `git+https://github.com/owner/repo.git#<ref>`, or the SSH form.
|
|
100
|
+
* A `#path:` parameter is dropped; the first remaining parameter is the ref.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseGitSpec(spec: string): {
|
|
103
|
+
owner: string;
|
|
104
|
+
repo: string;
|
|
105
|
+
ref: string;
|
|
106
|
+
} | null;
|
|
107
|
+
/** The install command for one source and target version; null when it must not install. */
|
|
108
|
+
export declare function installCommand(source: InstallSource, profile: string, name: string, version: string): InstallCommand | null;
|
|
109
|
+
/** One update checker per mounted component. */
|
|
110
|
+
export interface UpdateChecker {
|
|
111
|
+
/** The last known answer, reading the cache on first use. */
|
|
112
|
+
status(): Promise<UpdateStatus>;
|
|
113
|
+
/** Ask the remote now; concurrent calls share one request. */
|
|
114
|
+
check(): Promise<UpdateStatus>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create the checker for one component instance.
|
|
118
|
+
* @param ctx - host context, read for the profile directory the spec lives in.
|
|
119
|
+
* @param options - live settings snapshot; registry and auto-install are read per check.
|
|
120
|
+
* @param runner - how an install runs; defaults to `pnpm add` in the profile.
|
|
121
|
+
*/
|
|
122
|
+
export declare function createUpdateChecker(ctx: Context, options: () => Options, runner?: InstallRunner): UpdateChecker;
|
|
123
|
+
/**
|
|
124
|
+
* Run the automatic checks: one shortly after activation, then at the
|
|
125
|
+
* configured interval. The next delay is recomputed after every run, so an
|
|
126
|
+
* interval edited in the panel is picked up without a restart.
|
|
127
|
+
*/
|
|
128
|
+
export declare function startUpdateWatcher(ctx: Context, checker: UpdateChecker, options: () => Options): void;
|
|
129
|
+
export {};
|