Skip to content

RaheesAhmed/SajiCode

Repository files navigation

SajiCode

The AI engineering team in your terminal.

17 specialized agents Β· 21 expert skills Β· 3-layer memory Β· 23 security checks
Builds production software, not prototypes.

Stars License npm Node

Why Β· Quickstart Β· WhatsApp Β· How It Works Β· Architecture Β· Features Β· Memory Β· Security Β· Models Β· MCP Β· Contributing


SajiCode Demo


Why SajiCode?

Every AI coding assistant today uses a single agent for everything. This falls apart at scale:

Problem Result
No specialization The same model writes code, tests, and security reviews β€” equally badly
Context loss Large changes make the model forget what it just built
Placeholder code // TODO: implement later ships to production
No autonomy You become the project manager of your AI assistant

SajiCode replaces the single agent with a distributed team of 17 specialists β€” exactly how real engineering teams are structured.

  • PM plans, backend builds APIs, frontend builds UI β€” in parallel
  • QA writes tests and security scans vulnerabilities β€” after every build
  • A 3-layer judgment middleware blocks placeholder code before it reaches disk
  • Each agent owns a territory β€” backend cannot touch frontend files and vice versa

Quickstart

# Install globally
npm install -g sajicode

# Or run without installing
npx sajicode
# Local model β€” no API key needed
sajicode -p ollama -m llama3.1:70b

# Cloud providers
sajicode -p openai    -m gpt-4.1
sajicode -p google    -m gemini-2.5-flash
sajicode -p anthropic -m claude-sonnet-4-20250514

# Headless mode for CI/CD
sajicode build "Fix the login bug and write tests" --headless

Environment Variables

export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="..."           # or GEMINI_API_KEY
export ANTHROPIC_API_KEY="sk-ant-..."
export TAVILY_API_KEY="tvly-..."      # optional β€” enables web search

WhatsApp Integration

Send coding tasks from your phone. SajiCode connects directly to WhatsApp via WebSocket β€” no third-party service, no extra API key.

sajicode --channels whatsapp

On first run, a QR code appears in your terminal. Scan it with WhatsApp β†’ Settings β†’ Linked Devices β†’ Link a Device. Auth is saved to ~/.sajicode/whatsapp-auth/ and persists across all projects.

Phone (WhatsApp) β†’ Baileys WebSocket β†’ Channel Adapter β†’ Agent Core β†’ WhatsApp Reply

Details:

  • Uses @whiskeysockets/baileys β€” pure WebSocket, no browser, no Selenium
  • Auto-reconnects on disconnect
  • Responses are chunked to respect WhatsApp's 4096-character limit
  • Terminal and WhatsApp run side-by-side

Two Modes

Mode Who uses it Behavior
Admin (default) You, the developer Your messages trigger coding tasks
Personal Bot Your contacts AI replies to incoming messages in your style

Configure in .sajicode/config.json:

// Admin Mode β€” send tasks from your phone
{
  "whatsapp": { "enabled": true, "mode": "admin" }
}

// Personal Bot Mode β€” AI replies as you
{
  "whatsapp": {
    "enabled": true,
    "mode": "personal",
    "personalBotPrompt": "Reply like Rahees β€” direct, friendly, use emojis sometimes."
  }
}

Coming soon: Discord and Telegram via the same adapter pattern.


How It Works

1 β€” Describe what to build

>_ build a fullstack task manager with Express, SQLite, and a React dashboard

2 β€” PM Agent architects the solution

Scans your codebase with collect_repo_map, produces architecture.md with system diagrams, API tables, and file ownership β€” then presents the plan before any code is written.

3 β€” Parallel delegation to specialists

PM Agent
  β”œβ”€β–Ά Backend Lead   β†’ "Build Express REST API in src/routes/, src/models/"
  β”œβ”€β–Ά Frontend Lead  β†’ "Build React dashboard in src/components/, src/pages/"
  β”œβ”€β–Ά QA Lead        β†’ "Write tests for all endpoints and components"
  β”œβ”€β–Ά Security Lead  β†’ "Audit for XSS, injection, hardcoded secrets"
  └─▢ Review Agent   β†’ "Final quality gate β€” no TODOs, no broken imports"

