@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,598 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { mkdir, mkdtemp, readFile, realpath, rename, rm, stat, symlink, writeFile } from 'node:fs/promises'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { Readable, Writable } from 'node:stream'
|
|
6
|
+
import test from 'node:test'
|
|
7
|
+
import * as host from '../host.mjs'
|
|
8
|
+
import { limits } from '../import-files.mjs'
|
|
9
|
+
import { createImports } from '../imports.mjs'
|
|
10
|
+
import { hostRequire } from '../library.mjs'
|
|
11
|
+
|
|
12
|
+
const owner = id => ({ id, principal: { kind: 'owner' }, signal: new AbortController().signal })
|
|
13
|
+
const encoded = (path, content) => ({ path, base64: Buffer.from(content).toString('base64') })
|
|
14
|
+
const markdown = '---\nname: sample\ndescription: Test input\n---\n\nA skill for this test.\n'
|
|
15
|
+
|
|
16
|
+
async function setup(t) {
|
|
17
|
+
const temp = await mkdtemp(path.join(await realpath(tmpdir()), 'dsh-skill-manager-test-'))
|
|
18
|
+
const workspace = { id: 'workspace', path: path.join(temp, 'project') }
|
|
19
|
+
const other = { id: 'another', path: path.join(temp, 'other') }
|
|
20
|
+
const target = { id: 'custom', path: path.join(temp, 'skills'), kind: 'custom', writable: true }
|
|
21
|
+
const personal = { id: 'personal-dir', path: path.join(temp, 'personal', 'skills'), kind: 'personal', writable: true }
|
|
22
|
+
await Promise.all([workspace.path, other.path, target.path].map(dir => mkdir(dir)))
|
|
23
|
+
const opened = []
|
|
24
|
+
const ctx = {
|
|
25
|
+
agents: { get: () => assert.fail('Owner management must never look up Agents') },
|
|
26
|
+
get(service) {
|
|
27
|
+
assert.notEqual(service, 'sessionQuery')
|
|
28
|
+
if (service === 'agentPresets') return { list: async () => [{ id: 'standard' }, { id: 'cordis' }] }
|
|
29
|
+
},
|
|
30
|
+
workingDirectory: { get: () => assert.fail('Owner management must never read a Session cwd'), defaultDirectory: temp },
|
|
31
|
+
workspaceRegistry: { get: id => [workspace, other].find(w => w.id === id) },
|
|
32
|
+
sessionController: {
|
|
33
|
+
canOpenWorkspacePath: () => true,
|
|
34
|
+
workspaceDesktop: () => ({ fileManager: 'finder', available: true }),
|
|
35
|
+
async openWorkspacePath(request) { opened.push(request); return { opened: true } },
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
const registered = []
|
|
39
|
+
const library = {
|
|
40
|
+
async list(cwd, selection) { return { cwd, presetId: selection.presetId } },
|
|
41
|
+
async targets() { return [target, personal] },
|
|
42
|
+
async imported(cwd, receipt, enabled, selection) { registered.push({ cwd, receipt, enabled, selection }) },
|
|
43
|
+
}
|
|
44
|
+
const sources = []
|
|
45
|
+
const gateway = host.createGateway(ctx, library, () => {
|
|
46
|
+
const imports = createImports({ home: temp })
|
|
47
|
+
return { ...imports, preview(input) { sources.push(input); return imports.preview(input) } }
|
|
48
|
+
})
|
|
49
|
+
const main = owner('browser-a')
|
|
50
|
+
const call = (op, data = {}, peer = main) => gateway.handle(op, data, new AbortController().signal, peer)
|
|
51
|
+
const value = async (op, data, peer) => {
|
|
52
|
+
const result = await call(op, data, peer)
|
|
53
|
+
assert.equal(result.ok, true, JSON.stringify(result))
|
|
54
|
+
return result.value
|
|
55
|
+
}
|
|
56
|
+
t.after(async () => {
|
|
57
|
+
await gateway.dispose()
|
|
58
|
+
await rm(temp, { recursive: true, force: true })
|
|
59
|
+
})
|
|
60
|
+
return { temp, workspace, other, personal, target, library, registered, call, value, sources, gateway, opened,
|
|
61
|
+
controller: ctx.sessionController }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test('owner authentication precedes dispatch and working directories are resolved by the Host', async t => {
|
|
65
|
+
const h = await setup(t)
|
|
66
|
+
const foreign = { ...owner('guest'), principal: { kind: 'guest' } }
|
|
67
|
+
assert.equal((await h.call('list', null, foreign)).error.code, 'FORBIDDEN')
|
|
68
|
+
assert.equal((await h.call('setEnabled', {})).error.code, 'INVALID_INPUT')
|
|
69
|
+
assert.deepEqual(await h.value('list', { sessionId: 'active', cwd: '/forged' }), { cwd: h.temp, presetId: null })
|
|
70
|
+
assert.deepEqual(await h.value('list', { sessionId: 'cold', cwd: '/forged' }), { cwd: h.temp, presetId: null })
|
|
71
|
+
assert.deepEqual(await h.value('list', { presetId: 'cordis', agentPreset: 'standard' }), { cwd: h.temp, presetId: 'cordis' })
|
|
72
|
+
assert.equal((await h.value('list', { workspaceId: 'workspace' })).cwd, h.workspace.path)
|
|
73
|
+
assert.equal((await h.value('list', { cwd: '/forged' })).cwd, h.temp)
|
|
74
|
+
assert.equal((await h.call('list', { workspaceId: 'removed' })).error.code, 'WORKSPACE_NOT_FOUND')
|
|
75
|
+
assert.equal((await h.value('list', { sessionId: 'active', workspaceId: 'another' })).cwd, h.other.path)
|
|
76
|
+
assert.equal((await h.value('list', { sessionId: 'removed', workspaceId: 'workspace' })).cwd, h.workspace.path)
|
|
77
|
+
assert.equal((await h.call('list', { presetId: 'removed' })).error.code, 'PRESET_NOT_FOUND')
|
|
78
|
+
assert.equal((await h.call('constructor', {})).error.code, 'UNKNOWN_OPERATION')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('creator drafts use the validated workspace and compatible preset without choosing an install target', async t => {
|
|
82
|
+
const h = await setup(t)
|
|
83
|
+
h.library.targets = () => assert.fail('Opening the composer must not require a skill installation directory')
|
|
84
|
+
h.library.creatorPreset = (cwd, selection) => {
|
|
85
|
+
assert.equal(cwd, h.workspace.path)
|
|
86
|
+
assert.equal(selection.presetId, 'cordis')
|
|
87
|
+
return 'standard'
|
|
88
|
+
}
|
|
89
|
+
assert.deepEqual(await h.value('prepareCreator', { workspaceId: h.workspace.id, presetId: 'cordis', cwd: '/forged' }), {
|
|
90
|
+
workspaceId: h.workspace.id, cwd: h.workspace.path, agentPreset: 'standard',
|
|
91
|
+
})
|
|
92
|
+
await assert.rejects(stat(h.personal.path), { code: 'ENOENT' })
|
|
93
|
+
await rename(h.workspace.path, h.workspace.path + '-moved')
|
|
94
|
+
assert.equal((await h.call('prepareCreator', { workspaceId: h.workspace.id })).error.code, 'WORKSPACE_NOT_FOUND')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('removal confirmation is single-use and bound to the owner peer, workspace and preset', async t => {
|
|
98
|
+
const h = await setup(t)
|
|
99
|
+
const plan = { id: 'visible-id', kind: 'skill', name: 'sample', scope: 'file', path: path.join(h.target.path, 'sample.md') }
|
|
100
|
+
const calls = []
|
|
101
|
+
h.library.prepareRemoval = async (cwd, kind, id, agent, signal) => {
|
|
102
|
+
assert.deepEqual([cwd, kind, id, agent?.presetId], [h.workspace.path, 'skill', plan.id, 'standard'])
|
|
103
|
+
assert.equal(signal.aborted, false)
|
|
104
|
+
calls.push('prepare')
|
|
105
|
+
return plan
|
|
106
|
+
}
|
|
107
|
+
h.library.commitRemoval = async (cwd, target, agent) => {
|
|
108
|
+
assert.deepEqual([cwd, target, agent?.presetId], [h.workspace.path, plan, 'standard'])
|
|
109
|
+
calls.push('commit')
|
|
110
|
+
return { receipt: { id: 'receipt' }, snapshot: { items: [] } }
|
|
111
|
+
}
|
|
112
|
+
const scope = { workspaceId: 'workspace', presetId: 'standard' }
|
|
113
|
+
const payload = { ...scope, kind: 'skill', id: plan.id, path: '/forged' }
|
|
114
|
+
const guest = { ...owner('guest'), principal: { kind: 'guest' } }
|
|
115
|
+
for (const operation of ['prepareRemoval', 'commitRemoval', 'listRemovals', 'restoreRemoval']) {
|
|
116
|
+
assert.equal((await h.call(operation, payload, guest)).error.code, 'FORBIDDEN')
|
|
117
|
+
}
|
|
118
|
+
assert.deepEqual(calls, [])
|
|
119
|
+
assert.equal((await h.call('prepareRemoval', { ...payload, kind: 'directory' })).error.code, 'INVALID_INPUT')
|
|
120
|
+
const { token, ...confirmation } = await h.value('prepareRemoval', payload)
|
|
121
|
+
assert.deepEqual(confirmation, plan)
|
|
122
|
+
assert.equal((await h.call('commitRemoval', { token, ...scope, workspaceId: 'another' })).error.code, 'REMOVAL_EXPIRED')
|
|
123
|
+
assert.equal((await h.call('commitRemoval', { token, ...scope, presetId: 'cordis' })).error.code, 'REMOVAL_EXPIRED')
|
|
124
|
+
assert.equal((await h.call('commitRemoval', { token, ...scope }, owner('browser-b'))).error.code, 'REMOVAL_EXPIRED')
|
|
125
|
+
assert.deepEqual(await h.value('commitRemoval', { token, ...scope, path: '/forged' }), { receipt: { id: 'receipt' }, snapshot: { items: [] } })
|
|
126
|
+
assert.equal((await h.call('commitRemoval', { token, ...scope })).error.code, 'REMOVAL_EXPIRED')
|
|
127
|
+
assert.deepEqual(calls, ['prepare', 'commit'])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('package resource RPC resolves the registered workspace and chosen preset', async t => {
|
|
131
|
+
const h = await setup(t)
|
|
132
|
+
await writeFile(path.join(h.workspace.path, 'info.md'), 'owner resource')
|
|
133
|
+
const calls = []
|
|
134
|
+
h.library.list = async (cwd, selection) => {
|
|
135
|
+
calls.push({ cwd, presetId: selection.presetId })
|
|
136
|
+
return { items: selection.presetId === 'cordis' ? [{ package: { id: 'visible-id', root: h.workspace.path } }] : [] }
|
|
137
|
+
}
|
|
138
|
+
const payload = { id: 'visible-id', workspaceId: h.workspace.id, presetId: 'cordis', root: h.temp, cwd: h.temp }
|
|
139
|
+
const guest = { ...owner('guest'), principal: { kind: 'guest' } }
|
|
140
|
+
assert.equal((await h.call('packageEntries', payload, guest)).error.code, 'FORBIDDEN')
|
|
141
|
+
assert.equal((await h.call('packageFile', { ...payload, path: 'info.md' }, guest)).error.code, 'FORBIDDEN')
|
|
142
|
+
assert.equal((await h.call('setPackageEnabled', { ...payload, enabled: false }, guest)).error.code, 'FORBIDDEN')
|
|
143
|
+
assert.equal(calls.length, 0)
|
|
144
|
+
assert.deepEqual((await h.value('packageEntries', payload)).entries.map(entry => entry.name), ['info.md'])
|
|
145
|
+
assert.equal((await h.value('packageFile', { ...payload, path: 'info.md' })).content, 'owner resource')
|
|
146
|
+
const expected = { cwd: h.workspace.path, presetId: 'cordis' }
|
|
147
|
+
assert.deepEqual(calls, [expected, expected])
|
|
148
|
+
assert.equal((await h.call('packageFile', { ...payload, presetId: 'standard', path: 'info.md' })).error.code, 'PACKAGE_NOT_FOUND')
|
|
149
|
+
h.library.setPackageEnabled = async (cwd, id, enabled, selection) => {
|
|
150
|
+
assert.equal(cwd, h.workspace.path)
|
|
151
|
+
assert.equal(selection.presetId, 'cordis')
|
|
152
|
+
assert.equal(id, 'visible-id')
|
|
153
|
+
return { items: [{ id, enabled }] }
|
|
154
|
+
}
|
|
155
|
+
assert.equal((await h.call('setPackageEnabled', { ...payload, enabled: 'false' })).error.code, 'INVALID_INPUT')
|
|
156
|
+
assert.deepEqual(await h.value('setPackageEnabled', { ...payload, enabled: false }), { items: [{ id: 'visible-id', enabled: false }] })
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('only a catalog Markdown file can be opened or revealed through the native service', async t => {
|
|
160
|
+
const h = await setup(t)
|
|
161
|
+
const skill = path.join(h.temp, 'example.md')
|
|
162
|
+
const executable = path.join(h.temp, 'other.sh')
|
|
163
|
+
const alias = path.join(h.temp, 'alias.md')
|
|
164
|
+
const disguised = path.join(h.temp, 'disguised.md')
|
|
165
|
+
await writeFile(skill, markdown)
|
|
166
|
+
await writeFile(executable, 'test fixture')
|
|
167
|
+
await writeFile(disguised, '#!test-fixture')
|
|
168
|
+
await symlink(executable, alias)
|
|
169
|
+
const items = Object.entries({ sample: skill, executable, alias, disguised }).map(([id, path]) => ({ id, path }))
|
|
170
|
+
h.library.list = async () => ({ items })
|
|
171
|
+
await h.value('openItem', { id: 'sample', kind: 'file', path: executable })
|
|
172
|
+
await h.value('openItem', { id: 'sample', kind: 'directory' })
|
|
173
|
+
for (const id of ['unknown', 'executable', 'alias', 'disguised']) {
|
|
174
|
+
assert.equal((await h.call('openItem', { id, kind: 'file' })).error.code, 'NO_LOCAL_FILE')
|
|
175
|
+
}
|
|
176
|
+
assert.deepEqual(h.opened, [{ path: skill }, { path: skill, action: 'reveal' }])
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('discovers native handlers for the scoped Markdown and revalidates explicit selections', async t => {
|
|
180
|
+
const h = await setup(t)
|
|
181
|
+
const skill = path.join(h.workspace.path, 'sample.md')
|
|
182
|
+
await writeFile(skill, markdown)
|
|
183
|
+
h.library.list = async (_cwd, selection) => ({ items: selection.presetId === 'standard' ? [{ id: 'sample', path: skill }] : [] })
|
|
184
|
+
const payload = { presetId: 'standard', id: 'sample', path: '/arbitrary/other.md' }
|
|
185
|
+
const guest = { ...owner('guest'), principal: { kind: 'guest' } }
|
|
186
|
+
const queried = []
|
|
187
|
+
let apps = [{ id: 'os:editor', name: 'Fixture Editor', default: true, icon: null }, { id: 'os:preview', name: 'Fixture Preview', default: false }]
|
|
188
|
+
h.controller.workspacePathApplications = async (request, signal) => {
|
|
189
|
+
signal.throwIfAborted()
|
|
190
|
+
queried.push(request)
|
|
191
|
+
return apps
|
|
192
|
+
}
|
|
193
|
+
assert.equal((await h.call('openOptions', payload, guest)).error.code, 'FORBIDDEN')
|
|
194
|
+
assert.equal((await h.call('openItem', { ...payload, kind: 'file' }, guest)).error.code, 'FORBIDDEN')
|
|
195
|
+
assert.deepEqual(await h.value('openOptions', { ...payload, presetId: 'cordis' }), { archived: false, applications: [], canReveal: false })
|
|
196
|
+
assert.deepEqual(queried, [])
|
|
197
|
+
assert.deepEqual(await h.value('openOptions', payload), {
|
|
198
|
+
archived: false, canReveal: true,
|
|
199
|
+
applications: [{ id: 'os:editor', name: 'Fixture Editor', isDefault: true }, { id: 'os:preview', name: 'Fixture Preview', isDefault: false }],
|
|
200
|
+
})
|
|
201
|
+
assert.deepEqual(queried, [{ path: skill }])
|
|
202
|
+
assert.deepEqual(h.opened, [])
|
|
203
|
+
await h.value('openItem', { ...payload, kind: 'file', applicationId: 'os:editor' })
|
|
204
|
+
const attempt = (applicationId, kind = 'file') => h.call('openItem', { ...payload, kind, applicationId })
|
|
205
|
+
assert.equal((await attempt('/arbitrary/unregistered.app')).error.code, 'APPLICATION_UNAVAILABLE')
|
|
206
|
+
assert.equal((await attempt('os:editor', 'directory')).error.code, 'INVALID_INPUT')
|
|
207
|
+
apps = []
|
|
208
|
+
assert.equal((await attempt('os:editor')).error.code, 'APPLICATION_UNAVAILABLE')
|
|
209
|
+
assert.deepEqual(await h.value('openOptions', payload), { archived: false, applications: [], canReveal: true })
|
|
210
|
+
h.controller.canOpenWorkspacePath = () => false
|
|
211
|
+
assert.deepEqual(await h.value('openOptions', payload), { archived: false, applications: [], canReveal: false })
|
|
212
|
+
assert.equal((await attempt(undefined)).error.code, 'OPEN_UNAVAILABLE')
|
|
213
|
+
assert.deepEqual(h.opened, [{ path: skill, application: 'os:editor' }])
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
test('serves an actual bundled skill and nested resources through Electron without desktop handoff', async t => {
|
|
217
|
+
if (!process.versions.electron || !process.resourcesPath) return t.skip('Requires a packaged Electron installation')
|
|
218
|
+
const root = path.join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh-agent-preset', 'skills', 'dsh-doc')
|
|
219
|
+
const entry = path.join(root, 'SKILL.md')
|
|
220
|
+
if (!await stat(entry).then(() => true, () => false)) return t.skip('Requires the installed DSH archive')
|
|
221
|
+
const h = await setup(t)
|
|
222
|
+
const item = { id: 'builtin-archive', path: entry, resourceBase: { kind: 'directory', path: root } }
|
|
223
|
+
h.library.list = async (_cwd, selection) => ({ items: selection.presetId === 'standard' ? [item] : [] })
|
|
224
|
+
h.library.detail = async () => item
|
|
225
|
+
h.controller.workspacePathApplications = () => assert.fail('Archive must never query desktop associations')
|
|
226
|
+
const payload = { id: item.id, presetId: 'standard' }
|
|
227
|
+
const guest = { ...owner('guest'), principal: { kind: 'guest' } }
|
|
228
|
+
assert.equal((await h.call('skillEntries', payload, guest)).error.code, 'FORBIDDEN')
|
|
229
|
+
assert.equal((await h.call('skillFile', { ...payload, path: 'SKILL.md' }, guest)).error.code, 'FORBIDDEN')
|
|
230
|
+
const metadata = { root, entryPath: 'SKILL.md', canBrowse: true, archived: true }
|
|
231
|
+
assert.deepEqual((await h.value('detail', payload)).files, metadata)
|
|
232
|
+
const page = await h.value('skillEntries', payload)
|
|
233
|
+
for (const [key, expected] of Object.entries(metadata)) assert.equal(page[key], expected)
|
|
234
|
+
assert.ok(page.entries.some(entry => entry.name === 'references' && entry.kind === 'directory'))
|
|
235
|
+
assert.match((await h.value('skillFile', { ...payload, path: 'SKILL.md' })).content, /name: dsh-doc/)
|
|
236
|
+
const child = (await h.value('skillEntries', { ...payload, path: 'references' })).entries.find(file => file.name === 'locate-docs.md')
|
|
237
|
+
assert.match((await h.value('skillFile', { ...payload, path: child.path })).content, /# Locate documentation and sources/)
|
|
238
|
+
assert.deepEqual(await h.value('openOptions', payload), { archived: true, applications: [], canReveal: false })
|
|
239
|
+
for (const kind of ['file', 'directory']) {
|
|
240
|
+
assert.equal((await h.call('openItem', { ...payload, kind })).error.code, 'ARCHIVED_RESOURCE')
|
|
241
|
+
}
|
|
242
|
+
assert.deepEqual(h.opened, [])
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
test('upload validation rejects broad paths, duplicate spellings, multiple roots and invalid data', async t => {
|
|
246
|
+
const h = await setup(t)
|
|
247
|
+
const invalid = [
|
|
248
|
+
[[encoded('../outside.md', '')], 'UNSAFE_PATH'],
|
|
249
|
+
[[encoded('/absolute.md', '')], 'UNSAFE_PATH'],
|
|
250
|
+
[[encoded('C:\\outside.md', '')], 'UNSAFE_PATH'],
|
|
251
|
+
[[encoded('a/one', ''), encoded('a/ONE', '')], 'UNSAFE_PATH'],
|
|
252
|
+
[[encoded('a/file', ''), encoded('a/file/child', '')], 'UNSAFE_PATH'],
|
|
253
|
+
[[encoded('one.md', ''), encoded('two.md', '')], 'INVALID_UPLOAD'],
|
|
254
|
+
[[{ path: 'a.md', base64: '!!' }], 'INVALID_UPLOAD'],
|
|
255
|
+
[Array.from({ length: limits.entries + 1 }, () => encoded('a.md', '')), 'SIZE_LIMIT'],
|
|
256
|
+
[[{ path: 'folder/payload.zip', base64: 'A'.repeat(4 * Math.ceil(limits.file / 3) + 4) }], 'SIZE_LIMIT'],
|
|
257
|
+
[[{ path: 'payload.skill', base64: 'A'.repeat(4 * Math.ceil(limits.archive / 3) + 4) }], 'SIZE_LIMIT'],
|
|
258
|
+
]
|
|
259
|
+
for (const [files, expected] of invalid) assert.equal((await h.call('upload', { files })).error.code, expected)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('folder upload and previews are scoped, independently cancellable, and commit preserves resources', async t => {
|
|
263
|
+
const h = await setup(t)
|
|
264
|
+
const context = { workspaceId: h.workspace.id, presetId: 'standard' }
|
|
265
|
+
const { uploadId } = await h.value('upload', { ...context, files: [encoded('chosen/SKILL.md', markdown), encoded('chosen/assets/sample.txt', 'payload')] })
|
|
266
|
+
const source = { ...context, type: 'local', uploadId }
|
|
267
|
+
assert.equal((await h.call('preview', source, owner('other-peer'))).error.code, 'PREVIEW_EXPIRED')
|
|
268
|
+
assert.equal((await h.call('preview', { ...source, presetId: 'cordis' })).error.code, 'PREVIEW_EXPIRED')
|
|
269
|
+
assert.equal((await h.call('preview', { ...source, workspaceId: h.other.id })).error.code, 'PREVIEW_EXPIRED')
|
|
270
|
+
const first = await h.value('preview', source)
|
|
271
|
+
assert.deepEqual(first.files, ['SKILL.md', 'assets/sample.txt'])
|
|
272
|
+
assert.equal(first.sourcePath, 'chosen')
|
|
273
|
+
const staged = h.sources.at(-1).path
|
|
274
|
+
assert.equal((await h.call('preview', { ...context, type: 'local', path: staged })).error.code, 'INVALID_INPUT')
|
|
275
|
+
await h.value('cancel', { ...context, token: first.token })
|
|
276
|
+
const second = await h.value('preview', source)
|
|
277
|
+
await h.value('cancel', { ...context, uploadId })
|
|
278
|
+
await assert.rejects(stat(staged), { code: 'ENOENT' })
|
|
279
|
+
assert.equal((await h.call('preview', source)).error.code, 'PREVIEW_EXPIRED')
|
|
280
|
+
const request = { ...context, token: second.token, directoryId: h.target.id, enabled: false, directory: { path: '/forged' } }
|
|
281
|
+
assert.equal((await h.call('commit', request, owner('other-peer'))).error.code, 'PREVIEW_EXPIRED')
|
|
282
|
+
assert.equal((await h.call('commit', { ...request, directoryId: h.temp })).error.code, 'INVALID_TARGET')
|
|
283
|
+
assert.equal((await h.call('commit', { ...request, token: first.token })).error.code, 'PREVIEW_EXPIRED')
|
|
284
|
+
const receipt = await h.value('commit', request)
|
|
285
|
+
assert.equal(receipt.path, path.join(h.target.path, 'sample', 'SKILL.md'))
|
|
286
|
+
assert.equal(receipt.sourcePath, 'chosen')
|
|
287
|
+
assert.equal(receipt.enabled, false)
|
|
288
|
+
assert.equal(await readFile(path.join(h.target.path, 'sample', 'assets', 'sample.txt'), 'utf8'), 'payload')
|
|
289
|
+
assert.deepEqual((await h.value('commit', request)), receipt)
|
|
290
|
+
assert.equal(h.registered.length, 1)
|
|
291
|
+
assert.equal(h.registered[0].selection.presetId, 'standard')
|
|
292
|
+
assert.equal(h.registered[0].cwd, h.workspace.path)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('a conflict requires confirmation and a registration retry does not rewrite the target', async t => {
|
|
296
|
+
const h = await setup(t)
|
|
297
|
+
const source = path.join(h.temp, 'source.md')
|
|
298
|
+
const destination = path.join(h.target.path, 'sample.md')
|
|
299
|
+
await writeFile(source, markdown)
|
|
300
|
+
await writeFile(destination, markdown + 'original\n')
|
|
301
|
+
const { token } = await h.value('preview', { type: 'local', path: 'source.md', cwd: '/ignored' })
|
|
302
|
+
const request = { token, directoryId: h.target.id, enabled: true }
|
|
303
|
+
const conflict = await h.call('commit', request)
|
|
304
|
+
assert.equal(conflict.error.code, 'CONFLICT')
|
|
305
|
+
assert.equal(conflict.error.details.existingPath, destination)
|
|
306
|
+
assert.equal(h.registered.length, 0)
|
|
307
|
+
assert.match(await readFile(destination, 'utf8'), /original/)
|
|
308
|
+
let attempts = 0
|
|
309
|
+
h.library.imported = async () => {
|
|
310
|
+
if (!attempts++) throw new Error('暂时无法登记')
|
|
311
|
+
return { items: [{ path: destination, directoryId: h.target.id, enabled: false }], warnings: ['当前预设已排除此技能。'] }
|
|
312
|
+
}
|
|
313
|
+
const failed = await h.call('commit', { ...request, conflict: 'replace' })
|
|
314
|
+
assert.equal(failed.error.code, 'REGISTRATION_FAILED')
|
|
315
|
+
assert.deepEqual(failed.error.details, { path: destination, directoryId: h.target.id, enabled: true })
|
|
316
|
+
assert.equal(await readFile(destination, 'utf8'), markdown)
|
|
317
|
+
await writeFile(destination, markdown + 'edited after import\n')
|
|
318
|
+
const registered = await h.value('commit', request)
|
|
319
|
+
assert.equal(registered.replaced, true)
|
|
320
|
+
assert.equal(registered.enabled, false)
|
|
321
|
+
assert.equal(registered.warning, '当前预设已排除此技能。')
|
|
322
|
+
assert.match(await readFile(destination, 'utf8'), /edited after import/)
|
|
323
|
+
assert.equal(attempts, 2)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
const familyFiles = () => [
|
|
327
|
+
encoded('workshop/README.md', '# Workshop\n\nA fixture family.\n'),
|
|
328
|
+
encoded('workshop/skills/inspect/SKILL.md', '---\nname: inspect\ndescription: Inspect files\n---\nFirst member.\n'),
|
|
329
|
+
encoded('workshop/skills/check/SKILL.md', '---\nname: check\ndescription: Check files\ndisable-model-invocation: true\n---\nSecond member.\n'),
|
|
330
|
+
encoded('workshop/shared/input.txt', 'shared fixture'),
|
|
331
|
+
]
|
|
332
|
+
|
|
333
|
+
test('a family import retains a committed receipt across partial registration and respects replacement confirmation', async t => {
|
|
334
|
+
const h = await setup(t)
|
|
335
|
+
const assets = Array.from({ length: 105 }, (_, i) => encoded(`workshop/shared/resource-${i}.txt`, `asset ${i}`))
|
|
336
|
+
const { uploadId } = await h.value('upload', { files: [...familyFiles(), ...assets] })
|
|
337
|
+
const source = { type: 'local', uploadId }
|
|
338
|
+
const preview = await h.value('preview', source)
|
|
339
|
+
assert.equal(preview.kind, 'family')
|
|
340
|
+
assert.equal(preview.members.length, 2)
|
|
341
|
+
assert.equal(preview.targetRelativePath, preview.family.id)
|
|
342
|
+
let attempts = 0
|
|
343
|
+
const registeredPkg = { id: 'pkg', root: path.join(h.target.path, preview.family.id), label: preview.name, enabled: true }
|
|
344
|
+
h.library.imported = async (_cwd, receipt, enabled) => {
|
|
345
|
+
attempts++
|
|
346
|
+
assert.equal(enabled, undefined)
|
|
347
|
+
const source = attempts === 1 ? receipt.members.slice(0, 1) : receipt.members
|
|
348
|
+
return { importedPackage: { ...registeredPkg, enabled: receipt.family.enabled }, importedItems: source.map(member => ({
|
|
349
|
+
id: `skill-${member.name}`, package: registeredPkg, name: member.name, enabled: receipt.family.enabled && member.name === 'inspect',
|
|
350
|
+
})) }
|
|
351
|
+
}
|
|
352
|
+
const request = { token: preview.token, directoryId: h.target.id }
|
|
353
|
+
const failed = await h.call('commit', request)
|
|
354
|
+
assert.equal(failed.error.code, 'REGISTRATION_FAILED')
|
|
355
|
+
assert.equal(failed.error.details.path, registeredPkg.root)
|
|
356
|
+
assert.equal(failed.error.details.memberCount, 2)
|
|
357
|
+
const shared = path.join(registeredPkg.root, 'shared', 'input.txt')
|
|
358
|
+
await writeFile(shared, 'edited while registration was pending')
|
|
359
|
+
assert.equal((await h.call('commit', { ...request, directoryId: h.personal.id })).error.code, 'ALREADY_SAVED')
|
|
360
|
+
const receipt = await h.value('commit', request)
|
|
361
|
+
assert.equal(receipt.memberCount, 2)
|
|
362
|
+
assert.deepEqual(receipt.members.map(member => [member.name, member.enabled]).sort(), [['check', false], ['inspect', true]])
|
|
363
|
+
assert.equal(receipt.familyRoot, registeredPkg.root)
|
|
364
|
+
assert.equal(receipt.package.id, 'pkg')
|
|
365
|
+
assert.equal(receipt.sourcePath, 'workshop')
|
|
366
|
+
assert.equal(await readFile(shared, 'utf8'), 'edited while registration was pending')
|
|
367
|
+
assert.equal(await readFile(path.join(registeredPkg.root, 'shared', 'resource-104.txt'), 'utf8'), 'asset 104')
|
|
368
|
+
assert.deepEqual(await h.value('commit', request), receipt)
|
|
369
|
+
assert.equal(attempts, 2)
|
|
370
|
+
|
|
371
|
+
const next = await h.value('preview', source)
|
|
372
|
+
const update = { token: next.token, directoryId: h.target.id, enabled: false }
|
|
373
|
+
assert.equal((await h.call('commit', update)).error.code, 'CONFLICT')
|
|
374
|
+
const replaced = await h.value('commit', { ...update, conflict: 'replace' })
|
|
375
|
+
assert.equal(replaced.replaced, true)
|
|
376
|
+
assert.equal(replaced.enabled, false)
|
|
377
|
+
assert.ok(replaced.members.every(member => member.enabled === false))
|
|
378
|
+
assert.equal(await readFile(shared, 'utf8'), 'shared fixture')
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
test('expired and disposed uploads are removed without writing a skill', async t => {
|
|
382
|
+
const h = await setup(t)
|
|
383
|
+
let now = Date.now()
|
|
384
|
+
t.mock.method(Date, 'now', () => now)
|
|
385
|
+
async function uploadedSource() {
|
|
386
|
+
const { uploadId } = await h.value('upload', { files: [encoded('demo.md', markdown)] })
|
|
387
|
+
const descriptor = { type: 'local', uploadId }
|
|
388
|
+
const { token } = await h.value('preview', descriptor)
|
|
389
|
+
return { path: h.sources.at(-1).path, descriptor, token }
|
|
390
|
+
}
|
|
391
|
+
const first = await uploadedSource()
|
|
392
|
+
now += 15 * 60_000 + 1
|
|
393
|
+
assert.equal((await h.call('preview', first.descriptor)).error.code, 'PREVIEW_EXPIRED')
|
|
394
|
+
assert.equal((await h.call('commit', { token: first.token, directoryId: h.target.id })).error.code, 'PREVIEW_EXPIRED')
|
|
395
|
+
await assert.rejects(stat(first.path), { code: 'ENOENT' })
|
|
396
|
+
const second = await uploadedSource()
|
|
397
|
+
await h.gateway.dispose()
|
|
398
|
+
await assert.rejects(stat(second.path), { code: 'ENOENT' })
|
|
399
|
+
assert.equal((await h.call('list')).error.code, 'CANCELLED')
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
test('cancelling an upload preserves a directory that replaced its staging path', async t => {
|
|
403
|
+
const h = await setup(t)
|
|
404
|
+
const { uploadId } = await h.value('upload', { files: [encoded('demo.md', markdown)] })
|
|
405
|
+
await h.value('preview', { type: 'local', uploadId })
|
|
406
|
+
const directory = path.dirname(h.sources.at(-1).path)
|
|
407
|
+
assert.equal(path.dirname(directory), await realpath(tmpdir()))
|
|
408
|
+
assert.match(path.basename(directory), /^dsh-skill-manager-upload-/)
|
|
409
|
+
await rename(directory, path.join(h.temp, 'relocated'))
|
|
410
|
+
await mkdir(directory)
|
|
411
|
+
t.after(() => rm(directory, { recursive: true, force: true }))
|
|
412
|
+
const otherFile = path.join(directory, 'other.txt')
|
|
413
|
+
await writeFile(otherFile, 'another process owns this directory')
|
|
414
|
+
await h.value('cancel', { uploadId })
|
|
415
|
+
assert.equal(await readFile(otherFile, 'utf8'), 'another process owns this directory')
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
test('installed Connection and filesystem registry import, toggle and read single skills and families over authenticated RPC', async t => {
|
|
419
|
+
const { Context } = hostRequire('@deepseek-ai/cordis')
|
|
420
|
+
const connection = hostRequire('@deepseek-ai/dsh-client-connection')
|
|
421
|
+
const { Loader } = hostRequire('@deepseek-ai/cordis-plugin-loader')
|
|
422
|
+
const { AgentPresetRegistry } = hostRequire('@deepseek-ai/dsh-agent-preset-registry')
|
|
423
|
+
const { createScope } = hostRequire('@deepseek-ai/dsh-scope')
|
|
424
|
+
const { SkillRegistry } = hostRequire('@deepseek-ai/dsh-skill')
|
|
425
|
+
const filesystem = hostRequire('@deepseek-ai/dsh-skill-filesystem')
|
|
426
|
+
const temp = await mkdtemp(path.join(await realpath(tmpdir()), 'dsh-skill-manager-transport-test-'))
|
|
427
|
+
const cwd = path.join(temp, 'project')
|
|
428
|
+
const dshHome = path.join(temp, 'dsh')
|
|
429
|
+
const bundledSkillDir = path.join(temp, 'bundled')
|
|
430
|
+
const agentsHome = path.join(temp, 'agents')
|
|
431
|
+
await Promise.all([cwd, bundledSkillDir, agentsHome].map(directory => mkdir(directory)))
|
|
432
|
+
await writeFile(path.join(cwd, '.git'), 'test marker\n')
|
|
433
|
+
const root = new Context()
|
|
434
|
+
t.after(async () => {
|
|
435
|
+
await root.fiber.dispose()
|
|
436
|
+
await rm(temp, { recursive: true, force: true })
|
|
437
|
+
})
|
|
438
|
+
const routes = new Map()
|
|
439
|
+
const fixtures = {
|
|
440
|
+
webServer: { register(route) { routes.set(route.path, route); return () => routes.delete(route.path) } },
|
|
441
|
+
agents: { get: () => assert.fail('Owner management must never look up Agents') }, workingDirectory: { defaultDirectory: cwd },
|
|
442
|
+
workspaceRegistry: { list: () => [] }, sessionController: { canOpenWorkspacePath: () => false },
|
|
443
|
+
tools: { register: () => () => {} },
|
|
444
|
+
}
|
|
445
|
+
for (const [key, service] of Object.entries(fixtures)) { root.provide(key); root.set(key, service) }
|
|
446
|
+
await root.plugin(SkillRegistry)
|
|
447
|
+
await root.plugin(filesystem, { dshHome, agentsHome, bundledSkillDir, watch: false })
|
|
448
|
+
await root.plugin(connection)
|
|
449
|
+
const plugin = await root.plugin(host)
|
|
450
|
+
const resource = routes.get('/dsh-skill-manager')
|
|
451
|
+
assert.equal(resource?.auth, 'required')
|
|
452
|
+
assert.equal(routes.get('/api').auth, 'required')
|
|
453
|
+
|
|
454
|
+
async function rpc(method, payload = {}, peer = root.connection.browserPeer) {
|
|
455
|
+
const message = { type: 'client-request', rpcId: 'wire-test', method, payload }
|
|
456
|
+
const request = Object.assign(Readable.from([Buffer.from(JSON.stringify(message))]), {
|
|
457
|
+
method: 'POST', url: `/dsh-skill-manager/${method}`, headers: { 'content-type': 'application/json' },
|
|
458
|
+
})
|
|
459
|
+
const chunks = []
|
|
460
|
+
const response = new Writable({ write(chunk, _encoding, callback) { chunks.push(chunk); callback() } })
|
|
461
|
+
response.writeHead = code => assert.equal(code, 200)
|
|
462
|
+
await resource.handler(request, response, peer)
|
|
463
|
+
const result = JSON.parse(Buffer.concat(chunks))
|
|
464
|
+
assert.equal(result.type, 'server-response')
|
|
465
|
+
assert.equal(result.rpcId, message.rpcId)
|
|
466
|
+
return result.result
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function value(method, payload) {
|
|
470
|
+
const result = await rpc(method, payload)
|
|
471
|
+
assert.equal(result.ok, true, JSON.stringify(result))
|
|
472
|
+
return result.value
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const guest = root.connection.createPeer({ principal: { kind: 'guest' } })
|
|
476
|
+
assert.equal((await rpc('list', {}, guest)).error.code, 'FORBIDDEN')
|
|
477
|
+
assert.equal((await rpc('prepareCreator', {}, guest)).error.code, 'FORBIDDEN')
|
|
478
|
+
const [creatorSkill] = (await value('list')).items
|
|
479
|
+
assert.equal(creatorSkill.name, 'skill-creator')
|
|
480
|
+
assert.equal(creatorSkill.category, 'provided')
|
|
481
|
+
assert.equal(creatorSkill.canRemove, false)
|
|
482
|
+
assert.deepEqual(creatorSkill.invocation, { modelInvocable: false, userInvocable: true })
|
|
483
|
+
assert.match((await value('detail', { id: creatorSkill.id })).content, /创建或改进 DSH 技能/)
|
|
484
|
+
const targetId = (await value('targets')).find(row => row.kind === 'personal').id
|
|
485
|
+
const { uploadId } = await value('upload', { files: [encoded('demo.md', markdown)] })
|
|
486
|
+
const { token } = await value('preview', { type: 'local', uploadId })
|
|
487
|
+
const receipt = await value('commit', { token, directoryId: targetId, enabled: false })
|
|
488
|
+
assert.equal(receipt.enabled, false)
|
|
489
|
+
assert.equal(receipt.path, path.join(dshHome, 'skills', 'sample.md'))
|
|
490
|
+
const item = (await value('list')).items.find(row => row.name === 'sample')
|
|
491
|
+
assert.equal(item.name, 'sample')
|
|
492
|
+
assert.equal(item.enabled, false)
|
|
493
|
+
await value('setEnabled', { id: item.id, enabled: true })
|
|
494
|
+
const detail = await value('detail', { id: item.id })
|
|
495
|
+
assert.equal(detail.enabled, true)
|
|
496
|
+
assert.match(detail.content, /A skill for this test/)
|
|
497
|
+
assert.deepEqual(detail.files, { root: path.dirname(receipt.path), entryPath: 'sample.md', canBrowse: false, archived: false })
|
|
498
|
+
assert.deepEqual((await value('skillEntries', { id: item.id })).entries.map(entry => entry.name), ['sample.md'])
|
|
499
|
+
assert.match((await value('skillFile', { id: item.id, path: 'sample.md' })).content, /A skill for this test/)
|
|
500
|
+
|
|
501
|
+
const familyUpload = await value('upload', { files: familyFiles() })
|
|
502
|
+
const preview = await value('preview', { type: 'upload', uploadId: familyUpload.uploadId })
|
|
503
|
+
assert.equal(preview.kind, 'family')
|
|
504
|
+
const family = await value('commit', { token: preview.token, directoryId: targetId })
|
|
505
|
+
assert.equal(family.memberCount, 2)
|
|
506
|
+
assert.equal(family.package.root, family.familyRoot)
|
|
507
|
+
assert.equal(family.package.canToggle, true)
|
|
508
|
+
assert.deepEqual(family.members.map(member => [member.name, member.enabled]).sort(), [['check', false], ['inspect', true]])
|
|
509
|
+
const packageId = family.package.id
|
|
510
|
+
const listed = await value('packageEntries', { id: packageId })
|
|
511
|
+
assert.ok(listed.entries.some(entry => entry.path === 'shared' && entry.kind === 'directory'))
|
|
512
|
+
assert.equal((await value('packageFile', { id: packageId, path: 'shared/input.txt' })).content, 'shared fixture')
|
|
513
|
+
const member = family.members.find(member => member.name === 'inspect')
|
|
514
|
+
const memberDetail = await value('detail', { id: member.id })
|
|
515
|
+
assert.deepEqual(memberDetail.files, { root: path.dirname(memberDetail.path), entryPath: 'SKILL.md', canBrowse: true, archived: false })
|
|
516
|
+
assert.equal((await rpc('skillFile', { id: member.id, path: 'shared/input.txt' })).error.code, 'RESOURCE_NOT_FOUND')
|
|
517
|
+
const off = await value('setPackageEnabled', { id: packageId, enabled: false })
|
|
518
|
+
assert.deepEqual(off.items.filter(item => item.package?.id === packageId).map(item => item.enabled), [false, false])
|
|
519
|
+
const existing = await value('preview', { type: 'upload', uploadId: familyUpload.uploadId })
|
|
520
|
+
const update = { token: existing.token, directoryId: targetId }
|
|
521
|
+
assert.equal((await rpc('commit', update)).error.code, 'CONFLICT')
|
|
522
|
+
const replaced = await value('commit', { ...update, conflict: 'replace' })
|
|
523
|
+
assert.equal(replaced.enabled, false)
|
|
524
|
+
assert.equal(replaced.package.id, packageId)
|
|
525
|
+
const on = await value('setPackageEnabled', { id: packageId, enabled: true })
|
|
526
|
+
assert.deepEqual(on.items.filter(item => item.package?.id === packageId).map(item => [item.name, item.enabled]).sort(), [['check', false], ['inspect', true]])
|
|
527
|
+
assert.equal((await rpc('prepareRemoval', { id: member.id, kind: 'skill' })).error.code, 'REMOVAL_NOT_ALLOWED')
|
|
528
|
+
const plan = await value('prepareRemoval', { id: packageId, kind: 'package' })
|
|
529
|
+
assert.equal(plan.scope, 'directory')
|
|
530
|
+
assert.equal(plan.memberCount, 2)
|
|
531
|
+
const removed = await value('commitRemoval', { token: plan.token })
|
|
532
|
+
assert.equal(removed.snapshot.items.some(item => item.package?.id === packageId), false)
|
|
533
|
+
assert.deepEqual((await value('listRemovals')).map(entry => entry.id), [removed.receipt.id])
|
|
534
|
+
const restored = await value('restoreRemoval', { id: removed.receipt.id })
|
|
535
|
+
assert.equal(restored.receipt.canRestore, false)
|
|
536
|
+
assert.equal(restored.snapshot.items.filter(item => item.package?.id === packageId).length, 2)
|
|
537
|
+
assert.deepEqual(await value('listRemovals'), [])
|
|
538
|
+
assert.equal((await value('packageFile', { id: packageId, path: 'shared/input.txt' })).content, 'shared fixture')
|
|
539
|
+
root.provide('sessionProjections', { register: () => ({}) })
|
|
540
|
+
root.provide('sessionQuery', { observeSession() { assert.fail('Owner management must never observe a Session') } })
|
|
541
|
+
await root.plugin(Loader)
|
|
542
|
+
await root.plugin(AgentPresetRegistry)
|
|
543
|
+
const releaseStandard = await root.agentPresets.register({ id: 'standard', order: 0, plugins: [] })
|
|
544
|
+
const releaseCreator = await root.agentPresets.register({ id: 'cordis', name: '创造模式', order: 1, plugins: [] })
|
|
545
|
+
const creatorLease = await root.agentPresets.acquireScope('cordis')
|
|
546
|
+
const creatorScope = createScope(root, creatorLease.key)
|
|
547
|
+
const office = await creatorScope.ctx.plugin(hostRequire('@deepseek-ai/dsh-skill-office'), {})
|
|
548
|
+
try {
|
|
549
|
+
const defaultView = await value('list')
|
|
550
|
+
assert.deepEqual(defaultView.mode, { id: null, source: 'all' })
|
|
551
|
+
const stale = { sessionId: 'cold-creator', agentPreset: 'standard', cwd: '/ignored-ui-value' }
|
|
552
|
+
assert.deepEqual(await value('list', stale), defaultView)
|
|
553
|
+
assert.deepEqual(defaultView.modes, [{ id: 'standard' }, { id: 'cordis', name: '创造模式' }])
|
|
554
|
+
const creator = { presetId: 'cordis' }
|
|
555
|
+
const creatorView = await value('list', creator)
|
|
556
|
+
assert.deepEqual(creatorView.mode, { id: 'cordis', name: '创造模式', source: 'preset' })
|
|
557
|
+
assert.equal(creatorView.cwd, cwd)
|
|
558
|
+
const row = creatorView.items.find(item => item.name === 'office')
|
|
559
|
+
const request = { ...creator, id: row?.id }
|
|
560
|
+
const allRow = defaultView.items.find(item => item.id === row?.id)
|
|
561
|
+
assert.deepEqual(allRow.modeStates.map(state => [state.id, state.available]), [['standard', false], ['cordis', true]])
|
|
562
|
+
assert.equal(defaultView.items.filter(item => item.name === 'sample').length, 1)
|
|
563
|
+
const switched = await value('setEnabled', { ...creator, id: item.id, enabled: false })
|
|
564
|
+
assert.deepEqual(switched.mode, creatorView.mode)
|
|
565
|
+
assert.equal(switched.items.find(candidate => candidate.id === item.id).modeStates[0].enabled, false)
|
|
566
|
+
assert.deepEqual((await value('refresh', stale)).items.find(candidate => candidate.id === item.id).modeStates
|
|
567
|
+
.map(state => [state.id, state.enabled]), [['standard', false], ['cordis', false]])
|
|
568
|
+
assert.ok(row.path.endsWith(path.join('assets', 'office', 'SKILL.md')))
|
|
569
|
+
const detail = await value('detail', request)
|
|
570
|
+
assert.deepEqual(detail.mode, creatorView.mode)
|
|
571
|
+
const archived = Boolean(process.versions.electron && process.resourcesPath && row.path.startsWith(path.join(process.resourcesPath, 'app.asar') + path.sep))
|
|
572
|
+
const meta = { root: path.dirname(row.path), entryPath: 'SKILL.md', canBrowse: true, archived }
|
|
573
|
+
assert.deepEqual(detail.files, meta)
|
|
574
|
+
assert.match(detail.content, /## Python environment/)
|
|
575
|
+
assert.equal((await value('detail', { id: row.id })).content, detail.content)
|
|
576
|
+
const files = await value('skillEntries', request)
|
|
577
|
+
assert.equal(files.root, meta.root)
|
|
578
|
+
assert.equal(files.entryPath, meta.entryPath)
|
|
579
|
+
assert.deepEqual(files.entries.map(({ name, kind }) => ({ name, kind })), [{ name: 'SKILL.md', kind: 'file' }])
|
|
580
|
+
const raw = await value('skillFile', { ...request, path: 'SKILL.md' })
|
|
581
|
+
assert.match(raw.content, /name: office/)
|
|
582
|
+
assert.doesNotMatch(raw.content, /## Python environment/)
|
|
583
|
+
assert.deepEqual(await value('openOptions', request), { archived, applications: [], canReveal: false })
|
|
584
|
+
assert.equal((await rpc('openItem', { ...request, kind: 'directory' })).error.code, archived ? 'ARCHIVED_RESOURCE' : 'OPEN_UNAVAILABLE')
|
|
585
|
+
assert.equal((await rpc('skillEntries', { id: row.id, presetId: 'standard' })).error.code, 'NO_LOCAL_FILE')
|
|
586
|
+
assert.equal((await value('skillFile', { id: row.id, path: 'SKILL.md' })).content, raw.content)
|
|
587
|
+
assert.equal((await value('packageFile', { ...creator, id: packageId, path: 'shared/input.txt' })).content, 'shared fixture')
|
|
588
|
+
} finally {
|
|
589
|
+
await office.dispose()
|
|
590
|
+
await creatorScope.dispose()
|
|
591
|
+
await creatorLease[Symbol.asyncDispose]()
|
|
592
|
+
await releaseCreator()
|
|
593
|
+
await releaseStandard()
|
|
594
|
+
}
|
|
595
|
+
await plugin.dispose()
|
|
596
|
+
assert.equal(await root.skills.get('skill-creator', { cwd }), undefined)
|
|
597
|
+
assert.deepEqual([...routes.keys()], ['/api'])
|
|
598
|
+
})
|