feat: fold subagent trees and open them from Agent Task rows

Subagent sessions now render as a collapsed tree in the sidebar: parents with
workers get an expand/collapse chevron, expanded child rows sit behind a guide
line, and the parent keeps its worker count. The parent of the open subagent
expands once so its child is visible.

Subagent tool rows in the parent chat (subagent or task) are labeled 子代理,
show the description and open the child session on tap; a child outside the
loaded page is fetched by id first.

Subagent chats are read-only by default with the first-party notice;
allowPromptingSubagentSessions permits ordinary subagents, while a Lead's
operator-child worker stays read-only until takeover.

0.4.10 (410).
This commit is contained in:
blumia committed 2026-11-23 21:15:18 +08:00
1 parent cebf09048e
commit 9cbd97d532
10 files changed
+271 -23

No files matched your search

+45
View File
@@ -103,6 +103,11 @@ class AppState extends ChangeNotifier {
/// with the web UI; 'queue' is the first-party default.
String followUpBehavior = 'queue';
/// Server setting: allow typing into a subagent session. Off by default;
/// lead workers stay read-only until taken over regardless (the first-party
/// `allowPromptingSubagentSessions`).
bool allowPromptingSubagentSessions = false;
/// Projects the server knows, for the new-session picker and the sidebar's
/// group headers.
List<ProjectInfo> projects = [];
@@ -171,6 +176,8 @@ class AppState extends ChangeNotifier {
final settings = await cl.settings();
if (client != cl) return;
followUpBehavior = normalizeFollowUp(settings['followUpBehavior']);
allowPromptingSubagentSessions =
settings['allowPromptingSubagentSessions'] == true;
notifyListeners();
} catch (_) {}
}
@@ -469,6 +476,7 @@ class AppState extends ChangeNotifier {
projects = [];
chatsRoot = null;
chatRoots = [];
allowPromptingSubagentSessions = false;
_childrenLoaded.clear();
_childrenLoading.clear();
_projectIcons.clear();
@@ -689,6 +697,43 @@ class AppState extends ChangeNotifier {
/// chats root can be relocated away from the home config directory, so it
/// comes from `/api/fs/home`; before that answer the default layout is still
/// recognised.
/// A subagent session is read-only unless the server allows prompting
/// subagents. A lead's operator worker is read-only until it is taken over.
bool promptReadOnlyFor(Session session) {
final openchamber = session.metadata['openchamber'];
if (openchamber is Map && openchamber['kind'] == 'operator-child') {
return true;
}
if (session.isChild) return !allowPromptingSubagentSessions;
return false;
}
/// Opens a subagent by id, fetching its record when the loaded list does not
/// have it (the tool row can name a session older than the current page).
Future<bool> openSubagent(String sessionId) async {
if (sessionId.isEmpty) return false;
for (final session in sessions) {
if (session.id == sessionId) {
await openChat(session);
return true;
}
}
final cl = client;
if (cl == null) return false;
try {
final session =
await cl.getSession(sessionId, directory: chat?.session.directory);
if (client != cl) return false;
if (!sessions.any((s) => s.id == session.id)) sessions.add(session);
await openChat(session);
return true;
} catch (e) {
_lastError = '无法打开子代理会话:$e';
notifyListeners();
return false;
}
}
bool isChatDirectory(String directory) {
if (directory.isEmpty) return false;
if (directory == chatTarget) return true;