Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
restored-src/.claude-sandbox/
restored-src/.claude-verify/
restored-src/.claude-debug-repro/
restored-src/.claude-debug-repro2/
restored-src/tmp-debug*.log
restored-src/print-debug*.log
restored-src/ui-debug.log
restored-src/ui-debug*.log
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,50 @@

本仓库通过 npm 发布包(`@anthropic-ai/claude-code`)内附带的 source map(`cli.js.map`)还原的 TypeScript 源码,版本为 `2.1.88`。

## 运行

当前仓库里真正可直接运行的是 npm 发布包内的打包产物 `package/cli.js`,不是 `restored-src`。

```bash
npm run version:claude
npm start -- --help
```

重新提取源码可直接执行:

```bash
npm run extract
```

`restored-src` 目前仍是还原后的研究素材,不包含完整官方构建配置,不能视为已恢复成可直接编译运行的源码工程。

如果后续目标是把 `restored-src` 也修到可运行,需要继续补官方构建期宏、路径别名以及还原结果里缺失的依赖文件;当前这一步只把仓库修到“可以直接运行打包版 CLI,并能重新提取源码”。

当前仓库也额外提供了 `restored-src` 的最小启动壳,方便继续排查源码工程的运行阻塞:

```bash
cd restored-src
bun run bootstrap:manifests
```

如果在 Windows 上从 `restored-src` 或其子目录直接执行 `bun`,Bun 1.3.7 目前会额外打印一条与仓库根目录相关的伪 `EPERM`:

```text
error: Cannot read file "F:\Projects\claude-code-sourcemap\": EPERM
```

这条噪音不来自 `restored-src` 源码本身;从仓库根目录启动同一入口则不会出现。为了走干净链路,仓库根还提供了无噪音包装脚本:

```bash
bun run restored:help
bun run restored:version
bun run restored:cli -- --bare -p "ping"
bun run version:claude
bun run help
```

它会先为还原出来但缺少 `package.json` 的依赖包生成最小入口清单,再用 Bun 启动入口;这仍然不代表 `restored-src` 已完全恢复为官方可构建工程。

## 来源

