@hcmai/sdk 0.4.4 → 0.4.5

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
@@ -179,24 +179,37 @@ var TokenStore = class _TokenStore {
179
179
  }
180
180
  }
181
181
  async setAccessToken(token2) {
182
- if (await this.canUseKeychain()) {
183
- const keytar = await loadKeytar();
184
- if (!keytar) return this.writeTokenFile("access", token2);
185
- const account = `${this.keychainAccountPrefix()}/access`;
186
- await keytar.setPassword(SERVICE_PREFIX, account, token2);
187
- return `keychain:${SERVICE_PREFIX}/${account}`;
188
- }
189
- return this.writeTokenFile("access", token2);
182
+ return this.storeToken("access", token2);
190
183
  }
191
184
  async setRefreshToken(token2) {
192
- if (await this.canUseKeychain()) {
193
- const keytar = await loadKeytar();
194
- if (!keytar) return this.writeTokenFile("refresh", token2);
195
- const account = `${this.keychainAccountPrefix()}/refresh`;
185
+ return this.storeToken("refresh", token2);
186
+ }
187
+ /**
188
+ * 把一枚 token 存到能存的地方 —— 优先钥匙串,存不进就落 0600 文件。
189
+ *
190
+ * 🔴 **承重的那个操作自己就是探针**。原先的写法是「先 `getPassword` 探一下,
191
+ * 不抛就当钥匙串可用,然后**不设防**地 `setPassword`」——
192
+ * 那是**用读探针证写能力**,而这两件事在真机上会分家:
193
+ * `HOME` 不指向本人家目录时(SSH 会话 / 容器 / `sudo` / 换 `HOME` 跑),
194
+ * `getPassword` 返回 **`null` 而不抛**(「没找到」与「根本够不着」在这个 API 上同形),
195
+ * 探针于是判「可用」,紧接着 `setPassword` 抛一个 keytar 未映射的 OSStatus,
196
+ * 整条登录中止 —— 而那时**一次性配对码已经消费掉了**,屏幕上只有一句
197
+ * `An unknown error occurred.`(那句话来自 keytar 原生模块,不是本 CLI 的文案,
198
+ * 所以连错误码和 traceId 都没有)。issue #79。
199
+ *
200
+ * ⇒ 不再有单独的探针,也就不再有「探针探 A、承重靠 B」那道缝:
201
+ * 直接写,抛了就落回文件。下面那条兜底原本**永远够不到**,现在够得到了。
202
+ */
203
+ async storeToken(kind, token2) {
204
+ const keytar = await loadKeytar();
205
+ if (!keytar) return this.writeTokenFile(kind, token2);
206
+ const account = `${this.keychainAccountPrefix()}/${kind}`;
207
+ try {
196
208
  await keytar.setPassword(SERVICE_PREFIX, account, token2);
197
- return `keychain:${SERVICE_PREFIX}/${account}`;
209
+ } catch (e) {
210
+ return this.writeTokenFile(kind, token2, e);
198
211
  }
199
- return this.writeTokenFile("refresh", token2);
212
+ return `keychain:${SERVICE_PREFIX}/${account}`;
200
213
  }
201
214
  async getAccessToken() {
202
215
  if (process.env.HCM_PAT) return process.env.HCM_PAT;
@@ -249,22 +262,20 @@ var TokenStore = class _TokenStore {
249
262
  if (ref.startsWith("plain:")) return ref.slice("plain:".length);
250
263
  return null;
251
264
  }
252
- async canUseKeychain() {
253
- const keytar = await loadKeytar();
254
- if (!keytar) return false;
255
- try {
256
- await keytar.getPassword(SERVICE_PREFIX, "__probe__");
257
- return true;
258
- } catch {
259
- return false;
260
- }
261
- }
262
- async writeTokenFile(kind, token2) {
265
+ /**
266
+ * 兜底:0600 文件。
267
+ *
268
+ * 🔴 `cause` 分开两档措辞,**不许合并**:「这台机器上没有 keytar」是常态
269
+ * (Linux 无 libsecret 等),「有 keytar 但写不进去」是异常,顾问的下一步不同 ——
270
+ * 后者必须把原始报错**原样转述**出来,否则他看到的还是一句没有出处的话。
271
+ */
272
+ async writeTokenFile(kind, token2, cause) {
263
273
  const file = `${this.metaFile()}.${kind}`;
264
274
  await fs.mkdir(this.dataDir(), { recursive: true });
265
275
  await fs.writeFile(file, token2, { mode: 384 });
266
276
  if (kind === "access") {
267
- console.warn(`[hcm] WARNING: OS keychain unavailable. Token saved to ${file} (0600).`);
277
+ const why = cause === void 0 ? "OS keychain unavailable" : `OS keychain refused the write (${cause instanceof Error ? cause.message : String(cause)})`;
278
+ console.warn(`[hcm] WARNING: ${why}. Token saved to ${file} (0600).`);
268
279
  }
269
280
  return `file:${file}`;
270
281
  }
@@ -5200,6 +5211,32 @@ async function clearMetaCache(http, model, opts = {}) {
5200
5211
  return resp.data?.data ?? resp.data;
5201
5212
  }
5202
5213
 
5214
+ // src/script.ts
5215
+ function unwrap(data) {
5216
+ const body = data;
5217
+ return (body && typeof body === "object" && "data" in body ? body.data : data) ?? data;
5218
+ }
5219
+ async function scriptDryRun(http, request) {
5220
+ const resp = await http.post("/api/script/dry-run", request);
5221
+ return unwrap(resp.data);
5222
+ }
5223
+ async function validateScriptManifest(http, manifestYaml) {
5224
+ const resp = await http.post("/api/script/manifest/validate", { manifestYaml });
5225
+ return unwrap(resp.data);
5226
+ }
5227
+ async function queryScriptLogs(http, query2 = {}) {
5228
+ const params = {};
5229
+ for (const [k, v] of Object.entries(query2)) {
5230
+ if (v !== void 0 && v !== null && v !== "") params[k] = v;
5231
+ }
5232
+ const resp = await http.get("/api/script-logs", { params });
5233
+ return unwrap(resp.data);
5234
+ }
5235
+ async function getScriptTask(http, taskId) {
5236
+ const resp = await http.get(`/api/script-tasks/${encodeURIComponent(taskId)}`);
5237
+ return unwrap(resp.data);
5238
+ }
5239
+
5203
5240
  // src/tenant.ts
5204
5241
  async function bootstrapTenant(http, bootstrapKey, req) {
5205
5242
  const resp = await http.post("/api/bootstrap/tenant", req, {
@@ -5958,8 +5995,8 @@ function noteFor(error) {
5958
5995
  // src/fde/recon/crawl.ts
5959
5996
  var KIT_PREMISE_KEY = "_kitPremiseCheck";
5960
5997
  var DEFAULT_META_TYPE = "model";
5961
- function metaPath(modelKey2, metaType = DEFAULT_META_TYPE) {
5962
- const base = `/api/models/${modelKey2}/meta`;
5998
+ function metaPath(modelKey, metaType = DEFAULT_META_TYPE) {
5999
+ const base = `/api/models/${modelKey}/meta`;
5963
6000
  return metaType === DEFAULT_META_TYPE ? base : `${base}?type=${metaType}`;
5964
6001
  }
5965
6002
  function modelRows(body) {
@@ -6188,8 +6225,8 @@ var REJECT_NOTES = {
6188
6225
  "malformed-key": "\u52A8\u4F5C\u6CA1\u6709\u53EF\u7528\u7684 key \u2014\u2014 \u6CA1\u6709 key \u5C31\u65E0\u6CD5\u8C03\u7528\uFF0C\u4E5F\u65E0\u6CD5\u4E0E\u4EA7\u54C1\u4FA7\u5BF9\u8D26",
6189
6226
  "malformed-action": "\u52A8\u4F5C\u6761\u76EE\u4E0D\u662F\u5BF9\u8C61\uFF0C\u65E0\u6CD5\u5224\u8BFB\u5B83\u662F\u4E0D\u662F\u53EA\u8BFB\u95F8"
6190
6227
  };
6191
- function actionsPath(modelKey2, state = "") {
6192
- const base = `/api/models/${modelKey2}/actions`;
6228
+ function actionsPath(modelKey, state = "") {
6229
+ const base = `/api/models/${modelKey}/actions`;
6193
6230
  if (!state) return base;
6194
6231
  return `${base}?${new URLSearchParams({ state }).toString()}`;
6195
6232
  }
@@ -6667,15 +6704,15 @@ function buildMapping(metas, edges, mutation, codeTables = []) {
6667
6704
  const byField = /* @__PURE__ */ new Map();
6668
6705
  for (const e of edges) byField.set(`${e.fromModel} ${e.fromField}`, e);
6669
6706
  const sheets = [];
6670
- for (const modelKey2 of Object.keys(metas).sort()) {
6671
- const { fields, problem: problem6 } = metaFields(metas[modelKey2]);
6707
+ for (const modelKey of Object.keys(metas).sort()) {
6708
+ const { fields, problem: problem6 } = metaFields(metas[modelKey]);
6672
6709
  const rows = [];
6673
6710
  for (const f of fields) {
6674
6711
  if (!isRecord2(f)) continue;
6675
6712
  const key = f.key;
6676
6713
  if (typeof key !== "string" || !key) continue;
6677
6714
  const { writable, reason } = writability(f);
6678
- const edge = byField.get(`${modelKey2} ${key}`);
6715
+ const edge = byField.get(`${modelKey} ${key}`);
6679
6716
  const ref = edge ? {
6680
6717
  toModel: edge.toModel,
6681
6718
  carrier: edge.carrier,
@@ -6710,11 +6747,11 @@ function buildMapping(metas, edges, mutation, codeTables = []) {
6710
6747
  });
6711
6748
  }
6712
6749
  sheets.push({
6713
- model: modelKey2,
6750
+ model: modelKey,
6714
6751
  // 「爬过且这个模型确实没有字段」必须与「没爬过」(文件不存在)区分开。
6715
6752
  crawled: true,
6716
6753
  wording: WORDING3,
6717
- mutation: mutationSection(isRecord2(mutation) ? mutation[modelKey2] : mutation),
6754
+ mutation: mutationSection(isRecord2(mutation) ? mutation[modelKey] : mutation),
6718
6755
  fieldCount: rows.length,
6719
6756
  // 🔴 `null` = 载荷判读正常(fieldCount=0 就是「这个模型确实没字段」);
6720
6757
  // 非 null = **爬过、但判不出字段**,此时 fieldCount=0 不代表「没字段」。
@@ -6730,14 +6767,14 @@ function allowedIn(sheet, op) {
6730
6767
  return isRecord2(cell) ? cell.allowed : "unknown";
6731
6768
  }
6732
6769
  var PATH_SEPARATORS = ["/", String.fromCharCode(92)];
6733
- function unsafeKeyReason(modelKey2) {
6734
- if (typeof modelKey2 !== "string" || !modelKey2) return `modelKey \u4E0D\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08${JSON.stringify(modelKey2)}\uFF09`;
6735
- if (PATH_SEPARATORS.some((s) => modelKey2.includes(s))) {
6736
- return `modelKey \u542B\u8DEF\u5F84\u5206\u9694\u7B26\uFF0C\u4E0D\u80FD\u5F53\u6587\u4EF6\u540D\uFF1A${JSON.stringify(modelKey2)}`;
6770
+ function unsafeKeyReason(modelKey) {
6771
+ if (typeof modelKey !== "string" || !modelKey) return `modelKey \u4E0D\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08${JSON.stringify(modelKey)}\uFF09`;
6772
+ if (PATH_SEPARATORS.some((s) => modelKey.includes(s))) {
6773
+ return `modelKey \u542B\u8DEF\u5F84\u5206\u9694\u7B26\uFF0C\u4E0D\u80FD\u5F53\u6587\u4EF6\u540D\uFF1A${JSON.stringify(modelKey)}`;
6737
6774
  }
6738
- if (modelKey2 === "." || modelKey2 === "..") return `modelKey \u6307\u5411\u76EE\u5F55\u672C\u8EAB\u6216\u4E0A\u7EA7\uFF1A${JSON.stringify(modelKey2)}`;
6739
- if (modelKey2.startsWith(".") || modelKey2.startsWith("_")) {
6740
- return `modelKey \u4EE5 . \u6216 _ \u5F00\u5934\uFF0C\u4E0D\u80FD\u5F53\u6587\u4EF6\u540D\uFF1A${JSON.stringify(modelKey2)} \u2014\u2014 \u524D\u8005\u4EA7\u51FA ls \u770B\u4E0D\u89C1\u7684\u9690\u85CF\u6587\u4EF6\u3001\u540E\u8005\u4F1A\u9876\u6389\u5DE5\u5177\u81EA\u5DF1\u7684 _index.json`;
6775
+ if (modelKey === "." || modelKey === "..") return `modelKey \u6307\u5411\u76EE\u5F55\u672C\u8EAB\u6216\u4E0A\u7EA7\uFF1A${JSON.stringify(modelKey)}`;
6776
+ if (modelKey.startsWith(".") || modelKey.startsWith("_")) {
6777
+ return `modelKey \u4EE5 . \u6216 _ \u5F00\u5934\uFF0C\u4E0D\u80FD\u5F53\u6587\u4EF6\u540D\uFF1A${JSON.stringify(modelKey)} \u2014\u2014 \u524D\u8005\u4EA7\u51FA ls \u770B\u4E0D\u89C1\u7684\u9690\u85CF\u6587\u4EF6\u3001\u540E\u8005\u4F1A\u9876\u6389\u5DE5\u5177\u81EA\u5DF1\u7684 _index.json`;
6741
6778
  }
6742
6779
  return null;
6743
6780
  }
@@ -6755,11 +6792,11 @@ function writeMapping(layout, sheets, opts = {}) {
6755
6792
  const written = [];
6756
6793
  const unsafe = [];
6757
6794
  for (const sheet of sheets) {
6758
- const modelKey2 = sheet.model;
6759
- let reason = unsafeKeyReason(modelKey2);
6795
+ const modelKey = sheet.model;
6796
+ let reason = unsafeKeyReason(modelKey);
6760
6797
  if (reason === null) {
6761
6798
  try {
6762
- written.push(layout.writeJson(`mapping/${modelKey2}.json`, sheet));
6799
+ written.push(layout.writeJson(`mapping/${modelKey}.json`, sheet));
6763
6800
  continue;
6764
6801
  } catch (err) {
6765
6802
  if (!(err instanceof LayoutContainmentError)) throw err;
@@ -6767,7 +6804,7 @@ function writeMapping(layout, sheets, opts = {}) {
6767
6804
  }
6768
6805
  }
6769
6806
  unsafe.push({
6770
- model: typeof modelKey2 === "string" ? modelKey2 : JSON.stringify(modelKey2),
6807
+ model: typeof modelKey === "string" ? modelKey : JSON.stringify(modelKey),
6771
6808
  reason,
6772
6809
  fieldCount: sheet.fieldCount
6773
6810
  });
@@ -6939,8 +6976,8 @@ function refEdges(metas, knownModels) {
6939
6976
  const known = new Set(knownModels);
6940
6977
  const edges = [];
6941
6978
  const dangling = [];
6942
- for (const modelKey2 of Object.keys(metas).sort()) {
6943
- const { fields } = metaFields(metas[modelKey2]);
6979
+ for (const modelKey of Object.keys(metas).sort()) {
6980
+ const { fields } = metaFields(metas[modelKey]);
6944
6981
  for (const field of fields) {
6945
6982
  if (!field || typeof field !== "object" || Array.isArray(field)) continue;
6946
6983
  const rec2 = field;
@@ -6951,7 +6988,7 @@ function refEdges(metas, knownModels) {
6951
6988
  const target = rec2[carrier];
6952
6989
  if (typeof target !== "string") {
6953
6990
  dangling.push({
6954
- fromModel: modelKey2,
6991
+ fromModel: modelKey,
6955
6992
  fromField: fieldKey,
6956
6993
  toModel: reprOf(target),
6957
6994
  carrier,
@@ -6960,13 +6997,13 @@ function refEdges(metas, knownModels) {
6960
6997
  continue;
6961
6998
  }
6962
6999
  if (!known.has(target)) {
6963
- dangling.push({ fromModel: modelKey2, fromField: fieldKey, toModel: target, carrier, reason: "not-in-registry" });
7000
+ dangling.push({ fromModel: modelKey, fromField: fieldKey, toModel: target, carrier, reason: "not-in-registry" });
6964
7001
  continue;
6965
7002
  }
6966
7003
  const label = rec2.objectLabel;
6967
7004
  const declared = typeof label === "string" && label.length > 0;
6968
7005
  edges.push({
6969
- fromModel: modelKey2,
7006
+ fromModel: modelKey,
6970
7007
  fromField: fieldKey,
6971
7008
  // 🔴 字段中文名,是「grep 部门 → 落到 {model, key}」这条链上唯一的人话。
6972
7009
  // 接错成 key 会让产物里全是英文键名——语法完好、不报错,
@@ -7006,8 +7043,8 @@ var DYNAMIC_TYPE = "DYNAMIC";
7006
7043
  var MAX_REQUESTS_PER_TABLE = 40;
7007
7044
  var MAX_SECONDS_PER_TABLE = 30;
7008
7045
  var WORDING4 = "rows = \u672C\u8F6E\u4EE5\u5F53\u524D\u767B\u5F55\u8EAB\u4EFD\u8BFB\u5230\u7684\u7801\u8868\u884C\uFF1B\u6BCF\u884C\u539F\u6837\u4FDD\u7559\u670D\u52A1\u7AEF\u8FD4\u56DE\u7684\u5168\u90E8\u952E\u3002\u5F15\u7528\u5B57\u6BB5\u5B58\u7684\u662F\u8FD9\u91CC\u7684 `id`\uFF0C\u4E0D\u662F `code`\u3002completeness: visible-complete = **\u5F53\u524D\u89D2\u8272\u53EF\u89C1\u8303\u56F4\u5185**\u53D6\u6EE1\uFF08\u4E0D\u662F\u5168\u96C6\uFF0CRBAC \u88C1\u526A\u5148\u4E8E count\uFF09\uFF1Bpartial = \u6CA1\u53D6\u6EE1\u6216\u6709\u9875\u5931\u8D25**\u6216\u89E6\u53D1\u4E86\u5DE5\u5177\u7684\u6BCF\u8868\u4E0A\u9650**\uFF08\u540E\u8005\u770B\u8FD9\u5F20\u8868\u7684 `truncatedBy`\uFF1Anull = \u6CA1\u89E6\u53D1\uFF0C\u5BF9\u8C61 = \u505C\u5728\u7B2C\u51E0\u9875 / \u5DF2\u6536\u591A\u5C11\u884C / \u89E6\u53D1\u7684\u662F\u54EA\u4E2A\u4E0A\u9650 \u2014\u2014 \u90A3\u662F**\u5DE5\u5177**\u7684\u622A\u65AD\uFF0C\u4E0D\u662F\u670D\u52A1\u7AEF\u7684\u6BDB\u75C5\uFF0C\u6539\u4E0A\u9650\u91CD\u8DD1\u5C31\u80FD\u53D6\u5168\uFF09\uFF1Bunavailable = \u8FDE\u8BA1\u6570\u90FD\u6CA1\u8BFB\u5230\uFF08crawled=false\uFF0C\u4E0E\u300C\u8FD9\u5F20\u7801\u8868\u662F\u7A7A\u7684\u300D\u662F\u4E24\u56DE\u4E8B\uFF09\uFF1Bauthoritative-complete = \u9700\u8981\u4EA7\u54C1\u4FA7\u6743\u5A01\u503C\u57DF\u51FA\u53E3\uFF0C**\u672C\u7248\u672C\u6C38\u8FDC\u4E0D\u4F1A\u4EA7\u51FA**\u3002partial / unavailable \u65F6\u7981\u6B62\u636E\u6B64\u751F\u6210\u5199\u811A\u672C\u3002";
7009
- function listPath(modelKey2) {
7010
- return `/api/models/${modelKey2}/list/dsl`;
7046
+ function listPath(modelKey) {
7047
+ return `/api/models/${modelKey}/list/dsl`;
7011
7048
  }
7012
7049
  function isRecord4(v) {
7013
7050
  return Boolean(v) && typeof v === "object" && !Array.isArray(v);
@@ -7164,8 +7201,8 @@ async function collectCodeTables(probe, modelEntries2, opts = {}) {
7164
7201
  }
7165
7202
  function collectEnumDomains(metas) {
7166
7203
  const rows = [];
7167
- for (const modelKey2 of Object.keys(metas).sort()) {
7168
- const { fields } = metaFields(metas[modelKey2]);
7204
+ for (const modelKey of Object.keys(metas).sort()) {
7205
+ const { fields } = metaFields(metas[modelKey]);
7169
7206
  for (const field of fields) {
7170
7207
  if (!isRecord4(field)) continue;
7171
7208
  const fieldKey = field.key;
@@ -7174,7 +7211,7 @@ function collectEnumDomains(metas) {
7174
7211
  if (!Array.isArray(enums) || enums.length === 0) continue;
7175
7212
  const kept = enums.filter(isRecord4).map((e) => ({ ...e }));
7176
7213
  rows.push({
7177
- model: modelKey2,
7214
+ model: modelKey,
7178
7215
  field: fieldKey,
7179
7216
  fieldName: typeof field.name === "string" && field.name || "",
7180
7217
  count: kept.length,
@@ -11072,15 +11109,15 @@ function unsafeRelReason(rel) {
11072
11109
  }
11073
11110
  return null;
11074
11111
  }
11075
- function unsafeModelKeyReason(modelKey2) {
11076
- if (typeof modelKey2 !== "string" || !modelKey2) {
11077
- return `\u6A21\u578B\u540D\u4E0D\u662F\u4E00\u4E2A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF1A${JSON.stringify(modelKey2)}`;
11112
+ function unsafeModelKeyReason(modelKey) {
11113
+ if (typeof modelKey !== "string" || !modelKey) {
11114
+ return `\u6A21\u578B\u540D\u4E0D\u662F\u4E00\u4E2A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF1A${JSON.stringify(modelKey)}`;
11078
11115
  }
11079
- if (modelKey2.includes("/") || modelKey2.includes("\\")) {
11080
- return `\u6A21\u578B\u540D\u542B\u8DEF\u5F84\u5206\u9694\u7B26\uFF1A${JSON.stringify(modelKey2)}`;
11116
+ if (modelKey.includes("/") || modelKey.includes("\\")) {
11117
+ return `\u6A21\u578B\u540D\u542B\u8DEF\u5F84\u5206\u9694\u7B26\uFF1A${JSON.stringify(modelKey)}`;
11081
11118
  }
11082
- if (modelKey2.startsWith(".") || modelKey2.startsWith("_")) {
11083
- return `\u6A21\u578B\u540D\u4EE5 . \u6216 _ \u5F00\u5934\uFF1A${JSON.stringify(modelKey2)} \u2014\u2014 recon \u90A3\u8FB9\u5C31\u62D2\u7EDD\u6309\u8FD9\u79CD\u540D\u5B57\u843D\u76D8\uFF0C\u6240\u4EE5\u8FD9\u4EFD sheet \u6839\u672C\u4E0D\u4F1A\u5B58\u5728`;
11119
+ if (modelKey.startsWith(".") || modelKey.startsWith("_")) {
11120
+ return `\u6A21\u578B\u540D\u4EE5 . \u6216 _ \u5F00\u5934\uFF1A${JSON.stringify(modelKey)} \u2014\u2014 recon \u90A3\u8FB9\u5C31\u62D2\u7EDD\u6309\u8FD9\u79CD\u540D\u5B57\u843D\u76D8\uFF0C\u6240\u4EE5\u8FD9\u4EFD sheet \u6839\u672C\u4E0D\u4F1A\u5B58\u5728`;
11084
11121
  }
11085
11122
  return null;
11086
11123
  }
@@ -11124,12 +11161,12 @@ var ReconView = class {
11124
11161
  return { body, failure: null, detail: file };
11125
11162
  }
11126
11163
  /** `recon/mapping/<M>.json`。`path` 恒给出(读不成时顾问也要知道去哪找)。 */
11127
- sheet(modelKey2) {
11128
- const cached = this.sheets.get(modelKey2);
11164
+ sheet(modelKey) {
11165
+ const cached = this.sheets.get(modelKey);
11129
11166
  if (cached !== void 0) return cached;
11130
- const rel = `${MAPPING_SUBDIR}/${modelKey2}.json`;
11167
+ const rel = `${MAPPING_SUBDIR}/${modelKey}.json`;
11131
11168
  const got = { ...this.readJson(rel), path: path13.join(this.dir, rel) };
11132
- this.sheets.set(modelKey2, got);
11169
+ this.sheets.set(modelKey, got);
11133
11170
  return got;
11134
11171
  }
11135
11172
  /** `ref.valueDomain` 指的那份码表快照。 */
@@ -16010,6 +16047,11 @@ var PROTOCOL_FACTS = [
16010
16047
  token: "/api/auth/login",
16011
16048
  probe: "packages/core/tests/fde-gate0-facts.test.ts::login-body-carries-tenant",
16012
16049
  note: "\u767B\u5F55\u7684 tenantId \u5728**\u8BF7\u6C42\u4F53**\u91CC\uFF0C\u4E0D\u5728 header\u3002\u63A2\u9488\u65AD\u7684\u662F\u5B9E\u9645\u53D1\u51FA\u53BB\u7684\u8BF7\u6C42\u4F53\u4E0E\u8BF7\u6C42\u5934\uFF0C\u5220\u6389 tenantId \u6216\u632A\u8FDB header \u90FD\u4F1A\u7EA2\u3002"
16050
+ },
16051
+ {
16052
+ token: "/api/tenant-extension/workspaces",
16053
+ probe: "packages/core/tests/fde-triage-probe.test.ts::workspaces-path-wire-shape",
16054
+ note: "\u5F00\u53D1\u7A7A\u95F4\u6E05\u5355\u8D70\u88F8\u8DEF\u5F84 GET\uFF0C\u662F\u5206\u8BCA\u516D\u683C\u91CC `graaljs-spi` \u90A3\u4E00\u683C\u552F\u4E00\u8981\u8054\u7F51\u7684\u4E00\u53D1\u3002\u63A2\u9488\u65AD\u7684\u662F**\u6574\u8D9F\u5B9E\u9645\u6253\u51FA\u53BB\u7684\u8DEF\u5F84\u5217\u8868\u9010\u5B57\u76F8\u7B49**\uFF08\u4E0D\u662F\u300C\u542B\u67D0\u4E2A\u8BCD\u300D\uFF09\u2014\u2014\u8DEF\u5F84\u6539\u4E86\u3001\u6216\u8005\u522B\u7684\u683C\u5077\u5077\u591A\u6253\u4E86\u4E00\u53D1\uFF0C\u90FD\u4F1A\u7EA2\u3002"
16013
16055
  }
16014
16056
  ];
16015
16057
  function loadProtocolFacts(entries = PROTOCOL_FACTS, options = {}) {
@@ -16082,13 +16124,22 @@ function loadProtocolFacts(entries = PROTOCOL_FACTS, options = {}) {
16082
16124
  // src/fde/gate0/scan.ts
16083
16125
  import { readFileSync as readFileSync14, readdirSync as readdirSync4, readlinkSync, statSync as statSync10 } from "fs";
16084
16126
  import * as path22 from "path";
16085
- var CHANNEL_ACLASS = "aclass";
16127
+
16128
+ // src/fde/gate0/owned.ts
16129
+ var OWNED_CODE_SETS = [
16130
+ PROBLEM_CODES,
16131
+ RISK_CODES,
16132
+ APPLY_PROBLEM_CODES,
16133
+ PLAN_PROBLEM_CODES
16134
+ ];
16135
+ var OWNED_CODES = new Set(OWNED_CODE_SETS.flat());
16136
+
16137
+ // src/fde/gate0/scan.ts
16086
16138
  var CHANNEL_ARTIFACT = "artifact-path";
16087
16139
  var CHANNEL_UNREGISTERED = "protocol-unregistered";
16088
16140
  var CHANNEL_REGISTERED_IS_ACLASS = "registered-but-is-aclass";
16089
16141
  var CHANNEL_NO_PROBE = "no-probe";
16090
16142
  var CHANNELS = [
16091
- CHANNEL_ACLASS,
16092
16143
  CHANNEL_ARTIFACT,
16093
16144
  CHANNEL_UNREGISTERED,
16094
16145
  CHANNEL_REGISTERED_IS_ACLASS,
@@ -16154,7 +16205,6 @@ var PRODUCT_RELATIVE_SHAPES = [
16154
16205
  ["valuedomain", ".json"],
16155
16206
  ["valuedomain", ".jsonl"]
16156
16207
  ];
16157
- var REASON_ENVIRONMENT_FACT = "environment-fact";
16158
16208
  var REASON_PRODUCT_TREE_PATH = "product-tree-path";
16159
16209
  var REASON_PRODUCT_RELATIVE_PATH = "product-relative-path";
16160
16210
  var REASON_PRODUCT_FILE_NAME = "product-file-name";
@@ -16163,7 +16213,6 @@ var REASON_ERROR_CODE = "error-code";
16163
16213
  var REASON_REGISTERED_IS_ACLASS = "registered-is-aclass";
16164
16214
  var REASON_REJECTED_REGISTRATION = "rejected-registration";
16165
16215
  var RED_REASONS = {
16166
- [CHANNEL_ACLASS]: [REASON_ENVIRONMENT_FACT],
16167
16216
  [CHANNEL_ARTIFACT]: [
16168
16217
  REASON_PRODUCT_TREE_PATH,
16169
16218
  REASON_PRODUCT_RELATIVE_PATH,
@@ -16193,7 +16242,12 @@ var ACLASS_EMPTY_WHY = {
16193
16242
  };
16194
16243
  var GAP_NOISE_TOKEN = "pure-digit-or-single-char";
16195
16244
  var GAP_CJK_INSIDE_LONGER_RUN = "cjk-inside-longer-run";
16196
- var GAP_REASONS = [GAP_NOISE_TOKEN, GAP_CJK_INSIDE_LONGER_RUN];
16245
+ var GAP_ACLASS_NOT_DISCRIMINATIVE = "aclass-not-discriminative";
16246
+ var GAP_REASONS = [
16247
+ GAP_NOISE_TOKEN,
16248
+ GAP_CJK_INSIDE_LONGER_RUN,
16249
+ GAP_ACLASS_NOT_DISCRIMINATIVE
16250
+ ];
16197
16251
  function checkReds(reds) {
16198
16252
  for (const red of reds) {
16199
16253
  if (!CHANNELS.includes(red.channel)) {
@@ -16213,7 +16267,7 @@ function checkGaps(gaps) {
16213
16267
  for (const gap of gaps) {
16214
16268
  if (!GAP_REASONS.includes(gap.reason)) {
16215
16269
  throw new Error(
16216
- `\u7F3A\u53E3\u53F0\u8D26\u7684 reason \u53EA\u6709 ${GAP_REASONS.join("/")} \u4E24\u4E2A\u53D6\u503C\uFF0C\u62FF\u5230\u7684\u662F ${JSON.stringify(gap.reason)}\uFF08${gap.why}\uFF09`
16270
+ `\u7F3A\u53E3\u53F0\u8D26\u7684 reason \u53EA\u6709 ${GAP_REASONS.join("/")} \u8FD9\u51E0\u4E2A\u53D6\u503C\uFF0C\u62FF\u5230\u7684\u662F ${JSON.stringify(gap.reason)}\uFF08${gap.why}\uFF09`
16217
16271
  );
16218
16272
  }
16219
16273
  }
@@ -16469,11 +16523,14 @@ function judgeLine(line, lineno, rel, matcher, index, reds, gaps) {
16469
16523
  unique2.push({ ...red, message: red.message + foldedNoteFor(line, folded, red.token) });
16470
16524
  }
16471
16525
  reds.push(...unique2);
16472
- const redTokens = new Set(unique2.filter((r) => r.channel === CHANNEL_ACLASS).map((r) => r.token));
16526
+ const definite = new Set(
16527
+ lineGaps.filter((g) => g.reason === GAP_ACLASS_NOT_DISCRIMINATIVE).map((g) => g.token)
16528
+ );
16473
16529
  const seenGaps = /* @__PURE__ */ new Set();
16474
16530
  for (const gap of lineGaps) {
16475
16531
  const key = `${gap.reason} ${gap.token}`;
16476
- if (seenGaps.has(key) || folded !== line && redTokens.has(gap.token)) continue;
16532
+ if (seenGaps.has(key) || folded !== line && gap.reason !== GAP_ACLASS_NOT_DISCRIMINATIVE && definite.has(gap.token))
16533
+ continue;
16477
16534
  seenGaps.add(key);
16478
16535
  gaps.push({ ...gap, why: gap.why + foldedNoteFor(line, folded, gap.token) });
16479
16536
  }
@@ -16503,14 +16560,13 @@ function judgePass(line, lineno, rel, matcher, index, reds, gaps) {
16503
16560
  });
16504
16561
  continue;
16505
16562
  }
16506
- reds.push({
16507
- channel: CHANNEL_ACLASS,
16508
- reason: REASON_ENVIRONMENT_FACT,
16563
+ gaps.push({
16564
+ reason: GAP_ACLASS_NOT_DISCRIMINATIVE,
16509
16565
  token: token2,
16566
+ kinds,
16510
16567
  path: rel,
16511
16568
  line: lineno,
16512
- kinds,
16513
- message: `${rel}:${lineno} \u51FA\u73B0\u73AF\u5883\u4E8B\u5B9E ${JSON.stringify(token2)}\uFF08A \u7C7B ${kinds.join("/")}\uFF09\u2014\u2014 \u6362\u4E2A\u5BA2\u6237\u5C31\u5168\u9519\uFF0C**\u65E0\u8C41\u514D**`
16569
+ why: `${rel}:${lineno} ${JSON.stringify(token2)} \u5728\u57FA\u7EBF\u91CC\u51FA\u73B0\u8FC7\uFF08A \u7C7B ${kinds.join("/")}\uFF09\u2014\u2014 **\u8FD9\u53E5\u8BDD\u51E0\u4E4E\u4E0D\u542B\u4FE1\u606F\u91CF**\uFF1A\u57FA\u7EBF\u662F\u4EA7\u54C1\u5168\u91CF\uFF0C\u4E0B\u4E00\u4E2A\u5BA2\u6237\u88C5\u7684\u662F\u540C\u4E00\u4E2A\u4EA7\u54C1\uFF0C\u8FD9\u4E2A\u5B57\u9762\u5728\u90A3\u8FB9\u4E5F\u4E00\u6837\u5728\u3002\u4E0D\u9876 rc\uFF0C\u8BF7\u81EA\u5DF1\u770B\u4E00\u773C\u5B83\u5230\u5E95\u662F\u4E0D\u662F\u53D6\u503C`
16514
16570
  });
16515
16571
  }
16516
16572
  const spans = [];
@@ -16547,6 +16603,7 @@ function judgePass(line, lineno, rel, matcher, index, reds, gaps) {
16547
16603
  function judgeProtocol(token2, reason, shape, lineno, rel, matcher, index, reds) {
16548
16604
  if (matcher.owners.has(token2)) return;
16549
16605
  if (covered(token2, index)) return;
16606
+ if (reason === REASON_ERROR_CODE && OWNED_CODES.has(token2)) return;
16550
16607
  reds.push({
16551
16608
  channel: CHANNEL_UNREGISTERED,
16552
16609
  reason,
@@ -16826,23 +16883,19 @@ function readArtifactJsonl(dir, rel) {
16826
16883
  return rows;
16827
16884
  }
16828
16885
  function modelRows2(dir) {
16829
- const body = readArtifactJson(dir, MODELS_REL);
16830
- const rows = body && typeof body === "object" ? body.models : null;
16831
- return Array.isArray(rows) ? rows : [];
16886
+ return modelEntries(readArtifactJson(dir, MODELS_REL));
16832
16887
  }
16833
- function modelKey(row) {
16834
- if (!row || typeof row !== "object") return null;
16835
- const key = row.key;
16888
+ function entryKey(row) {
16889
+ const key = row.modelKey;
16836
16890
  return typeof key === "string" && key ? key : null;
16837
16891
  }
16838
16892
  function probeConfigSurface(dir) {
16839
- let rows;
16893
+ let keys;
16840
16894
  try {
16841
- rows = modelRows2(dir);
16895
+ keys = modelKeys(readArtifactJson(dir, MODELS_REL));
16842
16896
  } catch (err) {
16843
16897
  return unavailableCell("config-surface", err);
16844
16898
  }
16845
- const keys = rows.map(modelKey).filter((k) => k !== null);
16846
16899
  if (keys.length === 0) {
16847
16900
  return buildCarrierResult("config-surface", CARRIER_MISS, {
16848
16901
  note: "\u6A21\u578B\u6E05\u5355\u662F\u7A7A\u7684 \u2014\u2014 \u8FD9\u4E2A\u73AF\u5883\u4E0A\u6CA1\u6709\u53EF\u914D\u7F6E\u7684\u6A21\u578B\u9762"
@@ -16860,7 +16913,7 @@ function probeFlexModel(dir) {
16860
16913
  } catch (err) {
16861
16914
  return unavailableCell("flex-model", err);
16862
16915
  }
16863
- const hits = rows.filter((r) => r && typeof r === "object" && r.type === DYNAMIC_TYPE2).map(modelKey).filter((k) => k !== null);
16916
+ const hits = rows.filter((r) => r.type === DYNAMIC_TYPE2).map(entryKey).filter((k) => k !== null);
16864
16917
  if (hits.length === 0) {
16865
16918
  return buildCarrierResult("flex-model", CARRIER_MISS, {
16866
16919
  note: `\u8FD9\u4E2A\u73AF\u5883\u4E0A\u6CA1\u6709 ${DYNAMIC_TYPE2} \u578B\u6A21\u578B`
@@ -16887,7 +16940,7 @@ function probeJsonModel(dir) {
16887
16940
  }
16888
16941
  const hits = [];
16889
16942
  for (const row of rows) {
16890
- const key = modelKey(row);
16943
+ const key = entryKey(row);
16891
16944
  if (key === null) continue;
16892
16945
  let mapping;
16893
16946
  try {
@@ -17858,7 +17911,6 @@ export {
17858
17911
  CHANGE_UNKNOWN,
17859
17912
  CHANGE_WRITTEN,
17860
17913
  CHANNELS,
17861
- CHANNEL_ACLASS,
17862
17914
  CHANNEL_ARTIFACT,
17863
17915
  CHANNEL_NO_PROBE,
17864
17916
  CHANNEL_REGISTERED_IS_ACLASS,
@@ -17914,6 +17966,7 @@ export {
17914
17966
  FORCE_STALE_FLAG,
17915
17967
  FORCE_STALE_FLAG_TEXT,
17916
17968
  FULLWIDTH_ALNUM_RANGES,
17969
+ GAP_ACLASS_NOT_DISCRIMINATIVE,
17917
17970
  GAP_CJK_INSIDE_LONGER_RUN,
17918
17971
  GAP_NOISE_TOKEN,
17919
17972
  GAP_REASONS,
@@ -18158,6 +18211,7 @@ export {
18158
18211
  fromAxiosError,
18159
18212
  getCacheStats,
18160
18213
  getMiniStatus,
18214
+ getScriptTask,
18161
18215
  getSettingDomain,
18162
18216
  getTenantMeta,
18163
18217
  globalConfigFile,
@@ -18237,6 +18291,7 @@ export {
18237
18291
  profileFile,
18238
18292
  pullMiniAppProject,
18239
18293
  pushMiniAppProject,
18294
+ queryScriptLogs,
18240
18295
  readBusinessKeyFields,
18241
18296
  readImportPlan,
18242
18297
  readMiniContext,
@@ -18278,6 +18333,7 @@ export {
18278
18333
  saveTenantMeta,
18279
18334
  saveWorkspaceFileContent,
18280
18335
  scan,
18336
+ scriptDryRun,
18281
18337
  seedBaselines,
18282
18338
  seedMappingPath,
18283
18339
  seedWorkDir,
@@ -18297,6 +18353,7 @@ export {
18297
18353
  update,
18298
18354
  uploadDocument,
18299
18355
  validateMiniProject,
18356
+ validateScriptManifest,
18300
18357
  valueState,
18301
18358
  valuesRoundCaveat,
18302
18359
  verifyAttention,