Repository navigation
fix(templates): surface local templates in /api/templates + reject unprefixed (#843) - #844
Merged
Merged
Conversation
…prefixed (#843) Before this PR: - `GET /api/templates` returned only GitHub-configured templates. The 10+ local templates bundled under `config/agent-templates/` (dd-*, demo-analyst, etc.) were invisible to the frontend. The "Local templates" section in `CreateAgentModal.vue:106` rendered empty even though those templates work fine via the API when called with a `local:` prefix. - `POST /api/agents` with an unprefixed template name (e.g. `"dd-compliance"` instead of `"local:dd-compliance"`) silently fell through the elif chain in `crud.py:129` and created a blank agent — 200 OK, no warning, but no template.yaml, no MCP servers, no metadata. The user only noticed when the agent didn't act like the template promised. What changes - `services/template_service.py`: - New `get_local_templates()` scans `/agent-configs/templates/` (or `./config/agent-templates/` outside the container), parses each `template.yaml`, and returns entries shaped identically to GitHub-template entries — same `id`/`display_name`/`description`/ `source` keys so the existing frontend rendering at `CreateAgentModal.vue:117` handles both without a per-source branch. Each entry's id is `local:<dirname>`. - New `get_local_template(id)` resolves a single `local:<name>` id so the per-template GET endpoint works for both sources. - `get_all_templates()` returns local + GitHub (local first). - `routers/templates.py`: - List endpoint unchanged at the call site — gets the merged list via `get_all_templates()`. - Single-template GET now also handles `local:` ids. - `services/agent_service/crud.py:129`: - Added an explicit prefix validation before the elif chain. Empty `template` (blank agent) is still allowed. Unrecognised prefix returns 400 with a message that names both valid prefixes and suggests the most likely correction (`local:<input>`). Live verification - `GET /api/templates` now returns 27 entries on this dev box (21 local + 6 GitHub). Pre-PR: 6 (GitHub only). - `GET /api/templates/local:dd-compliance` returns the full template metadata including `capabilities` and `use_cases`. - `POST /api/agents` with `template: "dd-compliance"` (no prefix) → 400 with: "Template 'dd-compliance' must start with 'local:' … Example: 'local:dd-compliance' or 'github:owner/repo'." - `POST /api/agents` with empty `template` → 200 (blank agent) - `POST /api/agents` with `template: "local:dd-compliance"` → 200 (no regression on the working path) Tests `tests/unit/test_local_templates_listing.py` — 11 unit tests covering scan happy-path, skip-no-yaml, skip-malformed-yaml, empty-dir, files-not-dirs, deterministic ordering, single-id lookup, wrong-prefix rejection, display-name + description fallback chains. Run stdlib-only via the importlib pattern other backend-internal tests use. Related to #843 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
4 of 6 tasks
vybe
approved these changes
May 14, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Clean two-for-one fix. Shape-matched local entries, correct path resolution, actionable 400 message, lint-compliant tests. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related defects: the UI never saw local templates, and the API silently accepted broken template names.
Before:
GET /api/templatesreturned only GitHub-configured templates. The 10+ bundled local templates underconfig/agent-templates/were invisible to the frontend — the "Local templates" section inCreateAgentModal.vuerendered empty even on installs where local templates were obviously present on disk.POST /api/agentswithtemplate: "dd-compliance"(missinglocal:prefix) silently fell through the elif chain incrud.py:129and created a blank agent — 200 OK, no warning, no metadata applied.After:
GET /api/templatesreturns local + GitHub (27 entries on this dev box; 21 local + 6 GitHub).GET /api/templates/local:<name>resolves a single local template.POST /api/agentswith an unprefixed template returns 400 with a clear actionable message ("Template '' must start with 'local:' … Example: 'local:'"). Empty template still creates a blank agent (unchanged).Files
services/template_service.py— newget_local_templates()+get_local_template(id). Entries shape-match_build_template(GitHub entries) so the frontend handles both sources identically.get_all_templates()merges local first.routers/templates.py— single-template GET now resolveslocal:ids in addition togithub:.services/agent_service/crud.py:129— explicit prefix validation before the elif chain. 400 on unrecognised prefix; empty template still allowed.Live verification
Tests
tests/unit/test_local_templates_listing.py— 11 unit tests:template.yamlget_local_template)github:and unprefixed)All 11 pass locally. Stdlib-only via the importlib loader pattern other tests use.
Test plan
tests/lint_sys_modules.py— uses monkeypatch.setitem)Related to #843
🤖 Generated with Claude Code