mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* feat(hooks): record Codex hook trust on sync with --trust Codex runs a user-level hook only after its trusted_hash is stored in that home's config.toml, keyed by the hook's position in hooks.json. Only the TUI's /hooks review writes it, so every hook Skillshare adds or moves starts untrusted and codex exec skips it without a word. `hooks sync --trust` (global mode, opt-in) asks each Codex home's `codex app-server` for the current hash of the hooks Skillshare owns and writes trusted_hash through config/batchWrite, the same calls /hooks makes, so the hash is always the one Codex computes. It changes nothing else in config.toml: disabled hooks stay disabled and are reported. Trust it wrote is remembered in the hooks state directory, so when a hook moves or is removed the next --trust sync clears the old position, unless that trust has changed since. Without codex on PATH the hook files are still written and the command fails saying trust was not recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(hooks): scope Codex trust to config owner Scope trust selection and saved hashes to the active config owner so a global config cannot trust or reconcile another config’s hooks. Recheck hooks.json after hooks/list to avoid trusting a handler from a stale position, and only report trusted or cleared actions after config/batchWrite succeeds. Keep v1 ownerless hashes cleanup-only so upgraded installs clear stale trust after hook removal without trusting foreign hooks. * fix(hooks): retain parked Codex trust receipts Locate hooks using all records for their canonical file before selecting the active config owner, so identical hooks remain identifiable across shared and symlinked homes. Keep cleanup receipts for parked registrations whose native group still matches, including when duplicate counts make locate ambiguous, while clearing receipts for removed hooks. Add regressions for identical hooks across config owners, symlink aliases, parked-home restoration, ambiguous duplicates, and stale receipt cleanup. * fix(hooks): coalesce symlinked Codex trust homes Canonicalize current-owner and legacy trust receipts so symlink spellings of one hooks.json are processed once. Remove the redundant parked-position branch because the hash-matching fallback below covers it. Add regression coverage for current and legacy receipts. * fix(hooks): coalesce removed Codex hook homes Resolve existing home directories when hook files have been removed so trust receipts for symlink aliases reconcile once. Correct canonical key expectations and exercise coalescing without unsupported ledger migration. * fix(hooks): read reconciled trust fixture into fresh state JSON decoding retains existing map entries, so reusing the seeded receipt map makes the alias appear to survive reconciliation. Decode the persisted state into a new value to verify its actual contents. * feat(hooks): confirm Codex trust before recording it and drop the receipts file `hooks sync --trust` recorded trust for every owned hook without showing what it was trusting, and tracked its own writes in codex-trust.json so it could clear them later. Codex's review exists so that a person sees a command before it runs, and the receipts file was the source of most of the edge cases found in review. Trust is now two steps. A preview asks Codex which owned hooks are new or changed and returns them with their commands and a revision; the write takes that revision and is refused when the hooks changed since. The CLI lists the hooks and asks once, `--yes` skips the question, and without a terminal nothing is trusted unless `--yes` is given. The dashboard gets the same two steps as API routes. Nothing is cleared any more: a leftover entry only matches a hook with the same event, matcher and handler at that position, which is the hook the user already approved. That removes codex-trust.json. The app-server is started without CODEX_HOME for the default home. Codex resolves the symlinks of CODEX_HOME but not of ~/.codex, so a symlinked default home got a trust key the user's own Codex never looks up. A home whose write fails no longer stops the other homes, and the error names which were recorded. A preview releases the hooks operation lock before it waits on Codex, so a slow Codex does not fail other hooks operations. Refs #828 * feat(ui): trust Codex hooks from the Hooks page The dashboard could sync Codex hooks but left them untrusted, so Codex skipped them until the user ran the CLI or approved each one in Codex. The Sync box now offers "Trust Codex hooks" in the global scope when a hook is bound to a Codex target. The dialog shows each hook that needs trust with its full command and records trust for exactly that list; a change since the list was shown is refused. The button is hidden while changes are pending, because trust covers the hooks on disk and the next sync would invalidate it. Refs #828 * test(ui): cover the Codex trust dialog's refused, empty and disabled states Only the happy path was tested, so a regression in the states where the dialog must not offer a write would have passed. The docs sentence on several Codex homes now says what is isolated: a failed write, not a home that cannot be listed. Refs #828 * refactor(hooks): split the trust prompt and output rendering out of the handlers hooks_handlers.go had grown past 500 lines and mixed orchestration with the confirmation prompt and every print function, which the CLI layering rule asks to keep apart. The code is moved unchanged: the prompt goes to hooks_prompt.go and the printing to hooks_render.go. * fix(hooks): leave out a Codex home that cannot be listed instead of stopping With several Codex homes, one home Codex could not list aborted the whole trust run, so a broken account home kept every other home untrusted. A home that fails to list is now reported and left out, and the other homes are previewed and trusted as usual. The CLI warns before the question and exits with an error that names the home; the dashboard dialog shows the same note. When no home can be listed the preview still fails. Codex answers a home it cannot load, such as one with an invalid config.toml, with a successful reply that has no hooks and the reason in `errors`. That was read as a home without hooks and passed silently. It is now a failed listing that carries Codex's own message. Refs #828 * fix(hooks): check the reviewed Codex hooks per home when recording trust The revision was one digest over every home's hooks. When a home was listed in the preview but failed to list again at the write, its hooks dropped out of the digest, so the write was refused as stale: the homes the user had just reviewed stayed untrusted and the real listing error was hidden behind "changed since they were listed". The revision now has one part per home. A home is refused only when its own hooks changed; a home that cannot be listed any more is reported and the reviewed homes are still trusted. Refs #828 * chore: release as 0.30.10 Keep the next release on the patch version the maintainer asked for, instead of the 0.31.0 that Release Please derives from the feat commit. Release-As: 0.30.10 --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Willie <egg358358@gmail.com>
758 lines
31 KiB
Go
758 lines
31 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"sync"
|
|
"sync/atomic"
|
|
"syscall"
|
|
"time"
|
|
|
|
"skillshare/internal/config"
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/sourcewalk"
|
|
"skillshare/internal/version"
|
|
)
|
|
|
|
// Server holds the HTTP server state
|
|
type Server struct {
|
|
cfg *config.Config
|
|
skillsStore *install.MetadataStore
|
|
agentsStore *install.MetadataStore
|
|
addr string
|
|
// trustedOrigins are the origins besides localhost and IP addresses the dashboard answers at.
|
|
trustedOrigins []string
|
|
// refusedHosts are the Hosts servedHandler has logged, so each is logged once.
|
|
refusedMu sync.Mutex
|
|
refusedHosts map[string]bool
|
|
mux *http.ServeMux
|
|
handler http.Handler
|
|
mu sync.RWMutex // protects config: Lock for writes/reloads, RLock for reads
|
|
|
|
startTime time.Time // for uptime reporting in health check
|
|
|
|
// follow is nil while follow_source_links is off; see snapshotFollow.
|
|
follow atomic.Pointer[followConfig]
|
|
|
|
// pluginStop asks the running plugin batch update to start no further plugins.
|
|
pluginStop atomic.Bool
|
|
|
|
// Project mode fields (empty/nil for global mode)
|
|
projectRoot string
|
|
projectCfg *config.ProjectConfig
|
|
// unresolvedTargets are project targets left out of cfg.Targets because
|
|
// they cannot resolve (no path); sync reports them as failed.
|
|
unresolvedTargets map[string]error
|
|
|
|
// uiDistDir, when non-empty, serves UI from this disk directory
|
|
// instead of the embedded SPA. Used for runtime-downloaded UI assets.
|
|
uiDistDir string
|
|
|
|
// basePath is the URL prefix under which the UI and API are served
|
|
// (e.g. "/app"). Empty means serve at root.
|
|
basePath string
|
|
|
|
// onReady is called after the listener is bound but before serving.
|
|
// Used to open the browser only after the port is confirmed available.
|
|
onReady func()
|
|
}
|
|
|
|
// NormalizeBasePath ensures the base path starts with "/" and has no trailing slash.
|
|
// An empty or "/" input returns "".
|
|
func NormalizeBasePath(p string) string {
|
|
p = strings.TrimRight(p, "/")
|
|
if p == "" {
|
|
return ""
|
|
}
|
|
if !strings.HasPrefix(p, "/") {
|
|
p = "/" + p
|
|
}
|
|
return p
|
|
}
|
|
|
|
// wrapBasePath wraps the handler chain with StripPrefix and bare-path redirect
|
|
// when basePath is set. Skips wrapping in dev mode (no uiDistDir) and prints a warning.
|
|
func (s *Server) wrapBasePath() {
|
|
if s.basePath == "" {
|
|
return
|
|
}
|
|
if s.uiDistDir == "" {
|
|
fmt.Fprintf(os.Stderr, "Warning: --base-path is ignored in dev mode (no UI assets). Start Vite without base path.\n")
|
|
s.basePath = ""
|
|
return
|
|
}
|
|
stripped := http.StripPrefix(s.basePath, s.handler)
|
|
s.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == s.basePath {
|
|
http.Redirect(w, r, s.basePath+"/", http.StatusMovedPermanently)
|
|
return
|
|
}
|
|
stripped.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
// New creates a new Server for global mode.
|
|
// uiDistDir, when non-empty, serves UI from disk instead of the embedded SPA.
|
|
func New(cfg *config.Config, addr, basePath, uiDistDir string) *Server {
|
|
skillsStore, _ := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
|
|
if skillsStore == nil {
|
|
skillsStore = install.NewMetadataStore()
|
|
}
|
|
agentsStore, _ := install.LoadMetadataWithMigration(cfg.EffectiveAgentsSource(), "agent")
|
|
if agentsStore == nil {
|
|
agentsStore = install.NewMetadataStore()
|
|
}
|
|
s := &Server{
|
|
cfg: cfg,
|
|
skillsStore: skillsStore,
|
|
agentsStore: agentsStore,
|
|
addr: addr,
|
|
mux: http.NewServeMux(),
|
|
basePath: NormalizeBasePath(basePath),
|
|
uiDistDir: uiDistDir,
|
|
}
|
|
s.snapshotFollow()
|
|
s.registerRoutes()
|
|
s.handler = rejectCrossSiteWrites(s.withConfigAutoReload(s.mux))
|
|
s.wrapBasePath()
|
|
return s
|
|
}
|
|
|
|
// NewProject creates a new Server for project mode.
|
|
// uiDistDir, when non-empty, serves UI from disk instead of the embedded SPA.
|
|
func NewProject(cfg *config.Config, projectCfg *config.ProjectConfig, projectRoot, addr, basePath, uiDistDir string) *Server {
|
|
skillsDir := projectCfg.EffectiveSkillsSource(projectRoot)
|
|
agentsDir := projectCfg.EffectiveAgentsSource(projectRoot)
|
|
skillsStore, _ := install.LoadMetadataWithMigration(skillsDir, "")
|
|
if skillsStore == nil {
|
|
skillsStore = install.NewMetadataStore()
|
|
}
|
|
agentsStore, _ := install.LoadMetadataWithMigration(agentsDir, "agent")
|
|
if agentsStore == nil {
|
|
agentsStore = install.NewMetadataStore()
|
|
}
|
|
s := &Server{
|
|
cfg: cfg,
|
|
skillsStore: skillsStore,
|
|
agentsStore: agentsStore,
|
|
addr: addr,
|
|
mux: http.NewServeMux(),
|
|
basePath: NormalizeBasePath(basePath),
|
|
projectRoot: projectRoot,
|
|
projectCfg: projectCfg,
|
|
uiDistDir: uiDistDir,
|
|
}
|
|
_, s.unresolvedTargets = config.ResolveValidProjectTargets(projectRoot, projectCfg)
|
|
s.snapshotFollow()
|
|
s.registerRoutes()
|
|
s.handler = rejectCrossSiteWrites(s.withConfigAutoReload(s.mux))
|
|
s.wrapBasePath()
|
|
return s
|
|
}
|
|
|
|
// IsProjectMode returns true when serving a project-scoped dashboard
|
|
func (s *Server) IsProjectMode() bool {
|
|
return s.projectRoot != ""
|
|
}
|
|
|
|
// skillEntry returns a copy of the skills metadata entry for relPath, or nil.
|
|
// It takes s.mu.RLock, so the caller must not hold s.mu.
|
|
func (s *Server) skillEntry(relPath string) *install.MetadataEntry {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
return copyMetadataEntry(s.skillsStore.GetByPath(relPath))
|
|
}
|
|
|
|
// discoveredSkillEntry returns a copy of the metadata entry for a discovered
|
|
// skill. A skill nested inside a tracked repo has no entry of its own, so it
|
|
// falls back to the repo's entry, which carries the repo source. repoRelPath is
|
|
// the skill's tracked repo root from discovery, empty outside a repo.
|
|
func (s *Server) discoveredSkillEntry(relPath, repoRelPath string) *install.MetadataEntry {
|
|
if repoRelPath == "" {
|
|
return s.skillEntry(relPath)
|
|
}
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
// GetByPath also matches a bare basename key, which for a nested repo skill
|
|
// can be an unrelated top-level skill of the same name. Only an exact or
|
|
// group-matched entry belongs to the skill itself.
|
|
if e := s.skillsStore.GetByPath(relPath); e != nil && (e.Group != "" || s.skillsStore.Has(relPath)) {
|
|
return copyMetadataEntry(e)
|
|
}
|
|
if e := s.skillsStore.Get(repoRelPath); e != nil && e.Tracked {
|
|
return copyMetadataEntry(e)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// agentEntry returns a copy of the agents metadata entry for key, or nil.
|
|
// It takes s.mu.RLock, so the caller must not hold s.mu.
|
|
func (s *Server) agentEntry(key string) *install.MetadataEntry {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
return copyMetadataEntry(s.agentsStore.GetByPath(key))
|
|
}
|
|
|
|
// copyMetadataEntry returns a shallow copy so callers can read the entry after
|
|
// s.mu is released while other requests replace or mutate the store.
|
|
func copyMetadataEntry(e *install.MetadataEntry) *install.MetadataEntry {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
c := *e
|
|
return &c
|
|
}
|
|
|
|
// skillsSource returns the skills source directory for the current mode.
|
|
// Caller must hold s.mu (RLock or Lock) when accessing s.cfg.
|
|
func (s *Server) skillsSource() string {
|
|
if s.IsProjectMode() {
|
|
return s.projectCfg.EffectiveSkillsSource(s.projectRoot)
|
|
}
|
|
return s.cfg.EffectiveSkillsSource()
|
|
}
|
|
|
|
// followConfig is the config skillsWalk reads, copied whenever the config is
|
|
// loaded, reloaded, or saved, so handlers can build a policy without s.mu.
|
|
type followConfig struct {
|
|
source string
|
|
targets map[string]config.TargetConfig
|
|
}
|
|
|
|
// snapshotFollow records the current mode's follow_source_links setting.
|
|
// Caller must hold s.mu or own s exclusively.
|
|
func (s *Server) snapshotFollow() {
|
|
enabled := s.cfg.FollowSourceLinks
|
|
if s.IsProjectMode() {
|
|
enabled = s.projectCfg.FollowSourceLinks
|
|
}
|
|
if !enabled {
|
|
s.follow.Store(nil)
|
|
return
|
|
}
|
|
s.follow.Store(&followConfig{source: s.skillsSource(), targets: s.cloneTargets()})
|
|
}
|
|
|
|
// skillsWalk returns a fresh skills source traversal policy for one request,
|
|
// following first-level source links when the current mode's config enables it.
|
|
func (s *Server) skillsWalk() sourcewalk.Options {
|
|
f := s.follow.Load()
|
|
if f == nil {
|
|
return sourcewalk.Options{}
|
|
}
|
|
return config.SkillsWalk(true, f.source, f.targets)
|
|
}
|
|
|
|
// agentsSource returns the agents source directory for the current mode.
|
|
// Caller must hold s.mu (RLock or Lock) when accessing s.cfg.
|
|
func (s *Server) agentsSource() string {
|
|
if s.IsProjectMode() {
|
|
return s.projectCfg.EffectiveAgentsSource(s.projectRoot)
|
|
}
|
|
return s.cfg.EffectiveAgentsSource()
|
|
}
|
|
|
|
// cloneTargets returns a shallow copy of the Targets map.
|
|
// Callers must hold s.mu (RLock or Lock).
|
|
func (s *Server) cloneTargets() map[string]config.TargetConfig {
|
|
targets := make(map[string]config.TargetConfig, len(s.cfg.Targets))
|
|
for k, v := range s.cfg.Targets {
|
|
targets[k] = v
|
|
}
|
|
return config.WithSharedSkillsTargets(targets, s.cfg.Mode)
|
|
}
|
|
|
|
// parseOpts returns install.ParseOptions from the current config.
|
|
// In project mode, project config is used unconditionally (not a fallback to global).
|
|
func (s *Server) parseOpts() install.ParseOptions {
|
|
if s.IsProjectMode() && s.projectCfg != nil {
|
|
return install.ParseOptions{
|
|
GitLabHosts: s.projectCfg.EffectiveGitLabHosts(),
|
|
AzureHosts: s.projectCfg.EffectiveAzureHosts(),
|
|
CNBHosts: s.projectCfg.EffectiveCNBHosts(),
|
|
GiteaHosts: s.projectCfg.EffectiveGiteaHosts(),
|
|
}
|
|
}
|
|
return install.ParseOptions{
|
|
GitLabHosts: s.cfg.EffectiveGitLabHosts(),
|
|
AzureHosts: s.cfg.EffectiveAzureHosts(),
|
|
CNBHosts: s.cfg.EffectiveCNBHosts(),
|
|
GiteaHosts: s.cfg.EffectiveGiteaHosts(),
|
|
}
|
|
}
|
|
|
|
// gitignoreDir returns the directory containing the managed .gitignore.
|
|
// In project mode this is .skillshare/ (entries are "skills/<name>/");
|
|
// in global mode this is the source skill directory.
|
|
func (s *Server) gitignoreDir() string {
|
|
if s.IsProjectMode() {
|
|
dir, _ := config.ProjectGitignoreTarget(s.projectRoot, s.skillsSource())
|
|
return dir
|
|
}
|
|
return s.cfg.EffectiveSkillsSource()
|
|
}
|
|
|
|
func (s *Server) projectGitignorePrefix() string {
|
|
_, prefix := config.ProjectGitignoreTarget(s.projectRoot, s.skillsSource())
|
|
return prefix
|
|
}
|
|
|
|
// configPath returns the config file path for the current mode
|
|
func (s *Server) configPath() string {
|
|
if s.IsProjectMode() {
|
|
return config.ProjectConfigPath(s.projectRoot)
|
|
}
|
|
return config.ConfigPath()
|
|
}
|
|
|
|
// saveConfig persists the config for the current mode
|
|
func (s *Server) saveConfig() error {
|
|
s.snapshotFollow()
|
|
if s.IsProjectMode() {
|
|
return s.projectCfg.Save(s.projectRoot)
|
|
}
|
|
return s.cfg.Save()
|
|
}
|
|
|
|
// saveAndReloadConfig persists config to disk then reloads it into memory.
|
|
// Callers must hold s.mu.
|
|
func (s *Server) saveAndReloadConfig() error {
|
|
if err := s.saveConfig(); err != nil {
|
|
return fmt.Errorf("failed to save config: %w", err)
|
|
}
|
|
if err := s.reloadConfig(); err != nil {
|
|
return fmt.Errorf("failed to reload config: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// reloadConfig reloads the config for the current mode
|
|
func (s *Server) reloadConfig() error {
|
|
if s.IsProjectMode() {
|
|
pcfg, err := config.LoadProject(s.projectRoot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.projectCfg = pcfg
|
|
s.cfg.Targets, s.unresolvedTargets = config.ResolveValidProjectTargets(s.projectRoot, pcfg)
|
|
skillsDir := pcfg.EffectiveSkillsSource(s.projectRoot)
|
|
agentsDir := pcfg.EffectiveAgentsSource(s.projectRoot)
|
|
s.cfg.Source = skillsDir
|
|
s.cfg.AgentsSource = agentsDir
|
|
if st, err := install.LoadMetadata(skillsDir); err == nil {
|
|
s.skillsStore = st
|
|
}
|
|
if st, err := install.LoadMetadata(agentsDir); err == nil {
|
|
s.agentsStore = st
|
|
}
|
|
s.snapshotFollow()
|
|
return nil
|
|
}
|
|
newCfg, err := config.Load()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.installGlobalConfig(newCfg)
|
|
return nil
|
|
}
|
|
|
|
// installGlobalConfig refreshes dependent state from an already expanded config.
|
|
// Callers must hold s.mu.
|
|
func (s *Server) installGlobalConfig(newCfg *config.Config) {
|
|
s.cfg = newCfg
|
|
if st, err := install.LoadMetadata(newCfg.EffectiveSkillsSource()); err == nil {
|
|
s.skillsStore = st
|
|
}
|
|
if st, err := install.LoadMetadata(newCfg.EffectiveAgentsSource()); err == nil {
|
|
s.agentsStore = st
|
|
}
|
|
s.snapshotFollow()
|
|
}
|
|
|
|
func (s *Server) refreshConfig() error {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
return s.reloadConfig()
|
|
}
|
|
|
|
func (s *Server) shouldAutoReloadConfig(path string) bool {
|
|
if !strings.HasPrefix(path, "/api/") {
|
|
return false
|
|
}
|
|
if path == "/api/health" || path == "/api/update-settings" {
|
|
return false
|
|
}
|
|
// Project handlers reload without persisting legacy migrations, after taking
|
|
// the shared project lock for mutations.
|
|
if path == "/api/projects" || strings.HasPrefix(path, "/api/projects/") {
|
|
return false
|
|
}
|
|
// Keep config editor recoverable even if config file is temporarily invalid.
|
|
if path == "/api/config" {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (s *Server) withConfigAutoReload(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if s.shouldAutoReloadConfig(r.URL.Path) {
|
|
if err := s.refreshConfig(); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "failed to reload config: "+err.Error())
|
|
return
|
|
}
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
// Start starts the HTTP server with graceful shutdown on SIGTERM/SIGINT.
|
|
func (s *Server) Start() error {
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
return s.StartWithContext(ctx)
|
|
}
|
|
|
|
// SetOnReady sets a callback invoked after the listener is bound but before
|
|
// serving begins. Used to open the browser only after the port is confirmed
|
|
// available.
|
|
func (s *Server) SetOnReady(fn func()) {
|
|
s.onReady = fn
|
|
}
|
|
|
|
// StartWithContext starts the HTTP server and shuts down gracefully when ctx is cancelled.
|
|
func (s *Server) StartWithContext(ctx context.Context) error {
|
|
s.startTime = time.Now()
|
|
|
|
// Bind the port first so callers know immediately if it's in use.
|
|
ln, err := net.Listen("tcp", s.addr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if s.basePath != "" {
|
|
fmt.Printf("Skillshare UI running at http://%s%s/\n", s.addr, s.basePath)
|
|
} else {
|
|
fmt.Printf("Skillshare UI running at http://%s\n", s.addr)
|
|
}
|
|
|
|
if s.onReady != nil {
|
|
s.onReady()
|
|
}
|
|
|
|
srv := &http.Server{
|
|
Handler: s.servedHandler(),
|
|
ReadHeaderTimeout: 5 * time.Second,
|
|
ReadTimeout: 15 * time.Second,
|
|
WriteTimeout: 30 * time.Second,
|
|
IdleTimeout: 60 * time.Second,
|
|
}
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- srv.Serve(ln)
|
|
}()
|
|
|
|
select {
|
|
case err := <-errCh:
|
|
return err
|
|
case <-ctx.Done():
|
|
}
|
|
|
|
fmt.Println("\nShutting down server...")
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
if err := srv.Shutdown(shutdownCtx); err != nil {
|
|
return fmt.Errorf("server shutdown: %w", err)
|
|
}
|
|
fmt.Println("Server stopped gracefully")
|
|
return nil
|
|
}
|
|
|
|
// registerRoutes sets up all API and static file routes
|
|
func (s *Server) registerRoutes() {
|
|
// Health check
|
|
s.mux.HandleFunc("GET /api/health", s.handleHealth)
|
|
s.mux.HandleFunc("GET /api/update-settings", s.handleUpdatePolicy)
|
|
|
|
// Overview
|
|
s.mux.HandleFunc("GET /api/overview", s.handleOverview)
|
|
|
|
// Resources (skills + agents)
|
|
s.mux.HandleFunc("GET /api/resources", s.handleListSkills)
|
|
s.mux.HandleFunc("GET /api/resources/templates", s.handleGetTemplates)
|
|
s.mux.HandleFunc("GET /api/resources/templates/preview", s.handlePreviewSkill)
|
|
s.mux.HandleFunc("POST /api/resources", s.handleCreateSkill)
|
|
s.mux.HandleFunc("GET /api/resources/{name}", s.handleGetSkill)
|
|
s.mux.HandleFunc("GET /api/resources/{name}/files/{filepath...}", s.handleGetSkillFile)
|
|
s.mux.HandleFunc("GET /api/resources/{name}/local-changes", s.handleSkillLocalChanges)
|
|
s.mux.HandleFunc("PUT /api/resources/{name}/content", s.handlePutSkillContent)
|
|
s.mux.HandleFunc("PATCH /api/resources/{name}/source", s.handlePatchSkillSource)
|
|
s.mux.HandleFunc("POST /api/resources/{name}/open-in-editor", s.handleOpenSkillInEditor)
|
|
s.mux.HandleFunc("POST /api/resources/{name}/disable", s.handleDisableSkill)
|
|
s.mux.HandleFunc("POST /api/resources/{name}/enable", s.handleEnableSkill)
|
|
s.mux.HandleFunc("DELETE /api/resources/{name}", s.handleUninstallSkill)
|
|
s.mux.HandleFunc("POST /api/resources/batch/targets", s.handleBatchSetTargets)
|
|
s.mux.HandleFunc("POST /api/resources/batch/toggle", s.handleBatchToggleSkills)
|
|
s.mux.HandleFunc("POST /api/resources/batch/move", s.handleBatchMove)
|
|
s.mux.HandleFunc("PATCH /api/resources/{name}/targets", s.handleSetSkillTargets)
|
|
|
|
// Targets
|
|
s.mux.HandleFunc("GET /api/targets", s.handleListTargets)
|
|
s.mux.HandleFunc("POST /api/targets", s.handleAddTarget)
|
|
s.mux.HandleFunc("PATCH /api/targets/{name}", s.handleUpdateTarget)
|
|
s.mux.HandleFunc("DELETE /api/targets/{name}", s.handleRemoveTarget)
|
|
s.mux.HandleFunc("GET /api/targets/{name}/skills-off-preview", s.handleSkillsOffPreview)
|
|
s.mux.HandleFunc("GET /api/targets/{name}/instructions", s.handleGetTargetInstructions)
|
|
s.mux.HandleFunc("PUT /api/targets/{name}/instructions", s.handlePutTargetInstructions)
|
|
s.mux.HandleFunc("POST /api/targets/{name}/instructions/convert", s.handleConvertTargetInstructions)
|
|
s.mux.HandleFunc("PUT /api/targets/{name}/instructions/setup", s.handlePutTargetInstructionsSetup)
|
|
s.mux.HandleFunc("DELETE /api/targets/{name}/instructions/setup", s.handleDeleteTargetInstructionsSetup)
|
|
s.mux.HandleFunc("GET /api/targets/{name}/files", s.handleListTargetFiles)
|
|
s.mux.HandleFunc("POST /api/targets/{name}/files", s.handleAddTargetFile)
|
|
s.mux.HandleFunc("DELETE /api/targets/{name}/files", s.handleRemoveTargetFile)
|
|
s.mux.HandleFunc("GET /api/targets/{name}/files/content", s.handleGetTargetFileContent)
|
|
s.mux.HandleFunc("PUT /api/targets/{name}/files/content", s.handlePutTargetFileContent)
|
|
s.mux.HandleFunc("GET /api/targets/{name}/omp-extensions", s.requireLocalPlugin(s.handleOMPExtensions))
|
|
s.mux.HandleFunc("POST /api/targets/{name}/omp-extensions/preview", s.requireLocalPlugin(s.handleOMPExtensionsPreview))
|
|
s.mux.HandleFunc("POST /api/targets/{name}/omp-extensions/apply", s.requireLocalPlugin(s.handleOMPExtensionsApply))
|
|
s.mux.HandleFunc("GET /api/targets/{name}/pi-extensions", s.requireLocalPlugin(s.handlePiExtensions))
|
|
s.mux.HandleFunc("POST /api/targets/{name}/pi-extensions/preview", s.requireLocalPlugin(s.handlePiExtensionsPreview))
|
|
s.mux.HandleFunc("POST /api/targets/{name}/pi-extensions/apply", s.requireLocalPlugin(s.handlePiExtensionsApply))
|
|
|
|
// Instruction files: shared files (tool targets are global only) and the project AGENTS.md
|
|
s.mux.HandleFunc("GET /api/instructions", s.handleListSharedInstructions)
|
|
s.mux.HandleFunc("POST /api/instructions", s.handleCreateSharedInstructions)
|
|
s.mux.HandleFunc("POST /api/instructions/assign", s.requireGlobalInstructions(s.handleAssignSharedInstructions))
|
|
s.mux.HandleFunc("GET /api/instructions/{name}/content", s.handleGetSharedInstructionsContent)
|
|
s.mux.HandleFunc("PUT /api/instructions/{name}/content", s.handlePutSharedInstructionsContent)
|
|
s.mux.HandleFunc("POST /api/instructions/{name}/restore", s.requireGlobalInstructions(s.handleRestoreSharedInstructions))
|
|
s.mux.HandleFunc("POST /api/instructions/{name}/resolve", s.handleResolveSharedInstructions)
|
|
s.mux.HandleFunc("GET /api/instructions/{name}/restore-preview", s.requireGlobalInstructions(s.handleSharedInstructionsRestorePreview))
|
|
s.mux.HandleFunc("PUT /api/instructions/{name}/targets/{target}/mode", s.requireGlobalInstructions(s.handlePutSharedInstructionsMode))
|
|
s.mux.HandleFunc("POST /api/instructions/{name}/locations", s.handleAddSharedInstructionsLocation)
|
|
s.mux.HandleFunc("DELETE /api/instructions/{name}/locations", s.handleDeleteSharedInstructionsLocation)
|
|
s.mux.HandleFunc("PUT /api/instructions/{name}/locations/mode", s.handlePutSharedInstructionsLocationMode)
|
|
s.mux.HandleFunc("GET /api/instructions/{name}/locations/restore-preview", s.handleSharedInstructionsLocationRestorePreview)
|
|
s.mux.HandleFunc("GET /api/instructions/project", s.requireProjectInstructions(s.handleGetProjectInstructions))
|
|
s.mux.HandleFunc("PUT /api/instructions/project", s.requireProjectInstructions(s.handlePutProjectInstructions))
|
|
s.mux.HandleFunc("POST /api/instructions/project/shim", s.requireProjectInstructions(s.handleProjectInstructionsShim))
|
|
|
|
// Projects (global config only)
|
|
s.mux.HandleFunc("GET /api/projects", s.requireGlobalProjects(s.handleListProjects))
|
|
s.mux.HandleFunc("PUT /api/projects", s.requireGlobalProjects(s.handleSaveProject))
|
|
s.mux.HandleFunc("DELETE /api/projects", s.requireGlobalProjects(s.handleRemoveProject))
|
|
s.mux.HandleFunc("POST /api/projects/convert", s.requireGlobalProjects(s.handleConvertProject))
|
|
|
|
// Sync matrix
|
|
s.mux.HandleFunc("GET /api/sync-matrix", s.handleSyncMatrix)
|
|
s.mux.HandleFunc("POST /api/sync-matrix/preview", s.handleSyncMatrixPreview)
|
|
|
|
// Sync
|
|
s.mux.HandleFunc("POST /api/sync", s.handleSync)
|
|
s.mux.HandleFunc("GET /api/diff/stream", s.handleDiffStream)
|
|
s.mux.HandleFunc("GET /api/diff", s.handleDiff)
|
|
|
|
// Collect
|
|
s.mux.HandleFunc("GET /api/collect/scan", s.handleCollectScan)
|
|
s.mux.HandleFunc("POST /api/collect", s.handleCollect)
|
|
|
|
// Hub
|
|
s.mux.HandleFunc("GET /api/hub/drafts", s.handleHubDrafts)
|
|
s.mux.HandleFunc("POST /api/hub/drafts", s.handleHubDrafts)
|
|
s.mux.HandleFunc("GET /api/hub/drafts/candidates", s.handleHubDraftCandidates)
|
|
s.mux.HandleFunc("POST /api/hub/drafts/import", s.handleHubDraftImport)
|
|
s.mux.HandleFunc("GET /api/hub/drafts/{id}", s.handleHubDraft)
|
|
s.mux.HandleFunc("PUT /api/hub/drafts/{id}", s.handleHubDraft)
|
|
s.mux.HandleFunc("DELETE /api/hub/drafts/{id}", s.handleHubDraft)
|
|
s.mux.HandleFunc("POST /api/hub/drafts/{id}/export", s.handleHubDraftExport)
|
|
s.mux.HandleFunc("GET /api/hub/index", s.handleHubIndex)
|
|
s.mux.HandleFunc("POST /api/hub/refs", s.handleHubRefs)
|
|
s.mux.HandleFunc("GET /api/hub/saved", s.handleGetHubSaved)
|
|
s.mux.HandleFunc("PUT /api/hub/saved", s.handlePutHubSaved)
|
|
s.mux.HandleFunc("POST /api/hub/saved", s.handlePostHubSaved)
|
|
s.mux.HandleFunc("DELETE /api/hub/saved/{label}", s.handleDeleteHubSaved)
|
|
|
|
// Search & Install
|
|
s.mux.HandleFunc("GET /api/search", requireSameOrigin(s.handleSearch))
|
|
s.mux.HandleFunc("GET /api/preview", requireSameOrigin(s.handlePreview))
|
|
s.mux.HandleFunc("POST /api/discover", s.handleDiscover)
|
|
s.mux.HandleFunc("POST /api/install", s.handleInstall)
|
|
s.mux.HandleFunc("POST /api/install/batch", s.handleInstallBatch)
|
|
s.mux.HandleFunc("GET /api/install/missing", s.handleMissingConfigEntries)
|
|
s.mux.HandleFunc("POST /api/install/from-config", s.handleInstallFromConfig)
|
|
s.mux.HandleFunc("POST /api/uninstall/batch", s.handleBatchUninstall)
|
|
s.mux.HandleFunc("POST /api/source-links", s.handleCreateSourceLink)
|
|
s.mux.HandleFunc("DELETE /api/source-links/{name}", s.handleRemoveSourceLink)
|
|
|
|
// Update & Check
|
|
s.mux.HandleFunc("POST /api/update", s.handleUpdate)
|
|
s.mux.HandleFunc("GET /api/update/stream", requireSameOrigin(s.handleUpdateStream))
|
|
s.mux.HandleFunc("GET /api/check/stream", s.handleCheckStream)
|
|
s.mux.HandleFunc("GET /api/check", s.handleCheck)
|
|
|
|
// Repo uninstall
|
|
s.mux.HandleFunc("DELETE /api/repos/{name}", s.handleUninstallRepo)
|
|
|
|
// Version check / app lifecycle
|
|
s.mux.HandleFunc("GET /api/version", s.handleVersionCheck)
|
|
s.mux.HandleFunc("POST /api/upgrade", s.handleUpgrade)
|
|
s.mux.HandleFunc("POST /api/restart", s.handleRestart)
|
|
|
|
// Doctor (health check)
|
|
s.mux.HandleFunc("GET /api/doctor", s.handleDoctor)
|
|
s.mux.HandleFunc("GET /api/doctor/stream", s.handleDoctorStream)
|
|
|
|
// Backups
|
|
s.mux.HandleFunc("GET /api/backups", s.handleListBackups)
|
|
s.mux.HandleFunc("DELETE /api/backups", s.handleDeleteAllBackups)
|
|
s.mux.HandleFunc("DELETE /api/backups/{timestamp}", s.handleDeleteBackup)
|
|
s.mux.HandleFunc("POST /api/backup", s.handleCreateBackup)
|
|
s.mux.HandleFunc("POST /api/backup/cleanup", s.handleCleanupBackups)
|
|
s.mux.HandleFunc("POST /api/restore", s.handleRestore)
|
|
s.mux.HandleFunc("POST /api/restore/validate", s.handleValidateRestore)
|
|
|
|
// File history (backups of single files skillshare rewrote)
|
|
s.mux.HandleFunc("GET /api/file-backups", s.handleListFileBackups)
|
|
s.mux.HandleFunc("GET /api/file-backups/versions", s.handleFileBackupVersions)
|
|
s.mux.HandleFunc("GET /api/file-backups/version", s.handleFileBackupVersion)
|
|
s.mux.HandleFunc("POST /api/file-backups/restore", s.handleRestoreFileBackup)
|
|
|
|
// Trash
|
|
s.mux.HandleFunc("GET /api/trash", s.handleListTrash)
|
|
s.mux.HandleFunc("POST /api/trash/{name}/restore", s.handleRestoreTrash)
|
|
s.mux.HandleFunc("DELETE /api/trash/{name}", s.handleDeleteTrash)
|
|
s.mux.HandleFunc("POST /api/trash/empty", s.handleEmptyTrash)
|
|
|
|
// Extras
|
|
s.mux.HandleFunc("GET /api/plugins", s.requireLocalPlugin(s.handlePluginList))
|
|
s.mux.HandleFunc("GET /api/plugins/{name}/files", s.requireLocalPlugin(s.handlePluginFiles))
|
|
s.mux.HandleFunc("GET /api/plugins/{name}/files/{filepath...}", s.requireLocalPlugin(s.handlePluginFile))
|
|
s.mux.HandleFunc("POST /api/plugins/discover", s.requireLocalPlugin(s.handlePluginDiscover))
|
|
s.mux.HandleFunc("POST /api/plugins/preview", s.requireLocalPlugin(s.handlePluginPreview))
|
|
s.mux.HandleFunc("POST /api/plugins/apply", s.requireLocalPlugin(s.handlePluginApply))
|
|
s.mux.HandleFunc("GET /api/plugins/check/stream", s.requireLocalPlugin(s.handlePluginCheckStream))
|
|
s.mux.HandleFunc("POST /api/plugins/update/stream", s.requireLocalPlugin(s.handlePluginUpdateStream))
|
|
s.mux.HandleFunc("POST /api/plugins/update/stop", s.requireLocalPlugin(s.handlePluginUpdateStop))
|
|
s.mux.HandleFunc("GET /api/mcp", s.requireLocalMCP(s.handleMCPList))
|
|
s.mux.HandleFunc("POST /api/mcp", s.requireLocalMCP(s.handleMCPConfigure))
|
|
s.mux.HandleFunc("GET /api/mcp/check", s.requireLocalMCP(s.handleMCPCheck))
|
|
s.mux.HandleFunc("POST /api/mcp/probe", s.requireLocalMCP(s.handleMCPProbe))
|
|
s.mux.HandleFunc("POST /api/mcp/preview", s.requireLocalMCP(s.handleMCPPreview))
|
|
s.mux.HandleFunc("POST /api/mcp/render", s.requireLocalMCP(s.handleMCPRender))
|
|
s.mux.HandleFunc("POST /api/mcp/import", s.requireLocalMCP(s.handleMCPImport))
|
|
s.mux.HandleFunc("POST /api/mcp/restore", s.requireLocalMCP(s.handleMCPRestore))
|
|
s.mux.HandleFunc("POST /api/mcp/open", s.requireLocalMCP(s.handleMCPOpen))
|
|
s.mux.HandleFunc("GET /api/hooks", s.requireLocalHooks(s.handleHooksList))
|
|
s.mux.HandleFunc("POST /api/hooks", s.requireLocalHooks(s.handleHooksConfigure))
|
|
s.mux.HandleFunc("POST /api/hooks/preview", s.requireLocalHooks(s.handleHooksPreview))
|
|
s.mux.HandleFunc("POST /api/hooks/render", s.requireLocalHooks(s.handleHooksRender))
|
|
s.mux.HandleFunc("POST /api/hooks/import", s.requireLocalHooks(s.handleHooksImport))
|
|
s.mux.HandleFunc("POST /api/hooks/native", s.requireLocalHooks(s.handleHooksNativeApply))
|
|
s.mux.HandleFunc("POST /api/hooks/native/preview", s.requireLocalHooks(s.handleHooksNativePreview))
|
|
s.mux.HandleFunc("POST /api/hooks/restore", s.requireLocalHooks(s.handleHooksRestore))
|
|
s.mux.HandleFunc("POST /api/hooks/codex-trust/preview", s.requireLocalHooks(s.handleHooksCodexTrustPreview))
|
|
s.mux.HandleFunc("POST /api/hooks/codex-trust", s.requireLocalHooks(s.handleHooksCodexTrust))
|
|
s.mux.HandleFunc("GET /api/hooks/catalog", s.requireLocalHooks(s.handleHooksCatalog))
|
|
s.mux.HandleFunc("GET /api/extras", s.handleExtras)
|
|
s.mux.HandleFunc("GET /api/extras/memory/notes", s.handleMemoryNotes)
|
|
s.mux.HandleFunc("GET /api/extras/memory/recent", s.handleMemoryRecent)
|
|
s.mux.HandleFunc("POST /api/extras/memory/init", s.handleMemoryInit)
|
|
s.mux.HandleFunc("PUT /api/extras/memory/index", s.handleMemoryIndex)
|
|
s.mux.HandleFunc("POST /api/extras/memory/move", s.handleMemoryMove)
|
|
s.mux.HandleFunc("GET /api/extras/memory/notes/content", s.handleMemoryContent)
|
|
s.mux.HandleFunc("PUT /api/extras/memory/notes/content", s.handleMemoryWrite)
|
|
s.mux.HandleFunc("DELETE /api/extras/memory/notes/content", s.handleMemoryDelete)
|
|
s.mux.HandleFunc("GET /api/extras/memory/guidance", s.handleMemoryGuidance)
|
|
s.mux.HandleFunc("POST /api/extras/memory/guidance/plan", s.handleMemoryGuidancePlan)
|
|
s.mux.HandleFunc("POST /api/extras/memory/guidance/apply", s.handleMemoryGuidanceApply)
|
|
s.mux.HandleFunc("GET /api/extras/extensions", s.handleExtrasExtensions)
|
|
s.mux.HandleFunc("GET /api/extras/diff", s.handleExtrasDiff)
|
|
s.mux.HandleFunc("POST /api/extras", s.handleExtrasCreate)
|
|
s.mux.HandleFunc("POST /api/extras/sync", s.handleExtrasSync)
|
|
s.mux.HandleFunc("PATCH /api/extras/{name}/mode", s.handleExtrasMode)
|
|
s.mux.HandleFunc("DELETE /api/extras/{name}", s.handleExtrasDelete)
|
|
s.mux.HandleFunc("POST /api/extras/{name}/targets", s.handleExtrasAddTarget)
|
|
s.mux.HandleFunc("DELETE /api/extras/{name}/targets", s.handleExtrasRemoveTarget)
|
|
s.mux.HandleFunc("PUT /api/extras/{name}/targets", s.handleExtrasEditTarget)
|
|
s.mux.HandleFunc("POST /api/extras/{name}/preview", s.handleExtrasPreview)
|
|
s.mux.HandleFunc("PATCH /api/extras/{name}", s.handleExtrasEdit)
|
|
|
|
// Extensions (transform extensions management)
|
|
s.mux.HandleFunc("GET /api/extensions", s.handleExtensionsList)
|
|
s.mux.HandleFunc("POST /api/extensions/install", s.handleExtensionsInstall)
|
|
s.mux.HandleFunc("POST /api/extensions/open", s.handleExtensionsOpen)
|
|
s.mux.HandleFunc("DELETE /api/extensions/{name}", s.handleExtensionsRemove)
|
|
|
|
// Git
|
|
s.mux.HandleFunc("GET /api/git/status", s.handleGitStatus)
|
|
s.mux.HandleFunc("POST /api/git/root", s.handleSetGitRoot)
|
|
s.mux.HandleFunc("GET /api/git/branches", s.handleGitBranches)
|
|
s.mux.HandleFunc("POST /api/git/checkout", s.handleGitCheckout)
|
|
s.mux.HandleFunc("POST /api/git/commit", s.handleGitCommit)
|
|
s.mux.HandleFunc("POST /api/git/discard", s.handleGitDiscard)
|
|
s.mux.HandleFunc("POST /api/git/absorb-nested", s.handleAbsorbNested)
|
|
s.mux.HandleFunc("POST /api/push", s.handlePush)
|
|
s.mux.HandleFunc("POST /api/pull", s.handlePull)
|
|
|
|
// Audit
|
|
s.mux.HandleFunc("GET /api/audit/stream", s.handleAuditStream)
|
|
s.mux.HandleFunc("PATCH /api/audit/policy", s.handleAuditPolicy)
|
|
s.mux.HandleFunc("GET /api/audit/rules/compiled", s.handleGetCompiledRules)
|
|
s.mux.HandleFunc("POST /api/audit/rules/toggle", s.handleToggleRule)
|
|
s.mux.HandleFunc("POST /api/audit/rules/reset", s.handleResetRules)
|
|
s.mux.HandleFunc("GET /api/audit/rules", s.handleGetAuditRules)
|
|
s.mux.HandleFunc("PUT /api/audit/rules", s.handlePutAuditRules)
|
|
s.mux.HandleFunc("POST /api/audit/rules", s.handleInitAuditRules)
|
|
s.mux.HandleFunc("GET /api/audit", s.handleAuditAll)
|
|
s.mux.HandleFunc("GET /api/audit/{name}", s.handleAuditSkill)
|
|
|
|
// Analyze (context-window budget)
|
|
s.mux.HandleFunc("GET /api/analyze", s.handleAnalyze)
|
|
|
|
// Log
|
|
s.mux.HandleFunc("GET /api/log", s.handleListLog)
|
|
s.mux.HandleFunc("GET /api/log/stats", s.handleLogStats)
|
|
s.mux.HandleFunc("DELETE /api/log", s.handleClearLog)
|
|
|
|
// Config
|
|
s.mux.HandleFunc("GET /api/config", s.handleGetConfig)
|
|
s.mux.HandleFunc("PUT /api/config", s.handlePutConfig)
|
|
s.mux.HandleFunc("PATCH /api/config", s.handlePatchConfig)
|
|
s.mux.HandleFunc("GET /api/config/available-targets", s.handleAvailableTargets)
|
|
|
|
// Skillignore
|
|
s.mux.HandleFunc("GET /api/skillignore", s.handleGetSkillignore)
|
|
s.mux.HandleFunc("PUT /api/skillignore", s.handlePutSkillignore)
|
|
|
|
// Agentignore
|
|
s.mux.HandleFunc("GET /api/agentignore", s.handleGetAgentignore)
|
|
s.mux.HandleFunc("PUT /api/agentignore", s.handlePutAgentignore)
|
|
|
|
// SPA fallback — must be last
|
|
if s.uiDistDir != "" {
|
|
s.mux.Handle("/", spaHandlerFromDisk(s.uiDistDir, s.basePath))
|
|
} else {
|
|
s.mux.Handle("/", uiPlaceholderHandler())
|
|
}
|
|
}
|
|
|
|
// handleHealth responds with status, version, and uptime
|
|
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
|
|
uptime := int64(0)
|
|
if !s.startTime.IsZero() {
|
|
uptime = int64(time.Since(s.startTime).Seconds())
|
|
}
|
|
writeJSON(w, map[string]any{
|
|
"status": "ok",
|
|
"version": version.Version,
|
|
"uptime_seconds": uptime,
|
|
})
|
|
}
|