@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/cli.js
CHANGED
|
@@ -12,34 +12,34 @@ import { homedir } from "node:os";
|
|
|
12
12
|
import { stdin, argv } from "node:process";
|
|
13
13
|
import { createRequire } from "node:module";
|
|
14
14
|
import { Command, CommanderError, Option } from "commander";
|
|
15
|
-
import { ConfigStore, defaultPaths, removedProfileKeys
|
|
15
|
+
import { ConfigStore, defaultPaths, removedProfileKeys } from "./config-store.js";
|
|
16
16
|
import { loadCoverageManifest, versionFamilyNotice } from "./coverage.js";
|
|
17
17
|
import { redactText } from "./redact.js";
|
|
18
|
-
import {
|
|
19
|
-
import { BATCH_MAX_ENTRIES, runBatchCall } from "./batch-call.js";
|
|
18
|
+
import { toolsByTextIntent } from "./call.js";
|
|
20
19
|
import { cmdModelScaffold } from "./model-scaffold.js";
|
|
21
20
|
import { cmdFieldAdd } from "./field-add.js";
|
|
22
21
|
import { cmdModelPurge } from "./model-purge.js";
|
|
23
22
|
import { cmdProgrammingAdopt, cmdProgrammingApply, cmdProgrammingPull, cmdProgrammingStatus, cmdProgrammingTest } from "./programming-workflow.js";
|
|
24
23
|
import { environmentWritable, requiresProductionConfirmation } from "./environment-policy.js";
|
|
25
|
-
import { CLI_EXIT_CODES, asciiStdout,
|
|
24
|
+
import { CLI_EXIT_CODES, asciiStdout, envelope, errorEnvelope, humanUtf8, installCodePageSafeStderr, requestId } from "./cli-contract.js";
|
|
26
25
|
import { ownsStdout } from "./cli-stdout.js";
|
|
27
26
|
import { installStdoutPipeGuard } from "./stdout-pipe.js";
|
|
28
27
|
import { formatDoctorHumanSummary, unsupportedCapabilities } from "./version-family-gaps.js";
|
|
29
|
-
import {
|
|
28
|
+
import { configureOutput, outputOptions, setOutReceiptHint, stripOutputFlags, writeEnvelope } from "./cli-output.js";
|
|
30
29
|
import { beginUsage, completeUsage, currentUsageArgsDigest, ensureProjectIgnore, priorIdenticalSuccess, recordUsageOutput, usageReport } from "./usage-log.js";
|
|
31
|
-
import {
|
|
30
|
+
import { artifactRoot, boundResult, emitInvalid, emitResult, emitThrown, emitTransportResult, withTransport, } from "./command-transport.js";
|
|
32
31
|
import { CLI_DEFAULT_OUTPUT_BYTES, assertSafeOutputPath, pruneArtifacts } from "./artifacts.js";
|
|
33
|
-
import {
|
|
32
|
+
import { suggestArgumentKey } from "./call-input.js";
|
|
33
|
+
export { suggestArgumentKey };
|
|
34
|
+
import { runCallCommand } from "./call-command.js";
|
|
35
|
+
import { cmdArtifactGet, extractArtifactGetOutFlag } from "./artifact-cmd.js";
|
|
34
36
|
import { closeWritableWindow, openWritableWindow, parseWritableTtl, sweepWritableWindowsAtStartup, validateWritableReason, writableWindowStatus, WRITABLE_WINDOW_DEFAULT_TTL_MINUTES, WRITABLE_WINDOW_LOG, WRITABLE_WINDOW_MAX_TTL_MINUTES, WritableWindowInputError } from "./writable-window.js";
|
|
35
|
-
import {
|
|
37
|
+
import { projectResultExtract } from "./path-projection.js";
|
|
36
38
|
import { isUncertainWireError } from "./support.js";
|
|
37
|
-
import { containerKeyOf } from "./read.js";
|
|
38
39
|
import { dirname, join, resolve } from "node:path";
|
|
39
|
-
import { existsSync, readFileSync, writeFileSync,
|
|
40
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
40
41
|
import { buildToolRegistry } from "./tools.js";
|
|
41
42
|
import { parseDurationMs } from "./duration.js";
|
|
42
|
-
import { acquireWriteLock, writeLockHeldFace } from "./write-lock.js";
|
|
43
43
|
import { cmdCompute } from "./compute.js";
|
|
44
44
|
import { cmdRuleWhen } from "./rule-when.js";
|
|
45
45
|
import { cmdApprovalFlow } from "./approval-flow.js";
|
|
@@ -57,9 +57,7 @@ else if (process.env.OMC_ASCII_STDOUT !== "0" && process.argv.some((arg) => arg
|
|
|
57
57
|
}
|
|
58
58
|
import { SEARCH_MARGIN_THRESHOLD } from "./tool-search.js";
|
|
59
59
|
import { commandCapabilitySlice, commandIndex, commandInventory, commandKindIndex, describeContract, describeContractFull, describeContractTool, describeExample, describeParam, describeSchemaOnly, describeTool, describeToolFull, filterTools } from "./discovery.js";
|
|
60
|
-
import { locatorMetaFor } from "./read-shapes.js";
|
|
61
60
|
import { surfaceRefFor } from "./surface-ref.js";
|
|
62
|
-
import { KEY_ALIAS_HINTS, TOOL_KEY_ALTERNATIVES, inputAliasSynonymKeys } from "./tool-types.js";
|
|
63
61
|
import { repeatFullDescribe } from "./describe-cache.js";
|
|
64
62
|
import { buildCapabilityOverview, capabilityCandidatesFor, capabilityDetail, capabilityRouteForTool, capabilityRouteIndex, compactCapabilities, executableCapabilityBundle, resolveCapabilityId, DISCOVERY_AUTHORITY } from "./capability-overview.js";
|
|
65
63
|
import { goalRoute } from "./goal-routes.js";
|
|
@@ -69,7 +67,6 @@ import { planGoal, planToNdjson, planToNdjsonSkipped } from "./goal-plan.js";
|
|
|
69
67
|
import { intentSchemaBlock, intentExample, intentExampleIds } from "./intent/schema.js";
|
|
70
68
|
import { planIntent, readbackIntent, applyIntent, intentWarnings } from "./intent/plan-apply.js";
|
|
71
69
|
import { listSkills, readSkill, readSkillOutline, readSkillSection, searchSkills, suggestHelpTopics } from "./skills.js";
|
|
72
|
-
import { parseToolInput, ToolInputError } from "./tool-types.js";
|
|
73
70
|
import { WireError, wireCall } from "./wire.js";
|
|
74
71
|
import { describeWireFailure } from "./wire-failure.js";
|
|
75
72
|
import { DEFAULT_PULL_CONCURRENCY, GraphIndexAmbiguousError, GraphIndexError, GraphIndexUnreadableError, GraphPullLockHeldError, GraphPullTimeoutError, DEFAULT_GRAPH_PULL_TIMEOUT_MS, MAX_GRAPH_PULL_TIMEOUT_MS, MAX_PULL_CONCURRENCY, graphDbPath, graphRoot, impactGraph, listGraphIndexes, publishGraphPull, queryGraphReferences, queryGraphReferencesBatch, queryGraphEdges, readGraphStatus, searchGraphRules, } from "./graph.js";
|
|
@@ -417,929 +414,6 @@ function doctorAnchor() {
|
|
|
417
414
|
"落盘 远端写=环境 writable 决定的平台变更;本地落盘=.omc/(artifacts/usage/describe 缓存,读面也会写;usage 台账只供维护者计量,agent 不要读它自查成本——你的成本口径=轮数+字节)。可用 OMC_CONFIG_HOME 重定位配置根(其下 .omc/),或 OMC_ARTIFACTS_HOME 单独重定位产物目录",
|
|
418
415
|
].join("\n");
|
|
419
416
|
}
|
|
420
|
-
function flag0(args, name) {
|
|
421
|
-
return argvValue(args, name);
|
|
422
|
-
}
|
|
423
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
424
|
-
/**
|
|
425
|
-
* `omc call <tool> --args-list '<json array>'` — see batch-call.ts for why this
|
|
426
|
-
* exists. The envelope is a summary; per-entry outcomes only appear for
|
|
427
|
-
* failures so a successful batch of 8 costs one short response, not eight.
|
|
428
|
-
*/
|
|
429
|
-
async function cmdBatchCall(store, toolName, rawList, options) {
|
|
430
|
-
const request = options.requestValue ?? requestId();
|
|
431
|
-
// issue 07:批量面同款——汇总信封(含 preflight)都带 resultMeta.sessionAccount。
|
|
432
|
-
const accountMeta = () => ({ sessionAccount: sessionAccountForEnvironment(store, options.environment) });
|
|
433
|
-
let parsed;
|
|
434
|
-
try {
|
|
435
|
-
parsed = JSON.parse(rawList);
|
|
436
|
-
}
|
|
437
|
-
catch (error) {
|
|
438
|
-
const message = `--args-list 必须是 JSON 数组:${error instanceof Error ? error.message : String(error)}`;
|
|
439
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
440
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
441
|
-
}
|
|
442
|
-
if (!Array.isArray(parsed)) {
|
|
443
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 必须是 JSON 数组(每条是一个 args 对象)", retryable: false }), resultMeta: accountMeta() });
|
|
444
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
445
|
-
}
|
|
446
|
-
const entries = parsed;
|
|
447
|
-
const badIndex = entries.findIndex((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry));
|
|
448
|
-
if (badIndex >= 0) {
|
|
449
|
-
writeEnvelope({ ...envelope("error", {}, request, {
|
|
450
|
-
code: "invalid-input",
|
|
451
|
-
message: `--args-list 第 ${badIndex} 条不是对象(每条必须是 {"字段":值} 形状)`,
|
|
452
|
-
retryable: false,
|
|
453
|
-
}), resultMeta: accountMeta() });
|
|
454
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
455
|
-
}
|
|
456
|
-
if (entries.length === 0) {
|
|
457
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 至少一条", retryable: false }), resultMeta: accountMeta() });
|
|
458
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
459
|
-
}
|
|
460
|
-
if (entries.length > BATCH_MAX_ENTRIES) {
|
|
461
|
-
writeEnvelope({ ...envelope("error", {}, request, {
|
|
462
|
-
code: "invalid-input",
|
|
463
|
-
message: `--args-list 最多 ${BATCH_MAX_ENTRIES} 条(本次 ${entries.length});分批执行或用 omc script 读文件`,
|
|
464
|
-
retryable: false,
|
|
465
|
-
}), resultMeta: accountMeta() });
|
|
466
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
467
|
-
}
|
|
468
|
-
try {
|
|
469
|
-
for (const entry of entries)
|
|
470
|
-
validateAgentPaths(entry);
|
|
471
|
-
}
|
|
472
|
-
catch (error) {
|
|
473
|
-
writeEnvelope({ ...envelope("error", {}, request, {
|
|
474
|
-
code: "invalid-input",
|
|
475
|
-
message: `--args-list 含越界路径:${error instanceof Error ? error.message : String(error)}`,
|
|
476
|
-
retryable: false,
|
|
477
|
-
}), resultMeta: accountMeta() });
|
|
478
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
479
|
-
}
|
|
480
|
-
// Whole-batch shape precheck (issue 2026-10-25 §6): `--args-list --dry-run`
|
|
481
|
-
// runs every entry through the full tool (reads included) to report N
|
|
482
|
-
// previews. When the caller only wants "will this batch be accepted", the
|
|
483
|
-
// per-tool semantic gate is the thing that refuses mis-shapes, and it is
|
|
484
|
-
// pure — no wire, no writes. Run it for every entry and report ALL failures
|
|
485
|
-
// in one envelope instead of N round-trips.
|
|
486
|
-
if (options.preflight === true) {
|
|
487
|
-
const registry = buildToolRegistry();
|
|
488
|
-
const tool = registry.find((definition) => definition.name === toolName);
|
|
489
|
-
if (!tool) {
|
|
490
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: `unknown tool ${toolName};用 omc next 或 omc commands --json --compact --lane <lane> 定位`, retryable: false }), resultMeta: accountMeta() });
|
|
491
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
492
|
-
}
|
|
493
|
-
const failures = [];
|
|
494
|
-
entries.forEach((entry, index) => {
|
|
495
|
-
try {
|
|
496
|
-
const parsedEntry = parseToolInput(tool, {
|
|
497
|
-
...entry,
|
|
498
|
-
...(options.environment !== undefined && entry.environment === undefined ? { environment: options.environment } : {}),
|
|
499
|
-
});
|
|
500
|
-
tool.writePreflight?.(parsedEntry);
|
|
501
|
-
}
|
|
502
|
-
catch (error) {
|
|
503
|
-
// ToolRefusalError carries the real payload (blocker/citation/validation);
|
|
504
|
-
// rebuild it only when the failure is a plain Error.
|
|
505
|
-
const carried = error.payload;
|
|
506
|
-
const payload = error instanceof ToolInputError ? error.payload : carried ?? { status: "refused", blocker: "tool-input-invalid", message: error instanceof Error ? error.message : String(error) };
|
|
507
|
-
failures.push({ index, blocker: payload.blocker ?? null, message: refusalText(payload), ...(Array.isArray(payload.validation) ? { validation: payload.validation } : {}), ...(payload.citation !== undefined ? { citation: payload.citation } : {}) });
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
let result = {
|
|
511
|
-
status: failures.length > 0 ? "partial" : "ok",
|
|
512
|
-
mode: "preflight",
|
|
513
|
-
shapeOnly: true,
|
|
514
|
-
tool: toolName,
|
|
515
|
-
requested: entries.length,
|
|
516
|
-
shapeChecked: entries.length,
|
|
517
|
-
failed: failures.length,
|
|
518
|
-
writes: 0,
|
|
519
|
-
// On failure the caller has to change the JSON first, so there is no
|
|
520
|
-
// runnable command yet; on success, hand over the exact execution command.
|
|
521
|
-
...(failures.length > 0 ? { failures } : { nextCommand: `omc call ${toolName} --args-list '<file|stdin>'` }),
|
|
522
|
-
};
|
|
523
|
-
const preflightPaths = [...argvValues(options.args, "--extract"), ...argvValues(options.args, "--jq")]
|
|
524
|
-
.flatMap((path) => path.split(",")).map((path) => path.trim()).filter(Boolean);
|
|
525
|
-
const preflightKeys = options.args.includes("--extract-keys") || options.args.includes("--keys") || options.args.some((token, index) => token === "--jq" && (options.args[index + 1] === undefined || options.args[index + 1].startsWith("--")));
|
|
526
|
-
if (preflightPaths.length > 0 || preflightKeys) {
|
|
527
|
-
const projected = projectResultExtract(result, preflightPaths, preflightKeys, { tool: toolName, ...(options.environment !== undefined ? { environment: options.environment } : {}) });
|
|
528
|
-
if (projected !== undefined)
|
|
529
|
-
result = projected;
|
|
530
|
-
}
|
|
531
|
-
const classified = classifyResult(result);
|
|
532
|
-
// 与 `omc call --jq` 同一契约(issue 2026-11-18 §05):单路径命中时 result 是本体。
|
|
533
|
-
const unwrapped = preflightPaths.length === 1 && !preflightKeys && Array.isArray(result.extract)
|
|
534
|
-
? unwrapSinglePathProjection(result)
|
|
535
|
-
: undefined;
|
|
536
|
-
const envelopeValue = envelope(classified.status, unwrapped !== undefined ? unwrapped.result : result, request, classified.error);
|
|
537
|
-
writeEnvelope({
|
|
538
|
-
...envelopeValue,
|
|
539
|
-
resultMeta: { sessionAccount: accountMeta().sessionAccount, ...(unwrapped?.resultMeta ?? {}) },
|
|
540
|
-
});
|
|
541
|
-
return failures.length > 0 ? 1 : 0;
|
|
542
|
-
}
|
|
543
|
-
const batched = await runBatchCall({
|
|
544
|
-
tool: toolName,
|
|
545
|
-
argsList: entries,
|
|
546
|
-
...(options.environment !== undefined ? { environment: options.environment } : {}),
|
|
547
|
-
...(options.args.includes("--dry-run") ? { dryRun: true } : {}),
|
|
548
|
-
...(options.reason !== undefined ? { reason: options.reason } : {}),
|
|
549
|
-
requestId: request,
|
|
550
|
-
});
|
|
551
|
-
const classified = classifyResult(batched.result);
|
|
552
|
-
writeEnvelope({ ...envelope(classified.status, batched.result, request, classified.error), resultMeta: accountMeta() });
|
|
553
|
-
return batched.exitCode;
|
|
554
|
-
}
|
|
555
|
-
async function cmdCall(store, args) {
|
|
556
|
-
const request = flag0(args, "--request-id") ?? requestId();
|
|
557
|
-
// issue 07(retro 2026-11-19):每次 omc call 的回执(成功与错误信封)都带
|
|
558
|
-
// resultMeta.sessionAccount——token 解码(0 wire),解不出就回 unavailableReason,
|
|
559
|
-
// 不谎报。环境旗标解析出来之前 callEnvironment 是 undefined,按默认环境解析。
|
|
560
|
-
let callEnvironment;
|
|
561
|
-
const accountMeta = () => ({ sessionAccount: sessionAccountForEnvironment(store, callEnvironment) });
|
|
562
|
-
let maxOutputBytes;
|
|
563
|
-
try {
|
|
564
|
-
maxOutputBytes = outputBudget(args);
|
|
565
|
-
}
|
|
566
|
-
catch (error) {
|
|
567
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
568
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
569
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
570
|
-
}
|
|
571
|
-
const emit = (status, result, exitCode, extra) => {
|
|
572
|
-
if (status === "uncertain" && result !== null && typeof result === "object" && !Array.isArray(result) && result.nextAction === undefined)
|
|
573
|
-
result = { ...result, nextAction: "read back the requestId before retrying; retry only after the outcome is established" };
|
|
574
|
-
// F7(0.8.17 真机 P1):`result` 可能是 --jq 单路径解包后的**叶子**(null /
|
|
575
|
-
// 标量 / 数组),不是工具结果。此处再 classifyResult 会走 `.status`:
|
|
576
|
-
// discover_environment 缓存命中 `models:null` 时 `--jq models` 直接 internal
|
|
577
|
-
// (Cannot read properties of null);标量叶子则把 refused 翻成 ok:true。
|
|
578
|
-
// 结论以**投影前**的分类为准——单路径解包时由调用方放进 extra.error。
|
|
579
|
-
const carriedError = extra !== undefined && Object.prototype.hasOwnProperty.call(extra, "error")
|
|
580
|
-
? extra.error
|
|
581
|
-
: undefined;
|
|
582
|
-
const classifiedError = carriedError !== undefined
|
|
583
|
-
? carriedError
|
|
584
|
-
: result !== null && typeof result === "object" && !Array.isArray(result)
|
|
585
|
-
? classifyResult(result).error
|
|
586
|
-
: null;
|
|
587
|
-
// 回归(0.8.17 复核):字符串叶子仍必须受 stdout 预算约束——否则 `--jq` 取
|
|
588
|
-
// 一个 >64KiB 的字符串会整段内联,破「大读回不内联」。number/boolean/null
|
|
589
|
-
// 有界,原样返回。
|
|
590
|
-
const bounded = result !== null && typeof result === "object"
|
|
591
|
-
? boundResult(result, maxOutputBytes)
|
|
592
|
-
: typeof result === "string"
|
|
593
|
-
? boundResult(result, maxOutputBytes)
|
|
594
|
-
: result;
|
|
595
|
-
const envelopeValue = envelope(status, bounded, request, classifiedError);
|
|
596
|
-
// issue 2026-11-18 §05:单路径 --jq 解包后,`result` 是目标节点本体(可能是
|
|
597
|
-
// 数组/标量,装不进结果对象),路径来源等元信息放信封旁的 `resultMeta`。
|
|
598
|
-
// issue 07:sessionAccount 恒在 resultMeta(瘦身影封保留 resultMeta)。
|
|
599
|
-
writeEnvelope({
|
|
600
|
-
...envelopeValue,
|
|
601
|
-
...(extra !== undefined ? { ...extra, resultMeta: { sessionAccount: accountMeta().sessionAccount, ...(extra.resultMeta ?? {}) } } : { resultMeta: accountMeta() }),
|
|
602
|
-
});
|
|
603
|
-
maybeWarnMergedStreams();
|
|
604
|
-
return exitCode;
|
|
605
|
-
};
|
|
606
|
-
const flag = (name) => argvValue(args, name);
|
|
607
|
-
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")));
|
|
608
|
-
const toolName = positional[0];
|
|
609
|
-
if (!toolName || toolName === "help" || args.includes("--help")) {
|
|
610
|
-
// r29f F3:`omc call <tool> --help` 识别具名工具时转发 describe 摘要,
|
|
611
|
-
// 并写死输出预算默认值(别只回通用 call 选项)。
|
|
612
|
-
if (toolName && toolName !== "help") {
|
|
613
|
-
const registry = buildToolRegistry();
|
|
614
|
-
const described = describeTool(registry, toolName);
|
|
615
|
-
if (described) {
|
|
616
|
-
console.error(`工具:${toolName}`);
|
|
617
|
-
console.error(`输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192`);
|
|
618
|
-
console.error(`投影:--jq 不是 jq,仅路径选择器;--jq/--extract 相对 result(不要写 result. 前缀;误写会自动剥并标 autoStripped);先投影再判预算`);
|
|
619
|
-
return emitTransportResult({ status: "ok", ...described, helpNote: "来自 omc describe;完整面用 omc describe <tool> [--full|--param|--example]" }, { request, maxOutputBytes });
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
console.error("用法:omc call <tool> [--env <环境>] [--args '<json>' | --args - (stdin) | --args-file <配置根内路径(必须位于配置根内;数组批量请改用 --args-list;跨目录临时文件用 --args -(stdin))>] [--extract <path>]... [--jq [path]] [--extract-keys] [--args-list <json数组>(最多 200 条;超出请分批或用 omc script 读文件) [--preflight]] [--reason <写入原因(审计)>]");
|
|
623
|
-
console.error("输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192");
|
|
624
|
-
console.error("写入:由环境 writable 决定(只读环境拒写);生产环境的写必须在 args 里带 confirmProduction:true。");
|
|
625
|
-
console.error("会话账号:每次回执 resultMeta.sessionAccount(token 解码:id=user_id、username=user_name、name=登录显示名;解不出回 unavailableReason)。报错里的 currentUser 是平台按 username 反查的 id,同名多账号时与 id 不同——排查 not-mine 先看这两个是否同一个人。");
|
|
626
|
-
return emit(toolName && toolName !== "help" ? "error" : "ok", {}, toolName && toolName !== "help" ? CLI_EXIT_CODES.invalidInput : 0);
|
|
627
|
-
}
|
|
628
|
-
const environment = (callEnvironment = flag("--env") ?? flag("--environment"));
|
|
629
|
-
const requestValue = flag("--request-id");
|
|
630
|
-
// R88 #3:写审计原因(只进 artifact/journal,不是工具参数,也不是门禁)。
|
|
631
|
-
const writeReason = flag("--reason");
|
|
632
|
-
if (writeReason !== undefined && writeReason.trim().length === 0) {
|
|
633
|
-
const message = "--reason 不能为空:给一句话说明本次写的目的(只记审计,不影响门禁)";
|
|
634
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
635
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
636
|
-
}
|
|
637
|
-
// Batch mode: the SAME tool N times, one process (r12: 36 field.create calls).
|
|
638
|
-
const argsList = flag("--args-list");
|
|
639
|
-
if (argsList !== undefined)
|
|
640
|
-
return cmdBatchCall(store, toolName, argsList, { environment, requestValue, args, preflight: args.includes("--preflight"), ...(writeReason !== undefined ? { reason: writeReason } : {}) });
|
|
641
|
-
if (args.includes("--preflight")) {
|
|
642
|
-
const message = "--preflight 仅用于 --args-list 批量形状;单次调用没有批量预检语义。请改用 --args-list,或移除 --preflight 后执行单次调用。";
|
|
643
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
644
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
645
|
-
}
|
|
646
|
-
// 1.2 of issue 2026-10-23: read faces answer {detailArtifactId, sha256} and the
|
|
647
|
-
// caller then needs a SECOND call to see one value (16 two-step chains in one
|
|
648
|
-
// session; 15 more were pure --keys probes). `--extract <path>` (repeatable)
|
|
649
|
-
// resolves the path inside the artifact of THIS result and returns only the
|
|
650
|
-
// value; `--extract-keys` lists the artifact's top-level keys with sizes.
|
|
651
|
-
//
|
|
652
|
-
// issue 2026-10-25 §8: `artifact get` had `--jq` while `omc call` did not, so
|
|
653
|
-
// every list read that only wanted one column paid a second artifact round.
|
|
654
|
-
// `--jq` is the same path projection plus `[]` fan-out; a bare `--jq` is the
|
|
655
|
-
// key inventory (the same muscle memory as `artifact get <id> --jq`).
|
|
656
|
-
const extractPaths = [...argvValues(args, "--extract"), ...argvValues(args, "--jq")]
|
|
657
|
-
// A3(GitLab #15):逗号多路径——一张 9 列表此前要 9 次 artifact get。
|
|
658
|
-
// 路径语法(点式/下标/切片/[]/按键)不含逗号,拆分无歧义。
|
|
659
|
-
.flatMap((path) => path.split(","))
|
|
660
|
-
.map((path) => path.trim())
|
|
661
|
-
.filter(Boolean);
|
|
662
|
-
// `artifact get` uses `--keys`; `call` only had `--extract-keys`, so the muscle
|
|
663
|
-
// memory failed with "unknown option '--keys'" (r16 P7). Accept both.
|
|
664
|
-
const extractKeys = args.includes("--extract-keys") || args.includes("--keys") || args.some((token, index) => token === "--jq" && (args[index + 1] === undefined || args[index + 1].startsWith("--")));
|
|
665
|
-
// C6(0.8.4):pathMiss 默认只回结论(≤300B),完整排查载荷(available/
|
|
666
|
-
// correctPath/nextCommand/hint)只在显式 --explain 时给。
|
|
667
|
-
const explainProjection = args.includes("--explain");
|
|
668
|
-
const dryRun = args.includes("--dry-run");
|
|
669
|
-
const waitValue = flag("--wait");
|
|
670
|
-
let waitMs = 0;
|
|
671
|
-
if (waitValue !== undefined) {
|
|
672
|
-
waitMs = Number(waitValue);
|
|
673
|
-
if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 600_000) {
|
|
674
|
-
const message = "--wait must be an integer number of milliseconds from 0 to 600000";
|
|
675
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
676
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
let timeoutMs;
|
|
680
|
-
try {
|
|
681
|
-
if (requestValue !== undefined && requestValue.length === 0)
|
|
682
|
-
throw new Error("--request-id must not be empty");
|
|
683
|
-
const value = flag("--timeout-ms");
|
|
684
|
-
if (value !== undefined) {
|
|
685
|
-
timeoutMs = Number(value);
|
|
686
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 600_000)
|
|
687
|
-
throw new Error("--timeout-ms must be an integer from 1 to 600000");
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
catch (error) {
|
|
691
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
692
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
693
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
694
|
-
}
|
|
695
|
-
if (timeoutMs !== undefined)
|
|
696
|
-
process.env.OMC_HTTP_TIMEOUT_MS = String(timeoutMs);
|
|
697
|
-
const rawArgs = flag("--args");
|
|
698
|
-
const argsFile = flag("--args-file");
|
|
699
|
-
let parsedArgs = {};
|
|
700
|
-
try {
|
|
701
|
-
if (rawArgs !== undefined && argsFile !== undefined)
|
|
702
|
-
throw new Error("--args and --args-file are mutually exclusive");
|
|
703
|
-
if (rawArgs === "-")
|
|
704
|
-
parsedArgs = readStdinArgs();
|
|
705
|
-
else if (argsFile)
|
|
706
|
-
parsedArgs = readArgsFile(argsFile, resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd())));
|
|
707
|
-
else if (rawArgs) {
|
|
708
|
-
parsedArgs = JSON.parse(rawArgs);
|
|
709
|
-
if (parsedArgs === null || typeof parsedArgs !== "object" || Array.isArray(parsedArgs))
|
|
710
|
-
throw new Error("--args must be a JSON object");
|
|
711
|
-
}
|
|
712
|
-
validateAgentPaths(parsedArgs);
|
|
713
|
-
}
|
|
714
|
-
catch (error) {
|
|
715
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
716
|
-
// r10 F9: an out-of-root `--args-file` was reported under "--args 必须是
|
|
717
|
-
// 合法 JSON", which points the reader at the wrong flag. Name the real
|
|
718
|
-
// cause (and the configuration root) when the failure came from the file.
|
|
719
|
-
// 线上 #39-D:args-file 配置根与 .omc-envs 同源——worktree 下回退主检出
|
|
720
|
-
// (git 结构锚定),.scratch 参数文件不再因 worktree 被迫挪位置。
|
|
721
|
-
const configRoot = resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd()));
|
|
722
|
-
// 1.1 of issue 2026-10-23: the old hint told the caller to write a TEMP file
|
|
723
|
-
// while the validator only accepts paths under the config root — the two
|
|
724
|
-
// instructions contradicted each other and neither named the root. Offer a
|
|
725
|
-
// single executable recipe: an absolute path inside the root.
|
|
726
|
-
const outOfRoot = /must be inside the configuration root/.test(detail);
|
|
727
|
-
// 流畅性(GitLab #18 P3-8):PowerShell 把内联 JSON 拆坏时,报错形态是
|
|
728
|
-
// `Expected property name or '}' in JSON at position 1` / `Unexpected end of
|
|
729
|
-
// JSON input`——此时唯一有效的动作是改用文件或 stdin,而不是再调引号。
|
|
730
|
-
// 原来只在末尾附一句「若问题在引号转义…」,容易被当成补充说明;这里把它
|
|
731
|
-
// 提成主建议,并给出 PS 可粘贴的两条命令。
|
|
732
|
-
const looksLikeShellSplitting = /Unexpected (token|end of JSON)|Expected property name|position \d+/i.test(detail);
|
|
733
|
-
const message = argsFile !== undefined && /must be a JSON object/.test(detail)
|
|
734
|
-
? `${detail};--args-file 只收单个 JSON 对象,批量数组请改用 --args-list(最多 200 条,可分批执行)`
|
|
735
|
-
: outOfRoot
|
|
736
|
-
? `--args-file 越界:${detail}。可执行做法:把参数文件放到 ${configRoot} 之下(如 ${join(configRoot, "args.json")}),再用 --args-file 引用;不要把参数文件放在系统临时目录(配置根之外一律拒绝)`
|
|
737
|
-
: looksLikeShellSplitting
|
|
738
|
-
? `--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`
|
|
739
|
-
: `--args 必须是合法 JSON:${detail}。若问题在引号转义(Windows PowerShell),改用 --args-file <配置根内的路径> 或 --args -(stdin)`;
|
|
740
|
-
console.error(message);
|
|
741
|
-
// The MACHINE envelope must carry the same actionable text: agents read
|
|
742
|
-
// stdout, and the old envelope only repeated the English detail.
|
|
743
|
-
// Keep the FULL path the caller passed (resolved) in the envelope: the bare
|
|
744
|
-
// file name read like a relative path and sent the caller looking in cwd
|
|
745
|
-
// (F3, 0.8.15 probe I). The resolved path is the caller's own input, not a
|
|
746
|
-
// leaked host layout (ticket 103); it is what they must move into the root.
|
|
747
|
-
const rejectedPath = typeof argsFile === "string" ? resolve(configRoot, argsFile) : "";
|
|
748
|
-
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", 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, retryable: false, ...(outOfRoot ? { configurationRoot: configRoot } : {}) }), resultMeta: accountMeta() });
|
|
749
|
-
return CLI_EXIT_CODES.invalidInput;
|
|
750
|
-
}
|
|
751
|
-
const registry = buildToolRegistry();
|
|
752
|
-
const tool = registry.find((definition) => definition.name === toolName);
|
|
753
|
-
// C1(0.8.4):同义参数**先换算**再校验——未知键表里那两行(onlyCustom→all、
|
|
754
|
-
// pageSize→page)是语义不等价的改名,照做会拿到相反/更少的结果。这里接受
|
|
755
|
-
// 真实语义别名并回执 aliasesApplied,而不是把人引到另一个键。
|
|
756
|
-
let aliasesApplied = {};
|
|
757
|
-
// 只对读面换算:写面参数静默改写会改掉真实载荷,写面继续走严格未知键拒绝。
|
|
758
|
-
if (tool && tool.kind !== "write") {
|
|
759
|
-
const aliased = applyReadArgAliases(tool.name, new Set(Object.keys(tool.inputSchema)), parsedArgs);
|
|
760
|
-
if (aliased.conflict !== undefined) {
|
|
761
|
-
const conflict = {
|
|
762
|
-
status: "refused",
|
|
763
|
-
blocker: "read-arg-alias-conflict",
|
|
764
|
-
tool: toolName,
|
|
765
|
-
alias: aliased.conflict.alias,
|
|
766
|
-
canonicalKey: aliased.conflict.canonical,
|
|
767
|
-
message: `同时传了 ${aliased.conflict.alias} 与 ${aliased.conflict.canonical}:${aliased.conflict.alias} 是 ${aliased.conflict.canonical} 的同义别名,二者只能留一个(名字里的语义不同——${aliased.conflict.alias} 不会静默覆盖显式给的 ${aliased.conflict.canonical})`,
|
|
768
|
-
};
|
|
769
|
-
return emit("refused", conflict, CLI_EXIT_CODES.policyRefused);
|
|
770
|
-
}
|
|
771
|
-
parsedArgs = aliased.args;
|
|
772
|
-
aliasesApplied = aliased.applied;
|
|
773
|
-
}
|
|
774
|
-
// r29f F7:读面未知参数默认硬拒(与写面 tool-input-unknown-keys 对齐);
|
|
775
|
-
// 显式 `lenientArgs:true` 才回退到旧的 ignoredArgs 回显。
|
|
776
|
-
//
|
|
777
|
-
// F6(r27):应用级键(appCode/applicationCode/application)静默回落会把写
|
|
778
|
-
// 操作打到错误应用——这些键被忽略时直接拒绝,不进 ignoredArgs。
|
|
779
|
-
const ignoredReadKeys = [];
|
|
780
|
-
if (tool) {
|
|
781
|
-
const schemaKeys = new Set(Object.keys(tool.inputSchema));
|
|
782
|
-
const recognized = new Set(["environment", "capability", "requestId", "dryRun", "lenientArgs"]);
|
|
783
|
-
// r54 C② F2:工具声明的输入别名同义词也算 recognized(工具层归一化接管);
|
|
784
|
-
// 否则读面先拒、写面却放行的双标准。
|
|
785
|
-
for (const synonym of inputAliasSynonymKeys(tool.name))
|
|
786
|
-
recognized.add(synonym);
|
|
787
|
-
const lenientArgs = parsedArgs.lenientArgs === true;
|
|
788
|
-
const unknownKeys = Object.keys(parsedArgs).filter((key) => !schemaKeys.has(key) && !recognized.has(key));
|
|
789
|
-
const appScopeUnknown = unknownKeys.filter((key) => APP_SCOPE_ARG_KEYS.has(key));
|
|
790
|
-
if (appScopeUnknown.length > 0) {
|
|
791
|
-
const hasApplicationCode = schemaKeys.has("applicationCode");
|
|
792
|
-
const hasAppCode = schemaKeys.has("appCode");
|
|
793
|
-
const wrong = appScopeUnknown.join("、");
|
|
794
|
-
// r29a F7:schema 两个应用范围键都没有时,旧文案回退成
|
|
795
|
-
// 「请改用 applicationCode(或 appCode…)」——调用方传的正是它,形成死循环。
|
|
796
|
-
// 这种工具根本没有应用范围参数(如 rule.* 按 schemaCode 定位),走专用 blocker。
|
|
797
|
-
if (!hasApplicationCode && !hasAppCode) {
|
|
798
|
-
const locateBy = schemaKeys.has("schemaCode")
|
|
799
|
-
? "schemaCode(模型 code)"
|
|
800
|
-
: schemaKeys.has("code")
|
|
801
|
-
? "code"
|
|
802
|
-
: "本工具自己的定位键(见 omc describe)";
|
|
803
|
-
const result = {
|
|
804
|
-
status: "refused",
|
|
805
|
-
blocker: "tool-has-no-app-scope",
|
|
806
|
-
tool: toolName,
|
|
807
|
-
ignored: appScopeUnknown,
|
|
808
|
-
locateBy,
|
|
809
|
-
message: `本工具没有应用范围参数(不接受 applicationCode/appCode);你传的 ${wrong} 不会生效。` +
|
|
810
|
-
`它按 ${locateBy} 定位——应用边界请在 model.*/folder.*/app.* 面使用。` +
|
|
811
|
-
`(\`omc describe ${toolName}\` 可确认参数表)`,
|
|
812
|
-
};
|
|
813
|
-
return emit("refused", result, CLI_EXIT_CODES.policyRefused);
|
|
814
|
-
}
|
|
815
|
-
const canonical = hasApplicationCode ? "applicationCode" : "appCode";
|
|
816
|
-
const result = {
|
|
817
|
-
status: "refused",
|
|
818
|
-
blocker: "unknown-app-scope-arg",
|
|
819
|
-
tool: toolName,
|
|
820
|
-
ignored: appScopeUnknown,
|
|
821
|
-
acceptedAppScopeArg: canonical,
|
|
822
|
-
message: `本工具的应用范围参数叫 ${canonical},你传的 ${wrong} 不会生效——为避免写到错误应用,本次调用已拒绝。请改用 ${canonical} 后重试(\`omc describe ${toolName}\` 可确认参数表)。`,
|
|
823
|
-
};
|
|
824
|
-
return emit("refused", result, CLI_EXIT_CODES.policyRefused);
|
|
825
|
-
}
|
|
826
|
-
const otherUnknown = unknownKeys.filter((key) => !APP_SCOPE_ARG_KEYS.has(key));
|
|
827
|
-
if (tool.kind !== "write" && otherUnknown.length > 0) {
|
|
828
|
-
if (!lenientArgs) {
|
|
829
|
-
// 探针 J F4/F5:可执行替代由 TOOL_KEY_ALTERNATIVES 提供(tool+key 显式
|
|
830
|
-
// 登记),替代出现在 suggestions[].replaceWith/hint/nextCommand;没有
|
|
831
|
-
// 登记的键沿用旧口径({key} 只表「被拒」,不编造改名——见 0.8.4 C1)。
|
|
832
|
-
const suggestions = otherUnknown.map((key) => ({ key, ...suggestArgumentKey(key, [...schemaKeys], toolName) }));
|
|
833
|
-
const pairs = suggestions.map((entry) => {
|
|
834
|
-
if (entry.replaceWith !== undefined)
|
|
835
|
-
return `${entry.key}→${entry.replaceWith}${entry.hint !== undefined ? `(${entry.hint})` : ""}`;
|
|
836
|
-
if (entry.hint)
|
|
837
|
-
return `${entry.key}(${entry.hint})`;
|
|
838
|
-
if (entry.closest)
|
|
839
|
-
return `${entry.key}→${entry.closest}`;
|
|
840
|
-
if (entry.absentInTool)
|
|
841
|
-
return `${entry.key}(本工具没有 ${entry.absentInTool})`;
|
|
842
|
-
return entry.key;
|
|
843
|
-
});
|
|
844
|
-
const explicitNext = suggestions.find((entry) => entry.nextCommand !== undefined)?.nextCommand;
|
|
845
|
-
const result = {
|
|
846
|
-
status: "error",
|
|
847
|
-
blocker: "tool-input-unknown-keys",
|
|
848
|
-
tool: toolName,
|
|
849
|
-
unknownKeys: otherUnknown,
|
|
850
|
-
// F1(retro 22,ticket 138):与写面同款机器字段——被拒键 + 合法键全集
|
|
851
|
-
// 成对给出;nextCommand 指向「最接近的合法键」的参数面(而非整份
|
|
852
|
-
// describe),脚本可零解析消费。
|
|
853
|
-
expectedKeys: [...schemaKeys],
|
|
854
|
-
suggestions,
|
|
855
|
-
// 显式替代(探针 J)优先给可复制命令;其次有拼写近邻时直达该参数的
|
|
856
|
-
// describe;否则退回整份参数表。
|
|
857
|
-
...(explicitNext !== undefined
|
|
858
|
-
? { nextCommand: explicitNext }
|
|
859
|
-
: suggestions.some((entry) => entry.closest !== undefined)
|
|
860
|
-
? { nextCommand: `omc describe ${toolName} --param ${suggestions.find((entry) => entry.closest !== undefined).closest}` }
|
|
861
|
-
: { nextCommand: `omc describe ${toolName}` }),
|
|
862
|
-
message: `读面不接受未知键(与写面对齐):${pairs.join("、")}。` +
|
|
863
|
-
// C1(0.8.4):没有可信的改写建议时,不编造改名——直接把该工具的
|
|
864
|
-
// 真实参数名列出来,让人按名字挑。探针 J:混合键里只要有一个键
|
|
865
|
-
// 没拿到替代(如 all 有 replaceWith、zzz 没有),仍要列真实参数。
|
|
866
|
-
`${suggestions.some((entry) => entry.closest === undefined && entry.hint === undefined && entry.absentInTool === undefined && entry.replaceWith === undefined) ? `本工具的真实参数:${[...schemaKeys].join("、")}。` : ""}` +
|
|
867
|
-
`改用合法键后重试;确需宽松忽略传 lenientArgs:true。参数表:omc describe ${toolName}`,
|
|
868
|
-
};
|
|
869
|
-
return emit("error", result, CLI_EXIT_CODES.invalidInput);
|
|
870
|
-
}
|
|
871
|
-
for (const key of otherUnknown) {
|
|
872
|
-
ignoredReadKeys.push({ key, ...suggestArgumentKey(key, [...schemaKeys], toolName) });
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
if (tool) {
|
|
877
|
-
try {
|
|
878
|
-
parsedArgs = parseToolInput(tool, {
|
|
879
|
-
...parsedArgs,
|
|
880
|
-
...(environment && parsedArgs.environment === undefined ? { environment } : {}),
|
|
881
|
-
...(requestValue !== undefined ? { requestId: requestValue } : {}),
|
|
882
|
-
...(dryRun ? { dryRun: true } : {}),
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
catch (error) {
|
|
886
|
-
const result = error instanceof ToolInputError ? error.payload : { status: "error", message: error instanceof Error ? error.message : String(error) };
|
|
887
|
-
return emit("error", result, CLI_EXIT_CODES.invalidInput);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
// GitLab #47:显式 --env 指向未配置环境时,恢复动作是「去掉 --env 重跑本次
|
|
891
|
-
// 调用」。在进入执行面(会话/写锁/wire)之前给出,stderr 与 stdout 同一份
|
|
892
|
-
// 文案,不必让 agent 再撞一次。只处理 unknown environment;跨环境拒绝/凭据
|
|
893
|
-
// 缺失的恢复动作不同,继续走原有分类。
|
|
894
|
-
if (environment !== undefined && tool !== undefined) {
|
|
895
|
-
try {
|
|
896
|
-
if (!store.readConfig().environments[environment])
|
|
897
|
-
store.resolveEnvironment(environment);
|
|
898
|
-
}
|
|
899
|
-
catch (error) {
|
|
900
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
901
|
-
if (/^unknown environment "/u.test(message)) {
|
|
902
|
-
const result = withUnknownEnvironmentRecovery({ status: "error", message }, { tool: toolName, ...(rawArgs !== undefined ? { rawArgs } : {}), ...(argsFile !== undefined ? { argsFile } : {}), parsedArgs });
|
|
903
|
-
humanSummary(JSON.stringify(result));
|
|
904
|
-
return emit("error", result, CLI_EXIT_CODES.authConfig);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
const toolKind = tool?.kind;
|
|
909
|
-
// F2':只对写面(含 dry-run 预览)标记;读面人话不追加 2>&1 提示。
|
|
910
|
-
if (toolKind === "write")
|
|
911
|
-
beginWriteFace();
|
|
912
|
-
let lock;
|
|
913
|
-
// A `--dry-run` never mutates the environment: the governed pipeline settles it
|
|
914
|
-
// before write admission, so it must not contend for the cross-process lock.
|
|
915
|
-
if (toolKind === "write" && !dryRun) {
|
|
916
|
-
const lockTarget = environment ?? resolvedDefaultEnvironment(store);
|
|
917
|
-
const deadline = Date.now() + waitMs;
|
|
918
|
-
for (;;) {
|
|
919
|
-
lock = await acquireWriteLock(lockTarget);
|
|
920
|
-
if (lock.held)
|
|
921
|
-
break;
|
|
922
|
-
if (Date.now() >= deadline) {
|
|
923
|
-
// r31b F2: structured retryable/lockOwner/nextCommand so scripts do not
|
|
924
|
-
// invent a shell retry loop (help says use --wait; the refusal must too).
|
|
925
|
-
const conflict = writeLockHeldFace({
|
|
926
|
-
environment: lockTarget,
|
|
927
|
-
owner: lock.owner,
|
|
928
|
-
recovery: lock.recovery,
|
|
929
|
-
refusedTool: toolName,
|
|
930
|
-
waitMs: waitMs > 0 ? waitMs : 30_000,
|
|
931
|
-
});
|
|
932
|
-
console.error(`write lock conflict: ${JSON.stringify({ pid: lock.owner?.pid, tool: lock.owner?.tool ?? lock.owner?.command, startedAt: lock.owner?.startedAt })}`);
|
|
933
|
-
writeEnvelope({ ...envelope("refused", conflict, request, classifyResult(conflict).error), resultMeta: accountMeta() });
|
|
934
|
-
return CLI_EXIT_CODES.policyRefused;
|
|
935
|
-
}
|
|
936
|
-
await sleep(Math.min(200, Math.max(0, deadline - Date.now())));
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
let timedOut = false;
|
|
940
|
-
let result;
|
|
941
|
-
try {
|
|
942
|
-
({ result } = await runToolCall(toolName, {
|
|
943
|
-
args: parsedArgs,
|
|
944
|
-
// O2: this registry already validated the args above; do not rebuild or
|
|
945
|
-
// re-parse the same input inside runToolCall.
|
|
946
|
-
registry,
|
|
947
|
-
parsedInput: true,
|
|
948
|
-
...(environment ? { environment } : {}),
|
|
949
|
-
...(requestValue !== undefined ? { requestId: requestValue } : {}),
|
|
950
|
-
...(writeReason !== undefined ? { reason: writeReason } : {}),
|
|
951
|
-
dryRun,
|
|
952
|
-
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
953
|
-
print: (line) => humanSummary(line),
|
|
954
|
-
}));
|
|
955
|
-
if (result?.status === "uncertain" && result?.blocker === "cli-timeout")
|
|
956
|
-
timedOut = true;
|
|
957
|
-
}
|
|
958
|
-
finally {
|
|
959
|
-
if (lock?.held) {
|
|
960
|
-
if (timedOut) {
|
|
961
|
-
console.error(`cli-timeout: the write may still be in flight; the environment lock is deliberately NOT released — it auto-recovers once pid ${process.pid} exits (stale recovery)`);
|
|
962
|
-
}
|
|
963
|
-
else
|
|
964
|
-
await lock.release();
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
// GitLab #47:unknown --env 的恢复动作 = 去掉 --env 重跑同一调用。文案由
|
|
968
|
-
// config-store 给出绑定事实,这里补上只有 call 层才知道的 tool + 本次参数。
|
|
969
|
-
result = withUnknownEnvironmentRecovery(result, { tool: toolName, ...(rawArgs !== undefined ? { rawArgs } : {}), ...(argsFile !== undefined ? { argsFile } : {}), parsedArgs });
|
|
970
|
-
let unwrappedBody;
|
|
971
|
-
let resultMeta;
|
|
972
|
-
// C7(0.8.4):结果容器键自描述——`items`/`models`/`rules`/`logs`/`fields` 各面
|
|
973
|
-
// 不同,每个工具首次使用都要先探一次键名。在**投影前**的原始结果上判定,
|
|
974
|
-
// 挂到信封 resultMeta(result 本体与 --jq 路径零改动)。
|
|
975
|
-
const container = containerKeyOf(result);
|
|
976
|
-
if (extractPaths.length > 0 || extractKeys) {
|
|
977
|
-
// F1(retro 22,ticket 138):把调用上下文交给投影层——pathMiss 能推导出
|
|
978
|
-
// correctPath 时,拼一条含 --env/--args/--jq 的完整可复制命令(nextCommand)。
|
|
979
|
-
// args 用调用方**原始** JSON(未归一化),>500B 时投影层放弃拼命令(不截断造假)。
|
|
980
|
-
const projected = projectResultExtract(result, extractPaths, extractKeys, {
|
|
981
|
-
tool: toolName,
|
|
982
|
-
...(environment !== undefined && environment.length > 0 ? { environment } : {}),
|
|
983
|
-
argsJson: rawArgs !== undefined ? rawArgs : JSON.stringify(parsedArgs),
|
|
984
|
-
}, explainProjection);
|
|
985
|
-
if (projected !== undefined)
|
|
986
|
-
result = projected;
|
|
987
|
-
// Projected reads are represented by extract[] (and rows[] for multi-path).
|
|
988
|
-
// Do not also copy the single-path value to top-level content.
|
|
989
|
-
if (extractPaths.length > 0 && !extractKeys && typeof result === "object" && result !== null)
|
|
990
|
-
delete result.content;
|
|
991
|
-
// r40a: unsupported jq language is an input error, never an `ok:true`
|
|
992
|
-
// projection with a null value. Keep the path engine's detailed hint but
|
|
993
|
-
// make the CLI contract actionable and machine-classifiable.
|
|
994
|
-
if (typeof result === "object" && result !== null && Array.isArray(result.extract)) {
|
|
995
|
-
const extracts = result.extract;
|
|
996
|
-
const unsupported = extracts.filter((entry) => entry.unsupportedSyntax === true);
|
|
997
|
-
if (unsupported.length > 0) {
|
|
998
|
-
const first = unsupported[0];
|
|
999
|
-
const detail = typeof first?.hint === "string" ? first.hint : "投影 DSL 只做路径选择(点式 / [] 映射 / [key=value] / 切片)";
|
|
1000
|
-
const message = `--jq 不是 jq:仅路径选择器,${detail}(${String(first?.path ?? "")})。可运行示例:--jq 'fields[].code,fields[].typeName'`;
|
|
1001
|
-
const invalid = { status: "error", blocker: "tool-input-invalid", unsupportedSyntax: true, paths: unsupported.map((entry) => entry.path), message, nextCommand: "omc call <tool> --args '<json>' --jq 'fields[].code,fields[].typeName'" };
|
|
1002
|
-
return emit("error", invalid, CLI_EXIT_CODES.invalidInput);
|
|
1003
|
-
}
|
|
1004
|
-
// issue 2026-11-18 §05:单路径命中 → 信封的 result 直接是节点本体,元信息
|
|
1005
|
-
// 走 resultMeta(形状与不带 --jq 时的 result 同层级,只是被裁剪)。
|
|
1006
|
-
// 未命中/不支持语法不解包:pathMiss/available/hint 留在 result 顶层才能自愈。
|
|
1007
|
-
if (extractPaths.length === 1 && !extractKeys) {
|
|
1008
|
-
const unwrapped = unwrapSinglePathProjection(result);
|
|
1009
|
-
if (unwrapped !== undefined) {
|
|
1010
|
-
unwrappedBody = unwrapped.result;
|
|
1011
|
-
resultMeta = unwrapped.resultMeta;
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
for (const entry of extracts)
|
|
1015
|
-
delete entry.autoStripped;
|
|
1016
|
-
}
|
|
1017
|
-
// `extract[]` is the canonical multi-path result. Do not emit the second
|
|
1018
|
-
// row-alignment copy: callers can align the explicitly named path values.
|
|
1019
|
-
if (typeof result === "object" && result !== null && extractPaths.length > 1)
|
|
1020
|
-
delete result.rows;
|
|
1021
|
-
}
|
|
1022
|
-
// 读面未知键的非阻断回显:放在投影**之后**,否则会被 --jq 的窄投影吞掉。
|
|
1023
|
-
// 单路径解包后 result 是节点本体(可能是数组/标量),不能再往本体上加键——
|
|
1024
|
-
// 这类元信息跟着 resultMeta 走,确保「本体就是本体」。
|
|
1025
|
-
if (ignoredReadKeys.length > 0 && unwrappedBody !== undefined) {
|
|
1026
|
-
const pairs = ignoredReadKeys.map((entry) => entry.hint ? `${entry.key}(${entry.hint})` : entry.closest ? `${entry.key}→${entry.closest}` : entry.key);
|
|
1027
|
-
resultMeta = {
|
|
1028
|
-
...(resultMeta ?? {}),
|
|
1029
|
-
ignoredArgs: {
|
|
1030
|
-
keys: ignoredReadKeys,
|
|
1031
|
-
hint: `这些参数本工具不认识,已被忽略(没有生效):${pairs.join("、")}。若是拼写问题按 → 改;要确认完整参数表用 \`omc describe ${toolName}\``,
|
|
1032
|
-
},
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
else if (ignoredReadKeys.length > 0 && typeof result === "object" && result !== null) {
|
|
1036
|
-
const pairs = ignoredReadKeys.map((entry) => {
|
|
1037
|
-
if (entry.hint)
|
|
1038
|
-
return `${entry.key}(${entry.hint})`;
|
|
1039
|
-
if (entry.closest)
|
|
1040
|
-
return `${entry.key}→${entry.closest}`;
|
|
1041
|
-
if (entry.absentInTool)
|
|
1042
|
-
return `${entry.key}(本工具没有 ${entry.absentInTool} 参数)`;
|
|
1043
|
-
return entry.key;
|
|
1044
|
-
});
|
|
1045
|
-
result = {
|
|
1046
|
-
...result,
|
|
1047
|
-
ignoredArgs: {
|
|
1048
|
-
keys: ignoredReadKeys,
|
|
1049
|
-
hint: `这些参数本工具不认识,已被忽略(没有生效):${pairs.join("、")}。若是拼写问题按 → 改;要确认完整参数表用 \`omc describe ${toolName}\`。注意「过滤/排序没生效」最常见的原因就是这里拼错键。`,
|
|
1050
|
-
},
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
// C1(0.8.4):同义参数换算的说明与 ignoredArgs 同层——放在投影**之后**,
|
|
1054
|
-
// 否则被 --jq 的窄投影吞掉;单路径解包时随 resultMeta 走。
|
|
1055
|
-
if (Object.keys(aliasesApplied).length > 0) {
|
|
1056
|
-
if (unwrappedBody !== undefined)
|
|
1057
|
-
resultMeta = { ...(resultMeta ?? {}), aliasesApplied };
|
|
1058
|
-
else if (typeof result === "object" && result !== null)
|
|
1059
|
-
result = { ...result, aliasesApplied };
|
|
1060
|
-
}
|
|
1061
|
-
const classified = classifyResult(result);
|
|
1062
|
-
try {
|
|
1063
|
-
// 单路径 --jq 命中:emit 的是节点本体(可能不是对象),元信息在信封旁。
|
|
1064
|
-
// body 自带 `status`/`blocker` 时(如 --jq 直接取回整包),信封的 error 仍以
|
|
1065
|
-
// **投影前**的 classified 为准——别让 payload 里的字段改写本调用的结论。
|
|
1066
|
-
const emitValue = unwrappedBody !== undefined ? unwrappedBody : result;
|
|
1067
|
-
// C4(0.8.4):`--out` + `--jq` 同用——把「投影后的值」交给输出层,由它先落盘
|
|
1068
|
-
// 投影 JSON、再在 stdout 回执里带上投影值(此前投影只影响 stdout 的 result、
|
|
1069
|
-
// --out 只回 {out,bytes},提取值在两边都拿不到)。未命中不解包,投影回执
|
|
1070
|
-
// (pathMiss 等纠错载荷)本身就是这里要回显的值,不静默。
|
|
1071
|
-
// 裸 `--jq` / `--keys`(键清单)也是投影(同一套 omit 语义):一并交给输出层,
|
|
1072
|
-
// 免得「带 --jq 值」与「带 --jq 不带值」在 --out 下又分两套。
|
|
1073
|
-
if (extractPaths.length > 0 || extractKeys) {
|
|
1074
|
-
const projectionValue = unwrappedBody !== undefined ? unwrappedBody : result;
|
|
1075
|
-
const unanswered = projectionValue !== null && typeof projectionValue === "object" && !Array.isArray(projectionValue)
|
|
1076
|
-
&& projectionValue.unanswered === true;
|
|
1077
|
-
noteOutProjection({ paths: extractPaths, value: projectionValue, hit: !unanswered, budget: maxOutputBytes });
|
|
1078
|
-
}
|
|
1079
|
-
// A2(r89 契约层):跨面键名对照(read-shapes 单一声明)挂信封 resultMeta.locator——
|
|
1080
|
-
// 成功读回才有定位意义;result 本体与 --jq 路径零改动。
|
|
1081
|
-
const locatorExtra = classified.status === "ok" ? locatorMetaFor(toolName) : undefined;
|
|
1082
|
-
const containerExtra = classified.status === "ok" && container !== undefined
|
|
1083
|
-
? { containerKey: container.key, ...(container.path !== undefined ? { containerPath: container.path } : {}) }
|
|
1084
|
-
: undefined;
|
|
1085
|
-
const mergedMeta = { ...(locatorExtra ?? {}), ...(containerExtra ?? {}), ...(resultMeta ?? {}) };
|
|
1086
|
-
const extras = unwrappedBody !== undefined
|
|
1087
|
-
? { error: classified.error, ...(Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : {}) }
|
|
1088
|
-
: Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : undefined;
|
|
1089
|
-
return emit(classified.status, emitValue, classified.exitCode, extras);
|
|
1090
|
-
}
|
|
1091
|
-
finally {
|
|
1092
|
-
if (toolKind === "write")
|
|
1093
|
-
endWriteFace();
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
/** Collect every value of a repeatable flag (`--extract a --extract b`). */
|
|
1097
|
-
function argvValues(args, name) {
|
|
1098
|
-
const values = [];
|
|
1099
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
1100
|
-
if (args[index] !== name)
|
|
1101
|
-
continue;
|
|
1102
|
-
const value = args[index + 1];
|
|
1103
|
-
if (value !== undefined && !value.startsWith("--"))
|
|
1104
|
-
values.push(value);
|
|
1105
|
-
}
|
|
1106
|
-
return values;
|
|
1107
|
-
}
|
|
1108
|
-
/** F6:应用级范围键。被工具 schema 忽略时必须拒绝,不能静默回落到默认应用。 */
|
|
1109
|
-
const APP_SCOPE_ARG_KEYS = new Set(["appCode", "applicationCode", "application"]);
|
|
1110
|
-
/** 归一化编辑距离(去分隔符 + 统一大小写),用于「拼写级」改名判定。 */
|
|
1111
|
-
function normalizedEditDistance(a, b) {
|
|
1112
|
-
const left = a.toUpperCase().replace(/[\s._-]/g, "");
|
|
1113
|
-
const right = b.toUpperCase().replace(/[\s._-]/g, "");
|
|
1114
|
-
const row = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
1115
|
-
for (let i = 1; i <= left.length; i += 1) {
|
|
1116
|
-
let previous = row[0];
|
|
1117
|
-
row[0] = i;
|
|
1118
|
-
for (let j = 1; j <= right.length; j += 1) {
|
|
1119
|
-
const temp = row[j];
|
|
1120
|
-
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (left[i - 1] === right[j - 1] ? 0 : 1));
|
|
1121
|
-
previous = temp;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
return row[right.length];
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* C1(0.8.4):**语义**别名(不是拼写)——只在目标键真实存在时换算,且回执
|
|
1128
|
-
* 写明换算结果(aliasesApplied),不让调用方以为原名生效了。
|
|
1129
|
-
*
|
|
1130
|
-
* 两条别名的语义边界不同:
|
|
1131
|
-
* - `pageSize` 与分页工具的 `size`(每页条数)是同一件事,任何有 `size` 的工具都换算。
|
|
1132
|
-
* 平台依据:`/api/runtime/query/list` 的 `QueryDataVO{page,size}` 在
|
|
1133
|
-
* `QueryRuntimeController` 里按 `new PageableImpl(page * size, size)` 落到分页
|
|
1134
|
-
* (8.6.26 QueryRuntimeController.java:3304/3945;2.1.5 同名文件:3658/4187),
|
|
1135
|
-
* 即 `size` = 每页条数、`page` = 页序号;前端列表页也是
|
|
1136
|
-
* `page:this.curPage-1, size:this.pageSize`(8.6.26 frontend-dist
|
|
1137
|
-
* portal-app/js/17491.eed01ae7.js:1、31275.a9b046c8.js:1)。
|
|
1138
|
-
* - `onlyCustom` 与 `all` **方向相反**(`all:true` = 连系统字段一起返)。只有
|
|
1139
|
-
* field.list 的 `all` 是「包含系统字段」的客户端过滤(lanes/field.ts:453 用
|
|
1140
|
-
* isSystemFieldCode 过滤),系统字段本身由平台 `defaultProperty=true` 标注
|
|
1141
|
-
* (BizProperty.isSystem(),8.6.26 shared/BizProperty.java:257-259;
|
|
1142
|
-
* 2.1.5 contracts/BizProperty.java:262-264)。**不扩展到 data.list**:那里的
|
|
1143
|
-
* `all` 是「自动翻页聚合全部」,换算过去只会拿错结果集。
|
|
1144
|
-
* 其余同名键(如 model.inspect 的 `all`)没有被实测误用证据,宁可不加。
|
|
1145
|
-
*/
|
|
1146
|
-
const ONLY_CUSTOM_TO_ALL_TOOLS = new Set(["field.list"]);
|
|
1147
|
-
function applyReadArgAliases(toolName, schemaKeys, input) {
|
|
1148
|
-
const args = { ...input };
|
|
1149
|
-
const applied = {};
|
|
1150
|
-
const move = (alias, canonical, transform, describe) => {
|
|
1151
|
-
if (args[alias] === undefined || schemaKeys.has(alias) || !schemaKeys.has(canonical))
|
|
1152
|
-
return undefined;
|
|
1153
|
-
if (args[canonical] !== undefined)
|
|
1154
|
-
return { args, applied, conflict: { alias, canonical } };
|
|
1155
|
-
const next = transform(args[alias]);
|
|
1156
|
-
if (next === undefined)
|
|
1157
|
-
return undefined; // 类型不符:交给正常参数校验,不做半截换算
|
|
1158
|
-
args[canonical] = next;
|
|
1159
|
-
delete args[alias];
|
|
1160
|
-
applied[alias] = describe(next);
|
|
1161
|
-
return { args, applied };
|
|
1162
|
-
};
|
|
1163
|
-
// 探针 V F2(0.8.30):filter/filters/filterGroup 里的 `operator` 是 `op` 的
|
|
1164
|
-
// 同义别名(CloudPivot 习惯键)。在此换算并回执 aliasesApplied;两者同给且
|
|
1165
|
-
// 不一致 → 走既有 read-arg-alias-conflict。
|
|
1166
|
-
if (schemaKeys.has("filter") || schemaKeys.has("filters")) {
|
|
1167
|
-
const fixClause = (clause, path) => {
|
|
1168
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
1169
|
-
return clause;
|
|
1170
|
-
const row = clause;
|
|
1171
|
-
if (Array.isArray(row.clauses))
|
|
1172
|
-
return { ...row, clauses: row.clauses.map((entry, index) => fixClause(entry, `${path}.clauses[${index}]`)) };
|
|
1173
|
-
if (row.operator === undefined)
|
|
1174
|
-
return row;
|
|
1175
|
-
if (row.op !== undefined && row.op !== row.operator)
|
|
1176
|
-
return { __aliasConflict: true, path };
|
|
1177
|
-
const { operator, ...rest } = row;
|
|
1178
|
-
applied[`${path}.operator`] = `op=${String(operator)}`;
|
|
1179
|
-
return { ...rest, op: operator };
|
|
1180
|
-
};
|
|
1181
|
-
const fixedFilter = fixClause(args.filter, "filter");
|
|
1182
|
-
const fixedFilters = Array.isArray(args.filters) ? args.filters.map((entry, index) => fixClause(entry, `filters[${index}]`)) : args.filters;
|
|
1183
|
-
const fixedGroup = fixClause(args.filterGroup, "filterGroup");
|
|
1184
|
-
const hasConflict = (value) => Array.isArray(value)
|
|
1185
|
-
? value.some(hasConflict)
|
|
1186
|
-
: !!value && typeof value === "object" && (value.__aliasConflict === true || (Array.isArray(value.clauses) && (value.clauses).some(hasConflict)));
|
|
1187
|
-
if ([fixedFilter, fixedGroup, ...(Array.isArray(fixedFilters) ? fixedFilters : [])].some(hasConflict))
|
|
1188
|
-
return { args, applied, conflict: { alias: "operator", canonical: "op" } };
|
|
1189
|
-
if ("filter" in args)
|
|
1190
|
-
args.filter = fixedFilter;
|
|
1191
|
-
if ("filters" in args)
|
|
1192
|
-
args.filters = fixedFilters;
|
|
1193
|
-
if ("filterGroup" in args)
|
|
1194
|
-
args.filterGroup = fixedGroup;
|
|
1195
|
-
}
|
|
1196
|
-
const pageSize = move("pageSize", "size", (value) => (typeof value === "number" && Number.isFinite(value) ? value : undefined), (next) => `size=${String(next)}`);
|
|
1197
|
-
if (pageSize !== undefined)
|
|
1198
|
-
return pageSize;
|
|
1199
|
-
// 探针 R F2(0.8.26):org.role.list 的行把角色主键叫 `id`,相邻的
|
|
1200
|
-
// org.role.users 却只收 roleId——同一概念两个名字。仅在目标键真实存在时换算。
|
|
1201
|
-
// 探针 S F1(0.8.27):同一行的角色码叫 `code`,role.users 只收 roleCode;一并换算。
|
|
1202
|
-
if (toolName === "org.role.users") {
|
|
1203
|
-
const idAlias = move("id", "roleId", (value) => (typeof value === "string" && value.trim().length > 0 ? value : undefined), (next) => `roleId=${String(next)}(org.role.list 的 id)`);
|
|
1204
|
-
if (idAlias?.conflict !== undefined)
|
|
1205
|
-
return idAlias;
|
|
1206
|
-
const codeAlias = move("code", "roleCode", (value) => (typeof value === "string" && value.trim().length > 0 ? value : undefined), (next) => `roleCode=${String(next)}(org.role.list 的 code)`);
|
|
1207
|
-
if (codeAlias?.conflict !== undefined)
|
|
1208
|
-
return codeAlias;
|
|
1209
|
-
if (idAlias !== undefined || codeAlias !== undefined)
|
|
1210
|
-
return { args, applied };
|
|
1211
|
-
}
|
|
1212
|
-
if (ONLY_CUSTOM_TO_ALL_TOOLS.has(toolName)) {
|
|
1213
|
-
const onlyCustom = move("onlyCustom", "all", (value) => (typeof value === "boolean" ? !value : undefined), (next) => `all=${String(next)}`);
|
|
1214
|
-
if (onlyCustom !== undefined)
|
|
1215
|
-
return onlyCustom;
|
|
1216
|
-
}
|
|
1217
|
-
return { args, applied };
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* 读面「拼错键」建议(r25 真机实证,2026-11-04):`limt:5` 曾按编辑距离被指到
|
|
1221
|
-
* `filter`——两者共享 "fi" 片段就过阈值,但语义完全不同(取 5 条 vs 按条件过滤)。
|
|
1222
|
-
* 短键(≤5 字符)靠距离算不准,这里先查显式缩写表(与 tool-types 的 KEY_ALIAS_HINTS
|
|
1223
|
-
* 同源),命中且参数真实存在才用;否则只认**拼写级**近似(编辑距离 ≤2)。
|
|
1224
|
-
*
|
|
1225
|
-
* C1(0.8.4):最后一步此前是 closestMatches 的「least-bad」兜底——它总会挑一个
|
|
1226
|
-
* 名字,于是 `onlyCustom` 被建议到语义相反的 `all`、`pageSize` 被建议到 `page`。
|
|
1227
|
-
* 改名建议只在**拼错**(编辑距离 ≤2)或上面人工核过的同义表里给;其余宁可不猜
|
|
1228
|
-
* (回执仍列全部真实参数 expectedKeys)。语义别名走 applyReadArgAliases,不用
|
|
1229
|
-
* 「改名建议」表达——建议无法携带方向/换算信息。
|
|
1230
|
-
*/
|
|
1231
|
-
export function suggestArgumentKey(key, schemaKeys, toolName) {
|
|
1232
|
-
// 探针 J F4/F5:按 tool+key 的显式替代优先于拼写猜测(见
|
|
1233
|
-
// TOOL_KEY_ALTERNATIVES)。命中的是「语义改写」而不是「拼错」,所以
|
|
1234
|
-
// closest/编辑距离不参与,避免把原键再建议一次。
|
|
1235
|
-
const alternative = toolName !== undefined ? TOOL_KEY_ALTERNATIVES[toolName]?.[key] : undefined;
|
|
1236
|
-
if (alternative !== undefined)
|
|
1237
|
-
return { ...alternative };
|
|
1238
|
-
const known = new Set(schemaKeys);
|
|
1239
|
-
const paginationKeys = new Set(["page", "pagesize", "size", "pageindex", "pagenumber", "pageno", "offset", "limit"]);
|
|
1240
|
-
if (paginationKeys.has(key.toLowerCase()) && !schemaKeys.some((name) => paginationKeys.has(name.toLowerCase()))) {
|
|
1241
|
-
return { hint: "本工具不支持分页(返回全量/受限于应用范围);省略该键即可" };
|
|
1242
|
-
}
|
|
1243
|
-
const normalizedTool = toolName?.toLowerCase() ?? "";
|
|
1244
|
-
if ((normalizedTool.startsWith("workflow.") || normalizedTool.startsWith("workitem.")) && key === "code" && known.has("workflowCode"))
|
|
1245
|
-
return { closest: "workflowCode" };
|
|
1246
|
-
if (normalizedTool.startsWith("data.") && key === "id" && known.has("bizObjectId"))
|
|
1247
|
-
return { closest: "bizObjectId" };
|
|
1248
|
-
// r53 场景03 F8:rule.run 的记录标识叫 ids(数组),与 data.* 族的 bizObjectId
|
|
1249
|
-
// 完全不共享字符串相似度——最近匹配回不出建议,只能报「无相近键」。
|
|
1250
|
-
if (normalizedTool.startsWith("rule.") && key === "bizObjectId" && known.has("ids"))
|
|
1251
|
-
return { closest: "ids", hint: "rule.run 的记录标识是 ids(字符串数组)" };
|
|
1252
|
-
if (normalizedTool.startsWith("data.") && key === "ids" && known.has("bizObjectIds"))
|
|
1253
|
-
return { closest: "bizObjectIds" };
|
|
1254
|
-
const aliases = KEY_ALIAS_HINTS[key.toLowerCase()] ?? [];
|
|
1255
|
-
for (const candidate of aliases) {
|
|
1256
|
-
if (known.has(candidate))
|
|
1257
|
-
return { closest: candidate };
|
|
1258
|
-
}
|
|
1259
|
-
// 关键:若这个键明确是某个已知参数的缩写、而**本工具根本没有该参数**(实测
|
|
1260
|
-
// `model.list` 就没有 `size`),不能退回最近匹配硬凑一个(`filter` 语义相反)——
|
|
1261
|
-
// 返回 absentInTool,让回执直说「本工具没有这个参数」。
|
|
1262
|
-
if (aliases.length > 0)
|
|
1263
|
-
return { absentInTool: aliases[0] };
|
|
1264
|
-
// 拼写级近似:距离 ≤2 才算「同一个名字写错了」;更远的一律不猜。
|
|
1265
|
-
let closest;
|
|
1266
|
-
let closestDistance = Number.POSITIVE_INFINITY;
|
|
1267
|
-
for (const candidate of schemaKeys) {
|
|
1268
|
-
const distance = normalizedEditDistance(key, candidate);
|
|
1269
|
-
if (distance < closestDistance) {
|
|
1270
|
-
closest = candidate;
|
|
1271
|
-
closestDistance = distance;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
return closest !== undefined && closestDistance <= 2 ? { closest } : {};
|
|
1275
|
-
}
|
|
1276
|
-
function resolvedDefaultEnvironment(store) {
|
|
1277
|
-
try {
|
|
1278
|
-
return store.resolveEnvironment(undefined).name;
|
|
1279
|
-
}
|
|
1280
|
-
catch {
|
|
1281
|
-
return "default";
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* GitLab #47:`unknown environment "test"` 的恢复动作在 99% 情况下是「去掉
|
|
1286
|
-
* --env 重跑同一条调用」(项目 .omc-env 已是正确绑定)。config-store 的文案
|
|
1287
|
-
* 说明了这条规则,但只有 call 这一层知道 tool 与本次参数,所以在这里补一条
|
|
1288
|
-
* **真正可复制**的 nextCommand。
|
|
1289
|
-
*
|
|
1290
|
-
* 只对 `unknown environment "…"` 这一类生效:跨环境访问被拒、凭据缺失、平台
|
|
1291
|
-
* 错误的恢复动作各不相同,不能套用「去掉 --env」。参数过大/来自 stdin/文件时
|
|
1292
|
-
* 退回不内联参数的命令,绝不截断或编造载荷。
|
|
1293
|
-
*/
|
|
1294
|
-
function withoutEnvironmentCommand(input) {
|
|
1295
|
-
const inlineRaw = input.rawArgs !== undefined && input.rawArgs.trim().startsWith("{") ? input.rawArgs : undefined;
|
|
1296
|
-
// `parseToolInput` folds `--env` into args.environment; keeping it in the retry
|
|
1297
|
-
// would reproduce the very failure it is meant to recover from. Strip it from
|
|
1298
|
-
// the caller's JSON too (a tool-arg `environment` fails the same way).
|
|
1299
|
-
let inline = inlineRaw;
|
|
1300
|
-
if (inlineRaw !== undefined) {
|
|
1301
|
-
try {
|
|
1302
|
-
const parsed = JSON.parse(inlineRaw);
|
|
1303
|
-
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) && "environment" in parsed) {
|
|
1304
|
-
delete parsed.environment;
|
|
1305
|
-
inline = Object.keys(parsed).length > 0 ? JSON.stringify(parsed) : undefined;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
catch {
|
|
1309
|
-
// Not valid JSON: the call already failed input validation before this path.
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
const remaining = { ...input.parsedArgs };
|
|
1313
|
-
delete remaining.environment;
|
|
1314
|
-
const serialized = inline ?? (Object.keys(remaining).length > 0 ? JSON.stringify(remaining) : undefined);
|
|
1315
|
-
if (serialized === undefined || serialized === "{}")
|
|
1316
|
-
return `omc call ${input.tool}`;
|
|
1317
|
-
if (serialized.length <= 500)
|
|
1318
|
-
return `omc call ${input.tool} --args '${serialized.replace(/'/g, "'\\''")}'`;
|
|
1319
|
-
if (input.argsFile !== undefined)
|
|
1320
|
-
return `omc call ${input.tool} --args-file ${input.argsFile}`;
|
|
1321
|
-
if (input.rawArgs === "-")
|
|
1322
|
-
return `omc call ${input.tool} --args -`;
|
|
1323
|
-
return `omc call ${input.tool}`;
|
|
1324
|
-
}
|
|
1325
|
-
function withUnknownEnvironmentRecovery(result, input) {
|
|
1326
|
-
if (result.status !== "error" || typeof result.message !== "string")
|
|
1327
|
-
return result;
|
|
1328
|
-
if (!/^unknown environment "/u.test(result.message))
|
|
1329
|
-
return result;
|
|
1330
|
-
const nextCommand = withoutEnvironmentCommand(input);
|
|
1331
|
-
return {
|
|
1332
|
-
...result,
|
|
1333
|
-
nextCommand,
|
|
1334
|
-
message: result.message.includes("直接重试:") ? result.message : `${result.message};直接重试:${nextCommand}`,
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* Above this size `omc artifact get` returns the outline, not the body. The
|
|
1339
|
-
* transport cap (64 KB) is far too generous for a working context: one 27 KB
|
|
1340
|
-
* template re-read three times is 81 KB of the session.
|
|
1341
|
-
*/
|
|
1342
|
-
const ARTIFACT_INLINE_CEILING_BYTES = 8192;
|
|
1343
417
|
/**
|
|
1344
418
|
* commands --json 的上下文预算。2026-11-24(审批动作 / MCP 对齐批):32KiB →
|
|
1345
419
|
* 40KiB——裸目录已到 32.8KB(workflow 审批动作七件套 + 可驳回节点查询 8 行),
|
|
@@ -1350,104 +424,6 @@ const ARTIFACT_INLINE_CEILING_BYTES = 8192;
|
|
|
1350
424
|
const COMMANDS_JSON_INLINE_CEILING_BYTES = 40 * 1024;
|
|
1351
425
|
/** 超过这个体积就提醒走更窄的面(不改变返回值)。 */
|
|
1352
426
|
const COMMANDS_JSON_HINT_BYTES = 16 * 1024;
|
|
1353
|
-
/**
|
|
1354
|
-
* issue 2026-11 F3:默认骨架不是限流——同一句话必须同时出现在 `hint` 与顶层
|
|
1355
|
-
* `message`(并列通道同源),否则只看 message 的程序化消费方会误判。
|
|
1356
|
-
*/
|
|
1357
|
-
function artifactOutlineHint(id, bytes, depth) {
|
|
1358
|
-
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。`;
|
|
1359
|
-
}
|
|
1360
|
-
function artifactDefaultMetadata(id, bytes, content, depth) {
|
|
1361
|
-
return {
|
|
1362
|
-
status: "ok",
|
|
1363
|
-
artifactId: id,
|
|
1364
|
-
bytes,
|
|
1365
|
-
outline: true,
|
|
1366
|
-
depth,
|
|
1367
|
-
shape: shapeOf(content, depth),
|
|
1368
|
-
hint: artifactOutlineHint(id, bytes, depth),
|
|
1369
|
-
message: artifactOutlineHint(id, bytes, depth),
|
|
1370
|
-
fullCommand: `omc artifact get ${id} --full`,
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
|
-
function projectArtifactPath(value, path) {
|
|
1374
|
-
if (!path.includes("[]")) {
|
|
1375
|
-
const projected = projectJsonPath(value, path);
|
|
1376
|
-
return projected.missed
|
|
1377
|
-
? { 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 } : {}) }
|
|
1378
|
-
: { missed: false, content: projected.value ?? null };
|
|
1379
|
-
}
|
|
1380
|
-
const fanout = projectJsonPathFanout(value, path);
|
|
1381
|
-
return fanout.missed
|
|
1382
|
-
? { 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 } : {}) }
|
|
1383
|
-
: { missed: false, content: fanout.values, mapped: fanout.values.length, ...(fanout.missedEntries > 0 ? { missedEntries: fanout.missedEntries } : {}), nullEntries: fanout.nullEntries, nonNullEntries: fanout.nonNullEntries };
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* C3(0.8.4):artifact 面**唯一**的 miss 条目构造器——`call` 面(projectResultExtract
|
|
1387
|
-
* 的 extract[])同形:路径未命中 → `path`/`content:null`/`pathMiss`/`missedAt`/
|
|
1388
|
-
* (didYouMean|helpRef)(--explain 才带 available/correctPath/nextCommand/hint);
|
|
1389
|
-
* 不支持语法 → `pathMiss:false` + `unsupportedSyntax:true`(不是「键不存在」)。
|
|
1390
|
-
* 三处(裸 --jq / --summary --jq / --shape <path>)此前各写一份,容易再分叉。
|
|
1391
|
-
*/
|
|
1392
|
-
function artifactMissEntry(path, projected, content, artifactId, explainMiss) {
|
|
1393
|
-
if (projected.unsupportedSyntax === true) {
|
|
1394
|
-
return {
|
|
1395
|
-
path,
|
|
1396
|
-
content: null,
|
|
1397
|
-
pathMiss: false,
|
|
1398
|
-
unsupportedSyntax: true,
|
|
1399
|
-
unanswered: true,
|
|
1400
|
-
available: projected.available,
|
|
1401
|
-
hint: UNSUPPORTED_JQ_OBJECT_HINT,
|
|
1402
|
-
};
|
|
1403
|
-
}
|
|
1404
|
-
return {
|
|
1405
|
-
path,
|
|
1406
|
-
content: null,
|
|
1407
|
-
pathMiss: true,
|
|
1408
|
-
...(projected.at !== undefined ? { missedAt: projected.at } : {}),
|
|
1409
|
-
...artifactMissFields(projected, explainMiss),
|
|
1410
|
-
...(explainMiss ? artifactMissCorrection(content, path, projected.at, artifactId) : {}),
|
|
1411
|
-
};
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* F1/F2(retro 21/22,ticket 138):artifact 面 pathMiss 的机器可读纠错面——
|
|
1415
|
-
* `correctPath`(已验证可解析)+ `helpRef`(教程指针)+ 可整段复制的重跑命令。
|
|
1416
|
-
* 与 call 面(projectResultExtract)同一套推导(拼写近似走 didYouMean 字段,
|
|
1417
|
-
* 这里只补跨面改写与同名键两条**全路径**推导),推导不出就全部缺席(不编造)。
|
|
1418
|
-
*/
|
|
1419
|
-
function artifactMissCorrection(content, path, at, artifactId) {
|
|
1420
|
-
const correction = pathMissCrossFaceCorrection(content, path, at) ?? (() => {
|
|
1421
|
-
const copyable = pathMissCopyablePaths(content, path, at, 1);
|
|
1422
|
-
return copyable.length > 0 ? { correctPath: copyable[0] } : undefined;
|
|
1423
|
-
})();
|
|
1424
|
-
return {
|
|
1425
|
-
...(correction !== undefined ? { correctPath: correction.correctPath } : {}),
|
|
1426
|
-
helpRef: PATH_MISS_HELP_REF,
|
|
1427
|
-
...(correction !== undefined ? { nextCommand: `omc artifact get ${artifactId} --jq '${correction.correctPath.replace(/'/g, "'\\''")}'` } : {}),
|
|
1428
|
-
};
|
|
1429
|
-
}
|
|
1430
|
-
/** Preserve source completeness/count facts on every artifact projection. */
|
|
1431
|
-
function artifactProjectionMetadata(value) {
|
|
1432
|
-
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
1433
|
-
return {};
|
|
1434
|
-
const record = value;
|
|
1435
|
-
const metadata = {};
|
|
1436
|
-
for (const key of ["truncated", "truncatedKeys", "itemsCount", "total"]) {
|
|
1437
|
-
if (Object.prototype.hasOwnProperty.call(record, key))
|
|
1438
|
-
metadata[key] = record[key];
|
|
1439
|
-
}
|
|
1440
|
-
return metadata;
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* T6(GitLab #17):`mapped`/`nullEntries` 的读法要跟数据一起走,否则 `mapped:5`
|
|
1444
|
-
* 会被读成"取到 5 个值"。文案的单一真相源在 path-projection(与 `--extract`
|
|
1445
|
-
* 面共用),这里只负责从产物内容算 total。
|
|
1446
|
-
*/
|
|
1447
|
-
function artifactNullHint(content, nullEntries) {
|
|
1448
|
-
const total = Array.isArray(content) ? content.length : 0;
|
|
1449
|
-
return nullProjectionHint(nullEntries, total);
|
|
1450
|
-
}
|
|
1451
427
|
function formatBytes(bytes) {
|
|
1452
428
|
if (bytes < 1024)
|
|
1453
429
|
return `${bytes}B`;
|
|
@@ -1455,328 +431,6 @@ function formatBytes(bytes) {
|
|
|
1455
431
|
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
1456
432
|
return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
|
|
1457
433
|
}
|
|
1458
|
-
/**
|
|
1459
|
-
* r73 #7(GitLab #40 P1):从 `omc artifact get <id> --out <path>` 的 argv 里截出
|
|
1460
|
-
* `--out` 并原地摘除那两个 token,让 configureOutput / stripOutputFlags 的全局
|
|
1461
|
-
* 信封重定向语义不再吃掉它。只对 `artifact get` 子命令生效;缺值/flag 形值与
|
|
1462
|
-
* configureOutput 同规则拒绝(invalid-input)。返回截得的路径,未出现则 undefined。
|
|
1463
|
-
*/
|
|
1464
|
-
function extractArtifactGetOutFlag(argv) {
|
|
1465
|
-
const tokens = argv.slice(2);
|
|
1466
|
-
if (tokens[0] !== "artifact" || tokens[1] !== "get")
|
|
1467
|
-
return undefined;
|
|
1468
|
-
for (let index = 2; index < argv.length; index += 1) {
|
|
1469
|
-
const token = argv[index];
|
|
1470
|
-
if (token === "--out") {
|
|
1471
|
-
const value = argv[index + 1];
|
|
1472
|
-
if (value === undefined || value.startsWith("--"))
|
|
1473
|
-
throw new Error("--out requires a file path");
|
|
1474
|
-
argv.splice(index, 2);
|
|
1475
|
-
return value;
|
|
1476
|
-
}
|
|
1477
|
-
if (token.startsWith("--out=")) {
|
|
1478
|
-
const value = token.slice("--out=".length);
|
|
1479
|
-
if (value.length === 0)
|
|
1480
|
-
throw new Error("--out requires a file path");
|
|
1481
|
-
argv.splice(index, 1);
|
|
1482
|
-
return value;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
return undefined;
|
|
1486
|
-
}
|
|
1487
|
-
/** artifact 面 pathMiss 的 didYouMean/截断计数附加字段(r75:与 call 面一致)。 */
|
|
1488
|
-
/**
|
|
1489
|
-
* C6(0.8.4):artifact 面 miss 的默认载荷与 call 面同口径——只留
|
|
1490
|
-
* `didYouMean` + `helpRef`;`available`(该层全部键)/`availableTruncated`
|
|
1491
|
-
* 只在显式 `--explain` 时给(排查载荷不再每次吃 600–1200B)。
|
|
1492
|
-
*/
|
|
1493
|
-
function artifactMissFields(projected, explain) {
|
|
1494
|
-
const didYouMean = pathMissDidYouMean(projected.at, projected.available, projected.availableAll);
|
|
1495
|
-
return {
|
|
1496
|
-
...(didYouMean !== undefined ? { didYouMean } : {}),
|
|
1497
|
-
helpRef: PATH_MISS_HELP_REF,
|
|
1498
|
-
...(explain
|
|
1499
|
-
? {
|
|
1500
|
-
available: projected.available,
|
|
1501
|
-
...(projected.availableTruncated !== undefined ? { availableTruncated: projected.availableTruncated } : {}),
|
|
1502
|
-
}
|
|
1503
|
-
: {}),
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
async function cmdArtifactGet(id, transport, options = {}) {
|
|
1507
|
-
const explainMiss = options.explain === true;
|
|
1508
|
-
try {
|
|
1509
|
-
if (options.depth !== undefined && (!Number.isInteger(options.depth) || options.depth < 1 || options.depth > SHAPE_MAX_DEPTH)) {
|
|
1510
|
-
const parsed = errorEnvelope(new Error(`--depth 必须是 1-${SHAPE_MAX_DEPTH} 的整数(默认 2;再深就成了正文复刻,字节失控)`), "artifact-depth-invalid", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
1511
|
-
writeEnvelope(parsed.envelope);
|
|
1512
|
-
return parsed.exitCode;
|
|
1513
|
-
}
|
|
1514
|
-
const artifact = readArtifact(artifactRoot(), id);
|
|
1515
|
-
let content;
|
|
1516
|
-
try {
|
|
1517
|
-
content = JSON.parse(artifact.content.toString("utf8"));
|
|
1518
|
-
}
|
|
1519
|
-
catch {
|
|
1520
|
-
content = artifact.content.toString("utf8");
|
|
1521
|
-
}
|
|
1522
|
-
// r73 #7(GitLab #40 P1,2026-11-17):`--out <配置根内路径>` 把 artifact 原始
|
|
1523
|
-
// 正文**全量落盘**——写文件不走 stdout 限额,`--full` 被上限卡死(fullRejected)
|
|
1524
|
-
// 的大对象(实测 589KB 视图 artifact)此前只能拆 key 取、易漏。这里写的是已过
|
|
1525
|
-
// sha256 校验的原文字节;回执只给 {out,bytes,sha256},stdout 不回正文。
|
|
1526
|
-
if (options.out !== undefined) {
|
|
1527
|
-
// issue 06(retro 2026-11-19):`--out -` 想把正文直接打到 stdout——铁律是
|
|
1528
|
-
// stdout 恒为恰好一个 JSON envelope,混排正文字节会破坏所有脚本解析,不做。
|
|
1529
|
-
// 错误里给两步替代(根内落盘 + cat),用户照抄即可。
|
|
1530
|
-
if (options.out === "-") {
|
|
1531
|
-
const sample = join(intentConfigRoot(), "artifacts-out", `${id}.json`);
|
|
1532
|
-
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);
|
|
1533
|
-
writeEnvelope(parsed.envelope);
|
|
1534
|
-
return parsed.exitCode;
|
|
1535
|
-
}
|
|
1536
|
-
let outPath;
|
|
1537
|
-
try {
|
|
1538
|
-
outPath = assertSafeOutputPath(intentConfigRoot(), options.out, "artifact output file");
|
|
1539
|
-
}
|
|
1540
|
-
catch (error) {
|
|
1541
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
1542
|
-
const parsed = errorEnvelope(new Error(`artifact get --out 落盘被拒:${detail}。--out 按配置根(OMC_CONFIG_HOME)解析,只允许配置根内的常规文件路径;根内父目录会自动创建,配置根外(含系统临时目录)一律拒绝`), "artifact-out-refused", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
1543
|
-
writeEnvelope(parsed.envelope);
|
|
1544
|
-
return parsed.exitCode;
|
|
1545
|
-
}
|
|
1546
|
-
writeFileSync(outPath, artifact.content, { mode: 0o600 });
|
|
1547
|
-
chmodSync(outPath, 0o600);
|
|
1548
|
-
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, out: options.out, mode: "0600" }, transport);
|
|
1549
|
-
}
|
|
1550
|
-
// `--path-only` deliberately does NOT return the local path: the Agent-facing
|
|
1551
|
-
// CLI contract forbids exposing local filesystem paths. It returns the fetch
|
|
1552
|
-
// command instead, which is the portable way to reach the body.
|
|
1553
|
-
if (options.pathOnly)
|
|
1554
|
-
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, fetch: artifactFetchHint(id) }, transport);
|
|
1555
|
-
// --meta is the stable metadata-only choice. It deliberately never returns
|
|
1556
|
-
// the body, including for small artifacts whose default face is inline.
|
|
1557
|
-
if (options.meta === true) {
|
|
1558
|
-
const depth = options.depth ?? 2;
|
|
1559
|
-
return emitTransportResult({
|
|
1560
|
-
...artifactDefaultMetadata(id, artifact.content.length, content, depth),
|
|
1561
|
-
sha256: artifact.sha256,
|
|
1562
|
-
projectionRule: "投影要写到叶子(数组元素里的字段);取值用 --jq <path> 或 --keys <a,b>",
|
|
1563
|
-
projectionExample: `omc artifact get ${id} --jq '<path>'`,
|
|
1564
|
-
}, transport);
|
|
1565
|
-
}
|
|
1566
|
-
// r75 调查C:`--shape [path]` 回执形状先验——深度受限骨架(默认 2,--depth 可
|
|
1567
|
-
// 到 4)。--summary 是预算事实(多大/会不会截断),--shape 是导航图(嵌套骨架
|
|
1568
|
-
// 到哪层有哪些键);>8KB 默认 outline 与本分支共用同一份 shapeOf(单一真相源,
|
|
1569
|
-
// 防 r25「两面雷同」复发)。显式 --shape 优先于 --summary/--keys/--jq。
|
|
1570
|
-
if (options.shape !== undefined) {
|
|
1571
|
-
const depth = options.depth ?? 2;
|
|
1572
|
-
if (typeof options.shape === "string" && options.shape.trim() !== "") {
|
|
1573
|
-
// `--shape <path>`:在命中的子树上出骨架(同 --jq 的路径 DSL,含 [] 与 [code=X])。
|
|
1574
|
-
const projected = projectArtifactPath(artifact.content.toString("utf8") === "" ? undefined : content, options.shape);
|
|
1575
|
-
if (projected.missed) {
|
|
1576
|
-
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);
|
|
1577
|
-
}
|
|
1578
|
-
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);
|
|
1579
|
-
}
|
|
1580
|
-
// 裸 `--shape`:整棵根的骨架。<8KB 的产物正本默认整体内联,骨架无增益——
|
|
1581
|
-
// 明确劝退(r38 模式:别为已经免费的东西花第二轮)。
|
|
1582
|
-
const smallBody = artifact.content.length <= ARTIFACT_INLINE_CEILING_BYTES;
|
|
1583
|
-
return emitTransportResult({
|
|
1584
|
-
status: "ok",
|
|
1585
|
-
artifactId: id,
|
|
1586
|
-
sha256: artifact.sha256,
|
|
1587
|
-
bytes: artifact.content.length,
|
|
1588
|
-
depth,
|
|
1589
|
-
shape: shapeOf(content, depth),
|
|
1590
|
-
...(smallBody
|
|
1591
|
-
? { shapeNote: `产物 ${artifact.content.length}B 未超过内联上限 ${ARTIFACT_INLINE_CEILING_BYTES}B:默认 get 本就整体内联正文,--shape 无增益;直接取正文或 --jq <path> 定向取值`, defaultCommand: `omc artifact get ${id}` }
|
|
1592
|
-
: { fetch: artifactFetchHint(id) }),
|
|
1593
|
-
}, transport);
|
|
1594
|
-
}
|
|
1595
|
-
// `--summary` / `--keys` (round 4): inspect a large artifact without pulling
|
|
1596
|
-
// its whole body. Reproduced benchmark: agents fetched 30–75 KB workflow
|
|
1597
|
-
// bodies just to look at the node list.
|
|
1598
|
-
if (options.summary) {
|
|
1599
|
-
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
1600
|
-
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) : [];
|
|
1601
|
-
// r25 真机(2026-11-04):`--summary` 与裸 `--keys` 曾输出逐字相同(各 878 B),
|
|
1602
|
-
// 但 fetch 提示写「--summary(再 --keys/--jq)」暗示递进——探针白跑一次。
|
|
1603
|
-
// 现在 `--summary` 多给一眼"要花多少/会不会被截断",`--keys` 保持纯 key 表。
|
|
1604
|
-
const shapeFacts = {
|
|
1605
|
-
bytes: artifact.content.length,
|
|
1606
|
-
...(record ? { topLevelKeys: keys.length } : {}),
|
|
1607
|
-
overInlineCeiling: artifact.content.length > ARTIFACT_INLINE_CEILING_BYTES,
|
|
1608
|
-
...(record ? {} : { kind: Array.isArray(content) ? `array[${content.length}]` : typeof content }),
|
|
1609
|
-
};
|
|
1610
|
-
// `--summary --jq <path>`: shape AND the one value, in a single call. Without
|
|
1611
|
-
// this the caller had to spend one round on the shape and another on the
|
|
1612
|
-
// path (or pull the whole body); r5 hit that on 67 KB workflow templates.
|
|
1613
|
-
if (options.jq !== undefined) {
|
|
1614
|
-
const projected = projectArtifactPath(artifact.content.toString("utf8") === "" ? undefined : content, options.jq);
|
|
1615
|
-
// T1(GitLab #17):形状 + 值 + 键表是**同一层**的三件事实,不再把值多套
|
|
1616
|
-
// 一层 `projection:{path,content}`——`artifact get --jq` 与 `--summary --jq`
|
|
1617
|
-
// 因此同形(顶层 path/content),换读面不用重新探根键。
|
|
1618
|
-
return emitTransportResult(projected.missed
|
|
1619
|
-
? (() => {
|
|
1620
|
-
const miss = artifactMissEntry(options.jq, projected, content, id, explainMiss);
|
|
1621
|
-
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)) } : {}) };
|
|
1622
|
-
})()
|
|
1623
|
-
: {
|
|
1624
|
-
status: "ok",
|
|
1625
|
-
artifactId: id,
|
|
1626
|
-
sha256: artifact.sha256,
|
|
1627
|
-
bytes: artifact.content.length,
|
|
1628
|
-
...artifactProjectionMetadata(content),
|
|
1629
|
-
keys,
|
|
1630
|
-
path: options.jq,
|
|
1631
|
-
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 } : {}) }],
|
|
1632
|
-
...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}),
|
|
1633
|
-
...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}),
|
|
1634
|
-
...(projected.nonNullEntries !== undefined ? { nonNullEntries: projected.nonNullEntries } : {}),
|
|
1635
|
-
...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}),
|
|
1636
|
-
...(artifactNullHint(projected.content, projected.nullEntries) !== undefined ? { hint: artifactNullHint(projected.content, projected.nullEntries) } : {}),
|
|
1637
|
-
}, transport);
|
|
1638
|
-
}
|
|
1639
|
-
// 裸 `--keys` / 裸 `--jq` 只要键表(`pureKeys`),不带 summary 的形状事实——
|
|
1640
|
-
// 两者要有可见差异,否则 fetch 提示里的「--summary(再 --keys)」就是误导。
|
|
1641
|
-
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...(options.pureKeys === true ? {} : { summary: shapeFacts }), keys, fetch: artifactFetchHint(id) }, transport);
|
|
1642
|
-
}
|
|
1643
|
-
if (options.keys !== undefined) {
|
|
1644
|
-
// Round 15: tolerate a `result.`/`data.` prefix and report missing keys.
|
|
1645
|
-
// bench63 tried `--keys result.publishedAttributesJson` (empty) before
|
|
1646
|
-
// `--keys publishedAttributesJson` worked; the artifact content IS the
|
|
1647
|
-
// result object, so a leading envelope prefix is a no-op the caller does
|
|
1648
|
-
// not expect. Strip it, and when a key truly is absent list the real
|
|
1649
|
-
// top-level keys so the next call is correct.
|
|
1650
|
-
const wanted = options.keys.split(",").map((key) => key.trim()).filter(Boolean);
|
|
1651
|
-
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
1652
|
-
const projected = {};
|
|
1653
|
-
const missing = [];
|
|
1654
|
-
for (const raw of wanted) {
|
|
1655
|
-
const candidates = record === undefined ? [raw] : [raw, raw.replace(/^(result|data)\./, "")];
|
|
1656
|
-
const hit = candidates.find((key) => record !== undefined && key in record);
|
|
1657
|
-
if (hit !== undefined && record !== undefined)
|
|
1658
|
-
projected[hit] = record[hit];
|
|
1659
|
-
else
|
|
1660
|
-
missing.push(raw);
|
|
1661
|
-
}
|
|
1662
|
-
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 };
|
|
1663
|
-
if (Buffer.byteLength(JSON.stringify(result), "utf8") > transport.maxOutputBytes)
|
|
1664
|
-
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);
|
|
1665
|
-
return emitTransportResult(result, transport);
|
|
1666
|
-
}
|
|
1667
|
-
if (options.jq !== undefined) {
|
|
1668
|
-
// A3(GitLab #15):逗号多路径——一次取多列(projections 数组),单路径形态不变。
|
|
1669
|
-
const jqPaths = options.jq.split(",").map((path) => path.trim()).filter(Boolean);
|
|
1670
|
-
const artifactContent = artifact.content.toString("utf8") === "" ? undefined : content;
|
|
1671
|
-
if (jqPaths.length > 1) {
|
|
1672
|
-
const projections = jqPaths.map((path) => {
|
|
1673
|
-
const projected = projectArtifactPath(artifactContent, path);
|
|
1674
|
-
return projected.missed
|
|
1675
|
-
? artifactMissEntry(path, projected, artifactContent, id, explainMiss)
|
|
1676
|
-
: { 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) } : {}) };
|
|
1677
|
-
});
|
|
1678
|
-
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), projections, ...(projections.some((entry) => entry.pathMiss) ? { unanswered: true, hint: partialPathMissHint() } : {}) }, transport);
|
|
1679
|
-
}
|
|
1680
|
-
const projected = projectArtifactPath(artifactContent, options.jq);
|
|
1681
|
-
return emitTransportResult(projected.missed
|
|
1682
|
-
? { 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)) } : {}) }
|
|
1683
|
-
: { 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);
|
|
1684
|
-
}
|
|
1685
|
-
// r6-onboarding 2026-10-21: 47 artifact fetches, 0 used a projection; the 10
|
|
1686
|
-
// large ones (up to 55 KB) pulled whole workflow templates just to read one
|
|
1687
|
-
// nested key. Round 10 still spent 247 KB (22.7% of the session) on 28
|
|
1688
|
-
// `artifact get` calls, re-fetching 10–27 KB bodies — the nudge below was
|
|
1689
|
-
// advisory and did not change behaviour.
|
|
1690
|
-
//
|
|
1691
|
-
// 0.4.80: shape first, the same rule as `omc help`. Above the inline ceiling
|
|
1692
|
-
// the default is the depth-2 skeleton (same shapeOf as `--shape`; r75 调查C:
|
|
1693
|
-
// 两面共用一份实现——顶层键表请走 --summary,此处不再第二张雷同面);
|
|
1694
|
-
// `--full` returns the whole body exactly as before. Explicit projections
|
|
1695
|
-
// (--shape/--summary/--keys/--jq/--path-only) are handled above and are
|
|
1696
|
-
// never affected.
|
|
1697
|
-
if (options.full !== true && artifact.content.length > ARTIFACT_INLINE_CEILING_BYTES) {
|
|
1698
|
-
const depth = options.depth ?? 2;
|
|
1699
|
-
return emitTransportResult({
|
|
1700
|
-
status: "ok",
|
|
1701
|
-
artifactId: id,
|
|
1702
|
-
sha256: artifact.sha256,
|
|
1703
|
-
bytes: artifact.content.length,
|
|
1704
|
-
outline: true,
|
|
1705
|
-
depth,
|
|
1706
|
-
shape: shapeOf(content, depth),
|
|
1707
|
-
hint: artifactOutlineHint(id, artifact.content.length, depth),
|
|
1708
|
-
message: artifactOutlineHint(id, artifact.content.length, depth),
|
|
1709
|
-
projectionRule: "投影要写到叶子(数组元素里的字段);写整棵父节点(如 data.activities)会因总量超限再次被外置",
|
|
1710
|
-
...(() => {
|
|
1711
|
-
const rec = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
1712
|
-
const data = rec && rec.data && typeof rec.data === "object" && !Array.isArray(rec.data) ? rec.data : undefined;
|
|
1713
|
-
const leaf = data && Array.isArray(data.activities) ? "data.activities[].bizActions" : undefined;
|
|
1714
|
-
return leaf ? { projectionExample: `omc artifact get ${id} --jq '${leaf}'` } : {};
|
|
1715
|
-
})(),
|
|
1716
|
-
fullCommand: `omc artifact get ${id} --full`,
|
|
1717
|
-
}, transport);
|
|
1718
|
-
}
|
|
1719
|
-
const result = { status: "ok", artifactId: id, sha256: artifact.sha256, content, fullCommand: `omc artifact get ${id}`, projectionExample: `omc artifact get ${id} --jq '<path>'` };
|
|
1720
|
-
if (Buffer.byteLength(JSON.stringify(result), "utf8") > transport.maxOutputBytes) {
|
|
1721
|
-
// 2026-11-04 r70: `--full` used to fall back to the same bare `fetch`
|
|
1722
|
-
// pointer it had just been asked to bypass — re-running `--full` re-hits
|
|
1723
|
-
// the same ceiling, so a caller that genuinely needs the body loops
|
|
1724
|
-
// forever (observed live: three consecutive `--full` calls returned the
|
|
1725
|
-
// same id with bytes 90K→151K→227K of pointer metadata). Say what
|
|
1726
|
-
// actually happened and give the two projections that DO work.
|
|
1727
|
-
const record = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
1728
|
-
const keys = record
|
|
1729
|
-
? Object.entries(record)
|
|
1730
|
-
.map(([key, value]) => ({ key, bytes: Buffer.byteLength(JSON.stringify(value) ?? "null", "utf8") }))
|
|
1731
|
-
.sort((left, right) => right.bytes - left.bytes)
|
|
1732
|
-
.slice(0, 3)
|
|
1733
|
-
.map((entry) => entry.key)
|
|
1734
|
-
: [];
|
|
1735
|
-
// 0.6.82(issue 06 连锁):自愈文案加长后,fullRejected 回执自身可能超过
|
|
1736
|
-
// 顽强的小预算(调用方正用 1024B 这类极限值测试)——被 boundResult 二次
|
|
1737
|
-
// 截断会把 fullRejected 语义键一起截掉。按预算渐进丢弃可选长文案,
|
|
1738
|
-
// 语义键(fullRejected/artifactId/sha256/bytes + 最短出路)永不丢。
|
|
1739
|
-
const fullRejectedReceipt = {
|
|
1740
|
-
status: "ok",
|
|
1741
|
-
artifactId: id,
|
|
1742
|
-
sha256: artifact.sha256,
|
|
1743
|
-
bytes: artifact.content.length,
|
|
1744
|
-
fullRejected: true,
|
|
1745
|
-
reason: `整包 ${Math.round(artifact.content.length / 1024)}KB 超过本通道输出上限 ${transport.maxOutputBytes}B;--full 无法一次返回,再跑一次结果相同`,
|
|
1746
|
-
...(keys.length > 0 ? { keysCommand: `omc artifact get ${id} --keys ${keys.join(",")}`, sampledKeys: keys } : {}),
|
|
1747
|
-
jqCommand: `omc artifact get ${id} --jq '<path>'`,
|
|
1748
|
-
outCommand: `omc artifact get ${id} --out <配置根内文件路径>(整包落盘,不走 stdout 限额,适合一次性备份;根内父目录自动创建,越界拒绝的错误里带可用示例路径)`,
|
|
1749
|
-
raiseCeilingCommand: `omc artifact get ${id} --full --max-output-bytes ${Math.max(artifact.content.length + 1024, transport.maxOutputBytes * 2)}`,
|
|
1750
|
-
hint: "三选一:用 --jq/--keys 取你真正需要的那部分(推荐),整包落盘备份用 --out <配置根内路径>(写文件不受 stdout 限额),或显式抬高 --max-output-bytes",
|
|
1751
|
-
};
|
|
1752
|
-
const optionalKeys = ["hint", "raiseCeilingCommand", "keysCommand", "sampledKeys"];
|
|
1753
|
-
for (const drop of optionalKeys) {
|
|
1754
|
-
if (Buffer.byteLength(JSON.stringify(fullRejectedReceipt), "utf8") <= transport.maxOutputBytes)
|
|
1755
|
-
break;
|
|
1756
|
-
delete fullRejectedReceipt[drop];
|
|
1757
|
-
}
|
|
1758
|
-
return emitTransportResult(fullRejectedReceipt, transport);
|
|
1759
|
-
}
|
|
1760
|
-
return emitTransportResult(result, transport);
|
|
1761
|
-
}
|
|
1762
|
-
catch (error) {
|
|
1763
|
-
// Round 16 (bench67 feedback): a missing/expired artifact id is ordinary
|
|
1764
|
-
// caller error, not an internal fault — classify it as invalid-input with a
|
|
1765
|
-
// structured code and a recovery hint instead of a generic `internal`.
|
|
1766
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1767
|
-
if (message === "artifact not found" || message === "invalid artifact id") {
|
|
1768
|
-
const hint = message === "artifact not found"
|
|
1769
|
-
? "artifact 不存在或已被清理/过期;用产出它的命令返回的最新 artifactId(结果里的 fetch 提示)重新取,或重跑该命令"
|
|
1770
|
-
: "artifactId 不是合法 UUID(36 位十六进制/连字符)";
|
|
1771
|
-
const parsed = errorEnvelope(new Error(hint), "artifact-absent", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
1772
|
-
writeEnvelope(parsed.envelope);
|
|
1773
|
-
return parsed.exitCode;
|
|
1774
|
-
}
|
|
1775
|
-
const parsed = errorEnvelope(error, "internal", CLI_EXIT_CODES.internal, transport.request);
|
|
1776
|
-
writeEnvelope(parsed.envelope);
|
|
1777
|
-
return parsed.exitCode;
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
434
|
async function cmdBench(args) {
|
|
1781
435
|
const liveSample = args.includes("--live-sample");
|
|
1782
436
|
const envIndex = args.indexOf("--env");
|
|
@@ -3871,10 +2525,10 @@ async function main() {
|
|
|
3871
2525
|
commandExitCode = CLI_EXIT_CODES.ok;
|
|
3872
2526
|
});
|
|
3873
2527
|
command.command("doctor").option("--environment <environment>").option("--env <environment>").option("--service <serviceCode>", "可选:体检单个业务集成服务的鉴权参数形状(掩码/占位/全 0 检出,WARN 非致命)").option("--fresh-login", "忽略 token 缓存,做一次完整登录握手(默认复用缓存,登录请求 0 次;回执 loginSource 标明来源)").addOption(new Option("--jq [path]", "--jq 不是 jq,仅路径选择器(与 call --jq 同 DSL;可逗号多路径;裸 --jq 列顶层键),相对回执 result(checks/anchor/unsupportedCapabilities)").argParser((value, previous = []) => [...previous, value]).default([])).option("--explain", "--jq 未命中时给出完整排查载荷(available/correctPath/成因 hint);默认 miss 只回 missedAt/didYouMean/helpRef").action(async (options) => { commandExitCode = await cmdDoctor(new ConfigStore(defaultPaths()), options.environment ?? options.env, options.service, options.freshLogin === true, Array.isArray(options.jq) ? options.jq : [], options.explain === true); });
|
|
3874
|
-
command.command("call <tool>").option("--env <environment>", "环境名;项目白名单按当前 cwd 解析,须在含 .omc-env 的目录内运行").option("--environment <environment>").option("--args <json>").option("--args-file <path>", "从文件读参数 JSON。**必须位于配置根内**(数组批量请改用 --args-list;跨目录/系统临时文件会被拒);免落盘用 `--args -`(stdin)").option("--args-list <json-array>", '同一工具跑 N 次(JSON 数组,每条一个 args 对象,最多 200 条);超过上限请分批,或用 omc script 读文件。逐条执行、默认不中断,最后回 succeeded/failed
|
|
2528
|
+
command.command("call <tool>").option("--env <environment>", "环境名;项目白名单按当前 cwd 解析,须在含 .omc-env 的目录内运行").option("--environment <environment>").option("--args <json>").option("--args-file <path>", "从文件读参数 JSON。**必须位于配置根内**(数组批量请改用 --args-list;跨目录/系统临时文件会被拒);免落盘用 `--args -`(stdin)").option("--args-list <json-array>", '同一工具跑 N 次(JSON 数组,每条一个 args 对象,最多 200 条);超过上限请分批,或用 omc script 读文件。逐条执行、默认不中断,最后回 succeeded/failed 汇总;写工具整批取**一次**环境写锁(冲突时整批零执行,可 --wait 排队)。**只回汇总(succeeded/failed + 每行 ok),不内联各条 result**;读批量请用 `omc script -`(逐行带 result)或工具的 schemaCodes/ruleCodes 批参数。适合批量建字段等').option("--preflight", "与 --args-list 一起用:只跑参数校验 + 写前语义闸(零 wire、零写入),一次报全所有形状问题").option("--keys", "与 artifact get 的 --keys 同义(= --extract-keys):列出本次结果 artifact 的顶层键与体积").addOption(new Option("--extract <path>", "在本次结果的 artifact 内取一个路径的值(可重复;省掉一次 artifact get)").argParser((value, previous = []) => [...previous, value]).default([])).addOption(new Option("--jq [path]", "仅路径选择器,不是 jq(不支持 {a,b} 对象构造)——不是 jq 表达式,不支持管道;[] 映射如 items[].fields.planNo;裸 --jq 列顶层键。单路径命中时 result 直接是节点本体。示例:omc call model.list --env e --jq models · omc call rule.list --env e --args '{\"schemaCode\":\"m\"}' --jq rules[].code · omc call workflow.get_published --env e --args '{\"code\":\"f\"}' --jq activities[].bizActions").argParser((value, previous = []) => [...previous, value]).default([])).option("--extract-keys", "列出本次结果 artifact 的顶层键与体积(省掉一次 artifact get --keys)").option("--max-output-bytes <bytes>", "最终 stdout 信封预算;默认 65536(投影/--jq 之后再判);读面 diet(~2048) 独立外置 detailArtifactId,抬高本参数不会把已 diet 的大表重新内联;artifact get 内联上限 8192").option("--request-id <requestId>").option("--reason <text>", "写入原因(审计面,仅写操作):记入本次写 journal 行的 reason;不是工具参数(写 schema 拒未知键),也不参与任何门禁").option("--timeout-ms <milliseconds>").option("--wait <milliseconds>", "仅 `omc call` / `omc intent apply` 支持;写锁冲突时有界排队(0=立刻拒绝;`--args-list` 写批量按整批排队)").option("--dry-run").option("--quiet", "机器模式:抑制 stderr 人类诊断行(stdout 信封/退出码/artifact 不变;管道里不要 2>&1)").option("--explain", "--jq 未命中时给出完整排查载荷(available 该层全部键、correctPath、nextCommand、成因 hint);默认 miss 只回 missedAt/didYouMean/helpRef(≤300B)").addHelpText("after", `\n${onboardingHelp()}\n`).action(async (tool, options) => {
|
|
3875
2529
|
const rest = [tool, ...(options.env ? ["--env", options.env] : []), ...(options.environment ? ["--environment", options.environment] : []), ...(options.args !== undefined ? ["--args", options.args] : []), ...(options.argsFile !== undefined ? ["--args-file", options.argsFile] : []), ...(options.argsList !== undefined ? ["--args-list", options.argsList] : []), ...(options.preflight ? ["--preflight"] : []), ...(Array.isArray(options.extract) ? options.extract.flatMap((path) => ["--extract", path]) : []), ...(options.jq === true ? ["--jq"] : Array.isArray(options.jq) ? options.jq.flatMap((path) => path === true ? ["--jq"] : ["--jq", path]) : []), ...(options.extractKeys ? ["--extract-keys"] : []),
|
|
3876
2530
|
...(options.keys ? ["--keys"] : []), ...(options.maxOutputBytes !== undefined ? ["--max-output-bytes", options.maxOutputBytes] : []), ...(options.requestId ? ["--request-id", options.requestId] : []), ...(options.reason !== undefined ? ["--reason", options.reason] : []), ...(options.timeoutMs !== undefined ? ["--timeout-ms", options.timeoutMs] : []), ...(options.wait !== undefined ? ["--wait", options.wait] : []), ...(options.dryRun ? ["--dry-run"] : []), ...(options.explain ? ["--explain"] : [])];
|
|
3877
|
-
commandExitCode = await
|
|
2531
|
+
commandExitCode = await runCallCommand(new ConfigStore(defaultPaths()), rest);
|
|
3878
2532
|
});
|
|
3879
2533
|
command.command("compute").option("--schema <schemaCode>").option("--schema-code <schemaCode>").option("--target <propertyCode>").option("--property <propertyCode>").option("--formula <formula>").option("--where <condition>", "条件聚合:\"<子列code> = <值>\",与 --formula \"{<子表code>.<子列code>}\" 配合编译为 COUNTIF/SUMIF").option("--aggregate <count|sum>", "条件聚合用哪种:count(默认,→COUNTIF)/ sum(→SUMIF)").option("--allow-unfiltered", "显式接受「对整个子表列无条件聚合」;不给则拒绝(会把不符合条件的行也算进去)").option("--name <name>").option("--env <environment>").option("--environment <environment>").option("--apply").addHelpText("after", "\n字段计算规则拼装器:公式 {字段} 引用 → datarule type2 完整形状(editorText/editorMark 自动生成)。默认 dry-run,--apply 写入。条件聚合用 --formula \"{子表.子列}\" --where \"子列 = 值\"。复杂场景(条件分支/跨模型)走 omc next 的 recipe 路径。\n").action(async (options) => {
|
|
3880
2534
|
const rest = ["compute", ...(options.schema ? ["--schema", options.schema] : []), ...(options.schemaCode ? ["--schema-code", options.schemaCode] : []), ...(options.target ? ["--target", options.target] : []), ...(options.property ? ["--property", options.property] : []), ...(options.formula !== undefined ? ["--formula", options.formula] : []), ...(options.where !== undefined ? ["--where", options.where] : []), ...(options.aggregate !== undefined ? ["--aggregate", options.aggregate] : []), ...(options.allowUnfiltered ? ["--allow-unfiltered"] : []), ...(options.name ? ["--name", options.name] : []), ...(options.env ? ["--env", options.env] : []), ...(options.environment ? ["--environment", options.environment] : []), ...(options.apply ? ["--apply"] : [])];
|