Initial TrueGrowth source import

This commit is contained in:
2026-07-07 09:36:36 +08:00
commit 3b6781d695
2283 changed files with 691996 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
## Context
Prompt optimization is used by AI input, generation tools, PPT outline prompts, and music creation. The current prompt builder lives in the image/video generation utility and only understands broad model types.
## Decisions
- Use scenario IDs as the public routing key. Scenario IDs keep optimization intent separate from storage history buckets.
- Use Knowledge Base notes as the user-editable template store. Notes are matched by `metadata.sourceUrl = aitu://prompt-optimization/<scenarioId>`.
- Always append a system-controlled input block containing original prompt and requirements so a user-edited template cannot drop required runtime data.
- Restore missing or empty template notes from built-in defaults, but never overwrite non-empty user-edited notes.
## Risks
- Knowledge Base access is asynchronous, so prompt construction is async and must stay inside the existing optimize request flow.
- PPT prompt history and optimization type are intentionally separate. Public PPT prompts use `ppt-common`; slide prompts keep image history behavior.
- Large prompt templates must remain in note content, not note metadata, to avoid bloating list reads.

View File

@@ -0,0 +1,14 @@
# Change: Refactor Prompt Optimization Public Capability
## Why
Prompt optimization is now embedded in several UI entrypoints with shared behavior but coarse scene prompts. Each scene needs a different optimization direction, and users should be able to tune those directions without changing code.
## What Changes
- Extract prompt optimization scenario registry, prompt building, and result normalization into a shared service.
- Add a shared prompt optimization button component for common icon, tooltip, dialog, and fill-back behavior.
- Store scenario-specific optimization templates as editable Knowledge Base notes under a "提示词优化" directory.
- Keep built-in templates as fallback and automatically restore missing or empty template notes.
## Impact
- Affected specs: prompt-optimization
- Affected code: shared prompt optimization dialog/button, AI input bar, image/video prompt input, PPT outline prompts, music analyzer create page, Knowledge Base note access.

View File

@@ -0,0 +1,33 @@
## ADDED Requirements
### Requirement: Scenario-Based Prompt Optimization
The system SHALL route prompt optimization through a shared scenario registry that defines the optimization type, default mode, history bucket, display name, and built-in template for each supported entrypoint.
#### Scenario: Existing entrypoints use distinct scenarios
- **WHEN** a user opens prompt optimization from AI input, image/video tools, PPT outline prompts, or music creation
- **THEN** the optimizer uses the scenario assigned to that entrypoint rather than only the broad generation type
### Requirement: Knowledge Base Template Overrides
The system SHALL store prompt optimization templates as editable Knowledge Base notes in a "提示词优化" directory and prefer those note contents over built-in templates.
#### Scenario: User edits a template note
- **WHEN** the template note for a scenario has non-empty user-edited content
- **THEN** future optimizations for that scenario use the edited content
#### Scenario: Template note is missing or empty
- **WHEN** the directory or scenario note is missing, or the note content is empty
- **THEN** the system restores the built-in default template and continues optimization
### Requirement: Required Runtime Inputs
The system SHALL append the original prompt and supplemental requirements to every optimization request outside of the editable template content.
#### Scenario: Template omits variables
- **WHEN** a user-edited template does not include `{{originalPrompt}}` or `{{requirements}}`
- **THEN** the optimization request still contains the original prompt and requirements in a system-controlled input block
### Requirement: Shared Prompt Optimization UI
The system SHALL provide a shared prompt optimization button that opens the shared dialog, supports tooltip placement and styling overrides, and fills optimized prompts back to the caller.
#### Scenario: Caller applies optimized prompt
- **WHEN** the user applies an optimized draft from the dialog
- **THEN** the caller receives the optimized prompt through its existing fill-back handler

View File

@@ -0,0 +1,11 @@
## 1. Implementation
- [x] 1.1 Add shared prompt optimization service with scenario registry and Knowledge Base template loading/restoration.
- [x] 1.2 Add shared prompt optimization button component.
- [x] 1.3 Update prompt optimization dialog to consume scenario IDs and async prompt building.
- [x] 1.4 Migrate AI input, image/video prompt input, PPT outline, and music create-song entrypoints.
- [x] 1.5 Move legacy prompt optimization exports out of generation tool utilities.
## 2. Verification
- [x] 2.1 Add/adjust unit tests for scenario registry, Knowledge Base fallback, variable rendering, and dialog scenario behavior.
- [x] 2.2 Run OpenSpec validation.
- [x] 2.3 Run targeted lint/type/test checks.