feat(cli): chunk subtree + MCP chunk_list tool + curation rationale

New subtree (chunk list / view / delete) exposes RAG retrieval
debugging primitives with SDK-grounded field set (23 Chunk fields).
Pagination follows v0.4 canon: --limit / --page-size (1..1000) /
--all-pages.

- chunk list --doc <id>: enumerate by ChunkIndex (separate from
  search chunks which is hybrid retrieval; Long help documents the
  distinction)
- chunk view <id>: scope-less render via /chunks/by-id route; full
  content verbatim
- chunk delete <id> --doc <id>: scope-flag + scope-id; L-13
  destructive; 404 NOT idempotent; resource.not_found /
  auth.forbidden / input.confirmation_required typed exit codes
  documented in Long help

MCP server gains chunk_list as 10th curated tool. Schema deliberately
exposes only doc_id + limit (no pagination workflow on MCP); response
includes truncated_at_limit flag when total > limit.

cli/AGENTS.md MCP curation rationale rewritten: curated read-only is
a deliberate product call because the server side does not yet
enforce per-token scope. When server scope ships, mutation tools can
land in the MCP surface.

Shared helper cli/internal/text/timeago_string.go (FuzzyAgoStr)
extracted from session list during the C2 quality-review pass.
This commit is contained in:
nullkey
2026-05-16 01:22:14 +08:00
committed by lyingbug
parent 59132a56f6
commit 5b07c9ab87
15 changed files with 1111 additions and 19 deletions
+25
View File
@@ -0,0 +1,25 @@
package text
import "time"
// FuzzyAgoStr is the string-input variant of FuzzyAgo for SDK types that
// carry timestamps as RFC3339 strings (sdk.Chunk.UpdatedAt, sdk.Session.
// UpdatedAt, ...) rather than time.Time.
//
// Behavior:
// - ts == "" → "-" (server has no timestamp; render placeholder)
// - parse error → ts (surface the raw value rather than hide it)
// - parse OK → FuzzyAgo(now, parsed)
//
// The parse-error fallback is deliberate: if the server starts emitting a
// new format we want it visible in the table, not silently replaced by "-".
func FuzzyAgoStr(now time.Time, ts string) string {
if ts == "" {
return "-"
}
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
return ts
}
return FuzzyAgo(now, t)
}
+31
View File
@@ -0,0 +1,31 @@
package text_test
import (
"testing"
"time"
"github.com/Tencent/WeKnora/cli/internal/text"
)
func TestFuzzyAgoStr(t *testing.T) {
now := time.Date(2026, 5, 15, 12, 0, 0, 0, time.UTC)
tests := []struct {
name string
ts string
want string
}{
{"empty renders dash", "", "-"},
{"valid RFC3339 5m ago", now.Add(-5 * time.Minute).Format(time.RFC3339), "about 5 minutes ago"},
{"valid RFC3339 2d ago", now.Add(-2 * 24 * time.Hour).Format(time.RFC3339), "about 2 days ago"},
{"unparseable returned verbatim", "not-a-date", "not-a-date"},
{"wrong format returned verbatim", "2026-05-15 12:00:00", "2026-05-15 12:00:00"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := text.FuzzyAgoStr(now, tt.ts)
if got != tt.want {
t.Errorf("FuzzyAgoStr(%q) = %q, want %q", tt.ts, got, tt.want)
}
})
}
}