feat: add the kettle CLI, replacing the plugin's Python scripts
The plugin resolved its issue store from `__file__`, which put it inside a versioned plugin cache: issues written from one project were invisible from the next, and `origin: local` files — the only copy of that work by definition — were stranded a version bump at a time. The walk that answers "which directory is the project" was written three times over, and in a linked worktree the three disagreed. Both are runtime failures rather than logic ones, so the fix is a compiled binary: one walk, imported rather than re-derived, and a layering rule the build graph enforces instead of a grep. Seven packages, knowledge flowing one way. `project` answers which directory is the project and depends on nothing. `issue` is the domain — format, taxonomy, validation, checkboxes, dependency graph, the store, eviction — offline, with no tracker in it. `wire` holds the protocol shapes. `gitea` is the transport, `mapping` the bridge, `config` the credentials, `cmd` the command tree. Four tests hold the boundaries, each failing on a real mistake rather than a naming convention. The marker moves to `.kettle/` and the login pin moves out of the harness's settings file into `.kettle/config.yaml`, which pins a login by NAME; the tokens live in one file per machine, mode 0600, outside every working tree. That retires the PreToolUse guard hook entirely — the binary holds its own credentials, so a command running under a login nobody chose is not expressible rather than caught. `kettle init` migrates an older `tmp/issues` or `.tea/issues` store in, as a move: a store left behind at an old path is one somebody edits by accident months later. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.noodles.cam/claude-skills/marketplace/cli/internal/issue"
|
||||
)
|
||||
|
||||
func init() {
|
||||
register(&Command{
|
||||
Name: "check",
|
||||
Group: GroupIssue,
|
||||
Args: "[<id>…]",
|
||||
Short: "validate issues against the canonical format",
|
||||
Long: `The same check the sync layer runs before it pushes anything, available on its
|
||||
own so a local-only issue can be held to the format without a tracker being
|
||||
involved.
|
||||
|
||||
Errors mean malformed; warnings mean it deviates from its type's template or its
|
||||
graph looks suspect. An unticked checkbox is neither: work not done yet is the
|
||||
normal state of a perfectly well-formed issue.
|
||||
|
||||
Exit status is 1 when anything has errors, which is what makes this usable in a
|
||||
hook or a CI step.`,
|
||||
Examples: []Example{
|
||||
{"kettle check", "every issue in the store"},
|
||||
{"kettle check wire-sqlc-appclick", "one issue"},
|
||||
{"kettle check --quiet", "exit status only"},
|
||||
{"kettle check --strict", "treat warnings as errors"},
|
||||
},
|
||||
Setup: func(fs *flag.FlagSet) func([]string) error {
|
||||
quiet := fs.Bool("quiet", false, "exit status only, print nothing")
|
||||
strict := fs.Bool("strict", false, "treat warnings as errors")
|
||||
out := storeFlag(fs)
|
||||
|
||||
return func(args []string) error {
|
||||
root, err := storeRoot(*out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := issue.StoreError(root); err != nil {
|
||||
return err
|
||||
}
|
||||
issues, err := issue.LoadAll(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids := args
|
||||
if len(ids) == 0 {
|
||||
for id := range issues {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
sort.Strings(ids)
|
||||
}
|
||||
known := map[string]bool{}
|
||||
for id := range issues {
|
||||
known[id] = true
|
||||
}
|
||||
for _, id := range ids {
|
||||
if !known[id] {
|
||||
return Fail("no issue %q in %s", id, root)
|
||||
}
|
||||
}
|
||||
|
||||
bad := 0
|
||||
for _, id := range ids {
|
||||
errs, warns := issue.Validate(issues[id], known)
|
||||
if *strict {
|
||||
errs, warns = append(errs, warns...), nil
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
bad++
|
||||
}
|
||||
if *quiet {
|
||||
continue
|
||||
}
|
||||
if len(errs) == 0 && len(warns) == 0 {
|
||||
fmt.Printf("ok %s\n", id)
|
||||
continue
|
||||
}
|
||||
for _, e := range errs {
|
||||
fmt.Printf("ERROR %s: %s\n", id, e)
|
||||
}
|
||||
for _, w := range warns {
|
||||
fmt.Printf("warn %s: %s\n", id, w)
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range issue.FindCycles(issue.Graph(issues)) {
|
||||
bad++
|
||||
if !*quiet {
|
||||
fmt.Printf("ERROR cycle: %s\n", strings.Join(c, " -> "))
|
||||
}
|
||||
}
|
||||
|
||||
if !*quiet {
|
||||
fmt.Printf("%d issue(s) checked, %d with errors\n", len(ids), bad)
|
||||
}
|
||||
if bad > 0 {
|
||||
return SilentError{Code: 1}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user