yunhe799

My Coding Agent — Development skill for Claude Code

Development community

从零手写的 CLI Coding Agent(TypeScript):Agent 主循环 / 工具层 / 权限闸门 / 上下文压缩 / 多 Agent / MCP / 自治三件套,附 36 条自建评测集.

How to install My Coding Agent

This entry records only its repository, not the path inside it, so there is no exact command to give. Open yunhe799/my-coding-agent and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What My Coding Agent does

从零手写的 CLI Coding Agent(TypeScript):Agent 主循环 / 工具层 / 权限闸门 / 上下文压缩 / 多 Agent / MCP / 自治三件套,附 36 条自建评测集.

Alternatives in Development

  • OpenAI Codex CLI — (Rust implementation) 67.8k ★
  • Vibe Kanban — Get 10X more out of Claude Code, Gemini CLI, Codex, Amp and other coding agents 23.5k ★
  • Mcporter — Call MCPs via TypeScript, masquerading as simple TypeScript API 4.1k ★

README

my-coding-agent

**从零手写的一个命令行 Coding Agent**(TypeScript,12 个模块 / 约 1700 行):自己实现 Agent 主循环、工具层、分层系统提示词、权限闸门、上下文压缩、记忆、技能、Plan 只读模式、多 Agent 子代理、MCP 客户端,以及自治三件套(`/goal` · `/loop` · Auto Mode)。

另外配了一个**自研业务 MCP server**([codebase-archaeology-mcp](../codebase-archaeology-mcp):让 Agent 查代码的历史与决策)和一套**自建评测集**(36 条用例,mock/真模型双轨)。

它和聊天机器人的区别

普通聊天机器人只会回话,**Agent 会自己动手**。

你只说目标、不说步骤;它自己决定读哪个文件、改哪一行、跑什么命令,并用闸门保证不会乱来。

架构

用户输入
   ↓
cli.ts      加载 .env · 技能展开(/xxx)· --plan 只读 · --auto 分类器 · /goal · /loop
   ↓
agent.ts    主循环:调用模型 → 有 tool_use 就执行 → 结果喂回 → 直到模型不再请求工具
   ├─ context.ts   历史按**内容体量**压缩(摘要 + 有损警告)
   ├─ prompt.ts    静态核心(可缓存)+ 动态环境信息
   ├─ memory.ts    召回与本次提问相关的记忆
   ├─ 工具表 = 7 个内置 + MCP 外部工具 + loop 内临时的 schedule_wakeup
   ├─ 模型(流式输出)
   └─ tool_use 分发:
        ├─ schedule_wakeup → /loop dynamic 排下一次
        ├─ agent           → subagent.ts 派只读子 Agent(独立上下文,只带回结论)
        ├─ mcp__…          → mcp.ts 按前缀转发给外部 MCP 服务器
        ├─ --auto 模式      → autonomy.ts 分类器判该不该放行(只读工具走 fast-path)
        ├─ permissions.ts + plan 模式 → 危险 / 只读模式下要动手 → 拦截
        └─ executeTool      → 结果喂回历史 → 回到循环顶部
   ↓
session.ts  每轮存盘,--resume 可恢复

自治三件套(`autonomy.ts`):`/goal` 用一个独立评估器把停止条件追到底(含 `impossible` 刹车)、`/loop` 支持定时重投与模型自定节奏、Auto Mode 用两段式分类器代替"确认框"。

快速开始

# 1) 装依赖
npm install

# 2) 配置 .env(复制 .env.example,填 ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL / MINI_MODEL)
#    没有 key 也能玩:npm test 与 npm run eval:mock 不需要任何 key

# 3) 编译(Windows 上别直接用 .bin/tsc)
node node_modules/typescript/bin/tsc

# 4) 用起来
node dist/cli.js "读一下 package.json,告诉我项目名"      # 一次性提问
node dist/cli.js                                          # 交互式 REPL
node dist/cli.js --resume                                 # 恢复上次会话
node dist/cli.js --plan  "做一个改版计划"                  # 只读(计划)模式
node dist/cli.js --auto  "重构这个模块"                    # Auto Mode:分类器代替确认框

**⚠️ 考古 MCP 需要两个仓库并列 clone**:`my-coding-agent/.mcp.json` 里指向考古 server 的是相对路径 `../codebase-archaeology-mcp/server.js`。只 clone 这一个仓库