新增: 初始化 DevFlow 项目仓库
Tauri 2 + Vue 3 + Vite 6 桌面应用,Rust workspace 含 13 个 crate (df-ai / df-storage / df-workflow / df-core / df-execute 等)。 核心能力:AI 聊天 agentic 循环(工具调用+人工审批)、工作流引擎、 任务/想法/项目/阶段管理、可追溯性,及配套前端组件。
This commit is contained in:
11
crates/df-core/Cargo.toml
Normal file
11
crates/df-core/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "df-core"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
49
crates/df-core/src/error.rs
Normal file
49
crates/df-core/src/error.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
//! 统一错误类型定义
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
/// 统一错误类型
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("未找到: {0}")]
|
||||
NotFound(String),
|
||||
|
||||
#[error("已存在: {0}")]
|
||||
AlreadyExists(String),
|
||||
|
||||
#[error("验证失败: {0}")]
|
||||
Validation(String),
|
||||
|
||||
#[error("状态错误: 当前状态 {current}, 期望 {expected}")]
|
||||
InvalidState {
|
||||
current: String,
|
||||
expected: String,
|
||||
},
|
||||
|
||||
#[error("工作流错误: {0}")]
|
||||
Workflow(String),
|
||||
|
||||
#[error("执行错误: {0}")]
|
||||
Execution(String),
|
||||
|
||||
#[error("存储错误: {0}")]
|
||||
Storage(String),
|
||||
|
||||
#[error("插件错误: {0}")]
|
||||
Plugin(String),
|
||||
|
||||
#[error("AI 提供者错误: {0}")]
|
||||
AiProvider(String),
|
||||
|
||||
#[error("配置错误: {0}")]
|
||||
Config(String),
|
||||
|
||||
#[error("IO 错误: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
#[error("序列化错误: {0}")]
|
||||
Serialization(#[from] serde_json::Error),
|
||||
}
|
||||
|
||||
/// 统一 Result 别名
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
74
crates/df-core/src/events.rs
Normal file
74
crates/df-core/src/events.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
//! 工作流事件定义
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::NodeId;
|
||||
|
||||
/// 人工审批响应
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct HumanApprovalResponse {
|
||||
pub execution_id: String,
|
||||
pub node_id: NodeId,
|
||||
pub decision: String,
|
||||
pub comment: Option<String>,
|
||||
}
|
||||
|
||||
/// 工作流事件
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum WorkflowEvent {
|
||||
/// 节点开始执行
|
||||
NodeStarted {
|
||||
node_id: NodeId,
|
||||
},
|
||||
/// 节点执行进度更新
|
||||
NodeProgress {
|
||||
node_id: NodeId,
|
||||
progress: f32,
|
||||
message: String,
|
||||
},
|
||||
/// 节点产生输出
|
||||
NodeOutput {
|
||||
node_id: NodeId,
|
||||
output: String,
|
||||
},
|
||||
/// 节点执行完成
|
||||
NodeCompleted {
|
||||
node_id: NodeId,
|
||||
duration_ms: u64,
|
||||
},
|
||||
/// 节点执行失败
|
||||
NodeFailed {
|
||||
node_id: NodeId,
|
||||
error: String,
|
||||
},
|
||||
/// 工作流暂停(等待外部输入)
|
||||
WorkflowPaused {
|
||||
reason: String,
|
||||
waiting_node: NodeId,
|
||||
},
|
||||
/// 工作流执行完成
|
||||
WorkflowCompleted {
|
||||
total_duration_ms: u64,
|
||||
},
|
||||
/// 工作流执行失败
|
||||
WorkflowFailed {
|
||||
error: String,
|
||||
failed_node: NodeId,
|
||||
},
|
||||
/// 人工审批请求
|
||||
HumanApprovalRequest {
|
||||
execution_id: String,
|
||||
node_id: NodeId,
|
||||
title: String,
|
||||
description: String,
|
||||
options: Vec<String>,
|
||||
},
|
||||
/// 人工审批响应
|
||||
HumanApprovalResponse {
|
||||
execution_id: String,
|
||||
node_id: NodeId,
|
||||
decision: String,
|
||||
comment: Option<String>,
|
||||
},
|
||||
}
|
||||
5
crates/df-core/src/lib.rs
Normal file
5
crates/df-core/src/lib.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
//! df-core: 核心类型定义,所有 crate 的基础依赖
|
||||
|
||||
pub mod error;
|
||||
pub mod events;
|
||||
pub mod types;
|
||||
301
crates/df-core/src/types.rs
Normal file
301
crates/df-core/src/types.rs
Normal file
@@ -0,0 +1,301 @@
|
||||
//! 核心类型定义:ID 别名、状态枚举、优先级等
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// ============================================================
|
||||
// ID 类型别名
|
||||
// ============================================================
|
||||
|
||||
/// 想法 ID
|
||||
pub type IdeaId = String;
|
||||
/// 项目 ID
|
||||
pub type ProjectId = String;
|
||||
/// 任务 ID
|
||||
pub type TaskId = String;
|
||||
/// 工作流 ID
|
||||
pub type WorkflowId = String;
|
||||
/// 节点 ID
|
||||
pub type NodeId = String;
|
||||
/// 发布 ID
|
||||
pub type ReleaseId = String;
|
||||
/// 分支 ID
|
||||
pub type BranchId = String;
|
||||
/// 插件 ID
|
||||
pub type PluginId = String;
|
||||
/// 执行 ID
|
||||
pub type ExecutionId = String;
|
||||
/// 决策 ID
|
||||
pub type DecisionId = String;
|
||||
|
||||
// ============================================================
|
||||
// 状态枚举
|
||||
// ============================================================
|
||||
|
||||
/// 想法状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum IdeaStatus {
|
||||
/// 草稿
|
||||
Draft,
|
||||
/// 待评估
|
||||
PendingReview,
|
||||
/// 已批准
|
||||
Approved,
|
||||
/// 已拒绝
|
||||
Rejected,
|
||||
/// 已转为项目
|
||||
Promoted,
|
||||
/// 已归档
|
||||
Archived,
|
||||
}
|
||||
|
||||
impl IdeaStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
IdeaStatus::Draft => "draft",
|
||||
IdeaStatus::PendingReview => "pending_review",
|
||||
IdeaStatus::Approved => "approved",
|
||||
IdeaStatus::Rejected => "rejected",
|
||||
IdeaStatus::Promoted => "promoted",
|
||||
IdeaStatus::Archived => "archived",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IdeaStatus {
|
||||
fn default() -> Self {
|
||||
IdeaStatus::Draft
|
||||
}
|
||||
}
|
||||
|
||||
/// 项目状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ProjectStatus {
|
||||
/// 规划中
|
||||
Planning,
|
||||
/// 开发中
|
||||
InProgress,
|
||||
/// 测试中
|
||||
Testing,
|
||||
/// 发布中
|
||||
Releasing,
|
||||
/// 已完成
|
||||
Completed,
|
||||
/// 已暂停
|
||||
Paused,
|
||||
/// 已取消
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
impl ProjectStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
ProjectStatus::Planning => "planning",
|
||||
ProjectStatus::InProgress => "in_progress",
|
||||
ProjectStatus::Testing => "testing",
|
||||
ProjectStatus::Releasing => "releasing",
|
||||
ProjectStatus::Completed => "completed",
|
||||
ProjectStatus::Paused => "paused",
|
||||
ProjectStatus::Cancelled => "cancelled",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ProjectStatus {
|
||||
fn default() -> Self {
|
||||
ProjectStatus::Planning
|
||||
}
|
||||
}
|
||||
|
||||
/// 任务状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TaskStatus {
|
||||
/// 待开始
|
||||
Todo,
|
||||
/// 进行中
|
||||
InProgress,
|
||||
/// 代码审查中
|
||||
InReview,
|
||||
/// 测试中
|
||||
Testing,
|
||||
/// 已完成
|
||||
Done,
|
||||
/// 已阻塞
|
||||
Blocked,
|
||||
/// 已取消
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
impl TaskStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
TaskStatus::Todo => "todo",
|
||||
TaskStatus::InProgress => "in_progress",
|
||||
TaskStatus::InReview => "in_review",
|
||||
TaskStatus::Testing => "testing",
|
||||
TaskStatus::Done => "done",
|
||||
TaskStatus::Blocked => "blocked",
|
||||
TaskStatus::Cancelled => "cancelled",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TaskStatus {
|
||||
fn default() -> Self {
|
||||
TaskStatus::Todo
|
||||
}
|
||||
}
|
||||
|
||||
/// 工作流状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum WorkflowStatus {
|
||||
/// 待执行
|
||||
Pending,
|
||||
/// 运行中
|
||||
Running,
|
||||
/// 已暂停(等待人工输入等)
|
||||
Paused,
|
||||
/// 已完成
|
||||
Completed,
|
||||
/// 已失败
|
||||
Failed,
|
||||
/// 已取消
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
impl WorkflowStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
WorkflowStatus::Pending => "pending",
|
||||
WorkflowStatus::Running => "running",
|
||||
WorkflowStatus::Paused => "paused",
|
||||
WorkflowStatus::Completed => "completed",
|
||||
WorkflowStatus::Failed => "failed",
|
||||
WorkflowStatus::Cancelled => "cancelled",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WorkflowStatus {
|
||||
fn default() -> Self {
|
||||
WorkflowStatus::Pending
|
||||
}
|
||||
}
|
||||
|
||||
/// 节点状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NodeStatus {
|
||||
/// 待执行
|
||||
Pending,
|
||||
/// 运行中
|
||||
Running,
|
||||
/// 已完成
|
||||
Completed,
|
||||
/// 已失败
|
||||
Failed,
|
||||
/// 已跳过
|
||||
Skipped,
|
||||
/// 等待中(如等待人工操作)
|
||||
Waiting,
|
||||
/// 已取消
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
impl NodeStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
NodeStatus::Pending => "pending",
|
||||
NodeStatus::Running => "running",
|
||||
NodeStatus::Completed => "completed",
|
||||
NodeStatus::Failed => "failed",
|
||||
NodeStatus::Skipped => "skipped",
|
||||
NodeStatus::Waiting => "waiting",
|
||||
NodeStatus::Cancelled => "cancelled",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NodeStatus {
|
||||
fn default() -> Self {
|
||||
NodeStatus::Pending
|
||||
}
|
||||
}
|
||||
|
||||
/// 分支状态
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum BranchStatus {
|
||||
/// 活跃中
|
||||
Active,
|
||||
/// 已合并
|
||||
Merged,
|
||||
/// 已废弃
|
||||
Abandoned,
|
||||
}
|
||||
|
||||
impl BranchStatus {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
BranchStatus::Active => "active",
|
||||
BranchStatus::Merged => "merged",
|
||||
BranchStatus::Abandoned => "abandoned",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BranchStatus {
|
||||
fn default() -> Self {
|
||||
BranchStatus::Active
|
||||
}
|
||||
}
|
||||
|
||||
/// 优先级
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Priority {
|
||||
/// 低
|
||||
Low = 0,
|
||||
/// 中
|
||||
Medium = 1,
|
||||
/// 高
|
||||
High = 2,
|
||||
/// 紧急
|
||||
Critical = 3,
|
||||
}
|
||||
|
||||
impl Priority {
|
||||
/// 返回数据库存储用的小写字符串
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Priority::Low => "low",
|
||||
Priority::Medium => "medium",
|
||||
Priority::High => "high",
|
||||
Priority::Critical => "critical",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Priority {
|
||||
fn default() -> Self {
|
||||
Priority::Medium
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 辅助函数
|
||||
// ============================================================
|
||||
|
||||
/// 生成新的 UUID v4 字符串
|
||||
pub fn new_id() -> String {
|
||||
uuid::Uuid::new_v4().to_string()
|
||||
}
|
||||
Reference in New Issue
Block a user