weaver-work-cli 0.1.8 → 0.1.21
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.
- package/README.md +25 -17
- package/dist/cmd/action.js +76 -0
- package/dist/cmd/index.js +2 -0
- package/dist/cmd/refs/index.js +103 -0
- package/dist/cmd/register.js +31 -0
- package/dist/cmd/root.js +1 -0
- package/dist/cmd/setup/index.js +25 -5
- package/dist/cmd/skills/index.js +37 -5
- package/dist/core/connector.js +54 -0
- package/dist/core/context.js +2 -1
- package/dist/core/input.js +48 -0
- package/dist/core/output.js +298 -3
- package/dist/core/refs.js +435 -0
- package/dist/core/state.js +26 -0
- package/dist/internal/e10/auth/commands.js +34 -19
- package/dist/internal/e10/auth/session.js +74 -2
- package/dist/internal/e10/auth/xiaoe.js +359 -94
- package/dist/internal/e10/context.js +18 -6
- package/dist/internal/e10/request-runtime.js +8 -1
- package/dist/internal/skills/install.js +148 -28
- package/dist/internal/skills/reader.js +12 -9
- package/dist/shortcuts/blog/continuation.js +74 -0
- package/dist/shortcuts/blog/errors.js +60 -0
- package/dist/shortcuts/blog/host.js +175 -0
- package/dist/shortcuts/blog/index.js +324 -0
- package/dist/shortcuts/blog/manifest.js +415 -0
- package/dist/shortcuts/blog/operations/comment.js +125 -0
- package/dist/shortcuts/blog/operations/comments.js +31 -0
- package/dist/shortcuts/blog/operations/edit.js +131 -0
- package/dist/shortcuts/blog/operations/export.js +46 -0
- package/dist/shortcuts/blog/operations/like.js +80 -0
- package/dist/shortcuts/blog/operations/publish.js +157 -0
- package/dist/shortcuts/blog/operations/query-user.js +58 -0
- package/dist/shortcuts/blog/operations/query.js +96 -0
- package/dist/shortcuts/blog/operations/registry.js +54 -0
- package/dist/shortcuts/blog/operations/remind.js +176 -0
- package/dist/shortcuts/blog/operations/shared.js +330 -0
- package/dist/shortcuts/blog/operations/types.js +16 -0
- package/dist/shortcuts/blog/operations.js +9 -0
- package/dist/shortcuts/caizhilian/continuation.js +70 -0
- package/dist/shortcuts/caizhilian/errors.js +53 -0
- package/dist/shortcuts/caizhilian/host.js +190 -0
- package/dist/shortcuts/caizhilian/index.js +186 -0
- package/dist/shortcuts/caizhilian/manifest.js +42 -0
- package/dist/shortcuts/caizhilian/operations/api.js +801 -0
- package/dist/shortcuts/caizhilian/operations/confirm.js +75 -0
- package/dist/shortcuts/caizhilian/operations/files.js +306 -0
- package/dist/shortcuts/caizhilian/operations/form.js +170 -0
- package/dist/shortcuts/caizhilian/operations/handlers/collab.js +611 -0
- package/dist/shortcuts/caizhilian/operations/handlers/document.js +890 -0
- package/dist/shortcuts/caizhilian/operations/handlers/file-collection.js +1227 -0
- package/dist/shortcuts/caizhilian/operations/handlers/file-upload.js +192 -0
- package/dist/shortcuts/caizhilian/operations/handlers/fileops.js +570 -0
- package/dist/shortcuts/caizhilian/operations/handlers/folder.js +1024 -0
- package/dist/shortcuts/caizhilian/operations/handlers/search.js +318 -0
- package/dist/shortcuts/caizhilian/operations/handlers/setting-attach.js +294 -0
- package/dist/shortcuts/caizhilian/operations/handlers/setting-backup.js +423 -0
- package/dist/shortcuts/caizhilian/operations/handlers/setting-encrypt.js +238 -0
- package/dist/shortcuts/caizhilian/operations/handlers/setting-storage.js +364 -0
- package/dist/shortcuts/caizhilian/operations/handlers/system.js +106 -0
- package/dist/shortcuts/caizhilian/operations/registry.js +151 -0
- package/dist/shortcuts/caizhilian/operations/shared.js +408 -0
- package/dist/shortcuts/caizhilian/operations/specs.js +698 -0
- package/dist/shortcuts/caizhilian/operations/types.js +57 -0
- package/dist/shortcuts/caizhilian/operations.js +21 -0
- package/dist/shortcuts/contract/continuation.js +70 -0
- package/dist/shortcuts/contract/errors.js +62 -0
- package/dist/shortcuts/contract/host.js +205 -0
- package/dist/shortcuts/contract/index.js +318 -0
- package/dist/shortcuts/contract/manifest.js +596 -0
- package/dist/shortcuts/contract/operations/clause-reference.js +78 -0
- package/dist/shortcuts/contract/operations/form-info.js +371 -0
- package/dist/shortcuts/contract/operations/read.js +118 -0
- package/dist/shortcuts/contract/operations/registry.js +43 -0
- package/dist/shortcuts/contract/operations/request.js +300 -0
- package/dist/shortcuts/contract/operations/shared.js +133 -0
- package/dist/shortcuts/contract/operations/subject.js +157 -0
- package/dist/shortcuts/contract/operations/template.js +81 -0
- package/dist/shortcuts/contract/operations/types.js +7 -0
- package/dist/shortcuts/contract/operations/workflow.js +52 -0
- package/dist/shortcuts/contract/operations/write.js +131 -0
- package/dist/shortcuts/contract/operations.js +8 -0
- package/dist/shortcuts/hrm/index.js +83 -2
- package/dist/shortcuts/hrm/manifest.js +16 -9
- package/dist/shortcuts/hrm/operations/employee.js +160 -30
- package/dist/shortcuts/hrm/operations/org.js +17 -3
- package/dist/shortcuts/hrm/operations/position.js +18 -2
- package/dist/shortcuts/hrm/operations/registry.js +2 -0
- package/dist/shortcuts/hrm/operations/resolve.js +449 -0
- package/dist/shortcuts/index.js +5 -1
- package/dist/shortcuts/invoice/index.js +74 -36
- package/dist/shortcuts/invoice/manifest.js +674 -4
- package/dist/shortcuts/invoice/markdown.js +172 -0
- package/dist/shortcuts/invoice/operations/add.js +3 -3
- package/dist/shortcuts/invoice/operations/delete.js +2 -2
- package/dist/shortcuts/invoice/operations/get.js +10 -2
- package/dist/shortcuts/invoice/operations/import.js +2 -2
- package/dist/shortcuts/invoice/operations/registry.js +8 -1
- package/dist/shortcuts/invoice/operations/reim-auto.js +719 -0
- package/dist/shortcuts/invoice/operations/reim.js +85 -2
- package/dist/shortcuts/invoice/operations/shared.js +75 -8
- package/dist/shortcuts/invoice/operations/update.js +2 -2
- package/dist/shortcuts/invoice/operations/upload-and-validate.js +93 -0
- package/dist/shortcuts/invoice/operations/validate-preview.js +2 -1
- package/dist/shortcuts/invoice/projection.js +328 -0
- package/dist/shortcuts/meeting/host.js +18 -1
- package/dist/shortcuts/meeting/manifest.js +30 -18
- package/dist/shortcuts/meeting/operations/eb/catalog.js +390 -0
- package/dist/shortcuts/meeting/operations/eb/conflict.js +389 -0
- package/dist/shortcuts/meeting/operations/eb/factory.js +389 -0
- package/dist/shortcuts/meeting/operations/eb/index.js +22 -0
- package/dist/shortcuts/meeting/operations/env.js +8 -1
- package/dist/shortcuts/meeting/operations/registry.js +2 -0
- package/dist/shortcuts/meeting/operations/signs.js +216 -2
- package/dist/shortcuts/workflow/endpoints.js +2 -1
- package/dist/shortcuts/workflow/errors.js +8 -2
- package/dist/shortcuts/workflow/host.js +11 -4
- package/dist/shortcuts/workflow/operations/form.js +1016 -590
- package/dist/shortcuts/workflow/operations/read.js +913 -231
- package/dist/shortcuts/workflow/operations/shared.js +21 -0
- package/dist/shortcuts/workflow/operations/write.js +750 -52
- package/dist/shortcuts/workflow/operations.js +36 -10
- package/docs/_catalog.md +6 -0
- package/docs/agent-invoice.md +5 -1
- package/docs/agent-io-channel-design.md +468 -0
- package/docs/agent-skill-install.md +9 -4
- package/docs/blog.md +123 -0
- package/docs/caizhilian.md +304 -0
- package/docs/contract.md +91 -0
- package/docs/e10-auth.md +4 -2
- package/docs/hrm.md +53 -11
- package/docs/invoice.md +5 -1
- package/docs/meeting.md +1 -1
- package/docs/operation-manual.md +15 -3
- package/docs/skill-review-2026-09-19.md +2 -2
- package/package.json +1 -1
- package/scripts/package-skill.mjs +32 -20
- package/scripts/xiaoe_env.py +118 -0
- package/skill-template/business-info.json +113 -14
- package/skill-template/domains/blog.md +24 -0
- package/skill-template/domains/caizhilian.md +22 -0
- package/skill-template/domains/hrm.md +2 -1
- package/skill-template/domains/jinchengda.md +23 -0
- package/skill-template/domains/meeting.md +1 -1
- package/skill-template/domains/workflow.md +1 -1
- package/skill-template/skill-template.md +1 -1
- package/skills/weaver-e10-blog/SKILL.md +111 -0
- package/skills/weaver-e10-blog/references/blog-comment.md +51 -0
- package/skills/weaver-e10-blog/references/blog-comments.md +39 -0
- package/skills/weaver-e10-blog/references/blog-default-permission.md +38 -0
- package/skills/weaver-e10-blog/references/blog-disabled-capabilities.md +11 -0
- package/skills/weaver-e10-blog/references/blog-edit.md +51 -0
- package/skills/weaver-e10-blog/references/blog-export.md +42 -0
- package/skills/weaver-e10-blog/references/blog-like.md +50 -0
- package/skills/weaver-e10-blog/references/blog-publish.md +52 -0
- package/skills/weaver-e10-blog/references/blog-query-user.md +45 -0
- package/skills/weaver-e10-blog/references/blog-query.md +49 -0
- package/skills/weaver-e10-blog/references/blog-remind.md +51 -0
- package/skills/weaver-e10-blog/references/blog-resolve-users.md +38 -0
- package/skills/weaver-e10-blog/references/source-manifest.json +1540 -0
- package/skills/weaver-e10-caizhilian/SKILL.md +217 -0
- package/skills/weaver-e10-caizhilian/references/agent-entry.md +106 -0
- package/skills/weaver-e10-caizhilian/references/collaboration.md +112 -0
- package/skills/weaver-e10-caizhilian/references/document.md +111 -0
- package/skills/weaver-e10-caizhilian/references/file-collection.md +173 -0
- package/skills/weaver-e10-caizhilian/references/file-upload.md +309 -0
- package/skills/weaver-e10-caizhilian/references/files.md +120 -0
- package/skills/weaver-e10-caizhilian/references/folder.md +122 -0
- package/skills/weaver-e10-caizhilian/references/org-browser.md +104 -0
- package/skills/weaver-e10-caizhilian/references/setting-attach.md +440 -0
- package/skills/weaver-e10-caizhilian/references/setting-backup.md +372 -0
- package/skills/weaver-e10-caizhilian/references/setting-encrypt.md +399 -0
- package/skills/weaver-e10-caizhilian/references/setting-storage.md +603 -0
- package/skills/weaver-e10-caizhilian/references/source-manifest.json +5694 -0
- package/skills/weaver-e10-caizhilian/references/withheld.md +93 -0
- package/skills/weaver-e10-caizhilian/references/write-protocol.md +120 -0
- package/skills/weaver-e10-calendar/SKILL.md +4 -3
- package/skills/weaver-e10-ebuilder-form/SKILL.md +4 -9
- package/skills/weaver-e10-ebuilder-form/references/context-routing.md +0 -9
- package/skills/weaver-e10-ebuilder-form/references/custom-api.md +1 -5
- package/skills/weaver-e10-ebuilder-form/references/fields-browser.md +1 -5
- package/skills/weaver-e10-ebuilder-form/references/list-nlist.md +1 -5
- package/skills/weaver-e10-ebuilder-form/references/openapi-read.md +1 -5
- package/skills/weaver-e10-ebuilder-form/references/openapi-write.md +1 -5
- package/skills/weaver-e10-esb/SKILL.md +2 -2
- package/skills/weaver-e10-esb/references/source-manifest.json +9 -9
- package/skills/weaver-e10-hrm/SKILL.md +104 -9
- package/skills/weaver-e10-hrm/references/employee.md +89 -15
- package/skills/weaver-e10-hrm/references/org.md +114 -5
- package/skills/weaver-e10-hrm/references/position.md +14 -7
- package/skills/weaver-e10-hrm/references/source-manifest.json +1 -1
- package/skills/weaver-e10-jinchengda/SKILL.md +167 -0
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +82 -0
- package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +69 -0
- package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +78 -0
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +27 -0
- package/skills/weaver-e10-jinchengda/references/contract-request-status.md +71 -0
- package/skills/weaver-e10-jinchengda/references/contract-request-write.md +94 -0
- package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +89 -0
- package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +77 -0
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +66 -0
- package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +94 -0
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +259 -0
- package/skills/weaver-e10-jiuchuanhui/SKILL.md +5 -11
- package/skills/weaver-e10-jucailin/SKILL.md +4 -3
- package/skills/weaver-e10-mail/SKILL.md +4 -11
- package/skills/weaver-e10-meeting/SKILL.md +66 -32
- package/skills/weaver-e10-meeting/references/meeting-change.md +5 -2
- package/skills/weaver-e10-meeting/references/meeting-create.md +2 -1
- package/skills/weaver-e10-meeting/references/meeting-eb.md +114 -0
- package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +9 -8
- package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +35 -7
- package/skills/weaver-e10-meeting/references/meeting-update.md +1 -1
- package/skills/weaver-e10-okr/SKILL.md +6 -11
- package/skills/weaver-e10-okr/references/source-manifest.json +3 -3
- package/skills/weaver-e10-plan/SKILL.md +3 -3
- package/skills/weaver-e10-plan/references/plan-collect-and-compose.md +1 -1
- package/skills/weaver-e10-plan/references/plan-overview-and-routing.md +1 -1
- package/skills/weaver-e10-plan/references/source-manifest.json +13 -13
- package/skills/weaver-e10-qiyecheng/SKILL.md +4 -10
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +9 -9
- package/skills/weaver-e10-shared/SKILL.md +42 -34
- package/skills/weaver-e10-shared/references/e10-auth-and-session.md +16 -43
- package/skills/weaver-e10-shared/references/json-output-contract.md +20 -11
- package/skills/weaver-e10-shared/references/non-interactive-environment.md +21 -14
- package/skills/weaver-e10-shijingran/SKILL.md +2 -1
- package/skills/weaver-e10-shijingran/references/source-manifest.json +9 -9
- package/skills/weaver-e10-skill-maker/SKILL.md +4 -10
- package/skills/weaver-e10-skill-maker/references/business-skill-generation.md +5 -3
- package/skills/weaver-e10-skill-maker/references/module-cli-generation.md +12 -27
- package/skills/weaver-e10-skill-maker/references/module-gap-audit-and-repair.md +17 -5
- package/skills/weaver-e10-skill-maker/references/source-update-detection.md +4 -27
- package/skills/weaver-e10-skill-maker/references/weaver-skill-style.md +1 -1
- package/skills/weaver-e10-wenshuding/SKILL.md +5 -16
- package/skills/weaver-e10-wenshuding/references/source-manifest.json +7 -7
- package/skills/weaver-e10-workflow/SKILL.md +41 -46
- package/skills/weaver-e10-workflow/references/source-manifest.json +39 -75
- package/skills/weaver-e10-workflow/references/workflow-batch.md +90 -29
- package/skills/weaver-e10-workflow/references/workflow-create.md +83 -109
- package/skills/weaver-e10-workflow/references/workflow-memory.md +19 -9
- package/skills/weaver-e10-workflow/references/workflow-operate.md +2 -2
- package/skills/weaver-e10-workflow/references/workflow-query.md +40 -27
- package/skills/weaver-e10-workflow/references/workflow-share.md +18 -2
- package/skills/weaver-e10-workflow/references/workflow-view.md +3 -4
- package/skills/weaver-e10-yepiaotong/SKILL.md +74 -39
- package/skills/weaver-e10-yepiaotong/references/invoice-detail.md +22 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +3 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-output-view.md +135 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +15 -3
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +1 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-summarize.py +217 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +88 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +7 -2
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +89 -9
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +1 -0
- package/skills/weaver-e10-yepiaotong/references/reim-expense-subject-rules.md +70 -49
- package/skills/weaver-e10-yepiaotong/references/reim-fast-path.md +119 -0
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +55 -36
- package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +4 -0
- package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +149 -0
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +125 -5
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +430 -63
- package/skills/weaver-e10-yimiaoban/SKILL.md +4 -12
- package/skills/weaver-e10-yimiaoban/references/source-manifest.json +3 -3
- package/skills/weaver-e10-ziguanjia/SKILL.md +2 -1
- package/skills/weaver-e10-ziguanjia/references/ziguanjia-agent-entry.md +3 -3
- package/tools/weaver-skill-detector-1.0.13/SKILL.md +9 -9
- package/tools/weaver-skill-detector-1.0.13/references/checklist.md +3 -3
- package/tools/weaver-skill-detector-1.0.13/scripts/__pycache__/validate_skill.cpython-313.pyc +0 -0
- package/tools/weaver-skill-detector-1.0.13/scripts/validate_skill.py +98 -91
- package/scripts/sync-connector-skills.mjs +0 -172
package/dist/core/output.js
CHANGED
|
@@ -1,11 +1,238 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { pruneRefs, writeRef } from './refs.js';
|
|
3
4
|
export function writeRawJson(outputPath, value) {
|
|
4
5
|
const absolutePath = resolve(outputPath);
|
|
5
6
|
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
6
7
|
writeFileSync(absolutePath, JSON.stringify(value, null, 2), 'utf-8');
|
|
7
8
|
return absolutePath;
|
|
8
9
|
}
|
|
10
|
+
/** 宿主实测约 24-32 KB 后会把 stdout 截断成约 2048 B 预览,取保守值。 */
|
|
11
|
+
export const DEFAULT_RESULT_THRESHOLD_BYTES = 24 * 1024;
|
|
12
|
+
/** 比 continuation 的 10 分钟更长:读结果往往要跨多步任务。 */
|
|
13
|
+
export const DEFAULT_REF_TTL_MS = 30 * 60_000;
|
|
14
|
+
export const DEFAULT_REF_MAX_COUNT = 50;
|
|
15
|
+
export const DEFAULT_REF_MAX_BYTES = 200 * 1024 * 1024;
|
|
16
|
+
const COMPACT_TIERS = [
|
|
17
|
+
{ array: 10, string: 200 },
|
|
18
|
+
{ array: 5, string: 80 },
|
|
19
|
+
{ array: 2, string: 40 },
|
|
20
|
+
{ array: 1, string: 20 },
|
|
21
|
+
];
|
|
22
|
+
function numberFromEnv(name) {
|
|
23
|
+
const raw = process.env[name];
|
|
24
|
+
if (raw === undefined || raw.trim() === '')
|
|
25
|
+
return undefined;
|
|
26
|
+
const parsed = Number(raw);
|
|
27
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
28
|
+
}
|
|
29
|
+
function configValue(ctx, key) {
|
|
30
|
+
const io = ctx.config.get('io');
|
|
31
|
+
if (io && typeof io === 'object' && !Array.isArray(io)) {
|
|
32
|
+
const holder = io;
|
|
33
|
+
if (key in holder)
|
|
34
|
+
return holder[key];
|
|
35
|
+
}
|
|
36
|
+
return ctx.config.get(key);
|
|
37
|
+
}
|
|
38
|
+
function numeric(ctx, envName, configKey, fallback) {
|
|
39
|
+
const fromEnv = numberFromEnv(envName);
|
|
40
|
+
if (fromEnv !== undefined)
|
|
41
|
+
return fromEnv;
|
|
42
|
+
const fromConfig = configValue(ctx, configKey);
|
|
43
|
+
if (typeof fromConfig === 'number' && Number.isFinite(fromConfig))
|
|
44
|
+
return fromConfig;
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
export function resultThresholdBytes(ctx) {
|
|
48
|
+
const value = numeric(ctx, 'WEAVER_WORK_CLI_REF_THRESHOLD', 'resultThreshold', DEFAULT_RESULT_THRESHOLD_BYTES);
|
|
49
|
+
return value === 0 || value >= 2 * 1024 ? Math.floor(value) : DEFAULT_RESULT_THRESHOLD_BYTES;
|
|
50
|
+
}
|
|
51
|
+
export function refTtlMs(ctx) {
|
|
52
|
+
const value = numeric(ctx, 'WEAVER_WORK_CLI_REF_TTL_MS', 'refTtlMs', DEFAULT_REF_TTL_MS);
|
|
53
|
+
return value >= 1 ? Math.floor(value) : DEFAULT_REF_TTL_MS;
|
|
54
|
+
}
|
|
55
|
+
export function refMaxCount(ctx) {
|
|
56
|
+
const value = numeric(ctx, 'WEAVER_WORK_CLI_REF_MAX_COUNT', 'refMaxCount', DEFAULT_REF_MAX_COUNT);
|
|
57
|
+
return value >= 1 ? Math.floor(value) : DEFAULT_REF_MAX_COUNT;
|
|
58
|
+
}
|
|
59
|
+
export function refMaxBytes(ctx) {
|
|
60
|
+
const value = numeric(ctx, 'WEAVER_WORK_CLI_REF_MAX_BYTES', 'refMaxBytes', DEFAULT_REF_MAX_BYTES);
|
|
61
|
+
return value >= 1 ? Math.floor(value) : DEFAULT_REF_MAX_BYTES;
|
|
62
|
+
}
|
|
63
|
+
export function bytesOf(value) {
|
|
64
|
+
return Buffer.byteLength(JSON.stringify(value ?? null, null, 2), 'utf8');
|
|
65
|
+
}
|
|
66
|
+
function compactValue(value, arrayLimit, stringLimit, depth = 0) {
|
|
67
|
+
if (depth > 6)
|
|
68
|
+
return '<omitted: too deep>';
|
|
69
|
+
if (typeof value === 'string') {
|
|
70
|
+
return value.length > stringLimit
|
|
71
|
+
? `${value.slice(0, stringLimit)}…(truncated ${value.length - stringLimit} chars)`
|
|
72
|
+
: value;
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return value.slice(0, arrayLimit).map((item) => compactValue(item, arrayLimit, stringLimit, depth + 1));
|
|
76
|
+
}
|
|
77
|
+
if (value && typeof value === 'object') {
|
|
78
|
+
const out = {};
|
|
79
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
80
|
+
out[key] = compactValue(inner, arrayLimit, stringLimit, depth + 1);
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/** 逐档收紧,尽量让精简版本身也落在 stdout 预算内。 */
|
|
87
|
+
export function compactForStdout(value, budgetBytes) {
|
|
88
|
+
let current = value;
|
|
89
|
+
for (const tier of COMPACT_TIERS) {
|
|
90
|
+
current = compactValue(value, tier.array, tier.string);
|
|
91
|
+
if (bytesOf(current) <= budgetBytes)
|
|
92
|
+
return current;
|
|
93
|
+
}
|
|
94
|
+
return current;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 保留判别字段(ok / operation / schemaVersion / error 等),压缩其余字段。
|
|
98
|
+
*
|
|
99
|
+
* 不能只压 `data`:像 `invoice schema` 这类命令的 envelope 没有 data 键,
|
|
100
|
+
* 大字段是 `operations` / `withheldOperations`,只压 data 等于没压。
|
|
101
|
+
*/
|
|
102
|
+
export function compactRecord(value, budgetBytes, keepKeys) {
|
|
103
|
+
let current = value;
|
|
104
|
+
for (const tier of COMPACT_TIERS) {
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
107
|
+
out[key] = keepKeys.includes(key) ? inner : compactValue(inner, tier.array, tier.string);
|
|
108
|
+
}
|
|
109
|
+
current = out;
|
|
110
|
+
if (bytesOf(out) <= budgetBytes)
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
return current;
|
|
114
|
+
}
|
|
115
|
+
/** 兜底:逐档压缩后仍超预算时,只留判别字段与占位符,保证指针必然落在前 2048 B 内。 */
|
|
116
|
+
export function skeletonOf(value, keepKeys, hasRef = true) {
|
|
117
|
+
const out = {};
|
|
118
|
+
const recoveryHint = hasRef ? 'use --input-ref' : 'result unavailable';
|
|
119
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
120
|
+
if (keepKeys.includes(key)) {
|
|
121
|
+
out[key] = key === 'error' ? compactError(inner) : inner;
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(inner)) {
|
|
124
|
+
out[key] = `<omitted: ${inner.length} items, ${recoveryHint}>`;
|
|
125
|
+
}
|
|
126
|
+
else if (inner && typeof inner === 'object') {
|
|
127
|
+
out[key] = `<omitted: ${Object.keys(inner).length} keys, ${recoveryHint}>`;
|
|
128
|
+
}
|
|
129
|
+
else if (typeof inner === 'string') {
|
|
130
|
+
out[key] = inner.length > 160 ? `${inner.slice(0, 160)}…(truncated)` : inner;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
out[key] = inner;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/** 判别成败所必需的字段,压缩时原样保留。 */
|
|
139
|
+
export const ENVELOPE_KEEP_KEYS = [
|
|
140
|
+
'schemaVersion',
|
|
141
|
+
'ok',
|
|
142
|
+
'operation',
|
|
143
|
+
'status',
|
|
144
|
+
'error',
|
|
145
|
+
];
|
|
146
|
+
/** 错误可能带很大的 details;精简时保留分类和可执行的错误信息。 */
|
|
147
|
+
function compactError(value) {
|
|
148
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
149
|
+
return value;
|
|
150
|
+
const error = value;
|
|
151
|
+
const out = {};
|
|
152
|
+
for (const key of ['type', 'subtype', 'code', 'retryable', 'stage']) {
|
|
153
|
+
if (error[key] !== undefined)
|
|
154
|
+
out[key] = error[key];
|
|
155
|
+
}
|
|
156
|
+
if (typeof error.message === 'string') {
|
|
157
|
+
out.message = error.message.length > 240 ? `${error.message.slice(0, 240)}…(truncated)` : error.message;
|
|
158
|
+
}
|
|
159
|
+
if (error.details !== undefined)
|
|
160
|
+
out.details = '<omitted: see the error subtype and message>';
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
function operationOf(value) {
|
|
164
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
165
|
+
const operation = value.operation;
|
|
166
|
+
if (typeof operation === 'string')
|
|
167
|
+
return operation;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
function warningsOf(value) {
|
|
172
|
+
const warnings = value.warnings;
|
|
173
|
+
return Array.isArray(warnings) ? warnings : [];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 引用信息必须排在 JSON 前面,保证被宿主预览截断时仍能看到 refId。
|
|
177
|
+
*/
|
|
178
|
+
function withLeadingMeta(value, leading, body, extraWarnings) {
|
|
179
|
+
const base = value && typeof value === 'object' && !Array.isArray(value)
|
|
180
|
+
? value
|
|
181
|
+
: { data: value };
|
|
182
|
+
const reserved = new Set([...Object.keys(leading), 'warnings']);
|
|
183
|
+
const safeBody = Object.fromEntries(Object.entries(body).filter(([key]) => !reserved.has(key)));
|
|
184
|
+
const compactWarnings = Object.prototype.hasOwnProperty.call(body, 'warnings')
|
|
185
|
+
? (Array.isArray(body.warnings) ? body.warnings : [body.warnings])
|
|
186
|
+
: warningsOf(base);
|
|
187
|
+
return {
|
|
188
|
+
...leading,
|
|
189
|
+
...safeBody,
|
|
190
|
+
warnings: [...compactWarnings, ...extraWarnings],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function slimmedBody(value, threshold, hasRef) {
|
|
194
|
+
const base = value && typeof value === 'object' && !Array.isArray(value)
|
|
195
|
+
? value
|
|
196
|
+
: { data: value };
|
|
197
|
+
const compacted = compactRecord(base, threshold, ENVELOPE_KEEP_KEYS);
|
|
198
|
+
if (bytesOf(compacted) <= threshold)
|
|
199
|
+
return compacted;
|
|
200
|
+
return skeletonOf(base, ENVELOPE_KEEP_KEYS, hasRef);
|
|
201
|
+
}
|
|
202
|
+
function fitEnvelope(value, leading, extraWarnings, budgetBytes) {
|
|
203
|
+
const hasRef = leading.resultPersisted === true;
|
|
204
|
+
const body = slimmedBody(value, budgetBytes, hasRef);
|
|
205
|
+
let envelope = withLeadingMeta(value, leading, body, extraWarnings);
|
|
206
|
+
if (bytesOf(envelope) <= budgetBytes)
|
|
207
|
+
return envelope;
|
|
208
|
+
const base = value && typeof value === 'object' && !Array.isArray(value)
|
|
209
|
+
? value
|
|
210
|
+
: { data: value };
|
|
211
|
+
envelope = withLeadingMeta(value, leading, skeletonOf(base, ENVELOPE_KEEP_KEYS, leading.resultPersisted === true), extraWarnings);
|
|
212
|
+
if (bytesOf(envelope) <= budgetBytes)
|
|
213
|
+
return envelope;
|
|
214
|
+
const persisted = leading.resultPersisted === true;
|
|
215
|
+
const refId = String(leading.refId ?? '').slice(0, 80);
|
|
216
|
+
return {
|
|
217
|
+
...(persisted ? { refId } : {}),
|
|
218
|
+
resultPersisted: persisted,
|
|
219
|
+
outputBytes: Number(leading.outputBytes) || 0,
|
|
220
|
+
largeOutputNotice: persisted
|
|
221
|
+
? `结果已精简,使用 --input-ref ${refId} 读取。`
|
|
222
|
+
: '结果无法暂存;stdout 仅保留精简内容,完整结果不可恢复。',
|
|
223
|
+
previewTruncated: true,
|
|
224
|
+
schemaVersion: typeof base.schemaVersion === 'number' || typeof base.schemaVersion === 'string'
|
|
225
|
+
? String(base.schemaVersion).slice(0, 20)
|
|
226
|
+
: 1,
|
|
227
|
+
ok: typeof base.ok === 'boolean' ? base.ok : true,
|
|
228
|
+
...(typeof base.operation === 'string' ? { operation: base.operation.slice(0, 80) } : {}),
|
|
229
|
+
...(base.error === undefined ? {} : { error: compactError(base.error) }),
|
|
230
|
+
data: persisted
|
|
231
|
+
? '<omitted: use --input-ref>'
|
|
232
|
+
: '<omitted: full result unavailable>',
|
|
233
|
+
warnings: [...extraWarnings, 'stdout_compacted'],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
9
236
|
export class Output {
|
|
10
237
|
ctx;
|
|
11
238
|
constructor(ctx) {
|
|
@@ -13,11 +240,79 @@ export class Output {
|
|
|
13
240
|
}
|
|
14
241
|
write(value, options = {}) {
|
|
15
242
|
const globalOptions = this.ctx.getGlobalOptions();
|
|
16
|
-
|
|
17
|
-
|
|
243
|
+
const useJson = globalOptions.json || options.json || !options.text;
|
|
244
|
+
if (!useJson) {
|
|
245
|
+
console.log(options.text);
|
|
18
246
|
return;
|
|
19
247
|
}
|
|
20
|
-
console.log(options
|
|
248
|
+
console.log(JSON.stringify(this.prepare(value, options), null, 2));
|
|
249
|
+
}
|
|
250
|
+
prepare(value, options) {
|
|
251
|
+
const threshold = resultThresholdBytes(this.ctx);
|
|
252
|
+
if (options.persist === false || threshold <= 0)
|
|
253
|
+
return value;
|
|
254
|
+
const finalBudget = Math.max(1024, threshold - 1024);
|
|
255
|
+
const bytes = bytesOf(value);
|
|
256
|
+
if (bytes <= threshold)
|
|
257
|
+
return value;
|
|
258
|
+
const limits = { maxCount: refMaxCount(this.ctx), maxBytes: refMaxBytes(this.ctx) };
|
|
259
|
+
const warnings = [];
|
|
260
|
+
try {
|
|
261
|
+
try {
|
|
262
|
+
pruneRefs(this.ctx, limits);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
warnings.push('ref_gc_failed');
|
|
266
|
+
}
|
|
267
|
+
const meta = writeRef(this.ctx, { value, operation: operationOf(value), ttlMs: refTtlMs(this.ctx) });
|
|
268
|
+
let retention;
|
|
269
|
+
try {
|
|
270
|
+
retention = pruneRefs(this.ctx, { ...limits, preserveRefIds: [meta.refId] });
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
warnings.push('ref_gc_failed');
|
|
274
|
+
}
|
|
275
|
+
if (retention?.overLimit)
|
|
276
|
+
warnings.push('ref_store_over_limit');
|
|
277
|
+
if (retention?.cleanupIncomplete)
|
|
278
|
+
warnings.push('ref_gc_incomplete');
|
|
279
|
+
return fitEnvelope(value, this.leadingFor(meta, bytes, retention), warnings, finalBudget);
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
// 落盘失败绝不静默截断:标注 degraded,让调用方知道这份结果不完整。
|
|
283
|
+
const code = error && typeof error === 'object' && 'code' in error
|
|
284
|
+
? String(error.code)
|
|
285
|
+
: '';
|
|
286
|
+
const message = code === 'ENOSPC'
|
|
287
|
+
? '磁盘空间不足'
|
|
288
|
+
: code === 'EACCES' || code === 'EPERM'
|
|
289
|
+
? 'CLI 暂存目录无写入权限'
|
|
290
|
+
: '无法写入 CLI 暂存目录';
|
|
291
|
+
process.stderr.write(`[weaver-work-cli] 结果 ${bytes} 字节超过 stdout 预算 ${threshold} 字节且落盘失败,输出已精简:${message}\n`);
|
|
292
|
+
return fitEnvelope(value, {
|
|
293
|
+
outputBytes: bytes,
|
|
294
|
+
resultPersisted: false,
|
|
295
|
+
largeOutputNotice: `结果超过 stdout 限制且无法暂存;当前内容已精简,可能不完整:${message.slice(0, 160)}`,
|
|
296
|
+
}, ['result_persist_failed'], finalBudget);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
leadingFor(meta, bytes, retention) {
|
|
300
|
+
const retentionNotice = retention?.cleanupIncomplete
|
|
301
|
+
? ' 部分旧引用暂时无法删除,CLI 会在后续命令重试。'
|
|
302
|
+
: retention?.overLimit
|
|
303
|
+
? ' 本结果超过暂存容量上限,已保留本次结果并淘汰旧结果。'
|
|
304
|
+
: '';
|
|
305
|
+
return {
|
|
306
|
+
refId: meta.refId,
|
|
307
|
+
resultPersisted: true,
|
|
308
|
+
outputBytes: bytes,
|
|
309
|
+
sha256: meta.sha256,
|
|
310
|
+
expiresAt: meta.expiresAt,
|
|
311
|
+
previewTruncated: true,
|
|
312
|
+
largeOutputNotice: `结果 ${bytes} 字节已暂存。使用 --input-ref ${meta.refId} 引用;`
|
|
313
|
+
+ `取单个字段时加 --pick-as <字段名>。`
|
|
314
|
+
+ retentionNotice,
|
|
315
|
+
};
|
|
21
316
|
}
|
|
22
317
|
raw(message) {
|
|
23
318
|
console.log(message);
|