feat: @mention detection, branch linking, stale worktree pull

This commit is contained in:
sam committed 2026-07-24 10:38:07 +10:00
1 parent e4368f70af
commit 006b4e8e54
4 files changed
+58

No files matched your search

+42
View File
@@ -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
+4
View File
@@ -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
}
+7
View File
@@ -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
+5
View File
@@ -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")