feat: add a project from the picker, and keep the context ring

- the project picker has an "Add project" action: a folder browser starts
  at the server user's home, navigates (typed path, up, new folder) and
  adds the chosen folder through POST /api/openchamber/directory; the new
  project becomes the draft's target at once
- refreshProjects merges settings-only projects (newest added first), so a
  project added before its first session still appears in the picker; the
  first session moves it into /api/project as usual
- usageReading no longer hides the composer's context ring when the
  session's model has left the server catalog: a 200K window is assumed,
  the percentage is prefixed with "~", and the usage sheet says the window
  is estimated. A failed model fetch at connect is retried when a chat
  opens, so a normal session shows the real percentage
- tests: the add-project browser flow, settings-only projects, and the
  estimated/known context readings
This commit is contained in:
blumia committed 2026-11-27 09:26:14 +08:00
1 parent bd8afeb686
commit c6b5a870c6
11 files changed
+708 -22

No files matched your search

+29 -4
View File
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import '../api/models.dart';
import '../l10n.dart';
import '../state.dart';
import 'directory_picker.dart';
import 'project_icon.dart';
/// The "All projects" row of the stats scope picker, where a report is not
@@ -117,6 +118,15 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
setState(() => _refreshing = false);
}
/// Browses the server's folders and returns with the new project selected.
Future<void> _addProject() async {
final path = await showDirectoryPicker(context, app: widget.app);
if (path == null || !mounted) return;
final project = widget.app.projectFor(path) ??
ProjectInfo(id: '', canonical: path, name: pathLeaf(path));
Navigator.pop(context, ProjectChoice.project(project));
}
@override
Widget build(BuildContext context) {
final chat = widget.selected == AppState.chatTarget;
@@ -125,10 +135,25 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
final loading = _refreshing && projects.isEmpty;
return Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(16, 14, 16, 6),
child: AppText('Choose project',
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
Padding(
padding: const EdgeInsets.fromLTRB(16, 6, 8, 0),
child: Row(
children: [
const Expanded(
child: AppText('Choose project',
style:
TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
),
TextButton.icon(
onPressed: _addProject,
style: TextButton.styleFrom(
visualDensity: VisualDensity.compact,
padding: const EdgeInsets.symmetric(horizontal: 8)),
icon: const Icon(Icons.create_new_folder_outlined, size: 18),
label: const AppText('Add project'),
),
],
),
),
Expanded(
child: loading