Commit Graph

355 Commits

Author SHA1 Message Date
Ubuntu e7641e9831 feat(history): enable 'Analysis Report' button in simulation history
- ProjectManager._to_dict now scans simulation state files to find
  last_simulation_id and last_report_id for each project
- HistoryDatabase: report button enabled when last_report_id or
  last_simulation_id available; goToReport looks up report by
  simulation ID if no direct report_id; report status icon reflects
  availability
- Add getReportBySimulation() to frontend report API

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 23:27:10 +00:00
Ubuntu f0f8a797ef feat(step5): add 'New simulation' button to return to home
Adds a restart button in the action-bar-header of Step5Interaction
that navigates to '/' (home/project list). Translated in all 4 locales.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 23:23:22 +00:00
Ubuntu 2aa44760d1 feat(f2a-b): step02/03 UX overhaul, Azure OpenAI fix, offline report interviews
Step 02/03 UX:
- Remove duplicate simulation params (total_hours, minutes_per_round) from Fase B form
- Add following_probability + recsys_type to step 03 config panel instead
- Step 03 now read-only by default with Edit / Save toolbar toggle
- Add common.edit and log.configSaved i18n keys to all 4 locales

Backend - Azure OpenAI fix (run_parallel_simulation.py):
- create_model() now detects Azure URLs (cognitiveservices.azure.com / openai.azure.com)
  and uses ModelPlatformType.AZURE with AzureOpenAIModel, passing api_version and
  azure_deployment_name explicitly — fixes 404 "Resource not found" from camel-ai

Backend - offline report interviews (simulation_runner.py):
- interview_agents_batch() falls back to _offline_batch_interview() when OASIS env is
  closed (simulation finished), reading posts from SQLite DB instead of failing with
  "No successful interviews / check OASIS environment status"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 23:20:41 +00:00
