KI-Tasks
Task-Management-System für Mensch-KI-Kollaboration.
| Tool | /tasks |
|---|---|
| Datenbank | ki_dev |
| Tabellen | tasks, task_assignments, task_results, task_comments |
Web-UI (RESTful)
| URL | Beschreibung |
|---|---|
| /tasks | Task-Liste mit Statistik und Filtern |
| /tasks/new | Neuen Task erstellen |
| /tasks/{id} | Task-Details anzeigen |
| /tasks/{id}/edit | Task bearbeiten |
Dokumentation
| Thema | Beschreibung |
|---|---|
| API-Referenz | REST-API Endpoints für Task-Management |
| CLI-Befehle | Kommandozeilen-Interface |
| Datenbank-Schema | Tabellenstruktur und SQL |
| Hook-Integration | Automatische Task-Erstellung aus Prompts |
Funktionen
- Task-Typen: human_task, ai_task, mixed
- Status: pending, in_progress, completed, failed, cancelled
- Zuweisungen: Mensch, Ollama, Claude Code, Anthropic API
- Token-Tracking: Input/Output Tokens, Kosten, Dauer
- Subtasks: Hierarchische Task-Struktur
Schnellstart
Task erstellen (API)
curl -X POST http://localhost/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{"title": "Aufgabe", "type": "ai_task"}'
MCP-Tasks
# Tasks auflisten
tasks_list(status="pending")
# Task erstellen
tasks_create(title="Aufgabe", type="ai_task")
API-Referenz
REST-API für das KI-Task-Management System.
Controller\Api\TaskController.
Sie ist unabhängig vom MCP-Tasks Server (Python), der via Claude Code MCP-Protokoll angesprochen wird.
| Implementierung | Controller\Api\TaskController |
|---|---|
| Base-URL | https://dev.campus.systemische-tools.de/api/v1/tasks |
| Format | JSON |
| Authentifizierung | Keine (lokales Netzwerk) |
Endpoints
Tasks
| Methode | Endpoint | Beschreibung |
|---|---|---|
| GET | /api/v1/tasks | Liste aller Tasks |
| GET | /api/v1/tasks/{id} | Task-Details |
| POST | /api/v1/tasks | Task erstellen |
| PUT | /api/v1/tasks/{id} | Task aktualisieren |
| DELETE | /api/v1/tasks/{id} | Task löschen |
| GET | /api/v1/tasks/statistics | Statistiken |
Zuweisungen & Ergebnisse
| Methode | Endpoint | Beschreibung |
|---|---|---|
| POST | /api/v1/tasks/{id}/assign | Task zuweisen |
| PUT | /api/v1/tasks/{id}/status | Status ändern |
| GET | /api/v1/tasks/{id}/results | Ergebnisse abrufen |
| POST | /api/v1/tasks/{id}/results | Ergebnis speichern |
| POST | /api/v1/tasks/{id}/execute | KI-Ausführung |
GET /api/v1/tasks
Listet alle Tasks mit optionalen Filtern.
Query-Parameter
| Parameter | Typ | Beschreibung |
|---|---|---|
| status | string | pending, in_progress, completed, failed, cancelled |
| type | string | human_task, ai_task, mixed |
| search | string | Suche in Titel/Beschreibung |
| limit | int | Max. Anzahl (default: 50) |
| offset | int | Offset für Paginierung |
Beispiel
curl "https://dev.campus.systemische-tools.de/api/v1/tasks?status=pending&limit=10"
Response
{
"success": true,
"data": [
{
"id": 1,
"uuid": "abc-123-...",
"title": "Analyse durchführen",
"type": "ai_task",
"status": "pending",
"created_by": "root",
"created_at": "2025-12-20 10:00:00"
}
],
"meta": {
"total": 42,
"limit": 10,
"offset": 0
}
}
POST /api/v1/tasks
Erstellt einen neuen Task.
Request-Body
{
"title": "Analyse durchführen", // required
"description": "Details...", // optional
"type": "ai_task", // optional: human_task, ai_task, mixed
"created_by": "user", // optional
"created_by_type": "human", // optional: human, ai
"due_date": "2025-12-31 23:59:59", // optional
"parent_task_id": 1, // optional
"metadata": {"key": "value"} // optional
}
Beispiel
curl -X POST https://dev.campus.systemische-tools.de/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Daten analysieren",
"type": "ai_task"
}'
Response (201 Created)
{
"success": true,
"data": {
"id": 2,
"uuid": "def-456-...",
"title": "Daten analysieren",
"status": "pending",
...
}
}
GET /api/v1/tasks/{id}
Gibt Task-Details inkl. Zuweisungen, Ergebnisse und Subtasks zurück.
Response
{
"success": true,
"data": {
"task": { ... },
"assignments": [ ... ],
"results": [ ... ],
"subtasks": [ ... ]
}
}
POST /api/v1/tasks/{id}/assign
Weist einen Task einem Bearbeiter zu.
Request-Body
{
"assignee": "ollama", // required
"assignee_type": "ollama", // required: human, ollama, claude, anthropic_api
"model_name": "mistral", // optional
"assigned_by": "user", // optional
"notes": "Bitte priorisieren" // optional
}
PUT /api/v1/tasks/{id}/status
Ändert den Task-Status.
Request-Body
{
"status": "in_progress", // required
"updated_by": "user", // optional
"updated_by_type": "human" // optional
}
Erlaubte Übergänge
| Von | Nach |
|---|---|
| pending | in_progress, cancelled |
| in_progress | completed, failed, cancelled |
| completed/failed/cancelled | (keine) |
POST /api/v1/tasks/{id}/execute
Führt einen Task mit KI aus.
Request-Body
{
"executor_type": "ollama", // optional: ollama, anthropic_api
"model": "mistral", // optional
"auto_complete": true, // optional: Task nach Erfolg abschließen
"additional_context": "..." // optional: Zusätzlicher Kontext
}
Response
{
"success": true,
"data": {
"id": 1,
"task_id": 2,
"executor": "ollama",
"model_name": "mistral",
"response": "Die Analyse ergab...",
"tokens_input": 150,
"tokens_output": 420,
"tokens_total": 570,
"duration_ms": 12500,
"status": "success"
}
}
Error-Responses
// 400 Bad Request
{
"success": false,
"error": "Title is required"
}
// 404 Not Found
{
"success": false,
"error": "Task not found"
}
// 500 Internal Server Error
{
"success": false,
"error": "Database connection failed"
}
Vergleich: PHP API vs MCP-Tasks
| Aspekt | PHP Web-API | MCP-Tasks Server |
|---|---|---|
| Zugriff | HTTP REST (curl, Browser) | Claude Code MCP-Protokoll |
| Implementierung | PHP Controller | Python MCP Server |
| Pfad | /api/v1/tasks | tasks_list(), tasks_create() |
| Verwendung | Web-Anwendungen, Scripts | Claude Code Sessions |
Änderungshistorie
| Datum | Änderung |
|---|---|
| 2025-12-31 | Klarstellung: PHP Web-API vs MCP-Tasks Server, Host in Beispielen korrigiert |
| 2025-12-20 | Initial erstellt |
CLI-Befehle
Kommandozeilen-Interface für das KI-Task-Management System.
| Pfad | /var/www/tools/ki-tasks/cli.php |
|---|---|
| Aufruf | php cli.php <command> [options] |
Befehle
create
Erstellt einen neuen Task.
php cli.php create --title="Aufgabe" [options]
Optionen:
--title="..." Titel (required)
--description="..." Beschreibung
--type=... human_task, ai_task, mixed (default: human_task)
--created-by=... Ersteller (default: $USER)
Beispiele
# Einfacher Task
php cli.php create --title="Code Review durchführen"
# KI-Task
php cli.php create --title="Analyse" --type=ai_task
# Task mit Beschreibung
php cli.php create \
--title="Dokumentation aktualisieren" \
--description="README.md mit neuen Features aktualisieren" \
--type=human_task
list
Listet Tasks auf.
php cli.php list [options]
Optionen:
--status=... Filter nach Status
--type=... Filter nach Typ
--limit=... Max. Anzahl (default: 20)
Beispiele
# Alle Tasks
php cli.php list
# Nur offene Tasks
php cli.php list --status=pending
# KI-Tasks
php cli.php list --type=ai_task --limit=10
Ausgabe
ID Titel Typ Status Erstellt
---------------------------------------------------------------------------------
1 Test-Task für KI-Analyse ai_task in_progress 2025-12-20 10:00
2 Code Review human_task pending 2025-12-20 11:00
show
Zeigt Task-Details an.
php cli.php show <id>
Beispiel
php cli.php show 1
Task #1: Test-Task für KI-Analyse
============================================================
Status: in_progress
Typ: ai_task
Erstellt: 2025-12-20 10:00:00 von root
Beschreibung:
Dies ist ein Test-Task
Zuweisungen:
- ollama (ollama) - completed
Ergebnisse:
- ollama (mistral) - success - 686 tokens
assign
Weist einen Task zu.
php cli.php assign <id> --to=<name> --type=<type> [options]
Optionen:
--to=... Bearbeiter-Name (required)
--type=... human, ollama, claude, anthropic_api (required)
--model=... Model-Name (optional)
Beispiele
# An Ollama zuweisen
php cli.php assign 1 --to=ollama --type=ollama --model=mistral
# An Mensch zuweisen
php cli.php assign 2 --to=max --type=human
# An Anthropic API zuweisen
php cli.php assign 3 --to=anthropic --type=anthropic_api --model=claude-sonnet-4
execute
Führt einen Task mit KI aus.
php cli.php execute <id> [options]
Optionen:
--executor=... ollama, anthropic_api (default: ollama)
--model=... Model-Name (default: mistral)
--auto-complete Task nach Erfolg abschließen
Beispiele
# Mit Ollama (Mistral)
php cli.php execute 1 --executor=ollama --model=mistral
# Mit llama3.2
php cli.php execute 1 --model=llama3.2
# Mit Anthropic API
php cli.php execute 1 --executor=anthropic_api --model=claude-sonnet-4
# Mit Auto-Complete
php cli.php execute 1 --auto-complete
Ausgabe
ℹ Führe Task #1 mit ollama (mistral) aus...
✓ Erfolgreich ausgeführt!
Tokens: 686 | Dauer: 13043ms
Antwort:
----------------------------------------
Die Analyse ergab folgende Ergebnisse...
status
Ändert den Task-Status.
php cli.php status <id> <new_status>
Status-Werte:
pending Offen
in_progress In Arbeit
completed Abgeschlossen
failed Fehlgeschlagen
cancelled Abgebrochen
Beispiele
# Task starten
php cli.php status 1 in_progress
# Task abschließen
php cli.php status 1 completed
# Task abbrechen
php cli.php status 1 cancelled
complete
Schließt einen Task ab (Shortcut für status + result).
php cli.php complete <id> [options]
Optionen:
--result="..." Ergebnis-Text speichern
Beispiele
# Einfach abschließen
php cli.php complete 1
# Mit Ergebnis
php cli.php complete 1 --result="Alle Tests bestanden"
delete
Löscht einen Task.
php cli.php delete <id>
stats
Zeigt Statistiken an.
php cli.php stats
Ausgabe
Task-Statistiken
========================================
Gesamt: 42
Offen: 15
In Arbeit: 5
Abgeschlossen: 20
Fehlgeschlagen:1
Abgebrochen: 1
Nach Typ:
Mensch: 10
KI: 30
Gemischt: 2
Token-Statistiken
========================================
Ergebnisse: 25
Tokens gesamt: 15420
Kosten (USD): 0.0350
Avg. Dauer: 8500ms
help
Zeigt die Hilfe an.
php cli.php help
Exit-Codes
| Code | Bedeutung |
|---|---|
| 0 | Erfolgreich |
| 1 | Fehler (z.B. Task nicht gefunden, ungültige Parameter) |
Umgebungsvariablen
| Variable | Verwendung |
|---|---|
| $USER | Standard-Wert für created_by und updated_by |
Datenbank-Schema
Tabellenstruktur des KI-Task-Management Systems in der Datenbank ki_dev.
| Datenbank | ki_dev |
|---|---|
| Tabellen | 4 (tasks, task_assignments, task_results, task_comments) |
| Engine | InnoDB |
| Charset | utf8mb4_unicode_ci |
tasks
Haupttabelle für alle Tasks.
| Spalte | Typ | Beschreibung |
|---|---|---|
| id | BIGINT UNSIGNED | Primary Key, Auto-Increment |
| uuid | VARCHAR(36) | Unique Identifier |
| title | VARCHAR(255) | Titel des Tasks |
| description | TEXT | Beschreibung |
| type | ENUM | 'human_task', 'ai_task', 'mixed' |
| status | ENUM | 'pending', 'in_progress', 'completed', 'failed', 'cancelled' |
| created_by | VARCHAR(100) | Ersteller |
| created_by_type | ENUM | 'human', 'ai' |
| parent_task_id | BIGINT UNSIGNED | FK zu übergeordnetem Task |
| due_date | DATETIME | Fälligkeitsdatum |
| created_at | DATETIME(6) | Erstellungszeitpunkt |
| updated_at | DATETIME(6) | Letzte Änderung |
| completed_at | DATETIME(6) | Abschlusszeitpunkt |
| metadata | JSON | Zusätzliche Daten |
Indizes
PRIMARY KEY (id)
UNIQUE KEY uk_uuid (uuid)
KEY idx_status (status)
KEY idx_created_by (created_by)
KEY idx_type (type)
KEY idx_parent_task (parent_task_id)
KEY idx_created_at (created_at)
KEY idx_status_created (status, created_at)
task_assignments
Zuweisungen von Tasks an Bearbeiter.
| Spalte | Typ | Beschreibung |
|---|---|---|
| id | BIGINT UNSIGNED | Primary Key |
| task_id | BIGINT UNSIGNED | FK zu tasks |
| assignee | VARCHAR(100) | Bearbeiter-Name |
| assignee_type | ENUM | 'human', 'ollama', 'claude', 'anthropic_api' |
| model_name | VARCHAR(100) | KI-Model (z.B. mistral) |
| assigned_by | VARCHAR(100) | Zuweisender |
| assigned_by_type | ENUM | 'human', 'ai' |
| status | ENUM | 'pending', 'accepted', 'rejected', 'in_progress', 'completed' |
| assigned_at | DATETIME(6) | Zuweisungszeitpunkt |
| accepted_at | DATETIME(6) | Annahmezeitpunkt |
| completed_at | DATETIME(6) | Abschlusszeitpunkt |
| notes | TEXT | Anmerkungen zur Zuweisung |
task_results
Ergebnisse von Task-Ausführungen mit Token-Tracking.
| Spalte | Typ | Beschreibung |
|---|---|---|
| id | BIGINT UNSIGNED | Primary Key |
| task_id | BIGINT UNSIGNED | FK zu tasks |
| assignment_id | BIGINT UNSIGNED | FK zu task_assignments |
| executor | VARCHAR(100) | Ausführender |
| executor_type | ENUM | 'human', 'ollama', 'claude', 'anthropic_api' |
| model_name | VARCHAR(100) | Verwendetes KI-Model |
| request | TEXT | Anfrage/Prompt |
| response | LONGTEXT | Antwort/Ergebnis |
| request_timestamp | DATETIME(6) | Anfragezeitpunkt |
| response_timestamp | DATETIME(6) | Antwortzeitpunkt |
| duration_ms | INT UNSIGNED | Dauer in Millisekunden |
| tokens_input | INT UNSIGNED | Input-Tokens |
| tokens_output | INT UNSIGNED | Output-Tokens |
| tokens_total | INT UNSIGNED | Gesamt-Tokens |
| cost_usd | DECIMAL(10,6) | Kosten in USD |
| status | ENUM | 'success', 'error', 'partial' |
| error_message | TEXT | Fehlermeldung bei Fehler |
| created_at | DATETIME(6) | Erstellungszeitpunkt |
task_comments
Kommentare und Protokoll-Einträge zu Tasks.
| Spalte | Typ | Beschreibung |
|---|---|---|
| id | BIGINT UNSIGNED | Primary Key |
| task_id | BIGINT UNSIGNED | FK zu tasks |
| author | VARCHAR(100) | Autor |
| author_type | ENUM | 'human', 'ai', 'system' |
| comment_type | ENUM | 'comment', 'status_change', 'assignment', 'result', 'note' |
| content | TEXT | Inhalt |
| metadata | JSON | Zusätzliche Daten |
| created_at | DATETIME(6) | Erstellungszeitpunkt |
Abfragen
Letzte 10 Tasks
SELECT id, title, status, created_at
FROM tasks
ORDER BY id DESC
LIMIT 10;
Tasks nach Status
SELECT status, COUNT(*) as count
FROM tasks
GROUP BY status;
Token-Verbrauch pro Model
SELECT model_name,
SUM(tokens_total) as total_tokens,
SUM(cost_usd) as total_cost,
COUNT(*) as executions
FROM task_results
WHERE model_name IS NOT NULL
GROUP BY model_name
ORDER BY total_tokens DESC;
Änderungshistorie
| Datum | Änderung |
|---|---|
| 2025-12-31 | Fehlende Felder ergänzt: task_assignments (assigned_at, accepted_at, completed_at, notes), task_results (10 Felder), task_comments (metadata, created_at) |
| 2025-12-20 | Initial erstellt |
Hook-Integration
Automatische Task-Erstellung aus Claude Code Prompts via Hook-System.
task_hook.py ist derzeit nicht aktiv.
Er ist nicht in der Hook-Konfiguration registriert. Diese Dokumentation beschreibt die geplante Funktionalität.
| Hook-Script | /var/www/tools/ki-protokoll/claude-hook/task_hook.py |
|---|---|
| Trigger | UserPromptSubmit (nicht aktiv) |
| Status | Nicht aktiviert |
Erkannte Patterns (geplant)
Bei Aktivierung würde der Hook folgende Patterns in User-Prompts erkennen und automatisch Tasks erstellen:
| Pattern | Beispiel | Task-Titel |
|---|---|---|
TODO: <text> | TODO: Tests schreiben | Tests schreiben |
TASK: <text> | TASK: API dokumentieren | API dokumentieren |
@task <text> | @task Refactoring | Refactoring |
#task <text> | #task Bug fixen | Bug fixen |
Funktionsweise (bei Aktivierung)
User-Prompt: "Bitte TODO: Logging implementieren und den Code reviewen"
↓
Hook erkennt Pattern
↓
Task erstellt: "Logging implementieren"
↓
type: ai_task
status: pending
created_by: $USER
created_by_type: ai
Aktivierung
Um den Hook zu aktivieren, muss er in der Hook-Konfiguration registriert werden:
Datei: /root/.claude/settings.json oder .claude/settings.local.json
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "/var/www/tools/ki-protokoll/claude-hook/log_to_db.py",
"timeout": 5
},
{
"type": "command",
"command": "/var/www/tools/ki-protokoll/claude-hook/task_hook.py",
"timeout": 5
}
]
}
]
}
}
Aktive Hooks (aktueller Stand)
Derzeit sind folgende Hooks für UserPromptSubmit aktiv:
| Hook | Funktion |
|---|---|
| log_to_db.py | Protokolliert Prompts in Datenbank |
Hook-Script
Konfiguration
# Datenbankverbindung - verwendet Umgebungsvariablen
DB_CONFIG = {
'host': os.environ.get('CLAUDE_DB_HOST', 'localhost'),
'port': int(os.environ.get('CLAUDE_DB_PORT', '3306')),
'user': os.environ.get('CLAUDE_DB_USER', 'claude_code'),
'password': os.environ.get('CLAUDE_DB_PASSWORD'),
'database': os.environ.get('CLAUDE_DB_NAME', 'ki_dev'),
'charset': 'utf8mb4'
}
# Erkennungsmuster
TASK_PATTERNS = [
(r'TODO:\s*(.+?)(?:\n|$)', 'todo'),
(r'TASK:\s*(.+?)(?:\n|$)', 'task'),
(r'@task\s+(.+?)(?:\n|$)', 'mention'),
(r'#task\s+(.+?)(?:\n|$)', 'hashtag'),
]
Erstellte Task-Eigenschaften
| Eigenschaft | Wert |
|---|---|
| type | ai_task |
| status | pending |
| created_by | $USER oder 'claude-code-hook' |
| created_by_type | ai |
Installation (falls gewünscht)
1. Hook ausführbar machen
chmod +x /var/www/tools/ki-protokoll/claude-hook/task_hook.py
2. Python-Abhängigkeiten
pip3 install pymysql
3. Hook in settings.json registrieren
# Füge den task_hook.py zu den UserPromptSubmit Hooks hinzu (siehe oben)
4. Testen
# In Claude Code eingeben:
"TODO: Test-Task erstellen"
# Prüfen ob Task erstellt wurde
Fehlerbehandlung
Der Hook ist non-blocking. Fehler werden zu stderr geloggt, aber der Claude Code Workflow wird nicht unterbrochen.
# Immer zurückgegeben:
{"continue": true}
Debugging
# Hook manuell testen
echo '{"hook_event_name":"UserPromptSubmit","prompt":"TODO: Test"}' | python3 /var/www/tools/ki-protokoll/claude-hook/task_hook.py
# Logs prüfen (stderr)
# Task #123 created: Test...
Zusammenspiel mit anderen Hooks
| Hook | Funktion | Event | Status |
|---|---|---|---|
| log_to_db.py | Protokolliert alle Events | Alle | Aktiv |
| block_direct_db.py | Blockiert mysql/mariadb CLI | PreToolUse:Bash | Aktiv |
| file_backup_hook.py | Backup vor Dateiänderungen | PreToolUse:Edit|Write | Aktiv |
| task_hook.py | Tasks aus Prompts erstellen | UserPromptSubmit | Nicht aktiv |
Änderungshistorie
| Datum | Änderung |
|---|---|
| 2025-12-31 | Klarstellung: Hook ist nicht aktiv, Aktivierungsanleitung hinzugefügt |
| 2025-12-20 | Initial erstellt |