feat: Minimale Webansicht für Templates hinzugefügt

- web/index.html: GitLab-ähnliches Dark-Theme UI
- web/templates.json: Dynamische Template-Metadaten
- web/serve.py: Python Dev-Server (Port 8080)
- Templates werden automatisch gescannt und angezeigt
- Features: Suche, Filter, Kopieren von Pfaden
- Styling angelehnt an server_tool frontend

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Michael 2026-04-24 09:31:50 +02:00
parent 9cb083a0a0
commit b17858444d
4 changed files with 583 additions and 1 deletions

View file

@ -246,7 +246,12 @@ Beispiele:
for template_path in sorted(templates): for template_path in sorted(templates):
is_valid, errors = validate_template(template_path) is_valid, errors = validate_template(template_path)
rel_path = str(template_path.relative_to(base_dir)) # Make path relative to base_dir, handling both absolute and relative paths
try:
rel_path = str(template_path.relative_to(base_dir))
except ValueError:
# If template_path is not under base_dir, use absolute path
rel_path = str(template_path)
if is_valid: if is_valid:
print(f"{rel_path}") print(f"{rel_path}")

478
web/index.html Normal file
View file

@ -0,0 +1,478 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prompt Templates</title>
<style>
:root {
--bg-primary: #0f0f0f;
--bg-secondary: #1a1a1a;
--bg-card: #1e1e1e;
--bg-input: #262626;
--bg-hover: #2a2a2a;
--border: #2e2e2e;
--border-light: #3d3d3d;
--text-primary: #dbdbdb;
--text-secondary: #8b8b8b;
--text-muted: #5e5e5e;
--accent: #e24329;
--accent-hover: #fc6d26;
--accent-light: rgba(226, 67, 41, 0.12);
--green: #2da160;
--red: #dd3e31;
--yellow: #e0a118;
--gray: #737373;
--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
--mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: var(--bg-primary);
color: var(--text-primary);
font-family: var(--font);
font-size: 14px;
line-height: 1.5;
min-height: 100vh;
-webkit-font-smoothing: antialiased;
}
.header {
background: var(--bg-secondary);
border-bottom: 1px solid var(--border);
padding: 16px 24px;
display: flex;
align-items: center;
gap: 16px;
}
.header h1 {
font-size: 18px;
font-weight: 600;
}
.header .badge {
background: var(--accent-light);
color: var(--accent);
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
}
.header .actions {
margin-left: auto;
display: flex;
gap: 8px;
}
.btn {
background: var(--bg-input);
color: var(--text-primary);
border: 1px solid var(--border);
padding: 8px 16px;
border-radius: 6px;
font-size: 13px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
}
.btn:hover {
background: var(--bg-hover);
border-color: var(--border-light);
}
.btn-primary {
background: var(--accent);
color: white;
border-color: var(--accent);
}
.btn-primary:hover {
background: var(--accent-hover);
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 24px;
}
.nav {
display: flex;
gap: 8px;
margin-bottom: 24px;
border-bottom: 1px solid var(--border);
padding-bottom: 16px;
}
.nav a {
color: var(--text-secondary);
padding: 8px 16px;
border-radius: 4px;
font-size: 13px;
text-decoration: none;
}
.nav a:hover {
color: var(--text-primary);
background: var(--bg-hover);
}
.nav a.active {
color: var(--accent);
background: var(--accent-light);
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
overflow: hidden;
}
.card-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
}
.card-header h2 {
font-size: 15px;
font-weight: 600;
}
.card-body {
padding: 20px;
}
.template-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 16px;
}
.template-item {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 8px;
padding: 20px;
transition: border-color 0.15s;
}
.template-item:hover {
border-color: var(--border-light);
}
.template-item h3 {
font-size: 14px;
font-weight: 600;
margin-bottom: 8px;
color: var(--accent-hover);
}
.template-item .meta {
display: flex;
gap: 12px;
margin-bottom: 12px;
font-size: 12px;
color: var(--text-secondary);
}
.template-item .meta span {
display: inline-flex;
align-items: center;
gap: 4px;
}
.template-item p {
font-size: 13px;
color: var(--text-secondary);
margin-bottom: 12px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.template-item .tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.template-item .tag {
background: var(--bg-input);
color: var(--text-muted);
padding: 3px 8px;
border-radius: 4px;
font-size: 11px;
}
.template-item .actions {
display: flex;
gap: 8px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--border);
}
.template-item .btn-icon {
padding: 6px 12px;
font-size: 12px;
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: var(--text-muted);
}
.empty-state h3 {
font-size: 16px;
font-weight: 500;
margin-bottom: 8px;
color: var(--text-secondary);
}
.code-block {
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 6px;
padding: 16px;
font-family: var(--mono);
font-size: 12px;
overflow-x: auto;
white-space: pre;
margin-top: 12px;
color: var(--text-primary);
}
/* Filter bar */
.filter-bar {
display: flex;
gap: 12px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.filter-bar input {
background: var(--bg-input);
border: 1px solid var(--border);
color: var(--text-primary);
padding: 8px 12px;
border-radius: 6px;
font-size: 13px;
flex: 1;
min-width: 200px;
}
.filter-bar input:focus {
outline: none;
border-color: var(--accent);
}
/* Responsive */
@media (max-width: 768px) {
.container {
padding: 16px;
}
.template-grid {
grid-template-columns: 1fr;
}
.header {
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.nav {
overflow-x: auto;
padding-bottom: 8px;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Prompt Templates</h1>
<span class="badge">Git Managed</span>
<div class="actions">
<button class="btn btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M5 12h14"/>
</svg>
Neues Template
</button>
</div>
</div>
<div class="container">
<nav class="nav">
<a href="#" class="active">Alle</a>
<a href="#?type=system">System</a>
<a href="#?type=user">User</a>
<a href="#?type=custom">Custom</a>
<a href="#?type=categories">Kategorien</a>
</nav>
<div class="filter-bar">
<input type="text" id="search" placeholder="Suche Templates... (Name, Beschreibung, Tags)">
</div>
<div class="card">
<div class="card-header">
<h2>Templates</h2>
<span id="count">0 Template(s)</span>
</div>
<div class="card-body">
<div class="template-grid" id="templates"></div>
</div>
</div>
<div class="card" style="margin-top: 16px;">
<div class="card-header">
<h2>Usage Beispiel</h2>
</div>
<div class="card-body">
<div class="code-block"># JSON Template
$ cat templates/system/commit_analysis.json | jq -r '.template'
# Validierung
$ python scripts/validate.py templates/system/commit_analysis.json
# Alle validieren
$ python scripts/validate.py --all</div>
</div>
</div>
</div>
<script>
// Template-Daten laden
async function loadTemplates() {
const response = await fetch('templates.json');
if (!response.ok) {
// Fallback: manuell scannen
return await scanTemplates();
}
return response.json();
}
async function scanTemplates() {
const templates = [];
// System Templates
const systemFiles = [
'commit_analysis', 'code_reviewer', 'summarizer'
];
for (const file of systemFiles) {
try {
const response = await fetch(`templates/system/${file}.json`);
if (response.ok) {
const data = await response.json();
templates.push({
path: `templates/system/${file}.json`,
type: 'system',
name: data.name || file,
description: data.description || '',
version: data.version || '1.0',
tags: data.tags || [],
format: 'json'
});
}
} catch (e) {}
}
// User Templates (MD)
const userFiles = ['email_draft', 'brainstorming'];
for (const file of userFiles) {
try {
const response = await fetch(`templates/user/${file}.md`);
if (response.ok) {
const text = await response.text();
const name = text.split('\n')[0].replace('# ', '');
templates.push({
path: `templates/user/${file}.md`,
type: 'user',
name: name,
description: '',
version: '1.0',
tags: [],
format: 'md'
});
}
} catch (e) {}
}
return templates;
}
function renderTemplates(templates) {
const container = document.getElementById('templates');
const count = document.getElementById('count');
count.textContent = `${templates.length} Template(s)`;
if (templates.length === 0) {
container.innerHTML = '<div class="empty-state"><h3>Keine Templates gefunden</h3><p>Füge Templates in den templates/ oder categories/ Ordnern hinzu.</p></div>';
return;
}
container.innerHTML = templates.map(t => `
<div class="template-item">
<h3>${t.name}</h3>
<div class="meta">
<span>🏷️ ${t.type}</span>
<span>📄 ${t.format}</span>
<span>📌 v${t.version}</span>
</div>
<p>${t.description || 'Keine Beschreibung'}</p>
<div class="tags">
${t.tags.map(tag => `<span class="tag">#${tag}</span>`).join('')}
</div>
<div class="actions">
<button class="btn btn-icon" onclick="viewTemplate('${t.path}')">Anzeigen</button>
<button class="btn btn-icon" onclick="copyPath('${t.path}')">Kopieren</button>
</div>
</div>
`).join('');
}
function viewTemplate(path) {
alert(`Template: ${path}\n\nBitte öffne die Datei manuell oder implementiere einen Viewer.`);
}
function copyPath(path) {
navigator.clipboard.writeText(path);
const btn = event.target;
const original = btn.textContent;
btn.textContent = '✓ Kopiert';
setTimeout(() => btn.textContent = original, 2000);
}
// Search
document.getElementById('search').addEventListener('input', async (e) => {
const query = e.target.value.toLowerCase();
const templates = await loadTemplates();
const filtered = templates.filter(t =>
t.name.toLowerCase().includes(query) ||
t.description.toLowerCase().includes(query) ||
t.tags.some(tag => tag.toLowerCase().includes(query))
);
renderTemplates(filtered);
});
// Initial load
loadTemplates().then(renderTemplates);
</script>
</body>
</html>

34
web/serve.py Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""
Minimaler Entwicklungs-Server für die Prompt Templates Webansicht.
Startet auf Port 8080 und dient die statischen Dateien aus.
"""
import http.server
import socketserver
import os
PORT = 8080
DIRECTORY = os.path.dirname(os.path.abspath(__file__))
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)
def do_GET(self):
# Für Root-Pfad: index.htmlservieren
if self.path == '/' or self.path == '/index.html':
self.path = '/index.html'
return super().do_GET()
def main():
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f"Serving Prompt Templates on http://localhost:{PORT}")
print(f"Press Ctrl+C to stop")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nServer stopped")
if __name__ == "__main__":
main()

65
web/templates.json Normal file
View file

@ -0,0 +1,65 @@
[
{
"path": "templates/custom/brainstorming.md",
"type": "custom",
"name": "Brainstorming Assistent",
"description": "",
"version": "1.0",
"tags": [],
"format": "md"
},
{
"path": "templates/user/email_draft.md",
"type": "user",
"name": "Email Entwurf Assistent",
"description": "",
"version": "1.0",
"tags": [],
"format": "md"
},
{
"path": "templates/system/code_reviewer.json",
"type": "system",
"name": "Code Reviewer",
"description": "Analysiert Code auf Qualität, Best Practices und potenzielle Bugs",
"version": "1.0",
"tags": [
"code",
"review",
"quality",
"best-practices",
"security"
],
"format": "json"
},
{
"path": "templates/system/commit_analysis.json",
"type": "system",
"name": "Git Commit Deep Analysis",
"description": "Erstellt eine tiefe Analyse der letzten Git-Commits mit technischer und fachlicher Bewertung",
"version": "1.0",
"tags": [
"git",
"code-review",
"audit",
"analysis",
"commit",
"quality"
],
"format": "json"
},
{
"path": "templates/system/summarizer.json",
"type": "system",
"name": "Text Summarizer",
"description": "Erstellt präzise Zusammenfassungen von Texten mit konfigurierbarer Länge",
"version": "1.0",
"tags": [
"summary",
"text",
"condense",
"abstract"
],
"format": "json"
}
]