Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
157 changes: 157 additions & 0 deletions internal/cli/commands/check.go
Original file line number Diff line number Diff line change
@@ -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) }
63 changes: 63 additions & 0 deletions internal/cli/commands/check_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
38 changes: 38 additions & 0 deletions internal/cli/commands/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions internal/cli/commands/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
add(RegisterTools)
add(RegisterDoctor)
add(RegisterStatus)
add(RegisterCheck)
add(RegisterLs)
add(RegisterPs)
add(RegisterSend)
Expand Down
6 changes: 6 additions & 0 deletions internal/hints/hints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down