bots-garden/sidekickspublic Fork
⑂ feature/m3-channels-multi-agents
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. 1d19377 · on feature/m3-channels-multi-agents · k33g · 26d ago
main.go · 117 lines · 4.2 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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// 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/channels"
	"git.rickub.com/bots-garden/sidekicks/internal/config"
	"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[channels.ListPayload](events.ChannelsChanged)
	application.RegisterEvent[channels.MessagePayload](events.MessageUpdated)
	application.RegisterEvent[channels.DeltaPayload](events.MessageDelta)
	application.RegisterEvent[channels.TurnPayload](events.TurnChanged)
	application.RegisterEvent[channels.Permission](events.PermissionRequested)
	application.RegisterEvent[channels.PermissionResolvedPayload](events.PermissionResolved)
	application.RegisterEvent[channels.UsagePayload](events.UsageChanged)
	application.RegisterEvent[channels.CommandsPayload](events.CommandsChanged)
}

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 file dialog is used once the application exists. Events sent while
	// core is created (declared channels) have nobody to reach yet: the
	// interface reads the initial state from the services.
	var wailsApp *application.App
	emitter := events.EmitterFunc(func(name string, payload any) {
		if wailsApp != nil {
			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.ChannelService{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)
	}
}