@hcmai/sdk 0.3.17 → 0.4.1

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/index.js CHANGED
@@ -1083,18 +1083,18 @@ async function action(http, model, actionName, input) {
1083
1083
  if (scope === "object" && !input.id) {
1084
1084
  throw new Error(`object action ${model}.${actionName} requires id`);
1085
1085
  }
1086
- const path20 = scope === "object" ? `/api/models/${model}/${input.id}/action/${actionName}` : `/api/models/${model}/action/${actionName}`;
1086
+ const path24 = scope === "object" ? `/api/models/${model}/${input.id}/action/${actionName}` : `/api/models/${model}/action/${actionName}`;
1087
1087
  const resp = await (async () => {
1088
1088
  if (method === "GET") {
1089
- return http.get(path20, { params: queryParams(input) });
1089
+ return http.get(path24, { params: queryParams(input) });
1090
1090
  }
1091
1091
  if (method === "DELETE") {
1092
- return http.delete(path20, { params: queryParams(input) });
1092
+ return http.delete(path24, { params: queryParams(input) });
1093
1093
  }
1094
1094
  if (method === "PUT") {
1095
- return http.put(path20, scope === "object" ? objectBody(input) : classBody(input));
1095
+ return http.put(path24, scope === "object" ? objectBody(input) : classBody(input));
1096
1096
  }
1097
- return http.post(path20, scope === "object" ? objectBody(input) : classBody(input));
1097
+ return http.post(path24, scope === "object" ? objectBody(input) : classBody(input));
1098
1098
  })();
1099
1099
  return resp.data;
1100
1100
  }
@@ -5215,18 +5215,18 @@ async function listTenantMeta(http, opts = {}) {
5215
5215
  const items = payload?.items ?? payload?.list ?? payload?.records ?? [];
5216
5216
  return { items, total: payload?.total, raw: payload };
5217
5217
  }
5218
- async function getTenantMeta(http, path20) {
5219
- const resp = await http.get("/api/tenant-meta/meta", { params: { path: path20 } });
5218
+ async function getTenantMeta(http, path24) {
5219
+ const resp = await http.get("/api/tenant-meta/meta", { params: { path: path24 } });
5220
5220
  const payload = resp.data?.data ?? resp.data;
5221
5221
  if (typeof payload === "string") return payload;
5222
5222
  return String(payload?.content ?? "");
5223
5223
  }
5224
- async function saveTenantMeta(http, path20, content) {
5225
- const resp = await http.put("/api/tenant-meta/meta", { content }, { params: { path: path20 } });
5224
+ async function saveTenantMeta(http, path24, content) {
5225
+ const resp = await http.put("/api/tenant-meta/meta", { content }, { params: { path: path24 } });
5226
5226
  return resp.data?.data ?? resp.data;
5227
5227
  }
5228
- async function deleteTenantMeta(http, path20) {
5229
- const resp = await http.delete("/api/tenant-meta/meta", { params: { path: path20 } });
5228
+ async function deleteTenantMeta(http, path24) {
5229
+ const resp = await http.delete("/api/tenant-meta/meta", { params: { path: path24 } });
5230
5230
  return resp.data?.data ?? resp.data;
5231
5231
  }
5232
5232
 
@@ -5328,14 +5328,14 @@ function resolveSkillInstallOrder(manifest2, targetId) {
5328
5328
  throw invalid(`\u6280\u80FD\u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728 ${targetId}`);
5329
5329
  }
5330
5330
  const state = /* @__PURE__ */ new Map();
5331
- const path20 = [];
5331
+ const path24 = [];
5332
5332
  const order = [];
5333
5333
  const visit = (id, requiredBy) => {
5334
5334
  const current = state.get(id);
5335
5335
  if (current === "done") return;
5336
5336
  if (current === "visiting") {
5337
- const cycleStart = path20.indexOf(id);
5338
- const cycle = [...path20.slice(Math.max(0, cycleStart)), id];
5337
+ const cycleStart = path24.indexOf(id);
5338
+ const cycle = [...path24.slice(Math.max(0, cycleStart)), id];
5339
5339
  throw invalid(`\u6280\u80FD\u4F9D\u8D56\u5B58\u5728\u73AF: ${cycle.join(" -> ")}`);
5340
5340
  }
5341
5341
  const skill = byId.get(id);
@@ -5344,11 +5344,11 @@ function resolveSkillInstallOrder(manifest2, targetId) {
5344
5344
  }
5345
5345
  assertSafeSkillId(skill.id);
5346
5346
  state.set(id, "visiting");
5347
- path20.push(id);
5347
+ path24.push(id);
5348
5348
  for (const required2 of normalizeRequirements(skill.requires, skill.id)) {
5349
5349
  visit(required2, skill.id);
5350
5350
  }
5351
- path20.pop();
5351
+ path24.pop();
5352
5352
  state.set(id, "done");
5353
5353
  order.push(skill);
5354
5354
  };
@@ -5439,11 +5439,11 @@ async function resetSettingItem(http, domain, namespace, settingKey, revision) {
5439
5439
  function parseSettingAssignment(raw) {
5440
5440
  const eq = raw.indexOf("=");
5441
5441
  if (eq <= 0) throw new Error(`--set \u9700\u8981 namespace.key=value \u5F62\u6001\uFF0C\u6536\u5230 "${raw}"`);
5442
- const path20 = raw.slice(0, eq).trim();
5442
+ const path24 = raw.slice(0, eq).trim();
5443
5443
  const value = raw.slice(eq + 1);
5444
- const dot = path20.lastIndexOf(".");
5445
- if (dot <= 0) throw new Error(`--set \u7684\u952E\u9700\u542B namespace\uFF0C\u5982 security.password.passwordPolicy=complex\uFF0C\u6536\u5230 "${path20}"`);
5446
- return { namespace: path20.slice(0, dot), settingKey: path20.slice(dot + 1), value };
5444
+ const dot = path24.lastIndexOf(".");
5445
+ if (dot <= 0) throw new Error(`--set \u7684\u952E\u9700\u542B namespace\uFF0C\u5982 security.password.passwordPolicy=complex\uFF0C\u6536\u5230 "${path24}"`);
5446
+ return { namespace: path24.slice(0, dot), settingKey: path24.slice(dot + 1), value };
5447
5447
  }
5448
5448
 
5449
5449
  // src/fde/layout.ts
@@ -5687,8 +5687,8 @@ var WorkLayout = class {
5687
5687
  }
5688
5688
  /** 读出**文本**,按 UTF-8 严格解码(BOM 先剥掉)。解不出时抛 `TypeError`。 */
5689
5689
  readText(rel) {
5690
- const bytes = this.readBytes(rel);
5691
- const text2 = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
5690
+ const bytes2 = this.readBytes(rel);
5691
+ const text2 = new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
5692
5692
  return text2.startsWith("\uFEFF") ? text2.slice(1) : text2;
5693
5693
  }
5694
5694
  /**
@@ -5832,11 +5832,11 @@ function classifyStatus(status) {
5832
5832
  return "bad-response";
5833
5833
  }
5834
5834
  var CAPABILITIES_HEADER = "x-hcm-capabilities";
5835
- function buildUrl(path20, params) {
5835
+ function buildUrl(path24, params) {
5836
5836
  const entries = Object.entries(params ?? {}).filter(([, v]) => v !== void 0 && v !== null);
5837
- if (entries.length === 0) return path20;
5837
+ if (entries.length === 0) return path24;
5838
5838
  const qs = entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join("&");
5839
- return `${path20}${path20.includes("?") ? "&" : "?"}${qs}`;
5839
+ return `${path24}${path24.includes("?") ? "&" : "?"}${qs}`;
5840
5840
  }
5841
5841
  function lowerHeaders(raw) {
5842
5842
  const out = {};
@@ -5878,14 +5878,14 @@ function httpProbe(http, capabilities) {
5878
5878
  const headers = { [CAPABILITIES_HEADER]: capabilities };
5879
5879
  const probe = {
5880
5880
  capabilities,
5881
- get(path20, params) {
5881
+ get(path24, params) {
5882
5882
  return once(
5883
- () => http.get(buildUrl(path20, params), { headers, validateStatus: () => true })
5883
+ () => http.get(buildUrl(path24, params), { headers, validateStatus: () => true })
5884
5884
  );
5885
5885
  },
5886
- post(path20, body) {
5886
+ post(path24, body) {
5887
5887
  return once(
5888
- () => http.post(path20, body, {
5888
+ () => http.post(path24, body, {
5889
5889
  headers: { ...headers, "content-type": "application/json" },
5890
5890
  validateStatus: () => true
5891
5891
  })
@@ -5976,7 +5976,7 @@ async function crawlModels(probe) {
5976
5976
  const healthy = Boolean(out.body) && typeof out.body === "object" && !Array.isArray(out.body);
5977
5977
  const body = healthy ? { ...out.body } : { totalCount: 0, typeCounts: {}, models: [] };
5978
5978
  const rows = Array.isArray(body.models) ? body.models : void 0;
5979
- const premise = {
5979
+ const premise2 = {
5980
5980
  // 前提显式断言:totalCount 与 models 长度不符时,后续任何「共 N 个模型」都不成立。
5981
5981
  totalCountMatchesListLength: Boolean(healthy && rows !== void 0 && body.totalCount === rows.length),
5982
5982
  responseShape: shapeOf(out.body),
@@ -5985,10 +5985,10 @@ async function crawlModels(probe) {
5985
5985
  // 撞键与否**恒有值**:没有这个键时「没撞」与「没检查过」在产物里同形。
5986
5986
  collidedWithServerKey: Object.prototype.hasOwnProperty.call(body, KIT_PREMISE_KEY)
5987
5987
  };
5988
- if (premise.collidedWithServerKey) {
5989
- premise.serverValue = body[KIT_PREMISE_KEY];
5988
+ if (premise2.collidedWithServerKey) {
5989
+ premise2.serverValue = body[KIT_PREMISE_KEY];
5990
5990
  }
5991
- body[KIT_PREMISE_KEY] = premise;
5991
+ body[KIT_PREMISE_KEY] = premise2;
5992
5992
  return body;
5993
5993
  }
5994
5994
  async function crawlMeta(probe, modelKeys2, metaType = DEFAULT_META_TYPE) {
@@ -5997,8 +5997,8 @@ async function crawlMeta(probe, modelKeys2, metaType = DEFAULT_META_TYPE) {
5997
5997
  const results = probe.getMany ? await probe.getMany([...paths.keys()]) : await sequentialGet(probe, [...paths.keys()]);
5998
5998
  const metas = {};
5999
5999
  const unavailable = [];
6000
- for (const [path20, key] of paths) {
6001
- const out = results[path20];
6000
+ for (const [path24, key] of paths) {
6001
+ const out = results[path24];
6002
6002
  if (out === void 0) {
6003
6003
  unavailable.push({
6004
6004
  modelKey: key,
@@ -6009,8 +6009,8 @@ async function crawlMeta(probe, modelKeys2, metaType = DEFAULT_META_TYPE) {
6009
6009
  });
6010
6010
  continue;
6011
6011
  }
6012
- const isObject2 = Boolean(out.body) && typeof out.body === "object" && !Array.isArray(out.body);
6013
- if (out.error === "ok" && isObject2) {
6012
+ const isObject3 = Boolean(out.body) && typeof out.body === "object" && !Array.isArray(out.body);
6013
+ if (out.error === "ok" && isObject3) {
6014
6014
  metas[key] = out.body;
6015
6015
  continue;
6016
6016
  }
@@ -6125,9 +6125,9 @@ function extractFieldRows(metas) {
6125
6125
  const rows = [];
6126
6126
  const dropped = [];
6127
6127
  for (const [model, body] of Object.entries(metas)) {
6128
- const { fields, problem: problem5 } = metaFields(body);
6129
- if (problem5) {
6130
- dropped.push(`${model}: ${problem5}\uFF0C\u6574\u4E2A\u6A21\u578B\u6CA1\u6709\u5B57\u6BB5\u8FDB\u7D22\u5F15`);
6128
+ const { fields, problem: problem6 } = metaFields(body);
6129
+ if (problem6) {
6130
+ dropped.push(`${model}: ${problem6}\uFF0C\u6574\u4E2A\u6A21\u578B\u6CA1\u6709\u5B57\u6BB5\u8FDB\u7D22\u5F15`);
6131
6131
  continue;
6132
6132
  }
6133
6133
  fields.forEach((f, index) => {
@@ -6214,8 +6214,8 @@ async function collectActionGates(probe, modelKeys2, state = "") {
6214
6214
  const statesEchoed = /* @__PURE__ */ new Set();
6215
6215
  let noStateEcho = 0;
6216
6216
  let answered = 0;
6217
- for (const [path20, model] of paths) {
6218
- const out = results[path20];
6217
+ for (const [path24, model] of paths) {
6218
+ const out = results[path24];
6219
6219
  if (out === void 0) {
6220
6220
  unavailable.push({
6221
6221
  modelKey: model,
@@ -6594,8 +6594,8 @@ async function collectMutation(probe, modelKeys2) {
6594
6594
  const results = probe.getMany ? await probe.getMany([...paths.keys()]) : await sequentialGet(probe, [...paths.keys()]);
6595
6595
  const mutation = {};
6596
6596
  const problems = [];
6597
- for (const [path20, key] of paths) {
6598
- const out = results[path20];
6597
+ for (const [path24, key] of paths) {
6598
+ const out = results[path24];
6599
6599
  if (out === void 0) {
6600
6600
  problems.push(`${key}: mutation-capability ${BATCH_LOST}`);
6601
6601
  mutation[key] = Object.fromEntries(
@@ -6666,7 +6666,7 @@ function buildMapping(metas, edges, mutation, codeTables = []) {
6666
6666
  for (const e of edges) byField.set(`${e.fromModel} ${e.fromField}`, e);
6667
6667
  const sheets = [];
6668
6668
  for (const modelKey2 of Object.keys(metas).sort()) {
6669
- const { fields, problem: problem5 } = metaFields(metas[modelKey2]);
6669
+ const { fields, problem: problem6 } = metaFields(metas[modelKey2]);
6670
6670
  const rows = [];
6671
6671
  for (const f of fields) {
6672
6672
  if (!isRecord2(f)) continue;
@@ -6716,7 +6716,7 @@ function buildMapping(metas, edges, mutation, codeTables = []) {
6716
6716
  fieldCount: rows.length,
6717
6717
  // 🔴 `null` = 载荷判读正常(fieldCount=0 就是「这个模型确实没字段」);
6718
6718
  // 非 null = **爬过、但判不出字段**,此时 fieldCount=0 不代表「没字段」。
6719
- fieldsProblem: problem5 ?? null,
6719
+ fieldsProblem: problem6 ?? null,
6720
6720
  fields: rows
6721
6721
  });
6722
6722
  }
@@ -6862,10 +6862,10 @@ function renderModelsMd(modelsBody, metas, gates, dropped = []) {
6862
6862
  for (const d of dropped) parts.push(`> - ${d}`);
6863
6863
  parts.push("");
6864
6864
  }
6865
- const listed2 = /* @__PURE__ */ new Set();
6865
+ const listed3 = /* @__PURE__ */ new Set();
6866
6866
  for (const m of modelEntries(modelsBody)) {
6867
6867
  const key = String(m.modelKey ?? "");
6868
- listed2.add(key);
6868
+ listed3.add(key);
6869
6869
  const name = m.name || "";
6870
6870
  parts.push(name ? `## ${key} \xB7 ${name}` : `## ${key}`);
6871
6871
  parts.push("");
@@ -6873,9 +6873,9 @@ function renderModelsMd(modelsBody, metas, gates, dropped = []) {
6873
6873
  if (!Object.prototype.hasOwnProperty.call(metas, key)) {
6874
6874
  parts.push(FIELDS_NOT_CRAWLED);
6875
6875
  } else {
6876
- const { fields, problem: problem5 } = metaFields(metas[key]);
6876
+ const { fields, problem: problem6 } = metaFields(metas[key]);
6877
6877
  parts.push(
6878
- problem5 === void 0 ? `- \u5B57\u6BB5\u6570\uFF1A${fields.length}` : `- \u5B57\u6BB5\u6570\uFF1A\u65E0\u6CD5\u5224\u8BFB\uFF08${problem5}\uFF09\uFF0C\u8BE5\u6A21\u578B\u6CA1\u6709\u5B57\u6BB5\u8FDB\u7D22\u5F15`
6878
+ problem6 === void 0 ? `- \u5B57\u6BB5\u6570\uFF1A${fields.length}` : `- \u5B57\u6BB5\u6570\uFF1A\u65E0\u6CD5\u5224\u8BFB\uFF08${problem6}\uFF09\uFF0C\u8BE5\u6A21\u578B\u6CA1\u6709\u5B57\u6BB5\u8FDB\u7D22\u5F15`
6879
6879
  );
6880
6880
  }
6881
6881
  const gs = byModel.get(key) ?? [];
@@ -6887,7 +6887,7 @@ function renderModelsMd(modelsBody, metas, gates, dropped = []) {
6887
6887
  }
6888
6888
  parts.push("");
6889
6889
  }
6890
- const orphans = gates.filter((g) => !listed2.has(String(g.model ?? "")));
6890
+ const orphans = gates.filter((g) => !listed3.has(String(g.model ?? "")));
6891
6891
  if (orphans.length > 0) {
6892
6892
  parts.push(ORPHAN_TITLE);
6893
6893
  parts.push("");
@@ -7040,11 +7040,11 @@ async function collectCodeTables(probe, modelEntries2, opts = {}) {
7040
7040
  keys.push(key);
7041
7041
  }
7042
7042
  for (const key of [...new Set(keys)].sort()) {
7043
- const path20 = listPath(key);
7043
+ const path24 = listPath(key);
7044
7044
  const started = tick();
7045
7045
  let requests = 0;
7046
7046
  let truncatedBy = null;
7047
- const probeOut = await post.call(probe, path20, { page: 0, size: 0 });
7047
+ const probeOut = await post.call(probe, path24, { page: 0, size: 0 });
7048
7048
  requests += 1;
7049
7049
  let total = null;
7050
7050
  let reason = null;
@@ -7093,7 +7093,7 @@ async function collectCodeTables(probe, modelEntries2, opts = {}) {
7093
7093
  failed = `\u89E6\u53D1\u5DE5\u5177\u7684\u6BCF\u8868${which === "requests" ? "\u8BF7\u6C42" : "\u5899\u949F"}\u4E0A\u9650\uFF08${which === "requests" ? `\u5DF2\u53D1 ${requests} \u6B21\u8BF7\u6C42` : `\u5DF2\u82B1 ${elapsed.toFixed(3)}s`}\uFF09\uFF0C\u505C\u5728\u7B2C ${page} \u9875\uFF0C\u5DF2\u6536 ${rows.length} \u884C / \u8BA1\u6570 ${total} \u884C\uFF0C\u672C\u8868\u6807 partial\u3002**\u8FD9\u662F\u5DE5\u5177\u7684\u622A\u65AD\uFF0C\u4E0D\u662F\u670D\u52A1\u7AEF\u7684\u6BDB\u75C5** \u2014\u2014 \u8C03\u5927 valuedomain.${which === "requests" ? "MAX_REQUESTS_PER_TABLE" : "MAX_SECONDS_PER_TABLE"} \u6216\u7ED9 collectCodeTables \u4F20 ${which === "requests" ? "maxRequests" : "maxSeconds"} \u540E\u91CD\u8DD1\u5C31\u80FD\u53D6\u5168`;
7094
7094
  break;
7095
7095
  }
7096
- const out = await post.call(probe, path20, { page, size: PAGE_SIZE });
7096
+ const out = await post.call(probe, path24, { page, size: PAGE_SIZE });
7097
7097
  requests += 1;
7098
7098
  if (out.error !== "ok") {
7099
7099
  failed = `\u7B2C ${page} \u9875\u5931\u8D25\uFF08HTTP ${out.status} / ${out.error}\uFF09`;
@@ -7833,7 +7833,7 @@ async function loadKeyIndex(client, model, keyFields, pageSize = PAGE_SIZE_DEFAU
7833
7833
  for (const name of ["id", ...fields]) {
7834
7834
  if (!projected.includes(name)) projected.push(name);
7835
7835
  }
7836
- const path20 = listPath2(model);
7836
+ const path24 = listPath2(model);
7837
7837
  const idx = /* @__PURE__ */ new Map();
7838
7838
  let total = null;
7839
7839
  let pages = 0;
@@ -7850,7 +7850,7 @@ async function loadKeyIndex(client, model, keyFields, pageSize = PAGE_SIZE_DEFAU
7850
7850
  let repeatedIds = 0;
7851
7851
  while (total === null || received < total) {
7852
7852
  const pageNo = pages;
7853
- const out = await client.post(path20, {
7853
+ const out = await client.post(path24, {
7854
7854
  page: pageNo,
7855
7855
  size: pageSize,
7856
7856
  fields: projected,
@@ -8042,8 +8042,8 @@ var CFB_MAGIC = Buffer.from([208, 207, 17, 224, 161, 177, 26, 225]);
8042
8042
  var ENCRYPTED_PACKAGE = Buffer.from("EncryptedPackage", "utf16le");
8043
8043
  var MAX_ENTRY_BYTES = 128 * 1024 * 1024;
8044
8044
  var SCAN_CHUNK_BYTES = 1024 * 1024;
8045
- function scanFor(path20, needle = ENCRYPTED_PACKAGE, budget = MAX_ENTRY_BYTES) {
8046
- const fd = openSync2(path20, "r");
8045
+ function scanFor(path24, needle = ENCRYPTED_PACKAGE, budget = MAX_ENTRY_BYTES) {
8046
+ const fd = openSync2(path24, "r");
8047
8047
  try {
8048
8048
  let tail = Buffer.alloc(0);
8049
8049
  let seen = 0;
@@ -8064,9 +8064,9 @@ function scanFor(path20, needle = ENCRYPTED_PACKAGE, budget = MAX_ENTRY_BYTES) {
8064
8064
  closeSync2(fd);
8065
8065
  }
8066
8066
  }
8067
- function isCfb(path20) {
8068
- if (statSync2(path20).size < CFB_MAGIC.length) return false;
8069
- const fd = openSync2(path20, "r");
8067
+ function isCfb(path24) {
8068
+ if (statSync2(path24).size < CFB_MAGIC.length) return false;
8069
+ const fd = openSync2(path24, "r");
8070
8070
  try {
8071
8071
  const head = Buffer.alloc(CFB_MAGIC.length);
8072
8072
  const n = readSync(fd, head, 0, CFB_MAGIC.length, 0);
@@ -8075,9 +8075,9 @@ function isCfb(path20) {
8075
8075
  closeSync2(fd);
8076
8076
  }
8077
8077
  }
8078
- function classifyCfb(path20, budget = MAX_ENTRY_BYTES) {
8079
- if (!isCfb(path20)) return "not-cfb";
8080
- switch (scanFor(path20, ENCRYPTED_PACKAGE, budget)) {
8078
+ function classifyCfb(path24, budget = MAX_ENTRY_BYTES) {
8079
+ if (!isCfb(path24)) return "not-cfb";
8080
+ switch (scanFor(path24, ENCRYPTED_PACKAGE, budget)) {
8081
8081
  case "found":
8082
8082
  return "encrypted";
8083
8083
  case "absent":
@@ -9978,6 +9978,19 @@ function problem(code, model, message, hint, entry) {
9978
9978
  // src/fde/seed/plan.ts
9979
9979
  var VERSION2 = 1;
9980
9980
  var IMPORT_PLAN_FILE = "import-plan.json";
9981
+ var PLAN_PROBLEM_CODES = [
9982
+ "DUPLICATE_BUSINESS_KEY",
9983
+ "DANGLING_PARENT",
9984
+ "ROW_LEVEL_CYCLE",
9985
+ "MODEL_ORDER_CONFLICT",
9986
+ "BUSINESS_KEY_VALUE_MISSING",
9987
+ "BUSINESS_KEY_REFERENCE_UNRESOLVED",
9988
+ "SELF_REFERENCE_UNUSABLE",
9989
+ "EXISTING_INDEX_MISSING",
9990
+ "SOURCE_ROWS_MISSING",
9991
+ "MAPPING_NOT_USABLE",
9992
+ "PLAN_CHECKS_SKIPPED"
9993
+ ];
9981
9994
  var PREMISE_CODES2 = [
9982
9995
  "DUPLICATE_BUSINESS_KEY",
9983
9996
  "BUSINESS_KEY_VALUE_MISSING",
@@ -10306,14 +10319,14 @@ function planModel(mm, tables, indexes, entry, indexError, keyFieldsByModel, res
10306
10319
  byCode.set(got.code, list);
10307
10320
  }
10308
10321
  });
10309
- const listed2 = (items) => items.slice(0, MAX_LISTED).join("\u3001") + (items.length > MAX_LISTED ? `\u2026\uFF08\u5171 ${items.length} \u884C\uFF09` : "");
10322
+ const listed3 = (items) => items.slice(0, MAX_LISTED).join("\u3001") + (items.length > MAX_LISTED ? `\u2026\uFF08\u5171 ${items.length} \u884C\uFF09` : "");
10310
10323
  if (byCode.has("BUSINESS_KEY_VALUE_MISSING")) {
10311
10324
  const unusable = byCode.get("BUSINESS_KEY_VALUE_MISSING");
10312
10325
  problems.push(
10313
10326
  problem2(
10314
10327
  "BUSINESS_KEY_VALUE_MISSING",
10315
10328
  mm.model,
10316
- `${mm.model} \u6709 ${unusable.length} \u884C\u53D6\u4E0D\u5230\u53EF\u7528\u7684\u4E1A\u52A1\u952E [${keyFields.map((f) => `'${f}'`).join(", ")}]\uFF1A${listed2(unusable)}`,
10329
+ `${mm.model} \u6709 ${unusable.length} \u884C\u53D6\u4E0D\u5230\u53EF\u7528\u7684\u4E1A\u52A1\u952E [${keyFields.map((f) => `'${f}'`).join(", ")}]\uFF1A${listed3(unusable)}`,
10317
10330
  "\u7A7A\u4E1A\u52A1\u952E\u5F53\u4E0D\u4E86\u5E42\u7B49\u652F\u70B9\uFF1A\u8FD9\u4E9B\u884C\u5EFA\u8FDB\u53BB\u4E4B\u540E\uFF0C\u4E0B\u4E00\u8F6E\u56DE\u8BFB\u5339\u914D\u4E0D\u4E0A\uFF0C\u4E8E\u662F\u518D\u5EFA\u4E00\u904D\u3002\u5148\u628A\u6E90\u8868\u91CC\u8FD9\u51E0\u884C\u7684\u952E\u5217\u8865\u9F50\uFF0C\u6216\u628A\u5B83\u4EEC\u4ECE\u8FD9\u4E00\u8F6E\u91CC\u53BB\u6389",
10318
10331
  entry
10319
10332
  )
@@ -10326,7 +10339,7 @@ function planModel(mm, tables, indexes, entry, indexError, keyFieldsByModel, res
10326
10339
  problem2(
10327
10340
  "BUSINESS_KEY_REFERENCE_UNRESOLVED",
10328
10341
  mm.model,
10329
- `${mm.model} \u6709 ${unresolved.length} \u884C\u7684**\u4E1A\u52A1\u952E\u91CC\u6709\u5F15\u7528\u5B57\u6BB5\u6362\u4E0D\u51FA id** \u21D2 \u7B97\u4E0D\u51FA\u8FD9\u4E00\u884C\u7684\u8EAB\u4EFD\uFF1A${listed2(unresolved)}`,
10342
+ `${mm.model} \u6709 ${unresolved.length} \u884C\u7684**\u4E1A\u52A1\u952E\u91CC\u6709\u5F15\u7528\u5B57\u6BB5\u6362\u4E0D\u51FA id** \u21D2 \u7B97\u4E0D\u51FA\u8FD9\u4E00\u884C\u7684\u8EAB\u4EFD\uFF1A${listed3(unresolved)}`,
10330
10343
  "\u{1F534} \u4E1A\u52A1\u952E\u5E26 resolveBy \u65F6\uFF0C\u884C\u952E\u53D6\u7684\u662F**\u89E3\u6790\u540E\u7684 id** \u2014\u2014 \u670D\u52A1\u7AEF\u5B58\u7684\u3001\u56DE\u8BFB\u641C\u7684\u3001\u65E2\u5B58\u7D22\u5F15\u5EFA\u7684\u90FD\u662F\u90A3\u4E2A id\uFF0C\u53D6\u6E90\u8868\u503C\u4F1A\u4E0E\u5B83\u4EEC\u5168\u4F53\u9519\u4F4D\u3002\u6362\u4E0D\u51FA id \u5C31\u6CA1\u6709\u8EAB\u4EFD\uFF0C\u8FD9\u4E00\u884C**\u4E0D\u8FDB\u8BA1\u5212**\u3002\u89E3\u6790**\u53EA\u67E5\u65E2\u5B58\u7D22\u5F15**\uFF08\u672C kit \u4E0D\u5EFA\u8DE8\u6A21\u578B\u7684\u6CE2\uFF09\uFF0C\u6240\u4EE5\u5173\u8054\u8868\u8FD9\u4E00\u65CF\u8981\u8D70**\u4E24\u8D9F**\uFF1A\u5148\u5355\u72EC\u8DD1\u4E00\u8F6E\u628A\u88AB\u5F15\u7528\u7684\u90A3\u4E2A\u6A21\u578B\u5BFC\u5B8C\uFF0C**\u518D\u91CD\u8DD1 plan** \u5BFC\u8FD9\u4E00\u4E2A\u3002\u9010\u884C\u62EC\u53F7\u91CC\u90A3\u4E2A\u6863\u8BF4\u7684\u662F\u6362\u4E0D\u51FA\u7684\u539F\u56E0\uFF1Aref-not-found = \u7D22\u5F15\u91CC\u6CA1\u6709\u8FD9\u4E2A\u503C\uFF1Bunresolved-no-index = \u5DE5\u4EF6\u7684 models[] \u91CC\u6CA1\u6709\u90A3\u4E2A\u6A21\u578B\uFF1Bref-key-mismatch = \u90A3\u4E2A\u6A21\u578B\u7684 businessKey \u4E0E\u8FD9\u91CC\u7684 keyField \u4E0D\u662F\u540C\u4E00\u4E2A\u952E",
10331
10344
  entry
10332
10345
  )
@@ -10604,16 +10617,16 @@ function rowCycles(parents) {
10604
10617
  const cycles = [];
10605
10618
  for (const start of [...parents.keys()].sort((a, b) => a - b)) {
10606
10619
  if (done.has(start)) continue;
10607
- const path20 = [];
10620
+ const path24 = [];
10608
10621
  const seen = /* @__PURE__ */ new Map();
10609
10622
  let node = start;
10610
10623
  while (node !== void 0 && !seen.has(node) && !done.has(node)) {
10611
- seen.set(node, path20.length);
10612
- path20.push(node);
10624
+ seen.set(node, path24.length);
10625
+ path24.push(node);
10613
10626
  node = parents.get(node);
10614
10627
  }
10615
- if (node !== void 0 && seen.has(node)) cycles.push(path20.slice(seen.get(node)));
10616
- for (const n of path20) done.add(n);
10628
+ if (node !== void 0 && seen.has(node)) cycles.push(path24.slice(seen.get(node)));
10629
+ for (const n of path24) done.add(n);
10617
10630
  }
10618
10631
  return cycles;
10619
10632
  }
@@ -11199,9 +11212,9 @@ function enumKey(model, field) {
11199
11212
  }
11200
11213
  var Utf8Error = class extends Error {
11201
11214
  };
11202
- function decodeUtf8(bytes) {
11215
+ function decodeUtf8(bytes2) {
11203
11216
  try {
11204
- return new TextDecoder("utf-8", { fatal: true }).decode(bytes).replace(/^\uFEFF/, "");
11217
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes2).replace(/^\uFEFF/, "");
11205
11218
  } catch {
11206
11219
  throw new Utf8Error("not utf-8");
11207
11220
  }
@@ -11837,14 +11850,14 @@ var ROUND_HINT_ASSESSED = "\u4E0B\u9762\u6BCF\u4E00\u6761\u300C\u6CA1\u62A5\u51F
11837
11850
  var ROUND_HINT_NOT_ASSESSED = "\u26A0\uFE0F \u8FD9\u4E00\u4EFD\u6E05\u5355**\u6CA1\u6709\u300C\u4E0B\u9762\u6BCF\u4E00\u6761\u300D**\uFF1A\u5DE5\u4EF6\u81EA\u5DF1\u5148\u6CA1\u8FC7\u6821\u9A8C\uFF0C\u4E00\u6761\u5224\u636E\u90FD\u6CA1\u8DD1\uFF08\u770B RISK_NOT_BUILT \u4E0E modelsAssessed\uFF09\u3002\u6240\u4EE5\u672C\u6761\u6B64\u523B\u8FD8\u6CA1\u6709\u6CE2\u53CA\u5230\u4EFB\u4F55\u7ED3\u8BBA \u2014\u2014\u4F46\u5B83**\u4E0E\u90A3\u4EF6\u4E8B\u4E92\u4E0D\u66FF\u4EE3**\uFF1A\u5DE5\u4EF6\u4FEE\u597D\u4E4B\u540E\u5B83\u7167\u6837\u5728\uFF0C\u4E24\u4EF6\u4E8B\u5206\u522B\u4FEE\u3002";
11838
11851
  function roundProblems(roundPremise, assessed = true) {
11839
11852
  const out = [];
11840
- for (const premise of roundPremise ?? []) {
11841
- const p = rec(premise);
11853
+ for (const premise2 of roundPremise ?? []) {
11854
+ const p = rec(premise2);
11842
11855
  const raw = p === null ? void 0 : p.message;
11843
11856
  let message;
11844
11857
  if (typeof raw === "string" && raw) {
11845
11858
  message = raw;
11846
11859
  } else {
11847
- message = `\u95E8 0 \u7ED9\u7684\u8F6E\u6B21\u5224\u8BCD\u6E32\u67D3\u4E0D\u51FA\u6765\uFF08\u62FF\u5230\u7684\u662F ${JSON.stringify(premise)}\uFF0C\u5B83\u7684 \`message\` \u4E0D\u662F\u4E00\u53E5\u975E\u7A7A\u7684\u8BDD\uFF09\u2014\u2014 \u672C\u5C42\u4E0D\u66FF\u5B83\u5224\uFF0C\u4E5F**\u4E0D\u5F53\u6210 complete**`;
11860
+ message = `\u95E8 0 \u7ED9\u7684\u8F6E\u6B21\u5224\u8BCD\u6E32\u67D3\u4E0D\u51FA\u6765\uFF08\u62FF\u5230\u7684\u662F ${JSON.stringify(premise2)}\uFF0C\u5B83\u7684 \`message\` \u4E0D\u662F\u4E00\u53E5\u975E\u7A7A\u7684\u8BDD\uFF09\u2014\u2014 \u672C\u5C42\u4E0D\u66FF\u5B83\u5224\uFF0C\u4E5F**\u4E0D\u5F53\u6210 complete**`;
11848
11861
  }
11849
11862
  out.push(
11850
11863
  problem3(
@@ -12268,8 +12281,8 @@ function seedBaselines(out, tenant) {
12268
12281
  }
12269
12282
  var RC_DECIDING_FIELDS = ["plan.problems", "risk.problems", "risk.blocking"];
12270
12283
  function planRc(plan, risk) {
12271
- const premise = plan.problems.some((p) => p.kind === "premise") || risk.problems.some((p) => p.kind === "premise");
12272
- if (premise) return INIT_EXIT_CODES.premise;
12284
+ const premise2 = plan.problems.some((p) => p.kind === "premise") || risk.problems.some((p) => p.kind === "premise");
12285
+ if (premise2) return INIT_EXIT_CODES.premise;
12273
12286
  if (risk.blocking || plan.problems.length > 0) return INIT_EXIT_CODES.blocked;
12274
12287
  return INIT_EXIT_CODES.clean;
12275
12288
  }
@@ -12278,14 +12291,14 @@ function discardedColumnLines(notes) {
12278
12291
  return [`\u88AB\u4E22\u5F03\u7684\u65E0\u540D\u7A7A\u5217\uFF1A${notes.length} \u6761`, ...notes.map((n) => ` \xB7 ${JSON.stringify(n)}`)];
12279
12292
  }
12280
12293
  function planSummaryLine(plan, risk) {
12281
- const premise = risk.problems.filter((p) => p.kind === "premise");
12294
+ const premise2 = risk.problems.filter((p) => p.kind === "premise");
12282
12295
  const content = risk.problems.filter((p) => p.kind !== "premise");
12283
12296
  const blocking = risk.problems.filter(
12284
12297
  (p) => BLOCKING_CODES.includes(p.code) && !p.exempted
12285
12298
  );
12286
12299
  const where = [...new Set(blocking.map((p) => p.kind))].sort();
12287
12300
  const spread = where.length > 1 ? "\u6A2A\u8DE8\u4E0A\u9762\u4E24\u6863" : where.length === 1 ? `\u5168\u5728${where[0] === "premise" ? "\u524D\u63D0\u672A\u6210\u7ACB" : "\u5185\u5BB9\u7EA7"}\u6863` : "\u672C\u8F6E\u6CA1\u6709\u62E6\u8DEF\u9879";
12288
- return `\u98CE\u9669\uFF1Ablocking=${risk.blocking}\uFF0C\u5171 ${risk.problems.length} \u6761 = \u524D\u63D0\u672A\u6210\u7ACB ${premise.length} \u6761 + \u5185\u5BB9\u7EA7 ${content.length} \u6761\uFF1B\u5176\u4E2D\u62E6\u8DEF ${blocking.length} \u6761\uFF08${spread}\uFF0C\u4E0D\u53E6\u8BA1\uFF09\uFF1B\u8BA1\u5212\u95EE\u9898 ${plan.problems.length} \u6761`;
12301
+ return `\u98CE\u9669\uFF1Ablocking=${risk.blocking}\uFF0C\u5171 ${risk.problems.length} \u6761 = \u524D\u63D0\u672A\u6210\u7ACB ${premise2.length} \u6761 + \u5185\u5BB9\u7EA7 ${content.length} \u6761\uFF1B\u5176\u4E2D\u62E6\u8DEF ${blocking.length} \u6761\uFF08${spread}\uFF0C\u4E0D\u53E6\u8BA1\uFF09\uFF1B\u8BA1\u5212\u95EE\u9898 ${plan.problems.length} \u6761`;
12289
12302
  }
12290
12303
  function planProblemLines(plan, risk) {
12291
12304
  const lines = [];
@@ -12332,6 +12345,65 @@ function roundWarning(round) {
12332
12345
  return ROUND_WARNINGS[state ?? ""] ?? ROUND_WARNING_FALLBACK.replace("{state}", String(state));
12333
12346
  }
12334
12347
  var WARNED_ROUND_STATES = ROUND_STATES.filter((s) => s !== "complete");
12348
+ var RC_DECIDING_REPORT_FIELDS = ["aborted", "writeFailed", "quarantined", "blocked"];
12349
+ function applyRc(report) {
12350
+ if (report.aborted !== null || report.writeFailed || report.quarantined || report.blocked) {
12351
+ return INIT_EXIT_CODES.blocked;
12352
+ }
12353
+ return INIT_EXIT_CODES.clean;
12354
+ }
12355
+ var JOURNAL_STOP_KINDS = {
12356
+ "journal-unwritable": [
12357
+ "\u8FD9\u4E00\u8F6E**\u8DD1\u5230\u4E00\u534A\u505C\u4E86**\uFF1A\u53F0\u8D26\u5199\u4E0D\u4E0B\u53BB",
12358
+ "\u{1F534} \u5148\u5904\u7406\u78C1\u76D8 / \u6743\u9650\uFF0C\u518D\u5E26 `--resume` \u7EED\u8DD1\u3002",
12359
+ "\u{1F534} **\u8FD9\u4E00\u8F6E\u5DF2\u7ECF\u53D1\u51FA\u53BB\u7684\u5199\uFF0C\u53EA\u5728\u8FD9\u4EFD\u53F0\u8D26\u91CC\u6709\u8BB0\u5F55 \u2014\u2014 \u5148\u5907\u4EFD\u8D70\u518D\u52A8\u78C1\u76D8\uFF1B\u4E0D\u8981\u5220\u6389\u5B83\u91CD\u8DD1**\uFF0C\u90A3\u4F1A\u628A\u5DF2\u7ECF\u5EFA\u597D\u7684\u884C\u518D\u5EFA\u4E00\u904D\u3002"
12360
+ ],
12361
+ "bad-entry": [
12362
+ "\u8FD9\u4E00\u8F6E**\u505C\u5728\u8FD9\u91CC**\uFF1A\u8BA1\u5212\u91CC\u6709\u4E00\u884C\u7684\u4E1A\u52A1\u952E\u4E0D\u5408\u6CD5",
12363
+ "\u{1F534} \u8FD9\u662F `import-plan.json` **\u81EA\u5DF1**\u524D\u540E\u5BF9\u4E0D\u4E0A\uFF08\u884C\u952E\u6052\u662F\u4E00\u7EC4\u975E\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u8DDF\u53F0\u8D26\u5199\u5F97\u4E0B\u5199\u4E0D\u4E0B**\u6CA1\u6709\u5173\u7CFB**\u3002\u505A\u5F97\u5230\u7684\u4E0B\u4E00\u6B65\uFF1A\u5728\u8FD9\u4E2A work \u76EE\u5F55\u4E0A\u91CD\u65B0\u8DD1\u4E00\u6B21 `plan`\uFF0C\u8BA9\u5B83\u7167\u5DE5\u4EF6\u4E0E\u6E90\u8868\u91CD\u7B97\u4E00\u4EFD\u884C\u952E\uFF1B\u90A3\u4E00\u884C\u7684\u539F\u6587\u89C1\u4E0A\u9762\u65B9\u62EC\u53F7\u540E\u9762\u90A3\u53E5\u3002",
12364
+ ""
12365
+ ]
12366
+ };
12367
+ var JOURNAL_STOP_UNKNOWN = [
12368
+ "\u8FD9\u4E00\u8F6E**\u505C\u5728\u8FD9\u91CC**\uFF1A\u53F0\u8D26\u8FD9\u4E00\u5C42\u62A5\u4E86\u4E00\u6761\u672C\u5C42\u8BA4\u4E0D\u51FA\u7684\u6210\u56E0",
12369
+ "\u672C\u5C42**\u8BF4\u4E0D\u51FA**\u5B83\u5C5E\u4E8E\u54EA\u4E00\u6863\uFF08\u65B9\u62EC\u53F7\u91CC\u90A3\u4E2A reason \u4E0D\u5728\u672C\u5C42\u7684\u5206\u6863\u8868\u91CC\uFF09\u2014\u2014 \u7167\u4E0A\u9762\u7684\u539F\u6587\u4E0E\u5B83\u81EA\u5E26\u7684 hint \u5904\u7406\u3002\u672C\u5C42\u4E0D\u66FF\u4F60\u731C\u65B9\u5411\uFF1A\u6307\u9519\u65B9\u5411\u6BD4\u4E0D\u6307\u65B9\u5411\u66F4\u8D35\u3002",
12370
+ ""
12371
+ ];
12372
+ function journalNote(journalPath, whenPresent = "") {
12373
+ if (!existsSync7(journalPath)) {
12374
+ return ` \u53F0\u8D26 \`${journalPath}\` **\u6B64\u523B\u4E0D\u5728\u76D8\u4E0A**\uFF08\u672C\u5C42\u521A\u67E5\u8FC7\uFF09\u2014\u2014\u6240\u4EE5\u6CA1\u6709\u300C\u5DF2\u7ECF\u8BB0\u4E0B\u6765\u7684\u5199\u300D\u53EF\u4EE5\u62FF\u3002`;
12375
+ }
12376
+ return ` \u53F0\u8D26\u5728 \`${journalPath}\`\u3002${whenPresent}`;
12377
+ }
12378
+ var APPLY_CAVEAT = "\u26A0\uFE0F \u8BA1\u5212\u4E0E\u5DE5\u4EF6\u53EA\u5BF9\u8FC7\u4E24\u683C\uFF08\u6A21\u578B\u6E05\u5355\u3001businessKey.fields\uFF09\u3002\u5DE5\u4EF6\u91CC**\u8FD9\u4E24\u683C\u4E4B\u5916\u7684\u4E00\u5207**\u6539\u4E86 kit \u90FD**\u5BF9\u4E0D\u51FA\u6765** \u2014\u2014 \u5217\u6620\u5C04 / valueMap / \u5E38\u91CF / source.file / source.sheet / onExisting / headerRow / businessKey.sourceColumns \u90FD\u7B97\uFF08\u8BA1\u5212\u91CC\u6CA1\u6709\u5DE5\u4EF6\u6307\u7EB9\uFF09\u2014\u2014 \u5DE5\u4EF6\u6539\u8FC7\u5C31\u91CD\u65B0\u8DD1\u4E00\u6B21 `plan`\u3002";
12379
+ var DRY_RUN_TAIL = "\u2191 \u8FD9\u662F**\u5E72\u8DD1**\uFF1A\u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u6CA1\u6709\u53D1\u3002\u8981\u771F\u5199\uFF0C\u52A0 `--execute`\u3002";
12380
+ function planVsBaselinePremise(baselinePath, plannedRound, nowRound) {
12381
+ if (plannedRound === nowRound) return null;
12382
+ const notWaived = `\`${FORCE_STALE_FLAG_TEXT}\` \u4E0D\u8C41\u514D\u8FD9\u4E00\u6761 \u2014\u2014 \u5B83\u7BA1\u7684\u662F\u300C\u57FA\u7EBF\u5BF9\u4E0D\u5BF9\u5F97\u4E0A\u8FD9\u4E2A\u73AF\u5883\u300D\uFF0C\u4E0D\u662F\u300C\u8BA1\u5212\u5BF9\u4E0D\u5BF9\u5F97\u4E0A\u57FA\u7EBF\u300D\u3002`;
12383
+ if (plannedRound === null) {
12384
+ return [
12385
+ `\u8FD9\u4EFD\u8BA1\u5212**\u6CA1\u8BB0**\u57FA\u7EBF\u662F\u54EA\u4E00\u8F6E\uFF0C\u800C \`${baselinePath}\` \u73B0\u5728\u7ED9\u5F97\u51FA\u8F6E\u6B21 \`${nowRound}\` \u2014\u2014 **\u5224\u4E0D\u51FA**\u8FD9\u4EFD\u8BA1\u5212\u7167\u7684\u8FD8\u662F\u4E0D\u662F\u76D8\u4E0A\u8FD9\u4E00\u4EFD`,
12386
+ "\u8001\u57FA\u7EBF\u6CA1\u6709\u8F6E\u6B21\u6233\uFF0C\u6240\u4EE5\u8FD9\u91CC**\u6CA1\u6709**\u8BF4\u5B83\u53D8\u8FC7 \u2014\u2014 \u8BF4\u7684\u662F**\u67E5\u4E0D\u51FA\u6765**\uFF08\u91CD\u722C\u540C\u4E00\u4E2A\u73AF\u5883\u4E5F\u4F1A\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6233\uFF0C\u90A3\u79CD\u60C5\u51B5\u4E0B\u8FD9\u4EFD\u8BA1\u5212\u4ECD\u7136\u6709\u6548\uFF09\u3002\u91CD\u8DD1\u4E00\u6B21 `plan`\uFF08\u96F6\u5199\uFF1A`plan` \u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\uFF0C\u65B0\u8BA1\u5212\u4F1A\u5E26\u4E0A\u8F6E\u6B21\u6233\u3002" + notWaived
12387
+ ];
12388
+ }
12389
+ if (nowRound === null) {
12390
+ return [
12391
+ `\u8FD9\u4EFD\u8BA1\u5212\u8BB0\u7684\u57FA\u7EBF\u8F6E\u6B21\u662F \`${plannedRound}\`\uFF0C\u800C \`${baselinePath}\` \u73B0\u5728**\u8BFB\u4E0D\u51FA**\u8F6E\u6B21\u6233\uFF08\u90A3\u4EFD\u6839\u90E8\u53F0\u8D26\u4E0D\u5728 / \u8BFB\u4E0D\u51FA\u6765 / \u91CC\u9762\u6CA1\u6709\u8F6E\u6B21\u6233\uFF09\u2014\u2014 **\u5224\u4E0D\u6E05**\u76D8\u4E0A\u8FD9\u4E00\u4EFD\u8FD8\u662F\u4E0D\u662F \`plan\` \u8BFB\u7684\u90A3\u4E00\u4EFD`,
12392
+ "\u8F6E\u6B21\u6233\u53EA\u6765\u81EA\u57FA\u7EBF\u76EE\u5F55\u91CC\u7684\u90A3\u4EFD\u6839\u90E8\u53F0\u8D26\uFF0C\u800C\u672C\u5C42\u53EA\u89C2\u6D4B\u5230\u300C\u8FD9\u4E00\u523B\u53D6\u4E0D\u5230\u5B83\u300D\u2014\u2014\u662F\u8C01\u52A8\u7684\u3001\u52A8\u6CA1\u52A8\uFF0C\u672C\u5C42**\u6CA1\u6709\u67E5\u8FC7**\u3002\u4E09\u6761\u51FA\u8DEF\u5E76\u5217\uFF0C\u4ECE\u6700\u4FBF\u5B9C\u7684\u5F00\u59CB\uFF1A\u2460 \u5148\u53BB\u770B\u4E00\u773C\u90A3\u4EFD\u6587\u4EF6\u5728\u4E0D\u5728\u3001\u6743\u9650\u5BF9\u4E0D\u5BF9\u3001\u5185\u5BB9\u662F\u4E0D\u662F\u88AB\u5199\u574F\u4E86\uFF08\u6743\u9650\u4E0D\u5BF9 / \u5199\u5230\u4E00\u534A\u8FD9\u4E24\u79CD\uFF0C\u57FA\u7EBF\u5185\u5BB9\u4E00\u4E2A\u5B57\u8282\u90FD\u6CA1\u53D8\uFF0C**\u522B\u52A8\u4EA7\u7269**\uFF09\uFF1B\u2461 \u786E\u5B9E\u662F\u62F7\u8D1D\u3001\u538B\u7F29\u5305\u6F0F\u5E26\uFF0C\u5C31\u628A\u90A3\u4EFD recon \u4EA7\u7269\u539F\u6837\u62F7\u56DE\u6765\uFF1B\u2462 \u90FD\u6392\u9664\u6389\uFF0C\u518D\u91CD\u8DD1\u4E00\u6B21 `hcm delivery recon` \u52A0\u4E00\u6B21 `plan`\uFF08\u96F6\u5199\uFF09\u3002\u{1F534} \u2461 \u4E0E \u2462 \u90FD\u6362\u6389\u76D8\u4E0A\u7684\u4EA7\u7269\uFF0C\u800C\u8FD9\u4EFD\u8BA1\u5212\u6B63\u662F\u7167\u65E7\u5185\u5BB9\u7B97\u7684 \u2014\u2014 \u6240\u4EE5\u5B83\u4EEC\u6392\u5728 \u2460 \u540E\u9762\u3002" + notWaived
12393
+ ];
12394
+ }
12395
+ return [
12396
+ `\u8FD9\u4EFD\u8BA1\u5212\u7B97\u7684\u662F\u53E6\u4E00\u8F6E\u57FA\u7EBF\uFF1A\u8BA1\u5212\u91CC\u8BB0\u7684\u662F \`${plannedRound}\`\uFF0C\u800C \`${baselinePath}\` \u73B0\u5728\u662F \`${nowRound}\``,
12397
+ "\u8BA1\u5212\u91CC\u7684\u884C\u52A8\u4F5C\u3001\u65E2\u5B58\u7D22\u5F15\u4E0E\u98CE\u9669\u6E05\u5355\u90FD\u662F\u7167**\u90A3\u4E00\u8F6E\u7684\u57FA\u7EBF\u5185\u5BB9**\u7B97\u51FA\u6765\u7684\uFF0C\u6362\u4E86\u4E00\u8F6E\u4E4B\u540E\u5B83\u4EEC\u8BF4\u7684\u8FD8\u662F\u4E0A\u4E00\u7248\u3002\u91CD\u8DD1\u4E00\u6B21 `plan`\uFF08\u96F6\u5199\uFF1A`plan` \u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\u3002" + notWaived
12398
+ ];
12399
+ }
12400
+ var FORCE_STALE_FLAG_TEXT = "--force-stale";
12401
+ function existingJournalStop(journalPath, entries) {
12402
+ return [
12403
+ `\u8FD9\u4E2A work \u76EE\u5F55\u5DF2\u7ECF\u6709\u4E00\u8F6E\u7684\u53F0\u8D26\uFF1A${journalPath}\uFF08${entries} \u6761\uFF09`,
12404
+ "\u8981**\u63A5\u7740\u8DD1**\u5C31\u52A0 `--resume`\uFF08\u53F0\u8D26\u672C\u6765\u5C31\u662F append-only\u3001\u6700\u540E\u4E00\u6761\u8D62\uFF0C\u7B2C\u4E8C\u8F6E\u6BCF\u884C\u600E\u4E48\u8D70\u7531\u53F0\u8D26\u81EA\u5DF1\u5224\uFF09\uFF1B\u8981**\u91CD\u6765**\u5C31\u6362\u4E00\u4E2A `--out` / `--work`\uFF0C\u6216\u8005\u4F60\u81EA\u5DF1\u5220\u6389\u90A3\u4EFD\u53F0\u8D26 \u2014\u2014 kit \u4E0D\u66FF\u4F60\u5220\uFF0C\u90A3\u662F\u4E0D\u53EF\u9006\u7684\u3002"
12405
+ ];
12406
+ }
12335
12407
 
12336
12408
  // src/fde/seed/plan-io.ts
12337
12409
  import * as path15 from "path";
@@ -12479,9 +12551,9 @@ function readImportPlan(out) {
12479
12551
  "\u5148\u5728\u540C\u4E00\u4E2A work \u76EE\u5F55\u4E0A\u8DD1\u4E00\u6B21 `plan` \u5B50\u547D\u4EE4\u3002\u{1F534} `apply` \u4E0D\u4F1A\u81EA\u5DF1\u53BB\u7B97\u8BA1\u5212\uFF1A\u7B97\u8BA1\u5212\u8981\u53D1\u8BF7\u6C42\u5EFA\u65E2\u5B58\u7D22\u5F15\uFF0C\u800C\u300C\u987A\u624B\u7B97\u4E00\u4EFD\u300D\u610F\u5473\u7740\u4F60 apply \u7684\u4E0D\u662F\u4F60\u770B\u8FC7\u7684\u90A3\u4E00\u4EFD"
12480
12552
  );
12481
12553
  }
12482
- let bytes;
12554
+ let bytes2;
12483
12555
  try {
12484
- bytes = work.readBytes(IMPORT_PLAN_FILE);
12556
+ bytes2 = work.readBytes(IMPORT_PLAN_FILE);
12485
12557
  } catch (e) {
12486
12558
  throw new PlanReadError(
12487
12559
  "plan-unreadable",
@@ -12491,7 +12563,7 @@ function readImportPlan(out) {
12491
12563
  }
12492
12564
  let raw;
12493
12565
  try {
12494
- raw = new TextDecoder("utf-8", { fatal: true }).decode(bytes).replace(/^\uFEFF/, "");
12566
+ raw = new TextDecoder("utf-8", { fatal: true }).decode(bytes2).replace(/^\uFEFF/, "");
12495
12567
  } catch {
12496
12568
  throw new PlanReadError(
12497
12569
  "plan-unreadable",
@@ -12661,189 +12733,2954 @@ function rowFromJson(r) {
12661
12733
  };
12662
12734
  }
12663
12735
 
12664
- // src/fde/seed/risk-io.ts
12665
- function fromArtifactProblem2(p) {
12666
- return {
12667
- code: p.code,
12668
- model: p.model,
12669
- field: null,
12670
- message: p.message,
12671
- hint: p.hint,
12672
- kind: p.kind,
12673
- severity: "blocking",
12674
- entry: p.entry,
12675
- // 🔴 不留裸 `{}`:这一条的证据在工件层那一侧,本模块转手时手上确实没有可记的数。
12676
- evidence: {
12677
- _kitNoEvidence: "\u8FD9\u6761\u662F validateMapping \u7684\u539F\u6837\u8F6C\u5F55\uFF0C\u672C\u6A21\u5757\u6CA1\u6709\u91CD\u65B0\u5224\u5B83\uFF0C\u624B\u4E0A\u6CA1\u6709\u53EF\u8BB0\u7684\u8BC1\u636E"
12678
- },
12679
- exempted: false
12680
- };
12736
+ // src/fde/seed/journal.ts
12737
+ import { createHash as createHash4 } from "crypto";
12738
+ import { existsSync as existsSync8, statSync as statSync7 } from "fs";
12739
+ import * as os3 from "os";
12740
+ import * as path16 from "path";
12741
+ var JOURNAL_FILE = "journal.jsonl";
12742
+ var STATUSES = ["done", "skipped", "failed", "unknown", "quarantined"];
12743
+ var STEP_SEND = "send";
12744
+ var STEP_READBACK = "readback";
12745
+ var STEP_NOTHING = "nothing";
12746
+ var STEP_STOP = "stop";
12747
+ var NEXT_STEP = {
12748
+ // 用字符串 `'null'` 当键会与一个真叫 "null" 的状态撞;这里用 `Map` 的等价写法:
12749
+ // 键就是 `String(status)`,而 `STATUSES` 里没有 `"null"` 这个值(值域守卫钉着)。
12750
+ null: STEP_SEND,
12751
+ done: STEP_NOTHING,
12752
+ skipped: STEP_NOTHING,
12753
+ // 收到过明确拒绝 ⇒ 服务端那边**什么都没建** ⇒ 重发是安全的。
12754
+ // 🔴 **写这一档的调用方必须已经查证过「没建成」**:只是「按这个业务键查不到」**不够** ——
12755
+ // 服务端可能刚接受了一次写、只是存成了别的键,那时重发会再造一条野行。那一档归
12756
+ // `quarantined`。⚠️ 「可以重放」不等于「重放会成功」:多半要顾问先改数据。
12757
+ failed: STEP_SEND,
12758
+ // 🔴 承重:既不是 send 也不是 readback。回读已经问过了,答案是「按这个键没有」,
12759
+ // 而服务端那边**可能有一行别的键的**。自动做任何事都只会让情况更糟。
12760
+ quarantined: STEP_STOP,
12761
+ // 🔴 承重:**不许**退化成 STEP_SEND。
12762
+ unknown: STEP_READBACK
12763
+ };
12764
+ var NEEDS_PRIOR_RECORD = ["done", "failed", "quarantined"];
12765
+ var ENTRY_KEYS2 = [
12766
+ "sourceRowId",
12767
+ "model",
12768
+ "businessKey",
12769
+ "payloadHash",
12770
+ "serverId",
12771
+ "status",
12772
+ "attempts",
12773
+ "roundId"
12774
+ ];
12775
+ var KIND_KEY = "kind";
12776
+ var KIND_ENTRY = "entry";
12777
+ var KIND_DRIFT_WAIVER = "drift-waiver";
12778
+ var KINDS = [KIND_ENTRY, KIND_DRIFT_WAIVER];
12779
+ var WAIVER_KEYS = [
12780
+ "kind",
12781
+ "roundId",
12782
+ "at",
12783
+ "verdict",
12784
+ "causes",
12785
+ "gateDiffs",
12786
+ "incomplete",
12787
+ "advisory",
12788
+ "baseline"
12789
+ ];
12790
+ var JournalError = class extends Error {
12791
+ reason;
12792
+ detail;
12793
+ hint;
12794
+ constructor(reason, detail, hint = "") {
12795
+ super(`[${reason}] ${detail}${hint ? ` \u2014\u2014 ${hint}` : ""}`);
12796
+ this.name = "JournalError";
12797
+ this.reason = reason;
12798
+ this.detail = detail;
12799
+ this.hint = hint;
12800
+ }
12801
+ };
12802
+ function nowStamp(at = /* @__PURE__ */ new Date()) {
12803
+ return stampOf(at);
12681
12804
  }
12682
- async function riskFromArtifacts(mappingPath, reconDir, options = {}) {
12683
- const mapping = loadMapping(mappingPath);
12684
- const scan2 = await scanSources(mapping, options.sourceDir);
12685
- const problems = [...scan2.problems, ...validateMapping(mapping, scan2.headers)];
12686
- if (problems.length === 0) {
12687
- return buildRisk(mapping, reconDir, {
12688
- notes: [...scan2.notes],
12689
- tables: scan2.rows,
12690
- exemptions: options.exemptions,
12691
- plan: options.plan,
12692
- roundPremise: options.roundPremise
12693
- });
12805
+ function stampOf(at) {
12806
+ return at.toISOString().replace(/Z$/, "+00:00");
12807
+ }
12808
+ function parseStamp(text2) {
12809
+ if (typeof text2 !== "string" || !text2.trim()) {
12810
+ return [null, `\u4E0D\u662F\u4E00\u4E2A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF1A${JSON.stringify(text2)}`];
12694
12811
  }
12695
- const blocked = PREMISE_BLOCKS3.RISK_NOT_BUILT;
12696
- const converted = problems.map(fromArtifactProblem2);
12697
- converted.push(...roundProblems(options.roundPremise ?? null, false));
12698
- converted.push(
12699
- problem3(
12700
- "RISK_NOT_BUILT",
12701
- "*",
12702
- `\u5DE5\u4EF6\u6709 ${problems.length} \u6761\u95EE\u9898\uFF0C**\u6574\u4EFD\u98CE\u9669\u6E05\u5355\u6CA1\u6709\u5EFA**\uFF1A${blocked.length} \u7EC4\u5224\u636E\u4E00\u7EC4\u90FD\u6CA1\u8DD1\uFF0C\u4E00\u4E2A\u6A21\u578B\u90FD\u6CA1\u8BC4\u4F30`,
12703
- `validateMapping \u8FD4\u56DE\u975E\u7A7A\u7684\u8BED\u4E49\u662F\u300C\u4E0D\u8BB8\u5F80\u4E0B\u8D70\u300D\u3002\u5148\u6309\u4E0A\u9762\u6BCF\u6761\u7684 hint \u6539\u5DE5\u4EF6 / \u6E90\u8868\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002\u{1F534} \`models: []\` \u5728\u8FD9\u4E00\u4EFD\u4EA7\u7269\u91CC**\u4E0D\u662F**\u300C\u96F6\u4E2A\u6A21\u578B\u6709\u98CE\u9669\u300D\u2014\u2014 \u770B \`modelsAssessed: false\`\uFF08\u8BC4\u4F30\u538B\u6839\u6CA1\u53D1\u751F\uFF09\u3002\u6CA1\u8DD1\u7684\u90A3\u51E0\u7EC4\u662F\uFF1A${blocked.join("\uFF1B")}`,
12704
- null,
12812
+ let normalised = text2.trim();
12813
+ if (/[Zz]$/.test(normalised)) normalised = `${normalised.slice(0, -1)}+00:00`;
12814
+ if (!/(?:[+-]\d{2}:?\d{2})$/.test(normalised)) {
12815
+ return [
12705
12816
  null,
12706
- { artifactProblems: problems.length, checkGroups: blocked.length }
12707
- )
12708
- );
12709
- return {
12710
- version: VERSION3,
12711
- roundId: newRoundId(/* @__PURE__ */ new Date()),
12712
- blocking: true,
12713
- models: [],
12714
- problems: converted,
12715
- // 🔴 `notes` 照常带出:源表扫过了(扫描在校验之前跑),丢掉它等于把已经查到的事实
12716
- // 一起扔了。
12717
- notes: [...scan2.notes],
12718
- notesProvided: true,
12719
- exemptions: [],
12720
- // 🔴 传了豁免也**没有判**(一条风险项都没算出来,无从匹配)⇒ 这里必须是 false:
12721
- // `[]` + `exemptionsProvided: true` 会被读成「签的那几份一条都没生效」,
12722
- // 而真相是「压根没走到判豁免那一步」。
12723
- exemptionsProvided: false,
12724
- modelsAssessed: false,
12725
- // 🔴 轮次身份与工件校验是两回事:这一轮判没判它,只看有没有把结论传进来。
12726
- roundJudged: options.roundPremise !== void 0 && options.roundPremise !== null,
12727
- // 🔴 一个模型都没评估 ⇒ **每一组**判据都没跑,这一格是 `true`(不是 `null`、更不是
12728
- // `false`)。与 `modelsAssessed: false` 一起读才分得出这是哪一档。
12729
- checksSkipped: true,
12730
- wording: WORDING5
12817
+ `${JSON.stringify(text2)} \u6CA1\u6709\u65F6\u533A\u504F\u79FB \u2014\u2014 \u5B83\u662F\u672C\u673A\u65F6\u95F4\u8FD8\u662F UTC \u65E0\u4ECE\u5F97\u77E5\uFF0C\u4E24\u79CD\u89E3\u91CA\u5DEE\u51FA\u6765\u7684\u5C0F\u65F6\u6570\u8DB3\u4EE5\u628A\u300C\u9648\u65E7\u300D\u5224\u6210\u300C\u6D3B\u7740\u300D`
12818
+ ];
12819
+ }
12820
+ const moment = new Date(normalised);
12821
+ if (Number.isNaN(moment.getTime())) {
12822
+ return [null, `\u4E0D\u662F\u80FD\u89E3\u6790\u7684 ISO 8601 \u65F6\u95F4\u6233\uFF1A${JSON.stringify(text2)}`];
12823
+ }
12824
+ return [moment, ""];
12825
+ }
12826
+ function canonicalise(value, at = "$") {
12827
+ if (value === null) return null;
12828
+ const t = typeof value;
12829
+ if (t === "string" || t === "boolean") return value;
12830
+ if (t === "number") {
12831
+ if (!Number.isFinite(value)) {
12832
+ throw new TypeError(`${at} \u662F ${String(value)}\uFF0CJSON \u8868\u793A\u4E0D\u4E86\u5B83 \u2014\u2014 \u6362\u4E2A\u8868\u793A\u6CD5\u5C31\u7B49\u4E8E\u4E24\u6B21\u8C03\u7528\u7ED9\u51FA\u4E24\u4E2A\u54C8\u5E0C`);
12833
+ }
12834
+ return value;
12835
+ }
12836
+ if (t === "undefined" || t === "function" || t === "symbol" || t === "bigint") {
12837
+ throw new TypeError(`${at} \u662F ${t}\uFF0CJSON \u5E8F\u5217\u5316\u4E0D\u4E86\u5B83\uFF08JSON.stringify \u4F1A\u9759\u9ED8\u4E22\u6389\u8FD9\u4E2A\u952E\uFF09`);
12838
+ }
12839
+ if (Array.isArray(value)) return value.map((v, i) => canonicalise(v, `${at}[${i}]`));
12840
+ const obj = value;
12841
+ const out = {};
12842
+ for (const key of Object.keys(obj).sort()) out[key] = canonicalise(obj[key], `${at}.${key}`);
12843
+ return out;
12844
+ }
12845
+ function payloadHash(payload) {
12846
+ const text2 = JSON.stringify(canonicalise(payload));
12847
+ return `sha256:${createHash4("sha256").update(text2, "utf8").digest("hex")}`;
12848
+ }
12849
+ function businessKeyOf(value) {
12850
+ if (typeof value === "string" || !Array.isArray(value)) {
12851
+ throw new JournalError(
12852
+ "bad-entry",
12853
+ `businessKey \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7684\u6570\u7EC4\uFF0C\u6536\u5230 ${JSON.stringify(value)}`,
12854
+ "\u4E1A\u52A1\u952E\u662F\u590D\u5408\u7684\uFF08\u5DE5\u4EF6\u5C42 businessKey.fields \u53EF\u4EE5\u6709\u591A\u4E2A\u5B57\u6BB5\uFF09\uFF0C\u6240\u4EE5\u8FD9\u91CC\u6052\u662F\u4E00\u4E2A\u5E8F\u5217\uFF0C\u54EA\u6015\u53EA\u6709\u4E00\u4E2A\u5B57\u6BB5"
12855
+ );
12856
+ }
12857
+ if (value.length === 0) {
12858
+ throw new JournalError(
12859
+ "bad-entry",
12860
+ "businessKey \u662F\u7A7A\u7684",
12861
+ "\u7A7A\u4E1A\u52A1\u952E\u5F53\u4E0D\u4E86\u5E42\u7B49\u7684\u652F\u70B9 \u2014\u2014 \u8BA1\u5212\u5C42\u7684 BUSINESS_KEY_VALUE_MISSING \u5C31\u662F\u62E6\u8FD9\u4E2A\u7684\uFF0C\u8D70\u5230\u8FD9\u91CC\u8BF4\u660E\u90A3\u4E00\u6B65\u88AB\u8DF3\u8FC7\u4E86"
12862
+ );
12863
+ }
12864
+ for (const part of value) {
12865
+ if (typeof part !== "string" || !part.trim()) {
12866
+ throw new JournalError(
12867
+ "bad-entry",
12868
+ `businessKey \u91CC\u6709\u5143\u7D20\u4E0D\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF1A${JSON.stringify(part)}\uFF08\u6574\u4E2A\u952E ${JSON.stringify(value)}\uFF09`,
12869
+ "\u53F0\u8D26\u8981\u5199\u5230\u78C1\u76D8\u518D\u8BFB\u56DE\u6765\uFF0C\u975E\u5B57\u7B26\u4E32\u7684\u952E\u5728 JSON \u5F80\u8FD4\u4E4B\u540E\u4E0E\u8BA1\u5212\u90A3\u8FB9\u7684\u5B57\u7B26\u4E32\u952E**\u6C38\u8FDC\u914D\u4E0D\u4E0A**\uFF0C\u8868\u73B0\u662F\u8FD9\u4E00\u884C\u88AB\u5F53\u6210\u300C\u4ECE\u6CA1\u8BB0\u8FC7\u300D\u800C\u91CD\u653E"
12870
+ );
12871
+ }
12872
+ }
12873
+ return [...value];
12874
+ }
12875
+ function entryJson(entry) {
12876
+ const out = {
12877
+ sourceRowId: entry.sourceRowId,
12878
+ model: entry.model,
12879
+ businessKey: [...entry.businessKey],
12880
+ payloadHash: entry.payloadHash,
12881
+ serverId: entry.serverId,
12882
+ status: entry.status,
12883
+ attempts: entry.attempts,
12884
+ roundId: entry.roundId
12731
12885
  };
12886
+ if (entry.error !== void 0 && entry.error !== null) out.error = entry.error;
12887
+ return out;
12732
12888
  }
12733
- function riskToJson(risk) {
12889
+ function entryFromJson(row, where) {
12890
+ const missing = ENTRY_KEYS2.filter((k) => !(k in row));
12891
+ if (missing.length > 0) {
12892
+ throw new JournalError(
12893
+ "journal-bad-line",
12894
+ `${where} \u7F3A\u4E86 ${JSON.stringify(missing)} \u8FD9\u51E0\u4E2A\u952E`,
12895
+ `\u53F0\u8D26\u6BCF\u4E00\u884C\u7684\u952E\u96C6\u662F\u5B9A\u6B7B\u7684\uFF08${JSON.stringify([...ENTRY_KEYS2])}\uFF09\u3002\u7F3A\u952E\u7684\u884C\u8BFB\u4E0D\u51FA\u7ED3\u8BBA \u2014\u2014 \u800C\u300C\u8BFB\u4E0D\u51FA\u300D\u88AB\u5F53\u6210\u300C\u6CA1\u8BB0\u8FC7\u300D\u5C31\u4F1A\u91CD\u653E\u8FD9\u4E00\u884C`
12896
+ );
12897
+ }
12898
+ if (!STATUSES.includes(row.status)) {
12899
+ throw new JournalError(
12900
+ "journal-bad-line",
12901
+ `${where} \u7684 status \u662F ${JSON.stringify(row.status)}\uFF0C\u4E0D\u5728 ${JSON.stringify([...STATUSES])} \u91CC`,
12902
+ "\u8BA4\u4E0D\u51FA\u7684\u72B6\u6001\u6CA1\u6709\u5BF9\u5E94\u7684\u5904\u7F6E \u2014\u2014 \u731C\u4E00\u4E2A\uFF08\u6BD4\u5982\u5F53\u6210 failed \u53BB\u91CD\u653E\uFF09\u6B63\u597D\u662F\u6700\u574F\u7684\u90A3\u79CD\u731C\u6CD5"
12903
+ );
12904
+ }
12905
+ for (const field of ["attempts", "sourceRowId"]) {
12906
+ const value = row[field];
12907
+ if (typeof value !== "number" || !Number.isInteger(value)) {
12908
+ throw new JournalError(
12909
+ "journal-bad-line",
12910
+ `${where} \u7684 ${field} \u662F ${JSON.stringify(value)}\uFF0C\u4E0D\u662F\u6574\u6570`,
12911
+ "\u8FD9\u4E24\u4E2A\u952E\u90FD\u662F\u6570\uFF1Aattempts \u662F\u300C\u53D1\u8FC7\u51E0\u6B21\u8BF7\u6C42\u300D\uFF0CsourceRowId \u662F\u6E90\u8868\u884C\u53F7\u3002\u88AB\u522B\u7684\u5DE5\u5177\u6539\u8FC7\u7684\u53F0\u8D26\u4E0D\u53EF\u4FE1 \u2014\u2014 \u800C\u4E0D\u53EF\u4FE1\u7684\u53F0\u8D26\u6BD4\u6CA1\u6709\u53F0\u8D26\u66F4\u5371\u9669"
12912
+ );
12913
+ }
12914
+ }
12734
12915
  return {
12735
- version: risk.version,
12736
- roundId: risk.roundId,
12737
- blocking: risk.blocking,
12738
- wording: risk.wording,
12739
- // 🔴 可审计出口:`notes` 是**原样**留痕,这个数是**展示出来**的条数。两者都要有 ——
12740
- // 只有原样留痕就回到了「有出参、没人展示」,只有条数则丢掉了读取器记下的原文。
12741
- discardedColumnsShown: risk.problems.filter((p) => p.code === "SOURCE_COLUMN_DISCARDED").length,
12742
- // 🔴 `notes: []` 的两种成因分得开:true = 扫过、一列都没丢;
12743
- // false = 这一轮没把 notes 传进来。
12744
- notesProvided: risk.notesProvided,
12745
- // 豁免台账。🔴 与 notes 同一条口径:`[]` 与「压根没签」分得开。
12746
- exemptions: risk.exemptions.map((e) => ({ ...e })),
12747
- exemptionsProvided: risk.exemptionsProvided,
12748
- // 🔴 与上面那一对同一条口径:没有那条轮次前提码时,`true` = 判过且完整、
12749
- // `false` = **这一轮没判轮次身份**。
12750
- roundJudged: risk.roundJudged,
12751
- // 🔴 `models: []` 的两种成因分得开:true = 评估过、就是没有模型;
12752
- // false = 门面早退,一个模型都没评估(此时 `models` 恒为空,别读成「零风险」)。
12753
- modelsAssessed: risk.modelsAssessed,
12754
- // 🔴 `blocking: false` 的两种成因分得开:本键 false = 该跑的判据都跑了、没查出拦路的;
12755
- // true = **有判据这一轮根本没跑**,此时「没查出问题」不等于「没问题」。
12756
- checksSkipped: risk.checksSkipped,
12757
- models: risk.models.map(modelJson2),
12758
- problems: risk.problems.map((p) => ({ ...p })),
12759
- notes: [...risk.notes]
12916
+ sourceRowId: row.sourceRowId,
12917
+ model: row.model,
12918
+ businessKey: businessKeyOf(row.businessKey),
12919
+ payloadHash: row.payloadHash ?? null,
12920
+ serverId: row.serverId ?? null,
12921
+ status: row.status,
12922
+ attempts: row.attempts,
12923
+ roundId: row.roundId,
12924
+ error: row.error
12760
12925
  };
12761
12926
  }
12762
- function modelJson2(m) {
12927
+ function waiverJson(waiver) {
12763
12928
  return {
12764
- model: m.model,
12765
- entry: m.entry,
12766
- reconSheet: { ...m.reconSheet },
12767
- checks: Object.fromEntries(
12768
- Object.entries(m.checks).map(([group, info]) => [
12769
- group,
12770
- { ran: info.ran, applicable: info.applicable, why: [...info.why] }
12771
- ])
12772
- ),
12773
- counts: { ...m.counts }
12929
+ kind: KIND_DRIFT_WAIVER,
12930
+ roundId: waiver.roundId,
12931
+ at: waiver.at,
12932
+ verdict: waiver.verdict,
12933
+ causes: [...waiver.causes],
12934
+ gateDiffs: [...waiver.gateDiffs],
12935
+ incomplete: [...waiver.incomplete],
12936
+ advisory: [...waiver.advisory],
12937
+ baseline: waiver.baseline
12774
12938
  };
12775
12939
  }
12776
- function writeRisk(risk, out) {
12777
- return new WorkLayout(out).writeJson(RISK_FILE, riskToJson(risk));
12778
- }
12779
-
12780
- // src/fde/gate0/aclass.ts
12781
- import { existsSync as existsSync8, readFileSync as readFileSync9, readdirSync as readdirSync3, statSync as statSync7 } from "fs";
12782
- import * as path16 from "path";
12783
-
12784
- // src/fde/gate0/mapping-artifact.ts
12785
- import { readFileSync as readFileSync8 } from "fs";
12786
- var MAPPING_ARTIFACT_VERSION = 1;
12787
- var MappingArtifactError = class extends Error {
12788
- constructor(reason, message) {
12789
- super(`[${reason}] ${message}`);
12790
- this.reason = reason;
12791
- this.message = message;
12792
- this.name = "MappingArtifactError";
12940
+ function strArray(value, key, where) {
12941
+ if (!Array.isArray(value) || value.some((x) => typeof x !== "string")) {
12942
+ throw new JournalError(
12943
+ "journal-bad-line",
12944
+ `${where} \u7684 ${key} \u662F ${JSON.stringify(value)}\uFF0C\u4E0D\u662F\u4E00\u4E2A\u5B57\u7B26\u4E32\u6570\u7EC4`,
12945
+ "\u8FD9\u56DB\u683C\u662F\u653E\u884C\u90A3\u4E00\u523B\u5224\u636E\u8BF4\u7684\u8BDD\uFF0C\u539F\u6837\u843D\u76D8\uFF1B\u5F62\u72B6\u4E0D\u5BF9\u7684\u884C\u8BFB\u4E0D\u51FA\u7ED3\u8BBA\uFF0C\u800C\u8BFB\u4E0D\u51FA\u7684\u653E\u884C\u8BB0\u5F55\u4E0E\u300C\u6CA1\u6709\u653E\u884C\u8BB0\u5F55\u300D\u5728\u5C4F\u5E55\u4E0A\u957F\u5F97\u4E00\u6837"
12946
+ );
12793
12947
  }
12794
- reason;
12795
- message;
12796
- };
12797
- function isRecord6(value) {
12798
- return typeof value === "object" && value !== null && !Array.isArray(value);
12948
+ return [...value];
12799
12949
  }
12800
- function readBusinessKeyFields(file) {
12801
- let text2;
12802
- try {
12803
- text2 = readFileSync8(file, "utf8");
12804
- } catch (e) {
12805
- const code = e?.code;
12806
- if (code === "ENOENT") throw new MappingArtifactError("not-found", `\u627E\u4E0D\u5230\u6620\u5C04\u5DE5\u4EF6 ${file}`);
12807
- throw new MappingArtifactError("unreadable", `${file} \u8BFB\u4E0D\u52A8\uFF08${String(e)}\uFF09`);
12808
- }
12809
- if (text2.charCodeAt(0) === 65279) text2 = text2.slice(1);
12810
- let body;
12811
- try {
12812
- body = JSON.parse(text2);
12813
- } catch (e) {
12814
- throw new MappingArtifactError("not-json", `${file} \u4E0D\u662F\u5408\u6CD5 JSON\uFF1A${String(e)}`);
12815
- }
12816
- if (!isRecord6(body)) {
12817
- throw new MappingArtifactError("bad-shape", `${file} \u7684\u6839\u4E0D\u662F\u5BF9\u8C61`);
12950
+ function waiverFromJson(row, where) {
12951
+ const missing = WAIVER_KEYS.filter((k) => !(k in row));
12952
+ if (missing.length > 0) {
12953
+ throw new JournalError(
12954
+ "journal-bad-line",
12955
+ `${where} \u7F3A\u4E86 ${JSON.stringify(missing)} \u8FD9\u51E0\u4E2A\u952E`,
12956
+ `\u653E\u884C\u8BB0\u5F55\u6BCF\u4E00\u884C\u7684\u952E\u96C6\u662F\u5B9A\u6B7B\u7684\uFF08${JSON.stringify([...WAIVER_KEYS])}\uFF09`
12957
+ );
12818
12958
  }
12819
- if (!("version" in body)) {
12820
- throw new MappingArtifactError("version-missing", `${file} \u6CA1\u6709 version \u5B57\u6BB5`);
12959
+ for (const key of ["roundId", "at", "verdict"]) {
12960
+ if (typeof row[key] !== "string") {
12961
+ throw new JournalError(
12962
+ "journal-bad-line",
12963
+ `${where} \u7684 ${key} \u662F ${JSON.stringify(row[key])}\uFF0C\u4E0D\u662F\u5B57\u7B26\u4E32`,
12964
+ "\u8FD9\u4E09\u4E2A\u952E\u90FD\u662F\u4E32\u3002\u8FD9\u4E00\u884C\u662F\u8C01\u5199\u7684\u3001\u88AB\u4EC0\u4E48\u52A8\u8FC7\uFF0C\u672C\u6A21\u5757**\u6CA1\u6709\u67E5\u8FC7** \u2014\u2014 \u5185\u5BB9\u5B58\u7591\u7684\u53F0\u8D26\u6BD4\u6CA1\u6709\u53F0\u8D26\u66F4\u5371\u9669"
12965
+ );
12966
+ }
12821
12967
  }
12822
- if (body.version !== MAPPING_ARTIFACT_VERSION) {
12823
- throw new MappingArtifactError(
12824
- "unsupported-version",
12825
- `${file} \u7684 version \u662F ${JSON.stringify(body.version)}\uFF0C\u672C\u5DE5\u5177\u53EA\u8BA4 ${MAPPING_ARTIFACT_VERSION} \u2014\u2014\u300C\u5C3D\u91CF\u6309\u8001\u7248\u672C\u8BFB\u300D\u4F1A\u628A\u65B0\u8BED\u4E49\u9759\u9ED8\u4E22\u6389`
12968
+ if (!(row.baseline === null || typeof row.baseline === "string")) {
12969
+ throw new JournalError(
12970
+ "journal-bad-line",
12971
+ `${where} \u7684 baseline \u662F ${JSON.stringify(row.baseline)}\uFF0C\u4E0D\u662F\u5B57\u7B26\u4E32\u6216 null`,
12972
+ "`null` \u7684\u610F\u601D\u662F\u300C\u90A3\u4E00\u8F6E\u7684\u8BA1\u5212\u91CC\u6CA1\u8BF4\u662F\u54EA\u4E00\u4EFD\u57FA\u7EBF\u300D\uFF0C\u4E0E\u300C\u51FA\u5904\u662F\u7A7A\u4E32\u300D\u4E0D\u662F\u4E00\u56DE\u4E8B"
12826
12973
  );
12827
12974
  }
12828
- const models = body.models;
12829
- if (!Array.isArray(models)) {
12830
- throw new MappingArtifactError(
12831
- "bad-shape",
12832
- `${file} \u7684 models \u5E94\u5F53\u662F\u4E00\u4E2A\u6570\u7EC4\uFF0C\u5B9E\u9645\u662F ${models === null ? "null" : typeof models}`
12975
+ return {
12976
+ roundId: row.roundId,
12977
+ at: row.at,
12978
+ verdict: row.verdict,
12979
+ causes: strArray(row.causes, "causes", where),
12980
+ gateDiffs: strArray(row.gateDiffs, "gateDiffs", where),
12981
+ incomplete: strArray(row.incomplete, "incomplete", where),
12982
+ advisory: strArray(row.advisory, "advisory", where),
12983
+ baseline: row.baseline
12984
+ };
12985
+ }
12986
+ function workDirOf(p) {
12987
+ if (existsSync8(p) && !statSync7(p).isDirectory()) {
12988
+ throw new JournalError(
12989
+ "not-a-work-dir",
12990
+ `${p} \u5DF2\u5B58\u5728\uFF0C\u4F46\u5B83\u4E0D\u662F\u76EE\u5F55 \u2014\u2014 \u53F0\u8D26\u6536\u7684\u662F **work \u76EE\u5F55**\uFF0C\u4E0D\u662F\u53F0\u8D26\u6587\u4EF6`,
12991
+ `\u4F20 \`work/\`\uFF08\u4E0E\u79DF\u7EA6\u540C\u4E00\u4E2A\u5165\u53C2\uFF09\uFF0C\u53F0\u8D26\u56FA\u5B9A\u843D\u5728\u5B83\u4E0B\u9762\u7684 ${JOURNAL_FILE}\u3002\u{1F534} \u8FD9\u91CC\u786C\u5931\u8D25\u662F\u6709\u610F\u7684\uFF1A\u4F20\u6210\u6587\u4EF6\u65F6\u300C${JOURNAL_FILE} \u5728\u4E0D\u5728\u300D\u6052\u7B54\u300C\u4E0D\u5728\u300D\uFF0C\u9759\u9ED8\u8D70\u8FDB\u300C\u7B2C\u4E00\u8F6E\u3001\u7A7A\u53F0\u8D26\u300D\u90A3\u4E00\u6863\uFF0C\u800C\u7A7A\u53F0\u8D26\u7684\u610F\u601D\u662F\u300C\u6BCF\u4E00\u884C\u90FD\u6CA1\u8BB0\u8FC7\u300D\u21D2 \u7167\u5B83\u8DD1\u4E00\u904D\u5C31\u662F**\u5168\u91CF\u91CD\u590D\u884C**`
12833
12992
  );
12834
12993
  }
12835
- if (models.length === 0) {
12836
- throw new MappingArtifactError(
12837
- "empty",
12838
- `${file} \u7684 models \u662F\u7A7A\u7684 \u2014\u2014 \u7A7A\u5DE5\u4EF6\u8DD1\u5B8C\u4EC0\u4E48\u4E5F\u4E0D\u4F1A\u53D1\u751F\uFF0C\u800C\u987E\u95EE\u4F1A\u4EE5\u4E3A\u300C\u5BFC\u8FC7\u4E86\u300D`
12839
- );
12994
+ return p;
12995
+ }
12996
+ function keyOf(model, businessKey) {
12997
+ return JSON.stringify([model, businessKey]);
12998
+ }
12999
+ var Journal = class _Journal {
13000
+ workDir;
13001
+ path;
13002
+ entries;
13003
+ waivers;
13004
+ /**
13005
+ * 🔴 `entries === []` 有两种成因,这个布尔把它们分开:
13006
+ * true = 文件在、里面一条都没有;false = 文件**根本不存在**(第一轮)。
13007
+ */
13008
+ exists;
13009
+ layout;
13010
+ latestByKey = /* @__PURE__ */ new Map();
13011
+ constructor(workDir, entries = [], exists = false, waivers = []) {
13012
+ this.workDir = workDirOf(workDir);
13013
+ this.layout = new WorkLayout(this.workDir);
13014
+ this.path = path16.join(this.workDir, JOURNAL_FILE);
13015
+ this.entries = [...entries];
13016
+ this.waivers = [...waivers];
13017
+ this.exists = exists;
13018
+ for (const entry of this.entries) this.latestByKey.set(keyOf(entry.model, entry.businessKey), entry);
12840
13019
  }
12841
- return models.map((raw, i) => {
12842
- if (!isRecord6(raw)) {
12843
- throw new MappingArtifactError("bad-shape", `${file} \u7684 models[${i}] \u4E0D\u662F\u5BF9\u8C61`);
13020
+ /**
13021
+ * 读回台账。`path` 是 **work 目录**,台账固定落在它下面的 `journal.jsonl`。
13022
+ *
13023
+ * 🔴 **读不了就抛,不返回空台账**:空台账的下游语义是「每一行都没记过 ⇒ 全部重放」,
13024
+ * 也就是全量重复。
13025
+ */
13026
+ static load(p) {
13027
+ const work = workDirOf(p);
13028
+ const target = path16.join(work, JOURNAL_FILE);
13029
+ if (!existsSync8(target)) return new _Journal(work, [], false);
13030
+ let text2;
13031
+ try {
13032
+ text2 = new WorkLayout(work).readText(JOURNAL_FILE);
13033
+ } catch (e) {
13034
+ if (e instanceof TypeError) {
13035
+ throw new JournalError(
13036
+ "journal-unreadable",
13037
+ `${target} \u4E0D\u662F UTF-8 \u7F16\u7801`,
13038
+ "\u53F0\u8D26\u662F kit \u81EA\u5DF1\u5199\u7684 UTF-8 jsonl\uFF0C\u800C\u8FD9\u4E00\u4EFD\u89E3\u4E0D\u51FA UTF-8\u3002\u5B83\u662F\u8C01\u5199\u7684\u3001\u88AB\u4EC0\u4E48\u52A8\u8FC7\uFF0C\u672C\u6A21\u5757**\u6CA1\u6709\u67E5\u8FC7** \u2014\u2014 \u5148\u81EA\u5DF1\u53BB\u770B\u4E00\u773C\u8FD9\u4EFD\u6587\u4EF6\uFF1B\u5185\u5BB9\u5B58\u7591\u7684\u53F0\u8D26\u6BD4\u6CA1\u6709\u53F0\u8D26\u66F4\u5371\u9669"
13039
+ );
13040
+ }
13041
+ throw new JournalError(
13042
+ "journal-unreadable",
13043
+ `${target} \u8BFB\u4E0D\u4E86\uFF1A${String(e)}`,
13044
+ "\u53F0\u8D26\u8BFB\u4E0D\u4E86\u65F6**\u4E0D\u8BB8**\u5F53\u6210\u7A7A\u53F0\u8D26\u5F80\u4E0B\u8D70\uFF1A\u7A7A\u53F0\u8D26\u7684\u610F\u601D\u662F\u300C\u6BCF\u4E00\u884C\u90FD\u6CA1\u8BB0\u8FC7\u300D\uFF0C\u7167\u5B83\u8DD1\u4E00\u904D\u5C31\u662F\u5168\u91CF\u91CD\u590D\u3002\u5148\u628A\u6587\u4EF6\u6743\u9650/\u4ECB\u8D28\u95EE\u9898\u89E3\u51B3"
13045
+ );
12844
13046
  }
12845
- const businessKey = raw.businessKey;
12846
- if (businessKey === void 0 || businessKey === null) return [];
13047
+ const entries = [];
13048
+ const waivers = [];
13049
+ text2.split("\n").forEach((line, i) => {
13050
+ if (!line.trim()) return;
13051
+ const where = `${target} \u7B2C ${i + 1} \u884C`;
13052
+ let row;
13053
+ try {
13054
+ row = JSON.parse(line);
13055
+ } catch (e) {
13056
+ throw new JournalError(
13057
+ "journal-bad-line",
13058
+ `${where} \u4E0D\u662F\u5408\u6CD5 JSON\uFF1A${String(e)}`,
13059
+ "\u8FD9\u4E00\u884C\u662F\u8C01\u5199\u7684\u3001\u65AD\u5728\u54EA\u91CC\uFF0C\u672C\u6A21\u5757**\u6CA1\u6709\u67E5\u8FC7**\u3002\u786E\u8BA4\u90A3\u4E00\u884C\u5C5E\u4E8E\u54EA\u4E00\u6B21\u5C1D\u8BD5\u4E4B\u540E\uFF0C\u628A\u5B83**\u6574\u884C**\u5220\u6389\u518D\u8DD1 \u2014\u2014 \u5220\u6389\u4E4B\u540E\u90A3\u4E00\u884C\u4F1A\u6309\u300C\u6CA1\u8BB0\u8FC7\u300D\u5904\u7406\uFF0C\u6240\u4EE5\u5220\u4E4B\u524D\u5148\u6309\u4E1A\u52A1\u952E\u53BB\u7CFB\u7EDF\u91CC\u770B\u4E00\u773C\u5B83\u5728\u4E0D\u5728"
13060
+ );
13061
+ }
13062
+ if (row === null || typeof row !== "object" || Array.isArray(row)) {
13063
+ throw new JournalError(
13064
+ "journal-bad-line",
13065
+ `${where} \u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61`,
13066
+ "\u53F0\u8D26\u6BCF\u4E00\u884C\u90FD\u662F\u4E00\u4E2A JSON \u5BF9\u8C61\uFF1B\u4E0D\u662F\u7684\u8BDD\u8FD9\u4EFD\u6587\u4EF6\u4E0D\u662F kit \u5199\u7684"
13067
+ );
13068
+ }
13069
+ const obj = row;
13070
+ const kind = obj[KIND_KEY];
13071
+ if (kind === void 0 || kind === null) entries.push(entryFromJson(obj, where));
13072
+ else if (kind === KIND_DRIFT_WAIVER) waivers.push(waiverFromJson(obj, where));
13073
+ else {
13074
+ throw new JournalError(
13075
+ "journal-bad-line",
13076
+ `${where} \u7684 kind \u662F ${JSON.stringify(kind)}\uFF0C\u4E0D\u5728 ${JSON.stringify([...KINDS])} \u91CC`,
13077
+ "\u8BA4\u4E0D\u51FA\u7684\u884C\u6CA1\u6709\u5BF9\u5E94\u7684\u8BFB\u6CD5 \u2014\u2014 \u731C\u4E00\u4E2A\uFF08\u6BD4\u5982\u5F53\u6210\u884C\u8BB0\u5F55\uFF09\u7B49\u4E8E\u628A\u8FD9\u4E00\u884C\u7684\u7ED3\u5C40\u8BFB\u6210\u53E6\u4E00\u4EF6\u4E8B\u3002\u8FD9\u4EFD\u53F0\u8D26\u662F\u8C01\u5199\u7684\u3001\u88AB\u4EC0\u4E48\u52A8\u8FC7\uFF0C\u672C\u6A21\u5757**\u6CA1\u6709\u67E5\u8FC7**"
13078
+ );
13079
+ }
13080
+ });
13081
+ return new _Journal(work, entries, true, waivers);
13082
+ }
13083
+ /** 这个模型 + 业务键**最后一条**记录;从没记过返回 `null`。 */
13084
+ latest(model, key) {
13085
+ return this.latestByKey.get(keyOf(model, businessKeyOf(key))) ?? null;
13086
+ }
13087
+ /**
13088
+ * → {@link STATUSES} 里的一档,或 `null`。
13089
+ *
13090
+ * 🔴 `null` = **这一行本模块从没记过**,与 `'failed'` 是两回事,也与 `'skipped'`
13091
+ * 是两回事。三者的下一步动作分别是「发」「发」「什么都不做」—— 看着有两档相同,
13092
+ * 但**理由**不同,合并就没法解释产物了。
13093
+ */
13094
+ statusOf(model, key) {
13095
+ const entry = this.latest(model, key);
13096
+ return entry === null ? null : entry.status;
13097
+ }
13098
+ /**
13099
+ * 这一行接下来该做什么 —— 取值域恒等于 `NEXT_STEP` 的值集。
13100
+ *
13101
+ * 🔴 **推荐调用方只读这一个**:两个布尔(`needsReadback` / `shouldReplay`)是从这里
13102
+ * 派生的**投影**,它们「都为 false」时有**三**种完全不同的含义
13103
+ * (已建好 / 已跳过 / **中毒了要人处理**),单看任何一个都读不出来。
13104
+ */
13105
+ nextStep(model, key) {
13106
+ return NEXT_STEP[String(this.statusOf(model, key))];
13107
+ }
13108
+ /** 这一行要不要**先按业务键回读**再决定 —— 只有 `unknown` 是 true。 */
13109
+ needsReadback(model, key) {
13110
+ return this.nextStep(model, key) === STEP_READBACK;
13111
+ }
13112
+ /**
13113
+ * 这一行可不可以**直接重发**请求。
13114
+ *
13115
+ * 🔴 `unknown` / `quarantined` 恒为 false:那两条路正是产生重复行的路。
13116
+ * ⚠️ true 的含义是「重发是安全的」,**不是**「重发会成功」—— `failed` 那一档多半要
13117
+ * 顾问先把源表改对。
13118
+ */
13119
+ shouldReplay(model, key) {
13120
+ return this.nextStep(model, key) === STEP_SEND;
13121
+ }
13122
+ /**
13123
+ * **发请求之前**先落一条 `unknown`(写前落账)。
13124
+ *
13125
+ * `attempts` 在这里自动 +1(前一条没有就从 1 起)—— 让调用方自己数,两处状态迟早漂,
13126
+ * 而漂的方向是「重试了 5 次,台账里写着 1」。
13127
+ */
13128
+ begin(sourceRowId, model, key, payloadHashValue, roundId) {
13129
+ const businessKey = businessKeyOf(key);
13130
+ const previous = this.latest(model, businessKey);
13131
+ return this.append({
13132
+ sourceRowId,
13133
+ model,
13134
+ businessKey,
13135
+ payloadHash: payloadHashValue,
13136
+ // 🔴 沿用上一条的 `serverId`:一行可能先 unknown、回读判成 done 拿到 id,
13137
+ // 之后又因为 payload 变了要 update —— 那次 `begin` 不该把已知的 id 抹掉。
13138
+ serverId: previous === null ? null : previous.serverId,
13139
+ status: "unknown",
13140
+ attempts: previous === null ? 1 : previous.attempts + 1,
13141
+ roundId
13142
+ });
13143
+ }
13144
+ /**
13145
+ * 把一条结局追加进台账(内存 + 磁盘)。
13146
+ *
13147
+ * 校验三件事,任一不成立**硬失败**:状态在取值域内 · 业务键是字符串序列 ·
13148
+ * 终态必须有前置记录(写前落账协议)。
13149
+ */
13150
+ append(entry) {
13151
+ if (entry === null || typeof entry !== "object") {
13152
+ throw new JournalError(
13153
+ "bad-entry",
13154
+ `append \u6536\u7684\u662F Entry\uFF0C\u4E0D\u662F ${typeof entry}`,
13155
+ "\u7528\u4E00\u4E2A Entry \u5B57\u9762\u91CF\u6784\u9020\uFF0C\u6216\u4ECE latest(...) \u62FF\u5230\u4E0A\u4E00\u6761\u518D\u5C55\u5F00\u6539"
13156
+ );
13157
+ }
13158
+ if (!STATUSES.includes(entry.status)) {
13159
+ throw new JournalError(
13160
+ "bad-entry",
13161
+ `status \u662F ${JSON.stringify(entry.status)}\uFF0C\u4E0D\u5728 ${JSON.stringify([...STATUSES])} \u91CC`,
13162
+ "\u4E94\u6863\u7684\u8BED\u4E49\u89C1\u6A21\u5757\u5934\u6CE8\u91CA\uFF1Adone/skipped/failed/quarantined \u90FD\u662F**\u67E5\u8FC7\u4E4B\u540E**\u7684\u7ED3\u8BBA\uFF0C\u5206\u4E0D\u6E05\u5C31\u5199 unknown"
13163
+ );
13164
+ }
13165
+ const businessKey = businessKeyOf(entry.businessKey);
13166
+ const settled = { ...entry, businessKey };
13167
+ const mapKey = keyOf(settled.model, businessKey);
13168
+ if (NEEDS_PRIOR_RECORD.includes(settled.status) && !this.latestByKey.has(mapKey)) {
13169
+ throw new JournalError(
13170
+ "write-ahead-missing",
13171
+ `${settled.model} ${JSON.stringify(businessKey)} \u76F4\u63A5\u843D\u4E86 ${settled.status}\uFF0C\u800C\u5B83\u6B64\u524D**\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709**`,
13172
+ "\u5199\u524D\u843D\u8D26\u534F\u8BAE\uFF1A\u53D1\u8BF7\u6C42**\u4E4B\u524D**\u5148 begin() \u843D\u4E00\u6761 unknown\uFF0C\u62FF\u5230\u54CD\u5E94\u4E4B\u540E\u518D append() \u843D\u7EC8\u6001\u3002\u5C11\u4E86\u524D\u7F6E\u90A3\u4E00\u6761\u65F6\uFF0C\u8FDB\u7A0B\u5728\u300C\u670D\u52A1\u7AEF\u5DF2\u5EFA\u6210\u3001\u53F0\u8D26\u8FD8\u6CA1\u5199\u300D\u4E4B\u95F4\u88AB\u6253\u65AD\uFF0C\u7EED\u8DD1\u5C31\u4F1A\u628A\u8FD9\u4E00\u884C\u5F53\u6210\u4ECE\u6CA1\u8BD5\u8FC7\u800C\u91CD\u53D1 \u2014\u2014 \u90A3\u5C31\u662F\u91CD\u590D\u884C\u3002\u26A0\uFE0F \u672C\u95F8\u53EA\u8BA4\u300C\u6709\u6CA1\u6709\u524D\u7F6E\u8BB0\u5F55\u300D\uFF0C\u4E0D\u8BA4\u300C\u8FD9\u4E00\u8F6E\u6709\u6CA1\u6709 begin \u8FC7\u300D\uFF1A\u7EED\u8DD1\u65F6\u62FF\u4E0A\u4E00\u8F6E\u7684 unknown \u53BB\u5199 done \u662F\u56DE\u8BFB\u5224\u5B9A\u7684\u6B63\u5E38\u7ED3\u5C40\uFF0C\u5FC5\u987B\u653E\u884C"
13173
+ );
13174
+ }
13175
+ this.writeLine(JSON.stringify(entryJson(settled)), settled.status === "unknown");
13176
+ this.entries.push(settled);
13177
+ this.latestByKey.set(mapKey, settled);
13178
+ this.exists = true;
13179
+ return settled;
13180
+ }
13181
+ /**
13182
+ * 把一次 `--force-stale` 放行追加进台账(内存 + 磁盘)。
13183
+ *
13184
+ * 🔴 **不 fsync**:它不是崩溃标记 —— 丢了不会让任何一行被重放,而写前落账那一条丢了
13185
+ * 就等于那一行没落过账。
13186
+ * 🔴 走 `append` 同一条落盘路径与同一条错误边界:写失败时内存态一个字节都不许动,
13187
+ * 否则「台账里有据可查」这句话会在盘上落空而在内存里成立。
13188
+ */
13189
+ appendWaiver(waiver) {
13190
+ if (waiver === null || typeof waiver !== "object" || typeof waiver.verdict !== "string") {
13191
+ throw new JournalError(
13192
+ "bad-entry",
13193
+ `appendWaiver \u6536\u7684\u662F Waiver\uFF0C\u4E0D\u662F ${typeof waiver}`,
13194
+ "\u7528\u4E00\u4E2A Waiver \u5B57\u9762\u91CF\u6784\u9020 \u2014\u2014 \u5B83\u4E0E Entry \u662F\u4E24\u79CD\u884C\uFF0C\u4E0D\u8BB8\u4E92\u76F8\u9876\u66FF"
13195
+ );
13196
+ }
13197
+ this.writeLine(JSON.stringify(waiverJson(waiver)), false);
13198
+ this.waivers.push(waiver);
13199
+ this.exists = true;
13200
+ return waiver;
13201
+ }
13202
+ /**
13203
+ * 真正落盘的那一步。单独拆出来只为**让写失败有一个明确的边界** ——
13204
+ * 内存态的更新必须留在这个边界之外(写失败时台账不许在内存里「已经有了」)。
13205
+ *
13206
+ * 🔴 `sync` 由调用方给,不在这里按行的内容判:两种行走的是**同一条**落盘路径,
13207
+ * 而「值不值得 fsync」是各自的语义。
13208
+ */
13209
+ writeLine(line, sync) {
13210
+ try {
13211
+ this.layout.appendLine(JOURNAL_FILE, line, sync);
13212
+ } catch (e) {
13213
+ throw new JournalError(
13214
+ "journal-unwritable",
13215
+ `\u53F0\u8D26\u5199\u4E0D\u4E0B\u53BB\uFF1A${this.path}\uFF08${String(e)}\uFF09`,
13216
+ "\u78C1\u76D8\u6EE1 / \u53EA\u8BFB\u6302\u8F7D / \u6743\u9650 / \u4ECB\u8D28\u51FA\u9519\u90FD\u4F1A\u8D70\u5230\u8FD9\u91CC\u3002\u{1F534} **\u8FD9\u4E00\u8F6E\u5DF2\u7ECF\u53D1\u51FA\u53BB\u7684\u5199\uFF0C\u53EA\u5728\u53F0\u8D26\u91CC\u6709\u8BB0\u5F55**\uFF1B\u800C\u672C\u5C42\u5224\u4E0D\u51FA\u90A3\u4EFD\u6587\u4EF6\u6B64\u523B\u5728\u4E0D\u5728\uFF08\u8FD9\u4E00\u6B21\u843D\u8D26\u6B63\u662F\u5728\u5B83\u4E0A\u9762\u5931\u8D25\u7684\uFF09\u2014\u2014 \u6240\u4EE5\u8FD9\u91CC**\u4E0D\u7ED9\u300C\u5BF9\u5B83\u505A\u4EC0\u4E48\u300D\u7684\u6307\u4EE4**\uFF0C\u90A3\u53E5\u8BDD\u7531\u62FF\u5F97\u5230\u76D8\u4E0A\u4E8B\u5B9E\u7684\u90A3\u4E00\u5C42\u8BF4"
13217
+ );
13218
+ }
13219
+ }
13220
+ };
13221
+ function readbackFields(model, keyFields, key) {
13222
+ if (!Array.isArray(keyFields) || keyFields.length === 0 || keyFields.some((f) => typeof f !== "string" || !f.trim())) {
13223
+ throw new JournalError(
13224
+ "bad-entry",
13225
+ `${model} \u7684\u4E1A\u52A1\u952E\u5B57\u6BB5\u540D\u4E0D\u53EF\u7528\uFF08${JSON.stringify(keyFields)}\uFF09`,
13226
+ "\u56DE\u8BFB\u6309 filter \u9010\u5B57\u6BB5 eq\uFF0C\u5B57\u6BB5\u540D\u5FC5\u987B\u662F\u5DE5\u4EF6\u91CC businessKey.fields \u90A3\u51E0\u4E2A"
13227
+ );
13228
+ }
13229
+ const fields = keyFields;
13230
+ if (new Set(fields).size !== fields.length) {
13231
+ throw new JournalError(
13232
+ "bad-entry",
13233
+ `${model} \u7684\u4E1A\u52A1\u952E\u5B57\u6BB5\u91CC\u6709\u91CD\u540D\uFF1A${JSON.stringify(fields)}`,
13234
+ "\u540C\u4E00\u4E2A\u5B57\u6BB5\u88AB\u8981\u6C42\u540C\u65F6\u7B49\u4E8E\u4E24\u4E2A\u503C\u65F6\uFF0C\u56DE\u8BFB\u6052 0 \u884C \u21D2 \u88AB\u5224\u6210\u300C\u6CA1\u5EFA\u6210\u300D\u21D2 \u91CD\u5EFA\u4E00\u884C\u672C\u6765\u5C31\u5728\u7684\u8BB0\u5F55\u3002\u5148\u53BB\u5DE5\u4EF6\u91CC\u628A businessKey.fields \u7684\u91CD\u590D\u53BB\u6389"
13235
+ );
13236
+ }
13237
+ const parts = businessKeyOf(key);
13238
+ if (fields.length !== parts.length) {
13239
+ throw new JournalError(
13240
+ "bad-entry",
13241
+ `${model} \u7684\u4E1A\u52A1\u952E\u5B57\u6BB5\u6709 ${fields.length} \u4E2A\uFF0C\u800C\u8FD9\u4E00\u884C\u7684\u952E\u6709 ${parts.length} \u4E2A`,
13242
+ "\u4E24\u8005\u5FC5\u987B\u4E00\u4E00\u5BF9\u5E94 \u2014\u2014 \u6570\u76EE\u5BF9\u4E0D\u4E0A\u65F6\u62FC\u51FA\u6765\u7684 filter \u4F1A\u5C11\u4E00\u4E2A\u6761\u4EF6\uFF0C\u800C\u5C11\u4E00\u4E2A\u6761\u4EF6\u7684\u56DE\u8BFB\u4F1A\u5339\u914D\u5230**\u522B\u7684\u884C**"
13243
+ );
13244
+ }
13245
+ const projected = [];
13246
+ for (const name of ["id", ...fields]) if (!projected.includes(name)) projected.push(name);
13247
+ return projected;
13248
+ }
13249
+ async function resolveUnknown(client, model, keyFields, key) {
13250
+ const fields = readbackFields(model, keyFields, key);
13251
+ const parts = businessKeyOf(key);
13252
+ const body = {
13253
+ page: 0,
13254
+ // 2 就够:要的只是「0 / 1 / 更多」这个三分。多取一行是白花的服务端开销。
13255
+ size: 2,
13256
+ fields,
13257
+ // 🔴 一律用 `{and: [...]}` 包,哪怕只有一个 leaf(真服务器上实测两种写法同结果)——
13258
+ // 单键与复合键一条代码路径,少一处「只在复合键上才走到」的分支。
13259
+ filter: { and: keyFields.map((f, i) => ({ field: f, op: "eq", value: parts[i] })) }
13260
+ // ⚠️ 不带 `orders`:只取 2 行、不翻页,稳定排序在这里没有可守的前提;
13261
+ // 而实测有模型带不带 orders 都 400,少一个入参就少一类无谓的失败面。
13262
+ };
13263
+ const out = await client.post(listPath2(model), body);
13264
+ if (out.error !== "ok") {
13265
+ throw new JournalError(
13266
+ "readback-failed",
13267
+ `${model} \u6309\u4E1A\u52A1\u952E ${JSON.stringify(parts)} \u56DE\u8BFB\u5931\u8D25\uFF08HTTP ${out.status} / ${out.error}\uFF09`,
13268
+ "\u8FD9\u4E00\u884C\u7684\u72B6\u6001\u662F unknown\uFF08\u670D\u52A1\u7AEF\u53EF\u80FD\u5DF2\u7ECF\u5EFA\u6210\u3001\u54CD\u5E94\u5728\u56DE\u7A0B\u4E22\u4E86\uFF09\u3002\u56DE\u8BFB\u95EE\u4E0D\u51FA\u6765\u65F6**\u4E0D\u8BB8**\u5F53\u6210\u300C\u6CA1\u5EFA\u6210\u300D\u53BB\u91CD\u5EFA \u2014\u2014 \u90A3\u6B63\u662F\u4EA7\u751F\u91CD\u590D\u884C\u7684\u90A3\u6761\u8DEF\u3002\u5148\u6309 error \u90A3\u4E00\u7EF4\u5904\u7F6E\uFF08unauthorized=\u91CD\u767B / forbidden=\u8981\u6743\u9650 / network=\u901A\u9053 / server-error=\u770B\u670D\u52A1\u7AEF\uFF09\u518D\u8DD1\u4E00\u6B21\u3002\u26A0\uFE0F \u82E5 details \u91CC\u5199\u7740\u67D0\u4E2A\u5B57\u6BB5\u4E0D\u5B58\u5728\uFF0C\u90A3\u662F**\u4E1A\u52A1\u952E\u5B57\u6BB5\u540D\u5199\u9519\u4E86**\uFF1Afilter \u5BF9\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5\u540D\u662F\u786C\u5931\u8D25\u7684\u3002\u{1F534} **\u522B\u6309 code \u5206\u652F**\uFF1A\u9876\u5C42 error.code \u4E24\u4E2A\u6A21\u578B\u90FD\u662F BUSINESS_RULE_VIOLATION\uFF08\u592A\u7C97\uFF09\uFF0C\u800C details \u91CC\u65B9\u62EC\u53F7\u90A3\u4E2A token \u968F\u6A21\u578B\u53D8\uFF08\u4E0D\u7A33\uFF09\u2014\u2014 \u4E24\u5904\u90FD\u4E0D\u53EF\u673A\u8BFB"
13269
+ );
13270
+ }
13271
+ const { rows, total, defect } = readPage(out.body);
13272
+ if (rows === null) {
13273
+ throw new JournalError(
13274
+ "readback-bad-shape",
13275
+ `${model} \u56DE\u8BFB HTTP ${out.status} \u4F46\u54CD\u5E94\u5F62\u72B6\u7528\u4E0D\u4E86\uFF1A${defect}`,
13276
+ "\u8FD9\u4EFD\u54CD\u5E94\u662F\u8C01\u7ED9\u7684\uFF0C\u672C\u6A21\u5757**\u6CA1\u6709\u67E5\u8FC7**\uFF0C\u4E5F**\u4E0D\u731C\u5F62\u72B6**\uFF1A\u731C\u9519\u7684\u4EE3\u4EF7\u662F\u628A\u4E00\u884C\u5DF2\u7ECF\u5EFA\u597D\u7684\u8BB0\u5F55\u5224\u6210\u300C\u6CA1\u5EFA\u6210\u300D\uFF0C\u7136\u540E\u518D\u5EFA\u4E00\u904D\u3002\u4E0A\u9762\u90A3\u53E5\u91CC\u662F\u8FD9\u6B21\u6536\u5230\u7684\u5F62\u72B6\uFF0C\u7167\u539F\u6837\u628A\u8FD9\u4E2A\u8BF7\u6C42\u91CD\u6253\u4E00\u6B21\uFF08curl \u5373\u53EF\uFF09\u770B\u770B\u662F\u8C01\u5728\u7B54"
13277
+ );
13278
+ }
13279
+ if (total > 1) {
13280
+ throw new JournalError(
13281
+ "readback-ambiguous",
13282
+ `${model} \u7684\u4E1A\u52A1\u952E ${JSON.stringify(parts)} \u5728\u7CFB\u7EDF\u91CC\u5339\u914D\u5230 ${total} \u884C`,
13283
+ "\u4E1A\u52A1\u952E\u662F\u5E42\u7B49\u7684\u652F\u70B9\uFF0C\u5B83\u5728\u672C\u79DF\u6237\u4E0D\u552F\u4E00\u7684\u8BDD\u300C\u8FD9\u4E00\u884C\u5EFA\u6210\u6CA1\u6709\u300D\u6839\u672C\u6CA1\u6709\u7B54\u6848\u3002\u26A0\uFE0F \u8FD9\u53EF\u80FD\u662F\u4E0A\u4E00\u8F6E**\u5DF2\u7ECF**\u91CD\u590D\u5EFA\u8FC7\u4E86 \u2014\u2014 \u5148\u53BB\u7CFB\u7EDF\u91CC\u628A\u91CD\u590D\u884C\u5904\u7406\u6389\uFF0C\u518D\u51B3\u5B9A\u8FD9\u4E00\u884C\u600E\u4E48\u529E\u3002kit \u4E0D\u66FF\u4F60\u6311\u4E00\u884C\u8BA4\u9886"
13284
+ );
13285
+ }
13286
+ if (total === 0) return { status: "failed", serverId: null, total: 0 };
13287
+ const serverId = rows.length > 0 ? rows[0].id : void 0;
13288
+ if (typeof serverId !== "string" || !serverId) {
13289
+ throw new JournalError(
13290
+ "readback-bad-shape",
13291
+ `${model} \u56DE\u8BFB\u8BF4\u6709 1 \u884C\uFF0C\u4F46\u90A3\u4E00\u884C\u7684 id \u662F ${JSON.stringify(serverId ?? null)}`,
13292
+ "id \u662F\u540E\u7EED update / \u5F15\u7528\u56DE\u586B\u8981\u7528\u7684\u4E1C\u897F\u3002\u62FF\u4E0D\u5230\u5B83\u65F6\u8FD9\u6761\u56DE\u8BFB**\u6CA1\u6709\u7ED3\u8BBA**\uFF0C\u8BB0\u6210 done \u4F1A\u8BA9\u4E0B\u6E38\u62FF\u7740\u4E00\u4E2A null \u53BB\u53D1\u8BF7\u6C42"
13293
+ );
13294
+ }
13295
+ return { status: "done", serverId, total };
13296
+ }
13297
+ var LEASE_FILE = ".lease.json";
13298
+ var LEASE_KEYS = ["host", "pid", "roundId", "acquiredAt", "heartbeatAt"];
13299
+ var LEASE_STALE_SECONDS = DEFAULT_HTTP_TIMEOUT_MS / 1e3 * 4;
13300
+ var LEASE_HEARTBEAT_SECONDS = LEASE_STALE_SECONDS / 4;
13301
+ var LeaseViolation = class extends Error {
13302
+ reason;
13303
+ detail;
13304
+ hint;
13305
+ constructor(reason, detail, hint = "") {
13306
+ super(`[${reason}] ${detail}${hint ? ` \u2014\u2014 ${hint}` : ""}`);
13307
+ this.name = "LeaseViolation";
13308
+ this.reason = reason;
13309
+ this.detail = detail;
13310
+ this.hint = hint;
13311
+ }
13312
+ };
13313
+ var SYSTEM_CLOCK = {
13314
+ now: () => /* @__PURE__ */ new Date(),
13315
+ monotonic: () => Number(process.hrtime.bigint() / 1000000n) / 1e3
13316
+ };
13317
+ function leaseIdentity(payload) {
13318
+ return [payload.host, payload.pid, payload.roundId];
13319
+ }
13320
+ function sameIdentity(a, b) {
13321
+ return a.length === b.length && a.every((x, i) => x === b[i]);
13322
+ }
13323
+ function readLease(layout, file = LEASE_FILE) {
13324
+ const p = path16.join(layout.dir, file);
13325
+ if (!existsSync8(p)) return [null, `${p} \u4E0D\u5B58\u5728`];
13326
+ let text2;
13327
+ try {
13328
+ text2 = layout.readText(file);
13329
+ } catch (e) {
13330
+ if (e instanceof TypeError) return [null, `${p} \u4E0D\u662F UTF-8 \u7F16\u7801`];
13331
+ return [null, `${p} \u8BFB\u4E0D\u4E86\uFF1A${String(e)}`];
13332
+ }
13333
+ let body;
13334
+ try {
13335
+ body = JSON.parse(text2);
13336
+ } catch (e) {
13337
+ return [null, `${p} \u4E0D\u662F\u5408\u6CD5 JSON\uFF1A${String(e)}`];
13338
+ }
13339
+ if (body === null || typeof body !== "object" || Array.isArray(body)) {
13340
+ return [null, `${p} \u7684\u5185\u5BB9\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61`];
13341
+ }
13342
+ const obj = body;
13343
+ const missing = LEASE_KEYS.filter((k) => !(k in obj));
13344
+ if (missing.length > 0) return [null, `${p} \u7F3A\u4E86 ${JSON.stringify(missing)} \u8FD9\u51E0\u4E2A\u952E`];
13345
+ return [obj, ""];
13346
+ }
13347
+ function serialiseLease(payload) {
13348
+ return `${JSON.stringify(payload, null, 2)}
13349
+ `;
13350
+ }
13351
+ function hostname2() {
13352
+ try {
13353
+ return os3.hostname() || "unknown-host";
13354
+ } catch {
13355
+ return "unknown-host";
13356
+ }
13357
+ }
13358
+ var LEASE_JUDGE_SIGNPOST = "\u89E3\u51B3\u4E4B\u540E\u5E26 `--resume` \u518D\u8DD1\uFF1B\u5982\u679C\u90A3\u4E00\u6B21\u62A5\u4E86\u79DF\u7EA6\u76F8\u5173\u7684\u95EE\u9898\uFF0C**\u7167\u90A3\u6761\u6D88\u606F\u8D70**\u3002";
13359
+ function leaseStampNote(raw, beat, at) {
13360
+ if (beat === null) {
13361
+ return `\u76D8\u4E0A\u90A3\u4E2A\u503C\u539F\u6837\u662F ${JSON.stringify(raw)} \u2014\u2014 \u672C kit \u89E3\u6790\u4E0D\u51FA\u5B83\u7684\u5E74\u9F84\u3002`;
13362
+ }
13363
+ const seconds = (at.getTime() - beat.getTime()) / 1e3;
13364
+ if (seconds < 0) {
13365
+ return `\u76D8\u4E0A\u90A3\u4E2A\u503C\u539F\u6837\u662F ${String(raw)}\uFF0C\u6BD4\u5F53\u4E0B\u665A ${(-seconds).toFixed(0)} \u79D2\u3002`;
13366
+ }
13367
+ return `\u76D8\u4E0A\u90A3\u4E2A\u503C\u539F\u6837\u662F ${String(raw)}\uFF0C\u8DDD\u5F53\u4E0B ${seconds.toFixed(0)} \u79D2\u3002`;
13368
+ }
13369
+ var Lease = class {
13370
+ layout;
13371
+ path;
13372
+ host;
13373
+ pid;
13374
+ roundId;
13375
+ acquiredAt;
13376
+ heartbeatAt;
13377
+ reclaimed;
13378
+ clock;
13379
+ /** 节流用的**单调**标记,与 `heartbeatAt`(墙钟、要落盘)分开两个钟。 */
13380
+ beatMark;
13381
+ constructor(layout, spec, reclaimed = null, clock = SYSTEM_CLOCK) {
13382
+ this.layout = layout;
13383
+ this.path = path16.join(layout.dir, LEASE_FILE);
13384
+ this.host = spec.host;
13385
+ this.pid = spec.pid;
13386
+ this.roundId = spec.roundId;
13387
+ this.acquiredAt = spec.acquiredAt;
13388
+ this.heartbeatAt = spec.heartbeatAt;
13389
+ this.reclaimed = reclaimed;
13390
+ this.clock = clock;
13391
+ this.beatMark = clock.monotonic();
13392
+ }
13393
+ /**
13394
+ * 🔴 身份是 `(host, pid, roundId)` 三件套。
13395
+ *
13396
+ * 单靠 `pid` 不行:`kill -9` 之后 pid 会被复用,一个**别的**进程会被认成自己。
13397
+ * `roundId` 后半截是随机的,撞不上。
13398
+ */
13399
+ get identity() {
13400
+ return [this.host, this.pid, this.roundId];
13401
+ }
13402
+ payload() {
13403
+ return {
13404
+ host: this.host,
13405
+ pid: this.pid,
13406
+ roundId: this.roundId,
13407
+ acquiredAt: stampOf(this.acquiredAt),
13408
+ heartbeatAt: stampOf(this.heartbeatAt)
13409
+ };
13410
+ }
13411
+ /**
13412
+ * 盖一次心跳。**先核对这份租约还是不是自己的**,不是就抛 `lost`。
13413
+ *
13414
+ * 🔴 不核对的话,本进程会把一份**已经被别人回收**的租约悄悄抢回来 ——
13415
+ * 于是两个写者都以为自己独占。核对一次的代价是一次读文件。
13416
+ *
13417
+ * 🔴 **这个方法无条件盖章,不看间隔** —— 想要节流的走 {@link heartbeatIfDue}。
13418
+ * 两种语义**不塞进一个名字**:真正想强制盖一次的地方拿到的必须是「一定盖」,
13419
+ * 而不是「可能盖了、可能没盖」。
13420
+ *
13421
+ * ⚠️ 本模块**不起后台线程**:要调用方自己调。心跳与请求在同一个线程上,
13422
+ * 一次阻塞的请求期间它发不出去 —— {@link LEASE_STALE_SECONDS} 就是照这一点定的。
13423
+ */
13424
+ heartbeat() {
13425
+ const [held, why] = readLease(this.layout);
13426
+ if (held === null) {
13427
+ throw new LeaseViolation(
13428
+ "lost",
13429
+ `\u79DF\u7EA6\u6587\u4EF6\u4E0D\u89C1\u4E86\u6216\u8BFB\u4E0D\u4E86\uFF08${this.path}\uFF09\uFF1A${why}`,
13430
+ "\u672C\u6A21\u5757\u53EA\u77E5\u9053**\u8FD9\u4E00\u6B21\u8BFB\u4E0D\u5230\u5B83**\uFF08\u539F\u56E0\u5728\u4E0A\u9762\u90A3\u53E5\u62EC\u53F7\u91CC\uFF09\uFF0C\u8FD9\u4E2A\u6587\u4EF6\u662F\u600E\u4E48\u6CA1\u7684\u5B83**\u6CA1\u6709\u67E5\u8FC7**\u3002\u65E0\u8BBA\u5982\u4F55\uFF0C\u6211\u65B9\u5DF2\u7ECF\u4E0D\u80FD\u8BC1\u660E\u81EA\u5DF1\u662F\u552F\u4E00\u5199\u8005 \u2014\u2014 \u505C\u4E0B\u6765\uFF0C\u522B\u63A5\u7740\u5199"
13431
+ );
13432
+ }
13433
+ if (!sameIdentity(leaseIdentity(held), this.identity)) {
13434
+ throw new LeaseViolation(
13435
+ "lost",
13436
+ `\u79DF\u7EA6\u5DF2\u7ECF\u4E0D\u662F\u6211\u65B9\u7684\u4E86\uFF1A\u6587\u4EF6\u91CC\u662F ${JSON.stringify(leaseIdentity(held))}\uFF0C\u6211\u65B9\u662F ${JSON.stringify(this.identity)}`,
13437
+ "\u672C\u6A21\u5757\u53EA\u6BD4\u5BF9\u4E86\u521A\u8BFB\u5230\u7684\u8FD9\u4E00\u4EFD\u8EAB\u4EFD\uFF1A\u76D8\u4E0A\u662F\u8C01\u3001\u6211\u65B9\u662F\u4EC0\u4E48\u65F6\u5019\u88AB\u9876\u6389\u7684\uFF0C\u5B83**\u4E00\u6B21\u90FD\u6CA1\u67E5\u8FC7**\u3002**\u7ACB\u523B\u505C\u624B**\uFF1A\u6211\u65B9\u5DF2\u7ECF\u4E0D\u80FD\u8BC1\u660E\u81EA\u5DF1\u662F\u552F\u4E00\u5199\u8005\uFF0C\u800C\u53F0\u8D26\u53EA\u6709\u4E00\u4EFD \u2014\u2014 \u5DF2\u7ECF\u53D1\u51FA\u53BB\u7684\u5199\u90FD\u8BB0\u5728\u53F0\u8D26\u91CC\uFF0C\u522B\u5220\u5B83"
13438
+ );
13439
+ }
13440
+ const previousBeat = this.heartbeatAt;
13441
+ const attemptedAt = this.clock.now();
13442
+ this.heartbeatAt = attemptedAt;
13443
+ try {
13444
+ this.layout.replaceAtomically(LEASE_FILE, serialiseLease(this.payload()));
13445
+ } catch (e) {
13446
+ this.heartbeatAt = previousBeat;
13447
+ const [beat] = parseStamp(held.heartbeatAt);
13448
+ throw new LeaseViolation(
13449
+ "lease-unwritable",
13450
+ `\u76D6\u5FC3\u8DF3\u65F6\u5199\u4E0D\u8FDB\u79DF\u7EA6\u6587\u4EF6 ${this.path}\uFF1A${String(e)}`,
13451
+ `**\u8FD9\u4E00\u6B21\u5FC3\u8DF3\u6CA1\u6709\u76D6\u4E0A**\uFF0C\u79DF\u7EA6\u6587\u4EF6\u7684\u5185\u5BB9**\u6CA1\u6709\u88AB\u6539\u52A8**\uFF08\u4E34\u65F6\u6587\u4EF6\u5DF2\u6536\u62FE\u6389\uFF0C\u6539\u540D\u6CA1\u9876\u4E0A\u53BB\uFF09\u3002${leaseStampNote(held.heartbeatAt, beat, attemptedAt)}\u5199\u4E4B\u524D\u521A\u6838\u5BF9\u8FC7\u8EAB\u4EFD \u2014\u2014 **\u90A3\u4E00\u6B21\u8BFB\u5230\u7684**\u79DF\u7EA6\u662F\u6211\u65B9\u7684\u3002\u4E09\u79CD\u5E38\u89C1\u6210\u56E0\uFF1A\u2460 \u78C1\u76D8\u6EE1\uFF1B\u2461 \u76EE\u5F55\u53EA\u8BFB\u6216\u6743\u9650\u4E0D\u8DB3\uFF1B\u2462 \u4ECB\u8D28\u51FA\u9519\u3002**\u5148\u505C\u624B\u518D\u5904\u7406**\uFF1A\u5DF2\u7ECF\u53D1\u51FA\u53BB\u7684\u5199\u90FD\u8BB0\u5728 ${path16.dirname(this.path)} \u7684\u53F0\u8D26\u91CC\uFF08\u5199\u524D\u843D\u8D26\uFF1A\u53D1\u8BF7\u6C42\u4E4B\u524D\u5148 begin \u843D\u4E00\u6761 unknown\uFF09\u3002${LEASE_JUDGE_SIGNPOST}`
13452
+ );
13453
+ }
13454
+ this.beatMark = this.clock.monotonic();
13455
+ return this;
13456
+ }
13457
+ /**
13458
+ * 距上一次盖章不足 {@link LEASE_HEARTBEAT_SECONDS} 就**不盖**,够了才盖一次。
13459
+ *
13460
+ * 🔴 **节流住在这一侧**:执行器每花掉一次请求就调它一次,而「多久算够」是租约的事
13461
+ * —— 执行器不该知道那两个时间常量。少了这一层,一轮 3000 行就是 3000 次
13462
+ * 「读租约 + 写租约」。
13463
+ *
13464
+ * 比的是**本对象上一次盖章以来的单调秒**,既不是盘上那个值、也不是墙钟差:
13465
+ * 盘上的值可能是别人写的;而墙钟被 NTP 往回拨一次,「距上次多久」会变成负数,
13466
+ * 从此再也不到钟。**盘上写的仍然是墙钟** —— 别的进程要拿它比阈值,两个钟别串。
13467
+ *
13468
+ * ⚠️ {@link heartbeat} 写失败时不推进那个标记 ⇒ 下一次调用照样够钟。
13469
+ * ⚠️ 没到钟的那一次**什么都不做**,原样返回 `this`(不读文件、不写文件)——
13470
+ * 也就**不核身份**:本方法**不是**「租约还归我吗」的探针。
13471
+ */
13472
+ heartbeatIfDue() {
13473
+ if (this.clock.monotonic() - this.beatMark < LEASE_HEARTBEAT_SECONDS) return this;
13474
+ return this.heartbeat();
13475
+ }
13476
+ /**
13477
+ * 释放租约(删文件)。→ 真的删了没有。
13478
+ *
13479
+ * 🔴 **只删自己的那一份**:文件已经易主时什么都不做并返回 false。
13480
+ * 删别人的租约等于给下一个进程发一张假的通行证。
13481
+ */
13482
+ release() {
13483
+ const [held] = readLease(this.layout);
13484
+ if (held === null || !sameIdentity(leaseIdentity(held), this.identity)) return false;
13485
+ return this.layout.remove(LEASE_FILE);
13486
+ }
13487
+ };
13488
+ function acquireLease(workDir, roundId, clock = SYSTEM_CLOCK) {
13489
+ if (typeof roundId !== "string" || !roundId.trim()) {
13490
+ throw new LeaseViolation(
13491
+ "held-by-another",
13492
+ `roundId \u4E0D\u53EF\u7528\uFF08${JSON.stringify(roundId)}\uFF09`,
13493
+ "\u79DF\u7EA6\u7684\u8EAB\u4EFD\u662F (host, pid, roundId)\uFF1BroundId \u7A7A\u6389\u7684\u8BDD pid \u590D\u7528\u4F1A\u8BA9\u4E00\u4E2A\u522B\u7684\u8FDB\u7A0B\u88AB\u8BA4\u6210\u81EA\u5DF1\u3002\u7528\u8BA1\u5212\u91CC\u7684\u90A3\u4E2A roundId"
13494
+ );
13495
+ }
13496
+ const layout = new WorkLayout(workDirOf(workDir));
13497
+ const p = path16.join(layout.dir, LEASE_FILE);
13498
+ const me = [hostname2(), process.pid, roundId];
13499
+ const now = clock.now();
13500
+ const fresh = new Lease(
13501
+ layout,
13502
+ { host: me[0], pid: me[1], roundId, acquiredAt: now, heartbeatAt: now },
13503
+ null,
13504
+ clock
13505
+ );
13506
+ try {
13507
+ layout.createExclusive(LEASE_FILE, serialiseLease(fresh.payload()));
13508
+ return fresh;
13509
+ } catch (e) {
13510
+ const code = e.code;
13511
+ if (code !== "EEXIST") {
13512
+ throw new LeaseViolation(
13513
+ "lease-unwritable",
13514
+ `${p} \u5EFA\u4E0D\u51FA\u6765\uFF1A${String(e)}`,
13515
+ "\u79DF\u7EA6\u662F\u7528\u300C\u5199\u4E34\u65F6\u6587\u4EF6 + \u786C\u94FE\u63A5\u539F\u5B50\u6302\u4E0A\u53BB\u300D\u843D\u5730\u7684\uFF08\u8FD9\u6837\u5B83\u4E00\u51FA\u73B0\u5C31\u662F\u5B8C\u6574\u7684\uFF09\u3002\u8D70\u5230\u8FD9\u91CC\u7684\u4E09\u79CD\u5E38\u89C1\u6210\u56E0\uFF1A\u2460 \u8FD9\u4E2A\u76EE\u5F55\u6240\u5728\u7684\u6587\u4EF6\u7CFB\u7EDF**\u4E0D\u652F\u6301\u786C\u94FE\u63A5**\uFF08FAT / exFAT / \u90E8\u5206 SMB \u5171\u4EAB\uFF09\uFF1B\u2461 \u76EE\u5F55\u53EA\u8BFB\u6216\u6743\u9650\u4E0D\u8DB3\uFF1B\u2462 \u78C1\u76D8\u6EE1\u3002\u2460 \u7684\u8BDD\u628A work \u76EE\u5F55\u632A\u5230\u672C\u5730\u76D8\u4E0A\u518D\u8DD1"
13516
+ );
13517
+ }
13518
+ }
13519
+ const [held, why] = readLease(layout);
13520
+ if (held === null) {
13521
+ throw new LeaseViolation(
13522
+ "lease-unreadable",
13523
+ `${p} \u5728\uFF0C\u4F46\u8BFB\u4E0D\u51FA\u5185\u5BB9\uFF1A${why}`,
13524
+ `\u8BFB\u4E0D\u51FA\u5185\u5BB9\u5C31\u5224\u4E0D\u51FA\u5B83\u662F\u6D3B\u7684\u8FD8\u662F\u9648\u65E7\u7684\uFF0C\u800C\u300C\u5224\u4E0D\u51FA\u300D\u5F53\u6210\u300C\u9648\u65E7\u300D\u5C31\u662F\u5141\u8BB8\u53CC\u5199\u3002\u786E\u8BA4\u8FD9\u4E2A work \u76EE\u5F55\u4E0A**\u6CA1\u6709\u522B\u7684 kit \u8FDB\u7A0B\u5728\u8DD1**\u4E4B\u540E\uFF0C\u624B\u5DE5\u5220\u6389 ${p} \u518D\u8DD1\u4E00\u6B21`
13525
+ );
13526
+ }
13527
+ if (sameIdentity(leaseIdentity(held), me)) {
13528
+ const [acquired] = parseStamp(held.acquiredAt);
13529
+ const again = new Lease(
13530
+ layout,
13531
+ { host: me[0], pid: me[1], roundId, acquiredAt: acquired ?? now, heartbeatAt: now },
13532
+ null,
13533
+ clock
13534
+ );
13535
+ try {
13536
+ layout.replaceAtomically(LEASE_FILE, serialiseLease(again.payload()));
13537
+ } catch (e) {
13538
+ throw new LeaseViolation(
13539
+ "lease-unwritable",
13540
+ `\u5E42\u7B49\u91CD\u5165\u65F6\u5237\u65B0\u79DF\u7EA6\u5199\u4E0D\u8FDB\u53BB\uFF08${String(e)}\uFF09\u3002\u79DF\u7EA6\u6587\u4EF6\uFF1A${p}`,
13541
+ "\u79DF\u7EA6\u6587\u4EF6\u5DF2\u7ECF\u5728\u3001\u800C\u4E14**\u5C31\u662F\u6211\u65B9\u7684**\uFF08\u540C host + pid + roundId\uFF09\uFF0C\u5199\u5931\u8D25\u53EA\u662F\u6CA1\u80FD\u628A heartbeatAt \u5237\u5230\u5F53\u4E0B \u2014\u2014 \u6587\u4EF6\u5185\u5BB9\u4ECD\u662F\u539F\u6837\uFF08\u4E34\u65F6\u6587\u4EF6\u5DF2\u6536\u62FE\u6389\uFF0C\u6539\u540D\u6CA1\u9876\u4E0A\u53BB\uFF09\u3002**\u8FD9\u4E00\u6B21\u8C03\u7528\u6CA1\u6709\u4EA4\u51FA Lease**\uFF0C\u4EC0\u4E48\u90FD\u6CA1\u505A\u3002\u4E09\u79CD\u5E38\u89C1\u6210\u56E0\uFF1A\u2460 \u78C1\u76D8\u6EE1\uFF1B\u2461 \u76EE\u5F55\u53EA\u8BFB\u6216\u6743\u9650\u4E0D\u8DB3\uFF1B\u2462 \u4ECB\u8D28\u51FA\u9519\u3002\u89E3\u51B3\u4E4B\u540E\u518D\u8DD1\u4E00\u6B21\uFF1B\u26A0\uFE0F \u8FD9\u4E00\u8F6E\u6B64\u524D\u53D1\u51FA\u53BB\u7684\u5199\uFF08\u5982\u679C\u6709\uFF09\u90FD\u8BB0\u5728\u53F0\u8D26\u91CC\uFF0C\u7EED\u8DD1\u9760\u5B83\u5224"
13542
+ );
13543
+ }
13544
+ return again;
13545
+ }
13546
+ const [beat, beatWhy] = parseStamp(held.heartbeatAt);
13547
+ if (beat === null) {
13548
+ throw new LeaseViolation(
13549
+ "age-unknown",
13550
+ `${p} \u7684 heartbeatAt \u8BFB\u4E0D\u51FA\u5E74\u9F84\uFF08${beatWhy}\uFF09\uFF0C\u6301\u6709\u8005\u662F ${JSON.stringify(leaseIdentity(held))}`,
13551
+ `\u5224\u4E0D\u51FA\u8FD9\u4EFD\u79DF\u7EA6\u662F\u65B0\u662F\u65E7\u65F6**\u4E0D\u8BB8**\u628A\u5B83\u5F53\u9648\u65E7\u7684\u62A2\u8FC7\u6765 \u2014\u2014 \u300C\u6CA1\u67E5\u51FA\u6765\u300D\u5F53\u6210\u300C\u67E5\u8FC7\u3001\u6CA1\u95EE\u9898\u300D\u6B63\u662F\u672C kit \u53CD\u590D\u5728\u6CBB\u7684\u75C5\u3002\u786E\u8BA4\u90A3\u4E2A\u8FDB\u7A0B\u786E\u5B9E\u4E0D\u5728\u4E86\u4E4B\u540E\uFF0C\u624B\u5DE5\u5220\u6389 ${p} \u518D\u8DD1\u4E00\u6B21`
13552
+ );
13553
+ }
13554
+ const age = (now.getTime() - beat.getTime()) / 1e3;
13555
+ if (age < LEASE_STALE_SECONDS) {
13556
+ throw new LeaseViolation(
13557
+ "held-by-another",
13558
+ `${p} \u5DF2\u88AB ${JSON.stringify(leaseIdentity(held))} \u6301\u6709\uFF0C\u6700\u8FD1\u4E00\u6B21\u5FC3\u8DF3\u5728 ${age.toFixed(0)} \u79D2\u524D\uFF08\u9608\u503C ${LEASE_STALE_SECONDS} \u79D2\uFF09`,
13559
+ "\u540C\u4E00\u4E2A work \u76EE\u5F55\u540C\u65F6\u53EA\u5141\u8BB8\u4E00\u4E2A\u5199\u8005\uFF1A\u4E24\u4E2A\u5199\u8005\u5171\u7528\u4E00\u4EFD\u53F0\u8D26\uFF0C\u800C\u53F0\u8D26\u662F\u300C\u8FD9\u4E00\u884C\u5EFA\u8FC7\u6CA1\u6709\u300D\u7684\u552F\u4E00\u4F9D\u636E\u3002\u7B49\u90A3\u4E00\u8F6E\u8DD1\u5B8C\uFF0C\u6216\u8005\u786E\u8BA4\u90A3\u4E2A\u6301\u6709\u8005\u771F\u7684\u4E0D\u5728\u4E86\uFF0C\u518D\u8DD1\u4E00\u6B21 \u2014\u2014 \u786E\u8BA4\u4E0D\u4E86\u5C31\u522B\u62A2"
13560
+ );
13561
+ }
13562
+ const taken = new Lease(
13563
+ layout,
13564
+ { host: me[0], pid: me[1], roundId, acquiredAt: now, heartbeatAt: now },
13565
+ { identity: leaseIdentity(held), heartbeatAt: held.heartbeatAt, ageSeconds: Math.round(age * 10) / 10 },
13566
+ clock
13567
+ );
13568
+ try {
13569
+ layout.replaceAtomically(LEASE_FILE, serialiseLease(taken.payload()));
13570
+ } catch (e) {
13571
+ throw new LeaseViolation(
13572
+ "lease-unwritable",
13573
+ `\u56DE\u6536\u9648\u65E7\u79DF\u7EA6\u65F6\u5199\u4E0D\u8FDB\u53BB\uFF08${String(e)}\uFF09\u3002\u79DF\u7EA6\u6587\u4EF6\uFF1A${p}`,
13574
+ `\u90A3\u4EFD\u9648\u65E7\u79DF\u7EA6\uFF08${JSON.stringify(leaseIdentity(held))}\uFF0C\u5FC3\u8DF3\u5728 ${age.toFixed(0)} \u79D2\u524D\uFF09**\u6CA1\u6709\u88AB\u9876\u6389\uFF0C\u6587\u4EF6\u4ECD\u662F\u539F\u6837**\uFF08\u4E34\u65F6\u6587\u4EF6\u5DF2\u6536\u62FE\u6389\uFF0C\u6539\u540D\u6CA1\u9876\u4E0A\u53BB\uFF09\u3002\u8FD9\u4E00\u8F6E**\u6CA1\u6709\u62FF\u5230\u79DF\u7EA6**\uFF1B\u5199\u8BF7\u6C42\u662F\u62FF\u5230\u79DF\u7EA6\u4E4B\u540E\u624D\u5F00\u59CB\u53D1\u7684\uFF0C\u6240\u4EE5\u6B64\u523B\u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u6CA1\u6709\u53D1\u51FA\u53BB\u3002\u4E09\u79CD\u5E38\u89C1\u6210\u56E0\uFF1A\u2460 \u78C1\u76D8\u6EE1\uFF1B\u2461 \u76EE\u5F55\u53EA\u8BFB\u6216\u6743\u9650\u4E0D\u8DB3\uFF1B\u2462 \u4ECB\u8D28\u51FA\u9519\u3002\u89E3\u51B3\u4E4B\u540E\u518D\u8DD1\u4E00\u6B21`
13575
+ );
13576
+ }
13577
+ return taken;
13578
+ }
13579
+
13580
+ // src/fde/seed/execute.ts
13581
+ var VERSION4 = 1;
13582
+ var EXECUTABLE_ACTIONS = ["create", "skip"];
13583
+ var RESOLVABLE_REFS = ["no-parent", "existing-index", "wave-row"];
13584
+ var UNRESOLVABLE_REFS = [
13585
+ "unchecked-no-index",
13586
+ "unresolved-no-index",
13587
+ "ref-key-mismatch",
13588
+ "ref-target-key-space",
13589
+ "ref-not-found"
13590
+ ];
13591
+ var REF_NEXT_STEPS = {
13592
+ "unchecked-no-index": "\u8FD9\u4E2A\u6A21\u578B\u8FD9\u4E00\u8F6E\u6CA1\u6709\u65E2\u5B58\u7D22\u5F15\uFF08\u7236\u6307\u9488\u6CA1\u67E5\u8FC7\u65E2\u5B58\uFF09\u2014\u2014 \u5148\u8BA9\u5B83\u7684\u65E2\u5B58\u7D22\u5F15\u53D6\u6570\u6210\u529F\uFF0C\u518D\u8DD1\u4E00\u6B21 plan",
13593
+ "unresolved-no-index": "\u5DE5\u4EF6\u7684 models[] \u91CC**\u6CA1\u6709**\u88AB\u5F15\u7528\u7684\u90A3\u4E2A\u6A21\u578B \u21D2 \u6CA1\u4EBA\u53BB\u5EFA\u5B83\u7684\u7D22\u5F15\u3002\u628A\u90A3\u4E2A\u6A21\u578B\u4E5F\u5217\u8FDB models[]\uFF08\u54EA\u6015\u5B83\u8FD9\u4E00\u8F6E\u4E00\u884C\u90FD\u4E0D\u5BFC\uFF0C\u6709\u4E86\u5B83\u7684 businessKey\uFF0C\u7D22\u5F15\u5C31\u4F1A\u88AB\u5EFA\u51FA\u6765\uFF09",
13594
+ "ref-key-mismatch": "\u90A3\u4E2A\u6A21\u578B\u7684\u7D22\u5F15**\u5EFA\u6210\u4E86**\uFF0C\u4F46\u5B83\u662F\u6309\u5DE5\u4EF6\u7ED9\u5B83\u58F0\u660E\u7684 businessKey \u5EFA\u7684\uFF0C\u4E0E\u8FD9\u91CC\u7684 resolveBy.keyField \u4E0D\u662F\u540C\u4E00\u4E2A\u952E \u21D2 \u6362\u4E0D\u51FA id\u3002\u628A\u4E24\u8005\u5BF9\u9F50\uFF08\u6539 keyField\uFF0C\u6216\u6539\u90A3\u4E2A\u6A21\u578B\u7684 businessKey\uFF09\u3002\u{1F534} \u76EE\u6807\u6A21\u578B\u662F**\u590D\u5408\u4E1A\u52A1\u952E**\u65F6\u5FC5\u7136\u843D\u8FD9\u4E00\u6863\uFF1A\u4E00\u4E2A\u5355\u503C keyField \u6362\u4E0D\u51FA\u4E00\u4E2A\u590D\u5408\u952E\uFF0C\u8FD9\u65F6\u53EA\u80FD\u6539\u6570\u636E\u6A21\u578B\u6216\u8D70\u4EBA\u5DE5",
13595
+ "ref-target-key-space": "\u88AB\u5F15\u7528\u7684\u90A3\u4E2A\u6A21\u578B\uFF0C**\u5B83\u81EA\u5DF1\u7684\u4E1A\u52A1\u952E**\u5E26 resolveBy \u21D2 \u5B83\u7684\u884C\u952E\u4E0E\u65E2\u5B58\u7D22\u5F15\u90FD\u5728**\u89E3\u6790\u540E\u7684 id** \u7A7A\u95F4\uFF0C\u800C\u8FD9\u6761\u5F15\u7528\u624B\u4E0A\u662F**\u6E90\u8868\u91CC\u7684\u503C**\uFF0C\u4E24\u8FB9\u6C38\u4E0D\u76F8\u7B49\u3002\u{1F534} **\u91CD\u8DD1\u4E0D\u4F1A\u53D8**\uFF1A\u76EE\u6807\u884C\u65E9\u5C31\u5BFC\u8FDB\u53BB\u4E86\u4E5F\u4E00\u6837\uFF0C\u522B\u518D\u53BB\u5BFC\u4E00\u904D\u90A3\u4E2A\u6A21\u578B\u3002\u505A\u5F97\u5230\u7684\u662F\u6539\u6570\u636E\u6A21\u578B\uFF08\u7ED9\u90A3\u4E2A\u6A21\u578B\u4E00\u4E2A\u771F\u6B63\u7684\u81EA\u7136\u952E\u5217\uFF0C\u518D\u628A keyField \u6307\u5411\u5B83\uFF09\u6216\u8FD9\u6761\u5F15\u7528\u8D70\u4EBA\u5DE5",
13596
+ "ref-not-found": "\u7D22\u5F15\u5728\u3001\u952E\u4E5F\u5BF9\u5F97\u4E0A\uFF0C\u53EA\u662F\u8FD9\u4E2A\u503C**\u4E0D\u5728\u65E2\u5B58\u7D22\u5F15\u91CC**\u3002\u5148\u628A\u90A3\u4E2A\u6A21\u578B\u7684\u76EE\u6807\u884C\u5BFC\u8FDB\u53BB\uFF08\u6216\u786E\u8BA4\u5B83\u5728\u7CFB\u7EDF\u91CC\u7684\u952E\u5C31\u662F\u8FD9\u4E2A\u5199\u6CD5\uFF09\uFF0C\u518D\u8DD1\u4E00\u6B21 plan\u3002\u26A0\uFE0F \u672C kit \u4E0D\u5EFA\u8DE8\u6A21\u578B\u7684\u6CE2\uFF0C\u6240\u4EE5\u300C\u5B83\u4E5F\u5728\u8FD9\u4E00\u8F6E\u91CC\u7B49\u7740\u88AB\u5EFA\u300D\u540C\u6837\u843D\u8FD9\u4E00\u6863 \u2014\u2014 \u90A3\u5C31\u5148\u5355\u72EC\u8DD1\u4E00\u8F6E\u628A\u90A3\u4E2A\u6A21\u578B\u5BFC\u5B8C"
13597
+ };
13598
+ var REF_STEP_UNKNOWN = "\u8BA1\u5212\u5C42\u51FA\u4E86\u4E00\u6863\u672C\u6267\u884C\u5668**\u4E0D\u8BA4\u8BC6**\u7684 resolveFrom\uFF0C\u6309\u300C\u672A\u77E5\u5373\u62D2\u300D\u505C\u624B\u4E86 \u2014\u2014 \u8FD9\u4E0D\u7B49\u4E8E\u8BF4\u5B83\u6362\u4E0D\u51FA id\uFF0C\u672C\u6267\u884C\u5668\u5224\u4E0D\u4E86\u3002\u53BB\u8BA1\u5212\u5C42\u7684 RESOLVE_FROM \u770B\u5B83\u7684\u8BED\u4E49\uFF1A\u8BE5\u7B97\u300C\u6362\u5F97\u51FA\u300D\u5C31\u628A\u5B83\u52A0\u8FDB RESOLVABLE_REFS\uFF0C\u8BE5\u7B97\u300C\u6362\u4E0D\u51FA\u300D\u5C31\u7ED9\u5B83\u5199\u4E00\u6761 REF_NEXT_STEPS";
13599
+ var DRY_RUN_ID = "<dry-run:\u6267\u884C\u65F6\u624D\u6709 id>";
13600
+ var APPLY_PROBLEM_CODES = [
13601
+ // ── 前置闸(零请求)──
13602
+ "PLAN_NOT_CLEAN",
13603
+ "PLAN_MAPPING_MISMATCH",
13604
+ "PLAN_ROW_KEY_ARITY_MISMATCH",
13605
+ "PLAN_ROW_KEY_INVALID",
13606
+ "ACTION_NOT_EXECUTABLE",
13607
+ "REF_UNRESOLVED",
13608
+ // ── 执行期(逐行)──
13609
+ "CREATE_REJECTED",
13610
+ "BUSINESS_KEY_NOT_ROUND_TRIPPED",
13611
+ "READBACK_FAILED",
13612
+ "CREATE_OUTCOME_UNKNOWN",
13613
+ "PARENT_NOT_WRITTEN",
13614
+ "SAMPLE_VERIFY_FAILED",
13615
+ "ROW_QUARANTINED",
13616
+ "LEASE_HEARTBEAT_FAILED"
13617
+ ];
13618
+ var MAX_LISTED3 = 20;
13619
+ var BUCKETS = [
13620
+ "created",
13621
+ "skipped",
13622
+ "already",
13623
+ "writeFailed",
13624
+ "unverified",
13625
+ "blocked",
13626
+ "quarantined",
13627
+ "notAttempted",
13628
+ "wouldCreate"
13629
+ ];
13630
+ var ApplyPremiseError = class extends Error {
13631
+ reason;
13632
+ detail;
13633
+ hint;
13634
+ constructor(reason, detail, hint = "") {
13635
+ super(`[${reason}] ${detail}${hint ? ` \u2014\u2014 ${hint}` : ""}`);
13636
+ this.name = "ApplyPremiseError";
13637
+ this.reason = reason;
13638
+ this.detail = detail;
13639
+ this.hint = hint;
13640
+ }
13641
+ };
13642
+ var ApplyInvariantError = class extends Error {
13643
+ constructor(message) {
13644
+ super(message);
13645
+ this.name = "ApplyInvariantError";
13646
+ }
13647
+ };
13648
+ function problem4(code, model, message, hint, row = null, key = null, rawError = null) {
13649
+ return { code, model, row, key, message, hint, rawError };
13650
+ }
13651
+ function createPath(model) {
13652
+ return `/api/models/${model}`;
13653
+ }
13654
+ function assertBusinessKeySent(payload, keyFields, key, model, rowNo2) {
13655
+ keyFields.forEach((field, position) => {
13656
+ if (!(field in payload)) {
13657
+ throw new ApplyInvariantError(
13658
+ `${model} \u7B2C ${rowNo2} \u884C\u7684 payload \u91CC\u6CA1\u6709\u4E1A\u52A1\u952E\u5B57\u6BB5 ${JSON.stringify(field)} \u2014\u2014 \u5B9E\u6D4B\uFF1A\u4E0D\u9001\u4E1A\u52A1\u952E\u65F6\u670D\u52A1\u7AEF\u4F1A\u8865\u4E00\u4E2A\u6D41\u6C34\u7801\uFF08OU2026\u2026\uFF09\uFF0C\u4E0B\u4E00\u8F6E\u6309\u539F\u952E\u56DE\u8BFB 0 \u884C \u21D2 \u518D\u5EFA\u4E00\u6761 \u21D2 \u91CD\u590D\u884C\u3002payload \u7684\u952E\uFF1A${JSON.stringify(Object.keys(payload).sort())}`
13659
+ );
13660
+ }
13661
+ const sent = norm(payload[field]);
13662
+ if (sent !== key[position]) {
13663
+ throw new ApplyInvariantError(
13664
+ `${model} \u7B2C ${rowNo2} \u884C\u9001\u51FA\u53BB\u7684 ${field} \u662F ${JSON.stringify(payload[field])}\uFF08\u5F52\u4E00\u540E ${JSON.stringify(sent)}\uFF09\uFF0C\u800C\u8BA1\u5212\u7B97\u51FA\u6765\u7684\u884C\u952E\u662F ${JSON.stringify(key[position])} \u2014\u2014 \u4E24\u8005\u5FC5\u987B\u9010\u5B57\u76F8\u540C\uFF0C\u5426\u5219\u56DE\u8BFB\u6BD4\u5BF9\u65AD\u7684\u5C31\u4E0D\u662F\u8FD9\u4E00\u884C`
13665
+ );
13666
+ }
13667
+ });
13668
+ }
13669
+ function buildPayload(row, createdIds, journal) {
13670
+ const body = Object.fromEntries(row.fields);
13671
+ for (const ref of row.refs) {
13672
+ if (ref.resolveFrom === "no-parent") continue;
13673
+ if (ref.resolvedId) {
13674
+ body[ref.field] = ref.resolvedId;
13675
+ continue;
13676
+ }
13677
+ const target = [norm(ref.value) ?? ""];
13678
+ let found = createdIds.get(createdKey(ref.model, target));
13679
+ if (found === void 0) {
13680
+ const previous = journal.latest(ref.model, target);
13681
+ if (previous !== null && previous.status === "done") found = previous.serverId ?? void 0;
13682
+ }
13683
+ if (!found) return [null, ref];
13684
+ body[ref.field] = found;
13685
+ }
13686
+ return [body, null];
13687
+ }
13688
+ function createdKey(model, key) {
13689
+ return JSON.stringify([model, key]);
13690
+ }
13691
+ var ACTION_HINTS = {
13692
+ update: "\u672C\u6267\u884C\u5668\u8FD9\u4E00\u8F6E**\u4E0D\u5199 update**\uFF08\u6682\u65F6\u4E0D\u505A\uFF0C\u4E0D\u662F\u505A\u4E0D\u5230\uFF09\uFF1A\u5B9E\u6D4B\u53EA\u8DD1\u8FC7 create\uFF0C\u300Cupdate \u8DEF\u5F84\u80FD\u5426\u6539 auto-generated \u7684 code\u300D\u6CA1\u6709\u5B9E\u6D4B\u80CC\u4E66\uFF0C\u800C\u627F\u91CD\u89C4\u5219 2 \u7684\u56DE\u8BFB\u6BD4\u5BF9\u6B63\u662F\u9760\u5B83\u3002\u8981\u4E48\u628A onExisting \u6539\u6210 skip \u53EA\u8865\u589E\u91CF\uFF0C\u8981\u4E48\u8FD9\u51E0\u884C\u8D70\u4EBA\u5DE5",
13693
+ fail: '\u5DE5\u4EF6\u5199\u7684\u662F onExisting: "fail" \u2014\u2014 \u547D\u4E2D\u65E2\u5B58\u65F6**\u672C\u610F\u5C31\u662F\u505C**\u3002\u5148\u786E\u8BA4\u8FD9\u4E9B\u884C\u5230\u5E95\u8BE5\u8DF3\u8FC7\u8FD8\u662F\u8BE5\u66F4\u65B0\uFF0C\u518D\u6539\u5DE5\u4EF6',
13694
+ unknown: "\u8BA1\u5212\u5C42\u6CA1\u6709\u67E5\u8FC7\u65E2\u5B58\uFF08\u7F3A\u7D22\u5F15\uFF09\uFF0C\u6240\u4EE5\u8BF4\u4E0D\u51FA\u8FD9\u51E0\u884C\u662F\u5EFA\u8FD8\u662F\u5BF9\u65E2\u5B58\u3002\u8FD9\u65F6\u5019\u5EFA = \u300C\u7D22\u5F15\u4E3A\u7A7A\u88AB\u8BFB\u6210\u5168\u662F\u65B0\u884C\u300D\u90A3\u4E2A\u6D1E\uFF0C\u4F1A\u9759\u9ED8\u9020\u51FA\u5168\u91CF\u91CD\u590D\u3002\u5148\u8BA9\u65E2\u5B58\u7D22\u5F15\u53D6\u6570\u6210\u529F"
13695
+ };
13696
+ function listed2(items, total) {
13697
+ return `${items.slice(0, MAX_LISTED3).join("\uFF1B")}${total > MAX_LISTED3 ? `\u2026\uFF08\u5171 ${total} \u6761\uFF09` : ""}`;
13698
+ }
13699
+ function preflight(plan, mapping) {
13700
+ const out = [];
13701
+ if (plan.problems.length > 0) {
13702
+ const codes = [...new Set(plan.problems.map((p) => p.code))].sort();
13703
+ out.push(
13704
+ problem4(
13705
+ "PLAN_NOT_CLEAN",
13706
+ "*",
13707
+ `\u8BA1\u5212\u91CC\u6709 ${plan.problems.length} \u6761\u95EE\u9898\uFF08${codes.join("\u3001")}\uFF09\uFF0C**\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u4F1A\u53D1**`,
13708
+ "\u8BA1\u5212\u5C42\u7684 problem \u5168\u90FD\u662F\u786C\u5931\u8D25\uFF0C\u6CA1\u6709\u300C\u5EFA\u8BAE\u300D\u6863\u3002\u9010\u6761\u6309\u5B83\u7684 hint \u4FEE\u5DE5\u4EF6/\u6E90\u8868\uFF0C\u91CD\u65B0\u8DD1\u4E00\u6B21 plan\uFF0C\u7EFF\u4E86\u518D apply"
13709
+ )
13710
+ );
13711
+ }
13712
+ const plannedModels = plan.models.map((m) => m.model);
13713
+ const artifactModels = mapping.models.map((m) => m.model);
13714
+ if (JSON.stringify(plannedModels) !== JSON.stringify(artifactModels)) {
13715
+ out.push(
13716
+ problem4(
13717
+ "PLAN_MAPPING_MISMATCH",
13718
+ "*",
13719
+ `\u8BA1\u5212\u91CC\u7684\u6A21\u578B\u662F ${JSON.stringify(plannedModels)}\uFF0C\u5DE5\u4EF6\u91CC\u7684\u662F ${JSON.stringify(artifactModels)} \u2014\u2014 \u4E24\u4EFD\u5BF9\u4E0D\u4E0A`,
13720
+ "\u8BA1\u5212\u662F\u843D\u76D8\u4EA7\u7269\uFF08import-plan.json\uFF09\uFF0C\u5DE5\u4EF6\u4E5F\u662F\u3002\u5DE5\u4EF6\u6539\u8FC7\u4E4B\u540E\u5FC5\u987B\u91CD\u65B0\u8DD1 plan\uFF1A\u62FF\u65E7\u8BA1\u5212\u914D\u65B0\u5DE5\u4EF6\u5199\u51FA\u53BB\u7684\u662F**\u4E0A\u4E00\u7248\u7684\u53E3\u5F84**\uFF0C\u800C\u8FD9\u4EF6\u4E8B\u5728\u4EA7\u7269\u91CC\u770B\u4E0D\u51FA\u6765"
13721
+ )
13722
+ );
13723
+ } else {
13724
+ plan.models.forEach((modelPlan, i) => {
13725
+ const declared = mapping.models[i].businessKey?.fields ?? [];
13726
+ if (JSON.stringify(modelPlan.businessKeyFields) !== JSON.stringify([...declared])) {
13727
+ out.push(
13728
+ problem4(
13729
+ "PLAN_MAPPING_MISMATCH",
13730
+ modelPlan.model,
13731
+ `${modelPlan.model} \u7684\u4E1A\u52A1\u952E\uFF1A\u8BA1\u5212\u91CC\u662F ${JSON.stringify(modelPlan.businessKeyFields)}\uFF0C\u5DE5\u4EF6\u91CC\u662F ${JSON.stringify([...declared])}`,
13732
+ "\u4E1A\u52A1\u952E\u662F\u5E42\u7B49\u7684\u652F\u70B9\u3002\u4E24\u4EFD\u4E0D\u4E00\u81F4\u65F6\uFF0C\u56DE\u8BFB\u6BD4\u5BF9\u65AD\u7684\u662F\u4E00\u4E2A\u952E\u3001\u5199\u8FDB\u53BB\u7684\u662F\u53E6\u4E00\u4E2A\u952E \u2014\u2014 \u91CD\u65B0\u8DD1\u4E00\u6B21 plan"
13733
+ )
13734
+ );
13735
+ }
13736
+ });
13737
+ }
13738
+ for (const modelPlan of plan.models) {
13739
+ if (!modelPlan.planned || modelPlan.waves === null) continue;
13740
+ out.push(...modelGates(modelPlan));
13741
+ }
13742
+ return out;
13743
+ }
13744
+ function modelGates(modelPlan) {
13745
+ const out = [];
13746
+ const badActions = /* @__PURE__ */ new Map();
13747
+ const unresolved = [];
13748
+ const badArity = [];
13749
+ const badKeys = [];
13750
+ const arity = modelPlan.businessKeyFields.length;
13751
+ for (const wave of modelPlan.waves) {
13752
+ for (const row of wave.rows) {
13753
+ const rawKey = row.key;
13754
+ try {
13755
+ businessKeyOf(rawKey);
13756
+ } catch (e) {
13757
+ if (!(e instanceof JournalError)) throw e;
13758
+ badKeys.push([row.row, rawKey, e]);
13759
+ }
13760
+ const actual = Array.isArray(rawKey) ? rawKey.length : null;
13761
+ if (actual !== arity) badArity.push([row.row, rawKey, actual]);
13762
+ if (!EXECUTABLE_ACTIONS.includes(row.action)) {
13763
+ const at = badActions.get(row.action);
13764
+ if (at === void 0) badActions.set(row.action, [row.row]);
13765
+ else at.push(row.row);
13766
+ }
13767
+ for (const ref of row.refs) {
13768
+ if (!RESOLVABLE_REFS.includes(ref.resolveFrom)) {
13769
+ unresolved.push([row.row, ref]);
13770
+ }
13771
+ }
13772
+ }
13773
+ }
13774
+ if (badKeys.length > 0) {
13775
+ out.push(
13776
+ problem4(
13777
+ "PLAN_ROW_KEY_INVALID",
13778
+ modelPlan.model,
13779
+ `${modelPlan.model} \u6709 ${badKeys.length} \u884C\u7684 key \u4E0D\u662F\u4E00\u7EC4\u975E\u7A7A\u5B57\u7B26\u4E32\uFF1A` + listed2(
13780
+ badKeys.map(([n, k, e]) => `\u7B2C ${n} \u884C\uFF08${JSON.stringify(k)}\uFF09\uFF1A[${e.reason}] ${e.detail}`),
13781
+ badKeys.length
13782
+ ),
13783
+ "\u{1F534} \u8FD9\u662F**\u8FD9\u4EFD `import-plan.json` \u81EA\u5DF1**\u524D\u540E\u5BF9\u4E0D\u4E0A\uFF0C\u4E0D\u662F\u6E90\u8868\u5185\u5BB9\u7684\u95EE\u9898\u3002\u8BA1\u5212\u5C42\u7B97\u51FA\u6765\u7684\u884C\u952E\u9010\u5B57\u6BB5\u90FD\u662F\u5B57\u7B26\u4E32\uFF0C\u8FD9\u4EFD\u8BA1\u5212**\u88AB\u4EC0\u4E48\u52A8\u8FC7\u3001\u8FD8\u662F\u522B\u7684\u4E1C\u897F\u5199\u7684**\uFF0C\u672C\u6A21\u5757\u6CA1\u6709\u67E5\u8FC7\u3002\u26A0\uFE0F \u522B\u53BB\u6539 `key` \u51D1\u4E00\u4E2A\u5B57\u7B26\u4E32\u4E0A\u53BB\uFF1A\u51D1\u51FA\u6765\u7684\u90A3\u4E00\u683C\u6CA1\u6709\u6E90\u8868\u503C\u515C\u7740\u3002\u5728\u8FD9\u4E2A work \u76EE\u5F55\u4E0A\u91CD\u65B0\u8DD1\u4E00\u6B21 `plan`\u3002\u{1F534} **\u4E3A\u4EC0\u4E48\u5FC5\u987B\u6574\u8F6E\u505C**\uFF1A\u53F0\u8D26\u662F\u5199\u5230\u78C1\u76D8\u518D\u8BFB\u56DE\u6765\u7684\uFF0C\u975E\u5B57\u7B26\u4E32\u7684\u952E\u5728 JSON \u5F80\u8FD4\u4E4B\u540E\u4E0E\u8BA1\u5212\u90A3\u8FB9\u7684\u5B57\u7B26\u4E32\u952E\u914D\u4E0D\u4E0A\uFF0C\u8868\u73B0\u662F\u8FD9\u4E00\u884C\u88AB\u5F53\u6210\u300C\u4ECE\u6CA1\u8BB0\u8FC7\u300D\u800C\u91CD\u653E \u2014\u2014 \u4E5F\u5C31\u662F\u91CD\u590D\u884C\u3002"
13784
+ )
13785
+ );
13786
+ }
13787
+ if (badArity.length > 0) {
13788
+ out.push(
13789
+ problem4(
13790
+ "PLAN_ROW_KEY_ARITY_MISMATCH",
13791
+ modelPlan.model,
13792
+ `${modelPlan.model} \u58F0\u660E\u7684\u4E1A\u52A1\u952E\u5B57\u6BB5\u6709 ${arity} \u4E2A\uFF08${JSON.stringify(modelPlan.businessKeyFields)}\uFF09\uFF0C\u800C\u6709 ${badArity.length} \u884C\u7684 key \u4E0D\u662F\u8FD9\u4E2A\u4E2A\u6570\uFF1A` + listed2(
13793
+ badArity.map(
13794
+ ([n, k, actual]) => actual !== null ? `\u7B2C ${n} \u884C\u6709 ${actual} \u4E2A\uFF08${JSON.stringify(k)}\uFF09` : `\u7B2C ${n} \u884C\u7684 key \u6839\u672C\u4E0D\u662F\u4E00\u7EC4\uFF08${JSON.stringify(k)}\uFF09`
13795
+ ),
13796
+ badArity.length
13797
+ ),
13798
+ "\u{1F534} \u8FD9\u662F**\u8FD9\u4EFD `import-plan.json` \u81EA\u5DF1\u524D\u540E\u5BF9\u4E0D\u4E0A**\uFF0C\u4E0D\u662F\u6E90\u8868\u5185\u5BB9\u7684\u95EE\u9898 \u2014\u2014 \u540C\u4E00\u4EFD\u6587\u4EF6\u91CC\u4E24\u5904\u4E92\u76F8\u77DB\u76FE\uFF0C\u5FC5\u6709\u4E00\u5904\u662F\u5047\u7684\u3002\u8BA1\u5212\u5C42\u7B97\u51FA\u6765\u7684\u884C\u952E\u6052\u6309 businessKey.fields \u9010\u5B57\u6BB5\u53D6 \u21D2 \u4E24\u8005\u6052\u7B49\u957F\uFF1B\u8FD9\u4EFD\u8BA1\u5212**\u88AB\u4EC0\u4E48\u52A8\u8FC7\u3001\u8FD8\u662F\u522B\u7684\u4E1C\u897F\u5199\u7684**\uFF0C\u672C\u6A21\u5757\u6CA1\u6709\u67E5\u8FC7\u3002\u26A0\uFE0F \u522B\u53BB\u6539 `key` \u51D1\u4E2A\u6570\uFF1A\u51D1\u51FA\u6765\u7684\u90A3\u4E00\u683C\u6CA1\u6709\u6E90\u8868\u503C\u515C\u7740\u3002\u5728\u8FD9\u4E2A work \u76EE\u5F55\u4E0A\u91CD\u65B0\u8DD1\u4E00\u6B21 `plan`\u3002\u{1F534} **\u4E3A\u4EC0\u4E48\u6574\u8F6E\u505C**\uFF1A\u56DE\u8BFB\u6309 businessKeyFields \u4E0E\u884C\u952E**\u9010\u4F4D\u914D\u5BF9**\u62FC filter\uFF0C\u4E2A\u6570\u5BF9\u4E0D\u4E0A\u65F6\u62FC\u51FA\u6765\u7684 filter \u5C11\u4E00\u4E2A\u6761\u4EF6\uFF0C\u800C\u5C11\u4E00\u4E2A\u6761\u4EF6\u7684\u56DE\u8BFB\u4F1A\u5339\u914D\u5230**\u522B\u7684\u884C** \u2014\u2014 \u987A\u7740\u5B83\u5224\u300C\u5DF2\u7ECF\u5EFA\u8FC7\u4E86\u300D\u5C31\u662F\u6F0F\u5EFA\uFF0C\u5224\u300C\u6CA1\u5EFA\u6210\u300D\u5C31\u662F\u91CD\u5EFA"
13799
+ )
13800
+ );
13801
+ }
13802
+ for (const [action3, rows] of [...badActions.entries()].sort()) {
13803
+ out.push(
13804
+ problem4(
13805
+ "ACTION_NOT_EXECUTABLE",
13806
+ modelPlan.model,
13807
+ `${modelPlan.model} \u6709 ${rows.length} \u884C\u7684\u52A8\u4F5C\u662F ${JSON.stringify(action3)}\uFF0C\u672C\u6267\u884C\u5668\u6267\u884C\u4E0D\u4E86\uFF08\u80FD\u6267\u884C\u7684\u662F ${JSON.stringify([...EXECUTABLE_ACTIONS])}\uFF09\uFF1A\u7B2C ${rows.slice(0, MAX_LISTED3).join("\u3001")} \u884C${rows.length > MAX_LISTED3 ? `\u2026\uFF08\u5171 ${rows.length} \u884C\uFF09` : ""}`,
13808
+ ACTION_HINTS[action3] ?? "\u5148\u786E\u8BA4\u8FD9\u4E2A\u52A8\u4F5C\u8BE5\u7531\u8C01\u6765\u505A"
13809
+ )
13810
+ );
13811
+ }
13812
+ if (unresolved.length > 0) out.push(refProblem(modelPlan.model, unresolved));
13813
+ return out;
13814
+ }
13815
+ function refProblem(model, unresolved) {
13816
+ const detail = listed2(
13817
+ unresolved.map(
13818
+ ([n, ref]) => `\u7B2C ${n} \u884C\u7684 ${ref.field} \u8981\u62FF ${ref.model}.${ref.keyField} \u6362 id\uFF08${ref.resolveFrom}\uFF09`
13819
+ ),
13820
+ unresolved.length
13821
+ );
13822
+ const archetypes = [...new Set(unresolved.map(([, ref]) => ref.resolveFrom))].sort();
13823
+ const unknown = archetypes.filter((a) => !UNRESOLVABLE_REFS.includes(a));
13824
+ const headline = unknown.length > 0 ? `${model} \u6709 ${unresolved.length} \u6761\u5F15\u7528**\u8FD9\u4E00\u8F6E\u4E0D\u53D1**\uFF08\u5176\u4E2D ${unknown.join("\u3001")} \u8FD9 ${unknown.length} \u6863\u672C\u6267\u884C\u5668\u4E0D\u8BA4\u8BC6\uFF09\uFF1A${detail}` : `${model} \u6709 ${unresolved.length} \u6761\u5F15\u7528\u6362\u4E0D\u51FA id\uFF1A${detail}`;
13825
+ const preface = unknown.length > 0 ? "**\u672A\u77E5\u6863\u6309\u300C\u672A\u77E5\u5373\u62D2\u300D\u505C\u624B**\uFF0C\u672C\u6267\u884C\u5668\u8BF4\u4E0D\u51FA\u5B83\u4EEC\u6362\u4E0D\u6362\u5F97\u51FA id\u3002\u9010\u6863\u7684\u4E0B\u4E00\u6B65\uFF1A" : "\u6362\u4E0D\u51FA id \u5C31\u628A\u4E00\u4E2A**\u4E1A\u52A1\u952E\u5B57\u7B26\u4E32**\u5F53 id \u9001\u51FA\u53BB\u4E86 \u2014\u2014 \u597D\u7684\u60C5\u51B5\u662F 400\uFF0C\u574F\u7684\u60C5\u51B5\u662F\u5B83\u88AB\u5199\u8FDB\u4E00\u4E2A text \u5217\uFF0C\u770B\u7740\u50CF\u6210\u529F\u3002\u9010\u6863\u7684\u4E0B\u4E00\u6B65\uFF1A";
13826
+ return problem4(
13827
+ "REF_UNRESOLVED",
13828
+ model,
13829
+ headline,
13830
+ preface + archetypes.map((a) => `\u3010${a}\u3011${REF_NEXT_STEPS[a] ?? REF_STEP_UNKNOWN}`).join("\uFF1B")
13831
+ );
13832
+ }
13833
+ var TALLY_FIELDS = [...BUCKETS, "requests", "readbacks"];
13834
+ var Tally = class {
13835
+ counts = /* @__PURE__ */ new Map();
13836
+ constructor() {
13837
+ for (const name of TALLY_FIELDS) this.counts.set(name, 0);
13838
+ }
13839
+ get(name) {
13840
+ return this.counts.get(name);
13841
+ }
13842
+ add(name, count = 1) {
13843
+ this.counts.set(name, this.get(name) + count);
13844
+ }
13845
+ };
13846
+ function reportOf(plan, dryRun, sample, executed, aborted, models, totals, problems) {
13847
+ return {
13848
+ version: VERSION4,
13849
+ roundId: plan.roundId,
13850
+ dryRun,
13851
+ sample,
13852
+ executed,
13853
+ aborted,
13854
+ models: [...models],
13855
+ created: totals.get("created"),
13856
+ skipped: totals.get("skipped"),
13857
+ already: totals.get("already"),
13858
+ writeFailed: totals.get("writeFailed"),
13859
+ unverified: totals.get("unverified"),
13860
+ blocked: totals.get("blocked"),
13861
+ quarantined: totals.get("quarantined"),
13862
+ notAttempted: totals.get("notAttempted"),
13863
+ wouldCreate: totals.get("wouldCreate"),
13864
+ requests: totals.get("requests"),
13865
+ readbacks: totals.get("readbacks"),
13866
+ problems: [...problems]
13867
+ };
13868
+ }
13869
+ function errorEnvelope(body) {
13870
+ if (body !== null && typeof body === "object" && !Array.isArray(body)) {
13871
+ const err = body["error"];
13872
+ if (err !== null && typeof err === "object" && !Array.isArray(err)) return err;
13873
+ }
13874
+ return body;
13875
+ }
13876
+ function priorEntry(journal, model, key) {
13877
+ const previous = journal.latest(model, key);
13878
+ if (previous === null) {
13879
+ throw new ApplyInvariantError(
13880
+ `${model} ${JSON.stringify([...key])} \u5728\u53F0\u8D26\u91CC\u6CA1\u6709\u524D\u7F6E\u8BB0\u5F55\uFF0C\u800C\u8FD9\u91CC\u6B63\u8981\u6539\u5199\u5B83\u7684\u7EC8\u6001 \u2014\u2014 \u5199\u524D\u843D\u8D26\u534F\u8BAE\u8981\u6C42\u300C\u5148\u843D unknown \u518D\u843D\u7EC8\u6001\u300D\uFF0C\u8D70\u5230\u8FD9\u91CC\u5374\u6CA1\u6709\u90A3\u6761\u8BB0\u5F55\uFF0C\u8BF4\u660E\u672C\u6A21\u5757\u81EA\u5DF1\u7684\u987A\u5E8F\u88AB\u7834\u574F\u4E86`
13881
+ );
13882
+ }
13883
+ return previous;
13884
+ }
13885
+ function stampProgress(onRequestSpent, model, row, problems) {
13886
+ try {
13887
+ onRequestSpent();
13888
+ } catch (raw) {
13889
+ if (!(raw instanceof LeaseViolation)) throw raw;
13890
+ const e = raw;
13891
+ problems.push(
13892
+ problem4(
13893
+ "LEASE_HEARTBEAT_FAILED",
13894
+ model,
13895
+ `\u5904\u7406\u7B2C ${row.row} \u884C\uFF08\u5DF2\u7ECF\u53D1\u51FA\u8FC7\u8BF7\u6C42\uFF09\u4E4B\u540E\u76D6\u5FC3\u8DF3\u65F6\u79DF\u7EA6\u51FA\u4E86\u95EE\u9898\uFF1A[${e.reason}] ${e.message}`,
13896
+ e.hint || "",
13897
+ row.row,
13898
+ row.key
13899
+ )
13900
+ );
13901
+ return "lease-heartbeat-failed";
13902
+ }
13903
+ return null;
13904
+ }
13905
+ function quarantineRow(plan, model, row, journal, tally, problems, serverId, stored, evidence, how) {
13906
+ tally.add("writeFailed");
13907
+ journal.append({
13908
+ ...priorEntry(journal, model, row.key),
13909
+ status: "quarantined",
13910
+ serverId,
13911
+ roundId: plan.roundId,
13912
+ error: {
13913
+ fdeKit: {
13914
+ reason: "business-key-not-round-tripped",
13915
+ sentKey: [...row.key],
13916
+ storedKey: stored === null ? null : [...stored],
13917
+ how
13918
+ },
13919
+ response: evidence
13920
+ }
13921
+ });
13922
+ problems.push(
13923
+ problem4(
13924
+ "BUSINESS_KEY_NOT_ROUND_TRIPPED",
13925
+ model,
13926
+ `\u7B2C ${row.row} \u884C\u7684**\u4E1A\u52A1\u952E\u672A\u539F\u6837\u5B58\u4E0B**\uFF1A\u9001\u51FA\u53BB\u7684\u662F ${JSON.stringify([...row.key])}\uFF0C${how}` + (stored !== null ? `\uFF1B\u670D\u52A1\u7AEF\u5B58\u4E0B\u6765\u7684\u952E\u662F ${JSON.stringify([...stored])}` : ""),
13927
+ "\u5B9E\u6D4B `OrgUnit` / `Position` \u7684 `code` \u5143\u6570\u636E\u6807 auto-generated\uFF0C\u4E0D\u9001\u5C31\u88AB\u6362\u6210 OU2026\u2026 \u7684\u6D41\u6C34\u7801\uFF1B\u672C\u5DE5\u5177\u662F**\u9001**\u4E86\u7684\uFF0C\u6240\u4EE5\u8D70\u5230\u8FD9\u91CC\u8BF4\u660E\u670D\u52A1\u7AEF\u4ECD\u7136\u6362\u6389\u4E86\u5B83\u3002" + (serverId ? `\u{1F534} \u670D\u52A1\u7AEF\u90A3\u8FB9\u6709\u4E00\u884C id=${serverId}\uFF0C\u5B83**\u4E0D\u5728**\u4F60\u7684\u4E1A\u52A1\u952E\u4E0B \u2014\u2014 \u5148\u4EBA\u5DE5\u786E\u8BA4/\u5904\u7406\u90A3\u4E00\u884C\u3002` : "\u{1F534} \u670D\u52A1\u7AEF\u5EFA\u4E86\u4EC0\u4E48\u3001id \u662F\u591A\u5C11\uFF0C\u8FD9\u6B21\u54CD\u5E94\u91CC\u6CA1\u7ED9 \u2014\u2014 \u53EA\u80FD\u53BB\u7CFB\u7EDF\u91CC\u627E\u3002") + "\u53F0\u8D26\u91CC\u8FD9\u4E00\u884C\u8BB0\u6210 **quarantined**\uFF1A\u672C\u5DE5\u5177**\u4E0D\u4F1A**\u81EA\u52A8\u91CD\u653E\u5B83\uFF08\u91CD\u653E\u4F1A\u518D\u9020\u4E00\u6761\u67E5\u4E0D\u56DE\u6765\u7684\u91CE\u884C\uFF09\u3002\u672C\u8F6E\u5230\u6B64\u4E2D\u6B62",
13928
+ row.row,
13929
+ row.key
13930
+ )
13931
+ );
13932
+ return [true, "business-key-not-round-tripped"];
13933
+ }
13934
+ function rejectedRow(plan, model, row, journal, tally, problems, out) {
13935
+ tally.add("writeFailed");
13936
+ journal.append({
13937
+ ...priorEntry(journal, model, row.key),
13938
+ status: "failed",
13939
+ roundId: plan.roundId,
13940
+ error: { httpStatus: out.status, clientError: out.error, response: out.body }
13941
+ });
13942
+ problems.push(
13943
+ problem4(
13944
+ "CREATE_REJECTED",
13945
+ model,
13946
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09\u88AB\u4EA7\u54C1\u62D2\u7EDD\uFF08HTTP ${out.status} / ${out.error}\uFF09 \u2014\u2014 \u539F\u59CB error \u4FE1\u5C01\u5DF2\u539F\u6837\u843D\u53F0\u8D26`,
13947
+ "\u{1F534} **\u672C\u5DE5\u5177\u4E0D\u89E3\u8BFB\u8FD9\u4E2A\u9519\u8BEF**\uFF1A\u5B9E\u6D4B\u4EA7\u54C1\u7528\u56DB\u79CD\u5F62\u6001\u4E0A\u62A5\u540C\u4E00\u7C7B\u4E8B\u4EF6\uFF0Cerror.code \u8DE8\u6A21\u578B\u7CCA\u6210\u540C\u4E00\u4E2A\u503C\u800C details \u91CC\u7684\u65B9\u62EC\u53F7 token \u8DE8\u6A21\u578B\u4E0D\u4E00\u81F4 \u2014\u2014 \u4E24\u5904\u90FD\u4E0D\u53EF\u673A\u8BFB\uFF0C\u8BFB\u51FA\u6765\u7684\u4EFB\u4F55\u7ED3\u8BBA\u90FD\u662F\u7F16\u7684\u3002\u82E5\u5B83\u8BF4\u7684\u662F\u300C\u5DF2\u5B58\u5728\u300D\uFF0C\u90A3\u610F\u5473\u7740**\u8DD1\u524D\u62CD\u7684\u65E2\u5B58\u7D22\u5F15\u4E0E\u73B0\u5B9E\u4E0D\u4E00\u81F4**\uFF08\u5FEB\u7167\u8FC7\u671F\uFF0C\u6216\u6709\u522B\u7684\u5199\u5165\u8005\uFF09\uFF1A\u91CD\u65B0\u8DD1\u4E00\u6B21 plan \u518D apply",
13948
+ row.row,
13949
+ row.key,
13950
+ errorEnvelope(out.body)
13951
+ )
13952
+ );
13953
+ return [true, null];
13954
+ }
13955
+ async function acceptRow(client, plan, model, row, journal, createdIds, tally, problems, serverId, keyFields, sample, verifiedAlready = false) {
13956
+ if (sample !== null && !verifiedAlready) {
13957
+ let verified;
13958
+ try {
13959
+ verified = await resolveUnknown(client, model, keyFields, row.key);
13960
+ } catch (raw) {
13961
+ if (!(raw instanceof JournalError)) throw raw;
13962
+ tally.add("readbacks");
13963
+ tally.add("unverified");
13964
+ problems.push(
13965
+ problem4(
13966
+ "SAMPLE_VERIFY_FAILED",
13967
+ model,
13968
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09create \u56DE\u4E86 id=${serverId}\uFF0C\u4F46\u5C0F\u6837\u672C\u590D\u9A8C\u56DE\u8BFB**\u95EE\u4E0D\u51FA\u6765**\uFF1A[${raw.reason}] ${raw.message}`,
13969
+ `${raw.hint || ""} \u{1F534} \u53F0\u8D26\u91CC\u8FD9\u4E00\u884C**\u505C\u5728 unknown**\uFF08\u6CA1\u6709\u843D done\uFF09\uFF1A\u5C0F\u6837\u672C\u7684\u610F\u4E49\u5C31\u662F\u300C\u5148\u8BC1\u4E00\u904D\u518D\u5168\u91CF\u300D\uFF0C\u8FD9\u4E00\u6B65\u6CA1\u8BC1\u6210\u5C31\u4E0D\u8BB8\u5199\u300C\u786E\u8BA4\u5EFA\u6210\u4E86\u300D`,
13970
+ row.row,
13971
+ row.key
13972
+ )
13973
+ );
13974
+ return [true, "sample-verify-failed"];
13975
+ }
13976
+ tally.add("readbacks");
13977
+ if (verified.status !== "done" || verified.serverId !== serverId) {
13978
+ return quarantineRow(
13979
+ plan,
13980
+ model,
13981
+ row,
13982
+ journal,
13983
+ tally,
13984
+ problems,
13985
+ serverId,
13986
+ null,
13987
+ null,
13988
+ `create \u56DE\u4E86 id=${serverId}\uFF0C\u800C\u5C0F\u6837\u672C\u590D\u9A8C\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB\u5F97\u5230\u7684\u662F ${verified.status}\uFF08id=${verified.serverId}\uFF09`
13989
+ );
13990
+ }
13991
+ }
13992
+ journal.append({
13993
+ ...priorEntry(journal, model, row.key),
13994
+ status: "done",
13995
+ serverId,
13996
+ roundId: plan.roundId
13997
+ });
13998
+ createdIds.set(createdKey(model, row.key), serverId);
13999
+ tally.add("created");
14000
+ return [true, null];
14001
+ }
14002
+ async function judgeCreate(client, out, plan, modelPlan, row, journal, createdIds, tally, problems, sample) {
14003
+ const model = modelPlan.model;
14004
+ const keyFields = [...modelPlan.businessKeyFields];
14005
+ if (out.error !== "ok") {
14006
+ if (out.status >= 400 && out.status < 500) {
14007
+ return rejectedRow(plan, model, row, journal, tally, problems, out);
14008
+ }
14009
+ tally.add("unverified");
14010
+ problems.push(
14011
+ problem4(
14012
+ "CREATE_OUTCOME_UNKNOWN",
14013
+ model,
14014
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09\u53D1\u51FA\u53BB\u4E86\uFF0C\u4F46**\u4E0D\u77E5\u9053\u670D\u52A1\u7AEF\u8BA4\u6CA1\u8BA4**\uFF08HTTP ${out.status} / ${out.error}\uFF09`,
14015
+ "\u8FD9\u6B63\u662F unknown \u90A3\u4E00\u6863\u7684\u5178\u578B\u6210\u56E0\uFF08\u670D\u52A1\u7AEF\u53EF\u80FD\u5DF2\u7ECF\u5EFA\u6210\u3001\u54CD\u5E94\u5728\u56DE\u7A0B\u4E22\u4E86\uFF09\u3002\u53F0\u8D26\u91CC\u8FD9\u4E00\u884C\u505C\u5728 unknown\uFF0C**\u4E0B\u4E00\u8F6E\u4F1A\u5148\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB**\u518D\u51B3\u5B9A \u2014\u2014 \u522B\u624B\u5DE5\u628A\u5B83\u6539\u6210 failed\uFF0C\u90A3\u7B49\u4E8E\u6388\u6743\u4E00\u6B21\u76F2\u91CD\u53D1\u3002\u5148\u6309 error \u90A3\u4E00\u7EF4\u5904\u7F6E\uFF08network=\u901A\u9053 / server-error=\u770B\u670D\u52A1\u7AEF\uFF09",
14016
+ row.row,
14017
+ row.key
14018
+ )
14019
+ );
14020
+ return [true, "create-outcome-unknown"];
14021
+ }
14022
+ const body = out.body !== null && typeof out.body === "object" && !Array.isArray(out.body) ? out.body : {};
14023
+ const id = body["id"];
14024
+ const serverId = typeof id === "string" && id ? id : null;
14025
+ const echoed = keyFields.filter((f) => f in body).map((f) => norm(body[f]));
14026
+ if (echoed.length === keyFields.length && JSON.stringify(echoed) === JSON.stringify([...row.key]) && serverId) {
14027
+ return acceptRow(
14028
+ client,
14029
+ plan,
14030
+ model,
14031
+ row,
14032
+ journal,
14033
+ createdIds,
14034
+ tally,
14035
+ problems,
14036
+ serverId,
14037
+ keyFields,
14038
+ sample
14039
+ );
14040
+ }
14041
+ let result;
14042
+ try {
14043
+ result = await resolveUnknown(client, model, keyFields, row.key);
14044
+ } catch (raw) {
14045
+ if (!(raw instanceof JournalError)) throw raw;
14046
+ tally.add("readbacks");
14047
+ tally.add("unverified");
14048
+ problems.push(
14049
+ problem4(
14050
+ "READBACK_FAILED",
14051
+ model,
14052
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09create \u56DE\u4E86 HTTP ${out.status}\uFF0C\u4F46\u56DE\u663E\u5BF9\u4E0D\u4E0A\u4E1A\u52A1\u952E\uFF08\u6216\u6CA1\u6709\u53EF\u7528 id\uFF09\uFF0C\u9000\u56DE\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB\u53C8**\u95EE\u4E0D\u51FA\u6765**\uFF1A[${raw.reason}] ${raw.message}`,
14053
+ raw.hint || "\u53F0\u8D26\u91CC\u8FD9\u4E00\u884C\u505C\u5728 unknown\uFF08\u4E0D\u77E5\u9053\uFF09\uFF0C\u4E0B\u4E00\u8F6E\u8FD8\u4F1A\u5148\u56DE\u8BFB\u3002**\u4E0D\u8BB8**\u5F53\u6210\u300C\u6CA1\u5EFA\u6210\u300D\u53BB\u91CD\u5EFA",
14054
+ row.row,
14055
+ row.key
14056
+ )
14057
+ );
14058
+ return [true, "readback-failed"];
14059
+ }
14060
+ tally.add("readbacks");
14061
+ if (result.status === "done" && result.serverId) {
14062
+ return acceptRow(
14063
+ client,
14064
+ plan,
14065
+ model,
14066
+ row,
14067
+ journal,
14068
+ createdIds,
14069
+ tally,
14070
+ problems,
14071
+ result.serverId,
14072
+ keyFields,
14073
+ sample,
14074
+ true
14075
+ );
14076
+ }
14077
+ return quarantineRow(
14078
+ plan,
14079
+ model,
14080
+ row,
14081
+ journal,
14082
+ tally,
14083
+ problems,
14084
+ serverId,
14085
+ echoed.length === keyFields.length ? echoed : null,
14086
+ out.body,
14087
+ `create \u56DE\u4E86 HTTP ${out.status}\uFF0C\u518D\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB**0 \u884C**`
14088
+ );
14089
+ }
14090
+ async function applyRow(client, plan, modelPlan, row, journal, createdIds, tally, problems, dryRun, budgetLeft, sample) {
14091
+ const model = modelPlan.model;
14092
+ const keyFields = [...modelPlan.businessKeyFields];
14093
+ if (row.action === "skip") {
14094
+ tally.add("skipped");
14095
+ if (!dryRun && journal.statusOf(model, row.key) === null) {
14096
+ journal.append({
14097
+ sourceRowId: row.row,
14098
+ model,
14099
+ businessKey: row.key,
14100
+ payloadHash: null,
14101
+ serverId: row.existingId,
14102
+ status: "skipped",
14103
+ attempts: 0,
14104
+ roundId: plan.roundId
14105
+ });
14106
+ }
14107
+ if (row.existingId) createdIds.set(createdKey(model, row.key), row.existingId);
14108
+ return [false, null];
14109
+ }
14110
+ const step = journal.nextStep(model, row.key);
14111
+ if (step === STEP_STOP) {
14112
+ tally.add("quarantined");
14113
+ const previous = journal.latest(model, row.key);
14114
+ problems.push(
14115
+ problem4(
14116
+ "ROW_QUARANTINED",
14117
+ model,
14118
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09\u5728\u53F0\u8D26\u91CC\u662F quarantined \u2014\u2014 \u4E0A\u4E00\u8F6E\u670D\u52A1\u7AEF**\u63A5\u53D7**\u8FC7\u4E00\u6B21\u5199\uFF0C\u800C\u8FD9\u4E2A\u4E1A\u52A1\u952E**\u67E5\u4E0D\u56DE\u6765**` + (previous !== null && previous.serverId ? `\uFF08\u90A3\u6B21\u5199\u843D\u5728 id=${previous.serverId}\uFF09` : ""),
14119
+ "\u672C\u5DE5\u5177**\u4E0D\u4F1A**\u81EA\u52A8\u91CD\u653E\u5B83\uFF1A\u91CD\u653E\u4F1A\u518D\u9020\u4E00\u6761\u6309\u4E1A\u52A1\u952E\u67E5\u4E0D\u56DE\u6765\u7684\u91CE\u884C\u3002\u5148\u53BB\u7CFB\u7EDF\u91CC\u628A\u90A3\u4E00\u884C\u5904\u7406\u6389\uFF08\u5220\u6389\uFF0C\u6216\u628A\u5B83\u7684\u4E1A\u52A1\u952E\u6539\u6210\u5DE5\u4EF6\u91CC\u7684\u90A3\u4E2A\uFF09\uFF0C\u518D\u628A\u53F0\u8D26\u91CC\u8FD9\u4E00\u884C**\u6574\u884C\u5220\u6389**\u8BA9\u5B83\u6309\u300C\u6CA1\u8BB0\u8FC7\u300D\u91CD\u8DD1",
14120
+ row.row,
14121
+ row.key
14122
+ )
14123
+ );
14124
+ return [false, null];
14125
+ }
14126
+ if (step === STEP_NOTHING) {
14127
+ tally.add("already");
14128
+ const previous = journal.latest(model, row.key);
14129
+ if (previous !== null && previous.serverId) {
14130
+ createdIds.set(createdKey(model, row.key), previous.serverId);
14131
+ }
14132
+ return [false, null];
14133
+ }
14134
+ if (budgetLeft !== null && budgetLeft <= 0) {
14135
+ tally.add("notAttempted");
14136
+ return [false, null];
14137
+ }
14138
+ if (step === STEP_READBACK) {
14139
+ if (dryRun) {
14140
+ tally.add("wouldCreate");
14141
+ createdIds.set(createdKey(model, row.key), DRY_RUN_ID);
14142
+ return [false, null];
14143
+ }
14144
+ let result;
14145
+ try {
14146
+ result = await resolveUnknown(client, model, keyFields, row.key);
14147
+ } catch (raw) {
14148
+ if (!(raw instanceof JournalError)) throw raw;
14149
+ tally.add("readbacks");
14150
+ tally.add("unverified");
14151
+ problems.push(
14152
+ problem4(
14153
+ "READBACK_FAILED",
14154
+ model,
14155
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09\u4E0A\u4E00\u8F6E\u505C\u5728 unknown\uFF0C\u8FD9\u4E00\u8F6E\u56DE\u8BFB**\u95EE\u4E0D\u51FA\u6765**\uFF1A[${raw.reason}] ${raw.message}`,
14156
+ raw.hint || "\u56DE\u8BFB\u95EE\u4E0D\u51FA\u6765\u65F6\u4E0D\u8BB8\u5F53\u6210\u300C\u6CA1\u5EFA\u6210\u300D\u53BB\u91CD\u5EFA \u2014\u2014 \u90A3\u6B63\u662F\u4EA7\u751F\u91CD\u590D\u884C\u7684\u90A3\u6761\u8DEF\u3002\u53F0\u8D26\u91CC\u8FD9\u4E00\u884C\u4ECD\u662F unknown\uFF0C\u4E0B\u4E00\u8F6E\u8FD8\u4F1A\u5148\u56DE\u8BFB",
14157
+ row.row,
14158
+ row.key
14159
+ )
14160
+ );
14161
+ return [true, "readback-failed"];
14162
+ }
14163
+ tally.add("readbacks");
14164
+ if (result.status === "done") {
14165
+ journal.append({
14166
+ ...priorEntry(journal, model, row.key),
14167
+ status: "done",
14168
+ serverId: result.serverId,
14169
+ roundId: plan.roundId
14170
+ });
14171
+ tally.add("already");
14172
+ if (result.serverId) createdIds.set(createdKey(model, row.key), result.serverId);
14173
+ return [true, null];
14174
+ }
14175
+ }
14176
+ const [body, missing] = buildPayload(row, createdIds, journal);
14177
+ if (missing !== null) {
14178
+ tally.add("blocked");
14179
+ problems.push(
14180
+ problem4(
14181
+ "PARENT_NOT_WRITTEN",
14182
+ model,
14183
+ `\u7B2C ${row.row} \u884C\uFF08${row.key.join("+")}\uFF09\u7684 ${missing.field} \u8981\u62FF ${missing.model}.${missing.keyField} = ${JSON.stringify(missing.value)} \u6362 id\uFF0C\u800C\u90A3\u4E00\u884C\u8FD9\u4E00\u8F6E**\u6CA1\u6709\u5199\u6210** \u21D2 \u8FD9\u4E00\u884C\u4E0D\u53D1`,
14184
+ "\u5148\u770B\u90A3\u4E00\u884C**\u4E3A\u4EC0\u4E48\u6CA1\u7559\u4E0B id**\uFF0C\u4E24\u7C7B\uFF1A**\u7532 \xB7 \u6709\u7EC8\u6001\u4F46\u6CA1\u6709\u53EF\u7528 id** \u2014\u2014 \u53F0\u8D26\u8BF4\u5B83\u5EFA\u8FC7/\u8DF3\u8FC7\u3001\u6216\u56DE\u8BFB\u5224 done \u5374\u6CA1\u5E26 id\uFF08\u540E\u4E00\u652F\u4ECA\u5929\u5230\u4E0D\u4E86\uFF0C\u662F\u9632\u5FA1\u6027\u7684\uFF1B\u524D\u4E00\u652F\u662F**\u600E\u4E48\u6765\u7684\uFF0C\u672C\u6267\u884C\u5668\u6CA1\u6709\u67E5\u8FC7** \u2014\u2014 \u53F0\u8D26\u91CC\u90A3\u4E00\u884C\u539F\u6837\u5728\u76D8\u4E0A\uFF0C\u81EA\u5DF1\u770B\uFF09\uFF1B**\u4E59 \xB7 \u660E\u786E\u51FA\u4E8B** \u2014\u2014 \u4E0A\u9762\u90A3\u6761 `CREATE_REJECTED`\uFF08\u4EA7\u54C1\u62D2\u4E86\u5B83\uFF09\u6216 `ROW_QUARANTINED`\uFF08\u53F0\u8D26\u8BF4\u5B83\u4E0A\u4E00\u8F6E\u4E2D\u6BD2\u4E86\uFF09\u3002\u4E5F\u53EF\u80FD\u5B83\u81EA\u5DF1\u88AB\u4E0A\u6E38\u6321\u4F4F\uFF08\u7EA7\u8054\uFF09\u3002\u26A0\uFE0F \u8FD9\u53E5\u8BDD\u6539\u5230\u7B2C\u4E09\u7248\uFF1A\u524D\u4E24\u7248\u5206\u522B\u628A\u300C\u7532\u300D\u5199\u6210\u5931\u8D25\u3001\u628A\u540D\u989D\u95F8\u7B97\u6210\u4E00\u79CD\u53BB\u5904\uFF0C**\u90FD\u662F\u628A\u6CA1\u679A\u4E3E\u8FC7\u7684\u53D6\u503C\u57DF\u5199\u6210\u5168\u79F0\u53E5**\uFF0C\u6240\u4EE5\u8FD9\u4E00\u7248\u53EA\u5206\u7C7B\u3001\u4E0D\u6570\u6570\u3002\u7236\u884C\u843D\u5730\u4E4B\u540E\u91CD\u65B0\u8DD1\u4E00\u6B21 plan + apply\uFF0C\u8FD9\u4E00\u884C\u4F1A\u8DDF\u7740\u8865\u4E0A\uFF08\u53F0\u8D26\u8BB0\u5F97\u5B83\u6CA1\u5EFA\u8FC7\uFF09",
14185
+ row.row,
14186
+ row.key
14187
+ )
14188
+ );
14189
+ return [false, null];
14190
+ }
14191
+ assertBusinessKeySent(body, keyFields, row.key, model, row.row);
14192
+ if (dryRun) {
14193
+ tally.add("wouldCreate");
14194
+ createdIds.set(createdKey(model, row.key), DRY_RUN_ID);
14195
+ return [false, null];
14196
+ }
14197
+ journal.begin(row.row, model, row.key, payloadHash(body), plan.roundId);
14198
+ const out = await client.post(createPath(model), body);
14199
+ tally.add("requests");
14200
+ return judgeCreate(client, out, plan, modelPlan, row, journal, createdIds, tally, problems, sample);
14201
+ }
14202
+ async function applyPlan(client, plan, mapping, journal, options = {}) {
14203
+ const dryRun = options.dryRun ?? true;
14204
+ const sample = options.sample ?? null;
14205
+ const onRequestSpent = options.onRequestSpent ?? null;
14206
+ if (sample !== null && (typeof sample !== "number" || !Number.isInteger(sample) || sample < 1)) {
14207
+ throw new ApplyPremiseError(
14208
+ "bad-sample",
14209
+ `sample=${JSON.stringify(sample)} \u4E0D\u662F\u4E00\u4E2A \u22651 \u7684\u6574\u6570`,
14210
+ "sample \u7684\u8BED\u4E49\u662F\u300C\u5148\u8DD1 N \u884C\u770B\u770B\u300D\uFF1B\u4E0D\u60F3\u9650\u91CF\u5C31\u4F20 null\uFF08\u6216\u4E0D\u4F20\uFF09\uFF0C\u4F20 0 \u4F1A\u53D8\u6210\u4E00\u4E2A\u300C\u4EC0\u4E48\u90FD\u4E0D\u505A\u4F46\u770B\u7740\u50CF\u8DD1\u8FC7\u4E86\u300D\u7684\u4E00\u8F6E"
14211
+ );
14212
+ }
14213
+ if (typeof dryRun !== "boolean") {
14214
+ throw new ApplyPremiseError(
14215
+ "bad-dry-run",
14216
+ `dryRun=${JSON.stringify(dryRun)} \u4E0D\u662F\u5E03\u5C14`,
14217
+ "\u8FD9\u4E2A\u53C2\u6570\u51B3\u5B9A\u8FD9\u4E00\u8F6E\u4F1A\u4E0D\u4F1A\u771F\u7684\u5F80\u5BA2\u6237\u5E93\u91CC\u5199\uFF0C\u4E0D\u63A5\u53D7\u300C\u771F\u503C\u300D\u8FD9\u79CD\u6A21\u7CCA\u8BED\u4E49"
14218
+ );
14219
+ }
14220
+ if (onRequestSpent !== null && typeof onRequestSpent !== "function") {
14221
+ throw new ApplyPremiseError(
14222
+ "bad-on-request-spent",
14223
+ `onRequestSpent=${JSON.stringify(onRequestSpent)} \u4E0D\u662F\u53EF\u8C03\u7528\u5BF9\u8C61`,
14224
+ "\u5B83\u662F\u6BCF\u82B1\u6389\u4E00\u6B21\u8BF7\u6C42\u8981\u76D6\u7684\u90A3\u4E00\u6B21\u7AE0\uFF08\u751F\u4EA7\u4E0A = `Lease.heartbeatIfDue`\uFF09\u3002\u4E0D\u60F3\u76D6\u5C31\u4F20 null \u2014\u2014 \u4F20\u4E00\u4E2A\u8C03\u4E0D\u52A8\u7684\u4E1C\u897F\u4F1A\u5728\u7B2C\u4E00\u6B21\u8BF7\u6C42\u53D1\u51FA\u53BB\u4E4B\u540E\u70B8\u5728\u534A\u8DEF\u4E0A\uFF0C\u800C\u90A3\u4E00\u6B21\u8BF7\u6C42\u5DF2\u7ECF\u51FA\u53BB\u4E86"
14225
+ );
14226
+ }
14227
+ const problems = preflight(plan, mapping);
14228
+ if (problems.length > 0) {
14229
+ return reportOf(plan, dryRun, sample, false, "preflight", [], new Tally(), problems);
14230
+ }
14231
+ const createdIds = /* @__PURE__ */ new Map();
14232
+ const tally = new Tally();
14233
+ const perModel = [];
14234
+ let budget = sample;
14235
+ let aborted = null;
14236
+ for (const modelPlan of plan.models) {
14237
+ const local = new Tally();
14238
+ const rows = (modelPlan.waves ?? []).flatMap((w) => w.rows);
14239
+ for (const row of rows) {
14240
+ if (aborted !== null) {
14241
+ local.add("notAttempted");
14242
+ continue;
14243
+ }
14244
+ let spent;
14245
+ [spent, aborted] = await applyRow(
14246
+ client,
14247
+ plan,
14248
+ modelPlan,
14249
+ row,
14250
+ journal,
14251
+ createdIds,
14252
+ local,
14253
+ problems,
14254
+ dryRun,
14255
+ budget,
14256
+ sample
14257
+ );
14258
+ if (spent && budget !== null) budget -= 1;
14259
+ if (spent && aborted === null && onRequestSpent !== null) {
14260
+ aborted = stampProgress(onRequestSpent, modelPlan.model, row, problems);
14261
+ }
14262
+ }
14263
+ perModel.push({
14264
+ model: modelPlan.model,
14265
+ rows: rows.length,
14266
+ created: local.get("created"),
14267
+ skipped: local.get("skipped"),
14268
+ already: local.get("already"),
14269
+ writeFailed: local.get("writeFailed"),
14270
+ unverified: local.get("unverified"),
14271
+ blocked: local.get("blocked"),
14272
+ quarantined: local.get("quarantined"),
14273
+ notAttempted: local.get("notAttempted"),
14274
+ wouldCreate: local.get("wouldCreate"),
14275
+ requests: local.get("requests")
14276
+ });
14277
+ for (const name of TALLY_FIELDS) tally.add(name, local.get(name));
14278
+ }
14279
+ return reportOf(plan, dryRun, sample, true, aborted, perModel, tally, problems);
14280
+ }
14281
+ function applyReportToJson(report) {
14282
+ return {
14283
+ version: report.version,
14284
+ roundId: report.roundId,
14285
+ dryRun: report.dryRun,
14286
+ sample: report.sample,
14287
+ executed: report.executed,
14288
+ aborted: report.aborted,
14289
+ created: report.created,
14290
+ skipped: report.skipped,
14291
+ already: report.already,
14292
+ writeFailed: report.writeFailed,
14293
+ unverified: report.unverified,
14294
+ blocked: report.blocked,
14295
+ quarantined: report.quarantined,
14296
+ notAttempted: report.notAttempted,
14297
+ wouldCreate: report.wouldCreate,
14298
+ requests: report.requests,
14299
+ readbacks: report.readbacks,
14300
+ models: report.models.map((m) => ({ ...m })),
14301
+ problems: report.problems.map((p) => ({
14302
+ code: p.code,
14303
+ model: p.model,
14304
+ row: p.row,
14305
+ key: p.key === null ? null : [...p.key],
14306
+ message: p.message,
14307
+ hint: p.hint,
14308
+ // 🔴 `rawError` 恒在键集里(没有时是 `null`):让它时有时无,读者就得先判键在不在,
14309
+ // 而「这一条没有原始信封」与「这个版本还没有这个字段」会长成同一个样子。
14310
+ rawError: p.rawError ?? null
14311
+ }))
14312
+ };
14313
+ }
14314
+ function applyReportText(report) {
14315
+ return JSON.stringify(applyReportToJson(report), null, 2);
14316
+ }
14317
+
14318
+ // src/fde/seed/drift.ts
14319
+ import { existsSync as existsSync9, readFileSync as readFileSync8, realpathSync as realpathSync2, statSync as statSync8 } from "fs";
14320
+ import * as path17 from "path";
14321
+ var VERDICT_SAME = "same";
14322
+ var VERDICT_DIVERGED = "diverged";
14323
+ var VERDICT_INCOMPARABLE = "incomparable";
14324
+ var VERDICTS = [VERDICT_SAME, VERDICT_DIVERGED, VERDICT_INCOMPARABLE];
14325
+ var INCOMPLETE_PREFIX = "incomplete:";
14326
+ var CAUSE_PLAN_HAS_NO_BASELINE = "plan-has-no-baseline";
14327
+ var CAUSE_BASELINE_NOT_ON_DISK = "baseline-not-on-disk";
14328
+ var CAUSE_FINGERPRINT_UNREADABLE = "fingerprint-unreadable";
14329
+ var CAUSE_INCOMPLETE_RECORDED = "incomplete-recorded";
14330
+ var CAUSE_INCOMPLETE_CURRENT = "incomplete-current";
14331
+ var INCOMPARABLE_CAUSES = [
14332
+ CAUSE_PLAN_HAS_NO_BASELINE,
14333
+ CAUSE_BASELINE_NOT_ON_DISK,
14334
+ CAUSE_FINGERPRINT_UNREADABLE,
14335
+ CAUSE_INCOMPLETE_RECORDED,
14336
+ CAUSE_INCOMPLETE_CURRENT
14337
+ ];
14338
+ var FINGERPRINT_FILE = "fingerprint.json";
14339
+ var RECON_DIRNAME = "recon";
14340
+ var FORCE_STALE_FLAG = "--force-stale";
14341
+ var FORCE_STALE_COST = "\u8FD9\u4E00\u6279\u884C\u5C31\u662F\u5728\u300C\u5206\u4E0D\u6E05\u662F\u4E0D\u662F\u540C\u4E00\u4E2A\u73AF\u5883\u300D\u7684\u524D\u63D0\u4E0B\u5199\u51FA\u53BB\u7684\uFF0C\u53F0\u8D26\u91CC\u6709\u636E\u53EF\u67E5\uFF1B`apply` \u6CA1\u6709 `--rollback`\uFF0C\u5199\u51FA\u53BB\u7684\u884C\u7559\u5728\u5BA2\u6237\u5E93\u91CC\u3002";
14342
+ function resolveBaselineDir(outRoot, baselineRef) {
14343
+ if (baselineRef === null || baselineRef === void 0) {
14344
+ return [null, CAUSE_PLAN_HAS_NO_BASELINE];
14345
+ }
14346
+ const ref = String(baselineRef);
14347
+ const root = path17.join(outRoot, RECON_DIRNAME);
14348
+ const parts = ref.split(/[\\/]+/);
14349
+ if (!ref || parts.includes("..") || path17.isAbsolute(ref) || /^[A-Za-z]:/.test(ref)) {
14350
+ return [null, CAUSE_BASELINE_NOT_ON_DISK];
14351
+ }
14352
+ const base = path17.join(root, ref);
14353
+ let inside;
14354
+ try {
14355
+ const realRoot = realpathSync2(root);
14356
+ const realBase = realpathSync2(base);
14357
+ inside = realBase === realRoot || realBase.startsWith(realRoot + path17.sep);
14358
+ } catch {
14359
+ inside = false;
14360
+ }
14361
+ if (!inside || !existsSync9(base) || !statSync8(base).isDirectory()) {
14362
+ return [null, CAUSE_BASELINE_NOT_ON_DISK];
14363
+ }
14364
+ return [base, null];
14365
+ }
14366
+ function loadRecordedFingerprint(outRoot, baselineRef) {
14367
+ const [base, cause] = resolveBaselineDir(outRoot, baselineRef);
14368
+ if (cause !== null) return [null, cause];
14369
+ let body;
14370
+ try {
14371
+ body = JSON.parse(readFileSync8(path17.join(base, FINGERPRINT_FILE), "utf-8"));
14372
+ } catch {
14373
+ return [null, CAUSE_FINGERPRINT_UNREADABLE];
14374
+ }
14375
+ if (body === null || typeof body !== "object" || Array.isArray(body)) {
14376
+ return [null, CAUSE_FINGERPRINT_UNREADABLE];
14377
+ }
14378
+ return [body, null];
14379
+ }
14380
+ var SIDE_CAUSES = {
14381
+ recorded: CAUSE_INCOMPLETE_RECORDED,
14382
+ current: CAUSE_INCOMPLETE_CURRENT
14383
+ };
14384
+ var SIDE_WORDS = {
14385
+ recorded: "\u65E7\u6307\u7EB9\uFF08\u722C\u8FD9\u4EFD\u57FA\u7EBF\u90A3\u4E00\u8F6E\uFF09",
14386
+ current: "\u8FD9\u4E00\u6B21\u73B0\u7B97"
14387
+ };
14388
+ var MARKER_HINTS = {
14389
+ "X-HCM-Extension-Source": "\u6A21\u578B\u7B54\u5E94\u4E86\u3001\u4F46\u670D\u52A1\u7AEF\u6CA1\u56DE\u8FD9\u4E2A\u5934 \u21D2 \u67E5**\u53CD\u4EE3**\u662F\u4E0D\u662F\u628A `X-HCM-*` \u54CD\u5E94\u5934\u5265\u4E86",
14390
+ "no-meta-answered": "\u4E00\u4E2A\u6A21\u578B\u90FD\u6CA1\u7B54\u5E94 \u21D2 \u67E5**\u8FDE\u901A / \u6743\u9650 / \u6A21\u578B\u6E05\u5355\u662F\u4E0D\u662F\u7A7A\u7684**\uFF0C\u4E0E\u53CD\u4EE3\u65E0\u5173",
14391
+ "page-cap": "\u5206\u9875\u88AB\u5224\u4E3A\u5F02\u5E38\u5E76\u622A\u65AD \u21D2 \u67E5**\u7F51\u5173**\u628A `totalPages` \u62A5\u6210\u4E86\u4EC0\u4E48",
14392
+ "empty-model-list": "\u8BF7\u6C42\u6210\u529F\u4F46\u4E00\u4E2A\u53EF\u7528 `modelKey` \u90FD\u6CA1\u6709 \u21D2 \u67E5**\u6743\u9650 / \u7F51\u5173\u6539\u5199**\uFF08\u952E\u540D\u8BFB\u9519\u4E5F\u662F\u8FD9\u4E00\u6863\uFF09"
14393
+ };
14394
+ var NO_MARKER_HINT = "\u8FD9\u4E2A\u7AEF\u70B9\u6574\u4E2A\u6CA1\u53D6\u56DE\u6765 \u21D2 \u67E5**\u8FDE\u901A / \u6743\u9650 / \u7F51\u5173**";
14395
+ var NON_ENDPOINT_HINTS = {
14396
+ // 🔴 措辞必须**覆盖两种成因**:整节缺失**或**那一格被摘了,两种都发这条尾部,
14397
+ // 而 hint 是**一条常量**。写成「没有 coverageNotes 这一节」对第二种成因是**假的**
14398
+ //(那一节明明在),顾问打开文件看见它,会连带怀疑这条结论本身。
14399
+ "coverageNotes-missing": "\u8FD9\u4EFD\u6307\u7EB9\u53D6\u4E0D\u5230 `coverageNotes.fetchFailures`\uFF08\u6574\u8282\u7F3A\u5931\u3001\u6216\u90A3\u4E00\u683C\u88AB\u6458\u4E86\uFF09\u21D2 \u5B83\u662F\u65E7\u7248\u4EA7\u7684\u3001\u6216\u88AB\u624B\u6539\u8FC7 \u2014\u2014 \u300C\u6709\u6CA1\u6709\u53D6\u6570\u5931\u8D25\u300D\u5728\u5B83\u4E0A\u9762\u662F**\u672A\u77E5**\uFF0C\u4E0D\u662F\u300C\u5426\u300D\u21D2 \u91CD\u8DD1\u4E00\u6B21 `recon` \u6362\u4E00\u4EFD\u65B0\u7684\uFF08\u8981\u4FEE\u7684\u662F\u8FD9\u4EFD**\u6587\u4EF6**\uFF0C\u8FD9\u4E2A\u73AF\u5883\u672C\u8EAB\u6CA1\u6BDB\u75C5\uFF09"
14400
+ };
14401
+ var RERUN_PLAN_AFTER_RECON = "\u3002\u26A0\uFE0F **\u8FD9\u4E4B\u540E\u8FD8\u8981\u518D\u8DD1\u4E00\u6B21**\uFF1A`plan` \u2014\u2014 `recon` \u4F1A**\u5C31\u5730**\u8986\u5199\u8FD9\u4EFD\u57FA\u7EBF\u5E76\u76D6\u4E00\u4E2A\u65B0\u8F6E\u6B21\u6233\uFF0C\u800C\u8FD9\u4EFD\u8BA1\u5212\u7167\u7684\u662F\u65E7\u5185\u5BB9\uFF0C`apply` \u7684\u8F6E\u6B21\u524D\u63D0\u4F1A\u5F53\u573A\u628A\u5B83\u62E6\u4E0B\u3002";
14402
+ var CAUSE_NEXT_STEPS = {
14403
+ [CAUSE_PLAN_HAS_NO_BASELINE]: [
14404
+ "\u8FD9\u4EFD `import-plan.json` \u91CC\u6CA1\u6709 `baseline` \u6BB5 \u2014\u2014 \u5B83\u662F\u66F4\u65E9\u7248\u672C\u7B97\u51FA\u6765\u7684\u3002",
14405
+ "\u2192 \u91CD\u8DD1\u4E00\u6B21 `plan`\uFF08\u96F6\u5199\uFF1A`plan` \u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\uFF0C\u65B0\u8BA1\u5212\u4F1A\u5E26\u4E0A\u57FA\u7EBF\u51FA\u5904\u3002"
14406
+ ],
14407
+ [CAUSE_BASELINE_NOT_ON_DISK]: [
14408
+ "\u8BA1\u5212\u70B9\u540D\u7684\u90A3\u4EFD\u57FA\u7EBF\u76EE\u5F55\u4E0D\u5728 `<out>/recon/` \u4E0B\uFF08\u542B `..` \u5206\u91CF\u3001\u6216\u843D\u5230 `recon/` \u4E4B\u5916\u7684\u5F15\u7528\uFF0C\u4E00\u5F8B\u6309**\u8D8A\u754C**\u62D2\u7EDD\uFF0C\u4E0D\u53BB\u8BFB\uFF09\u3002",
14409
+ "\u2192 \u628A\u90A3\u4EFD recon \u4EA7\u7269\u539F\u6837\u62F7\u56DE\u6765\uFF1B\u62F7\u4E0D\u56DE\u6765\u5C31\u91CD\u8DD1\u4E00\u6B21 `recon`" + RERUN_PLAN_AFTER_RECON
14410
+ ],
14411
+ [CAUSE_FINGERPRINT_UNREADABLE]: [
14412
+ "\u57FA\u7EBF\u76EE\u5F55\u5728\uFF0C`fingerprint.json` \u4E0D\u5728 / \u8BFB\u4E0D\u51FA\u6765 / \u4E0D\u662F\u4E00\u4E2A JSON \u5BF9\u8C61\uFF08\u8FD9\u4EFD\u6587\u4EF6\u662F\u53EF\u5220\u7684\uFF0C\u6240\u4EE5\u8FD9\u4E00\u6863\u4F1A\u771F\u5B9E\u53D1\u751F\uFF0C\u4E0D\u662F\u8FB9\u89D2\uFF09\u3002",
14413
+ "\u2192 \u91CD\u8DD1\u4E00\u6B21 `recon`\uFF1A\u8FD9\u4EFD\u6587\u4EF6\u662F\u5B83\u6BCF\u8F6E\u6700\u540E\u5199\u7684\uFF0C\u91CD\u8DD1\u5C31\u6709" + RERUN_PLAN_AFTER_RECON
14414
+ ],
14415
+ [CAUSE_INCOMPLETE_RECORDED]: [
14416
+ "\u65E7\u6307\u7EB9**\u81EA\u5DF1\u662F\u6B8B\u7684** \u2014\u2014 \u722C\u8FD9\u4EFD\u57FA\u7EBF\u7684\u90A3\u4E00\u8F6E\u5C31\u6CA1\u722C\u5168\uFF0C\u90A3\u51E0\u683C\u5728\u503C\u4E0A\u4E0E\u300C\u722C\u5230\u4E86\u800C\u4E14\u76F8\u7B49\u300D\u540C\u5F62\uFF0C\u4E0D\u80FD\u62FF\u6765\u5F53\u540C\u6E90\u7684\u8BC1\u636E\u3002",
14417
+ "\u2192 \u91CD\u8DD1\u4E00\u6B21 `recon`\uFF1A\u8981\u4FEE\u7684\u662F**\u57FA\u7EBF**\uFF0C\u4E0D\u662F\u8FD9\u4E2A\u73AF\u5883" + RERUN_PLAN_AFTER_RECON
14418
+ ],
14419
+ [CAUSE_INCOMPLETE_CURRENT]: [
14420
+ "\u8FD9\u4E00\u6B21**\u7B97\u4E0D\u51FA\u6765** \u2014\u2014 \u95E8\u7AEF\u70B9\u5728\u8FD9\u4E2A\u73AF\u5883\u4E0A\u53D6\u4E0D\u5230\u3002",
14421
+ "\u2192 \u{1F534} \u91CD\u8DD1 `recon` **\u6CA1\u6709\u7528**\uFF08\u5B83\u6253\u7684\u662F\u540C\u4E00\u6279\u7AEF\u70B9\uFF09\u3002\u5148\u6309\u4E0B\u9762\u70B9\u540D\u7684\u7AEF\u70B9**\u4FEE\u73AF\u5883**\u3002"
14422
+ ]
14423
+ };
14424
+ function splitIncomplete(item) {
14425
+ const rest = item.slice(INCOMPLETE_PREFIX.length);
14426
+ const at = rest.indexOf(":");
14427
+ return at === -1 ? [rest, ""] : [rest.slice(0, at), rest.slice(at + 1)];
14428
+ }
14429
+ function causesFromIncomplete(items) {
14430
+ const found = /* @__PURE__ */ new Set();
14431
+ for (const item of items) {
14432
+ const [side] = splitIncomplete(item);
14433
+ const cause = SIDE_CAUSES[side];
14434
+ if (cause === void 0) {
14435
+ throw new Error(
14436
+ `\u8BA4\u4E0D\u51FA\u7684 incomplete \u4FA7\u522B ${JSON.stringify(side)}\uFF08\u6761\u76EE ${JSON.stringify(item)}\uFF09\u3002compareFingerprint \u53EA\u4EA7\u51FA ${JSON.stringify(Object.keys(SIDE_CAUSES).sort())}\uFF1B\u591A\u51FA\u6765\u7684\u4E00\u4FA7\u6CA1\u6709\u5BF9\u5E94\u7684\u51FA\u8DEF\uFF0C\u4E0D\u8BB8\u731C\u4E00\u4E2A\u3002`
14437
+ );
14438
+ }
14439
+ found.add(cause);
14440
+ }
14441
+ return INCOMPARABLE_CAUSES.filter((c) => found.has(c));
14442
+ }
14443
+ function baselineWords(baseline) {
14444
+ return baseline ? `\u57FA\u7EBF \`${baseline}\`` : "\u57FA\u7EBF\uFF08\u8BA1\u5212\u91CC\u6CA1\u8BF4\u662F\u54EA\u4E00\u4EFD\uFF09";
14445
+ }
14446
+ function incompleteLines(items) {
14447
+ const lines = [];
14448
+ for (const item of [...items].sort()) {
14449
+ const [side, tail] = splitIncomplete(item);
14450
+ const who = SIDE_WORDS[side] ?? side;
14451
+ const nonEndpoint = NON_ENDPOINT_HINTS[tail];
14452
+ if (nonEndpoint !== void 0) {
14453
+ lines.push(` \xB7 ${who}\uFF1A\`${tail}\` \u2014\u2014 ${nonEndpoint}`);
14454
+ continue;
14455
+ }
14456
+ const at = tail.indexOf("#");
14457
+ const marker = at === -1 ? "" : tail.slice(at + 1);
14458
+ lines.push(` \xB7 ${who}\uFF1A\u7AEF\u70B9 \`${tail}\` \u2014\u2014 ${MARKER_HINTS[marker] ?? NO_MARKER_HINT}`);
14459
+ }
14460
+ return lines;
14461
+ }
14462
+ function forceStaleLines() {
14463
+ return [
14464
+ ` \u2192 \u4FEE\u4E0D\u52A8\u3001\u53C8\u5FC5\u987B\u4ECA\u5929\u5C31\u5199\uFF1A\`${FORCE_STALE_FLAG}\` \u653E\u884C\u3002**\u8FD9\u4E0D\u662F\u300C\u52A0\u4E2A\u53C2\u6570\u5C31\u597D\u4E86\u300D** \u2014\u2014 ${FORCE_STALE_COST}`
14465
+ ];
14466
+ }
14467
+ function driftMessage(verdict, gateDiffs, incomplete, advisory, causes, baseline) {
14468
+ const lines = [];
14469
+ if (verdict === VERDICT_SAME) {
14470
+ lines.push(
14471
+ `\u2705 \u540C\u6E90\uFF1A${baselineWords(baseline)} \u4E0E\u773C\u524D\u8FD9\u4E2A\u73AF\u5883\u7684\u4E09\u4E2A\u95E8\u5206\u91CF\uFF08${GATE_COMPONENTS.join(" / ")}\uFF09\u9010\u4E2A\u76F8\u7B49\u3002`
14472
+ );
14473
+ lines.push(" \u2192 \u53EF\u4EE5\u63A5\u7740\u8DD1 `apply --execute`\u3002");
14474
+ } else if (verdict === VERDICT_DIVERGED) {
14475
+ lines.push(`\u{1F534} \u4E0D\u540C\u6E90\uFF1A${baselineWords(baseline)} **\u4E0D\u662F**\u773C\u524D\u8FD9\u4E2A\u73AF\u5883\u7684\u3002`);
14476
+ lines.push(
14477
+ ` \u4E0D\u76F8\u7B49\u7684\u95E8\u5206\u91CF\uFF08${gateDiffs.length} \u683C\uFF09\uFF1A${gateDiffs.map((d) => `\`${d}\``).join("\u3001")}`
14478
+ );
14479
+ if (incomplete.length > 0) {
14480
+ lines.push(` \u53E6\u6709 ${incomplete.length} \u683C**\u6CA1\u67E5\u6210**\uFF08\u4E0D\u5F71\u54CD\u4E0A\u9762\u90A3\u4E2A\u7ED3\u8BBA\uFF0C\u4F46\u4E00\u5E76\u62A5\u51FA\u6765\uFF09\uFF1A`);
14481
+ lines.push(...incompleteLines(incomplete));
14482
+ }
14483
+ lines.push(
14484
+ " \u2192 \u91CD\u8DD1\u4E00\u6B21 `recon`\uFF0C\u518D\u91CD\u8DD1\u4E00\u6B21 `plan` \u2014\u2014 \u7528**\u8FD9\u4E2A\u73AF\u5883**\u7684\u57FA\u7EBF\u91CD\u65B0\u7B97\u8FD9\u4E00\u6279\u5199\u3002\u5DE5\u4EF6\u4E00\u884C\u90FD\u4E0D\u7528\u6539\u3002"
14485
+ );
14486
+ lines.push(...forceStaleLines());
14487
+ } else {
14488
+ lines.push(
14489
+ `\u{1F534} \u6BD4\u4E0D\u4E86\uFF1A${baselineWords(baseline)} \u4E0E\u773C\u524D\u8FD9\u4E2A\u73AF\u5883\u662F\u4E0D\u662F\u540C\u4E00\u4E2A\uFF0C**\u5206\u4E0D\u6E05** \u2014\u2014 **\u8FD9\u4E0D\u662F\u300C\u6BD4\u8FC7\u4E86\u3001\u4E00\u6837\u300D**\u3002`
14490
+ );
14491
+ for (const cause of causes) {
14492
+ const [why, how] = CAUSE_NEXT_STEPS[cause];
14493
+ lines.push(` \xB7 [${cause}] ${why}`);
14494
+ lines.push(` ${how}`);
14495
+ if (cause === CAUSE_INCOMPLETE_RECORDED || cause === CAUSE_INCOMPLETE_CURRENT) {
14496
+ const side = cause === CAUSE_INCOMPLETE_RECORDED ? "recorded" : "current";
14497
+ lines.push(...incompleteLines(incomplete.filter((i) => splitIncomplete(i)[0] === side)));
14498
+ }
14499
+ }
14500
+ lines.push(...forceStaleLines());
14501
+ }
14502
+ if (advisory.length > 0) {
14503
+ lines.push(
14504
+ " \u24D8 \u53E6\u6709\u975E\u95E8\u4E0A\u62A5\u9879\uFF08**\u4E0D\u6539\u4E0A\u9762\u90A3\u4E2A\u7ED3\u8BBA**\uFF0C\u53EA\u662F\u4E24\u4EFD\u4EA7\u7269\u7684\u722C\u6CD5\u4E0D\u540C\uFF09\uFF1A" + advisory.map((a) => `\`${a}\``).join("\u3001")
14505
+ );
14506
+ }
14507
+ return lines.join("\n");
14508
+ }
14509
+ function judgeDrift(recorded, current, options = {}) {
14510
+ const baseline = options.baseline ?? null;
14511
+ const loadCause = options.loadCause ?? null;
14512
+ if (loadCause !== null) {
14513
+ if (!INCOMPARABLE_CAUSES.includes(loadCause)) {
14514
+ throw new Error(
14515
+ `\u8BA4\u4E0D\u51FA\u7684\u88C5\u8F7D\u6210\u56E0 ${JSON.stringify(loadCause)}\uFF1B\u53D6\u503C\u57DF\u662F ${JSON.stringify([...INCOMPARABLE_CAUSES])}\u3002`
14516
+ );
14517
+ }
14518
+ const causes2 = [loadCause];
14519
+ return {
14520
+ verdict: VERDICT_INCOMPARABLE,
14521
+ gateDiffs: [],
14522
+ incomplete: [],
14523
+ advisory: [],
14524
+ causes: causes2,
14525
+ baseline,
14526
+ message: driftMessage(VERDICT_INCOMPARABLE, [], [], [], causes2, baseline)
14527
+ };
14528
+ }
14529
+ const ok = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
14530
+ if (!ok(recorded) || !ok(current)) {
14531
+ throw new Error(
14532
+ `judgeDrift \u62FF\u5230\u4E86\u975E\u6307\u7EB9\u8F93\u5165\uFF08recorded=${recorded === null ? "null" : typeof recorded}, current=${current === null ? "null" : typeof current}\uFF09\u3002\u88C5\u8F7D\u5931\u8D25\u5FC5\u987B\u8D70 \`loadCause\`\uFF08\u89C1 loadRecordedFingerprint \u7684\u8FD4\u56DE\u5951\u7EA6\uFF09\uFF0C\u4E0D\u8BB8\u628A null \u76F4\u63A5\u9012\u8FDB\u6765\u3002`
14533
+ );
14534
+ }
14535
+ const diffs = compareFingerprint(recorded, current);
14536
+ const gateDiffs = diffs.filter((d) => GATE_COMPONENTS.includes(d));
14537
+ const incomplete = diffs.filter((d) => d.startsWith(INCOMPLETE_PREFIX));
14538
+ const advisory = diffs.filter((d) => !gateDiffs.includes(d) && !incomplete.includes(d));
14539
+ let verdict;
14540
+ let causes;
14541
+ if (gateDiffs.length > 0) {
14542
+ verdict = VERDICT_DIVERGED;
14543
+ causes = [];
14544
+ } else if (incomplete.length > 0) {
14545
+ verdict = VERDICT_INCOMPARABLE;
14546
+ causes = causesFromIncomplete(incomplete);
14547
+ } else {
14548
+ verdict = VERDICT_SAME;
14549
+ causes = [];
14550
+ }
14551
+ return {
14552
+ verdict,
14553
+ gateDiffs,
14554
+ incomplete,
14555
+ advisory,
14556
+ causes,
14557
+ baseline,
14558
+ message: driftMessage(verdict, gateDiffs, incomplete, advisory, causes, baseline)
14559
+ };
14560
+ }
14561
+ var DRY_RUN_NOTE = "\u26A0\uFE0F \u4E0B\u9762\u8FD9\u6BB5\u5224\u65AD**\u6CA1\u6709\u62E6\u8FD9\u4E00\u8F6E** \u2014\u2014 \u8FD9\u662F\u5E72\u8DD1\uFF0C\u4E00\u53D1\u5199\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF0C\u6CA1\u6709\u53EF\u62E6\u7684\u4E1C\u897F\u3002\u540C\u4E00\u6BB5\u5224\u65AD\u5728 `--execute` \u90A3\u4E00\u8F6E\u662F\u786C\u505C\u3002\n{message}";
14562
+ var WAIVER_NOTE = "\u26A0\uFE0F `{flag}` \u653E\u884C\u4E86\u8FD9\u4E00\u8F6E\uFF0C\u5E76\u8BB0\u8FDB\u4E86\u53F0\u8D26\uFF08`{file}` \u91CC\u591A\u4E86\u4E00\u7B14 `{kind}`\uFF09\u3002{cost}\n{message}";
14563
+ var FORCE_STALE_UNUSED = "\u24D8 \u672C\u8F6E\u6CA1\u6709\u6F02\u79FB\uFF0C`{flag}` \u6CA1\u6709\u7528\u4E0A \u2014\u2014 \u95F8\u672C\u6765\u5C31\u662F\u653E\u884C\u7684\uFF0C\u53F0\u8D26\u91CC\u4E5F\u4E0D\u8BB0\u8FD9\u4E00\u7B14\uFF08\u6CA1\u6709\u653E\u884C\u53D1\u751F\uFF09\u3002";
14564
+ var WAIVER_REPLAY = "\u26A0\uFE0F \u8FD9\u4E2A work \u76EE\u5F55\u91CC\u5DF2\u6709 `{flag}` \u653E\u884C\u8BB0\u5F55\uFF1A{detail}";
14565
+ var DriftDetected = class extends Error {
14566
+ verdict;
14567
+ constructor(verdict) {
14568
+ super(verdict.message);
14569
+ this.name = "DriftDetected";
14570
+ this.verdict = verdict;
14571
+ }
14572
+ };
14573
+ function describeWaiver(waiver) {
14574
+ const where = waiver.baseline ? `\u57FA\u7EBF \`${waiver.baseline}\`` : "\u57FA\u7EBF\uFF08\u90A3\u4E00\u8F6E\u7684\u8BA1\u5212\u91CC\u6CA1\u8BF4\u662F\u54EA\u4E00\u4EFD\uFF09";
14575
+ let tail = "";
14576
+ if (waiver.causes.length > 0) {
14577
+ tail = `\uFF08\u6210\u56E0 ${waiver.causes.map((c) => `\`${c}\``).join("\u3001")}\uFF09`;
14578
+ } else if (waiver.gateDiffs.length > 0) {
14579
+ tail = `\uFF08\u4E0D\u76F8\u7B49\u7684\u95E8\u5206\u91CF ${waiver.gateDiffs.map((d) => `\`${d}\``).join("\u3001")}\uFF09`;
14580
+ }
14581
+ return `${waiver.at} \u90A3\u4E00\u8F6E roundId \`${waiver.roundId}\` \u5224\u4E3A \`${waiver.verdict}\`${tail}\uFF0C${where} \u2014\u2014 \u90A3\u4E00\u8F6E\u5199\u51FA\u53BB\u7684\u884C\uFF0C\u5C31\u662F\u5E26\u7740\u8FD9\u4E2A\u524D\u63D0\u5199\u7684\u3002`;
14582
+ }
14583
+ function enforceDriftGate(verdict, options) {
14584
+ const { journal, roundId, forced, dryRun } = options;
14585
+ if (verdict.verdict === VERDICT_SAME) {
14586
+ return forced ? FORCE_STALE_UNUSED.replace("{flag}", FORCE_STALE_FLAG) : null;
14587
+ }
14588
+ if (dryRun) return DRY_RUN_NOTE.replace("{message}", verdict.message);
14589
+ if (!forced) throw new DriftDetected(verdict);
14590
+ journal.appendWaiver({
14591
+ roundId,
14592
+ at: nowStamp(),
14593
+ verdict: verdict.verdict,
14594
+ causes: [...verdict.causes],
14595
+ gateDiffs: [...verdict.gateDiffs],
14596
+ incomplete: [...verdict.incomplete],
14597
+ advisory: [...verdict.advisory],
14598
+ baseline: verdict.baseline
14599
+ });
14600
+ return WAIVER_NOTE.replace("{flag}", FORCE_STALE_FLAG).replace("{file}", JOURNAL_FILE).replace("{kind}", KIND_DRIFT_WAIVER).replace("{cost}", FORCE_STALE_COST).replace("{message}", verdict.message);
14601
+ }
14602
+
14603
+ // src/fde/verify/run.ts
14604
+ var STATUS_UNKNOWN = "unknown";
14605
+ var PREMISE_JOURNAL_ON_DISK = "journal-on-disk";
14606
+ var PREMISE_JOURNAL_HAS_ENTRIES = "journal-has-entries";
14607
+ var PREMISE_PLAN_READABLE = "plan-readable";
14608
+ var PREMISE_CODES4 = [
14609
+ PREMISE_JOURNAL_ON_DISK,
14610
+ PREMISE_JOURNAL_HAS_ENTRIES,
14611
+ PREMISE_PLAN_READABLE
14612
+ ];
14613
+ var PREMISE_UNMET = "\u524D\u63D0\u672A\u6210\u7ACB";
14614
+ var WHY_NO_JOURNAL = "\u8FD9\u4E2A work \u76EE\u5F55\u4E0B\u6CA1\u6709\u53F0\u8D26\u6587\u4EF6 \u2014\u2014 \u672C\u5DE5\u5177\u5728**\u8FD9\u4E2A\u76EE\u5F55**\u4E0A\u4E00\u8F6E\u90FD\u6CA1\u843D\u8FC7\u8D26\u3002\u26A0\uFE0F\u300Cwork \u76EE\u5F55\u6307\u9519\u4E86\u300D\u4E0E\u300C\u7B2C\u4E00\u8F6E\u5929\u7136\u6CA1\u6709\u53F0\u8D26\u300D\u5728\u5BA2\u6237\u7AEF\u5206\u4E0D\u51FA\u6765\uFF0C\u6240\u4EE5\u300C0 \u884C\u300D\u5728\u8FD9\u91CC\u4E0D\u662F\u4E00\u53E5\u4E1A\u52A1\u7ED3\u8BBA\u3002";
14615
+ var WHY_NO_ENTRIES = {
14616
+ true: "\u53F0\u8D26\u6587\u4EF6\u5728\uFF0C\u91CC\u9762\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709\u3002\u843D\u8FC7\u8D26\u7684\u4E00\u8F6E\u81F3\u5C11\u7559\u5F97\u4E0B\u4E00\u6761\u5199\u524D\u843D\u8D26\u7684\u8BB0\u5F55\uFF0C\u6240\u4EE5\u300C\u6587\u4EF6\u5728\u3001\u96F6\u884C\u300D\u8FD9\u4E00\u6863\u8981\u4EBA\u53BB\u770B\u4E00\u773C\u90A3\u4EFD\u6587\u4EF6\u672C\u8EAB\u3002",
14617
+ false: "\u53F0\u8D26\u6587\u4EF6\u6839\u672C\u4E0D\u5728\uFF0C\u6240\u4EE5**\u65E0\u4ECE\u8C08\u884C\u6570** \u2014\u2014 \u8FD9\u4E00\u6863\u4E0D\u662F\u300C\u8DD1\u8FC7\u3001\u96F6\u884C\u300D\u3002\u26A0\uFE0F \u522B\u628A\u5B83\u8BFB\u6210\u300C\u4EC0\u4E48\u90FD\u6CA1\u52A8\u300D\uFF1A\u4E0A\u9762\u90A3\u6761\u524D\u63D0\u5DF2\u7ECF\u8BF4\u4E86\uFF0C\u300Cwork \u76EE\u5F55\u6307\u9519\u4E86\u300D\u5728\u5BA2\u6237\u7AEF\u4E0E\u300C\u7B2C\u4E00\u8F6E\u5929\u7136\u6CA1\u6709\u53F0\u8D26\u300D\u5206\u4E0D\u51FA\u6765\u3002"
14618
+ };
14619
+ var WHY_PLAN_UNREADABLE = "\u8BFB\u4E0D\u56DE\u76D8\u4E0A\u90A3\u4EFD\u8BA1\u5212 \u21D2\u300C\u8BA1\u5212\u91CC\u6709\u3001\u53F0\u8D26\u91CC\u6CA1\u6709\u300D\u8FD9\u4E00\u683C**\u6CA1\u6709\u7B54\u6848**\u3002\u{1F534} \u8BA1\u5212\u4E0D\u5728\u7684\u65F6\u5019\u5DEE\u96C6\u7B97\u51FA\u6765\u662F\u7A7A\u96C6\uFF0C\u4E0E\u300C\u4E00\u4EF6\u6CA1\u843D\u4E0B\u300D\u9010\u5B57\u540C\u5F62 \u2014\u2014 \u6240\u4EE5\u8FD9\u4E00\u683C\u7ED9\u7684\u662F\u524D\u63D0\uFF0C\u800C\u4E0D\u662F\u4E00\u4E2A\u7A7A\u5DEE\u96C6\u3002";
14620
+ var ROUND_SPAN = " \u2026 ";
14621
+ var NOT_COVERED = [
14622
+ "\u300C\u8BA1\u5212\u91CC\u6709\u3001\u53F0\u8D26\u91CC\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709\u300D\u8FD9\u4E00\u683C\u53EA\u8BF4\u8FD9\u4E9B\u884C**\u6CA1\u52A8\u6210**\uFF0C**\u672A\u8BB0\u5F55\u539F\u56E0**\uFF1A\u88AB\u7236\u884C\u6321\u4F4F\uFF08blocked\uFF09\u3001\u6574\u8F6E\u4E2D\u6B62\u4E4B\u540E\u6CA1\u8F6E\u5230\uFF08notAttempted\uFF09\u3001dry-run \u53EA\u7B97\u4E0D\u5199\uFF08wouldCreate\uFF09\u2014\u2014 \u8FD9\u4E09\u6863\u5728\u53F0\u8D26\u91CC\u4E00\u6761\u8BB0\u5F55\u90FD\u4E0D\u7559\uFF0C\u800C apply \u7684\u62A5\u544A\u5168\u6811\u552F\u4E00\u53BB\u5904\u662F\u6253\u5370\u5230\u5C4F\u5E55\u3001\u4ECE\u4E0D\u843D\u76D8 \u21D2 \u76D8\u4E0A\u95EE\u4E0D\u51FA\u539F\u56E0\u3002",
14623
+ "\u5DEE\u96C6\u7684\u5DE6\u8FB9\u662F**\u76D8\u4E0A\u6B64\u523B\u90A3\u4EFD import-plan.json**\uFF1A\u987E\u95EE\u4E2D\u9014\u91CD\u8DD1\u8FC7 plan \u7684\u8BDD\uFF0C\u76D8\u4E0A\u662F\u65B0\u8BA1\u5212\u3001\u53F0\u8D26\u91CC\u5374\u662F\u4E0A\u4E00\u4EFD\u8BA1\u5212\u90A3\u4E00\u8F6E\u5199\u4E0B\u7684\u884C \u2014\u2014\u300C\u8FD9\u4EFD\u8BA1\u5212\u4E0E\u8FD9\u4EFD\u53F0\u8D26\u662F\u540C\u4E00\u4EFD\u5417\u300D\u672C\u805A\u5408\u5668\u5224\u4E0D\u51FA\u6765\u3002",
14624
+ "`byStatus` \u91CC\u7684 quarantined \u662F**\u53F0\u8D26\u53E3\u5F84 \xB7 \u5386\u8F6E\u7D2F\u8BA1**\uFF08`Entry.status`\uFF09\uFF0C**\u4E0D\u8BF4**\u300C\u8FD9\u4E00\u8F6E\u54EA\u4E9B\u884C\u4E2D\u6BD2\u4E86\u300D\uFF1A\u672C\u8F6E\u53E3\u5F84\u90A3\u4E00\u4EFD\u4F4F\u5728 apply \u62A5\u544A\u7684 quarantined \u6863\u91CC\uFF0C\u800C\u90A3\u4EFD\u62A5\u544A\u4ECE\u4E0D\u843D\u76D8\uFF0C\u672C\u805A\u5408\u5668\u591F\u4E0D\u5230\u5B83\u3002",
14625
+ "\u8BA1\u5212\u90A3\u4E00\u4FA7\u53EA\u679A\u4E3E\u5F97\u5230**\u8FDB\u5F97\u4E86\u6CE2\u6B21**\u7684\u884C\uFF1A`ModelPlan.rowsNotInWaves` \u53EA\u6709\u8BA1\u6570\u3001\u6CA1\u6709\u884C\uFF1B`planned=false` \u7684\u6A21\u578B waves \u662F null \u21D2 \u5B83\u4E00\u884C\u90FD\u4E0D\u8FDB\u5DEE\u96C6\u7684\u5DE6\u8FB9\u3002",
14626
+ // ⚠️ 病史留在**注释**里,不进产物散文:这一格曾写成「这份基线里**唯一**的时间信息是
14627
+ // 计划轮次 id 的前半截」,被**同一个返回对象**上的 `waivers[].at`(完整 ISO-8601)
14628
+ // 当场证伪 —— 又一次「把没枚举全的取值域写成全称句」。产物是给 FDE 签字看的证据,
14629
+ // 不是变更日志;病史写进去还会把自己的判据顶红(那条用例禁「唯一」二字)。
14630
+ "\u53F0\u8D26\u884C**\u6CA1\u6709\u65F6\u95F4\u6233**\uFF08`ENTRY_KEYS` \u91CC\u4E00\u4E2A\u65F6\u95F4\u5B57\u6BB5\u90FD\u6CA1\u6709\uFF09\uFF1A**\u884C\u8FD9\u4E00\u4FA7**\u80FD\u62FF\u5230\u7684\u65F6\u95F4\u53EA\u6709\u8BA1\u5212\u8F6E\u6B21 id \u7684\u524D\u534A\u622A\uFF0C\u79D2\u7CBE\u5EA6\u3002\u26A0\uFE0F \u8BF4\u51C6\u4E00\u683C\uFF1A\u8FD9\u4EFD\u57FA\u7EBF\u91CC**\u4E0D\u662F\u6CA1\u6709\u522B\u7684\u65F6\u95F4** \u2014\u2014 waiver \u90A3\u4E00\u4FA7\u5E26\u5B8C\u6574 ISO-8601 \u7684 at\uFF08`WAIVER_KEYS` \u91CC\u6709\u5B83\uFF09\uFF0C\u5B83\u8BF4\u7684\u662F\u300C\u54EA\u4E00\u8F6E\u5728\u4EC0\u4E48\u524D\u63D0\u4E0B\u8DD1\u7684\u300D\uFF0C**\u4E0D\u843D\u5230\u4EFB\u4F55\u4E00\u884C\u5934\u4E0A**\u3002"
14631
+ ];
14632
+ function premise(code, ok, why, hint = "") {
14633
+ if (ok) return { code, ok: true, detail: "", hint: "" };
14634
+ return { code, ok: false, detail: `${PREMISE_UNMET}\uFF1A${why}`, hint };
14635
+ }
14636
+ function identityOf(model, key) {
14637
+ return JSON.stringify([model, key]);
14638
+ }
14639
+ function plannedWithoutRecordOf(plan, book) {
14640
+ const missing = [];
14641
+ for (const modelPlan of plan.models) {
14642
+ for (const wave of modelPlan.waves ?? []) {
14643
+ for (const row of wave.rows) {
14644
+ if (book.statusOf(modelPlan.model, row.key) === null) {
14645
+ missing.push({
14646
+ model: modelPlan.model,
14647
+ key: [...row.key],
14648
+ sourceRowId: row.row,
14649
+ action: row.action
14650
+ });
14651
+ }
14652
+ }
14653
+ }
14654
+ }
14655
+ return missing;
14656
+ }
14657
+ function labelOf(workDir, rounds) {
14658
+ if (rounds.length === 0) return `${workDir} \xB7 \u53F0\u8D26\u91CC\u6CA1\u6709\u4EFB\u4F55\u8BA1\u5212\u8F6E\u6B21`;
14659
+ const span = rounds.length === 1 ? rounds[0] : [rounds[0], rounds.at(-1)].join(ROUND_SPAN);
14660
+ return `${workDir} \xB7 \u8BA1\u5212\u8F6E\u6B21 ${span}\uFF08\u5171 ${rounds.length} \u8F6E\uFF09`;
14661
+ }
14662
+ function buildDeliveryRun(workDir) {
14663
+ const book = Journal.load(workDir);
14664
+ const rounds = [...new Set(book.entries.map((e) => e.roundId))];
14665
+ const identities = /* @__PURE__ */ new Map();
14666
+ for (const entry of book.entries) {
14667
+ const id = identityOf(entry.model, entry.businessKey);
14668
+ if (!identities.has(id)) identities.set(id, [entry.model, entry.businessKey]);
14669
+ }
14670
+ const rows = [...identities.values()].map(([model, key]) => book.latest(model, key));
14671
+ const byStatus = Object.fromEntries(STATUSES.map((s) => [s, 0]));
14672
+ for (const row of rows) byStatus[row.status] += 1;
14673
+ const unresolved = rows.filter((row) => row.status === STATUS_UNKNOWN);
14674
+ const premises = [
14675
+ premise(PREMISE_JOURNAL_ON_DISK, book.exists, WHY_NO_JOURNAL),
14676
+ premise(
14677
+ PREMISE_JOURNAL_HAS_ENTRIES,
14678
+ book.entries.length > 0,
14679
+ WHY_NO_ENTRIES[book.exists ? "true" : "false"]
14680
+ )
14681
+ ];
14682
+ let plannedWithoutRecord;
14683
+ try {
14684
+ const plan = readImportPlan(book.workDir);
14685
+ premises.push(premise(PREMISE_PLAN_READABLE, true, WHY_PLAN_UNREADABLE));
14686
+ plannedWithoutRecord = plannedWithoutRecordOf(plan, book);
14687
+ } catch (raw) {
14688
+ if (!(raw instanceof PlanReadError)) throw raw;
14689
+ premises.push(
14690
+ premise(
14691
+ PREMISE_PLAN_READABLE,
14692
+ false,
14693
+ `${WHY_PLAN_UNREADABLE}\uFF08[${raw.reason}] ${raw.detail}\uFF09`,
14694
+ raw.hint
14695
+ )
14696
+ );
14697
+ plannedWithoutRecord = null;
14698
+ }
14699
+ return {
14700
+ workDir: book.workDir,
14701
+ journalExists: book.exists,
14702
+ rounds,
14703
+ rows,
14704
+ byStatus,
14705
+ unresolved,
14706
+ waivers: [...book.waivers],
14707
+ plannedWithoutRecord,
14708
+ premises,
14709
+ notCovered: NOT_COVERED,
14710
+ label: labelOf(book.workDir, rounds)
14711
+ };
14712
+ }
14713
+ function deliveryRunFields(run) {
14714
+ return Object.keys(run).sort();
14715
+ }
14716
+
14717
+ // src/fde/verify/reconcile.ts
14718
+ var STATUS_FAILED = "failed";
14719
+ var VERDICT_CONFIRMED = "confirmed";
14720
+ var VERDICT_ID_DIFFERS = "id-differs";
14721
+ var VERDICT_CONTRADICTS = "contradicts";
14722
+ var VERDICT_UNATTRIBUTED = "unattributed";
14723
+ var VERDICT_INVISIBLE = "invisible";
14724
+ var VERDICT_UNREADABLE = "unreadable";
14725
+ var VERDICT_NOT_CHECKED = "not-checked";
14726
+ var VERDICTS2 = [
14727
+ VERDICT_CONFIRMED,
14728
+ VERDICT_ID_DIFFERS,
14729
+ VERDICT_CONTRADICTS,
14730
+ VERDICT_UNATTRIBUTED,
14731
+ VERDICT_INVISIBLE,
14732
+ VERDICT_UNREADABLE,
14733
+ VERDICT_NOT_CHECKED
14734
+ ];
14735
+ var AGREEING_VERDICTS = [VERDICT_CONFIRMED];
14736
+ var DIFFERENCE_VERDICTS = [VERDICT_ID_DIFFERS, VERDICT_CONTRADICTS];
14737
+ var UNDECIDED_VERDICTS = [
14738
+ VERDICT_UNATTRIBUTED,
14739
+ VERDICT_INVISIBLE,
14740
+ VERDICT_UNREADABLE,
14741
+ VERDICT_NOT_CHECKED
14742
+ ];
14743
+ var VERDICT_WORDS = {
14744
+ [VERDICT_CONFIRMED]: "\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u770B\u5F97\u89C1\u4E00\u884C\uFF0C\u4E14\u5B83\u7684 id \u4E0E\u53F0\u8D26\u8BB0\u4E0B\u7684**\u662F\u540C\u4E00\u4E2A** \u21D2 \u8D26\u672C\u8BF4\u7684\u90A3\u4E00\u884C\u6B64\u523B\u5728\u5E93\u91CC\u3002\u26A0\uFE0F \u8BF4\u51C6\u4E00\u683C\uFF1A\u8FD9\u8BF4\u7684\u662F\u300C\u8FD9\u4E00\u884C\u5728\u300D\uFF0C\u4E0D\u662F\u300C\u5B83\u7684\u5B57\u6BB5\u503C\u90FD\u5BF9\u300D\u2014\u2014\u672C\u5C42\u53EA\u5BF9\u8EAB\u4EFD\uFF0C\u4E0D\u6BD4\u5B57\u6BB5\u3002\u{1F534} \u53F0\u8D26\u72B6\u6001\u662F quarantined \u7684\u884C**\u5373\u4F7F\u5224 confirmed \u4E5F\u4ECD\u7136\u8981\u4EBA\u770B**\uFF1A\u8FD9\u4E00\u6863\u8BF4\u7684\u662F**\u8FD9\u4E2A\u952E**\u5728\uFF0C\u8BF4\u4E0D\u4E86\u670D\u52A1\u7AEF\u6709\u6CA1\u6709\u4E00\u6761**\u522B\u7684\u952E**\u7684\u91CE\u884C\uFF08\u53F0\u8D26\u90A3\u4E00\u6863\u7684\u4E0B\u4E00\u6B65\u9010\u5B57\u5199\u7740\u300C\u505C\u4E0B\u6765\u70B9\u540D\u8981\u4EBA\u300D\uFF0C\u672C\u5C42\u7684\u786E\u8BA4\u6E05\u4E0D\u6389\u90A3\u4E2A\u5ACC\u7591\uFF09\u3002",
14745
+ [VERDICT_ID_DIFFERS]: "\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u770B\u5F97\u89C1\u4E00\u884C\uFF0C\u4F46\u5B83\u7684 id \u4E0E\u53F0\u8D26\u8BB0\u4E0B\u7684**\u4E0D\u662F\u540C\u4E00\u4E2A** \u21D2 \u8981\u4E48\u8FD9\u4E2A\u952E\u5728\u672C\u79DF\u6237\u4E0D\u552F\u4E00\uFF0C\u8981\u4E48\u90A3\u4E00\u884C\u88AB\u5220\u8FC7\u53C8\u91CD\u5EFA\u8FC7\u3002\u5148\u53BB\u7CFB\u7EDF\u91CC\u770B\u90A3\u4E24\u4E2A id\u3002",
14746
+ [VERDICT_CONTRADICTS]: "\u53F0\u8D26\u8BF4\u8FD9\u4E00\u884C failed\uFF08\u8FD9\u4E00\u6863\u7684**\u627F\u8BFA**\u662F\u300C\u786E\u8BA4\u670D\u52A1\u7AEF\u4EC0\u4E48\u90FD\u6CA1\u5EFA\u300D\uFF09\uFF0C\u5E93\u91CC\u5374\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u770B\u5F97\u89C1\u4E00\u884C \u21D2 \u4E24\u4FA7\u5BF9\u4E0D\u4E0A\u3002\u{1F534} **\u8FD9\u4E2A\u300C\u5BF9\u4E0D\u4E0A\u300D\u6709\u591A\u786C\uFF0C\u53D6\u51B3\u4E8E\u90A3\u6761\u627F\u8BFA**\uFF1A\u53F0\u8D26\u7684 failed \u662F\u4ECE\u4EA7\u54C1\u7684 4xx **\u63A8\u65AD**\u51FA\u6765\u7684\uFF0C\u672C\u5DE5\u5177**\u6CA1\u6709**\u5728\u62D2\u7EDD\u4E4B\u540E\u56DE\u8BFB\u786E\u8BA4\u8FC7\u3002\u21D2 \u6700\u5E38\u89C1\u7684\u4E00\u79CD\u60C5\u5F62\u6070\u6070\u662F**\u8FD9\u4E00\u884C\u672C\u6765\u5C31\u5728**\u3001create \u56E0\u6B64\u88AB\u62D2\uFF08\u90A3\u8BF4\u660E\u8DD1\u524D\u62CD\u7684\u65E2\u5B58\u7D22\u5F15\u4E0E\u73B0\u5B9E\u4E0D\u4E00\u81F4\uFF09\uFF0C\u5176\u6B21\u624D\u662F**\u522B\u4EBA**\u5EFA\u7684\u540C\u952E\u884C\u3002**\u522B\u6025\u7740\u5220\u90A3\u4E00\u884C**\uFF1A\u5148\u53BB\u770B\u90A3\u6761 4xx \u7684\u539F\u6587\u3002",
14747
+ [VERDICT_UNATTRIBUTED]: "\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u770B\u5F97\u89C1\u4E00\u884C\uFF0C\u800C\u53F0\u8D26**\u6CA1\u6709**\u8BB0\u4E0B\u5B83\u7684 id \u21D2 \u300C\u8FD9\u4E00\u884C\u662F\u4E0D\u662F\u8FD9\u6B21\u4EA4\u4ED8\u5199\u8FDB\u53BB\u7684\u300D\u5BA2\u6237\u7AEF**\u5206\u4E0D\u51FA\u6765**\uFF08\u540C\u952E\u884C\u53EF\u80FD\u672C\u6765\u5C31\u5728\uFF0C\u4E5F\u53EF\u80FD\u662F\u522B\u4EBA\u5EFA\u7684\uFF09\u3002\u8FD9\u4E0D\u662F\u7ED3\u8BBA\uFF0C\u662F\u4E00\u5904\u5F85\u4EBA\u5224\u7684\u8D26\u3002",
14748
+ [VERDICT_INVISIBLE]: "**\u8FD9\u4E2A\u8D26\u53F7\u3001\u8FD9\u4E00\u523B**\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u67E5\u4E0D\u5230 \u2014\u2014 \u{1F534} \u8FD9**\u4E0D\u662F**\u300C\u6CA1\u5199\u8FDB\u53BB\u300D\u3002\u81F3\u5C11\u4E09\u79CD\u6210\u56E0\u5206\u4E0D\u5F00\uFF1A\u2460 \u6743\u9650\u88C1\u526A\uFF08\u53EF\u89C1\u603B\u6570\u672C\u8EAB\u5C31\u662F\u88C1\u526A\u540E\u7684\u6570\uFF09\xB7 \u2461 \u8BFB\u7684\u90A3\u4E00\u523B\u670D\u52A1\u7AEF\u4E8B\u52A1\u8FD8\u6CA1\u63D0\u4EA4 \xB7 \u2462 \u771F\u7684\u6CA1\u5199\u8FDB\u53BB\u3002\u{1F534} **\u5148\u770B\u8FD9\u4E2A\u6A21\u578B\u90A3\u4E00\u683C\u7684 visibleTotal**\uFF1A\u5B83\u662F 0 \u5C31\u8BF4\u660E**\u8FD9\u4E2A\u8D26\u53F7\u8FDE\u8FD9\u5F20\u8868\u90FD\u770B\u4E0D\u89C1**\uFF0C\u76F4\u63A5\u8D70\u2460\u3001\u522B\u5728\u2461\u4E0A\u5E72\u7B49\uFF1B\u5B83\u4E0D\u662F 0\uFF0C\u8BF4\u660E\u8868\u770B\u5F97\u89C1\u800C**\u8FD9\u4E2A\u952E**\u770B\u4E0D\u89C1\u3002\uFF08visibleTotal \u662F null \u65F6\u662F\u53E6\u4E00\u56DE\u4E8B\uFF1A\u90A3\u4E00\u6863\u7684\u5224\u5B9A\u662F unreadable\uFF0C\u4E0D\u662F\u672C\u6863\u3002\uFF09\u4E0B\u4E00\u6B65\u6709\u4E24\u6761\uFF0C**\u5206\u522B\u5BF9\u7740\u4E0D\u540C\u7684\u6210\u56E0**\uFF1A\u2460 \u6362\u4E00\u4E2A\u770B\u5F97\u89C1\u8FD9\u5F20\u8868\u7684\u8D26\u53F7\u518D\u8DD1\u4E00\u6B21\uFF0C\u4E24\u4EFD\u7ED3\u8BBA\u4E00\u8D77\u770B\uFF08\u6CBB\u2460\uFF09\uFF1B\u2461 \u9694\u4E00\u4F1A\u513F\u539F\u6837\u518D\u8DD1\u4E00\u6B21 \u2014\u2014 \u82E5\u6210\u56E0\u662F\u8BFB\u5EF6\u8FDF\uFF0C\u5B83\u4F1A\u53D8\uFF08\u6CBB\u2461\uFF09\u3002\u{1F534} \u4E24\u6761\u90FD\u505A\u5B8C\u4ECD\u7136\u67E5\u4E0D\u5230\uFF0C**\u4E5F\u8FD8\u4E0D\u662F**\u300C\u6CA1\u5199\u8FDB\u53BB\u300D\uFF1A\u90A3\u65F6\u8BE5\u62FF\u4E1A\u52A1\u952E\u53BB\u5E93\u91CC\u624B\u67E5\u4E00\u6B21\u3002",
14749
+ [VERDICT_UNREADABLE]: "\u8FD9\u4E2A\u6A21\u578B\u7684\u65E2\u5B58\u7D22\u5F15**\u6CA1\u5EFA\u6210**\uFF0C\u6240\u4EE5\u5B83\u540D\u4E0B\u6BCF\u4E00\u884C\u90FD**\u6CA1\u6709**\u5BF9\u8D26\u7ED3\u8BBA\u3002\u6210\u56E0\u539F\u6837\u8BB0\u5728\u8FD9\u4E2A\u6A21\u578B\u90A3\u4E00\u683C\u7684 problem \u91CC\uFF08\u53D6\u6570\u5931\u8D25 / \u54CD\u5E94\u5F62\u72B6\u4E0D\u5BF9 / \u4E1A\u52A1\u952E\u5728\u672C\u79DF\u6237\u4E0D\u552F\u4E00 \u2026\uFF09\u2014\u2014 \u5148\u6309\u90A3\u53E5\u8BDD\u5904\u7F6E\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002",
14750
+ [VERDICT_NOT_CHECKED]: "**\u4E00\u53D1\u8BF7\u6C42\u90FD\u6CA1\u4E3A\u5B83\u53D1\u8FC7**\uFF1A\u76D8\u4E0A\u90A3\u4EFD\u8BA1\u5212\u91CC\u95EE\u4E0D\u51FA\u8FD9\u4E2A\u6A21\u578B\u7684\u4E1A\u52A1\u952E\u5B57\u6BB5\uFF08\u53F0\u8D26\u91CC\u6709\u8FD9\u4E2A\u6A21\u578B\u3001\u8BA1\u5212\u91CC\u6CA1\u6709\uFF0C\u5178\u578B\u6210\u56E0\u662F\u4E2D\u9014\u91CD\u8DD1\u8FC7 plan\uFF09\u3002\u6CA1\u6709\u4E1A\u52A1\u952E\u5C31\u6CA1\u6709\u56DE\u8BFB\u7684\u652F\u70B9\uFF0C\u672C\u5C42\u4E0D\u731C\u4E00\u4E2A\u3002"
14751
+ };
14752
+ var PREMISE_ROWS_TO_CHECK = "journal-rows-to-check";
14753
+ var PREMISE_KEY_FIELDS = "plan-business-key-fields";
14754
+ var PREMISE_CLIENT = "client-on-hand";
14755
+ var PREMISE_IDENTITY = "readback-identity";
14756
+ var NETWORK_GATES = [PREMISE_ROWS_TO_CHECK, PREMISE_KEY_FIELDS, PREMISE_CLIENT];
14757
+ var WHY_NO_ROWS = "\u53F0\u8D26\u91CC\u4E00\u884C\u90FD\u6CA1\u6709 \u21D2 **\u6CA1\u6709\u4EFB\u4F55\u4E00\u884C\u53EF\u4EE5\u62FF\u53BB\u548C\u5E93\u91CC\u5BF9**\uFF0C\u672C\u5C42\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\u3002\u4E0B\u9762\u539F\u6837\u8F6C\u8F7D\u7B2C\u4E00\u5C42\u90A3\u51E0\u6761\u4E0D\u6210\u7ACB\u7684\u524D\u63D0 \u2014\u2014 \u300C\u96F6\u884C\u300D\u7684\u6210\u56E0\u4E0D\u6B62\u4E00\u79CD\uFF0C\u672C\u5C42**\u4E0D\u628A\u5B83\u4EEC\u5408\u6210\u4E00\u53E5**\u3002";
14758
+ var WHY_NO_KEY_FIELDS = "\u76D8\u4E0A\u90A3\u4EFD\u8BA1\u5212\u8BFB\u4E0D\u56DE\u6765 \u21D2 **\u95EE\u4E0D\u51FA\u4E1A\u52A1\u952E\u5B57\u6BB5\u540D**\uFF0C\u800C\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB\u662F\u672C\u5C42\u552F\u4E00\u7684\u652F\u70B9\uFF08\u4EA7\u54C1\u7684\u884C\u4E0A\u6CA1\u6709\u3001\u4E5F\u4E0D\u8BB8\u6709\u4EFB\u4F55\u672C\u5DE5\u5177\u7684\u6807\u8BB0\uFF09\u3002\u21D2 \u8FD9\u4E00\u95EE**\u6CA1\u6709\u7B54\u6848**\uFF0C\u672C\u5C42\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF0C\u9010\u6761\u90A3\u51E0\u683C\u7ED9\u7684\u662F null \u800C\u4E0D\u662F\u7A7A\u8868\u3002";
14759
+ var WHY_NO_CLIENT = "\u624B\u4E0A\u6CA1\u6709\u5BA2\u6237\u7AEF \u21D2 **\u5BF9\u4E0D\u4E86\u8D26**\u3002\u5E93\u91CC\u73B0\u5728\u957F\u4EC0\u4E48\u6837\uFF0C\u76D8\u4E0A\u4EFB\u4F55\u4E00\u4EFD\u4EA7\u7269\u90FD\u7B54\u4E0D\u4E86\uFF1A\u53F0\u8D26\u81EA\u5DF1\u7684 serverId \u4E0E\u8D26\u672C\u540C\u6E90\uFF08\u62FF\u5B83\u5F53\u53E6\u4E00\u4FA7\u662F\u81EA\u8BC1\uFF09\u3001\u8BA1\u5212\u91CC\u7684 existingId \u662F**\u8DD1\u4E4B\u524D**\u90A3\u4E00\u523B\u7684\u5FEB\u7167\u3001apply \u7684\u62A5\u544A\u4ECE\u4E0D\u843D\u76D8\u3002\u{1F534} **\u8FD9\u6761\u51FA\u8DEF\u5728\u6C14\u9699\u673A\u5668\u4E0A\u8D70\u4E0D\u901A** \u2014\u2014 \u672C\u5C42\u4E0D\u5047\u88C5\u8FD8\u6709\u522B\u7684\u8DEF\uFF0C\u4E5F**\u4E0D**\u4EA7\u51FA\u4E00\u4EFD\u300C\u5BF9\u8D26\u901A\u8FC7\u300D\u3002";
14760
+ var WHY_NO_IDENTITY = {
14761
+ false: "**\u4E0D\u77E5\u9053\u8FD9\u4E00\u4EFD\u662F\u7528\u8C01\u7684\u8EAB\u4EFD\u8BFB\u7684**\uFF1A\u672C\u5DE5\u5177**\u6CA1\u6709\u7ECF\u624B\u8FD9\u6B21\u767B\u5F55**\uFF08\u624B\u4E0A\u662F\u522B\u5904\u7ED9\u7684 token\uFF09\u3002\u53EF\u89C1\u8303\u56F4\u968F\u89D2\u8272\u53D8\uFF0C\u800C\u300C\u67E5\u4E0D\u5230\u300D\u8FD9\u4E00\u6863\u7684\u7B2C\u4E00\u79CD\u6210\u56E0\u6B63\u662F\u6743\u9650\u88C1\u526A \u21D2 \u8FD9\u4EFD\u5BF9\u8D26**\u8BF4\u4E0D\u51FA\u81EA\u5DF1\u7684\u53E3\u5F84**\u3002\u4E0B\u4E00\u6B65\uFF1A\u7528\u672C\u5DE5\u5177\u81EA\u5DF1\u7684\u767B\u5F55\u8DD1\u4E00\u6B21\u3002",
14762
+ true: "**\u670D\u52A1\u7AEF\u6CA1\u5728\u54CD\u5E94\u91CC\u7ED9 user**\uFF1A\u767B\u5F55**\u7ECF\u624B\u8FC7**\uFF08\u672C\u5DE5\u5177\u586B\u7684 requestedTenantId \u8FD8\u5728\uFF09\uFF0C\u4F46 tenantId / username / roles \u5168\u662F\u7A7A\u7684 \u2014\u2014 \u8FD9\u4EFD\u5BF9\u8D26**\u8BF4\u4E0D\u51FA\u662F\u8C01\u8DD1\u7684**\u3002\u{1F534} \u5C24\u5176\u522B\u628A\u7A7A\u7684 roles \u8BFB\u6210\u300C\u8FD9\u4E2A\u8D26\u53F7\u4EC0\u4E48\u90FD\u770B\u4E0D\u89C1\u300D\uFF1A\u90A3\u662F**\u6CA1\u62FF\u5230**\uFF0C\u4E0D\u662F**\u770B\u5230\u4E86\u7A7A\u7684**\u3002\u21D2 \u5BF9\u8D26\u7167\u6837\u8DD1\u5F97\u5B8C\uFF0C\u4F46\u6362\u4E2A\u4EBA\u590D\u6838\u65F6\u65E0\u4ECE\u6BD4\u5BF9\u4E24\u4EFD\u4E3A\u4EC0\u4E48\u4E0D\u4E00\u6837\u3002\u4E0B\u4E00\u6B65\uFF1A\u53BB\u95EE\u670D\u52A1\u7AEF\u4E3A\u4EC0\u4E48\u4E0D\u7ED9 user\uFF0C**\u4E0D\u662F**\u91CD\u767B\uFF08\u91CD\u767B\u6CBB\u7684\u662F\u4E0A\u9762\u90A3\u4E00\u6863\uFF09\u3002"
14763
+ };
14764
+ var NOT_COVERED2 = [
14765
+ "\u672C\u5C42\u53EA\u5BF9**\u53F0\u8D26\u91CC\u6709\u8BB0\u5F55**\u7684\u90A3\u4E9B\u884C\u3002\u300C\u8BA1\u5212\u91CC\u6709\u3001\u53F0\u8D26\u91CC\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709\u300D\u90A3\u4E00\u8F74\u5728\u7B2C\u4E00\u5C42\uFF08plannedWithoutRecord\uFF09\u2014\u2014 \u90A3\u4E9B\u884C\u672C\u5C42**\u4E00\u6B21\u90FD\u6CA1\u6709\u56DE\u8BFB\u8FC7**\uFF0C\u5B83\u4EEC\u6B64\u523B\u5728\u4E0D\u5728\u5E93\u91CC\uFF0C\u8FD9\u4EFD\u5BF9\u8D26\u8BF4\u4E0D\u51FA\u6765\u3002",
14766
+ "\u5BF9\u8D26**\u53EA\u5BF9\u8EAB\u4EFD\u3001\u4E0D\u6BD4\u5B57\u6BB5**\uFF1A\u6309\u8FD9\u4E2A\u4E1A\u52A1\u952E\u770B\u5F97\u89C1\u4E00\u884C\u3001\u4E14 id \u4E0E\u8D26\u672C\u8BB0\u7684\u76F8\u540C\uFF0C\u53EA\u8BF4\u660E**\u90A3\u4E00\u884C\u5728**\uFF0C**\u4E0D\u8BF4\u660E**\u5B83\u7684\u5B57\u6BB5\u503C\u4E0E\u6E90\u8868\u4E00\u81F4 \u2014\u2014 \u6709\u4EBA\u540E\u6765\u6539\u8FC7\u5B83\uFF0C\u672C\u5C42\u770B\u4E0D\u89C1\u3002",
14767
+ "\u540C\u4E00\u4E2A\u4E1A\u52A1\u952E\u5728\u5E93\u91CC\u6709**\u591A\u884C**\u65F6\uFF0C\u672C\u5C42**\u4E0D\u662F\u884C\u7EA7\u5224\u5B9A**\uFF1A\u6279\u91CF\u7D22\u5F15\u628A\u5B83\u538B\u6210\u6574\u4E2A\u6A21\u578B\u7684\u524D\u63D0\u5931\u8D25\uFF08key-count-mismatch\uFF09\uFF0C\u90A3\u4E2A\u6A21\u578B\u540D\u4E0B\u6BCF\u4E00\u884C\u843D unreadable\u3002\u{1F534} \u672C\u5C42**\u4E0D\u9000\u5316\u6210\u9010\u884C\u56DE\u8BFB**\uFF1A\u90A3\u4F1A\u9020\u51FA\u7B2C\u4E8C\u4E2A\u771F\u76F8\u6E90\uFF08\u4E24\u6761\u901A\u9053\u7684\u5B8C\u6574\u6027\u524D\u63D0\u4E0D\u540C\uFF09\u3002\u26A0\uFE0F \u90A3\u6761\u7ECF\u6D4E\u6027\u8BBA\u8BC1**\u6709\u524D\u63D0**\uFF0C\u522B\u5F53\u6210\u65E0\u6761\u4EF6\u7684\uFF1A\u300C\u9010\u884C 17396 \u53D1 \u224858 \u5206\u949F vs \u6279\u91CF 10 \u53D1 \u224822s\u300D\u6210\u7ACB\u4E8E**\u4EA4\u4ED8\u8986\u76D6\u6574\u5F20\u8868**\u7684\u573A\u666F\uFF08\u521D\u6B21\u5EFA\u5E93\u5BFC\u5165\uFF0C\u672C\u5DE5\u5177\u7684\u4E3B\u573A\u666F\uFF09\uFF1B\u8868 20 \u4E07\u884C\u800C\u8FD9\u4E00\u8F6E\u53EA\u52A8 5 \u884C\u65F6\u5B83**\u53CD\u8FC7\u6765** \u2014\u2014 \u6279\u91CF\u8981 100 \u53D1\u8BF7\u6C42 + 20 \u4E07\u884C\u8FC7\u7EBF\uFF0C\u9010\u884C\u53EA\u8981 5 \u53D1\uFF08\u4EE3\u4EF7\u4ECD\u5728\u53EF\u63A5\u53D7\u533A\u95F4\uFF0C\u6545\u5B9E\u73B0\u4E0D\u53D8\uFF09\u3002",
14768
+ "\u300C\u6070\u597D\u770B\u5F97\u89C1\u4E00\u884C\u300D\u4E5F\u53EF\u80FD\u662F**\u522B\u4EBA**\u5EFA\u7684\u540C\u952E\u884C \u2014\u2014 \u5BA2\u6237\u7AEF\u5206\u4E0D\u51FA\u6765\u3002\u6240\u4EE5 confirmed \u8BF4\u7684\u662F\u300C\u6309\u8FD9\u4E2A\u952E\u770B\u5F97\u89C1\u4E00\u884C\u3001\u4E14 id \u4E0E\u8D26\u672C\u8BB0\u7684\u76F8\u540C\u300D\uFF0C\u4EC5\u6B64\u800C\u5DF2\u3002",
14769
+ "\u7ED3\u8BBA\u53EA\u662F**\u8BFB\u7684\u90A3\u4E00\u523B**\u7684\u4E8B\u5B9E\uFF1A\u8FD9\u4E00\u4EFD\u5BF9\u8D26\u8DD1\u5B8C\u4E4B\u540E\u6709\u4EBA\u518D\u52A8\u5E93\uFF0C\u5B83\u5C31\u8FC7\u671F\u4E86\uFF1B\u800C\u672C\u5C42**\u6CA1\u6709**\u4EFB\u4F55\u673A\u5236\u80FD\u53D1\u73B0\u90A3\u4EF6\u4E8B\u3002",
14770
+ "contradicts \u7684\u5F3A\u5EA6**\u53D7\u9650\u4E8E\u53F0\u8D26 failed \u90A3\u6761\u672A\u7ECF\u67E5\u8BC1\u7684\u63A8\u65AD**\uFF1A\u5199 failed \u7684\u552F\u4E00\u90A3\u5904\u81EA\u5DF1\u5199\u7740\u300C4xx \u21D2 \u4EC0\u4E48\u90FD\u6CA1\u5EFA\u300D\u662F**\u63A8\u65AD**\u3001\u62D2\u7EDD\u4E4B\u540E**\u6CA1\u6709\u56DE\u8BFB\u786E\u8BA4\u8FC7**\u3002\u21D2 \u8FD9\u4E00\u6863\u8BF4\u7684\u662F\u300C\u4EA7\u54C1\u62D2\u4E86\u5B83\uFF0C\u800C\u8FD9\u4E2A\u952E\u6B64\u523B\u770B\u5F97\u89C1\u300D\uFF0C**\u4E0D\u662F**\u300C\u670D\u52A1\u7AEF\u786E\u5B9E\u4EC0\u4E48\u90FD\u6CA1\u5EFA\u3001\u5374\u53C8\u6709\u4E00\u884C\u300D\u3002\u6700\u5E38\u89C1\u7684\u4E00\u79CD\u5C31\u662F\u8FD9\u4E00\u884C\u672C\u6765\u5C31\u5728\u3001create \u56E0\u6B64\u88AB\u62D2 \u2014\u2014 \u90A3\u662F**\u7D22\u5F15\u8FC7\u671F**\uFF0C\u4E0D\u662F\u77DB\u76FE\u3002",
14771
+ "\u53F0\u8D26\u72B6\u6001\u662F quarantined \u7684\u884C**\u4F1A\u843D\u8FDB\u300C\u5BF9\u5F97\u4E0A\u300D\u90A3\u5F20\u67B6\u5B50**\uFF08\u5B83\u5E26\u7740 serverId\uFF0C\u56DE\u8BFB\u53C8\u786E\u8BA4\u8FD9\u4E2A\u952E\u5728\uFF09\u3002\u26A0\uFE0F \u53F0\u8D26\u90A3\u4E00\u6863\u7684\u4E0B\u4E00\u6B65\u662F\u300C\u505C\u4E0B\u6765\u70B9\u540D\u8981\u4EBA\u300D\uFF0C\u7406\u7531\u662F\u670D\u52A1\u7AEF**\u53EF\u80FD\u6709\u4E00\u6761\u522B\u7684\u952E\u7684\u91CE\u884C** \u2014\u2014 \u800C\u672C\u5C42\u6309\u4E1A\u52A1\u952E\u56DE\u8BFB\uFF0C**\u6E05\u4E0D\u6389\u90A3\u4E2A\u5ACC\u7591**\u3002\u21D2 \u7B7E\u5B57\u524D\u628A\u8FD9\u4E9B\u884C\u5355\u72EC\u6311\u51FA\u6765\u770B\uFF0C\u522B\u53EA\u770B\u67B6\u5B50\u3002",
14772
+ "\u53EF\u89C1\u603B\u6570\uFF08visibleTotal\uFF09\u662F**\u88C1\u526A\u540E**\u7684\u6570\uFF1A\u67E5\u8BE2\u5F15\u64CE\u5148\u6CE8\u5165\u6743\u9650\u8FC7\u6EE4\u518D\u5206\u9875\u4E0E\u8BA1\u6570\u3002\u21D2 \u5B83\u8BF4\u7684\u662F\u300C**\u8FD9\u4E2A\u8D26\u53F7**\u770B\u5F97\u89C1\u51E0\u884C\u300D\uFF0C**\u4E0D\u662F**\u300C\u8FD9\u5F20\u8868\u6709\u51E0\u884C\u300D\u2014\u2014\u4E24\u8005\u5728\u540C\u4E00\u4E2A\u6570\u4E0A\u540C\u5F62\uFF0C\u522B\u5F53\u6210\u540E\u8005\u53BB\u548C\u6E90\u8868\u7684\u884C\u6570\u5BF9\u3002"
14773
+ ];
14774
+ function isObject2(v) {
14775
+ return v !== null && typeof v === "object" && !Array.isArray(v);
14776
+ }
14777
+ function identityKnown(identity) {
14778
+ return isObject2(identity) && String(identity["tenantId"] ?? "").trim().length > 0;
14779
+ }
14780
+ function rowsWhy(delivery) {
14781
+ const upstream = delivery.premises.filter(
14782
+ (p) => (p.code === PREMISE_JOURNAL_ON_DISK || p.code === PREMISE_JOURNAL_HAS_ENTRIES) && !p.ok
14783
+ ).map((p) => p.detail);
14784
+ return [WHY_NO_ROWS, ...upstream].join("\n");
14785
+ }
14786
+ function keyFieldsOf(delivery) {
14787
+ const upstream = delivery.premises.filter((p) => p.code === PREMISE_PLAN_READABLE);
14788
+ if (upstream.length > 0 && !upstream[0].ok) {
14789
+ return [
14790
+ /* @__PURE__ */ new Map(),
14791
+ premise(
14792
+ PREMISE_KEY_FIELDS,
14793
+ false,
14794
+ `${WHY_NO_KEY_FIELDS}
14795
+ ${upstream[0].detail}`,
14796
+ upstream[0].hint
14797
+ )
14798
+ ];
14799
+ }
14800
+ try {
14801
+ const plan = readImportPlan(delivery.workDir);
14802
+ const table = /* @__PURE__ */ new Map();
14803
+ for (const m of plan.models) {
14804
+ if (m.businessKeyFields.length > 0) table.set(m.model, [...m.businessKeyFields]);
14805
+ }
14806
+ return [table, premise(PREMISE_KEY_FIELDS, true, WHY_NO_KEY_FIELDS)];
14807
+ } catch (raw) {
14808
+ if (!(raw instanceof PlanReadError)) throw raw;
14809
+ return [
14810
+ /* @__PURE__ */ new Map(),
14811
+ premise(
14812
+ PREMISE_KEY_FIELDS,
14813
+ false,
14814
+ `${WHY_NO_KEY_FIELDS}\uFF08[${raw.reason}] ${raw.detail}\uFF09`,
14815
+ raw.hint
14816
+ )
14817
+ ];
14818
+ }
14819
+ }
14820
+ function modelsInOrder(rows) {
14821
+ return [...new Set(rows.map((r) => r.model))];
14822
+ }
14823
+ function verdictOf(row, readback, index) {
14824
+ if (readback.keyFields === null) return [VERDICT_NOT_CHECKED, null];
14825
+ if (index === void 0) return [VERDICT_UNREADABLE, null];
14826
+ const found = index.rows.get(encodeKeyTuple([...row.businessKey]));
14827
+ if (found === void 0) {
14828
+ return [VERDICT_INVISIBLE, null];
14829
+ }
14830
+ if (row.status === STATUS_FAILED) {
14831
+ return [VERDICT_CONTRADICTS, found];
14832
+ }
14833
+ if (row.serverId === null) return [VERDICT_UNATTRIBUTED, found];
14834
+ if (found === row.serverId) return [VERDICT_CONFIRMED, found];
14835
+ return [VERDICT_ID_DIFFERS, found];
14836
+ }
14837
+ function judge(row, readback, index) {
14838
+ const [verdict, serverNow] = verdictOf(row, readback, index);
14839
+ return {
14840
+ sourceRowId: row.sourceRowId,
14841
+ model: row.model,
14842
+ businessKey: [...row.businessKey],
14843
+ ledgerStatus: row.status,
14844
+ ledgerServerId: row.serverId,
14845
+ serverNow,
14846
+ verdict
14847
+ };
14848
+ }
14849
+ async function buildReconciliation(delivery, client) {
14850
+ const premises = [
14851
+ premise(PREMISE_ROWS_TO_CHECK, delivery.rows.length > 0, rowsWhy(delivery))
14852
+ ];
14853
+ const [keyFieldsByModel, keyPremise] = keyFieldsOf(delivery);
14854
+ premises.push(keyPremise);
14855
+ premises.push(premise(PREMISE_CLIENT, client !== null, WHY_NO_CLIENT));
14856
+ const identity = client === null ? null : client.identity ?? null;
14857
+ premises.push(
14858
+ premise(
14859
+ PREMISE_IDENTITY,
14860
+ identityKnown(identity),
14861
+ WHY_NO_IDENTITY[isObject2(identity) ? "true" : "false"]
14862
+ )
14863
+ );
14864
+ const known = isObject2(identity) ? identity : null;
14865
+ const blocked = premises.filter(
14866
+ (p) => NETWORK_GATES.includes(p.code) && !p.ok
14867
+ );
14868
+ if (blocked.length > 0) {
14869
+ return {
14870
+ workDir: delivery.workDir,
14871
+ label: delivery.label,
14872
+ identity: known,
14873
+ findings: null,
14874
+ byVerdict: null,
14875
+ differences: null,
14876
+ undecided: null,
14877
+ models: null,
14878
+ premises,
14879
+ notCovered: NOT_COVERED2,
14880
+ verdictWords: VERDICT_WORDS
14881
+ };
14882
+ }
14883
+ const models = [];
14884
+ const indexes = /* @__PURE__ */ new Map();
14885
+ for (const model of modelsInOrder(delivery.rows)) {
14886
+ const keyFields = keyFieldsByModel.get(model);
14887
+ if (keyFields === void 0 || keyFields.length === 0) {
14888
+ models.push({ model, keyFields: null, visibleTotal: null, pages: null, problem: null });
14889
+ continue;
14890
+ }
14891
+ try {
14892
+ const index = await loadKeyIndex(client, model, keyFields);
14893
+ indexes.set(model, index);
14894
+ models.push({
14895
+ model,
14896
+ keyFields: [...keyFields],
14897
+ visibleTotal: index.total,
14898
+ pages: index.pages,
14899
+ problem: null
14900
+ });
14901
+ } catch (raw) {
14902
+ if (!(raw instanceof IndexPremiseError)) throw raw;
14903
+ models.push({
14904
+ model,
14905
+ keyFields: [...keyFields],
14906
+ visibleTotal: null,
14907
+ pages: null,
14908
+ problem: `[${raw.reason}] ${raw.detail} \u2014\u2014 ${raw.hint || "\u5148\u628A\u8FD9\u6761\u89E3\u51B3\u518D\u8DD1\u4E00\u6B21\u5BF9\u8D26"}`
14909
+ });
14910
+ }
14911
+ }
14912
+ const byModel = new Map(models.map((m) => [m.model, m]));
14913
+ const findings = delivery.rows.map((row) => judge(row, byModel.get(row.model), indexes.get(row.model)));
14914
+ const byVerdict = Object.fromEntries(VERDICTS2.map((v) => [v, 0]));
14915
+ for (const f of findings) byVerdict[f.verdict] = (byVerdict[f.verdict] ?? 0) + 1;
14916
+ return {
14917
+ workDir: delivery.workDir,
14918
+ label: delivery.label,
14919
+ identity: known,
14920
+ findings,
14921
+ byVerdict,
14922
+ differences: findings.filter((f) => DIFFERENCE_VERDICTS.includes(f.verdict)),
14923
+ undecided: findings.filter((f) => UNDECIDED_VERDICTS.includes(f.verdict)),
14924
+ models,
14925
+ premises,
14926
+ notCovered: NOT_COVERED2,
14927
+ verdictWords: VERDICT_WORDS
14928
+ };
14929
+ }
14930
+ function notAsked(delivery) {
14931
+ return {
14932
+ workDir: delivery.workDir,
14933
+ label: delivery.label,
14934
+ identity: null,
14935
+ findings: null,
14936
+ byVerdict: null,
14937
+ differences: null,
14938
+ undecided: null,
14939
+ models: null,
14940
+ premises: [],
14941
+ // 🔴 **更长的那一份**:把「库里现在怎么样,这一趟一个字都没问」逐字带上。
14942
+ notCovered: [...NOT_COVERED2, WHY_NO_CLIENT],
14943
+ verdictWords: VERDICT_WORDS
14944
+ };
14945
+ }
14946
+ function shelfPartition() {
14947
+ const domain = new Set(VERDICTS2);
14948
+ const shelves = [AGREEING_VERDICTS, DIFFERENCE_VERDICTS, UNDECIDED_VERDICTS];
14949
+ const union = new Set(shelves.flatMap((s) => [...s]));
14950
+ const seen = /* @__PURE__ */ new Map();
14951
+ for (const shelf of shelves) for (const v of shelf) seen.set(v, (seen.get(v) ?? 0) + 1);
14952
+ return {
14953
+ missing: [...domain].filter((v) => !union.has(v)).sort(),
14954
+ extra: [...union].filter((v) => !domain.has(v)).sort(),
14955
+ overlap: [...seen.entries()].filter(([, n]) => n > 1).map(([v]) => v).sort()
14956
+ };
14957
+ }
14958
+
14959
+ // src/fde/verify/face.ts
14960
+ var LEDGER_ONLY_FLAG = "--ledger-only";
14961
+ var NOT_COVERED_SELF = "\u5DF2\u77E5\u4E0D\u8986\u76D6 \xB7 \u672C\u547D\u4EE4";
14962
+ var NOT_COVERED_LAYER1 = "\u5DF2\u77E5\u4E0D\u8986\u76D6 \xB7 \u7B2C\u4E00\u5C42";
14963
+ var NOT_COVERED_LAYER2 = "\u5DF2\u77E5\u4E0D\u8986\u76D6 \xB7 \u7B2C\u4E8C\u5C42";
14964
+ function ledgerOnlySignpost(cmd) {
14965
+ if (cmd !== "verify") return "";
14966
+ return `
14967
+ \u2192 \u8FD9\u53F0\u673A\u5668\u8FDE\u4E0D\u4E0A\u5BA2\u6237\u5185\u7F51\u65F6\uFF0C\u7528 \`seed verify ${LEDGER_ONLY_FLAG}\`\uFF1A\u5B83\u53EA\u51FA**\u53F0\u8D26\u90A3\u4E00\u5C42**\uFF08\u96F6\u7F51\u7EDC\uFF0C\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\uFF1B**\u5E93\u91CC\u73B0\u5728\u600E\u4E48\u6837\uFF0C\u90A3\u4E00\u8D9F\u4E00\u4E2A\u5B57\u90FD\u6CA1\u95EE** \u2014\u2014 \u5BF9\u8D26\u8FD9\u4E00\u95EE\u5728\u8FD9\u53F0\u673A\u5668\u4E0A\u6CA1\u6709\u7B54\u6848\uFF0C\u522B\u62FF\u5B83\u5F53\u9A8C\u6536\u901A\u8FC7\u3002`;
14968
+ }
14969
+ function isZeroNetwork(args) {
14970
+ return args.ledgerOnly === true;
14971
+ }
14972
+ function askedTheDatabase(recon) {
14973
+ return recon.premises.length > 0;
14974
+ }
14975
+ function indent(text2) {
14976
+ return text2.split("\n").join("\n ");
14977
+ }
14978
+ function verifyAttention(delivery, recon) {
14979
+ const agreeing = new Set(AGREEING_VERDICTS);
14980
+ return [
14981
+ delivery.rows.filter((row) => NEXT_STEP[row.status] !== STEP_NOTHING),
14982
+ [...delivery.plannedWithoutRecord ?? []],
14983
+ (recon.findings ?? []).filter((f) => !agreeing.has(f.verdict))
14984
+ ];
14985
+ }
14986
+ function premiseLines(lines, title, premises) {
14987
+ lines.push(`[${title}]`);
14988
+ for (const item of premises) {
14989
+ lines.push(
14990
+ ` [${item.ok ? "\u6210\u7ACB " : "\u672A\u6210\u7ACB"}] ${item.code}` + (item.ok ? "" : `\uFF1A${indent(item.detail)}`)
14991
+ );
14992
+ if (item.hint) lines.push(" \u2192 " + indent(item.hint));
14993
+ }
14994
+ }
14995
+ function reconciliationLines(recon, findings) {
14996
+ const lines = [];
14997
+ if (!askedTheDatabase(recon)) {
14998
+ lines.push("[\u5BF9\u8D26] **\u8FD9\u4E00\u8D9F\u6CA1\u95EE\u8FC7\u5E93** \u2014\u2014 \u672C\u547D\u4EE4\u53EA\u51FA\u4E86\u53F0\u8D26\u90A3\u4E00\u5C42\u3002");
14999
+ lines.push(" \u5224\u5B9A\u9010\u6863 / \u4E09\u5F20\u67B6\u5B50 / \u9010\u6863\u4EBA\u8BDD**\u90FD\u4E0D\u5728\u8FD9\u9875\u7EB8\u4E0A**\uFF1A\u5B83\u4EEC\u53EA\u6709\u771F\u56DE\u8BFB\u8FC7\u624D\u4EA7\u5F97\u51FA\u3002");
15000
+ lines.push(
15001
+ ` \u26A0\uFE0F \u8FD9**\u4E0D\u662F**\u300C\u67E5\u8FC7\u3001\u4E00\u6761\u5DEE\u5F02\u90FD\u6CA1\u6709\u300D\u3002\u300C\u5E93\u91CC\u73B0\u5728\u600E\u4E48\u6837\u300D\u8FD9\u4E00\u95EE\u7684\u4E0B\u573A\uFF0C\u9010\u5B57\u5199\u5728\u4E0B\u9762\u90A3\u4EFD\u300C${NOT_COVERED_LAYER2}\u300D\u7684\u6700\u540E\u4E00\u6761\u91CC\u3002`
15002
+ );
15003
+ return lines;
15004
+ }
15005
+ premiseLines(lines, "\u7B2C\u4E8C\u5C42 \xB7 \u5BF9\u8D26\uFF08\u8D26\u672C\u8BF4\u7684 vs \u5E93\u91CC\u73B0\u5728\u7684\uFF09", recon.premises);
15006
+ if (recon.identity === null || recon.identity === void 0) {
15007
+ lines.push(" \u8EAB\u4EFD\uFF1A**\u8FD9\u4E00\u4EFD\u8BF4\u4E0D\u51FA\u662F\u7528\u8C01\u7684\u8EAB\u4EFD\u8BFB\u7684** \u2014\u2014 \u53EF\u89C1\u8303\u56F4\u968F\u89D2\u8272\u53D8\u3002");
15008
+ } else {
15009
+ lines.push(` \u8EAB\u4EFD\uFF1A${JSON.stringify(recon.identity)}`);
15010
+ }
15011
+ if (recon.findings === null) {
15012
+ lines.push(
15013
+ "[\u5BF9\u8D26] **\u8FD9\u4E00\u95EE\u6CA1\u6709\u7B54\u6848** \u2014\u2014 \u4E0A\u9762\u90A3\u6761\u672A\u6210\u7ACB\u7684\u524D\u63D0\u8BF4\u4E86\u4E3A\u4EC0\u4E48\uFF1B\u9010\u6761\u90A3\u51E0\u683C\u7ED9\u7684\u662F\u300C\u6CA1\u6709\u7B54\u6848\u300D\uFF0C**\u4E0D\u662F**\u300C\u67E5\u8FC7\u3001\u4E00\u6761\u5DEE\u5F02\u90FD\u6CA1\u6709\u300D\u3002"
15014
+ );
15015
+ return lines;
15016
+ }
15017
+ if (recon.byVerdict === null || recon.models === null || recon.verdictWords === null) {
15018
+ throw new TypeError(
15019
+ "reconcile \u7684\u4E94\u4E2A\u7B54\u6848\u683C\u6CA1\u6709\u540C\u751F\u540C\u6B7B\uFF1Afindings \u6709\u503C\u800C " + [
15020
+ recon.byVerdict === null ? "byVerdict" : null,
15021
+ recon.models === null ? "models" : null,
15022
+ recon.verdictWords === null ? "verdictWords" : null
15023
+ ].filter(Boolean).join("\u3001") + " \u662F null \u2014\u2014 \u8FD9\u662F\u5F15\u64CE\u7684\u4E0D\u53D8\u91CF\uFF0C\u6E32\u67D3\u5C42\u4E0D\u66FF\u5B83\u515C\u5E95"
15024
+ );
15025
+ }
15026
+ lines.push("[\u5BF9\u8D26] \u9010\u4E2A\u6A21\u578B\u56DE\u8BFB\u5230\u4E86\u4EC0\u4E48\uFF1A");
15027
+ for (const model of recon.models) {
15028
+ lines.push(
15029
+ ` \xB7 ${model.model} \u4E1A\u52A1\u952E\u5B57\u6BB5=${model.keyFields && model.keyFields.length ? JSON.stringify(model.keyFields) : "\uFF08\u8BA1\u5212\u91CC\u95EE\u4E0D\u51FA\uFF09"} \u53EF\u89C1\u603B\u6570=${model.visibleTotal === null ? "\uFF08\u6CA1\u5EFA\u6210\u7D22\u5F15\uFF09" : model.visibleTotal} \u53D6\u6570\u8BF7\u6C42=${model.pages === null ? "\uFF08\u6CA1\u53D1\u8FC7\uFF09" : model.pages} ${model.problem ?? ""}`.trimEnd()
15030
+ );
15031
+ }
15032
+ lines.push(" \u26A0\uFE0F \u53EF\u89C1\u603B\u6570\u662F**\u88C1\u526A\u540E**\u7684\u6570\uFF08\u67E5\u8BE2\u5F15\u64CE\u5148\u6CE8\u5165\u6743\u9650\u8FC7\u6EE4\u518D\u8BA1\u6570\uFF09\uFF0C\u5B83\u8BF4\u7684\u662F\u300C\u8FD9\u4E2A\u8D26\u53F7\u770B\u5F97\u89C1\u51E0\u884C\u300D\u3002");
15033
+ lines.push(` \u5224\u5B9A\u9010\u6863\uFF08\u5171 ${recon.findings.length} \u884C\uFF09\uFF1A`);
15034
+ for (const [verdict, count] of Object.entries(recon.byVerdict)) {
15035
+ lines.push(` \xB7 ${verdict}\uFF1A${count} \u884C`);
15036
+ }
15037
+ lines.push(" \u6709\u884C\u843D\u8FDB\u53BB\u7684\u6BCF\u4E00\u6863\uFF0C\u9010\u6863\u8BF4\u6E05\u5B83\u662F\u4EC0\u4E48\u610F\u601D\uFF1A");
15038
+ for (const [verdict, count] of Object.entries(recon.byVerdict)) {
15039
+ if (!count) continue;
15040
+ lines.push(` \xB7 ${verdict}\uFF1A${recon.verdictWords[verdict]}`);
15041
+ }
15042
+ lines.push(` \u8981\u4EBA\u770B\u7684 ${findings.length} \u884C\uFF08\u5224\u5B9A\u4E0D\u843D\u5728\u300C\u5BF9\u5F97\u4E0A\u300D\u90A3\u5F20\u67B6\u5B50\u4E0A\u7684\uFF09${findings.length ? "\uFF1A" : "\u3002"}`);
15043
+ for (const f of findings) {
15044
+ lines.push(
15045
+ ` - ${f.model} ${JSON.stringify(f.businessKey)} \u8D26\u672C\u8BF4 ${f.ledgerStatus} / \u5E93\u91CC\u73B0\u5728 ${f.serverNow || "\uFF08\u6CA1\u8BFB\u56DE\u503C \u2014\u2014 \u662F\u54EA\u4E00\u79CD\u770B\u53F3\u8FB9\u7684\u5224\u5B9A\uFF09"} \u21D2 ${f.verdict}`
15046
+ );
15047
+ }
15048
+ return lines;
15049
+ }
15050
+ function verifyText(delivery, recon) {
15051
+ const lines = [
15052
+ `\u4EA4\u4ED8\u8BC1\u636E\u94FE${askedTheDatabase(recon) ? "" : "\uFF08**\u4EC5\u53F0\u8D26\u90A3\u4E00\u5C42 \xB7 \u8FD9\u4E00\u8D9F\u6CA1\u95EE\u8FC7\u5E93**\uFF09"}\uFF1A${delivery.label}`
15053
+ ];
15054
+ premiseLines(lines, "\u7B2C\u4E00\u5C42 \xB7 \u53F0\u8D26\u4E0E\u8BA1\u5212\uFF08\u96F6\u7F51\u7EDC\uFF09", delivery.premises);
15055
+ lines.push(`[\u53F0\u8D26] **\u53F0\u8D26\u53E3\u5F84 \xB7 \u5386\u8F6E\u7D2F\u8BA1**\uFF08\u540C\u4E00\u4E2A\u4E1A\u52A1\u952E\u6700\u540E\u4E00\u6761\u8D62\uFF09\uFF0C\u5171 ${delivery.rows.length} \u884C`);
15056
+ for (const [status, count] of Object.entries(delivery.byStatus)) {
15057
+ lines.push(` \xB7 ${status}\uFF1A${count} \u884C`);
15058
+ }
15059
+ const [rows, planned, findings] = verifyAttention(delivery, recon);
15060
+ lines.push(` \u8981\u4EBA\u770B\u7684 ${rows.length} \u884C\uFF08\u4E0B\u4E00\u6B65\u4E0D\u662F\u300C\u4E0D\u5FC5\u518D\u52A8\u300D\u7684\u90A3\u4E9B\uFF09${rows.length ? "\uFF1A" : "\u3002"}`);
15061
+ for (const row of rows) {
15062
+ lines.push(
15063
+ ` - ${row.model} ${JSON.stringify(row.businessKey)} status=${row.status} \u4E0B\u4E00\u6B65=${NEXT_STEP[row.status]}`
15064
+ );
15065
+ }
15066
+ if (delivery.plannedWithoutRecord === null) {
15067
+ lines.push(
15068
+ "[\u8BA1\u5212\u91CC\u6709\u3001\u53F0\u8D26\u91CC\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709] **\u8FD9\u4E00\u95EE\u6CA1\u6709\u7B54\u6848** \u2014\u2014 \u89C1\u4E0A\u9762\u90A3\u6761\u672A\u6210\u7ACB\u7684\u524D\u63D0\u3002\u26A0\uFE0F \u8FD9\u4E00\u683C**\u4E0D\u662F**\u300C\u4E00\u4EF6\u6CA1\u843D\u4E0B\u300D\u3002"
15069
+ );
15070
+ } else {
15071
+ lines.push(
15072
+ `[\u8BA1\u5212\u91CC\u6709\u3001\u53F0\u8D26\u91CC\u4E00\u6761\u8BB0\u5F55\u90FD\u6CA1\u6709] ${planned.length} \u884C\uFF08\u5DEE\u96C6\u7B97\u8FC7\u4E86\uFF1B\u5DE6\u8FB9\u53EA\u542B**\u8FDB\u5F97\u4E86\u6CE2\u6B21**\u7684\u884C \u2014\u2014 \u5C04\u7A0B\u89C1\u300C${NOT_COVERED_LAYER1}\u300D\uFF09`
15073
+ );
15074
+ for (const row of planned) {
15075
+ lines.push(` - ${row.model} ${JSON.stringify(row.key)} \u6E90\u8868\u7B2C ${row.sourceRowId} \u884C \u8BA1\u5212\u5224\u5B83 ${row.action}`);
15076
+ }
15077
+ }
15078
+ lines.push(
15079
+ `[\u653E\u884C\u8BB0\u5F55] ${delivery.waivers.length} \u7B14\uFF08\u6BCF\u4E00\u7B14\u8BF4\u7684\u662F**\u6574\u6574\u4E00\u8F6E**\u5728\u4EC0\u4E48\u524D\u63D0\u4E0B\u8DD1\u7684\uFF0C\u4E0D\u843D\u5230\u4EFB\u4F55\u4E00\u884C\u5934\u4E0A\uFF1B\u4E0B\u9762\u6BCF\u4E00\u7B14\u91CC\u7684 roundId \u662F**\u8BA1\u5212\u8F6E\u6B21** id\uFF09`
15080
+ );
15081
+ for (const waiver of delivery.waivers) lines.push(" - " + describeWaiver(waiver));
15082
+ lines.push(...reconciliationLines(recon, findings));
15083
+ lines.push(`[${NOT_COVERED_SELF}]`);
15084
+ lines.push(
15085
+ ` \xB7 **\u672C\u547D\u4EE4\u4E0D\u843D\u76D8**\uFF1A\u4EA7\u51FA\u7269\u5C31\u662F\u5C4F\u5E55\u4E0A\u8FD9\u4E00\u9875\uFF1B\u8981\u7559\u4E00\u4EFD\u5B58\u6863\uFF0C\u81EA\u5DF1\u91CD\u5B9A\u5411\u4E00\u6B21 \u2014\u2014 \`hcm delivery seed verify --work <work \u76EE\u5F55> ${LEDGER_ONLY_FLAG} > \u4EA4\u4ED8\u8BC1\u636E-<\u65E5\u671F>.txt 2>&1\`\u3002`
15086
+ );
15087
+ lines.push(
15088
+ " \u{1F534} \u522B\u63A5\u7BA1\u9053\u5B58\u6863\uFF08`| tee \u6587\u4EF6`\uFF09\uFF1A\u90A3\u4E4B\u540E\u62FF\u5230\u7684\u9000\u51FA\u7801\u662F tee \u7684\uFF0C**\u6052\u4E3A 0**\uFF0C\u8FD9\u4E00\u8D9F\u5224\u6210\u4EC0\u4E48\u5C31\u4E22\u4E86\u3002"
15089
+ );
15090
+ lines.push(`[${NOT_COVERED_LAYER1}]`);
15091
+ for (const note of delivery.notCovered) lines.push(" \xB7 " + note);
15092
+ lines.push(`[${NOT_COVERED_LAYER2}]`);
15093
+ for (const note of recon.notCovered) lines.push(" \xB7 " + note);
15094
+ return lines.join("\n") + "\n";
15095
+ }
15096
+ function verifyRc(delivery, recon) {
15097
+ if ([...delivery.premises, ...recon.premises].some((p) => !p.ok)) return INIT_EXIT_CODES.premise;
15098
+ const [rows, planned, findings] = verifyAttention(delivery, recon);
15099
+ if (rows.length || planned.length || findings.length) return INIT_EXIT_CODES.blocked;
15100
+ return INIT_EXIT_CODES.clean;
15101
+ }
15102
+
15103
+ // src/fde/seed/risk-io.ts
15104
+ function fromArtifactProblem2(p) {
15105
+ return {
15106
+ code: p.code,
15107
+ model: p.model,
15108
+ field: null,
15109
+ message: p.message,
15110
+ hint: p.hint,
15111
+ kind: p.kind,
15112
+ severity: "blocking",
15113
+ entry: p.entry,
15114
+ // 🔴 不留裸 `{}`:这一条的证据在工件层那一侧,本模块转手时手上确实没有可记的数。
15115
+ evidence: {
15116
+ _kitNoEvidence: "\u8FD9\u6761\u662F validateMapping \u7684\u539F\u6837\u8F6C\u5F55\uFF0C\u672C\u6A21\u5757\u6CA1\u6709\u91CD\u65B0\u5224\u5B83\uFF0C\u624B\u4E0A\u6CA1\u6709\u53EF\u8BB0\u7684\u8BC1\u636E"
15117
+ },
15118
+ exempted: false
15119
+ };
15120
+ }
15121
+ async function riskFromArtifacts(mappingPath, reconDir, options = {}) {
15122
+ const mapping = loadMapping(mappingPath);
15123
+ const scan2 = await scanSources(mapping, options.sourceDir);
15124
+ const problems = [...scan2.problems, ...validateMapping(mapping, scan2.headers)];
15125
+ if (problems.length === 0) {
15126
+ return buildRisk(mapping, reconDir, {
15127
+ notes: [...scan2.notes],
15128
+ tables: scan2.rows,
15129
+ exemptions: options.exemptions,
15130
+ plan: options.plan,
15131
+ roundPremise: options.roundPremise
15132
+ });
15133
+ }
15134
+ const blocked = PREMISE_BLOCKS3.RISK_NOT_BUILT;
15135
+ const converted = problems.map(fromArtifactProblem2);
15136
+ converted.push(...roundProblems(options.roundPremise ?? null, false));
15137
+ converted.push(
15138
+ problem3(
15139
+ "RISK_NOT_BUILT",
15140
+ "*",
15141
+ `\u5DE5\u4EF6\u6709 ${problems.length} \u6761\u95EE\u9898\uFF0C**\u6574\u4EFD\u98CE\u9669\u6E05\u5355\u6CA1\u6709\u5EFA**\uFF1A${blocked.length} \u7EC4\u5224\u636E\u4E00\u7EC4\u90FD\u6CA1\u8DD1\uFF0C\u4E00\u4E2A\u6A21\u578B\u90FD\u6CA1\u8BC4\u4F30`,
15142
+ `validateMapping \u8FD4\u56DE\u975E\u7A7A\u7684\u8BED\u4E49\u662F\u300C\u4E0D\u8BB8\u5F80\u4E0B\u8D70\u300D\u3002\u5148\u6309\u4E0A\u9762\u6BCF\u6761\u7684 hint \u6539\u5DE5\u4EF6 / \u6E90\u8868\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002\u{1F534} \`models: []\` \u5728\u8FD9\u4E00\u4EFD\u4EA7\u7269\u91CC**\u4E0D\u662F**\u300C\u96F6\u4E2A\u6A21\u578B\u6709\u98CE\u9669\u300D\u2014\u2014 \u770B \`modelsAssessed: false\`\uFF08\u8BC4\u4F30\u538B\u6839\u6CA1\u53D1\u751F\uFF09\u3002\u6CA1\u8DD1\u7684\u90A3\u51E0\u7EC4\u662F\uFF1A${blocked.join("\uFF1B")}`,
15143
+ null,
15144
+ null,
15145
+ { artifactProblems: problems.length, checkGroups: blocked.length }
15146
+ )
15147
+ );
15148
+ return {
15149
+ version: VERSION3,
15150
+ roundId: newRoundId(/* @__PURE__ */ new Date()),
15151
+ blocking: true,
15152
+ models: [],
15153
+ problems: converted,
15154
+ // 🔴 `notes` 照常带出:源表扫过了(扫描在校验之前跑),丢掉它等于把已经查到的事实
15155
+ // 一起扔了。
15156
+ notes: [...scan2.notes],
15157
+ notesProvided: true,
15158
+ exemptions: [],
15159
+ // 🔴 传了豁免也**没有判**(一条风险项都没算出来,无从匹配)⇒ 这里必须是 false:
15160
+ // `[]` + `exemptionsProvided: true` 会被读成「签的那几份一条都没生效」,
15161
+ // 而真相是「压根没走到判豁免那一步」。
15162
+ exemptionsProvided: false,
15163
+ modelsAssessed: false,
15164
+ // 🔴 轮次身份与工件校验是两回事:这一轮判没判它,只看有没有把结论传进来。
15165
+ roundJudged: options.roundPremise !== void 0 && options.roundPremise !== null,
15166
+ // 🔴 一个模型都没评估 ⇒ **每一组**判据都没跑,这一格是 `true`(不是 `null`、更不是
15167
+ // `false`)。与 `modelsAssessed: false` 一起读才分得出这是哪一档。
15168
+ checksSkipped: true,
15169
+ wording: WORDING5
15170
+ };
15171
+ }
15172
+ function riskToJson(risk) {
15173
+ return {
15174
+ version: risk.version,
15175
+ roundId: risk.roundId,
15176
+ blocking: risk.blocking,
15177
+ wording: risk.wording,
15178
+ // 🔴 可审计出口:`notes` 是**原样**留痕,这个数是**展示出来**的条数。两者都要有 ——
15179
+ // 只有原样留痕就回到了「有出参、没人展示」,只有条数则丢掉了读取器记下的原文。
15180
+ discardedColumnsShown: risk.problems.filter((p) => p.code === "SOURCE_COLUMN_DISCARDED").length,
15181
+ // 🔴 `notes: []` 的两种成因分得开:true = 扫过、一列都没丢;
15182
+ // false = 这一轮没把 notes 传进来。
15183
+ notesProvided: risk.notesProvided,
15184
+ // 豁免台账。🔴 与 notes 同一条口径:`[]` 与「压根没签」分得开。
15185
+ exemptions: risk.exemptions.map((e) => ({ ...e })),
15186
+ exemptionsProvided: risk.exemptionsProvided,
15187
+ // 🔴 与上面那一对同一条口径:没有那条轮次前提码时,`true` = 判过且完整、
15188
+ // `false` = **这一轮没判轮次身份**。
15189
+ roundJudged: risk.roundJudged,
15190
+ // 🔴 `models: []` 的两种成因分得开:true = 评估过、就是没有模型;
15191
+ // false = 门面早退,一个模型都没评估(此时 `models` 恒为空,别读成「零风险」)。
15192
+ modelsAssessed: risk.modelsAssessed,
15193
+ // 🔴 `blocking: false` 的两种成因分得开:本键 false = 该跑的判据都跑了、没查出拦路的;
15194
+ // true = **有判据这一轮根本没跑**,此时「没查出问题」不等于「没问题」。
15195
+ checksSkipped: risk.checksSkipped,
15196
+ models: risk.models.map(modelJson2),
15197
+ problems: risk.problems.map((p) => ({ ...p })),
15198
+ notes: [...risk.notes]
15199
+ };
15200
+ }
15201
+ function modelJson2(m) {
15202
+ return {
15203
+ model: m.model,
15204
+ entry: m.entry,
15205
+ reconSheet: { ...m.reconSheet },
15206
+ checks: Object.fromEntries(
15207
+ Object.entries(m.checks).map(([group, info]) => [
15208
+ group,
15209
+ { ran: info.ran, applicable: info.applicable, why: [...info.why] }
15210
+ ])
15211
+ ),
15212
+ counts: { ...m.counts }
15213
+ };
15214
+ }
15215
+ function writeRisk(risk, out) {
15216
+ return new WorkLayout(out).writeJson(RISK_FILE, riskToJson(risk));
15217
+ }
15218
+
15219
+ // src/fde/seed/value-hints.ts
15220
+ import { existsSync as existsSync10, readFileSync as readFileSync9 } from "fs";
15221
+ import * as path18 from "path";
15222
+ var HINT_REF = (domain) => ` \u503C\uFF1A\u586B id\uFF08\u4E0D\u662F code\uFF09\u2190 ${domain}`;
15223
+ var HINT_NO_DOMAIN = (to) => ` \u503C\uFF1A\u586B ${to} \u7684 id\uFF08\u4E0D\u662F code\uFF09\uFF1B\u65E0\u5BF9\u7167\u8868\uFF0C\u6309\u4E1A\u52A1\u952E\u73B0\u67E5`;
15224
+ var HINT_ENUM = (n, model) => ` \u503C\uFF1A\u679A\u4E3E ${n} \u9879 \u2190 mapping/${model}.json`;
15225
+ var HINT_DOMAIN_MISSING = (to) => `\uFF1B\u26A0\uFE0F \u7D22\u5F15\u91CC\u6709\u8FD9\u5F20\u8868\u4F46\u76D8\u4E0A\u6CA1\u6709\u6587\u4EF6\uFF08\`values ${to}\` \u770B\u539F\u56E0\uFF09`;
15226
+ var HINT_DOMAIN_UNAVAILABLE = "\uFF1B\u26A0\uFE0F \u8FD9\u5F20\u8868\u672C\u8F6E\u8FDE\u8BA1\u6570\u90FD\u6CA1\u8BFB\u5230\uFF08unavailable\uFF09\uFF0C\u7981\u6B62\u636E\u6B64\u5199\u811A\u672C";
15227
+ var HINT_DOMAIN_INDEX_UNREADABLE = (to) => `\uFF1B\u26A0\uFE0F \u8FD9\u4EFD\u57FA\u7EBF\u7684 valuedomain/_index.json \u8BFB\u4E0D\u5230\uFF0C**\u65E0\u6CD5\u5224\u65AD**\u6709\u6CA1\u6709\u5BF9\u7167\u8868\uFF08\u53BB valuedomain/ \u76EE\u5F55\u770B\u6709\u6CA1\u6709 ${to}.json\uFF09`;
15228
+ var HINT_DOMAIN_UNKNOWN_TO_INDEX = "\uFF1B\u26A0\uFE0F mapping \u8BF4\u5B83\u662F\u7801\u8868\uFF0Cvaluedomain \u7D22\u5F15\u91CC\u5374\u6CA1\u6709\u8FD9\u5F20\u8868\uFF08\u5BF9\u4E0D\u4E0A\u8D26\uFF09";
15229
+ var HINT_LABEL = (label) => `\uFF1B\u62FF ${label} \u53CD\u67E5 id`;
15230
+ var HINT_LABEL_UNKNOWN = "\uFF1B\u6807\u7B7E\u5B57\u6BB5\u672A\u77E5\uFF08\u4EA7\u54C1\u6CA1\u58F0\u660E\u663E\u793A\u5B57\u6BB5\u540D\uFF0C\u522B\u9ED8\u8BA4\u662F name\uFF09";
15231
+ var HINT_AUDIT = "\uFF1B\u26A0\uFE0F \u5BA1\u8BA1\u56DE\u6307\uFF0C\u670D\u52A1\u7AEF\u81EA\u5DF1\u586B\uFF0C\u987E\u95EE\u4E0D\u586B";
15232
+ var VALUE_FOOTNOTE = "\uFF08\u6307\u8DEF\u53EA\u4F9D\u636E\u4EA7\u7269\u91CC**\u771F\u5B9E\u5B58\u5728**\u7684\u6587\u4EF6\u3002\u26A0\uFE0F \u300C\u6211\u8981\u4E86\u5B57\u6BB5 X\uFF0C\u56DE\u6765\u6CA1\u6709 X\u300D\u6709\u4E09\u79CD\u540C\u5F62\u6210\u56E0\uFF1A\u2460 \u4EA7\u54C1\u91CC\u6CA1\u8FD9\u4E2A\u5B57\u6BB5 \u2461 \u8BE5\u884C\u8BE5\u5B57\u6BB5\u4E3A null \u2462 \u4F60\u7684\u89D2\u8272\u88AB RBAC \u88C1\u6389\u4E86\u8FD9\u4E00\u5217 \u2014\u2014 \u4EA7\u7269\u5206\u4E0D\u5F00\uFF0C\u522B\u628A\u5176\u4E2D\u4EFB\u4E00\u8BFB\u6210\u53E6\u4E00\u4E2A\u3002\uFF09\n";
15233
+ function isLocalName(name) {
15234
+ if (typeof name !== "string" || name.length === 0) return false;
15235
+ if (name.includes("/") || name.includes("\\")) return false;
15236
+ if (name === "." || name === "..") return false;
15237
+ return !path18.isAbsolute(name);
15238
+ }
15239
+ var readJson = (file) => {
15240
+ try {
15241
+ return JSON.parse(readFileSync9(file, "utf-8"));
15242
+ } catch {
15243
+ return void 0;
15244
+ }
15245
+ };
15246
+ var isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
15247
+ var ValueHints = class {
15248
+ root;
15249
+ sheets = /* @__PURE__ */ new Map();
15250
+ domains = void 0;
15251
+ constructor(root) {
15252
+ this.root = root;
15253
+ }
15254
+ /** → `{modelKey: completeness}`;**索引根本读不到时返回 `null`**(与「读到了但是空的」分开)。 */
15255
+ domainIndex() {
15256
+ if (this.domains === void 0) {
15257
+ const body = readJson(path18.join(this.root, "valuedomain", "_index.json"));
15258
+ const by = isRec(body) ? body.byCompleteness : void 0;
15259
+ if (!isRec(by)) {
15260
+ this.domains = null;
15261
+ } else {
15262
+ const index = /* @__PURE__ */ new Map();
15263
+ for (const [completeness, names] of Object.entries(by)) {
15264
+ if (!Array.isArray(names)) continue;
15265
+ for (const n of names) if (typeof n === "string") index.set(n, completeness);
15266
+ }
15267
+ this.domains = index;
15268
+ }
15269
+ }
15270
+ return this.domains;
15271
+ }
15272
+ /** 某个模型的 `mapping/<model>.json` → `{fieldKey: 该字段那一行}`;没有则 null。 */
15273
+ sheet(model) {
15274
+ const key = String(model ?? "");
15275
+ if (!this.sheets.has(key)) {
15276
+ let fields = null;
15277
+ if (isLocalName(key)) {
15278
+ const body = readJson(path18.join(this.root, "mapping", `${key}.json`));
15279
+ const rows = isRec(body) ? body.fields : void 0;
15280
+ if (Array.isArray(rows)) {
15281
+ fields = /* @__PURE__ */ new Map();
15282
+ for (const f of rows) {
15283
+ if (isRec(f) && typeof f.key === "string") fields.set(f.key, f);
15284
+ }
15285
+ }
15286
+ }
15287
+ this.sheets.set(key, fields);
15288
+ }
15289
+ return this.sheets.get(key) ?? null;
15290
+ }
15291
+ refLine(ref) {
15292
+ const target = String(ref.toModel ?? "");
15293
+ const index = this.domainIndex();
15294
+ const completeness = index === null ? void 0 : index.get(target);
15295
+ const pointer = ref.valueDomain;
15296
+ const landed = isLocalName(target) && existsSync10(path18.join(this.root, "valuedomain", `${target}.json`));
15297
+ let line;
15298
+ if (pointer && completeness && completeness !== "unavailable" && landed) {
15299
+ line = HINT_REF(String(pointer));
15300
+ } else {
15301
+ line = HINT_NO_DOMAIN(target);
15302
+ if (pointer && index === null) line += HINT_DOMAIN_INDEX_UNREADABLE(target);
15303
+ else if (pointer && completeness === void 0) line += HINT_DOMAIN_UNKNOWN_TO_INDEX;
15304
+ else if (pointer && completeness === "unavailable") line += HINT_DOMAIN_UNAVAILABLE;
15305
+ else if (pointer && !landed) line += HINT_DOMAIN_MISSING(target);
15306
+ }
15307
+ if (ref.labelFieldSource === "declared" && ref.labelField) line += HINT_LABEL(String(ref.labelField));
15308
+ else line += HINT_LABEL_UNKNOWN;
15309
+ if (ref.auditBackref) line += HINT_AUDIT;
15310
+ return `${line}
15311
+ `;
15312
+ }
15313
+ /** 一条命中的指路行(含换行);无从指路时返回空串。 */
15314
+ line(model, key) {
15315
+ const sheet = this.sheet(model);
15316
+ if (!sheet || sheet.size === 0) return "";
15317
+ const field = sheet.get(String(key ?? ""));
15318
+ if (!isRec(field)) return "";
15319
+ const ref = field.ref;
15320
+ if (isRec(ref)) return this.refLine(ref);
15321
+ const count = field.enumCount;
15322
+ if (typeof count === "number" && Number.isInteger(count) && count > 0) {
15323
+ return `${HINT_ENUM(count, String(model))}
15324
+ `;
15325
+ }
15326
+ return "";
15327
+ }
15328
+ };
15329
+
15330
+ // src/fde/seed/find.ts
15331
+ var MAX_BYTES = 8192;
15332
+ var FIND_LIMIT = 500;
15333
+ var ENUM_SHOW = 8;
15334
+ var SYNTH_MARK = "\u26A0\u5408\u6210";
15335
+ var SYNTH_FOOTNOTE = `\uFF08\u5E26 ${SYNTH_MARK} \u7684\u53D6\u503C\u662F\u5DE5\u5177\u4ECE label \u6216\u5143\u7D20\u672C\u8EAB\u8865\u51FA\u6765\u7684\uFF0C\u4EA7\u54C1\u4ECE\u672A\u53D1\u51FA\u8FD9\u4E2A value\uFF0C**\u4E0D\u53EF**\u76F4\u63A5\u62FF\u53BB\u62FC\u7B5B\u9009\u6761\u4EF6\u3002\uFF09
15336
+ `;
15337
+ var DIMENSION_LABELS = {
15338
+ name: "\u540D\u79F0",
15339
+ key: "\u5B57\u6BB5\u540D",
15340
+ model: "\u6A21\u578B\u540D",
15341
+ synonyms: "\u540C\u4E49\u8BCD",
15342
+ description: "\u63CF\u8FF0",
15343
+ enumLabel: "\u679A\u4E3E\u6807\u7B7E",
15344
+ enumValue: "\u679A\u4E3E\u503C"
15345
+ };
15346
+ var KIT_MATCHED_ON = "_kitMatchedOn";
15347
+ var DIMENSION_RANK = {
15348
+ name: 2,
15349
+ key: 3,
15350
+ model: 3,
15351
+ synonyms: 4,
15352
+ enumLabel: 5,
15353
+ enumValue: 6,
15354
+ description: 7
15355
+ };
15356
+ var EXACT_NAME_RANK = 0;
15357
+ var EXACT_KEY_RANK = 1;
15358
+ var WEAKEST_RANK = Object.keys(DIMENSION_RANK).length;
15359
+ var VISIBLE_DIMENSIONS = /* @__PURE__ */ new Set(["name", "key", "model"]);
15360
+ var asList = (v) => v === null || v === void 0 ? [] : Array.isArray(v) ? v : [v];
15361
+ var str2 = (v) => v === null || v === void 0 ? "" : String(v);
15362
+ var bytes = (s) => Buffer.byteLength(s, "utf-8");
15363
+ function loadRows(text2) {
15364
+ const rows = [];
15365
+ const problems = [];
15366
+ const lines = text2.split("\n");
15367
+ lines.forEach((raw, i) => {
15368
+ const line = raw.trim();
15369
+ if (!line) return;
15370
+ try {
15371
+ const parsed = JSON.parse(line);
15372
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
15373
+ problems.push(`\u7B2C ${i + 1} \u884C\u4E0D\u662F JSON \u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7`);
15374
+ return;
15375
+ }
15376
+ rows.push(parsed);
15377
+ } catch {
15378
+ problems.push(`\u7B2C ${i + 1} \u884C\u89E3\u6790\u5931\u8D25\uFF0C\u5DF2\u8DF3\u8FC7`);
15379
+ }
15380
+ });
15381
+ return { rows, problems };
15382
+ }
15383
+ function matchedDimensions(row, term) {
15384
+ const t = term.toLowerCase();
15385
+ const dims = [];
15386
+ for (const dim of ["name", "key", "model"]) {
15387
+ if (str2(row[dim]).toLowerCase().includes(t)) dims.push(dim);
15388
+ }
15389
+ if (asList(row.synonyms).some((s) => str2(s).toLowerCase().includes(t))) dims.push("synonyms");
15390
+ if (str2(row.description).toLowerCase().includes(t)) dims.push("description");
15391
+ const labels = [];
15392
+ const values = [];
15393
+ for (const e of asList(row.enums)) {
15394
+ if (e && typeof e === "object" && !Array.isArray(e)) {
15395
+ const o = e;
15396
+ values.push(str2(o.value));
15397
+ labels.push(str2(o.label));
15398
+ } else {
15399
+ values.push(str2(e));
15400
+ }
15401
+ }
15402
+ if (labels.some((x) => x.toLowerCase().includes(t))) dims.push("enumLabel");
15403
+ if (values.some((x) => x.toLowerCase().includes(t))) dims.push("enumValue");
15404
+ return dims;
15405
+ }
15406
+ function hitRank(row, dims, term) {
15407
+ const t = term.toLowerCase();
15408
+ if (dims.includes("name") && str2(row.name).toLowerCase() === t) return EXACT_NAME_RANK;
15409
+ if (dims.includes("key") && str2(row.key).toLowerCase() === t) return EXACT_KEY_RANK;
15410
+ let best = WEAKEST_RANK;
15411
+ for (const d of dims) best = Math.min(best, DIMENSION_RANK[d] ?? WEAKEST_RANK);
15412
+ return best;
15413
+ }
15414
+ function find(rows, term, limit = FIND_LIMIT) {
15415
+ const t = (term ?? "").toLowerCase();
15416
+ if (!t) return [];
15417
+ const scored = [];
15418
+ rows.forEach((r, i) => {
15419
+ const dims = matchedDimensions(r, t);
15420
+ if (dims.length === 0) return;
15421
+ scored.push({ rank: hitRank(r, dims, t), i, hit: { ...r, [KIT_MATCHED_ON]: dims } });
15422
+ });
15423
+ scored.sort((a, b) => a.rank - b.rank || a.i - b.i);
15424
+ return scored.slice(0, limit).map((s) => s.hit);
15425
+ }
15426
+ function enumTail(row) {
15427
+ const items = asList(row.enums);
15428
+ if (items.length === 0) return { tail: "", hasSynth: false };
15429
+ const shown = [];
15430
+ let hasSynth = false;
15431
+ for (const e of items.slice(0, ENUM_SHOW)) {
15432
+ if (e && typeof e === "object" && !Array.isArray(e)) {
15433
+ const o = e;
15434
+ const synth = o[KIT_VALUE_SOURCE] !== void 0 && o[KIT_VALUE_SOURCE] !== null;
15435
+ if (synth) hasSynth = true;
15436
+ shown.push(`${str2(o.value)}${synth ? SYNTH_MARK : ""}`);
15437
+ } else {
15438
+ shown.push(str2(e));
15439
+ }
15440
+ }
15441
+ const more = items.length > ENUM_SHOW ? `\u2026\u5171 ${items.length} \u4E2A` : "";
15442
+ return { tail: ` {${shown.join("/")}${more}}`, hasSynth };
15443
+ }
15444
+ function matchNote(hit) {
15445
+ const dims = asList(hit[KIT_MATCHED_ON]).map(str2);
15446
+ if (dims.length === 0) return "";
15447
+ if (dims.some((d) => VISIBLE_DIMENSIONS.has(d))) return "";
15448
+ return " \u2190\u547D\u4E2D\u4E8E" + dims.map((d) => DIMENSION_LABELS[d] ?? d).join("/");
15449
+ }
15450
+ var budgetNote = (hitCount, shown) => `
15451
+ \uFF08\u5DF2\u622A\u65AD\uFF1A\u547D\u4E2D ${hitCount} \u6761\uFF0C\u6B64\u5904\u53EA\u663E\u793A ${shown} \u6761\u3002\u8BF7\u7F29\u5C0F\u68C0\u7D22\u8BCD\u3002\uFF09
15452
+ `;
15453
+ var searchCapNote = () => `\uFF08\u547D\u4E2D\u5DF2\u8FBE\u68C0\u7D22\u4E0A\u9650 ${FIND_LIMIT}\uFF0C\u5B9E\u9645\u53EF\u80FD\u66F4\u591A\uFF0C\u8BF7\u7F29\u5C0F\u68C0\u7D22\u8BCD\u3002\uFF09
15454
+ `;
15455
+ function renderFind(hits, term, total, options = {}) {
15456
+ const head = `# find \`${term}\` \u2014 ${hits.length} \u547D\u4E2D / \u7D22\u5F15\u5171 ${total} \u5B57\u6BB5
15457
+
15458
+ `;
15459
+ const reserve = bytes(budgetNote(hits.length, hits.length) + searchCapNote() + SYNTH_FOOTNOTE + VALUE_FOOTNOTE);
15460
+ const budget = MAX_BYTES - Math.max(0, Math.trunc(options.prefixBytes ?? 0));
15461
+ const lines = [];
15462
+ let shown = 0;
15463
+ let synthShown = false;
15464
+ let valueShown = false;
15465
+ for (const h of hits) {
15466
+ const { tail, hasSynth } = enumTail(h);
15467
+ const line = `- ${str2(h.name)} \u2192 \`${str2(h.model)}\`.\`${str2(h.key)}\` [${str2(h.type)}]${h.isRequired ? "\u5FC5\u586B" : ""}${tail}${matchNote(h)}
15468
+ `;
15469
+ const hint = options.hints ? options.hints.line(h.model, h.key) : "";
15470
+ const block = line + hint;
15471
+ if (bytes(head + lines.join("") + block) > budget - reserve) break;
15472
+ lines.push(block);
15473
+ shown += 1;
15474
+ synthShown = synthShown || hasSynth;
15475
+ valueShown = valueShown || hint.length > 0;
15476
+ }
15477
+ let out = head + lines.join("");
15478
+ if (shown < hits.length) out += budgetNote(hits.length, shown);
15479
+ if (hits.length >= FIND_LIMIT) out += searchCapNote();
15480
+ if (synthShown) out += SYNTH_FOOTNOTE;
15481
+ if (valueShown) out += VALUE_FOOTNOTE;
15482
+ return out;
15483
+ }
15484
+
15485
+ // src/fde/seed/values.ts
15486
+ import { existsSync as existsSync11, readFileSync as readFileSync10 } from "fs";
15487
+ import * as path19 from "path";
15488
+ var readJson2 = (file) => {
15489
+ try {
15490
+ return JSON.parse(readFileSync10(file, "utf-8"));
15491
+ } catch {
15492
+ return void 0;
15493
+ }
15494
+ };
15495
+ var isRec2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
15496
+ var VALUE_CELL_MISSING = "\u2014";
15497
+ var VALUE_STATE_DISABLED = "\u505C\u7528";
15498
+ var VALUE_STATE_ENABLED = "";
15499
+ var VALUE_STATE_UNKNOWN = "enabled?";
15500
+ var VALUE_STATE_FOOTNOTE = `\uFF08\u300C${VALUE_STATE_DISABLED}\u300D= \u8BE5\u884C \`enabled=false\`\uFF0C**\u522B\u5199\u8FDB\u5BFC\u5165\u811A\u672C**\uFF1B\u300C${VALUE_STATE_UNKNOWN}\u300D= \u8FD9\u4EFD\u4EA7\u7269\u91CC\u90A3\u4E00\u884C**\u6CA1\u6709 \`enabled\` \u952E**\uFF0C\u5DE5\u5177\u4E0D\u66FF\u4EA7\u54C1\u5047\u8BBE\u5B83\u662F\u542F\u7528\u7684\u3002\uFF09
15501
+ `;
15502
+ var valuesTruncated = (total, shown, file) => `\uFF08\u5DF2\u622A\u65AD\uFF1A\u5171 ${total} \u884C\uFF0C\u6B64\u5904\u53EA\u663E\u793A ${shown} \u884C \u2014\u2014 \u884C\u5757\u6709 ${MAX_BYTES} \u5B57\u8282\u9884\u7B97\uFF08\u62AC\u5934\u4E0E\u811A\u6CE8\u4E0D\u8BA1\u5165\uFF09\u3002\u5168\u91CF\u5728 ${file}\uFF1B\u8981\u5168\u90E8\u6253\u5370\u7528 \`--limit 0\`\uFF0C\u6216 \`--limit N\` \u6307\u5B9A\u884C\u6570\u3002\uFF09
15503
+ `;
15504
+ function valueState(row) {
15505
+ if (!Object.prototype.hasOwnProperty.call(row, "enabled")) return VALUE_STATE_UNKNOWN;
15506
+ const enabled = row.enabled;
15507
+ if (enabled === false) return VALUE_STATE_DISABLED;
15508
+ if (enabled === true) return VALUE_STATE_ENABLED;
15509
+ return `${VALUE_STATE_UNKNOWN}=${JSON.stringify(enabled)}`;
15510
+ }
15511
+ var VALUES_ROUND_STALE = (detail) => `> \u{1F534} \`valuedomain/_index.json\` ${detail} \u2014\u2014 \u4E0B\u9762\u90A3\u53E5\u53E3\u5F84\u91CC\u7684\u300C\u672C\u8F6E\u300D**\u4E0D\u662F\u4F60\u521A\u8DD1\u7684\u90A3\u4E00\u8F6E**\uFF0C\u8FD9\u5F20\u7801\u8868\u5FEB\u7167\u53EF\u80FD\u66F4\u65E9\u3002
15512
+ `;
15513
+ var VALUES_ROUND_MIXED = (state) => `> \u26A0\uFE0F \u8FD9\u4EFD\u57FA\u7EBF\u4E0D\u662F\u4E00\u8F6E\u5B8C\u6574\u8DD1\u51FA\u6765\u7684\uFF08\`round\` = ${state}\uFF09\uFF0C\u4E0D\u8FC7 \`valuedomain/_index.json\` \u672C\u8EAB\u662F\u672C\u8F6E\u7684 \u2014\u2014 \u4E0B\u9762\u90A3\u53E5\u53E3\u5F84\u91CC\u7684\u300C\u672C\u8F6E\u300D\u6309\u5B83\u7406\u89E3\u3002
15514
+ `;
15515
+ var STALE_WORDS = {
15516
+ "older-round": "\u662F**\u522B\u7684\u8F6E\u6B21**\u7559\u4E0B\u7684",
15517
+ unstamped: "**\u6CA1\u6709\u8F6E\u6B21\u6233**\uFF08\u66F4\u65E9\u7248\u672C\u5199\u7684\uFF09",
15518
+ missing: "**\u4E0D\u5728\u76D8\u4E0A**",
15519
+ unreadable: "**\u8BFB\u4E0D\u51FA JSON**"
15520
+ };
15521
+ function valuesRoundCaveat(round) {
15522
+ if (!isRec2(round)) return "";
15523
+ const state = round.state;
15524
+ if (state === "complete") return "";
15525
+ const products = round.products;
15526
+ const entry = Array.isArray(products) ? products.find((p) => isRec2(p) && p.path === "valuedomain/_index.json") : void 0;
15527
+ const productState = isRec2(entry) ? entry.state : void 0;
15528
+ if (typeof productState === "string" && productState in STALE_WORDS) {
15529
+ return VALUES_ROUND_STALE(STALE_WORDS[productState]);
15530
+ }
15531
+ return VALUES_ROUND_MIXED(String(state ?? "unknown"));
15532
+ }
15533
+ function renderValues(root, model, options = {}) {
15534
+ const indexBody = readJson2(path19.join(root, "valuedomain", "_index.json"));
15535
+ const byCompleteness = isRec2(indexBody) ? indexBody.byCompleteness : void 0;
15536
+ if (!isRec2(byCompleteness)) {
15537
+ return {
15538
+ ok: false,
15539
+ kind: "index-unreadable",
15540
+ message: `\u8BFB\u4E0D\u5230 valuedomain/_index.json\uFF08${root}\uFF09\u2014\u2014 \u53EF\u80FD\u662F\uFF1A\u8FD9\u4EFD\u57FA\u7EBF\u7531\u66F4\u65E9\u7248\u672C\u722C\u7684\u3001\u4F60\u6CA1\u62F7 valuedomain/ \u76EE\u5F55\u8FC7\u6765\u3001\u6216\u8005\u90A3\u4E2A\u6587\u4EF6\u574F\u4E86\u3002\u5148 \`ls ${path19.join(root, "valuedomain")}\` \u770B\u4E00\u773C\uFF1B\u786E\u5B9E\u6CA1\u6709\u5C31\u91CD\u8DD1\u4E00\u6B21 recon\u3002`
15541
+ };
15542
+ }
15543
+ let completeness;
15544
+ for (const [c, names] of Object.entries(byCompleteness)) {
15545
+ if (Array.isArray(names) && names.includes(model)) {
15546
+ completeness = c;
15547
+ break;
15548
+ }
15549
+ }
15550
+ if (completeness === void 0) {
15551
+ if (isLocalName(model) && existsSync11(path19.join(root, "mapping", `${model}.json`))) {
15552
+ return {
15553
+ ok: false,
15554
+ kind: "not-a-code-table",
15555
+ message: `${model} \u4E0D\u662F\u7801\u8868\uFF08\`type != DYNAMIC\`\uFF0Cvaluedomain/ \u91CC\u6CA1\u6709\u5B83\uFF09\u2014\u2014 \u6307\u5411\u5B83\u7684\u5F15\u7528\u503C\u53EA\u80FD\u6309\u4E1A\u52A1\u952E\u73B0\u67E5\u3002\u5B83\u7684\u5B57\u6BB5\u6E05\u5355\u5728 mapping/${model}.json\u3002`
15556
+ };
15557
+ }
15558
+ return {
15559
+ ok: false,
15560
+ kind: "model-not-in-baseline",
15561
+ message: `\u57FA\u7EBF\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6A21\u578B\uFF1A${model}\u3002\`ls ${path19.join(root, "mapping")}\` \u770B\u6709\u54EA\u4E9B\u3002`
15562
+ };
15563
+ }
15564
+ const file = path19.join(root, "valuedomain", `${model}.json`);
15565
+ if (!isLocalName(model) || !existsSync11(file)) {
15566
+ return {
15567
+ ok: false,
15568
+ kind: "file-missing",
15569
+ message: `${model} \u5728 valuedomain/_index.json \u91CC\u6302\u7740\uFF08completeness=${completeness}\uFF09\uFF0C\u4F46\u76D8\u4E0A\u6CA1\u6709\u8FD9\u4EFD\u6587\u4EF6 \u2014\u2014 \u53BB\u770B _index.json \u7684 writeProblems\u3002`
15570
+ };
15571
+ }
15572
+ const table = readJson2(file);
15573
+ const rows = isRec2(table) ? table.rows : void 0;
15574
+ if (!Array.isArray(rows)) {
15575
+ return { ok: false, kind: "rows-unreadable", message: `${file} \u8BFB\u4E0D\u51FA rows` };
15576
+ }
15577
+ const head = `# values ${model} \u2014 completeness=${completeness}\uFF0C\u53D6\u56DE ${String(isRec2(table) ? table.rowsRetrieved : "?")} \u884C / \u8BA1\u6570 ${String(isRec2(table) ? table.totalElements : "?")} \u884C
15578
+ `;
15579
+ const caveat = options.roundCaveat ?? "";
15580
+ const wording = `> ${String(indexBody && isRec2(indexBody) ? indexBody.wording ?? "" : "")}
15581
+ `;
15582
+ const lines = ["id code name \u72B6\u6001\n"];
15583
+ let missing = false;
15584
+ let stateShown = false;
15585
+ let shown = 0;
15586
+ let used = 0;
15587
+ const limit = options.limit;
15588
+ for (const row of rows) {
15589
+ if (!isRec2(row)) continue;
15590
+ const cells = [];
15591
+ for (const key of ["id", "code", "name"]) {
15592
+ const v = row[key];
15593
+ if (v === null || v === void 0) missing = true;
15594
+ cells.push(v === null || v === void 0 ? VALUE_CELL_MISSING : String(v));
15595
+ }
15596
+ const state = valueState(row);
15597
+ const line = `${[...cells, state].join(" ")}
15598
+ `;
15599
+ if (limit === void 0) {
15600
+ used += Buffer.byteLength(line, "utf-8");
15601
+ if (used > MAX_BYTES) break;
15602
+ } else if (limit > 0 && shown >= limit) {
15603
+ break;
15604
+ }
15605
+ lines.push(line);
15606
+ shown += 1;
15607
+ stateShown = stateShown || state.length > 0;
15608
+ }
15609
+ const total = rows.filter((r) => isRec2(r)).length;
15610
+ let out = head + caveat + wording + lines.join("");
15611
+ if (shown < total) out += valuesTruncated(total, shown, `valuedomain/${model}.json`);
15612
+ if (stateShown) out += VALUE_STATE_FOOTNOTE;
15613
+ if (missing) out += VALUE_FOOTNOTE;
15614
+ return { ok: true, text: out };
15615
+ }
15616
+
15617
+ // src/fde/gate0/aclass.ts
15618
+ import { existsSync as existsSync12, readFileSync as readFileSync12, readdirSync as readdirSync3, statSync as statSync9 } from "fs";
15619
+ import * as path20 from "path";
15620
+
15621
+ // src/fde/gate0/mapping-artifact.ts
15622
+ import { readFileSync as readFileSync11 } from "fs";
15623
+ var MAPPING_ARTIFACT_VERSION = 1;
15624
+ var MappingArtifactError = class extends Error {
15625
+ constructor(reason, message) {
15626
+ super(`[${reason}] ${message}`);
15627
+ this.reason = reason;
15628
+ this.message = message;
15629
+ this.name = "MappingArtifactError";
15630
+ }
15631
+ reason;
15632
+ message;
15633
+ };
15634
+ function isRecord6(value) {
15635
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15636
+ }
15637
+ function readBusinessKeyFields(file) {
15638
+ let text2;
15639
+ try {
15640
+ text2 = readFileSync11(file, "utf8");
15641
+ } catch (e) {
15642
+ const code = e?.code;
15643
+ if (code === "ENOENT") throw new MappingArtifactError("not-found", `\u627E\u4E0D\u5230\u6620\u5C04\u5DE5\u4EF6 ${file}`);
15644
+ throw new MappingArtifactError("unreadable", `${file} \u8BFB\u4E0D\u52A8\uFF08${String(e)}\uFF09`);
15645
+ }
15646
+ if (text2.charCodeAt(0) === 65279) text2 = text2.slice(1);
15647
+ let body;
15648
+ try {
15649
+ body = JSON.parse(text2);
15650
+ } catch (e) {
15651
+ throw new MappingArtifactError("not-json", `${file} \u4E0D\u662F\u5408\u6CD5 JSON\uFF1A${String(e)}`);
15652
+ }
15653
+ if (!isRecord6(body)) {
15654
+ throw new MappingArtifactError("bad-shape", `${file} \u7684\u6839\u4E0D\u662F\u5BF9\u8C61`);
15655
+ }
15656
+ if (!("version" in body)) {
15657
+ throw new MappingArtifactError("version-missing", `${file} \u6CA1\u6709 version \u5B57\u6BB5`);
15658
+ }
15659
+ if (body.version !== MAPPING_ARTIFACT_VERSION) {
15660
+ throw new MappingArtifactError(
15661
+ "unsupported-version",
15662
+ `${file} \u7684 version \u662F ${JSON.stringify(body.version)}\uFF0C\u672C\u5DE5\u5177\u53EA\u8BA4 ${MAPPING_ARTIFACT_VERSION} \u2014\u2014\u300C\u5C3D\u91CF\u6309\u8001\u7248\u672C\u8BFB\u300D\u4F1A\u628A\u65B0\u8BED\u4E49\u9759\u9ED8\u4E22\u6389`
15663
+ );
15664
+ }
15665
+ const models = body.models;
15666
+ if (!Array.isArray(models)) {
15667
+ throw new MappingArtifactError(
15668
+ "bad-shape",
15669
+ `${file} \u7684 models \u5E94\u5F53\u662F\u4E00\u4E2A\u6570\u7EC4\uFF0C\u5B9E\u9645\u662F ${models === null ? "null" : typeof models}`
15670
+ );
15671
+ }
15672
+ if (models.length === 0) {
15673
+ throw new MappingArtifactError(
15674
+ "empty",
15675
+ `${file} \u7684 models \u662F\u7A7A\u7684 \u2014\u2014 \u7A7A\u5DE5\u4EF6\u8DD1\u5B8C\u4EC0\u4E48\u4E5F\u4E0D\u4F1A\u53D1\u751F\uFF0C\u800C\u987E\u95EE\u4F1A\u4EE5\u4E3A\u300C\u5BFC\u8FC7\u4E86\u300D`
15676
+ );
15677
+ }
15678
+ return models.map((raw, i) => {
15679
+ if (!isRecord6(raw)) {
15680
+ throw new MappingArtifactError("bad-shape", `${file} \u7684 models[${i}] \u4E0D\u662F\u5BF9\u8C61`);
15681
+ }
15682
+ const businessKey = raw.businessKey;
15683
+ if (businessKey === void 0 || businessKey === null) return [];
12847
15684
  if (!isRecord6(businessKey)) {
12848
15685
  throw new MappingArtifactError("bad-shape", `${file} \u7684 models[${i}].businessKey \u4E0D\u662F\u5BF9\u8C61`);
12849
15686
  }
@@ -12883,13 +15720,13 @@ var REASON_EMPTY = "empty";
12883
15720
  var CLASS_REASONS = [REASON_UNREAD, REASON_EMPTY];
12884
15721
  function unguardedKinds(problems) {
12885
15722
  const out = /* @__PURE__ */ new Set();
12886
- for (const problem5 of problems) {
12887
- if (!SCOPES.includes(problem5.scope)) {
15723
+ for (const problem6 of problems) {
15724
+ if (!SCOPES.includes(problem6.scope)) {
12888
15725
  throw new Error(
12889
- `\u53F0\u8D26\u7684 scope \u53EA\u6709 ${SCOPES.join("/")} \u4E24\u4E2A\u53D6\u503C\uFF0C\u62FF\u5230\u7684\u662F ${JSON.stringify(problem5.scope)}\uFF08${problem5.message}\uFF09`
15726
+ `\u53F0\u8D26\u7684 scope \u53EA\u6709 ${SCOPES.join("/")} \u4E24\u4E2A\u53D6\u503C\uFF0C\u62FF\u5230\u7684\u662F ${JSON.stringify(problem6.scope)}\uFF08${problem6.message}\uFF09`
12890
15727
  );
12891
15728
  }
12892
- if (problem5.scope === CLASS_SCOPE) for (const kind of problem5.kinds) out.add(kind);
15729
+ if (problem6.scope === CLASS_SCOPE) for (const kind of problem6.kinds) out.add(kind);
12893
15730
  }
12894
15731
  return out;
12895
15732
  }
@@ -12911,10 +15748,10 @@ function scalarsWithin(value) {
12911
15748
  }
12912
15749
  function readText(file, kinds, scope, problems) {
12913
15750
  try {
12914
- return readFileSync9(file, "utf8");
15751
+ return readFileSync12(file, "utf8");
12915
15752
  } catch (e) {
12916
15753
  const code = e?.code;
12917
- const name = path16.basename(file);
15754
+ const name = path20.basename(file);
12918
15755
  problems.push({
12919
15756
  scope,
12920
15757
  reason: REASON_UNREAD,
@@ -12927,7 +15764,7 @@ function readText(file, kinds, scope, problems) {
12927
15764
  function readJsonl(file, kinds, scope, problems) {
12928
15765
  const text2 = readText(file, kinds, scope, problems);
12929
15766
  if (text2 === null) return [];
12930
- const name = path16.basename(file);
15767
+ const name = path20.basename(file);
12931
15768
  const rows = [];
12932
15769
  text2.split("\n").forEach((raw, i) => {
12933
15770
  const line = raw.trim();
@@ -12958,7 +15795,7 @@ function readJsonl(file, kinds, scope, problems) {
12958
15795
  return rows;
12959
15796
  }
12960
15797
  var UNREADABLE = /* @__PURE__ */ Symbol("unreadable");
12961
- function readJson(file, kinds, scope, problems) {
15798
+ function readJson3(file, kinds, scope, problems) {
12962
15799
  const text2 = readText(file, kinds, scope, problems);
12963
15800
  if (text2 === null) return UNREADABLE;
12964
15801
  try {
@@ -12968,13 +15805,13 @@ function readJson(file, kinds, scope, problems) {
12968
15805
  scope,
12969
15806
  reason: REASON_UNREAD,
12970
15807
  kinds,
12971
- message: `\u4EA7\u7269 ${path16.basename(file)} \u4E0D\u662F\u5408\u6CD5 JSON\uFF08${String(e)}\uFF09\u21D2 ${unguardedWord(kinds)} \u8FD9\u51E0\u7C7B\u6B64\u523B\u65E0\u4EBA\u5B88`
15808
+ message: `\u4EA7\u7269 ${path20.basename(file)} \u4E0D\u662F\u5408\u6CD5 JSON\uFF08${String(e)}\uFF09\u21D2 ${unguardedWord(kinds)} \u8FD9\u51E0\u7C7B\u6B64\u523B\u65E0\u4EBA\u5B88`
12972
15809
  });
12973
15810
  return UNREADABLE;
12974
15811
  }
12975
15812
  }
12976
15813
  function listUnder(payload, key, file, kinds, scope, problems) {
12977
- const name = path16.basename(file);
15814
+ const name = path20.basename(file);
12978
15815
  if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
12979
15816
  problems.push({
12980
15817
  scope,
@@ -13010,7 +15847,7 @@ function deriveAclass(root, mappingArtifact = null) {
13010
15847
  const problems = [];
13011
15848
  const out = Object.fromEntries(ACLASS_KINDS.map((k) => [k, /* @__PURE__ */ new Set()]));
13012
15849
  for (const row of readJsonl(
13013
- path16.join(root, ...FIELDS_INDEX),
15850
+ path20.join(root, ...FIELDS_INDEX),
13014
15851
  ["fieldKey", "fieldLabel", "caliber"],
13015
15852
  CLASS_SCOPE,
13016
15853
  problems
@@ -13026,7 +15863,7 @@ function deriveAclass(root, mappingArtifact = null) {
13026
15863
  }
13027
15864
  }
13028
15865
  for (const row of readJsonl(
13029
- path16.join(root, ...ENUM_MIRROR),
15866
+ path20.join(root, ...ENUM_MIRROR),
13030
15867
  ["enumValue"],
13031
15868
  CLASS_SCOPE,
13032
15869
  problems
@@ -13040,8 +15877,8 @@ function deriveAclass(root, mappingArtifact = null) {
13040
15877
  }
13041
15878
  }
13042
15879
  }
13043
- const rosterPath = path16.join(root, ...MODEL_ROSTER);
13044
- const roster = readJson(rosterPath, ["modelName"], CLASS_SCOPE, problems);
15880
+ const rosterPath = path20.join(root, ...MODEL_ROSTER);
15881
+ const roster = readJson3(rosterPath, ["modelName"], CLASS_SCOPE, problems);
13045
15882
  if (roster !== UNREADABLE) {
13046
15883
  const rows = listUnder(roster, "models", rosterPath, ["modelName"], CLASS_SCOPE, problems);
13047
15884
  const entries = modelEntries(roster);
@@ -13068,12 +15905,12 @@ function deriveAclass(root, mappingArtifact = null) {
13068
15905
  });
13069
15906
  }
13070
15907
  }
13071
- const valueDomain = path16.join(root, VALUE_DOMAIN_DIR);
13072
- if (existsSync8(valueDomain) && statSync7(valueDomain).isDirectory()) {
15908
+ const valueDomain = path20.join(root, VALUE_DOMAIN_DIR);
15909
+ if (existsSync12(valueDomain) && statSync9(valueDomain).isDirectory()) {
13073
15910
  const tables = readdirSync3(valueDomain).filter((f) => f.endsWith(".json") && !RESERVED_FILENAMES.includes(f)).sort();
13074
15911
  for (const name of tables) {
13075
- const file = path16.join(valueDomain, name);
13076
- const payload = readJson(file, ["codeValue"], ENTRY_SCOPE, problems);
15912
+ const file = path20.join(valueDomain, name);
15913
+ const payload = readJson3(file, ["codeValue"], ENTRY_SCOPE, problems);
13077
15914
  if (payload === UNREADABLE) continue;
13078
15915
  for (const row of listUnder(payload, "rows", file, ["codeValue"], ENTRY_SCOPE, problems)) {
13079
15916
  if (typeof row !== "object" || row === null || Array.isArray(row)) {
@@ -13138,8 +15975,8 @@ function deriveAclass(root, mappingArtifact = null) {
13138
15975
  }
13139
15976
 
13140
15977
  // src/fde/gate0/facts.ts
13141
- import { existsSync as existsSync9, readFileSync as readFileSync10 } from "fs";
13142
- import * as path17 from "path";
15978
+ import { existsSync as existsSync13, readFileSync as readFileSync13 } from "fs";
15979
+ import * as path21 from "path";
13143
15980
  var REGISTRY_SCOPE = "registry";
13144
15981
  var ENTRY_SCOPE2 = "entry";
13145
15982
  var REASON_NO_ENTRIES = "no-entries";
@@ -13221,9 +16058,9 @@ function loadProtocolFacts(entries = PROTOCOL_FACTS, options = {}) {
13221
16058
  return;
13222
16059
  }
13223
16060
  if (probeRoot !== void 0) {
13224
- const file = path17.join(probeRoot, shape.groups.file);
16061
+ const file = path21.join(probeRoot, shape.groups.file);
13225
16062
  const mark = `${PROBE_MARK_PREFIX} ${shape.groups.mark}`;
13226
- const found = existsSync9(file) && readFileSync10(file, "utf8").includes(mark);
16063
+ const found = existsSync13(file) && readFileSync13(file, "utf8").includes(mark);
13227
16064
  if (!found) {
13228
16065
  problems.push({
13229
16066
  scope: ENTRY_SCOPE2,
@@ -13241,8 +16078,8 @@ function loadProtocolFacts(entries = PROTOCOL_FACTS, options = {}) {
13241
16078
  }
13242
16079
 
13243
16080
  // src/fde/gate0/scan.ts
13244
- import { readFileSync as readFileSync11, readdirSync as readdirSync4, readlinkSync, statSync as statSync8 } from "fs";
13245
- import * as path18 from "path";
16081
+ import { readFileSync as readFileSync14, readdirSync as readdirSync4, readlinkSync, statSync as statSync10 } from "fs";
16082
+ import * as path22 from "path";
13246
16083
  var CHANNEL_ACLASS = "aclass";
13247
16084
  var CHANNEL_ARTIFACT = "artifact-path";
13248
16085
  var CHANNEL_UNREGISTERED = "protocol-unregistered";
@@ -13305,7 +16142,7 @@ var PRODUCT_FILE_RE = new RegExp(
13305
16142
  );
13306
16143
  var PLACEHOLDER_RE2 = /\{[A-Za-z0-9_]*\}/g;
13307
16144
  var ARTIFACT_ROOT = ".hcmnx";
13308
- var RECON_DIRNAME = "recon";
16145
+ var RECON_DIRNAME2 = "recon";
13309
16146
  var RECON_SEGMENTS_BELOW_ROOT = 2;
13310
16147
  var PRODUCT_RELATIVE_SHAPES = [
13311
16148
  ["index", ".md"],
@@ -13381,10 +16218,10 @@ function checkGaps(gaps) {
13381
16218
  return [...gaps];
13382
16219
  }
13383
16220
  function checkPremise(problems) {
13384
- for (const problem5 of problems) {
13385
- if (!PREMISE_REASONS.includes(problem5.reason)) {
16221
+ for (const problem6 of problems) {
16222
+ if (!PREMISE_REASONS.includes(problem6.reason)) {
13386
16223
  throw new Error(
13387
- `\u524D\u63D0\u7EA7\u53F0\u8D26\u7684 reason \u4E0D\u5728\u53D6\u503C\u57DF\u91CC\uFF1A${JSON.stringify(problem5.reason)}\uFF08${problem5.message}\uFF09`
16224
+ `\u524D\u63D0\u7EA7\u53F0\u8D26\u7684 reason \u4E0D\u5728\u53D6\u503C\u57DF\u91CC\uFF1A${JSON.stringify(problem6.reason)}\uFF08${problem6.message}\uFF09`
13388
16225
  );
13389
16226
  }
13390
16227
  }
@@ -13465,7 +16302,7 @@ function artifactReason(token2) {
13465
16302
  const last = segments[segments.length - 1] ?? "";
13466
16303
  if (head.includes(ARTIFACT_ROOT)) return REASON_PRODUCT_TREE_PATH;
13467
16304
  for (let i = 0; i < head.length; i += 1) {
13468
- if (head[i] === RECON_DIRNAME && segments.length - i - 1 > RECON_SEGMENTS_BELOW_ROOT) {
16305
+ if (head[i] === RECON_DIRNAME2 && segments.length - i - 1 > RECON_SEGMENTS_BELOW_ROOT) {
13469
16306
  return REASON_PRODUCT_TREE_PATH;
13470
16307
  }
13471
16308
  }
@@ -13565,9 +16402,9 @@ var Matcher = class {
13565
16402
  };
13566
16403
  function classReasons(problems) {
13567
16404
  const out = /* @__PURE__ */ new Map();
13568
- for (const problem5 of problems ?? []) {
13569
- if (problem5.scope === CLASS_SCOPE) {
13570
- for (const kind of problem5.kinds) out.set(kind, problem5.reason);
16405
+ for (const problem6 of problems ?? []) {
16406
+ if (problem6.scope === CLASS_SCOPE) {
16407
+ for (const kind of problem6.kinds) out.set(kind, problem6.reason);
13571
16408
  }
13572
16409
  }
13573
16410
  return out;
@@ -13720,7 +16557,7 @@ function judgeProtocol(token2, reason, shape, lineno, rel, matcher, index, reds)
13720
16557
  }
13721
16558
  function scan(skillRoot, aclass, facts, options = {}) {
13722
16559
  const reds = [];
13723
- const premise = [];
16560
+ const premise2 = [];
13724
16561
  const gaps = [];
13725
16562
  const scanned = [];
13726
16563
  const matcher = new Matcher(aclass);
@@ -13738,44 +16575,44 @@ function scan(skillRoot, aclass, facts, options = {}) {
13738
16575
  }
13739
16576
  why = ACLASS_EMPTY_WHY[reason];
13740
16577
  }
13741
- premise.push({
16578
+ premise2.push({
13742
16579
  reason: REASON_ACLASS_EMPTY,
13743
16580
  message: `A \u7C7B\u5B50\u96C6 ${kind} \u662F\u7A7A\u7684${why} \u21D2 \u95E8 0 \u5BF9\u8FD9\u4E00\u7C7B**\u6052\u7EFF**\uFF0C\u8FD9\u4E00\u8F6E\u7684\u7EFF\u4E0D\u7B97\u6570`
13744
16581
  });
13745
16582
  }
13746
- for (const problem5 of options.aclassProblems ?? []) {
13747
- if (problem5.scope !== ENTRY_SCOPE) continue;
13748
- premise.push({
16583
+ for (const problem6 of options.aclassProblems ?? []) {
16584
+ if (problem6.scope !== ENTRY_SCOPE) continue;
16585
+ premise2.push({
13749
16586
  reason: REASON_ACLASS_PARTIALLY_UNREAD,
13750
- message: `A \u7C7B\u5B50\u96C6 ${problem5.kinds.join("/")} \u5C11\u4E86\u4E00\u90E8\u5206\uFF08${problem5.reason}\uFF09\uFF1A${problem5.message} \u21D2 \u5C11\u6389\u7684\u90A3\u90E8\u5206\u95E8 0 \u5224\u4E0D\u51FA\u6765\uFF0C\u8FD9\u4E00\u8F6E\u7684\u7EFF\u4E0D\u7B97\u6570`
16587
+ message: `A \u7C7B\u5B50\u96C6 ${problem6.kinds.join("/")} \u5C11\u4E86\u4E00\u90E8\u5206\uFF08${problem6.reason}\uFF09\uFF1A${problem6.message} \u21D2 \u5C11\u6389\u7684\u90A3\u90E8\u5206\u95E8 0 \u5224\u4E0D\u51FA\u6765\uFF0C\u8FD9\u4E00\u8F6E\u7684\u7EFF\u4E0D\u7B97\u6570`
13751
16588
  });
13752
16589
  }
13753
16590
  let factsProblems = options.factsProblems;
13754
16591
  if (factsProblems === void 0) {
13755
- premise.push({
16592
+ premise2.push({
13756
16593
  reason: REASON_CHANNEL_FOUR_UNCHECKED,
13757
16594
  message: "\u6CA1\u6709\u628A loadProtocolFacts \u7684\u53F0\u8D26\u4F20\u8FDB\u6765 \u21D2 \u901A\u9053\u56DB\uFF08\u767B\u8BB0\u9879\u88AB\u62D2\uFF09\u4E00\u6761\u90FD\u6CA1\u67E5\u8FC7\u2014\u2014\u300C\u767B\u8BB0\u518C\u5E72\u51C0\u300D\u4E0E\u300C\u6CA1\u67E5\u767B\u8BB0\u518C\u300D\u5728\u8FD4\u56DE\u503C\u4E0A\u540C\u5F62"
13758
16595
  });
13759
16596
  factsProblems = [];
13760
16597
  }
13761
- for (const problem5 of factsProblems) {
13762
- if (problem5.scope === REGISTRY_SCOPE && PREMISE_REGISTRY_REASONS.includes(problem5.reason)) {
13763
- premise.push({
16598
+ for (const problem6 of factsProblems) {
16599
+ if (problem6.scope === REGISTRY_SCOPE && PREMISE_REGISTRY_REASONS.includes(problem6.reason)) {
16600
+ premise2.push({
13764
16601
  reason: REASON_REGISTRY,
13765
- message: `\u767B\u8BB0\u518C\u8FD9\u4E00\u5C42\u6CA1\u7ACB\u4F4F\uFF08${problem5.reason}\uFF09\uFF1A${problem5.message} \u21D2 \u8C41\u514D\u901A\u9053 P \u4E0D\u53EF\u4FE1`
16602
+ message: `\u767B\u8BB0\u518C\u8FD9\u4E00\u5C42\u6CA1\u7ACB\u4F4F\uFF08${problem6.reason}\uFF09\uFF1A${problem6.message} \u21D2 \u8C41\u514D\u901A\u9053 P \u4E0D\u53EF\u4FE1`
13766
16603
  });
13767
16604
  }
13768
16605
  }
13769
- for (const problem5 of factsProblems) {
13770
- if (problem5.scope === REGISTRY_SCOPE) continue;
16606
+ for (const problem6 of factsProblems) {
16607
+ if (problem6.scope === REGISTRY_SCOPE) continue;
13771
16608
  reds.push({
13772
16609
  channel: CHANNEL_NO_PROBE,
13773
16610
  reason: REASON_REJECTED_REGISTRATION,
13774
- token: problem5.token ?? `(\u7B2C${problem5.index}\u6761)`,
16611
+ token: problem6.token ?? `(\u7B2C${problem6.index}\u6761)`,
13775
16612
  path: null,
13776
16613
  line: 0,
13777
16614
  kinds: [],
13778
- message: `\u767B\u8BB0\u518C\u7B2C ${problem5.index} \u6761\u88AB\u62D2\uFF08${problem5.reason}\uFF09\uFF1A${problem5.message}`
16615
+ message: `\u767B\u8BB0\u518C\u7B2C ${problem6.index} \u6761\u88AB\u62D2\uFF08${problem6.reason}\uFF09\uFF1A${problem6.message}`
13779
16616
  });
13780
16617
  }
13781
16618
  for (const token2 of [...facts].sort()) {
@@ -13793,7 +16630,7 @@ function scan(skillRoot, aclass, facts, options = {}) {
13793
16630
  }
13794
16631
  let files = [];
13795
16632
  if (!isDirectory(skillRoot)) {
13796
- premise.push({
16633
+ premise2.push({
13797
16634
  reason: REASON_NO_SKILL_ROOT,
13798
16635
  message: `\u626B\u63CF\u9762 ${skillRoot} \u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55 \u21D2 \u4E00\u4E2A\u5B57\u90FD\u6CA1\u626B\u8FC7\uFF08\u8FD9\u4E0D\u662F\u300C\u626B\u8FC7\u3001\u5E72\u51C0\u300D\uFF09`
13799
16636
  });
@@ -13807,13 +16644,13 @@ function scan(skillRoot, aclass, facts, options = {}) {
13807
16644
  } catch {
13808
16645
  target = "(\u8BFB\u4E0D\u51FA\u94FE\u63A5\u76EE\u6807)";
13809
16646
  }
13810
- premise.push({
16647
+ premise2.push({
13811
16648
  reason: REASON_SYMLINK_NOT_SCANNED,
13812
- message: `${path18.relative(skillRoot, link)} \u662F\u4E00\u4E2A\u7B26\u53F7\u94FE\u63A5\uFF08\u6307\u5411 ${JSON.stringify(target)}\uFF09\u21D2 \u95E8 0 **\u6CA1\u6709\u987A\u7740\u5B83\u626B\u8FC7\u4E00\u4E2A\u5B57**\uFF0C\u8FD9\u4E00\u8F6E\u7684\u7EFF\u4E0D\u7B97\u6570\u3002\u51FA\u8DEF\uFF1A\u628A\u8FD9\u6761\u94FE\u4ECE skill \u91CC\u53BB\u6389 \u2014\u2014 \u94FE\u540E\u9762\u90A3\u4EFD\u5185\u5BB9\u672C\u8BE5\u88AB\u5224\u5C31 \`cp -RL\` \u62F7\u6210\u771F\u5185\u5BB9\uFF08\u26A0\uFE0F \u73AF\u8DEF\u4E0E\u65AD\u94FE\u4E0A\u5B83\u4F1A\u5F53\u573A\u62A5\u9519\uFF0C\u90A3\u4E24\u79CD\u76F4\u63A5\u5220\uFF09\uFF1B\u5185\u5BB9\u5DF2\u7ECF\u5728 skill \u91CC\uFF08\u6307\u5411\u540C\u6811\u7684\u522B\u540D\uFF09\u4E5F\u76F4\u63A5\u5220\u3002**\u4E0D\u8DDF\u968F**\u662F\u523B\u610F\u7684 \u2014\u2014 \u8DDF\u8FC7\u53BB\u4F1A\u8FDE\u4E0A\u73AF\u8DEF\u3001\u6216\u8D8A\u51FA skill \u76EE\u5F55\u626B\u5230\u65E0\u5173\u6587\u4EF6`
16649
+ message: `${path22.relative(skillRoot, link)} \u662F\u4E00\u4E2A\u7B26\u53F7\u94FE\u63A5\uFF08\u6307\u5411 ${JSON.stringify(target)}\uFF09\u21D2 \u95E8 0 **\u6CA1\u6709\u987A\u7740\u5B83\u626B\u8FC7\u4E00\u4E2A\u5B57**\uFF0C\u8FD9\u4E00\u8F6E\u7684\u7EFF\u4E0D\u7B97\u6570\u3002\u51FA\u8DEF\uFF1A\u628A\u8FD9\u6761\u94FE\u4ECE skill \u91CC\u53BB\u6389 \u2014\u2014 \u94FE\u540E\u9762\u90A3\u4EFD\u5185\u5BB9\u672C\u8BE5\u88AB\u5224\u5C31 \`cp -RL\` \u62F7\u6210\u771F\u5185\u5BB9\uFF08\u26A0\uFE0F \u73AF\u8DEF\u4E0E\u65AD\u94FE\u4E0A\u5B83\u4F1A\u5F53\u573A\u62A5\u9519\uFF0C\u90A3\u4E24\u79CD\u76F4\u63A5\u5220\uFF09\uFF1B\u5185\u5BB9\u5DF2\u7ECF\u5728 skill \u91CC\uFF08\u6307\u5411\u540C\u6811\u7684\u522B\u540D\uFF09\u4E5F\u76F4\u63A5\u5220\u3002**\u4E0D\u8DDF\u968F**\u662F\u523B\u610F\u7684 \u2014\u2014 \u8DDF\u8FC7\u53BB\u4F1A\u8FDE\u4E0A\u73AF\u8DEF\u3001\u6216\u8D8A\u51FA skill \u76EE\u5F55\u626B\u5230\u65E0\u5173\u6587\u4EF6`
13813
16650
  });
13814
16651
  }
13815
16652
  if (files.length === 0) {
13816
- premise.push({
16653
+ premise2.push({
13817
16654
  reason: REASON_NOTHING_SCANNED,
13818
16655
  message: `\u626B\u63CF\u9762 ${skillRoot} \u5728\u76D8\u4E0A\uFF0C\u4F46\u91CC\u9762\u4E00\u4E2A\u6587\u4EF6\u90FD\u6CA1\u6709 \u2014\u2014 \u67E5\u8FC7\u4E14\u4E3A\u7A7A`
13819
16656
  });
@@ -13822,15 +16659,15 @@ function scan(skillRoot, aclass, facts, options = {}) {
13822
16659
  for (const file of files) {
13823
16660
  let text2;
13824
16661
  try {
13825
- text2 = readFileSync11(file, "utf8");
16662
+ text2 = readFileSync14(file, "utf8");
13826
16663
  } catch (e) {
13827
- premise.push({
16664
+ premise2.push({
13828
16665
  reason: REASON_FILE_UNREADABLE,
13829
16666
  message: `${file} \u8BFB\u4E0D\u52A8\uFF08${String(e)}\uFF09\u21D2 \u5224\u4E0D\u4E86\u5B83\u5E72\u4E0D\u5E72\u51C0\uFF0C\u95E8 0 \u4E0D\u80FD\u5BF9\u7740\u5B83\u8BF4\u7EFF`
13830
16667
  });
13831
16668
  continue;
13832
16669
  }
13833
- const rel = path18.relative(skillRoot, file);
16670
+ const rel = path22.relative(skillRoot, file);
13834
16671
  scanned.push(rel);
13835
16672
  text2.split("\n").forEach((line, i) => {
13836
16673
  judgeLine(line, i + 1, rel, matcher, index, reds, gaps);
@@ -13852,12 +16689,12 @@ function scan(skillRoot, aclass, facts, options = {}) {
13852
16689
  channels,
13853
16690
  scanned,
13854
16691
  gaps: checkGaps(gaps),
13855
- premise: checkPremise(premise)
16692
+ premise: checkPremise(premise2)
13856
16693
  };
13857
16694
  }
13858
16695
  function isDirectory(target) {
13859
16696
  try {
13860
- return statSync8(target).isDirectory();
16697
+ return statSync10(target).isDirectory();
13861
16698
  } catch {
13862
16699
  return false;
13863
16700
  }
@@ -13867,10 +16704,10 @@ function walk3(root) {
13867
16704
  const unscannedLinks = [];
13868
16705
  const visit = (dir) => {
13869
16706
  for (const entry of readdirSync4(dir, { withFileTypes: true })) {
13870
- const full = path18.join(dir, entry.name);
16707
+ const full = path22.join(dir, entry.name);
13871
16708
  let followed = null;
13872
16709
  try {
13873
- followed = statSync8(full);
16710
+ followed = statSync10(full);
13874
16711
  } catch {
13875
16712
  followed = null;
13876
16713
  }
@@ -13951,8 +16788,8 @@ function buildCarrierResult(carrier, verdict, options = {}) {
13951
16788
  }
13952
16789
 
13953
16790
  // src/fde/triage/probe.ts
13954
- import { readFileSync as readFileSync12 } from "fs";
13955
- import * as path19 from "path";
16791
+ import { readFileSync as readFileSync15 } from "fs";
16792
+ import * as path23 from "path";
13956
16793
  var WORKSPACES_PATH = "/api/tenant-extension/workspaces";
13957
16794
  var MODELS_REL = "models.json";
13958
16795
  var FIELDS_REL = "index/fields.jsonl";
@@ -13975,10 +16812,10 @@ function unavailableCell(carrier, err) {
13975
16812
  });
13976
16813
  }
13977
16814
  function readArtifactJson(dir, rel) {
13978
- return JSON.parse(readFileSync12(path19.join(dir, rel), "utf8"));
16815
+ return JSON.parse(readFileSync15(path23.join(dir, rel), "utf8"));
13979
16816
  }
13980
16817
  function readArtifactJsonl(dir, rel) {
13981
- const body = readFileSync12(path19.join(dir, rel), "utf8");
16818
+ const body = readFileSync15(path23.join(dir, rel), "utf8");
13982
16819
  const rows = [];
13983
16820
  for (const line of body.split("\n")) {
13984
16821
  const trimmed = line.trim();
@@ -14133,7 +16970,7 @@ var CONFIG = "CONFIG";
14133
16970
  function fill(template, value) {
14134
16971
  return template.replace("{}", value);
14135
16972
  }
14136
- function problem4(rule, note) {
16973
+ function problem5(rule, note) {
14137
16974
  return { rule, note };
14138
16975
  }
14139
16976
  function cellsOf(entry) {
@@ -14148,13 +16985,13 @@ function withVerdict(cells, want) {
14148
16985
  function checkR1(entry) {
14149
16986
  const out = [];
14150
16987
  for (const field of REQUIRED_SECTIONS) {
14151
- if (!entry[field]) out.push(problem4("R1", fill(R1_MISSING_SECTION, field)));
16988
+ if (!entry[field]) out.push(problem5("R1", fill(R1_MISSING_SECTION, field)));
14152
16989
  }
14153
16990
  const cells = cellsOf(entry);
14154
16991
  for (const key of CARRIER_KEYS) {
14155
16992
  const cell = cells[key];
14156
16993
  if (!cell || typeof cell !== "object" || !cell.verdict) {
14157
- out.push(problem4("R1", fill(R1_EMPTY_CELL, key)));
16994
+ out.push(problem5("R1", fill(R1_EMPTY_CELL, key)));
14158
16995
  }
14159
16996
  }
14160
16997
  return out;
@@ -14163,19 +17000,19 @@ function checkR2(entry) {
14163
17000
  if (entry.verdict !== GAP) return [];
14164
17001
  const hits = withVerdict(cellsOf(entry), CARRIER_HIT);
14165
17002
  if (hits.length === 0) return [];
14166
- return [problem4("R2", fill(R2_HITS_UNDER_GAP, hits.join("\u3001")))];
17003
+ return [problem5("R2", fill(R2_HITS_UNDER_GAP, hits.join("\u3001")))];
14167
17004
  }
14168
17005
  function checkR3(entry) {
14169
17006
  if (entry.verdict !== CONFIG) return [];
14170
17007
  if (withVerdict(cellsOf(entry), CARRIER_HIT).length > 0) return [];
14171
- return [problem4("R3", R3_CONFIG_WITHOUT_HIT)];
17008
+ return [problem5("R3", R3_CONFIG_WITHOUT_HIT)];
14172
17009
  }
14173
17010
  function checkR4(entry) {
14174
17011
  if (entry.verdict !== GAP) return [];
14175
17012
  const blinds = withVerdict(cellsOf(entry), CARRIER_BLIND);
14176
17013
  if (blinds.length === 0) return [];
14177
17014
  if (entry.blindAcknowledged) return [];
14178
- return [problem4("R4", fill(R4_BLIND_AS_GAP, blinds.join("\u3001")))];
17015
+ return [problem5("R4", fill(R4_BLIND_AS_GAP, blinds.join("\u3001")))];
14179
17016
  }
14180
17017
  var RULES = [checkR1, checkR2, checkR3, checkR4];
14181
17018
  function checkCoherence(entry) {
@@ -14185,7 +17022,7 @@ function checkCoherence(entry) {
14185
17022
  }
14186
17023
 
14187
17024
  // src/fde/triage/report.ts
14188
- var VERDICTS = ["REUSE", "CONFIG", "EXTEND", "GAP"];
17025
+ var VERDICTS3 = ["REUSE", "CONFIG", "EXTEND", "GAP"];
14189
17026
  var GAP2 = "GAP";
14190
17027
  var DEBT_PREFIX = "# DEBT: \u7F3A ";
14191
17028
  var DEBT_UNKNOWN = "\uFF08\u8FD8\u8BF4\u4E0D\u51FA\u7F3A\u54EA\u4E2A Action \u2014\u2014 \u7559\u75D5\u5148\uFF0C\u522B\u8BA9\u8FD9\u6761 GAP \u4ECE\u6E05\u5355\u91CC\u6D88\u5931\uFF09";
@@ -14210,9 +17047,9 @@ function require_(entry, idx) {
14210
17047
  }
14211
17048
  }
14212
17049
  const verdict = entry.verdict;
14213
- if (!VERDICTS.includes(verdict)) {
17050
+ if (!VERDICTS3.includes(verdict)) {
14214
17051
  throw new Error(
14215
- `\u7B2C ${idx} \u6761\u7684\u7ED3\u8BBA ${JSON.stringify(verdict)} \u4E0D\u5728\u53D6\u503C\u57DF ${VERDICTS.join("\u3001")} \u5185`
17052
+ `\u7B2C ${idx} \u6761\u7684\u7ED3\u8BBA ${JSON.stringify(verdict)} \u4E0D\u5728\u53D6\u503C\u57DF ${VERDICTS3.join("\u3001")} \u5185`
14216
17053
  );
14217
17054
  }
14218
17055
  const cells = entry.cells ?? {};
@@ -14300,12 +17137,20 @@ async function runTriageRound(probe, artifactsDir, entriesIn) {
14300
17137
  export {
14301
17138
  ACLASS_EMPTY_WHY,
14302
17139
  ACLASS_KINDS,
17140
+ ADVISORY_CODES,
17141
+ AGREEING_VERDICTS,
17142
+ APPLY_CAVEAT,
17143
+ APPLY_PROBLEM_CODES,
17144
+ PROBLEM_CODES as ARTIFACT_PROBLEM_CODES,
14303
17145
  ARTIFACT_ROOT,
14304
17146
  ARTIFACT_SUFFIXES,
14305
17147
  ARTIFACT_WORDING,
14306
17148
  AUTH_INFO_PATH,
17149
+ ApplyInvariantError,
17150
+ ApplyPremiseError,
14307
17151
  BLIND_SPOTS,
14308
17152
  BLOCKING_CODES,
17153
+ BUCKETS,
14309
17154
  CARRIER_BLIND,
14310
17155
  CARRIER_HIT,
14311
17156
  CARRIER_KEYS,
@@ -14313,12 +17158,14 @@ export {
14313
17158
  CARRIER_MISS,
14314
17159
  CARRIER_UNAVAILABLE,
14315
17160
  CARRIER_VERDICTS,
17161
+ CAUSE_INCOMPLETE_CURRENT,
14316
17162
  CHANNELS,
14317
17163
  CHANNEL_ACLASS,
14318
17164
  CHANNEL_ARTIFACT,
14319
17165
  CHANNEL_NO_PROBE,
14320
17166
  CHANNEL_REGISTERED_IS_ACLASS,
14321
17167
  CHANNEL_UNREGISTERED,
17168
+ CHECK_GROUPS2 as CHECK_GROUPS,
14322
17169
  CLASS_REASONS,
14323
17170
  CLASS_SCOPE,
14324
17171
  CliError,
@@ -14328,14 +17175,27 @@ export {
14328
17175
  DEBT_UNKNOWN,
14329
17176
  DEFAULT_AGENT_ID,
14330
17177
  DEFAULT_SESSION_TTL_SECONDS,
17178
+ PREMISE_CODES4 as DELIVERY_PREMISE_CODES,
17179
+ DIMENSION_LABELS,
14331
17180
  DOCTOR_ANCHORS,
17181
+ DRY_RUN_NOTE,
17182
+ DRY_RUN_TAIL,
17183
+ DriftDetected,
14332
17184
  ENDPOINT_PREFIXES,
14333
17185
  ENTRY_SCOPE,
14334
17186
  ENUM_ELEMENT_KEYS,
17187
+ ENUM_SHOW,
17188
+ EXEMPTIBLE_CODES,
17189
+ EXEMPTION_CODES,
17190
+ EXEMPTION_REQUIRED_KEYS,
14335
17191
  EXTENSION_SOURCE_HEADER,
14336
17192
  ExitCode,
14337
17193
  FACTS_REASONS,
17194
+ FIND_LIMIT,
17195
+ MAX_BYTES as FIND_MAX_BYTES,
14338
17196
  FOLDED_NOTE,
17197
+ FORCE_STALE_FLAG,
17198
+ FORCE_STALE_FLAG_TEXT,
14339
17199
  FULLWIDTH_ALNUM_RANGES,
14340
17200
  GAP_CJK_INSIDE_LONGER_RUN,
14341
17201
  GAP_NOISE_TOKEN,
@@ -14344,10 +17204,20 @@ export {
14344
17204
  HcmClient,
14345
17205
  IMPORT_PLAN_FILE,
14346
17206
  INIT_EXIT_CODES,
17207
+ JOURNAL_FILE,
17208
+ JOURNAL_STOP_KINDS,
17209
+ JOURNAL_STOP_UNKNOWN,
17210
+ Journal,
17211
+ JournalError,
14347
17212
  KIT_CARRY_OVER_KEY,
14348
17213
  KIT_CRAWLED_AT_FILE,
17214
+ KIT_MATCHED_ON,
17215
+ LEASE_FILE,
14349
17216
  LEDGER_MISSING_WORD,
17217
+ LEDGER_ONLY_FLAG,
14350
17218
  LayoutContainmentError,
17219
+ Lease,
17220
+ LeaseViolation,
14351
17221
  MANIFEST_PATH,
14352
17222
  MAPPING_ARTIFACT_VERSION,
14353
17223
  MAPPING_FILE,
@@ -14364,10 +17234,26 @@ export {
14364
17234
  MappingArtifactError,
14365
17235
  MappingError,
14366
17236
  Matcher,
17237
+ NETWORK_GATES,
17238
+ NEXT_STEP,
17239
+ NOT_COVERED_LAYER1,
17240
+ NOT_COVERED_LAYER2,
17241
+ NOT_COVERED_SELF,
14367
17242
  OFFLINE_COMMANDS,
17243
+ ON_EXISTING,
14368
17244
  PASSWORD_CHANGE_REQUIRED,
17245
+ PLAN_JSON_KEYS,
17246
+ PLAN_PROBLEM_CODES,
17247
+ PREMISE_CLIENT,
17248
+ PREMISE_IDENTITY,
17249
+ PREMISE_JOURNAL_HAS_ENTRIES,
17250
+ PREMISE_JOURNAL_ON_DISK,
17251
+ PREMISE_KEY_FIELDS,
17252
+ PREMISE_PLAN_READABLE,
14369
17253
  PREMISE_REASONS,
14370
17254
  PREMISE_REGISTRY_REASONS,
17255
+ PREMISE_ROWS_TO_CHECK,
17256
+ PREMISE_UNMET,
14371
17257
  PROACTIVE_REFRESH_MARGIN_SECONDS,
14372
17258
  PROBE_MARK_PREFIX,
14373
17259
  PRODUCT_RELATIVE_SHAPES,
@@ -14375,6 +17261,7 @@ export {
14375
17261
  PROTOCOL_FACTS,
14376
17262
  PlanReadError,
14377
17263
  RC_DECIDING_FIELDS,
17264
+ RC_DECIDING_REPORT_FIELDS,
14378
17265
  REASON_DUPLICATE_TOKEN,
14379
17266
  REASON_EMPTY,
14380
17267
  REASON_NO_ENTRIES,
@@ -14382,12 +17269,14 @@ export {
14382
17269
  REASON_PROBE_SHAPE,
14383
17270
  REASON_PROBE_UNVERIFIED,
14384
17271
  REASON_UNREAD,
14385
- RECON_DIRNAME,
17272
+ VERDICTS2 as RECONCILE_VERDICTS,
17273
+ RECON_DIRNAME2 as RECON_DIRNAME,
14386
17274
  RECON_SEGMENTS_BELOW_ROOT,
14387
17275
  RED_REASONS,
14388
17276
  REGISTRY_REASONS,
14389
17277
  REGISTRY_SCOPE,
14390
17278
  REQUIRED_SECTIONS,
17279
+ RISK_CODES,
14391
17280
  RISK_FILE,
14392
17281
  ROUND_ANCHORS,
14393
17282
  ROUND_EXIT_CODES,
@@ -14401,20 +17290,43 @@ export {
14401
17290
  SCOPES,
14402
17291
  SDK_VERSION,
14403
17292
  SEGMENT_SEPARATOR,
17293
+ STATUSES,
17294
+ STEP_NOTHING,
17295
+ STEP_STOP,
17296
+ SYNTH_FOOTNOTE,
17297
+ SYNTH_MARK,
14404
17298
  CONFIG as TRIAGE_CONFIG,
14405
17299
  GAP as TRIAGE_GAP,
14406
- VERDICTS as TRIAGE_VERDICTS,
17300
+ VERDICTS3 as TRIAGE_VERDICTS,
14407
17301
  TargetModelNotFound,
14408
17302
  TokenStore,
17303
+ VALUE_CELL_MISSING,
17304
+ VALUE_FOOTNOTE,
17305
+ VALUE_STATE_DISABLED,
17306
+ VALUE_STATE_FOOTNOTE,
17307
+ VALUE_STATE_UNKNOWN,
17308
+ VERDICTS,
17309
+ VERDICT_DIVERGED,
17310
+ VERDICT_INCOMPARABLE,
17311
+ VERDICT_SAME,
17312
+ VERDICT_WORDS,
14409
17313
  VERSION_PATH,
17314
+ ValueHints,
17315
+ WAIVER_REPLAY,
14410
17316
  WARNED_ROUND_STATES,
14411
17317
  WORKSPACES_PATH,
14412
17318
  WORK_DIRNAME,
14413
17319
  WsClient,
14414
17320
  absoluteDownloadUrl,
17321
+ acquireLease,
14415
17322
  adminResetPassword,
17323
+ applyPlan,
17324
+ applyRc,
17325
+ applyReportText,
17326
+ applyReportToJson,
14416
17327
  archiveDir,
14417
17328
  artifactReason,
17329
+ askedTheDatabase,
14418
17330
  assertSafeReferencePath,
14419
17331
  assertSafeSkillFilePath,
14420
17332
  assertSafeSkillId,
@@ -14424,10 +17336,12 @@ export {
14424
17336
  buildAnswer,
14425
17337
  buildCarrierResult,
14426
17338
  buildConfirm,
17339
+ buildDeliveryRun,
14427
17340
  buildInterrupt,
14428
17341
  buildMiniAppTemplateFiles,
14429
17342
  buildMiniPreviewTargets,
14430
17343
  buildMiniVerifyAgentReport,
17344
+ buildReconciliation,
14431
17345
  buildReject,
14432
17346
  buildResumeSummary,
14433
17347
  buildSteer,
@@ -14458,9 +17372,11 @@ export {
14458
17372
  deleteIdentity,
14459
17373
  deleteTenantMeta,
14460
17374
  deleteWorkspaceFile,
17375
+ deliveryRunFields,
14461
17376
  deriveAclass,
14462
17377
  deriveNamelessToolLabel,
14463
17378
  describePrincipal,
17379
+ describeWaiver,
14464
17380
  detectDelegationPause,
14465
17381
  detectDirectInteractionPending,
14466
17382
  detectPasswordChangeChallenge,
@@ -14468,10 +17384,12 @@ export {
14468
17384
  displayWidth,
14469
17385
  downloadDocument,
14470
17386
  endpointsIn,
17387
+ enforceDriftGate,
14471
17388
  ensureSessionFresh,
14472
17389
  envDir,
14473
17390
  envFile,
14474
17391
  envsDir,
17392
+ existingJournalStop,
14475
17393
  exitCode,
14476
17394
  exitCodeFor,
14477
17395
  extractNextSteps,
@@ -14485,6 +17403,7 @@ export {
14485
17403
  fetchSkillMarkdown,
14486
17404
  fetchSkillReference,
14487
17405
  filterByStage,
17406
+ find,
14488
17407
  findLastAssistantSeq,
14489
17408
  flattenSkills,
14490
17409
  foldConfusables,
@@ -14500,9 +17419,11 @@ export {
14500
17419
  globalConfigFile,
14501
17420
  guessMimeType,
14502
17421
  hcmConfigDir,
17422
+ hitRank,
14503
17423
  httpProbe,
14504
17424
  identitiesDir,
14505
17425
  identityDir,
17426
+ identityKnown,
14506
17427
  identityMetaFile,
14507
17428
  inGap,
14508
17429
  inferEnvName,
@@ -14511,8 +17432,13 @@ export {
14511
17432
  inspectRound,
14512
17433
  isCjk,
14513
17434
  isDelegationToolName,
17435
+ isLocalName,
14514
17436
  isReadOnly,
14515
17437
  isServerSlidingSession,
17438
+ isZeroNetwork,
17439
+ journalNote,
17440
+ judgeDrift,
17441
+ ledgerOnlySignpost,
14516
17442
  listEnvs,
14517
17443
  listIdentities,
14518
17444
  listModels,
@@ -14524,14 +17450,19 @@ export {
14524
17450
  loadExemptions,
14525
17451
  loadGlobalConfig,
14526
17452
  loadIdentity,
17453
+ loadMapping,
14527
17454
  loadProfile,
14528
17455
  loadProtocolFacts,
17456
+ loadRecordedFingerprint,
17457
+ loadRows,
14529
17458
  loadWorkspaceFileContent,
14530
17459
  loginClientCredentials,
14531
17460
  loginPairing,
14532
17461
  loginPassword,
14533
17462
  loginPat,
17463
+ matchNote,
14534
17464
  matchSkills,
17465
+ matchedDimensions,
14535
17466
  migrateLegacyProfiles,
14536
17467
  modelEntries,
14537
17468
  modelKeys,
@@ -14539,6 +17470,7 @@ export {
14539
17470
  newRoundId,
14540
17471
  normalize,
14541
17472
  normalizeReferences,
17473
+ notAsked,
14542
17474
  oneShot,
14543
17475
  parseConfirmToolName,
14544
17476
  parseFixture,
@@ -14553,6 +17485,7 @@ export {
14553
17485
  planProblemLines,
14554
17486
  planRc,
14555
17487
  planSummaryLine,
17488
+ planVsBaselinePremise,
14556
17489
  probeAll,
14557
17490
  probeExtensionSource,
14558
17491
  profileDir,
@@ -14565,14 +17498,17 @@ export {
14565
17498
  readPullManifest,
14566
17499
  refreshToken,
14567
17500
  remove,
17501
+ renderFind,
14568
17502
  renderRound,
14569
17503
  renderTriage,
17504
+ renderValues,
14570
17505
  replHistoryFile,
14571
17506
  resetSettingItem,
14572
17507
  resolveActiveEnv,
14573
17508
  resolveActiveIdentity,
14574
17509
  resolveActiveProfile,
14575
17510
  resolveAllSkillsInstallOrder,
17511
+ resolveBaselineDir,
14576
17512
  resolveChironBase,
14577
17513
  resolveRefs,
14578
17514
  resolveSkillInstallOrder,
@@ -14598,6 +17534,7 @@ export {
14598
17534
  seedWorkDir,
14599
17535
  segmentsOf,
14600
17536
  sendMessageAndStream,
17537
+ shelfPartition,
14601
17538
  snakeToCamel,
14602
17539
  tenantSegment,
14603
17540
  toJson,
@@ -14610,6 +17547,11 @@ export {
14610
17547
  update,
14611
17548
  uploadDocument,
14612
17549
  validateMiniProject,
17550
+ valueState,
17551
+ valuesRoundCaveat,
17552
+ verifyAttention,
17553
+ verifyRc,
17554
+ verifyText,
14613
17555
  writeImportPlan,
14614
17556
  writeRisk
14615
17557
  };