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:
nullkey
2026-06-26 20:40:59 +08:00
committed by lyingbug
parent 445a4330fa
commit 6f8b825f5f
151 changed files with 7305 additions and 733 deletions
+16 -1
View File
@@ -70,6 +70,11 @@ Pass --full to also load the chat history (LoadMessages SDK call). Use
return err
}
fopts.ResolveDefault(iostreams.IO.IsStdoutTTY())
// Validate static input before building the client so a bad --limit
// returns input.invalid_argument (exit 5), not an auth error (exit 3).
if err := validateViewOpts(opts); err != nil {
return err
}
cli, err := f.Client()
if err != nil {
return err
@@ -89,7 +94,10 @@ Pass --full to also load the chat history (LoadMessages SDK call). Use
return cmd
}
func runView(ctx context.Context, opts *ViewOptions, fopts *cmdutil.FormatOptions, svc ViewService, id string) error {
// validateViewOpts checks the --limit/--full invariants. Called from RunE
// before the client is built (so a bad value surfaces as exit 5, not an auth
// error) and at runView's top for direct callers; idempotent.
func validateViewOpts(opts *ViewOptions) error {
if !opts.Full && opts.LimitSet {
return &cmdutil.Error{
Code: cmdutil.CodeInputInvalidArgument,
@@ -104,6 +112,13 @@ func runView(ctx context.Context, opts *ViewOptions, fopts *cmdutil.FormatOption
}
}
}
return nil
}
func runView(ctx context.Context, opts *ViewOptions, fopts *cmdutil.FormatOptions, svc ViewService, id string) error {
if err := validateViewOpts(opts); err != nil {
return err
}
s, err := svc.GetSession(ctx, id)
if err != nil {