@hcmai/cli 0.15.11 → 0.15.12
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 +38 -11
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2519,6 +2519,25 @@ function rejectionLine(reason) {
|
|
|
2519
2519
|
const known = rejectionMessages[reason];
|
|
2520
2520
|
return known ? `${known} (${reason})` : `\u6709\u4EBA\u6253\u5F00\u4E86\u6388\u6743\u94FE\u63A5\u4F46\u88AB\u6321\u4E0B\uFF0C\u539F\u56E0\u7801\u672C\u7248 CLI \u8FD8\u4E0D\u8BA4\u8BC6 (unknown:${reason})\uFF1B\u5347\u7EA7 hcm CLI \u53EF\u770B\u5230\u5BF9\u75C7\u8BF4\u660E\u3002`;
|
|
2521
2521
|
}
|
|
2522
|
+
var WAIT_COUNTDOWN_INTERVAL_MS = 6e4;
|
|
2523
|
+
var WAIT_COUNTDOWN_FLOOR_MS = 5e3;
|
|
2524
|
+
function humanDuration(ms) {
|
|
2525
|
+
const total = Math.round(ms / 1e3);
|
|
2526
|
+
const minutes = Math.floor(total / 60);
|
|
2527
|
+
const seconds = total % 60;
|
|
2528
|
+
if (minutes === 0) return `${seconds} \u79D2`;
|
|
2529
|
+
return seconds === 0 ? `${minutes} \u5206` : `${minutes} \u5206 ${seconds} \u79D2`;
|
|
2530
|
+
}
|
|
2531
|
+
function startWaitCountdown(deadline) {
|
|
2532
|
+
const timer = setInterval(() => {
|
|
2533
|
+
const remaining = deadline - Date.now();
|
|
2534
|
+
if (remaining < WAIT_COUNTDOWN_FLOOR_MS) return;
|
|
2535
|
+
process.stderr.write(`\u8FD8\u6709 ${humanDuration(remaining)}\uFF1B\u4ECD\u5728\u7B49\u5F85\u786E\u8BA4\uFF0C\u8981\u653E\u5F03\u8BF7\u6309 Ctrl-C\u3002
|
|
2536
|
+
`);
|
|
2537
|
+
}, WAIT_COUNTDOWN_INTERVAL_MS);
|
|
2538
|
+
timer.unref?.();
|
|
2539
|
+
return () => clearInterval(timer);
|
|
2540
|
+
}
|
|
2522
2541
|
async function beginDeviceLogin(input) {
|
|
2523
2542
|
const cancel = cancellation();
|
|
2524
2543
|
let session;
|
|
@@ -2540,19 +2559,24 @@ async function beginDeviceLogin(input) {
|
|
|
2540
2559
|
\u8BBE\u5907\u7801\uFF1A${authorization.userCode}
|
|
2541
2560
|
\u6388\u6743\u622A\u6B62\uFF1A${authorization.expiresAt}\uFF1B\u6B63\u5728\u7B49\u5F85\u786E\u8BA4\u3002
|
|
2542
2561
|
`);
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2562
|
+
const stopCountdown = startWaitCountdown(authorization.deadline);
|
|
2563
|
+
try {
|
|
2564
|
+
session = await pollDeviceAuthorization({
|
|
2565
|
+
...input,
|
|
2566
|
+
authorization,
|
|
2567
|
+
signal: cancel.controller.signal,
|
|
2568
|
+
onTimeout: () => process.stderr.write("\u6388\u6743\u8F6E\u8BE2\u8BF7\u6C42\u8D85\u65F6\uFF1B\u4ECD\u5728\u539F\u6388\u6743\u671F\u9650\u5185\u7B49\u5F85\uFF0C\u4E0D\u4F1A\u53D1\u8D77\u65B0\u6388\u6743\u3002\n"),
|
|
2569
|
+
// 🔴 印出来但**不结束等待**:授权链接里带着 requestId,谁拿到链接谁都能打开并触发一次拒绝,
|
|
2570
|
+
// 在这里失败等于让任何链接持有人都能取消别人的登录。停不停由用户按 Ctrl-C 决定。
|
|
2571
|
+
onRejection: (rejection) => process.stderr.write(
|
|
2572
|
+
`${rejectionLine(rejection.reason)}
|
|
2552
2573
|
\u4ECD\u5728\u7B49\u5F85\u672C\u6B21\u6388\u6743\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u53D6\u6D88\uFF1B\u8981\u653E\u5F03\u8BF7\u6309 Ctrl-C\u3002
|
|
2553
2574
|
`
|
|
2554
|
-
|
|
2555
|
-
|
|
2575
|
+
)
|
|
2576
|
+
});
|
|
2577
|
+
} finally {
|
|
2578
|
+
stopCountdown();
|
|
2579
|
+
}
|
|
2556
2580
|
return { session, complete: async () => {
|
|
2557
2581
|
if (cancel.controller.signal.aborted) throw cancel.error(new Error("\u767B\u5F55\u5DF2\u53D6\u6D88"));
|
|
2558
2582
|
session.complete();
|
|
@@ -2585,6 +2609,7 @@ async function beginBrowserLogin(input) {
|
|
|
2585
2609
|
let timeout;
|
|
2586
2610
|
let closing;
|
|
2587
2611
|
let watch;
|
|
2612
|
+
let stopCountdown = () => void 0;
|
|
2588
2613
|
let resolve3;
|
|
2589
2614
|
let reject;
|
|
2590
2615
|
const result = new Promise((yes, no) => {
|
|
@@ -2592,6 +2617,7 @@ async function beginBrowserLogin(input) {
|
|
|
2592
2617
|
reject = no;
|
|
2593
2618
|
});
|
|
2594
2619
|
void result.catch(() => void 0);
|
|
2620
|
+
void result.finally(() => stopCountdown()).catch(() => void 0);
|
|
2595
2621
|
const server = createServer((request, response) => {
|
|
2596
2622
|
let url;
|
|
2597
2623
|
try {
|
|
@@ -2706,6 +2732,7 @@ async function beginBrowserLogin(input) {
|
|
|
2706
2732
|
() => reject(cliAuthorizationExpired(watch?.lastRejection(), watch?.probe())),
|
|
2707
2733
|
Math.max(1, deadline - Date.now())
|
|
2708
2734
|
);
|
|
2735
|
+
stopCountdown = startWaitCountdown(deadline);
|
|
2709
2736
|
watch = watchBrowserAuthorization({
|
|
2710
2737
|
...input,
|
|
2711
2738
|
requestId: authorization.requestId,
|