-
Notifications
You must be signed in to change notification settings - Fork 15.9k
feat: restore buddy companion system (Phase 1) #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
97d9294
Initial backup: claude-code project
ac3382f
Overlay with amDosion/claude-code-bast main branch
4f9551e
chore: 清理本地多余文件,与远程 origin/main 保持一致
73e545d
Overlay with upstream claude-code-best/claude-code main branch
4979b03
feat: add built-in status line with usage quota, token counts, and co…
42168dd
refactor: built-in only status line with review fixes
edf2094
backup: 保存 buddy 系统文档和当前工作状态
b9db0fb
feat: restore buddy companion system (Phase 1 local-only)
ea505f9
feat: integrate upstream buddy + add off/on aliases and observer
e63c837
fix: remove TRANSCRIPT_CLASSIFIER from default features
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule anthropic-skills
added at
98669c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(git rm:*)", | ||
| "Bash(git commit:*)", | ||
| "Bash(grep -ri buddy /mnt/user/appdata/claude-code/src/ --include=*.ts --include=*.tsx --include=*.js -l)", | ||
| "Bash(grep -ri buddy /mnt/user/appdata/claude-code/ --include=*.md --include=*.json -l)", | ||
| "Bash(git remote:*)", | ||
| "Bash(git fetch:*)", | ||
| "Bash(git merge:*)", | ||
| "Bash(grep -rn \"getSettings_DEPRECATED\\\\|getSettingsForSource\\\\|useSettings\\\\b\" /mnt/user/appdata/claude-code/src/hooks/useSettings.ts /mnt/user/appdata/claude-code/src/utils/settings/ --include=*.ts --include=*.tsx)", | ||
| "Bash(grep -rn extractQuotaStatusFromHeaders src/ --include=*.ts --include=*.tsx)", | ||
| "Bash(find src/components -name Usage* -o -name usage*)", | ||
| "Bash(find src:*)", | ||
| "Bash(grep -rn \"extractQuotaStatusFromHeaders\\\\|extractQuotaStatusFromError\" src/services/api/ --include=*.ts --include=*.tsx)", | ||
| "Bash(grep -rn \"getRawUtilization\\\\|checkQuotaStatus\" /mnt/user/appdata/claude-code/src/ --include=*.ts --include=*.tsx)", | ||
| "Bash(grep -n TerminalSize /mnt/user/appdata/claude-code/src/ink/components/TerminalSizeContext.ts*)", | ||
| "Bash(ls /mnt/user/appdata/claude-code/src/components/BuiltinStatusLine*)", | ||
| "Bash(ls /mnt/user/appdata/claude-code/src/components/Builtin*)", | ||
| "Bash(grep -r export.*formatCountdown src/components/)", | ||
| "Bash(bun test:*)", | ||
| "Bash(bun run:*)", | ||
| "Bash(npx biome:*)", | ||
| "Bash(git status:*)", | ||
| "Bash(git add:*)", | ||
| "Bash(gh --version)", | ||
| "Bash(gh auth:*)", | ||
| "Bash(curl -sL https://github.com/cli/cli/releases/latest/download/gh_2.74.1_linux_amd64.tar.gz -o /tmp/gh.tar.gz)", | ||
| "Bash(tar -xzf /tmp/gh.tar.gz -C /tmp)", | ||
| "Read(//tmp/**)", | ||
| "Bash(curl -sI https://github.com/cli/cli/releases/latest)", | ||
| "Bash(curl -sL \"https://github.com/cli/cli/releases/download/v2.89.0/gh_2.89.0_linux_amd64.tar.gz\" -o /tmp/gh.tar.gz)", | ||
| "Bash(cp /tmp/gh_2.89.0_linux_amd64/bin/gh /usr/local/bin/gh)", | ||
| "Bash(chmod +x /usr/local/bin/gh)", | ||
| "Bash(git checkout:*)", | ||
| "Bash(git cherry-pick:*)", | ||
| "Bash(git push:*)", | ||
| "Bash(gh pr:*)", | ||
| "Bash(gh api:*)", | ||
| "Bash(curl:*)", | ||
| "Bash(ssh:*)", | ||
| "Bash(git reset:*)", | ||
| "WebSearch", | ||
| "Bash(mkdir -p ~/.claude/skills)", | ||
| "Read(//root/.claude/**)", | ||
| "Bash(mkdir -p /mnt/user/appdata/claude-code/.claude/skills)", | ||
| "Bash(git clone:*)", | ||
| "Bash(python3 -m json.tool)", | ||
| "Bash(python3 -c \"import sys,json; data=json.load\\(sys.stdin\\); [print\\(f'''' {d[\"\"name\"\"]}/ \\({d[\"\"type\"\"]}\\)''''\\) for d in data]\")", | ||
| "Bash(python3 -c \"import sys,json; data=json.load\\(sys.stdin\\); [print\\(f'''' {d[\"\"name\"\"]} \\({d[\"\"type\"\"]}\\)''''\\) for d in data]\")", | ||
| "Bash(git pull:*)" | ||
| ] | ||
| } | ||
| } | ||
Submodule anthropic-skills
added at
98669c
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # AGENTS.md | ||
|
|
||
| This file provides guidance to Codex (Codex.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| This is a **reverse-engineered / decompiled** version of Anthropic's official Codex 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. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| bun install | ||
|
|
||
| # Dev mode (runs cli.tsx with MACRO defines injected via -d flags) | ||
| bun run dev | ||
|
|
||
| # Pipe mode | ||
| echo "say hello" | bun run src/entrypoints/cli.tsx -p | ||
|
|
||
| # Build (code splitting, outputs dist/cli.js + ~450 chunk files) | ||
| bun run build | ||
|
|
||
| # Test | ||
| bun test # run all tests | ||
| bun test src/utils/__tests__/hash.test.ts # run single file | ||
| bun test --coverage # with coverage report | ||
|
|
||
| # Lint & Format (Biome) | ||
| bun run lint # check only | ||
| bun run lint:fix # auto-fix | ||
| bun run format # format all src/ | ||
| ``` | ||
|
|
||
| 详细的测试规范、覆盖状态和改进计划见 `docs/testing-spec.md`。 | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Runtime & Build | ||
|
|
||
| - **Runtime**: Bun (not Node.js). All imports, builds, and execution use Bun APIs. | ||
| - **Build**: `build.ts` 执行 `Bun.build()` with `splitting: true`,入口 `src/entrypoints/cli.tsx`,输出 `dist/cli.js` + ~450 chunk files。构建后自动替换 `import.meta.require` 为 Node.js 兼容版本(产物 bun/node 都可运行)。 | ||
| - **Dev mode**: `scripts/dev.ts` 通过 Bun `-d` flag 注入 `MACRO.*` defines,运行 `src/entrypoints/cli.tsx`。`scripts/defines.ts` 集中管理 define map。 | ||
| - **Module system**: ESM (`"type": "module"`), TSX with `react-jsx` transform. | ||
| - **Monorepo**: Bun workspaces — internal packages live in `packages/` resolved via `workspace:*`. | ||
| - **Lint/Format**: Biome (`biome.json`)。`bun run lint` / `bun run lint:fix` / `bun run format`。 | ||
|
|
||
| ### Entry & Bootstrap | ||
|
|
||
| 1. **`src/entrypoints/cli.tsx`** — True entrypoint. Injects runtime polyfills at the top: | ||
| - `feature()` always returns `false` (all feature flags disabled, skipping unimplemented branches). | ||
| - `globalThis.MACRO` — simulates build-time macro injection (VERSION, BUILD_TIME, etc.). | ||
| - `BUILD_TARGET`, `BUILD_ENV`, `INTERFACE_TYPE` globals. | ||
|
Comment on lines
+50
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update feature-flag docs to reflect current Buddy behavior. Lines 50-53 say all 🤖 Prompt for AI Agents |
||
| 2. **`src/main.tsx`** — Commander.js CLI definition. Parses args, initializes services (auth, analytics, policy), then launches the REPL or runs in pipe mode. | ||
| 3. **`src/entrypoints/init.ts`** — One-time initialization (telemetry, config, trust dialog). | ||
|
|
||
| ### Core Loop | ||
|
|
||
| - **`src/query.ts`** — The main API query function. Sends messages to Codex API, handles streaming responses, processes tool calls, and manages the conversation turn loop. | ||
| - **`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. | ||
| - **`src/screens/REPL.tsx`** — The interactive REPL screen (React/Ink component). Handles user input, message display, tool permission prompts, and keyboard shortcuts. | ||
|
|
||
| ### API Layer | ||
|
|
||
| - **`src/services/api/Codex.ts`** — Core API client. Builds request params (system prompt, messages, tools, betas), calls the Anthropic SDK streaming endpoint, and processes `BetaRawMessageStreamEvent` events. | ||
| - Supports multiple providers: Anthropic direct, AWS Bedrock, Google Vertex, Azure. | ||
| - Provider selection in `src/utils/model/providers.ts`. | ||
|
|
||
| ### Tool System | ||
|
|
||
| - **`src/Tool.ts`** — Tool interface definition (`Tool` type) and utilities (`findToolByName`, `toolMatchesName`). | ||
| - **`src/tools.ts`** — Tool registry. Assembles the tool list; some tools are conditionally loaded via `feature()` flags or `process.env.USER_TYPE`. | ||
| - **`src/tools/<ToolName>/`** — Each tool in its own directory (e.g., `BashTool`, `FileEditTool`, `GrepTool`, `AgentTool`). | ||
| - Tools define: `name`, `description`, `inputSchema` (JSON Schema), `call()` (execution), and optionally a React component for rendering results. | ||
|
|
||
| ### UI Layer (Ink) | ||
|
|
||
| - **`src/ink.ts`** — Ink render wrapper with ThemeProvider injection. | ||
| - **`src/ink/`** — Custom Ink framework (forked/internal): custom reconciler, hooks (`useInput`, `useTerminalSize`, `useSearchHighlight`), virtual list rendering. | ||
| - **`src/components/`** — React components rendered in terminal via Ink. Key ones: | ||
| - `App.tsx` — Root provider (AppState, Stats, FpsMetrics). | ||
| - `Messages.tsx` / `MessageRow.tsx` — Conversation message rendering. | ||
| - `PromptInput/` — User input handling. | ||
| - `permissions/` — Tool permission approval UI. | ||
| - Components use React Compiler runtime (`react/compiler-runtime`) — decompiled output has `_c()` memoization calls throughout. | ||
|
|
||
| ### State Management | ||
|
|
||
| - **`src/state/AppState.tsx`** — Central app state type and context provider. Contains messages, tools, permissions, MCP connections, etc. | ||
| - **`src/state/store.ts`** — Zustand-style store for AppState. | ||
| - **`src/bootstrap/state.ts`** — Module-level singletons for session-global state (session ID, CWD, project root, token counts). | ||
|
|
||
| ### Context & System Prompt | ||
|
|
||
| - **`src/context.ts`** — Builds system/user context for the API call (git status, date, AGENTS.md contents, memory files). | ||
| - **`src/utils/claudemd.ts`** — Discovers and loads AGENTS.md files from project hierarchy. | ||
|
|
||
| ### Feature Flag System | ||
|
|
||
| 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. | ||
|
|
||
| ### Stubbed/Deleted Modules | ||
|
|
||
| | Module | Status | | ||
| |--------|--------| | ||
| | Computer Use (`@ant/*`) | Stub packages in `packages/@ant/` | | ||
| | `*-napi` packages (audio, image, url, modifiers) | Stubs in `packages/` (except `color-diff-napi` which is fully implemented) | | ||
| | Analytics / GrowthBook / Sentry | Empty implementations | | ||
| | Magic Docs / Voice Mode / LSP Server | Removed | | ||
| | Plugins / Marketplace | Removed | | ||
| | MCP OAuth | Simplified | | ||
|
|
||
| ### Key Type Files | ||
|
|
||
| - **`src/types/global.d.ts`** — Declares `MACRO`, `BUILD_TARGET`, `BUILD_ENV` and internal Anthropic-only identifiers. | ||
| - **`src/types/internal-modules.d.ts`** — Type declarations for `bun:bundle`, `bun:ffi`, `@anthropic-ai/mcpb`. | ||
| - **`src/types/message.ts`** — Message type hierarchy (UserMessage, AssistantMessage, SystemMessage, etc.). | ||
| - **`src/types/permissions.ts`** — Permission mode and result types. | ||
|
|
||
| ## Testing | ||
|
|
||
| - **框架**: `bun:test`(内置断言 + mock) | ||
| - **单元测试**: 就近放置于 `src/**/__tests__/`,文件名 `<module>.test.ts` | ||
| - **集成测试**: `tests/integration/`,共享 mock/fixture 在 `tests/mocks/` | ||
| - **命名**: `describe("functionName")` + `test("behavior description")`,英文 | ||
| - **Mock 模式**: 对重依赖模块使用 `mock.module()` + `await import()` 解锁(必须内联在测试文件中,不能从共享 helper 导入) | ||
| - **当前状态**: 1286 tests / 67 files / 0 fail(详见 `docs/testing-spec.md` 的覆盖状态表和评分) | ||
|
|
||
| ## Working with This Codebase | ||
|
|
||
| - **Don't try to fix all tsc errors** — they're from decompilation and don't affect runtime. | ||
| - **`feature()` is always `false`** — any code behind a feature flag is dead code in this build. | ||
| - **React Compiler output** — Components have decompiled memoization boilerplate (`const $ = _c(N)`). This is normal. | ||
| - **`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. | ||
| - **`src/` path alias** — tsconfig maps `src/*` to `./src/*`. Imports like `import { ... } from 'src/utils/...'` are valid. | ||
| - **MACRO defines** — 集中管理在 `scripts/defines.ts`。Dev mode 通过 `bun -d` 注入,build 通过 `Bun.build({ define })` 注入。修改版本号等常量只改这个文件。 | ||
| - **构建产物兼容 Node.js** — `build.ts` 会自动后处理 `import.meta.require`,产物可直接用 `node dist/cli.js` 运行。 | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not commit an over-privileged local agent policy.
This checked-in local config grants destructive/network-capable permissions (
git push,ssh, broadcurl, reset/cherry-pick) and hardcodes machine-specific absolute paths. That is a security and portability risk if reused outside one workstation. Please keep this file local-only (gitignored) and commit a minimal least-privilege template instead.🤖 Prompt for AI Agents