feat(cli): agent-first WeKnora CLI
The `weknora` command-line client for the WeKnora RAG server. Full command surface: kb / doc / chunk / session / message / agent / model / search / chat / auth / profile / link / api / mcp / skills / config / doctor / schema / exit-codes. Agent-first wire contract: JSON envelope by default, typed error codes mapped to stable exit codes, error.retry_argv / retryable / partial-failure status, global --dry-run preview, the exit-10 confirmation protocol for writes, and control/ANSI/Bidi input hygiene. Stateless env-credential auth (WEKNORA_API_KEY / WEKNORA_TOKEN + WEKNORA_HOST) for headless/CI/agent use. A curated read-only MCP tool surface (`mcp serve`) and embedded Agent Skills (`skills install`). Extensive unit + contract-golden tests and CI.
This commit is contained in:
@@ -27,8 +27,11 @@ var kbViewFields = []string{
|
||||
type ViewOptions struct{}
|
||||
|
||||
// ViewService is the narrow SDK surface this command depends on.
|
||||
// ListKnowledgeBases is used only to enrich is_pinned (the single-KB GET
|
||||
// doesn't carry per-user pin state — pin is a per-user list concept).
|
||||
type ViewService interface {
|
||||
GetKnowledgeBase(ctx context.Context, id string) (*sdk.KnowledgeBase, error)
|
||||
ListKnowledgeBases(ctx context.Context) ([]sdk.KnowledgeBase, error)
|
||||
}
|
||||
|
||||
// NewCmdView builds `weknora kb view <id>`.
|
||||
@@ -70,6 +73,18 @@ func runView(ctx context.Context, opts *ViewOptions, fopts *cmdutil.FormatOption
|
||||
if err != nil {
|
||||
return cmdutil.WrapHTTP(err, "get knowledge base %q", id)
|
||||
}
|
||||
// The single-KB GET doesn't stamp per-user pin state, so is_pinned would
|
||||
// always read false here. Enrich it from the list (the canonical pin
|
||||
// source) so the field is accurate. Best-effort: a list error leaves the
|
||||
// (unstamped) value rather than failing the view.
|
||||
if kbs, lerr := svc.ListKnowledgeBases(ctx); lerr == nil {
|
||||
for i := range kbs {
|
||||
if kbs[i].ID == id {
|
||||
kb.IsPinned = kbs[i].IsPinned
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if fopts.WantsJSON() {
|
||||
return fopts.Emit(iostreams.IO.Out, kb, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user