1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE
// Command sidekicks is the Sidekicks desktop application: it reads the
// configuration, binds the services of internal/app to the Svelte interface
// and opens the window. The main package sits at the repository root because
// the build Taskfiles generated by Wails build "." (ADR 0003, amendment).
//
// sidekicks [--config path/to/config.yaml]
package main
import (
"context"
"embed"
"flag"
"fmt"
"log"
"os"
"git.rickub.com/bots-garden/sidekicks/internal/app"
"git.rickub.com/bots-garden/sidekicks/internal/config"
"git.rickub.com/bots-garden/sidekicks/internal/conversations"
"git.rickub.com/bots-garden/sidekicks/internal/events"
"git.rickub.com/bots-garden/sidekicks/internal/prefs"
"github.com/wailsapp/wails/v3/pkg/application"
)
//go:embed all:frontend/dist
var assets embed.FS
// titleBarInset must match --titlebar-inset in frontend/src/style.css: the
// height of the area covered by the macOS traffic lights.
const titleBarInset = 38
func init() {
// Registering the payload types generates typed TypeScript events.
application.RegisterEvent[events.ConfigChangedPayload](events.ConfigChanged)
application.RegisterEvent[events.AgentStatePayload](events.AgentState)
application.RegisterEvent[events.AgentLogPayload](events.AgentLog)
application.RegisterEvent[conversations.MessagePayload](events.MessageUpdated)
application.RegisterEvent[conversations.DeltaPayload](events.MessageDelta)
application.RegisterEvent[conversations.TurnPayload](events.TurnChanged)
application.RegisterEvent[conversations.Permission](events.PermissionRequested)
application.RegisterEvent[conversations.PermissionResolvedPayload](events.PermissionResolved)
application.RegisterEvent[conversations.UsagePayload](events.UsageChanged)
}
func main() {
configPath := flag.String("config", "", "configuration file (default: $"+config.EnvironmentVariable+", then the default location)")
flag.Parse()
var preferences *prefs.Store
if path, err := prefs.DefaultPath(); err == nil {
preferences = prefs.NewStore(path)
}
lastOpened := ""
if preferences != nil {
lastOpened = preferences.Load().LastOpened
}
location, err := config.Locate(*configPath, os.Getenv, lastOpened)
if err != nil {
fmt.Fprintln(os.Stderr, "sidekicks:", err)
os.Exit(1)
}
// The emitter and the file dialog are called once the application
// exists; core only uses them after Run has started.
var wailsApp *application.App
emitter := events.EmitterFunc(func(name string, payload any) { wailsApp.Event.Emit(name, payload) })
pickFile := func() (string, error) {
return wailsApp.Dialog.OpenFile().
SetTitle("Open a Sidekicks configuration").
AddFilter("YAML configuration", "*.yaml;*.yml").
PromptForSingleSelection()
}
core := app.New(location, app.Options{Emitter: emitter, Preferences: preferences, PickFile: pickFile})
ctx, cancel := context.WithCancel(context.Background())
wailsApp = application.New(application.Options{
Name: "Sidekicks",
Description: "Converse with AI agents in channels",
Services: []application.Service{
application.NewService(&app.AgentService{Core: core}),
application.NewService(&app.ConfigService{Core: core}),
application.NewService(&app.ChatService{Core: core}),
},
Assets: application.AssetOptions{Handler: application.AssetFileServerFS(assets)},
Mac: application.MacOptions{ApplicationShouldTerminateAfterLastWindowClosed: true},
OnShutdown: func() {
cancel()
core.Shutdown(context.Background())
},
})
wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Title: "Sidekicks",
Width: 1280,
Height: 800,
Mac: application.MacWindow{
InvisibleTitleBarHeight: titleBarInset,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(24, 25, 29),
URL: "/",
})
go core.Run(ctx)
if err := wailsApp.Run(); err != nil {
log.Fatal(err)
}
}
|