@hcmai/cli 0.4.21 → 0.4.23
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 +1008 -275
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +33 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function exitWithError(err) {
|
|
|
28
28
|
}
|
|
29
29
|
function exitOk(stdout) {
|
|
30
30
|
if (stdout) process.stdout.write(stdout + "\n");
|
|
31
|
-
process.
|
|
31
|
+
process.exitCode = 0;
|
|
32
32
|
}
|
|
33
33
|
var init_exit = __esm({
|
|
34
34
|
"src/utils/exit.ts"() {
|
|
@@ -523,8 +523,8 @@ var init_TerminalRenderer = __esm({
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
/** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
|
|
526
|
-
originLine(
|
|
527
|
-
const segs =
|
|
526
|
+
originLine(path17) {
|
|
527
|
+
const segs = path17.split(".").filter(Boolean);
|
|
528
528
|
if (segs.length < 2) return "";
|
|
529
529
|
const names = segs.map((k) => agentDisplayName(k));
|
|
530
530
|
return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
|
|
@@ -1706,8 +1706,8 @@ function agentLabel(agentId) {
|
|
|
1706
1706
|
if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
|
|
1707
1707
|
return agentDisplayName(agentId);
|
|
1708
1708
|
}
|
|
1709
|
-
function originLine(
|
|
1710
|
-
const segs = (
|
|
1709
|
+
function originLine(path17) {
|
|
1710
|
+
const segs = (path17 ?? "").split(".").filter(Boolean);
|
|
1711
1711
|
if (segs.length < 2) return null;
|
|
1712
1712
|
return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
|
|
1713
1713
|
}
|
|
@@ -1880,7 +1880,8 @@ async function runInkRepl(args) {
|
|
|
1880
1880
|
);
|
|
1881
1881
|
await waitUntilExit();
|
|
1882
1882
|
await ws.close();
|
|
1883
|
-
process.
|
|
1883
|
+
process.exitCode = 0;
|
|
1884
|
+
return;
|
|
1884
1885
|
} catch (e) {
|
|
1885
1886
|
exitWithError(e);
|
|
1886
1887
|
}
|
|
@@ -2277,10 +2278,17 @@ async function loginCommand(args) {
|
|
|
2277
2278
|
};
|
|
2278
2279
|
await saveIdentity(idName, identityMeta);
|
|
2279
2280
|
if (principal?.tenantId && String(principal.tenantId) !== String(tenantId)) {
|
|
2280
|
-
|
|
2281
|
-
|
|
2281
|
+
if (args.tenant) {
|
|
2282
|
+
process.stderr.write(
|
|
2283
|
+
`[hcm] WARNING: \u8BF7\u6C42\u7684\u79DF\u6237\u662F ${tenantId}\uFF0C\u4F46 token \u5B9E\u9645\u5F52\u5C5E\u79DF\u6237 ${principal.tenantId}\u3002\u540E\u7EED\u547D\u4EE4\u6309 ${principal.tenantId} \u6267\u884C\u3002
|
|
2282
2284
|
`
|
|
2283
|
-
|
|
2285
|
+
);
|
|
2286
|
+
} else {
|
|
2287
|
+
envCfg.tenantId = String(principal.tenantId);
|
|
2288
|
+
await saveEnv(envName, envCfg);
|
|
2289
|
+
process.stderr.write(`[hcm] env ${envName} \u7684\u79DF\u6237\u5DF2\u8BB0\u4E3A ${principal.tenantId}\uFF08token \u5F52\u5C5E\uFF09\u3002
|
|
2290
|
+
`);
|
|
2291
|
+
}
|
|
2284
2292
|
}
|
|
2285
2293
|
const shouldActivate = args.activate !== false;
|
|
2286
2294
|
if (shouldActivate && envCfg.defaultIdentity !== idName) {
|
|
@@ -2292,7 +2300,7 @@ async function loginCommand(args) {
|
|
|
2292
2300
|
gl.activeEnv = envName;
|
|
2293
2301
|
await saveGlobalConfig(gl);
|
|
2294
2302
|
}
|
|
2295
|
-
exitOk(
|
|
2303
|
+
return exitOk(
|
|
2296
2304
|
`\u2705 logged in (env=${envName}, identity=${idName}, scheme=${scheme}, ${describePrincipal(principal)}, scopes=${scopes.join(" ")})`
|
|
2297
2305
|
);
|
|
2298
2306
|
} catch (e) {
|
|
@@ -2319,8 +2327,7 @@ async function logoutCommand(args) {
|
|
|
2319
2327
|
const envCfg = await loadEnv(envName).catch(() => null);
|
|
2320
2328
|
const dflt = envCfg?.defaultIdentity;
|
|
2321
2329
|
if (!dflt) {
|
|
2322
|
-
exitOk("(no active identity to log out)");
|
|
2323
|
-
return;
|
|
2330
|
+
return exitOk("(no active identity to log out)");
|
|
2324
2331
|
}
|
|
2325
2332
|
target = dflt;
|
|
2326
2333
|
}
|
|
@@ -2329,9 +2336,9 @@ async function logoutCommand(args) {
|
|
|
2329
2336
|
const revoked = await revokeOnServer(store, envName ?? idMeta.env);
|
|
2330
2337
|
await store.clear();
|
|
2331
2338
|
if (revoked) {
|
|
2332
|
-
exitOk(`\u2705 logged out (identity: ${target})`);
|
|
2339
|
+
return exitOk(`\u2705 logged out (identity: ${target})`);
|
|
2333
2340
|
} else {
|
|
2334
|
-
exitOk(
|
|
2341
|
+
return exitOk(
|
|
2335
2342
|
`\u26A0\uFE0F \u5DF2\u6E05\u9664\u672C\u5730\u51ED\u636E (identity: ${target})\uFF0C\u4F46\u670D\u52A1\u7AEF\u540A\u9500\u672A\u786E\u8BA4\u2014\u2014\u8BE5 token \u53EF\u80FD\u4ECD\u7136\u6709\u6548\u76F4\u81F3\u81EA\u7136\u8FC7\u671F\u3002\u82E5\u51ED\u636E\u53EF\u80FD\u5DF2\u6CC4\u6F0F\uFF0C\u8BF7\u6539\u5BC6\u4EE5\u540A\u9500\u5168\u90E8\u4F1A\u8BDD\u3002`
|
|
2336
2343
|
);
|
|
2337
2344
|
}
|
|
@@ -2405,8 +2412,7 @@ async function envList() {
|
|
|
2405
2412
|
const envs = await listEnvs();
|
|
2406
2413
|
const g = await loadGlobalConfig2();
|
|
2407
2414
|
if (envs.length === 0) {
|
|
2408
|
-
exitOk("(no envs; run `hcm env add <name> --endpoint <url>`)");
|
|
2409
|
-
return;
|
|
2415
|
+
return exitOk("(no envs; run `hcm env add <name> --endpoint <url>`)");
|
|
2410
2416
|
}
|
|
2411
2417
|
const rows = await Promise.all(
|
|
2412
2418
|
envs.map(async (name) => {
|
|
@@ -2421,7 +2427,7 @@ async function envList() {
|
|
|
2421
2427
|
};
|
|
2422
2428
|
})
|
|
2423
2429
|
);
|
|
2424
|
-
exitOk(formatTable(rows));
|
|
2430
|
+
return exitOk(formatTable(rows));
|
|
2425
2431
|
} catch (e) {
|
|
2426
2432
|
exitWithError(e);
|
|
2427
2433
|
}
|
|
@@ -2431,12 +2437,11 @@ async function envCurrent() {
|
|
|
2431
2437
|
const g = await loadGlobalConfig2();
|
|
2432
2438
|
const cfg = await loadEnv2(g.activeEnv).catch(() => null);
|
|
2433
2439
|
if (!cfg) {
|
|
2434
|
-
exitOk("(no active env; run `hcm env add <name> --endpoint <url>`)");
|
|
2435
|
-
return;
|
|
2440
|
+
return exitOk("(no active env; run `hcm env add <name> --endpoint <url>`)");
|
|
2436
2441
|
}
|
|
2437
2442
|
const idName = cfg.defaultIdentity ?? "(none)";
|
|
2438
2443
|
const frontend = cfg.frontend ? ` frontend=${cfg.frontend}` : "";
|
|
2439
|
-
exitOk(`\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`);
|
|
2444
|
+
return exitOk(`\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`);
|
|
2440
2445
|
} catch (e) {
|
|
2441
2446
|
exitWithError(e);
|
|
2442
2447
|
}
|
|
@@ -2468,7 +2473,7 @@ async function envAdd(name, args) {
|
|
|
2468
2473
|
g.activeEnv = name;
|
|
2469
2474
|
await saveGlobalConfig2(g);
|
|
2470
2475
|
}
|
|
2471
|
-
exitOk(`\u2705 env '${name}' added. Run: hcm login --env ${name}`);
|
|
2476
|
+
return exitOk(`\u2705 env '${name}' added. Run: hcm login --env ${name}`);
|
|
2472
2477
|
} catch (e) {
|
|
2473
2478
|
exitWithError(e);
|
|
2474
2479
|
}
|
|
@@ -2500,7 +2505,7 @@ async function envUse(name, args) {
|
|
|
2500
2505
|
);
|
|
2501
2506
|
}
|
|
2502
2507
|
}
|
|
2503
|
-
exitOk(`\u2705 active env: ${name}`);
|
|
2508
|
+
return exitOk(`\u2705 active env: ${name}`);
|
|
2504
2509
|
} catch (e) {
|
|
2505
2510
|
exitWithError(e);
|
|
2506
2511
|
}
|
|
@@ -2510,8 +2515,7 @@ async function envRemove(name, args) {
|
|
|
2510
2515
|
if (!args.force) {
|
|
2511
2516
|
const ok = await promptConfirm(`remove env '${name}' and all its identities? [y/N] `);
|
|
2512
2517
|
if (!ok) {
|
|
2513
|
-
exitOk("aborted");
|
|
2514
|
-
return;
|
|
2518
|
+
return exitOk("aborted");
|
|
2515
2519
|
}
|
|
2516
2520
|
}
|
|
2517
2521
|
const ids = await listIdentities(name);
|
|
@@ -2537,7 +2541,7 @@ async function envRemove(name, args) {
|
|
|
2537
2541
|
const removedCount = ids.length - failed2.length;
|
|
2538
2542
|
const noun = (n) => n === 1 ? "identity" : "identities";
|
|
2539
2543
|
const failPart = failed2.length > 0 ? `, ${failed2.length} ${noun(failed2.length)} failed: ${failed2.join(", ")}` : "";
|
|
2540
|
-
exitOk(`\u2705 env '${name}' removed (${removedCount} ${noun(removedCount)} removed${failPart})`);
|
|
2544
|
+
return exitOk(`\u2705 env '${name}' removed (${removedCount} ${noun(removedCount)} removed${failPart})`);
|
|
2541
2545
|
} catch (e) {
|
|
2542
2546
|
exitWithError(e);
|
|
2543
2547
|
}
|
|
@@ -2548,7 +2552,7 @@ async function envShow(args) {
|
|
|
2548
2552
|
const target = args.name ?? g.activeEnv;
|
|
2549
2553
|
const cfg = await loadEnv2(target);
|
|
2550
2554
|
const ids = await listIdentities(target);
|
|
2551
|
-
exitOk(
|
|
2555
|
+
return exitOk(
|
|
2552
2556
|
toYaml({
|
|
2553
2557
|
name: target,
|
|
2554
2558
|
active: target === g.activeEnv,
|
|
@@ -2577,7 +2581,7 @@ async function envEdit(field, value, args) {
|
|
|
2577
2581
|
}
|
|
2578
2582
|
cfg[field] = value;
|
|
2579
2583
|
await saveEnv2(name, cfg);
|
|
2580
|
-
exitOk(`\u2705 ${name}.${field} = ${value}`);
|
|
2584
|
+
return exitOk(`\u2705 ${name}.${field} = ${value}`);
|
|
2581
2585
|
} catch (e) {
|
|
2582
2586
|
exitWithError(e);
|
|
2583
2587
|
}
|
|
@@ -2620,7 +2624,7 @@ async function configSet(key2, value) {
|
|
|
2620
2624
|
g.defaults = g.defaults ?? {};
|
|
2621
2625
|
g.defaults[sub] = value;
|
|
2622
2626
|
await saveGlobalConfig3(g);
|
|
2623
|
-
exitOk(`\u2705 defaults.${sub} = ${value}`);
|
|
2627
|
+
return exitOk(`\u2705 defaults.${sub} = ${value}`);
|
|
2624
2628
|
} catch (e) {
|
|
2625
2629
|
exitWithError(e);
|
|
2626
2630
|
}
|
|
@@ -2635,7 +2639,7 @@ async function configGet(key2) {
|
|
|
2635
2639
|
}
|
|
2636
2640
|
const sub = key2.slice("defaults.".length);
|
|
2637
2641
|
const g = await loadGlobalConfig3();
|
|
2638
|
-
exitOk(String(g.defaults?.[sub] ?? ""));
|
|
2642
|
+
return exitOk(String(g.defaults?.[sub] ?? ""));
|
|
2639
2643
|
} catch (e) {
|
|
2640
2644
|
exitWithError(e);
|
|
2641
2645
|
}
|
|
@@ -2880,7 +2884,8 @@ async function createCommand(model, args) {
|
|
|
2880
2884
|
const fmt = args.output ?? "json";
|
|
2881
2885
|
if (fmt !== "json") process.stdout.write("\u2705 created\n");
|
|
2882
2886
|
process.stdout.write(formatObject2(res, { format: fmt }) + "\n");
|
|
2883
|
-
process.
|
|
2887
|
+
process.exitCode = 0;
|
|
2888
|
+
return;
|
|
2884
2889
|
} catch (e) {
|
|
2885
2890
|
const err = e;
|
|
2886
2891
|
if (err?.isAxiosError) exitWithError(fromAxiosError3(err, args.profile));
|
|
@@ -2915,7 +2920,8 @@ async function updateCommand(model, args) {
|
|
|
2915
2920
|
if (fmt !== "json") process.stdout.write(`\u2705 ${model}#${args.id} \u5DF2\u66F4\u65B0
|
|
2916
2921
|
`);
|
|
2917
2922
|
process.stdout.write(formatObject3(result, { format: fmt }) + "\n");
|
|
2918
|
-
process.
|
|
2923
|
+
process.exitCode = 0;
|
|
2924
|
+
return;
|
|
2919
2925
|
} catch (e) {
|
|
2920
2926
|
const err = e;
|
|
2921
2927
|
if (err?.isAxiosError) exitWithError(fromAxiosError4(err, args.env));
|
|
@@ -2967,7 +2973,8 @@ async function settingGetCommand(domain, args) {
|
|
|
2967
2973
|
} else {
|
|
2968
2974
|
process.stdout.write(formatObject4(items, { format: fmt }) + "\n");
|
|
2969
2975
|
}
|
|
2970
|
-
process.
|
|
2976
|
+
process.exitCode = 0;
|
|
2977
|
+
return;
|
|
2971
2978
|
} catch (e) {
|
|
2972
2979
|
fail(e, args);
|
|
2973
2980
|
}
|
|
@@ -2992,7 +2999,8 @@ async function settingSetCommand(domain, args) {
|
|
|
2992
2999
|
`);
|
|
2993
3000
|
for (const i of items) process.stdout.write(` ${i.namespace}.${i.settingKey} = ${String(i.value)}
|
|
2994
3001
|
`);
|
|
2995
|
-
process.
|
|
3002
|
+
process.exitCode = 0;
|
|
3003
|
+
return;
|
|
2996
3004
|
}
|
|
2997
3005
|
const c = await client(args);
|
|
2998
3006
|
const result = await patchSettingDomain(c.raw(), domain, items);
|
|
@@ -3000,7 +3008,8 @@ async function settingSetCommand(domain, args) {
|
|
|
3000
3008
|
if (fmt !== "json") process.stdout.write(`\u2705 ${domain} \u5DF2\u66F4\u65B0 ${items.length} \u9879
|
|
3001
3009
|
`);
|
|
3002
3010
|
process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
|
|
3003
|
-
process.
|
|
3011
|
+
process.exitCode = 0;
|
|
3012
|
+
return;
|
|
3004
3013
|
} catch (e) {
|
|
3005
3014
|
fail(e, args);
|
|
3006
3015
|
}
|
|
@@ -3021,7 +3030,8 @@ async function settingResetCommand(domain, namespace, key2, args) {
|
|
|
3021
3030
|
if (fmt !== "json") process.stdout.write(`\u2705 ${namespace}.${key2} \u5DF2\u56DE\u843D\u5230\u9ED8\u8BA4\u503C
|
|
3022
3031
|
`);
|
|
3023
3032
|
process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
|
|
3024
|
-
process.
|
|
3033
|
+
process.exitCode = 0;
|
|
3034
|
+
return;
|
|
3025
3035
|
} catch (e) {
|
|
3026
3036
|
fail(e, args);
|
|
3027
3037
|
}
|
|
@@ -3067,7 +3077,8 @@ async function versionCommand(args) {
|
|
|
3067
3077
|
process.stdout.write(
|
|
3068
3078
|
formatObject5({ cli: CLI_VERSION, backend: info }, { format: fmt }) + "\n"
|
|
3069
3079
|
);
|
|
3070
|
-
process.
|
|
3080
|
+
process.exitCode = 0;
|
|
3081
|
+
return;
|
|
3071
3082
|
} catch (e) {
|
|
3072
3083
|
const err = e;
|
|
3073
3084
|
if (err?.isAxiosError) exitWithError(fromAxiosError6(err, args.env));
|
|
@@ -3117,7 +3128,8 @@ async function upgradeCommand(args) {
|
|
|
3117
3128
|
} else if (latest === CLI_VERSION) {
|
|
3118
3129
|
lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest} \u2014\u2014 \u5DF2\u662F\u6700\u65B0\uFF0C\u65E0\u9700\u5347\u7EA7`);
|
|
3119
3130
|
process.stdout.write(lines.join("\n") + "\n");
|
|
3120
|
-
process.
|
|
3131
|
+
process.exitCode = 0;
|
|
3132
|
+
return;
|
|
3121
3133
|
} else {
|
|
3122
3134
|
lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest}`);
|
|
3123
3135
|
}
|
|
@@ -3130,7 +3142,8 @@ async function upgradeCommand(args) {
|
|
|
3130
3142
|
lines.push("");
|
|
3131
3143
|
lines.push("\u5347\u7EA7\u540E\u7528 `hcm version` \u6838\u5BF9\uFF08\u5B83\u4F1A\u540C\u65F6\u62A5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF09\u3002");
|
|
3132
3144
|
process.stdout.write(lines.join("\n") + "\n");
|
|
3133
|
-
process.
|
|
3145
|
+
process.exitCode = args.check && latest !== null && latest !== CLI_VERSION ? 1 : 0;
|
|
3146
|
+
return;
|
|
3134
3147
|
}
|
|
3135
3148
|
|
|
3136
3149
|
// src/commands/open.ts
|
|
@@ -3169,7 +3182,7 @@ function launchBrowser(url, platform = process.platform) {
|
|
|
3169
3182
|
child.unref();
|
|
3170
3183
|
}
|
|
3171
3184
|
async function runOpen(target, args, deps) {
|
|
3172
|
-
const
|
|
3185
|
+
const path17 = normalizeTarget(target);
|
|
3173
3186
|
if (!deps.frontend?.trim()) {
|
|
3174
3187
|
throw new CliError12({
|
|
3175
3188
|
code: CliErrorCode11.INVALID_ARGUMENT,
|
|
@@ -3177,13 +3190,13 @@ async function runOpen(target, args, deps) {
|
|
|
3177
3190
|
});
|
|
3178
3191
|
}
|
|
3179
3192
|
const { ticket, expiresIn } = await deps.mintTicket();
|
|
3180
|
-
const url = buildBrowserLoginUrl(deps.frontend, ticket,
|
|
3193
|
+
const url = buildBrowserLoginUrl(deps.frontend, ticket, path17);
|
|
3181
3194
|
if (args.printUrl) {
|
|
3182
3195
|
deps.write(`${url}
|
|
3183
3196
|
`);
|
|
3184
3197
|
} else {
|
|
3185
3198
|
deps.launch(url);
|
|
3186
|
-
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${
|
|
3199
|
+
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path17}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
|
|
3187
3200
|
`);
|
|
3188
3201
|
}
|
|
3189
3202
|
return { url, expiresIn };
|
|
@@ -3229,7 +3242,8 @@ async function openCommand(target, args) {
|
|
|
3229
3242
|
write: (line) => process.stdout.write(line)
|
|
3230
3243
|
}
|
|
3231
3244
|
);
|
|
3232
|
-
process.
|
|
3245
|
+
process.exitCode = 0;
|
|
3246
|
+
return;
|
|
3233
3247
|
} catch (e) {
|
|
3234
3248
|
exitWithError(e);
|
|
3235
3249
|
}
|
|
@@ -3255,7 +3269,8 @@ async function deleteCommand(model, args) {
|
|
|
3255
3269
|
const fmt = args.output ?? "json";
|
|
3256
3270
|
if (fmt !== "json") process.stdout.write("\u2705 deleted\n");
|
|
3257
3271
|
process.stdout.write(formatObject6(res, { format: fmt }) + "\n");
|
|
3258
|
-
process.
|
|
3272
|
+
process.exitCode = 0;
|
|
3273
|
+
return;
|
|
3259
3274
|
} catch (e) {
|
|
3260
3275
|
const err = e;
|
|
3261
3276
|
if (err?.isAxiosError) exitWithError(fromAxiosError8(err, args.profile));
|
|
@@ -3275,8 +3290,8 @@ import {
|
|
|
3275
3290
|
formatObject as formatObject7,
|
|
3276
3291
|
fromAxiosError as fromAxiosError9
|
|
3277
3292
|
} from "@hcmai/sdk";
|
|
3278
|
-
function collectYmlFiles(
|
|
3279
|
-
if (statSync(
|
|
3293
|
+
function collectYmlFiles(path17) {
|
|
3294
|
+
if (statSync(path17).isFile()) return [path17];
|
|
3280
3295
|
const out = [];
|
|
3281
3296
|
const walk = (dir) => {
|
|
3282
3297
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3285,7 +3300,7 @@ function collectYmlFiles(path14) {
|
|
|
3285
3300
|
else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
|
|
3286
3301
|
}
|
|
3287
3302
|
};
|
|
3288
|
-
walk(
|
|
3303
|
+
walk(path17);
|
|
3289
3304
|
return out.sort();
|
|
3290
3305
|
}
|
|
3291
3306
|
var DRY_RUN_CLIENT = {
|
|
@@ -3293,9 +3308,9 @@ var DRY_RUN_CLIENT = {
|
|
|
3293
3308
|
create: async () => ({ id: "" }),
|
|
3294
3309
|
update: async () => ({})
|
|
3295
3310
|
};
|
|
3296
|
-
async function importCommand(
|
|
3311
|
+
async function importCommand(path17, args) {
|
|
3297
3312
|
try {
|
|
3298
|
-
const files = collectYmlFiles(
|
|
3313
|
+
const files = collectYmlFiles(path17);
|
|
3299
3314
|
const fixtures = files.map(
|
|
3300
3315
|
(f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
|
|
3301
3316
|
);
|
|
@@ -3314,7 +3329,8 @@ async function importCommand(path14, args) {
|
|
|
3314
3329
|
`
|
|
3315
3330
|
);
|
|
3316
3331
|
process.stdout.write(formatObject7(result, { format: fmt }) + "\n");
|
|
3317
|
-
process.
|
|
3332
|
+
process.exitCode = result.failed > 0 ? 3 : 0;
|
|
3333
|
+
return;
|
|
3318
3334
|
} catch (e) {
|
|
3319
3335
|
const err = e;
|
|
3320
3336
|
if (err?.isAxiosError) exitWithError(fromAxiosError9(err, args.profile));
|
|
@@ -3337,10 +3353,12 @@ async function describeCommand(model, args) {
|
|
|
3337
3353
|
const fmt = args.output ?? "table";
|
|
3338
3354
|
if (fmt !== "table") {
|
|
3339
3355
|
process.stdout.write(formatObject8(desc, { format: fmt }) + "\n");
|
|
3340
|
-
process.
|
|
3356
|
+
process.exitCode = 0;
|
|
3357
|
+
return;
|
|
3341
3358
|
}
|
|
3342
3359
|
process.stdout.write(formatDescriptionTable(desc, !!args.verbose) + "\n");
|
|
3343
|
-
process.
|
|
3360
|
+
process.exitCode = 0;
|
|
3361
|
+
return;
|
|
3344
3362
|
} catch (e) {
|
|
3345
3363
|
const err = e;
|
|
3346
3364
|
if (err?.isAxiosError) {
|
|
@@ -3357,7 +3375,13 @@ function formatDescriptionTable(desc, verbose = false) {
|
|
|
3357
3375
|
for (const f of desc.fields) {
|
|
3358
3376
|
const req = f.required ? " required" : " ";
|
|
3359
3377
|
const lbl = verbose ? ` ${f.label ?? ""} ${f.description ?? ""}` : ` ${f.label ?? ""}`;
|
|
3360
|
-
|
|
3378
|
+
const type = f.i18n ? `${f.type} (i18n)` : f.type;
|
|
3379
|
+
lines.push(` ${f.name.padEnd(20)} ${type.padEnd(14)} ${req}${lbl}`);
|
|
3380
|
+
}
|
|
3381
|
+
if (desc.fields.some((f) => f.i18n)) {
|
|
3382
|
+
lines.push(
|
|
3383
|
+
' \u2139\uFE0F (i18n) = \u591A\u8BED\u8A00\u5B57\u6BB5\uFF0C\u503C\u5F62\u5982 {zh_CN: "\u2026"}\uFF1B\u4E0D\u5E26 --i18n \u65F6\u4F20\u5B57\u7B26\u4E32\u53EA\u6539\u5F53\u524D\u8BED\u8A00\uFF0C\u5E26 --i18n \u5219\u6309 Map \u6574\u4EFD\u66FF\u6362'
|
|
3384
|
+
);
|
|
3361
3385
|
}
|
|
3362
3386
|
lines.push(`actions (${desc.actions.length}):`);
|
|
3363
3387
|
for (const a of desc.actions) {
|
|
@@ -3642,7 +3666,8 @@ async function chatCommand(prompt, args) {
|
|
|
3642
3666
|
});
|
|
3643
3667
|
}
|
|
3644
3668
|
await printConversationList(args);
|
|
3645
|
-
process.
|
|
3669
|
+
process.exitCode = 0;
|
|
3670
|
+
return;
|
|
3646
3671
|
}
|
|
3647
3672
|
const eventsConversationId = resolveEventsConversation(args);
|
|
3648
3673
|
if (eventsConversationId) {
|
|
@@ -3653,7 +3678,8 @@ async function chatCommand(prompt, args) {
|
|
|
3653
3678
|
});
|
|
3654
3679
|
}
|
|
3655
3680
|
await printConversationEvents(eventsConversationId, args);
|
|
3656
|
-
process.
|
|
3681
|
+
process.exitCode = 0;
|
|
3682
|
+
return;
|
|
3657
3683
|
}
|
|
3658
3684
|
let regenerateFromSeq;
|
|
3659
3685
|
let regenerateFromLastAssistant = false;
|
|
@@ -3853,7 +3879,8 @@ async function chatCommand(prompt, args) {
|
|
|
3853
3879
|
resolve4();
|
|
3854
3880
|
}
|
|
3855
3881
|
});
|
|
3856
|
-
process.
|
|
3882
|
+
process.exitCode = 0;
|
|
3883
|
+
return;
|
|
3857
3884
|
}
|
|
3858
3885
|
const { resolveInteraction: resolveInteraction2 } = await Promise.resolve().then(() => (init_control_prompt(), control_prompt_exports));
|
|
3859
3886
|
const { readLineFromStdin: readLineFromStdin2 } = await Promise.resolve().then(() => (init_readline(), readline_exports));
|
|
@@ -3924,7 +3951,8 @@ async function chatCommand(prompt, args) {
|
|
|
3924
3951
|
resolve4();
|
|
3925
3952
|
}
|
|
3926
3953
|
});
|
|
3927
|
-
process.
|
|
3954
|
+
process.exitCode = result.status === "interrupted" ? 130 : 0;
|
|
3955
|
+
return;
|
|
3928
3956
|
} catch (e) {
|
|
3929
3957
|
process.removeListener("SIGINT", sigintHandler);
|
|
3930
3958
|
await ws.close();
|
|
@@ -3984,7 +4012,8 @@ async function chatCommand(prompt, args) {
|
|
|
3984
4012
|
)
|
|
3985
4013
|
);
|
|
3986
4014
|
}
|
|
3987
|
-
process.
|
|
4015
|
+
process.exitCode = 0;
|
|
4016
|
+
return;
|
|
3988
4017
|
} catch (e) {
|
|
3989
4018
|
exitWithError(e);
|
|
3990
4019
|
}
|
|
@@ -4001,7 +4030,8 @@ async function downloadCommand(documentId, args) {
|
|
|
4001
4030
|
const client3 = HcmClient12.fromAuthContext(ctx);
|
|
4002
4031
|
const saved = await downloadDocument(client3.raw(), { documentId }, args.output);
|
|
4003
4032
|
process.stdout.write(saved + "\n");
|
|
4004
|
-
process.
|
|
4033
|
+
process.exitCode = 0;
|
|
4034
|
+
return;
|
|
4005
4035
|
} catch (e) {
|
|
4006
4036
|
const status = e?.response?.status;
|
|
4007
4037
|
if (status === 401 || status === 403) {
|
|
@@ -4353,10 +4383,12 @@ async function traceCommand(traceId, args) {
|
|
|
4353
4383
|
const rows = await fetchLlmTrace(http, convId);
|
|
4354
4384
|
const fmt = args.raw ? "json" : args.output;
|
|
4355
4385
|
process.stdout.write(formatObject10(rows, { format: fmt }) + "\n");
|
|
4356
|
-
process.
|
|
4386
|
+
process.exitCode = 0;
|
|
4387
|
+
return;
|
|
4357
4388
|
}
|
|
4358
4389
|
printLlmTraceTree(await gatherLlmTraceTree(http, convId));
|
|
4359
|
-
process.
|
|
4390
|
+
process.exitCode = 0;
|
|
4391
|
+
return;
|
|
4360
4392
|
}
|
|
4361
4393
|
if (!traceId) {
|
|
4362
4394
|
if (args.events || args.raw || args.span) {
|
|
@@ -4364,17 +4396,20 @@ async function traceCommand(traceId, args) {
|
|
|
4364
4396
|
return;
|
|
4365
4397
|
}
|
|
4366
4398
|
await listRecentTraces(client3, parsePositiveInt2(args.limit, 10, "--limit"));
|
|
4367
|
-
process.
|
|
4399
|
+
process.exitCode = 0;
|
|
4400
|
+
return;
|
|
4368
4401
|
}
|
|
4369
4402
|
const resp = await http.get(`/api/trace/${traceId}`);
|
|
4370
4403
|
const agg = resp.data ?? {};
|
|
4371
4404
|
if (args.raw) {
|
|
4372
4405
|
process.stdout.write(formatObject10(agg, { format: "json" }) + "\n");
|
|
4373
|
-
process.
|
|
4406
|
+
process.exitCode = 0;
|
|
4407
|
+
return;
|
|
4374
4408
|
}
|
|
4375
4409
|
if (args.output === "json" || args.output === "yaml") {
|
|
4376
4410
|
process.stdout.write(formatObject10(agg, { format: args.output }) + "\n");
|
|
4377
|
-
process.
|
|
4411
|
+
process.exitCode = 0;
|
|
4412
|
+
return;
|
|
4378
4413
|
}
|
|
4379
4414
|
const spans = agg.sources?.tempo?.spans ?? [];
|
|
4380
4415
|
if (args.span) {
|
|
@@ -4384,14 +4419,16 @@ async function traceCommand(traceId, args) {
|
|
|
4384
4419
|
return;
|
|
4385
4420
|
}
|
|
4386
4421
|
process.stdout.write(formatObject10(spans[idx], { format: "yaml" }) + "\n");
|
|
4387
|
-
process.
|
|
4422
|
+
process.exitCode = 0;
|
|
4423
|
+
return;
|
|
4388
4424
|
}
|
|
4389
4425
|
if (args.events) {
|
|
4390
4426
|
printTraceEvents(traceId, agg);
|
|
4391
4427
|
} else {
|
|
4392
4428
|
printTraceDetail(traceId, agg);
|
|
4393
4429
|
}
|
|
4394
|
-
process.
|
|
4430
|
+
process.exitCode = 0;
|
|
4431
|
+
return;
|
|
4395
4432
|
} catch (e) {
|
|
4396
4433
|
const err = e;
|
|
4397
4434
|
if (err?.isAxiosError) {
|
|
@@ -4420,7 +4457,8 @@ function emit(result, args, human) {
|
|
|
4420
4457
|
const fmt = args.output ?? "json";
|
|
4421
4458
|
if (fmt !== "json") process.stdout.write(human + "\n");
|
|
4422
4459
|
process.stdout.write(formatObject11(result, { format: fmt }) + "\n");
|
|
4423
|
-
process.
|
|
4460
|
+
process.exitCode = 0;
|
|
4461
|
+
return;
|
|
4424
4462
|
}
|
|
4425
4463
|
function fail2(e, args) {
|
|
4426
4464
|
const err = e;
|
|
@@ -4478,7 +4516,8 @@ function emit2(result, args, human) {
|
|
|
4478
4516
|
const fmt = args.output ?? "json";
|
|
4479
4517
|
if (fmt !== "json") process.stdout.write(human + "\n");
|
|
4480
4518
|
process.stdout.write(formatObject12(result, { format: fmt }) + "\n");
|
|
4481
|
-
process.
|
|
4519
|
+
process.exitCode = 0;
|
|
4520
|
+
return;
|
|
4482
4521
|
}
|
|
4483
4522
|
function fail3(e, args) {
|
|
4484
4523
|
const err = e;
|
|
@@ -4595,7 +4634,8 @@ async function uploadCommand(filePath, args) {
|
|
|
4595
4634
|
);
|
|
4596
4635
|
}
|
|
4597
4636
|
process.stdout.write(formatObject13(meta2, { format: fmt }) + "\n");
|
|
4598
|
-
process.
|
|
4637
|
+
process.exitCode = 0;
|
|
4638
|
+
return;
|
|
4599
4639
|
} catch (e) {
|
|
4600
4640
|
const err = e;
|
|
4601
4641
|
const status = err?.response?.status;
|
|
@@ -4619,13 +4659,23 @@ import {
|
|
|
4619
4659
|
formatObject as formatObject14,
|
|
4620
4660
|
fromAxiosError as fromAxiosError15,
|
|
4621
4661
|
packDataPackage,
|
|
4622
|
-
|
|
4662
|
+
installDataPackageArtifactAsync,
|
|
4663
|
+
waitForInstallRun,
|
|
4664
|
+
fetchInstallRun,
|
|
4665
|
+
isTerminalRunStatus,
|
|
4623
4666
|
DEFAULT_ARTIFACT_CATEGORY
|
|
4624
4667
|
} from "@hcmai/sdk";
|
|
4668
|
+
var DEFAULT_INSTALL_WAIT_SECONDS = 900;
|
|
4625
4669
|
async function datapackagePackCommand(packageDir, args) {
|
|
4626
4670
|
try {
|
|
4627
|
-
const result = await packDataPackage(packageDir, args.out);
|
|
4628
4671
|
const fmt = args.output ?? "json";
|
|
4672
|
+
const showProgress = fmt !== "json" && process.stderr.isTTY === true;
|
|
4673
|
+
const result = await packDataPackage(packageDir, args.out, {
|
|
4674
|
+
onFile: showProgress ? (rel, i, total) => {
|
|
4675
|
+
process.stderr.write(`\r\u{1F4E6} \u6253\u5305 ${i}/${total} ${truncateTail(rel, 60)}`.padEnd(90));
|
|
4676
|
+
if (i === total) process.stderr.write("\n");
|
|
4677
|
+
} : void 0
|
|
4678
|
+
});
|
|
4629
4679
|
if (fmt !== "json") {
|
|
4630
4680
|
process.stdout.write(
|
|
4631
4681
|
`\u{1F4E6} ${result.name} v${result.version}\uFF08${result.entryCount} \u4E2A\u6587\u4EF6\uFF09\u2192 ${result.artifactPath}
|
|
@@ -4633,7 +4683,8 @@ async function datapackagePackCommand(packageDir, args) {
|
|
|
4633
4683
|
);
|
|
4634
4684
|
}
|
|
4635
4685
|
process.stdout.write(formatObject14(result, { format: fmt }) + "\n");
|
|
4636
|
-
process.
|
|
4686
|
+
process.exitCode = 0;
|
|
4687
|
+
return;
|
|
4637
4688
|
} catch (e) {
|
|
4638
4689
|
exitWithError(e);
|
|
4639
4690
|
}
|
|
@@ -4642,22 +4693,68 @@ async function datapackageInstallCommand(artifactPath, args) {
|
|
|
4642
4693
|
try {
|
|
4643
4694
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
4644
4695
|
const client3 = HcmClient17.fromAuthContext(ctx);
|
|
4645
|
-
const
|
|
4696
|
+
const fmt = args.output ?? "json";
|
|
4697
|
+
const human = fmt !== "json";
|
|
4698
|
+
const accepted = await installDataPackageArtifactAsync(client3, artifactPath, {
|
|
4646
4699
|
category: args.category ?? DEFAULT_ARTIFACT_CATEGORY
|
|
4647
4700
|
});
|
|
4648
|
-
|
|
4649
|
-
if (fmt !== "json") {
|
|
4701
|
+
if (human) {
|
|
4650
4702
|
process.stdout.write(
|
|
4651
|
-
`\u{1F4E5} ${
|
|
4703
|
+
`\u{1F4E5} \u5DF2\u53D7\u7406 ${accepted.packageName ?? "?"} v${accepted.version ?? "?"}\uFF08runId=${accepted.runId}\uFF09
|
|
4652
4704
|
`
|
|
4653
4705
|
);
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4706
|
+
}
|
|
4707
|
+
if (args.wait === false) {
|
|
4708
|
+
emit3({
|
|
4709
|
+
runId: accepted.runId,
|
|
4710
|
+
documentId: accepted.documentId,
|
|
4711
|
+
packageName: accepted.packageName,
|
|
4712
|
+
version: accepted.version,
|
|
4713
|
+
status: "ACCEPTED",
|
|
4714
|
+
next_step: `hcm datapackage status ${accepted.runId}`
|
|
4715
|
+
}, fmt);
|
|
4716
|
+
process.exitCode = 0;
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
4719
|
+
const timeoutMs = Math.max(1, Number(args.timeout ?? DEFAULT_INSTALL_WAIT_SECONDS)) * 1e3;
|
|
4720
|
+
const showProgress = human && process.stderr.isTTY === true;
|
|
4721
|
+
const { run, timedOut } = await waitForInstallRun(client3, accepted.runId, {
|
|
4722
|
+
timeoutMs,
|
|
4723
|
+
onProgress: showProgress ? (r) => process.stderr.write(`\r${renderProgress(r)}`.padEnd(96)) : void 0
|
|
4724
|
+
});
|
|
4725
|
+
if (showProgress) process.stderr.write("\n");
|
|
4726
|
+
if (timedOut) {
|
|
4727
|
+
if (human) {
|
|
4728
|
+
process.stdout.write(
|
|
4729
|
+
`\u23F3 \u7B49\u5F85\u8D85\u8FC7 ${Math.round(timeoutMs / 1e3)}s\uFF0C\u88C5\u8F7D\u4ECD\u5728\u670D\u52A1\u7AEF\u7EE7\u7EED\u2014\u2014CLI \u9000\u51FA\u4E0D\u4F1A\u4E2D\u65AD\u5B83\u3002
|
|
4730
|
+
`
|
|
4731
|
+
);
|
|
4657
4732
|
}
|
|
4733
|
+
emit3({
|
|
4734
|
+
runId: accepted.runId,
|
|
4735
|
+
status: run?.status ?? "RUNNING",
|
|
4736
|
+
phase: run?.phase,
|
|
4737
|
+
filesDone: run?.filesDone,
|
|
4738
|
+
filesTotal: run?.filesTotal,
|
|
4739
|
+
rowsDone: run?.rowsDone,
|
|
4740
|
+
timedOut: true,
|
|
4741
|
+
next_step: `hcm datapackage status ${accepted.runId}`
|
|
4742
|
+
}, fmt);
|
|
4743
|
+
process.exitCode = 0;
|
|
4744
|
+
return;
|
|
4658
4745
|
}
|
|
4659
|
-
|
|
4660
|
-
|
|
4746
|
+
const failed2 = run?.status !== "SUCCESS";
|
|
4747
|
+
if (human) {
|
|
4748
|
+
process.stdout.write(
|
|
4749
|
+
`${failed2 ? "\u274C" : "\u2705"} ${run?.packageCode ?? accepted.packageName ?? "?"} v${run?.version ?? accepted.version ?? "?"} \u2192 ${run?.status ?? "?"}\uFF08rowCount=${run?.rowCount ?? 0}\uFF0C${Math.round((run?.durationMs ?? 0) / 1e3)}s\uFF09
|
|
4750
|
+
`
|
|
4751
|
+
);
|
|
4752
|
+
if (run?.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run.errorMessage}
|
|
4753
|
+
`);
|
|
4754
|
+
}
|
|
4755
|
+
emit3({ ...run ?? {}, runId: accepted.runId, documentId: accepted.documentId }, fmt);
|
|
4756
|
+
process.exitCode = failed2 ? 1 : 0;
|
|
4757
|
+
return;
|
|
4661
4758
|
} catch (e) {
|
|
4662
4759
|
const err = e;
|
|
4663
4760
|
if (err?.code === "ENOENT") {
|
|
@@ -4669,6 +4766,51 @@ async function datapackageInstallCommand(artifactPath, args) {
|
|
|
4669
4766
|
}
|
|
4670
4767
|
}
|
|
4671
4768
|
}
|
|
4769
|
+
async function datapackageStatusCommand(runId, args) {
|
|
4770
|
+
try {
|
|
4771
|
+
const ctx = await getActiveAuthContextFromCli(args);
|
|
4772
|
+
const client3 = HcmClient17.fromAuthContext(ctx);
|
|
4773
|
+
const run = await fetchInstallRun(client3, runId);
|
|
4774
|
+
const fmt = args.output ?? "json";
|
|
4775
|
+
if (!run) {
|
|
4776
|
+
if (fmt !== "json") {
|
|
4777
|
+
process.stdout.write(`\u23F3 \u6D41\u6C34 ${runId} \u8FD8\u6CA1\u51FA\u73B0\u2014\u2014\u521A\u53D7\u7406\u7684\u88C5\u8F7D\u4F1A\u6709\u51E0\u767E\u6BEB\u79D2\u7684\u7A7A\u7A97\u3002
|
|
4778
|
+
`);
|
|
4779
|
+
}
|
|
4780
|
+
emit3({ runId, status: "PENDING", next_step: `hcm datapackage status ${runId}` }, fmt);
|
|
4781
|
+
process.exitCode = 0;
|
|
4782
|
+
return;
|
|
4783
|
+
}
|
|
4784
|
+
if (fmt !== "json") {
|
|
4785
|
+
process.stdout.write(`${renderProgress(run)}
|
|
4786
|
+
`);
|
|
4787
|
+
if (run.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run.errorMessage}
|
|
4788
|
+
`);
|
|
4789
|
+
}
|
|
4790
|
+
emit3({ ...run, ...isTerminalRunStatus(run.status) ? {} : { next_step: `hcm datapackage status ${runId}` } }, fmt);
|
|
4791
|
+
process.exitCode = 0;
|
|
4792
|
+
return;
|
|
4793
|
+
} catch (e) {
|
|
4794
|
+
const err = e;
|
|
4795
|
+
if (err?.isAxiosError) exitWithError(fromAxiosError15(err, args.env));
|
|
4796
|
+
else exitWithError(e);
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
function renderProgress(run) {
|
|
4800
|
+
if (!run) return "\u23F3 \u7B49\u5F85\u88C5\u8F7D\u6D41\u6C34\u51FA\u73B0\u2026";
|
|
4801
|
+
const phase = run.phase ?? run.status ?? "?";
|
|
4802
|
+
const files = run.filesTotal ? `${run.filesDone ?? 0}/${run.filesTotal} \u6587\u4EF6` : `${run.filesDone ?? 0} \u6587\u4EF6`;
|
|
4803
|
+
const rows = run.rowsTotal ? `${run.rowsDone ?? 0}/${run.rowsTotal} \u884C` : `${run.rowsDone ?? 0} \u884C`;
|
|
4804
|
+
const pct = run.rowsTotal ? ` ${Math.min(100, Math.round((run.rowsDone ?? 0) / run.rowsTotal * 100))}%` : "";
|
|
4805
|
+
const file = run.currentFile ? ` ${truncateTail(run.currentFile, 42)}` : "";
|
|
4806
|
+
return `\u23F3 ${phase}${pct} ${files} ${rows}${file}`;
|
|
4807
|
+
}
|
|
4808
|
+
function truncateTail(text, max) {
|
|
4809
|
+
return text.length <= max ? text : "\u2026" + text.slice(text.length - max + 1);
|
|
4810
|
+
}
|
|
4811
|
+
function emit3(payload, fmt) {
|
|
4812
|
+
process.stdout.write(formatObject14(payload, { format: fmt }) + "\n");
|
|
4813
|
+
}
|
|
4672
4814
|
|
|
4673
4815
|
// src/commands/skills.ts
|
|
4674
4816
|
init_exit();
|
|
@@ -4753,17 +4895,17 @@ function emptyHalf() {
|
|
|
4753
4895
|
return { status: "skipped", entries: /* @__PURE__ */ new Map() };
|
|
4754
4896
|
}
|
|
4755
4897
|
function buildUnifiedCatalog(input) {
|
|
4756
|
-
const
|
|
4898
|
+
const chiron2 = emptyHalf();
|
|
4757
4899
|
const cli = emptyHalf();
|
|
4758
4900
|
if (input.source !== "cli" && input.chironManifest) {
|
|
4759
|
-
|
|
4760
|
-
for (const skill of flattenSkills(input.chironManifest))
|
|
4901
|
+
chiron2.status = "fetched";
|
|
4902
|
+
for (const skill of flattenSkills(input.chironManifest)) chiron2.entries.set(skill.id, chironEntry(skill));
|
|
4761
4903
|
}
|
|
4762
4904
|
if (input.source !== "chiron" && input.bundled) {
|
|
4763
4905
|
cli.status = "fetched";
|
|
4764
4906
|
for (const entry of input.bundled) cli.entries.set(entry.id, bundledEntry(entry, input.cliVersion));
|
|
4765
4907
|
}
|
|
4766
|
-
return { chiron, cli };
|
|
4908
|
+
return { chiron: chiron2, cli };
|
|
4767
4909
|
}
|
|
4768
4910
|
function detectIdConflicts(catalog) {
|
|
4769
4911
|
if (catalog.chiron.status !== "fetched" || catalog.cli.status !== "fetched") {
|
|
@@ -5156,14 +5298,16 @@ async function skillsListCommand(keyword, args) {
|
|
|
5156
5298
|
{ format: fmt }
|
|
5157
5299
|
) + "\n"
|
|
5158
5300
|
);
|
|
5159
|
-
process.
|
|
5301
|
+
process.exitCode = 0;
|
|
5302
|
+
return;
|
|
5160
5303
|
}
|
|
5161
5304
|
const shown = cats.flatMap((c) => c.skills);
|
|
5162
5305
|
const total = (manifest2?.skillCount ?? 0) + catalog.cli.entries.size;
|
|
5163
5306
|
if (shown.length === 0) {
|
|
5164
5307
|
process.stdout.write(`\u6CA1\u6709\u5339\u914D\u7684\u6280\u80FD\uFF08\u8FD9\u4E00\u8D9F\u770B\u7684\u6765\u6E90\u5171 ${total} \u4E2A\uFF09
|
|
5165
5308
|
`);
|
|
5166
|
-
process.
|
|
5309
|
+
process.exitCode = 0;
|
|
5310
|
+
return;
|
|
5167
5311
|
}
|
|
5168
5312
|
process.stdout.write(`${manifest2?.title ?? "HCM \u6280\u80FD"} \u2014 ${endpoint ?? `@hcmai/cli@${CLI_VERSION}`}
|
|
5169
5313
|
|
|
@@ -5198,7 +5342,8 @@ async function skillsListCommand(keyword, args) {
|
|
|
5198
5342
|
`);
|
|
5199
5343
|
process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
|
|
5200
5344
|
`);
|
|
5201
|
-
process.
|
|
5345
|
+
process.exitCode = 0;
|
|
5346
|
+
return;
|
|
5202
5347
|
}
|
|
5203
5348
|
for (const c of cats) {
|
|
5204
5349
|
process.stdout.write(` ${c.name}
|
|
@@ -5214,7 +5359,8 @@ async function skillsListCommand(keyword, args) {
|
|
|
5214
5359
|
`);
|
|
5215
5360
|
process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
|
|
5216
5361
|
`);
|
|
5217
|
-
process.
|
|
5362
|
+
process.exitCode = 0;
|
|
5363
|
+
return;
|
|
5218
5364
|
} catch (e) {
|
|
5219
5365
|
fail4(e, args);
|
|
5220
5366
|
}
|
|
@@ -5226,12 +5372,14 @@ async function listInstalledSkills(keyword, args) {
|
|
|
5226
5372
|
if (!state || Object.keys(state.skills).length === 0) {
|
|
5227
5373
|
if (fmt === "json" || fmt === "yaml") {
|
|
5228
5374
|
process.stdout.write(formatObject16({ baseDir: layout.baseDir, target: layout.target, all: false, skills: [] }, { format: fmt }) + "\n");
|
|
5229
|
-
process.
|
|
5375
|
+
process.exitCode = 0;
|
|
5376
|
+
return;
|
|
5230
5377
|
}
|
|
5231
5378
|
process.stdout.write(`${path4.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
|
|
5232
5379
|
`);
|
|
5233
5380
|
process.stdout.write(" \u88C5\u5168\u90E8\uFF1Ahcm skills install --all\n");
|
|
5234
|
-
process.
|
|
5381
|
+
process.exitCode = 0;
|
|
5382
|
+
return;
|
|
5235
5383
|
}
|
|
5236
5384
|
const rows = [];
|
|
5237
5385
|
for (const [id, record] of Object.entries(state.skills).sort(([a], [b]) => a.localeCompare(b))) {
|
|
@@ -5272,7 +5420,8 @@ async function listInstalledSkills(keyword, args) {
|
|
|
5272
5420
|
},
|
|
5273
5421
|
skills: shown
|
|
5274
5422
|
}, { format: fmt }) + "\n");
|
|
5275
|
-
process.
|
|
5423
|
+
process.exitCode = 0;
|
|
5424
|
+
return;
|
|
5276
5425
|
}
|
|
5277
5426
|
process.stdout.write(`\u5DF2\u5B89\u88C5\u7684\u6280\u80FD \u2014 ${layout.baseDir}\uFF08${layout.target}\uFF09
|
|
5278
5427
|
`);
|
|
@@ -5280,7 +5429,8 @@ async function listInstalledSkills(keyword, args) {
|
|
|
5280
5429
|
if (shown.length === 0) {
|
|
5281
5430
|
process.stdout.write(` \u6CA1\u6709\u5339\u914D\u300C${keyword}\u300D\u7684\u6280\u80FD\uFF08\u5171\u88C5\u4E86 ${rows.length} \u4E2A\uFF09
|
|
5282
5431
|
`);
|
|
5283
|
-
process.
|
|
5432
|
+
process.exitCode = 0;
|
|
5433
|
+
return;
|
|
5284
5434
|
}
|
|
5285
5435
|
for (const kind of ["chiron", "cli", "local"]) {
|
|
5286
5436
|
const group = shown.filter((row) => row.sourceKind === kind);
|
|
@@ -5308,7 +5458,8 @@ async function listInstalledSkills(keyword, args) {
|
|
|
5308
5458
|
].filter(Boolean).map((t) => `\uFF0C${t}`).join("") + "\n");
|
|
5309
5459
|
process.stdout.write(` \u5347\u7EA7\uFF1Ahcm skills update${state.all ? "" : "\uFF08\u60F3\u8DDF\u968F\u5168\u96C6\u52A0 --all\uFF09"}
|
|
5310
5460
|
`);
|
|
5311
|
-
process.
|
|
5461
|
+
process.exitCode = 0;
|
|
5462
|
+
return;
|
|
5312
5463
|
}
|
|
5313
5464
|
async function skillsShowCommand(id, args) {
|
|
5314
5465
|
try {
|
|
@@ -5317,7 +5468,8 @@ async function skillsShowCommand(id, args) {
|
|
|
5317
5468
|
if (source !== "chiron" && listBundledSkills().some((s) => s.id === id)) {
|
|
5318
5469
|
const document = await readBundledSkillDocument(id);
|
|
5319
5470
|
process.stdout.write(document.markdown.endsWith("\n") ? document.markdown : document.markdown + "\n");
|
|
5320
|
-
process.
|
|
5471
|
+
process.exitCode = 0;
|
|
5472
|
+
return;
|
|
5321
5473
|
}
|
|
5322
5474
|
if (source === "cli") {
|
|
5323
5475
|
throw invalid(`\u8FD9\u4E00\u7248 CLI \u6CA1\u6709\u81EA\u5E26 ${id} \u8FD9\u4E2A\u6280\u80FD\uFF08--source cli \u4E0D\u770B\u777F\u620E\u76EE\u5F55\uFF09`);
|
|
@@ -5325,7 +5477,8 @@ async function skillsShowCommand(id, args) {
|
|
|
5325
5477
|
const { http, base } = await chironClient(args);
|
|
5326
5478
|
const md = await fetchSkillMarkdown(http, id, base);
|
|
5327
5479
|
process.stdout.write(md.endsWith("\n") ? md : md + "\n");
|
|
5328
|
-
process.
|
|
5480
|
+
process.exitCode = 0;
|
|
5481
|
+
return;
|
|
5329
5482
|
} catch (e) {
|
|
5330
5483
|
fail4(e, args);
|
|
5331
5484
|
}
|
|
@@ -5489,7 +5642,8 @@ async function skillsInstallCommand(id, args) {
|
|
|
5489
5642
|
`);
|
|
5490
5643
|
process.stdout.write(all ? " \u5DF2\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF1A\u4EE5\u540E\u8DD1 hcm skills update\uFF0C\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\u4F1A\u81EA\u52A8\u8865\u4E0A\n" : " \u4EA7\u54C1\u66F4\u65B0\u540E\u8DD1 hcm skills update \u5347\u7EA7\n");
|
|
5491
5644
|
}
|
|
5492
|
-
process.
|
|
5645
|
+
process.exitCode = 0;
|
|
5646
|
+
return;
|
|
5493
5647
|
} catch (e) {
|
|
5494
5648
|
fail4(e, args);
|
|
5495
5649
|
}
|
|
@@ -6044,7 +6198,8 @@ async function skillsUpdateCommand(args) {
|
|
|
6044
6198
|
staleReferences: stale,
|
|
6045
6199
|
entries: plan.entries
|
|
6046
6200
|
}, { format: fmt }) + "\n");
|
|
6047
|
-
process.
|
|
6201
|
+
process.exitCode = 0;
|
|
6202
|
+
return;
|
|
6048
6203
|
}
|
|
6049
6204
|
process.stdout.write(`\u6280\u80FD\u5347\u7EA7 \u2014 ${source === "cli" ? `@hcmai/cli@${CLI_VERSION}\uFF08\u672A\u8FDE\u7F51\uFF09` : endpoint}
|
|
6050
6205
|
`);
|
|
@@ -6098,7 +6253,8 @@ async function skillsUpdateCommand(args) {
|
|
|
6098
6253
|
process.stdout.write(` ${[head, tail].filter(Boolean).join("\uFF1B")}
|
|
6099
6254
|
`);
|
|
6100
6255
|
}
|
|
6101
|
-
process.
|
|
6256
|
+
process.exitCode = 0;
|
|
6257
|
+
return;
|
|
6102
6258
|
} catch (e) {
|
|
6103
6259
|
fail4(e, args);
|
|
6104
6260
|
}
|
|
@@ -6201,7 +6357,8 @@ async function tenantBootstrapCommand(args) {
|
|
|
6201
6357
|
);
|
|
6202
6358
|
}
|
|
6203
6359
|
process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
|
|
6204
|
-
process.
|
|
6360
|
+
process.exitCode = 0;
|
|
6361
|
+
return;
|
|
6205
6362
|
} catch (e) {
|
|
6206
6363
|
const err = e;
|
|
6207
6364
|
if (err?.response?.status === 403) {
|
|
@@ -6263,24 +6420,26 @@ async function metaListCommand(args) {
|
|
|
6263
6420
|
if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
|
|
6264
6421
|
`);
|
|
6265
6422
|
process.stdout.write(formatObject18(items, { format: fmt }) + "\n");
|
|
6266
|
-
process.
|
|
6423
|
+
process.exitCode = 0;
|
|
6424
|
+
return;
|
|
6267
6425
|
} catch (e) {
|
|
6268
6426
|
fail5(e, args);
|
|
6269
6427
|
}
|
|
6270
6428
|
}
|
|
6271
|
-
async function metaGetCommand(
|
|
6429
|
+
async function metaGetCommand(path17, args) {
|
|
6272
6430
|
try {
|
|
6273
6431
|
const c = await client2(args);
|
|
6274
|
-
const content = await getTenantMeta(c.raw(),
|
|
6432
|
+
const content = await getTenantMeta(c.raw(), path17);
|
|
6275
6433
|
process.stdout.write(content.endsWith("\n") ? content : content + "\n");
|
|
6276
|
-
process.
|
|
6434
|
+
process.exitCode = 0;
|
|
6435
|
+
return;
|
|
6277
6436
|
} catch (e) {
|
|
6278
6437
|
fail5(e, args);
|
|
6279
6438
|
}
|
|
6280
6439
|
}
|
|
6281
6440
|
var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
|
|
6282
|
-
function parseMetaPath(
|
|
6283
|
-
const base =
|
|
6441
|
+
function parseMetaPath(path17) {
|
|
6442
|
+
const base = path17.split(/[\\/]/).pop() ?? path17;
|
|
6284
6443
|
if (!/\.(yml|yaml)$/i.test(base)) return {};
|
|
6285
6444
|
const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
|
|
6286
6445
|
return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
|
|
@@ -6297,10 +6456,10 @@ function unverifiableReason(e) {
|
|
|
6297
6456
|
if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
|
|
6298
6457
|
return void 0;
|
|
6299
6458
|
}
|
|
6300
|
-
async function verifyAfterWrite(c,
|
|
6301
|
-
const { model, kind, state } = parseMetaPath(
|
|
6459
|
+
async function verifyAfterWrite(c, path17) {
|
|
6460
|
+
const { model, kind, state } = parseMetaPath(path17);
|
|
6302
6461
|
if (!model || !kind) {
|
|
6303
|
-
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${
|
|
6462
|
+
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path17} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
|
|
6304
6463
|
}
|
|
6305
6464
|
try {
|
|
6306
6465
|
await clearMetaCache2(c.raw(), model, {});
|
|
@@ -6345,7 +6504,7 @@ async function verifyAfterWrite(c, path14) {
|
|
|
6345
6504
|
}
|
|
6346
6505
|
return { status: "ok" };
|
|
6347
6506
|
}
|
|
6348
|
-
async function metaSetCommand(
|
|
6507
|
+
async function metaSetCommand(path17, args) {
|
|
6349
6508
|
try {
|
|
6350
6509
|
if (!args.file) {
|
|
6351
6510
|
throw new CliError19({
|
|
@@ -6361,9 +6520,9 @@ async function metaSetCommand(path14, args) {
|
|
|
6361
6520
|
process.stdin.on("error", reject);
|
|
6362
6521
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6363
6522
|
if (!args.skipValidate) {
|
|
6364
|
-
const result2 = validateMetaContent(
|
|
6523
|
+
const result2 = validateMetaContent(path17, content);
|
|
6365
6524
|
if (result2.issues.length > 0) {
|
|
6366
|
-
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${
|
|
6525
|
+
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
|
|
6367
6526
|
`);
|
|
6368
6527
|
process.stderr.write(formatMetaIssues(result2, " ") + "\n");
|
|
6369
6528
|
}
|
|
@@ -6382,32 +6541,33 @@ async function metaSetCommand(path14, args) {
|
|
|
6382
6541
|
if (dryFmt === "json" || dryFmt === "yaml") {
|
|
6383
6542
|
process.stdout.write(
|
|
6384
6543
|
formatObject18(
|
|
6385
|
-
{ dryRun: true, path:
|
|
6544
|
+
{ dryRun: true, path: path17, bytes: Buffer.byteLength(content), content },
|
|
6386
6545
|
{ format: dryFmt }
|
|
6387
6546
|
) + "\n"
|
|
6388
6547
|
);
|
|
6389
6548
|
} else {
|
|
6390
6549
|
process.stdout.write(
|
|
6391
|
-
`[dry-run] \u5C06\u5199\u5165 ${
|
|
6550
|
+
`[dry-run] \u5C06\u5199\u5165 ${path17}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
|
|
6392
6551
|
---
|
|
6393
6552
|
${content}
|
|
6394
6553
|
`
|
|
6395
6554
|
);
|
|
6396
6555
|
}
|
|
6397
|
-
process.
|
|
6556
|
+
process.exitCode = 0;
|
|
6557
|
+
return;
|
|
6398
6558
|
}
|
|
6399
6559
|
const c = await client2(args);
|
|
6400
6560
|
let backupFile;
|
|
6401
6561
|
let backupState = "unknown";
|
|
6402
6562
|
let backupWhy;
|
|
6403
6563
|
try {
|
|
6404
|
-
const prev = await getTenantMeta(c.raw(),
|
|
6564
|
+
const prev = await getTenantMeta(c.raw(), path17);
|
|
6405
6565
|
if (!prev || prev.trim() === "") {
|
|
6406
6566
|
backupState = "absent";
|
|
6407
6567
|
} else {
|
|
6408
6568
|
backupFile = nodePath.join(
|
|
6409
6569
|
os3.tmpdir(),
|
|
6410
|
-
`hcm-meta-backup-${Date.now()}-${
|
|
6570
|
+
`hcm-meta-backup-${Date.now()}-${path17.replace(/[\\/]/g, "_")}`
|
|
6411
6571
|
);
|
|
6412
6572
|
await fsp3.writeFile(backupFile, prev, "utf8");
|
|
6413
6573
|
backupState = "saved";
|
|
@@ -6422,22 +6582,22 @@ ${content}
|
|
|
6422
6582
|
backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
|
|
6423
6583
|
}
|
|
6424
6584
|
}
|
|
6425
|
-
const result = await saveTenantMeta(c.raw(),
|
|
6585
|
+
const result = await saveTenantMeta(c.raw(), path17, content);
|
|
6426
6586
|
const fmt = args.output ?? "json";
|
|
6427
|
-
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${
|
|
6587
|
+
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path17}
|
|
6428
6588
|
`);
|
|
6429
6589
|
const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
|
|
6430
|
-
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${
|
|
6431
|
-
` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${
|
|
6590
|
+
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${path17} --file ${backupFile}${connFlags(args)}
|
|
6591
|
+
` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path17}${connFlags(args)}
|
|
6432
6592
|
` : ` \u26A0\uFE0F \u65E7\u5185\u5BB9**\u6CA1\u5907\u4EFD\u6210**\uFF08${backupWhy ?? "\u539F\u56E0\u672A\u77E5"}\uFF09\u2014\u2014\u65E2\u4E0D\u77E5\u9053\u6B64\u524D\u6709\u6CA1\u6709\u8986\u76D6\uFF0C\u4E5F\u5C31\u7ED9\u4E0D\u51FA\u6062\u590D\u547D\u4EE4\u3002
|
|
6433
|
-
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${
|
|
6593
|
+
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path17}${connFlags(args)}
|
|
6434
6594
|
`;
|
|
6435
6595
|
if (args.verify === false) {
|
|
6436
6596
|
process.stderr.write(
|
|
6437
6597
|
"\u26A0\uFE0F --no-verify\uFF1A**\u6CA1\u6709**\u9A8C\u8FC7\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\u3002\u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\u3002\n \u81EA\u5DF1\u8865\uFF1Ahcm cache clear-meta <Model> \u540E\u6253\u5F00\u9875\u9762\u770B\u4E00\u773C\u3002\n" + restoreHint
|
|
6438
6598
|
);
|
|
6439
6599
|
} else {
|
|
6440
|
-
const outcome = await verifyAfterWrite(c,
|
|
6600
|
+
const outcome = await verifyAfterWrite(c, path17);
|
|
6441
6601
|
if (outcome.status === "broken") {
|
|
6442
6602
|
const human = explainJacksonError(outcome.raw);
|
|
6443
6603
|
process.stderr.write(
|
|
@@ -6463,33 +6623,35 @@ ${content}
|
|
|
6463
6623
|
}
|
|
6464
6624
|
}
|
|
6465
6625
|
process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
|
|
6466
|
-
process.
|
|
6626
|
+
process.exitCode = 0;
|
|
6627
|
+
return;
|
|
6467
6628
|
} catch (e) {
|
|
6468
6629
|
if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
|
|
6469
6630
|
fail5(e, args);
|
|
6470
6631
|
}
|
|
6471
6632
|
}
|
|
6472
|
-
async function metaDeleteCommand(
|
|
6633
|
+
async function metaDeleteCommand(path17, args) {
|
|
6473
6634
|
try {
|
|
6474
6635
|
if (!args.yes) {
|
|
6475
|
-
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${
|
|
6636
|
+
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path17}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
|
|
6476
6637
|
if (!ok) {
|
|
6477
6638
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
6478
6639
|
process.exit(1);
|
|
6479
6640
|
}
|
|
6480
6641
|
}
|
|
6481
6642
|
const c = await client2(args);
|
|
6482
|
-
const result = await deleteTenantMeta(c.raw(),
|
|
6643
|
+
const result = await deleteTenantMeta(c.raw(), path17);
|
|
6483
6644
|
const fmt = args.output ?? "json";
|
|
6484
|
-
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${
|
|
6645
|
+
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path17}
|
|
6485
6646
|
`);
|
|
6486
6647
|
process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
|
|
6487
|
-
process.
|
|
6648
|
+
process.exitCode = 0;
|
|
6649
|
+
return;
|
|
6488
6650
|
} catch (e) {
|
|
6489
6651
|
fail5(e, args);
|
|
6490
6652
|
}
|
|
6491
6653
|
}
|
|
6492
|
-
async function metaValidateCommand(
|
|
6654
|
+
async function metaValidateCommand(path17, args) {
|
|
6493
6655
|
try {
|
|
6494
6656
|
if (!args.file) {
|
|
6495
6657
|
throw new CliError19({
|
|
@@ -6504,13 +6666,13 @@ async function metaValidateCommand(path14, args) {
|
|
|
6504
6666
|
process.stdin.on("end", () => resolve4(buf));
|
|
6505
6667
|
process.stdin.on("error", reject);
|
|
6506
6668
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6507
|
-
const result = validateMetaContent(
|
|
6669
|
+
const result = validateMetaContent(path17, content);
|
|
6508
6670
|
const fmt = args.output ?? "table";
|
|
6509
6671
|
if (fmt === "json" || fmt === "yaml") {
|
|
6510
6672
|
process.stdout.write(
|
|
6511
6673
|
formatObject18(
|
|
6512
6674
|
{
|
|
6513
|
-
path:
|
|
6675
|
+
path: path17,
|
|
6514
6676
|
kind: result.kind,
|
|
6515
6677
|
schemaKnown: result.schemaKnown,
|
|
6516
6678
|
schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
|
|
@@ -6522,14 +6684,15 @@ async function metaValidateCommand(path14, args) {
|
|
|
6522
6684
|
);
|
|
6523
6685
|
} else {
|
|
6524
6686
|
process.stdout.write(
|
|
6525
|
-
`\u{1F50E} ${
|
|
6687
|
+
`\u{1F50E} ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
|
|
6526
6688
|
`
|
|
6527
6689
|
);
|
|
6528
6690
|
process.stdout.write(
|
|
6529
6691
|
result.issues.length === 0 ? " \u6CA1\u6709\u53D1\u73B0\u95EE\u9898\u3002\n" : formatMetaIssues(result, " ") + "\n"
|
|
6530
6692
|
);
|
|
6531
6693
|
}
|
|
6532
|
-
process.
|
|
6694
|
+
process.exitCode = result.errors.length > 0 ? 1 : 0;
|
|
6695
|
+
return;
|
|
6533
6696
|
} catch (e) {
|
|
6534
6697
|
if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
|
|
6535
6698
|
fail5(e, args);
|
|
@@ -6625,7 +6788,8 @@ async function workspaceListCommand(args) {
|
|
|
6625
6788
|
limit
|
|
6626
6789
|
});
|
|
6627
6790
|
writeWorkspaceListResult(result.rows, args.output ?? "table", result.total);
|
|
6628
|
-
process.
|
|
6791
|
+
process.exitCode = 0;
|
|
6792
|
+
return;
|
|
6629
6793
|
} catch (e) {
|
|
6630
6794
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6631
6795
|
}
|
|
@@ -6654,7 +6818,8 @@ async function workspaceActiveCommand(args) {
|
|
|
6654
6818
|
rootDir
|
|
6655
6819
|
};
|
|
6656
6820
|
writeWorkspaceActiveResult(view, args.output ?? "table");
|
|
6657
|
-
process.
|
|
6821
|
+
process.exitCode = 0;
|
|
6822
|
+
return;
|
|
6658
6823
|
} catch (e) {
|
|
6659
6824
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6660
6825
|
}
|
|
@@ -6678,7 +6843,8 @@ async function workspaceBindCommand(workspaceKey, args) {
|
|
|
6678
6843
|
await fs5.mkdir(rootDir, { recursive: true });
|
|
6679
6844
|
await writeWorkspaceContext(rootDir, context);
|
|
6680
6845
|
writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
|
|
6681
|
-
process.
|
|
6846
|
+
process.exitCode = 0;
|
|
6847
|
+
return;
|
|
6682
6848
|
} catch (e) {
|
|
6683
6849
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6684
6850
|
}
|
|
@@ -6724,7 +6890,8 @@ async function workspaceCreateCommand(workspaceKey, args) {
|
|
|
6724
6890
|
},
|
|
6725
6891
|
args.output ?? "table"
|
|
6726
6892
|
);
|
|
6727
|
-
process.
|
|
6893
|
+
process.exitCode = 0;
|
|
6894
|
+
return;
|
|
6728
6895
|
} catch (e) {
|
|
6729
6896
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6730
6897
|
}
|
|
@@ -6797,7 +6964,8 @@ async function workspacePullCommand(args) {
|
|
|
6797
6964
|
},
|
|
6798
6965
|
args.output ?? "table"
|
|
6799
6966
|
);
|
|
6800
|
-
process.
|
|
6967
|
+
process.exitCode = 0;
|
|
6968
|
+
return;
|
|
6801
6969
|
} catch (e) {
|
|
6802
6970
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6803
6971
|
}
|
|
@@ -6838,7 +7006,8 @@ async function workspaceAddMiniCommand(appCode, args) {
|
|
|
6838
7006
|
force: !!args.force
|
|
6839
7007
|
});
|
|
6840
7008
|
writeWorkspaceAddMiniResult(result, rootDir, args.output ?? "table");
|
|
6841
|
-
process.
|
|
7009
|
+
process.exitCode = 0;
|
|
7010
|
+
return;
|
|
6842
7011
|
} catch (e) {
|
|
6843
7012
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6844
7013
|
}
|
|
@@ -6882,7 +7051,8 @@ async function workspaceStatusCommand(args) {
|
|
|
6882
7051
|
} else {
|
|
6883
7052
|
process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
|
|
6884
7053
|
}
|
|
6885
|
-
process.
|
|
7054
|
+
process.exitCode = 0;
|
|
7055
|
+
return;
|
|
6886
7056
|
} catch (e) {
|
|
6887
7057
|
exitWorkspaceError(e);
|
|
6888
7058
|
}
|
|
@@ -6896,7 +7066,8 @@ async function workspaceValidateCommand(args) {
|
|
|
6896
7066
|
miniApps.map(async (app) => ({ app, result: await validateMiniProject(app.dir) }))
|
|
6897
7067
|
);
|
|
6898
7068
|
writeWorkspaceValidateResult(results, args.output ?? "table");
|
|
6899
|
-
process.
|
|
7069
|
+
process.exitCode = results.every((item) => item.result.valid) ? 0 : 1;
|
|
7070
|
+
return;
|
|
6900
7071
|
} catch (e) {
|
|
6901
7072
|
exitWorkspaceError(e);
|
|
6902
7073
|
}
|
|
@@ -6953,9 +7124,8 @@ async function workspacePushCommand(args) {
|
|
|
6953
7124
|
if (hint) process.stderr.write(`
|
|
6954
7125
|
${hint}
|
|
6955
7126
|
`);
|
|
6956
|
-
process.
|
|
6957
|
-
|
|
6958
|
-
);
|
|
7127
|
+
process.exitCode = rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0;
|
|
7128
|
+
return;
|
|
6959
7129
|
} catch (e) {
|
|
6960
7130
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
6961
7131
|
}
|
|
@@ -6985,7 +7155,8 @@ async function workspacePreviewCommand(args) {
|
|
|
6985
7155
|
} else {
|
|
6986
7156
|
process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
|
|
6987
7157
|
}
|
|
6988
|
-
process.
|
|
7158
|
+
process.exitCode = 0;
|
|
7159
|
+
return;
|
|
6989
7160
|
} catch (e) {
|
|
6990
7161
|
exitWorkspaceError(e);
|
|
6991
7162
|
}
|
|
@@ -7076,7 +7247,8 @@ async function workspaceVerifyCommand(args) {
|
|
|
7076
7247
|
args.output ?? "table"
|
|
7077
7248
|
);
|
|
7078
7249
|
const rawOk = !!rawPlan && rawPlan.conflicts.length === 0;
|
|
7079
|
-
process.
|
|
7250
|
+
process.exitCode = rawOk && reports.every((item) => item.report.ok) ? 0 : 1;
|
|
7251
|
+
return;
|
|
7080
7252
|
} catch (e) {
|
|
7081
7253
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
7082
7254
|
}
|
|
@@ -7891,7 +8063,8 @@ async function workspaceActivateCommand(workspaceKey, args) {
|
|
|
7891
8063
|
formatObject19({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
|
|
7892
8064
|
);
|
|
7893
8065
|
}
|
|
7894
|
-
process.
|
|
8066
|
+
process.exitCode = 0;
|
|
8067
|
+
return;
|
|
7895
8068
|
} catch (e) {
|
|
7896
8069
|
exitWorkspaceError(e, args.env ?? args.profile);
|
|
7897
8070
|
}
|
|
@@ -7955,7 +8128,7 @@ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
|
|
|
7955
8128
|
async function identityShow(name, args) {
|
|
7956
8129
|
try {
|
|
7957
8130
|
const details = await inspectIdentity(name);
|
|
7958
|
-
exitOk(formatObject20(details, { format: args.output ?? "json" }));
|
|
8131
|
+
return exitOk(formatObject20(details, { format: args.output ?? "json" }));
|
|
7959
8132
|
} catch (e) {
|
|
7960
8133
|
exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
|
|
7961
8134
|
}
|
|
@@ -7966,8 +8139,7 @@ async function identityList(args) {
|
|
|
7966
8139
|
const filter = args.env === "all" ? void 0 : args.env ?? g.activeEnv;
|
|
7967
8140
|
const names = await listIdentities2(filter);
|
|
7968
8141
|
if (names.length === 0) {
|
|
7969
|
-
exitOk("(no identities)");
|
|
7970
|
-
return;
|
|
8142
|
+
return exitOk("(no identities)");
|
|
7971
8143
|
}
|
|
7972
8144
|
const lines = [];
|
|
7973
8145
|
for (const n of names) {
|
|
@@ -7977,7 +8149,7 @@ async function identityList(args) {
|
|
|
7977
8149
|
const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
|
|
7978
8150
|
lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
|
|
7979
8151
|
}
|
|
7980
|
-
exitOk(lines.join("\n"));
|
|
8152
|
+
return exitOk(lines.join("\n"));
|
|
7981
8153
|
} catch (e) {
|
|
7982
8154
|
exitWithError(e);
|
|
7983
8155
|
}
|
|
@@ -7993,7 +8165,7 @@ async function identityUse(name) {
|
|
|
7993
8165
|
});
|
|
7994
8166
|
env2.defaultIdentity = name;
|
|
7995
8167
|
await saveEnv3(meta2.env, env2);
|
|
7996
|
-
exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
|
|
8168
|
+
return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
|
|
7997
8169
|
} catch (e) {
|
|
7998
8170
|
exitWithError(e);
|
|
7999
8171
|
}
|
|
@@ -8015,7 +8187,7 @@ async function identityRemove(name) {
|
|
|
8015
8187
|
env2.defaultIdentity = void 0;
|
|
8016
8188
|
await saveEnv3(meta2.env, env2);
|
|
8017
8189
|
}
|
|
8018
|
-
exitOk(`\u2705 identity '${name}' removed`);
|
|
8190
|
+
return exitOk(`\u2705 identity '${name}' removed`);
|
|
8019
8191
|
} catch (e) {
|
|
8020
8192
|
exitWithError(e);
|
|
8021
8193
|
}
|
|
@@ -8798,7 +8970,8 @@ import { promises as fs6 } from "fs";
|
|
|
8798
8970
|
import path6 from "path";
|
|
8799
8971
|
|
|
8800
8972
|
// src/commands/delivery-page-acceptance.ts
|
|
8801
|
-
function renderPageAcceptanceSh() {
|
|
8973
|
+
function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
|
|
8974
|
+
const ev = evidenceDir;
|
|
8802
8975
|
return [
|
|
8803
8976
|
"#!/usr/bin/env bash",
|
|
8804
8977
|
"set -euo pipefail",
|
|
@@ -8808,12 +8981,12 @@ function renderPageAcceptanceSh() {
|
|
|
8808
8981
|
"\u7528\u6CD5\uFF1A",
|
|
8809
8982
|
" ./page-acceptance.sh --env <\u73AF\u5883> [--as <\u8EAB\u4EFD>] --path </\u7AD9\u5185\u8DEF\u5F84> \\",
|
|
8810
8983
|
" --expect-text <\u9875\u9762\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C> [--expect-text <\u6587\u672C> ...] \\",
|
|
8811
|
-
|
|
8984
|
+
` --out <${ev}/.../\u622A\u56FE.png> [--reject-text <\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C>] \\`,
|
|
8812
8985
|
" [--wait-ms 10000] [--size 1440x900]",
|
|
8813
8986
|
"",
|
|
8814
8987
|
"\u8BF4\u660E\uFF1A",
|
|
8815
8988
|
" - \u8C03\u7528 hcm open \u94F8\u4E00\u6B21\u6027\u767B\u5F55\u7968\u636E\uFF0C\u5E76\u7ACB\u5373\u4EA4\u7ED9\u672C\u673A Chrome/Chromium\u3002",
|
|
8816
|
-
|
|
8989
|
+
` - \u622A\u56FE\u53EA\u80FD\u5199\u5165\u9879\u76EE\u7684 ${ev}/ \u76EE\u5F55\uFF1B\u5DF2\u6709\u6587\u4EF6\u4E0D\u4F1A\u88AB\u8986\u76D6\u3002`,
|
|
8817
8990
|
" - \u81F3\u5C11\u4E00\u4E2A --expect-text \u662F\u5FC5\u586B\u9879\uFF0C\u9632\u6B62\u628A\u767B\u5F55\u9875\u6216\u9519\u8BEF\u9875\u8BEF\u8BB0\u6210\u901A\u8FC7\u3002",
|
|
8818
8991
|
" - \u6D4F\u89C8\u5668\u672A\u5728 PATH \u65F6\uFF0C\u7528 HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84 \u6307\u5B9A\u3002",
|
|
8819
8992
|
"USAGE",
|
|
@@ -8869,16 +9042,16 @@ function renderPageAcceptanceSh() {
|
|
|
8869
9042
|
'(( width >= 320 && width <= 7680 && height >= 240 && height <= 7680 )) || fail "--size \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u5BBD 320..7680\uFF0C\u9AD8 240..7680\uFF09" 2',
|
|
8870
9043
|
"",
|
|
8871
9044
|
'project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"',
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
`out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'
|
|
9045
|
+
`evidence_root="$project_root/${ev}"`,
|
|
9046
|
+
`[[ -d "$evidence_root" && ! -L "$evidence_root" ]] || fail "\u9879\u76EE\u7684 ${ev}/ \u5FC5\u987B\u662F\u666E\u901A\u76EE\u5F55\uFF0C\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5"`,
|
|
9047
|
+
`out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'${ev}'); const out=p.resolve(process.argv[1],process.argv[2]); if(out!==root && !out.startsWith(root+p.sep)){process.stderr.write('--out \u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE\u7684 ${ev}/ \u76EE\u5F55\\n'); process.exit(2)} process.stdout.write(out)" "$project_root" "$output")" || exit $?`,
|
|
8875
9048
|
'[[ ! -e "$out_abs" && ! -L "$out_abs" ]] || fail "\u622A\u56FE\u5DF2\u5B58\u5728\u6216\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A$out_abs"',
|
|
8876
9049
|
'mkdir -p "$(dirname "$out_abs")"',
|
|
8877
9050
|
'canonical_root="$(cd "$evidence_root" && pwd -P)"',
|
|
8878
9051
|
'canonical_parent="$(cd "$(dirname "$out_abs")" && pwd -P)"',
|
|
8879
9052
|
'case "$canonical_parent/" in',
|
|
8880
9053
|
' "$canonical_root/"*) ;;',
|
|
8881
|
-
|
|
9054
|
+
` *) fail "--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u9003\u51FA\u4E86 ${ev}/\uFF1A$output" ;;`,
|
|
8882
9055
|
"esac",
|
|
8883
9056
|
"",
|
|
8884
9057
|
"find_browser() {",
|
|
@@ -9259,14 +9432,14 @@ async function assertRegularFile(file) {
|
|
|
9259
9432
|
}
|
|
9260
9433
|
function upsertBlock(existing, begin, end, block) {
|
|
9261
9434
|
const start = existing.indexOf(begin);
|
|
9262
|
-
const
|
|
9263
|
-
const markersAreMalformed = start < 0 !==
|
|
9435
|
+
const finish2 = existing.indexOf(end);
|
|
9436
|
+
const markersAreMalformed = start < 0 !== finish2 < 0 || start >= 0 && (finish2 < start || existing.lastIndexOf(begin) !== start || existing.lastIndexOf(end) !== finish2);
|
|
9264
9437
|
if (markersAreMalformed) {
|
|
9265
9438
|
throw new Error(`\u6258\u7BA1\u5757\u6807\u8BB0\u635F\u574F\u6216\u91CD\u590D\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${begin} \u2026 ${end}`);
|
|
9266
9439
|
}
|
|
9267
9440
|
let next;
|
|
9268
|
-
if (start >= 0 &&
|
|
9269
|
-
next = `${existing.slice(0, start)}${block}${existing.slice(
|
|
9441
|
+
if (start >= 0 && finish2 >= start) {
|
|
9442
|
+
next = `${existing.slice(0, start)}${block}${existing.slice(finish2 + end.length)}`;
|
|
9270
9443
|
} else {
|
|
9271
9444
|
const prefix = existing.trimEnd();
|
|
9272
9445
|
next = `${prefix}${prefix ? "\n\n" : ""}${block}`;
|
|
@@ -9444,7 +9617,8 @@ async function deliveryInitCommand(args) {
|
|
|
9444
9617
|
nextStep: mode === "controlled" ? "hcm delivery assess <\u547D\u4EE4>\uFF1BR2 \u518D hcm delivery prepare --change-ref \u2026 --rollback-ref \u2026 --evidence-dir \u2026" : "hcm delivery assess <\u547D\u4EE4>\uFF1B\u672C\u9879\u76EE\u4E3A plan-only\uFF0Cexecute \u4F1A\u88AB\u62D2\u7EDD"
|
|
9445
9618
|
};
|
|
9446
9619
|
process.stdout.write(formatObject22(result, { format: args.output ?? "json" }) + "\n");
|
|
9447
|
-
process.
|
|
9620
|
+
process.exitCode = 0;
|
|
9621
|
+
return;
|
|
9448
9622
|
} catch (e) {
|
|
9449
9623
|
exitWithError(e);
|
|
9450
9624
|
process.exit(1);
|
|
@@ -9481,7 +9655,8 @@ async function deliveryModeCommand(args) {
|
|
|
9481
9655
|
{ format: args.output ?? "json" }
|
|
9482
9656
|
) + "\n"
|
|
9483
9657
|
);
|
|
9484
|
-
process.
|
|
9658
|
+
process.exitCode = 0;
|
|
9659
|
+
return;
|
|
9485
9660
|
}
|
|
9486
9661
|
const next = args.set;
|
|
9487
9662
|
if (!DELIVERY_MODES.includes(next)) {
|
|
@@ -9497,7 +9672,8 @@ async function deliveryModeCommand(args) {
|
|
|
9497
9672
|
process.stdout.write(
|
|
9498
9673
|
formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
|
|
9499
9674
|
);
|
|
9500
|
-
process.
|
|
9675
|
+
process.exitCode = 0;
|
|
9676
|
+
return;
|
|
9501
9677
|
} catch (e) {
|
|
9502
9678
|
exitWithError(e);
|
|
9503
9679
|
process.exit(1);
|
|
@@ -9552,7 +9728,8 @@ async function deliveryDoctorCommand(args) {
|
|
|
9552
9728
|
const fmt = args.output ?? "json";
|
|
9553
9729
|
if (fmt !== "json") process.stdout.write(render2(report) + "\n");
|
|
9554
9730
|
process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
|
|
9555
|
-
process.
|
|
9731
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
9732
|
+
return;
|
|
9556
9733
|
} catch (e) {
|
|
9557
9734
|
const err = e;
|
|
9558
9735
|
if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
|
|
@@ -9561,17 +9738,557 @@ async function deliveryDoctorCommand(args) {
|
|
|
9561
9738
|
}
|
|
9562
9739
|
}
|
|
9563
9740
|
|
|
9564
|
-
// src/commands/
|
|
9741
|
+
// src/commands/chiron-init.ts
|
|
9565
9742
|
init_auth_guard();
|
|
9566
9743
|
init_exit();
|
|
9744
|
+
import { promises as fs10 } from "fs";
|
|
9745
|
+
import path10 from "path";
|
|
9567
9746
|
import {
|
|
9747
|
+
CliError as CliError21,
|
|
9748
|
+
CliErrorCode as CliErrorCode20,
|
|
9568
9749
|
HcmClient as HcmClient22,
|
|
9750
|
+
fetchReconIdentity as fetchReconIdentity2,
|
|
9751
|
+
formatObject as formatObject24,
|
|
9752
|
+
httpProbe as httpProbe2,
|
|
9753
|
+
listIdentities as listIdentities3,
|
|
9754
|
+
loadEnv as loadEnv11,
|
|
9755
|
+
loadGlobalConfig as loadGlobalConfig10
|
|
9756
|
+
} from "@hcmai/sdk";
|
|
9757
|
+
|
|
9758
|
+
// src/commands/chiron-project.ts
|
|
9759
|
+
import { promises as fs9 } from "fs";
|
|
9760
|
+
import os4 from "os";
|
|
9761
|
+
import path9 from "path";
|
|
9762
|
+
import { spawnSync } from "child_process";
|
|
9763
|
+
import { hcmConfigDir, listEnvs as listEnvs3, loadEnv as loadEnv10 } from "@hcmai/sdk";
|
|
9764
|
+
var ENV_FILE = "env.yaml";
|
|
9765
|
+
var SKILLS_DIR = "hcm-skills";
|
|
9766
|
+
var CASES_REPO_URL = "https://cnb.cool/hcm/chiron-cases.git";
|
|
9767
|
+
var CASES_MCP_NAME = "chiron-cases";
|
|
9768
|
+
var CHIRON_PROJECT_DIRECTORIES = [
|
|
9769
|
+
"work",
|
|
9770
|
+
"decisions",
|
|
9771
|
+
"evidence",
|
|
9772
|
+
"requirements",
|
|
9773
|
+
"deliverables",
|
|
9774
|
+
"cases",
|
|
9775
|
+
"gaps",
|
|
9776
|
+
"customer-docs"
|
|
9777
|
+
];
|
|
9778
|
+
function renderEnvYaml(env2) {
|
|
9779
|
+
return [
|
|
9780
|
+
"# \u9879\u76EE\u73AF\u5883\uFF08hcm chiron init \u751F\u6210\uFF0C\u968F\u4ED3\u5E93\u63D0\u4EA4\uFF1B\u4E0D\u653E\u8EAB\u4EFD\u3001\u4E0D\u653E\u51ED\u636E\uFF09",
|
|
9781
|
+
"# \u767B\u5F55\uFF1Ahcm login <endpoint> --code <\u914D\u5BF9\u7801> \u6838\u5BF9\uFF1Ahcm chiron doctor",
|
|
9782
|
+
`endpoint: ${JSON.stringify(env2.endpoint)}`,
|
|
9783
|
+
`frontend: ${JSON.stringify(env2.frontend)}`,
|
|
9784
|
+
`tenant: ${JSON.stringify(env2.tenant)}`,
|
|
9785
|
+
""
|
|
9786
|
+
].join("\n");
|
|
9787
|
+
}
|
|
9788
|
+
function parseEnvYaml(text) {
|
|
9789
|
+
const out = {};
|
|
9790
|
+
for (const [offset, raw] of text.split(/\r?\n/).entries()) {
|
|
9791
|
+
if (!raw.trim() || raw.trimStart().startsWith("#")) continue;
|
|
9792
|
+
const m = raw.match(/^(endpoint|frontend|tenant):\s*(.+)$/);
|
|
9793
|
+
if (!m) throw new Error(`${ENV_FILE} \u7B2C ${offset + 1} \u884C\u4E0D\u662F endpoint / frontend / tenant \u4E4B\u4E00\uFF1A${raw.trim()}`);
|
|
9794
|
+
out[m[1]] = scalar(m[2] ?? "", offset + 1);
|
|
9795
|
+
}
|
|
9796
|
+
for (const key2 of ["endpoint", "frontend", "tenant"]) {
|
|
9797
|
+
if (!out[key2]) throw new Error(`${ENV_FILE} \u7F3A\u5C11 ${key2}`);
|
|
9798
|
+
}
|
|
9799
|
+
return { endpoint: normalizeOrigin(out.endpoint), frontend: normalizeOrigin(out.frontend), tenant: out.tenant };
|
|
9800
|
+
}
|
|
9801
|
+
function scalar(raw, lineNo) {
|
|
9802
|
+
const value = raw.trim();
|
|
9803
|
+
if (value.startsWith('"')) {
|
|
9804
|
+
try {
|
|
9805
|
+
return String(JSON.parse(value));
|
|
9806
|
+
} catch {
|
|
9807
|
+
throw new Error(`${ENV_FILE} \u7B2C ${lineNo} \u884C\u7684\u53CC\u5F15\u53F7\u503C\u975E\u6CD5`);
|
|
9808
|
+
}
|
|
9809
|
+
}
|
|
9810
|
+
if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1);
|
|
9811
|
+
return value.replace(/\s+#.*$/, "").trim();
|
|
9812
|
+
}
|
|
9813
|
+
function normalizeOrigin(url) {
|
|
9814
|
+
return url.trim().replace(/\/+$/, "");
|
|
9815
|
+
}
|
|
9816
|
+
function projectEnvFromConfig(cfg) {
|
|
9817
|
+
const endpoint = normalizeOrigin(cfg.endpoint);
|
|
9818
|
+
return {
|
|
9819
|
+
endpoint,
|
|
9820
|
+
// 冗余一份 frontend:前后端地址不一致的部署里,页面验收要开的是它。
|
|
9821
|
+
frontend: normalizeOrigin(cfg.frontend ?? endpoint),
|
|
9822
|
+
tenant: cfg.tenantId ?? "1"
|
|
9823
|
+
};
|
|
9824
|
+
}
|
|
9825
|
+
async function findEnvByEndpoint(endpoint) {
|
|
9826
|
+
const wanted = normalizeOrigin(endpoint);
|
|
9827
|
+
for (const name of await listEnvs3().catch(() => [])) {
|
|
9828
|
+
const config2 = await loadEnv10(name).catch(() => null);
|
|
9829
|
+
if (config2 && normalizeOrigin(config2.endpoint) === wanted) return { name, config: config2 };
|
|
9830
|
+
}
|
|
9831
|
+
return null;
|
|
9832
|
+
}
|
|
9833
|
+
function renderChironAgentInstructions() {
|
|
9834
|
+
return [
|
|
9835
|
+
AGENT_BEGIN,
|
|
9836
|
+
"# HCM \u987E\u95EE\u9879\u76EE\u8FB9\u754C",
|
|
9837
|
+
"",
|
|
9838
|
+
"- \u53EA\u4F7F\u7528\u672C\u9879\u76EE `hcm-skills/` \u91CC\u7684\u777F\u620E\u6280\u80FD\u4E0E\u5DF2\u53D1\u5E03\u7684 `hcm` CLI\uFF1B\u4E0D\u8BFB\u53D6\u4EA7\u54C1\u6E90\u7801\uFF0C\u4E0D\u76F4\u8FDE\u6570\u636E\u5E93\uFF0C\u4E0D\u7528 `curl` \u7ED5\u8FC7 CLI\u3002",
|
|
9839
|
+
"- \u9879\u76EE\u5BF9\u7740\u7684\u73AF\u5883\u5728 `env.yaml`\uFF08endpoint / frontend / tenant\uFF09\uFF0C\u8EAB\u4EFD\u5728\u672C\u673A `hcm login`\u3002\u6BCF\u6B21\u5F00\u5DE5\u5148\u8DD1 `hcm chiron doctor`\uFF1B\u73AF\u5883\u4E8B\u5B9E\u5FC5\u987B\u73B0\u67E5\uFF0C\u4E0D\u51ED\u8BB0\u5FC6\u586B\u5199\u3002",
|
|
9840
|
+
"- \u5199\u64CD\u4F5C\u5FC5\u987B\u4F9D\u6B21\u7ECF\u8FC7 `hcm delivery assess`\u3001`prepare`\u3001`execute`\uFF1B\u5199\u6388\u6743\u53EA\u8BA4\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728**\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66**\u91CC\u7684\u660E\u786E\u6279\u51C6\uFF0C\u5BA2\u6237\u53E3\u5934\u8981\u6C42\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743\u3002",
|
|
9841
|
+
"- \u5199\u524D\u5FC5\u987B\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u660E\u786E\u786E\u8BA4\u3002\u975E\u4EA4\u4E92\u8FD0\u884C\u62FF\u4E0D\u5230\u786E\u8BA4\u65F6\uFF0C\u6700\u591A\u505A\u5230 `prepare`\uFF0C\u7ED3\u8BBA\u5FC5\u987B\u4E3A `BLOCKED` \u5E76\u9644\u8BA1\u5212\uFF1B\u4E0D\u5F97\u81EA\u884C `delivery mode --set controlled` \u6216 `execute`\u3002",
|
|
9842
|
+
"- \u76EE\u5F55\u7EA6\u5B9A\uFF1A`requirements/` \u5BA2\u6237\u9700\u6C42 \xB7 `deliverables/` \u4EA4\u4ED8\u7269 \xB7 `evidence/` \u622A\u56FE\u4E0E\u6536\u636E \xB7 `cases/` \u6C89\u6DC0\u7684\u6848\u4F8B \xB7 `gaps/` \u4EA7\u54C1\u505A\u4E0D\u5230\u7684\u53F0\u8D26 \xB7 `decisions/` \u51B3\u7B56 \xB7 `customer-docs/` \u5BA2\u6237\u8D44\u6599 \xB7 `work/` \u53D8\u66F4\u4E0E\u56DE\u6EDA\u8BF4\u660E\u3002",
|
|
9843
|
+
"- \u649E\u5230\u4EA7\u54C1\u505A\u4E0D\u5230\uFF1A\u5148\u5199 `gaps/` \u53F0\u8D26\u5E76\u7B54\u6E05\u4E09\u95EE\uFF08\u8981\u4EC0\u4E48 / \u8BD5\u8FC7\u4EC0\u4E48 / \u66FF\u4EE3\u6CD5\uFF09\uFF0C\u7ECF\u987E\u95EE\u786E\u8BA4\u540E\u7528\u6848\u4F8B\u5E93 MCP \u7684 `gaps_submit` \u63D0\u4EA4\uFF0C\u62A5\u544A\u5199 `BLOCKED \xB7 \u5DF2\u63D0 #N \xB7 \u66FF\u4EE3\u6CD5`\u3002",
|
|
9844
|
+
"- \u9875\u9762\u9A8C\u6536\u7EDF\u4E00\u7528 `./page-acceptance.sh`\uFF1A\u663E\u5F0F\u4F20\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u7AD9\u5185\u8DEF\u5F84\u3001\u671F\u671B\u6587\u672C\u4E0E `evidence/` \u4E0B\u7684 PNG \u8DEF\u5F84\uFF1B\u4E0D\u80FD\u53EA\u4EE5\u201C\u751F\u6210\u4E86\u622A\u56FE\u201D\u5224\u901A\u8FC7\u3002",
|
|
9845
|
+
"- \u4EFB\u4F55\u51ED\u636E\u3001\u914D\u5BF9\u7801\u3001\u4EE4\u724C\u3001\u5BA2\u6237\u5BC6\u7801\u90FD\u4E0D\u5F97\u5199\u5165\u4ED3\u5E93\u3001\u547D\u4EE4\u53C2\u6570\u6216\u4EA4\u4ED8\u6587\u6863\u3002",
|
|
9846
|
+
AGENT_END,
|
|
9847
|
+
""
|
|
9848
|
+
].join("\n");
|
|
9849
|
+
}
|
|
9850
|
+
function mergeChironAgentInstructions(existing) {
|
|
9851
|
+
return upsertBlock(existing, AGENT_BEGIN, AGENT_END, renderChironAgentInstructions().trimEnd());
|
|
9852
|
+
}
|
|
9853
|
+
function caseLibraryDir() {
|
|
9854
|
+
return path9.join(hcmConfigDir(), CASES_MCP_NAME);
|
|
9855
|
+
}
|
|
9856
|
+
function codexConfigFile() {
|
|
9857
|
+
return path9.join(process.env.HOME ?? os4.homedir(), ".codex", "config.toml");
|
|
9858
|
+
}
|
|
9859
|
+
function renderCodexMcpSection(repo, envName) {
|
|
9860
|
+
const server = path9.join(repo, "mcp", "server.mjs");
|
|
9861
|
+
return [
|
|
9862
|
+
`[mcp_servers.${CASES_MCP_NAME}]`,
|
|
9863
|
+
'command = "node"',
|
|
9864
|
+
`args = [${JSON.stringify(server)}]`,
|
|
9865
|
+
`env = { CASES_REPO = ${JSON.stringify(repo)}, HCM_ENV = ${JSON.stringify(envName)} }`,
|
|
9866
|
+
""
|
|
9867
|
+
].join("\n");
|
|
9868
|
+
}
|
|
9869
|
+
function mergeCodexMcpConfig(existing, section) {
|
|
9870
|
+
const lines = existing.split(/\r?\n/);
|
|
9871
|
+
const isOurs = (line) => new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}(\\.|\\])`).test(line.trim());
|
|
9872
|
+
const isHeader = (line) => /^\s*\[/.test(line);
|
|
9873
|
+
let start = -1;
|
|
9874
|
+
let end = -1;
|
|
9875
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9876
|
+
const line = lines[i] ?? "";
|
|
9877
|
+
if (start < 0 && isOurs(line)) {
|
|
9878
|
+
start = i;
|
|
9879
|
+
continue;
|
|
9880
|
+
}
|
|
9881
|
+
if (start >= 0 && isHeader(line) && !isOurs(line)) {
|
|
9882
|
+
end = i;
|
|
9883
|
+
break;
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
const block = section.trimEnd();
|
|
9887
|
+
if (start < 0) {
|
|
9888
|
+
const prefix = existing.trimEnd();
|
|
9889
|
+
return `${prefix}${prefix ? "\n\n" : ""}${block}
|
|
9890
|
+
`;
|
|
9891
|
+
}
|
|
9892
|
+
const tail = lines.slice(end < 0 ? lines.length : end);
|
|
9893
|
+
const head = lines.slice(0, start);
|
|
9894
|
+
return `${[...head, block, "", ...tail].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}
|
|
9895
|
+
`;
|
|
9896
|
+
}
|
|
9897
|
+
function codexConfigHasCases(text) {
|
|
9898
|
+
return new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}\\]`, "m").test(text);
|
|
9899
|
+
}
|
|
9900
|
+
var defaultCaseLibraryDeps = {
|
|
9901
|
+
git: (args, cwd) => {
|
|
9902
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", timeout: 12e4, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
9903
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9904
|
+
},
|
|
9905
|
+
npmInstall: (cwd) => {
|
|
9906
|
+
const r = spawnSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund", "--loglevel=error"], {
|
|
9907
|
+
cwd,
|
|
9908
|
+
encoding: "utf8",
|
|
9909
|
+
timeout: 3e5
|
|
9910
|
+
});
|
|
9911
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9912
|
+
}
|
|
9913
|
+
};
|
|
9914
|
+
async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths = {}) {
|
|
9915
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9916
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9917
|
+
const status = { ok: false, repo, step: "present", serverInstalled: false, codexWired: false };
|
|
9918
|
+
const hasGit = await exists2(path9.join(repo, ".git"));
|
|
9919
|
+
if (hasGit) {
|
|
9920
|
+
const pull = deps.git(["pull", "--ff-only", "--quiet"], repo);
|
|
9921
|
+
status.step = pull.status === 0 ? "updated" : "present";
|
|
9922
|
+
if (pull.status !== 0) status.reason = `\u66F4\u65B0\u5931\u8D25\uFF0C\u6CBF\u7528\u672C\u5730\u7248\u672C\uFF1A${firstLine(pull.stderr, pull.error)}`;
|
|
9923
|
+
} else {
|
|
9924
|
+
await fs9.mkdir(path9.dirname(repo), { recursive: true });
|
|
9925
|
+
const clone = deps.git(["clone", "--depth", "1", "--quiet", CASES_REPO_URL, repo]);
|
|
9926
|
+
if (clone.status !== 0) {
|
|
9927
|
+
status.step = "clone-failed";
|
|
9928
|
+
status.reason = `clone \u5931\u8D25\uFF08\u591A\u534A\u662F\u6CA1\u6709 ${CASES_REPO_URL.replace(/\.git$/, "")} \u7684\u6743\u9650\uFF0C\u6216\u672C\u673A git \u672A\u767B\u5F55 cnb\uFF09\uFF1A${firstLine(clone.stderr, clone.error)}`;
|
|
9929
|
+
return status;
|
|
9930
|
+
}
|
|
9931
|
+
status.step = "cloned";
|
|
9932
|
+
}
|
|
9933
|
+
const mcpDir = path9.join(repo, "mcp");
|
|
9934
|
+
if (!await exists2(path9.join(mcpDir, "server.mjs"))) {
|
|
9935
|
+
status.step = "install-failed";
|
|
9936
|
+
status.reason = `\u6848\u4F8B\u5E93\u91CC\u6CA1\u6709 mcp/server.mjs\uFF1A${mcpDir}`;
|
|
9937
|
+
return status;
|
|
9938
|
+
}
|
|
9939
|
+
if (!await exists2(path9.join(mcpDir, "node_modules", "@modelcontextprotocol"))) {
|
|
9940
|
+
const install = deps.npmInstall(mcpDir);
|
|
9941
|
+
if (install.status !== 0) {
|
|
9942
|
+
status.step = "install-failed";
|
|
9943
|
+
status.reason = `npm install \u5931\u8D25\uFF1A${firstLine(install.stderr, install.error)}`;
|
|
9944
|
+
return status;
|
|
9945
|
+
}
|
|
9946
|
+
}
|
|
9947
|
+
status.serverInstalled = true;
|
|
9948
|
+
await fs9.mkdir(path9.dirname(codexConfig), { recursive: true });
|
|
9949
|
+
const existing = await fs9.readFile(codexConfig, "utf8").catch(() => "");
|
|
9950
|
+
const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
|
|
9951
|
+
if (next !== existing) await fs9.writeFile(codexConfig, next, "utf8");
|
|
9952
|
+
status.codexWired = true;
|
|
9953
|
+
status.ok = true;
|
|
9954
|
+
return status;
|
|
9955
|
+
}
|
|
9956
|
+
async function inspectCaseLibrary(paths = {}) {
|
|
9957
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9958
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9959
|
+
const cloned = await exists2(path9.join(repo, ".git"));
|
|
9960
|
+
const serverInstalled = cloned && await exists2(path9.join(repo, "mcp", "server.mjs")) && await exists2(path9.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
|
|
9961
|
+
const codexWired = codexConfigHasCases(await fs9.readFile(codexConfig, "utf8").catch(() => ""));
|
|
9962
|
+
return { repo, cloned, serverInstalled, codexWired };
|
|
9963
|
+
}
|
|
9964
|
+
function firstLine(stderr, error) {
|
|
9965
|
+
if (error) return error.message;
|
|
9966
|
+
const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
|
|
9967
|
+
return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
|
|
9968
|
+
}
|
|
9969
|
+
async function exists2(file) {
|
|
9970
|
+
try {
|
|
9971
|
+
await fs9.access(file);
|
|
9972
|
+
return true;
|
|
9973
|
+
} catch {
|
|
9974
|
+
return false;
|
|
9975
|
+
}
|
|
9976
|
+
}
|
|
9977
|
+
|
|
9978
|
+
// src/commands/chiron-init.ts
|
|
9979
|
+
async function probeTokenTenant(envName, requested) {
|
|
9980
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
9981
|
+
const client3 = HcmClient22.fromAuthContext(ctx);
|
|
9982
|
+
const identity2 = await fetchReconIdentity2(httpProbe2(client3.raw(), "default"), requested);
|
|
9983
|
+
return identity2?.tenantId ? String(identity2.tenantId) : void 0;
|
|
9984
|
+
}
|
|
9985
|
+
var defaultChironInitDeps = {
|
|
9986
|
+
tokenTenant: probeTokenTenant,
|
|
9987
|
+
installSkills: async (root, envName) => {
|
|
9988
|
+
const previous = process.cwd();
|
|
9989
|
+
process.chdir(root);
|
|
9990
|
+
try {
|
|
9991
|
+
await skillsInstallCommand(void 0, {
|
|
9992
|
+
all: true,
|
|
9993
|
+
target: "codex",
|
|
9994
|
+
env: envName,
|
|
9995
|
+
dir: path10.join(root, SKILLS_DIR),
|
|
9996
|
+
output: "table"
|
|
9997
|
+
});
|
|
9998
|
+
} finally {
|
|
9999
|
+
process.chdir(previous);
|
|
10000
|
+
}
|
|
10001
|
+
if (process.exitCode && process.exitCode !== 0) {
|
|
10002
|
+
throw new Error("\u6280\u80FD\u6CA1\u88C5\u4E0A\uFF08\u4E0A\u9762\u662F skills install \u7684\u8F93\u51FA\uFF09\uFF1B\u4FEE\u597D\u540E\u91CD\u8DD1 hcm chiron init");
|
|
10003
|
+
}
|
|
10004
|
+
},
|
|
10005
|
+
caseLibrary: (envName) => ensureCaseLibrary(envName)
|
|
10006
|
+
};
|
|
10007
|
+
async function resolveLoggedInEnv() {
|
|
10008
|
+
const g = await loadGlobalConfig10();
|
|
10009
|
+
const name = g.activeEnv;
|
|
10010
|
+
const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
|
|
10011
|
+
if (!name) {
|
|
10012
|
+
throw new CliError21({
|
|
10013
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10014
|
+
message: `\u8FD8\u6CA1\u767B\u5F55\u4EFB\u4F55\u73AF\u5883\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10015
|
+
});
|
|
10016
|
+
}
|
|
10017
|
+
const config2 = await loadEnv11(name).catch(() => null);
|
|
10018
|
+
if (!config2?.endpoint) {
|
|
10019
|
+
throw new CliError21({
|
|
10020
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10021
|
+
message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10022
|
+
});
|
|
10023
|
+
}
|
|
10024
|
+
const identities = await listIdentities3(name).catch(() => []);
|
|
10025
|
+
if (identities.length === 0) {
|
|
10026
|
+
throw new CliError21({
|
|
10027
|
+
code: CliErrorCode20.IDENTITY_NOT_FOUND,
|
|
10028
|
+
message: `\u73AF\u5883 '${name}'\uFF08${config2.endpoint}\uFF09\u8FD8\u6CA1\u6709\u767B\u5F55\u8EAB\u4EFD\u3002\u5148\u6267\u884C\uFF1Ahcm login ${config2.endpoint} --code <\u914D\u5BF9\u7801>`
|
|
10029
|
+
});
|
|
10030
|
+
}
|
|
10031
|
+
const identity2 = config2.defaultIdentity && identities.includes(config2.defaultIdentity) ? config2.defaultIdentity : identities[0];
|
|
10032
|
+
return { name, env: projectEnvFromConfig(config2), identity: identity2 };
|
|
10033
|
+
}
|
|
10034
|
+
async function scaffoldChironProject(root, env2, envName) {
|
|
10035
|
+
const result = { created: [], updated: [], preserved: [] };
|
|
10036
|
+
const envFile = path10.join(root, ENV_FILE);
|
|
10037
|
+
const existing = await fs10.readFile(envFile, "utf8").catch(() => null);
|
|
10038
|
+
if (existing !== null) {
|
|
10039
|
+
const recorded = parseEnvYaml(existing);
|
|
10040
|
+
if (recorded.endpoint !== env2.endpoint) {
|
|
10041
|
+
throw new CliError21({
|
|
10042
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10043
|
+
message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env2.endpoint}\uFF08env '${envName}'\uFF09\u3002
|
|
10044
|
+
\u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
|
|
10045
|
+
\u8981\u628A\u9879\u76EE\u6539\u5230\u4F60\u767B\u5F55\u7684\u73AF\u5883\uFF1A\u5220\u6389 ${ENV_FILE} \u540E\u91CD\u8DD1\uFF08\u8FD9\u4F1A\u5F71\u54CD\u6240\u6709\u534F\u4F5C\u8005\uFF0C\u5148\u8DDF\u8D1F\u8D23\u4EBA\u786E\u8BA4\uFF09`
|
|
10046
|
+
});
|
|
10047
|
+
}
|
|
10048
|
+
if (recorded.tenant !== env2.tenant) {
|
|
10049
|
+
throw new CliError21({
|
|
10050
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10051
|
+
message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env2.tenant}\u3002
|
|
10052
|
+
\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
|
|
10053
|
+
});
|
|
10054
|
+
}
|
|
10055
|
+
result.preserved.push(ENV_FILE);
|
|
10056
|
+
} else {
|
|
10057
|
+
await fs10.writeFile(envFile, renderEnvYaml(env2), { encoding: "utf8", mode: 420, flag: "wx" });
|
|
10058
|
+
result.created.push(ENV_FILE);
|
|
10059
|
+
}
|
|
10060
|
+
for (const directory of CHIRON_PROJECT_DIRECTORIES) {
|
|
10061
|
+
const absolute = path10.join(root, directory);
|
|
10062
|
+
await ensureDirectory(absolute);
|
|
10063
|
+
await writeIfAbsent(path10.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
|
|
10064
|
+
}
|
|
10065
|
+
const deliveryDir = path10.join(root, ".hcm-delivery");
|
|
10066
|
+
await ensureDirectory(deliveryDir);
|
|
10067
|
+
await writeIfAbsent(
|
|
10068
|
+
path10.join(deliveryDir, "project.yml"),
|
|
10069
|
+
renderProjectYml(envName, "plan-only"),
|
|
10070
|
+
result,
|
|
10071
|
+
".hcm-delivery/project.yml"
|
|
10072
|
+
);
|
|
10073
|
+
const pageAcceptanceFile = path10.join(root, "page-acceptance.sh");
|
|
10074
|
+
const created = await writeIfAbsent(pageAcceptanceFile, renderPageAcceptanceSh("evidence"), result, "page-acceptance.sh", 493);
|
|
10075
|
+
if (created) await fs10.chmod(pageAcceptanceFile, 493);
|
|
10076
|
+
await mergeManagedFile(path10.join(root, "AGENTS.md"), mergeChironAgentInstructions, result, "AGENTS.md");
|
|
10077
|
+
await mergeManagedFile(path10.join(root, "CLAUDE.md"), mergeChironAgentInstructions, result, "CLAUDE.md");
|
|
10078
|
+
await mergeManagedFile(path10.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
|
|
10079
|
+
return result;
|
|
10080
|
+
}
|
|
10081
|
+
async function runChironInit(args, deps = defaultChironInitDeps) {
|
|
10082
|
+
const root = path10.resolve(args.project ?? ".");
|
|
10083
|
+
const { name, env: env2, identity: identity2 } = await resolveLoggedInEnv();
|
|
10084
|
+
const say = (line) => process.stderr.write(`[chiron init] ${line}
|
|
10085
|
+
`);
|
|
10086
|
+
const actual = await deps.tokenTenant(name, env2.tenant);
|
|
10087
|
+
if (actual && actual !== env2.tenant) {
|
|
10088
|
+
say(`env ${name} \u8BB0\u7684\u79DF\u6237\u662F ${env2.tenant}\uFF0C\u4F46\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${actual}\uFF0C\u6309 ${actual} \u5199 ${ENV_FILE}`);
|
|
10089
|
+
env2.tenant = actual;
|
|
10090
|
+
}
|
|
10091
|
+
say(`\u73AF\u5883 ${name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant} \xB7 \u8EAB\u4EFD ${identity2}`);
|
|
10092
|
+
const scaffold = await scaffoldChironProject(root, env2, name);
|
|
10093
|
+
say(`\u9AA8\u67B6\uFF1A\u65B0\u5EFA ${scaffold.created.length} \xB7 \u66F4\u65B0 ${scaffold.updated.length} \xB7 \u4FDD\u7559 ${scaffold.preserved.length}`);
|
|
10094
|
+
let skills2 = "skipped";
|
|
10095
|
+
if (!args.skipSkills) {
|
|
10096
|
+
say("\u88C5\u777F\u620E\u6280\u80FD\uFF08\u5168\u90E8\uFF0CCodex \u5E03\u5C40\uFF09\u2026");
|
|
10097
|
+
await deps.installSkills(root, name);
|
|
10098
|
+
skills2 = "installed";
|
|
10099
|
+
}
|
|
10100
|
+
let cases = { ok: false, step: "skipped" };
|
|
10101
|
+
if (!args.skipCases) {
|
|
10102
|
+
say("\u63A5\u6848\u4F8B\u5E93\uFF08chiron-cases MCP\uFF09\u2026");
|
|
10103
|
+
cases = await deps.caseLibrary(name);
|
|
10104
|
+
if (cases.ok) say(`\u6848\u4F8B\u5E93\u5DF2\u63A5\u5165 Codex\uFF1A${cases.repo}`);
|
|
10105
|
+
else say(`\u6848\u4F8B\u5E93\u672A\u63A5\u5165\uFF08\u4E0D\u5F71\u54CD\u5F00\u5DE5\uFF0C\u7528\u5230\u65F6\u4F1A\u63D0\u793A\u6743\u9650\u4E0D\u8DB3\uFF09\uFF1A${cases.reason ?? cases.step}`);
|
|
10106
|
+
}
|
|
10107
|
+
return {
|
|
10108
|
+
project: root,
|
|
10109
|
+
env: name,
|
|
10110
|
+
endpoint: env2.endpoint,
|
|
10111
|
+
frontend: env2.frontend,
|
|
10112
|
+
tenant: env2.tenant,
|
|
10113
|
+
identity: identity2,
|
|
10114
|
+
scaffold,
|
|
10115
|
+
skills: skills2,
|
|
10116
|
+
cases,
|
|
10117
|
+
nextStep: "hcm chiron doctor \u6838\u5BF9\u4E00\u904D\uFF0C\u7136\u540E\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex"
|
|
10118
|
+
};
|
|
10119
|
+
}
|
|
10120
|
+
async function chironInitCommand(args, deps) {
|
|
10121
|
+
try {
|
|
10122
|
+
const result = await runChironInit(args, deps);
|
|
10123
|
+
const fmt = args.output ?? "table";
|
|
10124
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
10125
|
+
process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
|
|
10126
|
+
} else {
|
|
10127
|
+
process.stdout.write(
|
|
10128
|
+
[
|
|
10129
|
+
`\u2705 \u9879\u76EE\u5DF2\u521D\u59CB\u5316\uFF1A${result.project}`,
|
|
10130
|
+
` \u73AF\u5883 ${result.env} \xB7 ${result.endpoint} \xB7 \u79DF\u6237 ${result.tenant} \xB7 \u8EAB\u4EFD ${result.identity}`,
|
|
10131
|
+
` \u6280\u80FD ${result.skills === "installed" ? `\u5DF2\u88C5\u5230 ${SKILLS_DIR}/` : "\u672A\u88C5\uFF08--skip-skills\uFF09"}`,
|
|
10132
|
+
` \u6848\u4F8B\u5E93 ${result.cases.ok ? "\u5DF2\u63A5\u5165 Codex" : `\u672A\u63A5\u5165\uFF1A${"reason" in result.cases && result.cases.reason ? result.cases.reason : result.cases.step}`}`,
|
|
10133
|
+
` \u4E0B\u4E00\u6B65\uFF1A${result.nextStep}`
|
|
10134
|
+
].join("\n") + "\n"
|
|
10135
|
+
);
|
|
10136
|
+
}
|
|
10137
|
+
process.exitCode = 0;
|
|
10138
|
+
} catch (e) {
|
|
10139
|
+
exitWithError(e);
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
10142
|
+
|
|
10143
|
+
// src/commands/chiron-doctor.ts
|
|
10144
|
+
init_auth_guard();
|
|
10145
|
+
init_exit();
|
|
10146
|
+
import { promises as fs11 } from "fs";
|
|
10147
|
+
import path11 from "path";
|
|
10148
|
+
import {
|
|
10149
|
+
HcmClient as HcmClient23,
|
|
10150
|
+
CliError as CliError22,
|
|
10151
|
+
fetchReconIdentity as fetchReconIdentity3,
|
|
10152
|
+
formatObject as formatObject25,
|
|
10153
|
+
httpProbe as httpProbe3,
|
|
10154
|
+
runDoctor as runDoctor2
|
|
10155
|
+
} from "@hcmai/sdk";
|
|
10156
|
+
var defaultDeps = {
|
|
10157
|
+
anchors: async (envName, tenant2) => {
|
|
10158
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
10159
|
+
const client3 = HcmClient23.fromAuthContext(ctx);
|
|
10160
|
+
const probe = httpProbe3(client3.raw(), "default");
|
|
10161
|
+
const identity2 = await fetchReconIdentity3(probe, tenant2);
|
|
10162
|
+
return { report: await runDoctor2(probe, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
|
|
10163
|
+
},
|
|
10164
|
+
fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
|
|
10165
|
+
fixCases: async (envName) => {
|
|
10166
|
+
await ensureCaseLibrary(envName);
|
|
10167
|
+
},
|
|
10168
|
+
inspectCases: () => inspectCaseLibrary()
|
|
10169
|
+
};
|
|
10170
|
+
async function runChironDoctor(args, deps = defaultDeps) {
|
|
10171
|
+
const root = path11.resolve(args.project ?? ".");
|
|
10172
|
+
const report = { ok: false, project: root, env: null, envName: null, lines: [] };
|
|
10173
|
+
const envText = await fs11.readFile(path11.join(root, ENV_FILE), "utf8").catch(() => null);
|
|
10174
|
+
if (envText === null) {
|
|
10175
|
+
report.lines.push({
|
|
10176
|
+
item: "\u767B\u5F55",
|
|
10177
|
+
verdict: "fail",
|
|
10178
|
+
detail: `\u8FD9\u4E2A\u76EE\u5F55\u91CC\u6CA1\u6709 ${ENV_FILE}\uFF0C\u4E0D\u662F\u777F\u620E\u9879\u76EE\u4ED3\uFF08\u6216\u8FD8\u6CA1\u521D\u59CB\u5316\uFF09`,
|
|
10179
|
+
nextStep: "\u65B0\u4ED3\uFF1Ahcm login <\u5730\u5740> --code <\u914D\u5BF9\u7801> \u540E hcm chiron init\uFF1B\u5DF2\u6709\u4ED3\uFF1A\u786E\u8BA4 clone \u7684\u662F\u5BF9\u7684\u4ED3\u3001\u7AD9\u5728\u4ED3\u6839\u76EE\u5F55"
|
|
10180
|
+
});
|
|
10181
|
+
return finish(report);
|
|
10182
|
+
}
|
|
10183
|
+
let env2;
|
|
10184
|
+
try {
|
|
10185
|
+
env2 = parseEnvYaml(envText);
|
|
10186
|
+
} catch (e) {
|
|
10187
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: e.message, nextStep: `\u6309 hcm chiron init \u751F\u6210\u7684\u4E09\u884C\u5F62\u6001\u4FEE ${ENV_FILE}` });
|
|
10188
|
+
return finish(report);
|
|
10189
|
+
}
|
|
10190
|
+
report.env = env2;
|
|
10191
|
+
const found = await findEnvByEndpoint(env2.endpoint);
|
|
10192
|
+
const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
|
|
10193
|
+
if (!found) {
|
|
10194
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
|
|
10195
|
+
} else {
|
|
10196
|
+
report.envName = found.name;
|
|
10197
|
+
try {
|
|
10198
|
+
const { report: anchors, tokenTenant } = await deps.anchors(found.name, env2.tenant);
|
|
10199
|
+
report.anchors = anchors;
|
|
10200
|
+
const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
|
|
10201
|
+
const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
|
|
10202
|
+
if (bad.length === 0 && !tenantMismatch) {
|
|
10203
|
+
const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
|
|
10204
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
|
|
10205
|
+
} else {
|
|
10206
|
+
const parts = [`${found.name} \xB7 ${env2.endpoint}`];
|
|
10207
|
+
if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
|
|
10208
|
+
if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
|
|
10209
|
+
report.lines.push({
|
|
10210
|
+
item: "\u767B\u5F55",
|
|
10211
|
+
verdict: "fail",
|
|
10212
|
+
detail: parts.join("\uFF1B"),
|
|
10213
|
+
nextStep: tenantMismatch ? `${loginCmd}\uFF08\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\uFF09` : "\u6309\u4E0A\u9762\u951A\u70B9\u7684\u63D0\u793A\u5904\u7406\uFF1B\u8EAB\u4EFD\u8FC7\u671F\u5C31\u91CD\u65B0 " + loginCmd
|
|
10214
|
+
});
|
|
10215
|
+
}
|
|
10216
|
+
} catch (e) {
|
|
10217
|
+
const msg = e instanceof CliError22 ? e.message : e.message;
|
|
10218
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
|
|
10219
|
+
}
|
|
10220
|
+
}
|
|
10221
|
+
const skillsLine = async () => {
|
|
10222
|
+
const state = await readSkillsState(path11.join(root, SKILLS_DIR));
|
|
10223
|
+
if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron doctor --fix\uFF08\u6216 hcm chiron init\uFF09" };
|
|
10224
|
+
const count = Object.keys(state.skills).length;
|
|
10225
|
+
if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
|
|
10226
|
+
return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: "hcm chiron doctor --fix \u91CD\u88C5" };
|
|
10227
|
+
}
|
|
10228
|
+
if (state.target !== "codex") {
|
|
10229
|
+
return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: "hcm skills install --all --target codex" };
|
|
10230
|
+
}
|
|
10231
|
+
return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
|
|
10232
|
+
};
|
|
10233
|
+
let skills2 = await skillsLine();
|
|
10234
|
+
if (skills2.verdict === "fail" && args.fix && report.envName) {
|
|
10235
|
+
await deps.fixSkills(root, report.envName);
|
|
10236
|
+
skills2 = await skillsLine();
|
|
10237
|
+
}
|
|
10238
|
+
report.lines.push(skills2);
|
|
10239
|
+
const casesLine = async () => {
|
|
10240
|
+
const c = await deps.inspectCases();
|
|
10241
|
+
if (!c.cloned) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: `\u672A clone\uFF08${c.repo}\uFF09`, nextStep: "hcm chiron doctor --fix\uFF1B\u6CA1\u6709 cnb \u6743\u9650\u5C31\u5148\u8DF3\u8FC7\uFF0C\u63D0\u4EA4\u6848\u4F8B/\u7F3A\u53E3\u65F6\u4F1A\u63D0\u793A" };
|
|
10242
|
+
if (!c.serverInstalled) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "MCP \u4F9D\u8D56\u6CA1\u88C5", nextStep: "hcm chiron doctor --fix" };
|
|
10243
|
+
if (!c.codexWired) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "Codex \u6CA1\u63A5\u7EBF\uFF08~/.codex/config.toml \u7F3A [mcp_servers.chiron-cases]\uFF09", nextStep: "hcm chiron doctor --fix" };
|
|
10244
|
+
return { item: "\u6848\u4F8B\u5E93", verdict: "ok", detail: `\u5DF2\u63A5\u5165 Codex\uFF08${c.repo}\uFF09` };
|
|
10245
|
+
};
|
|
10246
|
+
let cases = await casesLine();
|
|
10247
|
+
if (cases.verdict !== "ok" && args.fix && report.envName) {
|
|
10248
|
+
await deps.fixCases(report.envName);
|
|
10249
|
+
cases = await casesLine();
|
|
10250
|
+
}
|
|
10251
|
+
report.lines.push(cases);
|
|
10252
|
+
return finish(report);
|
|
10253
|
+
}
|
|
10254
|
+
function finish(report) {
|
|
10255
|
+
report.ok = report.lines.every((l) => l.verdict !== "fail");
|
|
10256
|
+
return report;
|
|
10257
|
+
}
|
|
10258
|
+
function renderChironDoctor(report) {
|
|
10259
|
+
const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
|
|
10260
|
+
const out = [];
|
|
10261
|
+
for (const l of report.lines) {
|
|
10262
|
+
out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
|
|
10263
|
+
if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
|
|
10264
|
+
}
|
|
10265
|
+
out.push("");
|
|
10266
|
+
out.push(report.ok ? "\u53EF\u4EE5\u5F00\u5DE5\uFF1A\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex\u3002" : "\u5148\u6309 \u2192 \u5904\u7406\u7EA2\u9879\uFF0C\u518D\u8DD1\u4E00\u6B21 hcm chiron doctor\u3002");
|
|
10267
|
+
return out.join("\n");
|
|
10268
|
+
}
|
|
10269
|
+
async function chironDoctorCommand(args, deps) {
|
|
10270
|
+
try {
|
|
10271
|
+
const report = await runChironDoctor(args, deps);
|
|
10272
|
+
const fmt = args.output ?? "table";
|
|
10273
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject25(report, { format: fmt }) + "\n");
|
|
10274
|
+
else process.stdout.write(renderChironDoctor(report) + "\n");
|
|
10275
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
10276
|
+
} catch (e) {
|
|
10277
|
+
exitWithError(e);
|
|
10278
|
+
}
|
|
10279
|
+
}
|
|
10280
|
+
|
|
10281
|
+
// src/commands/delivery-recon.ts
|
|
10282
|
+
init_auth_guard();
|
|
10283
|
+
init_exit();
|
|
10284
|
+
import {
|
|
10285
|
+
HcmClient as HcmClient24,
|
|
9569
10286
|
ReconLayout,
|
|
9570
10287
|
ROUND_EXIT_CODES,
|
|
9571
10288
|
computeReconSourceKey,
|
|
9572
|
-
formatObject as
|
|
10289
|
+
formatObject as formatObject26,
|
|
9573
10290
|
fromAxiosError as fromAxiosError22,
|
|
9574
|
-
httpProbe as
|
|
10291
|
+
httpProbe as httpProbe4,
|
|
9575
10292
|
inspectRound,
|
|
9576
10293
|
renderRound,
|
|
9577
10294
|
runRecon
|
|
@@ -9580,8 +10297,8 @@ var DEFAULT_CAPABILITIES2 = "default";
|
|
|
9580
10297
|
async function deliveryReconCommand(args) {
|
|
9581
10298
|
try {
|
|
9582
10299
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
9583
|
-
const client3 =
|
|
9584
|
-
const probe =
|
|
10300
|
+
const client3 = HcmClient24.fromAuthContext(ctx);
|
|
10301
|
+
const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES2);
|
|
9585
10302
|
const sourceKey = await computeReconSourceKey(probe);
|
|
9586
10303
|
const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
|
|
9587
10304
|
const summary = await runRecon(probe, layout, {
|
|
@@ -9589,7 +10306,7 @@ async function deliveryReconCommand(args) {
|
|
|
9589
10306
|
onlyModel: args.model ?? null,
|
|
9590
10307
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
9591
10308
|
});
|
|
9592
|
-
process.stdout.write(
|
|
10309
|
+
process.stdout.write(formatObject26(summary, { format: args.output ?? "json" }) + "\n");
|
|
9593
10310
|
} catch (e) {
|
|
9594
10311
|
const err = e;
|
|
9595
10312
|
if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
|
|
@@ -9603,13 +10320,14 @@ async function deliveryReconRoundCommand(args) {
|
|
|
9603
10320
|
const result = inspectRound(args.dir ?? ".");
|
|
9604
10321
|
const fmt = args.output ?? "json";
|
|
9605
10322
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
9606
|
-
process.stdout.write(
|
|
10323
|
+
process.stdout.write(formatObject26(result, { format: fmt }) + "\n");
|
|
9607
10324
|
code = ROUND_EXIT_CODES[result.state];
|
|
9608
10325
|
} catch (e) {
|
|
9609
10326
|
exitWithError(e);
|
|
9610
10327
|
code = 1;
|
|
9611
10328
|
}
|
|
9612
|
-
process.
|
|
10329
|
+
process.exitCode = code;
|
|
10330
|
+
return;
|
|
9613
10331
|
}
|
|
9614
10332
|
|
|
9615
10333
|
// src/commands/delivery-gate0.ts
|
|
@@ -9621,14 +10339,14 @@ import {
|
|
|
9621
10339
|
GAP_REASONS,
|
|
9622
10340
|
deriveAclass,
|
|
9623
10341
|
exitCode as gate0ExitCode,
|
|
9624
|
-
formatObject as
|
|
10342
|
+
formatObject as formatObject27,
|
|
9625
10343
|
inspectRound as inspectRound2,
|
|
9626
10344
|
loadProtocolFacts,
|
|
9627
10345
|
scan
|
|
9628
10346
|
} from "@hcmai/sdk";
|
|
9629
|
-
import * as
|
|
10347
|
+
import * as path12 from "path";
|
|
9630
10348
|
function renderGate0(result, skillRoot) {
|
|
9631
|
-
const where = skillRoot ? `\uFF08${
|
|
10349
|
+
const where = skillRoot ? `\uFF08${path12.resolve(skillRoot)}\uFF09` : "";
|
|
9632
10350
|
const lines = [
|
|
9633
10351
|
`\u626B\u63CF\u9762${where}\uFF1A${result.scanned.length} \u4E2A\u6587\u4EF6\uFF1B\u5224\u7EA2 ${result.red.length} \u6761\uFF1B\u7F3A\u53E3\u653E\u884C ${result.gaps.length} \u6761\u3002`
|
|
9634
10352
|
];
|
|
@@ -9666,7 +10384,7 @@ async function deliveryGate0Command(args) {
|
|
|
9666
10384
|
const merged = { ...result, premise: premise5 };
|
|
9667
10385
|
const fmt = args.output ?? "json";
|
|
9668
10386
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
9669
|
-
process.stdout.write(`${
|
|
10387
|
+
process.stdout.write(`${formatObject27(merged, { format: fmt })}
|
|
9670
10388
|
`);
|
|
9671
10389
|
for (const problem of premise5) {
|
|
9672
10390
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -9677,7 +10395,8 @@ async function deliveryGate0Command(args) {
|
|
|
9677
10395
|
exitWithError(e);
|
|
9678
10396
|
code = 1;
|
|
9679
10397
|
}
|
|
9680
|
-
process.
|
|
10398
|
+
process.exitCode = code;
|
|
10399
|
+
return;
|
|
9681
10400
|
}
|
|
9682
10401
|
|
|
9683
10402
|
// src/commands/delivery-seed.ts
|
|
@@ -9690,8 +10409,8 @@ import {
|
|
|
9690
10409
|
DRY_RUN_TAIL,
|
|
9691
10410
|
DriftDetected,
|
|
9692
10411
|
FORCE_STALE_FLAG,
|
|
9693
|
-
HcmClient as
|
|
9694
|
-
fetchReconIdentity as
|
|
10412
|
+
HcmClient as HcmClient25,
|
|
10413
|
+
fetchReconIdentity as fetchReconIdentity4,
|
|
9695
10414
|
INIT_EXIT_CODES,
|
|
9696
10415
|
JOURNAL_STOP_KINDS,
|
|
9697
10416
|
JOURNAL_STOP_UNKNOWN,
|
|
@@ -9740,7 +10459,7 @@ import {
|
|
|
9740
10459
|
writeRisk
|
|
9741
10460
|
} from "@hcmai/sdk";
|
|
9742
10461
|
import { existsSync as existsSync3 } from "fs";
|
|
9743
|
-
import * as
|
|
10462
|
+
import * as path13 from "path";
|
|
9744
10463
|
function premise(message, hint = "") {
|
|
9745
10464
|
process.stderr.write(message + (hint ? `
|
|
9746
10465
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -9767,13 +10486,13 @@ async function runSeedPlan(args, client3) {
|
|
|
9767
10486
|
const reconDir = candidates[0].reconDir;
|
|
9768
10487
|
if (candidates.length > 1) {
|
|
9769
10488
|
process.stderr.write(
|
|
9770
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
10489
|
+
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path13.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path13.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
|
|
9771
10490
|
);
|
|
9772
10491
|
}
|
|
9773
10492
|
const round = inspectRound3(reconDir);
|
|
9774
10493
|
process.stderr.write(roundWarning(round));
|
|
9775
10494
|
const baseline = {
|
|
9776
|
-
path: `${
|
|
10495
|
+
path: `${path13.basename(path13.dirname(reconDir))}/${path13.basename(reconDir)}`,
|
|
9777
10496
|
roundId: round.roundId ?? null
|
|
9778
10497
|
};
|
|
9779
10498
|
let exemptions = null;
|
|
@@ -9830,7 +10549,7 @@ async function authOrSignpost(args, cmd) {
|
|
|
9830
10549
|
}
|
|
9831
10550
|
async function deliverySeedPlanCommand(args) {
|
|
9832
10551
|
const ctx = await authOrSignpost(args, "plan");
|
|
9833
|
-
const client3 =
|
|
10552
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
9834
10553
|
process.exitCode = await runSeedPlan(args, seedClient(client3, ctx));
|
|
9835
10554
|
}
|
|
9836
10555
|
function seedClient(client3, ctx) {
|
|
@@ -9866,7 +10585,7 @@ function seedClient(client3, ctx) {
|
|
|
9866
10585
|
}
|
|
9867
10586
|
async function seedVerifyClient(client3, ctx) {
|
|
9868
10587
|
const base = seedClient(client3, ctx);
|
|
9869
|
-
const identity2 = await
|
|
10588
|
+
const identity2 = await fetchReconIdentity4(base, String(ctx.tenantId ?? ""));
|
|
9870
10589
|
return { ...base, identity: identity2 };
|
|
9871
10590
|
}
|
|
9872
10591
|
function lowerCaseHeaders(headers) {
|
|
@@ -10004,7 +10723,7 @@ async function runSeedApply(args, client3) {
|
|
|
10004
10723
|
}
|
|
10005
10724
|
async function deliverySeedApplyCommand(args) {
|
|
10006
10725
|
const ctx = await authOrSignpost(args, "apply");
|
|
10007
|
-
const client3 =
|
|
10726
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10008
10727
|
process.exitCode = await runSeedApply(args, seedClient(client3, ctx));
|
|
10009
10728
|
}
|
|
10010
10729
|
async function runSeedVerify(args, client3) {
|
|
@@ -10028,14 +10747,14 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
10028
10747
|
return;
|
|
10029
10748
|
}
|
|
10030
10749
|
const ctx = await authOrSignpost(args, "verify");
|
|
10031
|
-
const client3 =
|
|
10750
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10032
10751
|
process.exitCode = await runSeedVerify(args, await seedVerifyClient(client3, ctx));
|
|
10033
10752
|
}
|
|
10034
10753
|
|
|
10035
10754
|
// src/commands/delivery-seed-find.ts
|
|
10036
10755
|
import { existsSync as existsSync4 } from "fs";
|
|
10037
10756
|
import { readFileSync as readFileSync6 } from "fs";
|
|
10038
|
-
import * as
|
|
10757
|
+
import * as path14 from "path";
|
|
10039
10758
|
import {
|
|
10040
10759
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
10041
10760
|
ValueHints,
|
|
@@ -10049,10 +10768,10 @@ import {
|
|
|
10049
10768
|
valuesRoundCaveat
|
|
10050
10769
|
} from "@hcmai/sdk";
|
|
10051
10770
|
function provenance(chosenReconDir, others) {
|
|
10052
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
10771
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path14.basename(chosenReconDir)}\`
|
|
10053
10772
|
`;
|
|
10054
10773
|
if (others.length > 0) {
|
|
10055
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
10774
|
+
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path14.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
|
|
10056
10775
|
}
|
|
10057
10776
|
return `${line}
|
|
10058
10777
|
`;
|
|
@@ -10143,7 +10862,7 @@ import {
|
|
|
10143
10862
|
CHANGE_STATES,
|
|
10144
10863
|
CHANGE_UNKNOWN,
|
|
10145
10864
|
CODE_WORDS,
|
|
10146
|
-
HcmClient as
|
|
10865
|
+
HcmClient as HcmClient26,
|
|
10147
10866
|
INIT_EXIT_CODES as INIT_EXIT_CODES3,
|
|
10148
10867
|
META_WRITE_STEPS,
|
|
10149
10868
|
META_VERIFY_STEPS,
|
|
@@ -10371,7 +11090,7 @@ function lowerCaseHeaders2(headers) {
|
|
|
10371
11090
|
}
|
|
10372
11091
|
async function deliveryMetaCommand(args) {
|
|
10373
11092
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10374
|
-
const client3 =
|
|
11093
|
+
const client3 = HcmClient26.fromAuthContext(ctx);
|
|
10375
11094
|
process.exitCode = await runDeliveryMeta(
|
|
10376
11095
|
{ ...args, tenant: args.tenant ?? String(ctx.tenantId ?? "") },
|
|
10377
11096
|
metaClient(client3, ctx)
|
|
@@ -10383,13 +11102,13 @@ init_auth_guard();
|
|
|
10383
11102
|
init_exit();
|
|
10384
11103
|
import {
|
|
10385
11104
|
computeReconSourceKey as computeReconSourceKey2,
|
|
10386
|
-
HcmClient as
|
|
10387
|
-
httpProbe as
|
|
11105
|
+
HcmClient as HcmClient27,
|
|
11106
|
+
httpProbe as httpProbe5,
|
|
10388
11107
|
ReconLayout as ReconLayout2,
|
|
10389
11108
|
runTriageRound
|
|
10390
11109
|
} from "@hcmai/sdk";
|
|
10391
11110
|
import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
|
|
10392
|
-
import * as
|
|
11111
|
+
import * as path15 from "path";
|
|
10393
11112
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
10394
11113
|
function premise4(message, hint) {
|
|
10395
11114
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -10425,8 +11144,8 @@ function renderProblems(rows) {
|
|
|
10425
11144
|
`;
|
|
10426
11145
|
}
|
|
10427
11146
|
function writeTriageArtifact(outDir, body) {
|
|
10428
|
-
const out =
|
|
10429
|
-
mkdirSync(
|
|
11147
|
+
const out = path15.join(outDir, "work", "triage.md");
|
|
11148
|
+
mkdirSync(path15.dirname(out), { recursive: true });
|
|
10430
11149
|
writeFileSync2(out, body, "utf8");
|
|
10431
11150
|
return out;
|
|
10432
11151
|
}
|
|
@@ -10439,8 +11158,8 @@ async function runTriage(args) {
|
|
|
10439
11158
|
return premise4(e instanceof Error ? e.message : String(e), REQUESTS_SHAPE);
|
|
10440
11159
|
}
|
|
10441
11160
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10442
|
-
const client3 =
|
|
10443
|
-
const probe =
|
|
11161
|
+
const client3 = HcmClient27.fromAuthContext(ctx);
|
|
11162
|
+
const probe = httpProbe5(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES4);
|
|
10444
11163
|
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
|
|
10445
11164
|
const result = await runTriageRound(probe, artifactsDir, entriesIn);
|
|
10446
11165
|
if (result.body === null) {
|
|
@@ -10460,15 +11179,16 @@ async function deliveryTriageCommand(args) {
|
|
|
10460
11179
|
exitWithError(e);
|
|
10461
11180
|
code = 1;
|
|
10462
11181
|
}
|
|
10463
|
-
process.
|
|
11182
|
+
process.exitCode = code;
|
|
11183
|
+
return;
|
|
10464
11184
|
}
|
|
10465
11185
|
|
|
10466
11186
|
// src/commands/delivery-execution.ts
|
|
10467
11187
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
10468
11188
|
import { spawn as spawn2 } from "child_process";
|
|
10469
|
-
import { createReadStream, promises as
|
|
10470
|
-
import
|
|
10471
|
-
import { CliError as
|
|
11189
|
+
import { createReadStream, promises as fs12 } from "fs";
|
|
11190
|
+
import path16 from "path";
|
|
11191
|
+
import { CliError as CliError23, CliErrorCode as CliErrorCode21, formatObject as formatObject28 } from "@hcmai/sdk";
|
|
10472
11192
|
init_exit();
|
|
10473
11193
|
var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
|
|
10474
11194
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -10510,11 +11230,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
10510
11230
|
};
|
|
10511
11231
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
10512
11232
|
const plan = { ...core, planId };
|
|
10513
|
-
const plansDir =
|
|
11233
|
+
const plansDir = path16.join(project, ".hcm-delivery", "execution-plans");
|
|
10514
11234
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
10515
|
-
const planFile =
|
|
11235
|
+
const planFile = path16.join(plansDir, `${planId}.json`);
|
|
10516
11236
|
try {
|
|
10517
|
-
await
|
|
11237
|
+
await fs12.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
10518
11238
|
`, {
|
|
10519
11239
|
encoding: "utf8",
|
|
10520
11240
|
mode: 384,
|
|
@@ -10528,7 +11248,7 @@ async function prepareDeliveryExecution(input) {
|
|
|
10528
11248
|
async function executeDeliveryPlan(input) {
|
|
10529
11249
|
if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
|
|
10530
11250
|
const project = await realProject(input.project);
|
|
10531
|
-
const planFile =
|
|
11251
|
+
const planFile = path16.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
10532
11252
|
const plan = await readPlan(project, planFile);
|
|
10533
11253
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
10534
11254
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -10565,13 +11285,13 @@ async function executeDeliveryPlan(input) {
|
|
|
10565
11285
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
10566
11286
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
10567
11287
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
10568
|
-
const receiptFile =
|
|
11288
|
+
const receiptFile = path16.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
10569
11289
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
10570
|
-
const claimsDir =
|
|
11290
|
+
const claimsDir = path16.join(project, ".hcm-delivery", "execution-claims");
|
|
10571
11291
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
10572
|
-
const claimFile =
|
|
11292
|
+
const claimFile = path16.join(claimsDir, `${plan.planId}.json`);
|
|
10573
11293
|
try {
|
|
10574
|
-
await
|
|
11294
|
+
await fs12.writeFile(
|
|
10575
11295
|
claimFile,
|
|
10576
11296
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
10577
11297
|
`,
|
|
@@ -10628,7 +11348,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
10628
11348
|
evidenceDir: args.evidenceDir,
|
|
10629
11349
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
10630
11350
|
});
|
|
10631
|
-
process.stdout.write(
|
|
11351
|
+
process.stdout.write(formatObject28(plan, { format: args.output ?? "json" }) + "\n");
|
|
10632
11352
|
process.stderr.write(`
|
|
10633
11353
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
10634
11354
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -10649,14 +11369,17 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
10649
11369
|
planId,
|
|
10650
11370
|
argv
|
|
10651
11371
|
});
|
|
10652
|
-
|
|
10653
|
-
process.exitCode = receipt.exitCode;
|
|
11372
|
+
writeDeliveryExecutionReceipt(receipt, args.output ?? "json");
|
|
10654
11373
|
} catch (cause) {
|
|
10655
11374
|
exitWithError(cause);
|
|
10656
11375
|
}
|
|
10657
11376
|
}
|
|
11377
|
+
function writeDeliveryExecutionReceipt(receipt, format = "json") {
|
|
11378
|
+
process.stderr.write(formatObject28(receipt, { format }) + "\n");
|
|
11379
|
+
process.exitCode = receipt.exitCode;
|
|
11380
|
+
}
|
|
10658
11381
|
async function readProjectMode(project, environment) {
|
|
10659
|
-
const file =
|
|
11382
|
+
const file = path16.join(project, ".hcm-delivery", "project.yml");
|
|
10660
11383
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
10661
11384
|
let mode;
|
|
10662
11385
|
try {
|
|
@@ -10672,13 +11395,13 @@ async function readProjectMode(project, environment) {
|
|
|
10672
11395
|
return mode;
|
|
10673
11396
|
}
|
|
10674
11397
|
var SKILLS_LOCK_CANDIDATES = [
|
|
10675
|
-
|
|
10676
|
-
|
|
11398
|
+
path16.join("hcm-skills", ".hcm-skills.json"),
|
|
11399
|
+
path16.join(".claude", "skills", ".hcm-skills.json")
|
|
10677
11400
|
];
|
|
10678
11401
|
async function readSkillsLock(project) {
|
|
10679
11402
|
const found = [];
|
|
10680
11403
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
10681
|
-
if (await pathExists(
|
|
11404
|
+
if (await pathExists(path16.join(project, candidate))) found.push(candidate);
|
|
10682
11405
|
}
|
|
10683
11406
|
if (found.length === 0) {
|
|
10684
11407
|
throw invalid2(
|
|
@@ -10690,7 +11413,7 @@ async function readSkillsLock(project) {
|
|
|
10690
11413
|
`\u9879\u76EE\u91CC\u6709\u591A\u4EFD\u6280\u80FD\u9501\uFF08${found.join("\u3001")}\uFF09\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u53D7\u63A7\u6267\u884C\u7ED1\u5B9A\u54EA\u4E00\u4EFD\u3002next_step=\u53EA\u4FDD\u7559\u5B9E\u9645\u5728\u7528\u7684\u90A3\u4E2A\u6280\u80FD\u76EE\u5F55`
|
|
10691
11414
|
);
|
|
10692
11415
|
}
|
|
10693
|
-
const bytes = await readSafeFile(project,
|
|
11416
|
+
const bytes = await readSafeFile(project, path16.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
10694
11417
|
try {
|
|
10695
11418
|
JSON.parse(bytes.toString("utf8"));
|
|
10696
11419
|
} catch (cause) {
|
|
@@ -10703,7 +11426,7 @@ async function bindDocument(project, reference, label) {
|
|
|
10703
11426
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
10704
11427
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
10705
11428
|
}
|
|
10706
|
-
const file =
|
|
11429
|
+
const file = path16.join(project, relative2);
|
|
10707
11430
|
const bytes = await readSafeFile(project, file, label);
|
|
10708
11431
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
10709
11432
|
}
|
|
@@ -10716,11 +11439,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
10716
11439
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
10717
11440
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
10718
11441
|
}
|
|
10719
|
-
const absolute =
|
|
11442
|
+
const absolute = path16.join(project, relative2);
|
|
10720
11443
|
await assertNoSymlinkComponents(project, relative2);
|
|
10721
|
-
const stat = await
|
|
11444
|
+
const stat = await fs12.stat(absolute).catch(() => null);
|
|
10722
11445
|
if (stat === null) {
|
|
10723
|
-
await
|
|
11446
|
+
await fs12.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
10724
11447
|
throw invalid2(
|
|
10725
11448
|
`evidence \u76EE\u5F55\u5EFA\u4E0D\u51FA\u6765\uFF1A${relative2}\u3002next_step=\u68C0\u67E5\u4E0A\u7EA7\u76EE\u5F55\u6743\u9650\uFF0C\u6216\u6362\u4E00\u4E2A evidence/ \u4E0B\u7684\u8DEF\u5F84`,
|
|
10726
11449
|
cause
|
|
@@ -10900,7 +11623,7 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
10900
11623
|
const relative2 = safeRelative(reference, label);
|
|
10901
11624
|
let stat;
|
|
10902
11625
|
try {
|
|
10903
|
-
stat = await
|
|
11626
|
+
stat = await fs12.stat(path16.join(project, relative2));
|
|
10904
11627
|
} catch (cause) {
|
|
10905
11628
|
throw invalid2(
|
|
10906
11629
|
`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}\u3002next_step=\u628A\u6570\u636E\u96C6\u653E\u8FDB\u9879\u76EE\u76EE\u5F55\u5185\uFF0C\u5E76\u7528\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84\u5F15\u7528\uFF08\u53D7\u63A7\u6267\u884C\u53EA\u9489\u5F97\u4F4F\u9879\u76EE\u5185\u7684\u8F7D\u8377\uFF09`,
|
|
@@ -10911,10 +11634,10 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
10911
11634
|
}
|
|
10912
11635
|
async function bindPayloadDirectory(project, reference, label) {
|
|
10913
11636
|
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
10914
|
-
const root =
|
|
11637
|
+
const root = path16.join(project, relative2);
|
|
10915
11638
|
let stat;
|
|
10916
11639
|
try {
|
|
10917
|
-
stat = await
|
|
11640
|
+
stat = await fs12.stat(root);
|
|
10918
11641
|
} catch {
|
|
10919
11642
|
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
10920
11643
|
}
|
|
@@ -10924,10 +11647,10 @@ async function bindPayloadDirectory(project, reference, label) {
|
|
|
10924
11647
|
const skipToolingAtRoot = relative2 === ".";
|
|
10925
11648
|
const entries = [];
|
|
10926
11649
|
const walk = async (dir, prefix) => {
|
|
10927
|
-
const items = await
|
|
11650
|
+
const items = await fs12.readdir(dir, { withFileTypes: true });
|
|
10928
11651
|
for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
10929
11652
|
if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
|
|
10930
|
-
const child =
|
|
11653
|
+
const child = path16.join(dir, item.name);
|
|
10931
11654
|
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
10932
11655
|
if (item.isSymbolicLink()) {
|
|
10933
11656
|
throw invalid2(
|
|
@@ -10952,7 +11675,7 @@ ${sha2565(bytes)}`);
|
|
|
10952
11675
|
}
|
|
10953
11676
|
async function bindPayloadFile(project, reference, label) {
|
|
10954
11677
|
const relative2 = safeRelative(reference, label);
|
|
10955
|
-
const file =
|
|
11678
|
+
const file = path16.join(project, relative2);
|
|
10956
11679
|
const bytes = await readSafeFile(project, file, label);
|
|
10957
11680
|
return { path: relative2, kind: "file", sha256: sha2565(bytes) };
|
|
10958
11681
|
}
|
|
@@ -11015,29 +11738,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
11015
11738
|
async function writeReceiptExclusive(target, receipt) {
|
|
11016
11739
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
11017
11740
|
try {
|
|
11018
|
-
await
|
|
11741
|
+
await fs12.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
11019
11742
|
`, {
|
|
11020
11743
|
encoding: "utf8",
|
|
11021
11744
|
mode: 384,
|
|
11022
11745
|
flag: "wx"
|
|
11023
11746
|
});
|
|
11024
|
-
await
|
|
11747
|
+
await fs12.link(temp, target);
|
|
11025
11748
|
} catch (cause) {
|
|
11026
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
11749
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path16.basename(target)}`, cause);
|
|
11027
11750
|
} finally {
|
|
11028
|
-
await
|
|
11751
|
+
await fs12.unlink(temp).catch(() => void 0);
|
|
11029
11752
|
}
|
|
11030
11753
|
}
|
|
11031
11754
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
11032
|
-
await assertNoSymlinkComponents(project,
|
|
11033
|
-
const existing = await
|
|
11755
|
+
await assertNoSymlinkComponents(project, path16.dirname(relative2));
|
|
11756
|
+
const existing = await fs12.lstat(absolute).catch(() => void 0);
|
|
11034
11757
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11035
11758
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
11036
|
-
if (!existing) await
|
|
11037
|
-
await
|
|
11759
|
+
if (!existing) await fs12.mkdir(absolute, { mode: 448 });
|
|
11760
|
+
await fs12.chmod(absolute, 448);
|
|
11038
11761
|
}
|
|
11039
11762
|
async function pathExists(file) {
|
|
11040
|
-
return
|
|
11763
|
+
return fs12.lstat(file).then(
|
|
11041
11764
|
() => true,
|
|
11042
11765
|
(cause) => {
|
|
11043
11766
|
if (cause.code === "ENOENT") return false;
|
|
@@ -11046,47 +11769,47 @@ async function pathExists(file) {
|
|
|
11046
11769
|
);
|
|
11047
11770
|
}
|
|
11048
11771
|
async function readSafeFile(project, file, label) {
|
|
11049
|
-
const relative2 =
|
|
11050
|
-
if (relative2.startsWith("../") ||
|
|
11772
|
+
const relative2 = path16.relative(project, file).split(path16.sep).join("/");
|
|
11773
|
+
if (relative2.startsWith("../") || path16.isAbsolute(relative2))
|
|
11051
11774
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11052
11775
|
await assertNoSymlinkComponents(project, relative2);
|
|
11053
11776
|
let stat;
|
|
11054
11777
|
try {
|
|
11055
|
-
stat = await
|
|
11778
|
+
stat = await fs12.lstat(file);
|
|
11056
11779
|
} catch (cause) {
|
|
11057
11780
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
11058
11781
|
}
|
|
11059
11782
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11060
11783
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
11061
|
-
return
|
|
11784
|
+
return fs12.readFile(file);
|
|
11062
11785
|
}
|
|
11063
11786
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
11064
11787
|
const parts = relative2.split("/").filter(Boolean);
|
|
11065
11788
|
let current = project;
|
|
11066
11789
|
for (const part of parts) {
|
|
11067
|
-
current =
|
|
11068
|
-
const stat = await
|
|
11790
|
+
current = path16.join(current, part);
|
|
11791
|
+
const stat = await fs12.lstat(current).catch(() => void 0);
|
|
11069
11792
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11070
11793
|
if (!stat) break;
|
|
11071
11794
|
}
|
|
11072
11795
|
}
|
|
11073
11796
|
async function realProject(requested) {
|
|
11074
|
-
const absolute =
|
|
11797
|
+
const absolute = path16.resolve(requested);
|
|
11075
11798
|
let project;
|
|
11076
11799
|
try {
|
|
11077
|
-
project = await
|
|
11800
|
+
project = await fs12.realpath(absolute);
|
|
11078
11801
|
} catch (cause) {
|
|
11079
11802
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
11080
11803
|
}
|
|
11081
|
-
const stat = await
|
|
11804
|
+
const stat = await fs12.stat(project);
|
|
11082
11805
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
11083
11806
|
return project;
|
|
11084
11807
|
}
|
|
11085
11808
|
function safeRelative(reference, label) {
|
|
11086
|
-
if (!reference ||
|
|
11809
|
+
if (!reference || path16.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
11087
11810
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
11088
11811
|
}
|
|
11089
|
-
const normalized =
|
|
11812
|
+
const normalized = path16.normalize(reference).split(path16.sep).join("/");
|
|
11090
11813
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
11091
11814
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11092
11815
|
}
|
|
@@ -11139,7 +11862,7 @@ async function sha256File(file) {
|
|
|
11139
11862
|
return hash.digest("hex");
|
|
11140
11863
|
}
|
|
11141
11864
|
function invalid2(message, cause) {
|
|
11142
|
-
return new
|
|
11865
|
+
return new CliError23({ code: CliErrorCode21.INVALID_ARGUMENT, message, cause });
|
|
11143
11866
|
}
|
|
11144
11867
|
function nextCommandHint(planId, project, argv) {
|
|
11145
11868
|
const quoted = argv.map((a) => /[\s"'$`\\]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a);
|
|
@@ -11151,25 +11874,25 @@ function nextCommandHint(planId, project, argv) {
|
|
|
11151
11874
|
init_auth_guard();
|
|
11152
11875
|
init_exit();
|
|
11153
11876
|
import {
|
|
11154
|
-
HcmClient as
|
|
11877
|
+
HcmClient as HcmClient28,
|
|
11155
11878
|
adminResetPassword,
|
|
11156
|
-
formatObject as
|
|
11879
|
+
formatObject as formatObject29,
|
|
11157
11880
|
fromAxiosError as fromAxiosError23,
|
|
11158
|
-
CliError as
|
|
11159
|
-
CliErrorCode as
|
|
11881
|
+
CliError as CliError24,
|
|
11882
|
+
CliErrorCode as CliErrorCode22
|
|
11160
11883
|
} from "@hcmai/sdk";
|
|
11161
11884
|
function buildAdminResetPasswordRequest(args, password) {
|
|
11162
11885
|
const hasId = Boolean(args.id);
|
|
11163
11886
|
const hasUsername = Boolean(args.username);
|
|
11164
11887
|
if (hasId === hasUsername) {
|
|
11165
|
-
throw new
|
|
11166
|
-
code:
|
|
11888
|
+
throw new CliError24({
|
|
11889
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11167
11890
|
message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
|
|
11168
11891
|
});
|
|
11169
11892
|
}
|
|
11170
11893
|
if (!password) {
|
|
11171
|
-
throw new
|
|
11172
|
-
code:
|
|
11894
|
+
throw new CliError24({
|
|
11895
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11173
11896
|
message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
|
|
11174
11897
|
});
|
|
11175
11898
|
}
|
|
@@ -11185,9 +11908,9 @@ async function userResetPasswordCommand(args) {
|
|
|
11185
11908
|
try {
|
|
11186
11909
|
const password = args.passwordStdin ? await readSecretFromStdin() : await promptPasswordTwice();
|
|
11187
11910
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
11188
|
-
const client3 =
|
|
11911
|
+
const client3 = HcmClient28.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11189
11912
|
const result = await adminResetPassword(client3.raw(), request);
|
|
11190
|
-
process.stdout.write(
|
|
11913
|
+
process.stdout.write(formatObject29(result, { format: args.output ?? "json" }) + "\n");
|
|
11191
11914
|
} catch (cause) {
|
|
11192
11915
|
const err = cause;
|
|
11193
11916
|
if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
|
|
@@ -11198,8 +11921,8 @@ async function promptPasswordTwice() {
|
|
|
11198
11921
|
const password = await promptSecret("\u65B0\u5BC6\u7801: ");
|
|
11199
11922
|
const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
|
|
11200
11923
|
if (password !== confirmation) {
|
|
11201
|
-
throw new
|
|
11202
|
-
code:
|
|
11924
|
+
throw new CliError24({
|
|
11925
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11203
11926
|
message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
|
|
11204
11927
|
});
|
|
11205
11928
|
}
|
|
@@ -11210,27 +11933,29 @@ async function promptPasswordTwice() {
|
|
|
11210
11933
|
init_exit();
|
|
11211
11934
|
init_auth_guard();
|
|
11212
11935
|
import {
|
|
11213
|
-
HcmClient as
|
|
11214
|
-
formatObject as
|
|
11936
|
+
HcmClient as HcmClient29,
|
|
11937
|
+
formatObject as formatObject30,
|
|
11215
11938
|
fromAxiosError as fromAxiosError24
|
|
11216
11939
|
} from "@hcmai/sdk";
|
|
11217
11940
|
async function modelsCommand(keyword, args) {
|
|
11218
11941
|
try {
|
|
11219
|
-
const client3 =
|
|
11942
|
+
const client3 = HcmClient29.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11220
11943
|
const all = await client3.listModels();
|
|
11221
11944
|
const needle = keyword?.trim().toLowerCase();
|
|
11222
11945
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
11223
11946
|
const fmt = args.output ?? "table";
|
|
11224
11947
|
if (fmt !== "table") {
|
|
11225
|
-
process.stdout.write(
|
|
11226
|
-
process.
|
|
11948
|
+
process.stdout.write(formatObject30({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
11949
|
+
process.exitCode = 0;
|
|
11950
|
+
return;
|
|
11227
11951
|
}
|
|
11228
11952
|
if (rows.length === 0) {
|
|
11229
11953
|
process.stdout.write(
|
|
11230
11954
|
needle ? `\u6CA1\u6709\u5339\u914D "${keyword}" \u7684 Model\uFF08\u5171 ${all.length} \u4E2A\u53EF\u89C1\uFF09\u3002
|
|
11231
11955
|
` : "\u5F53\u524D\u8EAB\u4EFD\u5728\u8FD9\u4E2A\u73AF\u5883\u770B\u4E0D\u5230\u4EFB\u4F55 Model\u3002\n"
|
|
11232
11956
|
);
|
|
11233
|
-
process.
|
|
11957
|
+
process.exitCode = 0;
|
|
11958
|
+
return;
|
|
11234
11959
|
}
|
|
11235
11960
|
const width = Math.max(...rows.map((m) => key(m).length), 8);
|
|
11236
11961
|
process.stdout.write(`${"MODEL".padEnd(width)} TYPE
|
|
@@ -11243,7 +11968,8 @@ async function modelsCommand(keyword, args) {
|
|
|
11243
11968
|
\u5171 ${rows.length} \u4E2A${needle ? `\uFF08\u5168\u90E8 ${all.length} \u4E2A\u4E2D\u5339\u914D\uFF09` : ""}\u3002
|
|
11244
11969
|
`);
|
|
11245
11970
|
process.stdout.write("\u4E0B\u4E00\u6B65\uFF1Ahcm describe <Model> \u770B\u5B57\u6BB5\u3001\u5173\u7CFB\u4E0E Action\u3002\n");
|
|
11246
|
-
process.
|
|
11971
|
+
process.exitCode = 0;
|
|
11972
|
+
return;
|
|
11247
11973
|
} catch (e) {
|
|
11248
11974
|
const err = e;
|
|
11249
11975
|
if (err?.isAxiosError) exitWithError(fromAxiosError24(err, args.profile));
|
|
@@ -11269,7 +11995,10 @@ var exitOnBrokenPipe = (err) => {
|
|
|
11269
11995
|
};
|
|
11270
11996
|
process.stdout.on("error", exitOnBrokenPipe);
|
|
11271
11997
|
process.stderr.on("error", exitOnBrokenPipe);
|
|
11272
|
-
program.name("hcm").description("HCM \u547D\u4EE4\u884C\u5DE5\u5177 \u2014 \u64CD\u4F5C HCM API\u3001\u4E0E Moirai \u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u3001\u5F00\u53D1\u79DF\u6237\u5F00\u53D1\u7A7A\u95F4").version(CLI_VERSION)
|
|
11998
|
+
program.name("hcm").description("HCM \u547D\u4EE4\u884C\u5DE5\u5177 \u2014 \u64CD\u4F5C HCM API\u3001\u4E0E Moirai \u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u3001\u5F00\u53D1\u79DF\u6237\u5F00\u53D1\u7A7A\u95F4").version(CLI_VERSION).option("--lang <code>", "\u8BF7\u6C42\u8BED\u8A00\uFF1Azh_CN | zh_HK | en\uFF08\u7B49\u4EF7\u4E8E\u73AF\u5883\u53D8\u91CF HCM_LANG\uFF1B\u4E0D\u7ED9\u6309\u670D\u52A1\u7AEF\u7F3A\u7701\u8BED\u8A00\uFF09").hook("preAction", (thisCommand) => {
|
|
11999
|
+
const lang = thisCommand.opts().lang;
|
|
12000
|
+
if (lang) process.env.HCM_LANG = lang;
|
|
12001
|
+
});
|
|
11273
12002
|
program.command("login").description("\u767B\u5F55 HCM\uFF08\u914D\u5BF9\u7801 / \u7528\u6237\u540D\u5BC6\u7801 / client_credentials / PAT \u56DB\u79CD\u65B9\u5F0F\uFF09").argument("[endpoint]", "\u4ECE\u7CFB\u7EDF\u9875\u9762\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u590D\u5236\u6765\u7684\u5730\u5740\uFF08\u914D\u5BF9\u7801\u65B9\u5F0F\uFF09").option("--code <code>", "\u914D\u5BF9\u7801\uFF0C\u5728\u7CFB\u7EDF\u9875\u9762\u7528\u6237\u83DC\u5355 \u2192\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u751F\u6210").option("--env <name>", "\u73AF\u5883\u540D\uFF08\u9ED8\u8BA4 activeEnv\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--name <id-name>", "\u81EA\u5B9A\u4E49 identity \u540D\uFF08\u9ED8\u8BA4\u6309 scheme \u63A8\u65AD\uFF09").option("--no-activate", "login \u5B8C\u4E0D\u5207\u5230\u8BE5\u73AF\u5883\u4E5F\u4E0D\u8BBE\u4E3A default identity").option("--endpoint <url>", "HCM \u540E\u7AEF\u5730\u5740\uFF0C\u4F8B\u5982 http://localhost:8080").option("--username <user>", "\u7528\u6237\u540D\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF09").option("--password <pwd>", "\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF1B\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0CAgent/\u53D7\u63A7\u4EA4\u4ED8\u8BF7\u7528 --password-stdin\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF0C\u975E\u4EA4\u4E92/\u4E0D\u56DE\u663E\uFF09").option("--client-id <id>", "OAuth client_id\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--client-secret <secret>", "OAuth client_secret\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--pat <token>", "PAT \u4E2A\u4EBA\u8BBF\u95EE\u4EE4\u724C\uFF08\u6CE8\u610F\uFF1A\u4F1A\u6CC4\u6F0F\u5230 ps/history\uFF0C\u5EFA\u8BAE\u6539\u7528 --pat-stdin\uFF09").option("--pat-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6 PAT\uFF08\u63A8\u8350\uFF09").option("--new-password <pwd>", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u7684\u65B0\u53E3\u4EE4\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --new-password-stdin\uFF09").option("--new-password-stdin", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u65B0\u53E3\u4EE4\uFF08\u975E\u4EA4\u4E92\u573A\u666F\uFF09").option("--tenant <tenantId>", "\u79DF\u6237 ID\uFF08\u9ED8\u8BA4 1\uFF09").action((endpoint, opts) => loginCommand({ ...opts, endpointArg: endpoint }));
|
|
11274
12003
|
program.command("logout").description("\u767B\u51FA HCM\uFF08\u6E05\u9664 identity \u7684 keychain token\uFF09").option("--identity <name>", "\u6307\u5B9A identity\uFF1B\u9ED8\u8BA4\u6E05\u5F53\u524D env \u7684 default identity").option("--env <name>", "\u6307\u5B9A env\uFF08\u5F71\u54CD default identity \u89E3\u6790\uFF09").action((opts) => logoutCommand(opts));
|
|
11275
12004
|
var config = program.command("config").description("\u7BA1\u7406\u5168\u5C40 defaults\uFF08env/identity \u7528 `hcm env` / `hcm identity`\uFF09");
|
|
@@ -11294,6 +12023,9 @@ identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 e
|
|
|
11294
12023
|
identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
|
|
11295
12024
|
var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
|
|
11296
12025
|
user.command("reset-password").description("\u7531 admin.system \u5B89\u5168\u91CD\u7F6E\u7528\u6237\u5BC6\u7801\uFF0C\u5E76\u4F7F\u65E2\u6709\u4F1A\u8BDD\u5931\u6548").option("--id <uuid>", "\u76EE\u6807\u7528\u6237 ID\uFF08\u4E0E --username \u4E8C\u9009\u4E00\uFF09").option("--username <user>", "\u76EE\u6807\u7528\u6237\u540D\uFF08\u4E0E --id \u4E8C\u9009\u4E00\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u65B0\u5BC6\u7801\uFF08Agent/\u53D7\u63A7\u4EA4\u4ED8\u5FC5\u987B\u4F7F\u7528\uFF09").option("--no-force-change", "\u4E0B\u6B21\u767B\u5F55\u4E0D\u5F3A\u5236\u6539\u5BC6\uFF08\u4EC5\u9650\u5DF2\u6279\u51C6\u7684\u9694\u79BB\u6D4B\u8BD5\u73AF\u5883\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u5FC5\u987B\u5177\u5907 admin.system\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => userResetPasswordCommand(opts));
|
|
12026
|
+
var chiron = program.command("chiron").description("\u777F\u620E\u987E\u95EE\u9879\u76EE\uFF1Ainit \u4E00\u6761\u547D\u4EE4\u521D\u59CB\u5316\u9879\u76EE\u4ED3\uFF0Cdoctor \u4E09\u884C\u6838\u5BF9\u80FD\u4E0D\u80FD\u5F00\u5DE5");
|
|
12027
|
+
chiron.command("init").description("\u521D\u59CB\u5316\u987E\u95EE\u9879\u76EE\u4ED3\uFF1A\u5199 env.yaml\uFF08\u7528\u521A hcm login \u7684\u73AF\u5883\uFF09\u3001\u5EFA\u76EE\u5F55\u3001\u88C5\u5168\u90E8\u6280\u80FD\u3001\u63A5\u6848\u4F8B\u5E93\uFF1B\u91CD\u8DD1\u5B89\u5168").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--skip-skills", "\u4E0D\u88C5\u6280\u80FD\uFF08\u79BB\u7EBF/\u6D4B\u8BD5\uFF09").option("--skip-cases", "\u4E0D\u63A5\u6848\u4F8B\u5E93").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironInitCommand(opts));
|
|
12028
|
+
chiron.command("doctor").description("\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").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").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));
|
|
11297
12029
|
var delivery = program.command("delivery").description("\u987E\u95EE\u4EA4\u4ED8\uFF1A\u73B0\u573A\u63A2\u6D3B\u3001\u98CE\u9669\u8BC4\u4F30\u4E0E\u4E00\u6B21\u6027\u53D7\u63A7\u6267\u884C\u5408\u540C");
|
|
11298
12030
|
delivery.command("assess").description("\u8BC4\u4F30\u4E00\u6B21 HCM CLI argv\uFF1BAction \u98CE\u63A7\u58F0\u660E\u8BFB\u53D6\u81EA\u76EE\u6807 Core\uFF0C\u7528 -- \u5206\u9694\u88AB\u8BC4\u4F30\u547D\u4EE4").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u8BC4\u4F30\u7684 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryAssessCommand(command, opts));
|
|
11299
12031
|
delivery.command("doctor").description("\u56DB\u6761\u951A\u70B9\u63A2\u6D3B\uFF1A\u8FDE\u901A / \u6211\u662F\u8C01 / configAdmin / \u7AD9\u5728\u54EA\u4E00\u5C42").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").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) => deliveryDoctorCommand(opts));
|
|
@@ -11427,7 +12159,8 @@ program.command("upload <file>").description("\u4E0A\u4F20\u672C\u5730\u6587\u4E
|
|
|
11427
12159
|
).action((file, opts) => uploadCommand(file, opts));
|
|
11428
12160
|
var datapackage = program.command("datapackage").description("DataPackage \u5355\u6587\u4EF6\u5236\u54C1\uFF1Apack \u6253\u5305\uFF08\u7EAF\u672C\u5730\uFF09/ install \u4E0A\u4F20\u5B89\u88C5\uFF08\u670D\u52A1\u7AEF\u5B89\u88C5\u5668\uFF09");
|
|
11429
12161
|
datapackage.command("pack <packageDir>").description("\u628A\u5305\u76EE\u5F55\uFF08\u542B package.yml\uFF09\u6253\u6210 .hcmpkg \u5355\u6587\u4EF6\u5236\u54C1\uFF0C\u4E0D\u8054\u7F51").option("-o, --out <path>", "\u4EA7\u7269\u8DEF\u5F84\uFF08\u7F3A\u7701 <name \u672B\u6BB5>-<version>.hcmpkg\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((dir, opts) => datapackagePackCommand(dir, opts));
|
|
11430
|
-
datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u5236\u54C1\u5E76\u7ECF\u670D\u52A1\u7AEF
|
|
12162
|
+
datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u5236\u54C1\u5E76\u7ECF\u670D\u52A1\u7AEF\u5F02\u6B65\u5B89\u88C5\u5668\u5B89\u88C5\uFF0C\u5B9E\u65F6\u663E\u793A\u8FDB\u5EA6\uFF08admin.system\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--category <name>", "\u5236\u54C1\u4E0A\u4F20\u7684\u5B58\u50A8\u5206\u7C7B\uFF08\u670D\u52A1\u7AEF\u6570\u636E\u975E\u679A\u4E3E\uFF09", "attachment").option("--no-wait", "\u53EA\u53D7\u7406\u4E0D\u7B49\u5F85\uFF0C\u7ACB\u523B\u8FD4\u56DE runId").option("--timeout <sec>", "\u7B49\u5F85\u4E0A\u9650\uFF08\u79D2\uFF09\uFF1B\u7B49\u4E0D\u5230\u4E0D\u662F\u5931\u8D25\uFF0C\u88C5\u8F7D\u5728\u670D\u52A1\u7AEF\u7EE7\u7EED", "900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((artifact, opts) => datapackageInstallCommand(artifact, opts));
|
|
12163
|
+
datapackage.command("status <runId>").description("\u67E5\u770B\u88C5\u8F7D\u6D41\u6C34\u8FDB\u5EA6/\u7EC8\u6001\uFF08\u914D\u5408 install --no-wait \u6216\u7B49\u5F85\u8D85\u65F6\u540E\u4F7F\u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((runId, opts) => datapackageStatusCommand(runId, opts));
|
|
11431
12164
|
var tenant = program.command("tenant").description("\u79DF\u6237\u5F00\u901A\u4E0E\u751F\u547D\u5468\u671F");
|
|
11432
12165
|
tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5EFA\u79DF\u6237 + admin \u7528\u6237 + \u7ED3\u6784 reconcile\uFF09\u2014\u2014\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8").requiredOption("--tenant-id <id>", "\u79DF\u6237 ID").requiredOption("--admin-username <user>", "\u7BA1\u7406\u5458\u7528\u6237\u540D").option("--admin-password <pwd>", "\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --admin-password-stdin\uFF09").option("--admin-password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u63A8\u8350\uFF09").option("--tenant-name <name>", "\u79DF\u6237\u540D\u79F0\uFF08\u9ED8\u8BA4\u53D6 tenantId\uFF09").option("--bootstrap-key <key>", "bootstrap \u5BC6\u94A5\uFF08\u5EFA\u8BAE\u7528 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\uFF09").option("--bootstrap-key-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB bootstrap \u5BC6\u94A5").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("-y, --yes", "\u8DF3\u8FC7\u786E\u8BA4\uFF08CI \u7528\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => tenantBootstrapCommand(opts));
|
|
11433
12166
|
var meta = program.command("meta").description("\u79DF\u6237\u5143\u6570\u636E\u8BFB\u5199\uFF08\u9875\u9762/\u5B57\u6BB5/\u5217\u8868\u914D\u7F6E\uFF09");
|
|
@@ -11445,7 +12178,7 @@ skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347
|
|
|
11445
12178
|
program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09\u3002\u5347\u7EA7 CLI \u8BF7\u7528 `hcm upgrade`").requiredOption("--id <id>", "\u8BB0\u5F55 ID").option("--data <JSON>", `\u8981\u66F4\u65B0\u7684\u5B57\u6BB5 JSON\uFF0C\u4F8B\u5982 '{"name":"\u65B0\u540D\u79F0"}'`).option("--data-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6\u66F4\u65B0\u5B57\u6BB5\uFF08\u4E0E --data \u4E92\u65A5\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").option("--i18n", "\u591A\u8BED\u8A00\u5B57\u6BB5\u6309 Map \u5B8C\u6574\u66FF\u6362\uFF08\u952E\u7528 zh-CN / en-US \u8FDE\u5B57\u7B26\u5F62\uFF09\uFF1B\u4E0D\u4F20\u5219\u6309\u5B57\u7B26\u4E32\u53EA\u6539\u5F53\u524D\u8BED\u8A00").action((model, opts) => updateCommand(model, opts));
|
|
11446
12179
|
program.command("version").description("\u67E5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF08commit / tag / \u6784\u5EFA\u65F6\u95F4\uFF09\u2014\u2014\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => versionCommand(opts));
|
|
11447
12180
|
program.command("upgrade").alias("self-update").description("\u5347\u7EA7 CLI \u81EA\u5DF1\uFF08\u6CE8\u610F\uFF1A`hcm update` \u662F\u66F4\u65B0\u4E1A\u52A1\u8BB0\u5F55\uFF0C\u4E0D\u662F\u5347\u7EA7\uFF09").option("--check", "\u53EA\u68C0\u67E5\uFF1B\u6709\u65B0\u7248\u672C\u65F6\u4EE5\u9000\u51FA\u7801 1 \u7ED3\u675F\uFF0C\u4FBF\u4E8E\u811A\u672C\u5224\u65AD").action((opts) => upgradeCommand(opts));
|
|
11448
|
-
program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((
|
|
12181
|
+
program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path17, opts) => openCommand(path17, opts));
|
|
11449
12182
|
var setting = program.command("setting").description("\u79DF\u6237\u7CFB\u7EDF\u53C2\u6570\uFF08\u767B\u5F55\u7B56\u7565 / \u5BC6\u7801\u7B56\u7565 / \u529F\u80FD\u5F00\u5173 / \u96C6\u6210\u53C2\u6570\uFF09");
|
|
11450
12183
|
setting.command("get <domain>").description("\u8BFB\u67D0\u57DF\u53C2\u6570\uFF08\u5B9A\u4E49 + \u79DF\u6237\u8986\u76D6\u503C\u5408\u5E76\uFF0C\u7F3A\u5931\u56DE\u843D\u9ED8\u8BA4\u503C\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
|
|
11451
12184
|
setting.command("set <domain>").description("\u6539\u53C2\u6570\uFF0C\u53EF\u91CD\u590D --set\uFF1B\u8D70\u53D7\u63A7\u6821\u9A8C\u8DEF\u5F84\u800C\u975E\u6807\u51C6 CRUD").option("--set <assignment...>", "namespace.key=value\uFF0C\u4F8B\u5982 security.password.passwordPolicy=complex").option("--dry-run", "\u53EA\u663E\u793A\u5C06\u5199\u5165\u4EC0\u4E48\uFF0C\u4E0D\u5B9E\u9645\u5199\u5165").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((d, opts) => settingSetCommand(d, opts));
|