conv

package
v0.0.263 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClaudeProjectsDir            = convops.ClaudeProjectsDir
	PathToProjectDir             = convops.PathToProjectDir
	GetClaudeProjectPath         = convops.GetClaudeProjectPath
	RemoveSessionsIndexEntry     = convops.RemoveSessionsIndexEntry
	UpsertSessionsIndexEntry     = convops.UpsertSessionsIndexEntry
	FindSessionByID              = convops.FindSessionByID
	RemoveSessionByID            = convops.RemoveSessionByID
	CopyDir                      = convops.CopyDir
	CopyFile                     = convops.CopyFile
	CopyConversationFile         = convops.CopyConversationFile
	LoadSessionsIndex            = convops.LoadSessionsIndex
	LoadSessionsIndexWithOptions = convops.LoadSessionsIndexWithOptions
	LoadEntriesFromDB            = convops.LoadEntriesFromDB
	RefreshConvIndexEntry        = convops.RefreshConvIndexEntry
	ScanAndUpsertFile            = convops.ScanAndUpsertFile
	ParseJSONLSessionPublic      = convops.ParseJSONLSessionPublic
)

Re-export functions from convops for backward compatibility. convops is the single source-of-truth implementation for all conv-data ops (parsing, SQLite-cached lookups, file I/O).

Functions

func ArchiveCmd added in v0.0.196

func ArchiveCmd() *cobra.Command

func BytesToFloat32 added in v0.0.55

func BytesToFloat32(b []byte) []float32

BytesToFloat32 converts raw bytes back to a float32 slice.

func Cmd

func Cmd() *cobra.Command

func CosineSimilarity added in v0.0.55

func CosineSimilarity(a, b []float32) float32

CosineSimilarity computes the cosine similarity between two vectors.

func CpCmd

func CpCmd() *cobra.Command

func DeleteCmd

func DeleteCmd() *cobra.Command

func DeleteConvByID added in v0.0.177

func DeleteConvByID(convID string) (db.AgentDeletionCounts, error)

DeleteConvByID is the single source-of-truth cleanup for a conversation — whether it's a free conv, an agent's conv, or an orphan with no conv_index row. Every "delete a conversation" surface (`tclaude conv rm`, daemon `/v1/agent/.../delete`, dashboard `DELETE /api/agents/...`) delegates here.

