add template management #14

Closed
opened 2026-04-01 19:20:56 +00:00 by despiegk · 4 comments
Owner

put this in admin section

let users change the prompts

do in markdown editor (like we already have)

put this in admin section let users change the prompts do in markdown editor (like we already have)
Author
Owner

Implementation Spec for Issue #14: Add Template Management

Objective

Add a "Templates" section to the Admin tab listing all AI prompt templates, and a new Templates top-level tab with a markdown editor for editing them — following the same editor pattern already used for slides, themes, and instructions.

Requirements

  • Admin tab shows an "AI Prompt Templates" subsection with cards for each template
  • Each card shows the template name and whether it is customized or using defaults
  • Clicking a template navigates to a new Templates tab with a full markdown editor (textarea + live preview)
  • Editor supports: editing, live markdown preview, save, and reset-to-default
  • Templates are scoped per scan root (using the existing prompts/ directory convention)
  • New RPC methods: template.list, template.get, template.save, template.resetDefault
  • New lib functions: list_templates(), save_template(), reset_template()

Files to Modify

File Description
crates/hero_slides_lib/src/prompts.rs Add list_templates(), save_template(), reset_template() functions
crates/hero_slides_lib/src/lib.rs Re-export new public functions
crates/hero_slides_server/src/rpc.rs Add template.list, template.get, template.save, template.resetDefault RPC handlers
crates/hero_slides_ui/templates/index.html Add Templates section in Admin tab + new Templates tab with editor
crates/hero_slides_ui/static/js/dashboard.js Add JS for template list, editor, save/reset/preview

Implementation Plan

Step 1: Add template management functions to hero_slides_lib

Files: prompts.rs, lib.rs

  • Add list_templates() → returns list of all template names and default content
  • Add save_template(prompts_dir, name, content) → writes template to disk (validates name against ALL_TEMPLATES)
  • Add reset_template(prompts_dir, name) → restores embedded default
  • Re-export from lib.rs
    Dependencies: none

Step 2: Add RPC handlers for template operations

Files: rpc.rs

  • Add template.list → lists all templates with content and default status
  • Add template.get → returns template content and default content
  • Add template.save → saves template (validates name)
  • Add template.resetDefault → restores default, returns content
    Dependencies: Step 1

Step 3: Add template UI (Admin section + Templates tab + editor)

Files: index.html, dashboard.js

  • Add "AI Prompt Templates" section in Admin tab with template cards
  • Add new "Templates" top-level tab with markdown editor (textarea + live preview)
  • Add JS functions: loadTemplatesList, openTemplateEditor (switches to Templates tab), saveTemplate, resetTemplate, updateTemplatePreview
  • Clicking a card in Admin navigates to Templates tab with that template loaded
  • Ctrl+S/Cmd+S keyboard shortcut for save
    Dependencies: Step 2

Acceptance Criteria

  • Admin tab shows "AI Prompt Templates" section listing all templates
  • Each card shows template name and customized/default status
  • Clicking a template opens the Templates tab with markdown editor
  • Live markdown preview in right pane
  • Save persists changes to prompts/ directory
  • "Reset to Default" restores embedded default (with confirmation)
  • Ctrl+S / Cmd+S works in editor
  • save_template validates name against known templates (security)
  • cargo build succeeds with no warnings
  • Existing prompt functionality unaffected

Notes

  • Security: save_template validates name against ALL_TEMPLATES to prevent arbitrary file writes
  • Root path: UI derives scan root from cached decks' parent path
  • Seeding: template.list calls seed_prompts_dir before listing to ensure directory exists
  • No new dependencies: Uses existing libraries only
