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, projectRoot string) (HookStatus, error)
- func (c *ClaudePlatform) InstallHooks(_ context.Context, projectRoot string) error
- func (c *ClaudePlatform) MapModelPrefs(prefs *models.ModelPrefs) map[string]any
- func (c *ClaudePlatform) Name() string
- func (c *ClaudePlatform) RemoveHooks(_ context.Context, projectRoot string) error
- func (c *ClaudePlatform) Sync(_ context.Context, prompt string, projectRoot string) error
- 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, projectRoot string) (HookStatus, error)
HooksStatus reports whether the brainjar hook is installed and whether the installed command matches what Install would write now.
func (*ClaudePlatform) InstallHooks ¶
func (c *ClaudePlatform) InstallHooks(_ context.Context, projectRoot string) error
InstallHooks registers the brainjar UserPromptSubmit hook in `.claude/settings.json`. 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 ¶
func (c *ClaudePlatform) RemoveHooks(_ context.Context, projectRoot string) error
RemoveHooks strips brainjar-owned hook entries from the settings file while preserving everything else. If removing brainjar's hook leaves the file semantically empty, the file is deleted.
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 under projectRoot. 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.
InstallHooks(ctx context.Context, projectRoot string) error
// RemoveHooks strips only brainjar-owned entries from the
// platform's settings file. User hooks and other settings survive.
RemoveHooks(ctx context.Context, projectRoot string) error
// HooksStatus reports whether brainjar hooks are installed and
// whether the installed command is current for this binary.
HooksStatus(ctx context.Context, 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.