platform

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 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, 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

func (c *ClaudePlatform) InstallHooks(_ context.Context, scope HookScope, projectRoot string) error

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

func (c *ClaudePlatform) Name() string

Name implements Platform.

func (*ClaudePlatform) RemoveHooks

func (c *ClaudePlatform) RemoveHooks(_ context.Context, scope HookScope, projectRoot string) error

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.

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 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.
const (
	HookScopeProject HookScope = iota
	HookScopeLocal
	HookScopeUser
)

func ParseHookScope added in v0.3.1

func ParseHookScope(s string) (HookScope, error)

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

func (s HookScope) NeedsProjectRoot() bool

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.

func (HookScope) String added in v0.3.1

func (s HookScope) String() string

String returns the canonical slug used on the CLI, in JSON output, and in error messages. Keep in sync with ParseHookScope.

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.

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