diff --git a/README.md b/README.md index 990a17c..5201101 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - **项目 `/overview`**:单行项目列表,部署中的排在前面;仅保留部署状态、环境/版本、时间和日志入口。支持部署中、最近失败与项目搜索。 - **记录 `/runs`**:按项目、环境、状态和关键词查询,每页 20 条。打开记录抽屉后查看步骤、统一输出和 Jenkins 日志。 -- **助手**:首页直接提问,或从顶部打开右侧抽屉。可问最近部署、纳管项目、构建结果及失败原因;后端模型自主调用只读工具,回答附来源。 +- **助手**:首页直接提问,或从顶部打开右侧抽屉。可问最近部署、纳管项目、构建结果及失败原因;后端模型查询事实并准备发布、回滚、取消和重试计划;回答附来源,操作必须核对后点击确认执行。 - **更多功能**:发布、接入、成员权限和设置统一收进顶部菜单。生产发布保留确认要求,权限由后端校验。 登录由后端识别角色,无需先选择管理员或成员。原有 `/releases`、`/projects`、`/members`、`/settings` 链接保留。 @@ -61,6 +61,8 @@ npm run build 前端不直连 Jenkins、Gitea、通知或模型供应商。发布步骤来源为服务端 `run.steps`,统一以 `nodeId` 定位;状态机、权限、幂等、审计和脱敏由后端负责。 -运维助手限于 DevOps,只提供查询与分析;发布、取消、重试仍通过明确操作与权限检查执行。 +运维助手限于 DevOps。模型不能执行任意命令或直接触发部署;操作卡片由后端签名,绑定操作者、具体提交和 10 分钟有效期,确认时重新检查权限与环境状态。历史问答中的计划不可直接执行。 + +发布页只保留目标版本和生产确认。发布记录中的“回滚到此版本”会重新构建历史成功记录的精确提交;回滚不撤销数据库迁移或外部数据。流水线需支持 `DEPLOY_COMMIT`,无法核实历史 SHA 时明确拒绝。 MIT License。环境文件与真实凭据不得进入 Git。 diff --git a/RTK.md b/RTK.md index 3562870..f28284e 100644 --- a/RTK.md +++ b/RTK.md @@ -2,9 +2,9 @@ 技术栈保持 Vue 3 + Vite + TypeScript + Element Plus + Pinia。所有业务数据统一经后端 API,不提供前端业务 mock 降级。 -- `/overview`:精简项目列表,部署中优先,直接查看日志;首页可以向只读助手提问。 +- `/overview`:精简项目列表,部署中优先,直接查看日志;首页可以向运维助手提问。 - `/runs?projectKey=…&environment=…&status=…&q=…&page=…&runId=…`:查询、分页、步骤与日志抽屉。 -- 顶部助手:真实远程模型通过后端自主调用只读工具;回答显示真实来源。没有独立侧栏页面或泛聊天能力。 +- 顶部助手:真实远程模型通过后端查询并准备操作计划,用户确认后由后端执行;回答显示真实来源。没有独立侧栏页面或泛聊天能力。 - 顶部更多菜单:`/releases`、`/projects`、`/members`、`/settings` 保留,管理路由继续按权限保护。 - `/settings?tab=integrations|notifications|audit|agent`:集成、通知、审计、模型配置。 - `/login`:统一登录;角色由后端识别;保留首次改密。 diff --git a/docs/minimal-workspace-verification.md b/docs/minimal-workspace-verification.md index 4f64ed6..8f0049f 100644 --- a/docs/minimal-workspace-verification.md +++ b/docs/minimal-workspace-verification.md @@ -1,4 +1,4 @@ -# 极简部署与只读 Agent 验证 +# 极简部署与确认操作验证 本记录说明上线前的验证范围。生产发布由现有 Gitea master webhook → Jenkins → 部署脚本执行,实际结果以目标构建和线上接口验收为准。 @@ -10,7 +10,7 @@ ## 自动化 -- 前端 `npm test`:12 项回归,覆盖请求、排序、权限、迟到请求和有界助手上下文。 +- 前端 `npm test`:14 项回归,覆盖请求、排序、权限、迟到请求和有界助手上下文。 - 前端 `npm run build`:TypeScript 与 Vite 生产构建。 - 后端 `npm run lint`、`npm test -- --runInBand`、`npm run prisma:generate`、`npm run build`。 - 后端回归额外覆盖只读工具、授权范围、模型循环/并发上限、流式读取大小、密钥脱敏和个人历史隔离。 @@ -28,3 +28,9 @@ Vite 仍有依赖内部 `@vueuse/core` 的两条 PURE annotation 提示,不阻 - 生产已验证真实数据库问答、持久化来源,以及 API #62 / Web #45 成功构建;后续轻量发现与公开构建链接补丁仍需按各自目标构建验收。 服务器基线:约 3.7GB 总内存、约 1.4GB 可用,API RSS 约 110MB。API 与 Web 顺序部署,避免同时构建。 + +## 本轮确认操作 + +移除回滚方案、发布窗口、通知对象三个留档必填项,以及重复的发布检查卡片。Agent 来源默认折叠,系统设置移除“等待后端说明”等实现提示。 + +新增签名操作计划和真实历史提交回滚,模型只准备,用户核对后执行。单元验证覆盖过期、篡改、跨账号、权限撤销、环境漂移、幂等、并发、精确提交与历史令牌去除;流水线升级脚本保留参数选择器,并通过 Jenkins Declarative 校验。本轮生产结果与实际操作回执在发布验收时另行核实。 diff --git a/src/components/GlobalAgentDrawer.vue b/src/components/GlobalAgentDrawer.vue index 3bd1059..2eff371 100644 --- a/src/components/GlobalAgentDrawer.vue +++ b/src/components/GlobalAgentDrawer.vue @@ -1,4 +1,5 @@ + + diff --git a/src/services/devopsApi.ts b/src/services/devopsApi.ts index 993a477..4498f3d 100644 --- a/src/services/devopsApi.ts +++ b/src/services/devopsApi.ts @@ -3,6 +3,8 @@ */ import type { AgentCard, + OperationPlan, + PrepareOperationPayload, AgentQuestionPayload, AgentConfigSummary, AgentConnectionTestResult, @@ -111,6 +113,9 @@ interface BackendDeployRun { environment?: EnvironmentName ref?: string status?: BackendRunStatus + resolvedCommit?: string + operationKind?: 'deploy' | 'rollback' | 'retry' + sourceRunId?: string trigger?: 'manual' | 'gitea_webhook' | 'retry' | 'jenkins_external' operator?: string jenkinsQueueId?: string | number @@ -423,6 +428,15 @@ export const devopsApi = { return (await fetchRuns()).map((run) => toReleaseRun(run, projectList)) }, + async prepareOperation(payload: PrepareOperationPayload): Promise { + const { data } = await http.post('/operations/prepare', payload, {timeout: 45_000}) + return data + }, + async executeOperation(confirmationToken: string, projectList: ProjectConfig[]): Promise { + const { data } = await http.post<{run:BackendDeployRun}>('/operations/execute', {confirmationToken,confirmed:true}, {timeout:45_000}) + return toReleaseRun(data.run,projectList) + }, + async createDeployRun( payload: CreateDeployRunPayload, projectList: ProjectConfig[] = [], @@ -1076,6 +1090,9 @@ function toReleaseRun(run: BackendDeployRun, projectList: ProjectConfig[]): Rele jenkinsBuildNumber: run.jenkinsBuildNumber, jenkinsBuildUrl: run.jenkinsBuildUrl, jenkinsSummary: formatJenkinsBuild(run), + resolvedCommit: run.resolvedCommit, + operationKind: run.operationKind, + sourceRunId: run.sourceRunId, commitSummary: ref === '-' ? trigger : `${ref} · ${trigger}`, steps: (Array.isArray(run.steps) ? run.steps : []) .slice() diff --git a/src/services/operationConfirmation.ts b/src/services/operationConfirmation.ts new file mode 100644 index 0000000..d5772cb --- /dev/null +++ b/src/services/operationConfirmation.ts @@ -0,0 +1,27 @@ +import { ElMessageBox } from 'element-plus' +import type { OperationPlan } from '../types/devops' + +/** 只展示服务端核实的目标,不使用模型文本执行操作。 */ +export async function confirmOperation(plan: OperationPlan): Promise { + if (!plan.confirmationToken || Date.parse(plan.expiresAt) <= Date.now()) + throw new Error('操作计划已过期,请重新生成') + const environment = plan.environment === 'production' ? '生产' : '测试' + const message = `${plan.projectKey} / ${environment}\n目标版本:${plan.ref}${plan.commit ? `\n锁定提交:${plan.commit}` : ''}${plan.kind === 'rollback' ? '\n将重新构建并部署此历史提交;数据库与外部数据不会随代码回滚。' : ''}` + try { + await ElMessageBox.confirm( + message, + `确认${plan.title}${environment === '生产' ? '到生产环境' : ''}`, + { + confirmButtonText: `确认${plan.title}`, + cancelButtonText: '返回', + type: 'warning', + autofocus: false, + customClass: 'operation-confirmation', + }, + ) + return true + } catch (error) { + if (error === 'cancel' || error === 'close') return false + throw error + } +} diff --git a/src/stores/assistant.ts b/src/stores/assistant.ts index 54f4b32..722a11a 100644 --- a/src/stores/assistant.ts +++ b/src/stores/assistant.ts @@ -1,7 +1,7 @@ import { defineStore } from 'pinia' import { ref } from 'vue' import { devopsApi } from '../services/devopsApi' -import type { AgentInvocation, AgentSource, AgentToolTrace } from '../types/devops' +import type { AgentInvocation, AgentSource, AgentToolTrace, OperationPlan } from '../types/devops' export type AssistantMessage = { id: string @@ -10,6 +10,7 @@ export type AssistantMessage = { status: 'success' | 'failed' sources?: AgentSource[] tools?: AgentToolTrace[] + operationPlans?: OperationPlan[] } export const useAssistantStore = defineStore('assistant', () => { const isOpen = ref(false) @@ -83,6 +84,7 @@ export const useAssistantStore = defineStore('assistant', () => { status: result.status === 'success' ? 'success' : 'failed', sources: result.sources, tools: result.toolExecutions, + operationPlans: result.operationPlans, }) } catch (error) { if (current !== generation) return @@ -127,6 +129,7 @@ export const useAssistantStore = defineStore('assistant', () => { status: record.status === 'success' ? 'success' : 'failed', sources: record.sources, tools: record.toolExecutions, + operationPlans: record.operationPlans, }, ] } diff --git a/src/stores/platform.ts b/src/stores/platform.ts index 9304127..6a32a94 100644 --- a/src/stores/platform.ts +++ b/src/stores/platform.ts @@ -142,6 +142,13 @@ export const usePlatformStore = defineStore('platform', () => { integrationConfig.value = { checkedAt: '', integrations: [] } } + async function executeOperation(confirmationToken: string) { + const currentGeneration = generation + const run = await devopsApi.executeOperation(confirmationToken, projects.value) + if (currentGeneration === generation) upsertRun(run) + return run + } + async function createDeployRun(payload: CreateDeployRunPayload) { const currentGeneration = generation const run = await devopsApi.createDeployRun(payload, projects.value) @@ -434,6 +441,7 @@ export const usePlatformStore = defineStore('platform', () => { canBuildProject, loadAll, createDeployRun, + executeOperation, cancelDeployRun, retryDeployRun, syncJenkinsRun, diff --git a/src/style.css b/src/style.css index d3f7052..fc826cc 100644 --- a/src/style.css +++ b/src/style.css @@ -337,3 +337,5 @@ a { padding: 0; overflow: hidden; } + +.operation-confirmation .el-message-box__message { white-space: pre-line; overflow-wrap: anywhere; } diff --git a/src/types/devops.ts b/src/types/devops.ts index b87ce6d..6a3e502 100644 --- a/src/types/devops.ts +++ b/src/types/devops.ts @@ -373,6 +373,9 @@ export interface ReleaseRun { jenkinsBuildUrl?: string jenkinsSummary?: string commitSummary: string + resolvedCommit?: string + operationKind?: 'deploy' | 'rollback' | 'retry' + sourceRunId?: string steps: PipelineStep[] } @@ -532,6 +535,7 @@ export interface AgentInvocation { sources?: AgentSource[] toolExecutions?: AgentToolTrace[] createdAt: string + operationPlans?: OperationPlan[] } export interface CreateAgentInvocationPayload { @@ -561,3 +565,21 @@ export interface AgentConnectionTestResult { message: string checkedAt: string } + +export interface OperationPlan { + id: string + kind: 'deploy' | 'rollback' | 'cancel' | 'retry' + title: string + projectKey: string + environment: EnvironmentName + ref: string + commit?: string + sourceRunId?: string + baselineRunId?: string + expiresAt: string + confirmationToken?: string +} +export type PrepareOperationPayload = + | { kind: 'deploy'; projectKey: string; environment: EnvironmentName; ref?: string } + | { kind: 'rollback'; projectKey?: string; environment?: EnvironmentName; runId?: string } + | { kind: 'cancel' | 'retry'; runId: string } diff --git a/src/views/ReleaseCenterView.vue b/src/views/ReleaseCenterView.vue index 83d059f..36fc5d0 100644 --- a/src/views/ReleaseCenterView.vue +++ b/src/views/ReleaseCenterView.vue @@ -1,24 +1,30 @@