feat: the files sidebar, Markdown thinking, a banner that clears

- The chat's top-right menu only repeated the per-turn menu. It now opens a
  files sidebar that slides in from the right, the way the official client's
  right panel does: browse the session directory with a breadcrumb and an up
  key, filter the current directory, search its subdirectories (bounded,
  skipping .git/node_modules/build and friends), preview text/code/Markdown/
  images, edit and save text files, create files and folders, and download
  any file through the system save dialog.
- The panel's "..." menu carries the official client's "显示被 git 忽略的文件"
  toggle (the listing asks the server to respect gitignore by default) and a
  refresh. 项目知识 and 终端 have their tabs, marked as coming later.
- Thinking blocks are Markdown too (headings, lists, inline code), rendered
  with the shared MarkdownView at a smaller, quieter size.
- The reconnect banner stayed forever: the stream loop sets it when the SSE
  connection drops and nothing cleared it. Any event proves the stream is
  back (the server greets every connection with server.connected), so it now
  clears the message then.
- Markdown rendering moved to lib/widgets/markdown_view.dart, shared by
  messages, thinking, compaction summaries and file previews.
Version 0.3.9 (code 309).
This commit is contained in:
blumia committed 2026-11-20 18:25:28 +08:00
1 parent b9433c30cb
commit 9b53338908
9 files changed
+1118 -80

No files matched your search

+70 -6
View File
@@ -355,13 +355,66 @@ class Client {
'path': path,
'allowOutsideWorkspace': 'true',
},
directory: directory);
directory: directory,
rawDirectory: true);
if (res.statusCode < 200 || res.statusCode >= 300) {
throw ApiError(res.statusCode, utf8.decode(res.body, allowMalformed: true));
}
return res.body;
}
// ------------------------------------------------------------ files
Future<List<FsEntry>> fsList(String path,
{String? directory, bool respectGitignore = true}) async {
final r = await _json('GET', '/api/fs/list',
query: {
'path': path,
if (respectGitignore) 'respectGitignore': 'true',
},
directory: directory,
rawDirectory: true);
return [
for (final e in (r['entries'] as List? ?? []))
if (e is Map<String, dynamic>) FsEntry.fromJson(e),
];
}
Future<String> fsRead(String path, {String? directory}) async {
final res = await _request('GET', '/api/fs/read',
query: {'path': path}, directory: directory, rawDirectory: true);
final text = utf8.decode(res.body, allowMalformed: true);
if (res.statusCode < 200 || res.statusCode >= 300) {
throw ApiError(res.statusCode, text.trim());
}
return text;
}
Future<FsStat?> fsStat(String path, {String? directory}) async {
final r = await _json('GET', '/api/fs/stat',
query: {'path': path}, directory: directory, rawDirectory: true);
final data = r['path'] == null ? r['data'] : r;
if (data is! Map<String, dynamic>) return null;
return FsStat.fromJson(data);
}
Future<void> fsWrite(String path, String content, {String? directory}) async {
await _json('POST', '/api/fs/write',
body: {'path': path, 'content': content},
directory: directory,
rawDirectory: true);
}
Future<void> fsMkdir(String path, {String? directory}) async {
await _json('POST', '/api/fs/mkdir',
body: {'path': path}, directory: directory, rawDirectory: true);
}
Future<void> fsDelete(String path, {String? directory}) async {
await _json('POST', '/api/fs/delete',
body: {'path': path}, directory: directory, rawDirectory: true);
}
/// Subscribes to GET /api/event, yielding each SSE event. The stream ends
/// when the connection drops; the caller restarts it with backoff.
Stream<Map<String, dynamic>> streamEvents({List<String>? types}) async* {
@@ -410,9 +463,14 @@ class Client {
{Map<String, String>? query,
Map<String, dynamic>? body,
String? directory,
bool partShells = false}) async {
bool partShells = false,
bool rawDirectory = false}) async {
final res = await _request(method, path,
query: query, body: body, directory: directory, partShells: partShells);
query: query,
body: body,
directory: directory,
partShells: partShells,
rawDirectory: rawDirectory);
final text = utf8.decode(res.body, allowMalformed: true);
if (res.statusCode < 200 || res.statusCode >= 300) {
String msg = text;
@@ -434,7 +492,8 @@ class Client {
{Map<String, String>? query,
Map<String, dynamic>? body,
String? directory,
bool partShells = false}) async {
bool partShells = false,
bool rawDirectory = false}) async {
final q = Uri(queryParameters: query ?? {});
final uri = base.resolve(path).replace(queryParameters: q.queryParameters.isEmpty ? null : q.queryParameters);
final req = await _http.openUrl(method, uri);
@@ -445,8 +504,13 @@ class Client {
req.headers.set('Authorization', 'Bearer $token');
}
if (directory != null && directory.isNotEmpty) {
req.headers.set('x-opencode-directory', Uri.encodeComponent(directory));
req.headers.set('x-opencode-directory-encoding', 'uri');
// The file routes compare this header with the workspace path, so they
// need it as written; the rest of the API wants it URI-encoded.
req.headers.set('x-opencode-directory',
rawDirectory ? directory : Uri.encodeComponent(directory));
if (!rawDirectory) {
req.headers.set('x-opencode-directory-encoding', 'uri');
}
}
if (partShells) {
req.headers.set('x-openchamber-part-shells', 'v1');