agent-mind 1.0.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.
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/bin/cli.js +38 -0
- package/package.json +33 -0
- package/src/commands/doctor.js +269 -0
- package/src/commands/init.js +345 -0
- package/src/commands/meta.js +34 -0
- package/src/commands/upgrade.js +177 -0
- package/src/index.js +18 -0
- package/src/utils/detect-tools.js +62 -0
- package/src/utils/inject-adapter.js +65 -0
- package/src/utils/template.js +103 -0
- package/src/utils/version.js +71 -0
- package/template/.am-tools/compact.sh +171 -0
- package/template/.am-tools/guide.md +274 -0
- package/template/.am-tools/health-check.sh +165 -0
- package/template/.am-tools/validate.sh +174 -0
- package/template/BOOT.md +71 -0
- package/template/README.md +109 -0
- package/template/VERSION.md +57 -0
- package/template/adapters/claude.md +56 -0
- package/template/adapters/codex.md +33 -0
- package/template/adapters/cursor.md +35 -0
- package/template/adapters/gemini.md +32 -0
- package/template/config.md +33 -0
- package/template/history/episodes/_index.md +13 -0
- package/template/history/maintenance-log.md +9 -0
- package/template/history/reflections/_index.md +11 -0
- package/template/knowledge/domains/_template/failures/_index.md +19 -0
- package/template/knowledge/domains/_template/patterns.md +21 -0
- package/template/knowledge/insights.md +23 -0
- package/template/knowledge/stack/_template.md +20 -0
- package/template/protocols/compaction.md +101 -0
- package/template/protocols/maintenance.md +99 -0
- package/template/protocols/memory-ops.md +89 -0
- package/template/protocols/quality-gate.md +66 -0
- package/template/protocols/workflow.md +81 -0
- package/template/workspace/.gitkeep +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shikhar Verma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Agent Mind
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/agent-mind)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](#)
|
|
7
|
+
|
|
8
|
+
**A cognitive memory system for LLM coding agents.**
|
|
9
|
+
|
|
10
|
+
Agent Mind is a `.agent-mind/` folder you drop into any project. It gives your AI coding tool — Claude Code, Codex, Gemini CLI, Cursor, or anything that reads files — persistent memory, a structured thinking protocol, and the ability to learn from experience across sessions.
|
|
11
|
+
|
|
12
|
+
Pure markdown. No databases. No embeddings. No external dependencies.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx agent-mind init
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Why This Exists
|
|
21
|
+
|
|
22
|
+
Every LLM coding agent today suffers from the same fundamental problem: **amnesia**.
|
|
23
|
+
|
|
24
|
+
Your agent solves a tricky auth bug on Monday. On Wednesday, it hits the same class of bug and starts from scratch. It doesn't remember the patterns it discovered, the approaches that failed, or the architectural decisions you made together. Each session is a blank slate.
|
|
25
|
+
|
|
26
|
+
This isn't just inconvenient — it's a compounding loss. Every insight that isn't captured is an insight that can't inform future work. Over weeks and months, the gap between what your agent *could* know and what it *does* know becomes enormous.
|
|
27
|
+
|
|
28
|
+
Existing solutions don't solve this well. Vector databases like [Mem0](https://github.com/mem0ai/mem0) embed memories as opaque vectors — you can't read, edit, or version-control them. Multi-agent frameworks add orchestration complexity when the real problem is memory, not coordination. And tool-specific configs (CLAUDE.md, AGENTS.md) give you static instructions but no learning loop.
|
|
29
|
+
|
|
30
|
+
Agent Mind takes a different approach: a structured filesystem that any LLM can read and write to, with protocols that turn raw experience into reusable knowledge.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Research Foundation
|
|
35
|
+
|
|
36
|
+
This isn't built on intuition. Every major design decision maps to a published finding.
|
|
37
|
+
|
|
38
|
+
**Filesystem beats vector databases.** [Letta/MemGPT](https://arxiv.org/abs/2310.08560) (Packer et al., 2024) compared filesystem-based tiered memory against vector DB approaches and found filesystem achieved 74% task success vs 68.5% for vector retrieval. The reason: deterministic access patterns. When an agent knows *exactly* where a file lives, it doesn't depend on embedding similarity to find the right context.
|
|
39
|
+
|
|
40
|
+
**Experience extraction compounds.** [ExpeL](https://arxiv.org/abs/2308.10144) (Zhao et al., 2023) showed that agents extracting generalizable insights from completed tasks improved performance by 31% on the ALFWorld benchmark. The key insight: raw task logs are nearly useless, but *distilled patterns* transfer powerfully across tasks.
|
|
41
|
+
|
|
42
|
+
**Failure analysis prevents recurrence.** [Reflexion](https://arxiv.org/abs/2303.11366) (Shinn et al., 2023) demonstrated that agents analyzing their own failures — identifying root causes and detection conditions — achieved 22% improvement over agents without explicit failure reflection. Knowing *what went wrong* is more valuable than knowing what went right.
|
|
43
|
+
|
|
44
|
+
**Unfiltered memory makes agents worse.** [SimpleMem](https://arxiv.org/abs/2310.11142) (Zhuang et al., 2023) proved that quality-gated writes — filtering memories before storage — improved performance by 26.4% over systems that store everything. Bad memories actively degrade agent performance. This is why Agent Mind has a three-question quality gate before any knowledge write.
|
|
45
|
+
|
|
46
|
+
**Memory injection is a real attack vector.** [MINJA](https://arxiv.org/abs/2403.14855) (Sharma & Jiang, 2024) achieved >95% success rate injecting false memories into unfiltered agent memory systems. Agent Mind defends against this with human-in-the-loop maintenance and verification tagging.
|
|
47
|
+
|
|
48
|
+
**Long-running agents degrade without maintenance.** Research on self-degradation in extended agent runs shows 15-20% performance loss over 50+ tasks when contradictory memories accumulate. Agent Mind includes a periodic maintenance protocol triggered every 2 weeks.
|
|
49
|
+
|
|
50
|
+
**Smaller files get better adherence.** Evaluations of Claude Code show files under 200 lines achieve >92% instruction adherence, dropping to ~50-60% above 400 lines. Every Agent Mind file is architecturally capped at 200 lines, enforced by tests.
|
|
51
|
+
|
|
52
|
+
The architecture draws from the [CoALA framework](https://arxiv.org/abs/2309.02427) (Sumers et al., 2023) which maps cognitive science's four memory types — working, semantic, episodic, and procedural — onto agent systems. Agent Mind implements all four.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Architecture
|
|
57
|
+
|
|
58
|
+
### Three-Tier Memory Model
|
|
59
|
+
|
|
60
|
+
| Tier | Location | Load Pattern | What It Stores |
|
|
61
|
+
|------|----------|--------------|----------------|
|
|
62
|
+
| **Hot** | `BOOT.md`, `protocols/`, `workspace/` | Always loaded | Active context, thinking protocols, current task |
|
|
63
|
+
| **Warm** | `knowledge/` | Loaded by relevance | Domain patterns, cross-task insights, tech-specific knowledge |
|
|
64
|
+
| **Cold** | `history/` | Searched on demand | Session records, failure analyses, maintenance logs |
|
|
65
|
+
|
|
66
|
+
### Folder Structure
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
.agent-mind/
|
|
70
|
+
BOOT.md # Entry point — agent reads this every session
|
|
71
|
+
config.md # Project name, stack, domains
|
|
72
|
+
VERSION.md # Installed version, core/user file manifest
|
|
73
|
+
workspace/ # Working memory (cleared after compaction)
|
|
74
|
+
knowledge/ # Semantic memory (grows over time)
|
|
75
|
+
domains/ # Domain-specific patterns and failure libraries
|
|
76
|
+
stack/ # Technology-specific knowledge
|
|
77
|
+
insights.md # Cross-domain learnings with vote tracking
|
|
78
|
+
history/ # Episodic memory (append-only)
|
|
79
|
+
episodes/ # Session records with outcomes
|
|
80
|
+
reflections/ # Failure analyses with root causes
|
|
81
|
+
maintenance-log.md # Record of all maintenance runs
|
|
82
|
+
protocols/ # Procedural memory (system-managed)
|
|
83
|
+
workflow.md # 5-phase thinking process
|
|
84
|
+
compaction.md # Post-task consolidation
|
|
85
|
+
quality-gate.md # Three-question filter before knowledge writes
|
|
86
|
+
maintenance.md # Periodic health checks
|
|
87
|
+
adapters/ # Tool-specific integration snippets
|
|
88
|
+
.am-tools/ # Shell utilities for mechanical operations
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### The Learning Loop
|
|
92
|
+
|
|
93
|
+
Every task follows five phases, defined in `protocols/workflow.md`:
|
|
94
|
+
|
|
95
|
+
**Understand** — Read the request. Identify domain. Assess scale. Load relevant knowledge from warm tier.
|
|
96
|
+
|
|
97
|
+
**Load Context** — Pull domain patterns, recent episodes, known failures. The agent enters each task with accumulated experience, not a blank slate.
|
|
98
|
+
|
|
99
|
+
**Think Critically** — Before writing code, reason about approach. Check against failure library. Consider alternatives. This is where past experience pays off.
|
|
100
|
+
|
|
101
|
+
**Work** — Execute. Log decisions and questions to workspace as you go.
|
|
102
|
+
|
|
103
|
+
**Capture** — Run compaction protocol. Create episode record. Extract insights through quality gate. Archive to history. Clear workspace.
|
|
104
|
+
|
|
105
|
+
The quality gate asks three questions before any write to `knowledge/`:
|
|
106
|
+
|
|
107
|
+
1. Is this genuinely new information? (not already captured)
|
|
108
|
+
2. Is it generalizable? (applies beyond this specific task)
|
|
109
|
+
3. Is the source verified? (test passed, human confirmed, or documented)
|
|
110
|
+
|
|
111
|
+
If any answer is no, the write is rejected. This is how Agent Mind prevents [memory poisoning](https://arxiv.org/abs/2403.14855) — the single biggest failure mode in agent memory systems.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Supported Tools
|
|
116
|
+
|
|
117
|
+
| Tool | Config File | Integration |
|
|
118
|
+
|------|-------------|-------------|
|
|
119
|
+
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | `CLAUDE.md` | Auto-detected during init |
|
|
120
|
+
| [Codex](https://github.com/openai/codex) | `AGENTS.md` | Auto-detected during init |
|
|
121
|
+
| [Gemini CLI](https://github.com/google-gemini/gemini-cli) | `GEMINI.md` | Auto-detected during init |
|
|
122
|
+
| [Cursor](https://cursor.sh/) | `.cursorrules` / `.cursor/rules/` | Auto-detected during init |
|
|
123
|
+
|
|
124
|
+
The init command detects which tools you use, shows you the integration snippet, and asks permission before modifying any config file. Each adapter adds a small block that tells your agent to read `.agent-mind/BOOT.md` at the start of every session.
|
|
125
|
+
|
|
126
|
+
Agent Mind is tool-agnostic by design. Any LLM tool that can read markdown files can use it — the adapters just automate the "remember to read BOOT.md" instruction.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## CLI Reference
|
|
131
|
+
|
|
132
|
+
### `npx agent-mind init`
|
|
133
|
+
|
|
134
|
+
Interactive setup. Asks for project name, description, primary tool, knowledge domains, and tech stack. Creates the `.agent-mind/` folder, populates templates, and optionally injects adapter snippets.
|
|
135
|
+
|
|
136
|
+
Works in both interactive (TTY) and piped/scripted modes.
|
|
137
|
+
|
|
138
|
+
### `npx agent-mind doctor`
|
|
139
|
+
|
|
140
|
+
Health check. Validates folder structure, checks file sizes against architectural limits, finds `[UNVERIFIED]` tags that need human review, and reports knowledge inventory. Returns exit code 0 (healthy) or 1 (issues found).
|
|
141
|
+
|
|
142
|
+
### `npx agent-mind upgrade`
|
|
143
|
+
|
|
144
|
+
Safe upgrade. Reads `VERSION.md` to identify core files (replaceable) vs user files (never touched). Shows exactly what will change. Requires confirmation. Your knowledge, history, and config are never modified.
|
|
145
|
+
|
|
146
|
+
### `npx agent-mind version` / `npx agent-mind help`
|
|
147
|
+
|
|
148
|
+
Version info and command reference.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Core Design Decisions
|
|
153
|
+
|
|
154
|
+
**Everything is markdown.** No databases, no APIs, no cloud services. Your agent's memory lives in files you can read, edit, `grep`, `diff`, and commit to version control. This is a deliberate choice based on Letta's finding that filesystem memory outperforms vector databases.
|
|
155
|
+
|
|
156
|
+
**Structure is the product.** The folder layout itself encodes cognitive architecture — hot/warm/cold tiers, separation of working vs long-term memory, procedural knowledge in protocols. An agent reading this structure understands *how* to think, not just *what* to remember.
|
|
157
|
+
|
|
158
|
+
**Quality over quantity.** One verified insight is worth more than ten unverified observations. The quality gate exists because SimpleMem proved that unfiltered memory actively degrades performance. Most memory systems fail by storing too much, not too little.
|
|
159
|
+
|
|
160
|
+
**Human drives, agent maintains.** The agent proposes memory updates; you approve them. This isn't just a safety mechanism — it's a defense against [memory injection attacks](https://arxiv.org/abs/2403.14855) that achieve >95% success in unfiltered systems.
|
|
161
|
+
|
|
162
|
+
**Nothing is deleted, only archived.** Full audit trail. History is append-only. Even during maintenance, the agent proposes and you decide.
|
|
163
|
+
|
|
164
|
+
**Zero external dependencies.** The npm package uses only Node.js built-in modules. The `.agent-mind/` folder uses only markdown and shell scripts. No lock-in, no supply chain risk.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Installation
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Via npx (no install needed)
|
|
172
|
+
npx agent-mind init
|
|
173
|
+
|
|
174
|
+
# Global install
|
|
175
|
+
npm install -g agent-mind
|
|
176
|
+
agent-mind init
|
|
177
|
+
|
|
178
|
+
# Project-local
|
|
179
|
+
npm install agent-mind --save-dev
|
|
180
|
+
npx agent-mind init
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
After initialization:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
cat .agent-mind/BOOT.md # Read the agent entry point
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Safe Upgrades
|
|
192
|
+
|
|
193
|
+
Agent Mind separates **core files** (protocols, adapters, BOOT.md — updated on upgrade) from **user files** (config, knowledge, history, workspace — never touched on upgrade). The manifest lives in `VERSION.md`.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npx agent-mind upgrade
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
This replaces system files with the latest version while preserving everything you've built. Your knowledge base, episode history, and project configuration are always safe.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
git clone https://github.com/shikhar1verma/agent-mind.git
|
|
207
|
+
cd agent-mind
|
|
208
|
+
npm test # 112 tests across 6 suites
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Tests cover folder structure validation, cross-file reference integrity, architectural size limits, template copying, upgrade safety, and utility scripts. See [docs/contributing.md](docs/contributing.md) for guidelines.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Further Reading
|
|
216
|
+
|
|
217
|
+
- [docs/architecture.md](docs/architecture.md) — Design philosophy and memory architecture deep dive
|
|
218
|
+
- [docs/research.md](docs/research.md) — Full research citations with findings and implementation mapping
|
|
219
|
+
- [docs/contributing.md](docs/contributing.md) — How to contribute
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
[MIT](LICENSE)
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
Built by [Shikhar Verma](https://github.com/shikhar1verma). Research-backed. Battle-tested against the ways LLM agents actually fail.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { init } = require('../src/commands/init');
|
|
5
|
+
const { upgrade } = require('../src/commands/upgrade');
|
|
6
|
+
const { doctor } = require('../src/commands/doctor');
|
|
7
|
+
const { version, help } = require('../src/commands/meta');
|
|
8
|
+
|
|
9
|
+
const COMMANDS = {
|
|
10
|
+
init,
|
|
11
|
+
upgrade,
|
|
12
|
+
doctor,
|
|
13
|
+
version,
|
|
14
|
+
help
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
const command = args[0] || 'help';
|
|
20
|
+
|
|
21
|
+
if (COMMANDS[command]) {
|
|
22
|
+
try {
|
|
23
|
+
await COMMANDS[command](args.slice(1));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(`\nError: ${error.message}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
console.error(`\nUnknown command: "${command}"\n`);
|
|
30
|
+
console.log('Use "agent-mind help" to see available commands.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
main().catch(error => {
|
|
36
|
+
console.error(`\nFatal error: ${error.message}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-mind",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cognitive memory system for LLM agents. Drop-in folder that makes any AI coding tool think better, remember what matters, and improve over time.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agent-mind": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node --test tests/*.test.js",
|
|
11
|
+
"test:benchmarks": "node tests/benchmarks/run.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai", "llm", "agent", "memory", "cognitive", "claude", "codex", "gemini", "cursor",
|
|
15
|
+
"context-management", "agent-memory", "claude-code", "coding-agent"
|
|
16
|
+
],
|
|
17
|
+
"author": "Shikhar Verma <shikhar1verma@gmail.com>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/shikhar1verma/agent-mind"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/",
|
|
28
|
+
"src/",
|
|
29
|
+
"template/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Count lines in a file
|
|
6
|
+
*/
|
|
7
|
+
function countLines(filePath) {
|
|
8
|
+
try {
|
|
9
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
10
|
+
return content.split('\n').length;
|
|
11
|
+
} catch {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Count entries in a file (lines starting with - or number)
|
|
18
|
+
*/
|
|
19
|
+
function countEntries(filePath) {
|
|
20
|
+
try {
|
|
21
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
22
|
+
const lines = content.split('\n');
|
|
23
|
+
return lines.filter(line => /^\s*[-*\d]/.test(line)).length;
|
|
24
|
+
} catch {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Find tags in a file
|
|
31
|
+
*/
|
|
32
|
+
function findTags(filePath, tag) {
|
|
33
|
+
try {
|
|
34
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
35
|
+
const regex = new RegExp(`\\[${tag}\\]`, 'g');
|
|
36
|
+
const matches = content.match(regex);
|
|
37
|
+
return (matches || []).length;
|
|
38
|
+
} catch {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if directory structure is valid
|
|
45
|
+
*/
|
|
46
|
+
function validateStructure(agentMindPath) {
|
|
47
|
+
const issues = [];
|
|
48
|
+
const warnings = [];
|
|
49
|
+
|
|
50
|
+
// Required directories
|
|
51
|
+
const requiredDirs = [
|
|
52
|
+
'workspace',
|
|
53
|
+
'knowledge',
|
|
54
|
+
'history',
|
|
55
|
+
'protocols',
|
|
56
|
+
'adapters',
|
|
57
|
+
'.am-tools'
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
requiredDirs.forEach(dir => {
|
|
61
|
+
const dirPath = path.join(agentMindPath, dir);
|
|
62
|
+
if (!fs.existsSync(dirPath)) {
|
|
63
|
+
issues.push(`Missing directory: ${dir}`);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Required files
|
|
68
|
+
const requiredFiles = [
|
|
69
|
+
'BOOT.md',
|
|
70
|
+
'VERSION.md',
|
|
71
|
+
'config.md',
|
|
72
|
+
'protocols/compaction.md',
|
|
73
|
+
'protocols/maintenance.md',
|
|
74
|
+
'protocols/workflow.md'
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
requiredFiles.forEach(file => {
|
|
78
|
+
const filePath = path.join(agentMindPath, file);
|
|
79
|
+
if (!fs.existsSync(filePath)) {
|
|
80
|
+
issues.push(`Missing file: ${file}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return { issues, warnings };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Check file sizes against limits
|
|
89
|
+
*/
|
|
90
|
+
function checkFileSizes(agentMindPath) {
|
|
91
|
+
const issues = [];
|
|
92
|
+
const warnings = [];
|
|
93
|
+
|
|
94
|
+
const limits = {
|
|
95
|
+
'BOOT.md': 150,
|
|
96
|
+
'protocols/compaction.md': 200,
|
|
97
|
+
'protocols/maintenance.md': 200,
|
|
98
|
+
'protocols/workflow.md': 200,
|
|
99
|
+
'protocols/quality-gate.md': 200,
|
|
100
|
+
'protocols/memory-ops.md': 200
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
Object.entries(limits).forEach(([file, limit]) => {
|
|
104
|
+
const filePath = path.join(agentMindPath, file);
|
|
105
|
+
if (fs.existsSync(filePath)) {
|
|
106
|
+
const lines = countLines(filePath);
|
|
107
|
+
if (lines > limit) {
|
|
108
|
+
warnings.push(`${file} has ${lines} lines (limit: ${limit})`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Check knowledge domains
|
|
114
|
+
const knowledgePath = path.join(agentMindPath, 'knowledge');
|
|
115
|
+
if (fs.existsSync(knowledgePath)) {
|
|
116
|
+
const domains = fs.readdirSync(knowledgePath);
|
|
117
|
+
domains.forEach(domain => {
|
|
118
|
+
const patternsPath = path.join(knowledgePath, domain, 'patterns.md');
|
|
119
|
+
if (fs.existsSync(patternsPath)) {
|
|
120
|
+
const lines = countLines(patternsPath);
|
|
121
|
+
if (lines > 200) {
|
|
122
|
+
warnings.push(`knowledge/${domain}/patterns.md has ${lines} lines (limit: 200)`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { issues, warnings };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Check for unverified content
|
|
133
|
+
*/
|
|
134
|
+
function checkUnverified(agentMindPath) {
|
|
135
|
+
const issues = [];
|
|
136
|
+
const warnings = [];
|
|
137
|
+
let unverifiedCount = 0;
|
|
138
|
+
|
|
139
|
+
function searchDir(dir) {
|
|
140
|
+
try {
|
|
141
|
+
const items = fs.readdirSync(dir);
|
|
142
|
+
items.forEach(item => {
|
|
143
|
+
const itemPath = path.join(dir, item);
|
|
144
|
+
const stat = fs.statSync(itemPath);
|
|
145
|
+
if (stat.isDirectory()) {
|
|
146
|
+
searchDir(itemPath);
|
|
147
|
+
} else if (item.endsWith('.md')) {
|
|
148
|
+
const count = findTags(itemPath, 'UNVERIFIED');
|
|
149
|
+
if (count > 0) {
|
|
150
|
+
unverifiedCount += count;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
} catch {
|
|
155
|
+
// Ignore errors
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
searchDir(agentMindPath);
|
|
160
|
+
|
|
161
|
+
if (unverifiedCount > 0) {
|
|
162
|
+
warnings.push(`Found ${unverifiedCount} [UNVERIFIED] entries - review and mark verified`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { issues, warnings };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Count knowledge items
|
|
170
|
+
*/
|
|
171
|
+
function countKnowledge(agentMindPath) {
|
|
172
|
+
let episodeCount = 0;
|
|
173
|
+
let insightCount = 0;
|
|
174
|
+
|
|
175
|
+
const historyPath = path.join(agentMindPath, 'history');
|
|
176
|
+
if (fs.existsSync(historyPath)) {
|
|
177
|
+
try {
|
|
178
|
+
const episodes = fs.readdirSync(historyPath).filter(f => f.endsWith('.md'));
|
|
179
|
+
episodeCount = episodes.length;
|
|
180
|
+
} catch {
|
|
181
|
+
// Ignore errors
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const insightsPath = path.join(agentMindPath, 'knowledge', 'insights.md');
|
|
186
|
+
if (fs.existsSync(insightsPath)) {
|
|
187
|
+
insightCount = countEntries(insightsPath);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { episodeCount, insightCount };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function doctor() {
|
|
194
|
+
const cwd = process.cwd();
|
|
195
|
+
const agentMindPath = path.join(cwd, '.agent-mind');
|
|
196
|
+
|
|
197
|
+
console.log('\n🏥 Agent Mind Health Check\n');
|
|
198
|
+
|
|
199
|
+
// Check if Agent Mind exists
|
|
200
|
+
if (!fs.existsSync(agentMindPath)) {
|
|
201
|
+
console.log('❌ Agent Mind not found in this directory.');
|
|
202
|
+
console.log('Run "agent-mind init" to initialize it.\n');
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let totalIssues = 0;
|
|
207
|
+
let totalWarnings = 0;
|
|
208
|
+
|
|
209
|
+
// Validate structure
|
|
210
|
+
console.log('📋 Checking directory structure...');
|
|
211
|
+
const { issues: structIssues, warnings: structWarnings } = validateStructure(agentMindPath);
|
|
212
|
+
if (structIssues.length > 0) {
|
|
213
|
+
structIssues.forEach(issue => {
|
|
214
|
+
console.log(` ❌ ${issue}`);
|
|
215
|
+
totalIssues++;
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
console.log(' ✅ All required files and directories present');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Check file sizes
|
|
222
|
+
console.log('\n📏 Checking file sizes...');
|
|
223
|
+
const { issues: sizeIssues, warnings: sizeWarnings } = checkFileSizes(agentMindPath);
|
|
224
|
+
if (sizeWarnings.length > 0) {
|
|
225
|
+
sizeWarnings.forEach(warning => {
|
|
226
|
+
console.log(` ⚠️ ${warning}`);
|
|
227
|
+
totalWarnings++;
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
console.log(' ✅ All files within size limits');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Check for unverified content
|
|
234
|
+
console.log('\n🔍 Checking for unverified content...');
|
|
235
|
+
const { warnings: verifyWarnings } = checkUnverified(agentMindPath);
|
|
236
|
+
if (verifyWarnings.length > 0) {
|
|
237
|
+
verifyWarnings.forEach(warning => {
|
|
238
|
+
console.log(` ⚠️ ${warning}`);
|
|
239
|
+
totalWarnings++;
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
console.log(' ✅ No unverified entries found');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Count knowledge items
|
|
246
|
+
console.log('\n📚 Knowledge inventory...');
|
|
247
|
+
const { episodeCount, insightCount } = countKnowledge(agentMindPath);
|
|
248
|
+
console.log(` • Episodes recorded: ${episodeCount}`);
|
|
249
|
+
console.log(` • Insights documented: ${insightCount}`);
|
|
250
|
+
|
|
251
|
+
// Summary
|
|
252
|
+
console.log('\n' + '='.repeat(50));
|
|
253
|
+
if (totalIssues === 0 && totalWarnings === 0) {
|
|
254
|
+
console.log('✅ Agent Mind is healthy!\n');
|
|
255
|
+
process.exit(0);
|
|
256
|
+
} else if (totalIssues === 0) {
|
|
257
|
+
console.log(
|
|
258
|
+
`⚠️ ${totalWarnings} warning${totalWarnings !== 1 ? 's' : ''} found (but no critical issues)\n`
|
|
259
|
+
);
|
|
260
|
+
process.exit(0);
|
|
261
|
+
} else {
|
|
262
|
+
console.log(`❌ ${totalIssues} critical issue${totalIssues !== 1 ? 's' : ''} found\n`);
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
module.exports = {
|
|
268
|
+
doctor
|
|
269
|
+
};
|