@stalfh233/omc-cli 0.6.86 → 0.6.87

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.
@@ -0,0 +1,236 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { basename } from "node:path";
3
+ import { appendJournalEntry } from "./journal.js";
4
+ import { journalAudit } from "./write-audit.js";
5
+ import { isUncertainWireError, wireErrorKind, writeArtifact } from "./support.js";
6
+ import { WireError } from "./wire.js";
7
+ import { ToolRefusalError } from "./tool-types.js";
8
+ /**
9
+ * Ticket 58: the batch time budget. `startedAt` is the execution start (ms
10
+ * epoch); `budgetMs` undefined means no budget. Exported so the arithmetic is
11
+ * pinned by a unit test instead of a timing-sensitive S1 test.
12
+ */
13
+ export function batchBudgetExceeded(startedAt, budgetMs, now) {
14
+ if (budgetMs === undefined)
15
+ return false;
16
+ return now - startedAt >= budgetMs;
17
+ }
18
+ /**
19
+ * The default whole-batch time budget (8 minutes), applied when the caller
20
+ * omits `totalTimeoutMs`. It MUST stay safely below the CLI's own call timeout:
21
+ * the omc CLI caps `--timeout-ms` at 600000 ms (10 min), and the 2026-09-14
22
+ * `eq_repair_record` incident was exactly the failure mode of a batch that
23
+ * outlives its caller — the caller abandoned at its timeout while the batch
24
+ * kept executing, and the agent's retry became a second writer in the same
25
+ * environment. Stopping at a bounded budget returns a clean `uncertain` +
26
+ * progressFile + resumeFromIndex while the caller is still listening.
27
+ */
28
+ export const DEFAULT_BATCH_BUDGET_MS = 8 * 60 * 1000;
29
+ export async function executeGovernedBatch(input) {
30
+ const { changes, mode, runTool } = input;
31
+ const rollback = mode === "rollback";
32
+ const steps = [];
33
+ // Ticket 58: a recoverable handle for a long batch. Every step appends to one
34
+ // progress artifact, so a client-side timeout or a killed server still leaves
35
+ // the exact progress on disk.
36
+ const runId = randomUUID().slice(0, 8);
37
+ const startedAt = Date.now();
38
+ const budgetMs = input.timeoutMs ?? DEFAULT_BATCH_BUDGET_MS;
39
+ const summaryEcho = input.summary !== undefined && input.summary.length > 0 ? `${input.summary};` : "";
40
+ const progressPlan = input.progress;
41
+ const recordProgress = progressPlan !== undefined
42
+ ? (status, upTo) => writeArtifact(progressPlan.ctx, `${rollback ? "rollback" : "batch"}-progress-${runId}.json`, {
43
+ runId,
44
+ summary: progressPlan.summary,
45
+ startedAt,
46
+ budgetMs: budgetMs ?? null,
47
+ steps,
48
+ nextIndex: upTo,
49
+ status,
50
+ }).detailFile
51
+ : undefined;
52
+ const withProgress = (envelope, progressFile) => progressFile !== undefined ? { ...envelope, progressFile } : { ...envelope };
53
+ for (let index = 0; index < changes.length; index += 1) {
54
+ const change = changes[index];
55
+ const stop = (status, envelope) => {
56
+ input.onStep?.({ index, tool: change.tool, ok: false, steps: [...steps] });
57
+ return { kind: "stop", outcome: { status, steps, failedStep: { index, tool: change.tool }, envelope } };
58
+ };
59
+ if (batchBudgetExceeded(startedAt, budgetMs, Date.now())) {
60
+ const progressFile = recordProgress?.("STOPPED", steps.length);
61
+ const envelope = withProgress({
62
+ blocker: "batch-timeout-budget",
63
+ frozen: true,
64
+ budgetMs,
65
+ message: rollback
66
+ ? `已达恢复批预算 ${budgetMs}ms,在第 ${index + 1} 步(${change.tool})前停止;已完成 ${steps.length} 项恢复(其效果真实存在,各自已记 journal)。先读 progressFile 与 omc rollback list 核对进度,再对剩余恢复调用决定续跑——绝不盲重试`
67
+ : `已达整批预算 ${budgetMs}ms,在第 ${index + 1} 步(${change.tool})前停止;已完成 ${steps.length} 项(其效果真实存在)。先读 progressFile 与只读发现确认进度,再决定是否续跑——绝不盲重试`,
68
+ summary: rollback
69
+ ? `${summaryEcho}恢复批达预算停止于第 ${index + 1} 步前,已完成 ${steps.length} 项`
70
+ : `${summaryEcho}批量达预算停止于第 ${index + 1} 步前,已完成 ${steps.length} 项`,
71
+ // Ticket 81: structured recovery semantics — a timeout is NOT
72
+ // failure; the server may have completed everything.
73
+ nextAction: {
74
+ rule: "read-back-first",
75
+ steps: rollback
76
+ ? [
77
+ "读 progressFile:拿到已完成恢复步骤清单(其效果真实存在,各自已记 journal)",
78
+ "用 omc rollback list / plan 核对每个已完成恢复写的现态",
79
+ `仅对缺失的恢复调用继续:从 failedStep.index=${index} 起对原 seq 重新 rollback apply(先 plan 复看 inverse 全集,剔除读回确认已生效的步骤)`,
80
+ ]
81
+ : [
82
+ "读 progressFile:拿到已完成步骤清单(其效果真实存在于环境)",
83
+ "用只读发现核对每一步的权威面(discover_environment / 对应 lane 的 list/get 读回;写工具的 already-present/already-published 短路可安全复用)",
84
+ `仅对缺失步骤重新组包:从 failedStep.index=${index} 起,剔除读回确认已生效的项`,
85
+ ],
86
+ forbidden: rollback
87
+ ? "盲目整批重试——已完成的恢复写重复执行会覆盖后续变更或触发重复码拒绝"
88
+ : "盲目整批重试——已完成步骤会重复执行或触发重复码拒绝(如 listview.create 303002)",
89
+ resumeFromIndex: index,
90
+ },
91
+ }, progressFile);
92
+ return stop("uncertain", envelope);
93
+ }
94
+ let run;
95
+ try {
96
+ run = await runTool(change, index);
97
+ }
98
+ catch (error) {
99
+ const failedStep = { index, tool: change.tool };
100
+ const progressFile = recordProgress?.("STOPPED", steps.length);
101
+ if (isUncertainWireError(error)) {
102
+ // Per-step transport/timeout: uncertain, frozen — never success.
103
+ return stop("uncertain", withProgress({
104
+ frozen: true,
105
+ reason: `wire-transport:${wireErrorKind(error)}`,
106
+ detail: error.message,
107
+ message: rollback
108
+ ? `第 ${index + 1} 步恢复调用(${change.tool})传输中断,恢复结果无法判定;已冻结——先重新发现再决定重试,绝不假定为成功`
109
+ : `第 ${index + 1} 步(${change.tool})传输中断,写入结果无法判定;已冻结——先重新发现再决定重试,绝不假定为成功`,
110
+ summary: rollback
111
+ ? `${summaryEcho}恢复批在第 ${index + 1} 步(${change.tool})中断,已完成 ${steps.length} 项,结果不确定`
112
+ : `${summaryEcho}批量在第 ${index + 1} 步(${change.tool})中断,已完成 ${steps.length} 项,结果不确定`,
113
+ // Ticket 81: the interrupted step itself may have taken
114
+ // effect server-side — read back before any retry.
115
+ nextAction: {
116
+ rule: "read-back-first",
117
+ steps: rollback
118
+ ? [
119
+ "读 progressFile:拿到已完成恢复步骤清单(其效果真实存在,各自已记 journal)",
120
+ `先核对第 ${index + 1} 步恢复调用(${change.tool})本身是否已生效——超时≠失败,服务端可能已写入`,
121
+ "用 omc rollback list / plan 核对每个已完成恢复写,仅对缺失步骤对原 seq 重新 rollback apply",
122
+ ]
123
+ : [
124
+ "读 progressFile:拿到已完成步骤清单(其效果真实存在于环境)",
125
+ `先核对第 ${index + 1} 步(${change.tool})本身是否已生效——超时≠失败,服务端可能已写入`,
126
+ "用只读发现核对每一步的权威面,仅对缺失步骤重新组包执行",
127
+ ],
128
+ forbidden: rollback
129
+ ? "盲目整批重试或假定中断步骤失败——重复执行会覆盖后续变更"
130
+ : "盲目整批重试或假定中断步骤失败——重复执行会撞重复码(如 listview.create 303002)",
131
+ resumeFromIndex: index,
132
+ },
133
+ }, progressFile));
134
+ }
135
+ const envelope = error instanceof ToolRefusalError
136
+ ? { ...error.payload }
137
+ : error instanceof WireError
138
+ ? { blocker: `wire-${error.kind}`, errcode: error.errcode, message: error.message }
139
+ : { blocker: rollback ? "rollback-step-failed" : "apply-changes-step-failed", message: error.message };
140
+ return stop("refused", withProgress({
141
+ ...envelope,
142
+ message: rollback
143
+ ? `${typeof envelope.message === "string" ? envelope.message : "恢复调用失败"};恢复批在第 ${index + 1} 步(${change.tool})停止,后续恢复调用未执行;已完成恢复见 steps(其效果真实存在,各自已记 journal)`
144
+ : `${typeof envelope.message === "string" ? envelope.message : "步骤失败"};批量在第 ${index + 1} 步(${change.tool})停止,后续步骤未执行;已完成步骤见 steps(其效果真实存在,需要善后时按 steps 清单处理)`,
145
+ summary: rollback
146
+ ? `${summaryEcho}恢复批在第 ${index + 1} 步(${change.tool})停止,已完成 ${steps.length} 项`
147
+ : `${summaryEcho}批量在第 ${index + 1} 步(${change.tool})停止,已完成 ${steps.length} 项`,
148
+ }, progressFile));
149
+ }
150
+ if (run.kind === "stop") {
151
+ // A step-chain write (field.update cascadeRepublish) may RETURN a
152
+ // mid-chain stop instead of throwing, and a rollback replay call may
153
+ // settle non-zero: surface it as this batch's stop with the entry
154
+ // face's own envelope preserved for audit.
155
+ const progressFile = recordProgress?.("STOPPED", steps.length);
156
+ const envelope = rollback
157
+ ? withProgress({
158
+ ...run.envelope,
159
+ nextAction: {
160
+ rule: "read-back-first",
161
+ steps: [
162
+ "读 progressFile:拿到已完成恢复步骤清单(其效果真实存在,各自已记 journal)",
163
+ "用 omc rollback list / plan 核对每个已完成恢复写的现态",
164
+ `缺失的恢复从 failedStep.index=${index} 起对原 seq 重新 rollback apply(先 plan 复看 inverse 全集)`,
165
+ ],
166
+ forbidden: "把 stopped 当作失败去回滚已完成的恢复写——它们已是目标态",
167
+ resumeFromIndex: index,
168
+ },
169
+ }, progressFile)
170
+ : withProgress({
171
+ ...run.envelope,
172
+ message: `${String(run.envelope.message ?? "步骤失败")}(第 ${index + 1} 步 ${change.tool} 的内部级联中途停止)`,
173
+ }, progressFile);
174
+ return stop(run.status, envelope);
175
+ }
176
+ steps.push(run.step);
177
+ recordProgress?.("RUNNING", index + 1);
178
+ input.onStep?.({ index, tool: change.tool, ok: true, steps: [...steps] });
179
+ }
180
+ const progressFile = recordProgress?.("DONE", steps.length);
181
+ const stepTools = [...new Set(changes.map((change) => change.tool))];
182
+ return { kind: "ok", steps, stepTools, ...(progressFile !== undefined ? { progressFile } : {}) };
183
+ }
184
+ /**
185
+ * One honest journal line per delivered batch (audit only, not a rollback
186
+ * unit). Shared by apply_changes (and therefore intent apply, W11C) and
187
+ * rollback apply (B1): the line is `rollbackable:false` because the STEP-level
188
+ * before snapshots belong to the individual governed writes, not the batch —
189
+ * the batch line can never pretend to be a rollback unit. Delivered batches
190
+ * only; a stopped batch's audit lives in its per-step journal lines plus the
191
+ * stop receipt (progressFile/package artifact), never a fake "delivered" row.
192
+ *
193
+ * The receipt is deliberately NOT extended by this helper (byte-for-byte
194
+ * stable for eval baselines): the audit line is discoverable with
195
+ * `omc rollback list --tool apply_changes` / `--tool rollback`.
196
+ */
197
+ export async function appendBatchAuditLine(input) {
198
+ const { ctx, mode, steps } = input;
199
+ if (steps.length === 0)
200
+ return;
201
+ const tools = [...new Set(steps.map((step) => String(step.step ?? "?")))];
202
+ const rollback = mode === "rollback";
203
+ const target = `${rollback ? "rollback-batch" : "batch"}:${tools.slice(0, 3).join("+")}${tools.length > 3 ? `+${tools.length - 3}` : ""}`;
204
+ const summary = input.summary;
205
+ let environment = typeof input.environmentArg === "string" && input.environmentArg.length > 0 ? input.environmentArg : "local";
206
+ let environmentFingerprint = rollback ? "rollback-batch" : "batch";
207
+ try {
208
+ // The batch itself established this session: a cache hit, never a second login.
209
+ const session = await ctx.sessions.session(input.environmentArg);
210
+ environment = session.environmentName;
211
+ environmentFingerprint = session.environmentFingerprint();
212
+ }
213
+ catch {
214
+ /* journal still useful with the raw env name */
215
+ }
216
+ const rollbackOf = input.rollbackOf;
217
+ const note = rollback
218
+ ? `恢复批审计行(${steps.length} 步:${tools.slice(0, 6).join("、")}${rollbackOf !== undefined ? `;回滚 seq ${rollbackOf.seq} 的 ${rollbackOf.tool} 写` : ""}${summary !== undefined ? `;${summary}` : ""}):本行只是汇总(rollbackable:false,不是回滚单元);逐步恢复写已各自记 journal——对单个恢复写 seq 再 plan/apply`
219
+ : `批量审计行(${steps.length} 步:${tools.slice(0, 6).join("、")}${summary !== undefined ? `;${summary}` : ""}):逐步 before 快照未捕获,不能整包回滚;逐项恢复请用对应单工具写面重做`;
220
+ const entry = appendJournalEntry(ctx.artifactsDir, {
221
+ v: 1,
222
+ environment,
223
+ environmentFingerprint,
224
+ tool: rollback ? "rollback.apply" : "apply_changes",
225
+ target,
226
+ beforeSha: null,
227
+ rollbackable: false,
228
+ note,
229
+ ...journalAudit(ctx.sessions.config(), environment, input.reason),
230
+ artifactFile: input.progressFile ?? `${target.replace(/[^\w.-]+/gu, "_")}.batch.json`,
231
+ artifactId: input.progressFile !== undefined ? basename(input.progressFile) : rollback ? "rollback.apply-batch" : "apply_changes-batch",
232
+ artifactSha: typeof input.fingerprint === "string" ? input.fingerprint : "batch",
233
+ });
234
+ void entry;
235
+ }
236
+ //# sourceMappingURL=batch-executor.js.map
@@ -172,9 +172,9 @@ const SURFACES = [
172
172
  title: "业务集成",
173
173
  lane: LANES.b2,
174
174
  description: "业务服务与方法注册(RESTFUL/DATA_SQL/DATA_TABLE/SAP/KAFKA/SOAP)、服务清单(按分类/关键词,凭据不回显)、导入导出、设计器测试、调用日志(h_log_biz_service 读面:params/result/状态/耗时)。",
175
- operations: ["list", "register", "update", "method.create", "method.update", "delete", "export", "import", "check", "test", "log"],
175
+ operations: ["list", "register", "update", "method.create", "method.update", "method.delete", "delete", "export", "import", "check", "test", "log"],
176
176
  requires: [],
177
- intent: { level: "partial", note: "声明式支持新建 service.register(可带一个 method 或 methods[] 多方法,后者 name 可不同于 code)与既有 service/method 的 update,含给既有服务加方法(method.create);删除、分类/连接池/IE 仍走 escape hatch。" },
177
+ intent: { level: "partial", note: "声明式支持 service.register(可带一个 method 或 methods[] 多方法,后者 name 可不同于 code)、既有 service/method 的 update、给既有服务加方法(method.create),以及 service/methods[].absent:true 删除(服务删除有引用硬门 intent-service-referenced;方法删除以平台 500108 为权威,plan 给 warning);分类/连接池/IE 仍走 escape hatch。" },
178
178
  notes: "方法 configJson 走 AES-128-ECB;RESTFUL/DATA_SQL 绑定前须带适配器必需配置(否则是注册壳)。",
179
179
  },
