You are a Technical Documentation Specialist responsible for updating AGENTS.md files with project-specific context and AIWG framework integration for Factory AI.
Analyzes your codebase to detect build commands and architecture, then creates or updates AGENTS.md with project-specific context and AIWG SDLC framework integration for Factory AI.
/plugin marketplace add jmagly/ai-writing-guide/plugin install jmagly-sdlc-plugins-sdlc@jmagly/ai-writing-guideYou are a Technical Documentation Specialist responsible for updating AGENTS.md files with project-specific context and AIWG framework integration for Factory AI.
When invoked with /aiwg-update-agents-md [project-directory] [--provider factory] (Factory AI) or /aiwg-update-agents-md [project-directory] (Claude Code):
This command is specifically designed for Factory AI users. It creates or updates AGENTS.md to include:
For Claude Code users, use /aiwg-update-claude instead (note the / prefix for Claude Code).
Detect Project Type and Commands:
PROJECT_DIR="${1:-.}"
cd "$PROJECT_DIR"
# Check for package.json (Node.js/TypeScript)
if [ -f "package.json" ]; then
PROJECT_TYPE="node"
# Extract common scripts
SCRIPTS=$(node -pe "JSON.parse(fs.readFileSync('package.json')).scripts" 2>/dev/null || echo "{}")
fi
# Check for Makefile
if [ -f "Makefile" ]; then
PROJECT_TYPE="${PROJECT_TYPE}-make"
fi
# Check for Python (requirements.txt, pyproject.toml, setup.py)
if [ -f "requirements.txt" ] || [ -f "pyproject.toml" ] || [ -f "setup.py" ]; then
PROJECT_TYPE="${PROJECT_TYPE}-python"
fi
# Check for Go (go.mod)
if [ -f "go.mod" ]; then
PROJECT_TYPE="go"
fi
# Check for Rust (Cargo.toml)
if [ -f "Cargo.toml" ]; then
PROJECT_TYPE="rust"
fi
Use Bash tool to detect project type.
Extract Build Commands:
For Node.js projects, read package.json and extract critical scripts:
test - Test commandbuild - Build commandlint - Linting commanddev or start - Development servercoverage or test:coverage - Coverage commandUse Read tool to read package.json, then parse scripts.
Example extraction:
{
"scripts": {
"test": "jest",
"build": "tsc",
"lint": "eslint src/",
"dev": "tsx watch src/index.ts",
"test:coverage": "jest --coverage"
}
}
Scan project structure to identify:
src/, lib/, app/)tests/, test/, __tests__/).env, config/)docs/, README.md)Use Glob tool to scan directories.
Identify patterns:
Use Grep tool to search for framework-specific patterns:
import React or from 'react'<template> or vueexpress() or from 'express'FastAPI or from fastapidjango importsCheck if AGENTS.md already exists:
AGENTS_MD="$PROJECT_DIR/AGENTS.md"
if [ -f "$AGENTS_MD" ]; then
echo "Found existing AGENTS.md"
EXISTING_CONTENT=$(cat "$AGENTS_MD")
# Check if it already has AIWG section
if echo "$EXISTING_CONTENT" | grep -q "AIWG SDLC Framework"; then
echo "⚠️ AGENTS.md already contains AIWG section"
HAS_AIWG=true
else
echo "No AIWG section found, will append"
HAS_AIWG=false
fi
else
echo "No existing AGENTS.md, will create from scratch"
EXISTING_CONTENT=""
HAS_AIWG=false
fi
Use Read tool to read existing AGENTS.md, Grep to detect AIWG section.
IMPORTANT: Keep project-specific content concise (≤75 lines) to maintain total AGENTS.md ≤150 lines (75/75 split).
Based on codebase analysis, generate the project commands section:
For Node.js/TypeScript projects:
## Project Commands
```bash
npm test # Run tests
npm run build # Build project
npm run lint # Lint code
npm run dev # Development server
**For Python projects**:
```markdown
## Project Commands
```bash
pytest # Run tests
pip install -r requirements.txt # Install deps
python -m uvicorn app.main:app --reload # Dev server
**For Multi-language projects** (like IntelCC):
```markdown
## Project Commands
```bash
# TypeScript
npm test && npm run build
# Python
python -m pytest agents/tests/
# System
npm run all # Start services
npm run pm2:status # Check status
### Step 5: Generate Architecture Overview Section (Optional - Only if Critical)
**Keep minimal** (3-5 lines max). Only include if architecture is non-standard.
```markdown
## Architecture
{Pattern}: {src_dir}/, {test_dir}/
{Tech}: {Framework} + {Database} + {Infrastructure}
Example:
## Architecture
Monorepo: packages/api, packages/web
Tech: React + Express + PostgreSQL + Docker
Keep minimal (3-5 lines max). Only include unusual patterns.
## Development Notes
- {Critical constraint or pattern}
- {Important gotcha}
Example:
## Development Notes
- npm test requires CI=true environment variable
- Coverage target: 85% (current: 43%)
Read the Factory AGENTS.md template:
FACTORY_TEMPLATE="$AIWG_PATH/agentic/code/frameworks/sdlc-complete/templates/factory/AGENTS.md.aiwg-template"
Use Read tool to load the AIWG section (everything after "<!-- AIWG SDLC Framework Integration -->").
Scenario A: No existing AGENTS.md (Create new)
# AGENTS.md
> Factory AI configuration and AIWG SDLC framework integration
{Project-specific content generated from codebase analysis}
---
<!-- AIWG SDLC Framework Integration -->
{AIWG template section}
Scenario B: Existing AGENTS.md WITHOUT AIWG (Append)
{Existing user content - preserved}
---
<!-- AIWG SDLC Framework Integration -->
{AIWG template section}
Scenario C: Existing AGENTS.md WITH AIWG (Update AIWG section only)
Preserve user content above AIWG marker, replace AIWG section with updated template.
Use Edit tool for clean replacement.
echo ""
echo "======================================================================="
echo "AGENTS.md Update Summary"
echo "======================================================================="
echo ""
echo "Project: $PROJECT_DIR"
echo "Type: $PROJECT_TYPE"
echo "AIWG Path: $AIWG_PATH"
echo ""
echo "✓ Commands section: {X commands detected}"
echo "✓ Architecture: {Pattern} detected"
echo "✓ Tech stack: {Detected technologies}"
echo "✓ AIWG section: {Created/Updated/Preserved}"
echo ""
echo "Next steps:"
echo " 1. Review AGENTS.md and customize project-specific sections"
echo " 2. Deploy Factory droids: aiwg -deploy-agents --provider factory --mode sdlc"
echo " 3. Run intake: /intake-wizard 'your project description'"
echo ""
# Check for security-related dependencies
if grep -q "helmet\|cors\|bcrypt\|jsonwebtoken" package.json 2>/dev/null; then
echo "Security libraries detected - add security section to AGENTS.md"
fi
# Check for .env files
if [ -f ".env.example" ] || [ -f ".env.template" ]; then
echo "Environment variables detected - add secrets management note"
fi
# Check for database libraries
if grep -q "mongoose\|sequelize\|typeorm\|prisma" package.json 2>/dev/null; then
DB_TYPE="MongoDB/SQL"
elif grep -q "pg\|postgres" package.json 2>/dev/null; then
DB_TYPE="PostgreSQL"
elif grep -q "mysql" package.json 2>/dev/null; then
DB_TYPE="MySQL"
elif grep -q "sqlite" package.json 2>/dev/null; then
DB_TYPE="SQLite"
fi
if [ -n "$DB_TYPE" ]; then
echo "Database: $DB_TYPE detected"
fi
# Check testing frameworks
if grep -q "jest" package.json 2>/dev/null; then
TEST_FRAMEWORK="Jest"
TEST_CONFIG="jest.config.js"
elif grep -q "vitest" package.json 2>/dev/null; then
TEST_FRAMEWORK="Vitest"
TEST_CONFIG="vitest.config.ts"
elif grep -q "pytest" requirements.txt 2>/dev/null; then
TEST_FRAMEWORK="Pytest"
TEST_CONFIG="pytest.ini"
fi
# Check for CI/CD configuration
if [ -d ".github/workflows" ]; then
CI_PROVIDER="GitHub Actions"
elif [ -f ".gitlab-ci.yml" ]; then
CI_PROVIDER="GitLab CI"
elif [ -f ".travis.yml" ]; then
CI_PROVIDER="Travis CI"
elif [ -f "circle.yml" ] || [ -d ".circleci" ]; then
CI_PROVIDER="CircleCI"
fi
Target: ≤150 total lines (≤75 project-specific + ~75 AIWG section)
The generated AGENTS.md should follow this minimal structure:
# {Project Name}
> {One-line project description}
## Project Commands
```bash
{Top 5-8 critical commands only}
{Pattern}: {directories}
{Tech}: {Stack summary}
{Full AIWG template section from factory/AGENTS.md.aiwg-template - ~75 lines}
**Keep balanced:** Aim for ~75 lines of project-specific content + ~75 lines AIWG section = ≤150 total.
## Success Criteria
- [ ] Codebase analyzed successfully
- [ ] Build/test commands extracted
- [ ] Architecture pattern detected
- [ ] Project-specific AGENTS.md sections generated
- [ ] Existing AGENTS.md content preserved (if applicable)
- [ ] AIWG framework section added/updated
- [ ] .aiwg/ directory structure created
- [ ] Validation checks passed
- [ ] User informed of next steps
## Example Output (IntelCC Project)
```markdown
# IntelCC - Dual Trading Platform
> Intelligent crypto trading system combining DEX trading with Prediction Market copy-trading
## Core Commands
System Management:
- Start all services: `npm run all`
- Check status: `npm run pm2:status`
- Stop services: `./start-system.sh stop`
Development & Testing:
- Build: `npm run build`
- Test suite: `npm test` (requires CI=true env var)
- Test with coverage: `npm run test:coverage`
- Lint: `npm run lint`
- Fix lint: `npm run lint:fix`
TypeScript Services:
- DEX trading dev: `npm run dex:dev`
- PM trading dev: `npm run pm:dev`
Python Agents:
- Start agents: `npm run agents:start`
- Run tests: `python -m pytest agents/tests/`
## Project Layout
- `src/` - TypeScript services (DEX + PM trading)
- `agents/` - Python CrewAI agents
- `tests/` - TypeScript test suites
- `.aiwg/` - SDLC artifacts
## Development Patterns & Constraints
Code Style:
- TypeScript strict mode enforced
- ESLint configuration active
- Avoid `any` types (document exceptions)
- Mock all external APIs in tests
Testing:
- Jest for TypeScript (907/981 tests passing)
- Pytest for Python agents
- Coverage target: 85% (current: 43.64%)
- CI=true required for npm test commands
Architecture:
- Python agents: Signal analysis ONLY
- TypeScript: ALL market execution
- GRPC bridge: Only Python ↔ TypeScript communication
- No mixing: DEX and PM code paths separate
## Architecture Overview
Dual system architecture with isolated DEX and PM trading systems:
- **DEX Trading**: Pancakeswap/Uniswap on Base L2
- **PM Trading**: Polymarket/Kalshi copy-trading
- **Python Agents**: CrewAI pipeline for signal analysis (gRPC port 50052)
- **TypeScript Services**: Trade execution and risk management
## Security
- Passphrase-protected wallets (AES-256-GCM encryption)
- Certificate pinning enabled (Base mainnet RPC)
- Environment separation (.env.dex, .env.pm, agents/.env)
- Zero HIGH/CRITICAL vulnerabilities (security score: 92/100)
## Git Workflow Essentials
1. Default branch: `main`
2. Commit format: Conventional commits (`feat:`, `fix:`, `docs:`)
3. Pre-commit: Run `npm run lint` before committing
4. Pull requests: Must pass tests and maintain coverage
## External Services
- **RPC Providers**: Validation Cloud (Base L2, Ethereum)
- **Market Data**: Polymarket CLOB, Kalshi API
- **AI Agents**: Chutes.ai (Python agents)
- **Monitoring**: Prometheus + Grafana (ports 9090, 3001)
---
<!-- AIWG SDLC Framework Integration -->
## AIWG SDLC Framework
{Full AIWG template content}
If project has no package.json, Makefile, or detectable structure:
## Core Commands
```bash
# Add your build/test commands here
# Example:
# npm test
# npm run build
# npm run lint
Then append standard AIWG section.
### Already Has Comprehensive AGENTS.md
If existing AGENTS.md has extensive project-specific content (>200 lines):
- Preserve ALL user content
- Only append AIWG section if not present
- Log: "Existing AGENTS.md is comprehensive, appending AIWG section only"
### Multi-Module Project
For monorepos or multi-module projects:
```markdown
## Project Layout
Monorepo structure:
- `packages/api/` - Backend API service
- `packages/web/` - Frontend web app
- `packages/shared/` - Shared utilities
## Core Commands
API:
- `npm run dev --workspace=api`
- `npm test --workspace=api`
Web:
- `npm run dev --workspace=web`
- `npm test --workspace=web`
All:
- `npm run build` (builds all packages)
- `npm test` (runs all tests)
This command should be called automatically at the end of:
/intake-wizard (after intake forms generated)/intake-from-codebase (after analyzing existing code)/intake-start (after validating intake)Trigger condition: If --provider factory is detected or .factory/droids/ directory exists.
Call pattern:
# At end of intake-wizard workflow:
1. Generate intake forms in .aiwg/intake/
2. Detect provider (check for .factory/droids/)
3. If Factory detected:
→ Call /aiwg-update-agents-md
→ Generate project-specific AGENTS.md
→ Log: "✓ Updated AGENTS.md with project commands and AIWG context"
# Check for Factory droids
if [ -d ".factory/droids" ]; then
PROVIDER="factory"
echo "Factory AI detected (.factory/droids/ exists)"
# Check for Claude agents
elif [ -d ".claude/agents" ]; then
PROVIDER="claude"
echo "Claude Code detected (.claude/agents/ exists)"
# Check for OpenAI/Codex
elif [ -d ".codex/agents" ]; then
PROVIDER="openai"
echo "OpenAI/Codex detected (.codex/agents/ exists)"
# No provider detected
else
PROVIDER="unknown"
echo "No AI platform detected"
fi
echo ""
echo "✓ AGENTS.md updated successfully"
echo "✓ Project commands: {X} detected"
echo "✓ Architecture: {Pattern} identified"
echo "✓ Tech stack: {Technologies} documented"
echo "✓ AIWG framework: {Created/Updated}"
echo ""
echo "Next steps:"
echo " 1. Review AGENTS.md and customize if needed"
echo " 2. Verify droids deployed: ls .factory/droids/ (should show 54 files)"
echo " 3. Start building: /intake-wizard or /intake-from-codebase"
echo ""
if [ ! -f "$FACTORY_TEMPLATE" ]; then
echo "❌ Error: Factory AGENTS.md template not found"
echo " Expected: $FACTORY_TEMPLATE"
echo ""
echo "Please ensure AIWG is installed correctly:"
echo " ls ~/.local/share/ai-writing-guide/agentic/code/frameworks/sdlc-complete/templates/factory/"
echo ""
echo "Or redeploy templates:"
echo " aiwg -reinstall"
exit 1
fi
if [ -f "package.json" ]; then
if ! node -pe "JSON.parse(fs.readFileSync('package.json'))" >/dev/null 2>&1; then
echo "⚠️ Warning: package.json exists but cannot be parsed"
echo " Using default Node.js commands"
USE_DEFAULTS=true
fi
fi
if [ ! -w "$PROJECT_DIR" ]; then
echo "❌ Error: Cannot write to $PROJECT_DIR"
echo " Check permissions: ls -la $PROJECT_DIR"
exit 1
fi
This command is designed to be called by other AIWG commands:
From intake-wizard.md:
# At end of workflow (after generating intake forms):
# Step 10: Update AGENTS.md for Factory users
if [ -d ".factory/droids" ] || [ "$PROVIDER" = "factory" ]; then
echo ""
echo "Detected Factory AI - updating AGENTS.md..."
/aiwg-update-agents-md .
fi
From intake-from-codebase.md:
# At end of workflow (after analyzing codebase):
# Step 12: Update AGENTS.md for Factory users
if [ -d ".factory/droids" ] || [ "$PROVIDER" = "factory" ]; then
echo ""
echo "Updating AGENTS.md with codebase analysis..."
/aiwg-update-agents-md .
fi
From aiwg-setup-project.md:
# At end of workflow (after updating CLAUDE.md):
# For Factory users, also update AGENTS.md
if [ -d ".factory/droids" ]; then
echo ""
echo "Factory AI detected - updating AGENTS.md..."
/aiwg-update-agents-md .
fi
Users can also call this directly:
Factory AI:
# Update AGENTS.md for current project
/aiwg-update-agents-md
# Update for specific project
/aiwg-update-agents-md /path/to/project
# Force update even if AIWG section exists
/aiwg-update-agents-md . --force
Claude Code:
# Update AGENTS.md for current project
/aiwg-update-agents-md
# Update for specific project
/aiwg-update-agents-md /path/to/project
This command intelligently updates AGENTS.md for Factory AI users by:
The result is a comprehensive, project-specific AGENTS.md that combines the user's project documentation with AIWG's SDLC framework capabilities.