Comprehensive cleanup:

  • filesystem: removes the .jsonl + any sibling conv directory; walks ~/.claude/projects/* to find the file when conv_index doesn't know where it lives (orphan path).
  • DB: invokes db.DeleteAgentByConvID, which purges every row referencing this conv-id across conv_index, sessions, and every agent_* table (group_members, group_owners, permissions, messages, cron_jobs, conv_succession, embeddings, …).
  • session-env: removes the ~/.claude/session-env/<convID> file the hook callback uses.

What it does NOT do: kill an alive tmux session. That's the caller's policy (force vs refuse). Callers must stop the tmux session first if they want a live agent dead.

Idempotent: orphans, unknown conv-ids, and double-calls all return (zero-counts, nil) with whatever work CAN be done. Errors are returned only for genuine I/O failures, not for "thing was already gone".

Returns the per-table DB-row-removal counts from db.DeleteAgentByConvID so callers (the daemon's /v1/agent/.../delete response in particular) can surface them to the user.

func Float32ToBytes added in v0.0.55

func Float32ToBytes(f []float32) []byte

Float32ToBytes converts a float32 slice to raw bytes for SQLite storage.

func IndexConversation added in v0.0.55

func IndexConversation(entry SessionEntry, client *OllamaClient) (int, error)

IndexConversation chunks and embeds a single conversation, storing results in the DB. Embeds chunks individually so one oversized chunk doesn't fail the whole conversation.

func IndexEmbeddingsCmd added in v0.0.55

func IndexEmbeddingsCmd() *cobra.Command

func ListCmd

func ListCmd() *cobra.Command

func MvCmd

func MvCmd() *cobra.Command

func ParseTimeParam

func ParseTimeParam(s string) (time.Time, error)

ParseTimeParam parses a time parameter string into a time.Time Supports formats: "2024-01-15", "2024-01-15T10:30", "24h", "7d", "2w", or any time.Duration

func PruneEmptyCmd

func PruneEmptyCmd() *cobra.Command

func RenderTable

func RenderTable(stdout *os.File, entries []SessionEntry, showProject, long bool, matchCounts []int, groupsByConv map[string][]string)

RenderTable renders a table of conversation entries. matchCounts is optional - if provided, adds a "Matches" column. groupsByConv is optional - if any conv has at least one group, adds a "Groups" column. Pass nil or an empty map to skip.

func ResumeCmd

func ResumeCmd() *cobra.Command

func RunConvWatch

func RunConvWatch(global bool, since, before string, state ConvWatchState) (WatchResult, ConvWatchState, error)

RunConvWatch runs the interactive watch mode and returns the result

func RunConvWatchMode

func RunConvWatchMode(global bool, since, before string) error

RunConvWatchMode runs the interactive watch mode with create/attach loop

func RunCp

func RunCp(params *CpParams, stdout, stderr *os.File, stdin *os.File) int

func RunDelete

func RunDelete(params *DeleteParams, stdout, stderr *os.File, stdin *os.File) int

func RunIndexEmbeddings added in v0.0.55

func RunIndexEmbeddings(params *IndexEmbeddingsParams, stdout, stderr *os.File) int

func RunList

func RunList(params *ListParams, stdout, stderr *os.File) int

func RunMv

func RunMv(params *MvParams, stdout, stderr *os.File, stdin *os.File) int

func RunPruneEmpty

func RunPruneEmpty(params *PruneEmptyParams, stdout, stderr *os.File, stdin *os.File) int

func RunResume

func RunResume(params *ResumeParams, stdout, stderr *os.File) int

func RunSearch

func RunSearch(params *SearchParams, stdout, stderr *os.File) int

func RunSearchEmbeddings added in v0.0.55

func RunSearchEmbeddings(params *SearchEmbeddingsParams, stdout, stderr *os.File) int

func SearchCmd

func SearchCmd() *cobra.Command

func SearchEmbeddingsCmd added in v0.0.55

func SearchEmbeddingsCmd() *cobra.Command

func SetDebugLog added in v0.0.223

func SetDebugLog(v bool)

DebugLog is a back-compat pointer alias to convops.DebugLog. Callers who used to do `conv.DebugLog = true` should switch to `convops.DebugLog = true`; this helper preserves the existing surface for one release.

func UnarchiveCmd added in v0.0.196

func UnarchiveCmd() *cobra.Command

Types

type ArchiveParams added in v0.0.196

type ArchiveParams struct {
	ConvID string `pos:"true" help:"Conversation ID (full UUID or 8+-char prefix)"`
}

type Chunk added in v0.0.55

type Chunk struct {
	Index int
	Type  string // "metadata" or "content"
	Text  string
}

Chunk represents a piece of a conversation to be embedded.

func ChunkConversation added in v0.0.55

func ChunkConversation(entry SessionEntry) ([]Chunk, error)

ChunkConversation reads a .jsonl conversation file and returns chunks. Chunk 0 is always the metadata chunk (title + summary + first prompt). Subsequent chunks are content chunks built from user+assistant turn pairs.

type ConvParams

type ConvParams struct {
	Global bool `short:"g" help:"List conversations from all projects"`
}

type ConvWatchState

type ConvWatchState struct {
	SearchInput    string
	Cursor         int
	ViewportOffset int
	Sort           table.SortState
	SemanticMode   bool
	SemanticQuery  string
	SemanticScores map[string]float32
}

ConvWatchState holds state that persists between attach cycles

type CpParams

type CpParams struct {
	ConvID   string `pos:"true" help:"Conversation ID to copy"`
	DestPath string `pos:"true" help:"Destination directory path (real path, not Claude project path)"`
	Force    bool   `short:"f" help:"Force overwrite without confirmation"`
	Global   bool   `short:"g" help:"Search for conversation across all projects"`
}

type DeleteParams

type DeleteParams struct {
	ConvID string `pos:"true" help:"Conversation ID to delete"`
	Yes    bool   `short:"y" help:"Skip confirmation prompt"`
	Global bool   `short:"g" help:"Search for conversation across all projects"`
}

type EmbedSearchResult added in v0.0.55

type EmbedSearchResult struct {
	Entry      SessionEntry
	Similarity float32
	ChunkText  string
	ChunkType  string
}

SearchResult holds a conversation match with its similarity score and matching chunk.

func SearchEmbeddings added in v0.0.55

func SearchEmbeddings(queryEmbedding []float32, entries []SessionEntry, topK int) ([]EmbedSearchResult, error)

SearchEmbeddings searches all stored embeddings for the query and returns top-K results.

type IndexEmbeddingsParams added in v0.0.55

type IndexEmbeddingsParams struct {
	Global  bool   `short:"g" help:"Index conversations from all projects"`
	Reindex bool   `long:"reindex" help:"Force re-index all conversations (ignore cache)"`
	Model   string `long:"model" env:"TCLAUDE_EMBED_MODEL" help:"Embedding model name" default:"qwen3-embedding:0.6b"`
	URL     string `long:"url" env:"TCLAUDE_OLLAMA_URL" help:"Ollama API base URL" default:"http://localhost:11434"`
}

type ListParams

type ListParams struct {
	Dir          string `short:"C" long:"dir" optional:"true" help:"Directory to list conversations from (defaults to current directory)"`
	Global       bool   `short:"g" help:"List conversations from all projects"`
	SortBy       string `long:"sort-by" help:"Sort by: created, modified, messages, prompt, project" default:"modified"`
	Asc          bool   `long:"asc" help:"Sort ascending (default is descending)"`
	Long         bool   `short:"l" help:"Show detailed output"`
	Limit        int    `short:"n" help:"Limit number of results (0 = no limit)" default:"0"`
	JSON         bool   `long:"json" help:"Output as JSON"`
	Count        bool   `short:"c" long:"count" help:"Only output the count of conversations"`
	Since        string `long:"since" optional:"true" help:"Only include conversations modified after this time (e.g., 2024-01-15, 1h30m, 7d)"`
	Before       string `long:"before" optional:"true" help:"Only include conversations modified before this time (e.g., 2024-01-15, 1h30m, 7d)"`
	Watch        bool   `short:"w" long:"watch" help:"Interactive watch mode with search and session management"`
	Verbose      bool   `short:"v" long:"verbose" help:"Show debug info (stale scan stats, timing)"`
	Reindex      bool   `long:"reindex" help:"Force rescan all conversations from .jsonl files and update index"`
	ShowArchived bool   `` /* 144-byte string literal not displayed */
}

type LoadSessionsIndexOptions

type LoadSessionsIndexOptions = convops.LoadSessionsIndexOptions

type MatchLine

type MatchLine struct {
	LineNum int
	Content string
}

type MvParams

type MvParams struct {
	ConvID   string `pos:"true" help:"Conversation ID to move"`
	DestPath string `pos:"true" help:"Destination directory path (real path, not Claude project path)"`
	Force    bool   `short:"f" help:"Force overwrite without confirmation"`
	Global   bool   `short:"g" help:"Search for conversation across all projects"`
}

type OllamaClient added in v0.0.55

type OllamaClient struct {
	BaseURL string
	Model   string
	Client  *http.Client
}

OllamaClient calls the Ollama embedding API.

func NewOllamaClient added in v0.0.55

func NewOllamaClient(baseURL, model string) *OllamaClient

NewOllamaClient creates a client with defaults.

func (*OllamaClient) EmbedOne added in v0.0.55

func (c *OllamaClient) EmbedOne(text string) ([]float32, error)

EmbedOne embeds a single text, automatically reducing size if it exceeds the model's context length. Reduces by 1/3 each attempt until it fits or text is under 8K chars. NOTE: reduction means the tail of the text is lost. Future improvement: re-split into smaller chunks instead of truncating.

type PruneEmptyParams

type PruneEmptyParams struct {
	Dir    string `pos:"true" optional:"true" help:"Directory to prune (defaults to current directory)"`
	Global bool   `short:"g" help:"Prune across all projects"`
	Yes    bool   `short:"y" help:"Skip confirmation prompt"`
	DryRun bool   `short:"n" long:"dry-run" help:"Show what would be deleted without deleting"`
}

type ResumeParams

type ResumeParams struct {
	ConvID   string `pos:"true" help:"Conversation ID to resume (can be short prefix)"`
	Global   bool   `short:"g" help:"Search for conversation across all projects"`
	Detached bool   `short:"d" long:"detached" help:"Start detached (don't attach to session)"`
}

type SearchEmbeddingsParams added in v0.0.55

type SearchEmbeddingsParams struct {
	Query  string `pos:"true" help:"Natural language search query"`
	Global bool   `short:"g" help:"Search across all projects"`
	Limit  int    `short:"n" help:"Number of results" default:"10"`
	Long   bool   `short:"l" help:"Show matching chunk text"`
	JSON   bool   `long:"json" help:"Output as JSON"`
	Model  string `long:"model" env:"TCLAUDE_EMBED_MODEL" help:"Embedding model name" default:"qwen3-embedding:0.6b"`
	URL    string `long:"url" env:"TCLAUDE_OLLAMA_URL" help:"Ollama API base URL" default:"http://localhost:11434"`
}

type SearchParams

type SearchParams struct {
	Pattern       string `pos:"true" help:"Search pattern (regex supported)"`
	Dir           string `pos:"true" optional:"true" help:"Directory to search in (defaults to current directory)"`
	Global        bool   `short:"g" help:"Search across all projects"`
	Content       bool   `short:"-" long:"content" help:"Search full conversation content (slow, default searches only titles/prompts)"`
	Long          bool   `short:"l" help:"Show detailed output"`
	Context       int    `short:"C" help:"Lines of context around matches" default:"0"`
	CaseSensitive bool   `short:"s" help:"Case sensitive search (default is insensitive)"`
	SortBy        string `long:"sort-by" help:"Sort by: created, modified, messages, prompt, project, matches" default:"modified"`
	Asc           bool   `long:"asc" help:"Sort ascending (default is descending)"`
	Limit         int    `short:"n" help:"Limit number of results (0 = no limit)" default:"0"`
	JSON          bool   `long:"json" help:"Output as JSON"`
	Count         bool   `short:"c" long:"count" help:"Only output the count of matching conversations"`
	Since         string `long:"since" optional:"true" help:"Only include conversations modified after this time (e.g., 2024-01-15, 1h30m, 7d)"`
	Before        string `long:"before" optional:"true" help:"Only include conversations modified before this time (e.g., 2024-01-15, 1h30m, 7d)"`
}

type SearchResult

type SearchResult struct {
	Entry   SessionEntry
	Matches []MatchLine
}

type SessionEntry

type SessionEntry = convops.SessionEntry

func FilterEntriesByTime

func FilterEntriesByTime(entries []SessionEntry, since, before string) ([]SessionEntry, error)

FilterEntriesByTime filters session entries by time range

func ListSessions

func ListSessions(projectPath string) ([]SessionEntry, error)

ListSessions returns all sessions from a project directory

type SessionsIndex

type SessionsIndex = convops.SessionsIndex

Type aliases - use types from convops to avoid duplication

type WatchResult

type WatchResult struct {
	Conv           *SessionEntry
	ShouldCreate   bool   // true = create new session, false = attach to existing
	ForceAttach    bool   // Detach other clients when attaching
	FocusOnly      bool   // Just focus the window, don't attach
	TmuxSession    string // Tmux session to focus (when FocusOnly is true)
	FocusSessionID string // Session ID for focus (needed for WSL window title search)
	CreateWorktree bool   // true = create worktree for selected conv
	WorktreeBranch string // Branch name for worktree
}

WatchResult holds the result of the watch mode selection

Jump to

Keyboard shortcuts

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