mirror of
https://github.com/dtzp555-max/memory-continuity.git
synced 2026-07-21 21:15:07 +00:00
feat: upgrade from skill to lifecycle plugin (v2.0.0)
Replace prompt-based skill approach with OpenClaw lifecycle hooks (before_agent_start, agent_end, before_compaction, before_reset). State injection now happens automatically at the hook level, making it model-agnostic and reliable across all providers. - Add index.js with 5 lifecycle hooks - Add openclaw.plugin.json manifest - Rewrite post-install.sh to handle plugin installation - Update README with plugin architecture docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+94
-49
@@ -1,71 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# post-install.sh — Flush stale skill snapshots after installing memory-continuity
|
||||
# post-install.sh — Install memory-continuity as an OpenClaw lifecycle plugin
|
||||
#
|
||||
# OpenClaw caches a "skillsSnapshot" per session. If this skill was installed
|
||||
# while the gateway was stopped (or after a gateway restart), the file watcher
|
||||
# won't detect the new SKILL.md and existing sessions will never refresh.
|
||||
#
|
||||
# This script clears stale snapshots so every session rebuilds on next turn.
|
||||
# This script:
|
||||
# 1. Copies the plugin to ~/.openclaw/extensions/memory-continuity/
|
||||
# 2. Adds the plugin entry to openclaw.json (if not present)
|
||||
# 3. Restarts the gateway
|
||||
#
|
||||
# Usage:
|
||||
# bash scripts/post-install.sh [--agent-id <id>]
|
||||
#
|
||||
# Options:
|
||||
# --agent-id <id> Agent ID (default: main)
|
||||
# bash scripts/post-install.sh
|
||||
#
|
||||
# Safe to run multiple times (idempotent).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
AGENT_ID="main"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--agent-id) AGENT_ID="$2"; shift 2 ;;
|
||||
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
OPENCLAW_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}"
|
||||
SESSIONS_FILE="$OPENCLAW_DIR/agents/$AGENT_ID/sessions/sessions.json"
|
||||
EXTENSIONS_DIR="$OPENCLAW_DIR/extensions"
|
||||
PLUGIN_DIR="$EXTENSIONS_DIR/memory-continuity"
|
||||
CONFIG_FILE="$OPENCLAW_DIR/openclaw.json"
|
||||
|
||||
if [[ ! -f "$SESSIONS_FILE" ]]; then
|
||||
echo "No sessions file found at $SESSIONS_FILE — nothing to do."
|
||||
exit 0
|
||||
# Resolve the repo root (parent of scripts/)
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
echo "=== memory-continuity plugin installer ==="
|
||||
echo ""
|
||||
|
||||
# Step 1: Copy plugin files to extensions directory
|
||||
echo "[1/3] Installing plugin to $PLUGIN_DIR ..."
|
||||
mkdir -p "$EXTENSIONS_DIR"
|
||||
|
||||
# Remove old installation if exists
|
||||
if [[ -d "$PLUGIN_DIR" || -L "$PLUGIN_DIR" ]]; then
|
||||
rm -rf "$PLUGIN_DIR"
|
||||
echo " Removed previous installation"
|
||||
fi
|
||||
|
||||
# Count and clear stale skillsSnapshot entries
|
||||
BEFORE=$(python3 -c "
|
||||
# Copy essential plugin files (not the entire repo)
|
||||
mkdir -p "$PLUGIN_DIR"
|
||||
for f in index.js openclaw.plugin.json SKILL.md; do
|
||||
if [[ -f "$REPO_DIR/$f" ]]; then
|
||||
cp "$REPO_DIR/$f" "$PLUGIN_DIR/"
|
||||
fi
|
||||
done
|
||||
echo " Copied plugin files"
|
||||
|
||||
# Step 2: Add plugin entry to openclaw.json
|
||||
echo "[2/3] Configuring openclaw.json ..."
|
||||
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
echo " WARNING: $CONFIG_FILE not found. Skipping config update."
|
||||
echo " You'll need to manually add the plugin entry."
|
||||
else
|
||||
# Check if memory-continuity entry already exists
|
||||
if python3 -c "
|
||||
import json, sys
|
||||
with open('$SESSIONS_FILE') as f:
|
||||
with open('$CONFIG_FILE') as f:
|
||||
data = json.load(f)
|
||||
count = sum(1 for v in data.values() if isinstance(v, dict) and 'skillsSnapshot' in v)
|
||||
print(count)
|
||||
" 2>/dev/null || echo "0")
|
||||
|
||||
if [[ "$BEFORE" == "0" ]]; then
|
||||
echo "No stale skill snapshots found — all sessions will discover skills normally."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
python3 -c "
|
||||
entries = data.get('plugins', {}).get('entries', {})
|
||||
if 'memory-continuity' in entries:
|
||||
print('exists')
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
" 2>/dev/null; then
|
||||
echo " Plugin entry already exists in config"
|
||||
else
|
||||
# Add the plugin entry
|
||||
python3 -c "
|
||||
import json
|
||||
path = '$SESSIONS_FILE'
|
||||
path = '$CONFIG_FILE'
|
||||
with open(path) as f:
|
||||
data = json.load(f)
|
||||
for key in data:
|
||||
if isinstance(data[key], dict) and 'skillsSnapshot' in data[key]:
|
||||
del data[key]['skillsSnapshot']
|
||||
if 'plugins' not in data:
|
||||
data['plugins'] = {}
|
||||
if 'entries' not in data['plugins']:
|
||||
data['plugins']['entries'] = {}
|
||||
data['plugins']['entries']['memory-continuity'] = {
|
||||
'enabled': True,
|
||||
'hooks': {
|
||||
'allowPromptInjection': True
|
||||
},
|
||||
'config': {
|
||||
'maxStateLines': 50,
|
||||
'archiveOnNew': True,
|
||||
'autoExtract': True
|
||||
}
|
||||
}
|
||||
with open(path, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
"
|
||||
|
||||
echo "Cleared skillsSnapshot from $BEFORE session(s) in $SESSIONS_FILE"
|
||||
echo "All sessions will rebuild their skill list on next turn."
|
||||
|
||||
# Restart gateway if running, so file watcher picks up the new SKILL.md
|
||||
if command -v openclaw &>/dev/null; then
|
||||
if openclaw gateway status 2>&1 | grep -q "running"; then
|
||||
echo "Restarting gateway to activate file watcher..."
|
||||
openclaw gateway restart 2>/dev/null && echo "Gateway restarted." || echo "Gateway restart failed — try manually: openclaw gateway restart"
|
||||
print(' Added plugin entry to config')
|
||||
" 2>/dev/null || echo " WARNING: Could not update config automatically. Add manually."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 3: Restart gateway
|
||||
echo "[3/3] Restarting gateway ..."
|
||||
if command -v openclaw &>/dev/null; then
|
||||
if openclaw gateway status 2>&1 | grep -q "running"; then
|
||||
openclaw gateway restart 2>/dev/null && echo " Gateway restarted" || echo " Gateway restart failed — try: openclaw gateway restart"
|
||||
else
|
||||
echo " Gateway not running — start it with: openclaw gateway start"
|
||||
fi
|
||||
else
|
||||
echo " openclaw command not found — install OpenClaw first"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Installation complete ==="
|
||||
echo ""
|
||||
echo "Verify with:"
|
||||
echo " openclaw gateway restart 2>&1 | grep memory-continuity"
|
||||
echo ""
|
||||
echo "Test with:"
|
||||
echo " 1. Tell your agent something memorable"
|
||||
echo " 2. Send /new"
|
||||
echo " 3. Ask what you told it"
|
||||
|
||||
Reference in New Issue
Block a user