Documentation
¶
Overview ¶
Package platform adapts brainjar's composed prompts to agent-specific config files on disk. Each adapter knows where its platform reads config from, how to merge brainjar-owned content with user-authored content, and how to install hooks that keep the file current as state changes.
Adapters are registered at init time and resolved by name from the user's config. The Claude adapter is the only one that ships in M4; Codex, Amp, and Cursor slot in later without changes to this package.
Index ¶
- Constants
- func Names() []string
- func Register(p Platform)
- type ClaudePlatform
- func (c *ClaudePlatform) HooksStatus(_ context.Context, scope HookScope, projectRoot string) (HookStatus, error)
- func (c *ClaudePlatform) InstallHooks(_ context.Context, scope HookScope, projectRoot string) error
- func (c *ClaudePlatform) MapModelPrefs(prefs *models.ModelPrefs) map[string]any
- func (c *ClaudePlatform) Name() string
- func (c *ClaudePlatform) RemoveHooks(_ context.Context, scope HookScope, projectRoot string) error
- func (c *ClaudePlatform) Sync(_ context.Context, prompt string, projectRoot string) error
- type HookScope
- type HookStatus
- type Platform
Constants ¶
const DefaultName = "claude"
DefaultName is the platform used when a workspace is initialized without an explicit choice.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClaudePlatform ¶
type ClaudePlatform struct{}
ClaudePlatform adapts brainjar to Claude Code. Writes composed prompts to `<projectRoot>/.claude/CLAUDE.md` inside a managed section, and keeps `.claude/settings.json` hooks in sync.
func (*ClaudePlatform) HooksStatus ¶
func (c *ClaudePlatform) HooksStatus(_ context.Context, scope HookScope, projectRoot string) (HookStatus, error)
HooksStatus reports whether the brainjar hook is installed at the requested scope and whether the installed command matches what Install would write now.
func (*ClaudePlatform) InstallHooks ¶
InstallHooks registers the brainjar UserPromptSubmit hook in `.claude/settings.json` at the requested scope. Existing user- authored hooks at any event are preserved. Re-invoking upserts — no duplicate entries.
func (*ClaudePlatform) MapModelPrefs ¶
func (c *ClaudePlatform) MapModelPrefs(prefs *models.ModelPrefs) map[string]any
MapModelPrefs translates a generic ModelPrefs into a params map using current Claude model IDs. Unknown generic names pass through unchanged — a user who wrote a specific ID meant exactly that.
func (*ClaudePlatform) RemoveHooks ¶
RemoveHooks strips brainjar-owned hook entries from the settings file at the requested scope while preserving everything else. If removing brainjar's hook leaves the file semantically empty, the file is deleted.
type HookScope ¶ added in v0.3.1
type HookScope int
HookScope selects which settings file a hook operation targets. The three scopes mirror the tiers every supported platform exposes:
- Project scope writes to the platform's committed per-repository settings (e.g. <projectRoot>/.claude/settings.json). Everyone who clones the repo inherits the hook.
- Local scope writes to the platform's per-repository override file that is conventionally gitignored (e.g. <projectRoot>/.claude/settings.local.json). The hook fires only for this checkout and is not shared with collaborators.
- User scope writes to the platform's global user settings (e.g. ~/.claude/settings.json), so the hook fires in every project.
func ParseHookScope ¶ added in v0.3.1
ParseHookScope maps a CLI slug to a HookScope. Empty is treated as project to keep the default easy.
func (HookScope) NeedsProjectRoot ¶ added in v0.3.1
NeedsProjectRoot reports whether the scope requires a project root. User scope is filesystem-rooted at the user's home and ignores the projectRoot argument; project and local scope both need one.
type HookStatus ¶
type HookStatus struct {
Installed bool `json:"installed"`
UpToDate bool `json:"up_to_date"`
Command string `json:"command,omitempty"`
}
HookStatus is the result of Platform.HooksStatus. Installed reports whether any brainjar-owned hook is present; UpToDate reports whether the installed command matches what Install would write now.
type Platform ¶
type Platform interface {
// Name returns the canonical slug used to look this adapter up in
// the registry and in user-facing config (e.g. "claude").
Name() string
// Sync writes prompt into the platform's managed section inside
// projectRoot. Idempotent: if the managed section already matches
// prompt, Sync makes no filesystem change. Content outside the
// managed section is preserved byte-for-byte.
Sync(ctx context.Context, prompt string, projectRoot string) error
// InstallHooks registers brainjar-owned hook entries in the
// platform's settings file at the scope requested. User-authored
// hooks and unrelated settings are preserved. Re-invoking with the
// same binary is a no-op; re-invoking after the binary path changes
// upserts. projectRoot is used when scope is HookScopeProject and
// ignored when scope is HookScopeUser.
InstallHooks(ctx context.Context, scope HookScope, projectRoot string) error
// RemoveHooks strips only brainjar-owned entries from the
// platform's settings file at the requested scope. User hooks and
// other settings survive.
RemoveHooks(ctx context.Context, scope HookScope, projectRoot string) error
// HooksStatus reports whether brainjar hooks are installed at the
// requested scope and whether the installed command matches what
// Install would write now.
HooksStatus(ctx context.Context, scope HookScope, projectRoot string) (HookStatus, error)
// MapModelPrefs translates a generic ModelPrefs into a params map
// the platform's runtime understands (e.g. Claude model IDs).
MapModelPrefs(prefs *models.ModelPrefs) map[string]any
}
Platform is a filesystem adapter for one agent runtime (Claude, Codex, Amp, …). Every method is local-only — no network, no daemon.