Ubuntu 34962edc20 fix(step2): add null-guard for task_id in pollTaskUntilDone, add try/catch to confirmDeleteAgent 2026-05-03 22:20:26 +00:00
Ubuntu c7bc4d5ad0 feat(step2/step3): add Fase A agent edit/delete/regen modal, Fase B config form, and Step3 enable_graph_memory_update checkbox
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:17:05 +00:00
Ubuntu 9b69c55842 feat(i18n): add F2-A+B translation keys for en and zh
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:12:10 +00:00
Ubuntu 1a5ea5a470 feat(frontend-api): add 7 new simulation API calls for F2-A+B
Adds patchAgent, deleteAgent, createAgent, regenerateAgent, generateConfig,
patchSimulationConfig, and cloneSimulation to the simulation API client.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:11:45 +00:00
Ubuntu 5ec98a3e0e fix(graph): use get_running_loop() in _execute_neo4j_query, unify delete_graph to single async-backed method 2026-05-03 22:10:14 +00:00
Ubuntu 0343cad632 feat(simulation): clone graph on start for per-simulation isolation, use graph_id_simulation in report
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:06:27 +00:00
Ubuntu 6ea83f31a4 feat(graph): add clone_graph and delete_graph to GraphitiBackend via APOC
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:05:19 +00:00
Ubuntu 594144e195 fix(simulation): move regenerate_agent validation to request handler (404/400 before task creation) 2026-05-03 22:02:56 +00:00
Ubuntu 5d679024c3 feat(simulation): add POST /agent create and /agent/{id}/regenerate endpoints
Implements Tasks 8 and 9 of F2-A+B: async agent creation from entity UUID
and async per-agent profile regeneration, both with atomic profile file writes.
Refactors generate_profile_from_entity to accept extra_instructions instead
of requiring user_id (renamed internal logic to _generate_single_profile).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:59:25 +00:00
Ubuntu 306414a555 fix(simulation): add int coercion and 400 validation for max_agents in prepare endpoint 2026-05-03 21:56:03 +00:00
Ubuntu ef46ba1743 feat(simulation): add max_agents selector via top-N connectivity in prepare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:54:34 +00:00
Ubuntu a74c0975fe fix(simulation): fix clone 400→404 for not found, remove redundant makedirs, hoist uuid import
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:52:35 +00:00
Ubuntu a6b4ccca3c feat(simulation): add POST /<simulation_id>/clone endpoint (Task 6)
Implements SimulationManager.clone_simulation() and the corresponding
Flask route. The clone copies reddit_profiles.json, twitter_profiles.csv
and agent_profiles.json from the source simulation; does not copy
simulation_config.json; sets status=PROFILES_READY and records
parent_simulation_id. All 3 tests in test_simulation_clone.py pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:48:57 +00:00
Ubuntu ed71afe442 fix(simulation): add FileNotFoundError check in delete_agent_profile and endpoint 2026-05-03 21:44:55 +00:00
Ubuntu 83cf890c83 feat(simulation): add DELETE agent, POST generate-config, PATCH config endpoints
- DELETE /<sim_id>/agent/<user_id>: removes agent from reddit_profiles.json (atomic write, guards against running/completed status)
- POST /<sim_id>/generate-config: transitions profiles_ready→configuring→ready, runs LLM config generation in background thread, returns task_id
- PATCH /<sim_id>/config: merges time/platform config fields into simulation_config.json (atomic write)
- Corresponding SimulationManager methods: delete_agent_profile(), patch_simulation_config()
- 7 tests all passing (3 original + 4 new)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:43:02 +00:00
Ubuntu c0356e706a fix(simulation): catch FileNotFoundError in patch_agent endpoint (return 404 not 500) 2026-05-03 21:40:16 +00:00
Ubuntu f7dd353a31 feat(simulation): add PATCH /simulation/{id}/agent/{user_id} endpoint
Implements atomic agent profile editing with manually_edited flag.
Blocks edits when simulation is running or completed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 21:37:19 +00:00
Ubuntu 8a0854ceba feat(simulation): add profiles_ready/configuring states and parent_simulation_id/graph_id_simulation fields 2026-05-03 21:33:14 +00:00
Ubuntu 65554bcd50 docs(plan): add F2-A+B implementation plan — agent editing, simulation params, graph isolation 2026-05-03 21:25:33 +00:00
Ubuntu 27cef87e65 docs(spec): add graph_id_simulation cleanup on simulation delete
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 20:38:43 +00:00
Ubuntu bb80ec115a docs(spec): fix F2-A graph isolation — ReportAgent queries graph_id_simulation only
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 20:38:20 +00:00
Ubuntu a1862c1c86 docs(spec): update F2-A spec — add agent creation/deletion and graph isolation (ex F2-D)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 20:32:33 +00:00
Ubuntu 26f0b72b3c docs(spec): add F2-A design spec for agent edit, regen and clone
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 20:12:10 +00:00
Ubuntu 607a2640e1 feat(history): use listProjects API for project recovery in home page
Replace getSimulationHistory (simulation API) with listProjects (graph API)
and adapt all template references from simulation_id/report_id fields to
project_id/graph_id fields matching the new project data model.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:31:53 +00:00
Ubuntu 1eae54346f feat(frontend-api): add listProjects() to graph API client 2026-05-03 01:30:11 +00:00
Ubuntu 17a547e9f0 test(graph-api): add integration tests for project CRUD endpoints
8 tests covering list, get, create, delete, and reset endpoints via
Flask test client with in-memory SQLite and mocked storage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:29:12 +00:00
Ubuntu 83b69dfd87 fix(graph-api): fix build_graph endpoint for dict-based ProjectManager
Convert all project.attribute accesses to project["key"]/project.get("key"),
use save_project({...}) dict calls, and wire save_graph_record/complete_graph_record
helpers for proper graph persistence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:24:56 +00:00
Ubuntu 5d6d4d787a fix(graph-api): cleanup orphan project on ontology generation failure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:23:15 +00:00
Ubuntu 284f962e17 fix(graph-api): rewrite generate_ontology/import_ontology to use dict ProjectManager
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:20:32 +00:00
Ubuntu ea9ac6a1cd fix(graph-api): fix project/task dict access after ProjectManager refactor
Replace .to_dict() calls and attribute access with direct dict usage,
add get_storage() import for delete_project, and rewrite reset_project
to use save_project() with a partial dict instead of mutating an ORM object.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:17:21 +00:00
Ubuntu 8a6d00b26e refactor(project): clean up _to_dict delegation and remove unused import
- Remove unused `import io`
- Avoid double-encoding in save_extracted_text by caching encoded bytes
- Delegate _to_dict queries to get_ontology/get_latest_graph_external_id
- Add comment to save_ontology noting full versioning is planned for F2-3

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:16:03 +00:00
Ubuntu 949921344b feat(project): add ontology/graph persistence helpers to ProjectManager
- Add `from ..config import Config` import
- Convert `_to_dict` from @staticmethod to @classmethod; it now opens a
  fresh session to populate `ontology` and `graph_id` from OntologyModel
  and GraphModel respectively
- Use `db.expunge(proj)` before closing sessions in create_project,
  get_project and list_projects so `_to_dict` can open its own session
  without nesting conflicts (SQLite StaticPool safe)
- Add five new classmethods: save_ontology, get_ontology,
  save_graph_record, get_latest_graph_external_id, complete_graph_record

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 01:13:26 +00:00
Ubuntu 9ed2412745 test(conftest): add in_memory_db and task manager singleton reset fixtures; fix broken tests
- Replace conftest.py with two autouse fixtures: reset_graph_factory_singleton
  and reset_task_manager_singleton, plus in_memory_db fixture for tests
  requiring a real DB
- Rewrite test_project_task_recovery.py to use ProjectManager + SQLite in-memory
  DB instead of the removed Project dataclass (same guarantee: active_task_id
  persists and defaults to None)
- Fix db.py init_db() to import db_models before Base.metadata.create_all() so
  all ORM tables are registered and created on first startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:15:42 +00:00
