Commit Graph

7 Commits

Author SHA1 Message Date
egutierrez 9cade2f2f8 fix(crash): init data_table State.col_visible + col_order before render
Pressing Refresh Agents (or Test Connection — both trigger fetch + table
re-render) crashed the app with Windows exit code 5 (access violation).

Root cause: agents_tbl_state was default-constructed, so
State.col_visible (std::vector<bool>) and State.col_order
(std::vector<int>) were empty. render_grid_stage0 indexes them by column
index up to N_COLS=11 without bounds checking → undefined behaviour →
segfault on the first render after agents data populated.

Fix: at first render of the agents panel, assign col_visible=true * N_COLS,
fill col_order with [0..N_COLS), and ensure stages.size() >= 1. Same
pattern tql_apply.cpp uses (col_visible.assign(eff_cols, true)).

Diagnostic infra added (kept in place — minimal overhead):
- FN_DBG macro: fprintf(stderr, ...) + fflush. Survives crashes that
  fn_log's buffered file output doesn't.
- --auto-refresh CLI flag: triggers fetch_agents_async at frame 30,
  auto-exits at frame 180 (~3s @ 60Hz). Headless smoke for CI.
- DBG breadcrumbs through main → load_apikey → fn::run_app → render →
  fetch_agents_async (thread enter/request/response/parse/exit) → render
  table (pre/post). Each step flushes stderr immediately.

E2E regression guard: test_app_survives_auto_refresh_cycle. Runs the .exe
with --auto-refresh, asserts exit 0, asserts the breadcrumb chain reaches
both "fetch thread parsed" and "agents_panel POST-render" in stderr. 25
tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 23:31:25 +02:00
egutierrez 18b5ffdfd9 feat(apikey): auto-fetch from pass agentes/api-key when env empty
Launching from the App Hub (or any double-click) no longer needs
AGENTS_API_KEY manually injected. Order of resolution:

  1. AGENTS_API_KEY env var          → apikey_source = "env"
  2. `pass agentes/api-key` shell    → apikey_source = "pass"
  3. neither                          → apikey_source = "missing"

On Windows the fallback shells via `wsl.exe -e sh -c "pass ... | head -n1"`
so the secret stays in the WSL user's GnuPG keychain (never copied to a
Windows file). On Linux it's a direct popen of `pass ...`.

Failure mode: GPG agent locked → empty output → "missing" state in UI
with a "Retry pass" button (user runs `pass agentes/api-key` once to
unlock the agent, clicks Retry, app refetches without restart).

Connection panel shows the active source:
  ✓ loaded from AGENTS_API_KEY env var
  ✓ loaded via `pass agentes/api-key`
  ⚠ apikey not found (env empty + pass failed)

--connect-test uses the same two-tier resolution so e2e exercises the
production code path.

E2E: renamed test_connect_fails_without_apikey →
test_connect_falls_back_to_pass_when_env_empty. Verifies that with
empty env, the .exe still returns OK N. Skips if `pass` is locked.

All 24 tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 23:16:22 +02:00
egutierrez c8b7adf81d feat(0131): data_table_cpp_viz migration + botones acción + 7 nuevos tests e2e
Issue 0131 (agents v0.2) — frontend agents_dashboard:

* Migra tabla Agents de ImGui::BeginTable a render_grid_stage0 (data_table_cpp_viz).
  11 columnas: Status(Badge), ID, Name, Uptime, Msg/24h,
  Start/Stop/Restart/Clear Memory/Del Cache/Logs (Button renderers).
* Lee campos reales uptime_seconds + messages_24h del backend (antes leía
  'instances' como proxy para msg_24h; ahora lee el campo correcto).
* Confirmation modal (ImGui::BeginPopupModal) para acciones destructivas
  clear_memory y delete_cache.
* Link fn_module_data_table en CMakeLists (HAS_DATA_TABLE activado).
* Actualiza app.md: data_table_cpp_viz en uses_functions, version 0.2.0.
* Añade 7 tests pytest nuevos (total 24):
  test_uptime_field_present, test_msg_24h_field_present,
  test_clear_memory_requires_apikey, test_delete_cache_requires_apikey,
  test_control_roundtrip, test_unified_stop_does_not_kill_launcher,
  test_clear_memory_response_shape.
  SEGURIDAD: solo test-bot se para/arranca en e2e, nunca agentes reales.

Build verificado: Linux + Windows cross-compile (cmake --build cpp/build/windows).

