* feat(gateway): give /status a real daemon-health surface Phase 2 of archie-core-wp9s. Phase 1 split the commands apart (health vs work) but left /status with one aggregate queue line and a static runtime block; it could not answer the questions an operator actually asks when something feels wrong. /status now reports, between the queue line and the runtime block: - Broker: the live state of this process's own NATS connection (eventbus/nats.Client.Connected), not a fresh dial -- a probe would report the probe's reachability, not the daemon's. - Containers: the pool's own active counter against the configured cap (Pool.Active/Cap), not a Docker listing, which would include containers this pool does not own. A zero cap means unlimited, so it is not shown as a ratio. - Channels: the channel manager's real lifecycle state, including a failed adapter's reason (the documented decision: read the existing manager rather than re-deriving health per adapter). - Chat model: last-known outcome of every chat-model call this process made, recorded once in sendChatTurn (the single choke point) and read back by /status. The second documented decision: never a live probe, so /status stays instant and reports what happened -- or says plainly that nothing has been attempted yet. - Last poll: when the most recent poll pass began, stamped on both poll paths (Run's single-identity loop and runIdentities' per-identity goroutines). A pass that hangs leaves the stamp stale, which is the signal; stamping completion would leave a wedged poller looking healthy. Truthful or absent: a section this process has no source for is omitted rather than rendered as a zero. The standalone Gateway owns no poll loop, pool or channel manager, so its /status reports broker and chat-model health only; aggregating across processes would need a new daemon RPC and is deliberately not built. Version stays out (/version owns it). /status and /tasks descriptions now describe what each command actually does on both published surfaces (Telegram menu/help and the shared specs), pinned by a test that also fails if the two surfaces drift. Sources are read through functions, not captured values: occupancy and channel state move, and the daemon is built after the gateways, so a source captured at construction would freeze /status on boot state. Left in place deliberately: the Runtime (provider/model) block, which Phase 1 flagged and which duplicates /model and /whoami. Removing it is a product call on a command Sam uses daily, not a mechanical follow-up. * docs(prds): record the two open /status health decisions as settled Both were flagged in PR #892 as needing the maintainer's call; both are now answered, and the PRD is the place a follow-up would look: - The Runtime (provider/model) block stays. It is the one line in /status the ticket's own rule says should not be there, but /status is read daily to see the active model at a glance, so the duplication is deliberate. Recorded as a settled product decision so it is not removed later as an oversight. - Health stays per-process. Pooling the daemon's and the Gateway's chat-model outcomes would need a new daemon<->gateway health RPC for one status line, and a per-process line is true where an aggregate would be a claim about a process the answering one cannot see. /agents' published description is still left to archie-core-mxls, unchanged.
107 lines
5.5 KiB
Go
107 lines
5.5 KiB
Go
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/go-telegram/bot"
|
|
"github.com/go-telegram/bot/models"
|
|
)
|
|
|
|
type commandSpec struct {
|
|
Command string
|
|
Description string
|
|
Usage string
|
|
}
|
|
|
|
// gatewayCommandSpecs is the single source of truth for both Telegram's
|
|
// published command menu and /help. Keeping the discoverability surfaces
|
|
// together prevents a newly registered command from being omitted from help.
|
|
var gatewayCommandSpecs = []commandSpec{
|
|
{Command: "status", Description: "Show daemon health: broker, workers, channels, provider", Usage: "/status"},
|
|
{Command: "tasks", Description: "Show your tasks: state, stage, age, parked reason", Usage: "/tasks"},
|
|
{Command: "version", Description: "Show installed Archie versions", Usage: "/version"},
|
|
{Command: "update", Description: "Check for Archie updates", Usage: "/update"},
|
|
{Command: "model", Description: "Choose a provider and model or switch directly", Usage: "/model [provider/model]"},
|
|
{Command: "personality", Description: "Choose a communication style", Usage: "/personality [name]"},
|
|
{Command: "spawn", Description: "Create a tracked task", Usage: "/spawn [identity=name] [repo=owner/name] [workflow=name] <title>"},
|
|
{Command: "cancel", Description: "Cancel a queued or waiting task", Usage: "/cancel [identity=name] <task-id>"},
|
|
{Command: "start", Description: "Confirm that Archie is running", Usage: "/start"},
|
|
{Command: "new", Description: "Start a fresh session, clearing conversation history", Usage: "/new [title]"},
|
|
{Command: "reset", Description: "Alias for /new", Usage: "/reset [title]"},
|
|
{Command: "topic", Description: "List or switch sessions for this channel", Usage: "/topic [off|help|<session-id>]"},
|
|
{Command: "retry", Description: "Replay the last message with a fresh reply", Usage: "/retry"},
|
|
{Command: "undo", Description: "Remove the last N messages from the session", Usage: "/undo [N]"},
|
|
{Command: "title", Description: "Show or set the current session's title", Usage: "/title [name]"},
|
|
{Command: "branch", Description: "Create a child session that inherits the current history", Usage: "/branch [name]"},
|
|
{Command: "fork", Description: "Alias for /branch", Usage: "/fork [name]"},
|
|
{Command: "compress", Description: "Compress the current session's context", Usage: "/compress [here [N]|focus <topic>|--preview|--dry-run]"},
|
|
{Command: "compact", Description: "Alias for /compress", Usage: "/compact [here [N]|focus <topic>|--preview|--dry-run]"},
|
|
{Command: "whoami", Description: "Show the active identity and model", Usage: "/whoami"},
|
|
{Command: "profile", Description: "Show the active identity's profile", Usage: "/profile"},
|
|
{Command: "sessions", Description: "List this channel's sessions", Usage: "/sessions"},
|
|
{Command: "resume", Description: "Switch to a session by id or unique prefix", Usage: "/resume <session-id>"},
|
|
{Command: "delete", Description: "Permanently delete a session and its history", Usage: "/delete <session-id>"},
|
|
{Command: "agents", Description: "List tasks currently being worked", Usage: "/agents"},
|
|
{Command: "rollback", Description: "Restore a filesystem checkpoint", Usage: "/rollback [number]"},
|
|
{Command: "stop", Description: "Terminate a background process", Usage: "/stop <process-name>"},
|
|
{Command: "restart", Description: "Reload Archie and its configuration", Usage: "/restart"},
|
|
{Command: "help", Description: "See what Archie can do", Usage: "/help"},
|
|
}
|
|
|
|
var gatewayCommands = func() []models.BotCommand {
|
|
commands := make([]models.BotCommand, 0, len(gatewayCommandSpecs))
|
|
for _, spec := range gatewayCommandSpecs {
|
|
commands = append(commands, models.BotCommand{
|
|
Command: spec.Command,
|
|
Description: spec.Description,
|
|
})
|
|
}
|
|
return commands
|
|
}()
|
|
|
|
func gatewayHelpText() string {
|
|
var help strings.Builder
|
|
help.WriteString("🤖 **Archie**\n\n")
|
|
help.WriteString("Send a message to chat with Archie. Replies stream into Telegram as they are generated.\n\n")
|
|
help.WriteString("**Commands**\n")
|
|
for _, spec := range gatewayCommandSpecs {
|
|
fmt.Fprintf(&help, "`%s`\n%s\n\n", spec.Usage, spec.Description)
|
|
}
|
|
return strings.TrimSpace(help.String())
|
|
}
|
|
|
|
// commandScopes are the scopes the menu is published to.
|
|
//
|
|
// Telegram resolves a chat's menu by scope specificity, not recency: a
|
|
// list set on all_private_chats wins over the default scope in every DM.
|
|
// Publishing only to the default scope therefore leaves the bot showing
|
|
// whatever a previous owner of the token registered against the narrower
|
|
// scopes -- state that lives on Telegram's side and survives redeploys,
|
|
// rewrites and migrations. Writing every scope we care about overwrites
|
|
// those leftovers instead of being shadowed by them.
|
|
var commandScopes = []models.BotCommandScope{
|
|
&models.BotCommandScopeDefault{},
|
|
&models.BotCommandScopeAllPrivateChats{},
|
|
&models.BotCommandScopeAllGroupChats{},
|
|
}
|
|
|
|
// registerCommands publishes the command menu to every scope. A failure
|
|
// here costs discoverability, not function -- every command still works
|
|
// when typed -- so it is logged rather than treated as fatal, and one
|
|
// failing scope does not stop the others.
|
|
func (g *Gateway) registerCommands(ctx context.Context, b *bot.Bot) {
|
|
for _, scope := range commandScopes {
|
|
if _, err := b.SetMyCommands(ctx, &bot.SetMyCommandsParams{
|
|
Commands: gatewayCommands,
|
|
Scope: scope,
|
|
}); err != nil {
|
|
g.log.Warn("set command menu failed", "scope", fmt.Sprintf("%T", scope), "error", err)
|
|
continue
|
|
}
|
|
}
|
|
g.log.Info("command menu registered",
|
|
"commands", len(gatewayCommands), "scopes", len(commandScopes))
|
|
}
|