clawt 2.7.1 → 2.7.2

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.
@@ -7,7 +7,7 @@
7
7
  - 命令流程在 `5. 需求场景详细设计` 下,每个命令一个子章节(5.1-5.13)
8
8
  - run 命令对应 `5.2 批量创建 Worktree + 执行 Claude Code 任务`,流程按步骤编号描述
9
9
  - merge 命令对应 `5.6 合并验证过的分支`,-b 可选,支持模糊匹配(与 resume/validate 共享匹配逻辑),流程按步骤编号描述
10
- - config 命令对应 `5.10 查看全局配置`,只读展示配置
10
+ - config 命令对应 `5.10 查看和管理全局配置`,包含查看配置和 config reset 子命令两部分(使用 `####` 子标题区分)
11
11
  - resume 命令对应 `5.11 在已有 Worktree 中恢复会话`,支持模糊匹配和交互式分支选择(-b 可选)
12
12
  - validate 命令对应 `5.4 在主 Worktree 验证其他分支`,-b 可选,支持模糊匹配(与 resume 共享匹配逻辑)
13
13
  - sync 命令对应 `5.12 将主分支代码同步到目标 Worktree`,-b 可选,支持模糊匹配(与 resume/validate/merge 共享匹配逻辑)
@@ -22,7 +22,7 @@
22
22
 
23
23
  ## 关键约定
24
24
  - `autoDeleteBranch` 配置项影响三处:remove 命令、merge 命令、run 中断清理
25
- - `confirmDestructiveOps` 配置项影响两处:reset 命令、validate --clean
25
+ - `confirmDestructiveOps` 配置项影响三处:reset 命令、validate --clean、config reset
26
26
  - merge 的清理确认和清理操作均在 merge 成功后执行(避免 merge 冲突时提前询问用户造成困惑)
27
27
  - merge 成功后自动清理对应的 validate 快照(hasSnapshot + removeSnapshot)
28
28
  - merge 成功消息根据 `autoPullPush` 配置动态显示推送状态
@@ -35,7 +35,7 @@
35
35
  - `launchInteractiveClaude` 是 run(交互式模式)和 resume 共用的公共函数(在 src/utils/claude.ts)
36
36
  - killAllChildProcesses 是 run 专用的子进程终止函数(在 src/utils/shell.ts)
37
37
  - validate 快照管理函数在 `src/utils/validate-snapshot.ts`,被 validate、merge 和 remove 三个命令使用
38
- - `confirmDestructiveAction` 在 `src/utils/formatter.ts`,被 resetvalidate --clean 使用
38
+ - `confirmDestructiveAction` 在 `src/utils/formatter.ts`,被 resetvalidate --clean 和 config reset 使用
39
39
  - sanitizeBranchName 清理后为空串时抛出 BRANCH_NAME_EMPTY 错误
40
40
 
41
41
  ## 配置项同步检查点
package/README.md CHANGED
@@ -269,14 +269,20 @@ clawt reset
269
269
  clawt reset
270
270
  ```
271
271
 
272
- ### `clawt config` — 查看全局配置
272
+ ### `clawt config` — 查看和管理全局配置
273
273
 
274
274
  ```bash
275
+ # 查看全局配置
275
276
  clawt config
