Add a home-restricted folder picker to the new-chat dialog
Server: list_directory returns a directory_listing (path, home, parent, entries with is_dir/is_git_repo/hidden, truncated) confined to the server user's home subtree after cleaning and resolving symlinks, refusing pseudo filesystems and capping entries at 2000. Documented in docs/cli.md. App: "Choose folder…" in the create dialog opens a picker (full-screen page on phones, large dialog on wide windows, Material and Cupertino) with breadcrumbs, filter, Show hidden, git badges, dimmed files, recent folders, inline errors and "Start chat here". The probe app gains a folder fixture for captures.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
// Fixture replies for the new-chat folder picker in the capture probe app
|
||||
// (`search_selection_probe_entry.dart`). They answer `chat_sessions`,
|
||||
// `chat_directories`, `chat_backends` and `list_directory` with server-shaped
|
||||
// bodies over an invented home tree, so `/chat` → New chat → Choose folder can
|
||||
// be rendered and captured without any server.
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
const probeHome = '/home/operator';
|
||||
|
||||
JsonMap _entry(
|
||||
String parent,
|
||||
String name, {
|
||||
bool dir = true,
|
||||
bool git = false,
|
||||
}) => {
|
||||
'name': name,
|
||||
'path': '$parent/$name',
|
||||
'is_dir': dir,
|
||||
'is_git_repo': git,
|
||||
'hidden': name.startsWith('.'),
|
||||
};
|
||||
|
||||
final Map<String, List<JsonMap>> _tree = {
|
||||
probeHome: [
|
||||
for (final name in ['.cache', '.config', '.ssh']) _entry(probeHome, name),
|
||||
_entry(probeHome, 'Desktop'),
|
||||
_entry(probeHome, 'Documents'),
|
||||
_entry(probeHome, 'Downloads'),
|
||||
_entry(probeHome, 'notes', git: true),
|
||||
_entry(probeHome, 'Private'),
|
||||
_entry(probeHome, 'repos'),
|
||||
_entry(probeHome, '.zshrc', dir: false),
|
||||
_entry(probeHome, 'todo.md', dir: false),
|
||||
],
|
||||
'$probeHome/repos': [
|
||||
_entry('$probeHome/repos', 'dotfiles', git: true),
|
||||
_entry('$probeHome/repos', 'pipelines', git: true),
|
||||
_entry('$probeHome/repos', 'scratch'),
|
||||
_entry('$probeHome/repos', 'website', git: true),
|
||||
_entry('$probeHome/repos', 'README.txt', dir: false),
|
||||
],
|
||||
'$probeHome/repos/pipelines': [
|
||||
for (final name in ['.git', '.github'])
|
||||
_entry('$probeHome/repos/pipelines', name),
|
||||
for (final name in ['app', 'cmd', 'docs', 'internal', 'web'])
|
||||
_entry('$probeHome/repos/pipelines', name),
|
||||
for (final name in ['AGENTS.md', 'go.mod', 'README.md'])
|
||||
_entry('$probeHome/repos/pipelines', name, dir: false),
|
||||
],
|
||||
};
|
||||
|
||||
/// The reply for a folder-picker request, or null when [request] is not one.
|
||||
JsonMap? probeFolderReply(JsonMap request) {
|
||||
final id = request['id'];
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_sessions':
|
||||
return {'id': id, 'type': 'chat_sessions', 'chat_sessions': const []};
|
||||
case 'chat_directories':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_directories',
|
||||
'chat_directories': [probeHome, '$probeHome/repos/pipelines'],
|
||||
};
|
||||
case 'chat_backends':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_backends',
|
||||
'chat_backends': ['opencode', 'claude', 'codex'],
|
||||
};
|
||||
case 'list_directory':
|
||||
final body = request['list_directory'];
|
||||
final requested = body is Map ? body['path'] as String? : null;
|
||||
final path = requested == null || requested == '~'
|
||||
? probeHome
|
||||
: requested;
|
||||
final entries = _tree[path];
|
||||
if (path == '$probeHome/Private') {
|
||||
return {'id': id, 'type': 'error', 'error': 'permission denied: $path'};
|
||||
}
|
||||
if (path != probeHome && !path.startsWith('$probeHome/')) {
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'error',
|
||||
'error':
|
||||
'path $path is outside the home directory $probeHome; only '
|
||||
'folders inside home can be listed',
|
||||
};
|
||||
}
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'directory_listing',
|
||||
'directory_listing': {
|
||||
'path': path,
|
||||
'home': probeHome,
|
||||
'parent': path == probeHome
|
||||
? null
|
||||
: path.substring(0, path.lastIndexOf('/')),
|
||||
'entries': entries ?? const [],
|
||||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
import 'probe_folder_fixture.dart';
|
||||
|
||||
/// The run every run-scoped hit names. Its recorded sequences are deliberately
|
||||
/// not its row indexes (plan 5, build 2, plan 1), exactly like the unit
|
||||
/// fixture, so a selection has to resolve the recorded sequence.
|
||||
@@ -395,7 +397,8 @@ JsonMap? probeReply(JsonMap request) {
|
||||
},
|
||||
};
|
||||
default:
|
||||
return error('Fixture does not implement $type');
|
||||
return probeFolderReply(request) ??
|
||||
error('Fixture does not implement $type');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user