@stalfh233/omc-cli 0.8.1 → 0.8.3

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.
@@ -100,7 +100,7 @@ export const CALL_FACE_TASKS = [
100
100
  await agent.write({ __tool: "field.create", schemaCode: "eval_m1", code: "f_amount", name: "金额", propertyType: "NUMERICAL", options: { scale: 3 } });
101
101
  await agent.write({ __tool: "field.create", schemaCode: "eval_m1", code: "f_when", name: "日期", propertyType: "DATE" });
102
102
  await agent.write({ __tool: "field.publish", schemaCode: "eval_m1" });
103
- await agent.write({ __tool: "form.draft", schemaCode: "eval_m1", sheetCode: "eval_m1" });
103
+ await agent.write({ __tool: "form.draft", schemaCode: "eval_m1", sheetCode: "eval_m1", rebuild: true });
104
104
  await agent.write({ __tool: "form.publish", schemaCode: "eval_m1", sheetCode: "eval_m1" });
105
105
  const fields = await agent.read("field.list", { schemaCode: "eval_m1", published: true });
106
106
  const codes = (fields.fields ?? []).map((field) => field.code);
@@ -122,11 +122,11 @@ export async function runScenario(harness) {
122
122
  await runner.step("field-publish-customer", "field.publish", { schemaCode: CUSTOMER });
123
123
  await runner.step("field-publish-project", "field.publish", { schemaCode: PROJECT });
124
124
  await runner.step("field-publish-declaration", "field.publish", { schemaCode: DECLARATION });
125
- await runner.step("form-draft-customer", "form.draft", { schemaCode: CUSTOMER, sheetCode: CUSTOMER });
125
+ await runner.step("form-draft-customer", "form.draft", { schemaCode: CUSTOMER, sheetCode: CUSTOMER, rebuild: true });
126
126
  await runner.step("form-publish-customer", "form.publish", { schemaCode: CUSTOMER, sheetCode: CUSTOMER });
127
- await runner.step("form-draft-project", "form.draft", { schemaCode: PROJECT, sheetCode: PROJECT });
127
+ await runner.step("form-draft-project", "form.draft", { schemaCode: PROJECT, sheetCode: PROJECT, rebuild: true });
128
128
  await runner.step("form-publish-project", "form.publish", { schemaCode: PROJECT, sheetCode: PROJECT });
129
- await runner.step("form-draft-declaration", "form.draft", { schemaCode: DECLARATION, sheetCode: DECLARATION });
129
+ await runner.step("form-draft-declaration", "form.draft", { schemaCode: DECLARATION, sheetCode: DECLARATION, rebuild: true });
130
130
  await runner.step("form-publish-declaration", "form.publish", { schemaCode: DECLARATION, sheetCode: DECLARATION });
131
131
  // Ticket 07 live knowledge: a fresh model's default list view has no
132
132
  // business columns — configure them or the list projection reads back null.
@@ -293,6 +293,27 @@ export const RESULT_STATUS_ROUTES = Object.freeze({
293
293
  // ordinary-path mapping of its own.
294
294
  error: { kind: "passthrough" },
295
295
  });
296
+ /**
297
+ * B1(2026-11-25,P0):把「网关 HTML 404」从「环境能力缺失 / 勿重试」里拆出来。
298
+ *
299
+ * 两类输入都要认:
300
+ * 1. `wire.ts` 改写后的稳定文案(同一前缀);
301
+ * 2. `omc-core` 原样的非 JSON HTTP 失败文案(若某个通道绕过 wireCall 直接
302
+ * 透出)——只认 404 + 非 JSON,其它状态码一概不动。
303
+ * 返回可执行的替换文案;不是网关 HTML 404 时返回 undefined。
304
+ */
305
+ const GATEWAY_HTML_404_TEXT = /^网关返回了 HTML 404(不是平台 JSON 信封)/u;
306
+ const CORE_NON_JSON_404_TEXT = /^CloudPivot (.+?) → HTTP 404(([^)]*))/u;
307
+ function gatewayHtml404Text(message) {
308
+ if (GATEWAY_HTML_404_TEXT.test(message))
309
+ return message;
310
+ const core = CORE_NON_JSON_404_TEXT.exec(message);
311
+ if (core === null || /json/i.test(core[2] ?? ""))
312
+ return undefined;
313
+ const path = core[1];
314
+ const contentType = (core[2] ?? "") === "unknown" || (core[2] ?? "") === "" ? "HTML" : core[2];
315
+ return `网关返回了 HTML 404(不是平台 JSON 信封):${path}(响应体 ${contentType})——通常是路由/网关瞬时抖动,可重试 1–2 次(同一载荷);连续复现(同一端点 ≥2 次)再查 readiness/部署(omc doctor)。`;
316
+ }
296
317
  export function classifyResult(result) {
297
318
  const status = String(result.status ?? "ok");
298
319
  const withNext = (error) => {
@@ -304,6 +325,35 @@ export function classifyResult(result) {
304
325
  : undefined;
305
326
  if (route?.kind === "success")
306
327
  return { status: route.envelopeStatus, error: null, exitCode: route.exitCode };
328
+ // B1(2026-11-25 真机 P0):网关/边缘的 HTML 404 曾被当成「该端点在此环境不可达,
329
+ // 属环境能力缺失,勿重试同一载荷」——真机同一载荷下一次即 200(随后 10+ 次全成功),
330
+ // 是路由抖动不是能力缺失。传输层(wire.ts)已把它改写成 `transport`(版本族
331
+ // 404 下探只认 Spring 的 JSON 404,所以这里不会被当成「端点缺席」),读/写通道
332
+ // 回 uncertain + detail;这里兜住任何绕过 wireCall 的原样透出,并保证信封的
333
+ // error.message 是可执行的「可重试 1–2 次」,不再出现「勿重试」。
334
+ // 平台自己的 JSON 404(有 errcode 信封)不在此列:它继续走 http-status/业务语义。
335
+ if (status === "error" || status === "uncertain") {
336
+ // `detail` first: the read/write lanes put the transport text there, while
337
+ // an `uncertain` write also carries its own generic caution in `message`.
338
+ const candidates = [result.detail, result.message]
339
+ .filter((value) => typeof value === "string" && value.length > 0);
340
+ const gateway = candidates.map((value) => gatewayHtml404Text(value)).find((value) => value !== undefined);
341
+ if (gateway !== undefined) {
342
+ // 写通道的 uncertain 自己带 caution(「outcome cannot be established」)——
343
+ // 保留它,别让「可重试」抹掉「写结果未知先别假设成功」。
344
+ const writeCaution = status === "uncertain"
345
+ && typeof result.message === "string"
346
+ && result.message.length > 0
347
+ && result.message !== gateway
348
+ ? `;${result.message}`
349
+ : "";
350
+ return {
351
+ status: "uncertain",
352
+ error: withNext({ code: "uncertain", message: `${gateway}${writeCaution}`, retryable: true }),
353
+ exitCode: CLI_EXIT_CODES.uncertain,
354
+ };
355
+ }
356
+ }
307
357
  // `--args-list` partial success (some entries landed, some refused). Without
308
358
  // this branch it fell through to "internal error", which reads as a CLI bug
309
359
  // rather than "2 of 3 fields were created — retry index 2".
@@ -316,11 +366,14 @@ export function classifyResult(result) {
316
366
  // A step-chain command (model-purge) also answers `partial`, and the batch
317
367
  // wording read "6/7 成功,0 失败" — meaningless for steps (r15).
318
368
  const isBatch = typeof result.tool === "string";
319
- const message = result.mode === "preflight"
369
+ // B4(0.8.4):`graph pull` 的 partial 自带结论(哪几个应用失败、索引仍可用);
370
+ // 有生产者 message 时优先用它,不再套用「逐条见 steps[]」的通用文案。
371
+ const producerMessage = typeof result.message === "string" && result.message.trim().length > 0 ? result.message : undefined;
372
+ const message = producerMessage ?? (result.mode === "preflight"
320
373
  ? `${failed}/${requested} 条未过写前校验(preflight:零 wire、零写入);逐条原因见 failures[]`
321
374
  : isBatch
322
375
  ? `${succeeded}/${requested} 成功,${failed} 失败;逐条原因见 failures[] / failedSteps[](--args-list 的 index 指向第几条)`
323
- : `部分步骤失败:逐条原因见 steps[] 的 status/detail(已在失败处停下;幂等,修好后重跑同一条命令)`;
376
+ : `部分步骤失败:逐条原因见 steps[] 的 status/detail(已在失败处停下;幂等,修好后重跑同一条命令)`);
324
377
  return {
325
378
  status: route.envelopeStatus,
326
379
  error: withNext({ code: route.code, message, retryable: false }),
@@ -6,6 +6,16 @@ import { isWithinRoot } from "./artifacts.js";
6
6
  import { asciiStdout, serializeEnvelope } from "./cli-contract.js";
7
7
  import { currentUsageCommand, priorRepeatedFailures, recordUsageOutput } from "./usage-log.js";
8
8
  let options = { quiet: false, verbose: false };
9
+ let outProjectionNote;
10
+ /** 记录一次「`--out` + 投影」的组合;下一个 writeEnvelope 消费它。 */
11
+ export function noteOutProjection(note) {
12
+ outProjectionNote = note;
13
+ }
14
+ function takeOutProjection() {
15
+ const note = outProjectionNote;
16
+ outProjectionNote = undefined;
17
+ return note;
18
+ }
9
19
  /**
10
20
  * F2'(r27):写面 + 非 TTY 时,stderr 人话末尾补一行「勿 2>&1 合流」提示。
11
21
  * 读面保持安静;stdout 字节不变。状态由 beginWriteFace / noteHumanStderr /
@@ -176,6 +186,19 @@ function compactForOutput(value) {
176
186
  * stdout and the file can never diverge (both follow the same verbose rule).
177
187
  */
178
188
  let asciiBannerEmitted = false;
189
+ /**
190
+ * C5(0.8.4):管道 + 非 UTF-8 代码页时的 stderr 提示。纯 ASCII——ascii 模式下
191
+ * stderr 自己也会被转义,混中文必乱码。措辞与 `omc help` 的编码行一致:
192
+ * `--utf8` 只动人类诊断、信封保持 \uXXXX、`--out` 落盘始终 UTF-8。
193
+ */
194
+ export function asciiEncodingBannerText() {
195
+ // [needs Windows live verification] 本机无 Windows,auto-ascii 路径未在真机复核。
196
+ return "[omc] legacy console code page detected: the JSON envelope is \\u-escaped (e.g. \\u6295\\u5f71) so it stays parseable in any code page.\n"
197
+ + " --utf8 de-escapes HUMAN diagnostics only (stderr/prose); it never changes the JSON envelope.\n"
198
+ + " --out <path> always writes raw UTF-8 -- read that file when you need readable Chinese.\n"
199
+ + " To read Chinese in this console: chcp 65001; if your consumer already decodes UTF-8 (agent harness / VS Code / Windows Terminal): set OMC_ASCII_STDOUT=0\n"
200
+ + " [needs Windows live verification]\n";
201
+ }
179
202
  function emitAsciiBannerOnce() {
180
203
  if (asciiBannerEmitted)
181
204
  return;
@@ -187,12 +210,7 @@ function emitAsciiBannerOnce() {
187
210
  // 注意:ascii 模式下 stderr 本身也会被转义,所以横幅必须是纯 ASCII。
188
211
  if (process.env.OMC_ASCII_STDOUT !== undefined || process.env.OMC_HUMAN_UTF8 !== undefined)
189
212
  return;
190
- // 2026-11-05:旧横幅只给了 `--utf8`,而它**只管 stderr**——用户要的正是不想再
191
- // 看 `\uXXXX`,照它做没有效果。给出真正能关掉转义的两个办法。
192
- process.stderr.write("[omc] legacy console code page detected: the JSON envelope is \\u-escaped (e.g. \\u6295\\u5f71) so it stays parseable.\n"
193
- + " If your consumer decodes UTF-8 (agent harness / VS Code / Windows Terminal), turn it off:\n"
194
- + " set OMC_ASCII_STDOUT=0 (Windows cmd / PowerShell: $env:OMC_ASCII_STDOUT=0)\n"
195
- + " or switch the console itself: chcp 65001\n");
213
+ process.stderr.write(asciiEncodingBannerText());
196
214
  }
197
215
  /**
198
216
  * Attach a repeat warning to a refusal that repeats the previous one. Refusal
@@ -241,6 +259,9 @@ function withRepeatWarning(value) {
241
259
  return { ...envelope, repeatWarning };
242
260
  }
243
261
  export function writeEnvelope(value) {
262
+ // 一次性消费:投影说明只属于**本次**调用,任何后续 writeEnvelope(批量/复合
263
+ // 命令同进程多次写回)都必须回到既有的 `--out` 语义。
264
+ const projection = takeOutProjection();
244
265
  // `--out-file`(issue 2026-11-18 §08.2):完整信封以 raw UTF-8 原子落盘,
245
266
  // stdout 只回小回执。它在 compactForOutput 之前分叉——文件里必须是**完整**
246
267
  // 信封(status/requestId/error 都在),stdout 的小回执固定保留 status。
@@ -278,15 +299,45 @@ export function writeEnvelope(value) {
278
299
  const text = serializeEnvelope(outputValue);
279
300
  if (asciiStdout())
280
301
  emitAsciiBannerOnce();
302
+ const envelopeValue = outputValue && typeof outputValue === "object" ? outputValue : {};
303
+ const failure = envelopeValue.error !== null && envelopeValue.error !== undefined;
281
304
  if (!options.outFile) {
282
305
  recordUsageOutput(value, Buffer.byteLength(text, "utf8"));
283
306
  process.stdout.write(text);
284
307
  return;
285
308
  }
309
+ // C4:`--out` + `--jq` 同用 —— 文件写**投影后的 JSON**,stdout 回执带 `jq`。
310
+ // 失败信封不在此列(投影没意义,且既有失败面要完整留档)。
311
+ if (projection !== undefined && !failure) {
312
+ const projectedValue = projection.value === undefined ? null : projection.value;
313
+ const projectedText = `${JSON.stringify(projectedValue, null, 2)}\n`;
314
+ writeFileSync(options.outFile, projectedText, "utf8");
315
+ const projectedBytes = Buffer.byteLength(projectedText, "utf8");
316
+ const inlineBytes = Buffer.byteLength(JSON.stringify(projectedValue), "utf8");
317
+ const fits = inlineBytes <= projection.budget;
318
+ const receipt = {
319
+ ok: envelopeValue.ok ?? true,
320
+ ...(options.verbose
321
+ ? { status: envelopeValue.status ?? "ok", requestId: envelopeValue.requestId ?? null, error: envelopeValue.error ?? null }
322
+ : {}),
323
+ result: {
324
+ out: options.outFile,
325
+ bytes: projectedBytes,
326
+ jq: fits ? projectedValue : { omitted: true, bytes: inlineBytes },
327
+ jqPaths: [...projection.paths],
328
+ jqHit: projection.hit,
329
+ ...(fits
330
+ ? {}
331
+ : { jqNote: `投影值 ${inlineBytes}B 超过 stdout 预算 ${projection.budget}B:完整投影已写入 --out 文件(stdout 只回指针),要看值请读该文件或缩小 --jq 路径;要放大回执用 --max-output-bytes` }),
332
+ },
333
+ };
334
+ const receiptText = serializeEnvelope(receipt);
335
+ recordUsageOutput(value, Buffer.byteLength(receiptText, "utf8"), projectedBytes);
336
+ process.stdout.write(receiptText);
337
+ return;
338
+ }
286
339
  const pretty = `${JSON.stringify(outputValue, null, 2)}\n`;
287
340
  writeFileSync(options.outFile, pretty, "utf8");
288
- const envelopeValue = outputValue && typeof outputValue === "object" ? outputValue : {};
289
- const failure = envelopeValue.error !== null && envelopeValue.error !== undefined;
290
341
  const confirmation = failure || options.verbose
291
342
  ? {
292
343
  ok: envelopeValue.ok ?? failure ? false : true,