Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4c01c10
docs(architecture): define session coordinators
zerob13 Jul 13, 2026
c164c71
test(session): lock coordinator invariants
zerob13 Jul 13, 2026
5036d1d
test(session): characterize consumers
zerob13 Jul 13, 2026
db1bf46
test(session): cover coordinator edge order
zerob13 Jul 13, 2026
b0c966e
test(session): merge consumer characterization
zerob13 Jul 13, 2026
71325c7
docs(architecture): record session characterization
zerob13 Jul 13, 2026
bff3ac9
refactor(session): extract projection
zerob13 Jul 13, 2026
cf610d5
refactor(session): extract assignment
zerob13 Jul 13, 2026
e39f093
fix(session): preserve assignment behavior
zerob13 Jul 13, 2026
7789c3b
refactor(session): extract turn coordinator
zerob13 Jul 13, 2026
e59719d
fix(session): contain initial turn failures
zerob13 Jul 13, 2026
9dc7f23
refactor(session): extract lifecycle
zerob13 Jul 13, 2026
0ef0b03
fix(session): contain lifecycle cleanup
zerob13 Jul 13, 2026
0825aca
refactor(routes): inject session ports
zerob13 Jul 13, 2026
8d5142e
refactor(session): wire remote and cron
zerob13 Jul 13, 2026
1cceca6
test(architecture): guard session boundaries
zerob13 Jul 13, 2026
862018a
fix(architecture): close session guard gaps
zerob13 Jul 13, 2026
17f3d2d
docs(session): document coordinators
zerob13 Jul 13, 2026
5d65d0f
docs(architecture): refresh baseline
zerob13 Jul 13, 2026
5091f4d
fix(architecture): scope session guards
zerob13 Jul 13, 2026
d045d3f
fix(architecture): verify session aggregates
zerob13 Jul 13, 2026
21785f4
docs(architecture): sync baseline checkpoint
zerob13 Jul 13, 2026
0cd62ef
docs(session): close coordinator work
zerob13 Jul 13, 2026
ea44750
docs(session): plan stage one integration
zerob13 Jul 13, 2026
1122b24
refactor(session): merge dev boundaries
zerob13 Jul 13, 2026
2f3d5a5
docs(architecture): refresh merged baseline
zerob13 Jul 13, 2026
cdd7f4e
docs(session): record boundary integration
zerob13 Jul 13, 2026
8066de7
test(architecture): reuse guard scans
zerob13 Jul 13, 2026
7182d79
docs(session): record integration validation
zerob13 Jul 13, 2026
7976a37
docs(session): close dev integration
zerob13 Jul 13, 2026
b4dd7ec
fix(session): address review feedback
zerob13 Jul 13, 2026
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
26 changes: 17 additions & 9 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ flowchart LR
Bridge --> Contracts["shared/contracts routes + events"]
Contracts --> Routes["src/main/routes dispatcher"]
Routes --> SessionOwners["explicit session owners<br/>search / translation / export / usage / catalog"]
Routes --> Ports["core session/chat services + narrow ports"]
Ports --> SessionFacade["AgentSessionPresenter<br/>core session façade"]
SessionFacade --> Manager["AgentManager<br/>descriptor.kind router"]
Routes --> Services["SessionService / ChatService"]
Services --> Coordinators["Lifecycle / Turn / Assignment / Projection"]
Compat["AgentSessionPresenter<br/>compatibility forwarding"] --> Coordinators
Coordinators --> Manager["AgentManager<br/>descriptor.kind router"]
Manager --> DeepBackend["typed DeepChat backend"]
Manager --> AcpBackend["direct ACP backend"]
DeepBackend --> DeepRuntime["DeepChatAgentRuntime"]
Expand All @@ -35,9 +36,13 @@ flowchart LR
- `kind=acp` 使用 direct ACP backend 和外部 ACP protocol loop,不进入 `DeepChatLoopEngine`。
- `kind=deepchat + providerId=acp` 仍是受支持的兼容组合:session 走 DeepChat backend/loop,provider
选择才进入 `AcpProvider` adapter。
- `AgentSessionPresenter` 是 core session façade,保留 session CRUD、title、turn、transfer/subagent 与
shared projection 编排。history、translation、export、usage、RTK、catalog 和 startup migrations 由
typed routes/lifecycle hooks 直接组合各自 owner。
- 四个 `sessionApplication` coordinator 拥有 core session lifecycle、turn、assignment 和 projection;
Session/Chat routes、Remote 和 Cron 通过 consumer-owned narrow ports 使用同一组实例。
- `AgentSessionPresenter` 仅保留 compatibility forwarding,把兼容调用转发到同一组 coordinator;不再拥有
core session policy/state,也不再拥有 history、translation、export、usage、RTK、catalog 或 startup
migration behavior。
- history、translation、export、usage、RTK、catalog 和 startup migrations 由 typed routes/lifecycle
hooks 直接组合各自 owner。
- `AgentRuntimePresenter` 仍初始化 `DeepChatAgentRuntime`,并保留 DeepChat state/delegate、message、Tape、
prompt/tool/provider adapter wiring;它不再实现 unified agent interface,也不负责 ACP runtime 构造。

Expand All @@ -55,16 +60,17 @@ flowchart LR
| DeepChat loop | `src/main/agent/deepchat/loop/` | `LoopRun`、provider/tool round state machine、fixed awaited commits与窄 ports |
| DeepChat Memory adapter | `src/main/agent/deepchat/memory/` | sole runtime coordinator、prompt contributor、background ingestion observer |
| ACP runtime | `src/main/agent/acp/` | catalog、launch、client/process/session/protocol、direct instance/runtime |
| `AgentSessionPresenter` | `src/main/presenter/agentSessionPresenter/` | core session lifecycle/turn/assignment façade与 shared projection operations |
| session application | `src/main/presenter/sessionApplication/` | Lifecycle、Turn、AgentAssignment、Projection coordinators 与窄 dependency ports |
| `AgentSessionPresenter` | `src/main/presenter/agentSessionPresenter/` | core session public compatibility forwarding;不拥有 application behavior |
| session boundary owners | `src/main/routes/sessions/`, `src/main/presenter/exporter/agentSessionExporter.ts`, `src/main/presenter/usageStatsService.ts` | history、translation、current export、usage dashboard/backfill |
| startup maintenance | `src/main/presenter/startupMigrations/` | default legacy import and stateless session-data migrations |
| shared session policies | `src/main/agent/shared/` | available-agent catalog and assistant-model selection |
| `AgentRuntimePresenter` | `src/main/presenter/agentRuntimePresenter/` | retained DeepChat state/delegate façade及现有 message/Tape/provider/tool adapters |
| `ToolPresenter` | `src/main/presenter/toolPresenter/` | MCP/local tool 聚合、collision policy、权限预检查、调用路由 |
| `MemoryPresenter` | `src/main/presenter/memoryPresenter/` | Memory rows、retrieval、write、vector、maintenance kernel |
| `LLMProviderPresenter` | `src/main/presenter/llmProviderPresenter/` | provider/model runtime和 DeepChat ACP-provider compatibility adapter |
| `RemoteControlPresenter` | `src/main/presenter/remoteControlPresenter/` | remote channel control,generation control 走 manager port |
| `CronJobsService` | `src/main/presenter/cronJobs/` | detached session run、cron 调度和 Remote 投递 |
| `RemoteControlPresenter` | `src/main/presenter/remoteControlPresenter/` | remote channel control;session 操作走四个 narrow ports,generation control 走 manager port |
| `CronJobsService` | `src/main/presenter/cronJobs/` | detached session run、composition-owned starter、cron 调度和 Remote 投递 |

## Agent runtime 分层

