WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
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
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (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
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 and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (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
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
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (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
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 and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (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
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
package kb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
||||
"github.com/Tencent/WeKnora/cli/internal/iostreams"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
)
|
||||
|
||||
// StatusResult is the health-oriented response for `kb status <id>`.
|
||||
// Shallow read only: 1 HTTP call, no failed-doc aggregation.
|
||||
// For deep verification including failed_count, use `kb check <id>`.
|
||||
type StatusResult struct {
|
||||
ID string `json:"id"`
|
||||
Reachable bool `json:"reachable"`
|
||||
// RetrievalReady is false when the KB has no embedding model bound — it can
|
||||
// never index or retrieve until `kb config set` runs. Always emitted (no
|
||||
// omitempty) so a not-ready KB is visible, not silently green.
|
||||
RetrievalReady bool `json:"retrieval_ready"`
|
||||
KnowledgeCount int64 `json:"knowledge_count,omitempty"`
|
||||
ChunkCount int64 `json:"chunk_count,omitempty"`
|
||||
IsProcessing bool `json:"is_processing,omitempty"`
|
||||
ProcessingCount int64 `json:"processing_count,omitempty"`
|
||||
}
|
||||
|
||||
// StatusService is the narrow SDK surface needed for kb status.
|
||||
type StatusService interface {
|
||||
GetKnowledgeBase(ctx context.Context, id string) (*sdk.KnowledgeBase, error)
|
||||
}
|
||||
|
||||
var kbStatusFields = []string{
|
||||
"id", "reachable", "retrieval_ready", "knowledge_count", "chunk_count",
|
||||
"is_processing", "processing_count",
|
||||
}
|
||||
|
||||
// NewCmdStatus builds `weknora kb status <id>`.
|
||||
func NewCmdStatus(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "status <kb-id>",
|
||||
Short: "Show health status of a knowledge base (shallow, 1 HTTP)",
|
||||
Long: `Show health-oriented fields for a KB.
|
||||
|
||||
1 HTTP call:
|
||||
reachable / knowledge_count / chunk_count / is_processing / processing_count
|
||||
|
||||
For deep verification including failed_count, use 'weknora kb check <id>'
|
||||
(1 + N HTTP, pages the doc list with parse_status=failed).
|
||||
|
||||
For full metadata (config / pinned / tenant), use 'weknora kb view <id>'.`,
|
||||
Example: ` weknora kb status kb_abc
|
||||
weknora kb status kb_abc --format json`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
fopts, err := cmdutil.CheckFormatFlag(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fopts.ResolveDefault(iostreams.IO.IsStdoutTTY())
|
||||
cli, err := f.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res, err := runStatus(c.Context(), cli, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return emitStatus(res, fopts, iostreams.IO.Out)
|
||||
},
|
||||
}
|
||||
cmdutil.AddFormatFlag(cmd, kbStatusFields...)
|
||||
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
|
||||
UsedFor: "shallow health probe of a knowledge base (one HTTP call): reachability, no failed-doc aggregation",
|
||||
RequiredFlags: []string{"<kb-id> (positional)"},
|
||||
Examples: []string{"weknora kb status kb_abc"},
|
||||
Output: "envelope.data is {id, reachable, retrieval_ready, ...}; retrieval_ready=false means no embedding model is bound (run `kb config set`), so the KB cannot index/retrieve; use `kb check` for deep failed-doc aggregation",
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
|
||||
// runStatus is the testable core: fetch KB metadata and return a StatusResult.
|
||||
// Never returns an error for "kb not reachable" (Reachable=false carries
|
||||
// that signal).
|
||||
func runStatus(ctx context.Context, svc StatusService, id string) (*StatusResult, error) {
|
||||
kb, err := svc.GetKnowledgeBase(ctx, id)
|
||||
if err != nil {
|
||||
return &StatusResult{ID: id, Reachable: false}, nil
|
||||
}
|
||||
return &StatusResult{
|
||||
ID: kb.ID,
|
||||
Reachable: true,
|
||||
RetrievalReady: kb.EmbeddingModelID != "",
|
||||
KnowledgeCount: kb.KnowledgeCount,
|
||||
ChunkCount: kb.ChunkCount,
|
||||
IsProcessing: kb.IsProcessing,
|
||||
ProcessingCount: kb.ProcessingCount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// emitStatus renders res using --format options. Mirrors emitWaitResult
|
||||
// pattern from cli/cmd/doc/wait.go for consistency.
|
||||
func emitStatus(res *StatusResult, fopts *cmdutil.FormatOptions, w io.Writer) error {
|
||||
switch fopts.Mode {
|
||||
case cmdutil.FormatJSON, cmdutil.FormatNDJSON:
|
||||
return fopts.Emit(w, res, nil)
|
||||
case cmdutil.FormatText, "":
|
||||
return writeStatusText(w, res)
|
||||
default:
|
||||
return fmt.Errorf("unsupported --format %q for kb status", fopts.Mode)
|
||||
}
|
||||
}
|
||||
|
||||
func writeStatusText(w io.Writer, res *StatusResult) error {
|
||||
fmt.Fprintf(w, "ID: %s\n", res.ID)
|
||||
fmt.Fprintf(w, "Reachable: %v\n", res.Reachable)
|
||||
if !res.Reachable {
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(w, "Retrieval: %v%s\n", res.RetrievalReady, retrievalHint(res.RetrievalReady))
|
||||
fmt.Fprintf(w, "Knowledge: %d\n", res.KnowledgeCount)
|
||||
fmt.Fprintf(w, "Chunks: %d\n", res.ChunkCount)
|
||||
fmt.Fprintf(w, "Processing: %v (%d active)\n", res.IsProcessing, res.ProcessingCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
// retrievalHint annotates a not-ready KB in text output with the fix.
|
||||
func retrievalHint(ready bool) string {
|
||||
if ready {
|
||||
return ""
|
||||
}
|
||||
return " ← no embedding model bound; run `weknora kb config set <id>`"
|
||||
}
|
||||
|
||||
// compile-time check: SDK client satisfies StatusService.
|
||||
var _ StatusService = (*sdk.Client)(nil)
|
||||
Reference in New Issue
Block a user