diff --git a/AGENTS.md b/AGENTS.md index 5501c30..4c00584 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,6 +30,7 @@ - **New tool**: Add definition in `tool_definitions.rs`, implement in `tools/`, add dispatch case - **New provider**: Implement `LLMProvider` trait in `g3-providers` - **New CLI mode**: Add to CLI args, implement handler in `g3-cli` +- **New skill**: Create `skills//SKILL.md`, optionally add to `embedded.rs` for binary inclusion - **New config option**: Add to `g3-config` structs ## Dangerous Code Paths @@ -43,6 +44,7 @@ These areas have subtle bugs if modified incorrectly: | **Tool dispatch** | Missing dispatch cases cause silent failures | | **Retry logic** | Aggressive retries hit rate limits harder | | **Parser sanitization** | Inline JSON can trigger false tool call detection | +| **Skill extraction** | Version hash mismatch causes stale scripts; path issues on Windows | ## Do's and Don'ts @@ -82,3 +84,24 @@ The `analysis/deps/` directory contains static analysis artifacts generated by t | `limitations.md` | What could not be observed and what may invalidate conclusions | These artifacts are useful for understanding coupling, planning refactors, and identifying architectural boundaries. + +## Skills System Entry Points + +The skills system (`crates/g3-core/src/skills/`) provides extensible agent capabilities: + +| File | Purpose | +|------|--------| +| `mod.rs` | Public API: `Skill`, `discover_skills`, `generate_skills_prompt` | +| `parser.rs` | SKILL.md parsing with YAML frontmatter validation | +| `discovery.rs` | Multi-location discovery with priority ordering | +| `embedded.rs` | Compile-time skill embedding via `include_str!` | +| `extraction.rs` | Script extraction to `.g3/bin/` with version tracking | +| `prompt.rs` | Generates `` XML for system prompt | + +**Key invariants for skills**: +- Skill names must be 1-64 chars, lowercase + hyphens only +- SKILL.md must have valid YAML frontmatter with `name` and `description` +- Embedded scripts are extracted lazily (on first use) +- Version tracking uses content hash, not timestamps +- Higher priority locations override lower (repo > workspace > global > embedded) +- Script extraction is Unix-only (chmod 755); Windows support is incomplete diff --git a/README.md b/README.md index 76cd08a..74454ea 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,11 @@ These commands give you fine-grained control over context management, allowing y g3 supports the [Agent Skills](https://agentskills.io) specification - an open format for portable skill packages that give the agent new capabilities. **Skill Locations** (in priority order, later overrides earlier): -1. Global: `~/.g3/skills/` -2. Extra paths from config -3. Workspace: `.g3/skills/` (highest priority) +1. Embedded skills (compiled into binary) +2. Global: `~/.g3/skills/` +3. Extra paths from config +4. Workspace: `.g3/skills/` +5. Repo: `skills/` (highest priority, checked into git) **SKILL.md Format**: ```yaml @@ -146,6 +148,12 @@ Each skill adds ~50-100 tokens to context (name + description + path). Skills ca - `references/` - Additional documentation - `assets/` - Templates, data files +**Embedded Skills**: Core skills like `research` are compiled into the binary, ensuring they work anywhere without external files. Embedded scripts are automatically extracted to `.g3/bin/` on first use. + +**Built-in Research Skill**: Perform asynchronous web research via `background_process("research", ".g3/bin/g3-research 'your query'")`. Results are saved to `.g3/research//report.md`. + +See [Skills Guide](docs/skills.md) for detailed documentation. + ### Provider Flexibility - Support for multiple LLM providers through a unified interface - Hot-swappable providers without code changes @@ -483,6 +491,7 @@ Detailed documentation is available in the `docs/` directory: | [Tools Reference](docs/tools.md) | Complete reference for all available tools | | [Providers Guide](docs/providers.md) | LLM provider setup and selection guide | | [Control Commands](docs/CONTROL_COMMANDS.md) | Interactive `/` commands for context management | +| [Skills Guide](docs/skills.md) | Agent Skills system, SKILL.md format, creating skills | | [Code Search](docs/CODE_SEARCH.md) | Tree-sitter code search query patterns | For AI agents working with this codebase, see [AGENTS.md](AGENTS.md). diff --git a/docs/architecture.md b/docs/architecture.md index 6243558..3bc5d43 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1,7 +1,7 @@ # g3 Architecture -**Last updated**: January 2025 -**Source of truth**: Crate structure in `crates/`, `Cargo.toml`, `DESIGN.md` +**Last updated**: February 2025 +**Source of truth**: Crate structure in `crates/`, `Cargo.toml`, `DESIGN.md`, `skills/` ## Purpose @@ -72,6 +72,7 @@ g3/ │ ├── g3-planner/ # Planning mode workflow │ └── studio/ # Multi-agent workspace manager ├── agents/ # Agent persona definitions +├── skills/ # Embedded skills (research, etc.) ├── logs/ # Session logs (auto-created) └── g3-plan/ # Planning artifacts ``` @@ -94,6 +95,7 @@ Key modules: - `retry.rs` - Retry logic with exponential backoff - `prompts.rs` - System prompt generation - `code_search/` - Tree-sitter based code search +- `skills/` - Agent Skills discovery, parsing, and extraction **Key types**: - `Agent` - Main agent struct, generic over UI output @@ -230,6 +232,57 @@ Key modules: Studio enables isolated agent sessions by creating git worktrees, allowing multiple agents to work on the same codebase without conflicts. +### Skills System (Extensible Capabilities) + +**Location**: `crates/g3-core/src/skills/` and `skills/` +**Purpose**: Portable skill packages that extend agent capabilities + +g3 implements the [Agent Skills](https://agentskills.io) specification, allowing skills to be discovered from multiple locations and embedded into the binary for portability. + +Key modules in `crates/g3-core/src/skills/`: +- `mod.rs` - Module exports and public API +- `parser.rs` - SKILL.md frontmatter and body parsing +- `discovery.rs` - Multi-location skill discovery with priority ordering +- `embedded.rs` - Skills compiled into the binary via `include_str!` +- `extraction.rs` - Script extraction to `.g3/bin/` with version tracking +- `prompt.rs` - Generates `` XML for system prompt + +**Discovery Priority** (lowest to highest): +1. Embedded skills (compiled into binary) +2. Global: `~/.g3/skills/` +3. Extra paths from config +4. Workspace: `.g3/skills/` +5. Repo: `skills/` (highest priority, checked into git) + +**Embedded Skills**: + +Core skills are embedded at compile time using `include_str!`, ensuring g3 works anywhere without external files: + +```rust +static EMBEDDED_SKILLS: &[EmbeddedSkill] = &[ + EmbeddedSkill { + name: "research", + skill_md: include_str!("../../../../skills/research/SKILL.md"), + scripts: &[ + ("g3-research", include_str!("../../../../skills/research/g3-research")), + ], + }, +]; +``` + +**Script Extraction**: + +Embedded scripts are extracted to `.g3/bin/` on first use: +- Version tracking via content hash in `.g3/bin/