From f993d9809b201c03771b901e906461c958591df3 Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Tue, 15 Sep 2026 18:27:15 +0530 Subject: [PATCH 01/11] Add settings loading and chat completions logic Load settings and determine chat completions tool usage based on API type. --- strix/agents/factory.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index b2fcbf08c..a707914e4 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -671,6 +671,12 @@ def build_strix_agent( instructions_override: Use this verbatim as the system prompt instead of rendering the built-in scan prompt. """ + settings = load_settings() + if settings.llm.api_type == "chat_completions": + chat_completions_tools = True + elif settings.llm.api_type == "responses": + chat_completions_tools = False + if instructions_override is not None: instructions = instructions_override else: @@ -686,7 +692,6 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: - # Yielding to the user is only meaningful when one is attached. agent_tools.append(respond_to_user) if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] From 4884d1ba75575570be7b53962b49ade1979fbd8a Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 00:46:40 +0530 Subject: [PATCH 02/11] Add deduplication of markdown headings in report Added a function to remove duplicate markdown headings from the report content before writing it to the file. Fixes #1332 --- strix/report/writer.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/strix/report/writer.py b/strix/report/writer.py index cf858f7d7..0c696d689 100644 --- a/strix/report/writer.py +++ b/strix/report/writer.py @@ -136,12 +136,34 @@ def write_run_record(run_dir: Path, run_record: dict[str, Any]) -> None: ) -def write_executive_report(run_dir: Path, final_scan_result: str) -> None: +def deduplicate_markdown_headings(content: str) -> str: + """Removes duplicate markdown headings appearing consecutively.""" + lines = content.splitlines() + cleaned: list[str] = [] + prev_heading: str | None = None + + for line in lines: + stripped = line.strip() + match = re.match(r"^(#{1,6})\s+(.*)$", stripped) + if match: + heading_key = f"{match.group(1)} {match.group(2).strip().lower()}" + if heading_key == prev_heading: + continue + prev_heading = heading_key + else: + if stripped: + prev_heading = None + cleaned.append(line) + + return "\n".join(cleaned) + +def write_execution_report(run_dir: Path, final_scan_result: str) -> None: path = run_dir / "penetration_test_report.md" + cleaned_result = deduplicate_markdown_headings(final_scan_result) with path.open("w", encoding="utf-8") as f: f.write("# Security Penetration Test Report\n\n") - f.write(f"**Generated:** {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')}\n\n") - f.write(f"{final_scan_result}\n") + f.write(f"**Generated:** {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')}\n\n") + f.write(f"{cleaned_result}\n") logger.info("Saved final penetration test report to: %s", path) From 05ec422bf54b948e746942c7fb0eb0544f43050f Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 00:53:57 +0530 Subject: [PATCH 03/11] Add tests for markdown heading deduplication test(report): add tests for markdown heading deduplication --- tests/test_report_writer.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_report_writer.py b/tests/test_report_writer.py index 9b8490101..25dd6a9d6 100644 --- a/tests/test_report_writer.py +++ b/tests/test_report_writer.py @@ -10,9 +10,10 @@ import pytest from strix.report.writer import ( atomic_write_text, + deduplicate_markdown_headings, read_run_record, render_vulnerability_md, - write_executive_report, + write_execution_report, write_run_record, write_vulnerabilities, ) @@ -240,6 +241,36 @@ def test_write_executive_report_writes_markdown(tmp_path: Path) -> None: assert "Scan complete. No critical issues." in content +def test_deduplicate_markdown_headings() -> None: + raw_markdown = ( + "# Executive Summary\n" + "# Executive Summary\n" + "This is the summary content.\n\n" + "## Methodology\n" + "## Methodology\n" + "Testing approach details." + ) + expected = ( + "# Executive Summary\n" + "This is the summary content.\n\n" + "## Methodology\n" + "Testing approach details." + ) + assert deduplicate_markdown_headings(raw_markdown) == expected + + +def test_write_execution_report_deduplicates_headings(tmp_path: Path) -> None: + duplicate_scan_output = ( + "# Executive Summary\n" + "# Executive Summary\n" + "Scan complete. No critical issues.\n" + ) + write_execution_report(tmp_path, duplicate_scan_output) + content = (tmp_path / "penetration_test_report.md").read_text(encoding="utf-8") + assert content.count("# Executive Summary") == 1 + assert "Scan complete. No critical issues." in content + + def test_render_vulnerability_md_surfaces_calibration_metadata() -> None: """Confidence, the case against the finding, and retest status are part of the deliverable — storing them without rendering hides the reasoning.""" From 05a28b077867f239c8e6c649e66a93eae849386c Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:17:49 +0530 Subject: [PATCH 04/11] Refactor agent tool settings initialization revert(factory): restore factory.py to match upstream --- strix/agents/factory.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index a707914e4..a1f2a33de 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -671,12 +671,6 @@ def build_strix_agent( instructions_override: Use this verbatim as the system prompt instead of rendering the built-in scan prompt. """ - settings = load_settings() - if settings.llm.api_type == "chat_completions": - chat_completions_tools = True - elif settings.llm.api_type == "responses": - chat_completions_tools = False - if instructions_override is not None: instructions = instructions_override else: @@ -692,7 +686,9 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: + # yielding to the user is only meaningful when one is attached agent_tools.append(respond_to_user) + if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] else: From eff2177fa0c5afe3570bae624f8ad45567753930 Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:25:09 +0530 Subject: [PATCH 05/11] Update factory.py revert(factory): align indentation with upstream From dfa29f2a755a4948485abf59993ef3488568665a Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:29:32 +0530 Subject: [PATCH 06/11] Fix comment formatting in factory.py revert(factory): align indentation with upstream --- strix/agents/factory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index a1f2a33de..23b96f511 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -686,9 +686,9 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: - # yielding to the user is only meaningful when one is attached + # Yielding to the user is only meaningful when one is attached. agent_tools.append(respond_to_user) - + if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] else: From 5571e9652dcd0c4b074e261a1306a9c6521c0f80 Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:31:23 +0530 Subject: [PATCH 07/11] Update factory.py revert(factory): align indentation with upstream --- strix/agents/factory.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index 23b96f511..2fb80eee3 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -687,8 +687,7 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: # Yielding to the user is only meaningful when one is attached. - agent_tools.append(respond_to_user) - + agent_tools.append(respond_to_user) if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] else: From 6d94ae86cb8bc7003cec401faf673d37c09e5250 Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:33:37 +0530 Subject: [PATCH 08/11] Update factory.py revert(factory): align indentation with upstream --- strix/agents/factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index 2fb80eee3..98c1e5cb6 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -687,7 +687,7 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: # Yielding to the user is only meaningful when one is attached. - agent_tools.append(respond_to_user) + agent_tools.append(respond_to_user) if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] else: From d3331c9d7b8a026fe28c11018e8c1caef0328dbd Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:36:38 +0530 Subject: [PATCH 09/11] Update factory.py revert(factory): align indentation with upstream --- strix/agents/factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strix/agents/factory.py b/strix/agents/factory.py index 98c1e5cb6..b2fcbf08c 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -687,7 +687,7 @@ def build_strix_agent( agent_tools = [*_EXTRA_TOOLS, *(extra_tools or [])] if interactive: # Yielding to the user is only meaningful when one is attached. - agent_tools.append(respond_to_user) + agent_tools.append(respond_to_user) if is_root: tools: list[Tool] = [*_BASE_TOOLS, *agent_tools, finish_scan] else: From e7006390a53848dd96a6330846fbc92e623e155a Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:46:14 +0530 Subject: [PATCH 10/11] Update writer.py fix(report): preserve fenced code blocks and use UTC in execution report --- strix/report/writer.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/strix/report/writer.py b/strix/report/writer.py index 0c696d689..44d083673 100644 --- a/strix/report/writer.py +++ b/strix/report/writer.py @@ -137,13 +137,38 @@ def write_run_record(run_dir: Path, run_record: dict[str, Any]) -> None: def deduplicate_markdown_headings(content: str) -> str: - """Removes duplicate markdown headings appearing consecutively.""" + """Removes duplicate markdown headings appearing consecutively, ignoring fenced code blocks.""" lines = content.splitlines() cleaned: list[str] = [] prev_heading: str | None = None + in_fence = False + fence_char = "" + fence_len = 0 for line in lines: stripped = line.strip() + + # Check for code fence start or end (``` or ~~~) + if stripped.startswith("```") or stripped.startswith("~~~"): + char = stripped[0] + count = len(stripped) - len(stripped.lstrip(char)) + if not in_fence: + in_fence = True + fence_char = char + fence_len = count + prev_heading = None + cleaned.append(line) + continue + elif char == fence_char and count >= fence_len: + in_fence = False + prev_heading = None + cleaned.append(line) + continue + + if in_fence: + cleaned.append(line) + continue + match = re.match(r"^(#{1,6})\s+(.*)$", stripped) if match: heading_key = f"{match.group(1)} {match.group(2).strip().lower()}" @@ -157,16 +182,18 @@ def deduplicate_markdown_headings(content: str) -> str: return "\n".join(cleaned) + def write_execution_report(run_dir: Path, final_scan_result: str) -> None: path = run_dir / "penetration_test_report.md" cleaned_result = deduplicate_markdown_headings(final_scan_result) with path.open("w", encoding="utf-8") as f: f.write("# Security Penetration Test Report\n\n") - f.write(f"**Generated:** {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')}\n\n") + f.write(f"**Generated:** {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')}\n\n") f.write(f"{cleaned_result}\n") logger.info("Saved final penetration test report to: %s", path) + def write_vulnerabilities( run_dir: Path, vulnerability_reports: list[dict[str, Any]], From 17eb71dfa199ed403083b4a1a57e55553a86aaf8 Mon Sep 17 00:00:00 2001 From: RAJVARDHAN <95933896+vardhans07@users.noreply.github.com> Date: Sat, 19 Sep 2026 01:48:40 +0530 Subject: [PATCH 11/11] Update test_report_writer.py test(report): verify fenced code blocks are preserved during deduplication --- tests/test_report_writer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_report_writer.py b/tests/test_report_writer.py index 25dd6a9d6..b3db43aca 100644 --- a/tests/test_report_writer.py +++ b/tests/test_report_writer.py @@ -246,6 +246,11 @@ def test_deduplicate_markdown_headings() -> None: "# Executive Summary\n" "# Executive Summary\n" "This is the summary content.\n\n" + "```bash\n" + "# bash comment inside fence\n" + "# bash comment inside fence\n" + "echo test\n" + "```\n\n" "## Methodology\n" "## Methodology\n" "Testing approach details." @@ -253,6 +258,11 @@ def test_deduplicate_markdown_headings() -> None: expected = ( "# Executive Summary\n" "This is the summary content.\n\n" + "```bash\n" + "# bash comment inside fence\n" + "# bash comment inside fence\n" + "echo test\n" + "```\n\n" "## Methodology\n" "Testing approach details." )