搜索

PythonReactSEOPDF
OpenClaw

cross-session-memory

Cross-session memory continuity system. Automatically loads 24h rolling memory and daily memory files for context awareness.

24267580930 来源安装数☆ 0 仓库 Stars

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

SkillHub CLI

skillhub install 2426758093/cross-session-memory

打开来源仓库,查看说明和兼容环境后,按来源提供的命令或步骤安装。

将来源链接提供给你的 Agent,让它先读取说明、核对依赖,并向你说明将执行的安装步骤。

查看来源 ↗使用指南

技能说明

跨会话记忆连续性

功能

  • 24 小时滚动记忆:自动加载最近 24 小时的记忆文件
  • 每日记忆加载:自动读取昨天和今天的 memory 文件
  • 上下文恢复:会话开始时自动恢复之前的对话上下文
  • 长期记忆整合:可选加载 MEMORY.md 长期记忆

使用场景

  • 跨天对话连续性
  • 多会话协作
  • 长期项目跟踪
  • 上下文不丢失

实现逻辑

# 伪代码
function Load-CrossSessionMemory {
    param(
        [int]$RollingHours = 24,
        [bool]$LoadLongTerm = $true
    )
    
    $now = Get-Date
    $memoryDir = "$workspace\memory"
    $context = @()
    
    # 1. 加载长期记忆(仅主会话)
    if ($LoadLongTerm -and $IsMainSession) {
        $longTerm = Get-Content "$workspace\MEMORY.md" -Raw
        $context += "## 长期记忆`n$longTerm"
    }
    
    # 2. 计算时间范围
    $startTime = $now.AddHours(-$RollingHours)
    
    # 3. 加载范围内的每日记忆文件
    $date = $startTime.Date
    while ($date -le $now.Date) {
        $file = "$memoryDir\$($date.ToString('yyyy-MM-dd')).md"
        if (Test-Path $file) {
            $content = Get-Content $file -Raw
            $context += "## 记忆:$($date.ToString('yyyy-MM-dd'))`n$content"
        }
        $date = $date.AddDays(1)
    }
    
    # 4. 返回整合的上下文
    return $context -join "`n`n"
}

文件结构

workspace/
├── MEMORY.md              # 长期记忆( curated )
└── memory/
    ├── 2026-03-02.md      # 每日记忆(raw logs)
    ├── 2026-03-03.md
    └── ...

使用示例

会话开始时自动加载

在 AGENTS.md 中已经定义:

## Every Session

Before doing anything else:

1. Read `SOUL.md` — this is who you are
2. Read `USER.md` — this is who you're helping
3. Read `memory/YYYY-MM-DD.md` (today + yesterday) for recent context
4. **If in MAIN SESSION**: Also read `MEMORY.md`
手动加载
# 加载最近 24 小时记忆
$context = Load-CrossSessionMemory -RollingHours 24

# 加载最近 7 天记忆(长期项目)
$context = Load-CrossSessionMemory -RollingHours 168 -LoadLongTerm $false

记忆文件内...

来源信息

Source
github
Repository
openclaw/skills
Path
skills/2426758093/cross-session-memory
Version
—
Commit
81af75eff191010bbdf94ae120fab409f574b53e
分类来源
rules
状态
active
可见性
public

这些信息来自收录时的来源分析,可能滞后;使用前请核对最新来源文件。

来源内容

SKILL.md
# 跨会话记忆连续性

## 功能

- **24 小时滚动记忆**:自动加载最近 24 小时的记忆文件
- **每日记忆加载**:自动读取昨天和今天的 memory 文件
- **上下文恢复**:会话开始时自动恢复之前的对话上下文
- **长期记忆整合**:可选加载 MEMORY.md 长期记忆

## 使用场景

- 跨天对话连续性
- 多会话协作
- 长期项目跟踪
- 上下文不丢失

## 实现逻辑

```powershell
# 伪代码
function Load-CrossSessionMemory {
    param(
        [int]$RollingHours = 24,
        [bool]$LoadLongTerm = $true
    )
    
    $now = Get-Date
    $memoryDir = "$workspace\memory"
    $context = @()
    
    # 1. 加载长期记忆(仅主会话)
    if ($LoadLongTerm -and $IsMainSession) {
        $longTerm = Get-Content "$workspace\MEMORY.md" -Raw
        $context += "## 长期记忆`n$longTerm"
    }
    
    # 2. 计算时间范围
    $startTime = $now.AddHours(-$RollingHours)
    
    # 3. 加载范围内的每日记忆文件
    $date = $startTime.Date
    while ($date -le $now.Date) {
        $file = "$memoryDir\$($date.ToString('yyyy-MM-dd')).md"
        if (Test-Path $file) {
            $content = Get-Content $file -Raw
            $context += "## 记忆:$($date.ToString('yyyy-MM-dd'))`n$content"
        }
        $date = $date.AddDays(1)
    }
    
    # 4. 返回整合的上下文
    return $context -join "`n`n"
}
```

## 文件结构

```
workspace/
├── MEMORY.md              # 长期记忆( curated )
└── memory/
    ├── 2026-03-02.md      # 每日记忆(raw logs)
    ├── 2026-03-03.md
    └── ...
```

## 使用示例

### 会话开始时自动加载

在 AGENTS.md 中已经定义:

```markdown
## Every Session

Before doing anything else:

1. Read `SOUL.md` — this is who you are
2. Read `USER.md` — this is who you're helping
3. Read `memory/YYYY-MM-DD.md` (today + yesterday) for recent context
4. **If in MAIN SESSION**: Also read `MEMORY.md`
```

### 手动加载

```powershell
# 加载最近 24 小时记忆
$context = Load-CrossSessionMemory -RollingHours 24

# 加载最近 7 天记忆(长期项目)
$context = Load-CrossSessionMemory -RollingHours 168 -LoadLongTerm $false
```

## 记忆文件内...

相关技能

OpenClaw

1password

daggerkun007

Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.