@stalfh233/omc-cli 0.4.12 → 0.4.13

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.13`,尚未宣称 `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.13
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:Windows 上默认把非 ASCII 转义成 `\uXXXX`(纯 ASCII,在 GBK 控制台也不会乱码,等价于 Python `json.dumps(ensure_ascii=True)`),Linux/macOS 保持原始 UTF-8。UTF-8 终端想要可读中文时设 `OMC_ASCII_STDOUT=0`。`--out` 文件、artifact、stderr、CloudPivot 请求体始终是原始 UTF-8。
276
+
273
277
  ### 版本策略
274
278
 
275
279
  - `0.2.x`:继续演进 CLI/覆盖清单/配置契约,允许新增能力和必要的行为修复。
@@ -13,16 +13,34 @@ 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
+ * stdout is machine-parsed JSON, so it must decode identically for ANY consumer
17
+ * regardless of the ambient console code page. On zh-CN Windows the console is
18
+ * GBK (cp936), and a native process's bytes are decoded with that code page — by
19
+ * the terminal for direct output, and by PowerShell's `[Console]::OutputEncoding`
20
+ * for `$x = omc …` / `omc … > f` / `omc … | …`. Raw UTF-8 Chinese is mangled
21
+ * there (verified on Windows PowerShell 5.1 AND PowerShell 7.6). Escaping every
22
+ * non-ASCII code unit to `\uXXXX` makes stdout pure ASCII, so it survives any
23
+ * code page and still `JSON.parse`s back to the original string. This is the
24
+ * same conservative default as Python's `json.dumps(ensure_ascii=True)`.
25
+ *
26
+ * Escaping is ON by default only on win32; POSIX keeps its smaller raw UTF-8
27
+ * bytes. Override with `OMC_ASCII_STDOUT=1|0` (set `0` on a UTF-8 terminal to
28
+ * get readable Chinese). `--out` files, artifacts, stderr, and the CloudPivot
29
+ * wire stay raw UTF-8 — they are not a code-page-bound console stream. See
30
+ * `CONTEXT.md` → Agent-facing CLI.
23
31
  */
32
+ export function asciiStdout() {
33
+ const override = process.env.OMC_ASCII_STDOUT;
34
+ if (override === "1")
35
+ return true;
36
+ if (override === "0")
37
+ return false;
38
+ return process.platform === "win32";
39
+ }
24
40
  export function serializeEnvelope(value) {
25
- return JSON.stringify(value) + "\n";
41
+ const json = JSON.stringify(value);
42
+ const escaped = asciiStdout() ? json.replace(/[\u007f-\uffff]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`) : json;
43
+ return escaped + "\n";
26
44
  }
27
45
  export function requestId() {
28
46
  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.13",
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.13",
55
55
  "proper-lockfile": "4.1.2",
56
56
  "write-file-atomic": "6.0.0",
57
57
  "zod": "^3.23.8",