DevOS v1 + Phase 2: unified resource model, infra ops, website deployment, AI chat ops

- Monorepo: NestJS API (Fastify) + React web (antd/ProComponents) + shared packages
- PostgreSQL/Prisma (unified resources, relations graph, audit, events, jobs)
- Auth/RBAC/workspace isolation, credential vault (AES-256-GCM)
- Servers/SSH, Docker discovery & lifecycle, Job Center
- Websites & deployments (git provider credential clone, env, health verification)
- Domains/DNS (Cloudflare adapter), certificates (TLS probe), monitoring
- Automation (cron/event/webhook HMAC + notifications), AI Gateway, MCP (29 tools)
- AI chat window (LLM function-calling + rules fallback, SSE streaming, approvals)
- Notes: Vditor WYSIWYG markdown editor, non-blocking autosave
- Tests: 35 unit/security tests; UI audit clean (desktop+mobile, deep links)
This commit is contained in:
phptits
2026-09-10 06:35:55 +00:00
commit 0d6cd37579
209 changed files with 22783 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# 00 — Gap Analysis
## 当前状态判断
现有实现已经具备优秀的基础设施骨架:NestJS/Fastify、React/Ant Design/ProComponents、PostgreSQL/Prisma、Redis、SSH、Docker、DNS、部署、监控、Automation、AI/MCP、Credential Vault、RBAC/Audit。
问题不是“没有基础”,而是大量模块停留在 MVP/adapter/demo 层,尚未形成真正的 Developer Work OS。
## 最大缺口
### P0 — 必须补齐
1. 统一 Resource Model 没有成为所有模块的真正核心。
2. Project → Repository → Website → Server → Deployment → Domain → Monitoring 关系链不完整。
3. Website 部署仍依赖 HTTPS 仓库 URL 内嵌 token,必须改成 Git Provider Credential + clone adapter。
4. Git Provider 集成需要 GitHub/GitLab/Gitea 可扩展模型,而不是只存 URL。
5. Server 管理需要从“连接/发现”升级为完整生命周期管理。
6. Docker 管理需要更多实际操作、实时日志、资源信息。
7. Domain/DNS/SSL 需要从 CRUD 升级为真实 provider abstraction。
8. Automation 需要完整 trigger/action/event/job 模型和 UI。
9. AI Agent 需要真正的 planning → approval → execution → verification,而不是 AI run demo。
10. MCP 必须复用内部 application services,不能形成第二套业务逻辑。
11. Email、Knowledge/Notes、Documents、Projects/Tasks 仍明显不足。
12. Dashboard 必须成为跨资源工作台,而非统计页。
### P1
- 通知中心
- 全局搜索
- Command Palette
- Activity Timeline
- Job Center
- Resource relation UI
- Provider connection management
- Environment/secret 管理
- Backup/restore abstraction
- Webhook HMAC
### P2
- Kubernetes
- Cloud provider
- 多租户高级策略
- 完整邮件客户端
- 高级文档协作
- DAG/parallel workflow
## 核心判断
后续开发不得继续以“增加一个页面/接口”为单位。必须以“完整业务闭环”为单位。
+45
View File
@@ -0,0 +1,45 @@
# 01 — Target Scope
DevOS 的目标不是替代每个专业软件,而是建立统一的开发者工作入口。
## 一级能力
- Dashboard
- AI
- Projects
- Infrastructure
- Websites
- Code
- Domains
- Email
- Knowledge
- Tasks
- Automation
- Credentials
- Monitoring
- Audit
- Settings
## 四个核心抽象
```text
Resource → Action → Event → Agent
```
所有业务能力都应该尽可能映射到这四个抽象。
## Developer Workspace
用户进入平台后,应能从 Project 出发看到:
- 代码仓库
- 网站
- 服务器
- 容器
- 数据库
- 域名
- SSL
- 部署
- 监控
- 任务
- 文档
- 自动化
并能从任何资源进入关联资源。
+44
View File
@@ -0,0 +1,44 @@
# 02 — Unified Resource Model
## 原则
Resource Registry 必须从“通用 CRUD”升级为平台的统一索引层。
## Resource 基础字段
```ts
interface Resource {
id: string
workspaceId: string
type: ResourceType
name: string
status: string
provider?: string
externalId?: string
metadata: Record<string, unknown>
createdAt: Date
updatedAt: Date
}
```
## 必须支持的类型
Server, Container, Website, Domain, Certificate, Repository, Deployment, Database, Project, Task, Note, Document, Credential, Automation, Job, Monitor。
## Relation
实现有方向关系并支持 relation type,例如:
- PROJECT_HAS_REPOSITORY
- PROJECT_HAS_WEBSITE
- WEBSITE_DEPLOYED_TO_SERVER
- WEBSITE_USES_DOMAIN
- WEBSITE_HAS_DEPLOYMENT
- DEPLOYMENT_FROM_REPOSITORY
- DEPLOYMENT_TO_SERVER
- SERVER_HAS_CONTAINER
- PROJECT_HAS_TASK
- PROJECT_HAS_DOCUMENT
## 关键要求
- 所有资源必须 workspace scoped。
- 资源详情页必须显示 Relations。
- 支持反向关系。
- 支持按关系跳转。
- 删除资源前检查关系影响。
- 不要让 Resource Registry 替代领域模型;它负责索引/关系/统一查询,领域模块负责业务规则。
+58
View File
@@ -0,0 +1,58 @@
# 03 — Infrastructure Completion
## Server
完善:
- create/edit/delete
- connect/disconnect
- connection health
- OS/kernel/arch
- CPU/RAM/disk/network
- uptime
- running processes摘要
- Docker availability
- last seen
- tags
- credentials reference
## SSH
必须:
- connect timeout
- command timeout
- output size limit
- stderr separation
- exit code
- audit log
- secret masking
- cancellation
## Docker
至少实现:
- list containers
- inspect
- start/stop/restart
- logs with tail/follow abstraction
- image list
- container resource usage
- ports
- environment key names(禁止返回 secret values)
- status/health
## Jobs
所有长任务统一 Job Center:
- queued/running/success/failed/cancelled
- progress
- logs
- retry
- actor
- resource relation
## Monitoring
建立 provider-neutral model:
- HTTP health check
- TCP check
- uptime state
- response time
- incident
- recovery event
V1 不需要复杂 Prometheus clone,但必须让 Website/Server/Deployment 都能进入统一 monitoring/activity 体系。
@@ -0,0 +1,61 @@
# 04 — Website & Deployment Completion
## Website 生命周期
```text
Website
→ Repository
→ Environment
→ Server
→ Build
→ Deploy
→ Health Check
→ Domain
→ SSL
→ Monitoring
```
## Repository access
禁止要求用户把 private repository token 放进 URL。
建立:
```text
GitProviderConnection
├── provider
├── credentialId
├── externalAccountId
└── metadata
```
Repository 使用 provider + externalId/clone metadata。
## Deployment
Deployment 必须成为 Job 的一种领域操作,并保存:
- commit/ref
- source repository
- target server
- environment
- build strategy
- deployment strategy
- started/finished
- logs
- result
- health check
## 部署策略
V1 支持:
1. Docker Compose / Dockerfile 项目
2. 静态网站
3. 可扩展 deployment adapter
不要把部署逻辑硬编码到 Website Controller。
## Environment
支持:
- development
- staging
- production
环境变量值使用 Credential Vault 或加密存储,UI 默认 mask。
## Health verification
部署成功不能只看 SSH exit code,必须执行 health check;失败则 Deployment 状态为 failed/verification_failed,并展示证据。
@@ -0,0 +1,60 @@
# 05 — Code / Domain / Email / Knowledge
## Git
建立 provider adapter:
- GitHub
- GitLab
- Gitea
统一能力:
- account connection
- repositories
- branches
- commits
- pull/merge requests
- issues(基础)
- webhook
V1 不需要实现 Git hosting,只需要聚合外部 provider。
## Domain/DNS
建立 provider interface:
- listZones
- listRecords
- createRecord
- updateRecord
- deleteRecord
- verify
Cloudflare 是第一个正式 adapter,Manual 是 fallback。
DNS 操作必须有 preview + audit。
## SSL
统一 Certificate 模型,provider/adaptor 可插拔。
至少支持状态:pending/active/expired/error。
## Email
V1 不做完整 Gmail clone。先实现:
- EmailAccount
- provider connection
- inbox message metadata
- send email abstraction
- search metadata
- attachments metadata
支持 SMTP/IMAP adapter;Provider OAuth 可后续加入。
## Knowledge
实现:
- Note
- Document
- folder/tree
- tags
- markdown/rich editor
- code block
- backlinks/resource links
TipTap 为默认编辑器。
重点:Note/Document 可以关联 Project/Resource/Task,成为操作上下文的一部分。
@@ -0,0 +1,50 @@
# 06 — Projects / Tasks / Automation
## Project
Project 是用户工作的顶层业务上下文,而不是简单 CRUD。
Project overview 必须汇总:
- repositories
- websites
- servers
- domains
- deployments
- tasks
- notes
- documents
- automations
- recent activity
## Task
支持:
- backlog/todo/doing/review/done
- priority
- labels
- due date
- relations
- resource links
- activity
## Automation
统一:
```text
Trigger → Condition → Action → Job → Event
```
Triggers:
- manual
- cron
- webhook
- event
Actions 至少:
- deployment.run
- server.command(受权限和风险策略限制)
- container.restart
- task.create/update
- note.create
- notification.send
Webhook 必须从明文 secret 比对升级到 HMAC 签名,支持 timestamp/replay protection。
Automation UI 必须能创建、编辑、启停、测试、查看执行历史。
+57
View File
@@ -0,0 +1,57 @@
# 07 — AI Agent / MCP Completion
## Agent architecture
```text
Intent
→ Context Discovery
→ Plan
→ Risk
→ Approval
→ Execute
→ Verify
→ Report
```
## Tool registry
每个 tool 必须包含:
- name
- description
- input schema
- output schema
- required permissions
- risk level
- idempotency behavior
- audit event
## V1 必须支持的 AI 场景
1. “列出所有服务器和当前状态。”
2. “查看 blog 项目最近一次部署。”
3. “分析为什么网站不可用。”
4. “部署 blog 到指定服务器。”
5. “重启异常容器。”
6. “创建任务记录这个问题。”
7. “把这个事件配置成自动化。”
## Approval
LOW read-only 可直接执行。
MEDIUM 根据 policy。
HIGH/CRITICAL 必须二次确认。
审批内容必须显示:
- 操作
- 资源
- 影响
- 参数摘要
- 风险
## Verification
任何 mutation tool 都应该定义 verify handler。
例如 deployment.run → deployment.status + health.check。
## Memory
V1 先做短期运行上下文 + resource references,不要过早建设复杂向量数据库。
## MCP
MCP 是 DevOS Tool Registry 的 adapter。
REST、Web UI、Agent、MCP 必须共享 application service。
禁止 MCP 直接访问 Prisma。
@@ -0,0 +1,35 @@
# 08 — Security Hardening
这是继续开发前的 P0 gate。
## 立即处理
1. 修改/禁用 README 中暴露的默认管理员账号密码。
2. 轮换 APP_SECRET。
3. 轮换 ENCRYPTION_KEY 前先设计 credential migration/clear strategy;不要盲目轮换导致现有凭据全部不可解密。
4. 检查公网注册策略;生产模式默认关闭公开注册,或增加 invite-only。
5. 检查 `/root/.ldns/config.toml`,确认 token 不进入项目、日志、git、API 响应。
6. 删除冒烟测试 credential/test-token。
## Auth
增加:
- password change
- session invalidation strategy(即使 V1 暂不实现完整 revoke list,也必须保留扩展点)
- login rate limit
- register rate limit
- optional invite-only mode
## Credentials
- AES-256-GCM 保留
- key 不存数据库
- secret access audit
- API never returns plaintext
- logs redact tokens/passwords/keys
- export disabled by default
## Command security
危险命令检测只是最后一道防线,不是授权机制。
真正权限模型必须先于 command execution。
## Production config
生产启动时必须拒绝明显开发默认 secret。
`.env.example` 可以有 placeholder,但 runtime 必须校验。
@@ -0,0 +1,50 @@
# 09 — Unified Workspace UX
## Global shell
ProLayout + workspace switcher + global search + notifications + AI entry。
## Command Palette
支持:
- search resource
- go to project
- create task
- deploy website
- open server
- run automation
- ask AI
## Global Search
搜索:
- projects
- resources
- repositories
- websites
- domains
- tasks
- notes
- deployments
结果显示 resource type + status + project。
## Activity
统一 Activity Feed,至少包括:
- deployment
- server command
- automation execution
- credential access
- task changes
- AI tool call
## Dashboard
Dashboard 不以数字 KPI 为核心,而以“今天我要处理什么”为核心:
- infrastructure incidents
- failed deployments
- pending approvals
- tasks due
- recent projects
- recent activity
- AI recommendations
## Resource detail
统一 tabs:Overview / Relations / Activity / Logs / Actions。
按资源类型隐藏不适用 tab。
@@ -0,0 +1,41 @@
# 10 — API/UI Contract
## API
统一 `/api/v1`。
所有 response/error 使用已有错误契约,不得出现模块私有错误格式。
Mutation API:
- authorization
- validation
- audit
- job if long-running
## Pagination
列表统一 cursor 或 page/limit,避免每个模块自定义。
## Filtering
Resource list 支持:
- type
- status
- tag
- project
- search
## UI
ProTable + ProForm + ProDescriptions 作为默认模式。
长任务统一 JobDrawer/JobDetail。
危险操作统一 Confirm + risk explanation。
## Loading/error/empty
所有页面必须处理:
- loading
- empty
- permission denied
- network error
- operation failure
## API client
前端不得在页面中直接拼 fetch URL;统一 api client/service。
@@ -0,0 +1,35 @@
# 11 — Test & Acceptance
## Quality gate
每个 milestone 必须:
- typecheck
- unit tests
- API integration tests
- critical E2E
- security regression
## Critical E2E
1. login → workspace → dashboard
2. add server → connect → inspect
3. server → containers → restart → audit
4. create project → connect repository
5. create website → deploy → health check
6. domain → DNS verify
7. create task → link project/resource
8. create automation → run → inspect job
9. AI read-only query
10. AI mutation → approval → execution → verification
11. MCP tool call → same permission/audit behavior
12. credential create → access → redaction
## Security tests
- cross-workspace resource access denied
- unauthorized server command denied
- secret never returned by API
- secret never appears in logs
- webhook replay rejected
- destructive AI action requires approval
- production defaults rejected
## Done definition
V1 Phase 2 不是“页面全部存在”,而是上述闭环可真实运行。
@@ -0,0 +1,95 @@
# 12 — Codex Execution Plan
## Rules
- Continue from `/home/dev/bun/devos`.
- Do NOT recreate the project.
- Before changes, inspect current source and Prisma schema.
- Preserve working functionality.
- Make incremental migrations only.
- Do not reset/drop production-like databases.
- Do not expose secrets.
## Phase A — Audit and hardening
1. Inspect auth, workspace guard, credential vault, mask utilities.
2. Remove/disable default admin credential exposure.
3. Add production secret validation.
4. Disable public registration by default in production.
5. Remove test credential.
6. Upgrade webhook authentication to HMAC + timestamp.
7. Add security regression tests.
## Phase B — Resource graph
1. Extend ResourceRelation.
2. Build relation service.
3. Add resource relation endpoints.
4. Add relation UI.
5. Add project-centric overview.
## Phase C — Infrastructure
1. Complete server lifecycle.
2. Complete Docker operations.
3. Standardize Job Center.
4. Add monitoring/incident model.
## Phase D — Website/deployment
1. Git provider connection model.
2. Repository model.
3. Credential-based private repo access.
4. Deployment adapters.
5. Environment management.
6. Health verification.
7. Deployment timeline/logs.
## Phase E — Code/domain/productivity
1. GitHub/GitLab/Gitea adapters.
2. Domain/DNS provider abstraction.
3. Certificate model.
4. Project/Task completion.
5. Note/Document completion.
6. Email account/send/search foundation.
## Phase F — Automation
1. Event catalog.
2. Trigger/action schemas.
3. Sequential workflow executor.
4. HMAC webhook.
5. Job Center integration.
6. Automation UI.
## Phase G — AI
1. Tool registry.
2. Tool permission resolver.
3. Risk engine.
4. Approval model/UI.
5. Planner.
6. Executor.
7. Verification.
8. Execution report.
## Phase H — MCP
Expose selected stable tools through MCP, reusing the exact application services and authorization pipeline.
## Phase I — Unified UX
1. Global search.
2. Command palette.
3. Activity feed.
4. Job center.
5. AI command entry.
6. Project dashboard.
7. Resource relation navigation.
## Execution protocol
For each phase:
1. inspect current implementation
2. write/update design notes
3. implement backend
4. migrate DB safely
5. implement frontend
6. add tests
7. run typecheck
8. run unit/integration/E2E
9. update docs
10. report files changed and verification
## Important
Do not mark a feature complete merely because its endpoint returns 200. Acceptance requires a complete user-facing workflow and tests.
+21
View File
@@ -0,0 +1,21 @@
# DevOS V1 Phase 2 — Completion Specification
目标:在现有 `/home/dev/bun/devos` V1 基础上继续开发,不推倒重来,补齐当前与目标产品约 80% 的差距。
## 使用方式
建议先阅读:
1. 00-GAP-ANALYSIS.md
2. 01-TARGET-SCOPE.md
3. 02-RESOURCE-MODEL.md
4. 03-INFRASTRUCTURE.md
5. 04-WEBSITE-DEPLOYMENT.md
6. 05-GIT-DOMAIN-EMAIL-KNOWLEDGE.md
7. 06-PROJECT-TASK-AUTOMATION.md
8. 07-AI-AGENT-MCP.md
9. 08-SECURITY-HARDENING.md
10. 09-UX-UNIFIED-WORKSPACE.md
11. 10-API-UI-CONTRACT.md
12. 11-TEST-ACCEPTANCE.md
13. 12-CODEX-EXECUTION.md
本文件包是“增量开发规范”,不是要求重新创建 DevOS。