@stalfh233/omc-cli 0.6.82 → 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/dist/cli.js +97 -6
- package/dist/config-store.js +35 -0
- package/dist/endpoints.js +10 -0
- package/dist/lanes/businessrule.js +78 -2
- package/dist/lanes/environment-contract.js +8 -0
- package/dist/lanes/environment.js +73 -0
- package/dist/lanes/runtime-data-contract.js +8 -0
- package/dist/lanes/runtime-data.js +99 -12
- package/dist/path-projection.js +133 -21
- package/dist/read-shapes.js +2 -1
- package/dist/refusal-guidance.js +1 -1
- package/dist/rule-support.js +105 -15
- package/dist/session.js +27 -0
- package/dist/token-cache.js +3 -0
- package/dist/tool-types.js +3 -1
- package/dist/writable-window.js +209 -0
- package/package.json +3 -3
package/dist/token-cache.js
CHANGED
|
@@ -37,6 +37,9 @@ export class TokenCache {
|
|
|
37
37
|
administrator: parsed.administrator,
|
|
38
38
|
...(parsed.accountIdentity !== undefined ? { accountIdentity: parsed.accountIdentity } : {}),
|
|
39
39
|
...(parsed.version !== undefined ? { version: parsed.version } : {}),
|
|
40
|
+
// r86(retro issue 17):白名单漏读会让 productVersion 面在产品线前缀上
|
|
41
|
+
// 永久降级(写进缓存却读不回 → 每次命中都走 detectedVersion 兜底)。
|
|
42
|
+
...(typeof parsed.rawVersion === "string" && parsed.rawVersion.trim().length > 0 ? { rawVersion: parsed.rawVersion } : {}),
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
save(environmentName, fingerprint, login) {
|
package/dist/tool-types.js
CHANGED
|
@@ -126,7 +126,9 @@ const TOOL_INPUT_ALIASES = Object.freeze({
|
|
|
126
126
|
// 调用方没给 code 时生效;kind=model 想按模型查请显式用 code。
|
|
127
127
|
"rule.references": Object.freeze({ code: ["ruleCode"], schemaCodes: ["schemaCode"] }),
|
|
128
128
|
// r73 探针02-P2:分页条数在 data.list 叫 size,调用方习惯 limit(SQL/REST 肌肉记忆)。
|
|
129
|
-
|
|
129
|
+
// r86(retro issue 16):排序参数名是 orderBy;真机报障的原形是 `sort:[{field,direction}]`
|
|
130
|
+
// (形状与 orderBy 完全一致,见 issue-16)。归一化免得同义键在读面未知键门先被拒。
|
|
131
|
+
"data.list": Object.freeze({ size: ["limit"], orderBy: ["sort"] }),
|
|
130
132
|
});
|
|
131
133
|
/**
|
|
132
134
|
* r54 C② F2:该工具在 TOOL_INPUT_ALIASES 里声明的**同义词键**(调用方可能拿来
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { sessionAccountForEnvironment } from "./session-account.js";
|
|
4
|
+
/**
|
|
5
|
+
* Issue 13(retro 2026-11-19):生产写临时开关。
|
|
6
|
+
*
|
|
7
|
+
* 现实流程曾是「备份 omc.config.json → 手改 writable → 写 → 还原备份」:没有
|
|
8
|
+
* 审计、没有到期恢复、多人共用一台机器时状态不可预期。这里把同一件事做成一条
|
|
9
|
+
* 有治理的命令:
|
|
10
|
+
*
|
|
11
|
+
* omc env writable <env> --ttl 10m --reason "..." # 开窗(reason 必填,TTL ≤30m)
|
|
12
|
+
* omc env writable <env> # 查看窗口
|
|
13
|
+
* omc env writable <env> --close # 立即恢复只读
|
|
14
|
+
*
|
|
15
|
+
* 治理语义(与 `writable` 门的关系):
|
|
16
|
+
* - 窗口只把该环境的 `writable` 置 true;生产环境的每笔写**仍然**需要在 args 里
|
|
17
|
+
* 带 confirmProduction:true(两道门并存,窗口不绕过生产确认)。
|
|
18
|
+
* - 到期恢复是**懒检查**:任意 `omc` 命令启动时扫一遍所有环境,过期即恢复
|
|
19
|
+
* writable:false 并清掉窗口记录;没有后台进程。
|
|
20
|
+
* - 每次 open/close/expire 都写配置根下的 append-only `writable-window.log`
|
|
21
|
+
* (一行一事件,JSONL:时间/环境/操作者/reason/TTL/到期时间)。
|
|
22
|
+
*/
|
|
23
|
+
export const WRITABLE_WINDOW_DEFAULT_TTL_MINUTES = 10;
|
|
24
|
+
export const WRITABLE_WINDOW_MAX_TTL_MINUTES = 30;
|
|
25
|
+
export const WRITABLE_WINDOW_LOG = "writable-window.log";
|
|
26
|
+
const REASON_MAX_CHARS = 500;
|
|
27
|
+
export class WritableWindowInputError extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "WritableWindowInputError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `--ttl 10m` / `10min` / `10` / `1h`。缺省 10 分钟;上限 30 分钟(规格)。
|
|
35
|
+
* 返回分钟数。非法/超限抛 WritableWindowInputError(CLI 映射 invalid-input)。
|
|
36
|
+
*/
|
|
37
|
+
export function parseWritableTtl(raw) {
|
|
38
|
+
if (raw === undefined || raw.trim() === "")
|
|
39
|
+
return WRITABLE_WINDOW_DEFAULT_TTL_MINUTES;
|
|
40
|
+
const match = /^\s*(\d+)\s*(m|min|mins|minute|minutes|h|hr|hour|hours)?\s*$/iu.exec(raw);
|
|
41
|
+
if (match === null)
|
|
42
|
+
throw new WritableWindowInputError(`--ttl 需要像 10m / 1h 这样的时长(默认 ${WRITABLE_WINDOW_DEFAULT_TTL_MINUTES}m,上限 ${WRITABLE_WINDOW_MAX_TTL_MINUTES}m):收到 "${raw}"`);
|
|
43
|
+
const amount = Number(match[1]);
|
|
44
|
+
const unit = (match[2] ?? "m").toLowerCase();
|
|
45
|
+
const minutes = unit.startsWith("h") ? amount * 60 : amount;
|
|
46
|
+
if (!Number.isInteger(minutes) || minutes < 1)
|
|
47
|
+
throw new WritableWindowInputError(`--ttl 至少 1 分钟:收到 "${raw}"`);
|
|
48
|
+
if (minutes > WRITABLE_WINDOW_MAX_TTL_MINUTES)
|
|
49
|
+
throw new WritableWindowInputError(`--ttl 上限 ${WRITABLE_WINDOW_MAX_TTL_MINUTES} 分钟(临时窗口不是长期授权):收到 "${raw}"`);
|
|
50
|
+
return minutes;
|
|
51
|
+
}
|
|
52
|
+
export function validateWritableReason(raw) {
|
|
53
|
+
const reason = raw?.trim() ?? "";
|
|
54
|
+
if (reason === "")
|
|
55
|
+
throw new WritableWindowInputError(`--reason 必填:写清这一次为什么要临时开写(会进 ${WRITABLE_WINDOW_LOG} 审计),如 --reason "修正 orderChange 变更渠道映射"`);
|
|
56
|
+
if (reason.length > REASON_MAX_CHARS)
|
|
57
|
+
throw new WritableWindowInputError(`--reason 最长 ${REASON_MAX_CHARS} 字符(审计一行一事件)`);
|
|
58
|
+
return reason;
|
|
59
|
+
}
|
|
60
|
+
/** sessionAccount → 审计/回执里的可读标签(永不编造身份)。 */
|
|
61
|
+
export function writableWindowOperator(account) {
|
|
62
|
+
if ("unavailableReason" in account)
|
|
63
|
+
return `unavailable:${account.unavailableReason}`;
|
|
64
|
+
const parts = [];
|
|
65
|
+
for (const value of [account.name, account.username, account.id]) {
|
|
66
|
+
if (typeof value === "string" && value.length > 0 && !parts.includes(value))
|
|
67
|
+
parts.push(value);
|
|
68
|
+
}
|
|
69
|
+
return parts.length > 0 ? parts.join(" / ") : `id:${account.id}`;
|
|
70
|
+
}
|
|
71
|
+
/** Append one JSONL event. Best-effort: an audit failure must not undo the gate change. */
|
|
72
|
+
export function appendWritableWindowAudit(store, event) {
|
|
73
|
+
try {
|
|
74
|
+
const path = join(dirname(store.configPaths.configPath), WRITABLE_WINDOW_LOG);
|
|
75
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
76
|
+
appendFileSync(path, JSON.stringify({ ts: new Date().toISOString(), ...event }) + "\n", { mode: 0o600 });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error(`writable-window 审计写入失败(门已按命令执行):${error.message}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function openWritableWindow(store, environment, options) {
|
|
83
|
+
const resolved = store.resolveEnvironment(environment);
|
|
84
|
+
const now = options.now ?? new Date();
|
|
85
|
+
const expiresAt = new Date(now.getTime() + options.ttlMinutes * 60_000);
|
|
86
|
+
const sessionAccount = sessionAccountForEnvironment(store, resolved.name);
|
|
87
|
+
const openedBy = writableWindowOperator(sessionAccount);
|
|
88
|
+
const window = {
|
|
89
|
+
openedBy,
|
|
90
|
+
openedAt: now.toISOString(),
|
|
91
|
+
expiresAt: expiresAt.toISOString(),
|
|
92
|
+
reason: options.reason,
|
|
93
|
+
ttlMinutes: options.ttlMinutes,
|
|
94
|
+
};
|
|
95
|
+
const profile = store.updateEnvironmentProfile(resolved.name, (current) => ({ ...current, writable: true, writableWindow: window }));
|
|
96
|
+
appendWritableWindowAudit(store, {
|
|
97
|
+
event: "open",
|
|
98
|
+
environment: resolved.name,
|
|
99
|
+
operator: openedBy,
|
|
100
|
+
reason: options.reason,
|
|
101
|
+
ttlMinutes: options.ttlMinutes,
|
|
102
|
+
expiresAt: window.expiresAt,
|
|
103
|
+
});
|
|
104
|
+
return { environment: resolved.name, profile, window, sessionAccount };
|
|
105
|
+
}
|
|
106
|
+
export function closeWritableWindow(store, environment, options = {}) {
|
|
107
|
+
const resolved = store.resolveEnvironment(environment);
|
|
108
|
+
const sessionAccount = sessionAccountForEnvironment(store, resolved.name);
|
|
109
|
+
const operator = writableWindowOperator(sessionAccount);
|
|
110
|
+
const current = store.readConfig().environments[resolved.name];
|
|
111
|
+
const previousWindow = current?.writableWindow;
|
|
112
|
+
store.updateEnvironmentProfile(resolved.name, (profile) => {
|
|
113
|
+
const { writableWindow: _dropped, ...rest } = profile;
|
|
114
|
+
return { ...rest, writable: false };
|
|
115
|
+
});
|
|
116
|
+
appendWritableWindowAudit(store, {
|
|
117
|
+
event: "close",
|
|
118
|
+
environment: resolved.name,
|
|
119
|
+
operator,
|
|
120
|
+
reason: previousWindow?.reason ?? "manual-close",
|
|
121
|
+
...(previousWindow !== undefined ? { ttlMinutes: previousWindow.ttlMinutes, expiresAt: previousWindow.expiresAt, openedBy: previousWindow.openedBy } : {}),
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
environment: resolved.name,
|
|
125
|
+
closed: true,
|
|
126
|
+
...(previousWindow !== undefined ? { previousWindow } : {}),
|
|
127
|
+
sessionAccount,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function writableWindowStatus(store, environment, options = {}) {
|
|
131
|
+
const resolved = store.resolveEnvironment(environment);
|
|
132
|
+
const now = options.now ?? new Date();
|
|
133
|
+
const window = resolved.profile.writableWindow;
|
|
134
|
+
return {
|
|
135
|
+
environment: resolved.name,
|
|
136
|
+
writable: resolved.profile.writable === true,
|
|
137
|
+
production: resolved.profile.production === true,
|
|
138
|
+
...(window !== undefined ? { window } : {}),
|
|
139
|
+
expired: window !== undefined && Date.parse(window.expiresAt) <= now.getTime(),
|
|
140
|
+
now: now.toISOString(),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Lazy expiry: restore `writable:false` and drop the window record for every
|
|
145
|
+
* expired environment. Returns what changed so the caller can say one stderr
|
|
146
|
+
* line. Scans ALL configured environments (not just this project's) — a window
|
|
147
|
+
* left open by another project must still expire.
|
|
148
|
+
*/
|
|
149
|
+
export function expireWritableWindows(store, options = {}) {
|
|
150
|
+
const now = options.now ?? new Date();
|
|
151
|
+
const config = store.readConfig();
|
|
152
|
+
const expired = [];
|
|
153
|
+
for (const [environment, profile] of Object.entries(config.environments)) {
|
|
154
|
+
const window = profile.writableWindow;
|
|
155
|
+
if (window === undefined)
|
|
156
|
+
continue;
|
|
157
|
+
if (Date.parse(window.expiresAt) > now.getTime())
|
|
158
|
+
continue;
|
|
159
|
+
expired.push({ environment, window });
|
|
160
|
+
}
|
|
161
|
+
const applied = [];
|
|
162
|
+
for (const { environment, window } of expired) {
|
|
163
|
+
try {
|
|
164
|
+
// Re-read per environment: updateEnvironmentProfile never writes a stale
|
|
165
|
+
// snapshot taken before a concurrent `env writable` finished.
|
|
166
|
+
store.updateEnvironmentProfile(environment, (profile) => {
|
|
167
|
+
const { writableWindow: _dropped, ...rest } = profile;
|
|
168
|
+
return { ...rest, writable: false };
|
|
169
|
+
});
|
|
170
|
+
appendWritableWindowAudit(store, {
|
|
171
|
+
event: "expire",
|
|
172
|
+
environment,
|
|
173
|
+
operator: "auto:ttl-expire",
|
|
174
|
+
openedBy: window.openedBy,
|
|
175
|
+
reason: window.reason,
|
|
176
|
+
ttlMinutes: window.ttlMinutes,
|
|
177
|
+
expiresAt: window.expiresAt,
|
|
178
|
+
});
|
|
179
|
+
applied.push({ environment, window });
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Environment removed / config rewritten mid-sweep: skip it; the next
|
|
183
|
+
// command retries. Never let one bad entry abort the rest.
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return applied;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Called once per CLI process, before command dispatch. Never throws: a broken
|
|
190
|
+
* config is the command's error to report, not the sweeper's. One stderr line
|
|
191
|
+
* only when something actually expired (no background process, no chatter).
|
|
192
|
+
*/
|
|
193
|
+
export function sweepWritableWindowsAtStartup(store) {
|
|
194
|
+
let expired = [];
|
|
195
|
+
try {
|
|
196
|
+
expired = expireWritableWindows(store);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
if (expired.length > 0) {
|
|
202
|
+
const detail = expired
|
|
203
|
+
.map(({ environment, window }) => `${environment}(到期 ${window.expiresAt},原因:${window.reason})`)
|
|
204
|
+
.join(";");
|
|
205
|
+
console.error(`writable 临时窗口已到期并自动恢复只读:${detail}。审计:${WRITABLE_WINDOW_LOG}`);
|
|
206
|
+
}
|
|
207
|
+
return expired;
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=writable-window.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stalfh233/omc-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.83",
|
|
4
4
|
"description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"commander": "14.0.3",
|
|
59
|
-
"omc-core": "0.6.
|
|
59
|
+
"omc-core": "0.6.83",
|
|
60
60
|
"proper-lockfile": "4.1.2",
|
|
61
61
|
"write-file-atomic": "6.0.0",
|
|
62
62
|
"zod": "^3.23.8",
|
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
"directory": "packages/omc-cli"
|
|
75
75
|
},
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"@stalfh233/omc-fake-platform": "0.6.
|
|
77
|
+
"@stalfh233/omc-fake-platform": "0.6.83"
|
|
78
78
|
}
|
|
79
79
|
}
|