setup

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 21 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 setup wires stacklit into AI coding assistants. Every step is idempotent, supports dry-run, and can be reversed with uninstall.

Index

Constants

View Source
const (
	StyleMarkdown = "md"
	StyleHash     = "hash"
)

Marker styles. Markdown files use HTML comments, config files use hashes.

View Source
const (
	CrawlOff      = "off"
	CrawlNudge    = "nudge"
	CrawlRedirect = "redirect"
)

Crawl guard modes.

View Source
const DefaultSteering = "a"

DefaultSteering is the variant used when none is configured.

View Source
const StructureTag = "map "

StructureTag prefixes the hash in the digest so a reader (or the session hook) can tell which structure a CLAUDE.md block was written from.

Variables

View Source
var SkillMD string

SkillMD is the /stacklit skill installed for Claude Code.

Functions

func BodyFor added in v0.5.0

func BodyFor(idx *schema.Index, variant string) string

BodyFor is MarkdownBody with a chosen steering variant. Nothing in it depends on line counts, timestamps or churn, only on structure.

func CrawlGuardHook added in v0.5.0

func CrawlGuardHook(stdin io.Reader, installed string) (out string)

CrawlGuardHook answers a PreToolUse payload. Any failure, a missing index or a narrow call produces no output, which Claude Code reads as allow.

func CrawlMode added in v0.5.0

func CrawlMode(root, installed string) string

CrawlMode resolves the mode: STACKLIT_CRAWL_GUARD, then the crawl_guard config key, then the mode the installed hook carries. Unknown means off.

func CrawlModes added in v0.5.0

func CrawlModes() []string

CrawlModes lists the valid modes.

func GuideJSON added in v0.5.0

func GuideJSON() string

GuideJSON is the same guide as JSON for tools that want structured input.

func GuideText added in v0.5.0

func GuideText() string

GuideText is the full agent usage guide, plain text, byte stable.

func MCPSchemaTokens added in v0.5.0

func MCPSchemaTokens(exe, dir string) int

MCPSchemaTokens starts `exe serve` and measures the tools/list payload an agent loads into context. It returns -1 when the server cannot be queried.

func MarkdownBody added in v0.5.0

func MarkdownBody(idx *schema.Index) string

MarkdownBody builds the always-on orientation digest. It is deterministic (sorted, no timestamps, no churn counters) so reruns are byte-identical and do not invalidate prompt caches, and it is capped to the token budget.

func PreToolHook added in v0.5.0

func PreToolHook(stdin io.Reader) string

PreToolHook answers a PreToolUse payload. For a Grep on a single identifier it points at the definition and top callers from the symbol graph; it never blocks or approves, and stays silent without a graph or for non-identifiers.

func Run added in v0.5.0

func Run(r *Runner, o Options) error

Run applies opts through r and returns the first hard error.

func SessionHook added in v0.5.0

func SessionHook(stdin io.Reader) string

SessionHook answers a SessionStart payload for every source (startup, resume, clear, compact, fork). When the project's CLAUDE.md already holds a digest of the current structure it adds only the status line, because Claude Code re-reads that file itself, including after compaction. Otherwise it injects the digest. Any failure or a missing index yields no output.

func SteeringFor added in v0.5.0

func SteeringFor(root string) string

SteeringFor resolves the variant: STACKLIT_STEERING wins, then the config key.

func SteeringVariants added in v0.5.0

func SteeringVariants() []string

SteeringVariants lists the valid variant names.

func SubagentHook added in v0.5.0

func SubagentHook(stdin io.Reader) string

SubagentHook answers a SubagentStart payload. Explore and Plan skip CLAUDE.md, so they get the digest; other agents already load it and get nothing, which avoids paying for the same text twice.

func Tokens added in v0.5.0

func Tokens(s string) int

Tokens approximates token count as bytes/4, the documented estimate used everywhere stacklit reports overhead.

Types

type ClaudeOptions added in v0.5.0

type ClaudeOptions struct {
	PreToolHook bool
	SessionHook bool
	RefreshHook bool
	// CrawlGuard is "", "off" (remove), "nudge" or "redirect".
	CrawlGuard   string
	Skill        bool
	GlobalScope  bool
	UninstallAll bool
}

ClaudeOptions selects the optional Claude Code extras.

type Crawl added in v0.5.0