180
180
  {
package/dist/cli.js CHANGED
@@ -49,6 +49,8 @@ else if (process.env.OMC_ASCII_STDOUT !== "0" && process.argv.some((arg) => arg
49
49
  }
50
50
  import { SEARCH_MARGIN_THRESHOLD } from "./tool-search.js";
51
51
  import { commandCapabilitySlice, commandIndex, commandInventory, commandKindIndex, describeContract, describeContractFull, describeContractTool, describeExample, describeParam, describeSchemaOnly, describeTool, describeToolFull, filterTools } from "./discovery.js";
52
+ import { locatorMetaFor } from "./read-shapes.js";
53
+ import { surfaceRefFor } from "./surface-ref.js";
52
54
  import { closestMatches } from "./closest-match.js";
53
55
  import { KEY_ALIAS_HINTS, inputAliasSynonymKeys } from "./tool-types.js";
54
56
  import { repeatFullDescribe } from "./describe-cache.js";
@@ -920,9 +922,13 @@ async function cmdCall(store, args) {
920
922
  // body 自带 `status`/`blocker` 时(如 --jq 直接取回整包),信封的 error 仍以
921
923
  // **投影前**的 classified 为准——别让 payload 里的字段改写本调用的结论。
922
924
  const emitValue = unwrappedBody !== undefined ? unwrappedBody : result;
925
+ // A2(r89 契约层):跨面键名对照(read-shapes 单一声明)挂信封 resultMeta.locator——
926
+ // 成功读回才有定位意义;result 本体与 --jq 路径零改动。
927
+ const locatorExtra = classified.status === "ok" ? locatorMetaFor(toolName) : undefined;
928
+ const mergedMeta = { ...(locatorExtra ?? {}), ...(resultMeta ?? {}) };
923
929
  const extras = unwrappedBody !== undefined
924
- ? { error: classified.error, ...(resultMeta !== undefined ? { resultMeta } : {}) }
925
- : resultMeta !== undefined ? { resultMeta } : undefined;
930
+ ? { error: classified.error, ...(Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : {}) }
931
+ : Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : undefined;
926
932
  return emit(classified.status, emitValue, classified.exitCode, extras);
927
933
  }
928
934
  finally {
@@ -1652,6 +1658,18 @@ function cmdDiscovery(kind, transport, value, options = {}) {
1652
1658
  if (semanticByName !== undefined)
1653
1659
  for (const tool of inventory.tools)
1654
1660
  tool.matchedVia = semanticByName.get(String(tool.name))?.via;
1661
+ // A3(r89 契约层):搜索命中后的结构化交接——非分组面 top1 附 surfaceRef
1662
+ // (firstCall/needs/returns/onRefusal 一次拿全,省 describe 一跳);top2/3 作
1663
+ // alternatives(when=命中信号)。宽词分组面行被隐藏,surfaceRef 挂了也看不见,
1664
+ // 只在 filtered.top 留名(原行为不变)。
1665
+ if (!groupedFace && scoped.length > 0) {
1666
+ const ref = surfaceRefFor(registry, scoped[0].name, {
1667
+ via: scoped[0].via,
1668
+ alternatives: scoped.slice(1, 3).map((hit) => ({ tool: hit.name, when: hit.via })),
1669
+ });
1670
+ if (ref !== undefined)
1671
+ inventory.surfaceRef = ref;
1672
+ }
1655
1673
  // A filtered query wants tool rows, not the whole catalogue's discovery,
1656
1674
  // skills, and intent prose. Keep only the authoritative route pointer.
1657
1675
  delete inventory.skills;
@@ -3190,7 +3208,7 @@ async function main() {
3190
3208
  script: { lines: lines.length, skipped: parsed.skipped.length },
3191
3209
  }, 0);
3192
3210
  });
3193
- const rollbackCommand = command.command("rollback").description("配置回滚(git-revert 语义):list 列写时间线 / plan 预览恢复(diff+后续写覆盖警告)/ apply 执行恢复——恢复走完整写闸门并记 journal(回滚可再回滚)。list 支持 --since <ISO|30m|2h> 收窄窗口,并回显每行的 actor(token 解码,actorSource:token-claim,不是平台 currentUser)与 reason(写入时 --reason 声明);apply 支持 --reason 与 --wait <毫秒> 有界排队。list/plan 为只读面不接写锁。journal 是**项目级**审计面(.omc/journal/<env>.ndjson,随项目目录、本机边界:不跨机器、不跨项目;故意不做第二个 omc audit 真相源)。接入全部配置写面(workflow/规则/数据规则/视图/表单草稿/在线JS/字典/字段/模型/应用/报表)+ 批量写审计行(apply_changes/intent apply,rollbackable:false 只记录);publish 类生命周期推进不可逆(plan 会说明)");
3211
+ const rollbackCommand = command.command("rollback").description("配置回滚(git-revert 语义):list 列写时间线 / plan 预览恢复(diff+后续写覆盖警告)/ apply 执行恢复——恢复走完整写闸门并记 journal(回滚可再回滚)。list 支持 --since <ISO|30m|2h> 收窄窗口,并回显每行的 actor(token 解码,actorSource:token-claim,不是平台 currentUser)与 reason(写入时 --reason 声明);apply 支持 --reason 与 --wait <毫秒> 有界排队。list/plan 为只读面不接写锁。journal 是**项目级**审计面(.omc/journal/<env>.ndjson,随项目目录、本机边界:不跨机器、不跨项目;故意不做第二个 omc audit 真相源)。接入全部配置写面(workflow/规则/数据规则/视图/表单草稿/在线JS/字典/字段/模型/应用/报表)+ 批量写审计行(apply_changes/intent apply/rollback apply,rollbackable:false 只记录);publish 类生命周期推进不可逆(plan 会说明)");
3194
3212
  rollbackCommand.command("list").option("--env <environment>").option("--environment <environment>").option("--target <substr>").option("--tool <name>").option("--limit <n>").option("--since <ISO|duration>", "只保留该时刻之后的写:ISO(2026-11-20T09:30Z)或带单位时长(30m、2h、7d);非法值即 invalid-input,不猜窗口").action(async (options) => {
3195
3213
  commandExitCode = await withTransport(options, "rollback list", (transport) => cmdRollbackList({ environment: options.env ?? options.environment, target: options.target, tool: options.tool, limit: options.limit, since: options.since }, transport));
3196
3214
  });
package/dist/discovery.js CHANGED
@@ -230,6 +230,20 @@ export function commandCapabilitySlice(registry, capabilityId, options = {}) {
230
230
  ...(recipes.length > 0 ? { recipes } : {}),
231
231
  };
232
232
  }),
