Merge branch 'main' into posthog-event-batching
This commit is contained in:
commit
8d61b03909
13 changed files with 958 additions and 86 deletions
171
binary/package-lock.json
generated
171
binary/package-lock.json
generated
|
|
@ -64,7 +64,6 @@
|
|||
"@sentry/esbuild-plugin": "^4.0.2",
|
||||
"@sentry/node": "^9.43.0",
|
||||
"@sentry/vite-plugin": "^4.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
||||
"@xenova/transformers": "2.14.0",
|
||||
"adf-to-md": "^1.1.0",
|
||||
"async-mutex": "^0.5.0",
|
||||
|
|
@ -144,6 +143,8 @@
|
|||
"@types/tar": "^6.1.13",
|
||||
"@types/uuid": "^9.0.7",
|
||||
"@types/win-ca": "^3.5.4",
|
||||
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
||||
"@typescript-eslint/parser": "^8.40.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"esbuild": "0.17.19",
|
||||
"eslint": "^8",
|
||||
|
|
@ -2895,6 +2896,19 @@
|
|||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/callsites": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
|
||||
|
|
@ -3368,6 +3382,20 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/eastasianwidth": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||
|
|
@ -3416,6 +3444,51 @@
|
|||
"is-arrayish": "^0.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-errors": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-set-tostringtag": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
||||
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"get-intrinsic": "^1.2.6",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"hasown": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.19.11",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.11.tgz",
|
||||
|
|
@ -3695,12 +3768,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
|
|
@ -3773,7 +3849,6 @@
|
|||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||
"dev": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
|
|
@ -3796,6 +3871,30 @@
|
|||
"node": "6.* || 8.* || >= 10.*"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-package-type": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz",
|
||||
|
|
@ -3805,6 +3904,19 @@
|
|||
"node": ">=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/get-stream": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
|
||||
|
|
@ -3886,6 +3998,18 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
|
|
@ -3909,11 +4033,37 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-tostringtag": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
||||
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"has-symbols": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/hasown": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
||||
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
|
|
@ -5184,6 +5334,15 @@
|
|||
"tmpl": "1.0.5"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-stream": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||
|
|
|
|||
108
extensions/cli/src/services/ResourceMonitoringService.test.ts
Normal file
108
extensions/cli/src/services/ResourceMonitoringService.test.ts
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { ResourceMonitoringService } from "./ResourceMonitoringService.js";
|
||||
|
||||
// Mock the logger and BaseService
|
||||
vi.mock("../util/logger.js", () => ({
|
||||
logger: {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("./BaseService.js", () => ({
|
||||
BaseService: class MockBaseService {
|
||||
logger = {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
describe("ResourceMonitoringService", () => {
|
||||
let service: ResourceMonitoringService;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Remove process event listeners to prevent interference
|
||||
process.removeAllListeners("exit");
|
||||
process.removeAllListeners("SIGINT");
|
||||
process.removeAllListeners("SIGTERM");
|
||||
|
||||
service = new ResourceMonitoringService();
|
||||
await service.initialize();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (service) {
|
||||
service.stopMonitoring(); // Ensure monitoring is stopped
|
||||
await service.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("should initialize without starting monitoring by default", () => {
|
||||
expect(service).toBeDefined();
|
||||
// Should not be monitoring unless --verbose is passed
|
||||
const usage = service.getCurrentResourceUsage();
|
||||
expect(usage.timestamp).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("should collect current resource usage", () => {
|
||||
const usage = service.getCurrentResourceUsage();
|
||||
|
||||
expect(usage.timestamp).toBeGreaterThan(0);
|
||||
expect(usage.memory.rss).toBeGreaterThan(0);
|
||||
expect(usage.memory.heapTotal).toBeGreaterThan(0);
|
||||
expect(usage.memory.heapUsed).toBeGreaterThan(0);
|
||||
expect(usage.cpu.user).toBeGreaterThanOrEqual(0);
|
||||
expect(usage.cpu.system).toBeGreaterThanOrEqual(0);
|
||||
expect(usage.system.uptime).toBeGreaterThan(0);
|
||||
expect(usage.system.totalMemory).toBeGreaterThan(0);
|
||||
expect(usage.eventLoop.lag).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it("should provide resource summary", () => {
|
||||
const summary = service.getResourceSummary();
|
||||
|
||||
expect(summary.current).toBeDefined();
|
||||
expect(summary.peak).toBeDefined();
|
||||
expect(summary.average).toBeDefined();
|
||||
|
||||
expect(summary.peak.memory).toBeGreaterThan(0);
|
||||
expect(summary.peak.cpu).toBeGreaterThanOrEqual(0);
|
||||
|
||||
expect(summary.average.memory).toBeGreaterThan(0);
|
||||
expect(summary.average.cpu).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it("should start and stop monitoring", async () => {
|
||||
service.startMonitoring(100); // 100ms interval for test
|
||||
|
||||
// Wait for some data collection
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
|
||||
const history = service.getResourceHistory();
|
||||
expect(history.length).toBeGreaterThan(0);
|
||||
|
||||
service.stopMonitoring();
|
||||
});
|
||||
|
||||
it("should handle verbose mode initialization", async () => {
|
||||
// Mock argv to include --verbose
|
||||
const originalArgv = process.argv;
|
||||
process.argv = [...originalArgv, "--verbose"];
|
||||
|
||||
const verboseService = new ResourceMonitoringService();
|
||||
await verboseService.initialize();
|
||||
|
||||
// Should start monitoring automatically
|
||||
// Note: Testing this properly would require checking internal state
|
||||
// which isn't directly exposed
|
||||
|
||||
await verboseService.cleanup();
|
||||
process.argv = originalArgv;
|
||||
});
|
||||
});
|
||||
312
extensions/cli/src/services/ResourceMonitoringService.ts
Normal file
312
extensions/cli/src/services/ResourceMonitoringService.ts
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
import { exec } from "child_process";
|
||||
import * as os from "os";
|
||||
import { promisify } from "util";
|
||||
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
export interface ResourceUsage {
|
||||
timestamp: number;
|
||||
memory: {
|
||||
rss: number; // Resident Set Size
|
||||
heapTotal: number;
|
||||
heapUsed: number;
|
||||
external: number;
|
||||
arrayBuffers: number;
|
||||
};
|
||||
cpu: {
|
||||
user: number;
|
||||
system: number;
|
||||
percent?: number; // CPU percentage (calculated)
|
||||
};
|
||||
system: {
|
||||
loadAverage: number[];
|
||||
uptime: number;
|
||||
freeMemory: number;
|
||||
totalMemory: number;
|
||||
};
|
||||
eventLoop: {
|
||||
lag: number;
|
||||
};
|
||||
fileDescriptors?: number;
|
||||
}
|
||||
|
||||
export interface ResourceMonitoringState {
|
||||
isMonitoring: boolean;
|
||||
resourceHistory: ResourceUsage[];
|
||||
}
|
||||
|
||||
class ResourceMonitoringService {
|
||||
private isMonitoring = false;
|
||||
private monitoringInterval?: NodeJS.Timeout;
|
||||
private intervalMs = 1000; // Default 1 second
|
||||
private resourceHistory: ResourceUsage[] = [];
|
||||
private maxHistorySize = 300; // Keep 5 minutes at 1s intervals
|
||||
private lastCpuUsage = process.cpuUsage();
|
||||
private lastTimestamp = Date.now();
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
// Start monitoring if verbose mode is enabled
|
||||
if (process.argv.includes("--verbose")) {
|
||||
this.startMonitoring();
|
||||
}
|
||||
|
||||
// Cleanup on exit
|
||||
process.on("exit", () => this.cleanup());
|
||||
process.on("SIGINT", () => this.cleanup());
|
||||
process.on("SIGTERM", () => this.cleanup());
|
||||
}
|
||||
|
||||
async cleanup(): Promise<void> {
|
||||
this.stopMonitoring();
|
||||
}
|
||||
|
||||
public startMonitoring(intervalMs = 1000): void {
|
||||
if (this.isMonitoring) return;
|
||||
|
||||
this.intervalMs = intervalMs;
|
||||
this.isMonitoring = true;
|
||||
this.lastCpuUsage = process.cpuUsage();
|
||||
this.lastTimestamp = Date.now();
|
||||
|
||||
this.monitoringInterval = setInterval(() => {
|
||||
this.collectResourceUsage();
|
||||
}, this.intervalMs);
|
||||
|
||||
logger.debug("Resource monitoring started", { intervalMs });
|
||||
}
|
||||
|
||||
public stopMonitoring(): void {
|
||||
if (!this.isMonitoring) return;
|
||||
|
||||
this.isMonitoring = false;
|
||||
if (this.monitoringInterval) {
|
||||
clearInterval(this.monitoringInterval);
|
||||
this.monitoringInterval = undefined;
|
||||
}
|
||||
|
||||
logger.debug("Resource monitoring stopped");
|
||||
}
|
||||
|
||||
public getCurrentResourceUsage(): ResourceUsage {
|
||||
const now = Date.now();
|
||||
const currentCpuUsage = process.cpuUsage();
|
||||
const timeDiff = now - this.lastTimestamp;
|
||||
|
||||
// Calculate CPU percentage
|
||||
const userDiff = currentCpuUsage.user - this.lastCpuUsage.user;
|
||||
const systemDiff = currentCpuUsage.system - this.lastCpuUsage.system;
|
||||
const totalDiff = userDiff + systemDiff;
|
||||
const cpuPercent = timeDiff > 0 ? (totalDiff / (timeDiff * 1000)) * 100 : 0;
|
||||
|
||||
const memoryUsage = process.memoryUsage();
|
||||
|
||||
const usage: ResourceUsage = {
|
||||
timestamp: now,
|
||||
memory: {
|
||||
rss: memoryUsage.rss,
|
||||
heapTotal: memoryUsage.heapTotal,
|
||||
heapUsed: memoryUsage.heapUsed,
|
||||
external: memoryUsage.external,
|
||||
arrayBuffers: memoryUsage.arrayBuffers,
|
||||
},
|
||||
cpu: {
|
||||
user: currentCpuUsage.user,
|
||||
system: currentCpuUsage.system,
|
||||
percent: Math.min(cpuPercent, 100), // Cap at 100%
|
||||
},
|
||||
system: {
|
||||
loadAverage: this.getLoadAverage(),
|
||||
uptime: this.getProcessUptime(),
|
||||
freeMemory: this.getFreeMemory(),
|
||||
totalMemory: this.getTotalMemory(),
|
||||
},
|
||||
eventLoop: {
|
||||
lag: this.measureEventLoopLag(),
|
||||
},
|
||||
};
|
||||
|
||||
// Try to get file descriptor count (Unix only)
|
||||
this.getFileDescriptorCount()
|
||||
.then((count) => {
|
||||
if (count !== null) {
|
||||
usage.fileDescriptors = count;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Ignore errors for file descriptor counting
|
||||
});
|
||||
|
||||
return usage;
|
||||
}
|
||||
|
||||
public getResourceHistory(): ResourceUsage[] {
|
||||
return [...this.resourceHistory];
|
||||
}
|
||||
|
||||
public getResourceSummary(): {
|
||||
current: ResourceUsage;
|
||||
peak: {
|
||||
memory: number;
|
||||
cpu: number;
|
||||
};
|
||||
average: {
|
||||
memory: number;
|
||||
cpu: number;
|
||||
};
|
||||
} {
|
||||
const current = this.getCurrentResourceUsage();
|
||||
|
||||
if (this.resourceHistory.length === 0) {
|
||||
return {
|
||||
current,
|
||||
peak: {
|
||||
memory: current.memory.rss,
|
||||
cpu: current.cpu.percent || 0,
|
||||
},
|
||||
average: {
|
||||
memory: current.memory.rss,
|
||||
cpu: current.cpu.percent || 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const peakMemory = Math.max(
|
||||
...this.resourceHistory.map((r) => r.memory.rss),
|
||||
);
|
||||
const peakCpu = Math.max(
|
||||
...this.resourceHistory.map((r) => r.cpu.percent || 0),
|
||||
);
|
||||
|
||||
const avgMemory =
|
||||
this.resourceHistory.reduce((sum, r) => sum + r.memory.rss, 0) /
|
||||
this.resourceHistory.length;
|
||||
const avgCpu =
|
||||
this.resourceHistory.reduce((sum, r) => sum + (r.cpu.percent || 0), 0) /
|
||||
this.resourceHistory.length;
|
||||
|
||||
return {
|
||||
current,
|
||||
peak: {
|
||||
memory: Math.max(peakMemory, current.memory.rss),
|
||||
cpu: Math.max(peakCpu, current.cpu.percent || 0),
|
||||
},
|
||||
average: {
|
||||
memory: avgMemory,
|
||||
cpu: avgCpu,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private collectResourceUsage(): void {
|
||||
try {
|
||||
const usage = this.getCurrentResourceUsage();
|
||||
|
||||
// Update for next CPU calculation
|
||||
this.lastCpuUsage = process.cpuUsage();
|
||||
this.lastTimestamp = usage.timestamp;
|
||||
|
||||
// Add to history
|
||||
this.resourceHistory.push(usage);
|
||||
|
||||
// Trim history if too large
|
||||
if (this.resourceHistory.length > this.maxHistorySize) {
|
||||
this.resourceHistory = this.resourceHistory.slice(-this.maxHistorySize);
|
||||
}
|
||||
|
||||
// Check for potential issues and log warnings
|
||||
this.checkResourceThresholds(usage);
|
||||
} catch (error) {
|
||||
logger.error("Error collecting resource usage", error);
|
||||
}
|
||||
}
|
||||
|
||||
private checkResourceThresholds(usage: ResourceUsage): void {
|
||||
const memoryUsageMB = usage.memory.rss / 1024 / 1024;
|
||||
const cpuPercent = usage.cpu.percent || 0;
|
||||
|
||||
// Memory threshold: 500MB
|
||||
if (memoryUsageMB > 500) {
|
||||
logger.warn("High memory usage detected", {
|
||||
memoryMB: Math.round(memoryUsageMB),
|
||||
threshold: 500,
|
||||
});
|
||||
}
|
||||
|
||||
// CPU threshold: 80%
|
||||
if (cpuPercent > 80) {
|
||||
logger.warn("High CPU usage detected", {
|
||||
cpuPercent: Math.round(cpuPercent),
|
||||
threshold: 80,
|
||||
});
|
||||
}
|
||||
|
||||
// Event loop lag threshold: 100ms
|
||||
if (usage.eventLoop.lag > 100) {
|
||||
logger.warn("High event loop lag detected", {
|
||||
lagMs: Math.round(usage.eventLoop.lag),
|
||||
threshold: 100,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async getFileDescriptorCount(): Promise<number | null> {
|
||||
if (process.platform === "win32") {
|
||||
return null; // Not supported on Windows
|
||||
}
|
||||
|
||||
try {
|
||||
const { stdout } = await execAsync(`lsof -p ${process.pid} | wc -l`);
|
||||
return parseInt(stdout.trim(), 10) - 1; // Subtract 1 for header line
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private getLoadAverage(): number[] {
|
||||
try {
|
||||
return process.platform === "win32" ? [0, 0, 0] : os.loadavg();
|
||||
} catch {
|
||||
return [0, 0, 0];
|
||||
}
|
||||
}
|
||||
|
||||
private getProcessUptime(): number {
|
||||
try {
|
||||
return typeof process.uptime === "function" ? process.uptime() : 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private getFreeMemory(): number {
|
||||
try {
|
||||
return os.freemem();
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private getTotalMemory(): number {
|
||||
try {
|
||||
return os.totalmem();
|
||||
} catch {
|
||||
return 1024 * 1024 * 1024; // 1GB default fallback
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronous approximation of event loop lag
|
||||
private measureEventLoopLag(): number {
|
||||
// Return a simple approximation based on load average on Unix systems
|
||||
const loadAvg = this.getLoadAverage();
|
||||
if (loadAvg[0] > 0) {
|
||||
// Rough approximation: higher load = higher lag
|
||||
return Math.min(loadAvg[0] * 10, 200); // Cap at 200ms
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export { ResourceMonitoringService };
|
||||
|
|
@ -9,6 +9,7 @@ import { FileIndexService } from "./FileIndexService.js";
|
|||
import { MCPService } from "./MCPService.js";
|
||||
import { ModelService } from "./ModelService.js";
|
||||
import { modeService } from "./ModeService.js";
|
||||
import { ResourceMonitoringService } from "./ResourceMonitoringService.js";
|
||||
import { serviceContainer } from "./ServiceContainer.js";
|
||||
import {
|
||||
ApiClientServiceState,
|
||||
|
|
@ -26,6 +27,7 @@ const modelService = new ModelService();
|
|||
const apiClientService = new ApiClientService();
|
||||
const mcpService = new MCPService();
|
||||
const fileIndexService = new FileIndexService();
|
||||
const resourceMonitoringService = new ResourceMonitoringService();
|
||||
|
||||
/**
|
||||
* Initialize all services and register them with the service container
|
||||
|
|
@ -219,6 +221,12 @@ export async function initializeServices(
|
|||
[],
|
||||
);
|
||||
|
||||
serviceContainer.register(
|
||||
SERVICE_NAMES.RESOURCE_MONITORING,
|
||||
() => resourceMonitoringService.initialize(),
|
||||
[],
|
||||
);
|
||||
|
||||
// Eagerly initialize all services to ensure they're ready when needed
|
||||
// This avoids race conditions and "service not ready" errors
|
||||
await serviceContainer.initializeAll();
|
||||
|
|
@ -261,6 +269,7 @@ export function areServicesReady(): boolean {
|
|||
SERVICE_NAMES.MODEL,
|
||||
SERVICE_NAMES.MCP,
|
||||
SERVICE_NAMES.FILE_INDEX,
|
||||
SERVICE_NAMES.RESOURCE_MONITORING,
|
||||
].every((name) => serviceContainer.isReady(name));
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +291,7 @@ export const services = {
|
|||
mcp: mcpService,
|
||||
fileIndex: fileIndexService,
|
||||
mode: modeService,
|
||||
resourceMonitoring: resourceMonitoringService,
|
||||
} as const;
|
||||
|
||||
// Export the service container for advanced usage
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ export const SERVICE_NAMES = {
|
|||
API_CLIENT: "apiClient",
|
||||
TOOL_PERMISSIONS: "toolPermissions",
|
||||
FILE_INDEX: "fileIndex",
|
||||
RESOURCE_MONITORING: "resourceMonitoring",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ export function SessionSelector({
|
|||
if (displaySessions[selectedIndex]) {
|
||||
onSelect(displaySessions[selectedIndex].id);
|
||||
}
|
||||
} else if (key.escape || (key.ctrl && input === "c")) {
|
||||
} else if (key.escape || (key.ctrl && input === "d")) {
|
||||
onExit();
|
||||
}
|
||||
});
|
||||
|
|
@ -73,7 +73,7 @@ export function SessionSelector({
|
|||
<Box flexDirection="column" padding={1}>
|
||||
<Text color="yellow">No previous sessions found.</Text>
|
||||
<Text color="gray">Start a new conversation with: cn</Text>
|
||||
<Text color="gray">Press ESC to exit</Text>
|
||||
<Text color="gray">Press ESC or Ctrl+D to exit</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ export function SessionSelector({
|
|||
Recent Sessions
|
||||
</Text>
|
||||
<Text color="gray">
|
||||
Use ↑↓ arrows to navigate, Enter to select, ESC to exit
|
||||
Use ↑↓ arrows to navigate, Enter to select, ESC or Ctrl+D to exit
|
||||
</Text>
|
||||
<Text> </Text>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
import { Box, Text } from "ink";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { useServices } from "../hooks/useService.js";
|
||||
import {
|
||||
|
|
@ -9,8 +15,10 @@ import {
|
|||
MCPServiceState,
|
||||
ModelServiceState,
|
||||
} from "../services/types.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
import { BottomStatusBar } from "./components/BottomStatusBar.js";
|
||||
import { ResourceDebugBar } from "./components/ResourceDebugBar.js";
|
||||
import { ScreenContent } from "./components/ScreenContent.js";
|
||||
import { StaticChatContent } from "./components/StaticChatContent.js";
|
||||
import { useNavigation } from "./context/NavigationContext.js";
|
||||
|
|
@ -39,6 +47,103 @@ interface TUIChatProps {
|
|||
additionalPrompts?: string[];
|
||||
}
|
||||
|
||||
// Helper function to load and set session
|
||||
async function loadAndSetSession(
|
||||
sessionId: string,
|
||||
closeCurrentScreen: () => void,
|
||||
setChatHistory: (history: any) => void,
|
||||
setMessages: (messages: any) => void,
|
||||
setShowIntroMessage: (show: boolean) => void,
|
||||
) {
|
||||
try {
|
||||
// Close the session selector
|
||||
closeCurrentScreen();
|
||||
|
||||
// Import session functions
|
||||
const { loadSessionById } = await import("../session.js");
|
||||
|
||||
// Load the session history
|
||||
const sessionHistory = loadSessionById(sessionId);
|
||||
if (!sessionHistory) {
|
||||
logger.error(`Session ${sessionId} could not be loaded.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the session ID so future operations use this session
|
||||
process.env.CONTINUE_CLI_TEST_SESSION_ID = sessionId.replace(
|
||||
"continue-cli-",
|
||||
"",
|
||||
);
|
||||
|
||||
// Directly set the chat history and messages to the loaded session
|
||||
setChatHistory(sessionHistory);
|
||||
|
||||
// Convert chat history to display messages (exclude system messages)
|
||||
const displayMessages = sessionHistory
|
||||
.filter((msg: any) => msg.role !== "system")
|
||||
.map((msg: any) => ({
|
||||
role: msg.role,
|
||||
content: msg.content as string,
|
||||
}));
|
||||
|
||||
setMessages(displayMessages);
|
||||
|
||||
// Clear the intro message since we're now showing a resumed session
|
||||
setShowIntroMessage(false);
|
||||
} catch (error) {
|
||||
console.error("Error loading session:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom hook to manage services
|
||||
function useTUIChatServices(remoteUrl?: string) {
|
||||
const isRemoteMode = useMemo(() => !!remoteUrl, [remoteUrl]);
|
||||
|
||||
const { services, allReady: allServicesReady } = useServices<{
|
||||
auth: AuthServiceState;
|
||||
config: ConfigServiceState;
|
||||
model: ModelServiceState;
|
||||
mcp: MCPServiceState;
|
||||
apiClient: ApiClientServiceState;
|
||||
}>(["auth", "config", "model", "mcp", "apiClient"]);
|
||||
|
||||
return { services, allServicesReady, isRemoteMode };
|
||||
}
|
||||
|
||||
// Custom hook for chat handlers
|
||||
function useChatHandlers(
|
||||
setShowIntroMessage: (show: boolean) => void,
|
||||
setStaticRefreshTrigger: React.Dispatch<React.SetStateAction<number>>,
|
||||
) {
|
||||
// Temporary refs to avoid circular dependency
|
||||
const resetChatHistoryRef = useRef<(() => void) | null>(null);
|
||||
|
||||
// Handle clearing chat and resetting intro message
|
||||
const handleClear = useCallback(() => {
|
||||
setShowIntroMessage(true);
|
||||
// Trigger static content refresh by incrementing the trigger
|
||||
setStaticRefreshTrigger((prev) => prev + 1);
|
||||
}, [setShowIntroMessage, setStaticRefreshTrigger]);
|
||||
|
||||
// Service reload handlers - these will trigger reactive updates
|
||||
const handleReload = useCallback(async () => {
|
||||
// Services will automatically update the UI when they reload
|
||||
// We just need to reset chat history, intro message, and clear the screen
|
||||
if (resetChatHistoryRef.current) {
|
||||
resetChatHistoryRef.current();
|
||||
}
|
||||
setShowIntroMessage(false);
|
||||
process.stdout.write("\x1b[2J\x1b[H");
|
||||
}, [setShowIntroMessage]);
|
||||
|
||||
return {
|
||||
handleClear,
|
||||
handleReload,
|
||||
resetChatHistoryRef,
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
const TUIChat: React.FC<TUIChatProps> = ({
|
||||
remoteUrl,
|
||||
configPath,
|
||||
|
|
@ -47,22 +152,12 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
additionalRules,
|
||||
additionalPrompts,
|
||||
}) => {
|
||||
// Check if we're in remote mode
|
||||
const isRemoteMode = useMemo(() => {
|
||||
return !!remoteUrl;
|
||||
}, [remoteUrl]);
|
||||
// Use custom hook for services
|
||||
const { services, allServicesReady, isRemoteMode } =
|
||||
useTUIChatServices(remoteUrl);
|
||||
|
||||
const repoURlText = useMemo(() => getRepoUrlText(remoteUrl), [remoteUrl]);
|
||||
|
||||
// Get all services reactively - only in normal mode
|
||||
const { services, allReady: allServicesReady } = useServices<{
|
||||
auth: AuthServiceState;
|
||||
config: ConfigServiceState;
|
||||
model: ModelServiceState;
|
||||
mcp: MCPServiceState;
|
||||
apiClient: ApiClientServiceState;
|
||||
}>(["auth", "config", "model", "mcp", "apiClient"]);
|
||||
|
||||
// Use navigation context
|
||||
const {
|
||||
state: navState,
|
||||
|
|
@ -88,24 +183,14 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
closeCurrentScreen,
|
||||
);
|
||||
|
||||
// Service reload handlers - these will trigger reactive updates
|
||||
const handleReload = async () => {
|
||||
// Services will automatically update the UI when they reload
|
||||
// We just need to reset chat history, intro message, and clear the screen
|
||||
resetChatHistory();
|
||||
setShowIntroMessage(false);
|
||||
process.stdout.write("\x1b[2J\x1b[H");
|
||||
};
|
||||
|
||||
// State to trigger static content refresh for /clear command
|
||||
const [staticRefreshTrigger, setStaticRefreshTrigger] = useState(0);
|
||||
|
||||
// Handle clearing chat and resetting intro message
|
||||
const handleClear = () => {
|
||||
setShowIntroMessage(true);
|
||||
// Trigger static content refresh by incrementing the trigger
|
||||
setStaticRefreshTrigger((prev) => prev + 1);
|
||||
};
|
||||
// Use chat handlers hook
|
||||
const { handleClear, handleReload, resetChatHistoryRef } = useChatHandlers(
|
||||
setShowIntroMessage,
|
||||
setStaticRefreshTrigger,
|
||||
);
|
||||
|
||||
const {
|
||||
messages,
|
||||
|
|
@ -141,6 +226,11 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
remoteUrl,
|
||||
});
|
||||
|
||||
// Update ref after useChat returns
|
||||
useEffect(() => {
|
||||
resetChatHistoryRef.current = resetChatHistory;
|
||||
}, [resetChatHistory]);
|
||||
|
||||
// Calculate context percentage
|
||||
const contextData = useContextPercentage({
|
||||
chatHistory,
|
||||
|
|
@ -156,52 +246,27 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
);
|
||||
|
||||
// Session selection handler
|
||||
const handleSessionSelect = async (sessionId: string) => {
|
||||
try {
|
||||
// Close the session selector
|
||||
closeCurrentScreen();
|
||||
|
||||
// Import session functions
|
||||
const { loadSessionById } = await import("../session.js");
|
||||
|
||||
// Load the session history
|
||||
const sessionHistory = loadSessionById(sessionId);
|
||||
if (!sessionHistory) {
|
||||
console.error(`Session ${sessionId} could not be loaded.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the session ID so future operations use this session
|
||||
process.env.CONTINUE_CLI_TEST_SESSION_ID = sessionId.replace(
|
||||
"continue-cli-",
|
||||
"",
|
||||
const handleSessionSelect = useCallback(
|
||||
async (sessionId: string) => {
|
||||
await loadAndSetSession(
|
||||
sessionId,
|
||||
closeCurrentScreen,
|
||||
setChatHistory,
|
||||
setMessages,
|
||||
setShowIntroMessage,
|
||||
);
|
||||
|
||||
// Directly set the chat history and messages to the loaded session
|
||||
setChatHistory(sessionHistory);
|
||||
|
||||
// Convert chat history to display messages (exclude system messages)
|
||||
const displayMessages = sessionHistory
|
||||
.filter((msg) => msg.role !== "system")
|
||||
.map((msg) => ({
|
||||
role: msg.role,
|
||||
content: msg.content as string,
|
||||
}));
|
||||
|
||||
setMessages(displayMessages);
|
||||
|
||||
// Clear the intro message since we're now showing a resumed session
|
||||
setShowIntroMessage(false);
|
||||
} catch (error) {
|
||||
console.error("Error loading session:", error);
|
||||
}
|
||||
};
|
||||
},
|
||||
[closeCurrentScreen, setChatHistory, setMessages, setShowIntroMessage],
|
||||
);
|
||||
|
||||
// Determine if input should be disabled
|
||||
// Allow input even when services are loading, but disable for UI overlays
|
||||
const isInputDisabled =
|
||||
navState.currentScreen !== "chat" || !!activePermissionRequest;
|
||||
|
||||
// Check if verbose mode is enabled for resource debugging
|
||||
const isVerboseMode = useMemo(() => process.argv.includes("--verbose"), []);
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" height="100%">
|
||||
{/* Chat history - takes up all available space above input */}
|
||||
|
|
@ -268,6 +333,11 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
isRemoteMode={isRemoteMode}
|
||||
/>
|
||||
|
||||
{/* Resource debug bar - only in verbose mode */}
|
||||
{isVerboseMode && !isRemoteMode && (
|
||||
<ResourceDebugBar visible={navState.currentScreen === "chat"} />
|
||||
)}
|
||||
|
||||
{/* Free trial status and Continue CLI info - always show */}
|
||||
<BottomStatusBar
|
||||
currentMode={currentMode}
|
||||
|
|
|
|||
|
|
@ -412,6 +412,16 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
return false;
|
||||
};
|
||||
|
||||
// Clear input function
|
||||
const clearInput = () => {
|
||||
textBuffer.clear();
|
||||
setInputText("");
|
||||
setCursorPosition(0);
|
||||
setShowSlashCommands(false);
|
||||
setShowFileSearch(false);
|
||||
inputHistory.resetNavigation();
|
||||
};
|
||||
|
||||
useInput((input, key) => {
|
||||
// Don't handle any input when disabled
|
||||
if (disabled) {
|
||||
|
|
@ -427,6 +437,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
showSlashCommands,
|
||||
showFileSearch,
|
||||
cycleModes,
|
||||
clearInput,
|
||||
})
|
||||
) {
|
||||
return;
|
||||
|
|
|
|||
184
extensions/cli/src/ui/components/ResourceDebugBar.tsx
Normal file
184
extensions/cli/src/ui/components/ResourceDebugBar.tsx
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
import { Box, Text } from "ink";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { services } from "../../services/index.js";
|
||||
import { ResourceUsage } from "../../services/ResourceMonitoringService.js";
|
||||
|
||||
interface ResourceDebugBarProps {
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
const mb = bytes / 1024 / 1024;
|
||||
return mb >= 1 ? `${mb.toFixed(1)}MB` : `${(bytes / 1024).toFixed(1)}KB`;
|
||||
}
|
||||
|
||||
function formatPercent(percent: number): string {
|
||||
return `${Math.round(percent)}%`;
|
||||
}
|
||||
|
||||
function formatTime(ms: number): string {
|
||||
if (ms < 1000) return `${Math.round(ms)}ms`;
|
||||
return `${(ms / 1000).toFixed(1)}s`;
|
||||
}
|
||||
|
||||
export function ResourceDebugBar({ visible }: ResourceDebugBarProps) {
|
||||
const [resourceData, setResourceData] = useState<ResourceUsage | null>(null);
|
||||
const [isError, setIsError] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!visible) return;
|
||||
|
||||
const updateResourceData = () => {
|
||||
try {
|
||||
const usage = services.resourceMonitoring.getCurrentResourceUsage();
|
||||
setResourceData(usage);
|
||||
setIsError(false);
|
||||
} catch {
|
||||
setIsError(true);
|
||||
}
|
||||
};
|
||||
|
||||
// Initial update
|
||||
updateResourceData();
|
||||
|
||||
// Update every 2 seconds
|
||||
const intervalId = setInterval(updateResourceData, 2000);
|
||||
|
||||
return () => {
|
||||
clearInterval(intervalId);
|
||||
};
|
||||
}, [visible]);
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<Box paddingX={1}>
|
||||
<Text color="red">Resource monitoring error</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (!resourceData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const memoryPercent =
|
||||
(resourceData.memory.rss / resourceData.system.totalMemory) * 100;
|
||||
const cpuPercent = resourceData.cpu.percent || 0;
|
||||
const heapPercent =
|
||||
(resourceData.memory.heapUsed / resourceData.memory.heapTotal) * 100;
|
||||
|
||||
// Color coding based on usage levels
|
||||
const getMemoryColor = () => {
|
||||
if (memoryPercent > 80) return "red";
|
||||
if (memoryPercent > 60) return "yellow";
|
||||
return "green";
|
||||
};
|
||||
|
||||
const getCpuColor = () => {
|
||||
if (cpuPercent > 80) return "red";
|
||||
if (cpuPercent > 60) return "yellow";
|
||||
return "green";
|
||||
};
|
||||
|
||||
const getEventLoopColor = () => {
|
||||
if (resourceData.eventLoop.lag > 100) return "red";
|
||||
if (resourceData.eventLoop.lag > 50) return "yellow";
|
||||
return "green";
|
||||
};
|
||||
|
||||
return (
|
||||
<Box paddingX={1}>
|
||||
<Text color="gray">Debug: </Text>
|
||||
|
||||
<Text color={getMemoryColor()}>
|
||||
MEM: {formatBytes(resourceData.memory.rss)}
|
||||
</Text>
|
||||
<Text color="gray"> | </Text>
|
||||
|
||||
<Text color="gray">HEAP: {formatPercent(heapPercent)}</Text>
|
||||
<Text color="gray"> | </Text>
|
||||
|
||||
<Text color={getCpuColor()}>CPU: {formatPercent(cpuPercent)}</Text>
|
||||
<Text color="gray"> | </Text>
|
||||
|
||||
<Text color={getEventLoopColor()}>
|
||||
LAG: {formatTime(resourceData.eventLoop.lag)}
|
||||
</Text>
|
||||
|
||||
{resourceData.fileDescriptors && (
|
||||
<>
|
||||
<Text color="gray"> | </Text>
|
||||
<Text color="gray">FD: {resourceData.fileDescriptors}</Text>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Text color="gray"> | </Text>
|
||||
<Text color="gray">
|
||||
UP: {formatTime(resourceData.system.uptime * 1000)}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export function ResourceDebugDetails({ visible }: { visible: boolean }) {
|
||||
const [summary, setSummary] = useState<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!visible) return;
|
||||
|
||||
const updateData = () => {
|
||||
try {
|
||||
const summaryData = services.resourceMonitoring.getResourceSummary();
|
||||
setSummary(summaryData);
|
||||
} catch {
|
||||
// Handle error silently
|
||||
}
|
||||
};
|
||||
|
||||
updateData();
|
||||
const intervalId = setInterval(updateData, 3000);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [visible]);
|
||||
|
||||
if (!visible || !summary) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
flexDirection="column"
|
||||
borderStyle="single"
|
||||
borderColor="gray"
|
||||
paddingX={1}
|
||||
marginTop={1}
|
||||
>
|
||||
<Text color="cyan" bold>
|
||||
Resource Usage Summary
|
||||
</Text>
|
||||
|
||||
<Box marginTop={1}>
|
||||
<Text color="gray">Current: </Text>
|
||||
<Text>{formatBytes(summary.current.memory.rss)} mem, </Text>
|
||||
<Text>{formatPercent(summary.current.cpu.percent || 0)} cpu</Text>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Text color="gray">Peak: </Text>
|
||||
<Text>{formatBytes(summary.peak.memory)} mem, </Text>
|
||||
<Text>{formatPercent(summary.peak.cpu)} cpu</Text>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Text color="gray">Average: </Text>
|
||||
<Text>{formatBytes(summary.average.memory)} mem, </Text>
|
||||
<Text>{formatPercent(summary.average.cpu)} cpu</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,14 +9,28 @@ interface ControlKeysOptions {
|
|||
showSlashCommands: boolean;
|
||||
showFileSearch: boolean;
|
||||
cycleModes: () => Promise<PermissionMode>;
|
||||
clearInput?: () => void;
|
||||
}
|
||||
|
||||
export function handleControlKeys(options: ControlKeysOptions): boolean {
|
||||
const { input, key, exit, showSlashCommands, showFileSearch, cycleModes } =
|
||||
options;
|
||||
const {
|
||||
input,
|
||||
key,
|
||||
exit,
|
||||
showSlashCommands,
|
||||
showFileSearch,
|
||||
cycleModes,
|
||||
clearInput,
|
||||
} = options;
|
||||
|
||||
// Handle Ctrl+C and Ctrl+D
|
||||
if (key.ctrl && (input === "c" || input === "d")) {
|
||||
// Handle Ctrl+C to clear input
|
||||
if (key.ctrl && input === "c" && clearInput) {
|
||||
clearInput();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle Ctrl+D to exit
|
||||
if (key.ctrl && input === "d") {
|
||||
exit();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"name": "wt-small-improvements",
|
||||
"name": "wt-plan-mode-sys-prompt",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
|
|
|
|||
11
packages/continue-sdk/typescript/package-lock.json
generated
11
packages/continue-sdk/typescript/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@continuedev/sdk",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@continuedev/sdk",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"openai": "^4.96.2"
|
||||
|
|
@ -1963,14 +1963,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
|
||||
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"es-set-tostringtag": "^2.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
|||
1
packages/openai-adapters/package-lock.json
generated
1
packages/openai-adapters/package-lock.json
generated
|
|
@ -12528,6 +12528,7 @@
|
|||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
|
||||
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue