From 3c4b347ac7dfb8ae01e2fd4676152d4adeecd1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Litavsk=C3=A1?= Date: Mon, 9 Nov 2026 12:13:36 +0100 Subject: [PATCH 01/16] Add question path to generation --- .../ai/generation/dmp_generator_component.py | 1 + .../tests/generation/test_dmp_generator.py | 43 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/service/src/ai_document_plugin_service/ai/generation/dmp_generator_component.py b/service/src/ai_document_plugin_service/ai/generation/dmp_generator_component.py index 7e60848..60d82b1 100644 --- a/service/src/ai_document_plugin_service/ai/generation/dmp_generator_component.py +++ b/service/src/ai_document_plugin_service/ai/generation/dmp_generator_component.py @@ -731,6 +731,7 @@ def construct_question_answers(question: dict[str, Any], level: int) -> str: groups = [construct_question_answers(q, level + 1) for q in question['children']] return '\t' * level + 'SUBQUESTIONS GROUP: \n' + ''.join(groups) result = ('\t' * level) + ' - Question: ' + (self.sanitize(question['question_title']) or '') + '\n' + result += ('\t' * level) + ' Question path: ' + question['question_path'] + '\n' if question.get('reply') is not None: result += ('\t' * level) + ' Answer: ' + question['reply'] + '\n' for child in question['children']: diff --git a/service/tests/generation/test_dmp_generator.py b/service/tests/generation/test_dmp_generator.py index 1383c7d..556ae39 100644 --- a/service/tests/generation/test_dmp_generator.py +++ b/service/tests/generation/test_dmp_generator.py @@ -261,13 +261,39 @@ def test_construct_chapter_prompt_returns_none_for_empty() -> None: def test_construct_chapter_prompt_formats_questions() -> None: replies = [ - {'type': 'question', 'question_title': 'Q1', 'reply': 'A1', 'children': []}, + {'type': 'question', 'question_path': 'ch.q1', 'question_title': 'Q1', 'reply': 'A1', 'children': []}, ] prompt = _component().construct_chapter_prompt('Data', replies) assert prompt is not None assert 'Chapter name: Data' in prompt - assert 'Q1' in prompt - assert 'A1' in prompt + assert ' - Question: Q1\n Question path: ch.q1\n Answer: A1\n' in prompt + + +def test_construct_chapter_prompt_preserves_nested_questions() -> None: + replies = [ + { + 'type': 'question', + 'question_path': 'ch.parent', + 'question_title': 'Parent', + 'children': [ + { + 'type': 'question', + 'question_path': 'ch.parent.child', + 'question_title': 'Child', + 'reply': 'Child answer', + 'children': [], + }, + ], + }, + ] + + prompt = _component().construct_chapter_prompt('Data', replies) + + assert prompt is not None + assert ( + ' - Question: Parent\n Question path: ch.parent\n' + '\t - Question: Child\n\t Question path: ch.parent.child\n\t Answer: Child answer\n' + ) in prompt async def test_disabled_cover_page_is_omitted_even_when_source_data_are_available() -> None: @@ -315,6 +341,13 @@ def test_match_replies_selection_handles_multianswer_groups() -> None: assert all(item['type'] == 'wrapper' for item in result) flattened = [child['reply'] for wrapper in result for child in wrapper['children']] assert sorted(flattened) == ['No', 'Yes'] + prompt = component.construct_chapter_prompt('Data', result) + assert prompt is not None + assert prompt.count('SUBQUESTIONS GROUP:') == 2 + assert prompt.count('Question path:') == 2 + assert '\t Question path: ch.listQ.uuidA.itemQ\n\t Answer: Yes\n' in prompt + assert '\t Question path: ch.listQ.uuidB.itemQ\n\t Answer: No\n' in prompt + assert '*' not in prompt def test_handle_single_reply_adds_synthetic_neighbour_answers_from_depth_two() -> None: @@ -348,6 +381,10 @@ def test_handle_single_reply_adds_synthetic_neighbour_answers_from_depth_two() - assert synthetic['question_title'] == 'Neighbor' assert synthetic['reply'] == 'No' assert synthetic['debug-info'] + prompt = component.construct_chapter_prompt('Data', result) + assert prompt is not None + assert ' Question path: ch.listQ.itemQ\n Answer: Yes\n' in prompt + assert ' Question path: ch.listQ.neighborQ\n Answer: No\n' in prompt def test_filter_reachable_replies_drops_stale_option_branch() -> None: From daddac4a4d15ebf106ac92b70926dae80ddfd444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Litavsk=C3=A1?= Date: Mon, 9 Nov 2026 12:16:59 +0100 Subject: [PATCH 02/16] Update generation prompt --- service/prompts.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/service/prompts.yaml b/service/prompts.yaml index 9ae35d5..e1be703 100644 --- a/service/prompts.yaml +++ b/service/prompts.yaml @@ -28,6 +28,16 @@ dmp_generation: Do not add any information not explicitly stated in the answers! You do not have to include all questions and answers, you may omit information that clearly does not fit into the section. Do not rewrite the heading, write only the section content. Make the text sound natural, it should not be just direct copy of the questions and answers, but rather a concise, well structured and fluent data management plan. Feel free to use markdown tables or lists. Maintain consistency in style and terminology with the already generated parts. + + Source attribution is mandatory for every factual statement. Wrap each statement in exactly this format: + xxxxx + Replace "question path" with the exact Question path supplied alongside the answer that supports the statement, and replace "xxxxx" with the statement text. Never output these placeholders literally. + Copy source paths exactly; do not invent, shorten, or translate them. Only cite questions with answers that support the statement. + If a statement combines information from multiple answers, list all supporting Question paths in the source attribute, separated by a single space, without duplicates: + Statement supported by both answers. + Do not leave any factual information outside statement tags. Use separate tags for statements with different supporting sources, and do not nest statement tags. + Keep Markdown list markers and table delimiters outside the tags; wrap the factual text within each list item or table cell. Purely structural headings and labels do not need source tags. + Return the tags directly as part of the section content, without escaping them or enclosing the output in a code block. The output language should be {language}. Keep proper names, official project names, abbreviations, identifiers, filenames, repository names, standards, licences, and technical terms that are conventionally left untranslated in their original form. From e8031d88f32dfd5d7e3e0fbbedc815b0bcbaec95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Litavsk=C3=A1?= Date: Mon, 9 Nov 2026 12:20:35 +0100 Subject: [PATCH 03/16] Update polishing prompt --- service/prompts.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/prompts.yaml b/service/prompts.yaml index e1be703..288fc04 100644 --- a/service/prompts.yaml +++ b/service/prompts.yaml @@ -59,6 +59,13 @@ dmp_polishing: - Consolidate related information that is scattered across sections. - Remove or shorten redundant mentions when the same information appears in multiple places (keep it in the most appropriate location). - Improve flow and logical structure so each section focuses on its intended theme. + + # Source attribution rules: + - Preserve the text markup and the association between each statement and its supporting source paths. Keep rephrased or translated statements inside their tags with their original sources. + - When moving a statement, move its entire statement element, including the opening tag, source attribute, text, and closing tag. + - When merging statements, combine their supporting source paths in the resulting statement's source attribute, separated by a single space and without duplicates. Do not attach sources from unrelated statements. + - Use only source paths already present in the input statement elements. Copy paths exactly; never invent, shorten, or translate them. + - Do not move factual text out of its statement tags, nest statement tags, escape the tags, or wrap them in code blocks. When removing a redundant statement, remove its enclosing tags together with its text. # Language rules: - Write all section content exclusively in {language}. From 9c971117262470b31641ac0b46a3fad6f992ef7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Litavsk=C3=A1?= Date: Mon, 9 Nov 2026 12:45:29 +0100 Subject: [PATCH 04/16] Increase max tokens --- service/prompts.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/prompts.yaml b/service/prompts.yaml index 288fc04..9355897 100644 --- a/service/prompts.yaml +++ b/service/prompts.yaml @@ -21,7 +21,7 @@ assignment: dmp_generation: - max_tokens: 4096 + max_tokens: 16384 temperature: 0.8 system_message: | You are a data management plan writer. Rewrite the following questions and answers into ONE SECTION with NO subsections of a DMP. @@ -49,7 +49,7 @@ cover_page_generation: Do not include the top-level section heading or add facts not present in the answers. dmp_polishing: - max_tokens: 16384 + max_tokens: 32768 temperature: 0.3 system_message: | You are a data management plan editor. Your task is to polish and reorganize a DMP document. Output a valid Markdown file. From e8c429f8673d29e32ef4f335c7aa16da64625dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hana=20Litavsk=C3=A1?= Date: Mon, 9 Nov 2026 13:06:03 +0100 Subject: [PATCH 05/16] Add temporary UI --- plugin/src/MarkdownRenderer.module.css | 12 +++++++ plugin/src/components/PipelineResultPanel.tsx | 7 +++- plugin/src/components/ProjectTab.tsx | 6 +++- plugin/src/components/RunDetailPanel.tsx | 2 ++ plugin/src/markdown-utils.tsx | 35 +++++++++++++++---- plugin/src/statement-sources.ts | 27 ++++++++++++++ 6 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 plugin/src/MarkdownRenderer.module.css create mode 100644 plugin/src/statement-sources.ts diff --git a/plugin/src/MarkdownRenderer.module.css b/plugin/src/MarkdownRenderer.module.css new file mode 100644 index 0000000..49aade2 --- /dev/null +++ b/plugin/src/MarkdownRenderer.module.css @@ -0,0 +1,12 @@ +.sourceLink { + display: inline-block; + font-size: 0.7em; + vertical-align: super; + padding: 0 0.15em; + text-decoration: none; +} + +.sourceLink:focus-visible { + outline: 2px solid currentColor; + outline-offset: 2px; +} diff --git a/plugin/src/components/PipelineResultPanel.tsx b/plugin/src/components/PipelineResultPanel.tsx index 8c77395..65156e4 100644 --- a/plugin/src/components/PipelineResultPanel.tsx +++ b/plugin/src/components/PipelineResultPanel.tsx @@ -13,6 +13,7 @@ import { MarkdownRenderer } from '@/markdown-utils' import type { PipelineStatusResponse, ResultRenderMode } from '@/types' type PipelineResultPanelProps = { + projectUuid: string resultMarkdown: string | null resultRunId: string | null downloadBaseName: string @@ -20,6 +21,7 @@ type PipelineResultPanelProps = { } export function PipelineResultPanel({ + projectUuid, resultMarkdown, resultRunId, downloadBaseName, @@ -156,7 +158,10 @@ export function PipelineResultPanel({ /> ) : ( - + )} diff --git a/plugin/src/components/ProjectTab.tsx b/plugin/src/components/ProjectTab.tsx index e132b79..211fcb4 100644 --- a/plugin/src/components/ProjectTab.tsx +++ b/plugin/src/components/ProjectTab.tsx @@ -171,7 +171,11 @@ export default function ProjectTab({
{selectedRunId ? ( - + ) : ( Promise diff --git a/plugin/src/markdown-utils.tsx b/plugin/src/markdown-utils.tsx index e153924..9bac47a 100644 --- a/plugin/src/markdown-utils.tsx +++ b/plugin/src/markdown-utils.tsx @@ -2,21 +2,44 @@ import { Prose } from '@ds-wizard/plugin-sdk/ui/Prose' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' +import styles from '@/MarkdownRenderer.module.css' +import { prepareStatementSources } from '@/statement-sources' + type MarkdownRendererProps = { markdown: string + projectUuid: string } -/** Generated Markdown, typeset by the wizard's `Prose`; raw HTML in it is skipped. */ -export function MarkdownRenderer({ markdown }: MarkdownRendererProps) { +export function MarkdownRenderer({ markdown, projectUuid }: MarkdownRendererProps) { + const prepared = prepareStatementSources(markdown, projectUuid, window.location.origin) return ( ( - - ), + a: ({ node: _node, href, children, ...props }) => { + const source = href ? prepared.sourceLinks.get(href) : undefined + return ( + + {source ? ( +