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,12 +1,24 @@
|
|
|
1
|
-
import { cp, lstat, mkdir,
|
|
2
|
-
import {
|
|
3
|
-
import { join, relative, resolve, sep } from 'node:path';
|
|
1
|
+
import { cp, lstat, mkdir, realpath, rename, rm, symlink } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
4
3
|
import { parseArgs } from 'node:util';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { noPresentAgentsError, PROJECT_SKILL_DIRS, agentGlobalPath, agentProjectPath, assertRelativePath, classifyCollectionMatch, collectionPaths, commitCollection, discoverSkills, exists, isExactSymlink, isGitSource, listCollection, listGlobalGroups, listPresentAgents, pathPresent, readMetadata, readState, resolveIncomingProvenance, sanitizeTerminal, writeState, } from '../domain/core.js';
|
|
5
|
+
import { installCollectionSkill, registerCollectionLinks, } from '../domain/collection-write.js';
|
|
6
|
+
import { canonicalizePath, isPhysicalSelfInstall, resolveCrossAgentInstallPlan, } from '../domain/cross-agent-install.js';
|
|
7
|
+
import { DomainError } from '../domain/errors.js';
|
|
7
8
|
import { matchesSkill } from '../domain/skill-query.js';
|
|
8
9
|
import { cloneGitSource } from '../domain/git.js';
|
|
9
10
|
import { collectionMatchLabels } from '../ui/collection-match.js';
|
|
11
|
+
import { t } from '../i18n/index.js';
|
|
12
|
+
export function formatSkillIdentity(meta) {
|
|
13
|
+
const source = meta.source;
|
|
14
|
+
// Local / path-only: show the path once (do not also append as /suffix).
|
|
15
|
+
if (source.type === 'local' || (!source.url && !source.id && source.path)) {
|
|
16
|
+
return sanitizeTerminal(source.path || source.type || 'local');
|
|
17
|
+
}
|
|
18
|
+
const base = source.url || source.id || source.type;
|
|
19
|
+
const path = source.path && source.path !== '.' ? `/${source.path}` : '';
|
|
20
|
+
return sanitizeTerminal(`${String(base).replace(/\/$/, '')}${path}`);
|
|
21
|
+
}
|
|
10
22
|
function present() {
|
|
11
23
|
return import('../ui/prompts/present.js');
|
|
12
24
|
}
|
|
@@ -14,239 +26,247 @@ function gitSkillDisplayPath(skill, gitContext) {
|
|
|
14
26
|
const sourcePath = assertRelativePath(relative(gitContext.repository, skill.path).split(sep).join('/'));
|
|
15
27
|
const ref = gitContext.source.ref ? `#${gitContext.source.ref}` : '';
|
|
16
28
|
const status = skill.collectionStatus
|
|
17
|
-
? ` · ${collectionMatchLabels[skill.collectionStatus]}`
|
|
29
|
+
? ` · ${collectionMatchLabels()[skill.collectionStatus]}`
|
|
18
30
|
: '';
|
|
19
31
|
return `${sanitizeTerminal(gitContext.source.url)}${sanitizeTerminal(ref)} · ${sanitizeTerminal(sourcePath)}${status}`;
|
|
20
32
|
}
|
|
21
|
-
function gitSkillMetadata(skill, gitContext, tags = []) {
|
|
33
|
+
async function gitSkillMetadata(skill, gitContext, tags = []) {
|
|
22
34
|
return {
|
|
23
35
|
name: skill.name,
|
|
24
36
|
description: skill.description,
|
|
25
37
|
tags,
|
|
26
38
|
note: '',
|
|
27
|
-
source:
|
|
28
|
-
...gitContext.source,
|
|
29
|
-
path: assertRelativePath(relative(gitContext.repository, skill.path).split(sep).join('/')),
|
|
30
|
-
},
|
|
39
|
+
source: await resolveIncomingProvenance(skill, gitContext),
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
|
-
function annotateGitCollectionStatus(skills, gitContext, collection) {
|
|
34
|
-
|
|
42
|
+
async function annotateGitCollectionStatus(skills, gitContext, collection) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const skill of skills) {
|
|
35
45
|
const sameName = collection.find((collected) => collected.name.toLowerCase() === skill.name.toLowerCase());
|
|
36
|
-
if (!sameName)
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
if (!sameName) {
|
|
47
|
+
out.push(skill);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
out.push({
|
|
39
51
|
...skill,
|
|
40
|
-
collectionStatus: classifyCollectionMatch(sameName, gitSkillMetadata(skill, gitContext)),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
52
|
+
collectionStatus: await classifyCollectionMatch(sameName, await gitSkillMetadata(skill, gitContext)),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
43
56
|
}
|
|
57
|
+
/** Write only — caller owns post-write commitCollection (and success messaging). */
|
|
44
58
|
async function importLocalSkill(skill, allowReplace, tags = []) {
|
|
45
|
-
const paths = collectionPaths();
|
|
46
59
|
const selectedPath = resolve(skill.path);
|
|
47
60
|
const selectedStats = await lstat(selectedPath);
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return false;
|
|
52
|
-
const provenance = await provenanceFromKnownLocks(skill);
|
|
53
|
-
await validateSkillTree(source);
|
|
54
|
-
if (await pathPresent(target)) {
|
|
55
|
-
if (!allowReplace) {
|
|
56
|
-
throw new Error(`收藏夹已存在同名技能:${skill.name},请确认后使用 --replace`);
|
|
57
|
-
}
|
|
58
|
-
await ensureCollection();
|
|
59
|
-
const transaction = await mkdtemp(join(paths.local, `.prepare-${skill.name}-`));
|
|
60
|
-
const staged = join(transaction, 'tree');
|
|
61
|
-
try {
|
|
62
|
-
await cp(source, staged, { recursive: true, errorOnExist: true });
|
|
63
|
-
await replaceCollectionSkill({
|
|
64
|
-
name: skill.name,
|
|
65
|
-
staged,
|
|
66
|
-
metadata: {
|
|
67
|
-
name: skill.name,
|
|
68
|
-
description: skill.description,
|
|
69
|
-
tags,
|
|
70
|
-
note: '',
|
|
71
|
-
source: provenance,
|
|
72
|
-
},
|
|
73
|
-
local: {
|
|
74
|
-
source,
|
|
75
|
-
selectedPath,
|
|
76
|
-
selectedWasSymlink: selectedStats.isSymbolicLink(),
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
await rm(transaction, { recursive: true, force: true });
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
await ensureCollection();
|
|
86
|
-
await moveDirectory(source, target);
|
|
87
|
-
try {
|
|
88
|
-
await symlink(target, source, 'dir');
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
await moveDirectory(target, source);
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
await writeMetadata({
|
|
61
|
+
const originPath = selectedStats.isSymbolicLink() ? await realpath(selectedPath) : selectedPath;
|
|
62
|
+
const provenance = await resolveIncomingProvenance(skill);
|
|
63
|
+
const metadata = {
|
|
95
64
|
name: skill.name,
|
|
96
65
|
description: skill.description,
|
|
97
66
|
tags,
|
|
98
67
|
note: '',
|
|
99
68
|
source: provenance,
|
|
69
|
+
};
|
|
70
|
+
const result = await installCollectionSkill({
|
|
71
|
+
name: skill.name,
|
|
72
|
+
sourceTree: originPath,
|
|
73
|
+
metadata,
|
|
74
|
+
allowReplace,
|
|
75
|
+
local: {
|
|
76
|
+
originPath,
|
|
77
|
+
selectedPath,
|
|
78
|
+
selectedWasSymlink: selectedStats.isSymbolicLink(),
|
|
79
|
+
},
|
|
80
|
+
commit: false,
|
|
81
|
+
commitMessage: `import ${skill.name}`,
|
|
100
82
|
});
|
|
101
|
-
|
|
102
|
-
const baseline = baselinePath(skill.name);
|
|
103
|
-
await rm(baseline, { recursive: true, force: true });
|
|
104
|
-
await cp(target, baseline, { recursive: true });
|
|
105
|
-
}
|
|
106
|
-
const links = [{ skill: skill.name, path: source, kind: 'origin' }];
|
|
107
|
-
if (selectedStats.isSymbolicLink()) {
|
|
108
|
-
links.push({ skill: skill.name, path: selectedPath, kind: 'dependent' });
|
|
109
|
-
}
|
|
110
|
-
await registerCollectionLinks(links);
|
|
111
|
-
return true;
|
|
83
|
+
return result === 'installed' || result === 'installed-uncommitted';
|
|
112
84
|
}
|
|
85
|
+
/** Write only — caller owns post-write commitCollection (and success messaging). */
|
|
113
86
|
async function importRemoteSkill(skill, gitContext, allowReplace, tags = []) {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
await ensureCollection();
|
|
126
|
-
const transaction = await mkdtemp(join(paths.local, `.prepare-${skill.name}-`));
|
|
127
|
-
const staged = join(transaction, 'tree');
|
|
128
|
-
try {
|
|
129
|
-
await cp(skill.path, staged, { recursive: true, errorOnExist: true });
|
|
130
|
-
await replaceCollectionSkill({
|
|
131
|
-
name: skill.name,
|
|
132
|
-
staged,
|
|
133
|
-
metadata,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
await rm(transaction, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
await ensureCollection();
|
|
142
|
-
await cp(skill.path, target, { recursive: true, errorOnExist: true });
|
|
143
|
-
await writeMetadata(metadata);
|
|
144
|
-
return true;
|
|
87
|
+
const metadata = await gitSkillMetadata(skill, gitContext, tags);
|
|
88
|
+
const result = await installCollectionSkill({
|
|
89
|
+
name: skill.name,
|
|
90
|
+
sourceTree: skill.path,
|
|
91
|
+
metadata,
|
|
92
|
+
allowReplace,
|
|
93
|
+
commit: false,
|
|
94
|
+
commitMessage: `import ${skill.name}`,
|
|
95
|
+
});
|
|
96
|
+
return result === 'installed' || result === 'installed-uncommitted';
|
|
145
97
|
}
|
|
146
98
|
export async function importRemoteSkillToCollection(source, skillName, options = {}) {
|
|
147
99
|
const gitContext = await cloneGitSource(source);
|
|
148
100
|
try {
|
|
149
101
|
const found = (await discoverSkills(gitContext.repository)).filter((skill) => skill.name.toLowerCase() === skillName.toLowerCase());
|
|
150
102
|
if (!found.length)
|
|
151
|
-
throw new
|
|
103
|
+
throw new DomainError('cmd.skillMissingInSource', { name: skillName });
|
|
152
104
|
if (found.length > 1)
|
|
153
|
-
throw new
|
|
105
|
+
throw new DomainError('cmd.skillDuplicateInSource', { name: skillName });
|
|
154
106
|
const skill = found[0];
|
|
155
|
-
const incoming = gitSkillMetadata(skill, gitContext);
|
|
107
|
+
const incoming = await gitSkillMetadata(skill, gitContext);
|
|
156
108
|
const target = join(collectionPaths().skills, skill.name);
|
|
157
109
|
const replacing = await pathPresent(target);
|
|
158
110
|
if (replacing) {
|
|
159
111
|
const current = await readMetadata(skill.name);
|
|
160
|
-
|
|
112
|
+
const match = await classifyCollectionMatch(current, incoming);
|
|
113
|
+
if (match === 'same-source') {
|
|
161
114
|
return { name: skill.name, status: 'unchanged' };
|
|
162
115
|
}
|
|
163
116
|
if (!options.replace) {
|
|
164
117
|
if (!options.confirmReplace) {
|
|
165
|
-
throw new
|
|
118
|
+
throw new DomainError(match === 'unverified-source'
|
|
119
|
+
? 'cmd.unverifiedSourceExists'
|
|
120
|
+
: 'cmd.conflictingSourceExists', { name: skill.name });
|
|
166
121
|
}
|
|
167
|
-
|
|
122
|
+
const allowed = await options.confirmReplace([
|
|
123
|
+
{ name: skill.name, match, current, incoming },
|
|
124
|
+
]);
|
|
125
|
+
if (!allowed) {
|
|
168
126
|
return { name: skill.name, status: 'cancelled' };
|
|
169
127
|
}
|
|
170
128
|
}
|
|
171
129
|
}
|
|
172
|
-
await importRemoteSkill(skill, gitContext, replacing, options.tags ?? []);
|
|
173
|
-
if (!
|
|
174
|
-
|
|
130
|
+
const wrote = await importRemoteSkill(skill, gitContext, replacing, options.tags ?? []);
|
|
131
|
+
if (!wrote)
|
|
132
|
+
return { name: skill.name, status: 'unchanged' };
|
|
133
|
+
// Soft-fail commit: warn already emitted; distinct from user cancel.
|
|
134
|
+
if (!(await commitCollection(`import ${skill.name}`))) {
|
|
135
|
+
return { name: skill.name, status: 'commit-failed' };
|
|
136
|
+
}
|
|
175
137
|
return { name: skill.name, status: 'imported' };
|
|
176
138
|
}
|
|
177
139
|
finally {
|
|
178
140
|
await rm(gitContext.temporary, { recursive: true, force: true });
|
|
179
141
|
}
|
|
180
142
|
}
|
|
181
|
-
|
|
182
|
-
if (!skills.length)
|
|
183
|
-
return { count: 0 };
|
|
184
|
-
let selected = skills;
|
|
185
|
-
let allowReplace = options.replace ?? false;
|
|
143
|
+
async function classifyImportReplacements(skills, gitContext) {
|
|
186
144
|
const paths = collectionPaths();
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
145
|
+
const sameSource = [];
|
|
146
|
+
const candidates = [];
|
|
147
|
+
for (const skill of skills) {
|
|
148
|
+
if (!(await pathPresent(join(paths.skills, skill.name))))
|
|
149
|
+
continue;
|
|
150
|
+
const current = await readMetadata(skill.name);
|
|
151
|
+
const incoming = gitContext
|
|
152
|
+
? await gitSkillMetadata(skill, gitContext, skill.tags ?? [])
|
|
153
|
+
: {
|
|
154
|
+
name: skill.name,
|
|
155
|
+
description: skill.description,
|
|
156
|
+
tags: skill.tags ?? [],
|
|
157
|
+
note: skill.note ?? '',
|
|
158
|
+
source: await resolveIncomingProvenance(skill),
|
|
159
|
+
};
|
|
160
|
+
// Always re-classify at plan time; scan-time collectionStatus is display-only.
|
|
161
|
+
const match = await classifyCollectionMatch(current, incoming);
|
|
162
|
+
if (match === 'same-source') {
|
|
163
|
+
sameSource.push(skill.name);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
candidates.push({ name: skill.name, match, current, incoming });
|
|
191
167
|
}
|
|
192
|
-
|
|
168
|
+
return { sameSource, candidates };
|
|
169
|
+
}
|
|
170
|
+
export function defaultReplaceConfirmMessage(candidates) {
|
|
171
|
+
if (candidates.length === 1) {
|
|
172
|
+
const item = candidates[0];
|
|
173
|
+
return {
|
|
174
|
+
message: t('cmd.replaceIdentityConfirm', {
|
|
175
|
+
name: item.name,
|
|
176
|
+
from: formatSkillIdentity(item.current),
|
|
177
|
+
to: formatSkillIdentity(item.incoming),
|
|
178
|
+
}),
|
|
179
|
+
details: [collectionMatchLabels()[item.match]],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
message: t('cmd.replaceSameNameConfirm', {
|
|
184
|
+
names: candidates.map((c) => c.name).join(t('common.listSep')),
|
|
185
|
+
}),
|
|
186
|
+
details: candidates.map((c) => `${c.name}: ${formatSkillIdentity(c.current)} → ${formatSkillIdentity(c.incoming)} · ${collectionMatchLabels()[c.match]}`),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Shared replace confirm for CLI default, browser, and search. */
|
|
190
|
+
export async function confirmCollectionReplace(candidates) {
|
|
191
|
+
const { message, details } = defaultReplaceConfirmMessage(candidates);
|
|
192
|
+
return (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
193
|
+
title: t('cmd.replaceCollectionTitle'),
|
|
194
|
+
message,
|
|
195
|
+
details,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async function resolveImportSelection(skills, options, gitContext) {
|
|
199
|
+
let selected = skills;
|
|
200
|
+
const replaceNames = new Set();
|
|
201
|
+
if (options.replace) {
|
|
202
|
+
for (const skill of selected)
|
|
203
|
+
replaceNames.add(skill.name);
|
|
204
|
+
}
|
|
205
|
+
const { sameSource, candidates } = await classifyImportReplacements(selected, gitContext);
|
|
206
|
+
const sameSourceNames = new Set(sameSource);
|
|
207
|
+
selected = selected.filter((skill) => !sameSourceNames.has(skill.name));
|
|
208
|
+
if (candidates.length && !options.replace) {
|
|
193
209
|
if (!process.stdin.isTTY || options.yes) {
|
|
194
|
-
throw new
|
|
195
|
-
|
|
196
|
-
allowReplace = options.confirmReplace
|
|
197
|
-
? await options.confirmReplace(conflicts)
|
|
198
|
-
: await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
199
|
-
title: '确认',
|
|
200
|
-
message: `替换同名收藏 ${conflicts.join(', ')} 吗?`,
|
|
210
|
+
throw new DomainError('cmd.conflictsExistReplace', {
|
|
211
|
+
names: candidates.map((c) => c.name).join(t('common.listSep')),
|
|
201
212
|
});
|
|
202
|
-
|
|
203
|
-
|
|
213
|
+
}
|
|
214
|
+
const confirm = options.confirmReplace
|
|
215
|
+
? await options.confirmReplace(candidates)
|
|
216
|
+
: await confirmCollectionReplace(candidates);
|
|
217
|
+
if (!confirm) {
|
|
218
|
+
const blocked = new Set(candidates.map((c) => c.name));
|
|
219
|
+
selected = selected.filter((skill) => !blocked.has(skill.name));
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
for (const c of candidates)
|
|
223
|
+
replaceNames.add(c.name);
|
|
204
224
|
}
|
|
205
225
|
}
|
|
226
|
+
return { selected, replaceNames };
|
|
227
|
+
}
|
|
228
|
+
export async function importSkillsToCollection(skills, options = {}) {
|
|
229
|
+
if (!skills.length)
|
|
230
|
+
return { count: 0 };
|
|
231
|
+
const { selected, replaceNames } = await resolveImportSelection(skills, options);
|
|
206
232
|
if (!selected.length)
|
|
207
233
|
return { count: 0 };
|
|
208
|
-
|
|
234
|
+
const installed = [];
|
|
209
235
|
for (const skill of selected) {
|
|
210
|
-
if (await importLocalSkill(skill,
|
|
211
|
-
|
|
236
|
+
if (await importLocalSkill(skill, replaceNames.has(skill.name), options.tags ?? [])) {
|
|
237
|
+
installed.push(skill.name);
|
|
238
|
+
}
|
|
212
239
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
240
|
+
if (!installed.length)
|
|
241
|
+
return { count: 0 };
|
|
242
|
+
// One commit point. Soft-fail: warn via domainNotify; no 已导入 line.
|
|
243
|
+
if (!(await commitCollection(`import ${installed.join(', ')}`))) {
|
|
244
|
+
return { count: installed.length, commitFailed: true };
|
|
216
245
|
}
|
|
217
|
-
|
|
246
|
+
if (!options.quiet)
|
|
247
|
+
console.log(t('cmd.importedCount', { count: installed.length }));
|
|
248
|
+
return { count: installed.length };
|
|
218
249
|
}
|
|
219
|
-
export async function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
250
|
+
export async function importGitSkillsToCollection(skills, gitContext, options = {}) {
|
|
251
|
+
if (!skills.length)
|
|
252
|
+
return { count: 0 };
|
|
253
|
+
const { selected, replaceNames } = await resolveImportSelection(skills, options, gitContext);
|
|
254
|
+
if (!selected.length)
|
|
255
|
+
return { count: 0 };
|
|
256
|
+
const installed = [];
|
|
257
|
+
for (const skill of selected) {
|
|
258
|
+
if (await importRemoteSkill(skill, gitContext, replaceNames.has(skill.name), options.tags ?? [])) {
|
|
259
|
+
installed.push(skill.name);
|
|
225
260
|
}
|
|
226
|
-
catch { }
|
|
227
261
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
:
|
|
232
|
-
const groups = [];
|
|
233
|
-
for (const { name, agent } of selected) {
|
|
234
|
-
const root = agent.global(home);
|
|
235
|
-
const skills = await Promise.all((await discoverSkills(root)).map(async (skill) => {
|
|
236
|
-
try {
|
|
237
|
-
const collected = collectedByPath.get(await realpath(skill.path));
|
|
238
|
-
return collected
|
|
239
|
-
? { ...collected, path: skill.path, fromCollection: true }
|
|
240
|
-
: { ...skill, fromCollection: false };
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
return { ...skill, fromCollection: false };
|
|
244
|
-
}
|
|
245
|
-
}));
|
|
246
|
-
skills.sort((a, b) => a.name.localeCompare(b.name));
|
|
247
|
-
groups.push({ agent: name, root, skills });
|
|
262
|
+
if (!installed.length)
|
|
263
|
+
return { count: 0 };
|
|
264
|
+
if (!(await commitCollection(`import ${installed.join(', ')}`))) {
|
|
265
|
+
return { count: installed.length, commitFailed: true };
|
|
248
266
|
}
|
|
249
|
-
|
|
267
|
+
if (!options.quiet)
|
|
268
|
+
console.log(t('cmd.importedCount', { count: installed.length }));
|
|
269
|
+
return { count: installed.length };
|
|
250
270
|
}
|
|
251
271
|
export async function commandImport(argv) {
|
|
252
272
|
const { values, positionals } = parseArgs({
|
|
@@ -261,9 +281,9 @@ export async function commandImport(argv) {
|
|
|
261
281
|
},
|
|
262
282
|
});
|
|
263
283
|
if (values.global && positionals.length)
|
|
264
|
-
throw new
|
|
284
|
+
throw new DomainError('cmd.cannotSourceAndGlobal');
|
|
265
285
|
if (positionals.length > 1)
|
|
266
|
-
throw new
|
|
286
|
+
throw new DomainError('cmd.oneImportRootOnly');
|
|
267
287
|
const input = positionals[0];
|
|
268
288
|
const localInput = input ? resolve(input) : undefined;
|
|
269
289
|
const gitContext = input && localInput && !(await exists(localInput)) && isGitSource(input)
|
|
@@ -277,13 +297,13 @@ export async function commandImport(argv) {
|
|
|
277
297
|
let globalGroups;
|
|
278
298
|
if (gitContext) {
|
|
279
299
|
const collection = await listCollection().catch(() => []);
|
|
280
|
-
skills = annotateGitCollectionStatus((await discoverSkills(gitContext.repository)).filter(isCollected), gitContext, collection);
|
|
300
|
+
skills = await annotateGitCollectionStatus((await discoverSkills(gitContext.repository)).filter(isCollected), gitContext, collection);
|
|
281
301
|
}
|
|
282
302
|
else if (values.global) {
|
|
283
303
|
if (!(values.agent?.length) && !(await listPresentAgents()).length) {
|
|
284
|
-
throw
|
|
304
|
+
throw noPresentAgentsError();
|
|
285
305
|
}
|
|
286
|
-
const groups = await
|
|
306
|
+
const groups = await listGlobalGroups(values.agent);
|
|
287
307
|
globalGroups = groups
|
|
288
308
|
.map((group) => ({
|
|
289
309
|
agent: group.agent,
|
|
@@ -296,24 +316,24 @@ export async function commandImport(argv) {
|
|
|
296
316
|
skills = (await discoverSkills(localInput || resolve('.'))).filter(isCollected);
|
|
297
317
|
}
|
|
298
318
|
if (!skills.length)
|
|
299
|
-
throw new
|
|
319
|
+
throw new DomainError('cmd.noSkillMd');
|
|
300
320
|
let selected = skills;
|
|
301
321
|
if (!values.all && (skills.length > 1 || !input)) {
|
|
302
322
|
if (!process.stdin.isTTY)
|
|
303
|
-
throw new
|
|
304
|
-
const groups = globalGroups ?? [{ agent: gitContext ? '
|
|
323
|
+
throw new DomainError('cmd.useAllOrInteractive');
|
|
324
|
+
const groups = globalGroups ?? [{ agent: gitContext ? t('common.git') : t('common.local'), skills }];
|
|
305
325
|
selected = await (await present()).promptSkillGroups(groups, globalGroups
|
|
306
|
-
? '
|
|
326
|
+
? t('cmd.scanGlobalSkills')
|
|
307
327
|
: !input
|
|
308
|
-
? '
|
|
309
|
-
: '
|
|
328
|
+
? t('cmd.selectRepoSkills')
|
|
329
|
+
: t('cmd.foundSkills'));
|
|
310
330
|
}
|
|
311
331
|
if (!selected.length)
|
|
312
332
|
return;
|
|
313
333
|
let importTags = [];
|
|
314
334
|
if (!values.yes) {
|
|
315
335
|
if (!process.stdin.isTTY)
|
|
316
|
-
throw new
|
|
336
|
+
throw new DomainError('cmd.useYesToConfirmImport');
|
|
317
337
|
const existingTags = [...new Set((await listCollection().catch(() => []))
|
|
318
338
|
.flatMap((skill) => skill.tags))]
|
|
319
339
|
.sort((a, b) => a.localeCompare(b));
|
|
@@ -327,40 +347,19 @@ export async function commandImport(argv) {
|
|
|
327
347
|
return;
|
|
328
348
|
importTags = review.tags;
|
|
329
349
|
}
|
|
330
|
-
let allowReplace = values.replace ?? false;
|
|
331
350
|
if (!gitContext) {
|
|
332
351
|
await importSkillsToCollection(selected, {
|
|
333
|
-
replace:
|
|
352
|
+
replace: values.replace ?? false,
|
|
334
353
|
yes: values.yes ?? false,
|
|
335
354
|
tags: importTags,
|
|
336
355
|
});
|
|
337
356
|
return;
|
|
338
357
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (conflicts.length && !allowReplace) {
|
|
347
|
-
if (!process.stdin.isTTY) {
|
|
348
|
-
throw new Error(`收藏夹已存在:${conflicts.join(', ')};确认后使用 --replace`);
|
|
349
|
-
}
|
|
350
|
-
allowReplace = await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
351
|
-
title: '确认',
|
|
352
|
-
message: `替换同名收藏 ${conflicts.join(', ')} 吗?`,
|
|
353
|
-
});
|
|
354
|
-
if (!allowReplace)
|
|
355
|
-
selected = selected.filter((skill) => !conflicts.includes(skill.name));
|
|
356
|
-
}
|
|
357
|
-
let count = 0;
|
|
358
|
-
for (const skill of selected) {
|
|
359
|
-
if (await importRemoteSkill(skill, gitContext, allowReplace, importTags))
|
|
360
|
-
count++;
|
|
361
|
-
}
|
|
362
|
-
await commitCollection(`import ${selected.map((skill) => skill.name).join(', ')}`);
|
|
363
|
-
console.log(`已导入 ${count} 个技能。`);
|
|
358
|
+
await importGitSkillsToCollection(selected, gitContext, {
|
|
359
|
+
replace: values.replace ?? false,
|
|
360
|
+
yes: values.yes ?? false,
|
|
361
|
+
tags: importTags,
|
|
362
|
+
});
|
|
364
363
|
}
|
|
365
364
|
finally {
|
|
366
365
|
if (gitContext)
|
|
@@ -375,13 +374,13 @@ async function resolveTargets(values) {
|
|
|
375
374
|
let names = requestedAgents;
|
|
376
375
|
if (!names.length) {
|
|
377
376
|
if (!process.stdin.isTTY)
|
|
378
|
-
throw new
|
|
377
|
+
throw new DomainError('cmd.globalNeedsAgent');
|
|
379
378
|
const presentNames = await listPresentAgents();
|
|
380
379
|
if (!presentNames.length)
|
|
381
|
-
throw
|
|
382
|
-
names = await (await present()).promptChoicesMany(presentNames.map((name) => ({ label: name, value: name })), '
|
|
380
|
+
throw noPresentAgentsError();
|
|
381
|
+
names = await (await present()).promptChoicesMany(presentNames.map((name) => ({ label: name, value: name })), t('cmd.selectGlobalAgent'));
|
|
383
382
|
if (!names.length)
|
|
384
|
-
throw
|
|
383
|
+
throw noPresentAgentsError();
|
|
385
384
|
}
|
|
386
385
|
return [...new Set(names.map((name) => agentGlobalPath(name)))];
|
|
387
386
|
}
|
|
@@ -398,7 +397,7 @@ async function resolveTargets(values) {
|
|
|
398
397
|
return unique.length ? unique : [resolve('.agents/skills')];
|
|
399
398
|
if (!process.stdin.isTTY)
|
|
400
399
|
return [resolve('.agents/skills')];
|
|
401
|
-
return (await present()).promptChoicesMany(unique.map((path) => ({ label: relative(process.cwd(), path), value: path })), '
|
|
400
|
+
return (await present()).promptChoicesMany(unique.map((path) => ({ label: relative(process.cwd(), path), value: path })), t('cmd.multipleAgentDirs'));
|
|
402
401
|
}
|
|
403
402
|
async function selectCollectionSkills(names) {
|
|
404
403
|
const skills = await listCollection();
|
|
@@ -410,31 +409,31 @@ async function selectCollectionSkills(names) {
|
|
|
410
409
|
const found = new Set(selected.map((skill) => skill.name));
|
|
411
410
|
const missing = names.filter((name) => !found.has(name));
|
|
412
411
|
if (missing.length)
|
|
413
|
-
throw new
|
|
412
|
+
throw new DomainError('cmd.missingInCollection', { names: missing.join(', ') });
|
|
414
413
|
return selected;
|
|
415
414
|
}
|
|
416
415
|
if (!process.stdin.isTTY)
|
|
417
|
-
throw new
|
|
416
|
+
throw new DomainError('cmd.specifySkillNames');
|
|
418
417
|
if (!skills.length) {
|
|
419
418
|
let source;
|
|
420
419
|
const ui = await present();
|
|
421
420
|
source = await ui.promptChoice([
|
|
422
|
-
{ label: '
|
|
423
|
-
{ label: '
|
|
424
|
-
{ label: '
|
|
425
|
-
], '
|
|
421
|
+
{ label: t('cmd.scanCurrentDir'), value: 'current' },
|
|
422
|
+
{ label: t('cmd.scanGlobalAgents'), value: 'global' },
|
|
423
|
+
{ label: t('cmd.enterPathOrGit'), value: 'custom' },
|
|
424
|
+
], t('cmd.emptyCollectionImportWhere'));
|
|
426
425
|
if (source === 'custom')
|
|
427
|
-
source = await ui.promptText('
|
|
426
|
+
source = await ui.promptText(t('cmd.pathOrGitPrompt'));
|
|
428
427
|
if (!source)
|
|
429
428
|
return [];
|
|
430
429
|
await commandImport(source === 'global' ? ['-g'] : source === 'current' ? [] : [source]);
|
|
431
430
|
return listCollection();
|
|
432
431
|
}
|
|
433
432
|
const ui = await present();
|
|
434
|
-
const query = await ui.promptText('
|
|
433
|
+
const query = await ui.promptText(t('cmd.searchCollection'));
|
|
435
434
|
if (query === undefined)
|
|
436
435
|
return [];
|
|
437
|
-
return ui.promptSkills(skills.filter((skill) => matchesSkill(skill, query)), '
|
|
436
|
+
return ui.promptSkills(skills.filter((skill) => matchesSkill(skill, query)), t('cmd.selectSkills'));
|
|
438
437
|
}
|
|
439
438
|
export async function addSkillsToProject(skills, values = {}) {
|
|
440
439
|
if (!skills.length)
|
|
@@ -450,7 +449,7 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
450
449
|
for (const skill of skills) {
|
|
451
450
|
const target = join(targetRoot, skill.name);
|
|
452
451
|
if (target === resolve(skill.path) || target.startsWith(`${resolve(skill.path)}${sep}`)) {
|
|
453
|
-
throw new
|
|
452
|
+
throw new DomainError('cmd.targetPointsSelf', { target });
|
|
454
453
|
}
|
|
455
454
|
if (await pathPresent(target)) {
|
|
456
455
|
if (await isExactSymlink(target, skill.path))
|
|
@@ -460,14 +459,14 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
460
459
|
replace = values.confirmReplace
|
|
461
460
|
? await values.confirmReplace(target)
|
|
462
461
|
: await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
463
|
-
title: '
|
|
464
|
-
message:
|
|
462
|
+
title: t('common.confirm'),
|
|
463
|
+
message: t('cmd.replaceTargetConfirm', { target }),
|
|
465
464
|
});
|
|
466
465
|
}
|
|
467
466
|
if (!replace) {
|
|
468
467
|
if (process.stdin.isTTY && !values.yes)
|
|
469
468
|
continue;
|
|
470
|
-
throw new
|
|
469
|
+
throw new DomainError('cmd.targetExistsReplace', { target });
|
|
471
470
|
}
|
|
472
471
|
await rm(target, { recursive: true });
|
|
473
472
|
}
|
|
@@ -484,8 +483,163 @@ export async function addSkillsToProject(skills, values = {}) {
|
|
|
484
483
|
}
|
|
485
484
|
await registerCollectionLinks(usageLinks);
|
|
486
485
|
if (!values.quiet) {
|
|
487
|
-
console.log(
|
|
486
|
+
console.log(t('cmd.addedSkillsToDirs', {
|
|
487
|
+
skills: addedSkills.size,
|
|
488
|
+
dirs: addedTargets.size,
|
|
489
|
+
copy: values.copy ? t('cmd.addedCopySuffix') : '',
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
return { count: addedSkills.size, targetCount: addedTargets.size };
|
|
493
|
+
}
|
|
494
|
+
/** Move existing target aside, create symlink, restore on failure. */
|
|
495
|
+
async function replacePathWithSymlink(target, linkTarget) {
|
|
496
|
+
const absolute = resolve(target);
|
|
497
|
+
const parent = dirname(absolute);
|
|
498
|
+
await mkdir(parent, { recursive: true });
|
|
499
|
+
let backup;
|
|
500
|
+
if (await pathPresent(absolute)) {
|
|
501
|
+
backup = join(parent, `.iskills-replace-${basename(absolute)}-${process.pid}-${Date.now()}`);
|
|
502
|
+
await rename(absolute, backup);
|
|
503
|
+
}
|
|
504
|
+
try {
|
|
505
|
+
await symlink(linkTarget, absolute, 'dir');
|
|
506
|
+
if (backup)
|
|
507
|
+
await rm(backup, { recursive: true, force: true });
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
await rm(absolute, { recursive: true, force: true }).catch(() => { });
|
|
511
|
+
if (backup)
|
|
512
|
+
await rename(backup, absolute);
|
|
513
|
+
throw error;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Drop any collection links recorded at `paths`, then append usage links for successful installs.
|
|
518
|
+
*/
|
|
519
|
+
async function rewriteUsageLinksAtTargets(clearPaths, add) {
|
|
520
|
+
if (!clearPaths.length && !add.length)
|
|
521
|
+
return;
|
|
522
|
+
const clear = new Set(clearPaths.map((path) => resolve(path)));
|
|
523
|
+
const state = await readState();
|
|
524
|
+
const links = state.links.filter((link) => !clear.has(resolve(link.path)));
|
|
525
|
+
for (const item of add) {
|
|
526
|
+
links.push({ skill: item.skill, path: resolve(item.path), kind: 'usage' });
|
|
527
|
+
}
|
|
528
|
+
await writeState({ ...state, links });
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Install skills from one agent location into other agent roots (symlink only).
|
|
532
|
+
* Collection-backed refs link to the collection skill path; local dirs link to A.
|
|
533
|
+
* Conflict handling aligns with add (best-effort); replace is confirmed once for all conflicts.
|
|
534
|
+
*/
|
|
535
|
+
export async function installSkillsAcrossAgents(skills, targetRoots, options = {}) {
|
|
536
|
+
if (!skills.length || !targetRoots.length)
|
|
537
|
+
return { count: 0, targetCount: 0 };
|
|
538
|
+
const plans = [];
|
|
539
|
+
for (const skill of skills) {
|
|
540
|
+
const plan = await resolveCrossAgentInstallPlan(skill);
|
|
541
|
+
if (!plan) {
|
|
542
|
+
throw new DomainError('cmd.crossAgentUnsupported', { name: skill.name, path: skill.path });
|
|
543
|
+
}
|
|
544
|
+
plans.push(plan);
|
|
545
|
+
}
|
|
546
|
+
// Dedupe target roots by canonical identity (symlink aliases collapse).
|
|
547
|
+
const rootsByCanon = new Map();
|
|
548
|
+
for (const root of targetRoots) {
|
|
549
|
+
const absolute = resolve(root);
|
|
550
|
+
await mkdir(absolute, { recursive: true });
|
|
551
|
+
const canon = await canonicalizePath(absolute);
|
|
552
|
+
if (!rootsByCanon.has(canon))
|
|
553
|
+
rootsByCanon.set(canon, absolute);
|
|
554
|
+
}
|
|
555
|
+
const roots = [...rootsByCanon.values()];
|
|
556
|
+
// One plan per absolute target path; reject ambiguous same-name sources.
|
|
557
|
+
const planByTarget = new Map();
|
|
558
|
+
for (const targetRoot of roots) {
|
|
559
|
+
for (const plan of plans) {
|
|
560
|
+
const target = resolve(join(targetRoot, plan.skill.name));
|
|
561
|
+
if (await isPhysicalSelfInstall(target, plan.linkTarget)) {
|
|
562
|
+
throw new DomainError('cmd.targetPointsSelf', { target });
|
|
563
|
+
}
|
|
564
|
+
if (target === resolve(plan.linkTarget) ||
|
|
565
|
+
target.startsWith(`${resolve(plan.linkTarget)}${sep}`)) {
|
|
566
|
+
throw new DomainError('cmd.targetPointsSelf', { target });
|
|
567
|
+
}
|
|
568
|
+
const existing = planByTarget.get(target);
|
|
569
|
+
if (existing) {
|
|
570
|
+
if (existing.linkTarget === plan.linkTarget)
|
|
571
|
+
continue;
|
|
572
|
+
throw new DomainError('cmd.crossAgentAmbiguousSource', {
|
|
573
|
+
name: plan.skill.name,
|
|
574
|
+
target,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
planByTarget.set(target, plan);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const work = [];
|
|
581
|
+
const conflicts = [];
|
|
582
|
+
for (const [target, plan] of planByTarget) {
|
|
583
|
+
if (await pathPresent(target)) {
|
|
584
|
+
if (await isExactSymlink(target, plan.linkTarget))
|
|
585
|
+
continue;
|
|
586
|
+
// Same physical tree via agent-root alias — never treat as replaceable conflict.
|
|
587
|
+
if (await isPhysicalSelfInstall(target, plan.linkTarget)) {
|
|
588
|
+
throw new DomainError('cmd.targetPointsSelf', { target });
|
|
589
|
+
}
|
|
590
|
+
conflicts.push(target);
|
|
591
|
+
}
|
|
592
|
+
work.push({ plan, target });
|
|
593
|
+
}
|
|
594
|
+
let replaceAll = options.replace ?? false;
|
|
595
|
+
if (conflicts.length && !replaceAll) {
|
|
596
|
+
if (options.confirmReplaceAll) {
|
|
597
|
+
replaceAll = await options.confirmReplaceAll(conflicts);
|
|
598
|
+
}
|
|
599
|
+
else if (process.stdin.isTTY) {
|
|
600
|
+
replaceAll = await (await import('../ui/overlay/static.js')).Modal.confirm({
|
|
601
|
+
title: t('cmd.replaceTargetTitle'),
|
|
602
|
+
message: t('cmd.replaceTargetsConfirm', { count: conflicts.length }),
|
|
603
|
+
details: conflicts,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
throw new DomainError('cmd.targetExistsReplace', { target: conflicts[0] ?? '' });
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
const conflictSet = new Set(conflicts);
|
|
611
|
+
const addedSkills = new Set();
|
|
612
|
+
const addedTargets = new Set();
|
|
613
|
+
const writtenPaths = [];
|
|
614
|
+
const usageAdds = [];
|
|
615
|
+
for (const item of work) {
|
|
616
|
+
const { plan, target } = item;
|
|
617
|
+
const isConflict = conflictSet.has(target);
|
|
618
|
+
if (isConflict && !replaceAll)
|
|
619
|
+
continue;
|
|
620
|
+
if (await pathPresent(target)) {
|
|
621
|
+
if (await isExactSymlink(target, plan.linkTarget))
|
|
622
|
+
continue;
|
|
623
|
+
if (await isPhysicalSelfInstall(target, plan.linkTarget)) {
|
|
624
|
+
throw new DomainError('cmd.targetPointsSelf', { target });
|
|
625
|
+
}
|
|
626
|
+
if (!isConflict && !replaceAll)
|
|
627
|
+
continue;
|
|
628
|
+
await replacePathWithSymlink(target, plan.linkTarget);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
await mkdir(dirname(target), { recursive: true });
|
|
632
|
+
await symlink(plan.linkTarget, target, 'dir');
|
|
633
|
+
}
|
|
634
|
+
writtenPaths.push(target);
|
|
635
|
+
if (plan.registerUsage) {
|
|
636
|
+
usageAdds.push({ skill: plan.skill.name, path: target });
|
|
637
|
+
}
|
|
638
|
+
addedSkills.add(plan.skill.name);
|
|
639
|
+
addedTargets.add(dirname(target));
|
|
488
640
|
}
|
|
641
|
+
// Clear stale link records at written paths, then register new usage rows.
|
|
642
|
+
await rewriteUsageLinksAtTargets(writtenPaths, usageAdds);
|
|
489
643
|
return { count: addedSkills.size, targetCount: addedTargets.size };
|
|
490
644
|
}
|
|
491
645
|
export async function commandAdd(argv) {
|