the-open-engine/opcore
GitHub: the-open-engine/opcore
一款基于 Rust 代码图的 AI 编码代理变更验证门控,在代码编辑落地前对类型、结构、死导出等问题进行本地确定性检查并输出退出码。
Stars: 11 | Forks: 0
**编码代理在编辑生效前运行的变更文件验证门控。**
由 Rust 代码图提供支持,可读取死导出、未测试的接口、扇入热点以及 Rust 模块循环。
[](LICENSE)
[](#install)
[](#platforms)
[](#the-open-engine)
它在本地运行,保持安装过程受批准门控限制,并为代理提供可据以执行分支操作的退出代码。
```
$ opcore check --changed
1 file changed · checks passed CLEARED exit 0
$ opcore check --changed # after an agent introduces a type error
1 file changed · 1 check failed BLOCKED exit 1
FAIL typescript.types src/cart.ts:9 TS2322
```
| 退出代码 | 含义 |
| ---: | --- |
| `0` | 在容差范围内。无任何发现。 |
| `1` | 存在发现问题,或出现调用方应处理的错误。 |
| `2` | 请求的检查不支持当前技术栈。 |
| `64` | 不支持的范围。已计入统计,未作失败处理。 |
## 检查内容
Rust 代码图能够洞察单文件 linter 无法察觉的结构问题:无人调用的导出、缺乏测试的符号,以及被所有模块依赖的模块。
| 技术栈 | 深度 | 检查项 |
| --- | --- | --- |
| TypeScript, JavaScript | 深度 | 语法、类型、导入、相关测试、死导出、扇入及上帝文件热点。 |
| Rust | 实用 | 源码规范、超大文件、模块循环与孤儿模块、cargo、fmt、clippy、rustdoc。 |
| Python (`.py`, `.pyi`) | 实验性 | 结构、未测试模块、死导出、语法、规范。 |
每一项发现都会精确指向具体的文件、检查 ID 以及对应的符号。
## 安装并接入该门控
```
npx opcore install
```
`opcore install` 会首先进行扫描,展示执行计划,并在 TTY 环境下写入前请求确认。在 Git 仓库中,它会询问是为当前仓库还是全局安装 Claude Code/Codex 写入门控。默认的仓库设置会安装 Opcore 代理技能(agent skill)、Claude Code/Codex 写入门控钩子(hook),并在不存在现有 pre-commit 钩子时,安装一个运行 `opcore check --changed` 的 Git pre-commit 钩子。
若要显式进行全局安装:
```
npm install -g opcore
opcore install --global
```
安装脚本不会修改仓库或代理设置。该包仅会输出设置提醒。需要 Node >= 22。
## 命令
```
opcore --repo . # read-only scan: coverage, then findings
opcore status # readiness and coverage; never writes
opcore check --changed --json # the agent gate; also --staged or explicit
opcore install # scan, then wire repo/global agent hooks after approval
opcore install --global # install the write gate for all repos using global settings
opcore uninstall --yes # remove only what Opcore added
opcore measure --repo . # before/after deltas from local history
opcore try # run the loop on generated sample repos
```
只有 `opcore install` 以及兼容路径 `opcore init` 会写入设置文件,且必须在批准后执行。`--json` 和非 TTY 运行仍仅限于查看计划,除非您为 install 传入 `--yes` 或为 init 传入 `--approve`。
## 工作原理
Opcore 采用混合架构:Rust 图谱核心负责提取、持久化和热点查询;TypeScript 负责契约、CLI 和验证适配器。发现问题基于图谱读取,因此它们能映射到真实的代码结构,而不是简单的文本匹配。
已批准的仓库设置会以增量方式写入 `.opcore` 配置、一个指导块、Opcore 代理技能、一个小型写入门控适配器、合并的 Claude Code/Codex 钩子条目、在安全前提下激活的 Git pre-commit 钩子,以及撤销元数据。已批准的全局设置会在相同的增量式、可撤销策略下写入用户级钩子配置和技能。有关所有权模型,请参阅 @docs/architecture/runtime-cli-ard.md。
## 平台
支持 `darwin-arm64`、`darwin-x64` 和 `linux-x64`。其他平台会返回明确的状态,而不会导致崩溃。
## 文档
[快速入门](docs/quickstart.md) · [核心概念](docs/concepts.md) · [示例](docs/examples.md) · [代理集成](docs/agent-integration.md) · [架构](docs/architecture/runtime-cli-ard.md)
## Open Engine
Opcore 是 [The Open Engine](https://theopenengine.com) 的 Layer 02(约束层),与 [Zeroshot](https://github.com/the-open-engine/zeroshot)(Layer 01,验证层)同级。标签:AI编程助手, MITM代理, Rust, TypeScript, 云安全监控, 代码图分析, 代码质量检查, 可视化界面, 安全插件, 网络安全研究, 网络流量审计, 自动化攻击, 静态分析