configedit

package
v1.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodexHooksEnabled

func CodexHooksEnabled(data []byte) bool

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 Delete

func Delete(data []byte, path string) ([]byte, error)

Delete removes the value at path via sjson and validates the result.

func EnsureCodexHooksFlag

func EnsureCodexHooksFlag(data []byte) ([]byte, bool, error)

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

func EscapePathKey(key string) string

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

func MarshalRawJSON(v any) (string, error)

MarshalRawJSON marshals v to a compact raw JSON string suitable for passing to SetRaw / RawArray.

func NormalizeJSONObject

func NormalizeJSONObject(data []byte) ([]byte, error)

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.

func Path

func Path(parts ...string) string

Path joins parts into a gjson/sjson path, escaping each part.

func RawArray

func RawArray(items []string) string

RawArray joins already-valid raw JSON elements into a JSON array literal. Empty input yields `[]`.

func SetRaw

func SetRaw(data []byte, path string, raw string) ([]byte, error)

SetRaw sets the value at path to raw via sjson and validates the result is still well-formed JSON.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL