Repository navigation
make @file references in custom slash commands more robust - #2203
Conversation
|
Looks like there's a broken workflow file? https://github.com/sst/opencode/actions/runs/17176454619/workflow Also I'm seeing brokenness with |
|
feel free to dm |
|
hey sorry i was slow to look at this - looks good can you resolve the conflict? |
art-shen
left a comment
There was a problem hiding this comment.
I honestly believe that regexes are a dead end here, and Markdown should be properly parsed instead to fix the error once and for all.
For example, afaik this would fail again with the same initial problem on my example command from #2327, wouldn't it?
Seems like the new regex would help with the first occurrence but still fail for the second). Because by design, regexes aren't suitable to properly handle languages like Markdown or any other complex syntax.
Example snippet from my command (I'm symlinking the commands from Claude Code):
1. Run this to show a context to the user:
`gh pr list --state open --json number,title,headRefName,author,comments,reviews,additions,deletions,isDraft,updatedAt --jq '.[] | "\("#" + (.number | tostring) | .[0:4] + " " * (4 - length)) \(if .isDraft then "📝 " else "✨ " end)\(.title | .[0:80] + " " * (80 - (.[0:80] | length))) @\(.author.login | .[0:12] + " " * (12 - (.[0:12] | length))) \(.headRefName | .[0:30] + " " * (30 - (.[0:30] | length))) 💬\(.comments | length)/🧵\((.reviews | length | tostring) + " " * (2 - (.reviews | length | tostring | length))) +\((.additions | tostring) + " " * (4 - (.additions | tostring | length)))/-\((.deletions | tostring) + " " * (4 - (.deletions | tostring | length))) \(.updatedAt[0:10])"'`
Shows: `PR# ✨/📝 Title(80ch) @author branch(30ch) 💬comments/🧵reviews +adds/-dels date`From this specific case
- it was trying to interpret
@\(.author.loginas a file reference (would be probably solved with this PR) - but the same problem is for the
@authoron the next line in the middle the inline code.
|
@thdxr Resolved conflicts, made everything cleaner, and added test cases for paths beginning |
This will make it easier to test, and also allow adding more sophisticated extraction logic without bloating `session/index.ts`.
This is a @valid/path/to/a/file, and it should also match at the beginning of a
line:
@another-valid/path/to/a/file
but references to email addresses and other strings are not:
- Adds a "Co-authored-by:" footer which clarifies which AI agent
helped create this commit, using an appropriate `noreply@...`
email address.
However currently the fileRegex is `/@([^\s]+)/g` which is much too inclusive
and triggers false positives.
As a first approximation, we can use a negative look-behind assertion to filter
out any matches for which the `@` is immediately preceded by an alphanumeric
character, and then also impose some heuristics regarding use of backticks,
commands, periods, and whitespace.
This can be seen as functional at: https://regex101.com/r/F6KAgH/5
Fixes anomalyco#2198.
1702ed6 to
37448e3
Compare
…#2203) Co-authored-by: Adam Spiers <[email protected]> Co-authored-by: rekram1-node <[email protected]>
…#2203) Co-authored-by: Adam Spiers <[email protected]> Co-authored-by: rekram1-node <[email protected]>
…#2203) Co-authored-by: Adam Spiers <[email protected]> Co-authored-by: rekram1-node <[email protected]>
The regular expression which was extracting file paths prefixed by
@from custom command text was too simplistic and created bugs. This PR makes it correctly handle several cases. See https://regex101.com/r/F6KAgH/ for examples.Fixes #2198.