clawt 3.8.4 → 3.8.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 CHANGED
@@ -26,6 +26,8 @@ var VALIDATE_BRANCH_PREFIX = "clawt-validate-";
26
26
  var COMMON_MESSAGES = {
27
27
  /** 不在主 worktree 根目录 */
28
28
  NOT_MAIN_WORKTREE: "\u8BF7\u5728\u4E3B worktree \u7684\u6839\u76EE\u5F55\u4E0B\u6267\u884C clawt",
29
+ /** 不在 git 仓库中 */
30
+ NOT_GIT_REPO: "\u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u5148\u6267\u884C git init \u5E76\u63D0\u4EA4\u540E\uFF0C\u518D\u6267\u884C clawt init \u521D\u59CB\u5316\u9879\u76EE",
29
31
  /** Git 未安装 */
30
32
  GIT_NOT_INSTALLED: "Git \u672A\u5B89\u88C5\u6216\u4E0D\u5728 PATH \u4E2D\uFF0C\u8BF7\u5148\u5B89\u88C5 Git",
31
33
  /** Claude Code CLI 未安装 */
@@ -1735,15 +1737,11 @@ async function ensureOnMainWorkBranch(cwd) {
1735
1737
 
1736
1738
  // src/utils/validation.ts
1737
1739
  function validateMainWorktree() {
1738
- try {
1739
- const gitCommonDir = getGitCommonDir();
1740
- if (gitCommonDir !== ".git") {
1741
- throw new ClawtError(MESSAGES.NOT_MAIN_WORKTREE);
1742
- }
1743
- } catch (error) {
1744
- if (error instanceof ClawtError) {
1745
- throw error;
1746
- }
1740
+ if (!isInsideGitRepo()) {
1741
+ throw new ClawtError(MESSAGES.NOT_GIT_REPO);
1742
+ }
1743
+ const gitCommonDir = getGitCommonDir();
1744
+ if (gitCommonDir !== ".git") {
1747
1745
  throw new ClawtError(MESSAGES.NOT_MAIN_WORKTREE);
1748
1746
  }
1749
1747
  }
@@ -6044,7 +6042,7 @@ function registerHomeCommand(program2) {
6044
6042
  }
6045
6043
  async function handleHome() {
6046
6044
  if (!isInsideGitRepo()) {
6047
- printError(MESSAGES.NOT_MAIN_WORKTREE);
6045
+ printError(MESSAGES.NOT_GIT_REPO);
6048
6046
  return;
6049
6047
  }
6050
6048
  if (!isMainWorktree()) {
@@ -17,6 +17,8 @@ var PROJECTS_CONFIG_DIR = join(CLAWT_HOME, "projects");
17
17
  var COMMON_MESSAGES = {
18
18
  /** 不在主 worktree 根目录 */
19
19
  NOT_MAIN_WORKTREE: "\u8BF7\u5728\u4E3B worktree \u7684\u6839\u76EE\u5F55\u4E0B\u6267\u884C clawt",
20
+ /** 不在 git 仓库中 */
21
+ NOT_GIT_REPO: "\u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u5148\u6267\u884C git init \u5E76\u63D0\u4EA4\u540E\uFF0C\u518D\u6267\u884C clawt init \u521D\u59CB\u5316\u9879\u76EE",
20
22
  /** Git 未安装 */
21
23
  GIT_NOT_INSTALLED: "Git \u672A\u5B89\u88C5\u6216\u4E0D\u5728 PATH \u4E2D\uFF0C\u8BF7\u5148\u5B89\u88C5 Git",
22
24
  /** Claude Code CLI 未安装 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawt",
3
- "version": "3.8.4",
3
+ "version": "3.8.5",
4
4
  "description": "本地并行执行多个Claude Code Agent任务,融合 Git Worktree 与 Claude Code CLI 的命令行工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -37,7 +37,7 @@ export function registerHomeCommand(program: Command): void {
37
37
  async function handleHome(): Promise<void> {
38
38
  // 场景 1:不在 git 仓库中,直接报错
39
39
  if (!isInsideGitRepo()) {
40
- printError(MESSAGES.NOT_MAIN_WORKTREE);
40
+ printError(MESSAGES.NOT_GIT_REPO);
41
41
  return;
42
42
  }
43
43
 
@@ -2,6 +2,8 @@
2
2
  export const COMMON_MESSAGES = {
3
3
  /** 不在主 worktree 根目录 */
4
4
  NOT_MAIN_WORKTREE: '请在主 worktree 的根目录下执行 clawt',
5
+ /** 不在 git 仓库中 */
6
+ NOT_GIT_REPO: '当前目录不是 git 仓库,请先执行 git init 并提交后,再执行 clawt init 初始化项目',
5
7
  /** Git 未安装 */
6
8
  GIT_NOT_INSTALLED: 'Git 未安装或不在 PATH 中,请先安装 Git',
7
9
  /** Claude Code CLI 未安装 */
@@ -1,7 +1,7 @@
1
1
  import { MESSAGES } from '../constants/index.js';
2
2
  import { ClawtError } from '../errors/index.js';
3
3
  import { execCommand } from './shell.js';
4
- import { getGitCommonDir, isWorkingDirClean } from './git.js';
4
+ import { getGitCommonDir, isInsideGitRepo, isWorkingDirClean } from './git.js';
5
5
  import { requireProjectConfig, guardMainWorkBranchExists } from './project-config.js';
6
6
  import { ensureOnMainWorkBranch } from './validate-branch.js';
7
7
 
@@ -25,20 +25,18 @@ export interface PreCheckOptions {
25
25
 
26
26
  /**
27
27
  * 校验当前目录是否为主 worktree 的根目录
28
- * 条件:git rev-parse --git-common-dir === ".git"
29
- * @throws {ClawtError} 不在主 worktree 根目录时抛出(包括不在 git 仓库中的情况)
28
+ * 先判断是否在 git 仓库中,再判断是否为主 worktree
29
+ * @throws {ClawtError} 不在 git 仓库时抛出 NOT_GIT_REPO
30
+ * @throws {ClawtError} 不在主 worktree 根目录时抛出 NOT_MAIN_WORKTREE
30
31
  */
31
32
  export function validateMainWorktree(): void {
32
- try {
33
- const gitCommonDir = getGitCommonDir();
34
- if (gitCommonDir !== '.git') {
35
- throw new ClawtError(MESSAGES.NOT_MAIN_WORKTREE);
36
- }
37
- } catch (error) {
38
- if (error instanceof ClawtError) {
39
- throw error;
40
- }
41
- // git 命令执行失败,可能不在 git 仓库中
33
+ // 先检查是否在 git 仓库中
34
+ if (!isInsideGitRepo()) {
35
+ throw new ClawtError(MESSAGES.NOT_GIT_REPO);
36
+ }
37
+ // 再检查是否在主 worktree 根目录
38
+ const gitCommonDir = getGitCommonDir();
39
+ if (gitCommonDir !== '.git') {
42
40
  throw new ClawtError(MESSAGES.NOT_MAIN_WORKTREE);
43
41
  }
44
42
  }
@@ -5,6 +5,7 @@ describe('MESSAGES', () => {
5
5
  describe('纯字符串消息', () => {
6
6
  const stringKeys = [
7
7
  'NOT_MAIN_WORKTREE',
8
+ 'NOT_GIT_REPO',
8
9
  'GIT_NOT_INSTALLED',
9
10
  'CLAUDE_NOT_INSTALLED',
10
11
  'NO_WORKTREES',
@@ -5,9 +5,10 @@ vi.mock('../../../src/utils/shell.js', () => ({
5
5
  execCommand: vi.fn(),
6
6
  }));
7
7
 
8
- // mock git(validateMainWorktree 依赖 getGitCommonDir)
8
+ // mock git(validateMainWorktree 依赖 getGitCommonDir 和 isInsideGitRepo
9
9
  vi.mock('../../../src/utils/git.js', () => ({
10
10
  getGitCommonDir: vi.fn(),
11
+ isInsideGitRepo: vi.fn(),
11
12
  }));
12
13
 
13
14
  // mock project-config(runPreChecks 依赖 requireProjectConfig 和 guardMainWorkBranchExists)
@@ -22,30 +23,35 @@ vi.mock('../../../src/logger/index.js', () => ({
22
23
  }));
23
24
 
24
25
  import { execCommand } from '../../../src/utils/shell.js';
25
- import { getGitCommonDir } from '../../../src/utils/git.js';
26
+ import { getGitCommonDir, isInsideGitRepo } from '../../../src/utils/git.js';
26
27
  import { validateMainWorktree, validateGitInstalled, validateClaudeCodeInstalled, validateHeadExists, runPreChecks } from '../../../src/utils/validation.js';
27
28
  import { requireProjectConfig, guardMainWorkBranchExists } from '../../../src/utils/project-config.js';
28
29
  import { ClawtError } from '../../../src/errors/index.js';
29
30
 
30
31
  const mockedExecCommand = vi.mocked(execCommand);
31
32
  const mockedGetGitCommonDir = vi.mocked(getGitCommonDir);
33
+ const mockedIsInsideGitRepo = vi.mocked(isInsideGitRepo);
32
34
  const mockedRequireProjectConfig = vi.mocked(requireProjectConfig);
33
35
  const mockedGuardMainWorkBranchExists = vi.mocked(guardMainWorkBranchExists);
34
36
 
35
37
  describe('validateMainWorktree', () => {
36
- it('.git 返回时正常通过', () => {
38
+ it('在主 worktree 根目录时正常通过', () => {
39
+ mockedIsInsideGitRepo.mockReturnValue(true);
37
40
  mockedGetGitCommonDir.mockReturnValue('.git');
38
41
  expect(() => validateMainWorktree()).not.toThrow();
39
42
  });
40
43
 
41
- it(' .git 时抛出 ClawtError', () => {
44
+ it('在子 worktree 中时抛出 NOT_MAIN_WORKTREE 错误', () => {
45
+ mockedIsInsideGitRepo.mockReturnValue(true);
42
46
  mockedGetGitCommonDir.mockReturnValue('/path/to/.git');
43
47
  expect(() => validateMainWorktree()).toThrow(ClawtError);
48
+ expect(() => validateMainWorktree()).toThrow('请在主 worktree 的根目录下执行 clawt');
44
49
  });
45
50
 
46
- it('命令失败时抛出 ClawtError', () => {
47
- mockedGetGitCommonDir.mockImplementation(() => { throw new Error('not a git repo'); });
51
+ it('不在 git 仓库中时抛出 NOT_GIT_REPO 错误', () => {
52
+ mockedIsInsideGitRepo.mockReturnValue(false);
48
53
  expect(() => validateMainWorktree()).toThrow(ClawtError);
54
+ expect(() => validateMainWorktree()).toThrow('当前目录不是 git 仓库');
49
55
  });
50
56
  });
51
57
 
@@ -87,6 +93,7 @@ describe('validateHeadExists', () => {
87
93
 
88
94
  describe('runPreChecks', () => {
89
95
  it('按选项组合调用对应校验', () => {
96
+ mockedIsInsideGitRepo.mockReturnValue(true);
90
97
  mockedGetGitCommonDir.mockReturnValue('.git');
91
98
  mockedExecCommand.mockReturnValue('abc1234');
92
99
  mockedRequireProjectConfig.mockReturnValue({ clawtMainWorkBranch: 'main' });