Files
loki/scripts/test/fix-note.ts
CatoandClaude Opus 5.5 f30ae002a5 feat(loki): structured updates in chat and feedback — benefit to users and us, downsides, costs, behind-the-scenes changes (#1145)
* feat(loki): the chat posts real progress updates — the story, the picture, the walkthrough

The owner, 2026-10-11: chat should post "pictures, screenshots, videos,
walkthroughs … real updates. It's like the team of engineers updating the
manager". It posted one markdown block when a run closed — the agent's raw
summary and "Pull request: https://…" as text you could not tap — and
nothing at all when the fix went live.

- progress-update.ts: one structured update, sections in a fixed order —
  asked, what was wrong, what was done, why this way, also considered,
  what could come next, checked — from the PR's design note, falling back
  to the handoff. Stored as meta.update with a plain-text twin in content.
- ProgressUpdateCard: the card the thread renders for it — stage chip,
  labelled sections, the report's screenshot as the before picture, and
  Watch the fix / the page / what changed.
- Two moments post: a run closing at its PR (run-outcome-post.ts, now with
  the note, the report and its screenshot) and the fix going live or failing
  to deploy (post-shipped-update.ts, fired from the same ledger transition
  as the push/Telegram notice, so once).
- Fixes from the feedback inbox had no chat to report to; they now post
  into their project's updates thread (`updates:<project>`, migration
  0091 adds conversations.channel with a unique (user, channel) index).
  Autopilot and cron runs stay silent as before.
- Pictures travel as owner-only URLs (/api/feedback/[id]/screenshot/[n]),
  never inlined — a thread is read whole.
- Bare https URLs in any chat message are now links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqXhtjrmVb4vKE6oKSyHVg

* feat(feedback): decision cards say it in lines — asked, done, next, what Loki saw

The owner, 2026-10-11, on the /feedback cards: "a lot of things written in
big strings that is hard to read and understand … not very well
structured", with five buttons wrapping onto three rows.