## Implementation Spec for Issue #14: Add Template Management ### Objective Add a "Templates" section to the Admin tab listing all AI prompt templates, and a new **Templates top-level tab** with a markdown editor for editing them — following the same editor pattern already used for slides, themes, and instructions. ### Requirements - Admin tab shows an "AI Prompt Templates" subsection with cards for each template - Each card shows the template name and whether it is customized or using defaults - Clicking a template navigates to a new **Templates tab** with a full markdown editor (textarea + live preview) - Editor supports: editing, live markdown preview, save, and reset-to-default - Templates are scoped per scan root (using the existing `prompts/` directory convention) - New RPC methods: `template.list`, `template.get`, `template.save`, `template.resetDefault` - New lib functions: `list_templates()`, `save_template()`, `reset_template()` ### Files to Modify | File | Description | |------|-------------| | `crates/hero_slides_lib/src/prompts.rs` | Add `list_templates()`, `save_template()`, `reset_template()` functions | | `crates/hero_slides_lib/src/lib.rs` | Re-export new public functions | | `crates/hero_slides_server/src/rpc.rs` | Add `template.list`, `template.get`, `template.save`, `template.resetDefault` RPC handlers | | `crates/hero_slides_ui/templates/index.html` | Add Templates section in Admin tab + new Templates tab with editor | | `crates/hero_slides_ui/static/js/dashboard.js` | Add JS for template list, editor, save/reset/preview | ### Implementation Plan #### Step 1: Add template management functions to `hero_slides_lib` Files: `prompts.rs`, `lib.rs` - Add `list_templates()` → returns list of all template names and default content - Add `save_template(prompts_dir, name, content)` → writes template to disk (validates name against ALL_TEMPLATES) - Add `reset_template(prompts_dir, name)` → restores embedded default - Re-export from `lib.rs` Dependencies: none #### Step 2: Add RPC handlers for template operations Files: `rpc.rs` - Add `template.list` → lists all templates with content and default status - Add `template.get` → returns template content and default content - Add `template.save` → saves template (validates name) - Add `template.resetDefault` → restores default, returns content Dependencies: Step 1 #### Step 3: Add template UI (Admin section + Templates tab + editor) Files: `index.html`, `dashboard.js` - Add "AI Prompt Templates" section in Admin tab with template cards - Add new "Templates" top-level tab with markdown editor (textarea + live preview) - Add JS functions: loadTemplatesList, openTemplateEditor (switches to Templates tab), saveTemplate, resetTemplate, updateTemplatePreview - Clicking a card in Admin navigates to Templates tab with that template loaded - Ctrl+S/Cmd+S keyboard shortcut for save Dependencies: Step 2 ### Acceptance Criteria - [ ] Admin tab shows "AI Prompt Templates" section listing all templates - [ ] Each card shows template name and customized/default status - [ ] Clicking a template opens the Templates tab with markdown editor - [ ] Live markdown preview in right pane - [ ] Save persists changes to `prompts/` directory - [ ] "Reset to Default" restores embedded default (with confirmation) - [ ] Ctrl+S / Cmd+S works in editor - [ ] `save_template` validates name against known templates (security) - [ ] `cargo build` succeeds with no warnings - [ ] Existing prompt functionality unaffected ### Notes - **Security:** `save_template` validates name against `ALL_TEMPLATES` to prevent arbitrary file writes - **Root path:** UI derives scan root from cached decks' parent path - **Seeding:** `template.list` calls `seed_prompts_dir` before listing to ensure directory exists - **No new dependencies:** Uses existing libraries only
Author
Owner

Test Results

  • Total: 57
  • Passed: 57
  • Failed: 0
  • Ignored: 1 (pre-existing AI integration test)

All tests pass. Build compiles with no new warnings.

## Test Results - **Total:** 57 - **Passed:** 57 - **Failed:** 0 - **Ignored:** 1 (pre-existing AI integration test) ✅ All tests pass. Build compiles with no new warnings.
Author
Owner

Implementation Summary

Changes Made

Library (crates/hero_slides_lib/)

  • src/error.rs — Added InvalidInput(String) variant to HeroSlidesError
  • src/prompts.rs — Added 3 new public functions: list_templates(), save_template(), reset_template()
  • src/lib.rs — Re-exported the new functions

Server (crates/hero_slides_server/)

  • src/rpc.rs — Added 4 RPC handlers: template.list, template.get, template.save, template.resetDefault

UI (crates/hero_slides_ui/)

  • templates/base.html — Added "Templates" nav tab button
  • templates/index.html — Added AI Prompt Templates section in Admin tab + new Templates tab with split-pane markdown editor
  • static/js/dashboard.js — Added template management JS (list, editor, save, reset, live preview, Ctrl+S shortcut)

Test Results

  • 57 tests passed, 0 failed, 1 ignored (pre-existing)
  • Build compiles cleanly with no new warnings
## Implementation Summary ### Changes Made **Library (`crates/hero_slides_lib/`)** - `src/error.rs` — Added `InvalidInput(String)` variant to `HeroSlidesError` - `src/prompts.rs` — Added 3 new public functions: `list_templates()`, `save_template()`, `reset_template()` - `src/lib.rs` — Re-exported the new functions **Server (`crates/hero_slides_server/`)** - `src/rpc.rs` — Added 4 RPC handlers: `template.list`, `template.get`, `template.save`, `template.resetDefault` **UI (`crates/hero_slides_ui/`)** - `templates/base.html` — Added "Templates" nav tab button - `templates/index.html` — Added AI Prompt Templates section in Admin tab + new Templates tab with split-pane markdown editor - `static/js/dashboard.js` — Added template management JS (list, editor, save, reset, live preview, Ctrl+S shortcut) ### Test Results - 57 tests passed, 0 failed, 1 ignored (pre-existing) - Build compiles cleanly with no new warnings
Author
Owner

Implementation committed: f859477

Browse: f859477

Implementation committed: `f859477` Browse: https://forge.ourworld.tf/lhumina_code/hero_slides/commit/f859477
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_slides#14
No description provided.