Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,16 @@ These principles are the highest-priority default for all project work. When the
- Design for the long term.
- Study proven products and adopt their patterns where they fit Minos.

# Project Architecture Reference

Minos 是一个远程 AI 编码控制系统:Mac 运行 host 端,通过手机或浏览器远程驱动 codex/claude/gemini/opencode CLI agent。各子系统的详细架构文档如下:

| 文档 | 覆盖范围 |
|------|---------|
| [docs/architecture-overview.md](docs/architecture-overview.md) | 项目总览、顶层架构、仓库结构、crate 依赖图、技术栈 |
| [docs/architecture-backend.md](docs/architecture-backend.md) | 后端服务 (minos-backend):HTTP API、WebSocket 网关、认证、配对、实时扇出、数据库层、Agent 会话、后台 Worker |
| [docs/architecture-daemon.md](docs/architecture-daemon.md) | Host 守护进程 (minos-daemon):relay 连接、agent 管理、本地 SQLite 持久化、Host Link、JSON-RPC 服务器 |
| [docs/architecture-mobile.md](docs/architecture-mobile.md) | 移动端 (Flutter + minos-mobile):四层架构、Riverpod 状态管理、FRB 桥接、认证/配对/会话流程、WebSocket 重连 |
| [docs/architecture-web.md](docs/architecture-web.md) | Web 管理控制台 (React + Vite):Zustand 状态、WebSocket 实时、工作区页面 |
| [docs/architecture-desktop.md](docs/architecture-desktop.md) | Host 桌面壳 (Tauri + React):主 Host GUI(已移除 Swift macOS app 与 minos-tui) |
| [docs/architecture-grok-acp-projection.md](docs/architecture-grok-acp-projection.md) | Grok ACP tool content/raw_output 双通道 → Minos UI 投影清单 |
| [docs/architecture-shared-crates.md](docs/architecture-shared-crates.md) | 共享 crate:domain、protocol、transport、cli-detect、agent-runtime、chat-store、acp-protocol、codex-protocol、ui-protocol、ffi-frb |
| [docs/architecture-messaging.md](docs/architecture-messaging.md) | Server + 全端消息体系:Conversation-first IM、@/Approval Attention、撤回/reaction、读写 fanout、Durable/Stream/Ingest/Command、Outbox 与水位 |
| [docs/superpowers/specs/2026-08-02-hub-collaboration-message-ssot.md](docs/superpowers/specs/2026-08-02-hub-collaboration-message-ssot.md) | 协作气泡 Hub SSOT 收敛:退役 Desktop dual-write、Agent 最终气泡单写者、Sync/Outbox 阶段 0–5 |
| [docs/superpowers/specs/2026-08-03-im-reliability-program/README.md](docs/superpowers/specs/2026-08-03-im-reliability-program/README.md) | **IM 可靠性总计划**:客户端 Sync + 后端投递/编排终态;任务图 TASKS.md |
| [docs/superpowers/specs/2026-08-03-im-reliability-program/next-track-b6-c5-c6.md](docs/superpowers/specs/2026-08-03-im-reliability-program/next-track-b6-c5-c6.md) | 下一轨 B6/C5/C6 终态:reaction 幂等、Intent Outbox、visibility、状态债 |
| [docs/superpowers/specs/2026-08-03-realtime-surface-model.md](docs/superpowers/specs/2026-08-03-realtime-surface-model.md) | 全局实时面模型:通道分级、订阅拓扑、带宽优先级、新增功能 checklist |
| [docs/superpowers/specs/2026-08-03-im-reliability-program/closeout-and-backlog.md](docs/superpowers/specs/2026-08-03-im-reliability-program/closeout-and-backlog.md) | IM Reliability 收口(B7/G2–G4)+ 产品 residual + Realtime 后续分层 |
| [docs/superpowers/specs/2026-08-03-client-im-sync-engine.md](docs/superpowers/specs/2026-08-03-client-im-sync-engine.md) | 客户端 IM Sync Engine 终态(Desktop + Mobile Outbox / Timeline / Inbox) |
| [docs/superpowers/specs/2026-08-03-backend-im-delivery-orchestration.md](docs/superpowers/specs/2026-08-03-backend-im-delivery-orchestration.md) | 后端投递与 Agent 编排终态(Outbox 车道、Push、CompletionWatch、Session 生命周期) |
| [docs/architecture-business-flow.md](docs/architecture-business-flow.md) | 完整业务流程:注册 → 配对 → 实时连接 → Agent 会话 → 流式交互 → 审批 → 重连恢复 |
| [docs/ci-gates.md](docs/ci-gates.md) | CI / 本地质量门禁矩阵:backend、backend-pg、mobile、web、desktop 职责划分与 just/xtask 入口 |
| [docs/ops/vps-deploy.md](docs/ops/vps-deploy.md) | 生产 VPS 部署:Caddy + GHCR 镜像 + Postgres/Redis,runtime-only(不 clone 源码) |
| [docs/ops/r2-media.md](docs/ops/r2-media.md) | 聊天附件 / media blob:Cloudflare R2(或本地目录)配置与 `/v1/media/*` API |
| [docs/ops/vps-dev-binary.md](docs/ops/vps-dev-binary.md) | Dev/agent 二进制旁路:linux amd64 构建 + rsync + systemd,与 Docker 数据面共存 |
| [docs/superpowers/specs/2026-07-30-cloud-identity-clients-long-term.md](docs/superpowers/specs/2026-07-30-cloud-identity-clients-long-term.md) | 长期方案 L0:Supabase exchange、Host 链接、Desktop/Web UI SSOT、Mobile 云端角色 |
| [docs/superpowers/specs/2026-07-30-program/](docs/superpowers/specs/2026-07-30-program/README.md) | 执行体系 L1/L2:分域设计 + 任务依赖图 TASKS.md |
# Project Context and Navigation

