| 1 | {{/* The results region, rendered two ways from one definition. |
| 2 | |
| 3 | index.html includes it, so a scriptless form submit gets it inside |
| 4 | the page; GET /search executes it alone, so search.js can swap it in |
| 5 | on every keystroke. One definition because the two must agree about |
| 6 | which result is primed — if they disagreed, where Enter goes would |
| 7 | depend on whether the script had loaded yet. */}} |
| 8 | {{/* One sentence, two places that must not disagree: the callout the |
| 9 | server renders when store.Search fails, and the attribute search.js |
| 10 | reads when its own fetch fails. Both mean "the search did not run", |
| 11 | and a page with two wordings for that would be two pages. */}} |
| 12 | {{define "searchFailed"}}The search did not run. Nothing was found because nothing was searched.{{end}} |
| 13 | |
| 14 | {{/* Team mode, standing Unknown (Paul, 2026-10-28): a list page is partial |
| 15 | with this notice, never a 503 — and in Memoria, which has no shares, |
| 16 | the partial list is empty, so this is what stops it reading as |
| 17 | "nothing matched". Rendered only then, and nothing at all otherwise. */}} |
| 18 | {{define "partial"}}<div rst-callout rst-tone="warning"> |
| 19 | <div rst-callout-body><strong>{{.PartialNotice.Title}}</strong><p>{{.PartialNotice.Body}}</p></div> |
| 20 | </div>{{end}} |
| 21 | |
| 22 | {{define "results"}}{{$L := localizer $}} |
| 23 | {{if .SearchFailed}} |
| 24 | <div rst-callout rst-tone="negative"> |
| 25 | <div rst-callout-body><p>{{template "searchFailed"}}</p></div> |
| 26 | </div> |
| 27 | {{else if .Partial}}{{if .Searched}} |
| 28 | {{template "partial" .}}{{end}} |
| 29 | {{else if .Searched}} |
| 30 | {{/* A typing request skipped §8.9's model step (nothing was sent); |
| 31 | search.js sees this and asks again, in full, once typing pauses. */}} |
| 32 | {{if .FactsDeferred}}<span rst-facts-deferred hidden></span>{{end}} |
| 33 | {{/* The count heading only when there is something to count. A zero |
| 34 | is said once, below, as one quiet line (spec §4): "0 results for |
| 35 | “rev”" over a callout was what live search showed on every partial |
| 36 | keystroke. */}} |
| 37 | {{if .Results}}<h2>{{len .Results}} result{{if ne (len .Results) 1}}s{{end}} for “{{.Query}}”</h2>{{end}} |
| 38 | {{/* §6.5's loud withholding, above the results rather than below them. |
| 39 | |
| 40 | A reader who scrolls past the last result has already decided what |
| 41 | the page means; the notice has to arrive before the list it is |
| 42 | about. What each line says is decided in Go (sibling.Outcome), so |
| 43 | one wording lives in one place — and every line names an app and |
| 44 | never a document, because naming the document would report the |
| 45 | existence of a passage this person may not have. */}} |
| 46 | {{if .Notices}} |
| 47 | <div rst-callout rst-tone="warning" rst-withheld> |
| 48 | <div rst-callout-body>{{range .Notices}}<p>{{.}}</p>{{end}}</div> |
| 49 | </div> |
| 50 | {{end}} |
| 51 | {{/* §8.8's fact box. BELOW the notices and above the list, both |
| 52 | deliberately: a confident single answer rendered above the line |
| 53 | saying the page is partial is the withholding notice's own |
| 54 | argument with the order reversed. |
| 55 | |
| 56 | Inside this define rather than above it, so search.js swaps box |
| 57 | and list together. A box outside it would leave query N-1's answer |
| 58 | sitting over query N's results on every keystroke. |
| 59 | |
| 60 | Every character here is the document's — the label it wrote, the |
| 61 | span byte for byte, its own title and heading trail. The link is |
| 62 | the ONLY link, and it must never wear rst-result-title: search.js |
| 63 | reads that attribute to decide where Enter goes, and §8.8 rules |
| 64 | that Enter still goes to the first result and not to a box. */}} |
| 65 | {{if .Facts}} |
| 66 | {{/* §8.10's answer card. One row is the answer in large type; a |
| 67 | guess is marked as one; "Is this wrong?" opens the correction |
| 68 | page for this query, for the deterministic kinds (a model row |
| 69 | has none, §8.10). */}} |
| 70 | {{$correctable := false}}{{range .Facts}}{{if not .Model}}{{$correctable = true}}{{end}}{{end}} |
| 71 | <div rst-fact-box{{if eq (len .Facts) 1}} rst-fact-one{{end}}> |
| 72 | {{range .Facts}} |
| 73 | {{/* A row a model pointed at is marked, and names its model — §8.9: |
| 74 | it does not inherit the deterministic layer's guarantees (the |
| 75 | model can omit, and "this is an address" is its judgement), so |
| 76 | the reader must be able to tell the two kinds of claim apart |
| 77 | at a glance. Decision 4: every answer names its provider. */}} |
| 78 | <p rst-fact{{if .Model}} rst-fact-model{{end}}{{if .Guess}} rst-fact-guess{{end}}> |
| 79 | {{if .Guess}}<span rst-fact-chip>Best guess</span>{{end}} |
| 80 | <span rst-fact-label>{{.Label}}</span> |
| 81 | {{/* Short structured values never break; an address or an email |
| 82 | can be long, and must wrap rather than widen the page. */}} |
| 83 | <span rst-fact-value{{if or (eq .Kind "phone") (eq .Kind "eircode") (eq .Kind "vat")}} rst-nowrap{{end}}>{{.Span}}</span> |
| 84 | {{if .Model}}<span rst-fact-by title="Found by a model, not validated">🤖 {{.Provider}} · {{.Model}}</span>{{end}} |
| 85 | <a href="/documents/{{.DocumentID}}#p{{.Ordinal}}" rst-fact-cite>{{.Title}}{{if .Trail}} › {{.Trail}}{{end}}</a> |
| 86 | </p> |
| 87 | {{/* §8.8's narrowing line, under the row it describes: the box |
| 88 | chose this row on the reader's own words, and how many it left |
| 89 | out. It keeps the others visible, which is the one thing |
| 90 | standing between a planted label and a single confident |
| 91 | answer. */}} |
| 92 | {{with .Note}}<p rst-fact-note>{{.Text}}</p>{{end}} |
| 93 | {{with .Guess}}<p rst-fact-note>{{.Text}}</p>{{end}} |
| 94 | {{end}} |
| 95 | {{if $correctable}}<p rst-fact-report><a href="/facts/correct?q={{$.Query}}">Is this wrong?</a></p>{{end}} |
| 96 | </div> |
| 97 | {{end}} |
| 98 | {{/* §8.8's account of itself, only for ?explain=facts and never linked. |
| 99 | Every value and label here is from a passage in this page's own |
| 100 | results, so it shows nothing the reader cannot already open. */}} |
| 101 | {{if .Explained}} |
| 102 | <details rst-fact-explain open> |
| 103 | <summary>Why the box looks like this</summary> |
| 104 | {{range .Explained}} |
| 105 | <p><strong>{{.Kind}}</strong>: {{.Outcome}}{{if .Qualifiers}} Narrowing words:{{range .Qualifiers}} “{{.}}”{{end}}.{{end}}</p> |
| 106 | {{if .Candidates}} |
| 107 | <div rst-scroll-x> |
| 108 | <table rst-table rst-explain-table> |
| 109 | <thead><tr><th>Value</th><th>Label</th><th>Document's own label</th><th>Too long</th><th>Matches</th><th>From</th></tr></thead> |
| 110 | <tbody> |
| 111 | {{range .Candidates}} |
| 112 | <tr> |
| 113 | <td>{{.Span}}</td> |
| 114 | <td>{{.Label}}</td> |
| 115 | <td>{{if .Own}}yes{{else}}no (fallback){{end}}</td> |
| 116 | <td>{{if .OverLong}}yes{{else}}no{{end}}</td> |
| 117 | <td>{{if .Matches}}yes{{else}}no{{end}}</td> |
| 118 | <td rst-muted>{{.Title}}{{if .Trail}} › {{.Trail}}{{end}}</td> |
| 119 | </tr> |
| 120 | {{end}} |
| 121 | </tbody> |
| 122 | </table> |
| 123 | </div> |
| 124 | {{end}} |
| 125 | {{end}} |
| 126 | </details> |
| 127 | {{end}} |
| 128 | {{/* §8.11's slot: when nothing checked answers, an AI answer may. |
| 129 | search.js fills it once typing settles; without a script the link |
| 130 | asks for it inline. The page never waits on the model. */}} |
| 131 | {{if .AnswerSlot}} |
| 132 | <div rst-answer{{if not .Answer}} rst-answer-pending{{end}}> |
| 133 | {{with .Answer}}{{template "answer" (withL (.) $L)}}{{else}}<noscript><p><a href="/?q={{$.Query}}&ai=1">🤖 Ask the AI about this</a></p></noscript>{{end}} |
| 134 | </div> |
| 135 | {{end}} |
| 136 | {{if not .Results}} |
| 137 | {{/* Not a callout: one muted line (spec §4). Three sentences, and |
| 138 | which one is true depends on why the page is empty. The first — |
| 139 | "no matches" — is only true when nothing was withheld and the |
| 140 | count could be read: a page emptied by withholding is not an |
| 141 | absence, and a count that failed is not a zero (AGENTS.md). Same |
| 142 | rule as ever; plainer words. |
| 143 | |
| 144 | rst-search-empty spaces it below the results region. */}} |
| 145 | <p rst-muted rst-search-empty> |
| 146 | {{if .Notices}} |
| 147 | Nothing that could be shown matched “{{.Query}}”. Some passages were |
| 148 | withheld (see above), so there may be more than this. |
| 149 | {{else if lt .Chunks 0}} |
| 150 | No matches for “{{.Query}}” — but the passage count could not be |
| 151 | read, so the index may be empty. |
| 152 | {{else}} |
| 153 | No matches for “{{.Query}}”. |
| 154 | {{end}} |
| 155 | </p> |
| 156 | {{end}} |
| 157 | <ol rst-results> |
| 158 | {{range $i, $r := .Results}} |
| 159 | <li rst-result{{if and $.Primed (eq $i 0)}} rst-result-primed{{end}}> |
| 160 | {{/* Ancestry above the title, heading trail below it. Both, and in |
| 161 | that order, because they answer different questions: the path |
| 162 | says which part of the workspace this came from, the heading |
| 163 | says where in the page. A result showing only the second is |
| 164 | two indistinguishable "Week one"s under different handbooks. */}} |
| 165 | {{if $r.Path}}<span rst-result-path>{{$r.Path}}</span>{{end}} |
| 166 | <a href="/documents/{{$r.DocumentID}}#p{{$r.Ordinal}}" rst-result-title>{{$r.Title}}</a> |
| 167 | {{if $r.Heading}}<span rst-result-trail>{{$r.Heading}}</span>{{end}} |
| 168 | <p rst-result-snippet>{{$r.Snippet | safeSnippet}}</p> |
| 169 | <p rst-result-meta rst-muted>{{$r.Source | sourceName}}</p> |
| 170 | </li> |
| 171 | {{end}} |
| 172 | </ol> |
| 173 | {{end}} |
| 174 | {{end}} |
| 175 | |
| 176 | {{/* §8.11's AI answer: what /answer returns, and what ?ai=1 renders |
| 177 | inline. Plain escaped text, never markup (§8.5), each sentence with |
| 178 | its citations; every state that is not an answer said in words, so |
| 179 | none reads as AI being off (§8.4). */}} |
| 180 | {{/* One block: its text (escaped; balanced **bold** the only markup, |
| 181 | ai.go's boldOnly) and its citations. */}} |
| 182 | {{define "answer-block"}}{{.HTML}}{{range .Cites}} <a href="{{.Href}}" title="{{.Title}}" rst-ai-cite>[{{.N}}]</a>{{end}}{{end}} |
| 183 | |
| 184 | {{define "answer"}}{{$L := localizer $}} |
| 185 | {{if .Notices}} |
| 186 | <div rst-callout rst-tone="warning" rst-withheld> |
| 187 | <div rst-callout-body>{{range .Notices}}<p>{{.}}</p>{{end}}</div> |
| 188 | </div> |
| 189 | {{end}} |
| 190 | {{if eq .State "answered"}} |
| 191 | <div rst-ai-answer> |
| 192 | {{/* Paul, 2026-10-27: "AI", not the provider or model, on the page. |
| 193 | They stay named here, in the title, and in the footer. */}} |
| 194 | <p rst-ai-by title="{{.Provider}} · {{.Model}}">🤖 AI answer</p> |
| 195 | {{range .Groups}}{{if .List}}<ul rst-ai-list>{{range .Blocks}}<li>{{template "answer-block" (withL (.) $L)}}</li>{{end}}</ul> |
| 196 | {{else}}{{range .Blocks}}<p rst-ai-text>{{template "answer-block" (withL (.) $L)}}</p>{{end}} |
| 197 | {{end}}{{end}} |
| 198 | {{/* 👍/👎, recorded for review (Paul, 2026-10-27). The handle holds |
| 199 | what was shown, as coordinates; nothing here is the answer. */}} |
| 200 | <form method="post" action="/answer/feedback" rst-ai-feedback> |
| 201 | <input type="hidden" name="handle" value="{{.Feedback}}"> |
| 202 | <span rst-muted>Was this right?</span> |
| 203 | <button rst-btn="quiet compact" type="submit" name="verdict" value="up" aria-label="Yes, it was right">👍</button> |
| 204 | <button rst-btn="quiet compact" type="submit" name="verdict" value="down" aria-label="No, it was wrong">👎</button> |
| 205 | </form> |
| 206 | </div> |
| 207 | {{else if eq .State "none"}}<p rst-muted rst-ai-state>🤖 No AI answer in these results.</p> |
| 208 | {{else if eq .State "dropped"}}<p rst-muted rst-ai-state>🤖 The AI's answer cited nothing in these results, so it is not shown.</p> |
| 209 | {{else if eq .State "computation"}}<p rst-muted rst-ai-state>🤖 Memoria doesn't ask the AI to calculate totals or averages.</p> |
| 210 | {{else if eq .State "withheld"}}<p rst-muted rst-ai-state>🤖 No AI answer: none of these results can be shown to you.</p> |
| 211 | {{else if eq .State "late"}}<p rst-muted rst-ai-state>🤖 The AI didn't answer in time.</p> |
| 212 | {{else}}<p rst-muted rst-ai-state>🤖 The AI answer failed.</p> |
| 213 | {{end}} |
| 214 | {{end}} |
| 215 | |
| 216 | {{/* The typeahead (/suggest): the box's one checked answer if there is |
| 217 | exactly one, then up to six documents. Each row is a link; search.js |
| 218 | moves a highlight over them with the arrows, and Enter follows the |
| 219 | highlighted one or, with none, submits the search. Every character |
| 220 | is the document's own, escaped. */}} |
| 221 | {{define "suggest"}} |
| 222 | <ul rst-suggest-list role="listbox" aria-label="Suggestions"> |
| 223 | {{with .Fact}} |
| 224 | {{/* The answer row, with Copy beside it (Paul, 2026-10-31). The button |
| 225 | sits outside the link — a control inside a link is two controls in |
| 226 | one — and is hidden until search.js wires it, because without a |
| 227 | script it would do nothing. ⌘C/Ctrl+C copies the same value while |
| 228 | the list is open and nothing in the box is selected. */}} |
| 229 | <li role="option" rst-suggest-fact-row><a href="/documents/{{.DocumentID}}#p{{.Ordinal}}" rst-suggest-item rst-suggest-fact> |
| 230 | <span rst-suggest-fact-label>{{.Label}}</span> |
| 231 | <strong{{if or (eq .Kind "phone") (eq .Kind "eircode") (eq .Kind "vat")}} rst-nowrap{{end}}>{{.Span}}</strong> |
| 232 | <span rst-muted>{{.Title}}</span> |
| 233 | </a><button type="button" rst-suggest-copy rst-copy-value="{{.Span}}" hidden>Copy</button></li> |
| 234 | {{end}} |
| 235 | {{range .Suggestions}} |
| 236 | <li role="option"><a href="{{.Href}}" rst-suggest-item> |
| 237 | <span rst-suggest-title>{{.Title}}</span>{{if and .Trail (ne .Trail .Title)}} <span rst-muted>› {{.Trail}}</span>{{end}} |
| 238 | </a></li> |
| 239 | {{end}} |
| 240 | {{/* An app that did not answer, said in the list (gate 3c): not an |
| 241 | option, so the arrow keys pass over it. */}} |
| 242 | {{range .Notices}}<li role="presentation" rst-suggest-notice>{{.}}</li>{{end}} |
| 243 | <li role="option"><a href="/?q={{.Query}}" rst-suggest-item rst-suggest-all>Search for “{{.Query}}” <span rst-muted>Enter</span></a></li> |
| 244 | </ul> |
| 245 | {{end}} |
| 246 | |