4 β€” Leads delegate further

Backend Lead spawns api-builder and db-designer concurrently. Frontend Lead spawns component-builder and style-designer. Every layer runs in parallel.

5 β€” Production-ready output

Every file passes through judgment middleware (placeholder code blocked), QA testing, security audit, and final review before the task closes.


Architecture

                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚   PM Agent   β”‚
                      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚        β”‚         β”‚         β”‚        β”‚
     β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”
     β”‚ Backend β”‚β”‚ Front β”‚β”‚   QA   β”‚β”‚  Sec.  β”‚β”‚Deploy β”‚
     β”‚  Lead   β”‚β”‚  Lead β”‚β”‚  Lead  β”‚β”‚  Lead  β”‚β”‚  Lead β”‚
     β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜β””β”€β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜β””β”€β”€β”€β”¬β”€β”€β”€β”˜
          β”‚         β”‚         β”‚        β”‚         β”‚
       api  db   comp style  unit integ vuln  dep  docker ci
       bldr dsgn  bldr dsgn  tstr tstr scan  aud   spec spec

1 PM + 6 Leads + 10 Sub-agents = 17 agents total

Each agent has owned directories it can write, forbidden paths it must never touch, persistent memory across sessions, and access to 21 expert skill files.

The Team

Agent Sub-Agents Territory Role
PM Agent All Leads Orchestration Architecture, delegation, output validation
Backend Lead api-builder, db-designer src/routes/, src/models/, src/services/ APIs, database, auth, server logic
Frontend Lead component-builder, style-designer src/components/, src/pages/, public/ UI, responsive design, animations
QA Lead unit-tester, integration-tester tests/, __tests__/ Coverage, TDD, edge cases
Security Lead vuln-scanner, dep-auditor Security policies OWASP scanning, dependency audit
Deploy Lead docker-specialist, ci-specialist Dockerfile, .github/ Docker, CI/CD, hosting
Review Agent β€” Read-only Final gate β€” no TODOs or stubs allowed

Features

Judgment Middleware β€” Zero Placeholder Code

A 3-layer protection system wraps every tool call:

  1. Risk assessment β€” warns on destructive operations (rm -rf, DROP TABLE) and sensitive paths (.env, credentials)
  2. Placeholder blocking β€” blocks write_file if content contains TODO, FIXME, empty function bodies, or stub implementations. Agents must write real code or fail
  3. Loop detection β€” breaks infinite loops when an agent calls the same tool identically 3+ times

23-Check Security System

Three gates on every shell command before execution:

Gate 1 β€” Pattern Detection (23 regex checks)

  • Destructive: rm -rf, mkfs, truncate, shred, partition tools
  • Exfiltration: curl POST, wget POST, nc -l, SSH tunnels
  • Privilege: sudo, chmod +s, chown root
  • System: crontab, systemctl, iptables, /etc/hosts
  • Execution: eval, download-pipe patterns, base64 decode

Gate 2 β€” Context Analysis

  • Command chaining (&&, ||, ;) and piping
  • Working directory (sensitive path detection)
  • Recent command history (repeated dangerous patterns)

Gate 3 β€” Risk Scoring (0–100)

Score Action
0–40 Auto-approved
41–60 Logged, allowed
61–80 Requires HITL approval
81–100 Blocked immediately
npm install express          # βœ… Auto-approved (score: 12)
rm -rf node_modules          # ⚠️  Logged but allowed (score: 55)
rm -rf / --no-preserve-root  # πŸ›‘ Blocked (score: 98)

See SECURITY_CHECKS.md for all 23 checks.

Human-in-the-Loop (HITL)

Optional approval system for shell commands and file deletions:

{
  "humanInTheLoop": {
    "enabled": true,
    "tools": {
      "execute":     { "allowedDecisions": ["approve", "edit", "reject"] },
      "delete_file": { "allowedDecisions": ["approve", "reject"] }
    },
    "allowedCommands": ["npm install", "npm run", "mkdir", "node "]
  }
}

Safe commands are auto-approved. Everything else requires explicit confirmation.

