agentleFS
Agentic-Engineering-AgencyAgentic-Engineering-Agency/agentforge/CLAUDE.md

agentforge

CLAUDE.md4 starsChanged 9 months agoApache-2.0Archived repositoryView on GitHub

Read this file completely before starting any work. All rules are mandatory. For deep technical reference on Convex + Mastra integration patterns, read: docs/reference/TECH-REFERENCE.md A self-hosted AI agent framework: central daemon (like OpenClaw) + local dashboard. Built on Mastra + Convex. Architecture: - packages/runtime/ — Mastra daemon (persistent Node.js process, channels: HTTP/Discord/Telegram) - packages/cli/ — CLI: scaffold, manage, start, chat - packages/core/ — shared types + utilities - packages/cli/dist/default/ / packages/cli/templates/default/ — what agentforge create scaffolds Auth, billing, and cloud…

The file

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

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before writing any code: search the codebase, look for existing implementations.

    line 25
  2. Distinctive:

    Every Convex template file must be kept identical in these 3 git-tracked locations:

    line 119
  3. Very specific:

    Use pnpm sync-templates after any template change.

    line 126
  4. Distinctive:

    All 7 specs implementing the daemon architecture have been merged (SPEC-020 through SPEC-026).

    line 176
  5. Distinctive:

    All sensitive Convex functions internalized with thin public wrappers

    line 199
  6. Very specific:

    Use agentforge status to check connection

    line 221

≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.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
CLAUDE.md

CLAUDE.md — AgentForge Development Context

Read this file completely before starting any work. All rules are mandatory. For deep technical reference on Convex + Mastra integration patterns, read: docs/reference/TECH-REFERENCE.md


What is AgentForge?

A self-hosted AI agent framework: central daemon (like OpenClaw) + local dashboard. Built on Mastra + Convex.

Architecture:

  • packages/runtime/ — Mastra daemon (persistent Node.js process, channels: HTTP/Discord/Telegram)
  • packages/cli/ — CLI: scaffold, manage, start, chat
  • packages/core/ — shared types + utilities
  • packages/cli/dist/default/ / packages/cli/templates/default/ — what agentforge create scaffolds

Auth, billing, and cloud hosting are future concerns. Do not implement them now.


🚨 RULES — Non-Negotiable

1 · Audit Before Implementing

Before writing any code: search the codebase, look for existing implementations. Does it exist? Is it broken? Is it a stub? Document what you find first.

2 · SpecSafe-First Workflow

1. Write tests (watch them FAIL — proves tests are real)
2. Implement
3. pnpm test — must be GREEN
4. Fix any failures NOW before moving on

3 · Read docs/reference/TECH-REFERENCE.md Before Every Sprint

Critical rules are documented there. APIs change constantly. Key links:

4 · CLI First → Dashboard Second

  1. agentforge <command> — implement and test via CLI
  2. Dashboard view — comes after CLI works

5 · Architecture Rules

Mastra belongs in packages/runtime/ — NEVER in Convex actions

Running Mastra inside Convex Node.js actions produces 10-15s cold starts, no real streaming, and broken crypto. The daemon runs as a persistent process.

✅ packages/runtime/ → Mastra agent runtime
✅ convex/ → data layer only (agents config, apiKeys, logs, threads display)
❌ convex/chat.ts → DELETED (never put LLM calls in Convex)
❌ convex/lib/agent.ts → DELETED
❌ convex/mastraIntegration.ts → DELETED

Memory: use ConvexStore (not LibSQL)

// ✅ packages/runtime — use @mastra/convex for memory
import { ConvexStore } from '@mastra/convex'
import { ConvexVector } from '@mastra/convex'

// ❌ Wrong for daemon — LibSQL creates a local SQLite file per project
import { LibSQLStore } from '@mastra/libsql'

Convex runtime boundaries

// "use node" files → ONLY action / internalAction (NEVER query/mutation)
// Default V8 files → query, mutation, internalQuery, internalMutation

// ✅ Call internal functions correctly
await ctx.runQuery(internal.apiKeys.getDecryptedForProvider, { provider })
// ❌ Wrong — api.* is public (client-accessible)
await ctx.runQuery(api.apiKeys.getDecryptedForProvider, { provider })

API key encryption — Node.js only

// ✅ "use node" internalAction with node:crypto
import * as crypto from 'node:crypto'
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv)

// ❌ Never — crypto.subtle in V8 runtime → 10-19s latency
await crypto.subtle.deriveBits(...)  // too slow for per-request use

Agent model format

// ✅ Mastra model router format
model: 'openai/gpt-5.1'
model: 'anthropic/claude-opus-4-6'
model: 'moonshotai/kimi-k2.5'     // default daemon model

// ❌ Old BYOK pattern — no longer needed
model: { providerId, modelId, apiKey, url }

