@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
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
3
|
+
import { chmod, mkdir, mkdtemp, readFile, readdir, realpath, rm, stat, symlink, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { test } from 'node:test'
|
|
7
|
+
import { crc32, deflateRawSync } from 'node:zlib'
|
|
8
|
+
import { createImports } from '../imports.mjs'
|
|
9
|
+
import { withSkillWriteLock } from '../import-commit.mjs'
|
|
10
|
+
import { deriveFamily, FAMILY_MARKER, parseFamilyMarker } from '../import-family.mjs'
|
|
11
|
+
import { limits, parseSkillMetadata } from '../import-files.mjs'
|
|
12
|
+
|
|
13
|
+
const md = (name, description = 'Import fixture', body = 'Do the task.') => `---\nname: ${name}\ndescription: ${description}\n---\n${body}\n`
|
|
14
|
+
const code = expected => error => error.code === expected
|
|
15
|
+
const local = target => ({ type: 'local', path: target })
|
|
16
|
+
|
|
17
|
+
async function fixture(t) {
|
|
18
|
+
const base = await realpath(await mkdtemp(path.join(tmpdir(), 'dsh-import-test-')))
|
|
19
|
+
t.after(() => rm(base, { recursive: true, force: true }))
|
|
20
|
+
const home = path.join(base, 'home'), root = path.join(base, 'library'), project = path.join(base, 'project')
|
|
21
|
+
await Promise.all([mkdir(home), mkdir(root), mkdir(project)])
|
|
22
|
+
const api = createImports({ home })
|
|
23
|
+
t.after(() => api.dispose())
|
|
24
|
+
return { base, root, home, project, api, directory: { id: 'test', path: root, writable: true, kind: 'custom' } }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function put(file, content) {
|
|
28
|
+
await mkdir(path.dirname(file), { recursive: true })
|
|
29
|
+
await writeFile(file, content)
|
|
30
|
+
return file
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Build small ZIPs with controlled central-directory metadata. These tests do
|
|
34
|
+
// not depend on a system zip executable or a separate packaging dependency.
|
|
35
|
+
function zip(entries) {
|
|
36
|
+
const localParts = [], directory = []
|
|
37
|
+
let offset = 0
|
|
38
|
+
for (const item of entries) {
|
|
39
|
+
const name = Buffer.from(item.path), bytes = Buffer.from(item.bytes || ''), compressed = deflateRawSync(bytes)
|
|
40
|
+
const checksum = item.crc ?? crc32(bytes), size = item.size ?? bytes.length
|
|
41
|
+
const header = Buffer.alloc(30), record = Buffer.alloc(46)
|
|
42
|
+
header.writeUInt32LE(0x04034b50, 0); header.writeUInt16LE(20, 4)
|
|
43
|
+
header.writeUInt16LE(8, 8); header.writeUInt32LE(checksum, 14)
|
|
44
|
+
header.writeUInt32LE(compressed.length, 18); header.writeUInt32LE(size, 22); header.writeUInt16LE(name.length, 26)
|
|
45
|
+
record.writeUInt32LE(0x02014b50, 0); record.writeUInt16LE(0x0314, 4); record.writeUInt16LE(20, 6)
|
|
46
|
+
record.writeUInt16LE(8, 10); record.writeUInt32LE(checksum, 16); record.writeUInt32LE(compressed.length, 20)
|
|
47
|
+
record.writeUInt32LE(size, 24); record.writeUInt16LE(name.length, 28)
|
|
48
|
+
record.writeUInt32LE(((item.mode ?? (item.path.endsWith('/') ? 0o040755 : 0o100644)) * 0x10000) >>> 0, 38)
|
|
49
|
+
record.writeUInt32LE(offset, 42)
|
|
50
|
+
localParts.push(header, name, compressed); directory.push(record, name)
|
|
51
|
+
offset += header.length + name.length + compressed.length
|
|
52
|
+
}
|
|
53
|
+
const records = Buffer.concat(directory), end = Buffer.alloc(22)
|
|
54
|
+
end.writeUInt32LE(0x06054b50, 0); end.writeUInt16LE(entries.length, 8); end.writeUInt16LE(entries.length, 10)
|
|
55
|
+
end.writeUInt32LE(records.length, 12); end.writeUInt32LE(offset, 16)
|
|
56
|
+
return Buffer.concat([...localParts, records, end])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test('reads native YAML fields and rejects malformed or incompatible invocation options', () => {
|
|
60
|
+
const text = '---\r\nname: hello-2\r\ndescription: >-\r\n 提取决定:\r\n 负责人和日期。\r\nmetadata:\r\n name: shadow\r\nuser-invocable: OFF\r\ndisable-model-invocation: 1\r\n---\r\nBody'
|
|
61
|
+
assert.deepEqual(parseSkillMetadata(text), { name: 'hello-2', description: '提取决定: 负责人和日期。' })
|
|
62
|
+
for (const invalid of [md('../../wrong'), md('valid', '42'), 'preamble\n' + md('valid'), '---\nmetadata:\n name: shadow\ndescription: test\n---', md('a').replace('name: a', 'name: a\nname: b'), md('a').replace('name: a', 'name: a\nuserInvocable: false'), md('a').replace('name: a', 'name: a\nuser-invocable: maybe')]) {
|
|
63
|
+
assert.throws(() => parseSkillMetadata(invalid), code('INVALID_SKILL'))
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('flat preview snapshots bytes and has a retryable, target-bound receipt', async t => {
|
|
68
|
+
const { api, base, root, directory } = await fixture(t)
|
|
69
|
+
const original = md('meeting-notes', '"A: B"')
|
|
70
|
+
const file = await put(path.join(base, 'Download.MD'), original)
|
|
71
|
+
const preview = await api.preview(local(file))
|
|
72
|
+
assert.equal(preview.description, 'A: B'); assert.equal(preview.format, 'markdown')
|
|
73
|
+
assert.equal(preview.entry, 'meeting-notes.md'); assert.equal(preview.targetRelativePath, 'meeting-notes.md')
|
|
74
|
+
assert.deepEqual(preview.files, ['meeting-notes.md']); assert.deepEqual(await readdir(root), [])
|
|
75
|
+
await writeFile(file, md('changed'))
|
|
76
|
+
const first = await api.commit({ token: preview.token, directory })
|
|
77
|
+
assert.equal(first.path, path.join(root, preview.entry)); assert.equal(first.replaced, false)
|
|
78
|
+
assert.equal(await readFile(first.path, 'utf8'), original)
|
|
79
|
+
assert.deepEqual(await api.commit({ token: preview.token, directory }), first)
|
|
80
|
+
await assert.rejects(api.commit({ token: preview.token, directory: { ...directory, id: 'elsewhere' } }), code('PREVIEW_EXPIRED'))
|
|
81
|
+
await assert.rejects(api.commit({ directory }), code('PREVIEW_EXPIRED'))
|
|
82
|
+
const other = await api.preview(local(file))
|
|
83
|
+
assert.deepEqual(await api.commit({ token: other.token, conflict: 'cancel' }), { cancelled: true })
|
|
84
|
+
await assert.rejects(api.commit({ token: other.token, directory }), code('PREVIEW_EXPIRED'))
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('folder import preserves resources, empty directories, executable flags and layout', async t => {
|
|
88
|
+
const { api, base, directory } = await fixture(t)
|
|
89
|
+
const folder = path.join(base, 'download')
|
|
90
|
+
await put(path.join(folder, 'SKILL.md'), md('layout')); await mkdir(path.join(folder, 'empty'))
|
|
91
|
+
const script = await put(path.join(folder, 'scripts', 'task'), Buffer.from([0, 255, 128, 9]))
|
|
92
|
+
await chmod(script, 0o755); await put(path.join(folder, '.git', 'config'), 'do not copy')
|
|
93
|
+
const preview = await api.preview(local(folder))
|
|
94
|
+
assert.equal(preview.entry, 'SKILL.md'); assert.equal(preview.targetRelativePath, 'layout/SKILL.md')
|
|
95
|
+
assert.deepEqual(preview.files, ['SKILL.md', 'scripts/task'])
|
|
96
|
+
const receipt = await api.commit({ token: preview.token, directory })
|
|
97
|
+
assert.equal(receipt.path, path.join(directory.path, 'layout', 'SKILL.md'))
|
|
98
|
+
const target = path.dirname(receipt.path)
|
|
99
|
+
assert.deepEqual(await readFile(path.join(target, 'scripts/task')), Buffer.from([0, 255, 128, 9]))
|
|
100
|
+
if (process.platform !== 'win32') assert.ok((await stat(path.join(target, 'scripts/task'))).mode & 0o100)
|
|
101
|
+
assert.deepEqual(await readdir(path.join(target, 'empty')), [])
|
|
102
|
+
assert.deepEqual((await readdir(target)).sort(), ['SKILL.md', 'empty', 'scripts'])
|
|
103
|
+
await symlink(script, path.join(folder, 'extra'))
|
|
104
|
+
await assert.rejects(api.preview(local(folder)), code('UNSAFE_PATH'))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('both compressed extensions accept root or wrapped skills and validate every member before writing', async t => {
|
|
108
|
+
const { base, api, directory } = await fixture(t)
|
|
109
|
+
for (const [extension, prefix, name] of [['skill', 'download/', 'pack-a'], ['zip', '', 'pack-b']]) {
|
|
110
|
+
const file = await put(path.join(base, `data.${extension}`), zip([
|
|
111
|
+
{ path: `${prefix}SKILL.md`, bytes: md(name) }, { path: `${prefix}assets/empty/` },
|
|
112
|
+
{ path: `${prefix}run`, bytes: Buffer.from([42, 0, 240]), mode: 0o100755 },
|
|
113
|
+
{ path: '__MACOSX/._source', bytes: 'metadata' },
|
|
114
|
+
]))
|
|
115
|
+
const preview = await api.preview(local(file))
|
|
116
|
+
assert.equal(preview.format, 'archive'); assert.equal(preview.entry, 'SKILL.md')
|
|
117
|
+
assert.deepEqual(preview.files, ['SKILL.md', 'run'])
|
|
118
|
+
const receipt = await api.commit({ token: preview.token, directory })
|
|
119
|
+
assert.deepEqual(await readFile(path.join(path.dirname(receipt.path), 'run')), Buffer.from([42, 0, 240]))
|
|
120
|
+
assert.deepEqual(await readdir(path.join(path.dirname(receipt.path), 'assets/empty')), [])
|
|
121
|
+
}
|
|
122
|
+
const main = { path: 'a/SKILL.md', bytes: md('ok') }
|
|
123
|
+
for (const addition of [
|
|
124
|
+
{ path: '../outside' }, { path: '/absolute' }, { path: 'a\\other' }, { path: 'a/file:stream' },
|
|
125
|
+
{ path: 'a/link', bytes: '../somewhere', mode: 0o120777 }, { path: 'a/sKILL.md' },
|
|
126
|
+
{ path: 'a/SKILL.md/file' },
|
|
127
|
+
{ path: 'a/big', size: limits.file + 1 }, { path: 'a/bad-crc', bytes: 'source', crc: 0 },
|
|
128
|
+
]) {
|
|
129
|
+
const file = await put(path.join(base, 'rejected.skill'), zip([main, addition]))
|
|
130
|
+
await assert.rejects(api.preview(local(file)), failure => ['UNSAFE_PATH', 'UNSAFE_ARCHIVE', 'INVALID_ARCHIVE', 'SIZE_LIMIT'].includes(failure.code), addition.path)
|
|
131
|
+
}
|
|
132
|
+
assert.deepEqual((await readdir(directory.path)).sort(), ['pack-a', 'pack-b'])
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('local folders, extracted wrappers, ZIP and .skill preserve the same family with its shared files', async t => {
|
|
136
|
+
const { api, base, directory } = await fixture(t)
|
|
137
|
+
const origin = path.join(base, 'source', 'field-kit')
|
|
138
|
+
const disabled = md('format-report', 'Format reports').replace('name: format-report', 'name: format-report\ndisable-model-invocation: yes\nuser-invocable: false')
|
|
139
|
+
const contents = {
|
|
140
|
+
'README.md': '# Field Kit\n\nTools for observation and reporting.\n',
|
|
141
|
+
'docs/guide.md': 'shared instructions', 'LICENSE': 'license', 'assets/icon.bin': Buffer.from([0, 255, 190]),
|
|
142
|
+
'skills/observe/SKILL.md': md('observe'), 'skills/report/SKILL.md': disabled,
|
|
143
|
+
'skills/report/references/sample/SKILL.md': md('resource'), 'automations/other/skills/helper/SKILL.md': md('ancillary'),
|
|
144
|
+
}
|
|
145
|
+
for (const [relative, content] of Object.entries(contents)) await put(path.join(origin, relative), content)
|
|
146
|
+
await mkdir(path.join(origin, 'empty'))
|
|
147
|
+
const expectFiles = Object.keys(contents).sort()
|
|
148
|
+
for (const [index, variant] of ['folder', 'extracted-wrapper', 'zip', 'skill'].entries()) {
|
|
149
|
+
const prefix = variant === 'zip' ? 'field-kit-main/' : ''
|
|
150
|
+
const request = variant === 'folder' ? origin : variant === 'extracted-wrapper' ? path.dirname(origin) : await put(path.join(base, `download.${variant}`), zip([
|
|
151
|
+
...Object.entries(contents).map(([file, bytes]) => ({ path: prefix + file, bytes })), { path: prefix + 'empty/' },
|
|
152
|
+
]))
|
|
153
|
+
const target = { ...directory, path: path.join(directory.path, `test-${index}`) }
|
|
154
|
+
await mkdir(target.path)
|
|
155
|
+
const preview = await api.preview(local(request))
|
|
156
|
+
assert.equal(preview.kind, 'family'); assert.equal(preview.name, 'Field Kit'); assert.equal(preview.description, 'Tools for observation and reporting.')
|
|
157
|
+
assert.equal(preview.entry, 'README.md'); assert.equal(preview.targetRelativePath, 'field-kit'); assert.deepEqual(preview.files, expectFiles)
|
|
158
|
+
assert.deepEqual(preview.members.map(({ name, entry }) => [name, entry]), [['observe', 'skills/observe/SKILL.md'], ['format-report', 'skills/report/SKILL.md']])
|
|
159
|
+
assert.deepEqual(preview.members[1].invocation, { modelInvocable: false, userInvocable: false })
|
|
160
|
+
// An RPC client never gets mutable references into the preview token.
|
|
161
|
+
preview.family.id = '../changed'; preview.members[1].entry = 'wrong.md'
|
|
162
|
+
const result = await api.commit({ token: preview.token, directory: target, enabled: false })
|
|
163
|
+
assert.deepEqual(await readdir(target.path), ['field-kit']); assert.equal(result.familyRoot, path.join(target.path, 'field-kit'))
|
|
164
|
+
assert.equal(result.path, path.join(result.familyRoot, 'README.md')); assert.equal(result.family.enabled, false); assert.equal(result.enabled, false)
|
|
165
|
+
for (const [relative, data] of Object.entries(contents)) assert.deepEqual(await readFile(path.join(result.familyRoot, relative)), Buffer.from(data))
|
|
166
|
+
assert.deepEqual(await readdir(path.join(result.familyRoot, 'empty')), [])
|
|
167
|
+
assert.equal(result.members[1].path, path.join(result.familyRoot, 'skills/report/SKILL.md'))
|
|
168
|
+
const marker = parseFamilyMarker(await readFile(path.join(result.familyRoot, FAMILY_MARKER), 'utf8'))
|
|
169
|
+
assert.equal(marker.enabled, false); assert.equal(marker.id, 'field-kit'); assert.equal(marker.source.label, path.basename(request))
|
|
170
|
+
assert.deepEqual(marker.members.map(item => item.entry), ['skills/observe/SKILL.md', 'skills/report/SKILL.md'])
|
|
171
|
+
const restarted = createImports(); t.after(() => restarted.dispose())
|
|
172
|
+
const later = await restarted.preview(local(result.familyRoot))
|
|
173
|
+
assert.equal(later.family.enabled, false); assert.deepEqual(later.members.map(item => item.invocation), result.members.map(item => item.invocation))
|
|
174
|
+
assert.deepEqual(later.files, expectFiles)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('separates native skill attachments, plain sibling families and ambiguous membership', async t => {
|
|
179
|
+
const { api, base, directory } = await fixture(t)
|
|
180
|
+
const single = path.join(base, 'single')
|
|
181
|
+
await put(path.join(single, 'SKILL.md'), md('ordinary'))
|
|
182
|
+
await put(path.join(single, 'examples/more/SKILL.md'), md('example'))
|
|
183
|
+
await put(path.join(single, 'references/SKILL.md'), 'example without YAML')
|
|
184
|
+
await put(path.join(single, 'scripts/reusable/SKILL.md'), md('script'))
|
|
185
|
+
await put(path.join(single, 'examples/skills/x/SKILL.md'), md('nested-example'))
|
|
186
|
+
const legacy = await api.preview(local(single))
|
|
187
|
+
assert.equal(legacy.family, undefined); assert.equal(legacy.entry, 'SKILL.md'); assert.equal(legacy.files.length, 5)
|
|
188
|
+
|
|
189
|
+
const bundle = path.join(base, 'plain-kit')
|
|
190
|
+
await put(path.join(bundle, 'a/SKILL.md'), md('one')); await put(path.join(bundle, 'b/SKILL.md'), md('two'))
|
|
191
|
+
await put(path.join(bundle, 'a/assets/manual/SKILL.md'), md('nested')); await put(path.join(bundle, 'docs/examples/SKILL.md'), 'sample')
|
|
192
|
+
const family = await api.preview(local(bundle))
|
|
193
|
+
assert.equal(family.targetRelativePath, 'plain-kit'); assert.equal(family.entry, 'a/SKILL.md'); assert.deepEqual(family.members.map(item => item.name), ['one', 'two'])
|
|
194
|
+
await api.commit({ token: family.token, conflict: 'cancel' }); assert.deepEqual(await readdir(directory.path), [])
|
|
195
|
+
await put(path.join(bundle, 'b/SKILL.md'), md('one'))
|
|
196
|
+
await assert.rejects(api.preview(local(bundle)), code('INVALID_FAMILY'))
|
|
197
|
+
await put(path.join(bundle, 'b/SKILL.md'), md('two'))
|
|
198
|
+
await put(path.join(bundle, FAMILY_MARKER), '{}')
|
|
199
|
+
await assert.rejects(api.preview(local(bundle)), code('INVALID_FAMILY'))
|
|
200
|
+
assert.deepEqual(await readdir(directory.path), [])
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('family replacement confirms the whole target and carries forward restricted member policies', async t => {
|
|
204
|
+
const { api, base, directory } = await fixture(t)
|
|
205
|
+
const source = path.join(base, 'my-kit')
|
|
206
|
+
const policy = md('one', 'old').replace('name: one', 'name: one\ndisable-model-invocation: yes\nuser-invocable: false')
|
|
207
|
+
await put(path.join(source, 'a/SKILL.md'), policy); await put(path.join(source, 'b/SKILL.md'), md('two'))
|
|
208
|
+
await put(path.join(source, 'README.md'), '# My Kit\n')
|
|
209
|
+
const initial = await api.preview(local(source))
|
|
210
|
+
const old = await api.commit({ token: initial.token, directory, enabled: false })
|
|
211
|
+
const next = path.join(source, 'new-path/SKILL.md')
|
|
212
|
+
await rm(path.join(source, 'a'), { recursive: true }); await put(next, md('one', 'new description', 'updated body'))
|
|
213
|
+
await put(path.join(source, 'c/SKILL.md'), md('three').replace('name: three', 'name: three\nuser-invocable: false'))
|
|
214
|
+
const preview = await api.preview(local(source))
|
|
215
|
+
const args = { token: preview.token, directory, conflict: 'replace' }
|
|
216
|
+
await assert.rejects(api.commit(args), error => error.code === 'CONFLICT' && error.existingPath === old.familyRoot && error.targetPath === old.familyRoot)
|
|
217
|
+
await put(path.join(old.familyRoot, 'shared-edited.txt'), 'concurrent user edit')
|
|
218
|
+
await assert.rejects(api.commit(args), code('CONFLICT'))
|
|
219
|
+
assert.equal(await readFile(path.join(old.familyRoot, 'a/SKILL.md'), 'utf8'), policy)
|
|
220
|
+
await put(next, 'source changed after preview')
|
|
221
|
+
if (process.platform === 'win32') {
|
|
222
|
+
await assert.rejects(api.commit(args), code('ATOMIC_REPLACE_UNAVAILABLE')); return
|
|
223
|
+
}
|
|
224
|
+
const saved = await api.commit(args)
|
|
225
|
+
assert.equal(saved.replaced, true); assert.equal(saved.family.enabled, false)
|
|
226
|
+
assert.deepEqual(saved.members.find(item => item.name === 'one').invocation, { modelInvocable: false, userInvocable: false })
|
|
227
|
+
assert.deepEqual(saved.members.find(item => item.name === 'three').invocation, { modelInvocable: true, userInvocable: false })
|
|
228
|
+
const installed = await readFile(path.join(saved.familyRoot, 'new-path/SKILL.md'), 'utf8')
|
|
229
|
+
assert.match(installed, /updated body/); assert.equal(parseSkillMetadata(installed).description, 'new description')
|
|
230
|
+
assert.deepEqual(parseSkillMetadata(installed, { invocation: true }).invocation, { modelInvocable: false, userInvocable: false })
|
|
231
|
+
assert.deepEqual((await readdir(directory.path)).sort(), ['my-kit']); assert.equal(parseFamilyMarker(await readFile(path.join(saved.familyRoot, FAMILY_MARKER), 'utf8')).enabled, false)
|
|
232
|
+
saved.members[0].name = 'altered'; assert.notEqual((await api.commit(args)).members[0].name, 'altered')
|
|
233
|
+
await assert.rejects(api.commit({ ...args, enabled: true }), code('ALREADY_SAVED'))
|
|
234
|
+
|
|
235
|
+
const replay = await api.preview(local(saved.familyRoot))
|
|
236
|
+
const stored = { ...parseFamilyMarker(await readFile(path.join(saved.familyRoot, FAMILY_MARKER), 'utf8')), extra: { keep: true } }
|
|
237
|
+
await put(path.join(saved.familyRoot, FAMILY_MARKER), JSON.stringify(stored))
|
|
238
|
+
const other = { ...directory, path: path.join(base, 'another') }; await mkdir(other.path)
|
|
239
|
+
const preserved = await api.preview(local(saved.familyRoot))
|
|
240
|
+
const reimported = await api.commit({ token: preserved.token, directory: other, enabled: true })
|
|
241
|
+
assert.equal(reimported.family.enabled, true)
|
|
242
|
+
assert.deepEqual(parseFamilyMarker(await readFile(path.join(reimported.familyRoot, FAMILY_MARKER), 'utf8')).extra, { keep: true })
|
|
243
|
+
assert.equal(reimported.members.find(item => item.name === 'one').invocation.modelInvocable, false)
|
|
244
|
+
await api.commit({ token: replay.token, conflict: 'cancel' })
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
test('a family rejects unrelated target directories and unsafe or incomplete persisted manifests', async t => {
|
|
248
|
+
const { api, base, directory } = await fixture(t)
|
|
249
|
+
const source = path.join(base, 'checked')
|
|
250
|
+
await put(path.join(source, 'skills/a/SKILL.md'), md('a')); await put(path.join(source, 'skills/b/SKILL.md'), md('b'))
|
|
251
|
+
const incoming = await api.preview(local(source))
|
|
252
|
+
await put(path.join(directory.path, 'checked/notes.md'), 'unrelated')
|
|
253
|
+
await assert.rejects(api.commit({ token: incoming.token, directory, conflict: 'replace' }), code('TARGET_OCCUPIED'))
|
|
254
|
+
assert.equal(await readFile(path.join(directory.path, 'checked/notes.md'), 'utf8'), 'unrelated')
|
|
255
|
+
const valid = { version: 1, id: 'checked', name: 'Checked', description: 'Two skills', entry: 'skills/a/SKILL.md', enabled: false,
|
|
256
|
+
source: { format: 'folder', label: 'checked' }, members: [{ name: 'a', entry: 'skills/a/SKILL.md' }, { name: 'b', entry: 'skills/b/SKILL.md' }] }
|
|
257
|
+
for (const marker of [ { ...valid, members: [{ name: 'a', entry: '../SKILL.md' }, valid.members[1]] }, { ...valid, entry: 'missing.md' },
|
|
258
|
+
{ ...valid, members: [valid.members[0], { ...valid.members[1], name: 'wrong' }]}, { ...valid, members: [valid.members[0], { name: 'x', entry: 'other/SKILL.md' }] } ]) {
|
|
259
|
+
await put(path.join(source, FAMILY_MARKER), JSON.stringify(marker))
|
|
260
|
+
await assert.rejects(api.preview(local(source)), error => ['INVALID_FAMILY','UNSAFE_PATH'].includes(error.code))
|
|
261
|
+
}
|
|
262
|
+
assert.throws(() => deriveFamily([{ path: FAMILY_MARKER.toUpperCase(), bytes: Buffer.from('{}') }]), code('INVALID_FAMILY'))
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test('discovers six tool scopes, surfaces invalid entries, binds selections to their source', async t => {
|
|
266
|
+
const { api, home, project } = await fixture(t)
|
|
267
|
+
await mkdir(path.join(project, '.git')); const cwd = path.join(project, 'nested/app'); await mkdir(cwd, { recursive: true })
|
|
268
|
+
let saved
|
|
269
|
+
for (const [tool, config] of Object.entries({ claude: '.claude', codex: '.agents', gemini: '.gemini' })) {
|
|
270
|
+
for (const scope of ['user', 'project']) {
|
|
271
|
+
const root = path.join(scope === 'user' ? home : project, config, 'skills')
|
|
272
|
+
await put(path.join(root, 'named-differently/SKILL.md'), md(`${tool}-${scope}`))
|
|
273
|
+
await put(path.join(root, 'broken.md'), 'missing YAML')
|
|
274
|
+
const request = { type: 'tool', tool, scope, cwd }
|
|
275
|
+
const result = await api.candidates(request)
|
|
276
|
+
assert.equal(result.sourcePath, root); assert.equal(result.warnings.length, 1); assert.equal(result.items.length, 1)
|
|
277
|
+
const [item] = result.items
|
|
278
|
+
assert.equal(item.name, `${tool}-${scope}`); assert.equal(item.format, 'folder')
|
|
279
|
+
const preview = await api.preview({ ...request, id: item.id })
|
|
280
|
+
assert.equal(preview.sourcePath, path.join(root, 'named-differently'))
|
|
281
|
+
if (!saved) saved = { ...request, id: item.id }
|
|
282
|
+
else await assert.rejects(api.preview({ ...request, id: saved.id }), code('CANDIDATE_EXPIRED'))
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const changed = path.join(home, '.claude/skills/named-differently/SKILL.md')
|
|
286
|
+
await writeFile(changed, md('different'))
|
|
287
|
+
await assert.rejects(api.preview(saved), code('SOURCE_CHANGED'))
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
test('external tool catalogs offer an extracted family as one candidate alongside individual skills', async t => {
|
|
291
|
+
const { api, directory, home } = await fixture(t)
|
|
292
|
+
const provider = { type: 'tool', tool: 'claude', scope: 'user' }
|
|
293
|
+
const providerRoot = path.join(home, '.claude/skills')
|
|
294
|
+
const root = path.join(providerRoot, 'research-kit')
|
|
295
|
+
await put(path.join(root, 'README.md'), '# Research Kit\n\nGather and summarize.')
|
|
296
|
+
await put(path.join(root, 'skills/data/SKILL.md'), md('collect'))
|
|
297
|
+
await put(path.join(root, 'skills/report/SKILL.md'), md('summarize'))
|
|
298
|
+
await put(path.join(root, 'docs/guide.txt'), 'shared')
|
|
299
|
+
await put(path.join(providerRoot, 'individual/SKILL.md'), md('individual'))
|
|
300
|
+
await put(path.join(providerRoot, 'individual/examples/nested/SKILL.md'), md('example'))
|
|
301
|
+
const found = await api.candidates(provider)
|
|
302
|
+
assert.deepEqual(found.warnings, []); assert.equal(found.items.length, 2)
|
|
303
|
+
const item = found.items.find(item => item.kind === 'family'); assert.equal(item.memberCount, 2); assert.equal(item.name, 'Research Kit')
|
|
304
|
+
assert.equal(item.instructionPath, path.join(root, 'README.md'))
|
|
305
|
+
const solo = await api.preview({ ...provider, id: found.items.find(item => item.name === 'individual').id })
|
|
306
|
+
assert.equal(solo.family, undefined); assert.equal(solo.files.length, 2)
|
|
307
|
+
const preview = await api.preview({ ...provider, id: item.id })
|
|
308
|
+
assert.equal(preview.kind, 'family'); assert.equal(preview.entry, 'README.md'); assert.equal(preview.members.length, 2)
|
|
309
|
+
const saved = await api.commit({ token: preview.token, directory }); assert.equal(await readFile(path.join(saved.familyRoot, 'docs/guide.txt'), 'utf8'), 'shared')
|
|
310
|
+
await put(path.join(root, 'skills/report/SKILL.md'), md('changed'))
|
|
311
|
+
await assert.rejects(api.preview({ ...provider, id: item.id }), code('SOURCE_CHANGED'))
|
|
312
|
+
|
|
313
|
+
const codexRoot = path.join(home, '.agents/skills')
|
|
314
|
+
await mkdir(codexRoot, { recursive: true })
|
|
315
|
+
const copy = await api.preview(local(saved.familyRoot)); await api.commit({ token: copy.token, directory: { ...directory, path: codexRoot }, enabled: false })
|
|
316
|
+
const codex = { type: 'tool', tool: 'codex', scope: 'user' }
|
|
317
|
+
const registered = await api.candidates(codex); assert.equal(registered.items.length, 1); assert.equal(registered.items[0].memberCount, 2)
|
|
318
|
+
assert.equal((await api.preview({ ...codex, id: registered.items[0].id })).family.enabled, false)
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
test('requires confirmation of the exact duplicate contents and destination, including aliases', async t => {
|
|
322
|
+
const { api, base, directory } = await fixture(t)
|
|
323
|
+
const source = await put(path.join(base, 'download.md'), md('repeat', 'new'))
|
|
324
|
+
const preview = await api.preview(local(source))
|
|
325
|
+
const alternate = await put(path.join(directory.path, 'alias', 'SKILL.md'), md('repeat', 'old'))
|
|
326
|
+
const accessory = await put(path.join(directory.path, 'alias', 'assets', 'template'), 'one')
|
|
327
|
+
const replace = { token: preview.token, directory, conflict: 'replace' }
|
|
328
|
+
await assert.rejects(api.commit(replace), error => error.code === 'CONFLICT' && error.existingPath === alternate)
|
|
329
|
+
const secondRoot = path.join(base, 'other'); await mkdir(secondRoot)
|
|
330
|
+
await put(path.join(secondRoot, 'repeat.md'), md('repeat', 'another'))
|
|
331
|
+
await assert.rejects(api.commit({ ...replace, directory: { ...directory, path: secondRoot, id: 'other' } }), code('CONFLICT'))
|
|
332
|
+
await assert.rejects(api.commit(replace), code('CONFLICT'))
|
|
333
|
+
await writeFile(accessory, 'edited since confirmation')
|
|
334
|
+
await assert.rejects(api.commit(replace), code('CONFLICT'))
|
|
335
|
+
assert.equal(await readFile(accessory, 'utf8'), 'edited since confirmation')
|
|
336
|
+
const saved = await api.commit(replace)
|
|
337
|
+
assert.equal(saved.path, path.join(directory.path, 'repeat.md')); assert.equal(saved.replaced, true)
|
|
338
|
+
assert.deepEqual(await readdir(directory.path), ['repeat.md'])
|
|
339
|
+
assert.equal(await readFile(saved.path, 'utf8'), md('repeat', 'new'))
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
test('protects unrelated files, occupied directories, symlinks and ambiguous duplicates', async t => {
|
|
343
|
+
const { api, base, root, directory } = await fixture(t)
|
|
344
|
+
const file = await put(path.join(base, 'doc.md'), md('same'))
|
|
345
|
+
const { token } = await api.preview(local(file))
|
|
346
|
+
const target = await put(path.join(root, 'same.md'), 'user notes')
|
|
347
|
+
await assert.rejects(api.commit({ token, directory, conflict: 'replace' }), code('TARGET_OCCUPIED'))
|
|
348
|
+
assert.equal(await readFile(target, 'utf8'), 'user notes')
|
|
349
|
+
await writeFile(target, md('different'))
|
|
350
|
+
await assert.rejects(api.commit({ token, directory }), code('TARGET_OCCUPIED'))
|
|
351
|
+
await writeFile(target, md('same'))
|
|
352
|
+
await put(path.join(root, 'alias.md'), md('same'))
|
|
353
|
+
await assert.rejects(api.commit({ token, directory }), code('TARGET_OCCUPIED'))
|
|
354
|
+
const outside = path.join(base, 'private'); await mkdir(outside)
|
|
355
|
+
const alias = path.join(base, 'linked-destination'); await symlink(outside, alias)
|
|
356
|
+
await assert.rejects(api.commit({ token, directory: { ...directory, path: alias } }), code('INVALID_TARGET'))
|
|
357
|
+
assert.deepEqual(await readdir(outside), [])
|
|
358
|
+
const bundle = path.join(base, 'folder'); await put(path.join(bundle, 'SKILL.md'), md('occupied'))
|
|
359
|
+
await mkdir(path.join(root, 'occupied'))
|
|
360
|
+
const another = await api.preview(local(bundle))
|
|
361
|
+
await assert.rejects(api.commit({ token: another.token, directory }), code('TARGET_OCCUPIED'))
|
|
362
|
+
assert.deepEqual(await readdir(path.join(root, 'occupied')), [])
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
test('serializes simultaneous single-file and folder imports and releases failed policy-edit locks', async t => {
|
|
366
|
+
const { api, base, home, directory } = await fixture(t)
|
|
367
|
+
const second = createImports({ home }); t.after(() => second.dispose())
|
|
368
|
+
const file = await put(path.join(base, 'download.md'), md('shared'))
|
|
369
|
+
const folder = path.join(base, 'folder'); await put(path.join(folder, 'SKILL.md'), md('shared'))
|
|
370
|
+
const [a, b] = await Promise.all([api.preview(local(file)), second.preview(local(folder))])
|
|
371
|
+
const results = await Promise.allSettled([api.commit({ token: a.token, directory }), second.commit({ token: b.token, directory })])
|
|
372
|
+
assert.equal(results.filter(row => row.status === 'fulfilled').length, 1)
|
|
373
|
+
assert.equal(results.find(row => row.status === 'rejected').reason.code, 'CONFLICT')
|
|
374
|
+
assert.equal((await readdir(directory.path)).length, 1)
|
|
375
|
+
await assert.rejects(withSkillWriteLock(directory.path, 'shared', () => { throw Error('fixture') }), /fixture/)
|
|
376
|
+
assert.equal(await withSkillWriteLock(directory.path, 'shared', () => 123), 123)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
test('creates missing personal roots only through a trusted writable target', async t => {
|
|
380
|
+
const { api, base, home } = await fixture(t)
|
|
381
|
+
const file = await put(path.join(base, 'one.md'), md('first'))
|
|
382
|
+
const { token } = await api.preview(local(file)); const root = path.join(home, '.dsh', 'skills')
|
|
383
|
+
await assert.rejects(api.commit({ token, directory: { id: 'custom', path: root, writable: true, kind: 'custom' } }), code('INVALID_TARGET'))
|
|
384
|
+
await assert.rejects(api.commit({ token, directory: { id: 'default', path: root, writable: false, kind: 'personal' } }), code('INVALID_TARGET'))
|
|
385
|
+
await api.commit({ token, directory: { id: 'default', path: root, writable: true, kind: 'personal' } })
|
|
386
|
+
assert.deepEqual(await readdir(root), ['first.md'])
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
test('expires tokens without writing and reclaims disposed sessions', async t => {
|
|
390
|
+
const { api, base, directory } = await fixture(t)
|
|
391
|
+
const { token } = await api.preview(local(await put(path.join(base, 'one.md'), md('one'))))
|
|
392
|
+
const later = Date.now() + 16 * 60 * 1000
|
|
393
|
+
t.mock.method(Date, 'now', () => later)
|
|
394
|
+
await assert.rejects(api.commit({ token, directory }), code('PREVIEW_EXPIRED'))
|
|
395
|
+
const again = await api.preview(local(path.join(base, 'one.md')))
|
|
396
|
+
api.dispose()
|
|
397
|
+
await assert.rejects(api.commit({ token: again.token, directory }), code('PREVIEW_EXPIRED'))
|
|
398
|
+
assert.deepEqual(await readdir(directory.path), [])
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
function repository({ ref = 'main', link = false, truncated = false, rateLimited = false } = {}) {
|
|
402
|
+
const revision = 'a'.repeat(40), skillsTree = 'b'.repeat(40), oneTree = 'c'.repeat(40), twoTree = 'd'.repeat(40)
|
|
403
|
+
const api = 'https://api.github.com/repos/public/examples', raw = `https://raw.githubusercontent.com/public/examples/${revision}/`
|
|
404
|
+
const files = new Map([
|
|
405
|
+
['skills/download/SKILL.md', Buffer.from(md('remote-skill', '"Quoted remote: description"'))],
|
|
406
|
+
['skills/download/bin/tool', Buffer.from([255, 0, 1, 2])],
|
|
407
|
+
['skills/other/SKILL.md', Buffer.from(md('other'))], ['skills/invalid/SKILL.md', Buffer.from('missing fields')],
|
|
408
|
+
])
|
|
409
|
+
function blob(file) {
|
|
410
|
+
const bytes = files.get(file)
|
|
411
|
+
return { path: file, type: 'blob', mode: file.endsWith('/tool') ? '100755' : '100644', size: bytes.length,
|
|
412
|
+
sha: createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex'), url: 'https://invalid.example/ignored' }
|
|
413
|
+
}
|
|
414
|
+
const dir = (path, sha) => ({ path, type: 'tree', mode: '040000', sha })
|
|
415
|
+
const tree = [dir('skills', skillsTree), dir('skills/download', oneTree), dir('skills/other', twoTree), ...[...files.keys()].map(blob)]
|
|
416
|
+
if (link) tree.push({ path: 'skills/download/linked', type: 'blob', mode: '120000', size: 6, sha: '1'.repeat(40) })
|
|
417
|
+
let current = revision
|
|
418
|
+
const requests = []
|
|
419
|
+
const json = object => new Response(JSON.stringify(object), { headers: { 'content-type': 'application/json' } })
|
|
420
|
+
async function fetch(url, options) {
|
|
421
|
+
const destination = new URL(url)
|
|
422
|
+
assert.ok(['api.github.com', 'raw.githubusercontent.com'].includes(destination.hostname))
|
|
423
|
+
assert.equal(options.redirect, 'error'); assert.equal(options.credentials, 'omit')
|
|
424
|
+
assert.deepEqual(Object.keys(options.headers), ['Accept']); assert.ok(options.signal instanceof AbortSignal)
|
|
425
|
+
requests.push(url)
|
|
426
|
+
if (rateLimited) return new Response('', { status: 429 })
|
|
427
|
+
if (url === api) return json({ private: false, default_branch: ref })
|
|
428
|
+
if (url.startsWith(`${api}/commits/`)) {
|
|
429
|
+
assert.equal(options.headers.Accept, 'application/vnd.github.sha')
|
|
430
|
+
return decodeURIComponent(url.slice(`${api}/commits/`.length)) === ref ? new Response(current) : new Response('', { status: 422 })
|
|
431
|
+
}
|
|
432
|
+
if (url === `${api}/git/trees/${revision}`) return json({ tree: [dir('skills', skillsTree)] })
|
|
433
|
+
if (url === `${api}/git/trees/${skillsTree}`) return json({ tree: [dir('download', oneTree), dir('other', twoTree)] })
|
|
434
|
+
if (url.endsWith('?recursive=1')) {
|
|
435
|
+
const prefix = url.includes(oneTree) ? 'skills/download/' : url.includes(skillsTree) ? 'skills/' : ''
|
|
436
|
+
return json({ truncated, tree: tree.filter(item => item.path.startsWith(prefix)).map(item => ({ ...item, path: item.path.slice(prefix.length) })) })
|
|
437
|
+
}
|
|
438
|
+
if (url.startsWith(raw)) {
|
|
439
|
+
const bytes = files.get(decodeURIComponent(url.slice(raw.length)))
|
|
440
|
+
if (bytes) return new Response(bytes)
|
|
441
|
+
}
|
|
442
|
+
throw Error(`unexpected fixture request ${url}`)
|
|
443
|
+
}
|
|
444
|
+
return { revision, files, requests, fetch, advance() { current = 'f'.repeat(40) } }
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
test('public GitHub listing reads real YAML and stages only the selected immutable subtree', async t => {
|
|
448
|
+
const { home, directory } = await fixture(t), repo = repository()
|
|
449
|
+
const api = createImports({ home, fetch: repo.fetch }); t.after(() => api.dispose())
|
|
450
|
+
const source = { type: 'github', url: 'https://github.com/public/examples' }
|
|
451
|
+
const found = await api.candidates(source)
|
|
452
|
+
assert.deepEqual(found.items.map(item => item.name), ['remote-skill', 'other'])
|
|
453
|
+
assert.equal(found.items[0].path, 'skills/download'); assert.equal(found.warnings.length, 1)
|
|
454
|
+
assert.equal(found.items[0].description, 'Quoted remote: description')
|
|
455
|
+
repo.advance()
|
|
456
|
+
const preview = await api.preview({ ...source, id: found.items[0].id })
|
|
457
|
+
assert.equal(preview.revision, repo.revision); assert.deepEqual(preview.files, ['SKILL.md', 'bin/tool'])
|
|
458
|
+
const imported = await api.commit({ token: preview.token, directory })
|
|
459
|
+
assert.deepEqual(await readFile(path.join(path.dirname(imported.path), 'bin/tool')), repo.files.get('skills/download/bin/tool'))
|
|
460
|
+
await assert.rejects(api.preview({ ...source, url: 'https://github.com/another/repo', id: found.items[0].id }), code('CANDIDATE_EXPIRED'))
|
|
461
|
+
const fetched = repo.requests.filter(url => url.includes('raw.githubusercontent.com'))
|
|
462
|
+
assert.ok(fetched.every(url => url.includes(repo.revision))); assert.equal(fetched.length, 4)
|
|
463
|
+
})
|
|
464
|
+
|
|
465
|
+
test('GitHub subtree URLs resolve slash-containing branches, tags and a single direct preview', async t => {
|
|
466
|
+
for (const ref of ['feature/review', 'v1.2.3']) {
|
|
467
|
+
const repo = repository({ ref })
|
|
468
|
+
const api = createImports({ fetch: repo.fetch }); t.after(() => api.dispose())
|
|
469
|
+
const source = { type: 'github', url: `https://github.com/public/examples/tree/${ref}/skills/download` }
|
|
470
|
+
const preview = await api.preview(source)
|
|
471
|
+
assert.equal(preview.name, 'remote-skill'); assert.equal(preview.ref, ref)
|
|
472
|
+
assert.deepEqual(preview.files, ['SKILL.md', 'bin/tool'])
|
|
473
|
+
assert.ok(repo.requests.some(url => url.endsWith(`commits/${encodeURIComponent(ref)}`)))
|
|
474
|
+
assert.ok(!repo.requests.some(url => url.includes('raw.githubusercontent.com') && url.includes('/other/')))
|
|
475
|
+
}
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
test('rejects foreign hosts, truncation, special Git entries and HTTP quotas without a destination write', async t => {
|
|
479
|
+
const { directory } = await fixture(t)
|
|
480
|
+
let calls = 0
|
|
481
|
+
const denied = createImports({ fetch() { calls++; throw Error('unexpected network') } }); t.after(() => denied.dispose())
|
|
482
|
+
for (const url of ['http://github.com/org/repo', 'https://github.com@other.example/x/y', 'https://user@github.com/org/repo', 'https://github.com:8123/org/repo', 'https://example.net/org/repo', 'file:///etc/passwd', 'https://github.com/org/repo/issues']) {
|
|
483
|
+
await assert.rejects(denied.candidates({ type: 'github', url }), code('INVALID_URL'))
|
|
484
|
+
}
|
|
485
|
+
assert.equal(calls, 0)
|
|
486
|
+
for (const [config, expected] of [[{ link: true }, 'UNSAFE_PATH'], [{ truncated: true }, 'SIZE_LIMIT'], [{ rateLimited: true }, 'GITHUB_HTTP']]) {
|
|
487
|
+
const api = createImports({ fetch: repository(config).fetch }); t.after(() => api.dispose())
|
|
488
|
+
await assert.rejects(api.preview({ type: 'github', url: 'https://github.com/public/examples/tree/main/skills/download' }), code(expected))
|
|
489
|
+
}
|
|
490
|
+
assert.deepEqual(await readdir(directory.path), [])
|
|
491
|
+
})
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import test from 'node:test'
|
|
3
|
+
import { builtinPreview, indexInventory, inventoryResults } from '../inventory.mjs'
|
|
4
|
+
import { AGENT_FILTERS, matchesSkillState, modeName, skillState } from '../skill-state.mjs'
|
|
5
|
+
|
|
6
|
+
const bundle = { id: 'toolkit-1', name: 'local-tools', label: '本地工具包', description: '本地文档助手' }
|
|
7
|
+
const rows = [
|
|
8
|
+
{ id: 'a', name: 'organize', description: '整理索引', enabled: true, category: 'user', package: bundle, updatedAt: 10 },
|
|
9
|
+
{ id: 'b', name: 'review', description: '校对', enabled: false, category: 'user', package: bundle, updatedAt: 30 },
|
|
10
|
+
{ id: 'c', name: 'organize-extra', enabled: true, category: 'user', package: null, updatedAt: 20 },
|
|
11
|
+
]
|
|
12
|
+
const packages = indexInventory(rows)
|
|
13
|
+
const get = options => inventoryResults(rows, packages, options)
|
|
14
|
+
|
|
15
|
+
test('aggregate an unpacked toolkit by stable identity and leave independently installed skills visible', () => {
|
|
16
|
+
assert.deepEqual(get().cards.map(card => card.id), [bundle.id, 'c'])
|
|
17
|
+
assert.equal(get().cards[0].total, 2)
|
|
18
|
+
assert.equal(get().skillCount, 3)
|
|
19
|
+
assert.equal(get().packageCount, 1)
|
|
20
|
+
const other = { ...rows[0], id: 'another-install', package: { ...bundle, id: 'toolkit-2' } }
|
|
21
|
+
assert.equal(indexInventory([...rows, other]).size, 2)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('member search, package names and invocation filters retain the original package card', () => {
|
|
25
|
+
const [match] = get({ query: '校对', filter: 'off' }).cards
|
|
26
|
+
assert.deepEqual([match.id, match.matched, match.total, match.initialQuery], [bundle.id, 1, 2, '校对'])
|
|
27
|
+
assert.equal(get({ query: '校对', filter: 'on' }).cards.length, 0)
|
|
28
|
+
for (const term of ['本地工具包', 'LOCAL-TOOLS', '文档助手']) {
|
|
29
|
+
const result = get({ query: term })
|
|
30
|
+
assert.equal(result.cards.length, 1)
|
|
31
|
+
assert.equal(result.cards[0].matched, 2)
|
|
32
|
+
assert.equal(result.cards[0].initialQuery, '')
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('home previews cap builtin cards and search includes every hidden builtin', () => {
|
|
37
|
+
const entries = Array.from({ length: 8 }, (_, i) => ({ id: i }))
|
|
38
|
+
for (let length = 0; length <= 6; length++) {
|
|
39
|
+
const subset = entries.slice(0, length)
|
|
40
|
+
assert.deepEqual(builtinPreview(subset, false), subset)
|
|
41
|
+
}
|
|
42
|
+
assert.deepEqual(builtinPreview(entries, false), entries.slice(0, 6))
|
|
43
|
+
assert.deepEqual(builtinPreview(entries, true), entries)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('invocation labels and filters distinguish public channels, documented references and unavailable definitions', () => {
|
|
47
|
+
const manual = { name: 'review', invocation: { modelInvocable: false, userInvocable: true }, enabled: false, package: bundle }
|
|
48
|
+
const model = { ...manual, invocation: { modelInvocable: true, userInvocable: false }, enabled: true }
|
|
49
|
+
const both = { ...model, invocation: { modelInvocable: true, userInvocable: true } }
|
|
50
|
+
const stopped = { ...manual, invocation: { modelInvocable: false, userInvocable: false } }
|
|
51
|
+
const referencedBy = ['overview']
|
|
52
|
+
const cases = [
|
|
53
|
+
[manual, 'manual', ['off', 'manual']],
|
|
54
|
+
[model, 'model', ['on', 'model']],
|
|
55
|
+
[both, 'both', ['on', 'both']],
|
|
56
|
+
[stopped, 'off', ['off', 'none']],
|
|
57
|
+
[{ ...stopped, referencedBy }, 'off', ['off', 'none', 'package']],
|
|
58
|
+
[{ ...manual, referencedBy }, 'manual', ['off', 'manual', 'package']],
|
|
59
|
+
[{ ...both, referencedBy, effective: false, shadowedBy: 'winner' }, 'shadowed', ['off', 'none', 'package']],
|
|
60
|
+
[{ ...both, referencedBy, excluded: true, effective: false }, 'excluded', ['off', 'none', 'package']],
|
|
61
|
+
[{ ...both, referencedBy, package: { ...bundle, enabled: false } }, 'off', ['off', 'none', 'package']],
|
|
62
|
+
[{ ...both, effective: false }, 'unavailable', ['off', 'none']],
|
|
63
|
+
[{ ...both, invocationAvailable: false }, 'noTool', ['off', 'none']],
|
|
64
|
+
]
|
|
65
|
+
const filters = ['on', 'off', 'both', 'model', 'manual', 'none', 'package']
|
|
66
|
+
assert.deepEqual(AGENT_FILTERS.map(option => option.label), ['全部', 'Agent 可调用', 'Agent 不可调用'])
|
|
67
|
+
for (const [row, key, matches] of cases) {
|
|
68
|
+
assert.equal(skillState(row).key, key)
|
|
69
|
+
assert.deepEqual(filters.filter(filter => matchesSkillState(row, filter)), matches)
|
|
70
|
+
assert.notEqual(matchesSkillState(row, 'on'), matchesSkillState(row, 'off'))
|
|
71
|
+
assert.equal(['both', 'model', 'manual', 'none'].filter(filter => matchesSkillState(row, filter)).length, 1)
|
|
72
|
+
}
|
|
73
|
+
assert.match(skillState(manual).detail, /Agent 自动调用已关闭.*\/review/)
|
|
74
|
+
assert.match(skillState(model).detail, /Agent 可按需加载.*手动调用入口已关闭/)
|
|
75
|
+
assert.deepEqual(skillState({ ...manual, referencedBy }).labels, ['仅手动调用', '包内引用'])
|
|
76
|
+
const restricted = skillState({ ...model, excluded: true }, { id: 'cordis' })
|
|
77
|
+
assert.equal(restricted.label, '模式限制')
|
|
78
|
+
assert.match(restricted.detail, /创造模式.*review/)
|
|
79
|
+
assert.equal(modeName({ id: 'cordis', name: '我的写作模式' }), '我的写作模式')
|
|
80
|
+
assert.equal(modeName({ id: 'review-mode' }), 'review-mode')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('mixed package cards retain original member status while the filter selects matching members', () => {
|
|
84
|
+
const [a, b] = rows
|
|
85
|
+
const mixed = [{ ...a, invocation: { modelInvocable: true, userInvocable: true } },
|
|
86
|
+
{ ...b, invocation: { modelInvocable: false, userInvocable: true } },
|
|
87
|
+
{ ...b, id: 'blocked', invocation: { modelInvocable: false, userInvocable: false }, excluded: true }]
|
|
88
|
+
const index = indexInventory(mixed)
|
|
89
|
+
const run = filter => inventoryResults(mixed, index, { filter }).cards
|
|
90
|
+
const [on] = run('on')
|
|
91
|
+
assert.deepEqual([on.total, on.matched, on.initialFilter], [3, 1, 'on'])
|
|
92
|
+
assert.equal(skillState(on).key, 'mixed')
|
|
93
|
+
assert.equal(run('manual')[0].matched, 1)
|
|
94
|
+
assert.equal(run('both')[0].matched, 1)
|
|
95
|
+
assert.equal(run('model').length, 0)
|
|
96
|
+
assert.equal(run('none')[0].matched, 1)
|
|
97
|
+
assert.equal(run('off')[0].matched, 2)
|
|
98
|
+
assert.equal(run('off')[0].initialFilter, 'off')
|
|
99
|
+
assert.equal(skillState({ members: mixed, pkg: { enabled: false } }).key, 'off')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('all modes show the available command and distinguish a package member from its bare-name winner', () => {
|
|
103
|
+
const member = { id: 'member', name: 'arena', invocation: { modelInvocable: false, userInvocable: false } }
|
|
104
|
+
const variant = { available: true, effective: false, shadowedBy: 'personal', invocation: member.invocation,
|
|
105
|
+
id: 'pstack', manualCommand: '/pstack arena' }
|
|
106
|
+
const row = { ...member, modeStates: [{ id: 'standard', available: false }, variant] }
|
|
107
|
+
const all = skillState(row, { source: 'all', id: null })
|
|
108
|
+
assert.equal(all.key, 'manual')
|
|
109
|
+
assert.equal(all.model, false)
|
|
110
|
+
assert.equal(all.user, true)
|
|
111
|
+
assert.match(all.detail, /在pstack中.*同名技能.*\/pstack arena/)
|
|
112
|
+
assert.doesNotMatch(all.detail, /输入 \/arena|在标准模式中/)
|
|
113
|
+
assert.ok(matchesSkillState(row, 'off'))
|
|
114
|
+
assert.ok(matchesSkillState(row, 'manual'))
|
|
115
|
+
assert.ok(matchesSkillState(row, 'shadowed'))
|
|
116
|
+
assert.equal(skillState({ ...member, invocation: { modelInvocable: false, userInvocable: true } }).detail,
|
|
117
|
+
'Agent 自动调用已关闭。可在消息中输入 /arena 手动调用。')
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('the independent catalog separates modes with usable, restricted and unobserved definitions', () => {
|
|
121
|
+
const row = { name: 'official-plugins', modeStates: [
|
|
122
|
+
{ id: 'standard', available: true, effective: true, invocation: { modelInvocable: true, userInvocable: false } },
|
|
123
|
+
{ id: 'cordis', available: true, effective: true, excluded: true, invocation: { modelInvocable: true, userInvocable: false } },
|
|
124
|
+
{ id: 'review', name: '评审模式', available: null },
|
|
125
|
+
] }
|
|
126
|
+
assert.equal(skillState(row).key, 'model')
|
|
127
|
+
assert.match(skillState(row).detail, /在标准模式中.*Agent 可按需加载.*在创造模式中.*限制.*评审模式的目录尚未读全/)
|
|
128
|
+
assert.ok(matchesSkillState(row, 'on'))
|
|
129
|
+
assert.ok(matchesSkillState(row, 'excluded'))
|
|
130
|
+
const selected = skillState(row, { id: 'cordis', source: 'preset' })
|
|
131
|
+
assert.equal(selected.key, 'excluded')
|
|
132
|
+
assert.equal(selected.model, false)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('separate mode permissions do not imply both channels are available together', () => {
|
|
136
|
+
const row = { name: 'draft', modeStates: [
|
|
137
|
+
{ id: 'standard', available: true, effective: true, invocation: { modelInvocable: true, userInvocable: false } },
|
|
138
|
+
{ id: 'cordis', available: true, effective: true, invocation: { modelInvocable: false, userInvocable: true } },
|
|
139
|
+
] }
|
|
140
|
+
assert.equal(skillState(row).label, '调用方式随模式变化')
|
|
141
|
+
assert.ok(matchesSkillState(row, 'model'))
|
|
142
|
+
assert.ok(matchesSkillState(row, 'manual'))
|
|
143
|
+
assert.equal(matchesSkillState(row, 'both'), false)
|
|
144
|
+
})
|