iskills 0.2.45 → 0.2.47
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 +9 -7
- package/README.zh-CN.md +8 -6
- package/bin/iskills.js +10 -2
- package/dist/src/cli.js +22 -7
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/browser-actions.d.ts +2 -0
- package/dist/src/commands/browser-actions.js +154 -49
- package/dist/src/commands/browser-actions.js.map +1 -1
- package/dist/src/commands/config.d.ts +5 -0
- package/dist/src/commands/config.js +23 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/create.js +12 -8
- package/dist/src/commands/create.js.map +1 -1
- package/dist/src/commands/index.d.ts +1 -0
- package/dist/src/commands/index.js +19 -77
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/library.d.ts +46 -12
- package/dist/src/commands/library.js +384 -230
- package/dist/src/commands/library.js.map +1 -1
- package/dist/src/commands/search.js +17 -39
- package/dist/src/commands/search.js.map +1 -1
- package/dist/src/domain/collection-write.d.ts +53 -2
- package/dist/src/domain/collection-write.js +293 -61
- package/dist/src/domain/collection-write.js.map +1 -1
- package/dist/src/domain/core.d.ts +46 -5
- package/dist/src/domain/core.js +164 -58
- package/dist/src/domain/core.js.map +1 -1
- package/dist/src/domain/cross-agent-install.d.ts +32 -0
- package/dist/src/domain/cross-agent-install.js +147 -0
- package/dist/src/domain/cross-agent-install.js.map +1 -0
- package/dist/src/domain/errors.d.ts +20 -0
- package/dist/src/domain/errors.js +31 -0
- package/dist/src/domain/errors.js.map +1 -0
- package/dist/src/domain/git.js +15 -14
- package/dist/src/domain/git.js.map +1 -1
- package/dist/src/domain/user-config.d.ts +12 -0
- package/dist/src/domain/user-config.js +55 -0
- package/dist/src/domain/user-config.js.map +1 -0
- package/dist/src/i18n/en.d.ts +5 -0
- package/dist/src/i18n/en.js +423 -0
- package/dist/src/i18n/en.js.map +1 -0
- package/dist/src/i18n/index.d.ts +54 -0
- package/dist/src/i18n/index.js +164 -0
- package/dist/src/i18n/index.js.map +1 -0
- package/dist/src/i18n/zh.d.ts +409 -0
- package/dist/src/i18n/zh.js +423 -0
- package/dist/src/i18n/zh.js.map +1 -0
- package/dist/src/ui/browser/browse-capabilities.d.ts +26 -0
- package/dist/src/ui/browser/browse-capabilities.js +130 -0
- package/dist/src/ui/browser/browse-capabilities.js.map +1 -0
- package/dist/src/ui/browser/browser.js +205 -62
- package/dist/src/ui/browser/browser.js.map +1 -1
- package/dist/src/ui/browser/detail.js +1 -1
- package/dist/src/ui/browser/detail.js.map +1 -1
- package/dist/src/ui/browser/footer.js +26 -88
- package/dist/src/ui/browser/footer.js.map +1 -1
- package/dist/src/ui/browser/format.d.ts +13 -20
- package/dist/src/ui/browser/format.js +81 -144
- package/dist/src/ui/browser/format.js.map +1 -1
- package/dist/src/ui/browser/index.js +35 -3
- package/dist/src/ui/browser/index.js.map +1 -1
- package/dist/src/ui/browser/shortcut-help.js +3 -4
- package/dist/src/ui/browser/shortcut-help.js.map +1 -1
- package/dist/src/ui/browser/store.d.ts +4 -0
- package/dist/src/ui/browser/store.js +2 -0
- package/dist/src/ui/browser/store.js.map +1 -1
- package/dist/src/ui/browser/types.d.ts +19 -4
- package/dist/src/ui/collection-match.d.ts +1 -1
- package/dist/src/ui/collection-match.js +8 -5
- package/dist/src/ui/collection-match.js.map +1 -1
- package/dist/src/ui/components/framed-panel.d.ts +6 -1
- package/dist/src/ui/components/framed-panel.js +7 -4
- package/dist/src/ui/components/framed-panel.js.map +1 -1
- package/dist/src/ui/components/modal-panel.d.ts +4 -1
- package/dist/src/ui/components/modal-panel.js +8 -2
- package/dist/src/ui/components/modal-panel.js.map +1 -1
- package/dist/src/ui/components/mouse/index.d.ts +1 -1
- package/dist/src/ui/components/mouse/index.js +1 -1
- package/dist/src/ui/components/mouse/index.js.map +1 -1
- package/dist/src/ui/components/mouse/parse.d.ts +0 -7
- package/dist/src/ui/components/mouse/parse.js +0 -41
- package/dist/src/ui/components/mouse/parse.js.map +1 -1
- package/dist/src/ui/components/multi-select.js +3 -10
- package/dist/src/ui/components/multi-select.js.map +1 -1
- package/dist/src/ui/components/options.d.ts +2 -0
- package/dist/src/ui/components/options.js +9 -0
- package/dist/src/ui/components/options.js.map +1 -1
- package/dist/src/ui/components/select.js +1 -1
- package/dist/src/ui/components/select.js.map +1 -1
- package/dist/src/ui/components/tag-editor.d.ts +1 -2
- package/dist/src/ui/components/tag-editor.js +6 -4
- package/dist/src/ui/components/tag-editor.js.map +1 -1
- package/dist/src/ui/components/termcn.d.ts +1 -5
- package/dist/src/ui/components/termcn.js +1 -4
- package/dist/src/ui/components/termcn.js.map +1 -1
- package/dist/src/ui/config/index.d.ts +11 -0
- package/dist/src/ui/config/index.js +22 -0
- package/dist/src/ui/config/index.js.map +1 -0
- package/dist/src/ui/config/settings.d.ts +17 -0
- package/dist/src/ui/config/settings.js +126 -0
- package/dist/src/ui/config/settings.js.map +1 -0
- package/dist/src/ui/footer/resolve-footer.js +54 -36
- package/dist/src/ui/footer/resolve-footer.js.map +1 -1
- package/dist/src/ui/footer/types.d.ts +12 -2
- package/dist/src/ui/import/review.js +5 -8
- package/dist/src/ui/import/review.js.map +1 -1
- package/dist/src/ui/import/skill-select.js +15 -33
- package/dist/src/ui/import/skill-select.js.map +1 -1
- package/dist/src/ui/install/review.js +18 -19
- package/dist/src/ui/install/review.js.map +1 -1
- package/dist/src/ui/overlay/bridge.d.ts +1 -1
- package/dist/src/ui/prompts/present.d.ts +4 -2
- package/dist/src/ui/prompts/present.js +70 -5
- package/dist/src/ui/prompts/present.js.map +1 -1
- package/dist/src/ui/search/index.js +9 -7
- package/dist/src/ui/search/index.js.map +1 -1
- package/dist/src/ui/shell/app-shell.d.ts +1 -1
- package/dist/src/ui/shell/app-shell.js +1 -1
- package/dist/src/ui/shell/run.d.ts +0 -11
- package/dist/src/ui/shell/run.js +0 -43
- package/dist/src/ui/shell/run.js.map +1 -1
- package/dist/src/ui/shell/terminal.d.ts +0 -1
- package/dist/src/ui/shell/terminal.js +2 -1
- package/dist/src/ui/shell/terminal.js.map +1 -1
- package/dist/src/ui/skill-labels.d.ts +10 -9
- package/dist/src/ui/skill-labels.js +14 -10
- package/dist/src/ui/skill-labels.js.map +1 -1
- package/dist/src/ui/tui/hooks.d.ts +1 -13
- package/dist/src/ui/tui/hooks.js +1 -11
- package/dist/src/ui/tui/hooks.js.map +1 -1
- package/dist/src/ui/tui/index.d.ts +1 -1
- package/dist/src/ui/tui/index.js +1 -1
- package/dist/src/ui/tui/index.js.map +1 -1
- package/package.json +10 -11
- package/bin/patch-react-reconciler.mjs +0 -71
- package/dist/src/ui/components/confirm.d.ts +0 -6
- package/dist/src/ui/components/confirm.js +0 -22
- package/dist/src/ui/components/confirm.js.map +0 -1
- package/dist/src/ui/components/link.d.ts +0 -7
- package/dist/src/ui/components/link.js +0 -17
- package/dist/src/ui/components/link.js.map +0 -1
- package/dist/src/ui/components/modal.d.ts +0 -16
- package/dist/src/ui/components/modal.js +0 -58
- package/dist/src/ui/components/modal.js.map +0 -1
|
@@ -1,13 +1,144 @@
|
|
|
1
1
|
import { cp, lstat, mkdir, mkdtemp, readdir, realpath, rename, rm, symlink, writeFile, } from 'node:fs/promises';
|
|
2
2
|
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
3
|
-
import { assertSkillName, baselinePath, collectionPaths, commitCollection, copyDirectoryContents, ensureCollection, errorMessage, exists, isExactSymlink, metadataPath, moveDirectory, pathPresent, readMetadata, readSkill, readState, validateSkillTree, writeMetadata, writeState, } from './core.js';
|
|
3
|
+
import { assertSkillName, baselinePath, classifyCollectionMatch, collectionPaths, commitCollection, copyDirectoryContents, ensureCollection, errorMessage, exists, isExactSymlink, metadataPath, moveDirectory, pathPresent, readMetadata, readSkill, readState, resolveIdentityPath, validateSkillTree, writeMetadata, writeState, } from './core.js';
|
|
4
|
+
import { DomainError, domainNotify } from './errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Single 收藏夹写入 entry for import: first install or replace.
|
|
7
|
+
* Same-source is a no-op. Callers decide allowReplace after confirm.
|
|
8
|
+
*/
|
|
9
|
+
export async function installCollectionSkill(input) {
|
|
10
|
+
const skillName = assertSkillName(input.name);
|
|
11
|
+
await ensureCollection();
|
|
12
|
+
const paths = collectionPaths();
|
|
13
|
+
const target = join(paths.skills, skillName);
|
|
14
|
+
const commitMessage = input.commitMessage ?? `import ${skillName}`;
|
|
15
|
+
// Canonical name is the install key; never write mismatched metadata files.
|
|
16
|
+
const metadata = { ...input.metadata, name: skillName };
|
|
17
|
+
if (input.local && resolve(input.sourceTree) !== resolve(input.local.originPath)) {
|
|
18
|
+
throw new DomainError('domain.unsafeSourcePath', { path: input.sourceTree });
|
|
19
|
+
}
|
|
20
|
+
if (input.local) {
|
|
21
|
+
const originReal = await resolveIdentityPath(input.local.originPath);
|
|
22
|
+
const targetReal = await resolveIdentityPath(target);
|
|
23
|
+
if (originReal === targetReal)
|
|
24
|
+
return 'unchanged';
|
|
25
|
+
}
|
|
26
|
+
await validateSkillTree(input.sourceTree);
|
|
27
|
+
if (await pathPresent(target)) {
|
|
28
|
+
const current = await readMetadata(skillName);
|
|
29
|
+
if ((await classifyCollectionMatch(current, metadata)) === 'same-source') {
|
|
30
|
+
return 'unchanged';
|
|
31
|
+
}
|
|
32
|
+
if (!input.allowReplace) {
|
|
33
|
+
throw new DomainError('cmd.sameNameExistsReplace', { name: skillName });
|
|
34
|
+
}
|
|
35
|
+
const transaction = await mkdtemp(join(paths.local, `.prepare-${skillName}-`));
|
|
36
|
+
const staged = join(transaction, 'tree');
|
|
37
|
+
try {
|
|
38
|
+
await cp(input.sourceTree, staged, { recursive: true, errorOnExist: true });
|
|
39
|
+
const replacement = {
|
|
40
|
+
name: skillName,
|
|
41
|
+
staged,
|
|
42
|
+
metadata,
|
|
43
|
+
commitMessage,
|
|
44
|
+
};
|
|
45
|
+
if (input.local) {
|
|
46
|
+
replacement.local = {
|
|
47
|
+
source: input.local.originPath,
|
|
48
|
+
selectedPath: input.local.selectedPath,
|
|
49
|
+
selectedWasSymlink: input.local.selectedWasSymlink,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (input.commit === false)
|
|
53
|
+
replacement.commit = false;
|
|
54
|
+
const replaceCommit = await replaceCollectionSkill(replacement);
|
|
55
|
+
if (replaceCommit === 'failed')
|
|
56
|
+
return 'installed-uncommitted';
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await rm(transaction, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
return 'installed';
|
|
62
|
+
}
|
|
63
|
+
// First-time install: tree + metadata + links (+ baseline); optional commit.
|
|
64
|
+
const stateBefore = await readState();
|
|
65
|
+
let sourceMoved = false;
|
|
66
|
+
let linksRegistered = false;
|
|
67
|
+
try {
|
|
68
|
+
if (input.local) {
|
|
69
|
+
await moveDirectory(input.local.originPath, target);
|
|
70
|
+
sourceMoved = true;
|
|
71
|
+
try {
|
|
72
|
+
await symlink(target, input.local.originPath, 'dir');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
await moveDirectory(target, input.local.originPath);
|
|
76
|
+
sourceMoved = false;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
await cp(input.sourceTree, target, { recursive: true, errorOnExist: true });
|
|
82
|
+
}
|
|
83
|
+
await writeMetadata(metadata);
|
|
84
|
+
// Align with replace: always clear stale baseline, then recreate when needed.
|
|
85
|
+
await rm(baselinePath(skillName), { recursive: true, force: true });
|
|
86
|
+
if (metadata.source.type === 'git' && !metadata.source.commit) {
|
|
87
|
+
await cp(target, baselinePath(skillName), { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
if (input.local) {
|
|
90
|
+
const links = [
|
|
91
|
+
{ skill: skillName, path: input.local.originPath, kind: 'origin' },
|
|
92
|
+
];
|
|
93
|
+
if (input.local.selectedWasSymlink) {
|
|
94
|
+
links.push({
|
|
95
|
+
skill: skillName,
|
|
96
|
+
path: input.local.selectedPath,
|
|
97
|
+
kind: 'dependent',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
await registerCollectionLinks(links);
|
|
101
|
+
linksRegistered = true;
|
|
102
|
+
}
|
|
103
|
+
if (input.commit !== false) {
|
|
104
|
+
if (!(await commitCollection(commitMessage)))
|
|
105
|
+
return 'installed-uncommitted';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
try {
|
|
110
|
+
if (linksRegistered) {
|
|
111
|
+
await writeState(stateBefore);
|
|
112
|
+
}
|
|
113
|
+
if (input.local && sourceMoved) {
|
|
114
|
+
await rm(input.local.originPath, { recursive: true, force: true });
|
|
115
|
+
if (await pathPresent(target)) {
|
|
116
|
+
await moveDirectory(target, input.local.originPath);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (await pathPresent(target)) {
|
|
120
|
+
await rm(target, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
await rm(metadataPath(skillName), { force: true });
|
|
123
|
+
await rm(baselinePath(skillName), { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
catch (rollbackError) {
|
|
126
|
+
throw new DomainError('domain.importFailedRollback', {
|
|
127
|
+
error: errorMessage(error),
|
|
128
|
+
rollback: errorMessage(rollbackError),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
return 'installed';
|
|
134
|
+
}
|
|
4
135
|
/** Creates a minimal collected Skill born in the collection (not an import). */
|
|
5
136
|
export async function createCollectionSkill(name) {
|
|
6
137
|
const skillName = assertSkillName(name);
|
|
7
138
|
const paths = await ensureCollection();
|
|
8
139
|
const target = join(paths.skills, skillName);
|
|
9
140
|
if (await pathPresent(target)) {
|
|
10
|
-
throw new
|
|
141
|
+
throw new DomainError('domain.skillExistsInCollection', { name: skillName });
|
|
11
142
|
}
|
|
12
143
|
const metadata = metadataPath(skillName);
|
|
13
144
|
let created = false;
|
|
@@ -18,7 +149,7 @@ export async function createCollectionSkill(name) {
|
|
|
18
149
|
}
|
|
19
150
|
catch (error) {
|
|
20
151
|
if (error.code === 'EEXIST') {
|
|
21
|
-
throw new
|
|
152
|
+
throw new DomainError('domain.skillExistsInCollection', { name: skillName });
|
|
22
153
|
}
|
|
23
154
|
throw error;
|
|
24
155
|
}
|
|
@@ -40,10 +171,79 @@ export async function createCollectionSkill(name) {
|
|
|
40
171
|
}
|
|
41
172
|
throw error;
|
|
42
173
|
}
|
|
43
|
-
await commitCollection(`create ${skillName}`);
|
|
44
|
-
return target;
|
|
174
|
+
const committed = await commitCollection(`create ${skillName}`);
|
|
175
|
+
return { path: target, committed };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Collected skill trees that have SKILL.md but no metadata file on disk.
|
|
179
|
+
* Skips directory/frontmatter name mismatches (those need interactive repair).
|
|
180
|
+
*/
|
|
181
|
+
export async function listCollectionSkillsMissingMetadata() {
|
|
182
|
+
const paths = collectionPaths();
|
|
183
|
+
if (!(await exists(paths.skills)))
|
|
184
|
+
return [];
|
|
185
|
+
const missing = [];
|
|
186
|
+
for (const entry of await readdir(paths.skills, { withFileTypes: true })) {
|
|
187
|
+
if (!entry.isDirectory())
|
|
188
|
+
continue;
|
|
189
|
+
const skillDir = join(paths.skills, entry.name);
|
|
190
|
+
if (!(await exists(join(skillDir, 'SKILL.md'))))
|
|
191
|
+
continue;
|
|
192
|
+
let skill;
|
|
193
|
+
try {
|
|
194
|
+
skill = await readSkill(skillDir);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (skill.name !== entry.name)
|
|
200
|
+
continue;
|
|
201
|
+
if (await pathPresent(metadataPath(skill.name)))
|
|
202
|
+
continue;
|
|
203
|
+
missing.push(skill.name);
|
|
204
|
+
}
|
|
205
|
+
return missing.sort((a, b) => a.localeCompare(b));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Adopt skill trees already under skills/ by writing create-shaped metadata
|
|
209
|
+
* (`source: unknown`). Does not invent git/local provenance or origin links.
|
|
210
|
+
*/
|
|
211
|
+
export async function adoptCollectionSkillsMissingMetadata(names) {
|
|
212
|
+
const candidates = names ?? (await listCollectionSkillsMissingMetadata());
|
|
213
|
+
const adopted = [];
|
|
214
|
+
const paths = collectionPaths();
|
|
215
|
+
for (const name of candidates) {
|
|
216
|
+
const skillName = assertSkillName(name);
|
|
217
|
+
const skillDir = join(paths.skills, skillName);
|
|
218
|
+
if (!(await exists(join(skillDir, 'SKILL.md'))))
|
|
219
|
+
continue;
|
|
220
|
+
let skill;
|
|
221
|
+
try {
|
|
222
|
+
skill = await readSkill(skillDir);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (skill.name !== skillName)
|
|
228
|
+
continue;
|
|
229
|
+
if (await pathPresent(metadataPath(skillName)))
|
|
230
|
+
continue;
|
|
231
|
+
await writeMetadata({
|
|
232
|
+
name: skillName,
|
|
233
|
+
description: skill.description,
|
|
234
|
+
tags: [],
|
|
235
|
+
note: '',
|
|
236
|
+
source: { type: 'unknown' },
|
|
237
|
+
});
|
|
238
|
+
adopted.push(skillName);
|
|
239
|
+
}
|
|
240
|
+
if (adopted.length) {
|
|
241
|
+
await commitCollection(`adopt ${adopted.join(', ')}`);
|
|
242
|
+
}
|
|
243
|
+
return adopted;
|
|
45
244
|
}
|
|
46
245
|
// Replaces one collected Skill while keeping its tree, metadata, links and baseline coherent.
|
|
246
|
+
/** @returns deferred when commit:false; failed when commit soft-failed; ok otherwise. */
|
|
47
247
|
export async function replaceCollectionSkill(input) {
|
|
48
248
|
const paths = collectionPaths();
|
|
49
249
|
const target = join(paths.skills, input.name);
|
|
@@ -62,7 +262,7 @@ export async function replaceCollectionSkill(input) {
|
|
|
62
262
|
let sourceMoved = false;
|
|
63
263
|
if (origin && !(await isExactSymlink(origin.path, target))) {
|
|
64
264
|
await rm(transaction, { recursive: true, force: true });
|
|
65
|
-
throw new
|
|
265
|
+
throw new DomainError('domain.originNotCollectionLink', { path: origin.path });
|
|
66
266
|
}
|
|
67
267
|
try {
|
|
68
268
|
await cp(target, oldTree, { recursive: true, errorOnExist: true });
|
|
@@ -108,7 +308,23 @@ export async function replaceCollectionSkill(input) {
|
|
|
108
308
|
}
|
|
109
309
|
}
|
|
110
310
|
await writeState(nextState);
|
|
111
|
-
|
|
311
|
+
let commitResult = 'deferred';
|
|
312
|
+
if (input.commit !== false) {
|
|
313
|
+
commitResult = (await commitCollection(input.commitMessage ?? `import ${input.name}`))
|
|
314
|
+
? 'ok'
|
|
315
|
+
: 'failed';
|
|
316
|
+
}
|
|
317
|
+
for (const conflict of state.conflicts) {
|
|
318
|
+
if (conflict.type === 'source' && conflict.skill === input.name) {
|
|
319
|
+
await rm(conflict.path, { recursive: true, force: true }).catch((error) => {
|
|
320
|
+
domainNotify('domain.warnConflictCleanup', { error: errorMessage(error) });
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
await rm(transaction, { recursive: true, force: true }).catch((error) => {
|
|
325
|
+
domainNotify('domain.warnReplaceBackupCleanup', { error: errorMessage(error) });
|
|
326
|
+
});
|
|
327
|
+
return commitResult;
|
|
112
328
|
}
|
|
113
329
|
catch (error) {
|
|
114
330
|
try {
|
|
@@ -133,21 +349,14 @@ export async function replaceCollectionSkill(input) {
|
|
|
133
349
|
}
|
|
134
350
|
}
|
|
135
351
|
catch (rollbackError) {
|
|
136
|
-
throw new
|
|
352
|
+
throw new DomainError('domain.importFailedRollback', {
|
|
353
|
+
error: errorMessage(error),
|
|
354
|
+
rollback: errorMessage(rollbackError),
|
|
355
|
+
});
|
|
137
356
|
}
|
|
138
357
|
await rm(transaction, { recursive: true, force: true }).catch(() => { });
|
|
139
358
|
throw error;
|
|
140
359
|
}
|
|
141
|
-
for (const conflict of state.conflicts) {
|
|
142
|
-
if (conflict.type === 'source' && conflict.skill === input.name) {
|
|
143
|
-
await rm(conflict.path, { recursive: true, force: true }).catch((error) => {
|
|
144
|
-
console.error(`警告:旧冲突目录清理失败:${errorMessage(error)}`);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
await rm(transaction, { recursive: true, force: true }).catch((error) => {
|
|
149
|
-
console.error(`警告:替换备份清理失败:${errorMessage(error)}`);
|
|
150
|
-
});
|
|
151
360
|
}
|
|
152
361
|
export async function registerCollectionLinks(links) {
|
|
153
362
|
if (!links.length)
|
|
@@ -164,10 +373,10 @@ export async function removeCollectionUsage(name, from) {
|
|
|
164
373
|
link.kind !== 'origin' &&
|
|
165
374
|
(resolve(link.path) === scope || resolve(link.path).startsWith(`${scope}${sep}`)));
|
|
166
375
|
if (!candidates.length)
|
|
167
|
-
throw new
|
|
376
|
+
throw new DomainError('domain.noUsageInScope', { name });
|
|
168
377
|
for (const link of candidates) {
|
|
169
378
|
if (!(await isExactSymlink(link.path, collectionTarget))) {
|
|
170
|
-
throw new
|
|
379
|
+
throw new DomainError('domain.usageNotExpectedLink', { path: link.path });
|
|
171
380
|
}
|
|
172
381
|
}
|
|
173
382
|
for (const link of candidates)
|
|
@@ -183,12 +392,12 @@ export async function removeFromCollection(name, confirmed = false, quiet = fals
|
|
|
183
392
|
const paths = collectionPaths();
|
|
184
393
|
const skillPath = join(paths.skills, assertSkillName(name));
|
|
185
394
|
if (!(await exists(skillPath)))
|
|
186
|
-
throw new
|
|
395
|
+
throw new DomainError('domain.notInCollection', { name });
|
|
187
396
|
const state = await readState();
|
|
188
397
|
const links = state.links.filter((link) => link.skill === name);
|
|
189
398
|
const origin = links.find((link) => link.kind === 'origin');
|
|
190
399
|
if (origin && !(await isExactSymlink(origin.path, skillPath))) {
|
|
191
|
-
throw new
|
|
400
|
+
throw new DomainError('domain.originNotCollectionLink', { path: origin.path });
|
|
192
401
|
}
|
|
193
402
|
for (const link of links.filter((item) => item.kind === 'usage')) {
|
|
194
403
|
if (await isExactSymlink(link.path, skillPath))
|
|
@@ -200,7 +409,7 @@ export async function removeFromCollection(name, confirmed = false, quiet = fals
|
|
|
200
409
|
}
|
|
201
410
|
else {
|
|
202
411
|
if (!confirmed)
|
|
203
|
-
throw new
|
|
412
|
+
throw new DomainError('domain.removeNeedsConfirm');
|
|
204
413
|
await rm(skillPath, { recursive: true });
|
|
205
414
|
}
|
|
206
415
|
await rm(metadataPath(name), { force: true });
|
|
@@ -213,15 +422,16 @@ export async function removeFromCollection(name, confirmed = false, quiet = fals
|
|
|
213
422
|
state.links = state.links.filter((link) => link.skill !== name);
|
|
214
423
|
state.conflicts = state.conflicts.filter((conflict) => conflict.type !== 'source' || conflict.skill !== name);
|
|
215
424
|
await writeState(state);
|
|
216
|
-
await commitCollection(`remove ${name}`);
|
|
217
|
-
|
|
218
|
-
|
|
425
|
+
const commitOk = await commitCollection(`remove ${name}`);
|
|
426
|
+
// Success lines only after a non-failed commit point (domain-invariants 消息真实性).
|
|
427
|
+
if (!quiet && commitOk) {
|
|
428
|
+
domainNotify(origin ? 'domain.removedWithRestore' : 'domain.removed', origin ? { name, path: origin.path } : { name });
|
|
219
429
|
}
|
|
220
430
|
}
|
|
221
431
|
async function validateMaterializableSkillTree(root, current = root, ancestors = new Set()) {
|
|
222
432
|
const currentReal = await realpath(current);
|
|
223
433
|
if (ancestors.has(currentReal)) {
|
|
224
|
-
throw new
|
|
434
|
+
throw new DomainError('domain.cyclicSymlink', { path: current });
|
|
225
435
|
}
|
|
226
436
|
const nextAncestors = new Set(ancestors).add(currentReal);
|
|
227
437
|
for (const entry of await readdir(current, { withFileTypes: true })) {
|
|
@@ -232,10 +442,10 @@ async function validateMaterializableSkillTree(root, current = root, ancestors =
|
|
|
232
442
|
target = await realpath(path);
|
|
233
443
|
}
|
|
234
444
|
catch {
|
|
235
|
-
throw new
|
|
445
|
+
throw new DomainError('domain.unresolvableSymlink', { path });
|
|
236
446
|
}
|
|
237
447
|
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
238
|
-
throw new
|
|
448
|
+
throw new DomainError('domain.symlinkOutside', { path });
|
|
239
449
|
}
|
|
240
450
|
if ((await lstat(target)).isDirectory()) {
|
|
241
451
|
await validateMaterializableSkillTree(root, target, nextAncestors);
|
|
@@ -250,7 +460,7 @@ async function assertMaterializedTree(current) {
|
|
|
250
460
|
for (const entry of await readdir(current, { withFileTypes: true })) {
|
|
251
461
|
const path = join(current, entry.name);
|
|
252
462
|
if (entry.isSymbolicLink()) {
|
|
253
|
-
throw new
|
|
463
|
+
throw new DomainError('domain.copyStillHasSymlink', { path });
|
|
254
464
|
}
|
|
255
465
|
if (entry.isDirectory())
|
|
256
466
|
await assertMaterializedTree(path);
|
|
@@ -263,19 +473,22 @@ async function validateSkillLocations(skills, operation) {
|
|
|
263
473
|
unique.set(resolve(skill.path), skill);
|
|
264
474
|
for (const [path, skill] of unique) {
|
|
265
475
|
if (path === collectionRoot || path.startsWith(`${collectionRoot}${sep}`)) {
|
|
266
|
-
throw new
|
|
476
|
+
throw new DomainError('domain.cannotOpCollectionByPath', {
|
|
477
|
+
operation: operation === 'delete' ? 'domain.opDelete' : 'domain.opMaterialize',
|
|
478
|
+
path,
|
|
479
|
+
});
|
|
267
480
|
}
|
|
268
481
|
if (!(await pathPresent(path)))
|
|
269
|
-
throw new
|
|
482
|
+
throw new DomainError('domain.locationGone', { path });
|
|
270
483
|
let current;
|
|
271
484
|
try {
|
|
272
485
|
current = await readSkill(path);
|
|
273
486
|
}
|
|
274
487
|
catch {
|
|
275
|
-
throw new
|
|
488
|
+
throw new DomainError(operation === 'delete' ? 'domain.locationChangedNotDeleted' : 'domain.locationChanged', { path });
|
|
276
489
|
}
|
|
277
490
|
if (current.name !== skill.name) {
|
|
278
|
-
throw new
|
|
491
|
+
throw new DomainError(operation === 'delete' ? 'domain.locationChangedNotDeleted' : 'domain.locationChanged', { path });
|
|
279
492
|
}
|
|
280
493
|
}
|
|
281
494
|
return unique;
|
|
@@ -283,29 +496,29 @@ async function validateSkillLocations(skills, operation) {
|
|
|
283
496
|
function throwIfAborted(signal) {
|
|
284
497
|
if (!signal?.aborted)
|
|
285
498
|
return;
|
|
286
|
-
const error = new
|
|
499
|
+
const error = new DomainError('common.interrupted');
|
|
287
500
|
error.name = 'AbortError';
|
|
288
501
|
throw error;
|
|
289
502
|
}
|
|
290
503
|
export async function materializeSkillReferences(skills, options = {}) {
|
|
291
504
|
if (!skills.length)
|
|
292
505
|
return 0;
|
|
293
|
-
const unique = await validateSkillLocations(skills, '
|
|
506
|
+
const unique = await validateSkillLocations(skills, 'materialize');
|
|
294
507
|
const preflight = [];
|
|
295
508
|
for (const [path, skill] of unique) {
|
|
296
509
|
throwIfAborted(options.signal);
|
|
297
510
|
if (!(await lstat(path)).isSymbolicLink()) {
|
|
298
|
-
throw new
|
|
511
|
+
throw new DomainError('domain.notAReference', { path });
|
|
299
512
|
}
|
|
300
513
|
let source;
|
|
301
514
|
try {
|
|
302
515
|
source = await realpath(path);
|
|
303
516
|
}
|
|
304
517
|
catch {
|
|
305
|
-
throw new
|
|
518
|
+
throw new DomainError('domain.referenceUnresolvable', { path });
|
|
306
519
|
}
|
|
307
520
|
if (!(await lstat(source)).isDirectory()) {
|
|
308
|
-
throw new
|
|
521
|
+
throw new DomainError('domain.referenceNotDir', { path });
|
|
309
522
|
}
|
|
310
523
|
await validateMaterializableSkillTree(source);
|
|
311
524
|
preflight.push({ skill, path, source });
|
|
@@ -336,7 +549,7 @@ export async function materializeSkillReferences(skills, options = {}) {
|
|
|
336
549
|
await assertMaterializedTree(staged);
|
|
337
550
|
const copied = await readSkill(staged);
|
|
338
551
|
if (copied.name !== input.skill.name) {
|
|
339
|
-
throw new
|
|
552
|
+
throw new DomainError('domain.copyNameChanged', { path: input.path });
|
|
340
553
|
}
|
|
341
554
|
}
|
|
342
555
|
const state = await readState();
|
|
@@ -361,7 +574,11 @@ export async function materializeSkillReferences(skills, options = {}) {
|
|
|
361
574
|
await rename(item.backup, item.path);
|
|
362
575
|
}
|
|
363
576
|
catch (rollbackError) {
|
|
364
|
-
throw new
|
|
577
|
+
throw new DomainError('domain.materializeFailedRollbackItem', {
|
|
578
|
+
error: errorMessage(error),
|
|
579
|
+
path: item.path,
|
|
580
|
+
rollback: errorMessage(rollbackError),
|
|
581
|
+
});
|
|
365
582
|
}
|
|
366
583
|
throw error;
|
|
367
584
|
}
|
|
@@ -392,11 +609,15 @@ export async function materializeSkillReferences(skills, options = {}) {
|
|
|
392
609
|
await writeState(state);
|
|
393
610
|
}
|
|
394
611
|
catch (rollbackError) {
|
|
395
|
-
|
|
612
|
+
// Technical fragment only — outer DomainError is localized via formatAppError.
|
|
613
|
+
rollbackErrors.push(`state: ${errorMessage(rollbackError)}`);
|
|
396
614
|
}
|
|
397
615
|
}
|
|
398
616
|
if (rollbackErrors.length) {
|
|
399
|
-
throw new
|
|
617
|
+
throw new DomainError('domain.materializeFailedRollback', {
|
|
618
|
+
error: errorMessage(error),
|
|
619
|
+
rollback: rollbackErrors.join('; '),
|
|
620
|
+
});
|
|
400
621
|
}
|
|
401
622
|
throw error;
|
|
402
623
|
}
|
|
@@ -405,7 +626,7 @@ export async function materializeSkillReferences(skills, options = {}) {
|
|
|
405
626
|
for (const item of prepared) {
|
|
406
627
|
if (committed || !(await pathPresent(item.backup))) {
|
|
407
628
|
await rm(item.workspace, { recursive: true, force: true }).catch((error) => {
|
|
408
|
-
|
|
629
|
+
domainNotify('domain.warnMaterializeTempCleanup', { error: errorMessage(error) });
|
|
409
630
|
});
|
|
410
631
|
}
|
|
411
632
|
}
|
|
@@ -414,12 +635,12 @@ export async function materializeSkillReferences(skills, options = {}) {
|
|
|
414
635
|
}
|
|
415
636
|
export async function removeSkillLocations(skills) {
|
|
416
637
|
const paths = collectionPaths();
|
|
417
|
-
const unique = await validateSkillLocations(skills, '
|
|
638
|
+
const unique = await validateSkillLocations(skills, 'delete');
|
|
418
639
|
for (const [path, skill] of unique) {
|
|
419
640
|
if (skill.fromCollection) {
|
|
420
641
|
const target = join(paths.skills, assertSkillName(skill.name));
|
|
421
642
|
if (!(await isExactSymlink(path, target))) {
|
|
422
|
-
throw new
|
|
643
|
+
throw new DomainError('domain.collectionLinkChanged', { path });
|
|
423
644
|
}
|
|
424
645
|
}
|
|
425
646
|
}
|
|
@@ -433,21 +654,32 @@ export async function removeSkillLocations(skills) {
|
|
|
433
654
|
}
|
|
434
655
|
export async function installMergedCollectionSkill(name, workspace, source) {
|
|
435
656
|
const paths = collectionPaths();
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
await
|
|
439
|
-
|
|
657
|
+
const skillName = assertSkillName(name);
|
|
658
|
+
const target = join(paths.skills, skillName);
|
|
659
|
+
if (!(await pathPresent(target))) {
|
|
660
|
+
throw new DomainError('domain.mergeNotValidSkill', { name: skillName });
|
|
661
|
+
}
|
|
440
662
|
await validateSkillTree(workspace);
|
|
441
|
-
await
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
663
|
+
const transaction = await mkdtemp(join(paths.local, `.merge-${skillName}-`));
|
|
664
|
+
const staged = join(transaction, 'tree');
|
|
665
|
+
try {
|
|
666
|
+
await mkdir(staged, { recursive: true });
|
|
667
|
+
await copyDirectoryContents(workspace, staged);
|
|
668
|
+
if (!(await exists(join(staged, 'SKILL.md')))) {
|
|
669
|
+
throw new DomainError('domain.mergeNotValidSkill', { name: skillName });
|
|
670
|
+
}
|
|
671
|
+
const metadata = await readMetadata(skillName);
|
|
672
|
+
metadata.description = (await readSkill(staged)).description;
|
|
673
|
+
metadata.source = source;
|
|
674
|
+
await replaceCollectionSkill({
|
|
675
|
+
name: skillName,
|
|
676
|
+
staged,
|
|
677
|
+
metadata,
|
|
678
|
+
commitMessage: `update ${skillName}`,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
finally {
|
|
682
|
+
await rm(transaction, { recursive: true, force: true }).catch(() => { });
|
|
683
|
+
}
|
|
452
684
|
}
|
|
453
685
|
//# sourceMappingURL=collection-write.js.map
|