@hcmai/cli 0.7.1 → 0.8.0
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 +886 -1362
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +29 -107
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6782,16 +6782,16 @@ async function verifyAfterWrite(c, path14) {
|
|
|
6782
6782
|
run: () => c.raw().get(`/api/models/${model}`, { params: { state: state ?? "default", size: 1 } })
|
|
6783
6783
|
});
|
|
6784
6784
|
}
|
|
6785
|
-
for (const
|
|
6785
|
+
for (const probe of probes) {
|
|
6786
6786
|
try {
|
|
6787
|
-
await
|
|
6787
|
+
await probe.run();
|
|
6788
6788
|
} catch (e) {
|
|
6789
6789
|
const why = unverifiableReason(e);
|
|
6790
|
-
if (why) return { status: "unverified", where:
|
|
6790
|
+
if (why) return { status: "unverified", where: probe.where, why };
|
|
6791
6791
|
const err = e;
|
|
6792
6792
|
const body = err.response?.data;
|
|
6793
6793
|
const raw = typeof body === "string" ? body : JSON.stringify(body ?? err.message ?? String(e));
|
|
6794
|
-
return { status: "broken", where:
|
|
6794
|
+
return { status: "broken", where: probe.where, raw };
|
|
6795
6795
|
}
|
|
6796
6796
|
}
|
|
6797
6797
|
return { status: "ok" };
|
|
@@ -9322,6 +9322,348 @@ async function chironInitCommand(args, deps) {
|
|
|
9322
9322
|
}
|
|
9323
9323
|
}
|
|
9324
9324
|
|
|
9325
|
+
// src/commands/gap.ts
|
|
9326
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
9327
|
+
import {
|
|
9328
|
+
createHttpClient as createHttpClient4,
|
|
9329
|
+
formatObject as formatObject22,
|
|
9330
|
+
loadEnv as loadEnv11,
|
|
9331
|
+
loadGlobalConfig as loadGlobalConfig11,
|
|
9332
|
+
resolveActiveEnv as resolveActiveEnv5
|
|
9333
|
+
} from "@hcmai/sdk";
|
|
9334
|
+
init_exit();
|
|
9335
|
+
import { createJiraClient } from "@hcmai/sdk";
|
|
9336
|
+
|
|
9337
|
+
// src/jira/gaps.ts
|
|
9338
|
+
import { CASES_REPO_SLUG, repoIssueUrl } from "@hcmai/sdk";
|
|
9339
|
+
import { linkedRepoRefs, parseRef } from "@hcmai/sdk";
|
|
9340
|
+
var MIN_LEN = [
|
|
9341
|
+
["title", 8],
|
|
9342
|
+
["phenomenon", 20],
|
|
9343
|
+
["repro", 10],
|
|
9344
|
+
["expected", 10],
|
|
9345
|
+
["alternative", 5],
|
|
9346
|
+
["q_mechanism", 10],
|
|
9347
|
+
["q_history", 10],
|
|
9348
|
+
["q_skill", 10]
|
|
9349
|
+
];
|
|
9350
|
+
function validateGapInput(x) {
|
|
9351
|
+
if (!x || typeof x !== "object") throw new Error("\u7F3A\u53E3\u8F7D\u8377\u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61");
|
|
9352
|
+
const g = x;
|
|
9353
|
+
const problems = [];
|
|
9354
|
+
for (const [k, min] of MIN_LEN) {
|
|
9355
|
+
const v = g[k];
|
|
9356
|
+
if (typeof v !== "string" || v.trim().length < min) problems.push(`${k} \u81F3\u5C11 ${min} \u4E2A\u5B57`);
|
|
9357
|
+
}
|
|
9358
|
+
if (typeof g.title === "string" && g.title.length > 80) problems.push("title \u4E0D\u8D85\u8FC7 80 \u4E2A\u5B57");
|
|
9359
|
+
if (!["\u963B\u65AD", "\u6709\u66FF\u4EE3\u6CD5", "\u63AA\u8F9E\u7EA7"].includes(String(g.severity))) problems.push("severity \u53EA\u80FD\u662F \u963B\u65AD / \u6709\u66FF\u4EE3\u6CD5 / \u63AA\u8F9E\u7EA7");
|
|
9360
|
+
if (!["\u7F3A\u9677", "\u7F3A\u80FD\u529B"].includes(String(g.kind))) problems.push("kind \u53EA\u80FD\u662F \u7F3A\u9677\uFF08\u6545\u969C\uFF09/ \u7F3A\u80FD\u529B\uFF08\u9700\u6C42\uFF09");
|
|
9361
|
+
if (g.module !== void 0 && !["HCM-Core", "HCM-Cloud", "\u4EA7\u54C1\u652F\u6301"].includes(String(g.module))) problems.push("module \u53EA\u80FD\u662F HCM-Core / HCM-Cloud / \u4EA7\u54C1\u652F\u6301");
|
|
9362
|
+
if (problems.length) throw new Error(`\u7F3A\u53E3\u8F7D\u8377\u4E0D\u5408\u683C\uFF0C\u6CA1\u6709\u63D0\uFF1A
|
|
9363
|
+
${problems.join("\n ")}`);
|
|
9364
|
+
return g;
|
|
9365
|
+
}
|
|
9366
|
+
var gapKeyTag = (g) => `\u3014${[g.model, g.action, g.error_code].filter(Boolean).join("\xB7") || "-"}\u3015`;
|
|
9367
|
+
var gapSummary = (g) => `\u7F3A\u53E3\uFF1A${g.title} ${gapKeyTag(g)}`;
|
|
9368
|
+
function renderGapDescription(g, fingerprintText2) {
|
|
9369
|
+
return [
|
|
9370
|
+
"h2. \u73B0\u8C61",
|
|
9371
|
+
g.phenomenon,
|
|
9372
|
+
"",
|
|
9373
|
+
"h2. \u590D\u73B0",
|
|
9374
|
+
"{code}",
|
|
9375
|
+
g.repro,
|
|
9376
|
+
"{code}",
|
|
9377
|
+
"",
|
|
9378
|
+
"h2. \u671F\u671B",
|
|
9379
|
+
g.expected,
|
|
9380
|
+
"",
|
|
9381
|
+
"h2. \u73AF\u5883\u6307\u7EB9",
|
|
9382
|
+
fingerprintText2,
|
|
9383
|
+
"",
|
|
9384
|
+
"h2. \u66FF\u4EE3\u6CD5",
|
|
9385
|
+
g.alternative,
|
|
9386
|
+
"",
|
|
9387
|
+
"h2. \u4E25\u91CD\u5EA6",
|
|
9388
|
+
`${g.severity}\uFF08\u987E\u95EE\u4FA7\u5224\u5B9A\uFF1A\u963B\u65AD=\u4EA4\u4ED8\u505C\u4E0B / \u6709\u66FF\u4EE3\u6CD5=\u80FD\u7ED5 / \u63AA\u8F9E\u7EA7=\u8F93\u51FA\u5DF2\u7ED9\u8DEF\u6807\uFF09`,
|
|
9389
|
+
"",
|
|
9390
|
+
"h2. \u4E09\u95EE\u81EA\u7B54",
|
|
9391
|
+
`# \u673A\u5236\u8FB9\u754C\uFF1A${g.q_mechanism}`,
|
|
9392
|
+
`# \u5386\u53F2\uFF1A${g.q_history}`,
|
|
9393
|
+
`# \u6280\u80FD\u6709\u6CA1\u6709\u6559\u9519\uFF1A${g.q_skill}`,
|
|
9394
|
+
"",
|
|
9395
|
+
"h2. \u5173\u952E\u8BCD",
|
|
9396
|
+
[g.error_code, g.model, g.action].filter(Boolean).join(" \xB7 ") || "\uFF08\u65E0\uFF09",
|
|
9397
|
+
"",
|
|
9398
|
+
"_\u7531\u987E\u95EE agent \u7ECF `hcm chiron gap submit` \u63D0\u4EA4\u3002\u5206\u8BCA\u4E09\u53BB\u5411\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u56DE\u94FE / \u6539\u6280\u80FD\u5E76\u56DE\u590D / \u5408\u5E76\u8BA1\u6570\u3002\u5904\u7406\u529E\u6CD5\u89C1\u4EA7\u54C1\u4ED3\u6280\u80FD jira-triage\u3002_"
|
|
9399
|
+
].join("\n");
|
|
9400
|
+
}
|
|
9401
|
+
function findDuplicateGap(open, summary, keyTag) {
|
|
9402
|
+
const bigrams = (t) => {
|
|
9403
|
+
const x = (t || "").replace(/〔.*?〕/g, "").replace(/[\s,。::、()()「」]/g, "");
|
|
9404
|
+
const out = /* @__PURE__ */ new Set();
|
|
9405
|
+
for (let i = 0; i + 1 < x.length; i++) out.add(x.slice(i, i + 2));
|
|
9406
|
+
return out;
|
|
9407
|
+
};
|
|
9408
|
+
const sim = (a, b) => {
|
|
9409
|
+
const A = bigrams(a);
|
|
9410
|
+
const B = bigrams(b);
|
|
9411
|
+
if (!A.size || !B.size) return 0;
|
|
9412
|
+
let n = 0;
|
|
9413
|
+
for (const s of A) if (B.has(s)) n++;
|
|
9414
|
+
return n / Math.min(A.size, B.size);
|
|
9415
|
+
};
|
|
9416
|
+
for (const i of open) {
|
|
9417
|
+
const t = i.fields.summary ?? "";
|
|
9418
|
+
if (keyTag !== "\u3014-\u3015" && t.includes(keyTag)) return i;
|
|
9419
|
+
if (sim(t, summary) >= 0.6) return i;
|
|
9420
|
+
}
|
|
9421
|
+
return null;
|
|
9422
|
+
}
|
|
9423
|
+
var KIND_TO_TYPE = { \u7F3A\u9677: ["\u6545\u969C", "Bug", "\u7F3A\u9677"], \u7F3A\u80FD\u529B: ["\u9700\u6C42", "Story", "New Feature"] };
|
|
9424
|
+
var KIND_TO_CATEGORY = { \u7F3A\u9677: "\u7A0B\u5E8FBug", \u7F3A\u80FD\u529B: "\u9700\u6C42" };
|
|
9425
|
+
var SEVERITY_TO_PRIORITY = {
|
|
9426
|
+
\u963B\u65AD: ["\u7D27\u6025", "Highest", "High", "\u9AD8"],
|
|
9427
|
+
\u6709\u66FF\u4EE3\u6CD5: ["Medium", "\u4E2D", "\u4E00\u822C", "High"],
|
|
9428
|
+
\u63AA\u8F9E\u7EA7: ["Low", "\u4F4E", "Lowest"]
|
|
9429
|
+
};
|
|
9430
|
+
var MODULE_DEFAULT_CHILD = { "HCM-Core": "\u57FA\u7840\u8BBE\u7F6E", "HCM-Cloud": "\u5F00\u53D1\u5E73\u53F0", \u4EA7\u54C1\u652F\u6301: "\u4EA7\u54C1\u652F\u6301" };
|
|
9431
|
+
function buildGapFields(g, ctx) {
|
|
9432
|
+
const wanted = KIND_TO_TYPE[g.kind] ?? [];
|
|
9433
|
+
const type = ctx.issuetypeOverride && ctx.types.find((t) => t.name === ctx.issuetypeOverride) || wanted.map((n) => ctx.types.find((t) => t.name === n)).find(Boolean);
|
|
9434
|
+
if (!type) {
|
|
9435
|
+
throw new Error(`\u9879\u76EE ${ctx.project} \u91CC\u6CA1\u6709\u300C${wanted.join(" / ")}\u300D\u8FD9\u7C7B issuetype\uFF0C\u5B9E\u9645\u6709\uFF1A${ctx.types.map((t) => t.name).join(" / ")}`);
|
|
9436
|
+
}
|
|
9437
|
+
const module = g.module ?? "HCM-Core";
|
|
9438
|
+
const keyTag = gapKeyTag(g);
|
|
9439
|
+
const byName = {
|
|
9440
|
+
\u6982\u8981: gapSummary(g),
|
|
9441
|
+
\u63CF\u8FF0: renderGapDescription(g, ctx.fingerprintText),
|
|
9442
|
+
\u95EE\u9898\u7C7B\u522B: KIND_TO_CATEGORY[g.kind],
|
|
9443
|
+
\u95EE\u9898\u6A21\u5757: module,
|
|
9444
|
+
\u4F18\u5148\u7EA7: SEVERITY_TO_PRIORITY[g.severity],
|
|
9445
|
+
\u62A5\u544A\u4EBA: ctx.me,
|
|
9446
|
+
\u7ECF\u529E\u4EBA: ctx.assignee,
|
|
9447
|
+
Bug\u53D1\u73B0\u4EBA: "\u987E\u95EE",
|
|
9448
|
+
Bug\u91CD\u73B0\u64CD\u4F5C\u6B65\u9AA4: g.repro,
|
|
9449
|
+
Bug\u9519\u8BEF\u53F7: g.error_code || "\u65E0\u9519\u8BEF\u7801\uFF08\u73B0\u8C61\u89C1\u63CF\u8FF0\uFF09"
|
|
9450
|
+
};
|
|
9451
|
+
const fields = { project: { key: ctx.project }, issuetype: { id: type.id } };
|
|
9452
|
+
const unfilled = [];
|
|
9453
|
+
const values = (f) => (f.allowedValues ?? []).map((v) => v.value ?? v.name).join("|");
|
|
9454
|
+
for (const f of type.fields ?? []) {
|
|
9455
|
+
if (["project", "issuetype"].includes(f.fieldId)) continue;
|
|
9456
|
+
const want = byName[f.name];
|
|
9457
|
+
if (want === void 0) {
|
|
9458
|
+
if (f.required) unfilled.push(`${f.name}(${f.fieldId})${f.allowedValues ? `=[${values(f)}]` : ""}`);
|
|
9459
|
+
continue;
|
|
9460
|
+
}
|
|
9461
|
+
if (f.schema?.type === "option-with-child") {
|
|
9462
|
+
const parent = (f.allowedValues ?? []).find((v) => (v.value ?? v.name) === want);
|
|
9463
|
+
if (!parent) {
|
|
9464
|
+
if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${String(want)}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
|
|
9465
|
+
continue;
|
|
9466
|
+
}
|
|
9467
|
+
const childName = g.module_detail || MODULE_DEFAULT_CHILD[module];
|
|
9468
|
+
const child = (parent.children ?? []).find((c) => (c.value ?? c.name) === childName);
|
|
9469
|
+
if (!child && (parent.children ?? []).length) {
|
|
9470
|
+
unfilled.push(`${f.name}(${f.fieldId}) \u7684\u4E8C\u7EA7\u9879\u300C${childName}\u300D\u4E0D\u5728 [${(parent.children ?? []).map((c) => c.value ?? c.name).join("|")}] \u91CC`);
|
|
9471
|
+
continue;
|
|
9472
|
+
}
|
|
9473
|
+
fields[f.fieldId] = { id: parent.id, ...child ? { child: { id: child.id } } : {} };
|
|
9474
|
+
continue;
|
|
9475
|
+
}
|
|
9476
|
+
if (f.allowedValues) {
|
|
9477
|
+
const candidates = Array.isArray(want) ? want : [want];
|
|
9478
|
+
const hit = candidates.map((c) => f.allowedValues.find((v) => (v.name ?? v.value) === c)).find(Boolean);
|
|
9479
|
+
if (!hit) {
|
|
9480
|
+
if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${candidates.join("/")}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
|
|
9481
|
+
continue;
|
|
9482
|
+
}
|
|
9483
|
+
fields[f.fieldId] = hit.id ? { id: hit.id } : { name: hit.name ?? hit.value };
|
|
9484
|
+
} else if (f.schema?.type === "user") {
|
|
9485
|
+
if (!want) {
|
|
9486
|
+
if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u53D6\u4E0D\u5230\u7528\u6237\u540D`);
|
|
9487
|
+
continue;
|
|
9488
|
+
}
|
|
9489
|
+
fields[f.fieldId] = { name: Array.isArray(want) ? want[0] : want };
|
|
9490
|
+
} else {
|
|
9491
|
+
fields[f.fieldId] = Array.isArray(want) ? want[0] : want;
|
|
9492
|
+
}
|
|
9493
|
+
}
|
|
9494
|
+
if ((type.fields ?? []).some((f) => f.fieldId === "labels")) {
|
|
9495
|
+
const sev = { \u963B\u65AD: "blocking", \u6709\u66FF\u4EE3\u6CD5: "workaround", \u63AA\u8F9E\u7EA7: "wording" }[g.severity];
|
|
9496
|
+
fields.labels = ["chiron-gap", `severity-${sev}`];
|
|
9497
|
+
}
|
|
9498
|
+
if (unfilled.length) {
|
|
9499
|
+
throw new Error(
|
|
9500
|
+
`\u8FD9\u53F0 Jira \u7684\u300C${type.name}\u300D\u6709\u6211\u586B\u4E0D\u4E0A\u7684\u5FC5\u586B\u5B57\u6BB5\uFF0C\u6CA1\u6709\u5EFA\u5355\uFF08\u4E0D\u66FF\u4F60\u731C\uFF09\uFF1A
|
|
9501
|
+
${unfilled.join("\n ")}
|
|
9502
|
+
next_step=\u8BA9 Jira \u7BA1\u7406\u5458\u628A\u8FD9\u4E9B\u5B57\u6BB5\u6539\u6210\u975E\u5FC5\u586B\uFF0C\u6216\u544A\u8BC9\u6211\u8BE5\u586B\u4EC0\u4E48\u3001\u6211\u52A0\u8FDB\u6620\u5C04\u3002\u53F0\u8D26\u5DF2\u7ECF\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u4E0D\u4F1A\u4E22\u3002`
|
|
9503
|
+
);
|
|
9504
|
+
}
|
|
9505
|
+
return { fields, type, keyTag, summary: gapSummary(g), module: `${module}/${g.module_detail || MODULE_DEFAULT_CHILD[module]}` };
|
|
9506
|
+
}
|
|
9507
|
+
async function gapSubmit({ client: client3 }, g, { fingerprintText: fingerprintText2, issuetypeOverride, assigneeOverride }) {
|
|
9508
|
+
const summary = gapSummary(g);
|
|
9509
|
+
const keyTag = gapKeyTag(g);
|
|
9510
|
+
const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
|
|
9511
|
+
const dup = findDuplicateGap(open, summary, keyTag);
|
|
9512
|
+
if (dup) {
|
|
9513
|
+
const body = `\u53C8\u4E00\u4E2A\u73B0\u573A\uFF08${fingerprintText2}\uFF09
|
|
9514
|
+
|
|
9515
|
+
**\u73B0\u8C61**\uFF1A${g.phenomenon}
|
|
9516
|
+
|
|
9517
|
+
**\u590D\u73B0**\uFF1A
|
|
9518
|
+
{code}
|
|
9519
|
+
${g.repro}
|
|
9520
|
+
{code}
|
|
9521
|
+
|
|
9522
|
+
**\u66FF\u4EE3\u6CD5**\uFF1A${g.alternative}
|
|
9523
|
+
\u4E25\u91CD\u5EA6\uFF1A${g.severity}`;
|
|
9524
|
+
await client3.addComment(dup.key, body);
|
|
9525
|
+
return { outcome: "appended", key: dup.key, url: client3.browseUrl(dup.key), summary: dup.fields.summary ?? "", alternative: g.alternative };
|
|
9526
|
+
}
|
|
9527
|
+
const [types, me, project] = await Promise.all([client3.createMeta(), client3.myself(), client3.projectInfo()]);
|
|
9528
|
+
const built = buildGapFields(g, {
|
|
9529
|
+
types,
|
|
9530
|
+
me: me.name ?? me.key ?? "",
|
|
9531
|
+
assignee: assigneeOverride || project.lead?.name || project.lead?.key,
|
|
9532
|
+
project: client3.project,
|
|
9533
|
+
fingerprintText: fingerprintText2,
|
|
9534
|
+
issuetypeOverride
|
|
9535
|
+
});
|
|
9536
|
+
const created = await client3.createIssue(built.fields);
|
|
9537
|
+
return { outcome: "created", key: created.key, url: client3.browseUrl(created.key), summary: built.summary, type: built.type.name, module: built.module, alternative: g.alternative };
|
|
9538
|
+
}
|
|
9539
|
+
async function gapSearch({ client: client3 }, keywords, { includeClosed = true } = {}) {
|
|
9540
|
+
const rows = [];
|
|
9541
|
+
let jiraError;
|
|
9542
|
+
try {
|
|
9543
|
+
for (const kw of keywords) {
|
|
9544
|
+
const safe = kw.replace(/["\\]/g, " ").trim();
|
|
9545
|
+
const jql = `project = ${client3.project} AND text ~ "${safe}"${includeClosed ? "" : " AND resolution = Unresolved"} ORDER BY updated DESC`;
|
|
9546
|
+
for (const i of await client3.search(jql, { max: 15 })) {
|
|
9547
|
+
rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, resolution: i.fields.resolution?.name, url: client3.browseUrl(i.key) });
|
|
9548
|
+
}
|
|
9549
|
+
}
|
|
9550
|
+
if (!rows.length) {
|
|
9551
|
+
const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
|
|
9552
|
+
for (const i of open) {
|
|
9553
|
+
if (keywords.some((k) => (i.fields.summary ?? "").includes(k))) {
|
|
9554
|
+
rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, url: client3.browseUrl(i.key) });
|
|
9555
|
+
}
|
|
9556
|
+
}
|
|
9557
|
+
}
|
|
9558
|
+
} catch (e) {
|
|
9559
|
+
jiraError = e.message;
|
|
9560
|
+
}
|
|
9561
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9562
|
+
return { rows: rows.filter((r) => seen.has(r.id) ? false : (seen.add(r.id), true)), jiraError };
|
|
9563
|
+
}
|
|
9564
|
+
async function gapStatus({ client: client3 }, ref, casesSlug = CASES_REPO_SLUG) {
|
|
9565
|
+
const parsed = parseRef(ref, client3.project, casesSlug);
|
|
9566
|
+
if (!parsed) throw new Error(`\u770B\u4E0D\u61C2 ${ref}\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12\uFF09`);
|
|
9567
|
+
if (parsed.kind === "repo") {
|
|
9568
|
+
throw new Error(
|
|
9569
|
+
`${parsed.repo}#${parsed.number} \u662F\u4EA7\u54C1\u4ED3\u7F16\u53F7\uFF0C\u987E\u95EE\u4FA7\u67E5\u4E0D\u5230\u5B83\u7684\u72B6\u6001\uFF08\u6CA1\u6709\u90A3\u4E2A\u4ED3\u7684\u8BFB\u6743\u9650\uFF09\u3002next_step=\u7528 Jira \u5355\u53F7\u67E5\uFF08HCMNX-12\uFF09\u3002\u4EA7\u54C1\u4FA7\u7684\u8FDB\u5C55\u4F1A\u56DE\u5199\u5230 Jira \u5355\u4E0A\uFF0C\u90A3\u662F\u4EA7\u54C1\u5BF9\u5916\u7684\u7EDF\u4E00\u9762\u3002`
|
|
9570
|
+
);
|
|
9571
|
+
}
|
|
9572
|
+
const issue = await client3.issue(parsed.key);
|
|
9573
|
+
const cs = await client3.comments(parsed.key);
|
|
9574
|
+
const status = issue.fields.status?.name;
|
|
9575
|
+
const resolution = issue.fields.resolution?.name;
|
|
9576
|
+
const lines = [`Jira ${issue.key} [${status}${resolution ? "\xB7" + resolution : ""}${issue.fields.priority ? " " + issue.fields.priority.name : ""}] ${issue.fields.summary ?? ""}`, ` ${client3.browseUrl(issue.key)}`];
|
|
9577
|
+
const keyComments = cs.filter((c) => /分诊|已转|已修|合入|不做|重复|改技能|产品侧|代码库已关闭/.test(c.body ?? ""));
|
|
9578
|
+
const last = (keyComments.length ? keyComments : cs).at(-1);
|
|
9579
|
+
if (last) lines.push(` \u6700\u65B0\u5904\u7406\uFF08${String(last.created ?? "").slice(0, 10)} ${last.author?.displayName ?? "?"}\uFF09\uFF1A${(last.body ?? "").split("\n").find((l) => l.trim()) ?? ""}`.slice(0, 400));
|
|
9580
|
+
else lines.push(" \u8FD8\u6CA1\u6709\u4EBA\u5904\u7406\uFF08\u4EA7\u54C1\u4FA7\u6BCF\u5468\u6E05\u4E00\u6B21\uFF1B\u963B\u65AD\u7EA7\u8BF7\u5728\u9879\u76EE\u7FA4\u91CC\u70B9\u540D\u8D1F\u8D23\u4EBA\uFF09");
|
|
9581
|
+
const remote = (await client3.remoteLinks(parsed.key)).map((l) => l.object?.url ?? "").join("\n");
|
|
9582
|
+
const links = linkedRepoRefs(`${remote}
|
|
9583
|
+
${issue.fields.description ?? ""}
|
|
9584
|
+
${cs.map((c) => c.body ?? "").join("\n")}`).map((l) => ({
|
|
9585
|
+
...l,
|
|
9586
|
+
url: repoIssueUrl(l.repo, l.number)
|
|
9587
|
+
}));
|
|
9588
|
+
for (const p of links) lines.push(`\u5DF2\u767B\u8BB0\u4EE3\u7801\u5E93\u6761\u76EE ${p.repo}#${p.number}`, ` ${p.url}`);
|
|
9589
|
+
let nextStep;
|
|
9590
|
+
if (resolution) nextStep = "Jira \u8FD9\u5355\u5DF2\u89E3\u51B3\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF08`hcm version` \u7684 commit \u4F1A\u53D8\uFF09\uFF0C\u8DD1 `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002";
|
|
9591
|
+
else if (status === "\u5DF2\u4FEE\u590D") nextStep = "\u4FEE\u590D\u5DF2\u5408\u5165\u3001\u8FD8\u6CA1\u53D1\u5230\u4F60\u7684\u73AF\u5883\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF0C\u53D1\u5E03\u540E\u590D\u9A8C\u3002";
|
|
9592
|
+
else if (links.length) nextStep = "\u5DF2\u5206\u8BCA\u3001\u4EE3\u7801\u5E93\u5DF2\u767B\u8BB0\uFF0C\u8FD8\u5728\u505A\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF1B\u60F3\u8981\u6392\u671F\u5C31\u5728 Jira \u8FD9\u5355\u4E0B\u7559\u8A00\u3002";
|
|
9593
|
+
else nextStep = `\u7B49\u5206\u8BCA\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF0C\u62A5\u544A\u5199 BLOCKED \xB7 \u5DF2\u63D0 ${issue.key}\u3002`;
|
|
9594
|
+
return { ref, lines, nextStep, jira: { key: issue.key, status, resolution, url: client3.browseUrl(issue.key) }, links };
|
|
9595
|
+
}
|
|
9596
|
+
|
|
9597
|
+
// src/commands/gap.ts
|
|
9598
|
+
var defaultDeps = { client: () => createJiraClient() };
|
|
9599
|
+
async function gapDeps(deps) {
|
|
9600
|
+
return { client: await deps.client() };
|
|
9601
|
+
}
|
|
9602
|
+
function emit4(fmt, data, text) {
|
|
9603
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject22(data, { format: fmt }) + "\n");
|
|
9604
|
+
else process.stdout.write(text() + "\n");
|
|
9605
|
+
}
|
|
9606
|
+
async function run(fn) {
|
|
9607
|
+
try {
|
|
9608
|
+
await fn();
|
|
9609
|
+
} catch (e) {
|
|
9610
|
+
exitWithError(e);
|
|
9611
|
+
}
|
|
9612
|
+
}
|
|
9613
|
+
async function gapSearchCommand(keywords, args, deps = defaultDeps) {
|
|
9614
|
+
await run(async () => {
|
|
9615
|
+
if (!keywords.length) throw new Error("\u7ED9\u81F3\u5C11\u4E00\u4E2A\u5173\u952E\u8BCD\uFF1A\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61");
|
|
9616
|
+
const r = await gapSearch(await gapDeps(deps), keywords, { includeClosed: args.includeClosed !== false });
|
|
9617
|
+
emit4(args.output, r, () => {
|
|
9618
|
+
const head = r.jiraError ? `\u26A0\uFE0F Jira \u6CA1\u67E5\u6210\uFF08${r.jiraError}\uFF09\uFF0C\u4E0B\u9762\u53EA\u6709\u4EA7\u54C1\u4ED3\u7684\u7ED3\u679C\uFF0C\u4E0D\u4EE3\u8868 Jira \u91CC\u6CA1\u6709\u3002
|
|
9619
|
+
` : "";
|
|
9620
|
+
if (!r.rows.length) return `${head}Jira \u4E0E\u4EA7\u54C1\u4ED3\u90FD\u6CA1\u6709\u76F8\u5173\u8BB0\u5F55\u3002\u53EF\u4EE5 submit\uFF0C\u4F46\u5148\u628A\u4E09\u95EE\u7B54\u5B8C\u3002`;
|
|
9621
|
+
return `${head}\u547D\u4E2D ${r.rows.length} \u6761\uFF08\u540C\u4E00\u7F3A\u53E3\u5DF2\u6709\u7F16\u53F7\u5C31\u5728\u90A3\u6761\u4E0B\u8FFD\u52A0\u73B0\u573A\uFF0C\u4E0D\u65B0\u5F00\uFF09\uFF1A
|
|
9622
|
+
${r.rows.map((i) => `${i.where} ${i.id} [${i.state}${i.resolution ? "\xB7" + i.resolution : ""}] ${i.title}
|
|
9623
|
+
${i.url}`).join("\n")}`;
|
|
9624
|
+
});
|
|
9625
|
+
});
|
|
9626
|
+
}
|
|
9627
|
+
async function gapStatusCommand(ref, args, deps = defaultDeps) {
|
|
9628
|
+
await run(async () => {
|
|
9629
|
+
const r = await gapStatus(await gapDeps(deps), ref);
|
|
9630
|
+
emit4(args.output, r, () => [...r.lines, `\u4E0B\u4E00\u6B65\uFF1A${r.nextStep}`].join("\n"));
|
|
9631
|
+
});
|
|
9632
|
+
}
|
|
9633
|
+
async function fingerprintText(env2) {
|
|
9634
|
+
try {
|
|
9635
|
+
const g = await loadGlobalConfig11();
|
|
9636
|
+
const name = resolveActiveEnv5({ envFlag: env2 }, process.env, g);
|
|
9637
|
+
const cfg = await loadEnv11(name);
|
|
9638
|
+
if (!cfg?.endpoint) return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${name}\uFF1A\u6CA1\u6709 endpoint\uFF09`;
|
|
9639
|
+
const http = createHttpClient4({ endpoint: cfg.endpoint.replace(/\/+$/, ""), getAccessToken: async () => null, onRefresh: async () => {
|
|
9640
|
+
} });
|
|
9641
|
+
const resp = await http.get("/api/version/backend");
|
|
9642
|
+
const info = resp.data?.data ?? resp.data ?? {};
|
|
9643
|
+
const commit = info.commit ?? info.gitCommit ?? info.version ?? "?";
|
|
9644
|
+
return `backend ${String(commit).slice(0, 12)} \xB7 CLI ${CLI_VERSION} \xB7 env ${name}`;
|
|
9645
|
+
} catch (e) {
|
|
9646
|
+
return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${env2 ?? "\u672A\u8BBE"}\uFF1B${String(e.message ?? e).split("\n")[0]?.slice(0, 120)}\uFF09`;
|
|
9647
|
+
}
|
|
9648
|
+
}
|
|
9649
|
+
async function gapSubmitCommand(args, deps = defaultDeps) {
|
|
9650
|
+
await run(async () => {
|
|
9651
|
+
const raw = args.file ? readFileSync5(args.file, "utf8") : process.stdin.isTTY ? "" : readFileSync5(0, "utf8");
|
|
9652
|
+
if (!raw.trim()) throw new Error("\u7F3A\u53E3\u8F7D\u8377\uFF1A--file <gap.json> \u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582 JSON");
|
|
9653
|
+
const gap2 = validateGapInput(JSON.parse(raw));
|
|
9654
|
+
const fp = args.fingerprint ?? await fingerprintText(args.env);
|
|
9655
|
+
const r = await gapSubmit(await gapDeps(deps), gap2, { fingerprintText: fp, issuetypeOverride: args.issuetype, assigneeOverride: args.assignee });
|
|
9656
|
+
emit4(
|
|
9657
|
+
args.output,
|
|
9658
|
+
r,
|
|
9659
|
+
() => r.outcome === "appended" ? `Jira \u91CC\u5DF2\u6709\u540C\u4E00\u7F3A\u53E3 ${r.key}\u300C${r.summary}\u300D\uFF0C\u5DF2\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\u8BC4\u8BBA\uFF0C\u6CA1\u6709\u65B0\u5F00\u3002
|
|
9660
|
+
${r.url}
|
|
9661
|
+
\u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u8FD9\u4E2A\u95EE\u9898\u5DF2\u7ECF\u5728\u4EA7\u54C1\u90A3\u8FB9\u6392\u7740\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u5206\u8BCA\u7ED3\u8BBA\u4F1A\u56DE\u5230\u90A3\u5355\u91CC\u3002` : `\u5DF2\u63D0 ${r.key}\uFF08${r.type} \xB7 ${r.module}\uFF09\uFF1A${r.url}
|
|
9662
|
+
\u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u7F3A\u53E3\u5DF2\u63D0\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u4EA7\u54C1\u5206\u8BCA\u540E\u4F1A\u5728\u90A3\u5355\u91CC\u56DE\u590D\u3002\u62A5\u544A\u91CC\u5199\u300CBLOCKED \xB7 \u5DF2\u63D0 ${r.key} \xB7 \u66FF\u4EE3\u6CD5\uFF1A${r.alternative}\u300D\u3002`
|
|
9663
|
+
);
|
|
9664
|
+
});
|
|
9665
|
+
}
|
|
9666
|
+
|
|
9325
9667
|
// src/commands/chiron-doctor.ts
|
|
9326
9668
|
init_auth_guard();
|
|
9327
9669
|
init_exit();
|
|
@@ -9331,17 +9673,17 @@ import {
|
|
|
9331
9673
|
HcmClient as HcmClient21,
|
|
9332
9674
|
CliError as CliError23,
|
|
9333
9675
|
fetchReconIdentity as fetchReconIdentity2,
|
|
9334
|
-
formatObject as
|
|
9676
|
+
formatObject as formatObject23,
|
|
9335
9677
|
httpProbe as httpProbe2,
|
|
9336
9678
|
runDoctor
|
|
9337
9679
|
} from "@hcmai/sdk";
|
|
9338
|
-
var
|
|
9680
|
+
var defaultDeps2 = {
|
|
9339
9681
|
anchors: async (envName, tenant2, as) => {
|
|
9340
9682
|
const ctx = await getActiveAuthContextFromCli({ env: envName, as });
|
|
9341
9683
|
const client3 = HcmClient21.fromAuthContext(ctx);
|
|
9342
|
-
const
|
|
9343
|
-
const identity2 = await fetchReconIdentity2(
|
|
9344
|
-
return { report: await runDoctor(
|
|
9684
|
+
const probe = httpProbe2(client3.raw(), "default");
|
|
9685
|
+
const identity2 = await fetchReconIdentity2(probe, tenant2);
|
|
9686
|
+
return { report: await runDoctor(probe, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
|
|
9345
9687
|
},
|
|
9346
9688
|
fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
|
|
9347
9689
|
fixCases: async (envName) => {
|
|
@@ -9350,7 +9692,7 @@ var defaultDeps = {
|
|
|
9350
9692
|
inspectCases: () => inspectCaseLibrary(),
|
|
9351
9693
|
inspectJira: () => inspectJira()
|
|
9352
9694
|
};
|
|
9353
|
-
async function runChironDoctor(args, deps =
|
|
9695
|
+
async function runChironDoctor(args, deps = defaultDeps2) {
|
|
9354
9696
|
const root = path9.resolve(args.project ?? ".");
|
|
9355
9697
|
const report = { ok: false, project: root, env: null, envName: null, lines: [] };
|
|
9356
9698
|
const envText = await fs10.readFile(path9.join(root, ENV_FILE), "utf8").catch(() => null);
|
|
@@ -9433,9 +9775,9 @@ async function runChironDoctor(args, deps = defaultDeps) {
|
|
|
9433
9775
|
cases = await casesLine();
|
|
9434
9776
|
}
|
|
9435
9777
|
report.lines.push(cases);
|
|
9436
|
-
const
|
|
9778
|
+
const jira = await deps.inspectJira();
|
|
9437
9779
|
report.lines.push(
|
|
9438
|
-
|
|
9780
|
+
jira.ok ? { item: "Jira", verdict: "ok", detail: `${jira.who || "\u5DF2\u8FDE\u63A5"} \xB7 \u770B\u5F97\u5230 ${JIRA_PROJECT2}\uFF08\u4EE4\u724C\u6765\u81EA ${jira.from}\uFF09` } : { item: "Jira", verdict: "warn", detail: jira.reason ?? "\u4E0D\u53EF\u7528", nextStep: "\u73B0\u5728\u4E0D\u914D\u4E5F\u80FD\u4EA4\u4ED8\uFF1B\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u8981\u63D0\u5355\u65F6\u5FC5\u987B\u5148\u914D\u597D" }
|
|
9439
9781
|
);
|
|
9440
9782
|
return finish(report);
|
|
9441
9783
|
}
|
|
@@ -9458,7 +9800,7 @@ async function chironDoctorCommand(args, deps) {
|
|
|
9458
9800
|
try {
|
|
9459
9801
|
const report = await runChironDoctor(args, deps);
|
|
9460
9802
|
const fmt = args.output ?? "table";
|
|
9461
|
-
if (fmt === "json" || fmt === "yaml") process.stdout.write(
|
|
9803
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
|
|
9462
9804
|
else process.stdout.write(renderChironDoctor(report) + "\n");
|
|
9463
9805
|
process.exitCode = report.ok ? 0 : 1;
|
|
9464
9806
|
} catch (e) {
|
|
@@ -9472,7 +9814,7 @@ import { spawnSync as spawnSync2 } from "child_process";
|
|
|
9472
9814
|
import { promises as fs11 } from "fs";
|
|
9473
9815
|
import path10 from "path";
|
|
9474
9816
|
import yaml from "js-yaml";
|
|
9475
|
-
import { formatObject as
|
|
9817
|
+
import { formatObject as formatObject24 } from "@hcmai/sdk";
|
|
9476
9818
|
|
|
9477
9819
|
// src/commands/delivery-action-policy.ts
|
|
9478
9820
|
init_auth_guard();
|
|
@@ -9668,16 +10010,13 @@ function classify(argv, actionResolution) {
|
|
|
9668
10010
|
if (subcommand === "doctor") return direct("R0", "local-discovery", "chiron-doctor");
|
|
9669
10011
|
if (subcommand === "init") return direct("R1", "managed-local-write", "chiron-project-scaffold");
|
|
9670
10012
|
if (subcommand === "test") return direct("R1", "remote-read", "chiron-regression-test");
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
return
|
|
10013
|
+
if (subcommand === "gap") {
|
|
10014
|
+
const third = argv[2] ?? "";
|
|
10015
|
+
if (["search", "status"].includes(third)) return direct("R1", "remote-read", "gap-read");
|
|
10016
|
+
if (third === "submit") return direct("R1", "external-tracker-write", "gap-submit");
|
|
10017
|
+
return forbidden("unknown-command", "\u672A\u77E5 chiron gap \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
|
|
9676
10018
|
}
|
|
9677
|
-
|
|
9678
|
-
return direct("R1", "external-tracker-write", "jira-tracker-write");
|
|
9679
|
-
}
|
|
9680
|
-
return forbidden("unknown-command", "\u672A\u77E5 jira \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
|
|
10019
|
+
return forbidden("unknown-command", "\u672A\u77E5 chiron \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
|
|
9681
10020
|
}
|
|
9682
10021
|
if (name === "skills") {
|
|
9683
10022
|
if (subcommand === "list" || subcommand === "show") {
|
|
@@ -9826,1401 +10165,597 @@ function summarizeTarget(argv, actionResolution) {
|
|
|
9826
10165
|
} else if (id) {
|
|
9827
10166
|
target.recordIdSha256 = sha2564(id);
|
|
9828
10167
|
}
|
|
9829
|
-
for (const flag of PAYLOAD_FLAGS) {
|
|
9830
|
-
const raw = flagValue(argv, flag);
|
|
9831
|
-
if (!raw) continue;
|
|
9832
|
-
target.payloadSha256 = sha2564(raw);
|
|
9833
|
-
try {
|
|
9834
|
-
const parsed = JSON.parse(raw);
|
|
9835
|
-
if (isPlainObject(parsed)) target.fieldNames = Object.keys(parsed).sort();
|
|
9836
|
-
} catch {
|
|
9837
|
-
}
|
|
9838
|
-
}
|
|
9839
|
-
return target;
|
|
9840
|
-
}
|
|
9841
|
-
function payloadError(argv) {
|
|
9842
|
-
for (const flag of PAYLOAD_FLAGS) {
|
|
9843
|
-
const raw = flagValue(argv, flag);
|
|
9844
|
-
if (raw === void 0) continue;
|
|
9845
|
-
try {
|
|
9846
|
-
const parsed = JSON.parse(raw);
|
|
9847
|
-
if (!isPlainObject(parsed)) return true;
|
|
9848
|
-
} catch {
|
|
9849
|
-
return true;
|
|
9850
|
-
}
|
|
9851
|
-
}
|
|
9852
|
-
return false;
|
|
9853
|
-
}
|
|
9854
|
-
function direct(risk, effect, reasonCode) {
|
|
9855
|
-
return {
|
|
9856
|
-
risk,
|
|
9857
|
-
execution: "direct",
|
|
9858
|
-
effect,
|
|
9859
|
-
reasonCode,
|
|
9860
|
-
reason: risk === "R0" ? "\u7EAF\u53D1\u73B0\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002" : "\u53EA\u8BFB\u6216\u53D7\u7BA1\u672C\u5730\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u5E76\u4FDD\u7559\u7ED3\u679C\u3002"
|
|
9861
|
-
};
|
|
9862
|
-
}
|
|
9863
|
-
function guarded(effect, reasonCode) {
|
|
9864
|
-
return {
|
|
9865
|
-
risk: "R2",
|
|
9866
|
-
execution: "guarded",
|
|
9867
|
-
effect,
|
|
9868
|
-
reasonCode,
|
|
9869
|
-
// 🔴 这一句是 R2 档的**主文案**,15 个调用方共用它,顾问跑任何写命令都读到它。
|
|
9870
|
-
// 0.7.0 之前它写的是「只允许在 controlled 项目中通过 delivery prepare +
|
|
9871
|
-
// delivery execute 单次受控执行」——那三个概念随受控执行三步一起删了,
|
|
9872
|
-
// 于是它变成一条指向不存在的路的下一步。既然 CLI 不再自建执行闸,
|
|
9873
|
-
// 真正的下一步就是「这条命令不从这里跑」,而不是「换个 CLI 姿势跑」。
|
|
9874
|
-
reason: "\u8FD9\u6761\u547D\u4EE4\u4F1A\u5199\u6570\u636E\uFF0C\u672C\u901A\u9053\u53EA\u8DD1\u53EA\u8BFB\uFF0C\u6240\u4EE5\u6CA1\u6709\u6267\u884C\u3002next_step=\u8981\u843D\u8FD9\u4E2A\u5199\uFF0C\u6309\u9879\u76EE\u7684\u5199\u6388\u6743\u7EAA\u5F8B\u5728\u73AF\u5883\u91CC\u505A\u6389\uFF08\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u786E\u8BA4\uFF09\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u5B83\u843D\u5E93\u7684\u6837\u5B50\uFF1B\u5982\u679C\u4F60\u8BA4\u4E3A\u5B83\u5176\u5B9E\u4E0D\u5199\u5E93\uFF0C\u53BB\u4EA7\u54C1\u4FA7\u628A effect \u5224\u6210 READ_ONLY\u3002"
|
|
9875
|
-
};
|
|
9876
|
-
}
|
|
9877
|
-
function classifyAction(policy) {
|
|
9878
|
-
if (policy.readOnly) {
|
|
9879
|
-
return {
|
|
9880
|
-
risk: "R1",
|
|
9881
|
-
execution: "direct",
|
|
9882
|
-
effect: "remote-read",
|
|
9883
|
-
reasonCode: "action-read-only",
|
|
9884
|
-
reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
|
|
9885
|
-
};
|
|
9886
|
-
}
|
|
9887
|
-
if (policy.effect === "declared-unknown") {
|
|
9888
|
-
return {
|
|
9889
|
-
risk: "R2",
|
|
9890
|
-
execution: "guarded",
|
|
9891
|
-
effect: "undetermined",
|
|
9892
|
-
reasonCode: "action-effect-undetermined",
|
|
9893
|
-
reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
|
|
9894
|
-
};
|
|
9895
|
-
}
|
|
9896
|
-
if (policy.effect === "unrecognized-effect") {
|
|
9897
|
-
return {
|
|
9898
|
-
risk: "R2",
|
|
9899
|
-
execution: "guarded",
|
|
9900
|
-
effect: "undetermined",
|
|
9901
|
-
reasonCode: "action-effect-unrecognized",
|
|
9902
|
-
reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
|
|
9903
|
-
};
|
|
9904
|
-
}
|
|
9905
|
-
return guarded("tenant-write", "action-write");
|
|
9906
|
-
}
|
|
9907
|
-
function describeEffectRaw(raw) {
|
|
9908
|
-
if (raw === null) return "null";
|
|
9909
|
-
if (typeof raw === "string") return JSON.stringify(raw);
|
|
9910
|
-
try {
|
|
9911
|
-
return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
|
|
9912
|
-
} catch {
|
|
9913
|
-
return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
|
|
9914
|
-
}
|
|
9915
|
-
}
|
|
9916
|
-
function forbidden(reasonCode, reason) {
|
|
9917
|
-
return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
|
|
9918
|
-
}
|
|
9919
|
-
function evidenceFor(risk) {
|
|
9920
|
-
if (risk === "R0") return ["command-digest", "discovery-result"];
|
|
9921
|
-
if (risk === "R1") return ["command-digest", "target-aliases", "result-summary"];
|
|
9922
|
-
if (risk === "R2") {
|
|
9923
|
-
return [
|
|
9924
|
-
"command-digest",
|
|
9925
|
-
"explicit-target-aliases",
|
|
9926
|
-
"pre-state-or-dry-run",
|
|
9927
|
-
"rollback-plan",
|
|
9928
|
-
"execution-receipt",
|
|
9929
|
-
"post-verification"
|
|
9930
|
-
];
|
|
9931
|
-
}
|
|
9932
|
-
return ["governance-decision"];
|
|
9933
|
-
}
|
|
9934
|
-
function flagValue(argv, flag) {
|
|
9935
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
9936
|
-
const arg = argv[index];
|
|
9937
|
-
if (arg === void 0) continue;
|
|
9938
|
-
if (arg === flag) return argv[index + 1];
|
|
9939
|
-
if (arg.startsWith(`${flag}=`)) return arg.slice(flag.length + 1);
|
|
9940
|
-
}
|
|
9941
|
-
return void 0;
|
|
9942
|
-
}
|
|
9943
|
-
function hasFlag(argv, flag) {
|
|
9944
|
-
return argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
9945
|
-
}
|
|
9946
|
-
function flagName(arg) {
|
|
9947
|
-
const equals = arg.indexOf("=");
|
|
9948
|
-
return equals < 0 ? arg : arg.slice(0, equals);
|
|
9949
|
-
}
|
|
9950
|
-
function valuesAfterFlag(argv, flag) {
|
|
9951
|
-
const index = argv.indexOf(flag);
|
|
9952
|
-
if (index < 0) return [];
|
|
9953
|
-
const values = [];
|
|
9954
|
-
for (let cursor = index + 1; cursor < argv.length; cursor += 1) {
|
|
9955
|
-
const value = argv[cursor];
|
|
9956
|
-
if (value === void 0 || value.startsWith("-")) break;
|
|
9957
|
-
values.push(value);
|
|
9958
|
-
}
|
|
9959
|
-
return values;
|
|
9960
|
-
}
|
|
9961
|
-
function sha2564(value) {
|
|
9962
|
-
return createHash5("sha256").update(value).digest("hex");
|
|
9963
|
-
}
|
|
9964
|
-
function isPlainObject(value) {
|
|
9965
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9966
|
-
}
|
|
9967
|
-
|
|
9968
|
-
// src/commands/delivery-action-policy.ts
|
|
9969
|
-
async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
9970
|
-
const local = assessDeliveryCommand(inputArgv);
|
|
9971
|
-
if (local.reasonCode !== "action-effect-unclassified") return local;
|
|
9972
|
-
const request = parseActionRequest(inputArgv);
|
|
9973
|
-
if ("status" in request) {
|
|
9974
|
-
return assessDeliveryCommand(inputArgv, { actionResolution: request });
|
|
9975
|
-
}
|
|
9976
|
-
const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
|
|
9977
|
-
return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
|
|
9978
|
-
}
|
|
9979
|
-
async function resolveCoreAction(request) {
|
|
9980
|
-
try {
|
|
9981
|
-
const auth = await getActiveAuthContextFromCli({
|
|
9982
|
-
env: request.env,
|
|
9983
|
-
as: request.identity,
|
|
9984
|
-
profile: request.profile
|
|
9985
|
-
});
|
|
9986
|
-
const description = await HcmClient22.fromAuthContext(auth).describe(request.model);
|
|
9987
|
-
const named = description.actions.filter((action) => action.name === request.action);
|
|
9988
|
-
if (named.length === 0) {
|
|
9989
|
-
const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
|
|
9990
|
-
return failed(
|
|
9991
|
-
"action-metadata-not-found",
|
|
9992
|
-
`Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002${degraded}next_step=\u7528 \`hcm describe ${request.model}\` \u770B\u5B83\u5217\u51FA\u7684 Action \u540D\uFF08\u811A\u672C Action \u4F1A\u6807 [script]\uFF09`
|
|
9993
|
-
);
|
|
9994
|
-
}
|
|
9995
|
-
const matches2 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
|
|
9996
|
-
if (matches2.length === 0) {
|
|
9997
|
-
const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
|
|
9998
|
-
return failed(
|
|
9999
|
-
"action-shape-mismatch",
|
|
10000
|
-
`${request.model}.${request.action} \u5B58\u5728\uFF0C\u4F46\u5F62\u6001\u5BF9\u4E0D\u4E0A\uFF1A\u4F60\u7ED9\u7684\u662F scope=${request.scope} method=${request.httpMethod}\uFF0C\u5143\u6570\u636E\u91CC\u662F ${shapes}\u3002next_step=\u53BB\u6389 --scope/--method \u8BA9 CLI \u6309\u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF0C\u6216\u6539\u6210\u4E0A\u9762\u7684\u5F62\u6001`
|
|
10001
|
-
);
|
|
10002
|
-
}
|
|
10003
|
-
if (matches2.length > 1) {
|
|
10004
|
-
return failed(
|
|
10005
|
-
"action-metadata-ambiguous",
|
|
10006
|
-
`${request.model}.${request.action} \u5728\u5143\u6570\u636E\u91CC\u6709\u591A\u79CD\u5F62\u6001\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u3002next_step=\u7528 --scope \u4E0E --method \u6307\u660E\u8981\u8C03\u54EA\u4E00\u4E2A`
|
|
10007
|
-
);
|
|
10168
|
+
for (const flag of PAYLOAD_FLAGS) {
|
|
10169
|
+
const raw = flagValue(argv, flag);
|
|
10170
|
+
if (!raw) continue;
|
|
10171
|
+
target.payloadSha256 = sha2564(raw);
|
|
10172
|
+
try {
|
|
10173
|
+
const parsed = JSON.parse(raw);
|
|
10174
|
+
if (isPlainObject(parsed)) target.fieldNames = Object.keys(parsed).sort();
|
|
10175
|
+
} catch {
|
|
10008
10176
|
}
|
|
10009
|
-
return policyFromActionMeta(matches2[0], request);
|
|
10010
|
-
} catch {
|
|
10011
|
-
return failed(
|
|
10012
|
-
"action-metadata-unavailable",
|
|
10013
|
-
"\u65E0\u6CD5\u8BFB\u53D6 Core Action \u5143\u6570\u636E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
|
|
10014
|
-
);
|
|
10015
10177
|
}
|
|
10178
|
+
return target;
|
|
10016
10179
|
}
|
|
10017
|
-
function
|
|
10018
|
-
const
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
return failed(
|
|
10027
|
-
"action-readonly-unclassified",
|
|
10028
|
-
"Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
|
|
10029
|
-
);
|
|
10180
|
+
function payloadError(argv) {
|
|
10181
|
+
for (const flag of PAYLOAD_FLAGS) {
|
|
10182
|
+
const raw = flagValue(argv, flag);
|
|
10183
|
+
if (raw === void 0) continue;
|
|
10184
|
+
try {
|
|
10185
|
+
const parsed = JSON.parse(raw);
|
|
10186
|
+
if (!isPlainObject(parsed)) return true;
|
|
10187
|
+
} catch {
|
|
10188
|
+
return true;
|
|
10030
10189
|
}
|
|
10031
|
-
return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
|
|
10032
10190
|
}
|
|
10191
|
+
return false;
|
|
10192
|
+
}
|
|
10193
|
+
function direct(risk, effect, reasonCode) {
|
|
10033
10194
|
return {
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
readOnly: effectClass === "read-only"
|
|
10040
|
-
}
|
|
10195
|
+
risk,
|
|
10196
|
+
execution: "direct",
|
|
10197
|
+
effect,
|
|
10198
|
+
reasonCode,
|
|
10199
|
+
reason: risk === "R0" ? "\u7EAF\u53D1\u73B0\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002" : "\u53EA\u8BFB\u6216\u53D7\u7BA1\u672C\u5730\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u5E76\u4FDD\u7559\u7ED3\u679C\u3002"
|
|
10041
10200
|
};
|
|
10042
10201
|
}
|
|
10043
|
-
function
|
|
10044
|
-
return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
|
|
10045
|
-
}
|
|
10046
|
-
function parseActionRequest(inputArgv) {
|
|
10047
|
-
const argv = normalizeAssessedArgv(inputArgv);
|
|
10048
|
-
const spec = argv[1] ?? "";
|
|
10049
|
-
const separator = spec.indexOf(".");
|
|
10050
|
-
if (separator <= 0 || separator === spec.length - 1) {
|
|
10051
|
-
return failed("invalid-action-spec", "Action \u5FC5\u987B\u4F7F\u7528 <Model>.<Action> \u683C\u5F0F\u3002");
|
|
10052
|
-
}
|
|
10053
|
-
const explicitMethod = flagValue2(argv, "--method");
|
|
10054
|
-
const httpMethod = (explicitMethod ?? "POST").toUpperCase();
|
|
10055
|
-
if (!["GET", "POST", "PUT", "DELETE"].includes(httpMethod)) {
|
|
10056
|
-
return failed("invalid-action-method", "Action method \u5FC5\u987B\u662F GET\u3001POST\u3001PUT \u6216 DELETE\u3002");
|
|
10057
|
-
}
|
|
10058
|
-
const explicitScope = flagValue2(argv, "--scope");
|
|
10059
|
-
const scope = explicitScope ?? (flagValue2(argv, "--id") ? "object" : "class");
|
|
10060
|
-
if (scope !== "class" && scope !== "object") {
|
|
10061
|
-
return failed("invalid-action-scope", "Action scope \u5FC5\u987B\u662F class \u6216 object\u3002");
|
|
10062
|
-
}
|
|
10202
|
+
function guarded(effect, reasonCode) {
|
|
10063
10203
|
return {
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10204
|
+
risk: "R2",
|
|
10205
|
+
execution: "guarded",
|
|
10206
|
+
effect,
|
|
10207
|
+
reasonCode,
|
|
10208
|
+
// 🔴 这一句是 R2 档的**主文案**,15 个调用方共用它,顾问跑任何写命令都读到它。
|
|
10209
|
+
// 0.7.0 之前它写的是「只允许在 controlled 项目中通过 delivery prepare +
|
|
10210
|
+
// delivery execute 单次受控执行」——那三个概念随受控执行三步一起删了,
|
|
10211
|
+
// 于是它变成一条指向不存在的路的下一步。既然 CLI 不再自建执行闸,
|
|
10212
|
+
// 真正的下一步就是「这条命令不从这里跑」,而不是「换个 CLI 姿势跑」。
|
|
10213
|
+
reason: "\u8FD9\u6761\u547D\u4EE4\u4F1A\u5199\u6570\u636E\uFF0C\u672C\u901A\u9053\u53EA\u8DD1\u53EA\u8BFB\uFF0C\u6240\u4EE5\u6CA1\u6709\u6267\u884C\u3002next_step=\u8981\u843D\u8FD9\u4E2A\u5199\uFF0C\u6309\u9879\u76EE\u7684\u5199\u6388\u6743\u7EAA\u5F8B\u5728\u73AF\u5883\u91CC\u505A\u6389\uFF08\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u786E\u8BA4\uFF09\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u5B83\u843D\u5E93\u7684\u6837\u5B50\uFF1B\u5982\u679C\u4F60\u8BA4\u4E3A\u5B83\u5176\u5B9E\u4E0D\u5199\u5E93\uFF0C\u53BB\u4EA7\u54C1\u4FA7\u628A effect \u5224\u6210 READ_ONLY\u3002"
|
|
10072
10214
|
};
|
|
10073
10215
|
}
|
|
10074
|
-
function
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
}
|
|
10083
|
-
|
|
10084
|
-
// src/commands/xlsx-peek.ts
|
|
10085
|
-
import { readFileSync as readFileSync5 } from "fs";
|
|
10086
|
-
import { inflateRawSync } from "zlib";
|
|
10087
|
-
function readZip(buf, want) {
|
|
10088
|
-
let eocd = -1;
|
|
10089
|
-
for (let i = buf.length - 22; i >= 0 && i > buf.length - 66e3; i--) {
|
|
10090
|
-
if (buf.readUInt32LE(i) === 101010256) {
|
|
10091
|
-
eocd = i;
|
|
10092
|
-
break;
|
|
10093
|
-
}
|
|
10094
|
-
}
|
|
10095
|
-
if (eocd < 0) throw new Error("\u4E0D\u662F\u6709\u6548\u7684 zip/xlsx\uFF08\u627E\u4E0D\u5230\u4E2D\u592E\u76EE\u5F55\uFF09");
|
|
10096
|
-
const count = buf.readUInt16LE(eocd + 10);
|
|
10097
|
-
let p = buf.readUInt32LE(eocd + 16);
|
|
10098
|
-
const out = [];
|
|
10099
|
-
for (let n = 0; n < count; n++) {
|
|
10100
|
-
if (buf.readUInt32LE(p) !== 33639248) break;
|
|
10101
|
-
const method = buf.readUInt16LE(p + 10);
|
|
10102
|
-
const compressedSize = buf.readUInt32LE(p + 20);
|
|
10103
|
-
const nameLen = buf.readUInt16LE(p + 28);
|
|
10104
|
-
const extraLen = buf.readUInt16LE(p + 30);
|
|
10105
|
-
const commentLen = buf.readUInt16LE(p + 32);
|
|
10106
|
-
const localOffset = buf.readUInt32LE(p + 42);
|
|
10107
|
-
const name = buf.subarray(p + 46, p + 46 + nameLen).toString("utf8");
|
|
10108
|
-
if (want(name)) {
|
|
10109
|
-
const lnameLen = buf.readUInt16LE(localOffset + 26);
|
|
10110
|
-
const lextraLen = buf.readUInt16LE(localOffset + 28);
|
|
10111
|
-
const start = localOffset + 30 + lnameLen + lextraLen;
|
|
10112
|
-
const raw = buf.subarray(start, start + compressedSize);
|
|
10113
|
-
if (method === 0) out.push({ name, data: Buffer.from(raw) });
|
|
10114
|
-
else if (method === 8) out.push({ name, data: inflateRawSync(raw) });
|
|
10115
|
-
else throw new Error(`xlsx \u91CC\u7684 ${name} \u7528\u4E86\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F ${method}`);
|
|
10116
|
-
}
|
|
10117
|
-
p += 46 + nameLen + extraLen + commentLen;
|
|
10118
|
-
}
|
|
10119
|
-
return out;
|
|
10120
|
-
}
|
|
10121
|
-
var decode = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
10122
|
-
function xlsxRows(file, maxRows = 50) {
|
|
10123
|
-
const buf = readFileSync5(file);
|
|
10124
|
-
const [sheet] = readZip(buf, (n) => n === "xl/worksheets/sheet1.xml");
|
|
10125
|
-
if (!sheet) throw new Error(`${file} \u91CC\u6CA1\u6709 xl/worksheets/sheet1.xml\uFF0C\u53EF\u80FD\u4E0D\u662F xlsx`);
|
|
10126
|
-
const [shared] = readZip(buf, (n) => n === "xl/sharedStrings.xml");
|
|
10127
|
-
const sharedStrings = [];
|
|
10128
|
-
if (shared) {
|
|
10129
|
-
for (const si of shared.data.toString("utf8").split("<si>").slice(1)) {
|
|
10130
|
-
sharedStrings.push(decode([...si.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((m) => m[1] ?? "").join("")));
|
|
10131
|
-
}
|
|
10132
|
-
}
|
|
10133
|
-
const xml = sheet.data.toString("utf8");
|
|
10134
|
-
const rows = [];
|
|
10135
|
-
for (const rowXml of xml.split("<row").slice(1)) {
|
|
10136
|
-
if (rows.length >= maxRows) break;
|
|
10137
|
-
const cells = [];
|
|
10138
|
-
for (const m of rowXml.matchAll(/<c\b([^>]*)>([\s\S]*?)<\/c>/g)) {
|
|
10139
|
-
const attrs = m[1] ?? "";
|
|
10140
|
-
const body = m[2] ?? "";
|
|
10141
|
-
const v = /<v>([\s\S]*?)<\/v>/.exec(body)?.[1] ?? "";
|
|
10142
|
-
const inline = [...body.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((x) => x[1] ?? "").join("");
|
|
10143
|
-
if (/t="s"/.test(attrs)) cells.push(sharedStrings[Number(v)] ?? "");
|
|
10144
|
-
else if (inline) cells.push(decode(inline));
|
|
10145
|
-
else cells.push(decode(v));
|
|
10146
|
-
}
|
|
10147
|
-
rows.push(cells);
|
|
10216
|
+
function classifyAction(policy) {
|
|
10217
|
+
if (policy.readOnly) {
|
|
10218
|
+
return {
|
|
10219
|
+
risk: "R1",
|
|
10220
|
+
execution: "direct",
|
|
10221
|
+
effect: "remote-read",
|
|
10222
|
+
reasonCode: "action-read-only",
|
|
10223
|
+
reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
|
|
10224
|
+
};
|
|
10148
10225
|
}
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
throw new Error(`${where}: \u7528\u4F8B\u8981\u6709 name \u4E0E\u81F3\u5C11\u4E00\u6761 checks`);
|
|
10226
|
+
if (policy.effect === "declared-unknown") {
|
|
10227
|
+
return {
|
|
10228
|
+
risk: "R2",
|
|
10229
|
+
execution: "guarded",
|
|
10230
|
+
effect: "undetermined",
|
|
10231
|
+
reasonCode: "action-effect-undetermined",
|
|
10232
|
+
reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
|
|
10233
|
+
};
|
|
10158
10234
|
}
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
10165
|
-
|
|
10166
|
-
|
|
10167
|
-
}
|
|
10168
|
-
tokenize(c.run);
|
|
10169
|
-
}
|
|
10170
|
-
if (c.page && !c.expect_text?.length) throw new Error(`${at}: \u9875\u9762\u5224\u636E\u81F3\u5C11\u8981\u4E00\u4E2A expect_text\u2014\u2014\u622A\u56FE\u5B58\u5728\u4E0D\u7B49\u4E8E\u9875\u9762\u5BF9`);
|
|
10171
|
-
if (c.file && !hasContentAssertion(c)) throw new Error(`${at}: \u8BFB\u6587\u4EF6\u5374\u6CA1\u6709\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")}\uFF09\u2014\u2014\u6587\u4EF6\u5B58\u5728\u4E0D\u7B49\u4E8E\u5185\u5BB9\u5BF9`);
|
|
10172
|
-
});
|
|
10173
|
-
if (!spec.checks.some(hasContentAssertion)) {
|
|
10174
|
-
throw new Error(
|
|
10175
|
-
`${where}: \u6574\u4EFD\u7528\u4F8B\u6CA1\u6709\u4EFB\u4F55\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")} / expect_text\uFF09\uFF0C\u53EA\u8DD1\u4E0D\u770B\u7B49\u4E8E\u6CA1\u6D4B\u3002`
|
|
10176
|
-
);
|
|
10235
|
+
if (policy.effect === "unrecognized-effect") {
|
|
10236
|
+
return {
|
|
10237
|
+
risk: "R2",
|
|
10238
|
+
execution: "guarded",
|
|
10239
|
+
effect: "undetermined",
|
|
10240
|
+
reasonCode: "action-effect-unrecognized",
|
|
10241
|
+
reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
|
|
10242
|
+
};
|
|
10177
10243
|
}
|
|
10244
|
+
return guarded("tenant-write", "action-write");
|
|
10178
10245
|
}
|
|
10179
|
-
function
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
if (quote) {
|
|
10187
|
-
if (ch === quote) quote = null;
|
|
10188
|
-
else if (ch === "\\" && quote === '"' && i + 1 < line.length) {
|
|
10189
|
-
cur += line[++i];
|
|
10190
|
-
} else cur += ch;
|
|
10191
|
-
continue;
|
|
10192
|
-
}
|
|
10193
|
-
if (ch === '"' || ch === "'") {
|
|
10194
|
-
quote = ch;
|
|
10195
|
-
started = true;
|
|
10196
|
-
continue;
|
|
10197
|
-
}
|
|
10198
|
-
if (ch === "\\" && i + 1 < line.length) {
|
|
10199
|
-
cur += line[++i];
|
|
10200
|
-
started = true;
|
|
10201
|
-
continue;
|
|
10202
|
-
}
|
|
10203
|
-
if (/\s/.test(ch)) {
|
|
10204
|
-
if (started || cur) {
|
|
10205
|
-
out.push(cur);
|
|
10206
|
-
cur = "";
|
|
10207
|
-
started = false;
|
|
10208
|
-
}
|
|
10209
|
-
continue;
|
|
10210
|
-
}
|
|
10211
|
-
cur += ch;
|
|
10212
|
-
started = true;
|
|
10246
|
+
function describeEffectRaw(raw) {
|
|
10247
|
+
if (raw === null) return "null";
|
|
10248
|
+
if (typeof raw === "string") return JSON.stringify(raw);
|
|
10249
|
+
try {
|
|
10250
|
+
return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
|
|
10251
|
+
} catch {
|
|
10252
|
+
return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
|
|
10213
10253
|
}
|
|
10214
|
-
if (quote) throw new Error(`\u547D\u4EE4\u91CC\u7684\u5F15\u53F7\u6CA1\u95ED\u5408\uFF1A${line}`);
|
|
10215
|
-
if (started || cur) out.push(cur);
|
|
10216
|
-
return out;
|
|
10217
10254
|
}
|
|
10218
|
-
function
|
|
10219
|
-
|
|
10220
|
-
const oa = stdout.indexOf("{"), ob = stdout.lastIndexOf("}");
|
|
10221
|
-
const aa = stdout.indexOf("["), ab = stdout.lastIndexOf("]");
|
|
10222
|
-
if (aa >= 0 && ab > aa) candidates.push([aa, ab]);
|
|
10223
|
-
if (oa >= 0 && ob > oa) candidates.push([oa, ob]);
|
|
10224
|
-
candidates.sort((x, y) => x[0] - y[0]);
|
|
10225
|
-
for (const [a, b] of candidates) {
|
|
10226
|
-
try {
|
|
10227
|
-
return JSON.parse(stdout.slice(a, b + 1));
|
|
10228
|
-
} catch {
|
|
10229
|
-
}
|
|
10230
|
-
}
|
|
10231
|
-
return void 0;
|
|
10255
|
+
function forbidden(reasonCode, reason) {
|
|
10256
|
+
return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
|
|
10232
10257
|
}
|
|
10233
|
-
function
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10258
|
+
function evidenceFor(risk) {
|
|
10259
|
+
if (risk === "R0") return ["command-digest", "discovery-result"];
|
|
10260
|
+
if (risk === "R1") return ["command-digest", "target-aliases", "result-summary"];
|
|
10261
|
+
if (risk === "R2") {
|
|
10262
|
+
return [
|
|
10263
|
+
"command-digest",
|
|
10264
|
+
"explicit-target-aliases",
|
|
10265
|
+
"pre-state-or-dry-run",
|
|
10266
|
+
"rollback-plan",
|
|
10267
|
+
"execution-receipt",
|
|
10268
|
+
"post-verification"
|
|
10269
|
+
];
|
|
10245
10270
|
}
|
|
10246
|
-
return
|
|
10271
|
+
return ["governance-decision"];
|
|
10247
10272
|
}
|
|
10248
|
-
function
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
const n = Number(want), a = Array.isArray(actual) ? actual.length : Number(actual);
|
|
10255
|
-
switch (op) {
|
|
10256
|
-
case ">":
|
|
10257
|
-
return Number.isFinite(a) && a > n;
|
|
10258
|
-
case "<":
|
|
10259
|
-
return Number.isFinite(a) && a < n;
|
|
10260
|
-
case ">=":
|
|
10261
|
-
return Number.isFinite(a) && a >= n;
|
|
10262
|
-
case "<=":
|
|
10263
|
-
return Number.isFinite(a) && a <= n;
|
|
10264
|
-
case "!=":
|
|
10265
|
-
return String(actual) !== want;
|
|
10266
|
-
default:
|
|
10267
|
-
return String(actual) === want;
|
|
10273
|
+
function flagValue(argv, flag) {
|
|
10274
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
10275
|
+
const arg = argv[index];
|
|
10276
|
+
if (arg === void 0) continue;
|
|
10277
|
+
if (arg === flag) return argv[index + 1];
|
|
10278
|
+
if (arg.startsWith(`${flag}=`)) return arg.slice(flag.length + 1);
|
|
10268
10279
|
}
|
|
10280
|
+
return void 0;
|
|
10269
10281
|
}
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
const vars = {};
|
|
10286
|
-
const fill = (text) => text.replace(/\$\{(\w+)\}/g, (_, k) => {
|
|
10287
|
-
if (vars[k] === void 0) throw new Error(`\u7528\u5230\u4E86 ${"$"}{${k}} \u4F46\u524D\u9762\u6CA1\u6709\u54EA\u4E00\u6B65\u6355\u83B7\u5B83`);
|
|
10288
|
-
return vars[k];
|
|
10289
|
-
});
|
|
10290
|
-
for (const c of spec.checks) {
|
|
10291
|
-
try {
|
|
10292
|
-
if (c.run) {
|
|
10293
|
-
const argv2 = tokenize(fill(c.run)).slice(1);
|
|
10294
|
-
const verdict = await deps.assess(argv2);
|
|
10295
|
-
if (verdict.execution !== "direct") {
|
|
10296
|
-
results.push({
|
|
10297
|
-
name: c.name,
|
|
10298
|
-
verdict: "fail",
|
|
10299
|
-
// 🔴 `verdict.reason` 里已经带着分档理由与 `next_step=`(见 delivery.ts 的
|
|
10300
|
-
// action-effect-undetermined / action-effect-unrecognized 两支)。此前这里
|
|
10301
|
-
// 把它整个丢掉、自己编了一句「走 delivery assess → prepare → execute」,
|
|
10302
|
-
// 而那三条命令已于 0.7.0 删除 —— 顾问撞到写命令,拿到的是一条不存在的路。
|
|
10303
|
-
// 手上有的就要打出来,不要自己编第二句。
|
|
10304
|
-
detail: `\u8FD9\u6761\u547D\u4EE4\u6309\u4EA4\u4ED8\u98CE\u63A7\u662F ${verdict.risk} / ${verdict.execution}\uFF08${verdict.reasonCode}\uFF09\uFF0C\u6CA1\u6709\u8DD1\u3002${verdict.reason} \u7528\u4F8B\u53EA\u8DD1\u53EA\u8BFB\uFF1A\u8981\u65AD\u8A00\u5199\u64CD\u4F5C\u7684\u7ED3\u679C\uFF0C\u5148\u5728\u73AF\u5883\u91CC\u628A\u5B83\u505A\u6389\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u843D\u5E93\u7684\u6837\u5B50\u3002`
|
|
10305
|
-
});
|
|
10306
|
-
continue;
|
|
10307
|
-
}
|
|
10308
|
-
if (opts.env && !argv2.includes("--env")) argv2.push("--env", opts.env);
|
|
10309
|
-
const as2 = c.as ?? opts.as;
|
|
10310
|
-
if (as2 && !argv2.includes("--as")) argv2.push("--as", as2);
|
|
10311
|
-
const r2 = deps.hcm(argv2, root);
|
|
10312
|
-
const want = c.expect ?? {};
|
|
10313
|
-
const bad = [];
|
|
10314
|
-
if (want.exit !== void 0 && r2.status !== want.exit) bad.push(`\u9000\u51FA\u7801 ${r2.status} \u2260 ${want.exit}`);
|
|
10315
|
-
for (const t of want.stdout_contains ?? []) if (!r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
10316
|
-
for (const t of want.stdout_not_contains ?? []) if (r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
|
|
10317
|
-
if (want.json) {
|
|
10318
|
-
const parsed = parseJsonLoose(r2.stdout);
|
|
10319
|
-
if (parsed === void 0) bad.push("\u8F93\u51FA\u4E0D\u662F JSON\uFF0C\u65E0\u6CD5\u6309 json \u5224\u636E\u6BD4\u5BF9");
|
|
10320
|
-
if (parsed !== void 0) {
|
|
10321
|
-
for (const [expr, rule] of Object.entries(want.json)) {
|
|
10322
|
-
const actual = pick(parsed, expr);
|
|
10323
|
-
if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
|
|
10324
|
-
}
|
|
10325
|
-
}
|
|
10326
|
-
}
|
|
10327
|
-
if (c.capture && bad.length === 0) {
|
|
10328
|
-
const parsed = parseJsonLoose(r2.stdout);
|
|
10329
|
-
for (const [name, expr] of Object.entries(c.capture)) {
|
|
10330
|
-
const v = pick(parsed, expr);
|
|
10331
|
-
if (v === void 0 || v === null || String(v) === "") bad.push(`\u8981\u6355\u83B7\u7684 ${name}\uFF08${expr}\uFF09\u5728\u8F93\u51FA\u91CC\u53D6\u4E0D\u5230`);
|
|
10332
|
-
else vars[name] = String(v);
|
|
10333
|
-
}
|
|
10334
|
-
}
|
|
10335
|
-
results.push(bad.length ? { name: c.name, verdict: "fail", detail: `${bad.join("\uFF1B")}${r2.stderr.trim() ? `\uFF5Cstderr: ${r2.stderr.trim().split("\n")[0]}` : ""}` } : { name: c.name, verdict: hasContentAssertion(c) ? "pass" : "step", detail: c.capture ? `\u6355\u83B7 ${Object.keys(c.capture).join("\u3001")}` : "" });
|
|
10336
|
-
continue;
|
|
10337
|
-
}
|
|
10338
|
-
if (c.file) {
|
|
10339
|
-
const file = path10.resolve(root, fill(c.file));
|
|
10340
|
-
const want = c.expect ?? {};
|
|
10341
|
-
const bad = [];
|
|
10342
|
-
if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
|
|
10343
|
-
const rows = deps.readXlsx(file);
|
|
10344
|
-
const header = (rows[0] ?? []).map((x) => String(x).trim());
|
|
10345
|
-
for (const h of want.xlsx_header ?? []) if (!header.includes(h)) bad.push(`\u8868\u5934\u91CC\u6CA1\u6709\u300C${h}\u300D\uFF0C\u5B9E\u9645\u662F [${header.slice(0, 8).join(", ")}]`);
|
|
10346
|
-
if (want.xlsx_min_rows !== void 0 && rows.length - 1 < want.xlsx_min_rows) bad.push(`\u6570\u636E\u884C ${Math.max(rows.length - 1, 0)} \u5C11\u4E8E ${want.xlsx_min_rows}`);
|
|
10347
|
-
}
|
|
10348
|
-
if (want.text_contains) {
|
|
10349
|
-
const text = await deps.readText(file);
|
|
10350
|
-
for (const t of want.text_contains) if (!text.includes(t)) bad.push(`\u6587\u4EF6\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
10351
|
-
}
|
|
10352
|
-
results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
|
|
10353
|
-
continue;
|
|
10354
|
-
}
|
|
10355
|
-
const out = path10.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
|
|
10356
|
-
const argv = ["--path", fill(c.page), "--out", out];
|
|
10357
|
-
if (opts.env) argv.push("--env", opts.env);
|
|
10358
|
-
const as = c.as ?? opts.as;
|
|
10359
|
-
if (as) argv.push("--as", as);
|
|
10360
|
-
for (const t of c.expect_text ?? []) argv.push("--expect-text", t);
|
|
10361
|
-
for (const t of c.reject_text ?? []) argv.push("--reject-text", t);
|
|
10362
|
-
const r = deps.pageAcceptance(root, argv);
|
|
10363
|
-
results.push(r.status === 0 ? { name: c.name, verdict: "pass", detail: out } : { name: c.name, verdict: "fail", detail: (r.stderr || r.stdout).trim().split("\n").slice(-1)[0] ?? `\u9000\u51FA\u7801 ${r.status}` });
|
|
10364
|
-
} catch (e) {
|
|
10365
|
-
results.push({ name: c.name, verdict: "fail", detail: e.message });
|
|
10366
|
-
}
|
|
10282
|
+
function hasFlag(argv, flag) {
|
|
10283
|
+
return argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
10284
|
+
}
|
|
10285
|
+
function flagName(arg) {
|
|
10286
|
+
const equals = arg.indexOf("=");
|
|
10287
|
+
return equals < 0 ? arg : arg.slice(0, equals);
|
|
10288
|
+
}
|
|
10289
|
+
function valuesAfterFlag(argv, flag) {
|
|
10290
|
+
const index = argv.indexOf(flag);
|
|
10291
|
+
if (index < 0) return [];
|
|
10292
|
+
const values = [];
|
|
10293
|
+
for (let cursor = index + 1; cursor < argv.length; cursor += 1) {
|
|
10294
|
+
const value = argv[cursor];
|
|
10295
|
+
if (value === void 0 || value.startsWith("-")) break;
|
|
10296
|
+
values.push(value);
|
|
10367
10297
|
}
|
|
10368
|
-
return
|
|
10298
|
+
return values;
|
|
10369
10299
|
}
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10300
|
+
function sha2564(value) {
|
|
10301
|
+
return createHash5("sha256").update(value).digest("hex");
|
|
10302
|
+
}
|
|
10303
|
+
function isPlainObject(value) {
|
|
10304
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10305
|
+
}
|
|
10306
|
+
|
|
10307
|
+
// src/commands/delivery-action-policy.ts
|
|
10308
|
+
async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
10309
|
+
const local = assessDeliveryCommand(inputArgv);
|
|
10310
|
+
if (local.reasonCode !== "action-effect-unclassified") return local;
|
|
10311
|
+
const request = parseActionRequest(inputArgv);
|
|
10312
|
+
if ("status" in request) {
|
|
10313
|
+
return assessDeliveryCommand(inputArgv, { actionResolution: request });
|
|
10378
10314
|
}
|
|
10379
|
-
|
|
10380
|
-
return
|
|
10315
|
+
const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
|
|
10316
|
+
return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
|
|
10381
10317
|
}
|
|
10382
|
-
async function
|
|
10318
|
+
async function resolveCoreAction(request) {
|
|
10383
10319
|
try {
|
|
10384
|
-
const
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
} else {
|
|
10398
|
-
for (const c of report) {
|
|
10399
|
-
process.stdout.write(`
|
|
10400
|
-
${c.case}\uFF08${c.file}\uFF09
|
|
10401
|
-
`);
|
|
10402
|
-
for (const r of c.results) {
|
|
10403
|
-
const mark = r.verdict === "pass" ? "\u2705" : r.verdict === "step" ? "\xB7" : r.verdict === "warn" ? "\u26A0\uFE0F" : "\u274C";
|
|
10404
|
-
process.stdout.write(` ${mark} ${r.name}${r.detail ? ` ${r.detail}` : ""}
|
|
10405
|
-
`);
|
|
10406
|
-
}
|
|
10407
|
-
}
|
|
10408
|
-
const verified = report.reduce((n, c) => n + c.results.filter((r) => r.verdict === "pass").length, 0);
|
|
10409
|
-
process.stdout.write(failed2 === 0 ? `
|
|
10410
|
-
\u5168\u90E8\u901A\u8FC7\uFF08\u771F\u5224\u8FC7\u5185\u5BB9\u7684 ${verified} \u6761\uFF1B\u5E26 \xB7 \u7684\u662F\u6B65\u9AA4\uFF0C\u4E0D\u7B97\u9A8C\u8BC1\uFF09\u3002
|
|
10411
|
-
` : `
|
|
10412
|
-
${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4E86\u5B9E\u9645\u503C\u4E0E\u671F\u671B\uFF0C\u7167\u7740\u67E5\u3002
|
|
10413
|
-
`);
|
|
10320
|
+
const auth = await getActiveAuthContextFromCli({
|
|
10321
|
+
env: request.env,
|
|
10322
|
+
as: request.identity,
|
|
10323
|
+
profile: request.profile
|
|
10324
|
+
});
|
|
10325
|
+
const description = await HcmClient22.fromAuthContext(auth).describe(request.model);
|
|
10326
|
+
const named = description.actions.filter((action) => action.name === request.action);
|
|
10327
|
+
if (named.length === 0) {
|
|
10328
|
+
const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
|
|
10329
|
+
return failed(
|
|
10330
|
+
"action-metadata-not-found",
|
|
10331
|
+
`Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002${degraded}next_step=\u7528 \`hcm describe ${request.model}\` \u770B\u5B83\u5217\u51FA\u7684 Action \u540D\uFF08\u811A\u672C Action \u4F1A\u6807 [script]\uFF09`
|
|
10332
|
+
);
|
|
10414
10333
|
}
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10334
|
+
const matches2 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
|
|
10335
|
+
if (matches2.length === 0) {
|
|
10336
|
+
const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
|
|
10337
|
+
return failed(
|
|
10338
|
+
"action-shape-mismatch",
|
|
10339
|
+
`${request.model}.${request.action} \u5B58\u5728\uFF0C\u4F46\u5F62\u6001\u5BF9\u4E0D\u4E0A\uFF1A\u4F60\u7ED9\u7684\u662F scope=${request.scope} method=${request.httpMethod}\uFF0C\u5143\u6570\u636E\u91CC\u662F ${shapes}\u3002next_step=\u53BB\u6389 --scope/--method \u8BA9 CLI \u6309\u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF0C\u6216\u6539\u6210\u4E0A\u9762\u7684\u5F62\u6001`
|
|
10340
|
+
);
|
|
10341
|
+
}
|
|
10342
|
+
if (matches2.length > 1) {
|
|
10343
|
+
return failed(
|
|
10344
|
+
"action-metadata-ambiguous",
|
|
10345
|
+
`${request.model}.${request.action} \u5728\u5143\u6570\u636E\u91CC\u6709\u591A\u79CD\u5F62\u6001\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u3002next_step=\u7528 --scope \u4E0E --method \u6307\u660E\u8981\u8C03\u54EA\u4E00\u4E2A`
|
|
10346
|
+
);
|
|
10347
|
+
}
|
|
10348
|
+
return policyFromActionMeta(matches2[0], request);
|
|
10349
|
+
} catch {
|
|
10350
|
+
return failed(
|
|
10351
|
+
"action-metadata-unavailable",
|
|
10352
|
+
"\u65E0\u6CD5\u8BFB\u53D6 Core Action \u5143\u6570\u636E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
|
|
10353
|
+
);
|
|
10418
10354
|
}
|
|
10419
10355
|
}
|
|
10420
|
-
|
|
10421
|
-
|
|
10422
|
-
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
// src/jira/refs.ts
|
|
10434
|
-
import { execFileSync } from "child_process";
|
|
10435
|
-
import { CASES_REPO_SLUG, repoIssueUrl } from "@hcmai/sdk";
|
|
10436
|
-
var defaultCnb = (args) => execFileSync("cnb", args, { encoding: "utf8", maxBuffer: 1 << 26, stdio: ["ignore", "pipe", "pipe"] });
|
|
10437
|
-
var PRODUCT_REPOS = ["hcm/hcm_nx_core", "hcm/hcm_nx_cli", "hcm/hcm_nx_cloud"];
|
|
10438
|
-
var REF_RE = /hcm\/(hcm_nx_(?:core|cli|cloud))(?:#|\/-\/issues\/)(\d+)/g;
|
|
10439
|
-
function linkedRepoRefs(text) {
|
|
10440
|
-
const out = /* @__PURE__ */ new Map();
|
|
10441
|
-
for (const m of String(text ?? "").matchAll(REF_RE)) {
|
|
10442
|
-
out.set(`hcm/${m[1]}#${m[2]}`, { repo: `hcm/${m[1]}`, number: m[2] });
|
|
10443
|
-
}
|
|
10444
|
-
return [...out.values()];
|
|
10445
|
-
}
|
|
10446
|
-
function parseCnbIssueOutput(raw) {
|
|
10447
|
-
const fields = {};
|
|
10448
|
-
let status;
|
|
10449
|
-
for (const line of raw.split("\n")) {
|
|
10450
|
-
const head = line.match(/^status:\s*(\d+)\s*$/);
|
|
10451
|
-
if (head && status === void 0) {
|
|
10452
|
-
status = Number(head[1]);
|
|
10453
|
-
continue;
|
|
10356
|
+
function policyFromActionMeta(action, request) {
|
|
10357
|
+
const shape = {
|
|
10358
|
+
scope: action.scope ?? request.scope,
|
|
10359
|
+
httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
|
|
10360
|
+
...action.source ? { source: action.source } : {}
|
|
10361
|
+
};
|
|
10362
|
+
const effectClass = classifyEffect(action.effect);
|
|
10363
|
+
if (effectClass === "absent") {
|
|
10364
|
+
if (typeof action.readOnly !== "boolean") {
|
|
10365
|
+
return failed(
|
|
10366
|
+
"action-readonly-unclassified",
|
|
10367
|
+
"Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
|
|
10368
|
+
);
|
|
10454
10369
|
}
|
|
10455
|
-
|
|
10456
|
-
if (!m) continue;
|
|
10457
|
-
const key2 = m[1];
|
|
10458
|
-
if (fields[key2] !== void 0) continue;
|
|
10459
|
-
fields[key2] = m[2].trim().replace(/^"|"$/g, "");
|
|
10370
|
+
return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
|
|
10460
10371
|
}
|
|
10461
|
-
return {
|
|
10372
|
+
return {
|
|
10373
|
+
status: "resolved",
|
|
10374
|
+
policy: {
|
|
10375
|
+
...shape,
|
|
10376
|
+
effect: effectClass,
|
|
10377
|
+
...effectClass === "unrecognized-effect" ? { effectRaw: action.effect } : {},
|
|
10378
|
+
readOnly: effectClass === "read-only"
|
|
10379
|
+
}
|
|
10380
|
+
};
|
|
10462
10381
|
}
|
|
10463
|
-
function
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10382
|
+
function matchesRequest(action, request) {
|
|
10383
|
+
return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
|
|
10384
|
+
}
|
|
10385
|
+
function parseActionRequest(inputArgv) {
|
|
10386
|
+
const argv = normalizeAssessedArgv(inputArgv);
|
|
10387
|
+
const spec = argv[1] ?? "";
|
|
10388
|
+
const separator = spec.indexOf(".");
|
|
10389
|
+
if (separator <= 0 || separator === spec.length - 1) {
|
|
10390
|
+
return failed("invalid-action-spec", "Action \u5FC5\u987B\u4F7F\u7528 <Model>.<Action> \u683C\u5F0F\u3002");
|
|
10391
|
+
}
|
|
10392
|
+
const explicitMethod = flagValue2(argv, "--method");
|
|
10393
|
+
const httpMethod = (explicitMethod ?? "POST").toUpperCase();
|
|
10394
|
+
if (!["GET", "POST", "PUT", "DELETE"].includes(httpMethod)) {
|
|
10395
|
+
return failed("invalid-action-method", "Action method \u5FC5\u987B\u662F GET\u3001POST\u3001PUT \u6216 DELETE\u3002");
|
|
10469
10396
|
}
|
|
10470
|
-
const
|
|
10471
|
-
|
|
10472
|
-
if (
|
|
10473
|
-
return
|
|
10397
|
+
const explicitScope = flagValue2(argv, "--scope");
|
|
10398
|
+
const scope = explicitScope ?? (flagValue2(argv, "--id") ? "object" : "class");
|
|
10399
|
+
if (scope !== "class" && scope !== "object") {
|
|
10400
|
+
return failed("invalid-action-scope", "Action scope \u5FC5\u987B\u662F class \u6216 object\u3002");
|
|
10474
10401
|
}
|
|
10475
|
-
if (!fields.state) return { kind: "unreadable", repo, number, reason: "cnb \u8F93\u51FA\u91CC\u6CA1\u6709 state \u5B57\u6BB5" };
|
|
10476
10402
|
return {
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10403
|
+
model: spec.slice(0, separator),
|
|
10404
|
+
action: spec.slice(separator + 1),
|
|
10405
|
+
httpMethod,
|
|
10406
|
+
scope,
|
|
10407
|
+
...explicitMethod !== void 0 || explicitScope !== void 0 ? { explicitShape: true } : {},
|
|
10408
|
+
env: flagValue2(argv, "--env"),
|
|
10409
|
+
identity: flagValue2(argv, "--as"),
|
|
10410
|
+
profile: flagValue2(argv, "--profile")
|
|
10485
10411
|
};
|
|
10486
10412
|
}
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
};
|
|
10492
|
-
|
|
10413
|
+
function failed(reasonCode, reason) {
|
|
10414
|
+
return { status: "failed", reasonCode, reason };
|
|
10415
|
+
}
|
|
10416
|
+
function flagValue2(argv, flag) {
|
|
10417
|
+
const equals = argv.find((arg) => arg.startsWith(`${flag}=`));
|
|
10418
|
+
if (equals) return equals.slice(flag.length + 1);
|
|
10419
|
+
const index = argv.indexOf(flag);
|
|
10420
|
+
return index >= 0 ? argv[index + 1] : void 0;
|
|
10421
|
+
}
|
|
10422
|
+
|
|
10423
|
+
// src/commands/xlsx-peek.ts
|
|
10424
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
10425
|
+
import { inflateRawSync } from "zlib";
|
|
10426
|
+
function readZip(buf, want) {
|
|
10427
|
+
let eocd = -1;
|
|
10428
|
+
for (let i = buf.length - 22; i >= 0 && i > buf.length - 66e3; i--) {
|
|
10429
|
+
if (buf.readUInt32LE(i) === 101010256) {
|
|
10430
|
+
eocd = i;
|
|
10431
|
+
break;
|
|
10432
|
+
}
|
|
10433
|
+
}
|
|
10434
|
+
if (eocd < 0) throw new Error("\u4E0D\u662F\u6709\u6548\u7684 zip/xlsx\uFF08\u627E\u4E0D\u5230\u4E2D\u592E\u76EE\u5F55\uFF09");
|
|
10435
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
10436
|
+
let p = buf.readUInt32LE(eocd + 16);
|
|
10493
10437
|
const out = [];
|
|
10494
|
-
let
|
|
10495
|
-
|
|
10496
|
-
const
|
|
10497
|
-
|
|
10498
|
-
const
|
|
10499
|
-
const
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10438
|
+
for (let n = 0; n < count; n++) {
|
|
10439
|
+
if (buf.readUInt32LE(p) !== 33639248) break;
|
|
10440
|
+
const method = buf.readUInt16LE(p + 10);
|
|
10441
|
+
const compressedSize = buf.readUInt32LE(p + 20);
|
|
10442
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
10443
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
10444
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
10445
|
+
const localOffset = buf.readUInt32LE(p + 42);
|
|
10446
|
+
const name = buf.subarray(p + 46, p + 46 + nameLen).toString("utf8");
|
|
10447
|
+
if (want(name)) {
|
|
10448
|
+
const lnameLen = buf.readUInt16LE(localOffset + 26);
|
|
10449
|
+
const lextraLen = buf.readUInt16LE(localOffset + 28);
|
|
10450
|
+
const start = localOffset + 30 + lnameLen + lextraLen;
|
|
10451
|
+
const raw = buf.subarray(start, start + compressedSize);
|
|
10452
|
+
if (method === 0) out.push({ name, data: Buffer.from(raw) });
|
|
10453
|
+
else if (method === 8) out.push({ name, data: inflateRawSync(raw) });
|
|
10454
|
+
else throw new Error(`xlsx \u91CC\u7684 ${name} \u7528\u4E86\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F ${method}`);
|
|
10504
10455
|
}
|
|
10505
|
-
|
|
10456
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
10506
10457
|
}
|
|
10507
|
-
if (cur?.number) out.push(finishRow(cur, repo));
|
|
10508
10458
|
return out;
|
|
10509
10459
|
}
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
}
|
|
10521
|
-
function searchRepoIssues(cnb, repo, keyword, state) {
|
|
10522
|
-
try {
|
|
10523
|
-
return parseCnbIssueList(
|
|
10524
|
-
cnb(["issues", "list-issues", "--repo", repo, "--keyword", keyword, "--state", state, "--page-size", "20"]),
|
|
10525
|
-
repo
|
|
10526
|
-
);
|
|
10527
|
-
} catch {
|
|
10528
|
-
return [];
|
|
10460
|
+
var decode = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
10461
|
+
function xlsxRows(file, maxRows = 50) {
|
|
10462
|
+
const buf = readFileSync6(file);
|
|
10463
|
+
const [sheet] = readZip(buf, (n) => n === "xl/worksheets/sheet1.xml");
|
|
10464
|
+
if (!sheet) throw new Error(`${file} \u91CC\u6CA1\u6709 xl/worksheets/sheet1.xml\uFF0C\u53EF\u80FD\u4E0D\u662F xlsx`);
|
|
10465
|
+
const [shared] = readZip(buf, (n) => n === "xl/sharedStrings.xml");
|
|
10466
|
+
const sharedStrings = [];
|
|
10467
|
+
if (shared) {
|
|
10468
|
+
for (const si of shared.data.toString("utf8").split("<si>").slice(1)) {
|
|
10469
|
+
sharedStrings.push(decode([...si.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((m) => m[1] ?? "").join("")));
|
|
10470
|
+
}
|
|
10529
10471
|
}
|
|
10472
|
+
const xml = sheet.data.toString("utf8");
|
|
10473
|
+
const rows = [];
|
|
10474
|
+
for (const rowXml of xml.split("<row").slice(1)) {
|
|
10475
|
+
if (rows.length >= maxRows) break;
|
|
10476
|
+
const cells = [];
|
|
10477
|
+
for (const m of rowXml.matchAll(/<c\b([^>]*)>([\s\S]*?)<\/c>/g)) {
|
|
10478
|
+
const attrs = m[1] ?? "";
|
|
10479
|
+
const body = m[2] ?? "";
|
|
10480
|
+
const v = /<v>([\s\S]*?)<\/v>/.exec(body)?.[1] ?? "";
|
|
10481
|
+
const inline = [...body.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((x) => x[1] ?? "").join("");
|
|
10482
|
+
if (/t="s"/.test(attrs)) cells.push(sharedStrings[Number(v)] ?? "");
|
|
10483
|
+
else if (inline) cells.push(decode(inline));
|
|
10484
|
+
else cells.push(decode(v));
|
|
10485
|
+
}
|
|
10486
|
+
rows.push(cells);
|
|
10487
|
+
}
|
|
10488
|
+
return rows;
|
|
10530
10489
|
}
|
|
10531
|
-
function parseRef(raw, project, casesSlug = CASES_REPO_SLUG) {
|
|
10532
|
-
const r = String(raw ?? "").trim();
|
|
10533
|
-
let m = r.match(/^(?:hcm\/)?(?:hcm_nx_)?(core|cli|cloud)#(\d+)$/i);
|
|
10534
|
-
if (m) return { kind: "repo", repo: `hcm/hcm_nx_${m[1].toLowerCase()}`, number: m[2] };
|
|
10535
|
-
m = r.match(/^(?:chiron-)?cases#(\d+)$/i);
|
|
10536
|
-
if (m) return { kind: "repo", repo: casesSlug, number: m[1] };
|
|
10537
|
-
m = r.match(/^([A-Z][A-Z0-9_]+)-(\d+)$/i);
|
|
10538
|
-
if (m) return { kind: "jira", key: `${m[1].toUpperCase()}-${m[2]}` };
|
|
10539
|
-
m = r.match(/^(\d+)$/);
|
|
10540
|
-
if (m) return { kind: "jira", key: `${project}-${m[1]}` };
|
|
10541
|
-
return null;
|
|
10542
|
-
}
|
|
10543
|
-
var firstLine2 = (s) => String(s ?? "").split("\n").find((l) => l.trim())?.trim() ?? "";
|
|
10544
10490
|
|
|
10545
|
-
// src/
|
|
10546
|
-
|
|
10547
|
-
var
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
["expected", 10],
|
|
10552
|
-
["alternative", 5],
|
|
10553
|
-
["q_mechanism", 10],
|
|
10554
|
-
["q_history", 10],
|
|
10555
|
-
["q_skill", 10]
|
|
10556
|
-
];
|
|
10557
|
-
function validateGapInput(x) {
|
|
10558
|
-
if (!x || typeof x !== "object") throw new Error("\u7F3A\u53E3\u8F7D\u8377\u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61");
|
|
10559
|
-
const g = x;
|
|
10560
|
-
const problems = [];
|
|
10561
|
-
for (const [k, min] of MIN_LEN) {
|
|
10562
|
-
const v = g[k];
|
|
10563
|
-
if (typeof v !== "string" || v.trim().length < min) problems.push(`${k} \u81F3\u5C11 ${min} \u4E2A\u5B57`);
|
|
10491
|
+
// src/commands/chiron-test.ts
|
|
10492
|
+
var CONTENT_KEYS = ["stdout_contains", "json", "xlsx_header", "xlsx_min_rows", "text_contains"];
|
|
10493
|
+
var hasContentAssertion = (c) => (c.page ? (c.expect_text?.length ?? 0) > 0 : false) || CONTENT_KEYS.some((k) => c.expect?.[k] !== void 0);
|
|
10494
|
+
function assertUsableSpec(spec, where) {
|
|
10495
|
+
if (!spec?.name || !Array.isArray(spec.checks) || spec.checks.length === 0) {
|
|
10496
|
+
throw new Error(`${where}: \u7528\u4F8B\u8981\u6709 name \u4E0E\u81F3\u5C11\u4E00\u6761 checks`);
|
|
10564
10497
|
}
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
}
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
"{code}",
|
|
10584
|
-
"",
|
|
10585
|
-
"h2. \u671F\u671B",
|
|
10586
|
-
g.expected,
|
|
10587
|
-
"",
|
|
10588
|
-
"h2. \u73AF\u5883\u6307\u7EB9",
|
|
10589
|
-
fingerprintText2,
|
|
10590
|
-
"",
|
|
10591
|
-
"h2. \u66FF\u4EE3\u6CD5",
|
|
10592
|
-
g.alternative,
|
|
10593
|
-
"",
|
|
10594
|
-
"h2. \u4E25\u91CD\u5EA6",
|
|
10595
|
-
`${g.severity}\uFF08\u987E\u95EE\u4FA7\u5224\u5B9A\uFF1A\u963B\u65AD=\u4EA4\u4ED8\u505C\u4E0B / \u6709\u66FF\u4EE3\u6CD5=\u80FD\u7ED5 / \u63AA\u8F9E\u7EA7=\u8F93\u51FA\u5DF2\u7ED9\u8DEF\u6807\uFF09`,
|
|
10596
|
-
"",
|
|
10597
|
-
"h2. \u4E09\u95EE\u81EA\u7B54",
|
|
10598
|
-
`# \u673A\u5236\u8FB9\u754C\uFF1A${g.q_mechanism}`,
|
|
10599
|
-
`# \u5386\u53F2\uFF1A${g.q_history}`,
|
|
10600
|
-
`# \u6280\u80FD\u6709\u6CA1\u6709\u6559\u9519\uFF1A${g.q_skill}`,
|
|
10601
|
-
"",
|
|
10602
|
-
"h2. \u5173\u952E\u8BCD",
|
|
10603
|
-
[g.error_code, g.model, g.action].filter(Boolean).join(" \xB7 ") || "\uFF08\u65E0\uFF09",
|
|
10604
|
-
"",
|
|
10605
|
-
"_\u7531\u987E\u95EE agent \u7ECF `hcm jira submit` \u63D0\u4EA4\u3002\u5206\u8BCA\u4E09\u53BB\u5411\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u56DE\u94FE / \u6539\u6280\u80FD\u5E76\u56DE\u590D / \u5408\u5E76\u8BA1\u6570\u3002\u5904\u7406\u529E\u6CD5\u89C1\u4EA7\u54C1\u4ED3\u6280\u80FD jira-triage\u3002_"
|
|
10606
|
-
].join("\n");
|
|
10607
|
-
}
|
|
10608
|
-
function findDuplicateGap(open, summary, keyTag) {
|
|
10609
|
-
const bigrams = (t) => {
|
|
10610
|
-
const x = (t || "").replace(/〔.*?〕/g, "").replace(/[\s,。::、()()「」]/g, "");
|
|
10611
|
-
const out = /* @__PURE__ */ new Set();
|
|
10612
|
-
for (let i = 0; i + 1 < x.length; i++) out.add(x.slice(i, i + 2));
|
|
10613
|
-
return out;
|
|
10614
|
-
};
|
|
10615
|
-
const sim = (a, b) => {
|
|
10616
|
-
const A = bigrams(a);
|
|
10617
|
-
const B = bigrams(b);
|
|
10618
|
-
if (!A.size || !B.size) return 0;
|
|
10619
|
-
let n = 0;
|
|
10620
|
-
for (const s of A) if (B.has(s)) n++;
|
|
10621
|
-
return n / Math.min(A.size, B.size);
|
|
10622
|
-
};
|
|
10623
|
-
for (const i of open) {
|
|
10624
|
-
const t = i.fields.summary ?? "";
|
|
10625
|
-
if (keyTag !== "\u3014-\u3015" && t.includes(keyTag)) return i;
|
|
10626
|
-
if (sim(t, summary) >= 0.6) return i;
|
|
10498
|
+
spec.checks.forEach((c, i) => {
|
|
10499
|
+
const at = `${where} \u7B2C ${i + 1} \u6761\u300C${c.name ?? "\u672A\u547D\u540D"}\u300D`;
|
|
10500
|
+
if (!c.name) throw new Error(`${at}: \u7F3A name`);
|
|
10501
|
+
const kinds = [c.run, c.file, c.page].filter(Boolean).length;
|
|
10502
|
+
if (kinds !== 1) throw new Error(`${at}: run / file / page \u5FC5\u987B\u4E14\u53EA\u80FD\u6709\u4E00\u4E2A`);
|
|
10503
|
+
if (c.run) {
|
|
10504
|
+
if (!/^hcm\s/.test(c.run.trim())) {
|
|
10505
|
+
throw new Error(`${at}: run \u53EA\u80FD\u8DD1 hcm \u5B50\u547D\u4EE4\uFF08\u4E0D\u63A5\u53D7\u4EFB\u610F shell\uFF1B\u8981\u7ED5\u8FC7 CLI \u7684\u4E8B\u672C\u6765\u5C31\u4E0D\u8BE5\u505A\uFF09`);
|
|
10506
|
+
}
|
|
10507
|
+
tokenize(c.run);
|
|
10508
|
+
}
|
|
10509
|
+
if (c.page && !c.expect_text?.length) throw new Error(`${at}: \u9875\u9762\u5224\u636E\u81F3\u5C11\u8981\u4E00\u4E2A expect_text\u2014\u2014\u622A\u56FE\u5B58\u5728\u4E0D\u7B49\u4E8E\u9875\u9762\u5BF9`);
|
|
10510
|
+
if (c.file && !hasContentAssertion(c)) throw new Error(`${at}: \u8BFB\u6587\u4EF6\u5374\u6CA1\u6709\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")}\uFF09\u2014\u2014\u6587\u4EF6\u5B58\u5728\u4E0D\u7B49\u4E8E\u5185\u5BB9\u5BF9`);
|
|
10511
|
+
});
|
|
10512
|
+
if (!spec.checks.some(hasContentAssertion)) {
|
|
10513
|
+
throw new Error(
|
|
10514
|
+
`${where}: \u6574\u4EFD\u7528\u4F8B\u6CA1\u6709\u4EFB\u4F55\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")} / expect_text\uFF09\uFF0C\u53EA\u8DD1\u4E0D\u770B\u7B49\u4E8E\u6CA1\u6D4B\u3002`
|
|
10515
|
+
);
|
|
10627
10516
|
}
|
|
10628
|
-
return null;
|
|
10629
10517
|
}
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
throw new Error(`\u9879\u76EE ${ctx.project} \u91CC\u6CA1\u6709\u300C${wanted.join(" / ")}\u300D\u8FD9\u7C7B issuetype\uFF0C\u5B9E\u9645\u6709\uFF1A${ctx.types.map((t) => t.name).join(" / ")}`);
|
|
10643
|
-
}
|
|
10644
|
-
const module = g.module ?? "HCM-Core";
|
|
10645
|
-
const keyTag = gapKeyTag(g);
|
|
10646
|
-
const byName = {
|
|
10647
|
-
\u6982\u8981: gapSummary(g),
|
|
10648
|
-
\u63CF\u8FF0: renderGapDescription(g, ctx.fingerprintText),
|
|
10649
|
-
\u95EE\u9898\u7C7B\u522B: KIND_TO_CATEGORY[g.kind],
|
|
10650
|
-
\u95EE\u9898\u6A21\u5757: module,
|
|
10651
|
-
\u4F18\u5148\u7EA7: SEVERITY_TO_PRIORITY[g.severity],
|
|
10652
|
-
\u62A5\u544A\u4EBA: ctx.me,
|
|
10653
|
-
\u7ECF\u529E\u4EBA: ctx.assignee,
|
|
10654
|
-
Bug\u53D1\u73B0\u4EBA: "\u987E\u95EE",
|
|
10655
|
-
Bug\u91CD\u73B0\u64CD\u4F5C\u6B65\u9AA4: g.repro,
|
|
10656
|
-
Bug\u9519\u8BEF\u53F7: g.error_code || "\u65E0\u9519\u8BEF\u7801\uFF08\u73B0\u8C61\u89C1\u63CF\u8FF0\uFF09"
|
|
10657
|
-
};
|
|
10658
|
-
const fields = { project: { key: ctx.project }, issuetype: { id: type.id } };
|
|
10659
|
-
const unfilled = [];
|
|
10660
|
-
const values = (f) => (f.allowedValues ?? []).map((v) => v.value ?? v.name).join("|");
|
|
10661
|
-
for (const f of type.fields ?? []) {
|
|
10662
|
-
if (["project", "issuetype"].includes(f.fieldId)) continue;
|
|
10663
|
-
const want = byName[f.name];
|
|
10664
|
-
if (want === void 0) {
|
|
10665
|
-
if (f.required) unfilled.push(`${f.name}(${f.fieldId})${f.allowedValues ? `=[${values(f)}]` : ""}`);
|
|
10518
|
+
function tokenize(line) {
|
|
10519
|
+
const out = [];
|
|
10520
|
+
let cur = "";
|
|
10521
|
+
let quote = null;
|
|
10522
|
+
let started = false;
|
|
10523
|
+
for (let i = 0; i < line.length; i++) {
|
|
10524
|
+
const ch = line[i];
|
|
10525
|
+
if (quote) {
|
|
10526
|
+
if (ch === quote) quote = null;
|
|
10527
|
+
else if (ch === "\\" && quote === '"' && i + 1 < line.length) {
|
|
10528
|
+
cur += line[++i];
|
|
10529
|
+
} else cur += ch;
|
|
10666
10530
|
continue;
|
|
10667
10531
|
}
|
|
10668
|
-
if (
|
|
10669
|
-
|
|
10670
|
-
|
|
10671
|
-
if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${String(want)}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
|
|
10672
|
-
continue;
|
|
10673
|
-
}
|
|
10674
|
-
const childName = g.module_detail || MODULE_DEFAULT_CHILD[module];
|
|
10675
|
-
const child = (parent.children ?? []).find((c) => (c.value ?? c.name) === childName);
|
|
10676
|
-
if (!child && (parent.children ?? []).length) {
|
|
10677
|
-
unfilled.push(`${f.name}(${f.fieldId}) \u7684\u4E8C\u7EA7\u9879\u300C${childName}\u300D\u4E0D\u5728 [${(parent.children ?? []).map((c) => c.value ?? c.name).join("|")}] \u91CC`);
|
|
10678
|
-
continue;
|
|
10679
|
-
}
|
|
10680
|
-
fields[f.fieldId] = { id: parent.id, ...child ? { child: { id: child.id } } : {} };
|
|
10532
|
+
if (ch === '"' || ch === "'") {
|
|
10533
|
+
quote = ch;
|
|
10534
|
+
started = true;
|
|
10681
10535
|
continue;
|
|
10682
10536
|
}
|
|
10683
|
-
if (
|
|
10684
|
-
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u53D6\u4E0D\u5230\u7528\u6237\u540D`);
|
|
10694
|
-
continue;
|
|
10537
|
+
if (ch === "\\" && i + 1 < line.length) {
|
|
10538
|
+
cur += line[++i];
|
|
10539
|
+
started = true;
|
|
10540
|
+
continue;
|
|
10541
|
+
}
|
|
10542
|
+
if (/\s/.test(ch)) {
|
|
10543
|
+
if (started || cur) {
|
|
10544
|
+
out.push(cur);
|
|
10545
|
+
cur = "";
|
|
10546
|
+
started = false;
|
|
10695
10547
|
}
|
|
10696
|
-
|
|
10697
|
-
} else {
|
|
10698
|
-
fields[f.fieldId] = Array.isArray(want) ? want[0] : want;
|
|
10548
|
+
continue;
|
|
10699
10549
|
}
|
|
10550
|
+
cur += ch;
|
|
10551
|
+
started = true;
|
|
10700
10552
|
}
|
|
10701
|
-
if (
|
|
10702
|
-
|
|
10703
|
-
|
|
10553
|
+
if (quote) throw new Error(`\u547D\u4EE4\u91CC\u7684\u5F15\u53F7\u6CA1\u95ED\u5408\uFF1A${line}`);
|
|
10554
|
+
if (started || cur) out.push(cur);
|
|
10555
|
+
return out;
|
|
10556
|
+
}
|
|
10557
|
+
function parseJsonLoose(stdout) {
|
|
10558
|
+
const candidates = [];
|
|
10559
|
+
const oa = stdout.indexOf("{"), ob = stdout.lastIndexOf("}");
|
|
10560
|
+
const aa = stdout.indexOf("["), ab = stdout.lastIndexOf("]");
|
|
10561
|
+
if (aa >= 0 && ab > aa) candidates.push([aa, ab]);
|
|
10562
|
+
if (oa >= 0 && ob > oa) candidates.push([oa, ob]);
|
|
10563
|
+
candidates.sort((x, y) => x[0] - y[0]);
|
|
10564
|
+
for (const [a, b] of candidates) {
|
|
10565
|
+
try {
|
|
10566
|
+
return JSON.parse(stdout.slice(a, b + 1));
|
|
10567
|
+
} catch {
|
|
10568
|
+
}
|
|
10704
10569
|
}
|
|
10705
|
-
|
|
10706
|
-
|
|
10707
|
-
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
|
|
10570
|
+
return void 0;
|
|
10571
|
+
}
|
|
10572
|
+
function pick(value, expr) {
|
|
10573
|
+
const tokens = [...expr.replace(/^\$/, "").matchAll(/\[(\d+)\]|([^.[\]]+)/g)];
|
|
10574
|
+
let cur = value;
|
|
10575
|
+
for (const t of tokens) {
|
|
10576
|
+
if (cur === null || cur === void 0) return void 0;
|
|
10577
|
+
if (t[1] !== void 0) {
|
|
10578
|
+
if (!Array.isArray(cur)) return void 0;
|
|
10579
|
+
cur = cur[Number(t[1])];
|
|
10580
|
+
} else {
|
|
10581
|
+
if (typeof cur !== "object") return void 0;
|
|
10582
|
+
cur = cur[t[2]];
|
|
10583
|
+
}
|
|
10711
10584
|
}
|
|
10712
|
-
return
|
|
10585
|
+
return cur;
|
|
10713
10586
|
}
|
|
10714
|
-
|
|
10715
|
-
const
|
|
10716
|
-
|
|
10717
|
-
const
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10587
|
+
function matches(actual, rule) {
|
|
10588
|
+
const r = rule.trim();
|
|
10589
|
+
if (r === "\u975E\u7A7A" || r === "nonempty") return actual !== void 0 && actual !== null && String(actual) !== "" && !(Array.isArray(actual) && actual.length === 0);
|
|
10590
|
+
const m = /^(>=|<=|>|<|!=|=)\s*(.*)$/.exec(r);
|
|
10591
|
+
if (!m) return String(actual) === r;
|
|
10592
|
+
const [, op, want] = m;
|
|
10593
|
+
const n = Number(want), a = Array.isArray(actual) ? actual.length : Number(actual);
|
|
10594
|
+
switch (op) {
|
|
10595
|
+
case ">":
|
|
10596
|
+
return Number.isFinite(a) && a > n;
|
|
10597
|
+
case "<":
|
|
10598
|
+
return Number.isFinite(a) && a < n;
|
|
10599
|
+
case ">=":
|
|
10600
|
+
return Number.isFinite(a) && a >= n;
|
|
10601
|
+
case "<=":
|
|
10602
|
+
return Number.isFinite(a) && a <= n;
|
|
10603
|
+
case "!=":
|
|
10604
|
+
return String(actual) !== want;
|
|
10605
|
+
default:
|
|
10606
|
+
return String(actual) === want;
|
|
10733
10607
|
}
|
|
10734
|
-
const [types, me, project] = await Promise.all([client3.createMeta(), client3.myself(), client3.projectInfo()]);
|
|
10735
|
-
const built = buildGapFields(g, {
|
|
10736
|
-
types,
|
|
10737
|
-
me: me.name ?? me.key ?? "",
|
|
10738
|
-
assignee: assigneeOverride || project.lead?.name || project.lead?.key,
|
|
10739
|
-
project: client3.project,
|
|
10740
|
-
fingerprintText: fingerprintText2,
|
|
10741
|
-
issuetypeOverride
|
|
10742
|
-
});
|
|
10743
|
-
const created = await client3.createIssue(built.fields);
|
|
10744
|
-
return { outcome: "created", key: created.key, url: client3.browseUrl(created.key), summary: built.summary, type: built.type.name, module: built.module, alternative: g.alternative };
|
|
10745
10608
|
}
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10609
|
+
var defaultDeps3 = {
|
|
10610
|
+
assess: (argv) => assessEffectiveDeliveryCommand(argv),
|
|
10611
|
+
hcm: (argv, cwd) => {
|
|
10612
|
+
const r = spawnSync2("hcm", argv, { cwd, encoding: "utf8", maxBuffer: 1 << 26, timeout: 6e5 });
|
|
10613
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
10614
|
+
},
|
|
10615
|
+
pageAcceptance: (root, argv) => {
|
|
10616
|
+
const r = spawnSync2("./page-acceptance.sh", argv, { cwd: root, encoding: "utf8", maxBuffer: 1 << 24, timeout: 3e5 });
|
|
10617
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
10618
|
+
},
|
|
10619
|
+
readXlsx: (file) => xlsxRows(file),
|
|
10620
|
+
readText: (file) => fs11.readFile(file, "utf8")
|
|
10621
|
+
};
|
|
10622
|
+
async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
|
|
10623
|
+
const results = [];
|
|
10624
|
+
const vars = {};
|
|
10625
|
+
const fill = (text) => text.replace(/\$\{(\w+)\}/g, (_, k) => {
|
|
10626
|
+
if (vars[k] === void 0) throw new Error(`\u7528\u5230\u4E86 ${"$"}{${k}} \u4F46\u524D\u9762\u6CA1\u6709\u54EA\u4E00\u6B65\u6355\u83B7\u5B83`);
|
|
10627
|
+
return vars[k];
|
|
10628
|
+
});
|
|
10629
|
+
for (const c of spec.checks) {
|
|
10630
|
+
try {
|
|
10631
|
+
if (c.run) {
|
|
10632
|
+
const argv2 = tokenize(fill(c.run)).slice(1);
|
|
10633
|
+
const verdict = await deps.assess(argv2);
|
|
10634
|
+
if (verdict.execution !== "direct") {
|
|
10635
|
+
results.push({
|
|
10636
|
+
name: c.name,
|
|
10637
|
+
verdict: "fail",
|
|
10638
|
+
// 🔴 `verdict.reason` 里已经带着分档理由与 `next_step=`(见 delivery.ts 的
|
|
10639
|
+
// action-effect-undetermined / action-effect-unrecognized 两支)。此前这里
|
|
10640
|
+
// 把它整个丢掉、自己编了一句「走 delivery assess → prepare → execute」,
|
|
10641
|
+
// 而那三条命令已于 0.7.0 删除 —— 顾问撞到写命令,拿到的是一条不存在的路。
|
|
10642
|
+
// 手上有的就要打出来,不要自己编第二句。
|
|
10643
|
+
detail: `\u8FD9\u6761\u547D\u4EE4\u6309\u4EA4\u4ED8\u98CE\u63A7\u662F ${verdict.risk} / ${verdict.execution}\uFF08${verdict.reasonCode}\uFF09\uFF0C\u6CA1\u6709\u8DD1\u3002${verdict.reason} \u7528\u4F8B\u53EA\u8DD1\u53EA\u8BFB\uFF1A\u8981\u65AD\u8A00\u5199\u64CD\u4F5C\u7684\u7ED3\u679C\uFF0C\u5148\u5728\u73AF\u5883\u91CC\u628A\u5B83\u505A\u6389\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u843D\u5E93\u7684\u6837\u5B50\u3002`
|
|
10644
|
+
});
|
|
10645
|
+
continue;
|
|
10646
|
+
}
|
|
10647
|
+
if (opts.env && !argv2.includes("--env")) argv2.push("--env", opts.env);
|
|
10648
|
+
const as2 = c.as ?? opts.as;
|
|
10649
|
+
if (as2 && !argv2.includes("--as")) argv2.push("--as", as2);
|
|
10650
|
+
const r2 = deps.hcm(argv2, root);
|
|
10651
|
+
const want = c.expect ?? {};
|
|
10652
|
+
const bad = [];
|
|
10653
|
+
if (want.exit !== void 0 && r2.status !== want.exit) bad.push(`\u9000\u51FA\u7801 ${r2.status} \u2260 ${want.exit}`);
|
|
10654
|
+
for (const t of want.stdout_contains ?? []) if (!r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
10655
|
+
for (const t of want.stdout_not_contains ?? []) if (r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
|
|
10656
|
+
if (want.json) {
|
|
10657
|
+
const parsed = parseJsonLoose(r2.stdout);
|
|
10658
|
+
if (parsed === void 0) bad.push("\u8F93\u51FA\u4E0D\u662F JSON\uFF0C\u65E0\u6CD5\u6309 json \u5224\u636E\u6BD4\u5BF9");
|
|
10659
|
+
if (parsed !== void 0) {
|
|
10660
|
+
for (const [expr, rule] of Object.entries(want.json)) {
|
|
10661
|
+
const actual = pick(parsed, expr);
|
|
10662
|
+
if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
|
|
10663
|
+
}
|
|
10664
|
+
}
|
|
10762
10665
|
}
|
|
10666
|
+
if (c.capture && bad.length === 0) {
|
|
10667
|
+
const parsed = parseJsonLoose(r2.stdout);
|
|
10668
|
+
for (const [name, expr] of Object.entries(c.capture)) {
|
|
10669
|
+
const v = pick(parsed, expr);
|
|
10670
|
+
if (v === void 0 || v === null || String(v) === "") bad.push(`\u8981\u6355\u83B7\u7684 ${name}\uFF08${expr}\uFF09\u5728\u8F93\u51FA\u91CC\u53D6\u4E0D\u5230`);
|
|
10671
|
+
else vars[name] = String(v);
|
|
10672
|
+
}
|
|
10673
|
+
}
|
|
10674
|
+
results.push(bad.length ? { name: c.name, verdict: "fail", detail: `${bad.join("\uFF1B")}${r2.stderr.trim() ? `\uFF5Cstderr: ${r2.stderr.trim().split("\n")[0]}` : ""}` } : { name: c.name, verdict: hasContentAssertion(c) ? "pass" : "step", detail: c.capture ? `\u6355\u83B7 ${Object.keys(c.capture).join("\u3001")}` : "" });
|
|
10675
|
+
continue;
|
|
10763
10676
|
}
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
}
|
|
10778
|
-
|
|
10779
|
-
const parsed = parseRef(ref, client3.project, casesSlug);
|
|
10780
|
-
if (!parsed) throw new Error(`\u770B\u4E0D\u61C2 ${ref}\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12\uFF09\u3001\u4EA7\u54C1\u4ED3\u5F15\u7528\uFF08core#2198\uFF09\u6216\u5386\u53F2\u961F\u5217\u6761\u76EE\uFF08cases#26\uFF09`);
|
|
10781
|
-
if (parsed.kind === "repo") {
|
|
10782
|
-
const s = cnbIssueState(cnb, parsed.repo, parsed.number);
|
|
10783
|
-
if (s.kind !== "issue") throw new Error(`${parsed.repo}#${parsed.number} \u8BFB\u4E0D\u5230\uFF08\u7F16\u53F7\u4E0D\u5BF9\u3001\u662F PR \u53F7\uFF0C\u6216\u4F60\u6CA1\u6709\u8FD9\u4E2A\u4ED3\u7684\u6743\u9650\uFF09`);
|
|
10784
|
-
const where = parsed.repo === casesSlug ? "\u5386\u53F2\u961F\u5217" : "\u4EA7\u54C1\u4ED3";
|
|
10785
|
-
const nextStep2 = s.state === "closed" ? "\u8FD9\u6761\u5DF2\u5173\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002" : "\u8FD8\u5F00\u7740\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF1B\u8981\u6392\u671F\u5C31\u5728\u90A3\u6761\u4E0B\u9762\u7559\u8A00\u3002";
|
|
10786
|
-
return { ref, lines: [`${where} ${s.repo}#${s.number} [${s.state}${s.reason ? "\xB7" + s.reason : ""}${s.priority ? " " + s.priority : ""}] ${s.title}`, ` ${s.url}`], nextStep: nextStep2, repo: s, links: [] };
|
|
10787
|
-
}
|
|
10788
|
-
const issue = await client3.issue(parsed.key);
|
|
10789
|
-
const cs = await client3.comments(parsed.key);
|
|
10790
|
-
const status = issue.fields.status?.name;
|
|
10791
|
-
const resolution = issue.fields.resolution?.name;
|
|
10792
|
-
const lines = [`Jira ${issue.key} [${status}${resolution ? "\xB7" + resolution : ""}${issue.fields.priority ? " " + issue.fields.priority.name : ""}] ${issue.fields.summary ?? ""}`, ` ${client3.browseUrl(issue.key)}`];
|
|
10793
|
-
const keyComments = cs.filter((c) => /分诊|已转|已修|合入|不做|重复|改技能|产品侧|代码库已关闭/.test(c.body ?? ""));
|
|
10794
|
-
const last = (keyComments.length ? keyComments : cs).at(-1);
|
|
10795
|
-
if (last) lines.push(` \u6700\u65B0\u5904\u7406\uFF08${String(last.created ?? "").slice(0, 10)} ${last.author?.displayName ?? "?"}\uFF09\uFF1A${(last.body ?? "").split("\n").find((l) => l.trim()) ?? ""}`.slice(0, 400));
|
|
10796
|
-
else lines.push(" \u8FD8\u6CA1\u6709\u4EBA\u5904\u7406\uFF08\u4EA7\u54C1\u4FA7\u6BCF\u5468\u6E05\u4E00\u6B21\uFF1B\u963B\u65AD\u7EA7\u8BF7\u5728\u9879\u76EE\u7FA4\u91CC\u70B9\u540D\u8D1F\u8D23\u4EBA\uFF09");
|
|
10797
|
-
const remote = (await client3.remoteLinks(parsed.key)).map((l) => l.object?.url ?? "").join("\n");
|
|
10798
|
-
const links = linkedRepoRefs(`${remote}
|
|
10799
|
-
${issue.fields.description ?? ""}
|
|
10800
|
-
${cs.map((c) => c.body ?? "").join("\n")}`).map((l) => cnbIssueState(cnb, l.repo, l.number));
|
|
10801
|
-
const issues = links.filter((l) => l.kind === "issue");
|
|
10802
|
-
for (const p of issues) lines.push(`\u4EA7\u54C1\u4ED3 ${p.repo}#${p.number} [${p.state}${p.reason ? "\xB7" + p.reason : ""}${p.priority ? " " + p.priority : ""}] ${p.title}`, ` ${p.url}`);
|
|
10803
|
-
let nextStep;
|
|
10804
|
-
if (resolution) nextStep = "Jira \u8FD9\u5355\u5DF2\u89E3\u51B3\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF08`hcm version` \u7684 commit \u4F1A\u53D8\uFF09\uFF0C\u8DD1 `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002";
|
|
10805
|
-
else if (issues.length && issues.every((s) => s.state === "closed")) nextStep = "\u4EA7\u54C1\u4ED3\u90A3\u6761\u5DF2\u5173\u3001Jira \u8FD8\u6CA1\u5173\uFF0C\u591A\u534A\u5728\u7B49\u53D1\u5E03\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF0C\u53D1\u5E03\u540E\u590D\u9A8C\u3002";
|
|
10806
|
-
else if (issues.length) nextStep = "\u4EA7\u54C1\u4ED3\u5DF2\u7ACB\u9879\u3001\u8FD8\u6CA1\u5173\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF1B\u60F3\u8981\u6392\u671F\u5C31\u5728 Jira \u8FD9\u5355\u4E0B\u7559\u8A00\u3002";
|
|
10807
|
-
else nextStep = `\u7B49\u5206\u8BCA\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF0C\u62A5\u544A\u5199 BLOCKED \xB7 \u5DF2\u63D0 ${issue.key}\u3002`;
|
|
10808
|
-
return { ref, lines, nextStep, jira: { key: issue.key, status, resolution, url: client3.browseUrl(issue.key) }, links };
|
|
10809
|
-
}
|
|
10810
|
-
|
|
10811
|
-
// src/jira/triage.ts
|
|
10812
|
-
var GAP_PREFIX = "\u7F3A\u53E3\uFF1A";
|
|
10813
|
-
var PENDING_STATUS = "\u65B0\u589E";
|
|
10814
|
-
var SYNC_MARKER = "\u4EE3\u7801\u5E93\u5DF2\u5173\u95ED\uFF1A";
|
|
10815
|
-
var bodyText = (issue, comments, remote = []) => [issue.fields.description ?? "", ...comments.map((c) => c.body ?? ""), ...remote.map((l) => l.object?.url ?? "")].join("\n");
|
|
10816
|
-
var remoteText = (remote) => remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
|
|
10817
|
-
var refKeys = (text) => linkedRepoRefs(text).map((l) => `${l.repo}#${l.number}`);
|
|
10818
|
-
async function listOpen(client3, { all = false } = {}) {
|
|
10819
|
-
const every = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
|
|
10820
|
-
const picked = all ? every : every.filter((i) => i.fields.status?.name === PENDING_STATUS);
|
|
10821
|
-
const linked = await Promise.all(picked.map((i) => client3.remoteLinks(i.key).then((r) => refKeys(remoteText(r)))));
|
|
10822
|
-
return {
|
|
10823
|
-
unresolved: every.length,
|
|
10824
|
-
rows: picked.map((i, n) => ({
|
|
10825
|
-
key: i.key,
|
|
10826
|
-
status: i.fields.status?.name ?? "?",
|
|
10827
|
-
priority: i.fields.priority?.name,
|
|
10828
|
-
summary: i.fields.summary ?? "",
|
|
10829
|
-
url: client3.browseUrl(i.key),
|
|
10830
|
-
reporter: i.fields.reporter?.displayName,
|
|
10831
|
-
assignee: i.fields.assignee?.displayName,
|
|
10832
|
-
linkedRefs: linked[n] ?? [],
|
|
10833
|
-
created: String(i.fields.created ?? "").slice(0, 10),
|
|
10834
|
-
fromAgent: (i.fields.summary ?? "").startsWith(GAP_PREFIX)
|
|
10835
|
-
}))
|
|
10836
|
-
};
|
|
10837
|
-
}
|
|
10838
|
-
async function showIssue({ client: client3, cnb }, key2) {
|
|
10839
|
-
const issue = await client3.issue(key2);
|
|
10840
|
-
const comments = await client3.comments(key2);
|
|
10841
|
-
const remoteLinks = await client3.remoteLinks(key2);
|
|
10842
|
-
const inRemote = new Set(refKeys(remoteText(remoteLinks)));
|
|
10843
|
-
const links = linkedRepoRefs(bodyText(issue, comments, remoteLinks)).map((l) => ({
|
|
10844
|
-
...cnbIssueState(cnb, l.repo, l.number),
|
|
10845
|
-
source: inRemote.has(`${l.repo}#${l.number}`) ? "remote" : "comment"
|
|
10846
|
-
}));
|
|
10847
|
-
const transitions = await client3.transitions(key2);
|
|
10848
|
-
return { issue, comments, remoteLinks, links, transitions };
|
|
10849
|
-
}
|
|
10850
|
-
async function commentIssue(client3, key2, body) {
|
|
10851
|
-
await client3.addComment(key2, body);
|
|
10852
|
-
return { key: key2, url: client3.browseUrl(key2) };
|
|
10853
|
-
}
|
|
10854
|
-
async function assignIssue(client3, key2, who) {
|
|
10855
|
-
const name = who === "me" || !who ? (await client3.myself()).name ?? "" : who;
|
|
10856
|
-
if (!name) throw new Error("\u53D6\u4E0D\u5230\u5F53\u524D\u7528\u6237\u540D\uFF0C\u65E0\u6CD5\u63A5\u624B");
|
|
10857
|
-
await client3.assign(key2, name);
|
|
10858
|
-
return { key: key2, who: name, transitions: await client3.transitions(key2) };
|
|
10859
|
-
}
|
|
10860
|
-
async function moveIssue(client3, key2, target, comment) {
|
|
10861
|
-
const transition = await client3.transition(key2, target, comment);
|
|
10862
|
-
return { key: key2, transition };
|
|
10863
|
-
}
|
|
10864
|
-
async function toIssue({ client: client3, cnb }, key2, { repo = "hcm/hcm_nx_core", force = false, priority = "P2" } = {}) {
|
|
10865
|
-
const issue = await client3.issue(key2);
|
|
10866
|
-
const comments = await client3.comments(key2);
|
|
10867
|
-
const remote = await client3.remoteLinks(key2);
|
|
10868
|
-
const existing = linkedRepoRefs(bodyText(issue, comments, remote));
|
|
10869
|
-
if (existing.length && !force) {
|
|
10870
|
-
const remoteText2 = remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
|
|
10871
|
-
const linked = [];
|
|
10872
|
-
const alreadyLinked = [];
|
|
10873
|
-
for (const e of existing) {
|
|
10874
|
-
const ref = `${e.repo}#${e.number}`;
|
|
10875
|
-
const url2 = repoIssueUrl(e.repo, e.number);
|
|
10876
|
-
if (remoteText2.includes(url2) || remoteText2.includes(ref)) {
|
|
10877
|
-
alreadyLinked.push(ref);
|
|
10677
|
+
if (c.file) {
|
|
10678
|
+
const file = path10.resolve(root, fill(c.file));
|
|
10679
|
+
const want = c.expect ?? {};
|
|
10680
|
+
const bad = [];
|
|
10681
|
+
if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
|
|
10682
|
+
const rows = deps.readXlsx(file);
|
|
10683
|
+
const header = (rows[0] ?? []).map((x) => String(x).trim());
|
|
10684
|
+
for (const h of want.xlsx_header ?? []) if (!header.includes(h)) bad.push(`\u8868\u5934\u91CC\u6CA1\u6709\u300C${h}\u300D\uFF0C\u5B9E\u9645\u662F [${header.slice(0, 8).join(", ")}]`);
|
|
10685
|
+
if (want.xlsx_min_rows !== void 0 && rows.length - 1 < want.xlsx_min_rows) bad.push(`\u6570\u636E\u884C ${Math.max(rows.length - 1, 0)} \u5C11\u4E8E ${want.xlsx_min_rows}`);
|
|
10686
|
+
}
|
|
10687
|
+
if (want.text_contains) {
|
|
10688
|
+
const text = await deps.readText(file);
|
|
10689
|
+
for (const t of want.text_contains) if (!text.includes(t)) bad.push(`\u6587\u4EF6\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
10690
|
+
}
|
|
10691
|
+
results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
|
|
10878
10692
|
continue;
|
|
10879
10693
|
}
|
|
10880
|
-
|
|
10881
|
-
|
|
10694
|
+
const out = path10.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
|
|
10695
|
+
const argv = ["--path", fill(c.page), "--out", out];
|
|
10696
|
+
if (opts.env) argv.push("--env", opts.env);
|
|
10697
|
+
const as = c.as ?? opts.as;
|
|
10698
|
+
if (as) argv.push("--as", as);
|
|
10699
|
+
for (const t of c.expect_text ?? []) argv.push("--expect-text", t);
|
|
10700
|
+
for (const t of c.reject_text ?? []) argv.push("--reject-text", t);
|
|
10701
|
+
const r = deps.pageAcceptance(root, argv);
|
|
10702
|
+
results.push(r.status === 0 ? { name: c.name, verdict: "pass", detail: out } : { name: c.name, verdict: "fail", detail: (r.stderr || r.stdout).trim().split("\n").slice(-1)[0] ?? `\u9000\u51FA\u7801 ${r.status}` });
|
|
10703
|
+
} catch (e) {
|
|
10704
|
+
results.push({ name: c.name, verdict: "fail", detail: e.message });
|
|
10882
10705
|
}
|
|
10883
|
-
return { key: key2, existing: existing.map((e) => `${e.repo}#${e.number}`), linked, alreadyLinked };
|
|
10884
|
-
}
|
|
10885
|
-
const title = `${issue.fields.summary ?? ""}\uFF08Jira ${key2}\uFF09`;
|
|
10886
|
-
const body = [
|
|
10887
|
-
`> \u6765\u81EA Jira ${key2}\uFF1A${client3.browseUrl(key2)}`,
|
|
10888
|
-
`> \u62A5\u544A\u4EBA\uFF1A${issue.fields.reporter?.displayName ?? "?"} \u4F18\u5148\u7EA7\uFF1A${issue.fields.priority?.name ?? "-"}`,
|
|
10889
|
-
"",
|
|
10890
|
-
issue.fields.description || "\uFF08Jira \u6B63\u6587\u4E3A\u7A7A\uFF09"
|
|
10891
|
-
].join("\n");
|
|
10892
|
-
const raw = cnb(["issues", "create-issue", "--repo", repo, "--title", title, "--body", body, "--priority", priority]);
|
|
10893
|
-
const number = raw.match(/number:\s*"?(\d+)/)?.[1];
|
|
10894
|
-
if (!number) throw new Error(`\u4EA7\u54C1\u4ED3 issue \u5EFA\u5931\u8D25\uFF0Ccnb \u539F\u6837\u8F93\u51FA\uFF1A
|
|
10895
|
-
${raw.slice(0, 500)}`);
|
|
10896
|
-
const url = repoIssueUrl(repo, number);
|
|
10897
|
-
await client3.addRemoteLink(key2, url, `${repo}#${number} ${issue.fields.summary ?? ""}`.slice(0, 250));
|
|
10898
|
-
await client3.addComment(key2, `\u5DF2\u5728\u4EE3\u7801\u5E93\u767B\u8BB0\uFF1A${repo}#${number}
|
|
10899
|
-
${url}
|
|
10900
|
-
\u4FEE\u590D\u5408\u5165\u540E\u56DE\u5199\u672C\u5355\u4E3A\u300C\u5DF2\u4FEE\u590D\u300D\uFF0C\u76EE\u6807\u73AF\u5883\u53D1\u5E03\u4E14\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\u540E\u624D\u5173\u95ED\u3002`);
|
|
10901
|
-
const me = (await client3.myself()).name;
|
|
10902
|
-
if (me && issue.fields.assignee?.name !== me) await client3.assign(key2, me);
|
|
10903
|
-
const out = { key: key2, repo, number, url };
|
|
10904
|
-
try {
|
|
10905
|
-
const hit = await client3.transition(key2, "\u6253\u5F00\u95EE\u9898");
|
|
10906
|
-
out.moved = hit.to?.name;
|
|
10907
|
-
} catch (e) {
|
|
10908
|
-
out.moveError = e.message;
|
|
10909
10706
|
}
|
|
10910
|
-
return
|
|
10707
|
+
return results;
|
|
10911
10708
|
}
|
|
10912
|
-
async function
|
|
10913
|
-
const
|
|
10914
|
-
const
|
|
10915
|
-
const
|
|
10916
|
-
const
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
const allClosed = issues.every((l) => l.state === "closed");
|
|
10921
|
-
if (!allClosed) return { key: key2, outcome: "not-closed", links };
|
|
10922
|
-
const already = comments.some((c) => (c.body ?? "").includes(SYNC_MARKER) || (c.body ?? "").includes("\u4EA7\u54C1\u4FA7\u5DF2\u5173\u95ED"));
|
|
10923
|
-
if (already) return { key: key2, outcome: "already-written", links };
|
|
10924
|
-
if (dryRun) return { key: key2, outcome: "dry-run-would-write", links };
|
|
10925
|
-
const summary = issues.map(describeIssueState).join("\u3001");
|
|
10926
|
-
await client3.addComment(
|
|
10927
|
-
key2,
|
|
10928
|
-
`${SYNC_MARKER}${summary}\u3002\u4FEE\u590D\u53EA\u662F\u8FDB\u4E86 main\u2014\u2014\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF0C\u7531\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\u624D\u5173\u672C\u5355\uFF08verify-pass\uFF09\uFF1B\u590D\u9A8C\u4E0D\u8FC7\u8D70 verify-fail \u9000\u56DE\u3002`
|
|
10929
|
-
);
|
|
10930
|
-
const out = { key: key2, outcome: "written", links };
|
|
10931
|
-
try {
|
|
10932
|
-
const hit = await client3.transition(key2, "\u5904\u7406\u5B8C\u6210");
|
|
10933
|
-
out.moved = hit.to?.name;
|
|
10934
|
-
} catch (e) {
|
|
10935
|
-
out.moveError = e.message;
|
|
10709
|
+
async function loadCases(target) {
|
|
10710
|
+
const stat = await fs11.stat(target);
|
|
10711
|
+
const files = stat.isDirectory() ? (await fs11.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path10.join(target, f)) : [target];
|
|
10712
|
+
const out = [];
|
|
10713
|
+
for (const f of files) {
|
|
10714
|
+
const spec = yaml.load(await fs11.readFile(f, "utf8"));
|
|
10715
|
+
assertUsableSpec(spec, path10.basename(f));
|
|
10716
|
+
out.push({ file: f, spec });
|
|
10936
10717
|
}
|
|
10718
|
+
if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
|
|
10937
10719
|
return out;
|
|
10938
10720
|
}
|
|
10939
|
-
async function
|
|
10940
|
-
await client3.addComment(key2, `\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\uFF1A${note}`);
|
|
10941
|
-
const hit = await client3.transition(key2, "\u786E\u8BA4\u5173\u95ED");
|
|
10942
|
-
return { key: key2, to: hit.to?.name, url: client3.browseUrl(key2) };
|
|
10943
|
-
}
|
|
10944
|
-
async function verifyFail({ client: client3, cnb }, key2, note) {
|
|
10945
|
-
await client3.addComment(key2, `\u987E\u95EE\u590D\u9A8C\u672A\u901A\u8FC7\uFF0C\u9000\u56DE\uFF1A
|
|
10946
|
-
${note}`);
|
|
10947
|
-
const out = { key: key2, reopened: [], failed: [] };
|
|
10721
|
+
async function chironTestCommand(target, args, deps) {
|
|
10948
10722
|
try {
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
try {
|
|
10959
|
-
cnb(["issues", "update-issue", "--repo", l.repo, "--number", l.number, "--state", "open", "--state-reason", "reopened"]);
|
|
10960
|
-
cnb(["issues", "post-issue-comment", "--repo", l.repo, "--number", l.number, "--body", `\u987E\u95EE\u590D\u9A8C\u672A\u901A\u8FC7\uFF0C\u91CD\u5F00\uFF08Jira ${key2}\uFF09\uFF1A
|
|
10961
|
-
${note}`]);
|
|
10962
|
-
out.reopened.push(`${l.repo}#${l.number}`);
|
|
10963
|
-
} catch {
|
|
10964
|
-
out.failed.push(`${l.repo}#${l.number}`);
|
|
10723
|
+
const root = path10.resolve(args.project ?? ".");
|
|
10724
|
+
const where = path10.resolve(root, target ?? "tests");
|
|
10725
|
+
const cases = await loadCases(where);
|
|
10726
|
+
const report = [];
|
|
10727
|
+
let failed2 = 0;
|
|
10728
|
+
for (const { file, spec } of cases) {
|
|
10729
|
+
const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
|
|
10730
|
+
failed2 += results.filter((r) => r.verdict === "fail").length;
|
|
10731
|
+
report.push({ case: spec.name, file: path10.relative(root, file), results });
|
|
10965
10732
|
}
|
|
10966
|
-
|
|
10967
|
-
|
|
10968
|
-
}
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
10975
|
-
|
|
10976
|
-
|
|
10977
|
-
|
|
10978
|
-
|
|
10979
|
-
const remote = await client3.remoteLinks(i.key);
|
|
10980
|
-
if (refKeys(remoteText(remote)).length) continue;
|
|
10981
|
-
const refs = refKeys(bodyText(await client3.issue(i.key), await client3.comments(i.key), remote));
|
|
10982
|
-
bad.push({ key: i.key, status, url: client3.browseUrl(i.key), kind: refs.length ? "comment-only" : "missing", refs });
|
|
10983
|
-
}
|
|
10984
|
-
return { checked: rows.length, audited, bad };
|
|
10985
|
-
}
|
|
10986
|
-
async function probe(client3) {
|
|
10987
|
-
const [info, me, project] = await Promise.all([client3.serverInfo(), client3.myself(), client3.projectInfo()]);
|
|
10988
|
-
const types = (await client3.createMeta()).map((t) => ({
|
|
10989
|
-
id: t.id,
|
|
10990
|
-
name: t.name,
|
|
10991
|
-
required: (t.fields ?? []).filter((f) => f.required && !["project", "issuetype"].includes(f.fieldId)).map((f) => `${f.name}(${f.fieldId})${f.allowedValues ? `=[${f.allowedValues.slice(0, 8).map((v) => v.name ?? v.value).join("|")}]` : ""}`)
|
|
10992
|
-
}));
|
|
10993
|
-
const flows = (await client3.projectStatuses()).map((t) => ({ name: t.name, statuses: (t.statuses ?? []).map((s) => s.name ?? "") }));
|
|
10994
|
-
return {
|
|
10995
|
-
server: `Jira ${info.version ?? "?"} (${info.deploymentType ?? "?"}) @ ${client3.base}`,
|
|
10996
|
-
me: `${me.displayName ?? "?"} <${me.emailAddress ?? me.name ?? ""}> key=${me.key ?? me.name ?? ""}`,
|
|
10997
|
-
project: `${project.key ?? client3.project} ${project.name ?? ""} lead=${project.lead?.displayName ?? "?"}`,
|
|
10998
|
-
types,
|
|
10999
|
-
flows
|
|
11000
|
-
};
|
|
11001
|
-
}
|
|
11002
|
-
|
|
11003
|
-
// src/commands/jira.ts
|
|
11004
|
-
var defaultDeps3 = { client: () => createJiraClient(), cnb: defaultCnb };
|
|
11005
|
-
async function triageDeps(deps) {
|
|
11006
|
-
return { client: await deps.client(), cnb: deps.cnb };
|
|
11007
|
-
}
|
|
11008
|
-
function emit4(fmt, data, text) {
|
|
11009
|
-
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject24(data, { format: fmt }) + "\n");
|
|
11010
|
-
else process.stdout.write(text() + "\n");
|
|
11011
|
-
}
|
|
11012
|
-
function readBody(opts, positional) {
|
|
11013
|
-
if (opts.file) return readFileSync6(opts.file, "utf8");
|
|
11014
|
-
if (opts.body) return opts.body;
|
|
11015
|
-
if (positional && positional.trim()) return positional;
|
|
11016
|
-
if (process.stdin.isTTY) throw new Error("\u7F3A\u6B63\u6587\uFF1A-f <\u6587\u4EF6> / --body <\u6587\u672C> / \u4F4D\u7F6E\u53C2\u6570\uFF0C\u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582");
|
|
11017
|
-
return readFileSync6(0, "utf8");
|
|
11018
|
-
}
|
|
11019
|
-
async function run(fn) {
|
|
11020
|
-
try {
|
|
11021
|
-
await fn();
|
|
11022
|
-
} catch (e) {
|
|
11023
|
-
exitWithError(e);
|
|
11024
|
-
}
|
|
11025
|
-
}
|
|
11026
|
-
async function jiraProbeCommand(args, deps = defaultDeps3) {
|
|
11027
|
-
await run(async () => {
|
|
11028
|
-
const r = await probe(await deps.client());
|
|
11029
|
-
emit4(
|
|
11030
|
-
args.output,
|
|
11031
|
-
r,
|
|
11032
|
-
() => [
|
|
11033
|
-
r.server,
|
|
11034
|
-
`\u6211\u662F\uFF1A${r.me}`,
|
|
11035
|
-
`\u9879\u76EE\uFF1A${r.project}`,
|
|
11036
|
-
...r.types.map((t) => `issuetype ${t.name}(${t.id}) \u5FC5\u586B\uFF1A${t.required.join(" \xB7 ") || "\uFF08\u65E0\uFF09"}`),
|
|
11037
|
-
...r.flows.map((f) => `\u72B6\u6001\u6D41 ${f.name}\uFF1A${f.statuses.join(" \u2192 ")}`)
|
|
11038
|
-
].join("\n")
|
|
11039
|
-
);
|
|
11040
|
-
});
|
|
11041
|
-
}
|
|
11042
|
-
async function jiraOpenCommand(args, deps = defaultDeps3) {
|
|
11043
|
-
await run(async () => {
|
|
11044
|
-
const r = await listOpen(await deps.client(), { all: !!args.all });
|
|
11045
|
-
emit4(args.output, r, () => {
|
|
11046
|
-
if (!r.rows.length) return args.all ? "\u9879\u76EE\u91CC\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u5355\u3002" : `\u6CA1\u6709\u5F85\u5206\u8BCA\uFF08\u72B6\u6001\u300C\u65B0\u589E\u300D\uFF09\u7684\u5355\uFF1B\u9879\u76EE\u91CC\u672A\u89E3\u51B3\u7684\u5171 ${r.unresolved} \u6761\uFF0C\u770B\u5168\u90E8\u52A0 --all\u3002`;
|
|
11047
|
-
return r.rows.map(
|
|
11048
|
-
(i) => `${i.key} [${i.status}${i.priority ? " " + i.priority : ""}]${i.fromAgent ? "" : " \uFF08\u975E agent \u63D0\u5355\uFF09"} ${i.summary}
|
|
11049
|
-
${i.url} \u62A5\u544A\u4EBA ${i.reporter ?? "?"} \u7ECF\u529E\u4EBA ${i.assignee ?? "\u672A\u63A5\u624B"} \u6761\u76EE ${i.linkedRefs.join(" / ") || "\u94FE\u63A5\u680F\u672A\u6302"} ${i.created}`
|
|
11050
|
-
).join("\n");
|
|
11051
|
-
});
|
|
11052
|
-
});
|
|
11053
|
-
}
|
|
11054
|
-
async function jiraShowCommand(key2, args, deps = defaultDeps3) {
|
|
11055
|
-
await run(async () => {
|
|
11056
|
-
const d = await triageDeps(deps);
|
|
11057
|
-
const r = await showIssue(d, key2);
|
|
11058
|
-
const i = r.issue;
|
|
11059
|
-
emit4(args.output, r, () => {
|
|
11060
|
-
const out = [
|
|
11061
|
-
`${i.key} [${i.fields.status?.name}${i.fields.resolution ? "\xB7" + i.fields.resolution.name : ""}${i.fields.priority ? " " + i.fields.priority.name : ""}] ${i.fields.summary ?? ""}`,
|
|
11062
|
-
`${d.client.browseUrl(i.key)} \u62A5\u544A\u4EBA ${i.fields.reporter?.displayName ?? "?"} \u7ECF\u529E\u4EBA ${i.fields.assignee?.displayName ?? "-"} \u6807\u7B7E ${(i.fields.labels ?? []).join(",") || "-"}`,
|
|
11063
|
-
"",
|
|
11064
|
-
"--- \u6B63\u6587 ---",
|
|
11065
|
-
i.fields.description || "\uFF08\u7A7A\uFF09"
|
|
11066
|
-
];
|
|
11067
|
-
for (const c of r.comments) out.push("", `--- \u8BC4\u8BBA ${c.author?.displayName ?? "?"} ${String(c.created ?? "").slice(0, 10)} ---`, c.body ?? "");
|
|
11068
|
-
for (const l of r.links)
|
|
11069
|
-
out.push("", `\u5173\u8054\u4EE3\u7801\u5E93 ${describeIssueState(l)}${l.source === "comment" ? ` \uFF08\u4EC5\u89C1\u4E8E\u8BC4\u8BBA\uFF0C\u300C\u94FE\u63A5\u300D\u680F\u672A\u6302\uFF1Bhcm jira to-issue ${i.key} \u53EF\u8865\u6302\uFF09` : ""}`);
|
|
11070
|
-
out.push("", `\u53EF\u7528\u6D41\u8F6C\uFF1A${r.transitions.map((t) => `${t.name}\u2192${t.to?.name}`).join(" / ") || "\uFF08\u65E0\uFF09"}`);
|
|
11071
|
-
return out.join("\n");
|
|
11072
|
-
});
|
|
11073
|
-
});
|
|
11074
|
-
}
|
|
11075
|
-
async function jiraCommentCommand(key2, text, args, deps = defaultDeps3) {
|
|
11076
|
-
await run(async () => {
|
|
11077
|
-
const body = readBody(args, text);
|
|
11078
|
-
const r = await commentIssue(await deps.client(), key2, body);
|
|
11079
|
-
emit4(args.output, r, () => `\u5DF2\u56DE\u590D ${r.key}\uFF1A${r.url}`);
|
|
11080
|
-
});
|
|
11081
|
-
}
|
|
11082
|
-
async function jiraAssignCommand(key2, who, args, deps = defaultDeps3) {
|
|
11083
|
-
await run(async () => {
|
|
11084
|
-
const r = await assignIssue(await deps.client(), key2, who);
|
|
11085
|
-
emit4(args.output, r, () => `${r.key} \u5DF2\u6539\u6D3E\u7ED9 ${r.who}\u3002\u73B0\u5728\u53EF\u505A\u7684\u6D41\u8F6C\uFF1A${r.transitions.map((x) => `${x.name}\u2192${x.to?.name}`).join(" / ") || "\uFF08\u65E0\uFF09"}`);
|
|
11086
|
-
});
|
|
11087
|
-
}
|
|
11088
|
-
async function jiraMoveCommand(key2, target, args, deps = defaultDeps3) {
|
|
11089
|
-
await run(async () => {
|
|
11090
|
-
const comment = args.file || args.body ? readBody(args) : void 0;
|
|
11091
|
-
const r = await moveIssue(await deps.client(), key2, target, comment);
|
|
11092
|
-
emit4(args.output, r, () => `${r.key} \u5DF2\u6D41\u8F6C\uFF1A${r.transition.name} \u2192 ${r.transition.to?.name}`);
|
|
11093
|
-
});
|
|
11094
|
-
}
|
|
11095
|
-
async function jiraToIssueCommand(key2, args, deps = defaultDeps3) {
|
|
11096
|
-
await run(async () => {
|
|
11097
|
-
const r = await toIssue(await triageDeps(deps), key2, { repo: args.repo, force: !!args.force });
|
|
11098
|
-
emit4(args.output, r, () => {
|
|
11099
|
-
if ("existing" in r) {
|
|
11100
|
-
const parts = [`${r.key} \u5DF2\u5173\u8054 ${r.existing.join("\u3001")}\uFF0C\u4E0D\u91CD\u590D\u5EFA\u3002\u8981\u518D\u5EFA\u52A0 --force`];
|
|
11101
|
-
if (r.linked.length) parts.push(`\u5DF2\u8865\u6302\u8FDC\u7A0B\u94FE\u63A5\uFF1A${r.linked.join("\u3001")}\uFF08\u539F\u5148\u53EA\u5199\u5728\u6B63\u6587/\u8BC4\u8BBA\u91CC\uFF0CJira\u300C\u94FE\u63A5\u300D\u680F\u770B\u4E0D\u5230\uFF09`);
|
|
11102
|
-
else if (r.alreadyLinked.length) parts.push("\u8FDC\u7A0B\u94FE\u63A5\u5DF2\u9F50\uFF0C\u65E0\u9700\u8865\u6302");
|
|
11103
|
-
return parts.join("\n");
|
|
11104
|
-
}
|
|
11105
|
-
const moved = r.moved ? `\uFF0C\u5DF2\u63A8\u8FDB\u5230 ${r.moved}` : r.moveError ? `\uFF0C\u4F46\u6CA1\u80FD\u63A8\u8FDB\u72B6\u6001\uFF1A${r.moveError}` : "";
|
|
11106
|
-
return `${r.key} \u2192 ${r.repo}#${r.number} ${r.url}${moved}`;
|
|
11107
|
-
});
|
|
11108
|
-
});
|
|
11109
|
-
}
|
|
11110
|
-
async function jiraSyncCommand(key2, args, deps = defaultDeps3) {
|
|
11111
|
-
await run(async () => {
|
|
11112
|
-
const r = await syncIssue(await triageDeps(deps), key2, { dryRun: !!args.dryRun });
|
|
11113
|
-
emit4(args.output, r, () => {
|
|
11114
|
-
const links = r.links.map(describeIssueState).join("\u3001") || "\uFF08\u65E0\uFF09";
|
|
11115
|
-
switch (r.outcome) {
|
|
11116
|
-
case "written":
|
|
11117
|
-
return `${r.key} \u5DF2\u56DE\u5199\uFF1A${links}${r.moved ? ` \u5E76\u63A8\u8FDB\u5230 ${r.moved}` : r.moveError ? `\uFF08\u72B6\u6001\u6CA1\u63A8\u52A8\uFF1A${r.moveError}\uFF09` : ""}`;
|
|
11118
|
-
case "dry-run-would-write":
|
|
11119
|
-
return `${r.key} \u4EE3\u7801\u5E93\u6761\u76EE\u5DF2\u5168\u5173\uFF0C\u5B9E\u8DD1\u4F1A\u56DE\u5199\u5E76\u63A8\u300C\u5904\u7406\u5B8C\u6210\u300D\uFF1A${links}`;
|
|
11120
|
-
case "already-written":
|
|
11121
|
-
return `${r.key} \u5DF2\u56DE\u5199\u8FC7\uFF0C\u8DF3\u8FC7\uFF1A${links}`;
|
|
11122
|
-
case "not-closed":
|
|
11123
|
-
return `${r.key} \u4EA7\u54C1\u4ED3\u8FD8\u6CA1\u5173\uFF1A${links}`;
|
|
11124
|
-
case "blocked-unreadable":
|
|
11125
|
-
return `${r.key} \u6709\u8BFB\u4E0D\u5230\u7684\u4EE3\u7801\u5E93\u6761\u76EE\uFF0C\u4E0D\u6562\u5224\u5DF2\u5173\uFF08fail-closed\uFF09\uFF1A${links}`;
|
|
11126
|
-
default:
|
|
11127
|
-
return `${r.key} \u6CA1\u6709\u5173\u8054\u7684\u4EA7\u54C1\u4ED3 issue\uFF08PR \u53F7\u4E0D\u7B97\uFF09\uFF0C\u5148 to-issue\uFF1A${links}`;
|
|
11128
|
-
}
|
|
11129
|
-
});
|
|
11130
|
-
if (r.outcome === "blocked-unreadable") process.exitCode = 1;
|
|
11131
|
-
});
|
|
11132
|
-
}
|
|
11133
|
-
async function jiraVerifyPassCommand(key2, note, args, deps = defaultDeps3) {
|
|
11134
|
-
await run(async () => {
|
|
11135
|
-
const text = args.file || args.body || note && note.trim() ? readBody(args, note) : "\u987E\u95EE\u5728\u76EE\u6807\u73AF\u5883\u590D\u9A8C\u901A\u8FC7\u3002";
|
|
11136
|
-
const r = await verifyPass(await deps.client(), key2, text);
|
|
11137
|
-
emit4(args.output, r, () => `${r.key} \u5DF2\u5173\u95ED\uFF08${r.to ?? "?"}\uFF09\uFF1A${r.url}`);
|
|
11138
|
-
});
|
|
11139
|
-
}
|
|
11140
|
-
async function jiraVerifyFailCommand(key2, note, args, deps = defaultDeps3) {
|
|
11141
|
-
await run(async () => {
|
|
11142
|
-
const r = await verifyFail(await triageDeps(deps), key2, readBody(args, note));
|
|
11143
|
-
emit4(args.output, r, () => {
|
|
11144
|
-
const moved = r.moved ? `\u5DF2\u9000\u56DE\u5230 ${r.moved}` : `\u72B6\u6001\u6CA1\u9000\u56DE\uFF08${r.moveError ?? "?"}\uFF09`;
|
|
11145
|
-
const failed2 = r.failed.length ? `\uFF1B\u91CD\u5F00\u5931\u8D25\uFF1A${r.failed.join("\u3001")}` : "";
|
|
11146
|
-
return `${r.key} ${moved}\uFF1B\u5DF2\u91CD\u5F00 ${r.reopened.join("\u3001") || "\uFF08\u6CA1\u6709\u53EF\u91CD\u5F00\u7684\u4EE3\u7801\u5E93\u6761\u76EE\uFF09"}${failed2}`;
|
|
11147
|
-
});
|
|
11148
|
-
});
|
|
11149
|
-
}
|
|
11150
|
-
async function jiraAuditCommand(args, deps = defaultDeps3) {
|
|
11151
|
-
await run(async () => {
|
|
11152
|
-
const r = await auditIssues(await deps.client());
|
|
11153
|
-
emit4(args.output, r, () => {
|
|
11154
|
-
if (!r.checked) return "\u9879\u76EE\u91CC\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u7F3A\u53E3\u5355\u3002";
|
|
11155
|
-
const lines = [`\u672C\u8F6E\u6838\u8FC7 ${r.audited.length} \u6761\u5DF2\u53D7\u7406\u7684\u5355\uFF08\u672A\u89E3\u51B3\u5171 ${r.checked} \u6761\uFF0C\u300C\u65B0\u589E\u300D\u7684\u4E0D\u7B97\uFF09\u3002`];
|
|
11156
|
-
for (const b of r.bad) {
|
|
11157
|
-
lines.push(
|
|
11158
|
-
b.kind === "comment-only" ? `\u26A0\uFE0F ${b.key} [${b.status}] \u6761\u76EE\u53EA\u5199\u5728\u8BC4\u8BBA\u91CC\u3001\u300C\u94FE\u63A5\u300D\u680F\u662F\u7A7A\u7684\uFF1A${b.refs.join(" / ")}
|
|
11159
|
-
${b.url}
|
|
11160
|
-
\u8865\u6302\uFF1Ahcm jira to-issue ${b.key}` : `\u26A0\uFE0F ${b.key} [${b.status}] \u6CA1\u6709\u4EFB\u4F55\u4EE3\u7801\u5E93\u6761\u76EE\uFF1A${b.url}
|
|
11161
|
-
\u5148\u5206\u8BCA\uFF1Ahcm jira to-issue ${b.key} --repo hcm/hcm_nx_core`
|
|
11162
|
-
);
|
|
10733
|
+
const fmt = args.output ?? "table";
|
|
10734
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
10735
|
+
process.stdout.write(formatObject24({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
|
|
10736
|
+
} else {
|
|
10737
|
+
for (const c of report) {
|
|
10738
|
+
process.stdout.write(`
|
|
10739
|
+
${c.case}\uFF08${c.file}\uFF09
|
|
10740
|
+
`);
|
|
10741
|
+
for (const r of c.results) {
|
|
10742
|
+
const mark = r.verdict === "pass" ? "\u2705" : r.verdict === "step" ? "\xB7" : r.verdict === "warn" ? "\u26A0\uFE0F" : "\u274C";
|
|
10743
|
+
process.stdout.write(` ${mark} ${r.name}${r.detail ? ` ${r.detail}` : ""}
|
|
10744
|
+
`);
|
|
10745
|
+
}
|
|
11163
10746
|
}
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
}
|
|
11171
|
-
|
|
11172
|
-
await run(async () => {
|
|
11173
|
-
if (!keywords.length) throw new Error("\u7ED9\u81F3\u5C11\u4E00\u4E2A\u5173\u952E\u8BCD\uFF1A\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61");
|
|
11174
|
-
const r = await gapSearch(await triageDeps(deps), keywords, { includeClosed: args.includeClosed !== false });
|
|
11175
|
-
emit4(args.output, r, () => {
|
|
11176
|
-
const head = r.jiraError ? `\u26A0\uFE0F Jira \u6CA1\u67E5\u6210\uFF08${r.jiraError}\uFF09\uFF0C\u4E0B\u9762\u53EA\u6709\u4EA7\u54C1\u4ED3\u7684\u7ED3\u679C\uFF0C\u4E0D\u4EE3\u8868 Jira \u91CC\u6CA1\u6709\u3002
|
|
11177
|
-
` : "";
|
|
11178
|
-
if (!r.rows.length) return `${head}Jira \u4E0E\u4EA7\u54C1\u4ED3\u90FD\u6CA1\u6709\u76F8\u5173\u8BB0\u5F55\u3002\u53EF\u4EE5 submit\uFF0C\u4F46\u5148\u628A\u4E09\u95EE\u7B54\u5B8C\u3002`;
|
|
11179
|
-
return `${head}\u547D\u4E2D ${r.rows.length} \u6761\uFF08\u540C\u4E00\u7F3A\u53E3\u5DF2\u6709\u7F16\u53F7\u5C31\u5728\u90A3\u6761\u4E0B\u8FFD\u52A0\u73B0\u573A\uFF0C\u4E0D\u65B0\u5F00\uFF09\uFF1A
|
|
11180
|
-
${r.rows.map((i) => `${i.where} ${i.id} [${i.state}${i.resolution ? "\xB7" + i.resolution : ""}] ${i.title}
|
|
11181
|
-
${i.url}`).join("\n")}`;
|
|
11182
|
-
});
|
|
11183
|
-
});
|
|
11184
|
-
}
|
|
11185
|
-
async function jiraStatusCommand(ref, args, deps = defaultDeps3) {
|
|
11186
|
-
await run(async () => {
|
|
11187
|
-
const r = await gapStatus(await triageDeps(deps), ref);
|
|
11188
|
-
emit4(args.output, r, () => [...r.lines, `\u4E0B\u4E00\u6B65\uFF1A${r.nextStep}`].join("\n"));
|
|
11189
|
-
});
|
|
11190
|
-
}
|
|
11191
|
-
async function fingerprintText(env2) {
|
|
11192
|
-
try {
|
|
11193
|
-
const g = await loadGlobalConfig11();
|
|
11194
|
-
const name = resolveActiveEnv5({ envFlag: env2 }, process.env, g);
|
|
11195
|
-
const cfg = await loadEnv11(name);
|
|
11196
|
-
if (!cfg?.endpoint) return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${name}\uFF1A\u6CA1\u6709 endpoint\uFF09`;
|
|
11197
|
-
const http = createHttpClient4({ endpoint: cfg.endpoint.replace(/\/+$/, ""), getAccessToken: async () => null, onRefresh: async () => {
|
|
11198
|
-
} });
|
|
11199
|
-
const resp = await http.get("/api/version/backend");
|
|
11200
|
-
const info = resp.data?.data ?? resp.data ?? {};
|
|
11201
|
-
const commit = info.commit ?? info.gitCommit ?? info.version ?? "?";
|
|
11202
|
-
return `backend ${String(commit).slice(0, 12)} \xB7 CLI ${CLI_VERSION} \xB7 env ${name}`;
|
|
10747
|
+
const verified = report.reduce((n, c) => n + c.results.filter((r) => r.verdict === "pass").length, 0);
|
|
10748
|
+
process.stdout.write(failed2 === 0 ? `
|
|
10749
|
+
\u5168\u90E8\u901A\u8FC7\uFF08\u771F\u5224\u8FC7\u5185\u5BB9\u7684 ${verified} \u6761\uFF1B\u5E26 \xB7 \u7684\u662F\u6B65\u9AA4\uFF0C\u4E0D\u7B97\u9A8C\u8BC1\uFF09\u3002
|
|
10750
|
+
` : `
|
|
10751
|
+
${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4E86\u5B9E\u9645\u503C\u4E0E\u671F\u671B\uFF0C\u7167\u7740\u67E5\u3002
|
|
10752
|
+
`);
|
|
10753
|
+
}
|
|
10754
|
+
process.exitCode = failed2 === 0 ? 0 : 1;
|
|
11203
10755
|
} catch (e) {
|
|
11204
|
-
|
|
10756
|
+
exitWithError(e);
|
|
11205
10757
|
}
|
|
11206
10758
|
}
|
|
11207
|
-
async function jiraSubmitCommand(args, deps = defaultDeps3) {
|
|
11208
|
-
await run(async () => {
|
|
11209
|
-
const raw = args.file ? readFileSync6(args.file, "utf8") : process.stdin.isTTY ? "" : readFileSync6(0, "utf8");
|
|
11210
|
-
if (!raw.trim()) throw new Error("\u7F3A\u53E3\u8F7D\u8377\uFF1A--file <gap.json> \u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582 JSON");
|
|
11211
|
-
const gap = validateGapInput(JSON.parse(raw));
|
|
11212
|
-
const fp = args.fingerprint ?? await fingerprintText(args.env);
|
|
11213
|
-
const r = await gapSubmit(await triageDeps(deps), gap, { fingerprintText: fp, issuetypeOverride: args.issuetype, assigneeOverride: args.assignee });
|
|
11214
|
-
emit4(
|
|
11215
|
-
args.output,
|
|
11216
|
-
r,
|
|
11217
|
-
() => r.outcome === "appended" ? `Jira \u91CC\u5DF2\u6709\u540C\u4E00\u7F3A\u53E3 ${r.key}\u300C${r.summary}\u300D\uFF0C\u5DF2\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\u8BC4\u8BBA\uFF0C\u6CA1\u6709\u65B0\u5F00\u3002
|
|
11218
|
-
${r.url}
|
|
11219
|
-
\u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u8FD9\u4E2A\u95EE\u9898\u5DF2\u7ECF\u5728\u4EA7\u54C1\u90A3\u8FB9\u6392\u7740\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u5206\u8BCA\u7ED3\u8BBA\u4F1A\u56DE\u5230\u90A3\u5355\u91CC\u3002` : `\u5DF2\u63D0 ${r.key}\uFF08${r.type} \xB7 ${r.module}\uFF09\uFF1A${r.url}
|
|
11220
|
-
\u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u7F3A\u53E3\u5DF2\u63D0\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u4EA7\u54C1\u5206\u8BCA\u540E\u4F1A\u5728\u90A3\u5355\u91CC\u56DE\u590D\u3002\u62A5\u544A\u91CC\u5199\u300CBLOCKED \xB7 \u5DF2\u63D0 ${r.key} \xB7 \u66FF\u4EE3\u6CD5\uFF1A${r.alternative}\u300D\u3002`
|
|
11221
|
-
);
|
|
11222
|
-
});
|
|
11223
|
-
}
|
|
11224
10759
|
|
|
11225
10760
|
// src/commands/delivery-recon.ts
|
|
11226
10761
|
init_auth_guard();
|
|
@@ -11242,10 +10777,10 @@ async function deliveryReconCommand(args) {
|
|
|
11242
10777
|
try {
|
|
11243
10778
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
11244
10779
|
const client3 = HcmClient23.fromAuthContext(ctx);
|
|
11245
|
-
const
|
|
11246
|
-
const sourceKey = await computeReconSourceKey(
|
|
10780
|
+
const probe = httpProbe3(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
|
|
10781
|
+
const sourceKey = await computeReconSourceKey(probe);
|
|
11247
10782
|
const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
|
|
11248
|
-
const summary = await runRecon(
|
|
10783
|
+
const summary = await runRecon(probe, layout, {
|
|
11249
10784
|
state: args.state ?? "",
|
|
11250
10785
|
onlyModel: args.model ?? null,
|
|
11251
10786
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
@@ -12034,9 +11569,9 @@ async function runTriage(args) {
|
|
|
12034
11569
|
}
|
|
12035
11570
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
12036
11571
|
const client3 = HcmClient26.fromAuthContext(ctx);
|
|
12037
|
-
const
|
|
12038
|
-
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(
|
|
12039
|
-
const result = await runTriageRound(
|
|
11572
|
+
const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES3);
|
|
11573
|
+
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
|
|
11574
|
+
const result = await runTriageRound(probe, artifactsDir, entriesIn);
|
|
12040
11575
|
if (result.body === null) {
|
|
12041
11576
|
process.stdout.write(renderProblems(result.problems));
|
|
12042
11577
|
return 1;
|
|
@@ -12229,21 +11764,10 @@ chiron.command("doctor").description(
|
|
|
12229
11764
|
"\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u63A5\u6CA1\u63A5 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355"
|
|
12230
11765
|
).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u8986\u76D6\u8981\u6838\u7684\u73AF\u5883\u522B\u540D\uFF08\u9ED8\u8BA4\u53D6 env.yaml\uFF1B\u591A\u73AF\u5883\u9879\u76EE\u7528\u5B83\u6328\u4E2A\u63A2\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\u63A2\u951A\u70B9").option("--fix", "\u80FD\u81EA\u52A8\u8865\u7684\u8865\u4E0A\uFF08\u6280\u80FD / \u6848\u4F8B\u5E93\uFF09\u540E\u518D\u6838\u4E00\u904D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
|
|
12231
11766
|
var OUTPUT_OPT = ["--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table"];
|
|
12232
|
-
var
|
|
12233
|
-
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
jira.command("comment").description("\u56DE\u590D\uFF08\u5206\u8BCA\u7ED3\u8BBA\u8D70\u8FD9\u6761\uFF09\uFF1A-f \u6587\u4EF6 / --body \u6587\u672C / \u4F4D\u7F6E\u53C2\u6570 / \u6807\u51C6\u8F93\u5165").argument("<key>", "Jira \u5355\u53F7").argument("[text]", "\u6B63\u6587").option("-f, --file <path>", "\u6B63\u6587\u6587\u4EF6").option("--body <text>", "\u6B63\u6587").option(...OUTPUT_OPT).action((key2, text, opts) => jiraCommentCommand(key2, text, opts));
|
|
12237
|
-
jira.command("assign").description("\u63A5\u624B\uFF1A\u6539\u7ECF\u529E\u4EBA\uFF08\u9ED8\u8BA4 me\uFF09").argument("<key>", "Jira \u5355\u53F7").argument("[who]", "\u7528\u6237\u540D\u6216 me", "me").option(...OUTPUT_OPT).action((key2, who, opts) => jiraAssignCommand(key2, who, opts));
|
|
12238
|
-
jira.command("move").description("\u6D41\u8F6C\uFF1A\u76EE\u6807\u72B6\u6001\u540D\u6216\u6D41\u8F6C\u540D\uFF08\u5982 \u63D0\u4EA4\u534F\u8C03 / \u4E0D\u7528\u5904\u7406\u4E86\uFF09\uFF1B\u53EF\u9644\u8BC4\u8BBA").argument("<key>", "Jira \u5355\u53F7").argument("<target>", "\u72B6\u6001\u6216\u6D41\u8F6C\u540D").option("-f, --file <path>", "\u9644\u5E26\u8BC4\u8BBA\u7684\u6587\u4EF6").option("--body <text>", "\u9644\u5E26\u8BC4\u8BBA").option(...OUTPUT_OPT).action((key2, target, opts) => jiraMoveCommand(key2, target, opts));
|
|
12239
|
-
jira.command("to-issue").description("\u5206\u8BCA\u4E3A\u771F\u7F3A\u53E3\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u53CC\u5411\u56DE\u94FE\uFF08\u5EFA\u6761\u76EE \u2192 \u6302\u94FE\u63A5 \u2192 \u63A5\u624B \u2192 \u63A8 OPEN\uFF09").argument("<key>", "Jira \u5355\u53F7").option("--repo <slug>", "\u4EA7\u54C1\u4ED3", "hcm/hcm_nx_core").option("--force", "\u5DF2\u5173\u8054\u8FC7\u4E5F\u518D\u5EFA\u4E00\u6761").option(...OUTPUT_OPT).action((key2, opts) => jiraToIssueCommand(key2, opts));
|
|
12240
|
-
jira.command("sync").description("\u4EE3\u7801\u5E93\u6761\u76EE\u5168\u5173 \u2192 \u56DE\u5199 Jira \u5E76\u63A8\u300C\u5DF2\u4FEE\u590D\u300D\uFF08PR \u53F7\u4E0D\u7B97\u6761\u76EE\uFF1B\u8BFB\u4E0D\u5230\u7684\u6309\u672A\u5173\u5904\u7406\uFF09").argument("<key>", "Jira \u5355\u53F7").option("--dry-run", "\u53EA\u5224\u65AD\u4E0D\u5199").option(...OUTPUT_OPT).action((key2, opts) => jiraSyncCommand(key2, opts));
|
|
12241
|
-
jira.command("verify-pass").description("\u987E\u95EE\u5728\u76EE\u6807\u73AF\u5883\u590D\u9A8C\u901A\u8FC7 \u2192 CLOSE").argument("<key>", "Jira \u5355\u53F7").argument("[note]", "\u8BF4\u660E").option("-f, --file <path>", "\u8BF4\u660E\u6587\u4EF6").option("--body <text>", "\u8BF4\u660E").option(...OUTPUT_OPT).action((key2, note, opts) => jiraVerifyPassCommand(key2, note, opts));
|
|
12242
|
-
jira.command("verify-fail").description("\u590D\u9A8C\u4E0D\u901A\u8FC7 \u2192 \u9000\u56DE OPEN\uFF0C\u5E76\u91CD\u5F00\u4EE3\u7801\u5E93 issue").argument("<key>", "Jira \u5355\u53F7").argument("[note]", "\u4E0D\u901A\u8FC7\u7684\u8BF4\u660E").option("-f, --file <path>", "\u8BF4\u660E\u6587\u4EF6").option("--body <text>", "\u8BF4\u660E").option(...OUTPUT_OPT).action((key2, note, opts) => jiraVerifyFailCommand(key2, note, opts));
|
|
12243
|
-
jira.command("audit").description("\u4E00\u81F4\u6027\uFF1A\u72B6\u6001\u5DF2\u79BB\u5F00\u300C\u65B0\u589E\u300D\u7684\u7F3A\u53E3\u5355\u5FC5\u987B\u6302\u7740\u4EE3\u7801\u5E93\u6761\u76EE").option(...OUTPUT_OPT).action((opts) => jiraAuditCommand(opts));
|
|
12244
|
-
jira.command("search").description("\u987E\u95EE\u4FA7\u67E5\u91CD\uFF1A\u6309\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61\u67E5 Jira \u4E0E\u4EA7\u54C1\u4ED3\uFF0C\u5E26\u56DE\u7F16\u53F7\u4E0E\u72B6\u6001").argument("<keywords...>", "\u5173\u952E\u8BCD\uFF0C\u6BCF\u4E2A\u5355\u72EC\u67E5\u4E00\u6B21").option("--no-include-closed", "\u53EA\u67E5\u672A\u89E3\u51B3\u7684").option(...OUTPUT_OPT).action((keywords, opts) => jiraSearchCommand(keywords, opts));
|
|
12245
|
-
jira.command("status").description("\u987E\u95EE\u4FA7\u67E5\u8FDB\u5EA6\uFF1A\u8BA4 HCMNX-12 / 12 / core#2198 / cases#26").argument("<ref>", "Jira \u5355\u53F7\u6216\u4EE3\u7801\u5E93\u5F15\u7528").option(...OUTPUT_OPT).action((ref, opts) => jiraStatusCommand(ref, opts));
|
|
12246
|
-
jira.command("submit").description("\u987E\u95EE\u4FA7\u63D0\u7F3A\u53E3\uFF1A\u5148\u67E5\u91CD\uFF08\u540C\u4E00\u7F3A\u53E3\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\uFF09\uFF0C\u5426\u5219\u6309 HCMNX \u5FC5\u586B\u683C\u65B0\u5F00\uFF1B\u8F7D\u8377 JSON \u8D70 --file \u6216\u6807\u51C6\u8F93\u5165").option("--file <path>", "\u7F3A\u53E3\u8F7D\u8377 JSON\uFF08title/phenomenon/repro/expected/alternative/q_*/severity/kind/module\u2026\uFF09").option("--env <name>", "\u53D6\u73AF\u5883\u6307\u7EB9\u7528\u7684\u73AF\u5883\u522B\u540D\uFF08\u7F3A\u7701 activeEnv\uFF09").option("--fingerprint <text>", "\u76F4\u63A5\u7ED9\u6307\u7EB9\u6587\u672C\uFF08\u8BAD\u7EC3\u573A\u4ECE \u573A.yml \u53D6\u65F6\u7528\uFF09\uFF0C\u4E0D\u518D\u73B0\u67E5").option("--issuetype <name>", "\u8986\u76D6 issuetype\uFF08\u7F3A\u7701\u6309 kind \u9009 \u6545\u969C / \u9700\u6C42\uFF09").option("--assignee <user>", "\u8986\u76D6\u7ECF\u529E\u4EBA\uFF08\u7F3A\u7701\u9879\u76EE\u8D1F\u8D23\u4EBA\uFF09").option(...OUTPUT_OPT).action((opts) => jiraSubmitCommand(opts));
|
|
11767
|
+
var gap = chiron.command("gap").description("\u7F3A\u53E3\uFF1A\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u65F6\u7684\u7EDF\u4E00\u51FA\u53E3\uFF0C\u8FDB Jira\uFF08HCMNX\uFF09\u2014\u2014\u67E5\u91CD search / \u67E5\u8FDB\u5EA6 status / \u63D0\u7F3A\u53E3 submit");
|
|
11768
|
+
gap.command("search").description("\u67E5\u91CD\uFF1A\u6309\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61\u67E5 Jira\uFF0C\u5E26\u56DE\u7F16\u53F7\u4E0E\u72B6\u6001").argument("<keywords...>", "\u5173\u952E\u8BCD\uFF0C\u6BCF\u4E2A\u5355\u72EC\u67E5\u4E00\u6B21").option("--no-include-closed", "\u53EA\u67E5\u672A\u89E3\u51B3\u7684").option(...OUTPUT_OPT).action((keywords, opts) => gapSearchCommand(keywords, opts));
|
|
11769
|
+
gap.command("status").description("\u67E5\u8FDB\u5EA6\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12 \u6216\u88F8\u6570\u5B57 12\uFF09").argument("<ref>", "Jira \u5355\u53F7").option(...OUTPUT_OPT).action((ref, opts) => gapStatusCommand(ref, opts));
|
|
11770
|
+
gap.command("submit").description("\u63D0\u7F3A\u53E3\uFF1A\u5148\u67E5\u91CD\uFF08\u540C\u4E00\u7F3A\u53E3\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\uFF09\uFF0C\u5426\u5219\u6309 HCMNX \u5FC5\u586B\u683C\u65B0\u5F00\uFF1B\u8F7D\u8377 JSON \u8D70 --file \u6216\u6807\u51C6\u8F93\u5165").option("--file <path>", "\u7F3A\u53E3\u8F7D\u8377 JSON\uFF08title/phenomenon/repro/expected/alternative/q_*/severity/kind/module\u2026\uFF09").option("--env <name>", "\u53D6\u73AF\u5883\u6307\u7EB9\u7528\u7684\u73AF\u5883\u522B\u540D\uFF08\u7F3A\u7701 activeEnv\uFF09").option("--fingerprint <text>", "\u76F4\u63A5\u7ED9\u6307\u7EB9\u6587\u672C\uFF08\u8BAD\u7EC3\u573A\u4ECE \u573A.yml \u53D6\u65F6\u7528\uFF09\uFF0C\u4E0D\u518D\u73B0\u67E5").option("--issuetype <name>", "\u8986\u76D6 issuetype\uFF08\u7F3A\u7701\u6309 kind \u9009 \u6545\u969C / \u9700\u6C42\uFF09").option("--assignee <user>", "\u8986\u76D6\u7ECF\u529E\u4EBA\uFF08\u7F3A\u7701\u9879\u76EE\u8D1F\u8D23\u4EBA\uFF09").option(...OUTPUT_OPT).action((opts) => gapSubmitCommand(opts));
|
|
12247
11771
|
var recon = chiron.command("recon").description("\u722C\u4E00\u4EFD\u53EF\u5E26\u8D70\u7684\u57FA\u7EBF\uFF1A\u6A21\u578B / \u5B57\u6BB5 / \u53EA\u8BFB\u95F8 / \u4F9D\u8D56\u56FE / \u7801\u8868 / \u53EF\u5199\u6027\u753B\u50CF").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--out <dir>", "\u4EA7\u7269\u6839\u76EE\u5F55\uFF08\u4EA7\u7269\u843D\u5728 <out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09", ".").option("--state <s>", "\u53EA\u8BFB\u95F8\u7684 state\uFF08\u4EA7\u54C1\u91CC state \u4E0D\u53EF\u679A\u4E3E\uFF0C\u95F8\u7684\u8986\u76D6\u9762\u6C38\u8FDC\u662F state-scoped\uFF09").option("--model <key>", "\u5B9A\u5411\u91CD\u722C\uFF1A\u53EA\u91CD\u722C\u8FD9\u4E00\u4E2A\u6A21\u578B\uFF0C\u5176\u4F59\u6CBF\u7528\u4E0A\u4E00\u8F6E\u4EA7\u7269").option("--capabilities <s>", "\u722C\u53D6\u65F6\u58F0\u660E\u7684 capability \u4E32\uFF08\u4F1A\u968F\u56DB\u5143\u7EC4\u7559\u6863\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryReconCommand(opts));
|
|
12248
11772
|
recon.command("round").description("\u96F6\u7F51\u7EDC\uFF1A\u8BFB\u4E00\u4EFD\u5DF2\u843D\u76D8\u7684\u57FA\u7EBF\uFF0C\u5224\u65AD\u5B83\u662F\u4E0D\u662F\u4E00\u8F6E\u5B8C\u6574\u8DD1\u51FA\u6765\u7684\uFF08complete/mixed/unknown\uFF09").option("--dir <dir>", "\u4EA7\u7269\u76EE\u5F55\uFF08<out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09", ".").action(
|
|
12249
11773
|
(opts, cmd) => deliveryReconRoundCommand({
|