shuiyuan1223

memory-system

0
0
# Install this skill:
npx skills add shuiyuan1223/skillfix_xuetang --skill "memory-system"

Install specific skill from multi-skill repository

# Description

Use when working on the memory/profile system - user profiles, memory search, daily logs, info collection.

# SKILL.md


name: memory-system
description: Use when working on the memory/profile system - user profiles, memory search, daily logs, info collection.


PHA Memory System

Architecture

MemoryManager (singleton)
β”œβ”€β”€ UserStore (SQLite)         β€” user records
β”œβ”€β”€ Profile (file-based)       β€” .pha/users/{uuid}/PROFILE.md
β”œβ”€β”€ Memory (file + FTS)        β€” .pha/users/{uuid}/MEMORY.md + chunks table
β”œβ”€β”€ Daily Logs                 β€” .pha/users/{uuid}/memory/{date}.md
β”œβ”€β”€ VectorStore (Vectra)       β€” optional vector search
β”œβ”€β”€ InfoCollector              β€” profile extraction from messages
└── Soul                       β€” .pha/SOUL.md agent persona

Key Files

File Purpose
src/memory/memory-manager.ts Main orchestrator, singleton via getMemoryManager()
src/memory/profile.ts File I/O for PROFILE.md, MEMORY.md, daily logs
src/memory/types.ts UserProfile, MemoryChunk, MemorySearchResult
src/memory/info-collector.ts Extract profile fields from user messages
src/memory/soul.ts SOUL.md agent persona, DEFAULT_SOUL constant
src/memory/schema.ts SQLite schema (chunks, chunks_fts)
src/memory/vector-store.ts Vectra vector search
src/memory/hybrid.ts Hybrid search (vector + keyword merge)
src/memory/user-store.ts SQLite user CRUD

Common Operations

import { getMemoryManager } from "../memory/index.js";
import { getUserUuid } from "../utils/config.js";

const mm = getMemoryManager();
const uuid = getUserUuid();

// Profile
mm.getProfile(uuid);                          // β†’ UserProfile
mm.updateProfile(uuid, { height: 175 });
mm.getProfileCompleteness(uuid);              // β†’ number (0-100)
mm.getAllMissingFields(uuid);                  // β†’ RequiredField[]
mm.extractAndUpdateProfile(uuid, message);    // β†’ Partial<UserProfile>

// Memory
mm.appendMemory(uuid, content);               // β†’ writes MEMORY.md + indexes
mm.appendDailyLog(uuid, content);             // β†’ writes daily log + indexes
await mm.searchAsync(uuid, query, opts);      // β†’ MemorySearchResult[]
mm.getMemoryStats(uuid);                      // β†’ { totalChunks, lastUpdated }

// System prompt
mm.buildSystemPrompt(uuid);                   // β†’ full prompt with soul + profile + memory

UserProfile Interface

interface UserProfile {
  nickname?: string;
  gender?: "male" | "female";
  birthYear?: number;
  height?: number;        // cm
  weight?: number;        // kg
  conditions?: string[];  // chronic conditions
  allergies?: string[];
  medications?: string[];
  goals?: { primary?: string; dailySteps?: number; sleepHours?: number; exercisePerWeek?: number };
  lifestyle?: { sleepSchedule?: string; exercisePreference?: string; dietPreference?: string };
  dataSources?: { huawei?: { connected: boolean; connectedAt?: number } };
}

File Storage Layout

.pha/
β”œβ”€β”€ SOUL.md                          # Agent persona
β”œβ”€β”€ memory.db                        # SQLite (chunks, FTS)
└── users/
    └── {uuid}/
        β”œβ”€β”€ PROFILE.md               # User health profile
        β”œβ”€β”€ MEMORY.md                # Long-term memory
        └── memory/
            β”œβ”€β”€ 2025-01-01.md        # Daily logs
            └── 2025-01-02.md

Adding New Profile Fields

  1. src/memory/types.ts β€” Add to UserProfile interface
  2. src/memory/info-collector.ts β€” Add to REQUIRED_FIELDS with parse/validate
  3. src/memory/profile.ts β€” Update parseProfileMd() and generateProfileMd()
  4. src/memory/memory-manager.ts β€” Update updateProfile() deep merge if nested

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.