Expand Down Expand Up @@ -132,6 +138,8 @@ fresh resume run。外部 hook notifications 仍是 non-blocking observer。
- 同一 guard 保持 Memory unique owner/structure、causal observation read-only 和 renderer typed boundary。
- 同一 guard 阻止 removed session-boundary methods/interface declarations、foreign owner imports,以及五个
startup hook 中的 presenter dependency、unsafe cast 和 optional task probe 回流。
- 同一 guard 阻止 Session/Chat、Remote、Cron 等 migrated consumer 重新依赖 session presenter、重复构造
coordinator、coordinator 反向导入 session-boundary owner,以及引入 combined session application façade。
- `scripts/agent-cleanup-guard.mjs` 覆盖 `src/main/agent/**` 与 retained presenter/tool/skill hot paths,防止旧
agent/session presenter import 回流。

Expand Down
42 changes: 25 additions & 17 deletions docs/FLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ sequenceDiagram
participant R as Renderer
participant C as SessionClient/ChatClient
participant Route as src/main/routes
participant F as AgentSessionPresenter
participant App as Lifecycle / Turn / Assignment / Projection
participant S as AppSessionService
participant M as AgentManager
participant B as Typed Backend

R->>C: create/send/restore
C->>Route: window.deepchat.invoke(route)
Route->>F: createSession/restore/send/listMessagesPage
F->>S: create/bind/read app-session shell
F->>M: resolve executable descriptor/session handle
Route->>App: narrow lifecycle/turn/projection port
App->>S: create/bind/read app-session shell
App->>M: resolve executable descriptor/session handle
M->>B: switch descriptor.kind and open handle
F->>B: initialize/send/snapshot
App->>B: initialize/send/snapshot
B-->>R: existing message projection + chat.stream.* events
```

Expand All @@ -35,11 +35,14 @@ sequenceDiagram
- `src/main/agent/manager/agentManager.ts`
- `src/main/agent/manager/deepChatAgentBackend.ts`
- `src/main/agent/manager/directAcpAgentBackend.ts`
- `src/main/presenter/sessionApplication/`
- `src/main/presenter/agentSessionPresenter/index.ts`

`AgentSessionPresenter` 是 core session lifecycle/turn/assignment façade;agent kind resolution 和
executable backend selection 只发生在 `AgentManager`。`new_sessions.session_kind` 仍表示
`regular | subagent`,不决定 DeepChat/ACP backend。
`SessionService` / `ChatService` 直接使用 consumer-owned coordinator ports。`AgentSessionPresenter` 只为
兼容调用转发 core session methods;history、translation、export、usage、RTK、catalog 与 startup
maintenance 直接进入各自 owner,不经过该 presenter。agent kind resolution 和 executable backend
selection 只发生在 `AgentManager`。`new_sessions.session_kind` 仍表示 `regular | subagent`,不决定
DeepChat/ACP backend。

## 2. DeepChat 消息处理主循环

Expand Down Expand Up @@ -124,13 +127,13 @@ sequenceDiagram
participant R as Renderer messageStore
participant S as SessionClient
participant Route as SessionService
participant N as AgentSessionPresenter
participant P as SessionProjectionCoordinator
participant DB as DeepChatMessageStore

R->>S: restore(sessionId, limit=100)
S->>Route: sessions.restore
Route->>N: restoreSession
N->>DB: listPageBySession
Route->>P: getSession + listMessagesPage
P->>DB: listPageBySession
DB-->>R: latest page + nextCursor
R->>S: listMessagesPage(cursor)
S->>Route: sessions.listMessagesPage
Expand All @@ -151,7 +154,8 @@ sequenceDiagram

```mermaid
flowchart TD
Route["AgentSessionPresenter"] --> Manager["AgentManager"]
CompatFacade["AgentSessionPresenter<br/>compatibility forwarding"] --> App["Session application coordinator"]
App --> Manager["AgentManager"]
Manager --> Kind{"descriptor.kind"}
Kind -->|acp| Direct["DirectAcpSessionBackend"]
Direct --> AcpRuntime["AcpAgentRuntime"]
Expand Down Expand Up @@ -233,20 +237,23 @@ sequenceDiagram
participant Client as CronJobsClient
participant Service as CronJobsService
participant Utility as Scheduler utility
participant Agent as AgentSessionPresenter
participant Starter as Cron session starter
participant App as Lifecycle / Turn
participant Runtime as Agent runtime updates
participant Remote as RemoteControlPresenter

