mano-coding 0.1.37 → 0.1.39
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/bin.js +402 -123
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -3681,7 +3681,8 @@ var init_zh = __esm({
|
|
|
3681
3681
|
"tty.confirmPrompt": "\n\u786E\u8BA4\u540E\u5C06\u6267\u884C\u4EE5\u4E0A\u64CD\u4F5C\u3002\n",
|
|
3682
3682
|
"tty.proceedPrompt": "\u662F\u5426\u6267\u884C\u6B64 Plan\uFF1F",
|
|
3683
3683
|
// update-notice.ts
|
|
3684
|
-
"update.notice": "
|
|
3684
|
+
"update.notice": "mano-coding {0} \u53EF\u7528\uFF08\u5F53\u524D {1}\uFF09\u3002\u8FD0\u884C mano-coding self-upgrade \u5347\u7EA7\u3002",
|
|
3685
|
+
"update.notice.paused": "mano-coding {0} \u53EF\u7528\uFF08\u5F53\u524D {1}\uFF09\u3002\u540E\u53F0\u81EA\u52A8\u5347\u7EA7\u5DF2\u6682\u505C\uFF08\u8FDE\u7EED\u5931\u8D25\uFF0C\u539F\u56E0\uFF1A{2}\uFF09\u3002\u8FD0\u884C mano-coding self-upgrade \u5347\u7EA7\u3002",
|
|
3685
3686
|
// plan-execution.ts
|
|
3686
3687
|
"plan.integrityMissing": "Capability '{0}/{1}' \u6CA1\u6709\u5DF2\u9A8C\u8BC1\u7684\u5305\u5B8C\u6574\u6027",
|
|
3687
3688
|
"plan.integrityConflict": "\u5B89\u88C5\u5B8C\u6574\u6027\u51B2\u7A81\uFF1A{0}/{1}@{2}",
|
|
@@ -22880,7 +22881,7 @@ import { join as join3 } from "node:path";
|
|
|
22880
22881
|
function isCliUpdateCache(value) {
|
|
22881
22882
|
if (!value || typeof value !== "object") return false;
|
|
22882
22883
|
const item = value;
|
|
22883
|
-
return item["schemaVersion"] === 1 && typeof item["registryOrigin"] === "string" && typeof item["checkedAt"] === "string" && typeof item["latestVersion"] === "string" && (item["latestIntegrity"] === void 0 || typeof item["latestIntegrity"] === "string") && (item["latestEnginesNode"] === void 0 || typeof item["latestEnginesNode"] === "string") && (item["lastNotifiedAt"] === void 0 || typeof item["lastNotifiedAt"] === "string");
|
|
22884
|
+
return item["schemaVersion"] === 1 && typeof item["registryOrigin"] === "string" && typeof item["checkedAt"] === "string" && typeof item["latestVersion"] === "string" && (item["latestIntegrity"] === void 0 || typeof item["latestIntegrity"] === "string") && (item["latestEnginesNode"] === void 0 || typeof item["latestEnginesNode"] === "string") && (item["lastNotifiedAt"] === void 0 || typeof item["lastNotifiedAt"] === "string") && (item["autoUpdateFailureCount"] === void 0 || typeof item["autoUpdateFailureCount"] === "number") && (item["autoUpdateLastError"] === void 0 || typeof item["autoUpdateLastError"] === "string") && (item["autoUpdatePaused"] === void 0 || typeof item["autoUpdatePaused"] === "boolean");
|
|
22884
22885
|
}
|
|
22885
22886
|
var CliUpdateCacheRepository;
|
|
22886
22887
|
var init_cli_update_repository = __esm({
|
|
@@ -22910,6 +22911,31 @@ var init_cli_update_repository = __esm({
|
|
|
22910
22911
|
if (!cache) return;
|
|
22911
22912
|
await this.write({ ...cache, lastNotifiedAt: now.toISOString() });
|
|
22912
22913
|
}
|
|
22914
|
+
/**
|
|
22915
|
+
* 记录自动升级失败,累加连续失败次数,并在达到阈值(默认 3 次)时标记暂停
|
|
22916
|
+
*/
|
|
22917
|
+
async recordAutoUpdateFailure(errorMessage, maxFailures = 3) {
|
|
22918
|
+
const cache = await this.read();
|
|
22919
|
+
if (!cache) return;
|
|
22920
|
+
const count = (cache.autoUpdateFailureCount ?? 0) + 1;
|
|
22921
|
+
const paused = count >= maxFailures;
|
|
22922
|
+
await this.write({
|
|
22923
|
+
...cache,
|
|
22924
|
+
autoUpdateFailureCount: count,
|
|
22925
|
+
autoUpdateLastError: errorMessage,
|
|
22926
|
+
autoUpdatePaused: paused
|
|
22927
|
+
});
|
|
22928
|
+
}
|
|
22929
|
+
/**
|
|
22930
|
+
* 重置自动升级失败状态(在升级成功或手动 self-upgrade 成功后调用)
|
|
22931
|
+
*/
|
|
22932
|
+
async resetAutoUpdateFailure() {
|
|
22933
|
+
const cache = await this.read();
|
|
22934
|
+
if (!cache) return;
|
|
22935
|
+
if (!cache.autoUpdateFailureCount && !cache.autoUpdateLastError && !cache.autoUpdatePaused) return;
|
|
22936
|
+
const { autoUpdateFailureCount, autoUpdateLastError, autoUpdatePaused, ...rest } = cache;
|
|
22937
|
+
await this.write(rest);
|
|
22938
|
+
}
|
|
22913
22939
|
async clear() {
|
|
22914
22940
|
await withStateLock(this.path, async () => {
|
|
22915
22941
|
await unlink4(this.path).catch((error) => {
|
|
@@ -27153,7 +27179,8 @@ var init_config_manager = __esm({
|
|
|
27153
27179
|
}
|
|
27154
27180
|
async get(key) {
|
|
27155
27181
|
const config = await this.read();
|
|
27156
|
-
|
|
27182
|
+
const val = config[key];
|
|
27183
|
+
return val !== void 0 ? String(val) : void 0;
|
|
27157
27184
|
}
|
|
27158
27185
|
async set(key, value) {
|
|
27159
27186
|
const config = await this.read();
|
|
@@ -27192,6 +27219,51 @@ var init_config_manager = __esm({
|
|
|
27192
27219
|
}
|
|
27193
27220
|
return DEFAULT_GITLAB_HOST;
|
|
27194
27221
|
}
|
|
27222
|
+
/**
|
|
27223
|
+
* 读取企业托管配置(只读)
|
|
27224
|
+
* 优先从环境变量 AICODING_MANAGED_CONFIG 或 MANO_MANAGED_CONFIG 指定的文件读取;
|
|
27225
|
+
* 若未指定,则尝试读取系统级配置路径
|
|
27226
|
+
*/
|
|
27227
|
+
async readManagedConfig() {
|
|
27228
|
+
const envManagedPath = process.env["AICODING_MANAGED_CONFIG"] ?? process.env["MANO_MANAGED_CONFIG"];
|
|
27229
|
+
const defaultManagedPath = process.platform === "win32" ? join8(process.env["ProgramData"] ?? "C:\\ProgramData", "mano", "config.json") : "/etc/mano/config.json";
|
|
27230
|
+
const managedPath = envManagedPath ?? defaultManagedPath;
|
|
27231
|
+
try {
|
|
27232
|
+
const content = await readFile10(managedPath, "utf-8");
|
|
27233
|
+
const parsed = JSON.parse(content);
|
|
27234
|
+
return typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
27235
|
+
} catch {
|
|
27236
|
+
return void 0;
|
|
27237
|
+
}
|
|
27238
|
+
}
|
|
27239
|
+
/**
|
|
27240
|
+
* 检查自动升级是否启用:
|
|
27241
|
+
* 1. 检查企业托管配置(最高优先级,管理员统一下发)
|
|
27242
|
+
* 2. 检查针对性环境变量 AICODING_AUTO_UPDATE 或 MANO_AUTO_UPDATE
|
|
27243
|
+
* 3. 检查 ~/.manorc 中的 autoUpdate 配置
|
|
27244
|
+
* 4. 默认启用(返回 true,对齐 OpenCode 默认开启体验)
|
|
27245
|
+
*/
|
|
27246
|
+
async isAutoUpdateEnabled() {
|
|
27247
|
+
const managed = await this.readManagedConfig();
|
|
27248
|
+
if (managed && managed.autoUpdate !== void 0) {
|
|
27249
|
+
const managedVal = String(managed.autoUpdate).toLowerCase().trim();
|
|
27250
|
+
if (managedVal === "false" || managedVal === "0" || managedVal === "no") return false;
|
|
27251
|
+
if (managedVal === "true" || managedVal === "1" || managedVal === "yes") return true;
|
|
27252
|
+
}
|
|
27253
|
+
const envAuto = process.env["AICODING_AUTO_UPDATE"] ?? process.env["MANO_AUTO_UPDATE"];
|
|
27254
|
+
if (envAuto !== void 0 && envAuto.trim().length > 0) {
|
|
27255
|
+
const envVal = envAuto.toLowerCase().trim();
|
|
27256
|
+
if (envVal === "false" || envVal === "0" || envVal === "no") return false;
|
|
27257
|
+
if (envVal === "true" || envVal === "1" || envVal === "yes") return true;
|
|
27258
|
+
}
|
|
27259
|
+
const userVal = await this.get("autoUpdate");
|
|
27260
|
+
if (userVal !== void 0) {
|
|
27261
|
+
const strVal = String(userVal).toLowerCase().trim();
|
|
27262
|
+
if (strVal === "false" || strVal === "0" || strVal === "no") return false;
|
|
27263
|
+
if (strVal === "true" || strVal === "1" || strVal === "yes") return true;
|
|
27264
|
+
}
|
|
27265
|
+
return true;
|
|
27266
|
+
}
|
|
27195
27267
|
};
|
|
27196
27268
|
defaultConfigManager = new ConfigManager();
|
|
27197
27269
|
}
|
|
@@ -52649,11 +52721,146 @@ var init_launch = __esm({
|
|
|
52649
52721
|
}
|
|
52650
52722
|
});
|
|
52651
52723
|
|
|
52652
|
-
// packages/cli/src/commands/self-upgrade.ts
|
|
52724
|
+
// packages/cli/src/commands/self-upgrade-pipeline.ts
|
|
52653
52725
|
import { spawn as spawn3 } from "node:child_process";
|
|
52654
52726
|
import { readFile as readFile33, realpath as realpath2 } from "node:fs/promises";
|
|
52655
|
-
import { homedir as homedir5 } from "node:os";
|
|
52656
52727
|
import { extname, join as join27, resolve as resolve27 } from "node:path";
|
|
52728
|
+
async function detectGlobalCliInstallation(cliPath = process.argv[1], runner = runCommand) {
|
|
52729
|
+
if (!cliPath) return void 0;
|
|
52730
|
+
const binPath = await realpath2(cliPath).catch(() => void 0);
|
|
52731
|
+
if (!binPath) return void 0;
|
|
52732
|
+
for (const manager of ["npm", "pnpm"]) {
|
|
52733
|
+
const root = await runner(manager, ["root", "-g"]).catch(() => void 0);
|
|
52734
|
+
if (!root || root.exitCode !== 0) continue;
|
|
52735
|
+
const packageRoot = resolve27(root.stdout.trim(), ...CLI_PACKAGE_NAME.split("/"));
|
|
52736
|
+
const packageJson = await readPackageJson(packageRoot);
|
|
52737
|
+
if (!packageJson || packageJson.name !== CLI_PACKAGE_NAME || !isExactCliVersion(packageJson.version)) continue;
|
|
52738
|
+
const declaredBin = typeof packageJson.bin === "object" && packageJson.bin ? packageJson.bin[CLI_BIN_NAME] : void 0;
|
|
52739
|
+
if (typeof declaredBin !== "string") continue;
|
|
52740
|
+
const expectedBin = await realpath2(resolve27(packageRoot, declaredBin)).catch(() => void 0);
|
|
52741
|
+
if (!expectedBin) continue;
|
|
52742
|
+
if (!isSamePath(expectedBin, binPath) && !await isWindowsCmdShimFor(binPath, expectedBin)) continue;
|
|
52743
|
+
return { manager, managerExecutable: manager, packageRoot, binPath: expectedBin, currentVersion: packageJson.version };
|
|
52744
|
+
}
|
|
52745
|
+
return void 0;
|
|
52746
|
+
}
|
|
52747
|
+
async function verifyCliVersion(binPath, expected, runner = runCommand) {
|
|
52748
|
+
const result = await runner(process.execPath, [binPath, "--version"]).catch(() => void 0);
|
|
52749
|
+
return result?.exitCode === 0 && result.stdout.trim() === expected;
|
|
52750
|
+
}
|
|
52751
|
+
async function performUpgrade(installation, targetVersion, offline, runner = runCommand) {
|
|
52752
|
+
const args = installation.manager === "npm" ? ["install", "-g", `${CLI_PACKAGE_NAME}@${targetVersion}`] : ["add", "-g", `${CLI_PACKAGE_NAME}@${targetVersion}`];
|
|
52753
|
+
if (offline) args.push("--offline");
|
|
52754
|
+
const result = await runner(installation.managerExecutable, args);
|
|
52755
|
+
if (result.exitCode === 0 && await verifyCliVersion(installation.binPath, targetVersion, runner)) {
|
|
52756
|
+
return;
|
|
52757
|
+
}
|
|
52758
|
+
const rollbackArgs = installation.manager === "npm" ? ["install", "-g", `${CLI_PACKAGE_NAME}@${installation.currentVersion}`] : ["add", "-g", `${CLI_PACKAGE_NAME}@${installation.currentVersion}`];
|
|
52759
|
+
const rollback = await runner(installation.managerExecutable, rollbackArgs);
|
|
52760
|
+
const rollbackVerified = rollback.exitCode === 0 && await verifyCliVersion(installation.binPath, installation.currentVersion, runner);
|
|
52761
|
+
if (!rollbackVerified) {
|
|
52762
|
+
throw new CliError(
|
|
52763
|
+
t("selfUpgrade.rollbackFailed", CLI_PACKAGE_NAME, installation.currentVersion),
|
|
52764
|
+
ExitCode.ExecuteFailed,
|
|
52765
|
+
"CLI_UPDATE_ROLLBACK_FAILED"
|
|
52766
|
+
);
|
|
52767
|
+
}
|
|
52768
|
+
throw new CliError(t("selfUpgrade.upgradeFailed"), ExitCode.ExecuteFailed, "CLI_UPDATE_FAILED");
|
|
52769
|
+
}
|
|
52770
|
+
async function fetchCliMetadata(registry, request = fetch, options) {
|
|
52771
|
+
const envTimeout = process.env["AICODING_FETCH_TIMEOUT"] ? Number.parseInt(process.env["AICODING_FETCH_TIMEOUT"], 10) : void 0;
|
|
52772
|
+
const timeoutMs = options?.timeoutMs ?? (Number.isFinite(envTimeout) && (envTimeout ?? 0) > 0 ? envTimeout : 15e3);
|
|
52773
|
+
const maxRetries = options?.retries ?? 1;
|
|
52774
|
+
let lastError;
|
|
52775
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
52776
|
+
const controller = new AbortController();
|
|
52777
|
+
let timedOut = false;
|
|
52778
|
+
const timer = setTimeout(() => {
|
|
52779
|
+
timedOut = true;
|
|
52780
|
+
controller.abort();
|
|
52781
|
+
}, timeoutMs);
|
|
52782
|
+
timer.unref?.();
|
|
52783
|
+
try {
|
|
52784
|
+
const response = await request(`${registry}/${encodeURIComponent(CLI_PACKAGE_NAME)}`, {
|
|
52785
|
+
signal: controller.signal,
|
|
52786
|
+
redirect: "error"
|
|
52787
|
+
});
|
|
52788
|
+
if (!response.ok) throw new Error(`Registry returned HTTP ${response.status}`);
|
|
52789
|
+
return await response.json();
|
|
52790
|
+
} catch (error) {
|
|
52791
|
+
const isAbort = timedOut || error instanceof Error && (error.name === "AbortError" || error.message.includes("aborted"));
|
|
52792
|
+
if (isAbort) {
|
|
52793
|
+
lastError = new Error(t("selfUpgrade.fetchMetadataTimeout", Math.round(timeoutMs / 1e3)));
|
|
52794
|
+
} else {
|
|
52795
|
+
lastError = error;
|
|
52796
|
+
}
|
|
52797
|
+
if (attempt < maxRetries) {
|
|
52798
|
+
await new Promise((resolve28) => setTimeout(resolve28, 200));
|
|
52799
|
+
}
|
|
52800
|
+
} finally {
|
|
52801
|
+
clearTimeout(timer);
|
|
52802
|
+
}
|
|
52803
|
+
}
|
|
52804
|
+
throw lastError;
|
|
52805
|
+
}
|
|
52806
|
+
async function runCommand(command, args) {
|
|
52807
|
+
const useCmd = process.platform === "win32" && (command === "pnpm" || command === "npm");
|
|
52808
|
+
const executable = useCmd ? process.env.ComSpec ?? "cmd.exe" : command;
|
|
52809
|
+
const commandArgs = useCmd ? ["/d", "/c", [command, ...args.map((value) => /[\s&|<>()^%!]/u.test(value) ? `"${value.replaceAll('"', '""')}"` : value)].join(" ")] : args;
|
|
52810
|
+
return new Promise((resolveResult, reject) => {
|
|
52811
|
+
const child = spawn3(executable, commandArgs, { shell: false, windowsHide: true });
|
|
52812
|
+
let stdout = "";
|
|
52813
|
+
let stderrOutput = "";
|
|
52814
|
+
child.stdout.on("data", (chunk) => {
|
|
52815
|
+
stdout = limitOutput(`${stdout}${chunk.toString()}`);
|
|
52816
|
+
});
|
|
52817
|
+
child.stderr.on("data", (chunk) => {
|
|
52818
|
+
stderrOutput = limitOutput(`${stderrOutput}${chunk.toString()}`);
|
|
52819
|
+
});
|
|
52820
|
+
child.on("error", reject);
|
|
52821
|
+
child.on("close", (code) => resolveResult({ exitCode: code ?? 1, stdout, stderr: stderrOutput }));
|
|
52822
|
+
});
|
|
52823
|
+
}
|
|
52824
|
+
function isSamePath(a, b2) {
|
|
52825
|
+
if (process.platform === "win32") {
|
|
52826
|
+
return resolve27(a).replaceAll("/", "\\").toLowerCase() === resolve27(b2).replaceAll("/", "\\").toLowerCase();
|
|
52827
|
+
}
|
|
52828
|
+
return resolve27(a) === resolve27(b2);
|
|
52829
|
+
}
|
|
52830
|
+
async function isWindowsCmdShimFor(shimPath, expectedBin) {
|
|
52831
|
+
if (process.platform !== "win32" || extname(shimPath).toLowerCase() !== ".cmd") return false;
|
|
52832
|
+
const shim = await readFile33(shimPath, "utf8").catch(() => void 0);
|
|
52833
|
+
if (!shim) return false;
|
|
52834
|
+
return shim.replaceAll("/", "\\").toLowerCase().includes(expectedBin.replaceAll("/", "\\").toLowerCase());
|
|
52835
|
+
}
|
|
52836
|
+
async function readPackageJson(root) {
|
|
52837
|
+
try {
|
|
52838
|
+
const value = JSON.parse(await readFile33(join27(root, "package.json"), "utf8"));
|
|
52839
|
+
if (!value || typeof value !== "object") return void 0;
|
|
52840
|
+
const item = value;
|
|
52841
|
+
return typeof item["name"] === "string" && typeof item["version"] === "string" ? { name: item["name"], version: item["version"], bin: item["bin"] } : void 0;
|
|
52842
|
+
} catch {
|
|
52843
|
+
return void 0;
|
|
52844
|
+
}
|
|
52845
|
+
}
|
|
52846
|
+
function limitOutput(value) {
|
|
52847
|
+
return value.length <= OUTPUT_LIMIT ? value : `${value.slice(0, OUTPUT_LIMIT)}
|
|
52848
|
+
[truncated]`;
|
|
52849
|
+
}
|
|
52850
|
+
var OUTPUT_LIMIT;
|
|
52851
|
+
var init_self_upgrade_pipeline = __esm({
|
|
52852
|
+
"packages/cli/src/commands/self-upgrade-pipeline.ts"() {
|
|
52853
|
+
"use strict";
|
|
52854
|
+
init_src2();
|
|
52855
|
+
init_cli_output();
|
|
52856
|
+
init_i18n();
|
|
52857
|
+
OUTPUT_LIMIT = 4096;
|
|
52858
|
+
}
|
|
52859
|
+
});
|
|
52860
|
+
|
|
52861
|
+
// packages/cli/src/commands/self-upgrade.ts
|
|
52862
|
+
import { homedir as homedir5 } from "node:os";
|
|
52863
|
+
import { join as join28 } from "node:path";
|
|
52657
52864
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
52658
52865
|
import { stdin, stderr } from "node:process";
|
|
52659
52866
|
function createSelfUpgradeCommand(cliVersion) {
|
|
@@ -52715,7 +52922,7 @@ async function executeSelfUpgrade(options, cliVersion) {
|
|
|
52715
52922
|
});
|
|
52716
52923
|
await auditLog.prune().catch(() => void 0);
|
|
52717
52924
|
try {
|
|
52718
|
-
const result = await withStateLock(
|
|
52925
|
+
const result = await withStateLock(join28(userDataDir, "cli-update"), async () => {
|
|
52719
52926
|
const target = await resolveTarget(options, cacheRepository, registry);
|
|
52720
52927
|
ensureTargetAllowed(target.version, installation.currentVersion, options.allowDowngrade);
|
|
52721
52928
|
if (!isCliVersionCompatible(process.version, target.enginesNode)) {
|
|
@@ -52737,11 +52944,13 @@ async function executeSelfUpgrade(options, cliVersion) {
|
|
|
52737
52944
|
await auditLog.append({
|
|
52738
52945
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
52739
52946
|
command: "self-upgrade",
|
|
52947
|
+
source: "manual",
|
|
52740
52948
|
currentVersion: installation.currentVersion,
|
|
52741
52949
|
targetVersion: result.plan.targetVersion,
|
|
52742
52950
|
result: "success",
|
|
52743
52951
|
rollbackResult: "not-needed"
|
|
52744
52952
|
});
|
|
52953
|
+
await cacheRepository.resetAutoUpdateFailure().catch(() => void 0);
|
|
52745
52954
|
}
|
|
52746
52955
|
if (options.json) emitSuccessJson("self-upgrade", { dryRun: result.dryRun, ...result.plan, changed: result.changed });
|
|
52747
52956
|
else if (result.dryRun) writeHumanOutput(
|
|
@@ -52753,6 +52962,7 @@ async function executeSelfUpgrade(options, cliVersion) {
|
|
|
52753
52962
|
await auditLog.append({
|
|
52754
52963
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
52755
52964
|
command: "self-upgrade",
|
|
52965
|
+
source: "manual",
|
|
52756
52966
|
currentVersion: installation.currentVersion,
|
|
52757
52967
|
result: "failure",
|
|
52758
52968
|
errorCode: error instanceof CliError ? error.code : "CLI_UPDATE_FAILED"
|
|
@@ -52767,7 +52977,7 @@ function validateOptions(options) {
|
|
|
52767
52977
|
}
|
|
52768
52978
|
}
|
|
52769
52979
|
function getUserDataDir3() {
|
|
52770
|
-
return process.env["AICODING_USER_DATA"] ??
|
|
52980
|
+
return process.env["AICODING_USER_DATA"] ?? join28(homedir5(), ".aicoding");
|
|
52771
52981
|
}
|
|
52772
52982
|
function getRegistryUrl() {
|
|
52773
52983
|
const raw = process.env["AICODING_NPM_REGISTRY"] || DEFAULT_NPM_REGISTRY;
|
|
@@ -52831,18 +53041,6 @@ function buildPlan(installation, targetVersion, integrity, offline) {
|
|
|
52831
53041
|
command: [installation.managerExecutable, ...args]
|
|
52832
53042
|
};
|
|
52833
53043
|
}
|
|
52834
|
-
async function performUpgrade(installation, targetVersion, offline) {
|
|
52835
|
-
const args = installation.manager === "npm" ? ["install", "-g", `${CLI_PACKAGE_NAME}@${targetVersion}`] : ["add", "-g", `${CLI_PACKAGE_NAME}@${targetVersion}`];
|
|
52836
|
-
if (offline) args.push("--offline");
|
|
52837
|
-
const result = await runCommand(installation.managerExecutable, args);
|
|
52838
|
-
if (result.exitCode === 0 && await verifyCliVersion(installation.binPath, targetVersion)) return;
|
|
52839
|
-
const rollback = await runCommand(installation.managerExecutable, installation.manager === "npm" ? ["install", "-g", `${CLI_PACKAGE_NAME}@${installation.currentVersion}`] : ["add", "-g", `${CLI_PACKAGE_NAME}@${installation.currentVersion}`]);
|
|
52840
|
-
const rollbackVerified = rollback.exitCode === 0 && await verifyCliVersion(installation.binPath, installation.currentVersion);
|
|
52841
|
-
if (!rollbackVerified) {
|
|
52842
|
-
throw new CliError(t("selfUpgrade.rollbackFailed", CLI_PACKAGE_NAME, installation.currentVersion), ExitCode.ExecuteFailed, "CLI_UPDATE_ROLLBACK_FAILED");
|
|
52843
|
-
}
|
|
52844
|
-
throw new CliError(t("selfUpgrade.upgradeFailed"), ExitCode.ExecuteFailed, "CLI_UPDATE_FAILED");
|
|
52845
|
-
}
|
|
52846
53044
|
async function confirmUpgrade() {
|
|
52847
53045
|
if (!stdin.isTTY) return false;
|
|
52848
53046
|
const readline3 = createInterface2({ input: stdin, output: stderr, terminal: true });
|
|
@@ -52853,133 +53051,211 @@ async function confirmUpgrade() {
|
|
|
52853
53051
|
readline3.close();
|
|
52854
53052
|
}
|
|
52855
53053
|
}
|
|
52856
|
-
function
|
|
52857
|
-
|
|
52858
|
-
return resolve27(a).replaceAll("/", "\\").toLowerCase() === resolve27(b2).replaceAll("/", "\\").toLowerCase();
|
|
52859
|
-
}
|
|
52860
|
-
return resolve27(a) === resolve27(b2);
|
|
53054
|
+
function messageOf2(error) {
|
|
53055
|
+
return error instanceof Error ? error.message : String(error);
|
|
52861
53056
|
}
|
|
52862
|
-
|
|
52863
|
-
|
|
52864
|
-
|
|
52865
|
-
|
|
52866
|
-
|
|
52867
|
-
|
|
52868
|
-
|
|
52869
|
-
|
|
52870
|
-
|
|
52871
|
-
|
|
52872
|
-
|
|
52873
|
-
|
|
52874
|
-
|
|
52875
|
-
|
|
52876
|
-
|
|
52877
|
-
|
|
53057
|
+
var DEFAULT_NPM_REGISTRY;
|
|
53058
|
+
var init_self_upgrade = __esm({
|
|
53059
|
+
"packages/cli/src/commands/self-upgrade.ts"() {
|
|
53060
|
+
"use strict";
|
|
53061
|
+
init_esm();
|
|
53062
|
+
init_src2();
|
|
53063
|
+
init_cli_output();
|
|
53064
|
+
init_shared_options();
|
|
53065
|
+
init_i18n();
|
|
53066
|
+
init_self_upgrade_pipeline();
|
|
53067
|
+
DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
53068
|
+
}
|
|
53069
|
+
});
|
|
53070
|
+
|
|
53071
|
+
// packages/cli/src/commands/auto-update.ts
|
|
53072
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
53073
|
+
import { homedir as homedir6 } from "node:os";
|
|
53074
|
+
import { join as join29 } from "node:path";
|
|
53075
|
+
async function scheduleAutoUpdateWorker(argv, currentVersion, options) {
|
|
53076
|
+
const disabled = argv.includes("--offline") || Boolean(process.env["AICODING_NO_UPDATE_CHECK"]) || Boolean(process.env["CI"]) || argv[2] === "self-upgrade" || argv[2] === "_self-update-worker" || argv[2] === "_launch";
|
|
53077
|
+
if (disabled) return;
|
|
53078
|
+
const configManager = options?.configManager ?? defaultConfigManager;
|
|
53079
|
+
const isEnabled = await configManager.isAutoUpdateEnabled();
|
|
53080
|
+
if (!isEnabled) return;
|
|
53081
|
+
const userDataDir = options?.userDataDir ?? getUserDataDir4();
|
|
53082
|
+
const cacheRepository = new CliUpdateCacheRepository(userDataDir);
|
|
53083
|
+
const cache = await cacheRepository.read();
|
|
53084
|
+
if (cache?.autoUpdatePaused) return;
|
|
53085
|
+
const checkedAt = cache?.checkedAt ? Date.parse(cache.checkedAt) : Number.NaN;
|
|
53086
|
+
const within24h = Number.isFinite(checkedAt) && Date.now() - checkedAt < 24 * 60 * 60 * 1e3;
|
|
53087
|
+
if (within24h && (!cache?.latestVersion || !isCliUpdateAvailable(currentVersion, cache.latestVersion))) {
|
|
53088
|
+
return;
|
|
53089
|
+
}
|
|
53090
|
+
if (options?.spawner) {
|
|
53091
|
+
options.spawner([process.argv[1] ?? "", "_self-update-worker", "--parent-pid", String(process.pid)]);
|
|
53092
|
+
return;
|
|
52878
53093
|
}
|
|
52879
|
-
return void 0;
|
|
52880
|
-
}
|
|
52881
|
-
async function isWindowsCmdShimFor(shimPath, expectedBin) {
|
|
52882
|
-
if (process.platform !== "win32" || extname(shimPath).toLowerCase() !== ".cmd") return false;
|
|
52883
|
-
const shim = await readFile33(shimPath, "utf8").catch(() => void 0);
|
|
52884
|
-
if (!shim) return false;
|
|
52885
|
-
return shim.replaceAll("/", "\\").toLowerCase().includes(expectedBin.replaceAll("/", "\\").toLowerCase());
|
|
52886
|
-
}
|
|
52887
|
-
async function readPackageJson(root) {
|
|
52888
53094
|
try {
|
|
52889
|
-
const
|
|
52890
|
-
if (!
|
|
52891
|
-
const
|
|
52892
|
-
|
|
53095
|
+
const scriptPath = process.argv[1];
|
|
53096
|
+
if (!scriptPath) return;
|
|
53097
|
+
const child = spawn4(process.execPath, [scriptPath, "_self-update-worker", "--parent-pid", String(process.pid)], {
|
|
53098
|
+
detached: true,
|
|
53099
|
+
stdio: "ignore",
|
|
53100
|
+
windowsHide: true
|
|
53101
|
+
});
|
|
53102
|
+
child.unref();
|
|
52893
53103
|
} catch {
|
|
52894
|
-
return void 0;
|
|
52895
53104
|
}
|
|
52896
53105
|
}
|
|
52897
|
-
|
|
52898
|
-
const
|
|
52899
|
-
|
|
53106
|
+
function createSelfUpdateWorkerCommand(cliVersion) {
|
|
53107
|
+
const cmd = new Command("_self-update-worker").description("\u5185\u90E8\u81EA\u52A8\u5347\u7EA7\u5DE5\u4F5C\u8FDB\u7A0B").option("--parent-pid <pid>", "\u7236\u8FDB\u7A0B PID").action(async (opts) => {
|
|
53108
|
+
const parentPid = opts.parentPid ? Number.parseInt(opts.parentPid, 10) : void 0;
|
|
53109
|
+
await executeAutoUpdateWorker({ parentPid, cliVersion }).catch(() => void 0);
|
|
53110
|
+
});
|
|
53111
|
+
return cmd;
|
|
52900
53112
|
}
|
|
52901
|
-
async function
|
|
52902
|
-
|
|
52903
|
-
const
|
|
52904
|
-
const
|
|
52905
|
-
|
|
52906
|
-
|
|
52907
|
-
|
|
52908
|
-
|
|
52909
|
-
|
|
52910
|
-
|
|
52911
|
-
|
|
52912
|
-
|
|
52913
|
-
|
|
52914
|
-
|
|
52915
|
-
|
|
52916
|
-
|
|
52917
|
-
|
|
53113
|
+
async function executeAutoUpdateWorker(options) {
|
|
53114
|
+
if (process.env["AICODING_NO_UPDATE_CHECK"] || process.env["CI"]) return;
|
|
53115
|
+
const userDataDir = options.userDataDir ?? getUserDataDir4();
|
|
53116
|
+
const cacheRepository = new CliUpdateCacheRepository(userDataDir);
|
|
53117
|
+
const cache = await cacheRepository.read();
|
|
53118
|
+
if (cache?.autoUpdatePaused) return;
|
|
53119
|
+
const registry = getRegistryUrl2();
|
|
53120
|
+
if (!registry) return;
|
|
53121
|
+
const checkedAt = cache?.checkedAt ? Date.parse(cache.checkedAt) : Number.NaN;
|
|
53122
|
+
const within24h = Number.isFinite(checkedAt) && Date.now() - checkedAt < 24 * 60 * 60 * 1e3;
|
|
53123
|
+
let targetVersion = cache?.latestVersion;
|
|
53124
|
+
let enginesNode = cache?.latestEnginesNode;
|
|
53125
|
+
if (!within24h || !targetVersion || !isCliUpdateAvailable(options.cliVersion, targetVersion)) {
|
|
53126
|
+
const metadata = await fetchCliMetadata(registry, options.fetcher, { timeoutMs: 3e3, retries: 0 }).catch(() => void 0);
|
|
53127
|
+
if (!metadata) return;
|
|
53128
|
+
const latest = parseLatestCliVersion(metadata);
|
|
53129
|
+
const release = latest ? parseCliReleaseMetadata(metadata, latest) : void 0;
|
|
53130
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
53131
|
+
if (!latest || !release || !isCliUpdateAvailable(options.cliVersion, latest)) {
|
|
53132
|
+
await cacheRepository.write({
|
|
53133
|
+
schemaVersion: 1,
|
|
53134
|
+
registryOrigin: registry,
|
|
53135
|
+
checkedAt: nowIso,
|
|
53136
|
+
latestVersion: latest ?? options.cliVersion,
|
|
53137
|
+
...cache?.lastNotifiedAt ? { lastNotifiedAt: cache.lastNotifiedAt } : {},
|
|
53138
|
+
...cache?.autoUpdateFailureCount ? { autoUpdateFailureCount: cache.autoUpdateFailureCount } : {},
|
|
53139
|
+
...cache?.autoUpdateLastError ? { autoUpdateLastError: cache.autoUpdateLastError } : {},
|
|
53140
|
+
...cache?.autoUpdatePaused ? { autoUpdatePaused: cache.autoUpdatePaused } : {}
|
|
52918
53141
|
});
|
|
52919
|
-
|
|
52920
|
-
|
|
52921
|
-
|
|
52922
|
-
|
|
52923
|
-
|
|
52924
|
-
|
|
52925
|
-
|
|
52926
|
-
|
|
53142
|
+
return;
|
|
53143
|
+
}
|
|
53144
|
+
targetVersion = latest;
|
|
53145
|
+
enginesNode = release.enginesNode;
|
|
53146
|
+
await cacheRepository.write({
|
|
53147
|
+
schemaVersion: 1,
|
|
53148
|
+
registryOrigin: registry,
|
|
53149
|
+
checkedAt: nowIso,
|
|
53150
|
+
latestVersion: latest,
|
|
53151
|
+
...release.integrity ? { latestIntegrity: release.integrity } : {},
|
|
53152
|
+
...release.enginesNode ? { latestEnginesNode: release.enginesNode } : {},
|
|
53153
|
+
...cache?.lastNotifiedAt ? { lastNotifiedAt: cache.lastNotifiedAt } : {},
|
|
53154
|
+
...cache?.autoUpdateFailureCount ? { autoUpdateFailureCount: cache.autoUpdateFailureCount } : {},
|
|
53155
|
+
...cache?.autoUpdateLastError ? { autoUpdateLastError: cache.autoUpdateLastError } : {},
|
|
53156
|
+
...cache?.autoUpdatePaused ? { autoUpdatePaused: cache.autoUpdatePaused } : {}
|
|
53157
|
+
});
|
|
53158
|
+
}
|
|
53159
|
+
if (!targetVersion || !isCliUpdateAvailable(options.cliVersion, targetVersion)) return;
|
|
53160
|
+
if (!isCliVersionCompatible(process.version, enginesNode)) return;
|
|
53161
|
+
try {
|
|
53162
|
+
await withStateLock(join29(userDataDir, "cli-update"), async () => {
|
|
53163
|
+
if (options.parentPid && options.parentPid > 0) {
|
|
53164
|
+
const parentExited = await waitForParentProcessExit(options.parentPid, {
|
|
53165
|
+
maxWaitMs: options.maxWaitMs ?? 1e4,
|
|
53166
|
+
initialIntervalMs: options.pollIntervalMs ?? 20,
|
|
53167
|
+
maxIntervalMs: 50
|
|
53168
|
+
});
|
|
53169
|
+
if (!parentExited) return;
|
|
52927
53170
|
}
|
|
52928
|
-
|
|
52929
|
-
|
|
53171
|
+
const runner = options.runner ?? runCommand;
|
|
53172
|
+
const installation = await detectGlobalCliInstallation(void 0, runner);
|
|
53173
|
+
if (!installation) return;
|
|
53174
|
+
const auditLog = new AuditLog(userDataDir);
|
|
53175
|
+
await auditLog.ensureReady().catch(() => void 0);
|
|
53176
|
+
try {
|
|
53177
|
+
await performUpgrade(installation, targetVersion, false, runner);
|
|
53178
|
+
await auditLog.append({
|
|
53179
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53180
|
+
command: "self-upgrade",
|
|
53181
|
+
source: "auto",
|
|
53182
|
+
currentVersion: installation.currentVersion,
|
|
53183
|
+
targetVersion,
|
|
53184
|
+
result: "success",
|
|
53185
|
+
rollbackResult: "not-needed"
|
|
53186
|
+
}).catch(() => void 0);
|
|
53187
|
+
await cacheRepository.resetAutoUpdateFailure().catch(() => void 0);
|
|
53188
|
+
} catch (error) {
|
|
53189
|
+
const rollbackFailed = error instanceof CliError && error.code === "CLI_UPDATE_ROLLBACK_FAILED";
|
|
53190
|
+
await auditLog.append({
|
|
53191
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53192
|
+
command: "self-upgrade",
|
|
53193
|
+
source: "auto",
|
|
53194
|
+
currentVersion: installation.currentVersion,
|
|
53195
|
+
targetVersion,
|
|
53196
|
+
result: "failure",
|
|
53197
|
+
errorCode: error instanceof CliError ? error.code : "CLI_UPDATE_FAILED",
|
|
53198
|
+
rollbackResult: rollbackFailed ? "failed" : "succeeded"
|
|
53199
|
+
}).catch(() => void 0);
|
|
53200
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
53201
|
+
await cacheRepository.recordAutoUpdateFailure(errorMsg).catch(() => void 0);
|
|
52930
53202
|
}
|
|
52931
|
-
}
|
|
52932
|
-
|
|
52933
|
-
}
|
|
53203
|
+
}, 0);
|
|
53204
|
+
} catch {
|
|
52934
53205
|
}
|
|
52935
|
-
throw lastError;
|
|
52936
53206
|
}
|
|
52937
|
-
async function
|
|
52938
|
-
const
|
|
52939
|
-
const
|
|
52940
|
-
const
|
|
52941
|
-
|
|
52942
|
-
|
|
52943
|
-
|
|
52944
|
-
let
|
|
52945
|
-
|
|
52946
|
-
|
|
52947
|
-
|
|
52948
|
-
|
|
52949
|
-
|
|
52950
|
-
}
|
|
52951
|
-
|
|
52952
|
-
|
|
52953
|
-
|
|
53207
|
+
async function waitForParentProcessExit(pid, options = {}) {
|
|
53208
|
+
const maxWaitMs = options.maxWaitMs ?? 1e4;
|
|
53209
|
+
const initialIntervalMs = options.initialIntervalMs ?? 20;
|
|
53210
|
+
const maxIntervalMs = options.maxIntervalMs ?? 50;
|
|
53211
|
+
const deadline = Date.now() + maxWaitMs;
|
|
53212
|
+
let interval = initialIntervalMs;
|
|
53213
|
+
while (Date.now() < deadline) {
|
|
53214
|
+
let alive = false;
|
|
53215
|
+
try {
|
|
53216
|
+
process.kill(pid, 0);
|
|
53217
|
+
alive = true;
|
|
53218
|
+
} catch {
|
|
53219
|
+
alive = false;
|
|
53220
|
+
}
|
|
53221
|
+
if (!alive) return true;
|
|
53222
|
+
await new Promise((resolve28) => setTimeout(resolve28, interval));
|
|
53223
|
+
interval = Math.min(interval + 10, maxIntervalMs);
|
|
53224
|
+
}
|
|
53225
|
+
return false;
|
|
52954
53226
|
}
|
|
52955
|
-
function
|
|
52956
|
-
return
|
|
52957
|
-
[truncated]`;
|
|
53227
|
+
function getUserDataDir4() {
|
|
53228
|
+
return process.env["AICODING_USER_DATA"] ?? join29(homedir6(), ".aicoding");
|
|
52958
53229
|
}
|
|
52959
|
-
function
|
|
52960
|
-
|
|
53230
|
+
function getRegistryUrl2() {
|
|
53231
|
+
const raw = process.env["AICODING_NPM_REGISTRY"] || DEFAULT_NPM_REGISTRY2;
|
|
53232
|
+
try {
|
|
53233
|
+
const url = new URL(raw);
|
|
53234
|
+
if (url.protocol !== "https:" || url.username || url.password) return "";
|
|
53235
|
+
return url.toString().replace(/\/$/, "");
|
|
53236
|
+
} catch {
|
|
53237
|
+
return "";
|
|
53238
|
+
}
|
|
52961
53239
|
}
|
|
52962
|
-
var
|
|
52963
|
-
var
|
|
52964
|
-
"packages/cli/src/commands/
|
|
53240
|
+
var DEFAULT_NPM_REGISTRY2;
|
|
53241
|
+
var init_auto_update = __esm({
|
|
53242
|
+
"packages/cli/src/commands/auto-update.ts"() {
|
|
52965
53243
|
"use strict";
|
|
52966
53244
|
init_esm();
|
|
52967
53245
|
init_src2();
|
|
53246
|
+
init_self_upgrade_pipeline();
|
|
52968
53247
|
init_cli_output();
|
|
52969
|
-
|
|
52970
|
-
init_i18n();
|
|
52971
|
-
DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
52972
|
-
OUTPUT_LIMIT = 4096;
|
|
53248
|
+
DEFAULT_NPM_REGISTRY2 = "https://registry.npmjs.org";
|
|
52973
53249
|
}
|
|
52974
53250
|
});
|
|
52975
53251
|
|
|
52976
53252
|
// packages/cli/src/commands/update-notice.ts
|
|
52977
|
-
import { homedir as
|
|
52978
|
-
import { join as
|
|
53253
|
+
import { homedir as homedir7 } from "node:os";
|
|
53254
|
+
import { join as join30 } from "node:path";
|
|
52979
53255
|
async function getCachedUpdateNotice(argv, currentVersion) {
|
|
52980
53256
|
const json = argv.includes("--json");
|
|
52981
|
-
const disabled = argv.includes("--offline") || argv[2] === "self-upgrade" || Boolean(process.env["AICODING_NO_UPDATE_CHECK"]) || Boolean(process.env["CI"]);
|
|
52982
|
-
const repository = new CliUpdateCacheRepository(process.env["AICODING_USER_DATA"] ??
|
|
53257
|
+
const disabled = argv.includes("--offline") || argv[2] === "self-upgrade" || argv[2] === "_self-update-worker" || Boolean(process.env["AICODING_NO_UPDATE_CHECK"]) || Boolean(process.env["CI"]);
|
|
53258
|
+
const repository = new CliUpdateCacheRepository(process.env["AICODING_USER_DATA"] ?? join30(homedir7(), ".aicoding"));
|
|
52983
53259
|
if (disabled || !json && !process.stdout.isTTY) return { json, markNotified: async () => void 0 };
|
|
52984
53260
|
const cache = await repository.read();
|
|
52985
53261
|
const notifiedAt = cache?.lastNotifiedAt ? Date.parse(cache.lastNotifiedAt) : Number.NaN;
|
|
@@ -52987,7 +53263,7 @@ async function getCachedUpdateNotice(argv, currentVersion) {
|
|
|
52987
53263
|
if (!cache || cache.registryOrigin !== configuredRegistryOrigin() || !due || !isCliUpdateAvailable(currentVersion, cache.latestVersion)) {
|
|
52988
53264
|
return { json, markNotified: async () => void 0 };
|
|
52989
53265
|
}
|
|
52990
|
-
const warning = t("update.notice", cache.latestVersion, currentVersion);
|
|
53266
|
+
const warning = cache.autoUpdatePaused ? t("update.notice.paused", cache.latestVersion, currentVersion, cache.autoUpdateLastError ?? "\u672A\u77E5\u539F\u56E0") : t("update.notice", cache.latestVersion, currentVersion);
|
|
52991
53267
|
return { warning, json, markNotified: () => repository.markNotified(/* @__PURE__ */ new Date()) };
|
|
52992
53268
|
}
|
|
52993
53269
|
function configuredRegistryOrigin() {
|
|
@@ -53011,7 +53287,7 @@ import { createRequire as createRequire2 } from "node:module";
|
|
|
53011
53287
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
53012
53288
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
53013
53289
|
function resolveVersion() {
|
|
53014
|
-
if (true) return "0.1.
|
|
53290
|
+
if (true) return "0.1.39";
|
|
53015
53291
|
const candidates = [
|
|
53016
53292
|
new URL("../package.json", import.meta.url),
|
|
53017
53293
|
new URL("../../package.json", import.meta.url),
|
|
@@ -53048,6 +53324,7 @@ __export(index_exports, {
|
|
|
53048
53324
|
async function run(argv) {
|
|
53049
53325
|
const updateNotice = await getCachedUpdateNotice(argv, CLI_VERSION);
|
|
53050
53326
|
setRunSuccessWarnings(updateNotice.warning && updateNotice.json ? [updateNotice.warning] : []);
|
|
53327
|
+
await scheduleAutoUpdateWorker(argv, CLI_VERSION);
|
|
53051
53328
|
const program2 = new Command();
|
|
53052
53329
|
program2.name("mano-coding").description("Mano Coding CLI - \u5DE5\u7A0B\u811A\u624B\u67B6\u4E0E AI Coding \u8D44\u4EA7\u7BA1\u7406\u5DE5\u5177").version(CLI_VERSION, "-V, --version", "\u663E\u793A CLI \u7248\u672C\u53F7").helpOption("-h, --help", "\u663E\u793A\u5E2E\u52A9\u4FE1\u606F").enablePositionalOptions().configureOutput({
|
|
53053
53330
|
writeErr: (str) => process.stderr.write(str),
|
|
@@ -53081,6 +53358,7 @@ async function run(argv) {
|
|
|
53081
53358
|
extensionCommand.addCommand(adapterCommand);
|
|
53082
53359
|
program2.addCommand(extensionCommand);
|
|
53083
53360
|
program2.addCommand(createLaunchCommand());
|
|
53361
|
+
program2.addCommand(createSelfUpdateWorkerCommand(CLI_VERSION));
|
|
53084
53362
|
try {
|
|
53085
53363
|
await program2.parseAsync(argv);
|
|
53086
53364
|
const code = process.exitCode;
|
|
@@ -53132,6 +53410,7 @@ var init_index = __esm({
|
|
|
53132
53410
|
init_cache();
|
|
53133
53411
|
init_launch();
|
|
53134
53412
|
init_self_upgrade();
|
|
53413
|
+
init_auto_update();
|
|
53135
53414
|
init_cli_output();
|
|
53136
53415
|
init_update_notice();
|
|
53137
53416
|
init_cli_version();
|