@yanglaofish/fishtools 0.4.0 → 0.5.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 (262) hide show
  1. package/README.md +33 -5
  2. package/bin/fst.js +1 -1
  3. package/manual/README.md +33 -5
  4. package/manual/docs/deployment.md +3 -3
  5. package/manual/docs/kernel-generation.md +97 -0
  6. package/manual/docs/modules.md +57 -0
  7. package/manual/docs/plugin-development.md +120 -10
  8. package/manual/docs/releases.md +24 -0
  9. package/manual/docs/research/2026-10-11-plugin-kernel-capabilities.md +6 -6
  10. package/manual/docs/roadmap.md +14 -3
  11. package/manual/docs/superpowers/plans/2026-10-09-workflow-mvp.md +5 -5
  12. package/manual/docs/superpowers/plans/2026-10-11-public-plugin-fixes.md +2 -2
  13. package/manual/docs/superpowers/plans/2026-10-12-kernel-generation.md +22 -0
  14. package/manual/docs/superpowers/plans/2026-10-12-modular-kernel.md +40 -0
  15. package/manual/docs/superpowers/reviews/2026-10-12-kernel-generation-review.md +27 -0
  16. package/manual/docs/superpowers/reviews/2026-10-12-modular-kernel-review.md +32 -0
  17. package/manual/docs/superpowers/reviews/2026-10-13-0.5.0-followup-review.md +67 -0
  18. package/manual/docs/superpowers/reviews/2026-10-13-kernel-runtime-release-review.md +19 -0
  19. package/manual/docs/superpowers/specs/2026-10-12-action-network-policy-design.md +52 -0
  20. package/manual/docs/superpowers/specs/2026-10-12-kernel-generation-design.md +38 -0
  21. package/manual/docs/superpowers/specs/2026-10-12-modular-kernel-design.md +70 -0
  22. package/manual/docs/superpowers/specs/2026-10-12-plugin-readiness-design.md +21 -0
  23. package/manual/docs/superpowers/specs/2026-10-12-runtime-maintenance-granularity-design.md +35 -0
  24. package/manual/docs/superpowers/specs/2026-10-12-workflow-variation-design.md +19 -0
  25. package/manual/docs/verification.md +55 -2
  26. package/manual/packages/core/README.md +44 -0
  27. package/manual/packages/core/package.json +38 -0
  28. package/manual/packages/core/src/application.js +251 -85
  29. package/manual/packages/core/src/bundle.js +2 -0
  30. package/manual/packages/core/src/development-watch-worker.js +69 -0
  31. package/manual/packages/core/src/development.js +146 -0
  32. package/manual/packages/core/src/environments.js +2 -0
  33. package/manual/packages/core/src/export-snapshot.js +42 -0
  34. package/manual/packages/core/src/plugin-update.js +108 -0
  35. package/manual/packages/core/src/process.js +2 -0
  36. package/manual/packages/core/src/resources.js +31 -0
  37. package/manual/packages/core/src/version.js +2 -0
  38. package/manual/packages/fst-cli/LICENSE +21 -0
  39. package/manual/packages/fst-cli/README.md +59 -0
  40. package/{node_modules/@mytools/core → manual/packages/fst-cli}/bin/fst.js +55 -23
  41. package/manual/packages/fst-cli/package.json +50 -0
  42. package/manual/packages/fst-cli/src/development.js +53 -0
  43. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/model.js +1 -1
  44. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/navigation.js +1 -1
  45. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/presentation.js +9 -1
  46. package/manual/packages/fst-cli/src/terminal/run-feed.js +119 -0
  47. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/run-viewer.js +9 -7
  48. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/schema.js +1 -1
  49. package/manual/packages/{core → fst-cli}/src/terminal/session.js +137 -9
  50. package/manual/packages/{core → fst-cli}/src/terminal/view.js +20 -3
  51. package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/workflow-menu.js +17 -2
  52. package/manual/packages/fst-devtools/LICENSE +21 -0
  53. package/manual/packages/fst-devtools/README.md +28 -0
  54. package/manual/packages/fst-devtools/package.json +29 -0
  55. package/{node_modules/@mytools/core → manual/packages/fst-devtools}/src/documentation.js +3 -1
  56. package/manual/packages/fst-devtools/src/plugin-quality.js +136 -0
  57. package/{node_modules/@mytools/core → manual/packages/fst-devtools}/src/plugin-tools.js +24 -5
  58. package/manual/packages/fst-logs/LICENSE +21 -0
  59. package/manual/packages/fst-logs/README.md +67 -0
  60. package/manual/packages/fst-logs/package.json +26 -0
  61. package/manual/packages/fst-logs/src/log-bounds.js +91 -0
  62. package/manual/packages/fst-logs/src/run-logs.js +224 -0
  63. package/manual/packages/fst-logs/src/run-preview.js +18 -0
  64. package/manual/packages/fst-logs/src/step-summaries.js +28 -0
  65. package/manual/packages/fst-platform/LICENSE +21 -0
  66. package/manual/packages/fst-platform/README.md +73 -0
  67. package/manual/packages/fst-platform/package.json +33 -0
  68. package/manual/packages/fst-platform/src/bundle.js +17 -0
  69. package/manual/packages/fst-platform/src/environments.js +67 -0
  70. package/manual/packages/fst-platform/src/file-probe-engine.js +183 -0
  71. package/manual/packages/fst-platform/src/file-probe-worker.js +43 -0
  72. package/manual/packages/fst-platform/src/file-probe.js +6 -0
  73. package/manual/packages/fst-platform/src/json.js +5 -0
  74. package/manual/packages/fst-platform/src/network.js +199 -0
  75. package/manual/packages/fst-platform/src/npm.js +11 -0
  76. package/manual/packages/fst-platform/src/process.js +110 -0
  77. package/manual/packages/fst-plugin/LICENSE +21 -0
  78. package/manual/packages/fst-plugin/README.md +29 -0
  79. package/manual/packages/fst-plugin/package.json +29 -0
  80. package/{node_modules/@mytools/core → manual/packages/fst-plugin}/src/contracts.js +30 -3
  81. package/manual/packages/fst-plugin/src/host.js +235 -0
  82. package/manual/packages/fst-plugin/src/loader.js +21 -0
  83. package/manual/packages/fst-plugin/src/privileges.js +91 -0
  84. package/{node_modules/@mytools/core → manual/packages/fst-plugin}/src/runtime.js +27 -8
  85. package/manual/packages/fst-workflow/LICENSE +21 -0
  86. package/manual/packages/fst-workflow/README.md +28 -0
  87. package/manual/packages/fst-workflow/package.json +24 -0
  88. package/{node_modules/@mytools/core → manual/packages/fst-workflow}/src/control.js +3 -2
  89. package/manual/packages/{core → fst-workflow}/src/engine.js +2 -2
  90. package/manual/packages/fst-workspace/LICENSE +21 -0
  91. package/manual/packages/fst-workspace/README.md +32 -0
  92. package/manual/packages/fst-workspace/package.json +34 -0
  93. package/{node_modules/@mytools/core → manual/packages/fst-workspace}/src/bundle-workspace.js +1 -1
  94. package/manual/packages/fst-workspace/src/index.js +3 -0
  95. package/{node_modules/@mytools/core → manual/packages/fst-workspace}/src/plugins.js +6 -36
  96. package/{node_modules/@mytools/core → manual/packages/fst-workspace}/src/workflows.js +40 -7
  97. package/manual/packages/pack/LICENSE +21 -0
  98. package/manual/packages/pack/README.md +31 -0
  99. package/manual/packages/pack/archive.js +15 -0
  100. package/manual/packages/pack/dependencies.js +105 -0
  101. package/manual/packages/pack/environments.js +50 -0
  102. package/manual/packages/pack/index.js +103 -0
  103. package/manual/packages/pack/package.json +29 -0
  104. package/manual/packages/pack/runtime.js +61 -0
  105. package/manual/packages/sdk/README.md +31 -0
  106. package/manual/packages/sdk/conditions.js +1 -0
  107. package/manual/packages/sdk/package.json +23 -1
  108. package/manual/plugins/web/README.md +29 -0
  109. package/manual/tests/application.test.js +6 -4
  110. package/node_modules/@mytools/core/README.md +44 -0
  111. package/node_modules/@mytools/core/package.json +17 -17
  112. package/node_modules/@mytools/core/src/application.js +251 -85
  113. package/node_modules/@mytools/core/src/bundle.js +2 -17
  114. package/node_modules/@mytools/core/src/development-watch-worker.js +69 -0
  115. package/node_modules/@mytools/core/src/development.js +146 -0
  116. package/node_modules/@mytools/core/src/environments.js +2 -67
  117. package/node_modules/@mytools/core/src/export-snapshot.js +42 -0
  118. package/node_modules/@mytools/core/src/plugin-update.js +108 -0
  119. package/node_modules/@mytools/core/src/process.js +2 -80
  120. package/node_modules/@mytools/core/src/version.js +1 -1
  121. package/node_modules/@mytools/fst-cli/LICENSE +21 -0
  122. package/node_modules/@mytools/fst-cli/README.md +59 -0
  123. package/node_modules/@mytools/fst-cli/bin/fst.js +124 -0
  124. package/node_modules/@mytools/fst-cli/package.json +50 -0
  125. package/node_modules/@mytools/fst-cli/src/cli-run.js +12 -0
  126. package/node_modules/@mytools/fst-cli/src/development.js +53 -0
  127. package/node_modules/@mytools/fst-cli/src/terminal/conditions.js +32 -0
  128. package/node_modules/@mytools/fst-cli/src/terminal/log-viewer.js +45 -0
  129. package/node_modules/@mytools/fst-cli/src/terminal/model.js +104 -0
  130. package/node_modules/@mytools/fst-cli/src/terminal/navigation.js +17 -0
  131. package/node_modules/@mytools/fst-cli/src/terminal/presentation.js +50 -0
  132. package/node_modules/@mytools/fst-cli/src/terminal/run-feed.js +119 -0
  133. package/node_modules/@mytools/fst-cli/src/terminal/run-presentation.js +60 -0
  134. package/node_modules/@mytools/fst-cli/src/terminal/run-viewer.js +106 -0
  135. package/node_modules/@mytools/fst-cli/src/terminal/schema.js +52 -0
  136. package/node_modules/@mytools/{core → fst-cli}/src/terminal/session.js +137 -9
  137. package/node_modules/@mytools/fst-cli/src/terminal/theme.js +29 -0
  138. package/node_modules/@mytools/{core → fst-cli}/src/terminal/view.js +20 -3
  139. package/node_modules/@mytools/fst-cli/src/terminal/workflow-menu.js +65 -0
  140. package/node_modules/@mytools/fst-devtools/LICENSE +21 -0
  141. package/node_modules/@mytools/fst-devtools/README.md +28 -0
  142. package/node_modules/@mytools/fst-devtools/package.json +29 -0
  143. package/node_modules/@mytools/fst-devtools/src/documentation.js +67 -0
  144. package/node_modules/@mytools/fst-devtools/src/plugin-quality.js +136 -0
  145. package/node_modules/@mytools/fst-devtools/src/plugin-tools.js +152 -0
  146. package/node_modules/@mytools/fst-logs/LICENSE +21 -0
  147. package/node_modules/@mytools/fst-logs/README.md +67 -0
  148. package/node_modules/@mytools/fst-logs/package.json +26 -0
  149. package/node_modules/@mytools/fst-logs/src/log-bounds.js +91 -0
  150. package/node_modules/@mytools/fst-logs/src/markdown-log.js +55 -0
  151. package/node_modules/@mytools/fst-logs/src/run-logs.js +224 -0
  152. package/node_modules/@mytools/fst-logs/src/run-preview.js +18 -0
  153. package/node_modules/@mytools/fst-logs/src/step-summaries.js +28 -0
  154. package/node_modules/@mytools/fst-platform/LICENSE +21 -0
  155. package/node_modules/@mytools/fst-platform/README.md +73 -0
  156. package/node_modules/@mytools/fst-platform/package.json +33 -0
  157. package/node_modules/@mytools/fst-platform/src/bundle.js +17 -0
  158. package/node_modules/@mytools/fst-platform/src/environments.js +67 -0
  159. package/node_modules/@mytools/fst-platform/src/file-probe-engine.js +183 -0
  160. package/node_modules/@mytools/fst-platform/src/file-probe-worker.js +43 -0
  161. package/node_modules/@mytools/fst-platform/src/file-probe.js +6 -0
  162. package/node_modules/@mytools/fst-platform/src/json.js +5 -0
  163. package/node_modules/@mytools/fst-platform/src/network.js +199 -0
  164. package/node_modules/@mytools/fst-platform/src/npm.js +11 -0
  165. package/node_modules/@mytools/fst-platform/src/process.js +110 -0
  166. package/node_modules/@mytools/fst-plugin/LICENSE +21 -0
  167. package/node_modules/@mytools/fst-plugin/README.md +29 -0
  168. package/node_modules/@mytools/fst-plugin/package.json +29 -0
  169. package/node_modules/@mytools/fst-plugin/src/contracts.js +86 -0
  170. package/node_modules/@mytools/fst-plugin/src/host.js +235 -0
  171. package/node_modules/@mytools/fst-plugin/src/loader.js +21 -0
  172. package/node_modules/@mytools/fst-plugin/src/privileges.js +91 -0
  173. package/{manual/packages/core → node_modules/@mytools/fst-plugin}/src/runtime.js +27 -8
  174. package/node_modules/@mytools/fst-workflow/LICENSE +21 -0
  175. package/node_modules/@mytools/fst-workflow/README.md +28 -0
  176. package/node_modules/@mytools/fst-workflow/package.json +24 -0
  177. package/node_modules/@mytools/fst-workflow/src/control.js +64 -0
  178. package/node_modules/@mytools/{core → fst-workflow}/src/engine.js +2 -2
  179. package/node_modules/@mytools/fst-workspace/LICENSE +21 -0
  180. package/node_modules/@mytools/fst-workspace/README.md +32 -0
  181. package/node_modules/@mytools/fst-workspace/package.json +34 -0
  182. package/node_modules/@mytools/fst-workspace/src/bundle-workspace.js +39 -0
  183. package/node_modules/@mytools/fst-workspace/src/index.js +3 -0
  184. package/node_modules/@mytools/fst-workspace/src/plugin-installations.js +84 -0
  185. package/node_modules/@mytools/fst-workspace/src/plugins.js +35 -0
  186. package/node_modules/@mytools/fst-workspace/src/project.js +29 -0
  187. package/node_modules/@mytools/fst-workspace/src/workflows.js +150 -0
  188. package/node_modules/@mytools/fst-workspace/templates/control-demo.yaml +47 -0
  189. package/node_modules/@mytools/fst-workspace/templates/hello.yaml +35 -0
  190. package/node_modules/@mytools/fst-workspace/templates/python-check.yaml +26 -0
  191. package/node_modules/@mytools/fst-workspace/templates/system-check.yaml +11 -0
  192. package/node_modules/@mytools/pack/README.md +31 -0
  193. package/node_modules/@mytools/pack/dependencies.js +7 -2
  194. package/node_modules/@mytools/pack/environments.js +1 -1
  195. package/node_modules/@mytools/pack/index.js +33 -25
  196. package/node_modules/@mytools/pack/package.json +29 -1
  197. package/node_modules/@mytools/sdk/README.md +31 -0
  198. package/node_modules/@mytools/sdk/conditions.js +1 -0
  199. package/node_modules/@mytools/sdk/diagnostics.js +27 -0
  200. package/node_modules/@mytools/sdk/package.json +23 -1
  201. package/node_modules/@mytools/sdk/schema-path.js +31 -0
  202. package/node_modules/@mytools/sdk/validation.js +78 -0
  203. package/node_modules/@mytools/web/README.md +29 -0
  204. package/node_modules/@mytools/web/package.json +7 -0
  205. package/node_modules/@mytools/web/public/THIRD_PARTY_NOTICES.txt +1440 -1240
  206. package/node_modules/@mytools/web/public/assets/index-BaVzHycP.js +70 -0
  207. package/node_modules/@mytools/web/public/assets/index-DA8Ae92t.css +1 -0
  208. package/node_modules/@mytools/web/public/index.html +2 -2
  209. package/node_modules/@mytools/web/server.js +24 -17
  210. package/node_modules/@mytools/web/src/model.js +84 -0
  211. package/node_modules/acorn/CHANGELOG.md +1012 -0
  212. package/node_modules/acorn/LICENSE +21 -0
  213. package/node_modules/acorn/README.md +309 -0
  214. package/node_modules/acorn/bin/acorn +4 -0
  215. package/node_modules/acorn/dist/acorn.d.mts +897 -0
  216. package/node_modules/acorn/dist/acorn.d.ts +897 -0
  217. package/node_modules/acorn/dist/acorn.js +6370 -0
  218. package/node_modules/acorn/dist/acorn.mjs +6341 -0
  219. package/node_modules/acorn/dist/bin.js +90 -0
  220. package/node_modules/acorn/package.json +50 -0
  221. package/node_modules/{minipass-flush/node_modules/minipass → tar}/node_modules/yallist/README.md +8 -7
  222. package/node_modules/tar/node_modules/yallist/package.json +68 -0
  223. package/node_modules/yallist/README.md +7 -8
  224. package/node_modules/yallist/package.json +12 -51
  225. package/package.json +131 -115
  226. package/manual/packages/core/src/host.js +0 -139
  227. package/manual/packages/core/src/terminal/run-feed.js +0 -78
  228. package/node_modules/@mytools/core/src/host.js +0 -139
  229. package/node_modules/@mytools/core/src/run-logs.js +0 -63
  230. package/node_modules/@mytools/core/src/terminal/run-feed.js +0 -78
  231. package/node_modules/@mytools/web/public/assets/index-DT2B4tMV.js +0 -70
  232. package/node_modules/@mytools/web/public/assets/index-vuZvrUTT.css +0 -1
  233. package/node_modules/minipass-flush/node_modules/minipass/node_modules/yallist/package.json +0 -29
  234. /package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/cli-run.js +0 -0
  235. /package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/conditions.js +0 -0
  236. /package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/log-viewer.js +0 -0
  237. /package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/run-presentation.js +0 -0
  238. /package/{node_modules/@mytools/core → manual/packages/fst-cli}/src/terminal/theme.js +0 -0
  239. /package/{node_modules/@mytools/core → manual/packages/fst-logs}/src/markdown-log.js +0 -0
  240. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/src/plugin-installations.js +0 -0
  241. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/src/project.js +0 -0
  242. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/templates/control-demo.yaml +0 -0
  243. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/templates/hello.yaml +0 -0
  244. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/templates/python-check.yaml +0 -0
  245. /package/{node_modules/@mytools/core → manual/packages/fst-workspace}/templates/system-check.yaml +0 -0
  246. /package/{node_modules/@mytools/core/src → manual/packages/sdk}/diagnostics.js +0 -0
  247. /package/{node_modules/@mytools/core/src → manual/packages/sdk}/schema-path.js +0 -0
  248. /package/{node_modules/@mytools/core/src → manual/packages/sdk}/validation.js +0 -0
  249. /package/node_modules/{yallist → tar/node_modules/yallist}/LICENSE.md +0 -0
  250. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/commonjs/index.d.ts +0 -0
  251. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/commonjs/index.d.ts.map +0 -0
  252. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/commonjs/index.js +0 -0
  253. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/commonjs/index.js.map +0 -0
  254. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/commonjs/package.json +0 -0
  255. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/esm/index.d.ts +0 -0
  256. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/esm/index.d.ts.map +0 -0
  257. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/esm/index.js +0 -0
  258. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/esm/index.js.map +0 -0
  259. /package/node_modules/{yallist → tar/node_modules/yallist}/dist/esm/package.json +0 -0
  260. /package/node_modules/{minipass-flush/node_modules/minipass/node_modules/yallist → yallist}/LICENSE +0 -0
  261. /package/node_modules/{minipass-flush/node_modules/minipass/node_modules/yallist → yallist}/iterator.js +0 -0
  262. /package/node_modules/{minipass-flush/node_modules/minipass/node_modules/yallist → yallist}/yallist.js +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mytools contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # 开发工具模块
