feat: 工具层及 mcp 大重构 (#252)

* feat: 第一版大重构

* fix: 修复类型问题

* chore: 更新版本到 1.3.2

* Add brave as alternative WebSearchTool

* fix: 修正顺序

* fix: 修复对穷鬼模式的 auto dream 和 session memory 越过

* feat: 穷鬼模式去除 session-summary

* feat: 创建 builtin-tools 包,搬运所有工具实现

将 src/tools/ 下的全部 60 个工具目录迁移至 packages/builtin-tools/src/tools/,
内部导入路径已更新为 src/ alias 模式。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: 更新 src/ 中所有工具引用至 builtin-tools 包,删除 src/tools/

- src/tools.ts 及 178 个 src/ 文件的 import 路径从 ./tools/ 改为 builtin-tools/tools/
- 删除 src/tools/ 整个目录(已迁移至 packages/builtin-tools/)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: 添加 builtin-tools 路径别名至 tsconfig,更新 bun.lock

- tsconfig.json 新增 builtin-tools/* 和 builtin-tools 路径映射
- 新增 packages/builtin-tools/src 至 include

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: 为 builtin-tools、mcp-client、agent-tools 添加 @claude-code-best 作用域前缀

所有包名及 import 路径统一添加 @claude-code-best/ 前缀:
- builtin-tools → @claude-code-best/builtin-tools
- mcp-client → @claude-code-best/mcp-client
- agent-tools → @claude-code-best/agent-tools

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: 修复 node 环境没有 bun 的问题

---------

Co-authored-by: Eric-Guo <eric.guocz@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-13 09:52:05 +08:00
committed by GitHub
parent bbb8b613a9
commit 2fb1c9dcd8
559 changed files with 9346 additions and 1837 deletions

View File

@@ -0,0 +1,195 @@
import { describe, expect, test } from "bun:test";
import { parseGitCommitId, detectGitOperation } from "../gitOperationTracking";
describe("parseGitCommitId", () => {
test("extracts commit hash from git commit output", () => {
expect(parseGitCommitId("[main abc1234] fix: some message")).toBe("abc1234");
});
test("extracts hash from root commit output", () => {
expect(
parseGitCommitId("[main (root-commit) abc1234] initial commit")
).toBe("abc1234");
});
test("returns undefined for non-commit output", () => {
expect(parseGitCommitId("nothing to commit")).toBeUndefined();
});
test("handles various branch name formats", () => {
expect(parseGitCommitId("[feature/foo abc1234] message")).toBe("abc1234");
expect(parseGitCommitId("[fix/bar-baz abc1234] message")).toBe("abc1234");
expect(parseGitCommitId("[v1.0.0 abc1234] message")).toBe("abc1234");
});
test("returns undefined for empty string", () => {
expect(parseGitCommitId("")).toBeUndefined();
});
});
describe("detectGitOperation", () => {
test("detects git commit operation", () => {
const result = detectGitOperation(
"git commit -m 'fix bug'",
"[main abc1234] fix bug"
);
expect(result.commit).toBeDefined();
expect(result.commit!.sha).toBe("abc123");
expect(result.commit!.kind).toBe("committed");
});
test("detects git commit --amend operation", () => {
const result = detectGitOperation(
"git commit --amend -m 'updated'",
"[main def5678] updated"
);
expect(result.commit).toBeDefined();
expect(result.commit!.kind).toBe("amended");
});
test("detects git cherry-pick operation", () => {
const result = detectGitOperation(
"git cherry-pick abc1234",
"[main def5678] cherry picked commit"
);
expect(result.commit).toBeDefined();
expect(result.commit!.kind).toBe("cherry-picked");
});
test("detects git push operation", () => {
const result = detectGitOperation(
"git push origin main",
" abc1234..def5678 main -> main"
);
expect(result.push).toBeDefined();
expect(result.push!.branch).toBe("main");
});
test("detects git merge operation", () => {
const result = detectGitOperation(
"git merge feature-branch",
"Merge made by the 'ort' strategy."
);
expect(result.branch).toBeDefined();
expect(result.branch!.action).toBe("merged");
expect(result.branch!.ref).toBe("feature-branch");
});
test("detects git rebase operation", () => {
const result = detectGitOperation(
"git rebase main",
"Successfully rebased and updated refs/heads/feature."
);
expect(result.branch).toBeDefined();
expect(result.branch!.action).toBe("rebased");
expect(result.branch!.ref).toBe("main");
});
test("returns null for non-git commands", () => {
const result = detectGitOperation("ls -la", "total 100\ndrwxr-xr-x");
expect(result.commit).toBeUndefined();
expect(result.push).toBeUndefined();
expect(result.branch).toBeUndefined();
expect(result.pr).toBeUndefined();
});
test("detects gh pr create operation", () => {
const result = detectGitOperation(
"gh pr create --title 'fix' --body 'desc'",
"https://github.com/owner/repo/pull/42"
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("created");
});
test("detects gh pr merge operation", () => {
const result = detectGitOperation(
"gh pr merge 42",
"✓ Merged pull request owner/repo#42"
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("merged");
});
test("handles git commit with -c options", () => {
const result = detectGitOperation(
"git -c commit.gpgsign=false commit -m 'msg'",
"[main aaa1111] msg"
);
expect(result.commit).toBeDefined();
expect(result.commit!.sha).toBe("aaa111");
});
test("detects fast-forward merge", () => {
const result = detectGitOperation(
"git merge develop",
"Fast-forward\n file.txt | 1 +\n 1 file changed"
);
expect(result.branch).toBeDefined();
expect(result.branch!.action).toBe("merged");
expect(result.branch!.ref).toBe("develop");
});
test("detects gh pr edit operation", () => {
const result = detectGitOperation(
"gh pr edit 42 --title 'new title'",
"https://github.com/owner/repo/pull/42"
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("edited");
});
test("detects gh pr comment operation", () => {
const result = detectGitOperation(
"gh pr comment 42 --body 'looks good'",
"https://github.com/owner/repo/pull/42"
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("commented");
});
test("detects gh pr close operation", () => {
const result = detectGitOperation(
"gh pr close 42",
"✓ Closed pull request owner/repo#42"
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("closed");
});
test("detects gh pr ready operation", () => {
const result = detectGitOperation(
"gh pr ready 42",
"✓ Converted pull request owner/repo#42 to \"Ready for review\""
);
expect(result.pr).toBeDefined();
expect(result.pr!.number).toBe(42);
expect(result.pr!.action).toBe("ready");
});
test("handles empty command string", () => {
const result = detectGitOperation("", "some output");
expect(result.commit).toBeUndefined();
expect(result.push).toBeUndefined();
expect(result.branch).toBeUndefined();
expect(result.pr).toBeUndefined();
});
test("handles empty output string", () => {
const result = detectGitOperation("git commit -m 'msg'", "");
expect(result.commit).toBeUndefined();
});
test("handles malformed git commit output", () => {
const result = detectGitOperation(
"git commit -m 'msg'",
"error: something went wrong"
);
expect(result.commit).toBeUndefined();
});
});