277
+
278
+ # 将配置恢复为默认值
279
+ clawt config reset
276
280
  ```
277
281
 
278
282
  读取并展示全局配置文件 `~/.clawt/config.json` 中的所有配置项,包括每项的当前值和描述说明。编辑配置需直接修改配置文件。
279
283
 
284
+ `config reset` 子命令可将配置文件恢复为默认值,执行前会弹出确认提示(受 `confirmDestructiveOps` 配置项控制)。
285
+
280
286
  ## 配置文件
281
287
 
282
288
  安装后会自动在 `~/.clawt/config.json` 生成全局配置文件:
@@ -295,7 +301,7 @@ clawt config
295
301
  | `autoDeleteBranch` | `boolean` | `false` | 移除 worktree 时自动删除对应本地分支;merge 成功后自动清理 worktree 和分支;run 中断后自动清理本次创建的 worktree 和分支 |
296
302
  | `claudeCodeCommand` | `string` | `"claude"` | Claude Code CLI 启动指令,用于 `clawt run` 不传 `--tasks` 时和 `clawt resume` 在 worktree 中打开交互式界面 |
297
303
  | `autoPullPush` | `boolean` | `false` | merge 成功后是否自动执行 git pull 和 git push |
298
- | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean)前是否提示确认 |
304
+ | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean、config reset)前是否提示确认 |
299
305
 
300
306
  ## 分支名规则
301
307
 
package/dist/index.js CHANGED
@@ -76,6 +76,8 @@ var MESSAGES = {
76
76
  INTERRUPT_KEPT: "\u5DF2\u4FDD\u7559 worktree\uFF0C\u53EF\u7A0D\u540E\u4F7F\u7528 clawt remove \u624B\u52A8\u6E05\u7406",
77
77
  /** 配置文件损坏,已重新生成默认配置 */
78
78
  CONFIG_CORRUPTED: "\u914D\u7F6E\u6587\u4EF6\u635F\u574F\u6216\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u91CD\u65B0\u751F\u6210\u9ED8\u8BA4\u914D\u7F6E",
79
+ /** 配置已恢复为默认值 */
80
+ CONFIG_RESET_SUCCESS: "\u2713 \u914D\u7F6E\u5DF2\u6062\u590D\u4E3A\u9ED8\u8BA4\u503C",
79
81
  /** 分隔线 */
80
82
  SEPARATOR: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
81
83
  /** 粗分隔线 */
@@ -1445,9 +1447,12 @@ async function handleMerge(options) {
1445
1447
  // src/commands/config.ts
1446
1448
  import chalk3 from "chalk";
1447
1449
  function registerConfigCommand(program2) {
1448
- program2.command("config").description("\u67E5\u770B\u5168\u5C40\u914D\u7F6E").action(() => {
1450
+ const configCmd = program2.command("config").description("\u67E5\u770B\u548C\u7BA1\u7406\u5168\u5C40\u914D\u7F6E").action(() => {
1449
1451
  handleConfig();
1450
1452
  });
1453
+ configCmd.command("reset").description("\u5C06\u914D\u7F6E\u6062\u590D\u4E3A\u9ED8\u8BA4\u503C").action(async () => {
1454
+ await handleConfigReset();
1455
+ });
1451
1456
  }
1452
1457
  function handleConfig() {
1453
1458
  const config = loadConfig();
@@ -1469,6 +1474,19 @@ ${chalk3.dim("\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84:")} ${CONFIG_PATH}
1469
1474
  }
1470
1475
  printSeparator();
1471
1476
  }
1477
+ async function handleConfigReset() {
1478
+ logger.info("config reset \u547D\u4EE4\u6267\u884C\uFF0C\u6062\u590D\u9ED8\u8BA4\u914D\u7F6E");
1479
+ const confirmed = await confirmDestructiveAction(
1480
+ "config reset",
1481
+ "\u5F53\u524D\u914D\u7F6E\u5C06\u88AB\u8986\u76D6\u4E3A\u9ED8\u8BA4\u503C"
1482
+ );
1483
+ if (!confirmed) {
1484
+ printInfo(MESSAGES.DESTRUCTIVE_OP_CANCELLED);
1485
+ return;
1486
+ }
1487
+ writeDefaultConfig();
1488
+ printSuccess(MESSAGES.CONFIG_RESET_SUCCESS);
1489
+ }
1472
1490
  function formatConfigValue(value) {
1473
1491
  if (typeof value === "boolean") {
1474
1492
  return value ? chalk3.green("true") : chalk3.yellow("false");
package/docs/spec.md CHANGED
@@ -21,7 +21,7 @@
21
21
  - [5.7 默认配置文件](#57-默认配置文件)
22
22
  - [5.8 获取当前项目所有 Worktree](#58-获取当前项目所有-worktree)
23
23
  - [5.9 日志系统](#59-日志系统)
24
- - [5.10 查看全局配置](#510-查看全局配置)
24
+ - [5.10 查看和管理全局配置](#510-查看和管理全局配置)
25
25
  - [5.11 在已有 Worktree 中恢复会话](#511-在已有-worktree-中恢复会话)
26
26
  - [5.12 将主分支代码同步到目标 Worktree](#512-将主分支代码同步到目标-worktree)
27
27
  - [5.13 重置主 Worktree 工作区和暂存区](#513-重置主-worktree-工作区和暂存区)
@@ -168,6 +168,7 @@ git show-ref --verify refs/heads/<branchName> 2>/dev/null
168
168
  | `clawt remove` | 移除 worktree(支持单个/批量/全部) | 5.5 |
169
169
  | `clawt list` | 列出当前项目所有 worktree(支持 `--json` 格式输出) | 5.8 |
170
170
  | `clawt config` | 查看全局配置 | 5.10 |
171
+ | `clawt config reset` | 将配置恢复为默认值 | 5.10 |
171
172
  | `clawt resume` | 在已有 worktree 中恢复 Claude Code 交互式会话 | 5.11 |
172
173
  | `clawt sync` | 将主分支最新代码同步到目标 worktree | 5.12 |
173
174
  | `clawt reset` | 重置主 worktree 工作区和暂存区 | 5.13 |
@@ -775,7 +776,7 @@ clawt merge [-m <commitMessage>]
775
776
  | `autoDeleteBranch` | `boolean` | `false` | 移除 worktree 时是否自动删除对应本地分支(无需每次确认);merge 成功后是否自动清理 worktree 和分支;run 任务被中断(Ctrl+C)后是否自动清理本次创建的 worktree 和分支 |
776
777
  | `claudeCodeCommand` | `string` | `"claude"` | Claude Code CLI 启动指令,用于 `clawt run` 不传 `--tasks` 时和 `clawt resume` 在 worktree 中打开交互式界面 |
777
778
  | `autoPullPush` | `boolean` | `false` | merge 成功后是否自动执行 git pull 和 git push |
778
- | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean)前是否提示确认 |
779
+ | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean、config reset)前是否提示确认 |
779
780
 
780
781
  ---
781
782
 
@@ -878,14 +879,20 @@ clawt list [--json]
878
879
 
879
880
  ---
880
881
 
881
- ### 5.10 查看全局配置
882
+ ### 5.10 查看和管理全局配置
882
883
 
883
884
  **命令:**
884
885
 
885
886
  ```bash
