@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.
Files changed (33) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -0
  3. package/bin/agent-memory.js +496 -0
  4. package/hooks/README.md +292 -0
  5. package/hooks/agent-memory-hooks/agent-memory-common.sh +1020 -0
  6. package/hooks/agent-memory-hooks/agent-memory-session.sh +98 -0
  7. package/hooks/agent-memory-hooks/agent-memory-sync.sh +147 -0
  8. package/hooks/claude-code/settings.json +51 -0
  9. package/hooks/codex/config.toml.snippet +38 -0
  10. package/hooks/codex/hooks.json +51 -0
  11. package/hooks/copilot/agent-memory.json +34 -0
  12. package/hooks/cursor/hooks.json +36 -0
  13. package/hooks/gemini/settings.json +50 -0
  14. package/hooks/git/pre-commit +45 -0
  15. package/hooks/install-hooks.sh +358 -0
  16. package/hooks/opencode/agent-memory.ts +320 -0
  17. package/package.json +22 -0
  18. package/skills/agent-memory/SKILL.md +185 -0
  19. package/skills/agent-memory/references/agent-block.md +115 -0
  20. package/skills/agent-memory/references/bootstrap.md +84 -0
  21. package/skills/agent-memory/references/init.md +211 -0
  22. package/skills/agent-memory/references/install-hooks.md +113 -0
  23. package/skills/agent-memory/references/lint.md +113 -0
  24. package/skills/agent-memory/references/sync.md +120 -0
  25. package/skills/agent-memory/references/update.md +145 -0
  26. package/skills/agent-memory/vendor/README.md +132 -0
  27. package/skills/agent-memory/vendor/UPDATE.md +369 -0
  28. package/skills/agent-memory/vendor/memory/active-work/TEMPLATE.md +33 -0
  29. package/skills/agent-memory/vendor/memory/current.md +34 -0
  30. package/skills/agent-memory/vendor/memory/decisions.md +30 -0
  31. package/skills/agent-memory/vendor/memory/index.md +55 -0
  32. package/skills/agent-memory/vendor/memory/instructions.md +340 -0
  33. package/skills/agent-memory/vendor/memory/log.md +38 -0
