importer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package importer reconciles drifted .claude directories and CLAUDE.md files from the user's repos into the canonical knowledge store. Scan is read-only; merge writes only to knowledge/.import/staged/; apply is the single reviewed step that touches knowledge/ proper (contract C4).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasProgress

func HasProgress(knowledgeDir string) bool

HasProgress reports whether an interrupted merge left resumable progress.

func WriteReport

func WriteReport(knowledgeDir string, rep Report) (string, error)

WriteReport persists the scan report for review and for merge to consume.

Types

type ApplyResult

type ApplyResult struct {
	Applied   []string // now live in knowledge/
	Conflicts []string // destination exists with different content; kept staged
	Residual  []string // residual CLAUDE.md files left for manual placement
}

ApplyResult reports what apply moved into knowledge/ and what it refused.

func Apply

func Apply(knowledgeDir string, force bool) (ApplyResult, error)

Apply moves reviewed staged files into knowledge/ proper. It is the single gate between LLM output and the canonical store (contract C4): an existing destination with different content is a conflict and stays staged unless force. Identical destinations are treated as already applied. residual/ files are never applied — they belong in their repos, listed for the user.

type ClaudeMDInput

type ClaudeMDInput struct {
	Repo    string
	Content string
}

ClaudeMDInput is one repo's root CLAUDE.md.

type Cluster

type Cluster struct {
	Key             string  `json:"key"`  // "<kind>/<name>"
	Kind            string  `json:"kind"` // agent | skill
	Name            string  `json:"name"`
	Class           string  `json:"class"`     // identical | superset | diverged | unique
	Canonical       string  `json:"canonical"` // repo whose copy merge stages (LLM output for diverged)
	Similarity      float64 `json:"similarity,omitempty"`
	AttachmentDrift bool    `json:"attachment_drift,omitempty"`
	Items           []Item  `json:"items"`
}

Cluster groups all copies of one artifact identity across repos.

type ClusterInput

type ClusterInput struct {
	Kind   string
	Name   string
	Copies []Copy
}

ClusterInput carries the drifted copies of one artifact, bodies only — frontmatter is reconciled mechanically from the canonical copy.

type ClusterMerge

type ClusterMerge struct {
	CanonicalBody string
	Residues      []Residue // repo-specific guidance that must not go global
	Notes         string
	Usage         Usage
}

ClusterMerge is the LLM's reconciliation of a diverged cluster.

type Copy

type Copy struct {
	Repo string
	Body string
}

Copy is one repo's version of an artifact body.

type DecomposedCard

type DecomposedCard struct {
	Slug     string
	Type     string // rule | style | pattern
	Title    string
	Summary  string
	Keywords []string
	Scope    string // global | lang:<x> | repo:<name>
	Body     string
}

DecomposedCard is one atomic card extracted from a CLAUDE.md.

type Decomposition

type Decomposition struct {
	Cards    []DecomposedCard
	Residual string
	Notes    string
	Usage    Usage
}

Decomposition splits a CLAUDE.md into atomic cards plus the residual repo-facts markdown that should stay in the repo.

type GenMerger

type GenMerger struct {
	// contains filtered or unexported fields
}

GenMerger implements Merger over any llmgen backend.

func NewCLIMerger

func NewCLIMerger(model string) (*GenMerger, error)

NewCLIMerger builds a merger on the claude CLI found in PATH — zero API key, billed to the user's existing subscription.

func NewLLMMerger

func NewLLMMerger(model string) (*GenMerger, error)

NewLLMMerger builds a merger on ANTHROPIC_API_KEY (env) and the configured model.

func NewOllamaMerger

func NewOllamaMerger(endpoint, model string) *GenMerger

NewOllamaMerger builds a merger on a local Ollama chat model (a GENERATION model, e.g. qwen3 — not the embedding model).

func (*GenMerger) DecomposeClaudeMD

