@stalfh233/omc-cli 0.8.2 → 0.8.4
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/bench/call-face-eval.js +1 -1
- package/dist/bench/scenario.js +3 -3
- package/dist/cli-contract.js +55 -2
- package/dist/cli-output.js +59 -8
- package/dist/cli.js +338 -59
- package/dist/field-families.js +19 -9
- package/dist/form-layout.js +19 -4
- package/dist/form-support.js +181 -9
- package/dist/graph.js +151 -29
- package/dist/intent/capabilities/field.js +98 -0
- package/dist/intent/plan-apply.js +9 -0
- package/dist/lanes/app.js +34 -6
- package/dist/lanes/field.js +360 -94
- package/dist/lanes/form.js +27 -5
- package/dist/lanes/model.js +42 -11
- package/dist/lanes/runtime-data.js +93 -4
- package/dist/lanes/workflow-contract.js +1 -1
- package/dist/lanes/workflow.js +30 -14
- package/dist/path-projection.js +25 -14
- package/dist/read.js +132 -3
- package/dist/refusal-guidance.js +14 -0
- package/dist/session.js +30 -2
- package/dist/support.js +3 -1
- package/dist/wire-failure.js +120 -0
- package/dist/wire.js +109 -5
- package/dist/workflow-support.js +41 -0
- package/package.json +3 -3
package/dist/graph.js
CHANGED
|
@@ -62,6 +62,31 @@ export const GRAPH_SCHEMA_VERSION = "9";
|
|
|
62
62
|
const STALE_LOCK_MS = 15 * 60 * 1000;
|
|
63
63
|
export const DEFAULT_PULL_CONCURRENCY = 16;
|
|
64
64
|
export const MAX_PULL_CONCURRENCY = 32;
|
|
65
|
+
/** B4:总超时(真机 `graph pull` 曾无输出挂起,只能手 kill)。 */
|
|
66
|
+
export const DEFAULT_GRAPH_PULL_TIMEOUT_MS = 120_000;
|
|
67
|
+
export const MAX_GRAPH_PULL_TIMEOUT_MS = 600_000;
|
|
68
|
+
/** B4:deadline 已过时,后续每一跳直接失败(由各面的 catch 记成 gap)。 */
|
|
69
|
+
class GraphPullDeadlineError extends Error {
|
|
70
|
+
constructor(path, deadline) {
|
|
71
|
+
super(`graph pull deadline exceeded before ${path} (deadline ${new Date(deadline).toISOString()})`);
|
|
72
|
+
this.name = "GraphPullDeadlineError";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** B4:总超时抛出(索引未发布;lock/staging 由 withGraphPullLock 清理)。 */
|
|
76
|
+
export class GraphPullTimeoutError extends Error {
|
|
77
|
+
elapsedMs;
|
|
78
|
+
timeoutMs;
|
|
79
|
+
progressSnapshot;
|
|
80
|
+
constructor(elapsedMs, timeoutMs, progressSnapshot) {
|
|
81
|
+
super(`graph pull 超时(${Math.round(elapsedMs / 1000)}s ≥ ${Math.round(timeoutMs / 1000)}s):已完成 ${progressSnapshot.applicationsDone}/${progressSnapshot.applicationsTotal} 个应用`
|
|
82
|
+
+ `${progressSnapshot.currentApplication !== undefined ? `(卡在 app=${progressSnapshot.currentApplication})` : ""};索引未发布。`
|
|
83
|
+
+ `恢复:缩小范围重跑 \`--application-codes <a,b>\`,或显式放宽 \`--timeout-ms ${Math.min(timeoutMs * 2, MAX_GRAPH_PULL_TIMEOUT_MS)}\`。`);
|
|
84
|
+
this.elapsedMs = elapsedMs;
|
|
85
|
+
this.timeoutMs = timeoutMs;
|
|
86
|
+
this.progressSnapshot = progressSnapshot;
|
|
87
|
+
this.name = "GraphPullTimeoutError";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
65
90
|
/** 索引超过这个天数就提示刷新(配置类查询,1 天足够新)。 */
|
|
66
91
|
export const STALE_INDEX_DAYS = 1;
|
|
67
92
|
export const STALE_AFTER_MINUTES = STALE_INDEX_DAYS * 24 * 60;
|
|
@@ -559,12 +584,27 @@ export function extractFormEdges(schemaCode, sheet, knownFieldCodes) {
|
|
|
559
584
|
* `datarule-list`) and vice versa (`rule-list`). Output is sorted so the
|
|
560
585
|
* published DB is byte-stable regardless of completion order.
|
|
561
586
|
*/
|
|
562
|
-
export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRENCY, requestedApplication, root) {
|
|
587
|
+
export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRENCY, requestedApplication, root, hooks) {
|
|
563
588
|
const identity = session.environmentFingerprint();
|
|
564
589
|
const pulledAtIso = new Date().toISOString();
|
|
565
590
|
const totalStart = Date.now();
|
|
566
591
|
let listMs = 0;
|
|
567
592
|
let readMs = 0;
|
|
593
|
+
// B4:进度行(stderr)+ 总超时倒计时。`appIndex` 让多应用轮次能打 3/13。
|
|
594
|
+
const appName = requestedApplication ?? session.profile.applicationCode ?? "(default)";
|
|
595
|
+
const appLabel = hooks?.appIndex !== undefined ? `${hooks.appIndex.index}/${hooks.appIndex.total} app=${appName}` : `app=${appName}`;
|
|
596
|
+
const progress = (stage) => hooks?.progress?.(`[graph] ${appLabel} ${stage}`);
|
|
597
|
+
/** Deadline-aware wire: every hop gets the remaining budget, never the full default. */
|
|
598
|
+
const wire = async (path, query) => {
|
|
599
|
+
if (hooks?.deadline !== undefined) {
|
|
600
|
+
const remaining = hooks.deadline - Date.now();
|
|
601
|
+
if (remaining <= 0)
|
|
602
|
+
throw new GraphPullDeadlineError(path, hooks.deadline);
|
|
603
|
+
return wireCall(session, { path, query, timeoutMs: remaining });
|
|
604
|
+
}
|
|
605
|
+
return wireCall(session, { path, query });
|
|
606
|
+
};
|
|
607
|
+
progress("phase=app-tree");
|
|
568
608
|
// Model enumeration mirrors the governed `model.list` tool exactly: the
|
|
569
609
|
// application tree flattened to BizModel rows. The bare `modelList` endpoint
|
|
570
610
|
// returns EMPTY data on a real platform (works only against the fake face)
|
|
@@ -573,18 +613,19 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
573
613
|
const scope = await resolveApplicationScope(session, requestedApplication).catch(() => undefined);
|
|
574
614
|
const applicationCode = scope?.code ?? "";
|
|
575
615
|
const gaps = [];
|
|
576
|
-
const treeRows = flattenTreeRows(wireRows((await
|
|
616
|
+
const treeRows = flattenTreeRows(wireRows((await wire(ENDPOINTS.applicationTree, { appCode: applicationCode })).data));
|
|
577
617
|
const modelEntities = treeRows.filter((row) => row.type === "BizModel" && typeof row.code === "string" && row.code !== "").map((row) => ({ schemaCode: String(row.code), name: String(row.name ?? row.code), applicationCode })).sort((a, b) => a.schemaCode.localeCompare(b.schemaCode));
|
|
618
|
+
progress(`phase=models models=${modelEntities.length}`);
|
|
578
619
|
const schemaCodes = modelEntities.map((row) => row.schemaCode);
|
|
579
620
|
const fields = [];
|
|
580
621
|
const services = [];
|
|
581
622
|
await Promise.all(schemaCodes.map(async (schemaCode) => {
|
|
582
623
|
try {
|
|
583
|
-
let rows = wireRows((await
|
|
624
|
+
let rows = wireRows((await wire(ENDPOINTS.fieldList, { schemaCode, isPublish: "true" })).data);
|
|
584
625
|
// Several applications expose fields only on the draft face. An empty
|
|
585
626
|
// published response is not evidence that the model has no fields.
|
|
586
627
|
if (rows.length === 0)
|
|
587
|
-
rows = wireRows((await
|
|
628
|
+
rows = wireRows((await wire(ENDPOINTS.fieldList, { schemaCode, isPublish: "false" })).data);
|
|
588
629
|
if (rows.length === 0)
|
|
589
630
|
gaps.push({ kind: "field-list", ref: schemaCode, note: "published and draft faces are empty" });
|
|
590
631
|
for (const row of rows) {
|
|
@@ -597,6 +638,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
597
638
|
gaps.push({ kind: "field-list", ref: schemaCode, note: error instanceof Error ? error.message : String(error) });
|
|
598
639
|
}
|
|
599
640
|
}));
|
|
641
|
+
progress(`phase=fields fields=${fields.length}`);
|
|
600
642
|
// r75:form 控件边按「码在该模型 fieldList 里」过滤——这里是已知字段的按模型
|
|
601
643
|
// 索引(fields 收集在上面 await 完成,此时已齐)。
|
|
602
644
|
const knownFields = new Map();
|
|
@@ -606,8 +648,8 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
606
648
|
knownFields.set(field.schemaCode, codes);
|
|
607
649
|
}
|
|
608
650
|
try {
|
|
609
|
-
await
|
|
610
|
-
const rows = wireRows((await
|
|
651
|
+
await wire(ENDPOINTS.bizServiceCategoryList, {});
|
|
652
|
+
const rows = wireRows((await wire(ENDPOINTS.bizServiceListByCategoryId, { categoryId: "" })).data);
|
|
611
653
|
for (const row of rows) {
|
|
612
654
|
const code = String(row.code ?? "");
|
|
613
655
|
if (code)
|
|
@@ -617,6 +659,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
617
659
|
catch (error) {
|
|
618
660
|
gaps.push({ kind: "service-list", ref: "all", note: error instanceof Error ? error.message : String(error) });
|
|
619
661
|
}
|
|
662
|
+
progress(`phase=services services=${services.length}`);
|
|
620
663
|
const rules = [];
|
|
621
664
|
const edges = [];
|
|
622
665
|
let parseFailures = 0;
|
|
@@ -639,6 +682,9 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
639
682
|
resolveAll();
|
|
640
683
|
};
|
|
641
684
|
const submit = (task) => {
|
|
685
|
+
// B4:deadline 已过就不再排新任务(在途的会被 timeoutMs 收紧的请求自己结束)。
|
|
686
|
+
if (hooks?.deadline !== undefined && Date.now() >= hooks.deadline)
|
|
687
|
+
return;
|
|
642
688
|
inflight += 1;
|
|
643
689
|
void (async () => {
|
|
644
690
|
await semaphore.acquire();
|
|
@@ -663,7 +709,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
663
709
|
let rows = [];
|
|
664
710
|
let ruleListOk = true;
|
|
665
711
|
try {
|
|
666
|
-
rows = wireRows((await
|
|
712
|
+
rows = wireRows((await wire(ENDPOINTS.businessRuleListBySchemaCode, { schemaCode })).data);
|
|
667
713
|
}
|
|
668
714
|
catch (error) {
|
|
669
715
|
ruleListOk = false;
|
|
@@ -671,7 +717,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
671
717
|
}
|
|
672
718
|
let dataruleRows = [];
|
|
673
719
|
try {
|
|
674
|
-
dataruleRows = wireRows((await
|
|
720
|
+
dataruleRows = wireRows((await wire(ENDPOINTS.dataRuleList, { schemaCode })).data);
|
|
675
721
|
dataruleCount += dataruleRows.length;
|
|
676
722
|
for (const row of dataruleRows)
|
|
677
723
|
edges.push(...extractDataRuleEdges(schemaCode, row).map((edge) => ({ ...edge, applicationCode })));
|
|
@@ -680,7 +726,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
680
726
|
gaps.push({ kind: "datarule-list", ref: schemaCode, note: error instanceof Error ? error.message : String(error) });
|
|
681
727
|
}
|
|
682
728
|
try {
|
|
683
|
-
const views = wireRows((await
|
|
729
|
+
const views = wireRows((await wire(ENDPOINTS.listQueryList, { schemaCode, clientType: "PC" })).data);
|
|
684
730
|
for (const view of views) {
|
|
685
731
|
const viewCode = typeof view.code === "string" ? view.code : "";
|
|
686
732
|
if (viewCode === "")
|
|
@@ -696,8 +742,8 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
696
742
|
// isWorkflowAbsent 同语义——该函数未导出,这里局部判定)。读失败记
|
|
697
743
|
// workflow-read gap,不静默。
|
|
698
744
|
try {
|
|
699
|
-
if ((await
|
|
700
|
-
const linked = (await
|
|
745
|
+
if ((await wire(ENDPOINTS.workflowIsWorkflow, { schemaCode })).data === true) {
|
|
746
|
+
const linked = (await wire(ENDPOINTS.workflowGetBySchema, { schemaCode })).data;
|
|
701
747
|
const workflowCode = linked !== null && typeof linked.workflowCode === "string" && linked.workflowCode !== "" ? linked.workflowCode : "";
|
|
702
748
|
if (workflowCode === "") {
|
|
703
749
|
gaps.push({ kind: "workflow-read", ref: schemaCode, note: "isworkflow=true 但 getWorkflow 未返回 workflowCode" });
|
|
@@ -707,7 +753,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
707
753
|
//(发布标记不阻断采集,草稿独有差异不追——见 r75 调查报告)。
|
|
708
754
|
let published = null;
|
|
709
755
|
try {
|
|
710
|
-
published = (await
|
|
756
|
+
published = (await wire(ENDPOINTS.workflowGetPublished, { workflowCode })).data;
|
|
711
757
|
}
|
|
712
758
|
catch (error) {
|
|
713
759
|
if (!(error instanceof WireError && error.kind === "business" && error.errcode === 401001))
|
|
@@ -727,7 +773,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
727
773
|
// 表单」的模型回 data:null——缺席不是缺口。多表单模型的其它槽位
|
|
728
774
|
//(sheetCode≠schemaCode)无清单端点,只扫默认槽(GRAPH_COVERAGE.note 声明)。
|
|
729
775
|
try {
|
|
730
|
-
const sheet = (await
|
|
776
|
+
const sheet = (await wire(ENDPOINTS.sheetGet, { schemaCode, sheetCode: schemaCode })).data;
|
|
731
777
|
if (sheet !== null) {
|
|
732
778
|
formCount += 1;
|
|
733
779
|
edges.push(...extractFormEdges(schemaCode, sheet, knownFields.get(schemaCode) ?? new Set()).map((edge) => ({ ...edge, applicationCode })));
|
|
@@ -757,7 +803,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
757
803
|
const runRuleRead = async (schemaCode, ruleCode, ruleId) => {
|
|
758
804
|
const start = Date.now();
|
|
759
805
|
try {
|
|
760
|
-
const record = (await
|
|
806
|
+
const record = (await wire(ENDPOINTS.businessRuleGet, { id: ruleId })).data;
|
|
761
807
|
if (!record) {
|
|
762
808
|
gaps.push({ kind: "rule-get", ref: `${schemaCode}/${ruleCode}`, note: "empty readback" });
|
|
763
809
|
return;
|
|
@@ -792,7 +838,7 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
|
|
|
792
838
|
};
|
|
793
839
|
const runListViewRead = async (schemaCode, viewCode) => {
|
|
794
840
|
try {
|
|
795
|
-
const got = (await
|
|
841
|
+
const got = (await wire(ENDPOINTS.listQueryGet, { schemaCode, code: viewCode, clientType: "PC" })).data;
|
|
796
842
|
if (got === null || !got.id) {
|
|
797
843
|
gaps.push({ kind: "listview-get", ref: `${schemaCode}/${viewCode}`, note: "empty readback" });
|
|
798
844
|
return;
|
|
@@ -923,26 +969,102 @@ async function withGraphPullLock(dbPath, run) {
|
|
|
923
969
|
}
|
|
924
970
|
/** Wholesalerebuild + atomic publish (staging file + rename), 0600. */
|
|
925
971
|
export async function publishGraphPull(session, concurrency = DEFAULT_PULL_CONCURRENCY, options = {}) {
|
|
972
|
+
// B4(0.8.4):总超时 + 进度行(默认 stderr)。真机 `graph pull` 曾「进程存活、
|
|
973
|
+
// CPU 0.28、输出为空、无超时」——agent 只能手 kill,再 `graph status` 拿
|
|
974
|
+
// graph-index-absent。这里:默认 120s 总超时(`--timeout-ms` 覆盖)、每应用
|
|
975
|
+
// start/done/failed 一行到 stderr(stdout 仍是单信封)、单应用失败只进
|
|
976
|
+
// failedApps[] 不拖垮整轮(成功部分照常发布,CLI 以 partial/退出码 1 说明)。
|
|
977
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_GRAPH_PULL_TIMEOUT_MS;
|
|
978
|
+
const progress = options.progress ?? ((line) => { process.stderr.write(`${line}\n`); });
|
|
979
|
+
const snapshot = { applicationsDone: 0, applicationsTotal: 0 };
|
|
926
980
|
// The environment decides the file: one project can index `test` and `prod`
|
|
927
981
|
// side by side, so the target is not known until the session resolves.
|
|
928
982
|
const dbPath = graphDbPath(options.root, session.environmentName);
|
|
929
983
|
try {
|
|
930
984
|
return await withGraphPullLock(dbPath, async () => {
|
|
931
985
|
const requested = options.applicationCodes?.length ? options.applicationCodes : [undefined];
|
|
932
|
-
|
|
933
|
-
const
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
986
|
+
snapshot.applicationsTotal = requested.length;
|
|
987
|
+
const startedAt = Date.now();
|
|
988
|
+
const deadline = startedAt + timeoutMs;
|
|
989
|
+
let timer;
|
|
990
|
+
const timeout = new Promise((_, reject) => {
|
|
991
|
+
timer = setTimeout(() => {
|
|
992
|
+
// 断掉在途 fetch(真实会话):否则 race 丢掉 pull 协程后 socket 仍挂着,
|
|
993
|
+
// 进程继续「活着没输出」——正是真机形态。注入 adapter 的测试里是 no-op。
|
|
994
|
+
session.abortInFlight("graph-pull-timeout");
|
|
995
|
+
reject(new GraphPullTimeoutError(Date.now() - startedAt, timeoutMs, { ...snapshot }));
|
|
996
|
+
}, Math.max(1, timeoutMs));
|
|
997
|
+
});
|
|
998
|
+
const pull = (async () => {
|
|
999
|
+
const parts = [];
|
|
1000
|
+
const failedApps = [];
|
|
1001
|
+
let firstError;
|
|
1002
|
+
for (let index = 0; index < requested.length; index += 1) {
|
|
1003
|
+
const application = requested[index];
|
|
1004
|
+
const label = application ?? session.profile.applicationCode ?? "(default)";
|
|
1005
|
+
snapshot.currentApplication = label;
|
|
1006
|
+
progress(`[graph] ${index + 1}/${requested.length} app=${label} start`);
|
|
1007
|
+
try {
|
|
1008
|
+
const part = await pullRuleGraph(session, concurrency, application, options.root, {
|
|
1009
|
+
deadline,
|
|
1010
|
+
progress,
|
|
1011
|
+
appIndex: { index: index + 1, total: requested.length },
|
|
1012
|
+
});
|
|
1013
|
+
parts.push(part);
|
|
1014
|
+
// B4:`applicationsDone` 是**成功**拉取数(超时回执说「已完成 N/M」
|
|
1015
|
+
// 时不能把失败应用也算进去,否则会出现「已完成 1/1(卡在 app=test)」)。
|
|
1016
|
+
snapshot.applicationsDone = parts.length;
|
|
1017
|
+
progress(`[graph] ${index + 1}/${requested.length} app=${label} done models=${part.scanned.models} rules=${part.scanned.rules} edges=${part.edges.length} ${(part.timings.totalMs / 1000).toFixed(1)}s`);
|
|
1018
|
+
}
|
|
1019
|
+
catch (error) {
|
|
1020
|
+
firstError ??= error;
|
|
1021
|
+
const reason = (error instanceof Error ? error.message : String(error)).slice(0, 300);
|
|
1022
|
+
failedApps.push({ applicationCode: label, reason });
|
|
1023
|
+
progress(`[graph] ${index + 1}/${requested.length} app=${label} failed err=${reason}`);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
// 全部失败 = 整轮失败(保留原来的 uncertain 语义);部分失败仍发布索引。
|
|
1027
|
+
if (parts.length === 0)
|
|
1028
|
+
throw firstError ?? new Error("graph pull failed for every requested application");
|
|
1029
|
+
const first = parts[0];
|
|
1030
|
+
const data = parts.length === 1 && failedApps.length === 0 ? first : {
|
|
1031
|
+
...first,
|
|
1032
|
+
meta: { ...first.meta, applicationCode: failedApps.length === 0 && parts.length > 1 ? "*" : (parts.length === 1 ? first.meta.applicationCode : "*"), applicationResolution: parts.length > 1 ? { code: "*", source: "wildcard" } : first.meta.applicationResolution, coverage: { applicationCodes: parts.flatMap((part) => part.meta.coverage.applicationCodes), tenantApplications: parts.flatMap((part) => part.meta.coverage.applicationCodes) } },
|
|
1033
|
+
rules: parts.flatMap((part) => part.rules),
|
|
1034
|
+
edges: parts.flatMap((part) => part.edges),
|
|
1035
|
+
models: parts.flatMap((part) => part.models),
|
|
1036
|
+
fields: parts.flatMap((part) => part.fields),
|
|
1037
|
+
services: parts.flatMap((part) => part.services),
|
|
1038
|
+
gaps: parts.flatMap((part) => part.gaps),
|
|
1039
|
+
...(failedApps.length > 0 ? { failedApps } : {}),
|
|
1040
|
+
scanned: parts.reduce((sum, part) => ({ models: sum.models + part.scanned.models, rules: sum.rules + part.scanned.rules, datarules: sum.datarules + part.scanned.datarules, views: sum.views + part.scanned.views, workflows: sum.workflows + part.scanned.workflows, forms: sum.forms + part.scanned.forms, parseFailures: sum.parseFailures + part.scanned.parseFailures }), { models: 0, rules: 0, datarules: 0, views: 0, workflows: 0, forms: 0, parseFailures: 0 }),
|
|
1041
|
+
timings: { listMs: parts.reduce((n, part) => n + part.timings.listMs, 0), readMs: parts.reduce((n, part) => n + part.timings.readMs, 0), totalMs: parts.reduce((n, part) => n + part.timings.totalMs, 0) },
|
|
1042
|
+
};
|
|
1043
|
+
return data;
|
|
1044
|
+
})();
|
|
1045
|
+
// 超时先赢时 pull 仍在跑:挂一个空的 catch,避免 unhandled rejection。
|
|
1046
|
+
pull.catch(() => undefined);
|
|
1047
|
+
let data;
|
|
1048
|
+
try {
|
|
1049
|
+
data = await Promise.race([pull, timeout]);
|
|
1050
|
+
}
|
|
1051
|
+
catch (error) {
|
|
1052
|
+
// 超时与 pull 的 deadline 检查是两条路径,谁先到都必须回**同一个**
|
|
1053
|
+
// graph-pull-timeout 语义。CPU 被占满时(全量测试并发、宿主负载),
|
|
1054
|
+
// pull 的微任务先恢复、`Date.now() >= deadline` 先命中,会抛内部
|
|
1055
|
+
// GraphPullDeadlineError;直接漏出去会让 CLI 走 emitThrown → code=internal
|
|
1056
|
+
// /exit 15,丢掉 blocker、已拉数量与恢复指引(真机 --timeout-ms 的可见
|
|
1057
|
+
// 症状就是不稳定的「内部错误」而不是超时)。
|
|
1058
|
+
if (error instanceof GraphPullDeadlineError) {
|
|
1059
|
+
throw new GraphPullTimeoutError(Date.now() - startedAt, timeoutMs, { ...snapshot });
|
|
1060
|
+
}
|
|
1061
|
+
throw error;
|
|
1062
|
+
}
|
|
1063
|
+
finally {
|
|
1064
|
+
if (timer)
|
|
1065
|
+
clearTimeout(timer);
|
|
1066
|
+
}
|
|
1067
|
+
progress(`[graph] publish env=${session.environmentName} apps=${data.meta.coverage.applicationCodes.length}${data.failedApps !== undefined && data.failedApps.length > 0 ? ` failedApps=${data.failedApps.length}` : ""}`);
|
|
946
1068
|
const staging = `${dbPath}.staging-${process.pid}`;
|
|
947
1069
|
rmSync(staging, { force: true });
|
|
948
1070
|
const DatabaseSyncCtor = nodeSqlite().DatabaseSync;
|
|
@@ -2,6 +2,8 @@ import { validateBusinessCode } from "../../code-rules.js";
|
|
|
2
2
|
import { fieldSemanticDescriptor, prepareFieldChange } from "../../field-change.js";
|
|
3
3
|
import { CHILD_TABLE_SCALAR_PROPERTY_TYPES, FIELD_PROPERTY_TYPES, OUT_OF_COVERAGE_FIELD_TYPES, isNumericalScale } from "../../field-families.js";
|
|
4
4
|
import { ENDPOINTS } from "../../endpoints.js";
|
|
5
|
+
import { lintFieldCreateWrite, modelSchemaCodes } from "../../lanes/field.js";
|
|
6
|
+
import { ToolRefusalError } from "../../tool-types.js";
|
|
5
7
|
import { wireCall, wireRows } from "../../wire.js";
|
|
6
8
|
import { canonicalJson } from "../dsl.js";
|
|
7
9
|
import { refuse } from "../capability.js";
|
|
@@ -171,6 +173,102 @@ async function readFields(session, schemaCode) {
|
|
|
171
173
|
}
|
|
172
174
|
return [...fields.values()];
|
|
173
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* 0.8.4 P0 同类收尾(W21):intent 逐字段调用 `field.create`,语义门确实会跑;
|
|
178
|
+
* 但**新模型**此刻发布面为空,而共享门 `assertRelationOptionsFields` 的既有设计是
|
|
179
|
+
* 「空读面不判」(避免读面不可用时误拒)。于是同一 `models[].fields[]` 内、映射
|
|
180
|
+
* target 指向同包字段、或聚合指向同包裸子表 code 的声明会落回那个逃生口——与
|
|
181
|
+
* `configure_model` 修前的 P0 同类。
|
|
182
|
+
*
|
|
183
|
+
* 这里把**本次 plan 里该模型声明的全部字段**整理成 overlay(code + 字段族),
|
|
184
|
+
* apply 时交给同一个 `lintFieldCreateWrite`。只取同一意图同一模型的声明:
|
|
185
|
+
* 不读上一次 plan、不跨模型借字段、不把声明 absent 的字段并进来。
|
|
186
|
+
*/
|
|
187
|
+
export function intentOwnFieldOverlays(intent) {
|
|
188
|
+
const overlays = new Map();
|
|
189
|
+
for (const model of intent.models) {
|
|
190
|
+
if (model.absent === true)
|
|
191
|
+
continue;
|
|
192
|
+
// Model schema: every declared-present field is a mapping target candidate.
|
|
193
|
+
const ownFields = model.fields
|
|
194
|
+
.filter((field) => field.absent !== true)
|
|
195
|
+
.map((field) => ({ code: field.code, propertyType: field.type }));
|
|
196
|
+
if (ownFields.length > 0)
|
|
197
|
+
overlays.set(model.code, ownFields);
|
|
198
|
+
// Child schema: `field.create` for a child column carries schemaCode = the
|
|
199
|
+
// parent field code, and its own face is the declared child columns. A child
|
|
200
|
+
// code shares the platform's global schema namespace with models, so never
|
|
201
|
+
// overwrite a model entry.
|
|
202
|
+
for (const field of model.fields) {
|
|
203
|
+
if (field.absent === true || field.type !== "CHILD_TABLE")
|
|
204
|
+
continue;
|
|
205
|
+
const columns = (field.subFields ?? []).map((sub) => ({ code: sub.code, propertyType: sub.type }));
|
|
206
|
+
if (columns.length > 0 && !overlays.has(field.code))
|
|
207
|
+
overlays.set(field.code, columns);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return overlays;
|
|
211
|
+
}
|
|
212
|
+
/** One planned `field.create` as the shared gate's input (the plan's args are the tool shape). */
|
|
213
|
+
function gateInputOf(schemaCode, args, targetVersion) {
|
|
214
|
+
return {
|
|
215
|
+
schemaCode,
|
|
216
|
+
code: String(args.code ?? ""),
|
|
217
|
+
name: String(args.name ?? ""),
|
|
218
|
+
propertyType: args.propertyType,
|
|
219
|
+
...(args.options !== null && typeof args.options === "object" ? { options: args.options } : {}),
|
|
220
|
+
...(Array.isArray(args.choices) ? { choices: args.choices } : {}),
|
|
221
|
+
...(typeof args.relativeCode === "string" ? { relativeCode: args.relativeCode } : {}),
|
|
222
|
+
...(Array.isArray(args.subFields) ? { subFields: args.subFields } : {}),
|
|
223
|
+
...(typeof args.propertyEmpty === "boolean" ? { propertyEmpty: args.propertyEmpty } : {}),
|
|
224
|
+
...(targetVersion ? { targetVersion } : {}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* `intent apply` 的字段写前语义门:在**任何写 wire 之前**把本次 plan 的字段
|
|
229
|
+
* 创建整包过一遍 `field.create` 的同门 `lintFieldCreateWrite`,并附上同包声明
|
|
230
|
+
* 字段作为本模型读面 overlay。只发 GET(发布面读 + 租户模型清单)。
|
|
231
|
+
*
|
|
232
|
+
* 判定不在这里重写:blocker / 诊断字段与 `field.create` 逐字同形(同门产物),
|
|
233
|
+
* 另加 `intentField` 定位到 plan 里的具体字段。
|
|
234
|
+
*/
|
|
235
|
+
export async function lintIntentFieldCreateChanges(session, intent, changes) {
|
|
236
|
+
const overlays = intentOwnFieldOverlays(intent);
|
|
237
|
+
if (overlays.size === 0)
|
|
238
|
+
return undefined;
|
|
239
|
+
const relevant = changes.filter((change) => change.tool === "field.create" && overlays.has(String(change.args.schemaCode ?? "")));
|
|
240
|
+
if (relevant.length === 0)
|
|
241
|
+
return undefined;
|
|
242
|
+
// One model-list read for the whole plan (field.create would read it per field).
|
|
243
|
+
const relationCandidates = await modelSchemaCodes(session);
|
|
244
|
+
const targetVersion = session.detectedVersion();
|
|
245
|
+
for (const change of relevant) {
|
|
246
|
+
const schemaCode = String(change.args.schemaCode ?? "");
|
|
247
|
+
try {
|
|
248
|
+
await lintFieldCreateWrite(session, gateInputOf(schemaCode, change.args, targetVersion), {
|
|
249
|
+
relationCandidates,
|
|
250
|
+
pendingOwnFields: overlays.get(schemaCode),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
if (!(error instanceof ToolRefusalError))
|
|
255
|
+
throw error;
|
|
256
|
+
const { status: _status, ...detail } = error.payload;
|
|
257
|
+
return {
|
|
258
|
+
status: "refused",
|
|
259
|
+
...detail,
|
|
260
|
+
intentField: {
|
|
261
|
+
schemaCode,
|
|
262
|
+
code: String(change.args.code ?? ""),
|
|
263
|
+
...(change.resource !== undefined ? { resource: change.resource } : {}),
|
|
264
|
+
},
|
|
265
|
+
message: `${String(detail.message ?? "字段写前语义门拒绝")};intent apply 在任何写 wire 之前按整包字段面判定,本次零写入——修正意图后重新 intent plan`,
|
|
266
|
+
nextAction: "fix the declared fields/mappings in the intent, then re-run intent plan + apply",
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
174
272
|
/**
|
|
175
273
|
* The field capability (field families + CHILD_TABLE columns). It owns the
|
|
176
274
|
* whole field lifecycle on the intent face: declaration validation, the
|
|
@@ -21,6 +21,7 @@ import { jsonBytes, sha256, writeArtifact } from "../support.js";
|
|
|
21
21
|
import { INTENT_COMPILER_VERSION, intentConfigRoot, readIntentFile } from "./cli.js";
|
|
22
22
|
import { validateRuleNodeGraph, PLATFORM_TRIGGER_RULE_CODES, walkConditionLeaves } from "../lanes/rule-graph.js";
|
|
23
23
|
import { expectedRuleGraph } from "./capabilities/businessrule.js";
|
|
24
|
+
import { lintIntentFieldCreateChanges } from "./capabilities/field.js";
|
|
24
25
|
import { readBaseline, baselineFingerprintOf } from "./baseline.js";
|
|
25
26
|
import { compileIntent } from "./compiler.js";
|
|
26
27
|
import { buildPlan, verifyPlan } from "./plan-file.js";
|
|
@@ -510,6 +511,14 @@ export async function applyIntent(planPath, options, ports) {
|
|
|
510
511
|
environment: session.environmentName,
|
|
511
512
|
message: "plan 之后环境已变化(baseline fingerprint 不一致)——按配置基线契约,写入前必须重新 intent plan;绝不盲用过期 plan",
|
|
512
513
|
});
|
|
514
|
+
// 0.8.4 P0 同类收尾(W21):intent 的字段创建走 field.create,门会跑,但新模型
|
|
515
|
+
// 此刻发布面为空——共享门的「空读面不判」会让同包关系映射/裸子表聚合落回逃生
|
|
516
|
+
// 口。用本次 plan 的整包字段声明作 overlay,在**任何写 wire 之前**补判(只 GET)。
|
|
517
|
+
const fieldGateRefusal = await lintIntentFieldCreateChanges(session, plan.intent, plan.changes);
|
|
518
|
+
if (fieldGateRefusal !== undefined) {
|
|
519
|
+
console.error(`intent apply ${planId}:字段写前语义门拒绝(${String(fieldGateRefusal.blocker)})——零写入`);
|
|
520
|
+
return emit(fieldGateRefusal);
|
|
521
|
+
}
|
|
513
522
|
// Ticket 123 — the final confirmation: after the writes (or on an
|
|
514
523
|
// already-converged no-op) decode the authoritative live state back into
|
|
515
524
|
// intent shape and compare. A mismatch is NEVER reported as plain success
|
package/dist/lanes/app.js
CHANGED
|
@@ -10,7 +10,7 @@ import { defineTool, ToolRefusalError } from "../tool-types.js";
|
|
|
10
10
|
import { wireCall, wireDownloadPackageStream, wireRows, WireError } from "../wire.js";
|
|
11
11
|
import { isWithinRoot } from "../artifacts.js";
|
|
12
12
|
import { readZipEntries } from "../zip.js";
|
|
13
|
-
import { resolveApplicationScope } from "../support.js";
|
|
13
|
+
import { resolveApplicationScope, mapBounded } from "../support.js";
|
|
14
14
|
import { APP_LANE_CONTRACT } from "./app-contract.js";
|
|
15
15
|
import { readAppTree } from "./folder.js";
|
|
16
16
|
const APP_LANE = APP_LANE_CONTRACT.lane;
|
|
@@ -299,12 +299,30 @@ export function registerAppLane(tools) {
|
|
|
299
299
|
description: APP_TOOLS["app.list"].description,
|
|
300
300
|
inputSchema: { environment: environmentArg, capability: capabilityArg },
|
|
301
301
|
handler: async (ctx, args, self) => governedRead(ctx, self, args, async (session) => {
|
|
302
|
-
const
|
|
302
|
+
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.applicationList, query: {} })).data);
|
|
303
|
+
// B3(0.8.4 真机):旧实现是 `Promise.all` **无界**扇出——每个应用一条
|
|
304
|
+
// `/apppackage/trees`,13 个应用=13 条并发(每跳后端还会 bindWorkflow 递归
|
|
305
|
+
// 查流程模板)。真机同会话 `model.list --allApplications`(同一 list 端点、
|
|
306
|
+
// trees 并发限 4)全正常,只有 app.list 连续 8 次 `fetch failed`。
|
|
307
|
+
// 并发限到 4(与 model.list 同口径),并让**单个应用**失败只进 failed[],
|
|
308
|
+
// 不再拖垮整条读。全部失败才抛(读面回 uncertain + 端点/分类诊断)。
|
|
309
|
+
const failed = [];
|
|
310
|
+
let firstError;
|
|
311
|
+
const applications = await mapBounded(rows, 4, async (row) => {
|
|
303
312
|
const code = String(row.appCode ?? row.code);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
313
|
+
try {
|
|
314
|
+
const tree = await readAppTree(session, code);
|
|
315
|
+
const modelCount = tree.reduce((count, node) => count + (node.type === "BizModel" ? 1 : 0), 0);
|
|
316
|
+
return { code, name: row.appName ?? row.name, groupId: row.groupId, modelCount };
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
firstError ??= error;
|
|
320
|
+
failed.push({ applicationCode: code, reason: (error instanceof Error ? error.message : String(error)).slice(0, 300) });
|
|
321
|
+
return { code, name: row.appName ?? row.name, groupId: row.groupId };
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
if (failed.length > 0 && failed.length === rows.length)
|
|
325
|
+
throw firstError;
|
|
308
326
|
// r29f F2:与 discover_environment 同构——一眼判断「内联是否全集」。
|
|
309
327
|
// 应用通常个位数,默认内联 + omitted:false;大租户由 governedRead 外置时
|
|
310
328
|
// 仍保留 applicationsCount,并由 diet 路径标 omitted。
|
|
@@ -312,6 +330,14 @@ export function registerAppLane(tools) {
|
|
|
312
330
|
applications,
|
|
313
331
|
applicationsCount: applications.length,
|
|
314
332
|
omitted: false,
|
|
333
|
+
...(failed.length > 0
|
|
334
|
+
? {
|
|
335
|
+
applicationsFailed: failed.length,
|
|
336
|
+
failed,
|
|
337
|
+
partial: true,
|
|
338
|
+
hint: `${failed.length}/${applications.length} 个应用的目录树读取失败(见 failed[]):applications 清单仍完整,但这些应用的 modelCount 缺失;先按 reason 重查或走 model.list --allApplications。`,
|
|
339
|
+
}
|
|
340
|
+
: {}),
|
|
315
341
|
};
|
|
316
342
|
}, {
|
|
317
343
|
target: "app.list",
|
|
@@ -321,6 +347,8 @@ export function registerAppLane(tools) {
|
|
|
321
347
|
applicationsCount: apps.length,
|
|
322
348
|
omitted: true,
|
|
323
349
|
applications: apps.slice(0, 20),
|
|
350
|
+
// B3:部分失败是结论本身(哪个应用读不到),diet 不得吞掉。
|
|
351
|
+
...(result.applicationsFailed !== undefined ? { applicationsFailed: result.applicationsFailed, failed: result.failed, partial: true, hint: result.hint } : {}),
|
|
324
352
|
tablesHint: "applications 已截断内联前 20 条(omitted:true);全集在 detailArtifactId,用 --jq applications[].code 或 artifact get 取回。",
|
|
325
353
|
};
|
|
326
354
|
},
|