@stalfh233/omc-cli 0.8.32 → 0.8.34
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/dist/arg-vocabulary.js +223 -0
- package/dist/artifact-cmd.js +443 -0
- package/dist/batch-call.js +56 -3
- package/dist/call-command.js +70 -0
- package/dist/call-execute.js +228 -0
- package/dist/call-input.js +557 -0
- package/dist/call-output.js +240 -0
- package/dist/cli.js +13 -1359
- package/dist/command-transport.js +4 -1
- package/dist/form-support.js +14 -3
- package/dist/intent/plan-apply.js +14 -24
- package/dist/lanes/datarule.js +21 -0
- package/dist/lanes/field-contract.js +1 -1
- package/dist/lanes/field.js +128 -1
- package/dist/lanes/list-view-shapes.js +8 -1
- package/dist/lanes/list-view.js +64 -2
- package/dist/lanes/runtime-data/aggregate-support.js +209 -0
- package/dist/lanes/runtime-data/aggregate.js +679 -0
- package/dist/lanes/runtime-data/field-options.js +52 -0
- package/dist/lanes/runtime-data/lane.js +4 -0
- package/dist/lanes/runtime-data/record-delete.js +419 -0
- package/dist/lanes/runtime-data/record-read.js +984 -0
- package/dist/lanes/runtime-data/record-write.js +562 -0
- package/dist/lanes/runtime-data/registration.js +22 -0
- package/dist/lanes/runtime-data/shapes.js +594 -0
- package/dist/lanes/runtime-data/submission.js +1304 -0
- package/dist/lanes/runtime-data/write-support.js +875 -0
- package/dist/lanes/runtime-data.js +10 -5590
- package/dist/lanes/workflow/approval-ops.js +983 -0
- package/dist/lanes/workflow/instance-read.js +284 -0
- package/dist/lanes/workflow/lifecycle-write.js +1499 -0
- package/dist/lanes/workflow/permissions.js +571 -0
- package/dist/lanes/workflow/recovery.js +361 -0
- package/dist/lanes/workflow/registration.js +14 -0
- package/dist/lanes/workflow/shapes.js +811 -0
- package/dist/lanes/workflow/template-fetch.js +197 -0
- package/dist/lanes/workflow/template-merge.js +1351 -0
- package/dist/lanes/workflow/template-read.js +327 -0
- package/dist/lanes/workflow.js +11 -6312
- package/dist/model-scaffold.js +6 -2
- package/dist/plan.js +23 -1
- package/dist/read-projection.js +442 -0
- package/dist/read.js +40 -335
- package/dist/rollback.js +17 -23
- package/dist/runtime-support.js +1 -1
- package/dist/verification.js +39 -0
- package/dist/write-coordinator.js +152 -0
- package/dist/write-outcome.js +295 -0
- package/dist/write.js +34 -115
- package/package.json +3 -3
- package/skills/omc-refusals.md +1 -1
- package/skills/omc-start-here.md +2 -2
package/dist/model-scaffold.js
CHANGED
|
@@ -409,6 +409,10 @@ export async function cmdModelScaffold(args) {
|
|
|
409
409
|
name,
|
|
410
410
|
fieldCount,
|
|
411
411
|
declaredFieldCount: fields.length,
|
|
412
|
+
// F3(探针 Y,0.8.34):fieldCount/publishedFields 是「父模型业务字段 + 子表列」
|
|
413
|
+
// 的合计口径。父子拆开给读数,避免把「子表列也算成父模型业务字段」。
|
|
414
|
+
publishedParentFieldCount: fields.length,
|
|
415
|
+
publishedChildColumnCount: childColumnCount,
|
|
412
416
|
createdFieldCount,
|
|
413
417
|
alreadyPresentFieldCount,
|
|
414
418
|
childColumnCount,
|
|
@@ -417,14 +421,14 @@ export async function cmdModelScaffold(args) {
|
|
|
417
421
|
? { childSchemas, childSchemaNote: "子表 schema code = 父 CHILD_TABLE 字段 code(平台规则):要 `pb_repair_items` 就把字段 code 命名为 `pb_repair_items`。" }
|
|
418
422
|
: {}),
|
|
419
423
|
failedFieldCount: failedFields.length,
|
|
420
|
-
countsNote: "declaredFieldCount = 本次 --fields 声明的顶层字段数;createdFieldCount = 本次真正新写入的业务字段数(子表 attach 一并建出的子列计入 created,不记 skipped);alreadyPresentFieldCount = 本次开始前就已存在的字段数;fieldCount = 最终业务字段总数(declaredFieldCount + childColumnCount
|
|
424
|
+
countsNote: "declaredFieldCount = 本次 --fields 声明的顶层字段数;publishedParentFieldCount = 父模型业务字段数(=declaredFieldCount);publishedChildColumnCount = 子表列数(=childColumnCount);createdFieldCount = 本次真正新写入的业务字段数(子表 attach 一并建出的子列计入 created,不记 skipped);alreadyPresentFieldCount = 本次开始前就已存在的字段数;fieldCount = 最终业务字段总数(declaredFieldCount + childColumnCount)——**publishedFields 是同一合计口径,别把它当成父模型业务字段数**,父字段数看 declaredFieldCount/publishedParentFieldCount。旧键 created/skipped 分别是 createdFieldCount/alreadyPresentFieldCount 的别名。",
|
|
421
425
|
created: createdFieldCount,
|
|
422
426
|
skipped: alreadyPresentFieldCount,
|
|
423
427
|
failed: failedFields.length,
|
|
424
428
|
...publishCounts,
|
|
425
429
|
publishNote: publishingBlocked || fieldPublishFailed
|
|
426
430
|
? "未发布字段(有失败或被跳过);精确状态用 field.list"
|
|
427
|
-
: `已执行 ${publishActions} 次模型级 field.publish(本次新建 ${publishCounts.fieldsPublishedEstimate}
|
|
431
|
+
: `已执行 ${publishActions} 次模型级 field.publish(本次新建 ${publishCounts.fieldsPublishedEstimate} 个字段随发布覆盖;父模型业务字段 ${fields.length} 个 + 子表列 ${childColumnCount} 个(合计 ${fieldCount})都在发布面;精确清单用 field.list --published)`,
|
|
428
432
|
...(failedFields.length > 0 ? { failedFields } : {}),
|
|
429
433
|
...(failedSteps.length > 0 ? { failedSteps } : {}),
|
|
430
434
|
...(lastSummaries.length > 0 ? { summaries: lastSummaries } : {}),
|
package/dist/plan.js
CHANGED
|
@@ -49,6 +49,17 @@ function smallStringPreview(value) {
|
|
|
49
49
|
}
|
|
50
50
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* F5(探针 Y,0.8.34):`formData` 的子表值是数组,`smallStringPreview` 只收标量,
|
|
54
|
+
* 于是 dry-run 静默省略子表行——调用方在提交前看不到「子表到底带了几行」。
|
|
55
|
+
* 只给 `{count, firstRow(标量, 400B 预算), omittedRows}`,不内联全部行;首行不是
|
|
56
|
+
* 对象/没有标量时不给 `firstRow`(不编造空对象)。
|
|
57
|
+
*/
|
|
58
|
+
function childRowsPreview(rows) {
|
|
59
|
+
const first = rows[0];
|
|
60
|
+
const firstRow = smallStringPreview(first);
|
|
61
|
+
return { count: rows.length, ...(firstRow !== undefined ? { firstRow } : {}), omittedRows: Math.max(0, rows.length - (firstRow !== undefined ? 1 : 0)) };
|
|
62
|
+
}
|
|
52
63
|
function summarizedArgs(tool, args) {
|
|
53
64
|
if (typeof args.summary === "string" && typeof args.fingerprint === "string")
|
|
54
65
|
return { ...args };
|
|
@@ -61,7 +72,18 @@ function summarizedArgs(tool, args) {
|
|
|
61
72
|
}
|
|
62
73
|
else if (Array.isArray(value) || (value && typeof value === "object") || typeof value === "string") {
|
|
63
74
|
summary[`${key}Summary`] = summarizeValue(value);
|
|
64
|
-
|
|
75
|
+
let preview = smallStringPreview(value);
|
|
76
|
+
// F5:formData 的子表行是数组;只给行数和首行标量,别静默吞掉。
|
|
77
|
+
if (key === "formData" && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
78
|
+
const childArrays = Object.entries(value).filter((entry) => Array.isArray(entry[1]));
|
|
79
|
+
if (childArrays.length > 0) {
|
|
80
|
+
preview ??= {};
|
|
81
|
+
for (const [childCode, rows] of childArrays.slice(0, 5))
|
|
82
|
+
preview[childCode] = childRowsPreview(rows);
|
|
83
|
+
if (childArrays.length > 5)
|
|
84
|
+
preview.omittedChildTables = childArrays.length - 5;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
65
87
|
if (preview !== undefined) {
|
|
66
88
|
// 探针 O F4(0.8.21):关联映射的方向是「写反即配置错」的核心,dry-run 的
|
|
67
89
|
// optionsPreview 必须能自查 source→target(原先只给 sha256 + 标量键)。
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { jsonBytes, summarizeValue } from "./support.js";
|
|
2
|
+
/**
|
|
3
|
+
* 读面投影 policy —— 三层投影的**单一真相源**(第一刀:只抽结构,行为零变化)。
|
|
4
|
+
*
|
|
5
|
+
* 读回执目前有三层投影,过去互不知道彼此:
|
|
6
|
+
*
|
|
7
|
+
* 1. `governedRead`(read.ts):原生结果 → 语义 diet(compact)/ 整包内联 /
|
|
8
|
+
* 外置到 detail artifact。哪一档由本文件的阈值与 keyset 决定。
|
|
9
|
+
* 2. `--jq` / `--extract`(path-projection.ts,出口在 call-output.ts):**只做
|
|
10
|
+
* 路径选择**,不改数据、不做预算判断(`--jq` 不是 jq)。
|
|
11
|
+
* 3. stdout 预算(command-transport.ts `boundResult`):信封已经定稿后才判断
|
|
12
|
+
* 最终字节,超预算整包外置成 stdout artifact。
|
|
13
|
+
*
|
|
14
|
+
* 顺序是契约:**artifact(读面 detail)→ 路径选择 → stdout 预算**。任何一层都不得
|
|
15
|
+
* 反向依赖另一层(`--jq` 不能因为「快超预算」改写路径结果;预算判定只看最终序列化
|
|
16
|
+
* 字节,不重新解释 bulky/码表语义)。
|
|
17
|
+
*
|
|
18
|
+
* 这一刀把第 1 层的常量与逐键判定收进 `ReadProjectionPolicy`:
|
|
19
|
+
* - `inlineKeys` ← 旧 `ALWAYS_INLINE_KEYS`(教学/证据键 + 字节上限)
|
|
20
|
+
* - `shapePreservingKeys` ← 旧 `CODE_NAME_LIST_KEYS`(保形为 `code|name` 码表)
|
|
21
|
+
* - `codeListKeys` ← 旧 `CODE_LIST_KEYS`(配置清单保形为裸码表)
|
|
22
|
+
* - `bulkyKeys` ← 旧 `BULKY_READ_KEYS`(压成 `*Count`,外置时补空占位)
|
|
23
|
+
* - `nonContainerKeys` ← 旧 `NON_CONTAINER_KEYS`(回执派生数组不算结果容器)
|
|
24
|
+
* - `containerKeys` ← 旧 `CONTAINER_NAME_KEYS` 的判定顺序
|
|
25
|
+
* - `custom` ← 逐键例外(`models` 回执行 / `rules` 瘦身 / activities)
|
|
26
|
+
*
|
|
27
|
+
* 阈值与分支顺序逐字节保持旧实现;lane 的 `compact` 仍由 `governedRead` 传入,
|
|
28
|
+
* 通过 `planReadProjection` 的 `customProjection` 适配,**没有**重写任何 lane。
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* 读面 diet 门:非小行集的读回超过它就只回语义投影 + detail artifact。
|
|
32
|
+
* 2026-11-01 预算批 v2(r38 实证):1–4KB 中结果 59 次/135KB≈37% 全内联,
|
|
33
|
+
* `model.inspect` 17 次全部卡在旧 4096 门下;降到 2048,配置清单仍保形为码表。
|
|
34
|
+
*/
|
|
35
|
+
export const READ_DIET_INLINE_BYTES = 2048;
|
|
36
|
+
/**
|
|
37
|
+
* `full:true` 的原生正文内联上限。超限时回语义投影 + artifact(见 read.ts 注释:
|
|
38
|
+
* `workflow.get_draft` 的 30–75KB 原生 blob 里可编辑形状 <1.5KB)。
|
|
39
|
+
*/
|
|
40
|
+
export const READ_FULL_INLINE_CEILING_BYTES = 8192;
|
|
41
|
+
/** `full:true` 的宽限:原生正文 ≤32KB 仍整包内联(r44fb 实测放宽)。 */
|
|
42
|
+
export const READ_FULL_RAW_CEILING_BYTES = 32768;
|
|
43
|
+
/** F3(w71 真机):单条记录不是「大列表」,与 items/logs 同列为小行集。 */
|
|
44
|
+
export const READ_LOAD_RECORD_INLINE_CEILING_BYTES = READ_FULL_INLINE_CEILING_BYTES;
|
|
45
|
+
/** 小行集:`items`/`logs` ≤10 行、`triggers` ≤60 行(0.6.97 真机:数据规则纳入后单模型可达 30+)。 */
|
|
46
|
+
export const READ_SMALL_ROW_SET_LIMIT = 10;
|
|
47
|
+
export const READ_TRIGGER_ROW_SET_LIMIT = 60;
|
|
48
|
+
/** `code|name` 码表的内联对数上限(~1–2KB);更大的清单回退 count + artifact。 */
|
|
49
|
+
export const READ_CODE_NAME_PAIR_LIMIT = 40;
|
|
50
|
+
/** `rules` 瘦身行的内联上限(r62b-F3:9 条连名字都看不到曾逼二次取回)。 */
|
|
51
|
+
export const READ_RULE_SLIM_LIMIT = 12;
|
|
52
|
+
/** 教学串(`*Hint`)的内联上限;超过才摘要(0.6.91 真机:209B hint 被摘要)。 */
|
|
53
|
+
export const READ_HINT_INLINE_CEILING_BYTES = 1200;
|
|
54
|
+
/** 「小对象原样内联」判据:≤4 键且 ≤200B(r28a:`applicationResolution` 是唯一证据)。 */
|
|
55
|
+
export const READ_SMALL_OBJECT_MAX_KEYS = 4;
|
|
56
|
+
export const READ_SMALL_OBJECT_MAX_BYTES = 200;
|
|
57
|
+
/**
|
|
58
|
+
* 2026-11-22(0.6.93 真机):compact 路径必须原样保留的**教学/证据**键及其上限
|
|
59
|
+
* (JSON 字节)。折叠它们只会把结论变成 `{count,sha256,omitted}`。
|
|
60
|
+
*/
|
|
61
|
+
const ALWAYS_INLINE_KEYS = new Map([
|
|
62
|
+
["notScanned", 2000],
|
|
63
|
+
["note", 1200],
|
|
64
|
+
["scanNote", 1200],
|
|
65
|
+
["doNot", 600],
|
|
66
|
+
["scanned", 600],
|
|
67
|
+
["coverage", 1200],
|
|
68
|
+
["applicationResolution", 600],
|
|
69
|
+
["summaryHint", 600],
|
|
70
|
+
]);
|
|
71
|
+
/** Config-inventory keys that compact to a code list (not a bare count). */
|
|
72
|
+
const CODE_LIST_KEYS = new Set(["fields", "columns", "conditions", "sorts", "datarules", "buttons", "views", "sheets"]);
|
|
73
|
+
/**
|
|
74
|
+
* 码不自解释的清单(2026-11-02 用户实测反馈):角色/模型/部门冷启动扫描
|
|
75
|
+
* 是刚需,但裸 code(SYS_1000000)不可读、全量 dump 又是 113×全字段的
|
|
76
|
+
* 上下文灾难——内联为 `code|name` 对,超大时仍回退 count+artifact。
|
|
77
|
+
*/
|
|
78
|
+
const CODE_NAME_LIST_KEYS = new Set(["roles", "groups", "models", "departments", "workflows", "services", "methods"]);
|
|
79
|
+
/** 节点类清单:参与者是扫描目标(r46 用户实测)——内联 `code:name@participant`。 */
|
|
80
|
+
const ACTIVITY_LIST_KEYS = new Set(["activities"]);
|
|
81
|
+
/**
|
|
82
|
+
* Keys whose values are the bulk a compact projection replaces with a count.
|
|
83
|
+
* Everything else is a small facet identity/decision fields (workflowCode,
|
|
84
|
+
* exists, published, id, code, schemaCode, note, …).
|
|
85
|
+
*/
|
|
86
|
+
const BULKY_READ_KEYS = new Set(["data", "nodes", "routes", "items", "rules", "applications", "foldersAndModels", "models"]);
|
|
87
|
+
/**
|
|
88
|
+
* 回执派生/诊断用数组不是「结果容器」:`failed[]`(部分失败清单)、`truncatedKeys`
|
|
89
|
+
* (被折叠的键名)这类在部分失败时可能比数据本身还长,按长度挑会挑错。
|
|
90
|
+
*/
|
|
91
|
+
const NON_CONTAINER_KEYS = new Set(["failed", "failures", "truncatedKeys", "omittedKeys", "changedKeys", "unknownKeys"]);
|
|
92
|
+
function codeOfEntry(entry) {
|
|
93
|
+
for (const key of ["propertyCode", "code", "schemaCode", "ruleCode", "fieldCode"]) {
|
|
94
|
+
const value = entry[key];
|
|
95
|
+
if (typeof value === "string" && value.length > 0)
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
function codeNameOfEntry(entry) {
|
|
101
|
+
const code = codeOfEntry(entry);
|
|
102
|
+
if (code === undefined)
|
|
103
|
+
return undefined;
|
|
104
|
+
const name = typeof entry.name === "string" && entry.name.length > 0 ? entry.name : undefined;
|
|
105
|
+
return name === undefined ? code : `${code}|${name}`;
|
|
106
|
+
}
|
|
107
|
+
function activityOfEntry(entry) {
|
|
108
|
+
const code = typeof entry.code === "string" && entry.code.length > 0 ? entry.code : typeof entry.activityCode === "string" ? entry.activityCode : undefined;
|
|
109
|
+
if (code === undefined)
|
|
110
|
+
return undefined;
|
|
111
|
+
const name = typeof entry.name === "string" && entry.name.length > 0 ? entry.name : "";
|
|
112
|
+
const participantRaw = entry.participant ?? entry.participants;
|
|
113
|
+
const participant = typeof participantRaw === "string" ? participantRaw : participantRaw && typeof participantRaw === "object" ? JSON.stringify(participantRaw) : "";
|
|
114
|
+
return `${code}${name ? `:${name}` : ""}${participant ? `@${participant.slice(0, 48)}` : ""}`;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 旧 `CONTAINER_NAME_KEYS` 的展开顺序:先常用容器名,再 keyset 的声明顺序。
|
|
118
|
+
* (顺序影响「没有非空对象数组」时的兜底选择。)
|
|
119
|
+
*/
|
|
120
|
+
function containerKeysOf(policy) {
|
|
121
|
+
return [
|
|
122
|
+
"items",
|
|
123
|
+
"models",
|
|
124
|
+
"rules",
|
|
125
|
+
"logs",
|
|
126
|
+
"triggers",
|
|
127
|
+
"fields",
|
|
128
|
+
"records",
|
|
129
|
+
...[...policy.bulkyKeys, ...policy.codeListKeys, ...policy.shapePreservingKeys, ...ACTIVITY_LIST_KEYS],
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 默认 policy 的逐键例外,逐字搬自 `compactReadback` 的三个具名分支。
|
|
134
|
+
* 分支顺序在旧实现里是「先保形后折叠」;这里保持同样的插入顺序。
|
|
135
|
+
*/
|
|
136
|
+
function defaultCustom(_result, ctx) {
|
|
137
|
+
const { key, value } = ctx;
|
|
138
|
+
if (key === "models" && Array.isArray(value) && value.length > 0 &&
|
|
139
|
+
typeof value[0] === "object" && value[0] !== null &&
|
|
140
|
+
"modelPresent" in value[0]) {
|
|
141
|
+
// r83:rule.list --schemaCodes[] 的 models[] 是**回执对象数组**(元素带
|
|
142
|
+
// modelPresent),不是码表——CODE_NAME_LIST_KEYS 会把它折成字符串数组,
|
|
143
|
+
// 跨模型回执不可用。保形:每元素留 schemaCode/modelPresent/rulesCount/
|
|
144
|
+
// customCount + rules 瘦身行(≤12,同顶层 rules 口径)。
|
|
145
|
+
return {
|
|
146
|
+
[key]: value.map((model) => {
|
|
147
|
+
const rules = Array.isArray(model.rules) ? model.rules : [];
|
|
148
|
+
return {
|
|
149
|
+
schemaCode: model.schemaCode ?? null,
|
|
150
|
+
modelPresent: model.modelPresent ?? null,
|
|
151
|
+
rulesCount: typeof model.rulesCount === "number" ? model.rulesCount : rules.length,
|
|
152
|
+
...(model.customCount !== undefined ? { customCount: model.customCount } : {}),
|
|
153
|
+
rules: rules.slice(0, READ_RULE_SLIM_LIMIT).map(slimRuleRow),
|
|
154
|
+
};
|
|
155
|
+
}),
|
|
156
|
+
[`${key}Count`]: value.length,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (key === "crossModelNotes" && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
160
|
+
// r83:跨模型面抬上来的三句提示(逐模型相同,只存一份)——原样保留,
|
|
161
|
+
// 不被通用对象分支摘要成 {keys}(否则默认面丢教学)。
|
|
162
|
+
return { [key]: value };
|
|
163
|
+
}
|
|
164
|
+
if (ACTIVITY_LIST_KEYS.has(key) && Array.isArray(value)) {
|
|
165
|
+
return {
|
|
166
|
+
[key]: value.map(activityOfEntry).filter((entry) => entry !== undefined),
|
|
167
|
+
[`${key}Count`]: value.length,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (key === "rules" && Array.isArray(value)) {
|
|
171
|
+
// r62b-F3(P1-10):rules 折叠成 `rules:[]`+artifact 曾逼探针二次取回——
|
|
172
|
+
// 9 条规则连名字都看不到。瘦身版 [{code,name,enabled,defaultRule}] ~40B/条,
|
|
173
|
+
// **≤12 条**内联(~500B);更大的清单保持外置语义。
|
|
174
|
+
const slim = value.length <= READ_RULE_SLIM_LIMIT ? value.map(slimRuleRow) : undefined;
|
|
175
|
+
return {
|
|
176
|
+
...(slim !== undefined ? { [key]: slim } : {}),
|
|
177
|
+
[`${key}Count`]: value.length,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
function slimRuleRow(rule) {
|
|
183
|
+
return {
|
|
184
|
+
code: typeof rule.code === "string" ? rule.code : null,
|
|
185
|
+
name: typeof rule.name === "string" ? rule.name : null,
|
|
186
|
+
...(rule.enabled !== undefined ? { enabled: rule.enabled } : {}),
|
|
187
|
+
...(rule.defaultRule !== undefined ? { defaultRule: rule.defaultRule } : {}),
|
|
188
|
+
// r83:rule.list --withMappings 的映射摘要随行保留(否则 >2048B 的常见
|
|
189
|
+
// 7 条预置规则会「开了 withMappings 却在默认面看不到映射」)。
|
|
190
|
+
...(Array.isArray(rule.mappings) ? { mappings: rule.mappings } : {}),
|
|
191
|
+
...(rule.mappingsUnavailable === true ? { mappingsUnavailable: true } : {}),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** 逐键通用投影(不含 `custom` 例外)。返回**要并入投影的键**,可含 `<key>Count`。 */
|
|
195
|
+
function projectGenericEntry(policy, key, value) {
|
|
196
|
+
if (policy.shapePreservingKeys.has(key) && Array.isArray(value)) {
|
|
197
|
+
const pairs = value.map(codeNameOfEntry).filter((entry) => entry !== undefined);
|
|
198
|
+
// 40 对上限(~1-2KB):更大的清单回退 count+artifact,保冷启动可扫又不失控
|
|
199
|
+
const projected = {};
|
|
200
|
+
if (pairs.length <= READ_CODE_NAME_PAIR_LIMIT)
|
|
201
|
+
projected[key] = pairs;
|
|
202
|
+
projected[`${key}Count`] = value.length;
|
|
203
|
+
return projected;
|
|
204
|
+
}
|
|
205
|
+
if (policy.codeListKeys.has(key) && Array.isArray(value)) {
|
|
206
|
+
// 2026-11-01 预算批 v2:读门 4096→2048 后,中结果(r38 实测 model.inspect
|
|
207
|
+
// 17 次 51KB 全部卡旧门下全内联)走 compact——配置清单类数组保形为码表
|
|
208
|
+
// (不是只给 count),否则 agent 被迫二次 artifact get 反加回合。
|
|
209
|
+
return {
|
|
210
|
+
[key]: value.map(codeOfEntry).filter((entry) => entry !== undefined),
|
|
211
|
+
[`${key}Count`]: value.length,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (policy.bulkyKeys.has(key)) {
|
|
215
|
+
return {
|
|
216
|
+
[`${key}Count`]: Array.isArray(value) ? value.length : value && typeof value === "object" ? Object.keys(value).length : 0,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// r28a 真机(2026-11-05)/ 2026-11-22(0.6.93 真机):见旧 read.ts 的一整段
|
|
220
|
+
// 说明——小对象、教学串、`*Hint` 都不该被摘要成 `{count/keys,sha256,omitted}`。
|
|
221
|
+
if (policy.inlineKeys.has(key) && jsonBytes(value) <= policy.inlineKeys.get(key)) {
|
|
222
|
+
return { [key]: value };
|
|
223
|
+
}
|
|
224
|
+
const small = value !== null && typeof value === "object" && !Array.isArray(value)
|
|
225
|
+
&& Object.keys(value).length <= READ_SMALL_OBJECT_MAX_KEYS
|
|
226
|
+
&& Buffer.byteLength(JSON.stringify(value), "utf8") <= READ_SMALL_OBJECT_MAX_BYTES;
|
|
227
|
+
if (small)
|
|
228
|
+
return { [key]: value };
|
|
229
|
+
if (typeof value === "string" && /Hint$/.test(key) && Buffer.byteLength(value, "utf8") <= READ_HINT_INLINE_CEILING_BYTES) {
|
|
230
|
+
return { [key]: value };
|
|
231
|
+
}
|
|
232
|
+
const summarized = summarizeValue(value);
|
|
233
|
+
return {
|
|
234
|
+
[key]: summarized !== null && typeof summarized === "object" && !Array.isArray(summarized)
|
|
235
|
+
? { ...summarized, omitted: true }
|
|
236
|
+
: summarized,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
let defaultPolicy;
|
|
240
|
+
/**
|
|
241
|
+
* 从旧 `read.ts` 常量构造的默认 policy(模块级单例——compact 是热路径,
|
|
242
|
+
* 不为每次读重建 keyset)。字段值与旧常量逐一对应,见单测。
|
|
243
|
+
*/
|
|
244
|
+
export function defaultReadProjectionPolicy() {
|
|
245
|
+
if (defaultPolicy !== undefined)
|
|
246
|
+
return defaultPolicy;
|
|
247
|
+
const base = {
|
|
248
|
+
inlineKeys: ALWAYS_INLINE_KEYS,
|
|
249
|
+
shapePreservingKeys: CODE_NAME_LIST_KEYS,
|
|
250
|
+
codeListKeys: CODE_LIST_KEYS,
|
|
251
|
+
bulkyKeys: BULKY_READ_KEYS,
|
|
252
|
+
nonContainerKeys: NON_CONTAINER_KEYS,
|
|
253
|
+
};
|
|
254
|
+
defaultPolicy = {
|
|
255
|
+
...base,
|
|
256
|
+
containerKeys: containerKeysOf(base),
|
|
257
|
+
custom: defaultCustom,
|
|
258
|
+
};
|
|
259
|
+
return defaultPolicy;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* 语义投影:逐键决定「保形 / 码表 / 折叠成 count / 摘要」。**不改阈值、不改
|
|
263
|
+
* 分支顺序**;`custom` 例外先于通用分支(旧实现里 `models` 回执行与 `rules`
|
|
264
|
+
* 分支的相对顺序也因此保持不变)。
|
|
265
|
+
*/
|
|
266
|
+
export function projectReadSemantics(result, policy = defaultReadProjectionPolicy()) {
|
|
267
|
+
const projected = {};
|
|
268
|
+
for (const [key, value] of Object.entries(result)) {
|
|
269
|
+
const custom = policy.custom?.(result, { key, value, projected, policy });
|
|
270
|
+
Object.assign(projected, custom !== undefined ? custom : projectGenericEntry(policy, key, value));
|
|
271
|
+
}
|
|
272
|
+
return projected;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 保形:外置结果与内联同形。compact 把 bulky 键折叠成 `*Count` 后,按内联形状
|
|
276
|
+
* 取数的脚本读 `result.items` / `result.data` 直接 TypeError——外置只是把数据
|
|
277
|
+
* 搬进 artifact,不应改变返回形状。被折叠的键补回空占位(数组→[],否则 null)
|
|
278
|
+
* 并标记 truncatedKeys;真实数据在 detailFile 指向的 artifact 里。
|
|
279
|
+
*/
|
|
280
|
+
export function externalizedShapePlaceholders(result, dropped) {
|
|
281
|
+
// r26b:什么都没折叠时不要宣称 `truncated:true`。
|
|
282
|
+
if (dropped.length === 0)
|
|
283
|
+
return {};
|
|
284
|
+
const placeholders = { truncatedKeys: [...dropped], omittedKeys: [...dropped], truncated: true };
|
|
285
|
+
for (const key of dropped)
|
|
286
|
+
placeholders[key] = Array.isArray(result[key]) ? [] : null;
|
|
287
|
+
// r57 真机(2026-11-12):`rules: []` 与 `truncated: true` 并置第一眼像
|
|
288
|
+
// 「0 条但被截断」——实际是「全在 artifact」。给一个机器可读标记。
|
|
289
|
+
placeholders.omittedShape = "artifact";
|
|
290
|
+
placeholders.omittedNote = "被折叠的键保留空占位(保形:脚本可直接 .length/.map),真实内容是完整数据,用 detailArtifactId 取;空占位不代表 0 条。";
|
|
291
|
+
return placeholders;
|
|
292
|
+
}
|
|
293
|
+
/** 旧 `droppedShapeKeys`:语义投影里没有出现的 bulky 键。 */
|
|
294
|
+
export function droppedShapeKeys(result, payload, policy = defaultReadProjectionPolicy()) {
|
|
295
|
+
return Object.keys(result).filter((key) => policy.bulkyKeys.has(key) && !(key in payload));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Carry the handler's small top-level facets through a compact projection.
|
|
299
|
+
* A lane's compact can drop scalar identity/decision keys — pass scalars through;
|
|
300
|
+
* the compact's own keys still win.
|
|
301
|
+
*/
|
|
302
|
+
export function passthroughScalars(result, omit = [], policy = defaultReadProjectionPolicy()) {
|
|
303
|
+
const carried = {};
|
|
304
|
+
for (const [key, value] of Object.entries(result)) {
|
|
305
|
+
if (key === "status" || policy.bulkyKeys.has(key) || omit.includes(key))
|
|
306
|
+
continue;
|
|
307
|
+
const type = typeof value;
|
|
308
|
+
if (value === null || type === "string" || type === "number" || type === "boolean")
|
|
309
|
+
carried[key] = value;
|
|
310
|
+
}
|
|
311
|
+
return carried;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* T1(GitLab #17):自定义 compact 用 `<key>Omitted` 声明「这段正文已外置」。
|
|
315
|
+
* `passthroughScalars` 会把字符串原样带回来,正好抵消外置;这里把省略声明
|
|
316
|
+
* 翻译成跳过名单。白名单化(审查 2026-11-04):只认 form 的八个布局面。
|
|
317
|
+
*/
|
|
318
|
+
const EXTERNALIZED_SCALAR_KEYS = new Set([
|
|
319
|
+
"draftViewJson",
|
|
320
|
+
"draftAttributesJson",
|
|
321
|
+
"draftHtmlJson",
|
|
322
|
+
"draftActionsJson",
|
|
323
|
+
"publishedViewJson",
|
|
324
|
+
"publishedAttributesJson",
|
|
325
|
+
"publishedHtmlJson",
|
|
326
|
+
"publishedActionsJson",
|
|
327
|
+
]);
|
|
328
|
+
export function omittedScalarKeys(compact) {
|
|
329
|
+
return Object.keys(compact)
|
|
330
|
+
.filter((key) => key.endsWith("Omitted") && compact[key] === true)
|
|
331
|
+
.map((key) => key.slice(0, -"Omitted".length))
|
|
332
|
+
.filter((key) => EXTERNALIZED_SCALAR_KEYS.has(key));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* C7(0.8.4,真机 issue 2026-11-25 §C7):同一个「本次结果的行集」在不同读面叫
|
|
336
|
+
* 不同名字——`data.list.items` / `model.list.models` / `rule.list.rules` /
|
|
337
|
+
* `servicelog.logs` / `field.list.fields`。不改既有键名,改为在通用读回执处回
|
|
338
|
+
* `resultMeta.containerKey`(必要时 `containerPath`)。
|
|
339
|
+
*
|
|
340
|
+
* 判定规则(按顺序,输出稳定):
|
|
341
|
+
* 1. 顶层「元素是对象的非空数组」里,取元素最多者(并列取声明顺序在前者)。
|
|
342
|
+
* 2. 都没有时,在 policy 的容器名顺序里取第一个仍在结果中的数组键——覆盖被
|
|
343
|
+
* diet 折叠成空占位的读面(`items: []` + `itemsCount`)。
|
|
344
|
+
* 3. 单层包装:`{records:{...,content:[]}}` → `containerPath:"records.content"`。
|
|
345
|
+
* 4. 都不成立就不回(不猜)。
|
|
346
|
+
*/
|
|
347
|
+
export function containerKeyOf(result, policy = defaultReadProjectionPolicy()) {
|
|
348
|
+
if (result === null || typeof result !== "object" || Array.isArray(result))
|
|
349
|
+
return undefined;
|
|
350
|
+
const record = result;
|
|
351
|
+
const arrays = Object.entries(record).filter(([key, value]) => Array.isArray(value) && !policy.nonContainerKeys.has(key));
|
|
352
|
+
const objectArrays = arrays.filter(([, value]) => value.length > 0 && value[0] !== null && typeof value[0] === "object" && !Array.isArray(value[0]));
|
|
353
|
+
if (objectArrays.length > 0) {
|
|
354
|
+
const [key] = objectArrays.reduce((best, entry) => (entry[1].length > best[1].length ? entry : best));
|
|
355
|
+
return { key };
|
|
356
|
+
}
|
|
357
|
+
for (const name of policy.containerKeys) {
|
|
358
|
+
if (arrays.some(([key]) => key === name))
|
|
359
|
+
return { key: name };
|
|
360
|
+
}
|
|
361
|
+
// 分页壳:`{records:{totalElements,content:[…]}}` —— 容器在下一层。
|
|
362
|
+
for (const [key, value] of Object.entries(record)) {
|
|
363
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.content))
|
|
364
|
+
return { key, path: `${key}.content` };
|
|
365
|
+
}
|
|
366
|
+
return undefined;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 外置判断(原 `read.ts` 的 `smallRowSet` / `large` / full 三分支,逐字搬运)。
|
|
370
|
+
*
|
|
371
|
+
* 注意:判断必须**先于**语义投影——阈值定义在原生结果上(`jsonBytes(result)`),
|
|
372
|
+
* 投影是判断结果为「外置」之后才付的成本。管线概念顺序仍是
|
|
373
|
+
* 语义投影 → 保形 → 外置(见 `projectReadResult`),但阈值判定可以提前。
|
|
374
|
+
*/
|
|
375
|
+
export function decideReadExternalization(result, input) {
|
|
376
|
+
const bytes = jsonBytes(result);
|
|
377
|
+
const smallItems = Array.isArray(result.items) && result.items.length <= READ_SMALL_ROW_SET_LIMIT;
|
|
378
|
+
const smallLogs = Array.isArray(result.logs) && result.logs.length <= READ_SMALL_ROW_SET_LIMIT;
|
|
379
|
+
const smallTriggers = Array.isArray(result.triggers) && result.triggers.length <= READ_TRIGGER_ROW_SET_LIMIT;
|
|
380
|
+
// F3(w71):单条记录(data.load)在 8192B 内联上限内不外置;缺席
|
|
381
|
+
// (exists:false)没有记录可外置,保持既有形状。
|
|
382
|
+
const loadRecord = input.toolName === "data.load" && result.exists !== false && bytes <= READ_LOAD_RECORD_INLINE_CEILING_BYTES;
|
|
383
|
+
const smallRowSet = smallItems || smallLogs || smallTriggers || loadRecord;
|
|
384
|
+
if (input.full === true) {
|
|
385
|
+
if (bytes <= READ_FULL_INLINE_CEILING_BYTES || smallRowSet || bytes <= READ_FULL_RAW_CEILING_BYTES) {
|
|
386
|
+
return {
|
|
387
|
+
inline: true,
|
|
388
|
+
reason: bytes <= READ_FULL_INLINE_CEILING_BYTES ? "full-under-ceiling" : smallRowSet ? "small-row-set" : "full-under-ceiling",
|
|
389
|
+
bytes,
|
|
390
|
+
smallRowSet,
|
|
391
|
+
limit: READ_FULL_RAW_CEILING_BYTES,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return { inline: false, reason: "full-over-ceiling", bytes, smallRowSet, limit: READ_FULL_RAW_CEILING_BYTES };
|
|
395
|
+
}
|
|
396
|
+
if (smallRowSet) {
|
|
397
|
+
return {
|
|
398
|
+
inline: true,
|
|
399
|
+
reason: loadRecord && !smallItems && !smallLogs && !smallTriggers ? "load-record" : "small-row-set",
|
|
400
|
+
bytes,
|
|
401
|
+
smallRowSet,
|
|
402
|
+
limit: READ_LOAD_RECORD_INLINE_CEILING_BYTES,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (bytes <= READ_DIET_INLINE_BYTES) {
|
|
406
|
+
return { inline: true, reason: "under-diet-budget", bytes, smallRowSet, limit: READ_DIET_INLINE_BYTES };
|
|
407
|
+
}
|
|
408
|
+
return { inline: false, reason: "diet-over-budget", bytes, smallRowSet, limit: READ_DIET_INLINE_BYTES };
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 语义投影 → 保形 → 外置 的纯管线(不含 artifact/缓存/信封)。
|
|
412
|
+
*
|
|
413
|
+
* 外置判断在这里**只决定要不要投影**(阈值基于原生结果),投影与占位的内容
|
|
414
|
+
* 与外置档完全一致:被 bulky 键折叠掉的数据一律补空占位并指向 artifact。
|
|
415
|
+
*/
|
|
416
|
+
export function projectReadResult(result, options) {
|
|
417
|
+
const decision = decideReadExternalization(result, options);
|
|
418
|
+
if (decision.inline)
|
|
419
|
+
return { decision };
|
|
420
|
+
const policy = options.policy ?? defaultReadProjectionPolicy();
|
|
421
|
+
const payload = options.customProjection !== undefined
|
|
422
|
+
? options.customProjection(result)
|
|
423
|
+
: projectReadSemantics(result, policy);
|
|
424
|
+
const placeholders = externalizedShapePlaceholders(result, droppedShapeKeys(result, payload, policy));
|
|
425
|
+
return { decision, projection: { payload, placeholders } };
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* stdout 预算的唯一字节判定(供 `command-transport.boundResult` 复用)。
|
|
429
|
+
*
|
|
430
|
+
* 边界:调用方已经完成 read 面 artifact 内联/外置与 `--jq` 路径选择,这里只
|
|
431
|
+
* 比较**最终序列化后**的字节——预算层不重新解释 bulky/码表语义,也不改路径
|
|
432
|
+
* 选择的结果。
|
|
433
|
+
*/
|
|
434
|
+
export function fitsStdoutBudget(serialized, budgetBytes) {
|
|
435
|
+
return Buffer.byteLength(serialized, "utf8") <= budgetBytes;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* 三层投影的顺序契约(测试钉住顺序)。不是运行时常量消费点,而是给读代码的人
|
|
439
|
+
* 与回归测试的**单一陈述**:任何一层换序都会改变 `--jq` 视野或外置阈值。
|
|
440
|
+
*/
|
|
441
|
+
export const READ_PROJECTION_STAGES = ["artifact", "path", "stdout-budget"];
|
|
442
|
+
//# sourceMappingURL=read-projection.js.map
|