Skip to content

feat(ui): link prose paths with non-ASCII file names - #1798

Open
heunghingwan wants to merge 1 commit into
NeuralNomadsAI:devfrom
heunghingwan:feat/prose-cjk-bare-paths
Open

heunghingwan wants to merge 1 commit into
NeuralNomadsAI:devfrom
heunghingwan:feat/prose-cjk-bare-paths

Conversation

@heunghingwan

Copy link
Copy Markdown
Contributor

Follow-up to #1780, which narrowed bare-path linking to exact inline-code paths and kept the prose parser for a separate change. This is that change: prose (non-backtick) paths now recognize file names written in any script.

What links now

  • 已写入 docs/superpowers/specs/2026-11-26-算法工作台MVP-design.md 定稿 — the whole path links: a prose token contains every script's letters, marks and digits as file-name content.
  • 看看src/app.ts吧 (ASCII path glued into CJK prose) and 对比 src/app.ts和docs/x.md 一下 (a CJK connector between two paths) keep linking as before; 打开C:\repo\src\app.ts keeps its drive prefix and File:/fixture-root/README.md still splits at the colon like a scheme.
  • Both-edges tokens made of segments (脚本/启动, 项目/v2/启动) read as one path; a trimmed edge run that exposes trailing punctuation (看看README.md.吧) trims it.

Fail closed

  • A prose URL with a non-ASCII path (https://example.com/资料README.md) stays whole: a token rooted at a doubled separator is one URL that yields no readings, so its tail can no longer link a same-named local file (README.md at the root) — dev's suffix leak, covered by a regression test with that file present.
  • A reading whose literal, verified target and generated destination could disagree — a percent escape that decodes, a # fragment — stays plain, the same agreement the inline grammar enforces (docs/%E7%AE%97.md stays text even when docs/算.md exists).
  • Missing files, worktree escapes, space-bearing paths and fenced code stay as rendered. One preserved edge: a missing CJK-named file whose directory exists can still link its directory prefix (docs/ as a folder link) — dev's boundary grammar produces the identical docs/ candidate today, and the new whole-file link replaces it whenever the file exists.

Cost bounded

  • The 64 cap counts readings — the integral probe plus every boundary piece, one file lookup each — not tokens. A 200-path token glued by 和 reads at most 64 directories; a Chromium test pins the exact count.

Implementation

  • lib/markdown-bare-paths.ts re-adds the two-reading grammar (integral + boundary pieces) with the scheme-splitting drive lookbehind and the URL-root guard; inlineCodeCandidates is unchanged apart from its return type name.
  • components/markdown-bare-paths.ts converts the integral reading first (whole token or nothing; pieces never overlap a converted integral) and falls back to pieces; inline spans keep the verified-target href from feat(ui): link bare paths with non-ASCII file names and inside inline code #1780, prose pieces keep their literal href, which the new agreement gate holds to the verified target and the click's re-resolution.

Validation

  • Unit 42/42 (30 lib: grammar, URL guards, reading cap, agreement gate; 12 cache).
  • Browser 5/5, three consecutive runs (whole-file CJK link, segment probes, connector fallback, punctuation trim, prose URL/percent negatives, 200-path budget).
  • tsc --noEmit, root npm run test:help 31/31.
  • Help updated in all ten locales; TRANSCRIPT.md describes the grammar.

Prose (non-backtick) bare paths keep the ASCII-only tokenizer, so a
CJK or otherwise non-ASCII file name never linked: the token split at
the letters and the fragments stayed plain text. Inline code got
exact-path linking in NeuralNomadsAI#1780; reviewers asked for the prose grammar as
a separate change, which this is.

A prose token now contains every script's letters, marks and digits
as file-name content. A token carrying them offers its integral
reading first — the whole token as one path — and falls back to its
boundary readings: edge letter runs glued to word characters trim as
surrounding prose, edge runs whose inner neighbour is a separator are
the path's own segments (项目/v2/启动), and interior runs split the
token as connectors (src/app.ts和docs/x.md). The candidate cap counts
readings — the integral probe plus every boundary piece, one file
lookup each — instead of tokens, so a glued run of paths cannot
multiply directory reads past the 64-lookup bound. A mid-token
Windows drive prefix stays glued to preceding prose (打开C:\…) while a
single-letter-colon prefix still splits like a scheme (File:/x), and a
token rooted at a doubled separator is one URL that yields no readings
— fixing the suffix leak where a prose URL with a non-ASCII path
linked its same-named local tail (https://example.com/资料README.md
linking the root README.md).

A reading whose literal, verified target and generated destination
could disagree — a percent escape that decodes, a fragment — stays
plain, applying the same three-way agreement the inline grammar
enforces; prose anchors keep their literal href, which the gate holds
to the verified target and the click's re-resolution. The exact
inline-code grammar from NeuralNomadsAI#1780 is unchanged.

Unit tests pin the two-reading grammar, the URL guards, the
reading-budget cap and the agreement gate (30 lib tests). The Chromium
fixture covers the whole-file CJK link, both-edges segment probes, the
connector fallback, the exposed-punctuation trim, the prose URL and
percent negatives, and a 200-path glued token staying within 64
directory reads (5 browser tests, three consecutive green runs). Help
pages in all ten locales and TRANSCRIPT.md describe the behavior.

This branch has not been deployed

No deployments
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