session_state.go RawHistoryFolder
1package port
2
3import (
4 "context"
5
6 "github.com/bnema/dumber/internal/domain/entity"
7)
8
9// WindowStateProvider provides window-scoped browser state for v2 snapshots.
10// Implemented by the UI layer and consumed by the snapshot service.
11type WindowStateProvider interface {
12 // GetWindowSnapshotState returns the ordered window tab lists and active window index atomically.
13 GetWindowSnapshotState() ([]entity.WindowTabListState, int)
14 // GetWindowTabLists returns the ordered list of windows with their tab lists.
15 // For consistent reads alongside GetActiveWindowIndex, prefer GetWindowSnapshotState.
16 GetWindowTabLists() []entity.WindowTabListState
17 // GetActiveWindowIndex returns the index of the currently focused window.
18 // For consistent reads alongside GetWindowTabLists, prefer GetWindowSnapshotState.
19 GetActiveWindowIndex() int
20 // GetSessionID returns the current session ID.
21 GetSessionID() entity.SessionID
22}
23
24// SessionSpawner spawns a new dumber instance for resurrection.
25type SessionSpawner interface {
26 // SpawnWithSession starts a new dumber instance to restore a session.
27 SpawnWithSession(sessionID entity.SessionID) error
28}
29
30// SessionSpawnEnvironment provides engine-specific environment overrides for
31// spawned restore-session processes. Implementations are optional: engines that
32// do not need extra launch environment can leave this nil.
33type SessionSpawnEnvironment interface {
34 // RootCacheEnvVar returns the environment variable used to override the
35 // engine's root cache/data directory.
36 RootCacheEnvVar() string
37 // SessionRootCachePath returns the engine-specific root cache/data path for
38 // the provided restored session.
39 SessionRootCachePath(sessionID entity.SessionID) string
40}
41
42// SnapshotService manages debounced session-state snapshots.
43type SnapshotService interface {
44 // Start begins the snapshot service with the given context.
45 Start(ctx context.Context)
46 // Stop stops the service and saves the final state.
47 Stop(ctx context.Context) error
48 // SetReady marks the service as ready to save snapshots.
49 // Call this after the session has been persisted to the database.
50 SetReady()
51 // MarkDirty signals that session state has changed and should be saved.
52 MarkDirty()
53 // SaveNow forces an immediate save (e.g. for shutdown).
54 SaveNow(ctx context.Context) error
55}