settings

package
v0.7.212 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const CommitIfFilter = "Bash(git commit*)"

CommitIfFilter is the per-entry "if" condition that restricts hook entries to git commit commands. The Bash(pattern) syntax is evaluated as a glob against the bash command string, not the tool name.

View Source
const CommitMatcher = "Bash"

CommitMatcher is the PreToolUse hook group matcher that chunk manages. It targets the Bash tool by name; per Claude Code's hook spec, matcher filters only on tool name. Command-content filtering is done via CommitIfFilter on individual hook entries.

View Source
const ConflictsCommand = "chunk conflicts --hook"

ConflictsCommand is the advisory merge-conflict notice chunk writes into the commit hook group. It carries CommitIfFilter like every other entry there, so Merge already owns it and no separate ownership rule is needed.

--hook is what keeps it advisory: the command exits 0 whatever it finds, and reports through hook JSON rather than an exit code. It sits alongside entries whose failure blocks the commit, so that distinction is the whole contract.

View Source
const StopCommand = "chunk validate"

StopCommand is the Stop hook command that chunk manages. Merge identifies chunk's own Stop entry by this exact string, so it must stay in sync with the command written by Build and BuildCodex.

Variables

This section is empty.

Functions

func Build

func Build(commands []config.Command) ([]byte, error)

Build generates .claude/settings.json content from commands. It creates:

  • A PreToolUse group on the Bash tool holding the advisory conflict notice and the commit gate, both restricted to git commit by their "if".
  • A Stop hook that runs "chunk validate" after every session.

func BuildCodex added in v0.7.85

func BuildCodex(commands []config.Command) ([]byte, error)

BuildCodex generates .codex/hooks.json content from commands. Produces the same hook types as Build but without Claude Code-specific metadata ($schema, _comment), without a permissions block, and with the commit gate as a single entry:

  • Codex launches every matching hook for an event concurrently, so one entry per command would have a formatter rewriting files while lint and test read them. A single `chunk validate` runs them in sequence instead.
  • Codex has no per-entry "if", so the entry still carries CommitIfFilter (it is how Merge recognises chunk's entries) but chunk validate does the filtering itself, from the command in the hook payload.

Commands run as-is. Codex runs hooks in the session's working directory, which may be a subdirectory of the project; chunk validate finds the project from there when it runs as a hook.

func CodexWanted added in v0.7.212

func CodexWanted(dir, homeDir string) bool

CodexWanted reports whether the project should have Codex hooks: Codex is installed on this machine, or the project already has a .codex directory. homeDir is the user's home directory, where an installed Codex keeps its settings.

func Diff

func Diff(original, merged []byte) string

Diff returns a unified diff string between the original and merged JSON. Returns an empty string if there are no differences.

Types

type ConfirmFunc added in v0.7.212

type ConfirmFunc func(path, diff string) (bool, error)

ConfirmFunc asks the user whether to apply diff to the file at path, which is relative to the project directory.

type MergeResult

type MergeResult struct {
	Original []byte // existing settings.json content (re-marshaled for normalized formatting)
	Merged   []byte // merged result
	Changed  bool   // false if already up to date
}

MergeResult holds the computed merge without performing any I/O.

func Merge

func Merge(existing, generated []byte) (*MergeResult, error)

Merge computes the merged settings from existing and generated JSON bytes. It preserves all unknown keys in the existing settings and applies chunk's generated keys on top. Returns data only — display and file writing are the caller's responsibility.

func MergeCodex added in v0.7.85

func MergeCodex(existing, generated []byte) (*MergeResult, error)

MergeCodex computes the merged .codex/hooks.json from existing and generated bytes. It preserves all unknown keys and hook types, and replaces chunk's own PreToolUse and Stop hook entries via the same mergeHooks used for .claude/settings.json.

type Outcome added in v0.7.212

type Outcome int

Outcome is what writing an agent's hook file did. The zero value is no outcome, so an unset result never reads as success.

const (
	// Created means the file did not exist and was written.
	Created Outcome = iota + 1
	// Updated means the user agreed to merge chunk's hooks into the file.
	Updated
	// UpToDate means the file already had chunk's hooks.
	UpToDate
	// Declined means the user chose to leave the file as it was.
	Declined
	// WroteExample means the user could not be asked, so the file was left as
	// it was and chunk's version written beside it.
	WroteExample
)

type WriteResult added in v0.7.212

type WriteResult struct {
	Outcome Outcome
	// Path is the file, relative to the project directory.
	Path string
	// Example is the file written beside Path, for WroteExample.
	Example string
	// ConfirmErr is why the user could not be asked, for WroteExample.
	ConfirmErr error
}

WriteResult says what writing an agent's hook file did.

func WriteClaude added in v0.7.212

func WriteClaude(dir string, commands []config.Command, confirm ConfirmFunc) (WriteResult, error)

WriteClaude writes .claude/settings.json for the project, with hooks that run commands. When the file already exists, it merges chunk's hooks in and asks before applying the change; when the user cannot be asked, it writes settings.example.json instead.

func WriteCodex added in v0.7.212

func WriteCodex(dir string, commands []config.Command, confirm ConfirmFunc) (WriteResult, error)

WriteCodex writes .codex/hooks.json for the project, the same way WriteClaude writes .claude/settings.json.

Jump to

Keyboard shortcuts

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