@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,185 @@
1
+ ---
2
+ name: agent-memory
3
+ description: >-
4
+ Orchestrates the local agent-memory Workspace Memory in `.agents/memory/`. Use
5
+ ONLY when the user explicitly runs the `/agent-memory` command with a
6
+ subcommand — `init` (create the memory structure; wire the harness-native
7
+ instruction file — `init` auto-detects harnesses from project markers, or
8
+ `init cursor` / `init claude` / `init codex` / `init opencode` / `init
9
+ copilot` / `init gemini` for one harness; prints manual hook-install
10
+ instructions), `install hooks` (print how to install or refresh lifecycle
11
+ hooks for one harness when memory already exists — does not copy scripts),
12
+ `update` (migrate an existing memory to the latest structure without project
13
+ memory, refresh the agent-memory block in harness instruction files, and
14
+ instruct the user to refresh installed harness hooks), `bootstrap` (analyze
15
+ the project and populate the memory), `sync` (refresh `current.md`, the
16
+ branch's `active-work/<branch>.md`, `log.md`, and `index.md` from repo state;
17
+ accepts `--auto` to apply all proposed diffs without the per-file prompt),
18
+ `lint` (check the memory for broken links, orphan files, and consistency
19
+ problems; accepts `--fix` to also delete stale per-branch `active-work`
20
+ files), or `help` (list the commands and how to use them). Never trigger
21
+ automatically; this skill must be invoked on demand only.
22
+ metadata:
23
+ invocation: manual
24
+ version: '0.0.13'
25
+ compatibility: >-
26
+ Works offline from the skill package vendor skeleton. Hook installation is
27
+ user-run (shell script or npx CLI), not performed by this skill.
28
+ allowed-tools: >-
29
+ Read Grep Glob Task Edit(.agents/memory/**) Write(.agents/memory/**)
30
+ Edit(AGENTS.md) Edit(CLAUDE.md) Edit(GEMINI.md) Write(AGENTS.md)
31
+ Write(CLAUDE.md) Write(GEMINI.md) Edit(.cursor/rules/agent-memory.mdc)
32
+ Write(.cursor/rules/agent-memory.mdc)
33
+ Edit(.github/instructions/agent-memory.instructions.md)
34
+ Write(.github/instructions/agent-memory.instructions.md)
35
+ Bash(git branch:*) Bash(git status:*) Bash(git diff:*) Bash(git log:*)
36
+ disable-model-invocation: true
37
+ ---
38
+
39
+ # agent-memory
40
+
41
+ Manual-only orchestrator for the local **agent-memory** method. The canonical
42
+ memory skeleton and migration log are **vendored with this skill** under
43
+ `vendor/` (`vendor/memory/` and `vendor/UPDATE.md`). This skill installs and
44
+ migrates from there — **no remote clone or fetch**. The installed copy lives at
45
+ the target project root in `.agents/memory/`, with its version recorded in
46
+ `.agents/memory/.version` (taken from the newest entry in `vendor/UPDATE.md`).
47
+
48
+ **Lifecycle hooks are not installed by this skill.** `init`, `update`, and
49
+ `install hooks` print user-run instructions (shell script or `npx` CLI). See
50
+ `references/install-hooks.md`.
51
+
52
+ **Do not act unless the user explicitly invoked `/agent-memory <command>`.**
53
+ This skill never runs on its own.
54
+
55
+ ## Enabled tools
56
+
57
+ Pre-approved via the `allowed-tools` frontmatter — a space-separated,
58
+ host-specific, **experimental** field
59
+ ([spec](https://agentskills.io/specification#allowed-tools-field)). Hosts that
60
+ do not support it simply ignore it. Names follow the Agent Skills / Claude Code
61
+ convention; adapt them if your host differs.
62
+
63
+ | Tool | Used for |
64
+ | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
65
+ | `Read`, `Grep`, `Glob` | Read-only project analysis (`bootstrap`), lint structural checks, migration diffs (`update`), reading `references/*.md` and `vendor/`. |
66
+ | `Task` | Parallel read-only subagents in `bootstrap`. Optional — fall back to sequential analysis. |
67
+ | `Edit`, `Write` (scoped) | `.agents/memory/**`, harness instruction files per `references/init.md` (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursor/rules/agent-memory.mdc`, `.github/instructions/agent-memory.instructions.md`). **Not** hook paths. |
68
+ | `Bash(git …)` | Read-only git used by `sync` / `lint`: `branch`, `status`, `diff`, `log`. **Never** `git clone` / `fetch` / `pull` / `push`. |
69
+
70
+ **Deliberately not pre-approved** (the host should still prompt): file deletion
71
+ (`rm`, used only on confirmed `update`/cleanup) and any other shell. This keeps
72
+ the "confirm sensitive changes" rule intact. The skill never writes harness hook
73
+ scripts or configs — the user runs the installer.
74
+
75
+ ### Write boundary
76
+
77
+ Create, edit, or delete **only** under `.agents/memory/**`, plus harness
78
+ instruction files listed in `references/init.md` (`AGENTS.md`, `CLAUDE.md`,
79
+ `GEMINI.md`, `.cursor/rules/agent-memory.mdc`,
80
+ `.github/instructions/agent-memory.instructions.md`) — and in those **only the
81
+ agent-memory block** (between `<!-- <agent-memory> -->` …
82
+ `<!-- </agent-memory> -->`, or legacy plain tags — to wire it in `init` and
83
+ refresh it in `update`; for `.mdc`/`.instructions.md`, frontmatter plus
84
+ delimited body). Creating a **subdirectory** inside an existing harness dir
85
+ (e.g. `.cursor/rules/`, `.github/instructions/`) is allowed when wiring native
86
+ instruction files; never create the harness root itself unless the user
87
+ explicitly requests it. **Never** write under `.cursor/hooks/`, `.claude/hooks/`,
88
+ `.codex/hooks/`, `.opencode/hooks/`, `.opencode/plugin/`, `.github/hooks/`,
89
+ `.gemini/hooks/`, or merge `hooks.json` / harness `settings.json` for hooks.
90
+ Never touch content outside those scopes, application code, other configs, or
91
+ other docs. Read the rest of the workspace freely.
92
+
93
+ ### Repository source (vendor)
94
+
95
+ `init` and `update` read the canonical skeleton and migration log **only** from
96
+ this skill package:
97
+
98
+ - Skeleton: `vendor/memory/` (next to this `SKILL.md`)
99
+ - Migrations: `vendor/UPDATE.md`
100
+
101
+ Resolve paths relative to the installed skill directory (the folder that
102
+ contains `SKILL.md`). Do **not** `git clone`, do **not** use
103
+ `raw.githubusercontent.com`, and do **not** use `WebFetch` for the skeleton.
104
+
105
+ In the upstream git repository, the skeleton SoT is
106
+ `skills/agent-memory/vendor/` (next to this skill).
107
+
108
+ ## Routing
109
+
110
+ Read the subcommand from the invocation, load **only** the matching reference,
111
+ and follow it exactly:
112
+
113
+ | Command | Does | Reference |
114
+ | --------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------- |
115
+ | `init` | Create `.agents/memory/`; wire harness-native instruction file; print hook-install instructions. | `references/init.md` |
116
+ | `install hooks` | Print how to install or refresh lifecycle hooks for one harness (user-run installer). | `references/install-hooks.md` |
117
+ | `update` | Migrate memory; refresh agent-memory block; instruct user to refresh installed hooks. | `references/update.md` |
118
+ | `bootstrap` | Analyze the project and populate the memory. | `references/bootstrap.md` |
119
+ | `sync` | Refresh `current.md` / active-work / `log.md` / `index.md` from repo state. | `references/sync.md` |
120
+ | `lint` | Check the memory for structural and consistency problems. | `references/lint.md` |
121
+ | `help` | List the commands and how to use them. | _Help_ section below |
122
+
123
+ If no subcommand is given, or it is not one of those above, run `help` (below)
124
+ and stop. Do not guess the user's intent.
125
+
126
+ For `init`, an optional second token selects one harness (`cursor`, `claude`,
127
+ `codex`, `opencode`, `copilot`, `gemini`). Load `references/init.md` and follow
128
+ its harness table.
129
+
130
+ For `install hooks` (or `install hook`), a `<harness>` token is **required**
131
+ (`cursor`, `claude`, `codex`, `opencode`, `copilot`, `gemini`). Load
132
+ `references/install-hooks.md`.
133
+
134
+ ## Help
135
+
136
+ For `/agent-memory help` (and for any empty or unknown invocation), output the
137
+ following Markdown exactly — nothing else:
138
+
139
+ ---
140
+
141
+ **agent-memory** — a local Workspace Memory that keeps AI agents on the same
142
+ page.
143
+
144
+ **Commands**
145
+
146
+ | Command | Does |
147
+ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
148
+ | `/agent-memory init` | Create `.agents/memory/`; auto-detect harnesses and write the native instruction file (`.mdc`, `.instructions.md`, or agent `*.md`), or `init <harness>` for one. |
149
+ | `/agent-memory install hooks` | Print how to install or refresh hooks for one harness — `cursor`, `claude`, `codex`, `opencode`, `copilot`, `gemini` (memory must exist). |
150
+ | `/agent-memory bootstrap` | Analyze the project (up to 3 subagents) and populate the memory. |
151
+ | `/agent-memory update` | Migrate memory; refresh agent-memory block in harness instruction files; instruct hook refresh. |
152
+ | `/agent-memory sync` | Refresh `current.md` / active-work / `log.md` / `index.md` from repo state. `--auto` applies all diffs without per-file prompts. |
153
+ | `/agent-memory lint` | Check for broken links, orphan files, stale branches, and consistency. `--fix` also deletes stale per-branch `active-work` files. |
154
+ | `/agent-memory help` | Show this guide. |
155
+
156
+ **Getting started**
157
+
158
+ - New project? Run `init` (or `init <harness>` — e.g. `init cursor` if you use
159
+ Cursor and already have a `.cursor/` directory), then optionally `bootstrap`.
160
+ Install hooks with the printed `npx` or shell command.
161
+ - Memory exists but hooks missing or stale? Run `install hooks <harness>` for
162
+ instructions, or re-run the installer from the release tag.
163
+ - Keeping the memory current? Run `sync` at checkpoints (end of task, before
164
+ commit, before compaction). Use `sync --auto` for low-friction routine
165
+ flushes.
166
+ - Already set up? Use `lint` to check health (`lint --fix` also removes stale
167
+ per-branch files), `update` to upgrade memory scaffolding, then refresh hooks
168
+ with the user-run installer if needed.
169
+
170
+ Method & conventions: `.agents/memory/instructions.md`
171
+
172
+ ---
173
+
174
+ ## Shared rules (apply to every command)
175
+
176
+ - **Never modify project memory content** — `current.md`, `active-work/*`,
177
+ `decisions.md`, `log.md`, `domains/*`, `features/*` — unless a command
178
+ explicitly says so, and only after the user confirms.
179
+ - Run memory/orchestration steps inside the user's current agent. **Do not
180
+ download, clone, or execute hook installers** — only print instructions for
181
+ the user to run.
182
+ - If the host ignores `allowed-tools` granularity: still **never** run
183
+ `git clone`, `git fetch`, `git pull`, or any network fetch for this skill.
184
+ - All paths are relative to the target project root unless stated otherwise
185
+ (vendor paths are relative to this skill directory).
@@ -0,0 +1,115 @@
1
+ # The agent-memory block
2
+
3
+ The exact block `init` writes into harness instruction files and `update`
4
+ refreshes in place. **Single source of truth** for the block content — both
5
+ `init` and `update` read it from here; never duplicate the block text in those
6
+ references.
7
+
8
+ **Write targets** (body identical everywhere; see `references/init.md` for
9
+ carrier resolution and which file receives the block):
10
+
11
+ | Harness | File |
12
+ | -------- | ------------------------------------------------------------------------ |
13
+ | cursor | `.cursor/rules/agent-memory.mdc` (with `alwaysApply: true` frontmatter) |
14
+ | copilot | `.github/instructions/agent-memory.instructions.md` |
15
+ | claude | `CLAUDE.md` (or `AGENTS.md` when `CLAUDE.md` delegates via `@AGENTS.md`) |
16
+ | codex | `AGENTS.md` |
17
+ | opencode | `AGENTS.md` |
18
+ | gemini | `GEMINI.md` (or delegated carrier — same rules as claude) |
19
+
20
+ ## The block
21
+
22
+ ```md
23
+ <!-- <agent-memory> -->
24
+
25
+ ## Agent Memory
26
+
27
+ This project uses Agent Memory (a local Workspace Memory). **Before starting any
28
+ task**, Read `.agents/memory/instructions.md` (it defines the workflow), then
29
+ read `.agents/memory/index.md`, `.agents/memory/current.md`, and your branch's
30
+ file in `.agents/memory/active-work/`.
31
+
32
+ This memory is **read AND written** by agents — it is not chat history. While
33
+ you work and when you finish a task, keep it current per `instructions.md`:
34
+ update your branch's `active-work/<branch>.md` (Task, progress, touched files,
35
+ blockers), append bullets to the **current session** heading in `log.md`,
36
+ **record architecture and design decisions in `decisions.md`**, keep `index.md`
37
+ aligned with lazy and domain/feature files, and refresh `current.md` when
38
+ project state changes (list open active-work files in _In progress_; move
39
+ completed work to _Done_). Ask the user before changing `vision.md` when
40
+ uncertain. Delete your `active-work/` file when the branch merges. At
41
+ checkpoints (end of task, before commit, before compaction, end of session), run
42
+ `/agent-memory sync` to flush `current.md`, active-work, `log.md`, and
43
+ `index.md` from repo state.
44
+
45
+ @.agents/memory/instructions.md
46
+
47
+ <!-- </agent-memory> -->
48
+ ```
49
+
50
+ ## Cursor `.mdc` wrapper
51
+
52
+ For Cursor, prepend this frontmatter to the block above (body unchanged):
53
+
54
+ ```yaml
55
+ ---
56
+ description: Agent Memory workspace memory workflow
57
+ alwaysApply: true
58
+ ---
59
+ ```
60
+
61
+ `update` compares only the delimited body; preserve frontmatter when refreshing.
62
+
63
+ ## Copilot `.instructions.md` wrapper
64
+
65
+ For Copilot, prepend this frontmatter to the block above (body unchanged):
66
+
67
+ ```yaml
68
+ ---
69
+ applyTo: '**'
70
+ ---
71
+ ```
72
+
73
+ Copilot path-specific files under `.github/instructions/**/*.instructions.md`
74
+ are applied only to files matching an `applyTo` glob. `**` makes the block
75
+ **always-on** (every file, every session) — required so the agent receives the
76
+ agent-memory workflow before any task. Without `applyTo`, the file may not apply
77
+ at all. `update` compares only the delimited body; preserve frontmatter when
78
+ refreshing.
79
+
80
+ ## Why the delimiters
81
+
82
+ `<!-- <agent-memory> -->` … `<!-- </agent-memory> -->` mark the block so
83
+ `update` can find and replace **only** it, without touching anything else in the
84
+ file. HTML comments are invisible in rendered Markdown (no raw tags in the
85
+ preview) but remain machine-identifiable in the source. Never edit content
86
+ outside the delimiters.
87
+
88
+ ## Why both the read list and `@import`
89
+
90
+ - The explicit "Read `.agents/memory/instructions.md`" line makes the agent load
91
+ the method file directly. This is the load path for harnesses that treat agent
92
+ files as plain Markdown or load context via rules — **Cursor** receives the
93
+ block through `.cursor/rules/agent-memory.mdc` (`alwaysApply: true`);
94
+ `@import` in `AGENTS.md` is a no-op there. The "Read …" line is the active
95
+ path on Cursor. For hooks (checkpoint layer), print user-run install commands
96
+ from `/agent-memory install hooks <harness>` — the skill never installs hooks;
97
+ see `instructions.md` → _Plain-Markdown harnesses_ (hooks = checkpoint; `.mdc` =
98
+ context).
99
+ - The `@.agents/memory/instructions.md` line is honored by harnesses that follow
100
+ the AGENTS.md `@import` convention (Claude Code, Gemini CLI, Codex),
101
+ auto-loading `instructions.md`.
102
+
103
+ Including both is intentional and harmless — a harness that loads `@import`
104
+ simply gets `instructions.md` once.
105
+
106
+ ## How to compare
107
+
108
+ `update` decides whether to refresh by comparing the block currently in the
109
+ instruction file (text between the delimiters, inclusive) against the block
110
+ above, byte-for-byte. Identical → nothing to do. Different → propose the unified
111
+ diff and confirm before replacing (sensitive). Legacy installs may still use
112
+ plain `<agent-memory>` … `</agent-memory>` tags (0.0.4–0.0.5); `update` treats
113
+ those as the same block and replaces them with the comment-delimited canonical
114
+ form. For `.cursor/rules/agent-memory.mdc`, compare the delimited body only —
115
+ ignore YAML frontmatter.
@@ -0,0 +1,84 @@
1
+ # `/agent-memory bootstrap`
2
+
3
+ Analyze the project and populate the memory with real content. Uses three
4
+ analyses that run as subagents when the host supports them.
5
+
6
+ ## Steps
7
+
8
+ 1. **Permission gate (always).** Tell the user that bootstrap will spawn up to
9
+ three subagents to analyze the project, and ask for explicit permission
10
+ before continuing — **even when running under bypass/auto-approve**. If
11
+ declined, stop.
12
+
13
+ 2. **Ensure structure.** If `.agents/memory/` does not exist, run the `init`
14
+ procedure first (`references/init.md`), then continue.
15
+
16
+ 3. **Run the three analyses.** Launch them as **parallel subagents** if the host
17
+ supports subagents (e.g. Claude Code's Task/Agent tool). If it does not, run
18
+ the same three analyses **sequentially** in the current agent.
19
+ - **A — Documentation.** Read `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, then
20
+ `README.md` and other `.md` docs. Extract: product purpose, scope, goals.
21
+ - **B — Structure.** Map the repo layout: backend, frontend, database,
22
+ services, and the major areas/modules.
23
+ - **C — Technologies.** Identify the main languages, frameworks, and tooling,
24
+ and determine what kind of project it is.
25
+
26
+ 4. **Vision gate.** Before writing `vision.md`, if purpose or scope is unclear
27
+ from the analyses, **ask the user** — do not invent product goals.
28
+
29
+ 5. **Synthesize and write (skip empties).** Wait for all three, then fill memory
30
+ files only where there is real content — respect the lazy principle, do not
31
+ create shallow placeholders:
32
+
33
+ | Source | Writes to |
34
+ | ------------- | ---------------------------------------------------- |
35
+ | A (docs) | `vision.md` (after vision gate) |
36
+ | B (structure) | `architecture.md`, `domains/*.md` (per major area) |
37
+ | C (tech) | `architecture.md` (stack), `patterns.md` |
38
+ | synthesis | `current.md` (state/version), `log.md` session entry |
39
+
40
+ - **Register every created lazy file and every `domains/*.md` /
41
+ `features/*.md` in `index.md`** (under the matching section, replacing
42
+ `_None yet._`). Otherwise `lint` will flag orphans.
43
+ - Append to `log.md` using the per-session format in `instructions.md` (one
44
+ heading + bullets), e.g. `## [YYYY-MM-DD] [docs] bootstrap initial memory`
45
+ with a bullet list of files created.
46
+ - Leave `active-work/` with only its `TEMPLATE.md` (no branch files), and
47
+ **do not invent** decisions — `decisions.md` stays empty unless a genuine,
48
+ already-made trade-off is documented in the project.
49
+
50
+ 6. **Report.** List which files were created/filled and which were skipped (and
51
+ why), so the user can fill the gaps later. If vision was uncertain, note what
52
+ still needs user input. Tell the user to run `/agent-memory sync` at
53
+ checkpoints to keep `current.md`, active-work, `log.md`, and `index.md`
54
+ current.
55
+
56
+ ## Subagent prompts
57
+
58
+ Pass each analysis to a subagent with `Task` (read-only). Replies must be short
59
+ and high-signal — they feed the memory, where tokens matter. **If subagents are
60
+ unavailable, run the three prompts yourself, in order.**
61
+
62
+ - **A — Documentation:**
63
+
64
+ > Read-only task. Read the project's agent/instruction files (`AGENTS.md`,
65
+ > `CLAUDE.md`, `GEMINI.md`), then `README.md` and other top-level `*.md` docs.
66
+ > Do not read source code. Return, in ≤150 words: the product purpose (1–2
67
+ > sentences), scope/goals (bullets), and any stated conventions or
68
+ > constraints. Cite the file for each fact. If something is not documented,
69
+ > say so — never invent.
70
+
71
+ - **B — Structure:**
72
+
73
+ > Read-only task. Map the repository layout. Identify backend, frontend,
74
+ > database, services, and the major modules/areas. Return a concise list of
75
+ > top-level areas, each with its role and key entry-point path(s). Flag
76
+ > anything ambiguous. Classify from paths and manifests; avoid reading file
77
+ > bodies unless necessary.
78
+
79
+ - **C — Technologies:**
80
+ > Read-only task. From manifests (`package.json`, `pyproject.toml`, `go.mod`,
81
+ > `Cargo.toml`, etc.) and config files, identify the main languages,
82
+ > frameworks, and build/test tooling, and decide the project type (web app,
83
+ > library, CLI, service, monorepo…). Return: the stack (bullets), notable
84
+ > tooling, and a one-line project-type verdict with the evidence (which file).
@@ -0,0 +1,211 @@
1
+ # `/agent-memory init`
2
+
3
+ Create the agent-memory structure in the target project and wire it into the
4
+ harness-specific instruction file(s). Prints user-run instructions for lifecycle
5
+ hooks (does not install hooks). Idempotent: never duplicate or overwrite
6
+ existing memory or harness instruction files.
7
+
8
+ ## Invocation
9
+
10
+ ```text
11
+ /agent-memory init # auto-detect harnesses from the project
12
+ /agent-memory init <harness> # wire one harness only
13
+ ```
14
+
15
+ Accepted `<harness>` values (aliases in parentheses):
16
+
17
+ | Harness | Aliases | Native instruction file (context) | Harness dir for hooks |
18
+ | ---------- | ------------- | --------------------------------------------------- | ----------------------------------- |
19
+ | `cursor` | — | `.cursor/rules/agent-memory.mdc` | `.cursor/` — lifecycle hooks |
20
+ | `claude` | `claude-code` | `CLAUDE.md` | `.claude/` — lifecycle hooks |
21
+ | `codex` | — | `AGENTS.md` | `.codex/` — lifecycle hooks |
22
+ | `opencode` | — | `AGENTS.md` | `.opencode/` — plugin + sync script |
23
+ | `copilot` | `github` | `.github/instructions/agent-memory.instructions.md` | `.github/` — lifecycle hooks |
24
+ | `gemini` | — | `GEMINI.md` | `.gemini/` — lifecycle hooks |
25
+
26
+ If `<harness>` is missing, **auto-detect** (see step 4). If it is unknown, stop
27
+ and list the accepted values.
28
+
29
+ Canonical sources live under `skills/agent-memory/` in the agent-memory repo:
30
+
31
+ - Agent block: [`references/agent-block.md`](./agent-block.md)
32
+ - Harness hooks/plugin: [`references/install-hooks.md`](./install-hooks.md)
33
+
34
+ ## Steps
35
+
36
+ 1. **Guard.** If `.agents/memory/` already exists, stop and tell the user the
37
+ project is already initialized — suggest `/agent-memory update` or
38
+ `/agent-memory install hooks <harness>` to refresh hooks. Do not overwrite
39
+ anything.
40
+
41
+ 2. **Copy the skeleton.** Read this skill's `vendor/memory/` (see `SKILL.md` →
42
+ Repository source) and copy that directory into the project as
43
+ `.agents/memory/` (the entire directory, including `active-work/TEMPLATE.md`
44
+ and `.gitignore` for hook-local state files). Do not clone or fetch remotely.
45
+
46
+ 3. **Write the version anchor.** Create `.agents/memory/.version` containing the
47
+ latest version — the newest version section in this skill's
48
+ `vendor/UPDATE.md`, e.g. `0.0.13`.
49
+
50
+ 4. **Parse the harness target.** From the invocation, read optional `<harness>`.
51
+ Normalize aliases (`claude-code` → `claude`, `github` → `copilot`). If
52
+ omitted, set mode to `auto` and **detect harnesses** (see **Auto-detection**
53
+ below).
54
+
55
+ 5. **Resolve carriers and wire instruction files.** Use the **canonical block**
56
+ from [`references/agent-block.md`](./agent-block.md) — copy it verbatim (the
57
+ `<!-- <agent-memory> -->` … `<!-- </agent-memory> -->` delimiters and
58
+ everything between them).
59
+
60
+ **Carrier resolution (before writing):** a harness is **served** if any file
61
+ it auto-loads already contains the block. The block is written only into the
62
+ **distinct set of effective carriers** — never into a second file the same
63
+ harness also loads.
64
+ - **Nominal native** per harness (table above).
65
+ - **Delegation via `@import`:** if `CLAUDE.md` or `GEMINI.md` contains
66
+ `@AGENTS.md` or `@./AGENTS.md`, the effective carrier for that harness is
67
+ `AGENTS.md`, not the nominal file. Do **not** write the block into the file
68
+ that delegates. Resolve recursively (`@CLAUDE.md`, `@GEMINI.md` in
69
+ `AGENTS.md` / other agent files); stop on cycles.
70
+ - **Copilot coexistence:** Copilot auto-loads `AGENTS.md` **and**
71
+ `.github/instructions/agent-memory.instructions.md`. If `AGENTS.md` is an
72
+ effective carrier (codex, opencode, or claude via delegation), Copilot is
73
+ already served — **do not** create
74
+ `.github/instructions/agent-memory.instructions.md`. If Copilot is the only
75
+ harness that needs a carrier and `AGENTS.md` is not one, create the
76
+ `.instructions.md` file and do not touch `AGENTS.md`.
77
+
78
+ **Targeted mode** (`init <harness>`): resolve the carrier for that harness
79
+ only. If the nominal native delegates to a file that already has the block,
80
+ skip and report. If it delegates to a file **without** the block, write the
81
+ block into the referenced file (effective carrier), not the nominal native.
82
+
83
+ **Auto mode** (`init`): detect harnesses (below), resolve carriers for each,
84
+ write the block once per distinct carrier. Apply copilot coexistence and
85
+ delegation rules across the full set.
86
+
87
+ **Cursor `.mdc` wrapper:** the block body is the canonical block verbatim.
88
+ Prepend YAML frontmatter:
89
+
90
+ ```yaml
91
+ ---
92
+ description: Agent Memory workspace memory workflow
93
+ alwaysApply: true
94
+ ---
95
+ ```
96
+
97
+ **Copilot `.instructions.md` wrapper:** the block body is the canonical block
98
+ verbatim. Prepend YAML frontmatter so the file is **always-on** (Copilot
99
+ path-specific files apply only to files matching `applyTo`):
100
+
101
+ ```yaml
102
+ ---
103
+ applyTo: '**'
104
+ ---
105
+ ```
106
+
107
+ **Prerequisite dirs (create harness roots only on explicit request).** Native
108
+ instruction files that live inside a harness dir require that dir to already
109
+ exist. By default the skill does **not** create `.cursor/`, `.claude/`,
110
+ `.codex/`, `.opencode/`, `.github/`, or `.gemini/`. If the required dir is
111
+ missing, **stop** for that harness and ask the user: offer to create it (and
112
+ the needed subdir) on explicit confirmation, or tell them to create/enable it
113
+ first (e.g. open the harness once so it creates its dir) and re-run. Create
114
+ the harness root only when the user explicitly requests it. Required dir per
115
+ harness:
116
+
117
+ | Harness | Required dir (for native + hooks) |
118
+ | -------- | ------------------------------------------------------------------- |
119
+ | cursor | `.cursor/` (native `.cursor/rules/`, hooks `.cursor/hooks/`) |
120
+ | copilot | `.github/` (native `.github/instructions/`, hooks `.github/hooks/`) |
121
+ | claude | `.claude/` (hooks only; `CLAUDE.md` lives at root) |
122
+ | codex | `.codex/` (hooks only; `AGENTS.md` lives at root) |
123
+ | opencode | `.opencode/` (hooks only; `AGENTS.md` lives at root) |
124
+ | gemini | `.gemini/` (hooks only; `GEMINI.md` lives at root) |
125
+
126
+ Creating a **subdirectory** inside an existing harness dir (e.g.
127
+ `.cursor/rules/`, `.github/instructions/`) is allowed; never create the
128
+ harness root itself unless user explicitly requests it.
129
+
130
+ **Idempotency:** if a carrier already contains a delimited agent-memory block
131
+ (`<!-- <agent-memory> -->` … `<!-- </agent-memory> -->`, or legacy plain
132
+ `<agent-memory>` … `</agent-memory>` from 0.0.4–0.0.5), skip it — do not add
133
+ a second one. For `.mdc`, compare the body between delimiters (ignore
134
+ frontmatter when comparing).
135
+
136
+ **Orphan block cleanup:** for `cursor` / `copilot`, if `AGENTS.md` contains a
137
+ block but is **not** an effective carrier (no codex/opencode/claude via
138
+ delegation), warn and offer to remove it (**sensitive** — show diff, confirm
139
+ first). Do not remove a block from `AGENTS.md` when it serves codex,
140
+ opencode, or claude via delegation.
141
+
142
+ 6. **Print hook-install instructions.** Follow
143
+ [`references/install-hooks.md`](./install-hooks.md) for each harness that
144
+ applies (targeted: that harness only; auto: every detected harness whose
145
+ prerequisite dir exists). In `init`, run those steps **without** the memory
146
+ guard (step 1 of that reference). **Do not** copy hook scripts or merge
147
+ harness hook configs — only print the user-run `npx` / shell commands. Note:
148
+ the skill never creates harness roots; the user-run installer **does** create
149
+ them if missing when the user runs the printed command.
150
+
151
+ 7. **Report.** List: mode (auto or targeted harness), detected harness(es),
152
+ skeleton created, carrier file(s) wired or skipped (and why — delegation,
153
+ copilot coexistence, idempotency), orphan-block offers, hook-install
154
+ commands printed (or skipped for missing harness dirs), and suggest
155
+ `bootstrap` / `sync` next steps. For Cursor, note that **hooks are the
156
+ recommended checkpoint integration** (user-installed) and **`.mdc` is the
157
+ context layer**.
158
+
159
+ ## Auto-detection (`init` without `<harness>`)
160
+
161
+ Scan the project root for file markers. Do **not** wire every existing agent
162
+ file — detect harness(es), then install each native (with carrier resolution).
163
+
164
+ | Marker (project root) | Harness inferred | Notes |
165
+ | ------------------------------------------- | ---------------- | -------------------------------- |
166
+ | `CLAUDE.md` or `.claude/` (dir) | `claude` | Claude Code |
167
+ | `GEMINI.md` or `.gemini/` (dir) | `gemini` | Gemini CLI / Antigravity |
168
+ | `.cursor/` or `.cursor/rules/` (directory) | `cursor` | Cursor rules system |
169
+ | `.github/copilot-instructions.md` | `copilot` | Copilot repo-wide |
170
+ | `.github/instructions/` (directory) | `copilot` | Copilot path-specific |
171
+ | `~/.copilot/instructions` (home) | `copilot` | **detection only** — never write |
172
+ | `AGENTS.md` + `.codex/` | `codex` | |
173
+ | `AGENTS.md` + `.opencode/` | `opencode` | OpenCode uses `AGENTS.md` |
174
+ | `AGENTS.md` (no `.codex/` nor `.opencode/`) | ambiguous | ask user: codex or opencode |
175
+
176
+ - **Multi-harness:** if several markers match (e.g. `CLAUDE.md` + `.cursor/`),
177
+ install each harness, applying carrier resolution and copilot coexistence
178
+ across the set.
179
+ - **`~/.copilot/instructions`:** use only to infer Copilot usage. The install
180
+ target remains project-level
181
+ `.github/instructions/agent-memory.instructions.md` — never write under `~/`.
182
+ - **Inconclusive detection** (no markers, or `AGENTS.md` alone without `.codex/`
183
+ / `.opencode/`): **ask the user** which harness to install (via `AskQuestion`:
184
+ cursor, claude, codex, opencode, copilot, gemini). Do not guess. Do not create
185
+ `AGENTS.md` blindly.
186
+
187
+ ### Carrier example (claude + opencode)
188
+
189
+ Project: `CLAUDE.md` contains `@AGENTS.md`, `AGENTS.md` exists, `.opencode/`
190
+ exists.
191
+
192
+ - opencode → carrier `AGENTS.md`
193
+ - claude → `CLAUDE.md` delegates → carrier `AGENTS.md`
194
+ - Result: write the block **once** in `AGENTS.md`; skip `CLAUDE.md`. Report:
195
+ "claude served via `AGENTS.md` (@import in `CLAUDE.md`); `CLAUDE.md` skipped".
196
+
197
+ When `CLAUDE.md` is standalone (no `@AGENTS.md`), claude and opencode have
198
+ distinct carriers → write the block in each file that is an effective carrier.
199
+
200
+ ## Notes
201
+
202
+ - Do not populate the memory here — `init` only scaffolds. To fill it from the
203
+ codebase, the user runs `/agent-memory bootstrap`. If product vision is
204
+ unclear, ask the user before writing `vision.md` (same rule as `bootstrap` /
205
+ `sync`).
206
+ - Optional git `pre-commit` hook is **not** wired by `init` — see the
207
+ [hooks README](https://github.com/diegoos/agent-memory/blob/0.0.13/hooks/README.md).
208
+ - **Context vs checkpoint:** native instruction files (`.mdc`, agent `*.md`,
209
+ `.instructions.md`) inject the agent-memory workflow into the model context.
210
+ Lifecycle hooks (see `install-hooks.md`) run deterministic git checkpoints —
211
+ they do not replace context injection.