WM

wisdomgraph/mega-code

开发工具
47 stars 质量 70 趋势 70

The Self-evolving AI Coding Infrastructure

概览

Self Optimizing Infrastructure for AI Coding Agents MEGA Code is a self-evolving infrastructure layer for AI coding agents. It turns your coding sessions into reusable wisdom by generating skills and strategies from real execution traces, decomposing validated knowledge into Primary-Context-Resultant (PCR) units, and reinjecting the right knowledge back into future tasks. Instead of treating skills as flat blocks, MEGA Code structures them at the atomic level so they can be retrieved, recomposed, and improved over time. The result is not just persistence, but compounding problem-solving quality. This wisdom is stored in the Wisdom Graph DB: a structured graph that maps relationships between procedures, contexts, constraints, and outcomes across sessions. Rather than loading entire skill blocks into context, MEGA Code retrieves only the knowledge relevant to the user’s current intent, along with workflow-level guidance and step-by-step cheatmaps.

README

MEGA Code is a self-evolving infrastructure layer for AI coding agents. It turns your coding sessions into reusable wisdom by generating skills and strategies from real execution traces, decomposing validated knowledge into Primary-Context-Resultant (PCR) units, and reinjecting the right knowledge back into future tasks. Instead of treating skills as flat blocks, MEGA Code structures them at the atomic level so they can be retrieved, recomposed, and improved over time. The result is not just persistence, but compounding problem-solving quality.

This wisdom is stored in the Wisdom Graph DB: a structured graph that maps relationships between procedures, contexts, constraints, and outcomes across sessions. Rather than loading entire skill blocks into context, MEGA Code retrieves only the knowledge relevant to the user’s current intent, along with workflow-level guidance and step-by-step cheatmaps. It also evaluates generated skills, surfaces ROI, and provides enhanced versions, so the system improves not only by accumulation, but by refinement. This is what allows quality and efficiency to improve together rather than trade off against each other.


Why MEGA Code

Most approaches to AI agent skills fail in a predictable way. Skills are stored as fixed blocks and injected wholesale into context at session start. As the library grows, the prompt grows — but the reasoning does not. More skills often mean more noise, not more capability.

What matters is not how many skills you store, but whether knowledge can be decomposed, retrieved, recomposed, and improved in a form that fits the task at hand.

MEGA Code is built around one principle: Evaluated wisdom compounds. Unevaluated assets just add noise.


Real Work. Real Results.

Measured head-to-head against 5 leading systems on tasks developers actually ship.

Token Usage

MEGA Code        ████░░░░░░░░░░░░░░░░  169K   ← 81% reduction
HF Upskill       ████████████████░░░░  763K
anthropic-skill  █████████████████░░░  826K
Baseline         ██████████████████░░  897K
skill-factory    ██████████████████████████████  1,448K
skill-builder    ██████████████████████████████████████████  2,024K

Combined Score

MEGA Code        ████████████████  78%   ← #1
HF Upskill       ██████████████░░  70%
anthropic-skill  █████████████░░░  65%
Baseline         █████████████░░░  65%
skill-builder    ██████████░░░░░░  50%
skill-factory    █████████░░░░░░░  43%

Two of the four competing systems perform worse than using no skills at all. MEGA Code is the only system that beats the no-skill baseline on both token efficiency and task quality simultaneously.

See the full benchmark →


How It Works

MEGA Code installs as a Claude Code plugin and runs inside your existing workflow — no new coding workflow required.

MEGA Code works through three core flows:

1. wisdom-gen
MEGA Code reads your coding session traces and extracts reusable wisdom from what actually happened. It identifies:

  • Skills: reusable procedures that worked
  • Strategies: decision rules and correction patterns that emerged across repeated choices
  • PCR units: atomic Primary-Context-Resultant structures distilled from validated knowledge

These are written into structured local assets and prepared for reuse.

2. wisdom-curate
MEGA Code does not simply inject an entire skill library into context. Instead, it decomposes curated skills into atomic PCR-level wisdom, stores them in the Wisdom Graph DB, and retrieves only the knowledge relevant to your current intent.

For a given command or task, MEGA Code can provide:

  • the most relevant Skills and Strategies
  • a recommended workflow for solving the problem
  • a Cheatmap explaining which skills should be used at each step and why