Three-Layer Memory System

Intelligent memory architecture with 70% token reduction compared to naive full-context loading:

.sajicode/
β”œβ”€β”€ config.json            # Model, HITL, and risk settings
β”œβ”€β”€ architecture.md        # Current project architecture plan
β”œβ”€β”€ whats_done.md          # Shared team log β€” append-only
β”œβ”€β”€ memories/
β”‚   β”œβ”€β”€ pointer-index.txt  # Layer 1: Always loaded (150-char summaries)
β”‚   β”œβ”€β”€ topics/            # Layer 2: On-demand detailed knowledge
β”‚   β”‚   β”œβ”€β”€ api-design.md
β”‚   β”‚   β”œβ”€β”€ database-schema.md
β”‚   β”‚   └── frontend-patterns.md
β”‚   └── transcripts/       # Layer 3: Search-only raw history
β”‚       └── 2026-04-23.log
β”œβ”€β”€ agents/                # Per-agent structured JSON memory
β”‚   β”œβ”€β”€ backend-lead.json
β”‚   └── frontend-lead.json
└── mcp-servers.json       # MCP server configurations
Layer What When Loaded
Layer 1 β€” Pointer Index 150-char topic summaries Always
Layer 2 β€” Topic Files Full knowledge per topic On-demand via read_topic()
Layer 3 β€” Transcripts Raw conversation history Search-only via search_transcripts()

See MEMORY_SYSTEM.md for complete documentation.

Multi-Provider LLM Support

Provider Flag Models
Ollama (local) -p ollama llama3.1:70b, deepseek-v3.1:671b-cloud
OpenAI -p openai gpt-4.1, gpt-4o
Google -p google gemini-2.5-flash, gemini-2.5-pro
Anthropic -p anthropic claude-sonnet-4-20250514

Codebase Intelligence

collect_repo_map scans your entire project and extracts function, class, and interface signatures across 7 languages (TypeScript, JavaScript, Python, Go, Java, Rust, Ruby). Agents get a ~50-token condensed map per file instead of loading 500+ raw tokens.

Headless & CI/CD Mode

SajiCode runs fully unattended in deployment pipelines. Use --headless to trigger agents for test generation, code review, or security audits inside GitHub Actions. Pre- and post-action hooks integrate with existing build systems.


21 Expert Skills

Skills are modular knowledge files loaded on-demand via progressive disclosure β€” agents read only what the current task requires.

Category Skill Capability
Core superpowers Engineering workflow, multi-file refactoring, code quality
debugger Error analysis, git bisect, memory profiling
web-research Package evaluation, technology comparison
Full-Stack fullstack-app-generator Framework selection, auth, schema, deployment
api-architect REST/GraphQL, OAuth/JWT, webhooks, rate limiting
nodejs Express/Fastify/Hono, Redis, WebSockets, BullMQ
nextjs App Router, server actions, ISR/SSG/SSR
python-engineer FastAPI, pytest, Typer CLI, pandas
Frontend frontend-design Design systems, animation, accessibility
shadcn-ui Forms, data tables, theming, composition
styling CSS architecture, design tokens, container queries
3d-web-experience Three.js, React Three Fiber, scroll-driven 3D
Infrastructure database Prisma, Drizzle, query optimization, N+1 prevention
devops Docker, GitHub Actions, Vercel/AWS, monitoring
security OWASP Top 10, auth, CSP headers, secrets management
testing Unit/integration/E2E (Playwright), mocking, CI config
performance-optimizer Core Web Vitals, bundle analysis, memory leak detection
Specialized ai-engineer LangGraph agents, RAG pipelines, prompt engineering
architect System design, CQRS, event-driven, ADR templates
mcp-server MCP tools, resources, prompts, transports
mobile-app React Native, Expo Router, offline-first, push notifications

MCP Integration

SajiCode connects to Model Context Protocol servers, giving agents access to external tools and data sources.

πŸ“– Full MCP Integration Guide β†’

Create .sajicode/mcp-servers.json:

