From 10d2501cff51eccec723aaeeab664fdb6eecfe22 Mon Sep 17 00:00:00 2001 From: Markus Fritsche Date: Sat, 16 May 2026 21:11:22 +0000 Subject: [PATCH] repl: peel trailing punctuation from @path mentions (#7 follow-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Natural-language prose like "look at @README.md, then..." or "@foo.lua." at sentence end previously failed to expand because the trailing comma/period was included in the path. Now: if the raw token doesn't resolve, peel trailing chars from [.,;:?!)] one at a time until the path resolves or no more peels are possible. On success, the peeled chars are emitted verbatim AFTER the closing fence so the original punctuation is preserved. Surfaced during higgs smoke test (TC: "say the first line of @README.md, then stop" — the trailing comma broke resolution). Co-Authored-By: Claude Opus 4.7 (1M context) --- repl.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/repl.lua b/repl.lua index 0d28a4b..2da2740 100644 --- a/repl.lua +++ b/repl.lua @@ -54,7 +54,22 @@ local function expand_mentions(line, on_status) local at_start = (i == 1) or line:sub(i - 1, i - 1):match("%s") ~= nil if at_start and line:sub(i, i) == "@" then local path_end = line:find("%s", i + 1) or (#line + 1) - local path = line:sub(i + 1, path_end - 1) + local raw = line:sub(i + 1, path_end - 1) + -- Peel one or more trailing punctuation chars (,.;:?!) if the + -- full path doesn't resolve — handles natural prose like + -- "look at @README.md, then..." or "@foo.lua." at sentence end. + local path, trail = raw, "" + while #path > 0 do + local f = io.open(path, "rb") + if f then f:close(); break end + local last = path:sub(-1) + if last:match("[%.,;:?!)]") then + trail = last .. trail + path = path:sub(1, -2) + else + break + end + end if path ~= "" then local content, truncated = _read_truncated(path) if content then @@ -62,12 +77,12 @@ local function expand_mentions(line, on_status) on_status(("@%s expanded (%d bytes%s)"):format( path, #content, truncated and ", truncated" or "")) end - out[#out + 1] = ("```%s path=%s\n%s\n```"):format( - _lang_of(path), path, content) + out[#out + 1] = ("```%s path=%s\n%s\n```%s"):format( + _lang_of(path), path, content, trail) i = path_end else if on_status then - on_status(("@%s: not found"):format(path)) + on_status(("@%s: not found"):format(raw)) end out[#out + 1] = line:sub(i, path_end - 1) i = path_end