resolve

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package resolve turns a discovered session file into the project it belongs to. It peeks the file header for the working directory, then resolves that directory's git origin remote to a canonical project key. Either hop can fail; rather than dropping the session, a failure classifies it: a folder with no usable git remote is standalone, a folder that no longer exists on disk is orphaned. Only a file we cannot even read a header from is skipped.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitRunner

type GitRunner func(ctx context.Context, dir string, args ...string) (string, error)

GitRunner runs a git subcommand in dir and returns its trimmed stdout. The default shells out to the system git; tests inject their own.

type Header struct {
	Cwd       string
	GitBranch string
	SourceID  string
	// contains filtered or unexported fields
}

Header is the minimum the client reads from a session file before deciding where it belongs. The full parse is the server's job.

func PeekHeader

func PeekHeader(f discover.File) (Header, error)

PeekHeader reads only as much of the file as it needs to extract cwd, the git branch, and a stable, unique source session id for the file. The id has to be unique per file: the server keys sessions on (user, agent, source_session_id), so two files that share an id fold into one row and clobber each other. Codex and pi files are already one-id-per-file, but Claude records the same sessionId in a main session file and in every subagent and workflow file under it, so those need an id derived from the file's location, not just its in-file sessionId.

type Kind

type Kind string

Kind classifies how a session resolves to a project.

const (
	// KindRemote is a session whose working directory resolves to a canonical git
	// remote. ProjectKey holds that remote.
	KindRemote Kind = "remote"
	// KindStandalone is a session whose working directory exists but yields no
	// usable git remote: not a repository, no origin, multiple origin URLs, or an
	// unrecognized origin URL. It is backed up and keyed by its local location.
	KindStandalone Kind = "standalone"
	// KindOrphaned is a session whose working directory is unknown or no longer
	// exists on disk, so its remote can never be resolved. It is still backed up.
	KindOrphaned Kind = "orphaned"
)

type Resolver

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

Resolver resolves files to projects, caching git lookups per directory for the process lifetime (the client keeps no on-disk state).

func New

func New() *Resolver

New builds a Resolver with the default system-git runner and ssh alias map.

func NewWith

func NewWith(git GitRunner, aliases map[string]string) *Resolver

NewWith builds a Resolver with an explicit git runner and alias map, for tests.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, f discover.File) Result

Resolve peeks the file header and classifies the session. A session with a resolvable git remote is KindRemote; one whose folder exists but has no usable remote is KindStandalone; one whose folder is unknown or gone is KindOrphaned. All three are returned ready to upload. Only a file whose header cannot be read is Skipped, since without a header there is nothing to identify or send.

type Result

type Result struct {
	File       discover.File
	Header     Header
	Kind       Kind
	ProjectKey string
	LocalRoot  string
	Skipped    bool
	Reason     string
}

Result is the outcome of resolving one file. Kind classifies the session; ProjectKey is the canonical remote only when Kind is KindRemote. Reason carries the human-readable detail behind a standalone or orphaned classification (and the failure detail when Skipped). Skipped is true only when the file's header could not be read at all, leaving nothing to upload.

LocalRoot is set only for a standalone session whose folder is a live git worktree: it holds the main worktree shared by every worktree of the repo, so the server can collapse a local-only repo's worktrees into one project the same way a canonical remote collapses a remote-backed repo's. It is empty for remote sessions, for orphaned sessions (the worktree is gone, so git cannot report it), and for non-git standalone folders.

Jump to

Keyboard shortcuts

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