weaver-work-cli 0.1.28 → 0.1.31

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 (219) hide show
  1. package/dist/chunks/archive-U766FTFH.js +2537 -0
  2. package/dist/chunks/archive-oa-DMWEKX3L.js +1317 -0
  3. package/dist/chunks/asset-TCR7VDEV.js +2109 -0
  4. package/dist/chunks/attachment-content-AQNX5N3S.js +23 -0
  5. package/dist/chunks/blog-EVZWGDVM.js +2157 -0
  6. package/dist/chunks/caizhilian-JOWS6SL5.js +10087 -0
  7. package/dist/chunks/calendar-5WNCV66Q.js +1195 -0
  8. package/dist/chunks/chunk-2DUV44UX.js +15606 -0
  9. package/dist/chunks/chunk-324YPTC2.js +1607 -0
  10. package/dist/chunks/chunk-65QMVWHS.js +231 -0
  11. package/dist/chunks/chunk-6V7ZLF34.js +387 -0
  12. package/dist/chunks/chunk-AC7KJWC5.js +358 -0
  13. package/dist/chunks/chunk-AJ62BGAW.js +29 -0
  14. package/dist/chunks/chunk-BUSC6UAE.js +43 -0
  15. package/dist/chunks/chunk-CVZ2JOSW.js +62 -0
  16. package/dist/chunks/chunk-D4LTJSJD.js +477 -0
  17. package/dist/chunks/chunk-EG6ZU444.js +654 -0
  18. package/dist/chunks/chunk-EZALDOQH.js +383 -0
  19. package/dist/chunks/chunk-FMPJJYYI.js +106 -0
  20. package/dist/chunks/chunk-G2JSIUWF.js +769 -0
  21. package/dist/chunks/chunk-GCG2NMWR.js +703 -0
  22. package/dist/chunks/chunk-GPMFD4RD.js +75 -0
  23. package/dist/chunks/chunk-H3WDBYJW.js +508 -0
  24. package/dist/chunks/chunk-H6XSTSLM.js +2357 -0
  25. package/dist/chunks/chunk-J7RJTZSV.js +5556 -0
  26. package/dist/chunks/chunk-LUSPKZKY.js +53 -0
  27. package/dist/chunks/chunk-NIAJ5ZCG.js +73 -0
  28. package/dist/chunks/chunk-NOODWMCL.js +584 -0
  29. package/dist/chunks/chunk-OOUTBLZ4.js +51 -0
  30. package/dist/chunks/chunk-P26ZWSKU.js +73 -0
  31. package/dist/chunks/chunk-QWY6PGL6.js +3472 -0
  32. package/dist/chunks/chunk-R2IJAK7T.js +464 -0
  33. package/dist/chunks/chunk-R7O5PUWO.js +205 -0
  34. package/dist/chunks/chunk-RCGYCOMG.js +6962 -0
  35. package/dist/chunks/chunk-VZTXRG6X.js +403 -0
  36. package/dist/chunks/chunk-WHD4XMRP.js +161 -0
  37. package/dist/chunks/chunk-YLCYX7LE.js +371 -0
  38. package/dist/chunks/chunk-ZEDWSH32.js +68 -0
  39. package/dist/chunks/continuation-2CKSBLA6.js +11 -0
  40. package/dist/chunks/continuation-HZIZRZBX.js +13 -0
  41. package/dist/chunks/continuation-NLECEJPX.js +11 -0
  42. package/dist/chunks/ebuilder-form-NJ4YK6CC.js +2276 -0
  43. package/dist/chunks/ehr-MMYN36VA.js +5241 -0
  44. package/dist/chunks/employee-SAK2QYXX.js +11 -0
  45. package/dist/chunks/esb-HIWHOU7Q.js +141 -0
  46. package/dist/chunks/fna-KBACQTA5.js +1444 -0
  47. package/dist/chunks/host-3OHS5QUX.js +21 -0
  48. package/dist/chunks/host-IG6KEH5Q.js +19 -0
  49. package/dist/chunks/host-KQL5N4HO.js +23 -0
  50. package/dist/chunks/host-LLSZQCWR.js +17 -0
  51. package/dist/chunks/hrm-LYEC67ZQ.js +244 -0
  52. package/dist/chunks/im-RN2UKAEU.js +252 -0
  53. package/dist/chunks/invoice-EEPHLAF6.js +5179 -0
  54. package/dist/chunks/jiuchuanhui-WVVZYSJE.js +1940 -0
  55. package/dist/chunks/lazy-dispatch-MDOFFL2S.js +28 -0
  56. package/dist/chunks/mail-LNQLTF6L.js +2695 -0
  57. package/dist/chunks/meeting-XSD3BDVQ.js +504 -0
  58. package/dist/chunks/msg-parse-4GSQ2WTO.js +41 -0
  59. package/dist/chunks/okr-TMWTIU2K.js +2482 -0
  60. package/dist/chunks/plan-A2FSFA7T.js +2025 -0
  61. package/dist/chunks/project-T26QLBQF.js +1361 -0
  62. package/dist/chunks/registry-2VLUAESA.js +14 -0
  63. package/dist/chunks/registry-JCFEYXOE.js +18 -0
  64. package/dist/chunks/registry-NYPYMZXG.js +16 -0
  65. package/dist/chunks/registry-Q7OQJ3SU.js +19 -0
  66. package/dist/chunks/registry-ZJMJVWFA.js +19 -0
  67. package/dist/chunks/room-recommend-UR4ZDZS6.js +20 -0
  68. package/dist/chunks/schedule-5L2PM4M6.js +24 -0
  69. package/dist/chunks/state-Y2XBP6YE.js +15 -0
  70. package/dist/chunks/workflow-TR6PG2SL.js +245 -0
  71. package/dist/cmd/argv.js +45 -0
  72. package/dist/cmd/docs/index.js +3 -3
  73. package/dist/cmd/lazy-dispatch.js +20 -0
  74. package/dist/cmd/root.js +2 -4
  75. package/dist/cmd/setup/index.js +2 -2
  76. package/dist/cmd/skills/index.js +2 -2
  77. package/dist/core/package-paths.js +47 -0
  78. package/dist/index.js +163 -7
  79. package/dist/internal/e10/auth/xiaoe.js +3 -3
  80. package/dist/internal/e10/request-runtime.js +18 -62
  81. package/dist/internal/skills/detector.js +2 -2
  82. package/dist/shortcuts/contract/data/performance-catalog.js +1306 -0
  83. package/dist/shortcuts/contract/host.js +91 -35
  84. package/dist/shortcuts/contract/index.js +213 -0
  85. package/dist/shortcuts/contract/manifest.js +928 -0
  86. package/dist/shortcuts/contract/ooxml/docx.js +295 -0
  87. package/dist/shortcuts/contract/ooxml/xlsx.js +221 -0
  88. package/dist/shortcuts/contract/ooxml/zip.js +158 -0
  89. package/dist/shortcuts/contract/operations/assistant.js +1156 -0
  90. package/dist/shortcuts/contract/operations/clause-library.js +522 -0
  91. package/dist/shortcuts/contract/operations/compare.js +193 -0
  92. package/dist/shortcuts/contract/operations/credit-page.js +34 -0
  93. package/dist/shortcuts/contract/operations/flow.js +98 -0
  94. package/dist/shortcuts/contract/operations/page.js +66 -0
  95. package/dist/shortcuts/contract/operations/performance.js +733 -0
  96. package/dist/shortcuts/contract/operations/quote.js +557 -0
  97. package/dist/shortcuts/contract/operations/recommend.js +78 -0
  98. package/dist/shortcuts/contract/operations/registry.js +18 -0
  99. package/dist/shortcuts/contract/operations/review.js +83 -0
  100. package/dist/shortcuts/contract/operations/shared.js +37 -0
  101. package/dist/shortcuts/contract/operations/upload.js +108 -0
  102. package/dist/shortcuts/contract/operations/write.js +3 -2
  103. package/dist/shortcuts/index.js +140 -40
  104. package/dist/shortcuts/invoice/host.js +2 -1
  105. package/dist/shortcuts/invoice/manifest.js +36 -12
  106. package/dist/shortcuts/invoice/operations/issuing-qys.js +132 -36
  107. package/dist/shortcuts/invoice/operations/reim-auto.js +9 -0
  108. package/dist/shortcuts/invoice/operations/reim.js +81 -5
  109. package/dist/shortcuts/invoice/operations/shared.js +12 -5
  110. package/dist/shortcuts/meeting/host.js +45 -3
  111. package/dist/shortcuts/meeting/invitation/docx.js +442 -0
  112. package/dist/shortcuts/meeting/operations/attachment-content.js +418 -0
  113. package/dist/shortcuts/meeting/operations/attachment.js +442 -0
  114. package/dist/shortcuts/meeting/operations/eb/cache.js +57 -0
  115. package/dist/shortcuts/meeting/operations/eb/catalog.js +343 -28
  116. package/dist/shortcuts/meeting/operations/eb/conflict.js +372 -11
  117. package/dist/shortcuts/meeting/operations/eb/create-flow.js +710 -0
  118. package/dist/shortcuts/meeting/operations/eb/decision.js +47 -1
  119. package/dist/shortcuts/meeting/operations/eb/factory.js +129 -11
  120. package/dist/shortcuts/meeting/operations/eb/index.js +122 -2
  121. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +378 -0
  122. package/dist/shortcuts/meeting/operations/eb/room-summary.js +84 -0
  123. package/dist/shortcuts/meeting/operations/eb/schedule.js +450 -0
  124. package/dist/shortcuts/meeting/operations/from-group-chat.js +576 -0
  125. package/dist/shortcuts/meeting/operations/invitation.js +458 -0
  126. package/dist/shortcuts/meeting/operations/minute-content.js +266 -0
  127. package/dist/shortcuts/meeting/operations/pipeline.js +489 -0
  128. package/dist/shortcuts/meeting/operations/qrcode.js +131 -0
  129. package/dist/shortcuts/meeting/operations/receipts.js +1 -1
  130. package/dist/shortcuts/meeting/operations/registry.js +18 -0
  131. package/dist/shortcuts/meeting/operations/summary.js +276 -0
  132. package/dist/shortcuts/meeting/operations/task-notify.js +325 -0
  133. package/dist/shortcuts/meeting/operations.js +42 -1
  134. package/dist/shortcuts/meeting/qr/encoder.js +427 -0
  135. package/dist/shortcuts/meeting/qr/render.js +103 -0
  136. package/dist/shortcuts/workflow/index.js +3 -0
  137. package/dist/shortcuts/workflow/operations/form.js +17 -5
  138. package/dist/shortcuts/workflow/operations/read.js +13 -6
  139. package/dist/shortcuts/workflow/operations/registry.js +2 -0
  140. package/dist/shortcuts/workflow/operations/todoSmartConvert/businessRules.js +331 -0
  141. package/dist/shortcuts/workflow/operations/todoSmartConvert/detailFieldRules.js +133 -0
  142. package/dist/shortcuts/workflow/operations/todoSmartConvert/summaryCache.js +326 -0
  143. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoDetailCache.js +113 -0
  144. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoDetailFetcher.js +259 -0
  145. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoListRows.js +64 -0
  146. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoOutputPlanner.js +28 -0
  147. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.aggregate.js +70 -0
  148. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +267 -0
  149. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +392 -0
  150. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.detail.js +165 -0
  151. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +448 -0
  152. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.groupSummary.js +348 -0
  153. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +222 -0
  154. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.pipeline.js +66 -0
  155. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +502 -0
  156. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.summary.js +540 -0
  157. package/docs/_catalog.md +1 -0
  158. package/docs/contract.md +39 -4
  159. package/docs/invoice.md +7 -7
  160. package/docs/todo-smart-convert/README.md +171 -0
  161. package/docs/todo-smart-convert/data-contract.md +236 -0
  162. package/docs/todo-smart-convert/mock/ai-todo-query-target.json +209 -0
  163. package/docs/todo-smart-convert/subgroup-rules.md +245 -0
  164. package/package.json +3 -2
  165. package/scripts/bundle.mjs +63 -0
  166. package/scripts/package-skill.mjs +1 -1
  167. package/skill-template/business-info.json +25 -4
  168. package/skill-template/domains/jinchengda.md +16 -3
  169. package/skill-template/domains/yepiaotong.md +3 -3
  170. package/skills/weaver-e10-jinchengda/SKILL.md +111 -31
  171. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +7 -13
  172. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +150 -0
  173. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +87 -0
  174. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +111 -0
  175. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +0 -15
  176. package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +0 -13
  177. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +50 -0
  178. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +4 -2
  179. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +74 -0
  180. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +84 -0
  181. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +29 -0
  182. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +28 -0
  183. package/skills/weaver-e10-jinchengda/references/contract-request-status.md +2 -21
  184. package/skills/weaver-e10-jinchengda/references/contract-request-write.md +0 -24
  185. package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +0 -15
  186. package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +0 -17
  187. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +70 -0
  188. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +0 -15
  189. package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +0 -15
  190. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1168 -152
  191. package/skills/weaver-e10-meeting/SKILL.md +493 -17
  192. package/skills/weaver-e10-meeting/references/meeting-change.md +4 -4
  193. package/skills/weaver-e10-meeting/references/meeting-create.md +6 -6
  194. package/skills/weaver-e10-meeting/references/meeting-eb.md +503 -27
  195. package/skills/weaver-e10-meeting/references/meeting-invitation.md +113 -0
  196. package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +6 -6
  197. package/skills/weaver-e10-meeting/references/meeting-minute-file.md +425 -0
  198. package/skills/weaver-e10-meeting/references/meeting-queries.md +4 -4
  199. package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +15 -15
  200. package/skills/weaver-e10-meeting/references/meeting-verification.md +19 -11
  201. package/skills/weaver-e10-meeting.zip +0 -0
  202. package/skills/weaver-e10-workflow/SKILL.md +23 -1
  203. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +282 -0
  204. package/skills/weaver-e10-workflow/scripts/todo-summary.cjs +695 -0
  205. package/skills/weaver-e10-yepiaotong/SKILL.md +15 -11
  206. package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +1 -1
  207. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-examples.md +10 -7
  208. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-form-fill-rules.md +41 -14
  209. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +54 -26
  210. package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +6 -5
  211. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +14 -11
  212. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +97 -56
  213. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +84 -60
  214. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +142 -105
  215. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +53 -194
  216. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +7 -7
  217. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +164 -72
  218. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +8 -2
  219. package/templates/meeting/invitation.docx +0 -0
