Skip to content

feat(coding-agent): recognize #<number> as a GitHub issue/PR reference#3224

Open
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:githubnumber
Open

feat(coding-agent): recognize #<number> as a GitHub issue/PR reference#3224
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:githubnumber

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Summary

Implements #3218: typing #<number> (e.g. #3164) in the prompt now offers GitHub issue/PR autocomplete candidates, resolving the referenced "bare # shows the hotkey menu" complaint's underlying ask.

Accepting a candidate rewrites the token to the corresponding internal URL (pr://3164 / issue://3164, + trailing space — matching the existing @/internal-URL convention). The existing tool-mediated pipeline then resolves it: the agent calls read(pr://3164)InternalUrlRoutergh, keyed off the session cwd's git remote. No new resolution code — this reuses the entire existing issue:///pr:// machinery.

How it works

New module packages/coding-agent/src/modes/github-ref-autocomplete.ts mirrors the internal-url-autocomplete.ts pattern and is wired into PromptActionAutocompleteProvider.getSuggestions / applyCompletion ahead of the prompt-action branch.

Design decision: additive (Approach A)

A 3-judge design panel scored three approaches; additive coexistence won (lowest regression risk, cleanest fit with the single-provider chain, fewest files touched). Full repurpose of # (removing the prompt-action menu entirely) was considered but is a behavior change deliberately left for a maintainer decision rather than bundled into this feature.

Deliberate follow-up (not done here — needs maintainer call)

If the user picks the wrong candidate (e.g. pr://3164 when 3164 is an issue), read(pr://3164) 404s today — the issue:///pr:// handlers are scheme-strict and do not cross-fallback. A self-healing fallback (pr→issue, issue→pr on 404) in issue-pr-protocol.ts was considered but declined here because it would change issue:///pr:// behavior for all existing users, not just #<number>, and silent type-switching can mask genuine errors. Flagging it as a separate decision.

Verification

  • bun --cwd=packages/coding-agent run check — typecheck passes.
  • biome check — clean on all changed files.
  • New + affected tests pass: github-ref-autocomplete.test.ts (6), prompt-action-autocomplete.test.ts, command-controller-hotkeys.test.ts.
  • Adversarial review: ship-ready, 0 blockers; the one minor finding (#0) was fixed (regex tightened to ^[1-9]\d*$).
  • Broader test/modes + test/internal-urls run: no new failures vs. baseline (the only failures are pre-existing Windows EBUSY temp-cleanup flakes in issue-pr-protocol.test.ts and a path-rendering assertion in omfg-controller.test.ts, confirmed identical on origin/main).

Closes #3218.

Typing #<number> (e.g. can1357#3164) in the prompt now offers PR and Issue autocomplete candidates; accepting one rewrites the token to the pr:///issue:// internal URL (+ trailing space, matching the @/internal-url convention). The existing read tool -> InternalUrlRouter -> gh pipeline resolves it from the cwd's git remote, so no new resolution code is needed.

Bare # and #<text> keep the existing prompt-action menu (additive, no regression). #<number> requires a positive integer, so #0 / leading zeros do not offer candidates.

Closes can1357#3218
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 22, 2026
@roboomp roboomp added cli CLI commands and arguments feat review:p1 triaged ux User experience improvements labels Jun 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7ec6d066d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +31 to +35
const hashIndex = textBeforeCursor.lastIndexOf("#");
if (hashIndex === -1) return null;
const token = textBeforeCursor.slice(hashIndex + 1);
if (!/^[1-9]\d*$/.test(token)) return null;
return `#${token}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require a boundary before numeric GitHub refs

When #<number> is embedded in another token, such as a standard cross-repo GitHub reference owner/repo#123 or text like C#12, this still returns #123; accepting the completion then splices pr://123 after the existing prefix (owner/repopr://123) and resolves against the current repo rather than the referenced repo. Treat this as a standalone token by checking the character before # (or explicitly support qualified refs) before offering the rewrite.

Useful? React with 👍 / 👎.

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P1: small, coherent coding-agent UX feature with changelog and focused tests; bun --cwd=packages/coding-agent run check and the new/hotkeys tests passed locally.
One should-fix: #<number> detection currently matches inside existing tokens/URLs, so accepting a candidate can corrupt owner/repo#N or URL-fragment text. Please tighten the token boundary or intentionally support that form.
Thanks for the focused implementation.

* `#0`, `#0123`, `#copy`, and `#3164abc` do not.
*/
export function getGithubRefPrefix(textBeforeCursor: string): string | null {
const hashIndex = textBeforeCursor.lastIndexOf("#");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should-fix: lastIndexOf("#") treats any suffix after the last hash as a GitHub ref, so owner/repo#3224, https://github.com/can1357/oh-my-pi#3224, or foo#3224 all get PR/Issue candidates and accepting one rewrites the buffer to e.g. owner/repopr://3224 . The PR describes a #<number> token; please require a token boundary (start/whitespace or the same boundary set as internal URLs) or explicitly support the owner/repo#N form instead of corrupting it.

… qualifier

Address review feedback on can1357#3224 (roboomp + Codex): #<number> now requires a token boundary before # (start/whitespace/quote/paren/</=), matching the internal-URL boundary set, so owner/repo#N, foo#N, C#12, and URL fragments no longer match and corrupt on accept. Also detect a pr/pull/issue qualifier word before the number (pr can1357#3164 / issue can1357#3164); when present, only that kind is offered and the qualifier is consumed on accept.
@oldschoola

Copy link
Copy Markdown
Contributor Author

Thanks @roboomp and @chatgpt-codex-connector — pushed d8f52e8 addressing the should-fix and folding in the qualifier disambiguation.

Boundary fix (the should-fix): #<number> now requires a token boundary before # (start / whitespace / " / ' / \`` / (/</=— the same setURL_TOKEN_REuses), soowner/repo#N, foo#N, C#12, and URL fragments (https://…/#3164, path/#3164) no longer match and can't corrupt on accept. owner/repo#N` cross-repo refs are intentionally left untouched rather than rewritten against the current repo.

Qualifier disambiguation (new): naming the type first — pr #3164 / pull #3164 / issue #3164 (case-insensitive) — offers only that kind, and the qualifier word is consumed on accept (pr #3164pr://3164 , no dangling pr). No qualifier → both candidates, as before.

The detection moved to a single anchored regex in getGithubRefContext (packages/coding-agent/src/modes/github-ref-autocomplete.ts). bun --cwd=packages/coding-agent run check passes; the test file now covers the boundary cases (owner/repo#N, foo#N, C#12, URL fragment) and the qualifier paths (incl. src/pr #3164 correctly not treating pr as a qualifier).

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8f52e8a9b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +162 to +163
if (getGithubRefContext(prefix)) {
return applyInternalUrlCompletion(lines, cursorLine, cursorCol, item, prefix);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the live GitHub ref before applying completion

When the autocomplete list is stale, this branch trusts the old prefix even though the editor refreshes suggestions with a 100ms debounce. If suggestions for #316 are still visible after the buffer has become #3164 and the user presses Tab, applyInternalUrlCompletion slices by the shorter prefix length and can produce #pr://316 or otherwise target the wrong issue/PR. Recompute or verify the current #<number> token at cursorCol before applying the GitHub-ref completion.

Useful? React with 👍 / 👎.

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

Labels

cli CLI commands and arguments feat review:p1 triaged ux User experience improvements vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recognize #<number> as a GitHub issue/PR reference (and rethink # showing the hotkey menu)

2 participants