The event-capture tables (captures, mappings, bindings, binding_dispatches,
playbook_dispatches) now live in PocketBase-owned collections and their ids
are opaque record ids rather than autoincrement integers. The task lifecycle
stays on SQLite: tasks/transitions/events carry FIFO claim ordering, id-cursor
pagination and the task-grant map, none of which gain anything from being
hand-editable. binding_dispatches.task_id is the single seam and stays an
integer addressing that store.
BREAKING: CapturedEvent.Id, Mapping.Id, Binding.Id and Binding.MappingId are
strings on the wire, as are the ids in the capture/mapping/binding requests.
RecordDispatchRequest.task_id is deliberately unchanged.
What the collections buy, beyond storage: a payload nobody has modelled yet is
inspectable, a mapping is editable at runtime, and a binding's relation to its
mapping is enforced. The old schema declared no FOREIGN KEY on that link, so a
dangling mapping_id was previously possible and is now refused.
Behaviour preserved deliberately, each recovered from the SQLite version
rather than reimplemented from memory:
- draft -> pending_approval -> armed, with approval only from
pending_approval and an edit always returning a binding for re-approval
- one binding per source, guarded on insert, update and approve
- an empty secret on update keeps the stored one, so an edit form that does
not echo it back cannot silently disarm a binding
- ErrMappingNotFound / ErrBindingNotFound on a missing delete target
- sentinels are re-exported from storecontract, never redefined: staterpc
matches on exact canonical message to rehydrate them, so a second
definition would break errors.Is across the wire invisibly
Two implementation notes worth keeping:
- at-most-once dispatch is now a unique index rather than INSERT OR IGNORE.
Only the unique-violation maps to ErrAlreadyDispatched; any other save
error is returned, because treating them all as "already recorded" would
turn the ledger into a silent at-least-once dispatcher.
- captures store received_at themselves at nanosecond precision in a
fixed-width layout. PocketBase autodates are millisecond and record ids
are random, so same-millisecond captures would otherwise order
arbitrarily; the old store got insertion order free from autoincrement.
- ListUndispatchedCaptures is raw SQL: the anti-join is a subquery and
PocketBase's filter DSL is not SQL. A read fires no hooks either way.
Adds tool_calls, which had no persistence at all: tool calls only ever reached
the on-disk task log, readable as text but never queryable or watchable.
Nothing writes it yet.
The binding secret cipher moves with the bindings it protects.
64 lines
2.7 KiB
Go
64 lines
2.7 KiB
Go
// Package store defines the task and event persistence for archied's data.
|
|
// TaskStore is the full surface the daemon needs and *Store is its SQLite
|
|
// implementation.
|
|
//
|
|
// REVISED (archie-core-8cda.5.6): the producer-owned contract surfaces this
|
|
// package used to define live in internal/contracts/store/v1 (package
|
|
// storev1) -- the approved contract location -- so the archie-ui process can
|
|
// reference the contract without linking this SQLite implementation. The
|
|
// definitions below are type aliases for compatibility with the daemon-side
|
|
// callers; new UI-process-facing code imports storev1 directly.
|
|
package store
|
|
|
|
import (
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
// Aliases: the daemon/webui/intake store surfaces moved to storecontract. The
|
|
// message strings of the sentinel errors are the wire contract (see
|
|
// storev1's var block); the aliases change nothing observable.
|
|
type (
|
|
TaskStore = storecontract.TaskStore
|
|
TaskLifecycle = storecontract.TaskLifecycle
|
|
TaskArchiver = storecontract.TaskArchiver
|
|
TaskRetryer = storecontract.TaskRetryer
|
|
TaskQueries = storecontract.TaskQueries
|
|
TaskEvents = storecontract.TaskEvents
|
|
TaskLogStore = storecontract.TaskLogStore
|
|
CaptureStore = storecontract.CaptureStore
|
|
ConfigSnapshotStore = storecontract.ConfigSnapshotStore
|
|
ChannelStatusStore = storecontract.ChannelStatusStore
|
|
ApplyStatusStore = storecontract.ApplyStatusStore
|
|
MappingStore = storecontract.MappingStore
|
|
BindingStore = storecontract.BindingStore
|
|
BindingDispatcher = storecontract.BindingDispatcher
|
|
BindingTaskCreator = storecontract.BindingTaskCreator
|
|
PlaybookDispatcher = storecontract.PlaybookDispatcher
|
|
CapturedEvent = storecontract.CapturedEvent
|
|
ConfigSnapshot = storecontract.ConfigSnapshot
|
|
ChannelStatus = storecontract.ChannelStatus
|
|
ApplyStatus = storecontract.ApplyStatus
|
|
WorkflowStat = storecontract.WorkflowStat
|
|
StageStat = storecontract.StageStat
|
|
DayTokens = storecontract.DayTokens
|
|
)
|
|
|
|
var (
|
|
ErrStaleTransition = storecontract.ErrStaleTransition
|
|
ErrBindingNotFound = storecontract.ErrBindingNotFound
|
|
ErrBindingOverlap = storecontract.ErrBindingOverlap
|
|
ErrBindingTransition = storecontract.ErrBindingTransition
|
|
ErrAlreadyDispatched = storecontract.ErrAlreadyDispatched
|
|
ErrMappingNotFound = storecontract.ErrMappingNotFound
|
|
)
|
|
|
|
// Compile-time check: *Store satisfies TaskStore.
|
|
var _ TaskStore = (*Store)(nil)
|
|
|
|
// Compile-time check: *Store satisfies ChannelStatusStore.
|
|
var _ ChannelStatusStore = (*Store)(nil)
|
|
|
|
// Compile-time check: *Store satisfies workflow.Store.
|
|
var _ workflow.Store = (*Store)(nil)
|