@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,277 @@
1
+ import { opendir, readdir, readFile, realpath } from 'node:fs/promises'
2
+ import { homedir } from 'node:os'
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
4
+ import { deriveFamily, FAMILY_MARKER, parseFamilyMarker } from './import-family.mjs'
5
+ import { limits, parseSkillMetadata, readRegular, statOrNull } from './import-files.mjs'
6
+
7
+ const provider = 'dsh-skill-manager-directories'
8
+ const npmName = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/
9
+ const toolFolders = ['.agents', '.claude', '.codex', '.gemini']
10
+ const resources = new Set(['assets', 'dist', 'build', 'docs', 'documentation', 'example', 'examples', 'fixture', 'fixtures', 'node_modules', 'reference', 'references', 'sample', 'samples', 'scripts', 'template', 'templates', 'test', 'tests', '__macosx'])
11
+ const deniedInvocation = Object.freeze({ modelInvocable: false, userInvocable: false })
12
+ const issued = new WeakMap()
13
+ const appArchive = process.versions.electron && process.resourcesPath && join(process.resourcesPath, 'app.asar')
14
+ const inArchive = path => Boolean(appArchive && path.startsWith(appArchive + sep))
15
+
16
+ function contains(root, file) {
17
+ const part = relative(root, file)
18
+ return part !== '..' && !part.startsWith(`..${sep}`) && !isAbsolute(part)
19
+ }
20
+
21
+ function missing(error) {
22
+ return ['ENOENT', 'ENOTDIR', 'FS_NOT_FOUND', 'FS_NOT_DIRECTORY'].includes(error.code)
23
+ }
24
+
25
+ // Package roots also back the owner's local file browser. The scoped DSH
26
+ // filesystem must explicitly share the same host location before we publish it.
27
+ function localAccess(ctx, { signal }) {
28
+ const fs = ctx.get('fs')
29
+ async function inspect(path, kind) {
30
+ signal?.throwIfAborted()
31
+ if (fs && fs.processPathFromHostPath(path) !== path) return
32
+ try {
33
+ let target, info
34
+ if (fs) {
35
+ info = await fs.lstat(path, {}, signal)
36
+ if (info?.type !== kind) return
37
+ target = await fs.resolve(path, { signal })
38
+ if (fs.processPath(target) !== path) return
39
+ }
40
+ const host = await statOrNull(path)
41
+ if (!(kind === 'directory' ? host?.isDirectory() : host?.isFile()) || await realpath(path) !== path) return
42
+ const archived = inArchive(path)
43
+ return { target, size: host.size, version: archived ? undefined : info?.version, ino: archived ? undefined : host.ino, dev: host.dev, ctime: host.ctimeMs }
44
+ } catch (error) { if (!missing(error)) throw error }
45
+ }
46
+ async function read(path, max, prefix = false, text = false) {
47
+ const before = await inspect(path, 'file')
48
+ if (!before) return
49
+ if (!prefix && before.size > max) throw new RangeError('技能文件超过读取上限。')
50
+ let result
51
+ if (!fs && inArchive(path)) {
52
+ if (before.size > limits.file) throw new RangeError('技能文件超过读取上限。')
53
+ const bytes = (await readFile(path, { signal })).subarray(0, max)
54
+ result = text ? bytes.toString('utf8') : bytes
55
+ } else if (!fs) {
56
+ const { bytes } = await readRegular(path, max, prefix)
57
+ result = text ? bytes.toString('utf8') : bytes
58
+ } else if (text) result = await fs.readText(before.target, signal)
59
+ else if (prefix) result = Buffer.from(await fs.readByteRange(before.target, { offset: 0, length: Math.min(before.size, max) }, signal))
60
+ else result = Buffer.from(await fs.readBytes(before.target, signal, max))
61
+ const after = await inspect(path, 'file')
62
+ if (!after || ['version', 'dev', 'ino', 'size', 'ctime'].some(key => after[key] !== before[key])) throw new Error('技能文件在读取期间发生变化。')
63
+ return result
64
+ }
65
+ async function directory(path, budget) {
66
+ const location = await inspect(path, 'directory')
67
+ if (!location) return new Map()
68
+ if (--budget.directories < 0) throw new RangeError('技能目录数量超过发现上限。')
69
+ // Electron supports readdir for its packaged application, but opendir goes
70
+ // directly to the operating system and sees the archive as a regular file.
71
+ const entries = fs ? await fs.listDir(location.target, signal) : inArchive(path) ? await readdir(path, { withFileTypes: true }) : await opendir(path)
72
+ const kinds = new Map()
73
+ for await (const entry of entries) {
74
+ signal?.throwIfAborted()
75
+ if (--budget.entries < 0) throw new RangeError('技能目录条目超过发现上限。')
76
+ if (!entry.name || entry.name === '.' || entry.name === '..' || /[\\/\x00-\x1f\x7f]/.test(entry.name)) continue
77
+ const kind = fs ? entry.type : entry.isDirectory() ? 'directory' : entry.isFile() ? 'file' : 'other'
78
+ kinds.set(entry.name, kind)
79
+ }
80
+ return kinds
81
+ }
82
+ return { inspect, read, directory }
83
+ }
84
+
85
+ // The native parser is exposed through FileSystemSkillProvider.get(). Give it
86
+ // the bytes just read from the verified file so it cannot reopen a swapped path.
87
+ async function parseNative(ctx, native, locator, source, text, options) {
88
+ const view = {
89
+ async resolve(path) { if (path !== locator.path) throw new Error('技能入口已经改变。'); return { displayPath: path } },
90
+ async stat() { return { type: 'file' } },
91
+ processPath() { return locator.path },
92
+ async readText() { return text },
93
+ }
94
+ const reader = new native.FileSystemSkillProvider({ get: () => view, logger: ctx.logger },
95
+ { signal: new AbortController().signal, invalidate() {} }, { providerName: provider, includeDefaultRoots: false, watch: false })
96
+ try {
97
+ // 'bundled' makes the native parser bypass its filesystem; the supplied
98
+ // bytes already came through this caller's filesystem for every source.
99
+ const skill = await reader.get({ locator, source: 'custom' }, options)
100
+ if (skill) return { ...skill, source }
101
+ } finally { await reader.dispose() }
102
+ }
103
+
104
+ async function discover(ctx, root, options, native, output) {
105
+ const access = localAccess(ctx, options)
106
+ const sourceRoot = resolve(root.path)
107
+ if (!isAbsolute(root.path) || dirname(sourceRoot) === sourceRoot || !await access.inspect(sourceRoot, 'directory')) return
108
+ const budget = { directories: 1024, entries: 8192, bytes: limits.bundle }
109
+ const cache = new Map()
110
+ async function entries(path) {
111
+ if (!cache.has(path)) cache.set(path, await access.directory(path, budget))
112
+ return cache.get(path)
113
+ }
114
+ async function bytes(path, max, prefix = false) {
115
+ const data = await access.read(path, max, prefix)
116
+ budget.bytes -= data?.length ?? 0
117
+ if (budget.bytes < 0) throw new RangeError('技能集合元数据超过读取上限。')
118
+ return data
119
+ }
120
+ const folders = listing => [...listing.keys()].filter(name => listing.get(name) === 'directory').sort()
121
+ async function memberEntries(path, listing, conventional = false) {
122
+ const found = []
123
+ for (const name of folders(listing)) {
124
+ if (name.startsWith('.') || (!conventional && resources.has(name.toLowerCase()))) continue
125
+ const file = join(path, name, 'SKILL.md')
126
+ if (await access.inspect(file, 'file')) found.push(file)
127
+ }
128
+ return found
129
+ }
130
+ async function mixedMarkdown(path, listing) {
131
+ for (const [name, kind] of listing) {
132
+ if (kind !== 'file' || !name.endsWith('.md')) continue
133
+ const data = await bytes(join(path, name), limits.header, true)
134
+ if (!data) continue
135
+ try { parseSkillMetadata(data.toString('utf8')); return true } catch (error) {
136
+ if (error.code !== 'INVALID_SKILL') throw error
137
+ }
138
+ }
139
+ return false
140
+ }
141
+ async function visit(path, depth) {
142
+ const listing = await entries(path)
143
+ const atRoot = path === sourceRoot
144
+ const own = !atRoot || root.includeDirect === true
145
+ const marked = own && listing.has(FAMILY_MARKER)
146
+ // A single skill may also be the entry of a documented family. Only the
147
+ // conventional skills containers can contribute members beneath this file.
148
+ const rootSkill = listing.has('SKILL.md')
149
+ if (rootSkill && !marked && (!own || !['skills', ...toolFolders].some(name => listing.get(name) === 'directory'))) return
150
+ let members = [], marker, manifest, manifestBytes
151
+ if (own) {
152
+ if (marked) {
153
+ marker = parseFamilyMarker((await bytes(join(path, FAMILY_MARKER), limits.file))?.toString('utf8'))
154
+ }
155
+ if (listing.get('package.json') === 'file') {
156
+ manifestBytes = await bytes(join(path, 'package.json'), 128 * 1024, true)
157
+ try { manifest = JSON.parse(manifestBytes) } catch { /* Optional display metadata. */ }
158
+ }
159
+ const containers = []
160
+ if (listing.get('skills') === 'directory') containers.push(join(path, 'skills'))
161
+ for (const tool of toolFolders) {
162
+ if (listing.get(tool) === 'directory') containers.push(join(path, tool, 'skills'))
163
+ }
164
+ for (const container of containers) members.push(...await memberEntries(container, await entries(container), true))
165
+ if (rootSkill) {
166
+ if (!members.length && !marker) return
167
+ members.push(join(path, 'SKILL.md'))
168
+ }
169
+ const packageName = typeof manifest?.name === 'string' && manifest.name.length <= 214 && npmName.test(manifest.name) ? manifest.name : null
170
+ const readme = [...listing.keys()].find(name => /^readme\.md$/i.test(name) && listing.get(name) === 'file')
171
+ const documentedRoot = atRoot && readme && !['skills', '.dsh', '.agents'].includes(basename(path).toLowerCase())
172
+ && path !== homedir() && !(options.cwd && contains(path, resolve(options.cwd)))
173
+ && await access.inspect(join(path, readme), 'file')
174
+ if (!members.length && (!atRoot || marker || packageName || documentedRoot)) {
175
+ if (marker || !atRoot || !await mixedMarkdown(path, listing)) members = await memberEntries(path, listing)
176
+ }
177
+ if (marker) {
178
+ members = [...new Set([...members, ...marker.members.map(item => join(path, item.entry))])]
179
+ }
180
+ if (members.length >= 2) {
181
+ const records = new Map()
182
+ function add(file, data) { const key = relative(path, file).split(sep).join('/'); records.set(key, { path: key, directory: false, bytes: data }) }
183
+ if (manifestBytes) add(join(path, 'package.json'), manifestBytes)
184
+ if (marker) add(join(path, FAMILY_MARKER), Buffer.from(JSON.stringify(marker)))
185
+ if (readme) {
186
+ const file = join(path, readme), data = await bytes(file, 128 * 1024, true)
187
+ if (data) add(file, data)
188
+ }
189
+ if (marker && !records.has(marker.entry) && await access.inspect(join(path, marker.entry), 'file')) add(join(path, marker.entry))
190
+ for (const file of members) {
191
+ if (!contains(path, file)) throw new Error('技能入口位于包根之外。')
192
+ const header = await bytes(file, limits.header, true)
193
+ if (header) add(file, header)
194
+ }
195
+ const info = deriveFamily([...records.values()], { sourceName: basename(path) })
196
+ if (!info) return
197
+ const hasReadme = records.has(readme)
198
+ const originalName = marker?.catalogName
199
+ const verifiedName = originalName === packageName || originalName === basename(path) ? originalName : undefined
200
+ const family = { root: path, name: verifiedName || marker?.id || packageName || (hasReadme ? info.id : basename(path)),
201
+ label: marker?.name || (hasReadme || packageName || manifest?.displayName ? info.name : basename(path)),
202
+ description: info.description, enabled: info.enabled, markerId: marker?.id ?? null, sourceRoot }
203
+ if (!marker) {
204
+ const template = { version: 1, id: info.id, catalogName: family.name, name: family.label,
205
+ description: info.description, entry: info.entry, enabled: true,
206
+ members: info.members.map(({ name, entry }) => ({ name, entry })), source: { format: 'folder', label: basename(path) } }
207
+ family.markerTemplate = parseFamilyMarker(JSON.stringify(template))
208
+ }
209
+ const candidates = []
210
+ for (const member of info.members) {
211
+ const file = join(path, member.entry), memberRoot = dirname(file)
212
+ const locator = Object.freeze({ path: file, directory: memberRoot })
213
+ const skill = await parseNative(ctx, native, locator, root.source, records.get(member.entry).bytes.toString('utf8'), options)
214
+ if (!skill || skill.name !== member.name) throw new Error('工具包成员的原生技能说明无效。')
215
+ const { content, ...summary } = skill
216
+ const facts = Object.freeze({ ...family, memberRoot, memberInvocation: Object.freeze({ ...skill.invocation }) })
217
+ issued.set(locator, { family: facts, entry: member.entry, name: skill.name, source: root.source })
218
+ candidates.push({ ...summary, rank: root.rank, locator, family: facts, invocation: facts.enabled ? skill.invocation : deniedInvocation })
219
+ }
220
+ output.candidates.push(...candidates)
221
+ return
222
+ }
223
+ }
224
+ if (depth >= 5) return
225
+ for (const name of folders(listing)) {
226
+ if (name.startsWith('.') || resources.has(name.toLowerCase())) continue
227
+ try { await visit(join(path, name), depth + 1) } catch (error) {
228
+ options.signal?.throwIfAborted()
229
+ output.complete = false
230
+ if (budget.directories < 0 || budget.entries < 0 || budget.bytes < 0) throw error
231
+ ctx.logger.warn(`技能包 ${join(path, name)} 无法读取:${error.message}`)
232
+ }
233
+ }
234
+ }
235
+ await visit(sourceRoot, 0)
236
+ }
237
+
238
+ export async function listFamilies(ctx, roots, options = {}, native) {
239
+ const output = { candidates: [], complete: true }
240
+ options.signal?.throwIfAborted()
241
+ for (const root of roots) {
242
+ try { await discover(ctx, root, options, native, output) } catch (error) {
243
+ options.signal?.throwIfAborted()
244
+ output.complete = false
245
+ ctx.logger.warn(`技能根 ${root.path} 无法读取:${error.message}`)
246
+ }
247
+ }
248
+ options.signal?.throwIfAborted()
249
+ return output
250
+ }
251
+
252
+ export async function getFamily(ctx, candidate, options = {}, native) {
253
+ options.signal?.throwIfAborted()
254
+ const locator = candidate?.locator, auth = issued.get(locator)
255
+ if (!auth) return
256
+ const { family, name, entry, source } = auth
257
+ if (!contains(family.sourceRoot, family.root) || !contains(family.root, locator.path) || locator.path !== join(family.root, entry) ||
258
+ locator.directory !== dirname(locator.path) || locator.directory !== family.memberRoot) return
259
+ const access = localAccess(ctx, options)
260
+ if (!await access.inspect(family.sourceRoot, 'directory') || !await access.inspect(family.root, 'directory')) return
261
+ const location = join(family.root, FAMILY_MARKER)
262
+ const raw = await access.read(location, limits.file)
263
+ let enabled = family.enabled
264
+ if (raw) {
265
+ const marker = parseFamilyMarker(raw.toString('utf8'))
266
+ if (marker.id !== family.markerId || !marker.members.some(member => member.name === name && member.entry === entry)) return
267
+ enabled = marker.enabled
268
+ } else if (family.markerId) return
269
+ let text
270
+ try { text = await access.read(locator.path, limits.file, false, true) } catch (error) {
271
+ if (error.code === 'FS_NOT_TEXT') return
272
+ throw error
273
+ }
274
+ if (text === undefined) return
275
+ const skill = await parseNative(ctx, native, locator, source, text, options)
276
+ if (skill?.name === name) return enabled ? skill : { ...skill, invocation: deniedInvocation }
277
+ }
package/locale/en.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "meta": {
3
+ "title": "Skill manager",
4
+ "description": "Browse skills across modes and see how each mode supports automatic and manual invocation. Manage skill directories, import, delete and restore your own skills and packages, or create a skill in a new conversation."
5
+ },
6
+ "document": {
7
+ "loading": "Loading document",
8
+ "retry": "Retry",
9
+ "copy": "Copy",
10
+ "copied": "Copied",
11
+ "codeBlock": "Code block",
12
+ "wrap": "Wrap lines",
13
+ "unwrap": "Turn off line wrapping",
14
+ "footnotes": "Footnotes"
15
+ }
16
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "meta": {
3
+ "title": "技能管理器",
4
+ "description": "在侧栏浏览所有模式的技能,查看各模式的 Agent 和手动调用方式。管理技能目录,导入、删除或恢复自己的技能和工具包,也可在新会话中让 Agent 编写技能。"
5
+ },
6
+ "document": {
7
+ "loading": "正在读取文档",
8
+ "retry": "重试",
9
+ "copy": "复制",
10
+ "copied": "已复制",
11
+ "codeBlock": "代码块",
12
+ "wrap": "自动换行",
13
+ "unwrap": "取消自动换行",
14
+ "footnotes": "脚注"
15
+ }
16
+ }
@@ -0,0 +1,158 @@
1
+ import { problem } from './import-files.mjs'
2
+
3
+ const management = Symbol('skill management view')
4
+ const missingPreset = new Set(['agent-preset/not-found', 'agent-preset/invalid', 'agent-preset/no-default'])
5
+ const unavailablePreset = () => problem('PRESET_NOT_FOUND', '所选模式已不可用,请刷新模式列表。')
6
+
7
+ export async function managementSelection(presets, presetId = null, signal) {
8
+ const modes = new Map()
9
+ const warnings = new Set()
10
+ for (const preset of await presets?.list() ?? []) {
11
+ if (typeof preset?.id !== 'string' || !preset.id.trim() || modes.has(preset.id)) continue
12
+ const name = typeof preset.name === 'string' && preset.name.trim() ? preset.name : undefined
13
+ if (preset.broken) warnings.add(modeWarning({ id: preset.id, name }))
14
+ else modes.set(preset.id, { id: preset.id, ...(name && { name }) })
15
+ }
16
+ signal?.throwIfAborted()
17
+ if (presetId !== null && !modes.has(presetId)) throw unavailablePreset()
18
+ return { [management]: { presets, modes, warnings, signal }, presetId }
19
+ }
20
+
21
+ export function isManagementSelection(selection) {
22
+ return selection?.[management] !== undefined
23
+ }
24
+
25
+ // Opening a single conversation only needs the first compatible mode. In particular,
26
+ // a click in Standard should not mount every other preset or wait for its providers.
27
+ export async function findManagementPreset(selection, fallback, matches) {
28
+ const { modes, signal } = selection[management]
29
+ for (const id of new Set([selection.presetId, fallback, ...modes.keys()])) {
30
+ if (!modes.has(id)) continue
31
+ try {
32
+ const accepted = await withManagementScope({ ...selection, presetId: id }, ({ scopes }) => matches(scopes[0].scope, signal))
33
+ if (accepted) return id
34
+ } catch (error) {
35
+ if (error.code !== 'PRESET_NOT_FOUND') throw error
36
+ }
37
+ }
38
+ }
39
+
40
+ function modeWarning(mode) {
41
+ return `模式「${mode.name ?? mode.id}」的技能目录暂时不可用。`
42
+ }
43
+
44
+ export async function withManagementScope(selection, action) {
45
+ const { presets, modes, warnings, signal } = selection[management]
46
+ const { presetId } = selection
47
+ const selected = presetId === null ? undefined : modes.get(presetId)
48
+ const leases = []
49
+ const scopes = []
50
+ const unavailable = new Set()
51
+ try {
52
+ for (const mode of selected ? [selected] : modes.values()) {
53
+ signal?.throwIfAborted()
54
+ let lease
55
+ try { lease = await presets.acquireScope(mode.id) }
56
+ catch (error) {
57
+ if (!missingPreset.has(error.code)) throw error
58
+ if (selected) throw unavailablePreset()
59
+ unavailable.add(mode.id)
60
+ continue
61
+ }
62
+ leases.push(lease)
63
+ scopes.push({ scope: lease.key, mode: { ...mode, source: 'preset' } })
64
+ }
65
+ signal?.throwIfAborted()
66
+ const mode = selected ? { ...selected, source: 'preset' } : { id: null, source: 'all' }
67
+ const notices = selected ? [] : [...warnings, ...Array.from(unavailable, id => modeWarning(modes.get(id)))].sort()
68
+ return await action({
69
+ mode,
70
+ scopes: scopes.length ? scopes : [{ scope: undefined, mode }],
71
+ modes: [...modes.values()].filter(mode => !unavailable.has(mode.id)),
72
+ warnings: notices,
73
+ signal,
74
+ })
75
+ } finally {
76
+ await Promise.all(leases.map(async lease => lease[Symbol.asyncDispose]()))
77
+ }
78
+ }
79
+
80
+ function modeState({ mode, output }, item) {
81
+ const { id, name } = mode
82
+ if (!item) return { id, ...(name && { name }), available: output.complete ? false : null }
83
+ const { enabled, effective, canToggle, toggleReason, invocation, shadowedBy, manualCommand, referencedBy } = item
84
+ return {
85
+ id, ...(name && { name }), available: true, enabled, effective, canToggle, toggleReason, invocation,
86
+ excluded: item.excluded === true, invocationAvailable: item.invocationAvailable !== false,
87
+ shadowedBy, referencedBy, packageEnabled: item.package?.enabled ?? null, manualCommand,
88
+ }
89
+ }
90
+
91
+ function byId(group, key) {
92
+ let members = group.get(key)
93
+ if (!members) { members = new Map(); group.set(key, members) }
94
+ return members
95
+ }
96
+
97
+ function representative(candidates, score) {
98
+ return Array.from(candidates.values()).reduce((best, candidate) => score(candidate) > score(best) ? candidate : best)
99
+ }
100
+
101
+ export function mergeManagementViews(views, { mode, modes, warnings }) {
102
+ const definitions = new Map(), packages = new Map(), directories = new Map(), packageRemovals = new Map()
103
+ for (const current of views) {
104
+ for (const [key, entry] of current.entries) {
105
+ byId(definitions, key).set(current.mode.id, { entry, current })
106
+ if (!entry.item.package) continue
107
+ const members = byId(packages, entry.item.package.id)
108
+ if (!members.has(current.mode.id)) members.set(current.mode.id, { package: entry.item.package, items: [] })
109
+ members.get(current.mode.id).items.push(entry.item)
110
+ }
111
+ for (const directory of current.output.directories) {
112
+ if (!directories.has(directory.id) || directory.writable) directories.set(directory.id, directory)
113
+ }
114
+ for (const [key, removal] of current.packageRemovals) if (!packageRemovals.has(key)) packageRemovals.set(key, removal)
115
+ }
116
+
117
+ const modesWithViews = views.filter(current => current.mode.id !== null)
118
+ const packageRows = new Map()
119
+ for (const [key, candidates] of packages) {
120
+ const { package: selected } = representative(candidates, ({ package: pkg }) => (pkg.canToggle ? 2 : 0) + (pkg.canRemove ? 1 : 0))
121
+ packageRows.set(key, {
122
+ ...selected,
123
+ modeStates: modesWithViews.map(current => {
124
+ const value = candidates.get(current.mode.id)
125
+ if (!value) return modeState(current)
126
+ const { enabled, canToggle } = value.package
127
+ return { id: current.mode.id, ...(current.mode.name && { name: current.mode.name }), available: true,
128
+ enabled, canToggle, effective: value.items.some(item => item.effective),
129
+ invocationAvailable: value.items.some(item => item.invocationAvailable !== false),
130
+ excluded: value.items.every(item => item.excluded), packageEnabled: enabled }
131
+ }),
132
+ })
133
+ }
134
+
135
+ const entries = new Map()
136
+ for (const [key, candidates] of definitions) {
137
+ const { entry, current } = representative(candidates, ({ entry: { item } }) =>
138
+ (item.canToggle ? 8 : 0) + (item.effective ? 4 : 0) + (item.enabled ? 2 : 0) + (item.canRemove ? 1 : 0))
139
+ const variants = [...candidates.values()].map(({ entry }) => entry.item)
140
+ const item = { ...entry.item,
141
+ enabled: variants.some(item => item.enabled), effective: variants.some(item => item.effective),
142
+ canToggle: variants.some(item => item.canToggle), excluded: variants.every(item => item.excluded),
143
+ invocationAvailable: variants.some(item => item.invocationAvailable !== false),
144
+ modeStates: modesWithViews.map(current => modeState(current, candidates.get(current.mode.id)?.entry.item)),
145
+ }
146
+ if (item.effective) item.shadowedBy = null
147
+ if (item.package) item.package = packageRows.get(item.package.id)
148
+ entries.set(key, { ...entry, item, origin: { item: entry.item, scope: current.scope } })
149
+ }
150
+
151
+ const items = Array.from(entries.values(), entry => entry.item).sort((a, b) =>
152
+ a.name.localeCompare(b.name) || Number(b.effective) - Number(a.effective) || a.id.localeCompare(b.id))
153
+ return { entries, packageRemovals, output: {
154
+ items, directories: [...directories.values()], cwd: views[0].output.cwd, mode, modes,
155
+ complete: warnings.length === 0 && views.every(current => current.output.complete),
156
+ warnings: [...new Set([...views.flatMap(current => current.output.warnings), ...warnings])],
157
+ } }
158
+ }
package/mode-view.mjs ADDED
@@ -0,0 +1,72 @@
1
+ import { controlIcon } from './control-icon.mjs'
2
+ import { modeName } from './skill-state.mjs'
3
+
4
+ // Main's workspace snapshot also changes when conversations move. Project
5
+ // only workspace identity and label so those updates leave the panel mounted.
6
+ export function workspaceProjection({ items }) {
7
+ const workspaces = items.map(({ workspaceId, title, path }) => ({ id: workspaceId, name: title || path }))
8
+ return JSON.stringify(workspaces.sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id)))
9
+ }
10
+
11
+ export function modeChoices(modes, selected) {
12
+ const choices = new Map([['', '全部模式']])
13
+ for (const mode of modes) choices.set(mode.id, modeName(mode))
14
+ if (selected && !choices.has(selected)) choices.set(selected, modeName({ id: selected }))
15
+ return choices
16
+ }
17
+
18
+ export function createScopeFilters(doc, { workspaceId, presetId, workspaces, onChange, menuTrigger, openMenu }) {
19
+ const node = doc.createElement('div')
20
+ node.className = 'sm-ui-scope-filters'
21
+ let changing = false
22
+
23
+ function field(text, key, selected, initialChoices, choose) {
24
+ const label = doc.createElement('label')
25
+ const trigger = doc.createElement('button')
26
+ const value = doc.createElement('span')
27
+ trigger.type = 'button'
28
+ trigger.className = 'sm-ui-button sm-ui-scope-control'
29
+ trigger.dataset.smFocus = key
30
+ trigger.append(value, controlIcon('chevron-down', 13))
31
+ label.append(text, trigger)
32
+ node.append(label)
33
+
34
+ let choices
35
+ menuTrigger(trigger, text, first => {
36
+ const entries = Array.from(choices, ([id, name]) => ({ action: id, label: name, checked: id === selected }))
37
+ openMenu(trigger, 'scope', entries, id => choose(id, key), first)
38
+ })
39
+ function setChoices(next) {
40
+ choices = next
41
+ value.textContent = choices.get(selected) || selected
42
+ trigger.title = `${text} · ${value.textContent}`
43
+ trigger.setAttribute('aria-label', trigger.title)
44
+ trigger.disabled = changing || choices.size < 2
45
+ }
46
+ setChoices(initialChoices)
47
+ return { trigger, setChoices }
48
+ }
49
+
50
+ const workspaceChoices = new Map([['', '默认工作目录'], ...workspaces.map(({ id, name }) => [id, name])])
51
+ const workspace = field('工作区', 'management-workspace', workspaceId, workspaceChoices,
52
+ (id, focus) => selectScope({ workspaceId: id, presetId, focus }))
53
+ const mode = field('模式', 'management-mode', presetId, modeChoices([], presetId),
54
+ (id, focus) => selectScope({ workspaceId, presetId: id, focus }))
55
+
56
+ function selectScope(next) {
57
+ if (changing || (next.workspaceId === workspaceId && next.presetId === presetId)) return
58
+ changing = true
59
+ node.setAttribute('aria-busy', 'true')
60
+ workspace.trigger.disabled = mode.trigger.disabled = true
61
+ onChange(next)
62
+ }
63
+ let previousModes
64
+ return {
65
+ node,
66
+ setModes(modes) {
67
+ if (modes === previousModes) return
68
+ previousModes = modes
69
+ mode.setChoices(modeChoices(modes, presetId))
70
+ },
71
+ }
72
+ }
@@ -0,0 +1,23 @@
1
+ The MIT License (Expat)
2
+
3
+ Copyright (c) 2014 Andrew Kelley
4
+
5
+ Permission is hereby granted, free of charge, to any person
6
+ obtaining a copy of this software and associated documentation files
7
+ (the "Software"), to deal in the Software without restriction,
8
+ including without limitation the rights to use, copy, modify, merge,
9
+ publish, distribute, sublicense, and/or sell copies of the Software,
10
+ and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Pend
2
+
3
+ Dead-simple optimistic async helper.
4
+
5
+ ## Usage
6
+
7
+ ```js
8
+ var Pend = require('pend');
9
+ var pend = new Pend();
10
+ pend.max = 10; // defaults to Infinity
11
+ setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
12
+ pend.go(function(cb) {
13
+ console.log("this function is immediately executed");
14
+ setTimeout(function() {
15
+ console.log("calling cb 1");
16
+ cb();
17
+ }, 500);
18
+ });
19
+ pend.go(function(cb) {
20
+ console.log("this function is also immediately executed");
21
+ setTimeout(function() {
22
+ console.log("calling cb 2");
23
+ cb();
24
+ }, 1000);
25
+ });
26
+ pend.wait(function(err) {
27
+ console.log("this is excuted when the first 2 have returned.");
28
+ console.log("err is a possible error in the standard callback style.");
29
+ });
30
+ ```
31
+
32
+ Output:
33
+
34
+ ```
35
+ this function is immediately executed
36
+ this function is also immediately executed
37
+ calling cb 1
38
+ calling cb 2
39
+ this is excuted when the first 2 have returned.
40
+ err is a possible error in the standard callback style.
41
+ ```
@@ -0,0 +1,55 @@
1
+ module.exports = Pend;
2
+
3
+ function Pend() {
4
+ this.pending = 0;
5
+ this.max = Infinity;
6
+ this.listeners = [];
7
+ this.waiting = [];
8
+ this.error = null;
9
+ }
10
+
11
+ Pend.prototype.go = function(fn) {
12
+ if (this.pending < this.max) {
13
+ pendGo(this, fn);
14
+ } else {
15
+ this.waiting.push(fn);
16
+ }
17
+ };
18
+
19
+ Pend.prototype.wait = function(cb) {
20
+ if (this.pending === 0) {
21
+ cb(this.error);
22
+ } else {
23
+ this.listeners.push(cb);
24
+ }
25
+ };
26
+
27
+ Pend.prototype.hold = function() {
28
+ return pendHold(this);
29
+ };
30
+
31
+ function pendHold(self) {
32
+ self.pending += 1;
33
+ var called = false;
34
+ return onCb;
35
+ function onCb(err) {
36
+ if (called) throw new Error("callback called twice");
37
+ called = true;
38
+ self.error = self.error || err;
39
+ self.pending -= 1;
40
+ if (self.waiting.length > 0 && self.pending < self.max) {
41
+ pendGo(self, self.waiting.shift());
42
+ } else if (self.pending === 0) {
43
+ var listeners = self.listeners;
44
+ self.listeners = [];
45
+ listeners.forEach(cbListener);
46
+ }
47
+ }
48
+ function cbListener(listener) {
49
+ listener(self.error);
50
+ }
51
+ }
52
+
53
+ function pendGo(self, fn) {
54
+ fn(pendHold(self));
55
+ }