compact-lifecycle-reuse — for Claude Code compact-lifecycle-reuse, cc_source, community, for Claude Code, ide skills, ## Reuse First, loadPreCompactSnapshot(sessionId), deletePreCompactSnapshot(sessionId), hasPreCompactSnapshot(sessionId), Singleton

v1.0.0

关于此技能

适用场景: Ideal for AI agents that need compact lifecycle reuse. 本地化技能摘要: Compact Architecture Reuse First src/services/compact/compact.ts — compactConversation() (line 388) Main full compact entry. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

功能特性

Compact Lifecycle Reuse
Compact Architecture
query.ts budget prefetch ← contextBudget.ts + orchestrator signals
autoCompactIfNeeded() ← autoCompact.ts, heavy-path threshold check
CompactOrchestrator.decide(input) ← orchestrator/index.ts:47, pure function → CompactPlan

# 核心主题

liuyu520 liuyu520
[0]
[0]
更新于: 4/26/2026

Killer-Skills Review

Decision support comes first. Repository text comes second.

Reference-Only Page Review Score: 10/11

This page remains useful for teams, but Killer-Skills treats it as reference material instead of a primary organic landing page.

Original recommendation layer Concrete use-case guidance Explicit limitations and caution Quality floor passed for review
Review Score
10/11
Quality Score
55
Canonical Locale
en
Detected Body Locale
en

适用场景: Ideal for AI agents that need compact lifecycle reuse. 本地化技能摘要: Compact Architecture Reuse First src/services/compact/compact.ts — compactConversation() (line 388) Main full compact entry. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

核心价值

推荐说明: compact-lifecycle-reuse helps agents compact lifecycle reuse. Compact Architecture Reuse First src/services/compact/compact.ts — compactConversation() (line 388) Main full compact entry. This AI agent skill

适用 Agent 类型

适用场景: Ideal for AI agents that need compact lifecycle reuse.

赋予的主要能力 · compact-lifecycle-reuse

适用任务: Applying Compact Lifecycle Reuse
适用任务: Applying Compact Architecture
适用任务: Applying query.ts budget prefetch ← contextBudget.ts + orchestrator signals

! 使用限制与门槛

  • 限制说明: This is the only place that destroys original messages — micro and session-memory compacts are non-destructive
  • 限制说明: Requires repository-specific context from the skill documentation
  • 限制说明: Works best when the underlying tools and dependencies are already configured

Why this page is reference-only

  • - Current locale does not satisfy the locale-governance contract.

Source Boundary

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

评审后的下一步

先决定动作,再继续看上游仓库材料

Killer-Skills 的主价值不应该停在“帮你打开仓库说明”,而是先帮你判断这项技能是否值得安装、是否应该回到可信集合复核,以及是否已经进入工作流落地阶段。

实验室 Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

常见问题与安装步骤

以下问题与步骤与页面结构化数据保持一致,便于搜索引擎理解页面内容。

? FAQ

compact-lifecycle-reuse 是什么?

适用场景: Ideal for AI agents that need compact lifecycle reuse. 本地化技能摘要: Compact Architecture Reuse First src/services/compact/compact.ts — compactConversation() (line 388) Main full compact entry. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

如何安装 compact-lifecycle-reuse?

运行命令:npx killer-skills add liuyu520/cc_source/compact-lifecycle-reuse。支持 Cursor、Windsurf、VS Code、Claude Code 等 19+ IDE/Agent。

compact-lifecycle-reuse 适用于哪些场景?

典型场景包括:适用任务: Applying Compact Lifecycle Reuse、适用任务: Applying Compact Architecture、适用任务: Applying query.ts budget prefetch ← contextBudget.ts + orchestrator signals。

compact-lifecycle-reuse 支持哪些 IDE 或 Agent?

该技能兼容 Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer。可使用 Killer-Skills CLI 一条命令通用安装。

compact-lifecycle-reuse 有哪些限制?

限制说明: This is the only place that destroys original messages — micro and session-memory compacts are non-destructive;限制说明: Requires repository-specific context from the skill documentation;限制说明: Works best when the underlying tools and dependencies are already configured。

安装步骤

  1. 1. 打开终端

    在你的项目目录中打开终端或命令行。

  2. 2. 执行安装命令

    运行:npx killer-skills add liuyu520/cc_source/compact-lifecycle-reuse。CLI 会自动识别 IDE 或 AI Agent 并完成配置。

  3. 3. 开始使用技能

    compact-lifecycle-reuse 已启用,可立即在当前项目中调用。

