dbagent

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dbagent is a stand-in agent that keeps its sessions in SQLite, as OpenCode does, for the core's tests: it lists and reads them with the Host's SQL, its bundle file is virtual (Materializer), only its own program writes the database (here, in the test's process), installs go through that program (VendorInstaller), and undo reaches it through SessionStore. Its sessions sit beside an anchor file at agent.AnchorRel.

Index

Constants

View Source
const ID agent.ID = "dbagent"

ID is the stand-in's agent id.

Variables

This section is empty.

Functions

func Anchor

func Anchor(data string, id agent.SessionID) string

Anchor is the anchor file of a session in a data root.

func Continue

func Continue(data string, id agent.SessionID, msg Message) error

Continue adds a message to a session, as using it in the agent does.

func DBFile

func DBFile(data string) string

DBFile is the database of a data root.

func Exists

func Exists(data string, id agent.SessionID) bool

Exists reports whether a data root's database holds a session.

func Init

func Init(data string) error

Init makes a data root's database with no sessions, as the agent does when it first runs.

func Seed

func Seed(data string, id agent.SessionID, dir, title string, msgs ...Message) error

Seed makes a session in a data root, as the agent would.

Types

type Message

type Message struct {
	ID   string `json:"id"`
	Role string `json:"role"` // user or assistant
	Text string `json:"text"`
}

Message is one message of a session.

type Module

type Module struct {

	// FailImport makes its program refuse every import while set.
	FailImport atomic.Bool
	// OwnIDs makes Write give a new session an id of its own (from the operation's id, so
	// RecoverWrite finds it again), not the one asked for.
	OwnIDs atomic.Bool
	// BeforeDelete runs as Delete starts (set before the module is used).
	BeforeDelete func(id agent.SessionID)
	// WriteStamps makes Write give the stamp its import left (ir.WriteResult.Stamp),
	// checked against the messages it wrote, as OpenCode's writer does.
	WriteStamps atomic.Bool
	// AfterImport runs right after Write's import, before the write reads anything back
	// (set before the module is used): a turn added there.
	AfterImport func(id agent.SessionID)
	// contains filtered or unexported fields
}

Module is the stand-in agent. Its counters say what its program did.

func New

func New() *Module

New returns the stand-in agent.

func (*Module) AfterInstall

func (m *Module) AfterInstall(ctx context.Context, h agent.Host, in agent.Install, key agent.SessionKey, _ agent.Placement) error

AfterInstall is the install itself: the agent's program imports the anchor the core placed, under the placement's id. A session already there with that content is done (a recovery runs it again); one with other content is ErrDiverged.

func (*Module) Backup

Backup exports the session to a file in its data root, through h (journaled).

func (*Module) Bundle

func (*Module) ChangeDir

func (*Module) ChangeDir(_ context.Context, _ agent.Host, in agent.Install, s agent.Summary, p agent.DirPlan) error

func (*Module) Delete

func (m *Module) Delete(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID, expect agent.SessionStamp) error

Delete deletes the session through its program while its stamp is expect.

func (*Module) Detect

func (m *Module) Detect(_ context.Context, h agent.Host) (agent.Install, error)

func (*Module) Imports

func (m *Module) Imports() int

Imports is how many sessions its program imported (an import of a session already there with the same content does nothing and is not counted).

func (*Module) InSession

func (*Module) InSession(_ agent.Install, dir string) string

func (*Module) InstallsViaVendor

func (*Module) InstallsViaVendor() bool

func (*Module) List

func (m *Module) List(ctx context.Context, h agent.Host, in agent.Install) (agent.Listing, error)

func (*Module) Materialize

func (m *Module) Materialize(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, _ agent.BundleFile) ([]byte, error)

Materialize is the session as JSON lines, from the database.

func (*Module) NewSessionID

func (m *Module) NewSessionID(agent.Install, time.Time) agent.SessionID

NewSessionID mints ids in the agent's own form.

func (*Module) PlanChangeDir

func (*Module) PlanChangeDir(_ context.Context, _ agent.Host, _ agent.Install, s agent.Summary, dir string) (agent.DirPlan, error)

PlanChangeDir has the agent's program move the session (DirAgent); its anchor stays.

func (*Module) PlanMove

func (*Module) Profile

func (*Module) Profile(agent.Install) ir.Profile

func (*Module) Read

func (m *Module) Read(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, from ir.Cursor) (ir.Segment, error)

Read reads the database, or, on a host without it (a peer's snapshot, staged files), the session's JSON lines at s.Path.

func (*Module) RecoverWrite

func (m *Module) RecoverWrite(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)

RecoverWrite finishes an interrupted Write: the anchor is there, so the import runs again (it does nothing when it ran).

func (*Module) Restore

func (m *Module) Restore(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID, backup string) (agent.SessionStamp, error)

Restore imports a backup again; a session there with other content is newer work.

func (*Module) Resume

func (*Module) SessionStamp

func (m *Module) SessionStamp(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID) (agent.SessionStamp, error)

SessionStamp is the session's message count and update time.

func (*Module) Spec

func (*Module) Spec() agent.Spec

Spec declares one data root holding the database, which only SQL reads.

func (*Module) Verify

func (*Module) Verify(ctx context.Context, h agent.Host, mp agent.MovePlan, staged map[string]string, p agent.Placement) error

Verify checks the staged session reads and is in the target's folder.

func (*Module) VirtualSessions

func (*Module) VirtualSessions()

func (*Module) Write

func (m *Module) Write(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)

Write writes a new session from another agent's: its JSON lines at its anchor, which its program then imports, under the id the core chose. The write is the install: the core runs no AfterInstall after it.

Jump to

Keyboard shortcuts

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