@stalfh233/omc-cli 0.4.12 → 0.4.14

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/README.md CHANGED
@@ -246,12 +246,12 @@ src/ args/support/plan/read/write/package/context(治理管道)
246
246
 
247
247
  ## npm 分发
248
248
 
249
- 本包(`@stalfh233/omc-cli`,可执行命令仍是 `omc`)通过公共 npm registry 分发。`omc-core` 是 `omc-cli` 的内部依赖,发布时先发 `omc-core`,再发 `omc-cli`;两者版本保持一致。当前版本为 `0.4.12`,尚未宣称 `1.0.0` 稳定契约。
249
+ 本包(`@stalfh233/omc-cli`,可执行命令仍是 `omc`)通过公共 npm registry 分发。`omc-core` 是 `omc-cli` 的内部依赖,发布时先发 `omc-core`,再发 `omc-cli`;两者版本保持一致。当前版本为 `0.4.14`,尚未宣称 `1.0.0` 稳定契约。
250
250
 
251
251
  ### 使用已发布包
252
252
 
253
253
  ```bash
254
- npm install -g @stalfh233/omc-cli@0.4.12
254
+ npm install -g @stalfh233/omc-cli@0.4.14
255
255
  omc setup
256
256
  omc doctor
257
257
  omc help omc-write-hazards
@@ -270,6 +270,10 @@ npm publish --workspace packages/omc-cli
270
270
 
271
271
  `omc-core` 与 `omc-cli` 版本保持一致;发布前先用 `git tag vX.Y.Z` 记录该版本。新包首次发布进入 npm staged-publishing 审核队列,需维护者在 npmjs.com 用交互式 2FA 批准后真实版本才可见。
272
272
 
273
+ ### 输出编码
274
+
275
+ stdout 是机器解析的 JSON,编码按消费方选择:**终端**(`isTTY`)写原始 UTF-8(Windows 上 Node 走 `WriteConsoleW`,中文正常显示);**管道/重定向/捕获**写 ASCII 安全 JSON(非 ASCII 转义成 `\uXXXX`,任何代码页都能正确解析,等价于 Python `json.dumps(ensure_ascii=True)`)。Linux/macOS 始终原始 UTF-8;`--out` 文件、artifact、stderr、CloudPivot 请求体始终原始 UTF-8。强制用 `OMC_ASCII_STDOUT=1|0`。
276
+
273
277
  ### 版本策略
274
278
 
275
279
  - `0.2.x`:继续演进 CLI/覆盖清单/配置契约,允许新增能力和必要的行为修复。
@@ -13,16 +13,39 @@ export function envelope(status, result, requestId, error = null) {
13
13
  /**
14
14
  * The single stdout serialization for every envelope.
15
15
  *
16
- * stdout is always UTF-8, on every platform. Escaping non-ASCII to `\uXXXX`
17
- * (an earlier win32 "ASCII-safe" mode) is deliberately gone: it made Windows
18
- * output diverge from POSIX byte-for-byte, broke plain string matching
19
- * (`findstr 采购`), and only worked around a legacy console code page that a
20
- * modern terminal (Windows Terminal, PowerShell 7, `chcp 65001`) fixes by
21
- * itself. JSON is UTF-8 by spec; downstream tools parse it losslessly. Callers
22
- * that truly need a file use `--out`, which was always raw UTF-8.
16
+ * Encoding is chosen by the CONSUMER, because "correct" differs by context:
17
+ *
18
+ * - A real terminal (stdout.isTTY) renders UTF-8 correctly on Windows: Node
19
+ * writes UTF-16 through the console API (WriteConsoleW), which bypasses the
20
+ * console code page entirely. So there we emit raw UTF-8 and a human sees
21
+ * readable Chinese.
22
+ * - A PIPE / redirect / capture (not a TTY) is decoded by the consumer with its
23
+ * own ambient code page. On zh-CN Windows that is GBK (cp936) and raw UTF-8 is
24
+ * mangled by the terminal AND by PowerShell's `[Console]::OutputEncoding`
25
+ * (verified on Windows PowerShell 5.1 and PowerShell 7.6) for `$x = omc …`,
26
+ * `omc … > f`, and the `.ps1` shim pipe. There we escape every non-ASCII code
27
+ * unit to `\uXXXX`: stdout stays pure ASCII, survives any code page, and
28
+ * still `JSON.parse`s back to the original string — the same conservative
29
+ * default as Python's `json.dumps(ensure_ascii=True)`.
30
+ *
31
+ * POSIX always keeps raw UTF-8. `OMC_ASCII_STDOUT=1|0` forces either mode. `--out`
32
+ * files, artifacts, stderr, and the CloudPivot wire stay raw UTF-8 — they are
33
+ * not a code-page-bound console stream. See `CONTEXT.md` → Agent-facing CLI.
23
34
  */
35
+ export function asciiStdout() {
36
+ const override = process.env.OMC_ASCII_STDOUT;
37
+ if (override === "1")
38
+ return true;
39
+ if (override === "0")
40
+ return false;
41
+ if (process.platform !== "win32")
42
+ return false;
43
+ return process.stdout.isTTY !== true;
44
+ }
24
45
  export function serializeEnvelope(value) {
25
- return JSON.stringify(value) + "\n";
46
+ const json = JSON.stringify(value);
47
+ const escaped = asciiStdout() ? json.replace(/[\u007f-\uffff]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`) : json;
48
+ return escaped + "\n";
26
49
  }
27
50
  export function requestId() {
28
51
  return randomUUID();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "commander": "14.0.3",
54
- "omc-core": "0.4.12",
54
+ "omc-core": "0.4.14",
55
55
  "proper-lockfile": "4.1.2",
56
56
  "write-file-atomic": "6.0.0",
57
57
  "zod": "^3.23.8",