refactor: 项目更名 WeKnora → Academy
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s

- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
This commit is contained in:
runny committed 2026-11-13 20:52:51 +08:00
1 parent 9097ee699d
commit 9058149576
3136 files changed
+18018 -18004

No files matched your search

+6 -6
View File
@@ -1,21 +1,21 @@
// Package agentcmd holds the `weknora agent` command tree:
// Package agentcmd holds the `academy agent` command tree:
// list / view / create / update / delete / status / check. The directory is
// named `agent/` to match the cobra subcommand; 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
// "agent" in this subtree refers to Academy's user-defined Custom
// Agents (server resource: GET/POST /agents/...) and handles CRUD
// operations only. Agent invocation has moved to `weknora session ask
// operations only. Agent invocation has moved to `academy session ask
// --agent <id>` (see cli/cmd/session/ask.go).
package agentcmd
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// NewCmd builds the `weknora agent` parent and registers leaves. Called
// NewCmd builds the `academy agent` parent and registers leaves. Called
// from cli/cmd/root.go.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
@@ -23,7 +23,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
Short: "Manage custom agents (CRUD + status/check)",
Long: `Custom Agents bundle a system prompt, model, tool allow-list, and KB
scope into an addressable resource. Create, update, list, view, check,
or delete agents. To invoke an agent, use: weknora session ask --agent <id>`,
or delete agents. To invoke an agent, use: academy session ask --agent <id>`,
}
cmd.AddCommand(NewCmdList(f))
cmd.AddCommand(NewCmdView(f))
+8 -8
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// AgentCheckResult is the deep-verification response for `agent check <id>`.
@@ -32,7 +32,7 @@ type AgentCheckService interface {
var agentCheckFields = []string{"id", "reachable", "model_id", "kb_scope_all_reachable"}
// NewCmdCheck builds `weknora agent check <id>`.
// NewCmdCheck builds `academy agent check <id>`.
func NewCmdCheck(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "check <agent-id>",
@@ -44,11 +44,11 @@ Performs 1 + N HTTP calls:
N GET /kb/{kb_id} for each id in agent.config.knowledge_bases
— sets kb_scope_all_reachable = true iff every probe succeeds
Use 'weknora agent status <id>' for a fast read-only health snapshot
Use 'academy agent status <id>' for a fast read-only health snapshot
(1 HTTP call, no KB probing). Use 'agent check' when you need to verify
the agent's downstream dependencies are all reachable.`,
Example: ` weknora agent check ag_abc
weknora agent check ag_abc --format json`,
Example: ` academy agent check ag_abc
academy agent check ag_abc --format json`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -71,7 +71,7 @@ the agent's downstream dependencies are all reachable.`,
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "verify a custom agent end-to-end: status plus kb_scope reachability",
RequiredFlags: []string{"<agent-id> (positional)"},
Examples: []string{"weknora agent check agent_abc"},
Examples: []string{"academy agent check agent_abc"},
Output: "envelope.data is {id, reachable, ...} with kb_scope reachability folded in",
})
return cmd
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
sdk "academy/client"
)
type fakeAgentCheckSvc struct {
+13 -13
View File
@@ -9,9 +9,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// CreateService is the narrow SDK surface this command depends on.
@@ -58,16 +58,16 @@ type createFlagSet struct {
kbsSet bool
}
const agentCreateExample = ` weknora agent create "Support Bot" --model <model-id>
weknora agent create "Code Reviewer" --model <model-id> --system-prompt-file ./prompt.md --attach-kb kb_eng --attach-kb kb_arch
weknora agent create "From Template" --model <model-id> --from ag_existing
weknora agent create --generate-skeleton > my-agent.yaml
weknora agent create "Tuned" --model <model-id> --config-file ./my-agent.yaml`
const agentCreateExample = ` academy agent create "Support Bot" --model <model-id>
academy agent create "Code Reviewer" --model <model-id> --system-prompt-file ./prompt.md --attach-kb kb_eng --attach-kb kb_arch
academy agent create "From Template" --model <model-id> --from ag_existing
academy agent create --generate-skeleton > my-agent.yaml
academy agent create "Tuned" --model <model-id> --config-file ./my-agent.yaml`
const agentCreateLong = `Create a new custom agent.
--model is required (an agent without a model cannot invoke); discover a
valid model id with 'weknora model list'. The 7
valid model id with 'academy model list'. The 7
optional hot-path flags cover the most frequently set AgentConfig fields;
for the remaining 27 use --config-file with a YAML or JSON document
matching the AgentConfig schema (run --generate-skeleton to get a
@@ -84,7 +84,7 @@ AI agents: writes a new resource server-side. Failure surfaces as a
typed code on stderr: input.invalid_argument (bad flags, bad file, or
bad model), resource.not_found (--from <missing>), auth.unauthenticated.`
// NewCmdCreate builds `weknora agent create <name> --model <id>`.
// NewCmdCreate builds `academy agent create <name> --model <id>`.
func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
opts := &CreateOptions{}
var systemPromptFile, configFile string
@@ -222,9 +222,9 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
UsedFor: "Create a new custom agent. --model is required and accepts a model id or name; --attach-kb (repeatable) accepts KB ids or names. Emits the created Agent object.",
RequiredFlags: []string{"<name> (positional)", "--model"},
Examples: []string{
`weknora agent create "Support Bot" --model gpt-4o`,
`weknora agent create "Support Bot" --model gpt-4o --attach-kb kb_eng --system-prompt "You are a support assistant."`,
`weknora agent create --generate-skeleton # print a blank config to fill in (no --model needed)`,
`academy agent create "Support Bot" --model gpt-4o`,
`academy agent create "Support Bot" --model gpt-4o --attach-kb kb_eng --system-prompt "You are a support assistant."`,
`academy agent create --generate-skeleton # print a blank config to fill in (no --model needed)`,
},
Output: "envelope.data is the created Agent object with id, name, config",
})
+3 -3
View File
@@ -11,9 +11,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeCreateSvc records all three SDK methods this command may invoke.
+10 -10
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
)
// agentDeleteFields enumerates the JSON discovery fields for `agent delete`.
@@ -51,11 +51,11 @@ and writes input.confirmation_required to stderr. NEVER auto-pass -y
without the user's explicit go-ahead — the exit-10 protocol exists
exactly to guard against unintended deletes.`
const agentDeleteExample = ` weknora agent delete ag_abc # interactive confirm
weknora agent delete ag_abc -y # no prompt
weknora agent delete ag_abc -y --format json # bare {id, deleted:true} JSON`
const agentDeleteExample = ` academy agent delete ag_abc # interactive confirm
academy agent delete ag_abc -y # no prompt
academy agent delete ag_abc -y --format json # bare {id, deleted:true} JSON`
// NewCmdDelete builds `weknora agent delete <agent-id>`.
// NewCmdDelete builds `academy agent delete <agent-id>`.
func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
opts := &DeleteOptions{}
cmd := &cobra.Command{
@@ -95,8 +95,8 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
RequiredFlags: []string{"<agent-id> (positional)"},
Output: "envelope.data is {id, deleted:true}",
Examples: []string{
"weknora agent delete ag_abc -y",
"weknora agent delete ag_abc -y --format json",
"academy agent delete ag_abc -y",
"academy agent delete ag_abc -y --format json",
},
Warnings: []string{
"Requires explicit user approval (exit 10 / input.confirmation_required); never auto-add -y.",
@@ -107,7 +107,7 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
}
func runDelete(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOptions, svc DeleteService, p prompt.Prompter) error {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "agent", opts.AgentID, "agent.delete", []string{"weknora", "agent", "delete", opts.AgentID, "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "agent", opts.AgentID, "agent.delete", []string{"academy", "agent", "delete", opts.AgentID, "-y"}); err != nil {
return err
}
if err := svc.DeleteAgent(ctx, opts.AgentID); err != nil {
+3 -3
View File
@@ -7,9 +7,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/testutil"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/testutil"
)
type fakeDeleteSvc struct {
+13 -13
View File
@@ -9,9 +9,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// EditService is the narrow SDK surface this command depends on. The fetch
@@ -92,13 +92,13 @@ with input.confirmation_required. Surface the prompt to the user and only
retry with -y after explicit approval. Other failure codes: resource.not_found
(agent id or KB id), auth.forbidden, input.invalid_argument (no flags, bad file).`
const agentEditExample = ` weknora agent update ag_abc --name "Renamed" -y
weknora agent update ag_abc --description "" -y # clear description
weknora agent update ag_abc --add-kb kb_new --remove-kb kb_old -y
weknora agent update ag_abc --system-prompt-file ./prompt.md -y
weknora agent update ag_abc --config-file ./tuned.yaml --temperature 0.9 -y`
const agentEditExample = ` academy agent update ag_abc --name "Renamed" -y
academy agent update ag_abc --description "" -y # clear description
academy agent update ag_abc --add-kb kb_new --remove-kb kb_old -y
academy agent update ag_abc --system-prompt-file ./prompt.md -y
academy agent update ag_abc --config-file ./tuned.yaml --temperature 0.9 -y`
// NewCmdEdit builds `weknora agent update <agent-id>`.
// NewCmdEdit builds `academy agent update <agent-id>`.
func NewCmdEdit(f *cmdutil.Factory) *cobra.Command {
opts := &EditOptions{}
var systemPromptFile, configFile string
@@ -219,7 +219,7 @@ func NewCmdEdit(f *cmdutil.Factory) *cobra.Command {
// Build the retry command from the flags the user actually passed.
// Include list-shaped and file-path flags so exit-10 retry_argv reproduces
// the original update (BuildRetryArgv expands StringSlice as repeats).
retryCmd := cmdutil.BuildRetryArgv(cmd, []string{"weknora", "agent", "update", opts.AgentID},
retryCmd := cmdutil.BuildRetryArgv(cmd, []string{"academy", "agent", "update", opts.AgentID},
"name", "description", "model", "system-prompt", "system-prompt-file",
"agent-mode", "rerank-model", "temperature", "add-kb", "remove-kb",
"kb-selection-mode", "config-file", "format")
@@ -272,9 +272,9 @@ func NewCmdEdit(f *cmdutil.Factory) *cobra.Command {
UsedFor: "surgically update a custom agent's configuration",
RequiredFlags: []string{"<agent-id> (positional)", "at least one update flag (--name, --add-kb, etc.)"},
Examples: []string{
"weknora agent update ag_abc --name \"Renamed\"",
"weknora agent update ag_abc --add-kb kb_new --remove-kb kb_old",
"weknora agent update ag_abc --config-file ./tuned.yaml",
"academy agent update ag_abc --name \"Renamed\"",
"academy agent update ag_abc --add-kb kb_new --remove-kb kb_old",
"academy agent update ag_abc --config-file ./tuned.yaml",
},
Output: "envelope.data is the updated Agent object (id, name, config) after the update is applied",
Warnings: []string{
+4 -4
View File
@@ -7,10 +7,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// agentDryRunFactory builds a Factory whose Client closure panics if invoked —
+7 -7
View File
@@ -12,10 +12,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// fakeEditSvc scripts GetAgent (fetch baseline) + UpdateAgent (apply
@@ -292,11 +292,11 @@ func TestEdit_SystemPromptFile(t *testing.T) {
assert.Equal(t, "new prompt", svc.updateReq.Config.SystemPrompt)
}
// withRootHarnessAgent wraps `weknora agent update ...` under a synthetic root
// withRootHarnessAgent wraps `academy agent update ...` under a synthetic root
// cmd that registers the global persistent flags (mirrors addGlobalFlags in
// cmd/root.go).
func withRootHarnessAgent(edit *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "Output format: text | json | ndjson")
@@ -352,7 +352,7 @@ func TestAgentEdit_RetryArgvPreservesAddKB(t *testing.T) {
assert.Equal(t, cmdutil.CodeInputConfirmationRequired, ce.Code)
// pflag Visit is lexicographical among changed flags.
assert.Equal(t, []string{
"weknora", "agent", "update", "ag_abc",
"academy", "agent", "update", "ag_abc",
"--add-kb", "kb_new",
"--format", "json",
"--remove-kb", "kb_old",
+7 -7
View File
@@ -9,11 +9,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
"academy/cli/internal/text"
sdk "academy/client"
)
// agentListFields enumerates the fields surfaced for `--format json` discovery
@@ -38,7 +38,7 @@ type ListOptions struct {
Limit int
}
// NewCmdList builds `weknora agent list`.
// NewCmdList builds `academy agent list`.
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
opts := &ListOptions{}
cmd := &cobra.Command{
@@ -67,7 +67,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmdutil.AddFormatFlag(cmd, agentListFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "List custom agents visible to the active tenant. The SDK returns all agents in one call (no server-side pagination); meta.count reflects the full tenant set, --limit caps client-side.",
Examples: []string{"weknora agent list --format json", "weknora agent list --limit 10 --format json"},
Examples: []string{"academy agent list --format json", "academy agent list --limit 10 --format json"},
Output: "envelope.data is an array of Agent objects with id, name, is_builtin; meta.total_count is the full tenant set and meta.has_more=true means --limit truncated it (raise --limit to get the rest)",
})
return cmd
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeListSvc struct {
+8 -8
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// AgentStatusResult is the shallow health snapshot for `agent status <id>`.
@@ -41,11 +41,11 @@ func NewCmdStatus(f *cmdutil.Factory) *cobra.Command {
Returns: reachable / model_id.
For downstream KB reachability verification use 'weknora agent check <id>'
For downstream KB reachability verification use 'academy agent check <id>'
(active verification, 1 + N HTTP). For full agent config / metadata use
'weknora agent view <id>'.`,
Example: ` weknora agent status ag_abc
weknora agent status ag_abc --format json`,
'academy agent view <id>'.`,
Example: ` academy agent status ag_abc
academy agent status ag_abc --format json`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -68,7 +68,7 @@ For downstream KB reachability verification use 'weknora agent check <id>'
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "shallow health probe of a custom agent: reachability without kb_scope verification",
RequiredFlags: []string{"<agent-id> (positional)"},
Examples: []string{"weknora agent status agent_abc"},
Examples: []string{"academy agent status agent_abc"},
Output: "envelope.data is {id, reachable, ...}; use `agent check` for deep kb_scope verification",
})
return cmd
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
sdk "academy/client"
)
type fakeAgentStatusSvc struct {
+9 -9
View File
@@ -8,10 +8,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/text"
sdk "academy/client"
)
// promptPreviewWidth caps inline KV row prompt previews. Multi-line prompts
@@ -34,7 +34,7 @@ type ViewService interface {
GetAgent(ctx context.Context, agentID string) (*sdk.Agent, error)
}
// NewCmdView builds `weknora agent view <agent-id>`.
// NewCmdView builds `academy agent view <agent-id>`.
func NewCmdView(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "view <agent-id>",
@@ -46,9 +46,9 @@ fields are omitted; sections with no set fields are suppressed entirely.
Pass --format json for the bare SDK Agent object (config nested, not flattened).
Use --jq to project specific fields or reach into nested config.`,
Example: ` weknora agent view ag_abc
weknora agent view ag_abc --format json --jq '{id, name, config}' # top-level projection
weknora agent view ag_abc --format json --jq '.config.system_prompt'`,
Example: ` academy agent view ag_abc
academy agent view ag_abc --format json --jq '{id, name, config}' # top-level projection
academy agent view ag_abc --format json --jq '.config.system_prompt'`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -67,7 +67,7 @@ Use --jq to project specific fields or reach into nested config.`,
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "fetch one custom agent's full configuration by id",
RequiredFlags: []string{"<agent-id> (positional)"},
Examples: []string{"weknora agent view agent_abc"},
Examples: []string{"academy agent view agent_abc"},
Output: "envelope.data is the custom agent (id, name, description, is_builtin, and a nested config object holding model/kb_scope/...)",
})
return cmd
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeViewSvc struct {
+6 -6
View File
@@ -8,19 +8,19 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// TestEveryLeafCommandHasAgentHelp enforces the agent-first contract: every
// leaf (runnable, no subcommands) command must emit a structured AgentHelp JSON
// blob under WEKNORA_AGENT_HELP=1, so an agent never has to scrape human prose.
// blob under ACADEMY_AGENT_HELP=1, so an agent never has to scrape human prose.
// Drift guard in the spirit of the K6/K7 skill-parity tests: a new leaf command
// added without SetAgentHelp fails CI here.
//
// Exemptions: cobra's generated `completion`/`help` subtrees carry no
// domain semantics worth a machine blob.
func TestEveryLeafCommandHasAgentHelp(t *testing.T) {
t.Setenv("WEKNORA_AGENT_HELP", "1")
t.Setenv("ACADEMY_AGENT_HELP", "1")
root := NewRootCmd(cmdutil.New())
var missing []string
@@ -44,7 +44,7 @@ func TestEveryLeafCommandHasAgentHelp(t *testing.T) {
}
}
// renderAgentHelp runs a leaf's help under WEKNORA_AGENT_HELP=1 and decodes the
// renderAgentHelp runs a leaf's help under ACADEMY_AGENT_HELP=1 and decodes the
// machine blob (used_for / output / examples) an agent would read.
func renderAgentHelp(t *testing.T, c *cobra.Command) struct {
UsedFor string `json:"used_for"`
@@ -71,7 +71,7 @@ func renderAgentHelp(t *testing.T, c *cobra.Command) struct {
// envelope (e.g. deletes emit {id, deleted:true}); an empty Output is a contract
// gap, not a valid state. Sibling drift guard to the agent-help test above.
func TestEveryLeafCommandDeclaresOutput(t *testing.T) {
t.Setenv("WEKNORA_AGENT_HELP", "1")
t.Setenv("ACADEMY_AGENT_HELP", "1")
root := NewRootCmd(cmdutil.New())
var missing []string
@@ -91,7 +91,7 @@ func TestEveryLeafCommandDeclaresOutput(t *testing.T) {
// TestEveryLeafCommandHasExample enforces that every leaf ships at least one
// runnable example — agents learn invocation shape from examples, not prose.
func TestEveryLeafCommandHasExample(t *testing.T) {
t.Setenv("WEKNORA_AGENT_HELP", "1")
t.Setenv("ACADEMY_AGENT_HELP", "1")
root := NewRootCmd(cmdutil.New())
var missing []string
+22 -22
View File
@@ -1,4 +1,4 @@
// Package api implements the `weknora api` raw HTTP passthrough command.
// Package api implements the `academy api` raw HTTP passthrough command.
//
// Shape: one positional (path) + `-X/--method` flag, default GET (auto-
// promoted to POST when a body is supplied via -d/--input). Text mode writes
@@ -22,9 +22,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// apiFields is intentionally a marker - api wraps arbitrary HTTP responses
@@ -50,12 +50,12 @@ type Service interface {
Raw(ctx context.Context, method, path string, body any) (*http.Response, error)
}
// NewCmd returns the `weknora api` command.
// NewCmd returns the `academy api` command.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
opts := &Options{}
cmd := &cobra.Command{
Use: "api <path>",
Short: "Make a raw API request to the WeKnora server",
Short: "Make a raw API request to the Academy server",
Long: `Raw HTTP API access. JSON body via -d/--data (inline) or --input <file>/- (stdin).
The default method is GET; supplying a body (-d or --input) auto-promotes it
@@ -71,11 +71,11 @@ With --paginate, text mode writes the merged {data, total} JSON object with a
trailing newline and no envelope.
Examples:
weknora api /api/v1/knowledge-bases # GET
weknora api /api/v1/knowledge-bases -d '{"name":"foo"}' # POST (auto)
weknora api /api/v1/knowledge-bases -F name=foo -F enabled=true # POST, typed body
echo '{"name":"foo"}' | weknora api /api/v1/knowledge-bases --input - # POST via stdin
weknora api /api/v1/knowledge-bases/kb_xxx -X DELETE`,
academy api /api/v1/knowledge-bases # GET
academy api /api/v1/knowledge-bases -d '{"name":"foo"}' # POST (auto)
academy api /api/v1/knowledge-bases -F name=foo -F enabled=true # POST, typed body
echo '{"name":"foo"}' | academy api /api/v1/knowledge-bases --input - # POST via stdin
academy api /api/v1/knowledge-bases/kb_xxx -X DELETE`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
opts.Yes, _ = c.Flags().GetBool("yes")
@@ -122,8 +122,8 @@ Examples:
}
}
method := resolveMethod(opts)
// Escape-hatch DELETE through `weknora api` is just as destructive
// as `weknora kb delete` - exit-10 destructive protocol must apply
// Escape-hatch DELETE through `academy api` is just as destructive
// as `academy kb delete` - exit-10 destructive protocol must apply
// (cli/README.md). PUT/PATCH mutate server state like a typed
// `kb/agent/doc update`, so they get the same exit-10 WRITE gate;
// without it the raw escape hatch bypassed the "an agent cannot
@@ -131,7 +131,7 @@ Examples:
// `create` (also ungated). GET/HEAD are reads.
switch method {
case http.MethodDelete:
if err := cmdutil.ConfirmDestructive(f.Prompter(), opts.Yes, fopts.WantsJSON(), "delete", "endpoint", args[0], "api.delete", []string{"weknora", "api", "-X", "DELETE", args[0], "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(f.Prompter(), opts.Yes, fopts.WantsJSON(), "delete", "endpoint", args[0], "api.delete", []string{"academy", "api", "-X", "DELETE", args[0], "-y"}); err != nil {
return err
}
case http.MethodPut, http.MethodPatch:
@@ -155,14 +155,14 @@ Examples:
cmdutil.AddFormatFlag(cmd, apiFields...)
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "raw HTTP passthrough to weknora-server API endpoints when typed subcommands are insufficient",
UsedFor: "raw HTTP passthrough to academy-server API endpoints when typed subcommands are insufficient",
RequiredFlags: []string{"path (positional)"},
Examples: []string{
"weknora api /api/v1/knowledge-bases",
"weknora api /api/v1/knowledge-bases -d '{\"name\":\"foo\"}'",
"weknora api -X POST /api/v1/knowledge-bases -F name=\"Eng Docs\" -F enabled=true",
"weknora api -X DELETE /api/v1/knowledge-bases/kb_x -y",
"echo '{\"name\":\"foo\"}' | weknora api /api/v1/knowledge-bases --input -",
"academy api /api/v1/knowledge-bases",
"academy api /api/v1/knowledge-bases -d '{\"name\":\"foo\"}'",
"academy api -X POST /api/v1/knowledge-bases -F name=\"Eng Docs\" -F enabled=true",
"academy api -X DELETE /api/v1/knowledge-bases/kb_x -y",
"echo '{\"name\":\"foo\"}' | academy api /api/v1/knowledge-bases --input -",
},
Output: "text mode: the raw server response body on stdout. " +
"json mode (default): the parsed server response is placed directly under envelope.data - " +
@@ -311,11 +311,11 @@ func resolveMethod(opts *Options) string {
return "GET"
}
// apiRetryArgv reconstructs a directly-executable `weknora api` argv (with -y)
// apiRetryArgv reconstructs a directly-executable `academy api` argv (with -y)
// for the write-confirmation gate, preserving the method, path and body flags
// the caller passed so an agent can re-run the exact mutation after approval.
func apiRetryArgv(opts *Options, method, path string) []string {
argv := []string{"weknora", "api", "-X", method, path}
argv := []string{"academy", "api", "-X", method, path}
switch {
case opts.Data != "":
argv = append(argv, "-d", opts.Data)
+4 -4
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// apiDryRunFactory builds a Factory whose Client closure panics if invoked —
+8 -8
View File
@@ -19,10 +19,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// fakeAPISvc is a test double for Service that delegates each call to a
@@ -306,12 +306,12 @@ func TestAPI_PathWithoutSlash(t *testing.T) {
}
}
// withRootHarness wraps `weknora api ...` under a synthetic root cmd that
// withRootHarness wraps `academy api ...` under a synthetic root cmd that
// registers the global persistent flags (mirrors addGlobalFlags in
// cmd/root.go). Required because api's NewCmd doesn't register --yes /
// --format / --jq itself — it inherits them from root in production.
func withRootHarness(api *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "")
@@ -325,7 +325,7 @@ func withRootHarness(api *cobra.Command, args ...string) *cobra.Command {
}
// TestAPI_DELETE_RequiresConfirmation pins the exit-10 protocol on the
// escape-hatch DELETE path: agent invokes `weknora api DELETE /...` without
// escape-hatch DELETE path: agent invokes `academy api DELETE /...` without
// -y/--yes, must get input.confirmation_required + exit 10. Confirmation is
// enforced in NewCmd.RunE (not runAPI), so the test drives the cobra cmd.
func TestAPI_DELETE_RequiresConfirmation(t *testing.T) {
@@ -659,7 +659,7 @@ func TestAPI_PaginateServerCapsPageSize(t *testing.T) {
}
// TestAPI_PUT_RequiresConfirmation pins the exit-10 write gate on the
// escape-hatch PUT path: `weknora api -X PUT /...` mutates server state the
// escape-hatch PUT path: `academy api -X PUT /...` mutates server state the
// same way a typed `kb update` does, so it must require -y (exit 10) rather
// than silently writing. Regression: only DELETE was gated, letting an agent
// bypass the write-confirmation protocol via raw PUT/PATCH.
+7 -7
View File
@@ -15,10 +15,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/cmd"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/cmd"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
func TestAPI_PaginateFormats(t *testing.T) {
@@ -110,8 +110,8 @@ func TestAPI_PaginateFormats(t *testing.T) {
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("WEKNORA_FORMAT", tc.env)
t.Setenv("WEKNORA_PROFILE", "")
t.Setenv("ACADEMY_FORMAT", tc.env)
t.Setenv("ACADEMY_PROFILE", "")
out, errOut := iostreams.SetForTest(t)
if tc.tty {
out, errOut = iostreams.SetForTestWithTTY(t)
@@ -209,7 +209,7 @@ func (w *paginationFailWriter) Write(p []byte) (int, error) {
func TestAPI_PaginateTextWriteError(t *testing.T) {
for _, tail := range []bool{false, true} {
t.Run(strconv.FormatBool(tail), func(t *testing.T) {
t.Setenv("WEKNORA_PROFILE", "")
t.Setenv("ACADEMY_PROFILE", "")
iostreams.SetForTest(t)
sentinel := errors.New("synthetic output failure")
out := &paginationFailWriter{err: sentinel, tail: tail}
+2 -2
View File
@@ -5,7 +5,7 @@ package auth
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// Credential-mode tokens used in the JSON output of auth list / login /
@@ -34,7 +34,7 @@ func modeFromRefs(apiKeyRef, tokenRef string) string {
}
}
// NewCmdAuth builds the `weknora auth` command tree and registers its
// NewCmdAuth builds the `academy auth` command tree and registers its
// subcommands. Called from cli/cmd/root.go.
func NewCmdAuth(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
+7 -7
View File
@@ -9,13 +9,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"github.com/Tencent/WeKnora/cli/internal/testutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/secrets"
"academy/cli/internal/testutil"
sdk "academy/client"
)
func TestNewCmdAuth_TreeShape(t *testing.T) {
+7 -7
View File
@@ -14,12 +14,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/secrets"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/secrets"
sdk "academy/client"
)
// authDryRunFactory builds a Factory whose Client closure panics if invoked —
@@ -44,7 +44,7 @@ func authDryRunFactory(t *testing.T, cfg *config.Config) *cmdutil.Factory {
// withRootHarnessAuth wraps an auth subcommand under a synthetic root cmd
// that registers the global persistent flags.
func withRootHarnessAuth(sub *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "")
+8 -8
View File
@@ -7,10 +7,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/format"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"academy/cli/internal/cmdutil"
"academy/cli/internal/format"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
)
type ListOptions struct{}
@@ -29,9 +29,9 @@ type listEntry struct {
Current bool `json:"current"`
}
// NewCmdList builds `weknora auth list`. Per-host enumeration: render one
// NewCmdList builds `academy auth list`. Per-host enumeration: render one
// row per registered profile, marking the active one. Reads only
// ~/.config/weknora/config.yaml - no network, no keyring touch.
// ~/.config/academy/config.yaml - no network, no keyring touch.
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
@@ -50,7 +50,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmdutil.AddFormatFlag(cmd, authListFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "list configured profiles and their credential mode (bearer / api-key)",
Examples: []string{"weknora auth list", "weknora auth list --jq '.data[].name'"},
Examples: []string{"academy auth list", "academy auth list --jq '.data[].name'"},
Output: "envelope.data is an array of profiles with name, host, mode, and which is active",
})
return cmd
@@ -78,7 +78,7 @@ func runList(fopts *cmdutil.FormatOptions, f *cmdutil.Factory) error {
return fopts.Emit(iostreams.IO.Out, entries, meta)
}
if len(entries) == 0 {
fmt.Fprintln(iostreams.IO.Out, "No profiles configured. Run `weknora auth login` to create one.")
fmt.Fprintln(iostreams.IO.Out, "No profiles configured. Run `academy auth login` to create one.")
return nil
}
tw := tabwriter.NewWriter(iostreams.IO.Out, 0, 0, 2, ' ', 0)
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
)
func newListFactory(cfg *config.Config) *cmdutil.Factory {
+18 -18
View File
@@ -8,11 +8,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/secrets"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/secrets"
sdk "academy/client"
)
// authLoginFields enumerates the fields surfaced for `--format json` discovery on
@@ -26,7 +26,7 @@ var authLoginFields = []string{
// LoginOptions is the configuration captured from flags + prompts. Host and
// Profile are resolved from the active profile in config (not from flags) -
// `auth login` authenticates the already-existing active profile, created
// beforehand with `weknora profile add <name> --host <h> --use`.
// beforehand with `academy profile add <name> --host <h> --use`.
type LoginOptions struct {
Host string // resolved from the active profile's Host in config
Profile string // resolved active profile name (honors global --profile)
@@ -65,22 +65,22 @@ var defaultAPIKeyValidator apiKeyValidator = func(ctx context.Context, host, api
return resp.Data.User, nil
}
// NewCmdLogin builds the `weknora auth login` command. runF is the testable
// NewCmdLogin builds the `academy auth login` command. runF is the testable
// entrypoint (left nil for production; see cli/cmd/auth/login_test.go).
func NewCmdLogin(f *cmdutil.Factory, runF func(context.Context, *LoginOptions, *cmdutil.FormatOptions, *cmdutil.Factory, LoginService) error) *cobra.Command {
opts := &LoginOptions{}
cmd := &cobra.Command{
Use: "login",
Short: "Authenticate the active profile against its WeKnora server",
Short: "Authenticate the active profile against its Academy server",
Long: `Authenticate the active profile by email + password (interactive prompt) or
pipe an API key with --with-token.
` + "`auth login`" + ` operates on the active profile (override with the global
--profile flag). Create the profile first with
` + "`weknora profile add <name> --host <h> --use`" + `, then run ` + "`weknora auth login`" + `.
` + "`academy profile add <name> --host <h> --use`" + `, then run ` + "`academy auth login`" + `.
Credentials are persisted to the OS keyring when available; otherwise to a
0600 file under $XDG_CONFIG_HOME/weknora/secrets.`,
0600 file under $XDG_CONFIG_HOME/academy/secrets.`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -103,10 +103,10 @@ Credentials are persisted to the OS keyring when available; otherwise to a
cmdutil.AddFormatFlag(cmd, authLoginFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "authenticate the active profile; --with-token reads an API key from stdin (non-interactive)",
Examples: []string{`echo "$WEKNORA_API_KEY" | weknora auth login --with-token`},
Examples: []string{`echo "$ACADEMY_API_KEY" | academy auth login --with-token`},
Output: "envelope.data is {profile, host, mode, email, tenant_id} on success (email matches `auth status`)",
Warnings: []string{
"a profile must exist and be active first (`weknora profile add <n> --host <url> --use`)",
"a profile must exist and be active first (`academy profile add <n> --host <url> --use`)",
"password login is interactive-only (no flags) — agents must use --with-token with the key piped to stdin",
},
})
@@ -119,7 +119,7 @@ Credentials are persisted to the OS keyring when available; otherwise to a
// add`'s job. Returns typed errors when no active profile is configured or
// the profile lacks a host.
func resolveActiveProfile(f *cmdutil.Factory) (name, host string, err error) {
// f.Config() already folds the global --profile / WEKNORA_PROFILE override
// f.Config() already folds the global --profile / ACADEMY_PROFILE override
// into cfg.CurrentProfile (same source f.ActiveProfile reads), so one load
// resolves the active profile — matches logout/refresh.
cfg, err := f.Config()
@@ -128,10 +128,10 @@ func resolveActiveProfile(f *cmdutil.Factory) (name, host string, err error) {
}
active := cfg.CurrentProfile
if active == "" {
msg := "no active profile; run `weknora profile add <name> --host <h> --use` first"
msg := "no active profile; run `academy profile add <name> --host <h> --use` first"
if envActive, kind := cmdutil.EnvCredential(); envActive {
msg = "no active profile to log in — you are already authenticated this session via " + kind +
"; `auth login` only persists a named profile, so run `weknora profile add <name> --host <h> --use` first if you want one"
"; `auth login` only persists a named profile, so run `academy profile add <name> --host <h> --use` first if you want one"
}
return "", "", cmdutil.NewError(cmdutil.CodeAuthUnauthenticated, msg)
}
@@ -197,7 +197,7 @@ func runLogin(ctx context.Context, opts *LoginOptions, fopts *cmdutil.FormatOpti
// Transport errors (connection refused, DNS failure) must not be
// surfaced as auth.bad_credential — the key may be fine but the
// host is unreachable. Classify via WrapHTTP so network errors
// get CodeNetworkError and the hint points at `weknora doctor`.
// get CodeNetworkError and the hint points at `academy doctor`.
if cmdutil.ClassifyHTTPError(err) == cmdutil.CodeNetworkError {
return cmdutil.Wrapf(cmdutil.CodeNetworkError, err, "validate API key: check host reachability")
}
@@ -381,8 +381,8 @@ func warnOnFileFallback(store secrets.Store) {
if _, isFile := store.(*secrets.FileStore); !isFile {
return
}
fmt.Fprintln(iostreams.IO.Err, "warning: OS keychain unavailable - credentials will be saved to a 0600 file under $XDG_CONFIG_HOME/weknora/secrets/.")
fmt.Fprintln(iostreams.IO.Err, " install / unlock the keyring (or use `weknora doctor` to inspect) for OS-backed storage.")
fmt.Fprintln(iostreams.IO.Err, "warning: OS keychain unavailable - credentials will be saved to a 0600 file under $XDG_CONFIG_HOME/academy/secrets/.")
fmt.Fprintln(iostreams.IO.Err, " install / unlock the keyring (or use `academy doctor` to inspect) for OS-backed storage.")
}
// readStdinTrimmed reads all of r and returns the result with surrounding
+7 -7
View File
@@ -10,13 +10,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"github.com/Tencent/WeKnora/cli/internal/testutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/secrets"
"academy/cli/internal/testutil"
sdk "academy/client"
)
// fakeLoginService captures the email/password it received.
+14 -14
View File
@@ -6,10 +6,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/secrets"
)
type LogoutOptions struct {
@@ -28,7 +28,7 @@ type logoutResult struct {
Removed []string `json:"removed"`
}
// NewCmdLogout builds `weknora auth logout`. Clears stored credentials
// NewCmdLogout builds `academy auth logout`. Clears stored credentials
// (keyring + file fallback) and removes the profile entry from config.yaml.
// No server-side revocation - local-only credential clear.
func NewCmdLogout(f *cmdutil.Factory) *cobra.Command {
@@ -37,14 +37,14 @@ func NewCmdLogout(f *cmdutil.Factory) *cobra.Command {
Use: "logout",
Short: "Remove stored credentials for a profile",
Long: `Clear keyring + file-fallback secrets for one profile (or all of
them with --all) and drop the profile entry from ~/.config/weknora/config.yaml.
them with --all) and drop the profile entry from ~/.config/academy/config.yaml.
Note: this does NOT revoke the credential server-side - for API keys, you
must rotate them in the server UI; for JWT, the token will continue to be
accepted until it expires.`,
Example: ` weknora auth logout # active profile
weknora --profile staging auth logout # specific profile
weknora auth logout --all`,
Example: ` academy auth logout # active profile
academy --profile staging auth logout # specific profile
academy auth logout --all`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -92,9 +92,9 @@ accepted until it expires.`,
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "clear stored credentials for the active profile (or --all); the profile itself stays registered (host preserved) so `auth login` can re-auth it — use `profile remove` to delete the profile entirely",
Examples: []string{
"weknora auth logout",
"weknora --profile staging auth logout",
"weknora auth logout --all",
"academy auth logout",
"academy --profile staging auth logout",
"academy auth logout --all",
},
Output: "envelope.data is {removed: [profile names cleared]}",
Warnings: []string{
@@ -125,9 +125,9 @@ func runLogout(opts *LogoutOptions, fopts *cmdutil.FormatOptions, f *cmdutil.Fac
// Destructive-write protocol: confirm before clearing credentials.
scope := fmt.Sprintf("%d profile(s) [%s]", len(targets), strings.Join(targets, ", "))
retryCmd := []string{"weknora", "auth", "logout", "-y"}
retryCmd := []string{"academy", "auth", "logout", "-y"}
if opts.All {
retryCmd = []string{"weknora", "auth", "logout", "--all", "-y"}
retryCmd = []string{"academy", "auth", "logout", "--all", "-y"}
}
if err := cmdutil.ConfirmDestructive(f.Prompter(), opts.Yes, fopts.WantsJSON(), "delete", "auth credentials", scope, "auth.logout", retryCmd); err != nil {
return err
+5 -5
View File
@@ -6,11 +6,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/secrets"
)
// newLogoutFactory builds a Factory whose Config closure mutates the supplied
+16 -16
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type RefreshOptions struct {
@@ -22,12 +22,12 @@ var authRefreshFields = []string{"profile"}
// refreshResult is the typed payload emitted under data on success. Token
// values are intentionally NOT included - emitting them would leak secrets
// into stdout / agent transcripts. Agents needing to verify the new token
// can re-run `weknora auth status` (live API check).
// can re-run `academy auth status` (live API check).
type refreshResult struct {
Profile string `json:"profile"`
}
// NewCmdRefresh builds `weknora auth refresh`. Renews the JWT access
// NewCmdRefresh builds `academy auth refresh`. Renews the JWT access
// token by spending the stored refresh_token via POST /auth/refresh -
// the standard OAuth refresh-token grant.
//
@@ -38,14 +38,14 @@ func NewCmdRefresh(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "refresh",
Short: "Renew the JWT access token using the stored refresh token",
Long: `Reads the refresh token previously stored by ` + "`weknora auth login`" + ` and
Long: `Reads the refresh token previously stored by ` + "`academy auth login`" + ` and
exchanges it for a new access + refresh token pair via POST /api/v1/auth/refresh.
Both new tokens replace the existing entries in the OS keyring.
API-key profiles are rejected with input.invalid_argument - they have no
refresh semantic. Rotate the key in the server UI instead.`,
Example: ` weknora auth refresh # refresh the active profile
weknora --profile staging auth refresh # refresh a specific profile`,
Example: ` academy auth refresh # refresh the active profile
academy --profile staging auth refresh # refresh a specific profile`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -67,7 +67,7 @@ refresh semantic. Rotate the key in the server UI instead.`,
"authenticated via "+kind+" (stateless env credential): there is no stored JWT to refresh — env credentials are supplied fresh each call, so no refresh is needed")
}
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated,
"no active profile configured; run `weknora auth login` to set one up")
"no active profile configured; run `academy auth login` to set one up")
}
prof, ok := cfg.Profiles[name]
if !ok {
@@ -79,9 +79,9 @@ refresh semantic. Rotate the key in the server UI instead.`,
fmt.Sprintf("profile %q has no host", name))
}
if prof.RefreshRef == "" {
hint := "api-key profiles can't be refreshed - rotate the key in the server UI and run `weknora auth login --with-token`"
hint := "api-key profiles can't be refreshed - rotate the key in the server UI and run `academy auth login --with-token`"
if prof.APIKeyRef == "" {
hint = "no refresh token stored - run `weknora auth login` to authenticate"
hint = "no refresh token stored - run `academy auth login` to authenticate"
}
return &cmdutil.Error{
Code: cmdutil.CodeInputInvalidArgument,
@@ -104,8 +104,8 @@ refresh semantic. Rotate the key in the server UI instead.`,
UsedFor: "Renew the JWT access token for the active profile (override with the global --profile) using the stored refresh token. API-key profiles are rejected.",
Output: "envelope.data has profile name that was refreshed",
Examples: []string{
"weknora auth refresh",
"weknora --profile staging auth refresh",
"academy auth refresh",
"academy --profile staging auth refresh",
},
})
return cmd
@@ -130,7 +130,7 @@ func runRefresh(ctx context.Context, opts *RefreshOptions, fopts *cmdutil.Format
"authenticated via "+kind+" (stateless env credential): there is no stored JWT to refresh — env credentials are supplied fresh each call, so no refresh is needed")
}
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated,
"no active profile configured; run `weknora auth login` to set one up")
"no active profile configured; run `academy auth login` to set one up")
}
c, ok := cfg.Profiles[name]
if !ok {
@@ -142,9 +142,9 @@ func runRefresh(ctx context.Context, opts *RefreshOptions, fopts *cmdutil.Format
fmt.Sprintf("profile %q has no host", name))
}
if c.RefreshRef == "" {
hint := "api-key profiles can't be refreshed - rotate the key in the server UI and run `weknora auth login --with-token`"
hint := "api-key profiles can't be refreshed - rotate the key in the server UI and run `academy auth login --with-token`"
if c.APIKeyRef == "" {
hint = "no refresh token stored - run `weknora auth login` to authenticate"
hint = "no refresh token stored - run `academy auth login` to authenticate"
}
return &cmdutil.Error{
Code: cmdutil.CodeInputInvalidArgument,
+7 -7
View File
@@ -10,13 +10,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"github.com/Tencent/WeKnora/cli/internal/testutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/secrets"
"academy/cli/internal/testutil"
sdk "academy/client"
)
// fakeRefreshService scripts a RefreshToken response.
+10 -10
View File
@@ -8,9 +8,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// authStatusFields enumerates the fields surfaced for `--format json` discovery
@@ -42,7 +42,7 @@ type statusResult struct {
TenantName string `json:"tenant_name,omitempty"`
}
// NewCmdStatus builds the `weknora auth status` command.
// NewCmdStatus builds the `academy auth status` command.
func NewCmdStatus(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "status",
@@ -51,7 +51,7 @@ func NewCmdStatus(f *cmdutil.Factory) *cobra.Command {
and tenant the server resolves the credential to.
Exits with auth.unauthenticated when the token is invalid or missing - run
` + "`weknora auth login`" + ` (or ` + "`auth refresh`" + ` for JWT profiles) to recover.
` + "`academy auth login`" + ` (or ` + "`auth refresh`" + ` for JWT profiles) to recover.
For JWT profiles the SDK transparently refreshes on 401, so this command
usually only surfaces a hard auth failure.`,
Args: cobra.NoArgs,
@@ -71,7 +71,7 @@ usually only surfaces a hard auth failure.`,
cmdutil.AddFormatFlag(cmd, authStatusFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "show the active profile, the authenticated principal, and token state",
Examples: []string{"weknora auth status", "weknora auth status --jq .data.tenant_id"},
Examples: []string{"academy auth status", "academy auth status --jq .data.tenant_id"},
Output: "envelope.data is {profile, host, auth_source, user_id, username, email, tenant_id, tenant_name, ...}; auth_source is 'profile + keyring' or a stateless env credential; exit 3 if unauthenticated",
})
return cmd
@@ -79,7 +79,7 @@ usually only surfaces a hard auth failure.`,
func runStatus(ctx context.Context, fopts *cmdutil.FormatOptions, f *cmdutil.Factory, svc StatusService) error {
if svc == nil {
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated, "no SDK client available; run `weknora auth login`")
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated, "no SDK client available; run `academy auth login`")
}
resp, err := svc.GetCurrentUser(ctx)
if err != nil {
@@ -94,8 +94,8 @@ func runStatus(ctx context.Context, fopts *cmdutil.FormatOptions, f *cmdutil.Fac
}
// Effective host + auth source. Stateless env credentials
// (WEKNORA_TOKEN/WEKNORA_API_KEY) override the profile + keyring for the
// client, so report the host they authenticate against (WEKNORA_HOST) and
// (ACADEMY_TOKEN/ACADEMY_API_KEY) override the profile + keyring for the
// client, so report the host they authenticate against (ACADEMY_HOST) and
// that they are in effect — not the bypassed config profile's host.
host := ""
if c, ok := cfg.Profiles[cfg.CurrentProfile]; ok {
@@ -104,7 +104,7 @@ func runStatus(ctx context.Context, fopts *cmdutil.FormatOptions, f *cmdutil.Fac
authSource := "profile + keyring"
if active, kind := cmdutil.EnvCredential(); active {
authSource = kind + " env (stateless)"
if h := strings.TrimSpace(os.Getenv("WEKNORA_HOST")); h != "" {
if h := strings.TrimSpace(os.Getenv("ACADEMY_HOST")); h != "" {
host = h
}
}
+4 -4
View File
@@ -6,10 +6,10 @@ import (
"net/http/httptest"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
sdk "academy/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+6 -6
View File
@@ -9,12 +9,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/testutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/testutil"
sdk "academy/client"
)
type fakeStatusService struct {
+21 -21
View File
@@ -6,8 +6,8 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// authTokenFields lists fields surfaced in `--help` as a hint for `--jq`
@@ -20,12 +20,12 @@ type tokenResult struct {
Profile string `json:"profile"`
}
// NewCmdToken builds `weknora auth token`. Prints the active profile's
// NewCmdToken builds `academy auth token`. Prints the active profile's
// credential to stdout for use in shell pipelines, e.g.
//
// WEKNORA_TOKEN=$(weknora auth token)
// curl -H "Authorization: Bearer $WEKNORA_TOKEN" ... # JWT mode
// curl -H "X-API-Key: $WEKNORA_TOKEN" ... # api-key mode
// ACADEMY_TOKEN=$(academy auth token)
// curl -H "Authorization: Bearer $ACADEMY_TOKEN" ... # JWT mode
// curl -H "X-API-Key: $ACADEMY_TOKEN" ... # api-key mode
//
// The user is responsible for constructing the appropriate header -
// `auth list` shows which mode each profile uses.
@@ -40,26 +40,26 @@ func NewCmdToken(f *cmdutil.Factory) *cobra.Command {
newline, suitable for shell command substitution.
The credential is the long-lived API key (mode: api-key) or the access JWT
(mode: bearer), depending on how the profile was created. Run ` + "`weknora auth list`" + `
(mode: bearer), depending on how the profile was created. Run ` + "`academy auth list`" + `
to see which mode each profile uses, and construct the matching HTTP header:
Authorization: Bearer <token> # bearer mode
X-API-Key: <token> # api-key mode
` + "`--profile <name>`" + ` (global flag) selects a non-active profile to read from.`,
Example: ` WEKNORA_TOKEN=$(weknora auth token)
weknora auth token --profile staging
weknora auth token --format json`,
Example: ` ACADEMY_TOKEN=$(academy auth token)
academy auth token --profile staging
academy auth token --format json`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
if err != nil {
return err
}
// `auth token` is a scalar scripting helper (WEKNORA_TOKEN=$(...)),
// `auth token` is a scalar scripting helper (ACADEMY_TOKEN=$(...)),
// so it defaults to the raw token — overriding the global json
// default, the same way `doc download` streams raw bytes. Explicit
// --format json / WEKNORA_FORMAT=json still emit the
// --format json / ACADEMY_FORMAT=json still emit the
// {token,mode,profile} envelope.
fopts.FromEnv()
if fopts.Mode == "" {
@@ -78,9 +78,9 @@ to see which mode each profile uses, and construct the matching HTTP header:
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "print the active profile's raw credential to stdout for shell capture",
Examples: []string{
"WEKNORA_TOKEN=$(weknora auth token)",
"weknora auth token --profile staging",
"weknora auth token --format json",
"ACADEMY_TOKEN=$(academy auth token)",
"academy auth token --profile staging",
"academy auth token --format json",
},
Output: "raw token on stdout (no envelope, no trailing newline) by default; --format json emits {token, mode, profile}",
Warnings: []string{
@@ -96,7 +96,7 @@ func runToken(f *cmdutil.Factory, fopts *cmdutil.FormatOptions) error {
// erroring on the absence of a stored profile.
if active, kind := cmdutil.EnvCredential(); active {
mode := ModeBearer
if kind == "WEKNORA_API_KEY" {
if kind == "ACADEMY_API_KEY" {
mode = ModeAPIKey
}
return emitToken(fopts, os.Getenv(kind), mode, "(env)")
@@ -143,12 +143,12 @@ func runToken(f *cmdutil.Factory, fopts *cmdutil.FormatOptions) error {
token, mode = v, ModeAPIKey
default:
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated,
fmt.Sprintf("profile %q has no stored credential; run `weknora auth login`", profileName))
fmt.Sprintf("profile %q has no stored credential; run `academy auth login`", profileName))
}
if token == "" {
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated,
fmt.Sprintf("profile %q credential is empty in keyring; run `weknora auth login`", profileName))
fmt.Sprintf("profile %q credential is empty in keyring; run `academy auth login`", profileName))
}
return emitToken(fopts, token, mode, profileName)
@@ -156,7 +156,7 @@ func runToken(f *cmdutil.Factory, fopts *cmdutil.FormatOptions) error {
// emitToken renders a resolved credential: the {token, mode, profile} envelope
// under --format json, else the raw token on stdout (no trailing newline, for
// clean $(weknora auth token) capture) with a TTY-only leak hint on stderr.
// clean $(academy auth token) capture) with a TTY-only leak hint on stderr.
func emitToken(fopts *cmdutil.FormatOptions, token, mode, profile string) error {
if token == "" {
return cmdutil.NewError(cmdutil.CodeAuthUnauthenticated, "active credential is empty")
@@ -165,7 +165,7 @@ func emitToken(fopts *cmdutil.FormatOptions, token, mode, profile string) error
return fopts.Emit(iostreams.IO.Out, tokenResult{Token: token, Mode: mode, Profile: profile}, nil)
}
// No trailing newline - clean $(weknora auth token) substitution.
// No trailing newline - clean $(academy auth token) substitution.
fmt.Fprint(iostreams.IO.Out, token)
// Defensive hint to stderr when stdout is an interactive terminal:
// the user likely didn't mean to display the secret on screen.
@@ -174,7 +174,7 @@ func emitToken(fopts *cmdutil.FormatOptions, token, mode, profile string) error
// recourse on leak - bearer tokens self-expire via refresh.
if iostreams.IO.IsStdoutTTY() {
fmt.Fprintln(iostreams.IO.Err)
fmt.Fprintln(iostreams.IO.Err, "hint: pipe to $(weknora auth token) to capture; this terminal scrollback now contains the secret")
fmt.Fprintln(iostreams.IO.Err, "hint: pipe to $(academy auth token) to capture; this terminal scrollback now contains the secret")
if mode == ModeAPIKey {
fmt.Fprintln(iostreams.IO.Err, "note: api-key credentials are long-lived - rotate via your auth provider if exposed (no `auth refresh` path)")
}
+6 -6
View File
@@ -5,10 +5,10 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/secrets"
)
// tokenTestFactory wires a config + in-memory secrets store the same way
@@ -24,8 +24,8 @@ func tokenTestFactory(t *testing.T, cfg *config.Config, store *secrets.MemStore)
}
// TestAuthToken_DefaultIsRawToken locks the scripting contract: with no
// explicit --format, `weknora auth token` emits the raw token (so
// WEKNORA_TOKEN=$(weknora auth token) works), NOT the JSON envelope — even
// explicit --format, `academy auth token` emits the raw token (so
// ACADEMY_TOKEN=$(academy auth token) works), NOT the JSON envelope — even
// though the global --format default is json. Explicit --format json still
// emits the {token,mode,profile} envelope (covered by the JSON test below).
func TestAuthToken_DefaultIsRawToken(t *testing.T) {
+14 -14
View File
@@ -1,4 +1,4 @@
// Package chat implements `weknora chat <text>` - the streaming RAG answer
// Package chat implements `academy chat <text>` - the streaming RAG answer
// entry point.
//
// Three output modes share a single SDK call:
@@ -28,11 +28,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"github.com/Tencent/WeKnora/cli/internal/sse"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
"academy/cli/internal/sse"
sdk "academy/client"
)
// chatFields enumerates the fields surfaced for `--jq` projection discovery
@@ -64,13 +64,13 @@ type ChatService interface {
KnowledgeQAStream(ctx context.Context, sessionID string, req *sdk.KnowledgeQARequest, cb func(*sdk.StreamResponse) error, opts ...sdk.ResourceURLOptions) error
}
// NewCmd builds `weknora chat <text>`.
// NewCmd builds `academy chat <text>`.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
opts := &Options{}
cmd := &cobra.Command{
Use: `chat "<text>"`,
Short: "Ask a streaming RAG question against a knowledge base",
Long: `Send a query to the WeKnora knowledge-chat endpoint and stream the
Long: `Send a query to the Academy knowledge-chat endpoint and stream the
answer back. By default a fresh session is created on first invocation; pass
--session to continue an existing conversation.
@@ -83,9 +83,9 @@ Modes:
Pass --reference to include bounded kb_id/chunk_id reference indexes. Pass
--verbose to include reasoning, tool activity, and lifecycle frames. Combine
both flags for the complete projected stream.`,
Example: ` weknora chat "What is RRF?" --kb a32a63ff-fb36-4874-bcaa-30f48570a694
weknora chat "Summarise this design doc" --kb my-kb --format json
weknora chat "Continue?" --session sess_abc`,
Example: ` academy chat "What is RRF?" --kb a32a63ff-fb36-4874-bcaa-30f48570a694
academy chat "Summarise this design doc" --kb my-kb --format json
academy chat "Continue?" --session sess_abc`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
opts.Query = strings.TrimSpace(args[0])
@@ -118,8 +118,8 @@ both flags for the complete projected stream.`,
UsedFor: "Ask a RAG question against a knowledge base. Default JSON returns a bounded answer-event projection. --reference adds indexed citations; --verbose adds reasoning, tools, and lifecycle events. --format ndjson streams raw SDK events; --format text renders the selected events live.",
RequiredFlags: []string{"<text> (positional)", "--kb"},
Examples: []string{
`weknora chat "What is RRF?" --kb kb_abc`,
`weknora chat "What is RRF?" --kb kb_abc --jq '[.data.events[].content] | join("")'`,
`academy chat "What is RRF?" --kb kb_abc`,
`academy chat "What is RRF?" --kb kb_abc --jq '[.data.events[].content] | join("")'`,
},
Output: "Default --format json: {ok,data:{events:[answer...],session_id,kb_id,query}}. --reference adds kb_id/chunk_id reference events; --verbose adds execution events. --format ndjson remains raw.",
})
@@ -146,7 +146,7 @@ func runChat(ctx context.Context, opts *Options, fopts *cmdutil.FormatOptions, s
sessionID := opts.SessionID
autoCreated := false
if sessionID == "" {
sess, err := svc.CreateSession(ctx, &sdk.CreateSessionRequest{Title: "weknora chat"})
sess, err := svc.CreateSession(ctx, &sdk.CreateSessionRequest{Title: "academy chat"})
if err != nil {
// Ctrl-C during session creation: classify as cancelled so the
// hint nudges the user toward retry-with-signal-clean, not
+4 -4
View File
@@ -7,10 +7,10 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/sse"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/sse"
sdk "academy/client"
)
// fakeChatService implements ChatService for unit tests. Tests configure the
+1 -1
View File
@@ -11,7 +11,7 @@ package chunkcmd
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
const chunkLong = `Manage and inspect document chunks.
+13 -13
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
)
// chunkDeleteFields enumerates the JSON discovery fields for `chunk delete`.
@@ -62,12 +62,12 @@ and writes input.confirmation_required to stderr. NEVER auto-pass -y
without the user's explicit go-ahead — the exit-10 protocol exists
exactly to guard against unintended deletes.`
const chunkDeleteExample = ` weknora chunk delete chunk_abc --doc doc_xyz # interactive confirm
weknora chunk delete chunk_abc --doc doc_xyz -y # no prompt
weknora chunk delete chunk_abc --doc doc_xyz -y --format json # bare {id, deleted:true} JSON
weknora chunk delete c1 c2 c3 --doc doc_xyz -y # delete 3 chunks under same doc, keep-going`
const chunkDeleteExample = ` academy chunk delete chunk_abc --doc doc_xyz # interactive confirm
academy chunk delete chunk_abc --doc doc_xyz -y # no prompt
academy chunk delete chunk_abc --doc doc_xyz -y --format json # bare {id, deleted:true} JSON
academy chunk delete c1 c2 c3 --doc doc_xyz -y # delete 3 chunks under same doc, keep-going`
// NewCmdDelete builds `weknora chunk delete <chunk-id> [<chunk-id>...] --doc <doc-id>`.
// NewCmdDelete builds `academy chunk delete <chunk-id> [<chunk-id>...] --doc <doc-id>`.
func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
opts := &DeleteOptions{}
cmd := &cobra.Command{
@@ -100,7 +100,7 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
opts.ChunkID = args[0]
return runDelete(c.Context(), opts, fopts, cli, f.Prompter())
}
batchRetry := append([]string{"weknora", "chunk", "delete"}, args...)
batchRetry := append([]string{"academy", "chunk", "delete"}, args...)
batchRetry = append(batchRetry, "--doc", opts.DocID, "-y")
if err := cmdutil.ConfirmDestructiveBatch(f.Prompter(), opts.Yes, fopts.WantsJSON(), "delete", "chunk", len(args), "chunk.delete", batchRetry); err != nil {
return err
@@ -132,9 +132,9 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
UsedFor: "permanently delete one or more chunks from a document",
RequiredFlags: []string{"<chunk-id>... (positional, at least one)", "--doc <doc-id>"},
Examples: []string{
"weknora chunk delete chunk_abc --doc doc_xyz -y",
"weknora chunk delete c1 c2 c3 --doc doc_xyz -y",
"weknora chunk delete chunk_abc --doc doc_xyz -y --format json",
"academy chunk delete chunk_abc --doc doc_xyz -y",
"academy chunk delete c1 c2 c3 --doc doc_xyz -y",
"academy chunk delete chunk_abc --doc doc_xyz -y --format json",
},
Output: "envelope.data shape depends on the form: a single chunk id -> {id, deleted:true}; multiple ids -> batch envelope (top-level status success|partial|error, ok=(failures==0), data per-item [{id, ok, error?}], meta.successes/failures — read data[].ok per id).",
Warnings: []string{
@@ -146,7 +146,7 @@ func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
}
func runDelete(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOptions, svc DeleteService, p prompt.Prompter) error {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "chunk", opts.ChunkID, "chunk.delete", []string{"weknora", "chunk", "delete", opts.ChunkID, "--doc", opts.DocID, "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "chunk", opts.ChunkID, "chunk.delete", []string{"academy", "chunk", "delete", opts.ChunkID, "--doc", opts.DocID, "-y"}); err != nil {
return err
}
if err := svc.DeleteChunk(ctx, opts.DocID, opts.ChunkID); err != nil {
+3 -3
View File
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/testutil"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/testutil"
)
type fakeChunkDeleteSvc struct {
+10 -10
View File
@@ -8,11 +8,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
"academy/cli/internal/text"
sdk "academy/client"
)
const (
@@ -72,11 +72,11 @@ AI agents: prefer 'search chunks' for retrieval tasks. Use 'chunk list'
only when you need to enumerate / verify the chunking output of a
specific document.`
const chunkListExample = ` weknora chunk list --doc doc_abc
weknora chunk list --doc doc_abc --all-pages --page-size 100
weknora chunk list --doc doc_abc --format json | jq '.[] | {id, chunk_index}'`
const chunkListExample = ` academy chunk list --doc doc_abc
academy chunk list --doc doc_abc --all-pages --page-size 100
academy chunk list --doc doc_abc --format json | jq '.[] | {id, chunk_index}'`
// NewCmdList builds `weknora chunk list --doc <doc-id>`.
// NewCmdList builds `academy chunk list --doc <doc-id>`.
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
opts := &ListOptions{}
cmd := &cobra.Command{
@@ -114,7 +114,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "List chunks of a specific document in stored order (admin/debug). Results come with meta.count; use --limit (1..10000) and --all-pages to paginate. Prefer 'search chunks' for RAG retrieval.",
RequiredFlags: []string{"--doc"},
Examples: []string{"weknora chunk list --doc doc_abc --format json", "weknora chunk list --doc doc_abc --all-pages --format json"},
Examples: []string{"academy chunk list --doc doc_abc --format json", "academy chunk list --doc doc_abc --all-pages --format json"},
Output: "envelope.data is an array of Chunk objects with id, chunk_index, content, is_enabled; meta.count is the returned count, meta.total_count the document's full chunk count, meta.has_more true when --limit truncated",
})
return cmd
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type listCall struct {
+9 -9
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// chunkViewFields enumerates the 23 SDK Chunk fields surfaced for `--format json`
@@ -37,7 +37,7 @@ const chunkViewLong = `Show a single chunk with all SDK fields.
Text output is a key-value block; pass --format json for the bare 23-field SDK
Chunk object. Content renders verbatim regardless of size — pipe to
less or use --format json for large chunks. WeKnora chunks are typically bounded
less or use --format json for large chunks. Academy chunks are typically bounded
by the ingest pipeline (~1000 tokens / a few KB), so unconditional full
rendering is reasonable.
@@ -53,11 +53,11 @@ invoke citation) is sufficient for view.
Typed exit codes:
resource.not_found no chunk with the given id (exit 4)`
const chunkViewExample = ` weknora chunk view chunk_abc
weknora chunk view chunk_abc --format json | jq '.content'
weknora chunk view chunk_abc --format json --jq '{id, chunk_index, is_enabled}'`
const chunkViewExample = ` academy chunk view chunk_abc
academy chunk view chunk_abc --format json | jq '.content'
academy chunk view chunk_abc --format json --jq '{id, chunk_index, is_enabled}'`
// NewCmdView builds `weknora chunk view <chunk-id>`.
// NewCmdView builds `academy chunk view <chunk-id>`.
func NewCmdView(f *cmdutil.Factory) *cobra.Command {
opts := &ViewOptions{}
cmd := &cobra.Command{
@@ -85,7 +85,7 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command {
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "fetch one chunk's fields and content by id (scope-less; no --doc needed)",
RequiredFlags: []string{"<chunk-id> (positional)"},
Examples: []string{"weknora chunk view chunk_abc"},
Examples: []string{"academy chunk view chunk_abc"},
Output: "envelope.data is the chunk object (id, content, knowledge_id, ...)",
})
return cmd
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeViewSvc struct {
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// TestCompletion_AllShells smoke-tests cobra's auto-registered completion
@@ -21,7 +21,7 @@ func TestCompletion_AllShells(t *testing.T) {
}{
{"bash", "bash completion", 1024},
{"zsh", "#compdef", 1024},
{"fish", "complete -c weknora", 1024},
{"fish", "complete -c academy", 1024},
{"powershell", "Register-ArgumentCompleter", 1024},
}
for _, tc := range cases {
+3 -3
View File
@@ -1,4 +1,4 @@
// Package configcmd holds the `weknora config` command tree.
// Package configcmd holds the `academy config` command tree.
//
// Currently a single read-only `view` subcommand that prints the resolved
// CLI configuration and its resolution chain. No mutation, no network.
@@ -11,10 +11,10 @@ package configcmd
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// NewCmd builds the `weknora config` parent command.
// NewCmd builds the `academy config` parent command.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
+24 -24
View File
@@ -8,13 +8,13 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/format"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/projectlink"
"github.com/Tencent/WeKnora/cli/internal/secrets"
"github.com/Tencent/WeKnora/cli/internal/xdg"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/format"
"academy/cli/internal/iostreams"
"academy/cli/internal/projectlink"
"academy/cli/internal/secrets"
"academy/cli/internal/xdg"
)
// viewFields enumerates the fields surfaced for `--format json` discovery on
@@ -46,7 +46,7 @@ type viewData struct {
ProjectLink string `json:"project_link"`
}
// NewCmdView builds `weknora config view`. Read-only inspection of the
// NewCmdView builds `academy config view`. Read-only inspection of the
// resolved config and resolution chain. Never builds the SDK client and
// never issues a network request: KB resolution uses ResolveKBLocal, secrets
// storage is detected from the store type, and everything else is read from
@@ -77,11 +77,11 @@ even when no profile or KB is configured (sources report "(none)" /
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "inspect the resolved CLI config and resolution chain (active profile, host, kb, log level, default format, file paths) without mutating or hitting the network",
Examples: []string{
"weknora config view",
"weknora config view --format json",
"weknora config view --jq '.data.active_profile'",
"academy config view",
"academy config view --format json",
"academy config view --jq '.data.active_profile'",
},
Output: "envelope.data is {active_profile, profile_source, auth_source, host, kb_id, kb_source, log_level, log_level_source, format_default, config_file, cache_dir, secrets, project_link}. auth_source reports whether the active credential is the profile+keyring or a stateless WEKNORA_TOKEN/WEKNORA_API_KEY env override.",
Output: "envelope.data is {active_profile, profile_source, auth_source, host, kb_id, kb_source, log_level, log_level_source, format_default, config_file, cache_dir, secrets, project_link}. auth_source reports whether the active credential is the profile+keyring or a stateless ACADEMY_TOKEN/ACADEMY_API_KEY env override.",
})
return cmd
}
@@ -129,14 +129,14 @@ func resolveView(cmd *cobra.Command, f *cmdutil.Factory) viewData {
}
}
// Auth source: stateless env credentials (WEKNORA_TOKEN/WEKNORA_API_KEY)
// Auth source: stateless env credentials (ACADEMY_TOKEN/ACADEMY_API_KEY)
// override the profile + keyring for the actual client, so report that —
// otherwise host/profile above would silently describe a profile the env
// credential bypassed. WEKNORA_HOST (when set) is the host that env cred
// credential bypassed. ACADEMY_HOST (when set) is the host that env cred
// authenticates against.
if active, kind := cmdutil.EnvCredential(); active {
d.AuthSource = kind + " env (stateless; bypasses profile + keyring)"
if h := strings.TrimSpace(os.Getenv("WEKNORA_HOST")); h != "" {
if h := strings.TrimSpace(os.Getenv("ACADEMY_HOST")); h != "" {
d.Host = h
}
} else if d.ActiveProfile != "" {
@@ -173,8 +173,8 @@ func resolveProfile(f *cmdutil.Factory) (name, source string) {
if f.ProfileOverride != "" {
return f.ProfileOverride, "--profile flag"
}
if v := os.Getenv("WEKNORA_PROFILE"); v != "" {
return v, "WEKNORA_PROFILE env"
if v := os.Getenv("ACADEMY_PROFILE"); v != "" {
return v, "ACADEMY_PROFILE env"
}
if f.Config != nil {
if cfg, err := f.Config(); err == nil && cfg != nil && cfg.CurrentProfile != "" {
@@ -196,8 +196,8 @@ func resolveKB(cmd *cobra.Command, f *cmdutil.Factory) (id, source string) {
if v, _ := cmd.Flags().GetString("kb"); v != "" {
return id, "--kb flag"
}
if v := os.Getenv("WEKNORA_KB_ID"); v != "" {
return id, "WEKNORA_KB_ID env"
if v := os.Getenv("ACADEMY_KB_ID"); v != "" {
return id, "ACADEMY_KB_ID env"
}
if cwd, werr := os.Getwd(); werr == nil {
if path, found, derr := projectlink.Discover(cwd); derr == nil && found {
@@ -216,14 +216,14 @@ func resolveLogLevel(cmd *cobra.Command) (level, source string) {
return level, "--log-level flag"
}
}
if v := os.Getenv("WEKNORA_LOG_LEVEL"); v != "" && cmdutil.IsValidLogLevel(v) {
return level, "WEKNORA_LOG_LEVEL env"
if v := os.Getenv("ACADEMY_LOG_LEVEL"); v != "" && cmdutil.IsValidLogLevel(v) {
return level, "ACADEMY_LOG_LEVEL env"
}
return level, "default"
}
// resolveFormatDefault reports the configured default output format: the
// config.yaml defaults.format value, else WEKNORA_FORMAT, else the hard
// config.yaml defaults.format value, else ACADEMY_FORMAT, else the hard
// default. This is the *default* used when --format is unset — not the
// per-invocation --format flag value.
func resolveFormatDefault() string {
@@ -231,7 +231,7 @@ func resolveFormatDefault() string {
if err == nil && cfg != nil && cfg.Defaults.Format != "" {
return cfg.Defaults.Format
}
if v := os.Getenv("WEKNORA_FORMAT"); v == "text" || v == "json" || v == "ndjson" {
if v := os.Getenv("ACADEMY_FORMAT"); v == "text" || v == "json" || v == "ndjson" {
return v
}
return string(cmdutil.DefaultFormatMode)
@@ -261,7 +261,7 @@ func resolveSecrets(f *cmdutil.Factory) string {
return "file"
}
// resolveProjectLink reports the discovered .weknora/project.yaml path or
// resolveProjectLink reports the discovered .academy/project.yaml path or
// "(none)". Walks up from cwd like ResolveKBLocal does.
func resolveProjectLink() string {
cwd, err := os.Getwd()
+8 -8
View File
@@ -7,10 +7,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type viewEnvelope struct {
@@ -101,7 +101,7 @@ func networkFreeFactory(t *testing.T) *cmdutil.Factory {
return f
}
// TestConfigView_EnvCredentialSurfaced: when WEKNORA_API_KEY + WEKNORA_HOST are
// TestConfigView_EnvCredentialSurfaced: when ACADEMY_API_KEY + ACADEMY_HOST are
// set, config view reports the env override (auth_source + the env host), not
// the bypassed config profile's host.
func TestConfigView_EnvCredentialSurfaced(t *testing.T) {
@@ -111,10 +111,10 @@ func TestConfigView_EnvCredentialSurfaced(t *testing.T) {
Profiles: map[string]config.Profile{"prod": {Host: "https://configured.example.com"}},
}
require.NoError(t, config.Save(cfg))
t.Setenv("WEKNORA_API_KEY", "sk-test")
t.Setenv("WEKNORA_HOST", "https://env-override.example.com")
t.Setenv("ACADEMY_API_KEY", "sk-test")
t.Setenv("ACADEMY_HOST", "https://env-override.example.com")
env := runViewJSON(t, networkFreeFactory(t))
assert.Contains(t, env.Data.AuthSource, "WEKNORA_API_KEY env")
assert.Contains(t, env.Data.AuthSource, "ACADEMY_API_KEY env")
assert.Equal(t, "https://env-override.example.com", env.Data.Host, "host must be the env override, not the profile host")
}
+15 -15
View File
@@ -1,4 +1,4 @@
// Package doc — create.go implements `weknora doc create --text "..."`.
// Package doc — create.go implements `academy doc create --text "..."`.
// Allows creating a knowledge entry directly from inline text content without
// uploading a file or fetching a remote URL.
package doc
@@ -10,10 +10,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
sdk "academy/client"
)
// docCreateFields enumerates the fields surfaced for `--format json` discovery
@@ -43,7 +43,7 @@ type CreateService interface {
) (*sdk.Knowledge, error)
}
// NewCmdCreate builds `weknora doc create --text "..."`.
// NewCmdCreate builds `academy doc create --text "..."`.
func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
opts := &CreateOptions{}
cmd := &cobra.Command{
@@ -52,15 +52,15 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
Long: `Create a new knowledge entry by passing Markdown content directly via --text.
Useful for short snippets, agent-generated content, or structured notes that
don't require a file upload or remote URL. KB resolution follows the standard
4-level chain: --kb flag > WEKNORA_KB_ID env > .weknora/project.yaml > error.
4-level chain: --kb flag > ACADEMY_KB_ID env > .academy/project.yaml > error.
--text <content> Document text in Markdown format (required).
--title <title> Display title stored with the entry (matches doc update --title).
--tag-id <id> Associate the new entry with a tag.
--channel <name> Override the ingestion-channel tag (default "api").`,
Example: ` weknora doc create --text "# Meeting Notes\n\nAction items: ..."
weknora doc create --text "$(cat notes.md)" --title "Sprint Notes" --kb my-kb
weknora doc create --text "API usage guide" --title "API Guide" --tag-id tag_abc`,
Example: ` academy doc create --text "# Meeting Notes\n\nAction items: ..."
academy doc create --text "$(cat notes.md)" --title "Sprint Notes" --kb my-kb
academy doc create --text "API usage guide" --title "API Guide" --tag-id tag_abc`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -108,11 +108,11 @@ don't require a file upload or remote URL. KB resolution follows the standard
cmdutil.AddFormatFlag(cmd, docCreateFields...)
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "Create a knowledge entry from inline Markdown text. KB resolved via --kb flag, WEKNORA_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"--text", "--kb (or WEKNORA_KB_ID / project link)"},
UsedFor: "Create a knowledge entry from inline Markdown text. KB resolved via --kb flag, ACADEMY_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"--text", "--kb (or ACADEMY_KB_ID / project link)"},
Examples: []string{
`weknora doc create --kb kb_eng --text "# Runbook\n\nRestart steps: ..."`,
`weknora doc create --kb kb_eng --text "$(cat notes.md)" --title "Sprint Notes"`,
`academy doc create --kb kb_eng --text "# Runbook\n\nRestart steps: ..."`,
`academy doc create --kb kb_eng --text "$(cat notes.md)" --title "Sprint Notes"`,
},
Output: "envelope.data is the created Knowledge object with id, knowledge_base_id, title, parse_status",
})
@@ -143,7 +143,7 @@ func runCreate(ctx context.Context, opts *CreateOptions, fopts *cmdutil.FormatOp
// timeout or `search` into empty results.
var meta *output.Meta
if k.ParseStatus == "draft" {
meta = &output.Meta{Hint: "document created in parse_status=draft (not yet indexed) — run `weknora doc reparse " + k.ID + "` to parse & make it searchable"}
meta = &output.Meta{Hint: "document created in parse_status=draft (not yet indexed) — run `academy doc reparse " + k.ID + "` to parse & make it searchable"}
}
if fopts.WantsJSON() {
return fopts.Emit(iostreams.IO.Out, k, meta)
+5 -5
View File
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeCreateSvc captures call arguments and returns canned responses.
@@ -151,12 +151,12 @@ func TestCreate_EmptyText_RejectsBeforeSDK(t *testing.T) {
assert.Nil(t, svc.got.req, "SDK must not be called when --text is empty")
}
// TestCreate_AgentHelp_EmitsUsedFor verifies that when WEKNORA_AGENT_HELP=1
// TestCreate_AgentHelp_EmitsUsedFor verifies that when ACADEMY_AGENT_HELP=1
// the `doc create --help` path emits a JSON blob containing "used_for".
// This is the representative test for 3.2; the mechanism is covered by
// internal/cmdutil/agenthelp_test.go — we test the wiring here.
func TestCreate_AgentHelp_EmitsUsedFor(t *testing.T) {
t.Setenv("WEKNORA_AGENT_HELP", "1")
t.Setenv("ACADEMY_AGENT_HELP", "1")
_, _ = iostreams.SetForTest(t)
f := &cmdutil.Factory{}
+19 -19
View File
@@ -6,11 +6,11 @@ import (
"github.com/spf13/cobra"
sdk "github.com/Tencent/WeKnora/client"
sdk "academy/client"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
)
// docDeleteFields enumerates the fields surfaced for `--format json` discovery
@@ -42,7 +42,7 @@ type deleteResult struct {
Deleted bool `json:"deleted"`
}
// NewCmdDelete builds `weknora doc delete`. Single-id keeps the simpler
// NewCmdDelete builds `academy doc delete`. Single-id keeps the simpler
// code path (one confirm prompt, exit 0/1); multi-id uses keep-going
// semantics (one -y confirms all, failures collected, exit 1 if any fail);
// --all --kb=<id> atomically clears every document in a knowledge base.
@@ -71,13 +71,13 @@ All-in-KB (--all --kb=<kb-id>):
AI agents: This is a high-risk write. Without -y/--yes the CLI exits 10
and writes input.confirmation_required to stderr. NEVER auto-pass -y
without the user's explicit go-ahead.`,
Example: ` weknora doc delete doc_abc # interactive confirm
weknora doc delete doc_abc -y # no prompt
weknora doc delete doc_abc -y --format json # bare {id, deleted:true} JSON
weknora doc delete doc_a doc_b doc_c -y # delete 3, keep-going
weknora doc delete doc_a doc_b --format json # multi-id JSON output
weknora doc delete --all --kb=kb_x -y # clear all docs in kb_x
weknora doc delete --all --kb=kb_x -y --format json # agent-friendly`,
Example: ` academy doc delete doc_abc # interactive confirm
academy doc delete doc_abc -y # no prompt
academy doc delete doc_abc -y --format json # bare {id, deleted:true} JSON
academy doc delete doc_a doc_b doc_c -y # delete 3, keep-going
academy doc delete doc_a doc_b --format json # multi-id JSON output
academy doc delete --all --kb=kb_x -y # clear all docs in kb_x
academy doc delete --all --kb=kb_x -y --format json # agent-friendly`,
Args: cobra.ArbitraryArgs,
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -94,7 +94,7 @@ without the user's explicit go-ahead.`,
if opts.KB == "" {
return cmdutil.NewError(cmdutil.CodeInputInvalidArgument, "--all requires --kb=<id>").
WithHint("specify --kb=<uuid-or-name> to scope the delete-all operation").
WithRetryArgv([]string{"weknora", "doc", "delete", "--all", "--kb=<kb-id>", "-y"})
WithRetryArgv([]string{"academy", "doc", "delete", "--all", "--kb=<kb-id>", "-y"})
}
if len(args) > 0 {
return cmdutil.NewFlagError(fmt.Errorf("--all is exclusive with positional doc ids"))
@@ -137,7 +137,7 @@ without the user's explicit go-ahead.`,
if len(args) == 1 {
return runDelete(c.Context(), opts, fopts, cli, f.Prompter(), args[0])
}
batchRetry := append([]string{"weknora", "doc", "delete"}, args...)
batchRetry := append([]string{"academy", "doc", "delete"}, args...)
batchRetry = append(batchRetry, "-y")
if err := cmdutil.ConfirmDestructiveBatch(f.Prompter(), opts.Yes, fopts.WantsJSON(), "delete", "document", len(args), "doc.delete", batchRetry); err != nil {
return err
@@ -168,9 +168,9 @@ without the user's explicit go-ahead.`,
UsedFor: "permanently delete one or more documents from a knowledge base",
RequiredFlags: []string{"<doc-id>... (positional) | --all --kb=<uuid-or-name>"},
Examples: []string{
"weknora doc delete doc_abc -y",
"weknora doc delete doc_a doc_b doc_c -y",
"weknora doc delete --all --kb=kb_x -y --format json",
"academy doc delete doc_abc -y",
"academy doc delete doc_a doc_b doc_c -y",
"academy doc delete --all --kb=kb_x -y --format json",
},
Output: "envelope.data shape depends on the form: a single doc id -> {id, deleted:true}; multiple doc ids -> batch envelope (top-level status success|partial|error, ok=(failures==0), data per-item [{id, ok, error?}], meta.successes/failures — read data[].ok per id, ok:true overall does not survive a partial failure / exit 1); --all --kb -> {kb_id, deleted_count}.",
Warnings: []string{
@@ -183,7 +183,7 @@ without the user's explicit go-ahead.`,
}
func runDelete(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOptions, svc DeleteService, p prompt.Prompter, id string) error {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "document", id, "doc.delete", []string{"weknora", "doc", "delete", id, "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "document", id, "doc.delete", []string{"academy", "doc", "delete", id, "-y"}); err != nil {
return err
}
@@ -203,7 +203,7 @@ func runDelete(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOp
// CodeInputConfirmationRequired (exit 10) with risk metadata so agents can
// surface the risk to the user before re-invoking with -y.
func runDeleteAll(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOptions, svc AllService, p prompt.Prompter) error {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "all docs in KB", opts.KB, "doc.delete_all", []string{"weknora", "doc", "delete", "--all", "--kb=" + opts.KB, "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "all docs in KB", opts.KB, "doc.delete_all", []string{"academy", "doc", "delete", "--all", "--kb=" + opts.KB, "-y"}); err != nil {
return err
}
+6 -6
View File
@@ -13,13 +13,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
sdk "github.com/Tencent/WeKnora/client"
sdk "academy/client"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/testutil"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/testutil"
)
// fakeAllSvc implements AllService for --all mode tests.
+3 -3
View File
@@ -1,4 +1,4 @@
// Package doc implements the `weknora doc` subtree (list / view / upload /
// Package doc implements the `academy doc` subtree (list / view / upload /
// fetch / create / download / delete / wait). Upload supports --recursive /
// --glob for bulk ingestion from local files. Fetch ingests a remote URL.
// Create adds a knowledge entry from inline text content.
@@ -12,10 +12,10 @@ package doc
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// NewCmd builds the `weknora doc` parent command.
// NewCmd builds the `academy doc` parent command.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "doc",
+10 -10
View File
@@ -10,8 +10,8 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// downloadFields enumerates the fields surfaced for `--format json` discovery on
@@ -38,7 +38,7 @@ type DownloadService interface {
OpenKnowledgeFile(ctx context.Context, knowledgeID string) (string, io.ReadCloser, error)
}
// NewCmdDownload builds `weknora doc download <id>`. Positional id, output
// NewCmdDownload builds `academy doc download <id>`. Positional id, output
// flag, `-` sentinel for stdout. Flags: `-O, --output <file>` for
// destination, `--clobber` for overwrite control.
func NewCmdDownload(f *cmdutil.Factory) *cobra.Command {
@@ -58,11 +58,11 @@ With --format json, on success emits a JSON envelope whose data has
path, bytes, and filename fields. When output is stdout (--output -),
the JSON envelope is suppressed because the raw bytes already occupy
stdout.`,
Example: ` weknora doc download doc_abc # writes ./<server-name>
weknora doc download doc_abc -O report.pdf
weknora doc download doc_abc --output - # stream to stdout (binary safe)
weknora doc download doc_abc -O report.pdf --clobber
weknora doc download doc_abc -O report.pdf --format json # JSON envelope`,
Example: ` academy doc download doc_abc # writes ./<server-name>
academy doc download doc_abc -O report.pdf
academy doc download doc_abc --output - # stream to stdout (binary safe)
academy doc download doc_abc -O report.pdf --clobber
academy doc download doc_abc -O report.pdf --format json # JSON envelope`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -86,8 +86,8 @@ stdout.`,
RequiredFlags: []string{"<doc-id> (positional)"},
Output: "with --format json (file output): envelope.data has path, bytes, filename; suppressed with --output - (raw bytes to stdout)",
Examples: []string{
"weknora doc download doc_abc --output ./manual.pdf",
"weknora doc download doc_abc --output - > manual.pdf",
"academy doc download doc_abc --output ./manual.pdf",
"academy doc download doc_abc --output - > manual.pdf",
},
})
return cmd
+2 -2
View File
@@ -13,8 +13,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// fakeDownloadSvc scripts an OpenKnowledgeFile response. The fake returns
+5 -5
View File
@@ -15,10 +15,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// docDryRunFactory builds a Factory whose Client closure panics if invoked —
@@ -43,7 +43,7 @@ func docDryRunFactory(t *testing.T) *cmdutil.Factory {
// registers the global persistent flags (mirrors addGlobalFlags in
// cmd/root.go).
func withRootHarnessDoc(sub *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "")
+13 -13
View File
@@ -1,4 +1,4 @@
// Package doc — fetch.go implements `weknora doc fetch <url>`.
// Package doc — fetch.go implements `academy doc fetch <url>`.
package doc
import (
@@ -8,9 +8,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// docFetchFields enumerates the fields surfaced for `--format json` discovery
@@ -45,7 +45,7 @@ type FetchService interface {
) (*sdk.Knowledge, error)
}
// NewCmdFetch builds `weknora doc fetch <url>`.
// NewCmdFetch builds `academy doc fetch <url>`.
func NewCmdFetch(f *cmdutil.Factory) *cobra.Command {
opts := &FetchOptions{}
cmd := &cobra.Command{
@@ -53,7 +53,7 @@ func NewCmdFetch(f *cmdutil.Factory) *cobra.Command {
Short: "Fetch a remote document into a knowledge base",
Long: `Server fetches the document at the given URL and ingests it into the resolved
knowledge base. KB resolution follows the standard 4-level chain:
--kb flag > WEKNORA_KB_ID env > .weknora/project.yaml > error.
--kb flag > ACADEMY_KB_ID env > .academy/project.yaml > error.
When the URL has a known file extension (.pdf, .docx, .md, .txt) the server
automatically switches from web-page-crawl mode to file-download mode. Pass
@@ -71,10 +71,10 @@ Server-side ingestion knobs:
--enable-multimodel Toggle multimodal extraction (image-in-PDF → text).
Unset ⇒ server default; pass true or false to override.
--channel <name> Override the ingestion-channel tag (default "api").`,
Example: ` weknora doc fetch https://example.com/whitepaper.pdf
weknora doc fetch https://example.com/no-ext --file-type pdf --title "Whitepaper"
weknora doc fetch https://example.com/article.html --name "Q3 Article" --tag-id tag_abc
weknora doc fetch https://example.com/report.pdf --kb my-kb --enable-multimodel`,
Example: ` academy doc fetch https://example.com/whitepaper.pdf
academy doc fetch https://example.com/no-ext --file-type pdf --title "Whitepaper"
academy doc fetch https://example.com/article.html --name "Q3 Article" --tag-id tag_abc
academy doc fetch https://example.com/report.pdf --kb my-kb --enable-multimodel`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
opts.URL = args[0]
@@ -135,10 +135,10 @@ Server-side ingestion knobs:
cmdutil.AddFormatFlag(cmd, docFetchFields...)
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "Ingest a remote URL into the resolved knowledge base. KB resolved via --kb flag, WEKNORA_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"<url> (positional)", "--kb (or WEKNORA_KB_ID / project link)"},
UsedFor: "Ingest a remote URL into the resolved knowledge base. KB resolved via --kb flag, ACADEMY_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"<url> (positional)", "--kb (or ACADEMY_KB_ID / project link)"},
Examples: []string{
`weknora doc fetch https://example.com/whitepaper.pdf --kb kb_eng`,
`academy doc fetch https://example.com/whitepaper.pdf --kb kb_eng`,
},
Output: "envelope.data is the created Knowledge object with id, knowledge_base_id, source, parse_status",
})
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeFetchSvc captures call arguments and returns canned responses.
+13 -13
View File
@@ -9,11 +9,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
"academy/cli/internal/text"
sdk "academy/client"
)
// docListFields enumerates the fields surfaced for `--format json` discovery on
@@ -58,7 +58,7 @@ type ListService interface {
ListKnowledgeWithFilter(ctx context.Context, kbID string, page, pageSize int, filter sdk.KnowledgeListFilter) ([]sdk.Knowledge, int64, error)
}
// NewCmdList builds `weknora doc list`.
// NewCmdList builds `academy doc list`.
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
opts := &ListOptions{}
cmd := &cobra.Command{
@@ -66,15 +66,15 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
Short: "List documents in a knowledge base",
Long: `Lists documents (uploaded files / web pages / inline text) in the
resolved knowledge base. KB resolution follows the standard 4-level chain:
--kb flag > WEKNORA_KB_ID env > .weknora/project.yaml > error. The --kb
--kb flag > ACADEMY_KB_ID env > .academy/project.yaml > error. The --kb
flag accepts either a KB UUID (passed through) or a name (resolved via list).
Default sort is updated_at desc so the most recent uploads surface first;
backend storage order is not guaranteed and varies between deployments.`,
Example: ` weknora doc list # uses project link / env
weknora doc list --kb a32a63ff-fb36-4874-bcaa-30f48570a694 # explicit UUID
weknora doc list --kb my-kb # resolved by name
weknora doc list --all-pages --format json # walk every page`,
Example: ` academy doc list # uses project link / env
academy doc list --kb a32a63ff-fb36-4874-bcaa-30f48570a694 # explicit UUID
academy doc list --kb my-kb # resolved by name
academy doc list --all-pages --format json # walk every page`,
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -115,7 +115,7 @@ backend storage order is not guaranteed and varies between deployments.`,
cmdutil.AddFormatFlag(cmd, docListFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "List documents in the resolved knowledge base. Results come with meta.count; use --limit to cap, --all-pages to walk every server page, --status/--keyword to filter server-side.",
Examples: []string{"weknora doc list --format json", "weknora doc list --all-pages --limit 200 --format json"},
Examples: []string{"academy doc list --format json", "academy doc list --all-pages --limit 200 --format json"},
Output: "envelope.data is an array of Knowledge objects with id, title, file_name, parse_status; meta.count is the returned count; meta.total_count is the server-side total before client-side --limit truncation; meta.has_more=true when --limit truncated",
})
return cmd
@@ -209,7 +209,7 @@ func runList(ctx context.Context, opts *ListOptions, fopts *cmdutil.FormatOption
}
// Default sort: updated_at desc. Server return order is not guaranteed,
// so client-side sort makes output deterministic regardless of backend
// storage choices. Mirrors `weknora kb list`.
// storage choices. Mirrors `academy kb list`.
sort.Slice(items, func(i, j int) bool {
return items[i].UpdatedAt.After(items[j].UpdatedAt)
})
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+7 -7
View File
@@ -13,10 +13,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeListSvc captures the request args and returns canned responses.
@@ -38,7 +38,7 @@ func (f *fakeListSvc) ListKnowledgeWithFilter(_ context.Context, kbID string, pa
}
// chdirIsolated parks cwd in a fresh tempdir so Factory.ResolveKB doesn't pick
// up a stray .weknora/project.yaml from the repo. Also clears WEKNORA_KB_ID
// up a stray .academy/project.yaml from the repo. Also clears ACADEMY_KB_ID
// for the duration of the test.
func chdirIsolated(t *testing.T) {
t.Helper()
@@ -46,7 +46,7 @@ func chdirIsolated(t *testing.T) {
require.NoError(t, err)
require.NoError(t, os.Chdir(t.TempDir()))
t.Cleanup(func() { _ = os.Chdir(prev) })
t.Setenv("WEKNORA_KB_ID", "")
t.Setenv("ACADEMY_KB_ID", "")
}
func TestList_Success_Text(t *testing.T) {
@@ -127,7 +127,7 @@ func TestList_HTTPError_500(t *testing.T) {
// TestList_KBIDRequired drives the cobra layer to verify Factory.ResolveKB's
// "no source supplied" path bubbles up as CodeKBIDRequired. Isolates cwd so
// no project.yaml sneaks in, and clears WEKNORA_KB_ID.
// no project.yaml sneaks in, and clears ACADEMY_KB_ID.
func TestList_KBIDRequired(t *testing.T) {
chdirIsolated(t)
_, _ = iostreams.SetForTest(t)
+10 -10
View File
@@ -6,10 +6,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/text"
sdk "academy/client"
)
// docReparseFields enumerates the fields surfaced for `--format json` discovery
@@ -27,7 +27,7 @@ type ReparseService interface {
ReparseKnowledge(ctx context.Context, id string) (*sdk.Knowledge, error)
}
// NewCmdReparse builds `weknora doc reparse <doc-id>`.
// NewCmdReparse builds `academy doc reparse <doc-id>`.
func NewCmdReparse(f *cmdutil.Factory) *cobra.Command {
opts := &ReparseOptions{}
cmd := &cobra.Command{
@@ -36,7 +36,7 @@ func NewCmdReparse(f *cmdutil.Factory) *cobra.Command {
Long: `Re-trigger server-side parsing of a document — the recovery path when a
document's parse_status is failed, or after its source changed. The document
keeps its id; parsing restarts asynchronously, so follow with
'weknora doc wait <doc-id>' to block until it reaches a terminal status.`,
'academy doc wait <doc-id>' to block until it reaches a terminal status.`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -64,10 +64,10 @@ keeps its id; parsing restarts asynchronously, so follow with
UsedFor: "re-run parsing on a document (recovery after parse_status=failed, or a changed source)",
RequiredFlags: []string{"<doc-id> (positional)"},
Examples: []string{
"weknora doc reparse doc_abc",
"weknora doc reparse doc_abc --format json",
"academy doc reparse doc_abc",
"academy doc reparse doc_abc --format json",
},
Output: "envelope.data is the Knowledge object with parse_status reset to the re-processing state; poll `weknora doc wait <doc-id>` for completion",
Output: "envelope.data is the Knowledge object with parse_status reset to the re-processing state; poll `academy doc wait <doc-id>` for completion",
})
return cmd
}
@@ -91,6 +91,6 @@ func runReparse(ctx context.Context, opts *ReparseOptions, fopts *cmdutil.Format
if k.ParseStatus != "" {
fmt.Fprintf(w, " parse_status: %s\n", k.ParseStatus)
}
fmt.Fprintf(w, " next: weknora doc wait %s\n", id)
fmt.Fprintf(w, " next: academy doc wait %s\n", id)
return nil
}
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeReparseSvc struct {
+7 -7
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// docUpdateFields enumerates the fields surfaced for `--format json` discovery
@@ -34,7 +34,7 @@ type UpdateService interface {
UpdateKnowledge(ctx context.Context, k *sdk.Knowledge) error
}
// NewCmdUpdate builds `weknora doc update <doc-id>`. At least one of
// NewCmdUpdate builds `academy doc update <doc-id>`. At least one of
// --title / --description must be provided.
func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
opts := &UpdateOptions{}
@@ -89,7 +89,7 @@ to the user first.`,
}
// Build a retry command from the flags the user actually passed so
// agents can re-invoke with -y after explicit human approval.
retryCmd := cmdutil.BuildRetryArgv(c, []string{"weknora", "doc", "update", id}, "title", "description", "format")
retryCmd := cmdutil.BuildRetryArgv(c, []string{"academy", "doc", "update", id}, "title", "description", "format")
if err := cmdutil.ConfirmWrite(f.Prompter(), opts.Yes, fopts.WantsJSON(), "update", "document", id, "doc.update", retryCmd); err != nil {
return err
}
@@ -106,8 +106,8 @@ to the user first.`,
UsedFor: "update a document's title or description (content is not editable — re-upload for that)",
RequiredFlags: []string{"<doc-id> (positional)", "--title or --description (at least one)"},
Examples: []string{
`weknora doc update doc_abc --title "Q3 Runbook" -y`,
`weknora doc update doc_abc --description "archived" --format json -y`,
`academy doc update doc_abc --title "Q3 Runbook" -y`,
`academy doc update doc_abc --description "archived" --format json -y`,
},
Output: "envelope.data is the Knowledge object with the new title/description",
Warnings: []string{
+4 -4
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
type fakeUpdateSvc struct {
+18 -18
View File
@@ -10,9 +10,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// uploadChannel is the default ingestion-channel tag the server records for
@@ -66,7 +66,7 @@ type UploadService interface {
) (*sdk.Knowledge, error)
}
// NewCmdUpload builds `weknora doc upload <file>`.
// NewCmdUpload builds `academy doc upload <file>`.
func NewCmdUpload(f *cmdutil.Factory) *cobra.Command {
opts := &UploadOptions{}
cmd := &cobra.Command{
@@ -74,7 +74,7 @@ func NewCmdUpload(f *cmdutil.Factory) *cobra.Command {
Short: "Upload a local file to the knowledge base",
Long: `Uploads a file (PDF / DOCX / Markdown / TXT / etc.) to the resolved
knowledge base. KB resolution follows the standard 4-level chain:
--kb flag > WEKNORA_KB_ID env > .weknora/project.yaml > error. The --kb
--kb flag > ACADEMY_KB_ID env > .academy/project.yaml > error. The --kb
flag accepts either a KB UUID (passed through) or a name (resolved via list).
Pass --name to override the recorded file name (useful when the local file
@@ -85,8 +85,8 @@ The two input modes (positional file / --recursive directory walk) are
mutually exclusive - pass exactly one. Use --recursive --glob to upload a
directory tree (see Examples); subdirectories are preserved as knowledge-base
folders, so a nested file lands at its path relative to the walked directory.
To ingest a remote URL use "weknora doc fetch";
to create an entry from inline text use "weknora doc create".
To ingest a remote URL use "academy doc fetch";
to create an entry from inline text use "academy doc create".
Server-side ingestion knobs:
@@ -99,12 +99,12 @@ Server-side ingestion knobs:
input.invalid_argument.
--channel <name> Override the ingestion-channel tag (default "api").
Applies to file / --recursive.`,
Example: ` weknora doc upload report.pdf
weknora doc upload notes.md --kb a32a63ff-fb36-4874-bcaa-30f48570a694
weknora doc upload notes.md --kb my-kb
weknora doc upload q3.pdf --name "Q3 Marketing Report.pdf"
weknora doc upload report.pdf --enable-multimodel --metadata team=alpha --metadata sprint=Q4
weknora doc upload ./docs --recursive --glob '*.pdf' --metadata team=alpha`,
Example: ` academy doc upload report.pdf
academy doc upload notes.md --kb a32a63ff-fb36-4874-bcaa-30f48570a694
academy doc upload notes.md --kb my-kb
academy doc upload q3.pdf --name "Q3 Marketing Report.pdf"
academy doc upload report.pdf --enable-multimodel --metadata team=alpha --metadata sprint=Q4
academy doc upload ./docs --recursive --glob '*.pdf' --metadata team=alpha`,
Args: cobra.MaximumNArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -192,11 +192,11 @@ Server-side ingestion knobs:
cmdutil.AddFormatFlag(cmd, docUploadFields...)
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "Upload a local file to the resolved knowledge base. KB resolved via --kb flag, WEKNORA_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"<file> (positional)", "--kb (or WEKNORA_KB_ID / project link)"},
UsedFor: "Upload a local file to the resolved knowledge base. KB resolved via --kb flag, ACADEMY_KB_ID env, or project link. Emits the created Knowledge object with its id.",
RequiredFlags: []string{"<file> (positional)", "--kb (or ACADEMY_KB_ID / project link)"},
Examples: []string{
`weknora doc upload report.pdf --kb kb_eng`,
`weknora doc upload report.pdf --kb kb_eng --jq .data.id # then: doc wait <id>`,
`academy doc upload report.pdf --kb kb_eng`,
`academy doc upload report.pdf --kb kb_eng --jq .data.id # then: doc wait <id>`,
},
Output: "envelope.data is the created Knowledge object with id, knowledge_base_id, file_name, parse_status",
})
@@ -250,7 +250,7 @@ func validateUploadFlags(opts *UploadOptions, args []string) error {
// MinimumNArgs(1) would emit — consistent with every other command
// that requires a positional argument.
return cmdutil.NewFlagError(errors.New(
"a file path is required (or use `weknora doc fetch` for URLs, `weknora doc create` for inline text)"))
"a file path is required (or use `academy doc fetch` for URLs, `academy doc create` for inline text)"))
}
return nil
}
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"path/filepath"
"strings"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
)
// uploadedFile holds the server-side result for a successful per-file upload.
+3 -3
View File
@@ -13,9 +13,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// scriptedUploadSvc records every CreateKnowledgeFromFile call and returns
+3 -3
View File
@@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeUploadSvc captures call arguments and returns canned responses.
+8 -8
View File
@@ -6,10 +6,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/text"
sdk "academy/client"
)
// docViewFields enumerates the fields surfaced for `--format json` discovery on
@@ -29,14 +29,14 @@ type ViewService interface {
GetKnowledge(ctx context.Context, id string) (*sdk.Knowledge, error)
}
// NewCmdView builds `weknora doc view <id>`.
// NewCmdView builds `academy doc view <id>`.
func NewCmdView(f *cmdutil.Factory) *cobra.Command {
opts := &ViewOptions{}
cmd := &cobra.Command{
Use: "view <doc-id>",
Short: "Show a document by ID",
Example: ` weknora doc view doc_abc
weknora doc view doc_abc --format json`,
Example: ` academy doc view doc_abc
academy doc view doc_abc --format json`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -56,7 +56,7 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command {
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "fetch one document's metadata by id",
RequiredFlags: []string{"<doc-id> (positional)"},
Examples: []string{"weknora doc view doc_abc", "weknora doc view doc_abc --jq .data.parse_status"},
Examples: []string{"academy doc view doc_abc", "academy doc view doc_abc --jq .data.parse_status"},
Output: "envelope.data is the document object (id, file_name, parse_status, ...)",
})
return cmd
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeViewSvc scripts a GetKnowledge response. Tests bypass cobra and call
+12 -12
View File
@@ -9,11 +9,11 @@ import (
"sync"
"time"
sdk "github.com/Tencent/WeKnora/client"
sdk "academy/client"
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// WaitOptions captures `doc wait` flag state.
@@ -23,11 +23,11 @@ type WaitOptions struct {
Interval time.Duration
}
// NewCmdWait builds `weknora doc wait <id> [<id>...]`.
// NewCmdWait builds `academy doc wait <id> [<id>...]`.
//
// Multi-id behaviour is always wait-all: blocks until every id reaches a
// terminal state. Use shell composition
// (`weknora doc wait id1 && weknora doc wait id2`) when fail-fast is
// (`academy doc wait id1 && academy doc wait id2`) when fail-fast is
// desired.
func NewCmdWait(f *cmdutil.Factory) *cobra.Command {
opts := &WaitOptions{}
@@ -46,10 +46,10 @@ Exit codes:
Multi-id is polled concurrently (max 5 parallel; use 'xargs -P' for more).
For fail-fast semantics, use shell composition:
weknora doc wait id1 && weknora doc wait id2 && weknora doc wait id3`,
Example: ` weknora doc wait doc_abc
weknora doc wait id1 id2 id3 --timeout 20m
weknora doc wait id1 id2 --format ndjson`,
academy doc wait id1 && academy doc wait id2 && academy doc wait id3`,
Example: ` academy doc wait doc_abc
academy doc wait id1 id2 id3 --timeout 20m
academy doc wait id1 id2 --format ndjson`,
Args: cobra.MinimumNArgs(1),
RunE: func(c *cobra.Command, args []string) error {
// Validate flags FIRST so an invalid --format doesn't cost the
@@ -99,8 +99,8 @@ For fail-fast semantics, use shell composition:
UsedFor: "block until one or more documents reach a terminal parse state (completed or failed), or --timeout elapses",
RequiredFlags: []string{"<doc-id>... (one or more positionals)"},
Examples: []string{
"weknora doc wait doc_abc",
"weknora doc wait doc_a doc_b --timeout 5m",
"academy doc wait doc_abc",
"academy doc wait doc_a doc_b --timeout 5m",
},
Output: "envelope.data is {completed:[], failed:[{id,message}], timeout:[]}",
Warnings: []string{
@@ -241,7 +241,7 @@ func waitForDocs(ctx context.Context, ids []string, svc WaitService, opts WaitOp
// auto-enqueues). It never progresses on its own, so
// waiting would hang to the --timeout (124). Fail fast with
// the exact unblock command instead of silently polling.
addFailed(FailedDoc{ID: id, Message: "parse_status=draft: not queued for parsing — run `weknora doc reparse " + id + "` to index it"})
addFailed(FailedDoc{ID: id, Message: "parse_status=draft: not queued for parsing — run `academy doc reparse " + id + "` to index it"})
return
}
+2 -2
View File
@@ -10,9 +10,9 @@ import (
"testing"
"time"
sdk "github.com/Tencent/WeKnora/client"
sdk "academy/client"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
func TestWaitCmd_Shape(t *testing.T) {
+25 -25
View File
@@ -1,4 +1,4 @@
// Package doctor implements `weknora doctor` - 4-item self-check.
// Package doctor implements `academy doctor` - 4-item self-check.
//
// Status semantics (4-tier):
//
@@ -29,13 +29,13 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/build"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/compat"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/secrets"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/build"
"academy/cli/internal/cmdutil"
"academy/cli/internal/compat"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/secrets"
sdk "academy/client"
)
// doctorFields enumerates the fields surfaced for `--format json` discovery on
@@ -94,7 +94,7 @@ type Services interface {
GetSystemInfo(ctx context.Context) (*sdk.SystemInfo, error)
}
// NewCmd builds `weknora doctor`.
// NewCmd builds `academy doctor`.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
opts := &Options{}
cmd := &cobra.Command{
@@ -124,15 +124,15 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command {
return nil
},
}
cmd.Flags().BoolVar(&opts.NoCache, "no-cache", false, "Bypass server-info cache (located at $XDG_CACHE_HOME/weknora/server-info.yaml); force re-probe")
cmd.Flags().BoolVar(&opts.NoCache, "no-cache", false, "Bypass server-info cache (located at $XDG_CACHE_HOME/academy/server-info.yaml); force re-probe")
cmd.Flags().BoolVar(&opts.Offline, "offline", false, "Skip network checks; only verify local keyring/file storage (credential_storage check still runs)")
cmdutil.AddFormatFlag(cmd, doctorFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "run self-checks: base-url reachability, auth credential, server version, credential storage",
Examples: []string{
"weknora doctor",
"weknora doctor --offline",
"weknora doctor --no-cache --format json",
"academy doctor",
"academy doctor --offline",
"academy doctor --no-cache --format json",
},
Output: "envelope.data is {summary:{all_passed,passed,warned,failed,skipped}, checks:[{name,status,details,hint?}]}",
})
@@ -175,7 +175,7 @@ func runChecks(ctx context.Context, opts *Options, svc Services, cliVer string)
t0 := time.Now()
if err := svc.PingBaseURL(ctx); err != nil {
checks[0].Status = StatusFail
checks[0].Hint = "verify the host configured for the active profile (run `weknora profile list` / `weknora profile add <n> --host=...`) and network reachability"
checks[0].Hint = "verify the host configured for the active profile (run `academy profile list` / `academy profile add <n> --host=...`) and network reachability"
checks[0].Details = err.Error()
} else {
checks[0].Status = StatusOK
@@ -187,7 +187,7 @@ func runChecks(ctx context.Context, opts *Options, svc Services, cliVer string)
if !cascade(&checks[1], opts.Offline, &checks[0]) {
if _, err := svc.GetCurrentUser(ctx); err != nil {
checks[1].Status = StatusFail
checks[1].Hint = "run `weknora auth login`"
checks[1].Hint = "run `academy auth login`"
checks[1].Details = err.Error()
} else {
checks[1].Status = StatusOK
@@ -297,7 +297,7 @@ func fillCredentialStorageCheck(c *Check) {
if _, isFile := store.(*secrets.FileStore); isFile {
c.Status = StatusWarn
c.Details = "falling back to file store: keychain unavailable"
c.Hint = "secrets persist at 0600 under $XDG_CONFIG_HOME/weknora/secrets/; install / unlock keyring for OS-backed storage"
c.Hint = "secrets persist at 0600 under $XDG_CONFIG_HOME/academy/secrets/; install / unlock keyring for OS-backed storage"
return
}
c.Status = StatusOK
@@ -389,7 +389,7 @@ func marker(s Status) string {
//
// Critically: this does NOT pre-resolve f.Client(). doctor's package promise
// (top comment) is that credential_storage runs even when no auth is set up -
// e.g. first-time `weknora doctor` to diagnose setup. Pre-resolving Client
// e.g. first-time `academy doctor` to diagnose setup. Pre-resolving Client
// here would early-exit with auth.unauthenticated before any check runs,
// contradicting the docs. Instead, GetCurrentUser / GetSystemInfo lazily
// resolve and surface their own failure as a per-check StatusFail.
@@ -405,12 +405,12 @@ func buildServices(f *cmdutil.Factory) (Services, error) {
// mirror the client builder (buildClientFromEnv) so doctor probes the host the
// real commands actually connect to; tier 1 is a doctor-local test/dev knob:
//
// 1. WEKNORA_BASE_URL — doctor-only probe override (used by tests); NOT read
// 1. ACADEMY_BASE_URL — doctor-only probe override (used by tests); NOT read
// by the client builder, so setting it points doctor at a host no real
// command uses. Kept for test/dev harnesses; leave unset in normal use.
// 2. WEKNORA_HOST — when stateless env credentials (WEKNORA_TOKEN /
// WEKNORA_API_KEY) are in effect, i.e. the headless agent path. Without
// this, `WEKNORA_API_KEY=… WEKNORA_HOST=… weknora doctor` falsely reported
// 2. ACADEMY_HOST — when stateless env credentials (ACADEMY_TOKEN /
// ACADEMY_API_KEY) are in effect, i.e. the headless agent path. Without
// this, `ACADEMY_API_KEY=… ACADEMY_HOST=… academy doctor` falsely reported
// "no host configured" and exited 1 while every other command worked.
// 3. active profile host — the configured default.
func resolveDoctorHost(cfg *config.Config) string {
@@ -418,15 +418,15 @@ func resolveDoctorHost(cfg *config.Config) string {
if ctx, ok := cfg.Profiles[cfg.CurrentProfile]; ok {
host = ctx.Host
}
// Env credentials authenticate via WEKNORA_HOST, bypassing the profile.
// Env credentials authenticate via ACADEMY_HOST, bypassing the profile.
// Honor it only when such creds are actually set, matching the client
// builder (a bare WEKNORA_HOST without creds is ignored there too).
// builder (a bare ACADEMY_HOST without creds is ignored there too).
if envActive, _ := cmdutil.EnvCredential(); envActive {
if v := strings.TrimSpace(os.Getenv("WEKNORA_HOST")); v != "" {
if v := strings.TrimSpace(os.Getenv("ACADEMY_HOST")); v != "" {
host = v
}
}
if v := os.Getenv("WEKNORA_BASE_URL"); v != "" {
if v := os.Getenv("ACADEMY_BASE_URL"); v != "" {
host = v
}
return host
+28 -28
View File
@@ -8,12 +8,12 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/compat"
"github.com/Tencent/WeKnora/cli/internal/config"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/secrets"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/compat"
"academy/cli/internal/config"
"academy/cli/internal/iostreams"
"academy/cli/internal/secrets"
sdk "academy/client"
)
// withCredStoreFactory swaps the package-level credStoreFactory hook for the
@@ -173,7 +173,7 @@ func TestDoctor_CacheHit_SkipsProbe(t *testing.T) {
// TestDoctor_NoConfig_StillRunsCredentialStorage guards the package-doc
// promise that credential_storage runs even with zero configuration. Round-4
// reviewer surfaced that buildServices used to abort on f.Client() failure,
// silently violating the doc for any first-time user running `weknora doctor`
// silently violating the doc for any first-time user running `academy doctor`
// to diagnose setup. The lazy-resolve fix means missing auth surfaces as
// auth_credential=fail, not a top-level command exit.
func TestDoctor_NoConfig_StillRunsCredentialStorage(t *testing.T) {
@@ -510,10 +510,10 @@ func TestDoctor_RunE_WarnReturnsNil(t *testing.T) {
}
// TestResolveDoctorHost_EnvCredentials - doctor's base_url probe must honor
// WEKNORA_HOST when stateless env credentials are in effect (the headless
// ACADEMY_HOST when stateless env credentials are in effect (the headless
// agent path), mirroring buildClientFromEnv. Regression: doctor previously
// read only the active profile host, so `WEKNORA_API_KEY=... WEKNORA_HOST=...
// weknora doctor` reported "no host configured" and exited 1 while every
// read only the active profile host, so `ACADEMY_API_KEY=... ACADEMY_HOST=...
// academy doctor` reported "no host configured" and exited 1 while every
// other command worked.
func TestResolveDoctorHost_EnvCredentials(t *testing.T) {
cfg := &config.Config{
@@ -521,39 +521,39 @@ func TestResolveDoctorHost_EnvCredentials(t *testing.T) {
Profiles: map[string]config.Profile{"prod": {Host: "https://profile-host"}},
}
t.Run("env creds + WEKNORA_HOST wins over profile", func(t *testing.T) {
t.Setenv("WEKNORA_TOKEN", "")
t.Setenv("WEKNORA_API_KEY", "sk-test")
t.Setenv("WEKNORA_HOST", "https://env-host:8080")
t.Setenv("WEKNORA_BASE_URL", "")
t.Run("env creds + ACADEMY_HOST wins over profile", func(t *testing.T) {
t.Setenv("ACADEMY_TOKEN", "")
t.Setenv("ACADEMY_API_KEY", "sk-test")
t.Setenv("ACADEMY_HOST", "https://env-host:8080")
t.Setenv("ACADEMY_BASE_URL", "")
if got := resolveDoctorHost(cfg); got != "https://env-host:8080" {
t.Errorf("want env host, got %q", got)
}
})
t.Run("env creds without WEKNORA_HOST falls back to profile", func(t *testing.T) {
t.Setenv("WEKNORA_API_KEY", "sk-test")
t.Setenv("WEKNORA_HOST", "")
t.Setenv("WEKNORA_BASE_URL", "")
t.Run("env creds without ACADEMY_HOST falls back to profile", func(t *testing.T) {
t.Setenv("ACADEMY_API_KEY", "sk-test")
t.Setenv("ACADEMY_HOST", "")
t.Setenv("ACADEMY_BASE_URL", "")
if got := resolveDoctorHost(cfg); got != "https://profile-host" {
t.Errorf("want profile host, got %q", got)
}
})
t.Run("no env creds ignores WEKNORA_HOST (matches client builder)", func(t *testing.T) {
t.Setenv("WEKNORA_TOKEN", "")
t.Setenv("WEKNORA_API_KEY", "")
t.Setenv("WEKNORA_HOST", "https://should-be-ignored")
t.Setenv("WEKNORA_BASE_URL", "")
t.Run("no env creds ignores ACADEMY_HOST (matches client builder)", func(t *testing.T) {
t.Setenv("ACADEMY_TOKEN", "")
t.Setenv("ACADEMY_API_KEY", "")
t.Setenv("ACADEMY_HOST", "https://should-be-ignored")
t.Setenv("ACADEMY_BASE_URL", "")
if got := resolveDoctorHost(cfg); got != "https://profile-host" {
t.Errorf("want profile host, got %q", got)
}
})
t.Run("WEKNORA_BASE_URL test override always wins", func(t *testing.T) {
t.Setenv("WEKNORA_API_KEY", "sk-test")
t.Setenv("WEKNORA_HOST", "https://env-host")
t.Setenv("WEKNORA_BASE_URL", "https://base-url-override")
t.Run("ACADEMY_BASE_URL test override always wins", func(t *testing.T) {
t.Setenv("ACADEMY_API_KEY", "sk-test")
t.Setenv("ACADEMY_HOST", "https://env-host")
t.Setenv("ACADEMY_BASE_URL", "https://base-url-override")
if got := resolveDoctorHost(cfg); got != "https://base-url-override" {
t.Errorf("want base-url override, got %q", got)
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// dryRunExpectation declares, for every leaf command, whether it must register
@@ -93,7 +93,7 @@ func TestDryRunCoverageMatchesExpectation(t *testing.T) {
var unlisted, wrong []string
eachLeafCommand(root, func(c *cobra.Command) {
key := strings.TrimPrefix(c.CommandPath(), "weknora ")
key := strings.TrimPrefix(c.CommandPath(), "academy ")
want, declared := dryRunExpectation[key]
if !declared {
unlisted = append(unlisted, key)
+9 -9
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
)
type exitCodeRow struct {
@@ -23,8 +23,8 @@ func exitCodeRows() []exitCodeRow {
return []exitCodeRow{
{0, "success", "", "continue"},
{1, "typed local.* / operation.failed / unclassified", "local.*, operation.failed, operation.cancelled, server.session_create_failed, internal.error", "read stderr, decide retry/abort"},
{2, "flag / argument validation error (cobra parse: unknown flag, arg count, missing required flag)", "input.invalid_argument (same type as exit 5; distinguish by exit code)", "re-check weknora <cmd> --help"},
{3, "authentication / authorization", "auth.*", "re-auth (weknora auth login), then retry"},
{2, "flag / argument validation error (cobra parse: unknown flag, arg count, missing required flag)", "input.invalid_argument (same type as exit 5; distinguish by exit code)", "re-check academy <cmd> --help"},
{3, "authentication / authorization", "auth.*", "re-auth (academy auth login), then retry"},
{4, "resource not found", "resource.not_found", "verify the resource id"},
{5, "invalid input value (typed validation, not a parse error)", "input.* (other than confirmation_required)", "adjust args, retry"},
{6, "rate limited", "server.rate_limited", "back off, retry"},
@@ -35,11 +35,11 @@ func exitCodeRows() []exitCodeRow {
}
}
// newCmdExitCodes builds the `weknora exit-codes` help-topic command.
// `weknora help exit-codes` renders Long for humans; running it directly
// newCmdExitCodes builds the `academy exit-codes` help-topic command.
// `academy help exit-codes` renders Long for humans; running it directly
// emits the machine-readable matrix (json by default, per the agent-first
// output contract). Listed in the command tree (not hidden) so humans have a
// discoverable path to it via `weknora help`, not only the README.
// discoverable path to it via `academy help`, not only the README.
func newCmdExitCodes() *cobra.Command {
cmd := &cobra.Command{
Use: "exit-codes",
@@ -66,7 +66,7 @@ func newCmdExitCodes() *cobra.Command {
cmdutil.AddFormatFlag(cmd, "code", "meaning", "error_types", "agent_action")
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "Machine-readable exit code matrix: what each code means and what to do next.",
Examples: []string{"weknora exit-codes", "weknora help exit-codes"},
Examples: []string{"academy exit-codes", "academy help exit-codes"},
Output: "envelope.data is an array of {code, meaning, error_types, agent_action}",
})
cmd.Long = "Exit codes and the agent action for each:\n\n" + exitCodesLongTable()
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
func TestExitCodesRows_CoversDocumentedMatrix(t *testing.T) {
+8 -8
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// CheckResult is the deep-verification response for `kb check <id>`.
@@ -41,7 +41,7 @@ var kbCheckFields = []string{
"is_processing", "processing_count", "failed_count",
}
// NewCmdCheck builds `weknora kb check <id>`.
// NewCmdCheck builds `academy kb check <id>`.
func NewCmdCheck(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "check <kb-id>",
@@ -52,11 +52,11 @@ Performs 1 + N HTTP calls:
1 GET /kb/{id} — reachable + counts + processing state
N page-walk doc list with parse_status=failed — failed_count
Use 'weknora kb status <id>' for a fast read-only health snapshot
Use 'academy kb status <id>' for a fast read-only health snapshot
(1 HTTP call, no failed_count). Use 'kb check' when you need
verification including failed-doc aggregation.`,
Example: ` weknora kb check kb_abc
weknora kb check kb_abc --format json`,
Example: ` academy kb check kb_abc
academy kb check kb_abc --format json`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -79,7 +79,7 @@ verification including failed-doc aggregation.`,
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "verify a knowledge base end-to-end: status plus failed-doc aggregation",
RequiredFlags: []string{"<kb-id> (positional)"},
Examples: []string{"weknora kb check kb_abc"},
Examples: []string{"academy kb check kb_abc"},
Output: "envelope.data is {id, reachable, retrieval_ready, failed_count, ...}; retrieval_ready=false means no embedding model is bound (run `kb config set`); deeper than `kb status`",
})
return cmd
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"strings"
"testing"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
sdk "academy/client"
)
type fakeCheckSvc struct {
+10 -10
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// kbConfigFields enumerates the fields surfaced for `--format json` discovery on
@@ -22,15 +22,15 @@ type ConfigService interface {
GetInitializationConfig(ctx context.Context, kbID string) (*sdk.KBModelConfigView, error)
}
// NewCmdConfig builds `weknora kb config <kb-id>` — read-only inspection of a
// knowledge base's model configuration. Write it with `weknora kb config set`.
// NewCmdConfig builds `academy kb config <kb-id>` — read-only inspection of a
// knowledge base's model configuration. Write it with `academy kb config set`.
func NewCmdConfig(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "config <kb-id>",
Short: "Show a knowledge base's model configuration (set it with `config set`)",
Long: `Show the model configuration bound to a knowledge base: embedding, llm
(chat), rerank, and multimodal model names + source. retrieval_ready is false
until an embedding model is bound — configure it with 'weknora kb config set'.
until an embedding model is bound — configure it with 'academy kb config set'.
Provider API keys are never shown.`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
@@ -48,12 +48,12 @@ Provider API keys are never shown.`,
}
// `kb config` reads (this command's RunE); `kb config set` writes. Same
// read/write pairing as mainstream config surfaces.
cmd.AddCommand(newKBModelWriteCmd(f, "set <kb-id>", []string{"weknora", "kb", "config", "set"}))
cmd.AddCommand(newKBModelWriteCmd(f, "set <kb-id>", []string{"academy", "kb", "config", "set"}))
cmdutil.AddFormatFlag(cmd, kbConfigFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "show a KB's model config (embedding/llm/rerank/multimodal by name, secret-free). retrieval_ready=false => run `weknora kb config set`. Write config with `weknora kb config set`.",
UsedFor: "show a KB's model config (embedding/llm/rerank/multimodal by name, secret-free). retrieval_ready=false => run `academy kb config set`. Write config with `academy kb config set`.",
RequiredFlags: []string{"<kb-id> (positional)"},
Examples: []string{"weknora kb config kb_abc --jq .data.embedding_model_id"},
Examples: []string{"academy kb config kb_abc --jq .data.embedding_model_id"},
Output: "envelope.data is {retrieval_ready, embedding{configured,model_name,source,dimension}, llm{...}, rerank{enabled,model_name}, multimodal{enabled}} — secret-free (no provider api keys)",
})
return cmd
@@ -77,7 +77,7 @@ func runConfig(ctx context.Context, fopts *cmdutil.FormatOptions, svc ConfigServ
fmt.Fprintf(w, "%-13s %s\n", "RERANK:", rerankLabel(cfg.Rerank))
fmt.Fprintf(w, "%-13s %v\n", "MULTIMODAL:", cfg.Multimodal.Enabled)
if !cfg.RetrievalReady {
fmt.Fprintln(w, "\n(not retrieval-ready — no embedding model; run `weknora kb config set <kb-id> --chat-model <id> --embedding-model <id>`)")
fmt.Fprintln(w, "\n(not retrieval-ready — no embedding model; run `academy kb config set <kb-id> --chat-model <id> --embedding-model <id>`)")
}
return nil
}
+10 -10
View File
@@ -7,9 +7,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type ConfigSetOptions struct {
@@ -28,7 +28,7 @@ type ConfigSetService interface {
}
// newKBModelWriteCmd builds the `kb config set` model-binding write command.
// head is the argv prefix used for the risk action and retry_argv (weknora kb
// head is the argv prefix used for the risk action and retry_argv (academy kb
// config set).
func newKBModelWriteCmd(f *cmdutil.Factory, use string, head []string) *cobra.Command {
opts := &ConfigSetOptions{}
@@ -39,7 +39,7 @@ func newKBModelWriteCmd(f *cmdutil.Factory, use string, head []string) *cobra.Co
Long: `Bind already-registered models to a knowledge base so it can embed, retrieve,
and generate. Both --chat-model (LLM, used for generation/summary) and
--embedding-model (used for retrieval) are required; register models first with
'weknora model create' and discover ids with 'weknora model list'.
'academy model create' and discover ids with 'academy model list'.
High-risk write: changing a KB's embedding model affects how its content is
indexed and searched (the server refuses to CHANGE it once the KB has
@@ -87,16 +87,16 @@ applying the change.`,
return runConfigSet(c.Context(), opts, fopts, cli, kbID)
},
}
cmd.Flags().StringVar(&opts.ChatModel, "chat-model", "", "Chat / LLM model id or name for generation & summary (required) — see `weknora model list`")
cmd.Flags().StringVar(&opts.EmbeddingModel, "embedding-model", "", "Embedding model id or name for retrieval (required) — see `weknora model list`")
cmd.Flags().StringVar(&opts.ChatModel, "chat-model", "", "Chat / LLM model id or name for generation & summary (required) — see `academy model list`")
cmd.Flags().StringVar(&opts.EmbeddingModel, "embedding-model", "", "Embedding model id or name for retrieval (required) — see `academy model list`")
cmdutil.AddFormatFlag(cmd, kbConfigFields...)
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
cmdutil.SetRisk(cmd, action)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "bind models to a KB so it becomes retrieval-ready. --chat-model and --embedding-model are required and accept a model id or name; discover them with `weknora model list`. Read the result back with `weknora kb config`.",
UsedFor: "bind models to a KB so it becomes retrieval-ready. --chat-model and --embedding-model are required and accept a model id or name; discover them with `academy model list`. Read the result back with `academy kb config`.",
RequiredFlags: []string{"<kb-id> (positional)", "--chat-model", "--embedding-model"},
Examples: []string{
"weknora kb config set kb_abc --chat-model model_llm --embedding-model model_emb -y",
"academy kb config set kb_abc --chat-model model_llm --embedding-model model_emb -y",
},
Output: "envelope.data is the resulting secret-free config view {retrieval_ready, embedding, llm, rerank, multimodal}",
Warnings: []string{
@@ -121,7 +121,7 @@ func validateConfigSetFlags(opts *ConfigSetOptions) error {
return &cmdutil.Error{
Code: cmdutil.CodeInputMissingFlag,
Message: "kb config set requires " + strings.Join(missing, " and "),
Hint: "discover model ids with `weknora model list` (or register one with `weknora model create`), then pass --chat-model <id> --embedding-model <id>",
Hint: "discover model ids with `academy model list` (or register one with `academy model create`), then pass --chat-model <id> --embedding-model <id>",
}
}
+5 -5
View File
@@ -10,10 +10,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
type fakeInitSvc struct {
@@ -103,7 +103,7 @@ func (s *readbackErrSvc) GetInitializationConfig(_ context.Context, _ string) (*
// keyed off the sub's own name (unlike withRootHarnessKB which is hardcoded to
// `update`).
func withRootKB(sub *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "")
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeConfigSvc struct {
+11 -11
View File
@@ -7,10 +7,10 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
sdk "academy/client"
)
// kbCreateFields enumerates the fields surfaced for `--format json` discovery
@@ -45,7 +45,7 @@ type CreateService interface {
CreateKnowledgeBase(ctx context.Context, kb *sdk.KnowledgeBase) (*sdk.KnowledgeBase, error)
}
// NewCmdCreate builds `weknora kb create <name>`. Positional <name> only,
// NewCmdCreate builds `academy kb create <name>`. Positional <name> only,
// consistent with `agent create <name>`.
func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
opts := &CreateOptions{}
@@ -86,14 +86,14 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
}
// --embedding-model accepts a model id or name (a UUID passes
// through; a name resolves among Embedding models). Configuring a
// KB's models fully is `weknora kb config set`; this just pre-sets the
// KB's models fully is `academy kb config set`; this just pre-sets the
// embedding model at creation.
if opts.EmbeddingModel, err = cmdutil.ResolveModelRef(c.Context(), cli, opts.EmbeddingModel, "Embedding"); err != nil {
return err
}
// --chat-model (id or name) pre-sets the KB's LLM at creation, so a
// KB can be born retrieval-ready in one step. Full model config
// (rerank / multimodal) is still `weknora kb config set`.
// (rerank / multimodal) is still `academy kb config set`.
if opts.ChatModel, err = cmdutil.ResolveModelRef(c.Context(), cli, opts.ChatModel, "KnowledgeQA"); err != nil {
return err
}
@@ -111,9 +111,9 @@ func NewCmdCreate(f *cmdutil.Factory) *cobra.Command {
UsedFor: "Create a new knowledge base with the given name. Emits the created KB object with its id.",
RequiredFlags: []string{"<name> (positional)"},
Examples: []string{
`weknora kb create "Eng Docs"`,
`weknora kb create "Eng Docs" --embedding-model text-embedding-3-small --chat-model gpt-4o-mini # retrieval-ready in one step`,
`weknora kb create "Eng Docs" --jq .data.id # capture id to chain into doc upload --kb`,
`academy kb create "Eng Docs"`,
`academy kb create "Eng Docs" --embedding-model text-embedding-3-small --chat-model gpt-4o-mini # retrieval-ready in one step`,
`academy kb create "Eng Docs" --jq .data.id # capture id to chain into doc upload --kb`,
},
Output: "envelope.data is the created KnowledgeBase object with id, name, type, embedding_model_id, summary_model_id",
})
@@ -155,7 +155,7 @@ func runCreate(ctx context.Context, opts *CreateOptions, fopts *cmdutil.FormatOp
// the agent to discover a silent-draft KB via a later empty search.
var meta *output.Meta
if created.EmbeddingModelID == "" {
meta = &output.Meta{Hint: "retrieval_ready=false: no embedding model bound. Uploaded docs will not be searchable until you run `weknora kb config set " + created.ID + " --embedding-model <id> --chat-model <id>` (create the KB with --embedding-model/--chat-model to skip this step)."}
meta = &output.Meta{Hint: "retrieval_ready=false: no embedding model bound. Uploaded docs will not be searchable until you run `academy kb config set " + created.ID + " --embedding-model <id> --chat-model <id>` (create the KB with --embedding-model/--chat-model to skip this step)."}
}
if fopts.WantsJSON() {
+5 -5
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// kbDryRunFactory builds a Factory whose Client closure panics if invoked —
@@ -37,7 +37,7 @@ func kbDryRunFactory(t *testing.T) *cmdutil.Factory {
// cmd/root.go). Required because kb subcommands inherit --yes / --format /
// --jq from root in production.
func withRootHarness(sub *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "")
+3 -3
View File
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakeCreateSvc captures the request and returns canned responses.
+10 -10
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
)
// kbDeleteFields enumerates the fields surfaced for `--format json` discovery
@@ -32,7 +32,7 @@ type deleteResult struct {
Deleted bool `json:"deleted"`
}
// NewCmdDelete builds `weknora kb delete`. The global -y/--yes persistent
// NewCmdDelete builds `academy kb delete`. The global -y/--yes persistent
// flag is the single skip-prompt switch for the destructive-write
// confirmation pattern.
func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
@@ -49,9 +49,9 @@ AI agents: This is a high-risk write. Without -y/--yes the CLI exits 10
and writes input.confirmation_required to stderr. NEVER auto-pass -y
without the user's explicit go-ahead — the exit-10 protocol exists
exactly to guard against unintended deletes.`,
Example: ` weknora kb delete kb_abc # interactive confirm
weknora kb delete kb_abc -y # no prompt
weknora kb delete kb_abc -y --format json # bare {id, deleted:true} JSON`,
Example: ` academy kb delete kb_abc # interactive confirm
academy kb delete kb_abc -y # no prompt
academy kb delete kb_abc -y --format json # bare {id, deleted:true} JSON`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
fopts, err := cmdutil.CheckFormatFlag(c)
@@ -83,8 +83,8 @@ exactly to guard against unintended deletes.`,
RequiredFlags: []string{"<kb-id> (positional)"},
Output: "envelope.data is {id, deleted:true}",
Examples: []string{
"weknora kb delete kb_abc -y",
"weknora kb delete kb_abc -y --format json",
"academy kb delete kb_abc -y",
"academy kb delete kb_abc -y --format json",
},
Warnings: []string{
"Requires explicit user approval (exit 10 / input.confirmation_required); never auto-add -y.",
@@ -95,7 +95,7 @@ exactly to guard against unintended deletes.`,
}
func runDelete(ctx context.Context, opts *DeleteOptions, fopts *cmdutil.FormatOptions, svc DeleteService, p prompt.Prompter, id string) error {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "knowledge base", id, "kb.delete", []string{"weknora", "kb", "delete", id, "-y"}); err != nil {
if err := cmdutil.ConfirmDestructive(p, opts.Yes, fopts.WantsJSON(), "delete", "knowledge base", id, "kb.delete", []string{"academy", "kb", "delete", id, "-y"}); err != nil {
return err
}
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// TestKBDelete_DryRun_NoExit10: --dry-run must bypass ConfirmDestructive.
+6 -6
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
"github.com/Tencent/WeKnora/cli/internal/testutil"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
"academy/cli/internal/testutil"
)
// fakeDeleteSvc records what id was deleted.
@@ -167,7 +167,7 @@ func TestDelete_JSONOut_WithYes_Proceeds(t *testing.T) {
func TestKbDelete_NoYes_JSONMode_AttachesRiskAndRetry(t *testing.T) {
// Non-TTY + JSON mode without -y must return CodeInputConfirmationRequired
// with risk.action == "kb.delete" and retry_argv == [weknora kb delete kb_x -y].
// with risk.action == "kb.delete" and retry_argv == [academy kb delete kb_x -y].
// Regression test for H1: ConfirmDestructive must attach risk + retry_argv.
iostreams.SetForTest(t)
svc := &fakeDeleteSvc{}
@@ -185,5 +185,5 @@ func TestKbDelete_NoYes_JSONMode_AttachesRiskAndRetry(t *testing.T) {
require.NotNil(t, ce.Risk, "expected risk metadata on confirmation_required error")
assert.Equal(t, "kb.delete", ce.Risk.Action, "expected risk.action == kb.delete")
assert.Equal(t, "destructive", ce.Risk.Level, "expected risk.level == destructive")
assert.Equal(t, []string{"weknora", "kb", "delete", "kb_x", "-y"}, ce.RetryArgv, "expected retry_argv")
assert.Equal(t, []string{"academy", "kb", "delete", "kb_x", "-y"}, ce.RetryArgv, "expected retry_argv")
}
+7 -7
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// kbEditFields enumerates the fields surfaced for `--format json` discovery on
@@ -45,7 +45,7 @@ type EditService interface {
UpdateKnowledgeBase(ctx context.Context, id string, req *sdk.UpdateKnowledgeBaseRequest) (*sdk.KnowledgeBase, error)
}
// NewCmdEdit builds `weknora kb update <id>`. At least one of --name /
// NewCmdEdit builds `academy kb update <id>`. At least one of --name /
// --description must be provided.
func NewCmdEdit(f *cmdutil.Factory) *cobra.Command {
opts := &EditOptions{}
@@ -105,7 +105,7 @@ to the user first.`,
}
// Build a retry command from the flags the user actually passed so
// agents can re-invoke with -y after explicit human approval.
retryCmd := cmdutil.BuildRetryArgv(c, []string{"weknora", "kb", "update", id}, "name", "description", "format")
retryCmd := cmdutil.BuildRetryArgv(c, []string{"academy", "kb", "update", id}, "name", "description", "format")
if err := cmdutil.ConfirmWrite(f.Prompter(), opts.Yes, fopts.WantsJSON(), "update", "knowledge base", id, "kb.update", retryCmd); err != nil {
return err
}
@@ -122,8 +122,8 @@ to the user first.`,
RequiredFlags: []string{"<kb-id> (positional)", "--name or --description (at least one)"},
Output: "envelope.data is the updated KnowledgeBase object (id, name, description)",
Examples: []string{
"weknora kb update kb_abc --name \"New Name\" -y",
"weknora kb update kb_abc --description \"Updated desc\" --format json -y",
"academy kb update kb_abc --name \"New Name\" -y",
"academy kb update kb_abc --description \"Updated desc\" --format json -y",
},
Warnings: []string{
"Requires explicit user approval (exit 10 / input.confirmation_required); never auto-add -y.",
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
)
// TestKBEdit_DryRun_RejectsNoMutationFlag: --dry-run must reject the same
+6 -6
View File
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/prompt"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/prompt"
sdk "academy/client"
)
// fakeEditSvc captures the (id, request) pair handed to UpdateKnowledgeBase
@@ -119,12 +119,12 @@ func TestEdit_NotFound(t *testing.T) {
func stringPtr(s string) *string { return &s }
// withRootHarnessKB wraps `weknora kb update ...` under a synthetic root cmd
// withRootHarnessKB wraps `academy kb update ...` under a synthetic root cmd
// that registers the global persistent flags (mirrors addGlobalFlags in
// cmd/root.go). Required because NewCmdEdit reads --yes and --format from the
// persistent flag set.
func withRootHarnessKB(edit *cobra.Command, args ...string) *cobra.Command {
root := &cobra.Command{Use: "weknora"}
root := &cobra.Command{Use: "academy"}
pf := root.PersistentFlags()
pf.BoolP("yes", "y", false, "")
pf.String("format", "", "Output format: text | json | ndjson")
+4 -4
View File
@@ -1,16 +1,16 @@
// Package kb holds the `weknora kb` command tree: list / view / create /
// Package kb holds the `academy kb` command tree: list / view / create /
// update / delete / pin / unpin. Verb set follows common CRUD vocabulary
// (list/view/create/update/delete) plus pin/unpin. Bulk content deletion
// is exposed via `weknora doc delete --all --kb=<id>`.
// is exposed via `academy doc delete --all --kb=<id>`.
package kb
import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"academy/cli/internal/cmdutil"
)
// NewCmd builds the `weknora kb` parent command.
// NewCmd builds the `academy kb` parent command.
func NewCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "kb",
+7 -7
View File
@@ -9,11 +9,11 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
"github.com/Tencent/WeKnora/cli/internal/output"
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
"academy/cli/internal/output"
"academy/cli/internal/text"
sdk "academy/client"
)
// kbListFields enumerates the fields surfaced for `--format json` discovery on
@@ -43,7 +43,7 @@ type ListService interface {
ListKnowledgeBases(ctx context.Context) ([]sdk.KnowledgeBase, error)
}
// NewCmdList builds `weknora kb list`.
// NewCmdList builds `academy kb list`.
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
opts := &ListOptions{}
cmd := &cobra.Command{
@@ -75,7 +75,7 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmdutil.AddFormatFlag(cmd, kbListFields...)
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: "List knowledge bases in the current tenant. --format json emits the standard envelope {ok, data:[...], meta:{count}, profile}.",
Examples: []string{"weknora kb list --format json"},
Examples: []string{"academy kb list --format json"},
Output: "envelope.data is an array of KnowledgeBase objects with id, name, is_pinned, type, embedding_model_id; meta.total_count is the full tenant set and meta.has_more=true means --limit truncated it (raise --limit to get the rest)",
})
return cmd
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
type fakeListSvc struct {
+6 -6
View File
@@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// kbPinFields enumerates the fields surfaced for `--format json` discovery on
@@ -31,12 +31,12 @@ type PinService interface {
TogglePinKnowledgeBase(ctx context.Context, id string) (*sdk.KnowledgeBase, error)
}
// NewCmdPin builds `weknora kb pin <id>`.
// NewCmdPin builds `academy kb pin <id>`.
func NewCmdPin(f *cmdutil.Factory) *cobra.Command {
return newPinCmd(f, "pin", true, "Pin a knowledge base to the top of the list")
}
// NewCmdUnpin builds `weknora kb unpin <id>`.
// NewCmdUnpin builds `academy kb unpin <id>`.
func NewCmdUnpin(f *cmdutil.Factory) *cobra.Command {
return newPinCmd(f, "unpin", false, "Unpin a knowledge base")
}
@@ -76,7 +76,7 @@ func newPinCmd(f *cmdutil.Factory, use string, want bool, short string) *cobra.C
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
UsedFor: use + " a knowledge base (idempotent: a no-op if it is already in the target state)",
RequiredFlags: []string{"<kb-id> (positional)"},
Examples: []string{"weknora kb " + use + " kb_abc"},
Examples: []string{"academy kb " + use + " kb_abc"},
Output: "envelope.data is the KnowledgeBase with is_pinned reflecting the new state",
})
return cmd
+3 -3
View File
@@ -10,9 +10,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
sdk "github.com/Tencent/WeKnora/client"
"academy/cli/internal/cmdutil"
"academy/cli/internal/iostreams"
sdk "academy/client"
)
// fakePinSvc satisfies PinService: ListKnowledgeBases + TogglePinKnowledgeBase.
Loaded 100 of 3136 files, more files were not shown because too many files have changed in this diff. Show more