Skip to content

feat(quiz): toggle the anchor panel + link the filename to GitHub - #30

Merged
jonasbrami merged 2 commits into
mainfrom
feat/anchor-toggle-link
May 29, 2026
Merged

feat(quiz): toggle the anchor panel + link the filename to GitHub#30
jonasbrami merged 2 commits into
mainfrom
feat/anchor-toggle-link

Conversation

@jonasbrami

Copy link
Copy Markdown
Owner

What

Two refinements to the inline code context, per feedback:

  1. The anchor is collapsible again — a closed-by-default disclosure that lazy-loads the hunk on first expand, instead of always-on. A multi-question quiz is no longer a wall of code. The clip-to-anchor + line highlighting from the inline-anchors PR is unchanged.
  2. The filename links to GitHub — the file name in the panel header now links to that file on the PR's head branch, deep-linked to the anchored line range (…/blob/<branch>/<path>#L<start>-L<end>, new tab). Clicking the link doesn't toggle the panel (stopPropagation).

Wiring

The PR's head branch (already known to the CLI as info.branch) is threaded through a new COGNIT_BRANCH env var → build_web_app(branch=...) → templated onto <body data-branch=...> (next to the existing pr-url). The browser derives the repo blob base from the PR url and builds the link. Falls back to plain text when there's no branch (tests/demos).

Testing

  • Unit: COGNIT_BRANCH present in the launch env (test_launch); branch templated into the page and placeholder substituted (test_web). Full mcp/engine suite green; ruff + ruff format --check + mypy --strict clean.
  • Real browser (Chrome DevTools): panel is a <details> closed by default; expanding lazy-loads the highlighted hunk; the filename is an <a> to …/blob/<branch>/<path>#L42-L46 with target=_blank; following it doesn't toggle the panel.

🤖 Generated with Claude Code

jonasbrami and others added 2 commits May 29, 2026 19:50
Two refinements to the inline code context:

- The anchored hunk is collapsible again (a closed-by-default disclosure that
  lazy-loads on first expand) rather than always-on, so a multi-question quiz
  isn't a wall of code. The clip-to-anchor + line highlighting is unchanged.
- The filename in the panel header is now a link to that file on the PR's head
  branch in GitHub, deep-linked to the anchored line range
  (`…/blob/<branch>/<path>#L<start>-L<end>`, opens in a new tab). Clicking the
  link doesn't toggle the panel.

Wiring: the PR head branch is threaded from the CLI through `COGNIT_BRANCH` into
the web app and templated onto `<body data-branch=...>` (alongside the existing
pr-url) so the browser can build blob URLs. Falls back to plain text when no
branch is available (tests/demos).

Tested: `COGNIT_BRANCH` in the launch env; branch templated into the page;
mcp/engine suite green; ruff + mypy clean. Verified in a real browser: panel
collapsed by default, expands + lazy-loads the highlighted hunk, and the filename
links to the correct branch + line range on GitHub.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Guards against a 404: the anchor filename now upgrades to a GitHub blob link only
after confirming the path is one of the PR's changed files (the list the coverage
map already fetches). A hallucinated or non-diff anchor path stays plain text
instead of linking to a file that doesn't exist on the branch.

Verified in a browser: an in-diff anchor renders as a link to the file on the
branch; an anchor whose path isn't in the diff stays plain text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jonasbrami
jonasbrami merged commit b2066c9 into main May 29, 2026
2 checks passed
@jonasbrami
jonasbrami deleted the feat/anchor-toggle-link branch May 29, 2026 16:04
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