agentleFS
iamtouchskyeriamtouchskyer/memex/AGENTS.md

memex

AGENTS.md142 starsChanged 3 months agoMITView on GitHub

Detailed architecture reference: docs/ARCHITECTURE.md Zettelkasten memory for AI agents. Markdown cards in ~/.memex/cards/ with [[wikilinks]]. npm package @touchskyer/memex. Distributed as CLI + MCP server + Claude Code plugin + VS Code extension + Pi extension. Build has a known TS error (node-llama-cpp optional dep). Ignore it — it compiles fine for distribution. The rule: MCP tools and CLI are thin wrappers. All logic lives in src/commands/. All data access in src/lib/store.ts. Don't put logic in the wrong layer. If you…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository8 other files it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

28 rules. About 0 are common, 7 are distinctive, and 21 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 21

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Keep commands pure: return {output, exitCode} or {success, content/error}.

    line 45
  2. Very specific:

    Use .js extensions in all imports (Node16 ESM resolution).

    line 46
  3. Very specific:

    Test both nestedSlugs: false (default) and nestedSlugs: true when touching store.ts.

    line 47
  4. Very specific:

    Run npm test before declaring anything done.

    line 48
  5. Very specific:

    Add new MCP tools in operations.ts if they need hooks, in server.ts if they don't.

    line 49
  6. Very specific:

    Use zod for MCP tool input schemas (already imported in both MCP files).

    line 50
  7. Very specific:

    Don't replace the custom YAML stringifier in parser.ts with js-yaml — it produces block scalars (>-) that break downstream parsers.

    line 54
  8. Very specific:

    Don't put business logic in cli.ts — it's orchestration only.

    line 55
  9. Very specific:

    Don't make hooks throw. HookRegistry.run() swallows errors by design.

    line 56
  10. Very specific:

    Don't use gray-matter for stringification — only for parsing.

    line 57
  11. Very specific:

    Don't add heavy dependencies.

    line 58
  12. Very specific:

    Don't forget to call store.invalidateCache() after any write/delete path that bypasses writeCard()/archiveCard().

    line 59
  13. Distinctive:

    If you add a new MCP tool:

    line 63
  14. Very specific:

    Add in server.ts (no hooks) or operations.ts (with hooks)

    line 64
  15. Distinctive:

    If you add a new CLI command:

    line 68
  16. Distinctive:

    If you change card format / frontmatter:

    line 73
  17. Very specific:

    Update parser.ts (parse + stringify)

    line 74
  18. Very specific:

    Check store.ts (slug validation)

    line 75
  19. Distinctive:

    Ensure backward compat — old cards must still parse

    line 76
  20. Very specific:

    Update docs/ARCHITECTURE.md § Data Model

    line 77
  21. Distinctive:

    If you add an embedding provider:

    line 79
  22. Very specific:

    Add to EmbeddingProviderType union + createEmbeddingProvider() factory

    line 81
  23. Very specific:

    Add config fields in config.ts

    line 82
  24. Distinctive:

    Update auto-detection fallback chain (current order: OpenAI → Azure OpenAI → Local → error.

    line 83
  25. Distinctive:

    If you change sync behavior:

    line 85
  26. Very specific:

    All in src/lib/sync.ts (GitAdapter)

    line 86
  27. Very specific:

    All imported cards get source: flomo in frontmatter.

    line 104
  28. Very specific:

    Use flomoImportCommand for bulk parsing, or flomo_import_parse MCP tool to preview memos before curating.

    line 105

≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Memex — Agent Working Instructions

Detailed architecture reference: docs/ARCHITECTURE.md

What Is This

Zettelkasten memory for AI agents. Markdown cards in ~/.memex/cards/ with [[wikilinks]]. npm package @touchskyer/memex. Distributed as CLI + MCP server + Claude Code plugin + VS Code extension + Pi extension.

Before You Touch Anything

npm test          # must pass. vitest, 70% coverage threshold.

Build has a known TS error (node-llama-cpp optional dep). Ignore it — it compiles fine for distribution.

How The Code Is Layered

MCP tools (src/mcp/)  →  Commands (src/commands/)  →  Lib (src/lib/)  →  Filesystem (~/.memex/)
     ↑ client-facing         ↑ business logic           ↑ data access

The rule: MCP tools and CLI are thin wrappers. All logic lives in src/commands/. All data access in src/lib/store.ts. Don't put logic in the wrong layer.

Files You'll Actually Need

When you're changing...Read these first
Card read/write/slug behaviorsrc/lib/store.ts (164 lines — read all of it)
MCP tool behaviorsrc/mcp/operations.ts (high-level), src/mcp/server.ts (low-level)
Search (keyword or semantic)src/commands/search.ts (most complex file, ~390 lines)
Sync / git operationssrc/lib/sync.ts (GitAdapter, autoSync, autoFetch)
Embeddingssrc/lib/embeddings.ts (3 providers + cache)
Card parsing / frontmattersrc/lib/parser.ts (47 lines — tiny but critical)
Organize / graph analysissrc/commands/organize.ts
Claude Code plugin hookshooks/hooks.json
VS Code extensionvscode-extension/src/extension.ts
Pi extensionpi-extension/index.ts

Do / Don't

DO

  • Keep commands pure: return {output, exitCode} or {success, content/error}. Let CLI/MCP handle I/O.
  • Use .js extensions in all imports (Node16 ESM resolution).
  • Test both nestedSlugs: false (default) and nestedSlugs: true when touching store.ts.
  • Run npm test before declaring anything done.
  • Add new MCP tools in operations.ts if they need hooks, in server.ts if they don't.
  • Use zod for MCP tool input schemas (already imported in both MCP files).

DON'T

  • Don't replace the custom YAML stringifier in parser.ts with js-yaml — it produces block scalars (>-) that break downstream parsers.
  • Don't put business logic in cli.ts — it's orchestration only.
  • Don't make hooks throw. HookRegistry.run() swallows errors by design. Hooks are infrastructure.
  • Don't use gray-matter for stringification — only for parsing. The custom stringifyFrontmatter exists for a reason.
  • Don't add heavy dependencies. This is a 4-dep project (commander, gray-matter, zod, @modelcontextprotocol/sdk). Keep it that way.
  • Don't forget to call store.invalidateCache() after any write/delete path that bypasses writeCard()/archiveCard().

Mutation Checklist

If you add a new MCP tool:

  1. Add in server.ts (no hooks) or operations.ts (with hooks)
  2. Schema with zod, return { content: [{ type: "text", text }] }
  3. Add tests

If you add a new CLI command:

  1. Create src/commands/<name>.ts
  2. Register in src/cli.ts
  3. Add tests

If you change card format / frontmatter:

  1. Update parser.ts (parse + stringify)
  2. Check store.ts (slug validation)
  3. Ensure backward compat — old cards must still parse
  4. Update docs/ARCHITECTURE.md § Data Model

If you add an embedding provider:

  1. Implement EmbeddingProvider interface in embeddings.ts
  2. Add to EmbeddingProviderType union + createEmbeddingProvider() factory
  3. Add config fields in config.ts
  4. Update auto-detection fallback chain (current order: OpenAI → Azure OpenAI → Local → error; Ollama is explicit-only)

If you change sync behavior:

  1. All in src/lib/sync.ts (GitAdapter)
  2. autoSync() / autoFetch() are called by hooks — test offline tolerance

Key Design Decisions (Don't Undo These)

  • Atomic writes: writeCard() → .tmp → rename(). Prevents corruption.
  • Path safety: validateSlug() + assertSafePath() = no directory traversal. Ever.
  • Client source tagging: MCP server captures clientInfo.name at init, injects into source frontmatter. This is how we track which client wrote each card.
  • Hooks fail silently: They're git sync calls, not user-facing logic. If git is offline, don't crash.
  • Embedding cache invalidation: SHA-256 content hash per card. Stale entries cleaned on embedCards(). Don't switch to timestamp-based — content hash is correct.

Flomo Integration (Bidirectional Sync)

Memex has bidirectional sync with flomo. Two hard rules:

Flomo → Memex (Import)

  • Digest, never mechanical import. Flomo memos are fleeting notes, NOT Zettelkasten cards. The agent must read, curate, and rewrite into atomic insights.
  • All imported cards get source: flomo in frontmatter.
  • Use flomoImportCommand for bulk parsing, or flomo_import_parse MCP tool to preview memos before curating.
  • Quality bar: skip garbage (<150 bytes), merge related memos, extract only non-obvious insights.

Memex → Flomo (Push)

  • Anti-loopback: NEVER push source: flomo cards back to flomo. This is enforced in code (pushSingleCard + batch filter in flomoPushCommand). Don't remove it.
  • Push via webhook (flomoPushCommand). Webhook URL validated at both read and write time (defense in depth).

Code Locations

WhatWhere
All flomo logicsrc/commands/flomo.ts
MCP toolssrc/mcp/operations.ts (flomo_push, flomo_import_parse)
Anti-loopback guardpushSingleCard() line ~135, batch filter line ~410
Webhook validationisValidFlomoWebhookUrl() — HTTPS + flomoapp.com + /iwh/ prefix
Teststests/commands/flomo.test.ts, tests/commands/flomo-import.test.ts

Platform Integration Files

Claude Code:  hooks/hooks.json, skills/*, .claude-plugin/*
VS Code:      vscode-extension/
Pi:           pi-extension/index.ts

These are separate integration surfaces. Changing core code doesn't require updating them unless you change tool signatures or card format.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.