oficina / memoria Public

Fact labels: an invisible gap between label and value is not text

Paul's live office-phone search still showed no box, and ?explain=facts
showed why: every Office number fell back to the heading, even the one
the page labels "The office phone number is:". The likely cause, a
hypothesis from the screenshot: invisible marks between the colon and
the number. macOS wraps copied phone numbers in bidi marks, and editors
leave zero-width spaces or a BOM.

The gap between separator and value is now spaces (Zs) plus a named set
of invisible marks. Tabs stay separators, line and paragraph separators
stay boundaries, and a label keeps its own characters.

Reviewed by GPT-6 Astra. The first version was too broad: it lost tab
separators, borrowed labels across line separators, and stripped a
label's bidi controls. Astra approved the fix, d9ba565. Tests cover
eight kinds of gap and every regression the review found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from fix/fact-label-invisible-chars into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 7c3858669901c22e5073c9b9b4daa637e0c61e0d parent 16c35c1
4 files changed, +123 −1
  • docs/superpowers/specs/2026-09-03-memoria-design.md +14 −0
  • internal/memoria/fact/fact.go +31 −1
  • internal/memoria/fact/fact_test.go +69 −0
  • internal/memoria/narrow_test.go +9 −0

CI passed — run details

diff --git a/docs/superpowers/specs/2026-09-03-memoria-design.md b/docs/superpowers/specs/2026-09-03-memoria-design.md
index 14a2799..626f13e 100644
--- a/docs/superpowers/specs/2026-09-03-memoria-design.md
+++ b/docs/superpowers/specs/2026-09-03-memoria-design.md
@@ -3320,6 +3320,20 @@ span's position in the chunk text:
2. **If what remains ends in a separator** — `:`, `—`, `–`, `-`, `=`, tab
— **and is non-empty after removing it and trimming, and is 60
characters or fewer, that is the label.**
+ **The gap between the separator and the value is not text
+ (2026-10-26).** Spaces (Unicode Zs) are gaps, and so are the invisible
+ marks that wrap a value: zero-width space, word joiner, BOM, the
+ directional marks, and bidi embeddings, overrides and isolates. A tab
+ is not a gap, because it is a separator. A line or paragraph separator
+ is not a gap either; it is a boundary. Only that trailing gap is
+ trimmed: bidi controls inside a label are the document's and stay.
+ **The cause on Paul's live page is a hypothesis.** His
+ `?explain=facts` screenshot showed every Office number falling back to
+ the heading while the snippet showed `is:` beside the number. These are
+ the characters macOS and common editors put there. A first version
+ trimmed every Unicode space and format character, and review found
+ that it lost tab separators, borrowed labels across line separators,
+ and stripped a label's own bidi controls.
3. **Empty after the separator → fall through.** A markdown bullet is the
case: the chunker keeps lines verbatim, so `- +353 1 547 7854` gives a
run of `-`, which "ends in a separator" and yields nothing. Two such
diff --git a/internal/memoria/fact/fact.go b/internal/memoria/fact/fact.go
index 3f4f82b..effef6e 100644
--- a/internal/memoria/fact/fact.go
+++ b/internal/memoria/fact/fact.go
@@ -783,6 +783,29 @@ func isAbbreviation(tok string) bool {
return size > 0 && len(tok) == size+1 && tok[size] == '.' && unicode.IsLetter(r)
}
+// isGap is a space (Zs) or one of the invisible marks that can sit
+// between a label's separator and its value: zero-width space, word
+// joiner, BOM, the directional marks (LRM, RLM, ALM), and the bidi
+// embeddings, overrides and isolates that wrap a copied number.
+//
+// A hypothesis about Paul's live page, not an observation: his
+// ?explain=facts screenshot showed every Office number falling back to
+// the heading while the snippet showed "is:" beside the number. These
+// are the characters macOS and common editors insert there.
+func isGap(r rune) bool {
+ if unicode.Is(unicode.Zs, r) {
+ return true
+ }
+ switch {
+ case r == '\u200b', r == '\u2060', r == '\ufeff',
+ r == '\u200e', r == '\u200f', r == '\u061c',
+ r >= '\u202a' && r <= '\u202e',
+ r >= '\u2066' && r <= '\u2069':
+ return true
+ }
+ return false
+}
+
// listMarker is one leading list marker: a bullet, a number, a to-do box
// after either, or a quote. memoria's own Notion renderer writes these
// (notion/markdown.go), and rule 1 anchors the run at the start of the
@@ -809,7 +832,14 @@ func labelOf(text string, start int, spans [][2]int, heading, title string) (str
if e := lastSpanEndBefore(spans, start); e > b {
b = e
}
- run := strings.TrimRight(text[b:start], "  ")
+ // The gap between the separator and the value is not text: spaces
+ // (Unicode Zs, so never a tab, which is a separator, and never a line
+ // or paragraph separator, which is a boundary), and the invisible
+ // marks that belong to the value rather than the label — the bidi
+ // marks macOS wraps a copied phone number in, zero-width spaces, a
+ // stray BOM. Only this trailing gap: the label's own characters,
+ // bidi controls included, are the document's and stay (2026-10-26).
+ run := strings.TrimRightFunc(text[b:start], isGap)
// A leading list marker is markup. The pattern needs a space after
// the marker and run is already trimmed on the right, so whatever it
// matches has something after it: a bare bullet — "- +353 1 547
diff --git a/internal/memoria/fact/fact_test.go b/internal/memoria/fact/fact_test.go
index a24a637..b3d221b 100644
--- a/internal/memoria/fact/fact_test.go
+++ b/internal/memoria/fact/fact_test.go
@@ -779,3 +779,72 @@ func TestListMarkersAreNotPartOfTheLabel(t *testing.T) {
}
}
}
+
+// Invisible characters between a label and its value are not text.
+//
+// Paul's live Office page, 2026-10-26: every number fell back to the
+// heading, including the one the page labels "The office phone number
+// is:". ?explain=facts showed it ("no (fallback)") while the search
+// snippet showed the label and the number side by side. Numbers copied
+// from Contacts or Messages on a Mac arrive wrapped in bidi marks
+// (U+202D … U+202C), and other editors leave zero-width spaces, thin
+// spaces or a BOM. The run then ended in one of those, not in the colon,
+// and rule 2 never saw its separator.
+//
+// Seen red before the fix, every case: label = "Office Address" own =
+// false — the live symptom exactly.
+func TestInvisibleCharactersDoNotHideTheLabel(t *testing.T) {
+ for name, gap := range map[string]string{
+ "LRO and PDF (macOS Contacts)": "\u202d",
+ "LRM": "\u200e",
+ "zero-width space": "\u200b",
+ "zero-width no-break (BOM)": "\ufeff",
+ "narrow no-break space": "\u202f",
+ "thin space": "\u2009",
+ "ideographic space": "\u3000",
+ "several at once": " \u202d\u200b",
+ } {
+ text := "- The office phone number is:" + gap + "+353 (0)1 547 7854\u202c\n"
+ got := Scan(text, "Office Address", "Office", []Kind{Phone})
+ if len(got) != 1 {
+ t.Fatalf("%s: Scan found %d, want 1", name, len(got))
+ }
+ if got[0].Label != "The office phone number is" || !got[0].Own {
+ t.Errorf("%s: label = %q own = %v, want the document's own label", name, got[0].Label, got[0].Own)
+ }
+ }
+}
+
+// The gap rule must not eat what is not a gap. GPT-6 Astra's review
+// (2026-10-26) found each of these regressed by a first version that
+// trimmed every Unicode space and every format character:
+// - a tab is a separator (rule 2), not whitespace to discard;
+// - a line or paragraph separator (U+2028, U+2029) is a boundary, and
+// a label must not be borrowed across it;
+// - bidi controls INSIDE a label are the document's, and removing them
+// changes how the label reads;
+// - an over-long label followed by marks still silences the kind.
+func TestTheGapRuleKeepsWhatIsNotAGap(t *testing.T) {
+ long := strings.Repeat("x", MaxLabel+1)
+ for _, c := range []struct {
+ name, text, label string
+ own, noBox bool
+ }{
+ {"tab separator", "Office\t+353 (0)1 547 7854", "Office", true, false},
+ {"over-long then tab", long + "\t+353 (0)1 547 7854", long, true, true},
+ {"line separator is a boundary", "Office:
+353 (0)1 547 7854", "Contact", false, false},
+ {"paragraph separator is a boundary", "Office:
+353 (0)1 547 7854", "Contact", false, false},
+ {"bidi inside the label stays", "‮eciffO‬: +353 (0)1 547 7854", "‮eciffO‬", true, false},
+ {"over-long then marks", long + ":‭+353 (0)1 547 7854‬", long, true, true},
+ } {
+ got := Scan(c.text, "Contact", "Tito", []Kind{Phone})
+ if len(got) != 1 {
+ t.Fatalf("%s: Scan found %d, want 1", c.name, len(got))
+ }
+ f := got[0]
+ if f.Label != c.label || f.Own != c.own || f.NoBox != c.noBox {
+ t.Errorf("%s: label = %q own = %v noBox = %v, want %q own = %v noBox = %v",
+ c.name, f.Label, f.Own, f.NoBox, c.label, c.own, c.noBox)
+ }
+ }
+}
diff --git a/internal/memoria/narrow_test.go b/internal/memoria/narrow_test.go
index 25bb309..2e7274e 100644
--- a/internal/memoria/narrow_test.go
+++ b/internal/memoria/narrow_test.go
@@ -157,6 +157,15 @@ func TestGate40NarrowingPicksExactlyOneOverTheCap(t *testing.T) {
none(t, searchFacts(t, s, "phone number"))
})
+ // Paul's live page, 2026-10-26: the same shape with the numbers
+ // wrapped in macOS's bidi marks. Every label fell back to the heading
+ // until invisible characters stopped counting as text.
+ t.Run("numbers wrapped in invisible marks", func(t *testing.T) {
+ marked := strings.NewReplacer("+353", "\u202d+353", "\n", "\u202c\n").Replace(officePage)
+ s := factCorpus(t, visible(), [][3]string{{"o", "Office", marked}})
+ one(t, searchFacts(t, s, "what is the office phone number?"), "+353 (0)1 547 7854", phone(3, "office"))
+ })
+
t.Run("under the cap nothing changes", func(t *testing.T) {
s := page(t, "## Office\n\nOffice phone: +353 (0)1 547 0001\n\nReception: +353 (0)1 547 0002\n\nSales: +353 (0)1 547 0003")
p := searchFacts(t, s, "office phone")