feat: browse subagent sessions nested under their parent

Sessions with a parentID were filtered out of the sidebar, so a subagent's
conversation was unreachable. They now render indented under the session that
started them (robot marker, "子代理 ·" subtitle), the parent shows its worker
count, and tapping one opens its full chat. Opening a parent also fetches its
children with parentID=<id>, so older workers missing from the loaded page
appear.

A subagent's app bar gets a back arrow to its parent session.

Builds now produce a universal APK plus per-ABI arm64/armv7/x86_64 splits; the
packaging preference is kept in project memory.

0.4.9 (409).
This commit is contained in:
blumia committed 2026-11-23 20:35:21 +08:00
1 parent 79221e57d7
commit cebf09048e
9 files changed
+170 -19

No files matched your search

+40 -1
View File
@@ -133,6 +133,10 @@ class AppState extends ChangeNotifier {
String? _sessionsNext;
bool loadingMoreSessions = false;
/// Parents whose subagent sessions were already fetched.
final Set<String> _childrenLoaded = {};
final Set<String> _childrenLoading = {};
/// Terminal workspaces by directory: each holds that directory's tabs and
/// keeps their shells alive while sessions/tabs are switched.
final Map<String, TerminalWorkspace> terminals = {};
@@ -465,6 +469,8 @@ class AppState extends ChangeNotifier {
projects = [];
chatsRoot = null;
chatRoots = [];
_childrenLoaded.clear();
_childrenLoading.clear();
_projectIcons.clear();
archivedSessions = [];
archivedLoaded = false;
@@ -1196,12 +1202,45 @@ class AppState extends ChangeNotifier {
Future<void> openChat(Session s) async {
draftOpen = false;
chat = ChatState(this, s);
// The shell shows the new session at once; its messages follow.
// The shell shows the new session at once; its messages follow. Fetching
// the session's subagents in parallel fills the nested rows under it.
notifyListeners();
unawaited(loadChildren(s));
await chat!.load();
notifyListeners();
}
/// Fetches a parent's worker sessions once. The global list usually carries
/// them, but an older parent's children can fall outside the loaded page.
Future<void> loadChildren(Session parent) async {
final cl = client;
if (cl == null || parent.isChild) return;
if (_childrenLoaded.contains(parent.id) ||
_childrenLoading.contains(parent.id)) {
return;
}
_childrenLoading.add(parent.id);
try {
final page = await cl.listSessions(
parentID: parent.id, limit: 50, directory: parent.directory);
if (client != cl) return;
final known = sessions.map((s) => s.id).toSet();
var added = false;
for (final child in page.data) {
if (known.add(child.id)) {
sessions.add(child);
added = true;
}
}
_childrenLoaded.add(parent.id);
if (added) notifyListeners();
} catch (_) {
// Retried the next time the session is opened.
} finally {
_childrenLoading.remove(parent.id);
}
}
void closeChat() {
chat = null;
notifyListeners();