@stalfh233/omc-cli 0.8.31 → 0.8.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arg-vocabulary.js +223 -0
- package/dist/artifact-cmd.js +443 -0
- package/dist/batch-call.js +56 -3
- package/dist/call-command.js +70 -0
- package/dist/call-execute.js +228 -0
- package/dist/call-input.js +557 -0
- package/dist/call-output.js +240 -0
- package/dist/cli.js +23 -1360
- package/dist/command-transport.js +4 -1
- package/dist/field-add.js +2 -1
- package/dist/form-support.js +17 -4
- package/dist/intent/plan-apply.js +14 -24
- package/dist/lanes/datarule.js +21 -0
- package/dist/lanes/field.js +31 -0
- package/dist/lanes/list-view-shapes.js +8 -1
- package/dist/lanes/list-view.js +64 -2
- package/dist/lanes/runtime-data/aggregate-support.js +209 -0
- package/dist/lanes/runtime-data/aggregate.js +679 -0
- package/dist/lanes/runtime-data/field-options.js +52 -0
- package/dist/lanes/runtime-data/lane.js +4 -0
- package/dist/lanes/runtime-data/record-delete.js +419 -0
- package/dist/lanes/runtime-data/record-read.js +984 -0
- package/dist/lanes/runtime-data/record-write.js +562 -0
- package/dist/lanes/runtime-data/registration.js +22 -0
- package/dist/lanes/runtime-data/shapes.js +594 -0
- package/dist/lanes/runtime-data/submission.js +1293 -0
- package/dist/lanes/runtime-data/write-support.js +875 -0
- package/dist/lanes/runtime-data-contract.js +1 -1
- package/dist/lanes/runtime-data.js +10 -5556
- 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 +3 -1
- package/dist/path-projection.js +27 -6
- 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 +3 -3
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { CLI_EXIT_CODES, classifyResult, envelope, refusalText, requestId } from "./cli-contract.js";
|
|
2
|
+
import { humanSummary, writeEnvelope } from "./cli-output.js";
|
|
3
|
+
import { BATCH_MAX_ENTRIES, runBatchCall } from "./batch-call.js";
|
|
4
|
+
import { runToolCall, validateAgentPaths } from "./call.js";
|
|
5
|
+
import { sessionAccountForEnvironment } from "./session-account.js";
|
|
6
|
+
import { buildToolRegistry } from "./tools.js";
|
|
7
|
+
import { parseToolInput, ToolInputError } from "./tool-types.js";
|
|
8
|
+
import { projectResultExtract, unwrapSinglePathProjection } from "./path-projection.js";
|
|
9
|
+
import { writeCoordinator, WriteLockConflictError } from "./write-coordinator.js";
|
|
10
|
+
import { argvValues, withUnknownEnvironmentRecovery } from "./call-input.js";
|
|
11
|
+
function resolvedDefaultEnvironment(store) {
|
|
12
|
+
try {
|
|
13
|
+
return store.resolveEnvironment(undefined).name;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return "default";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function executeCall(store, parsed) {
|
|
20
|
+
const { toolName, tool, registry, environment, requestValue, writeReason, rawArgs, argsFile, parsedArgs, dryRun, waitMs, timeoutMs } = parsed;
|
|
21
|
+
const toolKind = tool?.kind;
|
|
22
|
+
const callTool = async (lease) => {
|
|
23
|
+
const executed = await runToolCall(toolName, {
|
|
24
|
+
args: parsedArgs,
|
|
25
|
+
// O2: this registry already validated the args above; do not rebuild or
|
|
26
|
+
// re-parse the same input inside runToolCall.
|
|
27
|
+
registry,
|
|
28
|
+
parsedInput: true,
|
|
29
|
+
...(environment ? { environment } : {}),
|
|
30
|
+
...(requestValue !== undefined ? { requestId: requestValue } : {}),
|
|
31
|
+
...(writeReason !== undefined ? { reason: writeReason } : {}),
|
|
32
|
+
dryRun,
|
|
33
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
34
|
+
print: (line) => humanSummary(line),
|
|
35
|
+
});
|
|
36
|
+
if (executed.result?.status === "uncertain" && executed.result?.blocker === "cli-timeout" && lease !== undefined) {
|
|
37
|
+
// The write may still be in flight: keep the lock (stale-owner recovery
|
|
38
|
+
// releases it once this pid exits) instead of letting a second writer in.
|
|
39
|
+
lease.retain();
|
|
40
|
+
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)`);
|
|
41
|
+
}
|
|
42
|
+
return executed.result;
|
|
43
|
+
};
|
|
44
|
+
let result;
|
|
45
|
+
// A `--dry-run` never mutates the environment: the governed pipeline settles it
|
|
46
|
+
// before write admission, so it must not contend for the cross-process lock.
|
|
47
|
+
if (toolKind === "write" && !dryRun) {
|
|
48
|
+
const lockTarget = environment ?? resolvedDefaultEnvironment(store);
|
|
49
|
+
try {
|
|
50
|
+
result = await writeCoordinator.run({ environment: lockTarget, tool: toolName, waitMs, mode: "single" }, (lease) => callTool(lease));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!(error instanceof WriteLockConflictError))
|
|
54
|
+
throw error;
|
|
55
|
+
// r31b F2: structured retryable/lockOwner/nextCommand so scripts do not
|
|
56
|
+
// invent a shell retry loop (help says use --wait; the refusal must too).
|
|
57
|
+
return { kind: "lock-conflict", receipt: error.conflict.receipt, ...(error.conflict.stderr !== undefined ? { stderr: error.conflict.stderr } : {}) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
result = await callTool();
|
|
62
|
+
}
|
|
63
|
+
// GitLab #47:unknown --env 的恢复动作 = 去掉 --env 重跑同一调用。文案由
|
|
64
|
+
// config-store 给出绑定事实,这里补上只有 call 层才知道的 tool + 本次参数。
|
|
65
|
+
result = withUnknownEnvironmentRecovery(result, { tool: toolName, ...(rawArgs !== undefined ? { rawArgs } : {}), ...(argsFile !== undefined ? { argsFile } : {}), parsedArgs });
|
|
66
|
+
return { kind: "result", result };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `omc call <tool> --args-list '<json array>'` — see batch-call.ts for why this
|
|
70
|
+
* exists. The envelope is a summary; per-entry outcomes only appear for
|
|
71
|
+
* failures so a successful batch of 8 costs one short response, not eight.
|
|
72
|
+
*
|
|
73
|
+
* A write batch takes the environment write lock ONCE around the whole list
|
|
74
|
+
* (0.8.36): the entries are one serial operation, so they must not interleave
|
|
75
|
+
* with another process's write. The conflict receipt is the single-call face
|
|
76
|
+
* plus `batch:true`; `--wait` bounds that one acquisition.
|
|
77
|
+
*/
|
|
78
|
+
export async function runCallBatch(store, batch) {
|
|
79
|
+
const { toolName, argsList: rawList, environment: optionsEnvironment, requestValue: optionsRequestValue, args: optionsArgs, preflight: optionsPreflight, reason: optionsReason } = batch;
|
|
80
|
+
const request = optionsRequestValue ?? requestId();
|
|
81
|
+
// issue 07:批量面同款——汇总信封(含 preflight)都带 resultMeta.sessionAccount。
|
|
82
|
+
const accountMeta = () => ({ sessionAccount: sessionAccountForEnvironment(store, optionsEnvironment) });
|
|
83
|
+
let parsed;
|
|
84
|
+
try {
|
|
85
|
+
parsed = JSON.parse(rawList);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const message = `--args-list 必须是 JSON 数组:${error instanceof Error ? error.message : String(error)}`;
|
|
89
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
90
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(parsed)) {
|
|
93
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 必须是 JSON 数组(每条是一个 args 对象)", retryable: false }), resultMeta: accountMeta() });
|
|
94
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
95
|
+
}
|
|
96
|
+
const entries = parsed;
|
|
97
|
+
const badIndex = entries.findIndex((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry));
|
|
98
|
+
if (badIndex >= 0) {
|
|
99
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
100
|
+
code: "invalid-input",
|
|
101
|
+
message: `--args-list 第 ${badIndex} 条不是对象(每条必须是 {"字段":值} 形状)`,
|
|
102
|
+
retryable: false,
|
|
103
|
+
}), resultMeta: accountMeta() });
|
|
104
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
105
|
+
}
|
|
106
|
+
if (entries.length === 0) {
|
|
107
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 至少一条", retryable: false }), resultMeta: accountMeta() });
|
|
108
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
109
|
+
}
|
|
110
|
+
if (entries.length > BATCH_MAX_ENTRIES) {
|
|
111
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
112
|
+
code: "invalid-input",
|
|
113
|
+
message: `--args-list 最多 ${BATCH_MAX_ENTRIES} 条(本次 ${entries.length});分批执行或用 omc script 读文件`,
|
|
114
|
+
retryable: false,
|
|
115
|
+
}), resultMeta: accountMeta() });
|
|
116
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
for (const entry of entries)
|
|
120
|
+
validateAgentPaths(entry);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
124
|
+
code: "invalid-input",
|
|
125
|
+
message: `--args-list 含越界路径:${error instanceof Error ? error.message : String(error)}`,
|
|
126
|
+
retryable: false,
|
|
127
|
+
}), resultMeta: accountMeta() });
|
|
128
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
129
|
+
}
|
|
130
|
+
// Whole-batch shape precheck (issue 2026-10-25 §6): `--args-list --dry-run`
|
|
131
|
+
// runs every entry through the full tool (reads included) to report N
|
|
132
|
+
// previews. When the caller only wants "will this batch be accepted", the
|
|
133
|
+
// per-tool semantic gate is the thing that refuses mis-shapes, and it is
|
|
134
|
+
// pure — no wire, no writes. Run it for every entry and report ALL failures
|
|
135
|
+
// in one envelope instead of N round-trips.
|
|
136
|
+
if (optionsPreflight === true) {
|
|
137
|
+
const tool = buildToolRegistry().find((definition) => definition.name === toolName);
|
|
138
|
+
if (!tool) {
|
|
139
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: `unknown tool ${toolName};用 omc next 或 omc commands --json --compact --lane <lane> 定位`, retryable: false }), resultMeta: accountMeta() });
|
|
140
|
+
return CLI_EXIT_CODES.invalidInput;
|
|
141
|
+
}
|
|
142
|
+
const failures = [];
|
|
143
|
+
entries.forEach((entry, index) => {
|
|
144
|
+
try {
|
|
145
|
+
const parsedEntry = parseToolInput(tool, {
|
|
146
|
+
...entry,
|
|
147
|
+
...(optionsEnvironment !== undefined && entry.environment === undefined ? { environment: optionsEnvironment } : {}),
|
|
148
|
+
});
|
|
149
|
+
tool.writePreflight?.(parsedEntry);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
// ToolRefusalError carries the real payload (blocker/citation/validation);
|
|
153
|
+
// rebuild it only when the failure is a plain Error.
|
|
154
|
+
const carried = error.payload;
|
|
155
|
+
const payload = error instanceof ToolInputError ? error.payload : carried ?? { status: "refused", blocker: "tool-input-invalid", message: error instanceof Error ? error.message : String(error) };
|
|
156
|
+
failures.push({ index, blocker: payload.blocker ?? null, message: refusalText(payload), ...(Array.isArray(payload.validation) ? { validation: payload.validation } : {}), ...(payload.citation !== undefined ? { citation: payload.citation } : {}) });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
let result = {
|
|
160
|
+
status: failures.length > 0 ? "partial" : "ok",
|
|
161
|
+
mode: "preflight",
|
|
162
|
+
shapeOnly: true,
|
|
163
|
+
tool: toolName,
|
|
164
|
+
requested: entries.length,
|
|
165
|
+
shapeChecked: entries.length,
|
|
166
|
+
failed: failures.length,
|
|
167
|
+
writes: 0,
|
|
168
|
+
// On failure the caller has to change the JSON first, so there is no
|
|
169
|
+
// runnable command yet; on success, hand over the exact execution command.
|
|
170
|
+
...(failures.length > 0 ? { failures } : { nextCommand: `omc call ${toolName} --args-list '<file|stdin>'` }),
|
|
171
|
+
};
|
|
172
|
+
const preflightPaths = [...argvValues(optionsArgs, "--extract"), ...argvValues(optionsArgs, "--jq")]
|
|
173
|
+
.flatMap((path) => path.split(",")).map((path) => path.trim()).filter(Boolean);
|
|
174
|
+
const preflightKeys = optionsArgs.includes("--extract-keys") || optionsArgs.includes("--keys") || optionsArgs.some((token, index) => token === "--jq" && (optionsArgs[index + 1] === undefined || optionsArgs[index + 1].startsWith("--")));
|
|
175
|
+
if (preflightPaths.length > 0 || preflightKeys) {
|
|
176
|
+
const projected = projectResultExtract(result, preflightPaths, preflightKeys, { tool: toolName, ...(optionsEnvironment !== undefined ? { environment: optionsEnvironment } : {}) });
|
|
177
|
+
if (projected !== undefined)
|
|
178
|
+
result = projected;
|
|
179
|
+
}
|
|
180
|
+
const classified = classifyResult(result);
|
|
181
|
+
// 与 `omc call --jq` 同一契约(issue 2026-11-18 §05):单路径命中时 result 是本体。
|
|
182
|
+
const unwrapped = preflightPaths.length === 1 && !preflightKeys && Array.isArray(result.extract)
|
|
183
|
+
? unwrapSinglePathProjection(result)
|
|
184
|
+
: undefined;
|
|
185
|
+
const envelopeValue = envelope(classified.status, unwrapped !== undefined ? unwrapped.result : result, request, classified.error);
|
|
186
|
+
writeEnvelope({
|
|
187
|
+
...envelopeValue,
|
|
188
|
+
resultMeta: { sessionAccount: accountMeta().sessionAccount, ...(unwrapped?.resultMeta ?? {}) },
|
|
189
|
+
});
|
|
190
|
+
return failures.length > 0 ? 1 : 0;
|
|
191
|
+
}
|
|
192
|
+
const dryRun = optionsArgs.includes("--dry-run");
|
|
193
|
+
const runEntries = () => runBatchCall({
|
|
194
|
+
tool: toolName,
|
|
195
|
+
argsList: entries,
|
|
196
|
+
...(optionsEnvironment !== undefined ? { environment: optionsEnvironment } : {}),
|
|
197
|
+
...(dryRun ? { dryRun: true } : {}),
|
|
198
|
+
...(optionsReason !== undefined ? { reason: optionsReason } : {}),
|
|
199
|
+
requestId: request,
|
|
200
|
+
});
|
|
201
|
+
// 0.8.36:写批量整批取**一次**环境写锁(串行语义),与单条 `omc call` 互斥。
|
|
202
|
+
// 取锁失败 = 零条执行(没有「前 3 条已写、第 4 条撞锁」的交错)。读批量与
|
|
203
|
+
// dry-run 不取锁:它们不改变环境,争锁只会把读面拖成串行。
|
|
204
|
+
const toolKind = buildToolRegistry().find((definition) => definition.name === toolName)?.kind;
|
|
205
|
+
let batched;
|
|
206
|
+
if (toolKind === "write" && !dryRun) {
|
|
207
|
+
const lockTarget = optionsEnvironment ?? resolvedDefaultEnvironment(store);
|
|
208
|
+
try {
|
|
209
|
+
batched = await writeCoordinator.run({ environment: lockTarget, tool: `${toolName}:batch`, waitMs: batch.waitMs, mode: "batch", batchTool: toolName }, runEntries);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
if (!(error instanceof WriteLockConflictError))
|
|
213
|
+
throw error;
|
|
214
|
+
if (error.conflict.stderr !== undefined)
|
|
215
|
+
console.error(error.conflict.stderr);
|
|
216
|
+
const refused = classifyResult(error.conflict.receipt);
|
|
217
|
+
writeEnvelope({ ...envelope("refused", error.conflict.receipt, request, refused.error), resultMeta: accountMeta() });
|
|
218
|
+
return CLI_EXIT_CODES.policyRefused;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
batched = await runEntries();
|
|
223
|
+
}
|
|
224
|
+
const classified = classifyResult(batched.result);
|
|
225
|
+
writeEnvelope({ ...envelope(classified.status, batched.result, request, classified.error), resultMeta: accountMeta() });
|
|
226
|
+
return batched.exitCode;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=call-execute.js.map
|