Skip to content

Latest commit

Β 

History

History
326 lines (256 loc) Β· 11.6 KB

File metadata and controls

326 lines (256 loc) Β· 11.6 KB

πŸš€ AI Stack Orchestrator v2

Config-driven macOS AI development environment β€” extensible, reliable, and maintainable.

Add a new agent = add a folder. No code changes.


Architecture

AI_SETUP/
β”œβ”€β”€ setup.sh                  # Bash bootstrap β†’ installs brew+node, runs orchestrator
β”œβ”€β”€ nuke.sh                   # Bash bootstrap β†’ runs teardown
β”œβ”€β”€ package.json / tsconfig.json
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ orchestrate.ts        # Main entry: foundations β†’ select agents β†’ install β†’ MCP β†’ auth
β”‚   β”œβ”€β”€ nuke.ts               # Teardown: select agents β†’ uninstall β†’ cleanup β†’ remove foundations
β”‚   β”œβ”€β”€ ai-init.ts            # Project scaffolder: select agent β†’ copy scaffold + plugins
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ types.ts          # AgentConfig, AgentDriver, PluginConfig, Context interfaces
β”‚   β”‚   β”œβ”€β”€ registry.ts       # Auto-discovers agents/ and plugins/ folders
β”‚   β”‚   β”œβ”€β”€ config.ts         # Reads + validates agent.json
β”‚   β”‚   └── runner.ts         # Builds Context objects for drivers
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ ui.ts             # Terminal output (chalk colors, headers, steps)
β”‚   β”‚   β”œβ”€β”€ shell.ts          # exec, retry, safeRm, sudoRm
β”‚   β”‚   β”œβ”€β”€ prompts.ts        # Interactive menus (inquirer)
β”‚   β”‚   β”œβ”€β”€ mcp.ts            # Write MCP configs to disk
β”‚   β”‚   └── template.ts       # Deep-copy scaffold dirs with {{VAR}} replacement
β”‚   └── foundations/
β”‚       β”œβ”€β”€ index.ts           # Install/uninstall in order: brew β†’ node β†’ python β†’ git
β”‚       β”œβ”€β”€ homebrew.ts
β”‚       β”œβ”€β”€ node.ts
β”‚       β”œβ”€β”€ python.ts
β”‚       └── git.ts
β”‚
β”œβ”€β”€ agents/                    # One folder per agent (data, not code)
β”‚   β”œβ”€β”€ claude/
β”‚   β”‚   β”œβ”€β”€ agent.json         # Config: name, MCP paths, cleanup paths
β”‚   β”‚   β”œβ”€β”€ driver.ts          # 4 functions: isInstalled, install, authenticate, uninstall
β”‚   β”‚   β”œβ”€β”€ mcp/               # Global MCP JSON files
β”‚   β”‚   └── scaffold/          # Files copied into new projects by ai-init
β”‚   β”œβ”€β”€ codex/
β”‚   β”‚   β”œβ”€β”€ agent.json         # Config: name, MCP paths (TOML), cleanup paths
β”‚   β”‚   β”œβ”€β”€ driver.ts          # npm install, ChatGPT auth, npm uninstall
β”‚   β”‚   β”œβ”€β”€ mcp/               # Global MCP TOML (merged into ~/.codex/config.toml)
β”‚   β”‚   └── scaffold/          # AGENTS.md, .codex/, .agents/skills/
β”‚   β”œβ”€β”€ cursor/
β”‚   β”œβ”€β”€ vscode/
β”‚   └── _template/             # Copy this to add a new agent
β”‚
└── plugins/                   # Optional cross-agent project add-ons
    └── _template/

Quick Start

# Setup everything
chmod +x setup.sh && ./setup.sh

# Scaffold a new project
ai-init

# Teardown everything
chmod +x nuke.sh && ./nuke.sh

# Dry run (see what would happen without doing it)
./setup.sh --dry-run
./nuke.sh --dry-run

Built-in Agents

