package console import ( "context" "errors" "log" "strings" "git.novox.be/novox/mesh-sdk/go/views" ) // FirstViewer is the tool runner's four first views as the console shows them (novox/hq ADR 0615 §6; issue 1966 TLS-6): a // Source that also is one is asked by mesh_first_views and mesh_first_view_again. type FirstViewer interface { Status() []views.Status Again(ctx context.Context, why string) []error } // firstViewsAnswer is mesh_first_views and mesh_first_view_again. func (s *Surface) firstViewsAnswer(ctx context.Context, name string, args map[string]any) map[string]any { fv, ok := s.src.(FirstViewer) if !ok { return failure("this tool runner holds no first views: it reads the indexer's and the assigner's states through " + "another source") } if name == verbFirstViews { return answerText(map[string]any{"first views": fv.Status()}) } why, _ := args["why"].(string) if why = strings.TrimSpace(why); why == "" { why = "asked by hand with no reason given" } // A hand act, recorded through the seat mesh-hand-acts (novox/hq ADR 0615 §6, ADR 0565 §10) before it is done, and in the // runner's log. One that cannot be recorded is said, and the ask is not made. log.Printf("[mesh-tools] hand act: %s asked the four first views again: %s", s.who, why) if err := s.recordAct(map[string]any{"what": "asked the tool runner's four first views again", "why": why, "cause": "first-view-again", "verb": verbFirstAgain}); err != nil { return failure("the hand act was not recorded through mesh-hand-acts, so the first views were not asked again: " + err.Error()) } out := map[string]any{"asked again": why, "recorded": "mesh-hand-acts.hand-act"} if errs := fv.Again(ctx, why); len(errs) > 0 { var msgs []string for _, e := range errs { msgs = append(msgs, e.Error()) } out["not answered"] = msgs } out["first views"] = fv.Status() return answerText(out) } // recordAct records one act done by hand through the seat mesh-hand-acts (its verb hand-act); Surface.Record replaces the call // in a test. func (s *Surface) recordAct(args map[string]any) error { if s.Record != nil { return s.Record(args) } if s.conn == nil { return errNoBus } _, err := s.conn.Ask("mesh-hand-acts.hand-act", args, "") return err } var errNoBus = errors.New("no bus connection")