migrate

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

internal/migrate/catalog.go

internal/migrate/detect_agentfiles.go

internal/migrate/detect_docs.go

internal/migrate/detector.go

Index

Constants

View Source
const CatalogRenderCap = 100

CatalogRenderCap bounds how many rows a rendered catalog / directive shows before summarizing the remainder, so a huge KB never floods the terminal or the MCP tool output.

Variables

This section is empty.

Functions

func ClearManifest

func ClearManifest(contexoDir string) error

ClearManifest removes the manifest file and best-effort removes any external clone cache it referenced.

func DefaultCloner

func DefaultCloner(url, dest string) error

DefaultCloner shells out to git with an argument slice (never a shell string).

func IsGitURL

func IsGitURL(s string) bool

IsGitURL reports whether from looks like a git remote (vs a local path).

func LabelFor

func LabelFor(dir string) string

LabelFor derives a short label for a scan directory (its base name).

func ManifestPath

func ManifestPath(contexoDir string) string

func ResolveExternal

func ResolveExternal(from, contexoDir string, clone Cloner) (scanDir, cacheDir string, err error)

ResolveExternal turns a --from value into a local directory to scan. For a URL it clones into .contexo/.migrate-cache/<hash> and returns that as both scanDir and cacheDir (so the caller records it for later cleanup).

func SaveManifest

func SaveManifest(contexoDir string, m *Manifest) error

func Slugify

func Slugify(s string) string

Slugify is the exported wrapper for slugify.

Types

type Candidate

type Candidate struct {
	ID              int
	Detector        string
	SourceRoot      string
	AbsPath         string
	RelPath         string
	Title           string
	Preview         string
	EstTokens       int
	SuggestedType   schema.PageType
	SuggestedSlug   string
	AlreadyImported bool
}

Candidate is one discovered knowledge item. Detectors fill everything except ID (assigned by Catalog.Build after ordering) and AlreadyImported (set by Build against the local .contexo/ store).

type Catalog

type Catalog struct{ Items []Candidate }

Catalog is an ordered, numbered set of discovered candidates.

func Build

func Build(scanDir, contexoDir string, dets []Detector) (Catalog, error)

Build runs each detector over scanDir, dedups by AbsPath (earlier detector wins), orders deterministically, assigns 1-based IDs, and flags candidates whose SuggestedSlug already exists under contexoDir.

func NewCatalog

func NewCatalog(items []Candidate, contexoDir string) Catalog

NewCatalog finalizes a pre-ordered candidate slice into a Catalog: it assigns 1-based IDs in the given order (no reordering) and flags AlreadyImported. Build uses it after its own dedup+sort; generate uses it directly on adapter-produced candidates.

func (Catalog) Filter

func (c Catalog) Filter(typ, detector string) Catalog

Filter keeps items matching typ (SuggestedType) and/or detector name; empty strings match everything. IDs are renumbered 1..n so selection stays contiguous.

func (Catalog) Render

func (c Catalog) Render(w io.Writer, opts RenderOpts)

Render writes the catalog to w.

The signature stays (io.Writer, RenderOpts) on purpose: cli/migrate.go and cli/generate.go call it, and catalog_test.go hands it a bare *bytes.Buffer, so widening it would break a test in another package. Styling is therefore resolved INSIDE, from w, via ui.Plain — which yields the plain text again for any non-terminal sink, so the golden test output is unchanged.

Note this is CLI-only. The MCP tool path does NOT come through here; it builds its own catalog text in mcp/migrate.go and mcp/generate.go. The two renderers are duplicated and drift independently.

type Cloner

type Cloner func(url, dest string) error

Cloner fetches a git URL into dest. Seam for testing.

type Detector

type Detector interface {
	Name() string
	Detect(root string) ([]Candidate, error)
}

Detector recognizes a knowledge format under root and enumerates its items. A Detector that does not recognize root returns (nil, nil), not an error.

func DefaultDetectors

func DefaultDetectors() []Detector

DefaultDetectors returns the v1 detector set in registration order. Order is load-bearing: it decides dedup precedence and render grouping.

type Manifest

type Manifest struct {
	Version       int            `json:"version"`
	Created       string         `json:"created"`
	SourceRoot    string         `json:"source_root"`
	ExternalCache string         `json:"external_cache,omitempty"`
	Label         string         `json:"label"`
	Kind          string         `json:"kind,omitempty"` // "migrate" (default) | "generate"
	Items         []ManifestItem `json:"items"`
}

Manifest is the pending-migration handoff written by the CLI picker and consumed by the ctx_migrate MCP tool.

func LoadManifest

func LoadManifest(contexoDir string) (*Manifest, error)

LoadManifest returns the pending manifest, or (nil, nil) if none exists.

type ManifestItem

type ManifestItem struct {
	AbsPath       string          `json:"abs_path"`
	RelPath       string          `json:"rel_path"`
	Detector      string          `json:"detector"`
	SuggestedType schema.PageType `json:"suggested_type"`
	SuggestedSlug string          `json:"suggested_slug"`
}

ManifestItem is one staged source awaiting agent distillation.

type RenderOpts

type RenderOpts struct{ Max int }

RenderOpts controls Render. Max caps how many rows print (0 = all).

Jump to

Keyboard shortcuts

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