clawt 2.9.1 → 2.10.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.
Files changed (48) hide show
  1. package/.claude/agent-memory/docs-sync-updater/MEMORY.md +14 -10
  2. package/.claude/agents/docs-sync-updater.md +11 -0
  3. package/README.md +63 -268
  4. package/dist/index.js +420 -103
  5. package/dist/postinstall.js +242 -0
  6. package/docs/spec.md +162 -14
  7. package/package.json +1 -1
  8. package/src/commands/remove.ts +21 -28
  9. package/src/commands/status.ts +327 -0
  10. package/src/constants/index.ts +1 -1
  11. package/src/constants/messages/common.ts +41 -0
  12. package/src/constants/messages/config.ts +5 -0
  13. package/src/constants/messages/create.ts +5 -0
  14. package/src/constants/messages/index.ts +29 -0
  15. package/src/constants/messages/merge.ts +42 -0
  16. package/src/constants/messages/remove.ts +15 -0
  17. package/src/constants/messages/reset.ts +7 -0
  18. package/src/constants/messages/resume.ts +12 -0
  19. package/src/constants/messages/run.ts +16 -0
  20. package/src/constants/messages/status.ts +25 -0
  21. package/src/constants/messages/sync.ts +24 -0
  22. package/src/constants/messages/validate.ts +25 -0
  23. package/src/constants/messages.ts +22 -0
  24. package/src/index.ts +2 -0
  25. package/src/types/command.ts +6 -0
  26. package/src/types/index.ts +2 -1
  27. package/src/types/status.ts +49 -0
  28. package/src/utils/git.ts +16 -0
  29. package/src/utils/index.ts +4 -3
  30. package/src/utils/validate-snapshot.ts +17 -0
  31. package/src/utils/worktree-matcher.ts +92 -0
  32. package/tests/unit/commands/config.test.ts +110 -0
  33. package/tests/unit/commands/create.test.ts +115 -0
  34. package/tests/unit/commands/list.test.ts +118 -0
  35. package/tests/unit/commands/merge.test.ts +323 -0
  36. package/tests/unit/commands/remove.test.ts +240 -0
  37. package/tests/unit/commands/reset.test.ts +124 -0
  38. package/tests/unit/commands/resume.test.ts +91 -0
  39. package/tests/unit/commands/run.test.ts +207 -0
  40. package/tests/unit/commands/status.test.ts +214 -0
  41. package/tests/unit/commands/sync.test.ts +208 -0
  42. package/tests/unit/commands/validate.test.ts +382 -0
  43. package/tests/unit/constants/messages.test.ts +1 -1
  44. package/tests/unit/utils/config.test.ts +21 -1
  45. package/tests/unit/utils/formatter.test.ts +44 -1
  46. package/tests/unit/utils/git.test.ts +44 -0
  47. package/tests/unit/utils/validate-snapshot.test.ts +25 -0
  48. package/tests/unit/utils/worktree-matcher.test.ts +81 -5