UI->>Client: list/upsert/toggle/runNow
Client->>Service: cronJobs.* route
Service->>Utility: reconcile enabled jobs
Utility->>Service: RUN_DUE
Service->>Agent: create detached session and send task prompt
Agent-->>Service: run status and output updates
Service->>Starter: start run
Starter->>App: create detached session + send task prompt
Runtime-->>Service: DeepChatInternalSessionUpdate status/output/completion
Service->>Remote: optional notification-only delivery
```

Triggers 使用 cron 表达式。每次触发创建独立 detached session;Remote 投递只发送通知,不进入普通
Remote 会话上下文。
Remote 会话上下文。starter 在 composition root 接线,不依赖 route runtime 初始化。

## 10. Remote Control

Expand All @@ -259,7 +266,8 @@ flowchart LR
WeChat["WeChat iLink"] --> Remote
Remote --> Auth["channel auth / binding store"]
Remote --> Runner["remote conversation runner"]
Runner --> Agent["AgentSessionPresenter"]
Runner --> Ports["Lifecycle / Turn / Assignment / Projection ports"]
Runner --> Generation["AgentManager generation port"]
```

统一远程控制支持绑定、默认 agent、默认 workdir、`/sessions`、`/model`、状态输出、媒体/Markdown
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Renderer
-> window.deepchat
-> shared/contracts/routes + shared/contracts/events
-> src/main/routes dispatcher
-> route services / presenter-backed ports
-> agentSessionPresenter / agentRuntimePresenter / toolPresenter / llmProviderPresenter
-> route services / consumer-owned narrow ports
-> sessionApplication coordinators / typed runtimes / retained resource presenters
```

`useLegacyPresenter()`、`presenter:call`、`remoteControlPresenter:call` 和
Expand Down
30 changes: 18 additions & 12 deletions docs/architecture/agent-system-layered-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ DeepChat loop + `AcpProvider` compatibility。
Memory runtime orchestration 已收敛到唯一 `MemoryRuntimeCoordinator`,通过 awaited
`MemoryPromptContributor` 与 background `MemoryIngestionObserver` 接入;Tape tool facts 已迁到 stable
per-fact `TapeRecorder` path,causal observation 只读联结现有 Tape/message/trace。`AgentSessionPresenter`
只保留 core session lifecycle/turn/assignment/shared projection façade;typed routes 直接组合 history、
translation、export、usage、RTK 与 catalog owner,startup hooks 直接调用 migration/maintenance owner。
仅保留 compatibility forwarding;core lifecycle、turn、assignment 与 projection 已由四个
composition-owned session application coordinators 承担。typed routes 直接组合 history、translation、
export、usage、RTK 与 catalog owner,startup hooks 直接调用 migration/maintenance owner。
`AgentRuntimePresenter` 保留 DeepChat state/delegate 与 adapter wiring;两者不再构成 generic agent runtime。
current docs、architecture guards 与 baseline generator
已在 `ASLR-091` 收敛;`ASLR-092` 已完成 canonical baseline write、全量
Expand Down Expand Up @@ -169,15 +170,18 @@ accept input / claim pending item
## AFTER:已实现的当前架构

```text
typed routes / remote / cron
AgentManager (control plane)
├─ AgentCatalog
│ ├─ DeepChatAgentRepository ─┐
│ └─ AcpAgentRepository ├─ shared agents table + typed codecs
├─ AppSessionService ──────────┴─ new_sessions / transcript projection
└─ explicit switch(agent.kind)
typed routes -> SessionService / ChatService -- narrow ports ─┐
remote -> RemoteConversationRunner -- four narrow ports ─────┤
cron -> Cron session starter -- Lifecycle / Turn ports ──────┤
AgentSessionPresenter compatibility façade -- forwarding ─────┘
Lifecycle / Turn / AgentAssignment / Projection
├─ AppSessionService ─ new_sessions / window binding / shared CRUD
└─ AgentManager (control plane)
├─ AgentCatalog
│ ├─ DeepChatAgentRepository ─┐
│ └─ AcpAgentRepository ├─ shared agents table + typed codecs
└─ explicit switch(agent.kind)
├─ kind=deepchat
│ ▼
Expand Down Expand Up @@ -270,7 +274,8 @@ src/main/agent/
└── pending/ # durable pending input coordination

