@hit-sudomaker/ccw 0.4.1 → 0.5.1
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/README.md +54 -52
- package/assets/ccline/config.toml +34 -34
- package/assets/skills/amirc-research/SKILL.md +39 -39
- package/dist/ccline.js +149 -617
- package/dist/ccw.js +166 -381
- package/dist/claude-program.js +191 -0
- package/dist/claude.js +177 -0
- package/dist/cleanup.js +148 -362
- package/dist/effect-machine.js +65 -0
- package/dist/frozen-json.js +99 -0
- package/dist/instance.js +71 -0
- package/dist/machine.js +610 -572
- package/dist/main.js +66 -67
- package/dist/management-catalog.js +56 -56
- package/dist/messages.js +182 -0
- package/dist/model.js +37 -155
- package/dist/npm-registry.js +108 -29
- package/dist/officecli.js +270 -407
- package/dist/planning.js +141 -0
- package/dist/plugins.js +134 -319
- package/dist/program-channels.js +94 -393
- package/dist/program-operations.js +155 -0
- package/dist/read-machine.js +94 -38
- package/dist/render.js +345 -396
- package/dist/settings.js +380 -0
- package/dist/skill-files.js +182 -96
- package/dist/skills.js +393 -259
- package/dist/terminal-view.js +303 -455
- package/dist/terminal.js +207 -508
- package/dist/work.js +135 -0
- package/package.json +1 -2
- package/dist/claude-config.js +0 -349
- package/dist/collect.js +0 -147
- package/dist/errors.js +0 -140
- package/dist/legacy-amirc.js +0 -60
- package/dist/mcp.js +0 -317
- package/dist/programs.js +0 -797
- package/dist/run-presentation.js +0 -157
- package/dist/storage.js +0 -44
- package/dist/titles.js +0 -46
- package/dist/warnings.js +0 -6
package/dist/programs.js
DELETED
|
@@ -1,797 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { knownTitle } from './titles.js';
|
|
4
|
-
import { OFFICECLI_REPO_SLUG, officeIntegration } from './management-catalog.js';
|
|
5
|
-
import { errorCode, isObject, succeeded } from './machine.js';
|
|
6
|
-
import { cancelled, claudeEnvironment, claudeRunning, success, userBinary } from './model.js';
|
|
7
|
-
import { isExactVersion, npmInstallArgs, npmUninstallArgs, NPM_OFFICIAL, resolveNpmView } from './npm-registry.js';
|
|
8
|
-
import { channelCanPinVersion, containsPath, freezeNpmScope, freezeProgramScope, identifyProgramChannel, maintainProgramChannel, npmBinary, npmGlobalRoot, npmScriptFlags, npmScopeArgs, npmVersion, officeBinary, PROGRAM_PACKAGES, programPackageAbsent, removeProgramChannel, samePath, } from './program-channels.js';
|
|
9
|
-
import { installScratch } from './storage.js';
|
|
10
|
-
export async function programs(ctx, kind) {
|
|
11
|
-
const values = new Map();
|
|
12
|
-
const problems = [];
|
|
13
|
-
const canonicalPaths = [];
|
|
14
|
-
const native = kind === 'claude' ? userBinary(ctx, 'claude') : officeBinary(ctx);
|
|
15
|
-
const add = (value) => values.set(`${kind}:${value.channel}:${value.binary}`, value);
|
|
16
|
-
try {
|
|
17
|
-
const version = await npmVersion(ctx, PROGRAM_PACKAGES[kind]);
|
|
18
|
-
if (version !== null) {
|
|
19
|
-
const root = await npmGlobalRoot(ctx);
|
|
20
|
-
const binary = await npmBinary(ctx, kind, root);
|
|
21
|
-
add({
|
|
22
|
-
kind,
|
|
23
|
-
channel: 'npm',
|
|
24
|
-
binary,
|
|
25
|
-
version,
|
|
26
|
-
npmRoot: root,
|
|
27
|
-
packageName: PROGRAM_PACKAGES[kind],
|
|
28
|
-
isMissing: (await ctx.machine.treeStamp(binary)) === null,
|
|
29
|
-
});
|
|
30
|
-
canonicalPaths.push((await ctx.machine.realpath(binary)) ?? binary);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
if (errorCode(error) === 'npm-changed')
|
|
35
|
-
throw error;
|
|
36
|
-
problems.push(errorCode(error));
|
|
37
|
-
}
|
|
38
|
-
const candidates = new Set([native, ...(await ctx.machine.locate(kind))]);
|
|
39
|
-
for (const candidate of candidates) {
|
|
40
|
-
let binary = candidate;
|
|
41
|
-
if (ctx.platform === 'win32' && binary.endsWith('.exe')) {
|
|
42
|
-
const shim = await ctx.machine.read(binary.slice(0, -4) + '.shim');
|
|
43
|
-
const target = shim === null ? undefined : /^path\s*=\s*"([^"]+)"/m.exec(shim)?.[1];
|
|
44
|
-
if (target !== undefined &&
|
|
45
|
-
path.isAbsolute(target) &&
|
|
46
|
-
/\/apps\/officecli\/[^/]+\/(?:[^/]+\/)*officecli(?:\.exe)?$/.test(target.replaceAll('\\', '/').toLowerCase()))
|
|
47
|
-
binary = target;
|
|
48
|
-
}
|
|
49
|
-
const canonical = await ctx.machine.realpath(binary);
|
|
50
|
-
if (canonical === null ||
|
|
51
|
-
canonicalPaths.some(file => samePath(ctx, file, canonical)) ||
|
|
52
|
-
[...values.values()].some(program => program.npmRoot !== undefined &&
|
|
53
|
-
containsPath(ctx, path.join(program.npmRoot, program.packageName), canonical)))
|
|
54
|
-
continue;
|
|
55
|
-
if ([kind, `${kind}.cmd`, `${kind}.ps1`].includes(path.basename(binary).toLowerCase()) &&
|
|
56
|
-
[...values.values()].some(program => program.npmRoot !== undefined &&
|
|
57
|
-
samePath(ctx, program.npmRoot, path.join(path.dirname(binary), 'node_modules'))))
|
|
58
|
-
continue;
|
|
59
|
-
add({ kind, binary, version: null, ...(await identifyProgramChannel(ctx, kind, binary, canonical, native)) });
|
|
60
|
-
canonicalPaths.push(canonical);
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
values,
|
|
64
|
-
problems,
|
|
65
|
-
items: [...values.entries()].map(([id, value]) => ({
|
|
66
|
-
id,
|
|
67
|
-
name: kind,
|
|
68
|
-
title: knownTitle(kind),
|
|
69
|
-
kind,
|
|
70
|
-
canInstall: true,
|
|
71
|
-
location: value.binary,
|
|
72
|
-
facts: [
|
|
73
|
-
// 渠道与版本各占一条事实;展示层直读结构化字段,不反解拼接文本
|
|
74
|
-
{ code: value.isMissing ? 'program-missing' : 'program-exists', detail: value.channel },
|
|
75
|
-
...(value.version ? [{ code: 'program-version', detail: value.version }] : []),
|
|
76
|
-
],
|
|
77
|
-
actions: value.channel === 'manual'
|
|
78
|
-
? kind === 'officecli'
|
|
79
|
-
? ['connect']
|
|
80
|
-
: []
|
|
81
|
-
: [
|
|
82
|
-
...(value.isMissing
|
|
83
|
-
? ['install']
|
|
84
|
-
: [
|
|
85
|
-
'update',
|
|
86
|
-
'reinstall',
|
|
87
|
-
...(kind === 'officecli' ? ['connect'] : ['login']),
|
|
88
|
-
]),
|
|
89
|
-
'uninstall',
|
|
90
|
-
],
|
|
91
|
-
})),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export async function claudeCommand(ctx, args, isInteractive = false) {
|
|
95
|
-
const candidates = await programs(ctx, 'claude');
|
|
96
|
-
const program = [...candidates.values.values()].find(value => !value.isMissing && !value.binary.endsWith('.cmd'));
|
|
97
|
-
if (program === undefined)
|
|
98
|
-
throw new Error('claude-not-installed');
|
|
99
|
-
return executeClaude(ctx, program.binary, args, { isInteractive });
|
|
100
|
-
}
|
|
101
|
-
function executeClaude(ctx, binary, args, options = {}) {
|
|
102
|
-
return ctx.machine.execute(binary.endsWith('.js') ? process.execPath : binary, binary.endsWith('.js') ? [binary, ...args] : args, { env: claudeEnvironment(ctx), cwd: ctx.home, ...options });
|
|
103
|
-
}
|
|
104
|
-
/** 计划预览变更码按动作显式枚举:模板串会产生字典外码,登录复用既有官方登录入口码 */
|
|
105
|
-
const PROGRAM_ACTION_CHANGE = {
|
|
106
|
-
install: 'program-install',
|
|
107
|
-
update: 'program-update',
|
|
108
|
-
reinstall: 'program-reinstall',
|
|
109
|
-
login: 'login-browser',
|
|
110
|
-
};
|
|
111
|
-
export async function prepareProgram(ctx, kind, selection, program) {
|
|
112
|
-
if (selection.action === 'uninstall')
|
|
113
|
-
return prepareProgramRemoval(ctx, kind, program, !selection.removeData);
|
|
114
|
-
if (kind === 'claude' && program === undefined && selection.action === 'install')
|
|
115
|
-
return prepareClaudeInstall(ctx);
|
|
116
|
-
if (kind === 'officecli' && (program === undefined || program.channel === 'native'))
|
|
117
|
-
return prepareOfficeNative(ctx, selection, program);
|
|
118
|
-
const action = selection.action;
|
|
119
|
-
if (program === undefined)
|
|
120
|
-
throw new Error('program-changed');
|
|
121
|
-
const channel = program.channel;
|
|
122
|
-
if (channel === 'manual')
|
|
123
|
-
throw new Error('channel-not-supported');
|
|
124
|
-
if (action !== 'install' && action !== 'update' && action !== 'reinstall' && action !== 'login')
|
|
125
|
-
throw new Error('action-unavailable');
|
|
126
|
-
if (program.channel === 'npm' && action === 'install' && !program.isMissing)
|
|
127
|
-
throw new Error('program-changed');
|
|
128
|
-
const stamp = await ctx.machine.treeStamp(program.binary);
|
|
129
|
-
let targetVersion = null;
|
|
130
|
-
let targetRegistry;
|
|
131
|
-
if (kind === 'claude' && action !== 'login') {
|
|
132
|
-
if (!channelCanPinVersion(channel))
|
|
133
|
-
throw new Error('pinned-version-channel-unsupported');
|
|
134
|
-
const release = await stableClaudeVersion(ctx);
|
|
135
|
-
targetVersion = release.value;
|
|
136
|
-
targetRegistry = release.registry;
|
|
137
|
-
const current = program.version ?? (await claudeVersion(ctx, program.binary));
|
|
138
|
-
if (current === null)
|
|
139
|
-
throw new Error('program-version-unconfirmed');
|
|
140
|
-
if (current !== null && compareVersions(current, targetVersion) > 0)
|
|
141
|
-
throw new Error('newer-version-preserved');
|
|
142
|
-
}
|
|
143
|
-
if (channel === 'npm' && action !== 'login') {
|
|
144
|
-
const release = kind === 'claude' && targetVersion !== null && targetRegistry !== undefined
|
|
145
|
-
? { value: targetVersion, registry: targetRegistry }
|
|
146
|
-
: await resolveNpmView(ctx.machine, `${PROGRAM_PACKAGES[kind]}@latest`, 'version', exactVersion);
|
|
147
|
-
if (release === null)
|
|
148
|
-
throw new Error('invalid-release');
|
|
149
|
-
targetVersion = release.value;
|
|
150
|
-
targetRegistry = release.registry;
|
|
151
|
-
if (program.version && compareVersions(program.version, release.value) > 0)
|
|
152
|
-
throw new Error('newer-version-preserved');
|
|
153
|
-
}
|
|
154
|
-
const scope = await freezeProgramScope(ctx, program);
|
|
155
|
-
let isComplete = false;
|
|
156
|
-
let isCommandCompleted = false;
|
|
157
|
-
let commandStamp;
|
|
158
|
-
let verifiedBinary;
|
|
159
|
-
let verifiedStamp = null;
|
|
160
|
-
const operation = {
|
|
161
|
-
targetVersion,
|
|
162
|
-
...(targetRegistry !== undefined ? { targetRegistry } : {}),
|
|
163
|
-
get changes() {
|
|
164
|
-
return [
|
|
165
|
-
{
|
|
166
|
-
code: isCommandCompleted ? 'program-installation-confirm' : PROGRAM_ACTION_CHANGE[action],
|
|
167
|
-
detail: `${program.binary} · ${channel}${targetVersion ? ` · ${targetVersion}` : ''}`,
|
|
168
|
-
},
|
|
169
|
-
{ code: 'keep-user-data' },
|
|
170
|
-
];
|
|
171
|
-
},
|
|
172
|
-
async run(report, signal) {
|
|
173
|
-
cancelled(signal);
|
|
174
|
-
if (isCommandCompleted) {
|
|
175
|
-
if (commandStamp === undefined)
|
|
176
|
-
throw new Error('program-installation-unconfirmed');
|
|
177
|
-
if ((await ctx.machine.treeStamp(program.binary)) !== commandStamp)
|
|
178
|
-
throw new Error('program-changed');
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
if ((await ctx.machine.treeStamp(program.binary)) !== stamp)
|
|
182
|
-
throw new Error('program-changed');
|
|
183
|
-
await scope.verify();
|
|
184
|
-
}
|
|
185
|
-
if (action === 'login') {
|
|
186
|
-
success(await executeClaude(ctx, program.binary, ['auth', 'login'], { isInteractive: true }), 'login-failed');
|
|
187
|
-
const status = JSON.parse(success(await executeClaude(ctx, program.binary, ['auth', 'status', '--json'])));
|
|
188
|
-
if (!isObject(status) || status.loggedIn !== true)
|
|
189
|
-
throw new Error('login-unconfirmed');
|
|
190
|
-
isComplete = true;
|
|
191
|
-
report({ state: 'done', code: 'logged-in' });
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
if (!isCommandCompleted)
|
|
195
|
-
await maintainProgramChannel(ctx, program, scope, action, targetVersion, targetRegistry, async () => {
|
|
196
|
-
isCommandCompleted = true;
|
|
197
|
-
report({ state: 'done', code: 'package-command-completed' });
|
|
198
|
-
try {
|
|
199
|
-
commandStamp = await ctx.machine.treeStamp(program.binary);
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
throw new Error('program-installation-unconfirmed', { cause: error });
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
if (channel === 'npm' || channel === 'brew')
|
|
206
|
-
await scope.verify();
|
|
207
|
-
const found = await programs(ctx, kind);
|
|
208
|
-
let selected;
|
|
209
|
-
for (const value of found.values.values())
|
|
210
|
-
if (await scope.matches(value)) {
|
|
211
|
-
selected = value;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
if (selected === undefined || (await ctx.machine.treeStamp(selected.binary)) === null)
|
|
215
|
-
throw new Error('program-not-ready');
|
|
216
|
-
if (channel === 'npm' && selected.version !== targetVersion)
|
|
217
|
-
throw new Error('program-not-ready');
|
|
218
|
-
if (kind === 'claude' && (await claudeVersion(ctx, selected.binary)) !== targetVersion)
|
|
219
|
-
throw new Error('program-not-ready');
|
|
220
|
-
verifiedBinary = selected.binary;
|
|
221
|
-
verifiedStamp = await ctx.machine.treeStamp(selected.binary);
|
|
222
|
-
isComplete = true;
|
|
223
|
-
report({ state: 'done', code: 'program-ready' });
|
|
224
|
-
cancelled(signal);
|
|
225
|
-
},
|
|
226
|
-
remaining: () => (isComplete ? undefined : operation),
|
|
227
|
-
async verify() {
|
|
228
|
-
if (isCommandCompleted && commandStamp === undefined)
|
|
229
|
-
throw new Error('program-installation-unconfirmed');
|
|
230
|
-
if (verifiedBinary && (await ctx.machine.treeStamp(verifiedBinary)) !== verifiedStamp)
|
|
231
|
-
throw new Error('program-changed');
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
return operation;
|
|
235
|
-
}
|
|
236
|
-
async function claudeVersion(ctx, binary) {
|
|
237
|
-
const output = await executeClaude(ctx, binary, ['--version'], { timeoutMs: 10_000 });
|
|
238
|
-
const version = /\b(\d+\.\d+\.\d+)\b/.exec(output.stdout)?.[1];
|
|
239
|
-
return !output.failed && output.code === 0 ? (version ?? null) : null;
|
|
240
|
-
}
|
|
241
|
-
function exactVersion(value) {
|
|
242
|
-
return isExactVersion(value) ? value : null;
|
|
243
|
-
}
|
|
244
|
-
async function stableClaudeVersion(ctx) {
|
|
245
|
-
const release = await resolveNpmView(ctx.machine, `${PROGRAM_PACKAGES.claude}@stable`, 'version', exactVersion);
|
|
246
|
-
if (release !== null)
|
|
247
|
-
return release;
|
|
248
|
-
try {
|
|
249
|
-
const metadata = JSON.parse(await ctx.machine.fetchText(`${NPM_OFFICIAL}/@anthropic-ai%2Fclaude-code/stable`, { timeoutMs: 5_000 }));
|
|
250
|
-
if (!isObject(metadata))
|
|
251
|
-
throw new Error('invalid-release');
|
|
252
|
-
const version = exactVersion(metadata.version);
|
|
253
|
-
if (version === null)
|
|
254
|
-
throw new Error('invalid-release');
|
|
255
|
-
return { value: version, registry: NPM_OFFICIAL };
|
|
256
|
-
}
|
|
257
|
-
catch {
|
|
258
|
-
throw new Error('stable-release-unavailable');
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function installedClaude(ctx, channel, expected) {
|
|
262
|
-
const found = await programs(ctx, 'claude');
|
|
263
|
-
if (found.problems.length)
|
|
264
|
-
throw new Error('installation-state-unconfirmed');
|
|
265
|
-
const program = [...found.values.values()].find(value => value.channel === channel);
|
|
266
|
-
return program !== undefined &&
|
|
267
|
-
(await ctx.machine.treeStamp(program.binary)) !== null &&
|
|
268
|
-
(await claudeVersion(ctx, program.binary)) === expected
|
|
269
|
-
? program
|
|
270
|
-
: undefined;
|
|
271
|
-
}
|
|
272
|
-
/** 新装优先 npm;Windows 在确认无可用安装和 npm 残留后尝试一次 CMD */
|
|
273
|
-
async function prepareClaudeInstall(ctx) {
|
|
274
|
-
const release = await stableClaudeVersion(ctx);
|
|
275
|
-
const targetVersion = release.value;
|
|
276
|
-
const targetRegistry = release.registry;
|
|
277
|
-
let stage = 'npm';
|
|
278
|
-
let isComplete = false;
|
|
279
|
-
let binary;
|
|
280
|
-
let stamp = null;
|
|
281
|
-
let npmScope;
|
|
282
|
-
let npmFailure = null;
|
|
283
|
-
let npmSnapshot;
|
|
284
|
-
let isCleanupCompleted = false;
|
|
285
|
-
let cmdStamp;
|
|
286
|
-
let isCmdFailed = false;
|
|
287
|
-
let installerCleanup;
|
|
288
|
-
const native = userBinary(ctx, 'claude');
|
|
289
|
-
try {
|
|
290
|
-
npmScope = await freezeNpmScope(ctx);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
if (errorCode(error) !== 'npm-not-found')
|
|
294
|
-
throw error;
|
|
295
|
-
npmFailure = 'npm-install-failed';
|
|
296
|
-
}
|
|
297
|
-
const npmRoot = npmScope?.npmRoot;
|
|
298
|
-
const verifyNpmSnapshot = async () => {
|
|
299
|
-
if (npmRoot === undefined)
|
|
300
|
-
return;
|
|
301
|
-
if (npmSnapshot === undefined)
|
|
302
|
-
throw new Error('program-installation-unconfirmed');
|
|
303
|
-
if ((await ctx.machine.treeStamp(path.join(npmRoot, PROGRAM_PACKAGES.claude, 'package.json'))) !==
|
|
304
|
-
npmSnapshot.manifestStamp)
|
|
305
|
-
throw new Error('program-changed');
|
|
306
|
-
if (npmSnapshot.binary && (await ctx.machine.treeStamp(npmSnapshot.binary.file)) !== npmSnapshot.binary.stamp)
|
|
307
|
-
throw new Error('program-changed');
|
|
308
|
-
};
|
|
309
|
-
const cleanInstaller = async () => {
|
|
310
|
-
if (installerCleanup === undefined)
|
|
311
|
-
return;
|
|
312
|
-
const current = await ctx.machine.treeStamp(installerCleanup.directory);
|
|
313
|
-
if (current !== null) {
|
|
314
|
-
if (installerCleanup.stamp !== undefined && current !== installerCleanup.stamp)
|
|
315
|
-
throw new Error('installer-conflict');
|
|
316
|
-
installerCleanup.stamp = current;
|
|
317
|
-
await ctx.machine.removeTree(installerCleanup.directory, current);
|
|
318
|
-
}
|
|
319
|
-
installerCleanup = undefined;
|
|
320
|
-
};
|
|
321
|
-
const confirm = async (program) => {
|
|
322
|
-
binary = program.binary;
|
|
323
|
-
stamp = await ctx.machine.treeStamp(binary);
|
|
324
|
-
isComplete = true;
|
|
325
|
-
};
|
|
326
|
-
// 五段顺次落差推进;段守卫兼作续办重入点
|
|
327
|
-
/** npm 首装段:复核空机与 npm 槽位后落包,留存清单与二进制指纹供后续段核对 */
|
|
328
|
-
const installViaNpm = async (report) => {
|
|
329
|
-
if (stage !== 'npm')
|
|
330
|
-
return;
|
|
331
|
-
const before = await programs(ctx, 'claude');
|
|
332
|
-
if (before.values.size)
|
|
333
|
-
throw new Error('program-changed');
|
|
334
|
-
if (before.problems.length)
|
|
335
|
-
throw new Error('installation-state-unconfirmed');
|
|
336
|
-
await npmScope?.verify();
|
|
337
|
-
stage = 'npm-confirm';
|
|
338
|
-
report({ state: 'kept', code: 'npm-install-started' });
|
|
339
|
-
if (npmRoot === undefined)
|
|
340
|
-
return;
|
|
341
|
-
try {
|
|
342
|
-
const args = npmInstallArgs([
|
|
343
|
-
'install',
|
|
344
|
-
'-g',
|
|
345
|
-
...npmScopeArgs(ctx, npmRoot),
|
|
346
|
-
...npmScriptFlags('claude'),
|
|
347
|
-
`${PROGRAM_PACKAGES.claude}@${targetVersion}`,
|
|
348
|
-
], targetRegistry);
|
|
349
|
-
success(await ctx.machine.npm(args), 'npm-install-failed');
|
|
350
|
-
report({ state: 'done', code: 'package-command-completed' });
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
353
|
-
if (errorCode(error) === 'npm-changed')
|
|
354
|
-
throw error;
|
|
355
|
-
npmFailure = errorCode(error);
|
|
356
|
-
}
|
|
357
|
-
const manifest = path.join(npmRoot, PROGRAM_PACKAGES.claude, 'package.json');
|
|
358
|
-
try {
|
|
359
|
-
const manifestStamp = await ctx.machine.treeStamp(manifest);
|
|
360
|
-
if (manifestStamp === null)
|
|
361
|
-
npmSnapshot = { manifestStamp };
|
|
362
|
-
else {
|
|
363
|
-
const file = await npmBinary(ctx, 'claude', npmRoot);
|
|
364
|
-
npmSnapshot = { manifestStamp, binary: { file, stamp: await ctx.machine.treeStamp(file) } };
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
catch (error) {
|
|
368
|
-
throw new Error('program-installation-unconfirmed', { cause: error });
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
/** npm 确认段:核对指纹并验收;非 Windows 无备选渠道,失败即终局 */
|
|
372
|
-
const confirmNpmInstallation = async (report, signal) => {
|
|
373
|
-
if (stage !== 'npm-confirm')
|
|
374
|
-
return;
|
|
375
|
-
await npmScope?.verify();
|
|
376
|
-
await verifyNpmSnapshot();
|
|
377
|
-
const installed = await installedClaude(ctx, 'npm', targetVersion);
|
|
378
|
-
if (installed !== undefined) {
|
|
379
|
-
await confirm(installed);
|
|
380
|
-
report({ state: 'done', code: 'program-ready', detail: `npm · ${targetVersion}` });
|
|
381
|
-
cancelled(signal);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
cancelled(signal);
|
|
385
|
-
npmFailure ??= 'program-not-ready';
|
|
386
|
-
report({ state: 'kept', code: npmFailure });
|
|
387
|
-
if (ctx.platform !== 'win32')
|
|
388
|
-
throw new Error(npmFailure);
|
|
389
|
-
stage = 'cleanup';
|
|
390
|
-
};
|
|
391
|
-
/** 失败清理段:仅清本次目标版本的 npm 残留,清毕转入 CMD 备选 */
|
|
392
|
-
const cleanupFailedNpmInstall = async (report) => {
|
|
393
|
-
if (stage !== 'cleanup')
|
|
394
|
-
return;
|
|
395
|
-
await npmScope?.verify();
|
|
396
|
-
if (!isCleanupCompleted)
|
|
397
|
-
await verifyNpmSnapshot();
|
|
398
|
-
const remainder = await npmVersion(ctx, PROGRAM_PACKAGES.claude, npmRoot);
|
|
399
|
-
if (remainder !== null) {
|
|
400
|
-
if (remainder !== targetVersion || isCleanupCompleted)
|
|
401
|
-
throw new Error('program-changed');
|
|
402
|
-
success(await ctx.machine.npm(npmUninstallArgs(['uninstall', '-g', ...npmScopeArgs(ctx, npmRoot), PROGRAM_PACKAGES.claude])), 'failed-install-cleanup-failed');
|
|
403
|
-
isCleanupCompleted = true;
|
|
404
|
-
if ((await npmVersion(ctx, PROGRAM_PACKAGES.claude, npmRoot)) !== null)
|
|
405
|
-
throw new Error('failed-install-cleanup-failed');
|
|
406
|
-
report({ state: 'kept', code: 'failed-install-cleaned' });
|
|
407
|
-
}
|
|
408
|
-
stage = 'cmd';
|
|
409
|
-
};
|
|
410
|
-
/** CMD 备选段:拉取官方安装脚本到一次性目录执行,目录即用即清 */
|
|
411
|
-
const installViaCmd = async (report, signal) => {
|
|
412
|
-
if (stage !== 'cmd')
|
|
413
|
-
return;
|
|
414
|
-
const current = await programs(ctx, 'claude');
|
|
415
|
-
if (current.values.size)
|
|
416
|
-
throw new Error('program-changed');
|
|
417
|
-
if (current.problems.length)
|
|
418
|
-
throw new Error('installation-state-unconfirmed');
|
|
419
|
-
cancelled(signal);
|
|
420
|
-
report({ state: 'kept', code: 'cmd-install-started' });
|
|
421
|
-
const script = await ctx.machine.fetchText('https://claude.ai/install.cmd');
|
|
422
|
-
if (/^\s*</.test(script) || !script.trim())
|
|
423
|
-
throw new Error('installer-unavailable');
|
|
424
|
-
const directory = installScratch(ctx, `claude-${randomUUID()}`);
|
|
425
|
-
const file = path.join(directory, 'install.cmd');
|
|
426
|
-
if (!(await ctx.machine.initialize(file, script)))
|
|
427
|
-
throw new Error('installer-conflict');
|
|
428
|
-
installerCleanup = { directory };
|
|
429
|
-
try {
|
|
430
|
-
cancelled(signal);
|
|
431
|
-
stage = 'cmd-confirm';
|
|
432
|
-
const result = await ctx.machine.execute('cmd.exe', ['/d', '/v:off', '/s', '/c', '.\\install.cmd', targetVersion], { env: claudeEnvironment(ctx), cwd: directory });
|
|
433
|
-
isCmdFailed = !succeeded(result);
|
|
434
|
-
if (!isCmdFailed)
|
|
435
|
-
report({ state: 'done', code: 'package-command-completed' });
|
|
436
|
-
try {
|
|
437
|
-
cmdStamp = await ctx.machine.treeStamp(native);
|
|
438
|
-
}
|
|
439
|
-
catch (error) {
|
|
440
|
-
throw new Error('program-installation-unconfirmed', { cause: error });
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
finally {
|
|
444
|
-
await cleanInstaller();
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
/** CMD 确认段:核对原生位指纹并验收 */
|
|
448
|
-
const confirmCmdInstallation = async (report, signal) => {
|
|
449
|
-
if (stage !== 'cmd-confirm')
|
|
450
|
-
return;
|
|
451
|
-
await cleanInstaller();
|
|
452
|
-
if (cmdStamp === undefined)
|
|
453
|
-
throw new Error('program-installation-unconfirmed');
|
|
454
|
-
if ((await ctx.machine.treeStamp(native)) !== cmdStamp)
|
|
455
|
-
throw new Error('program-changed');
|
|
456
|
-
const installed = await installedClaude(ctx, 'native', targetVersion);
|
|
457
|
-
if (installed === undefined)
|
|
458
|
-
throw new Error(isCmdFailed ? 'cmd-install-failed' : 'program-not-ready');
|
|
459
|
-
await confirm(installed);
|
|
460
|
-
report({ state: 'done', code: 'program-ready', detail: `CMD · ${targetVersion}` });
|
|
461
|
-
cancelled(signal);
|
|
462
|
-
};
|
|
463
|
-
const operation = {
|
|
464
|
-
targetVersion,
|
|
465
|
-
targetRegistry,
|
|
466
|
-
get changes() {
|
|
467
|
-
return [
|
|
468
|
-
{
|
|
469
|
-
code: stage === 'npm-confirm' || stage === 'cmd-confirm'
|
|
470
|
-
? 'program-installation-confirm'
|
|
471
|
-
: ctx.platform === 'win32'
|
|
472
|
-
? 'program-install-cmd'
|
|
473
|
-
: 'program-install',
|
|
474
|
-
detail: `${stage === 'cmd-confirm' ? 'CMD' : 'npm'} · ${targetVersion}`,
|
|
475
|
-
},
|
|
476
|
-
{ code: 'keep-user-data' },
|
|
477
|
-
];
|
|
478
|
-
},
|
|
479
|
-
async run(report, signal) {
|
|
480
|
-
cancelled(signal);
|
|
481
|
-
await installViaNpm(report);
|
|
482
|
-
await confirmNpmInstallation(report, signal);
|
|
483
|
-
await cleanupFailedNpmInstall(report);
|
|
484
|
-
await installViaCmd(report, signal);
|
|
485
|
-
await confirmCmdInstallation(report, signal);
|
|
486
|
-
},
|
|
487
|
-
remaining: () => (isComplete ? undefined : operation),
|
|
488
|
-
async verify() {
|
|
489
|
-
if ((stage === 'cmd-confirm' && cmdStamp === undefined) ||
|
|
490
|
-
(stage !== 'npm' && npmRoot !== undefined && npmSnapshot === undefined))
|
|
491
|
-
throw new Error('program-installation-unconfirmed');
|
|
492
|
-
if (binary && (await ctx.machine.treeStamp(binary)) !== stamp)
|
|
493
|
-
throw new Error('program-changed');
|
|
494
|
-
},
|
|
495
|
-
};
|
|
496
|
-
return operation;
|
|
497
|
-
}
|
|
498
|
-
function officeAsset(ctx) {
|
|
499
|
-
const arch = ctx.arch ?? process.arch;
|
|
500
|
-
if (arch !== 'x64' && arch !== 'arm64')
|
|
501
|
-
throw new Error('unsupported-architecture');
|
|
502
|
-
if (ctx.platform === 'win32')
|
|
503
|
-
return `officecli-win-${arch}.exe`;
|
|
504
|
-
if (ctx.platform === 'darwin')
|
|
505
|
-
return `officecli-mac-${arch}`;
|
|
506
|
-
return `officecli-linux-${ctx.libc === 'musl' ? 'alpine-' : ''}${arch}`;
|
|
507
|
-
}
|
|
508
|
-
export async function officeVersion(ctx, binary) {
|
|
509
|
-
const deadlineMs = performance.now() + 5_000;
|
|
510
|
-
const probe = (argument) => ctx.machine.execute(binary, [argument], {
|
|
511
|
-
env: { ...officeIntegration.suppressSelfUpdate },
|
|
512
|
-
cwd: ctx.home,
|
|
513
|
-
timeoutMs: Math.max(1, Math.ceil(deadlineMs - performance.now())),
|
|
514
|
-
});
|
|
515
|
-
const output = await probe('--version');
|
|
516
|
-
const version = /\b(\d+\.\d+\.\d+)\b/.exec(output.stdout)?.[1];
|
|
517
|
-
if (!succeeded(output) || version === undefined)
|
|
518
|
-
return null;
|
|
519
|
-
if (/\bofficecli\b/i.test(output.stdout))
|
|
520
|
-
return version;
|
|
521
|
-
if (performance.now() >= deadlineMs)
|
|
522
|
-
return null;
|
|
523
|
-
const help = await probe('--help');
|
|
524
|
-
return succeeded(help) && /\bofficecli\b/i.test(help.stdout) ? version : null;
|
|
525
|
-
}
|
|
526
|
-
async function officeUpdates(ctx, binary) {
|
|
527
|
-
const files = ['.update', '.update.partial', '.old'].map(suffix => binary + suffix);
|
|
528
|
-
const entries = await ctx.machine.entries(path.dirname(binary));
|
|
529
|
-
return Promise.all(files.map(async (file) => {
|
|
530
|
-
if (entries.some(entry => entry.name === path.basename(file) && entry.kind === 'directory'))
|
|
531
|
-
throw new Error('program-update-conflict');
|
|
532
|
-
return { file, stamp: await ctx.machine.treeStamp(file), isDone: false };
|
|
533
|
-
}));
|
|
534
|
-
}
|
|
535
|
-
async function prepareOfficeNative(ctx, selection, program) {
|
|
536
|
-
const action = selection.action;
|
|
537
|
-
if (action !== 'install' && action !== 'update' && action !== 'reinstall')
|
|
538
|
-
throw new Error('action-unavailable');
|
|
539
|
-
const binary = program?.binary ?? officeBinary(ctx);
|
|
540
|
-
if (!samePath(ctx, binary, officeBinary(ctx)))
|
|
541
|
-
throw new Error('channel-not-supported');
|
|
542
|
-
const before = await ctx.machine.fingerprint(binary);
|
|
543
|
-
if (!program && before !== null)
|
|
544
|
-
throw new Error('program-changed');
|
|
545
|
-
const updates = await officeUpdates(ctx, binary);
|
|
546
|
-
const assetName = officeAsset(ctx);
|
|
547
|
-
const release = JSON.parse(await ctx.machine.fetchText(`https://api.github.com/repos/${OFFICECLI_REPO_SLUG}/releases/latest`));
|
|
548
|
-
if (!isObject(release) ||
|
|
549
|
-
release.draft !== false ||
|
|
550
|
-
release.prerelease !== false ||
|
|
551
|
-
typeof release.tag_name !== 'string' ||
|
|
552
|
-
!/^v\d+\.\d+\.\d+$/.test(release.tag_name) ||
|
|
553
|
-
!Array.isArray(release.assets))
|
|
554
|
-
throw new Error('invalid-release');
|
|
555
|
-
const targetVersion = release.tag_name.slice(1);
|
|
556
|
-
const baseUrl = `https://github.com/${OFFICECLI_REPO_SLUG}/releases/download/${release.tag_name}/`;
|
|
557
|
-
const assets = release.assets.filter(isObject);
|
|
558
|
-
const asset = assets.find(value => value.name === assetName);
|
|
559
|
-
const manifest = assets.find(value => value.name === 'SHA256SUMS');
|
|
560
|
-
if (!asset ||
|
|
561
|
-
asset.browser_download_url !== `${baseUrl}${assetName}` ||
|
|
562
|
-
!manifest ||
|
|
563
|
-
manifest.browser_download_url !== `${baseUrl}SHA256SUMS`)
|
|
564
|
-
throw new Error('release-asset-unavailable');
|
|
565
|
-
const checksums = await ctx.machine.fetchText(`${baseUrl}SHA256SUMS`);
|
|
566
|
-
const matching = checksums
|
|
567
|
-
.split(/\r?\n/)
|
|
568
|
-
.map(line => line.trim().split(/\s+/))
|
|
569
|
-
.filter(parts => parts[1]?.replace(/^\*/, '') === assetName);
|
|
570
|
-
const digest = matching.length === 1 ? matching[0]?.[0]?.toLowerCase() : undefined;
|
|
571
|
-
if (digest === undefined ||
|
|
572
|
-
!/^[a-f0-9]{64}$/.test(digest) ||
|
|
573
|
-
(asset.digest !== undefined && asset.digest !== null && asset.digest !== `sha256:${digest}`))
|
|
574
|
-
throw new Error('release-checksum-unavailable');
|
|
575
|
-
if (before !== null) {
|
|
576
|
-
const currentVersion = program?.version ?? (await officeVersion(ctx, binary));
|
|
577
|
-
if (currentVersion === null)
|
|
578
|
-
throw new Error('program-version-unconfirmed');
|
|
579
|
-
if (compareVersions(currentVersion, targetVersion) > 0)
|
|
580
|
-
throw new Error('newer-version-preserved');
|
|
581
|
-
}
|
|
582
|
-
const bytes = await ctx.machine.fetchBytes(`${baseUrl}${assetName}`);
|
|
583
|
-
if (createHash('sha256').update(bytes).digest('hex') !== digest)
|
|
584
|
-
throw new Error('release-checksum-mismatch');
|
|
585
|
-
let isDeployed = false;
|
|
586
|
-
let isProgramReady = false;
|
|
587
|
-
let isComplete = false;
|
|
588
|
-
const operation = {
|
|
589
|
-
targetVersion,
|
|
590
|
-
targetBinary: binary,
|
|
591
|
-
changes: [
|
|
592
|
-
{ code: PROGRAM_ACTION_CHANGE[action], detail: `OfficeCLI · native · ${targetVersion} · ${binary}` },
|
|
593
|
-
...updates
|
|
594
|
-
.filter(value => value.stamp !== null)
|
|
595
|
-
.map(value => ({ code: 'program-copy-remove', detail: value.file })),
|
|
596
|
-
{ code: 'program-user-path', detail: path.dirname(binary) },
|
|
597
|
-
{ code: 'keep-user-data' },
|
|
598
|
-
],
|
|
599
|
-
async run(report, signal) {
|
|
600
|
-
cancelled(signal);
|
|
601
|
-
if ((await ctx.machine.fingerprint(binary)) !== (isDeployed ? digest : before))
|
|
602
|
-
throw new Error('program-changed');
|
|
603
|
-
for (const update of updates) {
|
|
604
|
-
if ((await ctx.machine.treeStamp(update.file)) !== (update.isDone ? null : update.stamp))
|
|
605
|
-
throw new Error('program-changed');
|
|
606
|
-
if (update.isDone)
|
|
607
|
-
continue;
|
|
608
|
-
if (update.stamp !== null) {
|
|
609
|
-
await ctx.machine.removeTree(update.file, update.stamp);
|
|
610
|
-
report({ state: 'done', code: 'program-copy-removed', detail: update.file });
|
|
611
|
-
}
|
|
612
|
-
update.isDone = true;
|
|
613
|
-
cancelled(signal);
|
|
614
|
-
}
|
|
615
|
-
if (!isDeployed) {
|
|
616
|
-
await ctx.machine.replaceFile(binary, bytes, before, true);
|
|
617
|
-
isDeployed = true;
|
|
618
|
-
report({ state: 'done', code: 'program-file-ready', detail: binary });
|
|
619
|
-
}
|
|
620
|
-
if (!isProgramReady) {
|
|
621
|
-
if ((await officeVersion(ctx, binary)) !== targetVersion)
|
|
622
|
-
throw new Error('program-not-ready');
|
|
623
|
-
isProgramReady = true;
|
|
624
|
-
report({ state: 'done', code: 'program-ready', detail: `native · ${targetVersion}` });
|
|
625
|
-
}
|
|
626
|
-
cancelled(signal);
|
|
627
|
-
await ctx.machine.ensureUserPath(path.dirname(binary));
|
|
628
|
-
if ((await ctx.machine.fingerprint(binary)) !== digest)
|
|
629
|
-
throw new Error('program-changed');
|
|
630
|
-
for (const update of updates)
|
|
631
|
-
if ((await ctx.machine.treeStamp(update.file)) !== null)
|
|
632
|
-
throw new Error('program-changed');
|
|
633
|
-
isComplete = true;
|
|
634
|
-
report({ state: 'done', code: 'program-user-path', detail: path.dirname(binary) });
|
|
635
|
-
cancelled(signal);
|
|
636
|
-
},
|
|
637
|
-
remaining: () => (isComplete ? undefined : operation),
|
|
638
|
-
async verify() {
|
|
639
|
-
if (isDeployed && (await ctx.machine.fingerprint(binary)) !== digest)
|
|
640
|
-
throw new Error('program-changed');
|
|
641
|
-
for (const update of updates)
|
|
642
|
-
if ((await ctx.machine.treeStamp(update.file)) !== null)
|
|
643
|
-
throw new Error('program-changed');
|
|
644
|
-
},
|
|
645
|
-
};
|
|
646
|
-
return operation;
|
|
647
|
-
}
|
|
648
|
-
/** Claude 变更前的进程复核:枚举失败保留未知,不臆断未运行 */
|
|
649
|
-
async function ensureClaudeNotRunning(ctx) {
|
|
650
|
-
const isClaudeActive = await claudeRunning(ctx.machine);
|
|
651
|
-
if (isClaudeActive !== false)
|
|
652
|
-
throw new Error(isClaudeActive ? 'claude-running' : 'process-state-unconfirmed');
|
|
653
|
-
}
|
|
654
|
-
async function prepareProgramRemoval(ctx, kind, program, shouldPreserveData = true) {
|
|
655
|
-
if (!program)
|
|
656
|
-
throw new Error('program-not-installed');
|
|
657
|
-
if (program.channel === 'manual')
|
|
658
|
-
throw new Error('channel-not-supported');
|
|
659
|
-
if (kind === 'claude')
|
|
660
|
-
await ensureClaudeNotRunning(ctx);
|
|
661
|
-
const before = await ctx.machine.treeStamp(program.binary);
|
|
662
|
-
const scope = await freezeProgramScope(ctx, program);
|
|
663
|
-
if (kind === 'officecli' &&
|
|
664
|
-
program.channel === 'native' &&
|
|
665
|
-
before !== null &&
|
|
666
|
-
(await officeVersion(ctx, program.binary)) === null)
|
|
667
|
-
throw new Error('program-identity-unconfirmed');
|
|
668
|
-
const nativeFiles = program.channel === 'native'
|
|
669
|
-
? [program.binary, ...(kind === 'claude' ? [path.join(ctx.home, '.local/share/claude')] : [])]
|
|
670
|
-
: [];
|
|
671
|
-
const removals = [
|
|
672
|
-
...(await Promise.all(nativeFiles.map(async (file) => ({ file, stamp: await ctx.machine.treeStamp(file), isDone: false })))),
|
|
673
|
-
...(program.channel === 'native' && kind === 'officecli' ? await officeUpdates(ctx, program.binary) : []),
|
|
674
|
-
];
|
|
675
|
-
let isComplete = false;
|
|
676
|
-
let hasAttemptedCommand = false;
|
|
677
|
-
let isCommandFailed = false;
|
|
678
|
-
let isBinaryRemoved = false;
|
|
679
|
-
const verifyRemoved = async () => {
|
|
680
|
-
if (program.channel === 'npm') {
|
|
681
|
-
await scope.verify();
|
|
682
|
-
if ((await npmVersion(ctx, PROGRAM_PACKAGES[kind], scope.npmRoot)) !== null)
|
|
683
|
-
throw new Error('program-still-installed');
|
|
684
|
-
}
|
|
685
|
-
if ((await ctx.machine.treeStamp(program.binary)) !== null)
|
|
686
|
-
throw new Error('program-still-installed');
|
|
687
|
-
for (const target of removals)
|
|
688
|
-
if ((await ctx.machine.treeStamp(target.file)) !== null)
|
|
689
|
-
throw new Error('program-still-installed');
|
|
690
|
-
};
|
|
691
|
-
const operation = {
|
|
692
|
-
targetVersion: null,
|
|
693
|
-
get changes() {
|
|
694
|
-
const pending = removals.filter(value => !value.isDone && value.stamp !== null);
|
|
695
|
-
return [
|
|
696
|
-
...(removals.length
|
|
697
|
-
? pending.length
|
|
698
|
-
? pending.map(value => ({
|
|
699
|
-
code: value.file === program.binary ? 'program-uninstall' : 'program-copy-remove',
|
|
700
|
-
detail: value.file,
|
|
701
|
-
}))
|
|
702
|
-
: [{ code: 'program-removal-confirm' }]
|
|
703
|
-
: hasAttemptedCommand
|
|
704
|
-
? [{ code: 'program-removal-confirm' }]
|
|
705
|
-
: [{ code: 'program-uninstall', detail: `${program.channel} · ${program.binary}` }]),
|
|
706
|
-
...(shouldPreserveData ? [{ code: 'keep-user-data' }] : []),
|
|
707
|
-
];
|
|
708
|
-
},
|
|
709
|
-
async run(report, signal) {
|
|
710
|
-
cancelled(signal);
|
|
711
|
-
if (kind === 'claude')
|
|
712
|
-
await ensureClaudeNotRunning(ctx);
|
|
713
|
-
if (removals.length) {
|
|
714
|
-
for (const target of removals) {
|
|
715
|
-
if (target.isDone) {
|
|
716
|
-
if ((await ctx.machine.treeStamp(target.file)) !== null)
|
|
717
|
-
throw new Error('program-changed');
|
|
718
|
-
continue;
|
|
719
|
-
}
|
|
720
|
-
cancelled(signal);
|
|
721
|
-
if ((await ctx.machine.treeStamp(target.file)) !== target.stamp)
|
|
722
|
-
throw new Error('program-changed');
|
|
723
|
-
if (target.stamp !== null)
|
|
724
|
-
await ctx.machine.removeTree(target.file, target.stamp);
|
|
725
|
-
target.isDone = true;
|
|
726
|
-
report({ state: target.stamp === null ? 'kept' : 'done', code: 'program-copy-removed', detail: target.file });
|
|
727
|
-
cancelled(signal);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
const isConfirming = hasAttemptedCommand;
|
|
732
|
-
if (!hasAttemptedCommand) {
|
|
733
|
-
if ((await ctx.machine.treeStamp(program.binary)) !== before)
|
|
734
|
-
throw new Error('program-changed');
|
|
735
|
-
await scope.verify();
|
|
736
|
-
const result = await removeProgramChannel(ctx, program, scope);
|
|
737
|
-
hasAttemptedCommand = true;
|
|
738
|
-
isCommandFailed = !succeeded(result);
|
|
739
|
-
if (!isCommandFailed)
|
|
740
|
-
report({ state: 'kept', code: 'program-uninstall-command-completed' });
|
|
741
|
-
}
|
|
742
|
-
const current = await ctx.machine.treeStamp(program.binary);
|
|
743
|
-
if (current === null && before !== null && !isBinaryRemoved) {
|
|
744
|
-
isBinaryRemoved = true;
|
|
745
|
-
report({ state: 'done', code: 'program-copy-removed', detail: program.binary });
|
|
746
|
-
}
|
|
747
|
-
try {
|
|
748
|
-
await verifyRemoved();
|
|
749
|
-
}
|
|
750
|
-
catch (error) {
|
|
751
|
-
const code = errorCode(error);
|
|
752
|
-
if (code === 'program-still-installed' && current === before)
|
|
753
|
-
hasAttemptedCommand = false;
|
|
754
|
-
throw new Error(code === 'program-still-installed'
|
|
755
|
-
? isCommandFailed
|
|
756
|
-
? 'program-uninstall-failed'
|
|
757
|
-
: code
|
|
758
|
-
: 'program-removal-unconfirmed', { cause: error });
|
|
759
|
-
}
|
|
760
|
-
if (isCommandFailed && program.channel !== 'npm') {
|
|
761
|
-
if (!isConfirming || (await programPackageAbsent(ctx, program, scope)) !== true)
|
|
762
|
-
throw new Error('program-removal-unconfirmed');
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
await verifyRemoved();
|
|
766
|
-
isComplete = true;
|
|
767
|
-
report({ state: 'done', code: 'program-removed', detail: program.binary });
|
|
768
|
-
if (shouldPreserveData)
|
|
769
|
-
report({ state: 'kept', code: 'keep-user-data' });
|
|
770
|
-
try {
|
|
771
|
-
const found = await programs(ctx, kind);
|
|
772
|
-
for (const value of found.values.values())
|
|
773
|
-
report({ state: 'kept', code: 'program-other-copies-kept', detail: value.binary });
|
|
774
|
-
for (const code of found.problems)
|
|
775
|
-
report({ state: 'kept', code: 'program-inspection-warning', detail: code });
|
|
776
|
-
}
|
|
777
|
-
catch (error) {
|
|
778
|
-
report({ state: 'kept', code: 'program-inspection-warning', detail: errorCode(error) });
|
|
779
|
-
}
|
|
780
|
-
cancelled(signal);
|
|
781
|
-
},
|
|
782
|
-
remaining: () => (isComplete ? undefined : operation),
|
|
783
|
-
verify: verifyRemoved,
|
|
784
|
-
};
|
|
785
|
-
return operation;
|
|
786
|
-
}
|
|
787
|
-
/** 三段语义化版本比较:正值为左更新;ccline 的降级门共用 */
|
|
788
|
-
export function compareVersions(left, right) {
|
|
789
|
-
const a = left.split('.').map(Number);
|
|
790
|
-
const b = right.split('.').map(Number);
|
|
791
|
-
for (let index = 0; index < 3; index++) {
|
|
792
|
-
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
793
|
-
if (difference !== 0)
|
|
794
|
-
return difference;
|
|
795
|
-
}
|
|
796
|
-
return 0;
|
|
797
|
-
}
|