64 lines
2.9 KiB
Go
64 lines
2.9 KiB
Go
// The artifact-store-tools module's Go bundle (novox/hq ADR 0251 §1–3, ADR 0571 clause 2, to-be 51): a process the
|
||
// node's runtime launches and speaks MCP over stdio to. It says what the artifact store holds — its repositories, its
|
||
// size, and what the mesh keeps of each manifest — read through the registry seats' list (novox/hq ADR 0632 §4), and it
|
||
// holds the seat mesh-artifact-sweep: the keep set, the sweep at each build's end, and S25's image-missing.
|
||
//
|
||
// **A module beside the store, not the store's own.** It requires no provision: what it reads, holds and removes it asks
|
||
// the registry seats (listed.go, sweepseats.go), never the store's files or its read side. stdout is the protocol; what this bundle says, it says on stderr.
|
||
package main
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"os"
|
||
"time"
|
||
|
||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||
meshconditions "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||
|
||
"git.novox.be/novox/mesh-sdk/go/views"
|
||
)
|
||
|
||
func logf(format string, a ...any) { fmt.Fprintf(os.Stderr, format+"\n", a...) }
|
||
|
||
func main() {
|
||
s := &Store{Ask: stdio.Ask}
|
||
v := &views.Reader{Module: "artifact-store-tools", Logf: logf, Acts: meshhandactsclient.Recorder{Ask: stdio.Ask}}
|
||
v.Follow(assignerModule, "wants", WantsTool)
|
||
v.Follow(indexerModule, "manifests", ManifestsTool)
|
||
h := &Holder{Bus: runtimeBus{views: v}, Door: DoorAt(os.Getenv("MESH_ARTIFACT_STORE_ADDRESS_FILE"), s), Listed: s.View,
|
||
Seats: stdio.Ask, Now: time.Now, Logf: logf}
|
||
h.Acts = meshhandactsclient.Recorder{Ask: stdio.Ask}
|
||
// The module's one held writer (design 47 G §689, A-16, A-29, A-32): the holder's findings and the reader's go through it.
|
||
w, err := views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||
Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State("findings"), Kinds: []string{ImageMissing, SweepRefused}})
|
||
if err != nil {
|
||
logf("%v", err)
|
||
os.Exit(1)
|
||
}
|
||
h.Findings = w
|
||
v.Findings = w
|
||
// the runtime answers the writer's subscription only once Serve has its channel
|
||
go func() {
|
||
<-stdio.Served()
|
||
if err := w.Start(context.Background()); err != nil {
|
||
logf("%v", err)
|
||
os.Exit(1)
|
||
}
|
||
}()
|
||
v.Start(context.Background())
|
||
go follow(h, v)
|
||
// An empty name serves as the module the runtime names (MESH_SERVED_MODULE): artifact-store-tools.
|
||
if err := stdio.Serve("", append(append(Tools(s, h, &Catalogue{Ask: stdio.Ask}), SeatTools(h, s)...), v.Tools("artifact_store")...)); err != nil {
|
||
fmt.Fprintln(os.Stderr, err)
|
||
os.Exit(1)
|
||
}
|
||
}
|
||
|
||
// The owners' read tools of the states the holder follows, which the manifest invokes (ADR 0615).
|
||
const (
|
||
WantsTool = assignerModule + ".assigner_read_wants"
|
||
ManifestsTool = indexerModule + ".indexer_read_manifests"
|
||
)
|