@kafukatree/dsh-skill-manager 0.0.0-stage → 0.3.1
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/LICENSE-lucide.txt +43 -0
- package/README.md +44 -2
- package/agent-tool.mjs +118 -0
- package/client-bridge.mjs +307 -0
- package/client-entry.mjs +131 -0
- package/client.js +6769 -0
- package/control-icon.mjs +40 -0
- package/cordis.patch.yml +4 -0
- package/design/skill-manager.pen +798 -0
- package/design.css +320 -0
- package/design.mjs +629 -0
- package/dialogs.css +460 -0
- package/dialogs.mjs +1130 -0
- package/document-link.mjs +13 -0
- package/file-actions.mjs +62 -0
- package/file-view.mjs +384 -0
- package/header-scroll.css +90 -0
- package/header-scroll.mjs +121 -0
- package/host.mjs +460 -0
- package/icon.svg +6 -0
- package/import-archive.mjs +41 -0
- package/import-commit.mjs +247 -0
- package/import-family.mjs +213 -0
- package/import-files.mjs +186 -0
- package/import-github.mjs +168 -0
- package/import-limits.mjs +10 -0
- package/import-native.mjs +79 -0
- package/imports.mjs +209 -0
- package/inventory.mjs +62 -0
- package/library.mjs +1334 -0
- package/local-families.mjs +277 -0
- package/locale/en.json +16 -0
- package/locale/zh.json +16 -0
- package/management-view.mjs +158 -0
- package/mode-view.mjs +72 -0
- package/node_modules/pend/LICENSE +23 -0
- package/node_modules/pend/README.md +41 -0
- package/node_modules/pend/index.js +55 -0
- package/node_modules/pend/package.json +18 -0
- package/node_modules/pend/test.js +137 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +224 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +120 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +350 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +980 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/node_modules/yauzl/LICENSE +21 -0
- package/node_modules/yauzl/README.md +1015 -0
- package/node_modules/yauzl/crc32.js +45 -0
- package/node_modules/yauzl/fd-slicer.js +188 -0
- package/node_modules/yauzl/index.js +1096 -0
- package/node_modules/yauzl/package.json +40 -0
- package/package-files.mjs +244 -0
- package/package-view.mjs +375 -0
- package/package.css +131 -0
- package/package.json +75 -4
- package/removal.mjs +313 -0
- package/scripts/build.mjs +19 -0
- package/scripts/export-design.py +587 -0
- package/scripts/run-tests.mjs +14 -0
- package/skill-state.mjs +136 -0
- package/skills/skill-creator/SKILL.md +48 -0
- package/styles.mjs +10 -0
- package/surfaces.css +593 -0
- package/test/agent-tool.test.mjs +153 -0
- package/test/client-bridge.test.mjs +240 -0
- package/test/distribution.test.mjs +17 -0
- package/test/host.test.mjs +598 -0
- package/test/imports.test.mjs +491 -0
- package/test/inventory.test.mjs +144 -0
- package/test/library.test.mjs +785 -0
- package/test/local-families.test.mjs +220 -0
- package/test/management-view.test.mjs +102 -0
- package/test/mode-view.test.mjs +26 -0
- package/test/package-files.test.mjs +221 -0
- package/toolbar.css +228 -0
- package/typography.css +173 -0
- package/ui.css +399 -0
- package/ui.mjs +1545 -0
package/dialogs.mjs
ADDED
|
@@ -0,0 +1,1130 @@
|
|
|
1
|
+
import { designText } from './design.mjs';
|
|
2
|
+
import { controlIcon as icon } from './control-icon.mjs';
|
|
3
|
+
import { skillState } from './skill-state.mjs';
|
|
4
|
+
|
|
5
|
+
const text = designText;
|
|
6
|
+
const tools = [
|
|
7
|
+
{ id: 'claude', name: 'Claude Code', path: '.claude/skills', icon: 'square-terminal' },
|
|
8
|
+
{ id: 'codex', name: 'Codex', path: '.agents/skills', icon: 'braces' },
|
|
9
|
+
{ id: 'gemini', name: 'Gemini CLI', path: '.gemini/skills', icon: 'sparkles' },
|
|
10
|
+
];
|
|
11
|
+
const repositories = [
|
|
12
|
+
{ name: 'Anthropic Skills', path: 'anthropics/skills' },
|
|
13
|
+
{ name: 'Vercel Agent Skills', path: 'vercel-labs/agent-skills' },
|
|
14
|
+
{ name: 'Google Gemini Skills', path: 'google-gemini/gemini-skills' },
|
|
15
|
+
];
|
|
16
|
+
const recentlyViewed = new Set();
|
|
17
|
+
let dialogSequence = 0;
|
|
18
|
+
|
|
19
|
+
function el(tag, className, value) {
|
|
20
|
+
const element = document.createElement(tag);
|
|
21
|
+
if (className) element.className = className;
|
|
22
|
+
if (value != null) element.textContent = String(value);
|
|
23
|
+
return element;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function glyph(name, size = 18) {
|
|
27
|
+
const svg = icon(name, size);
|
|
28
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
29
|
+
svg.setAttribute('focusable', 'false');
|
|
30
|
+
return svg;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function button(label, action, style = '') {
|
|
34
|
+
const control = el('button', `smf-btn ${style}`, label);
|
|
35
|
+
control.type = 'button';
|
|
36
|
+
control.addEventListener('click', action);
|
|
37
|
+
return control;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function iconTile(name) {
|
|
41
|
+
const tile = el('span', 'smf-icon-tile');
|
|
42
|
+
tile.append(glyph(name));
|
|
43
|
+
return tile;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function itemCopy(name, detail, mono = true) {
|
|
47
|
+
const copy = el('span', 'smf-item-copy');
|
|
48
|
+
const title = el('span', 'smf-item-name', name);
|
|
49
|
+
title.title = name;
|
|
50
|
+
copy.append(title);
|
|
51
|
+
if (detail) {
|
|
52
|
+
const secondary = el('span', `smf-item-detail${mono ? ' smf-mono' : ''}`, detail);
|
|
53
|
+
secondary.title = detail;
|
|
54
|
+
copy.append(secondary);
|
|
55
|
+
}
|
|
56
|
+
return copy;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function sourceCard(iconName, name, path, trailing) {
|
|
60
|
+
const card = el('div', 'smf-source-card');
|
|
61
|
+
card.append(iconTile(iconName), itemCopy(name, path));
|
|
62
|
+
if (trailing) card.append(trailing);
|
|
63
|
+
return card;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function fieldLabel(label, id) {
|
|
67
|
+
const controlLabel = el('label', 'smf-label', label);
|
|
68
|
+
controlLabel.htmlFor = id;
|
|
69
|
+
return controlLabel;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function inputBox(control, iconName, hasChevron = false) {
|
|
73
|
+
const box = el('div', 'smf-input-box');
|
|
74
|
+
box.append(glyph(iconName, 17), control);
|
|
75
|
+
if (hasChevron) box.append(glyph('chevron-down', 15));
|
|
76
|
+
return box;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function basename(path) {
|
|
80
|
+
return String(path || '').split(/[\\/]/).filter(Boolean).pop() || '';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function directoryPath(directory) {
|
|
84
|
+
return directory?.displayPath || directory?.path || '';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function joinDisplayPath(directory, relative) {
|
|
88
|
+
const root = directoryPath(directory);
|
|
89
|
+
if (!root || !relative) return root;
|
|
90
|
+
const separator = root.includes('\\') && !root.includes('/') ? '\\' : '/';
|
|
91
|
+
return `${root.replace(/[\\/]$/, '')}${separator}${relative.replace(/[\\/]/g, separator)}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function githubUrl(input) {
|
|
95
|
+
const value = input.trim();
|
|
96
|
+
if (value.startsWith('github.com/')) return `https://${value}`;
|
|
97
|
+
if (/^[\w.-]+\/[\w.-]+(?:\/.*)?$/.test(value)) return `https://github.com/${value}`;
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function repositoryPath(url) {
|
|
102
|
+
return url.replace(/^https?:\/\/(?:www\.)?github\.com\//i, '').replace(/\/$/, '');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function fileTree(name, files, label = text('sm-r5-186', '压缩包内容')) {
|
|
106
|
+
const root = new Map();
|
|
107
|
+
for (const path of files) {
|
|
108
|
+
let directory = root;
|
|
109
|
+
for (const part of String(path).split(/[\\/]/).filter(part => part && part !== '.')) {
|
|
110
|
+
if (!directory.has(part)) directory.set(part, new Map());
|
|
111
|
+
directory = directory.get(part);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function folder(label, children, depth) {
|
|
116
|
+
const group = el('details', 'smf-tree-folder');
|
|
117
|
+
group.open = depth < 2;
|
|
118
|
+
const title = el('summary', 'smf-tree-line');
|
|
119
|
+
title.append(glyph(depth ? 'folder' : 'folder-open', depth ? 15 : 17), el('span', '', `${label}/`));
|
|
120
|
+
group.append(title);
|
|
121
|
+
const list = el('ul', 'smf-tree-list');
|
|
122
|
+
const entries = [...children.entries()].sort(([a], [b]) => {
|
|
123
|
+
if (a === 'SKILL.md') return -1;
|
|
124
|
+
if (b === 'SKILL.md') return 1;
|
|
125
|
+
return a.localeCompare(b);
|
|
126
|
+
});
|
|
127
|
+
for (const [key, descendants] of entries) {
|
|
128
|
+
const item = el('li');
|
|
129
|
+
if (descendants.size) item.append(folder(key, descendants, depth + 1));
|
|
130
|
+
else {
|
|
131
|
+
const line = el('span', 'smf-tree-line');
|
|
132
|
+
line.append(glyph('file-text', 15), el('span', '', key));
|
|
133
|
+
item.append(line);
|
|
134
|
+
}
|
|
135
|
+
list.append(item);
|
|
136
|
+
}
|
|
137
|
+
group.append(list);
|
|
138
|
+
return group;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const tree = el('div', 'smf-tree smf-mono');
|
|
142
|
+
tree.setAttribute('aria-label', label);
|
|
143
|
+
if (root.size) tree.append(folder(name, root, 0));
|
|
144
|
+
else tree.append(el('p', 'smf-empty', '压缩包中没有可预览的文件。'));
|
|
145
|
+
return tree;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function familyContents(family, files) {
|
|
149
|
+
const section = el('section', 'smf-family');
|
|
150
|
+
if (family.description) section.append(el('p', 'smf-family-description', family.description));
|
|
151
|
+
const heading = el('div', 'smf-section-heading smf-list-heading');
|
|
152
|
+
heading.append(el('h3', 'smf-label', '包内技能'), el('span', 'smf-count', `${family.members.length} 个技能`));
|
|
153
|
+
const members = el('ul', 'smf-choice-list smf-candidates smf-family-members');
|
|
154
|
+
members.setAttribute('aria-label', '包内技能');
|
|
155
|
+
members.tabIndex = 0;
|
|
156
|
+
for (const member of family.members) {
|
|
157
|
+
const row = el('li', 'smf-family-member');
|
|
158
|
+
const copy = itemCopy(member.name, member.description, false);
|
|
159
|
+
copy.append(el('code', 'smf-mono smf-member-path', member.entry));
|
|
160
|
+
row.append(copy);
|
|
161
|
+
if (member.invocation) row.append(el('span', 'smf-count', skillState(member).label));
|
|
162
|
+
members.append(row);
|
|
163
|
+
}
|
|
164
|
+
section.append(heading, members);
|
|
165
|
+
if (files.length) {
|
|
166
|
+
const details = el('details', 'smf-family-files');
|
|
167
|
+
details.append(el('summary', '', `查看全部 ${files.length} 个文件`));
|
|
168
|
+
details.addEventListener('toggle', () => {
|
|
169
|
+
if (details.open && details.childElementCount === 1) details.append(fileTree(family.id, files, '工具包文件'));
|
|
170
|
+
});
|
|
171
|
+
section.append(details);
|
|
172
|
+
}
|
|
173
|
+
return section;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function familyReceipt(result) {
|
|
177
|
+
const members = result.members || result.family.members;
|
|
178
|
+
const name = result.package?.label || result.family.name;
|
|
179
|
+
const count = result.memberCount ?? members.length;
|
|
180
|
+
let summary = `${result.replaced ? '已更新' : '已导入'}工具包「${name}」,共 ${count} 个技能`;
|
|
181
|
+
if (result.enabled === false) summary += ',工具包已停用';
|
|
182
|
+
else if (members.every(member => typeof member.enabled === 'boolean')) {
|
|
183
|
+
summary += `,其中 ${members.filter(member => skillState(member).model).length} 个允许 Agent 自动调用`;
|
|
184
|
+
}
|
|
185
|
+
if (result.familyRoot) summary += `。保存到 ${result.familyRoot}`;
|
|
186
|
+
return { name, members, summary };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function openFlow(container, api, { kind }, onChanged) {
|
|
190
|
+
const prefix = `skill-flow-${++dialogSequence}`;
|
|
191
|
+
const opener = document.activeElement;
|
|
192
|
+
const dialog = el('dialog', 'sm-flow sm-design');
|
|
193
|
+
dialog.setAttribute('aria-modal', 'true');
|
|
194
|
+
dialog.setAttribute('aria-labelledby', `${prefix}-title`);
|
|
195
|
+
container.append(dialog);
|
|
196
|
+
|
|
197
|
+
let active = true;
|
|
198
|
+
let operation = 0;
|
|
199
|
+
let writing = false;
|
|
200
|
+
let libraryPromise;
|
|
201
|
+
let library;
|
|
202
|
+
let directoryId;
|
|
203
|
+
let enabled = true;
|
|
204
|
+
let localSource = null;
|
|
205
|
+
let localLabel = '';
|
|
206
|
+
let manualPath = false;
|
|
207
|
+
let tool = tools[0];
|
|
208
|
+
let scope = 'user';
|
|
209
|
+
let url = `https://github.com/${repositories[0].path}`;
|
|
210
|
+
let source;
|
|
211
|
+
let listing;
|
|
212
|
+
let selected = new Set();
|
|
213
|
+
let query = '';
|
|
214
|
+
let filter = 'all';
|
|
215
|
+
let queue = [];
|
|
216
|
+
let index = 0;
|
|
217
|
+
let preview;
|
|
218
|
+
const installed = [];
|
|
219
|
+
const warnings = [];
|
|
220
|
+
let skipped = 0;
|
|
221
|
+
let pendingRegistration = '';
|
|
222
|
+
|
|
223
|
+
function release(handle) {
|
|
224
|
+
if (handle && api.cancel) void Promise.resolve().then(() => api.cancel(handle)).catch(() => {});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function releasePreview() {
|
|
228
|
+
release(preview?.token);
|
|
229
|
+
preview = null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function releaseUpload(value) {
|
|
233
|
+
if (value?.uploadId) release({ uploadId: value.uploadId });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function remove(restoreFocus) {
|
|
237
|
+
if (!active) return;
|
|
238
|
+
active = false;
|
|
239
|
+
operation++;
|
|
240
|
+
if (!writing) releasePreview();
|
|
241
|
+
releaseUpload(localSource);
|
|
242
|
+
if (dialog.open) dialog.close();
|
|
243
|
+
dialog.remove();
|
|
244
|
+
if (restoreFocus && opener?.isConnected && typeof opener.focus === 'function') {
|
|
245
|
+
opener.focus({ preventScroll: true });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function finish(interrupted = false) {
|
|
250
|
+
if (!active || writing) return;
|
|
251
|
+
remove(true);
|
|
252
|
+
const singles = installed.filter(item => !item.members);
|
|
253
|
+
const report = installed.filter(item => item.members).map(item => item.summary);
|
|
254
|
+
if (singles.length === 1) report.push(`${singles[0].enabled ? '已导入并启用' : '已导入'} ${singles[0].name}`);
|
|
255
|
+
else if (singles.length) report.push(`已导入 ${singles.length} 个技能`);
|
|
256
|
+
if (report.length && interrupted && !pendingRegistration) report.push('其余未导入');
|
|
257
|
+
if (skipped) report.push(`已跳过 ${skipped} 项`);
|
|
258
|
+
if (pendingRegistration) report.push(pendingRegistration);
|
|
259
|
+
if (report.length) onChanged?.([...report, ...warnings].join('。'));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const close = () => finish(true);
|
|
263
|
+
dialog.addEventListener('cancel', event => { event.preventDefault(); close(); });
|
|
264
|
+
let pressedOutside = false;
|
|
265
|
+
function outside(event) {
|
|
266
|
+
const box = dialog.getBoundingClientRect();
|
|
267
|
+
return event.target === dialog && (event.clientX < box.left || event.clientX > box.right ||
|
|
268
|
+
event.clientY < box.top || event.clientY > box.bottom);
|
|
269
|
+
}
|
|
270
|
+
dialog.addEventListener('pointerdown', event => { pressedOutside = outside(event); });
|
|
271
|
+
dialog.addEventListener('click', event => {
|
|
272
|
+
if (pressedOutside && outside(event)) close();
|
|
273
|
+
pressedOutside = false;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
function layout(view, title, description = '', dismissible = true) {
|
|
277
|
+
dialog.dataset.view = view;
|
|
278
|
+
const header = el('header', 'smf-head');
|
|
279
|
+
const heading = el('h2', '', title);
|
|
280
|
+
heading.id = `${prefix}-title`;
|
|
281
|
+
heading.tabIndex = -1;
|
|
282
|
+
header.append(heading);
|
|
283
|
+
if (description) {
|
|
284
|
+
const caption = el('p', 'smf-subtitle', description);
|
|
285
|
+
caption.id = `${prefix}-description`;
|
|
286
|
+
header.append(caption);
|
|
287
|
+
dialog.setAttribute('aria-describedby', caption.id);
|
|
288
|
+
} else dialog.removeAttribute('aria-describedby');
|
|
289
|
+
if (dismissible) {
|
|
290
|
+
const cross = button('', close, 'smf-close');
|
|
291
|
+
cross.setAttribute('aria-label', '关闭');
|
|
292
|
+
cross.title = '关闭';
|
|
293
|
+
cross.append(glyph('x', 16));
|
|
294
|
+
header.append(cross);
|
|
295
|
+
}
|
|
296
|
+
const body = el('div', 'smf-body');
|
|
297
|
+
const footer = el('footer', 'smf-footer');
|
|
298
|
+
dialog.replaceChildren(header, body, footer);
|
|
299
|
+
if (dialog.open) heading.focus({ preventScroll: true });
|
|
300
|
+
return { body, footer };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function show() {
|
|
304
|
+
if (active && dialog.isConnected && !dialog.open) {
|
|
305
|
+
dialog.showModal();
|
|
306
|
+
dialog.querySelector('h2')?.focus({ preventScroll: true });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function cancelButton() { return button(text('sm-r5-89', '取消'), close); }
|
|
311
|
+
|
|
312
|
+
async function run({ title, detail, task, success, failure, back, discarded, failedAfterClose }) {
|
|
313
|
+
const current = ++operation;
|
|
314
|
+
writing = !back;
|
|
315
|
+
const { body, footer } = layout('working', title, '', !writing);
|
|
316
|
+
const loader = el('div', 'smf-loading');
|
|
317
|
+
const progress = el('progress', 'smf-progress');
|
|
318
|
+
progress.setAttribute('aria-label', detail);
|
|
319
|
+
const status = el('p', 'smf-loading-text', detail);
|
|
320
|
+
status.setAttribute('role', 'status');
|
|
321
|
+
loader.append(glyph('loader', 34), status, progress);
|
|
322
|
+
body.append(loader);
|
|
323
|
+
if (back) footer.append(button(text('sm-r5-431', '上一步'), () => { operation++; back(); }));
|
|
324
|
+
else footer.remove();
|
|
325
|
+
|
|
326
|
+
let result;
|
|
327
|
+
try { result = await task(() => active && operation === current); }
|
|
328
|
+
catch (error) {
|
|
329
|
+
if (active && operation === current) { writing = false; failure(error); }
|
|
330
|
+
else failedAfterClose?.();
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (active && operation === current) { writing = false; success(result); }
|
|
334
|
+
else discarded?.(result);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function loadLibrary() {
|
|
338
|
+
if (!libraryPromise) {
|
|
339
|
+
libraryPromise = Promise.resolve().then(() => api.list()).then(result => {
|
|
340
|
+
library = result;
|
|
341
|
+
const directories = writableDirectories();
|
|
342
|
+
if (!directories.some(directory => directory.id === directoryId)) {
|
|
343
|
+
directoryId = (directories.find(directory => directory.kind === 'personal') || directories[0])?.id;
|
|
344
|
+
}
|
|
345
|
+
return result;
|
|
346
|
+
}).catch(error => { libraryPromise = undefined; throw error; });
|
|
347
|
+
}
|
|
348
|
+
return libraryPromise;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function writableDirectories() {
|
|
352
|
+
return (library?.directories || []).filter(directory => directory.writable === true);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function destination() {
|
|
356
|
+
return writableDirectories().find(directory => directory.id === directoryId);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function directorySelect(afterChange) {
|
|
360
|
+
const select = el('select', 'smf-field');
|
|
361
|
+
select.id = `${prefix}-directory`;
|
|
362
|
+
const directories = writableDirectories();
|
|
363
|
+
for (const directory of directories) {
|
|
364
|
+
const option = el('option', '', `${directory.label} · ${directoryPath(directory)}`);
|
|
365
|
+
option.value = directory.id;
|
|
366
|
+
option.selected = directory.id === directoryId;
|
|
367
|
+
select.append(option);
|
|
368
|
+
}
|
|
369
|
+
if (!directories.length) {
|
|
370
|
+
select.append(el('option', '', '暂无可写的技能目录'));
|
|
371
|
+
select.disabled = true;
|
|
372
|
+
}
|
|
373
|
+
select.addEventListener('change', () => { directoryId = directories[select.selectedIndex]?.id; afterChange(); });
|
|
374
|
+
return inputBox(select, 'folder', true);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function noDirectory() {
|
|
378
|
+
return el('p', 'smf-hint', '请在技能目录中添加可写的存放位置后重试。');
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function localCardTitle() {
|
|
382
|
+
return basename(localSource?.path) || localSource?.name || localLabel || localSource?.fileName || '已选择的技能';
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function localPage(problem = '') {
|
|
386
|
+
const { body, footer } = layout('local', text('sm-r5-93', '从本地导入'),
|
|
387
|
+
'选择技能或工具包,预览内容后选择保存目录。');
|
|
388
|
+
const zone = el('div', 'smf-drop');
|
|
389
|
+
const symbol = el('span', 'smf-drop-icon');
|
|
390
|
+
symbol.append(glyph('folder-plus', 24));
|
|
391
|
+
const instruction = el('p', 'smf-drop-title');
|
|
392
|
+
const choices = el('div', 'smf-drop-actions');
|
|
393
|
+
choices.append(button(text('sm-r5-77', '选择文件'), () => pick('file'), 'smf-small'),
|
|
394
|
+
button(text('sm-r5-79', '选择文件夹'), () => pick('directory'), 'smf-small'));
|
|
395
|
+
zone.append(symbol, instruction, choices);
|
|
396
|
+
body.append(zone);
|
|
397
|
+
|
|
398
|
+
let entered = 0;
|
|
399
|
+
zone.addEventListener('dragenter', event => {
|
|
400
|
+
event.preventDefault(); entered++; zone.classList.add('smf-dragging');
|
|
401
|
+
});
|
|
402
|
+
zone.addEventListener('dragover', event => {
|
|
403
|
+
event.preventDefault();
|
|
404
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
|
|
405
|
+
});
|
|
406
|
+
zone.addEventListener('dragleave', event => {
|
|
407
|
+
event.preventDefault(); entered = Math.max(0, entered - 1);
|
|
408
|
+
if (!entered) zone.classList.remove('smf-dragging');
|
|
409
|
+
});
|
|
410
|
+
zone.addEventListener('drop', event => {
|
|
411
|
+
event.preventDefault(); event.stopPropagation();
|
|
412
|
+
entered = 0; zone.classList.remove('smf-dragging');
|
|
413
|
+
const transfer = event.dataTransfer;
|
|
414
|
+
if (!transfer) return;
|
|
415
|
+
const label = transfer.files?.[0]?.name || '';
|
|
416
|
+
run({ title: text('sm-r5-93', '从本地导入'), detail: '正在读取拖入的技能…',
|
|
417
|
+
task: () => api.dropped(transfer), back: () => localPage(), discarded: releaseUpload,
|
|
418
|
+
success: value => { if (value) setLocal(value, label); localPage(); },
|
|
419
|
+
failure: error => localPage(error.message || '读取失败,请重新选择文件或输入本机路径。') });
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const sourcePath = el('input', 'smf-field smf-mono');
|
|
423
|
+
if (manualPath) {
|
|
424
|
+
sourcePath.id = `${prefix}-path`;
|
|
425
|
+
sourcePath.type = 'text';
|
|
426
|
+
sourcePath.autocomplete = 'off';
|
|
427
|
+
sourcePath.spellcheck = false;
|
|
428
|
+
sourcePath.placeholder = '~/Downloads/my-skill';
|
|
429
|
+
sourcePath.value = localSource?.type === 'local' ? localSource.path : '';
|
|
430
|
+
const manual = el('div', 'smf-manual');
|
|
431
|
+
manual.append(fieldLabel('本机文件或文件夹路径', sourcePath.id), inputBox(sourcePath, 'folder'));
|
|
432
|
+
body.append(manual);
|
|
433
|
+
}
|
|
434
|
+
if (problem) {
|
|
435
|
+
const alert = el('p', 'smf-inline-error', problem);
|
|
436
|
+
alert.setAttribute('role', 'alert');
|
|
437
|
+
body.append(alert);
|
|
438
|
+
}
|
|
439
|
+
const formats = el('dl', 'smf-formats');
|
|
440
|
+
for (const [name, description] of [
|
|
441
|
+
[text('sm-r5-82', 'Markdown'), text('sm-r5-83', '单个 .md 文件,YAML 文件头含 name 和 description。')],
|
|
442
|
+
[text('sm-r5-84', '技能文件夹'), '选择单个技能目录,或包含多个 SKILL.md 的工具包目录。'],
|
|
443
|
+
[text('sm-r5-86', '压缩包'), '选择 .zip 或 .skill。包内的技能、脚本和模板将一起导入。'],
|
|
444
|
+
]) formats.append(el('dt', '', name), el('dd', '', description));
|
|
445
|
+
body.append(formats);
|
|
446
|
+
|
|
447
|
+
const manualToggle = button(manualPath ? '收起路径输入' : '输入本机路径', () => {
|
|
448
|
+
manualPath = !manualPath; localPage();
|
|
449
|
+
if (manualPath) dialog.querySelector(`#${prefix}-path`)?.focus();
|
|
450
|
+
else dialog.querySelector('.smf-footer .smf-link-btn')?.focus();
|
|
451
|
+
}, 'smf-link-btn smf-push');
|
|
452
|
+
manualToggle.setAttribute('aria-expanded', String(manualPath));
|
|
453
|
+
const next = button(text('sm-r5-91', '预览导入'), () => { if (localSource) previewCurrent(); }, 'smf-primary');
|
|
454
|
+
footer.append(manualToggle, cancelButton(), next);
|
|
455
|
+
function selectionChanged() {
|
|
456
|
+
next.disabled = !localSource;
|
|
457
|
+
instruction.textContent = localSource ? localCardTitle() : text('sm-r5-76', '将技能文件或文件夹拖到这里');
|
|
458
|
+
instruction.title = localSource?.path || instruction.textContent;
|
|
459
|
+
}
|
|
460
|
+
sourcePath.addEventListener('input', () => {
|
|
461
|
+
const path = sourcePath.value.trim();
|
|
462
|
+
setLocal(path || null); selectionChanged();
|
|
463
|
+
});
|
|
464
|
+
sourcePath.addEventListener('keydown', event => {
|
|
465
|
+
if (event.key === 'Enter' && !event.isComposing && !next.disabled) next.click();
|
|
466
|
+
});
|
|
467
|
+
selectionChanged();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function setLocal(value, label = '') {
|
|
471
|
+
if (localSource?.uploadId !== value?.uploadId) releaseUpload(localSource);
|
|
472
|
+
localSource = typeof value === 'string' ? { type: 'local', path: value } : value;
|
|
473
|
+
localLabel = label;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async function pick(type) {
|
|
477
|
+
const current = ++operation;
|
|
478
|
+
// The Harness directory picker may itself be a DOM overlay.
|
|
479
|
+
if (dialog.open) dialog.close();
|
|
480
|
+
let problem = '';
|
|
481
|
+
try {
|
|
482
|
+
const value = await api.pick(type);
|
|
483
|
+
if (!active || current !== operation) { releaseUpload(value); return; }
|
|
484
|
+
if (value) { setLocal(value); manualPath = false; }
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (!active || current !== operation) return;
|
|
487
|
+
manualPath = true;
|
|
488
|
+
problem = error.message || '无法打开选择器,请输入本机路径。';
|
|
489
|
+
}
|
|
490
|
+
localPage(problem); show();
|
|
491
|
+
if (problem) dialog.querySelector(`#${prefix}-path`)?.focus();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function toolPath(entry = tool) { return scope === 'user' ? `~/${entry.path}` : entry.path; }
|
|
495
|
+
|
|
496
|
+
function toolPage() {
|
|
497
|
+
const personal = scope === 'user';
|
|
498
|
+
const { body, footer } = layout('tool', text('sm-r5-346', '从其他工具导入'), personal
|
|
499
|
+
? text('sm-r5-347', '选择一个工具目录,查看其中的技能。') : text('sm-r5-389', '以下路径均相对于当前项目根目录。'));
|
|
500
|
+
const row = el('div', 'smf-scope-row');
|
|
501
|
+
const title = text('sm-r5-338', '目录范围');
|
|
502
|
+
row.append(el('span', 'smf-label', title));
|
|
503
|
+
const scopes = el('div', 'smf-segments');
|
|
504
|
+
scopes.setAttribute('role', 'radiogroup'); scopes.setAttribute('aria-label', title);
|
|
505
|
+
for (const [value, label, iconName] of [['user', text('sm-r5-333', '个人目录'), 'house'], ['project', text('sm-r5-336', '当前项目'), 'folder']]) {
|
|
506
|
+
const segment = el('label', 'smf-segment');
|
|
507
|
+
const radio = el('input', 'smf-visually-hidden');
|
|
508
|
+
radio.type = 'radio'; radio.name = `${prefix}-scope`; radio.value = value; radio.checked = value === scope;
|
|
509
|
+
radio.addEventListener('change', () => {
|
|
510
|
+
scope = value; toolPage();
|
|
511
|
+
dialog.querySelector(`input[name="${prefix}-scope"]:checked`)?.focus();
|
|
512
|
+
});
|
|
513
|
+
segment.append(radio, glyph(iconName, 15), el('span', '', label)); scopes.append(segment);
|
|
514
|
+
}
|
|
515
|
+
row.append(scopes); body.append(row);
|
|
516
|
+
const list = el('div', 'smf-choice-list');
|
|
517
|
+
list.setAttribute('role', 'radiogroup'); list.setAttribute('aria-label', '工具来源');
|
|
518
|
+
const scanIndicators = [];
|
|
519
|
+
for (const entry of tools) {
|
|
520
|
+
const choice = el('label', 'smf-choice');
|
|
521
|
+
choice.append(iconTile(entry.icon), itemCopy(entry.name, toolPath(entry)));
|
|
522
|
+
const scanned = el('span', 'smf-status-tag', text('sm-r5-320', '已纳入扫描'));
|
|
523
|
+
scanned.hidden = true; choice.append(scanned);
|
|
524
|
+
scanIndicators.push([scanned, toolPath(entry)]);
|
|
525
|
+
const radio = el('input', 'smf-radio');
|
|
526
|
+
radio.type = 'radio'; radio.name = `${prefix}-tool`; radio.value = entry.id; radio.checked = entry.id === tool.id;
|
|
527
|
+
radio.addEventListener('change', () => { tool = entry; });
|
|
528
|
+
choice.append(radio); list.append(choice);
|
|
529
|
+
}
|
|
530
|
+
body.append(list);
|
|
531
|
+
footer.append(cancelButton(), button(text('sm-r5-344', '查看技能'), () => loadCandidates(), 'smf-primary'));
|
|
532
|
+
// A host may include a tool directory in its scan without making it writable.
|
|
533
|
+
void loadLibrary().then(() => {
|
|
534
|
+
if (list.isConnected) for (const [badge, path] of scanIndicators) {
|
|
535
|
+
badge.hidden = !library.directories.some(directory => directoryPath(directory) === path);
|
|
536
|
+
}
|
|
537
|
+
}).catch(() => {});
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function githubPage() {
|
|
541
|
+
const { body, footer } = layout('github', text('sm-r5-476', '从 GitHub 导入'),
|
|
542
|
+
text('sm-r5-477', '粘贴公开仓库或技能子目录链接,也可以从下方选择仓库。'));
|
|
543
|
+
const input = el('input', 'smf-field smf-mono');
|
|
544
|
+
input.id = `${prefix}-url`; input.type = 'text'; input.inputMode = 'url';
|
|
545
|
+
input.spellcheck = false; input.autocomplete = 'off'; input.value = url;
|
|
546
|
+
input.placeholder = text('sm-r5-465', 'https://github.com/anthropics/skills');
|
|
547
|
+
body.append(fieldLabel(text('sm-r5-463', '来源链接'), input.id), inputBox(input, 'link'));
|
|
548
|
+
const group = el('div', 'smf-section-heading smf-repos-heading');
|
|
549
|
+
const link = el('a', 'smf-external', text('sm-r5-468', '浏览 skills.sh 目录'));
|
|
550
|
+
link.href = 'https://skills.sh/'; link.target = '_blank'; link.rel = 'noopener noreferrer';
|
|
551
|
+
link.append(glyph('external-link', 13));
|
|
552
|
+
group.append(el('span', 'smf-label', text('sm-r5-467', '常用仓库')), link); body.append(group);
|
|
553
|
+
const list = el('div', 'smf-choice-list');
|
|
554
|
+
const next = button(text('sm-r5-474', '查看技能'), () => loadCandidates(), 'smf-primary');
|
|
555
|
+
function updateUrl() {
|
|
556
|
+
url = input.value;
|
|
557
|
+
const path = repositoryPath(githubUrl(url));
|
|
558
|
+
for (const row of list.children) {
|
|
559
|
+
const current = row.dataset.repository === path;
|
|
560
|
+
row.setAttribute('aria-pressed', String(current));
|
|
561
|
+
row.lastElementChild.replaceChildren(glyph(current ? 'check' : 'arrow-up-left', 17));
|
|
562
|
+
}
|
|
563
|
+
next.disabled = !url.trim();
|
|
564
|
+
}
|
|
565
|
+
for (const repo of repositories) {
|
|
566
|
+
const row = button('', () => { input.value = `https://github.com/${repo.path}`; updateUrl(); }, 'smf-choice');
|
|
567
|
+
row.dataset.repository = repo.path;
|
|
568
|
+
row.append(iconTile('book-marked'), itemCopy(repo.name, repo.path), el('span', 'smf-trailing'));
|
|
569
|
+
list.append(row);
|
|
570
|
+
}
|
|
571
|
+
input.addEventListener('input', updateUrl);
|
|
572
|
+
input.addEventListener('keydown', event => {
|
|
573
|
+
if (event.key === 'Enter' && !event.isComposing && !next.disabled) next.click();
|
|
574
|
+
});
|
|
575
|
+
body.append(list); footer.append(cancelButton(), next); updateUrl();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function sourcePage() {
|
|
579
|
+
if (kind === 'tool') toolPage();
|
|
580
|
+
else if (kind === 'github') githubPage();
|
|
581
|
+
else localPage();
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function sourceInfo() {
|
|
585
|
+
if (kind === 'tool') return { name: tool.name, path: listing?.sourcePath || toolPath(), icon: tool.icon,
|
|
586
|
+
tag: scope === 'user' ? text('sm-r5-333', '个人目录') : text('sm-r5-336', '当前项目') };
|
|
587
|
+
const path = repositoryPath(githubUrl(url));
|
|
588
|
+
const repo = repositories.find(entry => entry.path === path);
|
|
589
|
+
return { name: repo?.name || path.split('/').slice(0, 2).join('/') || 'GitHub',
|
|
590
|
+
path, icon: 'git-branch', tag: text('sm-r5-503', '公开仓库') };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function loadCandidates() {
|
|
594
|
+
source = kind === 'tool' ? { type: 'tool', tool: tool.id, scope } : { type: 'github', url: githubUrl(url) };
|
|
595
|
+
const title = kind === 'tool' ? text('sm-r5-346', '从其他工具导入') : text('sm-r5-476', '从 GitHub 导入');
|
|
596
|
+
listing = null; queue = []; index = 0;
|
|
597
|
+
run({ title, detail: kind === 'tool' ? '正在扫描技能目录…' : '正在读取公开仓库的技能目录…',
|
|
598
|
+
task: () => Promise.all([api.candidates(source), loadLibrary()]), back: sourcePage,
|
|
599
|
+
success: ([result]) => {
|
|
600
|
+
listing = result; selected = new Set(); query = ''; filter = 'all';
|
|
601
|
+
if (listing.items.length === 1 && !alreadyInstalled(listing.items[0])) selected.add(listing.items[0].id);
|
|
602
|
+
candidatesPage();
|
|
603
|
+
},
|
|
604
|
+
failure: error => problemPage({ title, error, name: '读取来源失败', back: sourcePage, retry: loadCandidates }) });
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function alreadyInstalled(item) {
|
|
608
|
+
if (item.kind === 'family') return Boolean(item.installed || installed.some(skill => skill.members && skill.name === item.name) ||
|
|
609
|
+
library?.items?.some(skill => skill.package?.label === item.name || skill.package?.name === item.name));
|
|
610
|
+
return Boolean(item.installed || (library?.items || []).some(skill => skill.name === item.name) ||
|
|
611
|
+
installed.some(skill => skill.name === item.name || skill.members?.some(member => member.name === item.name)));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function recentKey(item) { return JSON.stringify([source.url, item.path || item.name]); }
|
|
615
|
+
|
|
616
|
+
function candidatesPage() {
|
|
617
|
+
const github = kind === 'github';
|
|
618
|
+
const title = github ? text('sm-r5-525', '从 GitHub 导入 · 选择技能') : text('sm-r5-436', '从其他工具导入 · 选择技能');
|
|
619
|
+
const { body, footer } = layout(github ? 'github-skills' : 'tool-skills', title);
|
|
620
|
+
const info = sourceInfo();
|
|
621
|
+
body.append(sourceCard(info.icon, info.name, info.path, el('span', 'smf-status-tag', info.tag)));
|
|
622
|
+
const search = el('input', 'smf-field');
|
|
623
|
+
if (github) {
|
|
624
|
+
const filters = el('div', 'smf-filters');
|
|
625
|
+
search.type = 'search'; search.value = query;
|
|
626
|
+
search.placeholder = text('sm-r5-506', '搜索技能名称或路径');
|
|
627
|
+
search.setAttribute('aria-label', search.placeholder);
|
|
628
|
+
const range = el('select', 'smf-field');
|
|
629
|
+
range.setAttribute('aria-label', '筛选技能');
|
|
630
|
+
for (const [value, label] of [['all', '全部技能'], ['recent', text('sm-r5-509', '最近浏览')], ['selected', '已选择']]) {
|
|
631
|
+
const option = el('option', '', label); option.value = value; option.selected = value === filter; range.append(option);
|
|
632
|
+
}
|
|
633
|
+
search.addEventListener('input', () => { query = search.value; updateList(); });
|
|
634
|
+
range.addEventListener('change', () => { filter = range.value; updateList(); });
|
|
635
|
+
filters.append(inputBox(search, 'search'), inputBox(range, 'list-filter', true)); body.append(filters);
|
|
636
|
+
}
|
|
637
|
+
const head = el('div', 'smf-section-heading smf-list-heading');
|
|
638
|
+
const num = el('span', 'smf-count');
|
|
639
|
+
head.append(el('span', 'smf-label', github ? text('sm-r5-512', '技能目录') : text('sm-r5-423', '目录中的技能')), num);
|
|
640
|
+
const list = el('div', 'smf-choice-list smf-candidates');
|
|
641
|
+
list.setAttribute('role', 'group'); list.setAttribute('aria-label', '选择要导入的技能');
|
|
642
|
+
body.append(head, list);
|
|
643
|
+
if (listing.warnings?.length) {
|
|
644
|
+
const details = el('details', 'smf-list-warnings');
|
|
645
|
+
const notes = el('ul');
|
|
646
|
+
for (const warning of listing.warnings) notes.append(el('li', '', warning));
|
|
647
|
+
details.append(el('summary', '', `${listing.warnings.length} 项读取提示`), notes);
|
|
648
|
+
body.append(details);
|
|
649
|
+
}
|
|
650
|
+
if (destination()) {
|
|
651
|
+
const hint = el('p', 'smf-save-note');
|
|
652
|
+
hint.append(glyph('folder', 15), el('span', '', text('sm-r5-426', '默认保存到')),
|
|
653
|
+
el('span', 'smf-mono', directoryPath(destination())), el('span', '', text('sm-r5-428', ',可在确认时更改。')));
|
|
654
|
+
body.append(hint);
|
|
655
|
+
}
|
|
656
|
+
const count = el('span', 'smf-count smf-push'); count.setAttribute('aria-live', 'polite');
|
|
657
|
+
const next = button(text('sm-r5-433', '预览导入'), () => {
|
|
658
|
+
queue = listing.items.filter(item => selected.has(item.id)); index = 0;
|
|
659
|
+
if (queue.length) previewCurrent();
|
|
660
|
+
}, 'smf-primary');
|
|
661
|
+
footer.append(count, button(text('sm-r5-431', '上一步'), sourcePage), next);
|
|
662
|
+
|
|
663
|
+
function updateCount() { count.textContent = `已选 ${selected.size} 项`; next.disabled = !selected.size; }
|
|
664
|
+
function updateList() {
|
|
665
|
+
const needle = query.trim().toLowerCase();
|
|
666
|
+
const visible = listing.items.filter(item => {
|
|
667
|
+
if (filter === 'recent' && !recentlyViewed.has(recentKey(item))) return false;
|
|
668
|
+
if (filter === 'selected' && !selected.has(item.id)) return false;
|
|
669
|
+
return !needle || `${item.name}\n${item.path || ''}\n${item.description || ''}`.toLowerCase().includes(needle);
|
|
670
|
+
});
|
|
671
|
+
num.textContent = github ? `当前显示 ${visible.length} 项` : `${visible.length} 项`;
|
|
672
|
+
list.replaceChildren();
|
|
673
|
+
for (const item of visible) {
|
|
674
|
+
const row = el('label', 'smf-candidate');
|
|
675
|
+
const checkbox = el('input', 'smf-checkbox');
|
|
676
|
+
checkbox.type = 'checkbox'; checkbox.checked = selected.has(item.id);
|
|
677
|
+
checkbox.setAttribute('aria-label', item.name);
|
|
678
|
+
checkbox.addEventListener('change', () => {
|
|
679
|
+
if (checkbox.checked) selected.add(item.id); else selected.delete(item.id);
|
|
680
|
+
if (filter === 'selected') { updateList(); (list.querySelector('input') || search).focus(); }
|
|
681
|
+
else updateCount();
|
|
682
|
+
});
|
|
683
|
+
row.append(checkbox, itemCopy(item.name, github ? item.path || item.description : item.description || item.path, github));
|
|
684
|
+
if (item.kind === 'family') row.append(el('span', 'smf-count', `工具包 · ${item.memberCount} 个技能`));
|
|
685
|
+
if (alreadyInstalled(item)) {
|
|
686
|
+
const note = el('span', 'smf-status-tag', text('sm-r5-410', '已在技能库'));
|
|
687
|
+
checkbox.setAttribute('aria-label', `${item.name},${note.textContent}`);
|
|
688
|
+
row.append(note);
|
|
689
|
+
}
|
|
690
|
+
list.append(row);
|
|
691
|
+
}
|
|
692
|
+
if (!visible.length) {
|
|
693
|
+
let empty = '没有匹配的技能。';
|
|
694
|
+
if (!listing.items.length) empty = '这个来源中没有找到技能。';
|
|
695
|
+
else if (!needle && filter === 'recent') empty = '尚未预览此仓库中的技能。';
|
|
696
|
+
else if (!needle && filter === 'selected') empty = '还没有选择技能。';
|
|
697
|
+
list.append(el('p', 'smf-empty', empty));
|
|
698
|
+
}
|
|
699
|
+
list.scrollTop = 0; updateCount();
|
|
700
|
+
}
|
|
701
|
+
updateList();
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function selectedSource() {
|
|
705
|
+
releasePreview();
|
|
706
|
+
if (kind === 'local') localPage(); else candidatesPage();
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function previewCurrent() {
|
|
710
|
+
const options = kind === 'local' ? localSource : { ...source, id: queue[index].id };
|
|
711
|
+
const name = kind === 'local' ? localCardTitle() : queue[index].name;
|
|
712
|
+
releasePreview();
|
|
713
|
+
run({ title: text('sm-r5-91', '预览导入'), detail: `正在检查 ${name}…`,
|
|
714
|
+
task: async isCurrent => { await loadLibrary(); if (isCurrent()) return api.preview(options); }, back: selectedSource,
|
|
715
|
+
discarded: value => release(value?.token),
|
|
716
|
+
success: value => {
|
|
717
|
+
preview = value;
|
|
718
|
+
if (kind === 'github') {
|
|
719
|
+
const key = recentKey(queue[index]); recentlyViewed.delete(key); recentlyViewed.add(key);
|
|
720
|
+
if (recentlyViewed.size > 100) recentlyViewed.delete(recentlyViewed.values().next().value);
|
|
721
|
+
}
|
|
722
|
+
if (preview.format === 'archive' && !preview.family) archivePage(); else reviewPage();
|
|
723
|
+
},
|
|
724
|
+
failure: error => {
|
|
725
|
+
const title = text('sm-r5-293', '检查技能文件');
|
|
726
|
+
if (kind !== 'local' && ['CANDIDATE_EXPIRED', 'SOURCE_CHANGED'].includes(error.code)) {
|
|
727
|
+
problemPage({ title, error, name: '来源已更新', back: sourcePage, retry: loadCandidates, retryLabel: '重新读取来源' });
|
|
728
|
+
} else if (localSource?.uploadId && error.code === 'PREVIEW_EXPIRED') {
|
|
729
|
+
setLocal(null);
|
|
730
|
+
localPage(error.message || '上传已过期,请重新选择文件。');
|
|
731
|
+
} else problemPage({ title, error, name: '无法预览技能', back: selectedSource, retry: previewCurrent, canSkip: true });
|
|
732
|
+
} });
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function previewCard(reselect = true, archiveCount = false) {
|
|
736
|
+
const item = queue[index];
|
|
737
|
+
let label, path, iconName;
|
|
738
|
+
if (kind === 'local') {
|
|
739
|
+
label = localSource?.uploadId ? localCardTitle() : preview?.sourceLabel || localCardTitle();
|
|
740
|
+
path = preview?.sourcePath || localSource?.path || '';
|
|
741
|
+
const isMarkdown = preview?.format === 'markdown' || /\.md$/i.test(label);
|
|
742
|
+
const isArchive = preview?.format === 'archive' || /\.(skill|zip)$/i.test(label);
|
|
743
|
+
iconName = isMarkdown ? 'file-text' : isArchive ? 'file-archive' : 'folder-open';
|
|
744
|
+
if (!preview?.family && path === label && localSource?.uploadId) path = isMarkdown ? 'Markdown' : isArchive ? 'ZIP 格式' : '技能文件夹';
|
|
745
|
+
} else {
|
|
746
|
+
const info = sourceInfo();
|
|
747
|
+
label = item ? `${info.name} · ${preview?.name || item.name}` : info.name;
|
|
748
|
+
path = preview?.sourcePath || item?.path || info.path;
|
|
749
|
+
iconName = info.icon;
|
|
750
|
+
}
|
|
751
|
+
if (archiveCount) path = `ZIP 格式 · ${(preview.files || []).length} 个文件`;
|
|
752
|
+
if (preview?.family) label = preview.family.name;
|
|
753
|
+
return sourceCard(iconName, label, path, reselect ? button(text('sm-r5-103', '重新选择'), selectedSource, 'smf-ghost smf-small') : null);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function archivePage() {
|
|
757
|
+
const { body, footer } = layout('archive', text('sm-r5-192', '预览技能包'),
|
|
758
|
+
text('sm-r5-193', '导入时将保留技能说明和配套文件的目录结构。'));
|
|
759
|
+
body.append(previewCard(true, true), el('p', 'smf-label smf-tree-label', text('sm-r5-186', '压缩包内容')),
|
|
760
|
+
fileTree(preview.name, preview.files || []));
|
|
761
|
+
footer.append(cancelButton(), button(text('sm-r5-190', '核对信息'), reviewPage, 'smf-primary'));
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function reviewSubtitle() {
|
|
765
|
+
if (kind === 'tool') return `所选技能将从 ${tool.name} 目录复制到下方位置。`;
|
|
766
|
+
if (kind === 'github') return text('sm-r5-591', '所选技能子目录将从 GitHub 复制到下方位置。');
|
|
767
|
+
if (preview.format === 'markdown') return text('sm-r5-159', '请核对 Markdown 文件中的技能信息,再选择保存位置。');
|
|
768
|
+
if (preview.format === 'archive') return text('sm-r5-226', '解包后,技能说明和配套文件将保存到同一目录。');
|
|
769
|
+
return text('sm-r5-126', '这个文件夹中的技能说明和配套文件将一起导入。');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function targetPath() {
|
|
773
|
+
const entry = preview.targetRelativePath || preview.family?.id || preview.entry || (preview.format === 'markdown' ? `${preview.name}.md` : `${preview.name}/SKILL.md`);
|
|
774
|
+
return joinDisplayPath(destination(), entry);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function batchControls(footer) {
|
|
778
|
+
if (queue.length <= 1) return;
|
|
779
|
+
const group = el('div', 'smf-batch smf-push');
|
|
780
|
+
group.append(el('span', 'smf-count', `第 ${index + 1} / ${queue.length} 项`),
|
|
781
|
+
button('跳过此项', () => advance(true), 'smf-link-btn'));
|
|
782
|
+
footer.append(group);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function enableSwitch() {
|
|
786
|
+
const state = el('label', 'smf-enable');
|
|
787
|
+
const toggle = el('input', 'smf-switch');
|
|
788
|
+
toggle.type = 'checkbox'; toggle.setAttribute('role', 'switch'); toggle.checked = enabled;
|
|
789
|
+
toggle.setAttribute('aria-checked', String(enabled));
|
|
790
|
+
toggle.addEventListener('change', () => { enabled = toggle.checked; toggle.setAttribute('aria-checked', String(enabled)); });
|
|
791
|
+
state.append(el('span', 'smf-label', text('sm-r5-117', '导入后启用')), toggle);
|
|
792
|
+
return state;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function reviewPage() {
|
|
796
|
+
const family = preview.family;
|
|
797
|
+
const { body, footer } = layout('review', family ? '确认导入工具包' : text('sm-r5-125', '确认导入'),
|
|
798
|
+
family ? '包内所有技能和共享文件将一起保存。' : reviewSubtitle());
|
|
799
|
+
body.append(previewCard());
|
|
800
|
+
if (family) body.append(familyContents(family, preview.files));
|
|
801
|
+
else {
|
|
802
|
+
const facts = el('dl', 'smf-facts');
|
|
803
|
+
facts.append(el('dt', '', text('sm-r5-106', '技能名称')), el('dd', 'smf-fact-name', preview.name),
|
|
804
|
+
el('dt', '', text('sm-r5-108', '描述')), el('dd', '', preview.description || '—'));
|
|
805
|
+
body.append(facts);
|
|
806
|
+
}
|
|
807
|
+
const save = el('div', 'smf-save-row');
|
|
808
|
+
const target = el('div', 'smf-target');
|
|
809
|
+
const path = el('p', 'smf-mono smf-output-path'); path.setAttribute('aria-live', 'polite');
|
|
810
|
+
const directory = directorySelect(() => { path.textContent = targetPath(); });
|
|
811
|
+
path.textContent = targetPath();
|
|
812
|
+
target.append(directory, destination() ? path : noDirectory());
|
|
813
|
+
save.append(fieldLabel(text('sm-r5-111', '保存到'), `${prefix}-directory`), target);
|
|
814
|
+
body.append(save);
|
|
815
|
+
if (family) {
|
|
816
|
+
const note = family.enabled === false ? '来源工具包已停用。' : '新导入的技能沿用包内的调用设置。';
|
|
817
|
+
body.append(el('p', 'smf-hint', `${note}更新时保留已有工具包的开关和成员的禁用设置。`));
|
|
818
|
+
} else body.append(enableSwitch());
|
|
819
|
+
batchControls(footer);
|
|
820
|
+
const next = button(family ? '导入工具包' : text('sm-r5-123', '确认导入'), () => commit(false), 'smf-primary');
|
|
821
|
+
next.disabled = !destination(); footer.append(cancelButton(), next);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function commit(replace) {
|
|
825
|
+
if (writing || !preview || !destination()) return;
|
|
826
|
+
const family = preview.family;
|
|
827
|
+
const args = { token: preview.token, directoryId };
|
|
828
|
+
// Omitting a package-level override also preserves a previously disabled installation on replacement.
|
|
829
|
+
if (!family) args.enabled = enabled;
|
|
830
|
+
if (replace) args.conflict = 'replace';
|
|
831
|
+
const title = family ? '导入工具包' : text('skv-424', '导入技能');
|
|
832
|
+
const name = family?.name || preview.name;
|
|
833
|
+
run({ title, detail: `正在导入 ${name}…`, task: () => api.commit(args),
|
|
834
|
+
failedAfterClose: () => release(args.token), discarded: () => release(args.token),
|
|
835
|
+
success: result => {
|
|
836
|
+
installed.push(family ? familyReceipt(result) : { name, enabled: result?.enabled ?? enabled });
|
|
837
|
+
pendingRegistration = '';
|
|
838
|
+
if (result?.warning) warnings.push(result.warning);
|
|
839
|
+
releasePreview();
|
|
840
|
+
advance(false);
|
|
841
|
+
},
|
|
842
|
+
failure: error => {
|
|
843
|
+
if (error.code === 'CONFLICT') { conflictPage(error); return; }
|
|
844
|
+
if (error.code === 'REGISTRATION_FAILED') {
|
|
845
|
+
pendingRegistration = family
|
|
846
|
+
? `工具包「${name}」已保存到 ${error.details?.path || targetPath()},${error.details?.memberCount ?? family.members.length} 个技能尚未完成登记`
|
|
847
|
+
: `${name} 的文件已保存,技能尚未登记`;
|
|
848
|
+
problemPage({ title, error, name: '文件已保存,技能尚未登记',
|
|
849
|
+
back: close, backLabel: '关闭', retry: () => commit(replace), retryLabel: '重试登记' });
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (['CONNECTION_FAILED', 'BUSY', 'IMPORT_BUSY', 'IMPORT_IN_PROGRESS'].includes(error.code)) {
|
|
853
|
+
problemPage({ title, error, name: '尚未确认导入结果',
|
|
854
|
+
back: close, backLabel: '关闭', retry: () => commit(replace), retryLabel: '重试本次导入' });
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
if (error.code === 'INVALID_TARGET') {
|
|
858
|
+
libraryPromise = undefined;
|
|
859
|
+
problemPage({ title, error, name: '存放目录已变化',
|
|
860
|
+
back: selectedSource, retry: previewCurrent, retryLabel: '重选保存位置', canSkip: true });
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
const expired = error.code === 'PREVIEW_EXPIRED';
|
|
864
|
+
problemPage({ title, error,
|
|
865
|
+
name: expired ? '预览已过期' : error.code === 'TARGET_OCCUPIED' ? '目标位置已有其他文件' : '导入失败',
|
|
866
|
+
back: expired ? selectedSource : reviewPage, backLabel: expired ? '重新选择' : '返回确认',
|
|
867
|
+
retry: previewCurrent, retryLabel: '重新预览', canSkip: true });
|
|
868
|
+
} });
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function advance(skip) {
|
|
872
|
+
if (skip) { skipped++; releasePreview(); }
|
|
873
|
+
if (queue[index]) selected.delete(queue[index].id);
|
|
874
|
+
if (index + 1 < queue.length) { index++; previewCurrent(); }
|
|
875
|
+
else finish();
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function alertBox(title, message) {
|
|
879
|
+
const alert = el('div', 'smf-alert'); alert.setAttribute('role', 'alert');
|
|
880
|
+
const copy = el('div');
|
|
881
|
+
copy.append(el('strong', '', title));
|
|
882
|
+
if (message) copy.append(el('p', '', message));
|
|
883
|
+
alert.append(glyph('circle-alert', 18), copy);
|
|
884
|
+
return alert;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function conflictPage(error) {
|
|
888
|
+
const family = preview.family;
|
|
889
|
+
const { body, footer } = layout('conflict', family ? '替换工具包' : text('skv-503', '导入技能'));
|
|
890
|
+
const existing = error.details?.existingPath || error.existingPath;
|
|
891
|
+
const target = error.details?.targetPath || error.targetPath || targetPath();
|
|
892
|
+
const warning = alertBox(family ? '已存在同名工具包' : text('skv-492', '已存在同名技能'), existing ? '' : error.message);
|
|
893
|
+
if (existing) warning.lastElementChild.append(el('p', 'smf-conflict-path smf-mono', existing));
|
|
894
|
+
if (target !== existing) warning.lastElementChild.append(el('p', 'smf-conflict-path smf-mono', `导入到 ${target}`));
|
|
895
|
+
warning.lastElementChild.append(el('p', '', family
|
|
896
|
+
? `将用包内 ${family.members.length} 个技能及其配套文件替换整个目录,原有禁用设置会保留。`
|
|
897
|
+
: text('skv-494', '替换会覆盖该目录中的现有文件。')));
|
|
898
|
+
body.append(previewCard(false), warning);
|
|
899
|
+
batchControls(footer);
|
|
900
|
+
footer.append(cancelButton(), button('改选目录', reviewPage), button(text('skv-501', '确认替换'), () => commit(true), 'smf-primary'));
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
function problemPage({ title, name, error, back, backLabel, retry, retryLabel, canSkip = false }) {
|
|
904
|
+
const { body, footer } = layout('error', title);
|
|
905
|
+
body.append(previewCard(false));
|
|
906
|
+
body.append(alertBox(name, error?.message || String(error || '操作失败,请重试。')));
|
|
907
|
+
if (canSkip) batchControls(footer);
|
|
908
|
+
footer.append(button(backLabel || text('sm-r5-289', '重新选择'), back),
|
|
909
|
+
button(retryLabel || text('sm-r5-291', '重新检查'), retry, 'smf-primary'));
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
sourcePage();
|
|
913
|
+
show();
|
|
914
|
+
return { close, cleanup: () => remove(false) };
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function removalModal(container, view, title, onClose) {
|
|
918
|
+
const dialog = el('dialog', 'sm-flow sm-design smf-removal');
|
|
919
|
+
dialog.dataset.view = view;
|
|
920
|
+
const heading = el('h2', '', title);
|
|
921
|
+
heading.id = `skill-flow-${++dialogSequence}-title`;
|
|
922
|
+
heading.tabIndex = -1;
|
|
923
|
+
dialog.setAttribute('aria-labelledby', heading.id);
|
|
924
|
+
const head = el('header', 'smf-head');
|
|
925
|
+
const body = el('div', 'smf-body');
|
|
926
|
+
const footer = el('footer', 'smf-footer');
|
|
927
|
+
head.append(heading);
|
|
928
|
+
dialog.append(head, body, footer);
|
|
929
|
+
let busy = false;
|
|
930
|
+
let active = true;
|
|
931
|
+
function close(restoreFocus = true) {
|
|
932
|
+
if (!active) return;
|
|
933
|
+
active = false;
|
|
934
|
+
dialog.close();
|
|
935
|
+
dialog.remove();
|
|
936
|
+
onClose(restoreFocus);
|
|
937
|
+
}
|
|
938
|
+
const dismiss = () => { if (!busy) close(); };
|
|
939
|
+
dialog.addEventListener('cancel', event => { event.preventDefault(); dismiss(); });
|
|
940
|
+
const status = (message, pending = false) => {
|
|
941
|
+
const node = el('div', 'smf-subtitle');
|
|
942
|
+
node.setAttribute('role', 'status');
|
|
943
|
+
node.append(el('span', '', message));
|
|
944
|
+
if (pending) {
|
|
945
|
+
const progress = el('progress', 'smf-progress');
|
|
946
|
+
progress.setAttribute('aria-label', message);
|
|
947
|
+
node.append(progress);
|
|
948
|
+
}
|
|
949
|
+
return node;
|
|
950
|
+
};
|
|
951
|
+
const alert = error => {
|
|
952
|
+
const node = el('p', 'smf-inline-error', error?.message || '请求未完成,请重试。');
|
|
953
|
+
node.setAttribute('role', 'alert');
|
|
954
|
+
return node;
|
|
955
|
+
};
|
|
956
|
+
const closeButton = label => button(label, dismiss);
|
|
957
|
+
const focusHeading = () => heading.focus({ preventScroll: true });
|
|
958
|
+
function working(value) {
|
|
959
|
+
busy = value;
|
|
960
|
+
for (const control of dialog.querySelectorAll('button')) control.disabled = value;
|
|
961
|
+
if (value) focusHeading();
|
|
962
|
+
}
|
|
963
|
+
container.append(dialog);
|
|
964
|
+
dialog.showModal();
|
|
965
|
+
focusHeading();
|
|
966
|
+
return { dialog, body, footer, close, closeButton, working, status, alert, focusHeading, active: () => active };
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
export function openRemovalDialog(container, { kind, id, prepare, commit, onRemoved, onClose }) {
|
|
970
|
+
const title = kind === 'package' ? '删除技能包' : '删除技能';
|
|
971
|
+
const modal = removalModal(container, 'remove-skill', `${title}?`, onClose);
|
|
972
|
+
modal.dialog.dataset.kind = kind;
|
|
973
|
+
const { dialog, body, footer, close, closeButton, working, status, alert, focusHeading, active } = modal;
|
|
974
|
+
|
|
975
|
+
function showProblem(error, committedAttempt) {
|
|
976
|
+
body.append(alert(error));
|
|
977
|
+
const uncertain = ['CONNECTION_FAILED', 'RECOVERY_REQUIRED', 'SNAPSHOT_FAILED'].includes(error?.code);
|
|
978
|
+
if (committedAttempt && uncertain) {
|
|
979
|
+
body.append(el('p', 'smf-subtitle', '请刷新技能列表,并在“已删除”中查看恢复记录。'));
|
|
980
|
+
}
|
|
981
|
+
const dismiss = closeButton('关闭');
|
|
982
|
+
footer.replaceChildren(dismiss);
|
|
983
|
+
if (!committedAttempt || ['REMOVAL_EXPIRED', 'TARGET_CHANGED'].includes(error?.code)) {
|
|
984
|
+
footer.append(button('重新核对', load));
|
|
985
|
+
}
|
|
986
|
+
dismiss.focus({ preventScroll: true });
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
async function load() {
|
|
990
|
+
const cancel = closeButton('取消');
|
|
991
|
+
dialog.removeAttribute('aria-describedby');
|
|
992
|
+
body.replaceChildren(status('正在核对文件位置…', true));
|
|
993
|
+
footer.replaceChildren(cancel);
|
|
994
|
+
cancel.focus({ preventScroll: true });
|
|
995
|
+
try {
|
|
996
|
+
const plan = await prepare();
|
|
997
|
+
if (!active()) return;
|
|
998
|
+
if (!plan?.token || plan.kind !== kind || plan.id !== id || !plan.name || !plan.path || !['file', 'directory'].includes(plan.scope) ||
|
|
999
|
+
(kind === 'package' && (plan.scope !== 'directory' || !Number.isSafeInteger(plan.memberCount)))) {
|
|
1000
|
+
throw new Error('无法确认要删除的文件范围。');
|
|
1001
|
+
}
|
|
1002
|
+
const facts = el('dl', 'smf-removal-facts');
|
|
1003
|
+
facts.id = `${dialog.getAttribute('aria-labelledby')}-facts`;
|
|
1004
|
+
facts.append(el('dt', '', '名称'), el('dd', '', plan.name),
|
|
1005
|
+
el('dt', '', '原位置'), el('dd', 'smf-mono', plan.path));
|
|
1006
|
+
const scope = kind === 'package'
|
|
1007
|
+
? `整个技能包目录及其内容,包括 ${plan.memberCount} 个技能和配套文件。`
|
|
1008
|
+
: plan.scope === 'directory' ? '整个技能目录,包括技能说明和目录里的配套文件。' : '此技能文件。';
|
|
1009
|
+
facts.append(el('dt', '', '删除范围'), el('dd', '', scope));
|
|
1010
|
+
body.replaceChildren(facts);
|
|
1011
|
+
dialog.setAttribute('aria-describedby', facts.id);
|
|
1012
|
+
if (plan.members?.length) {
|
|
1013
|
+
const members = el('details', 'smf-removal-members');
|
|
1014
|
+
const list = el('ul');
|
|
1015
|
+
for (const member of plan.members) list.append(el('li', '', member.name));
|
|
1016
|
+
members.append(el('summary', '', '查看包内技能'), list);
|
|
1017
|
+
body.append(members);
|
|
1018
|
+
}
|
|
1019
|
+
body.append(el('p', 'smf-subtitle', '删除后可在“已删除”中恢复到原位置。'));
|
|
1020
|
+
footer.append(button(title, async () => {
|
|
1021
|
+
working(true);
|
|
1022
|
+
const pending = status('正在删除…', true);
|
|
1023
|
+
body.append(pending);
|
|
1024
|
+
let receipt;
|
|
1025
|
+
try {
|
|
1026
|
+
receipt = await commit(plan.token);
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
if (!active()) return;
|
|
1029
|
+
pending.remove();
|
|
1030
|
+
working(false);
|
|
1031
|
+
showProblem(error, true);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
if (!active()) return;
|
|
1035
|
+
close(false);
|
|
1036
|
+
onRemoved(receipt);
|
|
1037
|
+
}, 'smf-destructive'));
|
|
1038
|
+
if (cancel === cancel.ownerDocument.activeElement) focusHeading();
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
if (!active()) return;
|
|
1041
|
+
body.replaceChildren();
|
|
1042
|
+
showProblem(error, false);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
void load();
|
|
1047
|
+
return { cleanup: () => close(false) };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
export function openRecoveryDialog(container, { list, restore, onRestored, onClose }) {
|
|
1051
|
+
const modal = removalModal(container, 'removed-skills', '已删除', onClose);
|
|
1052
|
+
const { body, footer, close, closeButton, working, status, alert, active } = modal;
|
|
1053
|
+
const date = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
1054
|
+
let loading = false;
|
|
1055
|
+
const refresh = button('刷新', () => load(), 'smf-push');
|
|
1056
|
+
const done = closeButton('关闭');
|
|
1057
|
+
const entries = el('ul', 'smf-recovery-list');
|
|
1058
|
+
entries.setAttribute('aria-label', '已删除的技能和技能包');
|
|
1059
|
+
const feedback = el('div');
|
|
1060
|
+
body.append(feedback, entries);
|
|
1061
|
+
footer.append(refresh, done);
|
|
1062
|
+
|
|
1063
|
+
async function recover(receipt, control) {
|
|
1064
|
+
working(true);
|
|
1065
|
+
feedback.replaceChildren(status(`正在恢复 ${receipt.name}…`, true));
|
|
1066
|
+
try {
|
|
1067
|
+
const restored = await restore(receipt.id);
|
|
1068
|
+
if (!active()) return;
|
|
1069
|
+
control.closest('li').remove();
|
|
1070
|
+
const result = `已恢复 ${restored.name}`;
|
|
1071
|
+
feedback.replaceChildren(status(result));
|
|
1072
|
+
onRestored(receipt.id);
|
|
1073
|
+
if (!entries.childElementCount) feedback.append(el('p', 'smf-empty', '没有可恢复的技能或技能包。'));
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
if (!active()) return;
|
|
1076
|
+
feedback.replaceChildren(alert(error));
|
|
1077
|
+
await load({ preserveFeedback: true });
|
|
1078
|
+
} finally {
|
|
1079
|
+
if (active()) {
|
|
1080
|
+
working(false);
|
|
1081
|
+
refresh.focus({ preventScroll: true });
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
async function load({ preserveFeedback = false } = {}) {
|
|
1087
|
+
if (loading) return;
|
|
1088
|
+
loading = true;
|
|
1089
|
+
refresh.setAttribute('aria-disabled', 'true');
|
|
1090
|
+
const progress = status('正在读取已删除的技能…', true);
|
|
1091
|
+
if (preserveFeedback) feedback.append(progress);
|
|
1092
|
+
else feedback.replaceChildren(progress);
|
|
1093
|
+
entries.replaceChildren();
|
|
1094
|
+
try {
|
|
1095
|
+
const receipts = await list();
|
|
1096
|
+
if (!active()) return;
|
|
1097
|
+
progress.remove();
|
|
1098
|
+
if (!receipts.length) feedback.append(el('p', 'smf-empty', '没有可恢复的技能或技能包。'));
|
|
1099
|
+
for (const receipt of receipts) {
|
|
1100
|
+
const item = el('li', 'smf-recovery-item');
|
|
1101
|
+
const copy = el('div');
|
|
1102
|
+
const removedAt = Number.isFinite(receipt.removedAt) ? date.format(receipt.removedAt) : '';
|
|
1103
|
+
const kind = receipt.kind === 'package' ? `技能包 · ${receipt.memberCount} 个技能` : '技能';
|
|
1104
|
+
copy.append(el('strong', '', receipt.name), el('div', 'smf-subtitle', [kind, removedAt].filter(Boolean).join(' · ')),
|
|
1105
|
+
el('code', 'smf-mono', receipt.path));
|
|
1106
|
+
item.append(copy);
|
|
1107
|
+
if (receipt.canRestore) {
|
|
1108
|
+
const control = button('恢复', () => recover(receipt, control), 'smf-small');
|
|
1109
|
+
control.setAttribute('aria-label', `恢复 ${receipt.name}`);
|
|
1110
|
+
item.append(control);
|
|
1111
|
+
} else {
|
|
1112
|
+
copy.append(el('p', 'smf-subtitle', receipt.restoreReason || '当前无法恢复。'));
|
|
1113
|
+
}
|
|
1114
|
+
entries.append(item);
|
|
1115
|
+
}
|
|
1116
|
+
} catch (error) {
|
|
1117
|
+
if (active()) {
|
|
1118
|
+
progress.remove();
|
|
1119
|
+
feedback.append(alert(error));
|
|
1120
|
+
}
|
|
1121
|
+
} finally {
|
|
1122
|
+
loading = false;
|
|
1123
|
+
if (active()) refresh.removeAttribute('aria-disabled');
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
done.focus({ preventScroll: true });
|
|
1128
|
+
void load();
|
|
1129
|
+
return { cleanup: () => close(false) };
|
|
1130
|
+
}
|