Documentation
¶
Overview ¶
Package configedit provides byte-preserving edits of user-owned JSON and TOML settings files. Standard encoding/json round-trips rewrite key order, drop comments (TOML), and renormalize whitespace. configedit performs path-targeted edits backed by tidwall/gjson and tidwall/sjson for JSON, plus a narrow regex+mask patcher for the codex_hooks TOML feature flag.
Scope is intentionally narrow: only what the claudecode and codex adapters need.
Index ¶
- func CodexHooksEnabled(data []byte) bool
- func Delete(data []byte, path string) ([]byte, error)
- func EnsureCodexHooksFlag(data []byte) ([]byte, bool, error)
- func EscapePathKey(key string) string
- func MarshalRawJSON(v any) (string, error)
- func NormalizeJSONObject(data []byte) ([]byte, error)
- func Path(parts ...string) string
- func RawArray(items []string) string
- func SetRaw(data []byte, path string, raw string) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CodexHooksEnabled ¶
CodexHooksEnabled reports whether the bytes contain `[features].codex_hooks = true`. Multi-line strings and comments are masked so a literal containing the same text in a docstring is not misread as the real flag.
func EnsureCodexHooksFlag ¶
EnsureCodexHooksFlag returns the input bytes with `[features].codex_hooks = true` ensured. All bytes outside the touched line/section are preserved exactly. The boolean is true when the input changed.
Behavior:
- If `codex_hooks = true` already exists under [features], no change.
- If `codex_hooks = false` exists under [features], only the value token is rewritten to `true`.
- If [features] exists without the key, `codex_hooks = true` is inserted on its own line immediately after the table header.
- If [features] does not exist, a new `[features]` table is appended at the end of the file with `codex_hooks = true`.
Multi-line strings (`"""..."""`, `”'...”'`) and comments are masked before pattern matching so that user content cannot trick the scanner into treating the literal text `[features]` or `codex_hooks = true` inside a string as a real table header or key.
The patched output is validated by go-toml/v2 before return; if the rewrite produces invalid TOML the original bytes are returned with an error so the caller can abort the install with the file untouched.
func EscapePathKey ¶
EscapePathKey escapes characters that have special meaning in gjson/sjson path syntax so a literal key like "first.name" can be used as a single path component.
func MarshalRawJSON ¶
MarshalRawJSON marshals v to a compact raw JSON string suitable for passing to SetRaw / RawArray.
func NormalizeJSONObject ¶
NormalizeJSONObject returns the input bytes if they parse as a JSON object. Empty/whitespace-only input is treated as `{}`. Any other shape (array, scalar, malformed) is rejected.
Types ¶
This section is empty.