@@ -0,0 +1,340 @@
1
+ # Agent Memory — Instructions
2
+
3
+ A persistent **Workspace Memory** in `.agents/memory/`, versioned in Git: the
4
+ shared source of truth between humans and agents. Read it before any task and
5
+ keep it current as you work. **Goal: any human or agent can continue the work
6
+ from these files alone — without chat history.**
7
+
8
+ ## Principles
9
+
10
+ - The Memory belongs to the **project**, not the agent; keep it human-readable.
11
+ - Prefer small, focused files; prefer **updating** one over creating one; never
12
+ duplicate content.
13
+ - Record decisions and learnings **as they happen**, not only at the end.
14
+ - Never remove knowledge without an explicit reason; no temporary notes in
15
+ permanent files.
16
+ - Write **concise but context-rich**: one fact per line, no preamble, link
17
+ instead of repeating. Tokens cost — keep the always-loaded files
18
+ (`current.md`, your active-work file) short and push detail into
19
+ load-on-demand files.
20
+
21
+ ## Structure
22
+
23
+ Single root `.agents/memory/`; sub-areas (services, packages, contexts) go under
24
+ `domains/`.
25
+
26
+ **Core files (always present):**
27
+
28
+ | File | Purpose | Update |
29
+ | ----------------- | ------------------------------------------------------ | ---------- |
30
+ | `instructions.md` | This method. | rare |
31
+ | `index.md` | Map of the Memory + loading policy. | occasional |
32
+ | `current.md` | Shared project state (version, done, in progress). | frequent |
33
+ | `active-work/` | Per-branch ephemeral scratchpad (one file per branch). | very freq. |
34
+ | `decisions.md` | Important decisions + the reasoning. | frequent |
35
+ | `log.md` | Chronological activity record (per session). | frequent |
36
+
37
+ **Lazy files** — create only when there is real content, then link from
38
+ `index.md`: `vision.md` (purpose/scope), `architecture.md`
39
+ (components/tech/flows), `patterns.md` (conventions), `mistakes.md` (pitfalls to
40
+ avoid), `known-issues.md` (bugs/limitations/debt), and `domains/*.md` /
41
+ `features/*.md`. Each `domains/*` or `features/*` file: purpose, rules, key
42
+ flows/dependencies, and the related source files.
43
+
44
+ ### Per-branch active work
45
+
46
+ `active-work/` holds one scratchpad **per branch**, so parallel work never
47
+ collides. The current file is `active-work/<branch>.md`, where `<branch>` is the
48
+ branch name (`git branch --show-current`; `local` if none) with every character
49
+ outside `[A-Za-z0-9._-]` replaced by `-` (e.g. `feat/login` → `feat-login.md`).
50
+ On a branch's first task, copy `active-work/TEMPLATE.md` and set its `Branch:`
51
+ header to the real name (so the lossy filename is never reversed). **Delete the
52
+ file when the branch merges** — conflict-free, since no other branch touches it;
53
+ `lint` flags files whose branch is gone.
54
+
55
+ ## Workflow
56
+
57
+ **Before any task:** read `index.md`, `current.md`, and your branch's
58
+ active-work file (create from `active-work/TEMPLATE.md` if missing). Consult on
59
+ demand: `decisions.md`, `log.md`, and the lazy files.
60
+
61
+ **During:** keep your active-work file current; append to the **current
62
+ session's** `log.md` entry; record decisions in `decisions.md`; update lazy
63
+ files when their triggers fire (below).
64
+
65
+ **After:** update `current.md` if project state changed; finalize `decisions.md`
66
+ / `mistakes.md` / `log.md`; keep `index.md` aligned; delete your active-work
67
+ file when the branch merges.
68
+
69
+ **Flush early:** before the context grows long or is compacted, and before
70
+ ending a session, write the essentials to your active-work file and `log.md`.
71
+ The next agent must continue from the files, never from chat history. Run
72
+ `/agent-memory sync` as the executable form of the _During_ / _After_ / _Flush
73
+ early_ steps — it refreshes `current.md`, your branch's active-work file,
74
+ `log.md`, and `index.md` from repo state (`git`) and confirms each change before
75
+ writing. Use `/agent-memory sync --auto` at routine checkpoints to apply all
76
+ proposed diffs without the per-file prompt, keeping the flush low-friction.
77
+
78
+ ### Harness parity — memory contract
79
+
80
+ All supported harnesses (Cursor, Claude Code, Codex, Copilot, Gemini CLI,
81
+ OpenCode) target the **same memory shape**. Shared hook scripts in the
82
+ agent-memory repo (`hooks/agent-memory-hooks/`) define **what** is written;
83
+ harness config only defines **when** checkpoints run. If outcomes differ, treat
84
+ it as a bug — not a harness feature.
85
+
86
+ **Two layers (every harness):**
87
+
88
+ | Layer | Role | Mechanism |
89
+ | -------------- | ------------------------------------ | ---------------------------------- |
90
+ | **Context** | Obligation to read and update memory | Native instruction file (`.mdc`, |
91
+ | | | `*.instructions.md`, agent `*.md`) |
92
+ | **Checkpoint** | Deterministic git + session sync | Lifecycle hooks or OpenCode plugin |
93
+
94
+ **Hooks write (identical outcome everywhere hooks are installed):**
95
+
96
+ | Target | Content | When |
97
+ | -------------------------------- | --------------------------------------------------- | ------------------------- |
98
+ | `active-work/` → _Touched files_ | Session-cumulative repo paths (`git` + stdin on | Between-turn + end-of- |
99
+ | | harnesses with post-tool events) | turn checkpoints |
100
+ | `active-work/` → _Task_ stub | Branch-name placeholder when still generic | Same checkpoints |
101
+ | `log.md` → session heading | `## [YYYY-MM-DD] [session-id]` (see OpenCode below) | Session start / first |
102
+ | | | checkpoint of the period |
103
+ | `log.md` → file-path bullets | ``- `path` `` or `changed N files…` summary (>8) | **Full checkpoints only** |
104
+ | | — evidence from `git`, never semantic text | (end-of-turn, compact, |
105
+ | | | pre-commit) |
106
+ | `current.md` → _In progress_ | Links to open `active-work/*.md` + one-line goal | Session start |
107
+ | `.hook-sync-state` | Session IDs, dedupe sets (not committed) | Internal |
108
+
109
+ Hooks **never** write: semantic `log.md` bullets, `[type]` / summary in
110
+ headings, `decisions.md`, `active-work` _Progress_ / _Blockers_ / _Notes_,
111
+ `current.md` _Done_ / _Next steps_, lazy file bodies, or `index.md` link prose.
112
+
113
+ **Agent (or `/agent-memory sync`) writes — same on every harness:**
114
+
115
+ | Target | Content |
116
+ | -------------- | --------------------------------------------------------- |
117
+ | `log.md` | Semantic bullets; `[type]` and session summary in |
118
+ | | heading when the goal is clear |
119
+ | `active-work/` | **Task** (meaning), **Progress**, **Blockers**, **Notes** |
120
+ | `decisions.md` | ADR entries on every design/architecture change |
121
+ | `current.md` | _Done_, _Next steps_ (when evidence exists), milestone |
122
+ | `index.md` | Lazy and domain/feature links |
123
+ | Lazy files | Bodies when triggers fire (`architecture.md`, etc.) |
124
+
125
+ `/agent-memory sync` refreshes `current.md`, active-work, `log.md`, and
126
+ `index.md` from `git` — it does **not** replace the agent's obligation to update
127
+ `decisions.md` or lazy-file bodies.
128
+
129
+ **Evidence vs meaning (always split this way):**
130
+
131
+ ```md
132
+ ## [2026-07-05] [abc-123] [feat] interview list page
133
+
134
+ - changed 12 files (see active-work Touched files) ← hook (git evidence)
135
+ - `src/app/tag/entrevista/page.tsx` ← hook (≤8 new paths)
136
+ - added canonical /tag/entrevista/ route ← agent (semantic)
137
+ - recorded URL decision in decisions.md ← agent (semantic)
138
+ ```
139
+
140
+ **Harness timing (same writes, different schedule):**
141
+
142
+ | Checkpoint | Cursor | Claude / Codex | Copilot / Gemini | OpenCode |
143
+ | -------------- | ------------------ | -------------- | ---------------- | ----------------- |
144
+ | Session start | native | native | native | first idle / sync |
145
+ | Mid-turn paths | postToolUse + | PostToolUse | postToolUse | — (git at idle) |
146
+ | | afterFileEdit | | | |
147
+ | End of turn | afterAgentResponse | Stop | agentStop | session.idle |
148
+ | Before compact | preCompact | PreCompact | preCompact | compacting |
149
+
150
+ **OpenCode heading rule:** `ses_*` IDs rotate often. Hooks coalesce to **one
151
+ `log.md` heading per calendar day** (bound in `.hook-sync-state` as
152
+ `opencode_log_heading_id`). Bullets and semantic text still append under that
153
+ single heading — same contract, different session-key granularity.
154
+
155
+ **Without hooks:** run `/agent-memory sync` at the same checkpoints; the agent
156
+ must supply both evidence (from `git`) and semantic bullets manually.
157
+
158
+ See the [hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md)
159
+ for per-host wiring. Do not duplicate this contract elsewhere — link to this
160
+ section.
161
+
162
+ ### Obligations by file
163
+
164
+ #### `log.md` — session log (hooks + agent)
165
+
166
+ See **Harness parity — memory contract** above. Hooks maintain the session
167
+ **heading** and append **file-path bullets** from `git` (evidence only). You add
168
+ semantic bullets (fixes, features, outcomes) and refine the heading
169
+ type/summary.
170
+
171
+ - **One heading per session** (date + session ID). OpenCode: **one heading per
172
+ calendar day** when `ses_*` IDs rotate (same bullets, coalesced key).
173
+ - Hooks open `## [YYYY-MM-DD] [session-id]` on session start or first
174
+ checkpoint; you add `[type]` and a one-line summary when the session goal is
175
+ clear.
176
+ - Append your bullets under the same heading — do not open a new heading per
177
+ checkpoint.
178
+ - Session ID: `AGENT_MEMORY_SESSION_ID` (from sessionStart `env`), harness stdin
179
+ (`session_id` / `conversation_id`), or `.hook-sync-state`.
180
+
181
+ #### `decisions.md` — required; update when decisions change
182
+
183
+ **You MUST** append an ADR-style entry when you **make, confirm, or change** a
184
+ design, architecture, or convention choice (see `decisions.md`). When you
185
+ reverse or supersede a decision, add a new entry that references the old one. Do
186
+ not rely on chat or `log.md` alone.
187
+
188
+ #### `active-work/<branch>.md` — hooks + agent
189
+
190
+ - Hooks: ensure the file exists, refresh _Touched files_ from `git`, and seed
191
+ _Task_ from the branch name when still a placeholder.
192
+ - **You:** refine **Task** from branch + request + `log.md`; keep **Progress**,
193
+ **Blockers**, and **Notes** current.
194
+
195
+ #### `current.md` — shared snapshot
196
+
197
+ - **In progress:** hooks refresh this list on **session start** from open
198
+ `active-work/*.md`; you refine summaries when branch goals change.
199
+ - **Done:** when a branch merges and its active-work file is removed, add a
200
+ one-line summary of what landed here.
201
+ - **Next steps:** **only** when an explicit roadmap or user-recorded plan exists
202
+ in the project — never infer or invent upcoming work.
203
+
204
+ #### `index.md` — keep the map aligned
205
+
206
+ Whenever you create, rename, or delete a lazy file or a `domains/*` /
207
+ `features/*` file, update the matching section in `index.md` (add link, remove
208
+ stale link). `/agent-memory sync` can add missing domain/feature links from
209
+ `git`, but you must maintain lazy-file links and remove dead entries.
210
+
211
+ #### `vision.md` — ask when uncertain
212
+
213
+ During `init`, `bootstrap`, or `sync` (without `--force` / `--auto`): if product
214
+ purpose or scope is unclear from existing docs, **ask the user** before writing
215
+ or changing `vision.md`. If vision may need updating after your session, tell
216
+ the user at the end — do not silently rewrite goals.
217
+
218
+ #### `architecture.md` — update on structural change
219
+
220
+ Create or update when any of these occur:
221
+
222
+ - Major dependency or runtime version change (language, framework, DB, Node,
223
+ etc.).
224
+ - New service, package, or top-level module; removal or merge of one.
225
+ - Page/app routing or layout architecture change.
226
+ - New external integration or deployment topology change.
227
+
228
+ Keep components, stack, and key flows accurate; link from `index.md`.
229
+
230
+ #### `patterns.md` — update on convention change
231
+
232
+ Create or update when coding conventions change or when you establish patterns
233
+ that should hold across the repo. Stay aligned with `AGENTS.md`, `CLAUDE.md`,
234
+ `GEMINI.md`, and project linters — record project-specific rules here, do not
235
+ duplicate the full agent files.
236
+
237
+ Triggers: new error-handling pattern, API client pattern, test layout, naming
238
+ scheme, or anything you would want the next agent to follow consistently.
239
+
240
+ ### Plain-Markdown harnesses (Cursor, for example)
241
+
242
+ Some harnesses treat `AGENTS.md` as plain Markdown and do **not** honor
243
+ `@import` — in Cursor, `@.agents/memory/instructions.md` in the agent-memory
244
+ block is a no-op. `AGENTS.md` may also fail to auto-inject (known Cursor
245
+ regression: it can appear as "requestable" instead of "always applied"), so an
246
+ `AGENTS.md`-only block may never reach the model.
247
+
248
+ **On Cursor:** run `/agent-memory init cursor` when `.cursor/` already exists.
249
+ `init` creates `.cursor/rules/agent-memory.mdc` with `alwaysApply: true` — this
250
+ is the **context layer** (always-on rules that inject the agent-memory
251
+ workflow). Install lifecycle hooks (checkpoint layer) with the user-run
252
+ installer — `/agent-memory install hooks cursor` **prints** the `npx` / shell
253
+ commands; run them yourself (or use `init cursor` for the printed instructions
254
+ on first setup). Hooks keep `active-work/` (session-cumulative _Touched files_,
255
+ Task stub), `log.md` (session heading; file-path bullets on full checkpoints
256
+ only), and `current.md` _In progress_ on session start — you own **semantic**
257
+ log text, Task meaning, `decisions.md`, _Done_, and `index.md`. See the
258
+ [hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
259
+
260
+ **Context vs checkpoint:** `.mdc` puts the obligation to Read `instructions.md`
261
+ into every session context; hooks run deterministic git checkpoints without an
262
+ LLM. Both are recommended on Cursor — neither replaces the other.
263
+
264
+ If you are on Cursor and have not yet Read `instructions.md` in the current
265
+ session, Read it now before continuing. Harnesses that honor `@import` (Claude
266
+ Code, Gemini CLI, Codex) get `instructions.md` auto-loaded via their agent files
267
+ and need no `.mdc`.
268
+
269
+ ## Multi-developer rules
270
+
271
+ - **`current.md`** is shared/global; change it in the PR that changes project
272
+ state. Conflicts are rare, resolved like any doc.
273
+ - **`active-work/`** is per-branch — zero conflicts, no reset ritual; delete on
274
+ merge (see above).
275
+ - **`log.md` / `decisions.md`** are append-only, **oldest first / newest at the
276
+ bottom** (appending is safe; recent entries come out with `tail`). On
277
+ conflict, **keep both**.
278
+
279
+ ## Searching the log
280
+
281
+ `log.md` and `decisions.md` have parseable headers, so `grep` suffices:
282
+
283
+ > When available, use ripgrep (`rg`) instead of `grep` for better performance.
284
+ > To check if you have ripgrep installed, run `rg --version`.
285
+
286
+ ```bash
287
+ grep "^## \[" log.md | tail -5 # last 5 session headings
288
+ grep "^## \[2026-06" log.md # by date / month
289
+ grep "^## \[.*\] \[fix\]" log.md # by type tag
290
+ grep -A5 "^## \[2026-06-20\]" log.md # heading + bullets
291
+ ```
292
+
293
+ If you have ripgrep installed, you can use the following commands instead:
294
+
295
+ ```bash
296
+ rg "^## \[" log.md | tail -5 # last 5 session headings
297
+ rg "^## \[2026-06" log.md # by date / month
298
+ rg "^## \[.*\] \[fix\]" log.md # by type tag
299
+ rg -A5 "^## \[2026-06-20\]" log.md # heading + bullets
300
+ ```
301
+
302
+ ## Memory lint (anti-rot)
303
+
304
+ Run on request or at PR review — an out-of-date Memory is worse than none.
305
+ Check: contradictions with the code; stale `current.md`; orphaned `domains/*` /
306
+ `features/*`; stale per-branch files (branch gone); broken cross-references;
307
+ duplication; bloat (trim or move detail out of the always-loaded files). Partly
308
+ mechanizable (run from `.agents/memory/`):
309
+
310
+ ```bash
311
+ # Broken cross-references
312
+ grep -rhoE '\]\(\./[^)]+\)' . | sed -E 's/^\]\(\.\/([^)]+)\)$/\1/' \
313
+ | sort -u | while read -r f; do test -e "$f" || echo "missing: $f"; done
314
+ # Orphaned domains/features (not linked from index.md)
315
+ find domains features -name '*.md' 2>/dev/null | while read -r f; do
316
+ grep -q "$(basename "$f")" index.md || echo "orphan: $f"; done
317
+ # Stale per-branch files (skipped if git lists no branches)
318
+ branches=$(git branch --format='%(refname:short)' | sed 's#[^A-Za-z0-9._-]#-#g')
319
+ [ -n "$branches" ] && find active-work -name '*.md' ! -name 'TEMPLATE.md' 2>/dev/null | while read -r f; do
320
+ printf '%s\n' "$branches" | grep -qx "$(basename "$f" .md)" || echo "stale: $f"
321
+ done
322
+ ```
323
+
324
+ ## Git commit rules for the memory
325
+
326
+ The pre-commit hook runs an **evidence** checkpoint (touched files, file-path
327
+ `log.md` bullets from `git`). Run **`/agent-memory sync`** before committing so
328
+ semantic memory (progress, decisions, log meaning) stays current. Commit memory
329
+ changes with the rest of the repo, using the project's commit message rules (50
330
+ characters for the title when practical).
331
+
332
+ Example:
333
+
334
+ ```text
335
+ chore(memory): update memory on [CONCISE DESCRIPTION OF THE CHANGES]
336
+ ```
337
+
338
+ ## When in doubt
339
+
340
+ Prioritize: `current.md`, your active-work file, `log.md`, `decisions.md`.
@@ -0,0 +1,38 @@
1
+ # Log
2
+
3
+ Chronological record of relevant activity. Oldest first — append new entries at
4
+ the **bottom** (the most recent come out with `tail`). On merge conflicts, keep
5
+ both.
6
+
7
+ ## Format (one heading per date + session)
8
+
9
+ Each session gets **one** heading. Append concise bullets under it as work
10
+ happens — do not create a new heading for every checkpoint.
11
+
12
+ ```md
13
+ ## [YYYY-MM-DD] [session-id] [type] short session summary
14
+
15
+ - fixed bug X that breaks marketing pages
16
+ - implemented rate limit logic in `lib/rate-limit.ts`
17
+ ```
18
+
19
+ - **Date** — `YYYY-MM-DD` (session start date).
20
+ - **Session ID** — harness session/conversation ID when available (from
21
+ `AGENT_MEMORY_SESSION_ID`, or omit the bracket if unknown).
22
+ - **Type** — one of: `feat`, `fix`, `chore`, `review`, `docs`, `refactor`,
23
+ `test`, `perf`, `security`, `release`, `ingest`, `improve`. Hooks do **not**
24
+ invent a type or summary — you add them when the session goal is clear.
25
+ - **Summary** — one line describing the session's purpose (not a file count).
26
+ Hooks never write checkpoint lines or file counts in the heading.
27
+ - **Bullets** — hooks append ``- `path/to/file` `` from `git` (once per file per
28
+ session). You append semantic bullets (fixes, features, outcomes) during work
29
+ and at checkpoints.
30
+
31
+ To continue an existing session, **append bullets** under its heading; only open
32
+ a new heading for a new session (new conversation / new session ID). **OpenCode:**
33
+ when `ses_*` IDs change within the same calendar day, keep appending under the
34
+ day's bound heading — do not start a new section per idle event.
35
+
36
+ ---
37
+
38
+ _No entries yet._