Implements docs/prds/artifact-sender.md (Approved). archie-core now sends generated artifacts to the offloaded.dev collaborative editor, whose POST /api/artifacts route, bearer service token, PocketBase-backed versions and idempotency semantics are the receiving contract. - [artifacts] config section: base_url + token SecretRef with a token_env fallback naming WORKSPACE_INGEST_TOKEN. An empty base_url disables the sender entirely; a base_url with an unresolvable token disables it with a warning, because a missing credential disables a capability rather than stopping the daemon. - internal/infrastructure/artifactsync: one-method Publish seam in the Courier posture, full source per publish (versions of record are snapshots), 503 retried three times with backoff, 401/400 surfaced immediately with the field reason, deterministic request ids (artifact:pr-review:<owner>/<repo>#<n>). - ReviewReport gains a pure markdown renderer in internal/domain/workflow: summary, one subsection per finding with the failure scenario and disposition when present, verified properties as a checked-clean list. - The daemon's PR reviewer publishes after a completed review when the sender is configured, records the editor deep link on the result, and degrades a failed publish to a log line -- publishing never fails the producing work.
106 lines
4.0 KiB
Go
106 lines
4.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
)
|
|
|
|
// PRReviewResult is the structured outcome of an operator-triggered PR
|
|
// review, returned to the channel that requested it. It mirrors
|
|
// workflow.ReviewReport without importing the domain package: the gateway
|
|
// states what it needs and the daemon adapts between the two (the
|
|
// ChatTaskActor pattern). Status is "completed", "not_run", or "skipped";
|
|
// a zero-finding "completed" result is a review that ran and cleared, and
|
|
// is structurally distinct from "not_run".
|
|
type PRReviewResult struct {
|
|
Repo string `json:"repo"`
|
|
Number int `json:"number"`
|
|
Model string `json:"model,omitempty"`
|
|
Status string `json:"status"`
|
|
Summary string `json:"summary,omitempty"`
|
|
// Reason explains why a not_run/skipped review did not execute.
|
|
Reason string `json:"reason,omitempty"`
|
|
Findings []PRReviewFinding `json:"findings"`
|
|
// ArtifactURL is the editor deep link for the published review artifact,
|
|
// empty when artifact publishing is disabled or failed.
|
|
ArtifactURL string `json:"artifact_url,omitempty"`
|
|
}
|
|
|
|
// PRReviewFinding is one defect from an operator-triggered review.
|
|
type PRReviewFinding struct {
|
|
File string `json:"file"`
|
|
Line int `json:"line"`
|
|
Defect string `json:"defect"`
|
|
FailureScenario string `json:"failure_scenario,omitempty"`
|
|
Verdict string `json:"verdict"`
|
|
Level string `json:"level"`
|
|
Category string `json:"category,omitempty"`
|
|
Blocking bool `json:"blocking"`
|
|
}
|
|
|
|
// ChatPRReviewer is the surface review_pr needs. The gateway states what it
|
|
// needs and the daemon supplies an adapter over the forge, worktree manager
|
|
// and reviewer runtime, so this package keeps its independence from
|
|
// internal/forge, internal/worktree and internal/domain/workflow.
|
|
//
|
|
// identity follows the ChatTaskActor convention: nil denotes an
|
|
// authenticated dashboard operator who may review any configured
|
|
// repository; a non-nil identity is a chat identity scoped to its own
|
|
// configured repositories.
|
|
type ChatPRReviewer interface {
|
|
ReviewPR(ctx context.Context, identity *string, repo string, number int) (PRReviewResult, error)
|
|
}
|
|
|
|
// ReviewTools builds the review_pr chat tool. A nil reviewer omits the tool
|
|
// rather than registering one that always fails, so a daemon without
|
|
// operator review support advertises nothing.
|
|
func ReviewTools(reviewer ChatPRReviewer, identity string) []tools.ToolEntry {
|
|
if reviewer == nil {
|
|
return nil
|
|
}
|
|
return []tools.ToolEntry{reviewPRTool(reviewer, identity)}
|
|
}
|
|
|
|
func reviewPRTool(reviewer ChatPRReviewer, identity string) tools.ToolEntry {
|
|
return tools.ToolEntry{
|
|
Name: "review_pr",
|
|
Toolset: "tasks",
|
|
Description: "Run the adversarial reviewer against an existing pull request and return its structured findings. " +
|
|
"Use it when the user asks to review a PR, re-check one after a push, or see what the reviewer found. " +
|
|
"Only a confirmed error-level finding blocks; a clean result reports zero findings explicitly.",
|
|
Classification: tools.ClassMutating,
|
|
Schema: tools.JSONSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"repo": map[string]any{
|
|
"type": "string",
|
|
"description": "Repository of the PR as \"owner/name\". Must be a repository this identity is configured for.",
|
|
},
|
|
"pr_number": map[string]any{
|
|
"type": "integer",
|
|
"description": "Pull request number to review.",
|
|
},
|
|
},
|
|
"required": []any{"repo", "pr_number"},
|
|
},
|
|
Handler: func(ctx context.Context, input map[string]any) (any, error) {
|
|
repo := strings.TrimSpace(asString(input["repo"]))
|
|
if repo == "" {
|
|
return nil, fmt.Errorf("review_pr: repo is required")
|
|
}
|
|
number, ok := asInt64(input["pr_number"])
|
|
if !ok || number <= 0 {
|
|
return nil, fmt.Errorf("review_pr: pr_number must be a positive integer")
|
|
}
|
|
result, err := reviewer.ReviewPR(ctx, &identity, repo, int(number))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("review_pr: %w", err)
|
|
}
|
|
return result, nil
|
|
},
|
|
}
|
|
}
|