fleet-memory/hindsight-docs/examples/api/cli-reference.sh
DK09876 8ecb5d3a0c
Add documentation code validation system (#43)
* Add documentation code validation system

- Create runnable example scripts in examples/api/ (19 files)
- Add CodeSnippet component for extracting marked sections
- Add raw-loader dependency for importing source files
- Create sample retain-new.mdx showing new approach
- Add README documenting coverage and gaps

* Fix wheel glob expansion in test-doc-examples CI job

* Fix CI issue

* Fix wheel path - uv build outputs to repo root dist/

* Fix: use explicit shell expansion for wheel install

* Fix: run cd in subshell so install runs from repo root

* Add documentation code validation CI job

- Use uv sync + uv run pattern (matches existing CI)
- Add requests to test dependencies for cleanup scripts

* Fix async API client usage in documents.py example

* Fix main-methods.py: RecallResult and ReflectFact don't have weight attribute

* Fix opinions.py: use actual API attributes instead of non-existent ones

* Fix example scripts: remove non-existent API attributes

- recall.py: remove .weight, fix entities iteration (dict not list)
- retain.mjs: remove result.async check
2025-12-18 10:21:38 +01:00

209 lines
6 KiB
Bash
Executable file

#!/bin/bash
# CLI Reference examples for Hindsight
# Tests all documented CLI commands and flags
# Run: bash examples/api/cli-reference.sh
set -e
HINDSIGHT_URL="${HINDSIGHT_API_URL:-http://localhost:8888}"
BANK_ID="cli-test-bank"
DOC_ID="test-document-001"
# =============================================================================
# Setup
# =============================================================================
hindsight configure --api-url "$HINDSIGHT_URL"
# Create test data with a known document ID
hindsight memory retain "$BANK_ID" "Alice works at Google as a software engineer" --document-id "$DOC_ID"
hindsight memory retain "$BANK_ID" "Bob is a data scientist who collaborates with Alice" --document-id "$DOC_ID"
hindsight memory retain "$BANK_ID" "Alice and Bob work on machine learning projects"
# Wait a moment for processing
sleep 2
# =============================================================================
# Configuration (cli.md - Configuration section)
# =============================================================================
# [docs:cli-configure]
hindsight configure --api-url http://localhost:8888
# [/docs:cli-configure]
# =============================================================================
# Core Memory Commands (cli.md - Core Commands section)
# =============================================================================
# [docs:cli-retain-basic]
hindsight memory retain $BANK_ID "Alice works at Google as a software engineer"
# [/docs:cli-retain-basic]
# [docs:cli-retain-context]
hindsight memory retain $BANK_ID "Bob loves hiking" --context "hobby discussion"
# [/docs:cli-retain-context]
# [docs:cli-retain-async]
hindsight memory retain $BANK_ID "Meeting notes" --async
# [/docs:cli-retain-async]
# [docs:cli-recall-basic]
hindsight memory recall $BANK_ID "What does Alice do?"
# [/docs:cli-recall-basic]
# [docs:cli-recall-options]
hindsight memory recall $BANK_ID "hiking recommendations" \
--budget high \
--max-tokens 8192
# [/docs:cli-recall-options]
# [docs:cli-recall-fact-type]
hindsight memory recall $BANK_ID "query" --fact-type world,opinion
# [/docs:cli-recall-fact-type]
# [docs:cli-recall-trace]
hindsight memory recall $BANK_ID "query" --trace
# [/docs:cli-recall-trace]
# [docs:cli-reflect-basic]
hindsight memory reflect $BANK_ID "What do you know about Alice?"
# [/docs:cli-reflect-basic]
# [docs:cli-reflect-context]
hindsight memory reflect $BANK_ID "Should I learn Python?" --context "career advice"
# [/docs:cli-reflect-context]
# [docs:cli-reflect-budget]
hindsight memory reflect $BANK_ID "Summarize my week" --budget high
# [/docs:cli-reflect-budget]
# =============================================================================
# Bank Management (cli.md - Bank Management section)
# =============================================================================
# [docs:cli-bank-list]
hindsight bank list
# [/docs:cli-bank-list]
# [docs:cli-bank-profile]
hindsight bank profile $BANK_ID
# [/docs:cli-bank-profile]
# [docs:cli-bank-stats]
hindsight bank stats $BANK_ID
# [/docs:cli-bank-stats]
# [docs:cli-bank-name]
hindsight bank name $BANK_ID "My Assistant"
# [/docs:cli-bank-name]
# [docs:cli-bank-background]
hindsight bank background $BANK_ID "I am a helpful AI assistant interested in technology"
# [/docs:cli-bank-background]
# [docs:cli-bank-background-no-disposition]
hindsight bank background $BANK_ID "Background text" --no-update-disposition
# [/docs:cli-bank-background-no-disposition]
# =============================================================================
# Document Management (cli.md - Document Management section)
# =============================================================================
# [docs:cli-document-list]
hindsight document list $BANK_ID
# [/docs:cli-document-list]
# [docs:cli-document-get]
hindsight document get $BANK_ID $DOC_ID
# [/docs:cli-document-get]
# [docs:cli-document-delete]
# Create a temp document to delete
hindsight memory retain $BANK_ID "Temporary content" --document-id "temp-doc-to-delete"
sleep 1
hindsight document delete $BANK_ID temp-doc-to-delete
# [/docs:cli-document-delete]
# =============================================================================
# Entity Management (cli.md - Entity Management section)
# =============================================================================
# [docs:cli-entity-list]
hindsight entity list $BANK_ID
# [/docs:cli-entity-list]
# Get an entity ID from the list output and use it
ENTITY_ID=$(hindsight entity list $BANK_ID -o json 2>/dev/null | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4 || echo "")
if [ -n "$ENTITY_ID" ]; then
# [docs:cli-entity-get]
hindsight entity get $BANK_ID $ENTITY_ID
# [/docs:cli-entity-get]
# [docs:cli-entity-regenerate]
hindsight entity regenerate $BANK_ID $ENTITY_ID
# [/docs:cli-entity-regenerate]
else
echo "No entities found yet, skipping entity get/regenerate"
fi
# =============================================================================
# Output Formats (cli.md - Output Formats section)
# =============================================================================
# [docs:cli-output-json]
hindsight memory recall $BANK_ID "query" -o json
# [/docs:cli-output-json]
# [docs:cli-output-yaml]
hindsight memory recall $BANK_ID "query" -o yaml
# [/docs:cli-output-yaml]
# =============================================================================
# Global Options (cli.md - Global Options section)
# =============================================================================
# [docs:cli-verbose]
hindsight memory recall $BANK_ID "Alice" -v
# [/docs:cli-verbose]
# [docs:cli-help]
hindsight --help
# [/docs:cli-help]
# [docs:cli-version]
hindsight --version
# [/docs:cli-version]
# =============================================================================
# Cleanup
# =============================================================================
curl -s -X DELETE "${HINDSIGHT_URL}/v1/default/banks/${BANK_ID}" > /dev/null
echo "cli-reference.sh: All examples passed"