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:
Mohamed Boudra
2026-01-12 13:30:20 +07:00
parent 7c2e959c19
commit 868f9fb571
64 changed files with 5773 additions and 4741 deletions
+59 -16
View File
@@ -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