- The headline is one short sentence. What Loki saw when it read the live
  page used to be spliced into it ("Live on /projects. The provided page
  text does not contain any terminal status surface …"); it is now
  Recommendation.evidence, its own quieter line.
- Under the headline, each fact on its own line in a label column: Asked,
  Done (the PR's design note, else the handoff), Next (the note's new
  line), Loki saw (clamped to three lines).
- Whose report and when moves up beside the kicker.
- One yes, two answers, and More: Share the walkthrough moves into the
  More row; the walkthrough button reads "Watch the fix" everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqXhtjrmVb4vKE6oKSyHVg

* feat(feedback): every change says how it helps users; changes nobody can see say exactly what changed and the proof

The owner, 2026-10-11: "if there is a suggestion that doesn't involve user
experience — something systems or backend related, something that you cannot
screenshot and show — it still should explain exactly what was done. And I
also want to know how this change benefits users. Because every change
should benefit users."

- The design note gains Shows (on the page / behind the scenes), Under the
  hood (exactly what changed, for someone who does not code) and Proof (the
  test, measurement or log). Helps now asks for the effect on the people
  using the product, and the instruction says every change owes it.
- Chat updates: "How it helps users" right after what was done, "Under the
  hood" and "Proof it works" sections, a Behind the scenes chip, and no
  Watch the fix for a page that did not change. Work with no stated benefit
  shows that as a visible gap, never a guess.
- Feedback cards: Helps on every card; behind the scenes, Done is what changed
  in the system and Proof is shown. The recommendation stops asking the owner
  to "look" at such a fix (and the inbox stops spending a model read on it).
- The walkthrough of a behind-the-scenes fix points at nothing and plans no
  steps: it tells under the hood, how it helps users, and the proof.
- Chat builds are followed to live by their own card (#1146), so the "it's
  live" post now goes only to fixes with no chat of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqXhtjrmVb4vKE6oKSyHVg

* feat(feedback): every change states its downsides, costs and benefit to us — and "none" is shown clearly

The owner, 2026-10-11: "potential downsides are important and how it
benefits us is important … in some cases, some costs … but if there are no
downsides and no costs, that should be shown, that should be very clearly
shown."

- The design note gains Benefits us, Downsides and Costs. The instruction
  says every change must state them and write `none` only after checking.
  "none", "no extra cost" and the like normalise to NOTE_NONE; a real
  downside that merely starts with "No…" is kept as written.
- Chat updates: How it benefits us, Downsides and Costs right after How it
  helps users. "None" renders as a green check, never a blank; an owed
  section nobody answered is named as "Not stated by the developer"
  (missing[] replaces the helps-only flag).
- Feedback cards: a For us line; no downsides and no extra cost collapse to
  one "✓ None — no downsides, no extra cost" row; gaps are listed under
  Not stated. The label column widens so the labels fit on one line.
- The owner's walkthrough tells How it benefits us and Downsides & costs,
  saying "none" out loud; the reporter's never includes either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqXhtjrmVb4vKE6oKSyHVg

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-11 15:41:18 -07:00

235 lines
9.1 KiB
TypeScript

// The design note a fix carries in its PR description (src/lib/feedback/fix-note.ts):
// the instruction the agent gets and the parser that reads it back must agree,
// and a PR without the section must read as "no note", never as a half note.
import assert from "node:assert/strict";
import {
fixNoteInstruction,
parseFixNote,
tidyFixNote,
FIX_NOTE_HEADING,
NOTE_NONE,
} from "../../src/lib/feedback/fix-note";
import { deriveShippingFromPr } from "../../src/lib/feedback/fix-shipping";
// ---- a well-formed note ----
{
const body = [
"Fixes the overlap.",
"",
"## Walkthrough",
"- Problem: The caption card had no stacking order, so the site's tab bar drew over it.",
"- Change: The caption now sits above everything and rises clear of a bottom tab bar.",
"- Why: The tour is something the owner started on purpose; it should win.",
"- Considered: Hide the site's tab bar during the tour — changes their page under them",
"- Considered: Move the caption to the top — covers the headline the tour points at",
"- Helps: Anyone watching a fix on a phone.",
"- Where: The caption at the bottom of the screen during a walkthrough.",
"- For the reporter: The walkthrough card no longer hides behind the menu bar.",
"",
"## Verification",
"- Problem: not part of the note",
].join("\n");
const note = parseFixNote(body);
assert.ok(note);
assert.match(note.problem ?? "", /no stacking order/);
assert.match(note.change ?? "", /rises clear/);
assert.equal(note.considered.length, 2);
assert.equal(note.considered[0].option, "Hide the site's tab bar during the tour");
assert.match(note.considered[0].whyNot ?? "", /changes their page/);
assert.match(note.plain ?? "", /no longer hides/);
assert.match(note.where ?? "", /bottom of the screen/);
}
// ---- tolerant of how agents actually write markdown ----
{
const note = parseFixNote(
[
"### walkthrough",
"**Problem**: wrapped over",
" two lines.",
"* Change: bold labels and star bullets",
].join("\r\n"),
);
assert.equal(note?.problem, "wrapped over two lines.");
assert.equal(note?.change, "bold labels and star bullets");
}
// ---- absent, empty or placeholder-only reads as no note ----
assert.equal(parseFixNote(null), null);
assert.equal(parseFixNote("Just a description."), null);
assert.equal(parseFixNote(`## ${FIX_NOTE_HEADING}\n- Problem: <what was actually wrong>`), null);
// ---- the instruction lists every label the parser reads ----
{
const instruction = fixNoteInstruction();
const filled = instruction
.split("\n")
.filter((l) => l.startsWith("- "))
.map((l) => l.replace(/<[^>]*>/, "filled in"))
.join("\n");
const note = parseFixNote(`## ${FIX_NOTE_HEADING}\n${filled}`);
assert.ok(note);
for (const k of ["problem", "change", "why", "helps", "next", "where", "plain"] as const)
assert.equal(note[k], "filled in", `instruction and parser agree on ${k}`);
assert.equal(note.considered[0]?.option, "filled in");
}
// ---- caps: at most three alternatives, fields bounded ----
{
const many = Array.from({ length: 6 }, (_, i) => `- Considered: option ${i} — no`).join("\n");
const note = parseFixNote(`## Walkthrough\n${many}\n- Why: ${"x".repeat(2000)}`);
assert.equal(note?.considered.length, 3);
assert.ok((note?.why ?? "").length <= 400);
}
// ---- the ledger keeps it ----
{
const fix = deriveShippingFromPr(
{
number: 7,
html_url: "https://github.com/o/r/pull/7",
title: "fix",
state: "open",
merged_at: null,
merge_commit_sha: null,
body: "## Walkthrough\n- Change: kept on the ledger",
},
null,
"2026-10-07T00:00:00Z",
);
assert.equal(fix.pr?.note?.change, "kept on the ledger");
}
// ---- what agents actually wrote (substrata#169, 2026-10-09) ----
// Three alternatives on ONE Considered line, and the PR footer after a blank
// line. The first parser merged the alternatives into one and read the footer
// into the reporter's sentence — which a stranger would have seen.
{
const body = [
"## Walkthrough",
"- Considered: Making everything 48px on desktop too — wastes space where a mouse pointer is precise. Invisible enlarged tap areas around the small numbers — measuring tools would still see a 16px box. Making links inside sentences 48px tall — it breaks the line of text.",
"- For the reporter: Thanks — every button you pointed at is now big enough to tap.",
"",
"🤖 Generated with [Claude Code](https://claude.com/claude-code)",
].join("\n");
const note = parseFixNote(body);
assert.equal(note?.considered.length, 3, "one alternative per dashed sentence");
assert.equal(note?.considered[1].option, "Invisible enlarged tap areas around the small numbers");
assert.equal(note?.considered[2].whyNot, "it breaks the line of text.");
assert.equal(note?.plain, "Thanks — every button you pointed at is now big enough to tap.");
// A reason that runs to a second sentence without a dash stays one alternative.
const two = parseFixNote(
"## Walkthrough\n- Considered: A modal — it blocks the page. People closed it unread.",
);
assert.equal(two?.considered.length, 1);
assert.equal(two?.considered[0].whyNot, "it blocks the page. People closed it unread.");
// Labelled lines after a blank line still count.
const spaced = parseFixNote("## Walkthrough\n- Problem: a\n\n- Change: b");
assert.equal(spaced?.change, "b");
}
// ---- notes saved by the first parser are repaired on the way out ----
{
const stored = {
problem: "p",
change: "c",
why: null,
considered: [
{
option: "Making everything 48px on desktop too",
whyNot:
"wastes space. Invisible tap areas — tools would still see 16px. Inline links 48px — breaks the text.",
},
],
helps: null,
where: null,
plain:
"Thanks — it is bigger now. 🤖 Generated with [Claude Code](https://claude.com/claude-code)",
};
const tidy = tidyFixNote(stored);
assert.equal(tidy.plain, "Thanks — it is bigger now.");
assert.equal(tidy.considered.length, 3);
assert.equal(tidy.considered[0].whyNot, "wastes space.");
assert.deepEqual(tidyFixNote(tidy), tidy, "idempotent");
}
// ---- "Next": what else could be done, or honestly nothing ----
{
const note = parseFixNote(
"## Walkthrough\n- Change: c\n- Next: Lazy-load the gallery — left out to keep this change small.",
);
assert.match(note?.next ?? "", /Lazy-load/);
assert.equal(parseFixNote("## Walkthrough\n- Change: c\n- Next: nothing")?.next, null);
// Notes saved before the field existed still read.
const { next: _drop, ...old } = note!;
void _drop;
assert.equal(tidyFixNote(old).next, null);
}
// ---- behind the scenes: what changed, and the proof (owner, 2026-10-11) ----
// "Something that you cannot screenshot and show … it still should explain
// exactly what was done. And how this change benefits users."
{
const note = parseFixNote(
[
"## Walkthrough",
"- Change: The nightly import retries a failed batch.",
"- Shows: behind the scenes",
"- Under the hood: When the supplier's server times out, the import now waits a minute and tries that batch again, up to three times, instead of skipping it.",
"- Helps: Shop prices no longer go stale for a day when the supplier hiccups.",
"- Proof: A test forces two timeouts and checks every row lands; last night's log shows 0 skipped batches.",
].join("\n"),
);
assert.equal(note?.shows, "behind");
assert.match(note?.detail ?? "", /tries that batch again/);
assert.match(note?.proof ?? "", /0 skipped batches/);
assert.match(note?.helps ?? "", /no longer go stale/);
assert.equal(parseFixNote("## Walkthrough\n- Change: c\n- Shows: on the page")?.shows, "page");
assert.equal(
parseFixNote("## Walkthrough\n- Change: c\n- Shows: no, backend only")?.shows,
"behind",
);
// Older notes have none of it and still read.
const { shows: _s, detail: _d, proof: _p, ...old } = note!;
void _s;
void _d;
void _p;
const tidy = tidyFixNote(old);
assert.equal(tidy.shows, null);
assert.equal(tidy.detail, null);
}
// ---- downsides, costs, benefit to us: "none" is a finding, said as "None" ----
{
const note = parseFixNote(
[
"## Walkthrough",
"- Change: c",
"- Benefits us: Fewer support emails.",
"- Downsides: none",
"- Costs: No extra cost.",
].join("\n"),
);
assert.equal(note?.us, "Fewer support emails.");
assert.equal(note?.downsides, NOTE_NONE);
assert.equal(note?.costs, NOTE_NONE);
const real = parseFixNote(
"## Walkthrough\n- Change: c\n- Downsides: No caching, so the page is 40ms slower.\n- Costs: about $2/month more in AI calls",
);
assert.match(real?.downsides ?? "", /40ms slower/, "a real downside starting with 'No' is kept");
assert.match(real?.costs ?? "", /\$2\/month/);
assert.match(fixNoteInstruction(), /state its downsides and costs/);
assert.match(fixNoteInstruction(), /how it benefits us/);
}
// ---- the instruction asks for the benefit on every change ----
assert.match(
fixNoteInstruction(),
/Every change must say how it helps the people who use the product/,
);
console.log("fix-note: ok");