@@ -0,0 +1,327 @@
1
+ import type { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { MESSAGES } from '../constants/index.js';
4
+ import { logger } from '../logger/index.js';
5
+ import type { StatusOptions, WorktreeDetailedStatus, MainWorktreeStatus, SnapshotInfo, StatusResult, WorktreeInfo } from '../types/index.js';
6
+ import {
7
+ validateMainWorktree,
8
+ getProjectName,
9
+ getCurrentBranch,
10
+ isWorkingDirClean,
11
+ getProjectWorktrees,
12
+ getCommitCountAhead,
13
+ getCommitCountBehind,
14
+ getDiffStat,
15
+ hasMergeConflict,
16
+ hasLocalCommits,
17
+ hasSnapshot,
18
+ getProjectSnapshotBranches,
19
+ printInfo,
20
+ printDoubleSeparator,
21
+ printSeparator,
22
+ } from '../utils/index.js';
23
+
24
+ /**
25
+ * 注册 status 命令:显示项目全局状态总览
26
+ * @param {Command} program - Commander 实例
27
+ */
28
+ export function registerStatusCommand(program: Command): void {
29
+ program
30
+ .command('status')
31
+ .description('显示项目全局状态总览')
32
+ .option('--json', '以 JSON 格式输出')
33
+ .action((options: StatusOptions) => {
34
+ handleStatus(options);
35
+ });
36
+ }
37
+
38
+ /**
39
+ * 执行 status 命令的核心逻辑
40
+ * @param {StatusOptions} options - 命令选项
41
+ */
42
+ function handleStatus(options: StatusOptions): void {
43
+ validateMainWorktree();
44
+
45
+ const statusResult = collectStatus();
46
+
47
+ logger.info(`status 命令执行,项目: ${statusResult.main.projectName},共 ${statusResult.totalWorktrees} 个 worktree`);
48
+
49
+ if (options.json) {
50
+ printStatusAsJson(statusResult);
51
+ return;
52
+ }
53
+
54
+ printStatusAsText(statusResult);
55
+ }
56
+
57
+ /**
58
+ * 收集项目全局状态信息
59
+ * @returns {StatusResult} 完整的状态数据
60
+ */
61
+ function collectStatus(): StatusResult {
62
+ const projectName = getProjectName();
63
+ const currentBranch = getCurrentBranch();
64
+ const isClean = isWorkingDirClean();
65
+
66
+ // 主 worktree 状态
67
+ const main: MainWorktreeStatus = {
68
+ branch: currentBranch,
69
+ isClean,
70
+ projectName,
71
+ };
72
+
73
+ // 各 worktree 详细状态
74
+ const worktrees = getProjectWorktrees();
75
+ const worktreeStatuses = worktrees.map((wt) => collectWorktreeDetailedStatus(wt, projectName));
76
+
77
+ // 未清理的 validate 快照
78
+ const snapshots = collectSnapshots(projectName, worktrees);
79
+
80
+ return {
81
+ main,
82
+ worktrees: worktreeStatuses,
83
+ snapshots,
84
+ totalWorktrees: worktrees.length,
85
+ };
86
+ }
87
+
88
+ /**
89
+ * 收集单个 worktree 的详细状态
90
+ * 变更状态判断优先级:冲突 > 未提交 > 已提交 > 干净
91
+ * @param {WorktreeInfo} worktree - worktree 信息
92
+ * @param {string} projectName - 项目名
93
+ * @returns {WorktreeDetailedStatus} 详细状态
94
+ */
95
+ function collectWorktreeDetailedStatus(worktree: WorktreeInfo, projectName: string): WorktreeDetailedStatus {
96
+ const changeStatus = detectChangeStatus(worktree);
97
+ const { commitsAhead, commitsBehind } = countCommitDivergence(worktree.branch);
98
+ const { insertions, deletions } = countDiffStat(worktree.path);
99
+
100
+ return {
101
+ path: worktree.path,
102
+ branch: worktree.branch,
103
+ changeStatus,
104
+ commitsAhead,
105
+ commitsBehind,
106
+ hasSnapshot: hasSnapshot(projectName, worktree.branch),
107
+ insertions,
108
+ deletions,
109
+ };
110
+ }
111
+
112
+ /**
113
+ * 检测 worktree 的变更状态
114
+ * 优先级:冲突 > 未提交 > 已提交 > 干净
115
+ * @param {WorktreeInfo} worktree - worktree 信息
116
+ * @returns {WorktreeDetailedStatus['changeStatus']} 变更状态
117
+ */
118
+ function detectChangeStatus(worktree: WorktreeInfo): WorktreeDetailedStatus['changeStatus'] {
119
+ try {
120
+ if (hasMergeConflict(worktree.path)) {
121
+ return 'conflict';
122
+ }
123
+ if (!isWorkingDirClean(worktree.path)) {
124
+ return 'uncommitted';
125
+ }
126
+ if (hasLocalCommits(worktree.branch)) {
127
+ return 'committed';
128
+ }
129
+ return 'clean';
130
+ } catch {
131
+ return 'clean';
132
+ }
133
+ }
134
+
135
+ /**
136
+ * 统计分支与主分支的提交差异(领先/落后数)
137
+ * @param {string} branchName - 分支名
138
+ * @returns {{ commitsAhead: number; commitsBehind: number }} 领先和落后的提交数
139
+ */
140
+ function countCommitDivergence(branchName: string): { commitsAhead: number; commitsBehind: number } {
141
+ try {
142
+ return {
143
+ commitsAhead: getCommitCountAhead(branchName),
144
+ commitsBehind: getCommitCountBehind(branchName),
145
+ };
146
+ } catch {
147
+ return { commitsAhead: 0, commitsBehind: 0 };
148
+ }
149
+ }
150
+
151
+ /**
152
+ * 统计 worktree 的差异行数
153
+ * @param {string} worktreePath - worktree 路径
154
+ * @returns {{ insertions: number; deletions: number }} 新增和删除行数
155
+ */
156
+ function countDiffStat(worktreePath: string): { insertions: number; deletions: number } {
157
+ try {
158
+ return getDiffStat(worktreePath);
159
+ } catch {
160
+ return { insertions: 0, deletions: 0 };
161
+ }
162
+ }
163
+
164
+ /**
165
+ * 收集未清理的 validate 快照信息
166
+ * 对比快照分支与现有 worktree 分支,标识孤立快照
167
+ * @param {string} projectName - 项目名
168
+ * @param {WorktreeInfo[]} worktrees - 当前有效的 worktree 列表
169
+ * @returns {SnapshotInfo[]} 快照信息列表
170
+ */
171
+ function collectSnapshots(projectName: string, worktrees: WorktreeInfo[]): SnapshotInfo[] {
172
+ const snapshotBranches = getProjectSnapshotBranches(projectName);
173
+ const worktreeBranchSet = new Set(worktrees.map((wt) => wt.branch));
174
+
175
+ return snapshotBranches.map((branch) => ({
176
+ branch,
177
+ worktreeExists: worktreeBranchSet.has(branch),
178
+ }));
179
+ }
180
+
181
+ /**
182
+ * 以 JSON 格式输出状态信息
183
+ * @param {StatusResult} result - 状态数据
184
+ */
185
+ function printStatusAsJson(result: StatusResult): void {
186
+ console.log(JSON.stringify(result, null, 2));
187
+ }
188
+
189
+ /**
190
+ * 以文本格式输出状态信息
191
+ * @param {StatusResult} result - 状态数据
192
+ */
193
+ function printStatusAsText(result: StatusResult): void {
194
+ // 标题区域
195
+ printDoubleSeparator();
196
+ printInfo(` ${chalk.bold.cyan(MESSAGES.STATUS_TITLE(result.main.projectName))}`);
197
+ printDoubleSeparator();
198
+ printInfo('');
199
+
200
+ // 主 Worktree 区块
201
+ printMainSection(result.main);
202
+ printSeparator();
203
+ printInfo('');
204
+
205
+ // Worktree 列表区块
206
+ printWorktreesSection(result.worktrees, result.totalWorktrees);
207
+ printSeparator();
208
+ printInfo('');
209
+
210
+ // 未清理快照区块
211
+ printSnapshotsSection(result.snapshots);
212
+
213
+ printDoubleSeparator();
214
+ }
215
+
216
+ /**
217
+ * 输出主 Worktree 区块
218
+ * @param {MainWorktreeStatus} main - 主 worktree 状态
219
+ */
220
+ function printMainSection(main: MainWorktreeStatus): void {
221
+ printInfo(` ${chalk.bold('◆')} ${chalk.bold(MESSAGES.STATUS_MAIN_SECTION)}`);
222
+ printInfo(` 分支: ${chalk.bold(main.branch)}`);
223
+ if (main.isClean) {
224
+ printInfo(` 状态: ${chalk.green('✓ 干净')}`);
225
+ } else {
226
+ printInfo(` 状态: ${chalk.yellow('✗ 有未提交修改')}`);
227
+ }
228
+ printInfo('');
229
+ }
230
+
231
+ /**
232
+ * 输出 Worktree 列表区块
233
+ * @param {WorktreeDetailedStatus[]} worktrees - worktree 详细状态列表
234
+ * @param {number} total - worktree 总数
235
+ */
236
+ function printWorktreesSection(worktrees: WorktreeDetailedStatus[], total: number): void {
237
+ printInfo(` ${chalk.bold('◆')} ${chalk.bold(MESSAGES.STATUS_WORKTREES_SECTION)} (${total} 个)`);
238
+ printInfo('');
239
+
240
+ if (worktrees.length === 0) {
241
+ printInfo(` ${MESSAGES.STATUS_NO_WORKTREES}`);
242
+ return;
243
+ }
244
+
245
+ for (const wt of worktrees) {
246
+ printWorktreeItem(wt);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * 输出单个 worktree 状态项
252
+ * @param {WorktreeDetailedStatus} wt - worktree 详细状态
253
+ */
254
+ function printWorktreeItem(wt: WorktreeDetailedStatus): void {
255
+ // 分支名 + 变更状态标签
256
+ const statusLabel = formatChangeStatusLabel(wt.changeStatus);
257
+ printInfo(` ${chalk.bold('●')} ${chalk.bold(wt.branch)} [${statusLabel}]`);
258
+
259
+ // 差异统计行
260
+ const parts: string[] = [];
261
+
262
+ // 行数变更(仅在有变更时展示)
263
+ if (wt.insertions > 0 || wt.deletions > 0) {
264
+ parts.push(`${chalk.green(`+${wt.insertions}`)} ${chalk.red(`-${wt.deletions}`)}`);
265
+ }
266
+
267
+ // 本地提交数
268
+ if (wt.commitsAhead > 0) {
269
+ parts.push(chalk.yellow(`${wt.commitsAhead} 个本地提交`));
270
+ }
271
+
272
+ // 与主分支的同步状态
273
+ if (wt.commitsBehind > 0) {
274
+ parts.push(chalk.yellow(`落后主分支 ${wt.commitsBehind} 个提交`));
275
+ } else {
276
+ parts.push(chalk.green('与主分支同步'));
277
+ }
278
+
279
+ printInfo(` ${parts.join(' ')}`);
280
+
281
+ // 快照状态
282
+ if (wt.hasSnapshot) {
283
+ printInfo(` ${chalk.blue('有 validate 快照')}`);
284
+ }
285
+
286
+ printInfo('');
287
+ }
288
+
289
+ /**
290
+ * 将变更状态枚举格式化为带颜色的标签文本
291
+ * @param {WorktreeDetailedStatus['changeStatus']} status - 变更状态
292
+ * @returns {string} 格式化后的标签
293
+ */
294
+ function formatChangeStatusLabel(status: WorktreeDetailedStatus['changeStatus']): string {
295
+ switch (status) {
296
+ case 'committed':
297
+ return chalk.green(MESSAGES.STATUS_CHANGE_COMMITTED);
298
+ case 'uncommitted':
299
+ return chalk.yellow(MESSAGES.STATUS_CHANGE_UNCOMMITTED);
300
+ case 'conflict':
301
+ return chalk.red(MESSAGES.STATUS_CHANGE_CONFLICT);
302
+ case 'clean':
303
+ return chalk.gray(MESSAGES.STATUS_CHANGE_CLEAN);
304
+ }
305
+ }
306
+
307
+ /**
308
+ * 输出未清理快照区块
309
+ * @param {SnapshotInfo[]} snapshots - 快照信息列表
310
+ */
311
+ function printSnapshotsSection(snapshots: SnapshotInfo[]): void {
312
+ printInfo(` ${chalk.bold('◆')} ${chalk.bold(MESSAGES.STATUS_SNAPSHOTS_SECTION)} (${snapshots.length} 个)`);
313
+ printInfo('');
314
+
315
+ if (snapshots.length === 0) {
316
+ printInfo(` ${MESSAGES.STATUS_NO_SNAPSHOTS}`);
317
+ printInfo('');
318
+ return;
319
+ }
320
+
321
+ for (const snap of snapshots) {
322
+ const orphanLabel = snap.worktreeExists ? '' : ` ${chalk.yellow(MESSAGES.STATUS_SNAPSHOT_ORPHANED)}`;
323
+ const icon = snap.worktreeExists ? chalk.blue('●') : chalk.yellow('⚠');
324
+ printInfo(` ${icon} ${snap.branch}${orphanLabel}`);
325
+ }
326
+ printInfo('');
327
+ }
@@ -1,6 +1,6 @@
1
1
  export { CLAWT_HOME, CONFIG_PATH, LOGS_DIR, WORKTREES_DIR, VALIDATE_SNAPSHOTS_DIR } from './paths.js';
2
2
  export { INVALID_BRANCH_CHARS } from './branch.js';
3
- export { MESSAGES } from './messages.js';
3
+ export { MESSAGES } from './messages/index.js';
4
4
  export { EXIT_CODES } from './exitCodes.js';
5
5
  export { ENABLE_BRACKETED_PASTE, DISABLE_BRACKETED_PASTE, PASTE_THRESHOLD_MS } from './terminal.js';
6
6
  export { DEFAULT_CONFIG, CONFIG_DESCRIPTIONS, APPEND_SYSTEM_PROMPT } from './config.js';
@@ -0,0 +1,41 @@
1
+ /** 通用/共享提示消息 */
2
+ export const COMMON_MESSAGES = {
3
+ /** 不在主 worktree 根目录 */
4
+ NOT_MAIN_WORKTREE: '请在主 worktree 的根目录下执行 clawt',
5
+ /** Git 未安装 */
6
+ GIT_NOT_INSTALLED: 'Git 未安装或不在 PATH 中,请先安装 Git',
7
+ /** Claude Code CLI 未安装 */
8
+ CLAUDE_NOT_INSTALLED: 'Claude Code CLI 未安装,请先安装:npm install -g @anthropic-ai/claude-code',
9
+ /** 分支已存在 */
10
+ BRANCH_EXISTS: (name: string) => `分支 ${name} 已存在,无法创建`,
11
+ /** 分支名清理后为空 */
12
+ BRANCH_NAME_EMPTY: (original: string) =>
13
+ `分支名 "${original}" 中不包含合法字符,无法创建分支`,
14
+ /** 分支名被转换 */
15
+ BRANCH_SANITIZED: (original: string, sanitized: string) =>
16
+ `分支名已转换: ${original} → ${sanitized}`,
17
+ /** worktree 创建成功 */
18
+ WORKTREE_CREATED: (count: number) => `✓ 已创建 ${count} 个 worktree`,
19
+ /** worktree 移除成功 */
20
+ WORKTREE_REMOVED: (path: string) => `✓ 已移除 worktree: ${path}`,
21
+ /** 没有 worktree */
22
+ NO_WORKTREES: '(无 worktree)',
23
+ /** 目标 worktree 不存在 */
24
+ WORKTREE_NOT_FOUND: (name: string) => `worktree ${name} 不存在`,
25
+ /** 主 worktree 有未提交更改 */
26
+ MAIN_WORKTREE_DIRTY: '主 worktree 有未提交的更改,请先处理',
27
+ /** 目标 worktree 无更改 */
28
+ TARGET_WORKTREE_CLEAN: '该 worktree 的分支上没有任何更改,无需验证',
29
+ /** 用户取消破坏性操作 */
30
+ DESTRUCTIVE_OP_CANCELLED: '已取消操作',
31
+ /** 请提供提交信息 */
32
+ COMMIT_MESSAGE_REQUIRED: '请提供提交信息(-m 参数)',
33
+ /** 配置文件损坏,已重新生成默认配置 */
34
+ CONFIG_CORRUPTED: '配置文件损坏或无法解析,已重新生成默认配置',
35
+ /** worktree 状态获取失败 */
36
+ WORKTREE_STATUS_UNAVAILABLE: '(状态不可用)',
37
+ /** 分隔线 */
38
+ SEPARATOR: '────────────────────────────────────────',
39
+ /** 粗分隔线 */
40
+ DOUBLE_SEPARATOR: '════════════════════════════════════════',
41
+ } as const;
@@ -0,0 +1,5 @@
1
+ /** config 命令专属提示消息 */
2
+ export const CONFIG_CMD_MESSAGES = {
3
+ /** 配置已恢复为默认值 */
4
+ CONFIG_RESET_SUCCESS: '✓ 配置已恢复为默认值',
5
+ } as const;
@@ -0,0 +1,5 @@
1
+ /** create 命令专属提示消息 */
2
+ export const CREATE_MESSAGES = {
3
+ /** 创建数量参数无效 */
4
+ INVALID_COUNT: (value: string) => `无效的创建数量: "${value}",请输入正整数`,
5
+ } as const;
@@ -0,0 +1,29 @@
1
+ import { COMMON_MESSAGES } from './common.js';
2
+ import { RUN_MESSAGES } from './run.js';
3
+ import { CREATE_MESSAGES } from './create.js';
4
+ import { MERGE_MESSAGES } from './merge.js';
5
+ import { VALIDATE_MESSAGES } from './validate.js';
6
+ import { SYNC_MESSAGES } from './sync.js';
7
+ import { RESUME_MESSAGES } from './resume.js';
8
+ import { REMOVE_MESSAGES } from './remove.js';
9
+ import { RESET_MESSAGES } from './reset.js';
10
+ import { CONFIG_CMD_MESSAGES } from './config.js';
11
+ import { STATUS_MESSAGES } from './status.js';
12
+
13
+ /**
14
+ * 提示消息模板
15
+ * 合并所有子模块的消息,保持扁平结构以兼容现有的 MESSAGES.XXX 访问方式
16
+ */
17
+ export const MESSAGES = {
18
+ ...COMMON_MESSAGES,
19
+ ...RUN_MESSAGES,
20
+ ...CREATE_MESSAGES,
21
+ ...MERGE_MESSAGES,
22
+ ...VALIDATE_MESSAGES,
23
+ ...SYNC_MESSAGES,
24
+ ...RESUME_MESSAGES,
25
+ ...REMOVE_MESSAGES,
26
+ ...RESET_MESSAGES,
27
+ ...CONFIG_CMD_MESSAGES,
28
+ ...STATUS_MESSAGES,
29
+ } as const;
@@ -0,0 +1,42 @@
1
+ /** merge 命令专属提示消息 */
2
+ export const MERGE_MESSAGES = {
3
+ /** merge 成功 */
4
+ MERGE_SUCCESS: (branch: string, message: string, pushed: boolean) =>
5
+ `✓ 分支 ${branch} 已成功合并到当前分支\n 提交信息: ${message}${pushed ? '\n 已推送到远程仓库' : ''}`,
6
+ /** merge 成功(无提交信息,目标 worktree 已提交过) */
7
+ MERGE_SUCCESS_NO_MESSAGE: (branch: string, pushed: boolean) =>
8
+ `✓ 分支 ${branch} 已成功合并到当前分支${pushed ? '\n 已推送到远程仓库' : ''}`,
9
+ /** merge 冲突 */
10
+ MERGE_CONFLICT: '合并存在冲突,请手动处理:\n 解决冲突后执行 git add . && git merge --continue',
11
+ /** merge 后清理 worktree 和分支成功 */
12
+ WORKTREE_CLEANED: (branch: string) => `✓ 已清理 worktree 和分支: ${branch}`,
13
+ /** 目标 worktree 有未提交修改但未指定 -m */
14
+ TARGET_WORKTREE_DIRTY_NO_MESSAGE: '目标 worktree 有未提交的修改,请通过 -m 参数提供提交信息',
15
+ /** 目标 worktree 既干净又无本地提交 */
16
+ TARGET_WORKTREE_NO_CHANGES: '目标 worktree 没有任何可合并的变更(工作区干净且无本地提交)',
17
+ /** merge 命令检测到 validate 状态的提示 */
18
+ MERGE_VALIDATE_STATE_HINT: (branch: string) =>
19
+ `主 worktree 可能存在 validate 残留状态,可先执行 clawt validate -b ${branch} --clean 清理`,
20
+ /** merge 检测到 auto-save 提交,提示用户是否压缩 */
21
+ MERGE_SQUASH_PROMPT: '检测到 sync 产生的临时提交,是否将所有提交压缩为一个?\n 压缩后变更将保留在目标worktree的暂存区,需要重新提交(可使用 Claude Code Cli或其他工具生成提交信息)',
22
+ /** squash 完成且通过 -m 直接提交后的提示 */
23
+ MERGE_SQUASH_COMMITTED: (branch: string) =>
24
+ `✓ 已将分支 ${branch} 的所有提交压缩为一个`,
25
+ /** squash 完成但未提供 -m,提示用户自行提交 */
26
+ MERGE_SQUASH_PENDING: (worktreePath: string, branch: string) =>
27
+ `✓ 已将所有提交压缩到暂存区\n 请在目标 worktree 中提交后重新执行 merge:\n cd ${worktreePath}\n 提交完成后执行:clawt merge -b ${branch}`,
28
+ /** merge 后 pull 冲突 */
29
+ PULL_CONFLICT:
30
+ '自动 pull 时发生冲突,merge 已完成但远程同步失败\n 请手动解决冲突:\n 解决冲突后执行 git add . && git commit\n 然后执行 git push 推送到远程',
31
+ /** push 失败 */
32
+ PUSH_FAILED: '自动 push 失败,merge 和 pull 已完成\n 请手动执行 git push',
33
+ /** merge 无可用 worktree */
34
+ MERGE_NO_WORKTREES: '当前项目没有可用的 worktree,请先通过 clawt run 或 clawt create 创建',
35
+ /** merge 模糊匹配无结果,列出可用分支 */
36
+ MERGE_NO_MATCH: (name: string, branches: string[]) =>
37
+ `未找到与 "${name}" 匹配的分支\n 可用分支:\n${branches.map((b) => ` - ${b}`).join('\n')}`,
38
+ /** merge 交互选择提示 */
39
+ MERGE_SELECT_BRANCH: '请选择要合并的分支',
40
+ /** merge 模糊匹配到多个结果提示 */
41
+ MERGE_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择:`,
42
+ } as const;
@@ -0,0 +1,15 @@
1
+ /** remove 命令专属提示消息 */
2
+ export const REMOVE_MESSAGES = {
3
+ /** remove 无可用 worktree */
4
+ REMOVE_NO_WORKTREES: '当前项目没有可用的 worktree,无需移除',
5
+ /** remove 多选交互提示 */
6
+ REMOVE_SELECT_BRANCH: '请选择要移除的分支(空格选择,回车确认)',
7
+ /** remove 模糊匹配到多个结果提示 */
8
+ REMOVE_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择要移除的(空格选择,回车确认):`,
9
+ /** remove 模糊匹配无结果,列出可用分支 */
10
+ REMOVE_NO_MATCH: (name: string, branches: string[]) =>
11
+ `未找到与 "${name}" 匹配的分支\n 可用分支:\n${branches.map((b) => ` - ${b}`).join('\n')}`,
12
+ /** 批量移除部分失败 */
13
+ REMOVE_PARTIAL_FAILURE: (failures: Array<{ path: string; error: string }>) =>
14
+ `以下 worktree 移除失败:\n${failures.map((f) => ` ✗ ${f.path}: ${f.error}`).join('\n')}`,
15
+ } as const;
@@ -0,0 +1,7 @@
1
+ /** reset 命令专属提示消息 */
2
+ export const RESET_MESSAGES = {
3
+ /** reset 成功 */
4
+ RESET_SUCCESS: '✓ 主 worktree 工作区和暂存区已重置',
5
+ /** reset 时工作区和暂存区已干净 */
6
+ RESET_ALREADY_CLEAN: '主 worktree 工作区和暂存区已是干净状态,无需重置',
7
+ } as const;
@@ -0,0 +1,12 @@
1
+ /** resume 命令专属提示消息 */
2
+ export const RESUME_MESSAGES = {
3
+ /** resume 无可用 worktree */
4
+ RESUME_NO_WORKTREES: '当前项目没有可用的 worktree,请先通过 clawt run 或 clawt create 创建',
5
+ /** resume 模糊匹配无结果,列出可用分支 */
6
+ RESUME_NO_MATCH: (name: string, branches: string[]) =>
7
+ `未找到与 "${name}" 匹配的分支\n 可用分支:\n${branches.map((b) => ` - ${b}`).join('\n')}`,
8
+ /** resume 交互选择提示 */
9
+ RESUME_SELECT_BRANCH: '请选择要恢复的分支',
10
+ /** resume 模糊匹配到多个结果提示 */
11
+ RESUME_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择:`,
12
+ } as const;
@@ -0,0 +1,16 @@
1
+ /** run 命令专属提示消息 */
2
+ export const RUN_MESSAGES = {
3
+ /** 分支已存在时提示使用 resume */
4
+ BRANCH_EXISTS_USE_RESUME: (name: string) =>
5
+ `分支 ${name} 已存在,请使用 clawt resume -b ${name} 恢复会话`,
6
+ /** 检测到用户中断 */
7
+ INTERRUPTED: '检测到退出指令,已停止 Claude Code 任务',
8
+ /** 中断后自动清理完成 */
9
+ INTERRUPT_AUTO_CLEANED: (count: number) => `✓ 已自动清理 ${count} 个 worktree 和对应分支`,
10
+ /** 中断后手动确认清理 */
11
+ INTERRUPT_CONFIRM_CLEANUP: '是否移除刚刚创建的 worktree 和对应分支?',
12
+ /** 中断后清理完成 */
13
+ INTERRUPT_CLEANED: (count: number) => `✓ 已清理 ${count} 个 worktree 和对应分支`,
14
+ /** 中断后保留 worktree */
15
+ INTERRUPT_KEPT: '已保留 worktree,可稍后使用 clawt remove 手动清理',
16
+ } as const;
@@ -0,0 +1,25 @@
1
+ /** status 命令专属提示消息 */
2
+ export const STATUS_MESSAGES = {
3
+ /** status 命令标题 */
4
+ STATUS_TITLE: (projectName: string) => `项目状态总览: ${projectName}`,
5
+ /** status 主 worktree 区块标题 */
6
+ STATUS_MAIN_SECTION: '主 Worktree',
7
+ /** status worktrees 区块标题 */
8
+ STATUS_WORKTREES_SECTION: 'Worktree 列表',
9
+ /** status 快照区块标题 */
10
+ STATUS_SNAPSHOTS_SECTION: '未清理的 Validate 快照',
11
+ /** status 无 worktree */
12
+ STATUS_NO_WORKTREES: '(无活跃 worktree)',
13
+ /** status 无未清理快照 */
14
+ STATUS_NO_SNAPSHOTS: '(无未清理的快照)',
15
+ /** status 变更状态:已提交 */
16
+ STATUS_CHANGE_COMMITTED: '已提交',
17
+ /** status 变更状态:未提交修改 */
18
+ STATUS_CHANGE_UNCOMMITTED: '未提交修改',
19
+ /** status 变更状态:合并冲突 */
20
+ STATUS_CHANGE_CONFLICT: '合并冲突',
21
+ /** status 变更状态:无变更 */
22
+ STATUS_CHANGE_CLEAN: '无变更',
23
+ /** status 快照对应 worktree 已不存在 */
24
+ STATUS_SNAPSHOT_ORPHANED: '(对应 worktree 已不存在)',
25
+ } as const;
@@ -0,0 +1,24 @@
1
+ /** sync 命令专属提示消息 */
2
+ export const SYNC_MESSAGES = {
3
+ /** sync 自动保存未提交变更 */
4
+ SYNC_AUTO_COMMITTED: (branch: string) =>
5
+ `已自动保存 ${branch} 分支的未提交变更`,
6
+ /** sync 开始合并 */
7
+ SYNC_MERGING: (targetBranch: string, mainBranch: string) =>
8
+ `正在将 ${mainBranch} 合并到 ${targetBranch} ...`,
9
+ /** sync 成功 */
10
+ SYNC_SUCCESS: (targetBranch: string, mainBranch: string) =>
11
+ `✓ 已将 ${mainBranch} 的最新代码同步到 ${targetBranch}`,
12
+ /** sync 冲突 */
13
+ SYNC_CONFLICT: (worktreePath: string) =>
14
+ `合并存在冲突,请进入目标 worktree 手动解决:\n cd ${worktreePath}\n 解决冲突后执行 git add . && git merge --continue\n clawt validate -b <branch> 验证变更`,
15
+ /** sync 无可用 worktree */
16
+ SYNC_NO_WORKTREES: '当前项目没有可用的 worktree,请先通过 clawt run 或 clawt create 创建',
17
+ /** sync 模糊匹配无结果,列出可用分支 */
18
+ SYNC_NO_MATCH: (name: string, branches: string[]) =>
19
+ `未找到与 "${name}" 匹配的分支\n 可用分支:\n${branches.map((b) => ` - ${b}`).join('\n')}`,
20
+ /** sync 交互选择提示 */
21
+ SYNC_SELECT_BRANCH: '请选择要同步的分支',
22
+ /** sync 模糊匹配到多个结果提示 */
23
+ SYNC_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择:`,
24
+ } as const;
@@ -0,0 +1,25 @@
1
+ /** validate 命令专属提示消息 */
2
+ export const VALIDATE_MESSAGES = {
3
+ /** validate 成功 */
4
+ VALIDATE_SUCCESS: (branch: string) =>
5
+ `✓ 已将分支 ${branch} 的变更应用到主 worktree\n 可以开始验证了`,
6
+ /** 增量 validate 成功提示 */
7
+ INCREMENTAL_VALIDATE_SUCCESS: (branch: string) =>
8
+ `✓ 已将分支 ${branch} 的最新变更应用到主 worktree(增量模式)\n 暂存区 = 上次快照,工作目录 = 最新变更`,
9
+ /** 增量 validate 降级为全量模式提示 */
10
+ INCREMENTAL_VALIDATE_FALLBACK: '增量对比失败,已降级为全量模式',
11
+ /** validate 状态已清理 */
12
+ VALIDATE_CLEANED: (branch: string) => `✓ 分支 ${branch} 的 validate 状态已清理`,
13
+ /** validate patch apply 失败,提示用户同步主分支 */
14
+ VALIDATE_PATCH_APPLY_FAILED: (branch: string) =>
15
+ `变更迁移失败:目标分支与主分支差异过大\n 请先执行 clawt sync -b ${branch} 同步主分支后重试`,
16
+ /** validate 无可用 worktree */
17
+ VALIDATE_NO_WORKTREES: '当前项目没有可用的 worktree,请先通过 clawt run 或 clawt create 创建',
18
+ /** validate 模糊匹配无结果,列出可用分支 */
19
+ VALIDATE_NO_MATCH: (name: string, branches: string[]) =>
20
+ `未找到与 "${name}" 匹配的分支\n 可用分支:\n${branches.map((b) => ` - ${b}`).join('\n')}`,
21
+ /** validate 交互选择提示 */
22
+ VALIDATE_SELECT_BRANCH: '请选择要验证的分支',
23
+ /** validate 模糊匹配到多个结果提示 */
24
+ VALIDATE_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择:`,
25
+ } as const;
@@ -148,6 +148,28 @@ export const MESSAGES = {
148
148
  SYNC_SELECT_BRANCH: '请选择要同步的分支',
149
149
  /** sync 模糊匹配到多个结果提示 */
150
150
  SYNC_MULTIPLE_MATCHES: (name: string) => `"${name}" 匹配到多个分支,请选择:`,
151
+ /** status 命令标题 */
152
+ STATUS_TITLE: (projectName: string) => `项目状态总览: ${projectName}`,
153
+ /** status 主 worktree 区块标题 */
154
+ STATUS_MAIN_SECTION: '主 Worktree',
155
+ /** status worktrees 区块标题 */
156
+ STATUS_WORKTREES_SECTION: 'Worktree 列表',
157
+ /** status 快照区块标题 */
158
+ STATUS_SNAPSHOTS_SECTION: '未清理的 Validate 快照',
159
+ /** status 无 worktree */
160
+ STATUS_NO_WORKTREES: '(无活跃 worktree)',
161
+ /** status 无未清理快照 */
162
+ STATUS_NO_SNAPSHOTS: '(无未清理的快照)',
163
+ /** status 变更状态:已提交 */
164
+ STATUS_CHANGE_COMMITTED: '已提交',
165
+ /** status 变更状态:未提交修改 */
166
+ STATUS_CHANGE_UNCOMMITTED: '未提交修改',
167
+ /** status 变更状态:合并冲突 */
168
+ STATUS_CHANGE_CONFLICT: '合并冲突',
169
+ /** status 变更状态:无变更 */
170
+ STATUS_CHANGE_CLEAN: '无变更',
171
+ /** status 快照对应 worktree 已不存在 */
172
+ STATUS_SNAPSHOT_ORPHANED: '(对应 worktree 已不存在)',
151
173
  /** merge 后 pull 冲突 */
152
174
  PULL_CONFLICT:
153
175
  '自动 pull 时发生冲突,merge 已完成但远程同步失败\n 请手动解决冲突:\n 解决冲突后执行 git add . && git commit\n 然后执行 git push 推送到远程',
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import { registerMergeCommand } from './commands/merge.js';
14
14
  import { registerConfigCommand } from './commands/config.js';
15
15
  import { registerSyncCommand } from './commands/sync.js';
16
16
  import { registerResetCommand } from './commands/reset.js';
17
+ import { registerStatusCommand } from './commands/status.js';
17
18
 
18
19
  // 从 package.json 读取版本号,避免硬编码
19
20
  const require = createRequire(import.meta.url);
@@ -48,6 +49,7 @@ registerMergeCommand(program);
48
49
  registerConfigCommand(program);
49
50
  registerSyncCommand(program);
50
51
  registerResetCommand(program);
52
+ registerStatusCommand(program);
51
53
 
52
54
  // 全局未捕获异常处理
53
55
  process.on('uncaughtException', (error) => {
@@ -55,3 +55,9 @@ export interface ListOptions {
55
55
  /** 以 JSON 格式输出 */
56
56
  json?: boolean;
57
57
  }
58
+
59
+ /** status 命令选项 */
60
+ export interface StatusOptions {
61
+ /** 以 JSON 格式输出 */
62
+ json?: boolean;
63
+ }
@@ -1,5 +1,6 @@
1
1
  export type { ClawtConfig, ConfigItemDefinition, ConfigDefinitions } from './config.js';
2
- export type { CreateOptions, RunOptions, ValidateOptions, MergeOptions, RemoveOptions, ResumeOptions, SyncOptions, ListOptions } from './command.js';
2
+ export type { CreateOptions, RunOptions, ValidateOptions, MergeOptions, RemoveOptions, ResumeOptions, SyncOptions, ListOptions, StatusOptions } from './command.js';
3
3
  export type { WorktreeInfo, WorktreeStatus } from './worktree.js';
4
4
  export type { ClaudeCodeResult } from './claudeCode.js';
5
5
  export type { TaskResult, TaskSummary } from './taskResult.js';
6
+ export type { WorktreeDetailedStatus, MainWorktreeStatus, SnapshotInfo, StatusResult } from './status.js';