feat: tabs own the panel header, a Termux key bar, and agent memory

- The panel's top row is now the tab group plus the close button; each tab
  keeps its own header: the files tab has the breadcrumb with new/more (or
  the name and edit/download while previewing), knowledge its search and
  refresh, the terminal its status.
- The key bar is Termux's two rows of seven: ESC / — HOME ↑ END PGUP, then
  TAB CTRL ALT ← ↓ → PGDN; the modifiers still apply to what the phone
  keyboard types.
- The panel is a dialog, so it gives the IME's height back itself
  (viewInsets.bottom). The key bar and the terminal stay above the
  keyboard, and the PTY reflows to the smaller terminal.
- Project knowledge gains the memory tab: both scopes from
  /api/agent-memory/all, absent when the server has memory switched off,
  with type, edit and delete.
- File preview editing passes minLines: null alongside expands.
- 0.3.12 (312).
This commit is contained in:
blumia committed 2026-11-21 11:09:44 +08:00
1 parent 5f95e2da97
commit 5a371e4faf
8 files changed
+675 -231

No files matched your search

+13
View File
@@ -5,6 +5,19 @@
--- ---
## 0.3.12 侧栏头部、Termux 按键栏、键盘避让与记忆(分支 `flutter`)
| 项 | 结果 |
| --- | --- |
| 侧栏头部 | 顶部一行改成「标签组 + 关闭按钮」,标题/目录副标题去掉(目录本来就在面包屑里);文件/项目知识/终端各自的功能按钮下沉到标签自己的头部行——文件页是面包屑右侧的「+ / ⋯」(预览时是「编辑 / 下载」),项目知识页是搜索框 + 刷新,终端页是状态 + 键盘/重启/菜单 |
| 按键栏 | 按 Termux 改成两行七列等宽:`ESC / — HOME ↑ END PGUP`、`TAB CTRL ALT ← ↓ → PGDN`(左下角是 **TAB**,不是收起按钮);CTRL/ALT 修饰对手机输入法的字符仍然生效 |
| 键盘避让 | 侧栏是对话框,不会自己随输入法缩小;现在给底部加上 `MediaQuery.viewInsets.bottom` 的内边距,终端连同按键栏一起抬到键盘上方,`TerminalView` 随之减少行数并把新尺寸回传给 PTY |
| 记忆 | 项目知识新增「记忆」标签:`GET /api/agent-memory/all` 一次取全局与项目两份,服务端把功能关掉时(404)整个标签不出现;卡片显示标题、类型(事实/偏好/参考)、内容,可编辑(标题/类型/正文)与删除,搜索也覆盖记忆 |
| 顺带修复 | 文件预览的编辑框 `expands: true` 缺 `minLines: null`,进编辑会触发断言 |
| 版本 | **0.3.12(code 312)** |
---
## 0.3.11 终端、项目知识与下载进度(分支 `flutter`) ## 0.3.11 终端、项目知识与下载进度(分支 `flutter`)
| 项 | 结果 | | 项 | 结果 |
+5 -3
View File
@@ -5,15 +5,17 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
Flutter to compare mobile UI maturity. Flutter to compare mobile UI maturity.
Status: 0.3.11 — servers (passwordless / password login, HTTP/HTTPS and Status: 0.3.12 — servers (passwordless / password login, HTTP/HTTPS and
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
events, chat with streaming Markdown and full history paging, tool steps events, chat with streaming Markdown and full history paging, tool steps
grouped per turn (icon, one-line summary, foldable run) with image previews, a grouped per turn (icon, one-line summary, foldable run) with image previews, a
context usage ring with a detail sheet, model/agent switching (Build/Plan only, context usage ring with a detail sheet, model/agent switching (Build/Plan only,
current one checked), copy / fork / revert, attachments (photos/files, kept current one checked), copy / fork / revert, attachments (photos/files, kept
after a reload), the agent's native forms, permissions. The files sidebar also after a reload), the agent's native forms, permissions. The files sidebar also
carries the project knowledge (notes, todos, plans) and a full terminal with a carries the project knowledge (notes, todos, plans, and agent memory when the
Termux-style key bar; downloads show their progress and can be cancelled. A server enables it) and a full terminal with a Termux-style key bar; downloads
show their progress and can be cancelled. The panel is a tab row with its own
close button, and each tab has its own header row. A
phone opens the session list as the left drawer and a wide window (tablet, phone opens the session list as the left drawer and a wide window (tablet,
desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop
target used for local testing. target used for local testing.
+56
View File
@@ -586,6 +586,62 @@ class Client {
return ProjectPlanContent.fromJson(r); return ProjectPlanContent.fromJson(r);
} }
// ----------------------------------------------------------------- memory
/// Both memory scopes at once; null when the server has the feature switched
/// off (the route answers 404, which it also uses for a missing entry, but
/// this read has no entry id to miss).
Future<AgentMemorySnapshot?> agentMemory(String projectId,
{String? directory}) async {
try {
final r = await _json('GET', '/api/agent-memory/all',
query: {
if (projectId.isNotEmpty) 'projectId': projectId,
},
directory: directory);
return AgentMemorySnapshot.fromJson(r);
} on ApiError catch (error) {
if (error.status == 404) return null;
rethrow;
}
}
Future<void> updateMemory(String memoryId,
{required String scope,
String? projectId,
String? title,
String? body,
String? type,
String? directory}) async {
await _json(
'PATCH', '/api/agent-memory/${Uri.encodeComponent(memoryId)}',
query: {
'scope': scope,
if (scope == 'project' && projectId != null && projectId.isNotEmpty)
'projectId': projectId,
},
body: {
if (title != null) 'title': title,
if (body != null) 'body': body,
if (type != null) 'type': type,
},
directory: directory);
}
Future<void> deleteMemory(String memoryId,
{required String scope,
String? projectId,
String? directory}) async {
await _json(
'DELETE', '/api/agent-memory/${Uri.encodeComponent(memoryId)}',
query: {
'scope': scope,
if (scope == 'project' && projectId != null && projectId.isNotEmpty)
'projectId': projectId,
},
directory: directory);
}
// --------------------------------------------------------------- terminal // --------------------------------------------------------------- terminal
Future<TerminalSessionInfo> createTerminal( Future<TerminalSessionInfo> createTerminal(
+72
View File
@@ -590,6 +590,78 @@ class ProjectContext {
bool get isEmpty => notes.isEmpty && todos.isEmpty && plans.isEmpty; bool get isEmpty => notes.isEmpty && todos.isEmpty && plans.isEmpty;
} }
/// One remembered fact, preference or reference. The agent writes these
/// through its memory tool; the panel reads, corrects and deletes them.
class AgentMemoryEntry {
final String id;
final String title;
final String body;
final String type; // fact | preference | reference
final int createdAt;
final int updatedAt;
final bool flagged;
final String? sessionId;
const AgentMemoryEntry({
required this.id,
required this.title,
required this.body,
this.type = 'fact',
this.createdAt = 0,
this.updatedAt = 0,
this.flagged = false,
this.sessionId,
});
factory AgentMemoryEntry.fromJson(Map<String, dynamic> j) => AgentMemoryEntry(
id: j['id'] as String? ?? '',
title: j['title'] as String? ?? '',
body: j['body'] as String? ?? '',
type: j['type'] as String? ?? 'fact',
createdAt: (j['createdAt'] as num?)?.toInt() ?? 0,
updatedAt: (j['updatedAt'] as num?)?.toInt() ?? 0,
flagged: j['flagged'] == true,
sessionId: j['sessionId'] as String?,
);
String get typeLabel => switch (type) {
'preference' => '偏好',
'reference' => '参考',
_ => '事实',
};
}
/// Both memory scopes in one read, as `/api/agent-memory/all` answers.
class AgentMemorySnapshot {
final List<AgentMemoryEntry> global;
final List<AgentMemoryEntry> project;
final bool globalFailed;
final bool projectFailed;
const AgentMemorySnapshot({
this.global = const [],
this.project = const [],
this.globalFailed = false,
this.projectFailed = false,
});
factory AgentMemorySnapshot.fromJson(Map<String, dynamic> j) =>
AgentMemorySnapshot(
global: [
for (final m in (j['global'] as List? ?? []))
if (m is Map<String, dynamic>) AgentMemoryEntry.fromJson(m),
],
project: [
for (final m in (j['project'] as List? ?? []))
if (m is Map<String, dynamic>) AgentMemoryEntry.fromJson(m),
],
globalFailed: j['globalFailed'] == true,
projectFailed: j['projectFailed'] == true,
);
bool get isEmpty => global.isEmpty && project.isEmpty;
}
/// A plan as the server reads it back: the link plus its Markdown. /// A plan as the server reads it back: the link plus its Markdown.
class ProjectPlanContent { class ProjectPlanContent {
final String id; final String id;
+180 -168
View File
@@ -387,57 +387,198 @@ class _FilesPanelState extends State<FilesPanel> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
return SafeArea( return SafeArea(
child: Column( child: Padding(
crossAxisAlignment: CrossAxisAlignment.stretch, // The panel is a dialog, so it does not shrink for the keyboard on its
// own: give the IME's height back here, or it covers the terminal's
// key bar and its last lines.
padding:
EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_tabs(theme),
const Divider(height: 1),
Expanded(child: _body(theme)),
],
),
),
);
}
/// The tab row is the panel's title now; the only global action left is
/// closing the panel. Everything else belongs to the tab's own header.
Widget _tabs(ThemeData theme) {
const labels = ['文件', '项目知识', '终端'];
return Padding(
padding: const EdgeInsets.fromLTRB(12, 6, 2, 6),
child: Row(
children: [ children: [
_header(theme), Expanded(
_tabs(theme), child: SegmentedButton<int>(
const Divider(height: 1), showSelectedIcon: false,
Expanded(child: _body(theme)), style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: [
for (var i = 0; i < labels.length; i++)
ButtonSegment(value: i, label: Text(labels[i])),
],
selected: {_tab},
onSelectionChanged: (v) => setState(() => _tab = v.first),
),
),
IconButton(
icon: const Icon(Icons.close),
tooltip: '关闭侧栏',
onPressed: () => Navigator.of(context).maybePop(),
),
], ],
), ),
); );
} }
Widget _header(ThemeData theme) { Widget _body(ThemeData theme) {
return Padding( if (_root.isEmpty) {
padding: const EdgeInsets.fromLTRB(6, 6, 6, 0), return const Center(child: Text('这个会话没有关联目录'));
child: Row( }
children: [ switch (_tab) {
if (_previewPath != null) case 1:
IconButton( return KnowledgePanel(app: widget.app, directory: _root);
icon: const Icon(Icons.arrow_back), case 2:
tooltip: '返回', return TerminalPanel(app: widget.app, directory: _root);
onPressed: () => setState(() => _previewPath = null), default:
) return Column(
else crossAxisAlignment: CrossAxisAlignment.stretch,
const SizedBox(width: 8), children: [
Expanded( _pathBar(theme),
child: Column( Expanded(
crossAxisAlignment: CrossAxisAlignment.start, child: _previewPath != null
? _previewBody(theme)
: _browserBody(theme),
),
],
);
}
}
Widget _browserBody(ThemeData theme) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 6),
child: Row(
children: [
Expanded(
child: TextField(
controller: _search,
onChanged: (v) => setState(() {
_query = v;
_deepResults = [];
_deepDone = false;
}),
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
isDense: true,
prefixIcon: const Icon(Icons.search, size: 20),
hintText: '搜索当前目录…',
suffixIcon: _query.trim().isEmpty
? null
: IconButton(
icon: const Icon(Icons.travel_explore, size: 20),
tooltip: '搜索子目录',
onPressed: _searching ? null : _deepSearch,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12)),
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
),
),
),
],
),
),
if (_searching)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: [ children: [
Text(_previewPath != null ? _previewName : '文件', const SizedBox(
maxLines: 1, width: 14,
overflow: TextOverflow.ellipsis, height: 14,
style: const TextStyle( child: CircularProgressIndicator(strokeWidth: 2)),
fontSize: 16, fontWeight: FontWeight.w600)), const SizedBox(width: 8),
if (_previewPath == null && _root.isNotEmpty) Text('正在搜索子目录…(${_deepResults.length})',
Text(_rootName, style: TextStyle(fontSize: 12, color: theme.hintColor)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12, color: theme.hintColor)),
], ],
), ),
), ),
if (_previewPath != null) ...[ Expanded(child: _list(theme)),
],
);
}
/// The tab's own header: where you are, plus what you can do here. The
/// panel's global actions (close) sit in the tab row above.
Widget _pathBar(ThemeData theme) {
final crumbs = _crumbs;
final preview = _previewPath != null;
return Padding(
padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),
child: Row(
children: [
IconButton(
icon: Icon(preview ? Icons.arrow_back : Icons.arrow_upward,
size: 20),
tooltip: preview ? '返回' : '上一级',
onPressed: preview
? () => setState(() => _previewPath = null)
: (_path == _root ? null : _up),
),
Expanded(
child: preview
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_previewName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13.5, fontWeight: FontWeight.w600)),
Text(_previewPath!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 11, color: theme.hintColor)),
],
)
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_crumb(theme, _rootName, () => _load(_root),
last: crumbs.isEmpty),
for (var i = 0; i < crumbs.length; i++) ...[
Text(' / ', style: TextStyle(color: theme.hintColor)),
_crumb(theme, crumbs[i], () => _goToCrumb(i),
last: i == crumbs.length - 1),
],
],
),
),
),
if (preview) ...[
if (_previewText != null) if (_previewText != null)
IconButton( IconButton(
icon: Icon(_editing ? Icons.visibility_outlined : Icons.edit_outlined), icon: Icon(_editing
? Icons.visibility_outlined
: Icons.edit_outlined),
tooltip: _editing ? '预览' : '编辑', tooltip: _editing ? '预览' : '编辑',
onPressed: _saving onPressed:
? null _saving ? null : () => setState(() => _editing = !_editing),
: () => setState(() => _editing = !_editing),
), ),
if (_editing) if (_editing)
IconButton( IconButton(
@@ -495,136 +636,6 @@ class _FilesPanelState extends State<FilesPanel> {
], ],
), ),
], ],
IconButton(
icon: const Icon(Icons.close),
tooltip: '关闭',
onPressed: () => Navigator.of(context).maybePop(),
),
],
),
);
}
Widget _tabs(ThemeData theme) {
const labels = ['文件', '项目知识', '终端'];
return Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 8),
child: SegmentedButton<int>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: [
for (var i = 0; i < labels.length; i++)
ButtonSegment(value: i, label: Text(labels[i])),
],
selected: {_tab},
onSelectionChanged: (v) => setState(() => _tab = v.first),
),
);
}
Widget _body(ThemeData theme) {
if (_root.isEmpty) {
return const Center(child: Text('这个会话没有关联目录'));
}
switch (_tab) {
case 1:
return KnowledgePanel(app: widget.app, directory: _root);
case 2:
return TerminalPanel(app: widget.app, directory: _root);
default:
if (_previewPath != null) return _previewBody(theme);
return _browser(theme);
}
}
Widget _browser(ThemeData theme) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_pathBar(theme),
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 6),
child: Row(
children: [
Expanded(
child: TextField(
controller: _search,
onChanged: (v) => setState(() {
_query = v;
_deepResults = [];
_deepDone = false;
}),
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
isDense: true,
prefixIcon: const Icon(Icons.search, size: 20),
hintText: '搜索当前目录…',
suffixIcon: _query.trim().isEmpty
? null
: IconButton(
icon: const Icon(Icons.travel_explore, size: 20),
tooltip: '搜索子目录',
onPressed: _searching ? null : _deepSearch,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12)),
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
),
),
),
],
),
),
if (_searching)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: [
const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(strokeWidth: 2)),
const SizedBox(width: 8),
Text('正在搜索子目录…(${_deepResults.length})',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
],
),
),
Expanded(child: _list(theme)),
],
);
}
Widget _pathBar(ThemeData theme) {
final crumbs = _crumbs;
return Padding(
padding: const EdgeInsets.fromLTRB(4, 0, 8, 4),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_upward, size: 20),
tooltip: '上一级',
onPressed: _path == _root ? null : _up,
),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_crumb(theme, _rootName, () => _load(_root), last: crumbs.isEmpty),
for (var i = 0; i < crumbs.length; i++) ...[
Text(' / ', style: TextStyle(color: theme.hintColor)),
_crumb(theme, crumbs[i], () => _goToCrumb(i),
last: i == crumbs.length - 1),
],
],
),
),
),
], ],
), ),
); );
@@ -800,6 +811,7 @@ class _FilesPanelState extends State<FilesPanel> {
child: TextField( child: TextField(
controller: _editor, controller: _editor,
maxLines: null, maxLines: null,
minLines: null,
expands: true, expands: true,
style: const TextStyle(fontSize: 13, fontFamily: 'monospace', height: 1.4), style: const TextStyle(fontSize: 13, fontFamily: 'monospace', height: 1.4),
textAlignVertical: TextAlignVertical.top, textAlignVertical: TextAlignVertical.top,
+316 -17
View File
@@ -18,9 +18,13 @@ class KnowledgePanel extends StatefulWidget {
class _KnowledgePanelState extends State<KnowledgePanel> { class _KnowledgePanelState extends State<KnowledgePanel> {
ProjectContext? _context; ProjectContext? _context;
/// Null when the server has agent memory switched off, in which case the
/// memory section is not offered at all.
AgentMemorySnapshot? _memory;
bool _loading = true; bool _loading = true;
String? _error; String? _error;
int _section = 0; String _section = 'notes';
String _query = ''; String _query = '';
final TextEditingController _search = TextEditingController(); final TextEditingController _search = TextEditingController();
@@ -53,11 +57,19 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
_error = null; _error = null;
}); });
try { try {
final context = await client.projectContext(_projectId, // Both reads in one go: the memory tab appears with the rest instead of
directory: widget.directory); // popping in a moment later.
final results = await Future.wait([
client.projectContext(_projectId, directory: widget.directory),
client.agentMemory(_projectId, directory: widget.directory),
]);
if (!mounted) return; if (!mounted) return;
final context = results[0] as ProjectContext;
final memory = results[1] as AgentMemorySnapshot?;
setState(() { setState(() {
_context = context; _context = context;
_memory = memory;
if (memory == null && _section == 'memory') _section = 'notes';
_loading = false; _loading = false;
}); });
} catch (error) { } catch (error) {
@@ -93,7 +105,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
return Column( return Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 4, 0), padding: const EdgeInsets.fromLTRB(12, 6, 4, 0),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
@@ -103,7 +115,9 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
style: const TextStyle(fontSize: 13), style: const TextStyle(fontSize: 13),
decoration: InputDecoration( decoration: InputDecoration(
isDense: true, isDense: true,
hintText: '搜索笔记、待办与计划', hintText: _memory == null
? '搜索笔记、待办与计划'
: '搜索笔记、待办、计划与记忆',
prefixIcon: const Icon(Icons.search, size: 18), prefixIcon: const Icon(Icons.search, size: 18),
suffixIcon: _query.isEmpty suffixIcon: _query.isEmpty
? null ? null
@@ -134,25 +148,31 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
); );
} }
Widget _sections(ThemeData theme) { List<(String, String, int)> get _sectionsList {
final context_ = _context; final context = _context;
final counts = [ return [
context_?.notes.length ?? 0, ('notes', '笔记', context?.notes.length ?? 0),
context_?.todos.length ?? 0, ('todos', '待办', context?.todos.length ?? 0),
context_?.plans.length ?? 0, ('plans', '计划', context?.plans.length ?? 0),
if (_memory != null)
('memory', '记忆',
(_memory!.global.length + _memory!.project.length)),
]; ];
const names = ['笔记', '待办', '计划']; }
Widget _sections(ThemeData theme) {
final sections = _sectionsList;
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 6), padding: const EdgeInsets.fromLTRB(12, 8, 12, 6),
child: SegmentedButton<int>( child: SegmentedButton<String>(
showSelectedIcon: false, showSelectedIcon: false,
style: const ButtonStyle( style: const ButtonStyle(
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
), ),
segments: [ segments: [
for (var i = 0; i < names.length; i++) for (final (key, label, count) in sections)
ButtonSegment(value: i, label: Text('${names[i]} ${counts[i]}')), ButtonSegment(value: key, label: Text('$label $count')),
], ],
selected: {_section}, selected: {_section},
onSelectionChanged: (value) => setState(() => _section = value.first), onSelectionChanged: (value) => setState(() => _section = value.first),
@@ -180,10 +200,12 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
); );
} }
switch (_section) { switch (_section) {
case 1: case 'todos':
return _todos(theme); return _todos(theme);
case 2: case 'plans':
return _plans(theme); return _plans(theme);
case 'memory':
return _memoryBody(theme);
default: default:
return _notes(theme); return _notes(theme);
} }
@@ -480,6 +502,195 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
); );
} }
// -------------------------------------------------------------- memory
Widget _memoryBody(ThemeData theme) {
final snapshot = _memory;
if (snapshot == null) {
return _empty(theme, Icons.psychology_outlined, '记忆功能未启用');
}
final global = snapshot.global
.where((m) => _matches([m.title, m.body]))
.toList();
final project = snapshot.project
.where((m) => _matches([m.title, m.body]))
.toList();
if (global.isEmpty && project.isEmpty) {
return _empty(
theme,
Icons.psychology_outlined,
_query.isEmpty ? '还没有记忆' : '没有匹配的记忆');
}
return ListView(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
children: [
_memoryGroup(theme, '全局记忆', global, 'global',
failed: snapshot.globalFailed),
const SizedBox(height: 8),
_memoryGroup(theme, '项目记忆', project, 'project',
failed: snapshot.projectFailed),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
'记忆由 agent 在会话中记录;你可以在这里修改或删除它。',
style: TextStyle(fontSize: 11.5, color: theme.hintColor),
),
),
],
);
}
Widget _memoryGroup(
ThemeData theme, String title, List<AgentMemoryEntry> entries, String scope,
{required bool failed}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('$title(${entries.length})',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
if (failed)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('读取失败,请刷新',
style: TextStyle(
fontSize: 12, color: theme.colorScheme.error)),
)
else if (entries.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('暂无', style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
for (final entry in entries) _memoryCard(theme, entry, scope),
],
);
}
Widget _memoryCard(ThemeData theme, AgentMemoryEntry entry, String scope) {
final scheme = theme.colorScheme;
return Card(
margin: const EdgeInsets.only(bottom: 8),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () => _editMemory(entry, scope),
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 4, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(entry.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13.5, fontWeight: FontWeight.w600)),
),
const SizedBox(width: 6),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 5, vertical: 1),
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
),
child: Text(entry.typeLabel,
style: TextStyle(
fontSize: 10, color: theme.hintColor)),
),
if (entry.flagged)
Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(Icons.flag_outlined,
size: 13, color: scheme.error),
),
],
),
const SizedBox(height: 3),
Text(entry.body,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12.5, height: 1.35)),
],
),
),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, size: 18),
onSelected: (value) async {
if (value == 'edit') {
await _editMemory(entry, scope);
} else if (value == 'delete') {
await _deleteMemory(entry, scope);
}
},
itemBuilder: (_) => const [
PopupMenuItem(value: 'edit', child: Text('编辑')),
PopupMenuItem(value: 'delete', child: Text('删除')),
],
),
],
),
),
),
);
}
Future<void> _editMemory(AgentMemoryEntry entry, String scope) async {
final client = _client;
if (client == null) return;
final result = await showDialog<(String, String, String)>(
context: context,
builder: (_) => _MemoryDialog(entry: entry),
);
if (result == null) return;
try {
await client.updateMemory(entry.id,
scope: scope,
projectId: _projectId,
title: result.$1,
body: result.$2,
type: result.$3,
directory: widget.directory);
await _reloadMemory();
} catch (error) {
_fail(error);
}
}
Future<void> _deleteMemory(AgentMemoryEntry entry, String scope) async {
final client = _client;
if (client == null) return;
try {
await client.deleteMemory(entry.id,
scope: scope,
projectId: _projectId,
directory: widget.directory);
await _reloadMemory();
} catch (error) {
_fail(error);
}
}
Future<void> _reloadMemory() async {
final client = _client;
if (client == null) return;
try {
final memory = await client.agentMemory(_projectId,
directory: widget.directory);
if (!mounted) return;
setState(() => _memory = memory);
} catch (error) {
_fail(error);
}
}
// -------------------------------------------------------------- dialogs // -------------------------------------------------------------- dialogs
Widget _sectionHeader( Widget _sectionHeader(
@@ -840,3 +1051,91 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
); );
} }
} }
/// Edit one memory entry: its title, its text, and what kind it is.
class _MemoryDialog extends StatefulWidget {
final AgentMemoryEntry entry;
const _MemoryDialog({required this.entry});
@override
State<_MemoryDialog> createState() => _MemoryDialogState();
}
class _MemoryDialogState extends State<_MemoryDialog> {
late final TextEditingController _title =
TextEditingController(text: widget.entry.title);
late final TextEditingController _body =
TextEditingController(text: widget.entry.body);
late String _type = widget.entry.type;
@override
void dispose() {
_title.dispose();
_body.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('编辑记忆'),
content: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _title,
autofocus: true,
maxLength: 120,
decoration: const InputDecoration(
labelText: '标题',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
SegmentedButton<String>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: const [
ButtonSegment(value: 'fact', label: Text('事实')),
ButtonSegment(value: 'preference', label: Text('偏好')),
ButtonSegment(value: 'reference', label: Text('参考')),
],
selected: {_type},
onSelectionChanged: (value) =>
setState(() => _type = value.first),
),
const SizedBox(height: 8),
TextField(
controller: _body,
maxLength: 2000,
maxLines: 6,
minLines: 4,
decoration: const InputDecoration(
alignLabelWithHint: true,
labelText: '内容',
border: OutlineInputBorder(),
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context), child: const Text('取消')),
FilledButton(
onPressed: () {
final title = _title.text.trim();
if (title.isEmpty) return;
Navigator.pop(context, (title, _body.text.trim(), _type));
},
child: const Text('保存'),
),
],
);
}
}
+32 -42
View File
@@ -186,82 +186,74 @@ class _TerminalPanelState extends State<TerminalPanel> {
// ------------------------------------------------------------- key bar // ------------------------------------------------------------- key bar
static const _symbols = [ /// Two rows of seven, the way Termux lays them out: the keys a phone
'/', '-', '|', '~', '*', r'$', '#', '_', '=', '+', ':', ';', /// keyboard cannot produce, all reachable with a thumb.
'"', "'", '(', ')', '[', ']', '{', '}', '<', '>', '?', '!',
'&', r'\', '^', '%', '@',
];
Widget _keyBar(ThemeData theme) { Widget _keyBar(ThemeData theme) {
return Container( return Container(
height: 46,
decoration: BoxDecoration( decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHigh, color: theme.colorScheme.surfaceContainerHigh,
border: Border(top: BorderSide(color: theme.dividerColor, width: 0.5)), border: Border(top: BorderSide(color: theme.dividerColor, width: 0.5)),
), ),
child: SingleChildScrollView( padding: const EdgeInsets.fromLTRB(3, 3, 3, 3),
scrollDirection: Axis.horizontal, child: Column(
padding: const EdgeInsets.symmetric(horizontal: 6), mainAxisSize: MainAxisSize.min,
child: Row( children: [
children: [ _keyRow([
_key('CTRL', active: _t.ctrl, onTap: _t.toggleCtrl),
_key('ALT', active: _t.alt, onTap: _t.toggleAlt),
_key('SHIFT', active: _t.shift, onTap: _t.toggleShift),
_divider(theme),
_key('ESC', onTap: () => _sendKey(TerminalKey.escape)), _key('ESC', onTap: () => _sendKey(TerminalKey.escape)),
_key('TAB', onTap: () => _sendKey(TerminalKey.tab)), _key('/', onTap: () => _sendText('/')),
_divider(theme), _key('—', onTap: () => _sendText('-')),
_key('←', onTap: () => _sendKey(TerminalKey.arrowLeft)),
_key('↑', onTap: () => _sendKey(TerminalKey.arrowUp)),
_key('↓', onTap: () => _sendKey(TerminalKey.arrowDown)),
_key('→', onTap: () => _sendKey(TerminalKey.arrowRight)),
_divider(theme),
_key('HOME', onTap: () => _sendKey(TerminalKey.home)), _key('HOME', onTap: () => _sendKey(TerminalKey.home)),
_key('↑', big: true, onTap: () => _sendKey(TerminalKey.arrowUp)),
_key('END', onTap: () => _sendKey(TerminalKey.end)), _key('END', onTap: () => _sendKey(TerminalKey.end)),
_key('PGUP', onTap: () => _sendKey(TerminalKey.pageUp)), _key('PGUP', onTap: () => _sendKey(TerminalKey.pageUp)),
]),
_keyRow([
_key('TAB', onTap: () => _sendKey(TerminalKey.tab)),
_key('CTRL', active: _t.ctrl, onTap: _t.toggleCtrl),
_key('ALT', active: _t.alt, onTap: _t.toggleAlt),
_key('←', big: true, onTap: () => _sendKey(TerminalKey.arrowLeft)),
_key('↓', big: true, onTap: () => _sendKey(TerminalKey.arrowDown)),
_key('→', big: true, onTap: () => _sendKey(TerminalKey.arrowRight)),
_key('PGDN', onTap: () => _sendKey(TerminalKey.pageDown)), _key('PGDN', onTap: () => _sendKey(TerminalKey.pageDown)),
_key('DEL', onTap: () => _sendKey(TerminalKey.delete)), ]),
_divider(theme), ],
for (final symbol in _symbols)
_key(symbol, onTap: () => _sendText(symbol)),
],
),
), ),
); );
} }
Widget _divider(ThemeData theme) => Container( Widget _keyRow(List<Widget> keys) => Padding(
width: 1, padding: const EdgeInsets.symmetric(vertical: 1.5),
height: 20, child: Row(
margin: const EdgeInsets.symmetric(horizontal: 4), children: [for (final key in keys) Expanded(child: key)],
color: theme.dividerColor, ),
); );
/// [big] draws a single glyph (an arrow) larger than a word.
Widget _key(String label, Widget _key(String label,
{bool active = false, required VoidCallback onTap}) { {bool active = false, bool big = false, required VoidCallback onTap}) {
final theme = Theme.of(context); final theme = Theme.of(context);
final scheme = theme.colorScheme; final scheme = theme.colorScheme;
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: onTap, onTap: onTap,
child: Container( child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2, vertical: 8), height: 30,
padding: const EdgeInsets.symmetric(horizontal: 10), margin: const EdgeInsets.symmetric(horizontal: 1.5),
alignment: Alignment.center, alignment: Alignment.center,
constraints: const BoxConstraints(minWidth: 34),
decoration: BoxDecoration( decoration: BoxDecoration(
color: active color: active
? scheme.primary.withValues(alpha: 0.22) ? scheme.primary.withValues(alpha: 0.22)
: scheme.surfaceContainerHighest, : scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(6),
border: Border.all( border: Border.all(
color: active ? scheme.primary : Colors.transparent, width: 1), color: active ? scheme.primary : Colors.transparent, width: 1),
), ),
child: Text( child: Text(
label, label,
maxLines: 1,
style: TextStyle( style: TextStyle(
fontFamily: 'monospace', fontFamily: 'monospace',
fontSize: 12, fontSize: big ? 16 : 11,
fontWeight: active ? FontWeight.w700 : FontWeight.w500, fontWeight: active ? FontWeight.w700 : FontWeight.w500,
color: active ? scheme.primary : scheme.onSurface, color: active ? scheme.primary : scheme.onSurface,
), ),
@@ -270,8 +262,6 @@ class _TerminalPanelState extends State<TerminalPanel> {
); );
} }
// The terminal state applies the pending modifiers (and clears them) as the
// text leaves for the PTY, so both the bar and the phone keyboard take them.
void _sendKey(TerminalKey key) => void _sendKey(TerminalKey key) =>
_t.model.keyInput(key, ctrl: _t.ctrl, alt: _t.alt, shift: _t.shift); _t.model.keyInput(key, ctrl: _t.ctrl, alt: _t.alt, shift: _t.shift);
+1 -1
View File
@@ -2,7 +2,7 @@ name: openchamber
description: "A lightweight OpenChamber client for phones." description: "A lightweight OpenChamber client for phones."
publish_to: 'none' publish_to: 'none'
version: 0.3.11+311 version: 0.3.12+312
environment: environment:
sdk: ^3.14.0 sdk: ^3.14.0