ziiagentmemory 0.1.0

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 (160) hide show
  1. package/.env.example +175 -0
  2. package/AGENTS.md +124 -0
  3. package/LICENSE +190 -0
  4. package/README.md +1546 -0
  5. package/dist/cli.d.mts +5 -0
  6. package/dist/cli.d.mts.map +1 -0
  7. package/dist/cli.mjs +2859 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/config-ChC9EtgV.mjs +259 -0
  10. package/dist/config-ChC9EtgV.mjs.map +1 -0
  11. package/dist/connect-JnsJXc68.mjs +1075 -0
  12. package/dist/connect-JnsJXc68.mjs.map +1 -0
  13. package/dist/hooks/notification.d.mts +1 -0
  14. package/dist/hooks/notification.mjs +74 -0
  15. package/dist/hooks/notification.mjs.map +1 -0
  16. package/dist/hooks/post-commit.d.mts +1 -0
  17. package/dist/hooks/post-commit.mjs +101 -0
  18. package/dist/hooks/post-commit.mjs.map +1 -0
  19. package/dist/hooks/post-tool-failure.d.mts +1 -0
  20. package/dist/hooks/post-tool-failure.mjs +75 -0
  21. package/dist/hooks/post-tool-failure.mjs.map +1 -0
  22. package/dist/hooks/post-tool-use.d.mts +1 -0
  23. package/dist/hooks/post-tool-use.mjs +120 -0
  24. package/dist/hooks/post-tool-use.mjs.map +1 -0
  25. package/dist/hooks/pre-compact.d.mts +1 -0
  26. package/dist/hooks/pre-compact.mjs +78 -0
  27. package/dist/hooks/pre-compact.mjs.map +1 -0
  28. package/dist/hooks/pre-tool-use.d.mts +1 -0
  29. package/dist/hooks/pre-tool-use.mjs +84 -0
  30. package/dist/hooks/pre-tool-use.mjs.map +1 -0
  31. package/dist/hooks/prompt-submit.d.mts +1 -0
  32. package/dist/hooks/prompt-submit.mjs +67 -0
  33. package/dist/hooks/prompt-submit.mjs.map +1 -0
  34. package/dist/hooks/session-end.d.mts +1 -0
  35. package/dist/hooks/session-end.mjs +60 -0
  36. package/dist/hooks/session-end.mjs.map +1 -0
  37. package/dist/hooks/session-start.d.mts +1 -0
  38. package/dist/hooks/session-start.mjs +85 -0
  39. package/dist/hooks/session-start.mjs.map +1 -0
  40. package/dist/hooks/stop.d.mts +1 -0
  41. package/dist/hooks/stop.mjs +44 -0
  42. package/dist/hooks/stop.mjs.map +1 -0
  43. package/dist/hooks/subagent-start.d.mts +1 -0
  44. package/dist/hooks/subagent-start.mjs +73 -0
  45. package/dist/hooks/subagent-start.mjs.map +1 -0
  46. package/dist/hooks/subagent-stop.d.mts +1 -0
  47. package/dist/hooks/subagent-stop.mjs +74 -0
  48. package/dist/hooks/subagent-stop.mjs.map +1 -0
  49. package/dist/hooks/task-completed.d.mts +1 -0
  50. package/dist/hooks/task-completed.mjs +73 -0
  51. package/dist/hooks/task-completed.mjs.map +1 -0
  52. package/dist/image-refs-BKLmp_sD.mjs +34 -0
  53. package/dist/image-refs-BKLmp_sD.mjs.map +1 -0
  54. package/dist/image-refs-C2YU7BIm.mjs +34 -0
  55. package/dist/image-refs-C2YU7BIm.mjs.map +1 -0
  56. package/dist/index.d.mts +2 -0
  57. package/dist/index.mjs +22324 -0
  58. package/dist/index.mjs.map +1 -0
  59. package/dist/keyed-mutex-DTHtcZrt.mjs +88 -0
  60. package/dist/keyed-mutex-DTHtcZrt.mjs.map +1 -0
  61. package/dist/logger-BEB7pCI9.mjs +43 -0
  62. package/dist/logger-BEB7pCI9.mjs.map +1 -0
  63. package/dist/schema-CNiCWzV9.mjs +78 -0
  64. package/dist/schema-CNiCWzV9.mjs.map +1 -0
  65. package/dist/src-Cr3pH_uH.mjs +20745 -0
  66. package/dist/src-Cr3pH_uH.mjs.map +1 -0
  67. package/dist/standalone-C6KzNkt5.mjs +700 -0
  68. package/dist/standalone-C6KzNkt5.mjs.map +1 -0
  69. package/dist/standalone.d.mts +25 -0
  70. package/dist/standalone.d.mts.map +1 -0
  71. package/dist/standalone.mjs +1867 -0
  72. package/dist/standalone.mjs.map +1 -0
  73. package/dist/tools-registry-DCt2KAWA.mjs +1145 -0
  74. package/dist/tools-registry-DCt2KAWA.mjs.map +1 -0
  75. package/docker-compose.yml +47 -0
  76. package/iii-config.docker.yaml +53 -0
  77. package/iii-config.yaml +61 -0
  78. package/package.json +99 -0
  79. package/plugin/.claude-plugin/plugin.json +13 -0
  80. package/plugin/.codex-plugin/plugin.json +15 -0
  81. package/plugin/.mcp.copilot.json +15 -0
  82. package/plugin/.mcp.json +13 -0
  83. package/plugin/hooks/hooks.codex.json +67 -0
  84. package/plugin/hooks/hooks.copilot.json +72 -0
  85. package/plugin/hooks/hooks.json +125 -0
  86. package/plugin/opencode/README.md +229 -0
  87. package/plugin/opencode/agentmemory-capture.ts +687 -0
  88. package/plugin/opencode/commands/recall.md +19 -0
  89. package/plugin/opencode/commands/remember.md +19 -0
  90. package/plugin/opencode/plugin.json +12 -0
  91. package/plugin/plugin.json +15 -0
  92. package/plugin/scripts/diagnostics.mjs +551 -0
  93. package/plugin/scripts/notification.d.mts +1 -0
  94. package/plugin/scripts/notification.mjs +74 -0
  95. package/plugin/scripts/notification.mjs.map +1 -0
  96. package/plugin/scripts/post-commit.d.mts +1 -0
  97. package/plugin/scripts/post-commit.mjs +101 -0
  98. package/plugin/scripts/post-commit.mjs.map +1 -0
  99. package/plugin/scripts/post-tool-failure.d.mts +1 -0
  100. package/plugin/scripts/post-tool-failure.mjs +75 -0
  101. package/plugin/scripts/post-tool-failure.mjs.map +1 -0
  102. package/plugin/scripts/post-tool-use.d.mts +1 -0
  103. package/plugin/scripts/post-tool-use.mjs +120 -0
  104. package/plugin/scripts/post-tool-use.mjs.map +1 -0
  105. package/plugin/scripts/pre-compact.d.mts +1 -0
  106. package/plugin/scripts/pre-compact.mjs +78 -0
  107. package/plugin/scripts/pre-compact.mjs.map +1 -0
  108. package/plugin/scripts/pre-tool-use.d.mts +1 -0
  109. package/plugin/scripts/pre-tool-use.mjs +84 -0
  110. package/plugin/scripts/pre-tool-use.mjs.map +1 -0
  111. package/plugin/scripts/prompt-submit.d.mts +1 -0
  112. package/plugin/scripts/prompt-submit.mjs +67 -0
  113. package/plugin/scripts/prompt-submit.mjs.map +1 -0
  114. package/plugin/scripts/session-end.d.mts +1 -0
  115. package/plugin/scripts/session-end.mjs +60 -0
  116. package/plugin/scripts/session-end.mjs.map +1 -0
  117. package/plugin/scripts/session-start.d.mts +1 -0
  118. package/plugin/scripts/session-start.mjs +85 -0
  119. package/plugin/scripts/session-start.mjs.map +1 -0
  120. package/plugin/scripts/stop.d.mts +1 -0
  121. package/plugin/scripts/stop.mjs +44 -0
  122. package/plugin/scripts/stop.mjs.map +1 -0
  123. package/plugin/scripts/subagent-start.d.mts +1 -0
  124. package/plugin/scripts/subagent-start.mjs +73 -0
  125. package/plugin/scripts/subagent-start.mjs.map +1 -0
  126. package/plugin/scripts/subagent-stop.d.mts +1 -0
  127. package/plugin/scripts/subagent-stop.mjs +74 -0
  128. package/plugin/scripts/subagent-stop.mjs.map +1 -0
  129. package/plugin/scripts/task-completed.d.mts +1 -0
  130. package/plugin/scripts/task-completed.mjs +73 -0
  131. package/plugin/scripts/task-completed.mjs.map +1 -0
  132. package/plugin/skills/_shared/TROUBLESHOOTING.md +38 -0
  133. package/plugin/skills/agentmemory-agents/REFERENCE.md +28 -0
  134. package/plugin/skills/agentmemory-agents/SKILL.md +34 -0
  135. package/plugin/skills/agentmemory-architecture/SKILL.md +33 -0
  136. package/plugin/skills/agentmemory-config/REFERENCE.md +42 -0
  137. package/plugin/skills/agentmemory-config/SKILL.md +37 -0
  138. package/plugin/skills/agentmemory-hooks/REFERENCE.md +20 -0
  139. package/plugin/skills/agentmemory-hooks/SKILL.md +39 -0
  140. package/plugin/skills/agentmemory-mcp-tools/REFERENCE.md +65 -0
  141. package/plugin/skills/agentmemory-mcp-tools/SKILL.md +39 -0
  142. package/plugin/skills/agentmemory-rest-api/REFERENCE.md +129 -0
  143. package/plugin/skills/agentmemory-rest-api/SKILL.md +43 -0
  144. package/plugin/skills/commit-context/EXAMPLES.md +71 -0
  145. package/plugin/skills/commit-context/SKILL.md +64 -0
  146. package/plugin/skills/commit-history/EXAMPLES.md +71 -0
  147. package/plugin/skills/commit-history/SKILL.md +62 -0
  148. package/plugin/skills/forget/EXAMPLES.md +75 -0
  149. package/plugin/skills/forget/SKILL.md +66 -0
  150. package/plugin/skills/handoff/EXAMPLES.md +56 -0
  151. package/plugin/skills/handoff/SKILL.md +68 -0
  152. package/plugin/skills/recall/EXAMPLES.md +74 -0
  153. package/plugin/skills/recall/SKILL.md +60 -0
  154. package/plugin/skills/recap/EXAMPLES.md +60 -0
  155. package/plugin/skills/recap/SKILL.md +63 -0
  156. package/plugin/skills/remember/EXAMPLES.md +67 -0
  157. package/plugin/skills/remember/SKILL.md +61 -0
  158. package/plugin/skills/session-history/EXAMPLES.md +59 -0
  159. package/plugin/skills/session-history/SKILL.md +61 -0
  160. package/plugin/skills/write-agentmemory-skill/SKILL.md +40 -0
