From b20048bd1842a322514f7d3033e7eb75bf26f237 Mon Sep 17 00:00:00 2001 From: Tuan Ngo Date: Sun, 28 Jun 2026 16:58:48 +0700 Subject: [PATCH] feat: Add sloop check, a manifest-driven AI-readiness checklist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `sloop check` runs a best-practices checklist for the current workspace — AGENTS.md present, context delivered to each enabled tool, skills linked, status hooks installed — and prints the command that fixes each gap. It is a checklist, not a score: sloop checks presence, it can't judge content quality. The per-tool criteria are derived from each tool's adapter manifest (context/skills/hooks — the single provider-aware source) plus the on-disk delivery state, so the checklist deepens as the manifests do rather than baking in sloop's own opinions. Adds a read-only hooksInstalledFor detector (reusing the install idempotency check), a check hint (en/vi), and a README row. --- README.md | 1 + internal/cli/commands/check.go | 157 ++++++++++++++++++++++++++++ internal/cli/commands/check_test.go | 63 +++++++++++ internal/cli/commands/hooks.go | 38 +++++++ internal/cli/commands/registry.go | 1 + internal/hints/hints.yaml | 6 ++ 6 files changed, 266 insertions(+) create mode 100644 internal/cli/commands/check.go create mode 100644 internal/cli/commands/check_test.go diff --git a/README.md b/README.md index 9367756..46bcf93 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ agents — to launch (`r`), open a shell (`s`), `c` to copy a `cd`, or `Enter` t | `hooks install\|list\|print [tool]` | — | — | Wire a tool's own hooks so `ps` status is authoritative. | | `tools` | — | — | Capability matrix (context / skills / hooks per tool). | | `status` | `st` | — | One-screen workspace summary. | +| `check` | — | — | AI-readiness checklist for the workspace (AGENTS.md, context, skills, hooks) with a fix command per gap. | | `ls` | — | — | Registered workspaces + recent sessions. | | `doctor` | — | — | Environment health (tools, multiplexer, mode). | | `hints [list\|on\|off]` | — | — | Contextual education tips (en/vi). | diff --git a/internal/cli/commands/check.go b/internal/cli/commands/check.go new file mode 100644 index 0000000..d23ee22 --- /dev/null +++ b/internal/cli/commands/check.go @@ -0,0 +1,157 @@ +package commands + +import ( + "fmt" + "io" + "os" + + "github.com/spf13/cobra" + + "github.com/stroops/sloop/internal/adapter" + "github.com/stroops/sloop/internal/config" + "github.com/stroops/sloop/internal/hints" + syncpkg "github.com/stroops/sloop/internal/sync" + "github.com/stroops/sloop/internal/tui" + "github.com/stroops/sloop/internal/workspace" +) + +// checkItem is one readiness line: whether it passed, a label, and the command +// that fixes it when it hasn't. Info items are advisory (not counted as a gap). +type checkItem struct { + OK bool + Info bool + Label string + Fix string +} + +// readinessChecklist builds the workspace readiness checklist. Criteria are NOT +// sloop's own opinion: the per-tool checks are derived from each enabled tool's +// adapter manifest (context/skills/hooks — the single provider-aware source) and +// the on-disk delivery state. Only workspace-level basics (AGENTS.md, a default +// tool) are sloop's own minimal model. Pure aside from filesystem reads, so it's +// directly testable. +func readinessChecklist(root, sloopDir string, proj *config.Project, manifests map[string]adapter.Manifest) []checkItem { + var items []checkItem + + // Workspace-level basics. + items = append(items, checkItem{ + OK: syncpkg.AgentsState(root) == "ok", + Label: "AGENTS.md present (canonical context)", + Fix: "sloop init", + }) + _, hasDefault := manifests[proj.DefaultTool] + items = append(items, checkItem{ + OK: proj.DefaultTool != "" && hasDefault, + Label: "Default tool set in .sloop/config.yaml", + Fix: "set default_tool in .sloop/config.yaml", + }) + + // Per enabled tool, sourced from its manifest. + hasSkills := skillCount(sloopDir) > 0 + for _, t := range proj.Tools { + m, ok := manifests[t] + if !ok { + continue + } + + // Context delivery (pointer-mode tools only; native tools need nothing). + switch syncpkg.ContextState(root, m) { + case "ok": + items = append(items, checkItem{OK: true, Label: m.Name + ": context delivered (" + m.Context.File + ")"}) + case "foreign": + items = append(items, checkItem{Label: m.Name + ": " + m.Context.File + " is a hand-authored file, not a sloop pointer", Fix: "sloop sync --repair"}) + case "missing": + items = append(items, checkItem{Label: m.Name + ": context pointer not delivered (" + m.Context.File + ")", Fix: "sloop sync"}) + } + + // Skills linked — only relevant once there are skills to deliver. + if m.Skills.Target != "" && hasSkills { + if syncpkg.SkillsState(root, sloopDir, m) == "linked" { + items = append(items, checkItem{OK: true, Label: m.Name + ": skills linked"}) + } else { + items = append(items, checkItem{Label: m.Name + ": skills not linked into " + m.Skills.Target, Fix: "sloop sync"}) + } + } + + // Status hooks — only flag tools sloop can auto-install for. + if hookInstaller(m.Hooks.Install) != nil { + if hooksInstalledFor(root, m) { + items = append(items, checkItem{OK: true, Label: m.Name + ": status hooks installed"}) + } else { + items = append(items, checkItem{Label: m.Name + ": status hooks not installed", Fix: "sloop hooks install " + t}) + } + } + } + + return items +} + +// renderChecklist writes the checklist with ✓/✗ marks, a fix command per gap, +// and a one-line summary — a checklist of best practices, deliberately not a +// score (sloop checks presence, it can't judge content quality). +func renderChecklist(w io.Writer, name string, items []checkItem) { + _, _ = fmt.Fprintf(w, "⚓ Workspace readiness — %s\n\n", tui.Bold(name)) + gaps := 0 + for _, it := range items { + switch { + case it.OK: + _, _ = fmt.Fprintf(w, " %s %s\n", tui.Green("✓"), it.Label) + case it.Info: + _, _ = fmt.Fprintf(w, " %s %s\n", tui.Grey("•"), it.Label) + default: + gaps++ + line := fmt.Sprintf(" %s %s", tui.Yellow("✗"), it.Label) + if it.Fix != "" { + line += tui.Grey(" → " + it.Fix) + } + _, _ = fmt.Fprintln(w, line) + } + } + if gaps == 0 { + _, _ = fmt.Fprintf(w, "\n%s\n", tui.Green("Ready — every best practice is in place.")) + return + } + _, _ = fmt.Fprintf(w, "\n%s\n", tui.Yellow(fmt.Sprintf("%d to improve", gaps))+tui.Grey(" — run the suggested commands above.")) +} + +// RunCheck resolves the workspace and prints its readiness checklist. +func RunCheck(startDir string, w io.Writer) error { + ws, err := workspace.Resolve(startDir) + if err != nil { + return err + } + proj, err := config.LoadProject(ws.SloopDir()) + if err != nil { + return err + } + manifests, err := adapter.Load() + if err != nil { + return err + } + renderChecklist(w, ws.Name, readinessChecklist(ws.Root, ws.SloopDir(), proj, manifests)) + return nil +} + +var checkCmd = &cobra.Command{ + Use: "check", + Short: "Check this workspace against AI-readiness best practices (a checklist, not a score)", + Long: `Run a best-practices checklist for the current workspace: is AGENTS.md present, +is context delivered to each enabled tool, are skills linked, are status hooks +installed? Each gap comes with the command that fixes it. + +The per-tool criteria come from each tool's adapter manifest (context/skills/ +hooks), not from sloop's own opinion — so they deepen as the manifests do.`, + RunE: func(cmd *cobra.Command, args []string) error { + cwd, err := os.Getwd() + if err != nil { + return err + } + if err := RunCheck(cwd, cmd.OutOrStdout()); err != nil { + return err + } + hints.Show(cmd.OutOrStdout(), "check") + return nil + }, +} + +func RegisterCheck(cmd *cobra.Command) { cmd.AddCommand(checkCmd) } diff --git a/internal/cli/commands/check_test.go b/internal/cli/commands/check_test.go new file mode 100644 index 0000000..059e8e9 --- /dev/null +++ b/internal/cli/commands/check_test.go @@ -0,0 +1,63 @@ +package commands + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stroops/sloop/internal/adapter" + "github.com/stroops/sloop/internal/config" +) + +// labelOf finds the check item whose label contains substr. +func findItem(items []checkItem, substr string) (checkItem, bool) { + for _, it := range items { + if strings.Contains(it.Label, substr) { + return it, true + } + } + return checkItem{}, false +} + +func TestReadinessChecklist(t *testing.T) { + root := t.TempDir() + sloopDir := filepath.Join(root, ".sloop") + if err := os.MkdirAll(sloopDir, 0o755); err != nil { + t.Fatal(err) + } + + manifests := map[string]adapter.Manifest{ + "claude": { + Name: "Claude Code", + Context: adapter.ContextSpec{Mode: "pointer", File: "CLAUDE.md"}, + Hooks: adapter.HooksSpec{Install: "settings-json", Config: ".claude/settings.local.json", Events: adapter.HookEvents{Idle: "Stop"}}, + }, + } + proj := &config.Project{Tools: []string{"claude"}, DefaultTool: "claude"} + + // Bare workspace: no AGENTS.md, no pointer, no hooks → those should be gaps. + items := readinessChecklist(root, sloopDir, proj, manifests) + + if it, ok := findItem(items, "AGENTS.md"); !ok || it.OK { + t.Fatalf("AGENTS.md should be a gap: %+v", it) + } + if it, ok := findItem(items, "Default tool"); !ok || !it.OK { + t.Fatalf("default tool should pass: %+v", it) + } + if it, ok := findItem(items, "context pointer not delivered"); !ok || it.OK || it.Fix != "sloop sync" { + t.Fatalf("missing pointer should suggest sloop sync: %+v", it) + } + if it, ok := findItem(items, "status hooks not installed"); !ok || it.OK || !strings.Contains(it.Fix, "hooks install") { + t.Fatalf("missing hooks should suggest install: %+v", it) + } + + // Now satisfy AGENTS.md → that check flips to OK. + if err := os.WriteFile(filepath.Join(root, "AGENTS.md"), []byte("# guidance\n"), 0o644); err != nil { + t.Fatal(err) + } + items = readinessChecklist(root, sloopDir, proj, manifests) + if it, ok := findItem(items, "AGENTS.md"); !ok || !it.OK { + t.Fatalf("AGENTS.md should now pass: %+v", it) + } +} diff --git a/internal/cli/commands/hooks.go b/internal/cli/commands/hooks.go index d70f693..b494e6f 100644 --- a/internal/cli/commands/hooks.go +++ b/internal/cli/commands/hooks.go @@ -204,6 +204,44 @@ func hookInstaller(strategy string) func(path string, events map[string]string) } } +// hooksInstalledFor reports whether a tool's status hooks are already wired into +// its config file (read-only; reuses the same idempotency check as install). +// Only meaningful for auto-install strategies; false when the config is absent. +func hooksInstalledFor(root string, m adapter.Manifest) bool { + events := eventCommands(m.Hooks) + if len(events) == 0 { + return false + } + path, err := resolveHookConfigPath(root, m.Hooks.Config) + if err != nil { + return false + } + b, err := os.ReadFile(path) + if err != nil { + return false + } + var doc map[string]any + if json.Unmarshal(b, &doc) != nil { + return false + } + hooks, _ := doc["hooks"].(map[string]any) + for ev, cmd := range events { + switch m.Hooks.Install { + case "settings-json": + if !hasCommandHook(hooks[ev], cmd) { + return false + } + case "cursor-json": + if !hasCursorCommand(hooks[ev], cmd) { + return false + } + default: + return false + } + } + return true +} + // resolveHookConfigPath turns a manifest config path into an absolute path: ~/… // expands to the home dir, absolute paths pass through, and a repo-relative path // is joined to the workspace root. diff --git a/internal/cli/commands/registry.go b/internal/cli/commands/registry.go index 3fea980..0090741 100644 --- a/internal/cli/commands/registry.go +++ b/internal/cli/commands/registry.go @@ -23,6 +23,7 @@ func init() { add(RegisterTools) add(RegisterDoctor) add(RegisterStatus) + add(RegisterCheck) add(RegisterLs) add(RegisterPs) add(RegisterSend) diff --git a/internal/hints/hints.yaml b/internal/hints/hints.yaml index 090fdb5..576714b 100644 --- a/internal/hints/hints.yaml +++ b/internal/hints/hints.yaml @@ -128,6 +128,12 @@ hints: en: "Inside a session, detach with your tmux prefix then d — the agent keeps working; reattach with `sloop ps`." vi: "Trong một session, detach bằng tmux prefix rồi d — agent vẫn làm việc; quay lại bằng `sloop ps`." + - id: check-readiness + context: check + text: + en: "`sloop check` is a best-practices checklist, not a score — each ✗ comes with the command that fixes it. Re-run after `sloop sync` or `hooks install`." + vi: "`sloop check` là checklist best-practice, không phải điểm số — mỗi ✗ kèm lệnh sửa. Chạy lại sau `sloop sync` hoặc `hooks install`." + - id: lang-toggle context: general text: