feat(cli): v0.9 contract harmonization

Make the agent-facing contract uniform across the whole surface:

- cobra parse errors (unknown flag, arg-count) emit the JSON envelope by
  default, not bare prose — via a single DefaultFormatMode shared by the early
  resolver and ResolveDefault.
- a malformed --jq is input.invalid_argument (exit 5), not internal.error.
- destructive-confirmation messages name the real operation (edit/remove,
  not a hardcoded "delete").
- `doc wait` emits one envelope (Silent failure, no contradictory stderr);
  completed marshals as [] not null.
- WEKNORA_AGENT_HELP covers every leaf command, enforced by a coverage drift
  guard; a sibling guard enforces --dry-run on every mutation.
- `search docs`/`search chunks` resolve --kb through the same
  flag→env→project-link chain as `doc list`/`chat` (no longer a hard --kb
  requirement); a linked dir or WEKNORA_KB_ID now works without --kb, and an
  unresolved KB is local.kb_id_required (exit 1). The destructive
  `doc delete --all` keeps its explicit-only rule.
- exit-code and batch/wait ok-semantics documented in the shared skill, README,
  and AGENTS.md.
This commit is contained in:
nullkey
2026-05-29 20:06:53 +08:00
committed by lyingbug
parent 5f98df530c
commit 77b9b6a465
25 changed files with 590 additions and 98 deletions
+24
View File
@@ -12,6 +12,30 @@ CLI history before v0.3 is recorded in the project root
## [Unreleased]
### v0.9 — auth/profile model harmonization + flag cleanup
#### Added
- `weknora session stop <session-id>` command to abort an in-flight agent run.
- `profile add --use`: switch to the newly-added profile immediately (instead of only auto-selecting the first profile added).
- `-L` shorthand on `session view` (alias for `--limit`).
- `doc download --format json` now emits a success envelope (was bare).
- `SetAgentHelp` coverage extended across create / list / search commands.
#### Changed
- `auth login` now authenticates the **active profile** (resolved from config / global `--profile`) instead of creating a profile. Re-login MERGES credential refs into the existing record — host and an existing user are preserved, never clobbered.
#### Breaking
- **`--kb` now accepts a knowledge-base name *or* id** on `doc delete --all` and `search chunks` / `search docs`; it stays required (no silent project-link fallback on these commands).
- **`agent create --kb` renamed to `--attach-kb`** to disambiguate from the global `--kb` scope flag.
- **MCP tool `agent_invoke` renamed to `session_ask`** (clean rename — external MCP clients must update cached tool schemas).
- **`auth login` drops `--host` and `--name`.** It authenticates the active profile; create it first with `weknora profile add <name> --host <h> --use`. Target a non-active profile with the global `weknora --profile <name> auth login`.
- **`auth logout` and `auth refresh` drop `--name`.** They act on the active profile; target another with the global `--profile <name>`.
#### Removed
- Dead MCP error codes `mcp.readonly_mode`, `mcp.tool_not_allowed`, and `mcp.schema_unknown_command` (never emitted by the current tool surface).
---
### v0.8 — Agent safety nets + MCP annotations
#### Added