@dosx/agent-memory 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/bin/agent-memory.js +496 -0
- package/hooks/README.md +292 -0
- package/hooks/agent-memory-hooks/agent-memory-common.sh +1020 -0
- package/hooks/agent-memory-hooks/agent-memory-session.sh +98 -0
- package/hooks/agent-memory-hooks/agent-memory-sync.sh +147 -0
- package/hooks/claude-code/settings.json +51 -0
- package/hooks/codex/config.toml.snippet +38 -0
- package/hooks/codex/hooks.json +51 -0
- package/hooks/copilot/agent-memory.json +34 -0
- package/hooks/cursor/hooks.json +36 -0
- package/hooks/gemini/settings.json +50 -0
- package/hooks/git/pre-commit +45 -0
- package/hooks/install-hooks.sh +358 -0
- package/hooks/opencode/agent-memory.ts +320 -0
- package/package.json +22 -0
- package/skills/agent-memory/SKILL.md +185 -0
- package/skills/agent-memory/references/agent-block.md +115 -0
- package/skills/agent-memory/references/bootstrap.md +84 -0
- package/skills/agent-memory/references/init.md +211 -0
- package/skills/agent-memory/references/install-hooks.md +113 -0
- package/skills/agent-memory/references/lint.md +113 -0
- package/skills/agent-memory/references/sync.md +120 -0
- package/skills/agent-memory/references/update.md +145 -0
- package/skills/agent-memory/vendor/README.md +132 -0
- package/skills/agent-memory/vendor/UPDATE.md +369 -0
- package/skills/agent-memory/vendor/memory/active-work/TEMPLATE.md +33 -0
- package/skills/agent-memory/vendor/memory/current.md +34 -0
- package/skills/agent-memory/vendor/memory/decisions.md +30 -0
- package/skills/agent-memory/vendor/memory/index.md +55 -0
- package/skills/agent-memory/vendor/memory/instructions.md +340 -0
- package/skills/agent-memory/vendor/memory/log.md +38 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# `/agent-memory install hooks`
|
|
2
|
+
|
|
3
|
+
Print how to install or refresh lifecycle hooks for one harness. **This skill
|
|
4
|
+
does not copy scripts, merge configs, or run installers** — the user must run
|
|
5
|
+
the shell script or `npx` CLI themselves (trust boundary for security audits).
|
|
6
|
+
|
|
7
|
+
Does **not** create `.agents/memory/`, touch project memory content, or wire
|
|
8
|
+
agent instruction files — use `init` for that.
|
|
9
|
+
|
|
10
|
+
Also used by `init` (step 6) and `update` (refresh already-installed harnesses)
|
|
11
|
+
to print the same instructions.
|
|
12
|
+
|
|
13
|
+
## Invocation
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
/agent-memory install hooks <harness>
|
|
17
|
+
/agent-memory install hook <harness> # alias (singular)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Accepted `<harness>` values (aliases in parentheses):
|
|
21
|
+
|
|
22
|
+
| Harness | Aliases | Dir (created by installer if missing) | Installer writes into |
|
|
23
|
+
| ---------- | ------------- | ------------------------------------- | ---------------------------------------- |
|
|
24
|
+
| `cursor` | — | `.cursor/` | `.cursor/hooks/` + merge `hooks.json` |
|
|
25
|
+
| `claude` | `claude-code` | `.claude/` | `.claude/hooks/` + merge `settings.json` |
|
|
26
|
+
| `codex` | — | `.codex/` | `.codex/hooks/` + merge `hooks.json` |
|
|
27
|
+
| `opencode` | — | `.opencode/` | `.opencode/hooks/` + plugin `.ts` |
|
|
28
|
+
| `copilot` | `github` | `.github/` | `.github/hooks/` + `agent-memory.json` |
|
|
29
|
+
| `gemini` | — | `.gemini/` | `.gemini/hooks/` + merge `settings.json` |
|
|
30
|
+
|
|
31
|
+
Canonical hook sources live under `hooks/` in the
|
|
32
|
+
[agent-memory](https://github.com/diegoos/agent-memory) repository (tag matching
|
|
33
|
+
this skill's `metadata.version`).
|
|
34
|
+
|
|
35
|
+
## Steps
|
|
36
|
+
|
|
37
|
+
1. **Guard.** If `.agents/memory/` does not exist, stop and suggest
|
|
38
|
+
`/agent-memory init` first. (Skip this guard when called from `init` step 6.)
|
|
39
|
+
|
|
40
|
+
2. **Parse harness.** Read `<harness>` from the invocation. Normalize aliases
|
|
41
|
+
(`claude-code` → `claude`, `github` → `copilot`). If missing, stop and list
|
|
42
|
+
accepted values.
|
|
43
|
+
|
|
44
|
+
3. **Prerequisite dir.** The user-run installer (`install-hooks.sh` / `npx`)
|
|
45
|
+
**creates** the harness prerequisite directory if missing (e.g. `.cursor/`,
|
|
46
|
+
`.opencode/`). The skill itself still must **not** create those dirs — only
|
|
47
|
+
print the install commands.
|
|
48
|
+
|
|
49
|
+
4. **Print install instructions (do not execute).** Read this skill's
|
|
50
|
+
`metadata.version` (e.g. `0.0.13`). Tell the user to review and run **one** of
|
|
51
|
+
the following from the **project root** (never embed
|
|
52
|
+
`raw.githubusercontent.com` URLs):
|
|
53
|
+
|
|
54
|
+
**Preferred — npx:**
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx @dosx/agent-memory install hooks <harness>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Pinned tag (optional):**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx --yes github:diegoos/agent-memory#0.0.13 -- install hooks <harness>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
(Replace `0.0.13` with this skill's `metadata.version` when it differs.)
|
|
67
|
+
|
|
68
|
+
**Alternative — shell script:** open the GitHub release page for the matching
|
|
69
|
+
tag (Releases → `0.0.13`, or the tag tree on GitHub), review
|
|
70
|
+
`hooks/install-hooks.sh`, then from a checkout of that
|
|
71
|
+
tag:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
bash hooks/install-hooks.sh <harness>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Replace `<harness>` with the normalized harness name. Remind: the installer
|
|
78
|
+
needs Node.js for JSON merges; it creates the harness directory if missing;
|
|
79
|
+
Codex users should run `/hooks` in the TUI after install; Cursor may need a
|
|
80
|
+
hooks reload.
|
|
81
|
+
|
|
82
|
+
5. **Report.** List: harness, that hooks were **not** written by the agent, and
|
|
83
|
+
the exact commands printed. Suggest `/agent-memory sync` at the next
|
|
84
|
+
checkpoint after the user installs.
|
|
85
|
+
|
|
86
|
+
## Detecting installed harnesses (`update`)
|
|
87
|
+
|
|
88
|
+
A harness counts as **already installed** when its prerequisite dir exists
|
|
89
|
+
**and** any of these markers is present:
|
|
90
|
+
|
|
91
|
+
| Harness | Marker (any one) |
|
|
92
|
+
| ---------- | --------------------------------------------------------------------------------------- |
|
|
93
|
+
| `cursor` | `.cursor/hooks/agent-memory-sync.sh` or agent-memory in `.cursor/hooks.json` |
|
|
94
|
+
| `claude` | `.claude/hooks/agent-memory-sync.sh` |
|
|
95
|
+
| `codex` | `.codex/hooks/agent-memory-sync.sh` |
|
|
96
|
+
| `opencode` | `.opencode/plugin/agent-memory.ts` or `.opencode/hooks/agent-memory-sync.sh` |
|
|
97
|
+
| `copilot` | `.github/hooks/agent-memory.json` or `.github/hooks/agent-memory-sync.sh` |
|
|
98
|
+
| `gemini` | `.gemini/settings.json` containing agent-memory or `.gemini/hooks/agent-memory-sync.sh` |
|
|
99
|
+
|
|
100
|
+
For `update`, for **each** installed harness print the refresh commands from
|
|
101
|
+
step 4 (no agent copy/merge). Skip harnesses with no marker even if the
|
|
102
|
+
prerequisite dir exists.
|
|
103
|
+
|
|
104
|
+
## Behavior
|
|
105
|
+
|
|
106
|
+
Hooks run a **deterministic checkpoint** — `active-work/` (Touched files, Task
|
|
107
|
+
stub), `log.md` (session heading on session start + file-path bullets), and
|
|
108
|
+
`current.md` _In progress_ on session start. Semantic log text and
|
|
109
|
+
`decisions.md` stay agent-owned. See the
|
|
110
|
+
[hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
|
|
111
|
+
|
|
112
|
+
Optional git `pre-commit` is **not** installed by this command — see the same
|
|
113
|
+
[hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# `/agent-memory lint`
|
|
2
|
+
|
|
3
|
+
Check `.agents/memory/` for structural and consistency problems. Report
|
|
4
|
+
findings; fix only what is safe, and never change user content without
|
|
5
|
+
confirmation.
|
|
6
|
+
|
|
7
|
+
## Steps
|
|
8
|
+
|
|
9
|
+
1. **Guard.** If `.agents/memory/` does not exist, suggest `/agent-memory init`.
|
|
10
|
+
|
|
11
|
+
2. **Structural checks (deterministic).** Run from `.agents/memory/`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Broken cross-references: relative links pointing to files that no longer exist
|
|
15
|
+
grep -rhoE '\]\(\./[^)]+\)' . | sed -E 's/^\]\(\.\/([^)]+)\)$/\1/' \
|
|
16
|
+
| sort -u | while read -r f; do test -e "$f" || echo "missing: $f"; done
|
|
17
|
+
|
|
18
|
+
# Orphaned files: domains/features not referenced from index.md
|
|
19
|
+
find domains features -name '*.md' 2>/dev/null | while read -r f; do
|
|
20
|
+
grep -q "$(basename "$f")" index.md || echo "orphan: $f"
|
|
21
|
+
done
|
|
22
|
+
|
|
23
|
+
# Stale per-branch active-work: a file whose branch no longer exists
|
|
24
|
+
# (skipped when git lists no branches — no commits yet / not a git repo)
|
|
25
|
+
branches=$(git branch --format='%(refname:short)' | sed 's#[^A-Za-z0-9._-]#-#g')
|
|
26
|
+
[ -n "$branches" ] && find active-work -name '*.md' ! -name 'TEMPLATE.md' 2>/dev/null | while read -r f; do
|
|
27
|
+
printf '%s\n' "$branches" | grep -qx "$(basename "$f" .md)" || echo "stale: $f"
|
|
28
|
+
done
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Also report if `.agents/memory/.version` is missing — the memory was likely
|
|
32
|
+
installed manually without the skill, so `update` cannot track its version.
|
|
33
|
+
|
|
34
|
+
**Instruction wiring checks** — run from the **project root** (not from
|
|
35
|
+
`.agents/memory/`). Detect agent-memory blocks via `<!-- <agent-memory> -->`
|
|
36
|
+
… `<!-- </agent-memory> -->` or legacy plain tags.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Helper: true if file contains an agent-memory block
|
|
40
|
+
has_block() { grep -q '<agent-memory>' "$1" 2>/dev/null; }
|
|
41
|
+
|
|
42
|
+
# (a) Potential double-injection — block in AGENTS.md AND a harness-native file
|
|
43
|
+
# when AGENTS.md is not needed as a shared carrier
|
|
44
|
+
agents_block=false; has_block AGENTS.md && agents_block=true
|
|
45
|
+
codex_or_opencode=false
|
|
46
|
+
{ test -d .codex || test -d .opencode; } && codex_or_opencode=true
|
|
47
|
+
claude_delegates=false
|
|
48
|
+
test -f CLAUDE.md && grep -qE '@(\./)?AGENTS\.md' CLAUDE.md && claude_delegates=true
|
|
49
|
+
gemini_delegates=false
|
|
50
|
+
test -f GEMINI.md && grep -qE '@(\./)?AGENTS\.md' GEMINI.md && gemini_delegates=true
|
|
51
|
+
shared_carrier=false
|
|
52
|
+
{ $codex_or_opencode || $claude_delegates || $gemini_delegates; } && shared_carrier=true
|
|
53
|
+
|
|
54
|
+
if $agents_block; then
|
|
55
|
+
has_block .cursor/rules/agent-memory.mdc && \
|
|
56
|
+
! $shared_carrier && echo "double-injection: AGENTS.md + .cursor/rules/agent-memory.mdc"
|
|
57
|
+
has_block .github/instructions/agent-memory.instructions.md && \
|
|
58
|
+
! $shared_carrier && echo "double-injection: AGENTS.md + agent-memory.instructions.md"
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
# (b) Delegation canary — block in BOTH delegator and AGENTS.md
|
|
62
|
+
for f in CLAUDE.md GEMINI.md; do
|
|
63
|
+
test -f "$f" || continue
|
|
64
|
+
grep -qE '@(\./)?AGENTS\.md' "$f" || continue
|
|
65
|
+
has_block "$f" && has_block AGENTS.md && \
|
|
66
|
+
echo "delegation-canary: block in $f and AGENTS.md (remove from $f)"
|
|
67
|
+
done
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Report each finding as a **warning** with the suggested fix (remove redundant
|
|
71
|
+
block from the delegating file or from `AGENTS.md` when not a shared
|
|
72
|
+
carrier). `--fix` may offer to remove the block from the delegating file in
|
|
73
|
+
case (b) (**sensitive** — show diff, confirm per file). `--fix` never removes
|
|
74
|
+
blocks from `AGENTS.md` when it is a shared carrier for
|
|
75
|
+
codex/opencode/delegation.
|
|
76
|
+
|
|
77
|
+
3. **Semantic checks (judgment — report as warnings to review).** These need
|
|
78
|
+
reading, not grepping; surface them for the user to confirm rather than
|
|
79
|
+
auto-fixing:
|
|
80
|
+
- **Stale `current.md`** — does it still match the actual codebase state?
|
|
81
|
+
- **Duplication** — the same fact recorded in more than one file.
|
|
82
|
+
- **Contradictions** — files (or a file and the code) that disagree.
|
|
83
|
+
- **Bloat** — always-loaded files (`current.md`, active-work) grown long, or
|
|
84
|
+
verbose entries that waste tokens; suggest trimming.
|
|
85
|
+
|
|
86
|
+
4. **Report.** Group findings as **errors** (broken links, orphans, stale
|
|
87
|
+
per-branch files) and **warnings** (semantic). For each, name the file and
|
|
88
|
+
the problem.
|
|
89
|
+
|
|
90
|
+
5. **Fix offer.** Offer to fix only safe issues (e.g. remove a dead link, add an
|
|
91
|
+
orphan to `index.md`). Any fix that edits user content (`current.md`,
|
|
92
|
+
`decisions.md`, `domains/*`, …) must be confirmed first — show the diff. For
|
|
93
|
+
stale `current.md` / active-work / `log.md`, suggest `/agent-memory sync`
|
|
94
|
+
rather than editing by hand.
|
|
95
|
+
|
|
96
|
+
`--fix` — with this flag, also offer to **delete stale per-branch
|
|
97
|
+
`active-work/<branch>.md` files** (files whose branch no longer exists) and,
|
|
98
|
+
for **delegation-canary** findings (step 2), offer to remove the redundant
|
|
99
|
+
block from `CLAUDE.md`/`GEMINI.md` that delegate via `@AGENTS.md` (each
|
|
100
|
+
removal sensitive — show diff, confirm). Each deletion is still confirmed one
|
|
101
|
+
by one (it removes a file, so it is sensitive) unless combined with an
|
|
102
|
+
explicit "delete all stale" approval. `--fix` never deletes anything other
|
|
103
|
+
than stale `active-work` files, never touches `TEMPLATE.md`.
|
|
104
|
+
Delegation-canary block removal edits only the agent-memory delimiters in
|
|
105
|
+
`CLAUDE.md`/`GEMINI.md` (with confirmation). For other user content, fallback
|
|
106
|
+
to `sync` or a manual edit.
|
|
107
|
+
|
|
108
|
+
## Notes
|
|
109
|
+
|
|
110
|
+
- This mirrors the "Memory lint" section of `instructions.md`; keep them
|
|
111
|
+
aligned.
|
|
112
|
+
- No `markdownlint` here — Markdown style is the concern of the source repo, not
|
|
113
|
+
of the installed memory in a user's project.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# `/agent-memory sync`
|
|
2
|
+
|
|
3
|
+
Refresh the four files that rot between commands — `current.md`, your branch's
|
|
4
|
+
`active-work/<branch>.md`, `log.md`, and `index.md` — from **actual repo state**
|
|
5
|
+
(`git`) and session context, not chat history. This is the executable form of
|
|
6
|
+
the _During_ / _After_ / _Flush early_ workflow in `instructions.md`.
|
|
7
|
+
|
|
8
|
+
Use it at any checkpoint: end of a task, before a commit, before context
|
|
9
|
+
compaction, or when picking work back up. Safe and idempotent.
|
|
10
|
+
|
|
11
|
+
## Flags
|
|
12
|
+
|
|
13
|
+
- `--auto` — apply all proposed diffs without the per-file `AskQuestion` prompt.
|
|
14
|
+
Use at routine checkpoints (where you would approve everything anyway) to keep
|
|
15
|
+
the flush low-friction; without it, sync is the careful, per-file-confirm form
|
|
16
|
+
suited to the first run or a manual review. `--auto` still shows the diffs in
|
|
17
|
+
the report after applying, and still skips fields for which it has no evidence
|
|
18
|
+
(it never invents progress or log bullets).
|
|
19
|
+
- `--force` — reserved for explicit user override; does not skip the vision
|
|
20
|
+
uncertainty gate below.
|
|
21
|
+
|
|
22
|
+
## Boundary
|
|
23
|
+
|
|
24
|
+
Sync writes only to: `current.md`, `active-work/<branch>.md`, `log.md`, and
|
|
25
|
+
`index.md` (domains/features links and lazy-file links when evidence exists). It
|
|
26
|
+
**never** touches `decisions.md`, `instructions.md`, `domains/*` / `features/*`
|
|
27
|
+
body content, or any file outside `.agents/memory/`. It never deletes anything
|
|
28
|
+
except replacing placeholder lines inside the four target files.
|
|
29
|
+
|
|
30
|
+
Hooks maintain `log.md` session headings and file-path bullets from `git`; sync
|
|
31
|
+
adds semantic bullets, refines summaries/types, and aligns `decisions.md`
|
|
32
|
+
indirectly (sync still does not write `decisions.md` — the agent must). The
|
|
33
|
+
split is the same on every harness — see `instructions.md` → _Harness parity —
|
|
34
|
+
memory contract_.
|
|
35
|
+
|
|
36
|
+
## Steps
|
|
37
|
+
|
|
38
|
+
1. **Guard.** If `.agents/memory/` does not exist, stop and suggest
|
|
39
|
+
`/agent-memory init`.
|
|
40
|
+
|
|
41
|
+
2. **Resolve the branch.** Run `git branch --show-current` (fall back to `local`
|
|
42
|
+
if HEAD is detached or not a git repo). Sanitize every character outside
|
|
43
|
+
`[A-Za-z0-9._-]` to `-`. This is the active-work filename.
|
|
44
|
+
|
|
45
|
+
3. **Ensure the active-work file.** If `active-work/<branch>.md` is missing,
|
|
46
|
+
create it from `active-work/TEMPLATE.md` and set its `Branch:` header to the
|
|
47
|
+
real branch name (never reverse the lossy filename). If it exists, leave the
|
|
48
|
+
header as-is.
|
|
49
|
+
|
|
50
|
+
4. **Gather evidence (read-only, from `git` and memory).**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git log --since="<last-log-date>" --pretty='%h %ad %s' --date=short --no-merges
|
|
54
|
+
git diff --stat <base>..HEAD # base: main/master or origin/<branch>@{u}
|
|
55
|
+
git status --porcelain
|
|
56
|
+
git diff --name-only <last-log-sha>..HEAD 2>/dev/null || true
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Session ID: `AGENT_MEMORY_SESSION_ID`, harness stdin (`session_id` /
|
|
60
|
+
`conversation_id` / `sessionId`), or `current_session_id` from
|
|
61
|
+
`.agents/memory/.hook-sync-state`.
|
|
62
|
+
|
|
63
|
+
For `log.md`, find the **current session** heading:
|
|
64
|
+
`## [YYYY-MM-DD] [session-id] ...` (session-id bracket optional). Append
|
|
65
|
+
bullets under it; open a new heading only for a new session.
|
|
66
|
+
|
|
67
|
+
`<last-log-date>` comes from the newest `## [YYYY-MM-DD]` in `log.md`. If
|
|
68
|
+
empty, use the repo's first commit or `HEAD~20` as a sane default.
|
|
69
|
+
|
|
70
|
+
`<last-log-sha>` is `last_processed_head` from
|
|
71
|
+
`.agents/memory/.hook-sync-state` (written by hooks after each checkpoint).
|
|
72
|
+
If empty, skip the `git diff --name-only <last-log-sha>..HEAD` line — there
|
|
73
|
+
is no prior processed commit to diff from.
|
|
74
|
+
|
|
75
|
+
5. **Vision gate (unless `--auto`).** If `vision.md` does not exist or looks
|
|
76
|
+
stale/ambiguous and docs do not clarify product purpose, **ask the user**
|
|
77
|
+
before creating or rewriting `vision.md`. If you inferred a vision change
|
|
78
|
+
during sync, note it in the report for the user to confirm at session end.
|
|
79
|
+
|
|
80
|
+
6. **Propose updates (one diff per file).** Show each as a unified diff. Unless
|
|
81
|
+
`--auto` is set, confirm via `AskQuestion` before writing — sync touches
|
|
82
|
+
project memory, so the "confirm before editing user content" rule applies.
|
|
83
|
+
Allow approve / skip per file. Under `--auto`, apply all proposed diffs
|
|
84
|
+
without prompting and report them after.
|
|
85
|
+
- **`active-work/<branch>.md`** — fill/refresh _Task_ (infer from branch
|
|
86
|
+
name, user context, `current.md`, recent `log.md`), _Progress_, _Touched
|
|
87
|
+
files_ (from `git diff --name-only`), and _Blockers_. Keep _Notes_ as-is
|
|
88
|
+
unless evidence supports an update. Overwrite only fields the evidence
|
|
89
|
+
supports.
|
|
90
|
+
- **`log.md`** — maintain **one heading per session**:
|
|
91
|
+
`## [YYYY-MM-DD] [session-id] [type] short summary` with `-` bullets for
|
|
92
|
+
concrete changes this session. Hooks may have appended ``- `path` ``
|
|
93
|
+
bullets already — add semantic bullets; refine type/summary; dedupe. Oldest
|
|
94
|
+
first / newest at bottom.
|
|
95
|
+
- **`current.md`** — refresh _Version / milestone_, _Done_, _In progress_
|
|
96
|
+
(list each open `active-work/*.md` with a one-line branch goal), from
|
|
97
|
+
evidence plus active-work files. Move completed branch work to _Done_ when
|
|
98
|
+
the active-work file is gone. _Next steps_ **only** if an explicit
|
|
99
|
+
roadmap/plan exists — remove or leave placeholder otherwise; never infer.
|
|
100
|
+
- **`index.md`** — for every existing lazy file (`vision.md`,
|
|
101
|
+
`architecture.md`, `patterns.md`, etc.) and every `domains/*.md` /
|
|
102
|
+
`features/*.md` not yet listed, add a link (replace `_None yet._` the first
|
|
103
|
+
time). Remove links to deleted files. Do not remove valid entries.
|
|
104
|
+
|
|
105
|
+
7. **Apply approved diffs** only, with `Edit`/`Write` scoped to
|
|
106
|
+
`.agents/memory/**`. Skip anything the user declined.
|
|
107
|
+
|
|
108
|
+
8. **Report.** List each file: updated, skipped, or unchanged — and one line on
|
|
109
|
+
what the next agent should read to continue (the branch's active-work file
|
|
110
|
+
plus `current.md`). If `vision.md` may need user input, say so explicitly.
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
- Sync is **additive and conservative** for `current.md` facts — flag staleness
|
|
115
|
+
for `lint` instead of silent deletion.
|
|
116
|
+
- If `git` is unavailable, fall back to reading recently modified files under
|
|
117
|
+
the project and ask the user to confirm what changed.
|
|
118
|
+
- Remind the agent to update `decisions.md`, `architecture.md`, and
|
|
119
|
+
`patterns.md` when their triggers fired — sync does not write those files.
|
|
120
|
+
- Mirrors the _Flush early_ section of `instructions.md`; keep them aligned.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# `/agent-memory update`
|
|
2
|
+
|
|
3
|
+
Migrate an existing `.agents/memory/` to the latest structure from this skill's
|
|
4
|
+
`vendor/` — **without ever altering the project's memory content.** It also
|
|
5
|
+
refreshes the memory **block** inside harness instruction files, **only**
|
|
6
|
+
between the `<!-- <agent-memory> -->` … `<!-- </agent-memory> -->` delimiters
|
|
7
|
+
(or legacy plain `<agent-memory>` … `</agent-memory>` tags, which `update`
|
|
8
|
+
migrates to the comment form). Hook refresh is **instructions only** (user-run
|
|
9
|
+
installer).
|
|
10
|
+
|
|
11
|
+
## Boundary (read before doing anything)
|
|
12
|
+
|
|
13
|
+
- **Project memory (NEVER touch):** `current.md`, `active-work/*`,
|
|
14
|
+
`decisions.md`, `log.md`, `domains/*`, `features/*`, and any user-authored
|
|
15
|
+
content.
|
|
16
|
+
- **Scaffolding (may change, see rules):** `instructions.md`, the structural
|
|
17
|
+
sections of `index.md`, the `.version` file, brand-new core files, and the
|
|
18
|
+
agent-memory block in harness instruction files.
|
|
19
|
+
- **Outside the block (NEVER touch):** any content in instruction files outside
|
|
20
|
+
the agent-memory delimiters (`<!-- <agent-memory> -->` …
|
|
21
|
+
`<!-- </agent-memory> -->`, or legacy plain tags). For
|
|
22
|
+
`.cursor/rules/agent-memory.mdc`, preserve YAML frontmatter — refresh only the
|
|
23
|
+
delimited body.
|
|
24
|
+
|
|
25
|
+
## Canonical memory block
|
|
26
|
+
|
|
27
|
+
The exact block `init` writes and `update` refreshes is defined in
|
|
28
|
+
[`references/agent-block.md`](./agent-block.md) — read it from there; do not
|
|
29
|
+
inline the block text here. Each wired file's block is **replaced verbatim**
|
|
30
|
+
with that canonical block during update (single source of truth).
|
|
31
|
+
|
|
32
|
+
**Instruction file targets** (same as `init`; see `references/init.md` for
|
|
33
|
+
carrier rules):
|
|
34
|
+
|
|
35
|
+
| File | Notes |
|
|
36
|
+
| --------------------------------------------------- | ------------------------------------------------------- |
|
|
37
|
+
| `AGENTS.md`, `CLAUDE.md`, `GEMINI.md` | Root agent files |
|
|
38
|
+
| `.cursor/rules/agent-memory.mdc` | Compare body only; keep `alwaysApply: true` frontmatter |
|
|
39
|
+
| `.github/instructions/agent-memory.instructions.md` | Copilot path-specific; keep `applyTo: "**"` frontmatter |
|
|
40
|
+
|
|
41
|
+
## Steps
|
|
42
|
+
|
|
43
|
+
1. **Guard.** If `.agents/memory/` does not exist, stop and suggest
|
|
44
|
+
`/agent-memory init`.
|
|
45
|
+
|
|
46
|
+
2. **Read versions.** Installed = `.agents/memory/.version`. Latest = the newest
|
|
47
|
+
version section in this skill's `vendor/UPDATE.md`. If equal, still run step 5
|
|
48
|
+
(refresh instruction blocks) before reporting "already up to date".
|
|
49
|
+
|
|
50
|
+
3. **Select migrations.** Read this skill's `vendor/UPDATE.md` (see `SKILL.md` →
|
|
51
|
+
Repository source) and collect every entry with a version greater than the
|
|
52
|
+
installed version, up to the latest. Each change is tagged `safe` or
|
|
53
|
+
`sensitive`. **Skip** any item marked **superseded** (e.g. a later version
|
|
54
|
+
says it supersedes an earlier sensitive step) — do not apply superseded
|
|
55
|
+
migrations.
|
|
56
|
+
|
|
57
|
+
4. **Apply, conservatively:**
|
|
58
|
+
- **Automatic (no prompt):**
|
|
59
|
+
- Create new core files that are missing.
|
|
60
|
+
- **Always confirm with a diff before applying:**
|
|
61
|
+
- `instructions.md` when the installed copy differs from the skill's
|
|
62
|
+
current `vendor/memory/instructions.md` (identical → nothing to do).
|
|
63
|
+
- Any change to a file that can hold user content — including `index.md`
|
|
64
|
+
(merge structural sections, **preserve the user's Domains/Features
|
|
65
|
+
lists**).
|
|
66
|
+
- Any rename, move, or deletion.
|
|
67
|
+
- **Skip superseded items** — e.g. do **not** agent-merge `.cursor/hooks.json`
|
|
68
|
+
for `afterFileEdit` when `UPDATE.md` marks that 0.0.10 sensitive step as
|
|
69
|
+
superseded (hooks refresh is user-run installer only).
|
|
70
|
+
- Present each sensitive change as a unified diff and ask the user to
|
|
71
|
+
approve, skip, or abort. Apply only what is approved.
|
|
72
|
+
|
|
73
|
+
5. **Refresh instruction blocks.** Read the canonical block from
|
|
74
|
+
[`references/agent-block.md`](./agent-block.md). For **each wired target**
|
|
75
|
+
that exists at the project root (table above), decide what changed:
|
|
76
|
+
- **A delimited block exists** (`<!-- <agent-memory> -->` …
|
|
77
|
+
`<!-- </agent-memory> -->`, or legacy plain `<agent-memory>` …
|
|
78
|
+
`</agent-memory>`): compare its current text (between the delimiters,
|
|
79
|
+
inclusive) against the canonical block, byte-for-byte. **Identical → skip
|
|
80
|
+
(already current).** Different → replace block content with the canonical
|
|
81
|
+
block (comment delimiters). For `.mdc`, replace only the delimited body;
|
|
82
|
+
preserve existing frontmatter (or apply the canonical frontmatter from
|
|
83
|
+
`agent-block.md` — `alwaysApply: true` for Cursor, `applyTo: "**"` for
|
|
84
|
+
Copilot — if missing). **Sensitive** — show the unified diff, confirm
|
|
85
|
+
first. Never touch anything outside the delimiters.
|
|
86
|
+
- **No block yet, but a legacy `## Agent Memory` section exists** (installed
|
|
87
|
+
by an older `init` without delimiters): replace that section with the
|
|
88
|
+
canonical block (delimiters and content). **Sensitive** — show the diff,
|
|
89
|
+
confirm first.
|
|
90
|
+
- **No block and no legacy section:** skip (the file was never wired by
|
|
91
|
+
`init`). Do not create a block here — that is `init`'s job. Mention it in
|
|
92
|
+
the report so the user can run `init` if they want the file wired.
|
|
93
|
+
|
|
94
|
+
**Migration — cursor/copilot from `AGENTS.md` only** (sensitive, with diff):
|
|
95
|
+
if `.cursor/rules/agent-memory.mdc` or
|
|
96
|
+
`.github/instructions/agent-memory.instructions.md` is missing but the block
|
|
97
|
+
lives in `AGENTS.md`, and no codex/opencode/claude-via-delegation needs that
|
|
98
|
+
carrier, offer to **move** the block from `AGENTS.md` to the harness native
|
|
99
|
+
file (create native if needed).
|
|
100
|
+
|
|
101
|
+
**Migration — delegation canary** (sensitive, with diff): if `CLAUDE.md` or
|
|
102
|
+
`GEMINI.md` contains the block **and** `@AGENTS.md` (or `@./AGENTS.md`) while
|
|
103
|
+
`AGENTS.md` also contains the block, offer to **remove** the block from the
|
|
104
|
+
file that delegates (double injection from older installs).
|
|
105
|
+
|
|
106
|
+
Apply only what is approved. If every wired file's block is already
|
|
107
|
+
byte-identical to the canonical block, report "instruction blocks already
|
|
108
|
+
current" and move on.
|
|
109
|
+
|
|
110
|
+
6. **Instruct hook refresh.** Follow
|
|
111
|
+
[`references/install-hooks.md`](./install-hooks.md) → **Detecting installed
|
|
112
|
+
harnesses** and for each installed harness print the user-run refresh
|
|
113
|
+
commands (step 4 of that reference). **Do not** copy scripts or merge
|
|
114
|
+
configs. Run even when the installed version already equals the latest (hook
|
|
115
|
+
scripts may have changed without a memory migration). Report which harnesses
|
|
116
|
+
need a user refresh and which were skipped.
|
|
117
|
+
|
|
118
|
+
7. **Finalize.** Update `.agents/memory/.version` to the latest. Append one
|
|
119
|
+
entry to `log.md`:
|
|
120
|
+
`## [YYYY-MM-DD] chore | agent-memory update to <version>`.
|
|
121
|
+
|
|
122
|
+
8. **Report.** Summarize what was applied automatically, what was confirmed, and
|
|
123
|
+
what was skipped — including which instruction files had their block
|
|
124
|
+
refreshed, which had a legacy section migrated, delegation-canary removals
|
|
125
|
+
offered/applied, which files were left untouched, and which harness hook
|
|
126
|
+
refresh commands were printed.
|
|
127
|
+
|
|
128
|
+
For Cursor, note that `.cursor/rules/agent-memory.mdc` is the **context
|
|
129
|
+
layer** (always-on rules) and hooks are the **checkpoint layer** — both are
|
|
130
|
+
recommended after `init cursor`. If `.cursor/hooks/agent-memory-sync.sh`
|
|
131
|
+
exists but `.cursor/rules/agent-memory.mdc` is missing, suggest
|
|
132
|
+
`/agent-memory init cursor` to add the context layer (likewise for Copilot:
|
|
133
|
+
if `.github/hooks/` is wired but
|
|
134
|
+
`.github/instructions/agent-memory.instructions.md` is missing).
|
|
135
|
+
|
|
136
|
+
## Gotchas
|
|
137
|
+
|
|
138
|
+
- Never resolve a sensitive change silently. When in doubt, treat it as
|
|
139
|
+
sensitive and confirm.
|
|
140
|
+
- The block refresh edits only between the agent-memory delimiters (comment form
|
|
141
|
+
or legacy plain tags). If no delimiters are found, do **not** guess where the
|
|
142
|
+
block starts — treat it as the legacy-section case above, or skip and report.
|
|
143
|
+
- The skeleton source of truth is this skill's `vendor/memory/`;
|
|
144
|
+
`vendor/UPDATE.md` only describes _how_ to migrate between versions, not the
|
|
145
|
+
file contents.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Agent Memory
|
|
2
|
+
|
|
3
|
+
A local **Workspace Memory** method for AI coding agents — Claude Code, Cursor,
|
|
4
|
+
Codex, OpenCode, Gemini, and others.
|
|
5
|
+
|
|
6
|
+
The Memory is a small set of versioned Markdown files in `.agents/memory/` that
|
|
7
|
+
act as the shared source of truth between humans and agents. It separates
|
|
8
|
+
**permanent knowledge** (architecture, decisions, patterns) from **operational
|
|
9
|
+
memory** (current state, in-flight work), so any agent can pick up the project
|
|
10
|
+
without relying on chat history.
|
|
11
|
+
|
|
12
|
+
The method borrows the _discipline_ of the [llm-wiki pattern][llm-wiki] (an
|
|
13
|
+
index, a chronological log, periodic linting, small cross-referenced files) but
|
|
14
|
+
its identity is **project memory**, not external-source ingestion.
|
|
15
|
+
|
|
16
|
+
[llm-wiki]: https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f
|
|
17
|
+
|
|
18
|
+
## When to use it
|
|
19
|
+
|
|
20
|
+
Any project where AI agents do meaningful work across multiple sessions, and
|
|
21
|
+
where humans and agents need a single, trustworthy account of "where things
|
|
22
|
+
stand" and "why".
|
|
23
|
+
|
|
24
|
+
## How agents use it
|
|
25
|
+
|
|
26
|
+
Agents **read AND write** the memory — it is not chat history.
|
|
27
|
+
|
|
28
|
+
- **Before a task:** read `index.md`, `current.md`, and the current branch's
|
|
29
|
+
`active-work/<branch>.md`.
|
|
30
|
+
- **During:** keep that `active-work` file current (task, progress, touched
|
|
31
|
+
files, blockers); append events to `log.md`; record decisions in
|
|
32
|
+
`decisions.md`.
|
|
33
|
+
- **After / at checkpoints:** refresh `current.md` when project state changed;
|
|
34
|
+
run `/agent-memory sync` to flush `current.md`, `active-work`, `log.md`, and
|
|
35
|
+
`index.md` from repo state; delete the branch's `active-work` file when it
|
|
36
|
+
merges.
|
|
37
|
+
|
|
38
|
+
The full workflow and multi-developer rules live in
|
|
39
|
+
[`memory/instructions.md`](./memory/instructions.md) — the canonical method file
|
|
40
|
+
agents load first.
|
|
41
|
+
|
|
42
|
+
## What's inside the memory (`.agents/memory/`)
|
|
43
|
+
|
|
44
|
+
| File | Role |
|
|
45
|
+
| ----------------- | --------------------------------------- |
|
|
46
|
+
| `instructions.md` | The canonical method (read this first). |
|
|
47
|
+
| `index.md` | Map of the Memory. |
|
|
48
|
+
| `current.md` | Shared, durable project state. |
|
|
49
|
+
| `active-work/` | Per-branch ephemeral task scratchpad. |
|
|
50
|
+
| `decisions.md` | Decisions and their reasoning. |
|
|
51
|
+
| `log.md` | Chronological activity log. |
|
|
52
|
+
| `.gitignore` | Ignores hook-local state (not content). |
|
|
53
|
+
|
|
54
|
+
Other files (`vision.md`, `architecture.md`, `patterns.md`, `mistakes.md`,
|
|
55
|
+
`known-issues.md`, `domains/*`, `features/*`) are created **on demand** — only
|
|
56
|
+
when there is real content to record. See `memory/instructions.md` for the full
|
|
57
|
+
workflow and the multi-developer rules.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
### Recommended — via the skill
|
|
62
|
+
|
|
63
|
+
Install the `agent-memory` skill
|
|
64
|
+
([skills.sh](https://www.skills.sh/diegoos/agent-memory/agent-memory) /
|
|
65
|
+
[`SKILL.md`](../SKILL.md)) into your agent's skills directory, then run:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
/agent-memory init # auto-detect harnesses from project markers
|
|
69
|
+
/agent-memory init cursor # Cursor only (.cursor/ must exist)
|
|
70
|
+
/agent-memory init claude # Claude Code only
|
|
71
|
+
/agent-memory init codex # Codex only
|
|
72
|
+
/agent-memory init opencode # OpenCode only
|
|
73
|
+
/agent-memory init copilot # Copilot only
|
|
74
|
+
/agent-memory init gemini # Gemini only
|
|
75
|
+
/agent-memory bootstrap # optional: analyze the project and fill the memory
|
|
76
|
+
/agent-memory install hooks <harness> # print how to install/refresh hooks
|
|
77
|
+
/agent-memory update # update scaffolding + refresh instruction blocks
|
|
78
|
+
/agent-memory sync # keep current.md / active-work / log.md / index.md fresh
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Without a harness name, `init` **auto-detects** harnesses from project markers
|
|
82
|
+
and wires each harness's **native instruction file** (`.cursor/rules/*.mdc` for
|
|
83
|
+
Cursor, `.github/instructions/*.instructions.md` for Copilot, or the harness's
|
|
84
|
+
agent file for the rest), asking you when detection is inconclusive. It never
|
|
85
|
+
creates `.cursor/`, `.claude/`, `.github/`, etc. by default — those must already
|
|
86
|
+
exist, unless you explicitly ask `init` to create them. Use `init <harness>`
|
|
87
|
+
when you know which agent you use.
|
|
88
|
+
|
|
89
|
+
The skill installs from the vendored skeleton next to this file (`memory/`) and
|
|
90
|
+
also handles `sync`, `update`, `lint`, and `help`. See [`SKILL.md`](../SKILL.md).
|
|
91
|
+
Hooks are **user-installed** (the skill only prints commands) — see the
|
|
92
|
+
[hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
|
|
93
|
+
|
|
94
|
+
### Manual
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
mkdir -p .agents
|
|
98
|
+
cp -R memory .agents/memory
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Commit `.agents/memory/` to Git, then attach the Memory to your agent file(s) by
|
|
102
|
+
pasting the canonical agent-memory block into `AGENTS.md`, `CLAUDE.md`,
|
|
103
|
+
`GEMINI.md`, or any agent instructions file. The instructions stay in a single
|
|
104
|
+
source of truth (`.agents/memory/instructions.md`); the block only points to it.
|
|
105
|
+
|
|
106
|
+
The block is the **single source of truth** at
|
|
107
|
+
[`../references/agent-block.md`](../references/agent-block.md)
|
|
108
|
+
— copy it verbatim from there. It is wrapped in `<!-- <agent-memory> -->` …
|
|
109
|
+
`<!-- </agent-memory> -->` HTML comments so `/agent-memory update` can refresh
|
|
110
|
+
**only** that block later (comments are invisible in rendered Markdown); it
|
|
111
|
+
tells the agent to **Read** `instructions.md` and to **write** the memory as it
|
|
112
|
+
works, and adds `@import`, so harnesses that follow the AGENTS.md `@import`
|
|
113
|
+
convention (Claude Code, Gemini CLI, Codex) auto-load `instructions.md`. On
|
|
114
|
+
Cursor, run `init cursor` when `.cursor/` exists — it wires
|
|
115
|
+
`.cursor/rules/agent-memory.mdc` (context layer); install hooks separately. On
|
|
116
|
+
Copilot, run `init copilot` then the hooks installer. See
|
|
117
|
+
_Plain-Markdown harnesses_ in `memory/instructions.md`.
|
|
118
|
+
|
|
119
|
+
## Keeping the memory current
|
|
120
|
+
|
|
121
|
+
The memory rots if agents only read it. The agent-memory block tells them to
|
|
122
|
+
write it too, and `/agent-memory sync` is the executable flush at checkpoints.
|
|
123
|
+
|
|
124
|
+
**On Cursor:** `init cursor` wires the **context layer** —
|
|
125
|
+
`.cursor/rules/agent-memory.mdc` (`alwaysApply: true`). Install lifecycle hooks
|
|
126
|
+
separately as the **checkpoint layer**. Run `init` when `.cursor/` already
|
|
127
|
+
exists. See the
|
|
128
|
+
[hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
|
|
129
|
+
|
|
130
|
+
Lifecycle hooks (Cursor, Claude Code, Codex, OpenCode, Copilot, Gemini, plus git
|
|
131
|
+
`pre-commit`) run a deterministic git checkpoint between turns — same
|
|
132
|
+
[hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
|