Minos 是远程 AI 编码控制系统:用户通过 Mobile、Desktop 或 Web 协作界面操作,Hub 负责身份、协作消息与实时同步,Mac Host daemon 在用户机器上执行 codex、claude、gemini、opencode 等 CLI agent。协作消息的权威在 Hub;Host 是 agent runtime,不是第二个协作消息权威。

Read documentation selectively, starting from the change rather than mechanically reading an index:

- Start with [architecture-overview.md](docs/architecture-overview.md) for system boundaries and repository layout.
- Read the matching `docs/architecture-<surface>.md` for the subsystem being changed; read [architecture-messaging.md](docs/architecture-messaging.md) for any cross-end messaging, realtime, bot, or sync work.
- Read the applicable [ADR](docs/adr/) before changing a durable architectural decision, [ci-gates.md](docs/ci-gates.md) before verification, and `docs/ops/` only for operational work.
- Use `rg` to find a current contract or specification. A design spec is not automatically authoritative: prefer current architecture docs, accepted ADRs, types, code, and nearest tests; resolve disagreement at the ownership boundary.

# Current-State and Target-Architecture Policy

Expand All @@ -55,6 +36,34 @@ Minos is under active development and has no historical release that requires su
- A phased delivery is valid only when each phase is a releasable slice of that target architecture. It must compile, be verifiable, and leave no temporary behavior or migration debt behind.
- Fix shared-contract, lifecycle, and SSOT defects at their ownership boundary. Do not hide them with UI guards, retries, silent defaults, soft deduplication, placeholders, or other local workarounds.

# Code Language, Naming, and Comments

Code describes the current domain, not the history of how it was implemented.

