platform

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
const DefaultName = "claude"

DefaultName is the platform used when a workspace is initialized without an explicit choice.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns the sorted slugs of every registered adapter. Used by CLI surfaces that need to list what's available.

func Register

func Register(p Platform)

Register adds p to the registry under its Name(). Intended to be called from an adapter's init(). Panics on duplicate registration — duplicate adapter slugs are a programming error, not a runtime one.

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) Name

func (c *ClaudePlatform) Name() string

Name implements Platform.

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.

func (*ClaudePlatform) Sync

func (c *ClaudePlatform) Sync(_ context.Context, prompt string, projectRoot string) error

Sync writes prompt into the managed section of CLAUDE.md, creating the `.claude/` directory and file as needed. User content outside the managed section is preserved byte-for-byte. If the file already contains a managed section with matching content, Sync is a no-op.

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.

func Get

func Get(name string) (Platform, error)

Get resolves an adapter by name. Empty or unknown names return a BadRequest error with a config-pointing hint.

Jump to

Keyboard shortcuts

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