@hcmai/cli 0.14.3 → 0.15.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 +253 -31
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +12 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6018,6 +6018,7 @@ import {
|
|
|
6018
6018
|
formatObject as formatObject17,
|
|
6019
6019
|
fromAxiosError as fromAxiosError16,
|
|
6020
6020
|
loadGlobalConfig as loadGlobalConfig6,
|
|
6021
|
+
discoverProjectEnv as discoverProjectEnv3,
|
|
6021
6022
|
resolveEnvContext as resolveEnvContext5,
|
|
6022
6023
|
printResolvedEnvironment as printResolvedEnvironment4,
|
|
6023
6024
|
CliError as CliError20,
|
|
@@ -6116,7 +6117,7 @@ function classifyInstalledSource(id, record, catalog) {
|
|
|
6116
6117
|
return kind === "cli" ? "removed-in-cli" : "removed-upstream";
|
|
6117
6118
|
}
|
|
6118
6119
|
var SOURCE_STATUS_NOTE = {
|
|
6119
|
-
"removed-upstream": "\u4EA7\u54C1\u8FD9\u4E00\u7248\u7684\u6280\u80FD\u76EE\u5F55\u91CC\u5DF2\u7ECF\u6CA1\u6709\u5B83\u4E86
|
|
6120
|
+
"removed-upstream": "\u4EA7\u54C1\u8FD9\u4E00\u7248\u7684\u6280\u80FD\u76EE\u5F55\u91CC\u5DF2\u7ECF\u6CA1\u6709\u5B83\u4E86",
|
|
6120
6121
|
"removed-in-cli": "\u8FD9\u4E00\u7248 CLI \u4E0D\u518D\u81EA\u5E26\u5B83\uFF08\u591A\u534A\u662F\u88AB\u4EA7\u54C1\u6536\u7F16\u4E86\uFF0C\u8DD1 hcm skills list \u770B\u770B\uFF09",
|
|
6121
6122
|
"not-checked": "\u672C\u8F6E\u6CA1\u8FDE\u7F51\u6838\u5BF9\u5B83\u7684\u6765\u6E90\uFF08--source cli\uFF09\uFF0C\u5B83\u662F\u4E0D\u662F\u8FD8\u5728\u4EA7\u54C1\u76EE\u5F55\u91CC\u8FD9\u4E00\u8D9F\u4E0D\u77E5\u9053",
|
|
6122
6123
|
local: "\u672C\u5730\u6765\u6E90\uFF08install --from \u88C5\u7684\uFF09\uFF0Cupdate \u4E0D\u7BA1\u5B83\uFF1B\u8981\u66F4\u65B0\u5C31\u518D install --from \u4E00\u6B21"
|
|
@@ -6803,16 +6804,29 @@ async function resolveEndpoint(args) {
|
|
|
6803
6804
|
return args.endpoint.replace(/\/+$/, "");
|
|
6804
6805
|
}
|
|
6805
6806
|
const g = await loadGlobalConfig6();
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6807
|
+
try {
|
|
6808
|
+
const resolved = await resolveEnvContext5({ envFlag: args.env }, process.env, g);
|
|
6809
|
+
printResolvedEnvironment4(resolved);
|
|
6810
|
+
const env2 = resolved.config;
|
|
6811
|
+
if (env2?.endpoint) return env2.endpoint.replace(/\/+$/, "");
|
|
6812
|
+
} catch (e) {
|
|
6813
|
+
if (e?.code !== CliErrorCode19.ENV_NOT_FOUND) throw e;
|
|
6814
|
+
const project = await discoverProjectEnv3();
|
|
6815
|
+
const name = args.env ?? project?.config.default;
|
|
6816
|
+
const fromProject = name ? project?.config.environments[name] : void 0;
|
|
6817
|
+
if (fromProject?.endpoint) {
|
|
6818
|
+
process.stderr.write(
|
|
6819
|
+
`\u2192 ${fromProject.endpoint} \xB7 \u79DF\u6237 ${fromProject.tenant} \xB7 \u8EAB\u4EFD \u672A\u767B\u5F55\uFF08\u6765\u81EA ${project.path} \u7684 '${name}'\uFF1B\u672C\u673A\u6CA1\u6709\u5339\u914D\u7684\u69FD\uFF0C\u4F46\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u53D6\u76EE\u5F55\u4E0D\u9700\u8981\u5B83\uFF09
|
|
6820
|
+
`
|
|
6821
|
+
);
|
|
6822
|
+
return fromProject.endpoint.replace(/\/+$/, "");
|
|
6823
|
+
}
|
|
6824
|
+
throw e;
|
|
6814
6825
|
}
|
|
6815
|
-
|
|
6826
|
+
throw new CliError20({
|
|
6827
|
+
code: CliErrorCode19.MISSING_FLAG,
|
|
6828
|
+
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
|
|
6829
|
+
});
|
|
6816
6830
|
}
|
|
6817
6831
|
function normalizeEndpoint(endpoint) {
|
|
6818
6832
|
return endpoint.replace(/\/+$/, "");
|
|
@@ -7471,6 +7485,89 @@ async function readLocalSkills(localDir) {
|
|
|
7471
7485
|
}
|
|
7472
7486
|
return out;
|
|
7473
7487
|
}
|
|
7488
|
+
async function resolveSkillPath(layout, id) {
|
|
7489
|
+
assertSafeSkillId(id);
|
|
7490
|
+
const at = async (dir) => {
|
|
7491
|
+
const file = path8.join(dir, id, "SKILL.md");
|
|
7492
|
+
return await fsp2.stat(file).then(() => file).catch(() => void 0);
|
|
7493
|
+
};
|
|
7494
|
+
const inSync = await at(layout.baseDir);
|
|
7495
|
+
const inLocal = layout.localDir ? await at(layout.localDir) : void 0;
|
|
7496
|
+
if (inLocal) {
|
|
7497
|
+
return {
|
|
7498
|
+
id,
|
|
7499
|
+
file: inLocal,
|
|
7500
|
+
half: "local",
|
|
7501
|
+
references: path8.join(layout.localDir, id, "references"),
|
|
7502
|
+
...inSync ? { shadowed: inSync } : {}
|
|
7503
|
+
};
|
|
7504
|
+
}
|
|
7505
|
+
if (inSync) {
|
|
7506
|
+
return { id, file: inSync, half: "sync", references: path8.join(layout.baseDir, id, "references") };
|
|
7507
|
+
}
|
|
7508
|
+
const looked = [
|
|
7509
|
+
...layout.localDir ? [`${layout.localDir}/${id}/SKILL.md`] : [],
|
|
7510
|
+
`${layout.baseDir}/${id}/SKILL.md`
|
|
7511
|
+
];
|
|
7512
|
+
throw new CliError20({
|
|
7513
|
+
code: CliErrorCode19.INVALID_ARGUMENT,
|
|
7514
|
+
message: `\u8FD9\u4E2A\u9879\u76EE\u91CC\u6CA1\u6709\u6280\u80FD ${id}\u3002\u627E\u8FC7\uFF1A
|
|
7515
|
+
${looked.join("\n ")}
|
|
7516
|
+
\u770B\u6709\u54EA\u4E9B\uFF1Ahcm skills list --installed\uFF1B\u6CA1\u88C5\u5C31\u5148 hcm chiron skills sync\u3002`
|
|
7517
|
+
});
|
|
7518
|
+
}
|
|
7519
|
+
async function skillsPathCommand(id, args) {
|
|
7520
|
+
try {
|
|
7521
|
+
const layout = await resolveInstallLayout(args);
|
|
7522
|
+
const resolved = await resolveSkillPath(layout, id);
|
|
7523
|
+
const fmt = args.output ?? "table";
|
|
7524
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
7525
|
+
process.stdout.write(formatObject17(resolved, { format: fmt }) + "\n");
|
|
7526
|
+
process.exitCode = 0;
|
|
7527
|
+
return;
|
|
7528
|
+
}
|
|
7529
|
+
process.stderr.write(
|
|
7530
|
+
resolved.half === "local" ? `\u2192 ${SKILLS_LOCAL_SUBDIR}/ \u90A3\u4E00\u534A\uFF08\u4F60\u6539\u8FC7\u7684\u7248\u672C\uFF09` + (resolved.shadowed ? `\uFF0C\u5B83\u906E\u4F4F\u4E86 ${resolved.shadowed}
|
|
7531
|
+
` : "\n") : `\u2192 ${SKILLS_SYNC_SUBDIR}/ \u90A3\u4E00\u534A\uFF08\u4EA7\u54C1\u7EF4\u62A4\uFF0C\u540C\u6B65\u4F1A\u66F4\u65B0\u5B83\uFF09
|
|
7532
|
+
`
|
|
7533
|
+
);
|
|
7534
|
+
process.stdout.write(`${args.refs ? resolved.references : resolved.file}
|
|
7535
|
+
`);
|
|
7536
|
+
process.exitCode = 0;
|
|
7537
|
+
} catch (e) {
|
|
7538
|
+
fail6(e, args);
|
|
7539
|
+
}
|
|
7540
|
+
}
|
|
7541
|
+
async function findShadowBypassingRefs(layout, shadowedIds) {
|
|
7542
|
+
if (shadowedIds.size === 0) return [];
|
|
7543
|
+
const hits = [];
|
|
7544
|
+
let ids;
|
|
7545
|
+
try {
|
|
7546
|
+
ids = (await fsp2.readdir(layout.baseDir, { withFileTypes: true })).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
7547
|
+
} catch {
|
|
7548
|
+
return [];
|
|
7549
|
+
}
|
|
7550
|
+
for (const from of ids.sort()) {
|
|
7551
|
+
const files = [path8.join(layout.baseDir, from, "SKILL.md")];
|
|
7552
|
+
const refDir = path8.join(layout.baseDir, from, "references");
|
|
7553
|
+
try {
|
|
7554
|
+
for (const e of await fsp2.readdir(refDir, { withFileTypes: true })) {
|
|
7555
|
+
if (e.isFile()) files.push(path8.join(refDir, e.name));
|
|
7556
|
+
}
|
|
7557
|
+
} catch {
|
|
7558
|
+
}
|
|
7559
|
+
for (const file of files) {
|
|
7560
|
+
const text = await fsp2.readFile(file, "utf8").catch(() => void 0);
|
|
7561
|
+
if (text === void 0) continue;
|
|
7562
|
+
for (const to of shadowedIds) {
|
|
7563
|
+
if (new RegExp(`\\.\\./(?:\\.\\./)*${to.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`).test(text)) {
|
|
7564
|
+
hits.push({ from, to, file });
|
|
7565
|
+
}
|
|
7566
|
+
}
|
|
7567
|
+
}
|
|
7568
|
+
}
|
|
7569
|
+
return hits;
|
|
7570
|
+
}
|
|
7474
7571
|
async function syncAgentIndexes(layout, manifest2) {
|
|
7475
7572
|
if (!layout.agentsFile) return [];
|
|
7476
7573
|
const state = await readSkillsState(layout.baseDir);
|
|
@@ -7747,27 +7844,34 @@ async function planStaleReferences(state, documents, baseDir) {
|
|
|
7747
7844
|
const byKey = (a, b) => `${a.id}/${a.path}`.localeCompare(`${b.id}/${b.path}`);
|
|
7748
7845
|
return { remove: remove.sort(byKey), keptLocallyModified: keptLocallyModified.sort(byKey) };
|
|
7749
7846
|
}
|
|
7750
|
-
async function
|
|
7751
|
-
if (
|
|
7847
|
+
async function removeSkillDirs(baseDir, ids) {
|
|
7848
|
+
if (ids.length === 0) return [];
|
|
7752
7849
|
const kept = [];
|
|
7753
7850
|
const state = await readSkillsState(baseDir);
|
|
7754
|
-
for (const
|
|
7755
|
-
assertSafeSkillId(
|
|
7756
|
-
const dir = path8.join(baseDir,
|
|
7851
|
+
for (const id of ids) {
|
|
7852
|
+
assertSafeSkillId(id);
|
|
7853
|
+
const dir = path8.join(baseDir, id);
|
|
7757
7854
|
const resolved = path8.resolve(dir);
|
|
7758
|
-
if (resolved !== path8.join(path8.resolve(baseDir),
|
|
7855
|
+
if (resolved !== path8.join(path8.resolve(baseDir), id)) continue;
|
|
7759
7856
|
const hasSkillFile = await fsp2.stat(path8.join(dir, "SKILL.md")).then(() => true).catch(() => false);
|
|
7760
7857
|
const exists2 = await fsp2.stat(dir).then(() => true).catch(() => false);
|
|
7761
7858
|
if (exists2 && !hasSkillFile) {
|
|
7762
|
-
kept.push({
|
|
7763
|
-
|
|
7764
|
-
await fsp2.rm(dir, { recursive: true, force: true });
|
|
7859
|
+
kept.push({ id, kept: "\u76EE\u5F55\u91CC\u6CA1\u6709 SKILL.md\uFF0C\u50CF\u662F\u4F60\u81EA\u5DF1\u653E\u7684\u4E1C\u897F\uFF0C\u6CA1\u6709\u5220" });
|
|
7860
|
+
continue;
|
|
7765
7861
|
}
|
|
7766
|
-
if (
|
|
7862
|
+
if (exists2) await fsp2.rm(dir, { recursive: true, force: true });
|
|
7863
|
+
if (state?.skills[id] !== void 0) delete state.skills[id];
|
|
7767
7864
|
}
|
|
7768
7865
|
if (state) await writeSkillsState(baseDir, state);
|
|
7769
7866
|
return kept;
|
|
7770
7867
|
}
|
|
7868
|
+
async function removeRenamedSkills(baseDir, renamed) {
|
|
7869
|
+
const kept = await removeSkillDirs(baseDir, renamed.map((r) => r.from));
|
|
7870
|
+
return kept.map((k) => ({ from: k.id, kept: k.kept }));
|
|
7871
|
+
}
|
|
7872
|
+
async function removeOrphanSkills(baseDir, ids) {
|
|
7873
|
+
return await removeSkillDirs(baseDir, ids);
|
|
7874
|
+
}
|
|
7771
7875
|
async function writeSkillDocuments(documents, baseDir, removals = []) {
|
|
7772
7876
|
const staged = [];
|
|
7773
7877
|
const removed = [];
|
|
@@ -7834,9 +7938,69 @@ async function recordInstalled(baseDir, documents, meta2) {
|
|
|
7834
7938
|
await writeSkillsState(baseDir, state);
|
|
7835
7939
|
return state;
|
|
7836
7940
|
}
|
|
7941
|
+
function parsePruneMax(raw) {
|
|
7942
|
+
if (raw === void 0) return void 0;
|
|
7943
|
+
const text = typeof raw === "number" ? void 0 : raw.trim();
|
|
7944
|
+
const n = text === void 0 ? raw : text === "" ? Number.NaN : Number(text);
|
|
7945
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
7946
|
+
throw new CliError20({
|
|
7947
|
+
code: CliErrorCode19.INVALID_ARGUMENT,
|
|
7948
|
+
message: `--prune-max \u8981\u4E00\u4E2A\u975E\u8D1F\u6574\u6570\uFF0C\u6536\u5230 ${JSON.stringify(raw)}\u30020 = \u8FD9\u4E00\u8D9F\u4E00\u4EFD\u90FD\u522B\u6E05\uFF1B\u4E0D\u7ED9\u8FD9\u4E2A\u53C2\u6570\u65F6\u4E0A\u9650\u662F\u300C${PRUNE_DEFAULT_MAX} \u4E0E\u5728\u518C\u4EFD\u6570\u4E00\u534A\u53D6\u5C0F\u300D\u3002`
|
|
7949
|
+
});
|
|
7950
|
+
}
|
|
7951
|
+
return n;
|
|
7952
|
+
}
|
|
7837
7953
|
function invalid(message) {
|
|
7838
7954
|
return new CliError20({ code: CliErrorCode19.INVALID_ARGUMENT, message });
|
|
7839
7955
|
}
|
|
7956
|
+
var PRUNE_DEFAULT_MAX = 5;
|
|
7957
|
+
var PRUNE_MAX_SHARE = 0.5;
|
|
7958
|
+
function orphanPruneLimit(trackedCount, explicitMax) {
|
|
7959
|
+
if (explicitMax !== void 0) return explicitMax;
|
|
7960
|
+
return Math.min(PRUNE_DEFAULT_MAX, Math.floor(trackedCount * PRUNE_MAX_SHARE));
|
|
7961
|
+
}
|
|
7962
|
+
var PRUNABLE_STATUS = /* @__PURE__ */ new Set(["removed-upstream", "removed-in-cli"]);
|
|
7963
|
+
async function planOrphanPrune(options) {
|
|
7964
|
+
const { entries, state, baseDir, liveMarkdown, trackedCount, max } = options;
|
|
7965
|
+
const remove = [];
|
|
7966
|
+
const kept = [];
|
|
7967
|
+
for (const entry of entries) {
|
|
7968
|
+
if (!PRUNABLE_STATUS.has(entry.status)) continue;
|
|
7969
|
+
const id = entry.id;
|
|
7970
|
+
const record = state.skills[id];
|
|
7971
|
+
const onDisk = await readInstalled(baseDir, id);
|
|
7972
|
+
if (onDisk !== void 0 && record !== void 0) {
|
|
7973
|
+
let edited = sha2562(onDisk) !== record.sha256;
|
|
7974
|
+
for (const [refPath, recordedSha] of Object.entries(record.references ?? {})) {
|
|
7975
|
+
const installed = await readInstalledReference(baseDir, id, refPath);
|
|
7976
|
+
if (installed !== void 0 && sha2562(installed) !== recordedSha) edited = true;
|
|
7977
|
+
}
|
|
7978
|
+
if (edited) {
|
|
7979
|
+
kept.push({
|
|
7980
|
+
id,
|
|
7981
|
+
why: `\u672C\u5730\u6539\u8FC7\uFF0C\u6CA1\u6709\u5220\u3002\u4E0A\u6E38\u5DF2\u7ECF\u4E0D\u53D1\u5B83\u4E86\u2014\u2014\u76D8\u4E0A\u8FD9\u4EFD\u5C31\u662F\u552F\u4E00\u4E00\u4EFD\uFF0C\u60F3\u957F\u671F\u7559\u4F4F\u5C31\u632A\u5230 ${SKILLS_LOCAL_SUBDIR}/${id}/\uFF08\u90A3\u4E00\u4FA7 CLI \u4ECE\u4E0D\u5199\uFF09`
|
|
7982
|
+
});
|
|
7983
|
+
continue;
|
|
7984
|
+
}
|
|
7985
|
+
}
|
|
7986
|
+
const referrers = [...liveMarkdown].filter(([otherId, markdown]) => otherId !== id && /* 相对引用与同级链接两种形态 */
|
|
7987
|
+
(markdown.includes(`../${id}/`) || markdown.includes(`](${id}/`))).map(([otherId]) => otherId);
|
|
7988
|
+
if (referrers.length > 0) {
|
|
7989
|
+
kept.push({
|
|
7990
|
+
id,
|
|
7991
|
+
why: `\u8FD8\u6709 ${referrers.length} \u4EFD\u6D3B\u7740\u7684\u6280\u80FD\u5728\u5F15\u7528\u5B83\uFF08${referrers.join("\u3001")}\uFF09\uFF0C\u5220\u4E86\u5C31\u662F\u628A\u94FE\u63A5\u6307\u5411\u7A7A\u6C14`
|
|
7992
|
+
});
|
|
7993
|
+
continue;
|
|
7994
|
+
}
|
|
7995
|
+
remove.push({ id, status: entry.status });
|
|
7996
|
+
}
|
|
7997
|
+
const limit = orphanPruneLimit(trackedCount, max);
|
|
7998
|
+
if (remove.length > limit) {
|
|
7999
|
+
const why = max !== void 0 ? `\u4E00\u8D9F\u8981\u6E05 ${remove.length} \u4EFD\uFF0C\u8D85\u8FC7\u4F60\u7ED9\u7684\u4E0A\u9650 ${limit} \u4EFD` : limit < PRUNE_DEFAULT_MAX ? `\u4E00\u8D9F\u8981\u6E05 ${remove.length} \u4EFD\uFF0C\u8D85\u8FC7\u5728\u518C ${trackedCount} \u4EFD\u7684\u4E00\u534A\uFF08\u4E0A\u9650 ${limit} \u4EFD\uFF09` : `\u4E00\u8D9F\u8981\u6E05 ${remove.length} \u4EFD\uFF0C\u8D85\u8FC7\u4E0A\u9650 ${limit} \u4EFD`;
|
|
8000
|
+
return { remove: [], kept, refused: { count: remove.length, limit, why } };
|
|
8001
|
+
}
|
|
8002
|
+
return { remove, kept };
|
|
8003
|
+
}
|
|
7840
8004
|
async function readInstalled(baseDir, id) {
|
|
7841
8005
|
try {
|
|
7842
8006
|
return await fsp2.readFile(path8.join(baseDir, id, "SKILL.md"), "utf8");
|
|
@@ -7981,7 +8145,21 @@ async function planSkillUpdate(options) {
|
|
|
7981
8145
|
});
|
|
7982
8146
|
}
|
|
7983
8147
|
entries.sort((a, b) => a.id.localeCompare(b.id));
|
|
7984
|
-
|
|
8148
|
+
const liveMarkdown = /* @__PURE__ */ new Map();
|
|
8149
|
+
for (const id of closure.keys()) {
|
|
8150
|
+
const pending = documents.find((d) => d.id === id);
|
|
8151
|
+
const markdown = pending?.markdown ?? await readInstalled(baseDir, id);
|
|
8152
|
+
if (markdown !== void 0) liveMarkdown.set(id, markdown);
|
|
8153
|
+
}
|
|
8154
|
+
const prune = await planOrphanPrune({
|
|
8155
|
+
entries,
|
|
8156
|
+
state,
|
|
8157
|
+
baseDir,
|
|
8158
|
+
liveMarkdown,
|
|
8159
|
+
trackedCount: Object.keys(state.skills).length,
|
|
8160
|
+
max: options.pruneMax
|
|
8161
|
+
});
|
|
8162
|
+
return { entries, documents, renamed: renamedPairs, prune };
|
|
7985
8163
|
}
|
|
7986
8164
|
var UPDATE_STATUS_LABEL = {
|
|
7987
8165
|
updated: "\u5DF2\u66F4\u65B0",
|
|
@@ -8034,6 +8212,7 @@ async function skillsUpdateCommand(args) {
|
|
|
8034
8212
|
baseDir: layout.baseDir,
|
|
8035
8213
|
force: Boolean(args.force),
|
|
8036
8214
|
all,
|
|
8215
|
+
pruneMax: parsePruneMax(args.pruneMax),
|
|
8037
8216
|
fetchDocument: (skill) => fetchSkillDocument(http, skill, endpoint, base)
|
|
8038
8217
|
});
|
|
8039
8218
|
const stale = await planStaleReferences(state, plan.documents, layout.baseDir);
|
|
@@ -8052,6 +8231,7 @@ async function skillsUpdateCommand(args) {
|
|
|
8052
8231
|
`);
|
|
8053
8232
|
}
|
|
8054
8233
|
}
|
|
8234
|
+
const pruneKept = !args.check && plan.prune.remove.length > 0 ? await removeOrphanSkills(layout.baseDir, plan.prune.remove.map((r) => r.id)) : [];
|
|
8055
8235
|
const agentIndexes = !args.check && layout.agentsFile ? await syncAgentIndexes(layout, manifest2) : [];
|
|
8056
8236
|
const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
|
|
8057
8237
|
const fmt = args.output ?? "table";
|
|
@@ -8069,6 +8249,11 @@ async function skillsUpdateCommand(args) {
|
|
|
8069
8249
|
},
|
|
8070
8250
|
cliVersion: CLI_VERSION,
|
|
8071
8251
|
staleReferences: stale,
|
|
8252
|
+
prune: {
|
|
8253
|
+
removed: plan.prune.remove.map((r) => r.id),
|
|
8254
|
+
kept: plan.prune.kept,
|
|
8255
|
+
refused: plan.prune.refused
|
|
8256
|
+
},
|
|
8072
8257
|
entries: plan.entries
|
|
8073
8258
|
}, { format: fmt }) + "\n");
|
|
8074
8259
|
process.exitCode = 0;
|
|
@@ -8091,8 +8276,10 @@ async function skillsUpdateCommand(args) {
|
|
|
8091
8276
|
const notChecked = plan.entries.filter((e) => e.status === "not-checked").length;
|
|
8092
8277
|
const tail = [
|
|
8093
8278
|
skipped > 0 ? `${skipped} \u4E2A\u672C\u5730\u6539\u8FC7\u88AB\u8DF3\u8FC7\uFF08--force \u8986\u76D6\uFF09` : "",
|
|
8094
|
-
removed > 0 ? `${removed} \u4E2A\u4EA7\u54C1\u5DF2\u79FB\u9664
|
|
8095
|
-
removedInCli > 0 ? `${removedInCli} \u4E2A\u8FD9\u4E00\u7248 CLI \u4E0D\u518D\u81EA\u5E26
|
|
8279
|
+
removed > 0 ? `${removed} \u4E2A\u4EA7\u54C1\u5DF2\u79FB\u9664` : "",
|
|
8280
|
+
removedInCli > 0 ? `${removedInCli} \u4E2A\u8FD9\u4E00\u7248 CLI \u4E0D\u518D\u81EA\u5E26` : "",
|
|
8281
|
+
plan.prune.remove.length > 0 ? `\u5176\u4E2D ${plan.prune.remove.length} \u4EFD${args.check ? "\u4F1A\u88AB" : "\u5DF2"}\u6E05\u6389` : "",
|
|
8282
|
+
plan.prune.kept.length + pruneKept.length > 0 ? `${plan.prune.kept.length + pruneKept.length} \u4EFD\u6CA1\u6E05\uFF08\u4E0A\u9762\u9010\u4E2A\u8BF4\u4E86\u4E3A\u4EC0\u4E48\uFF09` : "",
|
|
8096
8283
|
notChecked > 0 ? `${notChecked} \u4E2A\u672C\u8F6E\u672A\u6838\uFF08\u90A3\u4E00\u534A\u8FD9\u8D9F\u6CA1\u770B\uFF09` : ""
|
|
8097
8284
|
].filter(Boolean).join("\uFF0C");
|
|
8098
8285
|
const cliCount = plan.entries.filter(
|
|
@@ -8116,13 +8303,47 @@ async function skillsUpdateCommand(args) {
|
|
|
8116
8303
|
`
|
|
8117
8304
|
);
|
|
8118
8305
|
}
|
|
8306
|
+
if (plan.prune.remove.length > 0) {
|
|
8307
|
+
process.stdout.write(
|
|
8308
|
+
` ${args.check ? "\u4F1A\u6E05\u6389" : "\u5DF2\u6E05\u6389"} ${plan.prune.remove.length} \u4EFD\u4E0A\u6E38\u4E0D\u518D\u53D1\u7684\u6280\u80FD\uFF08${plan.prune.remove.map((r) => r.id).join("\u3001")}\uFF09
|
|
8309
|
+
`
|
|
8310
|
+
);
|
|
8311
|
+
}
|
|
8312
|
+
for (const k of plan.prune.kept) {
|
|
8313
|
+
process.stdout.write(` ! ${k.id} \u6CA1\u6E05\uFF1A${k.why}
|
|
8314
|
+
`);
|
|
8315
|
+
}
|
|
8316
|
+
for (const k of pruneKept) {
|
|
8317
|
+
process.stdout.write(` ! ${k.id} \u6CA1\u6E05\uFF1A${k.kept}
|
|
8318
|
+
`);
|
|
8319
|
+
}
|
|
8320
|
+
if (plan.prune.refused) {
|
|
8321
|
+
process.stdout.write(
|
|
8322
|
+
` \u26A0\uFE0F \u5B64\u513F\u6E05\u7406\u6574\u6279\u62D2\u7EDD\uFF1A${plan.prune.refused.why}\u3002\u8FD9\u4E0D\u50CF\u6280\u80FD\u9000\u5F79\uFF0C\u50CF\u76EE\u5F55\u53D6\u6B8B\u4E86\u2014\u2014
|
|
8323
|
+
\u5148\u8DD1 hcm skills list \u770B\u770B\u76EE\u5F55\u662F\u4E0D\u662F\u5168\u7684\uFF1B\u786E\u8BA4\u65E0\u8BEF\u518D\u8DD1 hcm chiron skills sync --prune-max ${plan.prune.refused.count}
|
|
8324
|
+
`
|
|
8325
|
+
);
|
|
8326
|
+
}
|
|
8327
|
+
{
|
|
8328
|
+
const shadowedIds = new Set(
|
|
8329
|
+
(await readLocalSkills(layout.localDir)).map((x) => x.id).filter((id) => state.skills[id] !== void 0)
|
|
8330
|
+
);
|
|
8331
|
+
const bypass = await findShadowBypassingRefs(layout, shadowedIds);
|
|
8332
|
+
for (const hit of bypass) {
|
|
8333
|
+
process.stdout.write(
|
|
8334
|
+
` \u26A0\uFE0F ${path8.relative(layout.baseDir, hit.file)} \u91CC\u7684 ../${hit.to}/ \u7ED5\u8FC7\u4E86\u906E\u853D\uFF1A\u4F60\u5728 ${SKILLS_LOCAL_SUBDIR}/${hit.to}/ \u6539\u8FC7\u5B83\uFF0C\u4F46\u987A\u7740\u8FD9\u6761\u76F8\u5BF9\u8DEF\u5F84\u8BFB\u5230\u7684\u662F ${SKILLS_SYNC_SUBDIR}/ \u91CC\u7684\u4EA7\u54C1\u539F\u7248
|
|
8335
|
+
\u6B63\u6587\u6539\u6210\u6309 id \u53D6\u5740\u5C31\u4E0D\u4F1A\u518D\u9519\uFF1Ahcm chiron skills path ${hit.to}
|
|
8336
|
+
`
|
|
8337
|
+
);
|
|
8338
|
+
}
|
|
8339
|
+
}
|
|
8119
8340
|
if (stale.keptLocallyModified.length > 0) {
|
|
8120
8341
|
process.stdout.write(
|
|
8121
8342
|
` ${stale.keptLocallyModified.length} \u4E2A\u4EA7\u54C1\u5DF2\u64A4\u6389\u4F46\u672C\u5730\u6539\u8FC7\u7684\u53C2\u8003\u6587\u4EF6\u4FDD\u7559\u4E86\uFF08${stale.keptLocallyModified.map((r) => `${r.id}/references/${r.path}`).join("\u3001")}\uFF09
|
|
8122
8343
|
`
|
|
8123
8344
|
);
|
|
8124
8345
|
}
|
|
8125
|
-
if (changed.length === 0 && skipped === 0 && removed === 0) {
|
|
8346
|
+
if (changed.length === 0 && skipped === 0 && removed === 0 && removedInCli === 0 && plan.prune.remove.length === 0) {
|
|
8126
8347
|
process.stdout.write(args.check ? " \u5168\u90E8\u5DF2\u662F\u6700\u65B0\uFF08--check \u53EA\u770B\u4E0D\u52A8\uFF09\n" : " \u5168\u90E8\u5DF2\u662F\u6700\u65B0\uFF0C\u6CA1\u6709\u6539\u52A8\n");
|
|
8127
8348
|
} else {
|
|
8128
8349
|
const head = args.check ? changed.length > 0 ? `\u6709 ${changed.length} \u4E2A\u53EF\u4EE5\u66F4\u65B0\uFF0C\u53BB\u6389 --check \u5C31\u4F1A\u5199\u5165` : "\u6CA1\u6709\u53EF\u5199\u5165\u7684\u66F4\u65B0" : changed.length > 0 ? `\u5DF2\u66F4\u65B0 ${changed.length} \u4E2A` : "\u6CA1\u6709\u5199\u5165\u4EFB\u4F55\u6539\u52A8";
|
|
@@ -8241,7 +8462,7 @@ async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
|
|
|
8241
8462
|
// src/commands/tenant.ts
|
|
8242
8463
|
import {
|
|
8243
8464
|
bootstrapTenant,
|
|
8244
|
-
discoverProjectEnv as
|
|
8465
|
+
discoverProjectEnv as discoverProjectEnv4,
|
|
8245
8466
|
assertDangerWrite as assertDangerWrite3,
|
|
8246
8467
|
normalizeOrigin as normalizeOrigin4,
|
|
8247
8468
|
createHttpClient as createHttpClient3,
|
|
@@ -8307,7 +8528,7 @@ async function tenantBootstrapCommand(args) {
|
|
|
8307
8528
|
});
|
|
8308
8529
|
}
|
|
8309
8530
|
const endpoint = await resolveEndpoint2(args);
|
|
8310
|
-
const project = await
|
|
8531
|
+
const project = await discoverProjectEnv4();
|
|
8311
8532
|
const protectedNames = project ? Object.entries(project.config.environments).filter(([, candidate]) => candidate.danger && candidate.endpoint === normalizeOrigin4(endpoint)).map(([name]) => name) : [];
|
|
8312
8533
|
assertDangerWrite3({ name: protectedNames.join(", "), danger: protectedNames.length > 0, allowDanger: args.allowDanger }, "\u5F00\u901A\u79DF\u6237");
|
|
8313
8534
|
if (args.endpoint) process.stderr.write(`\u2192 ${endpoint} \xB7 \u79DF\u6237 ${args.tenantId} \xB7 \u8EAB\u4EFD bootstrap key\uFF08\u6765\u81EA --endpoint\uFF09
|
|
@@ -10385,7 +10606,7 @@ import {
|
|
|
10385
10606
|
isTempEnv as isTempEnv3,
|
|
10386
10607
|
listIdentities as listIdentities5,
|
|
10387
10608
|
loadEnv as loadEnv5,
|
|
10388
|
-
discoverProjectEnv as
|
|
10609
|
+
discoverProjectEnv as discoverProjectEnv5,
|
|
10389
10610
|
findEnvByEndpoint as findEnvByEndpoint4,
|
|
10390
10611
|
normalizeOrigin as normalizeOrigin5,
|
|
10391
10612
|
loadGlobalConfig as loadGlobalConfig9
|
|
@@ -10436,7 +10657,7 @@ async function resolveInitEnv(root, args, deps) {
|
|
|
10436
10657
|
identity: args.env ? await identityOf(args.env) : null
|
|
10437
10658
|
};
|
|
10438
10659
|
}
|
|
10439
|
-
const existing = await
|
|
10660
|
+
const existing = await discoverProjectEnv5(root);
|
|
10440
10661
|
if (existing && path10.dirname(existing.path) === path10.resolve(root)) {
|
|
10441
10662
|
const name2 = args.env ?? existing.config.default;
|
|
10442
10663
|
const env2 = existing.config.environments[name2];
|
|
@@ -11124,7 +11345,7 @@ import {
|
|
|
11124
11345
|
AUTH_INFO_PATH as AUTH_INFO_PATH2,
|
|
11125
11346
|
CliError as CliError26,
|
|
11126
11347
|
CliErrorCode as CliErrorCode24,
|
|
11127
|
-
discoverProjectEnv as
|
|
11348
|
+
discoverProjectEnv as discoverProjectEnv6,
|
|
11128
11349
|
ENV_FILE as ENV_FILE2,
|
|
11129
11350
|
findEnvByEndpoint as findEnvByEndpoint5,
|
|
11130
11351
|
formatObject as formatObject25,
|
|
@@ -11265,7 +11486,7 @@ async function runChironEnv(action, args = {}) {
|
|
|
11265
11486
|
invalid2(`\u672A\u77E5\u8F93\u51FA\u683C\u5F0F '${args.output}'\uFF0C\u914D\u7F6E\u672A\u5199\u5165\u3002`, "\u4F7F\u7528 --output table\u3001json \u6216 yaml");
|
|
11266
11487
|
}
|
|
11267
11488
|
const root = path12.resolve(args.project ?? ".");
|
|
11268
|
-
const discovered = await
|
|
11489
|
+
const discovered = await discoverProjectEnv6(root);
|
|
11269
11490
|
const file = discovered?.path ?? path12.join(root, ENV_FILE2);
|
|
11270
11491
|
if (!discovered && action !== "add") invalid2(`\u6CA1\u6709\u627E\u5230 ${file}\u3002`, "\u8FDB\u5165\u987E\u95EE\u9879\u76EE\uFF0C\u6216\u8FD0\u884C hcm chiron env add <\u540D\u5B57> --endpoint <URL> --frontend <URL> --tenant <\u79DF\u6237>");
|
|
11271
11492
|
const original = discovered ? await fs11.readFile(file, "utf8") : null;
|
|
@@ -13570,7 +13791,8 @@ chiron.command("doctor").description(
|
|
|
13570
13791
|
"\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 clone \u4E86\u6CA1 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355"
|
|
13571
13792
|
).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("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
|
|
13572
13793
|
var chironSkills = chiron.command("skills").description("\u8FD9\u4E2A\u9879\u76EE\u4ED3\u7684\u6280\u80FD\uFF1A\u8DDF\u76EE\u6807\u73AF\u5883\u5BF9\u9F50");
|
|
13573
|
-
chironSkills.command("sync").description("\u8BA9\u8FD9\u4E2A\u4ED3\u7684\u6280\u80FD\u8DDF\u76EE\u6807\u73AF\u5883\u5BF9\u9F50\uFF1A\u7B2C\u4E00\u6B21\u5C31\u88C5\u9F50\uFF0C\u4E4B\u540E\u6309\u4EA7\u54C1\u5F53\u524D\u5168\u96C6\u5BF9\u8D26\u3002\u5E42\u7B49\uFF0C\u4EA7\u54C1\u5347\u7EA7\u540E\u8DD1\u5B83").option("--only <id...>", "\u53EA\u8981\u8FD9\u51E0\u4E2A\u6280\u80FD\uFF08\u8FDE\u540C requires \u524D\u7F6E\uFF09\uFF0C\u4E0D\u8BA2\u9605\u5168\u96C6\uFF1B\u8BAD\u7EC3\u573A blind \u6863\u7528").option("--check", "\u53EA\u770B\u4F1A\u53D8\u4EC0\u4E48\uFF0C\u4E0D\u5199\u76D8").option("--target <agent>", "claude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + Agent \u7D22\u5F15\uFF09| auto", "auto").option("--global", "\u540C\u6B65\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u540C\u6B65\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u53D6\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--force", "\u8FDE\u672C\u5730\u6539\u8FC7\u7684\u6280\u80FD\u4E00\u8D77\u8986\u76D6\u6210\u4EA7\u54C1\u8FD9\u4E00\u7248").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216\u5B89\u88C5\u65F6\u8BB0\u5F55\u7684\u5730\u5740\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => skillsSyncCommand(opts));
|
|
13794
|
+
chironSkills.command("sync").description("\u8BA9\u8FD9\u4E2A\u4ED3\u7684\u6280\u80FD\u8DDF\u76EE\u6807\u73AF\u5883\u5BF9\u9F50\uFF1A\u7B2C\u4E00\u6B21\u5C31\u88C5\u9F50\uFF0C\u4E4B\u540E\u6309\u4EA7\u54C1\u5F53\u524D\u5168\u96C6\u5BF9\u8D26\u3002\u5E42\u7B49\uFF0C\u4EA7\u54C1\u5347\u7EA7\u540E\u8DD1\u5B83").option("--only <id...>", "\u53EA\u8981\u8FD9\u51E0\u4E2A\u6280\u80FD\uFF08\u8FDE\u540C requires \u524D\u7F6E\uFF09\uFF0C\u4E0D\u8BA2\u9605\u5168\u96C6\uFF1B\u8BAD\u7EC3\u573A blind \u6863\u7528").option("--check", "\u53EA\u770B\u4F1A\u53D8\u4EC0\u4E48\uFF0C\u4E0D\u5199\u76D8").option("--target <agent>", "claude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + Agent \u7D22\u5F15\uFF09| auto", "auto").option("--global", "\u540C\u6B65\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u540C\u6B65\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u53D6\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--force", "\u8FDE\u672C\u5730\u6539\u8FC7\u7684\u6280\u80FD\u4E00\u8D77\u8986\u76D6\u6210\u4EA7\u54C1\u8FD9\u4E00\u7248").option("--prune-max <n>", `\u4E00\u8D9F\u6700\u591A\u6E05\u51E0\u4EFD\u4E0A\u6E38\u4E0D\u518D\u53D1\u7684\u6280\u80FD\uFF0C\u8D85\u4E86\u6574\u6279\u62D2\u7EDD\uFF1B0 = \u4E00\u4EFD\u90FD\u522B\u6E05\uFF08\u7F3A\u7701 ${PRUNE_DEFAULT_MAX}\uFF09`).option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216\u5B89\u88C5\u65F6\u8BB0\u5F55\u7684\u5730\u5740\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => skillsSyncCommand(opts));
|
|
13795
|
+
chironSkills.command("path <id>").description("\u6253\u5370\u8FD9\u4E2A id \u5728\u672C\u9879\u76EE\u5B9E\u9645\u751F\u6548\u90A3\u4E00\u4EFD\u7684\u8DEF\u5F84\uFF08local/ \u906E\u853D sync/\uFF09\uFF0C\u4F9B\u6280\u80FD\u6B63\u6587\u5F15\u7528\uFF0C\u514D\u5F97\u6B63\u6587\u5199\u6B7B\u76EE\u5F55\u5C42\u6570").option("--refs", "\u8981 references/ \u7684\u843D\u70B9\uFF0C\u4E0D\u662F SKILL.md").option("--target <agent>", "claude | codex | auto", "auto").option("--global", "\u770B\u7528\u6237\u7EA7\u76EE\u5F55").option("--dir <path>", "\u770B\u6307\u5B9A\u76EE\u5F55").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((id, opts) => skillsPathCommand(id, opts));
|
|
13574
13796
|
var OUTPUT_OPT = ["--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table"];
|
|
13575
13797
|
var projectEnv = chiron.command("env").description("\u7EF4\u62A4\u672C\u9879\u76EE env.yaml\uFF1B\u672C\u673A\u69FD\u7531 hcm env \u7BA1\u7406");
|
|
13576
13798
|
projectEnv.command("list").description("\u5217\u51FA\u9879\u76EE\u73AF\u5883\u3001\u9ED8\u8BA4\u9879\u548C\u672C\u673A\u8EAB\u4EFD\u53EF\u7528\u6027\uFF08\u63A2\u4E0D\u5230\u65F6\u6807\u672A\u9A8C\u8BC1\uFF09").option("--project <dir>", "\u9879\u76EE\u76EE\u5F55\uFF08\u5411\u4E0A\u5BFB\u627E env.yaml\uFF09", ".").option(...OUTPUT_OPT).action((opts) => chironEnvCommand("list", opts));
|