feat: ship v0.7.0 with AI knowledge context integration
Add semi-automatic knowledge suggestions and user-confirmed injection across chat, interactive, auto, and wizard modes; fix writing flows to persist full systemPrompt in contextJson. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 笔临 P6 AI 知识上下文整合 Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [x]`) syntax for tracking.
|
||||
|
||||
**Goal:** 交付 v0.7.0:已审核知识库条目半自动推荐 + 用户勾选确认 + 注入对话/交互/自动/向导四种 AI 模式;修复写作流 `contextJson` 仅存标题摘要的问题。
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
- Modify: `src/shared/ipc-channels.ts`
|
||||
- Modify: `src/main/db/repositories/ai-session.repo.ts`
|
||||
|
||||
- [ ] **Step 1: 扩展 types**
|
||||
- [x] **Step 1: 扩展 types**
|
||||
|
||||
`src/shared/types.ts` 追加:
|
||||
|
||||
@@ -104,7 +104,7 @@ knowledgeAutoSuggest: boolean
|
||||
knowledgeSuggestTopN: number
|
||||
```
|
||||
|
||||
- [ ] **Step 2: IPC 通道**
|
||||
- [x] **Step 2: IPC 通道**
|
||||
|
||||
`src/shared/ipc-channels.ts`:
|
||||
|
||||
@@ -112,7 +112,7 @@ knowledgeSuggestTopN: number
|
||||
KNOWLEDGE_SUGGEST_CONTEXT: 'knowledge:suggestContext',
|
||||
```
|
||||
|
||||
- [ ] **Step 3: ai-session.repo 默认 knowledgeIds**
|
||||
- [x] **Step 3: ai-session.repo 默认 knowledgeIds**
|
||||
|
||||
```typescript
|
||||
const EMPTY_CONTEXT: AiContextBinding = {
|
||||
@@ -139,17 +139,17 @@ function parseContext(json: string): AiContextBinding {
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 全局修补 EMPTY_BINDING**
|
||||
- [x] **Step 4: 全局修补 EMPTY_BINDING**
|
||||
|
||||
搜索 `inspirationIds: []` 且无 `knowledgeIds` 的 `AiContextBinding` 字面量(`ContextEditorModal.tsx`、`useInteractiveStore.ts` 等),全部补上 `knowledgeIds: []`。
|
||||
|
||||
- [ ] **Step 5: build 验证**
|
||||
- [x] **Step 5: build 验证**
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
- [x] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add src/shared/types.ts src/shared/ipc-channels.ts src/main/db/repositories/ai-session.repo.ts
|
||||
@@ -164,7 +164,7 @@ git commit -m "feat: extend AiContextBinding with knowledgeIds for P6"
|
||||
- Create: `src/main/services/knowledge-retrieval.service.ts`
|
||||
- Create: `tests/main/knowledge-retrieval.test.ts`
|
||||
|
||||
- [ ] **Step 1: UT-CTX-01 / UT-CTX-04 失败测试**
|
||||
- [x] **Step 1: UT-CTX-01 / UT-CTX-04 失败测试**
|
||||
|
||||
`tests/main/knowledge-retrieval.test.ts`:
|
||||
|
||||
@@ -254,13 +254,13 @@ describe('KnowledgeRetrievalService', () => {
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 运行确认 FAIL**
|
||||
- [x] **Step 2: 运行确认 FAIL**
|
||||
|
||||
```bash
|
||||
npm run test -- tests/main/knowledge-retrieval.test.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 3: 实现 KnowledgeRetrievalService**
|
||||
- [x] **Step 3: 实现 KnowledgeRetrievalService**
|
||||
|
||||
`src/main/services/knowledge-retrieval.service.ts` 核心:
|
||||
|
||||
@@ -357,13 +357,13 @@ export class KnowledgeRetrievalService {
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行 PASS**
|
||||
- [x] **Step 4: 运行 PASS**
|
||||
|
||||
```bash
|
||||
npm run test -- tests/main/knowledge-retrieval.test.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
- [x] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/main/services/knowledge-retrieval.service.ts tests/main/knowledge-retrieval.test.ts
|
||||
@@ -380,7 +380,7 @@ git commit -m "feat: add KnowledgeRetrievalService with scoring for context sugg
|
||||
- Modify: `tests/main/ai-context-builder.test.ts`
|
||||
- Create: `tests/main/flow-context.test.ts`
|
||||
|
||||
- [ ] **Step 1: UT-CTX-02 / UT-CTX-03 测试**
|
||||
- [x] **Step 1: UT-CTX-02 / UT-CTX-03 测试**
|
||||
|
||||
在 `tests/main/ai-context-builder.test.ts` 追加:
|
||||
|
||||
@@ -483,13 +483,13 @@ describe('flow-context.util', () => {
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 运行确认 FAIL**
|
||||
- [x] **Step 2: 运行确认 FAIL**
|
||||
|
||||
```bash
|
||||
npm run test -- tests/main/ai-context-builder.test.ts tests/main/flow-context.test.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 3: 扩展 ai-context-builder**
|
||||
- [x] **Step 3: 扩展 ai-context-builder**
|
||||
|
||||
要点:
|
||||
|
||||
@@ -522,13 +522,13 @@ export function buildFlowContextPayload(
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行 PASS**
|
||||
- [x] **Step 4: 运行 PASS**
|
||||
|
||||
```bash
|
||||
npm run test -- tests/main/ai-context-builder.test.ts tests/main/flow-context.test.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
- [x] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/main/services/ai-context-builder.service.ts src/main/services/flow-context.util.ts tests/main/
|
||||
@@ -546,7 +546,7 @@ git commit -m "feat: extend AiContextBuilder with knowledge blocks and flow payl
|
||||
- Modify: `src/main/services/global-settings.ts`
|
||||
- Modify: `src/renderer/stores/useSettingsStore.ts`
|
||||
|
||||
- [ ] **Step 1: knowledge.handler 追加**
|
||||
- [x] **Step 1: knowledge.handler 追加**
|
||||
|
||||
```typescript
|
||||
ipcMain.handle(
|
||||
@@ -563,7 +563,7 @@ ipcMain.handle(
|
||||
|
||||
`registerKnowledgeHandlers` 签名改为接收 `GlobalSettingsService`,`topN` 默认 `settings.get().knowledgeSuggestTopN ?? 8`。
|
||||
|
||||
- [ ] **Step 2: global-settings 默认值**
|
||||
- [x] **Step 2: global-settings 默认值**
|
||||
|
||||
```typescript
|
||||
knowledgeAutoSuggest: true,
|
||||
@@ -572,7 +572,7 @@ knowledgeSuggestTopN: 8,
|
||||
|
||||
`get()` merge 补默认。
|
||||
|
||||
- [ ] **Step 3: preload + electron-api.d.ts**
|
||||
- [x] **Step 3: preload + electron-api.d.ts**
|
||||
|
||||
```typescript
|
||||
suggestContext: (
|
||||
@@ -581,13 +581,13 @@ suggestContext: (
|
||||
): Promise<IpcResult<ScoredKnowledge[]>>
|
||||
```
|
||||
|
||||
- [ ] **Step 4: build**
|
||||
- [x] **Step 4: build**
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
- [x] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "feat: add knowledge suggestContext IPC and global settings defaults"
|
||||
@@ -604,7 +604,7 @@ git commit -m "feat: add knowledge suggestContext IPC and global settings defaul
|
||||
- Modify: `src/main/ipc/handlers/wizard.handler.ts`
|
||||
- Modify: `src/main/services/wizard-writing.service.ts`(`buildPreview` 追加知识列表)
|
||||
|
||||
- [ ] **Step 1: interactive confirmContext 存 FlowContextPayload**
|
||||
- [x] **Step 1: interactive confirmContext 存 FlowContextPayload**
|
||||
|
||||
`interactive.handler.ts` `INTERACTIVE_CONFIRM_CONTEXT`:
|
||||
|
||||
@@ -642,7 +642,7 @@ enrichFlow(flow: InteractiveFlow): InteractiveFlow {
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: auto.handler / wizard.handler readContextText**
|
||||
- [x] **Step 2: auto.handler / wizard.handler readContextText**
|
||||
|
||||
替换本地 `readContextText` 为读 `systemPrompt`:
|
||||
|
||||
@@ -660,21 +660,21 @@ function readContextText(registry, bookId, flowId): string {
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: wizard confirmContext 同 interactive**
|
||||
- [x] **Step 3: wizard confirmContext 同 interactive**
|
||||
|
||||
`wizard.handler.ts` `WIZARD_CONFIRM_CONTEXT` 使用 `buildFlowContextPayload`。
|
||||
|
||||
- [ ] **Step 4: buildPreview 追加知识标题**
|
||||
- [x] **Step 4: buildPreview 追加知识标题**
|
||||
|
||||
`WizardWritingService.buildPreview` 返回前,从 `payload.binding.knowledgeIds` 查标题,append `\n将注入知识:A、B、C`。
|
||||
|
||||
- [ ] **Step 5: auto planScenes 前自动 confirm**
|
||||
- [x] **Step 5: auto planScenes 前自动 confirm**
|
||||
|
||||
`AutoPanel` 在 `planScenes` 调用前,若 flow 无 `systemPrompt`,用 session binding + 默认推荐 knowledgeIds 调 `interactive.confirmContext` 等价逻辑(可新增 `auto:confirmContext` IPC 或复用 `buildFlowContextPayload` + `setContextSummary` 扩展为存完整 payload)。
|
||||
|
||||
推荐:新增 `auto.handler` `AUTO_CONFIRM_CONTEXT` 与 interactive 对称。
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
- [x] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "fix: store full systemPrompt in writing flow contextJson for P6"
|
||||
@@ -689,7 +689,7 @@ git commit -m "fix: store full systemPrompt in writing flow contextJson for P6"
|
||||
- Modify: `src/renderer/components/ai/ContextEditorModal.tsx`
|
||||
- Modify: `src/renderer/lib/ai-context-summary.ts`
|
||||
|
||||
- [ ] **Step 1: KnowledgeSuggestList**
|
||||
- [x] **Step 1: KnowledgeSuggestList**
|
||||
|
||||
Props:
|
||||
|
||||
@@ -703,7 +703,7 @@ interface KnowledgeSuggestListProps {
|
||||
|
||||
渲染 checkbox + title + `t(\`knowledge.type.${entry.type}\`)` + reason badges `t(reason)`。
|
||||
|
||||
- [ ] **Step 2: ContextEditorModal 扩展**
|
||||
- [x] **Step 2: ContextEditorModal 扩展**
|
||||
|
||||
新增 props:`goalText?: string`
|
||||
|
||||
@@ -719,7 +719,7 @@ const suggested = await ipcCall(() =>
|
||||
|
||||
新增 Tab `knowledge`;顶部推荐区 + `context-refresh-suggest`;下方 approved 全列表(`knowledge.list(bookId, { status: 'approved' })`)可勾选。
|
||||
|
||||
- [ ] **Step 3: formatContextSummary 含 knowledge**
|
||||
- [x] **Step 3: formatContextSummary 含 knowledge**
|
||||
|
||||
```typescript
|
||||
const counts = { chapter: 0, outline: 0, setting: 0, inspiration: 0, knowledge: 0 }
|
||||
@@ -729,7 +729,7 @@ return t('ai.contextSummary', { ...counts })
|
||||
|
||||
更新 `ai.contextSummary` i18n 为 `{{chapters}}章·{{outlines}}纲·{{settings}}设·{{inspirations}}感·{{knowledge}}知`。
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
- [x] **Step 4: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "feat: add KnowledgeSuggestList and knowledge tab in context editor"
|
||||
@@ -747,25 +747,25 @@ git commit -m "feat: add KnowledgeSuggestList and knowledge tab in context edito
|
||||
- Modify: `src/renderer/stores/useAutoStore.ts`(confirmContext)
|
||||
- Modify: `src/renderer/components/ai/AiPanel.tsx`(传 goalText 空)
|
||||
|
||||
- [ ] **Step 1: InteractivePanel context_confirm**
|
||||
- [x] **Step 1: InteractivePanel context_confirm**
|
||||
|
||||
- mount 时 `suggestContext` → state `suggested`
|
||||
- 内联 `<KnowledgeSuggestList>`,`data-testid="interactive-knowledge-suggest"`
|
||||
- 勾选同步到 session `context.knowledgeIds`(`ai.sessionUpdate`)
|
||||
- `confirmContextAndStart` 传含 `knowledgeIds` 的 binding
|
||||
|
||||
- [ ] **Step 2: AutoPanel**
|
||||
- [x] **Step 2: AutoPanel**
|
||||
|
||||
- `goal_setup` 区域下方折叠「知识上下文」`data-testid="auto-knowledge-suggest"`
|
||||
- `goalText` = `chapterGoal` + 选中大纲 description
|
||||
- `planScenes` 前调用 `auto.confirmContext`(Task 5 新增 IPC)
|
||||
|
||||
- [ ] **Step 3: WizardPanel wizard_context**
|
||||
- [x] **Step 3: WizardPanel wizard_context**
|
||||
|
||||
- 同 Interactive 内联推荐列表 `data-testid="wizard-knowledge-suggest"`
|
||||
- `handleContextClose` 传 `goalText` = goal + styleNote
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
- [x] **Step 4: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "feat: integrate knowledge suggest into interactive auto wizard panels"
|
||||
@@ -779,9 +779,9 @@ git commit -m "feat: integrate knowledge suggest into interactive auto wizard pa
|
||||
- Modify: `public/locales/zh-CN/translation.json`
|
||||
- Modify: `public/locales/en/translation.json`
|
||||
|
||||
- [ ] **Step 1: 追加 spec §9 全部键 + `ai.contextSummary` 更新**
|
||||
- [x] **Step 1: 追加 spec §9 全部键 + `ai.contextSummary` 更新**
|
||||
|
||||
- [ ] **Step 2: Commit**
|
||||
- [x] **Step 2: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "feat: add P6 AI context i18n strings"
|
||||
@@ -794,7 +794,7 @@ git commit -m "feat: add P6 AI context i18n strings"
|
||||
**Files:**
|
||||
- Create: `tests/main/ai-context-integration.test.ts`
|
||||
|
||||
- [ ] **Step 1: IT-CTX-01**
|
||||
- [x] **Step 1: IT-CTX-01**
|
||||
|
||||
```typescript
|
||||
it('IT-CTX-01: suggestContext returns entries when approved exist', () => {
|
||||
@@ -802,11 +802,11 @@ it('IT-CTX-01: suggestContext returns entries when approved exist', () => {
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: IT-CTX-02**
|
||||
- [x] **Step 2: IT-CTX-02**
|
||||
|
||||
通过 `aiContextBuilder.build` 含 knowledgeIds 断言 `systemPrompt` 含 `【知识·`(无需 Electron IPC)。
|
||||
|
||||
- [ ] **Step 3: IT-CTX-03(240s)**
|
||||
- [x] **Step 3: IT-CTX-03(240s)**
|
||||
|
||||
```typescript
|
||||
it('IT-CTX-03: interactive confirm then suggestPlots uses knowledge context', async () => {
|
||||
@@ -816,13 +816,13 @@ it('IT-CTX-03: interactive confirm then suggestPlots uses knowledge context', as
|
||||
}, 240_000)
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行**
|
||||
- [x] **Step 4: 运行**
|
||||
|
||||
```bash
|
||||
npm run test -- tests/main/ai-context-integration.test.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
- [x] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "test: add P6 AI context integration tests"
|
||||
@@ -835,7 +835,7 @@ git commit -m "test: add P6 AI context integration tests"
|
||||
**Files:**
|
||||
- Create: `e2e/ai-context.spec.ts`
|
||||
|
||||
- [ ] **Step 1: E2E-CTX-01**
|
||||
- [x] **Step 1: E2E-CTX-01**
|
||||
|
||||
```typescript
|
||||
test('E2E-CTX-01: context editor knowledge tab shows suggestions', async () => {
|
||||
@@ -843,7 +843,7 @@ test('E2E-CTX-01: context editor knowledge tab shows suggestions', async () => {
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: E2E-CTX-02**
|
||||
- [x] **Step 2: E2E-CTX-02**
|
||||
|
||||
```typescript
|
||||
test('E2E-CTX-02: interactive context_confirm shows knowledge suggest', async () => {
|
||||
@@ -851,7 +851,7 @@ test('E2E-CTX-02: interactive context_confirm shows knowledge suggest', async ()
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 3: E2E-CTX-03(300s)**
|
||||
- [x] **Step 3: E2E-CTX-03(300s)**
|
||||
|
||||
```typescript
|
||||
test('E2E-CTX-03: chat with knowledge context gets AI reply', async () => {
|
||||
@@ -860,13 +860,13 @@ test('E2E-CTX-03: chat with knowledge context gets AI reply', async () => {
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行**
|
||||
- [x] **Step 4: 运行**
|
||||
|
||||
```bash
|
||||
npm run test:e2e -- e2e/ai-context.spec.ts
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
- [x] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "test: add P6 AI context E2E specs"
|
||||
@@ -882,15 +882,15 @@ git commit -m "test: add P6 AI context E2E specs"
|
||||
- Modify: `src/renderer/components/settings/SettingsPage.tsx`(about 版本号)
|
||||
- Modify: `docs/superpowers/plans/2026-07-07-bilin-p6-ai-context.md`(勾选完成项)
|
||||
|
||||
- [ ] **Step 1: 版本号 `0.7.0`**
|
||||
- [x] **Step 1: 版本号 `0.7.0`**
|
||||
|
||||
- [ ] **Step 2: README 追加**
|
||||
- [x] **Step 2: README 追加**
|
||||
|
||||
```markdown
|
||||
- 知识库 AI 上下文:半自动推荐 + 勾选注入四种写作模式(P6)
|
||||
```
|
||||
|
||||
- [ ] **Step 3: 全量测试**
|
||||
- [x] **Step 3: 全量测试**
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
@@ -898,7 +898,7 @@ npm run test
|
||||
npm run test:e2e
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
- [x] **Step 4: Commit**
|
||||
|
||||
```bash
|
||||
git commit -m "feat: ship v0.7.0 with AI knowledge context integration"
|
||||
|
||||
Reference in New Issue
Block a user