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,654 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ refsDir,
5
+ refsIndexPath
6
+ } from "./chunk-AJ62BGAW.js";
7
+ import {
8
+ CliError
9
+ } from "./chunk-LUSPKZKY.js";
10
+
11
+ // src/core/refs.ts
12
+ import { createHash, randomBytes } from "node:crypto";
13
+ import {
14
+ appendFileSync,
15
+ chmodSync,
16
+ existsSync,
17
+ lstatSync,
18
+ mkdirSync,
19
+ readFileSync,
20
+ readdirSync,
21
+ realpathSync,
22
+ statSync,
23
+ truncateSync,
24
+ writeFileSync
25
+ } from "node:fs";
26
+ import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
27
+ var REF_SCHEMA_VERSION = 1;
28
+ var RefError = class extends CliError {
29
+ type = "policy";
30
+ subtype;
31
+ retryable = false;
32
+ constructor(subtype, message, exitCode = 2 /* UsageError */) {
33
+ super(message, exitCode);
34
+ this.name = "RefError";
35
+ this.subtype = subtype;
36
+ }
37
+ };
38
+ function slug(value) {
39
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
40
+ }
41
+ function pad(value) {
42
+ return String(value).padStart(2, "0");
43
+ }
44
+ function refIdFor(operation, now = /* @__PURE__ */ new Date()) {
45
+ const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
46
+ const name = operation ? slug(operation) : "result";
47
+ return `${stamp}-${name || "result"}-${randomBytes(8).toString("hex")}`;
48
+ }
49
+ function dateDirOf(now) {
50
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
51
+ }
52
+ function sha256Of(value) {
53
+ return createHash("sha256").update(value, "utf8").digest("hex");
54
+ }
55
+ function ensureDir(dir) {
56
+ mkdirSync(dir, { recursive: true, mode: 448 });
57
+ if (process.platform !== "win32") {
58
+ chmodSync(dir, 448);
59
+ }
60
+ }
61
+ function ensurePrivateFile(file) {
62
+ if (process.platform !== "win32") {
63
+ chmodSync(file, 384);
64
+ }
65
+ }
66
+ function isInsideRefs(ctx, file) {
67
+ const root = resolve(refsDir(ctx));
68
+ const absolute = resolve(file);
69
+ const isChild = (parent, candidate) => {
70
+ const relativePath = relative(parent, candidate);
71
+ return relativePath !== "" && relativePath !== ".." && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath);
72
+ };
73
+ if (!isChild(root, absolute)) return false;
74
+ try {
75
+ return isChild(realpathSync(root), realpathSync(absolute));
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
80
+ function writeFileDirectSync(file, data) {
81
+ writeFileSync(file, data, { encoding: "utf8", mode: 384 });
82
+ ensurePrivateFile(file);
83
+ }
84
+ function dropRefFile(file) {
85
+ try {
86
+ truncateSync(file, 0);
87
+ return true;
88
+ } catch (error) {
89
+ return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
90
+ }
91
+ }
92
+ function readIndex(ctx) {
93
+ const path = refsIndexPath(ctx);
94
+ if (!existsSync(path)) return [];
95
+ const rows = [];
96
+ for (const line of readFileSync(path, "utf8").split("\n")) {
97
+ const trimmed = line.trim();
98
+ if (!trimmed) continue;
99
+ try {
100
+ const parsed = JSON.parse(trimmed);
101
+ if (parsed && typeof parsed.refId === "string" && typeof parsed.file === "string" && typeof parsed.bytes === "number" && Number.isFinite(parsed.bytes) && parsed.bytes >= 0 && typeof parsed.sha256 === "string" && /^[a-f0-9]{64}$/u.test(parsed.sha256) && isInsideRefs(ctx, parsed.file)) rows.push({ ...parsed, file: resolve(parsed.file) });
102
+ } catch {
103
+ }
104
+ }
105
+ return rows;
106
+ }
107
+ function writeIndex(ctx, rows) {
108
+ ensureDir(refsDir(ctx));
109
+ const data = rows.map((row) => JSON.stringify(row)).join("\n");
110
+ writeFileDirectSync(refsIndexPath(ctx), rows.length ? `${data}
111
+ ` : "");
112
+ }
113
+ function appendIndex(ctx, meta) {
114
+ ensureDir(refsDir(ctx));
115
+ try {
116
+ appendFileSync(refsIndexPath(ctx), `${JSON.stringify(meta)}
117
+ `, { encoding: "utf8", mode: 384 });
118
+ ensurePrivateFile(refsIndexPath(ctx));
119
+ } catch {
120
+ }
121
+ }
122
+ function scanFiles(ctx) {
123
+ const root = refsDir(ctx);
124
+ if (!existsSync(root)) return [];
125
+ const files = [];
126
+ for (const entry of readdirSync(root, { withFileTypes: true })) {
127
+ if (!entry.isDirectory()) continue;
128
+ const dir = join(root, entry.name);
129
+ for (const inner of readdirSync(dir, { withFileTypes: true })) {
130
+ if (inner.isFile() && inner.name.endsWith(".json")) files.push(join(dir, inner.name));
131
+ }
132
+ }
133
+ return files;
134
+ }
135
+ function metaFromFile(file) {
136
+ try {
137
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
138
+ if (!parsed || typeof parsed.refId !== "string") return null;
139
+ return {
140
+ refId: parsed.refId,
141
+ ...parsed.operation ? { operation: parsed.operation } : {},
142
+ file,
143
+ bytes: statSync(file).size,
144
+ sha256: sha256Of(JSON.stringify(parsed.envelope ?? null, null, 2)),
145
+ createdAt: parsed.createdAt,
146
+ expiresAt: parsed.expiresAt,
147
+ ttlMs: typeof parsed.ttlMs === "number" ? parsed.ttlMs : 0
148
+ };
149
+ } catch {
150
+ return null;
151
+ }
152
+ }
153
+ function findMeta(ctx, refId) {
154
+ const fromIndex = readIndex(ctx).find((row) => row.refId === refId);
155
+ if (fromIndex) return fromIndex;
156
+ for (const file of scanFiles(ctx)) {
157
+ if (basename(file, ".json") === refId) {
158
+ const meta = metaFromFile(file);
159
+ if (meta) return meta;
160
+ }
161
+ }
162
+ return null;
163
+ }
164
+ function defaultTtlMs() {
165
+ return 30 * 6e4;
166
+ }
167
+ function writeRef(ctx, options) {
168
+ const now = options.now ?? /* @__PURE__ */ new Date();
169
+ const ttlMs = options.ttlMs ?? defaultTtlMs();
170
+ const refId = refIdFor(options.operation, now);
171
+ const dir = join(refsDir(ctx), dateDirOf(now));
172
+ ensureDir(dir);
173
+ const file = join(dir, `${refId}.json`);
174
+ const payload = {
175
+ schemaVersion: REF_SCHEMA_VERSION,
176
+ refId,
177
+ ...options.operation ? { operation: options.operation } : {},
178
+ createdAt: now.toISOString(),
179
+ expiresAt: new Date(now.getTime() + ttlMs).toISOString(),
180
+ ttlMs,
181
+ envelope: options.value ?? null
182
+ };
183
+ const fileContents = JSON.stringify(payload, null, 2);
184
+ writeFileDirectSync(file, fileContents);
185
+ const meta = {
186
+ refId,
187
+ ...options.operation ? { operation: options.operation } : {},
188
+ file,
189
+ bytes: Buffer.byteLength(fileContents, "utf8"),
190
+ sha256: sha256Of(JSON.stringify(options.value ?? null, null, 2)),
191
+ createdAt: payload.createdAt,
192
+ expiresAt: payload.expiresAt,
193
+ ttlMs
194
+ };
195
+ appendIndex(ctx, meta);
196
+ return meta;
197
+ }
198
+ function readRef(ctx, refId) {
199
+ const meta = findMeta(ctx, refId);
200
+ if (!meta || !isInsideRefs(ctx, meta.file) || !existsSync(meta.file)) {
201
+ throw new RefError("ref_missing", `\u672A\u627E\u5230\u7ED3\u679C\u5F15\u7528\uFF1A${refId}`);
202
+ }
203
+ try {
204
+ if (!lstatSync(meta.file).isFile()) {
205
+ throw new RefError("ref_corrupt", `\u7ED3\u679C\u5F15\u7528\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${refId}`, 6 /* PolicyError */);
206
+ }
207
+ } catch (error) {
208
+ if (error instanceof RefError) throw error;
209
+ throw new RefError("ref_missing", `\u672A\u627E\u5230\u7ED3\u679C\u5F15\u7528\uFF1A${refId}`);
210
+ }
211
+ let parsed;
212
+ try {
213
+ parsed = JSON.parse(readFileSync(meta.file, "utf8"));
214
+ } catch {
215
+ throw new RefError("ref_corrupt", `\u7ED3\u679C\u5F15\u7528\u6587\u4EF6\u635F\u574F\uFF1A${refId}`, 6 /* PolicyError */);
216
+ }
217
+ if (parsed.schemaVersion !== REF_SCHEMA_VERSION || parsed.refId !== refId || typeof parsed.createdAt !== "string" || typeof parsed.expiresAt !== "string" || !Number.isFinite(Date.parse(parsed.createdAt)) || !Number.isFinite(Date.parse(parsed.expiresAt)) || parsed.createdAt !== meta.createdAt || parsed.expiresAt !== meta.expiresAt || parsed.ttlMs !== meta.ttlMs) {
218
+ throw new RefError("ref_corrupt", `\u7ED3\u679C\u5F15\u7528\u5143\u6570\u636E\u4E0D\u5339\u914D\uFF1A${refId}`, 6 /* PolicyError */);
219
+ }
220
+ const expiresAt = Date.parse(parsed.expiresAt);
221
+ if (expiresAt < Date.now()) {
222
+ dropRefFile(meta.file);
223
+ writeIndex(ctx, readIndex(ctx).filter((row) => row.refId !== refId));
224
+ throw new RefError("ref_expired", `\u7ED3\u679C\u5F15\u7528\u5DF2\u8FC7\u671F\uFF1A${refId}`, 6 /* PolicyError */);
225
+ }
226
+ const serialized = JSON.stringify(parsed.envelope ?? null, null, 2);
227
+ if (sha256Of(serialized) !== meta.sha256) {
228
+ throw new RefError("ref_corrupt", `\u7ED3\u679C\u5F15\u7528\u6821\u9A8C\u5931\u8D25\uFF1A${refId}`, 6 /* PolicyError */);
229
+ }
230
+ return { meta, envelope: parsed.envelope };
231
+ }
232
+ function listRefs(ctx) {
233
+ const seen = /* @__PURE__ */ new Set();
234
+ const rows = [];
235
+ for (const row of readIndex(ctx)) {
236
+ if (seen.has(row.refId) || !existsSync(row.file)) continue;
237
+ seen.add(row.refId);
238
+ rows.push(row);
239
+ }
240
+ for (const file of scanFiles(ctx)) {
241
+ const id = basename(file, ".json");
242
+ if (seen.has(id)) continue;
243
+ const meta = metaFromFile(file);
244
+ if (meta) {
245
+ seen.add(id);
246
+ rows.push(meta);
247
+ }
248
+ }
249
+ return rows.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
250
+ }
251
+ function pruneRefs(ctx, options = {}) {
252
+ const maxCount = options.maxCount ?? 50;
253
+ const maxBytes = options.maxBytes ?? 200 * 1024 * 1024;
254
+ const preserved = new Set(options.preserveRefIds ?? []);
255
+ const rows = listRefs(ctx);
256
+ const now = Date.now();
257
+ const expired = [];
258
+ const alive = [];
259
+ const ageCutoff = options.olderThanMs === void 0 ? void 0 : now - options.olderThanMs;
260
+ for (const row of rows) {
261
+ const at = Date.parse(row.expiresAt);
262
+ const created = Date.parse(row.createdAt);
263
+ const tooOld = ageCutoff !== void 0 && Number.isFinite(created) && created <= ageCutoff;
264
+ if ((Number.isFinite(at) && at < now || tooOld) && !preserved.has(row.refId)) expired.push(row);
265
+ else alive.push(row);
266
+ }
267
+ const byAge = [...alive].sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
268
+ const victims = new Set(expired.map((row) => row.refId));
269
+ const protectedRows = byAge.filter((row) => preserved.has(row.refId));
270
+ const candidates = byAge.filter((row) => !preserved.has(row.refId));
271
+ const allowedCandidates = Math.max(0, Math.floor(maxCount) - protectedRows.length);
272
+ if (candidates.length > allowedCandidates) {
273
+ for (const row of candidates.slice(0, candidates.length - allowedCandidates)) victims.add(row.refId);
274
+ }
275
+ let total = byAge.filter((row) => !victims.has(row.refId)).reduce((sum, row) => sum + row.bytes, 0);
276
+ if (total > maxBytes) {
277
+ for (const row of candidates) {
278
+ if (total <= maxBytes) break;
279
+ if (victims.has(row.refId)) continue;
280
+ victims.add(row.refId);
281
+ total -= row.bytes;
282
+ }
283
+ }
284
+ let cleanupIncomplete = false;
285
+ for (const row of rows) {
286
+ if (!victims.has(row.refId)) continue;
287
+ if (!dropRefFile(row.file)) cleanupIncomplete = true;
288
+ }
289
+ const kept = rows.filter((row) => !victims.has(row.refId));
290
+ if (rows.length > 0 || existsSync(refsIndexPath(ctx))) writeIndex(ctx, kept);
291
+ const keptBytes = kept.reduce((sum, row) => sum + row.bytes, 0);
292
+ return {
293
+ removed: victims.size,
294
+ kept: kept.length,
295
+ bytes: keptBytes,
296
+ overLimit: cleanupIncomplete || kept.length > maxCount || keptBytes > maxBytes,
297
+ cleanupIncomplete
298
+ };
299
+ }
300
+ function pickValue(value, path) {
301
+ let cursor = value;
302
+ for (const token of tokenizePath(path)) {
303
+ if (cursor === null || cursor === void 0) {
304
+ throw new RefError("ref_pick_failed", `--pick \u8DEF\u5F84 ${path} \u5728 ${token} \u5904\u65E0\u6CD5\u7EE7\u7EED`);
305
+ }
306
+ if (typeof token === "number") {
307
+ if (!Array.isArray(cursor)) {
308
+ throw new RefError("ref_pick_failed", `--pick \u8DEF\u5F84 ${path} \u7684 ${token} \u4E0D\u662F\u6570\u7EC4\u4E0B\u6807\u53EF\u8BBF\u95EE\u7684\u503C`);
309
+ }
310
+ cursor = cursor[token];
311
+ continue;
312
+ }
313
+ if (typeof cursor !== "object") {
314
+ throw new RefError("ref_pick_failed", `--pick \u8DEF\u5F84 ${path} \u65E0\u6CD5\u4ECE\u975E\u5BF9\u8C61\u4E2D\u53D6\u5B57\u6BB5 ${token}`);
315
+ }
316
+ const holder = cursor;
317
+ if (!(token in holder)) {
318
+ throw new RefError("ref_pick_failed", `--pick \u8DEF\u5F84 ${path} \u4E2D\u4E0D\u5B58\u5728\u5B57\u6BB5 ${token}`);
319
+ }
320
+ cursor = holder[token];
321
+ }
322
+ return cursor;
323
+ }
324
+ function tokenizePath(path) {
325
+ let cursor = path.trim().replace(/^\$/, "").replace(/^data\./, "");
326
+ const tokens = [];
327
+ const pattern = /([^.[\]]+)|\[(\d+)\]/g;
328
+ let match;
329
+ while ((match = pattern.exec(cursor)) !== null) {
330
+ if (match[1] !== void 0) tokens.push(match[1]);
331
+ else tokens.push(Number(match[2]));
332
+ }
333
+ if (!tokens.length) {
334
+ throw new RefError("ref_pick_failed", `\u65E0\u6CD5\u89E3\u6790 --pick \u8DEF\u5F84\uFF1A${path}`);
335
+ }
336
+ return tokens;
337
+ }
338
+ function resolveRefInput(ctx, options) {
339
+ const { envelope } = readRef(ctx, options.refId);
340
+ const data = envelope && typeof envelope === "object" && !Array.isArray(envelope) && "data" in envelope ? envelope.data : envelope;
341
+ const target = options.pick ? pickValue(data, options.pick) : data;
342
+ if (target && typeof target === "object" && !Array.isArray(target)) {
343
+ if (options.pickAs) {
344
+ throw new RefError("ref_pick_as_object", "--pick-as \u53EA\u7528\u4E8E\u628A\u5355\u4E2A\u503C\u6620\u5C04\u5230\u8F93\u5165\u5B57\u6BB5\uFF1B\u5F53\u524D\u9009\u62E9\u7ED3\u679C\u5DF2\u7ECF\u662F\u5BF9\u8C61");
345
+ }
346
+ return target;
347
+ }
348
+ if (!options.pickAs || !/^[A-Za-z_][A-Za-z0-9_]*$/u.test(options.pickAs)) {
349
+ throw new RefError(
350
+ "ref_pick_scalar_requires_key",
351
+ "\u9009\u62E9\u7ED3\u679C\u662F\u5355\u4E2A\u503C\uFF1B\u8BF7\u52A0 --pick-as <\u8F93\u5165\u5B57\u6BB5\u540D>\uFF0C\u4F8B\u5982 --pick items[0].fid --pick-as fid"
352
+ );
353
+ }
354
+ return { [options.pickAs]: target ?? null };
355
+ }
356
+
357
+ // src/core/output.ts
358
+ var DEFAULT_RESULT_THRESHOLD_BYTES = 24 * 1024;
359
+ var DEFAULT_REF_TTL_MS = 30 * 6e4;
360
+ var DEFAULT_REF_MAX_COUNT = 50;
361
+ var DEFAULT_REF_MAX_BYTES = 200 * 1024 * 1024;
362
+ var COMPACT_TIERS = [
363
+ { array: 10, string: 200 },
364
+ { array: 5, string: 80 },
365
+ { array: 2, string: 40 },
366
+ { array: 1, string: 20 }
367
+ ];
368
+ function numberFromEnv(name) {
369
+ const raw = process.env[name];
370
+ if (raw === void 0 || raw.trim() === "") return void 0;
371
+ const parsed = Number(raw);
372
+ return Number.isFinite(parsed) ? parsed : void 0;
373
+ }
374
+ function configValue(ctx, key) {
375
+ const io = ctx.config.get("io");
376
+ if (io && typeof io === "object" && !Array.isArray(io)) {
377
+ const holder = io;
378
+ if (key in holder) return holder[key];
379
+ }
380
+ return ctx.config.get(key);
381
+ }
382
+ function numeric(ctx, envName, configKey, fallback) {
383
+ const fromEnv = numberFromEnv(envName);
384
+ if (fromEnv !== void 0) return fromEnv;
385
+ const fromConfig = configValue(ctx, configKey);
386
+ if (typeof fromConfig === "number" && Number.isFinite(fromConfig)) return fromConfig;
387
+ return fallback;
388
+ }
389
+ function resultThresholdBytes(ctx) {
390
+ const value = numeric(ctx, "WEAVER_WORK_CLI_REF_THRESHOLD", "resultThreshold", DEFAULT_RESULT_THRESHOLD_BYTES);
391
+ return value === 0 || value >= 2 * 1024 ? Math.floor(value) : DEFAULT_RESULT_THRESHOLD_BYTES;
392
+ }
393
+ function refTtlMs(ctx) {
394
+ const value = numeric(ctx, "WEAVER_WORK_CLI_REF_TTL_MS", "refTtlMs", DEFAULT_REF_TTL_MS);
395
+ return value >= 1 ? Math.floor(value) : DEFAULT_REF_TTL_MS;
396
+ }
397
+ function refMaxCount(ctx) {
398
+ const value = numeric(ctx, "WEAVER_WORK_CLI_REF_MAX_COUNT", "refMaxCount", DEFAULT_REF_MAX_COUNT);
399
+ return value >= 1 ? Math.floor(value) : DEFAULT_REF_MAX_COUNT;
400
+ }
401
+ function refMaxBytes(ctx) {
402
+ const value = numeric(ctx, "WEAVER_WORK_CLI_REF_MAX_BYTES", "refMaxBytes", DEFAULT_REF_MAX_BYTES);
403
+ return value >= 1 ? Math.floor(value) : DEFAULT_REF_MAX_BYTES;
404
+ }
405
+ function bytesOf(value) {
406
+ return Buffer.byteLength(JSON.stringify(value ?? null, null, 2), "utf8");
407
+ }
408
+ function compactValue(value, arrayLimit, stringLimit, depth = 0) {
409
+ if (depth > 6) return "<omitted: too deep>";
410
+ if (typeof value === "string") {
411
+ return value.length > stringLimit ? `${value.slice(0, stringLimit)}\u2026(truncated ${value.length - stringLimit} chars)` : value;
412
+ }
413
+ if (Array.isArray(value)) {
414
+ return value.slice(0, arrayLimit).map((item) => compactValue(item, arrayLimit, stringLimit, depth + 1));
415
+ }
416
+ if (value && typeof value === "object") {
417
+ const out = {};
418
+ for (const [key, inner] of Object.entries(value)) {
419
+ out[key] = compactValue(inner, arrayLimit, stringLimit, depth + 1);
420
+ }
421
+ return out;
422
+ }
423
+ return value;
424
+ }
425
+ function compactRecord(value, budgetBytes, keepKeys) {
426
+ let current = value;
427
+ for (const tier of COMPACT_TIERS) {
428
+ const out = {};
429
+ for (const [key, inner] of Object.entries(value)) {
430
+ out[key] = keepKeys.includes(key) ? inner : compactValue(inner, tier.array, tier.string);
431
+ }
432
+ current = out;
433
+ if (bytesOf(out) <= budgetBytes) return out;
434
+ }
435
+ return current;
436
+ }
437
+ function skeletonOf(value, keepKeys, hasRef = true) {
438
+ const out = {};
439
+ const recoveryHint = hasRef ? "use --input-ref" : "result unavailable";
440
+ for (const [key, inner] of Object.entries(value)) {
441
+ if (keepKeys.includes(key)) {
442
+ out[key] = key === "error" ? compactError(inner) : inner;
443
+ } else if (Array.isArray(inner)) {
444
+ out[key] = `<omitted: ${inner.length} items, ${recoveryHint}>`;
445
+ } else if (inner && typeof inner === "object") {
446
+ out[key] = `<omitted: ${Object.keys(inner).length} keys, ${recoveryHint}>`;
447
+ } else if (typeof inner === "string") {
448
+ out[key] = inner.length > 160 ? `${inner.slice(0, 160)}\u2026(truncated)` : inner;
449
+ } else {
450
+ out[key] = inner;
451
+ }
452
+ }
453
+ return out;
454
+ }
455
+ var ENVELOPE_KEEP_KEYS = [
456
+ "schemaVersion",
457
+ "ok",
458
+ "operation",
459
+ "status",
460
+ "error"
461
+ ];
462
+ function compactError(value) {
463
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
464
+ const error = value;
465
+ const out = {};
466
+ for (const key of ["type", "subtype", "code", "retryable", "stage"]) {
467
+ if (error[key] !== void 0) out[key] = error[key];
468
+ }
469
+ if (typeof error.message === "string") {
470
+ out.message = error.message.length > 240 ? `${error.message.slice(0, 240)}\u2026(truncated)` : error.message;
471
+ }
472
+ if (error.details !== void 0) out.details = "<omitted: see the error subtype and message>";
473
+ return out;
474
+ }
475
+ function operationOf(value) {
476
+ if (value && typeof value === "object" && !Array.isArray(value)) {
477
+ const operation = value.operation;
478
+ if (typeof operation === "string") return operation;
479
+ }
480
+ return void 0;
481
+ }
482
+ function warningsOf(value) {
483
+ const warnings = value.warnings;
484
+ return Array.isArray(warnings) ? warnings : [];
485
+ }
486
+ function withLeadingMeta(value, leading, body, extraWarnings) {
487
+ const base = value && typeof value === "object" && !Array.isArray(value) ? value : { data: value };
488
+ const reserved = /* @__PURE__ */ new Set([...Object.keys(leading), "warnings"]);
489
+ const safeBody = Object.fromEntries(Object.entries(body).filter(([key]) => !reserved.has(key)));
490
+ const compactWarnings = Object.prototype.hasOwnProperty.call(body, "warnings") ? Array.isArray(body.warnings) ? body.warnings : [body.warnings] : warningsOf(base);
491
+ return {
492
+ ...leading,
493
+ ...safeBody,
494
+ warnings: [...compactWarnings, ...extraWarnings]
495
+ };
496
+ }
497
+ function slimmedBody(value, threshold, hasRef) {
498
+ const base = value && typeof value === "object" && !Array.isArray(value) ? value : { data: value };
499
+ const compacted = compactRecord(base, threshold, ENVELOPE_KEEP_KEYS);
500
+ if (bytesOf(compacted) <= threshold) return compacted;
501
+ return skeletonOf(base, ENVELOPE_KEEP_KEYS, hasRef);
502
+ }
503
+ function fitEnvelope(value, leading, extraWarnings, budgetBytes) {
504
+ const hasRef = leading.resultPersisted === true;
505
+ const body = slimmedBody(value, budgetBytes, hasRef);
506
+ let envelope = withLeadingMeta(value, leading, body, extraWarnings);
507
+ if (bytesOf(envelope) <= budgetBytes) return envelope;
508
+ const base = value && typeof value === "object" && !Array.isArray(value) ? value : { data: value };
509
+ envelope = withLeadingMeta(
510
+ value,
511
+ leading,
512
+ skeletonOf(base, ENVELOPE_KEEP_KEYS, leading.resultPersisted === true),
513
+ extraWarnings
514
+ );
515
+ if (bytesOf(envelope) <= budgetBytes) return envelope;
516
+ const persisted = leading.resultPersisted === true;
517
+ const refId = String(leading.refId ?? "").slice(0, 80);
518
+ return {
519
+ ...persisted ? { refId } : {},
520
+ resultPersisted: persisted,
521
+ outputBytes: Number(leading.outputBytes) || 0,
522
+ largeOutputNotice: persisted ? `\u7ED3\u679C\u5DF2\u7CBE\u7B80\uFF0C\u4F7F\u7528 --input-ref ${refId} \u8BFB\u53D6\u3002` : "\u7ED3\u679C\u65E0\u6CD5\u6682\u5B58\uFF1Bstdout \u4EC5\u4FDD\u7559\u7CBE\u7B80\u5185\u5BB9\uFF0C\u5B8C\u6574\u7ED3\u679C\u4E0D\u53EF\u6062\u590D\u3002",
523
+ previewTruncated: true,
524
+ schemaVersion: typeof base.schemaVersion === "number" || typeof base.schemaVersion === "string" ? String(base.schemaVersion).slice(0, 20) : 1,
525
+ ok: typeof base.ok === "boolean" ? base.ok : true,
526
+ ...typeof base.operation === "string" ? { operation: base.operation.slice(0, 80) } : {},
527
+ ...base.error === void 0 ? {} : { error: compactError(base.error) },
528
+ data: persisted ? "<omitted: use --input-ref>" : "<omitted: full result unavailable>",
529
+ warnings: [...extraWarnings, "stdout_compacted"]
530
+ };
531
+ }
532
+ function stringifyForStdout(value, compactPaths) {
533
+ const wanted = new Set((compactPaths ?? []).filter((path) => typeof path === "string" && path !== ""));
534
+ const plain = JSON.stringify(value, null, 2);
535
+ if (!wanted.size || plain === void 0) return plain;
536
+ let salt = "";
537
+ do {
538
+ salt = `__WEAVER_COMPACT_${Math.random().toString(36).slice(2, 12)}__`;
539
+ } while (plain.includes(salt));
540
+ const compacted = [];
541
+ const swap = (node, path) => {
542
+ if (node !== null && typeof node === "object" && wanted.has(path)) {
543
+ const inline = JSON.stringify(node);
544
+ if (inline !== void 0) {
545
+ compacted.push(inline);
546
+ return `${salt}${compacted.length - 1}__`;
547
+ }
548
+ }
549
+ if (Array.isArray(node)) return node.map((item, index) => swap(item, `${path}[${index}]`));
550
+ if (node !== null && typeof node === "object") {
551
+ const out = {};
552
+ for (const [key, item] of Object.entries(node)) {
553
+ out[key] = swap(item, path ? `${path}.${key}` : key);
554
+ }
555
+ return out;
556
+ }
557
+ return node;
558
+ };
559
+ const swapped = JSON.stringify(swap(value, ""), null, 2);
560
+ if (typeof swapped !== "string") return swapped;
561
+ return swapped.replace(
562
+ new RegExp(`"${salt}(\\d+)__"`, "g"),
563
+ (_match, index) => compacted[Number(index)] ?? "null"
564
+ );
565
+ }
566
+ var Output = class {
567
+ constructor(ctx) {
568
+ this.ctx = ctx;
569
+ }
570
+ ctx;
571
+ write(value, options = {}) {
572
+ const globalOptions = this.ctx.getGlobalOptions();
573
+ const useJson = globalOptions.json || options.json || !options.text;
574
+ if (!useJson) {
575
+ console.log(options.text);
576
+ return;
577
+ }
578
+ console.log(stringifyForStdout(this.prepare(value, options), options.compactPaths));
579
+ }
580
+ prepare(value, options) {
581
+ const threshold = resultThresholdBytes(this.ctx);
582
+ if (options.persist === false || threshold <= 0) return value;
583
+ const finalBudget = Math.max(1024, threshold - 1024);
584
+ const bytes = bytesOf(value);
585
+ if (bytes <= threshold) return value;
586
+ const limits = { maxCount: refMaxCount(this.ctx), maxBytes: refMaxBytes(this.ctx) };
587
+ const warnings = [];
588
+ try {
589
+ try {
590
+ pruneRefs(this.ctx, limits);
591
+ } catch {
592
+ warnings.push("ref_gc_failed");
593
+ }
594
+ const meta = writeRef(this.ctx, { value, operation: operationOf(value), ttlMs: refTtlMs(this.ctx) });
595
+ let retention;
596
+ try {
597
+ retention = pruneRefs(this.ctx, { ...limits, preserveRefIds: [meta.refId] });
598
+ } catch {
599
+ warnings.push("ref_gc_failed");
600
+ }
601
+ if (retention?.overLimit) warnings.push("ref_store_over_limit");
602
+ if (retention?.cleanupIncomplete) warnings.push("ref_gc_incomplete");
603
+ return fitEnvelope(value, this.leadingFor(meta, bytes, retention), warnings, finalBudget);
604
+ } catch (error) {
605
+ const code = error && typeof error === "object" && "code" in error ? String(error.code) : "";
606
+ const message = code === "ENOSPC" ? "\u78C1\u76D8\u7A7A\u95F4\u4E0D\u8DB3" : code === "EACCES" || code === "EPERM" ? "CLI \u6682\u5B58\u76EE\u5F55\u65E0\u5199\u5165\u6743\u9650" : "\u65E0\u6CD5\u5199\u5165 CLI \u6682\u5B58\u76EE\u5F55";
607
+ process.stderr.write(
608
+ `[weaver-work-cli] \u7ED3\u679C ${bytes} \u5B57\u8282\u8D85\u8FC7 stdout \u9884\u7B97 ${threshold} \u5B57\u8282\u4E14\u843D\u76D8\u5931\u8D25\uFF0C\u8F93\u51FA\u5DF2\u7CBE\u7B80\uFF1A${message}
609
+ `
610
+ );
611
+ return fitEnvelope(
612
+ value,
613
+ {
614
+ outputBytes: bytes,
615
+ resultPersisted: false,
616
+ largeOutputNotice: `\u7ED3\u679C\u8D85\u8FC7 stdout \u9650\u5236\u4E14\u65E0\u6CD5\u6682\u5B58\uFF1B\u5F53\u524D\u5185\u5BB9\u5DF2\u7CBE\u7B80\uFF0C\u53EF\u80FD\u4E0D\u5B8C\u6574\uFF1A${message.slice(0, 160)}`
617
+ },
618
+ ["result_persist_failed"],
619
+ finalBudget
620
+ );
621
+ }
622
+ }
623
+ leadingFor(meta, bytes, retention) {
624
+ const retentionNotice = retention?.cleanupIncomplete ? " \u90E8\u5206\u65E7\u5F15\u7528\u6682\u65F6\u65E0\u6CD5\u5220\u9664\uFF0CCLI \u4F1A\u5728\u540E\u7EED\u547D\u4EE4\u91CD\u8BD5\u3002" : retention?.overLimit ? " \u672C\u7ED3\u679C\u8D85\u8FC7\u6682\u5B58\u5BB9\u91CF\u4E0A\u9650\uFF0C\u5DF2\u4FDD\u7559\u672C\u6B21\u7ED3\u679C\u5E76\u6DD8\u6C70\u65E7\u7ED3\u679C\u3002" : "";
625
+ return {
626
+ refId: meta.refId,
627
+ resultPersisted: true,
628
+ outputBytes: bytes,
629
+ sha256: meta.sha256,
630
+ expiresAt: meta.expiresAt,
631
+ previewTruncated: true,
632
+ largeOutputNotice: `\u7ED3\u679C ${bytes} \u5B57\u8282\u5DF2\u6682\u5B58\u3002\u4F7F\u7528 --input-ref ${meta.refId} \u5F15\u7528\uFF1B\u53D6\u5355\u4E2A\u5B57\u6BB5\u65F6\u52A0 --pick-as <\u5B57\u6BB5\u540D>\u3002` + retentionNotice
633
+ };
634
+ }
635
+ raw(message) {
636
+ console.log(message);
637
+ }
638
+ };
639
+
640
+ export {
641
+ RefError,
642
+ readRef,
643
+ listRefs,
644
+ pruneRefs,
645
+ pickValue,
646
+ resolveRefInput,
647
+ DEFAULT_RESULT_THRESHOLD_BYTES,
648
+ resultThresholdBytes,
649
+ refMaxCount,
650
+ refMaxBytes,
651
+ bytesOf,
652
+ stringifyForStdout,
653
+ Output
654
+ };