2
+
3
+ 包名:`@mytools/fst-devtools`。内部 workspace 包,随 `@yanglaofish/fishtools` 统一交付。
4
+
5
+ ## 职责与边界
6
+
7
+ 插件脚手架、validate、lint、离线文档发现与导出。不管理常驻宿主或用户运行状态。
8
+
9
+ 内部依赖:`@mytools/sdk`、`@mytools/fst-platform`、`@mytools/fst-plugin`。
10
+ ## 公开入口
11
+
12
+ | 导入路径 | 实现位置 |
13
+ | --- | --- |
14
+ | `@mytools/fst-devtools` | `./src/plugin-tools.js` |
15
+ | `@mytools/fst-devtools/documentation` | `./src/documentation.js` |
16
+ | `@mytools/fst-devtools/package.json` | `./package.json` |
17
+
18
+ 仅依赖 exports 声明的入口,禁止消费者跨包读取 src/bin 私有文件。入口路径由本模块维护,修改协议时同步消费方回归。
19
+
20
+ ## 维护与验证
21
+
22
+ 本模块负责上述职责的实现、文档与回归;跨模块接口调整需要同时检查生产者与消费者。具体维护人员尚未指定。
23
+
24
+ 在仓库根目录执行:
25
+
26
+ ```sh
27
+ node --test tests/modules.test.js tests/plugin-tools.test.js tests/plugin-lint.test.js tests/documentation.test.js
28
+ ```
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@mytools/fst-devtools",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "src/plugin-tools.js",
7
+ "exports": {
8
+ ".": "./src/plugin-tools.js",
9
+ "./documentation": "./src/documentation.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "license": "MIT",
18
+ "engines": {
19
+ "node": ">=24.15.0"
20
+ },
21
+ "dependencies": {
22
+ "@mytools/sdk": "0.1.0",
23
+ "@mytools/fst-platform": "0.1.0",
24
+ "@mytools/fst-plugin": "0.1.0",
25
+ "semver": "7.7.4",
26
+ "validate-npm-package-name": "8.0.0",
27
+ "acorn": "8.19.0"
28
+ }
29
+ }
@@ -9,10 +9,12 @@ const topics=[
9
9
  ['services','服务插件示例','examples/service-plugins/README.md'],
10
10
  ['example','可安装的零依赖动作插件','docs/examples/action-plugin/README.md'],
11
11
  ['roadmap','路线图','docs/roadmap.md'],
12
+ ['modules','模块架构与维护','docs/modules.md'],
13
+ ['generation','大日志、开发重载与隔离文件探测','docs/kernel-generation.md'],
12
14
  ['readme','Fishtools 使用说明','README.md'],
13
15
  ];
