add Claude session storage view with user-driven cleanup

The claude.session-storage command opens a modal listing the workspace's
session transcripts with their on-disk sizes (the <id>.jsonl plus the
<id>/ subagents dir) and a total. Each row deletes with a deliberate
two-click confirm; deletion is guarded against unsafe ids and clide never
removes transcripts on its own. SessionSummary gains a sizeBytes field and
session_index gains formatBytes + deleteSession.

T-148.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 17:02:20 +02:00
co-authored by Claude Opus 4.7
parent 849024b7ee
commit 8907abeca7
8 changed files with 377 additions and 1 deletions
@@ -112,5 +112,50 @@ void main() {
expect(sessions.single.firstUser, 'the very first prompt');
expect(sessions.single.lastUser, 'the very last prompt');
});
test('sizeBytes folds the transcript and its subagents dir (T-148)', () async {
final main = '${userLine('hi')}\n';
await File('${dir.path}/sz.jsonl').writeAsString(main);
final subDir = Directory('${dir.path}/sz/subagents')..createSync(recursive: true);
const subBody = 'agent transcript bytes';
await File('${subDir.path}/agent-1.jsonl').writeAsString(subBody);
final s = (await listSessions(dir)).single;
expect(s.sizeBytes, main.length + subBody.length);
});
});
group('deleteSession', () {
late Directory dir;
setUp(() async => dir = await Directory.systemTemp.createTemp('session_del_test'));
tearDown(() async {
if (await dir.exists()) await dir.delete(recursive: true);
});
test('removes the transcript and its subagents dir', () async {
await File('${dir.path}/del.jsonl').writeAsString('x');
Directory('${dir.path}/del/subagents').createSync(recursive: true);
await File('${dir.path}/del/subagents/a.jsonl').writeAsString('y');
await deleteSession(dir, 'del');
expect(File('${dir.path}/del.jsonl').existsSync(), isFalse);
expect(Directory('${dir.path}/del').existsSync(), isFalse);
});
test('rejects ids that could escape the dir', () async {
expect(() => deleteSession(dir, '../evil'), throwsArgumentError);
expect(() => deleteSession(dir, 'a/b'), throwsArgumentError);
expect(() => deleteSession(dir, ''), throwsArgumentError);
});
});
group('formatBytes', () {
test('scales B / KB / MB / GB', () {
expect(formatBytes(0), '0 B');
expect(formatBytes(512), '512 B');
expect(formatBytes(2048), '2 KB');
expect(formatBytes((1.5 * 1024 * 1024).round()), '1.5 MB');
expect(formatBytes((2 * 1024 * 1024 * 1024).round()), '2.0 GB');
});
});
}
@@ -0,0 +1,74 @@
import 'dart:io';
import 'package:clide/builtin/claude/src/session_index.dart';
import 'package:clide/builtin/claude/src/session_storage.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../helpers/kernel_fixture.dart';
import '../../helpers/widget_harness.dart';
void main() {
late KernelFixture f;
setUp(() async => f = await KernelFixture.create());
tearDown(() => f.dispose());
SessionSummary session(String id, int bytes) => SessionSummary(id: id, modified: DateTime.now(), firstUser: 'f', lastUser: 'l', sizeBytes: bytes);
testWidgets('shows the total and a two-click delete that calls the deleter', (tester) async {
final deleted = <String>[];
await tester.pumpWidget(harness(
f,
SessionStorageDialog(
dir: Directory.systemTemp,
sessions: [session('aaa', 2048)],
onClose: () {},
deleter: (d, id) async => deleted.add(id),
),
));
await tester.pump();
expect(find.text('Session storage · 2 KB total'), findsOneWidget);
expect(find.text('f … l'), findsOneWidget);
// First click arms the confirm; second click deletes.
await tester.tap(find.text('Delete'));
await tester.pump();
expect(find.text('Keep'), findsOneWidget);
await tester.tap(find.text('Delete'));
await tester.pump();
expect(deleted, ['aaa']);
expect(find.text('f … l'), findsNothing); // row removed
});
testWidgets('Escape closes', (tester) async {
var closed = false;
await tester.pumpWidget(harness(
f,
SessionStorageDialog(
dir: Directory.systemTemp,
sessions: [session('aaa', 1024)],
onClose: () => closed = true,
deleter: (_, __) async {},
),
));
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
expect(closed, isTrue);
});
testWidgets('empty list shows a message', (tester) async {
await tester.pumpWidget(harness(
f,
SessionStorageDialog(
dir: Directory.systemTemp,
sessions: const [],
onClose: () {},
deleter: (_, __) async {},
),
));
await tester.pump();
expect(find.text('No sessions found for this workspace.'), findsOneWidget);
});
}