package/.env.example ADDED
@@ -0,0 +1,175 @@
1
+ # =============================================================================
2
+ # agentmemory configuration
3
+ # =============================================================================
4
+ #
5
+ # Copy this file to `~/.agentmemory/.env` (or to your project root if you
6
+ # prefer scoped config) and uncomment the lines you want to override.
7
+ #
8
+ # Every line is OFF by default — `agentmemory` runs out of the box with no
9
+ # LLM key, no embedding key, and no API auth. Set keys here only when you
10
+ # want to enable the corresponding feature.
11
+ #
12
+ # Run `npx @agentmemory/agentmemory init` to copy this file into place
13
+ # automatically. Run `npx @agentmemory/agentmemory doctor` to verify that
14
+ # the daemon reads the env you expect.
15
+ #
16
+ # Defaults shown in comments. Listed in priority order — the first key
17
+ # present wins on the LLM detection path (see src/config.ts::detectProvider).
18
+
19
+ # -----------------------------------------------------------------------------
20
+ # 1. LLM provider — pick ONE
21
+ # -----------------------------------------------------------------------------
22
+ #
23
+ # Without a provider key, agentmemory runs in noop mode: observations are
24
+ # indexed via zero-LLM synthetic compression, hybrid search still works,
25
+ # but LLM-backed summarisation / reflection / consolidation are disabled.
26
+ # The detection order is OPENAI_API_KEY → MINIMAX_API_KEY → ANTHROPIC_API_KEY
27
+ # → GEMINI_API_KEY → OPENROUTER_API_KEY → noop.
28
+
29
+ # OPENAI_API_KEY=sk-... # Used for OpenAI-compatible embeddings today. PR #307 will extend this to chat completions (DeepSeek, SiliconFlow, vLLM, LM Studio, Ollama via `/v1`).
30
+ # OPENAI_BASE_URL=https://api.openai.com # Override for OpenAI-compatible providers
31
+
32
+ # ANTHROPIC_API_KEY=sk-ant-...
33
+ # ANTHROPIC_MODEL=claude-sonnet-4-20250514 # Default Anthropic model
34
+ # ANTHROPIC_BASE_URL=https://api.anthropic.com # Override for Anthropic-compatible proxies / Azure AI Foundry
35
+
36
+ # GEMINI_API_KEY=... # Either env name works; GEMINI_API_KEY takes precedence
37
+ # GOOGLE_API_KEY=... # Alias for GEMINI_API_KEY when set alone (emits a one-time stderr hint)
38
+ # GEMINI_MODEL=gemini-2.5-flash # Default Gemini model (auto-detected GA model)
39
+
40
+ # OPENROUTER_API_KEY=sk-or-...
41
+ # OPENROUTER_MODEL=anthropic/claude-sonnet-4-20250514
42
+
43
+ # MINIMAX_API_KEY=...
44
+ # MINIMAX_MODEL=MiniMax-M2.7
45
+
46
+ # MAX_TOKENS=4096 # Cap LLM completion tokens for compression / summarise calls
47
+
48
+ # Outbound LLM / embedding timeout — shared across every raw-fetch provider
49
+ # (Gemini, OpenRouter, MiniMax, OpenAI LLM, and OpenAI/Cohere/Voyage/OpenRouter
50
+ # embedding). The OpenAI LLM path also honours the OpenAI-scoped
51
+ # OPENAI_TIMEOUT_MS alias for back-compat with v0.9.17 (precedence).
52
+ # AGENTMEMORY_LLM_TIMEOUT_MS=60000 # Default: 60 000 ms (60 s)
53
+
54
+ # Opt-in Claude-subscription fallback (spawns @anthropic-ai/claude-agent-sdk
55
+ # child sessions). Off by default — the agent-sdk fallback can trigger
56
+ # Stop-hook recursion (#149 follow-up) when invoked from inside Claude Code.
57
+ # AGENTMEMORY_ALLOW_AGENT_SDK=true
58
+
59
+ # FALLBACK_PROVIDERS=anthropic,gemini # Comma-separated chain tried after the primary provider returns an error (e.g. rate limit)
60
+
61
+ # -----------------------------------------------------------------------------
62
+ # 2. Embedding provider — auto-detected, override via EMBEDDING_PROVIDER
63
+ # -----------------------------------------------------------------------------
64
+ #
65
+ # Without an embedding key, agentmemory runs in BM25-only mode for hybrid
66
+ # search. Detection order: EMBEDDING_PROVIDER override → GEMINI_API_KEY →
67
+ # OPENAI_API_KEY → VOYAGE_API_KEY → COHERE_API_KEY → OPENROUTER_API_KEY →
68
+ # local (Xenova/all-MiniLM-L6-v2, 384-dim).
69
+
70
+ # EMBEDDING_PROVIDER=local # local | openai | voyage | cohere | gemini | openrouter
71
+
72
+ # VOYAGE_API_KEY=pa-... # Optimised for code embeddings
73
+
74
+ # COHERE_API_KEY=... # General-purpose embeddings
75
+
76
+ # Reuses OPENAI_API_KEY / OPENAI_BASE_URL above when EMBEDDING_PROVIDER=openai.
77
+ # OPENAI_EMBEDDING_MODEL=text-embedding-3-small # Embedding model when EMBEDDING_PROVIDER=openai
78
+ # OPENAI_EMBEDDING_DIMENSIONS=1536 # Required when the model is not in the known-models table
79
+
80
+ # OPENROUTER_EMBEDDING_MODEL=openai/text-embedding-3-small # When EMBEDDING_PROVIDER=openrouter
81
+
82
+ # -----------------------------------------------------------------------------
83
+ # 3. Auth & security
84
+ # -----------------------------------------------------------------------------
85
+ #
86
+ # Bearer-token auth for the REST API + viewer + all integration plugins.
87
+ # Without a secret, REST endpoints are open on loopback. Set this when
88
+ # you expose the daemon beyond loopback or run behind a reverse proxy.
89
+
90
+ # AGENTMEMORY_SECRET=your-secret-here
91
+
92
+ # -----------------------------------------------------------------------------
93
+ # 4. Search tuning
94
+ # -----------------------------------------------------------------------------
95
+
96
+ # BM25_WEIGHT=0.4 # Hybrid search weight for BM25 leg
97
+ # VECTOR_WEIGHT=0.6 # Hybrid search weight for vector leg
98
+ # AGENTMEMORY_GRAPH_WEIGHT=0.2 # Graph traversal bonus on smart-search ranking
99
+ # TOKEN_BUDGET=2000 # Max tokens injected via mem::context per session
100
+ # MAX_OBS_PER_SESSION=500 # Per-session observation cap before consolidation kicks in
101
+ # SUMMARIZE_CHUNK_SIZE=400 # When mem::summarize sees a session larger than this, it chunks observations and map-reduces (chunk-summarize → reduce-merge) to stay within the LLM's context window. Default 400 ≈ 50k tokens per chunk at ~110 tok/obs. Native sessions are capped by MAX_OBS_PER_SESSION; chunking primarily matters for bulk-imported jsonl sessions, which bypass that cap.
102
+ # SUMMARIZE_CHUNK_CONCURRENCY=6 # Parallel chunk LLM calls during chunked summarize. Default 6 fits ~100-chunk sessions under iii's 180s function-invocation timeout at typical ~8s/call. High-throughput providers (Novita, DeepInfra, DeepSeek) commonly allow 100+ concurrent — bump this for very large imported sessions.
103
+
104
+ # -----------------------------------------------------------------------------
105
+ # 5. Behaviour flags
106
+ # -----------------------------------------------------------------------------
107
+
108
+ # AGENTMEMORY_AUTO_COMPRESS=true # Run LLM compression on every observation batch (requires a provider key). Default off — synthetic compression handles most cases.
109
+ # AGENTMEMORY_INJECT_CONTEXT=true # Inject recalled memories back into agent prompts (#143). Default off — hooks capture observations but do not modify conversation.
110
+ # CONSOLIDATION_ENABLED=true # Run the 4-tier consolidation pipeline (memories → semantic → procedural). Default off — opt in once you've measured the LLM cost.
111
+ # CONSOLIDATION_DECAY_DAYS=30 # Age (days) after which non-reinforced memories decay during consolidation
112
+ # GRAPH_EXTRACTION_ENABLED=true # Extract concept-graph edges on remember; powers the graph-traversal recall path
113
+ # GRAPH_EXTRACTION_BATCH_SIZE=8 # Memories per graph-extraction batch
114
+ # AGENTMEMORY_REFLECT=true # Periodically auto-synthesize lessons from memories
115
+ # AGENTMEMORY_DROP_STALE_INDEX=true # Drop on-disk BM25 / vector index on startup if dim guard fires (#248). Recovery toggle for stuck-state debugging.
116
+ # AGENTMEMORY_IMAGE_EMBEDDINGS=true # Enable image embeddings when an image provider is present (experimental).
117
+
118
+ # -----------------------------------------------------------------------------
119
+ # 6. CLI / runtime knobs
120
+ # -----------------------------------------------------------------------------
121
+
122
+ # AGENTMEMORY_TOOLS=all # core (7 tools, default) | all (51 tools) — surface exposed to MCP clients
123
+ # AGENTMEMORY_SLOTS=memory # Comma-separated plugin slot names the CLI should claim
124
+ # AGENTMEMORY_DEBUG=1 # Trace MCP shim probe + standalone fallback decisions to stderr
125
+ # AGENTMEMORY_FORCE_PROXY=1 # Skip the MCP shim livez probe and trust AGENTMEMORY_URL (for sandboxed MCP clients that can't reach localhost)
126
+ # AGENTMEMORY_PROBE_TIMEOUT_MS=2000 # MCP shim livez probe timeout
127
+ # AGENTMEMORY_URL=http://localhost:3111 # REST base URL — honored by status, doctor, MCP shim
128
+ # AGENTMEMORY_VIEWER_URL=http://localhost:3113 # Override the viewer URL printed by `agentmemory status`
129
+ # AGENTMEMORY_EXPORT_ROOT=~/agentmemory-backup # Default destination for `agentmemory export`
130
+
131
+ # STANDALONE_MCP=1 # MCP shim only — bypass the worker and run @agentmemory/mcp in-process
132
+ # STANDALONE_PERSIST_PATH=~/.agentmemory/local.db # Path used by the standalone MCP shim's local fallback store
133
+
134
+ # Snapshot exporter — periodic snapshots of state_store + stream_store.
135
+ # SNAPSHOT_ENABLED=true
136
+ # SNAPSHOT_DIR=~/.agentmemory/snapshots
137
+ # SNAPSHOT_INTERVAL=3600 # Seconds between snapshots
138
+
139
+ # Team sharing — when set, memories are scoped to (TEAM_ID, USER_ID) tuples.
140
+ # TEAM_MODE=shared
141
+ # TEAM_ID=acme
142
+ # USER_ID=rohit
143
+
144
+ # -----------------------------------------------------------------------------
145
+ # 7. Ports
146
+ # -----------------------------------------------------------------------------
147
+
148
+ # III_REST_PORT=3111 # REST API port (also affects viewer at +2)
149
+ # III_STREAMS_PORT=3112 # Streams API port
150
+ # III_ENGINE_URL=ws://localhost:49134 # iii-engine WebSocket URL (used by the worker)
151
+
152
+ # -----------------------------------------------------------------------------
153
+ # 8. iii engine pin
154
+ # -----------------------------------------------------------------------------
155
+ #
156
+ # agentmemory currently pins iii-engine to v0.11.2 — v0.11.6 introduces a
157
+ # new sandbox-everything-via-`iii worker add` model that agentmemory
158
+ # hasn't been refactored for yet. Override with AGENTMEMORY_III_VERSION
159
+ # only after migrating to the sandbox model manually.
160
+
161
+ # AGENTMEMORY_III_VERSION=0.11.2
162
+
163
+ # -----------------------------------------------------------------------------
164
+ # 9. Claude Code bridge (opt-in)
165
+ # -----------------------------------------------------------------------------
166
+
167
+ # CLAUDE_MEMORY_BRIDGE=true # Mirror compressed memories into Claude Code's CLAUDE.md
168
+ # CLAUDE_PROJECT_PATH=/path/to/your/project # Required when CLAUDE_MEMORY_BRIDGE=true
169
+ # CLAUDE_MEMORY_LINE_BUDGET=200 # Lines of memory CLAUDE.md should hold
170
+
171
+ # -----------------------------------------------------------------------------
172
+ # 10. Obsidian export (opt-in)
173
+ # -----------------------------------------------------------------------------
174
+
175
+ # OBSIDIAN_AUTO_EXPORT=true # Auto-export memories to an Obsidian vault on every consolidation
package/AGENTS.md ADDED
@@ -0,0 +1,124 @@
1
+ # agentmemory — Agent Instructions
2
+
3
+ ## Architecture
4
+
5
+ agentmemory is a persistent memory system for AI coding agents, built on iii-engine's three primitives (Worker/Function/Trigger). Everything goes through `registerFunction`/`registerTrigger`/`sdk.trigger()` — never bypass iii-engine with standalone SQLite or in-process alternatives.
6
+
7
+ - **Engine**: iii-sdk (WebSocket to iii-engine on port 49134)
8
+ - **State**: File-based SQLite via iii-engine's StateModule (`./data/state_store.db`)
9
+ - **Build**: TypeScript → ESM via tsdown, output to `dist/`
10
+ - **Test**: vitest (`npm test` excludes integration tests)
11
+
12
+ ## Consistency Rules
13
+
14
+ **When adding or removing MCP tools, you MUST update ALL of the following:**
15
+ 1. `src/mcp/tools-registry.ts` — tool definition + `getAllTools()` array
16
+ 2. `src/mcp/server.ts` — handler case in the `mcp::tools::call` switch
17
+ 3. `src/triggers/api.ts` — REST endpoint registration
18
+ 4. `src/index.ts` — function registration + endpoint count in the log line
19
+ 5. `test/mcp-standalone.test.ts` — tool count assertion
20
+ 6. `README.md` — tool counts (search for "MCP tools")
21
+ 7. `plugin/.claude-plugin/plugin.json` — tool count in description
22
+ 8. `plugin/plugin.json` and `plugin/.mcp.copilot.json` (when present) — tool count or MCP exposure
23
+
24
+ **When adding REST endpoints, you MUST update:**
25
+ 1. `src/triggers/api.ts` — endpoint registration
26
+ 2. `src/index.ts` — endpoint count in the log line
27
+ 3. `README.md` — endpoint count (search for "REST endpoints" and "endpoints on port")
28
+
29
+ **When bumping version, you MUST update ALL of the following:**
30
+ 1. `package.json` — version field
31
+ 2. `src/version.ts` — VERSION constant and type union
32
+ 3. `src/types.ts` — ExportData version union
33
+ 4. `src/functions/export-import.ts` — supportedVersions set
34
+ 5. `test/export-import.test.ts` — version assertion
35
+ 6. `plugin/.claude-plugin/plugin.json` — version field
36
+ 7. `plugin/plugin.json` (when present) — version field
37
+
38
+ **When adding new KV scopes:**
39
+ 1. `src/state/schema.ts` — add to the KV object
40
+ 2. `src/types.ts` — add the corresponding interface
41
+
42
+ **When adding new audit operations:**
43
+ 1. `src/types.ts` — add to AuditEntry.operation union type
44
+
45
+ ## Code Patterns
46
+
47
+ ### Function Registration
48
+ ```typescript
49
+ sdk.registerFunction(
50
+ "mem::your-function",
51
+ async (data: { ... }) => {
52
+ // validate inputs
53
+ // do work via kv.get/kv.set/kv.list
54
+ // record audit via recordAudit()
55
+ return { success: true, ... };
56
+ },
57
+ );
58
+ ```
59
+
60
+ ### REST Endpoint Registration
61
+ ```typescript
62
+ sdk.registerFunction("api::your-endpoint", async (req: ApiRequest) => {
63
+ const denied = checkAuth(req, secret);
64
+ if (denied) return denied;
65
+ const body = req.body as Record<string, unknown>;
66
+ // validate + whitelist fields (never pass raw body to sdk.trigger)
67
+ const result = await sdk.trigger({
68
+ function_id: "mem::your-function",
69
+ payload: { ... },
70
+ });
71
+ return { status_code: 200, body: result };
72
+ });
73
+ sdk.registerTrigger({
74
+ type: "http",
75
+ function_id: "api::your-endpoint",
76
+ config: { api_path: "/agentmemory/your-path", http_method: "POST" },
77
+ });
78
+ ```
79
+
80
+ ### MCP Tool Handler
81
+ ```typescript
82
+ case "memory_your_tool": {
83
+ // validate args with typeof checks
84
+ // parse CSV args: args.field.split(",").map(t => t.trim()).filter(Boolean)
85
+ const result = await sdk.trigger({
86
+ function_id: "mem::your-function",
87
+ payload: { ... },
88
+ });
89
+ return { status_code: 200, body: { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] } };
90
+ }
91
+ ```
92
+
93
+ ### Hook Scripts
94
+ Hook scripts in `src/hooks/` are standalone Node.js scripts (no iii-sdk import). They read JSON from stdin, make HTTP calls to the REST API, and exit. There are two patterns depending on whether Claude Code consumes the script's stdout:
95
+
96
+ - **Context-injecting hooks** (`pre-tool-use`, `pre-compact`, `session-start`) write recalled context to stdout for Claude Code to inject. These MUST use `try/catch` with `await fetch(..., { signal: AbortSignal.timeout(N) })` — the script has to wait for the response before exiting, and the timeout is the only bound on hang time.
97
+ - **Telemetry-only hooks** (`notification`, `post-tool-failure`, `post-tool-use`, `prompt-submit`, `stop`, `session-end`, `subagent-start`, `subagent-stop`, `task-completed`) write nothing to stdout. These MUST use fire-and-forget `fetch(..., { signal: AbortSignal.timeout(N) }).catch(() => {})` paired with `setTimeout(() => process.exit(0), 500).unref()`. The unawaited fetch dispatches the request; the unref'd `setTimeout` force-exits the process after the request has been flushed to the local daemon's socket buffer (~500ms is enough for single-request hooks; use 1500ms for multi-request hooks like `stop` and `session-end` so all fetches have time to start, especially when `AGENTMEMORY_URL` points to a remote daemon). Without the `setTimeout` Node keeps the event loop alive waiting for any in-flight fetch to settle, which means the hook still blocks Claude Code's next-prompt boundary for up to the AbortSignal duration — exactly the bug fire-and-forget is meant to fix.
98
+
99
+ ## Coding Standards
100
+
101
+ - TypeScript, ESM only (`"type": "module"`)
102
+ - No code comments explaining WHAT — use clear naming instead
103
+ - Use `fingerprintId()` for content-addressable dedup, `generateId()` for unique IDs
104
+ - Parallel operations where possible (`Promise.all` for independent kv writes/reads)
105
+ - Input validation at system boundaries (MCP handlers, REST endpoints)
106
+ - REST endpoints must whitelist fields — never pass raw request body to `sdk.trigger()`
107
+ - Use `recordAudit()` for state-changing operations
108
+ - Timestamps: capture once with `new Date().toISOString()` and reuse
109
+
110
+ ## Testing
111
+
112
+ - All tests must pass before PR: `npm test` (950+ tests)
113
+ - Mock pattern: `vi.mock("iii-sdk")` with mock `sdk.trigger`, `kv.get/set/list`
114
+ - Test files go in `test/` with `.test.ts` extension
115
+ - Follow existing patterns in `test/crystallize.test.ts` for function tests
116
+
117
+ ## Current Stats (v0.9.16)
118
+
119
+ - 53 MCP tools (8 visible by default, `AGENTMEMORY_TOOLS=all` for all)
120
+ - 128 REST endpoints
121
+ - 6 MCP resources, 3 MCP prompts
122
+ - 12 hooks, 15 skills
123
+ - 50+ iii functions
124
+ - 950+ tests
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Rohit Ghumare
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.