type Crawl struct {
	Kind    string // find, ls, tree, grep, glob, read-dir, subagent
	Ident   string // identifier searched for, when the pattern is one
	Query   string // words to put in a stacklit query, may be empty
	Command string // suggested stacklit command
}

Crawl describes one recognised repo-wide crawl and the stacklit command that answers the same need.

func DetectBash added in v0.5.0

func DetectBash(cmd, root string) (Crawl, bool)

DetectBash judges a shell command line. A cd into a subdirectory ends the scan, since later relative paths no longer mean the repo root.

func DetectCrawl added in v0.5.0

func DetectCrawl(in hookInput, root string) (Crawl, bool)

DetectCrawl classifies one PreToolUse payload.

func DetectGlob added in v0.5.0

func DetectGlob(pattern, dir, root string) (Crawl, bool)

DetectGlob flags a Glob that lists every file or every file of an extension from the repo root. Patterns naming a file or a subdirectory pass.

func DetectRead added in v0.5.0

func DetectRead(file string) (Crawl, bool)

DetectRead flags a Read whose target is a directory.

func DetectSubagent added in v0.5.0

func DetectSubagent(prompt string) (Crawl, bool)

DetectSubagent flags a subagent prompt that asks to explore the whole repo with no identifier, path or file named.

type GuideCommand added in v0.5.0

type GuideCommand struct {
	Command string `json:"command"`
	Use     string `json:"use"`
}

GuideCommand is one row of the command list in the guide.

func GuideCommands added in v0.5.0

func GuideCommands() []GuideCommand

GuideCommands lists the commands an agent should reach for, in order.

type MCP added in v0.5.0

type MCP struct {
	Path  string
	Style MCPStyle
	// Global paths are relative to the home directory and need --global.
	Global bool
}

MCP describes where and how a tool registers the stacklit server.

type MCPStyle added in v0.5.0

type MCPStyle string

MCPStyle selects the config file format a tool expects.

const (
	StyleMCPServers MCPStyle = "mcpServers"
	StyleVSCode     MCPStyle = "vscode"
	StyleZed        MCPStyle = "zed"
	StyleOpenCode   MCPStyle = "opencode"
	StyleCrush      MCPStyle = "crush"
	StyleCodexTOML  MCPStyle = "codex-toml"
	StyleContinue   MCPStyle = "continue"
)

type Options added in v0.5.0

type Options struct {
	Root      string
	Tools     []Tool
	Index     *schema.Index
	Uninstall bool
	NoMCP     bool
	NoGitHook bool
	// Global lets setup write outside the repo (home directory configs).
	Global bool
	Claude ClaudeOptions
}

Options controls one setup run.

type ReportRow added in v0.5.0

type ReportRow struct {
	Item   string
	Tokens int
	Note   string
}

ReportRow is the always-on context one integration adds, in tokens (bytes/4).

func Report added in v0.5.0

func Report(idx *schema.Index, tools []Tool, mcpTokens int) []ReportRow

Report measures the always-on cost of each integration for idx. mcpTokens is the shared MCP schema cost, or -1 if unknown.

type Rule added in v0.5.0

type Rule struct {
	Path        string
	Style       string
	Frontmatter string
}

Rule is one instruction file a tool reads. Owned files are ours alone and are deleted on uninstall once the block is gone; shared files only lose the block.

type Runner added in v0.5.0

type Runner struct {
	Root   string
	DryRun bool
	Out    io.Writer
	// Changed counts files that were (or would be) created, updated or removed.
	Changed int
}

Runner applies file changes, or only reports them in dry-run mode.

func (*Runner) ApplyClaudeExtras added in v0.5.0

func (r *Runner) ApplyClaudeExtras(o ClaudeOptions, uninstall bool) error

ApplyClaudeExtras installs or removes the optional hooks and skill. Settings are only written under .claude/ unless GlobalScope is set.

type Tool

type Tool struct {
	ID    string
	Name  string
	Rules []Rule
	MCP   []MCP
	// Paths and Bins drive auto-detection.
	Paths []string
	Bins  []string
}

Tool is one supported AI coding assistant.

func Lookup added in v0.5.0

func Lookup(id string) (Tool, bool)

Lookup finds a tool by id.

func Registry added in v0.5.0

func Registry() []Tool

Registry lists every supported tool. Order is the display order.

func (Tool) Detected

func (t Tool) Detected(root string) bool

Detected reports whether the tool looks installed or in use under root.

Jump to

Keyboard shortcuts

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