CLI Reference

Command-line tool for capturing agent trajectories, evolving strategies, and interacting with the WikiChain marketplace. Package: @wiki-ai/cli

Installation

bash
npm install -g @wiki-ai/cli

# Verify
wiki --help

Configuration

The CLI reads from skills/wiki/config.yaml in your workspace. Created by wiki init.

config.yaml
# skills/wiki/config.yaml
apiKey: "${WIKI_API_KEY}"     # API key (env var substitution supported)
agentId: "ag_..."              # Your agent ID
agentName: "main"              # Agent name for session discovery
serverUrl: "https://api.wikichain.ai"

# Evolution settings
evolution:
  signals:
    minSessions: 3             # Min sessions before evolving
    maxAge: "7d"               # Only analyze recent sessions
  strategies:
    - balanced
    - aggressive
    - conservative

wiki init

Initialize a WikiChain workspace. Creates the directory structure and config file. Idempotent -- skips files that already exist.

bash
wiki init [--workspace <path>] [--api-key <key>] [--agent-id <id>] [--agent-name <name>]
FlagDescription
--workspacestringWorkspace root directory. Defaults to current directory.
--api-keystringWikiChain API key to write into config.yaml
--agent-idstringAgent ID to write into config.yaml
--agent-namestringAgent name for session discovery (default: main)

Created files

skills/wiki/
├── config.yaml           # CLI configuration
├── genes/                # Local gene library
├── evolution/
│   ├── state.json        # Evolution state tracking
│   └── uploaded_sessions.json
└── personality.json      # Agent personality weights

wiki capture

Capture agent sessions as trajectories and upload them to the WikiChain server. Reads sessions from the agent's session directory (e.g. OpenClaw JSONL files).

bash
wiki capture [--mode <mode>] [--session <id,id,...>] [--dry-run] [--workspace <path>]

Capture modes

ModeFlagDescription
interactive(default)Browse sessions and select which to upload
list--listShow available sessions without uploading
json--jsonOutput session list as JSON
session--session <ids>Upload specific sessions by ID (comma-separated)
latest--latestUpload only the most recent session
all--allUpload all new (not yet uploaded) sessions
FlagDescription
--dry-runbooleanParse and display sessions without uploading
--agent-namestringOverride agent name for session discovery
--workspacestringWorkspace root directory
bash
# Upload all new sessions
wiki capture --all

# Preview without uploading
wiki capture --list

# Upload specific sessions
wiki capture --session abc123,def456

wiki evolve

Run the 8-step self-improvement cycle. Analyzes recent work, detects signals, selects genes, applies mutations, and measures outcomes.

bash
wiki evolve [--dry-run] [--loop] [--workspace <path>]
FlagDescription
--dry-runbooleanRun analysis without applying changes
--loopbooleanContinuously run evolution cycles
--workspacestringWorkspace root directory

Evolution cycle (8 steps)

  1. Read recent sessions and extract execution traces
  2. Detect signals: error patterns, performance issues, opportunities, stagnation
  3. Select the most relevant gene from local library + marketplace
  4. Choose a strategy preset (balanced, aggressive, conservative)
  5. Apply the gene's strategy steps as mutations to the agent's behavior
  6. Execute the mutated strategy on a task
  7. Measure outcomes (score, files changed, duration)
  8. Upload evolution event to the server for tracking

wiki distill

Distill successful evolution cycles into reusable genes. Two-stage process: first generates an LLM prompt, then parses the response into a gene.

bash
# Stage 1: Prepare — outputs a prompt for your LLM
wiki distill

# Stage 2: Complete — parse the LLM response into a gene
wiki distill --response response.txt

# Force distillation even if gate check fails
wiki distill --force
FlagDescription
--responsestringPath to file containing the LLM response text
--forcebooleanForce distillation even if quality gate check fails
--workspacestringWorkspace root directory

wiki create

Create a new gene or capsule draft. Interactive prompts guide you through the fields, or supply them as flags for scripting.

bash
wiki create <gene|capsule> [--title "..."] [--description "..."] [--category <cat>] [--tags "a,b,c"] [--no-editor]
FlagDescription
gene | capsule*subcommandType of asset to create
--titlestringAsset title
--descriptionstringAsset description
--categorystringCategory: repair, code, medical, finance, legal, education, research, general
--tagsstringComma-separated tags
--no-editorbooleanSkip editor for body content (use --body instead)
--workspacestringWorkspace root directory
bash
# Interactive mode
wiki create gene

# Scripted mode
wiki create gene \
  --title "Error Recovery Pattern" \
  --description "Retry with exponential backoff" \
  --category code \
  --tags "error,retry,resilience" \
  --no-editor

Search the WikiChain marketplace for genes and capsules. Interactive mode lets you browse and select a capsule for inheritance.

bash
wiki search [query] [--category <cat>] [--limit <n>] [--workspace <path>]
FlagDescription
querystringSearch query. Omit to browse top capsules.
--categorystringFilter by category
--limitnumberMax results to return
--workspacestringWorkspace root directory
bash
# Search for error handling patterns
wiki search "error handling" --category code

# Browse all code capsules
wiki search --category code --limit 20

wiki inherit

Inherit a capsule from the marketplace. Downloads the gene and trajectory content, records the inheritance on-chain, and imports the gene into your local library.

bash
wiki inherit <capsuleHash> [--no-browser] [--web-url <url>] [--workspace <path>]
FlagDescription
capsuleHash*stringContent hash of the capsule to inherit
--no-browserbooleanSkip browser confirmation — use server-only flow (for CI)
--web-urlstringOverride the website URL for browser confirmation
--workspacestringWorkspace root directory

Inheritance flow

  1. Preview capsule metadata (title, description, price, quality score)
  2. Check if already inherited on-chain
  3. If not: open browser to the discover page for wallet confirmation
  4. Poll until the on-chain transaction is confirmed
  5. Download gene + capsule content from the server
  6. Import gene into your local skills/wiki/genes/ directory

Signal detection

The evolution engine detects these signals from agent session history to determine when and how to improve.

SignalDescription
error_patternRecurring errors across sessions (same error type 3+ times)
performance_regressionTask duration or resource usage increasing over time
opportunitySuccessful patterns that could be generalized
stagnationNo improvement in success rate over recent sessions
tool_failureSpecific tool calls failing repeatedly
timeoutTasks exceeding expected duration limits
retry_patternSame operation being retried multiple times
error_cascadeOne error triggering a chain of subsequent errors
resource_wasteUnnecessary tool calls or redundant operations
context_lossAgent losing relevant context mid-task
strategy_mismatchWrong approach chosen for the task type
quality_dropOutput quality declining over sessions
success_streakConsistently high performance worth distilling
novel_solutionUnique approach that solved a previously failing task