! 参考页模式

此页面仍可作为安装与查阅参考,但 Killer-Skills 不再把它视为主要可索引落地页。请优先阅读上方评审结论,再决定是否继续查看上游仓库说明。

Upstream Repository Material

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

Upstream Source

compact-lifecycle-reuse

Compact Architecture Reuse First src/services/compact/compact.ts — compactConversation() (line 388) Main full compact entry. This AI agent skill supports

SKILL.md
Readonly
Upstream Repository Material
The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.
Supporting Evidence

Compact Lifecycle Reuse

Use this skill when hooking into the compact lifecycle (pre/post compact behavior), extending compact strategies, adding new compact side effects, or debugging compact flow.

Compact Architecture

query.ts budget prefetch             ← contextBudget.ts + orchestrator signals
         ↓
autoCompactIfNeeded()                ← autoCompact.ts, heavy-path threshold check
         ↓
CompactOrchestrator.decide(input)    ← orchestrator/index.ts:47, pure function → CompactPlan
         ↓
CompactOrchestrator.execute(plan)    ← orchestrator/index.ts:57, dispatches by strategy
         ↓
┌────────────────────────────────────┐
│ full_compact → compactConversation │ ← compact.ts:388, forked-agent summary
│ micro_compact → microCompact       │ ← microCompact.ts, keep by relevance+recency
│ session_memory → sessionMemory     │ ← sessionMemoryCompact.ts, keep recent msgs
│ noop → skip                        │
└────────────────────────────────────┘

Reuse First

  • src/services/compact/compact.tscompactConversation() (line ~388) Main full compact entry. Takes messages + context, returns CompactionResult. Pre-compact hooks run here. This is the only place that destroys original messages — micro and session-memory compacts are non-destructive.

  • src/services/compact/snapshot.ts — Pre-compact snapshot module savePreCompactSnapshot(sessionId, messages) — serialize full messages before compact loadPreCompactSnapshot(sessionId) — restore messages (returns Message[] | null) deletePreCompactSnapshot(sessionId) — cleanup after rollback hasPreCompactSnapshot(sessionId) — existence check Pattern: best-effort (failure logged, never blocks compact).

  • src/services/compact/orchestrator/index.tsCompactOrchestrator Singleton. decide() is pure (no side effects), returns CompactPlan. execute() dispatches via ExecuteContext closures. Shadow mode (isCompactOrchestratorShadowMode()) skips execution for safe rollout.

  • src/services/compact/orchestrator/planner.tsplan() Decision logic: token stats → strategy selection. Pure function.

  • src/services/compact/orchestrator/types.tsCompactPlan Fields: strategy, reason, estimatedTokensSaved, runSnip, runMicro, preserveAsEpisodic.

  • src/services/compact/contextBudget.ts Shared system / tools / history / output allocator. Reuse this when adding new compact triggers or proactive prefetch logic.

  • src/services/compact/orchestrator/importance.ts Shared relevance scoring. Use this before creating another message-priority heuristic.

  • src/services/compact/autoCompact.tsshouldAutoCompact() (line 160) Heavy-path trigger. Reuse budget allocation and keep the circuit breaker behavior.

  • src/services/compact/microCompact.tsCOMPACTABLE_TOOLS (line 41-50) Time-based smart compact for old tool_result content. Relevance + recency decide what stays; summaries replace cleared content when available.

  • src/services/compact/toolResultSummary.ts Reuse this for ephemeral tool-result summaries. It already handles forked-agent summarization and fallback.

  • src/services/api/promptCacheBreakDetection.ts Reuse section volatility if a new compact decision should react to which prompt segment is changing most often.

  • src/services/compact/sessionMemoryCompact.ts No LLM call. Keeps recent messages (≥10K tokens or 5 messages, cap 40K tokens). Non-destructive.

Common Tasks

Adding pre-compact behavior (like snapshot)

Insert at compactConversation() entry, after the messages.length === 0 check:

typescript
1// compact.ts — compactConversation() entry 2import { myPreCompactHook } from './myHook.js' 3 4// After messages.length check, before preCompactTokenCount: 5const sessionId = getSessionId() 6if (sessionId) { 7 try { 8 await myPreCompactHook(sessionId, messages) 9 } catch (e) { 10 // Best-effort — never block compact 11 logForDebugging(`[MyHook] Failed: ${(e as Error).message}`) 12 } 13}

