Join item 1: the catalogue's modules take the router's ask from operator-channel's contract and client
mesh-sdk holds neither asks nor asker, nor the vault's answer types, and mesh-delivery's sdk/views is mesh-sdk's go/views (a1-progress.md, the rewrite map for the join): thirteen modules switch to the operatorchannel contract and client, mesh-sdk's channel package and meshvault, with go.mod requiring each at the group pin (nats: meshbroker too). The gate holds the checks mesh-sdk dropped (an ask's id is its key's asking, at least one option), with a row that fails without them; claude-code refuses a router record whose times do not parse, as its JSON decode did, with a row. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -20,8 +20,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/go/seats/operatorchannel"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/asks"
|
||||
)
|
||||
|
||||
// Module is this module's name: the one the bus grants its asks under.
|
||||
@@ -34,7 +35,7 @@ const (
|
||||
)
|
||||
|
||||
// AskLasts is how long the operator has to answer: a day less a margin, under the router's bound for an approval.
|
||||
const AskLasts = asks.ApproveLasts - 10*time.Minute
|
||||
const AskLasts = occ.ApproveLasts - 10*time.Minute
|
||||
|
||||
// The states of an operator's ask, as the record keeps them.
|
||||
const (
|
||||
@@ -58,8 +59,8 @@ func (sdkAskBus) Publish(subject string, body any, id string) error {
|
||||
func (sdkAskBus) Record(id string) (*stdio.StateEntry, error) { return stdio.SeatRecord("", id) }
|
||||
|
||||
// act is what an answer binds: this record's version, by its digest, and the answer.
|
||||
func act(r *Record, a *OperatorAsk, option string) asks.Act {
|
||||
return asks.Act{"verb": "knowledge-base.accept", "option": option, "ask": a.ID, "kind": r.Kind,
|
||||
func act(r *Record, a *OperatorAsk, option string) occ.Act {
|
||||
return occ.Act{"verb": "knowledge-base.accept", "option": option, "ask": a.ID, "kind": r.Kind,
|
||||
"number": strconv.Itoa(r.Number), "version": strconv.Itoa(a.Version), "digest": r.Digest()}
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ const AskGlance = 1
|
||||
// composeAsk is the ask for a record, composed from the record and its ask alone: asked once, and composed
|
||||
// again to hold the warrant to it — in the form it was asked in, so an ask made before a form changed is still
|
||||
// held to the words the operator was shown.
|
||||
func composeAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
func composeAsk(r *Record, a *OperatorAsk) oc.Ask {
|
||||
if a.Form == AskGlance {
|
||||
return glanceAsk(r, a)
|
||||
}
|
||||
@@ -101,10 +102,10 @@ func composeAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
// points; who proposed it, its review, its fingerprint and how to read every clause are its Details, which the
|
||||
// router notes after the answers. A record without a brief (one proposed before the rule) is asked with its
|
||||
// title as its summary. The clauses are never listed.
|
||||
func glanceAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
func glanceAsk(r *Record, a *OperatorAsk) oc.Ask {
|
||||
name := r.Key().String()
|
||||
headline, explanation := "Approve "+name+"?", name+" needs your approval before it holds."
|
||||
if t := strings.TrimSuffix(strings.TrimSpace(r.Title), "."); shown(t) && len([]rune(t)) < asks.SummaryLength {
|
||||
if t := strings.TrimSuffix(strings.TrimSpace(r.Title), "."); shown(t) && len([]rune(t)) < occ.SummaryLength {
|
||||
explanation = t + "."
|
||||
}
|
||||
if r.Brief != nil && len(briefProblems(r.Brief)) == 0 {
|
||||
@@ -120,12 +121,12 @@ func glanceAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
}
|
||||
details := fmt.Sprintf("%s, proposed by %s; the knowledge base's own review approved it. Fingerprint %s.\n%s",
|
||||
name, author, fingerprint(r.Digest()), clauses)
|
||||
return withOptions(r, a, asks.Ask{ID: a.ID, Headline: headline, Explanation: explanation, Details: details})
|
||||
return withOptions(r, a, oc.Ask{ID: a.ID, Headline: headline, Explanation: explanation, Details: details})
|
||||
}
|
||||
|
||||
// listedAsk is the ask as it was composed before the brief: every clause's lead listed. Composed only to hold
|
||||
// the warrant of an ask made then.
|
||||
func listedAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
func listedAsk(r *Record, a *OperatorAsk) oc.Ask {
|
||||
name := r.Key().String()
|
||||
headline := "Accept " + name + "?"
|
||||
var b strings.Builder
|
||||
@@ -150,21 +151,21 @@ func listedAsk(r *Record, a *OperatorAsk) asks.Ask {
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(&b, "\n\nRead it whole with the knowledge base's get, number %d; its fingerprint is %s.", r.Number, fingerprint(r.Digest()))
|
||||
return withOptions(r, a, asks.Ask{ID: a.ID, Headline: headline, Explanation: b.String()})
|
||||
return withOptions(r, a, oc.Ask{ID: a.ID, Headline: headline, Explanation: b.String()})
|
||||
}
|
||||
|
||||
// withOptions is an ask with what every form of it carries: who answers, its expiry, what it is about, and its
|
||||
// two options, each binding its act.
|
||||
func withOptions(r *Record, a *OperatorAsk, out asks.Ask) asks.Ask {
|
||||
out.Who, out.Expires = asks.Operator, a.At.Add(AskLasts)
|
||||
func withOptions(r *Record, a *OperatorAsk, out oc.Ask) oc.Ask {
|
||||
out.Who, out.Expires = occ.Operator, occ.FormatTime(a.At.Add(AskLasts))
|
||||
out.OnExpiry = "the record stays proposed; nothing of it is in force"
|
||||
out.About = "knowledge." + r.Kind + "." + strconv.Itoa(r.Number)
|
||||
for _, o := range []struct{ id, label, does string }{
|
||||
{OptionApprove, "Approve", "the record is accepted and its clauses are in force"},
|
||||
{OptionDecline, "Decline", "the record stays proposed; nothing of it is in force"},
|
||||
} {
|
||||
binds, _ := asks.ActDigest(act(r, a, o.id))
|
||||
out.Options = append(out.Options, asks.Option{ID: o.id, Label: o.label, Does: o.does, Level: asks.Approve, Binds: binds})
|
||||
binds, _ := occ.ActDigest(act(r, a, o.id))
|
||||
out.Options = append(out.Options, oc.Option{ID: o.id, Label: o.label, Does: o.does, Level: occ.Approve, Binds: binds})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -204,7 +205,7 @@ func (k *KB) askOperator(ctx context.Context, held *Entry, w *Record, by string,
|
||||
}
|
||||
oa := &OperatorAsk{ID: newAskID(w), At: k.now(), Version: version, Said: AskWaiting, Form: AskGlance}
|
||||
ask := composeAsk(w, oa)
|
||||
if err := ask.Check(k.now()); err != nil {
|
||||
if err := occ.Check(ask, k.now()); err != nil {
|
||||
return unasked(fmt.Sprintf("the ask could not be made (%v)", err))
|
||||
}
|
||||
w.Ask = oa
|
||||
@@ -213,7 +214,7 @@ func (k *KB) askOperator(ctx context.Context, held *Entry, w *Record, by string,
|
||||
return "", fmt.Errorf("%s: the review could not be kept (%v); the operator was not asked", w.Key(), err)
|
||||
}
|
||||
k.emit(EventReviewed, w, by, "approved; the operator is asked", held.Versions+1)
|
||||
if err := k.Asks.Publish(asks.AskSubject(Module), ask, ask.ID); err != nil {
|
||||
if err := k.Asks.Publish(oc.AcceptSubjectAsk(Module), ask, ask.ID); err != nil {
|
||||
k.logf("[mesh-knowledge] the ask for %s could not be published: %v", w.Key(), err)
|
||||
return unasked(fmt.Sprintf("the operator could not be asked (%v)", err))
|
||||
}
|
||||
@@ -224,9 +225,9 @@ func (k *KB) askOperator(ctx context.Context, held *Entry, w *Record, by string,
|
||||
type routerRecord struct {
|
||||
State string `json:"state"`
|
||||
// Held is why no channel can carry the ask yet, while its state is held (ADR 0397).
|
||||
Held string `json:"held"`
|
||||
Ask *asks.Ask `json:"ask"`
|
||||
Warrant *asks.Warrant `json:"warrant"`
|
||||
Held string `json:"held"`
|
||||
Ask *oc.Ask `json:"ask"`
|
||||
Warrant *oc.Warrant `json:"warrant"`
|
||||
}
|
||||
|
||||
// Reconcile decides every record waiting for the operator whose ask the router has closed: accepted on a warrant
|
||||
@@ -319,10 +320,10 @@ func (k *KB) endAsk(ctx context.Context, e *Entry, w *Record, why string) string
|
||||
}
|
||||
|
||||
// decide holds one closed ask's warrant to the record, and accepts the record when it is the operator's Approve.
|
||||
func (k *KB) decide(ctx context.Context, e *Entry, w *Record, warrant asks.Warrant) string {
|
||||
func (k *KB) decide(ctx context.Context, e *Entry, w *Record, warrant oc.Warrant) string {
|
||||
w = w.Clone()
|
||||
w.Ask.Held = "" // an ask that ended is held no longer
|
||||
if warrant.Outcome != asks.OutcomeChosen {
|
||||
if warrant.Outcome != occ.OutcomeChosen {
|
||||
why := "ended " + string(warrant.Outcome)
|
||||
if warrant.Words != "" {
|
||||
why += " (" + warrant.Words + ")"
|
||||
@@ -330,9 +331,9 @@ func (k *KB) decide(ctx context.Context, e *Entry, w *Record, warrant asks.Warra
|
||||
return k.endAsk(ctx, e, w, why)
|
||||
}
|
||||
ask := composeAsk(w, w.Ask)
|
||||
option, err := warrant.For(Module, ask)
|
||||
option, err := occ.For(warrant, Module, ask)
|
||||
if err == nil {
|
||||
err = option.Performs(act(w, w.Ask, option.ID))
|
||||
err = occ.Performs(option, act(w, w.Ask, option.ID))
|
||||
}
|
||||
if err != nil {
|
||||
k.logf("[mesh-knowledge] REFUSED the answer to the ask for %s: %v", w.Key(), err)
|
||||
@@ -341,15 +342,15 @@ func (k *KB) decide(ctx context.Context, e *Entry, w *Record, warrant asks.Warra
|
||||
switch option.ID {
|
||||
case OptionApprove:
|
||||
w = w.Clone()
|
||||
w.Ask.Said, w.Ask.Warrant = AskApproved, warrant.Says()
|
||||
r, err := k.accept(ctx, e, w, "the operator", "accepted on the operator's Approve after the knowledge base's review", "warrant: "+warrant.Says())
|
||||
w.Ask.Said, w.Ask.Warrant = AskApproved, occ.Says(warrant)
|
||||
r, err := k.accept(ctx, e, w, "the operator", "accepted on the operator's Approve after the knowledge base's review", "warrant: "+occ.Says(warrant))
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return fmt.Sprintf("%s: %s on the operator's warrant (%s)", r.Key(), r.Status, warrant.Says())
|
||||
return fmt.Sprintf("%s: %s on the operator's warrant (%s)", r.Key(), r.Status, occ.Says(warrant))
|
||||
case OptionDecline:
|
||||
w = w.Clone()
|
||||
w.Ask.Warrant = warrant.Says()
|
||||
w.Ask.Warrant = occ.Says(warrant)
|
||||
return k.endAsk(ctx, e, w, "declined by the operator")
|
||||
}
|
||||
return k.endAsk(ctx, e, w, "was answered with "+option.ID+", which it does not offer")
|
||||
@@ -357,8 +358,8 @@ func (k *KB) decide(ctx context.Context, e *Entry, w *Record, warrant asks.Warra
|
||||
|
||||
// HeardEnd takes the router's word that one of this module's asks ended without a choice: nothing is accepted on
|
||||
// such a word, so it needs no proof beyond its subject. A choice is only ever taken from the router's record.
|
||||
func (k *KB) HeardEnd(w asks.Warrant) {
|
||||
if w.Asker != Module || w.Outcome == asks.OutcomeChosen {
|
||||
func (k *KB) HeardEnd(w oc.Warrant) {
|
||||
if w.Asker != Module || w.Outcome == occ.OutcomeChosen {
|
||||
if _, err := k.Reconcile(); err != nil {
|
||||
k.logf("[mesh-knowledge] reading the router's answers: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user