@hit-sudomaker/ccw 0.4.0 → 0.5.0

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/render.js CHANGED
@@ -1,10 +1,15 @@
1
- import { knownTitle, programCopySuffix } from './titles.js';
2
- import { ERROR_MESSAGES } from './errors.js';
3
- import { WARNING_MESSAGES } from './warnings.js';
4
- import { kindOf } from './model.js';
1
+ import { createRequire } from 'node:module';
2
+ import stringWidth from 'string-width';
3
+ import { MESSAGES } from './messages.js';
4
+ import { isObject } from './machine.js';
5
+ const FIRST_PRINTABLE_ASCII_CODE = 0x20;
6
+ const ASCII_DELETE_CODE = 0x7f;
7
+ const manifest = createRequire(import.meta.url)('../package.json');
8
+ const packageVersion = isObject(manifest) && typeof manifest.version === 'string' ? manifest.version : '';
9
+ /** 从包清单取得的终端品牌与版本 */
5
10
  export const BRAND = {
6
11
  title: 'Claude Code Workpack',
7
- version: 'V0.4.0',
12
+ versionNumber: packageVersion,
8
13
  credit: 'Designed By AMIRC',
9
14
  logo: [
10
15
  ' ██████╗ ██████╗ ██╗ ██╗',
@@ -15,56 +20,32 @@ export const BRAND = {
15
20
  ' ╚═════╝ ╚═════╝ ╚══╝╚══╝',
16
21
  ],
17
22
  };
18
- export const HELP_TEXT = `CCW ${BRAND.version.slice(1)}\n无参数:打开菜单\n--inspect:检查环境\n--version:查看版本\n--help:查看帮助\n--details:显示本次启动异常详情\n安装:勾选后执行\n卸载、清理:预览后确认\n`;
19
- export const HOME_TITLE = `CCW ${BRAND.version.slice(1)} · 当前用户`;
20
- const CONTENT_ORDER = {
21
- claude: 0,
22
- settings: 1,
23
- plugin: 2,
24
- mcp: 3,
25
- skill: 4,
26
- command: 5,
27
- ccline: 6,
28
- officecli: 7,
29
- data: 8,
30
- };
31
- const GROUPS = {
32
- claude: '基础配置',
33
- settings: '基础配置',
34
- plugin: 'Plugins',
35
- mcp: 'MCPs',
36
- skill: 'Skills',
37
- command: 'Skills',
38
- ccline: '附加工具',
39
- officecli: '附加工具',
40
- data: '运行数据',
41
- };
42
- export const ACTION_NAMES = {
23
+ /** 命令行帮助正文 */
24
+ export const HELP_TEXT = `CCW ${BRAND.versionNumber}\n无参数:打开菜单\n--inspect:检查状态\n--version:查看版本\n--help:查看帮助\n--details:显示诊断代码与检查明细\n安装配置、移除程序、清理数据:选择后预览确认\n检查状态:只读查看\n`;
25
+ /** 主菜单显示标题 */
26
+ export const HOME_TITLE = 'CCW ' + BRAND.versionNumber;
27
+ /** 返回主菜单的共用选项文案 */
28
+ export const BACK_TO_HOME = '返回主菜单';
29
+ const ACTION_NAMES = {
43
30
  install: '安装',
44
- connect: '安装',
45
31
  update: '更新',
46
- reinstall: '重装',
47
- configure: '编辑',
48
- login: '登录',
32
+ configure: '配置',
49
33
  detach: '解除接入',
50
- uninstall: '卸载程序',
34
+ uninstall: '移除程序',
51
35
  clean: '清理',
52
36
  };
53
- export function planVerb(item) {
54
- if (item.id === 'data:claude')
55
- return '删除';
56
- return item.action === 'uninstall' ? '卸载' : ACTION_NAMES[item.action];
57
- }
58
- export function preparationTitle(task) {
59
- return { install: '准备安装', uninstall: '准备卸载', clean: '准备清理' }[task];
60
- }
37
+ /** 模型配置表单的字段键与显示顺序 */
61
38
  export const MODEL_FIELDS = [
62
- { key: 'model', label: 'Default Model' },
63
- { key: 'fable', label: 'Fable' },
39
+ { key: 'model', label: '默认模型' },
64
40
  { key: 'opus', label: 'Opus' },
65
41
  { key: 'sonnet', label: 'Sonnet' },
66
42
  { key: 'haiku', label: 'Haiku' },
67
43
  ];
44
+ /** 配置表单在缺少已有值时采用的偏好 */
45
+ export const DEFAULT_PREFERENCES = { language: 'Simplified Chinese', outputStyle: 'Explanatory' };
46
+ /** 模型连接、语言和风格分别编辑,计划阶段仍合并为同一配置对象 */
47
+ export const SETTINGS_EDITORS = ['connection', 'language', 'outputStyle'];
48
+ /** 语言和风格选择的显示标签与实际配置值 */
68
49
  export const SETTINGS_LANGUAGES = [
69
50
  { value: 'Simplified Chinese', label: '中文' },
70
51
  { value: 'English', label: '英文' },
@@ -76,336 +57,358 @@ export const SETTINGS_STYLES = [
76
57
  { value: 'Explanatory', label: '解释型 · Explanatory' },
77
58
  { value: 'Learning', label: '学习型 · Learning' },
78
59
  ];
79
- export const SETTINGS_FIELDS = {
80
- connection: ['mode', 'auth', 'baseUrl', 'secret', 'login', ...MODEL_FIELDS.map(field => field.key)],
81
- language: ['language'],
82
- outputStyle: ['outputStyle'],
60
+ const INDICATORS = {
61
+ waiting: { symbol: '·', status: '等待' },
62
+ running: { symbol: '▶', status: '执行中' },
63
+ done: { symbol: '✔', status: '完成' },
64
+ partial: { symbol: '!', status: '部分完成' },
65
+ failed: { symbol: '✕', status: '失败' },
66
+ skipped: { symbol: '○', status: '已跳过' },
67
+ cancelled: { symbol: '○', status: '已停止' },
68
+ };
69
+ const GROUPS = {
70
+ claude: '基础配置',
71
+ settings: '基础配置',
72
+ plugin: 'Plugins',
73
+ skill: 'Skills',
74
+ officecli: '附加工具',
75
+ ccline: '附加工具',
76
+ data: '清理数据',
83
77
  };
84
- export function contentEntries(items, shouldExpandEditors) {
85
- return items.flatMap(item => item.kind === 'settings' && shouldExpandEditors
86
- ? [
87
- { item, editor: 'connection' },
88
- { item, editor: 'language' },
89
- { item, editor: 'outputStyle' },
90
- ]
91
- : [{ item }]);
78
+ /** 按终端菜单的类别顺序返回新数组,不修改输入 */
79
+ export function contentOrder(items) {
80
+ const order = ['claude', 'settings', 'plugin', 'skill', 'officecli', 'ccline', 'data'];
81
+ return [...items].sort((left, right) => order.indexOf(left.kind) - order.indexOf(right.kind));
92
82
  }
93
- export function entrySelected(entry, drafts) {
94
- const selection = drafts.get(entry.item.id);
95
- return (selection !== undefined &&
96
- (entry.editor === undefined ||
97
- SETTINGS_FIELDS[entry.editor].some(field => Object.hasOwn(selection.fields ?? {}, field))));
83
+ /** 生成包含名称与简短状态的菜单行 */
84
+ export function contentRow(item) {
85
+ return { label: contentName(item), detail: shortStatus(item), group: GROUPS[item.kind] };
98
86
  }
99
- export function entryRows(entries, drafts) {
100
- const rows = contentRows(entries.map(entry => entry.item));
101
- return entries.map((entry, index) => {
102
- const editor = entry.editor;
103
- if (editor === undefined)
104
- return rows[index] ?? { label: '' };
105
- const fields = { ...entry.item.values, ...drafts.get(entry.item.id)?.fields };
106
- if (editor === 'connection')
107
- return {
108
- ...rows[index],
109
- label: contentName(entry.item),
110
- detail: effectiveConnection(fields, entry.item.facts) === 'api' ? '第三方 API' : '官方登录',
111
- };
112
- const choices = editor === 'language' ? SETTINGS_LANGUAGES : SETTINGS_STYLES;
113
- const value = fields[editor] ?? (editor === 'language' ? 'Simplified Chinese' : 'Explanatory');
87
+ /** 按当前值和本次草稿显示独立设置入口,不读取或写入配置 */
88
+ export function settingsRow(item, editor, fields) {
89
+ const values = { ...item.values, ...fields };
90
+ if (editor === 'connection')
114
91
  return {
115
- ...rows[index],
116
- label: editor === 'language' ? '默认输出语言' : '输出风格',
117
- detail: choices.find(choice => choice.value === value)?.label ?? value,
92
+ label: '模型配置',
93
+ group: GROUPS.settings,
94
+ detail: item.problem
95
+ ? reason(item.problem)
96
+ : effectiveConnection(values, item.facts) === 'api'
97
+ ? '第三方 API'
98
+ : '官方登录',
118
99
  };
119
- });
100
+ const choices = editor === 'language' ? SETTINGS_LANGUAGES : SETTINGS_STYLES;
101
+ const value = values[editor] ?? DEFAULT_PREFERENCES[editor];
102
+ return {
103
+ label: editor === 'language' ? '默认语言' : '输出风格',
104
+ group: GROUPS.settings,
105
+ detail: item.problem
106
+ ? reason(item.problem)
107
+ : (choices.find(choice => choice.value === value)?.label ?? safeText(value)),
108
+ };
109
+ }
110
+ /**
111
+ * 汇总检查条目和检查问题的显示文本
112
+ *
113
+ * @param details - 为 true 时附带事实诊断代码;输入详情必须已脱敏
114
+ */
115
+ export function describeInspection(view, details = false) {
116
+ const lines = [];
117
+ const groups = new Map();
118
+ for (const item of contentOrder(view.items)) {
119
+ if (!details &&
120
+ item.id.startsWith('skill-set:') &&
121
+ !item.problem &&
122
+ item.facts.some(fact => fact.code === 'skill-members-present'))
123
+ continue;
124
+ if (!details && item.launcherFor && view.items.some(parent => parent.id === item.launcherFor))
125
+ continue;
126
+ const group = GROUPS[item.kind];
127
+ groups.set(group, [...(groups.get(group) ?? []), item]);
128
+ }
129
+ for (const [group, items] of groups) {
130
+ lines.push((lines.length ? '\n' : '') + '── ' + group);
131
+ const nameWidth = Math.max(...items.map(item => stringWidth(contentName(item))));
132
+ const commonPath = !details && items.every(item => item.kind === 'plugin' && item.location === items[0]?.location)
133
+ ? items[0]?.location
134
+ : undefined;
135
+ if (commonPath)
136
+ lines.push(' 路径:' + safeText(commonPath));
137
+ for (const item of items)
138
+ lines.push(describeItem(item, nameWidth, details, commonPath));
139
+ }
140
+ if (!view.items.length)
141
+ lines.push('未发现可展示的项目');
142
+ if (view.problems.length)
143
+ lines.push('\n── 检查未完成', ...view.problems.map(change => describeChange(change, details)));
144
+ return lines.join('\n');
120
145
  }
146
+ /** 优先采用表单中的显式连接模式,否则从已有配置事实推断初始选项 */
121
147
  export function effectiveConnection(values, facts) {
122
148
  return values.mode === 'api' || (values.mode !== 'official' && facts.some(fact => fact.code === 'api-configured'))
123
149
  ? 'api'
124
150
  : 'official';
125
151
  }
126
- export function contentOrder(items) {
127
- return [...items].sort((a, b) => CONTENT_ORDER[a.kind] - CONTENT_ORDER[b.kind]);
152
+ /** 生成当前准备对象的进度文案 */
153
+ export function describePreparation(event) {
154
+ return '准备:' + contentName(event);
155
+ }
156
+ /** 按产品类别展示计划,详细模式展开执行步骤 */
157
+ export function describePlan(plan, details = false) {
158
+ const counts = new Map();
159
+ for (const item of plan.items) {
160
+ const action = item.problem ? '不可执行' : planVerb(item);
161
+ counts.set(action, (counts.get(action) ?? 0) + 1);
162
+ }
163
+ const lines = [
164
+ '共 ' + plan.items.length + ' 项' + [...counts].map(([label, count]) => ` · ${label} ${count}`).join(''),
165
+ ];
166
+ const groups = new Map();
167
+ for (const item of plan.items) {
168
+ const kind = item.id.split(':')[0];
169
+ const group = kind === 'skill-set' ? GROUPS.skill : (Object.entries(GROUPS).find(([key]) => key === kind)?.[1] ?? '其他');
170
+ groups.set(group, [...(groups.get(group) ?? []), item]);
171
+ }
172
+ const actionWidth = Math.max(0, ...plan.items.map(item => stringWidth(planVerb(item))));
173
+ const nameWidth = Math.max(0, ...plan.items.map(item => stringWidth(contentName(item))));
174
+ for (const [group, items] of groups) {
175
+ lines.push('', '── ' + group);
176
+ const settingsPaths = new Set();
177
+ const dataPaths = new Set();
178
+ for (const item of items) {
179
+ const action = planVerb(item);
180
+ const name = contentName(item).replaceAll('\n', ' ');
181
+ const version = item.id === 'claude'
182
+ ? item.changes.find(change => ['program-install', 'program-update'].includes(change.code))?.detail
183
+ : undefined;
184
+ const suffix = item.problem
185
+ ? '无法执行:' + reason(item.problem)
186
+ : version && /^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/.test(version)
187
+ ? version
188
+ : '';
189
+ lines.push(' ' +
190
+ action +
191
+ ' '.repeat(actionWidth - stringWidth(action) + 2) +
192
+ name +
193
+ (suffix ? ' '.repeat(nameWidth - stringWidth(name) + 2) + suffix : ''));
194
+ if (details) {
195
+ if (item.problem)
196
+ lines.push(' ' + describeChange({ code: item.problem }, true).replaceAll('\n', '\n '));
197
+ else
198
+ for (const change of item.changes)
199
+ lines.push(' ' + describeChange(change, true).replaceAll('\n', '\n '));
200
+ }
201
+ else if (!item.problem) {
202
+ for (const change of item.changes) {
203
+ if (change.code === 'settings-edit' && change.detail)
204
+ settingsPaths.add(change.detail);
205
+ if (change.code === 'skills-refresh')
206
+ lines.push(' 清理此来源的旧技能并重新安装');
207
+ if (change.code === 'login-browser')
208
+ lines.push(' 打开浏览器完成登录');
209
+ if (change.code === 'data-delete')
210
+ lines.push(' ' + describeChange(change));
211
+ if (change.code === 'data-links-kept')
212
+ lines.push(' ' + describeChange(change));
213
+ if (change.code === 'data-root' && change.detail)
214
+ dataPaths.add(change.detail);
215
+ }
216
+ }
217
+ }
218
+ if (!details) {
219
+ for (const directory of dataPaths)
220
+ lines.push(' 清理目录:' + safeText(directory));
221
+ if (items.some(item => item.changes.some(change => change.code === 'data-permanent')))
222
+ lines.push(' 永久删除所选数据,保留程序、配置与凭据');
223
+ for (const file of settingsPaths)
224
+ lines.push(' 配置文件:' + safeText(file));
225
+ if (items.some(item => !item.problem && item.changes.some(change => change.code === 'new-session-required')))
226
+ lines.push(' 新会话或重新加载后生效');
227
+ if (items.some(item => item.action === 'uninstall' && item.changes.some(change => change.code === 'keep-user-data')))
228
+ lines.push(' 保留会话记录和个人文件');
229
+ }
230
+ }
231
+ if (plan.problem)
232
+ lines.push('', describeChange({ code: plan.problem }, details));
233
+ return lines.join('\n');
128
234
  }
129
- /** 技能安装目录不是观测结果;检查只展示实际发现的成员和读取问题 */
130
- export function inspectedItems(items) {
131
- return items.filter(item => kindOf(item.id) !== 'skill-set' &&
132
- !(item.kind === 'skill' && !item.problem && item.facts.some(fact => fact.code === 'not-installed')));
235
+ /**
236
+ * 将计划、进度事件和最终结果转换为执行视图
237
+ *
238
+ * @param task - 整批失败时的任务名称,省略时显示通用失败文案
239
+ * @param details - 显示原因码,不改变执行状态
240
+ * @returns 仅更新内存的视图生成器,保留计划中的条目标题
241
+ */
242
+ export function createRunPresentation(plan, task, details = false) {
243
+ const execution = new Map(plan.items.map(item => [
244
+ item.id,
245
+ { id: item.id, title: item.title, action: item.action, state: 'waiting', effects: [] },
246
+ ]));
247
+ const items = () => [...execution.values()];
248
+ const recordResult = (result) => {
249
+ for (const item of result.items) {
250
+ const previous = execution.get(item.id);
251
+ execution.set(item.id, {
252
+ ...previous,
253
+ ...item,
254
+ title: previous?.title ?? item.title,
255
+ });
256
+ }
257
+ };
258
+ return {
259
+ /** 记录已知条目的事件并返回当前视图;省略事件只读取视图 */
260
+ progress(event) {
261
+ if (event) {
262
+ const previous = execution.get(event.id);
263
+ if (previous) {
264
+ execution.set(event.id, event.kind === 'finished' || event.kind === 'checked'
265
+ ? { ...previous, ...event.result, title: previous.title }
266
+ : event.kind === 'started'
267
+ ? { ...previous, state: 'running' }
268
+ : { ...previous, effects: [...previous.effects, event.effect] });
269
+ }
270
+ }
271
+ return progressView(items(), details);
272
+ },
273
+ /** 合入最终条目结果并返回结果视图 */
274
+ result(result) {
275
+ recordResult(result);
276
+ return resultView(result, items(), details, task);
277
+ },
278
+ };
133
279
  }
134
- export function contentName(item) {
135
- return safeText(item.title);
280
+ /** 将执行视图转换为标题、汇总和状态行组成的多行文本 */
281
+ export function describeRun(view) {
282
+ return [view.title, view.summary, ...view.rows.map(statusLine)].filter(Boolean).join('\n');
283
+ }
284
+ /** 生成启动失败文案,details 决定是否附带诊断码 */
285
+ export function startupFailure(code, details) {
286
+ return 'CCW 启动失败:' + describeChange({ code }, details);
287
+ }
288
+ function describeItem(item, nameWidth, details, commonPath) {
289
+ const facts = item.facts;
290
+ const values = item.values ?? {};
291
+ const information = [];
292
+ if (item.kind === 'ccline')
293
+ information.push(['状态栏', facts.some(fact => fact.code === 'connected') ? '已配置' : '未配置']);
294
+ if (item.kind === 'settings' && !item.problem) {
295
+ for (const { key, label } of MODEL_FIELDS)
296
+ if (values[key])
297
+ information.push([label, values[key]]);
298
+ if (values.language)
299
+ information.push(['默认语言', values.language]);
300
+ if (values.outputStyle)
301
+ information.push(['输出风格', values.outputStyle]);
302
+ }
303
+ if (item.location && item.location !== commonPath)
304
+ information.push(['路径', item.location]);
305
+ const labelWidth = Math.max(0, ...information.map(([label]) => stringWidth(label)));
306
+ const name = contentName(item);
307
+ return [
308
+ name +
309
+ ' '.repeat(nameWidth - stringWidth(name)) +
310
+ ':' +
311
+ (item.problem ? describeChange({ code: item.problem }, details) : shortStatus(item)),
312
+ ...information.map(([label, value]) => ' ' + label + ' '.repeat(labelWidth - stringWidth(label)) + ':' + safeText(value)),
313
+ ...(details ? facts.map(change => ' ' + describeChange(change, true).replaceAll('\n', '\n ')) : []),
314
+ ].join('\n');
136
315
  }
137
316
  function shortStatus(item) {
317
+ if (item.problem)
318
+ return reason(item.problem);
319
+ if (item.launcherFor)
320
+ return 'npm 启动脚本';
138
321
  const has = (code) => item.facts.some(fact => fact.code === code);
139
- if (['invalid-appearance', 'appearance-migration-required', 'skill-entry-invalid', 'invalid-mcp-registration'].includes(item.problem ?? ''))
140
- return '配置异常';
141
- if (item.problem || has('inspection-incomplete'))
142
- return '待确认';
322
+ if (item.kind === 'data')
323
+ return item.facts.find(fact => fact.code === 'data-size')?.detail ?? '暂无数据';
143
324
  if (has('program-missing'))
144
325
  return '程序入口缺失';
145
- if (kindOf(item.id) === 'skill-set')
146
- return '';
147
326
  if (item.kind === 'settings')
148
- return has('api-configured') ? '已有连接字段' : '默认连接';
327
+ return has('api-configured') ? '第三方 API' : '官方连接';
149
328
  if (item.kind === 'plugin')
150
- return has('plugin-files-missing')
151
- ? '插件文件缺失'
152
- : has('plugin-installed')
153
- ? has('declared-disabled')
154
- ? '已停用'
155
- : '已安装'
156
- : has('declared-enabled')
157
- ? '残留声明'
158
- : '未安装';
159
- if (item.kind === 'mcp')
160
- return has('registration-exists') ? '已注册' : has('amirc-permissions-present') ? '残留许可' : '未安装';
161
- if (item.kind === 'data')
162
- return item.facts.find(fact => fact.code === 'data-size')?.detail ?? '无数据';
163
- if (has('shared-link') || has('entry-exists'))
164
- return '已安装';
165
- if (has('program-identity-unchecked'))
166
- return '待确认';
167
- if (['ccline', 'officecli'].includes(item.kind) && !has('program-exists') && has('connected'))
168
- return '残留配置';
169
- if (has('program-exists')) {
170
- const version = item.facts.find(fact => fact.code === 'program-version')?.detail;
171
- const status = ['ccline', 'officecli'].includes(item.kind) && !has('connected')
172
- ? '待接入'
173
- : item.kind === 'ccline' && has('appearance-missing')
174
- ? '待配置'
175
- : '已安装';
176
- return `${status}${version ? ` ${version}` : ''}`;
177
- }
178
- return '未安装';
179
- }
180
- export function contentRows(items) {
181
- return items.map(item => ({
182
- label: `${contentName(item)}${programCopySuffix(item.id, items.map(other => other.id))}`,
183
- detail: shortStatus(item),
184
- group: GROUPS[item.kind],
185
- }));
186
- }
187
- export const TEXT = {
188
- 'skill-confirm': { brief: '确认技能', detail: '确认技能文件' },
189
- 'claude-data-remove': { brief: '删除用户数据', detail: '删除 Claude 配置和数据' },
190
- 'claude-state-remove': { brief: '删除用户状态', detail: '删除 Claude 用户状态' },
191
- 'claude-data-impact': {
192
- brief: '删除范围',
193
- detail: '删除目录内全部配置、登录状态、会话、Skills 和附加工具文件;其他 Claude 副本同步失去这些数据',
194
- },
195
- 'claude-data-removed': { brief: '用户数据已删', detail: '删除 Claude 数据' },
196
- 'claude-data-cleared': { brief: '用户数据已清', detail: '清除 Claude 用户数据' },
197
- 'program-uninstall': { brief: '卸载程序', detail: '卸载程序' },
198
- 'program-removed': { brief: '程序已卸载', detail: '卸载程序' },
199
- 'program-copy-remove': { brief: '删除程序文件', detail: '删除程序文件' },
200
- 'program-copy-removed': { brief: '程序文件已删', detail: '删除程序文件' },
201
- 'program-user-path': { brief: '设置命令路径', detail: '配置用户命令路径' },
202
- 'program-file-ready': { brief: '程序文件已写', detail: '写入程序文件' },
203
- 'program-other-copies-kept': { brief: '其他副本保留', detail: '保留其他程序副本' },
204
- 'package-removed': { brief: '程序包已卸载', detail: '卸载程序包' },
205
- 'program-not-installed': { brief: '程序未安装', detail: '程序未安装' },
206
- 'program-removal-confirm': { brief: '确认程序卸载', detail: '确认程序卸载' },
207
- 'program-installation-confirm': { brief: '确认程序安装', detail: '确认程序安装' },
208
- 'program-uninstall-command-completed': { brief: '卸载命令完成', detail: '执行卸载命令;确认程序状态' },
209
- 'unrecognized-program-kept': { brief: '程序已保留', detail: '保留身份未知的程序文件' },
210
- 'office-skill-connected': { brief: '技能已接入', detail: 'OfficeCLI Skill 已添加' },
211
- 'office-mcp-connected': { brief: '服务已注册', detail: 'OfficeCLI MCP 已注册' },
212
- 'registration-kept': { brief: '注册已保留', detail: '保留 MCP 注册' },
213
- 'program-missing': { brief: '程序入口缺失', detail: '程序入口缺失;安装记录存在' },
214
- 'program-kept': { brief: '程序已保留', detail: '保留程序' },
215
- 'amirc-permissions-present': { brief: '工具许可存在', detail: 'AMIRC 工具许可存在' },
216
- 'skill-existing-kept': { brief: '技能已保留', detail: '保留技能' },
217
- 'program-exists': { brief: '程序存在', detail: '程序存在' },
218
- 'program-version': { brief: '程序版本', detail: '程序版本' },
219
- 'not-installed': { brief: '未安装', detail: '未安装' },
220
- 'not-connected': { brief: '未接入', detail: '未接入' },
221
- 'appearance-missing': { brief: '外观待配置', detail: '外观未配置' },
222
- 'program-install': { brief: '安装程序', detail: '安装程序' },
223
- 'program-install-cmd': { brief: '安装程序', detail: '经 CMD 备用安装程序' },
224
- 'program-update': { brief: '更新程序', detail: '更新程序' },
225
- 'program-reinstall': { brief: '重装程序', detail: '重装程序' },
226
- 'keep-user-data': { brief: '保留用户数据', detail: '保留用户数据' },
227
- 'program-ready': { brief: '程序已就绪', detail: '程序就绪' },
228
- 'package-command-completed': { brief: '管理命令完成', detail: '执行包管理命令' },
229
- 'plugin-installed': { brief: '插件已安装', detail: '插件已安装' },
230
- 'plugin-not-installed': { brief: '插件未安装', detail: '插件未安装' },
231
- 'declared-enabled': { brief: '已启用', detail: '已启用' },
232
- 'declared-disabled': { brief: '已停用', detail: '已停用' },
233
- 'not-declared': { brief: '未启用', detail: '未启用' },
234
- 'plugin-disable': { brief: '停用插件', detail: '停用用户插件' },
235
- 'keep-plugin-files': { brief: '保留插件文件', detail: '保留插件文件和市场' },
236
- 'plugin-disabled': { brief: '插件已停用', detail: '停用用户插件' },
237
- 'plugin-install': { brief: '安装插件', detail: '安装插件' },
238
- 'plugin-keep-data': { brief: '保留插件数据', detail: '保留插件数据' },
239
- 'plugin-delete-own-data': { brief: '可能删除数据', detail: '官方卸载可能删除插件数据' },
240
- 'plugin-credentials-removed': { brief: '可能清除认证', detail: '官方卸载可能清除插件设置和认证' },
241
- 'plugin-command-completed': { brief: '插件命令完成', detail: '执行插件命令' },
242
- 'plugin-ready': { brief: '插件已就绪', detail: '安装插件' },
243
- 'plugin-removed': { brief: '插件已卸载', detail: '卸载用户插件' },
244
- 'api-configured': {
245
- brief: '已有连接字段',
246
- detail: '当前用户文件存在所检查的 API 地址或凭据字段;尚未确认有效认证和连接',
247
- },
248
- 'official-connection': {
249
- brief: '默认连接',
250
- detail: '当前用户文件未见所检查的 API 地址或凭据字段;尚未确认会话连接和登录状态',
251
- },
252
- 'settings-edit': { brief: '修改设置', detail: '修改设置' },
253
- 'settings-disconnect': { brief: '解除模型连接', detail: '解除模型连接' },
254
- 'settings-saved': { brief: '配置已保存', detail: '保存设置' },
255
- 'login-browser': { brief: '打开官方登录', detail: '打开官方登录' },
256
- 'logged-in': { brief: '登录已确认', detail: '确认登录' },
257
- 'shared-link': { brief: '共享链接', detail: '共享内容链接' },
258
- 'entry-exists': { brief: '入口存在', detail: '读取入口存在' },
259
- 'entry-disable': { brief: '解除读取接入', detail: '移出 Claude 读取位置' },
260
- 'preserved-at': { brief: '原内容已保留', detail: '保留原内容' },
261
- 'no-recovery': { brief: '永久删除', detail: '永久删除;CCW 不提供恢复' },
262
- 'keep-link-target': { brief: '保留共享目标', detail: '保留链接目标和共享源' },
263
- 'entry-disabled': { brief: '读取接入已解', detail: '解除读取接入;保留原内容' },
264
- 'skill-install': { brief: '复制技能资源', detail: '复制技能和资源' },
265
- 'skill-installed': { brief: '技能资源已写', detail: '写入技能资源' },
266
- 'skill-source-repair': { brief: '补记技能来源', detail: '补记技能来源' },
267
- 'skill-source-recorded': { brief: '来源已记录', detail: '补记技能来源' },
268
- 'registration-exists': { brief: '注册存在', detail: '注册存在' },
269
- 'not-registered': { brief: '未注册', detail: '未注册' },
270
- 'mcp-remove-registration': { brief: '删除用户注册', detail: '删除匹配的用户注册' },
271
- 'mcp-keep-runtime': { brief: '保留服务程序', detail: '保留服务程序、共享运行时和远端服务' },
272
- 'mcp-auth-unchanged': { brief: '保留远端认证', detail: '保留远端认证' },
273
- 'registration-removed': { brief: '注册已删除', detail: '删除注册' },
274
- 'mcp-registration-confirm': { brief: '确认服务注册', detail: '确认已写入的 MCP 注册' },
275
- 'plugin-confirm': { brief: '确认插件变更', detail: '确认已执行的插件变更' },
276
- 'mcp-register': { brief: '写入服务注册', detail: '写入 MCP 注册' },
277
- 'mcp-program-update': { brief: '更新服务程序', detail: '更新 MCP 程序' },
278
- 'uv-python-dependency': { brief: '准备共享依赖', detail: '按需安装 uv 和 Python 3.13;保留供其他工具使用' },
279
- 'disconnect-before-reinstall': { brief: '先解除再重装', detail: '先解除接入,再重装并接入' },
280
- 'uv-installed': { brief: '依赖已安装', detail: '安装 uv' },
281
- 'serena-installed': { brief: '服务程序就绪', detail: '安装 Serena' },
282
- 'registration-saved': { brief: '接入已保存', detail: '保存接入' },
283
- 'data-size': { brief: '数据大小', detail: '文件数 · 逻辑大小' },
284
- 'data-delete': { brief: '删除数据', detail: '删除数据' },
285
- 'keep-settings-credentials': { brief: '保留配置凭据', detail: '保留设置、认证、扩展和未选数据' },
286
- 'data-file-removed': { brief: '文件已删除', detail: '删除文件' },
287
- 'data-remains-or-regenerated': { brief: '仍有保留项', detail: '保留未选、新增或再生文件' },
288
- 'no-data': { brief: '无选中数据', detail: '无选中数据' },
289
- disconnected: { brief: '状态栏已解除', detail: '解除 Claude 状态栏接入' },
290
- 'no-connection': { brief: '无可解除接入', detail: '无可移除的 Claude 入口或声明' },
291
- connected: { brief: '状态栏已接入', detail: 'Claude 状态栏已接入' },
292
- 'appearance-copied': { brief: '外观已复制', detail: '复制 CCW 外观配置' },
293
- 'appearance-kept': { brief: '外观已保留', detail: '保留外观配置' },
294
- 'ccline-disconnect-before-uninstall': { brief: '先解除状态栏', detail: '解除 CCometixLine 主状态栏与子状态栏' },
295
- 'ccline-companion-kept': { brief: '保留配套插件', detail: '保留配套插件与市场' },
296
- 'ccline-detach': { brief: '解除状态栏', detail: '解除 CCometixLine 接入;保留程序与外观' },
297
- 'ccline-program-kept': { brief: '程序已保留', detail: '保留 CCometixLine 程序' },
298
- 'ccline-program-update': { brief: '更新程序', detail: '更新 npm 程序' },
299
- 'ccline-program-prepare': { brief: '准备程序', detail: '准备 CCometixLine 程序(可复用同版本)' },
300
- 'ccline-reinstall-connection': { brief: '重装后恢复接入', detail: '解除旧接入;重装后恢复' },
301
- 'ccline-subagent-restore': { brief: '恢复子状态栏', detail: '恢复子代理状态栏及设置' },
302
- 'appearance-copy': { brief: '复制外观配置', detail: '复制 CCW 外观配置' },
303
- 'ccline-connect': { brief: '接入状态栏', detail: '接入 Claude 状态栏' },
304
- 'ccline-statusline-replace': { brief: '替换现有状态栏', detail: '替换现有 Claude 状态栏' },
305
- 'ccline-root-configure': { brief: '设置配置目录', detail: '设置 CCometixLine 配置目录' },
306
- 'ccline-settings-kept': { brief: '保留外观设置', detail: '保留外观与 Claude 设置' },
307
- cancelled: { brief: '已停止', detail: '停止后续操作' },
308
- 'dependency-not-ready': { brief: '已跳过', detail: '跳过操作:前置操作未完成' },
309
- 'removal-confirm': { brief: '确认入口删除', detail: '确认入口删除' },
310
- 'cleanup-link-kept': { brief: '共享目标保留', detail: '保留共享链接和目标' },
311
- 'data-clean-root': { brief: '清理位置', detail: '清理数据位置' },
312
- 'data-runtime-impact': { brief: '运行数据影响', detail: '删除后台任务、会话标记和运行状态;需退出 Claude' },
313
- 'data-empty-directories': { brief: '清理空子目录', detail: '删除空子目录;保留数据根' },
314
- 'data-file-absent': { brief: '文件已不存在', detail: '跳过删除:文件不存在' },
315
- 'data-selected-cleared': { brief: '选中数据已清', detail: '清理数据' },
316
- 'npm-install-started': { brief: '开始安装', detail: '开始 npm 安装' },
317
- 'cmd-install-started': { brief: '开始备用安装', detail: '开始 CMD 备用安装' },
318
- 'failed-install-cleaned': { brief: '安装残留已清', detail: '清理 npm 安装残留' },
319
- 'unmatched-integration-kept': { brief: '同名入口保留', detail: '保留同名入口:与程序关系未知' },
320
- 'replace-existing-registration': { brief: '替换注册设置', detail: '替换注册设置' },
321
- 'serena-initialize': { brief: '初始化服务', detail: '初始化 Serena 配置和语言服务' },
322
- 'serena-initialized': { brief: '服务已初始化', detail: '初始化 Serena' },
323
- 'github-credential-configure': { brief: '配置访问凭据', detail: '配置 GitHub 凭据;预览隐藏内容' },
324
- 'github-credential-saved': { brief: '访问凭据已存', detail: '保存 GitHub 凭据' },
325
- 'skill-current': {
326
- brief: '技能已保留',
327
- detail: '保留已有的有效技能内容,并复核准备时摘要;未确认与上游最新版是否一致',
328
- },
329
- 'amirc-permissions-remove': { brief: '删除工具许可', detail: '删除文献工具专用许可' },
330
- 'amirc-permissions-removed': { brief: '工具许可已删', detail: '删除文献工具许可' },
331
- 'plugin-files-present': { brief: '插件文件存在', detail: '插件目录存在' },
332
- 'plugin-files-missing': { brief: '插件文件缺失', detail: '插件目录缺失;安装记录存在' },
333
- 'office-connection-kept': { brief: '接入已保留', detail: '保留 OfficeCLI 接入;不添加 Skill' },
334
- 'office-local-skill-kept': { brief: '本地技能保留', detail: '保留 OfficeCLI Skill:来源未知或内容已修改' },
335
- 'plugin-reuse': { brief: '复用启用插件', detail: '复用并启用插件' },
336
- };
337
- export function safeText(text) {
338
- return Array.from(text)
339
- .filter(character => character === '\n' || (character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127))
340
- .join('');
341
- }
342
- export function reason(code) {
343
- return message(code)?.brief ?? '操作失败';
329
+ return has('plugin-installed') ? (has('declared-disabled') ? '已停用' : '已安装') : '未安装';
330
+ const version = item.kind === 'claude' ? item.facts.find(fact => fact.code === 'program-version')?.detail : undefined;
331
+ if (has('entry-exists') || has('program-exists'))
332
+ return '已安装' + (version ? ' ' + version : '') + (has('external-program-preserved') ? ' · 仅查看' : '');
333
+ return has('skill-members-present') ? '已安装' : '未安装';
344
334
  }
345
- function message(code) {
346
- return ERROR_MESSAGES[code] ?? WARNING_MESSAGES[code] ?? TEXT[code];
347
- }
348
- export function failureLabel(action) {
349
- if (action === undefined)
350
- return '操作失败';
335
+ function progressView(items, details) {
351
336
  return {
352
- install: '安装失败',
353
- connect: '安装失败',
354
- update: '更新失败',
355
- reinstall: '重装失败',
356
- configure: '配置失败',
357
- login: '登录失败',
358
- detach: '解除失败',
359
- uninstall: '卸载失败',
360
- clean: '清理失败',
361
- }[action];
337
+ title: '执行进度',
338
+ summary: executionSummary(items),
339
+ rows: executionRows(items, details),
340
+ };
362
341
  }
363
- export function startupFailure(code, shouldShowDetails) {
364
- const brief = ['unknown-argument', 'interactive-terminal-required', 'unsupported-platform'].includes(code)
365
- ? reason(code)
366
- : '启动失败';
367
- return shouldShowDetails ? `${brief}\n${describeDiagnostic({ code })}` : brief;
342
+ function resultView(result, items, details, task) {
343
+ return {
344
+ title: '运行结果 · ' + (result.state === 'failed' ? failureLabel(task) : INDICATORS[result.state].status),
345
+ summary: executionSummary(items),
346
+ rows: executionRows(items, details),
347
+ };
368
348
  }
369
- export function describePreparation(event, task = 'install') {
370
- const inspect = { install: '检查安装', uninstall: '检查卸载', clean: '检查清理' }[task];
371
- const actions = { inspect, metadata: '查询来源', download: '下载程序', source: '获取技能' };
372
- return `${actions[event.stage]}:${contentName(event)}`;
349
+ function executionSummary(items) {
350
+ const states = items.map(item => item.state);
351
+ const count = (state) => states.filter(value => value === state).length;
352
+ const processed = states.length - count('waiting') - count('running');
353
+ return `处理 ${processed}/${items.length} · 完成 ${count('done')} · 失败 ${count('failed') + count('partial')} · 跳过 ${count('skipped')}${count('cancelled') ? ` · 已停止 ${count('cancelled')}` : ''}`;
373
354
  }
374
- /** detail 一律原文:注册键、配置键、成员名与路径不在此改名 */
375
- export function describeChange(change) {
376
- return `${message(change.code)?.detail ?? '操作失败:原因未知'}${change.detail ? `:${safeText(change.detail)}` : ''}`;
355
+ function executionRows(items, details) {
356
+ const titleWidth = Math.max(0, ...items.map(item => stringWidth(contentName(item))));
357
+ return items.map(item => {
358
+ const state = item.state;
359
+ const indicator = INDICATORS[state];
360
+ const problem = ['failed', 'partial', 'skipped'].includes(state)
361
+ ? ([...item.effects].reverse().find(effect => effect.state === 'failed') ??
362
+ item.effects.find(effect => effect.state === 'skipped'))
363
+ : undefined;
364
+ const status = state === 'failed' ? failureLabel(item.action) : indicator.status;
365
+ const notice = item.effects.find(effect => effect.state === 'kept' && effect.code === 'source-metadata-unavailable');
366
+ return {
367
+ title: contentName(item),
368
+ titleWidth,
369
+ ...indicator,
370
+ status: problem ? `${status}:${describeChange({ code: problem.code }, details)}` : status,
371
+ ...(notice ? { notice: describeChange({ code: notice.code }, details) } : {}),
372
+ };
373
+ });
377
374
  }
378
- export function describeDiagnostic(change) {
375
+ /** 交互执行视图与纯文本输出共用的状态行格式 */
376
+ export const statusLine = (row) => `${row.symbol} ${safeText(row.title).replaceAll('\n', ' ')}${' '.repeat(Math.max(0, (row.titleWidth ?? stringWidth(row.title)) - stringWidth(row.title)) + 2)}${row.status.replaceAll('\n', '\n ')}` +
377
+ (row.notice ? '\n 提示:' + row.notice.replaceAll('\n', '\n ') : '');
378
+ /**
379
+ * 拼接变更说明与可选详情
380
+ *
381
+ * @param change - 详情必须已适合公开显示,不得携带凭据
382
+ * @param details - 为 true 时附带原因码;非法原因码使用通用失败码
383
+ */
384
+ export function describeChange(change, details = false) {
379
385
  const code = /^[a-zA-Z][a-zA-Z0-9-]{0,79}$/.test(change.code) ? change.code : 'operation-failed';
380
- return `${describeChange({ ...change, code })}\n代码:${code}`;
386
+ const text = reason(code) + (change.detail ? ':' + safeText(change.detail) : '');
387
+ return text + (details ? '\n代码:' + code : '');
381
388
  }
382
- export function describeItem(item, shouldShowDetails = false) {
383
- const body = shouldShowDetails
384
- ? [
385
- `标识:${safeText(item.id)}`,
386
- ...item.facts.map(describeDiagnostic),
387
- ...(item.problem ? [`! ${describeDiagnostic({ code: item.problem })}`] : []),
388
- ]
389
- : [shortStatus(item)];
390
- return `${contentName(item)}\n${body.filter(Boolean).join('\n')}${item.location ? `\n位置:${safeText(item.location)}` : ''}`;
389
+ /** 清理条目标题中的显示控制字符 */
390
+ function contentName(item) {
391
+ return safeText(item.title);
391
392
  }
392
- export function describeInspection(view) {
393
- return [
394
- ...inspectedItems(view.items).map(item => describeItem(item, true)),
395
- ...view.problems.map(problem => `! ${describeInspectionProblem(problem)}`),
396
- ].join('\n');
393
+ /** 返回计划动作的中文名称 */
394
+ function planVerb(item) {
395
+ return ACTION_NAMES[item.action];
397
396
  }
398
- /** 检查问题按读取来源归组:集合名映射到列表分组,其余来源用已知标题表 */
399
- const PROBLEM_KINDS = {
400
- plugins: 'plugin',
401
- mcp: 'mcp',
402
- skills: 'skill',
403
- data: 'data',
404
- };
405
- export function describeInspectionProblem(problem) {
406
- const kind = PROBLEM_KINDS[problem.detail ?? ''];
407
- return describeDiagnostic({
408
- ...problem,
409
- ...(problem.detail ? { detail: kind !== undefined ? GROUPS[kind] : knownTitle(problem.detail) } : {}),
410
- });
397
+ function failureLabel(action) {
398
+ return action ? ACTION_NAMES[action] + '失败' : '操作失败';
399
+ }
400
+ /** 将原因码映射为中文说明,未知码返回统一兜底文案 */
401
+ export function reason(code) {
402
+ return (Object.hasOwn(MESSAGES, code) ? MESSAGES[code] : undefined) ?? '原因未知';
403
+ }
404
+ /**
405
+ * 移除换行以外的 ASCII 控制字符
406
+ *
407
+ * @remarks 仅清理显示控制字符,不承担凭据脱敏
408
+ */
409
+ export function safeText(text) {
410
+ return Array.from(text)
411
+ .filter(character => character === '\n' ||
412
+ (character.charCodeAt(0) >= FIRST_PRINTABLE_ASCII_CODE && character.charCodeAt(0) !== ASCII_DELETE_CODE))
413
+ .join('');
411
414
  }