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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -7
  3. package/README.zh-CN.md +8 -6
  4. package/bin/iskills.js +10 -2
  5. package/dist/src/cli.js +22 -7
  6. package/dist/src/cli.js.map +1 -1
  7. package/dist/src/commands/browser-actions.d.ts +2 -0
  8. package/dist/src/commands/browser-actions.js +154 -49
  9. package/dist/src/commands/browser-actions.js.map +1 -1
  10. package/dist/src/commands/config.d.ts +5 -0
  11. package/dist/src/commands/config.js +23 -0
  12. package/dist/src/commands/config.js.map +1 -0
  13. package/dist/src/commands/create.js +12 -8
  14. package/dist/src/commands/create.js.map +1 -1
  15. package/dist/src/commands/index.d.ts +1 -0
  16. package/dist/src/commands/index.js +19 -77
  17. package/dist/src/commands/index.js.map +1 -1
  18. package/dist/src/commands/library.d.ts +46 -12
  19. package/dist/src/commands/library.js +384 -230
  20. package/dist/src/commands/library.js.map +1 -1
  21. package/dist/src/commands/search.js +17 -39
  22. package/dist/src/commands/search.js.map +1 -1
  23. package/dist/src/domain/collection-write.d.ts +53 -2
  24. package/dist/src/domain/collection-write.js +293 -61
  25. package/dist/src/domain/collection-write.js.map +1 -1
  26. package/dist/src/domain/core.d.ts +46 -5
  27. package/dist/src/domain/core.js +164 -58
  28. package/dist/src/domain/core.js.map +1 -1
  29. package/dist/src/domain/cross-agent-install.d.ts +32 -0
  30. package/dist/src/domain/cross-agent-install.js +147 -0
  31. package/dist/src/domain/cross-agent-install.js.map +1 -0
  32. package/dist/src/domain/errors.d.ts +20 -0
  33. package/dist/src/domain/errors.js +31 -0
  34. package/dist/src/domain/errors.js.map +1 -0
  35. package/dist/src/domain/git.js +15 -14
  36. package/dist/src/domain/git.js.map +1 -1
  37. package/dist/src/domain/user-config.d.ts +12 -0
  38. package/dist/src/domain/user-config.js +55 -0
  39. package/dist/src/domain/user-config.js.map +1 -0
  40. package/dist/src/i18n/en.d.ts +5 -0
  41. package/dist/src/i18n/en.js +423 -0
  42. package/dist/src/i18n/en.js.map +1 -0
  43. package/dist/src/i18n/index.d.ts +54 -0
  44. package/dist/src/i18n/index.js +164 -0
  45. package/dist/src/i18n/index.js.map +1 -0
  46. package/dist/src/i18n/zh.d.ts +409 -0
  47. package/dist/src/i18n/zh.js +423 -0
  48. package/dist/src/i18n/zh.js.map +1 -0
  49. package/dist/src/ui/browser/browse-capabilities.d.ts +26 -0
  50. package/dist/src/ui/browser/browse-capabilities.js +130 -0
  51. package/dist/src/ui/browser/browse-capabilities.js.map +1 -0
  52. package/dist/src/ui/browser/browser.js +205 -62
  53. package/dist/src/ui/browser/browser.js.map +1 -1
  54. package/dist/src/ui/browser/detail.js +1 -1
  55. package/dist/src/ui/browser/detail.js.map +1 -1
  56. package/dist/src/ui/browser/footer.js +26 -88
  57. package/dist/src/ui/browser/footer.js.map +1 -1
  58. package/dist/src/ui/browser/format.d.ts +13 -20
  59. package/dist/src/ui/browser/format.js +81 -144
  60. package/dist/src/ui/browser/format.js.map +1 -1
  61. package/dist/src/ui/browser/index.js +35 -3
  62. package/dist/src/ui/browser/index.js.map +1 -1
  63. package/dist/src/ui/browser/shortcut-help.js +3 -4
  64. package/dist/src/ui/browser/shortcut-help.js.map +1 -1
  65. package/dist/src/ui/browser/store.d.ts +4 -0
  66. package/dist/src/ui/browser/store.js +2 -0
  67. package/dist/src/ui/browser/store.js.map +1 -1
  68. package/dist/src/ui/browser/types.d.ts +19 -4
  69. package/dist/src/ui/collection-match.d.ts +1 -1
  70. package/dist/src/ui/collection-match.js +8 -5
  71. package/dist/src/ui/collection-match.js.map +1 -1
  72. package/dist/src/ui/components/framed-panel.d.ts +6 -1
  73. package/dist/src/ui/components/framed-panel.js +7 -4
  74. package/dist/src/ui/components/framed-panel.js.map +1 -1
  75. package/dist/src/ui/components/modal-panel.d.ts +4 -1
  76. package/dist/src/ui/components/modal-panel.js +8 -2
  77. package/dist/src/ui/components/modal-panel.js.map +1 -1
  78. package/dist/src/ui/components/mouse/index.d.ts +1 -1
  79. package/dist/src/ui/components/mouse/index.js +1 -1
  80. package/dist/src/ui/components/mouse/index.js.map +1 -1
  81. package/dist/src/ui/components/mouse/parse.d.ts +0 -7
  82. package/dist/src/ui/components/mouse/parse.js +0 -41
  83. package/dist/src/ui/components/mouse/parse.js.map +1 -1
  84. package/dist/src/ui/components/multi-select.js +3 -10
  85. package/dist/src/ui/components/multi-select.js.map +1 -1
  86. package/dist/src/ui/components/options.d.ts +2 -0
  87. package/dist/src/ui/components/options.js +9 -0
  88. package/dist/src/ui/components/options.js.map +1 -1
  89. package/dist/src/ui/components/select.js +1 -1
  90. package/dist/src/ui/components/select.js.map +1 -1
  91. package/dist/src/ui/components/tag-editor.d.ts +1 -2
  92. package/dist/src/ui/components/tag-editor.js +6 -4
  93. package/dist/src/ui/components/tag-editor.js.map +1 -1
  94. package/dist/src/ui/components/termcn.d.ts +1 -5
  95. package/dist/src/ui/components/termcn.js +1 -4
  96. package/dist/src/ui/components/termcn.js.map +1 -1
  97. package/dist/src/ui/config/index.d.ts +11 -0
  98. package/dist/src/ui/config/index.js +22 -0
  99. package/dist/src/ui/config/index.js.map +1 -0
  100. package/dist/src/ui/config/settings.d.ts +17 -0
  101. package/dist/src/ui/config/settings.js +126 -0
  102. package/dist/src/ui/config/settings.js.map +1 -0
  103. package/dist/src/ui/footer/resolve-footer.js +54 -36
  104. package/dist/src/ui/footer/resolve-footer.js.map +1 -1
  105. package/dist/src/ui/footer/types.d.ts +12 -2
  106. package/dist/src/ui/import/review.js +5 -8
  107. package/dist/src/ui/import/review.js.map +1 -1
  108. package/dist/src/ui/import/skill-select.js +15 -33
  109. package/dist/src/ui/import/skill-select.js.map +1 -1
  110. package/dist/src/ui/install/review.js +18 -19
  111. package/dist/src/ui/install/review.js.map +1 -1
  112. package/dist/src/ui/overlay/bridge.d.ts +1 -1
  113. package/dist/src/ui/prompts/present.d.ts +4 -2
  114. package/dist/src/ui/prompts/present.js +70 -5
  115. package/dist/src/ui/prompts/present.js.map +1 -1
  116. package/dist/src/ui/search/index.js +9 -7
  117. package/dist/src/ui/search/index.js.map +1 -1
  118. package/dist/src/ui/shell/app-shell.d.ts +1 -1
  119. package/dist/src/ui/shell/app-shell.js +1 -1
  120. package/dist/src/ui/shell/run.d.ts +0 -11
  121. package/dist/src/ui/shell/run.js +0 -43
  122. package/dist/src/ui/shell/run.js.map +1 -1
  123. package/dist/src/ui/shell/terminal.d.ts +0 -1
  124. package/dist/src/ui/shell/terminal.js +2 -1
  125. package/dist/src/ui/shell/terminal.js.map +1 -1
  126. package/dist/src/ui/skill-labels.d.ts +10 -9
  127. package/dist/src/ui/skill-labels.js +14 -10
  128. package/dist/src/ui/skill-labels.js.map +1 -1
  129. package/dist/src/ui/tui/hooks.d.ts +1 -13
  130. package/dist/src/ui/tui/hooks.js +1 -11
  131. package/dist/src/ui/tui/hooks.js.map +1 -1
  132. package/dist/src/ui/tui/index.d.ts +1 -1
  133. package/dist/src/ui/tui/index.js +1 -1
  134. package/dist/src/ui/tui/index.js.map +1 -1
  135. package/package.json +10 -11
  136. package/bin/patch-react-reconciler.mjs +0 -71
  137. package/dist/src/ui/components/confirm.d.ts +0 -6
  138. package/dist/src/ui/components/confirm.js +0 -22
  139. package/dist/src/ui/components/confirm.js.map +0 -1
  140. package/dist/src/ui/components/link.d.ts +0 -7
  141. package/dist/src/ui/components/link.js +0 -17
  142. package/dist/src/ui/components/link.js.map +0 -1
  143. package/dist/src/ui/components/modal.d.ts +0 -16
  144. package/dist/src/ui/components/modal.js +0 -58
  145. 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 Error(`收藏夹已存在同名技能:${skillName}`);
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 Error(`收藏夹已存在同名技能:${skillName}`);
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 Error(`原始位置已不是指向收藏夹的软链,已中止:${origin.path}`);
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
- await commitCollection(`import ${input.name}`);
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 Error(`导入失败:${errorMessage(error)};回滚失败:${errorMessage(rollbackError)}`);
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 Error(`当前范围没有使用技能:${name}`);
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 Error(`使用位置已不是预期软链,未删除:${link.path}`);
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 Error(`收藏夹中不存在:${name}`);
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 Error(`原始位置已不是指向收藏夹的软链,已中止:${origin.path}`);
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 Error('删除收藏需要确认');
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
- if (!quiet) {
218
- console.log(origin ? `已从收藏夹移除 ${name},并还回 ${origin.path}。` : `已从收藏夹移除 ${name}。`);
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 Error(`技能包含循环软链:${current}`);
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 Error(`技能包含无法解析的软链:${path}`);
445
+ throw new DomainError('domain.unresolvableSymlink', { path });
236
446
  }
