restore

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package restore implements the "supermodel restore" command: it builds a high-level project summary (a "context bomb") and writes it to stdout so that Claude Code can re-establish codebase understanding after a context compaction event.

Graph data comes from two sources:

  • API mode: calls /v1/graphs/supermodel and parses the full SupermodelIR response into a ProjectGraph with semantic domains, critical files, and external dependencies.
  • Local mode: scans the repository file tree without any network calls, grouping files by directory to produce a minimal ProjectGraph.

The resulting ProjectGraph is rendered as Markdown with a configurable token budget (default 2 000 tokens) via Render.

Index

Constants

View Source
const DefaultMaxTokens = 2000

DefaultMaxTokens is the default token budget for the rendered context bomb.

Variables

This section is empty.

Functions

func CountTokens

func CountTokens(text string) int

CountTokens estimates the LLM token count of text using max(chars/4, words*4/3).

func DetectExternalDeps

func DetectExternalDeps(rootDir string) []string

DetectExternalDeps scans rootDir for common dependency manifests and returns up to 15 top-level dependency names. Supports go.mod, package.json, requirements.txt, Cargo.toml, Gemfile, and pyproject.toml.

func ReadClaudeMD

func ReadClaudeMD(rootDir string) string

ReadClaudeMD reads and returns the contents of CLAUDE.md from rootDir, truncated to 3 000 runes. Returns "" if the file is absent.

func Render

func Render(graph *ProjectGraph, projectName string, opts RenderOptions) (output string, tokens int, err error)

Render produces the context bomb Markdown, respecting the token budget. Returns the rendered text, estimated token count, and any template error.

Types

type CircularDependencyCycle

type CircularDependencyCycle struct {
	Cycle []string `json:"cycle"`
}

CircularDependencyCycle is a single circular import chain.

type CriticalFile

type CriticalFile struct {
	Path              string `json:"path"`
	RelationshipCount int    `json:"relationship_count"`
}

CriticalFile is a highly-referenced file derived from domain key file counts.

type Domain

type Domain struct {
	Name             string      `json:"name"`
	Description      string      `json:"description"`
	KeyFiles         []string    `json:"key_files"`
	Responsibilities []string    `json:"responsibilities"`
	Subdomains       []Subdomain `json:"subdomains,omitempty"`
	DependsOn        []string    `json:"depends_on,omitempty"`
}

Domain is a semantic area of the codebase.

type ProjectGraph

type ProjectGraph struct {
	Name                 string                    `json:"name"`
	Language             string                    `json:"language"`
	Framework            string                    `json:"framework,omitempty"`
	Description          string                    `json:"description,omitempty"`
	Domains              []Domain                  `json:"domains"`
	ExternalDeps         []string                  `json:"external_deps,omitempty"`
	CriticalFiles        []CriticalFile            `json:"critical_files,omitempty"`
	Stats                Stats                     `json:"stats"`
	Cycles               []CircularDependencyCycle `json:"cycles,omitempty"`
	CircularDepsAnalyzed bool                      `json:"circular_deps_analyzed"`
	UpdatedAt            time.Time                 `json:"updated_at"`
}

ProjectGraph is the processed project model used for rendering. It is derived from either a SupermodelIR API response or a local file scan.

func BuildProjectGraph

func BuildProjectGraph(ctx context.Context, rootDir, projectName string) (*ProjectGraph, error)

BuildProjectGraph generates a ProjectGraph from local repository analysis with no external API calls.

func FromSupermodelIR

func FromSupermodelIR(ir *api.SupermodelIR, projectName string) *ProjectGraph

FromSupermodelIR converts the raw API response into a ProjectGraph.

type RenderOptions

type RenderOptions struct {
	// MaxTokens is the token budget. Defaults to DefaultMaxTokens when zero.
	MaxTokens int
	// Stale indicates the graph data is older than the TTL.
	Stale   bool
	StaleAt *time.Time
	// ClaudeMD is the raw content of CLAUDE.md in the project root (may be "").
	ClaudeMD string
	// LocalMode causes an informational banner to be shown (no API key used).
	LocalMode bool
}

RenderOptions controls the context bomb output.

type Stats

type Stats struct {
	TotalFiles               int      `json:"total_files"`
	TotalFunctions           int      `json:"total_functions"`
	Languages                []string `json:"languages,omitempty"`
	CircularDependencyCycles int      `json:"circular_dependency_cycles,omitempty"`
}

Stats holds aggregate codebase statistics.

type Subdomain

type Subdomain struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Subdomain is a named sub-area within a Domain.

Jump to

Keyboard shortcuts

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