Chat: unnamed chats take the harness title, harness default per folder, word-safe tables, Send later

- New chat: a cleared Name creates the chat without an operator title; the
  list shows the harness's own title, or the default name until it has one.
  The server no longer records "New chat" for a blank title and OpenCode
  is created without a title so it names the session itself.
- New chat harness defaults to the one last used in the chosen folder,
  else anywhere, else OpenCode; remembered on the device per server.
- Markdown tables wrap at word boundaries and never go below a column's
  longest word (tokens over ~40 characters may break); a table whose words
  cannot fit scrolls sideways with the code block affordance.
- Composer: right-click, long-press, Shift+F10 or the context menu key on
  Send opens Send later... (30 min, 1 h, tomorrow 9:00, usage reset, pick a
  time), sent through the same path with send_at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 19:55:40 +00:00
parent c441400f36
commit b1fcdcf2c3
22 changed files with 1059 additions and 90 deletions
@@ -0,0 +1,88 @@
import 'package:shared_preferences/shared_preferences.dart';
import '../../../core/servers/server_scope.dart';
/// The harness last used to create a chat, per directory and anywhere, kept
/// on this device so the create dialog can offer it again.
abstract interface class ChatCreateHarnessStore {
/// The harness last used in [directory], or null.
Future<String?> read(String directory);
/// The harness last used to create any chat, or null.
Future<String?> readLast();
Future<void> write(String directory, String backend);
}
/// The harness the create dialog starts on: the one last used in the
/// directory, else the one last used anywhere, else OpenCode, else the
/// server's first harness. A remembered harness the server no longer offers
/// is skipped.
String chatDefaultHarness(
List<String> offered, {
String? directoryLast,
String? anywhereLast,
}) {
for (final candidate in [directoryLast, anywhereLast, 'opencode']) {
if (candidate != null && offered.contains(candidate)) return candidate;
}
return offered.first;
}
class SharedPreferencesChatCreateHarnessStore
implements ChatCreateHarnessStore {
const SharedPreferencesChatCreateHarnessStore({this.serverId = ''});
final String serverId;
String _key(String suffix) =>
scopedServerKey('pipelines.chat.createHarness.v1.$suffix', serverId);
Future<String?> _get(String key) async {
try {
final prefs = await SharedPreferences.getInstance();
final value = prefs.getString(key);
return value == null || value.isEmpty ? null : value;
} catch (_) {
return null;
}
}
@override
Future<String?> read(String directory) => _get(_key('dir|$directory'));
@override
Future<String?> readLast() => _get(_key('last'));
@override
Future<void> write(String directory, String backend) async {
if (backend.isEmpty) return;
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_key('dir|$directory'), backend);
await prefs.setString(_key('last'), backend);
} catch (_) {
// Remembering is a convenience; the chat is still created.
}
}
}
/// An in-memory store for tests and hosts without preferences.
class MemoryChatCreateHarnessStore implements ChatCreateHarnessStore {
MemoryChatCreateHarnessStore({Map<String, String>? byDirectory, this.last})
: byDirectory = byDirectory ?? {};
final Map<String, String> byDirectory;
String? last;
@override
Future<String?> read(String directory) async => byDirectory[directory];
@override
Future<String?> readLast() async => last;
@override
Future<void> write(String directory, String backend) async {
byDirectory[directory] = backend;
last = backend;
}
}
@@ -3,6 +3,8 @@ import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../core/servers/server_scope.dart';
export '../domain/chat_default_name.dart' show defaultChatName;
/// Whether a new chat starts with a prompt, and which, for one harness and
/// directory: the last choice made there.
typedef ChatCreatePrompt = ({bool send, String text});
@@ -55,17 +57,3 @@ class SharedPreferencesChatCreatePromptStore implements ChatCreatePromptStore {
}
}
}
/// The default chat name: the directory's last folder and the harness, as in
/// "Pipelines Codex".
String defaultChatName(String directory, String harnessLabel) {
final parts = directory
.split('/')
.where((part) => part.isNotEmpty && part != '~')
.toList();
final leaf = parts.isEmpty ? 'Home' : parts.last;
final folder = leaf.isEmpty
? 'Home'
: '${leaf[0].toUpperCase()}${leaf.substring(1)}';
return '$folder $harnessLabel';
}