2026-05-15 17:22:14 +00:00
package chunkcmd
import (
"context"
"fmt"
"text/tabwriter"
"time"
"github.com/spf13/cobra"
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
"github.com/Tencent/WeKnora/cli/internal/iostreams"
refactor(cli): envelope sweep — Emit shape, batch ops, MCP StructuredContent, api flag cleanup
Sweep every CLI output path through the v0.7 envelope contract.
FormatOptions.Emit signature changes to (w, data, meta *output.Meta)
so list commands surface meta.count / has_more in the wire envelope.
TTY indent decision plumbed via FormatOptions.TTY (set by
ResolveDefault). --format and --jq promoted to persistent root flags
so unknown-subcommand paths still reach the typed-envelope guard
(per-command registration would have rejected --format on unknown
commands as cobra-prose exit 2). WEKNORA_FORMAT env-var fallback
honored before TTY-resolved default. AddFormatFlag retained for the
per-command --jq field-hint Long-text addendum.
~55 production Emit call sites swept across cli/cmd/**: list paths
populate meta.count; mutation paths pass nil meta; envelope.profile
threaded via globalProfile. Existing JSON-shape tests migrated to
decode the envelope wrapper.
Multi-target batch operations get a unified shape via new helpers:
- output.BatchItem + output.WriteBatchEnvelope (§4.5 per-item ok
pattern; data:[{id, ok, result?|error?}], meta:{count, successes*,
failures*}; Successes/Failures *int so explicit zero survives
omitempty in all-fail case).
- cmdutil.RunBatch + cmdutil.EmitBatch + cmdutil.DeletedAtNow +
cmdutil.ClassifyContextErr collapse the three previously-duplicated
multi-delete pipelines (doc / chunk / session) into one call site
pattern. doc upload --recursive uses the same helpers with a per-
file resultFn. Summary error sets Silent:true so the stderr
envelope path doesn't duplicate the stdout batch detail (exit 1
preserved via Code → ExitCode).
ConfirmDestructive / ConfirmDestructiveBatch extended with action +
retryCmd parameters. Every destructive command (kb delete, kb edit,
doc delete, doc delete --all, agent delete, agent edit, session
delete, chunk delete, auth logout, api -X DELETE) now attaches
error.risk.{level:"destructive", action:"<noun.verb>"} +
error.retry_command on the exit-10 envelope. kb edit / agent edit
also gain the destructive guard wiring (CHANGELOG listed them as
gated but they were silently executing without -y).
MCP tool handlers' 31 error paths return CallToolResult with
IsError + Content text fallback + StructuredContent (envelope.error
shape via cmdutil.ErrorToDetail). Handler Out type changed from
typed *sdk.X to any so the go-sdk auto-marshal doesn't overwrite
StructuredContent with a zero-struct on error returns. Success path
manually populates CallToolResult.StructuredContent via successResult
helper.
weknora api cleanup:
- -d/--data flag removed; body via --input <file> or --input -
(stdin) only. Aligns with gh / curl convention.
- HTTP method whitelist removed; any non-empty method accepted.
- HTTP Retry-After header → cmdutil.Error.RetryAfterSeconds →
envelope.error.retry_after_seconds.
- runAPIPaginated raw-passthrough fallback now wraps response in
envelope so --paginate never emits bare JSON to stdout.
Test sweep: ~60 cmd/** tests migrated to decode envelope shape.
9 wire-contract goldens updated under cli/acceptance/testdata/wire/.
Spec: docs/superpowers/specs/2026-05-20-weknora-cli-v0.7-design.md §4 / §5
2026-05-21 10:41:56 +00:00
"github.com/Tencent/WeKnora/cli/internal/output"
2026-05-15 17:22:14 +00:00
"github.com/Tencent/WeKnora/cli/internal/text"
sdk "github.com/Tencent/WeKnora/client"
)
const (
defaultPageSize = 50
maxPageSize = 1000
defaultLimit = 50
maxLimit = 1000
previewWidth = 80
)
2026-05-17 17:38:30 +00:00
// chunkListFields enumerates the fields surfaced for `--format json` discovery on
2026-05-15 17:22:14 +00:00
// `chunk list`. Mirrors sdk.Chunk json tags — all 23 fields are projectable
// because chunk list returns bare SDK objects.
var chunkListFields = [ ] string {
"id" , "seq_id" , "knowledge_id" , "knowledge_base_id" , "tenant_id" ,
"tag_id" , "content" , "chunk_index" , "is_enabled" , "status" ,
"start_at" , "end_at" , "pre_chunk_id" , "next_chunk_id" , "chunk_type" ,
"parent_chunk_id" , "relation_chunks" , "indirect_relation_chunks" ,
"metadata" , "content_hash" , "image_info" , "created_at" , "updated_at" ,
}
// ListService is the narrow SDK surface this command depends on.
type ListService interface {
2026-05-25 12:21:41 +00:00
ListKnowledgeChunks ( ctx context . Context , knowledgeID string , page , pageSize int , chunkTypes ... string ) ( [ ] sdk . Chunk , int64 , error )
2026-05-15 17:22:14 +00:00
}
type ListOptions struct {
// DocID scopes the listing to a single knowledge document (SDK
// `knowledge_id`). The chunks SDK does not expose a KB-wide route.
DocID string
// PageSize is the server batch size (1..1000, default 50).
PageSize int
// Limit caps the client-side accumulated slice (1..1000, default 50).
// Default 50 chosen as domain-tuned for chunk enumeration (RAG debug).
Limit int
// AllPages walks server pages internally until total exhausted or
2026-05-17 17:38:30 +00:00
// --limit hit. Mirrors the session list / doc list pagination pattern.
2026-05-15 17:22:14 +00:00
AllPages bool
}
const chunkListLong = ` List chunks under a document in stored order .
' chunk list -- doc D ' enumerates ALL chunks of document D in ChunkIndex
order ( the per - doc ordinal assigned at ingest time ) . This is the
admin / debug surface for RAG retrieval — see what the chunking pipeline
produced , audit content , find a chunk id to view / delete .
For relevance - ranked retrieval ( the RAG runtime surface ) , use
' search chunks "<query>" -- kb K ' instead . That command runs hybrid
vector + keyword scoring across all chunks of a knowledge base .
Typed exit codes :
input . invalid_argument -- limit / -- page - size out of 1. .1000 range ( exit 5 )
resource . not_found no document with the given id ( exit 4 )
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
2026-05-17 17:38:30 +00:00
weknora chunk list -- doc doc_abc -- format json | jq ' . [ ] | { id , chunk_index } ' `
2026-05-15 17:22:14 +00:00
// NewCmdList builds `weknora chunk list --doc <doc-id>`.
func NewCmdList ( f * cmdutil . Factory ) * cobra . Command {
2026-05-15 18:42:18 +00:00
opts := & ListOptions { }
2026-05-15 17:22:14 +00:00
cmd := & cobra . Command {
Use : "list" ,
Short : "List chunks of a document (admin/debug, not retrieval)" ,
Long : chunkListLong ,
Example : chunkListExample ,
Args : cobra . NoArgs ,
RunE : func ( c * cobra . Command , _ [ ] string ) error {
2026-05-17 17:38:30 +00:00
fopts , err := cmdutil . CheckFormatFlag ( c )
2026-05-15 17:22:14 +00:00
if err != nil {
return err
}
2026-05-17 17:38:30 +00:00
fopts . ResolveDefault ( iostreams . IO . IsStdoutTTY ( ) )
2026-05-15 17:22:14 +00:00
cli , err := f . Client ( )
if err != nil {
return err
}
2026-05-17 17:38:30 +00:00
return runList ( c . Context ( ) , opts , fopts , cli )
2026-05-15 17:22:14 +00:00
} ,
}
cmd . Flags ( ) . StringVar ( & opts . DocID , "doc" , "" , "Document id (SDK knowledge_id) to enumerate chunks for" )
_ = cmd . MarkFlagRequired ( "doc" )
cmd . Flags ( ) . IntVarP ( & opts . Limit , "limit" , "L" , defaultLimit , "Maximum results to return (1..1000)" )
cmd . Flags ( ) . IntVar ( & opts . PageSize , "page-size" , defaultPageSize , "Items per server batch (1..1000)" )
cmd . Flags ( ) . BoolVar ( & opts . AllPages , "all-pages" , false , "Walk all server pages until exhausted (or --limit hit)" )
2026-05-17 17:38:30 +00:00
cmdutil . AddFormatFlag ( cmd , chunkListFields ... )
2026-05-29 12:06:30 +00:00
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..1000) 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" } ,
Output : "envelope.data is an array of Chunk objects with id, chunk_index, content, is_enabled; meta.count is the total returned" ,
} )
2026-05-15 17:22:14 +00:00
return cmd
}
2026-05-17 17:38:30 +00:00
func runList ( ctx context . Context , opts * ListOptions , fopts * cmdutil . FormatOptions , svc ListService ) error {
2026-05-15 17:22:14 +00:00
if opts . Limit < 1 || opts . Limit > maxLimit {
return & cmdutil . Error {
Code : cmdutil . CodeInputInvalidArgument ,
Message : fmt . Sprintf ( "--limit must be in 1..%d, got %d" , maxLimit , opts . Limit ) ,
}
}
if opts . PageSize < 1 || opts . PageSize > maxPageSize {
return & cmdutil . Error {
Code : cmdutil . CodeInputInvalidArgument ,
Message : fmt . Sprintf ( "--page-size must be in 1..%d, got %d" , maxPageSize , opts . PageSize ) ,
}
}
var items [ ] sdk . Chunk
refactor(cli): envelope sweep — Emit shape, batch ops, MCP StructuredContent, api flag cleanup
Sweep every CLI output path through the v0.7 envelope contract.
FormatOptions.Emit signature changes to (w, data, meta *output.Meta)
so list commands surface meta.count / has_more in the wire envelope.
TTY indent decision plumbed via FormatOptions.TTY (set by
ResolveDefault). --format and --jq promoted to persistent root flags
so unknown-subcommand paths still reach the typed-envelope guard
(per-command registration would have rejected --format on unknown
commands as cobra-prose exit 2). WEKNORA_FORMAT env-var fallback
honored before TTY-resolved default. AddFormatFlag retained for the
per-command --jq field-hint Long-text addendum.
~55 production Emit call sites swept across cli/cmd/**: list paths
populate meta.count; mutation paths pass nil meta; envelope.profile
threaded via globalProfile. Existing JSON-shape tests migrated to
decode the envelope wrapper.
Multi-target batch operations get a unified shape via new helpers:
- output.BatchItem + output.WriteBatchEnvelope (§4.5 per-item ok
pattern; data:[{id, ok, result?|error?}], meta:{count, successes*,
failures*}; Successes/Failures *int so explicit zero survives
omitempty in all-fail case).
- cmdutil.RunBatch + cmdutil.EmitBatch + cmdutil.DeletedAtNow +
cmdutil.ClassifyContextErr collapse the three previously-duplicated
multi-delete pipelines (doc / chunk / session) into one call site
pattern. doc upload --recursive uses the same helpers with a per-
file resultFn. Summary error sets Silent:true so the stderr
envelope path doesn't duplicate the stdout batch detail (exit 1
preserved via Code → ExitCode).
ConfirmDestructive / ConfirmDestructiveBatch extended with action +
retryCmd parameters. Every destructive command (kb delete, kb edit,
doc delete, doc delete --all, agent delete, agent edit, session
delete, chunk delete, auth logout, api -X DELETE) now attaches
error.risk.{level:"destructive", action:"<noun.verb>"} +
error.retry_command on the exit-10 envelope. kb edit / agent edit
also gain the destructive guard wiring (CHANGELOG listed them as
gated but they were silently executing without -y).
MCP tool handlers' 31 error paths return CallToolResult with
IsError + Content text fallback + StructuredContent (envelope.error
shape via cmdutil.ErrorToDetail). Handler Out type changed from
typed *sdk.X to any so the go-sdk auto-marshal doesn't overwrite
StructuredContent with a zero-struct on error returns. Success path
manually populates CallToolResult.StructuredContent via successResult
helper.
weknora api cleanup:
- -d/--data flag removed; body via --input <file> or --input -
(stdin) only. Aligns with gh / curl convention.
- HTTP method whitelist removed; any non-empty method accepted.
- HTTP Retry-After header → cmdutil.Error.RetryAfterSeconds →
envelope.error.retry_after_seconds.
- runAPIPaginated raw-passthrough fallback now wraps response in
envelope so --paginate never emits bare JSON to stdout.
Test sweep: ~60 cmd/** tests migrated to decode envelope shape.
9 wire-contract goldens updated under cli/acceptance/testdata/wire/.
Spec: docs/superpowers/specs/2026-05-20-weknora-cli-v0.7-design.md §4 / §5
2026-05-21 10:41:56 +00:00
truncated := false
2026-05-15 17:22:14 +00:00
if opts . AllPages {
accum := make ( [ ] sdk . Chunk , 0 )
for page := 1 ; ; page ++ {
chunks , total , err := svc . ListKnowledgeChunks ( ctx , opts . DocID , page , opts . PageSize )
if err != nil {
return cmdutil . WrapHTTP ( err , "list chunks for doc %s" , opts . DocID )
}
accum = append ( accum , chunks ... )
if len ( accum ) >= opts . Limit {
accum = accum [ : opts . Limit ]
refactor(cli): envelope sweep — Emit shape, batch ops, MCP StructuredContent, api flag cleanup
Sweep every CLI output path through the v0.7 envelope contract.
FormatOptions.Emit signature changes to (w, data, meta *output.Meta)
so list commands surface meta.count / has_more in the wire envelope.
TTY indent decision plumbed via FormatOptions.TTY (set by
ResolveDefault). --format and --jq promoted to persistent root flags
so unknown-subcommand paths still reach the typed-envelope guard
(per-command registration would have rejected --format on unknown
commands as cobra-prose exit 2). WEKNORA_FORMAT env-var fallback
honored before TTY-resolved default. AddFormatFlag retained for the
per-command --jq field-hint Long-text addendum.
~55 production Emit call sites swept across cli/cmd/**: list paths
populate meta.count; mutation paths pass nil meta; envelope.profile
threaded via globalProfile. Existing JSON-shape tests migrated to
decode the envelope wrapper.
Multi-target batch operations get a unified shape via new helpers:
- output.BatchItem + output.WriteBatchEnvelope (§4.5 per-item ok
pattern; data:[{id, ok, result?|error?}], meta:{count, successes*,
failures*}; Successes/Failures *int so explicit zero survives
omitempty in all-fail case).
- cmdutil.RunBatch + cmdutil.EmitBatch + cmdutil.DeletedAtNow +
cmdutil.ClassifyContextErr collapse the three previously-duplicated
multi-delete pipelines (doc / chunk / session) into one call site
pattern. doc upload --recursive uses the same helpers with a per-
file resultFn. Summary error sets Silent:true so the stderr
envelope path doesn't duplicate the stdout batch detail (exit 1
preserved via Code → ExitCode).
ConfirmDestructive / ConfirmDestructiveBatch extended with action +
retryCmd parameters. Every destructive command (kb delete, kb edit,
doc delete, doc delete --all, agent delete, agent edit, session
delete, chunk delete, auth logout, api -X DELETE) now attaches
error.risk.{level:"destructive", action:"<noun.verb>"} +
error.retry_command on the exit-10 envelope. kb edit / agent edit
also gain the destructive guard wiring (CHANGELOG listed them as
gated but they were silently executing without -y).
MCP tool handlers' 31 error paths return CallToolResult with
IsError + Content text fallback + StructuredContent (envelope.error
shape via cmdutil.ErrorToDetail). Handler Out type changed from
typed *sdk.X to any so the go-sdk auto-marshal doesn't overwrite
StructuredContent with a zero-struct on error returns. Success path
manually populates CallToolResult.StructuredContent via successResult
helper.
weknora api cleanup:
- -d/--data flag removed; body via --input <file> or --input -
(stdin) only. Aligns with gh / curl convention.
- HTTP method whitelist removed; any non-empty method accepted.
- HTTP Retry-After header → cmdutil.Error.RetryAfterSeconds →
envelope.error.retry_after_seconds.
- runAPIPaginated raw-passthrough fallback now wraps response in
envelope so --paginate never emits bare JSON to stdout.
Test sweep: ~60 cmd/** tests migrated to decode envelope shape.
9 wire-contract goldens updated under cli/acceptance/testdata/wire/.
Spec: docs/superpowers/specs/2026-05-20-weknora-cli-v0.7-design.md §4 / §5
2026-05-21 10:41:56 +00:00
truncated = true
2026-05-15 17:22:14 +00:00
break
}
2026-05-17 17:38:30 +00:00
if len ( chunks ) == 0 || int64 ( len ( accum ) ) >= total {
2026-05-15 17:22:14 +00:00
break
}
}
items = accum
} else {
chunks , _ , err := svc . ListKnowledgeChunks ( ctx , opts . DocID , 1 , opts . PageSize )
if err != nil {
return cmdutil . WrapHTTP ( err , "list chunks for doc %s" , opts . DocID )
}
items = chunks
}
if items == nil {
items = [ ] sdk . Chunk { } // JSON [] not null
}
if len ( items ) > opts . Limit {
items = items [ : opts . Limit ]
refactor(cli): envelope sweep — Emit shape, batch ops, MCP StructuredContent, api flag cleanup
Sweep every CLI output path through the v0.7 envelope contract.
FormatOptions.Emit signature changes to (w, data, meta *output.Meta)
so list commands surface meta.count / has_more in the wire envelope.
TTY indent decision plumbed via FormatOptions.TTY (set by
ResolveDefault). --format and --jq promoted to persistent root flags
so unknown-subcommand paths still reach the typed-envelope guard
(per-command registration would have rejected --format on unknown
commands as cobra-prose exit 2). WEKNORA_FORMAT env-var fallback
honored before TTY-resolved default. AddFormatFlag retained for the
per-command --jq field-hint Long-text addendum.
~55 production Emit call sites swept across cli/cmd/**: list paths
populate meta.count; mutation paths pass nil meta; envelope.profile
threaded via globalProfile. Existing JSON-shape tests migrated to
decode the envelope wrapper.
Multi-target batch operations get a unified shape via new helpers:
- output.BatchItem + output.WriteBatchEnvelope (§4.5 per-item ok
pattern; data:[{id, ok, result?|error?}], meta:{count, successes*,
failures*}; Successes/Failures *int so explicit zero survives
omitempty in all-fail case).
- cmdutil.RunBatch + cmdutil.EmitBatch + cmdutil.DeletedAtNow +
cmdutil.ClassifyContextErr collapse the three previously-duplicated
multi-delete pipelines (doc / chunk / session) into one call site
pattern. doc upload --recursive uses the same helpers with a per-
file resultFn. Summary error sets Silent:true so the stderr
envelope path doesn't duplicate the stdout batch detail (exit 1
preserved via Code → ExitCode).
ConfirmDestructive / ConfirmDestructiveBatch extended with action +
retryCmd parameters. Every destructive command (kb delete, kb edit,
doc delete, doc delete --all, agent delete, agent edit, session
delete, chunk delete, auth logout, api -X DELETE) now attaches
error.risk.{level:"destructive", action:"<noun.verb>"} +
error.retry_command on the exit-10 envelope. kb edit / agent edit
also gain the destructive guard wiring (CHANGELOG listed them as
gated but they were silently executing without -y).
MCP tool handlers' 31 error paths return CallToolResult with
IsError + Content text fallback + StructuredContent (envelope.error
shape via cmdutil.ErrorToDetail). Handler Out type changed from
typed *sdk.X to any so the go-sdk auto-marshal doesn't overwrite
StructuredContent with a zero-struct on error returns. Success path
manually populates CallToolResult.StructuredContent via successResult
helper.
weknora api cleanup:
- -d/--data flag removed; body via --input <file> or --input -
(stdin) only. Aligns with gh / curl convention.
- HTTP method whitelist removed; any non-empty method accepted.
- HTTP Retry-After header → cmdutil.Error.RetryAfterSeconds →
envelope.error.retry_after_seconds.
- runAPIPaginated raw-passthrough fallback now wraps response in
envelope so --paginate never emits bare JSON to stdout.
Test sweep: ~60 cmd/** tests migrated to decode envelope shape.
9 wire-contract goldens updated under cli/acceptance/testdata/wire/.
Spec: docs/superpowers/specs/2026-05-20-weknora-cli-v0.7-design.md §4 / §5
2026-05-21 10:41:56 +00:00
truncated = true
2026-05-15 17:22:14 +00:00
}
2026-05-17 17:38:30 +00:00
if fopts . WantsJSON ( ) {
refactor(cli): envelope sweep — Emit shape, batch ops, MCP StructuredContent, api flag cleanup
Sweep every CLI output path through the v0.7 envelope contract.
FormatOptions.Emit signature changes to (w, data, meta *output.Meta)
so list commands surface meta.count / has_more in the wire envelope.
TTY indent decision plumbed via FormatOptions.TTY (set by
ResolveDefault). --format and --jq promoted to persistent root flags
so unknown-subcommand paths still reach the typed-envelope guard
(per-command registration would have rejected --format on unknown
commands as cobra-prose exit 2). WEKNORA_FORMAT env-var fallback
honored before TTY-resolved default. AddFormatFlag retained for the
per-command --jq field-hint Long-text addendum.
~55 production Emit call sites swept across cli/cmd/**: list paths
populate meta.count; mutation paths pass nil meta; envelope.profile
threaded via globalProfile. Existing JSON-shape tests migrated to
decode the envelope wrapper.
Multi-target batch operations get a unified shape via new helpers:
- output.BatchItem + output.WriteBatchEnvelope (§4.5 per-item ok
pattern; data:[{id, ok, result?|error?}], meta:{count, successes*,
failures*}; Successes/Failures *int so explicit zero survives
omitempty in all-fail case).
- cmdutil.RunBatch + cmdutil.EmitBatch + cmdutil.DeletedAtNow +
cmdutil.ClassifyContextErr collapse the three previously-duplicated
multi-delete pipelines (doc / chunk / session) into one call site
pattern. doc upload --recursive uses the same helpers with a per-
file resultFn. Summary error sets Silent:true so the stderr
envelope path doesn't duplicate the stdout batch detail (exit 1
preserved via Code → ExitCode).
ConfirmDestructive / ConfirmDestructiveBatch extended with action +
retryCmd parameters. Every destructive command (kb delete, kb edit,
doc delete, doc delete --all, agent delete, agent edit, session
delete, chunk delete, auth logout, api -X DELETE) now attaches
error.risk.{level:"destructive", action:"<noun.verb>"} +
error.retry_command on the exit-10 envelope. kb edit / agent edit
also gain the destructive guard wiring (CHANGELOG listed them as
gated but they were silently executing without -y).
MCP tool handlers' 31 error paths return CallToolResult with
IsError + Content text fallback + StructuredContent (envelope.error
shape via cmdutil.ErrorToDetail). Handler Out type changed from
typed *sdk.X to any so the go-sdk auto-marshal doesn't overwrite
StructuredContent with a zero-struct on error returns. Success path
manually populates CallToolResult.StructuredContent via successResult
helper.
weknora api cleanup:
- -d/--data flag removed; body via --input <file> or --input -
(stdin) only. Aligns with gh / curl convention.
- HTTP method whitelist removed; any non-empty method accepted.
- HTTP Retry-After header → cmdutil.Error.RetryAfterSeconds →
envelope.error.retry_after_seconds.
- runAPIPaginated raw-passthrough fallback now wraps response in
envelope so --paginate never emits bare JSON to stdout.
Test sweep: ~60 cmd/** tests migrated to decode envelope shape.
9 wire-contract goldens updated under cli/acceptance/testdata/wire/.
Spec: docs/superpowers/specs/2026-05-20-weknora-cli-v0.7-design.md §4 / §5
2026-05-21 10:41:56 +00:00
meta := & output . Meta { Count : len ( items ) , HasMore : truncated }
return fopts . Emit ( iostreams . IO . Out , items , meta )
2026-05-15 17:22:14 +00:00
}
if len ( items ) == 0 {
fmt . Fprintln ( iostreams . IO . Out , "(no chunks)" )
return nil
}
tw := tabwriter . NewWriter ( iostreams . IO . Out , 0 , 0 , 2 , ' ' , 0 )
fmt . Fprintln ( tw , "CHUNK_ID\tINDEX\tTYPE\tENABLED\tPREVIEW\tUPDATED" )
now := time . Now ( )
for _ , c := range items {
enabled := "-"
if c . IsEnabled {
enabled = "yes"
}
2026-05-15 18:42:18 +00:00
preview := text . OneLine ( previewWidth , c . Content )
2026-05-15 17:22:14 +00:00
if preview == "" {
preview = "-"
}
typ := c . ChunkType
if typ == "" {
typ = "-"
}
fmt . Fprintf ( tw , "%s\t%d\t%s\t%s\t%s\t%s\n" ,
c . ID , c . ChunkIndex , typ , enabled , preview , text . FuzzyAgoStr ( now , c . UpdatedAt ) )
}
return tw . Flush ( )
}