CAT-K2: a Store on the ledger, the records' heads without text and each section's text once
ledgerStore implements Store on the tool runner's ledger calls: a record is the instance decision/0290 or research/081, a Save is the operation named by what changed, a section's text is written once in its write-section and named by digest and sequence in the head, a version is read back from the history, the whole-set findings and the told marks are keys of the state findings. Every test that runs over each store now also runs over the ledger, played with the manifest's own types. The bundle's pipe to the tool runner needs the SDK's raw request (request to A1); until then it answers loudly. Issue 1966. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
// The module's reach to its bus state (novox/hq ADR 0595 §9, ADR 0597 §10): the calls of mesh-sdk's buscalls, made over
|
||||
// the bundle's pipe to the tool runner, and the module's states, made through the SDK's State. Both are interfaces here,
|
||||
// so the ledger's store is tested against a ledger played in the test and not against a bus.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// Pipe makes one call of buscalls on the tool runner: the method, its request, and where its answer is decoded.
|
||||
type Pipe interface {
|
||||
Call(method string, request, answer any) error
|
||||
}
|
||||
|
||||
// KV is one of the module's states (stdio.KeptState is one).
|
||||
type KV interface {
|
||||
Get(key string) (*stdio.StateEntry, error)
|
||||
Put(key string, value any) (uint64, error)
|
||||
Create(key string, value any) (uint64, error)
|
||||
Update(key string, value any, revision uint64) (uint64, error)
|
||||
Delete(key string) error
|
||||
Keys() ([]string, error)
|
||||
}
|
||||
|
||||
// States are the module's states by their local names in `requires`.
|
||||
type States interface {
|
||||
State(name string) KV
|
||||
}
|
||||
|
||||
// sdkStates are the module's states through the SDK.
|
||||
type sdkStates struct{}
|
||||
|
||||
func (sdkStates) State(name string) KV { return stdio.State(name) }
|
||||
|
||||
// callKey carries, in a context, the id of the tool call an operation serves: the tool runner stamps the caller it
|
||||
// proved for that call as the operation's author (buscalls.MetaCall, ADR 0597 §7).
|
||||
type callKey struct{}
|
||||
|
||||
// withCall is ctx naming the tool call in flight.
|
||||
func withCall(ctx context.Context, call string) context.Context {
|
||||
if call == "" {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, callKey{}, call)
|
||||
}
|
||||
|
||||
// callOf is the tool call ctx names, or "" for the module's own act.
|
||||
func callOf(ctx context.Context) string {
|
||||
s, _ := ctx.Value(callKey{}).(string)
|
||||
return s
|
||||
}
|
||||
|
||||
// ErrNoPipe is the answer of a pipe the pinned mesh-sdk does not give the bundle yet.
|
||||
var ErrNoPipe = errors.New("the pinned mesh-sdk gives a bundle no request on the tool runner's bus-state calls yet " +
|
||||
"(a request to the SDK's owner: stdio.Request); the records cannot be reached over the bus")
|
||||
|
||||
// sdkPipe is the pipe through the SDK. Request is set when the SDK offers it; until then the pipe answers ErrNoPipe,
|
||||
// loudly, and nothing is written.
|
||||
type sdkPipe struct{}
|
||||
|
||||
// request is the SDK's raw request on the runtime's channel (stdio.Request(method, params) (json.RawMessage, error)),
|
||||
// wired in the one place the group's mesh-sdk pin brings it.
|
||||
var request func(method string, params any) (json.RawMessage, error)
|
||||
|
||||
func (sdkPipe) Call(method string, req, answer any) error {
|
||||
if request == nil {
|
||||
return ErrNoPipe
|
||||
}
|
||||
raw, err := request(method, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if answer == nil || len(raw) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(raw, answer)
|
||||
}
|
||||
Reference in New Issue
Block a user