src/main/presenter/
├── agentSessionPresenter/ # retained route/application/shared-projection façade
├── sessionApplication/ # lifecycle/turn/assignment/projection coordinators
├── agentSessionPresenter/ # retained compatibility façade
└── agentRuntimePresenter/ # retained DeepChat state/delegate + message/Tape/resource adapters
```

Expand Down Expand Up @@ -407,6 +412,7 @@ renderer event 缺口;
| --- | --- |
| agent identity、kind、display summary | `AgentCatalog` |
| app session title/project/pin/draft/window binding | shared `AppSessionService` / `new_sessions` |
| lifecycle transaction / turn commands / assignment policy / renderer projection | four `sessionApplication` coordinators over narrow owner ports |
| DeepChat effective config、status、pending inputs、ordered interactions | `DeepChatAgentInstance` |
| pre-stream cancellation before active generation registration | `DeepChatAgentInstance` preparation state |
| active run、abort signal、per-attempt requestSeq、outer providerRoundCount、round messages、overflow retry flags | per-turn `LoopRun` |
Expand Down
43 changes: 25 additions & 18 deletions docs/architecture/agent-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ kind=acp -> direct ACP backend -> external ACP protocol
```mermaid
flowchart TD
UI["Renderer / typed routes"] --> RouteOwners["Session route owners<br/>search / translation / export / usage / catalog"]
UI --> Facade["AgentSessionPresenter<br/>core session façade"]
Facade --> Sessions["AppSessionService"]
Facade --> Manager["AgentManager"]
UI --> Services["SessionService / ChatService"]
Services --> App["Session application coordinators"]
Compat["AgentSessionPresenter<br/>compatibility forwarding"] --> App
App --> Sessions["AppSessionService"]
App --> Manager["AgentManager"]
Manager --> Catalog["strict executable catalog"]
Manager --> DeepBackend["DeepChatAgentBackend"]
Manager --> AcpBackend["DirectAcpSessionBackend"]
Expand All @@ -53,16 +55,19 @@ flowchart TD

- `AgentManager` 是薄 control plane,只做 catalog/app-session lookup、alias normalization、kind switch 和
required facet selection。
- `AgentSessionPresenter` 保留 session CRUD、draft/window binding、title、turn、transfer/subagent 及 shared
projection application logic;它不猜 backend kind,也不拥有 import/search/export/dashboard/catalog。
- `SessionLifecycleCoordinator`、`SessionTurnCoordinator`、`SessionAgentAssignmentCoordinator` 和
`SessionProjectionCoordinator` 分别拥有 core session application invariants;typed Session/Chat、Remote
和 Cron 通过 consumer-owned narrow ports 调用它们。
- `AgentSessionPresenter` 仅保留 compatibility public surface;core session methods 只转发到
composition-owned coordinators,不拥有 application policy、state 或 session-boundary capabilities。
- typed session routes 直接组合 `SessionHistorySearch`、`SessionTranslation`、
`AgentSessionExportService`、`UsageStatsService`、RTK runtime service 与 available-agent catalog policy;
lifecycle hooks 直接调用 startup migration/maintenance owner。
- `AgentRuntimePresenter` 保留 DeepChat state/delegate façade,初始化 `DeepChatAgentRuntime`,并接线现有
message/Tape/prompt/provider/tool/permission adapters。它不再实现 unified agent interface,也不构造
`AcpAgentRuntime`。
- composition root 负责 backend wiring 和 `AcpAgentRuntime` construction;runtime/instance 实现分别位于
`agent/deepchat` 与 `agent/acp`。
`agent/deepchat` 与 `agent/acp`,并且只构造一组 session application coordinators

