An owed act met by the forge away (401 while the store was replaced) ended could not be performed and nothing performed it again. Each act is now a kept call at the module's pace (kept-call-pace-first, kept-call-pace-max) until owed-away-bound (60 minutes), then ends could not be performed naming every try. Before each try the bridge reads the pull request through the seat git's pull: one closed unmerged ends owed.ended not-needed, never performed. The gate's owed event gains record (the delivery record's source revision), kept with the act in performed, and bridge_owed_again by record and why performs again every act of that record that ended could not be performed, written in the hand-act log first. Builds: design 47 H2 §807, §775, §819, H-A-432
195 lines
8.6 KiB
Go
195 lines
8.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
|
|
|
"mesh-delivery-forge-bridge/internal/groups"
|
|
)
|
|
|
|
// The tools of what the bridge performs of what is owed to the forge (novox/hq design 47 *What the gate owes the forge*).
|
|
const (
|
|
OwedTool = "bridge_owed"
|
|
OwedAgainTool = "bridge_owed_again"
|
|
OwedDropTool = "bridge_owed_drop"
|
|
)
|
|
|
|
// OwedRow is one act the bridge performed, as the state performed keeps it: the outcome said as owed.ended, and the pull
|
|
// request the act names (groups.Performed).
|
|
type OwedRow struct {
|
|
forgemsg.OwedEnded
|
|
Repository string `json:"repository,omitempty"`
|
|
Number int `json:"number,omitempty"`
|
|
}
|
|
|
|
// OwedFilter is what bridge_owed reads of performed: one act (its id, of narrowing it to one key) or one pull request's
|
|
// acts (repository and number), never the whole state (novox/hq design 47 H-A-181).
|
|
type OwedFilter struct {
|
|
Of, ID, Repository string
|
|
Number int
|
|
}
|
|
|
|
func (f OwedFilter) holds(r OwedRow) bool {
|
|
return (f.Of == "" || r.Of == f.Of) && (f.ID == "" || r.ID == f.ID) &&
|
|
(f.Repository == "" || (r.Repository == f.Repository && r.Number == f.Number))
|
|
}
|
|
|
|
// performedRows reads the acts of performed f names, newest first: one key when f names the seat and the id, else each
|
|
// key's value held to f. A key that is not an act (a group end's bookkeeping) is left.
|
|
func performedRows(s stdio.KeptState, f OwedFilter) ([]OwedRow, error) {
|
|
var keys []string
|
|
if f.Of != "" && f.ID != "" {
|
|
keys = []string{groups.PerformedKey(f.Of, f.ID)}
|
|
} else {
|
|
all, err := s.Keys()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the bridge's performed state cannot be listed: %w", err)
|
|
}
|
|
keys = all
|
|
}
|
|
rows := []OwedRow{}
|
|
for _, k := range keys {
|
|
e, err := s.Get(k)
|
|
if err != nil || e == nil {
|
|
continue
|
|
}
|
|
var p groups.Performed
|
|
if json.Unmarshal(e.Value, &p) == nil && p.Ended.Of != "" {
|
|
if r := (OwedRow{OwedEnded: p.Ended, Repository: p.Repository, Number: p.Number}); f.holds(r) {
|
|
rows = append(rows, r)
|
|
}
|
|
}
|
|
}
|
|
sort.Slice(rows, func(i, j int) bool { return rows[i].At.After(rows[j].At) })
|
|
return rows, nil
|
|
}
|
|
|
|
// OwedTools are bridge_owed, bridge_owed_again and bridge_owed_drop: ask writes an owed-asks value and waits for the
|
|
// bridge's answer; performed reads the state performed; record writes a hand act in the seat mesh-hand-acts' log (what,
|
|
// why and its cause) before a drop or a record's acts performed again is asked, so neither is made without its record.
|
|
func OwedTools(ask func(key string, value []byte) ([]byte, error), performed func(OwedFilter) ([]OwedRow, error), record func(what, why, cause string) error, now func() time.Time) []stdio.Tool {
|
|
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
|
|
act := map[string]any{
|
|
"of": map[string]any{"type": "string", "description": "the seat that said the act: mesh-delivery (the gate)"},
|
|
"id": map[string]any{"type": "string", "description": "the act's id, as owed and owed.ended say it"}}
|
|
asked := func(kind string, args map[string]any) (groups.OwedAsk, error) {
|
|
key, value, err := groups.NewOwedAsk(kind, str(args, "of"), str(args, "id"), str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return groups.OwedAsk{}, err
|
|
}
|
|
v, err := ask(key, value)
|
|
if err != nil {
|
|
return groups.OwedAsk{}, err
|
|
}
|
|
return groups.DecodeOwedAsk(v)
|
|
}
|
|
read := map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "the pull request's repository, as owner/name; with number"},
|
|
"number": map[string]any{"type": "integer", "description": "the pull request's number; with repository"}}
|
|
for k, v := range act {
|
|
read[k] = v
|
|
}
|
|
againArgs := map[string]any{
|
|
"record": map[string]any{"type": "string", "description": "instead of of and id: a delivery record's source revision, <branch>.<source>; with why"},
|
|
"why": map[string]any{"type": "string", "description": "with record: why its acts are performed again, in plain words"}}
|
|
for k, v := range act {
|
|
againArgs[k] = v
|
|
}
|
|
withWhy := map[string]any{"why": map[string]any{"type": "string", "description": "why it is dropped, in plain words"}}
|
|
for k, v := range act {
|
|
withWhy[k] = v
|
|
}
|
|
return []stdio.Tool{
|
|
{Name: OwedTool,
|
|
Description: "What the forge bridge performed of what the gate and the checker owe the forge (design 47): each act it said as " +
|
|
"owed.ended, newest first, with its seat, id, pull request, outcome (performed, refused, could not be performed, " +
|
|
"undecodable, dropped, not-needed), the forge's words and when, from its state performed (kept 3 days), of one act (id, of " +
|
|
"narrowing it) or of one pull request (repository and number), never the whole state; and the backlog of its " +
|
|
"durable on each seat's stream owed: the last event applied, the events waiting and held, the age of the oldest. " +
|
|
"Read-only.",
|
|
Input: map[string]any{"type": "object", "properties": read},
|
|
Run: func(args map[string]any) (any, error) {
|
|
f := OwedFilter{Of: str(args, "of"), ID: str(args, "id"), Repository: str(args, "repository")}
|
|
if n, ok := args["number"].(float64); ok {
|
|
f.Number = int(n)
|
|
}
|
|
if f.ID == "" && (f.Repository == "" || f.Number <= 0) {
|
|
return nil, fmt.Errorf("bridge_owed reads one act (id) or one pull request's acts (repository and number), never the whole state")
|
|
}
|
|
rows, err := performed(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := map[string]any{"performed": rows}
|
|
if a, err := asked(groups.OwedBacklog, args); err != nil {
|
|
out["backlog-error"] = err.Error()
|
|
} else {
|
|
out["backlog"] = a.Backlog
|
|
}
|
|
return out, nil
|
|
}},
|
|
{Name: OwedAgainTool,
|
|
Description: "Perform one act owed to the forge again now, by hand, whatever its last outcome (a refusal the forge no longer " +
|
|
"makes, an act that could not be performed): the bridge calls the seat git's verb of the act under its id (safe to " +
|
|
"repeat) and says its outcome as owed.ended. The act is read from the stream owed of the seat that said it, on the " +
|
|
"subject of the pull request the bridge's state performed names (kept 3 days there). Or, with record (a delivery " +
|
|
"record's source revision, <branch>.<source>) and why instead of of and id, every act of that record that ended " +
|
|
"could not be performed, written first in the hand-act log (design 47 H2 §807). Each act reads its pull request " +
|
|
"again before it acts: one closed unmerged ends not-needed. Answers the outcome, or each act's.",
|
|
Input: map[string]any{"type": "object", "properties": againArgs},
|
|
Run: func(args map[string]any) (any, error) {
|
|
if rec := str(args, "record"); rec != "" {
|
|
if str(args, "of") != "" || str(args, "id") != "" {
|
|
return nil, fmt.Errorf("bridge_owed_again names one act (of and id) or one record, not both")
|
|
}
|
|
key, value, err := groups.NewOwedRecordAsk(rec, str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := record("performed again every act of the record "+rec+" that could not be performed", str(args, "why"), "owed-again"); err != nil {
|
|
return nil, err
|
|
}
|
|
v, err := ask(key, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := groups.DecodeOwedAsk(v)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"record": a.Record, "answer": a.Answer}, nil
|
|
}
|
|
a, err := asked(groups.OwedAgain, args)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"of": a.Of, "id": a.ID, "outcome": a.Outcome, "answer": a.Answer}, nil
|
|
}},
|
|
{Name: OwedDropTool,
|
|
Description: "Drop one act owed to the forge, by hand, with why: written first in the hand-act log of the seat mesh-hand-acts, " +
|
|
"then said by the bridge as owed.ended with the outcome dropped, so its owner records it answered and stops saying " +
|
|
"it again. Nothing is done at the forge. Answers the outcome said.",
|
|
Input: map[string]any{"type": "object", "required": []string{"of", "id", "why"}, "properties": withWhy},
|
|
Run: func(args map[string]any) (any, error) {
|
|
if str(args, "why") == "" {
|
|
return nil, fmt.Errorf("a drop says why")
|
|
}
|
|
if err := record(fmt.Sprintf("dropped the act %s that %s owes the forge", str(args, "id"), str(args, "of")), str(args, "why"), "owed-dropped"); err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := asked(groups.OwedDrop, args)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"of": a.Of, "id": a.ID, "outcome": a.Outcome, "answer": a.Answer}, nil
|
|
}},
|
|
}
|
|
}
|