-
Notifications
You must be signed in to change notification settings - Fork 8
feat(page-actions): add agent handoff prompt #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JakeSCahill
merged 4 commits into
redpanda-data:main
from
malinskibeniamin:ben-malinski/send-to-ai-agent/copy-agent-handoff
Aug 4, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
67871ae
feat(page-actions): add agent handoff prompt
malinskibeniamin 864ba5f
fix(page-actions): require agent handoff opt-in
malinskibeniamin 1d5428b
fix(review): harden agent handoff flow
malinskibeniamin 5738a74
fix(review): assign agent prompt ownership
malinskibeniamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /src/js/13-agent-handoff.js @redpanda-data/documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| :!table-caption: | ||
| :page-pagination: | ||
| :page-has-markdown: | ||
| :page-agent-handoff: | ||
|
|
||
| {description} | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Show the agent handoff action only when the page opts in. | ||
| */ | ||
|
|
||
| module.exports = ({ data: { root } }) => { | ||
| return root.page?.attributes?.['agent-handoff'] !== undefined | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| ;(function (root, factory) { | ||
| const agentHandoff = factory() | ||
|
|
||
| if (typeof module === 'object' && module.exports) { | ||
| module.exports = agentHandoff | ||
| } else { | ||
| root.RedpandaDocsAgentHandoff = agentHandoff | ||
| } | ||
| })(typeof window === 'undefined' ? this : window, function () { | ||
| const headingPattern = /^(#{1,6})[ \t]+(.+?)\s*$/ | ||
| const fencePattern = /^[ \t]*(`{3,}|~{3,})/ | ||
|
|
||
| function normalizedAnchors (sectionAnchor) { | ||
| const rawAnchor = sectionAnchor.replace(/^#/, '') | ||
| let decodedAnchor | ||
|
|
||
| try { | ||
| decodedAnchor = decodeURIComponent(rawAnchor) | ||
| } catch (error) { | ||
| decodedAnchor = rawAnchor | ||
| } | ||
|
|
||
| const generatedMarkdownAnchor = decodedAnchor.replace(/^_/, '').replace(/_/g, '-') | ||
| return generatedMarkdownAnchor === decodedAnchor | ||
| ? [decodedAnchor] | ||
| : [decodedAnchor, generatedMarkdownAnchor] | ||
| } | ||
|
|
||
| function extractMarkdownSection (markdown, sectionAnchor) { | ||
| const fullPage = markdown.trim() | ||
| if (!sectionAnchor) return fullPage | ||
|
|
||
| const anchorMarkers = normalizedAnchors(sectionAnchor).map((anchor) => `(#${anchor})`) | ||
| const lines = fullPage.split('\n') | ||
| const headingLines = computeHeadingLines(lines) | ||
| const startIndex = lines.findIndex( | ||
| (line, index) => headingLines[index] && anchorMarkers.some((marker) => line.includes(marker)) | ||
| ) | ||
| if (startIndex === -1) return fullPage | ||
|
|
||
| const sectionLevel = lines[startIndex].match(headingPattern)[1].length | ||
| const endIndex = lines.findIndex((line, index) => { | ||
| if (index <= startIndex) return false | ||
|
|
||
| if (!headingLines[index]) return false | ||
| return line.match(headingPattern)[1].length <= sectionLevel | ||
| }) | ||
|
|
||
| return lines.slice(startIndex, endIndex === -1 ? undefined : endIndex).join('\n').trim() | ||
| } | ||
|
|
||
| function computeHeadingLines (lines) { | ||
| let fenceMarker = '' | ||
|
|
||
| return lines.map((line) => { | ||
| const fence = line.match(fencePattern) | ||
| if (fence) { | ||
| const marker = fence[1][0] | ||
| if (!fenceMarker) fenceMarker = marker | ||
| else if (marker === fenceMarker) fenceMarker = '' | ||
| return false | ||
| } | ||
|
|
||
| return !fenceMarker && headingPattern.test(line) | ||
| }) | ||
| } | ||
|
|
||
| function buildAgentHandoffPrompt ({ | ||
| componentName = '', | ||
| docsOrigin, | ||
| markdown, | ||
| markdownUrl, | ||
| pageTitle, | ||
| pageUrl, | ||
| sectionAnchor = '', | ||
| sectionTitle = '', | ||
| }) { | ||
| const context = extractMarkdownSection(markdown, sectionAnchor) | ||
| const componentExport = componentName | ||
| ? new URL(`/${encodeURIComponent(componentName)}-full.txt`, docsOrigin).href | ||
| : null | ||
| const scope = [ | ||
| `- Documentation page: ${pageTitle}`, | ||
| sectionTitle ? `- Current section: ${sectionTitle}` : null, | ||
| `- Page: ${pageUrl}`, | ||
| `- Markdown source: ${markdownUrl}`, | ||
| ].filter(Boolean) | ||
| const sources = [ | ||
| `- Documentation index: ${new URL('/llms.txt', docsOrigin).href}`, | ||
| componentExport ? `- Component documentation export: ${componentExport}` : null, | ||
| `- Documentation MCP server: ${new URL('/mcp', docsOrigin).href}`, | ||
| ].filter(Boolean) | ||
| const instructions = [ | ||
| "1. Read the current project's agent and contributor instructions before changing anything.", | ||
| '2. Inspect the project and identify where this documentation applies. Do not invent Redpanda commands, fields, or behavior.', | ||
| '3. If applicable, implement the smallest reversible change and preserve unrelated behavior. If not applicable, explain why and stop.', | ||
| '4. You may edit and test local files. Before destructive operations, external mutations, or changes to a live ' + | ||
| 'Redpanda environment, show the plan or diff and get my confirmation. Never expose credentials or secrets.', | ||
| "5. Run the project's relevant checks and any documented Redpanda validation or diff command.", | ||
| '6. Summarize the changes, verification, remaining manual steps, and any missing or conflicting documentation.', | ||
| ] | ||
|
|
||
| return `# Apply this Redpanda documentation | ||
|
|
||
| Work in the current project. Determine whether this guidance applies, then make the smallest safe update that keeps the project aligned with the current Redpanda pattern. | ||
|
|
||
| ## Scope | ||
|
|
||
| ${scope.join('\n')} | ||
|
|
||
| ## Authoritative Redpanda context | ||
|
|
||
| ${sources.join('\n')} | ||
|
|
||
| ## Instructions | ||
|
|
||
| ${instructions.join('\n')} | ||
|
|
||
| ## Documentation context | ||
|
|
||
| --- BEGIN CURRENT DOCUMENTATION --- | ||
| ${context} | ||
| --- END CURRENT DOCUMENTATION ---` | ||
| } | ||
|
|
||
| return { | ||
| buildAgentHandoffPrompt, | ||
| extractMarkdownSection, | ||
| } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.