Rules:

  • Always wrap in try/catch — compact must not fail due to hook errors
  • Only hook into compactConversation() for destructive operations (full compact)
  • micro/session-memory compacts don't need hooks (they're non-destructive)

Adding post-compact cleanup

Use postCompactCleanup.ts pattern or add after buildPostCompactMessages() return in compact.ts.

Extending compact strategies

  1. Add new strategy to CompactStrategy type in orchestrator/types.ts
  2. Add decision logic in orchestrator/planner.ts
  3. Add dispatch case in CompactOrchestrator.execute()
  4. Inject implementation via ExecuteContext closure

Adding or changing compact signals

  1. Start in src/services/compact/contextBudget.ts if the signal depends on system/tools/history/output pressure.
  2. Reuse src/services/api/promptCacheBreakDetection.ts if the signal depends on which prompt section churns most often.
  3. Reuse src/services/compact/orchestrator/importance.ts if the signal depends on message relevance.
  4. Only promote a signal into autoCompact.ts after it is represented in the shared allocator or scorer.

Adding a new command that reads compact state

Follow the /rollback pattern:

typescript
1// Your command 2import { loadPreCompactSnapshot } from '../../services/compact/snapshot.js' 3const snapshot = await loadPreCompactSnapshot(sessionId) 4if (!snapshot) { onDone('No snapshot available.'); return null } 5context.setMessages(() => snapshot)

Integration Points

ComponentFileKey location
Full compact entrycompact.ts~line 388 (compactConversation)
Pre-compact snapshotsnapshot.tssavePreCompactSnapshot()
Snapshot restoresnapshot.tsloadPreCompactSnapshot()
Orchestrator decideorchestrator/index.tsline 47
Orchestrator executeorchestrator/index.tsline 57
Unified decide+logorchestrator/index.tsline 94 (decideAndLog)
Auto-compact triggerautoCompact.tsline 160
Micro compactmicroCompact.tsCOMPACTABLE_TOOLS
Session memorysessionMemoryCompact.tskeeps recent messages
Post-compact boundarycompact.tscreateCompactBoundaryMessage()
Compact promptprompt.tsgetCompactPrompt()

Snapshot Storage Convention

  • Location: same directory as session JSONL (~/.claude/projects/<sanitized-cwd>/)
  • Filename: {sessionId}.pre-compact-snapshot.jsonl
  • Format: one JSON.stringify(message) per line
  • Atomic write: write to .tmp then rename()
  • Lifecycle: created before compact, consumed by /rollback, overwritten by next compact

Anti-Patterns

  • Blocking compact on hook failure — always use try/catch with best-effort semantics
  • Hooking into micro/session-memory compact for "message loss" scenarios — they don't lose messages
  • Modifying messages in pre-compact hooks — hooks should be read-only observers
  • Storing snapshots outside the session directory — breaks session lifecycle binding
  • Relying on CompactOrchestrator for all compact paths — legacy code may bypass it (check isCompactOrchestratorEnabled())
  • Reintroducing separate threshold math in query.ts or autoCompact.ts instead of reusing contextBudget.ts
  • Adding a second tool-result summarizer instead of reusing toolResultSummary.ts

相关技能

寻找 compact-lifecycle-reuse 的替代方案 (Alternative) 或可搭配使用的同类 community Skill?探索以下相关开源技能。

查看全部

openclaw-release-maintainer

Logo of openclaw
openclaw

本地化技能摘要: 🦞 # OpenClaw Release Maintainer Use this skill for release and publish-time workflow. It covers ai, assistant, crustacean workflows. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

333.8k
0
AI

widget-generator

Logo of f
f

本地化技能摘要: Generate customizable widget plugins for the prompts.chat feed system # Widget Generator Skill This skill guides creation of widget plugins for prompts.chat . It covers ai, artificial-intelligence, awesome-list workflows. This AI agent skill supports Claude Code, Cursor, and Windsurf

149.6k
0
AI

flags

Logo of vercel
vercel

本地化技能摘要: The React Framework # Feature Flags Use this skill when adding or changing framework feature flags in Next.js internals. It covers blog, browser, compiler workflows. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

138.4k
0
浏览器

pr-review

Logo of pytorch
pytorch

本地化技能摘要: Usage Modes No Argument If the user invokes /pr-review with no arguments, do not perform a review . It covers autograd, deep-learning, gpu workflows. This AI agent skill supports Claude Code, Cursor, and Windsurf workflows.

98.6k
0
开发者工具