Commit Graph

135 Commits

Author SHA1 Message Date
liyizhouAI 8990b60fe5 Fix report citation chip labels 2026-06-08 21:47:31 +08:00
liyizhouAI 86a8ae629a Route course simulation to interactive summary 2026-06-08 21:20:57 +08:00
liyizhouAI 57263d5337 Preserve completed simulation replay flow 2026-06-08 19:51:36 +08:00
liyizhouAI e1467b53e2 Use realistic personas for cached demo agents 2026-06-08 19:37:57 +08:00
liyizhouAI c5cc5912c0 Refine report citation anchors 2026-06-08 19:21:14 +08:00
liyizhouAI a6a12d7775 Enhance Foresight demo replay and evidence citations 2026-06-08 19:09:16 +08:00
liyizhouAI cd51ebe282 feat: report quality overhaul — concrete data, agent quotes, infographic
- Add SimulationAnalyticsService: direct actions.jsonl access for stats,
  top posts, agent quotes (positive/negative), sentiment breakdown
- Add simulation_analytics tool to ReportAgent ReACT loop
- Rewrite prompts: demand specific numbers, prohibit vague language,
  require verbatim agent quotes (min 5 per section)
- Refactor report_agent.py: extract prompts → report_prompts.py,
  data classes → report_data.py (both under 800 lines)
- Add ReportInfographic.vue: metrics cards, action distribution bars,
  sentiment breakdown, top agents, timeline sparkline
- Add infographic API endpoint: GET /api/report/<id>/infographic
- Pre-compute infographic data during report generation
- Increase max_tokens from 4096 to 8192 for detailed sections
2026-04-17 16:58:53 +08:00
liyizhouAI 9efdced7f2 fix: report prompt alignment + auto-report trigger + failed report redirect
1. Report prompt now extracts user's core questions from simulation_requirement
   and structures the report to directly answer them (e.g. "will it go well?",
   "where are the problems?") instead of generic future-prediction questions.

2. Step3Simulation auto-triggers report generation 1.5s after simulation completes.

3. ReportView auto-redirects to latest successful report when current report
   has failed, via /api/report/check/<simulation_id> endpoint.
2026-04-17 13:16:03 +08:00
liyizhouAI 86106001da feat: auto-trigger report generation after simulation completes
Simulation completion detection now automatically triggers report
generation after a 1.5s delay, eliminating the need for users to
manually click the "generate report" button.
2026-04-17 13:03:23 +08:00
liyizhouAI 8b77a7b9ba fix: report 429 retry + theme toggle on all pages
- LLMClient: increase retries 5→8, backoff 1s→2s, max 30s→60s for GLM rate limit recovery
- Report agent: add 3s delay between sections to avoid sustained 429
- Add theme-toggle-anchor to SimulationRun/Report/Interaction/Replay views
- All pages now have dark/light theme toggle button
2026-04-17 08:36:58 +08:00
liyizhouAI b7df4880c8 fix: v0.3.4 - production stability fixes for simulation pipeline
- LLM JSON truncation: add _repair_truncated_json() to handle max_tokens cutoff
- Ontology generation: increase max_tokens 4096→8192 to prevent truncation
- Config generation: parallel batch processing (3 threads × 30 agents/batch) for ~3x speedup
- Rate limit: reduce semaphore 30→8 to avoid GLM API 429 storms
- HuggingFace offline: set HF_HUB_OFFLINE=1 to skip unreachable hf-mirror.com
- Simulation recovery: auto-reset stuck "preparing" states on Flask restart
- Prepare endpoint: handle concurrent prepare requests gracefully
- Frontend: handle page-refresh-during-prepare edge case
- API: return 429 instead of 500 for LLM rate limit errors
2026-04-16 22:44:40 +08:00
liyizhouAI f1f2ea4ea5 fix: v0.3.1 - 7 bug fixes unblock end-to-end production flow
First successful E2E test uncovered 7 blocking bugs. All fixed and deployed
to production server. User confirmed full pipeline now runs through.

## Bug Fixes

