Skip to content

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

feat: update terminal

Sergey Kozyrenkofe9ba1a89eb3
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index e45e168c..c34934a4 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -32,12 +32,12 @@
"@radix-ui/react-tooltip": "^1.1.3",
"@react-pdf/renderer": "^4.3.2",
"@tanstack/react-table": "^8.21.3",
- "@xterm/addon-fit": "^0.10.0",
- "@xterm/addon-search": "^0.15.0",
- "@xterm/addon-unicode11": "^0.8.0",
- "@xterm/addon-web-links": "^0.11.0",
- "@xterm/addon-webgl": "^0.18.0",
- "@xterm/xterm": "^5.5.0",
+ "@xterm/addon-fit": "^0.11.0",
+ "@xterm/addon-search": "^0.16.0",
+ "@xterm/addon-unicode11": "^0.9.0",
+ "@xterm/addon-web-links": "^0.12.0",
+ "@xterm/addon-webgl": "^0.19.0",
+ "@xterm/xterm": "^6.0.0",
"anser": "^2.3.5",
"axios": "^1.13.5",
"class-variance-authority": "^0.7.0",
@@ -214,7 +214,6 @@
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@babel/code-frame": "^7.27.1",
"@babel/generator": "^7.28.5",
@@ -5779,7 +5778,6 @@
"integrity": "sha512-xpr/lmLPQEj+TUnHmR+Ab91/glhJvsqcjB+yY0Ix9GO70H6Lb4FHH5GeqdOE5btAx7eIMwuHkp4H2MSkLcqWbA==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"undici-types": "~6.21.0"
}
@@ -5808,7 +5806,6 @@
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.2.tgz",
"integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==",
"license": "MIT",
- "peer": true,
"dependencies": {
"csstype": "^3.0.2"
}
@@ -5819,7 +5816,6 @@
"integrity": "sha512-9KQPoO6mZCi7jcIStSnlOWn2nEF3mNmyr3rIAsGnAbQKYbRLyqmeSc39EVgtxXVia+LMT8j3knZLAZAh+xLmrw==",
"devOptional": true,
"license": "MIT",
- "peer": true,
"peerDependencies": {
"@types/react": "^19.2.0"
}
@@ -5899,7 +5895,6 @@
"integrity": "sha512-tK3GPFWbirvNgsNKto+UmB/cRtn6TZfyw0D6IKrW55n6Vbs7KJoZtI//kpTKzE/DUmmnAFD8/Ca46s7Obs92/w==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "8.46.4",
"@typescript-eslint/types": "8.46.4",
@@ -6394,56 +6389,43 @@
}
},
"node_modules/@xterm/addon-fit": {
- "version": "0.10.0",
- "resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.10.0.tgz",
- "integrity": "sha512-UFYkDm4HUahf2lnEyHvio51TNGiLK66mqP2JoATy7hRZeXaGMRDr00JiSF7m63vR5WKATF605yEggJKsw0JpMQ==",
- "license": "MIT",
- "peerDependencies": {
- "@xterm/xterm": "^5.0.0"
- }
+ "version": "0.11.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.11.0.tgz",
+ "integrity": "sha512-jYcgT6xtVYhnhgxh3QgYDnnNMYTcf8ElbxxFzX0IZo+vabQqSPAjC3c1wJrKB5E19VwQei89QCiZZP86DCPF7g==",
+ "license": "MIT"
},
"node_modules/@xterm/addon-search": {
- "version": "0.15.0",
- "resolved": "https://registry.npmjs.org/@xterm/addon-search/-/addon-search-0.15.0.tgz",
- "integrity": "sha512-ZBZKLQ+EuKE83CqCmSSz5y1tx+aNOCUaA7dm6emgOX+8J9H1FWXZyrKfzjwzV+V14TV3xToz1goIeRhXBS5qjg==",
- "license": "MIT",
- "peerDependencies": {
- "@xterm/xterm": "^5.0.0"
- }
+ "version": "0.16.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-search/-/addon-search-0.16.0.tgz",
+ "integrity": "sha512-9OeuBFu0/uZJPu+9AHKY6g/w0Czyb/Ut0A5t79I4ULoU4IfU5BEpPFVGQxP4zTTMdfZEYkVIRYbHBX1xWwjeSA==",
+ "license": "MIT"
},
"node_modules/@xterm/addon-unicode11": {
- "version": "0.8.0",
- "resolved": "https://registry.npmjs.org/@xterm/addon-unicode11/-/addon-unicode11-0.8.0.tgz",
- "integrity": "sha512-LxinXu8SC4OmVa6FhgwsVCBZbr8WoSGzBl2+vqe8WcQ6hb1r6Gj9P99qTNdPiFPh4Ceiu2pC8xukZ6+2nnh49Q==",
- "license": "MIT",
- "peerDependencies": {
- "@xterm/xterm": "^5.0.0"
- }
+ "version": "0.9.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-unicode11/-/addon-unicode11-0.9.0.tgz",
+ "integrity": "sha512-FxDnYcyuXhNl+XSqGZL/t0U9eiNb/q3EWT5rYkQT/zuig8Gz/VagnQANKHdDWFM2lTMk9ly0EFQxxxtZUoRetw==",
+ "license": "MIT"
},
"node_modules/@xterm/addon-web-links": {
- "version": "0.11.0",
- "resolved": "https://registry.npmjs.org/@xterm/addon-web-links/-/addon-web-links-0.11.0.tgz",
- "integrity": "sha512-nIHQ38pQI+a5kXnRaTgwqSHnX7KE6+4SVoceompgHL26unAxdfP6IPqUTSYPQgSwM56hsElfoNrrW5V7BUED/Q==",
- "license": "MIT",
- "peerDependencies": {
- "@xterm/xterm": "^5.0.0"
- }
+ "version": "0.12.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-web-links/-/addon-web-links-0.12.0.tgz",
+ "integrity": "sha512-4Smom3RPyVp7ZMYOYDoC/9eGJJJqYhnPLGGqJ6wOBfB8VxPViJNSKdgRYb8NpaM6YSelEKbA2SStD7lGyqaobw==",
+ "license": "MIT"
},
"node_modules/@xterm/addon-webgl": {
- "version": "0.18.0",
- "resolved": "https://registry.npmjs.org/@xterm/addon-webgl/-/addon-webgl-0.18.0.tgz",
- "integrity": "sha512-xCnfMBTI+/HKPdRnSOHaJDRqEpq2Ugy8LEj9GiY4J3zJObo3joylIFaMvzBwbYRg8zLtkO0KQaStCeSfoaI2/w==",
- "license": "MIT",
- "peerDependencies": {
- "@xterm/xterm": "^5.0.0"
- }
+ "version": "0.19.0",
+ "resolved": "https://registry.npmjs.org/@xterm/addon-webgl/-/addon-webgl-0.19.0.tgz",
+ "integrity": "sha512-b3fMOsyLVuCeNJWxolACEUED0vm7qC0cy4wRvf3oURSzDTYVQiGPhTnhWZwIHdvC48Y+oLhvYXnY4XDXPoJo6A==",
+ "license": "MIT"
},
"node_modules/@xterm/xterm": {
- "version": "5.5.0",
- "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
- "integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==",
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-6.0.0.tgz",
+ "integrity": "sha512-TQwDdQGtwwDt+2cgKDLn0IRaSxYu1tSUjgKarSDkUM0ZNiSRXFpjxEsvc/Zgc5kq5omJ+V0a8/kIM2WD3sMOYg==",
"license": "MIT",
- "peer": true
+ "workspaces": [
+ "addons/*"
+ ]
},
"node_modules/abs-svg-path": {
"version": "0.1.1",
@@ -6457,7 +6439,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
- "peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -7079,7 +7060,6 @@
}
],
"license": "MIT",
- "peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.8.19",
"caniuse-lite": "^1.0.30001751",
@@ -7758,7 +7738,6 @@
"integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"env-paths": "^2.2.1",
"import-fresh": "^3.3.0",
@@ -8848,7 +8827,6 @@
"integrity": "sha512-BhHmn2yNOFA9H9JmmIVKJmd288g9hrVRDkdoIgRCRuSySRUHH7r/DI6aAXW9T1WwUuY3DFgrcaqB+deURBLR5g==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.8.0",
"@eslint-community/regexpp": "^4.12.1",
@@ -9989,7 +9967,6 @@
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.12.0.tgz",
"integrity": "sha512-DKKrynuQRne0PNpEbzuEdHlYOMksHSUI8Zc9Unei5gTsMNA2/vMpoMz/yKba50pejK56qj98qM0SjYxAKi13gQ==",
"license": "MIT",
- "peer": true,
"engines": {
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
}
@@ -10123,7 +10100,6 @@
"resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-6.0.6.tgz",
"integrity": "sha512-zgfER9s+ftkGKUZgc0xbx8T7/HMO4AV5/YuYiFc+AtgcO5T0v8AxYYNQ+ltzuzDZgNkYJaFspm5MMYLjQzrkmw==",
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=20"
},
@@ -13697,7 +13673,6 @@
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.55.1.tgz",
"integrity": "sha512-jz4x+TJNFHwHtwuV9vA9rMujcZRb0CEilTEwG2rRSpe/A7Jdkuj8xPKttCgOh+v/lkHy7HsZ64oj+q3xoAFl9A==",
"license": "MIT",
- "peer": true,
"dependencies": {
"dompurify": "3.2.7",
"marked": "14.0.0"
@@ -14379,7 +14354,6 @@
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=12"
},
@@ -14475,7 +14449,6 @@
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
"dev": true,
"license": "MIT",
- "peer": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
@@ -14647,7 +14620,6 @@
"resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz",
"integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==",
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=0.10.0"
}
@@ -14698,7 +14670,6 @@
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.0.tgz",
"integrity": "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ==",
"license": "MIT",
- "peer": true,
"dependencies": {
"scheduler": "^0.27.0"
},
@@ -14711,7 +14682,6 @@
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.66.0.tgz",
"integrity": "sha512-xXBqsWGKrY46ZqaHDo+ZUYiMUgi8suYu5kdrS20EG8KiL7VRQitEbNjm+UcrDYrNi1YLyfpmAeGjCZYXLT9YBw==",
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=18.0.0"
},
@@ -14727,8 +14697,7 @@
"version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==",
- "license": "MIT",
- "peer": true
+ "license": "MIT"
},
"node_modules/react-markdown": {
"version": "10.1.0",
@@ -14762,7 +14731,6 @@
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz",
"integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==",
"license": "MIT",
- "peer": true,
"dependencies": {
"@types/use-sync-external-store": "^0.0.6",
"use-sync-external-store": "^1.4.0"
@@ -14964,8 +14932,7 @@
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==",
- "license": "MIT",
- "peer": true
+ "license": "MIT"
},
"node_modules/redux-thunk": {
"version": "3.1.0",
@@ -16256,8 +16223,7 @@
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.18.tgz",
"integrity": "sha512-4+Z+0yiYyEtUVCScyfHCxOYP06L5Ne+JiHhY2IjR2KWMIWhJOYZKLSGZaP5HkZ8+bY0cxfzwDE5uOmzFXyIwxw==",
"dev": true,
- "license": "MIT",
- "peer": true
+ "license": "MIT"
},
"node_modules/tapable": {
"version": "2.3.0",
@@ -16509,7 +16475,6 @@
"integrity": "sha512-ytQKuwgmrrkDTFP4LjR0ToE2nqgy886GpvRSpU0JAnrdBYppuY5rLkRUYPU1yCryb24SsKBTL/hlDQAEFVwtZg==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"esbuild": "~0.25.0",
"get-tsconfig": "^4.7.5"
@@ -16643,7 +16608,6 @@
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true,
"license": "Apache-2.0",
- "peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -17127,7 +17091,6 @@
"integrity": "sha512-BxAKBWmIbrDgrokdGZH1IgkIk/5mMHDreLDmCJ0qpyJaAteP8NvMhkwr/ZCQNqNH97bw/dANTE9PDzqwJghfMQ==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"esbuild": "^0.25.0",
"fdir": "^6.5.0",
@@ -17268,7 +17231,6 @@
"integrity": "sha512-urzu3NCEV0Qa0Y2PwvBtRgmNtxhj5t5ULw7cuKhIHh3OrkKTLlut0lnBOv9qe5OvbkMH2g38G7KPDCTpIytBVg==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@vitest/expect": "4.0.8",
"@vitest/mocker": "4.0.8",
@@ -17559,7 +17521,6 @@
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
"devOptional": true,
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=10.0.0"
},
@@ -17681,7 +17642,6 @@
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
"license": "MIT",
- "peer": true,
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
diff --git a/frontend/package.json b/frontend/package.json
index 26ef9cc6..3bcad1eb 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -42,12 +42,12 @@
"@radix-ui/react-tooltip": "^1.1.3",
"@react-pdf/renderer": "^4.3.2",
"@tanstack/react-table": "^8.21.3",
- "@xterm/addon-fit": "^0.10.0",
- "@xterm/addon-search": "^0.15.0",
- "@xterm/addon-unicode11": "^0.8.0",
- "@xterm/addon-web-links": "^0.11.0",
- "@xterm/addon-webgl": "^0.18.0",
- "@xterm/xterm": "^5.5.0",
+ "@xterm/addon-fit": "^0.11.0",
+ "@xterm/addon-search": "^0.16.0",
+ "@xterm/addon-unicode11": "^0.9.0",
+ "@xterm/addon-web-links": "^0.12.0",
+ "@xterm/addon-webgl": "^0.19.0",
+ "@xterm/xterm": "^6.0.0",
"anser": "^2.3.5",
"axios": "^1.13.5",
"class-variance-authority": "^0.7.0",
diff --git a/frontend/src/components/shared/terminal.tsx b/frontend/src/components/shared/terminal.tsx
index dd162163..a6911eea 100644
--- a/frontend/src/components/shared/terminal.tsx
+++ b/frontend/src/components/shared/terminal.tsx
@@ -9,7 +9,7 @@ import { WebLinksAddon } from '@xterm/addon-web-links';
import { WebglAddon } from '@xterm/addon-webgl';
import { Terminal as XTerminal } from '@xterm/xterm';
import debounce from 'lodash/debounce';
-import { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
+import { useCallback, useEffect, useImperativeHandle, useReducer, useRef } from 'react';
import { useTheme } from '@/hooks/use-theme';
import { Log } from '@/lib/log';
@@ -231,7 +231,6 @@ const terminalOptions: ITerminalOptions = {
cursorBlink: false,
customGlyphs: true,
disableStdin: true,
- fastScrollModifier: 'alt',
fastScrollSensitivity: 10,
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
fontSize: 12,
@@ -305,6 +304,11 @@ const lightTheme: ITheme = {
yellow: '#eab308',
} as const;
+const processLog = (log: string): string =>
+ needsSanitization(log) ? sanitizeTerminalOutput(log) : log;
+
+type TerminalLifecycle = 'idle' | 'opened' | 'ready';
+
interface TerminalProps {
className?: string;
logs: string[];
@@ -328,12 +332,14 @@ const Terminal = ({
const searchAddonRef = useRef<null | SearchAddon>(null);
const lastLogIndexRef = useRef<number>(0);
const webglAddonRef = useRef<null | WebglAddon>(null);
+ const unicodeAddonRef = useRef<null | Unicode11Addon>(null);
+ const webLinksAddonRef = useRef<null | WebLinksAddon>(null);
+ const contextLossDisposableRef = useRef<null | { dispose: () => void }>(null);
const resizeObserverRef = useRef<null | ResizeObserver>(null);
const debouncedFitRef = useRef<null | ReturnType<typeof debounce>>(null);
const { theme } = useTheme();
- const [isTerminalOpened, setIsTerminalOpened] = useState(false);
- const [isTerminalReady, setIsTerminalReady] = useState(false);
- const isTerminalReadyRef = useRef(false);
+ const [lifecycle, setLifecycle] = useReducer((_: TerminalLifecycle, next: TerminalLifecycle) => next, 'idle');
+ const lifecycleRef = useRef<TerminalLifecycle>('idle');
const prevLogsLengthRef = useRef<number>(0);
const terminalInitializedRef = useRef(false);
const isMountedRef = useRef(true);
@@ -473,10 +479,12 @@ const Terminal = ({
terminal.loadAddon(searchAddon);
const unicodeAddon = new Unicode11Addon();
+ unicodeAddonRef.current = unicodeAddon;
terminal.loadAddon(unicodeAddon);
terminal.unicode.activeVersion = '11';
const webLinksAddon = new WebLinksAddon();
+ webLinksAddonRef.current = webLinksAddon;
terminal.loadAddon(webLinksAddon);
// Add WebGL addon last (and optionally)
@@ -484,7 +492,7 @@ const Terminal = ({
const webglAddon = new WebglAddon();
webglAddonRef.current = webglAddon;
terminal.loadAddon(webglAddon);
- webglAddon.onContextLoss(() => {
+ contextLossDisposableRef.current = webglAddon.onContextLoss(() => {
if (isMountedRef.current && webglAddonRef.current) {
webglAddonRef.current.dispose();
}
@@ -495,7 +503,7 @@ const Terminal = ({
// Set up resize handler
const debouncedFit = debounce(() => {
- if (isMountedRef.current && isTerminalReadyRef.current) {
+ if (isMountedRef.current && lifecycleRef.current === 'ready') {
safeFit();
}
}, 150);
@@ -503,7 +511,7 @@ const Terminal = ({
debouncedFitRef.current = debouncedFit;
const resizeObserver = new ResizeObserver(() => {
- if (isMountedRef.current && isTerminalReadyRef.current) {
+ if (isMountedRef.current && lifecycleRef.current === 'ready') {
debouncedFit();
}
});
@@ -519,7 +527,8 @@ const Terminal = ({
try {
terminal.open(terminalRef.current);
- setIsTerminalOpened(true);
+ lifecycleRef.current = 'opened';
+ setLifecycle('opened');
// Observe size changes only after successful terminal opening
if (terminalRef.current && resizeObserverRef.current) {
@@ -530,9 +539,8 @@ const Terminal = ({
fitTimeoutRef.current = setTimeout(() => {
if (isMountedRef.current) {
safeFit();
- // Mark terminal as fully ready only after successful fit()
- isTerminalReadyRef.current = true;
- setIsTerminalReady(true);
+ lifecycleRef.current = 'ready';
+ setLifecycle('ready');
}
}, 200);
} catch (error: unknown) {
@@ -562,6 +570,26 @@ const Terminal = ({
debouncedFitRef.current = null;
}
+ if (unicodeAddonRef.current) {
+ try {
+ unicodeAddonRef.current.dispose();
+ } catch {
+ // Ignore errors during disposal
+ }
+
+ unicodeAddonRef.current = null;
+ }
+
+ if (webLinksAddonRef.current) {
+ try {
+ webLinksAddonRef.current.dispose();
+ } catch {
+ // Ignore errors during disposal
+ }
+
+ webLinksAddonRef.current = null;
+ }
+
if (searchAddonRef.current) {
try {
searchAddonRef.current.dispose();
@@ -572,6 +600,16 @@ const Terminal = ({
searchAddonRef.current = null;
}
+ if (contextLossDisposableRef.current) {
+ try {
+ contextLossDisposableRef.current.dispose();
+ } catch {
+ // Ignore errors during disposal
+ }
+
+ contextLossDisposableRef.current = null;
+ }
+
if (webglAddonRef.current) {
try {
webglAddonRef.current.dispose();
@@ -605,9 +643,8 @@ const Terminal = ({
lastLogIndexRef.current = 0;
prevLogsLengthRef.current = 0;
terminalInitializedRef.current = false;
- setIsTerminalOpened(false);
- isTerminalReadyRef.current = false;
- setIsTerminalReady(false);
+ lifecycleRef.current = 'idle';
+ setLifecycle('idle');
};
} catch (error: unknown) {
Log.error('Terminal initialization failed:', error);
@@ -615,11 +652,12 @@ const Terminal = ({
return;
}
- }, [isDarkTheme]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
// Handle search functionality with decorations
useEffect(() => {
- if (!searchAddonRef.current || !isTerminalReady || !isMountedRef.current) {
+ if (!searchAddonRef.current || lifecycle !== 'ready' || !isMountedRef.current) {
return;
}
@@ -641,7 +679,7 @@ const Terminal = ({
} catch (error: unknown) {
Log.error('Terminal search failed:', error);
}
- }, [searchValue, isTerminalReady, getSearchDecorations]);
+ }, [searchValue, lifecycle, getSearchDecorations]);
// Update theme and listen to system theme changes
useEffect(() => {
@@ -674,7 +712,7 @@ const Terminal = ({
// Update logs only when terminal is fully ready
useEffect(() => {
- if (!isMountedRef.current || !xtermRef.current || !isTerminalOpened || !isTerminalReady) {
+ if (!isMountedRef.current || !xtermRef.current || lifecycle !== 'ready') {
return;
}
@@ -702,14 +740,11 @@ const Terminal = ({
return;
}
- // Add logs in batch for performance optimization
safeTerminalOperation(() => {
- for (const log of newLogs.filter(Boolean)) {
- terminal.writeln(needsSanitization(log) ? sanitizeTerminalOutput(log) : log);
- }
+ const batch = newLogs.filter(Boolean).map(processLog).join('\r\n');
- // Scroll down only once after adding all logs
- if (newLogs.length > 0) {
+ if (batch) {
+ terminal.write(batch + '\r\n');
terminal.scrollToBottom();
}
});
@@ -717,13 +752,13 @@ const Terminal = ({
lastLogIndexRef.current = logs.length;
prevLogsLengthRef.current = logs.length;
} else {
- // If logs were reset (became fewer)
safeTerminalOperation(() => {
terminal.clear();
- // Add all logs in batch again
- for (const log of logs.filter(Boolean)) {
- terminal.writeln(needsSanitization(log) ? sanitizeTerminalOutput(log) : log);
+ const batch = logs.filter(Boolean).map(processLog).join('\r\n');
+
+ if (batch) {
+ terminal.write(batch + '\r\n');
}
terminal.scrollToBottom();
@@ -735,12 +770,13 @@ const Terminal = ({
} catch (error) {
Log.error('Terminal log update failed:', error);
}
- }, [logs, isTerminalOpened, isTerminalReady]);
+ }, [logs, lifecycle]);
return (
<div
className={cn('overflow-hidden', className)}
ref={terminalRef}
+ style={{ contain: 'strict' }}
/>
);
};
diff --git a/frontend/src/features/flows/terminal/flow-terminal.tsx b/frontend/src/features/flows/terminal/flow-terminal.tsx
index 2324d51b..43710e64 100644
--- a/frontend/src/features/flows/terminal/flow-terminal.tsx
+++ b/frontend/src/features/flows/terminal/flow-terminal.tsx
@@ -11,6 +11,7 @@ import { Button } from '@/components/ui/button';
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
import { Form, FormControl, FormField } from '@/components/ui/form';
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';
+import { cn } from '@/lib/utils';
import { useFlow } from '@/providers/flow-provider';
import FlowTasksDropdown from '../flow-tasks-dropdown';
@@ -227,14 +228,13 @@ const FlowTerminal = () => {
</div>
</Form>
</div>
- {hasLogs ? (
- <Terminal
- className="w-full grow"
- logs={filteredLogs}
- ref={terminalRef}
- searchValue={debouncedSearchValue}
- />
- ) : hasActiveFilters ? (
+ <Terminal
+ className={cn('w-full grow', hasActiveFilters && !hasLogs && 'hidden')}
+ logs={filteredLogs}
+ ref={terminalRef}
+ searchValue={debouncedSearchValue}
+ />
+ {hasActiveFilters && !hasLogs && (
<Empty>
<EmptyHeader>
<EmptyMedia variant="icon">
@@ -253,13 +253,6 @@ const FlowTerminal = () => {
</Button>
</EmptyContent>
</Empty>
- ) : (
- <Terminal
- className="w-full grow"
- logs={filteredLogs}
- ref={terminalRef}
- searchValue={debouncedSearchValue}
- />
)}
</div>
);