Tools — createTool, not magic strings

// ✅ Always use createTool from @mastra/core/tools
import { createTool } from '@mastra/core/tools'
export const myTool = createTool({
  id: 'my-tool',
  execute: async ({ query }) => { /* inputData directly, NOT { context } */ }
})

Streaming

// ✅ Always stream for channels
const stream = await agent.stream(messages, { threadId, resourceId })
for await (const chunk of stream.fullStream) { ... }

6 · Template Sync (3 git-tracked locations)

Every Convex template file must be kept identical in these 3 git-tracked locations:

packages/cli/templates/default/convex/  ← CANONICAL SOURCE
templates/default/convex/
convex/

packages/cli/dist/default/convex/ is gitignored — pnpm sync-templates handles it at build time. Use pnpm sync-templates after any template change.

7 · File Storage

// ✅ Real Convex file storage
const uploadUrl = await ctx.storage.generateUploadUrl()
// ❌ Never fake it
url: 'pending-upload'

8 · QA + Security After Every PR

  • pnpm test — all green
  • tsc --noEmit — 0 errors
  • pnpm audit — 0 high/critical vulnerabilities
  • Manual CLI test: agentforge start, agentforge chat, agentforge status
  • No hardcoded secrets

Security Patterns — Convex Function Visibility

Sensitive functions MUST be internal

// ✅ Sensitive operations → internalMutation / internalAction
export const censorMessage = internalMutation({ ... })  // pattern detection
export const create = internalAction({ ... })            // API key encryption

// ✅ Public wrappers → strip sensitive fields
export const censorText = mutation({                     // returns only { censoredText, secretsDetected }
  handler: async (ctx, args) => {
    const result = await ctx.runMutation(internal.vault.censorMessage, ...)
    return { censoredText: result.censoredText, secretsDetected: result.secretsDetected }
  }
})

// ❌ Never expose pattern names, storedSecrets, or encryption internals to clients

Public wrapper naming convention

Internal functionPublic wrapperPurpose
vault.censorMessagevault.censorTextStrips pattern names
apiKeys.createapiKeys.createKeyDelegates to encryption
apiKeys.updateapiKeys.updateKeyDelegates to encryption

Current Status (v0.12.24, March 2026)

Architecture Redesign Complete

All 7 specs implementing the daemon architecture have been merged (SPEC-020 through SPEC-026).

Sprint 3 (v0.12.24) — Public Launch Prep

  • #253: Security hardening + community readiness (PR merged)
    • censorMessage → internalMutation + censorText public wrapper (#239)
    • apiKeys.create/update → internalAction + createKey/updateKey wrappers
    • HTTP auth bypass documented with startup warning (#248)
    • Dependencies patched: undici ≥7.24.0, hono ≥4.12.7, fast-xml-parser ≥5.5.6 (#232)
    • SECURITY.md, issue/PR templates added
    • Git history scrubbed of hardcoded API key via git-filter-repo
    • Internal dev files removed (TASK.md, PROJECT_STATE.md, AGENTS.md → docs/development.md)
    • CONTRIBUTING.md updated: XOR → AES-256-GCM encryption docs

What Works (v0.12.24)

  • Full daemon model: agentforge start → persistent Mastra runtime
  • agentforge create / status / agents / models / keys / tokens / threads / logs / skills / dashboard / chat
  • HTTP channel with OpenAI-compatible POST /api/chat + GET /api/agents
  • Discord and Telegram channel adapters
  • Dynamic model fetching from all 8 provider APIs
  • Usage token tracking per request
  • AES-256-GCM API key encryption (Node.js only, never crypto.subtle)
  • SHA-256 token hashing — plaintext returned once at creation, validated by hash
  • Chat-scoped model override — per-thread model selection, config cascade
  • All sensitive Convex functions internalized with thin public wrappers
  • pnpm audit → 0 vulnerabilities
  • SECURITY.md, issue templates, PR template for community contributions

Key Architectural Decisions

  • Central daemon model (like OpenClaw, not per-project)
  • Channels v1: HTTP + Discord + Telegram
  • Memory: ConvexStore (not LibSQL) — dashboard visibility
  • Mastra runs in packages/runtime/ — never in Convex actions
  • Model override: per-thread (not per-agent) — creates temporary agent, never mutates cached agent
  • Sensitive Convex functions: always internal*, with thin public wrappers that strip sensitive data

Known Technical Debt (from multi-model audit)

  • 429 any casts in CLI commands (use typed FunctionReference instead)
  • 72 unreferenced exports (audit: public API surface vs dead code)
  • 81 untested public exports (priority: createStandardAgent, model registry, streaming utils)
  • ~50 silent catch blocks (add structured debug logging)

Live Test Deployments

  • hallowed-stork-858 — main test project at /tmp/af-npm-test/test-proj
  • Use agentforge status to check connection

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.