/p8-engine-plugin:inject-memory runs instead · from p8-engine-plugin
Injects a lightweight AI memory system into any project, creating a memory/ directory with structured templates, appending memory usage rules to CLAUDE.md, and configuring a PostToolUse hook for auto-syncing index timestamps.
This skill never runs in Claude Code
It ships in p8-engine-plugin at skills/, but /p8-engine-plugin:inject-memory (a command, or a skill Claude Code finds first) has the same name: typing it, or Claude choosing it, runs that one instead.
在当前项目注入一套轻量 AI 记忆系统(memory/ 目录 + CLAUDE.md 规范 + PostToolUse 自动同步 hook),并做原子 git commit。
目标是让 Claude 在多次会话间保持"项目记忆",通过索引 + 结构化模板 + 自动化同步三件套实现。
skill 执行时 cwd 是目标项目根,模板在 skill 自身目录。用下面的顺序找 $SKILL_DIR:
./.claude/skills/inject-memory$HOME/.claude/skills/inject-memoryif [ -d "./.claude/skills/inject-memory/templates" ]; then
SKILL_DIR="./.claude/skills/inject-memory"
elif [ -d "$HOME/.claude/skills/inject-memory/templates" ]; then
SKILL_DIR="$HOME/.claude/skills/inject-memory"
else
echo "inject-memory skill not found"; exit 1
fi
在所有后续 Bash 命令中用这个变量引用模板。
按顺序执行,任何一步失败用 AskUserQuestion 向用户确认如何处理。
git rev-parse --git-dir 2>/dev/null
git init。拒绝则放弃注入。git status --porcelain
有未提交变更时,用 AskUserQuestion 给三个选项:
[ -e memory ] && echo "exists"
已存在时,用 AskUserQuestion 问:
grep -l "MEMORY-SYSTEM:BEGIN" CLAUDE.md 2>/dev/null
mkdir -p memory/modules memory/bugs memory/progress
用 Read 读取 $SKILL_DIR/templates/ 下的模板内容,用 Write 写到目标:
| 源($SKILL_DIR/templates/) | 目标 |
|---|---|
_index.md | memory/_index.md |
_tutorial.md | memory/_tutorial.md |
modules/overview.template.md | memory/modules/overview.template.md |
modules/design.template.md | memory/modules/design.template.md |
modules/integration.template.md | memory/modules/integration.template.md |
modules/known_issues.template.md | memory/modules/known_issues.template.md |
bugs/bug.template.md | memory/bugs/bug.template.md |
progress/current-status.template.md | memory/progress/current-status.template.md |
合并模式下:只复制目标不存在的文件。
读取 $SKILL_DIR/templates/CLAUDE_INJECT.md,用追加方式写入项目 CLAUDE.md:
CLAUDE.md 不存在:创建,内容就是 CLAUDE_INJECT.md 的内容<!-- MEMORY-SYSTEM:BEGIN --> 标记:在文件末尾追加(前面加一个空行)用 Edit 工具做追加(读现有内容 → 拼接 → Write)。
mkdir -p .claude/hooks
cp "$SKILL_DIR/hooks/sync-memory-index.mjs" .claude/hooks/sync-memory-index.mjs
(Windows 的 Git Bash 下 cp 可用。跨平台稳妥的话用 Read + Write 代替 cp。)
读取 .claude/settings.json(不存在则新建 {}),确保下列条目存在:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "node .claude/hooks/sync-memory-index.mjs"
}
]
}
]
}
}
hook 说明:
sync-memory-index.mjs(PostToolUse):修改 memory/ 文件后,自动同步 _index.md 的最后更新日期(一次可更新所有匹配行)合并规则:
hooks.PostToolUse 数组,检查是否已有相同 command 的条目;有则跳过,没有则追加一项。写回时用4 空格缩进,保留 JSON 格式。
node --version
无 Node 时提示用户安装 Node 16+,但不阻断注入(hook 可后补配置)。
git add memory/ CLAUDE.md .claude/hooks/sync-memory-index.mjs .claude/settings.json
git status --short
git commit -m "chore: inject AI memory system
- memory/ directory skeleton with templates
- _tutorial.md as portable guide
- PostToolUse hook: auto-sync _index.md last-updated column
- CLAUDE.md: memory usage rules + startup protocol appended
Generated by inject-memory skill."
禁止 --no-verify。如果 pre-commit hook 失败:
git status 查看commit 成功后,向用户报告:
memory/modules/X.md 保存,应能看到 _index.md 的日期被同步(前提是表格里有对应条目和日期列)memory/_tutorial.md 了解如何开始用回滚触发条件:阶段三/四出错且用户选择"回滚"。
回滚动作(需二次确认后执行,因为会删除新建文件):
rm -rf memory/
rm -f .claude/hooks/sync-memory-index.mjs
git checkout -- CLAUDE.md .claude/settings.json 2>/dev/null || rm -f CLAUDE.md .claude/settings.json
注意:git checkout -- 只对已追踪文件有效;没被追踪过的新文件要 rm。
永远不要:
git reset --hard此 skill 重复运行应当无害:
如果只部分已存在,只补齐缺的部分。
hooks/sync-memory-index.mjs (opens in a new tab)templates/CLAUDE_INJECT.md (opens in a new tab)templates/_index.md (opens in a new tab)templates/_tutorial.md (opens in a new tab)templates/bugs/bug.template.md (opens in a new tab)templates/modules/design.template.md (opens in a new tab)templates/modules/integration.template.md (opens in a new tab)templates/modules/known_issues.template.md (opens in a new tab)templates/modules/overview.template.md (opens in a new tab)templates/progress/current-status.template.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub darven-cs/p8-engine --plugin p8-engine3 skills in this plugin
/p8-engineEngineering methodology skill for all tasks. Core behaviors: clarify before assuming, investigate before asking, verify before delivering, review full dependency chains, match existing code style. Trigger on: any task start, code development, debugging, multi-step work. Do NOT skip just because the task looks easy./specSpec-Driven Development (SDD) 工作流——在改动代码前先生成一份中文设计文档(spec) 并与用户确认。**必须触发**的场景:用户提出新增功能/加一个按钮/页面/接口/字段/能力、refactor/重构、修复非平凡 bug、优化、做一个 X、涉及 2 个及以上文件的多步改动、提到「设计/方案/规划/先想清楚」。即使没说「写 spec」,只要改动不是纯 typo、文档润色、依赖升级、版本号、单行修复,都应触发。关键词(中):新功能、新增、加、实现、重构、修复、优化、改造、调整;关键词(英):feature、refactor、fix、optimize、redesign、rework、add、implement。Other plugins' skills for the same job