AgentSkillsCN

memory-summary-retrieve

可根据 ID、项目名称,或记忆的最新时间,检索记忆摘要。返回结构化 JSON,并附带压缩指标。可用于为 LLM 提示词获取压缩后的历史上下文。

SKILL.md
--- frontmatter
name: memory-summary-retrieve
description: Retrieve memory summaries by ID, project, or recency. Returns structured JSON with compression metrics. Use to access compressed historical context for LLM prompts.
license: Apache-2.0
compatibility: Requires BrAIny API at localhost:3000, Bun runtime
metadata:
  author: brainy
  version: "1.1"
  category: memory-management
  subagent: summarizer
allowed-tools: Bash(bun:*)

Memory Summary Retrieval

Retrieves existing memory summaries from BrAIny storage.

Execution Path

code
┌─────────────────────────────────────────────────────────┐
│                   EXECUTION DECISION                    │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  ┌──────────┐     ┌───────────────────┐                │
│  │  START   │────▶│ SUBAGENT AVAILABLE?│                │
│  └──────────┘     └─────────┬─────────┘                │
│                             │                           │
│              ┌──────────────┴──────────────┐           │
│              ▼                             ▼           │
│       ┌────────────┐                ┌────────────┐     │
│       │    YES     │                │     NO     │     │
│       └─────┬──────┘                └─────┬──────┘     │
│             │                             │            │
│             ▼                             ▼            │
│  ┌─────────────────────┐      ┌─────────────────────┐  │
│  │ Task(summarizer,    │      │ Bash(bun scripts/   │  │
│  │   prompt: "...")    │      │   list-summaries.ts)│  │
│  └─────────────────────┘      └─────────────────────┘  │
│                                                         │
└─────────────────────────────────────────────────────────┘

Path A: Subagent Available (Preferred)

Use the summarizer subagent for lower token cost:

code
Task(
  subagent_type: "summarizer",
  description: "Retrieve summaries",
  prompt: "List summaries for project 3afb861a-b783-45a6-bba2-4b6d96468aeb limit 5"
)

Path B: Script Fallback

If subagent unavailable, execute scripts directly:

bash
bun .opencode/skills/memory-summary-retrieve/scripts/list-summaries.ts PROJECT_ID [LIMIT]
bun .opencode/skills/memory-summary-retrieve/scripts/get-summary-by-id.ts SUMMARY_ID
bun .opencode/skills/memory-summary-retrieve/scripts/format-summary-context.ts SUMMARY_ID

State Machine

code
┌─────────────────────────────────────────────────────────────┐
│                  RETRIEVAL WORKFLOW                         │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌──────────┐     ┌─────────────────┐                      │
│  │  START   │────▶│ DETERMINE_MODE  │                      │
│  └──────────┘     └────────┬────────┘                      │
│                            │                                │
│         ┌──────────────────┼──────────────────┐            │
│         ▼                  ▼                  ▼            │
│  ┌────────────┐    ┌────────────┐     ┌────────────┐       │
│  │ BY_ID      │    │ BY_PROJECT │     │ FORMAT     │       │
│  │            │    │            │     │            │       │
│  └─────┬──────┘    └─────┬──────┘     └─────┬──────┘       │
│        │                 │                  │              │
│        ▼                 ▼                  ▼              │
│  ┌────────────┐    ┌────────────┐     ┌────────────┐       │
│  │ FETCH_ONE  │    │ FETCH_LIST │     │ FETCH_ONE  │       │
│  └─────┬──────┘    └─────┬──────┘     └─────┬──────┘       │
│        │                 │                  │              │
│        ▼                 ▼                  ▼              │
│  ┌────────────┐    ┌────────────┐     ┌────────────┐       │
│  │ OUTPUT_JSON│    │OUTPUT_LIST │     │OUTPUT_MD   │       │
│  └─────┬──────┘    └─────┬──────┘     └─────┬──────┘       │
│        │                 │                  │              │
│        └─────────────────┼──────────────────┘              │
│                          ▼                                 │
│                   ┌────────────┐                           │
│                   │    END     │                           │
│                   └────────────┘                           │
│                                                             │
└─────────────────────────────────────────────────────────────┘

States

StateEntry ConditionActionExit Condition
DETERMINE_MODEStartParse argumentsMode selected
BY_IDSUMMARY_ID providedFetch single summaryData retrieved
BY_PROJECTPROJECT_ID providedFetch summary listList retrieved
FORMAT--format flag setFetch and formatContent formatted
OUTPUT_JSONJSON modePrint JSONEnd
OUTPUT_LISTList modePrint tableEnd
OUTPUT_MDFormat modePrint MarkdownEnd

Commands

Get Summary by ID

bash
bun .opencode/skills/memory-summary-retrieve/scripts/get-summary-by-id.ts SUMMARY_ID

Input: SUMMARY_ID (UUID)

Output:

code
ID: abc-123
Type: coding_session
Compression: 6.25x (5000 → 800 tokens)
Memories: 44
Created: 2026-01-07T10:30:00Z

File: /tmp/summary-abc-123.json

List Project Summaries

bash
bun .opencode/skills/memory-summary-retrieve/scripts/list-summaries.ts PROJECT_ID [LIMIT]

Input:

  • PROJECT_ID: UUID (required)
  • LIMIT: integer (default: 50)

Output:

code
Found: 3 summaries

1. abc-123
   Type: coding_session
   Compression: 6.25x
   Memories: 44

2. def-456
   Type: conversation
   Compression: 4.50x
   Memories: 30

Format for LLM Context

bash
bun .opencode/skills/memory-summary-retrieve/scripts/format-summary-context.ts SUMMARY_ID

Input: SUMMARY_ID (UUID)

Output (Markdown):

markdown
## OBJECTIVE: Implement authentication

## PROGRESS:
- Created AuthService → JWT generation working
- Added middleware → Routes protected

## FILES TOUCHED:
| Path | Operation | Changes |
|------|-----------|---------|
| src/auth/service.ts | created | JWT logic |

## CURRENT STATE: Tests passing

## CRITICAL DETAILS:
- JWT_SECRET required in production
- Token expiry: 24h

Summary Structure

typescript
interface Summary {
  id: string;                    // UUID
  summaryType: string;           // coding_session | conversation | custom
  sections: object;              // Type-specific structured data
  content: string | null;        // Formatted text for LLM
  originalMemoryIds: string[];   // Source memory UUIDs
  originalTokenCount: number;    // Pre-compression tokens
  compressedTokenCount: number;  // Post-compression tokens
  compressionRatio: number;      // original / compressed
  model: string;                 // AI model used
  createdAt: string;             // ISO timestamp
}

Section Schemas

coding_session

typescript
{
  objective: string;
  progress: string[];
  filesTouched: { path: string; operation: string; changes: string }[];
  currentState: string;
  criticalDetails: string[];
}

conversation

typescript
{
  topics: string[];
  decisions: string[];
  actionItems: string[];
  context: string[];
  openQuestions: string[];
}

custom

typescript
{
  prompt: string;
  content: string;
  keyPoints: string[];
}

Configuration

VariableDefaultDescription
BRAINY_API_URLhttp://localhost:3000API endpoint
SUMMARY_OUTPUT_FORMATjsonOutput format (json | markdown)

Error Codes

ErrorCauseResolution
"Summary not found"Invalid SUMMARY_IDVerify UUID
"Project not found"Invalid PROJECT_IDVerify UUID
Empty listNo summaries existRun memory-summarize first

Decision Tree

code
What do you need?
├── Single summary by ID → get-summary-by-id.ts
├── List of project summaries → list-summaries.ts
└── Formatted text for LLM → format-summary-context.ts

Exit Codes

CodeMeaning
0Success
1Error (invalid input, API failure)
2Not found
3No content