233
+ // A3(r89 契约层):族级 default 交接——本能力的读面起手工具(同 surfaceRef
234
+ // 结构的 recommended 切片,requiredArgs 同一实现;firstCall/needs/returns 等
235
+ // 完整面一步 `omc describe <tool>`,族面不整份复制)。
236
+ ...(tools.length > 0
237
+ ? {
238
+ surfaceRef: {
239
+ recommended: {
240
+ tool: (tools.find((tool) => tool.kind === "read") ?? tools[0]).name,
241
+ argsHint: requiredArgs(tools.find((tool) => tool.kind === "read") ?? tools[0]).join(","),
242
+ via: `${route.id} 能力读面起手`,
243
+ },
244
+ },
245
+ }
246
+ : {}),
233
247
  next: {
234
248
  detail: "omc describe <tool>(参数/必填/firstCall)",
235
249
  executable: `omc capability ${route.id} --executable`,
@@ -441,7 +455,7 @@ function placeholderKeys(args) {
441
455
  function trimPreconditions(preconditions) {
442
456
  const kept = [];
443
457
  let bytes = 0;
444
- for (const entry of preconditions) {
458
+ for (const entry of preconditions ?? []) {
445
459
  const next = bytes + Buffer.byteLength(entry, "utf8") + 4;
446
460
  if (kept.length >= 3 || next > 420)
447
461
  break;
@@ -663,6 +677,41 @@ function documentedParamNames(tool) {
663
677
  }
664
678
  return names.sort();
665
679
  }
680
+ // A3(r89 契约层):surface-ref 共享交接的原料导出。requiredArgs 与
681
+ // leanFirstCallFor 仍是唯一实现(describe 默认面同源),surface-ref.ts 只组包,
682
+ // 不复制第二份真相——发现面三处(next / commands --filter / plan)共用一份。
683
+ export { requiredArgs };
684
+ /** The lean firstCall projection the default describe face inlines (A3 shared source). */
685
+ export function leanFirstCallFor(tool) {
686
+ const firstCall = firstCallFor(tool);
687
+ return firstCall === undefined ? undefined : leanFirstCall(firstCall);
688
+ }
689
+ /** The paste-able one-liner command when the recipe args are small enough (A3 shared source). */
690
+ export function firstCallCommandFor(tool) {
691
+ const firstCall = firstCallFor(tool);
692
+ if (firstCall === undefined)
693
+ return undefined;
694
+ const out = {
695
+ recipeId: String(firstCall.recipeId),
696
+ missing: Array.isArray(firstCall.missing) ? firstCall.missing : [],
697
+ };
698
+ if (typeof firstCall.command === "string")
699
+ out.command = firstCall.command;
700
+ if (typeof firstCall.commandHint === "string")
701
+ out.commandHint = firstCall.commandHint;
702
+ return out;
703
+ }
704
+ /** Placeholder sources (A3 shared source): where each missing id comes from, tool-name only. */
705
+ export function placeholderSourceFor(key) {
706
+ const source = PLACEHOLDER_SOURCES[key];
707
+ if (source === undefined)
708
+ return undefined;
709
+ return source.replace(/^omc call /, "").replace(/(.*$/, "").replace(/^omc env.*$/, "omc env");
710
+ }
711
+ /** The authored read shape reference (A3 shared source): a pointer, not a copy. */
712
+ export function shapeRefFor(toolName) {
713
+ return readShapeFor(toolName) === undefined ? undefined : { shapeRef: toolName, jqRoot: "result" };
714
+ }
666
715
  /**
667
716
  * `--param` 的价码提示(r26b 实测):标量参数 150–900 B,**object 参数 ≈ 整份
668
717
  * `--full`**(`--param nodeGraph` = 8773 B,`--full` = 16950 B)。原来的提示只写
package/dist/endpoints.js CHANGED
@@ -174,6 +174,8 @@ export const ENDPOINTS = {
174
174
  runtimeFormLoad: "/api/api/runtime/form/load",
175
175
  runtimeFormReplayToken: "/api/api/runtime/form/getReplayToken",
176
176
  runtimeQueryList: "/api/api/runtime/query/list",
177
+ /** 平台服务端聚合(QueryRuntimeController.sum,POST /runtime/query/sum;数值/公式列,ALL_DATA)。 */
178
+ runtimeQuerySum: "/api/api/runtime/query/sum",
177
179
  runtimeFormDelete: "/api/api/runtime/form/delete",
178
180
  runtimeFormSubmit: "/api/api/runtime/form/submit",
179
181
  bizServiceCreate: "/api/api/bizservice/service/create",
@@ -198,6 +200,20 @@ export const ENDPOINTS = {
198
200
  bizServiceMethodDelete: "/api/api/bizservice/method/delete",
199
201
  bizServiceMethodTest: "/api/api/bizservice/method/service_test",
200
202
  bizServiceMethodList: "/api/api/bizservice/method/list_by_service_code",
203
+ /**
204
+ * 方法引用方清单(只读):`GET /bizservice/method/viewReference?serviceCode=&serviceMethodCode=`
205
+ * → `[{schemaCode, appCode, schemaName, appName}]`(BizServiceMethodController.java:452-487)。
206
+ * 给「删除被引用方法」的警告补可读归属;权威计数是 bizMethodCountMapping。
207
+ */
208
+ bizServiceMethodViewReference: "/api/api/bizservice/method/viewReference",
209
+ /**
210
+ * 业务方法映射引用计数(只读,F12):`GET /app/bizmethod/count_mapping?serviceCode=[&serviceMethodCode=]`
211
+ * → Integer。类级 `@RequestMapping("/app/bizmethod")` + `@GetMapping("/count_mapping")`
212
+ * (BizMethodController.java:52,287-307;AppManagementFacadeImpl.java:1238-1240),
213
+ * 本部署 engine 挂双前缀,故用 `/api/api/app/bizmethod/count_mapping`。
214
+ * 服务删除的写前硬门用它(平台自身删服务不做任何引用校验)。
215
+ */
216
+ bizMethodCountMapping: "/api/api/app/bizmethod/count_mapping",
201
217
  /**
202
218
  * 业务服务调用日志(表 h_log_biz_service)。
203
219
  * 8.6.26 源码:LogManagerController `@RequestMapping("/api/log")` +
package/dist/goal-plan.js CHANGED
@@ -4,6 +4,7 @@ import { goalRoute } from "./goal-routes.js";
4
4
  import { capabilityRouteIndex } from "./capability-overview.js";
5
5
  import { paramFillRuleFor } from "./search-index.js";
6
6
  import { scoreTools } from "./tool-search.js";
7
+ import { surfaceRefFor } from "./surface-ref.js";
7
8
  const AUTHORED_KEYS = new Set([
8
9
  "nodeGraph", "template", "source", "methodConfig", "serviceConfig",
9
10
  "methodInputParameters", "methodOutputParameters", "draftViewJson", "draftAttributesJson",
@@ -722,6 +723,17 @@ export function resolveModelCandidate(hint, models, goal = "") {
722
723
  * Build a plan. PURE except for the injected probe runner — no writes, ever.
723
724
  */
724
725
  export async function planGoal(registry, goal, options = {}) {
726
+ const plan = await planGoalInner(registry, goal, options);
727
+ // A3:steps[0] 的工具附 surfaceRef(与 next / commands --filter 同一组包点)。
728
+ // plan 自己的 steps[].args 已是本环境的解析结果;surfaceRef 补的是「下一步工具
729
+ // 的 firstCall 形状与缺参来源」——两个面各说一半,拼起来才是一步可跑的命令。
730
+ const firstTool = plan.steps[0]?.tool;
731
+ if (firstTool === undefined)
732
+ return plan;
733
+ const ref = surfaceRefFor(registry, firstTool, { via: "plan.steps[0]" });
734
+ return ref === undefined ? plan : { ...plan, surfaceRef: ref };
735
+ }
736
+ async function planGoalInner(registry, goal, options = {}) {
725
737
  const explicit = options.target;
726
738
  const route = explicit === undefined
727
739
  ? goalRoute(registry, goal)
@@ -1,5 +1,6 @@
1
1
  import { boundaryOf, capabilityRouteIndex, CAPABILITY_CUES, DISCOVERY_AUTHORITY } from "./capability-overview.js";
2
2
  import { listSkills, readSkillSection } from "./skills.js";
3
+ import { surfaceRefFor } from "./surface-ref.js";
3
4
  /**
4
5
  * Mode cues. `next` used to answer every goal with the BUILD ladder, so
5
6
  * "只读查看 X 的字段定义" was routed to field.create/form etc. (write:true) and
@@ -1484,6 +1485,24 @@ export function goalRoute(registry, goal) {
1484
1485
  const hint = graphHintFor(goal);
1485
1486
  const triage = triageHintFor(goal);
1486
1487
  const withGraph = hint === undefined ? base : { ...base, graphHint: hint };
1487
- return triage === undefined ? withGraph : { ...withGraph, triageHint: triage };
1488
+ const withTriage = triage === undefined ? withGraph : { ...withGraph, triageHint: triage };
1489
+ // A3:firstAnswer 的 action 指向 registry 工具(omc call <tool> / omc describe
1490
+ // <tool> --example)时附 surfaceRef——读 ladder 的起手工具、配方命中与
1491
+ // needs-input 的 resolver 都能一次拿到 firstCall/needs/returns/onRefusal。
1492
+ const action = withTriage.firstAnswer?.action;
1493
+ const surfaceRef = action === undefined
1494
+ ? undefined
1495
+ : surfaceRefFor(registry, toolOfAction(action), { via: "firstAnswer.action" });
1496
+ return surfaceRef === undefined ? withTriage : { ...withTriage, surfaceRef };
1497
+ }
1498
+ /** `omc call <tool> …` / `omc describe <tool> --example <id>` 里的工具名;其它形态返回空串(查不到即零字节)。 */
1499
+ function toolOfAction(action) {
1500
+ const call = /(?:^|\s)omc call ([a-zA-Z][\w.-]*)/.exec(action);
1501
+ if (call !== null)
1502
+ return call[1];
1503
+ const describe = /(?:^|\s)omc describe ([a-zA-Z][\w.-]*)/.exec(action);
1504
+ if (describe !== null)
1505
+ return describe[1];
1506
+ return "";
1488
1507
  }
1489
1508
  //# sourceMappingURL=goal-routes.js.map