- Comments explain non-obvious current invariants, ownership, concurrency, protocol boundaries, or reasoning; never narrate a plan, ticket, phase, review, tool, prompt, or ADR. Remove comments that merely restate code or became stale. A runtime state-machine may use its own locally defined terms.
- Name files, modules, types, APIs, and variables for their current responsibility. Do not preserve temporal, migration, compatibility, or tool-specific vocabulary as a domain name; rename active paths or delete obsolete ones.
- Use the [architecture glossary](docs/architecture-overview.md#glossary) for shared system terms. Add or revise a term there when it needs a stable definition; do not create a private synonym or encode a terminology decision in a source comment.
- Apply terminology changes cohesively across declarations, call sites, tests, generated bindings, and documentation. Do not keep aliases merely to preserve an old name.

# Documentation Lifecycle

Documentation is a maintained product surface, not a record of agent activity. Keep only material that helps a future engineer safely operate, understand, or change the current system. Git and the PR retain historical working notes.

## Document classes

- **Long-lived reference:** `README.md`, `docs/architecture-*.md`, accepted `docs/adr/`, and `docs/ops/`. These describe the current system, a durable decision, or a runnable operation. Update or delete affected content in the same change as the code.
- **Current design specification:** a narrowly scoped target contract that is still needed to guide work across multiple changes or ownership boundaries. It has one canonical owner/topic, states its status, and must be folded into the long-lived reference or deleted when its work is complete or superseded.
- **Temporary work artifact:** implementation plans, investigation notes, review reports, checklists, and PR-specific task tracking. Keep these in the issue/PR by default, not in the repository. If collaboration requires a committed temporary file, label it `Temporary`, state its removal condition, and delete it before the PR is opened or merged.

## Rules

- Do not create a document merely to narrate work, restate code, preserve a chat transcript, or prove that a task was completed. Do not add dated plans, reviews, or task logs as permanent repository content.
- Before adding a document, search for an existing canonical document and extend it when the subject is the same. One fact has one source of truth; replace duplicate text with a link or delete it.
- A new long-lived document needs a durable audience and maintenance reason. New ADRs are for consequential, long-lived decisions, not routine implementation choices.
- When a feature, migration, or refactor completes, promote only its lasting contract, operational procedure, or decision into the relevant architecture document, runbook, or ADR. Delete its temporary plan, review, task list, stale examples, and superseded specification in the same change.
- When changing an existing document, remove invalid sections and links rather than appending another historical layer. Mark an ADR as superseded only when its decision has actually been replaced; ADRs remain the concise historical decision record.
- Before handoff, account for every documentation file added or touched: why it remains useful after the PR, what canonical document it updates, and which temporary artifacts were removed. If that cannot be stated plainly, do not keep the file.

# Agent Workflow

## Before changing code
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Hosted backend + host daemon + Desktop/TUI host consoles + Flutter mobile for re

Minos is moving from MVP delivery into formal development.

- Historical planning docs under `docs/superpowers/` have been retired.
- Planning and review artifacts belong in the relevant PR or issue; the repository keeps only current architecture, ADR, and operational documentation.
- The active backend architecture source of truth is `docs/backend-formal-development.md`.
- Current shipped surfaces are the hosted Rust backend, `minos-daemon` (host runtime), Desktop (Tauri) / TUI host consoles, the Flutter mobile client, and the browser-admin web client.
- The legacy Swift `apps/macos` host UI and UniFFI bridge have been removed; Desktop owns the host GUI.
Expand Down Expand Up @@ -166,7 +166,7 @@ The current account-based login + agent session flow is:

1. **Sign in via Supabase** — clients authenticate with Supabase Auth, then call `POST /v1/auth/supabase` to obtain Minos access + refresh tokens plus an `account_id`.
2. **Pair** — once authenticated, the iPhone scans the Mac's QR (v2 payload), POSTs `/v1/pairing/consume` with the bearer, and persists the freshly minted `DeviceSecret`. Same-device subsequent runs re-use the secret; switching accounts on a previously-paired device drops the pairing automatically (`MinosCore._onAuthLanded`).
3. **`start_agent`** — the iPhone opens an authenticated `/devices` WebSocket, then forwards `minos_start_agent` (and follow-up `minos_send_user_message`) to the Mac via `Envelope::Forward`. The daemon replies with a `session_id`; live `EventKind::UiEventMessage` frames stream back over the same socket.
3. **Agent session** — clients open formal `/ws/client` (ticket) and the host opens `/ws/host` (Bearer `hit_*`). Host commands are durable (`HostCommandIssued` outbox); live agent UI is delivered as topic `StreamEvent` / `DurableEvent` frames, not legacy envelope forwards.

### Local setup

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pnpm check:all
- Frontend lives in `src/` and is intentionally **not** shared with `apps/web` yet — visual baseline is the desktop mockup, not the current web admin demo.
- Rust host process lives in `src-tauri/` as a **standalone Cargo package** (not a workspace member of the root `crates/*` workspace).
- Bridge to `minos-daemon` will reuse the same local JSON-RPC surface the TUI uses (`minos_local_*`).
- **Wave 1 Phase 4:** design tokens live in `src/index.css` (`:root` CSS vars) and map through `tailwind.config.js`. Markdown/code polish is in `shared/ui/MarkdownText.tsx` + tone CSS vars (streaming still plain text). See [docs/architecture-desktop.md](../../docs/architecture-desktop.md) § Design tokens + markdown.
- **Design tokens** live in `src/index.css` (`:root` CSS vars) and map through `tailwind.config.js`. Markdown/code polish is in `shared/ui/MarkdownText.tsx` + tone CSS vars (streaming still plain text). See [docs/architecture-desktop.md](../../docs/architecture-desktop.md) § Design tokens + markdown.
- **Chat reactions:** MessageRow action bar + emoji-mart picker; durable via local daemon (`toggle_conversation_message_reaction` / `chat_message_reactions`); `reaction-store` optimistic toggle (generation-gated) + hydrate from `list_conversation_messages`; mock seed only in browser Vite. See [docs/architecture-desktop.md](../../docs/architecture-desktop.md).

See [docs/architecture-desktop.md](../../docs/architecture-desktop.md).
14 changes: 9 additions & 5 deletions apps/desktop/scripts/check-file-sizes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ const HARD_LINES = 800;

/** @type {Record<string, number>} path relative to src/ → temporary hard cap */
const ALLOWLIST = {
// Agents page create/list/edit + Hub registry; split to AgentsView sections next wave.
// Agents page create/list/edit + cloud registry; split to AgentsView sections next wave.
"features/agents/AgentsView.tsx": 1250,
// WS connect / inbox digest / subscription fanout; split hub-realtime lanes next wave.
"shared/lib/hub-realtime.ts": 1000,
// Hub REST helpers (auth + conversations + agents). sendConversationMessage removed;
// further split to minos-cloud-hub.ts / agents helpers planned (freeze above current LOC).
// WS connect / inbox digest / subscription fanout; split cloud-realtime lanes next wave.
// Cap raised after Hub→Cloud identifier rename (hub-realtime @982→cloud-realtime ~1017).
"shared/lib/cloud-realtime.ts": 1050,
// Cloud REST helpers (auth + conversations + agents). sendConversationMessage removed;
// further split to minos-cloud helpers planned (freeze above current LOC).
"shared/lib/minos-cloud.ts": 1100,
// Mock fixtures + Conversation types; extract mock-conversations.ts planned.
"shared/lib/mock-data.ts": 850,
// Outbox posts + per-lane worker share one module; split to im-outbox-worker.ts next.
"shared/lib/im-cloud-sync.ts": 950,
// Cloud IM bridge (lifecycle + mark-read + timeline merge). Split mark-read /
// lifecycle helpers next; cap raised after Hub→Cloud rename (im-hub-bridge @784→~826).
"shared/lib/im-cloud-bridge.ts": 850,
};

/**
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src-tauri/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct ConnectionDto {
/// False when disconnected, connecting, or non-managed external daemon
/// without a handle (cannot observe relay link).
#[serde(default)]
pub hub_online: bool,
pub cloud_online: bool,
/// Local `hit_` present (host can dial hub). Not a product "Link" flag.
#[serde(default)]
pub has_host_token: bool,
Expand Down Expand Up @@ -382,7 +382,7 @@ pub struct PushStatusDto {
pub live: bool,
}

/// Host Link prepare material (D02 §7.2 / daemon `host_prepare_link`).
/// Host Link prepare material (daemon `host_prepare_link`).
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HostPrepareLinkDto {
Expand Down Expand Up @@ -660,7 +660,7 @@ impl DaemonBridge {
}

fn status_locked(guard: &BridgeInner) -> ConnectionDto {
let hub_online = guard.managed.as_ref().is_some_and(|h| {
let cloud_online = guard.managed.as_ref().is_some_and(|h| {
matches!(
h.current_relay_link(),
minos_domain::RelayLinkState::Connected
Expand All @@ -676,7 +676,7 @@ impl DaemonBridge {
error: guard.last_error.clone(),
source: guard.source.clone(),
managed: guard.managed.is_some(),
hub_online,
cloud_online,
has_host_token,
}
}
Expand Down
Loading
Loading