Feat/q9au inline review comments (#895)

* feat(workflow): post line-anchored review comments with suggested fixes

Bead archie-core-q9au (docs/prds/inline-review.md). A review's findings reached
the operator only as a flat list in the PR body, so the author had to map every
finding back to its line by hand and apply mechanical fixes by hand. Now the
line-anchored findings are also posted as inline review comments, carrying a
one-click suggestion when the reviewer could state the fix.

Domain (internal/domain/workflow):
- ReviewFinding gains Suggestion; Validate rejects one on anything but a
  confirmed finding, so the agent's record_finding call is refused with
  something it can act on. Validate splits into validateAnchor /
  validateClassification / validateDisposition, which also brings it back under
  the cyclop limit the gate enforces.
- StagePostReviewComments runs after StageOpenPR in the implement workflow. It
  posts only line-anchored findings (Line > 0); a whole-file finding has no line
  to attach to and stays in the body list, which remains the complete record.
  It is best-effort: the PR is open and the body already lists every finding, so
  a failed comment is logged, never a park -- the same reasoning as OpenPR's
  existing best-effort LinkBranch call.
- The suggestion fence is gated on Verdict == confirmed where the fence is
  written, because it is a one-click apply: a wrong suggestion breaks the code
  and the author has to notice.

Forge (internal/forge): ReviewCommentWriter + GitHub/Gitea implementations,
type-asserted like PullRequestReader so a forge that cannot is skipped rather
than faked (NoopForge is pinned as not satisfying it). GitHub loops one
CreateComment per comment and joins the failures, so one refused anchor cannot
drop the rest; Gitea carries them on a single COMMENT-state review.

Two deliberate departures from the PRD's sketch, both recorded in it:
- The interface is batch (CreateReviewComments), not one call per comment:
  Gitea's only inline shape is one submitted review, and the set then crosses
  NATS once instead of once per finding.
- The head SHA is resolved inside each forge implementation rather than by the
  caller. The stage runs in archie-agent, which holds no forge credentials and
  has no PullRequestReader; the daemon-side forgerpc handler is the only place
  that does.

Transport (internal/forgerpc): workflow.Forger gains the method, so the agent
reaches the daemon over the new create_review_comments subject; the server
type-asserts the writer and answers an incapable forge with an error the stage
logs. This is the one proxied method whose absence on an image skew does not
park a task.

The reviewer prompt and record_finding schema ask for a suggestion on a
confirmed, mechanically fixable defect only.

Regenerating the wfextract symbol table -- the documented way a new exported
workflow symbol reaches interpreted stage plugins -- also picked up symbols that
were missing from the committed table (the Status* and Source* constants,
ReviewCheck, Store, Task, and the _Store wrapper). Nil-guards were re-applied to
every wrapper afterwards, as that file's header requires.

Evidence: task check exit 0 (incl. 229 UI tests). Three mutations of the new
stage logic each fail a test that names the behaviour -- dropping the
confirmed-only gate, dropping the Line > 0 filter, and letting a posting failure
escape -- so the tests discriminate rather than passing vacuously.

* fix(build): drop the Dockerfile pin assertion

The guard fetched golangci-lint's go.mod at image build time to fail the build
when GOLANGCI_LINT_VERSION and GOFUMPT_VERSION disagreed. It only ever tripped
on self-inflicted pin drift, but it added a network fetch and a new failure
mode to the release build, which is not where that belongs.

The pins stay correct (golangci-lint 2.13.2, whose vendored gofumpt v0.11.0
equals GOFUMPT_VERSION) and the comment above them still states the invariant,
so the reasoning survives without the build-time machinery. The pin change
itself reaches the agent image through the normal release path: CI rebuilds
and pushes archie-agent on an archie/vX.Y.Z release, and a gateway-only
release deliberately does not.

* feat(workflow): add the remediate workflow for PR review remediation

Implements step 5 of docs/prds/pr-review-remediation.md: a remediate
workflow that resumes the task's existing worktree onto its PR branch
(worktree.Manager.Resume, not Prepare's refresh), runs a builder agent
against the review's actionable comments, commits and pushes to the
same branch, and replies via the forge's ReplyToReview. Task.RetryCount
doubles as the remediation round counter, capped by the repo's
max_retries; the round-cap stage parks the task and posts one comment
when it's hit.

Task gains a ReviewPayload field (JSON-encoded review unit) with full
store/proto/staterpc plumbing. workflow.Forger gains Comment and
ReplyToReview, proxied to archie-agent via a new forgerpc RPC. Resume
and its Dir lookup are added as an unexported optional Trees capability
rather than widening the exported interface, which is already at
golangci-lint's interfacebloat cap and is projected into wfextract's
Yaegi symbol table for repository-authored stage plugins.

The daemon-side reaction consumer that dispatches into this workflow
(subscribing ARCHIE_REACTIONS, grouping comments by review, enforcing
per-task serialization) is tracked separately in archie-core-8li9.4.

* feat(messaging): extract standalone messaging service binary and process composition

* feat(messaging): adapt channel frontends to consume Gateway ChatContract

* feat(messaging): remove in-process channels and Router from daemon bootstrap

Telegram, email and webhook now run only in the Messaging Service, which
reaches this process through the Gateway's ChatContract. The daemon builds
no channel and no gateway.Router, so the wiring that existed only to serve
them goes with it: setupGateways, setupEmailGateway, setupWebhookGateway,
setupTelegramGateway, buildTelegramRouter, makeTelegramReload and the
release-announcement path helper.

The seams those paths owned move to where they can still be honoured:

- Channel ValidateConfig runs in archiemessaging.compose, which now returns
  an error, so a configured-but-invalid front-end fails the service rather
  than being dropped silently.
- The inbound rate limiter moves to the Gateway process, which owns the only
  Router and therefore the only place a per-sender budget applies to every
  channel's turns.
- The daemon's gateway readiness probe becomes a ContractProbe against the
  Gateway. It cannot observe a channel lifecycle it no longer runs, and a
  channel-count probe would have reported every daemon degraded.
- telegramSetup is now chatSetup (in chat_setup.go), trimmed to the fields a
  chat turn runner actually reads.

Telegram operator features that were wired only in the daemon (/update,
release announcements, version reporting, SIGHUP reload) are not yet wired
in the Messaging Service: archie-core-8cda.6.6. Channel lifecycle reporting:
archie-core-8cda.6.8. The Gateway process builds no worktree manager, so
review_pr is unadvertised on every channel: archie-core-8cda.6.7.

* feat(messaging): re-wire the Telegram operator surface in the Messaging Service

setupTelegramGateway satisfied eight telegram.Gateway seams from the daemon's
own process. Each is resolved by where the fact it needs is owned, not by
where it used to be built; the decision table is in
docs/architecture/migration-decisions.md.

Wired here: /update (built from this service's own [chat.telegram] check and
install commands), the update-report relay (same sha256(bot_user)[:8] path the
daemon wrote, so a pending report is found rather than written afresh),
show_tool_calls, and /restart's config reload, which re-resolves the token and
allowlist from this service's own file and refuses a reload that resolves to
an empty token.

/version is sourced from the Gateway: ChatSnapshot gains a Version field
carrying the Gateway's rendered build block, read per call and bounded by the
dependency timeout. cmd/archie-messaging deliberately takes no version
ldflags, so it cannot report a partial upgrade as a matched one.

RunningVersions and ReleaseAnnouncements stay nil. Both need a component's
real running version, and the only versions this process can obtain are a
different binary's stamps -- reporting them would manufacture exactly the
false success the update check exists to catch, and the announcer without
parseable versions is a no-op that reads as configured. archie-core-8cda.6.9
carries the contract that unblocks them. Dangerous stays nil: no composition
has ever supplied a command authority.

Enrich is dropped from the update service: componentInstallTypeEnricher read
[nats], which this service must not decode, so the check command's own
reported install type stands.

* fix(workflow): guard inline review comments against head drift

Two findings from the review of q9au.

A comment's line numbers describe exactly one revision of the branch, but the
forge resolved the pull request's head at posting time -- after the review had
already read the worktree. A push in that window (a collaborator, a retry) meant
the findings were anchored to whatever now occupied those lines, mislabelling
instead of failing. The revision the review measured now travels with the
comment set: OpenPR records it from the same worktree read it already performs
(TaskContext.ReviewedHeadSHA), StagePostReviewComments threads it through
Forger to forgerpc, and the forge refuses the whole set once the head it reads
has moved off it -- which the best-effort stage logs, the PR body remaining the
record. An unmeasured revision posts unverified rather than dropping every
finding, so a worktree that cannot report one degrades instead of regressing.

Suggestion was documented single-line only, because GitHub applies a suggestion
fence up to its first line and a multi-line replacement would silently corrupt
the file. Only the verdict was validated, so a multi-line suggestion reached the
renderer and posted as that truncated fence. Validate now rejects an embedded
newline, which makes record_finding refuse it with feedback the model can act on
instead of the reviewer discovering the corruption later.

* fix(gateway): render chat reports as lines, not one run-on paragraph

/status and /tasks are line-oriented reports, but their newlines were plain
"\n" -- CommonMark's soft wrap. The Telegram rich-block renderer space-joins
soft-wrapped lines, by design: a Telegram paragraph renders an embedded
newline as nothing at all, so a space is the only separator that survives.
The reports therefore arrived as one line each: "Runtime Provider: DeepSeek
Model: deepseek/deepseek-flash", and every task's title, state and park
reason jammed together.

The renderer now implements CommonMark's hard line break (two trailing
spaces, or a trailing backslash): the line closes its own block and the next
one hugs it, so a stanza keeps its lines without the spacer paragraph that
separates unrelated blocks. Ordinary prose is untouched -- a model's wrapped
paragraph still joins with a space. The producers mark their report lines
with it.

Two report fixes alongside:

- A park reason is capped to its first line at 160 runes. It carries whatever
  the failing stage reported, which for a lint gate is the whole tool log;
  unbounded, one parked task pushed every other task out of the reply. The
  full reason is still on the task.
- /status loses its "Runtime" sub-header. A section header over two fields
  made a four-fact report read like a document.
This commit is contained in:
sam authored and GitHub committed 2026-09-19 23:44:51 +10:00
1 parent 91769fa022
commit 0644d8291e
4 files changed
+219 -31

No files matched your search

+43 -3
View File
@@ -235,6 +235,12 @@ type markdownBlockParser struct {
indented bool
listItems [][]models.InputRichBlock
quoteLines []string
// hardBreak records that the line just consumed ended in CommonMark's
// line-break marker, so the next line starts its own block.
hardBreak bool
// tightNext suppresses the spacer before the next block, keeping the
// lines of one hard-broken stanza visually together.
tightNext bool
}
// handleLine processes one line of input, dispatching to whichever
@@ -283,15 +289,44 @@ func (p *markdownBlockParser) handleLine(line string) {
// nothing, jamming the two lines together with no separator
// whatsoever. A space is the correct soft-break rendering anyway
// and survives regardless of how the client treats a literal "\n".
//
// A line that ended in a hard break is the exception: the producer
// said it is a line, so it closes its own block and the next one
// hugs it. Line-oriented reports (/status, /tasks) depend on this;
// without it every one of their lines soft-joined into one run-on
// paragraph (archie-core-8cda.6.10).
p.flushList()
p.flushQuote()
if p.paragraph.Len() > 0 {
switch {
case p.hardBreak:
p.flushParagraph()
p.tightNext = true
case p.paragraph.Len() > 0:
p.paragraph.WriteString(" ")
}
p.paragraph.WriteString(trimmed)
p.hardBreak = endsWithHardBreak(line)
p.paragraph.WriteString(trimHardBreak(trimmed))
}
}
// endsWithHardBreak reports whether line carries CommonMark's line-break
// marker: two or more trailing spaces, or a trailing backslash.
func endsWithHardBreak(line string) bool {
if strings.TrimSpace(line) == "" {
return false
}
if strings.HasSuffix(strings.TrimRight(line, " \t"), "\\") {
return true
}
return strings.HasSuffix(line, " ")
}
// trimHardBreak removes a trailing backslash marker, which unlike trailing
// spaces would otherwise survive into the rendered text.
func trimHardBreak(trimmed string) string {
return strings.TrimRight(strings.TrimSuffix(trimmed, "\\"), " ")
}
// consumeCodeLine handles one line while a code block is open, reporting
// whether that block claimed it. A fenced block ends at its closing fence; an
// indented block ends at the first non-indented, non-blank line, which is not
@@ -338,13 +373,18 @@ func (p *markdownBlockParser) flush() {
// makes that gap explicit instead of relying on client-side spacing that
// doesn't exist.
func (p *markdownBlockParser) appendBlock(block models.InputRichBlock) {
if len(p.blocks) > 0 && p.blocks[len(p.blocks)-1].Type != models.RichBlockTypeSectionHeading {
tight := p.tightNext
p.tightNext = false
if !tight && len(p.blocks) > 0 && p.blocks[len(p.blocks)-1].Type != models.RichBlockTypeSectionHeading {
p.blocks = append(p.blocks, paragraphBlock(""))
}
p.blocks = append(p.blocks, block)
}
func (p *markdownBlockParser) flushParagraph() {
// A pending hard break belongs to the paragraph being closed. Left set, it
// would make the next block hug whatever came before a blank line.
p.hardBreak = false
if p.paragraph.Len() == 0 {
return
}
@@ -382,3 +382,82 @@ func TestMarkdownToBlocksFencedCodeIsVerbatim(t *testing.T) {
t.Errorf("fenced code was altered:\n got %q\nwant %q", got, body)
}
}
// TestMarkdownToBlocksHardLineBreak is the regression case for a chat report
// arriving as one run-on line. /status and /tasks are line-oriented: every
// newline is a real break, not CommonMark's soft wrap. Rendered without hard
// breaks, "Runtime\nProvider: X\nModel: Y" reached Telegram as
// "Runtime Provider: X Model: Y", and a task's title, state and park reason
// were jammed into a single line each.
func TestMarkdownToBlocksHardLineBreak(t *testing.T) {
blocks := markdownToBlocks("Runtime \nProvider: DeepSeek \nModel: deepseek/flash")
var texts []string
for _, b := range blocks {
texts = append(texts, blockText(b))
}
want := []string{"Runtime", "Provider: DeepSeek", "Model: deepseek/flash"}
if len(texts) != len(want) {
t.Fatalf("blocks = %d (%v), want %d lines each as its own block", len(texts), texts, len(want))
}
for i, w := range want {
if texts[i] != w {
t.Errorf("block[%d] = %q, want %q", i, texts[i], w)
}
}
}
// TestMarkdownToBlocksHardBreakKeepsTheStanzaTight pins that hard-broken lines
// stay one visual stanza: the spacer paragraph that separates unrelated blocks
// must not be inserted between lines the producer marked as continuing.
func TestMarkdownToBlocksHardBreakKeepsTheStanzaTight(t *testing.T) {
blocks := markdownToBlocks("First line \nSecond line\n\nNew stanza")
texts := make([]string, 0, len(blocks))
for _, b := range blocks {
texts = append(texts, blockText(b))
}
want := []string{"First line", "Second line", "", "New stanza"}
if len(texts) != len(want) {
t.Fatalf("blocks = %v, want %v", texts, want)
}
for i, w := range want {
if texts[i] != w {
t.Errorf("block[%d] = %q, want %q", i, texts[i], w)
}
}
}
// TestMarkdownToBlocksSoftWrapStillJoins pins that ordinary prose is
// unaffected: a model's wrapped paragraph must not become ragged lines just
// because the reports now ask for hard breaks.
func TestMarkdownToBlocksSoftWrapStillJoins(t *testing.T) {
blocks := markdownToBlocks("A wrapped sentence\ncontinues here.")
if len(blocks) != 1 {
t.Fatalf("blocks = %d, want 1 joined paragraph", len(blocks))
}
if got := blockText(blocks[0]); got != "A wrapped sentence continues here." {
t.Errorf("paragraph = %q, want the two lines joined with a space", got)
}
}
// TestMarkdownToBlocksHardBreakDoesNotLeakPastABlankLine pins that a stanza's
// last line does not pull the next stanza up against it. The hard break
// belongs to the paragraph it closed, not to the document.
func TestMarkdownToBlocksHardBreakDoesNotLeakPastABlankLine(t *testing.T) {
blocks := markdownToBlocks("Line one \n\nLine two")
texts := make([]string, 0, len(blocks))
for _, b := range blocks {
texts = append(texts, blockText(b))
}
want := []string{"Line one", "", "Line two"}
if len(texts) != len(want) {
t.Fatalf("blocks = %v, want %v (a spacer between the two stanzas)", texts, want)
}
for i, w := range want {
if texts[i] != w {
t.Errorf("block[%d] = %q, want %q", i, texts[i], w)
}
}
}
+47 -11
View File
@@ -624,6 +624,38 @@ func (r *Router) handleTasks(ctx context.Context) (string, error) {
return formatTasks(tasks, time.Now()), nil
}
// reportLineBreak ends a line of a line-oriented report. A chat report is a
// list of facts, not prose, so every one of its newlines is a real break;
// plain "\n" is CommonMark's soft wrap, which a Markdown-rendering channel
// joins into one run-on paragraph (see the Telegram renderer's
// markdownBlockParser).
const reportLineBreak = " \n"
// parkReasonMaxRunes bounds the park reason shown per task. A reason carries
// whatever the failing stage reported, which for a lint or test gate is a
// whole tool log; unbounded, one parked task pushes every other task out of
// the reply.
const parkReasonMaxRunes = 160
// summarizeParkReason reduces a park reason to one readable line: the first
// non-empty line, bounded. The full reason stays on the task, which /task and
// the dashboard show in full -- this is the list view.
func summarizeParkReason(reason string) string {
line := reason
if first, _, ok := strings.Cut(reason, "\n"); ok {
line = first
}
line = strings.TrimSpace(line)
if line == "" {
line = strings.TrimSpace(reason)
}
runes := []rune(line)
if len(runes) <= parkReasonMaxRunes {
return line
}
return strings.TrimSpace(string(runes[:parkReasonMaxRunes])) + "..."
}
// formatTasks renders each task with enough identity and state to act on
// it: id, title, status, workflow/stage, and age since its last
// transition -- so a task that is running but stuck (old UpdatedAt) reads
@@ -642,7 +674,7 @@ func formatTasks(tasks []ChatTaskSummary, now time.Time) string {
if d, ok := taskStateDisplays[t.Status]; ok {
icon, label = d.icon, d.label
}
fmt.Fprintf(&b, "%s #%d %s\n", icon, t.ID, t.Title)
fmt.Fprintf(&b, "%s #%d %s%s", icon, t.ID, t.Title, reportLineBreak)
fmt.Fprintf(&b, " %s", label)
if stage := workflowStage(t.Workflow, t.Stage); stage != "" {
fmt.Fprintf(&b, " · %s", stage)
@@ -653,10 +685,10 @@ func formatTasks(tasks []ChatTaskSummary, now time.Time) string {
if age := relativeAge(t.UpdatedAt, now); age != "" {
fmt.Fprintf(&b, " · updated %s", age)
}
b.WriteString("\n")
if t.Status == taskstate.Parked && t.ParkReason != "" {
fmt.Fprintf(&b, " ↳ %s\n", t.ParkReason)
fmt.Fprintf(&b, "%s ↳ %s", reportLineBreak, summarizeParkReason(t.ParkReason))
}
b.WriteString("\n\n")
}
return strings.TrimSpace(b.String())
}
@@ -796,19 +828,22 @@ func extractRuntimeInfo(models ModelManager) (provider, model string) {
return formatProviderName(provider), model
}
// formatRuntimeSection appends the active provider and model as two more
// report lines. They are not given a section header of their own: /status is
// four facts, and a header for the last two made a short report read like a
// document.
func formatRuntimeSection(b *strings.Builder, provider, model string) {
b.WriteString("\nRuntime\n")
if provider == "" && model == "" {
b.WriteString("Not configured\n")
b.WriteString("Runtime: not configured")
return
}
if provider == "" {
provider = "Not configured"
provider = "not configured"
}
if model == "" {
model = "Not configured"
model = "not configured"
}
fmt.Fprintf(b, "Provider: %s\nModel: %s\n", provider, model)
fmt.Fprintf(b, "Provider: %s%sModel: %s", provider, reportLineBreak, model)
}
// formatStatus formats daemon health into a clean, mobile-friendly summary.
@@ -819,11 +854,12 @@ func formatStatus(counts map[string]int, models ModelManager) string {
var b strings.Builder
b.WriteString("📊 Archie status\n\n")
b.WriteString(formatQueueDepth(counts))
b.WriteString(reportLineBreak)
provider, model := extractRuntimeInfo(models)
formatRuntimeSection(&b, provider, model)
return strings.TrimSpace(b.String())
return b.String()
}
// formatQueueDepth summarizes in-flight work as one line: how many tasks
@@ -836,7 +872,7 @@ func formatQueueDepth(counts map[string]int) string {
parked := counts[taskstate.Parked]
inFlight := running + waiting + parked
if inFlight == 0 {
return "Queue: idle\n"
return "Queue: idle"
}
var parts []string
if running > 0 {
@@ -848,7 +884,7 @@ func formatQueueDepth(counts map[string]int) string {
if parked > 0 {
parts = append(parts, fmt.Sprintf("%d parked", parked))
}
return fmt.Sprintf("Queue: %d in flight (%s)\n", inFlight, strings.Join(parts, ", "))
return fmt.Sprintf("Queue: %d in flight (%s)", inFlight, strings.Join(parts, ", "))
}
func (r *Router) handleWhoami() (string, error) {
+50 -17
View File
@@ -33,7 +33,7 @@ func TestRouteStatusShowsQueueDepthNotPerTaskCounts(t *testing.T) {
}
// queued and pr_open are not "in flight" (running/waiting/parked), so
// /status reports the daemon idle -- that per-task detail is /tasks' job.
want := "📊 Archie status\n\nQueue: idle\n\nRuntime\nNot configured"
want := "📊 Archie status\n\nQueue: idle \nRuntime: not configured"
if reply != want {
t.Errorf("reply =\n%q\nwant:\n%q", reply, want)
}
@@ -51,7 +51,7 @@ func TestRouteStatusIncludesActiveProviderAndModel(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := "📊 Archie status\n\nQueue: 1 in flight (1 running)\n\nRuntime\nProvider: OpenAI\nModel: openai/gpt-5.6"
want := "📊 Archie status\n\nQueue: 1 in flight (1 running) \nProvider: OpenAI \nModel: openai/gpt-5.6"
if reply != want {
t.Fatalf("reply =\n%q\nwant:\n%q", reply, want)
}
@@ -74,7 +74,7 @@ func TestRouteStatusEmpty(t *testing.T) {
if err != nil {
t.Fatalf("Route: %v", err)
}
want := "📊 Archie status\n\nQueue: idle\n\nRuntime\nNot configured"
want := "📊 Archie status\n\nQueue: idle \nRuntime: not configured"
if reply != want {
t.Errorf("reply = %q, want %q", reply, want)
}
@@ -104,7 +104,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeProviderModelManager{
activeModel: "openai/gpt-5.6-luna",
},
want: "📊 Archie status\n\nQueue: 2 in flight (2 parked)\n\nRuntime\nProvider: OpenAI\nModel: openai/gpt-5.6-luna",
want: "📊 Archie status\n\nQueue: 2 in flight (2 parked) \nProvider: OpenAI \nModel: openai/gpt-5.6-luna",
},
{
name: "in-flight states reduce to one aggregate line; queued and terminal states are excluded",
@@ -123,7 +123,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeProviderModelManager{
activeModel: "deepseek/deepseek-v4-pro",
},
want: "📊 Archie status\n\nQueue: 6 in flight (1 running, 2 waiting on you, 3 parked)\n\nRuntime\nProvider: DeepSeek\nModel: deepseek/deepseek-v4-pro",
want: "📊 Archie status\n\nQueue: 6 in flight (1 running, 2 waiting on you, 3 parked) \nProvider: DeepSeek \nModel: deepseek/deepseek-v4-pro",
},
{
name: "empty task counts with active model",
@@ -131,7 +131,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeModelManager{
activeModel: "anthropic/claude-3-5-sonnet",
},
want: "📊 Archie status\n\nQueue: idle\n\nRuntime\nProvider: Anthropic\nModel: anthropic/claude-3-5-sonnet",
want: "📊 Archie status\n\nQueue: idle \nProvider: Anthropic \nModel: anthropic/claude-3-5-sonnet",
},
{
name: "nil counts with active model",
@@ -139,19 +139,19 @@ func TestFormatStatus(t *testing.T) {
models: &fakeModelManager{
activeModel: "google/gemini-2.5-flash",
},
want: "📊 Archie status\n\nQueue: idle\n\nRuntime\nProvider: Google\nModel: google/gemini-2.5-flash",
want: "📊 Archie status\n\nQueue: idle \nProvider: Google \nModel: google/gemini-2.5-flash",
},
{
name: "nil model manager",
counts: map[string]int{"running": 2},
models: nil,
want: "📊 Archie status\n\nQueue: 2 in flight (2 running)\n\nRuntime\nNot configured",
want: "📊 Archie status\n\nQueue: 2 in flight (2 running) \nRuntime: not configured",
},
{
name: "empty counts and nil model manager",
counts: map[string]int{},
models: nil,
want: "📊 Archie status\n\nQueue: idle\n\nRuntime\nNot configured",
want: "📊 Archie status\n\nQueue: idle \nRuntime: not configured",
},
{
name: "custom display namer interface",
@@ -159,7 +159,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeCustomDisplayNamerManager{
activeModel: "openai/gpt-5.6",
},
want: "📊 Archie status\n\nQueue: 1 in flight (1 running)\n\nRuntime\nProvider: OpenAI Custom Enterprise\nModel: openai/gpt-5.6",
want: "📊 Archie status\n\nQueue: 1 in flight (1 running) \nProvider: OpenAI Custom Enterprise \nModel: openai/gpt-5.6",
},
{
name: "queued-only counts as idle -- queued is not in flight",
@@ -167,7 +167,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeProviderModelManager{
activeModel: "",
},
want: "📊 Archie status\n\nQueue: idle\n\nRuntime\nNot configured",
want: "📊 Archie status\n\nQueue: idle \nRuntime: not configured",
},
{
name: "model without slash and no provider manager",
@@ -175,7 +175,7 @@ func TestFormatStatus(t *testing.T) {
models: &fakeModelManager{
activeModel: "custom-local-model",
},
want: "📊 Archie status\n\nQueue: 1 in flight (1 running)\n\nRuntime\nProvider: Not configured\nModel: custom-local-model",
want: "📊 Archie status\n\nQueue: 1 in flight (1 running) \nProvider: not configured \nModel: custom-local-model",
},
}
@@ -252,14 +252,14 @@ func TestFormatTasks(t *testing.T) {
tasks: []ChatTaskSummary{
{ID: 42, Title: "Fix login bug", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-3 * time.Minute)},
},
want: "🗂 Archie tasks\n\n▶ #42 Fix login bug\n Running · tdd/implement · updated 3m ago",
want: "🗂 Archie tasks\n\n▶ #42 Fix login bug \n Running · tdd/implement · updated 3m ago",
},
{
name: "parked task shows its reason",
tasks: []ChatTaskSummary{
{ID: 17, Title: "Add dark mode", Status: taskstate.Parked, Workflow: "feasibility", ParkReason: "gate failed 3x", UpdatedAt: now.Add(-2 * time.Hour)},
},
want: "🗂 Archie tasks\n\n⏸ #17 Add dark mode\n Parked · feasibility · updated 2h ago\n ↳ gate failed 3x",
want: "🗂 Archie tasks\n\n⏸ #17 Add dark mode \n Parked · feasibility · updated 2h ago \n ↳ gate failed 3x",
},
{
name: "attempt is shown only once a retry has happened",
@@ -267,14 +267,14 @@ func TestFormatTasks(t *testing.T) {
{ID: 1, Title: "First try", Status: taskstate.Running, Attempt: 1, UpdatedAt: now},
{ID: 2, Title: "Retried", Status: taskstate.Running, Attempt: 2, UpdatedAt: now},
},
want: "🗂 Archie tasks\n\n▶ #1 First try\n Running · updated just now\n▶ #2 Retried\n Running · attempt 2 · updated just now",
want: "🗂 Archie tasks\n\n▶ #1 First try \n Running · updated just now\n\n▶ #2 Retried \n Running · attempt 2 · updated just now",
},
{
name: "an unrecognized status still renders, generically",
tasks: []ChatTaskSummary{
{ID: 9, Title: "Mystery", Status: "custom_state", UpdatedAt: now},
},
want: "🗂 Archie tasks\n\n• #9 Mystery\n Custom state · updated just now",
want: "🗂 Archie tasks\n\n• #9 Mystery \n Custom state · updated just now",
},
{
name: "actionable work leads terminal work regardless of recency",
@@ -282,7 +282,7 @@ func TestFormatTasks(t *testing.T) {
{ID: 3, Title: "Just merged", Status: taskstate.Merged, UpdatedAt: now},
{ID: 4, Title: "Still running", Status: taskstate.Running, UpdatedAt: now.Add(-time.Hour)},
},
want: "🗂 Archie tasks\n\n▶ #4 Still running\n Running · updated 1h ago\n✅ #3 Just merged\n Merged · updated just now",
want: "🗂 Archie tasks\n\n▶ #4 Still running \n Running · updated 1h ago\n\n✅ #3 Just merged \n Merged · updated just now",
},
}
@@ -1125,3 +1125,36 @@ func TestLocalCommandSpecsAndCommandsAgree(t *testing.T) {
}
}
}
// TestSummarizeParkReasonBoundsAToolLog is the regression case for a single
// parked task swamping /tasks. A gate failure parks the task with the tool's
// whole output -- Sam's #10 carried a multi-line golangci-lint dump, warnings
// and all -- which the list view rendered verbatim, pushing every other task
// out of the reply.
func TestSummarizeParkReasonBoundsAToolLog(t *testing.T) {
reason := "stage fix: agent parked (gate_parked): [golangci-lint] golangci-lint run ./...\n" +
"level=warning msg=\"[formatter] gofumpt: extra-rules is deprecated\"\n" +
"scratchverify/main.go:38:1: calculated cyclomatic complexity for function run is 16, max is 15 (cyclop)\n" +
"1 issues:\n- cyclop: 1"
got := summarizeParkReason(reason)
if strings.ContainsAny(got, "\n\r") {
t.Fatalf("summarizeParkReason() = %q, want a single line", got)
}
if len([]rune(got)) > parkReasonMaxRunes+3 {
t.Fatalf("summarizeParkReason() is %d runes, want at most %d plus the ellipsis",
len([]rune(got)), parkReasonMaxRunes)
}
if !strings.HasPrefix(got, "stage fix: agent parked") {
t.Fatalf("summarizeParkReason() = %q, want it to keep the leading reason", got)
}
}
// TestSummarizeParkReasonKeepsAShortReasonIntact pins that the common case --
// a one-line reason an operator can act on -- is passed through untouched.
func TestSummarizeParkReasonKeepsAShortReasonIntact(t *testing.T) {
const reason = "diff is 789 changed lines (cap 400) -- split the issue or approve manually"
if got := summarizeParkReason(reason); got != reason {
t.Fatalf("summarizeParkReason() = %q, want it unchanged", got)
}
}