fix: resolve golangci-lint funlen, nilerr, and empty branch issues

This commit is contained in:
sam committed 2026-09-02 23:10:38 +10:00
1 parent 5dc3c9895c
commit 59638ed35e
6 files changed
+101 -73

No files matched your search

+32 -13
View File
@@ -310,28 +310,47 @@ func manualRequeueTask(ctx context.Context, st store.TaskStore, taskID int64) er
}
}
func Run() int {
type runArgs struct {
cfgPath string
overlayPath string
noConfigOverlay bool
once bool
requeue int64
}
func parseArgs() (runArgs, bool) {
defaultCfg := filepath.Join(configHome(), "archie", "config.toml")
cfgPath := flag.String("config", defaultCfg, "path to a TOML/YAML config file or configuration directory")
overlayPath := flag.String("config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
noConfigOverlay := flag.Bool("no-config-overlay", false, "skip the runtime config overlay (recovery hatch for the DB overlay; the -config-overlay file overlay still applies)")
once := flag.Bool("once", false, "run a single poll+process cycle and exit (systemd timer / testing)")
requeue := flag.Int64("requeue", 0, "requeue a parked/waiting task by id (keeps its workflow), then exit unless -once is also set")
var args runArgs
flag.StringVar(&args.cfgPath, "config", defaultCfg, "path to a TOML/YAML config file or configuration directory")
flag.StringVar(&args.overlayPath, "config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
flag.BoolVar(&args.noConfigOverlay, "no-config-overlay", false, "skip the runtime config overlay (recovery hatch for the DB overlay; the -config-overlay file overlay still applies)")
flag.BoolVar(&args.once, "once", false, "run a single poll+process cycle and exit (systemd timer / testing)")
flag.Int64Var(&args.requeue, "requeue", 0, "requeue a parked/waiting task by id (keeps its workflow), then exit unless -once is also set")
showVersion := flag.Bool("version", false, "print the gateway and runtime versions and exit")
flag.Parse()
// The versions were only reachable through the chat /version command,
// which needs a running daemon and a configured channel. An update-check
// adapter has to answer "what is installed?" from a shell, so expose the
// same two values here. Machine-readable: one "name version" per line.
if *showVersion {
fmt.Printf("archied %s\narchie-agent %s\n", gatewayVersion, runtimeVersion)
return args, true
}
return args, false
}
func Run() int {
args, exit := parseArgs()
if exit {
return 0
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
b := newBootstrap()
if err := b.loadConfig(ctx, *cfgPath, *overlayPath, *noConfigOverlay); err != nil {
if err := b.loadConfig(ctx, args.cfgPath, args.overlayPath, args.noConfigOverlay); err != nil {
return 1
}
defer b.cleanup()
@@ -339,12 +358,12 @@ func Run() int {
if err := b.openStores(ctx); err != nil {
return 1
}
if exit, err := b.handleRequeue(ctx, *requeue, *once); err != nil {
if exit, err := b.handleRequeue(ctx, args.requeue, args.once); err != nil {
return 1
} else if exit {
return 0
}
b.loadCatalog(ctx, *cfgPath)
b.loadCatalog(ctx, args.cfgPath)
b.setupObservability()
if err := b.setupBackends(ctx); err != nil {
@@ -352,7 +371,7 @@ func Run() int {
}
b.setupLLMAndChat(ctx)
if !b.setupGateways(ctx, *cfgPath, *overlayPath) {
if !b.setupGateways(ctx, args.cfgPath, args.overlayPath) {
return 1
}
@@ -380,15 +399,15 @@ func Run() int {
}
b.registerStandaloneTools()
b.buildDaemon()
b.wireConfigPublishing(ctx, *cfgPath, *overlayPath)
b.wireConfigPublishing(ctx, args.cfgPath, args.overlayPath)
b.installUpdateConfigHandler()
b.installUpdateRepoFieldHandler()
b.installConfigHandlers(*cfgPath, *overlayPath)
b.installConfigHandlers(args.cfgPath, args.overlayPath)
if err := b.startServices(ctx); err != nil {
return 1
}
return exitCode(b.runLoop(ctx, *once))
return exitCode(b.runLoop(ctx, args.once))
}
// bootConfigOverlay layers the runtime config overlay over the resolved
+61 -52
View File
@@ -251,6 +251,64 @@ func (g *Gateway) Start(ctx context.Context, router *gateway.Router, lifecycle g
}
}
func (g *Gateway) registerCommandHandlers(b *bot.Bot, router *gateway.Router) {
b.RegisterHandler(bot.HandlerTypeMessageText, "/status", bot.MatchTypeExact, g.statusHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/whoami", bot.MatchTypeExact, g.whoamiHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/profile", bot.MatchTypeExact, g.profileHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/sessions", bot.MatchTypeExact, g.sessionsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/resume", bot.MatchTypeExact, g.resumeHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/agents", bot.MatchTypeExact, g.agentsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/version", bot.MatchTypeExact, g.versionHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/update", bot.MatchTypeExact, g.updateHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, g.startHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/help", bot.MatchTypeExact, g.helpHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/restart", bot.MatchTypeExact, g.restartHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/rollback", bot.MatchTypePrefix, g.rollbackHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/stop", bot.MatchTypePrefix, g.stopHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/approve", bot.MatchTypeExact, g.approveHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/deny", bot.MatchTypeExact, g.denyHandler())
}
func (g *Gateway) startListening(ctx context.Context, b *bot.Bot, lifecycle gateway.Lifecycle) error {
if g.WebhookURL != "" {
params := &bot.SetWebhookParams{
URL: g.WebhookURL,
SecretToken: g.WebhookSecret,
MaxConnections: 40,
AllowedUpdates: []string{"message", "callback_query"},
DropPendingUpdates: true,
}
if _, err := b.SetWebhook(ctx, params); err != nil {
return fmt.Errorf("set webhook: %w", err)
}
g.log.Info("webhook set", "url", g.WebhookURL)
info, err := b.GetWebhookInfo(ctx)
if err != nil {
g.log.Warn("failed to get webhook info", "error", err)
} else {
g.log.Info(
"webhook info",
"url", info.URL,
"pending_update_count", info.PendingUpdateCount,
"last_error_message", info.LastErrorMessage,
"max_connections", info.MaxConnections,
)
}
webhookCtx, cancel := context.WithCancel(ctx)
g.webhookCancel = cancel
g.running = true
go b.StartWebhook(webhookCtx)
lifecycle.ReportRunning()
} else {
g.dropPendingUpdates(ctx, b)
g.running = true
go b.Start(ctx)
}
return nil
}
// launch builds one bot instance, registers handlers and starts its delivery
// worker. Webhook readiness is synchronous; long-poll readiness is reported by
// pollReadinessClient after the first successful getUpdates response.
@@ -288,22 +346,7 @@ func (g *Gateway) launch(ctx context.Context, router *gateway.Router, lifecycle
}
g.bot = b
// Gateway-local commands: handled directly, no LLM.
b.RegisterHandler(bot.HandlerTypeMessageText, "/status", bot.MatchTypeExact, g.statusHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/whoami", bot.MatchTypeExact, g.whoamiHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/profile", bot.MatchTypeExact, g.profileHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/sessions", bot.MatchTypeExact, g.sessionsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/resume", bot.MatchTypeExact, g.resumeHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/agents", bot.MatchTypeExact, g.agentsHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/version", bot.MatchTypeExact, g.versionHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/update", bot.MatchTypeExact, g.updateHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, g.startHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/help", bot.MatchTypeExact, g.helpHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/restart", bot.MatchTypeExact, g.restartHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/rollback", bot.MatchTypePrefix, g.rollbackHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/stop", bot.MatchTypePrefix, g.stopHandler(router))
b.RegisterHandler(bot.HandlerTypeMessageText, "/approve", bot.MatchTypeExact, g.approveHandler())
b.RegisterHandler(bot.HandlerTypeMessageText, "/deny", bot.MatchTypeExact, g.denyHandler())
g.registerCommandHandlers(b, router)
// Publish the command list so Telegram renders a menu. Without this
// the commands are undiscoverable and the LLM, having no idea they
@@ -311,42 +354,8 @@ func (g *Gateway) launch(ctx context.Context, router *gateway.Router, lifecycle
g.registerCommands(ctx, b)
g.notifyLaunch(ctx, b)
// Set up webhook or fall back to long polling.
if g.WebhookURL != "" {
params := &bot.SetWebhookParams{
URL: g.WebhookURL,
SecretToken: g.WebhookSecret,
MaxConnections: 40,
AllowedUpdates: []string{"message", "callback_query"},
DropPendingUpdates: true,
}
if _, err := b.SetWebhook(ctx, params); err != nil {
return nil, fmt.Errorf("set webhook: %w", err)
}
g.log.Info("webhook set", "url", g.WebhookURL)
info, err := b.GetWebhookInfo(ctx)
if err != nil {
g.log.Warn("failed to get webhook info", "error", err)
} else {
g.log.Info(
"webhook info",
"url", info.URL,
"pending_update_count", info.PendingUpdateCount,
"last_error_message", info.LastErrorMessage,
"max_connections", info.MaxConnections,
)
}
webhookCtx, cancel := context.WithCancel(ctx)
g.webhookCancel = cancel
g.running = true
go b.StartWebhook(webhookCtx)
lifecycle.ReportRunning()
} else {
g.dropPendingUpdates(ctx, b)
g.running = true
go b.Start(ctx)
if err := g.startListening(ctx, b, lifecycle); err != nil {
return nil, err
}
return b, nil
@@ -312,9 +312,7 @@ func TestManifestShape(t *testing.T) {
if len(m.Tools) != 0 {
t.Errorf("Manifest().Tools = %v, want none: extraction is a plain completion, not tool-calling", m.Tools)
}
if !m.Skills {
// deliberately NOT checking true -- documents the negative
}
// deliberately NOT checking true -- documents the negative
if m.Skills {
t.Error("Manifest().Skills = true, want false")
}
@@ -105,12 +105,12 @@ func (c *Curator) reviewOne(ctx context.Context, name string) ([]curator.Action,
return nil, err
}
fm, _, parseErr := skill.Parse([]byte(sk.Content))
if parseErr != nil {
fm, _, fail := skill.Parse([]byte(sk.Content))
if fail != nil {
return []curator.Action{{
Type: ActionInvalid,
Detail: name,
Reason: parseErr.Error(),
Reason: fail.Error(),
}}, nil
}