Files
archie/modules/memory/internal/store/notes.go
T
samandCopilot cbfcd43018 feat(chat): add the chat module to the archie binary (#2018)
Conversations are the chat module's own tables. A turn is stored before it
is acknowledged, runs after the turns before it in its session, and records
everything it streams, so a reader replays it from a cursor. The agent uses
the configured agent model, the same connector tools as a run and the
dashboard's own reads; every action is judged, and one judgement holds is
put to people through approvals and run once when approved. A restart fails
the turns it interrupted visibly and never restarts a started action.

Conversation memory is a set of notes in the memory module. The chat
prompts are copied from internal/prompts (chat-system.tmpl, soul.md,
session-title.md) into internal/platform/prompts while the gateway still
reads them; the tool parameter redaction is copied from
internal/domain/messaging/tool_parameters.go.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-19 19:40:44 +11:00

47 lines
1.3 KiB
Go

package store
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
)
// Note is one remembered fact.
type Note struct {
ID uuid.UUID `db:"id"`
Text string `db:"text"`
CreatedAt time.Time `db:"created_at"`
}
// AddNote stores a fact.
func (s *Store) AddNote(ctx context.Context, orgID string, n Note) error {
if _, err := s.db.ExecContext(ctx, `
INSERT INTO memory.notes (id, org_id, text) VALUES ($1, $2, $3)`, n.ID, orgID, n.Text); err != nil {
return fmt.Errorf("remember note: %w", err)
}
return nil
}
// Notes returns the remembered facts, oldest first.
func (s *Store) Notes(ctx context.Context, orgID string, limit int) ([]Note, error) {
var out []Note
if err := s.db.SelectContext(ctx, &out, `
SELECT id, text, created_at FROM memory.notes WHERE org_id = $1
ORDER BY created_at LIMIT $2`, orgID, limit); err != nil {
return nil, fmt.Errorf("list notes: %w", err)
}
return out, nil
}
// DeleteNote forgets a fact and reports whether it existed.
func (s *Store) DeleteNote(ctx context.Context, orgID string, id uuid.UUID) (bool, error) {
res, err := s.db.ExecContext(ctx, `DELETE FROM memory.notes WHERE org_id = $1 AND id = $2`, orgID, id)
if err != nil {
return false, fmt.Errorf("forget note: %w", err)
}
n, err := res.RowsAffected()
return n > 0, err
}