@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.
@@ -1,157 +0,0 @@
1
- import { CLEANUP_RESIDUE_CODES } from './cleanup.js';
2
- import { contentName, describeDiagnostic, failureLabel, safeText } from './render.js';
3
- const INDICATORS = {
4
- waiting: { symbol: '·', status: '等待', tone: 'muted' },
5
- running: { symbol: '▶', status: '执行中', tone: 'accent' },
6
- done: { symbol: '✔', status: '完成', tone: 'success' },
7
- partial: { symbol: '!', status: '部分完成', tone: 'danger' },
8
- failed: { symbol: '✕', status: '失败', tone: 'danger' },
9
- skipped: { symbol: '○', status: '已跳过', tone: 'warning' },
10
- cancelled: { symbol: '○', status: '已停止', tone: 'muted' },
11
- };
12
- const EFFECTS = {
13
- done: { symbol: '✔', tone: 'success', statement: '已完成' },
14
- kept: { symbol: '—', tone: 'muted', statement: '已保留' },
15
- failed: { symbol: '✕', tone: 'danger', statement: '未完成' },
16
- skipped: { symbol: '○', tone: 'warning', statement: '未执行' },
17
- };
18
- function executionState(item) {
19
- return item.state === 'failed' && item.effects.length > 0 && item.effects.every(effect => effect.state === 'skipped')
20
- ? 'skipped'
21
- : item.state;
22
- }
23
- function executionSummary(items) {
24
- const states = items.map(executionState);
25
- const count = (state) => states.filter(value => value === state).length;
26
- const processed = states.length - count('waiting') - count('running');
27
- return `处理 ${processed}/${items.length} · 完成 ${count('done')} · 失败 ${count('failed') + count('partial')} · 跳过 ${count('skipped')}${count('cancelled') ? ` · 已停止 ${count('cancelled')}` : ''}`;
28
- }
29
- function detail(effect) {
30
- const presentation = EFFECTS[effect.state];
31
- return {
32
- symbol: presentation.symbol,
33
- text: `${EFFECTS[effect.state].statement} · ${describeDiagnostic(effect)}`,
34
- tone: presentation.tone,
35
- };
36
- }
37
- function executionRows(items, shouldShowDetails = false) {
38
- return items.map(item => {
39
- const state = executionState(item);
40
- const indicator = INDICATORS[state];
41
- return {
42
- id: item.id,
43
- title: contentName(item),
44
- ...indicator,
45
- ...(state === 'failed' ? { status: failureLabel(item.action) } : {}),
46
- details: shouldShowDetails
47
- ? [
48
- { text: `标识:${safeText(item.id)}`, tone: 'muted' },
49
- ...item.effects.map(detail),
50
- {
51
- text: item.isPending === true
52
- ? '本项仍有未完成步骤'
53
- : item.isPending === false
54
- ? '本项无可续办步骤'
55
- : '本项续办状态未提供',
56
- tone: 'muted',
57
- },
58
- ]
59
- : [],
60
- };
61
- });
62
- }
63
- function activeItem(items) {
64
- return (items.find(item => item.state === 'running')?.id ?? [...items].reverse().find(item => item.state !== 'waiting')?.id);
65
- }
66
- function progressView(items) {
67
- const activeId = activeItem(items);
68
- return {
69
- phase: 'progress',
70
- title: '执行进度',
71
- summary: executionSummary(items),
72
- rows: executionRows(items),
73
- ...(activeId !== undefined ? { activeId } : {}),
74
- };
75
- }
76
- function resultTitle(result, items, action) {
77
- if (result.state === 'done' &&
78
- result.items.some(item => item.effects.some(effect => CLEANUP_RESIDUE_CODES.includes(effect.code)))) {
79
- return '清理完成(有保留)';
80
- }
81
- if (result.state === 'failed') {
82
- const actions = new Set(items.map(item => item.action));
83
- return failureLabel(action ?? (actions.size === 1 ? items[0]?.action : undefined));
84
- }
85
- return INDICATORS[result.state].status;
86
- }
87
- function resultView(result, items, action, detailsId) {
88
- return {
89
- phase: 'result',
90
- title: detailsId === undefined ? `运行结果 · ${resultTitle(result, items, action)}` : '结果详情',
91
- summary: detailsId === undefined
92
- ? executionSummary(items)
93
- : result.remaining
94
- ? '本次仍有可续办任务'
95
- : '本次没有可续办任务',
96
- rows: executionRows(detailsId === undefined ? items : items.filter(item => item.id === detailsId), detailsId !== undefined),
97
- };
98
- }
99
- /** 统一投影冻结计划的进度与结果;名称由计划条目携带 */
100
- export function createRunPresentation(plan, action) {
101
- const execution = new Map(plan.items.map(item => [
102
- item.id,
103
- { id: item.id, title: item.title, action: item.action, state: 'waiting', effects: [] },
104
- ]));
105
- const items = () => [...execution.values()];
106
- const recordResult = (result) => {
107
- for (const item of result.items) {
108
- const previous = execution.get(item.id);
109
- execution.set(item.id, {
110
- ...previous,
111
- ...item,
112
- title: previous?.title ?? item.title,
113
- });
114
- }
115
- };
116
- return {
117
- progress(event) {
118
- if (event) {
119
- const previous = execution.get(event.id);
120
- if (previous) {
121
- execution.set(event.id, event.kind === 'finished'
122
- ? { ...previous, ...event.result, title: previous.title }
123
- : event.kind === 'started'
124
- ? { ...previous, state: 'running' }
125
- : { ...previous, effects: [...previous.effects, event.effect] });
126
- }
127
- }
128
- return progressView(items());
129
- },
130
- result(result) {
131
- recordResult(result);
132
- return resultView(result, items(), action);
133
- },
134
- details(result, id) {
135
- recordResult(result);
136
- return resultView(result, items(), action, id);
137
- },
138
- };
139
- }
140
- /** 状态行文本形状:交互窄屏回退与非交互输出共用 */
141
- export const statusLine = (row) => `${row.symbol} ${row.status} ${row.title}`;
142
- export function describeRun(view) {
143
- return [
144
- view.title,
145
- view.summary,
146
- ...view.rows.flatMap(row => [
147
- statusLine(row),
148
- ...row.details.map(value => ` ${value.symbol ? `${value.symbol} ` : ''}${value.text}`),
149
- ]),
150
- ]
151
- .filter(Boolean)
152
- .join('\n');
153
- }
154
- export function describeResult(result) {
155
- const items = result.items.map(item => ({ ...item }));
156
- return describeRun(resultView(result, items));
157
- }
package/dist/storage.js DELETED
@@ -1,44 +0,0 @@
1
- import path from 'node:path';
2
- import { json } from './model.js';
3
- /** CCW 自有存储(~/.ccw)的文件与目录名单一出处:写入侧(各域)与读取侧(诊断收集)都经此取路径 */
4
- export const sourcesFile = (ctx) => path.join(ctx.storage, 'sources.json');
5
- export const lastRunFile = (ctx) => path.join(ctx.storage, 'last-run.json');
6
- export const replacedDirectory = (ctx) => path.join(ctx.storage, 'replaced');
7
- export const disabledDirectory = (ctx) => path.join(ctx.storage, 'disabled');
8
- export const logsDirectory = (ctx) => path.join(ctx.storage, 'logs');
9
- /** 安装类临时产物(install-claude-*、install-uv-*)在存储根下的共用名称前缀 */
10
- export const INSTALL_SCRATCH_PREFIX = 'install-';
11
- export const installScratch = (ctx, name) => path.join(ctx.storage, `${INSTALL_SCRATCH_PREFIX}${name}`);
12
- /** apply 后尽力落盘最近执行摘要:写入失败静默吞掉,不抛给调用方、不影响执行结果 */
13
- export async function writeLastRun(ctx, plan, result, remaining) {
14
- try {
15
- await ctx.machine.editJson(lastRunFile(ctx), values => {
16
- values.schema = 1;
17
- values.planId = plan.id;
18
- values.finishedAt = new Date().toISOString();
19
- values.state = result.state;
20
- values.items = plan.items.map((item, index) => ({
21
- id: item.id,
22
- title: item.title,
23
- action: item.action,
24
- state: result.items[index]?.state ?? null,
25
- effects: (result.items[index]?.effects ?? []).map(effect => ({
26
- state: effect.state,
27
- code: effect.code,
28
- ...(effect.detail ? { detail: effect.detail } : {}),
29
- })),
30
- }));
31
- if (remaining !== undefined)
32
- values.remaining = remaining;
33
- else
34
- delete values.remaining;
35
- });
36
- }
37
- catch {
38
- return;
39
- }
40
- }
41
- /** 读取最近执行记录:文件缺失得空对象(无历史),损坏或不可读抛错由调用方保留未知 */
42
- export function readLastRun(ctx) {
43
- return json(ctx.machine, lastRunFile(ctx));
44
- }
package/dist/titles.js DELETED
@@ -1,46 +0,0 @@
1
- import { bundledSkills, mcpSpecs, pluginSpecs, skillMembers, skillSuites } from './management-catalog.js';
2
- import { CLAUDE_DATA_ID } from './model.js';
3
- /** 定义清理类别的键序与标题 */
4
- const DATA_CATEGORY_TABLE = [
5
- ['cache', '缓存与诊断日志'],
6
- ['history', '会话与历史'],
7
- ['memory', '自动记忆'],
8
- ['backups', '恢复备份'],
9
- ['runtime', '后台任务与运行状态'],
10
- ];
11
- export const DATA_CATEGORY_KEYS = DATA_CATEGORY_TABLE.map(([key]) => key);
12
- /** 目录表标题扁平为 <prefix>:<name> 键的标题表 */
13
- const prefixedTitles = (prefix, specs) => Object.fromEntries(Object.entries(specs).map(([name, spec]) => [`${prefix}:${name}`, spec.title]));
14
- /** 映射已知键到官方标题;显示标题不证明身份或授予操作资格 */
15
- const KNOWN_TITLES = {
16
- claude: 'Claude Code',
17
- settings: '模型配置',
18
- ccline: 'CCometixLine',
19
- officecli: 'OfficeCLI',
20
- [CLAUDE_DATA_ID]: 'Claude 用户数据',
21
- ...Object.fromEntries(DATA_CATEGORY_TABLE.map(([key, title]) => [`data:${key}`, title])),
22
- plan: '操作计划',
23
- ...prefixedTitles('plugin', pluginSpecs),
24
- ...prefixedTitles('mcp', mcpSpecs),
25
- ...prefixedTitles('skill-set', skillSuites),
26
- ...prefixedTitles('skill', { ...skillMembers, ...bundledSkills }),
27
- };
28
- export function knownTitle(key, fallback = key) {
29
- return KNOWN_TITLES[key] ?? fallback;
30
- }
31
- /** 程序副本标题后缀:批内出现同工具其他副本附渠道,渠道仍相同再附路径;
32
- * 展示层不得反解 id 推断渠道;检查列表与计划标题共用 */
33
- export function programCopySuffix(id, batch) {
34
- const segments = id.split(':');
35
- const [kind, channel] = segments;
36
- if (segments.length < 3 || kind === undefined || channel === undefined)
37
- return '';
38
- const sameToolCopy = (other) => {
39
- const parts = other.split(':');
40
- return other !== id && parts[0] === kind && parts.length >= 3;
41
- };
42
- if (!batch.some(sameToolCopy))
43
- return '';
44
- const hasDuplicateChannel = batch.some(other => other !== id && other.startsWith(`${kind}:${channel}:`));
45
- return ` (${channel}${hasDuplicateChannel ? ` · ${segments.slice(2).join(':')}` : ''})`;
46
- }
package/dist/warnings.js DELETED
@@ -1,6 +0,0 @@
1
- export const WARNING_MESSAGES = {
2
- 'program-identity-unchecked': { brief: '身份待确认', detail: '程序文件已找到;操作前确认身份' },
3
- 'program-inspection-warning': { brief: '检查不完整', detail: '检查其他安装不完整' },
4
- 'inspection-incomplete': { brief: '检查不完整', detail: '检查不完整' },
5
- 'new-session-required': { brief: '稍后生效', detail: '新会话或重新加载后生效' },
6
- };