Files
Egutierrez c468b24d2b feat(0130): kanban_cpp v2 — backend Go + 5 registry parser fns + epic/sub-issues
Registry (issue 0130a):
- 5 fns infra: parse_issue_md, write_issue_md, scan_issues_dir,
  scan_flows_dir, watch_dir_fsnotify
- 3 tipos: Issue, Flow, FsEvent
- Tests round-trip + scan reales + watcher fsnotify (all PASS)
- Capability group 'kanban' nuevo (docs/capabilities/kanban.md)

Apps:
- apps/kanban_cpp/ (sub-repo) — frontend ImGui: board drag-drop,
  flows, filters, detail con CSV editors
- apps/kanban_cpp/backend/ — Go service port 8487: REST + SSE +
  fsnotify watcher, parser bidireccional MD<->SQLite cache

Issues:
- dev/issues/0130-kanban-cpp-v2.md (epic)
- 0130a parser, 0130b backend, 0130c frontend

CMakeLists.txt: add_subdirectory apps/kanban_cpp (registrado por
init_cpp_app scaffolder).

End-to-end verde: backend devuelve 189 issues + 9 flows; PATCH a
/api/issues/{id} reescribe .md (solo frontmatter, body intacto);
frontend --self-test exit 0; tests Go infra 5/5 PASS.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 22:20:15 +02:00

84 lines
1.9 KiB
Go

package infra
import (
"fmt"
"log"
"os"
"path/filepath"
"sort"
"strings"
"gopkg.in/yaml.v3"
)
// ScanFlowsDir escanea el directorio root (dev/flows/) y devuelve todos los Flows
// encontrados en *.md directos.
// Si un archivo falla al parsearse, se emite un warning al log y se continua.
// Los flows se devuelven ordenados por ID ascendente.
func ScanFlowsDir(root string) ([]Flow, error) {
matches, err := filepath.Glob(filepath.Join(root, "*.md"))
if err != nil {
return nil, fmt.Errorf("scan_flows_dir: glob: %w", err)
}
var flows []Flow
for _, path := range matches {
base := filepath.Base(path)
if strings.EqualFold(base, "INDEX.md") || strings.EqualFold(base, "README.md") || strings.EqualFold(base, "AGENT_GUIDE.md") {
continue
}
info, err := os.Stat(path)
if err != nil || !info.Mode().IsRegular() {
continue
}
f, err := parseFlowMd(path)
if err != nil {
log.Printf("scan_flows_dir: warning: skip %s: %v", path, err)
continue
}
flows = append(flows, f)
}
sort.Slice(flows, func(i, j int) bool {
return flows[i].ID < flows[j].ID
})
return flows, nil
}
// parseFlowMd parsea el frontmatter de un archivo dev/flows/*.md en un struct Flow.
func parseFlowMd(path string) (Flow, error) {
data, err := os.ReadFile(path)
if err != nil {
return Flow{}, fmt.Errorf("read %s: %w", path, err)
}
info, err := os.Stat(path)
if err != nil {
return Flow{}, fmt.Errorf("stat %s: %w", path, err)
}
fm, _, err := splitFrontmatter(data)
if err != nil {
return Flow{}, fmt.Errorf("frontmatter %s: %w", path, err)
}
var f Flow
if err := yaml.Unmarshal(fm, &f); err != nil {
return Flow{}, fmt.Errorf("yaml %s: %w", path, err)
}
// Algunos flows usan "name" y no "title" — normalizar
if f.Title == "" && f.Name != "" {
f.Title = f.Name
}
// Algunos flows usan entero como ID en el YAML — yaml.v3 lo convierte a string OK
f.FilePath = path
f.MtimeNs = info.ModTime().UnixNano()
return f, nil
}