Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
refactor(markdown-editor): review-driven quality pass (5 findings)
Sergey Kozyrenko2b54a0a6b427
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.tsindex a30fe077..20dc8335 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts@@ -37,14 +37,14 @@ const longestBacktickRun = (text: string): number =>// contains a ``` line (a doc demonstrating fenced markdown — common in knowledge/prompt examples) re-parses as// TWO blocks on the next load: the inner fence closes the outer one. CommonMark requires the fence to be longer// than any backtick run inside — widen it. Otherwise identical to upstream.-const renderTunedCodeBlock = (node: MarkdownRenderNode, h: MarkdownRenderHelpers): string => {+const renderTunedCodeBlock = (node: MarkdownRenderNode, helpers: MarkdownRenderHelpers): string => {const language = node.attrs?.language || '';if (!node.content) {return `\`\`\`${language}\n\n\`\`\``;}- const content = h.renderChildren(node.content);+ const content = helpers.renderChildren(node.content);const fence = '`'.repeat(Math.max(3, longestBacktickRun(content) + 1));return [`${fence}${language}`, content, fence].join('\n');diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.tsindex 47ed862c..458531eb 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts@@ -52,11 +52,10 @@ type ManagerWithEncode = { encodeTextForMarkdown: (text: string) => string };const TunedMarkdownText = Extension.create({name: 'tunedMarkdownText',onBeforeCreate() {- const manager = this.editor.markdown as unknown as ManagerWithEncode | undefined;-- if (!manager) {- return;- }+ // editor.markdown is always assigned by the Markdown extension (priority ordering below); the+ // non-optional cast makes a future regression throw here instead of silently reverting save to the+ // lossy default encoder.+ const manager = this.editor.markdown as unknown as ManagerWithEncode;manager.encodeTextForMarkdown = (text) => text;},diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-variable-highlight.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-variable-highlight.tsindex 86df51de..a5e0adca 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-variable-highlight.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-variable-highlight.ts@@ -7,12 +7,8 @@ import { Decoration, DecorationSet } from '@tiptap/pm/view';import { collectInlineMatches } from './markdown-editor-inline-scan';import { VARIABLE_RE, variableProbe } from './markdown-editor-variable-syntax';-// Highlights Go-template actions ({{.Var}}, {{- if .X}}, {{end}}, {{.A | upper}}, …) as VIEW-ONLY-// decorations. Decorations never touch the document, so getMarkdown() stays byte-identical, and {{ }}-// already round-trips verbatim. A node/mark would gain nothing here and would break the variables-// side-panel, which inserts {{.X}} as plain text and finds its uses by scanning, not by node identity.-// The pure `{{ }}` matching (VARIABLE_RE / variableProbe / findVariableUseRanges) lives in-// markdown-editor-variable-syntax.ts so tiptap-free consumers can use it without the decoration/PM code.+// View-only decorations, never a node/mark: a mark would alter the document (corrupting save) and defeat the+// variables side-panel, which inserts {{.X}} as plain text and finds its uses by scanning, not node identity.const variableHighlightKey = new PluginKey('variableHighlight');const buildDecorations = (doc: PMNode): DecorationSet =>diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor.tsxindex b3216878..114528fb 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx+++ b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx@@ -23,7 +23,7 @@ import {Table,Undo,} from 'lucide-react';-import { type Ref, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';+import { type Ref, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';import { Separator } from '@/components/ui/separator';import { Toggle } from '@/components/ui/toggle';@@ -118,6 +118,11 @@ function MarkdownEditor({const hasResetInitialHistoryRef = useRef(false);+ // Captured at mount: tiptap only reads `content` at construction, and the value-sync effect below owns+ // every later update. Passing `value` reactively would make useEditor's compareOptions see content change+ // on each keystroke and fire a redundant setOptions → view.updateState.+ const [initialContent] = useState(() => value);+// `placeholder` is captured at mount, like the native <input placeholder>. tiptap's setOptions merges// options without re-registering extensions, so a later change can't reach the already-built Placeholder// plugin regardless; keeping it out of the deps makes that explicit and stops rebuilding the whole@@ -127,7 +132,7 @@ function MarkdownEditor({// tiptap invokes onBlur/onUpdate from its live options ref, so these closures always read the latest props.const editor = useEditor({- content: value,+ content: initialContent,contentType: 'markdown',editable: !disabled,extensions,@@ -239,7 +244,7 @@ function MarkdownEditor({}, [editor, value]);useEffect(() => {- if (!editor) {+ if (!editor || editor.isEditable === !disabled) {return;}