For every watched branch the registrations name, one source revision at each registered repository's head read through git.branch, start true, a call of its own, source-moved said and no record opened; recorded in the hand-act log first, the counts answered. It refuses to run while a key of the earlier form is held, naming it (the source bucket is dropped first). Builds: design 47 H §768; H-A-15, H-A-47 (the seed opens no record; the start pass writes through its path), H-A-76 (Q-G2: numbers from 1, refuses an earlier-form key) Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
116 lines
5.7 KiB
Go
116 lines
5.7 KiB
Go
package main
|
|
|
|
// The gate's tools over its source revisions (design 47 G §83, §84, §93): gate_source reads every branch's source revision
|
|
// whole, and gate_source_again says source-moved once more for one branch, recorded first in the hand-act log of the seat
|
|
// mesh-hand-acts, so a part that missed it reads the branch's source again.
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// SourceAll is the seat verb source's answer for every branch the gate keeps a source revision of, each as the verb answers
|
|
// it for that branch, or why the branches cannot be read.
|
|
func (h *Holder) SourceAll() map[string]any {
|
|
list := h.SourceRevision("")
|
|
if list.Error != "" {
|
|
return map[string]any{"error": list.Error}
|
|
}
|
|
out := make([]seat.SourceAnswer, 0, len(list.Branches))
|
|
for _, b := range list.Branches {
|
|
out = append(out, h.SourceRevision(b))
|
|
}
|
|
return map[string]any{"branches": out}
|
|
}
|
|
|
|
// SourceAgain says source-moved again for one branch with the revision its key holds now, after the hand-act log took it:
|
|
// nothing is said when the log did not take it, or the branch has no source key.
|
|
func (h *Holder) SourceAgain(branch, why, by string, acts handActs) (map[string]any, error) {
|
|
if strings.TrimSpace(branch) == "" || strings.TrimSpace(why) == "" {
|
|
return nil, errors.New("say the branch and why its source-moved is said again")
|
|
}
|
|
if h.Source == nil || h.SaySeat == nil {
|
|
return nil, errors.New("this gate keeps no source or says no events")
|
|
}
|
|
held, _, err := h.Source.Read(branch)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if held == nil {
|
|
return nil, fmt.Errorf("the gate keeps no source revision of the branch %s", branch)
|
|
}
|
|
if acts == nil {
|
|
return nil, errors.New("the hand-act log cannot be reached here, so nothing was said")
|
|
}
|
|
if _, err := acts.Record(meshhandactsclient.Request{What: "said source-moved again for the branch " + branch,
|
|
Why: why, Cause: "gate_source_again", Verb: "source-again"}); err != nil {
|
|
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was said: %w", err)
|
|
}
|
|
at := h.Now().UTC()
|
|
escaped, number := keys.EscapeName(branch), strconv.FormatInt(held.Source, 10)
|
|
id := "source-moved." + escaped + "." + number + ".again." + strconv.FormatInt(at.UnixNano(), 10)
|
|
e := seat.SourceMovedEvent{V: 1, Branch: branch, Source: held.Source, Call: held.Call, Heads: []seat.SourceMovedEventHeadsItem{}}
|
|
for _, r := range sortedKeys(held.Heads) {
|
|
e.Heads = append(e.Heads, seat.SourceMovedEventHeadsItem{Repository: r, Commit: held.Heads[r]})
|
|
}
|
|
if err := h.SaySeat(seat.SubjectSourceMoved(escaped, number), e, id); err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]any{"said": "source-moved", "branch": branch, "source": held.Source, "call": held.Call, "by": by}, nil
|
|
}
|
|
|
|
// sourceTools are the source's tools; acts is the hand-act log.
|
|
func sourceTools(h *Holder, acts handActs) []stdio.Tool {
|
|
return []stdio.Tool{
|
|
{Name: "gate_source",
|
|
Description: "Every branch's source revision the gate keeps, each whole: its repositories with their trunk branch and head, " +
|
|
"the merge call that moved it last and its source revision. Read, never written.",
|
|
Run: func(map[string]any) (any, error) { return h.SourceAll(), nil }},
|
|
{Name: "gate_source_again",
|
|
Description: "Say source-moved again for one branch, with the revision its source key holds now, for a part that missed it; " +
|
|
"recorded in the hand-act log of the seat mesh-hand-acts first.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"branch": str("the watched branch"), "why": str("why it is said again, in plain words")},
|
|
"required": []string{"branch", "why"}},
|
|
Run: func(a map[string]any) (any, error) {
|
|
return h.SourceAgain(strArg(a, "branch"), strArg(a, "why"), stdio.CallerOf(a), acts)
|
|
}},
|
|
{Name: "gate_source_seed",
|
|
Description: "Seed every watched branch's first source revision at the clean state (design 47 H §768): for every watched " +
|
|
"branch the registrations name, one source revision at each registered repository's current head read from the forge, " +
|
|
"start true, then source-moved; no record. Recorded in the hand-act log of the seat mesh-hand-acts first. It refuses " +
|
|
"to run while a source key of the earlier form is held, naming it. Answers the branches and repositories written, counted.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{"why": str("why the sources are seeded, in plain words")},
|
|
"required": []string{"why"}},
|
|
Run: func(a map[string]any) (any, error) { return h.SourceSeed(strArg(a, "why"), stdio.CallerOf(a), acts) }},
|
|
{Name: "gate_source_start",
|
|
Description: "Start the source of one watched branch the registrations name and no source key holds yet, from the forge: each " +
|
|
"registered repository at the branch's head, one source revision with a call of its own, then source-moved; recorded in the hand-act log of the seat " +
|
|
"mesh-hand-acts first. A key the gate holds is never rewritten.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{
|
|
"branch": str("the watched branch"), "why": str("why it is started by hand, in plain words")},
|
|
"required": []string{"branch", "why"}},
|
|
Run: func(a map[string]any) (any, error) {
|
|
return h.SourceStart(strArg(a, "branch"), strArg(a, "why"), stdio.CallerOf(a), acts)
|
|
}},
|
|
}
|
|
}
|
|
|
|
// sortedKeys are a map's keys, sorted.
|
|
func sortedKeys(m map[string]string) []string {
|
|
out := make([]string, 0, len(m))
|
|
for k := range m {
|
|
out = append(out, k)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|