Co-Authored-By: fn-orquestador (issue 0131) <noreply@fn-registry>
2026-05-22 23:07:01 +02:00
egutierrez b61626b759 fix(ui): parse running/enabled into status; expand e2e to 13 tests
Backend /agents response shape: {id, name, version, desc, enabled: bool,
running: bool, pid, instances, config_path}. parse_agents() was reading
nonexistent fields "status", "uptime_seconds", "messages_24h" so the
table showed every agent as "unknown".

Derive status from running + enabled:
  running=true                  → "running"
  running=false, enabled=false  → "disabled"
  running=false, enabled=true   → "stopped"

E2E suite now covers (13 tests, all passing in ~9s):
- connect happy + bad-host + missing-apikey + URL-trim
- shape contract (id/name/running/enabled present + bool)
- SSE smoke: /sse/status and /sse/agents/{id}/logs must NOT return
  "streaming unsupported" (depends on backend statusWriter.Flush fix
  shipped in agents_and_robots master 4822208)
- auth boundary: /health no-auth, /agents 401 sin Bearer + 401 con key falsa
- control: POST /agents/test-bot/start returns valid JSON
- detail: GET /agents/{id} returns id + logs[]

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 22:34:57 +02:00
egutierrez ea3c62d2f2 feat(agents_dashboard): apikey via env (pass agentes/api-key), e2e tests
Security: apikey NUNCA mas vive en local DB ni se introduce por UI.
Se lee al arranque via getenv("AGENTS_API_KEY"), sourced typically con
`pass agentes/api-key` antes de lanzar el .exe.

Connection panel:
- Removed apikey TextInput (+show/hide button)
- Removed UI mask flag
- Replaced con indicador "loaded from env" verde / "missing" rojo
- Hint visible: "Launch with: AGENTS_API_KEY=$(pass agentes/api-key) <exe>"

Persistencia local:
- db_save_connection: solo base_url (blob de apikey ya no se cifra)
- db_load_connection: solo base_url
- No mas roundtrip a fn_secret en runtime de la UI (la funcion del
  registry secret_store_cpp_infra sigue util para otras apps)

CLI:
- --connect-test <url> ahora lee apikey de AGENTS_API_KEY env var
- trim_url() en make_url + en CLI defensivo contra paste con CR/LF
- run_self_test sin cambios (secret_store roundtrip se mantiene)

E2E tests (tests/test_connect_e2e.py, 5 casos):
- test_connect_succeeds_with_valid_apikey
- test_connect_fails_without_apikey
- test_connect_fails_on_bad_host
- test_count_matches_direct_curl
- test_url_trim_robust_to_whitespace

Lanzar con:
  AGENTS_API_KEY=$(pass agentes/api-key) \
    python3 -m pytest -v tests/test_connect_e2e.py

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 22:15:55 +02:00
fn-orquestador 460b7f1484 fix: build errors — nlohmann include path, fn_log printf style, crypt32 link
- Fix nlohmann include: 'vendor/nlohmann/json.hpp' -> 'nlohmann/json.hpp'
  (cpp/vendor is in include path, no double-vendor prefix needed)
- Fix fn_log API: log_info/log_warn/log_error (not info/warn/error)
- Fix format strings: {} -> %s (logger uses printf-style, not fmtlib)
- CMakeLists: add crypt32 link for Windows DPAPI (MinGW needs explicit link,
  #pragma comment(lib) only works with MSVC)
- Build: exit 0, exe 22MB, .rsrc section present (icon embedded)

Issue: 0129
Co-Authored-By: fn-orquestador <noreply@fn-registry.local>
2026-05-22 21:47:39 +02:00
fn-orquestador 8795f2842b feat: initial implementation of agents_dashboard v0.1.0
Panels: Connection + Agents + Logs + Status Feed.
- HTTP GET /agents + POST /agents/{id}/{start,stop,restart}
- SSE streaming: /sse/agents/{id}/logs + /sse/status
- DPAPI/XOR credential storage in local_files/agents_dashboard.db
- data_table style agents table with filter + status icons
- SQLite migrations via sqlite3_exec at startup
- --self-test mode: db + secret_store round-trip + subsystem checks
- pytest mock server emulating agents_and_robots API

Registry functions: http_request_cpp_core, sse_client_cpp_core,
  secret_store_cpp_infra, logger_cpp_core
App icon: robot phosphor violet-500 (#8b5cf6)

Issue: 0129
Co-Authored-By: fn-orquestador <noreply@fn-registry.local>
2026-05-22 21:42:54 +02:00