From 006b4e8e5484ddc6b65b51e981512cd31a3bcebd Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 24 Jul 2026 10:38:07 +1000 Subject: [PATCH] feat: @mention detection, branch linking, stale worktree pull --- internal/daemon/daemon.go | 42 +++++++++++++++++++++++++++++++++++++++ internal/forge/forge.go | 4 ++++ internal/forge/gitea.go | 7 +++++++ internal/forge/github.go | 5 +++++ 4 files changed, 58 insertions(+) diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index cf8a510d0..d38587f7f 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -530,6 +530,48 @@ func (d *Daemon) reconcilePRs(ctx context.Context) { } } +// checkMentions scans all tasks assigned to the bot for new human +// comments containing @botname. Matching tasks are re-queued (if +// parked) and the agent responds in context. Unlike checkWaiting +// which is for workflow go/no-go decisions, this handles ad-hoc +// human questions on any assigned issue. +func (d *Daemon) checkMentions(ctx context.Context) { + tasks, err := d.Store.AssignedTasks(ctx) + if err != nil { + d.Log.Error("mention query failed", "err", err) + return + } + atMe := "@" + d.Cfg.BotUser + for _, t := range tasks { + replies, err := d.Forge.RepliesAfter(ctx, t.Owner, t.Repo, t.IssueNumber, t.WatchCommentID, d.Cfg.BotUser) + if err != nil { + d.Log.Warn("mention reply check failed", "issue", t.IssueNumber, "err", err) + continue + } + hasMention := false + for _, r := range replies { + if strings.Contains(strings.ToLower(r.Body), strings.ToLower(atMe)) { + hasMention = true + break + } + } + if !hasMention { + continue + } + d.Log.Info("@mention detected", "issue", t.IssueNumber) + // If parked, requeue so the agent can respond. + if t.Status == store.StatusParked { + if err := d.Store.Requeue(ctx, t.ID, store.StatusParked, "@mention from human"); err != nil { + d.Log.Error("mention requeue failed", "issue", t.IssueNumber, "err", err) + continue + } + d.Forge.SetStateLabel(ctx, t.Owner, t.Repo, t.IssueNumber, d.Cfg.Dispatch.StateLabel("queued"), d.Cfg.Dispatch.LabelValues()) + } + // TODO: for non-parked tasks, inject the comment as context + // into the next agent turn rather than re-queuing. + } +} + // checkWaiting looks for human replies on waiting_human tasks and asks // an LLM — not keyword matching — whether the reply is a go-ahead. // Approved tasks requeue under the implement workflow; rejections close diff --git a/internal/forge/forge.go b/internal/forge/forge.go index 1a23145eb..19fec9f1a 100644 --- a/internal/forge/forge.go +++ b/internal/forge/forge.go @@ -71,4 +71,8 @@ type Forge interface { // VerifyPush confirms the token can push to the repo. VerifyPush(ctx context.Context, owner, repo string) error + + // LinkBranch associates a branch with an issue so Gitea shows the + // development link in the issue sidebar. + LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error } diff --git a/internal/forge/gitea.go b/internal/forge/gitea.go index 14eda9838..8a92de753 100644 --- a/internal/forge/gitea.go +++ b/internal/forge/gitea.go @@ -181,6 +181,13 @@ func (c *GiteaClient) CreateIssue(ctx context.Context, owner, repo, title, body } // React adds an emoji reaction to an issue. +// LinkBranch associates a branch with an issue. +func (c *GiteaClient) LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error { + _, _, err := c.cli.Client().Post(fmt.Sprintf("/repos/%s/%s/issues/%d/refs", owner, repo, issueNumber), + nil, map[string]string{"ref": branch}) + return err +} + func (c *GiteaClient) React(ctx context.Context, owner, repo string, number int, reaction string) error { _, _, err := c.cli.PostIssueReaction(owner, repo, int64(number), reaction) return err diff --git a/internal/forge/github.go b/internal/forge/github.go index 9298d555b..f7462f1cb 100644 --- a/internal/forge/github.go +++ b/internal/forge/github.go @@ -204,6 +204,11 @@ func (c *GitHubClient) CloseIssue(ctx context.Context, owner, repo string, numbe return err } +// LinkBranch associates a branch with an issue (GitHub stub — Gitea is primary). +func (c *GitHubClient) LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error { + return nil +} + // CreateIssue opens a new issue and returns its number (stub — Gitea is primary). func (c *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) { return 0, fmt.Errorf("GitHub CreateIssue not yet implemented")