This allows the agent to use the right knowledge in the right structure, instead of loading everything and adding noise.

Note: For wisdom-curate to work correctly, all Skills recommended by MEGA Code must be installed. Missing skills will cause the curation to reference procedures that the agent cannot access.

3. skill-enhance
MEGA Code evaluates generated skills, measures their ROI, and produces enhanced versions. Instead of merely accumulating more assets, the system improves the quality, efficiency, and transferability of the skills you already have.

One command, two modes:

  • /mega-code:skill-enhance — remote mode (default), the entire A/B + iteration loop runs on the MEGA Code server. The client packages the skill, uploads it, blocks on a polling loop, and installs the enhanced version on success. Requires MEGA_CODE_CLIENT_MODE=remote and a valid MEGA_CODE_API_KEY. Runs the full evaluator pipeline at scale, returning per-model ROI deltas in the result envelope.
  • /mega-code:skill-enhance --hitl — local human-in-the-loop mode, the host agent (Claude Code) drives the A/B grading loop synchronously with an HTML review viewer. No server calls beyond the initial wisdom storage; works offline once installed. (--hitl is case-insensitive.)

What gets generated locally:

~/.local/share/mega-code/data/
├── pending-skills/{skill-name}/SKILL.md         ← reusable procedures extracted from session traces
├── pending-strategies/{strategy-name}.md        ← decision rules extracted from corrections and repeated choices
└── enhanced-skills/{skill-name}/SKILL.md        ← evaluated and enhanced versions with ROI insights

