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,21 @@
# Change: 生成工具支持知识库上下文
## Why
内部生成工具已沉淀图片、视频、音频等工作流,但用户常需要复用知识库笔记中的设定、风格、品牌和项目资料。当前生成请求缺少轻量、可控的知识库上下文引用能力。
## What Changes
- 为内部生成工具新增“本次上下文”知识库笔记选择能力
- 生成请求只保存轻量 refs执行时再按需读取笔记内容
- 执行时对上下文做长度截断与失效降级,避免大内存占用和任务失败
- 明确 Chat-MJ 等外部 iframe 工具不支持该能力
## Impact
- Affected specs:
- `generation-context-library`
- Affected code:
- 内部生成工具入口与任务提交上下文
- 知识库笔记读取服务
- 生成任务执行与提示词组装链路

View File

@@ -0,0 +1,63 @@
## ADDED Requirements
### Requirement: Internal Generation Context Selection
The system SHALL allow supported internal generation tools to select knowledge-base notes as context for the current generation request.
#### Scenario: Select notes for the current request
- **GIVEN** the user is using an internal generation tool that supports generation context
- **WHEN** the user selects one or more knowledge-base notes
- **THEN** the tool SHALL attach those notes as current-request context
- **AND** the selected context SHALL be visible and removable before submission
#### Scenario: Keep context scoped to the request
- **GIVEN** the user has selected knowledge-base notes for one generation request
- **WHEN** the request is submitted
- **THEN** the system SHALL pass the selected note refs with that request
- **AND** it SHALL NOT implicitly apply them to unrelated future requests unless the user selects them again
### Requirement: Lightweight Context References
The system SHALL persist only lightweight references for selected knowledge-base context.
#### Scenario: Store selected context refs
- **WHEN** a generation request or task stores selected knowledge-base context
- **THEN** it SHALL store lightweight refs such as note id, title snapshot, and updated-at snapshot
- **AND** it SHALL NOT store full note bodies, embedded media payloads, base64 data, or large serialized markdown in durable task state
### Requirement: On-Demand Context Loading
The system SHALL read selected knowledge-base notes on demand during generation execution and bound the content added to prompts.
#### Scenario: Load context at execution time
- **GIVEN** a generation task contains knowledge-base note refs
- **WHEN** the task starts execution
- **THEN** the executor SHALL read the latest available note content for those refs
- **AND** it SHALL combine the readable content with the user prompt before calling the provider
#### Scenario: Truncate oversized context
- **GIVEN** selected knowledge-base notes exceed the configured context budget
- **WHEN** the executor prepares the provider prompt
- **THEN** it SHALL truncate or omit excess context deterministically
- **AND** it SHALL avoid loading or concatenating unbounded note content in memory
### Requirement: Missing Context Degradation
The system SHALL degrade gracefully when selected knowledge-base context is empty, deleted, or unreadable.
#### Scenario: Empty note is selected
- **GIVEN** a selected knowledge-base note has no usable text content
- **WHEN** generation execution prepares context
- **THEN** the executor SHALL skip that note
- **AND** it SHALL continue generation with the remaining context and user prompt
#### Scenario: Note was deleted or cannot be read
- **GIVEN** a generation task references a note that no longer exists or cannot be read
- **WHEN** the task starts execution
- **THEN** the executor SHALL skip the unavailable note
- **AND** it SHALL continue generation instead of failing solely because that context is unavailable
### Requirement: External Iframe Tool Exclusion
The system SHALL NOT expose knowledge-base generation context selection for external iframe tools such as Chat-MJ.
#### Scenario: Open Chat-MJ iframe tool
- **GIVEN** the user opens Chat-MJ or another external iframe generation tool
- **WHEN** the tool UI is rendered
- **THEN** the system SHALL NOT show the knowledge-base context selector in that iframe tool
- **AND** it SHALL NOT attempt to inject selected note content into the external iframe request

View File

@@ -0,0 +1,19 @@
# Tasks: 生成工具支持知识库上下文
## 1. 上下文选择
- [x] 1.1 在内部生成工具中提供知识库笔记选择入口
- [x] 1.2 将已选笔记作为本次请求上下文展示、移除和随请求提交
- [x] 1.3 隐藏或禁用 Chat-MJ 等外部 iframe 工具的上下文选择入口
## 2. 轻量引用与执行读取
- [x] 2.1 请求与任务记录仅保存笔记 id、标题快照、更新时间等轻量 refs
- [x] 2.2 任务执行时按需读取最新可用笔记内容
- [x] 2.3 对读取内容做长度截断、数量限制和安全拼接
## 3. 降级与验证
- [x] 3.1 空笔记、删除笔记、读取失败时跳过该上下文并继续生成
- [x] 3.2 增加覆盖轻量 refs、截断、降级和 iframe 不支持的测试
- [x] 3.3 手动验证图片、视频、音频内部生成工具的上下文传递