chore: auto-commit (97 archivos)

- .claude/CLAUDE.md
- .claude/agents/fn-recopilador/SKILL.md
- .claude/rules/INDEX.md
- .claude/rules/cpp_apps.md
- bash/functions/infra/build_cpp_windows.sh
- cpp/CMakeLists.txt
- cpp/PATTERNS.md
- cpp/framework/app_base.cpp
- cpp/framework/app_base.h
- dev/issues/README.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 18:11:24 +02:00
parent 852322a708
commit 750b7abcd5
99 changed files with 7879 additions and 73 deletions
+25
View File
@@ -295,6 +295,14 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/apps/text_editor_smoke/CMakeLists.txt)
add_subdirectory(apps/text_editor_smoke)
endif()
# --- AltSnap viewport-jitter regression test ---
# Headless harness que conduce glfwSetWindowPos cada frame y verifica que
# ImGui viewport->Pos sigue al OS dentro de 1px. Sin la patch del framework
# (callback GLFW + per-frame sync) este test falla exit=1.
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/apps/altsnap_jitter_test/CMakeLists.txt)
add_subdirectory(apps/altsnap_jitter_test)
endif()
# --- Registry Dashboard (lives in projects/fn_monitoring/apps/) ---
# _DASH_DIR puede sobreescribirse via -D_DASH_DIR=<path> para apuntar a un
# worktree (parallel-fix-issues u otros flujos que aislen builds).
@@ -315,6 +323,23 @@ if(EXISTS ${_GE_DIR}/CMakeLists.txt)
add_subdirectory(${_GE_DIR} ${CMAKE_BINARY_DIR}/apps/graph_explorer)
endif()
# --- odr_console (lives in projects/online_data_recopilation/apps/) ---
if(NOT DEFINED _ODR_DIR)
set(_ODR_DIR ${CMAKE_SOURCE_DIR}/../projects/online_data_recopilation/apps/odr_console)
endif()
if(EXISTS ${_ODR_DIR}/CMakeLists.txt)
add_subdirectory(${_ODR_DIR} ${CMAKE_BINARY_DIR}/apps/odr_console)
endif()
# --- navegator_dashboard (lives in projects/navegator/apps/) ---
# Windows-only — el propio CMakeLists.txt hace return() en non-WIN32.
if(NOT DEFINED _NAVD_DIR)
set(_NAVD_DIR ${CMAKE_SOURCE_DIR}/../projects/navegator/apps/navegator_dashboard)
endif()
if(EXISTS ${_NAVD_DIR}/CMakeLists.txt)
add_subdirectory(${_NAVD_DIR} ${CMAKE_BINARY_DIR}/apps/navegator_dashboard)
endif()
# --- Tests (Catch2 amalgamated, ctest-driven) ---
option(BUILD_TESTING "Build C++ tests" ON)
if(BUILD_TESTING)
+12 -5
View File
@@ -22,8 +22,13 @@ Antes de mergear una app, verificar uno por uno:
};
```
Pasarlo a `AppConfig::panels` + `AppConfig::panel_count = 2`.
- [ ] **Layouts persistentes** (si aplica). Si la app guarda layouts:
implementa `fn_ui::LayoutCallbacks` y pasalas en `AppConfig::layouts_cb`.
- [ ] **Layouts persistentes**. Vienen activos por defecto: `fn::run_app` abre
un `LayoutStorage` SQLite en `<exe_dir>/local_files/layouts.db` y enchufa
el menu Layouts (Save / Apply / Delete / Reset) sin codigo. La app solo
pasa `AppConfig::layouts_cb` si quiere personalizar (ej. on_reset que
restaure paneles especificos como en `shaders_lab`). Para apagar el
auto-storage: `cfg.auto_layouts = false`. Para cambiar el nombre del
archivo: `cfg.auto_layouts_db = "myapp_layouts.db"`.
- [ ] **GL loader** (si la app usa OpenGL >= 2.0 directamente). Pasar
`AppConfig::init_gl_loader = true` para que `fn::run_app()` llame
`fn::gfx::gl_loader_init()` tras crear el contexto.
@@ -86,9 +91,11 @@ int main() {
}
```
Con esto la app obtiene gratis: MainMenuBar (View/Settings/About), ventana About,
ventana Settings, FPS overlay configurable, theming `FnDark`, fuentes vectoriales
+ iconos Tabler mergeados, multi-viewport opcional.
Con esto la app obtiene gratis: MainMenuBar (View/**Layouts**/Settings/About),
ventana About, ventana Settings, ventana Logs, FPS overlay configurable, theming
`FnDark`, fuentes vectoriales + iconos Tabler mergeados, multi-viewport opcional,
**y persistencia de layouts ImGui en `<exe_dir>/local_files/layouts.db`** sin
escribir una linea de codigo.
## Anti-patrones
Submodule cpp/apps/altsnap_jitter_test added at 64a01defbc
+80 -5
View File
@@ -13,6 +13,7 @@
#include "core/fps_overlay.h"
#include "core/logger.h"
#include "core/log_window.h"
#include "core/layout_storage.h"
#include "gfx/gl_loader.h"
#include <GLFW/glfw3.h>
@@ -203,6 +204,27 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
glfwMakeContextCurrent(window);
glfwSwapInterval(config.vsync ? 1 : 0);
// Anti-jitter: when the OS moves/resizes the window externally (Windows
// tools like AltSnap, tiling WMs, snap-assist), ImGui's viewport pos can
// lag one frame and `UpdatePlatformWindows` reapplies the stale value via
// glfwSetWindowPos, fighting the OS and producing visible jitter.
// Updating the viewport struct directly from the GLFW callback closes the
// loop in the same tick — no stale Pos can ever reach the platform sync.
// ImGui_ImplGlfw_InitForOpenGL does NOT install pos/size callbacks, so we
// can install ours without breaking the backend's own callback chain.
glfwSetWindowPosCallback(window, [](GLFWwindow* w, int x, int y) {
if (ImGui::GetCurrentContext() == nullptr) return;
if (ImGuiViewport* vp = ImGui::FindViewportByPlatformHandle(w)) {
vp->Pos = ImVec2((float)x, (float)y);
}
});
glfwSetWindowSizeCallback(window, [](GLFWwindow* w, int cx, int cy) {
if (ImGui::GetCurrentContext() == nullptr) return;
if (ImGuiViewport* vp = ImGui::FindViewportByPlatformHandle(w)) {
vp->Size = ImVec2((float)cx, (float)cy);
}
});
// Carga punteros a funciones GL >= 2.0 si la app lo pide. En Linux es
// no-op; en Windows usa wglGetProcAddress (requiere ctx GL activo).
if (config.init_gl_loader) {
@@ -241,6 +263,25 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
// fuentes. Si no existe el .ini, los defaults se aplican.
fn_ui::settings_load();
// Auto-wiring del menu Layouts: si la app no proporciono layouts_cb y no
// ha desactivado auto_layouts, abrimos un LayoutStorage por defecto con
// SQLite en `<local_dir>/<auto_layouts_db>` y generamos los callbacks
// estandar (list/save/apply/delete/reset). Asi toda app C++ obtiene el
// menu Layouts gratis sin codigo.
fn_ui::LayoutStorage* auto_layouts_storage = nullptr;
fn_ui::LayoutCallbacks auto_layouts_cb;
if (config.layouts_cb == nullptr && config.auto_layouts) {
const char* db_name = (config.auto_layouts_db && *config.auto_layouts_db)
? config.auto_layouts_db : "layouts.db";
auto_layouts_storage = fn_ui::layout_storage_open(local_path(db_name));
if (auto_layouts_storage) {
fn_ui::layout_storage_make_callbacks(auto_layouts_storage, auto_layouts_cb);
config.layouts_cb = &auto_layouts_cb;
} else {
fn_log::log_warn("auto_layouts: layout_storage_open fallo (%s)", db_name);
}
}
// Registra info de la ventana About si la app la proveyo en AppConfig.
if (config.about.name != nullptr) {
fn_ui::about_window_set_info(
@@ -294,6 +335,25 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
continue;
}
// Anti-jitter pass 2: covers secondary viewport windows that the
// backend creates dynamically (panels dragged outside the main).
// Sync each viewport's Pos/Size to the OS-reported state BEFORE
// NewFrame, so ImGui logic this tick already sees the up-to-date
// values and UpdatePlatformWindows can't stomp them with stale data.
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGuiPlatformIO& pio = ImGui::GetPlatformIO();
for (int i = 0; i < pio.Viewports.Size; ++i) {
ImGuiViewport* vp = pio.Viewports[i];
if (!vp || !vp->PlatformHandle) continue;
GLFWwindow* gw = (GLFWwindow*)vp->PlatformHandle;
int x = 0, y = 0, cx = 0, cy = 0;
glfwGetWindowPos(gw, &x, &y);
glfwGetWindowSize(gw, &cx, &cy);
vp->Pos = ImVec2((float)x, (float)y);
vp->Size = ImVec2((float)cx, (float)cy);
}
}
// Tamaño de fuente: aplica via style.FontSizeBase cada frame. Cambios
// se ven al instante (ImGui 1.92+ escala el atlas dinamicamente, no
// hace falta rebuild).
@@ -313,11 +373,20 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Menubar canonica (View / Layouts / Settings / About) si la app la
// configuro en AppConfig. Se renderiza ANTES del render_fn para que
// el render_fn pueda hacer DockSpaceOverViewport debajo.
if (config.panels != nullptr || config.layouts_cb != nullptr ||
(bool)config.view_extras) {
// Si auto_layouts esta gestionando el storage, aplica el layout
// pendiente ANTES de que el render_fn cree ventanas. Si la app gestiona
// su propio storage, debe llamar layout_storage_apply_pending ella misma
// dentro de render_fn (patron que ya usan shaders_lab y graph_explorer).
if (auto_layouts_storage) {
std::string applied = fn_ui::layout_storage_apply_pending(auto_layouts_storage);
if (!applied.empty()) auto_layouts_cb.active_name = applied;
}
// Menubar canonica (View / Layouts / Settings / About) — siempre se
// renderiza para que Settings/Logs/About esten disponibles aunque la
// app no declare panels/layouts/view_extras propios. Se dibuja ANTES
// del render_fn para que pueda hacer DockSpaceOverViewport debajo.
{
// Adapter: std::function<bool()> -> ViewMenuExtrasFn(void*).
fn_ui::ViewMenuExtrasFn extras_fn = nullptr;
void* extras_user = nullptr;
@@ -380,6 +449,12 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
fn_log::logger_close();
}
// Cierra el storage de layouts auto-creado, si lo hay.
if (auto_layouts_storage) {
fn_ui::layout_storage_close(auto_layouts_storage);
auto_layouts_storage = nullptr;
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
+16
View File
@@ -113,8 +113,24 @@ struct AppConfig {
// Callbacks de layouts persistentes. Si layouts_cb != nullptr, run_app
// llama fn_ui::app_menubar(panels, panel_count, layouts_cb) cada frame.
// Si layouts_cb == nullptr y auto_layouts == true (default), run_app abre
// un fn_ui::LayoutStorage por defecto sobre `<local_dir>/<auto_layouts_db>`,
// genera unos LayoutCallbacks estandar (save/load/list/delete/reset),
// los aplica al inicio de cada frame y los cierra al salir. Asi cualquier
// app obtiene el menu Layouts gratis sin tocar codigo.
fn_ui::LayoutCallbacks* layouts_cb = nullptr;
// Auto-wiring del menu Layouts cuando layouts_cb == nullptr.
// - true (default): run_app crea LayoutStorage interno con SQLite.
// - false: no se crea storage. Util si la app no quiere persistencia
// (ej. demo headless, capture mode).
bool auto_layouts = true;
// Nombre del archivo SQLite (relativo a `<exe_dir>/local_files/`) usado
// por el layout storage por defecto. Solo se consulta si layouts_cb es
// nullptr y auto_layouts es true. Default "layouts.db".
const char* auto_layouts_db = "layouts.db";
// Items extra dentro del menu "View", al final tras los toggles de
// paneles. Si view_extras != nullptr, run_app lo pasa a app_menubar.
// El callback se invoca dentro de un BeginMenu("View") ya abierto:
+66
View File
@@ -0,0 +1,66 @@
#include "job_cache_sha256.h"
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <sstream>
namespace fs = std::filesystem;
namespace fn::cache_sha256 {
namespace {
std::string subdir_for(const std::string& key) {
return key.size() >= 2 ? key.substr(0, 2) : key;
}
} // namespace
std::string path_for(const std::string& root,
const std::string& key,
const std::string& suffix) {
fs::path p = fs::path(root) / subdir_for(key) / (key + suffix);
return p.string();
}
bool ensure_dir(const std::string& root, const std::string& key) {
std::error_code ec;
fs::path dir = fs::path(root) / subdir_for(key);
fs::create_directories(dir, ec);
return !ec;
}
bool read(const std::string& root,
const std::string& key,
const std::string& suffix,
std::string* out) {
if (!out) return false;
std::ifstream f(path_for(root, key, suffix), std::ios::binary);
if (!f.is_open()) return false;
std::ostringstream ss;
ss << f.rdbuf();
*out = ss.str();
return f.good() || f.eof();
}
bool write(const std::string& root,
const std::string& key,
const std::string& suffix,
const std::string& bytes) {
if (!ensure_dir(root, key)) return false;
std::ofstream f(path_for(root, key, suffix),
std::ios::binary | std::ios::trunc);
if (!f.is_open()) return false;
f.write(bytes.data(), (std::streamsize)bytes.size());
return f.good();
}
bool exists(const std::string& root,
const std::string& key,
const std::string& suffix) {
std::error_code ec;
return fs::exists(path_for(root, key, suffix), ec) && !ec;
}
} // namespace fn::cache_sha256
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include <string>
// job_cache_sha256 — addressable cache layout helper.
//
// Layout:
// <root>/<key[0:2]>/<key><suffix>
//
// El caller calcula el `key` (tipicamente SHA-256 hex de algun valor
// canonico — URL, parametros, etc.). Esta funcion no hashea: solo
// gestiona el path y la I/O.
//
// Suffix permite multiples blobs por la misma key (`.html`, `.md`,
// `.json`). Pasa "" si solo hay un blob.
namespace fn::cache_sha256 {
// Pure. Devuelve "<root>/<key[0:2]>/<key><suffix>". No toca disco.
// Si key tiene menos de 2 caracteres, usa la key entera como subdir.
std::string path_for(const std::string& root,
const std::string& key,
const std::string& suffix = "");
// Impure. Crea el directorio `<root>/<key[0:2]>/` si no existe.
// Devuelve true en exito. No falla si ya existe.
bool ensure_dir(const std::string& root, const std::string& key);
// Impure. Lee el archivo en `path_for(root, key, suffix)` entero.
// Devuelve true si existia y se leyo; false en caso contrario.
bool read(const std::string& root,
const std::string& key,
const std::string& suffix,
std::string* out);
// Impure. Escribe `bytes` en `path_for(root, key, suffix)`. Crea el
// directorio padre si no existe. Devuelve true en exito.
bool write(const std::string& root,
const std::string& key,
const std::string& suffix,
const std::string& bytes);
// Impure. true si el archivo existe en `path_for(root, key, suffix)`.
bool exists(const std::string& root,
const std::string& key,
const std::string& suffix);
} // namespace fn::cache_sha256
+70
View File
@@ -0,0 +1,70 @@
---
name: job_cache_sha256
kind: function
lang: cpp
domain: infra
version: "1.0.0"
purity: impure
signature: "std::string fn::cache_sha256::path_for(const std::string& root, const std::string& key, const std::string& suffix = \"\"); bool fn::cache_sha256::ensure_dir(const std::string& root, const std::string& key); bool fn::cache_sha256::read(const std::string& root, const std::string& key, const std::string& suffix, std::string* out); bool fn::cache_sha256::write(const std::string& root, const std::string& key, const std::string& suffix, const std::string& bytes); bool fn::cache_sha256::exists(const std::string& root, const std::string& key, const std::string& suffix)"
description: "Cache addressable con layout '<root>/<key[0:2]>/<key><suffix>'. El caller hashea (tipicamente SHA-256 hex), esta funcion gestiona path + I/O. Suffix opcional permite multiples blobs por key (.html, .md, .json). Pieza extraida del jobs system de graph_explorer (issue 0026/0027) para reuso entre apps C++ que recolectan datos online."
tags: [cache, sha256, addressable, jobs, fs, scraping]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [string, cstdio, filesystem, fstream, sstream]
tested: false
tests: []
test_file_path: ""
file_path: "cpp/functions/infra/job_cache_sha256.cpp"
framework: ""
params:
- name: root
desc: "Directorio raiz del cache. Tipicamente <app_dir>/local_files/cache/. La funcion crea subdirectorios on-demand."
- name: key
desc: "Clave de cache. Tipicamente SHA-256 hex (64 chars) de un valor canonico (URL, hash de params). El caller calcula el hash."
- name: suffix
desc: "Sufijo del archivo. Permite multiples blobs por la misma key. Ejemplos: '.html', '.md', '.json'. Pasa '' si solo hay un blob por key."
- name: out
desc: "Buffer de salida para read(). Recibe los bytes del archivo. Devuelve false si no existia."
- name: bytes
desc: "Contenido a escribir en write(). Se trata como binario (no se anade newline ni se interpreta)."
output: "path_for: string con el path absoluto. ensure_dir/read/write/exists: bool true en exito; read tambien rellena out. Ningun error_type custom — fallo de fs se traduce a false (ver fstream/filesystem para detalles)."
notes: "1) Pure: solo path_for. Resto impuro (toca filesystem). 2) Layout compatible con el cache que ya usan los enrichers Python de graph_explorer (`<cache_dir>/<sha[0:2]>/<sha>.{html,md}`), por lo que apps C++ pueden leer blobs escritos por subprocess Python sin migrar formato. 3) Si el caller necesita SHA-256 propio, anadir funcion separada `sha256_hex_cpp_core` (no implementada aun)."
documentation: "Pieza minima del refactor de issue 0065. El cache es un helper standalone que cualquier app C++ que recolecte datos online puede usar para evitar refetchear. odr_console (issue 0066) lo usa via la cache_dir que pasa al subprocess Python en stdin JSON, manteniendo compatibilidad con enrichers existentes."
example: |
#include "cpp/functions/infra/job_cache_sha256.h"
#include <openssl/sha.h> // o cualquier impl SHA-256
std::string url = "https://example.com/data.json";
// Hash de la URL como key (usuario provee la impl).
std::string key = sha256_hex(url);
std::string root = "/path/to/app/local_files/cache";
if (!fn::cache_sha256::exists(root, key, ".json")) {
std::string body = fetch_http(url);
fn::cache_sha256::write(root, key, ".json", body);
}
std::string cached;
if (fn::cache_sha256::read(root, key, ".json", &cached)) {
// ... usar cached ...
}
---
## Notas
Helper de I/O addressable. No hace SHA-256 — el caller provee la key (normalmente hex). Layout `<root>/<key[0:2]>/<key><suffix>` es identico al que usan los enrichers de graph_explorer en sus `run.py`, por lo que C++ y Python pueden leer/escribir el mismo cache.
### Decisiones de diseño
- **Hash fuera de la funcion**: separar el hashing del path-handling deja el modulo libre de dependencias criptograficas. Si una app prefiere blake3, xxhash o md5 para keys mas cortas, esta funcion sigue valiendo.
- **Suffix opcional**: enrichers de graph_explorer guardan dos blobs por URL (`.html` y `.md`); odr_console probablemente guarde `.json`/`.parquet`. Suffix unifica casos.
- **Sin SQLite**: cache es solo files. Si una app necesita metadata por entry (TTL, last-access, content-type), eso vive en operations.db o en una tabla aparte.
- **Layout compatible**: identico al Python `cache_paths()` en `enrichers/fetch_webpage/run.py`. C++ puede leer blobs escritos por enrichers Python y viceversa.
### Que NO incluye
- No incluye SHA-256 ni ningun hash. Caller responsable.
- No incluye TTL ni eviction. Implementar fuera si se necesita.
- No incluye locking entre procesos. Si dos workers escriben la misma key concurrente, ultimo gana — para invalidacion atomica usar nombre temporal + rename.