**Example - SKILL.md entry:**
```markdown
---
name: ui-consistency-and-discovery
description: 'Guidelines for maintaining UI legibility and clean aesthetics while
  using ripgrep for efficient project exploration and global string replacement.'
metadata:
  tags: [ui-ux, ripgrep, accessibility, project-navigation]
  author: co-authored by http://www.megacode.ai
  version: "1.0.0"
  generated_at: "2026-03-26T05:22:58Z"
  roi:
    model: gemini-3-flash
    performance_increase: "75%"
    token_savings: "83%"
---

## Handle authentication token refresh

When an API call returns 401, check token expiry before retrying.
Refresh using POST /auth/refresh with the stored refresh_token.
Only retry the original request once — if it fails again, surface the error.

Applies to: src/api/client.py, any authenticated endpoint
Validated: 4 sessions

Example — strategies.md entry:

## Database migration approach

In this project, always run migrations against a local test DB first.
Schema changes that touch the users table require a backup step before applying.
Learned from: 2 rollback incidents in sessions 3 and 7.

The agent reads these files at the start of every session. It does not repeat the mistake that generated the strategy. It does not re-derive the procedure that generated the skill.

Example — Cheatmap output:

Wisdom Curation

IMPORTANT: How to use this curation
This curation contains a step-by-step workflow. Each step may have a Reference: entry pointing to domain-specific knowledge that you likely do NOT already know. Before executing each step, you MUST read the referenced section.

step-1: Visual Hierarchy and Aesthetic Audit

Portfolio: 1 core + 0 supporting skills selected for complementary coverage.

1. [H] Visual and Accessibility Audit
P: Assess visual polish against an 8px spacing scale, typography hierarchy, and semantic color usage. Verify WCAG 2.1 AA compliance, specifically color contrast ratios and keyboard tab order.
R: UI components are fully keyboard-accessible and screen-reader friendly. The design system remains consistent by using a single source of truth for primitives.
Reference: design-review/SKILL.md#Phase 3: Visual Polish L136-150
Reference: design-review/SKILL.md#Phase 4: Accessibility (WCAG 2.1 AA) L153-174

step-2: Advanced UI Component Design Systems

Portfolio: 1 core + 1 supporting skills selected for complementary coverage.

1. [H] micro-interaction-and-animation-implementation
P: Apply subtle CSS transitions and spring physics to buttons, toggles, and form elements to create satisfying tactile feedback.
R: Interface elements provide immediate, satisfying visual and haptic feedback within 1 second.
Reference: delight/SKILL.md#Micro-interactions & Animation L84-122
Reference: delight/SKILL.md#Satisfying Interactions L175-200

2. [M] Animation and Motion Constraints
P: Apply performant animation constraints using motion/react and Tailwind CSS to prevent interface slop.
R: Animations are smooth and do not trigger expensive browser layout or paint cycles.
Reference: baseline-ui/SKILL.md#Animation L52-64

When Are Skills Generated?

The 5 Core Conditions for Skill Creation

1. Repeated Work Patterns (minimum 2 occurrences)
One-off tasks are never turned into skills. A skill candidate must be a proven repeated pattern found across at least 2 separate conversation sessions or task groups.

2. Active User Involvement (30%+ contribution)
Tasks where the AI acted alone do not become skills. The work must reflect sufficient user intent — through direct guidance, error correction, or approval of a specific approach. For professional domain skills, user contribution must account for at least 30% of the work.

3. Verified Efficiency Gains (performance metrics)
After a skill is generated, MEGA Code runs a self-evaluation. The skill must pass a performance improvement threshold — either a 5%+ increase in task success rate, or a 20%+ reduction in token usage (cost and speed) — before it receives final approval.

4. Quality Score Threshold (reliability standard)
Skills are evaluated against actual evidence (screen recordings, command executions, etc.) — not assumptions. Content must be specific and structured, and only high-quality skills that score above the quality threshold (3.0) are registered.

5. Value of Error Resolution (exception cases included)
Beyond standard task procedures, instances where a user corrected an AI mistake are treated as highly valuable. This error-prevention knowledge is converted into skills — even with lower user contribution ratios — to prevent the same mistakes from recurring in future sessions.


Quick Start

Step 1 — Install the plugin

Claude Code

In a Claude Code session, run:

/plugin marketplace add https://github.com/wisdomgraph/mega-code

Install the plugin:

/plugin install mega-code@mind-ai-mega-code

Restart Claude Code to load the plugin.

Step 2 — Sign in

/mega-code:login

Authenticates via GitHub or Google. A service key is automatically issued and saved for your account.

Step 3 — Run in any project

/mega-code:wisdom-gen         # Generate skills and strategies from session traces
/mega-code:wisdom-curate      # Retrieve the right skills, workflows, and cheatmaps for your intent
/mega-code:skill-enhance      # Enhance a skill (remote server by default; add --hitl for local human-in-the-loop A/B)
/mega-code:status             # Check results and pipeline status

Codex Support

MEGA Code also works with OpenAI Codex CLI. Install from the codex branch:

npx skills add https://github.com/wisdomgraph/mega-code/tree/codex -a codex

For Codex-specific commands and usage, see the Codex branch README.


Free to Start

MEGA Code is currently free to use — just bring your own LLM API key (Gemini or OpenAI).

The current release includes:

  • wisdom-gen for generating Skills and Strategies from coding sessions
  • wisdom-curate for retrieving relevant workflows and Cheatmaps from the Wisdom Graph DB
  • skill-enhance for evaluating skills and generating enhanced versions with ROI insights

Available Commands

Command Description
/mega-code:login Sign in via GitHub or Google OAuth
/mega-code:wisdom-gen Generate Skills and Strategies from session traces
/mega-code:wisdom-curate Retrieve relevant Skills, workflows, and Cheatmaps for your current intent
/mega-code:skill-enhance Enhance a Skill (remote server by default; pass --hitl for local human-in-the-loop A/B)
/mega-code:status Show generated assets and pipeline status
/mega-code:stop Stop a running pipeline
/mega-code:profile View or update your developer profile (language, level, style)
/mega-code:help Show help and reference

Example Session

/mega-code:login                    # Sign in (first time)
/mega-code:profile                  # Set your language, level, and style
/mega-code:wisdom-gen --project     # Generate skills and strategies from project session traces
/mega-code:wisdom-curate            # Retrieve the best workflow and cheatmap for the current task
/mega-code:skill-enhance           # Enhance a skill on the server (remote — requires MEGA_CODE_CLIENT_MODE=remote)
/mega-code:skill-enhance  --hitl   # Local human-in-the-loop A/B (host-driven, HTML review viewer)
/mega-code:status                   # See what was generated
/mega-code:stop                     # Stop a pipeline if needed

How to update

Claude Code:

/plugin marketplace update mind-ai-mega-code

Development Setup (from main repo)

If you are developing from the main mega-code repository (which includes this as a submodule), use the sync script to test changes without committing:

# From the main mega-code repo root:
bash scripts/setup-oss-test.sh

# This syncs skills/, hooks/, client code, and installs deps.
# Then test locally with:
claude --plugin-dir mega-code-oss/plugin

The sync script copies the latest code from the main repo into this submodule so you can iterate quickly without any git commits to GitHub.

Project Structure

plugin/
├── .claude-plugin/
│   └── plugin.json          # Plugin metadata
├── skills/
│   ├── login/SKILL.md       # /mega-code:login
│   ├── wisdom-gen/SKILL.md  # /mega-code:wisdom-gen
│   ├── skill-enhance/SKILL.md       # /mega-code:skill-enhance (remote A/B + iteration loop, default)
│   ├── skill-enhance-hitl/SKILL.md  # internal — backs /mega-code:skill-enhance --hitl (local host-driven A/B)
│   ├── status/SKILL.md      # /mega-code:status
│   ├── stop/SKILL.md        # /mega-code:stop
│   ├── profile/SKILL.md     # /mega-code:profile
│   └── help/SKILL.md        # /mega-code:help
├── mega_code/
│   └── client/              # Python client modules
└── pyproject.toml

Session ingestion is hook-less. On each wisdom-gen, the client scans ~/.claude/projects//.jsonl directly, filters by the user’s working directory, and uploads matching transcripts. Upload state lives in ~/.local/share/mega-code/projects//claude-sync-ledger.json.

mega-code:wisdom-gen Behaviour

Session resolution

The pipeline always operates on a project — a set of collected sessions grouped by working directory.

Invocation What gets processed
/mega-code:wisdom-gen All sessions for the current working directory
/mega-code:wisdom-gen --project Same as above (explicit, equivalent to no args)
/mega-code:wisdom-gen --project @name All sessions for the named project (prefix-matched against mapping.json; also accepts name, name_hash, or /absolute/path)
/mega-code:wisdom-gen --session-id A single session by ID

When no explicit project or session is given, the current working directory is hashed to locate its data folder under ~/.local/share/mega-code/projects/.

Trajectory sync

Before triggering the pipeline, sessions are uploaded to the server. The sync process uses a ledger file per project to track which sessions have already been uploaded. Ledgers are stored in ~/.local/share/mega-code/projects/{project_id}/:

Ledger file Tracks
sync-ledger.json mega-code’s own sessions (and Claude Code native sessions)
codex-sync-ledger.json Codex CLI sessions
  • Sessions not in the ledger are uploaded.
  • Sessions already in the ledger are skipped, unless the source file’s mtime has changed since the last upload — in which case the session is re-uploaded. This handles sessions whose files are appended to after the initial upload (e.g. a long-running session that gains new turns).
  • The ledger records uploaded_at, turn_count, and (where applicable) file_mtime for each synced session.

Sync invariants

  1. No data loss on first run. When no ledger exists, every locally stored session for the project MUST be uploaded — not just the current terminal session.
  2. Idempotency. Re-running /mega-code:wisdom-gen with an up-to-date ledger produces no duplicate uploads.
  3. Modified-session re-sync. If a session file’s mtime has changed since the last recorded upload, it MUST be re-uploaded.
  4. Filter-before-upload. All turns pass through SecretMasker and PathAnonymizer before transmission. No raw absolute paths or secrets leave the client.

Pipeline lifecycle

  1. Trigger — the client sends the project ID (and optionally a session ID) to the server.
  2. Poll — the client polls until the server reports completion, failure, or timeout. Default poll timeout is 20 minutes (--poll-timeout to override; 0 means wait indefinitely).
  3. Save — on success, extracted Skills and Strategies are written to local pending folders for review.
Exit code Meaning
0 Success — outputs saved, post-pipeline review begins
1 Fatal error (auth, network, unexpected failure)
2 Conflict — a pipeline is already running for this project
3 Server timeout — the pipeline exceeded max server runtime

Configuration

Configuration is stored in ~/.local/share/mega-code/ and persists across sessions. Use /mega-code:login to authenticate, or mega-code configure CLI for advanced settings.

Terms of Service

By using this plugin, you agree to the Terms of Service.

License

Apache-2.0

View this README on GitHub

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add wisdomgraph/mega-code