{
  "mcpServers": {
    "code-context": {
      "command": "npx",
      "args": ["-y", "@anthropic/code-context-server", "{{projectPath}}"],
      "transport": "stdio"
    },
    "database": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sqlite", "./data/app.db"],
      "transport": "stdio"
    }
  }
}

{{projectPath}} is replaced automatically with your project's absolute path. MCP tools are injected into the PM agent and available immediately.


CLI Reference

Commands

Command Description
/init Scan project and generate SAJICODE.md context file
/status Show session info β€” thread, model, context, HITL status
/undo <file> Restore the last agent-modified file from snapshot
/snapshots List recent file snapshots
/help List all available commands
/clear Clear the terminal
/exit Shut down all agents and MCP connections

Flags

sajicode [options]

  -p, --provider <name>   LLM provider: ollama | openai | google | anthropic
  -m, --model <name>      Model name
  -c, --channels <list>   Comma-separated channels to enable (e.g. whatsapp)
  -H, --headless          Headless mode β€” no UI, ideal for CI/CD

Memory Tools (Available to Agents)

Tool Purpose
read_memory_index View all available topics (Layer 1)
read_topic(name) Load detailed topic knowledge (Layer 2)
write_memory_topic(topic, content, summary) Save new knowledge with 150-char summary
search_transcripts(pattern) Grep raw history (Layer 3)
append_transcript(content) Log to daily transcript
transcript_stats View transcript file sizes

Project Structure

src/
β”œβ”€β”€ index.ts                  # REPL entrypoint, HITL handling, stream processing
β”œβ”€β”€ agents/
β”‚   β”œβ”€β”€ index.ts              # createSajiCode() β€” main agent factory
β”‚   β”œβ”€β”€ agent-factory.ts      # Dynamic agent creation from AgentSpec presets
β”‚   β”œβ”€β”€ domain-heads.ts       # Lead agent wrappers
β”‚   β”œβ”€β”€ context.ts            # Project context and memory loading
β”‚   β”œβ”€β”€ judgment.ts           # 3-layer protection middleware
β”‚   └── onboarding.ts         # Interactive project setup
β”œβ”€β”€ channels/
β”‚   β”œβ”€β”€ channel.ts            # Unified ChannelAdapter interface
β”‚   β”œβ”€β”€ whatsapp.ts           # WhatsApp adapter (Baileys)
β”‚   └── router.ts             # Routes channel messages β†’ agent core
β”œβ”€β”€ cli/
β”‚   β”œβ”€β”€ renderer.ts           # StreamRenderer β€” terminal UI with markdown
β”‚   β”œβ”€β”€ index.ts              # Commander CLI (build, init, audit)
β”‚   └── progress.ts           # Progress bar tracking
β”œβ”€β”€ prompts/
β”‚   β”œβ”€β”€ pm.ts                 # PM system prompt
β”‚   └── specialists.ts        # Domain lead prompts
β”œβ”€β”€ llms/
β”‚   └── provider.ts           # Multi-provider LLM factory
β”œβ”€β”€ mcp/
β”‚   └── MCPClient.ts          # MCP server connection manager
β”œβ”€β”€ memory/
β”‚   └── agent-memory.ts       # Structured JSON agent memory
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ context-tools.ts      # LangChain context, memory, and log tools
β”‚   β”œβ”€β”€ repo-map.ts           # Codebase symbol scanner (7 languages)
β”‚   └── web-search.ts         # Tavily web search
β”œβ”€β”€ types/
β”‚   └── config.ts             # TypeScript types, AgentRole, icons, labels
└── utils/
    β”œβ”€β”€ platform.ts           # OS detection and platform-specific prompts
    └── skills.ts             # Skill auto-discovery

Contributing

git clone https://github.com/raheesahmed/sajicode.git
cd sajicode
npm install
npm run build

Workflow:

  1. Edit TypeScript in src/
  2. npm run build to compile
  3. node dist/index.js to test
  4. Add new skills in skills/<name>/SKILL.md

PRs for new skills, LLM providers, and agent improvements are welcome.


License

MIT β€” see LICENSE

Built by Rahees Ahmed

About

AI engineering team in your terminal | Builds production software, not prototypes.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors