clawt 1.0.3 → 1.0.5
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/index.js +27 -5
- package/package.json +3 -2
- package/src/commands/create.ts +11 -1
- package/src/constants/messages.ts +4 -0
- package/src/index.ts +6 -1
- package/src/types/command.ts +2 -2
- package/src/utils/config.ts +19 -3
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createRequire as __clawt_createRequire } from "module";
|
|
|
3
3
|
const require = __clawt_createRequire(import.meta.url);
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
+
import { createRequire } from "module";
|
|
6
7
|
import { Command } from "commander";
|
|
7
8
|
|
|
8
9
|
// src/constants/paths.ts
|
|
@@ -71,10 +72,14 @@ var MESSAGES = {
|
|
|
71
72
|
INTERRUPT_CLEANED: (count) => `\u2713 \u5DF2\u6E05\u7406 ${count} \u4E2A worktree \u548C\u5BF9\u5E94\u5206\u652F`,
|
|
72
73
|
/** 中断后保留 worktree */
|
|
73
74
|
INTERRUPT_KEPT: "\u5DF2\u4FDD\u7559 worktree\uFF0C\u53EF\u7A0D\u540E\u4F7F\u7528 clawt remove \u624B\u52A8\u6E05\u7406",
|
|
75
|
+
/** 配置文件损坏,已重新生成默认配置 */
|
|
76
|
+
CONFIG_CORRUPTED: "\u914D\u7F6E\u6587\u4EF6\u635F\u574F\u6216\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u91CD\u65B0\u751F\u6210\u9ED8\u8BA4\u914D\u7F6E",
|
|
74
77
|
/** 分隔线 */
|
|
75
78
|
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",
|
|
76
79
|
/** 粗分隔线 */
|
|
77
|
-
DOUBLE_SEPARATOR: "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"
|
|
80
|
+
DOUBLE_SEPARATOR: "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",
|
|
81
|
+
/** 创建数量参数无效 */
|
|
82
|
+
INVALID_COUNT: (value) => `\u65E0\u6548\u7684\u521B\u5EFA\u6570\u91CF: "${value}"\uFF0C\u8BF7\u8F93\u5165\u6B63\u6574\u6570`
|
|
78
83
|
};
|
|
79
84
|
|
|
80
85
|
// src/constants/exitCodes.ts
|
|
@@ -425,13 +430,22 @@ function cleanupWorktrees(worktrees) {
|
|
|
425
430
|
}
|
|
426
431
|
|
|
427
432
|
// src/utils/config.ts
|
|
428
|
-
import { existsSync as existsSync4, readFileSync } from "fs";
|
|
433
|
+
import { existsSync as existsSync4, readFileSync, writeFileSync } from "fs";
|
|
429
434
|
function loadConfig() {
|
|
430
435
|
if (!existsSync4(CONFIG_PATH)) {
|
|
431
436
|
return { ...DEFAULT_CONFIG };
|
|
432
437
|
}
|
|
433
|
-
|
|
434
|
-
|
|
438
|
+
try {
|
|
439
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
440
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(raw) };
|
|
441
|
+
} catch {
|
|
442
|
+
logger.warn(MESSAGES.CONFIG_CORRUPTED);
|
|
443
|
+
writeDefaultConfig();
|
|
444
|
+
return { ...DEFAULT_CONFIG };
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function writeDefaultConfig() {
|
|
448
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(DEFAULT_CONFIG, null, 2), "utf-8");
|
|
435
449
|
}
|
|
436
450
|
function getConfigValue(key) {
|
|
437
451
|
const config = loadConfig();
|
|
@@ -479,6 +493,12 @@ function registerCreateCommand(program2) {
|
|
|
479
493
|
function handleCreate(options) {
|
|
480
494
|
validateMainWorktree();
|
|
481
495
|
const count = Number(options.number);
|
|
496
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
497
|
+
throw new ClawtError(
|
|
498
|
+
MESSAGES.INVALID_COUNT(options.number),
|
|
499
|
+
EXIT_CODES.ARGUMENT_ERROR
|
|
500
|
+
);
|
|
501
|
+
}
|
|
482
502
|
logger.info(`create \u547D\u4EE4\u6267\u884C\uFF0C\u5206\u652F: ${options.branch}\uFF0C\u6570\u91CF: ${count}`);
|
|
483
503
|
const worktrees = createWorktrees(options.branch, count);
|
|
484
504
|
printSuccess(MESSAGES.WORKTREE_CREATED(worktrees.length));
|
|
@@ -899,9 +919,11 @@ async function handleMerge(options) {
|
|
|
899
919
|
}
|
|
900
920
|
|
|
901
921
|
// src/index.ts
|
|
922
|
+
var require2 = createRequire(import.meta.url);
|
|
923
|
+
var { version } = require2("../package.json");
|
|
902
924
|
ensureClawtDirs();
|
|
903
925
|
var program = new Command();
|
|
904
|
-
program.name("clawt").description("\u672C\u5730\u5E76\u884C\u6267\u884C\u591A\u4E2AClaude Code Agent\u4EFB\u52A1\uFF0C\u878D\u5408 Git Worktree \u4E0E Claude Code CLI \u7684\u547D\u4EE4\u884C\u5DE5\u5177").version(
|
|
926
|
+
program.name("clawt").description("\u672C\u5730\u5E76\u884C\u6267\u884C\u591A\u4E2AClaude Code Agent\u4EFB\u52A1\uFF0C\u878D\u5408 Git Worktree \u4E0E Claude Code CLI \u7684\u547D\u4EE4\u884C\u5DE5\u5177").version(version);
|
|
905
927
|
registerListCommand(program);
|
|
906
928
|
registerCreateCommand(program);
|
|
907
929
|
registerRemoveCommand(program);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clawt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "本地并行执行多个Claude Code Agent任务,融合 Git Worktree 与 Claude Code CLI 的命令行工具",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsup",
|
|
12
12
|
"dev": "tsup --watch",
|
|
13
|
-
"postinstall": "node dist/postinstall.js"
|
|
13
|
+
"postinstall": "node dist/postinstall.js",
|
|
14
|
+
"release": "bash scripts/release.sh"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
16
17
|
"claude",
|
package/src/commands/create.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
|
-
import { MESSAGES } from '../constants/index.js';
|
|
2
|
+
import { MESSAGES, EXIT_CODES } from '../constants/index.js';
|
|
3
|
+
import { ClawtError } from '../errors/index.js';
|
|
3
4
|
import { logger } from '../logger/index.js';
|
|
4
5
|
import type { CreateOptions } from '../types/index.js';
|
|
5
6
|
import {
|
|
@@ -33,6 +34,15 @@ function handleCreate(options: CreateOptions): void {
|
|
|
33
34
|
validateMainWorktree();
|
|
34
35
|
|
|
35
36
|
const count = Number(options.number);
|
|
37
|
+
|
|
38
|
+
// 校验创建数量必须为正整数
|
|
39
|
+
if (!Number.isInteger(count) || count <= 0) {
|
|
40
|
+
throw new ClawtError(
|
|
41
|
+
MESSAGES.INVALID_COUNT(options.number),
|
|
42
|
+
EXIT_CODES.ARGUMENT_ERROR,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
36
46
|
logger.info(`create 命令执行,分支: ${options.branch},数量: ${count}`);
|
|
37
47
|
|
|
38
48
|
const worktrees = createWorktrees(options.branch, count);
|
|
@@ -54,8 +54,12 @@ export const MESSAGES = {
|
|
|
54
54
|
INTERRUPT_CLEANED: (count: number) => `✓ 已清理 ${count} 个 worktree 和对应分支`,
|
|
55
55
|
/** 中断后保留 worktree */
|
|
56
56
|
INTERRUPT_KEPT: '已保留 worktree,可稍后使用 clawt remove 手动清理',
|
|
57
|
+
/** 配置文件损坏,已重新生成默认配置 */
|
|
58
|
+
CONFIG_CORRUPTED: '配置文件损坏或无法解析,已重新生成默认配置',
|
|
57
59
|
/** 分隔线 */
|
|
58
60
|
SEPARATOR: '────────────────────────────────────────',
|
|
59
61
|
/** 粗分隔线 */
|
|
60
62
|
DOUBLE_SEPARATOR: '════════════════════════════════════════',
|
|
63
|
+
/** 创建数量参数无效 */
|
|
64
|
+
INVALID_COUNT: (value: string) => `无效的创建数量: "${value}",请输入正整数`,
|
|
61
65
|
} as const;
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { Command } from 'commander';
|
|
2
3
|
import { ClawtError } from './errors/index.js';
|
|
3
4
|
import { logger } from './logger/index.js';
|
|
@@ -10,6 +11,10 @@ import { registerRunCommand } from './commands/run.js';
|
|
|
10
11
|
import { registerValidateCommand } from './commands/validate.js';
|
|
11
12
|
import { registerMergeCommand } from './commands/merge.js';
|
|
12
13
|
|
|
14
|
+
// 从 package.json 读取版本号,避免硬编码
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const { version } = require('../package.json');
|
|
17
|
+
|
|
13
18
|
// 确保全局目录结构存在
|
|
14
19
|
ensureClawtDirs();
|
|
15
20
|
|
|
@@ -18,7 +23,7 @@ const program = new Command();
|
|
|
18
23
|
program
|
|
19
24
|
.name('clawt')
|
|
20
25
|
.description('本地并行执行多个Claude Code Agent任务,融合 Git Worktree 与 Claude Code CLI 的命令行工具')
|
|
21
|
-
.version(
|
|
26
|
+
.version(version);
|
|
22
27
|
|
|
23
28
|
// 注册所有命令
|
|
24
29
|
registerListCommand(program);
|
package/src/types/command.ts
CHANGED
package/src/utils/config.ts
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { CONFIG_PATH, CLAWT_HOME, LOGS_DIR, WORKTREES_DIR, DEFAULT_CONFIG } from '../constants/index.js';
|
|
2
|
+
import { CONFIG_PATH, CLAWT_HOME, LOGS_DIR, WORKTREES_DIR, DEFAULT_CONFIG, MESSAGES } from '../constants/index.js';
|
|
3
3
|
import { ensureDir } from './fs.js';
|
|
4
|
+
import { logger } from '../logger/index.js';
|
|
4
5
|
import type { ClawtConfig } from '../types/index.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 加载全局配置,不存在则返回默认配置
|
|
9
|
+
* 配置文件损坏或无法解析时,视为不存在,重新生成默认配置
|
|
8
10
|
* @returns {ClawtConfig} 配置对象
|
|
9
11
|
*/
|
|
10
12
|
export function loadConfig(): ClawtConfig {
|
|
11
13
|
if (!existsSync(CONFIG_PATH)) {
|
|
12
14
|
return { ...DEFAULT_CONFIG };
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
try {
|
|
17
|
+
const raw = readFileSync(CONFIG_PATH, 'utf-8');
|
|
18
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(raw) };
|
|
19
|
+
} catch {
|
|
20
|
+
// 配置文件损坏或无法解析时,重新生成默认配置
|
|
21
|
+
logger.warn(MESSAGES.CONFIG_CORRUPTED);
|
|
22
|
+
writeDefaultConfig();
|
|
23
|
+
return { ...DEFAULT_CONFIG };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 将默认配置写入配置文件
|
|
29
|
+
*/
|
|
30
|
+
function writeDefaultConfig(): void {
|
|
31
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
/**
|