feat(app): new chats are named after folder and harness; the first prompt is optional and remembered per harness and folder

This commit is contained in:
2026-10-24 00:25:17 +01:00
parent 1e55b8d2b3
commit 9a2c678f68
5 changed files with 282 additions and 19 deletions
@@ -0,0 +1,67 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
/// 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});
abstract interface class ChatCreatePromptStore {
Future<ChatCreatePrompt?> read(String backend, String directory);
Future<void> write(String backend, String directory, ChatCreatePrompt value);
}
class SharedPreferencesChatCreatePromptStore implements ChatCreatePromptStore {
const SharedPreferencesChatCreatePromptStore();
static String _key(String backend, String directory) =>
'pipelines.chat.createPrompt.v1.$backend|$directory';
@override
Future<ChatCreatePrompt?> read(String backend, String directory) async {
try {
final prefs = await SharedPreferences.getInstance();
final raw = prefs.getString(_key(backend, directory));
if (raw == null) return null;
final data = jsonDecode(raw);
if (data is! Map || data['send'] is! bool || data['text'] is! String) {
return null;
}
return (send: data['send'] as bool, text: data['text'] as String);
} catch (_) {
return null;
}
}
@override
Future<void> write(
String backend,
String directory,
ChatCreatePrompt value,
) async {
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(
_key(backend, directory),
jsonEncode({'send': value.send, 'text': value.text}),
);
} catch (_) {
// Remembering is a convenience; the chat is still created.
}
}
}
/// 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';
}