本文へ移動
cccskills
無料GitHub で公開

context-lifecycle

上下文生命周期管理总览:四层记忆架构(L0-L3)、任务阶段感知、 渐进压缩策略、按需召回与四分区预算模型。

インストール方法を見る

含まれるファイル(1)

  • SKILL.md6.8 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Context Lifecycle Skill

管理 Claude Code 长时多轮任务中的上下文生命周期,避免压缩导致关键细节丢失。

架构概览

┌──────────────────────────────────────────────────────┐
│                 上下文窗口 (200K tokens)                │
│                                                        │
│  ┌──────────┐ ┌──────────┐ ┌────────────┐ ┌────────┐ │
│  │  System   │ │  Ledger  │ │  Working   │ │ Buffer │ │
│  │  (10%)    │ │  (10%)   │ │  (65%)     │ │ (15%)  │ │
│  │ protected │ │ protected│ │ 主工作区    │ │ 溢出区  │ │
│  └──────────┘ └──────────┘ └────────────┘ └────────┘ │
└──────────────────────────────────────────────────────┘
         ↕ 渐进压缩                ↕ 按需召回
┌──────────────────────────────────────────────────────┐
│  L1: 摘要 + L2 引用   →   L2: 全文归档 (索引)         │
│  (替换 L0 原文)             (~/.claude/memory/)       │
│                                                        │
│  L3: 项目记忆 (跨会话)  →  docs/memory/ + Phase Ledger │
└──────────────────────────────────────────────────────┘

四层记忆模型

层级名称位置内容生命周期
L0工作记忆上下文窗口当前对话、工具结果、代码当前会话
L1摘要记忆上下文窗口 (替换 L0)压缩摘要 + L2 归档引用当前会话
L2详情归档~/.claude/memory/sessions/{sid}/完整原文、关键词索引本地持久
L3项目记忆docs/memory/Phase Ledger、决策日志、经验跨会话持久

渐进压缩策略

压缩基于 Working Zone 使用率,而非整体上下文使用率:

Working 使用率压缩级别操作
< 60%无保持 L0 原文
60%L0→L1摘要工具结果、旧对话,原文归档到 L2
75%L1→L2摘要 L1 内容,更老的摘要归档到 L2
90%L2→L3紧急压缩,决策提升到项目记忆

阶段感知优先级

压缩时的保留/归档决策受当前任务阶段影响:

阶段优先保留优先归档
Planning需求、边界、约束探索性讨论
Design架构决策、接口契约备选方案分析
Implementation当前文件、测试结果设计讨论
Testing测试结果、缺陷实现细节
Review评审结论、修改建议测试细节

核心组件

库模块 (scripts/lib/)

模块职责
phase_tracker.py任务阶段状态机,多信号检测(命令 / handoff / 工具启发)
phase_ledger.py阶段交接账页,在阶段切换时生成结构化 Markdown
context_budget.py四分区预算模型,Zone-aware 压缩级别判定
context_archiver.pyL2 归档写入、关键词索引、去重、批量归档
context_recall.py按需召回:关键词 / 阶段 / 类型 / 决策多维检索
context_priority.py上下文元素优先级评分(已有)

Hooks (scripts/hooks/)

Hook触发点作用
session_start.py会话开始加载 Phase Timeline、未解决项、决策摘要
pre_compact.py压缩前分类元素为 keep/summarize/archive/discard
suggest_compact.py压缩建议根据 Working Zone 使用率推荐渐进压缩策略

Skills (skills/)

Skill用途
context-recall/recall 命令,按需从 L2 归档和 Phase Ledger 检索
context-lifecycle本文档,整体架构说明
strategic-compact已有的 trigger-based 上下文重组能力

数据流

写入路径

对话/工具结果 (L0)
    ↓ Working Zone > 60%
pre_compact → categorize as "archive"
    ↓
context_archiver.archive_and_index()
    ├── 写入 L2 文件: ~/.claude/memory/sessions/{sid}/archived/{hash}.md
    ├── 更新索引: ~/.claude/memory/sessions/{sid}/index.json
    └── 返回 L1 摘要 (替换上下文中的原文)
    
阶段切换时
    ↓
phase_ledger.generate_ledger() + save_ledger()
    ├── 写入 L3: docs/memory/sessions/{sid}/phase-{N}-{name}.md
    └── 更新索引: /tmp/harness-phase-ledger-{sid}.json

读取路径

会话启动
    ↓
session_start → get_recall_context_for_session_start()
    ├── 读取 Phase Ledger 索引 → phase_timeline
    ├── 统计未解决项 → pending_items
    └── 统计决策数 → recall_hint

用户请求 /recall
    ↓
context_recall → recall_by_keyword/phase/type/decisions()
    ├── 搜索 L2 索引 (index.json)
    ├── 加载 L2 完整内容
    └── 搜索 Phase Ledger

使用指南

自动行为(无需干预)

  1. 会话启动自动加载 Phase Timeline 和未解决项
  2. 压缩时自动按阶段优先级归档而非丢弃
  3. 阶段切换时自动生成 Phase Ledger

手动操作

  1. /recall keyword — 从归档中按关键词搜索
  2. /recall phase:design — 查看 design 阶段的完整交接记录
  3. /recall decisions — 查看所有决策链路
  4. /recall timeline — 查看阶段时间线

与现有能力的协同

  • strategic-compact: 本系统的 L0→L1 压缩替代了 strategic-compact 的全量压缩,两者可共存
  • error-experience-library: 错误经验在 L3 层跨会话持久保存
  • continuous-learning: instinct 产物不受压缩影响,已在 L3 层

配置

可通过环境变量或 hooks.json 参数调整:

参数默认值说明
Zone ratios10/10/65/15System/Ledger/Working/Buffer 分区比例
L0→L1 threshold60%Working Zone 使用率触发 L0→L1
L1→L2 threshold75%Working Zone 使用率触发 L1→L2
L2→L3 threshold90%Working Zone 使用率触发 L2→L3

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Use AtomLane to compile and execute safe atomic parallel plans on macOS and native Windows Preview for worthwhile independent argv tasks, dependency DAGs, supported platform entrypoints, or Apple-silicon operators. Use at task start or an execution boundary when structured local work may contain two or more worthwhile units; skip plain answers, one quick command, and work whose effects cannot be safely bounded.

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

add

無料

Register a deferred decision in the debt registry. Trigger by judgment, not a marker scan, whenever a future reader would ask "why this way?": an unmade decision, stub, loosened type, bypassed check, swallowed error, a default picked "for now", or a TODO/FIXME/HACK/XXX marker. Trigger immediately whenever you defer work, or when the user invokes $add. Over-register freely; the developer drops with "drop A", "drop A,C", or "drop all".

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

ADK 框架适配层。为 LangChain / EINO / AutoGen / AgentScope / CrewAI 提供框架特定的 代码模板、惯用模式、API 映射和项目结构,供 agent-dev-workshop Phase 5 代码生成使用。 每个框架 reference 文件标注 verified_date 用于版本锁定。

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

中文调试修复技能。用于报错、测试失败、页面异常、功能不符合预期、需要定位根因并做最小修复时。触发语包括"进入调试模式""帮我修问题""报错了""测试失败""页面坏了""找根因"。

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

交互式 AI Agent 开发工作坊:通过 6 阶段深度协作对话,引导用户完成 Agent 需求分析、架构设计、 工具定义、Prompt 与编排设计、代码生成、验证迭代,产出可直接运行的 Agent 项目。 框架无关设计优先,支持 LangChain / EINO / AutoGen / AgentScope / CrewAI 等 ADK 框架。

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

中文漂移审计技能。用于项目或学习过程变乱、上下文漂移、任务分叉、多个方案冲突、命名不一致、Codex 可能顺手改多了时。触发语包括"漂移检查""感觉跑偏了""项目变乱了""检查是否失控""分叉太多""上下文漂移"。

日本語の概要は準備中です。原文の説明を表示しています。

hashgraph-online/awesome-codex-plugins1,2752026年10月11日 更新

hashgraph-online のスキルをすべて見る

このスキルの問題を報告する