WIP: Large refactor checkpoint
- Refactored daemon client and RPC layer - Added new client package structure in server - Removed legacy hooks (use-daemon-request, use-session-rpc, use-websocket) - Added use-daemon-client hook - Added e2e test infrastructure with Playwright - Updated agent providers and session handling - Removed codex-sdk patches
This commit is contained in:
@@ -29,6 +29,8 @@ async function configureNativeNotifications(): Promise<void> {
|
||||
Notifications.setNotificationHandler({
|
||||
handleNotification: async () => ({
|
||||
shouldShowAlert: true,
|
||||
shouldShowBanner: true,
|
||||
shouldShowList: true,
|
||||
shouldPlaySound: false,
|
||||
shouldSetBadge: false,
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import { getNowMs, isPerfLoggingEnabled, perfLog } from "@/utils/perf";
|
||||
|
||||
const PERF_MONITOR_LOG_TAG = "[PerfMonitor]";
|
||||
const FRAME_GAP_THRESHOLD_MS = 100;
|
||||
const EVENT_LOOP_STALL_THRESHOLD_MS = 100;
|
||||
const EVENT_LOOP_TICK_MS = 100;
|
||||
const LONG_TASK_THRESHOLD_MS = 100;
|
||||
|
||||
type StopPerfMonitor = () => void;
|
||||
|
||||
type GlobalScope = typeof globalThis & {
|
||||
requestAnimationFrame?: (callback: (timestamp: number) => void) => number;
|
||||
cancelAnimationFrame?: (handle: number) => void;
|
||||
PerformanceObserver?: unknown;
|
||||
};
|
||||
|
||||
type PerfObserverEntry = {
|
||||
duration: number;
|
||||
startTime: number;
|
||||
};
|
||||
|
||||
type PerfObserverLike = {
|
||||
observe: (options: { entryTypes: string[] }) => void;
|
||||
disconnect: () => void;
|
||||
};
|
||||
|
||||
type PerfObserverConstructor = new (
|
||||
callback: (list: { getEntries(): PerfObserverEntry[] }) => void
|
||||
) => PerfObserverLike;
|
||||
|
||||
export function startPerfMonitor(scope: string): StopPerfMonitor {
|
||||
if (!isPerfLoggingEnabled()) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
const globalScope = globalThis as GlobalScope;
|
||||
if (!globalScope) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
const startMs = getNowMs();
|
||||
perfLog(PERF_MONITOR_LOG_TAG, { event: "monitor_start", scope });
|
||||
|
||||
let rafHandle: number | null = null;
|
||||
let lastFrameMs = getNowMs();
|
||||
|
||||
if (typeof globalScope.requestAnimationFrame === "function") {
|
||||
const onFrame = (now: number) => {
|
||||
const delta = now - lastFrameMs;
|
||||
if (delta >= FRAME_GAP_THRESHOLD_MS) {
|
||||
perfLog(PERF_MONITOR_LOG_TAG, {
|
||||
event: "frame_gap",
|
||||
scope,
|
||||
deltaMs: Math.round(delta),
|
||||
sinceStartMs: Math.round(now - startMs),
|
||||
});
|
||||
}
|
||||
lastFrameMs = now;
|
||||
rafHandle = globalScope.requestAnimationFrame?.(onFrame) ?? null;
|
||||
};
|
||||
rafHandle = globalScope.requestAnimationFrame(onFrame);
|
||||
}
|
||||
|
||||
let lastTickMs = getNowMs();
|
||||
const intervalHandle = setInterval(() => {
|
||||
const now = getNowMs();
|
||||
const drift = now - lastTickMs - EVENT_LOOP_TICK_MS;
|
||||
if (drift >= EVENT_LOOP_STALL_THRESHOLD_MS) {
|
||||
perfLog(PERF_MONITOR_LOG_TAG, {
|
||||
event: "event_loop_stall",
|
||||
scope,
|
||||
driftMs: Math.round(drift),
|
||||
sinceStartMs: Math.round(now - startMs),
|
||||
});
|
||||
}
|
||||
lastTickMs = now;
|
||||
}, EVENT_LOOP_TICK_MS);
|
||||
|
||||
let observer: PerfObserverLike | null = null;
|
||||
const ObserverCtor = globalScope.PerformanceObserver as PerfObserverConstructor | undefined;
|
||||
if (typeof ObserverCtor === "function") {
|
||||
try {
|
||||
observer = new ObserverCtor((list) => {
|
||||
for (const entry of list.getEntries()) {
|
||||
if (entry.duration >= LONG_TASK_THRESHOLD_MS) {
|
||||
perfLog(PERF_MONITOR_LOG_TAG, {
|
||||
event: "longtask",
|
||||
scope,
|
||||
durationMs: Math.round(entry.duration),
|
||||
startMs: Math.round(entry.startTime),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe({ entryTypes: ["longtask"] });
|
||||
} catch (error) {
|
||||
perfLog(PERF_MONITOR_LOG_TAG, {
|
||||
event: "longtask_observer_error",
|
||||
scope,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (rafHandle !== null && typeof globalScope.cancelAnimationFrame === "function") {
|
||||
globalScope.cancelAnimationFrame(rafHandle);
|
||||
}
|
||||
clearInterval(intervalHandle);
|
||||
observer?.disconnect();
|
||||
perfLog(PERF_MONITOR_LOG_TAG, { event: "monitor_stop", scope });
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
import { z } from "zod";
|
||||
import { getNowMs, isPerfLoggingEnabled, perfLog } from "./perf";
|
||||
|
||||
const TOOL_CALL_DIFF_LOG_TAG = "[ToolCallDiff]";
|
||||
const LINE_DIFF_DURATION_THRESHOLD_MS = 16;
|
||||
const WORD_DIFF_DURATION_THRESHOLD_MS = 8;
|
||||
const LINE_DIFF_MATRIX_THRESHOLD = 200000;
|
||||
const WORD_DIFF_MATRIX_THRESHOLD = 50000;
|
||||
|
||||
export type DiffSegment = {
|
||||
text: string;
|
||||
@@ -74,11 +81,14 @@ function splitIntoWords(text: string): string[] {
|
||||
}
|
||||
|
||||
function computeWordLevelDiff(oldLine: string, newLine: string): { oldSegments: DiffSegment[]; newSegments: DiffSegment[] } {
|
||||
const shouldLog = isPerfLoggingEnabled();
|
||||
const startMs = shouldLog ? getNowMs() : 0;
|
||||
const oldWords = splitIntoWords(oldLine);
|
||||
const newWords = splitIntoWords(newLine);
|
||||
|
||||
const m = oldWords.length;
|
||||
const n = newWords.length;
|
||||
const matrixSize = m * n;
|
||||
|
||||
// LCS to find common words
|
||||
const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
||||
@@ -143,13 +153,34 @@ function computeWordLevelDiff(oldLine: string, newLine: string): { oldSegments:
|
||||
return segments;
|
||||
};
|
||||
|
||||
const oldSegments = buildSegments(oldWords, oldInLCS);
|
||||
const newSegments = buildSegments(newWords, newInLCS);
|
||||
|
||||
if (shouldLog) {
|
||||
const durationMs = getNowMs() - startMs;
|
||||
if (
|
||||
durationMs >= WORD_DIFF_DURATION_THRESHOLD_MS ||
|
||||
matrixSize >= WORD_DIFF_MATRIX_THRESHOLD
|
||||
) {
|
||||
perfLog(TOOL_CALL_DIFF_LOG_TAG, {
|
||||
event: "word_diff",
|
||||
durationMs: Math.round(durationMs),
|
||||
oldWordCount: m,
|
||||
newWordCount: n,
|
||||
matrixSize,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
oldSegments: buildSegments(oldWords, oldInLCS),
|
||||
newSegments: buildSegments(newWords, newInLCS),
|
||||
oldSegments,
|
||||
newSegments,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildLineDiff(originalText: string, updatedText: string): DiffLine[] {
|
||||
const shouldLog = isPerfLoggingEnabled();
|
||||
const startMs = shouldLog ? getNowMs() : 0;
|
||||
const originalLines = splitIntoLines(originalText);
|
||||
const updatedLines = splitIntoLines(updatedText);
|
||||
|
||||
@@ -160,6 +191,7 @@ export function buildLineDiff(originalText: string, updatedText: string): DiffLi
|
||||
|
||||
const m = originalLines.length;
|
||||
const n = updatedLines.length;
|
||||
const matrixSize = m * n;
|
||||
const dp: number[][] = Array.from({ length: m + 1 }, () =>
|
||||
Array(n + 1).fill(0)
|
||||
);
|
||||
@@ -218,6 +250,23 @@ export function buildLineDiff(originalText: string, updatedText: string): DiffLi
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldLog) {
|
||||
const durationMs = getNowMs() - startMs;
|
||||
if (
|
||||
durationMs >= LINE_DIFF_DURATION_THRESHOLD_MS ||
|
||||
matrixSize >= LINE_DIFF_MATRIX_THRESHOLD
|
||||
) {
|
||||
perfLog(TOOL_CALL_DIFF_LOG_TAG, {
|
||||
event: "line_diff",
|
||||
durationMs: Math.round(durationMs),
|
||||
originalLineCount: m,
|
||||
updatedLineCount: n,
|
||||
diffLineCount: diff.length,
|
||||
matrixSize,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -1009,21 +1058,15 @@ const ReadResultSchema = z.object({
|
||||
const ReadToolCallSchema = z
|
||||
.object({
|
||||
input: ReadInputSchema,
|
||||
result: z.unknown(),
|
||||
result: ReadResultSchema,
|
||||
})
|
||||
.transform((data): { type: "read"; filePath: string; content: string; offset?: number; limit?: number } => {
|
||||
const filePath = data.input.file_path;
|
||||
const resultParsed = ReadResultSchema.safeParse(data.result);
|
||||
const content = resultParsed.success ? resultParsed.data.content : "";
|
||||
|
||||
return {
|
||||
type: "read",
|
||||
filePath,
|
||||
content,
|
||||
offset: data.input.offset,
|
||||
limit: data.input.limit,
|
||||
};
|
||||
});
|
||||
.transform((data): { type: "read"; filePath: string; content: string; offset?: number; limit?: number } => ({
|
||||
type: "read",
|
||||
filePath: data.input.file_path,
|
||||
content: data.result.content,
|
||||
offset: data.input.offset,
|
||||
limit: data.input.limit,
|
||||
}));
|
||||
|
||||
// Generic tool call display schema (fallback)
|
||||
const GenericToolCallSchema = z
|
||||
|
||||
Reference in New Issue
Block a user