adapter

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package adapter defines the agent adapter contract and the pieces shared by concrete adapters: hook-config editing, event IDs and payload sanitizing.

Index

Constants

View Source
const DryRunEnv = "MEMSPACE_HOOK_DRY_RUN"

DryRunEnv makes `memspace hook` print normalized events instead of spooling them; doctor uses it to exercise the installed command.

View Source
const MCPServerName = "memspace"

MCPServerName is the name MemSpace registers under in agent configs.

View Source
const OmittedSensitive = "[omitted: sensitive file]"

OmittedSensitive replaces content captured from a secret file.

Variables

This section is empty.

Functions

func Command

func Command(exe, home, configPath string, args ...string) string

Command builds a shell command line that runs this binary with the given client home/config pinned.

func HookCommand

func HookCommand(exe, home, configPath, agent string) string

HookCommand builds the command string agents execute. Paths are quoted for POSIX shells, which both Claude Code and Codex use to run hooks.

func InstalledHooks

func InstalledHooks(doc map[string]any, agent string) map[string][]string

InstalledHooks returns, per event, the MemSpace hook commands present.

func IsBridgeCommand

func IsBridgeCommand(command string, args []string) bool

IsBridgeCommand reports whether a registered stdio command runs MemSpace's MCP bridge.

func IsMemSpaceHook

func IsMemSpaceHook(command, agent string) bool

IsMemSpaceHook reports whether a hook command was installed by MemSpace for the given agent.

func LoadJSONFile

func LoadJSONFile(path string) (doc map[string]any, exists bool, err error)

LoadJSONFile reads a JSON object file. A missing file yields an empty object and exists=false.

func MentionsSensitivePath

func MentionsSensitivePath(command string) bool

MentionsSensitivePath reports whether a shell command references a secret file (e.g. `cat .env`), in which case its output is not captured.

func MergeHooks

func MergeHooks(doc map[string]any, agent, command string, specs []HookSpec) bool

MergeHooks makes doc contain exactly one MemSpace handler running command for each spec. Existing identical entries are left in place (so agents that key trust on position keep it); stale MemSpace entries are removed. Reports whether doc changed.

func Payload

func Payload(v map[string]any) json.RawMessage

Payload redacts and size-bounds an event payload.

func RandomID

func RandomID(prefix string) string

RandomID returns a time-ordered unique ID for observations that have no natural identity.

func RemoveHooks

func RemoveHooks(doc map[string]any, agent string) bool

RemoveHooks deletes every MemSpace handler for agent. Reports whether doc changed.

func SaveJSONFile

func SaveJSONFile(path string, doc map[string]any) error

SaveJSONFile atomically writes doc, keeping a copy of the previous file at <path>.memspace.bak.

func StableID

func StableID(prefix string, parts ...string) string

StableID derives a deterministic event ID, so re-capturing the same observation (hook retries, re-imports) deduplicates on the server.

Types

type Adapter

type Adapter interface {
	// Name is the CLI name, e.g. "claude" or "codex".
	Name() string
	// Detect reports whether the agent is present on this machine.
	Detect(ctx context.Context) Detection
	// Install registers MemSpace hooks with the agent.
	Install(ctx context.Context, opts InstallOptions) error
	// Uninstall removes MemSpace hooks, leaving the user's other config intact.
	Uninstall(ctx context.Context, out io.Writer) error
	// Doctor checks that capture works end to end on this machine.
	Doctor(ctx context.Context, opts InstallOptions) []Check
	// Capabilities lists the event types this adapter can capture.
	Capabilities() []string
	// Normalizer converts a hook invocation (stdin of `memspace hook <name>`).
	Normalizer
}

Adapter integrates one coding agent with MemSpace.

type Check

type Check struct {
	Name   string
	Status Status
	Detail string
}

Check is one doctor finding.

func HookChecks

func HookChecks(doc map[string]any, agent, want string, specs []HookSpec) Check

HookChecks verifies that every spec has a MemSpace handler, and that it is the command this binary would install.

func SelfTest

func SelfTest(ctx context.Context, agent, command string, sample []byte) Check

SelfTest runs the installed hook command the way the agent would (through a shell, with a sample payload on stdin) in dry-run mode, and checks that it produced a normalized event.

type Detection

type Detection struct {
	Found     bool
	Binary    string
	Version   string
	ConfigDir string
}

Detection describes an agent installation.

type HookSpec

type HookSpec struct {
	Event   string
	Matcher string // empty: no matcher (non-tool events)
	Timeout int    // seconds
}

HookSpec is one event MemSpace subscribes to.

type InstallOptions

type InstallOptions struct {
	// HookCommand is the shell command the agent runs for each hook, e.g.
	// `"/usr/local/bin/memspace" hook claude`.
	HookCommand string
	// Trust pre-approves the installed hooks where the agent requires review
	// (Codex). Only set when the user asked for it explicitly.
	Trust bool
	Out   io.Writer
}

InstallOptions are shared by Install and Doctor.

type MCPOptions

type MCPOptions struct {
	URL string // server endpoint the bridge forwards to, for messages
	// Command runs the stdio bridge (`memspace mcp stdio`), as argv.
	Command []string
	Out     io.Writer
}

MCPOptions describe how an agent should reach MemSpace's MCP tools without storing a secret in the agent's configuration.

type MCPRegistrar

type MCPRegistrar interface {
	RegisterMCP(ctx context.Context, opts MCPOptions) error
	UnregisterMCP(ctx context.Context) error
	MCPCheck(ctx context.Context) Check
}

MCPRegistrar is implemented by adapters that can register the MCP server.

type Normalizer

type Normalizer interface {
	Normalize(raw []byte, now time.Time) ([]spool.Record, error)
}

Normalizer converts one raw hook invocation into spool records.

type Status

type Status int

Status of a Check.

const (
	OK Status = iota
	Warn
	Fail
)

func (Status) Symbol

func (s Status) Symbol() string

Directories

Path Synopsis
Package claudecode captures Claude Code activity through its command hooks.
Package claudecode captures Claude Code activity through its command hooks.
Package codex captures OpenAI Codex CLI activity and injects MemSpace context through its SessionStart / UserPromptSubmit hooks.
Package codex captures OpenAI Codex CLI activity and injects MemSpace context through its SessionStart / UserPromptSubmit hooks.
Package dsh captures DeepSeek Harness (DSH) activity and gives its agents MemSpace context and tools.
Package dsh captures DeepSeek Harness (DSH) activity and gives its agents MemSpace context and tools.

Jump to

Keyboard shortcuts

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