14
16
  // 保留文档链接所需的目录布局;参考代码仅供阅读,不是第二份运行时。
15
- const assets=['README.md','LICENSE','THIRD_PARTY_NOTICES.md','docs','examples/service-plugins','plugins/examples','plugins/environment','packages/sdk','packages/core/src/host.js','packages/core/src/runtime.js','packages/core/src/engine.js','packages/core/src/application.js','packages/core/src/terminal/view.js','packages/core/src/terminal/run-feed.js','packages/core/src/terminal/session.js','packages/core/LICENSE','tests/application.test.js'];
17
+ const assets=['README.md','LICENSE','THIRD_PARTY_NOTICES.md','docs','examples/service-plugins','plugins/examples','plugins/environment','plugins/web/README.md','packages/sdk','packages/core','packages/pack','packages/fst-logs','packages/fst-platform','packages/fst-workflow','packages/fst-plugin','packages/fst-workspace','packages/fst-devtools','packages/fst-cli','tests/application.test.js'];
16
18
  const excluded=new Set(['node_modules','dist','.git','.cache','__pycache__','.pytest_cache','coverage','public']);
17
19
  const inside=(parent,child)=>{const relative=path.relative(parent,child);return relative===''||(!relative.startsWith(`..${path.sep}`)&&relative!=='..'&&!path.isAbsolute(relative));};
