agentimport

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package agentimport imports a coding agent's pre-existing local transcripts into Entire as read-only, commit-less checkpoints on the v1 metadata branch.

The orchestration (discovery loop, idempotent per-turn IDs, redaction, and the checkpoint write) is agent-agnostic and lives here. Each agent plugs in an Importer that knows where its transcripts live and how to split one into per-user-prompt turns. Claude Code is the only implementation today (see claude.go); others register themselves the same way.

Index

Constants

View Source
const LookbackDays = 30

LookbackDays bounds how far back import reaches. Fixed this pass (no flag).

Variables

This section is empty.

Functions

func DeriveCheckpointID

func DeriveCheckpointID(sessionID, turnUUID string) id.CheckpointID

DeriveCheckpointID produces a stable 12-hex checkpoint ID for an imported turn. Re-importing the same (sessionID, turnUUID) yields the same ID, which is how import stays idempotent.

Types

type Importer

type Importer interface {
	// Name is the registry key and the provenance source (e.g. "claude-code").
	Name() string
	// AgentType is the display name stored in checkpoint metadata (e.g. "Claude Code").
	AgentType() types.AgentType
	// Discover returns the agent's transcript files for the repo within the
	// lookback window. overridePath replaces the default transcript dir;
	// sessionFilter, when non-empty, keeps only matching session IDs.
	Discover(repoRoot, overridePath string, now time.Time, sessionFilter []string) ([]SessionFile, error)
	// SplitTurns splits one session's raw transcript bytes into per-turn units.
	SplitTurns(sf SessionFile, full []byte) ([]Turn, error)
}

Importer is the per-agent seam: it locates an agent's transcripts for a repo and splits one into per-turn units. Everything else (idempotency, redaction, writing) is handled generically by Run.

func All

func All() []Importer

All returns every supported importer, sorted by name.

type Options

type Options struct {
	RepoRoot      string
	OverridePath  string
	SessionFilter []string
	Now           time.Time
	DryRun        bool

	// LinkCommitSHA, when non-empty, is the fallback anchor written to each
	// imported checkpoint's metadata as commit_sha — the commit the UI shows
	// imported sessions against. The caller resolves it (default branch head
	// when resolvable; see resolveImportLinkCommitSHA); Run does not. A turn
	// whose transcript records a resolvable commit that is an ancestor of this
	// fallback anchors to that real commit instead (see turnAnchorResolver).
	LinkCommitSHA string
}

Options configures an import run.

type Result

type Result struct {
	SessionsScanned int
	TurnsImported   int
	TurnsSkipped    int
}

Result summarizes an import run.

func Run

func Run(ctx context.Context, repo *git.Repository, imp Importer, opts Options) (Result, error)

Run imports the given agent's transcripts (within the lookback window) as read-only checkpoints on the v1 metadata branch (Kind "imported"). It is idempotent: turns whose deterministic ID already exists are skipped.

type SessionFile

type SessionFile struct {
	Path      string // absolute path to the transcript file
	SessionID string // agent session id (used in checkpoint metadata)
}

SessionFile is one discovered agent transcript for a repo.

type Turn

type Turn struct {
	LineStart, LineEnd int
	UUID               string
	Prompt, Model      string
	CreatedAt          time.Time
	// Tokens is this turn's token usage. Every field is a per-turn delta:
	// main-agent fields are scoped to the turn's [LineStart, LineEnd) slice by
	// the token helpers, and SubagentTokens is rescoped from the cumulative
	// snapshot those helpers return to a per-turn increment by
	// rescopeSubagentTokensToDeltas (see linesplit.go). That invariant lets
	// callers sum turns freely: writeSessionState sums them for the session
	// total and each imported checkpoint stores its own turn's delta, so a
	// subagent's tokens are counted exactly once rather than re-added on every
	// turn after it is discovered.
	Tokens *types.TokenUsage
	// CommitSHAs are the commit SHAs (possibly abbreviated) this turn's
	// transcript records creating, in transcript order. Extraction is
	// per-importer (see commitSHAsInRange for Claude Code). Callers must
	// resolve them against the repo before use. Nil when the transcript
	// records no commits (including agents that don't extract them); the
	// anchor then falls back to Options.LinkCommitSHA.
	CommitSHAs []string
}

Turn is one user-prompt turn extracted from a session transcript. Line offsets are in raw-line space (newline-counted), matching transcript slicing and the agent token-usage helpers.

Jump to

Keyboard shortcuts

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