Add Discord markdown link length warnings for agents - #81
Conversation
Expose helpers to detect when a formatted [label](url) exceeds Discord's 2000-character message limit, return discordMarkdownLinkWarning from link generation, and surface the warning in the viewer and link creator UI. Update the agent skill, docs, and agent-skills digest accordingly. Co-authored-by: Aanish Bhirud <baanish@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds Discord per-message character-limit (2000) detection for markdown links. A new ChangesDiscord Markdown Link Warnings
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying agent-render with
|
| Latest commit: |
2530695
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://437b29b4.agent-render.pages.dev |
| Branch Preview URL: | https://cursor-discord-markdown-link.agent-render.pages.dev |
Clarify in the agent skill that createGeneratedArtifactLink* returns a ready-to-paste markdownLink string. Expose it in the link creator with a dedicated copy action. Co-authored-by: Aanish Bhirud <baanish@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/markdown-link.test.ts (1)
37-52: ⚡ Quick winAdd an exact-limit boundary test (
== 2,000) for regression safety.Current coverage checks “over” and “well under” the limit, but not the exact boundary where
>vs>=regressions usually happen.Suggested test addition
+ it("does not warn when markdown link length is exactly Discord's limit", () => { + const label = "R"; + const prefix = `[${label}](https://example.com/#`; + const suffix = ")"; + const payloadLength = DISCORD_MESSAGE_MAX_LENGTH - (prefix.length + suffix.length); + const href = `https://example.com/#${"a".repeat(payloadLength)}`; + const markdownLink = formatMarkdownLink(label, href); + + expect(markdownLink.length).toBe(DISCORD_MESSAGE_MAX_LENGTH); + expect(isDiscordMarkdownLinkTooLong(markdownLink)).toBe(false); + expect(getDiscordMarkdownLinkWarning(markdownLink)).toBeNull(); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/markdown-link.test.ts` around lines 37 - 52, Add a new test case that checks the exact boundary condition when a markdown link is precisely 2,000 characters (the exact value of DISCORD_MESSAGE_MAX_LENGTH). This test should create a markdown link using formatMarkdownLink or buildMarkdownLinkShareInfo that results in exactly DISCORD_MESSAGE_MAX_LENGTH characters and verify the behavior of isDiscordMarkdownLinkTooLong and getDiscordMarkdownLinkWarning at this critical boundary. This boundary test is essential to catch off-by-one regressions where incorrect comparison operators (> vs >=) could cause the limit check to fail unexpectedly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/home/link-creator.tsx`:
- Around line 183-195: The handleCopyMarkdownLink function has a race condition
where the async copyTextToClipboard call can complete after generatedLink has
been replaced by a newer generation, causing stale state updates. To fix this,
capture the current generatedLink value at the start of the async operation,
then after the copy operation completes (in both success and error cases),
verify that generatedLink still matches the captured value before calling
setMarkdownLinkCopyState. Only update the state if the value hasn't changed,
ensuring the copy status reflects the actual current link.
---
Nitpick comments:
In `@tests/markdown-link.test.ts`:
- Around line 37-52: Add a new test case that checks the exact boundary
condition when a markdown link is precisely 2,000 characters (the exact value of
DISCORD_MESSAGE_MAX_LENGTH). This test should create a markdown link using
formatMarkdownLink or buildMarkdownLinkShareInfo that results in exactly
DISCORD_MESSAGE_MAX_LENGTH characters and verify the behavior of
isDiscordMarkdownLinkTooLong and getDiscordMarkdownLinkWarning at this critical
boundary. This boundary test is essential to catch off-by-one regressions where
incorrect comparison operators (> vs >=) could cause the limit check to fail
unexpectedly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1989b674-49a3-404e-8b14-e1a8ff55ee7c
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (12)
AGENTS.mddocs/payload-format.mdpublic/.well-known/agent-skills/index.jsonskills/agent-render-linking/SKILL.mdsrc/app/globals.csssrc/components/home/link-creator.tsxsrc/components/viewer/artifact-stage.tsxsrc/lib/markdown-link.tssrc/lib/payload/link-creator.tstests/components/link-creator.test.tsxtests/link-creator.test.tstests/markdown-link.test.ts
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Incremental review — 1 new commit since prior passReviewed the incremental diff since the prior review at Verified: Static review only (typecheck/lint not run in read-only review mode). Files Reviewed (4 files, incremental)
Prior pass — unchanged files carried forward (No Issues)
Previous Review Summary (commit 4c17ffe)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 4c17ffe)Status: No Issues Found | Recommendation: Merge Files Reviewed (12 files)
Notes
Reviewed by GLM-5.2 · Input: 86.4K · Output: 11.6K · Cached: 172.5K |
|
| Filename | Overview |
|---|---|
| src/lib/markdown-link.ts | Core new helpers for markdown link formatting and Discord length checks; uses Intl.NumberFormat for locale-safe number formatting, provides separate agent-facing vs viewer-facing warning strings. |
| src/lib/payload/link-creator.ts | Adds markdownLink, markdownLinkLength, and discordMarkdownLinkWarning to GeneratedArtifactLink; both createGeneratedArtifactLink and createGeneratedArtifactLinkAsync correctly populate these via buildGeneratedLinkShareInfo. |
| src/components/home/link-creator.tsx | Adds markdown-link textarea, length metric card, concurrency-safe copy button, and warning banner; copy state management consistent with existing handleCopy pattern. |
| src/components/viewer/artifact-stage.tsx | Uses pageHref state (SSR-safe, set in useEffect) and memoized markdownLinkShareInfo to show a viewer-appropriate Discord notice; copy handler falls back to window.location.href when state not yet populated. |
| src/app/globals.css | Adds .artifact-share-warning and .creator-warning-state styles using --warning CSS variable and color-mix; mirrors existing .creator-error-state pattern. |
| tests/markdown-link.test.ts | Good coverage: tests both over-limit and under-limit paths, verifies viewer notice does not contain split-bundle guidance, and checks buildMarkdownLinkShareInfo output shape. |
| tests/link-creator.test.ts | Adds test for the Discord warning surface path via createGeneratedArtifactLinkAsync with a 2800-char payload; asserts markdownLinkLength, warning text, and multi-message guidance. |
| skills/agent-render-linking/SKILL.md | Updated with ready-to-send markdown link guidance, markdownLinkLength/discordMarkdownLinkWarning fields, and revised Discord limit from 1,500 to 2,000 characters. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[createGeneratedArtifactLink / Async] --> B[buildGeneratedLinkShareInfo\nlabel from envelope.title]
B --> C[buildMarkdownLinkShareInfo\nformatMarkdownLink + length check]
C --> D{markdownLink.length\n> 2000?}
D -->|No| E[discordMarkdownLinkWarning: null]
D -->|Yes| F[getDiscordMarkdownLinkWarning\nagent-directed split-bundle advice]
E --> G[GeneratedArtifactLink\nmarkdownLink / markdownLinkLength / discordMarkdownLinkWarning]
F --> G
G --> H[LinkCreator UI\nwarning banner + copy button]
I[ArtifactStage viewer] --> J[buildMarkdownLinkShareInfo\nactiveArtifactHeading + pageHref]
J --> K{markdownLink.length\n> 2000?}
K -->|No| L[discordViewerNotice: null]
K -->|Yes| M[getDiscordMarkdownLinkViewerNotice\nviewer-facing may be too long notice]
L --> N[No warning shown]
M --> O[artifact-share-warning paragraph]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[createGeneratedArtifactLink / Async] --> B[buildGeneratedLinkShareInfo\nlabel from envelope.title]
B --> C[buildMarkdownLinkShareInfo\nformatMarkdownLink + length check]
C --> D{markdownLink.length\n> 2000?}
D -->|No| E[discordMarkdownLinkWarning: null]
D -->|Yes| F[getDiscordMarkdownLinkWarning\nagent-directed split-bundle advice]
E --> G[GeneratedArtifactLink\nmarkdownLink / markdownLinkLength / discordMarkdownLinkWarning]
F --> G
G --> H[LinkCreator UI\nwarning banner + copy button]
I[ArtifactStage viewer] --> J[buildMarkdownLinkShareInfo\nactiveArtifactHeading + pageHref]
J --> K{markdownLink.length\n> 2000?}
K -->|No| L[discordViewerNotice: null]
K -->|Yes| M[getDiscordMarkdownLinkViewerNotice\nviewer-facing may be too long notice]
L --> N[No warning shown]
M --> O[artifact-share-warning paragraph]
Reviews (2): Last reviewed commit: "Address review feedback on Discord markd..." | Re-trigger Greptile
- Guard markdown-link copy against stale async completion - Use viewer-facing notice copy in artifact stage - Format warning numbers with Intl.NumberFormat - Rename duplicate metric label to Markdown link length Co-authored-by: Aanish Bhirud <baanish@users.noreply.github.com>
Summary
Agents generating agent-render links can now detect when a formatted Discord markdown link
[label](url)exceeds Discord's 2,000-character message limit.DISCORD_MESSAGE_MAX_LENGTH,buildMarkdownLinkShareInfo, and related helpers insrc/lib/markdown-link.tscreateGeneratedArtifactLink*results withmarkdownLink,markdownLinkLength, anddiscordMarkdownLinkWarningskills/agent-render-linking/SKILL.md, docs,AGENTS.md, and the agent-skills digestAgent contract
When
discordMarkdownLinkWarningis non-null, agents should surface the warning and split the bundle into smaller artifacts, sending separate markdown links across multiple Discord messages.Testing
npm run test -- tests/markdown-link.test.ts tests/link-creator.test.ts tests/components/link-creator.test.tsxnpm run lintnpm run typecheckSummary by CodeRabbit