18
20
 
@@ -0,0 +1,136 @@
1
+ import path from 'node:path';
2
+ import {readFile,realpath} from 'node:fs/promises';
3
+ import {isBuiltin,createRequire} from 'node:module';
4
+ import {fileURLToPath,pathToFileURL} from 'node:url';
5
+ import {parse} from 'acorn';
6
+
7
+ const nonempty=value=>typeof value==='string'&&value.trim().length>0;
8
+ function inspectSchema(schema,location,warning,seen=new WeakSet()){
9
+ if(typeof schema==='boolean'){
10
+ warning('BOOLEAN_SCHEMA','布尔 schema 合法,但无法提供字段级表单提示;建议按业务需要描述字段',location);return;
11
+ }
12
+ if(!schema||typeof schema!=='object'||seen.has(schema))return;
13
+ seen.add(schema);
14
+ if(Array.isArray(schema)){schema.forEach((child,index)=>inspectSchema(child,`${location}[${index}]`,warning,seen));return;}
15
+ for(const key of ['properties','patternProperties','$defs','definitions','dependencies']){
16
+ for(const [name,child] of Object.entries(schema[key]??{})){
17
+ const at=`${location}.${key}.${name}`;
18
+ if(['properties','patternProperties'].includes(key)&&!nonempty(child?.title))warning('MISSING_TITLE','字段缺少非空 title',`${at}.title`);
19
+ inspectSchema(child,at,warning,seen);
20
+ }
21
+ }
22
+ for(const key of ['items','additionalItems','contains','propertyNames','additionalProperties','not','if','then','else']){
23
+ // additionalProperties 等布尔约束是正常用法,不作为表单质量提示。
24
+ if(typeof schema[key]==='object')inspectSchema(schema[key],`${location}.${key}`,warning,seen);
25
+ }
26
+ for(const key of ['allOf','anyOf','oneOf','prefixItems']){
27
+ if(Array.isArray(schema[key]))schema[key].forEach((child,index)=>inspectSchema(child,`${location}.${key}[${index}]`,warning,seen));
28
+ }
29
+ }
30
+
31
+ export function inspectMetadata(plugin,warning){
32
+ for(const collection of ['actions','commands']){
33
+ for(const [name,item] of Object.entries(plugin[collection]??{})){
34
+ if(!item||typeof item!=='object')continue;
35
+ const location=`plugin.${collection}.${name}`;
36
+ // 动作别名命令可以复用动作元信息。
37
+ const target=collection==='commands'&&item.action?plugin.actions?.[item.action]:undefined;
38
+ for(const key of ['title','description']){
39
+ if(!nonempty(item[key]??target?.[key]))warning(`MISSING_${key.toUpperCase()}`,`缺少非空 ${key}`,`${location}.${key}`);
40
+ }
41
+ if(!target)for(const key of ['input','output'])inspectSchema(item[key],`${location}.${key}`,warning);
42
+ }
43
+ }
44
+ }
45
+
46
+ function walk(node,visit){
47
+ if(!node||typeof node!=='object')return;
48
+ if(typeof node.type==='string')visit(node);
49
+ for(const value of Object.values(node)){
50
+ if(Array.isArray(value))for(const child of value)walk(child,visit);
51
+ else if(value&&typeof value==='object')walk(value,visit);
52
+ }
53
+ }
54
+
55
+ function bindingNames(pattern,result){
56
+ if(!pattern)return;
57
+ if(pattern.type==='Identifier')result.set(pattern.name,(result.get(pattern.name)??0)+1);
58
+ else if(pattern.type==='RestElement')bindingNames(pattern.argument,result);
59
+ else if(pattern.type==='AssignmentPattern')bindingNames(pattern.left,result);
60
+ else if(pattern.type==='ObjectPattern')for(const p of pattern.properties)bindingNames(p.type==='RestElement'?p.argument:p.value,result);
61
+ else if(pattern.type==='ArrayPattern')for(const p of pattern.elements)bindingNames(p,result);
62
+ }
63
+
64
+ function sourceReferences(ast,commonjs,warning,location){
65
+ const bindings=new Map(),references=[],factories=new Set(),loaders=new Set();
66
+ walk(ast,node=>{
67
+ if(node.type==='VariableDeclarator')bindingNames(node.id,bindings);
68
+ if(['FunctionDeclaration','FunctionExpression','ArrowFunctionExpression'].includes(node.type)){
69
+ bindingNames(node.id,bindings);for(const p of node.params)bindingNames(p,bindings);
70
+ }
71
+ if(node.type==='ClassDeclaration'||node.type==='ClassExpression')bindingNames(node.id,bindings);
72
+ if(node.type==='CatchClause')bindingNames(node.param,bindings);
73
+ if(node.type==='ImportDeclaration')for(const p of node.specifiers){
74
+ bindingNames(p.local,bindings);
75
+ if(['node:module','module'].includes(node.source.value)&&p.imported?.name==='createRequire')factories.add(p.local.name);
76
+ }
77
+ // 重赋值也跳过,避免把可变的局部函数当作 require。
78
+ if(node.type==='AssignmentExpression')bindingNames(node.left,bindings);
79
+ });
80
+ walk(ast,node=>{
81
+ const base=node.init?.arguments?.[0];
82
+ if(node.type==='VariableDeclarator'&&node.id.type==='Identifier'&&bindings.get(node.id.name)===1&&node.init?.type==='CallExpression'&&
83
+ node.init.callee.type==='Identifier'&&factories.has(node.init.callee.name)&&bindings.get(node.init.callee.name)===1&&
84
+ base?.type==='MemberExpression'&&!base.computed&&base.property.name==='url'&&base.object.type==='MetaProperty'&&base.object.meta.name==='import')loaders.add(node.id.name);
85
+ });
86
+ // 保守跳过文件内重名绑定;不把局部对象当作 Node 全局对象。
87
+ walk(ast,node=>{
88
+ const at=`${location}:${node.loc.start.line}:${node.loc.start.column+1}`;
89
+ if(['ImportDeclaration','ExportNamedDeclaration','ExportAllDeclaration','ImportExpression'].includes(node.type)&&typeof node.source?.value==='string'){
90
+ references.push({specifier:node.source.value,at,commonjs:false});
91
+ }
92
+ if(node.type!=='CallExpression')return;
93
+ const callee=node.callee;
94
+ if(callee.type==='Identifier'&&((commonjs&&!bindings.has('require')&&callee.name==='require')||loaders.has(callee.name))&&typeof node.arguments[0]?.value==='string'){
95
+ references.push({specifier:node.arguments[0].value,at,commonjs:true});
96
+ }
97
+ if(!bindings.has('console')&&callee.type==='MemberExpression'&&callee.object.type==='Identifier'&&callee.object.name==='console'&&
98
+ (callee.computed?callee.property.value:callee.property.name)==='log')warning('CONSOLE_LOG','直接 console.log 可能干扰终端或 JSON 输出;动作和命令内请使用上下文 log / print',at);
99
+ });
100
+ return references;
101
+ }
102
+
103
+ export async function inspectSources(directory,pkg,warning){
104
+ const root=await realpath(directory),seen=new Set(),declared=new Set([pkg.name,...Object.keys(pkg.dependencies??{}),...Object.keys(pkg.peerDependencies??{}),...Object.keys(pkg.optionalDependencies??{})]);
105
+ const within=file=>{const relative=path.relative(root,file);return relative!== '..'&&!relative.startsWith(`..${path.sep}`)&&!path.isAbsolute(relative)&&!relative.split(path.sep).includes('node_modules');};
106
+ async function scan(file){
107
+ let actual;
108
+ try{actual=await realpath(file);}catch(cause){warning('SOURCE_UNREADABLE',`无法扫描本地模块:${cause.message}`,path.relative(root,file));return;}
109
+ if(!within(actual)){warning('SOURCE_OUTSIDE_PACKAGE','跳过包目录外或 node_modules 中的源码',path.relative(root,file));return;}
110
+ if(seen.has(actual))return;seen.add(actual);
111
+ const extension=path.extname(actual);
112
+ if(extension==='.json'||extension==='.node')return;
113
+ if(!['.js','.mjs','.cjs'].includes(extension)){warning('SOURCE_UNSUPPORTED','仅扫描 .js/.mjs/.cjs 源码',path.relative(root,actual));return;}
114
+ let ast;
115
+ const location=path.relative(root,actual),commonjs=extension==='.cjs';
116
+ try{ast=parse(await readFile(actual,'utf8'),{ecmaVersion:'latest',sourceType:commonjs?'commonjs':'module',locations:true});}
117
+ catch(cause){warning('SOURCE_PARSE_FAILED',`无法完成源码检查:${cause.message}`,location);return;}
118
+ for(const ref of sourceReferences(ast,commonjs,warning,location)){
119
+ const spec=ref.specifier;
120
+ if(isBuiltin(spec))continue;
121
+ if(spec.startsWith('.')){
122
+ try{
123
+ const target=ref.commonjs?createRequire(actual).resolve(spec):fileURLToPath(new URL(spec,pathToFileURL(actual)));
124
+ await scan(target);
125
+ }catch(cause){warning('SOURCE_UNREADABLE',`无法解析本地模块 ${spec}:${cause.message}`,ref.at);}
126
+ }else if(spec.startsWith('#')||spec.includes(':')||path.isAbsolute(spec)){
127
+ warning('DEPENDENCY_UNCHECKED',`未检查特殊模块引用 ${spec}`,ref.at);
128
+ }else{
129
+ const name=spec.startsWith('@')?spec.split('/').slice(0,2).join('/'):spec.split('/')[0];
130
+ if(!declared.has(name))warning('UNDECLARED_DEPENDENCY',`运行时引用 ${name},但 package.json 的 dependencies / optionalDependencies / peerDependencies 未声明它`,ref.at);
131
+ }
132
+ }
133
+ }
134
+ if(typeof (pkg.main??'index.js')!=='string'){warning('SOURCE_UNREADABLE','package.json.main 必须是入口路径','package.json.main');return;}
135
+ await scan(path.resolve(root,pkg.main??'index.js'));
136
+ }
@@ -3,10 +3,10 @@ import {readFile,writeFile,mkdir,mkdtemp,rename,rm,access} from 'node:fs/promise
3
3
  import semver from 'semver';
