@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/errors.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
export const ERROR_MESSAGES = {
|
|
2
|
-
'npm-changed': { brief: '环境已变化', detail: 'npm 已变化,请重启 CCW 后重新操作' },
|
|
3
|
-
'inspection-timeout': { brief: '检查超时', detail: '检查超时,请刷新重试' },
|
|
4
|
-
'source-timeout': { brief: '获取超时', detail: '获取资源失败:请求超时' },
|
|
5
|
-
'invalid-data-root': { brief: '删除范围无效', detail: '删除用户数据失败:目录范围过大' },
|
|
6
|
-
'claude-removal-required': { brief: '请先选择程序', detail: '删除用户数据失败:未选择 Claude 程序' },
|
|
7
|
-
'program-removal-unconfirmed': { brief: '卸载待确认', detail: '确认程序卸载失败:状态未知' },
|
|
8
|
-
'program-still-installed': { brief: '卸载失败', detail: '卸载程序失败:程序仍存在' },
|
|
9
|
-
'program-uninstall-failed': { brief: '卸载失败', detail: '卸载程序失败' },
|
|
10
|
-
'npm-uninstall-failed': { brief: '卸载失败', detail: '卸载 npm 程序失败' },
|
|
11
|
-
'program-installation-unconfirmed': { brief: '安装待确认', detail: '确认程序安装失败:状态未知' },
|
|
12
|
-
'program-identity-unconfirmed': { brief: '身份待确认', detail: '确认程序失败:身份未知' },
|
|
13
|
-
'program-update-conflict': { brief: '程序已变化', detail: '更新程序失败:目标已变化' },
|
|
14
|
-
'program-scope-unconfirmed': { brief: '管理范围待确认', detail: '确认程序失败:包管理器范围未知;保留程序' },
|
|
15
|
-
'user-path-save-failed': { brief: '路径保存失败', detail: '保存用户命令路径失败' },
|
|
16
|
-
'user-home-unconfirmed': { brief: '用户目录待确认', detail: '确认用户目录失败:位置未知' },
|
|
17
|
-
'release-asset-unavailable': { brief: '获取程序失败', detail: '获取发布程序失败:平台文件缺失' },
|
|
18
|
-
'release-checksum-unavailable': { brief: '校验信息缺失', detail: '校验发布程序失败:校验信息缺失' },
|
|
19
|
-
'release-checksum-mismatch': { brief: '程序校验失败', detail: '校验下载程序失败:完整性不符' },
|
|
20
|
-
'unsupported-architecture': { brief: '架构不支持', detail: '安装程序失败:处理器架构不支持' },
|
|
21
|
-
'program-selection-required': { brief: '请选择副本', detail: '选择程序失败:发现多个副本' },
|
|
22
|
-
'source-metadata-unavailable': { brief: '来源记录异常', detail: '本次未能完成技能来源记录的读取或保存' },
|
|
23
|
-
'api-fields-required': { brief: '请补全连接项', detail: '保存配置失败:缺少 Base URL 和 API Key' },
|
|
24
|
-
'base-url-required': { brief: '请填写地址', detail: '保存配置失败:缺少 Base URL' },
|
|
25
|
-
'plan-unavailable': { brief: '计划已失效', detail: '执行操作失败:计划已失效' },
|
|
26
|
-
'operation-in-progress': { brief: '已有操作进行', detail: '执行操作失败:另一批操作进行中' },
|
|
27
|
-
'empty-selection': { brief: '请先选择内容', detail: '执行操作失败:未选择变更' },
|
|
28
|
-
'duplicate-selection': { brief: '选择存在冲突', detail: '选择内容失败:同一内容有多个动作' },
|
|
29
|
-
'npm-inspection-failed': { brief: '安装记录读取失败', detail: '读取 npm 安装记录失败' },
|
|
30
|
-
'invalid-npm-result': { brief: '安装记录无效', detail: '读取 npm 安装记录失败:格式无效' },
|
|
31
|
-
'npm-not-found': { brief: '管理程序缺失', detail: '执行 npm 失败:程序缺失' },
|
|
32
|
-
'npm-install-failed': { brief: '安装失败', detail: '安装 npm 程序失败' },
|
|
33
|
-
'command-failed': { brief: '执行失败', detail: '执行命令失败' },
|
|
34
|
-
'invalid-settings': { brief: '配置读取失败', detail: '读取配置失败:格式无效;保留文件' },
|
|
35
|
-
'target-changed': { brief: '目标已变化', detail: '操作目标失败:目标已变化' },
|
|
36
|
-
'settings-changed': { brief: '配置已变化', detail: '写入设置失败:配置已变化' },
|
|
37
|
-
'connection-changed': { brief: '接入已变化', detail: '修改接入失败:配置已变化' },
|
|
38
|
-
'program-changed': { brief: '程序已变化', detail: '操作程序失败:程序已变化' },
|
|
39
|
-
'binary-changed': { brief: '文件已变化', detail: '操作程序副本失败:文件已变化;保留副本' },
|
|
40
|
-
'program-not-ready': { brief: '程序未就绪', detail: '确认程序失败:命令完成但程序未就绪' },
|
|
41
|
-
'binary-version-mismatch': { brief: '程序版本不符', detail: '确认程序失败:版本不符' },
|
|
42
|
-
'target-remains': { brief: '删除未完成', detail: '删除内容失败:目标仍存在' },
|
|
43
|
-
'newer-version-preserved': { brief: '较新版未替换', detail: '保留较新版本' },
|
|
44
|
-
'manual-program-preserved': { brief: '手工版未替换', detail: '保留手工安装的程序' },
|
|
45
|
-
'channel-not-supported': { brief: '渠道暂不支持', detail: '管理程序失败:需使用原安装管理器' },
|
|
46
|
-
'appearance-changed': { brief: '外观已变化', detail: '修改外观失败:配置已变化;保留配置' },
|
|
47
|
-
'appearance-migration-required': { brief: '外观需要迁移', detail: '配置外观失败:需要迁移;保留配置' },
|
|
48
|
-
'invalid-appearance': { brief: '外观配置无效', detail: '读取外观失败:格式错误;保留配置' },
|
|
49
|
-
'npm-package-missing': { brief: '程序包缺失', detail: 'npm 程序包缺失' },
|
|
50
|
-
'asset-missing': { brief: '运行资源缺失', detail: '运行包资产缺失' },
|
|
51
|
-
'claude-not-installed': { brief: '请先安装程序', detail: 'Claude 程序缺失' },
|
|
52
|
-
'plugin-command-failed': { brief: '插件操作失败', detail: '执行插件命令失败' },
|
|
53
|
-
'marketplace-command-failed': { brief: '市场准备失败', detail: '准备插件市场失败' },
|
|
54
|
-
'plugin-not-ready': { brief: '插件未就绪', detail: '安装插件失败:插件未就绪' },
|
|
55
|
-
'plugin-not-enabled': { brief: '插件启用失败', detail: '启用插件失败' },
|
|
56
|
-
'plugin-remains': { brief: '插件卸载未完', detail: '卸载插件失败:安装或启用记录仍存在' },
|
|
57
|
-
'plugin-keep-data-unconfirmed': {
|
|
58
|
-
brief: '保留未确认',
|
|
59
|
-
detail: '无法确认官方卸载支持保留数据;已阻止重装,请检查 Claude CLI 后重试',
|
|
60
|
-
},
|
|
61
|
-
'credential-required': { brief: '请填写密钥', detail: '保存配置失败:缺少 API Key' },
|
|
62
|
-
'invalid-base-url': { brief: '地址无效', detail: '地址需使用 HTTP 或 HTTPS,不能包含用户名、密码、查询参数或片段' },
|
|
63
|
-
'inherited-configuration-conflict': { brief: '连接配置冲突', detail: '配置连接失败:外部环境变量覆盖设置' },
|
|
64
|
-
'login-failed': { brief: '登录失败', detail: '登录官方账号失败' },
|
|
65
|
-
'login-unconfirmed': { brief: '登录待确认', detail: '确认登录失败:状态未知' },
|
|
66
|
-
'local-edits-preserved': { brief: '替换未执行', detail: '保留内容:来源未知或内容已修改;可备份并替换' },
|
|
67
|
-
'source-version-unavailable': { brief: '资源版本待确认', detail: '确认资源失败:版本对应关系未知' },
|
|
68
|
-
'source-unavailable': { brief: '获取资源失败', detail: '获取来源失败' },
|
|
69
|
-
'source-empty': { brief: '预期资源缺失', detail: '获取来源失败:预期资源缺失' },
|
|
70
|
-
'skill-payload-missing': { brief: '技能资源无效', detail: '读取技能资源失败:下载内容缺少有效 SKILL.md' },
|
|
71
|
-
'skill-name-conflict': { brief: '技能名称冲突', detail: '安装技能失败:同名技能导致目录未知' },
|
|
72
|
-
'not-in-update-catalog': { brief: '暂不支持更新', detail: '更新内容失败:不在 CCW 清单;可解除接入' },
|
|
73
|
-
'changes-not-started': { brief: '操作未开始', detail: '准备操作失败' },
|
|
74
|
-
'skill-entry-invalid': { brief: '技能入口无效', detail: '读取技能入口失败:内容为空或不可读' },
|
|
75
|
-
'invalid-mcp-registration': { brief: '服务注册无效', detail: '读取 MCP 注册失败:格式无效;可重新配置或解除接入' },
|
|
76
|
-
'file-too-large': { brief: '文件过大', detail: '读取文件失败:文件过大' },
|
|
77
|
-
'cleanup-inspection-incomplete': { brief: '数据检查不完整', detail: '检查数据失败:读取不完整' },
|
|
78
|
-
'cleanup-network-root': { brief: '目录不受支持', detail: '删除数据失败:网络目录不受支持;保留目录' },
|
|
79
|
-
'cleanup-type-changed': { brief: '目标类型已变', detail: '删除数据失败:目标类型已变化;保留目标' },
|
|
80
|
-
'stable-release-unavailable': { brief: '版本获取失败', detail: '确认 stable 版本失败:来源不可用' },
|
|
81
|
-
'cmd-install-failed': { brief: '备用安装失败', detail: '执行 CMD 备用安装失败' },
|
|
82
|
-
'failed-install-cleanup-failed': { brief: '安装残留未清', detail: '清理 npm 安装残留失败;跳过备用安装' },
|
|
83
|
-
'installation-state-unconfirmed': { brief: '安装待确认', detail: '确认安装状态失败:状态未知' },
|
|
84
|
-
'pinned-version-channel-unsupported': {
|
|
85
|
-
brief: '渠道不支持更新',
|
|
86
|
-
detail: '更新程序失败:渠道不支持固定版本;保留程序',
|
|
87
|
-
},
|
|
88
|
-
'program-version-unconfirmed': { brief: '版本待确认', detail: '确认程序版本失败:版本未知;保留程序' },
|
|
89
|
-
'claude-may-be-running': { brief: '清理已暂停', detail: '清理数据暂停:Claude 可能正在使用数据' },
|
|
90
|
-
'linked-parent': { brief: '路径不可操作', detail: '保留目录:路径经过共享链接' },
|
|
91
|
-
'not-regular-file': { brief: '目标不可操作', detail: '保留目标:链接或特殊文件' },
|
|
92
|
-
'action-unavailable': { brief: '操作暂不支持', detail: '执行操作失败:操作不受支持' },
|
|
93
|
-
'invalid-release': { brief: '发布版本无效', detail: '读取发布版本失败:格式未知' },
|
|
94
|
-
'serena-install-failed': { brief: '服务安装失败', detail: '安装 Serena 失败' },
|
|
95
|
-
'unsupported-ccline-release': { brief: '版本暂不支持', detail: '保留 CCometixLine:版本需要新兼容验证' },
|
|
96
|
-
'channel-change-required': { brief: '需要重新接入', detail: '接入服务失败:启动渠道不同;需重新接入' },
|
|
97
|
-
'serena-initialization-failed': { brief: '服务初始化失败', detail: '初始化 Serena 失败' },
|
|
98
|
-
'marketplace-source-conflict': { brief: '市场来源不符', detail: '保留同名市场:来源不同' },
|
|
99
|
-
'overlapping-selection': { brief: '选择范围重复', detail: '选择内容失败:与同批另一项的操作范围重叠' },
|
|
100
|
-
'installer-unavailable': { brief: '安装未执行', detail: '安装程序失败:官方来源返回网页;未执行安装' },
|
|
101
|
-
'selected-item-unavailable': { brief: '所选内容失效', detail: '选择内容失败:内容不在检查结果' },
|
|
102
|
-
'integration-source-conflict': { brief: '接入来源待确认', detail: '接入内容失败:同名入口与程序关系未知' },
|
|
103
|
-
'claude-running': { brief: '请先退出程序', detail: '执行 Claude 操作失败:Claude 正在运行' },
|
|
104
|
-
'process-state-unconfirmed': { brief: '进程待确认', detail: '确认 Claude 进程失败:状态未知' },
|
|
105
|
-
'backup-exists': { brief: '备份目标已存在', detail: '保存备份失败:目标已存在' },
|
|
106
|
-
'report-name-conflict': { brief: '报告文件冲突', detail: '保存诊断报告失败:同名报告过多' },
|
|
107
|
-
'connection-not-applied': { brief: '接入未生效', detail: '确认接入失败:配置未生效' },
|
|
108
|
-
'inspection-failed': { brief: '检查失败', detail: '检查内容失败' },
|
|
109
|
-
'installer-conflict': { brief: '安装目标冲突', detail: '启动安装器失败:临时目标已存在' },
|
|
110
|
-
'invalid-config-root': { brief: '配置目录无效', detail: '启动 CCW 失败:配置目录无效' },
|
|
111
|
-
'invalid-command': { brief: '命令调用无效', detail: '执行命令失败:调用参数无效' },
|
|
112
|
-
'invalid-data-category': { brief: '类别无效', detail: '清理数据失败:类别不受支持' },
|
|
113
|
-
'invalid-mcp-name': { brief: '名称无效', detail: '接入 MCP 失败:名称不受支持' },
|
|
114
|
-
'invalid-npm-command': { brief: 'npm 命令无效', detail: '执行 npm 失败:命令不受支持' },
|
|
115
|
-
'invalid-plugin-id': { brief: '插件标识无效', detail: '管理插件失败:标识不符合市场语法' },
|
|
116
|
-
'config-root-relative': { brief: '请使用绝对路径', detail: '确认 CCometixLine 目录失败:路径需使用绝对地址' },
|
|
117
|
-
'invalid-npm-root': { brief: '管理目录无效', detail: '读取 npm 目录失败:路径无效' },
|
|
118
|
-
'invalid-plugin-record': { brief: '插件记录无效', detail: '读取插件记录失败:格式无效' },
|
|
119
|
-
'invalid-program-entry': { brief: '程序入口无效', detail: '确认程序失败:入口无效' },
|
|
120
|
-
'invalid-source': { brief: '来源配置无效', detail: '读取来源失败:配置无效' },
|
|
121
|
-
'invalid-source-path': { brief: '来源路径无效', detail: '读取来源失败:路径无效' },
|
|
122
|
-
'invalid-source-url': { brief: '来源地址无效', detail: '读取来源失败:地址无效' },
|
|
123
|
-
'invalid-target': { brief: '目标路径无效', detail: '操作目标失败:路径无效' },
|
|
124
|
-
'invalid-tool-directory': { brief: '工具目录无效', detail: '确认工具目录失败:路径无效' },
|
|
125
|
-
'source-link-unsupported': { brief: '共享链接不支持', detail: '读取来源失败:不支持共享链接' },
|
|
126
|
-
'source-too-large': { brief: '来源内容过大', detail: '读取来源失败:内容过大' },
|
|
127
|
-
'special-file': { brief: '文件类型不支持', detail: '读取文件失败:不支持特殊文件' },
|
|
128
|
-
'unknown-selection': { brief: '选择无效', detail: '准备操作失败:所选内容不受支持' },
|
|
129
|
-
'unknown-argument': {
|
|
130
|
-
brief: '参数无效',
|
|
131
|
-
detail: '只接受一个模式:--help、--version、--inspect 或 --collect-logs;可附加一次 --details;不接受其他参数',
|
|
132
|
-
},
|
|
133
|
-
'interactive-terminal-required': { brief: '需要交互终端', detail: '启动界面失败:需要交互终端' },
|
|
134
|
-
'unsupported-platform': { brief: '系统暂不支持', detail: '启动 CCW 失败:系统不支持' },
|
|
135
|
-
EEXIST: { brief: '目标已存在', detail: '写入内容失败:同名目标存在或另一轮写入进行中' },
|
|
136
|
-
EACCES: { brief: '访问失败', detail: '访问内容失败:权限不足' },
|
|
137
|
-
EPERM: { brief: '访问失败', detail: '访问内容失败:目标占用或权限不足' },
|
|
138
|
-
ENOENT: { brief: '目标不存在', detail: '操作目标失败:目标不存在' },
|
|
139
|
-
'operation-failed': { brief: '操作失败', detail: '执行操作失败:原因未知' },
|
|
140
|
-
};
|
package/dist/legacy-amirc.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { cancelled, json, MCP_SERVERS_KEY, object, readMcpServers, removeFields, sequence, unchanged, } from './model.js';
|
|
2
|
-
const OWNED_RULES = ['mcp__amirc__organize_papers', 'mcp__amirc__search_papers', 'mcp__amirc__get_papers'];
|
|
3
|
-
function allowedTools(settings) {
|
|
4
|
-
const allow = object(settings.permissions).allow;
|
|
5
|
-
if (allow === undefined)
|
|
6
|
-
return [];
|
|
7
|
-
if (!Array.isArray(allow) || !allow.every((rule) => typeof rule === 'string'))
|
|
8
|
-
throw new Error('invalid-settings');
|
|
9
|
-
return allow;
|
|
10
|
-
}
|
|
11
|
-
export async function hasLegacyAmircPermissions(ctx) {
|
|
12
|
-
return allowedTools(await json(ctx.machine, ctx.settingsFile)).some(rule => OWNED_RULES.includes(rule));
|
|
13
|
-
}
|
|
14
|
-
/** 退役迁移只解除明确选择的旧注册与精确允许规则,保留技能与用户材料 */
|
|
15
|
-
export async function prepareLegacyAmircDetach(ctx) {
|
|
16
|
-
const before = await readMcpServers(ctx);
|
|
17
|
-
const allowBefore = allowedTools(await json(ctx.machine, ctx.settingsFile));
|
|
18
|
-
if (before.amirc === undefined && !allowBefore.some(rule => OWNED_RULES.includes(rule)))
|
|
19
|
-
throw new Error('no-connection');
|
|
20
|
-
let hasAttemptedWrite = false;
|
|
21
|
-
let isWritten = false;
|
|
22
|
-
let isComplete = false;
|
|
23
|
-
const selected = OWNED_RULES.filter(rule => allowBefore.includes(rule));
|
|
24
|
-
const verify = async () => {
|
|
25
|
-
const current = allowedTools(await json(ctx.machine, ctx.settingsFile));
|
|
26
|
-
if (current.some(rule => OWNED_RULES.includes(rule)))
|
|
27
|
-
throw new Error('target-changed');
|
|
28
|
-
};
|
|
29
|
-
const permissions = {
|
|
30
|
-
writes: [ctx.settingsFile],
|
|
31
|
-
get changes() {
|
|
32
|
-
return [{ code: isWritten ? 'removal-confirm' : 'amirc-permissions-remove' }];
|
|
33
|
-
},
|
|
34
|
-
async run(report, signal) {
|
|
35
|
-
cancelled(signal);
|
|
36
|
-
const current = allowedTools(await json(ctx.machine, ctx.settingsFile));
|
|
37
|
-
if (selected.length && !isWritten && (!hasAttemptedWrite || current.some(rule => OWNED_RULES.includes(rule)))) {
|
|
38
|
-
await ctx.machine.editJson(ctx.settingsFile, settings => {
|
|
39
|
-
const allow = allowedTools(settings);
|
|
40
|
-
unchanged(OWNED_RULES.filter(rule => allow.includes(rule)), selected);
|
|
41
|
-
settings.permissions = {
|
|
42
|
-
...object(settings.permissions),
|
|
43
|
-
allow: allow.filter(rule => !selected.includes(rule)),
|
|
44
|
-
};
|
|
45
|
-
hasAttemptedWrite = true;
|
|
46
|
-
});
|
|
47
|
-
isWritten = true;
|
|
48
|
-
}
|
|
49
|
-
await verify();
|
|
50
|
-
isComplete = true;
|
|
51
|
-
report({ state: 'done', code: 'amirc-permissions-removed' });
|
|
52
|
-
},
|
|
53
|
-
remaining: () => (isComplete ? undefined : permissions),
|
|
54
|
-
verify,
|
|
55
|
-
};
|
|
56
|
-
return sequence([
|
|
57
|
-
removeFields(ctx, ctx.stateFile, { amirc: before.amirc }, [{ code: 'mcp-remove-registration', detail: 'amirc' }, { code: 'mcp-keep-runtime' }], { state: 'done', code: 'registration-removed', detail: 'amirc' }, MCP_SERVERS_KEY),
|
|
58
|
-
permissions,
|
|
59
|
-
]);
|
|
60
|
-
}
|
package/dist/mcp.js
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { knownTitle } from './titles.js';
|
|
4
|
-
import { mcpSpecs } from './management-catalog.js';
|
|
5
|
-
import { errorCode, isObject } from './machine.js';
|
|
6
|
-
import { cancelled, editFields, MCP_SERVERS_KEY, readMcpServers, removeFields, restOf, success, unchanged, userBinDirectory, userBinary, } from './model.js';
|
|
7
|
-
import { isExactVersion } from './npm-registry.js';
|
|
8
|
-
import { hasLegacyAmircPermissions, prepareLegacyAmircDetach } from './legacy-amirc.js';
|
|
9
|
-
import { installScratch } from './storage.js';
|
|
10
|
-
const MCP_PROTOCOLS = {
|
|
11
|
-
http: ['http:', 'https:'],
|
|
12
|
-
'streamable-http': ['http:', 'https:'],
|
|
13
|
-
sse: ['http:', 'https:'],
|
|
14
|
-
ws: ['ws:', 'wss:'],
|
|
15
|
-
};
|
|
16
|
-
function validRegistration(value) {
|
|
17
|
-
if (!isObject(value))
|
|
18
|
-
return false;
|
|
19
|
-
if (value.type === undefined || value.type === 'stdio')
|
|
20
|
-
return (typeof value.command === 'string' &&
|
|
21
|
-
Boolean(value.command.trim()) &&
|
|
22
|
-
(value.args === undefined || (Array.isArray(value.args) && value.args.every(arg => typeof arg === 'string'))));
|
|
23
|
-
const protocols = typeof value.type === 'string' ? MCP_PROTOCOLS[value.type] : undefined;
|
|
24
|
-
if (protocols === undefined || typeof value.url !== 'string')
|
|
25
|
-
return false;
|
|
26
|
-
try {
|
|
27
|
-
return protocols.includes(new URL(value.url).protocol);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Serena 命令形状判定:注册身份确认与更新渠道守卫共用同一谓词 */
|
|
34
|
-
const isSerenaCommand = (command) => /(?:^|[\\/])serena(?:\.exe)?$/.test(command);
|
|
35
|
-
/** 以本地形状证据判定注册身份:与 CCW 写入模板一致才算确认,证据不足保留原始键名;
|
|
36
|
-
* 不联网、不启动程序 */
|
|
37
|
-
function confirmedMcpTitle(name, registration) {
|
|
38
|
-
if (registration === undefined)
|
|
39
|
-
return knownTitle(`mcp:${name}`, name);
|
|
40
|
-
if (!Object.hasOwn(mcpSpecs, name) || !isObject(registration) || !validRegistration(registration))
|
|
41
|
-
return name;
|
|
42
|
-
if (name === 'context7')
|
|
43
|
-
return (registration.type === 'http' || registration.type === 'streamable-http') &&
|
|
44
|
-
registration.url === mcpSpecs.context7.registration.url
|
|
45
|
-
? knownTitle('mcp:context7')
|
|
46
|
-
: name;
|
|
47
|
-
if (name === 'serena')
|
|
48
|
-
return (registration.type === undefined || registration.type === 'stdio') &&
|
|
49
|
-
typeof registration.command === 'string' &&
|
|
50
|
-
isSerenaCommand(registration.command) &&
|
|
51
|
-
Array.isArray(registration.args) &&
|
|
52
|
-
registration.args[0] === mcpSpecs.serena.registration.args[0]
|
|
53
|
-
? knownTitle('mcp:serena')
|
|
54
|
-
: name;
|
|
55
|
-
return name;
|
|
56
|
-
}
|
|
57
|
-
/** 创建 MCP 域渠道:检查数组归一为聚合,余段即注册名;裸函数仍供跨域调用 */
|
|
58
|
-
export function createMcpDomain(ctx) {
|
|
59
|
-
return {
|
|
60
|
-
async inspect() {
|
|
61
|
-
return { items: await inspectMcp(ctx), problems: [] };
|
|
62
|
-
},
|
|
63
|
-
prepare(selection, describe) {
|
|
64
|
-
const name = restOf(selection.id);
|
|
65
|
-
if (name === undefined)
|
|
66
|
-
throw new Error('unknown-selection');
|
|
67
|
-
return prepareMcp(ctx, name, selection, describe ? { describe } : {});
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 判定退役 AMIRC 许可证据
|
|
73
|
-
*
|
|
74
|
-
* @returns 读取失败时返回 unknown,不以 absent 代替
|
|
75
|
-
*/
|
|
76
|
-
async function readLegacyAmircPermissionEvidence(ctx) {
|
|
77
|
-
try {
|
|
78
|
-
return (await hasLegacyAmircPermissions(ctx)) ? { kind: 'present' } : { kind: 'absent' };
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return { kind: 'unknown', problem: errorCode(error) };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async function inspectMcp(ctx) {
|
|
85
|
-
// 注册文件不可读时方案入口降级可见(带问题、无资格),与插件族同形,不整族消失
|
|
86
|
-
let registrations = {};
|
|
87
|
-
let readProblem;
|
|
88
|
-
try {
|
|
89
|
-
registrations = await readMcpServers(ctx);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
readProblem = errorCode(error);
|
|
93
|
-
}
|
|
94
|
-
const result = [];
|
|
95
|
-
const legacyAmircPermissionEvidence = await readLegacyAmircPermissionEvidence(ctx);
|
|
96
|
-
for (const name of new Set([
|
|
97
|
-
...Object.keys(mcpSpecs),
|
|
98
|
-
...Object.keys(registrations),
|
|
99
|
-
...(legacyAmircPermissionEvidence.kind !== 'absent' ? ['amirc'] : []),
|
|
100
|
-
])) {
|
|
101
|
-
const isRegistered = registrations[name] !== undefined;
|
|
102
|
-
const isOffered = Object.hasOwn(mcpSpecs, name);
|
|
103
|
-
const hasAmircPermissions = name === 'amirc' && legacyAmircPermissionEvidence.kind === 'present';
|
|
104
|
-
let problem = name === 'amirc' && legacyAmircPermissionEvidence.kind === 'unknown'
|
|
105
|
-
? legacyAmircPermissionEvidence.problem
|
|
106
|
-
: undefined;
|
|
107
|
-
if (isRegistered && !validRegistration(registrations[name]))
|
|
108
|
-
problem = 'invalid-mcp-registration';
|
|
109
|
-
const itemProblem = problem ?? readProblem;
|
|
110
|
-
// 许可证据未知时 AMIRC 不因注册在档获得解除资格,其余条目不受此证据影响
|
|
111
|
-
const canDetach = readProblem === undefined &&
|
|
112
|
-
(name !== 'amirc' || legacyAmircPermissionEvidence.kind !== 'unknown') &&
|
|
113
|
-
(isRegistered || hasAmircPermissions);
|
|
114
|
-
result.push({
|
|
115
|
-
id: `mcp:${name}`,
|
|
116
|
-
title: confirmedMcpTitle(name, registrations[name]),
|
|
117
|
-
kind: 'mcp',
|
|
118
|
-
canInstall: isOffered && readProblem === undefined,
|
|
119
|
-
location: ctx.stateFile,
|
|
120
|
-
facts: [
|
|
121
|
-
...(readProblem === undefined ? [{ code: isRegistered ? 'registration-exists' : 'not-registered' }] : []),
|
|
122
|
-
...(hasAmircPermissions ? [{ code: 'amirc-permissions-present' }] : []),
|
|
123
|
-
],
|
|
124
|
-
...(itemProblem !== undefined ? { problem: itemProblem } : {}),
|
|
125
|
-
actions: [
|
|
126
|
-
...(isOffered && readProblem === undefined
|
|
127
|
-
? isRegistered
|
|
128
|
-
? ['connect', ...(name === 'serena' ? ['update'] : []), 'reinstall']
|
|
129
|
-
: ['install']
|
|
130
|
-
: []),
|
|
131
|
-
...(canDetach ? ['detach'] : []),
|
|
132
|
-
],
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
export async function prepareMcp(ctx, name, selection, options = {}) {
|
|
138
|
-
const { registration: customRegistration, hasDetached = false, describe } = options;
|
|
139
|
-
if (name === 'amirc' && selection.action === 'detach')
|
|
140
|
-
return prepareLegacyAmircDetach(ctx);
|
|
141
|
-
if (name === 'amirc')
|
|
142
|
-
throw new Error('action-unavailable');
|
|
143
|
-
const registrationsNow = () => readMcpServers(ctx);
|
|
144
|
-
const before = await registrationsNow();
|
|
145
|
-
describe?.(confirmedMcpTitle(name, before[name]));
|
|
146
|
-
const action = selection.action;
|
|
147
|
-
if (!['install', 'connect', 'update', 'reinstall', 'detach'].includes(action) ||
|
|
148
|
-
(action === 'update' && name !== 'serena'))
|
|
149
|
-
throw new Error('action-unavailable');
|
|
150
|
-
if (action === 'detach' && before[name] === undefined)
|
|
151
|
-
throw new Error('no-connection');
|
|
152
|
-
if (action === 'detach')
|
|
153
|
-
return removeFields(ctx, ctx.stateFile, { [name]: before[name] }, [{ code: 'mcp-remove-registration', detail: name }, { code: 'mcp-keep-runtime' }, { code: 'mcp-auth-unchanged' }], { state: 'done', code: 'registration-removed', detail: name }, MCP_SERVERS_KEY);
|
|
154
|
-
if (!/^[\w.:-]+$/.test(name))
|
|
155
|
-
throw new Error('invalid-mcp-name');
|
|
156
|
-
if (!Object.hasOwn(mcpSpecs, name) && customRegistration === undefined)
|
|
157
|
-
throw new Error('not-in-update-catalog');
|
|
158
|
-
const value = isObject(before[name]) ? before[name] : {};
|
|
159
|
-
if (action === 'install' && validRegistration(before[name]) && Object.keys(selection.fields ?? {}).length === 0) {
|
|
160
|
-
return {
|
|
161
|
-
changes: [{ code: 'registration-kept', detail: name }],
|
|
162
|
-
async run(report) {
|
|
163
|
-
unchanged((await registrationsNow())[name], value);
|
|
164
|
-
report({ state: 'kept', code: 'registration-kept', detail: name });
|
|
165
|
-
},
|
|
166
|
-
async verify() {
|
|
167
|
-
unchanged((await registrationsNow())[name], value);
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (hasDetached)
|
|
172
|
-
before[name] = undefined;
|
|
173
|
-
if (name === 'serena' &&
|
|
174
|
-
action === 'update' &&
|
|
175
|
-
(typeof value.command !== 'string' || !isSerenaCommand(value.command)))
|
|
176
|
-
throw new Error('channel-change-required');
|
|
177
|
-
/** 注册目标解析:context7 合并既有凭据,外部产品由所属域提供,其余拉取 Serena 发布元数据 */
|
|
178
|
-
const resolveTarget = async () => {
|
|
179
|
-
if (name === 'context7')
|
|
180
|
-
return {
|
|
181
|
-
registration: {
|
|
182
|
-
...mcpSpecs.context7.registration,
|
|
183
|
-
...(selection.fields?.secret
|
|
184
|
-
? { headers: { Authorization: `Bearer ${selection.fields.secret}` } }
|
|
185
|
-
: value.headers !== undefined
|
|
186
|
-
? { headers: value.headers }
|
|
187
|
-
: {}),
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
if (customRegistration !== undefined)
|
|
191
|
-
return { registration: customRegistration() };
|
|
192
|
-
const release = JSON.parse(await ctx.machine.fetchText(mcpSpecs.serena.release.metadataUrl));
|
|
193
|
-
if (!isObject(release) || !isObject(release.info) || !isExactVersion(release.info.version))
|
|
194
|
-
throw new Error('invalid-release');
|
|
195
|
-
return {
|
|
196
|
-
registration: { command: 'serena', args: [...mcpSpecs.serena.registration.args] },
|
|
197
|
-
targetVersion: release.info.version,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
const resolved = await resolveTarget();
|
|
201
|
-
const registration = resolved.registration;
|
|
202
|
-
const targetVersion = resolved.targetVersion;
|
|
203
|
-
let isRemoved = false;
|
|
204
|
-
let isToolReady = false;
|
|
205
|
-
let isInitialized = false;
|
|
206
|
-
let isRegistrationSaved = false;
|
|
207
|
-
let toolStamp = null;
|
|
208
|
-
/** 定位 uv;缺失时经官方脚本装入用户目录,脚本即用即清 */
|
|
209
|
-
const ensureUv = async (report) => {
|
|
210
|
-
let uv = (await ctx.machine.locate('uv'))[0];
|
|
211
|
-
const localUv = userBinary(ctx, 'uv');
|
|
212
|
-
if (uv === undefined && (await ctx.machine.treeStamp(localUv)) !== null)
|
|
213
|
-
uv = localUv;
|
|
214
|
-
if (uv !== undefined)
|
|
215
|
-
return uv;
|
|
216
|
-
const file = installScratch(ctx, `uv-${randomUUID()}.${ctx.platform === 'win32' ? 'ps1' : 'sh'}`);
|
|
217
|
-
await ctx.machine.initialize(file, await ctx.machine.fetchText(`https://astral.sh/uv/install.${ctx.platform === 'win32' ? 'ps1' : 'sh'}`));
|
|
218
|
-
try {
|
|
219
|
-
success(await ctx.machine.execute(ctx.platform === 'win32' ? 'powershell.exe' : 'sh', ctx.platform === 'win32' ? ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', file] : [file], { env: { UV_NO_MODIFY_PATH: '1', UV_INSTALL_DIR: userBinDirectory(ctx) } }));
|
|
220
|
-
}
|
|
221
|
-
finally {
|
|
222
|
-
const stamp = await ctx.machine.treeStamp(file);
|
|
223
|
-
if (stamp !== null)
|
|
224
|
-
await ctx.machine.removeTree(file, stamp);
|
|
225
|
-
}
|
|
226
|
-
report({ state: 'done', code: 'uv-installed' });
|
|
227
|
-
return localUv;
|
|
228
|
-
};
|
|
229
|
-
/** Serena 运行时链:uv 供给 → 固定版本安装 → 注册命令解析 → 首装初始化 */
|
|
230
|
-
const ensureSerenaRuntime = async (report, signal) => {
|
|
231
|
-
if (name !== 'serena')
|
|
232
|
-
return;
|
|
233
|
-
if (isToolReady && (await ctx.machine.treeStamp(String(registration.command))) !== toolStamp)
|
|
234
|
-
throw new Error('program-changed');
|
|
235
|
-
if (!isToolReady) {
|
|
236
|
-
const uv = await ensureUv(report);
|
|
237
|
-
cancelled(signal);
|
|
238
|
-
const serenaIn = (text) => text
|
|
239
|
-
.split('\n')
|
|
240
|
-
.some(line => line.trim().split(/\s+/).slice(0, 2).join(' ') === `${mcpSpecs.serena.release.package} v${targetVersion}`);
|
|
241
|
-
const currentTools = await ctx.machine.execute(uv, ['tool', 'list']);
|
|
242
|
-
const isAlreadyInstalled = !currentTools.failed && currentTools.code === 0 && serenaIn(currentTools.stdout);
|
|
243
|
-
if (!isAlreadyInstalled || action === 'reinstall')
|
|
244
|
-
success(await ctx.machine.execute(uv, [
|
|
245
|
-
'tool',
|
|
246
|
-
'install',
|
|
247
|
-
'--python',
|
|
248
|
-
mcpSpecs.serena.release.python,
|
|
249
|
-
'--upgrade',
|
|
250
|
-
...(action === 'reinstall' ? ['--reinstall'] : []),
|
|
251
|
-
`${mcpSpecs.serena.release.package}==${targetVersion}`,
|
|
252
|
-
]), 'serena-install-failed');
|
|
253
|
-
const installed = success(await ctx.machine.execute(uv, ['tool', 'list']));
|
|
254
|
-
if (!serenaIn(installed))
|
|
255
|
-
throw new Error('binary-version-mismatch');
|
|
256
|
-
const bin = success(await ctx.machine.execute(uv, ['tool', 'dir', '--bin'])).trim();
|
|
257
|
-
if (!path.isAbsolute(bin) || /[\r\n]/.test(bin))
|
|
258
|
-
throw new Error('invalid-tool-directory');
|
|
259
|
-
registration.command = path.join(bin, ctx.platform === 'win32' ? 'serena.exe' : 'serena');
|
|
260
|
-
if ((await ctx.machine.treeStamp(String(registration.command))) === null)
|
|
261
|
-
throw new Error('program-not-ready');
|
|
262
|
-
toolStamp = await ctx.machine.treeStamp(String(registration.command));
|
|
263
|
-
isToolReady = true;
|
|
264
|
-
report({ state: 'done', code: 'serena-installed' });
|
|
265
|
-
}
|
|
266
|
-
cancelled(signal);
|
|
267
|
-
if (action !== 'update' && !isInitialized) {
|
|
268
|
-
success(await ctx.machine.execute(String(registration.command), ['init']), 'serena-initialization-failed');
|
|
269
|
-
isInitialized = true;
|
|
270
|
-
report({ state: 'done', code: 'serena-initialized' });
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
const removeExistingRegistration = async (report) => {
|
|
274
|
-
await editFields(ctx, ctx.stateFile, before, { [name]: undefined }, MCP_SERVERS_KEY, () => {
|
|
275
|
-
before[name] = undefined;
|
|
276
|
-
isRemoved = true;
|
|
277
|
-
report({ state: 'done', code: 'registration-removed' });
|
|
278
|
-
});
|
|
279
|
-
};
|
|
280
|
-
const saveRegistration = async (report) => {
|
|
281
|
-
if (isRegistrationSaved) {
|
|
282
|
-
unchanged((await registrationsNow())[name], registration);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
await editFields(ctx, ctx.stateFile, before, { [name]: registration }, MCP_SERVERS_KEY, () => {
|
|
286
|
-
isRegistrationSaved = true;
|
|
287
|
-
before[name] = registration;
|
|
288
|
-
report({ state: 'done', code: 'registration-saved', detail: name });
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
return {
|
|
292
|
-
get changes() {
|
|
293
|
-
if (isRegistrationSaved)
|
|
294
|
-
return [{ code: 'mcp-registration-confirm', detail: name }];
|
|
295
|
-
return [
|
|
296
|
-
{
|
|
297
|
-
code: action === 'update' ? 'mcp-program-update' : 'mcp-register',
|
|
298
|
-
detail: `${name}${targetVersion ? ` · ${targetVersion}` : ''}`,
|
|
299
|
-
},
|
|
300
|
-
...(before[name] !== undefined && action !== 'update' ? [{ code: 'replace-existing-registration' }] : []),
|
|
301
|
-
...(name === 'serena' && !isToolReady ? [{ code: 'uv-python-dependency' }] : []),
|
|
302
|
-
...(name === 'serena' && !isInitialized && action !== 'update' ? [{ code: 'serena-initialize' }] : []),
|
|
303
|
-
...(action === 'reinstall' && !isRemoved ? [{ code: 'disconnect-before-reinstall' }] : []),
|
|
304
|
-
];
|
|
305
|
-
},
|
|
306
|
-
async run(report, signal) {
|
|
307
|
-
unchanged((await registrationsNow())[name], before[name]);
|
|
308
|
-
cancelled(signal);
|
|
309
|
-
if (action === 'reinstall' && !isRemoved)
|
|
310
|
-
await removeExistingRegistration(report);
|
|
311
|
-
await ensureSerenaRuntime(report, signal);
|
|
312
|
-
cancelled(signal);
|
|
313
|
-
if (action !== 'update')
|
|
314
|
-
await saveRegistration(report);
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
}
|