Agent Icon Global MCPs Project Scaffold
Claude Code πŸ€– sequential-thinking, memory CLAUDE.md, rules, skills, .mcp.json
VS Code πŸ’Ž puppeteer copilot-instructions.md, .instructions.md, skills, .vscode/mcp.json

Adding a New Agent

# 1. Copy the template
cp -r agents/_template agents/opencode

# 2. Edit the config
#    agents/opencode/agent.json β€” name, MCP paths, cleanup paths
#    agents/opencode/driver.ts  β€” isInstalled, install, authenticate, uninstall

# 3. Add MCP configs
#    agents/opencode/mcp/global.json

# 4. Add scaffold files
#    agents/opencode/scaffold/  β€” rules, skills, project MCP, etc.

# 5. Done. Run ./setup.sh β€” OpenCode appears in the menu automatically.

agent.json Reference

{
  "name": "OpenCode",              // Display name
  "id": "opencode",               // Must match folder name
  "description": "Terminal AI",    // Shown in menus
  "icon": "πŸ–₯️",                   // Menu icon
  "requires": ["homebrew", "node"],
  "installMethod": "custom",      // "custom" | "brew-cask" | "brew" | "npm-global"
  "command": "opencode",           // CLI command to check installation
  "mcp": {
    "global.json": {               // File under mcp/ β†’ destination path
      "path": "~/.opencode/mcp.json"
    }
  },
  "cleanup": {
    "paths": ["~/.opencode"],      // Removed by nuke (user-level)
    "sudoPaths": []                // Removed by nuke (with sudo)
  }
}

driver.ts Reference

import type { AgentDriver, Context } from "../../src/core/types.js";

export const driver: AgentDriver = {
  async isInstalled() { /* return true if installed */ },
  async install(ctx)  { /* install the agent */ },
  async authenticate(ctx) { /* prompt user to log in */ },
  async uninstall(ctx) { /* remove the agent */ },
};
export default driver;

Codex Agent β€” Deep Dive

Codex is unique among the agents because it uses TOML configuration (not JSON) and has a richer per-project structure: subagents, command rules, skills, and shared .agents/ skills.

Global Setup (./setup.sh β†’ select Codex)

Installs the CLI via npm install -g @openai/codex, then merges MCP servers into ~/.codex/config.toml (preserving your existing model, sandbox, and approval settings):

# Your existing settings stay untouched
# model = "gpt-5.4"
# approval_policy = "on-request"

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

[mcp_servers.sequential-thinking]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-sequential-thinking"]

[mcp_servers.memory]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-memory"]

Project Scaffold (ai-init β†’ select Codex β†’ "myapp")

myapp/
β”œβ”€β”€ AGENTS.md                              # Project instructions for Codex
β”œβ”€β”€ .agents/
β”‚   └── skills/                            # Shared skills (usable by any subagent)
β”‚       β”œβ”€β”€ code-review/
β”‚       β”‚   └── SKILL.md                   # Structured review workflow
β”‚       └── testing-strategy/
β”‚           └── SKILL.md                   # Unit/integration/E2E patterns
└── .codex/
    β”œβ”€β”€ config.toml                        # Project-level MCP servers + settings
    β”œβ”€β”€ agents/
    β”‚   β”œβ”€β”€ explorer.toml                  # Read-only codebase exploration (skills disabled)
    β”‚   └── reviewer.toml                  # PR review (code-review + testing-strategy enabled)
    β”œβ”€β”€ rules/
    β”‚   └── default.rules                  # Starlark command policies
    └── skills/
        └── project-conventions/
            └── SKILL.md                   # Coding standards, git workflow, docs

TOML Support

The framework detects config format from file extension:

Source file Read as Destination file Write as
mcp/global.json JSON ~/.cursor/mcp.json JSON (overwrite)
mcp/global.toml TOML ~/.codex/config.toml TOML (merge)

TOML destinations are merged (not overwritten) β€” your existing config.toml settings are preserved. JSON destinations use the existing overwrite behavior.

