From 632ceb0f85885c2b1ed53d3447d0fd9e2a3f84f2 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 9 Nov 2026 07:46:30 +1100 Subject: [PATCH] refactor: archieplaybooks is not required for some time now, webui is where playbooks are defined --- cmd/archied/main.go | 3 - internal/app/archieplaybooks/command.go | 78 ----------------- internal/app/archieplaybooks/lint.go | 29 ------ internal/app/archieplaybooks/serve.go | 112 ------------------------ 4 files changed, 222 deletions(-) delete mode 100644 internal/app/archieplaybooks/command.go delete mode 100644 internal/app/archieplaybooks/lint.go delete mode 100644 internal/app/archieplaybooks/serve.go diff --git a/cmd/archied/main.go b/cmd/archied/main.go index 06f0a9ed4..d336bae23 100644 --- a/cmd/archied/main.go +++ b/cmd/archied/main.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/samcharles93/archie-core/internal/app/archied" - "github.com/samcharles93/archie-core/internal/app/archieplaybooks" "github.com/samcharles93/archie-core/internal/app/prbench" ) @@ -35,8 +34,6 @@ func run(args []string) int { return archied.RunStatus(args[1:], os.Stdout, os.Stderr) case "prbench": return prbench.Main(args[1:], os.Stdout, os.Stderr) - case "playbooks": - return archieplaybooks.Run(args[1:], os.Stderr) } // A word that is not a subcommand is refused rather than ignored: a // stale `archied update-topology` would otherwise start a second diff --git a/internal/app/archieplaybooks/command.go b/internal/app/archieplaybooks/command.go deleted file mode 100644 index f04e2d283..000000000 --- a/internal/app/archieplaybooks/command.go +++ /dev/null @@ -1,78 +0,0 @@ -package archieplaybooks - -import ( - "context" - "flag" - "fmt" - "io" - "os" - "os/signal" - "syscall" -) - -// Run runs `archied playbooks `: lint for CI, serve for editors. -// Both use the loaders the daemon runs, so a check here cannot disagree with -// what the daemon accepts at startup. -func Run(args []string, stderr io.Writer) int { - commands := map[string]func([]string, io.Writer) int{ - "lint": runLint, - "serve": runServe, - } - - if len(args) == 0 { - fmt.Fprintln(stderr, "usage: archied playbooks [args]") - fmt.Fprintln(stderr, "commands:") - for name := range commands { - fmt.Fprintf(stderr, " %s\n", name) - } - return 2 - } - - cmd, ok := commands[args[0]] - if !ok { - fmt.Fprintf(stderr, "archied playbooks: unknown command %q\n", args[0]) - return 2 - } - return cmd(args[1:], stderr) -} - -// runLint validates an EDA playbook directory against the compiler the daemon -// runs. Exit codes: 0 clean, 1 findings, 2 usage error. -func runLint(args []string, stderr io.Writer) int { - flags := flag.NewFlagSet("archied playbooks lint", flag.ContinueOnError) - flags.SetOutput(stderr) - edaDir := flags.String("eda-dir", "", "EDA playbook directory to lint") - if err := flags.Parse(args); err != nil { - return 2 // flag.ContinueOnError already printed the message - } - if *edaDir == "" { - fmt.Fprintln(stderr, "lint: -eda-dir is required") - flags.Usage() - return 2 - } - return LintEDA(*edaDir, stderr).ExitCode -} - -// runServe runs the language server on stdin/stdout until the editor -// disconnects or the process is signalled. -func runServe(args []string, stderr io.Writer) int { - if len(args) > 0 { - fmt.Fprintln(stderr, "serve: takes no arguments; the editor speaks LSP on stdin/stdout") - return 2 - } - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer stop() - if err := Serve(ctx, stdio{}); err != nil { - fmt.Fprintln(stderr, "serve:", err) - return 1 - } - return 0 -} - -// stdio joins stdin and stdout into the one stream the language server reads -// and writes. -type stdio struct{} - -func (stdio) Read(p []byte) (int, error) { return os.Stdin.Read(p) } -func (stdio) Write(p []byte) (int, error) { return os.Stdout.Write(p) } -func (stdio) Close() error { return os.Stdin.Close() } diff --git a/internal/app/archieplaybooks/lint.go b/internal/app/archieplaybooks/lint.go deleted file mode 100644 index 0e7f7052c..000000000 --- a/internal/app/archieplaybooks/lint.go +++ /dev/null @@ -1,29 +0,0 @@ -// Package archieplaybooks implements the `archied playbooks` command, using the -// daemon's own playbook loaders. -package archieplaybooks - -import ( - "fmt" - "io" - "log/slog" - - "github.com/samcharles93/archie-core/internal/domain/eda/module" - "github.com/samcharles93/archie-core/internal/domain/eda/playbook" -) - -// Result is the outcome of one lint run: the exit code for the process and -// the human-readable findings. -type Result struct { - ExitCode int - Findings []string -} - -// LintEDA validates a directory of EDA playbook documents with the compiler -// the eda-playbooks resource validates against. -func LintEDA(dir string, stderr io.Writer) Result { - if _, err := playbook.Load(dir, module.New(slog.New(slog.DiscardHandler))); err != nil { - fmt.Fprintln(stderr, err) - return Result{ExitCode: 1, Findings: []string{err.Error()}} - } - return Result{} -} diff --git a/internal/app/archieplaybooks/serve.go b/internal/app/archieplaybooks/serve.go deleted file mode 100644 index a6460d37b..000000000 --- a/internal/app/archieplaybooks/serve.go +++ /dev/null @@ -1,112 +0,0 @@ -package archieplaybooks - -import ( - "context" - "io" - "path/filepath" - "regexp" - "strconv" - "strings" - "sync" - - "go.lsp.dev/jsonrpc2" - "go.lsp.dev/protocol" - "go.lsp.dev/uri" -) - -// Serve runs the language server over rwc until the client disconnects or ctx -// ends, publishing diagnostics for the saved directory when a playbook is -// opened or saved. -func Serve(ctx context.Context, rwc io.ReadWriteCloser) error { - s := &server{exited: make(chan struct{})} - _, conn, client := protocol.NewServer(ctx, s, jsonrpc2.NewStream(rwc)) - s.client = client - select { - case <-conn.Done(): - return nil - case <-s.exited: - case <-ctx.Done(): - } - return conn.Close() -} - -type server struct { - protocol.UnimplementedServer - client protocol.Client - // exited is closed by the exit notification. Serve closes the connection: - // closing it from inside the handler would wait on that handler. - exited chan struct{} - exitOnce sync.Once -} - -func (s *server) Initialize(context.Context, *protocol.InitializeParams) (*protocol.InitializeResult, error) { - // The server reads files from disk, so it needs opens, closes and saves, - // not content changes. - openClose, change := true, protocol.TextDocumentSyncKindNone - return &protocol.InitializeResult{ - Capabilities: protocol.ServerCapabilities{ - TextDocumentSync: &protocol.TextDocumentSyncOptions{ - OpenClose: &openClose, - Change: &change, - Save: protocol.Boolean(true), - }, - }, - ServerInfo: protocol.ServerInfo{Name: "archied-playbooks"}, - }, nil -} - -func (s *server) Shutdown(context.Context) error { return nil } - -func (s *server) Exit(context.Context) error { - s.exitOnce.Do(func() { close(s.exited) }) - return nil -} - -func (s *server) DidOpen(ctx context.Context, p *protocol.DidOpenTextDocumentParams) error { - return s.client.PublishDiagnostics(ctx, diagnose(p.TextDocument.URI)) -} - -func (s *server) DidSave(ctx context.Context, p *protocol.DidSaveTextDocumentParams) error { - return s.client.PublishDiagnostics(ctx, diagnose(p.TextDocument.URI)) -} - -func (s *server) DidClose(ctx context.Context, p *protocol.DidCloseTextDocumentParams) error { - return s.client.PublishDiagnostics(ctx, &protocol.PublishDiagnosticsParams{URI: p.TextDocument.URI, Diagnostics: []protocol.Diagnostic{}}) -} - -// diagnose lints the directory holding u's file and returns the findings that -// belong to that file: a finding naming another file of the directory belongs -// there, and one naming this file without a line (a file-level error) goes on -// its first line. -func diagnose(u uri.URI) *protocol.PublishDiagnosticsParams { - out := &protocol.PublishDiagnosticsParams{URI: u, Diagnostics: []protocol.Diagnostic{}} - if !u.IsFile() { - return out - } - path := u.FsPath() - result := LintEDA(filepath.Dir(path), io.Discard) - for _, finding := range result.Findings { - line, ok := findingLine(finding, path) - if !ok { - continue - } - out.Diagnostics = append(out.Diagnostics, protocol.Diagnostic{ - Range: protocol.Range{Start: protocol.Position{Line: line}, End: protocol.Position{Line: line + 1}}, - Severity: protocol.DiagnosticSeverityError, - Source: protocol.NewOptional("archied-playbooks"), - Message: protocol.String(finding), - }) - } - return out -} - -// findingLine places a finding on path. A compiler-style `path:line:` prefix -// gives the 0-based line; a finding naming path without a line goes on line -// 0; a finding naming another file is not path's. -func findingLine(finding, path string) (uint32, bool) { - if m := regexp.MustCompile(regexp.QuoteMeta(path) + `:(\d+):`).FindStringSubmatch(finding); m != nil { - n, _ := strconv.ParseUint(m[1], 10, 32) - return uint32(max(n, 1) - 1), true - } - return 0, strings.Contains(finding, path) -}