bots-garden/sidekickspublic Fork
⑂ feature/m1-foundations
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/sidekicks.git
git clone ssh://git@rickub.com/bots-garden/sidekicks.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. b34befd · on feature/m1-foundations · k33g · 26d ago
main.go · 87 lines · 2.8 KBGo Blame HistoryRaw
 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
// 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/events"
	"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)
}

func main() {
	configPath := flag.String("config", "", "configuration file (default: $"+config.EnvironmentVariable+", then the default location)")
	flag.Parse()

	location, err := config.Locate(*configPath, os.Getenv, "")
	if err != nil {
		fmt.Fprintln(os.Stderr, "sidekicks:", err)
		os.Exit(1)
	}

	// The emitter is called once the application exists; core only emits
	// after Run has started.
	var wailsApp *application.App
	emitter := events.EmitterFunc(func(name string, payload any) { wailsApp.Event.Emit(name, payload) })
	core := app.New(location, emitter, nil)
	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}),
		},
		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)
	}
}