From 9a57642d3a147fdf877ad1273f4875192678a318 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Wed, 1 Apr 2026 10:42:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E5=8F=AF=E6=9E=84=E5=BB=BA=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 +++++-------- build.ts | 47 ++++++++++++++++++++++++++++ package.json | 2 +- packages/modifiers-napi/src/index.ts | 9 +++--- 4 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 build.ts diff --git a/README.md b/README.md index 209d6a0..175d69b 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,22 @@ Anthropic 官方 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI 工具的源码反编译/逆向还原项目。目标是将 Claude Code 大部分功能及工程化能力复现。虽然很难绷, 但是它叫做 CCB(踩踩背)... -> V1 会完成跑通及基本的类型检查通过; +> V1 会完成跑通及基本的类型检查通过; > -> V2 会完整实现工程化配套设施; +> V2 会完整实现工程化配套设施; > -> V3 会实现多层级解耦, 很多比如 UI 包, Agent 包都可以独立优化; +> V3 会实现多层级解耦, 很多比如 UI 包, Agent 包都可以独立优化; > > V4 会完成大量的测试文件, 以提高稳定性 > > 我不知道这个项目还会存在多久, fork 不好使, git clone 或者下载 .zip 包才稳健; -> +> > 这个项目更新很快, 后台有 Opus 持续优化, 所以你可以提 issues, 但是 PR 暂时不会接受; > > 存活记录: > 开源后 12 小时: 愚人节, star 破 1k, 并且牢 A 没有发邮件搞这个项目 > -> 如果你想要私人咨询服务, 那么可以发送邮件到 claude-code-best@proton.me, 备注咨询与联系方式即可; 由于后续工作非常多, 可能会忽略邮件, 半天没回复, 可以多发; +> 如果你想要私人咨询服务, 那么可以发送邮件到 , 备注咨询与联系方式即可; 由于后续工作非常多, 可能会忽略邮件, 半天没回复, 可以多发; ## 快速开始 @@ -26,8 +26,7 @@ Anthropic 官方 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) C 一定要最新版本的 bun 啊, 不然一堆奇奇怪怪的 BUG!!! bun upgrade!!! - [Bun](https://bun.sh/) >= 1.3.11 -- Node.js >= 18(部分依赖需要) -- 有效的 Anthropic API Key(或 Bedrock / Vertex 凭据) +- 常规的配置 CC 的方式, 各大提供商都有自己的配置方式 ### 安装 @@ -41,17 +40,11 @@ bun install # 开发模式, 看到版本号 888 说明就是对了 bun run dev -# 直接运行 -bun run src/entrypoints/cli.tsx - -# 管道模式(-p) -echo "say hello" | bun run src/entrypoints/cli.tsx -p - # 构建 bun run build ``` -构建产物输出到 `dist/cli.js`(~25.75 MB,5326 模块)。 +构建产物会输出到 `dist/cli.js`, 构建出的版本 bun 和 node 都可以启动, 你 publish 到私有源可以直接启动 ## 能力清单 @@ -302,7 +295,6 @@ bun run build `ABLATION_BASELINE` `AGENT_MEMORY_SNAPSHOT` `BG_SESSIONS` `BRIDGE_MODE` `BUDDY` `CCR_MIRROR` `CCR_REMOTE_SETUP` `CHICAGO_MCP` `COORDINATOR_MODE` `DAEMON` `DIRECT_CONNECT` `EXPERIMENTAL_SKILL_SEARCH` `FORK_SUBAGENT` `HARD_FAIL` `HISTORY_SNIP` `KAIROS` `KAIROS_BRIEF` `KAIROS_CHANNELS` `KAIROS_GITHUB_WEBHOOKS` `LODESTONE` `MCP_SKILLS` `PROACTIVE` `SSH_REMOTE` `TORCH` `TRANSCRIPT_CLASSIFIER` `UDS_INBOX` `ULTRAPLAN` `UPLOAD_USER_SETTINGS` `VOICE_MODE` `WEB_BROWSER_TOOL` `WORKFLOW_SCRIPTS` - ## 项目结构 ``` diff --git a/build.ts b/build.ts new file mode 100644 index 0000000..85b2b20 --- /dev/null +++ b/build.ts @@ -0,0 +1,47 @@ +import { readdir, readFile, writeFile } from "fs/promises"; +import { join } from "path"; + +const outdir = "dist"; + +// Step 1: Clean output directory +const { rmSync } = await import("fs"); +rmSync(outdir, { recursive: true, force: true }); + +// Step 2: Bundle with splitting +const result = await Bun.build({ + entrypoints: ["src/entrypoints/cli.tsx"], + outdir, + target: "bun", + splitting: true, +}); + +if (!result.success) { + console.error("Build failed:"); + for (const log of result.logs) { + console.error(log); + } + process.exit(1); +} + +// Step 3: Post-process — replace Bun-only `import.meta.require` with Node.js compatible version +const files = await readdir(outdir); +const IMPORT_META_REQUIRE = "var __require = import.meta.require;"; +const COMPAT_REQUIRE = `var __require = typeof import.meta.require === "function" ? import.meta.require : (await import("module")).createRequire(import.meta.url);`; + +let patched = 0; +for (const file of files) { + if (!file.endsWith(".js")) continue; + const filePath = join(outdir, file); + const content = await readFile(filePath, "utf-8"); + if (content.includes(IMPORT_META_REQUIRE)) { + await writeFile( + filePath, + content.replace(IMPORT_META_REQUIRE, COMPAT_REQUIRE), + ); + patched++; + } +} + +console.log( + `Bundled ${result.outputs.length} files to ${outdir}/ (patched ${patched} for Node.js compat)`, +); diff --git a/package.json b/package.json index 884b141..1346a97 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dist" ], "scripts": { - "build": "bun build src/entrypoints/cli.tsx --outdir dist --target bun", + "build": "bun run build.ts", "dev": "bun run src/entrypoints/cli.tsx", "prepublishOnly": "bun run build", "lint": "biome lint src/", diff --git a/packages/modifiers-napi/src/index.ts b/packages/modifiers-napi/src/index.ts index 61509cd..a5cba59 100644 --- a/packages/modifiers-napi/src/index.ts +++ b/packages/modifiers-napi/src/index.ts @@ -1,5 +1,3 @@ -import { dlopen, FFIType, suffix } from "bun:ffi"; - const FLAG_SHIFT = 0x20000; const FLAG_CONTROL = 0x40000; const FLAG_OPTION = 0x80000; @@ -23,12 +21,13 @@ function loadFFI(): void { } try { - const lib = dlopen( + const ffi = require("bun:ffi") as typeof import("bun:ffi"); + const lib = ffi.dlopen( `/System/Library/Frameworks/Carbon.framework/Carbon`, { CGEventSourceFlagsState: { - args: [FFIType.i32], - returns: FFIType.u64, + args: [ffi.FFIType.i32], + returns: ffi.FFIType.u64, }, } );