Compare commits
No commits in common. "main" and "v0.3.3" have entirely different histories.
229
CLAUDE.md
229
CLAUDE.md
@ -1,81 +1,71 @@
|
|||||||
# KAOS — Mastermind
|
# KAOS — Mastermind
|
||||||
|
|
||||||
**Verzija:** 0.6.0
|
**Verzija:** 0.3.0
|
||||||
**Ažurirano:** 2026-02-20
|
**Poslednje ažuriranje:** 2026-02-20
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Učesnici
|
|
||||||
|
|
||||||
| Uloga | Ko | Šta radi |
|
|
||||||
|-------|----|----------|
|
|
||||||
| Klijent | Korisnik | Prijavi problem/zahtev kroz dashboard formu |
|
|
||||||
| Planer | Claude u chatu | Piše taskove, odgovara na pitanja agenata |
|
|
||||||
| Operater | Nenad | Odobrava, pregleda, kontroliše. Šef. |
|
|
||||||
| Agent | Claude Code na serveru | Izvršava taskove (čist kontekst po tasku) |
|
|
||||||
|
|
||||||
Komunikacija: kroz fajlove u TASKS/ (sync Windows ↔ Server).
|
|
||||||
Planer i Agent nikad direktno. → detalji: `TASKS/Workflow-Spec.md`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Dashboard (http://10.0.0.1:8080)
|
|
||||||
|
|
||||||
| Tab | Funkcija |
|
|
||||||
|-----|----------|
|
|
||||||
| Kanban | Board sa kolonama, drag & drop, workflow dugmad |
|
|
||||||
| Dokumenti | Pregled svih .md fajlova (goldmark renderovanje) |
|
|
||||||
| Konzola | Terminal — 2 paralelne claude sesije |
|
|
||||||
| Prijava | Klijent mod (forma) + Operater mod (chat sa claude CLI) |
|
|
||||||
|
|
||||||
### Workflow dugmad na karticama
|
|
||||||
|
|
||||||
| Stanje | Dugme |
|
|
||||||
|--------|-------|
|
|
||||||
| backlog, zavisnosti ❌ | 🔒 Blokiran |
|
|
||||||
| backlog, zavisnosti ✅ | 👁 Pregledaj → ✅ Odobri |
|
|
||||||
| ready | ▶ Pusti (pokreni agenta) |
|
|
||||||
| active | ⚙️ Radi |
|
|
||||||
| review, pitanje | 💬 Odgovori → ▶ Nastavi |
|
|
||||||
| review, završen | 👁 Pregledaj → ✅ Odobri / ↩ Vrati |
|
|
||||||
| done | 📊 Izveštaj |
|
|
||||||
|
|
||||||
### Pokretanje agenta
|
|
||||||
|
|
||||||
"Pusti ▶" pokrene NOV `claude` proces sa čistim kontekstom:
|
|
||||||
```bash
|
|
||||||
claude --permission-mode bypassPermissions -p "Pročitaj CLAUDE.md i radi task TASKS/ready/T{XX}.md"
|
|
||||||
```
|
|
||||||
Svaki task = zasebna sesija. Nema istorije iz prethodnih taskova.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Kad te pokrenu
|
## Kad te pokrenu
|
||||||
|
|
||||||
1. Pogledaj `TASKS/ready/` i `TASKS/review/`
|
Ti razgovaraš sa operaterom. Operater je tvoj šef — on odlučuje šta se radi.
|
||||||
2. Pokaži operateru šta ćeš da radiš — **čekaj odobrenje**
|
|
||||||
3. Izvršavaj po pravilima agenta (`agents/*/CLAUDE.md`)
|
|
||||||
|
|
||||||
### Kad završiš task
|
### Tok rada
|
||||||
|
|
||||||
- Build/test/vet moraju proći
|
1. Operater kaže "radi" ili "T01" ili "nastavi"
|
||||||
- Commit: `T{XX}: Opis na srpskom`
|
2. Pogledaj `TASKS/ready/` — ima li task spreman za rad
|
||||||
- Push + tag (semver) + push tags
|
3. Pogledaj `TASKS/review/` — ima li task sa dopunjenim odgovorima
|
||||||
- Izveštaj u `TASKS/reports/T{XX}-report.md`
|
4. Pokaži operateru šta ćeš da radiš — **čekaj odobrenje**
|
||||||
- Premesti task u `review/`
|
5. Kad dobiješ ok — izvršavaj
|
||||||
|
|
||||||
|
### Kad izvršavaš task
|
||||||
|
|
||||||
|
1. Premesti fajl iz `ready/` u `active/`
|
||||||
|
2. Pročitaj `agents/coder/CLAUDE.md` — pravila kodiranja
|
||||||
|
3. Kod piši u `code/` folderu
|
||||||
|
4. Ako imaš pitanje:
|
||||||
|
- Zapiši pitanje u task fajl pod `## Pitanja`
|
||||||
|
- Premesti fajl iz `active/` u `review/`
|
||||||
|
- Reci operateru "imam pitanje, čekam odgovor u fajlu"
|
||||||
|
- **STANI — ne radi dalje dok operater ne kaže "nastavi"**
|
||||||
|
5. Kad nastaviš:
|
||||||
|
- Pročitaj odgovor u task fajlu
|
||||||
|
- Premesti fajl iz `review/` u `active/`
|
||||||
|
- Nastavi rad
|
||||||
|
6. Kad završiš:
|
||||||
|
- Svi testovi moraju proći
|
||||||
|
- Build mora proći
|
||||||
|
- Commituj: `T{XX}: Opis na srpskom`
|
||||||
|
- Push: `git push origin main`
|
||||||
|
- Tag: `git tag v0.1.{PATCH}` (patch = redni broj završenog taska)
|
||||||
|
- Push tag: `git push origin --tags`
|
||||||
|
- Napiši izveštaj u `TASKS/reports/T{XX}-report.md`
|
||||||
|
- Premesti task fajl iz `active/` u `review/`
|
||||||
|
- Reci operateru "gotovo, čeka pregled"
|
||||||
|
|
||||||
### NIKAD
|
### NIKAD
|
||||||
|
|
||||||
- Ne radi bez odobrenja operatera
|
- Ne radi bez odobrenja operatera
|
||||||
|
- Ne pretpostavljaj šta operater želi
|
||||||
- Ne preskoči "čekaj odobrenje"
|
- Ne preskoči "čekaj odobrenje"
|
||||||
- Ne radi na tasku koji nije u `ready/` ili `review/`
|
- Ne radi na tasku koji nije u `ready/` ili `review/`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Ko šta sme da premesti
|
## Task folderi
|
||||||
|
|
||||||
| Iz → U | Operater | Agent |
|
```
|
||||||
|---------|----------|-------|
|
TASKS/
|
||||||
|
├── backlog/ ← novi taskovi (piše planer, čeka odobrenje operatera)
|
||||||
|
├── ready/ ← odobreni za rad (operater premesti iz backlog/)
|
||||||
|
├── active/ ← u izradi (agent premesti iz ready/)
|
||||||
|
├── review/ ← čeka pregled (agent ima pitanje ili završio)
|
||||||
|
├── done/ ← završeno i odobreno (operater premesti iz review/)
|
||||||
|
└── reports/ ← izveštaji izvršenih taskova
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ko šta sme da premesti
|
||||||
|
|
||||||
|
| Iz → U | Operater (dashboard) | Agent (CLI) |
|
||||||
|
|---------|---------------------|-------------|
|
||||||
| backlog → ready | ✅ | ❌ |
|
| backlog → ready | ✅ | ❌ |
|
||||||
| ready → backlog | ✅ | ❌ |
|
| ready → backlog | ✅ | ❌ |
|
||||||
| ready → active | ❌ | ✅ |
|
| ready → active | ❌ | ✅ |
|
||||||
@ -84,68 +74,93 @@ Svaki task = zasebna sesija. Nema istorije iz prethodnih taskova.
|
|||||||
| review → ready | ✅ | ❌ |
|
| review → ready | ✅ | ❌ |
|
||||||
| done → bilo gde | ❌ | ❌ |
|
| done → bilo gde | ❌ | ❌ |
|
||||||
|
|
||||||
Server validira. Nedozvoljen potez → 403.
|
|
||||||
Deployer jedini KREIRA taskove u backlog/ (greške iz logova).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Struktura
|
## Struktura projekta
|
||||||
|
|
||||||
```
|
```
|
||||||
/opt/kaos/
|
/root/projects/KAOS/
|
||||||
├── CLAUDE.md ← OVO
|
│
|
||||||
├── agents/*/CLAUDE.md ← pravila po agentu
|
├── CLAUDE.md ← OVO — mastermind (v0.3.0)
|
||||||
├── TASKS/ ← backlog/ready/active/review/done/reports/
|
├── README.md
|
||||||
├── code/ ← Go + HTMX (jedan binary, nema npm)
|
│
|
||||||
├── logs/ ← persistent logovi (planirano)
|
├── agents/ ← specijalizovani agenti
|
||||||
├── documentation/ ← eksterna dokumentacija
|
│ ├── triage/CLAUDE.md
|
||||||
└── templates/new-project/ ← template za nove projekte
|
│ ├── task-manager/CLAUDE.md
|
||||||
|
│ ├── coder/CLAUDE.md
|
||||||
|
│ ├── frontend/CLAUDE.md
|
||||||
|
│ ├── checker/CLAUDE.md
|
||||||
|
│ ├── reporter/CLAUDE.md
|
||||||
|
│ ├── docs/CLAUDE.md
|
||||||
|
│ └── deployer/CLAUDE.md
|
||||||
|
│
|
||||||
|
├── documentation/ ← eksterna dokumentacija (tuđe)
|
||||||
|
│
|
||||||
|
├── TASKS/ ← taskovi po stanju
|
||||||
|
│ ├── backlog/
|
||||||
|
│ ├── ready/
|
||||||
|
│ ├── active/
|
||||||
|
│ ├── review/
|
||||||
|
│ ├── done/
|
||||||
|
│ ├── reports/
|
||||||
|
│ ├── MASTER-STATUS.md
|
||||||
|
│ └── Implementation-Tasks.md
|
||||||
|
│
|
||||||
|
└── code/ ← Go kod
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Stack
|
|
||||||
|
|
||||||
Go 1.22+ · Gin · HTMX + Sortable.js (nema npm) · goldmark (markdown) · Gitea (localhost:3000) · Hetzner (10.0.0.1) · Claude Code CLI (Pro licenca)
|
|
||||||
|
|
||||||
Projekat: `/opt/kaos/` (vlasnik: kaos korisnik)
|
|
||||||
Server radi kao root, agenti se pokreću kao `kaos` korisnik.
|
|
||||||
Operater mod u Prijavi koristi `claude` CLI (Pro licenca), ne API.
|
|
||||||
API ključ (ANTHROPIC_API_KEY) se čuva za budući direktni API mod.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Agent registar
|
## Agent registar
|
||||||
|
|
||||||
| Agent | Model | Verzija | Detalji |
|
| Agent | Folder | Model | Verzija |
|
||||||
|-------|-------|---------|---------|
|
|-------|--------|-------|---------|
|
||||||
| Triage | Haiku | 0.1.0 | `agents/triage/CLAUDE.md` |
|
| Triage | agents/triage/ | Haiku | 0.1.0 |
|
||||||
| Task Manager | Sonnet/Haiku | 0.1.0 | `agents/task-manager/CLAUDE.md` |
|
| Task Manager | agents/task-manager/ | Sonnet/Haiku | 0.1.0 |
|
||||||
| Coder | Sonnet/Opus | 0.2.0 | `agents/coder/CLAUDE.md` |
|
| Coder | agents/coder/ | Sonnet/Opus | 0.2.0 |
|
||||||
| Frontend | Sonnet | 0.2.0 | `agents/frontend/CLAUDE.md` |
|
| Frontend | agents/frontend/ | Sonnet | 0.2.0 |
|
||||||
| Checker | Haiku/Opus | 0.1.0 | `agents/checker/CLAUDE.md` |
|
| Checker | agents/checker/ | Haiku/Opus | 0.1.0 |
|
||||||
| Reporter | Haiku | 0.1.0 | `agents/reporter/CLAUDE.md` |
|
| Reporter | agents/reporter/ | Haiku | 0.1.0 |
|
||||||
| Docs | Haiku | 0.1.0 | `agents/docs/CLAUDE.md` |
|
| Docs | agents/docs/ | Haiku | 0.1.0 |
|
||||||
| Deployer | Haiku/Sonnet | 0.2.0 | `agents/deployer/CLAUDE.md` |
|
| Deployer | agents/deployer/ | Haiku | 0.1.0 |
|
||||||
|
|
||||||
Pravilo: najjeftiniji model koji može da uradi posao.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Verzionisanje
|
## Model selekcija
|
||||||
|
|
||||||
Semver. Patch = task, Minor = milestone, Major = breaking change.
|
Pravilo: uvek najjeftiniji model koji može da uradi posao.
|
||||||
Git: commit → push → tag → push tags. Format: `T{XX}: Opis`
|
|
||||||
Timeout: 30 min default (KAOS_TIMEOUT u .env).
|
| Zadatak | Agent | Model | Cena/M tokena |
|
||||||
|
|---------|-------|-------|---------------|
|
||||||
|
| Klasifikacija prijave | triage | Haiku | $0.25/$1.25 |
|
||||||
|
| Generisanje taska | task-manager | Sonnet | $3/$15 |
|
||||||
|
| Kodiranje | coder | Sonnet | $3/$15 |
|
||||||
|
| Kompleksno kodiranje | coder | Opus | $15/$75 |
|
||||||
|
| Frontend | frontend | Sonnet | $3/$15 |
|
||||||
|
| Build + Test | checker | Haiku | $0.25/$1.25 |
|
||||||
|
| Code review | checker | Opus | $15/$75 |
|
||||||
|
| Izveštaj | reporter | Haiku | $0.25/$1.25 |
|
||||||
|
| Dokumentacija | docs | Haiku | $0.25/$1.25 |
|
||||||
|
| Deploy | deployer | Haiku | $0.25/$1.25 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Reference
|
## Pristup
|
||||||
|
|
||||||
| Šta | Gde |
|
| Folder | Čita | Piše |
|
||||||
|-----|-----|
|
|--------|------|------|
|
||||||
| Status svih taskova + bugovi | `TASKS/MASTER-STATUS.md` |
|
| agents/ | ✅ | ❌ |
|
||||||
| Kompletan workflow | `TASKS/Workflow-Spec.md` |
|
| TASKS/ | ✅ | ✅ (status, premesti fajlove) |
|
||||||
| Multi-agent arhitektura | `TASKS/Multi-Agent-Spec.md` |
|
| documentation/ | ✅ | ❌ |
|
||||||
| Format izveštaja | `TASKS/reports/T01-report.md` (primer) |
|
| code/ | ✅ | ✅ (kad izvršava task) |
|
||||||
| Template za novi projekat | `templates/new-project/` |
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Verzionisanje CLAUDE.md fajlova
|
||||||
|
|
||||||
|
Format: `Major.Minor.Patch`
|
||||||
|
- Patch (0.1.1) — sitne ispravke
|
||||||
|
- Minor (0.2.0) — nova pravila, novi korak
|
||||||
|
- Major (1.0.0) — fundamentalna promena
|
||||||
|
|
||||||
|
Kad se promeni CLAUDE.md → podigne verzija → ažurira Agent registar.
|
||||||
|
|||||||
68
README.md
68
README.md
@ -1,9 +1,9 @@
|
|||||||
# KAOS — AI-Supervised Development System
|
# KAOS — AI-Supervised Development System
|
||||||
|
|
||||||
**Verzija:** 0.3.0
|
**Verzija:** 0.1.0
|
||||||
**Status:** Aktivan razvoj
|
**Status:** Pokretanje
|
||||||
**Autor:** DAL d.o.o.
|
**Autor:** DAL d.o.o.
|
||||||
**Poslednje azuriranje:** 2026-02-21
|
**Poslednje ažuriranje:** 2026-02-20
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -101,23 +101,13 @@ Deploy ili dorada
|
|||||||
│ ├── regulations/
|
│ ├── regulations/
|
||||||
│ └── third-party/
|
│ └── third-party/
|
||||||
│
|
│
|
||||||
├── docs/ ← dokumentacija
|
└── TASKS/ ← taskovi, specifikacije, izveštaji
|
||||||
│ ├── SPEC.md
|
├── MASTER-STATUS.md
|
||||||
│ ├── ARCHITECTURE.md
|
├── Architecture.md
|
||||||
│ └── SETUP.md
|
├── Workflow-Spec.md
|
||||||
│
|
├── Supervisor-Spec.md
|
||||||
├── code/ ← Go kod (server, testovi)
|
├── Multi-Agent-Spec.md
|
||||||
│ ├── cmd/kaos-server/
|
├── Implementation-Tasks.md
|
||||||
│ ├── internal/server/
|
|
||||||
│ ├── internal/supervisor/
|
|
||||||
│ └── web/templates/
|
|
||||||
│
|
|
||||||
└── TASKS/ ← taskovi po stanju
|
|
||||||
├── backlog/
|
|
||||||
├── ready/
|
|
||||||
├── active/
|
|
||||||
├── review/
|
|
||||||
├── done/
|
|
||||||
└── reports/
|
└── reports/
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -125,26 +115,30 @@ Deploy ili dorada
|
|||||||
|
|
||||||
## Verzije
|
## Verzije
|
||||||
|
|
||||||
### v0.1 — Osnova
|
### v0.1 — Osnova (TRENUTNO)
|
||||||
- Mastermind + agenti definisani u CLAUDE.md fajlovima
|
- Mastermind + agenti definisani u CLAUDE.md fajlovima
|
||||||
- Supervisor: rucno pokretanje (`kaos-supervisor run T01`)
|
- Supervisor: ručno pokretanje (`kaos-supervisor run T01`)
|
||||||
- Checker: build + test + vet
|
- Checker: build + test + vet (deterministički)
|
||||||
- Izvestaji: markdown u TASKS/reports/
|
- Izveštaji: markdown u TASKS/reports/
|
||||||
|
- Git: direktno na main
|
||||||
|
- Nema baze, nema frontend-a, nema AI trijaže
|
||||||
|
|
||||||
### v0.2 — Dashboard
|
### v0.2 — Automatizacija (planirano)
|
||||||
- Web dashboard sa Kanban board-om
|
- Supervisor daemon ili watch folder
|
||||||
- Drag & drop premestanje taskova
|
- AI trijaža prijava
|
||||||
- SSE real-time update
|
- AI compliance provere (modul, pravila, konvencije)
|
||||||
- Pretraga, dokumenti, prijava taskova
|
- Staging → main branch strategija
|
||||||
|
- Auto-retry za flaky testove
|
||||||
|
- Notifikacije (konfigurabilan kanal)
|
||||||
|
|
||||||
### v0.3 — Konzola i PTY (TRENUTNO)
|
### v0.3 — Kompletni ekosistem (planirano)
|
||||||
- xterm.js terminali u browseru
|
- Frontend dashboard
|
||||||
- Svaki task dobija sopstvenu claude PTY sesiju
|
- WebSocket real-time praćenje
|
||||||
- "Pusti" automatski pokrece rad
|
- Help sistem
|
||||||
- "Proveri" pokrece review sesiju
|
- Embed SDK
|
||||||
- WebSocket za real-time terminal I/O
|
- Cost tracking dashboard
|
||||||
- Replay buffer za reconnect
|
- Metrike i analitika
|
||||||
- 125+ testova u 12 fajlova
|
- Distribucija prema licencama
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -1,114 +1,55 @@
|
|||||||
# KAOS — Master Status
|
# KAOS — Master Status
|
||||||
|
|
||||||
**Verzija:** v0.3.4
|
**Verzija:** 0.3.0
|
||||||
**Poslednje ažuriranje:** 2026-02-20 18:00
|
**Poslednje ažuriranje:** 2026-02-20
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Stanje fajlova na Windows-u
|
## Fajl indeks
|
||||||
|
|
||||||
| Folder | Taskovi |
|
| Fajl | Opis |
|
||||||
|--------|---------|
|
|------|------|
|
||||||
| backlog/ | T17, T18, T23 |
|
| `CLAUDE.md` | Mastermind (v0.3.0) |
|
||||||
| ready/ | T25 |
|
| `README.md` | Pregled projekta, arhitektura, odluke |
|
||||||
| active/ | — |
|
| `agents/*/CLAUDE.md` | 8 agenata (v0.1.0) |
|
||||||
| review/ | — |
|
| `TASKS/MASTER-STATUS.md` | Ovo — navigacija, status |
|
||||||
| done/ | (server ima T01-T22, T24) |
|
| `TASKS/Implementation-Tasks.md` | Svi taskovi detaljno |
|
||||||
|
| `TASKS/Workflow-Spec.md` | 10 koraka, odluke |
|
||||||
|
| `TASKS/Multi-Agent-Spec.md` | Arhitektura agenata |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## v0.1 Supervisor — ZAVRŠENO ✅ (67 testova)
|
## Task folderi
|
||||||
|
|
||||||
| Task | Naslov | Tag |
|
| Folder | Sadržaj | Taskovi |
|
||||||
|------|--------|-----|
|
|--------|---------|---------|
|
||||||
| T01 | Inicijalizacija Go projekta | v0.1.1 |
|
| backlog/ | Čeka odobrenje | T08, T09, T10 |
|
||||||
| T02 | Task loader (parsiranje MD) | v0.1.2 |
|
| ready/ | Odobren za rad | — |
|
||||||
| T03 | Runner (pokretanje Claude Code) | v0.1.4 |
|
| active/ | U izradi | — |
|
||||||
| T04 | Checker (build + test + vet) | v0.1.3 |
|
| review/ | Čeka pregled/odgovor | — |
|
||||||
| T05 | Reporter (pisanje izveštaja) | v0.1.5 |
|
| done/ | Završeno | T01, T02, T03, T04, T05, T06, T07 |
|
||||||
| T06 | CLI (komandni interfejs) | v0.1.6 |
|
|
||||||
| T07 | Integracija (end-to-end) | v0.1.7 |
|
|
||||||
|
|
||||||
## v0.2 Dashboard — ZAVRŠENO ✅ (23 testova)
|
|
||||||
|
|
||||||
| Task | Naslov | Tag |
|
|
||||||
|------|--------|-----|
|
|
||||||
| T08 | HTTP server + API | v0.2.1 |
|
|
||||||
| T09 | Dashboard Kanban + templates | v0.2.2 |
|
|
||||||
| T10 | Drag & Drop + validacija | v0.2.3 |
|
|
||||||
|
|
||||||
## v0.3 UX + Operaterski interfejs — U TOKU
|
|
||||||
|
|
||||||
| Task | Naslov | Tag | Status |
|
|
||||||
|------|--------|-----|--------|
|
|
||||||
| T11 | Fix — svež stanje sa diska | v0.2.4 | done ✅ |
|
|
||||||
| T12 | Prikaz dokumentacije | v0.2.5 | done ✅ |
|
|
||||||
| T13 | Pretraga taskova i dokumentacije | v0.2.6 | done ✅ |
|
|
||||||
| T14 | Konzola (2 sesije) | v0.2.7 | done ✅ |
|
|
||||||
| T15 | Fix — docs širina | v0.2.8 | done ✅ |
|
|
||||||
| T16 | SSE auto-refresh | v0.3.0 | done ✅ |
|
|
||||||
| T19 | Dugme "Pusti" na taskovima | v0.2.9 | done ✅ |
|
|
||||||
| T20 | Workflow dugmad po statusu | v0.3.1 | done ✅ |
|
|
||||||
| T21 | UI fix — konzola, detalj panel, layout | v0.3.2 | done ✅ |
|
|
||||||
| T22 | Prijava — dva moda + dontAsk fix | v0.3.3 | done ✅ |
|
|
||||||
| T24 | PTY za real-time konzolu | v0.3.4 | done ✅ |
|
|
||||||
| T25 | Timestampi + izveštaj prikaz | — | ready |
|
|
||||||
| T26 | Test — prikaži zadnjih 20 linija loga | v0.3.5 | review |
|
|
||||||
| T23 | Persistent logovi + log viewer tab | — | backlog |
|
|
||||||
| T17 | Systemd servis | — | backlog |
|
|
||||||
| T18 | End-to-end test uživo | — | backlog |
|
|
||||||
|
|
||||||
## PROJEKAT UKUPNO: 192 testova ✅
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Taskovi za kreiranje (dogovoreni, nemaju .md)
|
## v0.1 Taskovi — ZAVRŠENO ✅
|
||||||
|
|
||||||
| # | Šta | Prioritet |
|
| Task | Naslov | Tag | Commit | Testova |
|
||||||
|---|-----|-----------|
|
|------|--------|-----|--------|---------|
|
||||||
| T26 | Tema: svetla/tamna/auto | nizak |
|
| T01 | Inicijalizacija Go projekta | v0.1.1 | f001c53 | 6 |
|
||||||
| T27 | Fix: konzola se prazni posle vremena | srednji |
|
| T02 | Task loader (parsiranje MD) | v0.1.2 | 79bcd52 | 17 |
|
||||||
| T28 | Notifikacije (zvuk/badge kad task završi) | srednji |
|
| T03 | Runner (pokretanje Claude Code) | v0.1.4 | 9d2c249 | 7 |
|
||||||
| T29 | Task editor iz dashboarda | nizak |
|
| T04 | Checker (build + test + vet) | v0.1.3 | 5d869f5 | 10 |
|
||||||
| T30 | Autentifikacija (login) | visok (pre produkcije) |
|
| T05 | Reporter (pisanje izveštaja) | v0.1.5 | 028872b | 10 |
|
||||||
| T31 | Deployer agent implementacija | visok |
|
| T06 | CLI (komandni interfejs) | v0.1.6 | 38e1e10 | 9 |
|
||||||
| T32 | Cost tracking (tokeni, cena, vreme po tasku) | srednji |
|
| T07 | Integracija (end-to-end) | v0.1.7 | b2ece98 | 8 |
|
||||||
|
| **Ukupno** | | | | **67** |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Poznati bugovi
|
## Sledeće — v0.2 Dashboard
|
||||||
|
|
||||||
| Bug | Task | Status |
|
| Task | Naslov | Folder | Zavisi od |
|
||||||
|-----|------|--------|
|
|------|--------|--------|-----------|
|
||||||
| Konzola se prazni posle vremena | T27 | za kreiranje |
|
| T08 | HTTP server + API | backlog | T07 ✅ |
|
||||||
| Sync vraća obrisane fajlove iz done/ | — | otvoreno |
|
| T09 | Dashboard kanban board | backlog | T08 |
|
||||||
| "T01 Naslov" template u done/ | — | za brisanje |
|
| T10 | Drag & Drop | backlog | T09 |
|
||||||
| Agent menjao CLAUDE.md | — | dodato pravilo "nikad ne menjaj" |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Ključne odluke
|
|
||||||
|
|
||||||
| Odluka | Detalji |
|
|
||||||
|--------|---------|
|
|
||||||
| HTMX umesto React | Nema npm, jedan binary |
|
|
||||||
| Folder-based state machine | Task stanje = folder lokacija |
|
|
||||||
| Čist kontekst po tasku | Svaki task = nov claude proces |
|
|
||||||
| dontAsk permission mode | Radi kao root bez problema |
|
|
||||||
| Operater mod = claude CLI | Pro licenca, ne API |
|
|
||||||
| Deployer jedini piše backlog/ | Auto-kreiranje taskova iz logova |
|
|
||||||
| Agent nikad ne menja CLAUDE.md | Samo planer |
|
|
||||||
| Max 2 paralelne sesije | Svaka = zaseban claude proces |
|
|
||||||
| Semver tagging | Patch=task, Minor=milestone |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Reference
|
|
||||||
|
|
||||||
| Šta | Gde |
|
|
||||||
|-----|-----|
|
|
||||||
| Mastermind pravila | `CLAUDE.md` v0.6.0 |
|
|
||||||
| Workflow spec | `TASKS/Workflow-Spec.md` |
|
|
||||||
| Multi-agent arhitektura | `TASKS/Multi-Agent-Spec.md` |
|
|
||||||
| Agent pravila | `agents/*/CLAUDE.md` |
|
|
||||||
| Template | `templates/new-project/` |
|
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
# T26 Izveštaj — Test: prikaži zadnjih 20 linija loga
|
|
||||||
|
|
||||||
## Rezultat: USPEŠNO ✅
|
|
||||||
|
|
||||||
## Šta je urađeno
|
|
||||||
|
|
||||||
Handler `handleLogsTail` i ruta `/api/logs/tail` su već postojali (iz ranijeg rada).
|
|
||||||
UI link "Logovi" u layoutu je takođe već bio implementiran.
|
|
||||||
|
|
||||||
Ovaj task je dodao **7 novih testova** za logs endpoint:
|
|
||||||
|
|
||||||
| Test | Šta proverava |
|
|
||||||
|------|---------------|
|
|
||||||
| TestHandleLogsTail_OK | 200, vraća tačno 20 linija iz fajla sa 25 linija |
|
|
||||||
| TestHandleLogsTail_LessThan20Lines | Vraća sve linije kad ih ima manje od 20 |
|
|
||||||
| TestHandleLogsTail_NoLogFile | Poruka kad KAOS_LOG_FILE nije podešen |
|
|
||||||
| TestHandleLogsTail_FileNotFound | Poruka kad fajl ne postoji |
|
|
||||||
| TestHandleLogsTail_Max20Lines | Max 20 linija čak iz fajla sa 100 linija |
|
|
||||||
| TestTailLines | Table-driven test (5 slučajeva) za helper funkciju |
|
|
||||||
| TestTailLines_Content | Provera tačnog sadržaja poslednjih linija |
|
|
||||||
|
|
||||||
## Fajlovi
|
|
||||||
|
|
||||||
| Fajl | Akcija |
|
|
||||||
|------|--------|
|
|
||||||
| code/internal/server/logs_test.go | KREIRAN (161 linija) |
|
|
||||||
|
|
||||||
## Testovi
|
|
||||||
|
|
||||||
- Novih: 7 (12 sub-testova ukupno)
|
|
||||||
- Svi prolaze ✅
|
|
||||||
- `go build ./...` ✅
|
|
||||||
- `go vet ./...` ✅
|
|
||||||
- PROJEKAT UKUPNO: 192 testova ✅
|
|
||||||
|
|
||||||
## Commit
|
|
||||||
|
|
||||||
- `4031593` — T26: Testovi za endpoint zadnjih 20 linija loga
|
|
||||||
|
|
||||||
## Vremena
|
|
||||||
|
|
||||||
| Događaj | Vreme |
|
|
||||||
|---------|-------|
|
|
||||||
| Početak | 2026-02-21 04:33 |
|
|
||||||
| Završetak | 2026-02-21 04:40 |
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
# T26: Test — prikaži zadnjih 20 linija loga
|
|
||||||
|
|
||||||
**Kreirao:** planer
|
|
||||||
**Datum:** 2026-02-20
|
|
||||||
**Agent:** coder
|
|
||||||
**Model:** Sonnet
|
|
||||||
**Zavisi od:** —
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Opis
|
|
||||||
|
|
||||||
Jednostavan test task. Dodaj endpoint koji prikazuje zadnjih 20 linija
|
|
||||||
server loga.
|
|
||||||
|
|
||||||
## Šta treba
|
|
||||||
|
|
||||||
1. Endpoint: GET /api/logs/tail
|
|
||||||
2. Čita zadnjih 20 linija iz stdout/journalctl loga servera
|
|
||||||
3. Vraća plain text
|
|
||||||
|
|
||||||
```go
|
|
||||||
// Ako server piše u fajl:
|
|
||||||
tail -20 /tmp/kaos-server.log
|
|
||||||
|
|
||||||
// Ili journalctl:
|
|
||||||
journalctl -u kaos-server -n 20 --no-pager
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Na dashboardu: dodaj link "Poslednji logovi" negde vidljivo
|
|
||||||
|
|
||||||
## Testovi
|
|
||||||
|
|
||||||
- GET /api/logs/tail → 200, vraća tekst
|
|
||||||
- Odgovor ima max 20 linija
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Pitanja
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Odgovori
|
|
||||||
|
|
||||||
## Vremena
|
|
||||||
|
|
||||||
| Događaj | Vreme |
|
|
||||||
|---------|-------|
|
|
||||||
| Pokrenut | 2026-02-20 15:52 |
|
|
||||||
| Pokrenut | 2026-02-21 04:05 |
|
|
||||||
| Pokrenut (→active) | 2026-02-21 04:11 |
|
|
||||||
| Pokrenut (→active) | 2026-02-21 04:33 |
|
|
||||||
| Završen (→review) | 2026-02-21 04:40 |
|
|
||||||
66
TESTING.md
66
TESTING.md
@ -1,66 +0,0 @@
|
|||||||
# KAOS — Test Checklist
|
|
||||||
|
|
||||||
## Dashboard (Kanban)
|
|
||||||
- [ ] Ucitavanje sa svim kolonama (backlog, ready, active, review, done)
|
|
||||||
- [ ] Prikaz taskova u ispravnim kolonama
|
|
||||||
- [ ] Klik na task otvara detail modal
|
|
||||||
- [ ] Escape zatvara modal
|
|
||||||
- [ ] Klik na pozadinu zatvara modal
|
|
||||||
- [ ] Drag & drop premestanje taskova
|
|
||||||
- [ ] SSE auto-refresh kad se task promeni
|
|
||||||
- [ ] Tema (svetla/tamna/auto) radi
|
|
||||||
|
|
||||||
## Task akcije
|
|
||||||
- [ ] "Odobri" premesta backlog -> ready
|
|
||||||
- [ ] "Pusti" premesta ready -> active i pokrece claude
|
|
||||||
- [ ] "Pregledaj" otvara task detail za review
|
|
||||||
- [ ] "Proveri" pokrece review claude sesiju
|
|
||||||
- [ ] "Odobri" (review) premesta review -> done
|
|
||||||
- [ ] "Vrati" premesta review -> ready
|
|
||||||
- [ ] "Izvestaj" otvara report modal
|
|
||||||
- [ ] Blokiran task prikazuje "Blokiran" dugme
|
|
||||||
|
|
||||||
## Konzola
|
|
||||||
- [ ] Prazna stranica kad nema sesija (empty state)
|
|
||||||
- [ ] Posle "Pusti" - terminal se pojavljuje
|
|
||||||
- [ ] Terminal prikazuje claude output u realnom vremenu
|
|
||||||
- [ ] Keyboard input radi (moze se tipkati u terminal)
|
|
||||||
- [ ] Terminal resize radi
|
|
||||||
- [ ] Reconnect na page reload (replay buffer)
|
|
||||||
- [ ] "Ugasi" dugme zavrsava sesiju
|
|
||||||
- [ ] Vise sesija istovremeno
|
|
||||||
- [ ] Review sesija prikazuje "[pregled]" label
|
|
||||||
|
|
||||||
## Pretraga
|
|
||||||
- [ ] Pretrazuje taskove po naslovu i ID-u
|
|
||||||
- [ ] Pretrazuje dokumente
|
|
||||||
- [ ] Pretrazuje izvestaje
|
|
||||||
- [ ] Case-insensitive
|
|
||||||
- [ ] Prazna pretraga ne vraca rezultate
|
|
||||||
- [ ] "Nema rezultata" za nepostojeci termin
|
|
||||||
|
|
||||||
## Dokumenti
|
|
||||||
- [ ] Lista svih .md fajlova
|
|
||||||
- [ ] Pregled sa markdown renderovanjem
|
|
||||||
- [ ] Tabele se renderuju
|
|
||||||
- [ ] Breadcrumbs navigacija
|
|
||||||
- [ ] Sidebar sa listom fajlova
|
|
||||||
- [ ] Path traversal blokiran
|
|
||||||
|
|
||||||
## Prijava
|
|
||||||
- [ ] Klijent mod: forma za prijavu
|
|
||||||
- [ ] Operater mod: chat sa claude
|
|
||||||
- [ ] Task se kreira u backlog/ sa ispravnim ID-om
|
|
||||||
- [ ] Prazan naslov vraca gresku
|
|
||||||
|
|
||||||
## Server logovi
|
|
||||||
- [ ] Prikaz poslednjih logova
|
|
||||||
- [ ] Modal se zatvara
|
|
||||||
|
|
||||||
## API
|
|
||||||
- [ ] GET /api/tasks vraca JSON listu
|
|
||||||
- [ ] GET /api/task/:id vraca detalj sa sadrzajem
|
|
||||||
- [ ] POST /api/task/:id/move premesta task
|
|
||||||
- [ ] Nepostojeci task vraca 404
|
|
||||||
- [ ] Nevalidan folder vraca 400
|
|
||||||
- [ ] Zabranjeni prelazi vracaju 403
|
|
||||||
@ -2,4 +2,3 @@ KAOS_TIMEOUT=30m
|
|||||||
KAOS_PROJECT_PATH=.
|
KAOS_PROJECT_PATH=.
|
||||||
KAOS_TASKS_DIR=../TASKS
|
KAOS_TASKS_DIR=../TASKS
|
||||||
KAOS_PORT=8080
|
KAOS_PORT=8080
|
||||||
KAOS_LOG_FILE=/tmp/kaos-server.log
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ require (
|
|||||||
github.com/bytedance/sonic v1.14.0 // indirect
|
github.com/bytedance/sonic v1.14.0 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||||
github.com/creack/pty v1.1.24 // indirect
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
@ -16,7 +15,6 @@ require (
|
|||||||
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/goccy/go-yaml v1.18.0 // indirect
|
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
|||||||
@ -4,8 +4,6 @@ github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZw
|
|||||||
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||||
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
|
||||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -30,8 +28,6 @@ github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7Lk
|
|||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||||
|
|||||||
@ -20,8 +20,6 @@ type Config struct {
|
|||||||
TasksDir string
|
TasksDir string
|
||||||
// Port is the HTTP server port.
|
// Port is the HTTP server port.
|
||||||
Port string
|
Port string
|
||||||
// LogFile is the path to the server log file (optional).
|
|
||||||
LogFile string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load reads configuration from environment variables.
|
// Load reads configuration from environment variables.
|
||||||
@ -55,14 +53,11 @@ func Load() (*Config, error) {
|
|||||||
port = "8080"
|
port = "8080"
|
||||||
}
|
}
|
||||||
|
|
||||||
logFile := os.Getenv("KAOS_LOG_FILE")
|
|
||||||
|
|
||||||
return &Config{
|
return &Config{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
ProjectPath: projectPath,
|
ProjectPath: projectPath,
|
||||||
TasksDir: tasksDir,
|
TasksDir: tasksDir,
|
||||||
Port: port,
|
Port: port,
|
||||||
LogFile: logFile,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,205 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAPIGetTasks(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/tasks", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
var tasks []taskResponse
|
|
||||||
if err := json.Unmarshal(w.Body.Bytes(), &tasks); err != nil {
|
|
||||||
t.Fatalf("invalid JSON: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(tasks) != 2 {
|
|
||||||
t.Fatalf("expected 2 tasks, got %d", len(tasks))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that tasks have correct statuses
|
|
||||||
statuses := map[string]string{}
|
|
||||||
for _, task := range tasks {
|
|
||||||
statuses[task.ID] = task.Status
|
|
||||||
}
|
|
||||||
if statuses["T01"] != "done" {
|
|
||||||
t.Errorf("expected T01 status done, got %s", statuses["T01"])
|
|
||||||
}
|
|
||||||
if statuses["T08"] != "backlog" {
|
|
||||||
t.Errorf("expected T08 status backlog, got %s", statuses["T08"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIGetTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
var detail taskDetailResponse
|
|
||||||
if err := json.Unmarshal(w.Body.Bytes(), &detail); err != nil {
|
|
||||||
t.Fatalf("invalid JSON: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if detail.ID != "T01" {
|
|
||||||
t.Errorf("expected T01, got %s", detail.ID)
|
|
||||||
}
|
|
||||||
if detail.Content == "" {
|
|
||||||
t.Error("expected non-empty content")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIGetTask_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/task/T99", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify file was moved
|
|
||||||
if _, err := os.Stat(filepath.Join(srv.Config.TasksDir, "ready", "T08.md")); err != nil {
|
|
||||||
t.Error("expected T08.md in ready/")
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(filepath.Join(srv.Config.TasksDir, "backlog", "T08.md")); !os.IsNotExist(err) {
|
|
||||||
t.Error("expected T08.md removed from backlog/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T99/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_InvalidFolder(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=invalid", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("expected 400, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_ForbiddenToActive(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Put T08 in ready first
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Try to move ready → active (agent-only)
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=active", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusForbidden {
|
|
||||||
t.Fatalf("expected 403 for ready→active, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_ForbiddenActiveToReview(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Put T08 in active
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "active", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Try to move active → review (agent-only)
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=review", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusForbidden {
|
|
||||||
t.Fatalf("expected 403 for active→review, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_AllowedBacklogToReady(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200 for backlog→ready, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_AllowedReviewToDone(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Put T08 in review
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "review", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=done", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200 for review→done, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPIMoveTask_AddsTimestamp(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(filepath.Join(srv.Config.TasksDir, "ready", "T08.md"))
|
|
||||||
text := string(content)
|
|
||||||
if !containsStr(text, "Odobren (→ready)") {
|
|
||||||
t.Error("expected timestamp in API-moved task file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,168 +1,404 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os/exec"
|
||||||
"path/filepath"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// taskSession represents a PTY session tied to a specific task.
|
// sessionState represents the state of a console session.
|
||||||
type taskSession struct {
|
type sessionState struct {
|
||||||
TaskID string
|
mu sync.Mutex
|
||||||
Type string // "work" or "review"
|
status string // "idle" or "running"
|
||||||
PTY *consolePTYSession
|
cmd *exec.Cmd
|
||||||
Started time.Time
|
execID string
|
||||||
|
taskID string // which task is being worked on (if any)
|
||||||
|
history []historyEntry
|
||||||
|
output []string
|
||||||
|
listeners map[chan string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// taskSessionResponse is the JSON representation of a task session.
|
// historyEntry represents a command in the session history.
|
||||||
type taskSessionResponse struct {
|
type historyEntry struct {
|
||||||
TaskID string `json:"task_id"`
|
Command string `json:"command"`
|
||||||
Type string `json:"type"`
|
ExecID string `json:"exec_id"`
|
||||||
Status string `json:"status"` // "running" or "exited"
|
Timestamp string `json:"timestamp"`
|
||||||
Started string `json:"started"`
|
Status string `json:"status"` // "running", "done", "error", "killed"
|
||||||
}
|
}
|
||||||
|
|
||||||
// taskSessionManager manages dynamic PTY sessions per task.
|
// execRequest is the JSON body for starting a command.
|
||||||
type taskSessionManager struct {
|
type execRequest struct {
|
||||||
mu sync.RWMutex
|
Cmd string `json:"cmd"`
|
||||||
sessions map[string]*taskSession
|
Session int `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTaskSessionManager() *taskSessionManager {
|
// execResponse is the JSON response after starting a command.
|
||||||
return &taskSessionManager{
|
type execResponse struct {
|
||||||
sessions: make(map[string]*taskSession),
|
ExecID string `json:"exec_id"`
|
||||||
|
Session int `json:"session"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// sessionStatus represents the status of a session for the API.
|
||||||
|
type sessionStatus struct {
|
||||||
|
Session int `json:"session"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
TaskID string `json:"task_id,omitempty"`
|
||||||
|
ExecID string `json:"exec_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// consoleManager manages the two console sessions.
|
||||||
|
type consoleManager struct {
|
||||||
|
sessions [2]*sessionState
|
||||||
|
mu sync.Mutex
|
||||||
|
counter int
|
||||||
|
}
|
||||||
|
|
||||||
|
// newConsoleManager creates a new console manager with two idle sessions.
|
||||||
|
func newConsoleManager() *consoleManager {
|
||||||
|
return &consoleManager{
|
||||||
|
sessions: [2]*sessionState{
|
||||||
|
{status: "idle", listeners: make(map[chan string]bool)},
|
||||||
|
{status: "idle", listeners: make(map[chan string]bool)},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sessionKey returns a unique key for a task session.
|
// nextExecID generates a unique execution ID.
|
||||||
func sessionKey(taskID, sessionType string) string {
|
func (cm *consoleManager) nextExecID() string {
|
||||||
if sessionType == "review" {
|
cm.mu.Lock()
|
||||||
return taskID + "-review"
|
defer cm.mu.Unlock()
|
||||||
}
|
cm.counter++
|
||||||
return taskID
|
return fmt.Sprintf("exec-%d-%d", time.Now().Unix(), cm.counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// startSession spawns an interactive claude PTY and sends the task prompt.
|
// getSession returns a session by index (0 or 1).
|
||||||
func (sm *taskSessionManager) startSession(taskID, sessionType, projectDir, prompt string) (*taskSession, error) {
|
func (cm *consoleManager) getSession(idx int) *sessionState {
|
||||||
key := sessionKey(taskID, sessionType)
|
if idx < 0 || idx > 1 {
|
||||||
|
return nil
|
||||||
sm.mu.Lock()
|
|
||||||
if _, exists := sm.sessions[key]; exists {
|
|
||||||
sm.mu.Unlock()
|
|
||||||
return nil, fmt.Errorf("sesija %s već postoji", key)
|
|
||||||
}
|
}
|
||||||
sm.mu.Unlock()
|
return cm.sessions[idx]
|
||||||
|
|
||||||
ptySess, err := spawnTaskPTY(projectDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sess := &taskSession{
|
// handleConsoleExec starts a command in a session.
|
||||||
TaskID: taskID,
|
func (s *Server) handleConsoleExec(c *gin.Context) {
|
||||||
Type: sessionType,
|
var req execRequest
|
||||||
PTY: ptySess,
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
Started: time.Now(),
|
c.JSON(http.StatusBadRequest, gin.H{"error": "nevalidan JSON: " + err.Error()})
|
||||||
}
|
|
||||||
|
|
||||||
sm.mu.Lock()
|
|
||||||
sm.sessions[key] = sess
|
|
||||||
sm.mu.Unlock()
|
|
||||||
|
|
||||||
log.Printf("Session[%s]: started (PID %d)", key, ptySess.Cmd.Process.Pid)
|
|
||||||
|
|
||||||
// Write prompt to file, then send a one-liner to claude
|
|
||||||
// (multi-line prompt can't be typed into PTY — each \n submits early)
|
|
||||||
promptFile := filepath.Join(os.TempDir(), fmt.Sprintf("kaos-%s-prompt.txt", key))
|
|
||||||
if err := os.WriteFile(promptFile, []byte(prompt), 0644); err != nil {
|
|
||||||
log.Printf("Session[%s]: failed to write prompt file: %v", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
subID := fmt.Sprintf("init-%d", time.Now().UnixNano())
|
|
||||||
ch := ptySess.Subscribe(subID)
|
|
||||||
|
|
||||||
timer := time.NewTimer(30 * time.Second)
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
// Claude is alive and producing output
|
|
||||||
case <-timer.C:
|
|
||||||
log.Printf("Session[%s]: timeout waiting for claude to start", key)
|
|
||||||
case <-ptySess.Done():
|
|
||||||
log.Printf("Session[%s]: claude exited before producing output", key)
|
|
||||||
ptySess.Unsubscribe(subID)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
timer.Stop()
|
|
||||||
ptySess.Unsubscribe(subID)
|
|
||||||
|
|
||||||
// Let claude fully render its welcome screen
|
if req.Session < 1 || req.Session > 2 {
|
||||||
time.Sleep(2 * time.Second)
|
c.JSON(http.StatusBadRequest, gin.H{"error": "sesija mora biti 1 ili 2"})
|
||||||
|
return
|
||||||
// Send one-liner that tells claude to read the prompt file
|
|
||||||
oneliner := fmt.Sprintf("Pročitaj fajl %s i uradi SVE što piše unutra.", promptFile)
|
|
||||||
log.Printf("Session[%s]: sending prompt via file %s (%d bytes)", key, promptFile, len(prompt))
|
|
||||||
ptySess.WriteInput([]byte(oneliner + "\n"))
|
|
||||||
}()
|
|
||||||
|
|
||||||
return sess, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSessionByKey returns a session by its full key.
|
sessionIdx := req.Session - 1
|
||||||
func (sm *taskSessionManager) getSessionByKey(key string) *taskSession {
|
session := s.console.getSession(sessionIdx)
|
||||||
sm.mu.RLock()
|
|
||||||
defer sm.mu.RUnlock()
|
session.mu.Lock()
|
||||||
return sm.sessions[key]
|
if session.status == "running" {
|
||||||
|
session.mu.Unlock()
|
||||||
|
c.JSON(http.StatusConflict, gin.H{"error": "sesija je zauzeta"})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// listSessions returns all active sessions.
|
execID := s.console.nextExecID()
|
||||||
func (sm *taskSessionManager) listSessions() []taskSessionResponse {
|
session.status = "running"
|
||||||
sm.mu.RLock()
|
session.execID = execID
|
||||||
defer sm.mu.RUnlock()
|
session.output = nil
|
||||||
|
session.mu.Unlock()
|
||||||
|
|
||||||
result := make([]taskSessionResponse, 0, len(sm.sessions))
|
// Add to history
|
||||||
for _, sess := range sm.sessions {
|
entry := historyEntry{
|
||||||
status := "running"
|
Command: req.Cmd,
|
||||||
select {
|
ExecID: execID,
|
||||||
case <-sess.PTY.Done():
|
Timestamp: timeNow(),
|
||||||
status = "exited"
|
Status: "running",
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = append(result, taskSessionResponse{
|
session.mu.Lock()
|
||||||
TaskID: sess.TaskID,
|
session.history = append(session.history, entry)
|
||||||
Type: sess.Type,
|
if len(session.history) > 50 {
|
||||||
Status: status,
|
session.history = session.history[len(session.history)-50:]
|
||||||
Started: sess.Started.Format("15:04:05"),
|
}
|
||||||
|
session.mu.Unlock()
|
||||||
|
|
||||||
|
// Start the command in background
|
||||||
|
go s.runCommand(session, req.Cmd, execID)
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, execResponse{
|
||||||
|
ExecID: execID,
|
||||||
|
Session: req.Session,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
// runCommand executes a command and streams output to listeners.
|
||||||
|
func (s *Server) runCommand(session *sessionState, command, execID string) {
|
||||||
|
// Build the claude command
|
||||||
|
cmd := exec.Command("claude", "--dangerously-skip-permissions", "-p", command)
|
||||||
|
cmd.Dir = s.projectRoot()
|
||||||
|
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
s.sendToSession(session, "[greška: "+err.Error()+"]")
|
||||||
|
s.finishSession(session, execID, "error")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// killSession terminates a session and removes it.
|
stderr, err := cmd.StderrPipe()
|
||||||
func (sm *taskSessionManager) killSession(taskID, sessionType string) bool {
|
if err != nil {
|
||||||
key := sessionKey(taskID, sessionType)
|
s.sendToSession(session, "[greška: "+err.Error()+"]")
|
||||||
|
s.finishSession(session, execID, "error")
|
||||||
sm.mu.Lock()
|
return
|
||||||
sess, exists := sm.sessions[key]
|
|
||||||
if exists {
|
|
||||||
delete(sm.sessions, key)
|
|
||||||
}
|
|
||||||
sm.mu.Unlock()
|
|
||||||
|
|
||||||
if !exists {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Session[%s]: killed", key)
|
session.mu.Lock()
|
||||||
sess.PTY.Close()
|
session.cmd = cmd
|
||||||
return true
|
session.mu.Unlock()
|
||||||
|
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
s.sendToSession(session, "[greška pri pokretanju: "+err.Error()+"]")
|
||||||
|
s.finishSession(session, execID, "error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read stdout and stderr concurrently
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
s.streamReader(session, stdout)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
s.streamReader(session, stderr)
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
err = cmd.Wait()
|
||||||
|
status := "done"
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(*exec.ExitError); ok {
|
||||||
|
status = "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.finishSession(session, execID, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// streamReader reads from a reader line by line and sends to session.
|
||||||
|
func (s *Server) streamReader(session *sessionState, reader io.Reader) {
|
||||||
|
scanner := bufio.NewScanner(reader)
|
||||||
|
scanner.Buffer(make([]byte, 64*1024), 256*1024)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
s.sendToSession(session, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendToSession sends a line to all listeners and stores in output buffer.
|
||||||
|
func (s *Server) sendToSession(session *sessionState, line string) {
|
||||||
|
session.mu.Lock()
|
||||||
|
defer session.mu.Unlock()
|
||||||
|
|
||||||
|
session.output = append(session.output, line)
|
||||||
|
|
||||||
|
for ch := range session.listeners {
|
||||||
|
select {
|
||||||
|
case ch <- line:
|
||||||
|
default:
|
||||||
|
// Skip if channel is full
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// finishSession marks a session as idle and notifies listeners.
|
||||||
|
func (s *Server) finishSession(session *sessionState, execID, status string) {
|
||||||
|
session.mu.Lock()
|
||||||
|
defer session.mu.Unlock()
|
||||||
|
|
||||||
|
session.status = "idle"
|
||||||
|
session.cmd = nil
|
||||||
|
|
||||||
|
// Update history entry status
|
||||||
|
for i := len(session.history) - 1; i >= 0; i-- {
|
||||||
|
if session.history[i].ExecID == execID {
|
||||||
|
session.history[i].Status = status
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify listeners that stream is done
|
||||||
|
for ch := range session.listeners {
|
||||||
|
select {
|
||||||
|
case ch <- "[DONE]":
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleConsoleStream serves an SSE stream for a command execution.
|
||||||
|
func (s *Server) handleConsoleStream(c *gin.Context) {
|
||||||
|
execID := c.Param("id")
|
||||||
|
|
||||||
|
// Find which session has this exec ID
|
||||||
|
var session *sessionState
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
sess := s.console.getSession(i)
|
||||||
|
sess.mu.Lock()
|
||||||
|
if sess.execID == execID {
|
||||||
|
session = sess
|
||||||
|
sess.mu.Unlock()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sess.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
if session == nil {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{"error": "sesija nije pronađena"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set SSE headers
|
||||||
|
c.Header("Content-Type", "text/event-stream")
|
||||||
|
c.Header("Cache-Control", "no-cache")
|
||||||
|
c.Header("Connection", "keep-alive")
|
||||||
|
|
||||||
|
// Create listener channel
|
||||||
|
ch := make(chan string, 100)
|
||||||
|
|
||||||
|
session.mu.Lock()
|
||||||
|
// Send buffered output first
|
||||||
|
for _, line := range session.output {
|
||||||
|
fmt.Fprintf(c.Writer, "data: %s\n\n", line)
|
||||||
|
}
|
||||||
|
c.Writer.Flush()
|
||||||
|
|
||||||
|
// If already done, send done event and return
|
||||||
|
if session.status == "idle" && session.execID == execID {
|
||||||
|
session.mu.Unlock()
|
||||||
|
fmt.Fprintf(c.Writer, "event: done\ndata: finished\n\n")
|
||||||
|
c.Writer.Flush()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.listeners[ch] = true
|
||||||
|
session.mu.Unlock()
|
||||||
|
|
||||||
|
// Clean up on disconnect
|
||||||
|
defer func() {
|
||||||
|
session.mu.Lock()
|
||||||
|
delete(session.listeners, ch)
|
||||||
|
session.mu.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
notify := c.Request.Context().Done()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-notify:
|
||||||
|
return
|
||||||
|
case line := <-ch:
|
||||||
|
if line == "[DONE]" {
|
||||||
|
fmt.Fprintf(c.Writer, "event: done\ndata: finished\n\n")
|
||||||
|
c.Writer.Flush()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(c.Writer, "data: %s\n\n", line)
|
||||||
|
c.Writer.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleConsoleKill kills the running process in a session.
|
||||||
|
func (s *Server) handleConsoleKill(c *gin.Context) {
|
||||||
|
sessionNum, err := strconv.Atoi(c.Param("session"))
|
||||||
|
if err != nil || sessionNum < 1 || sessionNum > 2 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "nevalidna sesija"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session := s.console.getSession(sessionNum - 1)
|
||||||
|
|
||||||
|
session.mu.Lock()
|
||||||
|
defer session.mu.Unlock()
|
||||||
|
|
||||||
|
if session.status != "running" || session.cmd == nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"status": "idle", "message": "sesija nije aktivna"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if session.cmd.Process != nil {
|
||||||
|
session.cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update history
|
||||||
|
for i := len(session.history) - 1; i >= 0; i-- {
|
||||||
|
if session.history[i].ExecID == session.execID {
|
||||||
|
session.history[i].Status = "killed"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
session.status = "idle"
|
||||||
|
session.cmd = nil
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"status": "killed"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleConsoleSessions returns the status of both sessions.
|
||||||
|
func (s *Server) handleConsoleSessions(c *gin.Context) {
|
||||||
|
statuses := make([]sessionStatus, 2)
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
sess := s.console.getSession(i)
|
||||||
|
sess.mu.Lock()
|
||||||
|
statuses[i] = sessionStatus{
|
||||||
|
Session: i + 1,
|
||||||
|
Status: sess.status,
|
||||||
|
TaskID: sess.taskID,
|
||||||
|
ExecID: sess.execID,
|
||||||
|
}
|
||||||
|
sess.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, statuses)
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleConsoleHistory returns command history for a session.
|
||||||
|
func (s *Server) handleConsoleHistory(c *gin.Context) {
|
||||||
|
sessionNum, err := strconv.Atoi(c.Param("session"))
|
||||||
|
if err != nil || sessionNum < 1 || sessionNum > 2 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "nevalidna sesija"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session := s.console.getSession(sessionNum - 1)
|
||||||
|
|
||||||
|
session.mu.Lock()
|
||||||
|
history := make([]historyEntry, len(session.history))
|
||||||
|
copy(history, session.history)
|
||||||
|
session.mu.Unlock()
|
||||||
|
|
||||||
|
data, _ := json.Marshal(history)
|
||||||
|
c.Header("Content-Type", "application/json")
|
||||||
|
c.String(http.StatusOK, string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// timeNow returns the current time formatted as HH:MM:SS.
|
||||||
|
func timeNow() string {
|
||||||
|
return time.Now().Format("15:04:05")
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleConsolePage serves the console HTML page.
|
// handleConsolePage serves the console HTML page.
|
||||||
@ -170,106 +406,3 @@ func (s *Server) handleConsolePage(c *gin.Context) {
|
|||||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||||
c.String(http.StatusOK, renderConsolePage())
|
c.String(http.StatusOK, renderConsolePage())
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleConsoleSessions returns all active task sessions as JSON.
|
|
||||||
func (s *Server) handleConsoleSessions(c *gin.Context) {
|
|
||||||
sessions := s.console.listSessions()
|
|
||||||
c.JSON(http.StatusOK, sessions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleConsoleKill kills a task session.
|
|
||||||
func (s *Server) handleConsoleKill(c *gin.Context) {
|
|
||||||
taskID := c.Param("taskID")
|
|
||||||
sessionType := c.DefaultQuery("type", "work")
|
|
||||||
|
|
||||||
if s.console.killSession(taskID, sessionType) {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"status": "killed", "task": taskID})
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "sesija nije pronađena"})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildWorkPrompt builds the prompt for a work session.
|
|
||||||
func buildWorkPrompt(taskID string, taskContent []byte) string {
|
|
||||||
return fmt.Sprintf(`Radiš na tasku %s. Evo sadržaj taska:
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
PRAVILA:
|
|
||||||
1. Pročitaj agents/coder/CLAUDE.md za pravila kodiranja
|
|
||||||
2. Kod piši u code/ folderu
|
|
||||||
3. Svi testovi moraju proći: go test ./... -count=1
|
|
||||||
4. Build mora proći: go build ./...
|
|
||||||
5. go vet ./... mora proći
|
|
||||||
6. Commituj sa porukom: %s: Opis na srpskom
|
|
||||||
7. Napiši izveštaj u TASKS/reports/%s-report.md
|
|
||||||
8. Premesti task fajl: mv TASKS/active/%s.md TASKS/review/%s.md
|
|
||||||
9. Kada sve završiš, reci "GOTOVO"`, taskID, string(taskContent), taskID, taskID, taskID, taskID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// buildReviewPrompt builds the prompt for a review session.
|
|
||||||
func buildReviewPrompt(taskID string, taskContent, reportContent []byte) string {
|
|
||||||
prompt := fmt.Sprintf(`Pregledaj task %s. Evo sadržaj taska:
|
|
||||||
|
|
||||||
%s
|
|
||||||
`, taskID, string(taskContent))
|
|
||||||
|
|
||||||
if len(reportContent) > 0 {
|
|
||||||
prompt += fmt.Sprintf(`
|
|
||||||
Izveštaj agenta:
|
|
||||||
|
|
||||||
%s
|
|
||||||
`, string(reportContent))
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt += fmt.Sprintf(`
|
|
||||||
KORACI PREGLEDA:
|
|
||||||
1. Pročitaj agents/checker/CLAUDE.md za pravila
|
|
||||||
2. Proveri da li je kod napisan prema zadatku
|
|
||||||
3. Pokreni testove: go test ./... -count=1
|
|
||||||
4. Pokreni build: go build ./...
|
|
||||||
5. Pokreni vet: go vet ./...
|
|
||||||
6. Ako je SVE u redu:
|
|
||||||
- Premesti task: mv TASKS/review/%s.md TASKS/done/%s.md
|
|
||||||
- Reci "ODOBRENO"
|
|
||||||
7. Ako NIJE u redu:
|
|
||||||
- Zapiši šta treba popraviti u task fajl
|
|
||||||
- Premesti task: mv TASKS/review/%s.md TASKS/active/%s.md
|
|
||||||
- Reci "VRAĆENO NA DORADU"`, taskID, taskID, taskID, taskID)
|
|
||||||
|
|
||||||
return prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleReviewTask launches a review claude session for a task.
|
|
||||||
func (s *Server) handleReviewTask(c *gin.Context) {
|
|
||||||
id := c.Param("id")
|
|
||||||
|
|
||||||
// Read task content
|
|
||||||
taskPath := filepath.Join(s.Config.TasksDir, "review", id+".md")
|
|
||||||
taskContent, err := os.ReadFile(taskPath)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "task nije pronađen u review/"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read report if exists
|
|
||||||
reportPath := filepath.Join(s.Config.TasksDir, "reports", id+"-report.md")
|
|
||||||
reportContent, _ := os.ReadFile(reportPath)
|
|
||||||
|
|
||||||
// Build review prompt
|
|
||||||
prompt := buildReviewPrompt(id, taskContent, reportContent)
|
|
||||||
|
|
||||||
// Start review session
|
|
||||||
_, err = s.console.startSession(id, "review", s.projectRoot(), prompt)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"status": "started", "task": id, "type": "review"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// timeNow returns the current time formatted as HH:MM:SS.
|
|
||||||
func timeNow() string {
|
|
||||||
return time.Now().Format("15:04:05")
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,312 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestConsolePage(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "KAOS") {
|
|
||||||
t.Error("expected 'KAOS' in console page")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Konzola") {
|
|
||||||
t.Error("expected 'Konzola' in console page")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsoleSessions_Empty(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console/sessions", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sessions []taskSessionResponse
|
|
||||||
if err := json.Unmarshal(w.Body.Bytes(), &sessions); err != nil {
|
|
||||||
t.Fatalf("invalid JSON: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(sessions) != 0 {
|
|
||||||
t.Fatalf("expected 0 sessions, got %d", len(sessions))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsoleKill_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/console/kill/T99", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSessionKey(t *testing.T) {
|
|
||||||
if got := sessionKey("T01", "work"); got != "T01" {
|
|
||||||
t.Errorf("expected T01, got %s", got)
|
|
||||||
}
|
|
||||||
if got := sessionKey("T01", "review"); got != "T01-review" {
|
|
||||||
t.Errorf("expected T01-review, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskSessionManager_ListEmpty(t *testing.T) {
|
|
||||||
sm := newTaskSessionManager()
|
|
||||||
sessions := sm.listSessions()
|
|
||||||
if len(sessions) != 0 {
|
|
||||||
t.Errorf("expected 0 sessions, got %d", len(sessions))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskSessionManager_KillNotFound(t *testing.T) {
|
|
||||||
sm := newTaskSessionManager()
|
|
||||||
if sm.killSession("T99", "work") {
|
|
||||||
t.Error("expected false for non-existent session")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskSessionManager_GetNotFound(t *testing.T) {
|
|
||||||
sm := newTaskSessionManager()
|
|
||||||
if sm.getSessionByKey("T99") != nil {
|
|
||||||
t.Error("expected nil for non-existent session")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildWorkPrompt(t *testing.T) {
|
|
||||||
prompt := buildWorkPrompt("T08", []byte("# T08: Test task\n\nOpis."))
|
|
||||||
|
|
||||||
if !containsStr(prompt, "T08") {
|
|
||||||
t.Error("expected task ID in prompt")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "Test task") {
|
|
||||||
t.Error("expected task content in prompt")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "agents/coder/CLAUDE.md") {
|
|
||||||
t.Error("expected coder CLAUDE.md reference")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "go test") {
|
|
||||||
t.Error("expected test instruction")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "report") {
|
|
||||||
t.Error("expected report instruction")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildReviewPrompt(t *testing.T) {
|
|
||||||
prompt := buildReviewPrompt("T08", []byte("# T08: Test\n"), []byte("# Report\nSve ok."))
|
|
||||||
|
|
||||||
if !containsStr(prompt, "T08") {
|
|
||||||
t.Error("expected task ID in review prompt")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "Sve ok") {
|
|
||||||
t.Error("expected report content in review prompt")
|
|
||||||
}
|
|
||||||
if !containsStr(prompt, "agents/checker/CLAUDE.md") {
|
|
||||||
t.Error("expected checker CLAUDE.md reference")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildReviewPrompt_NoReport(t *testing.T) {
|
|
||||||
prompt := buildReviewPrompt("T08", []byte("# T08: Test\n"), nil)
|
|
||||||
|
|
||||||
if !containsStr(prompt, "T08") {
|
|
||||||
t.Error("expected task ID")
|
|
||||||
}
|
|
||||||
if containsStr(prompt, "Izveštaj agenta") {
|
|
||||||
t.Error("should not include report section when no report")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReviewTask_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T99/review", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasKillButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "killSession") {
|
|
||||||
t.Error("expected killSession function in console page")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_HasProveriButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Put T08 in review
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "review", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T08", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Proveri") {
|
|
||||||
t.Error("expected 'Proveri' button for review task")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "/review") {
|
|
||||||
t.Error("expected /review endpoint in Proveri button")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_ToolbarAbovePanels(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// Toolbar should appear before console-panels in the HTML
|
|
||||||
toolbarIdx := strings.Index(body, "console-toolbar")
|
|
||||||
panelsIdx := strings.Index(body, "console-panels")
|
|
||||||
|
|
||||||
if toolbarIdx == -1 {
|
|
||||||
t.Fatal("expected console-toolbar in console page")
|
|
||||||
}
|
|
||||||
if panelsIdx == -1 {
|
|
||||||
t.Fatal("expected console-panels in console page")
|
|
||||||
}
|
|
||||||
if toolbarIdx > panelsIdx {
|
|
||||||
t.Error("expected toolbar before panels in console HTML")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasDynamicSessions(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "refreshSessions") {
|
|
||||||
t.Error("expected refreshSessions function in console page")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "/console/sessions") {
|
|
||||||
t.Error("expected /console/sessions API call")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasXtermJS(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "xterm.min.js") {
|
|
||||||
t.Error("expected xterm.min.js CDN link in console page")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "addon-fit") {
|
|
||||||
t.Error("expected addon-fit CDN link in console page")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "xterm.css") {
|
|
||||||
t.Error("expected xterm.css CDN link in console page")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasWebSocket(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "console/ws/") {
|
|
||||||
t.Error("expected WebSocket URL console/ws/ in console page")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "new WebSocket") {
|
|
||||||
t.Error("expected WebSocket constructor in console page")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasEmptyState(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "empty-state") {
|
|
||||||
t.Error("expected empty-state element")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Pusti") {
|
|
||||||
t.Error("expected 'Pusti' instruction in empty state")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "console-terminal") {
|
|
||||||
t.Error("expected console-terminal class in JS code")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasBinaryMessageSupport(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "arraybuffer") {
|
|
||||||
t.Error("expected arraybuffer binary type for WebSocket")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Uint8Array") {
|
|
||||||
t.Error("expected Uint8Array handling for binary messages")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConsolePage_HasResizeHandler(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/console", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "fitAddon.fit()") {
|
|
||||||
t.Error("expected fitAddon.fit() for resize handling")
|
|
||||||
}
|
|
||||||
if !containsStr(body, `'resize'`) {
|
|
||||||
t.Error("expected resize message type in WebSocket handler")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,317 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDashboardHTML(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "KAOS Dashboard") {
|
|
||||||
t.Error("expected 'KAOS Dashboard' in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "T01") {
|
|
||||||
t.Error("expected T01 in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "T08") {
|
|
||||||
t.Error("expected T08 in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "BACKLOG") {
|
|
||||||
t.Error("expected BACKLOG column in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "DONE") {
|
|
||||||
t.Error("expected DONE column in HTML")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHTMLMoveTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Should return updated dashboard HTML
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "KAOS Dashboard") {
|
|
||||||
t.Error("expected dashboard HTML after move")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_HasAllColumns(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
for _, col := range []string{"BACKLOG", "READY", "ACTIVE", "REVIEW", "DONE"} {
|
|
||||||
if !containsStr(body, col) {
|
|
||||||
t.Errorf("expected %s column in dashboard", col)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_HasHTMXAttributes(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "hx-get") {
|
|
||||||
t.Error("expected hx-get attributes in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "hx-target") {
|
|
||||||
t.Error("expected hx-target attributes in HTML")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_TasksInCorrectColumns(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// T01 should be in done column, T08 in backlog
|
|
||||||
if !containsStr(body, `id="col-done"`) {
|
|
||||||
t.Error("expected col-done in HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, `id="col-backlog"`) {
|
|
||||||
t.Error("expected col-backlog in HTML")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsMoveAllowed(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
from, to string
|
|
||||||
allowed bool
|
|
||||||
}{
|
|
||||||
{"backlog", "ready", true},
|
|
||||||
{"ready", "backlog", true},
|
|
||||||
{"review", "done", true},
|
|
||||||
{"review", "ready", true},
|
|
||||||
{"done", "review", true},
|
|
||||||
{"ready", "active", false},
|
|
||||||
{"active", "review", false},
|
|
||||||
{"backlog", "done", false},
|
|
||||||
{"backlog", "active", false},
|
|
||||||
{"done", "backlog", false},
|
|
||||||
{"ready", "ready", false},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
got := isMoveAllowed(tt.from, tt.to)
|
|
||||||
if got != tt.allowed {
|
|
||||||
t.Errorf("isMoveAllowed(%s, %s) = %v, want %v", tt.from, tt.to, got, tt.allowed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNoCacheHeaders(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Dynamic route should have no-cache headers
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
cc := w.Header().Get("Cache-Control")
|
|
||||||
if !containsStr(cc, "no-store") {
|
|
||||||
t.Errorf("expected Cache-Control no-store on dashboard, got %q", cc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// API route should also have no-cache headers
|
|
||||||
req2 := httptest.NewRequest(http.MethodGet, "/api/tasks", nil)
|
|
||||||
w2 := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w2, req2)
|
|
||||||
|
|
||||||
cc2 := w2.Header().Get("Cache-Control")
|
|
||||||
if !containsStr(cc2, "no-store") {
|
|
||||||
t.Errorf("expected Cache-Control no-store on API, got %q", cc2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardReflectsDiskChanges(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Initial state: T08 in backlog
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/tasks", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
var tasks1 []taskResponse
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &tasks1)
|
|
||||||
|
|
||||||
found := false
|
|
||||||
for _, task := range tasks1 {
|
|
||||||
if task.ID == "T08" && task.Status == "backlog" {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Fatal("expected T08 in backlog initially")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move file on disk (simulating external change)
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Second request should reflect the change without server restart
|
|
||||||
req2 := httptest.NewRequest(http.MethodGet, "/api/tasks", nil)
|
|
||||||
w2 := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w2, req2)
|
|
||||||
|
|
||||||
var tasks2 []taskResponse
|
|
||||||
json.Unmarshal(w2.Body.Bytes(), &tasks2)
|
|
||||||
|
|
||||||
found = false
|
|
||||||
for _, task := range tasks2 {
|
|
||||||
if task.ID == "T08" && task.Status == "ready" {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
t.Fatal("expected T08 in ready after disk move — server did not read fresh state")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_HasSortableScript(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "sortable.min.js") {
|
|
||||||
t.Error("expected sortable.min.js script tag")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "initSortable") {
|
|
||||||
t.Error("expected initSortable function")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_HasDataFolderAttributes(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, `data-folder="backlog"`) {
|
|
||||||
t.Error("expected data-folder attribute on column-tasks")
|
|
||||||
}
|
|
||||||
if !containsStr(body, `data-folder="ready"`) {
|
|
||||||
t.Error("expected data-folder=ready attribute")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_HasMoveButtons(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T08 is in backlog, should have "Odobri" button
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T08", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Odobri") {
|
|
||||||
t.Error("expected 'Odobri' button for backlog task")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_HasRunButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Move T08 to ready to test run button
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Pusti") {
|
|
||||||
t.Error("expected 'Pusti' button for ready task")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "btn-run") {
|
|
||||||
t.Error("expected btn-run class")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_BlockedButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T08 in backlog with dep T07 not in done → blocked
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Blokiran") {
|
|
||||||
t.Error("expected 'Blokiran' for backlog task with unmet deps")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "btn-blocked") {
|
|
||||||
t.Error("expected btn-blocked class")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboardHTML_DoneReportButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// T01 is in done → should have "Izvestaj" button
|
|
||||||
if !containsStr(body, "btn-report") {
|
|
||||||
t.Error("expected btn-report for done task")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboard_HasPrijavaNav(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, `href="/submit"`) {
|
|
||||||
t.Error("expected Prijava nav link in dashboard")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,201 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDocsList(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "CLAUDE.md") {
|
|
||||||
t.Error("expected CLAUDE.md in docs list")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "README.md") {
|
|
||||||
t.Error("expected README.md in docs list")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "agents/coder/CLAUDE.md") {
|
|
||||||
t.Error("expected agents/coder/CLAUDE.md in docs list")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_CLAUDE(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/CLAUDE.md", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Glavni fajl") {
|
|
||||||
t.Error("expected rendered markdown content")
|
|
||||||
}
|
|
||||||
// Should have table rendered as HTML
|
|
||||||
if !containsStr(body, "<table>") || !containsStr(body, "<th>") {
|
|
||||||
t.Error("expected HTML table from markdown")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_NestedFile(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/agents/coder/CLAUDE.md", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Coder Agent") {
|
|
||||||
t.Error("expected nested file content")
|
|
||||||
}
|
|
||||||
// Breadcrumbs
|
|
||||||
if !containsStr(body, "agents") {
|
|
||||||
t.Error("expected breadcrumb for agents")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_PathTraversal(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/../../etc/passwd", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusForbidden {
|
|
||||||
t.Fatalf("expected 403 for path traversal, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_NonMarkdown(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/main.go", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusForbidden {
|
|
||||||
t.Fatalf("expected 403 for non-.md file, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/nonexistent.md", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_HasBreadcrumbs(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/agents/coder/CLAUDE.md", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Dokumenti") {
|
|
||||||
t.Error("expected 'Dokumenti' in breadcrumbs")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "coder") {
|
|
||||||
t.Error("expected 'coder' in breadcrumbs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_HasSidebarLayout(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/CLAUDE.md", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "docs-layout") {
|
|
||||||
t.Error("expected docs-layout class for grid layout")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "docs-sidebar") {
|
|
||||||
t.Error("expected docs-sidebar class")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "docs-main") {
|
|
||||||
t.Error("expected docs-main class")
|
|
||||||
}
|
|
||||||
// Sidebar should list files
|
|
||||||
if !containsStr(body, "README.md") {
|
|
||||||
t.Error("expected file list in sidebar")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsView_HTMXReturnsFragment(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs/CLAUDE.md", nil)
|
|
||||||
req.Header.Set("HX-Request", "true")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// Should NOT have full page HTML
|
|
||||||
if containsStr(body, "<!DOCTYPE html>") {
|
|
||||||
t.Error("HTMX request should return fragment, not full page")
|
|
||||||
}
|
|
||||||
// Should have breadcrumbs and content
|
|
||||||
if !containsStr(body, "Dokumenti") {
|
|
||||||
t.Error("expected breadcrumbs in fragment")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Glavni fajl") {
|
|
||||||
t.Error("expected rendered content in fragment")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsList_HasSidebarLayout(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "docs-layout") {
|
|
||||||
t.Error("expected docs-layout class on docs list page")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRewriteLinksSimple(t *testing.T) {
|
|
||||||
input := `<a href="README.md">link</a> and <a href="https://example.com">ext</a>`
|
|
||||||
result := rewriteLinksSimple(input, ".")
|
|
||||||
if !containsStr(result, `/docs/README.md`) {
|
|
||||||
t.Errorf("expected rewritten link, got: %s", result)
|
|
||||||
}
|
|
||||||
if !containsStr(result, `https://example.com`) {
|
|
||||||
t.Error("external link should not be rewritten")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRewriteLinksSimple_NestedDir(t *testing.T) {
|
|
||||||
input := `<a href="CLAUDE.md">link</a>`
|
|
||||||
result := rewriteLinksSimple(input, "agents/coder")
|
|
||||||
if !containsStr(result, `/docs/agents/coder/CLAUDE.md`) {
|
|
||||||
t.Errorf("expected nested rewritten link, got: %s", result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
const maxLogLines = 20
|
|
||||||
|
|
||||||
// handleLogsTail returns the last 20 lines of the server log file as plain text.
|
|
||||||
func (s *Server) handleLogsTail(c *gin.Context) {
|
|
||||||
if s.Config.LogFile == "" {
|
|
||||||
c.String(http.StatusOK, "KAOS_LOG_FILE nije podešen. Podesi env varijablu za prikaz logova.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := os.ReadFile(s.Config.LogFile)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
c.String(http.StatusOK, "Log fajl ne postoji: "+s.Config.LogFile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.String(http.StatusInternalServerError, "Greška pri čitanju loga: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := tailLines(string(data), maxLogLines)
|
|
||||||
c.String(http.StatusOK, strings.Join(lines, "\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// tailLines returns the last n non-empty lines from text.
|
|
||||||
func tailLines(text string, n int) []string {
|
|
||||||
allLines := strings.Split(strings.TrimRight(text, "\n"), "\n")
|
|
||||||
if len(allLines) <= n {
|
|
||||||
return allLines
|
|
||||||
}
|
|
||||||
return allLines[len(allLines)-n:]
|
|
||||||
}
|
|
||||||
@ -1,161 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHandleLogsTail_OK(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
logFile := filepath.Join(t.TempDir(), "test.log")
|
|
||||||
lines := make([]string, 25)
|
|
||||||
for i := range lines {
|
|
||||||
lines[i] = "linija " + string(rune('A'+i))
|
|
||||||
}
|
|
||||||
os.WriteFile(logFile, []byte(strings.Join(lines, "\n")+"\n"), 0644)
|
|
||||||
srv.Config.LogFile = logFile
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/logs/tail", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
got := strings.Split(strings.TrimRight(w.Body.String(), "\n"), "\n")
|
|
||||||
if len(got) != maxLogLines {
|
|
||||||
t.Fatalf("expected %d lines, got %d", maxLogLines, len(got))
|
|
||||||
}
|
|
||||||
// First returned line should be line 6 (index 5) since we have 25 lines, tail 20
|
|
||||||
if got[0] != "linija F" {
|
|
||||||
t.Errorf("expected first line 'linija F', got %q", got[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleLogsTail_LessThan20Lines(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
logFile := filepath.Join(t.TempDir(), "test.log")
|
|
||||||
os.WriteFile(logFile, []byte("prva\ndruga\ntreca\n"), 0644)
|
|
||||||
srv.Config.LogFile = logFile
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/logs/tail", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
got := strings.Split(strings.TrimRight(w.Body.String(), "\n"), "\n")
|
|
||||||
if len(got) != 3 {
|
|
||||||
t.Fatalf("expected 3 lines, got %d", len(got))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleLogsTail_NoLogFile(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
// LogFile is empty string by default in test config
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/logs/tail", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(w.Body.String(), "KAOS_LOG_FILE") {
|
|
||||||
t.Error("expected message about KAOS_LOG_FILE not being set")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleLogsTail_FileNotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
srv.Config.LogFile = "/tmp/nonexistent-kaos-test-log-12345.log"
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/logs/tail", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(w.Body.String(), "ne postoji") {
|
|
||||||
t.Error("expected message about file not existing")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHandleLogsTail_Max20Lines(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
logFile := filepath.Join(t.TempDir(), "test.log")
|
|
||||||
lines := make([]string, 100)
|
|
||||||
for i := range lines {
|
|
||||||
lines[i] = "log line"
|
|
||||||
}
|
|
||||||
os.WriteFile(logFile, []byte(strings.Join(lines, "\n")+"\n"), 0644)
|
|
||||||
srv.Config.LogFile = logFile
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/api/logs/tail", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
got := strings.Split(strings.TrimRight(w.Body.String(), "\n"), "\n")
|
|
||||||
if len(got) > maxLogLines {
|
|
||||||
t.Errorf("expected max %d lines, got %d", maxLogLines, len(got))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTailLines(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
text string
|
|
||||||
n int
|
|
||||||
expected int
|
|
||||||
}{
|
|
||||||
{"empty", "", 20, 1},
|
|
||||||
{"less than n", "a\nb\nc", 20, 3},
|
|
||||||
{"exact n", "a\nb\nc", 3, 3},
|
|
||||||
{"more than n", "a\nb\nc\nd\ne", 3, 3},
|
|
||||||
{"trailing newline", "a\nb\nc\n", 2, 2},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
got := tailLines(tt.text, tt.n)
|
|
||||||
if len(got) != tt.expected {
|
|
||||||
t.Errorf("tailLines(%q, %d) = %d lines, want %d", tt.text, tt.n, len(got), tt.expected)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTailLines_Content(t *testing.T) {
|
|
||||||
text := "first\nsecond\nthird\nfourth\nfifth\n"
|
|
||||||
got := tailLines(text, 3)
|
|
||||||
|
|
||||||
if len(got) != 3 {
|
|
||||||
t.Fatalf("expected 3 lines, got %d", len(got))
|
|
||||||
}
|
|
||||||
if got[0] != "third" {
|
|
||||||
t.Errorf("expected 'third', got %q", got[0])
|
|
||||||
}
|
|
||||||
if got[1] != "fourth" {
|
|
||||||
t.Errorf("expected 'fourth', got %q", got[1])
|
|
||||||
}
|
|
||||||
if got[2] != "fifth" {
|
|
||||||
t.Errorf("expected 'fifth', got %q", got[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/creack/pty"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ansiRegex matches ANSI escape sequences for stripping terminal formatting.
|
|
||||||
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]|\x1b\].*?\x07|\x1b\[[\?0-9;]*[a-zA-Z]`)
|
|
||||||
|
|
||||||
// stripAnsi removes ANSI escape codes from a string.
|
|
||||||
func stripAnsi(s string) string {
|
|
||||||
return ansiRegex.ReplaceAllString(s, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// startPTY starts a command in a pseudo-terminal and returns the PTY master fd.
|
|
||||||
// The caller is responsible for closing the returned *os.File.
|
|
||||||
func startPTY(cmd *exec.Cmd) (*os.File, error) {
|
|
||||||
ptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 40, Cols: 120})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ptmx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// readPTY reads from a PTY master and calls sendLine for each chunk of text.
|
|
||||||
// It splits on newlines so each SSE event is one line.
|
|
||||||
func readPTY(ptmx io.Reader, sendLine func(string)) {
|
|
||||||
buf := make([]byte, 4096)
|
|
||||||
var partial string
|
|
||||||
for {
|
|
||||||
n, err := ptmx.Read(buf)
|
|
||||||
if n > 0 {
|
|
||||||
text := partial + stripAnsi(string(buf[:n]))
|
|
||||||
partial = ""
|
|
||||||
|
|
||||||
// Split into lines, keep partial for next read
|
|
||||||
for {
|
|
||||||
idx := -1
|
|
||||||
for i, b := range []byte(text) {
|
|
||||||
if b == '\n' || b == '\r' {
|
|
||||||
idx = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if idx < 0 {
|
|
||||||
partial = text
|
|
||||||
break
|
|
||||||
}
|
|
||||||
line := text[:idx]
|
|
||||||
// Skip empty lines from \r\n sequences
|
|
||||||
if line != "" {
|
|
||||||
sendLine(line)
|
|
||||||
}
|
|
||||||
// Skip past the newline character(s)
|
|
||||||
text = text[idx+1:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
// Send remaining partial text
|
|
||||||
if partial != "" {
|
|
||||||
sendLine(partial)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,253 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/creack/pty"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
outputBufferSize = 1024 * 1024 // 1MB ring buffer for replay
|
|
||||||
)
|
|
||||||
|
|
||||||
// RingBuffer is a fixed-size circular buffer for terminal output.
|
|
||||||
type RingBuffer struct {
|
|
||||||
data []byte
|
|
||||||
size int
|
|
||||||
pos int
|
|
||||||
full bool
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRingBuffer creates a new ring buffer with the given size.
|
|
||||||
func NewRingBuffer(size int) *RingBuffer {
|
|
||||||
return &RingBuffer{data: make([]byte, size), size: size}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write appends data to the ring buffer.
|
|
||||||
func (rb *RingBuffer) Write(p []byte) {
|
|
||||||
rb.mu.Lock()
|
|
||||||
defer rb.mu.Unlock()
|
|
||||||
for _, b := range p {
|
|
||||||
rb.data[rb.pos] = b
|
|
||||||
rb.pos++
|
|
||||||
if rb.pos >= rb.size {
|
|
||||||
rb.pos = 0
|
|
||||||
rb.full = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes returns the buffer contents in correct order.
|
|
||||||
func (rb *RingBuffer) Bytes() []byte {
|
|
||||||
rb.mu.Lock()
|
|
||||||
defer rb.mu.Unlock()
|
|
||||||
if !rb.full {
|
|
||||||
result := make([]byte, rb.pos)
|
|
||||||
copy(result, rb.data[:rb.pos])
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
result := make([]byte, rb.size)
|
|
||||||
n := copy(result, rb.data[rb.pos:])
|
|
||||||
copy(result[n:], rb.data[:rb.pos])
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset clears the buffer.
|
|
||||||
func (rb *RingBuffer) Reset() {
|
|
||||||
rb.mu.Lock()
|
|
||||||
defer rb.mu.Unlock()
|
|
||||||
rb.pos = 0
|
|
||||||
rb.full = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// consolePTYSession manages a single claude CLI running in a pseudo-terminal.
|
|
||||||
type consolePTYSession struct {
|
|
||||||
ID string
|
|
||||||
Ptmx *os.File
|
|
||||||
Cmd *exec.Cmd
|
|
||||||
buffer *RingBuffer
|
|
||||||
subscribers map[string]chan []byte
|
|
||||||
mu sync.Mutex
|
|
||||||
done chan struct{}
|
|
||||||
lastActive time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// spawnTaskPTY starts an interactive claude CLI with auto-permissions in a PTY.
|
|
||||||
// Used for task work and review sessions. The prompt is sent after startup.
|
|
||||||
func spawnTaskPTY(projectDir string) (*consolePTYSession, error) {
|
|
||||||
cmd := exec.Command("claude", "--permission-mode", "dontAsk")
|
|
||||||
cmd.Dir = projectDir
|
|
||||||
cmd.Env = cleanEnvForPTY()
|
|
||||||
|
|
||||||
ptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 50, Cols: 180})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("start pty: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sess := &consolePTYSession{
|
|
||||||
ID: fmt.Sprintf("task-%d", time.Now().UnixNano()),
|
|
||||||
Ptmx: ptmx,
|
|
||||||
Cmd: cmd,
|
|
||||||
buffer: NewRingBuffer(outputBufferSize),
|
|
||||||
subscribers: make(map[string]chan []byte),
|
|
||||||
done: make(chan struct{}),
|
|
||||||
lastActive: time.Now(),
|
|
||||||
}
|
|
||||||
|
|
||||||
go sess.readLoop()
|
|
||||||
go sess.waitExit()
|
|
||||||
|
|
||||||
return sess, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// spawnShellPTY starts an interactive claude CLI in a PTY for the console.
|
|
||||||
func spawnShellPTY(projectDir string) (*consolePTYSession, error) {
|
|
||||||
cmd := exec.Command("claude")
|
|
||||||
cmd.Dir = projectDir
|
|
||||||
cmd.Env = cleanEnvForPTY()
|
|
||||||
|
|
||||||
ptmx, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 24, Cols: 120})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("start pty: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sess := &consolePTYSession{
|
|
||||||
ID: fmt.Sprintf("shell-%d", time.Now().UnixNano()),
|
|
||||||
Ptmx: ptmx,
|
|
||||||
Cmd: cmd,
|
|
||||||
buffer: NewRingBuffer(outputBufferSize),
|
|
||||||
subscribers: make(map[string]chan []byte),
|
|
||||||
done: make(chan struct{}),
|
|
||||||
lastActive: time.Now(),
|
|
||||||
}
|
|
||||||
|
|
||||||
go sess.readLoop()
|
|
||||||
go sess.waitExit()
|
|
||||||
|
|
||||||
return sess, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// readLoop reads PTY output, writes to ring buffer, and forwards to subscribers.
|
|
||||||
func (s *consolePTYSession) readLoop() {
|
|
||||||
buf := make([]byte, 4096)
|
|
||||||
totalBytes := 0
|
|
||||||
for {
|
|
||||||
n, err := s.Ptmx.Read(buf)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("PTY[%s]: readLoop ended (read %d bytes total, err: %v)", s.ID, totalBytes, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
totalBytes += n
|
|
||||||
data := make([]byte, n)
|
|
||||||
copy(data, buf[:n])
|
|
||||||
|
|
||||||
s.buffer.Write(data)
|
|
||||||
|
|
||||||
s.mu.Lock()
|
|
||||||
s.lastActive = time.Now()
|
|
||||||
subs := len(s.subscribers)
|
|
||||||
for _, ch := range s.subscribers {
|
|
||||||
select {
|
|
||||||
case ch <- data:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.mu.Unlock()
|
|
||||||
|
|
||||||
if totalBytes == n {
|
|
||||||
// First chunk — log it
|
|
||||||
log.Printf("PTY[%s]: first output (%d bytes, %d subscribers)", s.ID, n, subs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// waitExit waits for the CLI process to exit and signals done.
|
|
||||||
func (s *consolePTYSession) waitExit() {
|
|
||||||
if s.Cmd.Process != nil {
|
|
||||||
s.Cmd.Wait()
|
|
||||||
}
|
|
||||||
close(s.done)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe adds a subscriber for PTY output.
|
|
||||||
func (s *consolePTYSession) Subscribe(id string) chan []byte {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
ch := make(chan []byte, 256)
|
|
||||||
s.subscribers[id] = ch
|
|
||||||
return ch
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unsubscribe removes a subscriber.
|
|
||||||
func (s *consolePTYSession) Unsubscribe(id string) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
if ch, ok := s.subscribers[id]; ok {
|
|
||||||
close(ch)
|
|
||||||
delete(s.subscribers, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resize changes the PTY terminal size.
|
|
||||||
func (s *consolePTYSession) Resize(rows, cols uint16) error {
|
|
||||||
return pty.Setsize(s.Ptmx, &pty.Winsize{Rows: rows, Cols: cols})
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteInput sends keyboard input to the PTY.
|
|
||||||
func (s *consolePTYSession) WriteInput(data []byte) (int, error) {
|
|
||||||
s.mu.Lock()
|
|
||||||
s.lastActive = time.Now()
|
|
||||||
s.mu.Unlock()
|
|
||||||
return s.Ptmx.Write(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetBuffer returns the ring buffer contents for replay.
|
|
||||||
func (s *consolePTYSession) GetBuffer() []byte {
|
|
||||||
return s.buffer.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done returns a channel that closes when the process exits.
|
|
||||||
func (s *consolePTYSession) Done() <-chan struct{} {
|
|
||||||
return s.done
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close terminates the PTY session.
|
|
||||||
func (s *consolePTYSession) Close() {
|
|
||||||
s.mu.Lock()
|
|
||||||
for id, ch := range s.subscribers {
|
|
||||||
close(ch)
|
|
||||||
delete(s.subscribers, id)
|
|
||||||
}
|
|
||||||
s.mu.Unlock()
|
|
||||||
|
|
||||||
s.Ptmx.Close()
|
|
||||||
if s.Cmd.Process != nil {
|
|
||||||
s.Cmd.Process.Kill()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanEnvForPTY returns environment with proper terminal settings.
|
|
||||||
func cleanEnvForPTY() []string {
|
|
||||||
var env []string
|
|
||||||
for _, e := range os.Environ() {
|
|
||||||
if strings.HasPrefix(e, "CLAUDECODE=") ||
|
|
||||||
strings.HasPrefix(e, "CLAUDE_CODE_ENTRYPOINT=") ||
|
|
||||||
strings.HasPrefix(e, "TERM=") ||
|
|
||||||
strings.HasPrefix(e, "COLORTERM=") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
env = append(env, e)
|
|
||||||
}
|
|
||||||
env = append(env, "TERM=xterm-256color", "COLORTERM=truecolor")
|
|
||||||
return env
|
|
||||||
}
|
|
||||||
@ -33,7 +33,7 @@ type dashboardData struct {
|
|||||||
// taskDetailData holds data for the task detail panel.
|
// taskDetailData holds data for the task detail panel.
|
||||||
type taskDetailData struct {
|
type taskDetailData struct {
|
||||||
Task supervisor.Task
|
Task supervisor.Task
|
||||||
Content template.HTML
|
Content string
|
||||||
HasReport bool
|
HasReport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,23 +203,11 @@ func renderSearchResults(data searchResultsData) string {
|
|||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// renderReportModal generates HTML fragment for the report overlay modal.
|
|
||||||
func renderReportModal(taskID, title, content string) string {
|
|
||||||
rendered := renderMarkdown([]byte(content), taskID+"-report.md")
|
|
||||||
return `<div class="detail-inner">
|
|
||||||
<span class="detail-close" onclick="closeDetail()">✕</span>
|
|
||||||
<h2>` + template.HTMLEscapeString(title) + `</h2>
|
|
||||||
<div class="detail-content docs-content">` + rendered + `</div>
|
|
||||||
</div>`
|
|
||||||
}
|
|
||||||
|
|
||||||
// renderTaskDetail generates HTML fragment for task detail panel.
|
// renderTaskDetail generates HTML fragment for task detail panel.
|
||||||
// Content is rendered from markdown to HTML using goldmark.
|
|
||||||
func renderTaskDetail(t supervisor.Task, content string, hasReport bool) string {
|
func renderTaskDetail(t supervisor.Task, content string, hasReport bool) string {
|
||||||
rendered := renderMarkdown([]byte(content), t.ID+".md")
|
|
||||||
data := taskDetailData{
|
data := taskDetailData{
|
||||||
Task: t,
|
Task: t,
|
||||||
Content: template.HTML(rendered),
|
Content: content,
|
||||||
HasReport: hasReport,
|
HasReport: hasReport,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,117 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSearch_FindsTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=Prvi", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "T01") {
|
|
||||||
t.Error("expected T01 in search results for 'Prvi'")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_FindsTaskByID(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=T08", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "T08") {
|
|
||||||
t.Error("expected T08 in search results")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_FindsDocument(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=checker", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "checker/CLAUDE.md") {
|
|
||||||
t.Error("expected checker CLAUDE.md in search results")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_FindsReport(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=prolaze", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "T01-report.md") {
|
|
||||||
t.Error("expected T01 report in search results")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_EmptyQuery(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
if w.Body.Len() != 0 {
|
|
||||||
t.Errorf("expected empty response for empty query, got %d bytes", w.Body.Len())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_NoResults(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=xyznepostoji", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Nema rezultata") {
|
|
||||||
t.Error("expected 'Nema rezultata' message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_CaseInsensitive(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=CODER", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "coder") {
|
|
||||||
t.Error("expected case-insensitive match for 'CODER'")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearch_HasSnippet(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/search?q=kodiranja", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "kodiranja") {
|
|
||||||
t.Error("expected snippet with 'kodiranja' text")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,15 +2,12 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
@ -23,7 +20,7 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
Router *gin.Engine
|
Router *gin.Engine
|
||||||
console *taskSessionManager
|
console *consoleManager
|
||||||
events *eventBroker
|
events *eventBroker
|
||||||
chatMu sync.RWMutex
|
chatMu sync.RWMutex
|
||||||
chats map[string]*chatState
|
chats map[string]*chatState
|
||||||
@ -74,7 +71,7 @@ func New(cfg *config.Config) *Server {
|
|||||||
s := &Server{
|
s := &Server{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
Router: router,
|
Router: router,
|
||||||
console: newTaskSessionManager(),
|
console: newConsoleManager(),
|
||||||
events: newEventBroker(cfg.TasksDir),
|
events: newEventBroker(cfg.TasksDir),
|
||||||
chats: make(map[string]*chatState),
|
chats: make(map[string]*chatState),
|
||||||
}
|
}
|
||||||
@ -107,7 +104,6 @@ func (s *Server) setupRoutes() {
|
|||||||
s.Router.GET("/task/:id", s.handleTaskDetail)
|
s.Router.GET("/task/:id", s.handleTaskDetail)
|
||||||
s.Router.POST("/task/:id/move", s.handleMoveTask)
|
s.Router.POST("/task/:id/move", s.handleMoveTask)
|
||||||
s.Router.POST("/task/:id/run", s.handleRunTask)
|
s.Router.POST("/task/:id/run", s.handleRunTask)
|
||||||
s.Router.POST("/task/:id/review", s.handleReviewTask)
|
|
||||||
s.Router.GET("/report/:id", s.handleReport)
|
s.Router.GET("/report/:id", s.handleReport)
|
||||||
|
|
||||||
// SSE events
|
// SSE events
|
||||||
@ -118,12 +114,11 @@ func (s *Server) setupRoutes() {
|
|||||||
|
|
||||||
// Console routes
|
// Console routes
|
||||||
s.Router.GET("/console", s.handleConsolePage)
|
s.Router.GET("/console", s.handleConsolePage)
|
||||||
|
s.Router.POST("/console/exec", s.handleConsoleExec)
|
||||||
|
s.Router.GET("/console/stream/:id", s.handleConsoleStream)
|
||||||
|
s.Router.POST("/console/kill/:session", s.handleConsoleKill)
|
||||||
s.Router.GET("/console/sessions", s.handleConsoleSessions)
|
s.Router.GET("/console/sessions", s.handleConsoleSessions)
|
||||||
s.Router.POST("/console/kill/:taskID", s.handleConsoleKill)
|
s.Router.GET("/console/history/:session", s.handleConsoleHistory)
|
||||||
s.Router.GET("/console/ws/:key", s.handleConsoleWS)
|
|
||||||
|
|
||||||
// Logs route
|
|
||||||
s.Router.GET("/api/logs/tail", s.handleLogsTail)
|
|
||||||
|
|
||||||
// Docs routes
|
// Docs routes
|
||||||
s.Router.GET("/docs", s.handleDocsList)
|
s.Router.GET("/docs", s.handleDocsList)
|
||||||
@ -212,12 +207,6 @@ func (s *Server) apiMoveTask(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append timestamp to moved file
|
|
||||||
newPath := filepath.Join(s.Config.TasksDir, toFolder, id+".md")
|
|
||||||
if label, ok := moveEventLabel[toFolder]; ok {
|
|
||||||
appendTimestamp(newPath, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"status": "ok", "moved": id, "to": toFolder})
|
c.JSON(http.StatusOK, gin.H{"status": "ok", "moved": id, "to": toFolder})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,12 +277,6 @@ func (s *Server) handleMoveTask(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append timestamp to moved file
|
|
||||||
newPath := filepath.Join(s.Config.TasksDir, toFolder, id+".md")
|
|
||||||
if label, ok := moveEventLabel[toFolder]; ok {
|
|
||||||
appendTimestamp(newPath, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-scan and return updated dashboard
|
// Re-scan and return updated dashboard
|
||||||
s.handleDashboard(c)
|
s.handleDashboard(c)
|
||||||
}
|
}
|
||||||
@ -343,72 +326,69 @@ func (s *Server) handleRunTask(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
readyPath := filepath.Join(s.Config.TasksDir, "ready", id+".md")
|
|
||||||
appendTimestamp(readyPath, "Odobren (→ready)")
|
|
||||||
task.Status = "ready"
|
task.Status = "ready"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move ready → active
|
// Find free session
|
||||||
if err := supervisor.MoveTask(s.Config.TasksDir, id, "ready", "active"); err != nil {
|
sessionIdx := -1
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
for i := 0; i < 2; i++ {
|
||||||
|
sess := s.console.getSession(i)
|
||||||
|
sess.mu.Lock()
|
||||||
|
if sess.status == "idle" {
|
||||||
|
sessionIdx = i
|
||||||
|
sess.mu.Unlock()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sess.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
if sessionIdx == -1 {
|
||||||
|
c.JSON(http.StatusConflict, gin.H{"error": "obe sesije su zauzete"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append "Pokrenut" timestamp
|
// Build the prompt
|
||||||
taskPath := filepath.Join(s.Config.TasksDir, "active", id+".md")
|
prompt := "Pročitaj CLAUDE.md u root-u projekta. Tvoj task: TASKS/ready/" + id + ".md — Pročitaj task fajl i uradi šta piše. Prati pravila iz CLAUDE.md."
|
||||||
appendTimestamp(taskPath, "Pokrenut (→active)")
|
|
||||||
|
|
||||||
// Read task content and spawn a claude work session
|
// Start in the session
|
||||||
taskContent, _ := os.ReadFile(taskPath)
|
session := s.console.getSession(sessionIdx)
|
||||||
prompt := buildWorkPrompt(id, taskContent)
|
execID := s.console.nextExecID()
|
||||||
|
|
||||||
_, err = s.console.startSession(id, "work", s.projectRoot(), prompt)
|
session.mu.Lock()
|
||||||
if err != nil {
|
session.status = "running"
|
||||||
log.Printf("Warning: session start failed for %s: %v", id, err)
|
session.execID = execID
|
||||||
}
|
session.taskID = id
|
||||||
|
session.output = nil
|
||||||
|
session.history = append(session.history, historyEntry{
|
||||||
|
Command: "pusti " + id,
|
||||||
|
ExecID: execID,
|
||||||
|
Timestamp: timeNow(),
|
||||||
|
Status: "running",
|
||||||
|
})
|
||||||
|
session.mu.Unlock()
|
||||||
|
|
||||||
|
go s.runCommand(session, prompt, execID)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"status": "started",
|
"status": "started",
|
||||||
"task": id,
|
"session": sessionIdx + 1,
|
||||||
"session": id,
|
"exec_id": execID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleReport serves a task report in the overlay modal.
|
// handleReport serves a task report file.
|
||||||
// If a report file exists, render it. Otherwise, show the task content.
|
|
||||||
func (s *Server) handleReport(c *gin.Context) {
|
func (s *Server) handleReport(c *gin.Context) {
|
||||||
id := strings.ToUpper(c.Param("id"))
|
id := strings.ToUpper(c.Param("id"))
|
||||||
reportPath := filepath.Join(s.Config.TasksDir, "reports", id+"-report.md")
|
reportPath := filepath.Join(s.Config.TasksDir, "reports", id+"-report.md")
|
||||||
|
|
||||||
var content []byte
|
content, err := os.ReadFile(reportPath)
|
||||||
var title string
|
|
||||||
|
|
||||||
if data, err := os.ReadFile(reportPath); err == nil {
|
|
||||||
content = data
|
|
||||||
title = id + " — Izveštaj"
|
|
||||||
} else {
|
|
||||||
// No report — show the task file itself
|
|
||||||
tasks, err := supervisor.ScanTasks(s.Config.TasksDir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, "Greška: %v", err)
|
c.String(http.StatusNotFound, "Izveštaj za %s nije pronađen", id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
task := supervisor.FindTask(tasks, id)
|
|
||||||
if task == nil {
|
|
||||||
c.String(http.StatusNotFound, "Task %s nije pronađen", id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data, err := os.ReadFile(task.FilePath)
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusNotFound, "Fajl nije pronađen")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content = data
|
|
||||||
title = id + " — " + task.Title
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
c.Header("Content-Type", "text/plain; charset=utf-8")
|
||||||
c.String(http.StatusOK, renderReportModal(id, title, string(content)))
|
c.String(http.StatusOK, string(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the HTTP server.
|
// Run starts the HTTP server.
|
||||||
@ -459,40 +439,6 @@ func isMoveAllowed(from, to string) bool {
|
|||||||
return targets[to]
|
return targets[to]
|
||||||
}
|
}
|
||||||
|
|
||||||
// moveEventLabel returns a human-readable label for a folder transition.
|
|
||||||
var moveEventLabel = map[string]string{
|
|
||||||
"ready": "Odobren (→ready)",
|
|
||||||
"active": "Pokrenut (→active)",
|
|
||||||
"review": "Završen (→review)",
|
|
||||||
"done": "Odobren (→done)",
|
|
||||||
}
|
|
||||||
|
|
||||||
// appendTimestamp adds a timestamp row to the task file's "## Vremena" table.
|
|
||||||
// If the table doesn't exist yet, it creates it.
|
|
||||||
func appendTimestamp(filePath, event string) error {
|
|
||||||
content, err := os.ReadFile(filePath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now().Format("2006-01-02 15:04")
|
|
||||||
row := fmt.Sprintf("| %s | %s |", event, now)
|
|
||||||
|
|
||||||
text := string(content)
|
|
||||||
marker := "## Vremena"
|
|
||||||
|
|
||||||
if strings.Contains(text, marker) {
|
|
||||||
// Table exists — append row before the last line break at end
|
|
||||||
text = strings.TrimRight(text, "\n") + "\n" + row + "\n"
|
|
||||||
} else {
|
|
||||||
// Create the table section at the end
|
|
||||||
section := fmt.Sprintf("\n%s\n\n| Događaj | Vreme |\n|---------|-------|\n%s\n", marker, row)
|
|
||||||
text = strings.TrimRight(text, "\n") + "\n" + section
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(filePath, []byte(text), 0644)
|
|
||||||
}
|
|
||||||
|
|
||||||
func toTaskResponse(t supervisor.Task) taskResponse {
|
func toTaskResponse(t supervisor.Task) taskResponse {
|
||||||
deps := t.DependsOn
|
deps := t.DependsOn
|
||||||
if deps == nil {
|
if deps == nil {
|
||||||
|
|||||||
1660
code/internal/server/server_test.go
Normal file
1660
code/internal/server/server_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,121 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/dal/kaos/internal/supervisor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSSE_EventsEndpoint(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/events", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
|
|
||||||
// Use a context with cancel to stop the SSE handler
|
|
||||||
ctx, cancel := req.Context(), func() {}
|
|
||||||
_ = ctx
|
|
||||||
_ = cancel
|
|
||||||
|
|
||||||
// Just check the handler starts without error and sets correct headers
|
|
||||||
go func() {
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
}()
|
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
|
|
||||||
if ct := w.Header().Get("Content-Type"); ct != "text/event-stream" {
|
|
||||||
t.Errorf("expected Content-Type text/event-stream, got %s", ct)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHashTaskState(t *testing.T) {
|
|
||||||
tasks1 := []supervisor.Task{
|
|
||||||
{ID: "T01", Status: "done"},
|
|
||||||
{ID: "T02", Status: "backlog"},
|
|
||||||
}
|
|
||||||
tasks2 := []supervisor.Task{
|
|
||||||
{ID: "T01", Status: "done"},
|
|
||||||
{ID: "T02", Status: "ready"}, // changed
|
|
||||||
}
|
|
||||||
tasks3 := []supervisor.Task{
|
|
||||||
{ID: "T02", Status: "backlog"},
|
|
||||||
{ID: "T01", Status: "done"}, // same as tasks1 but different order
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 := hashTaskState(tasks1)
|
|
||||||
h2 := hashTaskState(tasks2)
|
|
||||||
h3 := hashTaskState(tasks3)
|
|
||||||
|
|
||||||
if h1 == h2 {
|
|
||||||
t.Error("hash should differ when task status changes")
|
|
||||||
}
|
|
||||||
if h1 != h3 {
|
|
||||||
t.Error("hash should be same regardless of task order")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSSE_BroadcastOnChange(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Subscribe a client
|
|
||||||
ch := srv.events.subscribe()
|
|
||||||
defer srv.events.unsubscribe(ch)
|
|
||||||
|
|
||||||
// Trigger a check — first call sets the baseline hash and broadcasts
|
|
||||||
srv.events.checkAndBroadcast(func() string { return "board-html" })
|
|
||||||
|
|
||||||
// Drain initial broadcast
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
case <-time.After(100 * time.Millisecond):
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move a task to change state
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Trigger another check — state changed, should broadcast
|
|
||||||
srv.events.checkAndBroadcast(func() string { return "updated-board" })
|
|
||||||
|
|
||||||
select {
|
|
||||||
case data := <-ch:
|
|
||||||
if data != "updated-board" {
|
|
||||||
t.Errorf("expected 'updated-board', got %s", data)
|
|
||||||
}
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Error("expected broadcast after state change, got nothing")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSSE_NoBroadcastWithoutChange(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
ch := srv.events.subscribe()
|
|
||||||
defer srv.events.unsubscribe(ch)
|
|
||||||
|
|
||||||
// Two checks without changes — second should not broadcast
|
|
||||||
srv.events.checkAndBroadcast(func() string { return "board" })
|
|
||||||
|
|
||||||
// Drain the first broadcast (initial hash set)
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
case <-time.After(100 * time.Millisecond):
|
|
||||||
}
|
|
||||||
|
|
||||||
srv.events.checkAndBroadcast(func() string { return "board" })
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
t.Error("should not broadcast when state hasn't changed")
|
|
||||||
case <-time.After(100 * time.Millisecond):
|
|
||||||
// Good — no broadcast
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +1,20 @@
|
|||||||
// Package server — submit.go handles task submission in two modes:
|
// Package server — submit.go handles task submission in two modes:
|
||||||
// client (simple form) and operator (chat via claude CLI).
|
// client (simple form) and operator (chat with Claude API).
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -20,36 +22,22 @@ import (
|
|||||||
"github.com/dal/kaos/internal/supervisor"
|
"github.com/dal/kaos/internal/supervisor"
|
||||||
)
|
)
|
||||||
|
|
||||||
// chatCounter generates unique chat IDs.
|
// chatState manages an operator chat session.
|
||||||
var chatCounter atomic.Int64
|
|
||||||
|
|
||||||
func nextChatID() string {
|
|
||||||
chatCounter.Add(1)
|
|
||||||
return fmt.Sprintf("chat-%d-%d", time.Now().Unix(), chatCounter.Load())
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanEnv returns the current environment with CLAUDECODE removed,
|
|
||||||
// so child claude processes don't inherit the parent's session.
|
|
||||||
func cleanEnv() []string {
|
|
||||||
var env []string
|
|
||||||
for _, e := range os.Environ() {
|
|
||||||
if !strings.HasPrefix(e, "CLAUDECODE=") {
|
|
||||||
env = append(env, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return env
|
|
||||||
}
|
|
||||||
|
|
||||||
// chatState manages an operator chat session backed by a claude CLI process.
|
|
||||||
type chatState struct {
|
type chatState struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
id string
|
id string
|
||||||
cmd *exec.Cmd
|
messages []chatMessage
|
||||||
output []string
|
response string
|
||||||
done bool
|
done bool
|
||||||
listeners map[chan string]bool
|
listeners map[chan string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// chatMessage represents a single message in the chat.
|
||||||
|
type chatMessage struct {
|
||||||
|
Role string `json:"role"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
// nextTaskNumber finds the highest T{XX} number across all tasks and returns the next one.
|
// nextTaskNumber finds the highest T{XX} number across all tasks and returns the next one.
|
||||||
func nextTaskNumber(tasksDir string) (string, error) {
|
func nextTaskNumber(tasksDir string) (string, error) {
|
||||||
tasks, err := supervisor.ScanTasks(tasksDir)
|
tasks, err := supervisor.ScanTasks(tasksDir)
|
||||||
@ -131,10 +119,11 @@ func (s *Server) handleSimpleSubmit(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"status": "ok", "task_id": taskID})
|
c.JSON(http.StatusOK, gin.H{"status": "ok", "task_id": taskID})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleChatSubmit spawns a claude CLI process with the operator's message.
|
// handleChatSubmit handles an operator chat message by calling the Claude API.
|
||||||
func (s *Server) handleChatSubmit(c *gin.Context) {
|
func (s *Server) handleChatSubmit(c *gin.Context) {
|
||||||
var req struct {
|
var req struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
ChatID string `json:"chat_id,omitempty"`
|
||||||
}
|
}
|
||||||
if err := c.BindJSON(&req); err != nil {
|
if err := c.BindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "neispravan zahtev"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "neispravan zahtev"})
|
||||||
@ -146,92 +135,55 @@ func (s *Server) handleChatSubmit(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build prompt with context
|
apiKey := os.Getenv("ANTHROPIC_API_KEY")
|
||||||
|
if apiKey == "" {
|
||||||
|
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "ANTHROPIC_API_KEY nije podešen"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get or create chat session
|
||||||
|
chatID := req.ChatID
|
||||||
|
var chat *chatState
|
||||||
|
|
||||||
|
s.chatMu.Lock()
|
||||||
|
if chatID != "" {
|
||||||
|
chat = s.chats[chatID]
|
||||||
|
}
|
||||||
|
if chat == nil {
|
||||||
|
chatID = s.console.nextExecID()
|
||||||
|
chat = &chatState{
|
||||||
|
id: chatID,
|
||||||
|
listeners: make(map[chan string]bool),
|
||||||
|
}
|
||||||
|
s.chats[chatID] = chat
|
||||||
|
}
|
||||||
|
s.chatMu.Unlock()
|
||||||
|
|
||||||
|
// Add user message and reset response state
|
||||||
|
chat.mu.Lock()
|
||||||
|
chat.messages = append(chat.messages, chatMessage{Role: "user", Content: req.Message})
|
||||||
|
chat.done = false
|
||||||
|
chat.response = ""
|
||||||
|
chat.mu.Unlock()
|
||||||
|
|
||||||
|
// Build system prompt with task context
|
||||||
tasks, _ := supervisor.ScanTasks(s.Config.TasksDir)
|
tasks, _ := supervisor.ScanTasks(s.Config.TasksDir)
|
||||||
context := buildTaskContext(tasks)
|
context := buildTaskContext(tasks)
|
||||||
|
|
||||||
projectRoot := filepath.Dir(s.Config.TasksDir)
|
projectRoot := filepath.Dir(s.Config.TasksDir)
|
||||||
claudeMD, _ := os.ReadFile(filepath.Join(projectRoot, "CLAUDE.md"))
|
claudeMD, _ := os.ReadFile(filepath.Join(projectRoot, "CLAUDE.md"))
|
||||||
|
|
||||||
prompt := fmt.Sprintf("Kontekst (CLAUDE.md):\n%s\n\nTrenutni taskovi:\n%s\n\nOperater kaže:\n%s",
|
systemPrompt := string(claudeMD) + "\n\n## Trenutno stanje taskova\n\n" + context +
|
||||||
string(claudeMD), context, req.Message)
|
"\n\n## Tvoja uloga\n\nTi si KAOS mastermind. Operater ti govori šta treba. " +
|
||||||
|
"Predloži task u markdown formatu ili odgovori na pitanje. " +
|
||||||
|
"Ako operater kaže 'kreiraj task', generiši task markdown u standardnom KAOS formatu."
|
||||||
|
|
||||||
// Create chat session
|
go s.callClaudeAPI(chat, apiKey, systemPrompt)
|
||||||
chatID := nextChatID()
|
|
||||||
chat := &chatState{
|
|
||||||
id: chatID,
|
|
||||||
listeners: make(map[chan string]bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
s.chatMu.Lock()
|
|
||||||
s.chats[chatID] = chat
|
|
||||||
s.chatMu.Unlock()
|
|
||||||
|
|
||||||
// Spawn claude CLI process in background
|
|
||||||
go s.runChatCommand(chat, prompt)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"chat_id": chatID})
|
c.JSON(http.StatusOK, gin.H{"chat_id": chatID})
|
||||||
}
|
}
|
||||||
|
|
||||||
// runChatCommand executes claude CLI in a PTY and streams output to chat listeners.
|
// handleChatStream streams the Claude API response via SSE.
|
||||||
func (s *Server) runChatCommand(chat *chatState, prompt string) {
|
|
||||||
cmd := exec.Command("claude", "--permission-mode", "dontAsk", "-p", prompt)
|
|
||||||
cmd.Dir = s.projectRoot()
|
|
||||||
cmd.Env = cleanEnv()
|
|
||||||
|
|
||||||
ptmx, err := startPTY(cmd)
|
|
||||||
if err != nil {
|
|
||||||
sendChatLine(chat, "[greška pri pokretanju: "+err.Error()+"]")
|
|
||||||
finishChat(chat)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer ptmx.Close()
|
|
||||||
|
|
||||||
chat.mu.Lock()
|
|
||||||
chat.cmd = cmd
|
|
||||||
chat.mu.Unlock()
|
|
||||||
|
|
||||||
// Read PTY output and send to chat
|
|
||||||
readPTY(ptmx, func(line string) {
|
|
||||||
sendChatLine(chat, line)
|
|
||||||
})
|
|
||||||
|
|
||||||
cmd.Wait()
|
|
||||||
finishChat(chat)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendChatLine sends a line to all chat listeners and stores in output buffer.
|
|
||||||
func sendChatLine(chat *chatState, line string) {
|
|
||||||
chat.mu.Lock()
|
|
||||||
defer chat.mu.Unlock()
|
|
||||||
|
|
||||||
chat.output = append(chat.output, line)
|
|
||||||
|
|
||||||
for ch := range chat.listeners {
|
|
||||||
select {
|
|
||||||
case ch <- line:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// finishChat marks a chat as done and signals all listeners.
|
|
||||||
func finishChat(chat *chatState) {
|
|
||||||
chat.mu.Lock()
|
|
||||||
defer chat.mu.Unlock()
|
|
||||||
|
|
||||||
chat.done = true
|
|
||||||
chat.cmd = nil
|
|
||||||
|
|
||||||
for ch := range chat.listeners {
|
|
||||||
select {
|
|
||||||
case ch <- "[DONE]":
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleChatStream serves an SSE stream for a chat session.
|
|
||||||
func (s *Server) handleChatStream(c *gin.Context) {
|
func (s *Server) handleChatStream(c *gin.Context) {
|
||||||
chatID := c.Param("id")
|
chatID := c.Param("id")
|
||||||
|
|
||||||
@ -248,48 +200,168 @@ func (s *Server) handleChatStream(c *gin.Context) {
|
|||||||
c.Header("Cache-Control", "no-cache")
|
c.Header("Cache-Control", "no-cache")
|
||||||
c.Header("Connection", "keep-alive")
|
c.Header("Connection", "keep-alive")
|
||||||
|
|
||||||
ch := make(chan string, 100)
|
ch := make(chan string, 64)
|
||||||
|
|
||||||
chat.mu.Lock()
|
chat.mu.Lock()
|
||||||
// Replay buffered output
|
chat.listeners[ch] = true
|
||||||
for _, line := range chat.output {
|
// Replay existing response if available
|
||||||
fmt.Fprintf(c.Writer, "data: %s\n\n", line)
|
if chat.response != "" {
|
||||||
|
ch <- chat.response
|
||||||
}
|
}
|
||||||
c.Writer.Flush()
|
isDone := chat.done
|
||||||
|
|
||||||
// If already done, send done event and return
|
|
||||||
if chat.done {
|
|
||||||
chat.mu.Unlock()
|
chat.mu.Unlock()
|
||||||
fmt.Fprintf(c.Writer, "event: done\ndata: finished\n\n")
|
|
||||||
c.Writer.Flush()
|
if isDone {
|
||||||
|
c.SSEvent("done", "complete")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chat.listeners[ch] = true
|
c.Stream(func(w io.Writer) bool {
|
||||||
chat.mu.Unlock()
|
select {
|
||||||
|
case data, ok := <-ch:
|
||||||
defer func() {
|
if !ok {
|
||||||
|
c.SSEvent("done", "complete")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if data == "__DONE__" {
|
||||||
|
c.SSEvent("done", "complete")
|
||||||
chat.mu.Lock()
|
chat.mu.Lock()
|
||||||
delete(chat.listeners, ch)
|
delete(chat.listeners, ch)
|
||||||
chat.mu.Unlock()
|
chat.mu.Unlock()
|
||||||
}()
|
return false
|
||||||
|
}
|
||||||
|
c.SSEvent("message", data)
|
||||||
|
return true
|
||||||
|
case <-c.Request.Context().Done():
|
||||||
|
chat.mu.Lock()
|
||||||
|
delete(chat.listeners, ch)
|
||||||
|
chat.mu.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
notify := c.Request.Context().Done()
|
// callClaudeAPI calls the Anthropic Messages API with streaming and relays text to listeners.
|
||||||
|
func (s *Server) callClaudeAPI(chat *chatState, apiKey, systemPrompt string) {
|
||||||
|
chat.mu.Lock()
|
||||||
|
messages := make([]chatMessage, len(chat.messages))
|
||||||
|
copy(messages, chat.messages)
|
||||||
|
chat.mu.Unlock()
|
||||||
|
|
||||||
for {
|
// Build API request body
|
||||||
|
apiMessages := make([]map[string]string, len(messages))
|
||||||
|
for i, m := range messages {
|
||||||
|
apiMessages[i] = map[string]string{"role": m.Role, "content": m.Content}
|
||||||
|
}
|
||||||
|
|
||||||
|
body := map[string]interface{}{
|
||||||
|
"model": "claude-sonnet-4-6",
|
||||||
|
"max_tokens": 4096,
|
||||||
|
"system": systemPrompt,
|
||||||
|
"messages": apiMessages,
|
||||||
|
"stream": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBody, _ := json.Marshal(body)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", "https://api.anthropic.com/v1/messages", bytes.NewReader(jsonBody))
|
||||||
|
if err != nil {
|
||||||
|
broadcastChatError(chat, "HTTP greška: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("x-api-key", apiKey)
|
||||||
|
req.Header.Set("anthropic-version", "2023-06-01")
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
broadcastChatError(chat, "API greška: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
|
broadcastChatError(chat, fmt.Sprintf("API %d: %s", resp.StatusCode, string(respBody)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse SSE stream from Anthropic API
|
||||||
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
|
var fullResponse strings.Builder
|
||||||
|
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
if !strings.HasPrefix(line, "data: ") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
data := strings.TrimPrefix(line, "data: ")
|
||||||
|
if data == "[DONE]" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
var event map[string]interface{}
|
||||||
|
if err := json.Unmarshal([]byte(data), &event); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
eventType, _ := event["type"].(string)
|
||||||
|
if eventType == "content_block_delta" {
|
||||||
|
delta, ok := event["delta"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
text, _ := delta["text"].(string)
|
||||||
|
if text != "" {
|
||||||
|
fullResponse.WriteString(text)
|
||||||
|
broadcastChatText(chat, fullResponse.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finalize: save response and signal done
|
||||||
|
chat.mu.Lock()
|
||||||
|
chat.response = fullResponse.String()
|
||||||
|
chat.messages = append(chat.messages, chatMessage{Role: "assistant", Content: chat.response})
|
||||||
|
chat.done = true
|
||||||
|
for ch := range chat.listeners {
|
||||||
select {
|
select {
|
||||||
case <-notify:
|
case ch <- "__DONE__":
|
||||||
return
|
default:
|
||||||
case line := <-ch:
|
|
||||||
if line == "[DONE]" {
|
|
||||||
fmt.Fprintf(c.Writer, "event: done\ndata: finished\n\n")
|
|
||||||
c.Writer.Flush()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Fprintf(c.Writer, "data: %s\n\n", line)
|
|
||||||
c.Writer.Flush()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
chat.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// broadcastChatText sends the current accumulated text to all listeners.
|
||||||
|
func broadcastChatText(chat *chatState, text string) {
|
||||||
|
chat.mu.Lock()
|
||||||
|
chat.response = text
|
||||||
|
for ch := range chat.listeners {
|
||||||
|
select {
|
||||||
|
case ch <- text:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chat.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// broadcastChatError sends an error message and signals done.
|
||||||
|
func broadcastChatError(chat *chatState, errMsg string) {
|
||||||
|
chat.mu.Lock()
|
||||||
|
chat.done = true
|
||||||
|
chat.response = "Greška: " + errMsg
|
||||||
|
for ch := range chat.listeners {
|
||||||
|
select {
|
||||||
|
case ch <- "Greška: " + errMsg:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case ch <- "__DONE__":
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chat.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildTaskContext creates a text summary of current tasks for the system prompt.
|
// buildTaskContext creates a text summary of current tasks for the system prompt.
|
||||||
|
|||||||
@ -1,245 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/dal/kaos/internal/supervisor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestSubmitPage(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/submit", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Klijent") {
|
|
||||||
t.Error("expected 'Klijent' mode button")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Operater") {
|
|
||||||
t.Error("expected 'Operater' mode button")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "mode-client") {
|
|
||||||
t.Error("expected client mode section")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSubmitPage_ClientModeIsDefault(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/submit", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// Operator mode should be hidden by default
|
|
||||||
if !containsStr(body, `id="mode-operator" class="submit-mode" style="display:none"`) {
|
|
||||||
t.Error("expected operator mode to be hidden by default")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSimpleSubmit_CreatesTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
form := strings.NewReader("title=Test+prijava&description=Opis+testa&priority=Visok")
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/simple", form)
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp map[string]interface{}
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
||||||
|
|
||||||
if resp["status"] != "ok" {
|
|
||||||
t.Errorf("expected status ok, got %v", resp["status"])
|
|
||||||
}
|
|
||||||
|
|
||||||
taskID, ok := resp["task_id"].(string)
|
|
||||||
if !ok || taskID == "" {
|
|
||||||
t.Fatal("expected non-empty task_id")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify file was created in backlog
|
|
||||||
path := filepath.Join(srv.Config.TasksDir, "backlog", taskID+".md")
|
|
||||||
content, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("expected task file in backlog: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !containsStr(string(content), "Test prijava") {
|
|
||||||
t.Error("expected title in task file")
|
|
||||||
}
|
|
||||||
if !containsStr(string(content), "Visok") {
|
|
||||||
t.Error("expected priority in task file")
|
|
||||||
}
|
|
||||||
if !containsStr(string(content), "klijent (prijava)") {
|
|
||||||
t.Error("expected 'klijent (prijava)' as creator")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSimpleSubmit_MissingTitle(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
form := strings.NewReader("description=Samo+opis")
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/simple", form)
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("expected 400 for missing title, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSimpleSubmit_AutoNumbering(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Existing tasks: T01 (done), T08 (backlog)
|
|
||||||
// Next should be T09
|
|
||||||
|
|
||||||
form := strings.NewReader("title=Novi+task&priority=Srednji")
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/simple", form)
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
var resp map[string]interface{}
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
||||||
|
|
||||||
taskID, _ := resp["task_id"].(string)
|
|
||||||
if taskID != "T09" {
|
|
||||||
t.Errorf("expected T09 (next after T08), got %s", taskID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSimpleSubmit_DefaultPriority(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
form := strings.NewReader("title=Bez+prioriteta")
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/simple", form)
|
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
var resp map[string]interface{}
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
||||||
|
|
||||||
taskID, _ := resp["task_id"].(string)
|
|
||||||
path := filepath.Join(srv.Config.TasksDir, "backlog", taskID+".md")
|
|
||||||
content, _ := os.ReadFile(path)
|
|
||||||
|
|
||||||
if !containsStr(string(content), "Srednji") {
|
|
||||||
t.Error("expected default priority 'Srednji'")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestChatSubmit_ReturnsChatID(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
body := `{"message":"test poruka"}`
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/chat", strings.NewReader(body))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp map[string]interface{}
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
||||||
if resp["chat_id"] == nil || resp["chat_id"] == "" {
|
|
||||||
t.Error("expected non-empty chat_id in response")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestChatSubmit_EmptyMessage(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
body := `{"message":""}`
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/submit/chat", strings.NewReader(body))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("expected 400 for empty message, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestChatStream_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/submit/chat/stream/nonexistent", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNextTaskNumber(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
tasksDir := filepath.Join(dir, "TASKS")
|
|
||||||
for _, f := range []string{"backlog", "ready", "active", "review", "done"} {
|
|
||||||
os.MkdirAll(filepath.Join(tasksDir, f), 0755)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.WriteFile(filepath.Join(tasksDir, "done", "T01.md"), []byte(testTask1), 0644)
|
|
||||||
os.WriteFile(filepath.Join(tasksDir, "backlog", "T08.md"), []byte(testTask2), 0644)
|
|
||||||
|
|
||||||
num, err := nextTaskNumber(tasksDir)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if num != "T09" {
|
|
||||||
t.Errorf("expected T09, got %s", num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuildTaskContext(t *testing.T) {
|
|
||||||
tasks := []supervisor.Task{
|
|
||||||
{ID: "T01", Title: "Init", Status: "done", Agent: "coder", Model: "Sonnet"},
|
|
||||||
{ID: "T02", Title: "Server", Status: "active", Agent: "coder", Model: "Opus"},
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := buildTaskContext(tasks)
|
|
||||||
if !containsStr(ctx, "T01: Init") {
|
|
||||||
t.Error("expected T01 in context")
|
|
||||||
}
|
|
||||||
if !containsStr(ctx, "T02: Server") {
|
|
||||||
t.Error("expected T02 in context")
|
|
||||||
}
|
|
||||||
if !containsStr(ctx, "DONE") {
|
|
||||||
t.Error("expected DONE section")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSubmitPage_HasPrijavaNav(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/submit", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, `href="/submit"`) {
|
|
||||||
t.Error("expected Prijava nav link")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,272 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/dal/kaos/internal/supervisor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTaskDetailHTML(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "T01") {
|
|
||||||
t.Error("expected T01 in detail HTML")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Prvi task") {
|
|
||||||
t.Error("expected task title in detail HTML")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetailHTML_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T99", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReport_Exists(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Create a report
|
|
||||||
reportsDir := filepath.Join(srv.Config.TasksDir, "reports")
|
|
||||||
os.MkdirAll(reportsDir, 0755)
|
|
||||||
os.WriteFile(filepath.Join(reportsDir, "T01-report.md"), []byte("# T01 Report\nSve ok."), 0644)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/report/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
if !containsStr(w.Body.String(), "T01 Report") {
|
|
||||||
t.Error("expected report content")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReport_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/report/T99", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_Ready(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Move T08 to ready first
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp map[string]interface{}
|
|
||||||
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
||||||
if resp["status"] != "started" {
|
|
||||||
t.Errorf("expected status started, got %v", resp["status"])
|
|
||||||
}
|
|
||||||
if resp["task"] != "T08" {
|
|
||||||
t.Errorf("expected task T08, got %v", resp["task"])
|
|
||||||
}
|
|
||||||
// Verify task moved to active/
|
|
||||||
if _, err := os.Stat(filepath.Join(srv.Config.TasksDir, "active", "T08.md")); err != nil {
|
|
||||||
t.Error("expected T08.md in active/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_BacklogWithDeps(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T08 depends on T07, T01 is in done
|
|
||||||
// T08 depends on T07 which is NOT in done → should fail
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("expected 400 for unmet deps, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_AlreadyDone(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T01 is in done
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T01/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusBadRequest {
|
|
||||||
t.Fatalf("expected 400 for done task, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_NotFound(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T99/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_MovesToActive(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Move T08 to ready
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify task moved to active/
|
|
||||||
if _, err := os.Stat(filepath.Join(srv.Config.TasksDir, "active", "T08.md")); err != nil {
|
|
||||||
t.Error("expected T08.md in active/ after run")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Blocked(t *testing.T) {
|
|
||||||
doneSet := map[string]bool{"T01": true}
|
|
||||||
task := supervisor.Task{ID: "T08", Status: "backlog", DependsOn: []string{"T07"}}
|
|
||||||
if got := resolveTaskAction(task, doneSet); got != "blocked" {
|
|
||||||
t.Errorf("expected blocked, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Review(t *testing.T) {
|
|
||||||
doneSet := map[string]bool{"T07": true}
|
|
||||||
task := supervisor.Task{ID: "T08", Status: "backlog", DependsOn: []string{"T07"}}
|
|
||||||
if got := resolveTaskAction(task, doneSet); got != "review" {
|
|
||||||
t.Errorf("expected review, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Run(t *testing.T) {
|
|
||||||
task := supervisor.Task{ID: "T08", Status: "ready"}
|
|
||||||
if got := resolveTaskAction(task, nil); got != "run" {
|
|
||||||
t.Errorf("expected run, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Running(t *testing.T) {
|
|
||||||
task := supervisor.Task{ID: "T08", Status: "active"}
|
|
||||||
if got := resolveTaskAction(task, nil); got != "running" {
|
|
||||||
t.Errorf("expected running, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Approve(t *testing.T) {
|
|
||||||
task := supervisor.Task{ID: "T08", Status: "review"}
|
|
||||||
if got := resolveTaskAction(task, nil); got != "approve" {
|
|
||||||
t.Errorf("expected approve, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestResolveTaskAction_Done(t *testing.T) {
|
|
||||||
task := supervisor.Task{ID: "T01", Status: "done"}
|
|
||||||
if got := resolveTaskAction(task, nil); got != "done" {
|
|
||||||
t.Errorf("expected done, got %s", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReport_RendersMarkdownInModal(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/report/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "detail-inner") {
|
|
||||||
t.Error("expected detail-inner wrapper for modal")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "docs-content") {
|
|
||||||
t.Error("expected docs-content class for markdown rendering")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "<h1>") {
|
|
||||||
t.Error("expected rendered markdown heading")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "Izveštaj") {
|
|
||||||
t.Error("expected 'Izveštaj' in title")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReport_NoReport_ShowsTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T08 has no report — should show task content
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/report/T08", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "detail-inner") {
|
|
||||||
t.Error("expected detail-inner wrapper")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "HTTP server") {
|
|
||||||
t.Error("expected task title in fallback content")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReport_NotFoundTask(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/report/T99", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusNotFound {
|
|
||||||
t.Fatalf("expected 404, got %d", w.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/dal/kaos/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
const testTask1 = `# T01: Prvi task
|
|
||||||
|
|
||||||
**Agent:** coder
|
|
||||||
**Model:** Sonnet
|
|
||||||
**Zavisi od:** —
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Opis
|
|
||||||
|
|
||||||
Opis prvog taska.
|
|
||||||
|
|
||||||
---
|
|
||||||
`
|
|
||||||
|
|
||||||
const testTask2 = `# T08: HTTP server
|
|
||||||
|
|
||||||
**Agent:** coder
|
|
||||||
**Model:** Sonnet
|
|
||||||
**Zavisi od:** T07
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Opis
|
|
||||||
|
|
||||||
Implementacija HTTP servera.
|
|
||||||
|
|
||||||
---
|
|
||||||
`
|
|
||||||
|
|
||||||
func setupTestServer(t *testing.T) *Server {
|
|
||||||
t.Helper()
|
|
||||||
dir := t.TempDir()
|
|
||||||
|
|
||||||
tasksDir := filepath.Join(dir, "TASKS")
|
|
||||||
for _, folder := range []string{"backlog", "ready", "active", "review", "done", "reports"} {
|
|
||||||
os.MkdirAll(filepath.Join(tasksDir, folder), 0755)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.WriteFile(filepath.Join(tasksDir, "done", "T01.md"), []byte(testTask1), 0644)
|
|
||||||
os.WriteFile(filepath.Join(tasksDir, "backlog", "T08.md"), []byte(testTask2), 0644)
|
|
||||||
|
|
||||||
// Docs: create markdown files in project root
|
|
||||||
os.WriteFile(filepath.Join(dir, "CLAUDE.md"), []byte("# CLAUDE.md\n\nGlavni fajl.\n\n| Kolona | Opis |\n|--------|------|\n| A | B |\n"), 0644)
|
|
||||||
os.WriteFile(filepath.Join(dir, "README.md"), []byte("# README\n\nOpis projekta.\n"), 0644)
|
|
||||||
os.MkdirAll(filepath.Join(dir, "agents", "coder"), 0755)
|
|
||||||
os.WriteFile(filepath.Join(dir, "agents", "coder", "CLAUDE.md"), []byte("# Coder Agent\n\nPravila kodiranja.\n"), 0644)
|
|
||||||
os.MkdirAll(filepath.Join(dir, "agents", "checker"), 0755)
|
|
||||||
os.WriteFile(filepath.Join(dir, "agents", "checker", "CLAUDE.md"), []byte("# Checker Agent\n\nBuild + Test verifikacija.\n"), 0644)
|
|
||||||
os.WriteFile(filepath.Join(tasksDir, "reports", "T01-report.md"), []byte("# T01 Report\n\n10 testova, svi prolaze.\n"), 0644)
|
|
||||||
|
|
||||||
cfg := &config.Config{
|
|
||||||
TasksDir: tasksDir,
|
|
||||||
ProjectPath: dir,
|
|
||||||
Port: "0",
|
|
||||||
}
|
|
||||||
|
|
||||||
return New(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func containsStr(s, substr string) bool {
|
|
||||||
return len(s) >= len(substr) && findStr(s, substr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func findStr(s, substr string) bool {
|
|
||||||
for i := 0; i <= len(s)-len(substr); i++ {
|
|
||||||
if s[i:i+len(substr)] == substr {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@ -1,425 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMoveTask_AddsTimestamp(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the moved file and check for timestamp
|
|
||||||
content, err := os.ReadFile(filepath.Join(srv.Config.TasksDir, "ready", "T08.md"))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to read moved file: %v", err)
|
|
||||||
}
|
|
||||||
text := string(content)
|
|
||||||
if !containsStr(text, "## Vremena") {
|
|
||||||
t.Error("expected '## Vremena' section in task file")
|
|
||||||
}
|
|
||||||
if !containsStr(text, "Odobren (→ready)") {
|
|
||||||
t.Error("expected 'Odobren (→ready)' timestamp")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMoveTask_AppendsMultipleTimestamps(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Move backlog → ready
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/move?to=ready", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
// Move ready → backlog (return)
|
|
||||||
req2 := httptest.NewRequest(http.MethodPost, "/task/T08/move?to=backlog", nil)
|
|
||||||
w2 := httptest.NewRecorder()
|
|
||||||
// Need to re-fetch since task is now in ready/
|
|
||||||
srv.Router.ServeHTTP(w2, req2)
|
|
||||||
|
|
||||||
// Move backlog → ready again
|
|
||||||
req3 := httptest.NewRequest(http.MethodPost, "/task/T08/move?to=ready", nil)
|
|
||||||
w3 := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w3, req3)
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(filepath.Join(srv.Config.TasksDir, "ready", "T08.md"))
|
|
||||||
text := string(content)
|
|
||||||
|
|
||||||
// Should have two "Odobren (→ready)" entries
|
|
||||||
count := strings.Count(text, "Odobren (→ready)")
|
|
||||||
if count != 2 {
|
|
||||||
t.Errorf("expected 2 'Odobren (→ready)' timestamps, got %d", count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppendTimestamp_CreatesTable(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
path := filepath.Join(dir, "test.md")
|
|
||||||
os.WriteFile(path, []byte("# T01: Test\n\nSome content.\n"), 0644)
|
|
||||||
|
|
||||||
err := appendTimestamp(path, "Odobren (→ready)")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(path)
|
|
||||||
text := string(content)
|
|
||||||
if !containsStr(text, "## Vremena") {
|
|
||||||
t.Error("expected Vremena section")
|
|
||||||
}
|
|
||||||
if !containsStr(text, "| Događaj | Vreme |") {
|
|
||||||
t.Error("expected table header")
|
|
||||||
}
|
|
||||||
if !containsStr(text, "Odobren (→ready)") {
|
|
||||||
t.Error("expected timestamp row")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppendTimestamp_AppendsToExisting(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
path := filepath.Join(dir, "test.md")
|
|
||||||
os.WriteFile(path, []byte("# T01: Test\n\n## Vremena\n\n| Događaj | Vreme |\n|---------|-------|\n| Kreiran | 2026-02-20 14:00 |\n"), 0644)
|
|
||||||
|
|
||||||
err := appendTimestamp(path, "Odobren (→ready)")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(path)
|
|
||||||
text := string(content)
|
|
||||||
if !containsStr(text, "Kreiran") {
|
|
||||||
t.Error("expected existing row preserved")
|
|
||||||
}
|
|
||||||
if !containsStr(text, "Odobren (→ready)") {
|
|
||||||
t.Error("expected new timestamp row")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunTask_AddsTimestamp(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Move T08 to ready
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "ready", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/task/T08/run", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Task should now be in active/
|
|
||||||
content, _ := os.ReadFile(filepath.Join(srv.Config.TasksDir, "active", "T08.md"))
|
|
||||||
text := string(content)
|
|
||||||
if !containsStr(text, "Pokrenut") {
|
|
||||||
t.Error("expected 'Pokrenut' timestamp after run")
|
|
||||||
}
|
|
||||||
// Verify it's no longer in ready/
|
|
||||||
if _, err := os.Stat(filepath.Join(srv.Config.TasksDir, "ready", "T08.md")); err == nil {
|
|
||||||
t.Error("task should no longer be in ready/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppendTimestamp_Format(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
path := filepath.Join(dir, "test.md")
|
|
||||||
os.WriteFile(path, []byte("# T01: Test\n"), 0644)
|
|
||||||
|
|
||||||
appendTimestamp(path, "Pokrenut (→active)")
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(path)
|
|
||||||
text := string(content)
|
|
||||||
|
|
||||||
// Verify timestamp format YYYY-MM-DD HH:MM
|
|
||||||
re := regexp.MustCompile(`\| Pokrenut \(→active\) \| \d{4}-\d{2}-\d{2} \d{2}:\d{2} \|`)
|
|
||||||
if !re.MatchString(text) {
|
|
||||||
t.Errorf("expected timestamp format YYYY-MM-DD HH:MM, got:\n%s", text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppendTimestamp_FileNotFound(t *testing.T) {
|
|
||||||
err := appendTimestamp("/nonexistent/path/task.md", "test")
|
|
||||||
if err == nil {
|
|
||||||
t.Error("expected error for nonexistent file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMoveEventLabel_AllFolders(t *testing.T) {
|
|
||||||
expected := map[string]string{
|
|
||||||
"ready": "Odobren (→ready)",
|
|
||||||
"active": "Pokrenut (→active)",
|
|
||||||
"review": "Završen (→review)",
|
|
||||||
"done": "Odobren (→done)",
|
|
||||||
}
|
|
||||||
|
|
||||||
for folder, label := range expected {
|
|
||||||
got, ok := moveEventLabel[folder]
|
|
||||||
if !ok {
|
|
||||||
t.Errorf("missing label for folder %s", folder)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if got != label {
|
|
||||||
t.Errorf("folder %s: expected %q, got %q", folder, label, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDoneTimestamp_ReviewToDone(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Put T08 in review
|
|
||||||
os.Rename(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "backlog", "T08.md"),
|
|
||||||
filepath.Join(srv.Config.TasksDir, "review", "T08.md"),
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/task/T08/move?to=done", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
content, _ := os.ReadFile(filepath.Join(srv.Config.TasksDir, "done", "T08.md"))
|
|
||||||
text := string(content)
|
|
||||||
|
|
||||||
if !containsStr(text, "Odobren (→done)") {
|
|
||||||
t.Error("expected 'Odobren (→done)' timestamp")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_DoneShowsReportButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// T01 is in done and has a report
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "/report/T01") {
|
|
||||||
t.Error("expected report link for done task")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_DoneWithoutReportShowsButton(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Create a done task without a report
|
|
||||||
os.WriteFile(
|
|
||||||
filepath.Join(srv.Config.TasksDir, "done", "T02.md"),
|
|
||||||
[]byte("# T02: Bez reporta\n\n**Agent:** coder\n**Model:** Sonnet\n**Zavisi od:** —\n\n---\n\n## Opis\n\nTest task bez reporta.\n"),
|
|
||||||
0644,
|
|
||||||
)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T02", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "/report/T02") {
|
|
||||||
t.Error("expected report button for done task even without report file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTimestampVisibleInTaskDetail(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
// Add timestamps to T01 (done task)
|
|
||||||
taskPath := filepath.Join(srv.Config.TasksDir, "done", "T01.md")
|
|
||||||
appendTimestamp(taskPath, "Kreiran")
|
|
||||||
appendTimestamp(taskPath, "Pokrenut (→active)")
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", w.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Vremena") {
|
|
||||||
t.Error("expected Vremena section visible in task detail")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStripAnsi(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{"hello", "hello"},
|
|
||||||
{"\x1b[32mgreen\x1b[0m", "green"},
|
|
||||||
{"\x1b[1;31mbold red\x1b[0m", "bold red"},
|
|
||||||
{"\x1b[?25l\x1b[?25h", ""},
|
|
||||||
{"no \x1b[4munderline\x1b[24m here", "no underline here"},
|
|
||||||
{"\x1b]0;title\x07text", "text"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
got := stripAnsi(tt.input)
|
|
||||||
if got != tt.expected {
|
|
||||||
t.Errorf("stripAnsi(%q) = %q, want %q", tt.input, got, tt.expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReadPTY_SplitsLines(t *testing.T) {
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
readPTY(r, func(line string) {
|
|
||||||
lines = append(lines, line)
|
|
||||||
})
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
w.WriteString("line1\nline2\nline3\n")
|
|
||||||
w.Close()
|
|
||||||
<-done
|
|
||||||
|
|
||||||
if len(lines) != 3 {
|
|
||||||
t.Fatalf("expected 3 lines, got %d: %v", len(lines), lines)
|
|
||||||
}
|
|
||||||
if lines[0] != "line1" || lines[1] != "line2" || lines[2] != "line3" {
|
|
||||||
t.Errorf("unexpected lines: %v", lines)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReadPTY_StripsAnsi(t *testing.T) {
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
readPTY(r, func(line string) {
|
|
||||||
lines = append(lines, line)
|
|
||||||
})
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
w.WriteString("\x1b[32mcolored\x1b[0m\n")
|
|
||||||
w.Close()
|
|
||||||
<-done
|
|
||||||
|
|
||||||
if len(lines) != 1 {
|
|
||||||
t.Fatalf("expected 1 line, got %d", len(lines))
|
|
||||||
}
|
|
||||||
if lines[0] != "colored" {
|
|
||||||
t.Errorf("expected 'colored', got %q", lines[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReadPTY_HandlesPartialChunks(t *testing.T) {
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
readPTY(r, func(line string) {
|
|
||||||
lines = append(lines, line)
|
|
||||||
})
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Write partial, then complete
|
|
||||||
w.WriteString("partial")
|
|
||||||
w.Close()
|
|
||||||
<-done
|
|
||||||
|
|
||||||
if len(lines) != 1 {
|
|
||||||
t.Fatalf("expected 1 line for partial, got %d: %v", len(lines), lines)
|
|
||||||
}
|
|
||||||
if lines[0] != "partial" {
|
|
||||||
t.Errorf("expected 'partial', got %q", lines[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReadPTY_HandlesCarriageReturn(t *testing.T) {
|
|
||||||
r, w, _ := os.Pipe()
|
|
||||||
|
|
||||||
var lines []string
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
readPTY(r, func(line string) {
|
|
||||||
lines = append(lines, line)
|
|
||||||
})
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
w.WriteString("line1\r\nline2\r\n")
|
|
||||||
w.Close()
|
|
||||||
<-done
|
|
||||||
|
|
||||||
if len(lines) != 2 {
|
|
||||||
t.Fatalf("expected 2 lines, got %d: %v", len(lines), lines)
|
|
||||||
}
|
|
||||||
if lines[0] != "line1" || lines[1] != "line2" {
|
|
||||||
t.Errorf("unexpected lines: %v", lines)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRingBuffer_WriteAndRead(t *testing.T) {
|
|
||||||
rb := NewRingBuffer(16)
|
|
||||||
rb.Write([]byte("hello"))
|
|
||||||
|
|
||||||
got := rb.Bytes()
|
|
||||||
if string(got) != "hello" {
|
|
||||||
t.Errorf("expected 'hello', got '%s'", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRingBuffer_Overflow(t *testing.T) {
|
|
||||||
rb := NewRingBuffer(8)
|
|
||||||
rb.Write([]byte("abcdefgh")) // exactly fills
|
|
||||||
rb.Write([]byte("ij")) // wraps around
|
|
||||||
|
|
||||||
got := rb.Bytes()
|
|
||||||
// Should contain the last 8 bytes: "cdefghij"
|
|
||||||
if string(got) != "cdefghij" {
|
|
||||||
t.Errorf("expected 'cdefghij', got '%s'", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRingBuffer_Reset(t *testing.T) {
|
|
||||||
rb := NewRingBuffer(16)
|
|
||||||
rb.Write([]byte("test"))
|
|
||||||
rb.Reset()
|
|
||||||
|
|
||||||
got := rb.Bytes()
|
|
||||||
if len(got) != 0 {
|
|
||||||
t.Errorf("expected empty after reset, got %d bytes", len(got))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDashboard_EscapeClosesOverlay(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "Escape") {
|
|
||||||
t.Error("expected Escape key handler for overlay")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDashboard_BackdropClickClosesOverlay(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "e.target === this") {
|
|
||||||
t.Error("expected backdrop click handler for overlay")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_HasInnerWrapper(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "detail-inner") {
|
|
||||||
t.Error("expected detail-inner wrapper in task detail")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTaskDetail_RendersMarkdownAsHTML(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/task/T01", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
// Markdown headers should be rendered as HTML <h1> tags
|
|
||||||
if !containsStr(body, "<h1>") {
|
|
||||||
t.Error("expected rendered <h1> from markdown heading")
|
|
||||||
}
|
|
||||||
// Should have docs-content class for proper styling
|
|
||||||
if !containsStr(body, "docs-content") {
|
|
||||||
t.Error("expected docs-content class on detail content")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocsPage_HasFullHeightLayout(t *testing.T) {
|
|
||||||
srv := setupTestServer(t)
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/docs", nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
srv.Router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
body := w.Body.String()
|
|
||||||
if !containsStr(body, "docs-container") {
|
|
||||||
t.Error("expected docs-container class")
|
|
||||||
}
|
|
||||||
if !containsStr(body, "docs-layout") {
|
|
||||||
t.Error("expected docs-layout class for grid layout")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,128 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
)
|
|
||||||
|
|
||||||
var wsUpgrader = websocket.Upgrader{
|
|
||||||
ReadBufferSize: 4096,
|
|
||||||
WriteBufferSize: 4096,
|
|
||||||
CheckOrigin: func(r *http.Request) bool { return true },
|
|
||||||
}
|
|
||||||
|
|
||||||
// wsResizeMsg is sent from the browser when the terminal size changes.
|
|
||||||
type wsResizeMsg struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Cols uint16 `json:"cols"`
|
|
||||||
Rows uint16 `json:"rows"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleConsoleWS handles WebSocket connections for task console terminals.
|
|
||||||
// Each connection attaches to an existing PTY session by task key.
|
|
||||||
func (s *Server) handleConsoleWS(c *gin.Context) {
|
|
||||||
key := c.Param("key") // e.g., "T08" or "T08-review"
|
|
||||||
|
|
||||||
sess := s.console.getSessionByKey(key)
|
|
||||||
if sess == nil {
|
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "sesija nije pronađena"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := wsUpgrader.Upgrade(c.Writer, c.Request, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("WS[%s]: upgrade error: %v", key, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
log.Printf("WS[%s]: connected", key)
|
|
||||||
|
|
||||||
ptySess := sess.PTY
|
|
||||||
|
|
||||||
// Send replay buffer so the user sees existing output
|
|
||||||
replay := ptySess.GetBuffer()
|
|
||||||
if len(replay) > 0 {
|
|
||||||
if err := conn.WriteMessage(websocket.BinaryMessage, replay); err != nil {
|
|
||||||
log.Printf("WS[%s]: replay write error: %v", key, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("WS[%s]: replayed %d bytes", key, len(replay))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe to new PTY output
|
|
||||||
subID := key + "-ws"
|
|
||||||
outputCh := ptySess.Subscribe(subID)
|
|
||||||
defer ptySess.Unsubscribe(subID)
|
|
||||||
|
|
||||||
// Serialized write channel
|
|
||||||
writeCh := make(chan []byte, 256)
|
|
||||||
writeDone := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(writeDone)
|
|
||||||
for data := range writeCh {
|
|
||||||
if err := conn.WriteMessage(websocket.BinaryMessage, data); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// PTY output → WebSocket
|
|
||||||
go func() {
|
|
||||||
for data := range outputCh {
|
|
||||||
select {
|
|
||||||
case writeCh <- data:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Signal to stop goroutines when read pump exits
|
|
||||||
stopCh := make(chan struct{})
|
|
||||||
|
|
||||||
// Watch for process exit
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-ptySess.Done():
|
|
||||||
log.Printf("WS[%s]: process exited", key)
|
|
||||||
conn.WriteMessage(websocket.CloseMessage,
|
|
||||||
websocket.FormatCloseMessage(websocket.CloseNormalClosure, "done"))
|
|
||||||
case <-stopCh:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// WebSocket → PTY (read pump)
|
|
||||||
for {
|
|
||||||
_, msg, err := conn.ReadMessage()
|
|
||||||
if err != nil {
|
|
||||||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseNormalClosure) {
|
|
||||||
log.Printf("WS[%s]: read error: %v", key, err)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for resize message
|
|
||||||
var resize wsResizeMsg
|
|
||||||
if json.Unmarshal(msg, &resize) == nil && resize.Type == "resize" && resize.Cols > 0 && resize.Rows > 0 {
|
|
||||||
if err := ptySess.Resize(resize.Rows, resize.Cols); err != nil {
|
|
||||||
log.Printf("WS[%s]: resize error: %v", key, err)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular keyboard input → PTY
|
|
||||||
if _, err := ptySess.WriteInput(msg); err != nil {
|
|
||||||
log.Printf("WS[%s]: write error: %v", key, err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(stopCh)
|
|
||||||
close(writeCh)
|
|
||||||
<-writeDone
|
|
||||||
log.Printf("WS[%s]: disconnected", key)
|
|
||||||
}
|
|
||||||
@ -1,115 +1,23 @@
|
|||||||
/* === CSS varijable — teme === */
|
|
||||||
:root,
|
|
||||||
[data-theme="dark"] {
|
|
||||||
--bg-page: #1a1a2e;
|
|
||||||
--bg-panel: #16213e;
|
|
||||||
--bg-deep: #111;
|
|
||||||
--bg-hover: #0f3460;
|
|
||||||
--border: #0f3460;
|
|
||||||
--border-light: #333;
|
|
||||||
--border-disabled: #444;
|
|
||||||
--accent: #e94560;
|
|
||||||
--success: #4ecca3;
|
|
||||||
--info: #6ec6ff;
|
|
||||||
--warning: #ffd93d;
|
|
||||||
--text: #eee;
|
|
||||||
--text-light: #ddd;
|
|
||||||
--text-secondary: #aaa;
|
|
||||||
--text-muted: #888;
|
|
||||||
--text-dim: #666;
|
|
||||||
--text-disabled: #555;
|
|
||||||
--text-on-color: #1a1a2e;
|
|
||||||
--overlay: rgba(0,0,0,0.6);
|
|
||||||
--shadow: rgba(0,0,0,0.4);
|
|
||||||
--drag-over: rgba(15, 52, 96, 0.3);
|
|
||||||
--accent-shadow: rgba(233, 69, 96, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-theme="light"] {
|
|
||||||
--bg-page: #f0f2f5;
|
|
||||||
--bg-panel: #ffffff;
|
|
||||||
--bg-deep: #f5f6fa;
|
|
||||||
--bg-hover: #e0e5ed;
|
|
||||||
--border: #c9d1db;
|
|
||||||
--border-light: #d8dee6;
|
|
||||||
--border-disabled: #ccc;
|
|
||||||
--accent: #d63851;
|
|
||||||
--success: #1a8a6a;
|
|
||||||
--info: #2b7dbd;
|
|
||||||
--warning: #b8860b;
|
|
||||||
--text: #1e293b;
|
|
||||||
--text-light: #334155;
|
|
||||||
--text-secondary: #475569;
|
|
||||||
--text-muted: #64748b;
|
|
||||||
--text-dim: #94a3b8;
|
|
||||||
--text-disabled: #a0aec0;
|
|
||||||
--text-on-color: #ffffff;
|
|
||||||
--overlay: rgba(0,0,0,0.35);
|
|
||||||
--shadow: rgba(0,0,0,0.12);
|
|
||||||
--drag-over: rgba(59, 130, 246, 0.1);
|
|
||||||
--accent-shadow: rgba(214, 56, 81, 0.15);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Reset === */
|
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Header === */
|
|
||||||
.header {
|
.header {
|
||||||
padding: 16px 24px;
|
padding: 16px 24px;
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-bottom: 2px solid var(--border);
|
border-bottom: 2px solid #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header h1 { font-size: 1.4em; }
|
.header h1 { font-size: 1.4em; }
|
||||||
.header .version { color: var(--text-muted); font-size: 0.9em; }
|
.header .version { color: #888; font-size: 0.9em; }
|
||||||
|
|
||||||
.header-right {
|
|
||||||
display: flex;
|
|
||||||
gap: 12px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Theme toggle === */
|
|
||||||
.theme-toggle {
|
|
||||||
display: flex;
|
|
||||||
gap: 2px;
|
|
||||||
background: var(--bg-page);
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: 2px;
|
|
||||||
border: 1px solid var(--border-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-btn {
|
|
||||||
padding: 4px 8px;
|
|
||||||
border: none;
|
|
||||||
background: transparent;
|
|
||||||
color: var(--text-muted);
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 0.8em;
|
|
||||||
transition: background 0.2s, color 0.2s;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-btn:hover {
|
|
||||||
color: var(--text);
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-btn.active {
|
|
||||||
background: var(--bg-hover);
|
|
||||||
color: var(--text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Board (Kanban) === */
|
|
||||||
.board {
|
.board {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, 1fr);
|
grid-template-columns: repeat(5, 1fr);
|
||||||
@ -119,7 +27,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.column {
|
.column {
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
@ -129,22 +37,21 @@ body {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
border-bottom: 2px solid var(--border);
|
border-bottom: 2px solid #0f3460;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
.column-count {
|
.column-count {
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 2px 8px;
|
padding: 2px 8px;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Task cards === */
|
|
||||||
.task-card {
|
.task-card {
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
@ -153,13 +60,13 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.task-card:hover {
|
.task-card:hover {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
transform: translateY(-1px);
|
transform: translateY(-1px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-id {
|
.task-id {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-title {
|
.task-title {
|
||||||
@ -170,59 +77,54 @@ body {
|
|||||||
.task-meta {
|
.task-meta {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
color: var(--text-muted);
|
color: #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-deps {
|
.task-deps {
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
color: var(--text-dim);
|
color: #666;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Task detail modal === */
|
/* Task detail panel — 50% of screen */
|
||||||
#task-detail {
|
#task-detail {
|
||||||
display: none;
|
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
right: -50%;
|
||||||
width: 100%;
|
width: 50%;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
z-index: 50;
|
background: #16213e;
|
||||||
background: var(--overlay);
|
border-left: 2px solid #0f3460;
|
||||||
justify-content: center;
|
padding: 20px;
|
||||||
align-items: center;
|
overflow-y: auto;
|
||||||
|
z-index: 10;
|
||||||
|
transition: right 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
#task-detail.active {
|
#task-detail.active {
|
||||||
display: flex;
|
right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-inner {
|
/* Board compresses when detail is open */
|
||||||
background: var(--bg-panel);
|
.board {
|
||||||
border: 1px solid var(--border);
|
transition: margin-right 0.3s ease;
|
||||||
border-radius: 10px;
|
}
|
||||||
padding: 24px;
|
|
||||||
width: 700px;
|
body.detail-open .board {
|
||||||
max-width: 90%;
|
margin-right: 50%;
|
||||||
max-height: 85vh;
|
|
||||||
overflow-y: auto;
|
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-close {
|
.detail-close {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
position: absolute;
|
float: right;
|
||||||
top: 12px;
|
font-size: 1.2em;
|
||||||
right: 16px;
|
color: #888;
|
||||||
font-size: 1.4em;
|
|
||||||
color: var(--text-muted);
|
|
||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
line-height: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-close:hover { color: var(--accent); }
|
.detail-close:hover { color: #e94560; }
|
||||||
|
|
||||||
.detail-meta { margin-top: 12px; font-size: 0.9em; color: var(--text-secondary); }
|
.detail-meta { margin-top: 12px; font-size: 0.9em; color: #aaa; }
|
||||||
.detail-meta p { margin-bottom: 4px; }
|
.detail-meta p { margin-bottom: 4px; }
|
||||||
|
|
||||||
.detail-actions {
|
.detail-actions {
|
||||||
@ -232,33 +134,23 @@ body {
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-content {
|
|
||||||
margin-top: 16px;
|
|
||||||
padding: 12px;
|
|
||||||
background: var(--bg-deep);
|
|
||||||
border-radius: 6px;
|
|
||||||
max-height: 60vh;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Buttons === */
|
|
||||||
.btn {
|
.btn {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
transition: background 0.2s;
|
transition: background 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover { background: var(--bg-hover); }
|
.btn:hover { background: #0f3460; }
|
||||||
|
|
||||||
.btn-move { border-color: var(--accent); }
|
|
||||||
|
|
||||||
|
.btn-move { border-color: #e94560; }
|
||||||
|
/* Task action buttons */
|
||||||
.task-action {
|
.task-action {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
@ -269,27 +161,27 @@ body {
|
|||||||
padding: 4px 10px;
|
padding: 4px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-run { border-color: var(--success); color: var(--success); }
|
.btn-run { border-color: #4ecca3; color: #4ecca3; }
|
||||||
.btn-run:hover { background: var(--success); color: var(--text-on-color); }
|
.btn-run:hover { background: #4ecca3; color: #1a1a2e; }
|
||||||
|
|
||||||
.btn-review { border-color: var(--info); color: var(--info); }
|
.btn-review { border-color: #6ec6ff; color: #6ec6ff; }
|
||||||
.btn-review:hover { background: var(--info); color: var(--text-on-color); }
|
.btn-review:hover { background: #6ec6ff; color: #1a1a2e; }
|
||||||
|
|
||||||
.btn-approve { border-color: var(--warning); color: var(--warning); }
|
.btn-approve { border-color: #ffd93d; color: #ffd93d; }
|
||||||
.btn-approve:hover { background: var(--warning); color: var(--text-on-color); }
|
.btn-approve:hover { background: #ffd93d; color: #1a1a2e; }
|
||||||
|
|
||||||
.btn-report { border-color: var(--text-muted); color: var(--text-muted); }
|
.btn-report { border-color: #888; color: #888; }
|
||||||
.btn-report:hover { background: var(--text-muted); color: var(--text-on-color); }
|
.btn-report:hover { background: #888; color: #1a1a2e; }
|
||||||
|
|
||||||
.btn-blocked {
|
.btn-blocked {
|
||||||
border-color: var(--border-disabled);
|
border-color: #444;
|
||||||
color: var(--text-disabled);
|
color: #555;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-running {
|
.btn-running {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
animation: pulse 1.5s ease infinite;
|
animation: pulse 1.5s ease infinite;
|
||||||
}
|
}
|
||||||
@ -298,28 +190,36 @@ body {
|
|||||||
0%, 100% { opacity: 1; }
|
0%, 100% { opacity: 1; }
|
||||||
50% { opacity: 0.5; }
|
50% { opacity: 0.5; }
|
||||||
}
|
}
|
||||||
|
.btn-success { border-color: #4ecca3; color: #4ecca3; }
|
||||||
|
.btn-success:hover { background: #4ecca3; color: #1a1a2e; }
|
||||||
|
|
||||||
.btn-success { border-color: var(--success); color: var(--success); }
|
.detail-content {
|
||||||
.btn-success:hover { background: var(--success); color: var(--text-on-color); }
|
white-space: pre-wrap;
|
||||||
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
.btn-active {
|
font-size: 0.8em;
|
||||||
background: var(--bg-hover);
|
margin-top: 16px;
|
||||||
border-color: var(--accent);
|
line-height: 1.6;
|
||||||
|
padding: 12px;
|
||||||
|
background: #111;
|
||||||
|
border-radius: 6px;
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Sortable / Drag & Drop === */
|
/* Sortable column-tasks container */
|
||||||
.column-tasks {
|
.column-tasks {
|
||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Drag & Drop styles */
|
||||||
.task-ghost {
|
.task-ghost {
|
||||||
opacity: 0.4;
|
opacity: 0.4;
|
||||||
border: 2px dashed var(--accent);
|
border: 2px dashed #e94560;
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-chosen {
|
.task-chosen {
|
||||||
box-shadow: 0 4px 16px var(--accent-shadow);
|
box-shadow: 0 4px 16px rgba(233, 69, 96, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-drag {
|
.task-drag {
|
||||||
@ -327,26 +227,27 @@ body {
|
|||||||
transform: rotate(2deg);
|
transform: rotate(2deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Drop zone highlight */
|
||||||
.column-tasks.sortable-drag-over {
|
.column-tasks.sortable-drag-over {
|
||||||
background: var(--drag-over);
|
background: rgba(15, 52, 96, 0.3);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Flash animations === */
|
/* Flash animations */
|
||||||
@keyframes flash-success {
|
@keyframes flash-success {
|
||||||
0% { background: var(--success); }
|
0% { background: #4ecca3; }
|
||||||
100% { background: var(--bg-page); }
|
100% { background: #1a1a2e; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes flash-error {
|
@keyframes flash-error {
|
||||||
0% { background: var(--accent); }
|
0% { background: #e94560; }
|
||||||
100% { background: var(--bg-page); }
|
100% { background: #1a1a2e; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.flash-success { animation: flash-success 0.5s ease; }
|
.flash-success { animation: flash-success 0.5s ease; }
|
||||||
.flash-error { animation: flash-error 0.5s ease; }
|
.flash-error { animation: flash-error 0.5s ease; }
|
||||||
|
|
||||||
/* === Toast === */
|
/* Toast notifications */
|
||||||
.toast {
|
.toast {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
@ -365,25 +266,32 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.toast-success {
|
.toast-success {
|
||||||
background: var(--success);
|
background: #4ecca3;
|
||||||
color: var(--text-on-color);
|
color: #1a1a2e;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toast-error {
|
.toast-error {
|
||||||
background: var(--accent);
|
background: #e94560;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Search === */
|
/* Header right section */
|
||||||
|
.header-right {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search */
|
||||||
.search-wrapper {
|
.search-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-wrapper input {
|
.search-wrapper input {
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
width: 220px;
|
width: 220px;
|
||||||
@ -392,7 +300,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.search-wrapper input:focus {
|
.search-wrapper input:focus {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,9 +311,9 @@ body {
|
|||||||
width: 400px;
|
width: 400px;
|
||||||
max-height: 500px;
|
max-height: 500px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 8px 24px var(--shadow);
|
box-shadow: 0 8px 24px rgba(0,0,0,0.4);
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
@ -418,8 +326,8 @@ body {
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid #0f3460;
|
||||||
transition: background 0.15s;
|
transition: background 0.15s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +336,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.search-result:hover {
|
.search-result:hover {
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-result-header {
|
.search-result-header {
|
||||||
@ -448,19 +356,19 @@ body {
|
|||||||
font-size: 0.7em;
|
font-size: 0.7em;
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-status-done { color: var(--success); }
|
.search-status-done { color: #4ecca3; }
|
||||||
.search-status-active { color: var(--accent); }
|
.search-status-active { color: #e94560; }
|
||||||
.search-status-review { color: var(--warning); }
|
.search-status-review { color: #ffd93d; }
|
||||||
.search-status-ready { color: var(--info); }
|
.search-status-ready { color: #6ec6ff; }
|
||||||
.search-status-backlog { color: var(--text-muted); }
|
.search-status-backlog { color: #888; }
|
||||||
|
|
||||||
.search-snippet {
|
.search-snippet {
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
color: var(--text-muted);
|
color: #888;
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -471,18 +379,23 @@ body {
|
|||||||
.search-empty {
|
.search-empty {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: var(--text-muted);
|
color: #888;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Navigation === */
|
/* Navigation */
|
||||||
.nav {
|
.nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Docs === */
|
.btn-active {
|
||||||
|
background: #0f3460;
|
||||||
|
border-color: #e94560;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Docs — full height */
|
||||||
.docs-container {
|
.docs-container {
|
||||||
padding: 16px 24px;
|
padding: 16px 24px;
|
||||||
height: calc(100vh - 60px);
|
height: calc(100vh - 60px);
|
||||||
@ -500,7 +413,7 @@ body {
|
|||||||
|
|
||||||
.docs-sidebar h2 {
|
.docs-sidebar h2 {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,9 +428,9 @@ body {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
font-family: "JetBrains Mono", "Fira Code", monospace;
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
@ -525,7 +438,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.doc-item:hover {
|
.doc-item:hover {
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.doc-icon { font-size: 1em; }
|
.doc-icon { font-size: 1em; }
|
||||||
@ -536,7 +449,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docs-breadcrumbs a {
|
.docs-breadcrumbs a {
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,7 +458,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.breadcrumb-sep {
|
.breadcrumb-sep {
|
||||||
color: var(--text-dim);
|
color: #555;
|
||||||
margin: 0 4px;
|
margin: 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,7 +472,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docs-content {
|
.docs-content {
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
line-height: 1.7;
|
line-height: 1.7;
|
||||||
@ -567,24 +480,24 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docs-content h1, .docs-content h2, .docs-content h3 {
|
.docs-content h1, .docs-content h2, .docs-content h3 {
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
margin-top: 1.2em;
|
margin-top: 1.2em;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.docs-content h1 { font-size: 1.5em; border-bottom: 1px solid var(--border-light); padding-bottom: 8px; }
|
.docs-content h1 { font-size: 1.5em; border-bottom: 1px solid #333; padding-bottom: 8px; }
|
||||||
.docs-content h2 { font-size: 1.2em; }
|
.docs-content h2 { font-size: 1.2em; }
|
||||||
.docs-content h3 { font-size: 1.05em; }
|
.docs-content h3 { font-size: 1.05em; }
|
||||||
|
|
||||||
.docs-content a {
|
.docs-content a {
|
||||||
color: var(--success);
|
color: #4ecca3;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.docs-content a:hover { text-decoration: underline; }
|
.docs-content a:hover { text-decoration: underline; }
|
||||||
|
|
||||||
.docs-content code {
|
.docs-content code {
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
font-family: "JetBrains Mono", "Fira Code", monospace;
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
@ -592,7 +505,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docs-content pre {
|
.docs-content pre {
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
@ -611,13 +524,13 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.docs-content th, .docs-content td {
|
.docs-content th, .docs-content td {
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.docs-content th {
|
.docs-content th {
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.docs-content ul, .docs-content ol {
|
.docs-content ul, .docs-content ol {
|
||||||
@ -628,19 +541,19 @@ body {
|
|||||||
.docs-content li { margin: 4px 0; }
|
.docs-content li { margin: 4px 0; }
|
||||||
|
|
||||||
.docs-content blockquote {
|
.docs-content blockquote {
|
||||||
border-left: 3px solid var(--accent);
|
border-left: 3px solid #e94560;
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
color: var(--text-secondary);
|
color: #aaa;
|
||||||
margin: 12px 0;
|
margin: 12px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.docs-content hr {
|
.docs-content hr {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--border-light);
|
border-top: 1px solid #333;
|
||||||
margin: 16px 0;
|
margin: 16px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Console === */
|
/* Console — fullscreen */
|
||||||
.console-container {
|
.console-container {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
height: calc(100vh - 60px);
|
height: calc(100vh - 60px);
|
||||||
@ -660,7 +573,7 @@ body {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
background: var(--bg-panel);
|
background: #16213e;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
@ -670,7 +583,7 @@ body {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid #0f3460;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,55 +591,66 @@ body {
|
|||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
padding: 2px 8px;
|
padding: 2px 8px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.session-idle { color: var(--text-muted); }
|
.session-idle { color: #888; }
|
||||||
.session-running { color: var(--success); }
|
.session-running { color: #4ecca3; }
|
||||||
|
|
||||||
.btn-kill {
|
.btn-kill {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
padding: 4px 10px;
|
padding: 4px 10px;
|
||||||
font-size: 0.75em;
|
font-size: 0.75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.console-terminal {
|
.console-output {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
background: var(--bg-deep);
|
|
||||||
}
|
|
||||||
|
|
||||||
.console-terminal .xterm {
|
|
||||||
height: 100%;
|
|
||||||
padding: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.console-terminal .xterm-screen {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.console-terminal .xterm-viewport {
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
padding: 12px;
|
||||||
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
|
font-size: 0.8em;
|
||||||
|
line-height: 1.5;
|
||||||
|
background: #111;
|
||||||
|
}
|
||||||
|
|
||||||
|
.console-cmd {
|
||||||
|
color: #4ecca3;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.console-line {
|
||||||
|
color: #ddd;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.console-error {
|
||||||
|
color: #e94560;
|
||||||
|
}
|
||||||
|
|
||||||
|
.console-done {
|
||||||
|
color: #666;
|
||||||
|
margin-top: 4px;
|
||||||
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.console-input-row {
|
.console-input-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border-top: 1px solid var(--border);
|
border-top: 1px solid #0f3460;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.console-input {
|
.console-input {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
padding: 8px 12px;
|
padding: 8px 12px;
|
||||||
font-family: "JetBrains Mono", "Fira Code", monospace;
|
font-family: "JetBrains Mono", "Fira Code", monospace;
|
||||||
font-size: 0.85em;
|
font-size: 0.85em;
|
||||||
@ -734,7 +658,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.console-input:focus {
|
.console-input:focus {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
}
|
}
|
||||||
|
|
||||||
.console-input:disabled {
|
.console-input:disabled {
|
||||||
@ -748,7 +672,7 @@ body {
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Submit / Prijava === */
|
/* Submit / Prijava */
|
||||||
.submit-container {
|
.submit-container {
|
||||||
max-width: 700px;
|
max-width: 700px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
@ -765,19 +689,19 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-mode {
|
.btn-mode {
|
||||||
border-color: var(--border-light);
|
border-color: #333;
|
||||||
color: var(--text-muted);
|
color: #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-mode.active {
|
.btn-mode.active {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
background: var(--bg-hover);
|
background: #0f3460;
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit-mode h2 {
|
.submit-mode h2 {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
color: var(--accent);
|
color: #e94560;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group {
|
.form-group {
|
||||||
@ -788,15 +712,15 @@ body {
|
|||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
color: var(--text-secondary);
|
color: #aaa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-input {
|
.form-input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: var(--bg-page);
|
background: #1a1a2e;
|
||||||
border: 1px solid var(--border-light);
|
border: 1px solid #333;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
outline: none;
|
outline: none;
|
||||||
@ -805,7 +729,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-input:focus {
|
.form-input:focus {
|
||||||
border-color: var(--accent);
|
border-color: #e94560;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea.form-input {
|
textarea.form-input {
|
||||||
@ -823,7 +747,7 @@ textarea.form-input {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit-msg {
|
.submit-msg {
|
||||||
@ -835,16 +759,16 @@ textarea.form-input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.submit-success {
|
.submit-success {
|
||||||
background: var(--success);
|
background: #4ecca3;
|
||||||
color: var(--text-on-color);
|
color: #1a1a2e;
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit-error {
|
.submit-error {
|
||||||
background: var(--accent);
|
background: #e94560;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Chat (operator mode) === */
|
/* Chat (operator mode) */
|
||||||
#mode-operator {
|
#mode-operator {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@ -855,7 +779,7 @@ textarea.form-input {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
background: var(--bg-deep);
|
background: #111;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
min-height: 300px;
|
min-height: 300px;
|
||||||
@ -874,11 +798,11 @@ textarea.form-input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.chat-user {
|
.chat-user {
|
||||||
color: var(--info);
|
color: #6ec6ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-bot {
|
.chat-bot {
|
||||||
color: var(--text);
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-text {
|
.chat-text {
|
||||||
@ -891,18 +815,15 @@ textarea.form-input {
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === Placeholder text === */
|
/* Responsive */
|
||||||
.text-muted {
|
|
||||||
color: var(--text-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* === Responsive === */
|
|
||||||
@media (max-width: 1100px) {
|
@media (max-width: 1100px) {
|
||||||
.board { grid-template-columns: repeat(3, 1fr); }
|
.board { grid-template-columns: repeat(3, 1fr); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 700px) {
|
@media (max-width: 700px) {
|
||||||
.board { grid-template-columns: repeat(2, 1fr); }
|
.board { grid-template-columns: repeat(2, 1fr); }
|
||||||
|
#task-detail { width: 100%; right: -100%; }
|
||||||
|
body.detail-open .board { margin-right: 0; }
|
||||||
.docs-layout { grid-template-columns: 1fr; }
|
.docs-layout { grid-template-columns: 1fr; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,21 +5,13 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>KAOS — Konzola</title>
|
<title>KAOS — Konzola</title>
|
||||||
<script>(function(){var m=localStorage.getItem('kaos-theme')||'dark',t=m;if(m==='auto'){t=window.matchMedia('(prefers-color-scheme:light)').matches?'light':'dark'}document.documentElement.setAttribute('data-theme',t)})()</script>
|
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/css/xterm.css">
|
|
||||||
<script src="/static/htmx.min.js"></script>
|
<script src="/static/htmx.min.js"></script>
|
||||||
<script src="/static/theme.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>KAOS Dashboard</h1>
|
<h1>🔧 KAOS Dashboard</h1>
|
||||||
<div class="header-right">
|
<div class="header-right">
|
||||||
<div class="theme-toggle">
|
|
||||||
<button class="theme-btn" data-theme-mode="light" onclick="setTheme('light')" title="Svetla tema">☀️</button>
|
|
||||||
<button class="theme-btn" data-theme-mode="dark" onclick="setTheme('dark')" title="Tamna tema">🌙</button>
|
|
||||||
<button class="theme-btn" data-theme-mode="auto" onclick="setTheme('auto')" title="Sistemska tema">🔄</button>
|
|
||||||
</div>
|
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<a href="/" class="btn">Kanban</a>
|
<a href="/" class="btn">Kanban</a>
|
||||||
<a href="/docs" class="btn">Dokumenti</a>
|
<a href="/docs" class="btn">Dokumenti</a>
|
||||||
@ -31,233 +23,156 @@
|
|||||||
|
|
||||||
<div class="console-container">
|
<div class="console-container">
|
||||||
<div class="console-toolbar">
|
<div class="console-toolbar">
|
||||||
<span id="session-info">Sesije: 0</span>
|
<button class="btn" id="toggle-panel" onclick="togglePanel2()">+ Sesija 2</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="console-panels">
|
||||||
|
<div class="console-panel" id="panel-1">
|
||||||
|
<div class="console-panel-header">
|
||||||
|
<span>🔧 Sesija 1</span>
|
||||||
|
<span class="session-status" id="status-1">idle</span>
|
||||||
|
<button class="btn btn-kill" id="kill-1" onclick="killSession(1)" style="display:none">Prekini</button>
|
||||||
|
</div>
|
||||||
|
<div class="console-output" id="output-1"></div>
|
||||||
|
<div class="console-input-row">
|
||||||
|
<input type="text" id="input-1" class="console-input" placeholder="Komanda..." onkeydown="handleKey(event, 1)" autocomplete="off">
|
||||||
|
<button class="btn btn-move" onclick="sendCommand(1)">⏎</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="console-panel" id="panel-2" style="display:none">
|
||||||
|
<div class="console-panel-header">
|
||||||
|
<span>🔧 Sesija 2</span>
|
||||||
|
<span class="session-status" id="status-2">idle</span>
|
||||||
|
<button class="btn btn-kill" id="kill-2" onclick="killSession(2)" style="display:none">Prekini</button>
|
||||||
|
</div>
|
||||||
|
<div class="console-output" id="output-2"></div>
|
||||||
|
<div class="console-input-row">
|
||||||
|
<input type="text" id="input-2" class="console-input" placeholder="Komanda..." onkeydown="handleKey(event, 2)" autocomplete="off">
|
||||||
|
<button class="btn btn-move" onclick="sendCommand(2)">⏎</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="console-panels" id="panels">
|
|
||||||
<div class="console-empty" id="empty-state">
|
|
||||||
<p>Nema aktivnih sesija. Kliknite "Pusti" na tasku da pokrenete rad.</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/lib/xterm.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@xterm/addon-fit@0.10.0/lib/addon-fit.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@xterm/addon-web-links@0.11.0/lib/addon-web-links.min.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
// ── Terminal themes ──────────────────────────────────
|
var historyIdx = [0, 0];
|
||||||
var TERM_THEMES = {
|
var cmdHistory = [[], []];
|
||||||
dark: {
|
|
||||||
background: '#0d1117', foreground: '#e0e0e0', cursor: '#e94560', cursorAccent: '#0d1117',
|
function handleKey(e, session) {
|
||||||
selectionBackground: 'rgba(233,69,96,0.3)',
|
if (e.key === 'Enter') {
|
||||||
black: '#0d1117', red: '#f44336', green: '#4caf50', yellow: '#ff9800',
|
sendCommand(session);
|
||||||
blue: '#2196f3', magenta: '#e94560', cyan: '#00bcd4', white: '#e0e0e0',
|
} else if (e.key === 'ArrowUp') {
|
||||||
brightBlack: '#6c6c80', brightRed: '#ff6b81', brightGreen: '#66bb6a', brightYellow: '#ffb74d',
|
e.preventDefault();
|
||||||
brightBlue: '#64b5f6', brightMagenta: '#ff6b81', brightCyan: '#4dd0e1', brightWhite: '#ffffff'
|
var idx = session - 1;
|
||||||
},
|
if (historyIdx[idx] > 0) {
|
||||||
light: {
|
historyIdx[idx]--;
|
||||||
background: '#f5f6fa', foreground: '#1e293b', cursor: '#d63851', cursorAccent: '#f5f6fa',
|
document.getElementById('input-' + session).value = cmdHistory[idx][historyIdx[idx]] || '';
|
||||||
selectionBackground: 'rgba(214,56,81,0.15)',
|
|
||||||
black: '#1e293b', red: '#dc322f', green: '#859900', yellow: '#b58900',
|
|
||||||
blue: '#268bd2', magenta: '#d63851', cyan: '#2aa198', white: '#eee8d5',
|
|
||||||
brightBlack: '#586e75', brightRed: '#cb4b16', brightGreen: '#586e75', brightYellow: '#657b83',
|
|
||||||
brightBlue: '#839496', brightMagenta: '#6c71c4', brightCyan: '#93a1a1', brightWhite: '#002b36'
|
|
||||||
}
|
}
|
||||||
|
} else if (e.key === 'ArrowDown') {
|
||||||
|
e.preventDefault();
|
||||||
|
var idx = session - 1;
|
||||||
|
if (historyIdx[idx] < cmdHistory[idx].length) {
|
||||||
|
historyIdx[idx]++;
|
||||||
|
document.getElementById('input-' + session).value = cmdHistory[idx][historyIdx[idx]] || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendCommand(session) {
|
||||||
|
var input = document.getElementById('input-' + session);
|
||||||
|
var cmd = input.value.trim();
|
||||||
|
if (!cmd) return;
|
||||||
|
|
||||||
|
var idx = session - 1;
|
||||||
|
cmdHistory[idx].push(cmd);
|
||||||
|
historyIdx[idx] = cmdHistory[idx].length;
|
||||||
|
|
||||||
|
var output = document.getElementById('output-' + session);
|
||||||
|
output.innerHTML += '<div class="console-cmd">> ' + escapeHtml(cmd) + '</div>';
|
||||||
|
input.value = '';
|
||||||
|
|
||||||
|
setSessionUI(session, 'running');
|
||||||
|
|
||||||
|
fetch('/console/exec', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify({cmd: cmd, session: session})
|
||||||
|
})
|
||||||
|
.then(function(resp) {
|
||||||
|
if (!resp.ok) {
|
||||||
|
return resp.json().then(function(data) {
|
||||||
|
output.innerHTML += '<div class="console-error">' + escapeHtml(data.error) + '</div>';
|
||||||
|
setSessionUI(session, 'idle');
|
||||||
|
throw new Error(data.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return resp.json();
|
||||||
|
})
|
||||||
|
.then(function(data) {
|
||||||
|
if (!data) return;
|
||||||
|
streamOutput(session, data.exec_id);
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
setSessionUI(session, 'idle');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function streamOutput(session, execId) {
|
||||||
|
var output = document.getElementById('output-' + session);
|
||||||
|
var source = new EventSource('/console/stream/' + execId);
|
||||||
|
|
||||||
|
source.onmessage = function(e) {
|
||||||
|
output.innerHTML += '<div class="console-line">' + escapeHtml(e.data) + '</div>';
|
||||||
|
output.scrollTop = output.scrollHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTermTheme() {
|
source.addEventListener('done', function(e) {
|
||||||
var t = document.documentElement.getAttribute('data-theme') || 'dark';
|
source.close();
|
||||||
return TERM_THEMES[t] || TERM_THEMES.dark;
|
output.innerHTML += '<div class="console-done">--- gotovo ---</div>';
|
||||||
}
|
output.scrollTop = output.scrollHeight;
|
||||||
|
setSessionUI(session, 'idle');
|
||||||
// ── Session state ────────────────────────────────────
|
|
||||||
var terminals = {};
|
|
||||||
|
|
||||||
function sessionKey(sess) {
|
|
||||||
return sess.type === 'review' ? sess.task_id + '-review' : sess.task_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTerminal(sess) {
|
|
||||||
var key = sessionKey(sess);
|
|
||||||
if (terminals[key]) return;
|
|
||||||
|
|
||||||
document.getElementById('empty-state').style.display = 'none';
|
|
||||||
|
|
||||||
var panel = document.createElement('div');
|
|
||||||
panel.className = 'console-panel';
|
|
||||||
panel.id = 'panel-' + key;
|
|
||||||
|
|
||||||
var header = document.createElement('div');
|
|
||||||
header.className = 'console-panel-header';
|
|
||||||
var label = sess.task_id + (sess.type === 'review' ? ' [pregled]' : ' [rad]');
|
|
||||||
header.innerHTML = '<span>' + label + '</span>' +
|
|
||||||
'<span class="session-status session-running" id="status-' + key + '">' + sess.status + '</span>' +
|
|
||||||
'<button class="btn btn-sm" onclick="killSession(\'' + sess.task_id + '\', \'' + sess.type + '\')">Ugasi</button>';
|
|
||||||
|
|
||||||
var termDiv = document.createElement('div');
|
|
||||||
termDiv.className = 'console-terminal';
|
|
||||||
termDiv.id = 'terminal-' + key;
|
|
||||||
|
|
||||||
panel.appendChild(header);
|
|
||||||
panel.appendChild(termDiv);
|
|
||||||
document.getElementById('panels').appendChild(panel);
|
|
||||||
|
|
||||||
var theme = getTermTheme();
|
|
||||||
var term = new Terminal({
|
|
||||||
cursorBlink: true,
|
|
||||||
cursorStyle: 'block',
|
|
||||||
cursorInactiveStyle: 'outline',
|
|
||||||
fontSize: 14,
|
|
||||||
fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
|
|
||||||
theme: theme,
|
|
||||||
allowProposedApi: true,
|
|
||||||
scrollback: 10000,
|
|
||||||
convertEol: false,
|
|
||||||
drawBoldTextInBrightColors: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var fitAddon = new FitAddon.FitAddon();
|
source.onerror = function() {
|
||||||
term.loadAddon(fitAddon);
|
source.close();
|
||||||
term.loadAddon(new WebLinksAddon.WebLinksAddon());
|
setSessionUI(session, 'idle');
|
||||||
term.open(termDiv);
|
|
||||||
|
|
||||||
terminals[key] = { term: term, fitAddon: fitAddon, ws: null };
|
|
||||||
|
|
||||||
termDiv.addEventListener('click', function() { term.focus(); });
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
fitAddon.fit();
|
|
||||||
connectWS(key, term);
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── WebSocket connection ─────────────────────────────
|
|
||||||
function connectWS(key, term) {
|
|
||||||
var sess = terminals[key];
|
|
||||||
if (!sess) return;
|
|
||||||
|
|
||||||
if (sess.ws) {
|
|
||||||
sess.ws.close();
|
|
||||||
sess.ws = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
||||||
var url = proto + '//' + location.host + '/console/ws/' + key;
|
|
||||||
var ws = new WebSocket(url);
|
|
||||||
ws.binaryType = 'arraybuffer';
|
|
||||||
|
|
||||||
ws.onopen = function() {
|
|
||||||
var el = document.getElementById('status-' + key);
|
|
||||||
if (el) { el.textContent = 'connected'; el.className = 'session-status session-running'; }
|
|
||||||
ws.send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows }));
|
|
||||||
term.focus();
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
ws.onmessage = function(event) {
|
function killSession(session) {
|
||||||
if (event.data instanceof ArrayBuffer) {
|
fetch('/console/kill/' + session, {method: 'POST'})
|
||||||
term.write(new Uint8Array(event.data));
|
.then(function() {
|
||||||
|
var output = document.getElementById('output-' + session);
|
||||||
|
output.innerHTML += '<div class="console-error">--- prekinuto ---</div>';
|
||||||
|
setSessionUI(session, 'idle');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSessionUI(session, status) {
|
||||||
|
document.getElementById('status-' + session).textContent = status;
|
||||||
|
document.getElementById('status-' + session).className = 'session-status session-' + status;
|
||||||
|
document.getElementById('kill-' + session).style.display = status === 'running' ? 'inline-block' : 'none';
|
||||||
|
document.getElementById('input-' + session).disabled = status === 'running';
|
||||||
|
}
|
||||||
|
|
||||||
|
function togglePanel2() {
|
||||||
|
var panel = document.getElementById('panel-2');
|
||||||
|
var btn = document.getElementById('toggle-panel');
|
||||||
|
if (panel.style.display === 'none') {
|
||||||
|
panel.style.display = 'flex';
|
||||||
|
btn.textContent = '- Sesija 2';
|
||||||
} else {
|
} else {
|
||||||
term.write(event.data);
|
panel.style.display = 'none';
|
||||||
|
btn.textContent = '+ Sesija 2';
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = function() {
|
|
||||||
sess.ws = null;
|
|
||||||
var el = document.getElementById('status-' + key);
|
|
||||||
if (el) { el.textContent = 'disconnected'; el.className = 'session-status'; }
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onerror = function() {
|
|
||||||
sess.ws = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Keyboard input → WebSocket
|
|
||||||
term.onData(function(data) {
|
|
||||||
if (sess.ws && sess.ws.readyState === WebSocket.OPEN) {
|
|
||||||
sess.ws.send(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Resize → WebSocket
|
|
||||||
term.onResize(function(size) {
|
|
||||||
if (sess.ws && sess.ws.readyState === WebSocket.OPEN) {
|
|
||||||
sess.ws.send(JSON.stringify({ type: 'resize', cols: size.cols, rows: size.rows }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
sess.ws = ws;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Session management ───────────────────────────────
|
function escapeHtml(text) {
|
||||||
function killSession(taskID, type) {
|
var div = document.createElement('div');
|
||||||
fetch('/console/kill/' + taskID + '?type=' + type, { method: 'POST' })
|
div.textContent = text;
|
||||||
.then(function(resp) { return resp.json(); })
|
return div.innerHTML;
|
||||||
.then(function() { refreshSessions(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshSessions() {
|
|
||||||
fetch('/console/sessions')
|
|
||||||
.then(function(resp) { return resp.json(); })
|
|
||||||
.then(function(sessions) {
|
|
||||||
var info = document.getElementById('session-info');
|
|
||||||
info.textContent = 'Sesije: ' + sessions.length;
|
|
||||||
|
|
||||||
if (sessions.length === 0) {
|
|
||||||
document.getElementById('empty-state').style.display = 'block';
|
|
||||||
} else {
|
|
||||||
document.getElementById('empty-state').style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentKeys = {};
|
|
||||||
sessions.forEach(function(sess) {
|
|
||||||
var key = sessionKey(sess);
|
|
||||||
currentKeys[key] = true;
|
|
||||||
createTerminal(sess);
|
|
||||||
|
|
||||||
var el = document.getElementById('status-' + key);
|
|
||||||
if (el && sess.status === 'exited') {
|
|
||||||
el.textContent = 'finished';
|
|
||||||
el.className = 'session-status session-done';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove panels for sessions that no longer exist
|
|
||||||
Object.keys(terminals).forEach(function(key) {
|
|
||||||
if (!currentKeys[key]) {
|
|
||||||
var panel = document.getElementById('panel-' + key);
|
|
||||||
if (panel) panel.remove();
|
|
||||||
if (terminals[key].ws) terminals[key].ws.close();
|
|
||||||
delete terminals[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Theme sync ───────────────────────────────────────
|
|
||||||
var origSetTheme = window.setTheme;
|
|
||||||
window.setTheme = function(mode) {
|
|
||||||
if (origSetTheme) origSetTheme(mode);
|
|
||||||
setTimeout(function() {
|
|
||||||
var theme = getTermTheme();
|
|
||||||
Object.keys(terminals).forEach(function(key) {
|
|
||||||
if (terminals[key].term) {
|
|
||||||
terminals[key].term.options.theme = theme;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 50);
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── Window resize ────────────────────────────────────
|
|
||||||
window.addEventListener('resize', function() {
|
|
||||||
Object.keys(terminals).forEach(function(key) {
|
|
||||||
if (terminals[key].fitAddon) {
|
|
||||||
terminals[key].fitAddon.fit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── Initialize ───────────────────────────────────────
|
|
||||||
refreshSessions();
|
|
||||||
setInterval(refreshSessions, 5000);
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -4,11 +4,9 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>KAOS Dashboard</title>
|
<title>KAOS Dashboard</title>
|
||||||
<script>(function(){var m=localStorage.getItem('kaos-theme')||'dark',t=m;if(m==='auto'){t=window.matchMedia('(prefers-color-scheme:light)').matches?'light':'dark'}document.documentElement.setAttribute('data-theme',t)})()</script>
|
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
<script src="/static/htmx.min.js"></script>
|
<script src="/static/htmx.min.js"></script>
|
||||||
<script src="/static/sortable.min.js"></script>
|
<script src="/static/sortable.min.js"></script>
|
||||||
<script src="/static/theme.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -24,17 +22,11 @@
|
|||||||
autocomplete="off">
|
autocomplete="off">
|
||||||
<div id="search-results" class="search-results-dropdown"></div>
|
<div id="search-results" class="search-results-dropdown"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="theme-toggle">
|
|
||||||
<button class="theme-btn" data-theme-mode="light" onclick="setTheme('light')" title="Svetla tema">☀️</button>
|
|
||||||
<button class="theme-btn" data-theme-mode="dark" onclick="setTheme('dark')" title="Tamna tema">🌙</button>
|
|
||||||
<button class="theme-btn" data-theme-mode="auto" onclick="setTheme('auto')" title="Sistemska tema">🔄</button>
|
|
||||||
</div>
|
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<a href="/" class="btn btn-active">Kanban</a>
|
<a href="/" class="btn btn-active">Kanban</a>
|
||||||
<a href="/docs" class="btn">Dokumenti</a>
|
<a href="/docs" class="btn">Dokumenti</a>
|
||||||
<a href="/console" class="btn">Konzola</a>
|
<a href="/console" class="btn">Konzola</a>
|
||||||
<a href="/submit" class="btn">Prijava</a>
|
<a href="/submit" class="btn">Prijava</a>
|
||||||
<a href="#" class="btn" onclick="showLogs(); return false;">Logovi</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -45,6 +37,7 @@
|
|||||||
document.body.addEventListener('htmx:afterSwap', function(e) {
|
document.body.addEventListener('htmx:afterSwap', function(e) {
|
||||||
if (e.detail.target.id === 'task-detail') {
|
if (e.detail.target.id === 'task-detail') {
|
||||||
e.detail.target.classList.add('active');
|
e.detail.target.classList.add('active');
|
||||||
|
document.body.classList.add('detail-open');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,39 +45,7 @@ function closeDetail() {
|
|||||||
var el = document.getElementById('task-detail');
|
var el = document.getElementById('task-detail');
|
||||||
el.classList.remove('active');
|
el.classList.remove('active');
|
||||||
el.innerHTML = '';
|
el.innerHTML = '';
|
||||||
}
|
document.body.classList.remove('detail-open');
|
||||||
|
|
||||||
// Close overlay on Escape
|
|
||||||
document.addEventListener('keydown', function(e) {
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
var detail = document.getElementById('task-detail');
|
|
||||||
if (detail && detail.classList.contains('active')) {
|
|
||||||
closeDetail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close overlay on backdrop click
|
|
||||||
document.getElementById('task-detail').addEventListener('click', function(e) {
|
|
||||||
if (e.target === this) {
|
|
||||||
closeDetail();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function showLogs() {
|
|
||||||
fetch('/api/logs/tail')
|
|
||||||
.then(function(resp) { return resp.text(); })
|
|
||||||
.then(function(text) {
|
|
||||||
var el = document.getElementById('task-detail');
|
|
||||||
el.innerHTML = '<div class="detail-overlay"><div class="detail-header"><h2>Poslednji logovi</h2><button class="detail-close" onclick="closeDetail()">×</button></div><div class="detail-body"><pre style="white-space:pre-wrap;font-size:13px;line-height:1.5">' + escapeHtml(text) + '</pre></div></div>';
|
|
||||||
el.classList.add('active');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHtml(text) {
|
|
||||||
var div = document.createElement('div');
|
|
||||||
div.textContent = text;
|
|
||||||
return div.innerHTML;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showToast(msg, type) {
|
function showToast(msg, type) {
|
||||||
@ -96,39 +57,16 @@ function showToast(msg, type) {
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle "Proveri" button response
|
|
||||||
document.body.addEventListener('htmx:afterRequest', function(e) {
|
|
||||||
if (e.detail.pathInfo && e.detail.pathInfo.requestPath && e.detail.pathInfo.requestPath.match(/\/task\/T\d+\/review/)) {
|
|
||||||
var xhr = e.detail.xhr;
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
showToast('Pregled pokrenut', 'success');
|
|
||||||
setTimeout(function() { window.location.href = '/console'; }, 800);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
var data = JSON.parse(xhr.responseText);
|
|
||||||
showToast(data.error || 'Greška', 'error');
|
|
||||||
} catch(ex) {
|
|
||||||
showToast('Greška', 'error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle "Pusti" button response
|
// Handle "Pusti" button response
|
||||||
document.body.addEventListener('htmx:afterRequest', function(e) {
|
document.body.addEventListener('htmx:afterRequest', function(e) {
|
||||||
if (e.detail.pathInfo && e.detail.pathInfo.requestPath && e.detail.pathInfo.requestPath.match(/\/task\/T\d+\/run/)) {
|
if (e.detail.pathInfo && e.detail.pathInfo.requestPath && e.detail.pathInfo.requestPath.match(/\/task\/T\d+\/run/)) {
|
||||||
var xhr = e.detail.xhr;
|
var xhr = e.detail.xhr;
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
var data = JSON.parse(xhr.responseText);
|
var data = JSON.parse(xhr.responseText);
|
||||||
showToast('Pokrenuto: ' + (data.task || ''), 'success');
|
showToast(data.exec_id ? 'Pokrenuto u sesiji ' + data.session : 'Pokrenuto', 'success');
|
||||||
setTimeout(function() { window.location.href = '/console'; }, 800);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
var data = JSON.parse(xhr.responseText);
|
var data = JSON.parse(xhr.responseText);
|
||||||
showToast(data.error || 'Greška', 'error');
|
showToast(data.error || 'Greška', 'error');
|
||||||
} catch(ex) {
|
|
||||||
showToast('Greška', 'error');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
htmx.ajax('GET', '/', {target: '#board', swap: 'outerHTML', select: '#board'});
|
htmx.ajax('GET', '/', {target: '#board', swap: 'outerHTML', select: '#board'});
|
||||||
}
|
}
|
||||||
@ -147,6 +85,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
if (wrapper && !wrapper.contains(e.target)) {
|
if (wrapper && !wrapper.contains(e.target)) {
|
||||||
results.innerHTML = '';
|
results.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close detail panel on click outside
|
||||||
|
var detail = document.getElementById('task-detail');
|
||||||
|
if (detail && detail.classList.contains('active') && !detail.contains(e.target) && !e.target.closest('.task-card')) {
|
||||||
|
closeDetail();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
{{else if eq .Action "approve"}}
|
{{else if eq .Action "approve"}}
|
||||||
<button class="btn btn-approve" hx-get="/task/{{.ID}}" hx-target="#task-detail" hx-swap="innerHTML" onclick="event.stopPropagation()">Pregledaj</button>
|
<button class="btn btn-approve" hx-get="/task/{{.ID}}" hx-target="#task-detail" hx-swap="innerHTML" onclick="event.stopPropagation()">Pregledaj</button>
|
||||||
{{else if eq .Action "done"}}
|
{{else if eq .Action "done"}}
|
||||||
<button class="btn btn-report" hx-get="/report/{{.ID}}" hx-target="#task-detail" hx-swap="innerHTML" onclick="event.stopPropagation()">📊 Izveštaj</button>
|
<button class="btn btn-report" hx-get="/report/{{.ID}}" hx-target="#task-detail" hx-swap="innerHTML" onclick="event.stopPropagation()">Izvestaj</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
{{define "task-detail"}}
|
{{define "task-detail"}}
|
||||||
<div class="detail-inner">
|
|
||||||
<span class="detail-close" onclick="closeDetail()">✕</span>
|
<span class="detail-close" onclick="closeDetail()">✕</span>
|
||||||
<h2>{{.Task.ID}}: {{.Task.Title}}</h2>
|
<h2>{{.Task.ID}}: {{.Task.Title}}</h2>
|
||||||
<div class="detail-meta">
|
<div class="detail-meta">
|
||||||
@ -8,9 +7,9 @@
|
|||||||
<p><strong>Zavisi od:</strong> {{joinDeps .Task.DependsOn}}</p>
|
<p><strong>Zavisi od:</strong> {{joinDeps .Task.DependsOn}}</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{if or .HasReport (eq .Task.Status "done")}}
|
{{if .HasReport}}
|
||||||
<div class="detail-actions">
|
<div class="detail-actions">
|
||||||
<button class="btn btn-report" hx-get="/report/{{.Task.ID}}" hx-target="#task-detail" hx-swap="innerHTML">📊 Izveštaj</button>
|
<a href="/report/{{.Task.ID}}" class="btn" target="_blank">Izvestaj</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="detail-actions">
|
<div class="detail-actions">
|
||||||
@ -21,11 +20,9 @@
|
|||||||
<button class="btn btn-run" hx-post="/task/{{.Task.ID}}/run" hx-swap="none" onclick="closeDetail()">Pusti</button>
|
<button class="btn btn-run" hx-post="/task/{{.Task.ID}}/run" hx-swap="none" onclick="closeDetail()">Pusti</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if eq .Task.Status "review"}}
|
{{if eq .Task.Status "review"}}
|
||||||
<button class="btn btn-run" hx-post="/task/{{.Task.ID}}/review" hx-swap="none" onclick="closeDetail()">Proveri</button>
|
|
||||||
<button class="btn btn-success" hx-post="/task/{{.Task.ID}}/move?to=done" hx-target="#board" hx-swap="outerHTML" onclick="closeDetail()">Odobri</button>
|
<button class="btn btn-success" hx-post="/task/{{.Task.ID}}/move?to=done" hx-target="#board" hx-swap="outerHTML" onclick="closeDetail()">Odobri</button>
|
||||||
<button class="btn btn-move" hx-post="/task/{{.Task.ID}}/move?to=ready" hx-target="#board" hx-swap="outerHTML" onclick="closeDetail()">Vrati</button>
|
<button class="btn btn-move" hx-post="/task/{{.Task.ID}}/move?to=ready" hx-target="#board" hx-swap="outerHTML" onclick="closeDetail()">Vrati</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-content docs-content">{{.Content}}</div>
|
<div class="detail-content">{{.Content}}</div>
|
||||||
</div>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@ -108,7 +108,7 @@ function sendChat() {
|
|||||||
fetch('/submit/chat', {
|
fetch('/submit/chat', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({message: msg})
|
body: JSON.stringify({message: msg, chat_id: currentChatID})
|
||||||
})
|
})
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
@ -130,16 +130,14 @@ function streamChatResponse(chatID, botId) {
|
|||||||
var source = new EventSource('/submit/chat/stream/' + chatID);
|
var source = new EventSource('/submit/chat/stream/' + chatID);
|
||||||
var el = document.getElementById(botId);
|
var el = document.getElementById(botId);
|
||||||
var input = document.getElementById('chat-input');
|
var input = document.getElementById('chat-input');
|
||||||
var lines = [];
|
|
||||||
|
|
||||||
source.onmessage = function(e) {
|
source.addEventListener('message', function(e) {
|
||||||
if (el) {
|
if (el) {
|
||||||
lines.push(e.data);
|
el.querySelector('.chat-text').textContent = e.data;
|
||||||
el.querySelector('.chat-text').textContent = lines.join('\n');
|
|
||||||
var messages = document.getElementById('chat-messages');
|
var messages = document.getElementById('chat-messages');
|
||||||
messages.scrollTop = messages.scrollHeight;
|
messages.scrollTop = messages.scrollHeight;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
source.addEventListener('done', function() {
|
source.addEventListener('done', function() {
|
||||||
source.close();
|
source.close();
|
||||||
|
|||||||
@ -1,159 +0,0 @@
|
|||||||
# KAOS — Arhitektura
|
|
||||||
|
|
||||||
**Verzija:** 0.3.0
|
|
||||||
**Poslednje azuriranje:** 2026-02-21
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Tech Stack
|
|
||||||
|
|
||||||
| Komponenta | Tehnologija |
|
|
||||||
|------------|-------------|
|
|
||||||
| Backend | Go 1.22+ |
|
|
||||||
| HTTP framework | Gin |
|
|
||||||
| Frontend | Go templates + HTMX + xterm.js |
|
|
||||||
| Terminali | xterm.js 5.5.0 (CDN) + WebSocket |
|
|
||||||
| PTY | github.com/creack/pty |
|
|
||||||
| WebSocket | github.com/gorilla/websocket |
|
|
||||||
| Markdown | github.com/yuin/goldmark |
|
|
||||||
| Drag & Drop | Sortable.js |
|
|
||||||
| Real-time | Server-Sent Events (SSE) |
|
|
||||||
| Baza | Nema (disk je source of truth) |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Struktura koda
|
|
||||||
|
|
||||||
```
|
|
||||||
code/
|
|
||||||
├── cmd/
|
|
||||||
│ ├── kaos-server/ # HTTP server entry point
|
|
||||||
│ └── kaos-supervisor/ # CLI supervisor (legacy)
|
|
||||||
├── internal/
|
|
||||||
│ ├── config/ # Konfiguracija (env vars)
|
|
||||||
│ ├── server/ # HTTP handleri, PTY, WS, render
|
|
||||||
│ └── supervisor/ # Task scanner, file ops
|
|
||||||
├── web/
|
|
||||||
│ ├── static/ # CSS, JS (htmx, sortable, theme)
|
|
||||||
│ └── templates/ # Go templates (go:embed)
|
|
||||||
│ ├── layout.html
|
|
||||||
│ ├── console.html
|
|
||||||
│ └── partials/
|
|
||||||
│ ├── task-card.html
|
|
||||||
│ └── task-detail.html
|
|
||||||
├── go.mod
|
|
||||||
├── go.sum
|
|
||||||
└── .env.example
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Kljucne komponente
|
|
||||||
|
|
||||||
### Server (server.go)
|
|
||||||
- Gin router sa svim rutama
|
|
||||||
- No-cache middleware za dinamicke rute
|
|
||||||
- SSE event broker za real-time update
|
|
||||||
- Task session manager za PTY sesije
|
|
||||||
|
|
||||||
### Task Session Manager (console.go)
|
|
||||||
- `taskSessionManager` - mapa PTY sesija po task ID
|
|
||||||
- `startSession()` - spawna interaktivni claude u PTY
|
|
||||||
- Prompt se pise u temp fajl, claude dobija jednolinijsku instrukciju
|
|
||||||
- Sesije prezivljavaju page reload (PTY na serveru)
|
|
||||||
|
|
||||||
### PTY Session (pty_session.go)
|
|
||||||
- `consolePTYSession` - wrapper oko PTY procesa
|
|
||||||
- RingBuffer (1MB) za replay output-a
|
|
||||||
- Subscriber pattern za vise WS klijenata
|
|
||||||
- `spawnTaskPTY()` - claude --permission-mode dontAsk
|
|
||||||
|
|
||||||
### WebSocket Handler (ws.go)
|
|
||||||
- Konektuje se na postojecu PTY sesiju po kljucu
|
|
||||||
- Replay buffer na konekciju
|
|
||||||
- Bidirekcioni: PTY output -> browser, keyboard -> PTY
|
|
||||||
- Resize podrska
|
|
||||||
|
|
||||||
### Render Engine (render.go)
|
|
||||||
- Go templates sa go:embed
|
|
||||||
- Dashboard, task detail, report modal
|
|
||||||
- Markdown -> HTML sa goldmark
|
|
||||||
- Docs sa sidebar layoutom
|
|
||||||
|
|
||||||
### SSE Events (events.go)
|
|
||||||
- Event broker sa poll intervalom
|
|
||||||
- Hash task stanja za detekciju promena
|
|
||||||
- Broadcast samo kad se nesto promeni
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Dijagram toka - "Pusti" dugme
|
|
||||||
|
|
||||||
```
|
|
||||||
Browser: klik "Pusti"
|
|
||||||
|
|
|
||||||
v
|
|
||||||
POST /task/T08/run
|
|
||||||
|
|
|
||||||
v
|
|
||||||
handleRunTask:
|
|
||||||
1. Validacija (status, deps)
|
|
||||||
2. MoveTask ready -> active
|
|
||||||
3. appendTimestamp
|
|
||||||
4. Cita task sadrzaj
|
|
||||||
5. buildWorkPrompt -> temp fajl
|
|
||||||
6. startSession(T08, "work", ...)
|
|
||||||
|
|
|
||||||
v
|
|
||||||
spawnTaskPTY -> claude --permission-mode dontAsk
|
|
||||||
|
|
|
||||||
v
|
|
||||||
goroutine: ceka first output, salje prompt
|
|
||||||
|
|
|
||||||
v
|
|
||||||
JSON response {status: started, task: T08}
|
|
||||||
|
|
|
||||||
v
|
|
||||||
Browser: redirect /console
|
|
||||||
|
|
|
||||||
v
|
|
||||||
refreshSessions() -> GET /console/sessions
|
|
||||||
|
|
|
||||||
v
|
|
||||||
createTerminal(T08) -> WS /console/ws/T08
|
|
||||||
|
|
|
||||||
v
|
|
||||||
Replay buffer + live output
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Environment varijable
|
|
||||||
|
|
||||||
| Varijabla | Opis | Primer |
|
|
||||||
|-----------|------|--------|
|
|
||||||
| KAOS_PORT | HTTP port | 8080 |
|
|
||||||
| KAOS_PROJECT_PATH | Root projekta | /root/projects/KAOS |
|
|
||||||
| KAOS_TASKS_DIR | Tasks folder | /root/projects/KAOS/TASKS |
|
|
||||||
| KAOS_TIMEOUT | Timeout za agente | 300s |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Testovi
|
|
||||||
|
|
||||||
Testovi su razdvojeni po oblasti:
|
|
||||||
|
|
||||||
| Fajl | Oblast |
|
|
||||||
|------|--------|
|
|
||||||
| test_helpers_test.go | Deljeni setup i helper funkcije |
|
|
||||||
| api_test.go | REST API endpointi |
|
|
||||||
| dashboard_test.go | Dashboard HTML rendering |
|
|
||||||
| task_detail_test.go | Task detail, report, run |
|
|
||||||
| docs_test.go | Dokumenti stranica |
|
|
||||||
| search_test.go | Pretraga |
|
|
||||||
| submit_test.go | Prijava taskova |
|
|
||||||
| sse_test.go | Server-Sent Events |
|
|
||||||
| console_test.go | Konzola, sesije, prompt builderi |
|
|
||||||
| ui_test.go | UI ponasanje |
|
|
||||||
| timestamp_test.go | Vremena, PTY, RingBuffer |
|
|
||||||
| logs_test.go | Server logovi |
|
|
||||||
104
docs/SETUP.md
104
docs/SETUP.md
@ -1,104 +0,0 @@
|
|||||||
# KAOS — Setup
|
|
||||||
|
|
||||||
**Poslednje azuriranje:** 2026-02-21
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Zahtevi
|
|
||||||
|
|
||||||
- Go 1.22+
|
|
||||||
- claude CLI (instaliran i dostupan u PATH)
|
|
||||||
- Linux (PTY podrska)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Pokretanje
|
|
||||||
|
|
||||||
### 1. Build
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /root/projects/KAOS/code
|
|
||||||
go build -o kaos-server ./cmd/kaos-server/
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Environment
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export KAOS_PORT=8080
|
|
||||||
export KAOS_PROJECT_PATH=/root/projects/KAOS
|
|
||||||
export KAOS_TASKS_DIR=/root/projects/KAOS/TASKS
|
|
||||||
export KAOS_TIMEOUT=300s
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Start
|
|
||||||
|
|
||||||
```bash
|
|
||||||
nohup ./kaos-server > /tmp/kaos-server.log 2>&1 &
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Provera
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:8080/api/tasks
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Testovi
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /root/projects/KAOS/code
|
|
||||||
|
|
||||||
# Svi testovi
|
|
||||||
go test ./... -count=1
|
|
||||||
|
|
||||||
# Samo server testovi
|
|
||||||
go test ./internal/server/ -count=1 -v
|
|
||||||
|
|
||||||
# Build + vet
|
|
||||||
go build ./...
|
|
||||||
go vet ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Task folderi
|
|
||||||
|
|
||||||
```
|
|
||||||
TASKS/
|
|
||||||
├── backlog/ # Novi taskovi
|
|
||||||
├── ready/ # Odobreni za rad
|
|
||||||
├── active/ # U izradi
|
|
||||||
├── review/ # Ceka pregled
|
|
||||||
├── done/ # Zavrseno
|
|
||||||
└── reports/ # Izvestaji
|
|
||||||
```
|
|
||||||
|
|
||||||
Svaki task je markdown fajl (npr. `T08.md`).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Struktura task fajla
|
|
||||||
|
|
||||||
```markdown
|
|
||||||
# T08: Naziv taska
|
|
||||||
|
|
||||||
**Kreirao:** planer
|
|
||||||
**Datum:** 2026-02-20
|
|
||||||
**Agent:** coder
|
|
||||||
**Model:** Sonnet
|
|
||||||
**Zavisi od:** T07
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Opis
|
|
||||||
|
|
||||||
Sta treba da se uradi.
|
|
||||||
|
|
||||||
## Vremena
|
|
||||||
|
|
||||||
| Dogadjaj | Vreme |
|
|
||||||
|---------|-------|
|
|
||||||
| Odobren (->ready) | 2026-02-20 14:00 |
|
|
||||||
| Pokrenut (->active) | 2026-02-20 14:05 |
|
|
||||||
```
|
|
||||||
106
docs/SPEC.md
106
docs/SPEC.md
@ -1,106 +0,0 @@
|
|||||||
# KAOS — Specifikacija
|
|
||||||
|
|
||||||
**Verzija:** 0.3.0
|
|
||||||
**Poslednje azuriranje:** 2026-02-21
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Pregled
|
|
||||||
|
|
||||||
KAOS je sistem za razvoj softvera sa AI agentima pod ljudskim nadzorom.
|
|
||||||
Web dashboard omogucava operateru da upravlja taskovima, pokrece claude agente,
|
|
||||||
i prati rad u realnom vremenu kroz konzolne terminale.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Funkcionalnosti
|
|
||||||
|
|
||||||
### Kanban Board
|
|
||||||
- 5 kolona: Backlog, Ready, Active, Review, Done
|
|
||||||
- Drag & drop premestanje taskova (Sortable.js)
|
|
||||||
- SSE auto-refresh kad se stanje promeni
|
|
||||||
- Dugmad po statusu: Odobri, Pusti, Proveri, Izvestaj
|
|
||||||
- Task detail modal sa markdown renderovanjem
|
|
||||||
|
|
||||||
### Konzola (Task PTY Sessions)
|
|
||||||
- Svaki task dobija sopstvenu claude CLI sesiju u PTY
|
|
||||||
- "Pusti" dugme: premesta task u active, pokrece interaktivni claude
|
|
||||||
- "Proveri" dugme: pokrece review claude sesiju za task u review/
|
|
||||||
- Terminali u browseru via xterm.js + WebSocket
|
|
||||||
- Replay buffer (1MB ring buffer) za reconnect
|
|
||||||
- Sesije prezivljavaju page reload
|
|
||||||
- Dinamicko dodavanje/brisanje terminala po aktivnim sesijama
|
|
||||||
- Kill dugme za zavrsavanje sesije
|
|
||||||
|
|
||||||
### Pretraga
|
|
||||||
- Pretrazuje taskove, dokumente i izvestaje
|
|
||||||
- Case-insensitive, sa snippet kontekstom
|
|
||||||
- Real-time rezultati (htmx delay:300ms)
|
|
||||||
|
|
||||||
### Dokumenti
|
|
||||||
- Pregled svih .md fajlova u projektu
|
|
||||||
- Sidebar + main layout
|
|
||||||
- Markdown renderovanje sa tabelama
|
|
||||||
- Breadcrumbs navigacija
|
|
||||||
- HTMX fragmenti za client-side navigaciju
|
|
||||||
|
|
||||||
### Prijava taskova
|
|
||||||
- Klijent mod: jednostavna forma (naslov + opis + prioritet)
|
|
||||||
- Operater mod: chat sa claude CLI za kreiranje taska
|
|
||||||
|
|
||||||
### Server logovi
|
|
||||||
- GET /api/logs/tail - poslednjih 100 linija loga
|
|
||||||
- Modal prikaz na dashboardu
|
|
||||||
|
|
||||||
### Vremena (Timestamps)
|
|
||||||
- Svaki prelaz taska belexi timestamp u Vremena tabelu
|
|
||||||
- Automatski u task .md fajl
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Task workflow
|
|
||||||
|
|
||||||
```
|
|
||||||
backlog --> ready --> active --> review --> done
|
|
||||||
| | |
|
|
||||||
<---------- |
|
|
||||||
<-------------------
|
|
||||||
```
|
|
||||||
|
|
||||||
| Prelaz | Ko | Kako |
|
|
||||||
|--------|----|------|
|
|
||||||
| backlog -> ready | operater | Odobri dugme |
|
|
||||||
| ready -> active | server | Pusti dugme (automatski) |
|
|
||||||
| active -> review | claude agent | Kad zavrsi rad |
|
|
||||||
| review -> done | operater/checker | Odobri ili Proveri |
|
|
||||||
| review -> active | operater/checker | Vrati na doradu |
|
|
||||||
| ready -> backlog | operater | Vrati dugme |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## API endpointi
|
|
||||||
|
|
||||||
| Metod | Putanja | Opis |
|
|
||||||
|-------|---------|------|
|
|
||||||
| GET | / | Dashboard (Kanban) |
|
|
||||||
| GET | /api/tasks | Svi taskovi (JSON) |
|
|
||||||
| GET | /api/task/:id | Detalj taska (JSON) |
|
|
||||||
| POST | /api/task/:id/move?to= | Premesti task |
|
|
||||||
| GET | /task/:id | Task detail (HTML) |
|
|
||||||
| POST | /task/:id/move?to= | Premesti + vrati board |
|
|
||||||
| POST | /task/:id/run | Pusti task (active + claude) |
|
|
||||||
| POST | /task/:id/review | Pokreni review sesiju |
|
|
||||||
| GET | /report/:id | Izvestaj/task modal |
|
|
||||||
| GET | /events | SSE stream |
|
|
||||||
| GET | /search?q= | Pretraga |
|
|
||||||
| GET | /console | Konzola stranica |
|
|
||||||
| GET | /console/sessions | Aktivne sesije (JSON) |
|
|
||||||
| POST | /console/kill/:taskID | Ubij sesiju |
|
|
||||||
| GET | /console/ws/:key | WebSocket terminal |
|
|
||||||
| GET | /api/logs/tail | Server logovi |
|
|
||||||
| GET | /docs | Lista dokumenata |
|
|
||||||
| GET | /docs/*path | Pregled dokumenta |
|
|
||||||
| GET | /submit | Prijava stranica |
|
|
||||||
| POST | /submit/simple | Prijava forme |
|
|
||||||
| POST | /submit/chat | Operater chat |
|
|
||||||
| GET | /submit/chat/stream/:id | Chat SSE stream |
|
|
||||||
Loading…
Reference in New Issue
Block a user