feat(v3.2.24): Memory MCP 退避機能 — PreCompact hook + evacuation JSON - #177
Conversation
…08_AgentTeams クリーンアップ (Issue #176) - .claude/claudeos/hooks/memory-mcp-evacuation.md 新規: Claude 向け PreCompact 実行指示書 - pre-compact.js: writeEvacuationSummary() 追加 → evacuation-latest.json 原子書き込み - hooks.json: PreCompact セクション追加 (memory-mcp-evacuation エントリ) - snapshots/.gitignore: evacuation-latest.json 追加 (エフェメラル除外) - 08_AgentTeams対応表.md: 未実装機能セクション cleanup (Issue #100, #176 実装済み反映) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthrough/compact 実行前にセッション状態を Memory MCP へ退避する PreCompact フックを追加・定義し、pre-compact スクリプトを拡張して退避サマリをスナップショット出力、関連ドキュメントとタスクリストを更新・クリーンアップしました。 Changes
Sequence DiagramsequenceDiagram
participant User as ユーザー
participant ClaudeCode as ClaudeCode
participant PreCompact as PreCompact フック
participant State as ./state.json
participant MCP as Memory MCP
participant Snapshots as ./snapshots/
User->>ClaudeCode: /compact 実行
activate ClaudeCode
ClaudeCode->>PreCompact: memory-mcp-evacuation 実行
activate PreCompact
PreCompact->>MCP: mcp__memory__read_graph / search_nodes(接続確認)
alt Memory MCP 接続
MCP-->>PreCompact: 接続 OK
PreCompact->>State: ./state.json 読取
State-->>PreCompact: execution, stable, token 等
PreCompact->>PreCompact: 退避ペイロード構築(タイムスタンプ付与)
PreCompact->>MCP: mcp__memory__create_entities / add_observations(SessionEvacuation 保存)
MCP-->>PreCompact: 保存応答(失敗はログに留め継続)
PreCompact->>MCP: mcp__memory__search_nodes(既存 SessionEvacuation 検索)
MCP-->>PreCompact: 検索結果
PreCompact->>MCP: mcp__memory__delete_entities(最新5件を残して削除)
MCP-->>PreCompact: 削除応答(失敗は無視)
PreCompact->>Snapshots: evacuation-latest.json 書込(原子)
Snapshots-->>PreCompact: 書込完了
PreCompact-->>ClaudeCode: 完了ログ出力
else Memory MCP 非接続
MCP-->>PreCompact: 接続失敗
PreCompact-->>ClaudeCode: no-op で終了
end
deactivate PreCompact
ClaudeCode->>ClaudeCode: 既存 snapshot/compact 処理継続
deactivate ClaudeCode
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Implements Issue #176 by adding a PreCompact “evacuation” flow that persists distilled session-restart context to a JSON snapshot and instructs Claude (via a hook command-book) to also write the state into Memory MCP, plus related documentation/version bookkeeping.
Changes:
- Add
memory-mcp-evacuationPreCompact hook instructions to evacuate keystate.jsonfields into Memory MCP (fail-soft when MCP is unavailable). - Extend
pre-compact.jsto writeevacuation-latest.json(atomic write) alongside existing state snapshotting. - Register the new PreCompact hook and update changelog/README/TASKS and snapshots gitignore accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
TASKS.md |
Marks Issue #176 as done and updates the auto-extracted backlog section to indicate no remaining unimplemented items. |
README.md |
Bumps displayed version highlights to v3.2.24 and summarizes the new evacuation feature + doc cleanup. |
CHANGELOG.md |
Adds a v3.2.24 entry describing the PreCompact evacuation feature and doc cleanup. |
.claude/claudeos/snapshots/.gitignore |
Ignores evacuation-latest.json snapshot artifact. |
.claude/claudeos/scripts/hooks/pre-compact.js |
Adds writeEvacuationSummary() to write evacuation-latest.json under snapshots. |
.claude/claudeos/hooks/memory-mcp-evacuation.md |
New hook “command book” defining the Memory MCP evacuation steps and retention policy. |
.claude/claudeos/hooks/hooks.json |
Adds PreCompact hook registration for memory-mcp-evacuation. |
| | セッション要約 | `execution.last_session_summary` | 前回作業内容 | | ||
| | STABLE 状態 | `stable.stable_achieved` / `stable.consecutive_success` | 品質状態 | | ||
| | 最終検証日時 | `stable.last_verified_at` | STABLE の鮮度 | | ||
| | 停止日時 | `execution.last_stop_at` | セッション境界 | | ||
| | 現在フェーズ予算 | `token.current_phase_used` | トークン消費状況 | |
There was a problem hiding this comment.
Step 3 の収集フィールドに token.current_phase_used が含まれていますが、Step 4 の observations 例に token 使用量が反映されていません。このままだと「何を退避するか」の仕様が曖昧になるので、token 使用量をエンティティ observation に含めるか、収集対象フィールド表から削除して記載を揃えてください。
| 39. [DONE] [Priority:P2][Owner:Developer][Source:GitHub#176] v3.2.24 Memory MCP 退避機能 — memory-mcp-evacuation.md + pre-compact.js evacuation JSON + hooks.json PreCompact + 08_AgentTeams対応表クリーンアップ (Issue #176) | ||
|
|
||
| ## Auto Extracted From Agent Teams Matrix | ||
|
|
There was a problem hiding this comment.
## Auto Extracted From Agent Teams Matrix が未実装 0 件の注記 1 行だけになっていますが、この状態で Sync-AgentTeamsBacklog.ps1 -Action sync -ApplyMetadata を実行すると抽出行が 0 件のため Source:AgentTeamsMatrix を含む行が生成されず、tests/Diagnostics.Tests.ps1 の "Sync-AgentTeamsBacklog.ps1 が metadata 付き抽出を同期できること" が失敗します。未実装 0 件を許容するようにテスト側の期待値を更新するか、Sync スクリプト側で 0 件時もメタデータを含むプレースホルダ行を出力するなど、同期後の TASKS.md でもメタデータが現れる形に揃えてください。
| 1. [DONE] [Priority:P3][Owner:Architect][Source:AgentTeamsMatrix] 自動抽出対象の未実装機能なし — 全項目実装完了 (metadata placeholder) |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/claudeos/hooks/memory-mcp-evacuation.md:
- Line 59: Step 3 declares collecting token.current_phase_used but Step 4's
observations sample omits it, causing ambiguity; pick one canonical spec and
make both steps match — either remove token.current_phase_used from the Step 3
collection list or add token.current_phase_used into the Step 4 observations
sample (and any other samples at lines ~73-78). Update the sample names/keys
exactly (token.current_phase_used, observations) so the collection and example
obs are identical and tests/implementations can unambiguously use the same
field.
In `@README.md`:
- Around line 10-11: Update the README's Hooks summary and list to reflect the
new PreCompact hook introduced in v3.2.24: add the "PreCompact" entry and
include "memory-mcp-evacuation.md" in the hook list, increment the total hooks
count where displayed, and mention the related change in pre-compact.js that
writes "evacuation-latest.json" so the README and Hooks section no longer drift
from the changelog and actual implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 63f25e1a-6a22-4398-96d7-4273a5ae224f
📒 Files selected for processing (8)
.claude/claudeos/hooks/hooks.json.claude/claudeos/hooks/memory-mcp-evacuation.md.claude/claudeos/scripts/hooks/pre-compact.js.claude/claudeos/snapshots/.gitignoreCHANGELOG.mdREADME.mdTASKS.mddocs/common/08_AgentTeams対応表.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Agent
- GitHub Check: test-and-validate
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-17T13:20:45.445Z
Learnt from: CR
Repo: Kensan196948G/ClaudeCode-StartUpTools-New PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-17T13:20:45.445Z
Learning: At session start, immediately register 4 timed loops (`/loop 30m ClaudeOS Monitor`, `/loop 2h ClaudeOS Development`, `/loop 1h ClaudeOS Verify`, `/loop 1h ClaudeOS Improvement`) before starting development; complete Codex setup (`/codex:setup`, `/codex:status`) and memory restoration from previous session
Applied to files:
README.md
📚 Learning: 2026-04-17T02:53:58.179Z
Learnt from: CR
Repo: Kensan196948G/ClaudeCode-StartUpTools-New PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-04-17T02:53:58.179Z
Learning: Follow the standard autonomous development loop: Analysis → Main Agent Discussion → Task Decomposition → Agent Assignment → Implementation/Review → Validation → PR/Issue Update → Completion
Applied to files:
TASKS.md
🪛 LanguageTool
TASKS.md
[grammar] ~50-~50: Use a hyphen to join words.
Context: ...entTeams対応表クリーンアップ (Issue #176) ## Auto Extracted From Agent Teams Matrix (自動抽出...
(QB_NEW_EN_HYPHEN)
🔇 Additional comments (6)
.claude/claudeos/snapshots/.gitignore (1)
4-4:evacuation-latest.jsonの ignore 追加は適切です。ローカル生成アーティファクトの除外として妥当で、PreCompact の新フローと整合しています。
docs/common/08_AgentTeams対応表.md (1)
53-53: 未実装セクションのクリーンアップ方針は妥当です。完了済み項目の明示により、バックログ自動同期の意図が明確になっています。
Also applies to: 56-57
.claude/claudeos/hooks/hooks.json (1)
2-7: PreCompact フック登録の追加は問題ありません。
memory-mcp-evacuationの目的と no-op 条件が明示されており、運用意図が明確です。TASKS.md (1)
48-48: TASKS への完了反映は適切です。Issue
#176の完了記録と自動抽出セクションの状態が整合しています。Also applies to: 52-52
.claude/claudeos/scripts/hooks/pre-compact.js (1)
82-102: evacuation サマリ出力の追加実装は堅実です。既存の PreCompact 処理に対して、原子書き込み・null セーフ・明示ログの形で安全に拡張できています。
Also applies to: 106-108, 116-118
CHANGELOG.md (1)
5-28: v3.2.24 エントリの構成は明確で問題ありません。概要・変更対象・検証項目が分離されており、追跡しやすい記述です。
| | STABLE 状態 | `stable.stable_achieved` / `stable.consecutive_success` | 品質状態 | | ||
| | 最終検証日時 | `stable.last_verified_at` | STABLE の鮮度 | | ||
| | 停止日時 | `execution.last_stop_at` | セッション境界 | | ||
| | 現在フェーズ予算 | `token.current_phase_used` | トークン消費状況 | |
There was a problem hiding this comment.
Step 3 と Step 4 で退避項目の定義が不一致です。
収集対象に token.current_phase_used を含めていますが、書き込みサンプルの observations には出てこないため、実装解釈が分かれます。仕様を一意にしてください。
差分案(Step 4 のサンプルへ token を追加)
"observations": [
"phase: <execution.phase>",
"summary: <execution.last_session_summary>",
"stable: <stable.stable_achieved> (consecutive=<consecutive_success>)",
"last_verified_at: <stable.last_verified_at>",
+ "current_phase_used: <token.current_phase_used>",
"evacuated_at: <現在時刻 ISO 8601>"
]Also applies to: 73-78
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.claude/claudeos/hooks/memory-mcp-evacuation.md at line 59, Step 3 declares
collecting token.current_phase_used but Step 4's observations sample omits it,
causing ambiguity; pick one canonical spec and make both steps match — either
remove token.current_phase_used from the Step 3 collection list or add
token.current_phase_used into the Step 4 observations sample (and any other
samples at lines ~73-78). Update the sample names/keys exactly
(token.current_phase_used, observations) so the collection and example obs are
identical and tests/implementations can unambiguously use the same field.
| > **🔧 v3.2.24 — Memory MCP 退避機能 + AgentTeams ドキュメントクリーンアップ** | ||
| > PreCompact フック `memory-mcp-evacuation.md` 新規実装。`pre-compact.js` に `evacuation-latest.json` 書き出しを追加し MCP 非接続環境でも再開情報を保全。`08_AgentTeams対応表.md` の未実装機能セクションをクリーンアップ。詳細は [`CHANGELOG.md`](./CHANGELOG.md) v3.2.24 節を参照。 |
There was a problem hiding this comment.
v3.2.24 記載に対してフック一覧の数が追随していません。
この更新で PreCompact hook 追加を案内していますが、同一 README 内の Hooks 件数/一覧が旧状態のままです。ドキュメントドリフトを避けるため同時更新をお願いします。
差分案(README 内の関連箇所も合わせて更新)
-| Hooks | **4個** — agent-risk-check / capture-result / onboarding-refresh / usage-history-recorder |
+| Hooks | **6個** — memory-mcp-evacuation / agent-risk-check / capture-result / usage-history-recorder / onboarding-refresh-on-stable / session-end |
-### Hooks 構成 (4個)
+### Hooks 構成 (6個)
| Hook | 種別 | 機能 |
|------|------|------|
+| `memory-mcp-evacuation` | PreCompact | `/compact` 前に再開用状態を退避(MCP未接続時 no-op) |
| `agent-risk-check` | PreToolUse | Bash/Edit/Write 操作前に第 2 の Claude が SAFE/CAUTION/BLOCK 判定 |
| `capture-result` | PostToolUse | 主要ツール結果を後続フック向けに正規化 |
| `usage-history-recorder` | PostToolUse | Agent/Skill/Command/Hook 呼び出し履歴を state.json に記録 |
| `onboarding-refresh-on-stable` | PostToolUse | STABLE 判定到達時に ONBOARDING.md を自動更新 |
+| `session-end` | Stop | 終了時に状態と再開点を保存 |Also applies to: 30-30
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` around lines 10 - 11, Update the README's Hooks summary and list
to reflect the new PreCompact hook introduced in v3.2.24: add the "PreCompact"
entry and include "memory-mcp-evacuation.md" in the hook list, increment the
total hooks count where displayed, and mention the related change in
pre-compact.js that writes "evacuation-latest.json" so the README and Hooks
section no longer drift from the changelog and actual implementation.
## 未実装機能が空になった後もテストが動作するよう、バックアップ/注入/リストアパターンに変更。 [System.IO.File]::ReadAllBytes でリストア精度を保証。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
変更内容
Issue #176 の実装。
/compact前に作業状態を Memory MCP へ退避し、セッション再開時の継続性を確保する。主な変更
.claude/claudeos/hooks/memory-mcp-evacuation.md.claude/claudeos/scripts/hooks/pre-compact.jswriteEvacuationSummary()追加 → evacuation-latest.json 原子書き込み.claude/claudeos/hooks/hooks.json.claude/claudeos/snapshots/.gitignoreevacuation-latest.json除外追加docs/common/08_AgentTeams対応表.md## 未実装機能cleanup(Issue #100, #176 実装済み反映)CHANGELOG.md/README.md/TASKS.md2 層アーキテクチャ
Node.js から MCP は直接呼べないため、ファイル経由の 2 層構成。
テスト結果
node .claude/claudeos/scripts/hooks/pre-compact.js実行確認済み[PreCompact] evacuation summary written: ...evacuation-latest.jsonログ出力確認evacuation-latest.jsonが gitignore で追跡除外されることを確認影響範囲
/compact実行時にのみ動作残課題
なし
Closes #176
🤖 Generated with Claude Code
Summary by CodeRabbit
新機能
ドキュメント
改善
テスト