From 411f5e71df057aea3bf8e3844c676c0d8ff74370 Mon Sep 17 00:00:00 2001 From: Amit Shafnir Date: Thu, 2 Jul 2026 12:36:33 +0300 Subject: [PATCH] feat(templates): local template loader, ncl --template, provider-agnostic persona and skills seams Agent templates: folder-only templates under templates/ (context/instructions.md + optional context extras, .mcp.json, skills/). Stamping via ncl groups create --template writes the provider-neutral instructions.prepend.md (inlined at the top of CLAUDE.md/AGENTS.md every spawn), copies context extras preserving their template-relative layout, writes MCP servers to container config, and installs the per-group skills overlay. Includes docs (docs/templates.md, templates/README.md). Setup-wizard wiring ships separately on top of this. Co-Authored-By: Claude Opus 4.8 (1M context) --- CLAUDE.md | 1 + CONTRIBUTING.md | 4 + README.md | 1 + docs/templates.md | 177 +++++++++++++++++++++++++++++ src/claude-md-compose.test.ts | 93 +++++++++++++++ src/claude-md-compose.ts | 23 +++- src/cli/resources/groups.ts | 40 ++++++- src/config.ts | 6 + src/group-persona.test.ts | 32 ++++++ src/group-persona.ts | 30 +++++ src/group-skills.test.ts | 71 ++++++++++++ src/group-skills.ts | 52 +++++++++ src/templates/create-agent.test.ts | 83 ++++++++++++++ src/templates/create-agent.ts | 78 +++++++++++++ src/templates/local-dir.test.ts | 55 +++++++++ src/templates/local-dir.ts | 33 ++++++ src/templates/parse.test.ts | 56 +++++++++ src/templates/parse.ts | 64 +++++++++++ templates/README.md | 48 ++++++++ 19 files changed, 939 insertions(+), 8 deletions(-) create mode 100644 docs/templates.md create mode 100644 src/claude-md-compose.test.ts create mode 100644 src/group-persona.test.ts create mode 100644 src/group-persona.ts create mode 100644 src/group-skills.test.ts create mode 100644 src/group-skills.ts create mode 100644 src/templates/create-agent.test.ts create mode 100644 src/templates/create-agent.ts create mode 100644 src/templates/local-dir.test.ts create mode 100644 src/templates/local-dir.ts create mode 100644 src/templates/parse.test.ts create mode 100644 src/templates/parse.ts create mode 100644 templates/README.md diff --git a/CLAUDE.md b/CLAUDE.md index 0d9952dd1..000855cd4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -280,6 +280,7 @@ This project uses pnpm with `minimumReleaseAge: 4320` (3 days) in `pnpm-workspac | [docs/customizing.md](docs/customizing.md) | Short intro to customizing via skills | | [docs/skills-model.md](docs/skills-model.md) | The skills model in full: recipes, tests, upgrades, migrations | | [docs/skill-guidelines.md](docs/skill-guidelines.md) | Authoritative checklist for writing a skill | +| [docs/templates.md](docs/templates.md) | Agent templates: what they are, stamping via `ncl groups create --template` + the setup wizard, the OneCLI/MCP-credential model, supported providers, and how to contribute one | ## Container Build Cache diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8afea24ba..f976afeb2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,6 +125,10 @@ Instructions here... - Put code in separate files, not inline in the markdown - See the [skills standard](https://code.claude.com/docs/en/skills) for all available frontmatter fields +## Templates + +Agent templates (reusable bundles of instructions + MCP servers + skills) ship in the separate [`nanocoai/nanoclaw-templates`](https://github.com/nanocoai/nanoclaw-templates) repo, not this one. Contribute them there via PR (its README has the anatomy and checklist). For how templates load and the OneCLI credential model, see [docs/templates.md](docs/templates.md). + ## Testing Test your contribution on a fresh clone before submitting. For skills, run the skill end-to-end and verify it works. diff --git a/README.md b/README.md index 0ca3cc6e2..d9873b6f3 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ See [docs/v1-to-v2-changes.md](docs/v1-to-v2-changes.md) for what's different an - **Web access** — search and fetch content from the web - **Container isolation** — agents are sandboxed in Docker (macOS/Linux/WSL2), with optional [Docker Sandboxes](docs/docker-sandboxes.md) micro-VM isolation or Apple Container as a macOS-native opt-in - **Credential security** — agents never hold raw API keys. Outbound requests route through [OneCLI's Agent Vault](https://github.com/onecli/onecli), which injects credentials at request time and enforces per-agent policies and rate limits. +- **Agent templates**: stamp a ready-to-run agent (instructions + MCP tools + skills, no secrets) from a reusable bundle, via the setup wizard or `ncl groups create --template `. Load from the [public library](https://github.com/nanocoai/nanoclaw-templates), a local folder, or any git repo. See [docs/templates.md](docs/templates.md). ## Usage diff --git a/docs/templates.md b/docs/templates.md new file mode 100644 index 000000000..c9e2dc278 --- /dev/null +++ b/docs/templates.md @@ -0,0 +1,177 @@ +# Agent Templates + +A **template** is a reusable folder you stamp into a working agent group: it +carries the agent's standing instructions, its MCP tool servers, and its skills, +but **no secrets and no provider**. Point `ncl` (or the setup wizard) at one and +you get a configured agent in seconds; you choose the runtime/provider +separately. + +Templates are purely additive: no DB migration, no new dependency. **At runtime, +templates are resolved only from a local directory**: `templates/` at the +project root by default (committed but shipped empty), or whatever +`NANOCLAW_TEMPLATES_DIR` points at (a local path only). The setup wizard can also +discover templates from the public registry +([`nanocoai/nanoclaw-templates`](https://github.com/nanocoai/nanoclaw-templates)) +and copy a chosen one into your local `templates/` before stamping. + +## Using a template + +**During install.** `bash nanoclaw.sh` opens the setup wizard. Choose **Template +setup**, then either **NanoClaw template library** (clones the public registry, +copies the template you pick into your local `templates/`) or **Local templates** +(lists what's already in `templates/`). The normal auth step then picks the +runtime, and the wizard stamps and wires your first agent. + +**Anytime, via the CLI:** + +```bash +ncl groups create --template sales/sdr --name "SDR Agent" +``` + +This stamps the group but does **not** wire it to a channel. Run +`/manage-channels` (or `ncl wirings create`) afterward, exactly as for a +hand-built group. + +### The template ref + +`--template ` is a path **relative to the local templates directory** +(`templates/` by default, or `NANOCLAW_TEMPLATES_DIR`). Refs are multi-segment, +e.g. `sales/sdr` → `templates/sales/sdr`. + +For safety the ref must stay inside the templates directory: absolute paths, a +leading `~`, and `../` escapes are rejected. There is no `--source`, no git URL, +and no remote fetch at `ncl` time. Populate `templates/` first (by hand, or via +the setup wizard's library option), then stamp. + +`NANOCLAW_TEMPLATES_DIR` may point the library at another **local** directory; it +is never a URL and never changes at runtime. + +## What's in a template + +The full authoring reference lives in the +[templates repo README](https://github.com/nanocoai/nanoclaw-templates#anatomy-of-a-template). +The short version: only `context/instructions.md` is required; everything else +is optional and defaults sensibly: + +``` +