887
+ # 查看全局配置
886
888
  clawt config
889
+
890
+ # 将配置恢复为默认值
891
+ clawt config reset
887
892
  ```
888
893
 
894
+ #### 查看配置
895
+
889
896
  **运行流程:**
890
897
 
891
898
  1. 读取全局配置文件 `~/.clawt/config.json`
@@ -916,6 +923,14 @@ clawt config
916
923
 
917
924
  ```
918
925
 
926
+ #### 恢复默认配置
927
+
928
+ **运行流程:**
929
+
930
+ 1. 如果配置项 `confirmDestructiveOps` 为 `true`,提示确认(显示即将执行的操作和后果:当前配置将被覆盖为默认值),用户取消则退出
931
+ 2. 将默认配置写入 `~/.clawt/config.json`(覆盖现有配置文件)
932
+ 3. 输出成功提示:`✓ 配置已恢复为默认值`
933
+
919
934
  ---
920
935
 
921
936
  ### 5.11 在已有 Worktree 中恢复会话
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawt",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "description": "本地并行执行多个Claude Code Agent任务,融合 Git Worktree 与 Claude Code CLI 的命令行工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,21 +1,28 @@
1
1
  import type { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import { CONFIG_PATH, DEFAULT_CONFIG, CONFIG_DESCRIPTIONS } from '../constants/index.js';
3
+ import { CONFIG_PATH, DEFAULT_CONFIG, CONFIG_DESCRIPTIONS, MESSAGES } from '../constants/index.js';
4
4
  import { logger } from '../logger/index.js';
5
- import { loadConfig, printInfo, printSeparator } from '../utils/index.js';
5
+ import { loadConfig, writeDefaultConfig, printInfo, printSuccess, printSeparator, confirmDestructiveAction } from '../utils/index.js';
6
6
  import type { ClawtConfig } from '../types/index.js';
7
7
 
8
8
  /**
9
- * 注册 config 命令:查看全局配置
9
+ * 注册 config 命令组:查看和管理全局配置
10
10
  * @param {Command} program - Commander 实例
11
11
  */
12
12
  export function registerConfigCommand(program: Command): void {
13
- program
13
+ const configCmd = program
14
14
  .command('config')
15
- .description('查看全局配置')
15
+ .description('查看和管理全局配置')
16
16
  .action(() => {
17
17
  handleConfig();
18
18
  });
19
+
20
+ configCmd
21
+ .command('reset')
22
+ .description('将配置恢复为默认值')
23
+ .action(async () => {
24
+ await handleConfigReset();
25
+ });
19
26
  }
20
27
 
21
28
  /**
@@ -48,6 +55,26 @@ function handleConfig(): void {
48
55
  printSeparator();
49
56
  }
50
57
 
58
+ /**
59
+ * 执行 config reset 子命令的核心逻辑,将配置恢复为默认值
60
+ */
61
+ async function handleConfigReset(): Promise<void> {
62
+ logger.info('config reset 命令执行,恢复默认配置');
63
+
64
+ const confirmed = await confirmDestructiveAction(
65
+ 'config reset',
66
+ '当前配置将被覆盖为默认值',
67
+ );
68
+
69
+ if (!confirmed) {
70
+ printInfo(MESSAGES.DESTRUCTIVE_OP_CANCELLED);
71
+ return;
72
+ }
73
+
74
+ writeDefaultConfig();
75
+ printSuccess(MESSAGES.CONFIG_RESET_SUCCESS);
76
+ }
77
+
51
78
  /**
52
79
  * 格式化配置值的显示样式
53
80
  * @param {ClawtConfig[keyof ClawtConfig]} value - 配置值
@@ -60,6 +60,8 @@ export const MESSAGES = {
60
60
  INTERRUPT_KEPT: '已保留 worktree,可稍后使用 clawt remove 手动清理',
61
61
  /** 配置文件损坏,已重新生成默认配置 */
62
62
  CONFIG_CORRUPTED: '配置文件损坏或无法解析,已重新生成默认配置',
63
+ /** 配置已恢复为默认值 */
64
+ CONFIG_RESET_SUCCESS: '✓ 配置已恢复为默认值',
63
65
  /** 分隔线 */
64
66
  SEPARATOR: '────────────────────────────────────────',
65
67
  /** 粗分隔线 */
@@ -27,7 +27,7 @@ export function loadConfig(): ClawtConfig {
27
27
  /**
28
28
  * 将默认配置写入配置文件
29
29
  */
30
- function writeDefaultConfig(): void {
30
+ export function writeDefaultConfig(): void {
31
31
  writeFileSync(CONFIG_PATH, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
32
32
  }
33
33
 
@@ -47,7 +47,7 @@ export {
47
47
  export { sanitizeBranchName, generateBranchNames, validateBranchesNotExist } from './branch.js';
48
48
  export { validateMainWorktree, validateGitInstalled, validateClaudeCodeInstalled } from './validation.js';
49
49
  export { createWorktrees, getProjectWorktrees, getProjectWorktreeDir, cleanupWorktrees, getWorktreeStatus } from './worktree.js';
50
- export { loadConfig, getConfigValue, ensureClawtDirs } from './config.js';
50
+ export { loadConfig, getConfigValue, ensureClawtDirs, writeDefaultConfig } from './config.js';
51
51
  export { printSuccess, printError, printWarning, printInfo, printSeparator, printDoubleSeparator, confirmAction, confirmDestructiveAction, formatWorktreeStatus } from './formatter.js';
52
52
  export { ensureDir, removeEmptyDir } from './fs.js';
53
53
  export { multilineInput } from './prompt.js';