MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / handleUpgrade

Function handleUpgrade

apps/kimi-code/src/cli/sub/upgrade.ts:51–173  ·  view source on GitHub ↗
(
  currentVersion: string,
  overrides: Partial<UpgradeDeps> = {},
)

Source from the content-addressed store, hash-verified

49}
50
51export async function handleUpgrade(
52 currentVersion: string,
53 overrides: Partial<UpgradeDeps> = {},
54): Promise<number> {
55 const deps = createDefaultUpgradeDeps(overrides);
56
57 let cache: UpdateCache;
58 try {
59 cache = await deps.refreshUpdateCache();
60 } catch (error) {
61 const reason = formatErrorMessage(error);
62 trackUpgradeEvent(deps.track, 'upgrade_command_failed', {
63 current_version: currentVersion,
64 stage: 'refresh',
65 reason,
66 });
67 logUpgradeWarn(deps.logger, 'manual upgrade check failed', {
68 currentVersion,
69 error,
70 });
71 deps.stderr.write(`error: failed to check for updates: ${reason}\n`);
72 return 1;
73 }
74
75 const target = selectUpdateTarget(currentVersion, cache.latest);
76 if (target === null) {
77 trackUpgradeEvent(deps.track, 'upgrade_command_no_update', {
78 current_version: currentVersion,
79 });
80 logUpgradeInfo(deps.logger, 'manual upgrade no update', {
81 currentVersion,
82 });
83 deps.stdout.write(`Kimi Code is already up to date (${formatDisplayVersion(currentVersion)}).\n`);
84 return 0;
85 }
86
87 const source = await deps.detectInstallSource().catch(() => 'unsupported' as const);
88 const installCommand = installCommandFor(source, target.version, deps.platform);
89 if (!canAutoInstall(source, deps.platform) || !deps.isInteractive) {
90 trackUpgradeEvent(deps.track, 'upgrade_command_manual_command', {
91 current_version: currentVersion,
92 target_version: target.version,
93 source,
94 });
95 logUpgradeInfo(deps.logger, 'manual upgrade command shown', {
96 currentVersion,
97 targetVersion: target.version,
98 source,
99 });
100 deps.stdout.write(renderManualUpdateMessage(currentVersion, target, source, installCommand));
101 return 0;
102 }
103
104 trackUpgradeEvent(deps.track, 'upgrade_command_prompted', {
105 current_version: currentVersion,
106 target_version: target.version,
107 source,
108 });

Callers 2

upgrade.test.tsFile · 0.90
handleUpgradeCommandFunction · 0.90

Calls 12

selectUpdateTargetFunction · 0.90
installCommandForFunction · 0.90
canAutoInstallFunction · 0.90
createDefaultUpgradeDepsFunction · 0.85
trackUpgradeEventFunction · 0.85
logUpgradeWarnFunction · 0.85
logUpgradeInfoFunction · 0.85
formatDisplayVersionFunction · 0.85
formatErrorMessageFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected