hpatch 是一个 Codex Responses 路由器和 CLI,它用紧凑的选择器和替换文本取代冗长的 apply_patch 工具调用,从而减少模型输出 token,同时保留沙箱检查和差异界面。

Stars

6

7 天增长

暂无数据

Fork 数

1

开放 Issue

0

开源协议

MIT

最近更新

2026-07-30

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它通过将补丁重构移出模型输出实现可复现的 token 节省,使用约束语法消除无效工具调用,并与 Codex CLI 及其沙箱无缝集成。

适合谁使用

  • 使用 OpenAI Codex CLI 进行 AI 辅助代码编辑的开发者
  • 寻求降低 token 成本和延迟的 LLM 代理工程师
  • 分析 AI 代码生成中 token 效率的研究人员

典型使用场景

  • 通过 Codex 应用多个文件编辑时降低 token 消耗
  • 使用紧凑 DSL 进行独立文件打补丁而无需运行完整模型
  • 测量 hpatch 与传统 apply_patch 之间的输出 token 节省

项目优势

  • 通过避免重复旧上下文和 JavaScript 载体实现可测量的 token 节省(GPT-5 估计)
  • Lark 语法强制有效语法,防止无效工具调用导致的生成-拒绝-重试循环
  • 原子脚本验证,拒绝时文件保持不变
  • 兼容 Codex 差异界面和沙箱权限

使用前须知

  • 需要 Go 1.26+、用于路由器的 systemd 用户服务和带有 ChatGPT 认证的 Codex CLI
  • 路由器仅适用于单个可用工作区根目录;零个或多个根目录会直接失败
  • Token 节省是可复现的负载估计值,而非实际提供商计费总额

README 快速开始

hpatch

A Codex Responses router that lets agents edit with compact selectors and replacement text instead of emitting full patches.

hpatch-router sits between Codex and the Responses API. It replaces the Code Mode apply_patch surface with constrained functions.hpatch, resolves successful scripts against the declared workspace, and hands Codex a real apply_patch carrier so sandbox checks and the normal diff UI remain intact. The repository also includes the standalone hpatch CLI and reusable Go engine used by the router.

TL;DR:

GoalStart here
Route Codex edits through hpatchInstall and configure the Codex router
Make Codex prefer hpatchOverride the base instructions
Inspect measured token savingsMetrics, then run hpatch gain
Use the engine without CodexStandalone CLI
Read the full editing contracthpatch --help, hpatch --tool-help, doc/spec/interface.md

Why hpatch?

A direct Code Mode edit makes the model repeat patch framing, old context, replacement text, and the JavaScript carrier. The router moves patch reconstruction out of model output:

flowchart LR
    subgraph output["Alternative model-output payloads"]
        H["hpatch pathfunctions.hpatch + selectors + replacement"]
        A["apply_patch baselinefunctions.exec + JavaScript carrier+ old context + replacement + patch framing"]
    end

    subgraph router["Router and Codex after model output"]
        B["Router reads the immutableworkspace baseline"]
        C["Router generates theapply_patch envelope"]
        D["Codex applies the patchsandbox checks + normal diff"]
    end

    H --> B --> C --> D
    A --> D

The patch is not eliminated: the router generates it after inference. Savings are the difference between the two model-output payload estimates shown above. State reports, rejection diagnostics, and the net cost of installing the hpatch tool definition while removing the Code Mode apply_patch section are tracked separately as input overhead. These are reproducible GPT-5 token estimates, not provider billing totals.

For an 11-line function replacement, hpatch asks the model for this:

functions.hpatch
in parser.go
rsel 50:60
type

项目描述

Compact, editor-like file edits for agents: select text, type the change, skip rewriting full patches.

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

mereyabdenbekuly-ctrl
精选
mereyabdenbekuly-ctrl GitHub avatar

clodex-ide

Clodex is an open-source, local-first agentic IDE that combines persistent AI tasks, code, terminal, browser, Git, models, memory, and governed execution in one Electron workspace, currently in technical preview.

AI 与机器学习AI 智能体
859
MoonshotAI
精选
MoonshotAI GitHub avatar

Kimi-K3

Kimi K3 is an open-weight, 2.8T-parameter native multimodal agentic model with a 1M-token context window, designed for frontier coding, knowledge work, and reasoning tasks.

AI 与机器学习AI 智能体
3,348
lopopolo
精选
lopopolo GitHub avatar

harness-engineering

Harness Engineering is a methodology for improving coding agent outputs by carefully crafting the environment around them—providing curated context, tools, and executable constraints that encode an organization’s nonfunctional requirements and cumulative lessons.

AI 与机器学习AI 智能体
2,390