@stalfh233/omc-cli 0.6.81 → 0.6.83
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/coverage/m1-coverage-manifest-v1.json +5 -2
- package/dist/artifacts.js +28 -5
- package/dist/capability-overview.js +4 -4
- package/dist/cli.js +168 -41
- package/dist/config-store.js +35 -0
- package/dist/endpoints.js +22 -0
- package/dist/env-export.js +4 -0
- package/dist/human-summary.js +8 -0
- package/dist/lanes/b2-registration-contract.js +11 -0
- package/dist/lanes/b2-registration-coverage.js +1 -0
- package/dist/lanes/businessrule-contract.js +5 -3
- package/dist/lanes/businessrule.js +160 -2
- package/dist/lanes/environment-contract.js +8 -0
- package/dist/lanes/environment.js +73 -0
- package/dist/lanes/rule-graph.js +21 -5
- package/dist/lanes/runtime-data-contract.js +8 -0
- package/dist/lanes/runtime-data.js +99 -12
- package/dist/lanes/servicelog.js +376 -0
- package/dist/lanes/workflow-contract.js +12 -2
- package/dist/lanes/workflow-coverage.js +1 -0
- package/dist/lanes/workflow.js +357 -27
- package/dist/model-purge.js +12 -3
- package/dist/path-projection.js +133 -21
- package/dist/read-shapes.js +14 -9
- package/dist/recipes/businessrule.js +1 -1
- package/dist/refusal-guidance.js +5 -4
- package/dist/rule-support.js +414 -43
- package/dist/session-account.js +66 -0
- package/dist/session.js +27 -0
- package/dist/token-cache.js +3 -0
- package/dist/tool-search.js +5 -1
- package/dist/tool-types.js +3 -1
- package/dist/tools.js +2 -0
- package/dist/writable-window.js +209 -0
- package/package.json +3 -3
- package/skills/omc-capabilities.md +5 -5
|
@@ -340,6 +340,7 @@
|
|
|
340
340
|
"workflow.update",
|
|
341
341
|
"workflow.publish",
|
|
342
342
|
"workflow.bindRule",
|
|
343
|
+
"workflow.unbindRule",
|
|
343
344
|
"workflow.setButtons",
|
|
344
345
|
"workflow.delete",
|
|
345
346
|
"workflow.permissions",
|
|
@@ -1130,7 +1131,8 @@
|
|
|
1130
1131
|
"service.dbconnpool.delete",
|
|
1131
1132
|
"service.adapter_config",
|
|
1132
1133
|
"service.table_list",
|
|
1133
|
-
"service.table_sql"
|
|
1134
|
+
"service.table_sql",
|
|
1135
|
+
"servicelog.search"
|
|
1134
1136
|
],
|
|
1135
1137
|
"scopes": [
|
|
1136
1138
|
"readback",
|
|
@@ -1142,7 +1144,8 @@
|
|
|
1142
1144
|
"method update readback",
|
|
1143
1145
|
"method delete readback",
|
|
1144
1146
|
"create readback",
|
|
1145
|
-
"delete readback"
|
|
1147
|
+
"delete readback",
|
|
1148
|
+
"log readback"
|
|
1146
1149
|
]
|
|
1147
1150
|
},
|
|
1148
1151
|
{
|
package/dist/artifacts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { basename, isAbsolute, join, relative, resolve } from "node:path";
|
|
4
4
|
export const CLI_DEFAULT_OUTPUT_BYTES = 64 * 1024;
|
|
5
5
|
export const CLI_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
6
6
|
function artifactPath(root, artifactId) {
|
|
@@ -79,16 +79,39 @@ export function isWithinRoot(root, candidate) {
|
|
|
79
79
|
* assertSafeInputPath's containment rule, but the file need not exist yet).
|
|
80
80
|
* `omc intent plan --plan-out` uses it so the written plan is readable by
|
|
81
81
|
* `omc intent apply`, which enforces the same root.
|
|
82
|
+
*
|
|
83
|
+
* Issue 06(retro 2026-11-19):Windows 用户拿系统 temp 被拒后不知道往哪写——
|
|
84
|
+
* ① 越界拒绝时错误直接给出根内**可用的绝对示例路径**(`<root>/artifacts-out/<原名>`),
|
|
85
|
+
* 看一眼错误就知道下一步敲什么;② 根内目标的父目录自动创建(mkdir -p 语义,
|
|
86
|
+
* 仅限根内——越界路径仍然先拒,不建任何根外目录)。
|
|
82
87
|
*/
|
|
83
88
|
export function assertSafeOutputPath(root, candidate, label) {
|
|
89
|
+
const resolvedRoot = resolve(root);
|
|
84
90
|
const normalized = resolve(root, candidate);
|
|
85
91
|
if (!isWithinRoot(root, normalized))
|
|
86
|
-
throw new Error(`${label} must be inside the configuration root(配置根 ${
|
|
92
|
+
throw new Error(`${label} must be inside the configuration root(配置根 ${resolvedRoot};本次解析为 ${normalized})。` +
|
|
93
|
+
`可改用根内绝对路径,如 ${join(resolvedRoot, "artifacts-out", basename(normalized))}(父目录会自动创建)`);
|
|
87
94
|
const parent = resolve(normalized, "..");
|
|
88
95
|
if (!existsSync(parent))
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
97
|
+
// 根内逐段查符号链接(与 assertSafeInputPath 同规则):mkdir -p 会穿过指向根外
|
|
98
|
+
// 的符号链接目录,词法包含检查看不见——每段 lstat 才能守住「只在根内写」。
|
|
99
|
+
let current = parent;
|
|
100
|
+
while (current !== resolvedRoot) {
|
|
101
|
+
try {
|
|
102
|
+
if (lstatSync(current).isSymbolicLink())
|
|
103
|
+
throw new Error(`${label} cannot be inside a symbolic link`);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof Error && error.message === `${label} cannot be inside a symbolic link`)
|
|
107
|
+
throw error;
|
|
108
|
+
throw new Error(`${label} does not exist`);
|
|
109
|
+
}
|
|
110
|
+
const up = resolve(current, "..");
|
|
111
|
+
if (up === current)
|
|
112
|
+
throw new Error(`${label} must be inside the configuration root`);
|
|
113
|
+
current = up;
|
|
114
|
+
}
|
|
92
115
|
if (existsSync(normalized)) {
|
|
93
116
|
if (lstatSync(normalized).isSymbolicLink())
|
|
94
117
|
throw new Error(`${label} cannot be a symbolic link`);
|
|
@@ -141,8 +141,8 @@ const SURFACES = [
|
|
|
141
141
|
id: "workflow",
|
|
142
142
|
title: "流程模板 + 组织与权限",
|
|
143
143
|
lane: LANES.workflow,
|
|
144
|
-
description: "流程模板生命周期:workflow.list(应用内流程清单)、get_draft/get_published、create、update、publish、bindRule
|
|
145
|
-
operations: ["list", "create", "update", "publish", "bindRule", "delete"],
|
|
144
|
+
description: "流程模板生命周期:workflow.list(应用内流程清单)、get_draft/get_published、create、update、publish、bindRule/unbindRule(绑定与解绑)、delete、workitem.list。**含组织/部门/角色/权限范围(org.* 工具)**:部门树、角色组/角色、用户搜索、成员与管理范围(userScope)——流程参与人/可见性的候选来源。",
|
|
145
|
+
operations: ["list", "create", "update", "publish", "bindRule", "unbindRule", "delete"],
|
|
146
146
|
requires: ["model"],
|
|
147
147
|
intent: { level: "partial", note: "声明式支持 workflow.create/update/publish 与 bindRules(事件处理器规则绑定,merge/ensure-present);runtime workitem(提交/审批)仍走 escape hatch。" },
|
|
148
148
|
notes: "greenfield 首版;publish/bindRule 不得在 ValidateMessage[] 拒绝时报告成功。组织读写(org.*)挂在本能力下,别名 org/organization/organisation。r64 起含**流程运维三件套**(workflow.transfer 换审批人 / workflow.activate 跳转节点 / workflow.finish 手动结束·end 规则照常触发)——测试提速定位:运维过的实例权限语义已变,不能用于真实流程/权限验证。",
|
|
@@ -171,8 +171,8 @@ const SURFACES = [
|
|
|
171
171
|
id: "bizservice",
|
|
172
172
|
title: "业务集成",
|
|
173
173
|
lane: LANES.b2,
|
|
174
|
-
description: "业务服务与方法注册(RESTFUL/DATA_SQL/DATA_TABLE/SAP/KAFKA/SOAP
|
|
175
|
-
operations: ["list", "register", "update", "delete", "export", "import", "check", "test"],
|
|
174
|
+
description: "业务服务与方法注册(RESTFUL/DATA_SQL/DATA_TABLE/SAP/KAFKA/SOAP)、服务清单(按分类/关键词,凭据不回显)、导入导出、设计器测试、调用日志(h_log_biz_service 读面:params/result/状态/耗时)。",
|
|
175
|
+
operations: ["list", "register", "update", "delete", "export", "import", "check", "test", "log"],
|
|
176
176
|
requires: [],
|
|
177
177
|
intent: { level: "partial", note: "声明式支持新建 service.register(可带一个 method)与既有 service/method 的 update(结构化 config、AES 加密、patch 语义);删除、给既有服务加方法、分类/连接池/IE 仍走 escape hatch。" },
|
|
178
178
|
notes: "方法 configJson 走 AES-128-ECB;RESTFUL/DATA_SQL 绑定前须带适配器必需配置(否则是注册壳)。",
|
package/dist/cli.js
CHANGED
|
@@ -24,7 +24,9 @@ import { beginWriteFace, configureOutput, endWriteFace, humanSummary, maybeWarnM
|
|
|
24
24
|
import { beginUsage, completeUsage, currentUsageArgsDigest, ensureProjectIgnore, priorIdenticalSuccess, recordUsageOutput, usageReport } from "./usage-log.js";
|
|
25
25
|
import { artifactFetchHint, artifactRoot, boundResult, emitInvalid, emitResult, emitThrown, emitTransportResult, outputBudget, readArtifact, withTransport, } from "./command-transport.js";
|
|
26
26
|
import { CLI_DEFAULT_OUTPUT_BYTES, assertSafeOutputPath, pruneArtifacts } from "./artifacts.js";
|
|
27
|
-
import {
|
|
27
|
+
import { sessionAccountForEnvironment } from "./session-account.js";
|
|
28
|
+
import { closeWritableWindow, openWritableWindow, parseWritableTtl, sweepWritableWindowsAtStartup, validateWritableReason, writableWindowStatus, WRITABLE_WINDOW_DEFAULT_TTL_MINUTES, WRITABLE_WINDOW_LOG, WRITABLE_WINDOW_MAX_TTL_MINUTES, WritableWindowInputError } from "./writable-window.js";
|
|
29
|
+
import { artifactPathMissHint, nullProjectionHint, partialPathMissHint, pathMissCopyableHint, pathMissDidYouMean, projectJsonPath, projectJsonPathFanout, projectResultExtract, shapeOf, SHAPE_MAX_DEPTH, unwrapSinglePathProjection } from "./path-projection.js";
|
|
28
30
|
import { basename, join, resolve } from "node:path";
|
|
29
31
|
import { existsSync, readFileSync, writeFileSync, chmodSync } from "node:fs";
|
|
30
32
|
import { buildToolRegistry } from "./tools.js";
|
|
@@ -392,39 +394,41 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
392
394
|
*/
|
|
393
395
|
async function cmdBatchCall(store, toolName, rawList, options) {
|
|
394
396
|
const request = options.requestValue ?? requestId();
|
|
397
|
+
// issue 07:批量面同款——汇总信封(含 preflight)都带 resultMeta.sessionAccount。
|
|
398
|
+
const accountMeta = () => ({ sessionAccount: sessionAccountForEnvironment(store, options.environment) });
|
|
395
399
|
let parsed;
|
|
396
400
|
try {
|
|
397
401
|
parsed = JSON.parse(rawList);
|
|
398
402
|
}
|
|
399
403
|
catch (error) {
|
|
400
404
|
const message = `--args-list 必须是 JSON 数组:${error instanceof Error ? error.message : String(error)}`;
|
|
401
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message, retryable: false }));
|
|
405
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
402
406
|
return CLI_EXIT_CODES.invalidInput;
|
|
403
407
|
}
|
|
404
408
|
if (!Array.isArray(parsed)) {
|
|
405
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: "--args-list 必须是 JSON 数组(每条是一个 args 对象)", retryable: false }));
|
|
409
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 必须是 JSON 数组(每条是一个 args 对象)", retryable: false }), resultMeta: accountMeta() });
|
|
406
410
|
return CLI_EXIT_CODES.invalidInput;
|
|
407
411
|
}
|
|
408
412
|
const entries = parsed;
|
|
409
413
|
const badIndex = entries.findIndex((entry) => entry === null || typeof entry !== "object" || Array.isArray(entry));
|
|
410
414
|
if (badIndex >= 0) {
|
|
411
|
-
writeEnvelope(envelope("error", {}, request, {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
415
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
416
|
+
code: "invalid-input",
|
|
417
|
+
message: `--args-list 第 ${badIndex} 条不是对象(每条必须是 {"字段":值} 形状)`,
|
|
418
|
+
retryable: false,
|
|
419
|
+
}), resultMeta: accountMeta() });
|
|
416
420
|
return CLI_EXIT_CODES.invalidInput;
|
|
417
421
|
}
|
|
418
422
|
if (entries.length === 0) {
|
|
419
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: "--args-list 至少一条", retryable: false }));
|
|
423
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: "--args-list 至少一条", retryable: false }), resultMeta: accountMeta() });
|
|
420
424
|
return CLI_EXIT_CODES.invalidInput;
|
|
421
425
|
}
|
|
422
426
|
if (entries.length > BATCH_MAX_ENTRIES) {
|
|
423
|
-
writeEnvelope(envelope("error", {}, request, {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
427
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
428
|
+
code: "invalid-input",
|
|
429
|
+
message: `--args-list 最多 ${BATCH_MAX_ENTRIES} 条(本次 ${entries.length});分批执行或用 omc script 读文件`,
|
|
430
|
+
retryable: false,
|
|
431
|
+
}), resultMeta: accountMeta() });
|
|
428
432
|
return CLI_EXIT_CODES.invalidInput;
|
|
429
433
|
}
|
|
430
434
|
try {
|
|
@@ -432,11 +436,11 @@ async function cmdBatchCall(store, toolName, rawList, options) {
|
|
|
432
436
|
validateAgentPaths(entry);
|
|
433
437
|
}
|
|
434
438
|
catch (error) {
|
|
435
|
-
writeEnvelope(envelope("error", {}, request, {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
439
|
+
writeEnvelope({ ...envelope("error", {}, request, {
|
|
440
|
+
code: "invalid-input",
|
|
441
|
+
message: `--args-list 含越界路径:${error instanceof Error ? error.message : String(error)}`,
|
|
442
|
+
retryable: false,
|
|
443
|
+
}), resultMeta: accountMeta() });
|
|
440
444
|
return CLI_EXIT_CODES.invalidInput;
|
|
441
445
|
}
|
|
442
446
|
// Whole-batch shape precheck (issue 2026-10-25 §6): `--args-list --dry-run`
|
|
@@ -449,7 +453,7 @@ async function cmdBatchCall(store, toolName, rawList, options) {
|
|
|
449
453
|
const registry = buildToolRegistry();
|
|
450
454
|
const tool = registry.find((definition) => definition.name === toolName);
|
|
451
455
|
if (!tool) {
|
|
452
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: `unknown tool ${toolName};用 omc next 或 omc commands --json --compact --lane <lane> 定位`, retryable: false }));
|
|
456
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: `unknown tool ${toolName};用 omc next 或 omc commands --json --compact --lane <lane> 定位`, retryable: false }), resultMeta: accountMeta() });
|
|
453
457
|
return CLI_EXIT_CODES.invalidInput;
|
|
454
458
|
}
|
|
455
459
|
const failures = [];
|
|
@@ -496,7 +500,10 @@ async function cmdBatchCall(store, toolName, rawList, options) {
|
|
|
496
500
|
? unwrapSinglePathProjection(result)
|
|
497
501
|
: undefined;
|
|
498
502
|
const envelopeValue = envelope(classified.status, unwrapped !== undefined ? unwrapped.result : result, request, classified.error);
|
|
499
|
-
writeEnvelope(
|
|
503
|
+
writeEnvelope({
|
|
504
|
+
...envelopeValue,
|
|
505
|
+
resultMeta: { sessionAccount: accountMeta().sessionAccount, ...(unwrapped?.resultMeta ?? {}) },
|
|
506
|
+
});
|
|
500
507
|
return failures.length > 0 ? 1 : 0;
|
|
501
508
|
}
|
|
502
509
|
const batched = await runBatchCall({
|
|
@@ -507,18 +514,23 @@ async function cmdBatchCall(store, toolName, rawList, options) {
|
|
|
507
514
|
requestId: request,
|
|
508
515
|
});
|
|
509
516
|
const classified = classifyResult(batched.result);
|
|
510
|
-
writeEnvelope(envelope(classified.status, batched.result, request, classified.error));
|
|
517
|
+
writeEnvelope({ ...envelope(classified.status, batched.result, request, classified.error), resultMeta: accountMeta() });
|
|
511
518
|
return batched.exitCode;
|
|
512
519
|
}
|
|
513
520
|
async function cmdCall(store, args) {
|
|
514
521
|
const request = flag0(args, "--request-id") ?? requestId();
|
|
522
|
+
// issue 07(retro 2026-11-19):每次 omc call 的回执(成功与错误信封)都带
|
|
523
|
+
// resultMeta.sessionAccount——token 解码(0 wire),解不出就回 unavailableReason,
|
|
524
|
+
// 不谎报。环境旗标解析出来之前 callEnvironment 是 undefined,按默认环境解析。
|
|
525
|
+
let callEnvironment;
|
|
526
|
+
const accountMeta = () => ({ sessionAccount: sessionAccountForEnvironment(store, callEnvironment) });
|
|
515
527
|
let maxOutputBytes;
|
|
516
528
|
try {
|
|
517
529
|
maxOutputBytes = outputBudget(args);
|
|
518
530
|
}
|
|
519
531
|
catch (error) {
|
|
520
532
|
const message = error instanceof Error ? error.message : String(error);
|
|
521
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message, retryable: false }));
|
|
533
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
522
534
|
return CLI_EXIT_CODES.invalidInput;
|
|
523
535
|
}
|
|
524
536
|
const emit = (status, result, exitCode, extra) => {
|
|
@@ -528,7 +540,11 @@ async function cmdCall(store, args) {
|
|
|
528
540
|
const envelopeValue = envelope(status, boundResult(result, maxOutputBytes), request, classified.error);
|
|
529
541
|
// issue 2026-11-18 §05:单路径 --jq 解包后,`result` 是目标节点本体(可能是
|
|
530
542
|
// 数组/标量,装不进结果对象),路径来源等元信息放信封旁的 `resultMeta`。
|
|
531
|
-
|
|
543
|
+
// issue 07:sessionAccount 恒在 resultMeta(瘦身影封保留 resultMeta)。
|
|
544
|
+
writeEnvelope({
|
|
545
|
+
...envelopeValue,
|
|
546
|
+
...(extra !== undefined ? { ...extra, resultMeta: { sessionAccount: accountMeta().sessionAccount, ...(extra.resultMeta ?? {}) } } : { resultMeta: accountMeta() }),
|
|
547
|
+
});
|
|
532
548
|
maybeWarnMergedStreams();
|
|
533
549
|
return exitCode;
|
|
534
550
|
};
|
|
@@ -551,9 +567,10 @@ async function cmdCall(store, args) {
|
|
|
551
567
|
console.error("用法:omc call <tool> [--env <环境>] [--args '<json>' | --args - (stdin) | --args-file <配置根内路径(必须位于配置根内;数组批量请改用 --args-list;跨目录临时文件用 --args -(stdin))>] [--extract <path>]... [--jq [path]] [--extract-keys] [--args-list <json数组>(最多 200 条;超出请分批或用 omc script 读文件) [--preflight]]");
|
|
552
568
|
console.error("输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192");
|
|
553
569
|
console.error("写入:由环境 writable 决定(只读环境拒写);生产环境的写必须在 args 里带 confirmProduction:true。");
|
|
570
|
+
console.error("会话账号:每次回执 resultMeta.sessionAccount(token 解码:id=user_id、username=user_name、name=登录显示名;解不出回 unavailableReason)。报错里的 currentUser 是平台按 username 反查的 id,同名多账号时与 id 不同——排查 not-mine 先看这两个是否同一个人。");
|
|
554
571
|
return emit(toolName && toolName !== "help" ? "error" : "ok", {}, toolName && toolName !== "help" ? CLI_EXIT_CODES.invalidInput : 0);
|
|
555
572
|
}
|
|
556
|
-
const environment = flag("--env") ?? flag("--environment");
|
|
573
|
+
const environment = (callEnvironment = flag("--env") ?? flag("--environment"));
|
|
557
574
|
const requestValue = flag("--request-id");
|
|
558
575
|
// Batch mode: the SAME tool N times, one process (r12: 36 field.create calls).
|
|
559
576
|
const argsList = flag("--args-list");
|
|
@@ -561,7 +578,7 @@ async function cmdCall(store, args) {
|
|
|
561
578
|
return cmdBatchCall(store, toolName, argsList, { environment, requestValue, args, preflight: args.includes("--preflight") });
|
|
562
579
|
if (args.includes("--preflight")) {
|
|
563
580
|
const message = "--preflight 仅用于 --args-list 批量形状;单次调用没有批量预检语义。请改用 --args-list,或移除 --preflight 后执行单次调用。";
|
|
564
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message, retryable: false }));
|
|
581
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
565
582
|
return CLI_EXIT_CODES.invalidInput;
|
|
566
583
|
}
|
|
567
584
|
// 1.2 of issue 2026-10-23: read faces answer {detailArtifactId, sha256} and the
|
|
@@ -590,7 +607,7 @@ async function cmdCall(store, args) {
|
|
|
590
607
|
waitMs = Number(waitValue);
|
|
591
608
|
if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 600_000) {
|
|
592
609
|
const message = "--wait must be an integer number of milliseconds from 0 to 600000";
|
|
593
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message, retryable: false }));
|
|
610
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
594
611
|
return CLI_EXIT_CODES.invalidInput;
|
|
595
612
|
}
|
|
596
613
|
}
|
|
@@ -607,7 +624,7 @@ async function cmdCall(store, args) {
|
|
|
607
624
|
}
|
|
608
625
|
catch (error) {
|
|
609
626
|
const message = error instanceof Error ? error.message : String(error);
|
|
610
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message, retryable: false }));
|
|
627
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
|
|
611
628
|
return CLI_EXIT_CODES.invalidInput;
|
|
612
629
|
}
|
|
613
630
|
if (timeoutMs !== undefined)
|
|
@@ -661,7 +678,7 @@ async function cmdCall(store, args) {
|
|
|
661
678
|
// Keep the REJECTED path on stderr only: the machine envelope must not leak
|
|
662
679
|
// host layout (ticket 103), so it carries the root plus the bare file name.
|
|
663
680
|
const rejectedName = typeof argsFile === "string" ? basename(resolve(configRoot, argsFile)) : "";
|
|
664
|
-
writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: outOfRoot ? `--args-file 必须位于配置根内(配置根 ${configRoot}${rejectedName ? `;本次文件 ${rejectedName}` : ""})。免落盘替代:--args - 从 stdin 读 JSON(echo '<json>' | omc call <tool> --args -),或把文件放进配置根后再引用;限制是为了防参数文件携带凭据被收进会话产物` : argsFile !== undefined && /must be a JSON object/.test(detail) ? `${detail};批量数组请改用 --args-list(最多 200 条,可分批执行)` : detail, retryable: false, ...(outOfRoot ? { configurationRoot: configRoot } : {}) }));
|
|
681
|
+
writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message: outOfRoot ? `--args-file 必须位于配置根内(配置根 ${configRoot}${rejectedName ? `;本次文件 ${rejectedName}` : ""})。免落盘替代:--args - 从 stdin 读 JSON(echo '<json>' | omc call <tool> --args -),或把文件放进配置根后再引用;限制是为了防参数文件携带凭据被收进会话产物` : argsFile !== undefined && /must be a JSON object/.test(detail) ? `${detail};批量数组请改用 --args-list(最多 200 条,可分批执行)` : detail, retryable: false, ...(outOfRoot ? { configurationRoot: configRoot } : {}) }), resultMeta: accountMeta() });
|
|
665
682
|
return CLI_EXIT_CODES.invalidInput;
|
|
666
683
|
}
|
|
667
684
|
const registry = buildToolRegistry();
|
|
@@ -786,7 +803,7 @@ async function cmdCall(store, args) {
|
|
|
786
803
|
waitMs: waitMs > 0 ? waitMs : 30_000,
|
|
787
804
|
});
|
|
788
805
|
console.error(`write lock conflict: ${JSON.stringify({ pid: lock.owner?.pid, tool: lock.owner?.tool ?? lock.owner?.command, startedAt: lock.owner?.startedAt })}`);
|
|
789
|
-
writeEnvelope(envelope("refused", conflict, request, classifyResult(conflict).error));
|
|
806
|
+
writeEnvelope({ ...envelope("refused", conflict, request, classifyResult(conflict).error), resultMeta: accountMeta() });
|
|
790
807
|
return CLI_EXIT_CODES.policyRefused;
|
|
791
808
|
}
|
|
792
809
|
await sleep(Math.min(200, Math.max(0, deadline - Date.now())));
|
|
@@ -1078,13 +1095,22 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1078
1095
|
// 的大对象(实测 589KB 视图 artifact)此前只能拆 key 取、易漏。这里写的是已过
|
|
1079
1096
|
// sha256 校验的原文字节;回执只给 {out,bytes,sha256},stdout 不回正文。
|
|
1080
1097
|
if (options.out !== undefined) {
|
|
1098
|
+
// issue 06(retro 2026-11-19):`--out -` 想把正文直接打到 stdout——铁律是
|
|
1099
|
+
// stdout 恒为恰好一个 JSON envelope,混排正文字节会破坏所有脚本解析,不做。
|
|
1100
|
+
// 错误里给两步替代(根内落盘 + cat),用户照抄即可。
|
|
1101
|
+
if (options.out === "-") {
|
|
1102
|
+
const sample = join(intentConfigRoot(), "artifacts-out", `${id}.json`);
|
|
1103
|
+
const parsed = errorEnvelope(new Error(`artifact get --out - 不支持:stdout 必须恒为恰好一个 JSON envelope(铁律),不能把产物正文字节混排在信封外。一次性提取两步:① omc artifact get ${id} --out ${sample}(父目录会自动创建)② cat ${sample}`), "artifact-out-refused", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
1104
|
+
writeEnvelope(parsed.envelope);
|
|
1105
|
+
return parsed.exitCode;
|
|
1106
|
+
}
|
|
1081
1107
|
let outPath;
|
|
1082
1108
|
try {
|
|
1083
1109
|
outPath = assertSafeOutputPath(intentConfigRoot(), options.out, "artifact output file");
|
|
1084
1110
|
}
|
|
1085
1111
|
catch (error) {
|
|
1086
1112
|
const detail = error instanceof Error ? error.message : String(error);
|
|
1087
|
-
const parsed = errorEnvelope(new Error(`artifact get --out 落盘被拒:${detail}。--out 按配置根(OMC_CONFIG_HOME
|
|
1113
|
+
const parsed = errorEnvelope(new Error(`artifact get --out 落盘被拒:${detail}。--out 按配置根(OMC_CONFIG_HOME)解析,只允许配置根内的常规文件路径;根内父目录会自动创建,配置根外(含系统临时目录)一律拒绝`), "artifact-out-refused", CLI_EXIT_CODES.invalidInput, transport.request);
|
|
1088
1114
|
writeEnvelope(parsed.envelope);
|
|
1089
1115
|
return parsed.exitCode;
|
|
1090
1116
|
}
|
|
@@ -1107,7 +1133,7 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1107
1133
|
// `--shape <path>`:在命中的子树上出骨架(同 --jq 的路径 DSL,含 [] 与 [code=X])。
|
|
1108
1134
|
const projected = projectArtifactPath(artifact.content.toString("utf8") === "" ? undefined : content, options.shape);
|
|
1109
1135
|
if (projected.missed) {
|
|
1110
|
-
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.shape, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at) }, transport);
|
|
1136
|
+
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.shape, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at, pathMissCopyableHint(content, options.shape, projected.at)) }, transport);
|
|
1111
1137
|
}
|
|
1112
1138
|
return emitTransportResult({ status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, path: options.shape, depth, shape: shapeOf(projected.content, depth), fetch: artifactFetchHint(id) }, transport);
|
|
1113
1139
|
}
|
|
@@ -1150,7 +1176,7 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1150
1176
|
// 一层 `projection:{path,content}`——`artifact get --jq` 与 `--summary --jq`
|
|
1151
1177
|
// 因此同形(顶层 path/content),换读面不用重新探根键。
|
|
1152
1178
|
return emitTransportResult(projected.missed
|
|
1153
|
-
? { status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, ...artifactProjectionMetadata(content), keys, path: options.jq, content: null, projections: [{ path: options.jq, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected) }], pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at) }
|
|
1179
|
+
? { status: "ok", artifactId: id, sha256: artifact.sha256, bytes: artifact.content.length, ...artifactProjectionMetadata(content), keys, path: options.jq, content: null, projections: [{ path: options.jq, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected) }], pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at, pathMissCopyableHint(content, options.jq, projected.at)) }
|
|
1154
1180
|
: {
|
|
1155
1181
|
status: "ok",
|
|
1156
1182
|
artifactId: id,
|
|
@@ -1209,7 +1235,7 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1209
1235
|
}
|
|
1210
1236
|
const projected = projectArtifactPath(artifactContent, options.jq);
|
|
1211
1237
|
return emitTransportResult(projected.missed
|
|
1212
|
-
? { status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.jq, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at) }
|
|
1238
|
+
? { status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.jq, content: null, pathMiss: true, missedAt: projected.at, available: projected.available, ...artifactMissExtras(projected), unanswered: true, hint: artifactPathMissHint(projected.at, pathMissCopyableHint(artifactContent, options.jq, projected.at)) }
|
|
1213
1239
|
: { status: "ok", artifactId: id, sha256: artifact.sha256, ...artifactProjectionMetadata(content), path: options.jq, projections: [{ path: options.jq, content: projected.content ?? null, ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}) }], ...(projected.mapped !== undefined ? { mapped: projected.mapped } : {}), ...(projected.missedEntries !== undefined ? { missedEntries: projected.missedEntries } : {}), ...(projected.nullEntries !== undefined && projected.nullEntries > 0 ? { nullEntries: projected.nullEntries } : {}), ...(artifactNullHint(projected.content, projected.nullEntries) !== undefined ? { hint: artifactNullHint(projected.content, projected.nullEntries) } : {}) }, transport);
|
|
1214
1240
|
}
|
|
1215
1241
|
// r6-onboarding 2026-10-21: 47 artifact fetches, 0 used a projection; the 10
|
|
@@ -1234,7 +1260,7 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1234
1260
|
outline: true,
|
|
1235
1261
|
depth,
|
|
1236
1262
|
shape: shapeOf(content, depth),
|
|
1237
|
-
hint: `正文 ${Math.round(artifact.content.length / 1024)}KB 超过内联上限 ${ARTIFACT_INLINE_CEILING_BYTES}B,默认只回深度 ${depth} 骨架(键/类型/数组长度/示例值)。加深:--depth ≤${SHAPE_MAX_DEPTH};子树骨架:--shape <path>;要某几个键:--keys <a,b>;要某个路径:--jq '<path>'(支持 .rules[code=Create].name 这类数组选择器);确实需要整包:--full,或 --out <配置根内路径>
|
|
1263
|
+
hint: `正文 ${Math.round(artifact.content.length / 1024)}KB 超过内联上限 ${ARTIFACT_INLINE_CEILING_BYTES}B,默认只回深度 ${depth} 骨架(键/类型/数组长度/示例值)。加深:--depth ≤${SHAPE_MAX_DEPTH};子树骨架:--shape <path>;要某几个键:--keys <a,b>;要某个路径:--jq '<path>'(支持 .rules[code=Create].name 这类数组选择器);确实需要整包:--full,或 --out <配置根内路径> 整包落盘(父目录自动创建,不走 stdout 限额)。`,
|
|
1238
1264
|
projectionRule: "投影要写到叶子(数组元素里的字段);写整棵父节点(如 data.activities)会因总量超限再次被外置",
|
|
1239
1265
|
...(() => {
|
|
1240
1266
|
const rec = content && typeof content === "object" && !Array.isArray(content) ? content : undefined;
|
|
@@ -1261,7 +1287,11 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1261
1287
|
.slice(0, 3)
|
|
1262
1288
|
.map((entry) => entry.key)
|
|
1263
1289
|
: [];
|
|
1264
|
-
|
|
1290
|
+
// 0.6.82(issue 06 连锁):自愈文案加长后,fullRejected 回执自身可能超过
|
|
1291
|
+
// 顽强的小预算(调用方正用 1024B 这类极限值测试)——被 boundResult 二次
|
|
1292
|
+
// 截断会把 fullRejected 语义键一起截掉。按预算渐进丢弃可选长文案,
|
|
1293
|
+
// 语义键(fullRejected/artifactId/sha256/bytes + 最短出路)永不丢。
|
|
1294
|
+
const fullRejectedReceipt = {
|
|
1265
1295
|
status: "ok",
|
|
1266
1296
|
artifactId: id,
|
|
1267
1297
|
sha256: artifact.sha256,
|
|
@@ -1270,10 +1300,17 @@ async function cmdArtifactGet(id, transport, options = {}) {
|
|
|
1270
1300
|
reason: `整包 ${Math.round(artifact.content.length / 1024)}KB 超过本通道输出上限 ${transport.maxOutputBytes}B;--full 无法一次返回,再跑一次结果相同`,
|
|
1271
1301
|
...(keys.length > 0 ? { keysCommand: `omc artifact get ${id} --keys ${keys.join(",")}`, sampledKeys: keys } : {}),
|
|
1272
1302
|
jqCommand: `omc artifact get ${id} --jq '<path>'`,
|
|
1273
|
-
outCommand: `omc artifact get ${id} --out <配置根内文件路径>(整包落盘,不走 stdout
|
|
1303
|
+
outCommand: `omc artifact get ${id} --out <配置根内文件路径>(整包落盘,不走 stdout 限额,适合一次性备份;根内父目录自动创建,越界拒绝的错误里带可用示例路径)`,
|
|
1274
1304
|
raiseCeilingCommand: `omc artifact get ${id} --full --max-output-bytes ${Math.max(artifact.content.length + 1024, transport.maxOutputBytes * 2)}`,
|
|
1275
1305
|
hint: "三选一:用 --jq/--keys 取你真正需要的那部分(推荐),整包落盘备份用 --out <配置根内路径>(写文件不受 stdout 限额),或显式抬高 --max-output-bytes",
|
|
1276
|
-
}
|
|
1306
|
+
};
|
|
1307
|
+
const optionalKeys = ["hint", "raiseCeilingCommand", "keysCommand", "sampledKeys"];
|
|
1308
|
+
for (const drop of optionalKeys) {
|
|
1309
|
+
if (Buffer.byteLength(JSON.stringify(fullRejectedReceipt), "utf8") <= transport.maxOutputBytes)
|
|
1310
|
+
break;
|
|
1311
|
+
delete fullRejectedReceipt[drop];
|
|
1312
|
+
}
|
|
1313
|
+
return emitTransportResult(fullRejectedReceipt, transport);
|
|
1277
1314
|
}
|
|
1278
1315
|
return emitTransportResult(result, transport);
|
|
1279
1316
|
}
|
|
@@ -2635,6 +2672,10 @@ async function main() {
|
|
|
2635
2672
|
// stderr is the diagnostics stream: apply the same Windows code-page policy
|
|
2636
2673
|
// as stdout before ANY message is written (banner, doctor, refusals).
|
|
2637
2674
|
installCodePageSafeStderr();
|
|
2675
|
+
// issue 13:临时期限窗口的懒恢复——任意命令启动时检查所有环境的
|
|
2676
|
+
// writableWindow,过期即恢复只读(无后台进程),当次 stderr 提示一句。
|
|
2677
|
+
// 用与命令相同的配置根(OMC_CONFIG_HOME / homedir),失败静默交给命令自身。
|
|
2678
|
+
sweepWritableWindowsAtStartup(new ConfigStore(defaultPaths()));
|
|
2638
2679
|
beginUsage(argv);
|
|
2639
2680
|
const command = new Command();
|
|
2640
2681
|
// r60b-F7:helpDisplayed 不区分「根帮助」与「子命令帮助」——两者都走同一个
|
|
@@ -2721,7 +2762,7 @@ async function main() {
|
|
|
2721
2762
|
nextCommand: "omc setup --list",
|
|
2722
2763
|
}));
|
|
2723
2764
|
});
|
|
2724
|
-
command.command("env [action] [name]").description("环境清单与联调参数包;`env export` 一键导出 token/headers,免手工从浏览器复制 token").option("--json").option("--env <environment>", "环境名;按与 call 相同的项目范围门解析").option("--format <format>", "export:输出可 source 的 bash 环境变量语句").option("--field <field>", "输出单个裸值:accessToken|baseUrl|enterpriseId|engineCode").option("--example <example>", "追加一个复制即测示例:curl|node;path 换成你的接口(示例内 token 默认占位,真值走 --field accessToken 或管道注入)").option("--reveal-token", "示例里回填真实 accessToken(默认打码;只在本地直接执行时用,别把输出贴进对话/归档)").addHelpText("after", "\n`omc env export` 用于二开联调参数包;`--example curl|node` 追加复制即测示例(把 `<your-api-path>` 换成你的接口),默认 JSON 不带示例。`--format env` 可 source,`--field accessToken` 输出裸 token;`--example` 里的 token 默认占位(`--reveal-token` 才回填真值)。\n").action(async (action, name, options) => {
|
|
2765
|
+
command.command("env [action] [name]").description("环境清单与联调参数包;`env export` 一键导出 token/headers,免手工从浏览器复制 token").option("--json").option("--env <environment>", "环境名;按与 call 相同的项目范围门解析").option("--format <format>", "export:输出可 source 的 bash 环境变量语句").option("--field <field>", "输出单个裸值:accessToken|baseUrl|enterpriseId|engineCode").option("--example <example>", "追加一个复制即测示例:curl|node;path 换成你的接口(示例内 token 默认占位,真值走 --field accessToken 或管道注入)").option("--reveal-token", "示例里回填真实 accessToken(默认打码;只在本地直接执行时用,别把输出贴进对话/归档)").option("--ttl <duration>", `writable:窗口时长(默认 ${WRITABLE_WINDOW_DEFAULT_TTL_MINUTES}m,上限 ${WRITABLE_WINDOW_MAX_TTL_MINUTES}m),如 10m / 30m`).option("--reason <text>", "writable:必填,写清这一次为什么要临时开写(进 writable-window.log 审计)").option("--close", "writable:立即恢复只读并清掉窗口").addHelpText("after", "\n`omc env export` 用于二开联调参数包;`--example curl|node` 追加复制即测示例(把 `<your-api-path>` 换成你的接口),默认 JSON 不带示例。`--format env` 可 source,`--field accessToken` 输出裸 token;`--example` 里的 token 默认占位(`--reveal-token` 才回填真值)。\n账号口径(issue 07):`account` 是本次**导出凭据**登录的显示名;`sessionAccount` 是 token 声明的账号(id=user_id、username=user_name)。导出凭据账号 ≠ 之后 call 的会话账号——凭据轮换/token 过期重登/多环境同名账号时两者不同;每次 `omc call` 回执的 resultMeta.sessionAccount 才是当次会话账号(token 解码,解不出回 unavailableReason)。报错里的 currentUser 是平台按 username 反查的 id(同名多账号时可能与 token user_id 不同人)。\n\n环境写窗口(治理,issue 13):`omc env writable <env> --ttl 10m --reason \"为什么开写\"` 临时把该环境置为可写,回执带开启人/到期时间/到期自动恢复说明,并写 append-only 配置根 `" + WRITABLE_WINDOW_LOG + "` 审计(open/close/expire)。`--reason` 必填,TTL 默认 " + WRITABLE_WINDOW_DEFAULT_TTL_MINUTES + "m、上限 " + WRITABLE_WINDOW_MAX_TTL_MINUTES + "m。到期后**下一次任意 omc 命令**自动恢复只读(懒检查,没有后台进程);`omc env writable <env>` 查看窗口,`omc env writable <env> --close` 立即恢复只读。窗口只解除 writable 只读门——生产环境的每笔写**仍然**要在 args 里带 confirmProduction:true(两道门并存,窗口不绕过生产确认)。\n\n输入乱码自检(issue 18):若参数或用户消息出现异常汉字(如「翿」替掉「说/门/试」),先把原文回显请用户确认再执行——输入链路可能不是 UTF-8(终端/输入法→IPC),不要按猜测的语义写配置。\n").action(async (action, name, options) => {
|
|
2725
2766
|
// Read-only inventory of configured environment names. r18: the sandbox
|
|
2726
2767
|
// guessed names instead of listing them; doctor's wording now points here.
|
|
2727
2768
|
const store = new ConfigStore(defaultPaths());
|
|
@@ -2768,6 +2809,92 @@ async function main() {
|
|
|
2768
2809
|
}
|
|
2769
2810
|
return;
|
|
2770
2811
|
}
|
|
2812
|
+
if (action === "writable") {
|
|
2813
|
+
// issue 13:生产写临时开关。stdout 恒一个信封(与 export 同面);
|
|
2814
|
+
// 人类可读的一句话走 stderr。窗口只解除 writable 门,生产写仍须确认。
|
|
2815
|
+
const target = name ?? options.env;
|
|
2816
|
+
const emitWritable = (result) => {
|
|
2817
|
+
writeEnvelope(envelope("ok", result, request));
|
|
2818
|
+
return CLI_EXIT_CODES.ok;
|
|
2819
|
+
};
|
|
2820
|
+
try {
|
|
2821
|
+
if (!target) {
|
|
2822
|
+
console.error(`用法:omc env writable <环境名> [--ttl ${WRITABLE_WINDOW_DEFAULT_TTL_MINUTES}m] --reason "为什么开写" | omc env writable <环境名>(查看)| omc env writable <环境名> --close(立即恢复只读)`);
|
|
2823
|
+
const parsed = errorEnvelope(new Error("omc env writable 需要环境名"), "invalid-input", CLI_EXIT_CODES.invalidInput, request);
|
|
2824
|
+
writeEnvelope(parsed.envelope);
|
|
2825
|
+
commandExitCode = parsed.exitCode;
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
if (options.close === true) {
|
|
2829
|
+
if (options.ttl !== undefined || options.reason !== undefined) {
|
|
2830
|
+
const parsed = errorEnvelope(new Error("--close 与 --ttl/--reason 互斥:关窗不需要时长和原因(关窗本身会记审计)"), "invalid-input", CLI_EXIT_CODES.invalidInput, request);
|
|
2831
|
+
writeEnvelope(parsed.envelope);
|
|
2832
|
+
commandExitCode = parsed.exitCode;
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
const closed = closeWritableWindow(store, target);
|
|
2836
|
+
console.error(`已立即恢复只读:${closed.environment}${closed.previousWindow !== undefined ? `(原窗口:到期 ${closed.previousWindow.expiresAt},原因:${closed.previousWindow.reason})` : ""}`);
|
|
2837
|
+
commandExitCode = emitWritable({
|
|
2838
|
+
status: "ok",
|
|
2839
|
+
action: "close",
|
|
2840
|
+
environment: closed.environment,
|
|
2841
|
+
writable: false,
|
|
2842
|
+
...(closed.previousWindow !== undefined ? { previousWindow: closed.previousWindow } : {}),
|
|
2843
|
+
sessionAccount: closed.sessionAccount,
|
|
2844
|
+
audit: WRITABLE_WINDOW_LOG,
|
|
2845
|
+
});
|
|
2846
|
+
return;
|
|
2847
|
+
}
|
|
2848
|
+
if (options.ttl === undefined && options.reason === undefined) {
|
|
2849
|
+
const status = writableWindowStatus(store, target);
|
|
2850
|
+
console.error(status.window !== undefined
|
|
2851
|
+
? `${status.environment} 写窗口开启中:到期 ${status.window.expiresAt}(原因:${status.window.reason};开启人:${status.window.openedBy})。到期后下一次任意 omc 命令自动恢复只读;立即关:omc env writable ${status.environment} --close`
|
|
2852
|
+
: `${status.environment} 没有写窗口(writable=${status.writable})。开一次:omc env writable ${status.environment} --ttl ${WRITABLE_WINDOW_DEFAULT_TTL_MINUTES}m --reason "..."`);
|
|
2853
|
+
commandExitCode = emitWritable({
|
|
2854
|
+
status: "ok",
|
|
2855
|
+
action: "status",
|
|
2856
|
+
environment: status.environment,
|
|
2857
|
+
writable: status.writable,
|
|
2858
|
+
production: status.production,
|
|
2859
|
+
window: status.window ?? null,
|
|
2860
|
+
expired: status.expired,
|
|
2861
|
+
now: status.now,
|
|
2862
|
+
audit: WRITABLE_WINDOW_LOG,
|
|
2863
|
+
});
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
const ttlMinutes = parseWritableTtl(options.ttl);
|
|
2867
|
+
const reason = validateWritableReason(options.reason);
|
|
2868
|
+
const opened = openWritableWindow(store, target, { ttlMinutes, reason });
|
|
2869
|
+
const production = opened.profile.production === true;
|
|
2870
|
+
console.error(`已开启写窗口:${opened.environment} 到期 ${opened.window.expiresAt}(TTL ${opened.window.ttlMinutes}m,开启人:${opened.window.openedBy})。到期后下一次任意 omc 命令自动恢复只读;审计:${WRITABLE_WINDOW_LOG}${production ? "。注意:生产写仍需每笔 confirmProduction:true(窗口不绕过生产确认)" : ""}`);
|
|
2871
|
+
commandExitCode = emitWritable({
|
|
2872
|
+
status: "ok",
|
|
2873
|
+
action: "open",
|
|
2874
|
+
environment: opened.environment,
|
|
2875
|
+
writable: true,
|
|
2876
|
+
production,
|
|
2877
|
+
window: opened.window,
|
|
2878
|
+
openedBy: opened.window.openedBy,
|
|
2879
|
+
expiresAt: opened.window.expiresAt,
|
|
2880
|
+
sessionAccount: opened.sessionAccount,
|
|
2881
|
+
autoRestore: `到期(${opened.window.expiresAt})后下一次任意 omc 命令启动时自动恢复只读并清掉窗口记录(懒检查,无后台进程)`,
|
|
2882
|
+
productionConfirmation: production
|
|
2883
|
+
? { required: true, note: "窗口只解除 writable 只读门;生产环境每笔写仍须在 args 里带 confirmProduction:true(两道门并存)" }
|
|
2884
|
+
: { required: false, note: "窗口只解除 writable 只读门" },
|
|
2885
|
+
audit: WRITABLE_WINDOW_LOG,
|
|
2886
|
+
});
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
catch (error) {
|
|
2890
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2891
|
+
const invalid = error instanceof WritableWindowInputError || /unknown environment|跨环境访问被拒绝|writableWindow|not valid JSON|must contain an environments/.test(message);
|
|
2892
|
+
const parsed = errorEnvelope(error, invalid ? "invalid-input" : "environment-unreachable", invalid ? CLI_EXIT_CODES.invalidInput : CLI_EXIT_CODES.internal, request);
|
|
2893
|
+
writeEnvelope(parsed.envelope);
|
|
2894
|
+
commandExitCode = parsed.exitCode;
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2771
2898
|
if (action === "allow") {
|
|
2772
2899
|
// The only sanctioned way to widen a project's environment scope. The
|
|
2773
2900
|
// list stays project-scoped until the operator names the environment —
|
|
@@ -2790,7 +2917,7 @@ async function main() {
|
|
|
2790
2917
|
return;
|
|
2791
2918
|
}
|
|
2792
2919
|
if (action !== undefined && action !== "list") {
|
|
2793
|
-
console.error("用法:omc env list [--json] | omc env allow <环境名>");
|
|
2920
|
+
console.error("用法:omc env list [--json] | omc env allow <环境名> | omc env writable <环境名> [--ttl 10m --reason \"...\" | --close]");
|
|
2794
2921
|
commandExitCode = CLI_EXIT_CODES.invalidInput;
|
|
2795
2922
|
return;
|
|
2796
2923
|
}
|
|
@@ -3105,7 +3232,7 @@ async function main() {
|
|
|
3105
3232
|
console.error(`已清理 ${result.removed} 个读回产物,释放 ${formatBytes(result.freedBytes)};保留 ${result.kept} 个(${formatBytes(result.keptBytes)})`);
|
|
3106
3233
|
commandExitCode = CLI_EXIT_CODES.ok;
|
|
3107
3234
|
});
|
|
3108
|
-
artifactCommand.command("get <id>").addOption(new Option("--jq [path]", "路径选择器(非 jq);支持 [] 映射与逗号多路径;裸 --jq 列顶层键").argParser((value, previous = []) => [...previous, value]).default([])).option("--extract <path>", "同 --jq(与 omc call 的 --extract 同名,省一次命名切换)").option("--path-only").option("--shape [path]", "回执形状先验:深度受限骨架(键/类型/数组长度/≤40 字符示例值),一次看全嵌套路径图再 --jq;裸 --shape = 整棵根,--shape <path> = 命中子树(同 --jq 的路径 DSL);与 >8KB 默认 outline 同一实现").option("--depth <n>", "骨架深度 1-4(默认 2;--shape 与 >8KB 默认 outline 消费)").option("--summary").option("--keys [a,b]").option("--full", "整包返回正文(默认:正文超过 8KB 时只回深度 2 骨架 outline,按需 --shape/--jq/--keys 定向取值)").option("--out <path>", "把 artifact 原始正文全量写到配置根内文件(0600;写文件不走 stdout 限额,大对象一次落盘备份;回执只给 {out,bytes,sha256}
|
|
3235
|
+
artifactCommand.command("get <id>").addOption(new Option("--jq [path]", "路径选择器(非 jq);支持 [] 映射与逗号多路径;裸 --jq 列顶层键").argParser((value, previous = []) => [...previous, value]).default([])).option("--extract <path>", "同 --jq(与 omc call 的 --extract 同名,省一次命名切换)").option("--path-only").option("--shape [path]", "回执形状先验:深度受限骨架(键/类型/数组长度/≤40 字符示例值),一次看全嵌套路径图再 --jq;裸 --shape = 整棵根,--shape <path> = 命中子树(同 --jq 的路径 DSL);与 >8KB 默认 outline 同一实现").option("--depth <n>", "骨架深度 1-4(默认 2;--shape 与 >8KB 默认 outline 消费)").option("--summary").option("--keys [a,b]").option("--full", "整包返回正文(默认:正文超过 8KB 时只回深度 2 骨架 outline,按需 --shape/--jq/--keys 定向取值)").option("--out <path>", "把 artifact 原始正文全量写到配置根内文件(0600;写文件不走 stdout 限额,大对象一次落盘备份;回执只给 {out,bytes,sha256} 不回正文。根内父目录自动创建;配置根外(含系统临时目录)拒绝,拒绝错误里带可用的根内示例路径。stdout 管道提取用两步:--out <根内路径> 后 cat 该文件——`--out -` 会破坏单信封契约,不支持)").option("--max-output-bytes <bytes>").action(async (id, options) => {
|
|
3109
3236
|
// A bare `--jq`/`--keys` is a key-inventory request, not a missing argument:
|
|
3110
3237
|
// commander's "argument missing" (invalid-input + retry) is a dead end the
|
|
3111
3238
|
// caller cannot fix without already knowing the flag takes a value (r11
|
package/dist/config-store.js
CHANGED
|
@@ -44,6 +44,20 @@ export function removedProfileKeys(profile) {
|
|
|
44
44
|
const raw = profile;
|
|
45
45
|
return REMOVED_PROFILE_KEYS.filter((key) => raw[key] !== undefined);
|
|
46
46
|
}
|
|
47
|
+
/** Fail closed on a malformed window (hand-edited config must not fake a gate). */
|
|
48
|
+
function validateWritableWindow(environment, window) {
|
|
49
|
+
if (window === null || typeof window !== "object" || Array.isArray(window))
|
|
50
|
+
throw new ConfigurationError(`environment ${environment} writableWindow must be an object when present`);
|
|
51
|
+
const record = window;
|
|
52
|
+
for (const key of ["openedBy", "openedAt", "expiresAt", "reason"])
|
|
53
|
+
if (typeof record[key] !== "string" || record[key].length === 0)
|
|
54
|
+
throw new ConfigurationError(`environment ${environment} writableWindow.${key} must be a non-empty string`);
|
|
55
|
+
if (typeof record.ttlMinutes !== "number" || !Number.isFinite(record.ttlMinutes) || record.ttlMinutes <= 0)
|
|
56
|
+
throw new ConfigurationError(`environment ${environment} writableWindow.ttlMinutes must be a positive number`);
|
|
57
|
+
for (const key of ["openedAt", "expiresAt"])
|
|
58
|
+
if (Number.isNaN(Date.parse(record[key])))
|
|
59
|
+
throw new ConfigurationError(`environment ${environment} writableWindow.${key} must be an ISO timestamp`);
|
|
60
|
+
}
|
|
47
61
|
export class ConfigurationError extends Error {
|
|
48
62
|
policyRefused;
|
|
49
63
|
constructor(message, options = {}) {
|
|
@@ -131,6 +145,8 @@ export class ConfigStore {
|
|
|
131
145
|
for (const key of ["isDefault", "production", "writable"])
|
|
132
146
|
if (profile[key] !== undefined && typeof profile[key] !== "boolean")
|
|
133
147
|
throw new ConfigurationError(`environment ${name} ${key} must be boolean when present`);
|
|
148
|
+
if (profile.writableWindow !== undefined)
|
|
149
|
+
validateWritableWindow(name, profile.writableWindow);
|
|
134
150
|
const removed = removedProfileKeys(profile);
|
|
135
151
|
if (removed.length > 0)
|
|
136
152
|
throw new ConfigurationError(`environment ${name} carries removed governance keys: ${removed.join(", ")}. Writing is decided by "writable" alone, and a production write needs a per-write confirmProduction — delete these keys.`);
|
|
@@ -162,6 +178,25 @@ export class ConfigStore {
|
|
|
162
178
|
this.writeConfig({ environments });
|
|
163
179
|
return config;
|
|
164
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Read-modify-write one profile against a **fresh** config read. Used by the
|
|
183
|
+
* writable-window commands: the updater runs on the just-read profile so a
|
|
184
|
+
* concurrent setup edit is never silently overwritten by a stale snapshot.
|
|
185
|
+
*/
|
|
186
|
+
updateEnvironmentProfile(name, update) {
|
|
187
|
+
const config = this.readConfig();
|
|
188
|
+
const current = config.environments[name];
|
|
189
|
+
if (!current)
|
|
190
|
+
throw new ConfigurationError(`unknown environment "${name}"; available: ${this.availableEnvironmentNames()}`);
|
|
191
|
+
const next = update(current);
|
|
192
|
+
const environments = { ...config.environments, [name]: next };
|
|
193
|
+
if (next.isDefault)
|
|
194
|
+
for (const [other, otherProfile] of Object.entries(environments))
|
|
195
|
+
if (other !== name)
|
|
196
|
+
environments[other] = { ...otherProfile, isDefault: false };
|
|
197
|
+
this.writeConfig({ environments });
|
|
198
|
+
return next;
|
|
199
|
+
}
|
|
165
200
|
/**
|
|
166
201
|
* Environments visible to THIS project. Project isolation is the default:
|
|
167
202
|
* the caller only ever sees the project's own environments, never the rest of
|