@@ -0,0 +1,14 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ getImOperation,
5
+ imOperationDefinitions
6
+ } from "./chunk-QWY6PGL6.js";
7
+ import "./chunk-YLCYX7LE.js";
8
+ import "./chunk-ZEDWSH32.js";
9
+ import "./chunk-LUSPKZKY.js";
10
+ import "./chunk-BUSC6UAE.js";
11
+ export {
12
+ getImOperation,
13
+ imOperationDefinitions
14
+ };
@@ -0,0 +1,18 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ esbOperationDefinitions,
5
+ getEsbOperation,
6
+ hasEsbOperation
7
+ } from "./chunk-6V7ZLF34.js";
8
+ import "./chunk-R7O5PUWO.js";
9
+ import "./chunk-GPMFD4RD.js";
10
+ import "./chunk-H3WDBYJW.js";
11
+ import "./chunk-324YPTC2.js";
12
+ import "./chunk-LUSPKZKY.js";
13
+ import "./chunk-BUSC6UAE.js";
14
+ export {
15
+ esbOperationDefinitions,
16
+ getEsbOperation,
17
+ hasEsbOperation
18
+ };
@@ -0,0 +1,16 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ getHrmOperation,
5
+ hasHrmOperation,
6
+ hrmOperationDefinitions
7
+ } from "./chunk-G2JSIUWF.js";
8
+ import "./chunk-NOODWMCL.js";
9
+ import "./chunk-OOUTBLZ4.js";
10
+ import "./chunk-LUSPKZKY.js";
11
+ import "./chunk-BUSC6UAE.js";
12
+ export {
13
+ getHrmOperation,
14
+ hasHrmOperation,
15
+ hrmOperationDefinitions
16
+ };
@@ -0,0 +1,19 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ getWorkflowOperation,
5
+ hasWorkflowOperation,
6
+ workflowOperationDefinitions
7
+ } from "./chunk-2DUV44UX.js";
8
+ import "./chunk-EZALDOQH.js";
9
+ import "./chunk-FMPJJYYI.js";
10
+ import "./chunk-EG6ZU444.js";
11
+ import "./chunk-AJ62BGAW.js";
12
+ import "./chunk-324YPTC2.js";
13
+ import "./chunk-LUSPKZKY.js";
14
+ import "./chunk-BUSC6UAE.js";
15
+ export {
16
+ getWorkflowOperation,
17
+ hasWorkflowOperation,
18
+ workflowOperationDefinitions
19
+ };
@@ -0,0 +1,19 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ getMeetingOperation,
5
+ hasMeetingOperation,
6
+ meetingOperationDefinitions
7
+ } from "./chunk-RCGYCOMG.js";
8
+ import "./chunk-VZTXRG6X.js";
9
+ import "./chunk-AC7KJWC5.js";
10
+ import "./chunk-CVZ2JOSW.js";
11
+ import "./chunk-GCG2NMWR.js";
12
+ import "./chunk-H6XSTSLM.js";
13
+ import "./chunk-LUSPKZKY.js";
14
+ import "./chunk-BUSC6UAE.js";
15
+ export {
16
+ getMeetingOperation,
17
+ hasMeetingOperation,
18
+ meetingOperationDefinitions
19
+ };
@@ -0,0 +1,20 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ ebRoomRecommendOperation,
5
+ loadFrequentRooms,
6
+ loadRooms,
7
+ recommendRooms,
8
+ rememberFrequentRoom
9
+ } from "./chunk-AC7KJWC5.js";
10
+ import "./chunk-CVZ2JOSW.js";
11
+ import "./chunk-H6XSTSLM.js";
12
+ import "./chunk-LUSPKZKY.js";
13
+ import "./chunk-BUSC6UAE.js";
14
+ export {
15
+ ebRoomRecommendOperation,
16
+ loadFrequentRooms,
17
+ loadRooms,
18
+ recommendRooms,
19
+ rememberFrequentRoom
20
+ };
@@ -0,0 +1,24 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ applyMessageDetails,
5
+ buildScheduleFreeResult,
6
+ meetingEbScheduleOperations,
7
+ parseScheduleConflictMessage,
8
+ resolveMeetingScheduleTypeIds,
9
+ resolveMemberIdsByName,
10
+ runScheduleConflictFlow
11
+ } from "./chunk-VZTXRG6X.js";
12
+ import "./chunk-CVZ2JOSW.js";
13
+ import "./chunk-H6XSTSLM.js";
14
+ import "./chunk-LUSPKZKY.js";
15
+ import "./chunk-BUSC6UAE.js";
16
+ export {
17
+ applyMessageDetails,
18
+ buildScheduleFreeResult,
19
+ meetingEbScheduleOperations,
20
+ parseScheduleConflictMessage,
21
+ resolveMeetingScheduleTypeIds,
22
+ resolveMemberIdsByName,
23
+ runScheduleConflictFlow
24
+ };
@@ -0,0 +1,15 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ refsDir,
5
+ refsIndexPath,
6
+ stateDir,
7
+ stateRoot
8
+ } from "./chunk-AJ62BGAW.js";
9
+ import "./chunk-BUSC6UAE.js";
10
+ export {
11
+ refsDir,
12
+ refsIndexPath,
13
+ stateDir,
14
+ stateRoot
15
+ };
@@ -0,0 +1,245 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ createWorkflowHost
5
+ } from "./chunk-65QMVWHS.js";
6
+ import {
7
+ asObject,
8
+ assertNoForbiddenKeys,
9
+ compactStdoutPaths,
10
+ getWorkflowOperation,
11
+ workflowOperationDefinitions,
12
+ workflowSuccess
13
+ } from "./chunk-2DUV44UX.js";
14
+ import {
15
+ createWorkflowContinuationSigner
16
+ } from "./chunk-EZALDOQH.js";
17
+ import {
18
+ CLARIFICATION_SUBTYPE,
19
+ WorkflowCliError,
20
+ workflowValidationError
21
+ } from "./chunk-FMPJJYYI.js";
22
+ import "./chunk-EG6ZU444.js";
23
+ import "./chunk-AJ62BGAW.js";
24
+ import "./chunk-H3WDBYJW.js";
25
+ import "./chunk-324YPTC2.js";
26
+ import {
27
+ isCliError,
28
+ toErrorEnvelope
29
+ } from "./chunk-LUSPKZKY.js";
30
+ import "./chunk-BUSC6UAE.js";
31
+
32
+ // src/shortcuts/workflow/index.ts
33
+ import { readFile } from "node:fs/promises";
34
+
35
+ // src/shortcuts/workflow/manifest.ts
36
+ var WITHHELD = [];
37
+ function buildOperations() {
38
+ return workflowOperationDefinitions().map((definition) => ({
39
+ name: definition.name,
40
+ resource: definition.resource,
41
+ summary: definition.summary,
42
+ ...definition.capability ? { capability: definition.capability } : {},
43
+ risk: definition.risk,
44
+ ...definition.requiresConfirmation ? { requiresConfirmation: true } : {},
45
+ inputSchema: definition.inputSchema
46
+ }));
47
+ }
48
+ var workflowManifest = {
49
+ schemaVersion: 1,
50
+ name: "workflow",
51
+ title: "\u6CDB\u5FAEE10\u6D41\u7A0B\u667A\u80FD\u52A9\u624B\uFF08\u67E5\u8BE2/\u67E5\u770B/\u64CD\u4F5C/\u6279\u91CF/\u53D1\u8D77/\u4FEE\u6539\uFF09",
52
+ version: "0.1.0",
53
+ host: "e10-workflow",
54
+ status: "builtin",
55
+ sourceSkill: "weaver-e10-workflow",
56
+ capabilities: ["workflow"],
57
+ operations: buildOperations(),
58
+ withheldOperations: WITHHELD
59
+ };
60
+
61
+ // src/shortcuts/workflow/operations.ts
62
+ function idempotentReplayEnvelope(error, operation) {
63
+ if (!(error instanceof WorkflowCliError) || error.subtype !== "continuation_already_applied") return null;
64
+ const details = error.details ?? {};
65
+ const finishedAt = Number(details.finishedAt);
66
+ const onlyCommitted = details.stage === "committed" && details.result == null;
67
+ const previous = typeof details.operation === "string" && details.operation ? details.operation : operation;
68
+ const hasPrepare = /Apply$/u.test(previous);
69
+ const retryHint = hasPrepare ? "\u4E0D\u8981\u91CD\u8DD1 Prepare\uFF0C\u4E5F\u4E0D\u8981\u518D\u6B21\u63D0\u4EA4" : "\u4E0D\u8981\u91CD\u590D\u63D0\u4EA4\u540C\u4E00\u6279 requestId";
70
+ return workflowSuccess(operation, {
71
+ status: "ALREADY_APPLIED",
72
+ operation: previous,
73
+ requestId: typeof details.requestId === "string" && details.requestId ? details.requestId : null,
74
+ confirmedAt: Number.isFinite(finishedAt) ? new Date(finishedAt).toISOString() : null,
75
+ previousResult: details.result ?? null,
76
+ note: onlyCommitted ? `\u8BE5 continuation \u5BF9\u5E94\u7684\u4E0A\u4E00\u6B21\u6267\u884C\u5DF2\u7ECF\u5199\u5165\u6210\u529F\uFF08\u670D\u52A1\u7AEF\u5DF2\u8FD4\u56DE\u6210\u529F\u56DE\u6267\uFF0C\u53EA\u662F\u6CA1\u6765\u5F97\u53CA\u5199\u56DE\u672C\u5730\u7ED3\u679C\uFF09\uFF0C\u672C\u6B21\u672A\u91CD\u590D\u6267\u884C\u2014\u2014${retryHint}\uFF1B\u76EE\u6807\u6D41\u7A0B\u6309\u4E0A\u9762\u7684 requestId \u67E5\u5373\u53EF\u3002` : `\u8BE5 continuation \u5DF2\u7ECF\u6267\u884C\u8FC7\u4E14\u5DF2\u6210\u529F\uFF0C\u672C\u6B21\u672A\u91CD\u590D\u5199\u5165\uFF08\u5E42\u7B49\u56DE\u62A5\uFF09\u2014\u2014${retryHint}\u3002`
77
+ });
78
+ }
79
+ function clarificationEnvelope(error, operation) {
80
+ if (!(error instanceof WorkflowCliError) || error.subtype !== CLARIFICATION_SUBTYPE) return null;
81
+ const details = error.details ?? {};
82
+ const candidates = Array.isArray(details.candidates) ? details.candidates : [];
83
+ const question = typeof details.clarificationQuestion === "string" && details.clarificationQuestion ? details.clarificationQuestion : error.message;
84
+ const reason = typeof details.clarificationReason === "string" ? details.clarificationReason : "";
85
+ return workflowSuccess(operation, {
86
+ type: "workflowClarification",
87
+ status: "NEEDS_CLARIFICATION",
88
+ clarificationType: details.clarificationType ?? null,
89
+ clarificationKeyword: details.clarificationKeyword ?? null,
90
+ clarificationQuestion: question,
91
+ ...reason ? { clarificationReason: reason } : {},
92
+ candidates,
93
+ candidateCount: candidates.length,
94
+ note: clarificationNote(reason, candidates.length)
95
+ });
96
+ }
97
+ function clarificationNote(reason, candidateCount) {
98
+ const base = "\u8FD9\u4E0D\u662F\u5931\u8D25\uFF0C\u4E5F**\u4E0D\u4EE3\u8868\u67E5\u8BE2\u5DF2\u6267\u884C**\uFF1A\u672C\u6B21\u67E5\u8BE2\u5DF2\u505C\u6B62\uFF0C\u6CA1\u6709\u8FD4\u56DE\u4EFB\u4F55\u6D41\u7A0B\u6570\u636E\u3002";
99
+ if (reason === "workflow_not_exist") {
100
+ return base + '\u8BF7\u5982\u5B9E\u544A\u77E5\u7528\u6237\uFF1A\u8BE5\u5DE5\u4F5C\u6D41\u4E0D\u5B58\u5728\uFF08\u53EF\u80FD\u5DF2\u5220\u9664\u6216\u88AB\u505C\u7528\uFF09\uFF0C\u8BF7\u7528\u6237\u6539\u7528\u8BE5\u6D41\u7A0B\u7684\u5B8C\u6574\u540D\u79F0\uFF08\u6216\u5176\u5B83\u53EF\u7528\u4E8E\u68C0\u7D22\u7684\u5173\u952E\u8BCD\uFF09\u91CD\u65B0\u6307\u5B9A\u2014\u2014**\u4E0D\u8981\u5411\u7528\u6237\u7D22\u53D6 ID**\u3002**\u4E0D\u8981**\u8BF4\u6210"\u6CA1\u6709\u53EF\u53D1\u8D77\u7684\u5DE5\u4F5C\u6D41"\u8FD9\u7C7B\u6A21\u7CCA\u8BF4\u6CD5\u2014\u2014\u95EE\u9898\u5C31\u51FA\u5728\u8FD9\u4E2A\u76EE\u6807\u4E0A\u3002';
101
+ }
102
+ if (reason === "no_create_right") {
103
+ return base + '\u8BF7\u5982\u5B9E\u544A\u77E5\u7528\u6237\uFF1A\u8BE5\u6D41\u7A0B**\u5B58\u5728**\uFF0C\u4F46\u5F53\u524D\u8D26\u53F7**\u6CA1\u6709\u53D1\u8D77\u6743\u9650**\u3002**\u5FC5\u987B\u660E\u786E\u8BF4\u51FA\u300C\u5B58\u5728\u4F46\u6CA1\u6709\u53D1\u8D77\u6743\u9650\u300D**\uFF0C\u7EDD\u4E0D\u80FD\u8F6C\u8FF0\u6210"\u6D41\u7A0B\u4E0D\u5B58\u5728"\uFF1B\u5E76\u7ED9\u51FA\u4E0B\u4E00\u6B65\uFF1A\u6539\u7528\u5176\u4ED6\u53EF\u53D1\u8D77\u7684\u6D41\u7A0B\uFF0C\u6216\u8054\u7CFB\u7BA1\u7406\u5458\u4E3A\u8BE5\u6D41\u7A0B\u6388\u4E88\u53D1\u8D77\u6743\u9650\u3002';
104
+ }
105
+ return base + "\u8BF7\u628A\u6F84\u6E05\u95EE\u9898\u4E0E\u5019\u9009**\u539F\u6837**\u4EA4\u7ED9\u7528\u6237\u786E\u8BA4\uFF08\u9010\u6761\u5217\u51FA\u5019\u9009\u540D\u79F0\uFF09\uFF0C\u62FF\u5230\u786E\u8BA4\u540E\u7531\u4F60\u6309\u300C\u540D\u79F0(ID)\u300D\u628A ID \u62FC\u597D\u3001\u91CD\u53D1\u540C\u4E00\u6761\u547D\u4EE4\u2014\u2014**\u53EA\u95EE\u7528\u6237\u8BE5\u5BF9\u8C61\u7684\u5B8C\u6574\u540D\u79F0\u6216\u5176\u5B83\u53EF\u7528\u4E8E\u68C0\u7D22\u7684\u5173\u952E\u8BCD\uFF0C\u4E0D\u8981\u5411\u7528\u6237\u7D22\u53D6 ID**\u3002**\u4E0D\u8981**\u628A\u672C\u6B21\u7ED3\u679C\u8F6C\u8FF0\u6210\u300C\u6CA1\u6709\u5339\u914D\u7684\u6D41\u7A0B\u300D\u300C\u67E5\u8BE2\u7ED3\u679C\u4E3A 0 \u6761\u300D\u6216\u81EA\u884C\u6311\u4E00\u4E2A\u5019\u9009\u7EE7\u7EED\u67E5\u3002" + (candidateCount === 0 ? "\u5F53\u524D\u6CA1\u6709\u4EFB\u4F55\u5019\u9009\u2014\u2014\u8BF7\u8BA9\u7528\u6237\u7ED9\u51FA\u8BE5\u5BF9\u8C61\u7684\u5B8C\u6574\u540D\u79F0\uFF08\u6216\u7EA0\u6B63\u540D\u79F0\u91CC\u7684\u9519\u522B\u5B57\u3001\u6362\u5176\u5B83\u53EF\u7528\u4E8E\u68C0\u7D22\u7684\u5173\u952E\u8BCD\uFF09\u540E\u91CD\u53D1\u3002" : "");
106
+ }
107
+ async function settleAppliedContinuation(input, result, context, definition) {
108
+ if (definition.risk !== "high-risk-write") return;
109
+ const raw = typeof input.continuation === "string" ? input.continuation : typeof input.context === "string" ? input.context : "";
110
+ const reference = raw.trim();
111
+ if (!reference) return;
112
+ await context.continuation.settle(reference, result.data, definition.action || definition.name);
113
+ }
114
+ async function executeWorkflowOperation(operation, rawInput, context) {
115
+ const definition = getWorkflowOperation(operation);
116
+ const input = asObject(rawInput);
117
+ assertNoForbiddenKeys(input);
118
+ let result;
119
+ try {
120
+ result = await definition.handler(input, context);
121
+ } catch (error) {
122
+ const clarified = clarificationEnvelope(error, operation);
123
+ if (clarified) return clarified;
124
+ const replayed = idempotentReplayEnvelope(error, operation);
125
+ if (replayed) return replayed;
126
+ throw error;
127
+ }
128
+ await settleAppliedContinuation(input, result, context, definition);
129
+ return result;
130
+ }
131
+
132
+ // src/shortcuts/workflow/index.ts
133
+ function asOptions(value) {
134
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
135
+ }
136
+ async function readStdin() {
137
+ const chunks = [];
138
+ for await (const chunk of process.stdin) {
139
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
140
+ }
141
+ return Buffer.concat(chunks).toString("utf8");
142
+ }
143
+ function stripBom(value) {
144
+ return value.replace(/^\uFEFF+/u, "");
145
+ }
146
+ async function inputFrom(options, extra = {}) {
147
+ const opts = asOptions(options);
148
+ if (opts.input && opts.inputJson) {
149
+ throw workflowValidationError("input_conflict", "\u4E0D\u80FD\u540C\u65F6\u4F20 --input \u548C --input-json");
150
+ }
151
+ let input = {};
152
+ if (opts.inputJson) {
153
+ input = parseJsonInput(String(opts.inputJson), "--input-json");
154
+ }
155
+ if (opts.input) {
156
+ let raw;
157
+ try {
158
+ raw = stripBom(opts.input === "-" ? await readStdin() : await readFile(String(opts.input), "utf8"));
159
+ } catch {
160
+ throw workflowValidationError("input_unreadable", `\u65E0\u6CD5\u8BFB\u53D6 --input\uFF1A${String(opts.input)}`);
161
+ }
162
+ input = parseJsonInput(raw, "--input");
163
+ }
164
+ return {
165
+ ...input,
166
+ ...Object.fromEntries(Object.entries(extra).filter(([, value]) => value !== void 0 && value !== ""))
167
+ };
168
+ }
169
+ function parseJsonInput(raw, label) {
170
+ try {
171
+ const parsed = JSON.parse(stripBom(raw));
172
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
173
+ throw new Error("input must be an object");
174
+ }
175
+ return parsed;
176
+ } catch {
177
+ throw workflowValidationError("input_invalid", `${label} \u4E0D\u662F\u5408\u6CD5 JSON \u5BF9\u8C61`);
178
+ }
179
+ }
180
+ function successEnvelope(operation, result) {
181
+ return {
182
+ schemaVersion: 1,
183
+ ok: true,
184
+ operation,
185
+ data: result.data === void 0 ? null : result.data,
186
+ ...result.meta ? { meta: result.meta } : {},
187
+ warnings: []
188
+ };
189
+ }
190
+ function failureEnvelope(error) {
191
+ const structured = error;
192
+ return {
193
+ schemaVersion: 1,
194
+ ok: false,
195
+ ...structured?.partialData === void 0 ? {} : { data: structured.partialData },
196
+ error: toErrorEnvelope(error)
197
+ };
198
+ }
199
+ function printWorkflowResult(ctx, operation, result) {
200
+ ctx.output.write(successEnvelope(operation, result), {
201
+ json: true,
202
+ compactPaths: compactStdoutPaths(operation),
203
+ // todoSmartConvert 的业务契约要求直接返回完整 requestDatas/displayItems;
204
+ // 禁止公共输出层按 24KB 预算递归折叠该分支(2026-10-27 用户要求,勿删)。
205
+ persist: operation !== "workflow.todoSmartConvert"
206
+ });
207
+ }
208
+ async function executeAndPrint(ctx, operation, input) {
209
+ try {
210
+ const result = await executeWorkflowOperation(operation, input, {
211
+ ctx,
212
+ host: createWorkflowHost(ctx),
213
+ continuation: createWorkflowContinuationSigner(ctx)
214
+ });
215
+ printWorkflowResult(ctx, operation, result);
216
+ } catch (error) {
217
+ console.error(JSON.stringify(failureEnvelope(error), null, 2));
218
+ process.exitCode = isCliError(error) ? error.exitCode : 1 /* GeneralError */;
219
+ }
220
+ }
221
+ function withJsonInputOptions(command) {
222
+ command.option("--input <path>", "JSON input file, or - for stdin").option("--input-json <json>", "inline JSON input object");
223
+ return command;
224
+ }
225
+ var workflowShortcut = {
226
+ name: "workflow",
227
+ description: "\u6CDB\u5FAEE10\u6D41\u7A0B\u667A\u80FD\u52A9\u624B CLI\uFF08\u67E5\u8BE2/\u67E5\u770B/\u64CD\u4F5C/\u6279\u91CF/\u53D1\u8D77/\u4FEE\u6539\uFF09",
228
+ category: "shortcut",
229
+ register({ program, action }) {
230
+ const workflow = program.command("workflow").description("\u6CDB\u5FAEE10\u6D41\u7A0B\u667A\u80FD\u52A9\u624B\uFF08\u5F85\u529E/\u5DF2\u529E/\u6211\u53D1\u8D77/\u5168\u90E8\u3001\u8BE6\u60C5\u3001\u64CD\u4F5C\u3001\u6279\u91CF\u3001\u53D1\u8D77\u3001\u4FEE\u6539\uFF09");
231
+ workflow.command("schema").description("Print workflow operation manifest for agents").action(action((ctx) => {
232
+ ctx.output.write(workflowManifest, { json: true });
233
+ }));
234
+ withJsonInputOptions(workflow.command("run").description("Run a workflow operation with JSON input").argument("<operation>", "operation name, e.g. workflow.search")).action(action(async (ctx, operation, options) => {
235
+ await executeAndPrint(ctx, String(operation), await inputFrom(options));
236
+ }));
237
+ }
238
+ };
239
+ export {
240
+ compactStdoutPaths,
241
+ inputFrom,
242
+ printWorkflowResult,
243
+ successEnvelope,
244
+ workflowShortcut
245
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 会吃掉下一个 token 作为值的**全局**选项(与 `cmd/root.ts` 里 `program.option(...)` 一一对应)。
3
+ *
4
+ * `--is-connector [value]` 故意不算在内:它的值是可选的,宁可把后面的 token 当成命令名
5
+ * (多加载一个 shortcut 只是慢一点),也不要把它自己的值误当成命令名(那会少加载)。
6
+ */
7
+ export const VALUE_TAKING_GLOBAL_OPTIONS = new Set([
8
+ '--config',
9
+ '--auth',
10
+ '--profile',
11
+ '--runtime-agent',
12
+ '--base-url',
13
+ '--passport-url',
14
+ ]);
15
+ /**
16
+ * 取 argv 里**第一个位置参数**(= 最可能的顶层命令名),跳过所有 `-` 开头的选项。
17
+ *
18
+ * 注意:这个函数**只用于决定"要加载哪个 shortcut 实现"**,不参与真正的参数解析
19
+ * (真正的解析仍然全权交给 commander)。所以猜错的后果只有"多加载/少加载",
20
+ * 少加载那一种由 `lazy-dispatch.ts` 的重放兜住。
21
+ */
22
+ export function firstPositionalToken(argv) {
23
+ for (let index = 0; index < argv.length; index += 1) {
24
+ const token = argv[index];
25
+ if (token === undefined)
26
+ return undefined;
27
+ if (token === '--')
28
+ return argv[index + 1];
29
+ if (token.startsWith('-')) {
30
+ if (VALUE_TAKING_GLOBAL_OPTIONS.has(token))
31
+ index += 1;
32
+ continue;
33
+ }
34
+ return token;
35
+ }
36
+ return undefined;
37
+ }
38
+ /** 命令对象 → `ctx.commands` 里的元数据(`commands list` 就靠它)。 */
39
+ export function toCommandMetadata(commands) {
40
+ return commands.map((command) => ({
41
+ name: command.name,
42
+ description: command.description,
43
+ category: command.category,
44
+ }));
45
+ }
@@ -1,9 +1,9 @@
1
1
  import { cpSync, existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
3
  import { CliError } from '../../core/errors.js';
5
- const DOCS_DIR = fileURLToPath(new URL('../../../docs/', import.meta.url));
6
- const PKG_JSON_URL = new URL('../../../package.json', import.meta.url);
4
+ import { packageFileUrl, packagePath } from '../../core/package-paths.js';
5
+ const DOCS_DIR = packagePath('docs');
6
+ const PKG_JSON_URL = packageFileUrl('package.json');
7
7
  function packageVersion() {
8
8
  try {
9
9
  return JSON.parse(readFileSync(PKG_JSON_URL, 'utf-8')).version;
@@ -0,0 +1,20 @@
1
+ import { builtinCommands } from './index.js';
2
+ import { registerCommands } from './register.js';
3
+ import { createProgram } from './root.js';
4
+ import { toCommandMetadata } from './argv.js';
5
+ /**
6
+ * 懒加载兜底:把 argv 原样交给**一套新建的 program**,并把真实命令树注册上去重放一次。
7
+ *
8
+ * 只在一种情况下会走到这里:`src/index.ts` 的 argv 预判没猜中要跑哪个 shortcut
9
+ * (宿主用了我们没见过的参数形式),于是记录表里注册的**占位命令**接住了这条命令。
10
+ * 重放保证行为与「全量静态注册」时完全一致,代价是这一次多走一遍 commander。
11
+ */
12
+ export async function dispatchLazyShortcut(definition, metadata, argv = process.argv) {
13
+ const { program, ctx } = createProgram();
14
+ const command = await definition.load();
15
+ await registerCommands(program, ctx, [...builtinCommands, command]);
16
+ // `commands list` 要看到的是**全部**命令,而不是本次真实注册的那几个 —— 元数据是静态的,直接补齐。
17
+ ctx.commands = toCommandMetadata([...builtinCommands, ...metadata]);
18
+ ctx.modules = ctx.commands;
19
+ await program.parseAsync(argv);
20
+ }
package/dist/cmd/root.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
2
  import { Command } from 'commander';
5
3
  import { createCliContext } from '../core/context.js';
6
4
  import { HookManager } from '../core/hooks.js';
5
+ import { packagePath } from '../core/package-paths.js';
7
6
  const CLI_COMMAND_NAME = 'weaver-work-cli';
8
7
  function readPackageInfo() {
9
- const __dirname = dirname(fileURLToPath(import.meta.url));
10
- const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf-8'));
8
+ const pkg = JSON.parse(readFileSync(packagePath('package.json'), 'utf-8'));
11
9
  return {
12
10
  name: pkg.name || CLI_COMMAND_NAME,
13
11
  version: pkg.version || '0.0.0',
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { fileURLToPath } from 'node:url';
3
2
  import { CliError, ExitCode } from '../../core/errors.js';
3
+ import { packagePath } from '../../core/package-paths.js';
4
4
  import { findAuthFile } from '../../internal/e10/auth/session.js';
5
5
  import { installPackagedSkills, resolvePackagedSkillNames, resolveSkillsRoot, resolveSkillsTargetPath, unresolvedSkillsRootMessage, } from '../../internal/skills/install.js';
6
- const SKILLS_DIR = fileURLToPath(new URL('../../../skills/', import.meta.url));
6
+ const SKILLS_DIR = packagePath('skills');
7
7
  function versionMajor(version) {
8
8
  return Number(version.replace(/^v/, '').split('.')[0] || 0);
9
9
  }
@@ -1,11 +1,11 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { spawnSync } from 'node:child_process';
3
- import { fileURLToPath } from 'node:url';
4
3
  import { CliError, ExitCode } from '../../core/errors.js';
4
+ import { packagePath } from '../../core/package-paths.js';
5
5
  import { resolveDetectorInfo } from '../../internal/skills/detector.js';
6
6
  import { installPackagedSkills, resolveSkillsRoot, resolveSkillsTargetPath, unresolvedSkillsRootMessage, } from '../../internal/skills/install.js';
7
7
  import { SkillReader } from '../../internal/skills/reader.js';
8
- const SKILLS_DIR = fileURLToPath(new URL('../../../skills/', import.meta.url));
8
+ const SKILLS_DIR = packagePath('skills');
9
9
  function reader() {
10
10
  if (!existsSync(SKILLS_DIR)) {
11
11
  throw new CliError('skills directory does not exist: ' + SKILLS_DIR);
@@ -0,0 +1,47 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ /**
5
+ * 包根目录(含 package.json 的那一层)。
6
+ *
7
+ * 为什么不用 `new URL('../../..', import.meta.url)`:那条路径把「源码在 dist 下的相对深度」
8
+ * 写死了。2026-10-28 引入打包产物(B 方案,esbuild 打出 dist/index.js + 若干 chunk)之后,
9
+ * 同一个模块可能来自 `dist/cmd/docs/index.js`(深层),也可能被内联进 `dist/index.js`(浅层),
10
+ * 相对深度不再成立。改成从**入口脚本**往上找第一个 package.json,两种布局都对。
11
+ *
12
+ * 注意取 `process.argv[1]` 优先:它是"用户实际执行的那个文件",比 import.meta.url 更接近真相;
13
+ * 找不到时(`node -e`、被当成库 import)再退回本模块所在目录,最后兜底 cwd。
14
+ */
15
+ let cachedRoot;
16
+ export function packageRootDir() {
17
+ if (cachedRoot)
18
+ return cachedRoot;
19
+ const seeds = [];
20
+ const entry = process.argv[1];
21
+ if (entry)
22
+ seeds.push(dirname(resolve(entry)));
23
+ seeds.push(dirname(fileURLToPath(import.meta.url)));
24
+ for (const seed of seeds) {
25
+ let dir = seed;
26
+ for (let depth = 0; depth < 10; depth += 1) {
27
+ if (existsSync(join(dir, 'package.json'))) {
28
+ cachedRoot = dir;
29
+ return dir;
30
+ }
31
+ const parent = dirname(dir);
32
+ if (parent === dir)
33
+ break;
34
+ dir = parent;
35
+ }
36
+ }
37
+ cachedRoot = process.cwd();
38
+ return cachedRoot;
39
+ }
40
+ /** 包内相对路径 → 绝对路径。 */
41
+ export function packagePath(...segments) {
42
+ return join(packageRootDir(), ...segments);
43
+ }
44
+ /** 包内相对路径 → file:// URL(给 `readFileSync` 这类接受 URL 的 API 用)。 */
45
+ export function packageFileUrl(...segments) {
46
+ return pathToFileURL(packagePath(...segments));
47
+ }