Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(markdown-editor): clearer names for three helpers

Sergey Kozyrenko30b22f9c1764
diff --git a/frontend/src/components/shared/markdown-editor/index.ts b/frontend/src/components/shared/markdown-editor/index.ts
index 25605a84..4aa0cb0f 100644
--- a/frontend/src/components/shared/markdown-editor/index.ts
+++ b/frontend/src/components/shared/markdown-editor/index.ts
@@ -3,6 +3,6 @@
// owns the lazy() boundary, so importing it is chunk-free until rich mode renders).
export { MarkdownEditorField } from './markdown-editor-field';
export type { MarkdownEditorFieldHandle } from './markdown-editor-field';
-export { findVariableUseRanges, VARIABLE_RE, variableProbe } from './markdown-editor-variable-syntax';
+export { findVariableUseRanges, VARIABLE_RE, variableUseRegex } from './markdown-editor-variable-syntax';
export { EditorViewModeToggle } from './markdown-editor-view-mode';
export type { EditorViewMode } from './markdown-editor-view-mode';
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts
index 2a8f9aed..1a1fd908 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.ts
@@ -17,7 +17,7 @@ import { MarkdownPaste } from './markdown-editor-paste';
import { TagHighlight } from './markdown-editor-tag-highlight';
import { VariableHighlight } from './markdown-editor-variable-highlight';
-const dropUnderscore = (rules: { find: unknown }[]) =>
+const dropUnderscoreRules = (rules: { find: unknown }[]) =>
rules.filter((rule) => !(rule.find instanceof RegExp && rule.find.source.includes('_')));
const longestBacktickRun = (text: string): number =>
@@ -70,10 +70,10 @@ const TunedStarterKit = StarterKit.extend({
if (extension.name === 'bold' || extension.name === 'italic') {
return extension.extend({
addInputRules() {
- return dropUnderscore(this.parent?.() ?? []);
+ return dropUnderscoreRules(this.parent?.() ?? []);
},
addPasteRules() {
- return dropUnderscore(this.parent?.() ?? []);
+ return dropUnderscoreRules(this.parent?.() ?? []);
},
});
}
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-field.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor-field.tsx
index 721e2388..e9c79a18 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-field.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-field.tsx
@@ -12,7 +12,7 @@ import type { MarkdownEditorHandle } from './markdown-editor';
import type { EditorViewMode } from './markdown-editor-view-mode';
import { MARKDOWN_EDITOR_WRAPPER_CLASS } from './markdown-editor-styles';
-import { insertTextareaText, selectNextTextareaUse } from './markdown-editor-textarea';
+import { insertAtTextareaCaret, selectNextTextareaUse } from './markdown-editor-textarea';
// Static-importing MarkdownEditor would merge the tiptap chunk into every route that pulls a util from the barrel.
const MarkdownEditor = lazy(() => import('./markdown-editor').then((module) => ({ default: module.MarkdownEditor })));
@@ -65,7 +65,7 @@ export function MarkdownEditorField({
// would splice the value and dirty the form); the rich branch guards on editor.isEditable.
insertAtCursor: (text) => {
if (!disabled && rawRef.current) {
- insertTextareaText(rawRef.current.textarea, text, onChange);
+ insertAtTextareaCaret(rawRef.current.textarea, text, onChange);
}
},
selectNextUse: (variable) =>
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-highlight.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-highlight.test.ts
index 356bbdd4..767ae0d9 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-highlight.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-highlight.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { TAG_RE } from './markdown-editor-tag-highlight';
-import { findVariableUseRanges, VARIABLE_RE, variableProbe } from './markdown-editor-variable-syntax';
+import { findVariableUseRanges, VARIABLE_RE, variableUseRegex } from './markdown-editor-variable-syntax';
const matches = (re: RegExp, text: string) => [...text.matchAll(re)].map((m) => m[0]);
@@ -69,9 +69,9 @@ describe('findVariableUseRanges — block-first {{ … .Var … }} ranges (ReDoS
});
});
-describe('variableProbe — escapes the interpolated name', () => {
+describe('variableUseRegex — escapes the interpolated name', () => {
it('treats a dot in the name as literal, not any-char', () => {
- expect(variableProbe('Foo').test('.Foo')).toBe(true);
- expect(variableProbe('F.o').test('.Fxo')).toBe(false);
+ expect(variableUseRegex('Foo').test('.Foo')).toBe(true);
+ expect(variableUseRegex('F.o').test('.Fxo')).toBe(false);
});
});
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-textarea.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-textarea.ts
index 357ddd1c..9514b3d0 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-textarea.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-textarea.ts
@@ -1,6 +1,6 @@
import { findVariableUseRanges, nextVariableRange } from './markdown-editor-variable-syntax';
-export function insertTextareaText(
+export function insertAtTextareaCaret(
textarea: HTMLTextAreaElement,
text: string,
onChange: (value: string) => void,
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.ts
index a5e0adca..58629f35 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
@@ -5,7 +5,7 @@ import { Plugin, PluginKey } from '@tiptap/pm/state';
import { Decoration, DecorationSet } from '@tiptap/pm/view';
import { collectInlineMatches } from './markdown-editor-inline-scan';
-import { VARIABLE_RE, variableProbe } from './markdown-editor-variable-syntax';
+import { VARIABLE_RE, variableUseRegex } from './markdown-editor-variable-syntax';
// 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.
@@ -20,7 +20,7 @@ const buildDecorations = (doc: PMNode): DecorationSet =>
);
export const findVariableOccurrences = (doc: PMNode, variable: string): { from: number; to: number }[] => {
- const probe = variableProbe(variable);
+ const probe = variableUseRegex(variable);
return collectInlineMatches(doc, VARIABLE_RE)
.filter(({ text }) => probe.test(text))
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-variable-syntax.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-variable-syntax.ts
index e07ce576..41bdc3f2 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-variable-syntax.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-variable-syntax.ts
@@ -1,7 +1,7 @@
// Pure Go-template `{{ … }}` matching — no ProseMirror/tiptap imports, so consumers that only need the
// syntax helpers (settings-prompt's variable panel: cycle + "used" count) can pull them without dragging the
// editor (and its tiptap chunk) into their eager bundle. The DOM-facing decoration side lives in
-// markdown-editor-variable-highlight.ts, which reuses VARIABLE_RE / variableProbe from here.
+// markdown-editor-variable-highlight.ts, which reuses VARIABLE_RE / variableUseRegex from here.
// `[^{}]` keeps the scan linear (no catastrophic backtracking); Go actions never nest braces.
export const VARIABLE_RE = /\{\{[^{}]*\}\}/g;
@@ -12,10 +12,10 @@ const escapeRegExp = (value: string): string => value.replace(/[.*+?^${}()|[\]\\
// block-first — extract `{{ … }}` blocks with the linear VARIABLE_RE, THEN probe each — never a lazy
// `[^{}]*?` around the name, which backtracks O(n²) on an unclosed `{{`. Shared with settings-prompt.tsx
// (panel cycle + count) so the "used" badge and the editor cycle agree on what counts as a use.
-export const variableProbe = (variable: string): RegExp => new RegExp(`\\.${escapeRegExp(variable)}\\b`);
+export const variableUseRegex = (variable: string): RegExp => new RegExp(`\\.${escapeRegExp(variable)}\\b`);
export const findVariableUseRanges = (value: string, variable: string): { index: number; length: number }[] => {
- const probe = variableProbe(variable);
+ const probe = variableUseRegex(variable);
const ranges: { index: number; length: number }[] = [];
for (const match of value.matchAll(VARIABLE_RE)) {
diff --git a/frontend/src/pages/settings/settings-prompt.tsx b/frontend/src/pages/settings/settings-prompt.tsx
index 4e3e1c0d..ab344615 100644
--- a/frontend/src/pages/settings/settings-prompt.tsx
+++ b/frontend/src/pages/settings/settings-prompt.tsx
@@ -43,7 +43,7 @@ import {
MarkdownEditorField,
type MarkdownEditorFieldHandle,
VARIABLE_RE,
- variableProbe,
+ variableUseRegex,
} from '@/components/shared/markdown-editor';
type AgentPrompt = AgentPrompts;
@@ -109,7 +109,7 @@ type SystemFormData = z.infer<typeof systemFormSchema>;
// One pass over the `{{ … }}` blocks — the naive per-variable `.match` over the whole template is
// O(variables × length) on every keystroke.
function countVariableUses(template: string, variables: string[]): Record<string, number> {
- const probes = variables.map((variable) => [variable, variableProbe(variable)] as const);
+ const probes = variables.map((variable) => [variable, variableUseRegex(variable)] as const);
const counts: Record<string, number> = {};
for (const block of template.match(VARIABLE_RE) ?? []) {