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

+2
View File
@@ -95,6 +95,7 @@ class Client {
String? search,
String? directory,
bool? archived,
String? parentID,
}) async {
final query = <String, String>{
'limit': '$limit',
@@ -103,6 +104,7 @@ class Client {
if (search != null && search.isNotEmpty) 'search': search,
if (directory != null && directory.isNotEmpty) 'directory': directory,
if (archived != null) 'archived': '$archived',
if (parentID != null && parentID.isNotEmpty) 'parentID': parentID,
};
final r = await _json('GET', '/api/session', query: query, directory: directory);
final data = (r['data'] as List? ?? [])
+39 -8
View File
@@ -135,19 +135,50 @@ class _ChatScreenState extends State<ChatScreen> {
super.dispose();
}
/// The session that started this one, when it is a subagent.
Session? get _parentSession {
final parentID = widget.session.parentID;
if (parentID == null || parentID.isEmpty) return null;
for (final session in widget.app.sessions) {
if (session.id == parentID) return session;
}
return null;
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final parent = _parentSession;
return Scaffold(
appBar: AppBar(
leading: widget.onOpenSessions == null
? null
: IconButton(
icon: const Icon(Icons.menu),
tooltip: '会话',
onPressed: widget.onOpenSessions,
),
title: Text(_title(), maxLines: 1, overflow: TextOverflow.ellipsis),
// A subagent opened from its parent's row goes back there; its own
// sessions menu would lose that way back on a phone.
leading: parent != null
? IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: '返回父会话',
onPressed: () => widget.app.openChat(parent),
)
: widget.onOpenSessions == null
? null
: IconButton(
icon: const Icon(Icons.menu),
tooltip: '会话',
onPressed: widget.onOpenSessions,
),
title: Row(
children: [
if (widget.session.isChild) ...[
Icon(Icons.smart_toy_outlined,
size: 16, color: theme.hintColor),
const SizedBox(width: 6),
],
Expanded(
child: Text(_title(),
maxLines: 1, overflow: TextOverflow.ellipsis),
),
],
),
actions: [
IconButton(
icon: const Icon(Icons.view_sidebar_outlined),
+31 -6
View File
@@ -289,7 +289,7 @@ class _SessionListPaneState extends State<SessionListPane> {
if (!collapsed)
for (final entry in _dated(group.sessions)) ...[
_caption(entry.key),
for (final session in entry.value) _row(session),
for (final session in entry.value) ..._rowsWithChildren(session),
],
];
}
@@ -449,7 +449,7 @@ class _SessionListPaneState extends State<SessionListPane> {
),
),
if (!collapsed)
for (final session in pinned) _row(session),
for (final session in pinned) ..._rowsWithChildren(session),
];
}
@@ -489,7 +489,24 @@ class _SessionListPaneState extends State<SessionListPane> {
.any((s) => s.parentID == session.id && _app.active.contains(s.id));
}
Widget _row(Session session, {bool archived = false}) {
/// The session's worker sessions (subagents). The API lists them among the
/// sessions, so they are drawn nested right below their parent.
List<Session> _childrenOf(Session parent, {bool archived = false}) {
final source = archived ? _app.archivedSessions : _app.sessions;
return [
for (final session in source)
if (session.parentID == parent.id) session,
]..sort((a, b) => a.created.compareTo(b.created));
}
List<Widget> _rowsWithChildren(Session session, {bool archived = false}) => [
_row(session, archived: archived),
for (final child in _childrenOf(session, archived: archived))
_row(child, archived: archived, child: true),
];
Widget _row(Session session,
{bool archived = false, bool child = false}) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final running = _isActive(session);
@@ -531,6 +548,10 @@ class _SessionListPaneState extends State<SessionListPane> {
minTileHeight: 56,
selected: selected,
selectedTileColor: scheme.primary.withValues(alpha: 0.10),
leading: child
? Icon(Icons.smart_toy_outlined,
size: 16, color: scheme.onSurfaceVariant)
: null,
title: Text(
session.title.isEmpty ? '(无标题会话)' : session.title,
maxLines: 1,
@@ -540,8 +561,10 @@ class _SessionListPaneState extends State<SessionListPane> {
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
),
),
subtitle: Text(_subtitle(session),
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: Text(
child ? '子代理 · ${_subtitle(session)}' : _subtitle(session),
maxLines: 1,
overflow: TextOverflow.ellipsis),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -659,7 +682,7 @@ class _SessionListPaneState extends State<SessionListPane> {
),
if (_showArchived)
for (final session in app.archivedSessions)
_row(session, archived: true),
_row(session, archived: true, child: session.isChild),
if (_showArchived &&
app.archivedLoaded &&
app.archivedSessions.isEmpty)
@@ -684,6 +707,8 @@ class _SessionListPaneState extends State<SessionListPane> {
String _subtitle(Session s) {
final parts = <String>[];
if (s.agent.isNotEmpty) parts.add(s.agent);
final children = _childrenOf(s).length;
if (children > 0) parts.add('$children 个子代理');
if (s.model != null) parts.add(_app.modelName(s.model));
if (s.updated > 0) {
final t = DateTime.fromMillisecondsSinceEpoch(s.updated);
+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();
+1 -1
View File
@@ -1,2 +1,2 @@
/// The app version sent to the server in pairing and relay handshakes.
const appVersion = '0.4.8';
const appVersion = '0.4.9';