@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.
Files changed (307) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-lucide.txt +43 -0
  3. package/README.md +44 -2
  4. package/agent-tool.mjs +118 -0
  5. package/client-bridge.mjs +307 -0
  6. package/client-entry.mjs +131 -0
  7. package/client.js +6769 -0
  8. package/control-icon.mjs +40 -0
  9. package/cordis.patch.yml +4 -0
  10. package/design/skill-manager.pen +798 -0
  11. package/design.css +320 -0
  12. package/design.mjs +629 -0
  13. package/dialogs.css +460 -0
  14. package/dialogs.mjs +1130 -0
  15. package/document-link.mjs +13 -0
  16. package/file-actions.mjs +62 -0
  17. package/file-view.mjs +384 -0
  18. package/header-scroll.css +90 -0
  19. package/header-scroll.mjs +121 -0
  20. package/host.mjs +460 -0
  21. package/icon.svg +6 -0
  22. package/import-archive.mjs +41 -0
  23. package/import-commit.mjs +247 -0
  24. package/import-family.mjs +213 -0
  25. package/import-files.mjs +186 -0
  26. package/import-github.mjs +168 -0
  27. package/import-limits.mjs +10 -0
  28. package/import-native.mjs +79 -0
  29. package/imports.mjs +209 -0
  30. package/inventory.mjs +62 -0
  31. package/library.mjs +1334 -0
  32. package/local-families.mjs +277 -0
  33. package/locale/en.json +16 -0
  34. package/locale/zh.json +16 -0
  35. package/management-view.mjs +158 -0
  36. package/mode-view.mjs +72 -0
  37. package/node_modules/pend/LICENSE +23 -0
  38. package/node_modules/pend/README.md +41 -0
  39. package/node_modules/pend/index.js +55 -0
  40. package/node_modules/pend/package.json +18 -0
  41. package/node_modules/pend/test.js +137 -0
  42. package/node_modules/yaml/LICENSE +13 -0
  43. package/node_modules/yaml/README.md +172 -0
  44. package/node_modules/yaml/bin.mjs +11 -0
  45. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  46. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  47. package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
  48. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  49. package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
  50. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  51. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  52. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  53. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  54. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  55. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
  56. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  57. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  58. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  59. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  60. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  61. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  62. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  63. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  64. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  65. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  66. package/node_modules/yaml/browser/dist/errors.js +57 -0
  67. package/node_modules/yaml/browser/dist/index.js +17 -0
  68. package/node_modules/yaml/browser/dist/log.js +11 -0
  69. package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
  70. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  71. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  72. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  73. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  74. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  75. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  76. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  77. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  78. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  79. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  80. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  81. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  82. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  83. package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
  84. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  85. package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
  86. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  87. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  88. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  89. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  90. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  91. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  92. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  93. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  94. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  95. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  96. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  97. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  98. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  99. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  100. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  101. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  102. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
  103. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  104. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  105. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  106. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  107. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  108. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  109. package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
  110. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
  111. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  112. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  113. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
  114. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  115. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  116. package/node_modules/yaml/browser/dist/util.js +11 -0
  117. package/node_modules/yaml/browser/dist/visit.js +233 -0
  118. package/node_modules/yaml/browser/index.js +5 -0
  119. package/node_modules/yaml/browser/package.json +3 -0
  120. package/node_modules/yaml/dist/cli.d.ts +8 -0
  121. package/node_modules/yaml/dist/cli.mjs +201 -0
  122. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  123. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  124. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  125. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  126. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  127. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  128. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  129. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  130. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  131. package/node_modules/yaml/dist/compose/composer.js +224 -0
  132. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  133. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  134. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  135. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  136. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  137. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  138. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  139. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  140. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  141. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  142. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  143. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
  144. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  145. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  146. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  147. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  148. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  149. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  150. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  151. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  152. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  153. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  154. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  155. package/node_modules/yaml/dist/doc/Document.js +337 -0
  156. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  157. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  158. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  159. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  160. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  161. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  162. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  163. package/node_modules/yaml/dist/doc/directives.js +178 -0
  164. package/node_modules/yaml/dist/errors.d.ts +21 -0
  165. package/node_modules/yaml/dist/errors.js +62 -0
  166. package/node_modules/yaml/dist/index.d.ts +25 -0
  167. package/node_modules/yaml/dist/index.js +50 -0
  168. package/node_modules/yaml/dist/log.d.ts +3 -0
  169. package/node_modules/yaml/dist/log.js +19 -0
  170. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  171. package/node_modules/yaml/dist/nodes/Alias.js +120 -0
  172. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  173. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  174. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  175. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  176. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  177. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  178. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  179. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  180. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  181. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  182. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  183. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  184. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  185. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  186. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  187. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  188. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  189. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  190. package/node_modules/yaml/dist/options.d.ts +350 -0
  191. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  192. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  193. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  194. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  195. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  196. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  197. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  198. package/node_modules/yaml/dist/parse/cst.js +112 -0
  199. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  200. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  201. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  202. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  203. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  204. package/node_modules/yaml/dist/parse/parser.js +980 -0
  205. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  206. package/node_modules/yaml/dist/public-api.js +107 -0
  207. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  208. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  209. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  210. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  211. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  212. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  213. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  214. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  215. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  216. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  217. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  218. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  219. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  220. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  221. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  222. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  223. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  224. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  225. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  226. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  227. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  228. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  229. package/node_modules/yaml/dist/schema/tags.js +99 -0
  230. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  231. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  232. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  233. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  234. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  235. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  236. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  237. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  238. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  239. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  240. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  241. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  242. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  243. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  244. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  245. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  246. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  247. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  248. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  249. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  250. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  251. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  252. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  253. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  254. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  255. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  256. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  257. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  258. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  259. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  260. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  261. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  262. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  263. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  264. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  265. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  266. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  267. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  268. package/node_modules/yaml/dist/test-events.js +134 -0
  269. package/node_modules/yaml/dist/util.d.ts +16 -0
  270. package/node_modules/yaml/dist/util.js +28 -0
  271. package/node_modules/yaml/dist/visit.d.ts +102 -0
  272. package/node_modules/yaml/dist/visit.js +236 -0
  273. package/node_modules/yaml/package.json +97 -0
  274. package/node_modules/yaml/util.js +2 -0
  275. package/node_modules/yauzl/LICENSE +21 -0
  276. package/node_modules/yauzl/README.md +1015 -0
  277. package/node_modules/yauzl/crc32.js +45 -0
  278. package/node_modules/yauzl/fd-slicer.js +188 -0
  279. package/node_modules/yauzl/index.js +1096 -0
  280. package/node_modules/yauzl/package.json +40 -0
  281. package/package-files.mjs +244 -0
  282. package/package-view.mjs +375 -0
  283. package/package.css +131 -0
  284. package/package.json +75 -4
  285. package/removal.mjs +313 -0
  286. package/scripts/build.mjs +19 -0
  287. package/scripts/export-design.py +587 -0
  288. package/scripts/run-tests.mjs +14 -0
  289. package/skill-state.mjs +136 -0
  290. package/skills/skill-creator/SKILL.md +48 -0
  291. package/styles.mjs +10 -0
  292. package/surfaces.css +593 -0
  293. package/test/agent-tool.test.mjs +153 -0
  294. package/test/client-bridge.test.mjs +240 -0
  295. package/test/distribution.test.mjs +17 -0
  296. package/test/host.test.mjs +598 -0
  297. package/test/imports.test.mjs +491 -0
  298. package/test/inventory.test.mjs +144 -0
  299. package/test/library.test.mjs +785 -0
  300. package/test/local-families.test.mjs +220 -0
  301. package/test/management-view.test.mjs +102 -0
  302. package/test/mode-view.test.mjs +26 -0
  303. package/test/package-files.test.mjs +221 -0
  304. package/toolbar.css +228 -0
  305. package/typography.css +173 -0
  306. package/ui.css +399 -0
  307. package/ui.mjs +1545 -0
