@stalfh233/omc-cli 0.6.84 → 0.6.85
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 +5 -3
- package/coverage/m1-coverage-manifest-v1.json +28 -0
- package/dist/batch-call.js +1 -0
- package/dist/call.js +4 -1
- package/dist/capability-overview.js +2 -2
- package/dist/cli.js +21 -20
- package/dist/concurrency.js +165 -0
- package/dist/duration.js +73 -0
- package/dist/goal-routes.js +26 -1
- package/dist/governed-execution.js +5 -0
- package/dist/graph.js +5 -26
- package/dist/intent/capabilities/datarule.js +1 -1
- package/dist/intent/plan-apply.js +5 -1
- package/dist/journal.js +14 -1
- package/dist/lanes/apply-changes.js +49 -1
- package/dist/lanes/businessrule.js +63 -34
- package/dist/lanes/config-diff.js +477 -0
- package/dist/lanes/form.js +2 -2
- package/dist/lanes/workflow-contract.js +17 -0
- package/dist/lanes/workflow-coverage.js +11 -0
- package/dist/lanes/workflow.js +47 -22
- package/dist/package.js +5 -2
- package/dist/read-shapes.js +7 -0
- package/dist/rollback-spec.js +130 -32
- package/dist/rollback.js +67 -6
- package/dist/script.js +1 -0
- package/dist/tool-search.js +3 -0
- package/dist/tools.js +9 -0
- package/dist/write-audit.js +43 -0
- package/dist/write.js +10 -1
- package/docs/omc-introduction.md +2 -2
- package/package.json +3 -3
- package/skills/omc-capabilities.md +2 -2
package/dist/lanes/workflow.js
CHANGED
|
@@ -8,6 +8,7 @@ import { writeTool } from "../write.js";
|
|
|
8
8
|
import { registerPackageTool } from "../package-tool.js";
|
|
9
9
|
import { writeSummary } from "../human-summary.js";
|
|
10
10
|
import { defineTool, ToolInputError } from "../tool-types.js";
|
|
11
|
+
import { DEFAULT_SCAN_CONCURRENCY, mapWithConcurrency } from "../concurrency.js";
|
|
11
12
|
import { wireCall, wireRows, WireError } from "../wire.js";
|
|
12
13
|
import { diagnoseInstanceActivity, getInstanceBaseInfo, listInstanceActivities, listWorkItemsByParticipant, resolveBizObjectIdByInstance, searchWorkItems, wireString } from "../workflow-support.js";
|
|
13
14
|
import { readSchemaFormButtons } from "../form-support.js";
|
|
@@ -2175,7 +2176,7 @@ async function mergedTemplateBody(session, schemaCode, code, template, merge = f
|
|
|
2175
2176
|
* readback must treat them as "no workflow" so workflow.create can proceed
|
|
2176
2177
|
* instead of stopping at the probe's 401001.
|
|
2177
2178
|
*/
|
|
2178
|
-
function isWorkflowAbsent(error) {
|
|
2179
|
+
export function isWorkflowAbsent(error) {
|
|
2179
2180
|
return error instanceof WireError && error.kind === "business" && error.errcode === 401001;
|
|
2180
2181
|
}
|
|
2181
2182
|
/**
|
|
@@ -2183,7 +2184,7 @@ function isWorkflowAbsent(error) {
|
|
|
2183
2184
|
* workflow it backs via the platform link (workflow/isworkflow →
|
|
2184
2185
|
* workflow/getWorkflow); return null when the model has no workflow.
|
|
2185
2186
|
*/
|
|
2186
|
-
async function resolveWorkflowArg(session, args) {
|
|
2187
|
+
export async function resolveWorkflowArg(session, args) {
|
|
2187
2188
|
if (args.workflowCode)
|
|
2188
2189
|
return args.workflowCode;
|
|
2189
2190
|
if (!args.schemaCode)
|
|
@@ -2228,7 +2229,7 @@ async function getWorkflowHeaderOrNull(session, workflowCode) {
|
|
|
2228
2229
|
throw error;
|
|
2229
2230
|
}
|
|
2230
2231
|
}
|
|
2231
|
-
async function getWorkflowDraftOrNull(session, workflowCode) {
|
|
2232
|
+
export async function getWorkflowDraftOrNull(session, workflowCode) {
|
|
2232
2233
|
try {
|
|
2233
2234
|
return ((await wireCall(session, { path: ENDPOINTS.workflowGetDraft, query: { workflowCode } })).data ?? null);
|
|
2234
2235
|
}
|
|
@@ -2448,14 +2449,31 @@ export function workflowCompactProjection(result) {
|
|
|
2448
2449
|
*/
|
|
2449
2450
|
function effectiveActivityName(activity) {
|
|
2450
2451
|
const i18n = activity.name_i18n;
|
|
2451
|
-
|
|
2452
|
-
|
|
2452
|
+
// The rename carrier is normally a locale MAP, but some platform families
|
|
2453
|
+
// answer it as a JSON STRING of that map (observed on a 1.1.x-compat
|
|
2454
|
+
// endpoint: i18nMessage gets the new name, name_i18n comes back stringified).
|
|
2455
|
+
// Without parsing it, a renamed node keeps reading its first-created
|
|
2456
|
+
// activityName and every draft↔published diff would miss the rename.
|
|
2457
|
+
const map = typeof i18n === "string" ? parseLocalizedMap(i18n) : i18n && typeof i18n === "object" ? i18n : undefined;
|
|
2458
|
+
if (map !== undefined) {
|
|
2453
2459
|
const localized = map.zh ?? map.zh_TW ?? map.en;
|
|
2454
2460
|
if (localized !== undefined && String(localized) !== "")
|
|
2455
2461
|
return String(localized);
|
|
2456
2462
|
}
|
|
2457
2463
|
return (activity.activityName ?? activity.i18nMessage ?? null);
|
|
2458
2464
|
}
|
|
2465
|
+
function parseLocalizedMap(value) {
|
|
2466
|
+
const trimmed = value.trim();
|
|
2467
|
+
if (!trimmed.startsWith("{"))
|
|
2468
|
+
return undefined;
|
|
2469
|
+
try {
|
|
2470
|
+
const parsed = JSON.parse(trimmed);
|
|
2471
|
+
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : undefined;
|
|
2472
|
+
}
|
|
2473
|
+
catch {
|
|
2474
|
+
return undefined;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2459
2477
|
/**
|
|
2460
2478
|
* A workflow event handler (start/cancel/activate/end) binds a business rule by
|
|
2461
2479
|
* CODE. The platform's designer rule picker only offers CUSTOM rules — the
|
|
@@ -2673,32 +2691,36 @@ export function registerWorkflowLane(tools) {
|
|
|
2673
2691
|
}
|
|
2674
2692
|
const capped = totalModels > WORKFLOW_LIST_MODEL_CAP;
|
|
2675
2693
|
const scanRows = capped ? modelRows.slice(0, WORKFLOW_LIST_MODEL_CAP) : modelRows;
|
|
2694
|
+
// R88 提案 #2:模型级并发扫描(默认 4,direct-handoff 信号量)。回执按
|
|
2695
|
+
// scanRows 原序重组——与串行基线逐字段一致,并发完成顺序不抖动输出;
|
|
2696
|
+
// 单模型读失败仍落 readFailed 行(partial 语义不变);限流类错误一次
|
|
2697
|
+
// 抖动退避重试,仍失败把后续窗口降到 2(wire.concurrency 如实标注)。
|
|
2698
|
+
const scan = await mapWithConcurrency(scanRows, DEFAULT_SCAN_CONCURRENCY, (row) => scanModelWorkflowBindings(session, String(row.code)));
|
|
2676
2699
|
const workflows = [];
|
|
2677
2700
|
let withWorkflow = 0;
|
|
2678
2701
|
let publishedCount = 0;
|
|
2679
2702
|
let absentCount = 0;
|
|
2680
2703
|
let readFailures = 0;
|
|
2681
|
-
|
|
2682
|
-
const modelCode = String(
|
|
2683
|
-
|
|
2684
|
-
const face = await scanModelWorkflowBindings(session, modelCode);
|
|
2685
|
-
if (face === null) {
|
|
2686
|
-
absentCount += 1;
|
|
2687
|
-
workflows.push({ modelCode, workflowCode: null, exists: false, published: false, ruleBindingCount: 0 });
|
|
2688
|
-
continue;
|
|
2689
|
-
}
|
|
2690
|
-
withWorkflow += 1;
|
|
2691
|
-
if (face.published)
|
|
2692
|
-
publishedCount += 1;
|
|
2693
|
-
workflows.push({ modelCode, workflowCode: face.workflowCode, exists: true, published: face.published, ruleBindingCount: face.ruleBindingCount });
|
|
2694
|
-
}
|
|
2695
|
-
catch {
|
|
2704
|
+
scan.outcomes.forEach((outcome, index) => {
|
|
2705
|
+
const modelCode = String(scanRows[index].code);
|
|
2706
|
+
if (!outcome.ok) {
|
|
2696
2707
|
// 单模型读失败不中断整轮清单;行级 readFailed 标注,不让一次失败
|
|
2697
2708
|
// 变成整面错误(同 participantSearch 的容错口径)。
|
|
2698
2709
|
readFailures += 1;
|
|
2699
2710
|
workflows.push({ modelCode, workflowCode: null, exists: null, published: null, ruleBindingCount: null, readFailed: true });
|
|
2711
|
+
return;
|
|
2700
2712
|
}
|
|
2701
|
-
|
|
2713
|
+
const face = outcome.value;
|
|
2714
|
+
if (face === null) {
|
|
2715
|
+
absentCount += 1;
|
|
2716
|
+
workflows.push({ modelCode, workflowCode: null, exists: false, published: false, ruleBindingCount: 0 });
|
|
2717
|
+
return;
|
|
2718
|
+
}
|
|
2719
|
+
withWorkflow += 1;
|
|
2720
|
+
if (face.published)
|
|
2721
|
+
publishedCount += 1;
|
|
2722
|
+
workflows.push({ modelCode, workflowCode: face.workflowCode, exists: true, published: face.published, ruleBindingCount: face.ruleBindingCount });
|
|
2723
|
+
});
|
|
2702
2724
|
return {
|
|
2703
2725
|
applicationResolution: { ...applicationResolutionOf(scope), models: totalModels },
|
|
2704
2726
|
modelsCount: totalModels,
|
|
@@ -2708,7 +2730,10 @@ export function registerWorkflowLane(tools) {
|
|
|
2708
2730
|
absentCount,
|
|
2709
2731
|
...(readFailures > 0 ? { readFailures } : {}),
|
|
2710
2732
|
workflows,
|
|
2711
|
-
wire: {
|
|
2733
|
+
wire: {
|
|
2734
|
+
plan: "1 应用树 + 每模型 isworkflow(无流程即止,1 wire)→ 有流程再 getWorkflow + get_published(共 3 wire)",
|
|
2735
|
+
concurrency: scan.stats,
|
|
2736
|
+
},
|
|
2712
2737
|
...(capped
|
|
2713
2738
|
? {
|
|
2714
2739
|
partial: true,
|
package/dist/package.js
CHANGED
|
@@ -19,6 +19,7 @@ export async function executePackage(ctx, plan, coverage, args, execute) {
|
|
|
19
19
|
confirmProduction: args.confirmProduction,
|
|
20
20
|
dryRun: args.dryRun,
|
|
21
21
|
capability: args.capability,
|
|
22
|
+
...(ctx.writeAudit?.reason !== undefined ? { reason: ctx.writeAudit.reason } : {}),
|
|
22
23
|
coverage: claims,
|
|
23
24
|
plan: () => plan,
|
|
24
25
|
// A package dry-run is a TRUE preview: the environment is resolved and the
|
|
@@ -33,7 +34,7 @@ export async function executePackage(ctx, plan, coverage, args, execute) {
|
|
|
33
34
|
});
|
|
34
35
|
if (outcome.kind === "settled")
|
|
35
36
|
return outcome.result;
|
|
36
|
-
const { session, plan: boundPlan, productionConfirmed } = outcome.admission;
|
|
37
|
+
const { session, plan: boundPlan, productionConfirmed, reason } = outcome.admission;
|
|
37
38
|
return ctx.lease.run(session.environmentName, `${plan.actions[0]?.tool ?? "package"}:${randomUUID().slice(0, 8)}`, async () => {
|
|
38
39
|
const executed = await execute(session);
|
|
39
40
|
if (isPackageStopOutcome(executed)) {
|
|
@@ -45,6 +46,7 @@ export async function executePackage(ctx, plan, coverage, args, execute) {
|
|
|
45
46
|
failedStep: executed.failedStep,
|
|
46
47
|
stop: executed.envelope,
|
|
47
48
|
...(productionConfirmed ? { productionConfirmed: true } : {}),
|
|
49
|
+
...(reason !== undefined ? { reason } : {}),
|
|
48
50
|
deliveryState: "STOPPED",
|
|
49
51
|
recordedAt: new Date().toISOString(),
|
|
50
52
|
};
|
|
@@ -63,11 +65,12 @@ export async function executePackage(ctx, plan, coverage, args, execute) {
|
|
|
63
65
|
steps,
|
|
64
66
|
readback,
|
|
65
67
|
...(productionConfirmed ? { productionConfirmed: true } : {}),
|
|
68
|
+
...(reason !== undefined ? { reason } : {}),
|
|
66
69
|
deliveryState: "DELIVERED",
|
|
67
70
|
recordedAt: new Date().toISOString(),
|
|
68
71
|
};
|
|
69
72
|
writeArtifact(ctx, `package-${randomUUID().slice(0, 8)}.json`, artifact);
|
|
70
|
-
return { status: "ok", deliveryState: "DELIVERED", steps, readback, ...(productionConfirmed ? { productionConfirmed: true } : {}), ...(summary !== undefined ? { summary } : {}), artifactFingerprint: sha256(artifact) };
|
|
73
|
+
return { status: "ok", deliveryState: "DELIVERED", steps, readback, ...(productionConfirmed ? { productionConfirmed: true } : {}), ...(reason !== undefined ? { reason } : {}), ...(summary !== undefined ? { summary } : {}), artifactFingerprint: sha256(artifact) };
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
//# sourceMappingURL=package.js.map
|
package/dist/read-shapes.js
CHANGED
|
@@ -135,6 +135,13 @@ const READ_SHAPES = {
|
|
|
135
135
|
keys: ["status", "workflowCode", "exists", "workflowSummary:{workflowCode,templateType,activities:array<{index,code,type,name,bizActions?:{<nodeEvent>:[ruleCode]},systemBizActions?:{bizActionType,ruleCodes:[code]}}>,edges:array<{from,to}>,ruleBindings:array<{...}>,nodeRuleBindings?,systemRuleBindings?,ruleBindingCount,originateActivity:{code,type,name,participant}}", "activities:array<{code,name,type,bizActions?,systemBizActions?}>(投影)", "propertyPermissionsCount", "version", "summaryHint", "truncatedKeys?", "omittedKeys?", "truncated?", "data?(外置时 null,完整模板在 detailArtifactId)", "omittedShape?", "omittedNote?", "environmentFingerprint", "detailArtifactId?", "detailSha256?", "fetch?"],
|
|
136
136
|
notes: ["与 workflow.get_published 同形(少了 published 键);节点绑定看 activities[].bizActions、系统活动顶层看 systemBizActions;templateType=DRAFT;深层字段投影写到叶子,完整模板在 data/detailArtifactId"],
|
|
137
137
|
},
|
|
138
|
+
// R88 #1:双面排查面。returnsFace 只显 notes 首条——教学并进首条。
|
|
139
|
+
"config.diff": {
|
|
140
|
+
keys: ["domain:'workflow'|'form'", "target:{schemaCode,workflowCode?|sheetCode?}", "present?:boolean(form:表单槽位是否存在;false 的面缺语义看 verdict=absent)", "draft:{present,controlCount?(form)}", "published:{present,controlCount?(form)}", "changed:boolean|null(null=一面缺失不可比,配 verdict)", "verdict?:'draft-only'|'published-only'|'absent'|'both-empty'", "changes:array<{path,before,after}>(≤limit;before=发布面,after=草稿面)", "totalKnown", "truncated", "remaining?", "shapeWarnings?", "bindingFaces?:{ruleBindings,nodeRuleBindings,systemRuleBindings}(workflow)", "deepScan?:{changed,totalKnown,samplePaths?}(workflow)", "diffArtifactId?", "diffSha256?", "fetch?", "hint"],
|
|
141
|
+
notes: [
|
|
142
|
+
"changed:null ≠ 空 diff——一面缺失时看 verdict(draft-only=草稿全未发布);workflow 路径形如 activities[+code]/edges[A->B]/nodeRuleBindings[Activity2.endActivity].ruleCodes[+X],form 路径前缀 view/attributes/html/actions(按控件 key 对齐,不文本 diff);totalKnown 是精确全量计数,全量差异与双面快照在 diffArtifactId",
|
|
143
|
+
],
|
|
144
|
+
},
|
|
138
145
|
"rule.list": {
|
|
139
146
|
keys: ["rules:array<{code,name,enabled,status,ruleVersion,defaultRule,preset,mappings?,mappingsUnavailable?}>", "rulesCount", "modelPresent", "source", "executableHint", "mappingsWireNote?", "schemaCodes?/modelsCount?/models?:array<每模型同单模型回执>/partial?/failed?:array<{schemaCode,code,message}>/absentModels?"],
|
|
140
147
|
notes: [
|
package/dist/rollback-spec.js
CHANGED
|
@@ -11,28 +11,66 @@ function arrayEntryKey(entry) {
|
|
|
11
11
|
}
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
|
+
/** Entries cap; the walk itself is uncapped so totalKnown stays exact. */
|
|
15
|
+
const SHAPE_WARNING_LIMIT = 8;
|
|
14
16
|
/**
|
|
15
|
-
* Field-level deep diff
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Field-level deep diff. Arrays of objects with a business key
|
|
18
|
+
* (`code`/`id`/…) are aligned by that key; unkeyed arrays are compared
|
|
19
|
+
* sequentially AND report tail additions/deletions (the old face only walked
|
|
20
|
+
* the shared length, so a trailing add/del was silently invisible). Duplicate
|
|
21
|
+
* or missing business keys and unparseable JSON-looking strings produce
|
|
22
|
+
* `shapeWarnings` instead of a silent index alignment.
|
|
19
23
|
*/
|
|
20
|
-
export function deepDiff(before, current,
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
export function deepDiff(before, current, options = {}) {
|
|
25
|
+
// An EXPLICIT limit 0 means "counts only" (entries stay empty, totalKnown is
|
|
26
|
+
// still exact) — the coarse-coverage mode config.diff uses for its deep scan.
|
|
27
|
+
const rawLimit = options.limit ?? 40;
|
|
28
|
+
const limit = options.limit === 0 ? 0 : Number.isSafeInteger(rawLimit) && rawLimit > 0 ? rawLimit : 40;
|
|
29
|
+
const entries = [];
|
|
30
|
+
const warnings = [];
|
|
31
|
+
let totalKnown = 0;
|
|
32
|
+
let nonAdditionCount = 0;
|
|
33
|
+
const push = (entry) => {
|
|
34
|
+
// `undefined` is not a JSON value: a key set to undefined on one side is
|
|
35
|
+
// ABSENT, so it must read as the `<absent>` sentinel, never as a literal
|
|
36
|
+
// "current: undefined" ghost difference (JS objects can carry such keys;
|
|
37
|
+
// the wire's JSON round-trip cannot).
|
|
38
|
+
const normalized = {
|
|
39
|
+
path: entry.path,
|
|
40
|
+
before: entry.before === undefined ? "<absent>" : entry.before,
|
|
41
|
+
current: entry.current === undefined ? "<absent>" : entry.current,
|
|
42
|
+
};
|
|
43
|
+
if (normalized.before === "<absent>" && normalized.current === "<absent>")
|
|
23
44
|
return;
|
|
45
|
+
totalKnown += 1;
|
|
46
|
+
if (normalized.before !== "<absent>")
|
|
47
|
+
nonAdditionCount += 1;
|
|
48
|
+
if (entries.length < limit)
|
|
49
|
+
entries.push(normalized);
|
|
50
|
+
};
|
|
51
|
+
const warn = (warning) => {
|
|
52
|
+
warnings.push(warning);
|
|
53
|
+
};
|
|
54
|
+
const walk = (b, c, p) => {
|
|
24
55
|
if (b === null && c === null)
|
|
25
56
|
return;
|
|
26
57
|
const bothObject = b !== null && c !== null && typeof b === "object" && typeof c === "object";
|
|
27
58
|
if (!bothObject) {
|
|
28
59
|
if (b !== c && !(Number.isNaN(b) && Number.isNaN(c))) {
|
|
29
60
|
if (typeof b === "string" || typeof c === "string") {
|
|
30
|
-
const bp =
|
|
31
|
-
const cp =
|
|
61
|
+
const bp = jsonProbe(b);
|
|
62
|
+
const cp = jsonProbe(c);
|
|
32
63
|
if (bp.ok && cp.ok)
|
|
33
64
|
return walk(bp.value, cp.value, p);
|
|
65
|
+
// A string that LOOKS like structured JSON but does not parse is a
|
|
66
|
+
// shape problem worth naming: the raw-text comparison below may hide
|
|
67
|
+
// a semantically small break behind a large textual diff.
|
|
68
|
+
for (const probe of [bp, cp]) {
|
|
69
|
+
if (probe.looksLikeJson && !probe.ok)
|
|
70
|
+
warn({ path: p, kind: "unparseable-json-string", detail: `字符串以 {/[ 开头但 JSON 解析失败,按原文本比较(前 40 字符:${probe.head})` });
|
|
71
|
+
}
|
|
34
72
|
}
|
|
35
|
-
|
|
73
|
+
push({ path: p, before: b, current: c });
|
|
36
74
|
}
|
|
37
75
|
return;
|
|
38
76
|
}
|
|
@@ -40,52 +78,79 @@ export function deepDiff(before, current, path = "", limit = 40, acc = []) {
|
|
|
40
78
|
const cArr = Array.isArray(c);
|
|
41
79
|
if (bArr || cArr) {
|
|
42
80
|
if (!bArr || !cArr) {
|
|
43
|
-
|
|
81
|
+
push({ path: p, before: b, current: c });
|
|
44
82
|
return;
|
|
45
83
|
}
|
|
46
84
|
const bA = b;
|
|
47
85
|
const cA = c;
|
|
48
|
-
if (bA.length !== cA.length)
|
|
49
|
-
acc.push({ path: p, before: `<array×${bA.length}>`, current: `<array×${cA.length}>` });
|
|
50
86
|
const bKeys = bA.map(arrayEntryKey);
|
|
51
87
|
const cKeys = cA.map(arrayEntryKey);
|
|
52
|
-
const
|
|
53
|
-
|
|
88
|
+
const bDup = firstDuplicateKey(bKeys);
|
|
89
|
+
const cDup = firstDuplicateKey(cKeys);
|
|
90
|
+
// Only OBJECT rows are expected to carry a business key; a scalar array
|
|
91
|
+
// (["a","b"]) is legitimately keyed by index, so it never warns.
|
|
92
|
+
const bMissing = firstKeylessObjectRow(bA, bKeys);
|
|
93
|
+
const cMissing = firstKeylessObjectRow(cA, cKeys);
|
|
94
|
+
const canAlign = bMissing < 0 && cMissing < 0 && bA.every((_, i) => bKeys[i] !== undefined) && cA.every((_, i) => cKeys[i] !== undefined)
|
|
95
|
+
&& bDup === undefined && cDup === undefined;
|
|
54
96
|
if (canAlign) {
|
|
55
97
|
const bMap = new Map(bKeys.map((key, index) => [key, bA[index]]));
|
|
56
98
|
const cMap = new Map(cKeys.map((key, index) => [key, cA[index]]));
|
|
57
99
|
for (const key of new Set([...bMap.keys(), ...cMap.keys()])) {
|
|
58
|
-
if (acc.length >= limit)
|
|
59
|
-
return;
|
|
60
100
|
const inB = bMap.has(key);
|
|
61
101
|
const inC = cMap.has(key);
|
|
62
102
|
const short = key.includes(":") ? key.slice(key.indexOf(":") + 1) : key;
|
|
63
103
|
if (!inB) {
|
|
64
|
-
|
|
104
|
+
push({ path: `${p}[+${short}]`, before: "<absent>", current: cMap.get(key) });
|
|
65
105
|
continue;
|
|
66
106
|
}
|
|
67
107
|
if (!inC) {
|
|
68
|
-
|
|
108
|
+
push({ path: `${p}[-${short}]`, before: bMap.get(key), current: "<absent>" });
|
|
69
109
|
continue;
|
|
70
110
|
}
|
|
71
111
|
walk(bMap.get(key), cMap.get(key), `${p}[${short}]`);
|
|
72
112
|
}
|
|
73
113
|
return;
|
|
74
114
|
}
|
|
115
|
+
// Named fallback: key alignment is unavailable, so compare sequentially
|
|
116
|
+
// — and report the tail the shared length never covered. The warning
|
|
117
|
+
// names WHY alignment fell back, but only when this subtree actually
|
|
118
|
+
// produced differences: an unchanged keyless array (seqNoSetting rows,
|
|
119
|
+
// designer defaults) is compared correctly by position and warning on
|
|
120
|
+
// it would be pure noise for every clean diff.
|
|
121
|
+
const knownBefore = totalKnown;
|
|
122
|
+
const sequential = [];
|
|
123
|
+
if (bDup !== undefined)
|
|
124
|
+
sequential.push({ path: p, kind: "duplicate-array-key", detail: `before 侧业务键重复(${bDup})——键对齐不可用,退回按序比较` });
|
|
125
|
+
if (cDup !== undefined)
|
|
126
|
+
sequential.push({ path: p, kind: "duplicate-array-key", detail: `current 侧业务键重复(${cDup})——键对齐不可用,退回按序比较` });
|
|
127
|
+
if (bMissing >= 0)
|
|
128
|
+
sequential.push({ path: p, kind: "missing-array-key", detail: `before 侧第 ${bMissing} 行是没有业务键的对象行(code/id/propertyCode/activityCode/ruleCode/nodeCode 均缺)——退回按序比较` });
|
|
129
|
+
if (cMissing >= 0)
|
|
130
|
+
sequential.push({ path: p, kind: "missing-array-key", detail: `current 侧第 ${cMissing} 行是没有业务键的对象行(code/id/propertyCode/activityCode/ruleCode/nodeCode 均缺)——退回按序比较` });
|
|
75
131
|
const shared = Math.min(bA.length, cA.length);
|
|
76
|
-
for (let i = 0; i < shared
|
|
132
|
+
for (let i = 0; i < shared; i += 1)
|
|
77
133
|
walk(bA[i], cA[i], `${p}[${i}]`);
|
|
134
|
+
for (let i = shared; i < cA.length; i += 1)
|
|
135
|
+
push({ path: `${p}[+${i}]`, before: "<absent>", current: cA[i] });
|
|
136
|
+
for (let i = shared; i < bA.length; i += 1)
|
|
137
|
+
push({ path: `${p}[-${i}]`, before: bA[i], current: "<absent>" });
|
|
138
|
+
if (totalKnown > knownBefore)
|
|
139
|
+
for (const warning of sequential)
|
|
140
|
+
warn(warning);
|
|
78
141
|
return;
|
|
79
142
|
}
|
|
80
143
|
const bRec = b;
|
|
81
144
|
const cRec = c;
|
|
82
145
|
for (const key of new Set([...Object.keys(bRec), ...Object.keys(cRec)])) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const inB = key in bRec;
|
|
86
|
-
const inC = key in cRec;
|
|
146
|
+
// A key whose VALUE is undefined is absent for diff purposes (JSON has no
|
|
147
|
+
// undefined); only a real value counts as present.
|
|
148
|
+
const inB = key in bRec && bRec[key] !== undefined;
|
|
149
|
+
const inC = key in cRec && cRec[key] !== undefined;
|
|
150
|
+
if (!inB && !inC)
|
|
151
|
+
continue;
|
|
87
152
|
if (!inB || !inC) {
|
|
88
|
-
|
|
153
|
+
push({
|
|
89
154
|
path: joinPath(p, key),
|
|
90
155
|
before: inB ? bRec[key] : "<absent>",
|
|
91
156
|
current: inC ? cRec[key] : "<absent>",
|
|
@@ -95,8 +160,34 @@ export function deepDiff(before, current, path = "", limit = 40, acc = []) {
|
|
|
95
160
|
walk(bRec[key], cRec[key], joinPath(p, key));
|
|
96
161
|
}
|
|
97
162
|
};
|
|
98
|
-
walk(before, current, path);
|
|
99
|
-
return {
|
|
163
|
+
walk(before, current, options.path ?? "");
|
|
164
|
+
return {
|
|
165
|
+
entries,
|
|
166
|
+
totalKnown,
|
|
167
|
+
truncated: totalKnown > entries.length,
|
|
168
|
+
remaining: totalKnown - entries.length,
|
|
169
|
+
shapeWarnings: warnings.slice(0, SHAPE_WARNING_LIMIT),
|
|
170
|
+
...(warnings.length > SHAPE_WARNING_LIMIT ? { shapeWarningsOmitted: warnings.length - SHAPE_WARNING_LIMIT } : {}),
|
|
171
|
+
nonAdditionCount,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function firstDuplicateKey(keys) {
|
|
175
|
+
const seen = new Set();
|
|
176
|
+
for (const key of keys) {
|
|
177
|
+
if (key === undefined)
|
|
178
|
+
continue;
|
|
179
|
+
if (seen.has(key))
|
|
180
|
+
return key;
|
|
181
|
+
seen.add(key);
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
function isRecordish(value) {
|
|
186
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
187
|
+
}
|
|
188
|
+
/** Index of the first OBJECT row that carries no business key (-1 when none). */
|
|
189
|
+
function firstKeylessObjectRow(values, keys) {
|
|
190
|
+
return keys.findIndex((key, index) => key === undefined && isRecordish(values[index]));
|
|
100
191
|
}
|
|
101
192
|
/**
|
|
102
193
|
* Drop null/undefined values from inverse-call args, recursively (live r55
|
|
@@ -197,17 +288,24 @@ export function canonicalForVerify(value) {
|
|
|
197
288
|
function joinPath(base, key) {
|
|
198
289
|
return base === "" ? key : `${base}.${key}`;
|
|
199
290
|
}
|
|
200
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Probe a value for "stringified JSON" semantics: `ok` when the string parses
|
|
293
|
+
* as an object/array, `looksLikeJson && !ok` when it starts like structured
|
|
294
|
+
* JSON but fails to parse (the shapeWarning case — never silently compared as
|
|
295
|
+
* opaque text without naming the break).
|
|
296
|
+
*/
|
|
297
|
+
function jsonProbe(value) {
|
|
201
298
|
if (typeof value !== "string")
|
|
202
|
-
return { ok: false };
|
|
299
|
+
return { ok: false, looksLikeJson: false, head: "" };
|
|
203
300
|
const trimmed = value.trim();
|
|
204
301
|
if (!trimmed.startsWith("{") && !trimmed.startsWith("["))
|
|
205
|
-
return { ok: false };
|
|
302
|
+
return { ok: false, looksLikeJson: false, head: "" };
|
|
303
|
+
const head = trimmed.slice(0, 40);
|
|
206
304
|
try {
|
|
207
|
-
return { ok: true, value: JSON.parse(trimmed) };
|
|
305
|
+
return { ok: true, looksLikeJson: true, head, value: JSON.parse(trimmed) };
|
|
208
306
|
}
|
|
209
307
|
catch {
|
|
210
|
-
return { ok: false };
|
|
308
|
+
return { ok: false, looksLikeJson: true, head };
|
|
211
309
|
}
|
|
212
310
|
}
|
|
213
311
|
//# sourceMappingURL=rollback-spec.js.map
|
package/dist/rollback.js
CHANGED
|
@@ -7,8 +7,13 @@ import { runToolCall } from "./call.js";
|
|
|
7
7
|
import { readJournal, resolveJournalEntry, laterWritesOnTarget } from "./journal.js";
|
|
8
8
|
import { canonicalForVerify, deepDiff, pruneNullish } from "./rollback-spec.js";
|
|
9
9
|
import { sha256 } from "./support.js";
|
|
10
|
-
import { emitTransportResult } from "./command-transport.js";
|
|
10
|
+
import { emitTransportResult, emitInvalid } from "./command-transport.js";
|
|
11
11
|
import { acquireWriteLock } from "./write-lock.js";
|
|
12
|
+
import { resolveSinceRef } from "./duration.js";
|
|
13
|
+
import { normalizeWriteReason } from "./write-audit.js";
|
|
14
|
+
/** Invalid `--since`: the CLI maps it to invalid-input (exit 10), never a guessed window. */
|
|
15
|
+
export class SinceRefError extends Error {
|
|
16
|
+
}
|
|
12
17
|
/** Pure runtime assembly: an injected context (tests) or the default one. */
|
|
13
18
|
function runtime(context) {
|
|
14
19
|
return context ?? makeToolContext({ sessions: new SessionManager(new ConfigStore(defaultPaths())) });
|
|
@@ -38,8 +43,24 @@ function findSpec(toolName) {
|
|
|
38
43
|
}
|
|
39
44
|
export async function listRollback(options, context) {
|
|
40
45
|
const ctx = runtime(context);
|
|
46
|
+
// Validate `--since` BEFORE resolving the environment: bad caller input must
|
|
47
|
+
// not depend on (or require) a valid environment binding.
|
|
48
|
+
const since = options.since === undefined ? undefined : resolveSinceRef(options.since);
|
|
49
|
+
if (since !== undefined && "error" in since)
|
|
50
|
+
throw new SinceRefError(since.error);
|
|
41
51
|
const environment = resolvedEnvironment(options.environment);
|
|
42
52
|
let entries = readJournal(environment, ctx.artifactsDir);
|
|
53
|
+
const beforeSince = entries.length;
|
|
54
|
+
let sinceFilteredOut = 0;
|
|
55
|
+
if (since !== undefined) {
|
|
56
|
+
// `ts` is the journal's own ISO clock. An entry whose ts cannot be parsed is
|
|
57
|
+
// NOT inside the requested window (never silently kept).
|
|
58
|
+
entries = entries.filter((entry) => {
|
|
59
|
+
const at = Date.parse(entry.ts);
|
|
60
|
+
return Number.isFinite(at) && at >= since.cutoffMs;
|
|
61
|
+
});
|
|
62
|
+
sinceFilteredOut = beforeSince - entries.length;
|
|
63
|
+
}
|
|
43
64
|
if (options.target)
|
|
44
65
|
entries = entries.filter((entry) => entry.target.includes(options.target));
|
|
45
66
|
if (options.tool)
|
|
@@ -61,6 +82,17 @@ export async function listRollback(options, context) {
|
|
|
61
82
|
status: "ok",
|
|
62
83
|
environment,
|
|
63
84
|
journalFile: `.omc/journal/${environment}.ndjson(随本项目 artifacts 目录,本机边界:不跨机器)`,
|
|
85
|
+
...(since !== undefined
|
|
86
|
+
? {
|
|
87
|
+
since: {
|
|
88
|
+
input: since.input,
|
|
89
|
+
mode: since.mode,
|
|
90
|
+
cutoff: new Date(since.cutoffMs).toISOString(),
|
|
91
|
+
rule: "保留 ts ≥ cutoff 的写",
|
|
92
|
+
filteredOut: sinceFilteredOut,
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
64
96
|
entries: timeline.length,
|
|
65
97
|
writes: timeline.map((entry) => ({
|
|
66
98
|
seq: entry.seq,
|
|
@@ -68,12 +100,17 @@ export async function listRollback(options, context) {
|
|
|
68
100
|
tool: entry.tool,
|
|
69
101
|
target: entry.target,
|
|
70
102
|
rollbackable: entry.rollbackable,
|
|
103
|
+
// R88 #3:旧 entry 没有审计列 —— 缺省即不回(不回假 actor/reason)。
|
|
104
|
+
...(entry.actor !== undefined ? { actor: entry.actor } : {}),
|
|
105
|
+
...(entry.actorSource !== undefined ? { actorSource: entry.actorSource } : {}),
|
|
106
|
+
...(entry.actorUnavailableReason !== undefined ? { actorUnavailableReason: entry.actorUnavailableReason } : {}),
|
|
107
|
+
...(entry.reason !== undefined ? { reason: entry.reason } : {}),
|
|
71
108
|
...(entry.note ? { note: entry.note } : {}),
|
|
72
109
|
...(entry.steps !== undefined ? { steps: entry.steps } : {}),
|
|
73
110
|
artifact: basename(entry.artifactFile),
|
|
74
111
|
})),
|
|
75
112
|
...(unrollbackable.length > 0 ? { unrollbackable } : {}),
|
|
76
|
-
hint: "omc rollback plan <seq> 预览恢复(不写);omc rollback apply <seq> 执行恢复;unrollbackable[]
|
|
113
|
+
hint: "omc rollback plan <seq> 预览恢复(不写);omc rollback apply <seq> 执行恢复;unrollbackable[] 是本窗口内撤不了的写;actor 为 token 解码(actorSource:token-claim,非平台 currentUser);旧 entry 无审计列、解不出时见 actorUnavailableReason",
|
|
77
114
|
};
|
|
78
115
|
}
|
|
79
116
|
async function buildPlan(ref, environmentOption, context) {
|
|
@@ -95,7 +132,7 @@ async function buildPlan(ref, environmentOption, context) {
|
|
|
95
132
|
before: undefined,
|
|
96
133
|
artifactArgs: {},
|
|
97
134
|
context: ctx,
|
|
98
|
-
plan: { environmentMatch: true, diff: {
|
|
135
|
+
plan: { environmentMatch: true, diff: { entries: [], totalKnown: 0, truncated: false, remaining: 0, shapeWarnings: [], nonAdditionCount: 0 }, laterWrites: laterWritesOnTarget(environment, ctx.artifactsDir, entry.seq, entry.target), inverse: { kind: "irreversible", reason } },
|
|
99
136
|
});
|
|
100
137
|
if (!entry.rollbackable)
|
|
101
138
|
return unrollbackable(entry.note ?? "该写的 before 快照捕获失败,无法回滚");
|
|
@@ -147,7 +184,14 @@ export async function planRollback(ref, options, context) {
|
|
|
147
184
|
return {
|
|
148
185
|
status: "ok",
|
|
149
186
|
rollbackOf: { seq: entry.seq, tool: entry.tool, target: entry.target, ts: entry.ts },
|
|
150
|
-
diff: {
|
|
187
|
+
diff: {
|
|
188
|
+
changedPaths: plan.diff.entries.map((change) => ({ path: change.path, before: preview(change.before), current: preview(change.current) })),
|
|
189
|
+
// totalKnown is the EXACT difference count (the walk never stops at the
|
|
190
|
+
// inline cap); truncated/remaining say how much lives beyond this list.
|
|
191
|
+
total: plan.diff.totalKnown,
|
|
192
|
+
...(plan.diff.truncated ? { truncated: true, remaining: plan.diff.remaining } : {}),
|
|
193
|
+
...(plan.diff.shapeWarnings.length > 0 ? { shapeWarnings: plan.diff.shapeWarnings } : {}),
|
|
194
|
+
},
|
|
151
195
|
// r30a F12: do not claim "will overwrite later writes" when inverse is irreversible.
|
|
152
196
|
...(plan.laterWrites.length > 0 && !irreversible
|
|
153
197
|
? { warning: `该目标在此写之后还有 ${plan.laterWrites.length} 次写(seq ${plan.laterWrites.map((w) => w.seq).join(", ")});本次回滚会用 before 参数覆盖这些后续变更`, laterWrites: plan.laterWrites.map((w) => ({ seq: w.seq, tool: w.tool, ts: w.ts })) }
|
|
@@ -192,6 +236,9 @@ export async function applyRollback(ref, options, context) {
|
|
|
192
236
|
};
|
|
193
237
|
}
|
|
194
238
|
const results = [];
|
|
239
|
+
// R88 #3:恢复写本身也是写——journal 行要能回答「为什么」。调用方没给
|
|
240
|
+
// --reason 时记机器可证实的出处(回滚了哪个 seq),不发明人类理由。
|
|
241
|
+
const restoreReason = normalizeWriteReason(options.reason) ?? `rollback of seq ${entry.seq}(${entry.tool})`;
|
|
195
242
|
// The inverse plan is intentionally kept as the seam for future inverse
|
|
196
243
|
// extensions (for example onlinejs.compose remove:true): all new restore
|
|
197
244
|
// shapes still become governed calls here, without changing the evidence
|
|
@@ -221,6 +268,7 @@ export async function applyRollback(ref, options, context) {
|
|
|
221
268
|
args: { ...call.args, environment: entry.environment, ...(options.confirmProduction ? { confirmProduction: true } : {}) },
|
|
222
269
|
requestId: `omc-rollback-${entry.seq}-${index + 1}`,
|
|
223
270
|
context: ctx,
|
|
271
|
+
reason: restoreReason,
|
|
224
272
|
print: () => undefined,
|
|
225
273
|
});
|
|
226
274
|
results.push({
|
|
@@ -254,13 +302,17 @@ export async function applyRollback(ref, options, context) {
|
|
|
254
302
|
verify = "restored";
|
|
255
303
|
else {
|
|
256
304
|
const residual = deepDiff(canonicalForVerify(before), canonicalForVerify(restored));
|
|
257
|
-
|
|
305
|
+
// nonAdditionCount counts entries beyond the inline cap too, so the
|
|
306
|
+
// explicitification tolerance can never hide a real mismatch past limit.
|
|
307
|
+
verify = residual.nonAdditionCount === 0 ? "restored" : "mismatch";
|
|
258
308
|
}
|
|
259
309
|
return {
|
|
260
310
|
status: "ok",
|
|
261
311
|
rollbackOf: { seq: entry.seq, tool: entry.tool, target: entry.target },
|
|
262
312
|
calls: results,
|
|
263
313
|
verify,
|
|
314
|
+
// R88 #3:恢复写落 journal 时记的 reason(journal 是唯一审计真相源)。
|
|
315
|
+
reason: restoreReason,
|
|
264
316
|
// Stable evidence is present on both the restored and mismatch paths.
|
|
265
317
|
// `recoveredTo` deliberately identifies the original journal target; the
|
|
266
318
|
// replay writes are separately journaled and can be rolled back again.
|
|
@@ -272,7 +324,16 @@ export async function applyRollback(ref, options, context) {
|
|
|
272
324
|
};
|
|
273
325
|
}
|
|
274
326
|
export async function cmdRollbackList(options, transport) {
|
|
275
|
-
|
|
327
|
+
try {
|
|
328
|
+
return emitTransportResult(await listRollback(options), transport);
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
// Invalid `--since` is caller input, not an internal failure: exit 10 with
|
|
332
|
+
// the accepted shapes (never a silently guessed window).
|
|
333
|
+
if (error instanceof SinceRefError)
|
|
334
|
+
return emitInvalid(transport, { message: error.message, blocker: "since-invalid" });
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
276
337
|
}
|
|
277
338
|
export async function cmdRollbackPlan(ref, options, transport) {
|
|
278
339
|
return emitTransportResult(await planRollback(ref, options), transport);
|
package/dist/script.js
CHANGED
|
@@ -87,6 +87,7 @@ export async function runScript(lines, options = {}) {
|
|
|
87
87
|
dryRun: line.dryRun === true,
|
|
88
88
|
requestId: randomUUID(),
|
|
89
89
|
context,
|
|
90
|
+
...(options.reason !== undefined ? { reason: options.reason } : {}),
|
|
90
91
|
print: () => undefined,
|
|
91
92
|
});
|
|
92
93
|
const rendered = JSON.stringify({ index, tool: line.tool, exitCode, result });
|
package/dist/tool-search.js
CHANGED
|
@@ -225,6 +225,9 @@ const TOOL_PARENTS = Object.freeze({
|
|
|
225
225
|
// R79 三期:流程清单以模型为索引(应用树→模型→逐模型解析流程)——句子里
|
|
226
226
|
// 点模型时给 workflow.list 父对象信号(与 listview/form 同族)。
|
|
227
227
|
"workflow.list": ["model"],
|
|
228
|
+
// R88 #1:双面排查 diff 的目标是「某模型/流程/表单」——句子里点流程或表单
|
|
229
|
+
// 时给 config.diff 父对象信号(「流程和表单的草稿发布差异」两侧都命中)。
|
|
230
|
+
"config.diff": ["workflow", "form"],
|
|
228
231
|
"method.create": ["service"], "method.update": ["service"], "method.get": ["service"], "method.delete": ["service"], "method.test": ["service"], "method.list": ["service"],
|
|
229
232
|
// 业务服务调用日志:对象段是 servicelog,句子里同时点「服务」或「模型/单据」
|
|
230
233
|
// (schemaCode/bizObjectId 是核心过滤面)都该给父对象信号。
|
package/dist/tools.js
CHANGED
|
@@ -17,6 +17,7 @@ import { registerRuleLogLane } from "./lanes/rulelog.js";
|
|
|
17
17
|
import { registerRuleLifecycleLane } from "./lanes/rule-lifecycle.js";
|
|
18
18
|
import { registerRuntimeDataLane } from "./lanes/runtime-data.js";
|
|
19
19
|
import { registerWorkflowLane } from "./lanes/workflow.js";
|
|
20
|
+
import { registerConfigDiffTool } from "./lanes/config-diff.js";
|
|
20
21
|
import { registerOrganizationLane } from "./lanes/organization.js";
|
|
21
22
|
import { registerOnlineJsLane } from "./lanes/online-js.js";
|
|
22
23
|
import { registerProgrammingLane } from "./lanes/programming.js";
|
|
@@ -31,6 +32,7 @@ import { attachRefusalRecovery } from "./refusal-guidance.js";
|
|
|
31
32
|
import { defineTool, ToolRefusalError } from "./tool-types.js";
|
|
32
33
|
import { environmentArg } from "./args.js";
|
|
33
34
|
import { appendJournalEntry } from "./journal.js";
|
|
35
|
+
import { journalAudit } from "./write-audit.js";
|
|
34
36
|
import { listRequestArtifacts } from "./write.js";
|
|
35
37
|
export { ToolRefusalError, ToolUncertainError } from "./tool-types.js";
|
|
36
38
|
export { makeToolContext };
|
|
@@ -64,6 +66,11 @@ export function buildToolRegistry() {
|
|
|
64
66
|
registerRuleLifecycleLane(tools);
|
|
65
67
|
registerRuntimeDataLane(tools);
|
|
66
68
|
registerWorkflowLane(tools);
|
|
69
|
+
// R88 #1: draft↔published triage diff. Registered after the workflow lane
|
|
70
|
+
// (it declares the workflow lane's scope but lives in its own module to
|
|
71
|
+
// keep the diff adapters separate from the write lane) — importing it from
|
|
72
|
+
// workflow.ts instead would create a module cycle.
|
|
73
|
+
registerConfigDiffTool(tools);
|
|
67
74
|
registerOrganizationLane(tools);
|
|
68
75
|
registerOnlineJsLane(tools);
|
|
69
76
|
registerProgrammingLane(tools);
|
|
@@ -119,6 +126,8 @@ export function buildToolRegistry() {
|
|
|
119
126
|
rollbackable: false,
|
|
120
127
|
note: "复合写无逆操作,只记录(不假装可回滚)",
|
|
121
128
|
...(steps !== undefined ? { steps: steps.map((step) => (step && typeof step === "object" ? { step: step.step, skipped: step.skipped } : step)) } : {}),
|
|
129
|
+
// R88 #3:复合写同样记「谁/为什么」——审计列不由写面分叉。
|
|
130
|
+
...journalAudit(ctx.sessions.config(), environment, ctx.writeAudit?.reason),
|
|
122
131
|
artifactFile: typeof record.detailFile === "string" ? record.detailFile : `${toolName}.compound.json`,
|
|
123
132
|
artifactId: typeof record.detailFile === "string" ? basename(record.detailFile) : `${toolName}-compound`,
|
|
124
133
|
artifactSha: typeof record.artifactFingerprint === "string" ? record.artifactFingerprint : typeof record.detailSha256 === "string" ? record.detailSha256 : "compound",
|