func (m *GenMerger) DecomposeClaudeMD(ctx context.Context, in ClaudeMDInput) (Decomposition, error)

DecomposeClaudeMD splits one CLAUDE.md into cards + residual.

func (*GenMerger) MergeCluster

func (m *GenMerger) MergeCluster(ctx context.Context, in ClusterInput) (ClusterMerge, error)

MergeCluster reconciles one diverged cluster.

func (*GenMerger) ModelName

func (m *GenMerger) ModelName() string

ModelName reports the backend's model for provenance frontmatter.

type Item

type Item struct {
	Repo        string   `json:"repo"`      // repo name (unique across the scan)
	RepoPath    string   `json:"repo_path"` // absolute repo root
	Kind        string   `json:"kind"`      // agent | skill | claudemd
	Name        string   `json:"name"`      // identity within kind
	Path        string   `json:"path"`      // absolute file path (SKILL.md for skills)
	Hash        string   `json:"hash"`      // sha256 of raw content
	NormHash    string   `json:"norm_hash"` // sha256 of normalized content
	Lines       int      `json:"lines"`
	Description string   `json:"description,omitempty"` // from the artifact's own frontmatter
	Attachments []string `json:"attachments,omitempty"` // skill sibling files, dir-relative
}

Item is one copy of an artifact found in a repo.

type MergeOpts

type MergeOpts struct {
	Force  bool // wipe staged output and progress, start over
	Resume bool // keep staged output, skip units already recorded as done
}

MergeOpts controls how Merge treats an existing staging area.

type MergeResult

type MergeResult struct {
	Staged  []string // paths relative to .import/staged/
	Skipped []string // human-readable reasons
	Notes   []string // LLM notes worth surfacing at review time
	Usage   Usage
}

MergeResult reports what merge staged and what it could not.

func Merge

func Merge(ctx context.Context, knowledgeDir string, rep Report, m Merger, opts MergeOpts) (MergeResult, error)

Merge stages every cluster and CLAUDE.md decomposition into knowledge/.import/staged/. It never touches knowledge/ proper. An existing non-empty staging area is refused unless Force or Resume — it may hold un-applied review edits (contract C4). Progress is recorded per unit so an interrupted run resumes without repeating finished LLM calls.

type Merger

type Merger interface {
	MergeCluster(ctx context.Context, in ClusterInput) (ClusterMerge, error)
	DecomposeClaudeMD(ctx context.Context, in ClaudeMDInput) (Decomposition, error)
}

Merger reconciles content the mechanical path cannot: diverged clusters and CLAUDE.md decomposition. Consumer-side seam — the gopheragent-backed implementation lives in llm.go; tests use a fake. A nil Merger is valid: mechanical clusters still stage, LLM work is reported as skipped.

type RepoInfo

type RepoInfo struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	Agents   int    `json:"agents"`
	Skills   int    `json:"skills"`
	ClaudeMD bool   `json:"claude_md"`
}

RepoInfo summarizes one scanned repo.

type Report

type Report struct {
	GeneratedAt time.Time  `json:"generated_at"`
	Repos       []RepoInfo `json:"repos"`
	Clusters    []Cluster  `json:"clusters"`
	ClaudeMD    []Item     `json:"claude_md"` // root CLAUDE.md files, decomposed at merge
}

Report is the full scan result, persisted to knowledge/.import/scan.json so the user can inspect it and merge can consume it without rescanning.

func ReadReport

func ReadReport(knowledgeDir string) (Report, error)

ReadReport loads a previously written scan report.

func Scan

func Scan(repoPaths []string) (Report, error)

Scan inventories every repo and clusters agents and skills by identity.

type Residue

type Residue struct {
	Repo    string
	Title   string
	Summary string
	Body    string
}

Residue becomes a repo-scoped rule card.

type Usage

type Usage struct {
	Prompt     int
	Completion int
}

Usage accumulates LLM token counts for cost reporting.

Jump to

Keyboard shortcuts

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