picoclaw/pkg/memory/sqlc/agent_kv.sql.go
ZanzyTHEbar 626308ad95 feat(memory/sqlc): expand schema + harden queries + add vet rules
Schema:
- Add agent runtime tables: conversations, messages, runs, run_states,
  state_transitions, checkpoints, tool_results (all BLOB PKs, CASCADE)
- Add jobs queue table with dedupe_key unique partial index
- Add conversation graph tables: forks, links, threads, thread_messages,
  mentions, message_revisions

sqlc config:
- emit_db_tags: true — all generated structs carry db:"col" tags
- Fix stale comment: "TEXT storage" → "BLOB storage" for UUID overrides
- Add column overrides for all new agent runtime + conversation graph tables
- Add CEL vet rules: no-unbounded-delete, one-select-requires-limit-1

Query hardening:
- Add LIMIT 1 to 5 :one queries (recall, archival, working_context, docs, kv)
- Bound 12 unbounded :many queries with LIMIT sqlc.arg(lim)
- Add new query files for all agent runtime + jobs + conversation graph tables

Delegate:
- Add agentID param to GetRecallItem, DeleteRecallItem, GetArchivalChunk,
  ListArchivalChunks, ListAllArchivalChunks, CountArchivalChunks
- Pass Lim param to ListDocumentsByCategory, ListAllDocuments (default 1000)
- Pass Lim:10000 to ListArchivalChunks (bounded but practically unlimited)

CI / Makefile:
- Add sqlc-vet Makefile target (sqlc vet -f sqlc.yaml)
- Add sqlc-vet step to sqlc-check CI job
- Integrate sqlc-vet into check meta-target

Tests:
- Fix integration_test: add SetAgentID(testAgent), fix ListArchivalChunks/
  GetArchivalChunk calls to pass agentID
- Add benchmark suite for delegate ops
2026-02-18 23:40:03 +00:00

162 lines
3.2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: agent_kv.sql
package sqlc
import (
"context"
)
const DeleteKV = `-- name: DeleteKV :exec
DELETE FROM agent_kv
WHERE agent_id = ?1
AND key = ?2
`
type DeleteKVParams struct {
AgentID string `db:"agent_id" json:"agent_id"`
Key string `db:"key" json:"key"`
}
// DeleteKV
//
// DELETE FROM agent_kv
// WHERE agent_id = ?1
// AND key = ?2
func (q *Queries) DeleteKV(ctx context.Context, arg DeleteKVParams) error {
_, err := q.db.ExecContext(ctx, DeleteKV, arg.AgentID, arg.Key)
return err
}
const GetKV = `-- name: GetKV :one
SELECT agent_id,
key,
value,
updated_at
FROM agent_kv
WHERE agent_id = ?1
AND key = ?2
LIMIT 1
`
type GetKVParams struct {
AgentID string `db:"agent_id" json:"agent_id"`
Key string `db:"key" json:"key"`
}
// Agent KV Store queries
//
// SELECT agent_id,
// key,
// value,
// updated_at
// FROM agent_kv
// WHERE agent_id = ?1
// AND key = ?2
// LIMIT 1
func (q *Queries) GetKV(ctx context.Context, arg GetKVParams) (AgentKv, error) {
row := q.db.QueryRowContext(ctx, GetKV, arg.AgentID, arg.Key)
var i AgentKv
err := row.Scan(
&i.AgentID,
&i.Key,
&i.Value,
&i.UpdatedAt,
)
return i, err
}
const ListKVByPrefix = `-- name: ListKVByPrefix :many
SELECT agent_id,
key,
value,
updated_at
FROM agent_kv
WHERE agent_id = ?1
AND key LIKE ?2 || '%'
ORDER BY key
LIMIT ?3
`
type ListKVByPrefixParams struct {
AgentID string `db:"agent_id" json:"agent_id"`
Prefix *string `db:"prefix" json:"prefix"`
Lim int64 `db:"lim" json:"lim"`
}
// ListKVByPrefix
//
// SELECT agent_id,
// key,
// value,
// updated_at
// FROM agent_kv
// WHERE agent_id = ?1
// AND key LIKE ?2 || '%'
// ORDER BY key
// LIMIT ?3
func (q *Queries) ListKVByPrefix(ctx context.Context, arg ListKVByPrefixParams) ([]AgentKv, error) {
rows, err := q.db.QueryContext(ctx, ListKVByPrefix, arg.AgentID, arg.Prefix, arg.Lim)
if err != nil {
return nil, err
}
defer rows.Close()
items := []AgentKv{}
for rows.Next() {
var i AgentKv
if err := rows.Scan(
&i.AgentID,
&i.Key,
&i.Value,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const UpsertKV = `-- name: UpsertKV :exec
INSERT INTO agent_kv (agent_id, key, value, updated_at)
VALUES (
?1,
?2,
?3,
datetime('now')
) ON CONFLICT (agent_id, key) DO
UPDATE
SET value = excluded.value,
updated_at = excluded.updated_at
`
type UpsertKVParams struct {
AgentID string `db:"agent_id" json:"agent_id"`
Key string `db:"key" json:"key"`
Value string `db:"value" json:"value"`
}
// UpsertKV
//
// INSERT INTO agent_kv (agent_id, key, value, updated_at)
// VALUES (
// ?1,
// ?2,
// ?3,
// datetime('now')
// ) ON CONFLICT (agent_id, key) DO
// UPDATE
// SET value = excluded.value,
// updated_at = excluded.updated_at
func (q *Queries) UpsertKV(ctx context.Context, arg UpsertKVParams) error {
_, err := q.db.ExecContext(ctx, UpsertKV, arg.AgentID, arg.Key, arg.Value)
return err
}