修复: 安全加固+DRY 收敛+文档同步+测试补齐

安全:
- ScriptNode 默认黑名单兜底(rm/del/format/shutdown/mkfs/dd)
- bind_directory 分段 .. 检测替代 contains 子串(对齐 tool_registry)
- ai_providers 白名单移除 api_key(防 update_field 旁路写明文)

DRY:
- useAiEvents 抽 cleanupTerminatedConversation 统一三分支收尾
- 新增 useStoreAction 工具,4 个 store 替换 38 处 try/catch 样板

文档:
- df-core → df-types 批量替换(ARCHITECTURE/PROGRESS/SQLite-CRUD)
- INDEX 补齐 9 漏列文档(单对话并行多轮/跑题试验/工程系统设计等)
- Agent架构说明 死链修复(../构想审查/)
- AI对话引擎工具清单改为数量+按风险分组(不再用固定数字)
- ARCH 状态标签 设计阶段 → Phase 2 验证

测试:
- df-relay 新增 registry_test: ConnRegistry 路由 + RelayState + 16 项单测
This commit is contained in:
lxy
2026-06-29 21:57:07 +08:00
parent dfed588b54
commit ff3f153d45
17 changed files with 761 additions and 563 deletions
+13 -20
View File
@@ -1,6 +1,7 @@
import { ideaApi } from '@/api'
import type { IdeaQuery } from '@/api/types'
import { t } from '@/i18n/i18n-helpers'
import { runWithCatch } from '@/composables/useStoreAction'
import { state } from './state'
/** 灵感 CRUD 子 store(共享全局 state) */
@@ -13,22 +14,18 @@ export function createIdeasStore() {
* - 不传 → 全量(created_at DESC,等价旧行为)。
*/
async function loadIdeas(query?: IdeaQuery) {
try {
await runWithCatch(state, t('ideas.err.loadFailed'), async () => {
state.ideas = await ideaApi.list(query)
} catch (e: any) {
state.error = e?.toString() ?? t('ideas.err.loadFailed')
}
})
}
async function createIdea(input: { title: string; description?: string; priority?: number; tags?: string; source?: string }) {
try {
const record = await ideaApi.create(input)
state.ideas.push(record)
return record
} catch (e: any) {
state.error = e?.toString() ?? t('ideas.err.createFailed')
return null
}
const record = await runWithCatch(state, t('ideas.err.createFailed'), async () => {
const r = await ideaApi.create(input)
state.ideas.push(r)
return r
})
return record ?? null
}
async function updateIdea(id: string, field: string, value: string) {
@@ -40,12 +37,10 @@ export function createIdeasStore() {
}
async function deleteIdea(id: string) {
try {
await runWithCatch(state, t('ideas.err.deleteFailed'), async () => {
await ideaApi.delete(id)
state.ideas = state.ideas.filter(i => i.id !== id)
} catch (e: any) {
state.error = e?.toString() ?? t('ideas.err.deleteFailed')
}
})
}
async function evaluateIdea(id: string) {
@@ -62,12 +57,10 @@ export function createIdeasStore() {
}
async function relateIdeas(subjectId: string, targetIds: string[]) {
try {
await runWithCatch(state, t('ideas.err.relateFailed'), async () => {
await ideaApi.relateIdeas(subjectId, targetIds)
await loadIdeas() // 后端已原子更新全部受影响灵感,刷新列表保持 store 一致
} catch (e: any) {
state.error = e?.toString() ?? t('ideas.err.relateFailed')
}
})
}
return {
+19 -29
View File
@@ -1,6 +1,7 @@
import { projectApi } from '@/api'
import type { ImportProjectInput, ProjectQuery } from '@/api/project'
import { t } from '@/i18n/i18n-helpers'
import { runWithCatch } from '@/composables/useStoreAction'
import { state, clearError } from './state'
/** 项目 CRUD 子 store(共享全局 state) */
@@ -12,36 +13,29 @@ export function createProjectsStore() {
async function loadProjects(query?: ProjectQuery) {
state.loading = true
state.error = null
try {
await runWithCatch(state, t('projects.err.loadFailed'), async () => {
state.projects = await projectApi.list(query)
} catch (e: any) {
state.error = e?.toString() ?? t('projects.err.loadFailed')
} finally {
state.loading = false
}
})
state.loading = false
}
async function createProject(name: string, description = '', ideaId?: string, path?: string, stack?: string) {
try {
const record = await projectApi.create({ name, description, idea_id: ideaId, path, stack })
state.projects.push(record)
return record
} catch (e: any) {
state.error = e?.toString() ?? t('projects.err.createFailed')
return null
}
const record = await runWithCatch(state, t('projects.err.createFailed'), async () => {
const r = await projectApi.create({ name, description, idea_id: ideaId, path, stack })
state.projects.push(r)
return r
})
return record ?? null
}
/** 导入历史项目(选已存在目录,后端创建+绑定+探测栈+读 README 首段一步完成) */
async function importProject(input: ImportProjectInput) {
try {
const record = await projectApi.importProject(input)
const record = await runWithCatch(state, t('projects.err.importFailed'), async () => {
const r = await projectApi.importProject(input)
await loadProjects() // 刷新列表(后端已 insert,统一走 load 避免本地数组与后端不一致)
return record
} catch (e: any) {
state.error = e?.toString() ?? t('projects.err.importFailed')
return null
}
return r
})
return record ?? null
}
async function updateProject(id: string, field: string, value: string) {
@@ -61,20 +55,16 @@ export function createProjectsStore() {
}
async function deleteProject(id: string) {
try {
await runWithCatch(state, t('projects.err.deleteFailed'), async () => {
await projectApi.delete(id) // 软删 → 回收站(可恢复)
state.projects = state.projects.filter(p => p.id !== id)
} catch (e: any) {
state.error = e?.toString() ?? t('projects.err.deleteFailed')
}
})
}
async function loadDeletedProjects() {
try {
await runWithCatch(state, t('projects.err.loadTrashFailed'), async () => {
state.deletedProjects = await projectApi.listDeleted()
} catch (e: any) {
state.error = e?.toString() ?? t('projects.err.loadTrashFailed')
}
})
}
async function restoreProject(id: string) {
+13 -20
View File
@@ -1,6 +1,7 @@
import { taskApi } from '@/api'
import type { TaskQuery } from '@/api/types'
import { t } from '@/i18n/i18n-helpers'
import { runWithCatch } from '@/composables/useStoreAction'
import { state } from './state'
/** 任务 CRUD 子 store(共享全局 state) */
@@ -16,43 +17,35 @@ export function createTasksStore() {
* status/keyword 下沉后端 WHERE(P1/P2),取代 Tasks.vue 旧的前端内存 filter。
*/
async function loadTasks(queryOrProjectId?: TaskQuery | string) {
try {
await runWithCatch(state, t('tasks.err.loadFailed'), async () => {
state.tasks = await taskApi.list(queryOrProjectId)
} catch (e: any) {
state.error = e?.toString() ?? t('tasks.err.loadFailed')
}
})
}
async function createTask(input: { project_id: string; title: string; description?: string; priority?: number; branch_name?: string; assignee?: string; idea_id?: string }) {
try {
const record = await taskApi.create(input)
state.tasks.push(record)
return record
} catch (e: any) {
state.error = e?.toString() ?? t('tasks.err.createFailed')
return null
}
const record = await runWithCatch(state, t('tasks.err.createFailed'), async () => {
const r = await taskApi.create(input)
state.tasks.push(r)
return r
})
return record ?? null
}
async function updateTask(id: string, field: string, value: string) {
try {
await runWithCatch(state, t('tasks.err.updateFailed'), async () => {
await taskApi.update(id, field, value)
const idx = state.tasks.findIndex(t => t.id === id)
if (idx >= 0) {
(state.tasks[idx] as any)[field] = value
}
} catch (e: any) {
state.error = e?.toString() ?? t('tasks.err.updateFailed')
}
})
}
async function deleteTask(id: string) {
try {
await runWithCatch(state, t('tasks.err.deleteFailed'), async () => {
await taskApi.delete(id)
state.tasks = state.tasks.filter(t => t.id !== id)
} catch (e: any) {
state.error = e?.toString() ?? t('tasks.err.deleteFailed')
}
})
}
return {