Skip to content

Commit 4c0a655

Browse files
feat: 大规模清理 claude 的类型问题及依赖
1 parent 2c759fe commit 4c0a655

38 files changed

Lines changed: 1154 additions & 718 deletions

CLAUDE.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a **reverse-engineered / decompiled** version of Anthropic's official Claude Code CLI tool. The goal is to restore core functionality while trimming secondary capabilities. Many modules are stubbed or feature-flagged off. The codebase has ~1341 tsc errors from decompilation (mostly `unknown`/`never`/`{}` types) — these do **not** block Bun runtime execution.
8+
9+
## Commands
10+
11+
```bash
12+
# Install dependencies
13+
bun install
14+
15+
# Dev mode (direct execution via Bun)
16+
bun run dev
17+
# equivalent to: bun run src/entrypoints/cli.tsx
18+
19+
# Pipe mode
20+
echo "say hello" | bun run src/entrypoints/cli.tsx -p
21+
22+
# Build (outputs dist/cli.js, ~25MB)
23+
bun run build
24+
```
25+
26+
No test runner is configured. No linter is configured.
27+
28+
## Architecture
29+
30+
### Runtime & Build
31+
32+
- **Runtime**: Bun (not Node.js). All imports, builds, and execution use Bun APIs.
33+
- **Build**: `bun build src/entrypoints/cli.tsx --outdir dist --target bun` — single-file bundle.
34+
- **Module system**: ESM (`"type": "module"`), TSX with `react-jsx` transform.
35+
- **Monorepo**: Bun workspaces — internal packages live in `packages/` resolved via `workspace:*`.
36+
37+
### Entry & Bootstrap
38+
39+
1. **`src/entrypoints/cli.tsx`** — True entrypoint. Injects runtime polyfills at the top:
40+
- `feature()` always returns `false` (all feature flags disabled, skipping unimplemented branches).
41+
- `globalThis.MACRO` — simulates build-time macro injection (VERSION, BUILD_TIME, etc.).
42+
- `BUILD_TARGET`, `BUILD_ENV`, `INTERFACE_TYPE` globals.
43+
2. **`src/main.tsx`** — Commander.js CLI definition. Parses args, initializes services (auth, analytics, policy), then launches the REPL or runs in pipe mode.
44+
3. **`src/entrypoints/init.ts`** — One-time initialization (telemetry, config, trust dialog).
45+
46+
### Core Loop
47+
48+
- **`src/query.ts`** — The main API query function. Sends messages to Claude API, handles streaming responses, processes tool calls, and manages the conversation turn loop.
49+
- **`src/QueryEngine.ts`** — Higher-level orchestrator wrapping `query()`. Manages conversation state, compaction, file history snapshots, attribution, and turn-level bookkeeping. Used by the REPL screen.
50+
- **`src/screens/REPL.tsx`** — The interactive REPL screen (React/Ink component). Handles user input, message display, tool permission prompts, and keyboard shortcuts.
51+
52+
### API Layer
53+
54+
- **`src/services/api/claude.ts`** — Core API client. Builds request params (system prompt, messages, tools, betas), calls the Anthropic SDK streaming endpoint, and processes `BetaRawMessageStreamEvent` events.
55+
- Supports multiple providers: Anthropic direct, AWS Bedrock, Google Vertex, Azure.
56+
- Provider selection in `src/utils/model/providers.ts`.
57+
58+
### Tool System
59+
60+
- **`src/Tool.ts`** — Tool interface definition (`Tool` type) and utilities (`findToolByName`, `toolMatchesName`).
61+
- **`src/tools.ts`** — Tool registry. Assembles the tool list; some tools are conditionally loaded via `feature()` flags or `process.env.USER_TYPE`.
62+
- **`src/tools/<ToolName>/`** — Each tool in its own directory (e.g., `BashTool`, `FileEditTool`, `GrepTool`, `AgentTool`).
63+
- Tools define: `name`, `description`, `inputSchema` (JSON Schema), `call()` (execution), and optionally a React component for rendering results.
64+
65+
### UI Layer (Ink)
66+
67+
- **`src/ink.ts`** — Ink render wrapper with ThemeProvider injection.
68+
- **`src/ink/`** — Custom Ink framework (forked/internal): custom reconciler, hooks (`useInput`, `useTerminalSize`, `useSearchHighlight`), virtual list rendering.
69+
- **`src/components/`** — React components rendered in terminal via Ink. Key ones:
70+
- `App.tsx` — Root provider (AppState, Stats, FpsMetrics).
71+
- `Messages.tsx` / `MessageRow.tsx` — Conversation message rendering.
72+
- `PromptInput/` — User input handling.
73+
- `permissions/` — Tool permission approval UI.
74+
- Components use React Compiler runtime (`react/compiler-runtime`) — decompiled output has `_c()` memoization calls throughout.
75+
76+
### State Management
77+
78+
- **`src/state/AppState.tsx`** — Central app state type and context provider. Contains messages, tools, permissions, MCP connections, etc.
79+
- **`src/state/store.ts`** — Zustand-style store for AppState.
80+
- **`src/bootstrap/state.ts`** — Module-level singletons for session-global state (session ID, CWD, project root, token counts).
81+
82+
### Context & System Prompt
83+
84+
- **`src/context.ts`** — Builds system/user context for the API call (git status, date, CLAUDE.md contents, memory files).
85+
- **`src/utils/claudemd.ts`** — Discovers and loads CLAUDE.md files from project hierarchy.
86+
87+
### Feature Flag System
88+
89+
All `feature('FLAG_NAME')` calls come from `bun:bundle` (a build-time API). In this decompiled version, `feature()` is polyfilled to always return `false` in `cli.tsx`. This means all Anthropic-internal features (COORDINATOR_MODE, KAIROS, PROACTIVE, etc.) are disabled.
90+
91+
### Stubbed/Deleted Modules
92+
93+
| Module | Status |
94+
|--------|--------|
95+
| Computer Use (`@ant/*`) | Stub packages in `packages/@ant/` |
96+
| `*-napi` packages (audio, image, url, modifiers) | Stubs in `packages/` (except `color-diff-napi` which is fully implemented) |
97+
| Analytics / GrowthBook / Sentry | Empty implementations |
98+
| Magic Docs / Voice Mode / LSP Server | Removed |
99+
| Plugins / Marketplace | Removed |
100+
| MCP OAuth | Simplified |
101+
102+
### Key Type Files
103+
104+
- **`src/types/global.d.ts`** — Declares `MACRO`, `BUILD_TARGET`, `BUILD_ENV` and internal Anthropic-only identifiers.
105+
- **`src/types/internal-modules.d.ts`** — Type declarations for `bun:bundle`, `bun:ffi`, `@anthropic-ai/mcpb`.
106+
- **`src/types/message.ts`** — Message type hierarchy (UserMessage, AssistantMessage, SystemMessage, etc.).
107+
- **`src/types/permissions.ts`** — Permission mode and result types.
108+
109+
## Working with This Codebase
110+
111+
- **Don't try to fix all tsc errors** — they're from decompilation and don't affect runtime.
112+
- **`feature()` is always `false`** — any code behind a feature flag is dead code in this build.
113+
- **React Compiler output** — Components have decompiled memoization boilerplate (`const $ = _c(N)`). This is normal.
114+
- **`bun:bundle` import** — In `src/main.tsx` and other files, `import { feature } from 'bun:bundle'` works at build time. At dev-time, the polyfill in `cli.tsx` provides it.
115+
- **`src/` path alias** — tsconfig maps `src/*` to `./src/*`. Imports like `import { ... } from 'src/utils/...'` are valid.

