helpers

package
v1.0.34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package helpers — readable-output enrichment for `report inbox list` and `report outbox list`.

What this file adds:

  • EnrichReportListContent: pure function that walks an MCP `content` response, finds the report items list, and overlays five extra fields the agent layer relies on: success count agentDisplayContentIncluded (bool — inbox false, outbox true) agentDisplayColumns ([]string — wukong-aligned column set) agentDisplayMarkdown (string — markdown table) The function never mutates the input map in-place; it returns a fresh map so callers (including tests) can compare before/after safely.

  • AttachReportListReadableEnrichment: post-merge hook that finds the dynamic-built `report inbox list` / `report outbox list` leaves in the merged command tree and wraps their RunE to apply EnrichReportListContent to the JSON payload before it is written to stdout. Behaviour for other formats (--format raw / table / csv etc.) is preserved verbatim — enrichment only fires when the output is JSON.

Why a post-merge hook (mirroring AttachReportLegacyInboxAlias):

the envelope already publishes `report inbox` and `report outbox` as
groups with a `list` leaf each; the open-source CLI cannot add a same-
named helper leaf (MergeHardcodedLeaves would reject it as a shape
mismatch with the envelope). Wrapping the existing leaf's RunE keeps the
envelope as the single source of truth for flags/schema while letting us
layer wukong-equivalent enrichment on top.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWrite

func AtomicWrite(path string, data []byte, perm os.FileMode) error

AtomicWrite writes data to path atomically by creating a temp file in the same directory, writing and fsyncing the data, then renaming over the target. It replaces os.WriteFile for all config and download file writes.

os.WriteFile truncates the target before writing, so a process kill (CI timeout, OOM, Ctrl+C) between truncate and completion leaves the file empty or partial. AtomicWrite avoids this: on any failure the temp file is cleaned up and the original file remains untouched.

func AtomicWriteFromReader

func AtomicWriteFromReader(path string, reader io.Reader, perm os.FileMode) (int64, error)

AtomicWriteFromReader atomically copies reader contents into path.

func AtomicWriteJSON

func AtomicWriteJSON(path string, data []byte) error

AtomicWriteJSON is a convenience wrapper for writing JSON data atomically. It uses 0600 permissions by default for sensitive data.

func AttachReportLegacyInboxAlias added in v1.0.33

func AttachReportLegacyInboxAlias(commands []*cobra.Command, runner executor.Runner)

AttachReportLegacyInboxAlias finds the dynamic-built `report inbox` group in the merged command tree and turns it into a dual-role command: when invoked with flags (and no subcommand), it executes the canonical inbox list handler with a deprecation notice on stderr. Sub-command invocation (e.g. `report inbox list ...`) keeps working unchanged.

Why a post-merge hook: the envelope publishes `inbox` as a group whose only child is `list`. Hardcoded helpers cannot graft a same-named leaf in (MergeHardcodedLeaves rejects helper-leaf vs envelope-group as a shape mismatch), so we instead enrich the existing group's flags and RunE in place. The `runner` is the same executor that the helper leaves use, keeping behaviour identical to `report list` / `report inbox list`.

func AttachReportListReadableEnrichment added in v1.0.33

func AttachReportListReadableEnrichment(commands []*cobra.Command, runner executor.Runner)

AttachReportListReadableEnrichment wires EnrichReportListContent into the envelope-built `report inbox list` and `report outbox list` leaves.

Mechanism (decorator over the leaf's existing RunE):

  1. Replace leaf.RunE with a closure that delegates to the original RunE.
  2. Before delegating, redirect cmd.SetOut() to an in-memory buffer when the resolved output format is JSON (the only format the agent display schema cares about).
  3. After the original RunE returns, unmarshal the captured bytes, locate the MCP `content` payload, call EnrichReportListContent, and write the enriched JSON to the leaf's original stdout.
  4. For non-JSON formats (raw / table / csv / ...) we never replace stdout, so behaviour stays byte-for-byte identical to the unwrapped envelope.

`runner` is accepted for API symmetry with AttachReportLegacyInboxAlias — the wrapper itself does not invoke runner; the wrapped RunE already does. Keeping the parameter avoids a churn on app/legacy.go if we ever need to dispatch a sibling tool from inside the wrapper.

func EnrichReportListContent added in v1.0.33

func EnrichReportListContent(content map[string]any, includeContent bool) map[string]any

EnrichReportListContent overlays wukong-style agent-display fields on the MCP `content` map of a report list response. It is a pure function:

  • input map is never mutated;
  • on any structural mismatch (nil, no list, etc.) it returns the input untouched so the caller's behaviour is byte-stable.

includeContent controls whether the "日志内容" column appears in agentDisplayColumns / agentDisplayMarkdown and whether each result row retains the 日志内容 key. Pass true for outbox (sender == self, content safe to echo), false for inbox.

func NewPublicCommands

func NewPublicCommands(runner executor.Runner) []*cobra.Command

func NormalizeSkillName

func NormalizeSkillName(input string) string

NormalizeSkillName converts free-form skill names to a stable dash-case key.

func RegisterPublic

func RegisterPublic(factory Factory)

func ValidateNaming

func ValidateNaming(vendor, name string) error

Types

type Factory

type Factory func() Handler

type Handler

type Handler interface {
	Name() string
	Command(runner executor.Runner) *cobra.Command
}

type Manifest

type Manifest struct {
	Vendor      string
	Name        string
	Description string
}

func (Manifest) FullName

func (m Manifest) FullName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL