Skip to content

fix(memory): preserve literal links in published Wiki files - #422

Open
Afloat16 wants to merge 2 commits into
simplexai-labs:mainfrom
Afloat16:afloat/wiki-published-link-literals
Open

Afloat16 wants to merge 2 commits into
simplexai-labs:mainfrom
Afloat16:afloat/wiki-published-link-literals

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Rewrite readable Wiki destinations only for actual inline Markdown links. Preserve inline, fenced, indented and quoted code, escaped link syntax and literal unavailable-meeting references. Real links still move to readable paths, including links with code inside their labels.

The shared Markdown helper accounts for the parser's leading-BOM offset and supplies the parsed URL and label boundary. Publishing can separate a nested-code label from a title containing ]( without guessing the label boundary with a greedy expression. Surrounding source spelling, the BOM and title text are preserved.

How it was verified

Comparison base: 77abdcb37f779f9c9d2de89fa245efa88d3f6584. Linux, Node 26.5.0 and pnpm 11.7.0. Current head: 6adc5c1618223231490cc88f3f2f8c746518c2eb.

  • The original six literal-preservation regressions fail on the comparison base, with two existing controls passing. The nested-code-label case remains covered.
  • For review 6052661333, the leading-BOM helper regression failed on 9e2aebab (1 failed / 7 passed). Two real publishing regressions for a BOM and title punctuation also failed (2 failed / 9 passed across the two related files).
  • After the fix, pnpm --filter @linger/document-files check passes typecheck, lint and 39 tests across 3 files, including normal, empty and code-containing label boundaries.
  • The complete published-link-literals and personal-layout files pass 11/11 tests.
  • The repository's changed-file check passes Prettier, ESLint and English-only checks; git diff --check passes.

Complete owning-app gate

pnpm --filter @linger/node-services check exits 0 on the published tree 196c39db795295e713cc3affb702154aa887ebea: feature-catalog verification, typecheck and lint pass; 269 files passed, 8 skipped; 2,720 tests passed, 51 skipped. The normal suite configuration and a task-local temporary directory were used. Dependencies were installed with the frozen lockfile in an isolated worktree. No timeout or skip settings changed.

Hosted run 45566451875 also passes all selected checks, including the package and web consumer jobs.

  • Focused tests for the changed behavior
  • All affected package and app fast checks
  • No contracts changed

Boundary

The owning READMEs describe the behavior. The existing Markdown parser is reused; no dependency or network call is added. The tree is not serialized, so unrelated Markdown remains byte-for-byte intact. Reference definitions are not newly rewritten. Live-service/E2E results are not claimed.

@Afloat16
Afloat16 marked this pull request as ready for review November 25, 2026 06:02

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with nits (2 P3)

Scope: base main, merge base 77abdcb3, 1 commit, 5 files reviewed at 9e2aebab. Loaded ponytail-review; coderbook and karpathy-guidelines were not loaded (their criteria were applied from the review skill's checklist). Ran in a separate session.

Findings

P3

  1. Pages that start with a BOM no longer get their links rewritten (packages/document-files/src/index.ts:88-94)
    micromark drops a leading U+FEFF and does not count it in position.offset, so every slice is off by one character. I ran the helper on "# T\n\n[a](t.md) x": the callback got "\n[a](t.md", not "[a](t.md)". In memoryWikiFiles the anchored regex then fails to match, so every internal link on that page is published unchanged and points at the old path. The old global regex handled this case. The output is never corrupted, because the slice goes back unchanged. Fix: strip a leading BOM before parsing and add it back to the result, or add the BOM length to the offsets.

  2. A link title that contains ]( is no longer rewritten (apps/node-services/src/memory/published-memory-files.ts:89)
    ^(\[[\s\S]*\]\() is greedy, which the nested-code-label case needs, but it means [a](t.md "x ](y") matches the ]( inside the title. The href is parsed as y", the lookup fails, and the link stays unchanged. The old regex ([^\]\n]* label plus a title group) rewrote it. This is rare. A sturdier fix is to have rewriteMarkdownLinkSources pass the parsed node (node.url and the label's end offset from children.at(-1).position) so the caller doesn't parse the destination out of the source again.

Verified as fine

  • Traversal order: markdownNodes (packages/document-files/src/index.ts:70-77) is a pre-order DFS using a reversed-push stack, so link nodes arrive in document order and the offset cursor only moves forward. Links can't nest, so the start < offset guard never fires on valid input.
  • Offsets are JS string indices for CRLF, tabs in lists and blockquotes, and astral emoji. I ran the helper on "# T\r\n\r\n- \t[a](t.md) b\r\n", "> \t[a](t.md) 😀 [b](u.md)\n", "😀😀 [a](t.md)\n" and "- a\n\t- [b](t.md)\n", and each slice was exactly the link source.
  • Escaped bracket \[x](y), indented code, fenced code, quoted fences and inline code yield no link node, so their text is kept. A double backslash \\[a](t.md) is still treated as a real link, which is correct.
  • GFM autolink literals and email autolinks are link nodes, but their source doesn't start with [, so the anchored regex returns them unchanged (published-memory-files.ts:89).
  • Reference-style links (linkReference) and definitions are still not rewritten. Neither the old regex nor the new code rewrites them, and the PR body says so.
  • Labels that span lines ([multi\nline](t.md)) are now rewritten. The old [^\]\n]* skipped them. This is an improvement, and continuation-line > prefixes are kept because they stay inside start.
  • The unavailable-session path (start.slice(1, -2)) still yields the label source, and the code-in-label case is covered by the new test.
  • @linger/document-files is already a node-services dependency (apps/node-services/package.json:35) and already depends on remark-parse and remark-gfm. No new dependency.
  • Publishing runs in the background #projectWiki reconcile (apps/node-services/src/memory/wiki-index.ts:328-347), not on the user message → provider_ready path. Parsing every page with remark costs nothing on the request path.
  • Both owning READMEs were updated. No contracts, env vars or CJK text added. No merge or fixup commits.

Process notes

None.

CI

Every reported check passed or was skipped (check (packages), repository-gate, web tests, web-static, check (teamhub-cli), check (web)). CI lists no node-services job, so I ran pnpm --filter @linger/node-services exec vitest run tests/memory/published-link-literals.test.ts tests/memory/personal-layout.test.ts --maxWorkers=1 locally: 2 files, 9 tests passed. I also ran a throwaway probe (since deleted) of rewriteMarkdownLinkSources on the edge cases above. Merge state is BLOCKED only because a review is still required.

Automated review by Claude Code


Automated review of 9e2aeba by Claude Code.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 P0, 0 P1, 0 P2, 0 P3)

