feat(cli): agent CRUD + view full config rendering

Adds the three management verbs missing from v0.4's agent subtree
(create / edit / delete) and expands v0.4-shipped agent view to render
all 34 AgentConfig fields in human output (was 7).

Surface: hot-path flags (--model required + 7 optional) +
--config-file YAML/JSON tail + --generate-skeleton template emit.
Flag > file > server-default precedence for hybrid invocation.

- agent create <name> --model <id> [flags] + --from <agent-id> for
  copy-then-overlay (CopyAgent + UpdateAgent); preserves source
  config except for fields explicitly overridden
- agent edit <id> with --add-kb / --remove-kb idempotent pair,
  L-2 fetch-then-update, at-least-one-flag validation,
  --description "" clearing via Flags().Changed(). --config-file
  fully replaces the AgentConfig baseline (use surgical flags for
  partial edits; the Long help spells this out + a test pins the
  contract).
- agent delete <id> with ConfirmDestructive + exit-10 protocol;
  404 propagates resource.not_found (not idempotent)
- agent view: 10 grouped sections (Identity / LLM / KB attachment /
  Retrieval / Query rewrite / Tools / FAQ / Web search / Multi-turn /
  Fallback / Templates); --json field discovery includes all
  config.* keys

Shared helper cli/internal/cmdutil/agentconfig.go handles YAML/JSON
parsing, flag-overlay-file fusion, and skeleton emission.
This commit is contained in:
nullkey
2026-05-16 02:35:30 +08:00
committed by lyingbug
parent b7f9f155b3
commit 59132a56f6
11 changed files with 1924 additions and 44 deletions
+8 -5
View File
@@ -1,7 +1,7 @@
// Package agentcmd holds the `weknora agent` command tree:
// list / view / invoke. The directory is named `agent/` (matches cobra
// noun-verb convention) but the Go package is `agentcmd` to avoid
// colliding with cobra's *cobra.Command identifier.
// list / view / invoke / create / edit / delete. The directory is named
// `agent/` (matches cobra noun-verb convention) but the Go package is
// `agentcmd` to avoid colliding with cobra's *cobra.Command identifier.
//
// "agent" in this subtree refers to WeKnora's user-defined Custom
// Agents (server resource: GET/POST /agents/...). The CLI's
@@ -23,13 +23,16 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
Use: "agent",
Short: "Manage and invoke custom agents",
Long: `Custom Agents bundle a system prompt, model, tool allow-list, and KB
scope into an addressable resource. List visible agents, view a single
agent's configuration, or invoke an agent against a query.`,
scope into an addressable resource. Create, edit, list, view, invoke,
or delete agents.`,
Args: cobra.NoArgs,
Run: func(c *cobra.Command, _ []string) { _ = c.Help() },
}
cmd.AddCommand(NewCmdList(f))
cmd.AddCommand(NewCmdView(f))
cmd.AddCommand(NewCmdInvoke(f))
cmd.AddCommand(NewCmdCreate(f))
cmd.AddCommand(NewCmdEdit(f))
cmd.AddCommand(NewCmdDelete(f))
return cmd
}