Expand description
Applyable policy diffs — “diffs as the lingua franca” (dx-spec §5).
Every suggestion Keel makes — keel init --diff adds/removes, doctor fix
suggestions, and (future) keel flows add and keel mcp propose_policy —
is emitted as an applyable diff, because agents apply diffs reliably and
paraphrase prose unreliably. Callers describe a change as PolicyOps
against the current keel.toml text; propose returns a Proposal:
patch— a unified diff (a/keel.toml→b/keel.toml, or/dev/nullwhen the file does not exist yet) thatgit applyorpatch -p1applies cleanly,\ No newline at end of filemarkers included.changes— structured{path, before, after}hunks for machines (comments are a text-level concern; they appear only in the patch).new_text— the full proposed file, for callers that write directly.
Edits are surgical: they operate on the TOML document (toml_edit), not
a value round-trip, so user formatting and comments outside the touched
regions survive byte-for-byte. Everything here is a pure function of its
inputs — identical inputs yield byte-identical output (dx-spec §5).
Structs§
- Change
Hunk - One structured change: the TOML path plus the JSON value on each side
(
null= absent). Emitted depth-first over sorted keys — deterministic. - Policy
Path - A path into the policy document, segment by segment — e.g.
["target", "api.example.com", "retry"].Displayrenders the TOML dotted-key form (target."api.example.com".retry), quoting segments that are not bare keys, so paths stay unambiguous even when a target name contains dots. - Proposal
- The applyable result of
propose: serialize it (or embed it in a larger report) and both audiences are served —patchforgit apply,changesfor structured consumption.
Enums§
- Diff
Error - Why a proposal could not be built.
- Policy
Op - One edit to the policy document. Within a proposal,
SetandRemoveapply first (in order) as document surgery; everyAppendBlockis then appended to the rendered text (blank-line separated), so pre-rendered blocks keep their comments verbatim.
Functions§
- propose
- Build an applyable proposal: apply
opstocurrent(thekeel.tomltext;None= the file does not exist, which is distinct fromSome("")— it selects the/dev/nullcreation header) and return the patch + structured changes. Untouched regions ofcurrentsurvive byte-for-byte. - resolve_
dotted_ path - Resolve a
serde_path_to_error-style dotted path (e.g.target.api.example.com.retry.attempts, where the target key itself contains dots) against the document, greedily matching the longest key at each level. Array indices (on[1]) are stripped. When the path descends into a non-table value with segments left over, the path to that value is returned — it is the entry to fix. ReturnsNonewhen nothing matches. - unified_
diff - Render a unified diff between two texts: git-compatible headers, three
context lines,
\ No newline at end of filemarkers. Lines are compared with their terminators, so a missing final newline diffs correctly. Deterministic — a pure function of its inputs.