refactor(cli): resource-command refactors — --kb resolver, MCP session_ask, session stop (BREAKING)

Unify the --kb resolver (accepts name or UUID) across kb/doc/chunk/session/
search/chat/link; `agent create` attaches knowledge bases via --attach-kb
(no longer --kb). Rename the MCP tool agent_invoke → session_ask and drop dead
MCP error codes. Add `session stop` (StopSession), completing the
start / continue-stream / stop triad.

Across these commands, bring the agent contract up to par: --dry-run previews
on mutations (incl. kb pin/unpin, session stop), agent-help blobs on the
read/health surface, accurate destructive-confirmation verbs, and search
has_more truncation signalling so an agent can tell its results were capped.
This commit is contained in:
nullkey
2026-05-29 20:06:30 +08:00
committed by lyingbug
parent a68cc59310
commit c90f4e895e
54 changed files with 807 additions and 93 deletions
+32
View File
@@ -2,9 +2,11 @@ package kb
import (
"context"
"encoding/json"
"errors"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -104,3 +106,33 @@ func TestPin_JSON(t *testing.T) {
assert.Contains(t, body, `"is_pinned":true`)
assert.Contains(t, body, `"id":"kb_abc"`)
}
// TestPin_DryRun_NoServerCall: --dry-run must emit a kb.pin plan (exit 0)
// without reaching the server, so pin/unpin honor the same mutation-preview
// contract as create/edit/delete. Regression for pin/unpin lacking --dry-run.
func TestPin_DryRun_NoServerCall(t *testing.T) {
for _, tc := range []struct {
name, want string
cmd func(*cmdutil.Factory) *cobra.Command
}{
{"pin", "kb.pin", NewCmdPin},
{"unpin", "kb.unpin", NewCmdUnpin},
} {
t.Run(tc.name, func(t *testing.T) {
out, _ := iostreams.SetForTest(t)
root := withRootHarness(tc.cmd(kbDryRunFactory(t)), "kb_x", "--dry-run", "--format", "json")
require.NoError(t, root.Execute(), "dry-run must succeed without a client")
var env struct {
OK bool `json:"ok"`
Meta struct {
DryRun bool `json:"dry_run"`
Plan map[string]any `json:"plan"`
} `json:"meta"`
}
require.NoError(t, json.Unmarshal(out.Bytes(), &env), "got %q", out.String())
assert.True(t, env.OK)
assert.True(t, env.Meta.DryRun)
assert.Equal(t, tc.want, env.Meta.Plan["action"])
})
}
}