## 目录与职责

Expand Down Expand Up @@ -108,7 +113,8 @@ kind-specific facet。不存在 optional-method reflection,也不存在 agent
`legacy | direct runtimeKind`。

session delete 是 descriptor-independent cleanup:manager 不 hydrate、不读取 catalog,分别清理两个
backend cache/durable binding;façade 再按 shared state、permission、skills、app row 的既有顺序清理。
backend cache/durable binding;Lifecycle deletion transaction 再按 shared state、permission、skills、app
row 的既有顺序清理。

## DeepChat instance 与 lifecycle

Expand Down Expand Up @@ -167,7 +173,7 @@ DeepChat app projection;`acp_turns` 只是 protocol metadata。

仍保留:

- `AgentSessionPresenter` 和 `AgentRuntimePresenter` 两个薄而明确的 application/state-delegate façade;
- `AgentSessionPresenter` compatibility façade 和 `AgentRuntimePresenter` state/delegate façade;
- `AcpProvider` 的 DeepChat + ACP-provider compatibility;
- `startupMigrations/LegacyChatImportService`、旧 conversations/messages、`SessionPresenter`
export/thread/data compatibility;current agent-session export 由 `AgentSessionExportService` 拥有;
Expand All @@ -186,14 +192,15 @@ DeepChat app projection;`acp_turns` 只是 protocol metadata。
按问题选择入口:

1. kind/session routing:`src/main/agent/manager/agentManager.ts`
2. core session behavior:`src/main/presenter/agentSessionPresenter/index.ts`
3. session search/translation:`src/main/routes/sessions/`
4. current session export:`src/main/presenter/exporter/agentSessionExporter.ts`
5. usage/startup/catalog:`src/main/presenter/{usageStatsService.ts,startupMigrations/}` 与
2. core session application behavior:`src/main/presenter/sessionApplication/`
3. compatibility forwarding:`src/main/presenter/agentSessionPresenter/index.ts`
4. session search/translation:`src/main/routes/sessions/`
5. current session export:`src/main/presenter/exporter/agentSessionExporter.ts`
6. usage/startup/catalog:`src/main/presenter/{usageStatsService.ts,startupMigrations/}` 与
`src/main/agent/shared/availableAgentCatalog.ts`
6. DeepChat session state:`src/main/agent/deepchat/instance/`
7. provider/tool round:`src/main/agent/deepchat/loop/`,再看 retained presenter adapters
8. direct ACP:`src/main/agent/acp/instance/` 与 `src/main/agent/acp/runtime/`
9. tool source/dispatch:`src/main/presenter/toolPresenter/`
10. Tape/message projection:`src/main/presenter/agentRuntimePresenter/{tapeService,messageStore}.ts`
11. Memory runtime seam:`src/main/agent/deepchat/memory/memoryRuntimeCoordinator.ts`
7. DeepChat session state:`src/main/agent/deepchat/instance/`
8. provider/tool round:`src/main/agent/deepchat/loop/`,再看 retained presenter adapters
9. direct ACP:`src/main/agent/acp/instance/` 与 `src/main/agent/acp/runtime/`
10. tool source/dispatch:`src/main/presenter/toolPresenter/`
11. Tape/message projection:`src/main/presenter/agentRuntimePresenter/{tapeService,messageStore}.ts`
12. Memory runtime seam:`src/main/agent/deepchat/memory/memoryRuntimeCoordinator.ts`
Loading
Loading