Skip to content

DangQuangSE/team-development-skills / .agents/skills/session-memory

session-memory

Verified

Read and reuse AI coding session context across Claude Code, Codex, Antigravity/agent hooks, Cursor adapters, and compatible AI tools. Use this skill whenever the user asks to read, inspect, resume, compare, or continue another session by name or session ID, asks what happened in the previous session, or starts a new session that should inherit the nearest prior context. The paired provider adapter automatically loads the nearest previous project session at startup and resolves explicit session-read requests.

FileKindSize
SKILL.mdskill md3.8 KB
hooks/lib/ck_config_utils.pyscript3.7 KB
hooks/lib/hook_logger.pyscript1.4 KB
hooks/session_memory.pyscript25.7 KB

hooks/lib/ck_config_utils.py

View on GitHub
"""
Project root detection, .ck.json config access, and common path helpers.

Usage:
    from ck_config_utils import (
        find_project_root, get_project_name, get_claude_dir, get_sessions_dir,
        load_ck_config, get_section, is_enabled,
    )
"""
import json
import os
import subprocess
from pathlib import Path

SESSION_DATA_DIR = "session-data"


# ── project root ──────────────────────────────────────────────────────────────

def find_project_root(cwd: str | None = None) -> Path | None:
    """Locate the git project root. Uses git CLI for worktree support,
    falls back to .git-directory walk, then CLAUDE_PROJECT_DIR env var."""
    work_dir = cwd or os.getcwd()
    try:
        r = subprocess.run(
            ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"],
            capture_output=True, text=True, timeout=5, cwd=work_dir,
        )
        if r.returncode == 0 and r.stdout.strip():
            p = Path(r.stdout.strip())
            if p.name == ".git":
                return p.parent
            s = str(p)
            marker = os.sep + ".git"
            idx = s.lower().rfind(marker.lower())
            if idx > 0:
                return Path(s[:idx])
    except Exception:
        pass

    # Fallback: walk up for .git directory
    start = Path(work_dir)
    for p in [start, *start.parents]:
        if (p / ".git").exists():
            return p

    env = os.environ.get("CLAUDE_PROJECT_DIR")
    if env and Path(env).exists():
        return Path(env)

    return None


# ── path helpers ──────────────────────────────────────────────────────────────

def get_home_dir() -> Path:
    explicit = os.environ.get("HOME") or os.environ.get("USERPROFILE")
    return Path(explicit) if explicit else Path.home()


def get_claude_dir() -> Path:
    return get_home_dir() / ".claude"


def get_sessions_dir(cwd: str | None = None) -> Path:
    root = find_project_root(cwd)
    if root:
        return root / ".claude" / SESSION_DATA_DIR
    return get_claude_dir() / SESSION_DATA_DIR


def get_project_name(cwd: str | None = None) -> str | None:
    work_dir = cwd or os.getcwd()
    try:
        r = subprocess.run(
            ["git", "rev-parse", "--show-toplevel"],
            capture_output=True, text=True, timeout=5, cwd=work_dir,
        )
        if r.returncode == 0 and r.stdout.strip():
            return Path(r.stdout.strip()).name
    except Exception:
        pass
    return Path(work_dir).name or None


# ── .ck.json config ───────────────────────────────────────────────────────────

def load_ck_config(root: Path | None = None) -> dict:
    """Load .ck.json from project root. Returns empty dict on any failure."""
    r = root or find_project_root()
    if not r:
        return {}
    ck = r / ".ck.json"
    if not ck.exists():
        return {}
    try:
        return json.loads(ck.read_text(encoding="utf-8-sig"))
    except Exception:
        return {}


def get_section(key: str, default: dict | None = None, root: Path | None = None) -> dict:
    """Return a top-level config section, or default if missing."""
    return load_ck_config(root).get(key, default if default is not None else {})


def is_enabled(key: str, root: Path | None = None) -> bool:
    """Return True if the config section exists and has enabled != false."""
    return get_section(key, root=root).get("enabled", True)
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall