contextpack

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 13 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 contextpack builds the bounded context MemSpace hands to agents: at session start, a card for recent unfinished work in the project; on each prompt, history related to what the user asked.

Everything is wrapped in <memspace_context> with an explicit statement that it is historical, possibly stale, and not instructions, and fitted to a character budget by dropping whole items, lowest priority first (Claude Code replaces hook output over 10,000 characters with a stub, so overflowing is worse than omitting).

Index

Constants

View Source
const (
	ModeSessionStart = "session_start"
	ModePrompt       = "prompt"
	ModeExplicit     = "explicit" // MCP memspace_project_context
)

Modes.

View Source
const (
	SessionStartBudget = 4000
	PromptBudget       = 6000
	ExplicitBudget     = 8000
	// HardLimit stays below Claude Code's 10,000-character hook limit.
	HardLimit = 9500
)

Default character budgets (~1000 / ~2000 tokens).

Variables

View Source
var RecentWindow = 72 * time.Hour

RecentWindow bounds how old an unfinished session may be to be offered at session start.

Functions

This section is empty.

Types

type Item

type Item struct {
	Key       string    `json:"key"`
	Kind      string    `json:"kind"` // session | history
	Ref       string    `json:"ref"`
	ProjectID string    `json:"project_id"`
	Device    string    `json:"device,omitempty"`
	Agent     string    `json:"agent,omitempty"`
	At        time.Time `json:"at"`
}

Item is one delivered piece, for provenance and de-duplication.

type Pack

type Pack struct {
	Text      string `json:"text"`
	Items     []Item `json:"items"`
	Truncated bool   `json:"truncated"`
	ProjectID string `json:"project_id,omitempty"`
	Note      string `json:"note,omitempty"`
}

Pack is the result. Text is empty when there is nothing worth injecting.

func Build

func Build(ctx context.Context, db *sql.DB, owner, deviceID string, req Request) (*Pack, error)

Build assembles a pack for the caller (owner, device).

type Request

type Request struct {
	Mode    string            `json:"mode"`
	Project search.ProjectRef `json:"project"`
	// The calling agent's own session, excluded from results.
	AgentType       string `json:"agent_type,omitempty"`
	NativeSessionID string `json:"native_session_id,omitempty"`
	Query           string `json:"query,omitempty"`
	// Budget in characters; 0 means the mode's default.
	Budget int `json:"budget,omitempty"`
	// Item keys already delivered to this session (not repeated).
	Exclude []string `json:"exclude,omitempty"`
}

Request asks for a context pack.

Jump to

Keyboard shortcuts

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