Documentation
¶
Overview ¶
Package sdk is the `da-adapter-sdk` Go surface that bootstrap skills use exclusively to write into scoped KG storage (graph-backend-adapter-contract §8.4).
The contract rule the SDK enforces (§8.2): bootstrap skills and named queries MUST NOT open direct DB connections. Every storage operation goes through the SDK, which attaches a short-lived namespace token scoped to the operation. The storage layer validates every namespace referenced by an operation against the token's authorized set, and rejects anything outside it before any row is touched.
This package ships the SDK surface (§8.4.1) and an in-memory store backing it. The in-memory store is the substrate the TTRPG dogfood (.agents/sandbox/ttrpg-adapter/) runs its hard test against without standing up SQLite/Postgres: it is a faithful model of the namespace-token contract, not a production backend. A production SDK swaps the Store implementation for one backed by the gcc role-segregated graphstore (§2.7) — the SDK surface (this file) does not change.
Index ¶
- type Edge
- type FiredPredicate
- type Grant
- type MemStore
- func (m *MemStore) Edges(token Token, ns string) ([]Edge, error)
- func (m *MemStore) Namespaces() []string
- func (m *MemStore) Notes(token Token, ns string) ([]Note, error)
- func (m *MemStore) WriteEdges(token Token, ns string, edges []Edge) error
- func (m *MemStore) WriteNotes(token Token, ns string, notes []Note) error
- type Mode
- type NamespaceView
- type Note
- type QueryRunner
- type Row
- type SDK
- func (s *SDK) Adapter() string
- func (s *SDK) DeclarePredicateFired(predicate string, args map[string]any)
- func (s *SDK) FiredPredicates() []FiredPredicate
- func (s *SDK) MaterializeView(name string, readsFrom []string, runner ViewRunner) error
- func (s *SDK) Query(runner QueryRunner) ([]Row, error)
- func (s *SDK) WriteEdges(edges []Edge) error
- func (s *SDK) WriteNotes(notes []Note) error
- type Store
- type Token
- type ViewRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FiredPredicate ¶
FiredPredicate records a declare_predicate_fired call (§8.4.1).
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore is an in-memory Store for tests and the dogfood hard test. It enforces the §8.2 namespace-token contract: every operation's namespace and mode must be authorized by the supplied token, else the operation is rejected before touching storage. The zero value is not usable; use NewMemStore.
func (*MemStore) Namespaces ¶
Namespaces returns the namespaces with any data, sorted. Test/inspection aid.
func (*MemStore) Notes ¶
Notes returns ns's notes after token authorization (§8.2 N9: defense in depth — even a valid token is checked per-namespace).
func (*MemStore) WriteEdges ¶
WriteEdges appends edges to ns after token authorization.
type NamespaceView ¶
NamespaceView is the read-only data a QueryRunner sees.
func (NamespaceView) EdgesByType ¶
func (v NamespaceView) EdgesByType(t string) []Edge
EdgesByType returns the namespace's edges of a given type.
func (NamespaceView) NotesByType ¶
func (v NamespaceView) NotesByType(t string) []Note
NotesByType returns the namespace's notes of a given type.
type Note ¶
Note is a single note written to a namespace. The SDK is schema-agnostic at this layer: schema validation (§4) is the registry's job and runs before a bootstrap calls WriteNotes. ID and Type are required; Fields carries the declared note-type fields.
type QueryRunner ¶
type QueryRunner func(NamespaceView) []Row
QueryRunner runs a named query over a single namespace's data and returns rows. It is the in-process stand-in for a compiled DSL query.
type Row ¶
Row is a single named-query result row: an ordered set of column values keyed by the RETURN column name.
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is the `da-adapter-sdk` surface (§8.4.1). A bootstrap skill is constructed with For(adapter, store) and calls only these methods; it never sees a Store, a Token, or a namespace string it did not declare. The SDK derives the token for each operation from the adapter's identity and the operation kind — the bootstrap cannot widen its own authority.
func For ¶
For constructs an SDK bound to a single adapter's namespace and store. This is the only constructor a bootstrap skill uses; it cannot reach storage any other way (§8.2: direct DB connections are forbidden by contract).
func (*SDK) DeclarePredicateFired ¶
DeclarePredicateFired fires an env predicate (§8.4.1 sdk.declare_predicate_fired). The SDK records it; production routes it to the scoped-KG driver bus.
func (*SDK) FiredPredicates ¶
func (s *SDK) FiredPredicates() []FiredPredicate
FiredPredicates returns the predicates fired through this SDK, in call order.
func (*SDK) MaterializeView ¶
func (s *SDK) MaterializeView(name string, readsFrom []string, runner ViewRunner) error
MaterializeView computes and persists a view (§8.4.1 sdk.materialize_view). The SDK derives a multi-namespace token from readsFrom: {adapter, write} plus {dep, read} for each dependency. This is the ONLY surface that may read cross-namespace (§8.3). readNotes lets the runner pull a dependency's notes; the store rejects any namespace not in readsFrom.
func (*SDK) Query ¶
func (s *SDK) Query(runner QueryRunner) ([]Row, error)
Query executes a read-only operation within the adapter's own namespace and returns the matching notes (§8.4.1 sdk.query). The runner is a caller- supplied function that operates on the namespace's notes and edges; in v1 the named-query DSL compiler (internal/kg/dsl, a sibling task) would produce these runners from queries.yaml. Until that lands, the dogfood supplies runners directly — the SDK's job here is the token-scoped read boundary, not DSL compilation. The runner receives ONLY this adapter's namespace data: cross-namespace reads are not reachable from a named query (§8.3).
func (*SDK) WriteEdges ¶
WriteEdges bulk-writes edges to the adapter's own namespace (§8.4.1).
func (*SDK) WriteNotes ¶
WriteNotes bulk-writes notes to the adapter's own namespace (§8.4.1). The SDK attaches a {adapter, write} bootstrap token; the store rejects any attempt to write elsewhere.
type Store ¶
type Store interface {
// WriteNotes bulk-writes notes to ns. token must grant {ns, write}.
WriteNotes(token Token, ns string, notes []Note) error
// WriteEdges bulk-writes edges to ns. token must grant {ns, write}.
WriteEdges(token Token, ns string, edges []Edge) error
// Notes returns all notes in ns. token must grant {ns, read}.
Notes(token Token, ns string) ([]Note, error)
// Edges returns all edges in ns. token must grant {ns, read}.
Edges(token Token, ns string) ([]Edge, error)
}
Store is the storage substrate the SDK writes into. It is the only thing the SDK touches; a production SDK injects a gcc-backed Store (§2.7) and the SDK surface is unchanged. Every method takes the operation token and rejects out-of-namespace access (§8.2 storage-layer enforcement).
type Token ¶
Token is the namespace token of §8.2: a set of authorized (namespace, mode) pairs derived from the executing adapter's own namespace plus any cross-namespace dependencies declared in the operation being authorized.
In a production backend the token is signed and validated at the storage layer (§8.2.1 N13). Here the SDK constructs and checks it in-process; the authorization model — every referenced namespace must be in the authorized set — is identical, which is what the dogfood needs to exercise.
func BootstrapToken ¶
BootstrapToken derives the token for an adapter's bootstrap skill (§8.2 derivation rule: bootstrap grants {adapter, write}). N2.
func OwnReadToken ¶
OwnReadToken derives the token for an adapter reading its own namespace (§8.2 derivation rule: own queries grant {adapter, read}). N1/N5.