Scope: follow-up on 9e2aeba, reviewing head 6adc5c1 against main (merge base 77abdcb). I reviewed 2 commits and 6 files. The coderbook, ponytail-review and karpathy-guidelines guidance was applied. The review ran in a separate session.

Previous findings

  • P3: leading BOM shifts the parsed link offsets. Resolved. packages/document-files/src/index.ts:88 adds bomOffset to both node offsets. labelEnd is computed relative to nodeStart, so the BOM cancels out there. Coverage: preserves a leading BOM while rewriting exact link source ranges in index.test.ts, and the a leading byte-order mark case in published-link-literals.test.ts.
  • P3: a title containing ]( stopped the link from being rewritten. Resolved. The callback now receives the parsed url and the label boundary (labelEnd, from the end offset of the last label child). The destination regex runs only on link.slice(labelEnd), so a ]( in the label or the title can no longer move the split. Coverage: the link-like punctuation inside a title case and the it.each(["a", "a ](b", ""]) boundary test.

Findings

None.

Verified as fine

  • Label boundary.
    • With an empty label ([](t.md)), there are no children, so labelEnd falls back to 1 and link.slice(1) starts with ]( (index.ts:103). The test covers this.
    • Nested brackets, escaped \], hard breaks and image children all end at or before the closing ], so start = link.slice(0, labelEnd + 2) is always [label]( once the destination regex has matched ^\](.
    • The unavailable-session path, start.slice(1, -2), still yields the raw label text (published-memory-files.ts:113).
  • Link node types.
    • Autolinks and GFM literal autolinks are also link nodes, but they do not start with [, so the !link.startsWith("[") guard (published-memory-files.ts:94) leaves them untouched.
    • Reference links are linkReference, which the node.type !== "link" filter skips.
  • Using node.url instead of the raw href.
    • mdast decodes escapes and character references, but not percent-encoding. Percent-encoded paths therefore resolve exactly as before, and &amp;-style references now resolve to the real file name.
    • For angle-bracket destinations, the URL comes back without the <>, which matches the old href.replace(/^<|>$/gu, "").
  • Patterns the regex still rejects. Parenthesized titles, titles containing ) and balanced parentheses in a destination still fail the destination regex. Those links are returned unchanged, the same as on the merge base, so nothing regresses.
  • Callback signature. The only caller of rewriteMarkdownLinkSources is published-memory-files.ts, so the new second argument breaks nothing.
  • Docs. Both READMEs are updated in the same PR (apps/node-services/src/memory/README.md, packages/document-files/README.md).
  • English-only. No CJK appears in the added lines or in either commit message.

Process notes

  • The branch is 338 commits behind main. main requires up-to-date branches, so it needs a rebase.
  • 6adc5c16 only patches 9e2aebab in response to review. Because main uses rebase merges, consider squashing it into 9e2aebab with git rebase -i --autosquash so a single coherent commit lands.

CI

At review time, changes passed and check (packages), check (teamhub-cli), repository-gate, web-static and the web test shards were still pending; the remaining checks were skipped by path filtering. I ran no tests locally: there are no node_modules in this worktree, and nothing I suspected needed a run to confirm.

Automated review by Claude Code


Automated review of 6adc5c1 by Claude Code.

@Afloat16

Copy link
Copy Markdown
Contributor Author

Both link-boundary findings from review 6052661333 are addressed in 6adc5c1618223231490cc88f3f2f8c746518c2eb.

The helper adds the leading-BOM offset when slicing the original source, and passes the parsed URL plus the relative label end to the publisher. The publisher now starts its destination/title match after that label boundary. This keeps code inside labels intact and prevents ]( inside a title from being mistaken for the destination opener.

The BOM helper regression and both publishing regressions failed on the previous head and now pass. The complete Document Files check passes 39 tests with types/lint; the two publishing/layout files pass 11 tests. The full Node Services check passes 2,720 tests across 269 files, with the existing 8 files / 51 tests skipped. Changed-file formatting, lint and English-only checks pass. The published tree matches the checked tree, and the selected hosted CI jobs also pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant