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
- func Command(exe, home, configPath string, args ...string) string
- func HookCommand(exe, home, configPath, agent string) string
- func InstalledHooks(doc map[string]any, agent string) map[string][]string
- func IsBridgeCommand(command string, args []string) bool
- func IsMemSpaceHook(command, agent string) bool
- func LoadJSONFile(path string) (doc map[string]any, exists bool, err error)
- func MentionsSensitivePath(command string) bool
- func MergeHooks(doc map[string]any, agent, command string, specs []HookSpec) bool
- func Payload(v map[string]any) json.RawMessage
- func RandomID(prefix string) string
- func RemoveHooks(doc map[string]any, agent string) bool
- func SaveJSONFile(path string, doc map[string]any) error
- func StableID(prefix string, parts ...string) string
- type Adapter
- type Check
- type Detection
- type HookSpec
- type InstallOptions
- type MCPOptions
- type MCPRegistrar
- type Normalizer
- type Status
Constants ¶
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.
const MCPServerName = "memspace"
MCPServerName is the name MemSpace registers under in agent configs.
const OmittedSensitive = "[omitted: sensitive file]"
OmittedSensitive replaces content captured from a secret file.
Variables ¶
This section is empty.
Functions ¶
func Command ¶
Command builds a shell command line that runs this binary with the given client home/config pinned.
func HookCommand ¶
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 ¶
InstalledHooks returns, per event, the MemSpace hook commands present.
func IsBridgeCommand ¶
IsBridgeCommand reports whether a registered stdio command runs MemSpace's MCP bridge.
func IsMemSpaceHook ¶
IsMemSpaceHook reports whether a hook command was installed by MemSpace for the given agent.
func LoadJSONFile ¶
LoadJSONFile reads a JSON object file. A missing file yields an empty object and exists=false.
func MentionsSensitivePath ¶
MentionsSensitivePath reports whether a shell command references a secret file (e.g. `cat .env`), in which case its output is not captured.
func MergeHooks ¶
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 ¶
RandomID returns a time-ordered unique ID for observations that have no natural identity.
func RemoveHooks ¶
RemoveHooks deletes every MemSpace handler for agent. Reports whether doc changed.
func SaveJSONFile ¶
SaveJSONFile atomically writes doc, keeping a copy of the previous file at <path>.memspace.bak.
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 ¶
Check is one doctor finding.
func HookChecks ¶
HookChecks verifies that every spec has a MemSpace handler, and that it is the command this binary would install.
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
// HookArgv is HookCommand as an argument vector, for agents that start
// hooks without a shell (omp's generated extension).
HookArgv []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 ¶
Normalizer converts one raw hook invocation into spool records.
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. |
|
Package hookpayload normalizes the hook payloads MemSpace's hook-based agents send on stdin into spool records.
|
Package hookpayload normalizes the hook payloads MemSpace's hook-based agents send on stdin into spool records. |
|
Package omp integrates Oh My Pi (omp) with MemSpace.
|
Package omp integrates Oh My Pi (omp) with MemSpace. |
|
Package pi integrates pi (pi-coding-agent) with MemSpace.
|
Package pi integrates pi (pi-coding-agent) with MemSpace. |