4
4
  import validateNpmPackageName from 'validate-npm-package-name';
5
5
  import {SDK_VERSION} from '@mytools/sdk';
6
- import {loadPlugin} from './plugins.js';
7
- import {validateDeclarations,validateCommands} from './contracts.js';
8
- import {assertSchema} from './validation.js';
9
- import {platformWarnings} from './environments.js';
6
+ import {loadPlugin} from '@mytools/fst-plugin/loader';
7
+ import {validateDeclarations,validateCommands} from '@mytools/fst-plugin/contracts';
8
+ import {assertSchema} from '@mytools/sdk/schema';
9
+ import {platformWarnings} from '@mytools/fst-platform/environments';
10
10
 
11
11
  const validNpmName=name=>typeof name==='string'&&validateNpmPackageName(name).validForNewPackages===true;
12
12
  const hasOwn=(value,key)=>Object.hasOwn(value,key);
@@ -28,7 +28,20 @@ function inspectRequired(schema,location,warning,seen=new WeakSet()){
28
28
  }
29
29
  }
30
30
 
31
+ const validationNotes=()=>[{code:'RUNTIME_OUTPUT_UNVERIFIED',message:'输出 required 字段是否实际返回无法静态确认;请按发布清单执行一次工作流验证。'}];
32
+
31
33
  export async function validatePluginDirectory(directory){
34
+ return {...await inspectPluginDirectory(directory),notes:validationNotes()};
35
+ }
36
+
37
+ export async function lintPluginDirectory(directory){
38
+ const quality=await import('./plugin-quality.js');
39
+ return {...await inspectPluginDirectory(directory,quality),notes:[...validationNotes(),
40
+ {code:'STATIC_SCAN_LIMITS',message:'源码检查仅覆盖入口可达的本地 JavaScript 和字面量依赖;动态加载、别名调用和局部重名可能无法识别。质量警告不会修改文件,也不代表运行结果或安全保证。'},
41
+ ]};
42
+ }
43
+
44
+ async function inspectPluginDirectory(directory,quality){
32
45
  const root=path.resolve(directory),diagnostics=[];
33
46
  const report=(severity,code,message,location)=>diagnostics.push({severity,code,message,...(location?{path:location}:{})});
34
47
  const error=(code,message,location)=>report('error',code,message,location);
@@ -40,10 +53,12 @@ export async function validatePluginDirectory(directory){
40
53
  if(!validNpmName(pkg.name))error('INVALID_PACKAGE_NAME','package.json 的 name 必须是合法 npm 包名','package.json.name');
41
54
  if(!semver.valid(pkg.version))error('INVALID_PACKAGE_VERSION','package.json 的 version 必须是 semver 版本','package.json.version');
42
55
  if(pkg.type!=='module')error('ESM_REQUIRED','插件必须声明 type: module','package.json.type');
56
+ if(quality)await quality.inspectSources(root,pkg,warning);
43
57
  try{({plugin}=await loadPlugin('.',root));}
44
58
  catch(cause){error('PLUGIN_LOAD_FAILED',`无法导入插件:${cause.message}`,'package.json.main');return {valid:false,plugin:{},diagnostics};}
45
59
  if(!plugin||typeof plugin!=='object'||Array.isArray(plugin)){error('INVALID_PLUGIN','默认导出必须是插件定义对象','plugin');return {valid:false,plugin:{},diagnostics};}
46
60
  const identity={id:plugin.id,version:plugin.version};
61
+ if(quality)quality.inspectMetadata(plugin,warning);
47
62
  if(!validNpmName(plugin.id))error('INVALID_PLUGIN_ID','插件 id 必须是合法 npm 包名','plugin.id');
48
63
  else if(plugin.id!==pkg.name)error('PLUGIN_ID_MISMATCH',`插件 id ${plugin.id} 与包名 ${pkg.name} 不一致`,'plugin.id');
49
64
  if(!semver.valid(plugin.version))error('INVALID_PLUGIN_VERSION','插件 version 必须是 semver 版本','plugin.version');
@@ -54,6 +69,10 @@ export async function validatePluginDirectory(directory){
54
69
  if(plugin[key]===undefined)warning(`${key.toUpperCase()}_UNDECLARED`,`${key} 未声明,请明确插件支持范围`,location);
55
70
  }
56
71
  try{validateDeclarations(plugin);}catch(cause){error('INVALID_DECLARATION',cause.message,cause.details?.path??'plugin');}
72
+ if((plugin.runtime||Object.keys(plugin.services??{}).length||Object.values(plugin.commands??{}).some(command=>!command.action))&&!plugin.requirements?.privilege)
73
+ warning('MISSING_PRIVILEGE_DECLARATION','插件服务或独立命令未声明权限要求;请说明普通用户是否可运行','plugin.requirements.privilege');
74
+ for(const [name,action] of Object.entries(plugin.actions??{}))if(!action?.requirements?.privilege&&!plugin.requirements?.privilege)
75
+ warning('MISSING_PRIVILEGE_DECLARATION',`动作 ${name} 未声明权限要求;请说明普通用户是否可运行`,`plugin.actions.${name}.requirements.privilege`);
57
76
  if(['platforms','architectures'].every(key=>plugin[key]===undefined||Array.isArray(plugin[key]))) {
58
77
  for(const message of platformWarnings(plugin))warning('PLATFORM_MISMATCH',message,message.includes('架构')?'plugin.architectures':'plugin.platforms');
59
78
  }
@@ -107,7 +126,7 @@ export async function validatePluginDirectory(directory){
107
126
 
108
127
  function scaffold(name){
109
128
  const packageJson={name,version:'1.0.0',type:'module',main:'index.js',files:['index.js','test','README.md','LICENSE'],scripts:{test:'node --test'},license:'MIT',engines:{node:'>=24.15.0'}};
110
- const plugin=`// 直接导出插件定义,无需安装内部 SDK。\nexport default {\n id:${JSON.stringify(name)},version:'1.0.0',sdk:'^0.1.0',\n title:'嵌套输入示例',description:'演示业务结果、嵌套输入和判定预设。',\n platforms:['win32','linux','darwin'],architectures:['x64','arm64'],\n actions:{\n check:{\n title:'检查请求',description:'根据嵌套请求生成业务结果。',\n input:{type:'object',properties:{request:{type:'object',properties:{name:{type:'string',minLength:1,title:'姓名'},enabled:{type:'boolean',title:'启用'}},required:['name','enabled'],additionalProperties:false}},required:['request'],additionalProperties:false},\n output:{type:'object',properties:{ok:{type:'boolean'},message:{type:'string'}},required:['ok','message'],additionalProperties:false},\n conditions:{passed:{title:'业务通过',path:'ok',op:'eq',value:true}},\n async run({request},{signal}={}){\n signal?.throwIfAborted?.();\n return request.enabled?{ok:true,message:\`你好,\${request.name}\`}:{ok:false,message:'已禁用'};\n },\n },\n },\n};\n`;
129
+ const plugin=`// 直接导出插件定义,无需安装内部 SDK。\nexport default {\n id:${JSON.stringify(name)},version:'1.0.0',sdk:'^0.1.0',\n title:'嵌套输入示例',description:'演示业务结果、嵌套输入和判定预设。',\n platforms:['win32','linux','darwin'],architectures:['x64','arm64'],\n actions:{\n check:{\n title:'检查请求',description:'根据嵌套请求生成业务结果。',\n input:{type:'object',properties:{request:{type:'object',properties:{name:{type:'string',minLength:1,title:'姓名'},enabled:{type:'boolean',title:'启用'}},required:['name','enabled'],additionalProperties:false}},required:['request'],additionalProperties:false},\n output:{type:'object',properties:{ok:{type:'boolean'},message:{type:'string'}},required:['ok','message'],additionalProperties:false},\n conditions:{passed:{title:'业务通过',path:'ok',op:'eq',value:true}},\n requirements:{privilege:{win32:{level:'user'},linux:{level:'user'}}},\n async run({request},{signal}={}){\n signal?.throwIfAborted?.();\n return request.enabled?{ok:true,message:\`你好,\${request.name}\`}:{ok:false,message:'已禁用'};\n },\n },\n },\n};\n`;
111
130
  const testSource=`import test from 'node:test';\nimport assert from 'node:assert/strict';\nimport plugin from '../index.js';\n\ntest('嵌套参数和业务判定',async()=>{\n assert.deepEqual(await plugin.actions.check.run({request:{name:'阿青',enabled:true}}),{ok:true,message:'你好,阿青'});\n assert.deepEqual(await plugin.actions.check.run({request:{name:'阿青',enabled:false}}),{ok:false,message:'已禁用'});\n});\n`;
112
131
  const readme=`# ${name}\n\n可独立安装的 Fishtools 插件示例,不依赖尚未公开发布的 SDK。\n\n## 使用\n\n在本目录运行 \`npm test\`,并运行 \`fst plugin validate .\` 检查声明。安装后可将 \`${name}:check\` 加入工作流。\n\n输入示例:\n\n\`\`\`json\n{"request":{"name":"阿青","enabled":true}}\n\`\`\`\n\n输出含 \`ok\` 与 \`message\`。\`ok:false\` 表示业务未通过,但动作仍正常返回;\`conditions.passed\` 可供工作流分支使用。请同步修改 package.json 和 index.js 中的名称、版本,并根据实际支持情况调整 platforms / architectures。\n`;
113
132
  const license=`MIT License\n\nCopyright (c) ${new Date().getFullYear()} ${name}\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n`;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mytools contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # 日志模块
2
+
3
+ 包名:`@mytools/fst-logs`。内部 workspace 包,随 `@yanglaofish/fishtools` 统一交付。
4
+
5
+ ## 职责与边界
6
+
7
+ 运行日志写入器、串行落盘、有界事件缓存、快照、历史分页、保留和体积统计。运行调度由 core 负责。
8
+
9
+ 内部依赖:`@mytools/sdk`。
10
+ ## 公开入口
11
+
12
+ | 导入路径 | 实现位置 |
13
+ | --- | --- |
14
+ | `@mytools/fst-logs` | `./src/run-logs.js` |
15
+ | `@mytools/fst-logs/markdown` | `./src/markdown-log.js` |
16
+ | `@mytools/fst-logs/steps` | `./src/step-summaries.js` |
17
+ | `@mytools/fst-logs/preview` | `./src/run-preview.js` |
18
+ | `@mytools/fst-logs/package.json` | `./package.json` |
19
+
20
+ 仅依赖 exports 声明的入口,禁止消费者跨包读取 src/bin 私有文件。入口路径由本模块维护,修改协议时同步消费方回归。
21
+
22
+ ## 日志策略与完整记录
23
+
24
+ `createRunLogs(directory,{projectDir,allowLegacy=false,...policy})` 接受以下字节预算:
25
+
26
+ | 字段 | 默认值 | 含义 |
27
+ | --- | --- | --- |
28
+ | maxEvents | 1000 | 内存尾部事件条数 |
29
+ | maxMemoryBytes | 1048576 | 尾部事件 JSON 数组总字节,至少 2 |
30
+ | maxEventBytes | 65536 | 单条预览 JSON 字节,至少 256 |
31
+ | maxPendingBytes | 8388608 | 尚未完成的写入任务字节预算 |
32
+ | maxDiskBytes | null | 每次运行所有约定日志文件总字节;null 不主动限制磁盘 |
33
+
34
+ `start(initial,{onEvent})` 返回 `append(event)`、`finish(state)`、`save(state)`、`snapshot(state)` 与原有 `markdown(state)`。完整事件(含 output)持续顺序写入 `events.jsonl`,完整 Markdown 持续追加到 `run.md`。完成时额外写入完整可解析的 `run.result` JSONL 记录;此记录不重复广播或加入缓存。运行 ID 的归属在开始时写入 `run.meta.json`,结束信息写入 `result.json`。
35
+
36
+ `onEvent` 与 `snapshot().events` 提供有界预览,巨大字段带 `eventTruncated:true`。每条追加事件有递增 `seq`,缓存被淘汰后消费者仍可识别新事件。快照增加 `eventCount`(包括最终 run.result)、`eventBytes` 和 `eventsTruncated`。快照中的业务 input/output 保持完整,不能以事件摘要替代工作流数据。历史 result.json 对巨大字段保存摘要及对应 `outputTruncated`、`inputTruncated` 等标记;完整最终 output 可从 JSONL 的 run.result 或 Markdown 取得。小字段保持原结构。
37
+
38
+ 快照与历史元数据另有 `stepSummaries`、`stepSummaryBytes`、`stepsTruncated`。步骤摘要按 callPath(缺少时按 stepId)保留最新状态,仅包含类型、定位、动作、时间、序号、耗时及有界原因/错误,不缓存 input/output。步骤摘要使用独立的 maxEvents/maxMemoryBytes 预算,因此两份缓存合计最多为两倍 maxMemoryBytes;单条步骤摘要仍受 maxEventBytes 限制。普通日志淘汰不影响步骤状态;步骤本身超预算淘汰时 stepsTruncated 为 true,展示端应把无法确认的步骤显示为未知状态。
39
+
40
+ `createStepSummaries(policy)` 从 `/steps` 入口提供同一套摘要缓存,日志写入器与 TUI 共用。
41
+ `append(event)` 更新状态并刷新淘汰顺序;`get(callPath)`、`values()` 和 `snapshot()` 返回副本。
42
+ `snapshot()` 包含上述三个步骤摘要字段,`size` 为保留条数。
43
+
44
+ `previewRun(record,{maxValueBytes=65536})` 从 `/preview` 入口提供展示与历史元数据共用的结果投影。
45
+ input/output、error、reason 等字段转为有界 JSON 预览,过大时标记 `<字段>Truncated:true`;业务数据对象不变。
46
+ 定位字段与 events/stepSummaries 保留,后两者由各自缓存预算负责;展示端应裁去不使用的缓存副本。
47
+ maxValueBytes 至少为 2,连预览本身也容不下时省略字段值并保留截断标记。
48
+
49
+ 队列预算在追加时检查。未等待 append 的插件同样受到预算约束;超限返回 `LOG_QUEUE_LIMIT` 拒绝,并使 finish 失败。拒绝已安装内部处理,调用方仍可 await 观察失败,不会产生未处理拒绝。`LOG_DISK_LIMIT` 表示可选磁盘预算不足,拒绝完整追加而不静默截断。磁盘预算与队列预算都计算 JSONL 和 Markdown。建议插件等待 append,以便磁盘写入形成背压。
50
+
51
+ `read`/`list` 仅读取受限的 result.json 元数据,运行中的 read 回退到归属元数据;不加载 JSONL 或 Markdown 正文。巨大旧 result.json 超过读取预算时,read 明确返回 `LOG_METADATA_LIMIT`,list 跳过该记录。旧版本缺少归属信息时仅在 `allowLegacy:true` 下可读。
52
+
53
+ ## 分页与文件保护
54
+
55
+ `page(id,{cursor=0,limit=65536})` 返回 `{text,cursor,nextCursor,hasMore,totalBytes}`,cursor 为 UTF-8 字节位置。limit 至少 4,最大 262144;页尾退回完整字符边界,下一页使用 nextCursor。落在字符内部、负数或超出正文长度的 cursor 返回 `LOG_CURSOR_INVALID`。运行中的分页同样验证项目归属;旧日志没有 Markdown 时使用有界元数据生成正文后分页。分页只读取当前页,原 `markdown(id)` 保留完整读取兼容接口,查看巨大日志应使用 page。
56
+
57
+ 拒绝日志根目录、运行目录或正文文件链接,已有同 ID 日志拒绝覆盖。体积统计和保留策略仅涉及 `run.md`、`events.jsonl`、`result.json`、`run.meta.json` 四个约定文件;业务文件和子目录保持保留。统计不递归、不读取正文。普通文件系统检查不能提供针对恶意并发路径替换的操作系统安全沙箱。
58
+
59
+ ## 维护与验证
60
+
61
+ 本模块负责上述职责的实现、文档与回归;跨模块接口调整需要同时检查生产者与消费者。具体维护人员尚未指定。
62
+
63
+ 在仓库根目录执行:
64
+
65
+ ```sh
66
+ node --test tests/log-streaming.test.js tests/modules.test.js tests/module-interfaces.test.js tests/run-logs.test.js tests/live-output.test.js
67
+ ```
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@mytools/fst-logs",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "src/run-logs.js",
7
+ "exports": {
8
+ ".": "./src/run-logs.js",
9
+ "./steps": "./src/step-summaries.js",
10
+ "./preview": "./src/run-preview.js",
11
+ "./markdown": "./src/markdown-log.js",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "src",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "license": "MIT",
20
+ "engines": {
21
+ "node": ">=24.15.0"
22
+ },
23
+ "dependencies": {
24
+ "@mytools/sdk": "0.1.0"
25
+ }
26
+ }
@@ -0,0 +1,91 @@
1
+ import {FlowError} from '@mytools/sdk';
2
+
3
+ export const defaults={maxEvents:1000,maxMemoryBytes:1024*1024,maxEventBytes:64*1024,maxPendingBytes:8*1024*1024,maxDiskBytes:null};
4
+ export function logPolicy(options){
5
+ const policy={};
6
+ for(const [key,value] of Object.entries(defaults)){
7
+ policy[key]=options[key]??value;
8
+ if(key==='maxDiskBytes'&&policy[key]===null)continue;
9
+ if(!Number.isSafeInteger(policy[key])||policy[key]<1)throw new FlowError(`日志 ${key} 必须为正整数`);
10
+ }
11
+ if(policy.maxEventBytes<256)throw new FlowError('日志 maxEventBytes 至少为 256 字节');
12
+ if(policy.maxMemoryBytes<2)throw new FlowError('日志 maxMemoryBytes 至少为 2 字节');
13
+ return policy;
14
+ }
15
+
16
+ export function utf8Prefix(text,bytes){
17
+ // 先按字符截取,使临时 Buffer 也受预算限制。
18
+ const buffer=Buffer.from(text.slice(0,bytes));
19
+ let end=Math.min(bytes,buffer.length);
20
+ if(end<buffer.length)while(end>0&&(buffer[end]&0xc0)===0x80)end--;
21
+ return buffer.subarray(0,end).toString('utf8');
22
+ }
23
+
24
+ // 估算完整 JSON 的字节量,超预算立即停止;避免为超大消息先复制整份字符串。
25
+ export function jsonSize(value,limit){
26
+ const seen=new Set();let bytes=0;
27
+ function count(value){
28
+ if(bytes>limit)return;
29
+ if(typeof value==='string'){
30
+ bytes+=2;
31
+ for(let i=0;i<value.length&&bytes<=limit;i++){
32
+ const code=value.charCodeAt(i);
33
+ if(code<32)bytes+=([8,9,10,12,13].includes(code)?2:6);
34
+ else if(code===34||code===92)bytes+=2;
35
+ else if(code<128)bytes++;
36
+ else if(code<2048)bytes+=2;
37
+ else if(code>=0xd800&&code<=0xdbff&&value.charCodeAt(i+1)>=0xdc00&&value.charCodeAt(i+1)<=0xdfff){bytes+=4;i++;}
38
+ else bytes+=(code>=0xd800&&code<=0xdfff)?6:3;
39
+ }
40
+ }else if(value===null)bytes+=4;
41
+ else if(typeof value==='number')bytes+=String(value).length;
42
+ else if(typeof value==='boolean')bytes+=value?4:5;
43
+ else if(typeof value==='bigint')throw new TypeError('日志不能序列化 BigInt');
44
+ else if(value&&typeof value==='object'){
45
+ if(seen.has(value))throw new TypeError('日志不能序列化循环引用');
46
+ seen.add(value);bytes+=2;
47
+ if(Array.isArray(value)){for(const item of value){count(item===undefined?null:item);bytes++;if(bytes>limit)break;}}
48
+ else for(const key of Object.keys(value)){
49
+ if(value[key]===undefined||typeof value[key]==='function'||typeof value[key]==='symbol')continue;
50
+ count(key);bytes+=2;count(value[key]);if(bytes>limit)break;
51
+ }
52
+ seen.delete(value);
53
+ }
54
+ }
55
+ count(value);return bytes;
56
+ }
57
+
58
+ export function preview(value,maxBytes){
59
+ if(jsonSize(value,maxBytes)<=maxBytes){const text=JSON.stringify(value);if(Buffer.byteLength(text)<=maxBytes)return {value:JSON.parse(text),truncated:false};}
60
+ let remaining=Math.max(0,maxBytes-64);
61
+ function copy(item,depth=0){
62
+ if(remaining<16||depth>12)return undefined;
63
+ if(typeof item==='string'){
64
+ const size=jsonSize(item,remaining);
65
+ if(size<=remaining){remaining-=size;return item;}
66
+ const text=utf8Prefix(item,Math.max(0,Math.floor((remaining-2)/6)));
67
+ remaining-=Buffer.byteLength(JSON.stringify(text));return text;
68
+ }
69
+ if(item===null||typeof item==='number'||typeof item==='boolean'){remaining-=16;return item;}
70
+ if(!item||typeof item!=='object')return undefined;
71
+ remaining-=2;const result=Array.isArray(item)?[]:{};
72
+ for(const key of Object.keys(item)){
73
+ const cost=Buffer.byteLength(JSON.stringify(key))+2;
74
+ if(cost+16>remaining)break;remaining-=cost;
75
+ const child=copy(item[key],depth+1);if(child!==undefined)result[key]=child;
76
+ }
77
+ return result;
78
+ }
79
+ return {value:copy(value)??null,truncated:true};
80
+ }
81
+
82
+ export function eventPreview(event,maxBytes){
83
+ // 增量序号、类型和归属优先,消息随后;巨大正文不能挤掉路由信息。
84
+ const ordered={seq:event.seq,type:event.type,runId:event.runId,time:event.time};
85
+ for(const key of ['callPath','stepId','action','stream'])if(event[key]!==undefined)ordered[key]=event[key];
86
+ if(event.message!==undefined)ordered.message=event.message;
87
+ for(const key of Object.keys(event))if(!(key in ordered))ordered[key]=event[key];
88
+ const result=preview(ordered,maxBytes);
89
+ if(result.truncated)result.value.eventTruncated=true;
90
+ return result.value;
91
+ }