@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,40 @@
1
+ {
2
+ "name": "yauzl",
3
+ "version": "3.4.0",
4
+ "description": "yet another unzip library for node",
5
+ "engines": {
6
+ "node": ">=12"
7
+ },
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "test": "node test/test.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/thejoshwolfe/yauzl.git"
15
+ },
16
+ "keywords": [
17
+ "unzip",
18
+ "zip",
19
+ "stream",
20
+ "archive",
21
+ "file"
22
+ ],
23
+ "author": "Josh Wolfe <thejoshwolfe@gmail.com>",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://github.com/thejoshwolfe/yauzl/issues"
27
+ },
28
+ "homepage": "https://github.com/thejoshwolfe/yauzl",
29
+ "dependencies": {
30
+ "pend": "~1.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "bl": "^6.0.11"
34
+ },
35
+ "files": [
36
+ "crc32.js",
37
+ "fd-slicer.js",
38
+ "index.js"
39
+ ]
40
+ }
@@ -0,0 +1,244 @@
1
+ import { constants } from 'node:fs'
2
+ import { lstat, open, opendir, readFile, readdir, realpath } from 'node:fs/promises'
3
+ import path from 'node:path'
4
+ import { problem } from './import-files.mjs'
5
+
6
+ const pageSize = 100
7
+ const previewBytes = 128 * 1024
8
+ const archiveReadLimit = 16 * 1024 * 1024
9
+ const names = new Intl.Collator('zh-CN', { numeric: true })
10
+ const appArchive = process.versions.electron && process.resourcesPath && path.join(process.resourcesPath, 'app.asar')
11
+ const kindRank = { directory: 0, file: 1, link: 2 }
12
+ const hiddenNames = new Set(['.ds_store', '__macosx', '.dsh-skill-family.json'])
13
+
14
+ function compareEntries(a, b) {
15
+ const order = kindRank[a.kind] - kindRank[b.kind] || names.compare(a.name, b.name)
16
+ if (order || a.name === b.name) return order
17
+ return a.name < b.name ? -1 : 1
18
+ }
19
+
20
+ function safeName(name) {
21
+ return name.length > 0 && name !== '.' && name !== '..' && !hiddenNames.has(name.toLowerCase()) && !/[\\/\u0000-\u001f\u007f]/u.test(name) &&
22
+ (process.platform !== 'win32' || !(/[<>:"|?*]|[. ]$/.test(name) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name)))
23
+ }
24
+
25
+ function resourcePath(value, allowRoot) {
26
+ if (allowRoot && value === '') return value
27
+ if (typeof value !== 'string' || Buffer.byteLength(value) > 4096 || /^[a-z]:/i.test(value) || !value.split('/').every(safeName)) {
28
+ throw problem('INVALID_PACKAGE_PATH', '请选择当前资源根内的相对路径。')
29
+ }
30
+ return value
31
+ }
32
+
33
+ function changed() { return problem('PACKAGE_CHANGED', '技能资源的位置或内容已改变,请重新打开。') }
34
+
35
+ function checkCanonical(canonical, requested) {
36
+ if (canonical !== requested) throw problem('PACKAGE_LINK', '不能通过符号链接浏览技能资源。')
37
+ }
38
+
39
+ function sameNode(before, after, archived) {
40
+ // Electron assigns a new synthetic inode on each lstat in its own app.asar.
41
+ return archived ? before.size === after.size && before.mtimeNs === after.mtimeNs : before.dev === after.dev && before.ino === after.ino
42
+ }
43
+
44
+ async function packageRoot(library, context, id, signal) {
45
+ const snapshot = await library.list(context.cwd, context.agent)
46
+ signal.throwIfAborted()
47
+ const roots = new Set(snapshot.items.filter(item => item.package?.id === id).map(item => item.package.root))
48
+ if (roots.size !== 1) throw problem('PACKAGE_NOT_FOUND', '当前技能库中找不到这个技能包。')
49
+ const [root] = roots
50
+ if (typeof root !== 'string' || !path.isAbsolute(root) || root === path.parse(root).root || await realpath(root) !== root) throw changed()
51
+ return root
52
+ }
53
+
54
+ async function locate(root, relative, signal) {
55
+ signal.throwIfAborted()
56
+ const target = path.join(root, relative)
57
+ const archived = Boolean(appArchive && target.startsWith(appArchive + path.sep))
58
+ const rootStat = await lstat(root, { bigint: true })
59
+ if (!rootStat.isDirectory()) throw changed()
60
+ // Replacing a direct child with a link and then restoring it changes its parent's ctime.
61
+ const ancestors = relative ? [{ path: root, stat: rootStat }] : []
62
+ let parent = root
63
+ for (const component of relative.split('/').slice(0, -1)) {
64
+ signal.throwIfAborted()
65
+ parent = path.join(parent, component)
66
+ const stat = await lstat(parent, { bigint: true })
67
+ if (stat.isSymbolicLink()) throw problem('PACKAGE_LINK', '不能通过符号链接浏览技能资源。')
68
+ if (!stat.isDirectory()) throw problem('NOT_A_DIRECTORY', '所选资源不是目录。')
69
+ ancestors.push({ path: parent, stat })
70
+ }
71
+ const stat = relative ? await lstat(target, { bigint: true }) : rootStat
72
+ if (stat.isSymbolicLink()) throw problem('PACKAGE_LINK', '不能通过符号链接浏览技能资源。')
73
+ checkCanonical(await realpath(target), target)
74
+ return { target, stat, ancestors, archived }
75
+ }
76
+
77
+ export async function verifyResource(location, signal) {
78
+ signal.throwIfAborted()
79
+ const { target, stat, ancestors, archived } = location
80
+ checkCanonical(await realpath(target), target)
81
+ for (const before of [...ancestors, { path: target, stat }]) {
82
+ const current = await lstat(before.path, { bigint: true })
83
+ if (current.isSymbolicLink() || !sameNode(before.stat, current, archived) || before.stat.ctimeNs !== current.ctimeNs) throw changed()
84
+ }
85
+ }
86
+
87
+ async function directoryPage(location, relative, offset, signal) {
88
+ if (!location.stat.isDirectory()) throw problem('NOT_A_DIRECTORY', '所选资源不是目录。')
89
+ // Electron patches readdir for packed directories but leaves opendir as a native disk operation.
90
+ const source = location.archived ? await readdir(location.target, { withFileTypes: true }) : await opendir(location.target)
91
+ const rows = []
92
+ const keep = offset + pageSize + 1
93
+ try {
94
+ await verifyResource(location, signal)
95
+ } catch (error) {
96
+ if (!location.archived) await source.close()
97
+ throw error
98
+ }
99
+ for await (const entry of source) {
100
+ signal.throwIfAborted()
101
+ const kind = entry.isDirectory() ? 'directory' : entry.isFile() ? 'file' : entry.isSymbolicLink() ? 'link' : null
102
+ if (!kind || !safeName(entry.name)) continue
103
+ rows.push({ name: entry.name, kind })
104
+ // Keep only the leading pages, even if this directory contains many more entries.
105
+ if (rows.length >= Math.max(512, keep * 2)) { rows.sort(compareEntries); rows.length = keep }
106
+ }
107
+ rows.sort(compareEntries)
108
+ await verifyResource(location, signal)
109
+ const entries = await Promise.all(rows.slice(offset, offset + pageSize).map(async entry => {
110
+ const resource = relative ? `${relative}/${entry.name}` : entry.name
111
+ const stat = await lstat(path.join(location.target, entry.name))
112
+ if ((entry.kind === 'file' && !stat.isFile()) || (entry.kind === 'directory' && !stat.isDirectory()) || (entry.kind === 'link' && !stat.isSymbolicLink())) throw changed()
113
+ return entry.kind === 'file' ? { ...entry, path: resource, size: stat.size } : { ...entry, path: resource }
114
+ }))
115
+ await verifyResource(location, signal)
116
+ return { path: relative, entries, nextOffset: rows.length > offset + pageSize ? offset + pageSize : null }
117
+ }
118
+
119
+ function decodeText(bytes, truncated) {
120
+ // Distinguish common printable container headers from plain text, even for a minimal PDF or GIF.
121
+ if (/^(%PDF-|GIF8[79]a)/.test(bytes.toString('latin1', 0, 6))) return null
122
+ let encoding = 'utf-8'
123
+ if (bytes[0] === 0xff && bytes[1] === 0xfe) encoding = 'utf-16le'
124
+ if (bytes[0] === 0xfe && bytes[1] === 0xff) encoding = 'utf-16be'
125
+ try {
126
+ // At the byte boundary leave any partial UTF-8 sequence or UTF-16 surrogate out of the preview.
127
+ const content = new TextDecoder(encoding, { fatal: true }).decode(bytes, { stream: truncated })
128
+ return /[\u0000-\u0008\u000b\u000e-\u001f\u007f]/u.test(content) ? null : content
129
+ } catch { return null }
130
+ }
131
+
132
+ async function filePreview(location, relative, signal) {
133
+ if (!location.stat.isFile()) throw problem('NOT_A_FILE', '只能预览技能资源中的普通文件。')
134
+ const size = Number(location.stat.size)
135
+ let bytes
136
+ if (location.archived) {
137
+ // Electron's readFile reads ASAR bytes directly. Opening an fd can extract the file to disk.
138
+ if (size > archiveReadLimit) throw problem('RESOURCE_TOO_LARGE', '此归档资源超过 16 MiB,无法预览。')
139
+ const packed = await readFile(location.target, { signal })
140
+ if (packed.length !== size) throw changed()
141
+ await verifyResource(location, signal)
142
+ bytes = packed.subarray(0, previewBytes)
143
+ } else {
144
+ bytes = await readFilePrefix(location, size, signal)
145
+ }
146
+ const truncated = size > bytes.length
147
+ const content = decodeText(bytes, truncated)
148
+ return content === null ? { path: relative, kind: 'binary', size } : { path: relative, kind: 'text', size, content, truncated }
149
+ }
150
+
151
+ async function readFilePrefix(location, size, signal) {
152
+ const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)
153
+ const file = await open(location.target, flags)
154
+ try {
155
+ const stat = await file.stat({ bigint: true })
156
+ if (!stat.isFile() || location.stat.size !== stat.size || !sameNode(location.stat, stat, false)) throw changed()
157
+ await verifyResource(location, signal)
158
+ const bytes = Buffer.alloc(Math.min(size, previewBytes))
159
+ for (let read = 0; read < bytes.length;) {
160
+ signal.throwIfAborted()
161
+ const { bytesRead } = await file.read(bytes, read, bytes.length - read, read)
162
+ if (!bytesRead) throw changed()
163
+ read += bytesRead
164
+ }
165
+ const after = await file.stat({ bigint: true })
166
+ if (after.ctimeNs !== stat.ctimeNs || after.size !== stat.size) throw changed()
167
+ await verifyResource(location, signal)
168
+ return bytes
169
+ } finally { await file.close() }
170
+ }
171
+
172
+ function browserRequest(input, directory) {
173
+ const relative = resourcePath(directory && input.path === undefined ? '' : input.path, directory)
174
+ const offset = input.offset === undefined ? 0 : input.offset
175
+ if (directory && (!Number.isSafeInteger(offset) || offset < 0)) throw problem('INVALID_INPUT', '目录分页位置须为非负整数。')
176
+ return { relative, offset }
177
+ }
178
+
179
+ function resourceError(error) {
180
+ if (['ENOENT', 'ENOTDIR'].includes(error.code)) return problem('RESOURCE_NOT_FOUND', '技能资源不存在或已移动。')
181
+ if (error.code === 'ELOOP') return problem('PACKAGE_LINK', '不能通过符号链接浏览技能资源。')
182
+ if (['EACCES', 'EPERM'].includes(error.code)) return problem('RESOURCE_UNREADABLE', '主机无法读取此技能资源。')
183
+ return error
184
+ }
185
+
186
+ export async function browsePackage(library, context, id, input, directory, signal) {
187
+ const { relative, offset } = browserRequest(input, directory)
188
+ try {
189
+ const root = await packageRoot(library, context, id, signal)
190
+ const location = await locate(root, relative, signal)
191
+ return directory ? { ...await directoryPage(location, relative, offset, signal), root } : await filePreview(location, relative, signal)
192
+ } catch (error) { throw resourceError(error) }
193
+ }
194
+
195
+ export async function skillResources(item, signal) {
196
+ const source = item?.path
197
+ const base = item?.resourceBase
198
+ if (typeof source !== 'string' || !path.isAbsolute(source) || path.normalize(source) !== source ||
199
+ !/\.md$/i.test(source) || (base && base.kind !== 'directory')) return null
200
+ const root = path.dirname(source)
201
+ const entryPath = path.basename(source)
202
+ if (!safeName(entryPath) || (base && (typeof base.path !== 'string' || path.normalize(base.path) !== root))) return null
203
+ try {
204
+ const entry = await locate(root, entryPath, signal)
205
+ if (!entry.stat.isFile()) return null
206
+ const index = item.sourceDirectoryPath && await realpath(item.sourceDirectoryPath)
207
+ const relativeRoot = index ? path.relative(index, root) : ''
208
+ if (relativeRoot === '..' || relativeRoot.startsWith(`..${path.sep}`) || path.isAbsolute(relativeRoot)) return null
209
+ // Flat skill entries share the index directory, even if the file itself is named SKILL.md.
210
+ const shared = index === root
211
+ const canBrowse = Boolean(base && /^skill\.md$/i.test(entryPath) && !shared && root !== path.parse(root).root)
212
+ return { entry, files: { root, entryPath, canBrowse, archived: entry.archived } }
213
+ } catch (error) {
214
+ if (['ENOENT', 'ENOTDIR', 'EACCES', 'EPERM', 'ELOOP', 'PACKAGE_LINK', 'PACKAGE_CHANGED', 'NOT_A_DIRECTORY'].includes(error.code)) return null
215
+ throw error
216
+ }
217
+ }
218
+
219
+ export async function lookupSkillResources(library, context, id, signal) {
220
+ const { items } = await library.list(context.cwd, context.agent)
221
+ signal.throwIfAborted()
222
+ return skillResources(items?.find(item => item.id === id), signal)
223
+ }
224
+
225
+ export async function browseSkill(library, context, id, input, directory, signal) {
226
+ const { relative, offset } = browserRequest(input, directory)
227
+ try {
228
+ const resource = await lookupSkillResources(library, context, id, signal)
229
+ if (!resource) throw problem('NO_LOCAL_FILE', '此技能没有可浏览的本地 Markdown 文件。')
230
+ const { entry, files } = resource
231
+ if (!files.canBrowse && (directory ? relative !== '' : relative !== files.entryPath)) {
232
+ throw problem('RESOURCE_NOT_FOUND', '此技能只提供入口 Markdown 文件。')
233
+ }
234
+ if (directory && !files.canBrowse) {
235
+ await verifyResource(entry, signal)
236
+ const entries = offset === 0 ? [{ name: files.entryPath, kind: 'file', path: files.entryPath, size: Number(entry.stat.size) }] : []
237
+ return { ...files, path: '', entries, nextOffset: null }
238
+ }
239
+ const location = relative === files.entryPath ? entry : await locate(files.root, relative, signal)
240
+ const result = directory ? await directoryPage(location, relative, offset, signal) : await filePreview(location, relative, signal)
241
+ await verifyResource(entry, signal)
242
+ return directory ? { ...result, ...files } : result
243
+ } catch (error) { throw resourceError(error) }
244
+ }
@@ -0,0 +1,375 @@
1
+ import { controlIcon } from './control-icon.mjs'
2
+ import { skillAppearance } from './design.mjs'
3
+ import { createFileView } from './file-view.mjs'
4
+ import { matchesSkillState, packageModes, skillState, SKILL_STATE_FILTERS } from './skill-state.mjs'
5
+
6
+ let instance = 0
7
+
8
+ function normalize(value) {
9
+ return String(value || '').normalize('NFKC').trim().toLocaleLowerCase()
10
+ }
11
+
12
+ function matchesMember(member, word) {
13
+ return normalize(member.name).includes(word) || normalize(member.description).includes(word)
14
+ }
15
+
16
+ export function createPackageView(container, api, { back, openSkill, setEnabled, removePackage, renderMarkdown, menuTrigger, openMenu }) {
17
+ const doc = container.ownerDocument
18
+ const scroller = container.closest('.sm-ui-scroll') || container
19
+ const prefix = `sm-package-${++instance}`
20
+
21
+ function el(tag, className, text) {
22
+ const node = doc.createElement(tag)
23
+ if (className) node.className = className
24
+ if (text != null) node.textContent = text
25
+ return node
26
+ }
27
+
28
+ function button(className, text, action) {
29
+ const node = el('button', className, text)
30
+ node.type = 'button'
31
+ if (action) node.addEventListener('click', action)
32
+ return node
33
+ }
34
+
35
+ function iconButton(label, icon, action) {
36
+ const node = button('sm-ui-icon-button', '', action)
37
+ node.setAttribute('aria-label', label)
38
+ node.title = label
39
+ node.append(controlIcon(icon, 14))
40
+ return node
41
+ }
42
+
43
+ const root = el('article', 'sm-package')
44
+ root.hidden = true
45
+ const top = el('header', 'sm-pkg-top')
46
+ top.setAttribute('data-window-drag', '')
47
+ const backText = el('span', '', '返回技能列表')
48
+ const goBack = button('sm-ui-back', '', back)
49
+ goBack.append(controlIcon('arrow-left', 13), backText)
50
+ const remove = button('sm-ui-button sm-ui-destructive sm-pkg-remove', '删除技能包…', () => removePackage?.(pkg))
51
+ remove.setAttribute('aria-haspopup', 'dialog')
52
+ top.append(goBack, remove)
53
+ const tile = el('span', 'sm-ui-detail-tile sm-pkg-tile')
54
+ tile.append(controlIcon('layers', 32))
55
+ const title = el('h1', 'sm-ui-heading')
56
+ title.id = `${prefix}-heading`
57
+ title.tabIndex = -1
58
+ root.setAttribute('aria-labelledby', title.id)
59
+ const identity = el('code', 'sm-pkg-identity')
60
+ const description = el('p', 'sm-pkg-description')
61
+ const modes = el('p', 'sm-pkg-description')
62
+ const removalReason = el('p', 'sm-pkg-description')
63
+ const gate = el('section', 'sm-ui-detail-status sm-pkg-gate')
64
+ const gateCopy = el('div', 'sm-ui-status-copy')
65
+ const gateHeading = el('h2', '', '启用技能包')
66
+ gateHeading.id = `${prefix}-gate`
67
+ const gateHint = el('p', 'sm-ui-subtitle', '启用后按各技能原有设置调用。')
68
+ gateHint.id = `${prefix}-gate-hint`
69
+ const gateError = el('p', 'sm-pkg-gate-error')
70
+ gateError.setAttribute('role', 'alert')
71
+ const gateState = el('span', 'sm-ui-state-label')
72
+ gateState.setAttribute('aria-hidden', 'true')
73
+ const gateSwitch = button('sm-ui-detail-switch', '', toggleGate)
74
+ gateSwitch.setAttribute('role', 'switch')
75
+ gateSwitch.setAttribute('aria-labelledby', gateHeading.id)
76
+ gateSwitch.setAttribute('aria-describedby', gateHint.id)
77
+ gateSwitch.append(el('span'))
78
+ gateCopy.append(gateHeading, gateHint, gateError)
79
+ gate.append(gateCopy, gateState, gateSwitch)
80
+ const tabsRow = el('div', 'sm-ui-tab-row sm-pkg-tabs')
81
+ const tabs = el('div', 'sm-ui-tabs')
82
+ tabs.setAttribute('role', 'tablist')
83
+ tabs.setAttribute('aria-label', '技能包内容')
84
+ tabsRow.append(tabs)
85
+
86
+ function tabButton(key, text) {
87
+ const node = button('sm-ui-tab', text, () => chooseTab(key))
88
+ node.id = `${prefix}-${key}`
89
+ node.setAttribute('role', 'tab')
90
+ node.setAttribute('aria-controls', `${node.id}-panel`)
91
+ tabs.append(node)
92
+ return node
93
+ }
94
+
95
+ function tabPanel(tab) {
96
+ const node = el('section', 'sm-pkg-panel')
97
+ node.id = tab.getAttribute('aria-controls')
98
+ node.setAttribute('role', 'tabpanel')
99
+ node.setAttribute('aria-labelledby', tab.id)
100
+ return node
101
+ }
102
+
103
+ const memberTab = tabButton('members', '包内技能')
104
+ const total = el('span', 'sm-pkg-total')
105
+ memberTab.append(total)
106
+ const filesTab = tabButton('files', '文件')
107
+ const memberPanel = tabPanel(memberTab)
108
+ const filesPanel = tabPanel(filesTab)
109
+ const filters = el('div', 'sm-pkg-filters')
110
+ const searchBox = el('div', 'sm-ui-search')
111
+ const search = el('input', 'sm-ui-search-input')
112
+ search.type = 'search'
113
+ search.autocomplete = 'off'
114
+ search.placeholder = '搜索包内技能'
115
+ search.setAttribute('aria-label', '搜索包内技能名称或描述')
116
+ const clear = iconButton('清除包内搜索', 'x', clearSearch)
117
+ searchBox.append(controlIcon('search', 16), search, clear)
118
+ const filter = button('sm-ui-button sm-pkg-filter', '')
119
+ const filterLabel = el('span')
120
+ filter.append(filterLabel, controlIcon('chevron-down', 13))
121
+ filter.dataset.smFocus = 'package-filter'
122
+ menuTrigger(filter, '包内技能调用状态', showFilterMenu)
123
+ filters.append(searchBox, filter)
124
+ const memberNote = el('p', 'sm-pkg-note')
125
+ memberNote.setAttribute('role', 'status')
126
+ const memberList = el('ul', 'sm-pkg-list')
127
+ memberList.id = `${prefix}-member-list`
128
+ memberList.setAttribute('aria-label', '包内技能')
129
+ search.setAttribute('aria-controls', memberList.id)
130
+ memberPanel.append(filters, memberNote, memberList)
131
+
132
+ root.append(top, tile, title, identity, description, modes, removalReason, gate, tabsRow, memberPanel, filesPanel)
133
+ container.append(root)
134
+
135
+ let pkg = null
136
+ let members = []
137
+ let mode = null
138
+ let activeTab = 'members'
139
+ let selectedFilter = 'all'
140
+ let memberScroll = 0
141
+ let resetFiles = false
142
+ let disposed = false
143
+ let lastMember = null
144
+ const pendingGates = new Set()
145
+ const memberRows = new Map()
146
+ const files = createFileView(filesPanel, {
147
+ entries: (path, offset) => api.packageEntries(pkg.id, path, offset),
148
+ file: path => api.packageFile(pkg.id, path),
149
+ }, { renderMarkdown })
150
+
151
+ function renderGate() {
152
+ gate.hidden = !pkg.canToggle || typeof setEnabled !== 'function'
153
+ if (gate.hidden) return
154
+ const busy = pendingGates.has(pkg.id)
155
+ gateState.textContent = pkg.enabled ? '已启用' : '已停用'
156
+ gateSwitch.dataset.smFocus = `package-gate-${pkg.id}`
157
+ gateSwitch.setAttribute('aria-checked', String(!!pkg.enabled))
158
+ gateSwitch.setAttribute('aria-disabled', String(busy))
159
+ gateSwitch.setAttribute('aria-busy', String(busy))
160
+ }
161
+
162
+ async function toggleGate() {
163
+ if (disposed || root.hidden || gate.hidden || pendingGates.has(pkg.id)) return
164
+ const id = pkg.id
165
+ pendingGates.add(id)
166
+ gateError.textContent = ''
167
+ renderGate()
168
+ try {
169
+ await setEnabled(id, !pkg.enabled)
170
+ } catch (error) {
171
+ if (!disposed && !root.hidden && pkg.id === id && !gate.hidden) {
172
+ gateError.textContent = error?.message || String(error || '修改失败,请重试。')
173
+ }
174
+ } finally {
175
+ pendingGates.delete(id)
176
+ if (!disposed && !root.hidden && pkg.id === id) renderGate()
177
+ }
178
+ }
179
+
180
+ function clearSearch() {
181
+ search.value = ''
182
+ renderMembers()
183
+ search.focus()
184
+ }
185
+
186
+ function showFilterMenu(first) {
187
+ const word = normalize(search.value)
188
+ const matching = members.filter(member => matchesMember(member, word))
189
+ const entries = []
190
+ let previousGroup
191
+ for (const { value, label, group } of SKILL_STATE_FILTERS) {
192
+ const count = matching.filter(member => matchesSkillState(member, value)).length
193
+ if (!count && value !== 'all') continue
194
+ entries.push({ action: value, label: `${label}(${count})`, checked: value === selectedFilter, separatorBefore: group !== previousGroup })
195
+ previousGroup = group
196
+ }
197
+ openMenu(filter, 'filter', entries, value => {
198
+ selectedFilter = value
199
+ renderMembers()
200
+ }, first)
201
+ }
202
+
203
+ search.addEventListener('input', renderMembers)
204
+ search.addEventListener('keydown', event => {
205
+ if (event.key === 'Escape' && search.value && !event.isComposing) {
206
+ event.preventDefault()
207
+ clearSearch()
208
+ }
209
+ })
210
+
211
+ function createMemberRow(id) {
212
+ const row = el('li')
213
+ const open = button('sm-pkg-row sm-pkg-member', '', () => {
214
+ lastMember = id
215
+ memberScroll = scroller.scrollTop
216
+ openSkill(id)
217
+ })
218
+ open.dataset.smPackageMember = id
219
+ const glyph = el('span', 'sm-pkg-member-icon')
220
+ const copy = el('span', 'sm-pkg-copy')
221
+ const name = el('span', 'sm-pkg-name')
222
+ const desc = el('span', 'sm-pkg-desc')
223
+ const state = el('span', 'sm-pkg-state')
224
+ copy.append(name, desc)
225
+ open.append(glyph, copy, state, rightArrow())
226
+ row.append(open)
227
+ return { row, open, glyph, name, desc, state }
228
+ }
229
+
230
+ function rightArrow() {
231
+ const arrow = controlIcon('arrow-left', 12)
232
+ arrow.classList.add('sm-pkg-arrow')
233
+ return arrow
234
+ }
235
+
236
+ function renderMembers() {
237
+ const word = normalize(search.value)
238
+ const visible = members.filter(member => matchesSkillState(member, selectedFilter) && matchesMember(member, word))
239
+ filterLabel.textContent = SKILL_STATE_FILTERS.find(({ value }) => value === selectedFilter).label
240
+ filter.setAttribute('aria-label', `包内技能调用状态 · ${filterLabel.textContent}`)
241
+ clear.hidden = !search.value
242
+ const active = doc.activeElement
243
+ const seen = new Set()
244
+ let next = memberList.firstElementChild
245
+ for (const member of visible) {
246
+ let parts = memberRows.get(member.id)
247
+ if (!parts) { parts = createMemberRow(member.id); memberRows.set(member.id, parts) }
248
+ seen.add(member.id)
249
+ if (parts.name.textContent !== member.name) {
250
+ const look = skillAppearance(member.name)
251
+ parts.glyph.style.color = look.color
252
+ parts.glyph.replaceChildren(controlIcon(look.icon, 23))
253
+ parts.name.textContent = member.name
254
+ }
255
+ const desc = member.description || ''
256
+ if (parts.desc.textContent !== desc) parts.desc.textContent = desc
257
+ parts.desc.hidden = !desc
258
+ const state = skillState(member, mode)
259
+ const labels = state.labels.join(' · ')
260
+ if (parts.state.textContent !== labels) parts.state.textContent = labels
261
+ parts.state.title = state.detail
262
+ parts.row.dataset.state = state.key
263
+ if (parts.row !== next) memberList.insertBefore(parts.row, next)
264
+ next = parts.row.nextElementSibling
265
+ }
266
+ for (const [id, parts] of memberRows) {
267
+ if (!seen.has(id)) { parts.row.remove(); memberRows.delete(id) }
268
+ }
269
+ if (active?.isConnected && memberList.contains(active) && doc.activeElement !== active) active.focus({ preventScroll: true })
270
+ const message = visible.length ? (word || selectedFilter !== 'all' ? `找到 ${visible.length} 个技能` : '')
271
+ : members.length ? '没有符合条件的包内技能。' : '此包中没有可见技能。'
272
+ if (memberNote.textContent !== message) memberNote.textContent = message
273
+ memberNote.hidden = !message
274
+ }
275
+
276
+ function paintTabs() {
277
+ for (const [key, tab, panel] of [['members', memberTab, memberPanel], ['files', filesTab, filesPanel]]) {
278
+ const selected = activeTab === key
279
+ tab.setAttribute('aria-selected', String(selected))
280
+ tab.tabIndex = selected ? 0 : -1
281
+ panel.hidden = !selected
282
+ }
283
+ }
284
+
285
+ function chooseTab(key) {
286
+ if (key === activeTab) return
287
+ if (activeTab === 'members') memberScroll = scroller.scrollTop
288
+ else files.hide()
289
+ activeTab = key
290
+ paintTabs()
291
+ if (key === 'files') showFiles()
292
+ else scroller.scrollTop = memberScroll
293
+ }
294
+
295
+ function showFiles() {
296
+ files.show({ id: pkg.id, root: pkg.root, reset: resetFiles })
297
+ resetFiles = false
298
+ }
299
+
300
+ tabs.addEventListener('keydown', event => {
301
+ let key
302
+ if (event.key === 'Home') key = 'members'
303
+ else if (event.key === 'End') key = 'files'
304
+ else if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') key = activeTab === 'members' ? 'files' : 'members'
305
+ else return
306
+ event.preventDefault()
307
+ event.stopPropagation()
308
+ chooseTab(key)
309
+ const selected = key === 'members' ? memberTab : filesTab
310
+ selected.focus({ preventScroll: true })
311
+ })
312
+
313
+ function hide() {
314
+ if (root.hidden) return
315
+ if (activeTab === 'members') memberScroll = scroller.scrollTop
316
+ files.hide()
317
+ root.hidden = true
318
+ }
319
+
320
+ function show(nextPackage, nextMembers, initialQuery = '', options = {}) {
321
+ if (disposed) return
322
+ const fresh = nextPackage.id !== pkg?.id || options.reset === true
323
+ const entering = fresh || root.hidden || root.parentNode !== container
324
+ if (fresh) files.hide()
325
+ pkg = nextPackage
326
+ members = nextMembers || []
327
+ mode = options.mode
328
+ if (fresh) {
329
+ gateError.textContent = ''
330
+ activeTab = 'members'
331
+ lastMember = null
332
+ memberScroll = 0
333
+ resetFiles = true
334
+ const word = normalize(initialQuery)
335
+ const packageMatch = [pkg.name, pkg.label].some(name => normalize(name).includes(word))
336
+ search.value = word && !packageMatch && members.some(member => matchesMember(member, word)) ? initialQuery : ''
337
+ selectedFilter = SKILL_STATE_FILTERS.some(({ value }) => value === options.filter) ? options.filter : 'all'
338
+ }
339
+ if (root.parentNode !== container) container.replaceChildren(root)
340
+ root.hidden = false
341
+ if (options.backLabel || fresh) backText.textContent = options.backLabel || '返回技能列表'
342
+ const label = pkg.label || pkg.name || '技能包'
343
+ if (title.textContent !== label) title.textContent = label
344
+ identity.textContent = pkg.name !== label ? pkg.name || '' : ''
345
+ identity.hidden = !identity.textContent
346
+ description.textContent = pkg.description || ''
347
+ description.hidden = !description.textContent
348
+ modes.textContent = packageModes(pkg, mode)
349
+ modes.hidden = !modes.textContent
350
+ remove.dataset.smFocus = `remove-package-${pkg.id}`
351
+ remove.hidden = !pkg.canRemove || !api.prepareRemoval || !removePackage
352
+ removalReason.hidden = pkg.canRemove !== false
353
+ removalReason.textContent = [pkg.removeReason, options.removalOrigin].filter(Boolean).join(' ')
354
+ total.textContent = String(members.length)
355
+ memberTab.setAttribute('aria-label', `包内技能(${members.length})`)
356
+ renderGate()
357
+ renderMembers()
358
+ if (entering) {
359
+ paintTabs()
360
+ if (activeTab === 'members') scroller.scrollTop = memberScroll
361
+ if (options.focus !== false) (activeTab === 'members' && memberRows.get(lastMember)?.open || title).focus({ preventScroll: true })
362
+ }
363
+ if (activeTab === 'files') showFiles()
364
+ }
365
+
366
+ function dispose() {
367
+ hide()
368
+ disposed = true
369
+ files.dispose()
370
+ memberRows.clear()
371
+ root.remove()
372
+ }
373
+
374
+ return { show, hide, dispose }
375
+ }