### #1 LLMClient exponential backoff retry
- recognize RateLimitError / 429 / 5xx / 1302 / timeout / connection errors
- 5 retries with 1→2→4→8→16s backoff + random jitter
- file: backend/app/utils/llm_client.py

### #2 GLM → Qwen 32B dual-LLM fallback (ontology generation)
- primary LLM (智谱 GLM-4-Flash) retries exhausted → single attempt fallback to
  SiliconFlow Qwen 2.5-32B via GRAPHITI_LLM_* config
- solves GLM low RPM quota intermittent throttling
- fallback does NOT retry (avoid cascade)
- file: backend/app/services/ontology_generator.py

### #3 Qwen 32K context overflow
- MAX_TEXT_LENGTH_FOR_LLM 50000 → 28000 chars
- ensures prompt+response stays under 32768 tokens
- truncated docs get marker line "[文档已截断以适应 LLM 上下文窗口]"
- file: backend/app/services/ontology_generator.py

### #4 Neo4j entity summary flatten via monkey-patch
- Qwen occasionally returns {summary: {value, type, title, description}}
  which Neo4j rejects (properties must be primitives)
- monkey-patch Neo4jEntityNodeOperations.save / save_bulk
- recursive _flatten_entity_property extracts .value from nested dicts,
  json.dumps as string fallback
- file: backend/app/services/graphiti_client.py

### #5 Frontend stuck at /process/new with no pending state
- pendingUpload is in-memory reactive, lost on refresh / direct URL
- MainView.handleNewProject early-returned on empty state without navigating,
  leaving UI permanently in "waiting for ontology" limbo
- fix: detect empty state, log redirect msg, router.replace to Home after 800ms
- file: frontend/src/views/MainView.vue

### #6 Semaphore 100 → 30 (OASIS simulation)
- high concurrency triggered GLM rate limit cascade during profile/action LLM calls
- drop to 30 eliminates 1302 retries, total runtime impact < 10%
- file: backend/scripts/run_parallel_simulation.py

### #7 SimulationReplayView redesigned to Manus cinematic style
- previous 3-column analyst panel felt like a dashboard, not a replay
- new single-column immersive layout matching Manus's "observation window":
  - top breadcrumb: "Foresight is running Reddit simulation · Round 8/15"
  - main stage: browser chrome + native-style platform post card
    (Reddit subreddit header / Twitter tweet header)
  - action type badges, agent avatars with gradient palettes
  - stage meta bar: per-round action counts by type
- bottom scrubber row: timestamp chip + Jump to live button + live indicator
  (pulsing green dot when sim is running) + step/play/step buttons + 5 speed levels