Subagents

Each .toml file in .codex/agents/ defines a subagent with its own model, sandbox, and skill configuration:

# .codex/agents/reviewer.toml
name = "reviewer"
description = "PR reviewer focused on correctness, security, and missing tests."
sandbox_mode = "read-only"
model_reasoning_effort = "high"

[[skills.config]]
path = ".agents/skills/code-review/SKILL.md"
enabled = true

Subagents toggle shared skills independently β€” the explorer disables review skills, the reviewer enables them.

Command Rules

.codex/rules/default.rules uses Starlark syntax:

prefix_rule(
    pattern = ["git", ["status", "log", "diff"]],
    decision = "allow",
)
prefix_rule(
    pattern = ["git", ["push", "reset", "rebase"]],
    decision = "prompt",
    justification = "Destructive git operations need human review.",
)

Adding a Plugin

Plugins are optional add-ons that inject files into projects during ai-init.

# 1. Copy the template
cp -r plugins/_template plugins/git-hooks

# 2. Edit plugins/git-hooks/plugin.json
{
  "name": "Git Hooks",
  "id": "git-hooks",
  "description": "Husky + commitlint pre-commit hooks",
  "icon": "πŸͺ",
  "compatibleAgents": []    // empty = compatible with all agents
}

# 3. Add files under plugins/git-hooks/files/
#    These are copied to the project root preserving directory structure.
#    Supports {{PROJECT_DIR}} and {{PROJECT_NAME}} tokens.

# 4. Done. Plugin appears in ai-init menu automatically.

How It Works

Setup Flow (./setup.sh)

  1. Bash bootstrap ensures Homebrew + Node exist
  2. orchestrate.ts installs foundations (brew, node, python, git)
  3. Auto-discovers agents/*/agent.json
  4. Interactive checkbox: pick which agents to set up
  5. For each agent: install β†’ write global MCP β†’ authenticate
  6. Injects ai-init shell function into ~/.zshrc

Teardown Flow (./nuke.sh)

  1. Safety gate (type NUKE to confirm)
  2. Auto-discovers all agents
  3. For each: run driver.uninstall() β†’ remove cleanup paths β†’ remove MCP configs
  4. Removes ai-init from shell configs
  5. Uninstalls foundations in reverse order

Scaffold Flow (ai-init)

  1. Prompt for project name
  2. Select one agent from discovered list
  3. Optionally select plugins
  4. Deep-copy agents/<id>/scaffold/ into new project
  5. Replace {{PROJECT_DIR}} and {{PROJECT_NAME}} tokens in copied files
  6. Copy plugin files into project

Design Principles

Principle Implementation
Convention over configuration Agents discovered by folder existence β€” no central registry
Data, not code MCP configs, rules, skills are plain files β€” edit with any editor
Typed driver contract AgentDriver interface enforces consistent 4-function API
Idempotent Every step checks before acting (already installed β†’ skip)
Dry run --dry-run flag prints actions without executing
Isolated agents One agent's broken config can't affect another
Template tokens {{PROJECT_DIR}} replaced at scaffold time for dynamic values

What Each Agent Gets

MCP Servers

Agent Global MCP(s) Project MCPs
Claude Code sequential-thinking + memory filesystem + github
Codex context7 + sequential-thinking + memory git + filesystem
Cursor fetch brave-search + git
VS Code puppeteer sqlite + postgres

Skills (per project)

# Claude Code Codex Cursor VS Code
1 api-design β€” REST, Zod, rate limiting, OpenAPI code-review β€” Structured review, security, correctness react-components β€” Functional, hooks, lazy loading typescript-strict β€” Strict config, generics, utility types
2 error-handling β€” Error classes, tracing, circuit breakers testing-strategy β€” Unit, integration, E2E patterns tailwind-patterns β€” Utility-first, responsive, dark mode full-stack-patterns β€” Shared types, typed API, e2e safety
3 project-conventions β€” Code org, git workflow, docs