@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.
Files changed (52) hide show
  1. package/dist/arg-vocabulary.js +223 -0
  2. package/dist/artifact-cmd.js +443 -0
  3. package/dist/batch-call.js +56 -3
  4. package/dist/call-command.js +70 -0
  5. package/dist/call-execute.js +228 -0
  6. package/dist/call-input.js +557 -0
  7. package/dist/call-output.js +240 -0
  8. package/dist/cli.js +13 -1359
  9. package/dist/command-transport.js +4 -1
  10. package/dist/form-support.js +14 -3
  11. package/dist/intent/plan-apply.js +14 -24
  12. package/dist/lanes/datarule.js +21 -0
  13. package/dist/lanes/field-contract.js +1 -1
  14. package/dist/lanes/field.js +128 -1
  15. package/dist/lanes/list-view-shapes.js +8 -1
  16. package/dist/lanes/list-view.js +64 -2
  17. package/dist/lanes/runtime-data/aggregate-support.js +209 -0
  18. package/dist/lanes/runtime-data/aggregate.js +679 -0
  19. package/dist/lanes/runtime-data/field-options.js +52 -0
  20. package/dist/lanes/runtime-data/lane.js +4 -0
  21. package/dist/lanes/runtime-data/record-delete.js +419 -0
  22. package/dist/lanes/runtime-data/record-read.js +984 -0
  23. package/dist/lanes/runtime-data/record-write.js +562 -0
  24. package/dist/lanes/runtime-data/registration.js +22 -0
  25. package/dist/lanes/runtime-data/shapes.js +594 -0
  26. package/dist/lanes/runtime-data/submission.js +1304 -0
  27. package/dist/lanes/runtime-data/write-support.js +875 -0
  28. package/dist/lanes/runtime-data.js +10 -5590
  29. package/dist/lanes/workflow/approval-ops.js +983 -0
  30. package/dist/lanes/workflow/instance-read.js +284 -0
  31. package/dist/lanes/workflow/lifecycle-write.js +1499 -0
  32. package/dist/lanes/workflow/permissions.js +571 -0
  33. package/dist/lanes/workflow/recovery.js +361 -0
  34. package/dist/lanes/workflow/registration.js +14 -0
  35. package/dist/lanes/workflow/shapes.js +811 -0
  36. package/dist/lanes/workflow/template-fetch.js +197 -0
  37. package/dist/lanes/workflow/template-merge.js +1351 -0
  38. package/dist/lanes/workflow/template-read.js +327 -0
  39. package/dist/lanes/workflow.js +11 -6312
  40. package/dist/model-scaffold.js +6 -2
  41. package/dist/plan.js +23 -1
  42. package/dist/read-projection.js +442 -0
  43. package/dist/read.js +40 -335
  44. package/dist/rollback.js +17 -23
  45. package/dist/runtime-support.js +1 -1
  46. package/dist/verification.js +39 -0
  47. package/dist/write-coordinator.js +152 -0
  48. package/dist/write-outcome.js +295 -0
  49. package/dist/write.js +34 -115
  50. package/package.json +3 -3
  51. package/skills/omc-refusals.md +1 -1
  52. package/skills/omc-start-here.md +2 -2
@@ -0,0 +1,557 @@
1
+ import { argvValue } from "./args.js";
2
+ import { resolve, join } from "node:path";
3
+ import { resolveMainCheckout } from "./config-store.js";
4
+ import { readArgsFile, readStdinArgs, validateAgentPaths } from "./call.js";
5
+ import { CLI_EXIT_CODES } from "./cli-contract.js";
6
+ import { buildToolRegistry } from "./tools.js";
7
+ import { KEY_ALIAS_HINTS, TOOL_KEY_ALTERNATIVES, inputAliasSynonymKeys, parseToolInput, ToolInputError } from "./tool-types.js";
8
+ import { resolveArgAliases } from "./arg-vocabulary.js";
9
+ /** Collect every value of a repeatable flag (`--extract a --extract b`). */
10
+ export function argvValues(args, name) {
11
+ const values = [];
12
+ for (let index = 0; index < args.length; index += 1) {
13
+ if (args[index] !== name)
14
+ continue;
15
+ const value = args[index + 1];
16
+ if (value !== undefined && !value.startsWith("--"))
17
+ values.push(value);
18
+ }
19
+ return values;
20
+ }
21
+ /** F6:应用级范围键。被工具 schema 忽略时必须拒绝,不能静默回落到默认应用。 */
22
+ const APP_SCOPE_ARG_KEYS = new Set(["appCode", "applicationCode", "application"]);
23
+ /** 归一化编辑距离(去分隔符 + 统一大小写),用于「拼写级」改名判定。 */
24
+ function normalizedEditDistance(a, b) {
25
+ const left = a.toUpperCase().replace(/[\s._-]/g, "");
26
+ const right = b.toUpperCase().replace(/[\s._-]/g, "");
27
+ const row = Array.from({ length: right.length + 1 }, (_, index) => index);
28
+ for (let i = 1; i <= left.length; i += 1) {
29
+ let previous = row[0];
30
+ row[0] = i;
31
+ for (let j = 1; j <= right.length; j += 1) {
32
+ const temp = row[j];
33
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (left[i - 1] === right[j - 1] ? 0 : 1));
34
+ previous = temp;
35
+ }
36
+ }
37
+ return row[right.length];
38
+ }
39
+ /**
40
+ * C1(0.8.4):**语义**别名(不是拼写)——只在目标键真实存在时换算,且回执
41
+ * 写明换算结果(aliasesApplied),不让调用方以为原名生效了。
42
+ *
43
+ * 两条别名的语义边界不同:
44
+ * - `pageSize` 与分页工具的 `size`(每页条数)是同一件事,任何有 `size` 的工具都换算。
45
+ * 平台依据:`/api/runtime/query/list` 的 `QueryDataVO{page,size}` 在
46
+ * `QueryRuntimeController` 里按 `new PageableImpl(page * size, size)` 落到分页
47
+ * (8.6.26 QueryRuntimeController.java:3304/3945;2.1.5 同名文件:3658/4187),
48
+ * 即 `size` = 每页条数、`page` = 页序号;前端列表页也是
49
+ * `page:this.curPage-1, size:this.pageSize`(8.6.26 frontend-dist
50
+ * portal-app/js/17491.eed01ae7.js:1、31275.a9b046c8.js:1)。
51
+ * - `onlyCustom` 与 `all` **方向相反**(`all:true` = 连系统字段一起返)。只有
52
+ * field.list 的 `all` 是「包含系统字段」的客户端过滤(lanes/field.ts:453 用
53
+ * isSystemFieldCode 过滤),系统字段本身由平台 `defaultProperty=true` 标注
54
+ * (BizProperty.isSystem(),8.6.26 shared/BizProperty.java:257-259;
55
+ * 2.1.5 contracts/BizProperty.java:262-264)。**不扩展到 data.list**:那里的
56
+ * `all` 是「自动翻页聚合全部」,换算过去只会拿错结果集。
57
+ * 其余同名键(如 model.inspect 的 `all`)没有被实测误用证据,宁可不加。
58
+ */
59
+ const ONLY_CUSTOM_TO_ALL_TOOLS = new Set(["field.list"]);
60
+ /**
61
+ * 同义键换算(C1 0.8.4 / 探针 V·R·S 的既有语义)。
62
+ *
63
+ * 词汇表(`arg-vocabulary.ts`)拥有**哪些键是同一个概念**;这里只保留两件
64
+ * 词汇表不该管的事:
65
+ * - 写面不换算(静默改写会改掉真实载荷,写面继续走严格未知键拒绝);
66
+ * - `onlyCustom → all` 是**反向**布尔(`all:true` = 连系统字段一起返),
67
+ * 不是同义输入,无法写成 1:1 别名表,留在工具级特例里。
68
+ */
69
+ function applyReadArgAliases(toolName, schemaKeys, input) {
70
+ const { args, applied, conflict } = resolveArgAliases(toolName, input, schemaKeys);
71
+ if (conflict !== undefined)
72
+ return { args, applied, conflict };
73
+ if (ONLY_CUSTOM_TO_ALL_TOOLS.has(toolName)) {
74
+ // 等价改写只在目标键真实存在时发生;类型不符交给正常参数校验。
75
+ if (input.onlyCustom !== undefined && !schemaKeys.has("onlyCustom") && schemaKeys.has("all")) {
76
+ if (args.all !== undefined)
77
+ return { args, applied, conflict: { alias: "onlyCustom", canonical: "all" } };
78
+ if (typeof input.onlyCustom === "boolean") {
79
+ args.all = !input.onlyCustom;
80
+ delete args.onlyCustom;
81
+ applied.onlyCustom = `all=${String(args.all)}`;
82
+ }
83
+ }
84
+ }
85
+ return { args, applied };
86
+ }
87
+ /**
88
+ * 读面「拼错键」建议(r25 真机实证,2026-11-04):`limt:5` 曾按编辑距离被指到
89
+ * `filter`——两者共享 "fi" 片段就过阈值,但语义完全不同(取 5 条 vs 按条件过滤)。
90
+ * 短键(≤5 字符)靠距离算不准,这里先查显式缩写表(与 tool-types 的 KEY_ALIAS_HINTS
91
+ * 同源),命中且参数真实存在才用;否则只认**拼写级**近似(编辑距离 ≤2)。
92
+ *
93
+ * C1(0.8.4):最后一步此前是 closestMatches 的「least-bad」兜底——它总会挑一个
94
+ * 名字,于是 `onlyCustom` 被建议到语义相反的 `all`、`pageSize` 被建议到 `page`。
95
+ * 改名建议只在**拼错**(编辑距离 ≤2)或上面人工核过的同义表里给;其余宁可不猜
96
+ * (回执仍列全部真实参数 expectedKeys)。语义别名走 applyReadArgAliases,不用
97
+ * 「改名建议」表达——建议无法携带方向/换算信息。
98
+ */
99
+ export function suggestArgumentKey(key, schemaKeys, toolName) {
100
+ // 探针 J F4/F5:按 tool+key 的显式替代优先于拼写猜测(见
101
+ // TOOL_KEY_ALTERNATIVES)。命中的是「语义改写」而不是「拼错」,所以
102
+ // closest/编辑距离不参与,避免把原键再建议一次。
103
+ const alternative = toolName !== undefined ? TOOL_KEY_ALTERNATIVES[toolName]?.[key] : undefined;
104
+ if (alternative !== undefined)
105
+ return { ...alternative };
106
+ const known = new Set(schemaKeys);
107
+ const paginationKeys = new Set(["page", "pagesize", "size", "pageindex", "pagenumber", "pageno", "offset", "limit"]);
108
+ if (paginationKeys.has(key.toLowerCase()) && !schemaKeys.some((name) => paginationKeys.has(name.toLowerCase()))) {
109
+ return { hint: "本工具不支持分页(返回全量/受限于应用范围);省略该键即可" };
110
+ }
111
+ const normalizedTool = toolName?.toLowerCase() ?? "";
112
+ if ((normalizedTool.startsWith("workflow.") || normalizedTool.startsWith("workitem.")) && key === "code" && known.has("workflowCode"))
113
+ return { closest: "workflowCode" };
114
+ if (normalizedTool.startsWith("data.") && key === "id" && known.has("bizObjectId"))
115
+ return { closest: "bizObjectId" };
116
+ // r53 场景03 F8:rule.run 的记录标识叫 ids(数组),与 data.* 族的 bizObjectId
117
+ // 完全不共享字符串相似度——最近匹配回不出建议,只能报「无相近键」。
118
+ if (normalizedTool.startsWith("rule.") && key === "bizObjectId" && known.has("ids"))
119
+ return { closest: "ids", hint: "rule.run 的记录标识是 ids(字符串数组)" };
120
+ if (normalizedTool.startsWith("data.") && key === "ids" && known.has("bizObjectIds"))
121
+ return { closest: "bizObjectIds" };
122
+ const aliases = KEY_ALIAS_HINTS[key.toLowerCase()] ?? [];
123
+ for (const candidate of aliases) {
124
+ if (known.has(candidate))
125
+ return { closest: candidate };
126
+ }
127
+ // 关键:若这个键明确是某个已知参数的缩写、而**本工具根本没有该参数**(实测
128
+ // `model.list` 就没有 `size`),不能退回最近匹配硬凑一个(`filter` 语义相反)——
129
+ // 返回 absentInTool,让回执直说「本工具没有这个参数」。
130
+ if (aliases.length > 0)
131
+ return { absentInTool: aliases[0] };
132
+ // 拼写级近似:距离 ≤2 才算「同一个名字写错了」;更远的一律不猜。
133
+ let closest;
134
+ let closestDistance = Number.POSITIVE_INFINITY;
135
+ for (const candidate of schemaKeys) {
136
+ const distance = normalizedEditDistance(key, candidate);
137
+ if (distance < closestDistance) {
138
+ closest = candidate;
139
+ closestDistance = distance;
140
+ }
141
+ }
142
+ return closest !== undefined && closestDistance <= 2 ? { closest } : {};
143
+ }
144
+ /**
145
+ * GitLab #47:`unknown environment "test"` 的恢复动作在 99% 情况下是「去掉
146
+ * --env 重跑同一条调用」(项目 .omc-env 已是正确绑定)。config-store 的文案
147
+ * 说明了这条规则,但只有 call 这一层知道 tool 与本次参数,所以在这里补一条
148
+ * **真正可复制**的 nextCommand。
149
+ *
150
+ * 只对 `unknown environment "…"` 这一类生效:跨环境访问被拒、凭据缺失、平台
151
+ * 错误的恢复动作各不相同,不能套用「去掉 --env」。参数过大/来自 stdin/文件时
152
+ * 退回不内联参数的命令,绝不截断或编造载荷。
153
+ */
154
+ function withoutEnvironmentCommand(input) {
155
+ const inlineRaw = input.rawArgs !== undefined && input.rawArgs.trim().startsWith("{") ? input.rawArgs : undefined;
156
+ // `parseToolInput` folds `--env` into args.environment; keeping it in the retry
157
+ // would reproduce the very failure it is meant to recover from. Strip it from
158
+ // the caller's JSON too (a tool-arg `environment` fails the same way).
159
+ let inline = inlineRaw;
160
+ if (inlineRaw !== undefined) {
161
+ try {
162
+ const parsed = JSON.parse(inlineRaw);
163
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) && "environment" in parsed) {
164
+ delete parsed.environment;
165
+ inline = Object.keys(parsed).length > 0 ? JSON.stringify(parsed) : undefined;
166
+ }
167
+ }
168
+ catch {
169
+ // Not valid JSON: the call already failed input validation before this path.
170
+ }
171
+ }
172
+ const remaining = { ...input.parsedArgs };
173
+ delete remaining.environment;
174
+ const serialized = inline ?? (Object.keys(remaining).length > 0 ? JSON.stringify(remaining) : undefined);
175
+ if (serialized === undefined || serialized === "{}")
176
+ return `omc call ${input.tool}`;
177
+ if (serialized.length <= 500)
178
+ return `omc call ${input.tool} --args '${serialized.replace(/'/g, "'\\''")}'`;
179
+ if (input.argsFile !== undefined)
180
+ return `omc call ${input.tool} --args-file ${input.argsFile}`;
181
+ if (input.rawArgs === "-")
182
+ return `omc call ${input.tool} --args -`;
183
+ return `omc call ${input.tool}`;
184
+ }
185
+ /** 给 `unknown environment` 错误补一条「去掉 --env 重跑」的可复制命令。 */
186
+ export function withUnknownEnvironmentRecovery(result, input) {
187
+ if (result.status !== "error" || typeof result.message !== "string")
188
+ return result;
189
+ if (!/^unknown environment "/u.test(result.message))
190
+ return result;
191
+ const nextCommand = withoutEnvironmentCommand(input);
192
+ return {
193
+ ...result,
194
+ nextCommand,
195
+ message: result.message.includes("直接重试:") ? result.message : `${result.message};直接重试:${nextCommand}`,
196
+ };
197
+ }
198
+ /**
199
+ * `--wait` 取值校验,单条与 `--args-list` 批量共用(批量用它排队整批写锁)。
200
+ * 非法取值回错误文案,由调用方转成 invalid-input 早退。
201
+ */
202
+ function parseWaitMs(value) {
203
+ if (value === undefined)
204
+ return { waitMs: 0 };
205
+ const waitMs = Number(value);
206
+ if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 600_000) {
207
+ return { message: "--wait must be an integer number of milliseconds from 0 to 600000" };
208
+ }
209
+ return { waitMs };
210
+ }
211
+ /** 解析阶段的 invalid-input 早退(exit 10):环境与人类诊断一并带出。 */
212
+ function invalidExit(environment, message) {
213
+ return {
214
+ kind: "exit",
215
+ exit: {
216
+ exitCode: CLI_EXIT_CODES.invalidInput,
217
+ ...(environment !== undefined ? { environment } : {}),
218
+ emission: { via: "invalid", message },
219
+ },
220
+ };
221
+ }
222
+ export function parseCallInput(store, args) {
223
+ const flag = (name) => argvValue(args, name);
224
+ const positional = args.filter((token, index) => !token.startsWith("--") && (index === 0 || !args[index - 1]?.startsWith("--env") && !args[index - 1]?.startsWith("--environment") && !args[index - 1]?.startsWith("--args")));
225
+ const toolName = positional[0];
226
+ if (!toolName || toolName === "help" || args.includes("--help"))
227
+ return { kind: "help", toolName };
228
+ const environment = flag("--env") ?? flag("--environment");
229
+ const requestValue = flag("--request-id");
230
+ // R88 #3:写审计原因(只进 artifact/journal,不是工具参数,也不是门禁)。
231
+ const writeReason = flag("--reason");
232
+ if (writeReason !== undefined && writeReason.trim().length === 0) {
233
+ const message = "--reason 不能为空:给一句话说明本次写的目的(只记审计,不影响门禁)";
234
+ return invalidExit(environment, message);
235
+ }
236
+ // Batch mode: the SAME tool N times, one process (r12: 36 field.create calls).
237
+ const argsList = flag("--args-list");
238
+ if (argsList !== undefined) {
239
+ // A write batch takes ONE environment lock for the whole list; `--wait`
240
+ // bounds that one acquisition (it used to be silently ignored here).
241
+ const wait = parseWaitMs(flag("--wait"));
242
+ if ("message" in wait)
243
+ return invalidExit(environment, wait.message);
244
+ return {
245
+ kind: "batch",
246
+ batch: {
247
+ toolName,
248
+ argsList,
249
+ environment,
250
+ requestValue,
251
+ args,
252
+ preflight: args.includes("--preflight"),
253
+ ...(writeReason !== undefined ? { reason: writeReason } : {}),
254
+ waitMs: wait.waitMs,
255
+ },
256
+ };
257
+ }
258
+ if (args.includes("--preflight")) {
259
+ const message = "--preflight 仅用于 --args-list 批量形状;单次调用没有批量预检语义。请改用 --args-list,或移除 --preflight 后执行单次调用。";
260
+ return invalidExit(environment, message);
261
+ }
262
+ // 1.2 of issue 2026-10-23: read faces answer {detailArtifactId, sha256} and the
263
+ // caller then needs a SECOND call to see one value (16 two-step chains in one
264
+ // session; 15 more were pure --keys probes). `--extract <path>` (repeatable)
265
+ // resolves the path inside the artifact of THIS result and returns only the
266
+ // value; `--extract-keys` lists the artifact's top-level keys with sizes.
267
+ //
268
+ // issue 2026-10-25 §8: `artifact get` had `--jq` while `omc call` did not, so
269
+ // every list read that only wanted one column paid a second artifact round.
270
+ // `--jq` is the same path projection plus `[]` fan-out; a bare `--jq` is the
271
+ // key inventory (the same muscle memory as `artifact get <id> --jq`).
272
+ const extractPaths = [...argvValues(args, "--extract"), ...argvValues(args, "--jq")]
273
+ // A3(GitLab #15):逗号多路径——一张 9 列表此前要 9 次 artifact get。
274
+ // 路径语法(点式/下标/切片/[]/按键)不含逗号,拆分无歧义。
275
+ .flatMap((path) => path.split(","))
276
+ .map((path) => path.trim())
277
+ .filter(Boolean);
278
+ // `artifact get` uses `--keys`; `call` only had `--extract-keys`, so the muscle
279
+ // memory failed with "unknown option '--keys'" (r16 P7). Accept both.
280
+ const extractKeys = args.includes("--extract-keys") || args.includes("--keys") || args.some((token, index) => token === "--jq" && (args[index + 1] === undefined || args[index + 1].startsWith("--")));
281
+ // C6(0.8.4):pathMiss 默认只回结论(≤300B),完整排查载荷(available/
282
+ // correctPath/nextCommand/hint)只在显式 --explain 时给。
283
+ const explainProjection = args.includes("--explain");
284
+ const dryRun = args.includes("--dry-run");
285
+ const wait = parseWaitMs(flag("--wait"));
286
+ if ("message" in wait)
287
+ return invalidExit(environment, wait.message);
288
+ const waitMs = wait.waitMs;
289
+ let timeoutMs;
290
+ try {
291
+ if (requestValue !== undefined && requestValue.length === 0)
292
+ throw new Error("--request-id must not be empty");
293
+ const value = flag("--timeout-ms");
294
+ if (value !== undefined) {
295
+ timeoutMs = Number(value);
296
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 600_000)
297
+ throw new Error("--timeout-ms must be an integer from 1 to 600000");
298
+ }
299
+ }
300
+ catch (error) {
301
+ const message = error instanceof Error ? error.message : String(error);
302
+ return invalidExit(environment, message);
303
+ }
304
+ if (timeoutMs !== undefined)
305
+ process.env.OMC_HTTP_TIMEOUT_MS = String(timeoutMs);
306
+ const rawArgs = flag("--args");
307
+ const argsFile = flag("--args-file");
308
+ let parsedArgs = {};
309
+ try {
310
+ if (rawArgs !== undefined && argsFile !== undefined)
311
+ throw new Error("--args and --args-file are mutually exclusive");
312
+ if (rawArgs === "-")
313
+ parsedArgs = readStdinArgs();
314
+ else if (argsFile)
315
+ parsedArgs = readArgsFile(argsFile, resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd())));
316
+ else if (rawArgs) {
317
+ parsedArgs = JSON.parse(rawArgs);
318
+ if (parsedArgs === null || typeof parsedArgs !== "object" || Array.isArray(parsedArgs))
319
+ throw new Error("--args must be a JSON object");
320
+ }
321
+ validateAgentPaths(parsedArgs);
322
+ }
323
+ catch (error) {
324
+ const detail = error instanceof Error ? error.message : String(error);
325
+ // r10 F9: an out-of-root `--args-file` was reported under "--args 必须是
326
+ // 合法 JSON", which points the reader at the wrong flag. Name the real
327
+ // cause (and the configuration root) when the failure came from the file.
328
+ // 线上 #39-D:args-file 配置根与 .omc-envs 同源——worktree 下回退主检出
329
+ // (git 结构锚定),.scratch 参数文件不再因 worktree 被迫挪位置。
330
+ const configRoot = resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd()));
331
+ // 1.1 of issue 2026-10-23: the old hint told the caller to write a TEMP file
332
+ // while the validator only accepts paths under the config root — the two
333
+ // instructions contradicted each other and neither named the root. Offer a
334
+ // single executable recipe: an absolute path inside the root.
335
+ const outOfRoot = /must be inside the configuration root/.test(detail);
336
+ // 流畅性(GitLab #18 P3-8):PowerShell 把内联 JSON 拆坏时,报错形态是
337
+ // `Expected property name or '}' in JSON at position 1` / `Unexpected end of
338
+ // JSON input`——此时唯一有效的动作是改用文件或 stdin,而不是再调引号。
339
+ // 原来只在末尾附一句「若问题在引号转义…」,容易被当成补充说明;这里把它
340
+ // 提成主建议,并给出 PS 可粘贴的两条命令。
341
+ const looksLikeShellSplitting = /Unexpected (token|end of JSON)|Expected property name|position \d+/i.test(detail);
342
+ const message = argsFile !== undefined && /must be a JSON object/.test(detail)
343
+ ? `${detail};--args-file 只收单个 JSON 对象,批量数组请改用 --args-list(最多 200 条,可分批执行)`
344
+ : outOfRoot
345
+ ? `--args-file 越界:${detail}。可执行做法:把参数文件放到 ${configRoot} 之下(如 ${join(configRoot, "args.json")}),再用 --args-file 引用;不要把参数文件放在系统临时目录(配置根之外一律拒绝)`
346
+ : looksLikeShellSplitting
347
+ ? `--args 不像合法 JSON(${detail})——这个形态通常是 shell 把内联 JSON 拆坏了(Windows PowerShell 的引号/转义规则),不是你写错了字段。改法二选一:① 把 JSON 写进 ${join(configRoot, "args.json")} 再用 --args-file;② \`omc call <tool> --args - \` 从 stdin 读(PS: \`'{"k":"v"}' | omc call <tool> --args -\`)。POSIX 文档里的单引号写法不能照抄到 PS`
348
+ : `--args 必须是合法 JSON:${detail}。若问题在引号转义(Windows PowerShell),改用 --args-file <配置根内的路径> 或 --args -(stdin)`;
349
+ // The MACHINE envelope must carry the same actionable text: agents read
350
+ // stdout, and the old envelope only repeated the English detail.
351
+ // Keep the FULL path the caller passed (resolved) in the envelope: the bare
352
+ // file name read like a relative path and sent the caller looking in cwd
353
+ // (F3, 0.8.15 probe I). The resolved path is the caller's own input, not a
354
+ // leaked host layout (ticket 103); it is what they must move into the root.
355
+ const rejectedPath = typeof argsFile === "string" ? resolve(configRoot, argsFile) : "";
356
+ return {
357
+ kind: "exit",
358
+ exit: {
359
+ exitCode: CLI_EXIT_CODES.invalidInput,
360
+ ...(environment !== undefined ? { environment } : {}),
361
+ emission: {
362
+ via: "invalid",
363
+ message: outOfRoot ? `--args-file 必须位于配置根内(配置根 ${configRoot}${rejectedPath ? `;本次文件 ${rejectedPath}` : ""})。免落盘替代:--args - 从 stdin 读 JSON(echo '<json>' | omc call <tool> --args -),或把文件放进配置根后再引用;限制是为了防参数文件携带凭据被收进会话产物` : argsFile !== undefined && /must be a JSON object/.test(detail) ? `${detail};批量数组请改用 --args-list(最多 200 条,可分批执行)` : detail,
364
+ ...(outOfRoot ? { configurationRoot: configRoot } : {}),
365
+ },
366
+ stderr: { channel: "console", text: message },
367
+ },
368
+ };
369
+ }
370
+ const registry = buildToolRegistry();
371
+ const tool = registry.find((definition) => definition.name === toolName);
372
+ // C1(0.8.4):同义参数**先换算**再校验——未知键表里那两行(onlyCustom→all、
373
+ // pageSize→page)是语义不等价的改名,照做会拿到相反/更少的结果。这里接受
374
+ // 真实语义别名并回执 aliasesApplied,而不是把人引到另一个键。
375
+ let aliasesApplied = {};
376
+ // 只对读面换算:写面参数静默改写会改掉真实载荷,写面继续走严格未知键拒绝。
377
+ if (tool && tool.kind !== "write") {
378
+ const aliased = applyReadArgAliases(tool.name, new Set(Object.keys(tool.inputSchema)), parsedArgs);
379
+ if (aliased.conflict !== undefined) {
380
+ const conflict = {
381
+ status: "refused",
382
+ blocker: "read-arg-alias-conflict",
383
+ tool: toolName,
384
+ alias: aliased.conflict.alias,
385
+ canonicalKey: aliased.conflict.canonical,
386
+ message: `同时传了 ${aliased.conflict.alias} 与 ${aliased.conflict.canonical}:${aliased.conflict.alias} 是 ${aliased.conflict.canonical} 的同义别名,二者只能留一个(名字里的语义不同——${aliased.conflict.alias} 不会静默覆盖显式给的 ${aliased.conflict.canonical})`,
387
+ };
388
+ return { kind: "exit", exit: { exitCode: CLI_EXIT_CODES.policyRefused, ...(environment !== undefined ? { environment } : {}), emission: { via: "emit", status: "refused", result: conflict } } };
389
+ }
390
+ parsedArgs = aliased.args;
391
+ aliasesApplied = aliased.applied;
392
+ }
393
+ // r29f F7:读面未知参数默认硬拒(与写面 tool-input-unknown-keys 对齐);
394
+ // 显式 `lenientArgs:true` 才回退到旧的 ignoredArgs 回显。
395
+ //
396
+ // F6(r27):应用级键(appCode/applicationCode/application)静默回落会把写
397
+ // 操作打到错误应用——这些键被忽略时直接拒绝,不进 ignoredArgs。
398
+ const ignoredReadKeys = [];
399
+ if (tool) {
400
+ const schemaKeys = new Set(Object.keys(tool.inputSchema));
401
+ const recognized = new Set(["environment", "capability", "requestId", "dryRun", "lenientArgs"]);
402
+ // r54 C② F2:工具声明的输入别名同义词也算 recognized(工具层归一化接管);
403
+ // 否则读面先拒、写面却放行的双标准。
404
+ for (const synonym of inputAliasSynonymKeys(tool.name))
405
+ recognized.add(synonym);
406
+ const lenientArgs = parsedArgs.lenientArgs === true;
407
+ const unknownKeys = Object.keys(parsedArgs).filter((key) => !schemaKeys.has(key) && !recognized.has(key));
408
+ const appScopeUnknown = unknownKeys.filter((key) => APP_SCOPE_ARG_KEYS.has(key));
409
+ if (appScopeUnknown.length > 0) {
410
+ const hasApplicationCode = schemaKeys.has("applicationCode");
411
+ const hasAppCode = schemaKeys.has("appCode");
412
+ const wrong = appScopeUnknown.join("、");
413
+ // r29a F7:schema 两个应用范围键都没有时,旧文案回退成
414
+ // 「请改用 applicationCode(或 appCode…)」——调用方传的正是它,形成死循环。
415
+ // 这种工具根本没有应用范围参数(如 rule.* 按 schemaCode 定位),走专用 blocker。
416
+ if (!hasApplicationCode && !hasAppCode) {
417
+ const locateBy = schemaKeys.has("schemaCode")
418
+ ? "schemaCode(模型 code)"
419
+ : schemaKeys.has("code")
420
+ ? "code"
421
+ : "本工具自己的定位键(见 omc describe)";
422
+ const result = {
423
+ status: "refused",
424
+ blocker: "tool-has-no-app-scope",
425
+ tool: toolName,
426
+ ignored: appScopeUnknown,
427
+ locateBy,
428
+ message: `本工具没有应用范围参数(不接受 applicationCode/appCode);你传的 ${wrong} 不会生效。` +
429
+ `它按 ${locateBy} 定位——应用边界请在 model.*/folder.*/app.* 面使用。` +
430
+ `(\`omc describe ${toolName}\` 可确认参数表)`,
431
+ };
432
+ return { kind: "exit", exit: { exitCode: CLI_EXIT_CODES.policyRefused, ...(environment !== undefined ? { environment } : {}), emission: { via: "emit", status: "refused", result } } };
433
+ }
434
+ const canonical = hasApplicationCode ? "applicationCode" : "appCode";
435
+ const result = {
436
+ status: "refused",
437
+ blocker: "unknown-app-scope-arg",
438
+ tool: toolName,
439
+ ignored: appScopeUnknown,
440
+ acceptedAppScopeArg: canonical,
441
+ message: `本工具的应用范围参数叫 ${canonical},你传的 ${wrong} 不会生效——为避免写到错误应用,本次调用已拒绝。请改用 ${canonical} 后重试(\`omc describe ${toolName}\` 可确认参数表)。`,
442
+ };
443
+ return { kind: "exit", exit: { exitCode: CLI_EXIT_CODES.policyRefused, ...(environment !== undefined ? { environment } : {}), emission: { via: "emit", status: "refused", result } } };
444
+ }
445
+ const otherUnknown = unknownKeys.filter((key) => !APP_SCOPE_ARG_KEYS.has(key));
446
+ if (tool.kind !== "write" && otherUnknown.length > 0) {
447
+ if (!lenientArgs) {
448
+ // 探针 J F4/F5:可执行替代由 TOOL_KEY_ALTERNATIVES 提供(tool+key 显式
449
+ // 登记),替代出现在 suggestions[].replaceWith/hint/nextCommand;没有
450
+ // 登记的键沿用旧口径({key} 只表「被拒」,不编造改名——见 0.8.4 C1)。
451
+ const suggestions = otherUnknown.map((key) => ({ key, ...suggestArgumentKey(key, [...schemaKeys], toolName) }));
452
+ const pairs = suggestions.map((entry) => {
453
+ if (entry.replaceWith !== undefined)
454
+ return `${entry.key}→${entry.replaceWith}${entry.hint !== undefined ? `(${entry.hint})` : ""}`;
455
+ if (entry.hint)
456
+ return `${entry.key}(${entry.hint})`;
457
+ if (entry.closest)
458
+ return `${entry.key}→${entry.closest}`;
459
+ if (entry.absentInTool)
460
+ return `${entry.key}(本工具没有 ${entry.absentInTool})`;
461
+ return entry.key;
462
+ });
463
+ const explicitNext = suggestions.find((entry) => entry.nextCommand !== undefined)?.nextCommand;
464
+ const result = {
465
+ status: "error",
466
+ blocker: "tool-input-unknown-keys",
467
+ tool: toolName,
468
+ unknownKeys: otherUnknown,
469
+ // F1(retro 22,ticket 138):与写面同款机器字段——被拒键 + 合法键全集
470
+ // 成对给出;nextCommand 指向「最接近的合法键」的参数面(而非整份
471
+ // describe),脚本可零解析消费。
472
+ expectedKeys: [...schemaKeys],
473
+ suggestions,
474
+ // 显式替代(探针 J)优先给可复制命令;其次有拼写近邻时直达该参数的
475
+ // describe;否则退回整份参数表。
476
+ ...(explicitNext !== undefined
477
+ ? { nextCommand: explicitNext }
478
+ : suggestions.some((entry) => entry.closest !== undefined)
479
+ ? { nextCommand: `omc describe ${toolName} --param ${suggestions.find((entry) => entry.closest !== undefined).closest}` }
480
+ : { nextCommand: `omc describe ${toolName}` }),
481
+ message: `读面不接受未知键(与写面对齐):${pairs.join("、")}。` +
482
+ // C1(0.8.4):没有可信的改写建议时,不编造改名——直接把该工具的
483
+ // 真实参数名列出来,让人按名字挑。探针 J:混合键里只要有一个键
484
+ // 没拿到替代(如 all 有 replaceWith、zzz 没有),仍要列真实参数。
485
+ `${suggestions.some((entry) => entry.closest === undefined && entry.hint === undefined && entry.absentInTool === undefined && entry.replaceWith === undefined) ? `本工具的真实参数:${[...schemaKeys].join("、")}。` : ""}` +
486
+ `改用合法键后重试;确需宽松忽略传 lenientArgs:true。参数表:omc describe ${toolName}`,
487
+ };
488
+ return { kind: "exit", exit: { exitCode: CLI_EXIT_CODES.invalidInput, ...(environment !== undefined ? { environment } : {}), emission: { via: "emit", status: "error", result } } };
489
+ }
490
+ for (const key of otherUnknown) {
491
+ ignoredReadKeys.push({ key, ...suggestArgumentKey(key, [...schemaKeys], toolName) });
492
+ }
493
+ }
494
+ }
495
+ if (tool) {
496
+ try {
497
+ parsedArgs = parseToolInput(tool, {
498
+ ...parsedArgs,
499
+ ...(environment && parsedArgs.environment === undefined ? { environment } : {}),
500
+ ...(requestValue !== undefined ? { requestId: requestValue } : {}),
501
+ ...(dryRun ? { dryRun: true } : {}),
502
+ });
503
+ }
504
+ catch (error) {
505
+ const result = error instanceof ToolInputError ? error.payload : { status: "error", message: error instanceof Error ? error.message : String(error) };
506
+ return { kind: "exit", exit: { exitCode: CLI_EXIT_CODES.invalidInput, ...(environment !== undefined ? { environment } : {}), emission: { via: "emit", status: "error", result } } };
507
+ }
508
+ }
509
+ // GitLab #47:显式 --env 指向未配置环境时,恢复动作是「去掉 --env 重跑本次
510
+ // 调用」。在进入执行面(会话/写锁/wire)之前给出,stderr 与 stdout 同一份
511
+ // 文案,不必让 agent 再撞一次。只处理 unknown environment;跨环境拒绝/凭据
512
+ // 缺失的恢复动作不同,继续走原有分类。
513
+ if (environment !== undefined && tool !== undefined) {
514
+ try {
515
+ if (!store.readConfig().environments[environment])
516
+ store.resolveEnvironment(environment);
517
+ }
518
+ catch (error) {
519
+ const message = error instanceof Error ? error.message : String(error);
520
+ if (/^unknown environment "/u.test(message)) {
521
+ const result = withUnknownEnvironmentRecovery({ status: "error", message }, { tool: toolName, ...(rawArgs !== undefined ? { rawArgs } : {}), ...(argsFile !== undefined ? { argsFile } : {}), parsedArgs });
522
+ return {
523
+ kind: "exit",
524
+ exit: {
525
+ exitCode: CLI_EXIT_CODES.authConfig,
526
+ ...(environment !== undefined ? { environment } : {}),
527
+ emission: { via: "emit", status: "error", result },
528
+ stderr: { channel: "summary", text: JSON.stringify(result) },
529
+ },
530
+ };
531
+ }
532
+ }
533
+ }
534
+ return {
535
+ kind: "call",
536
+ parsed: {
537
+ toolName,
538
+ tool,
539
+ registry,
540
+ environment,
541
+ requestValue,
542
+ writeReason,
543
+ rawArgs,
544
+ argsFile,
545
+ parsedArgs,
546
+ extractPaths,
547
+ extractKeys,
548
+ explainProjection,
549
+ dryRun,
550
+ waitMs,
551
+ timeoutMs,
552
+ aliasesApplied,
553
+ ignoredReadKeys,
554
+ },
555
+ };
556
+ }
557
+ //# sourceMappingURL=call-input.js.map