7a94160fd2
Bloque de cambios revisados y validados con el usuario en sesiones previas que no habian aterrizado en commits propios. Lista por tema: * enrichers: web_search ahora usa lite.duckduckgo.com como endpoint primario (mas tolerante con bot detection desde IP residencial), con fallback al endpoint html. Detecta pagina captcha y emite error claro si ambos fallan. Anyade _DDGLiteParser para el formato lite + auto-pick de parser por contenido. * enrichers: tipo Webpage unificado en Url (campos de cuerpo cacheado viven en metadata del Url). Manifests actualizados (applies_to: [Url]). fetch_webpage ya no convierte Url->Webpage. * enrichers/manifest: campo `params` parseado a EnricherSpec.params (name, type, default_value, description). UI puede renderizar dialog de configuracion. * jobs: fix de path conversion para Python embebido nativo Windows (no convertir a /mnt/c/... cuando el subproceso es Windows-native; solo cuando es bash o python via WSL). * main.cpp: ventana ImGui (no modal) "Run enricher" con layout 2-col (label izq, input der). Inserta job con JSON tipado. Layout clustering apretado: hijos del mismo anchor en un solo anillo alrededor del padre, sin desperdigar por anillos crecientes. * views: inspector con layout 2-col via BeginTable (Identity, Schema fields, Extras). Description full-width debajo de su label. * tests: portable conftest (auto-detecta REGISTRY_ROOT, PYTHON_BIN, ENRICHERS_DIR para WSL y Windows portable). _runner.py trampoline inyecta stub via sys.path porque embedded Python ignora PYTHONPATH. Tests bash-only (vendor_script, freeze, dispatcher bash, resolver Linux-binary) skipean en Windows. Tests existentes adaptados a Webpage->Url. Resultado actual: 32 passed WSL, 21 passed + 11 skipped Windows.
402 lines
19 KiB
C++
402 lines
19 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "types_registry.h"
|
|
#include "entity_ops.h"
|
|
#include "tableview.h"
|
|
|
|
#include <cstdint>
|
|
#include <unordered_map>
|
|
|
|
struct GraphData;
|
|
struct GraphViewportState;
|
|
|
|
namespace ge {
|
|
|
|
// Estado compartido entre las vistas y el bucle render. Pasado por puntero
|
|
// desde main.cpp.
|
|
struct AppState {
|
|
// Datos
|
|
GraphData* graph = nullptr;
|
|
GraphViewportState* viewport = nullptr;
|
|
|
|
// Layout activo — default grid (1) para que los grafos cargados de
|
|
// operations.db se distribuyan ordenadamente al abrir.
|
|
// Default: fixed (5) — respeta posiciones guardadas y physics off por
|
|
// defecto. El usuario activa fisicas con el boton Physics y/o cambia
|
|
// layout desde el dropdown Layout en la toolbar.
|
|
int layout_mode = 5; // 0=force, 1=grid, 2=circular, 3=radial, 4=hierarchical, 5=fixed
|
|
int apply_layout_tick = 0; // se incrementa cuando hay que reaplicar layout
|
|
bool want_unpin_all = false; // Reset layout: limpia NF_PINNED y reaplica
|
|
|
|
// Force layout — config + GPU toggle. Repulsion bajada de 1500→800
|
|
// (issue 0006 follow-up) para evitar movimiento excesivo al cargar
|
|
// grafos pequenos. Combinado con damping=0.7 y max_velocity=8 en
|
|
// run_force_step.
|
|
float repulsion = 800.0f;
|
|
float attraction = 0.04f;
|
|
float gravity = 0.005f;
|
|
bool use_gpu = false;
|
|
|
|
// Stats UI
|
|
int fps_estimate = 0; // sintetico, calculado en main loop
|
|
|
|
// Filters / visibility por tipo (longitud = graph->type_count o rel_type_count)
|
|
bool type_visible[256] = {};
|
|
bool rel_type_visible[256] = {};
|
|
int type_visible_n = 0;
|
|
int rel_type_visible_n = 0;
|
|
|
|
// Inspector
|
|
bool panel_legend = true;
|
|
bool panel_inspector = true;
|
|
bool panel_stats = true;
|
|
bool panel_viewport = true;
|
|
bool panel_note = false;
|
|
bool panel_jobs = false; // issue 0026
|
|
bool panel_chat = false; // claude -p chat (issue 0001)
|
|
bool show_filters_modal = false;
|
|
bool show_open_modal = false;
|
|
|
|
// Triggers — main.cpp lee estos flags y actua
|
|
bool want_fit = false;
|
|
bool want_save_layout = false;
|
|
bool want_reload = false;
|
|
bool want_open_file = false; // marcado al confirmar el modal Open
|
|
char open_buf[512] = {};
|
|
|
|
// Project system (issue 0006)
|
|
std::string active_project; // slug del proyecto activo
|
|
bool want_switch_project = false;
|
|
std::string switch_project_target; // slug objetivo del switch
|
|
bool show_new_project_modal = false;
|
|
char new_project_buf[80] = {};
|
|
std::string new_project_error; // mensaje a mostrar en el modal
|
|
std::vector<std::string> project_list_cache; // refrescado al abrir el menu Project
|
|
std::vector<std::string> project_recent_cache;
|
|
|
|
// Labels overlay
|
|
bool labels_enabled = true;
|
|
|
|
// Path activo de operations.db (para CRUD desde toolbar / contextmenu).
|
|
// main.cpp lo escribe tras cargar y los handlers lo leen.
|
|
std::string input_db_path;
|
|
|
|
// Add-node toolbar input.
|
|
char add_buf[256] = {};
|
|
|
|
// Triggers de mutacion — main.cpp los procesa y dispara reload.
|
|
bool want_add_node = false; // commit del input add_buf
|
|
bool want_delete_node = false; // delete del nodo en ctx_node
|
|
bool want_duplicate_node = false;
|
|
bool want_change_type = false; // a ctx_new_type
|
|
int ctx_node = -1; // node_idx objetivo
|
|
char ctx_new_type[64] = {};
|
|
|
|
// Context menu state — popup global identificado por nombre.
|
|
bool ctx_open_request = false; // se setea en on_context_menu
|
|
|
|
// Note editor (panel "Note" abierto con doble click sobre nodo).
|
|
int note_node = -1; // node_idx siendo editado
|
|
std::string note_entity_id; // sql id resuelto
|
|
std::string note_entity_label; // display
|
|
std::string note_entity_type;
|
|
std::vector<char> note_buf; // editable, NUL-terminated
|
|
bool note_dirty = false;
|
|
bool want_save_note = false;
|
|
bool want_open_note = false; // doble click → cargar y abrir
|
|
int open_note_target = -1; // node_idx a abrir
|
|
|
|
// ---- Inspector editable (issue 0008) ----------------------------------
|
|
// Schema vivo del proyecto activo (load/save desde types.yaml).
|
|
ParsedTypes parsed_types;
|
|
|
|
// Draft del inspector — todo lo que el usuario esta editando para el
|
|
// nodo seleccionado. Se carga desde BD al cambiar la seleccion (si no
|
|
// hay cambios pendientes) y se persiste con entity_update al guardar.
|
|
int insp_node_idx = -1;
|
|
std::string insp_entity_id;
|
|
char insp_name_buf[256] = {};
|
|
char insp_type_buf[64] = {};
|
|
std::vector<char> insp_desc_buf; // multiline
|
|
int insp_status_idx = 0; // 0=active 1=stale 2=corrupted 3=archived
|
|
|
|
// Listas paralelas: keys + valores actuales de los campos de metadata.
|
|
// Las claves del schema del tipo van primero (en su orden), las "extras"
|
|
// van detras. `is_extra[i]` distingue para render diferenciado y para
|
|
// permitir borrar solo extras desde la UI.
|
|
std::vector<std::string> insp_field_keys;
|
|
std::vector<std::string> insp_field_values;
|
|
std::vector<unsigned char> insp_is_extra;
|
|
|
|
std::vector<std::string> insp_tags;
|
|
char insp_tag_input[64] = {};
|
|
char insp_extra_key[64] = {};
|
|
|
|
bool insp_dirty = false;
|
|
bool insp_show_unsaved = false;
|
|
int insp_pending_target = -1;
|
|
|
|
bool want_inspector_save = false;
|
|
bool want_inspector_discard = false;
|
|
|
|
// Caches refrescadas tras cargar grafo o tras Save.
|
|
std::vector<std::string> insp_tag_suggestions;
|
|
std::vector<std::string> insp_type_options;
|
|
|
|
// ---- Table node (issue 0010) ------------------------------------------
|
|
// Cache de conteo de filas por nodo Table indexado por user_data hash.
|
|
// Refrescado tras load_input y tras mutaciones que afecten a Tables.
|
|
std::unordered_map<uint64_t, int64_t> table_node_counts;
|
|
|
|
// ---- Table node UI fase 2 (issue 0011) --------------------------------
|
|
// Estado runtime por ventana de Table expandida. Una entrada por
|
|
// entity_id de Table que el usuario haya expandido. La ventana se cierra
|
|
// cuando set_expanded(false) — ya sea desde context menu o cerrando la
|
|
// ImGui window (que pone el flag a false automaticamente).
|
|
struct TableWindowState {
|
|
TableMetadata meta; // refrescada cada vez que entity cambia
|
|
int64_t total_rows = 0;
|
|
int64_t offset = 0;
|
|
std::vector<TablePageRow> page;
|
|
bool page_dirty = true;
|
|
bool open = true; // bound a ImGui::Begin
|
|
std::string last_error; // ultimo error de query (vacio = OK)
|
|
};
|
|
std::unordered_map<std::string, TableWindowState> table_windows;
|
|
|
|
// Triggers consumidos por main.cpp tras click en filas.
|
|
bool want_promote_row = false;
|
|
std::string promote_table_id; // entity_id del Table de origen
|
|
std::string promote_row_id; // valor del id_column
|
|
|
|
bool want_demote_entity = false;
|
|
std::string demote_entity_id;
|
|
|
|
bool want_focus_entity = false; // tras promote+open inspector
|
|
std::string focus_entity_id;
|
|
|
|
// Modal "Import dataset..." (issue 0011 Ingesta).
|
|
bool show_import_modal = false;
|
|
char import_path_buf[512] = {};
|
|
char import_table_buf[64] = {};
|
|
char import_duckdb_buf[256] = {}; // relativo a project root
|
|
char import_row_type_buf[64] = {};
|
|
bool want_import = false;
|
|
std::string import_error;
|
|
|
|
// Toggle expanded desde context menu del viewport.
|
|
bool want_toggle_expanded = false;
|
|
std::string toggle_expanded_id;
|
|
|
|
// ---- Table view (issue 0004) -------------------------------------------
|
|
// Vista tabular dockeable. Tabs por type_ref del grafo activo + opcional
|
|
// "All". Click selecciona el nodo en el viewport (mismo flujo que el
|
|
// Selectable del Inspector).
|
|
struct TableRow {
|
|
std::string id;
|
|
std::string name;
|
|
std::string type_ref;
|
|
std::string status;
|
|
std::string updated_at;
|
|
int neighbors = 0;
|
|
int node_idx = -1;
|
|
};
|
|
bool panel_table = false;
|
|
std::vector<TableRow> table_rows; // snapshot, refrescado tras load/reload
|
|
bool table_cache_dirty = true;
|
|
char table_search_buf[96] = {};
|
|
bool table_show_all = false;
|
|
int table_active_tab = 0;
|
|
// Filtros por columna: column_user_id (0..5) -> substring filter.
|
|
// Visible UX: right-click sobre header de columna abre popup con input;
|
|
// chips con filtros activos por encima de la tabla.
|
|
std::unordered_map<int, std::string> table_col_filters;
|
|
char table_filter_input[96] = {}; // buffer del popup activo
|
|
int table_filter_pending_col = -1; // col_user_id en edicion
|
|
|
|
// ---- Type Editor (issue 0007) ------------------------------------------
|
|
// Draft del editor de tipos. Se inicializa con una copia de parsed_types
|
|
// tras cargar el grafo. Save reescribe `types.yaml` y dispara
|
|
// apply_types_yaml + rebuild de IconAtlas.
|
|
bool panel_type_editor = false;
|
|
ParsedTypes types_draft;
|
|
bool types_dirty = false;
|
|
int te_tab_idx = 0; // 0=Entities 1=Relations
|
|
int te_entity_idx = -1; // seleccion entity
|
|
int te_relation_idx = -1; // seleccion relation
|
|
bool want_types_save = false;
|
|
bool want_types_reload = false;
|
|
int te_pending_delete_e = -1; // entity idx pendiente de confirmar
|
|
int te_pending_delete_r = -1;
|
|
int te_delete_use_count = 0; // entidades afectadas
|
|
bool show_te_delete_modal = false;
|
|
std::string types_save_error; // mensaje a renderizar bajo Save
|
|
|
|
// ---- Filtros y busqueda FTS5 (issue 0009) ------------------------------
|
|
// Modos: 0 = highlight (no-match dimmed), 1 = hide (no-match invisible).
|
|
enum FilterMode { FM_HIGHLIGHT = 0, FM_HIDE = 1 };
|
|
int filter_mode = FM_HIGHLIGHT;
|
|
char filter_query_buf[128] = {};
|
|
std::vector<std::string> filter_tags; // chips activos
|
|
std::vector<EntityHit> filter_hits; // dropdown FTS (max 20)
|
|
bool filter_dropdown_open = false;
|
|
bool filter_dirty = false; // pide reapply
|
|
int filter_focus_target = -1; // node_idx a centrar
|
|
char filter_tag_input[64] = {}; // input de chip nuevo
|
|
|
|
// ---- Enricher config window --------------------------------------------
|
|
// Cuando el usuario clica un enricher con `params` no vacios en el
|
|
// context menu, se rellena este bloque y se abre una ventana ImGui
|
|
// (no modal) que permite ajustar los valores antes de submitear el
|
|
// job. La ventana es dockeable y movible; cerrar la X cancela.
|
|
// Si el enricher no declara params, se submitea directamente con `{}`
|
|
// sin pasar por aqui.
|
|
bool enr_window_open = false; // visibilidad
|
|
std::string enr_modal_id; // enricher.id
|
|
std::string enr_modal_node_id; // sql_id del nodo
|
|
std::string enr_modal_node_label; // label visible
|
|
// Buffer editable por param. Tamano fijo 256 para inputs de texto;
|
|
// suficiente para queries y URLs cortas. Indices alineados con
|
|
// EnricherSpec::params del enricher seleccionado.
|
|
std::vector<std::vector<char>> enr_modal_param_bufs;
|
|
};
|
|
|
|
// Toolbar superior (Open file, Layout selector, Filters..., Fit, Save layout).
|
|
void views_toolbar(AppState& app);
|
|
|
|
// Panel Legend — checkboxes por tipo (entity / relation) con color swatch.
|
|
void views_legend(AppState& app);
|
|
|
|
// Panel Inspector — metadata del nodo seleccionado + vecinos.
|
|
void views_inspector(AppState& app);
|
|
|
|
// Stats line — counts + fps + energy + selection.
|
|
void views_stats(AppState& app);
|
|
|
|
// Note editor — abre con doble click sobre un nodo. Edita la columna `notes`
|
|
// (markdown) de la entidad y guarda con un boton.
|
|
void views_note(AppState& app);
|
|
|
|
// Modal Filters — toggles por tipo agrupados en columnas. Devuelve true si
|
|
// el usuario togglo algo.
|
|
bool views_filters_modal(AppState& app);
|
|
|
|
// Modal Open file — text input + boton Open.
|
|
bool views_open_modal(AppState& app);
|
|
|
|
// Modal "New project..." — slug input con validacion. Devuelve true si el
|
|
// usuario confirma con un slug valido.
|
|
bool views_new_project_modal(AppState& app);
|
|
|
|
// Refresca los flags `flags` de cada nodo/arista segun el array
|
|
// `type_visible[]` / `rel_type_visible[]`. Lineal en N+M.
|
|
void views_apply_visibility(AppState& app);
|
|
|
|
// Inicializa los arrays type_visible / rel_type_visible a true para todos
|
|
// los tipos del grafo activo. Llamar tras cargar/recargar el grafo.
|
|
void views_reset_visibility(AppState& app);
|
|
|
|
// ---- Inspector editable helpers (issue 0008) ------------------------------
|
|
|
|
// Refresca insp_tag_suggestions e insp_type_options leyendo BD y schema.
|
|
// Llamar tras cargar el grafo o tras un Save.
|
|
void views_inspector_refresh_caches(AppState& app);
|
|
|
|
// Carga el draft del Inspector desde la BD para el nodo `node_idx`. Si el
|
|
// nodo no es resoluble o no existe, deja el draft vacio. No respeta dirty:
|
|
// el caller debe haberlo manejado ya.
|
|
void views_inspector_load_draft(AppState& app, int node_idx,
|
|
const char* entity_id);
|
|
|
|
// Construye un EntityRecord desde el draft actual respetando el schema
|
|
// del type_ref para decidir is_string de cada metadata field.
|
|
EntityRecord views_inspector_build_record(const AppState& app);
|
|
|
|
// Resetea el draft (todos los buffers + dirty=false). Util tras Save o
|
|
// al cambiar de proyecto.
|
|
void views_inspector_clear_draft(AppState& app);
|
|
|
|
// ---- Table node UI fase 2 (issue 0011) ----------------------------------
|
|
|
|
// Renderiza una ventana ImGui dockeable por cada Table en table_windows
|
|
// con `open=true`. Cabecera con nombres de columnas. Filas paginadas con
|
|
// ImGuiListClipper consumiendo el page cache; al cambiar el offset, marca
|
|
// dirty para que main.cpp refresque via tableview_page. Doble click en
|
|
// fila no promovida -> setea promote_table_id/promote_row_id; promovida
|
|
// -> focus_entity_id. Cerrar la ventana setea expanded=false en BD.
|
|
void views_table_window(AppState& app);
|
|
|
|
// Modal "Import dataset..." — formulario para crear una tabla DuckDB
|
|
// desde CSV/Parquet/JSON y registrar el nodo Table correspondiente.
|
|
bool views_import_dataset_modal(AppState& app);
|
|
|
|
// Sincroniza table_windows con la metadata.expanded de cada nodo Table.
|
|
// Llamar tras load + tras mutaciones que cambien expanded. Crea entradas
|
|
// para nuevos expanded y borra las que ya no aplican.
|
|
void views_table_windows_sync(AppState& app, const char* ops_db);
|
|
|
|
// ---- Table node overlay (issue 0010) ------------------------------------
|
|
|
|
// Dibuja un overlay rectangulo redondeado sobre cada nodo `Table` del grafo
|
|
// con etiqueta "Table · N rows" leyendo de app.table_node_counts. Llamar
|
|
// despues de graph_viewport(...) — usa GetItemRectMin/Max + GetWindowDrawList
|
|
// del item viewport. No interactua con eventos; el hit-testing del nodo
|
|
// sigue usandolo el viewport circular de fondo.
|
|
void views_table_overlay(AppState& app);
|
|
|
|
// ---- Table view (issue 0004) --------------------------------------------
|
|
|
|
// Renderiza el panel "Table". Lee de app.table_rows; el caller ya ha hecho el
|
|
// build/refresh tras cargar el grafo. Click en fila selecciona el nodo en el
|
|
// viewport (mismo flujo que el Selectable del Inspector). Filtro por
|
|
// substring sobre name/id en la cabecera.
|
|
void views_table(AppState& app);
|
|
|
|
// Recompute neighbors[] y node_idx[] de las filas existentes a partir del
|
|
// grafo cargado. Llamar tras cargar el grafo o tras una mutacion.
|
|
void views_table_refresh_indices(AppState& app);
|
|
|
|
// ---- Type Editor (issue 0007) -------------------------------------------
|
|
|
|
// Renderiza el panel "Types" — tabs Entities/Relations, lista a la izquierda
|
|
// con +/-, panel de edicion a la derecha. Marca app.types_dirty al cambiar y
|
|
// activa app.want_types_save / app.want_types_reload desde el footer.
|
|
void views_type_editor(AppState& app);
|
|
|
|
// Modal de confirmacion para borrar un tipo en uso. Se abre cuando
|
|
// app.show_te_delete_modal = true. main.cpp es responsable de poblar
|
|
// te_delete_use_count via consulta a operations.db antes de mostrarlo.
|
|
bool views_type_editor_delete_modal(AppState& app);
|
|
|
|
// ---- Jobs panel (issue 0026) ---------------------------------------------
|
|
|
|
// Renderiza el panel "Jobs" — tabla con todos los jobs (queued/running/done/
|
|
// error/cancelled). Botones por fila para cancelar / reintentar / borrar.
|
|
// Click en target_node centra el viewport sobre ese nodo (futuro). Polling
|
|
// cada N frames para no spammear la BD.
|
|
void views_jobs(AppState& app);
|
|
|
|
// ---- Filter helpers (issue 0009) -----------------------------------------
|
|
|
|
// True si el filtro tiene query no vacia o al menos un tag activo.
|
|
bool views_filter_active(const AppState& app);
|
|
|
|
// Anade un tag como chip si no existe ya. Marca filter_dirty = true.
|
|
void views_filter_add_tag(AppState& app, const char* tag);
|
|
|
|
// Limpia query + tags y marca filter_dirty.
|
|
void views_filter_clear(AppState& app);
|
|
|
|
// Reaplica el filtro al grafo: recompute la mascara de visibilidad/alpha
|
|
// segun filter_query, filter_tags, filter_mode. Llama a la BD si hace
|
|
// falta (FTS + tags). Resetea color_override a 0 en los nodos que pasan
|
|
// el filtro y aplica un alpha bajo en los que no (modo highlight) o limpia
|
|
// NF_VISIBLE (modo hide). Tambien refresca filter_hits para el dropdown
|
|
// con max 20 resultados ordenados por rank.
|
|
void views_filter_apply(AppState& app);
|
|
|
|
} // namespace ge
|