@@ -0,0 +1,220 @@
1
+ import assert from 'node:assert/strict'
2
+ import { mkdir, mkdtemp, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises'
3
+ import { createRequire } from 'node:module'
4
+ import { tmpdir } from 'node:os'
5
+ import { dirname, join } from 'node:path'
6
+ import test from 'node:test'
7
+ import { FAMILY_MARKER } from '../import-family.mjs'
8
+ import { hostRequire } from '../library.mjs'
9
+ import { getFamily, listFamilies } from '../local-families.mjs'
10
+
11
+ const native = hostRequire('@deepseek-ai/dsh-skill-filesystem')
12
+ const { Context } = hostRequire('@deepseek-ai/cordis')
13
+ const { LocalFileSystem } = hostRequire('@deepseek-ai/dsh-fs-local')
14
+ const all = { modelInvocable: true, userInvocable: true }
15
+ const none = { modelInvocable: false, userInvocable: false }
16
+
17
+ function skill(name, extra = '', body = '原始 Markdown。') {
18
+ return `---\nname: ${name}\ndescription: ${name} 的说明\n${extra}---\n\n${body}\n`
19
+ }
20
+
21
+ async function setup(t, scoped = false) {
22
+ const temp = await mkdtemp(join(await realpath(tmpdir()), 'dsh-family-test-'))
23
+ t.after(() => rm(temp, { recursive: true, force: true }))
24
+ const path = join(temp, 'shared'), warnings = []
25
+ let fs
26
+ if (scoped) {
27
+ const host = new Context(), fiber = await host.plugin(LocalFileSystem, { cwd: temp })
28
+ fs = host.get('fs')
29
+ t.after(() => fiber.dispose())
30
+ }
31
+ const ctx = { get: () => fs, logger: { warn: text => warnings.push(text) } }
32
+ async function put(relative, data) {
33
+ const file = join(path, relative)
34
+ await mkdir(dirname(file), { recursive: true })
35
+ await writeFile(file, data)
36
+ return file
37
+ }
38
+ const list = (root = {}, options = {}) => listFamilies(ctx, [{ path, source: 'user-dsh', rank: 400, ...root }], options, native)
39
+ const get = (candidate, options = {}) => getFamily(ctx, candidate, options, native)
40
+ return { path, temp, ctx, fs, put, list, get, warnings }
41
+ }
42
+
43
+ for (const scoped of [false, true]) {
44
+ test(`discovers wrapped families, leaves native personal skills independent and uses the current native body (${scoped ? 'DSH fs' : 'local fs'})`, async t => {
45
+ const h = await setup(t, scoped)
46
+ const prefix = 'archive/extracted/套件'
47
+ const file = await h.put(`${prefix}/skills/one/SKILL.md`, skill('alpha', 'whenToUse: now\nmetadata: {revision: 2}\nuser-invocable: false\n'))
48
+ await h.put(`${prefix}/skills/two/SKILL.md`, skill('beta'))
49
+ await h.put(`${prefix}/skills/one/examples/example/SKILL.md`, skill('sample'))
50
+ await h.put(`${prefix}/automations/other/skills/examples/SKILL.md`, skill('auxiliary'))
51
+ await h.put(`${prefix}/README.md`, '# Workshop Kit\n\nWorkshop instructions.\n')
52
+ for (const name of ['personal-a', 'personal-b']) {
53
+ await h.put(`${name}/SKILL.md`, skill(name))
54
+ await h.put(`standalone/references/${name}/SKILL.md`, skill(`unused-${name}`))
55
+ }
56
+ await h.put('standalone/SKILL.md', skill('standalone'))
57
+ await h.put('README.md', '# Personal index')
58
+ const { candidates, complete } = await h.list()
59
+ assert.equal(complete, true, h.warnings.join('\n'))
60
+ assert.deepEqual(candidates.map(item => item.name), ['alpha', 'beta'])
61
+ const [one] = candidates
62
+ assert.equal(one.provider, 'dsh-skill-manager-directories')
63
+ assert.equal(one.source, 'user-dsh')
64
+ assert.equal(one.rank, 400)
65
+ assert.equal(one.whenToUse, 'now')
66
+ assert.equal(one.metadata.revision, 2)
67
+ assert.equal('content' in one, false)
68
+ assert.deepEqual(one.locator, { path: file, directory: dirname(file) })
69
+ const { markerTemplate, ...family } = one.family
70
+ assert.deepEqual(family, { root: join(h.path, prefix), sourceRoot: h.path, memberRoot: dirname(file),
71
+ name: 'workshop-kit', label: 'Workshop Kit', description: 'Workshop instructions.', enabled: true,
72
+ markerId: null, memberInvocation: { modelInvocable: true, userInvocable: false } })
73
+ assert.equal(markerTemplate, candidates[1].family.markerTemplate)
74
+ assert.equal(markerTemplate.id, 'workshop-kit')
75
+ await writeFile(file, skill('alpha', 'metadata: {revision: 3}\ndisable-model-invocation: true\n', '## Updated\n\nRead `resources/a`.'))
76
+ const full = await h.get(one)
77
+ assert.equal(full.content, '## Updated\n\nRead `resources/a`.')
78
+ assert.deepEqual(full.metadata, { revision: 3 })
79
+ assert.deepEqual(full.invocation, { modelInvocable: false, userInvocable: true })
80
+ assert.deepEqual(full.resourceBase, { kind: 'directory', path: dirname(file) })
81
+ })
82
+ }
83
+
84
+ test('a managed root may directly own named members, while an undocumented or mixed flat index stays independent', async t => {
85
+ const h = await setup(t)
86
+ const root = { includeDirect: true, source: 'custom', rank: 300 }
87
+ for (const name of ['aa', 'bb']) await h.put(`${name}/SKILL.md`, skill(name))
88
+ assert.deepEqual((await h.list(root)).candidates, [])
89
+ await h.put('README.md', '# Workshop Kit\n\nA dedicated collection.')
90
+ const documented = await h.list(root)
91
+ assert.deepEqual(documented.candidates.map(row => row.name), ['aa', 'bb'])
92
+ assert.ok(documented.candidates.every(row => row.family.root === h.path && row.family.label === 'Workshop Kit'))
93
+ assert.deepEqual((await h.list(root, { cwd: h.path })).candidates, [])
94
+ await h.put('manual.md', skill('independent-flat'))
95
+ assert.deepEqual((await h.list(root)).candidates, [])
96
+ await h.put('manual.md', 'ordinary supporting documentation')
97
+ await h.put('package.json', JSON.stringify({ name: '@example/tools', displayName: 'Tools', description: 'npm family' }))
98
+ const { candidates: npm } = await h.list(root)
99
+ assert.ok(npm.length === 2 && npm.every(row => row.family.name === '@example/tools' && row.family.label === 'Tools' && row.family.description === 'npm family'))
100
+ await h.put('plain/工具箱/left/SKILL.md', skill('cc'))
101
+ await h.put('plain/工具箱/right/SKILL.md', skill('dd'))
102
+ const ordinary = await h.list()
103
+ assert.ok(ordinary.candidates.length === 2 && ordinary.candidates.every(row => row.family.name === '工具箱'))
104
+ })
105
+
106
+ test('a root instruction with conventional child skills is one family and keeps its root resources', async t => {
107
+ const h = await setup(t)
108
+ const rootFile = await h.put('suite/SKILL.md', skill('primary'))
109
+ await h.put('suite/.claude/skills/child/SKILL.md', skill('child'))
110
+ await h.put('suite/examples/a/SKILL.md', skill('example-a'))
111
+ await h.put('suite/examples/b/SKILL.md', skill('example-b'))
112
+ const found = await h.list()
113
+ assert.equal(found.complete, true)
114
+ assert.deepEqual(found.candidates.map(row => row.name), ['primary', 'child'])
115
+ const primary = found.candidates[0]
116
+ assert.equal(primary.path, rootFile)
117
+ assert.equal(primary.family.root, primary.resourceBase.path)
118
+ assert.equal((await h.get(primary)).name, 'primary')
119
+ })
120
+
121
+ test('imported membership can name deep entries and both invocation flags follow the current marker', async t => {
122
+ const h = await setup(t, true)
123
+ const marker = { version: 1, id: 'workshop-kit', name: '导入的合集', description: '说明', enabled: false, entry: 'guide.md',
124
+ source: { format: 'archive', label: 'workshop.zip' }, members: [{ name: 'one', entry: 'tools/one/SKILL.md' }, { name: 'two', entry: 'docs/products/two/SKILL.md' }] }
125
+ const mark = await h.put(`workshop-kit/${FAMILY_MARKER}`, JSON.stringify(marker))
126
+ await h.put('workshop-kit/guide.md', 'Intro')
127
+ for (const member of marker.members) await h.put(`workshop-kit/${member.entry}`, skill(member.name, member.name === 'two' ? 'user-invocable: false\n' : ''))
128
+ const found = await h.list()
129
+ assert.deepEqual(found.candidates.map(row => row.name), ['one', 'two'], h.warnings.join('\n'))
130
+ const [one, two] = found.candidates
131
+ assert.equal(one.family.markerId, marker.id)
132
+ assert.equal(one.family.label, marker.name)
133
+ assert.ok(found.candidates.every(row => row.family.enabled === false))
134
+ assert.deepEqual(one.family.memberInvocation, all)
135
+ assert.deepEqual(one.invocation, none)
136
+ assert.deepEqual((await h.get(two)).invocation, none)
137
+ await writeFile(mark, JSON.stringify({ ...marker, enabled: true }))
138
+ assert.deepEqual((await h.get(one)).invocation, all)
139
+ assert.deepEqual((await h.get(two)).invocation, { modelInvocable: true, userInvocable: false })
140
+ await writeFile(mark, JSON.stringify({ ...marker, members: [marker.members[0], { name: 'bad', entry: '../other/SKILL.md' }] }))
141
+ assert.deepEqual((await h.list()).candidates, [])
142
+ await assert.rejects(h.get(one), { code: 'UNSAFE_PATH' })
143
+ })
144
+
145
+ test('rejects linked roots and replaced files, forged locators and unavailable filesystem mappings', async t => {
146
+ const h = await setup(t)
147
+ const first = await h.put('suite/a/SKILL.md', skill('a'))
148
+ await h.put('suite/b/SKILL.md', skill('b'))
149
+ const away = join(h.temp, 'outside')
150
+ await mkdir(away)
151
+ const external = join(away, 'SKILL.md')
152
+ await writeFile(external, skill('outside'))
153
+ await symlink(away, join(h.path, 'suite', 'outside'), 'dir')
154
+ const alias = join(h.temp, 'alias')
155
+ await symlink(h.path, alias, 'dir')
156
+ assert.deepEqual((await h.list({ path: alias })).candidates, [])
157
+ const { candidates } = await h.list()
158
+ assert.deepEqual(candidates.map(row => row.name), ['a', 'b'])
159
+ const [row] = candidates
160
+ assert.equal(await h.get({ ...row, locator: { path: external, directory: away } }), undefined)
161
+ const hidden = { get: () => ({ processPathFromHostPath() {} }), logger: h.ctx.logger }
162
+ assert.deepEqual((await listFamilies(hidden, [{ path: h.path, rank: 300, source: 'custom' }], {}, native)).candidates, [])
163
+ assert.equal(await getFamily(hidden, row, {}, native), undefined)
164
+ await rename(first, join(away, 'original.md'))
165
+ await symlink(external, first)
166
+ assert.equal(await h.get(row), undefined)
167
+ await assert.rejects(h.get(row, { signal: AbortSignal.abort() }), { name: 'AbortError' })
168
+ await assert.rejects(h.list({}, { signal: AbortSignal.abort() }), { name: 'AbortError' })
169
+ })
170
+
171
+ test('a raw family’s first marker keeps its verified catalog identity through reload', async t => {
172
+ const h = await setup(t)
173
+ const packages = [['工具集', '工具集'], ['npm', '@acme/tools'], ['extracted', 'workshop-kit']]
174
+ await h.put('npm/package.json', JSON.stringify({ name: '@acme/tools', displayName: 'Tools' }))
175
+ await h.put('extracted/README.md', '# Workshop Kit\n\nText')
176
+ for (const [dir] of packages) for (const name of ['one', 'two']) await h.put(`${dir}/${name}/SKILL.md`, skill(name))
177
+ const initial = (await h.list()).candidates
178
+ for (const [dir, name] of packages) {
179
+ const rows = initial.filter(row => row.family.root === join(h.path, dir))
180
+ assert.equal(rows.length, 2)
181
+ assert.equal(rows[0].family.name, name)
182
+ const template = rows[0].family.markerTemplate
183
+ assert.equal(rows[1].family.markerTemplate, template)
184
+ await h.put(`${dir}/${FAMILY_MARKER}`, JSON.stringify({ ...template, enabled: false }))
185
+ }
186
+ const reloaded = await h.list()
187
+ assert.equal(reloaded.complete, true)
188
+ assert.equal(reloaded.candidates.length, 6)
189
+ for (const row of reloaded.candidates) {
190
+ const old = initial.find(item => item.path === row.path).family
191
+ assert.equal(row.family.name, old.name)
192
+ assert.equal(row.family.markerId, old.markerTemplate.id)
193
+ assert.equal(row.family.markerTemplate, undefined)
194
+ assert.deepEqual(row.invocation, none)
195
+ }
196
+ const template = initial.find(row => row.family.name === '@acme/tools').family.markerTemplate
197
+ await h.put(`npm/${FAMILY_MARKER}`, JSON.stringify({ ...template, catalogName: '../../fake' }))
198
+ assert.equal((await h.list()).candidates.find(row => row.family.root === join(h.path, 'npm')).family.name, template.id)
199
+ })
200
+
201
+ test('discovery reports bounded work with an incomplete observation and retries the root independently', async t => {
202
+ const h = await setup(t, true)
203
+ await h.put('suite/a/SKILL.md', skill('a'))
204
+ await h.put('suite/b/SKILL.md', skill('b'))
205
+ const noisy = new Proxy(h.fs, { get(target, key) {
206
+ if (key === 'listDir') return () => Array.from({ length: 8193 }, (_, i) => ({ name: String(i), type: 'file' }))
207
+ const value = target[key]
208
+ return typeof value === 'function' ? value.bind(target) : value
209
+ } })
210
+ const excessive = await listFamilies({ ...h.ctx, get: () => noisy }, [{ path: h.path, source: 'custom', rank: 300 }], {}, native)
211
+ assert.deepEqual(excessive, { complete: false, candidates: [] })
212
+ assert.equal((await h.list()).candidates.length, 2)
213
+ })
214
+
215
+ test('the installed preset skills root yields a complete observation inside Electron ASAR', { skip: !process.versions.electron }, async () => {
216
+ const require = createRequire(join(process.resourcesPath, 'app.asar/dsh/package.json'))
217
+ const path = join(dirname(require.resolve('@deepseek-ai/dsh-agent-preset/package.json')), 'skills')
218
+ const found = await listFamilies({ get: () => undefined, logger: console }, [{ path, source: 'custom', rank: 300 }], {}, native)
219
+ assert.equal(found.complete, true)
220
+ })
@@ -0,0 +1,102 @@
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
3
+ import { managementSelection, mergeManagementViews, withManagementScope } from '../management-view.mjs'
4
+
5
+ const cwd = '/fixture'
6
+
7
+ function makeView(scoped, items, { complete = true, directories = [], warnings = [] } = {}) {
8
+ return { ...scoped,
9
+ entries: new Map(items.map(item => [item.id, { item }])), packageRemovals: new Map(),
10
+ output: { items, directories, cwd, complete, warnings },
11
+ }
12
+ }
13
+
14
+ test('all modes merge installed definitions and preserve scoped permissions and package membership', async () => {
15
+ const scopes = { standard: {}, cordis: {}, pstack: {}, pending: {} }
16
+ const opened = [], closed = []
17
+ const presets = {
18
+ async list() { return [
19
+ { id: 'standard' }, { id: 'cordis', name: '创造模式' }, { id: 'pstack' }, { id: 'pending' },
20
+ { id: 'broken', name: 'Broken mode', broken: 'broken plugin' }, { id: 'pstack' }, { id: ' ' }, { id: 'removed' },
21
+ ] },
22
+ async acquireScope(id) {
23
+ opened.push(id)
24
+ if (id === 'removed') throw Object.assign(new Error('no revision'), { code: 'agent-preset/not-found' })
25
+ return { key: scopes[id], async [Symbol.asyncDispose]() { closed.push(id) } }
26
+ },
27
+ }
28
+ const selection = await managementSelection(presets)
29
+ const sample = { id: 'sample', name: 'sample', effective: true, enabled: true, canToggle: true, toggleReason: null,
30
+ invocation: { modelInvocable: true, userInvocable: true } }
31
+ const pkg = { id: 'pkg', name: 'pstack fixture', root: '/fixture/pkg', enabled: null, canToggle: false }
32
+ const snapshot = await withManagementScope(selection, management => {
33
+ assert.deepEqual(closed, [])
34
+ const items = {
35
+ standard: [sample],
36
+ cordis: [{ ...sample, excluded: true, enabled: false, canToggle: false, toggleReason: 'Mode exclusion' }],
37
+ pstack: [sample, { ...sample, id: 'different-origin', name: 'sample', effective: false, shadowedBy: 'sample', canToggle: false,
38
+ invocation: { modelInvocable: false, userInvocable: false }, package: pkg, manualCommand: '/pstack sample', referencedBy: ['tool'] }],
39
+ pending: [],
40
+ }
41
+ const views = management.scopes.map(scoped => makeView(scoped, items[scoped.mode.id], {
42
+ complete: scoped.mode.id !== 'pending',
43
+ directories: [{ id: 'dir', writable: scoped.mode.id === 'cordis' }],
44
+ warnings: scoped.mode.id === 'pending' ? ['Incomplete scope'] : [],
45
+ }))
46
+ const merged = mergeManagementViews(views, management)
47
+ assert.equal(merged.entries.get('sample').origin.scope, scopes.standard)
48
+ assert.equal(merged.entries.get('different-origin').origin.scope, scopes.pstack)
49
+ return merged.output
50
+ })
51
+
52
+ assert.deepEqual(opened, ['standard', 'cordis', 'pstack', 'pending', 'removed'])
53
+ assert.deepEqual(closed, ['standard', 'cordis', 'pstack', 'pending'])
54
+ assert.deepEqual(snapshot.mode, { id: null, source: 'all' })
55
+ assert.deepEqual(snapshot.modes.map(mode => mode.id), closed)
56
+ assert.equal(snapshot.complete, false)
57
+ assert.deepEqual(snapshot.warnings, ['Incomplete scope', '模式「Broken mode」的技能目录暂时不可用。', '模式「removed」的技能目录暂时不可用。'])
58
+ assert.deepEqual(snapshot.directories, [{ id: 'dir', writable: true }])
59
+ assert.deepEqual(snapshot.items.map(item => item.id), ['sample', 'different-origin'])
60
+ assert.equal(snapshot.items[0].enabled, true)
61
+ assert.equal(snapshot.items[0].modeStates[1].excluded, true)
62
+ assert.equal(snapshot.items[0].modeStates[1].name, '创造模式')
63
+ assert.equal(snapshot.items[0].modeStates[1].toggleReason, 'Mode exclusion')
64
+ assert.equal(snapshot.items[0].toggleReason, null)
65
+ const modeStates = snapshot.items[1].modeStates
66
+ assert.deepEqual(modeStates.map(state => [state.id, state.available]), [
67
+ ['standard', false], ['cordis', false], ['pstack', true], ['pending', null],
68
+ ])
69
+ assert.equal(modeStates[2].manualCommand, '/pstack sample')
70
+ assert.equal(modeStates[2].shadowedBy, 'sample')
71
+ assert.deepEqual(modeStates[2].referencedBy, ['tool'])
72
+ assert.deepEqual(snapshot.items[1].package.modeStates.map(state => state.available), [false, false, true, null])
73
+ })
74
+
75
+ test('explicit views acquire only the selected valid mode and release the scope on failure or cancellation', async () => {
76
+ const key = {}, release = [], called = []
77
+ const controller = new AbortController()
78
+ let stale = false
79
+ const presets = {
80
+ async list() { return [{ id: 'standard' }, { id: 'cordis', name: '创造模式' }, { id: 'broken', broken: 'test' }] },
81
+ async acquireScope(id) {
82
+ called.push(id)
83
+ if (stale) throw Object.assign(new Error('revision removed'), { code: 'agent-preset/invalid' })
84
+ return { key, [Symbol.asyncDispose]() { release.push(id) } }
85
+ },
86
+ }
87
+ for (const id of ['forged', 'broken']) await assert.rejects(managementSelection(presets, id), { code: 'PRESET_NOT_FOUND' })
88
+ const chosen = await managementSelection(presets, 'cordis', controller.signal)
89
+ await assert.rejects(withManagementScope(chosen, management => {
90
+ assert.deepEqual(management.mode, { id: 'cordis', name: '创造模式', source: 'preset' })
91
+ assert.deepEqual(management.modes.map(mode => mode.id), ['standard', 'cordis'])
92
+ assert.deepEqual(management.scopes, [{ scope: key, mode: management.mode }])
93
+ assert.deepEqual(management.warnings, [])
94
+ throw new Error('scan failed')
95
+ }), { message: 'scan failed' })
96
+ stale = true
97
+ await assert.rejects(withManagementScope(chosen, () => assert.fail('stale lease')), { code: 'PRESET_NOT_FOUND' })
98
+ controller.abort()
99
+ await assert.rejects(withManagementScope(chosen, () => assert.fail('cancelled lease')), { name: 'AbortError' })
100
+ assert.deepEqual(called, ['cordis', 'cordis'])
101
+ assert.deepEqual(release, ['cordis'])
102
+ })
@@ -0,0 +1,26 @@
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
3
+ import { modeChoices, workspaceProjection } from '../mode-view.mjs'
4
+
5
+ test('workspace choices are stable through conversation changes and registry ordering', () => {
6
+ const workspace = { workspaceId: 'a', title: 'A', path: '/old', sessionIds: ['first'] }
7
+ const other = { workspaceId: 'b', title: 'B', path: '/other', sessionIds: [] }
8
+ const empty = workspaceProjection({ items: [] })
9
+ const first = workspaceProjection({ items: [workspace, other] })
10
+ const second = workspaceProjection({ items: [
11
+ { ...other, sessionIds: ['first'] },
12
+ { ...workspace, sessionIds: ['second'] },
13
+ ] })
14
+ assert.equal(empty, '[]')
15
+ assert.equal(first, second)
16
+ assert.deepEqual(JSON.parse(second), [{ id: 'a', name: 'A' }, { id: 'b', name: 'B' }])
17
+ })
18
+
19
+ test('filter offers the all-modes view and the host mode catalog', () => {
20
+ const modes = [{ id: 'standard' }, { id: 'cordis' }, { id: 'pstack', name: 'pstack 主模式' }]
21
+ assert.deepEqual([...modeChoices(modes, '')], [
22
+ ['', '全部模式'], ['standard', '标准模式'], ['cordis', '创造模式'], ['pstack', 'pstack 主模式'],
23
+ ])
24
+ // A removed preset can still be displayed until the user returns to all modes.
25
+ assert.deepEqual([...modeChoices([], 'cordis')], [['', '全部模式'], ['cordis', '创造模式']])
26
+ })
@@ -0,0 +1,221 @@
1
+ import assert from 'node:assert/strict'
2
+ import { execFile } from 'node:child_process'
3
+ import { Dir, renameSync, symlinkSync } from 'node:fs'
4
+ import { access, mkdir, mkdtemp, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises'
5
+ import { tmpdir } from 'node:os'
6
+ import path from 'node:path'
7
+ import test from 'node:test'
8
+ import { promisify } from 'node:util'
9
+ import { browsePackage, browseSkill } from '../package-files.mjs'
10
+
11
+ async function fixture(t) {
12
+ const temp = await mkdtemp(path.join(await realpath(tmpdir()), 'dsh-package-test-'))
13
+ t.after(() => rm(temp, { recursive: true, force: true }))
14
+ const root = path.join(temp, 'installed')
15
+ await mkdir(root)
16
+ const pkg = { id: 'pkg-id', name: '@example/skills', label: 'Example', root }
17
+ const context = { cwd: temp, agent: { id: 'session' } }
18
+ const items = [{ name: 'first', package: pkg }, { name: 'second', package: { ...pkg } }, { name: 'standalone', package: null }]
19
+ const library = { async list(cwd, agent) {
20
+ return { items: cwd === context.cwd && agent === context.agent ? items : [] }
21
+ } }
22
+ const signal = new AbortController().signal
23
+ const entries = (relative = '', offset = 0) => browsePackage(library, context, pkg.id, { path: relative, offset }, true, signal)
24
+ const file = relative => browsePackage(library, context, pkg.id, { path: relative }, false, signal)
25
+ return { root, temp, pkg, entries, file, library, context, items, signal }
26
+ }
27
+
28
+ test('uses only a package root currently visible to the requesting agent and checks browser paths', async t => {
29
+ const h = await fixture(t)
30
+ await writeFile(path.join(h.root, 'README.md'), 'package contents')
31
+ await writeFile(path.join(h.temp, 'README.md'), 'outside contents')
32
+ const read = (id, input, context = h.context) => browsePackage(h.library, context, id, input, false, h.signal)
33
+ assert.equal((await read(h.pkg.id, { root: h.temp, path: 'README.md' })).content, 'package contents')
34
+ for (const relative of ['', '.', '..', '/README.md', '../README.md', 'docs/../README.md', 'docs//README.md', 'docs/', 'C:/README.md', 'C:README.md', 'a\\b', 'a\0b']) {
35
+ await assert.rejects(h.file(relative), { code: 'INVALID_PACKAGE_PATH' })
36
+ }
37
+ for (const invalid of [-1, 0.5, '20', null, Number.POSITIVE_INFINITY]) await assert.rejects(h.entries('', invalid), { code: 'INVALID_INPUT' })
38
+ await assert.rejects(read(h.temp, { path: 'README.md' }), { code: 'PACKAGE_NOT_FOUND' })
39
+ await assert.rejects(read(h.pkg.id, { path: 'README.md' }, { ...h.context, agent: {} }), { code: 'PACKAGE_NOT_FOUND' })
40
+ h.items.push({ package: { ...h.pkg, root: h.temp } })
41
+ await assert.rejects(h.file('README.md'), { code: 'PACKAGE_NOT_FOUND' })
42
+ h.items.splice(0)
43
+ await assert.rejects(h.file('README.md'), { code: 'PACKAGE_NOT_FOUND' })
44
+ })
45
+
46
+ test('lists one directory at a time with stable paging, directory-first and natural name order', async t => {
47
+ const h = await fixture(t)
48
+ await Promise.all(['docs', 'empty', '围绕'].map(name => mkdir(path.join(h.root, name))))
49
+ await writeFile(path.join(h.root, 'docs', '说明-😀.md'), '有关组件的说明。')
50
+ const files = Array.from({ length: 513 }, (_, index) => `file-${index + 1}.txt`)
51
+ for (let offset = 0; offset < files.length; offset += 32) {
52
+ await Promise.all(files.slice(offset, offset + 32).map(name => writeFile(path.join(h.root, name), 'x')))
53
+ }
54
+ const first = await h.entries()
55
+ assert.equal(first.path, '')
56
+ assert.equal(first.entries.length, 100)
57
+ assert.equal(first.nextOffset, 100)
58
+ assert.ok(first.entries.slice(0, 3).every(row => row.kind === 'directory'))
59
+ const rows = [...first.entries]
60
+ let offset = first.nextOffset
61
+ while (offset !== null) {
62
+ const page = await h.entries('', offset)
63
+ rows.push(...page.entries)
64
+ offset = page.nextOffset
65
+ }
66
+ assert.deepEqual(rows.slice(3).map(row => row.name), files)
67
+ assert.ok(rows.slice(3).every(row => row.size === 1 && row.path === row.name))
68
+ assert.deepEqual(await h.entries('empty'), { path: 'empty', root: h.root, entries: [], nextOffset: null })
69
+ assert.deepEqual((await h.entries('', 10000)).entries, [])
70
+ const child = (await h.entries('docs')).entries[0]
71
+ assert.equal(child.path, 'docs/说明-😀.md')
72
+ assert.equal((await h.file(child.path)).content, '有关组件的说明。')
73
+ await assert.rejects(h.entries(child.path), { code: 'NOT_A_DIRECTORY' })
74
+ await assert.rejects(h.file('docs'), { code: 'NOT_A_FILE' })
75
+ await assert.rejects(h.file('does-not-exist'), { code: 'RESOURCE_NOT_FOUND' })
76
+ })
77
+
78
+ test('previews UTF-8 and BOM-marked UTF-16 text with byte limits and no partial characters', async t => {
79
+ const h = await fixture(t)
80
+ const limit = 128 * 1024
81
+ const prefix = 'x'.repeat(limit - 2)
82
+ const utf16 = Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from('中文🙂', 'utf16le')])
83
+ const bigEndian = Buffer.from(utf16).swap16()
84
+ const exact = 'y'.repeat(limit - 3) + '终'
85
+ const sources = { '跨界.md': prefix + '你好!', 'utf16.txt': utf16, 'utf16be.txt': bigEndian, exact, empty: '',
86
+ script: '#!/bin/sh\nexit 1\n', encoded: Buffer.from([0, 1, 2]), badUtf8: Buffer.from([0xff, 0xf9]), pdf: '%PDF-1.4\n' }
87
+ await Promise.all(Object.entries(sources).map(([name, data]) => writeFile(path.join(h.root, name), data)))
88
+ const large = await h.file('跨界.md')
89
+ assert.equal(large.kind, 'text')
90
+ assert.equal(large.truncated, true)
91
+ assert.equal(large.size, Buffer.byteLength(sources['跨界.md']))
92
+ assert.equal(large.content, prefix)
93
+ assert.equal((await h.file('exact')).content, exact)
94
+ assert.equal((await h.file('exact')).truncated, false)
95
+ assert.equal((await h.file('utf16.txt')).content, '中文🙂')
96
+ assert.equal((await h.file('utf16be.txt')).content, '中文🙂')
97
+ assert.equal((await h.file('empty')).content, '')
98
+ assert.equal((await h.file('script')).content, sources.script)
99
+ for (const name of ['encoded', 'badUtf8', 'pdf']) {
100
+ assert.deepEqual(await h.file(name), { path: name, kind: 'binary', size: Buffer.byteLength(sources[name]) })
101
+ }
102
+ })
103
+
104
+ test('omits Finder and manager metadata while retaining other dotfiles', async t => {
105
+ const h = await fixture(t)
106
+ await mkdir(path.join(h.root, '__MACOSX'))
107
+ await writeFile(path.join(h.root, '__MACOSX', 'cache'), 'metadata')
108
+ await Promise.all(['.DS_Store', '.dsh-skill-family.json', '.editorconfig'].map(name => writeFile(path.join(h.root, name), 'data')))
109
+ assert.deepEqual((await h.entries()).entries.map(row => row.name), ['.editorconfig'])
110
+ assert.equal((await h.file('.editorconfig')).content, 'data')
111
+ for (const relative of ['.DS_Store', '.dsh-skill-family.json', '__MACOSX/cache']) await assert.rejects(h.file(relative), { code: 'INVALID_PACKAGE_PATH' })
112
+ })
113
+
114
+ test('lists links without following them, including intermediate links and a replaced package root', async t => {
115
+ const h = await fixture(t)
116
+ const elsewhere = path.join(h.temp, 'elsewhere')
117
+ await mkdir(elsewhere)
118
+ await writeFile(path.join(elsewhere, 'outside.txt'), 'private outside data')
119
+ await writeFile(path.join(h.root, 'inside.txt'), 'ordinary')
120
+ await Promise.all([
121
+ symlink(elsewhere, path.join(h.root, 'linked-dir'), 'dir'),
122
+ symlink(path.join(elsewhere, 'outside.txt'), path.join(h.root, 'linked-file'), 'file'),
123
+ symlink(path.join(h.root, 'inside.txt'), path.join(h.root, 'internal-link'), 'file'),
124
+ ])
125
+ assert.equal((await h.entries()).entries.filter(row => row.kind === 'link').length, 3)
126
+ for (const name of ['linked-dir/outside.txt', 'linked-file', 'internal-link']) await assert.rejects(h.file(name), { code: 'PACKAGE_LINK' })
127
+ await assert.rejects(h.entries('linked-dir'), { code: 'PACKAGE_LINK' })
128
+ await rename(h.root, path.join(h.temp, 'moved-package'))
129
+ await symlink(elsewhere, h.root, 'dir')
130
+ await assert.rejects(h.file('outside.txt'), { code: 'PACKAGE_CHANGED' })
131
+ })
132
+
133
+ test('omits special files and refuses to open a named pipe', { skip: process.platform === 'win32' }, async t => {
134
+ const h = await fixture(t)
135
+ await promisify(execFile)('mkfifo', [path.join(h.root, 'pipe')])
136
+ assert.deepEqual((await h.entries()).entries, [])
137
+ await assert.rejects(h.file('pipe'), { code: 'NOT_A_FILE' })
138
+ })
139
+
140
+ test('rejects a child directory replaced while a listing is in progress', async t => {
141
+ const h = await fixture(t)
142
+ const child = path.join(h.root, 'resources')
143
+ const outside = path.join(h.temp, 'elsewhere')
144
+ await Promise.all([mkdir(child), mkdir(outside)])
145
+ await writeFile(path.join(child, 'inside.md'), 'inside')
146
+ await writeFile(path.join(outside, 'private.md'), 'outside')
147
+ const iterate = Dir.prototype[Symbol.asyncIterator]
148
+ let replaced = false
149
+ Dir.prototype[Symbol.asyncIterator] = function () {
150
+ if (this.path === child && !replaced) {
151
+ replaced = true
152
+ renameSync(child, path.join(h.root, 'moved'))
153
+ symlinkSync(outside, child, 'dir')
154
+ }
155
+ return iterate.call(this)
156
+ }
157
+ try { await assert.rejects(h.entries('resources'), err => ['PACKAGE_LINK', 'PACKAGE_CHANGED'].includes(err.code)) }
158
+ finally { Dir.prototype[Symbol.asyncIterator] = iterate }
159
+ assert.ok(replaced)
160
+ })
161
+
162
+ test('reads installed Electron ASAR directories and files using their virtual metadata', async t => {
163
+ if (!process.versions.electron || !process.resourcesPath) return t.skip('Requires a packaged Electron installation')
164
+ const root = path.join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh')
165
+ if (!await access(path.join(root, 'package.json')).then(() => true, () => false)) return t.skip('Requires the installed DSH archive')
166
+ const lib = { list: async () => ({ items: [{ package: { id: 'host', root } }] }) }
167
+ const read = (relative, directory) => browsePackage(lib, { cwd: tmpdir() }, 'host', { path: relative }, directory, new AbortController().signal)
168
+ const page = await read('', true)
169
+ assert.ok(page.entries.some(entry => entry.name === 'package.json'))
170
+ const metadata = await read('package.json', false)
171
+ assert.equal(metadata.kind, 'text')
172
+ assert.equal(JSON.parse(metadata.content).name, '@deepseek-ai/dsh')
173
+ })
174
+
175
+ test('limits flat skills to their entry and canonical skill directories to their own files', async t => {
176
+ const h = await fixture(t)
177
+ const flat = path.join(h.root, 'flat.md')
178
+ const sharedEntry = path.join(h.root, 'SKILL.md')
179
+ const dir = path.join(h.root, 'member')
180
+ const packedEntry = path.join(dir, 'SKILL.md')
181
+ const linkedEntry = path.join(dir, 'alias.md')
182
+ const linkedDir = path.join(h.temp, 'linked-member')
183
+ await mkdir(dir)
184
+ await Promise.all([[flat, 'flat'], [sharedEntry, 'shared'], [packedEntry, 'entry'], [path.join(dir, 'notes.md'), 'notes']]
185
+ .map(([target, content]) => writeFile(target, content)))
186
+ await symlink(flat, linkedEntry, 'file')
187
+ await symlink(dir, linkedDir, 'dir')
188
+ const base = root => ({ kind: 'directory', path: root })
189
+ h.items.push(
190
+ { id: 'flat', path: flat, resourceBase: base(h.root) },
191
+ { id: 'shared', path: sharedEntry, resourceBase: base(h.root), sourceDirectoryPath: h.root },
192
+ { id: 'member', path: packedEntry, resourceBase: base(dir), sourceDirectoryPath: h.root },
193
+ { id: 'alias', path: linkedEntry, resourceBase: base(dir) },
194
+ { id: 'aliased-dir', path: packedEntry, resourceBase: base(linkedDir) },
195
+ { id: 'outside', path: flat, resourceBase: base(dir) },
196
+ { id: 'outside-source', path: flat, resourceBase: base(h.root), sourceDirectoryPath: dir },
197
+ { id: 'virtual', path: flat, resourceBase: { kind: 'virtual', description: 'fixture' } },
198
+ )
199
+ const read = (id, relative, directory = false, context = h.context, offset = 0) =>
200
+ browseSkill(h.library, context, id, { path: relative, offset, root: h.temp }, directory, h.signal)
201
+ for (const [id, name] of [['flat', 'flat.md'], ['shared', 'SKILL.md']]) {
202
+ const files = await read(id, '', true)
203
+ assert.equal(files.root, h.root)
204
+ assert.equal(files.entryPath, name)
205
+ assert.equal(files.canBrowse, false)
206
+ assert.deepEqual(files.entries.map(entry => entry.name), [name])
207
+ assert.deepEqual((await read(id, '', true, h.context, 1)).entries, [])
208
+ assert.equal((await read(id, name)).content, id)
209
+ await assert.rejects(read(id, 'member', true), { code: 'RESOURCE_NOT_FOUND' })
210
+ await assert.rejects(read(id, 'member/SKILL.md'), { code: 'RESOURCE_NOT_FOUND' })
211
+ }
212
+ const member = await read('member', '', true)
213
+ assert.equal(member.root, dir)
214
+ assert.equal(member.canBrowse, true)
215
+ assert.equal(member.entryPath, 'SKILL.md')
216
+ assert.equal((await read('member', 'notes.md')).content, 'notes')
217
+ await assert.rejects(read('member', 'alias.md'), { code: 'PACKAGE_LINK' })
218
+ await assert.rejects(read('member', '../flat.md'), { code: 'INVALID_PACKAGE_PATH' })
219
+ await assert.rejects(read('member', 'SKILL.md', false, { ...h.context, agent: {} }), { code: 'NO_LOCAL_FILE' })
220
+ for (const id of ['alias', 'aliased-dir', 'outside', 'outside-source', 'virtual']) await assert.rejects(read(id, '', true), { code: 'NO_LOCAL_FILE' })
221
+ })