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
- func Anchor(data string, id agent.SessionID) string
- func Continue(data string, id agent.SessionID, msg Message) error
- func DBFile(data string) string
- func Exists(data string, id agent.SessionID) bool
- func Init(data string) error
- func Seed(data string, id agent.SessionID, dir, title string, msgs ...Message) error
- type Message
- type Module
- func (m *Module) AfterInstall(ctx context.Context, h agent.Host, in agent.Install, key agent.SessionKey, ...) error
- func (m *Module) Backup(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID) (string, agent.SessionStamp, error)
- func (*Module) Bundle(_ context.Context, _ agent.Host, _ agent.Install, s agent.Summary) (agent.Bundle, error)
- func (*Module) ChangeDir(_ context.Context, _ agent.Host, in agent.Install, s agent.Summary, ...) error
- func (m *Module) Delete(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID, ...) error
- func (m *Module) Detect(_ context.Context, h agent.Host) (agent.Install, error)
- func (m *Module) Imports() int
- func (*Module) InSession(_ agent.Install, dir string) string
- func (*Module) InstallsViaVendor() bool
- func (m *Module) List(ctx context.Context, h agent.Host, in agent.Install) (agent.Listing, error)
- func (m *Module) Materialize(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, ...) ([]byte, error)
- func (m *Module) NewSessionID(agent.Install, time.Time) agent.SessionID
- func (*Module) PlanChangeDir(_ context.Context, _ agent.Host, _ agent.Install, s agent.Summary, dir string) (agent.DirPlan, error)
- func (*Module) PlanMove(_, _ agent.Install, s agent.Summary, b agent.Bundle, p agent.Placement) (agent.MovePlan, error)
- func (*Module) Profile(agent.Install) ir.Profile
- func (m *Module) Read(ctx context.Context, h agent.Host, in agent.Install, s agent.Summary, ...) (ir.Segment, error)
- func (m *Module) RecoverWrite(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)
- func (m *Module) Restore(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID, ...) (agent.SessionStamp, error)
- func (*Module) Resume(_ agent.Install, key agent.SessionKey, p agent.Placement, ...) agent.Command
- func (m *Module) SessionStamp(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID) (agent.SessionStamp, error)
- func (*Module) Spec() agent.Spec
- func (*Module) Verify(ctx context.Context, h agent.Host, mp agent.MovePlan, staged map[string]string, ...) error
- func (*Module) VirtualSessions()
- func (m *Module) Write(ctx context.Context, h agent.Host, in agent.Install, req ir.WriteRequest) (ir.WriteResult, error)
Constants ¶
const ID agent.ID = "dbagent"
ID is the stand-in's agent id.
Variables ¶
This section is empty.
Functions ¶
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 (*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 ¶
func (m *Module) Backup(ctx context.Context, h agent.Host, in agent.Install, id agent.SessionID) (string, agent.SessionStamp, error)
Backup exports the session to a file in its data root, through h (journaled).
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) Imports ¶
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) InstallsViaVendor ¶
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 ¶
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) 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) 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) 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.