@stalfh233/omc-cli 0.6.82 → 0.6.84
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/lanes/workflow.js +101 -64
- package/dist/path-projection.js +163 -24
- 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/rule-support.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { wireCall, wireRows, WireError } from "./wire.js";
|
|
2
|
+
import { wireCall, wireCallWith404Fallback, wireRows, WireError } from "./wire.js";
|
|
3
3
|
import { ENDPOINTS } from "./endpoints.js";
|
|
4
4
|
import { readModelRecord } from "./model-record.js";
|
|
5
5
|
import { ToolRefusalError } from "./tool-types.js";
|
|
@@ -1408,6 +1408,73 @@ export async function lintRuleSaveWrite(session, args) {
|
|
|
1408
1408
|
...(mappingPreflight.absent !== undefined ? { absentMappingFields: mappingPreflight.absent } : {}),
|
|
1409
1409
|
};
|
|
1410
1410
|
}
|
|
1411
|
+
async function verifyRulePublish(session, schemaCode, ruleCode, publishResponse) {
|
|
1412
|
+
const verifyWire = "发布后经 runtime/business_rule/list_by_schemacode 读回验证(+1 wire,替换原先读不到发布事实的 app/DRAFT 面读回——app 面只投影 DRAFT 行,读它验证不了发布)";
|
|
1413
|
+
const responseVersion = publishResponse !== null && typeof publishResponse.ruleVersion === "number" ? publishResponse.ruleVersion : undefined;
|
|
1414
|
+
let rows;
|
|
1415
|
+
try {
|
|
1416
|
+
rows = wireRows((await wireCallWith404Fallback(session, [
|
|
1417
|
+
{ path: ENDPOINTS.runtimeBusinessRuleListBySchemaCode, query: { schemaCode } },
|
|
1418
|
+
{ path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } },
|
|
1419
|
+
])).data);
|
|
1420
|
+
}
|
|
1421
|
+
catch (error) {
|
|
1422
|
+
// 读回异常:发布请求本身已成功(wireCall errcode 0 才走到这里),验证失败 ≠ 未发布。
|
|
1423
|
+
return {
|
|
1424
|
+
publishedVerified: false,
|
|
1425
|
+
latestPublished: false,
|
|
1426
|
+
detail: {
|
|
1427
|
+
verifyWire,
|
|
1428
|
+
verifyFailed: "read-error",
|
|
1429
|
+
verifyError: error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200),
|
|
1430
|
+
verifyNote: "发布请求已成功(performed.errcode 0),但发布后读回验证读失败——不要据此重复 save(会造新记录);用 rule.list 复核 latestPublished/ruleVersion",
|
|
1431
|
+
nextCommand: `omc call rule.list --args '${JSON.stringify({ schemaCode })}' --env <env>(读 latestPublished/ruleVersion 复核发布)`,
|
|
1432
|
+
},
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const publishedRow = rows.find((row) => row.code === ruleCode && row.latestPublished === true);
|
|
1436
|
+
if (publishedRow !== undefined) {
|
|
1437
|
+
const listedVersion = typeof publishedRow.ruleVersion === "number" ? publishedRow.ruleVersion : undefined;
|
|
1438
|
+
const version = listedVersion ?? responseVersion ?? null;
|
|
1439
|
+
return {
|
|
1440
|
+
publishedVerified: true,
|
|
1441
|
+
verifiedBy: "published-list",
|
|
1442
|
+
ruleVersion: version,
|
|
1443
|
+
latestPublished: true,
|
|
1444
|
+
detail: {
|
|
1445
|
+
verifyWire,
|
|
1446
|
+
...(listedVersion !== undefined && responseVersion !== undefined && listedVersion !== responseVersion
|
|
1447
|
+
? { versionMismatchNote: `列表验证版本 ${listedVersion} ≠ 发布响应版本 ${responseVersion}(以列表为准——发布响应是 DRAFT 行模型 + facade 回填的版本号)` }
|
|
1448
|
+
: {}),
|
|
1449
|
+
},
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
if (responseVersion !== undefined) {
|
|
1453
|
+
// 列表读不到但发布响应带了新版本号:runtime 面按 DRAFT 行 enabled 过滤
|
|
1454
|
+
// (草稿未启用则 PUBLISH 行不出现),或 8.1 族 runtime 面缺席下探到的 app 面
|
|
1455
|
+
// 只回 DRAFT 行——发布本身有服务端同步证据。
|
|
1456
|
+
return {
|
|
1457
|
+
publishedVerified: true,
|
|
1458
|
+
verifiedBy: "publish-response",
|
|
1459
|
+
ruleVersion: responseVersion,
|
|
1460
|
+
latestPublished: false,
|
|
1461
|
+
detail: {
|
|
1462
|
+
verifyWire,
|
|
1463
|
+
latestPublishedUncheckedNote: "发布响应已带新 ruleVersion(facade 同步铸 PUBLISH 行的证据),但列表面读不到 latestPublished 行——runtime 面按 DRAFT 行 enabled 过滤(未启用则不显示)或本版本族走的是 app/DRAFT 面。latestPublished 未经列表证实,故不给该键",
|
|
1464
|
+
},
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
return {
|
|
1468
|
+
publishedVerified: false,
|
|
1469
|
+
latestPublished: false,
|
|
1470
|
+
detail: {
|
|
1471
|
+
verifyWire,
|
|
1472
|
+
verifyFailed: "not-visible",
|
|
1473
|
+
verifyNote: "发布请求已发出,但列表面与发布响应都没给出可验证的版本证据(可能仍在传播或该版本族的发布响应不带 ruleVersion)——不要据此重复 save;用 rule.list 复核",
|
|
1474
|
+
nextCommand: `omc call rule.list --args '${JSON.stringify({ schemaCode })}' --env <env>(读 latestPublished/ruleVersion 复核发布)`,
|
|
1475
|
+
},
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1411
1478
|
export async function executeRuleSaveWrite(session, args) {
|
|
1412
1479
|
// 与 dry-run 同源:同一套只读门先跑,然后才写。
|
|
1413
1480
|
const { lintWarnings, lintHazards, bizMethodChecks, existing, customTriggerApplied, isPresetRule, bizRuleType, nodeJson, routeJson, schedulerField, schedulerSetting, nodes, routesSource, emptyMappings, preservedDesignerText, designerTextOverwritten, mappingFieldChecks, absentMappingFields, } = await lintRuleSaveWrite(session, args);
|
|
@@ -1461,6 +1528,14 @@ export async function executeRuleSaveWrite(session, args) {
|
|
|
1461
1528
|
const currentLintWarnings = lintWarnings.filter((warning) => warning.nodeCode === undefined || graphNodeCodes.has(warning.nodeCode) || warning.code === "rule-graph-system-node-tool-owned");
|
|
1462
1529
|
if (args.publish === true) {
|
|
1463
1530
|
const row = await currentRow();
|
|
1531
|
+
// Publish-response evidence (r86 issue 14): the platform's publish answer is
|
|
1532
|
+
// itself synchronous proof — the facade mints the PUBLISH row inside a lock
|
|
1533
|
+
// (templateType=PUBLISH, latestPublished=TRUE, ruleVersion=max+1, status
|
|
1534
|
+
// ENABLED) and RETURNS the model with the minted ruleVersion
|
|
1535
|
+
// (BusinessRuleFacadeImpl.publishBusinessRule:337-352 →
|
|
1536
|
+
// BusinessRuleServiceImpl.publish:483-536). Keep the body; verification
|
|
1537
|
+
// falls back to it when the list face cannot show the row.
|
|
1538
|
+
let publishResponse = null;
|
|
1464
1539
|
if (row?.id) {
|
|
1465
1540
|
// Publish the FULL model, not the list-projection row: `list_by_schemacode`
|
|
1466
1541
|
// omits `node`/`route`/`schedulerSetting`, so publishing it drops the
|
|
@@ -1468,7 +1543,8 @@ export async function executeRuleSaveWrite(session, args) {
|
|
|
1468
1543
|
// the authoritative `businessrule/get?id` model (same as rule.get/enable).
|
|
1469
1544
|
const full = (await wireCall(session, { path: ENDPOINTS.businessRuleGet, query: { id: String(row.id) } })).data;
|
|
1470
1545
|
try {
|
|
1471
|
-
await wireCall(session, { path: ENDPOINTS.businessRulePublish, method: "POST", body: full ?? row });
|
|
1546
|
+
const publishedCall = await wireCall(session, { path: ENDPOINTS.businessRulePublish, method: "POST", body: full ?? row });
|
|
1547
|
+
publishResponse = (publishedCall.data ?? null);
|
|
1472
1548
|
}
|
|
1473
1549
|
catch (error) {
|
|
1474
1550
|
if (error instanceof WireError && error.errcode === RULE_SELF_CHECK_ERRCODE) {
|
|
@@ -1485,15 +1561,20 @@ export async function executeRuleSaveWrite(session, args) {
|
|
|
1485
1561
|
throw error;
|
|
1486
1562
|
}
|
|
1487
1563
|
}
|
|
1488
|
-
|
|
1489
|
-
//
|
|
1490
|
-
//
|
|
1491
|
-
//
|
|
1492
|
-
//
|
|
1493
|
-
//
|
|
1494
|
-
//
|
|
1495
|
-
//
|
|
1496
|
-
|
|
1564
|
+
// r86(retro issue 14):发布后必须用「能看见 PUBLISH 行的面」验证。旧的
|
|
1565
|
+
// currentRow() 走 app 面 list_by_schemacode,而平台用 **DRAFT 行**服务它
|
|
1566
|
+
// (BusinessRuleController.list → listViewsBySchemaCode →
|
|
1567
|
+
// listDraftBySchemaCode,BusinessRuleFacadeImpl.java:143-150 /
|
|
1568
|
+
// BusinessRuleServiceImpl.java:175-177)——DRAFT 行结构上不可能携带
|
|
1569
|
+
// latestPublished,于是发布成功后回执仍报 latestPublished:false /
|
|
1570
|
+
// ruleVersion:null(retro 实证:紧接着 rule.list 却读到 latestPublished:true、
|
|
1571
|
+
// ruleVersion:4),agent 以为没发布成功而重复 save,每次都铸造新规则记录 ID。
|
|
1572
|
+
// runtime 面 list_by_schemacode 才投影 PUBLISH 行
|
|
1573
|
+
// (BusinessRuleRuntimeController.java:71-77 → listLatestRulesBySchemaCode),
|
|
1574
|
+
// 与 rule.list 同源;发布后经它读回验证(+1 wire),列表读不到时回落发布
|
|
1575
|
+
// 响应体的 ruleVersion。绝不把「验证不了」谎报成 latestPublished:false。
|
|
1576
|
+
const verification = await verifyRulePublish(session, args.schemaCode, args.ruleCode, publishResponse);
|
|
1577
|
+
const published = verification.publishedVerified;
|
|
1497
1578
|
const effectiveNow = published && enabled;
|
|
1498
1579
|
const effectiveBasis = effectiveNow ? "本次图已发布且规则 enabled:true,当前运行面可用" : "本次图未同时满足 publish + enabled;仍需 rule.enable 才是当前运行图";
|
|
1499
1580
|
const previousRuleVersion = existing?.ruleVersion;
|
|
@@ -1502,8 +1583,16 @@ export async function executeRuleSaveWrite(session, args) {
|
|
|
1502
1583
|
readback: {
|
|
1503
1584
|
rulePresent: true,
|
|
1504
1585
|
published,
|
|
1586
|
+
// r86 issue 14:publishedVerified/verifiedBy 是发布成败的判定键;ruleVersion
|
|
1587
|
+
// 只报验证过的版本(列表验证值优先,回落发布响应值)。latestPublished 仅在
|
|
1588
|
+
// 列表验证成立时出现,否则 latestPublishedUnchecked——不再谎报 false。
|
|
1589
|
+
publishedVerified: verification.publishedVerified,
|
|
1590
|
+
...(verification.verifiedBy !== undefined ? { verifiedBy: verification.verifiedBy } : {}),
|
|
1591
|
+
...(verification.ruleVersion !== undefined ? { ruleVersion: verification.ruleVersion } : {}),
|
|
1592
|
+
...(verification.latestPublished === true ? { latestPublished: true } : { latestPublishedUnchecked: true }),
|
|
1593
|
+
...verification.detail,
|
|
1505
1594
|
enabled,
|
|
1506
|
-
status:
|
|
1595
|
+
status: row?.status,
|
|
1507
1596
|
...(currentLintWarnings.length > 0 ? { lintWarnings: currentLintWarnings } : {}),
|
|
1508
1597
|
...(lintHazards.length > 0 ? { lintHazards } : {}),
|
|
1509
1598
|
customTrigger: customTriggerApplied,
|
|
@@ -1516,15 +1605,16 @@ export async function executeRuleSaveWrite(session, args) {
|
|
|
1516
1605
|
executableRequires: "rule.enable",
|
|
1517
1606
|
executableHint: "publish 只写 PUBLISH 行,不等于可执行:运行时按 DRAFT 行的 enabled + status 判定(BusinessRuleTableImpl#getExecutableBySchemaCodeAndCode),而 list 面显示的是 PUBLISH 行。用 rule.run / domain_service_runtime 前先 rule.enable(它 publish 后再调平台 /enable,把 DRAFT 行 status 置 ENABLED)。",
|
|
1518
1607
|
...(customTriggerApplied ? {} : { customTriggerHint: "图中没有 CUSTOM_NODE 触发节点:门户按钮/流程按钮调用该规则时会按各自的触发面执行;rule.run 也能执行(它不要求 CUSTOM_NODE),执行时以 BUTTON 触发类型跑同一张图" }),
|
|
1519
|
-
id:
|
|
1520
|
-
ruleVersion: effective?.ruleVersion,
|
|
1608
|
+
id: row?.id ?? undefined,
|
|
1521
1609
|
previousRuleVersion,
|
|
1522
1610
|
effectiveNow,
|
|
1523
1611
|
effectiveBasis,
|
|
1524
|
-
latestPublished: effective?.latestPublished,
|
|
1525
1612
|
...r85Readback,
|
|
1526
1613
|
...(await modelWorkflowDispatchWarning(session, args.schemaCode)),
|
|
1527
1614
|
...(existing?.id ? { versionNote } : {}),
|
|
1615
|
+
// r86 issue 14:防重复保存警示——看错 latestPublished 而重复 save 的代价是
|
|
1616
|
+
// 每次都铸造新规则记录 ID(同 code 旧行仍可读,见 versionNote)。
|
|
1617
|
+
repeatSaveWarning: `发布是否成功看 publishedVerified(本次 ${verification.publishedVerified ? `verifiedBy:${verification.verifiedBy}` : "未验证通过"});同一 ruleCode 每次保存都会造新规则记录 ID,不要因 latestPublished 缺席/未验证而重复 save`,
|
|
1528
1618
|
...(enabled ? {} : { nextAction: "rule.enable(businessrule/publish + businessrule/enable 两步)后规则才会分发并对流程/按钮可见;publish:true 只写入版本" }),
|
|
1529
1619
|
},
|
|
1530
1620
|
};
|
package/dist/session.js
CHANGED
|
@@ -21,6 +21,8 @@ export class CloudPivotSession {
|
|
|
21
21
|
tokenCache;
|
|
22
22
|
loginResult;
|
|
23
23
|
version;
|
|
24
|
+
/** r86(retro issue 17):原始版本串("AI-Platform-v1.1.25" 这类含产品线前缀的完整值)。 */
|
|
25
|
+
rawVersion;
|
|
24
26
|
/**
|
|
25
27
|
* Non-fatal login caveats (e.g. the `client` blob in system/config was
|
|
26
28
|
* absent or unreadable, so the token request carried no client_secret).
|
|
@@ -67,6 +69,8 @@ export class CloudPivotSession {
|
|
|
67
69
|
};
|
|
68
70
|
if (cached.version !== undefined) {
|
|
69
71
|
this.version = cached.version;
|
|
72
|
+
if (cached.rawVersion !== undefined)
|
|
73
|
+
this.rawVersion = cached.rawVersion;
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
72
76
|
// Legacy cache written while version evidence was unavailable: probe the
|
|
@@ -77,6 +81,7 @@ export class CloudPivotSession {
|
|
|
77
81
|
.fetchCloudPivotSystemConfig(this.profile.baseUrl, undefined, fetch, core.cloudPivotTenantHeaders(this.profile.engineCode))
|
|
78
82
|
.catch(() => undefined);
|
|
79
83
|
this.version = detectVersion(systemConfig);
|
|
84
|
+
this.rawVersion = detectRawVersion(systemConfig);
|
|
80
85
|
if (this.version !== undefined) {
|
|
81
86
|
this.tokenCache?.save({
|
|
82
87
|
token: cached.token,
|
|
@@ -84,6 +89,7 @@ export class CloudPivotSession {
|
|
|
84
89
|
administrator: cached.administrator,
|
|
85
90
|
...(cached.accountIdentity !== undefined ? { accountIdentity: cached.accountIdentity } : {}),
|
|
86
91
|
version: this.version,
|
|
92
|
+
...(this.rawVersion !== undefined ? { rawVersion: this.rawVersion } : {}),
|
|
87
93
|
});
|
|
88
94
|
}
|
|
89
95
|
}
|
|
@@ -110,12 +116,14 @@ export class CloudPivotSession {
|
|
|
110
116
|
});
|
|
111
117
|
this.loginNotesValue = authenticator.loginNotes();
|
|
112
118
|
this.version = detectVersion(systemConfig);
|
|
119
|
+
this.rawVersion = detectRawVersion(systemConfig);
|
|
113
120
|
this.tokenCache?.save({
|
|
114
121
|
token: this.loginResult.token,
|
|
115
122
|
enterpriseId: this.loginResult.enterpriseId,
|
|
116
123
|
administrator: this.loginResult.administrator,
|
|
117
124
|
...(this.loginResult.accountIdentity !== undefined ? { accountIdentity: this.loginResult.accountIdentity } : {}),
|
|
118
125
|
...(this.version !== undefined ? { version: this.version } : {}),
|
|
126
|
+
...(this.rawVersion !== undefined ? { rawVersion: this.rawVersion } : {}),
|
|
119
127
|
});
|
|
120
128
|
return this.loginResult;
|
|
121
129
|
}
|
|
@@ -123,6 +131,10 @@ export class CloudPivotSession {
|
|
|
123
131
|
detectedVersion() {
|
|
124
132
|
return this.version;
|
|
125
133
|
}
|
|
134
|
+
/** r86(retro issue 17):原始版本串(含产品线前缀);无证据返回 undefined。 */
|
|
135
|
+
rawSystemVersion() {
|
|
136
|
+
return this.rawVersion;
|
|
137
|
+
}
|
|
126
138
|
/** Non-fatal login caveats; empty when the login was fully nominal. */
|
|
127
139
|
loginNotes() {
|
|
128
140
|
return this.loginNotesValue;
|
|
@@ -176,6 +188,7 @@ export class CloudPivotSession {
|
|
|
176
188
|
return first;
|
|
177
189
|
this.loginResult = undefined;
|
|
178
190
|
this.version = undefined;
|
|
191
|
+
this.rawVersion = undefined;
|
|
179
192
|
// The invalidated token must not be re-loaded by the re-login below.
|
|
180
193
|
this.tokenCache?.clear();
|
|
181
194
|
return this.send(input);
|
|
@@ -226,6 +239,20 @@ function detectVersion(systemConfig) {
|
|
|
226
239
|
}
|
|
227
240
|
return undefined;
|
|
228
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* r86(retro issue 17):原始版本键值(如 "AI-Platform-v1.1.25")——detectVersion
|
|
244
|
+
* 只留点号数字段,产品线前缀被丢弃;productVersion 面需要原串(同一 key 优先序)。
|
|
245
|
+
*/
|
|
246
|
+
function detectRawVersion(systemConfig) {
|
|
247
|
+
if (!systemConfig)
|
|
248
|
+
return undefined;
|
|
249
|
+
for (const key of ["version", "sysVersion", "systemVersion", "productVersion", "serverVersion"]) {
|
|
250
|
+
const value = systemConfig[key];
|
|
251
|
+
if (typeof value === "string" && value.trim().length > 0)
|
|
252
|
+
return value.trim();
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
229
256
|
/**
|
|
230
257
|
* A request that produced no response within the timeout. Without this, a
|
|
231
258
|
* stalled CloudPivot (e.g. mid-restart) would leave a write hanging forever and
|
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.84",
|
|
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.84",
|
|
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.84"
|
|
78
78
|
}
|
|
79
79
|
}
|