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
+12 -2
View File
@@ -99,7 +99,7 @@ func (o *FormatOptions) WantsJSON() bool {
// path) or as bare NDJSON lines (FormatNDJSON path). meta is optional
// (pass nil for mutation commands without batch counts).
//
// FormatJSON path: envelope is {ok:true, data:..., meta?:..., _notice?:...}.
// FormatJSON path: envelope is {ok:true, data:..., meta?:..., profile?:...}.
// Indent is determined by o.TTY (populated by ResolveDefault).
// When o.JQ is set, jq evaluates against the full envelope JSON, so users
// project with ".data[]", ".meta.count", etc.
@@ -149,13 +149,23 @@ func mapJQError(err error) error {
// - For human-readable rendering, pass --format text explicitly
func (o *FormatOptions) ResolveDefault(tty bool) {
o.TTY = tty
// Apply WEKNORA_FORMAT before the hard default so the documented
// precedence holds: explicit --format (already set on o.Mode by
// CheckFormatFlag) > WEKNORA_FORMAT > DefaultFormatMode. FromEnv is a
// no-op when --format was passed. Folded in here because nearly every
// command calls ResolveDefault but only a couple called FromEnv, so the
// env var was silently ignored on success output across the CLI.
o.FromEnv()
if o.Mode == "" {
o.Mode = DefaultFormatMode
}
}
// FromEnv reads WEKNORA_FORMAT and applies it when Mode hasn't been set
// by --format. Call between CheckFormatFlag and ResolveDefault.
// by --format. ResolveDefault now calls this, so commands get the env var
// applied automatically; explicit callers (e.g. the root PersistentPreRunE,
// which resolves the error-envelope mode before any command RunE) remain
// valid and idempotent.
//
// Invalid env values are silently ignored (the user's --format on a
// later invocation will still take precedence).