- npm 包:[@anthropic-ai/claude-code](https://www.npmjs.com/package/@anthropic-ai/claude-code)
Expand Down
138 changes: 138 additions & 0 deletions agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Agent Guide

## Purpose

This repository is a research workspace for the reconstructed Claude Code `2.1.88` package and its restored TypeScript sources.

There are two distinct runtimes in this repo:

1. `package/`
The extracted npm package build. This is the stable reference runtime.
2. `restored-src/`
The reconstructed source tree. This is the active repair target.

Current work is focused on making `restored-src` usable with a custom Anthropic-compatible API backend.

## Current Status

### Working

- Packaged CLI works from `package/cli.js`
- `restored-src` CLI entry can boot from the repo root
- `bun run restored:help`
- `bun run restored:version`
- `bun run restored:cli -- agents`
- `bun run restored:cli -- mcp list`
- `bun run restored:cli -- auth status`
- `bun run restored:cli -- --print --bare "hello"`

### Important runtime facts

- Start `restored-src` from the repository root, not from inside `restored-src`
- Root wrapper scripts avoid Bun nested-cwd noise on Windows
- `restored-src` now supports a `custom` API provider when `ANTHROPIC_BASE_URL` is set to a non-Anthropic host
- `custom` is treated as Anthropic-compatible for model resolution, but not as Anthropic first-party auth

## Recommended Commands

### Packaged CLI

```powershell
cd F:\Projects\claude-code-sourcemap
npm run start -- --help
npm run version:claude
```

### Restored source CLI

```powershell
cd F:\Projects\claude-code-sourcemap
bun run restored:help
bun run restored:version
bun run restored:cli
```

### Custom API mode

```powershell
cd F:\Projects\claude-code-sourcemap
$env:ANTHROPIC_BASE_URL='https://your-gateway.example.com'
$env:ANTHROPIC_API_KEY='your-key'

bun run restored:cli -- auth status
bun run restored:cli -- -p --bare "hello"
```

## Current Custom API Behavior

The active provider logic is centered in:

- [`restored-src/src/utils/model/providers.ts`](./restored-src/src/utils/model/providers.ts)
- [`restored-src/src/cli/handlers/auth.ts`](./restored-src/src/cli/handlers/auth.ts)
- [`restored-src/src/utils/model/model.ts`](./restored-src/src/utils/model/model.ts)
- [`restored-src/src/utils/model/modelOptions.ts`](./restored-src/src/utils/model/modelOptions.ts)

Rules:

- `firstParty`: official Anthropic API behavior
- `custom`: non-Anthropic `ANTHROPIC_BASE_URL`, still Anthropic-compatible request/model shape
- `bedrock` / `vertex` / `foundry`: cloud provider integrations

In `custom` mode:

- `claude auth login` is intentionally disabled
- OAuth-first startup checks are skipped
- default model resolution follows Anthropic-compatible model strings
- status output reports `apiProvider: "custom"`

## Known Constraints

- This is not the original internal repository structure
- Some build-time macros and generated artifacts were reconstructed or stubbed
- Some dependency manifests under `restored-src/node_modules/` were synthesized to make Bun resolution work
- Custom API support currently assumes Anthropic SDK compatibility, not OpenAI Chat Completions compatibility
- More request-path cleanup may still be needed for betas, tool search, and gateway-specific header handling
- Interactive `bun run restored:cli` still has an unresolved REPL first-frame / Ink rendering issue on Windows terminals
- Recent debug logs show `root.render done` without a corresponding first rendered frame, so the remaining blocker is in the interactive render path rather than provider/auth/bootstrap

## Files Worth Checking First

- [`README.md`](./README.md)
- [`package.json`](./package.json)
- [`restored-src/package.json`](./restored-src/package.json)
- [`restored-src/macro-shim.cjs`](./restored-src/macro-shim.cjs)
- [`restored-src/scripts/synthesize-node-module-manifests.cjs`](./restored-src/scripts/synthesize-node-module-manifests.cjs)
- [`restored-src/src/entrypoints/cli.tsx`](./restored-src/src/entrypoints/cli.tsx)
- [`restored-src/src/main.tsx`](./restored-src/src/main.tsx)

## Editing Guidance

- Prefer improving `restored-src` instead of changing packaged output behavior
- Keep `custom` provider separate from `firstParty`
- Treat `custom` as Anthropic-compatible, not as Bedrock/Vertex/Foundry
- Avoid reintroducing Anthropic OAuth assumptions into `custom` flows
- When validating behavior, prefer repo-root wrapper commands

## Verification Checklist

After making changes related to runtime behavior, verify at least:

```powershell
cd F:\Projects\claude-code-sourcemap

bun run restored:help
bun run restored:version
bun run restored:cli -- auth status
bun run restored:cli -- agents
bun run restored:cli -- mcp list
```

For custom API work, also verify:

```powershell
$env:ANTHROPIC_BASE_URL='https://your-gateway.example.com'
$env:ANTHROPIC_API_KEY='your-key'

bun run restored:cli -- auth status
bun run restored:cli -- -p --bare "hello"
```
1 change: 0 additions & 1 deletion extract-sources.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { SourceMapConsumer } = require('source-map');
const fs = require('fs');
const path = require('path');

Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "claude-code-sourcemap",
"private": true,
"version": "0.1.0",
"description": "Research workspace for the reconstructed Claude Code 2.1.88 package and extracted sources.",
"scripts": {
"extract": "node extract-sources.js",
"claude": "node package/cli.js",
"start": "node package/cli.js",
"version:claude": "node package/cli.js -v",
"restored:cli": "bun --preload ./restored-src/macro-shim.cjs ./restored-src/src/entrypoints/cli.tsx",
"restored:help": "bun --preload ./restored-src/macro-shim.cjs ./restored-src/src/entrypoints/cli.tsx --help",
"restored:version": "bun --preload ./restored-src/macro-shim.cjs ./restored-src/src/entrypoints/cli.tsx --version"
},
"engines": {
"node": ">=18.0.0"
}
}
39 changes: 39 additions & 0 deletions restored-src/macro-shim.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require("fs");
const path = require("path");

function readPackagedVersion() {
try {
const pkgPath = path.join(__dirname, "..", "package", "package.json");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
return {
version: pkg.version || "0.0.0",
packageName: pkg.name || "@anthropic-ai/claude-code",
};
} catch {
return {
version: "0.0.0",
packageName: "@anthropic-ai/claude-code",
};
}
}

const packaged = readPackagedVersion();

globalThis.MACRO = new Proxy(
{
VERSION: packaged.version,
PACKAGE_URL: packaged.packageName,
NATIVE_PACKAGE_URL: packaged.packageName,
FEEDBACK_CHANNEL: "the Claude Code issue tracker",
ISSUES_EXPLAINER: "file an issue in the Claude Code issue tracker",
BUILD_TIME: "",
},
{
get(target, prop) {
if (prop in target) {
return target[prop];
}
return "";
},
},
);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@ant/computer-use-mcp/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@anthropic-ai/mcpb/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@anthropic-ai/sdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@aws-crypto/crc32/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@aws-crypto/sha256-js/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@aws-crypto/util/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions restored-src/node_modules/@aws-sdk/client-sso/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading