convodag

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package convodag implements a DAG-based conversation store using SQLite. Instead of linear chat history, conversations are stored as a directed acyclic graph so users can fork from any point and explore alternatives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAG

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

DAG is a conversation stored as a directed acyclic graph backed by SQLite.

func New

func New(dbPath string, sessionID string) (*DAG, error)

New opens or creates a conversation DAG for the given session.

func (*DAG) Append

func (d *DAG) Append(parentID string, role string, content string) (*Node, error)

Append adds a new node as a child of the given parent and advances the head pointer. Pass an empty parentID to create a root node.

func (*DAG) Branches

func (d *DAG) Branches(nodeID string) ([]*Node, error)

Branches returns all child nodes of the given node (i.e., fork points).

func (*DAG) Close

func (d *DAG) Close() error

Close closes the underlying database connection.

func (*DAG) Fork

func (d *DAG) Fork(nodeID string) (*Node, error)

Fork creates a new branch from the given node. It copies the fork point node as a marker and returns it. The returned node can be used as a parent for new messages on the alternative branch. Fork also moves the head pointer to this new fork point.

func (*DAG) Head

func (d *DAG) Head() (*Node, error)

Head returns the most recent node in the current branch, i.e. the node the session's head pointer points to.

func (*DAG) History

func (d *DAG) History(nodeID string) ([]*Node, error)

History returns the linear path from root to the given node by walking parent pointers. The returned slice is ordered from root to the given node.

func (*DAG) Prune

func (d *DAG) Prune(nodeID string) error

Prune removes a node and all its descendants from the DAG. If the head points to a pruned node, the head is moved to the pruned node's parent.

func (*DAG) SetHead

func (d *DAG) SetHead(nodeID string) error

SetHead moves the current branch pointer to a specific node.

type Node

type Node struct {
	ID        string
	ParentID  string // empty for root nodes
	Role      string // "user", "assistant", "system", "tool"
	Content   string
	Model     string
	CreatedAt time.Time
	Metadata  map[string]string
}

Node is a single message in the conversation DAG.

Jump to

Keyboard shortcuts

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