Liking cljdoc? Tell your friends :D

im.ttalk.agent.tools.patch

apply_patch(T-04):Codex 补丁文法的解析器 + 内存应用器 + 工具壳。

翻译自 OpenAI Codex CLI(Apache-2.0,Copyright 2025 OpenAI;见模块根 THIRD-PARTY-NOTICES.md 与 LICENSE-codex.txt),经 Keelson Keelson.Text/Patch/* 与 ApplyPatchTool.cs 转写:

  • 解析:codex-rs/apply-patch/src/parser.rs(边界检查、宽松模式剥 heredoc)与 streaming_parser.rs(逐行状态机)@ 4bad6d78e9;
  • 匹配:codex-rs/apply-patch/src/seek_sequence.rs(精确 → 忽略行尾空白 → 忽略两端空白 → Unicode 标点归 ASCII);
  • 应用:codex-rs/apply-patch/src/{text_file.rs, file_update.rs, lib.rs}(逐行保行尾、compute_replacements、成功摘要);
  • 工具壳:codex-rs/core/src/tools/handlers/apply_patch.rs(先验证整份补丁、写前逐路径过权限)。

与上游的差别:引擎不碰 IO——读由调用方给,产出「先全部算好、再由调用方落盘」的 plan: 任一文件对不上 ⇒ 一个也不写。

apply_patch(T-04):Codex 补丁文法的解析器 + 内存应用器 + 工具壳。

翻译自 OpenAI Codex CLI(Apache-2.0,Copyright 2025 OpenAI;见模块根 THIRD-PARTY-NOTICES.md 与
LICENSE-codex.txt),经 Keelson `Keelson.Text/Patch/*` 与 `ApplyPatchTool.cs` 转写:
- 解析:codex-rs/apply-patch/src/parser.rs(边界检查、宽松模式剥 heredoc)与 streaming_parser.rs(逐行状态机)@ 4bad6d78e9;
- 匹配:codex-rs/apply-patch/src/seek_sequence.rs(精确 → 忽略行尾空白 → 忽略两端空白 → Unicode 标点归 ASCII);
- 应用:codex-rs/apply-patch/src/{text_file.rs, file_update.rs, lib.rs}(逐行保行尾、compute_replacements、成功摘要);
- 工具壳:codex-rs/core/src/tools/handlers/apply_patch.rs(先验证整份补丁、写前逐路径过权限)。

与上游的差别:引擎不碰 IO——读由调用方给,产出「先全部算好、再由调用方落盘」的 plan:
**任一文件对不上 ⇒ 一个也不写**。
raw docstring

add-fileclj

source

apply-patch*clj

(apply-patch* w args)
source

apply_patchclj

(apply_patch {:as args3665 :or {} :keys [input]})

(说明见 im.ttalk.agent.tools.patch/description,绑定时替换)

(说明见 im.ttalk.agent.tools.patch/description,绑定时替换)
sourceraw docstring

begin-patchclj

source

change-contextclj

source

delete-fileclj

source

derive-new-contentsclj

(derive-new-contents original path chunks)

按块改 original:保留每行原有行尾,插入的行用首选行尾,结果每一行都有行尾。

按块改 original:保留每行原有行尾,插入的行用首选行尾,结果每一行都有行尾。
sourceraw docstring

empty-change-contextclj

source

end-of-fileclj

source

end-patchclj

source

environment-idclj

source

move-toclj

source

parse-patchclj

(parse-patch patch)
(parse-patch patch lenient?)

解析补丁文本 ⇒ {:hunks [...] :patch 剥过 heredoc 的原文 :env-id}。错 ⇒ ex-info(ex-data ::parse-error)。 hunk:{:type :add :path :contents} | {:type :delete :path} | {:type :update :path :move-path :chunks [chunk]}; chunk:{:change-context :old [行] :new [行] :ctx-idx [[old-i new-i]] :eof?}。

解析补丁文本 ⇒ {:hunks [...] :patch 剥过 heredoc 的原文 :env-id}。错 ⇒ ex-info(ex-data ::parse-error)。
hunk:{:type :add :path :contents} | {:type :delete :path} | {:type :update :path :move-path :chunks [chunk]};
chunk:{:change-context :old [行] :new [行] :ctx-idx [[old-i new-i]] :eof?}。
sourceraw docstring

plan-applyclj

(plan-apply w {:keys [input]})

解析 ⇒ 路径策略(全部过了才往下)⇒ 同一路径多处操作拒 ⇒ 读现状 ⇒ 新鲜度 ⇒ 内存推演 ⇒ 语法闸。无副作用。

解析 ⇒ 路径策略(全部过了才往下)⇒ 同一路径多处操作拒 ⇒ 读现状 ⇒ 新鲜度 ⇒ 内存推演 ⇒ 语法闸。无副作用。
sourceraw docstring

plan-patchclj

(plan-patch {:keys [hunks]} resolve read)

推演整份补丁。resolve:补丁里的路径 ⇒ 完整路径(Path);read:完整路径 ⇒ {:kind :missing|:file|:dir|:unreadable :text :reason}。任一块失败 ⇒ 抛,一步都不产出。 ⇒ {:ops [[:write path text] [:delete path] ...] :changes [...] :added :modified :deleted}

推演整份补丁。resolve:补丁里的路径 ⇒ 完整路径(Path);read:完整路径 ⇒
{:kind :missing|:file|:dir|:unreadable :text :reason}。任一块失败 ⇒ 抛,一步都不产出。
⇒ {:ops [[:write path text] [:delete path] ...] :changes [...] :added :modified :deleted}
sourceraw docstring

preview-applyclj

(preview-apply w args)
source

seekclj

(seek lines pattern start eof?)

在 lines 里从 start 起找 pattern 这一串行;四级放宽。eof? ⇒ 先从文件末尾那个位置找。找不到 ⇒ nil。

在 lines 里从 start 起找 pattern 这一串行;四级放宽。eof? ⇒ 先从文件末尾那个位置找。找不到 ⇒ nil。
sourceraw docstring

summaryclj

(summary {:keys [added modified deleted]})

Codex print_summary 的口径:标题 + 每行 A / M / D + 补丁里写的路径。

Codex print_summary 的口径:标题 + 每行 A / M / D + 补丁里写的路径。
sourceraw docstring

update-fileclj

source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close