- bottom task bar: current pipeline step icon/label/progress
- dark theme (#0A0A0B base + #FF5722 accent)
- analyst mode toggle (◫/▦) preserves original 3-column view
- auto-polling every 10s while sim is running, auto-tracks live position
- file: frontend/src/views/SimulationReplayView.vue

## Docs
- PRD.md bumped to v0.3.1 with full hotfix changelog + decision log entries
2026-04-15 13:25:05 +08:00
liyizhouAI 1fef01d979 feat: v0.3 - Manus replay + token tracking + SIGTERM fix + accelerate button
This is the v0.3 milestone commit before the v0.4 big version push.
Major themes: process replay, runtime stability, cost observability.

## New Features

- **Manus-style process replay** (frontend + backend)
  - `GET /api/simulation/<id>/replay` returns full workflow + agents + rounds + aggregate
  - `frontend/src/views/SimulationReplayView.vue` 3-column layout (workflow / actions / stats)
  - bottom scrubber with play/pause/step + 5 speed levels (0.5x-10x)
  - filters out stale actions from previous runs via latest simulation_start timestamp

- **Token usage tracking** (`backend/app/utils/token_tracker.py`)
  - process-wide stage→model→tokens counter
  - LLMClient auto-records prompt/completion tokens after each call
  - stages tagged at API entry: step1_ontology, step2_graph_build, step3_prepare, step5_report
  - `GET /api/usage/summary` for live stats + CNY cost estimate
  - `GET /api/usage/estimate-simulation` for OASIS subprocess estimation
  - pricing table for GLM/SiliconFlow/MiniMax/OpenAI/Anthropic models
  - documented as internal-use, removed from customer-facing builds

- **Step 2 "Skip & Continue" button**
  - lets user stop profile generation early and proceed with what's already generated
  - `simulation_manager.request_accelerate()` + cancel_check in oasis_profile_generator
  - new endpoint `POST /api/simulation/prepare/accelerate`

## Critical Bug Fix

- **SIGTERM no longer kills running simulation subprocess**
  - root cause: `SimulationRunner.register_cleanup()` registered SIGTERM/SIGINT/SIGHUP handlers
    that called `os.killpg` on every tracked sim child, even though spawn already used
    `start_new_session=True` to give children isolated sessions
  - fix: neutered `register_cleanup` to a no-op; `cleanup_all_simulations` itself preserved
    for explicit stop_simulation paths
  - validated: killed Flask backend twice, simulation subprocess kept running
  - impact: hot-reload backend code without interrupting in-flight simulations

## Performance & Tuning

- semaphore 30 → 100 (twitter + reddit) for higher LLM concurrency
- discovered 200 agents as memory/cost/statistical sweet spot for 8G server
  (503 agents OOMs both platforms; 200 agents fits cleanly with 95% confidence margin)

## Documentation

- **PRD.md** rewritten as v0.3 baseline (10 chapters + 2 appendices, 639 lines)
  - product positioning across 3 usage modes (one-shot / model-reuse / SaaS)
  - v0.4 roadmap: domestic platforms (douyin/wechat/xiaohongshu/weibo), fork sim, multi-tenant
  - operational lessons: HF mirror, Tencent PyPI mirror, GLM-4-Flash choice, agent count
  - decision log with dates
  - per-stage token/cost breakdown for typical 200-agent run
- **README.md / README-ZH.md** updated with replay step + Graphiti+Neo4j

## Files Touched

19 files changed, 1105 insertions(+), 246 deletions(-)
2026-04-15 09:37:22 +08:00
liyizhouAI a245106514 feat: add error recovery UI + HTTPS API endpoint
- Add retry/home buttons when errors occur in graph building
- Improve error messages: Network Error, timeout, missing files
- Clear guidance for users when page refresh loses upload state
- API endpoint switched from HTTP to HTTPS (api.foresight.yizhou.chat)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-04-13 23:00:15 +08:00
liyizhouAI 4b682f24f4 feat: dark mode full-page responsive layout overrides
Override inner container max-width constraints (.main-content, .dashboard-section,
.content-area, .main-content-area, .panel-wrapper) so dark mode content fills
widescreen displays like light mode does natively.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-04-11 17:32:52 +08:00
liyizhouAI ded715feb2 feat: merge upstream i18n + rebrand MiroFish → Foresight 先见之明
- Merge 41 upstream commits (i18n for 7 languages, security fixes, new features)
- Rebrand all MiroFish references to Foresight/先见之明 across 37 files
- Re-apply dark theme CSS overhaul (pure black/gray, no blue tints)
- Re-apply Teleport-based theme toggle (inline with brand, 20px gap)
- Restore Foresight logo and favicon
- Update GitHub links to liyizhouAI/foresight
- Update locale files, README, package.json

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-04-11 16:40:13 +08:00
ghostubborn 2421010fe1 fix(i18n): fix English workflow desc font size with correct CSS selectors 2026-04-01 19:11:22 +08:00
ghostubborn 3929c3ade2 fix(i18n): further shorten English metrics and improve workflow layout 2026-04-01 19:07:19 +08:00
ghostubborn 21922da6cc fix(i18n): improve English layout for homepage left-pane and report title
- Add sans-serif font for English left-pane (status, workflow sections)
- Shorten English workflow step descriptions
- Reduce English report title font-size from 36px to 28px
2026-04-01 19:04:38 +08:00
ghostubborn c6cafdd532 fix(i18n): translate world1/world2 platform labels in interview tool display 2026-04-01 18:38:22 +08:00
ghostubborn 5072a2eaa8 feat(i18n): replace Chinese UI text in Step4Report.vue render functions
Only UI display text is replaced. Regex parsing patterns are kept as-is
since they match the backend output format.
2026-04-01 18:35:18 +08:00
ghostubborn 6db3f98a48 fix(i18n): fix English homepage layout with proper font and shorter copy
- Use sans-serif font for English titles, descriptions and navbar
- Shorten English hero text to avoid overflow
- Fix :global() scoped CSS issue that was setting root font-size to 3.5rem
- Use separate unscoped style block for html[lang] selectors
2026-04-01 18:04:05 +08:00
ghostubborn 1d358fc492 feat(i18n): replace expand/collapse Chinese text in Step4Report.vue 2026-04-01 17:44:45 +08:00
ghostubborn 3a8451c119 feat(i18n): replace remaining hardcoded Chinese in frontend addLog calls 2026-04-01 17:21:55 +08:00
ghostubborn e1db8bacc2 feat(i18n): replace hardcoded Chinese in frontend addLog() messages 2026-04-01 16:35:35 +08:00
ghostubborn ffe6369c52 fix(i18n): fix curly quotes in Home.vue and remove unused dark theme from LanguageSwitcher 2026-04-01 16:23:52 +08:00
ghostubborn fbaa3dbbeb fix(i18n): fix curly quotes and missing @ alias in vite config 2026-04-01 15:45:43 +08:00
ghostubborn fc47ae81b5 feat(i18n): replace hardcoded Chinese in frontend components with i18n calls
Replace all user-visible hardcoded Chinese strings in 7 component files
with $t() / t() calls using vue-i18n:

- Step1GraphBuild: ontology generation, graph build, status badges
- Step2EnvSetup: simulation setup, agent personas, platform config,
  time config, initial activation, modal profile details
- Step3Simulation: report generation button
- Step4Report: section loading text, interaction button
- Step5Interaction: chat interface, survey UI, tool descriptions,
  error messages, agent selection
- GraphPanel: graph status hints, loading states, tooltips
- HistoryDatabase: history cards, modal, replay buttons

Added missing translation keys to both zh.json and en.json locale files.
Added useI18n imports to components that need script-level translations.
2026-04-01 15:43:11 +08:00
ghostubborn 70833821a2 feat(i18n): replace hardcoded Chinese in frontend views with i18n calls 2026-04-01 15:36:29 +08:00
ghostubborn 3d5e5d024d feat(i18n): add language switcher component to navigation 2026-04-01 15:24:58 +08:00
ghostubborn 22bf50f877 feat(i18n): set up vue-i18n with dynamic locale loading 2026-04-01 15:22:14 +08:00
ghostubborn 2ffadd3038 feat(i18n): add Accept-Language header to all API requests 2026-04-01 15:22:07 +08:00
666ghj a795405428 style(home): add overflow-y property to upload zone and adjust alignment for files 2026-02-22 23:40:40 +08:00
666ghj ae1f38cdcc fix(report_agent): improve markdown rendering by cleaning up <br> tags around block-level elements and enhancing list formatting 2026-02-14 18:25:20 +08:00
666ghj 709a0d7023 feat(report_agent): enhance markdown rendering for lists and improve formatting; support nested lists and clean up HTML output 2026-02-14 17:04:04 +08:00
666ghj 7601d78fd4 feat(report_agent): enhance interview text processing and response handling; improve quote extraction and formatting for better clarity 2026-02-14 16:56:48 +08:00
666ghj f9abaf8e9f refactor(report_agent, Step4Report): simplify logging and remove subsection handling; update UI to reflect changes in section content generation 2026-02-06 18:13:30 +08:00
666ghj 0b71f89f96 fix(Step2EnvSetup): update expectedTotal only when API returns a valid value to prevent overwriting existing data 2026-01-29 10:58:36 +08:00
666ghj 085aa6bbe6 fix(GraphPanel): optimize force graph drag behavior to prevent simulation restart on click
Background:
- With many nodes, D3 force simulation tick callback updates all nodes/edges/labels every frame
- Original implementation called simulation.restart() in drag start event on mousedown
- Even after simulation converged, clicking a node to view details would restart simulation, causing lag

Solution:
- Distinguish between "click" and "drag" using 3px movement threshold
- On drag start: only record initial position, do not restart simulation
- On drag event: detect movement exceeding threshold before marking as actual drag and restarting simulation
- Pure click operations no longer trigger simulation restart, keeping graph static

Bug fix:
- Fixed issue where nodes became undraggable after initial optimization
- Cause: incorrectly used if(!event.active) check in drag event
- event.active equals 1 during drag event, causing restart() to never execute
- Removed that condition, using custom _isDragging flag to control logic instead
2026-01-18 22:35:24 +08:00
666ghj 49847c5b26 feat(Step5Interaction): add section number display for improved user navigation 2026-01-16 21:26:11 +08:00
666ghj ede410620a fix(Home.vue): update version text from V1.0 to v0.1 for accuracy 2026-01-14 15:16:52 +08:00
666ghj 8c817120f8 style(HistoryDatabase): update modal layout and enhance user guidance
- Changed the title for the environment configuration status icon to "环境搭建" for clarity.
- Added a creation time display in the project detail modal for better context.
- Introduced a divider for the playback section to improve visual separation.
- Enhanced navigation buttons with step indicators for clearer user progression.
- Added a hint for playback limitations to inform users about simulation requirements.
- Updated CSS styles for new elements and improved overall modal aesthetics.
2026-01-09 17:34:25 +08:00
666ghj 4977324497 style(HistoryDatabase): enhance card header and footer layout with status icons
- Updated card header to include status icons indicating project availability for different functionalities.
- Added a visual indicator for additional files when more than three are present.
- Improved card footer layout by grouping date and time, and enhancing progress display with status colors.
- Introduced new CSS styles for status icons and improved overall card aesthetics.
2026-01-09 16:42:31 +08:00
666ghj 0742194f9c style(HistoryDatabase): enhance modal design and transition effects
- Wrapped modal content in a Transition component for smoother animations.
- Adjusted modal dimensions and padding for improved layout and user experience.
- Updated styles for modal elements, including background colors, borders, and hover effects.
- Enhanced visual feedback for buttons and file items within the modal.
2026-01-09 16:13:37 +08:00
666ghj b4fe7f2f03 feat(HistoryDatabase): add project detail modal for enhanced user interaction
- Implemented a modal to display detailed information about selected projects, including simulation requirements and associated files.
- Added navigation buttons within the modal for quick access to project, simulation, and report pages.
- Enhanced user experience by allowing users to view project details without leaving the main interface.
2026-01-09 15:41:35 +08:00
666ghj aa47087b18 style(HistoryDatabase): adjust padding and max-width for improved layout
- Reduced top padding from 40px to 35px for better spacing.
- Increased max-width of the separator from 200px to 300px to enhance visual balance.
2026-01-09 11:26:27 +08:00
666ghj d79ea2b861 refactor(HistoryDatabase): enhance loading logic and card positioning
- Added route watcher to reload history data when navigating back to the homepage.
- Improved card positioning by adjusting vertical spacing for better visual alignment.
- Initialized IntersectionObserver to manage card visibility more effectively.
- Ensured data loading occurs after DOM rendering for smoother user experience.
2026-01-09 11:22:36 +08:00
666ghj 5e865c0234 refactor(HistoryDatabase): improve project display logic and loading states
- Added conditional rendering for the tech grid background and cards container based on project availability.
- Simplified the empty state display logic when no projects are present.
- Introduced a new CSS class to adjust layout when there are no projects, enhancing visual consistency.
2026-01-09 11:12:10 +08:00
666ghj cdf13739a6 refactor(HistoryDatabase): update card display to show round progress and time
- Changed card header to display round progress instead of status.
- Updated card footer to show formatted time instead of rounds.
- Introduced new methods for calculating progress class and formatting time.
- Adjusted styles for progress display and refined layout for better responsiveness.
2026-01-09 11:08:05 +08:00
666ghj 5a0c705cfb refactor(HistoryDatabase): enhance card expansion logic with pending state management
- Introduced a pending state to track the target expansion state during animations.
- Improved debounce handling to ensure smoother transitions and prevent rapid state changes.
- Updated logic to check for new pending states after animations complete, enhancing responsiveness and stability.
2026-01-09 10:57:48 +08:00