inject

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 15 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 inject runs inside agent hooks and returns the context MemSpace adds to the conversation: a card for unfinished work at session start and related history when the user submits a prompt.

Hooks are latency-sensitive and must never break the agent: every server call has a tight deadline, nothing is attempted while the client knows it is offline, and failures simply mean no injection. Session-start context falls back to a recent local cache when the server cannot be reached.

Index

Constants

View Source
const Hint = "" /* 236-byte string literal not displayed */

Hint is injected at session start when there is no unfinished work, so the agent knows the tools exist.

Variables

View Source
var (
	SessionStartTimeout = 2 * time.Second
	PromptTimeout       = 1500 * time.Millisecond
	CacheMaxAge         = 24 * time.Hour
)

Deadlines for the server call; agents wait for these hooks.

Functions

func Run

func Run(ctx context.Context, cfg Config, raw []byte) []byte

Run returns the hook's stdout (JSON with additionalContext) or nil.

Types

type Config

type Config struct {
	ServerURL string
	Token     string
	StateDir  string
	Agent     string // agent_type, e.g. claude-code
	Offline   bool   // the client is backing off after failed syncs
	MCP       bool   // the MCP server is registered (the hint names its tools)
	// StartWithFirstPrompt adds the session-start context to the first
	// prompt of a session, for agents whose SessionStart hook cannot.
	StartWithFirstPrompt bool
	// MarkerDir holds per-session markers (context already delivered);
	// default StateDir. DSH runs hooks in a sandbox that can write only to
	// the workspace and temporary directories.
	MarkerDir string
	// ProjectDir, when set, identifies the project instead of the hook's
	// cwd: the directory the session was started in.
	ProjectDir string
	// Notice, when set, returns a line for the user (e.g. a failed client
	// upgrade) to put first in the session-start context; "" for none.
	Notice func() string
	HTTP   *http.Client
}

Config is what a hook needs to fetch context.

type Input

type Input struct {
	SessionID     string `json:"session_id"`
	Cwd           string `json:"cwd"`
	HookEventName string `json:"hook_event_name"`
	Source        string `json:"source"`
	Prompt        string `json:"prompt"`
}

Input is the subset of hook stdin MemSpace reads (same field names in Claude Code and Codex).

Jump to

Keyboard shortcuts

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