1package shell
 2
 3import (
 4	"log/slog"
 5	"sync"
 6)
 7
 8// PersistentShell is a singleton shell instance that maintains state across the application
 9type PersistentShell struct {
10	*Shell
11}
12
13var (
14	once          sync.Once
15	shellInstance *PersistentShell
16)
17
18// GetPersistentShell returns the singleton persistent shell instance
19// This maintains backward compatibility with the existing API
20func GetPersistentShell(cwd string) *PersistentShell {
21	once.Do(func() {
22		shellInstance = &PersistentShell{
23			Shell: NewShell(&Options{
24				WorkingDir: cwd,
25				Logger:     &loggingAdapter{},
26			}),
27		}
28	})
29	return shellInstance
30}
31
32// INFO: only used for tests
33func Reset(cwd string) {
34	once = sync.Once{}
35	_ = GetPersistentShell(cwd)
36}
37
38// slog.dapter adapts the internal slog.package to the Logger interface
39type loggingAdapter struct{}
40
41func (l *loggingAdapter) InfoPersist(msg string, keysAndValues ...any) {
42	slog.Info(msg, keysAndValues...)
43}