@stalfh233/omc-cli 0.8.32 → 0.8.33
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.js +31 -0
- 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 +1293 -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/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
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { chmodSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CLI_EXIT_CODES, errorEnvelope } from "./cli-contract.js";
|
|
4
|
+
import { writeEnvelope } from "./cli-output.js";
|
|
5
|
+
import { artifactFetchHint, artifactRoot, emitTransportResult, readArtifact } from "./command-transport.js";
|
|
6
|
+
import { assertSafeOutputPath } from "./artifacts.js";
|
|
7
|
+
import { intentConfigRoot } from "./intent/cli.js";
|
|
8
|
+
import { PATH_MISS_HELP_REF, SHAPE_MAX_DEPTH, UNSUPPORTED_JQ_OBJECT_HINT, artifactPathMissHint, nullProjectionHint, partialPathMissHint, pathMissCopyableHint, pathMissCopyablePaths, pathMissCrossFaceCorrection, pathMissDidYouMean, projectJsonPath, projectJsonPathFanout, shapeOf, } from "./path-projection.js";
|
|
9
|
+
/**
|
|
10
|
+
* `omc artifact get`:读回产物的取回面。
|
|
11
|
+
*
|
|
12
|
+
* 与 `omc call` 的 `--jq/--extract` 共用同一套路径 DSL 与 pathMiss 纠错面
|
|
13
|
+
* (path-projection 是单一实现):单路径命中、`[]` 扇出、多路径、键表、骨架、
|
|
14
|
+
* 整包预算与落盘都在这里。它**不**解析 argv,也不写 call 的信封——入口只把
|
|
15
|
+
* id/transport/options 交进来。
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Above this size `omc artifact get` returns the outline, not the body. The
|
|
19
|
+
* transport cap (64 KB) is far too generous for a working context: one 27 KB
|
|
20
|
+
* template re-read three times is 81 KB of the session.
|
|
21
|
+
*/
|
|
22
|
+
const ARTIFACT_INLINE_CEILING_BYTES = 8192;
|
|
23
|
+
/**
|
|
24
|
+
* issue 2026-11 F3:默认骨架不是限流——同一句话必须同时出现在 `hint` 与顶层
|
|
25
|
+
* `message`(并列通道同源),否则只看 message 的程序化消费方会误判。
|
|
26
|
+
*/
|
|
27
|
+
function artifactOutlineHint(id, bytes, depth) {
|
|
28
|
+
return `正文 ${Math.round(bytes / 1024)}KB 超过内联上限 ${ARTIFACT_INLINE_CEILING_BYTES}B,默认只回深度 ${depth} 骨架(键/类型/数组长度/示例值),不是输出限流。加深:--depth ≤${SHAPE_MAX_DEPTH};子树骨架:--shape <path>;取键:--keys <a,b>;取路径:--jq '<path>';整包:--full 或 --out <配置根内路径>;只元数据:--meta。`;
|
|
29
|
+
}
|
|
30
|
+
function artifactDefaultMetadata(id, bytes, content, depth) {
|
|
31
|
+
return {
|
|
32
|
+
status: "ok",
|
|
33
|
+
artifactId: id,
|
|
34
|
+
bytes,
|
|
35
|
+
outline: true,
|
|
36
|
+
depth,
|
|
37
|
+
shape: shapeOf(content, depth),
|
|
38
|
+
hint: artifactOutlineHint(id, bytes, depth),
|
|
39
|
+
message: artifactOutlineHint(id, bytes, depth),
|
|
40
|
+
fullCommand: `omc artifact get ${id} --full`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function projectArtifactPath(value, path) {
|
|
44
|
+
if (!path.includes("[]")) {
|
|
45
|
+
const projected = projectJsonPath(value, path);
|
|
46
|
+
return projected.missed
|
|
47
|
+
? { missed: true, ...(projected.unsupportedSyntax === true ? { unsupportedSyntax: true } : {}), ...(projected.at !== undefined ? { at: projected.at } : {}), ...(projected.available !== undefined ? { available: projected.available } : {}), ...(projected.availableAll !== undefined ? { availableAll: projected.availableAll } : {}), ...(projected.availableTruncated !== undefined ? { availableTruncated: projected.availableTruncated } : {}) }
|
|
48
|
+
: { missed: false, content: projected.value ?? null };
|
|
49
|
+
}
|
|
50
|
+
const fanout = projectJsonPathFanout(value, path);
|
|
51
|
+
return fanout.missed
|
|
52
|
+
? { missed: true, ...(fanout.at !== undefined ? { at: fanout.at } : {}), ...(fanout.available !== undefined ? { available: fanout.available } : {}), ...(fanout.availableAll !== undefined ? { availableAll: fanout.availableAll } : {}), ...(fanout.availableTruncated !== undefined ? { availableTruncated: fanout.availableTruncated } : {}) }
|
|
53
|
+
: { missed: false, content: fanout.values, mapped: fanout.values.length, ...(fanout.missedEntries > 0 ? { missedEntries: fanout.missedEntries } : {}), nullEntries: fanout.nullEntries, nonNullEntries: fanout.nonNullEntries };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* C3(0.8.4):artifact 面**唯一**的 miss 条目构造器——`call` 面(projectResultExtract
|
|
57
|
+
* 的 extract[])同形:路径未命中 → `path`/`content:null`/`pathMiss`/`missedAt`/
|
|
58
|
+
* (didYouMean|helpRef)(--explain 才带 available/correctPath/nextCommand/hint);
|
|
59
|
+
* 不支持语法 → `pathMiss:false` + `unsupportedSyntax:true`(不是「键不存在」)。
|
|
60
|
+
* 三处(裸 --jq / --summary --jq / --shape <path>)此前各写一份,容易再分叉。
|
|
61
|
+
*/
|
|
62
|
+
function artifactMissEntry(path, projected, content, artifactId, explainMiss) {
|
|
63
|
+
if (projected.unsupportedSyntax === true) {
|
|
64
|
+
return {
|
|
65
|
+
path,
|
|
66
|
+
content: null,
|
|
67
|
+
pathMiss: false,
|
|
68
|
+
unsupportedSyntax: true,
|
|
69
|
+
unanswered: true,
|
|
70
|
+
available: projected.available,
|
|
71
|
+
hint: UNSUPPORTED_JQ_OBJECT_HINT,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
path,
|
|
76
|
+
content: null,
|
|
77
|
+
pathMiss: true,
|
|
78
|
+
...(projected.at !== undefined ? { missedAt: projected.at } : {}),
|
|
79
|
+
...artifactMissFields(projected, explainMiss),
|
|
80
|
+
...(explainMiss ? artifactMissCorrection(content, path, projected.at, artifactId) : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* F1/F2(retro 21/22,ticket 138):artifact 面 pathMiss 的机器可读纠错面——
|
|
85
|
+
* `correctPath`(已验证可解析)+ `helpRef`(教程指针)+ 可整段复制的重跑命令。
|
|
86
|
+
* 与 call 面(projectResultExtract)同一套推导(拼写近似走 didYouMean 字段,
|
|
87
|
+
* 这里只补跨面改写与同名键两条**全路径**推导),推导不出就全部缺席(不编造)。
|
|
88
|
+
*/
|
|
89
|
+
function artifactMissCorrection(content, path, at, artifactId) {
|
|
90
|
+
const correction = pathMissCrossFaceCorrection(content, path, at) ?? (() => {
|
|
91
|
+
const copyable = pathMissCopyablePaths(content, path, at, 1);
|
|
92
|
+
return copyable.length > 0 ? { correctPath: copyable[0] } : undefined;
|
|
93
|
+
})();
|
|
94
|
+
return {
|
|
95
|
+
...(correction !== undefined ? { correctPath: correction.correctPath } : {}),
|
|
96
|
+
helpRef: PATH_MISS_HELP_REF,
|
|
97
|
+
...(correction !== undefined ? { nextCommand: `omc artifact get ${artifactId} --jq '${correction.correctPath.replace(/'/g, "'\\''")}'` } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** Preserve source completeness/count facts on every artifact projection. */
|
|
101
|
+
function artifactProjectionMetadata(value) {
|
|
102
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
103
|
+
return {};
|
|
104
|
+
const record = value;
|
|
105
|
+
const metadata = {};
|
|
106
|
+
for (const key of ["truncated", "truncatedKeys", "itemsCount", "total"]) {
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(record, key))
|
|
108
|
+
metadata[key] = record[key];
|
|
109
|
+
}
|
|
110
|
+
return metadata;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* T6(GitLab #17):`mapped`/`nullEntries` 的读法要跟数据一起走,否则 `mapped:5`
|
|
114
|
+
* 会被读成"取到 5 个值"。文案的单一真相源在 path-projection(与 `--extract`
|
|
115
|
+
* 面共用),这里只负责从产物内容算 total。
|
|
116
|
+
*/
|
|
117
|
+
function artifactNullHint(content, nullEntries) {
|
|
118
|
+
const total = Array.isArray(content) ? content.length : 0;
|
|
119
|
+
return nullProjectionHint(nullEntries, total);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* r73 #7(GitLab #40 P1):从 `omc artifact get <id> --out <path>` 的 argv 里截出
|
|
123
|
+
* `--out` 并原地摘除那两个 token,让 configureOutput / stripOutputFlags 的全局
|
|
124
|
+
* 信封重定向语义不再吃掉它。只对 `artifact get` 子命令生效;缺值/flag 形值与
|
|
125
|
+
* configureOutput 同规则拒绝(invalid-input)。返回截得的路径,未出现则 undefined。
|
|
126
|
+
*/
|
|
127
|
+
export function extractArtifactGetOutFlag(argv) {
|
|
128
|
+
const tokens = argv.slice(2);
|
|
129
|
+
if (tokens[0] !== "artifact" || tokens[1] !== "get")
|
|
130
|
+
return undefined;
|
|
131
|
+
for (let index = 2; index < argv.length; index += 1) {
|
|
132
|
+
const token = argv[index];
|
|
133
|
+
if (token === "--out") {
|
|
134
|
+
const value = argv[index + 1];
|
|
135
|
+
if (value === undefined || value.startsWith("--"))
|
|
136
|
+
throw new Error("--out requires a file path");
|
|
137
|
+
argv.splice(index, 2);
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
if (token.startsWith("--out=")) {
|
|
141
|
+
const value = token.slice("--out=".length);
|
|
142
|
+
if (value.length === 0)
|
|
143
|
+
throw new Error("--out requires a file path");
|
|
144
|
+
argv.splice(index, 1);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/** artifact 面 pathMiss 的 didYouMean/截断计数附加字段(r75:与 call 面一致)。 */
|
|
151
|
+
/**
|
|
152
|
+
* C6(0.8.4):artifact 面 miss 的默认载荷与 call 面同口径——只留
|
|
153
|
+
* `didYouMean` + `helpRef`;`available`(该层全部键)/`availableTruncated`
|
|
154
|
+
* 只在显式 `--explain` 时给(排查载荷不再每次吃 600–1200B)。
|
|
155
|
+
*/
|
|
156
|
+
function artifactMissFields(projected, explain) {
|
|
157
|
+
const didYouMean = pathMissDidYouMean(projected.at, projected.available, projected.availableAll);
|
|
158
|
+
return {
|
|
159
|
+
...(didYouMean !== undefined ? { didYouMean } : {}),
|
|
160
|
+
helpRef: PATH_MISS_HELP_REF,
|
|
161
|
+
...(explain
|
|
162
|
+
? {
|
|
163
|
+
available: projected.available,
|
|
164
|
+
...(projected.availableTruncated !== undefined ? { availableTruncated: projected.availableTruncated } : {}),
|
|
165
|
+
}
|
|
166
|
+
: {}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export async function cmdArtifactGet(id, transport, options = {}) {
|
|
170
|
+
const explainMiss = options.explain === true;
|
|
171
|
+
try {
|
|
172
|
+
if (options.depth !== undefined && (!Number.isInteger(options.depth) || options.depth < 1 || options.depth > SHAPE_MAX_DEPTH)) {
|
|
173
|
+
const parsed = errorEnvelope(new Error(`--depth 必须是 1-${SHAPE_MAX_DEPTH} 的整数(默认 2;再深就成了正文复刻,字节失控)`), "artifact-depth-invalid", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
174
|
+
writeEnvelope(parsed.envelope);
|
|
175
|
+
return parsed.exitCode;
|
|
176
|
+
}
|
|
177
|
+
const artifact = readArtifact(artifactRoot(), id);
|
|
178
|
+
let content;
|
|
179
|
+
try {
|
|
180
|
+
content = JSON.parse(artifact.content.toString("utf8"));
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
content = artifact.content.toString("utf8");
|
|
184
|
+
}
|
|
185
|
+
// r73 #7(GitLab #40 P1,2026-11-17):`--out <配置根内路径>` 把 artifact 原始
|
|
186
|
+
// 正文**全量落盘**——写文件不走 stdout 限额,`--full` 被上限卡死(fullRejected)
|
|
187
|
+
// 的大对象(实测 589KB 视图 artifact)此前只能拆 key 取、易漏。这里写的是已过
|
|
188
|
+
// sha256 校验的原文字节;回执只给 {out,bytes,sha256},stdout 不回正文。
|
|
189
|
+
if (options.out !== undefined) {
|
|
190
|
+
// issue 06(retro 2026-11-19):`--out -` 想把正文直接打到 stdout——铁律是
|
|
191
|
+
// stdout 恒为恰好一个 JSON envelope,混排正文字节会破坏所有脚本解析,不做。
|
|
192
|
+
// 错误里给两步替代(根内落盘 + cat),用户照抄即可。
|
|
193
|
+
if (options.out === "-") {
|
|
194
|
+
const sample = join(intentConfigRoot(), "artifacts-out", `${id}.json`);
|
|
195
|
+
const parsed = errorEnvelope(new Error(`artifact get --out - 不支持:stdout 必须恒为恰好一个 JSON envelope(铁律),不能把产物正文字节混排在信封外。一次性提取两步:① omc artifact get ${id} --out ${sample}(父目录会自动创建)② cat ${sample}`), "artifact-out-refused", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
196
|
+
writeEnvelope(parsed.envelope);
|
|
197
|
+
return parsed.exitCode;
|
|
198
|
+
}
|
|
199
|
+
let outPath;
|
|
200
|
+
try {
|
|
201
|
+
outPath = assertSafeOutputPath(intentConfigRoot(), options.out, "artifact output file");
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
205
|
+
const parsed = errorEnvelope(new Error(`artifact get --out 落盘被拒:${detail}。--out 按配置根(OMC_CONFIG_HOME)解析,只允许配置根内的常规文件路径;根内父目录会自动创建,配置根外(含系统临时目录)一律拒绝`), "artifact-out-refused", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
206
|
+
writeEnvelope(parsed.envelope);
|
|
207
|
+
return parsed.exitCode;
|
|
208
|
+
}
|
|
209
|
+
writeFileSync(outPath, artifact.content, { mode: 0o600 });
|
|
210
|
+
chmodSync(outPath, 0o600);
|
|
211
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, out: options.out, mode: "0600" }, transport);
|
|
212
|
+
}
|
|
213
|
+
// `--path-only` deliberately does NOT return the local path: the Agent-facing
|
|
214
|
+
// CLI contract forbids exposing local filesystem paths. It returns the fetch
|
|
215
|
+
// command instead, which is the portable way to reach the body.
|
|
216
|
+
if (options.pathOnly)
|
|
217
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, fetch: artifactFetchHint(id) }, transport);
|
|
218
|
+
// --meta is the stable metadata-only choice. It deliberately never returns
|
|
219
|
+
// the body, including for small artifacts whose default face is inline.
|
|
220
|
+
if (options.meta === true) {
|
|
221
|
+
const depth = options.depth ?? 2;
|
|
222
|
+
return emitTransportResult({
|
|
223
|
+
...artifactDefaultMetadata(id, artifact.content.length, content, depth),
|
|
224
|
+
sha256: artifact.sha256,
|
|
225
|
+
projectionRule: "投影要写到叶子(数组元素里的字段);取值用 --jq <path> 或 --keys <a,b>",
|
|
226
|
+
projectionExample: `omc artifact get ${id} --jq '<path>'`,
|
|
227
|
+
}, transport);
|
|
228
|
+
}
|
|
229
|
+
// r75 调查C:`--shape [path]` 回执形状先验——深度受限骨架(默认 2,--depth 可
|
|
230
|
+
// 到 4)。--summary 是预算事实(多大/会不会截断),--shape 是导航图(嵌套骨架
|
|
231
|
+
// 到哪层有哪些键);>8KB 默认 outline 与本分支共用同一份 shapeOf(单一真相源,
|
|
232
|
+
// 防 r25「两面雷同」复发)。显式 --shape 优先于 --summary/--keys/--jq。
|
|
233
|
+
if (options.shape !== undefined) {
|
|
234
|
+
const depth = options.depth ?? 2;
|
|
235
|
+
if (typeof options.shape === "string" && options.shape.trim() !== "") {
|
|
236
|
+
// `--shape <path>`:在命中的子树上出骨架(同 --jq 的路径 DSL,含 [] 与 [code=X])。
|
|
237
|
+
const projected = projectArtifactPath(artifact.content.toString("utf8") === "" ? undefined : content, options.shape);
|
|
238
|
+
if (projected.missed) {
|
|
239
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), ...artifactMissEntry(options.shape, projected, content, id, explainMiss), unanswered: true, ...(explainMiss && projected.unsupportedSyntax !== true ? { hint: artifactPathMissHint(projected.at, pathMissCopyableHint(content, options.shape, projected.at)) } : {}) }, transport);
|
|
240
|
+
}
|
|
241
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, path: options.shape, depth, shape: shapeOf(projected.content, depth), fetch: artifactFetchHint(id) }, transport);
|
|
242
|
+
}
|
|
243
|
+
// 裸 `--shape`:整棵根的骨架。<8KB 的产物正本默认整体内联,骨架无增益——
|
|
244
|
+
// 明确劝退(r38 模式:别为已经免费的东西花第二轮)。
|
|
245
|
+
const smallBody = artifact.content.length <= ARTIFACT_INLINE_CEILING_BYTES;
|
|
246
|
+
return emitTransportResult({
|
|
247
|
+
status: "ok",
|
|
248
|
+
artifactId: id,
|
|
249
|
+
sha256: artifact.sha256,
|
|
250
|
+
bytes: artifact.content.length,
|
|
251
|
+
depth,
|
|
252
|
+
shape: shapeOf(content, depth),
|
|
253
|
+
...(smallBody
|
|
254
|
+
? { shapeNote: `产物 ${artifact.content.length}B 未超过内联上限 ${ARTIFACT_INLINE_CEILING_BYTES}B:默认 get 本就整体内联正文,--shape 无增益;直接取正文或 --jq <path> 定向取值`, defaultCommand: `omc artifact get ${id}` }
|
|
255
|
+
: { fetch: artifactFetchHint(id) }),
|
|
256
|
+
}, transport);
|
|
257
|
+
}
|
|
258
|
+
// `--summary` / `--keys` (round 4): inspect a large artifact without pulling
|
|
259
|
+
// its whole body. Reproduced benchmark: agents fetched 30–75 KB workflow
|
|
260
|
+
// bodies just to look at the node list.
|
|
261
|
+
if (options.summary) {
|
|
262
|
+
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
263
|
+
const keys = record ? Object.entries(record).map(([key, value]) => ({ key, bytes: Buffer.byteLength(JSON.stringify(value) ?? "null", "utf8"), kind: Array.isArray(value) ? `array[${value.length}]` : value === null ? "null" : typeof value })).sort((left, right) => right.bytes - left.bytes) : [];
|
|
264
|
+
// r25 真机(2026-11-04):`--summary` 与裸 `--keys` 曾输出逐字相同(各 878 B),
|
|
265
|
+
// 但 fetch 提示写「--summary(再 --keys/--jq)」暗示递进——探针白跑一次。
|
|
266
|
+
// 现在 `--summary` 多给一眼"要花多少/会不会被截断",`--keys` 保持纯 key 表。
|
|
267
|
+
const shapeFacts = {
|
|
268
|
+
bytes: artifact.content.length,
|
|
269
|
+
...(record ? { topLevelKeys: keys.length } : {}),
|
|
270
|
+
overInlineCeiling: artifact.content.length > ARTIFACT_INLINE_CEILING_BYTES,
|
|
271
|
+
...(record ? {} : { kind: Array.isArray(content) ? `array[${content.length}]` : typeof content }),
|
|
272
|
+
};
|
|
273
|
+
// `--summary --jq <path>`: shape AND the one value, in a single call. Without
|
|
274
|
+
// this the caller had to spend one round on the shape and another on the
|
|
275
|
+
// path (or pull the whole body); r5 hit that on 67 KB workflow templates.
|
|
276
|
+
if (options.jq !== undefined) {
|
|
277
|
+
const projected = projectArtifactPath(artifact.content.toString("utf8") === "" ? undefined : content, options.jq);
|
|
278
|
+
// T1(GitLab #17):形状 + 值 + 键表是**同一层**的三件事实,不再把值多套
|
|
279
|
+
// 一层 `projection:{path,content}`——`artifact get --jq` 与 `--summary --jq`
|
|
280
|
+
// 因此同形(顶层 path/content),换读面不用重新探根键。
|
|
281
|
+
return emitTransportResult(projected.missed
|
|
282
|
+
? (() => {
|
|
283
|
+
const miss = artifactMissEntry(options.jq, projected, content, id, explainMiss);
|
|
284
|
+
return { status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, ...artifactProjectionMetadata(content), keys, ...miss, projections: [miss], unanswered: true, ...(explainMiss && projected.unsupportedSyntax !== true ? { hint: artifactPathMissHint(projected.at, pathMissCopyableHint(content, options.jq, projected.at)) } : {}) };
|
|
285
|
+
})()
|
|
286
|
+
: {
|
|
287
|
+
status: "ok",
|
|
288
|
+
artifactId: id,
|
|
289
|
+
sha256: artifact.sha256,
|
|
290
|
+
bytes: artifact.content.length,
|
|
291
|
+
...artifactProjectionMetadata(content),
|
|
292
|
+
keys,
|
|
293
|
+
path: options.jq,
|
|
294
|
+
projections: [{ path: options.jq, content: projected.content ?? null, ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}), ...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}) }],
|
|
295
|
+
...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}),
|
|
296
|
+
...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}),
|
|
297
|
+
...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}),
|
|
298
|
+
...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}),
|
|
299
|
+
...(artifactNullHint(projected.content, projected.nullEntries) !== undefined ? { hint: artifactNullHint(projected.content, projected.nullEntries) } : {}),
|
|
300
|
+
}, transport);
|
|
301
|
+
}
|
|
302
|
+
// 裸 `--keys` / 裸 `--jq` 只要键表(`pureKeys`),不带 summary 的形状事实——
|
|
303
|
+
// 两者要有可见差异,否则 fetch 提示里的「--summary(再 --keys)」就是误导。
|
|
304
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...(options.pureKeys === true ? {} : { summary: shapeFacts }), keys, fetch: artifactFetchHint(id) }, transport);
|
|
305
|
+
}
|
|
306
|
+
if (options.keys !== undefined) {
|
|
307
|
+
// Round 15: tolerate a `result.`/`data.` prefix and report missing keys.
|
|
308
|
+
// bench63 tried `--keys result.publishedAttributesJson` (empty) before
|
|
309
|
+
// `--keys publishedAttributesJson` worked; the artifact content IS the
|
|
310
|
+
// result object, so a leading envelope prefix is a no-op the caller does
|
|
311
|
+
// not expect. Strip it, and when a key truly is absent list the real
|
|
312
|
+
// top-level keys so the next call is correct.
|
|
313
|
+
const wanted = options.keys.split(",").map((key) => key.trim()).filter(Boolean);
|
|
314
|
+
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
315
|
+
const projected = {};
|
|
316
|
+
const missing = [];
|
|
317
|
+
for (const raw of wanted) {
|
|
318
|
+
const candidates = record === undefined ? [raw] : [raw, raw.replace(/^(result|data)\./, "")];
|
|
319
|
+
const hit = candidates.find((key) => record !== undefined && key in record);
|
|
320
|
+
if (hit !== undefined && record !== undefined)
|
|
321
|
+
projected[hit] = record[hit];
|
|
322
|
+
else
|
|
323
|
+
missing.push(raw);
|
|
324
|
+
}
|
|
325
|
+
const result = { status: "ok", artifactId: id, sha256: artifact.sha256, keys: wanted, ...(missing.length > 0 ? { missingKeys: missing, availableKeys: record ? Object.keys(record) : [], unanswered: true, hint: `这些键不在产物顶层:${missing.join("、")}。availableKeys 是真实顶层键;嵌套值用 --jq a.b 或 --extract a.b` } : {}), content: projected };
|
|
326
|
+
if (Buffer.byteLength(JSON.stringify(result), "utf8") > transport.maxOutputBytes)
|
|
327
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, projection: options.keys, ...(missing.length > 0 ? { missingKeys: missing, availableKeys: record ? Object.keys(record) : [], unanswered: true } : {}), fetch: artifactFetchHint(id) }, transport);
|
|
328
|
+
return emitTransportResult(result, transport);
|
|
329
|
+
}
|
|
330
|
+
if (options.jq !== undefined) {
|
|
331
|
+
// A3(GitLab #15):逗号多路径——一次取多列(projections 数组),单路径形态不变。
|
|
332
|
+
const jqPaths = options.jq.split(",").map((path) => path.trim()).filter(Boolean);
|
|
333
|
+
const artifactContent = artifact.content.toString("utf8") === "" ? undefined : content;
|
|
334
|
+
if (jqPaths.length > 1) {
|
|
335
|
+
const projections = jqPaths.map((path) => {
|
|
336
|
+
const projected = projectArtifactPath(artifactContent, path);
|
|
337
|
+
return projected.missed
|
|
338
|
+
? artifactMissEntry(path, projected, artifactContent, id, explainMiss)
|
|
339
|
+
: { path, content: projected.content ?? null, ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}), ...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}), ...(artifactNullHint(projected.content, projected.nullEntries) !== undefined ? { hint: artifactNullHint(projected.content, projected.nullEntries) } : {}) };
|
|
340
|
+
});
|
|
341
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), projections, ...(projections.some((entry) => entry.pathMiss) ? { unanswered: true, hint: partialPathMissHint() } : {}) }, transport);
|
|
342
|
+
}
|
|
343
|
+
const projected = projectArtifactPath(artifactContent, options.jq);
|
|
344
|
+
return emitTransportResult(projected.missed
|
|
345
|
+
? { status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), ...artifactMissEntry(options.jq, projected, artifactContent, id, explainMiss), unanswered: true, ...(explainMiss && projected.unsupportedSyntax !== true ? { hint: artifactPathMissHint(projected.at, pathMissCopyableHint(artifactContent, options.jq, projected.at)) } : {}) }
|
|
346
|
+
: { status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.jq, projections: [{ path: options.jq, content: projected.content ?? null, ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}), ...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}) }], ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}), ...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}), ...(artifactNullHint(projected.content, projected.nullEntries) !== undefined ? { hint: artifactNullHint(projected.content, projected.nullEntries) } : {}) }, transport);
|
|
347
|
+
}
|
|
348
|
+
// r6-onboarding 2026-10-21: 47 artifact fetches, 0 used a projection; the 10
|
|
349
|
+
// large ones (up to 55 KB) pulled whole workflow templates just to read one
|
|
350
|
+
// nested key. Round 10 still spent 247 KB (22.7% of the session) on 28
|
|
351
|
+
// `artifact get` calls, re-fetching 10–27 KB bodies — the nudge below was
|
|
352
|
+
// advisory and did not change behaviour.
|
|
353
|
+
//
|
|
354
|
+
// 0.4.80: shape first, the same rule as `omc help`. Above the inline ceiling
|
|
355
|
+
// the default is the depth-2 skeleton (same shapeOf as `--shape`; r75 调查C:
|
|
356
|
+
// 两面共用一份实现——顶层键表请走 --summary,此处不再第二张雷同面);
|
|
357
|
+
// `--full` returns the whole body exactly as before. Explicit projections
|
|
358
|
+
// (--shape/--summary/--keys/--jq/--path-only) are handled above and are
|
|
359
|
+
// never affected.
|
|
360
|
+
if (options.full !== true && artifact.content.length > ARTIFACT_INLINE_CEILING_BYTES) {
|
|
361
|
+
const depth = options.depth ?? 2;
|
|
362
|
+
return emitTransportResult({
|
|
363
|
+
status: "ok",
|
|
364
|
+
artifactId: id,
|
|
365
|
+
sha256: artifact.sha256,
|
|
366
|
+
bytes: artifact.content.length,
|
|
367
|
+
outline: true,
|
|
368
|
+
depth,
|
|
369
|
+
shape: shapeOf(content, depth),
|
|
370
|
+
hint: artifactOutlineHint(id, artifact.content.length, depth),
|
|
371
|
+
message: artifactOutlineHint(id, artifact.content.length, depth),
|
|
372
|
+
projectionRule: "投影要写到叶子(数组元素里的字段);写整棵父节点(如 data.activities)会因总量超限再次被外置",
|
|
373
|
+
...(() => {
|
|
374
|
+
const rec = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
375
|
+
const data = rec && rec.data && typeof rec.data === "object" && !Array.isArray(rec.data) ? rec.data : undefined;
|
|
376
|
+
const leaf = data && Array.isArray(data.activities) ? "data.activities[].bizActions" : undefined;
|
|
377
|
+
return leaf ? { projectionExample: `omc artifact get ${id} --jq '${leaf}'` } : {};
|
|
378
|
+
})(),
|
|
379
|
+
fullCommand: `omc artifact get ${id} --full`,
|
|
380
|
+
}, transport);
|
|
381
|
+
}
|
|
382
|
+
const result = { status: "ok", artifactId: id, sha256: artifact.sha256, content, fullCommand: `omc artifact get ${id}`, projectionExample: `omc artifact get ${id} --jq '<path>'` };
|
|
383
|
+
if (Buffer.byteLength(JSON.stringify(result), "utf8") > transport.maxOutputBytes) {
|
|
384
|
+
// 2026-11-04 r70: `--full` used to fall back to the same bare `fetch`
|
|
385
|
+
// pointer it had just been asked to bypass — re-running `--full` re-hits
|
|
386
|
+
// the same ceiling, so a caller that genuinely needs the body loops
|
|
387
|
+
// forever (observed live: three consecutive `--full` calls returned the
|
|
388
|
+
// same id with bytes 90K→151K→227K of pointer metadata). Say what
|
|
389
|
+
// actually happened and give the two projections that DO work.
|
|
390
|
+
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
391
|
+
const keys = record
|
|
392
|
+
? Object.entries(record)
|
|
393
|
+
.map(([key, value]) => ({ key, bytes: Buffer.byteLength(JSON.stringify(value) ?? "null", "utf8") }))
|
|
394
|
+
.sort((left, right) => right.bytes - left.bytes)
|
|
395
|
+
.slice(0, 3)
|
|
396
|
+
.map((entry) => entry.key)
|
|
397
|
+
: [];
|
|
398
|
+
// 0.6.82(issue 06 连锁):自愈文案加长后,fullRejected 回执自身可能超过
|
|
399
|
+
// 顽强的小预算(调用方正用 1024B 这类极限值测试)——被 boundResult 二次
|
|
400
|
+
// 截断会把 fullRejected 语义键一起截掉。按预算渐进丢弃可选长文案,
|
|
401
|
+
// 语义键(fullRejected/artifactId/sha256/bytes + 最短出路)永不丢。
|
|
402
|
+
const fullRejectedReceipt = {
|
|
403
|
+
status: "ok",
|
|
404
|
+
artifactId: id,
|
|
405
|
+
sha256: artifact.sha256,
|
|
406
|
+
bytes: artifact.content.length,
|
|
407
|
+
fullRejected: true,
|
|
408
|
+
reason: `整包 ${Math.round(artifact.content.length / 1024)}KB 超过本通道输出上限 ${transport.maxOutputBytes}B;--full 无法一次返回,再跑一次结果相同`,
|
|
409
|
+
...(keys.length > 0 ? { keysCommand: `omc artifact get ${id} --keys ${keys.join(",")}`, sampledKeys: keys } : {}),
|
|
410
|
+
jqCommand: `omc artifact get ${id} --jq '<path>'`,
|
|
411
|
+
outCommand: `omc artifact get ${id} --out <配置根内文件路径>(整包落盘,不走 stdout 限额,适合一次性备份;根内父目录自动创建,越界拒绝的错误里带可用示例路径)`,
|
|
412
|
+
raiseCeilingCommand: `omc artifact get ${id} --full --max-output-bytes ${Math.max(artifact.content.length + 1024, transport.maxOutputBytes * 2)}`,
|
|
413
|
+
hint: "三选一:用 --jq/--keys 取你真正需要的那部分(推荐),整包落盘备份用 --out <配置根内路径>(写文件不受 stdout 限额),或显式抬高 --max-output-bytes",
|
|
414
|
+
};
|
|
415
|
+
const optionalKeys = ["hint", "raiseCeilingCommand", "keysCommand", "sampledKeys"];
|
|
416
|
+
for (const drop of optionalKeys) {
|
|
417
|
+
if (Buffer.byteLength(JSON.stringify(fullRejectedReceipt), "utf8") <= transport.maxOutputBytes)
|
|
418
|
+
break;
|
|
419
|
+
delete fullRejectedReceipt[drop];
|
|
420
|
+
}
|
|
421
|
+
return emitTransportResult(fullRejectedReceipt, transport);
|
|
422
|
+
}
|
|
423
|
+
return emitTransportResult(result, transport);
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
// Round 16 (bench67 feedback): a missing/expired artifact id is ordinary
|
|
427
|
+
// caller error, not an internal fault — classify it as invalid-input with a
|
|
428
|
+
// structured code and a recovery hint instead of a generic `internal`.
|
|
429
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
430
|
+
if (message === "artifact not found" || message === "invalid artifact id") {
|
|
431
|
+
const hint = message === "artifact not found"
|
|
432
|
+
? "artifact 不存在或已被清理/过期;用产出它的命令返回的最新 artifactId(结果里的 fetch 提示)重新取,或重跑该命令"
|
|
433
|
+
: "artifactId 不是合法 UUID(36 位十六进制/连字符)";
|
|
434
|
+
const parsed = errorEnvelope(new Error(hint), "artifact-absent", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
435
|
+
writeEnvelope(parsed.envelope);
|
|
436
|
+
return parsed.exitCode;
|
|
437
|
+
}
|
|
438
|
+
const parsed = errorEnvelope(error, "internal", CLI_EXIT_CODES.internal, transport.request);
|
|
439
|
+
writeEnvelope(parsed.envelope);
|
|
440
|
+
return parsed.exitCode;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
//# sourceMappingURL=artifact-cmd.js.map
|
package/dist/batch-call.js
CHANGED
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
* N full envelopes — the caller needs to know which entries to retry;
|
|
15
15
|
* - a dry-run stays a dry-run for every entry.
|
|
16
16
|
*
|
|
17
|
-
* Governance is inherited
|
|
18
|
-
* the
|
|
19
|
-
*
|
|
17
|
+
* Governance is inherited per entry: each entry goes through `runToolCall`, so
|
|
18
|
+
* the writable gate, the production acknowledgement and every per-tool
|
|
19
|
+
* preflight apply exactly as they do for a single call.
|
|
20
|
+
*
|
|
21
|
+
* The cross-process write lock is NOT inherited (0.8.35 review: this module
|
|
22
|
+
* never acquired it). `runToolCall` does not take the lock — only the CLI
|
|
23
|
+
* entries do — so a write batch is locked by `runCallBatch` (call-execute.ts):
|
|
24
|
+
* ONE acquisition for the whole list (`tool: "<tool>:batch"`, `mode: "batch"`,
|
|
25
|
+
* `--wait` bound), released after the last entry. A conflict therefore means
|
|
26
|
+
* zero entries ran, never a half-applied batch. Read batches and `--dry-run`
|
|
27
|
+
* batches take no lock.
|
|
20
28
|
*/
|
|
21
29
|
import { refusalText } from "./cli-contract.js";
|
|
22
30
|
import { createArtifact } from "./artifacts.js";
|
|
@@ -55,6 +63,40 @@ function failureDetails(entry, args) {
|
|
|
55
63
|
* (reads, model/field/config writes, …) gets no guessed warnings at all.
|
|
56
64
|
*/
|
|
57
65
|
const FORM_DATA_TOOLS = new Set(["data.save", "data.update", "data.submit"]);
|
|
66
|
+
function readbackConfirmsCompletion(readback) {
|
|
67
|
+
if (readback === null || typeof readback !== "object" || Array.isArray(readback))
|
|
68
|
+
return false;
|
|
69
|
+
const record = readback;
|
|
70
|
+
if (record.absent === true ||
|
|
71
|
+
record.allAbsent === true ||
|
|
72
|
+
record.deleted === true ||
|
|
73
|
+
record.present === true ||
|
|
74
|
+
record.existed === true ||
|
|
75
|
+
record.draftFieldPresent === true ||
|
|
76
|
+
record.fieldPresent === true ||
|
|
77
|
+
record.absentDraft === true ||
|
|
78
|
+
record.published === true ||
|
|
79
|
+
record.equivalent === true ||
|
|
80
|
+
record.unchanged === true ||
|
|
81
|
+
(typeof record.matchedCount === "number" && record.matchedCount > 0))
|
|
82
|
+
return true;
|
|
83
|
+
// data.save 的权威读回把落地行放在 readback.authoritative.id(没有 present 旗标)。
|
|
84
|
+
const authoritative = record.authoritative;
|
|
85
|
+
if (authoritative !== null && typeof authoritative === "object" && !Array.isArray(authoritative)) {
|
|
86
|
+
const row = authoritative;
|
|
87
|
+
if (typeof row.id === "string" || row.present === true)
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
const perCode = record.perCode;
|
|
91
|
+
return Array.isArray(perCode) && perCode.length > 0 && perCode.every((entry) => entry !== null && typeof entry === "object" && (entry.absent === true || entry.present === true));
|
|
92
|
+
}
|
|
93
|
+
function completionStateOf(result) {
|
|
94
|
+
const hasDeliveryState = typeof result.deliveryState === "string";
|
|
95
|
+
const hasReadback = result.readback !== null && typeof result.readback === "object";
|
|
96
|
+
if (!hasDeliveryState && !hasReadback)
|
|
97
|
+
return { completionState: "unverified", verificationOmittedReason: "batch-summary" };
|
|
98
|
+
return { completionState: readbackConfirmsCompletion(result.readback) ? "verified" : "delivered-unverified" };
|
|
99
|
+
}
|
|
58
100
|
export function batchWarnings(argsList, tool) {
|
|
59
101
|
// Without a tool name there is no schema to justify a row shape: return
|
|
60
102
|
// nothing rather than treating arbitrary args as formData.
|
|
@@ -181,6 +223,8 @@ export async function runBatchCall(options) {
|
|
|
181
223
|
...(applicationCode !== undefined ? { applicationCode } : {}),
|
|
182
224
|
...(entry.status === "ok" ? {} : { status: String(entry.result.status ?? "failed"), blocker: entry.result.blocker ?? null }),
|
|
183
225
|
...(skippedMarker !== undefined ? { skipped: String(skippedMarker) } : {}),
|
|
226
|
+
// 完成态是摘要字段,不是逐条正文;与 entries 的其它键同层。
|
|
227
|
+
...completionStateOf(entry.result),
|
|
184
228
|
};
|
|
185
229
|
});
|
|
186
230
|
const entriesInline = entriesSummary.slice(0, ENTRIES_INLINE_LIMIT);
|
|
@@ -197,6 +241,14 @@ export async function runBatchCall(options) {
|
|
|
197
241
|
const detailArtifact = detailOmitted
|
|
198
242
|
? createArtifact(artifactRoot(), JSON.stringify({ entries: entriesSummary, warnings }, null, 2) + "\n")
|
|
199
243
|
: undefined;
|
|
244
|
+
// 顶层汇总:全部 entry 的完成态(不只是内联的前 20 条)。旧计数
|
|
245
|
+
// succeeded/failed 保留,这一层回答「几条真被证明了」。
|
|
246
|
+
const completionStates = entries.map((entry) => completionStateOf(entry.result).completionState);
|
|
247
|
+
const completionSummary = {
|
|
248
|
+
verified: completionStates.filter((state) => state === "verified").length,
|
|
249
|
+
unverified: completionStates.filter((state) => state === "unverified").length,
|
|
250
|
+
deliveredUnverified: completionStates.filter((state) => state === "delivered-unverified").length,
|
|
251
|
+
};
|
|
200
252
|
return {
|
|
201
253
|
exitCode: failed > 0 ? 1 : 0,
|
|
202
254
|
result: {
|
|
@@ -206,6 +258,7 @@ export async function runBatchCall(options) {
|
|
|
206
258
|
executed,
|
|
207
259
|
succeeded,
|
|
208
260
|
failed,
|
|
261
|
+
completionSummary,
|
|
209
262
|
...(applicationCode !== undefined ? { applicationCode } : {}),
|
|
210
263
|
...(skipped > 0 ? { notExecuted: skipped } : {}),
|
|
211
264
|
// 每条一行摘要(index/ok/bizObjectId)——不是完整信封,但足以回答
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { argvValue } from "./args.js";
|
|
2
|
+
import { requestId } from "./cli-contract.js";
|
|
3
|
+
import { beginWriteFace, endWriteFace, humanSummary } from "./cli-output.js";
|
|
4
|
+
import { outputBudget } from "./command-transport.js";
|
|
5
|
+
import { createCallEmitter, emitCallHelp, emitCallLockConflict, emitCallResult, emitInvalidInput, projectCallResult } from "./call-output.js";
|
|
6
|
+
import { parseCallInput } from "./call-input.js";
|
|
7
|
+
import { executeCall, runCallBatch } from "./call-execute.js";
|
|
8
|
+
/**
|
|
9
|
+
* `omc call` 的薄编排:Commander action 只把 argv 交进来,这里按
|
|
10
|
+
* 解析(call-input)→ 执行(call-execute)→ 输出(call-output)串起来。
|
|
11
|
+
*
|
|
12
|
+
* 本模块只做顺序与早退:写面标记的 begin/end、写锁冲突的 refused 信封、
|
|
13
|
+
* 解析早退的 stderr 通道。任何一层的内容都不在这里重写。
|
|
14
|
+
*/
|
|
15
|
+
export async function runCallCommand(store, args) {
|
|
16
|
+
const request = argvValue(args, "--request-id") ?? requestId();
|
|
17
|
+
// issue 07(retro 2026-11-19):每次 omc call 的回执(成功与错误信封)都带
|
|
18
|
+
// resultMeta.sessionAccount——token 解码(0 wire),解不出就回 unavailableReason,
|
|
19
|
+
// 不谎报。环境旗标解析出来之前 callEnvironment 是 undefined,按默认环境解析。
|
|
20
|
+
let callEnvironment;
|
|
21
|
+
let maxOutputBytes = 0;
|
|
22
|
+
const callOutput = { store, request, maxOutputBytes: () => maxOutputBytes, environment: () => callEnvironment };
|
|
23
|
+
const emit = createCallEmitter(callOutput);
|
|
24
|
+
try {
|
|
25
|
+
maxOutputBytes = outputBudget(args);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
+
return emitInvalidInput(callOutput, message);
|
|
30
|
+
}
|
|
31
|
+
const outcome = parseCallInput(store, args);
|
|
32
|
+
if (outcome.kind === "help")
|
|
33
|
+
return emitCallHelp(callOutput, outcome.toolName, emit);
|
|
34
|
+
if (outcome.kind === "exit") {
|
|
35
|
+
const { exit } = outcome;
|
|
36
|
+
if (exit.environment !== undefined)
|
|
37
|
+
callEnvironment = exit.environment;
|
|
38
|
+
if (exit.stderr !== undefined) {
|
|
39
|
+
if (exit.stderr.channel === "summary")
|
|
40
|
+
humanSummary(exit.stderr.text);
|
|
41
|
+
else
|
|
42
|
+
console.error(exit.stderr.text);
|
|
43
|
+
}
|
|
44
|
+
if (exit.emission.via === "invalid")
|
|
45
|
+
return emitInvalidInput(callOutput, exit.emission.message, exit.emission.configurationRoot !== undefined ? { configurationRoot: exit.emission.configurationRoot } : {});
|
|
46
|
+
return emit(exit.emission.status, exit.emission.result, exit.exitCode, exit.emission.extra);
|
|
47
|
+
}
|
|
48
|
+
if (outcome.kind === "batch")
|
|
49
|
+
return runCallBatch(store, outcome.batch);
|
|
50
|
+
const parsed = outcome.parsed;
|
|
51
|
+
callEnvironment = parsed.environment;
|
|
52
|
+
const writeFace = parsed.tool?.kind === "write";
|
|
53
|
+
// F2':只对写面(含 dry-run 预览)标记;读面人话不追加 2>&1 提示。
|
|
54
|
+
if (writeFace)
|
|
55
|
+
beginWriteFace();
|
|
56
|
+
const executed = await executeCall(store, parsed);
|
|
57
|
+
if (executed.kind === "lock-conflict")
|
|
58
|
+
return emitCallLockConflict(callOutput, executed.receipt, executed.stderr);
|
|
59
|
+
const projection = projectCallResult(parsed, executed.result, maxOutputBytes);
|
|
60
|
+
if (projection.refusal !== undefined)
|
|
61
|
+
return emit(projection.refusal.status, projection.refusal.result, projection.refusal.exitCode);
|
|
62
|
+
try {
|
|
63
|
+
return emitCallResult({ emit, parsed, projection });
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (writeFace)
|
|
67
|
+
endWriteFace();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=call-command.js.map
|