Ubuntu 0b760eed0b fix(task): rename loop var t→task_row to avoid shadowing locale.t import 2026-05-03 00:13:12 +00:00
Ubuntu 2478beb9ea feat(project): refactor ProjectManager to persist via SQLAlchemy + StorageService
Replace file-based JSON persistence with SQLAlchemy DB (ProjectModel/ProjectFileModel)
and StorageService for file content; remove Project dataclass; add 7 passing tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:11:12 +00:00
Ubuntu 1f43d35d59 feat(task): refactor TaskManager to persist tasks in SQLAlchemy DB
Replace in-memory dict-based TaskManager with a SQLAlchemy-backed implementation
using TaskModel. Tasks now survive process restarts. 6 new tests added and passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:10:16 +00:00
Ubuntu 479ae0b712 feat(app): inject SQLAlchemy DB and StorageService into Flask app factory
Initializes the database (via init_db) and registers the StorageService
instance in app.extensions['storage'] inside create_app(). Adds get_storage()
helper for convenient access from any Flask context.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:08:13 +00:00
Ubuntu 868ce39577 fix(storage,db): path traversal fix, delete_prefix validation, remove dead import, factory uses Config
- local.py: use relative_to() for path traversal guard (fixes prefix-collision false negative)
- local.py: validate delete_prefix rejects empty/root prefix to prevent full-storage wipe
- local.py: remove unused `import os`
- db_models.py: remove dead UniqueConstraint import
- db_models.py: replace deprecated datetime.utcnow() with datetime.now(timezone.utc)
- factory.py: read STORAGE_TYPE and related settings from Config instead of os.environ directly; remove `import os`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:06:58 +00:00
Ubuntu aab0cd355a feat(alembic): add initial schema migration for all SQLAlchemy models
Initializes Alembic with autogenerated migration covering all 11 tables
(tasks, users, projects, project_files, ontologies, graphs, simulations,
reports, system_config, invitation_tokens, password_reset_tokens).
Adds *.db to .gitignore to exclude local SQLite dev database.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 00:04:18 +00:00
Ubuntu 999f6efa4f test(db): enable SQLite PRAGMA foreign_keys=ON in fixture for strict FK assertions 2026-05-02 23:56:58 +00:00
Ubuntu 773cc250c9 feat(db): add SQLAlchemy Base, session factory, and all ORM models
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 23:54:05 +00:00
Ubuntu 9e33f823d9 feat(storage): add StorageService protocol, LocalFSStorage, AzureBlobStorage, factory 2026-05-02 23:53:19 +00:00
Ubuntu ca2f9e2a8f feat(config): add DATABASE_URL, STORAGE_TYPE, AZURE_STORAGE_*, JWT config vars 2026-05-02 23:53:16 +00:00
Ubuntu dd1f713e42 chore(deps): add SQLAlchemy, Alembic, Azure Blob, bcrypt, flask-jwt-extended 2026-05-02 23:48:02 +00:00
Ubuntu d69d1976d8 docs(plan): add Fase 1 implementation plan for persistence infrastructure
Covers 9 tasks with TDD approach:
- Task 1: Dependencies (SQLAlchemy, Alembic, Azure Blob, bcrypt, flask-jwt-extended)
- Task 2: Config vars (DATABASE_URL, STORAGE_TYPE, AZURE_STORAGE_*, JWT_*)
- Task 3: SQLAlchemy models (all 11 entities)
- Task 4: Alembic migrations
- Task 5: StorageService (Protocol + LocalFS + AzureBlob + factory)
- Task 6: Flask app factory injection
- Task 7: TaskManager refactor → DB
- Task 8: ProjectManager refactor → DB + Storage
- Task 9: Test suite + e2e verification

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:40:18 +00:00
Ubuntu 6ec363add4 docs(persistencia): aclarir RBAC, auth provisional, forgot-password i look&feel
- Admin és també user: accés a tots els projectes + admin en pantalles separades
- Documentar auth provisional (DEMO_PASSWORD) a eliminar
- Afegir flux forgot-password amb resposta genèrica (no revela validesa email)
- Principi de seguretat: cap endpoint d'auth revela si un email existeix
- Look & feel: Sistema de Disseny Gencat, consistent amb AgentCAT

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:31:23 +00:00
Ubuntu 36107c2c69 docs(persistencia): afegir especificació completa de la capa de persistència
Disseny validat durant sessió de brainstorming. Cobreix:
- Model de dades SQLAlchemy 2.x (User, Project, Ontology, Graph, Simulation, Report, Task, SystemConfig)
- StorageService amb adaptadors LocalFS / Azure Blob (S3 preparat però diferit)
- Autenticació JWT + RBAC (user/admin) amb flux d'invitació
- SystemConfig per a configuració dinàmica (LLM keys, límits, features)
- 4 fases d'implementació amb criteris de verificació

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:03:47 +00:00