Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

feat(skills): SKILL.md playbooks, loaded on demand, two bundled in the binary

Rach Pradhan9dfb75054c72
diff --git a/README.md b/README.md
index 5125718c..ccea43d2 100644
--- a/README.md
+++ b/README.md
@@ -477,6 +477,7 @@ other animation names remain available.
/compact summarize history into a fresh context
/save | /resume | /sessions session persistence; bare /resume → interactive picker
/todo show the current task list
+/skills list SKILL.md playbooks + companion tools; add/remove toggles one
/mcp [add …] list MCP servers/tools; /mcp add <name> <cmd> connects one live
/help list commands
exit | /exit | ctrl-d | ctrl-c(empty) quit
@@ -512,6 +513,24 @@ limits; the ordinary invocation budget is unlimited by default, while explicit
and final report join the parent transcript. Use a later, explicit turn to fix
accepted findings.
+### Skills
+
+A skill is a markdown playbook graff loads only when a task calls for it. Drop
+one in `.harness/skills/<name>/SKILL.md` (or `~/.harness/skills/` for every
+project), give it `name` and `description` frontmatter, and write the
+instructions in the body. Skills already written for Claude Code work as they
+are: `.claude/skills/` is read too.
+
+Only the name and description enter the system prompt, so a large skill library
+costs one line each. The model calls the `skill` tool to pull a body in when it
+needs it, and a skill written mid-session is loadable straight away.
+
+Two skills ship inside the binary: `skill-creator` (how to author and install
+new skills) and `mcp-config` (how to inspect and change the MCP servers below).
+`/skills` lists everything with its source, `/skills remove <name>` hides one,
+and `/skills add <name>` brings it back. See
+[docs/skills.md](docs/skills.md) for the full reference.
+
### MCP servers
Graff speaks both MCP transports directly: local stdio servers and remote
diff --git a/assets/skills/mcp-config.md b/assets/skills/mcp-config.md
new file mode 100644
index 00000000..6470faf8
--- /dev/null
+++ b/assets/skills/mcp-config.md
@@ -0,0 +1,84 @@
+---
+name: mcp-config
+description: Inspect or change this workspace's MCP servers - use when adding, removing, or authenticating an MCP server, when MCP tools are missing or a server did not connect, or when the user asks how MCP config works here.
+---
+
+# MCP configuration
+
+MCP servers are configured per workspace in `.mcp.json` at the project root.
+Their tools reach the model as `mcp__<server>__<tool>`.
+
+## The file
+
+```json
+{
+ "mcpServers": {
+ "playwright": { "command": "npx", "args": ["-y", "@playwright/mcp"] },
+ "sentry": {
+ "command": "npx",
+ "args": ["-y", "@sentry/mcp-server"],
+ "env": { "SENTRY_AUTH_TOKEN": "..." }
+ },
+ "mobbin": { "url": "https://api.mobbin.com/mcp" },
+ "internal": {
+ "url": "https://mcp.example.com/mcp",
+ "headers": { "Authorization": "Bearer ..." }
+ }
+ }
+}
+```
+
+- Local (stdio) server: `command` plus optional `args` and `env`. `env` values
+ are literal strings - there is no `${VAR}` expansion.
+- Remote server: `url`, Streamable HTTP. HTTPS is required except for
+ localhost, and `headers` is for static tokens.
+- `smolify` is a reserved core server; a workspace entry cannot shadow its
+ pinned endpoint.
+- Invalid JSON means zero servers load, quietly. If tools vanished after an
+ edit, check the file parses first.
+
+## Prefer the CLI for writes
+
+```sh
+graff mcp # list configured servers
+graff mcp add <name> -- <command> [args...] # local server
+graff mcp add <name> --env KEY=VALUE -- <command> # with env
+graff mcp add <name> --url https://host/mcp # remote server
+graff mcp add <name> --url https://host/mcp --header KEY=VALUE
+graff mcp login <name> # OAuth for a remote server
+```
+
+Editing `.mcp.json` with `edit_file` or `write_file` is equally valid, and it is
+how you remove a server (drop its key) or rename one. Do not commit a secret
+into it: prefer `graff mcp login` (OAuth credentials are stored outside the
+repo) or a token the user supplies at runtime.
+
+## In-session, no restart
+
+- `/mcp` - connected servers, tool counts, and any workspace servers still
+ pending consent
+- `/mcp add <name> <command> [args...]` and `/mcp add <name> --url <URL>` -
+ connect one live and persist it
+- `/mcp trust` - connect the workspace servers that were skipped at startup
+
+## When a server is not connected
+
+A workspace `.mcp.json` launches arbitrary local commands, so graff never
+auto-spawns untrusted entries: it asks at startup, and without consent (or
+`--yolo`) it starts with an empty but live registry. `/mcp trust` is the
+in-session fix and `/mcp` shows what is pending. Remote servers pass the same
+gate, because their arguments leave the machine.
+
+After that, in likelihood order: the command is not on PATH, the package name
+is wrong, the server needs a token that is not set, the URL is not HTTPS, or
+the server needs an OAuth login (`graff mcp login <name>`).
+
+## After changing config
+
+Tools appear as soon as a server actually connects, which live `/mcp add` and
+`/mcp trust` both do. Editing `.mcp.json` alone changes nothing in the running
+session - connect the server live or restart.
+
+MCP tools are accelerators, never requirements. When a server is missing or a
+call fails, fall back to the native tools (`bash`, `read_file`, `webfetch`) and
+keep going.
diff --git a/assets/skills/skill-creator.md b/assets/skills/skill-creator.md
new file mode 100644
index 00000000..ee12df0a
--- /dev/null
+++ b/assets/skills/skill-creator.md
@@ -0,0 +1,79 @@
+---
+name: skill-creator
+description: Author, install, or edit a graff skill (a SKILL.md playbook) - use when the user wants to capture a repeatable workflow as a reusable skill, asks how skills work, or asks you to write or update a skill.
+---
+
+# Writing a graff skill
+
+A skill is a markdown playbook the harness finds on disk and loads on demand.
+Only its name and description sit in the system prompt; the body stays on disk
+until the `skill` tool loads it. That split is the whole point: the catalog
+line stays cheap, and the detail is there when a task actually needs it.
+
+## Where skills live
+
+| Location | Scope |
+| --- | --- |
+| `.harness/skills/` | this project, checked in with the repo |
+| `~/.harness/skills/` | you, in every project |
+| `.claude/skills/`, `~/.claude/skills/` | read as-is, for Claude Code compatibility |
+
+Precedence, lowest to highest: bundled, `~/.claude/skills`, `~/.harness/skills`,
+`.claude/skills`, `.harness/skills`. A project skill shadows a personal skill of
+the same name, which shadows a bundled one.
+
+Two layouts, both valid:
+
+- `.harness/skills/<name>/SKILL.md` - use this when the skill ships helper files
+- `.harness/skills/<name>.md` - a single-file skill
+
+## Format
+
+```markdown
+---
+name: run-migrations
+description: Apply or roll back database migrations in this repo - use when the user wants to migrate, add a migration, or a schema change needs deploying.
+---
+
+# Run migrations
+
+1. ...
+```
+
+- `name` is optional; it defaults to the file or directory name. Keep it
+ kebab-case, since that is what the user types after `/skills`.
+- `description` is the trigger, and the only thing another session sees before
+ deciding to load the skill. Say what it does AND when to reach for it, on one
+ line. A description that only names the topic ("migrations") will not fire.
+- The body is plain markdown. Bodies over 32 KB are truncated on load, with a
+ pointer to the file, so keep it focused.
+
+## Installing one
+
+1. `write_file` the SKILL.md (create the directory first if it does not exist).
+2. Load it back with the `skill` tool to confirm it parses. The tool rescans
+ every call, so a skill you just wrote is usable immediately in this session.
+3. Its catalog line reaches the system prompt at the next start. Until then,
+ load it by name.
+
+## What is worth a skill
+
+- A workflow repeated across sessions with steps that are easy to get wrong:
+ releases, deploys, migrations, codegen, incident checklists.
+- Project conventions too long to sit in CLAUDE.md or AGENTS.md.
+- Not worth it: one-off instructions, or anything already obvious from reading
+ the code. A skill nobody loads is context tax for every future session.
+
+## Helper files
+
+Anything next to SKILL.md travels with the skill. Reference it by relative path
+in the body and read it with `read_file` at the point it is needed - the loaded
+body tells you which directory the skill came from. Keep SKILL.md the index,
+not the encyclopedia.
+
+## Managing skills
+
+- `/skills` lists every skill with its source and file.
+- `/skills remove <name>` disables one. That persists as
+ `{"skills": {"<name>": false}}` in `.harness/settings.json`, and the skill
+ disappears from the catalog and from the `skill` tool entirely.
diff --git a/build.zig b/build.zig
index d3e67e8d..c8a5b975 100644
--- a/build.zig
+++ b/build.zig
@@ -104,6 +104,17 @@ pub fn build(b: *std.Build) void {
unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
}
+ // Bundled skills: SKILL.md playbooks compiled into every binary (embedded
+ // by name in src/skill_docs.zig), so a fresh install already knows how to
+ // author more skills and how to change this workspace's MCP servers.
+ for ([_]struct { import: []const u8, path: []const u8 }{
+ .{ .import = "skill_doc_creator", .path = "assets/skills/skill-creator.md" },
+ .{ .import = "skill_doc_mcp_config", .path = "assets/skills/mcp-config.md" },
+ }) |asset| {
+ exe.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
+ unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });
+ }
+
// --- spike (branch: spike/zigzag-repl): zigzag-based REPL ---
// Also reachable as the `graff repl` subcommand of the main binary (see
// src/main.zig). This standalone exe + `repl-test` step are kept for
diff --git a/docs/skills.md b/docs/skills.md
new file mode 100644
index 00000000..01a13709
--- /dev/null
+++ b/docs/skills.md
@@ -0,0 +1,112 @@
+# Skills
+
+A skill is a markdown playbook the harness discovers on disk and loads into
+context only when a task calls for it. Skills are how a project teaches the
+agent a workflow once instead of re-explaining it every session.
+
+Two kinds of thing are called "skills" in graff, and `/skills` lists both:
+
+- **SKILL.md playbooks** (this document): markdown instructions loaded on
+ demand through the `skill` tool. Implemented in `src/skill_docs.zig`.
+- **Companion tools** (`src/skills.zig`): optional CLI binaries such as `kuri`
+ or the codedb suite, which the harness detects on PATH and mentions in one
+ context line each. `/skills add <name>` installs those.
+
+## Layout and precedence
+
+| Location | Scope |
+| --- | --- |
+| bundled in the binary | every install |
+| `~/.claude/skills/` | you, every project (compatibility) |
+| `~/.harness/skills/` | you, every project |
+| `.claude/skills/` | this project (compatibility) |
+| `.harness/skills/` | this project |
+
+Later rows win: a project skill shadows a personal skill of the same name,
+which shadows a bundled one. Names come from frontmatter when present,
+otherwise from the file or directory name.
+
+Both layouts are read in every location:
+
+```
+.harness/skills/run-migrations/SKILL.md # a skill that ships helper files
+.harness/skills/release-notes.md # a single-file skill
+```
+
+Skills written for Claude Code need no changes, which is why the `.claude`
+directories are read as they are.
+
+## File format
+
+```markdown
+---
+name: run-migrations
+description: Apply or roll back database migrations in this repo, and when to reach for it.
+---
+
+# Run migrations
+
+1. ...
+```
+
+`name` is optional and defaults to the file or directory name. `description` is
+the trigger: it is the only part another session sees before deciding whether
+to load the skill, so it should say what the skill does and when to use it.
+Unknown frontmatter keys are ignored, and a file with no frontmatter is treated
+as all body.
+
+Limits: a SKILL.md is read up to 256 KB, a single load hands the model at most
+32 KB (longer bodies are truncated with a pointer to the file), and each
+description contributes at most 500 bytes to the system prompt.
+
+## Progressive disclosure
+
+At startup the harness scans every tier and appends one line per skill to the
+system prompt: name, source, description. Bodies are never in that block. When a
+task matches, the model calls the `skill` tool with a name and gets the body
+back, plus the directory the skill came from so it can read helper files with
+`read_file`.
+
+`skill` with no name lists every available skill; an unknown name comes back as
+an error result listing the ones that exist. Subagents have the tool too, and
+discover the catalog the same way.
+
+The tool re-scans the skill directories on every call, so a SKILL.md written
+earlier in the same session is immediately loadable. The startup catalog itself
+is rebuilt at the next launch, and `/skills` re-scans when it runs.
+
+## Managing skills
+
+```
+/skills list playbooks and companion tools, with sources
+/skills remove <name> hide one from the catalog and the tool
+/skills add <name> bring a hidden one back
+```
+
+An opt-out persists as `{"skills": {"<name>": false}}` in
+`.harness/settings.json`, the same key the companion registry uses. A disabled
+skill is absent everywhere: no catalog line, and the `skill` tool will not serve
+it.
+
+## Bundled skills
+
+Two skills are compiled into every binary, so a fresh install can already teach
+itself:
+
+- `skill-creator`: where skills live, the file format, how to install one, and
+ what is worth capturing as a skill.
+- `mcp-config`: the `.mcp.json` shape, the `graff mcp` CLI, the in-session
+ `/mcp` commands, and why a server may not have connected.
+
+Their sources are `assets/skills/*.md`, embedded through `build.zig` and parsed
+at compile time, so a bundled skill missing its description or body fails the
+build rather than going quietly absent.
+
+## Skills, agents, and project instructions
+
+- `AGENTS.md` / `CLAUDE.md` / `HARNESS.md`: always-on project instructions, in
+ context for every turn. Use for conventions that apply to all work.
+- Skills: loaded on demand. Use for detailed procedures that only matter
+ sometimes.
+- `.harness/agents/*.md` personas: whole system prompts for delegated
+ subagents, not instructions for the current agent.
diff --git a/scripts/eval/tier1-manifest.json b/scripts/eval/tier1-manifest.json
index fd6f7953..5ba68528 100644
--- a/scripts/eval/tier1-manifest.json
+++ b/scripts/eval/tier1-manifest.json
@@ -10,7 +10,7 @@
"src/main.zig",
"src/repl.zig"
],
- "test_count_baseline": 615,
+ "test_count_baseline": 626,
"required_invariants": [
{
"id": "goal-epochs",
diff --git a/sdk/py/harness_sdk.py b/sdk/py/harness_sdk.py
index f09ef96a..d39986b5 100644
--- a/sdk/py/harness_sdk.py
+++ b/sdk/py/harness_sdk.py
@@ -14,7 +14,7 @@ import urllib.request
from typing import Iterator, Optional
MODELS = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"]
-TOOLS = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"]
+TOOLS = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"]
PROVIDERS = ["anthropic", "codegraff", "deepseek", "openai", "minimax", "xiaomi", "kimi", "moonshot", "xai", "zai", "fugu", "fireworks", "mlx", "lmstudio", "codex"]
diff --git a/sdk/ts/harness.ts b/sdk/ts/harness.ts
index bbf28e3b..c62829ce 100644
--- a/sdk/ts/harness.ts
+++ b/sdk/ts/harness.ts
@@ -8,10 +8,10 @@ import { homedir } from "node:os";
import { join } from "node:path";
import { createInterface } from "node:readline";
-export const HARNESS_VERSION = "0.8";
+export const HARNESS_VERSION = "0.9";
export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex-spark" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "k3" | "kimi-for-coding" | "kimi-for-coding-highspeed" | "kimi-k2.6" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit" | (string & {});
-export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
+export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
/** Events streamed by `harness --json` (one JSON object per stdout line), each
@@ -429,4 +429,4 @@ export async function* runAgent(opts: RunAgentOptions): AsyncGenerator<Event> {
}
export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
-export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
+export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
diff --git a/sdk/ts/remote.ts b/sdk/ts/remote.ts
index 4d74ca16..301afffe 100644
--- a/sdk/ts/remote.ts
+++ b/sdk/ts/remote.ts
@@ -7,10 +7,10 @@
// `harness --json` child over there, and one POST = one protocol request,
// streamed back as NDJSON until that request's terminal event.
-export const HARNESS_VERSION = "0.8";
+export const HARNESS_VERSION = "0.9";
export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex-spark" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "k3" | "kimi-for-coding" | "kimi-for-coding-highspeed" | "kimi-k2.6" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit" | (string & {});
-export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
+export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
/** Events streamed by the bridge (same `--json` contract as the stdio SDK).
@@ -259,4 +259,4 @@ export async function* runAgentRemote(opts: RunAgentRemoteOptions): AsyncGenerat
}
export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
-export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
+export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
diff --git a/src/behavior_upload.zig b/src/behavior_upload.zig
index c225baf8..12841bc2 100644
--- a/src/behavior_upload.zig
+++ b/src/behavior_upload.zig
@@ -123,7 +123,7 @@ pub const ToolClass = enum {
/// table.
pub fn toolClass(name: []const u8) ToolClass {
if (std.mem.eql(u8, name, "bash") or std.mem.eql(u8, name, "bash_output") or std.mem.eql(u8, name, "bash_kill")) return .shell;
- if (std.mem.eql(u8, name, "read_file")) return .read;
+ if (std.mem.eql(u8, name, "read_file") or std.mem.eql(u8, name, "skill")) return .read; // `skill` reads an installed playbook off disk
if (std.mem.eql(u8, name, "edit_file") or std.mem.eql(u8, name, "write_file")) return .write;
if (std.mem.eql(u8, name, "codedb")) return .search;
if (std.mem.eql(u8, name, "webfetch")) return .web;
diff --git a/src/command_catalog.zig b/src/command_catalog.zig
index 795eaa42..796f9ec2 100644
--- a/src/command_catalog.zig
+++ b/src/command_catalog.zig
@@ -46,7 +46,7 @@ pub const commands = [_]Item{
.{ .name = "/privacy", .usage = "/privacy [local|aggregate|templates|examples]", .desc = "control prompt-learning data egress for this session" },
.{ .name = "/trajectory", .desc = "show this session's agent tree — turns + spawned subagents" },
.{ .name = "/agents", .desc = "list agent types — builtin personas + .harness/agents/*.md" },
- .{ .name = "/skills", .usage = "/skills [remove <name>]", .desc = "list available skills; /skills remove <name> disables one" },
+ .{ .name = "/skills", .usage = "/skills [add|remove <name>]", .desc = "list SKILL.md playbooks + companion tools; add/remove enables or disables one" },
.{ .name = "/hooks", .desc = "list lifecycle hooks and the built-in codedb guard" },
.{ .name = "/doctor", .desc = "read-only health check: goal/todo invariants, and why steering will or will not be appended" },
.{ .name = "/compact", .desc = "summarize history into a fresh context" },
diff --git a/src/commands_session.zig b/src/commands_session.zig
index 495d51dd..a4ce7d23 100644
--- a/src/commands_session.zig
+++ b/src/commands_session.zig
@@ -48,6 +48,7 @@ const skillDisabled = skills.skillDisabled;
const skillInstalled = skills.skillInstalled;
const saveSkillSetting = skills.saveSkillSetting;
const skills_registry = skills.skills_registry;
+const skill_docs = @import("skill_docs.zig"); // the other kind: SKILL.md playbooks
const title_mod = @import("title.zig");
const setTerminalTitle = title_mod.setTerminalTitle;
@@ -401,7 +402,9 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
try out.flush();
return true;
}
- try out.print("unknown skill: {s} — /skills lists the registry\n", .{name});
+ // Markdown skills use the same {"skills": {"<name>": false}} key.
+ if (try skill_docs.handleRemove(root.io, root.gpa, arena, name, out)) return true;
+ try out.print("unknown skill: {s} — /skills lists both kinds\n", .{name});
try out.flush();
return true;
}
@@ -455,11 +458,16 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
try out.flush();
return true;
}
- try out.print("unknown skill: {s} — /skills lists the registry\n", .{name});
+ // Not a companion: a markdown skill hidden by an earlier
+ // `/skills remove` comes back by clearing that opt-out.
+ if (try skill_docs.handleAdd(root.io, root.gpa, arena, name, out)) return true;
+ try out.print("unknown skill: {s} — /skills lists both kinds\n", .{name});
try out.flush();
return true;
}
- try out.print("{s}skills{s} — optional companion tools (codex-style; one context line each when installed)\n", .{ style.bold, style.reset });
+ // Markdown skills first (SKILL.md playbooks), then the companions.
+ try skill_docs.printSection(root.io, arena, out);
+ try out.print("{s}companions{s} — optional companion tools (codex-style; one context line each when installed)\n", .{ style.bold, style.reset });
for (skills_registry) |sk| {
const inst = skillInstalled(root.io, sk);
const disabled = skillDisabled(sk.name);
diff --git a/src/exec.zig b/src/exec.zig
index d997743a..2140d420 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -55,6 +55,7 @@ const jobOutput = jobs.jobOutput;
const jobKill = jobs.jobKill;
const shellArgv = jobs.shellArgv;
const skills = @import("skills.zig");
+const skill_docs = @import("skill_docs.zig");
const read_file = @import("read_file.zig");
const hooks = @import("hooks.zig");
const telemetry = @import("telemetry.zig");
@@ -464,6 +465,9 @@ fn execToolInner(ctx: ToolCtx, call: ToolCall) !ToolOutput {
preserveMode(io, resolved, prev_stat);
return .{ .text = try std.fmt.allocPrint(gpa, "wrote {d} bytes to {s}", .{ content.len, path }) };
}
+ // Loads one SKILL.md body (or lists them). Rescans on every call, so a
+ // skill written this session is loadable without a restart.
+ if (std.mem.eql(u8, call.name, "skill")) return skill_docs.execSkill(gpa, io, input);
if (std.mem.eql(u8, call.name, "subagent")) return execSubagent(ctx, input);
if (std.mem.eql(u8, call.name, "workflow")) return execWorkflow(ctx, input);
if (std.mem.eql(u8, call.name, "agent_output")) {
diff --git a/src/schema.zig b/src/schema.zig
index eb67fb10..a05822fb 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -13,6 +13,7 @@ const Allocator = std.mem.Allocator;
const mcp = @import("mcp.zig");
const pricing = @import("pricing.zig");
const learn_store = @import("learn_store.zig");
+const skill_docs = @import("skill_docs.zig"); // SKILL.md playbooks: the `skill` tool's name/desc/schema live there
const root = @import("main.zig");
const provider_mod = @import("provider.zig");
@@ -119,6 +120,9 @@ const base_specs = [_]ToolSpec{
\\{"type": "object", "properties": {"url": {"type": "string", "description": "Absolute http:// or https:// URL to fetch"}}, "required": ["url"]}
,
},
+ // Progressive disclosure: the system prompt carries skill names +
+ // descriptions, this tool fetches one body on demand (skill_docs.zig).
+ .{ .name = skill_docs.tool_name, .desc = skill_docs.tool_desc, .schema = skill_docs.tool_schema },
.{
.name = "codedb",
.desc = "Query codedb (github.com/justrach/codedb) — the code-intelligence index for this repo (fast & structural; prefer over grep/bash for navigating code). `command` is a codedb subcommand line: search <query> | symbol <name> [--body] | callers <name> | outline <path> | find <name> | deps <path> | tree | context <task...> | read <path>.",
@@ -175,7 +179,7 @@ const meta_specs = [_]ToolSpec{
const subagent_spec = ToolSpec{
.name = "subagent",
- .desc = "Delegate a self-contained task to a subagent. It has bash, read_file, edit_file, write_file, and codedb (code search); it cannot spawn further subagents and does NOT share your context — the prompt must be self-contained. Returns the subagent final report. Call several times in one response to run tasks in parallel. Pick a persona with agent (builtins: reviewer, researcher, implementer, skeptic — plus any in .harness/agents/), or give the child a custom system_prompt; the trajectory log records the lineage either way. Set run_in_background true to launch it asynchronously instead: you get the agent id back immediately and keep working, then fetch the result with agent_output.",
+ .desc = "Delegate a self-contained task to a subagent. It has bash, read_file, edit_file, write_file, codedb (code search), and skill (load an installed playbook); it cannot spawn further subagents and does NOT share your context — the prompt must be self-contained. Returns the subagent final report. Call several times in one response to run tasks in parallel. Pick a persona with agent (builtins: reviewer, researcher, implementer, skeptic — plus any in .harness/agents/), or give the child a custom system_prompt; the trajectory log records the lineage either way. Set run_in_background true to launch it asynchronously instead: you get the agent id back immediately and keep working, then fetch the result with agent_output.",
.schema =
\\{"type": "object", "properties": {"description": {"type": "string", "description": "Short label for logs, 3-5 words"}, "prompt": {"type": "string", "description": "Complete, self-contained task description"}, "agent": {"type": "string", "description": "Optional: a named agent type (reviewer, researcher, implementer, skeptic, or a .harness/agents/ name) whose persona the child runs with"}, "system_prompt": {"type": "string", "description": "Optional: replace the child's system prompt with a custom one (overrides agent)"}, "isolation": {"type": "string", "enum": ["shared_cwd", "worktree"], "description": "Optional: \"worktree\" gives this child its own scratch git worktree (auto-removed if it finishes with no changes, kept + reported if it has any) instead of the shared working tree — use for parallel agents that edit files. Default shared_cwd (today's behavior), unless the chosen agent persona sets its own default."}, "isolation_fallback": {"type": "boolean", "description": "Optional: if isolation:\"worktree\" fails to set up (not a git repo, git error), run in the shared working tree instead of failing the spawn. Default false (fails the spawn on setup failure)."}, "run_in_background": {"type": "boolean", "description": "Optional: start this subagent asynchronously and return its agent id immediately instead of waiting for it to finish (default false). Poll status/result with agent_output (id, optional wait_ms). A spawn beyond the concurrency cap is queued, never failed."}}, "required": ["description", "prompt"]}
,
@@ -382,7 +386,7 @@ fn writeToolEntry(s: *std.json.Stringify, kind: Provider.Kind, name: []const u8,
/// a per-commit git describe) — bump this only when the schema or JSONL
/// protocol changes shape, so SDK regeneration stays byte-stable across
/// commits.
-pub const schema_version = "0.8"; // #276 P0-3: subagent gained run_in_background; new agent_output tool
+pub const schema_version = "0.9"; // new `skill` tool (SKILL.md playbooks, skill_docs.zig)
/// Emit the machine-readable interface description for `harness --schema`:
/// providers, models, built-in tools (name/description/parameters), and the
diff --git a/src/skill_docs.zig b/src/skill_docs.zig
new file mode 100644
index 00000000..4e1b019b
--- /dev/null
+++ b/src/skill_docs.zig
@@ -0,0 +1,473 @@
+//! Markdown skills: the SKILL.md playbooks the harness discovers on disk and
+//! loads into context on demand.
+//!
+//! NOT to be confused with skills.zig, which is the *companion binary*
+//! registry (`/skills add kuri` — CLI tools the harness upgrades itself with
+//! when they're on PATH). This module is the document-shaped kind, same layout
+//! Claude Code uses: `<dir>/<name>/SKILL.md` (or `<dir>/<name>.md`) with
+//! `name:`/`description:` frontmatter and a markdown body. Discovery is tiered
+//! like fleet.zig's agent personas — bundled < personal < project — and
+//! disclosure is progressive: only the descriptions ride in the system prompt
+//! (promptCatalog), while bodies stay on disk until the `skill` tool loads one
+//! (execSkill). Two skills are embedded in the binary so a fresh install
+//! already knows how to write more (skill-creator) and how to change MCP
+//! config (mcp-config).
+
+const std = @import("std");
+const Io = std.Io;
+const Value = std.json.Value;
+const Allocator = std.mem.Allocator;
+
+const util = @import("util.zig");
+const tools = @import("tools.zig");
+const ToolOutput = tools.ToolOutput;
+const Approvals = @import("approvals.zig").Approvals;
+
+pub const Source = enum {
+ builtin,
+ personal,
+ project,
+
+ pub fn label(self: Source) []const u8 {
+ return switch (self) {
+ .builtin => "bundled",
+ .personal => "personal",
+ .project => "project",
+ };
+ }
+};
+
+pub const Skill = struct {
+ name: []const u8,
+ desc: []const u8,
+ body: []const u8,
+ /// Directory the SKILL.md came from; "" for a bundled skill. Helper files
+ /// that ship with a skill are relative to this, so the load note can point
+ /// the model at them.
+ dir: []const u8 = "",
+ path: []const u8 = "", // the file itself; "" when bundled
+ source: Source = .builtin,
+};
+
+/// Project tier (checked in with the repo) and the personal tier under $HOME.
+pub const project_dir = ".harness/skills";
+/// Read as-is so skills already written for Claude Code work here untouched.
+pub const compat_dir = ".claude/skills";
+
+const file_cap = 256 * 1024; // largest SKILL.md we'll read
+const body_cap = 32 * 1024; // largest body handed to the model in one load
+const desc_cap = 500; // per-skill description budget in the system prompt
+
+/// The `skill` tool's name/description/schema. Kept here (as plain strings, not
+/// a schema.ToolSpec) so schema.zig's catalog needs one entry and no import
+/// cycle. The description must stay free of characters needing JSON escapes.
+pub const tool_name = "skill";
+pub const tool_desc = "Load a skill: the full instructions for one kind of task, kept out of your context until you need them. The system prompt lists only skill names and descriptions, so call this to read the body BEFORE doing work a skill covers, then follow it. Omit name to list every available skill. Skills come from .harness/skills/ (this project), ~/.harness/skills/ (yours), .claude/skills/, plus two bundled ones: skill-creator (write and install a new skill) and mcp-config (inspect or change this workspace's MCP servers).";
+pub const tool_schema =
+ \\{"type": "object", "properties": {"name": {"type": "string", "description": "Skill name to load; omit to list every available skill"}}}
+;
+
+const Parsed = struct { name: []const u8, desc: []const u8, body: []const u8 };
+
+/// Split a SKILL.md into frontmatter fields + body. Same YAML-ish shape as
+/// fleet.zig's persona files: a leading "---\n…\n---\n" block with `name:` and
+/// `description:` lines. No frontmatter is fine — the file is all body and the
+/// name comes from the filename. Comptime-callable (the bundled skills are
+/// parsed at build time).
+fn parseDoc(fallback_name: []const u8, data: []const u8) Parsed {
+ var out: Parsed = .{ .name = fallback_name, .desc = "", .body = std.mem.trim(u8, data, " \t\r\n") };
+ if (!std.mem.startsWith(u8, data, "---\n")) return out;
+ const fm_end = std.mem.indexOfPos(u8, data, 4, "\n---") orelse return out;
+ var lines = std.mem.tokenizeScalar(u8, data[4..fm_end], '\n');
+ while (lines.next()) |raw| {
+ const ln = std.mem.trim(u8, raw, " \t\r");
+ const sep = std.mem.indexOfScalar(u8, ln, ':') orelse continue;
+ const key = std.mem.trim(u8, ln[0..sep], " \t");
+ const val = std.mem.trim(u8, ln[sep + 1 ..], " \t\"'");
+ if (std.mem.eql(u8, key, "name") and val.len > 0) out.name = val;
+ if (std.mem.eql(u8, key, "description") and val.len > 0) out.desc = val;
+ }
+ out.body = std.mem.trim(u8, data[@min(fm_end + "\n---".len + 1, data.len)..], " \t\r\n");
+ return out;
+}
+
+const Embedded = struct { fallback: []const u8, bytes: []const u8 };
+const embedded = [_]Embedded{
+ .{ .fallback = "skill-creator", .bytes = @embedFile("skill_doc_creator") },
+ .{ .fallback = "mcp-config", .bytes = @embedFile("skill_doc_mcp_config") },
+};
+
+/// Skills compiled into the binary: every install has these, no files needed.
+/// Parsed at comptime, so a bundled skill missing its description or body is a
+/// build error rather than a silently absent capability.
+pub const builtins = blk: {
+ // Frontmatter tokenizing + body trimming over a few KB of embedded markdown
+ // blows the default 1000-branch comptime budget.
+ @setEvalBranchQuota(200_000);
+ var out: [embedded.len]Skill = undefined;
+ for (embedded, 0..) |e, i| {
+ const p = parseDoc(e.fallback, e.bytes);
+ if (p.desc.len == 0 or p.body.len == 0)
+ @compileError("bundled skill '" ++ e.fallback ++ "' needs a frontmatter description and a body");
+ out[i] = .{ .name = p.name, .desc = p.desc, .body = p.body };
+ }
+ break :blk out;
+};
+
+/// This session's skills, in precedence order — loaded from the session arena
+/// each time startup.buildSystemPrompt composes a prompt. Read by the system
+/// prompt and `/skills`; the tool itself rescans instead, so a skill written
+/// mid-session is loadable without a restart.
+pub var g_skills: []const Skill = &builtins;
+/// Resolved HOME for the personal tier, so execSkill's rescan finds the same
+/// set the startup scan did.
+var g_home: ?[]const u8 = null;
+
+pub fn load(io: Io, arena: Allocator, home: ?[]const u8) []const Skill {
+ g_home = home;
+ return scan(io, arena, home);
+}
+
+/// Re-scan after the installed set may have changed — a `/skills remove` opt-out
+/// landing in settings, or a SKILL.md written this session — so `/skills` and
+/// any later prompt build stay honest without a restart.
+pub fn reload(io: Io, arena: Allocator) []const Skill {
+ g_skills = scan(io, arena, g_home);
+ return g_skills;
+}
+
+/// Every skill on disk *including* opted-out ones, so `/skills add <name>` can
+/// tell "disabled" apart from "no such skill".
+pub fn scanAll(io: Io, arena: Allocator) []const Skill {
+ return collect(io, arena, g_home).items;
+}
+
+fn scan(io: Io, arena: Allocator, home: ?[]const u8) []const Skill {
+ var list = collect(io, arena, home);
+ applyDisabled(io, arena, &list);
+ return list.items;
+}
+
+/// bundled < ~/.claude/skills < ~/.harness/skills < .claude/skills <
+/// .harness/skills. Each tier shadows the previous by name, so a project skill
+/// wins over a personal one and both win over a bundled one.
+fn collect(io: Io, arena: Allocator, home: ?[]const u8) std.ArrayList(Skill) {
+ var list: std.ArrayList(Skill) = .empty;
+ list.appendSlice(arena, &builtins) catch {};
+ if (home) |h| for ([_][]const u8{ compat_dir, project_dir }) |dir| {
+ const path = std.fmt.allocPrint(arena, "{s}/{s}", .{ h, dir }) catch continue;
+ loadDir(io, arena, &list, path, .personal);
+ };
+ loadDir(io, arena, &list, compat_dir, .project);
+ loadDir(io, arena, &list, project_dir, .project);
+ return list;
+}
+
+/// Merge one directory's skills: `<dir>/<name>/SKILL.md` (a skill that ships
+/// helper files) and `<dir>/<name>.md` (a single-file skill).
+fn loadDir(io: Io, arena: Allocator, list: *std.ArrayList(Skill), dir_path: []const u8, source: Source) void {
+ var dir = Io.Dir.cwd().openDir(io, dir_path, .{ .iterate = true }) catch return;
+ defer dir.close(io);
+ var it = dir.iterate();
+ while (it.next(io) catch null) |entry| switch (entry.kind) {
+ .file => {
+ if (!std.mem.endsWith(u8, entry.name, ".md")) continue;
+ // A bare SKILL.md directly in the skills dir has no name of its own.
+ if (std.ascii.eqlIgnoreCase(entry.name, "SKILL.md")) continue;
+ const path = std.fmt.allocPrint(arena, "{s}/{s}", .{ dir_path, entry.name }) catch continue;
+ mergeFile(io, arena, list, dir_path, path, entry.name[0 .. entry.name.len - ".md".len], source);
+ },
+ // A symlinked skill directory is common when skills are shared between
+ // checkouts; the SKILL.md read below decides whether it's really one.
+ .directory, .sym_link => {
+ const skill_dir = std.fmt.allocPrint(arena, "{s}/{s}", .{ dir_path, entry.name }) catch continue;
+ const path = std.fmt.allocPrint(arena, "{s}/SKILL.md", .{skill_dir}) catch continue;
+ mergeFile(io, arena, list, skill_dir, path, entry.name, source);
+ },
+ else => {},
+ };
+}
+
+fn mergeFile(io: Io, arena: Allocator, list: *std.ArrayList(Skill), dir_path: []const u8, path: []const u8, raw_name: []const u8, source: Source) void {
+ const data = Io.Dir.cwd().readFileAlloc(io, path, arena, .limited(file_cap)) catch return;
+ // raw_name points into the directory iterator's buffer, which the next
+ // entry overwrites — the parsed skill has to own it.
+ const fallback = arena.dupe(u8, raw_name) catch return;
+ const p = parseDoc(fallback, data);
+ if (p.body.len == 0) return; // an empty playbook is not a skill
+ insert(arena, list, .{
+ .name = p.name,
+ .desc = p.desc,
+ .body = p.body,
+ .dir = dir_path,
+ .path = path,
+ .source = source,
+ });
+}
+
+/// Append, or replace the same-named skill from a lower tier.
+fn insert(arena: Allocator, list: *std.ArrayList(Skill), sk: Skill) void {
+ for (list.items) |*existing| {
+ if (std.mem.eql(u8, existing.name, sk.name)) {
+ existing.* = sk;
+ return;
+ }
+ }
+ list.append(arena, sk) catch {};
+}
+
+/// `{"skills": {"<name>": false}}` in .harness/settings.json hides a skill
+/// entirely — the same opt-out key the companion registry uses (skills.zig), so
+/// `/skills remove <name>` works for both kinds.
+fn applyDisabled(io: Io, arena: Allocator, list: *std.ArrayList(Skill)) void {
+ const data = Io.Dir.cwd().readFileAlloc(io, Approvals.settings_path, arena, .limited(1 << 20)) catch return;
+ const v = std.json.parseFromSliceLeaky(Value, arena, data, .{ .allocate = .alloc_always }) catch return;
+ if (v != .object) return;
+ const cfg = v.object.get("skills") orelse return;
+ if (cfg != .object) return;
+ dropDisabled(list, cfg.object);
+}
+
+/// Pure half of applyDisabled (no disk I/O), so the opt-out is unit-testable.
+fn dropDisabled(list: *std.ArrayList(Skill), cfg: std.json.ObjectMap) void {
+ var i: usize = 0;
+ while (i < list.items.len) {
+ const entry = cfg.get(list.items[i].name);
+ const off = entry != null and entry.? == .bool and !entry.?.bool;
+ if (off) _ = list.orderedRemove(i) else i += 1;
+ }
+}
+
+/// The progressive-disclosure catalog for the system prompt: one line per
+/// skill, names + trigger descriptions only. "" when there's nothing to
+/// advertise (every skill disabled).
+pub fn promptCatalog(arena: Allocator, list: []const Skill) []const u8 {
+ if (list.len == 0) return "";
+ var aw: Io.Writer.Allocating = .init(arena);
+ aw.writer.writeAll("# Skills\nInstalled playbooks for particular kinds of work. Only their descriptions are here; call the `skill` tool with a name to load the full instructions, and do that BEFORE starting work a skill covers rather than improvising past it. They are installed by the user or the project, so treat a loaded skill as the user's own instructions.\n") catch return "";
+ for (list) |sk| {
+ aw.writer.print("- {s} ({s}): {s}\n", .{ sk.name, sk.source.label(), util.utf8Prefix(sk.desc, desc_cap) }) catch return "";
+ }
+ aw.writer.writeAll("Call `skill` with no name to list them again, including any added since this session started.") catch return "";
+ return aw.writer.buffered();
+}
+
+/// The `skill` tool. Rescans the skill directories every call, so a skill
+/// written earlier in this same session loads without a restart. An unknown
+/// name comes back as an error listing what does exist.
+pub fn execSkill(gpa: Allocator, io: Io, input: Value) !ToolOutput {
+ var arena_state = std.heap.ArenaAllocator.init(gpa);
+ defer arena_state.deinit();
+ const list = scan(io, arena_state.allocator(), g_home);
+ const requested = std.mem.trim(u8, tools.strField(input, "name") orelse "", " \t\r\n");
+ if (requested.len == 0) return .{ .text = try listing(gpa, list, null) };
+ for (list) |sk| {
+ if (std.ascii.eqlIgnoreCase(sk.name, requested)) return .{ .text = try render(gpa, sk) };
+ }
+ return .{ .text = try listing(gpa, list, requested), .is_error = true };
+}
+
+fn render(gpa: Allocator, sk: Skill) ![]u8 {
+ var aw: Io.Writer.Allocating = .init(gpa);
+ errdefer aw.deinit();
+ try aw.writer.print("# skill: {s} ({s})\n\n", .{ sk.name, sk.source.label() });
+ try aw.writer.writeAll(util.utf8Prefix(sk.body, body_cap));
+ if (sk.body.len > body_cap)
+ try aw.writer.print("\n\n[body truncated at {d} KB — read the rest from {s}]", .{ body_cap / 1024, sk.path });
+ if (sk.dir.len > 0)
+ try aw.writer.print("\n\n[this skill lives in {s}/ — read anything it references from there with read_file]", .{sk.dir});
+ return aw.toOwnedSlice();
+}
+
+fn listing(gpa: Allocator, list: []const Skill, unknown: ?[]const u8) ![]u8 {
+ var aw: Io.Writer.Allocating = .init(gpa);
+ errdefer aw.deinit();
+ if (unknown) |name| try aw.writer.print("no skill named '{s}'. ", .{name});
+ if (list.len == 0) return blk: {
+ try aw.writer.print("no skills installed — write one at {s}/<name>/SKILL.md (frontmatter: name, description; body: the instructions).", .{project_dir});
+ break :blk aw.toOwnedSlice();
+ };
+ try aw.writer.print("{d} skill(s) available — load one by name:\n", .{list.len});
+ for (list) |sk| try aw.writer.print(" {s} ({s}): {s}\n", .{ sk.name, sk.source.label(), sk.desc });
+ return aw.toOwnedSlice();
+}
+
+// --- the `/skills` surface (called from commands_session.zig) ---------------
+
+const skills_companions = @import("skills.zig");
+const ansi = @import("ansi.zig");
+const style = &ansi.style;
+
+/// `/skills remove <name>` for the markdown kind: true when `name` matched an
+/// active skill. Persists through the companions' {"skills": {…: false}} key.
+pub fn handleRemove(io: Io, gpa: Allocator, arena: Allocator, name: []const u8, out: *Io.Writer) !bool {
+ for (g_skills) |sk| {
+ if (!std.mem.eql(u8, sk.name, name)) continue;
+ if (skills_companions.saveSkillSetting(io, gpa, name, false)) {
+ _ = reload(io, arena);
+ try out.print("{s}✓ {s} disabled{s} — the skill tool no longer serves it; it leaves the startup catalog next session\n", .{ style.green, name, style.reset });
+ } else {
+ try out.print("{s}could not write {s} — {s} is still active{s}\n", .{ style.yellow, Approvals.settings_path, name, style.reset });
+ }
+ try out.flush();
+ return true;
+ }
+ return false;
+}
+
+/// `/skills add <name>`: re-enable a markdown skill hidden by an earlier
+/// remove. Scans disabled ones too, so "hidden" and "no such skill" differ.
+pub fn handleAdd(io: Io, gpa: Allocator, arena: Allocator, name: []const u8, out: *Io.Writer) !bool {
+ for (scanAll(io, arena)) |sk| {
+ if (!std.mem.eql(u8, sk.name, name)) continue;
+ if (skills_companions.saveSkillSetting(io, gpa, sk.name, true)) {
+ _ = reload(io, arena);
+ try out.print("{s}✓ {s} enabled{s} — loadable with the skill tool now\n", .{ style.green, sk.name, style.reset });
+ } else {
+ try out.print("{s}could not write {s} — {s} stays disabled{s}\n", .{ style.yellow, Approvals.settings_path, sk.name, style.reset });
+ }
+ try out.flush();
+ return true;
+ }
+ return false;
+}
+
+/// The markdown-skills section of `/skills` — re-scanned so a SKILL.md written
+/// this session shows up without a restart.
+pub fn printSection(io: Io, arena: Allocator, out: *Io.Writer) !void {
+ const md_skills = reload(io, arena);
+ try out.print("{s}skills{s} — SKILL.md playbooks; the model loads one on demand with the `skill` tool\n", .{ style.bold, style.reset });
+ if (md_skills.len == 0) {
+ try out.print(" {s}none — write one at {s}/<name>/SKILL.md{s}\n", .{ style.dim, project_dir, style.reset });
+ } else for (md_skills) |sk| {
+ try out.print(" {s}{s:<16}{s} {s}{s:<9}{s} {s}\n", .{ style.accent, sk.name, style.reset, style.dim, sk.source.label(), style.reset, util.utf8Prefix(sk.desc, 100) });
+ }
+ try out.print(" disable one: /skills remove <name> · re-enable: /skills add <name>\n\n", .{});
+}
+
+test "parseDoc: frontmatter wins over the filename, body starts after it" {
+ const p = parseDoc("from-file", "---\nname: real-name\ndescription: what it does and when\n---\n\n# Body\nstep one\n");
+ try std.testing.expectEqualStrings("real-name", p.name);
+ try std.testing.expectEqualStrings("what it does and when", p.desc);
+ try std.testing.expectEqualStrings("# Body\nstep one", p.body);
+}
+
+test "parseDoc: no frontmatter keeps the filename and the whole file as body" {
+ const p = parseDoc("deploy", "\n# Deploy\nrun it\n");
+ try std.testing.expectEqualStrings("deploy", p.name);
+ try std.testing.expectEqualStrings("", p.desc);
+ try std.testing.expectEqualStrings("# Deploy\nrun it", p.body);
+ // Unterminated frontmatter is body, not a silently swallowed header.
+ const open = parseDoc("x", "---\nname: y\n");
+ try std.testing.expectEqualStrings("x", open.name);
+ try std.testing.expectEqualStrings("---\nname: y", open.body);
+}
+
+test "bundled skills: both parse at comptime with a trigger description" {
+ try std.testing.expectEqual(@as(usize, 2), builtins.len);
+ try std.testing.expectEqualStrings("skill-creator", builtins[0].name);
+ try std.testing.expectEqualStrings("mcp-config", builtins[1].name);
+ for (builtins) |sk| {
+ try std.testing.expect(sk.desc.len > 40); // a trigger, not a topic word
+ try std.testing.expect(sk.body.len > 500);
+ try std.testing.expect(sk.source == .builtin);
+ try std.testing.expectEqualStrings("", sk.dir); // nothing on disk to point at
+ try std.testing.expect(std.mem.indexOfScalar(u8, sk.name, ' ') == null);
+ }
+ // Each bundled skill has to actually teach its subject.
+ try std.testing.expect(std.mem.indexOf(u8, builtins[0].body, project_dir) != null);
+ try std.testing.expect(std.mem.indexOf(u8, builtins[1].body, ".mcp.json") != null);
+ try std.testing.expect(std.mem.indexOf(u8, builtins[1].body, "/mcp trust") != null);
+}
+
+test "tool_desc stays JSON-escape-free (it is spliced into a raw schema string)" {
+ for (tool_desc) |c| try std.testing.expect(c != '"' and c != '\\' and c >= 0x20);
+ try std.testing.expect(std.mem.indexOf(u8, tool_desc, "skill-creator") != null);
+ try std.testing.expect(std.mem.indexOf(u8, tool_desc, "mcp-config") != null);
+}
+
+test "insert: a later tier shadows the same name, others append" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ var list: std.ArrayList(Skill) = .empty;
+ try list.appendSlice(arena, &builtins);
+ insert(arena, &list, .{ .name = "mcp-config", .desc = "mine", .body = "project version", .source = .project });
+ try std.testing.expectEqual(builtins.len, list.items.len); // shadowed, not appended
+ for (list.items) |sk| if (std.mem.eql(u8, sk.name, "mcp-config")) {
+ try std.testing.expectEqualStrings("project version", sk.body);
+ try std.testing.expect(sk.source == .project);
+ };
+ insert(arena, &list, .{ .name = "deploy", .desc = "d", .body = "b", .source = .personal });
+ try std.testing.expectEqual(builtins.len + 1, list.items.len);
+}
+
+test "dropDisabled: {\"<name>\": false} removes it; true and absent keep it" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ var list: std.ArrayList(Skill) = .empty;
+ try list.append(arena, .{ .name = "a", .desc = "", .body = "x" });
+ try list.append(arena, .{ .name = "b", .desc = "", .body = "x" });
+ try list.append(arena, .{ .name = "c", .desc = "", .body = "x" });
+ const v = try std.json.parseFromSliceLeaky(Value, arena, "{\"a\":false,\"b\":true}", .{ .allocate = .alloc_always });
+ dropDisabled(&list, v.object);
+ try std.testing.expectEqual(@as(usize, 2), list.items.len);
+ try std.testing.expectEqualStrings("b", list.items[0].name);
+ try std.testing.expectEqualStrings("c", list.items[1].name);
+}
+
+test "promptCatalog: names + descriptions only, never bodies" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ const list = [_]Skill{
+ .{ .name = "deploy", .desc = "ship a release", .body = "SECRET-BODY-TEXT", .source = .project },
+ };
+ const text = promptCatalog(arena, &list);
+ try std.testing.expect(std.mem.indexOf(u8, text, "deploy (project): ship a release") != null);
+ try std.testing.expect(std.mem.indexOf(u8, text, "SECRET-BODY-TEXT") == null);
+ try std.testing.expect(std.mem.indexOf(u8, text, "`skill`") != null);
+ try std.testing.expectEqualStrings("", promptCatalog(arena, &.{}));
+}
+
+test "promptCatalog: an over-long description is capped on a codepoint boundary" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ const long = "é" ** 400; // 800 bytes, cap lands mid-codepoint without utf8Prefix
+ const list = [_]Skill{.{ .name = "x", .desc = long, .body = "b" }};
+ const text = promptCatalog(arena, &list);
+ try std.testing.expect(std.mem.indexOf(u8, text, long) == null); // capped, not whole
+ try std.testing.expect(std.mem.indexOf(u8, text, long[0 .. desc_cap - 1]) != null); // kept a prefix
+ try std.testing.expect(std.unicode.utf8ValidateSlice(text)); // never mid-codepoint
+}
+
+test "render: bundled load has no file pointer; long bodies say where the rest is" {
+ const gpa = std.testing.allocator;
+ const bundled = try render(gpa, builtins[1]);
+ defer gpa.free(bundled);
+ try std.testing.expect(std.mem.startsWith(u8, bundled, "# skill: mcp-config (bundled)"));
+ try std.testing.expect(std.mem.indexOf(u8, bundled, ".mcp.json") != null);
+ try std.testing.expect(std.mem.indexOf(u8, bundled, "[this skill lives in") == null); // nothing on disk to point at
+
+ const big = try gpa.alloc(u8, body_cap + 100);
+ defer gpa.free(big);
+ @memset(big, 'x');
+ const long = try render(gpa, .{ .name = "big", .desc = "", .body = big, .dir = ".harness/skills/big", .path = ".harness/skills/big/SKILL.md", .source = .project });
+ defer gpa.free(long);
+ try std.testing.expect(std.mem.indexOf(u8, long, "body truncated at 32 KB") != null);
+ try std.testing.expect(std.mem.indexOf(u8, long, ".harness/skills/big/SKILL.md") != null);
+ try std.testing.expect(std.mem.indexOf(u8, long, "[this skill lives in .harness/skills/big/") != null);
+}
+
+test "listing: an unknown name is an error result that names what exists" {
+ const gpa = std.testing.allocator;
+ const text = try listing(gpa, &builtins, "nope");
+ defer gpa.free(text);
+ try std.testing.expect(std.mem.startsWith(u8, text, "no skill named 'nope'."));
+ try std.testing.expect(std.mem.indexOf(u8, text, "skill-creator (bundled)") != null);
+ const empty = try listing(gpa, &.{}, null);
+ defer gpa.free(empty);
+ try std.testing.expect(std.mem.indexOf(u8, empty, ".harness/skills/<name>/SKILL.md") != null);
+}
diff --git a/src/startup.zig b/src/startup.zig
index f745c6d3..023156f0 100644
--- a/src/startup.zig
+++ b/src/startup.zig
@@ -40,6 +40,8 @@ const router_catalog = @import("router_catalog.zig");
const subagent_selection = @import("subagent_selection.zig");
const serde = @import("serde.zig");
const skills = @import("skills.zig");
+const skill_docs = @import("skill_docs.zig");
+const fleet = @import("fleet.zig"); // g_home: resolved before any prompt build (session_run.initApprovalsHooksFleet)
const prompts = @import("prompts.zig");
const learn_store = @import("learn_store.zig");
const learn_bootstrap = @import("learn_bootstrap.zig");
@@ -376,6 +378,15 @@ pub fn buildSystemPrompt(
const note = skills.codedbproNote(mn.server, codedbpro_licensed, mn.note);
sys_normal = try std.fmt.allocPrint(arena, "{s}\n\n{s}", .{ sys_normal, note });
}
+ // Markdown skills (skill_docs.zig): names + trigger descriptions only. The
+ // bodies stay on disk until the model calls the `skill` tool, so a large
+ // installed skill set costs a line each rather than its full text. Loaded
+ // here rather than in session_run so every prompt rebuild rescans the tiers.
+ skill_docs.g_skills = skill_docs.load(io, arena, fleet.g_home);
+ const skill_catalog = skill_docs.promptCatalog(arena, skill_docs.g_skills);
+ if (skill_catalog.len > 0) {
+ sys_normal = try std.fmt.allocPrint(arena, "{s}\n\n{s}", .{ sys_normal, skill_catalog });
+ }
// #326: this returns the composed BASE only. prompts.setSystemPrompts()
// (called once by buildRootAgent, the sole consumer) derives
// sys_normal/sys_strict/sys_ultra/sys_ultra_strict from it — the single