package.json

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,111 +18,111 @@
1818
"@ant/computer-use-mcp": "workspace:*",
1919
"@ant/computer-use-swift": "workspace:*",
2020
"@anthropic-ai/bedrock-sdk": "^0.26.4",
21-
"@anthropic-ai/claude-agent-sdk": "latest",
21+
"@anthropic-ai/claude-agent-sdk": "^0.2.87",
2222
"@anthropic-ai/foundry-sdk": "^0.2.3",
23-
"@anthropic-ai/mcpb": "latest",
24-
"@anthropic-ai/sandbox-runtime": "latest",
25-
"@anthropic-ai/sdk": "latest",
23+
"@anthropic-ai/mcpb": "^2.1.2",
24+
"@anthropic-ai/sandbox-runtime": "^0.0.44",
25+
"@anthropic-ai/sdk": "^0.80.0",
2626
"@anthropic-ai/vertex-sdk": "^0.14.4",
27-
"@aws-sdk/client-bedrock": "latest",
28-
"@aws-sdk/client-bedrock-runtime": "latest",
27+
"@aws-sdk/client-bedrock": "^3.1020.0",
28+
"@aws-sdk/client-bedrock-runtime": "^3.1020.0",
2929
"@aws-sdk/client-sts": "^3.1020.0",
3030
"@aws-sdk/credential-provider-node": "^3.972.28",
31-
"@aws-sdk/credential-providers": "latest",
31+
"@aws-sdk/credential-providers": "^3.1020.0",
3232
"@azure/identity": "^4.13.1",
33-
"@commander-js/extra-typings": "latest",
34-
"@growthbook/growthbook": "latest",
35-
"@modelcontextprotocol/sdk": "latest",
36-
"@opentelemetry/api": "latest",
37-
"@opentelemetry/api-logs": "latest",
38-
"@opentelemetry/core": "latest",
39-
"@opentelemetry/exporter-logs-otlp-grpc": "latest",
40-
"@opentelemetry/exporter-logs-otlp-http": "latest",
33+
"@commander-js/extra-typings": "^14.0.0",
34+
"@growthbook/growthbook": "^1.6.5",
35+
"@modelcontextprotocol/sdk": "^1.29.0",
36+
"@opentelemetry/api": "^1.9.1",
37+
"@opentelemetry/api-logs": "^0.214.0",
38+
"@opentelemetry/core": "^2.6.1",
39+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.214.0",
40+
"@opentelemetry/exporter-logs-otlp-http": "^0.214.0",
4141
"@opentelemetry/exporter-logs-otlp-proto": "^0.214.0",
42-
"@opentelemetry/exporter-metrics-otlp-grpc": "latest",
43-
"@opentelemetry/exporter-metrics-otlp-http": "latest",
42+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.214.0",
43+
"@opentelemetry/exporter-metrics-otlp-http": "^0.214.0",
4444
"@opentelemetry/exporter-metrics-otlp-proto": "^0.214.0",
45-
"@opentelemetry/exporter-prometheus": "latest",
46-
"@opentelemetry/exporter-trace-otlp-grpc": "latest",
47-
"@opentelemetry/exporter-trace-otlp-http": "latest",
45+
"@opentelemetry/exporter-prometheus": "^0.214.0",
46+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
47+
"@opentelemetry/exporter-trace-otlp-http": "^0.214.0",
4848
"@opentelemetry/exporter-trace-otlp-proto": "^0.214.0",
49-
"@opentelemetry/resources": "latest",
50-
"@opentelemetry/sdk-logs": "latest",
51-
"@opentelemetry/sdk-metrics": "latest",
52-
"@opentelemetry/sdk-trace-base": "latest",
53-
"@opentelemetry/semantic-conventions": "latest",
54-
"@smithy/core": "latest",
55-
"@smithy/node-http-handler": "latest",
56-
"ajv": "latest",
57-
"asciichart": "latest",
49+
"@opentelemetry/resources": "^2.6.1",
50+
"@opentelemetry/sdk-logs": "^0.214.0",
51+
"@opentelemetry/sdk-metrics": "^2.6.1",
52+
"@opentelemetry/sdk-trace-base": "^2.6.1",
53+
"@opentelemetry/semantic-conventions": "^1.40.0",
54+
"@smithy/core": "^3.23.13",
55+
"@smithy/node-http-handler": "^4.5.1",
56+
"ajv": "^8.18.0",
57+
"asciichart": "^1.5.25",
5858
"audio-capture-napi": "workspace:*",
59-
"auto-bind": "latest",
60-
"axios": "latest",
61-
"bidi-js": "latest",
59+
"auto-bind": "^5.0.1",
60+
"axios": "^1.14.0",
61+
"bidi-js": "^1.0.3",
6262
"cacache": "^20.0.4",
63-
"chalk": "latest",
64-
"chokidar": "latest",
65-
"cli-boxes": "latest",
63+
"chalk": "^5.6.2",
64+
"chokidar": "^5.0.0",
65+
"cli-boxes": "^4.0.1",
6666
"cli-highlight": "^2.1.11",
67-
"code-excerpt": "latest",
67+
"code-excerpt": "^4.0.0",
6868
"color-diff-napi": "workspace:*",
69-
"diff": "latest",
70-
"emoji-regex": "latest",
71-
"env-paths": "latest",
72-
"execa": "latest",
73-
"fflate": "latest",
74-
"figures": "latest",
75-
"fuse.js": "latest",
76-
"get-east-asian-width": "latest",
77-
"google-auth-library": "latest",
78-
"highlight.js": "latest",
79-
"https-proxy-agent": "latest",
80-
"ignore": "latest",
69+
"diff": "^8.0.4",
70+
"emoji-regex": "^10.6.0",
71+
"env-paths": "^4.0.0",
72+
"execa": "^9.6.1",
73+
"fflate": "^0.8.2",
74+
"figures": "^6.1.0",
75+
"fuse.js": "^7.1.0",
76+
"get-east-asian-width": "^1.5.0",
77+
"google-auth-library": "^10.6.2",
78+
"highlight.js": "^11.11.1",
79+
"https-proxy-agent": "^8.0.0",
80+
"ignore": "^7.0.5",
8181
"image-processor-napi": "workspace:*",
82-
"indent-string": "latest",
82+
"indent-string": "^5.0.0",
8383
"jsonc-parser": "^3.3.1",
84-
"lodash-es": "latest",
85-
"lru-cache": "latest",
86-
"marked": "latest",
84+
"lodash-es": "^4.17.23",
85+
"lru-cache": "^11.2.7",
86+
"marked": "^17.0.5",
8787
"modifiers-napi": "workspace:*",
88-
"p-map": "latest",
89-
"picomatch": "latest",
88+
"p-map": "^7.0.4",
89+
"picomatch": "^4.0.4",
9090
"plist": "^3.1.0",
91-
"proper-lockfile": "latest",
92-
"qrcode": "latest",
93-
"react": "latest",
91+
"proper-lockfile": "^4.1.2",
92+
"qrcode": "^1.5.4",
93+
"react": "^19.2.4",
9494
"react-compiler-runtime": "^1.0.0",
95-
"react-reconciler": "latest",
96-
"semver": "latest",
95+
"react-reconciler": "^0.33.0",
96+
"semver": "^7.7.4",
9797
"sharp": "^0.34.5",
98-
"shell-quote": "latest",
99-
"signal-exit": "latest",
100-
"stack-utils": "latest",
101-
"strip-ansi": "latest",
102-
"supports-hyperlinks": "latest",
103-
"tree-kill": "latest",
98+
"shell-quote": "^1.8.3",
99+
"signal-exit": "^4.1.0",
100+
"stack-utils": "^2.0.6",
101+
"strip-ansi": "^7.2.0",
102+
"supports-hyperlinks": "^4.4.0",
103+
"tree-kill": "^1.2.2",
104104
"turndown": "^7.2.2",
105-
"type-fest": "latest",
106-
"undici": "latest",
105+
"type-fest": "^5.5.0",
106+
"undici": "^7.24.6",
107107
"url-handler-napi": "workspace:*",
108-
"usehooks-ts": "latest",
109-
"vscode-jsonrpc": "latest",
110-
"vscode-languageserver-protocol": "latest",
111-
"vscode-languageserver-types": "latest",
112-
"wrap-ansi": "latest",
113-
"ws": "latest",
114-
"xss": "latest",
108+
"usehooks-ts": "^3.1.1",
109+
"vscode-jsonrpc": "^8.2.1",
110+
"vscode-languageserver-protocol": "^3.17.5",
111+
"vscode-languageserver-types": "^3.17.5",
112+
"wrap-ansi": "^10.0.0",
113+
"ws": "^8.20.0",
114+
"xss": "^1.0.15",
115115
"yaml": "^2.8.3",
116-
"zod": "latest"
116+
"zod": "^4.3.6"
117117
},
118118
"devDependencies": {
119119
"@types/bun": "^1.3.11",
120120
"@types/cacache": "^20.0.1",
121121
"@types/plist": "^3.0.5",
122-
"@types/react": "latest",
123-
"@types/react-reconciler": "latest",
122+
"@types/react": "^19.2.14",
123+
"@types/react-reconciler": "^0.33.0",
124124
"@types/sharp": "^0.32.0",
125125
"@types/turndown": "^5.0.6",
126-
"typescript": "latest"
126+
"typescript": "^6.0.2"
127127
}
128128
}

0 commit comments

Comments
 (0)