237
447
  if (target !== root && !target.startsWith(`${root}${sep}`)) {
238
- throw new Error(`技能包含指向目录外的软链:${path}`);
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 Error(`副本仍包含软链:${path}`);
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 Error(`不能通过位置${operation}收藏夹内容:${path}`);
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 Error(`技能位置已不存在:${path}`);
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 Error(`技能位置已发生变化${operation === '删除' ? ',未删除' : ''}:${path}`);
488
+ throw new DomainError(operation === 'delete' ? 'domain.locationChangedNotDeleted' : 'domain.locationChanged', { path });
276
489
  }
277
490
  if (current.name !== skill.name) {
278
- throw new Error(`技能位置已发生变化${operation === '删除' ? ',未删除' : ''}:${path}`);
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 Error('操作已中断');
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 Error(`技能位置不是引用:${path}`);
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 Error(`技能引用无法解析:${path}`);
518
+ throw new DomainError('domain.referenceUnresolvable', { path });
306
519
  }
307
520
  if (!(await lstat(source)).isDirectory()) {
308
- throw new Error(`技能引用目标不是目录:${path}`);
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 Error(`复制结果中的技能名称已发生变化:${input.path}`);
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 Error(`转换失败:${errorMessage(error)};回滚失败:${item.path}: ${errorMessage(rollbackError)}`);
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
- rollbackErrors.push(`状态:${errorMessage(rollbackError)}`);
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 Error(`转换失败:${errorMessage(error)};回滚失败:${rollbackErrors.join(';')}`);
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
- console.error(`警告:转换临时目录清理失败:${errorMessage(error)}`);
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 Error(`收藏夹链接已发生变化,未删除:${path}`);
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 target = join(paths.skills, assertSkillName(name));
437
- const staged = join(paths.skills, `.${name}.update-${process.pid}`);
438
- await rm(staged, { recursive: true, force: true });
439
- await mkdir(staged, { recursive: true });
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 copyDirectoryContents(workspace, staged);
442
- if (!(await exists(join(staged, 'SKILL.md')))) {
443
- await rm(staged, { recursive: true, force: true });
444
- throw new Error(`合并结果不是有效技能:${name}`);
445
- }
446
- await rm(target, { recursive: true });
447
- await rename(staged, target);
448
- const metadata = await readMetadata(name);
449
- metadata.description = (await readSkill(target)).description;
450
- metadata.source = source;
451
- await writeMetadata(metadata);
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