Skip to content

Commit 5ceff75

Browse files
committed
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
1 parent 009b16f commit 5ceff75

1,266 files changed

Lines changed: 27863 additions & 9385 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxlintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"suspicious": "error"
88
},
99
"rules": {
10+
"curly": "error",
1011
"eslint-plugin-unicorn/prefer-array-find": "off",
1112
"eslint/no-await-in-loop": "off",
1213
"eslint/no-new": "off",

src/acp/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export type AcpClientHandle = {
2727
};
2828

2929
function toArgs(value: string[] | string | undefined): string[] {
30-
if (!value) return [];
30+
if (!value) {
31+
return [];
32+
}
3133
return Array.isArray(value) ? value : [value];
3234
}
3335

@@ -41,7 +43,9 @@ function buildServerArgs(opts: AcpClientOptions): string[] {
4143

4244
function printSessionUpdate(notification: SessionNotification): void {
4345
const update = notification.update;
44-
if (!("sessionUpdate" in update)) return;
46+
if (!("sessionUpdate" in update)) {
47+
return;
48+
}
4549

4650
switch (update.sessionUpdate) {
4751
case "agent_message_chunk": {
@@ -62,7 +66,9 @@ function printSessionUpdate(notification: SessionNotification): void {
6266
}
6367
case "available_commands_update": {
6468
const names = update.availableCommands?.map((cmd) => `/${cmd.name}`).join(" ");
65-
if (names) console.log(`\n[commands] ${names}`);
69+
if (names) {
70+
console.log(`\n[commands] ${names}`);
71+
}
6672
return;
6773
}
6874
default:

src/acp/event-mapper.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export function extractTextFromPrompt(prompt: ContentBlock[]): string {
1515
}
1616
if (block.type === "resource") {
1717
const resource = block.resource as { text?: string } | undefined;
18-
if (resource?.text) parts.push(resource.text);
18+
if (resource?.text) {
19+
parts.push(resource.text);
20+
}
1921
continue;
2022
}
2123
if (block.type === "resource_link") {
@@ -31,9 +33,13 @@ export function extractTextFromPrompt(prompt: ContentBlock[]): string {
3133
export function extractAttachmentsFromPrompt(prompt: ContentBlock[]): GatewayAttachment[] {
3234
const attachments: GatewayAttachment[] = [];
3335
for (const block of prompt) {
34-
if (block.type !== "image") continue;
36+
if (block.type !== "image") {
37+
continue;
38+
}
3539
const image = block as ImageContent;
36-
if (!image.data || !image.mimeType) continue;
40+
if (!image.data || !image.mimeType) {
41+
continue;
42+
}
3743
attachments.push({
3844
type: "image",
3945
mimeType: image.mimeType,
@@ -48,7 +54,9 @@ export function formatToolTitle(
4854
args: Record<string, unknown> | undefined,
4955
): string {
5056
const base = name ?? "tool";
51-
if (!args || Object.keys(args).length === 0) return base;
57+
if (!args || Object.keys(args).length === 0) {
58+
return base;
59+
}
5260
const parts = Object.entries(args).map(([key, value]) => {
5361
const raw = typeof value === "string" ? value : JSON.stringify(value);
5462
const safe = raw.length > 100 ? `${raw.slice(0, 100)}...` : raw;
@@ -58,16 +66,30 @@ export function formatToolTitle(
5866
}
5967

6068
export function inferToolKind(name?: string): ToolKind {
61-
if (!name) return "other";
69+
if (!name) {
70+
return "other";
71+
}
6272
const normalized = name.toLowerCase();
63-
if (normalized.includes("read")) return "read";
64-
if (normalized.includes("write") || normalized.includes("edit")) return "edit";
65-
if (normalized.includes("delete") || normalized.includes("remove")) return "delete";
66-
if (normalized.includes("move") || normalized.includes("rename")) return "move";
67-
if (normalized.includes("search") || normalized.includes("find")) return "search";
73+
if (normalized.includes("read")) {
74+
return "read";
75+
}
76+
if (normalized.includes("write") || normalized.includes("edit")) {
77+
return "edit";
78+
}
79+
if (normalized.includes("delete") || normalized.includes("remove")) {
80+
return "delete";
81+
}
82+
if (normalized.includes("move") || normalized.includes("rename")) {
83+
return "move";
84+
}
85+
if (normalized.includes("search") || normalized.includes("find")) {
86+
return "search";
87+
}
6888
if (normalized.includes("exec") || normalized.includes("run") || normalized.includes("bash")) {
6989
return "execute";
7090
}
71-
if (normalized.includes("fetch") || normalized.includes("http")) return "fetch";
91+
if (normalized.includes("fetch") || normalized.includes("http")) {
92+
return "fetch";
93+
}
7294
return "other";
7395
}

src/acp/meta.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ export function readString(
22
meta: Record<string, unknown> | null | undefined,
33
keys: string[],
44
): string | undefined {
5-
if (!meta) return undefined;
5+
if (!meta) {
6+
return undefined;
7+
}
68
for (const key of keys) {
79
const value = meta[key];
8-
if (typeof value === "string" && value.trim()) return value.trim();
10+
if (typeof value === "string" && value.trim()) {
11+
return value.trim();
12+
}
913
}
1014
return undefined;
1115
}
@@ -14,10 +18,14 @@ export function readBool(
1418
meta: Record<string, unknown> | null | undefined,
1519
keys: string[],
1620
): boolean | undefined {
17-
if (!meta) return undefined;
21+
if (!meta) {
22+
return undefined;
23+
}
1824
for (const key of keys) {
1925
const value = meta[key];
20-
if (typeof value === "boolean") return value;
26+
if (typeof value === "boolean") {
27+
return value;
28+
}
2129
}
2230
return undefined;
2331
}
@@ -26,10 +34,14 @@ export function readNumber(
2634
meta: Record<string, unknown> | null | undefined,
2735
keys: string[],
2836
): number | undefined {
29-
if (!meta) return undefined;
37+
if (!meta) {
38+
return undefined;
39+
}
3040
for (const key of keys) {
3141
const value = meta[key];
32-
if (typeof value === "number" && Number.isFinite(value)) return value;
42+
if (typeof value === "number" && Number.isFinite(value)) {
43+
return value;
44+
}
3345
}
3446
return undefined;
3547
}

src/acp/session-mapper.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export type AcpSessionMeta = {
1212
};
1313

1414
export function parseSessionMeta(meta: unknown): AcpSessionMeta {
15-
if (!meta || typeof meta !== "object") return {};
15+
if (!meta || typeof meta !== "object") {
16+
return {};
17+
}
1618
const record = meta as Record<string, unknown>;
1719
return {
1820
sessionKey: readString(record, ["sessionKey", "session", "key"]),
@@ -45,7 +47,9 @@ export async function resolveSessionKey(params: {
4547
}
4648

4749
if (params.meta.sessionKey) {
48-
if (!requireExisting) return params.meta.sessionKey;
50+
if (!requireExisting) {
51+
return params.meta.sessionKey;
52+
}
4953
const resolved = await params.gateway.request<{ ok: true; key: string }>("sessions.resolve", {
5054
key: params.meta.sessionKey,
5155
});
@@ -66,7 +70,9 @@ export async function resolveSessionKey(params: {
6670
}
6771

6872
if (requestedKey) {
69-
if (!requireExisting) return requestedKey;
73+
if (!requireExisting) {
74+
return requestedKey;
75+
}
7076
const resolved = await params.gateway.request<{ ok: true; key: string }>("sessions.resolve", {
7177
key: requestedKey,
7278
});
@@ -86,6 +92,8 @@ export async function resetSessionIfNeeded(params: {
8692
opts: AcpServerOptions;
8793
}): Promise<void> {
8894
const resetSession = params.meta.resetSession ?? params.opts.resetSession ?? false;
89-
if (!resetSession) return;
95+
if (!resetSession) {
96+
return;
97+
}
9098
await params.gateway.request("sessions.reset", { key: params.sessionKey });
9199
}

src/acp/session.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,35 @@ export function createInMemorySessionStore(): AcpSessionStore {
3939

4040
const setActiveRun: AcpSessionStore["setActiveRun"] = (sessionId, runId, abortController) => {
4141
const session = sessions.get(sessionId);
42-
if (!session) return;
42+
if (!session) {
43+
return;
44+
}
4345
session.activeRunId = runId;
4446
session.abortController = abortController;
4547
runIdToSessionId.set(runId, sessionId);
4648
};
4749

4850
const clearActiveRun: AcpSessionStore["clearActiveRun"] = (sessionId) => {
4951
const session = sessions.get(sessionId);
50-
if (!session) return;
51-
if (session.activeRunId) runIdToSessionId.delete(session.activeRunId);
52+
if (!session) {
53+
return;
54+
}
55+
if (session.activeRunId) {
56+
runIdToSessionId.delete(session.activeRunId);
57+
}
5258
session.activeRunId = null;
5359
session.abortController = null;
5460
};
5561

5662
const cancelActiveRun: AcpSessionStore["cancelActiveRun"] = (sessionId) => {
5763
const session = sessions.get(sessionId);
58-
if (!session?.abortController) return false;
64+
if (!session?.abortController) {
65+
return false;
66+
}
5967
session.abortController.abort();
60-
if (session.activeRunId) runIdToSessionId.delete(session.activeRunId);
68+
if (session.activeRunId) {
69+
runIdToSessionId.delete(session.activeRunId);
70+
}
6171
session.abortController = null;
6272
session.activeRunId = null;
6373
return true;

src/acp/translator.ts

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ export class AcpGatewayAgent implements Agent {
210210
if (!session) {
211211
throw new Error(`Session ${params.sessionId} not found`);
212212
}
213-
if (!params.modeId) return {};
213+
if (!params.modeId) {
214+
return {};
215+
}
214216
try {
215217
await this.gateway.request("sessions.patch", {
216218
key: session.sessionKey,
@@ -276,7 +278,9 @@ export class AcpGatewayAgent implements Agent {
276278

277279
async cancel(params: CancelNotification): Promise<void> {
278280
const session = this.sessionStore.getSession(params.sessionId);
279-
if (!session) return;
281+
if (!session) {
282+
return;
283+
}
280284

281285
this.sessionStore.cancelActiveRun(params.sessionId);
282286
try {
@@ -294,24 +298,38 @@ export class AcpGatewayAgent implements Agent {
294298

295299
private async handleAgentEvent(evt: EventFrame): Promise<void> {
296300
const payload = evt.payload as Record<string, unknown> | undefined;
297-
if (!payload) return;
301+
if (!payload) {
302+
return;
303+
}
298304
const stream = payload.stream as string | undefined;
299305
const data = payload.data as Record<string, unknown> | undefined;
300306
const sessionKey = payload.sessionKey as string | undefined;
301-
if (!stream || !data || !sessionKey) return;
307+
if (!stream || !data || !sessionKey) {
308+
return;
309+
}
302310

303-
if (stream !== "tool") return;
311+
if (stream !== "tool") {
312+
return;
313+
}
304314
const phase = data.phase as string | undefined;
305315
const name = data.name as string | undefined;
306316
const toolCallId = data.toolCallId as string | undefined;
307-
if (!toolCallId) return;
317+
if (!toolCallId) {
318+
return;
319+
}
308320

309321
const pending = this.findPendingBySessionKey(sessionKey);
310-
if (!pending) return;
322+
if (!pending) {
323+
return;
324+
}
311325

312326
if (phase === "start") {
313-
if (!pending.toolCalls) pending.toolCalls = new Set();
314-
if (pending.toolCalls.has(toolCallId)) return;
327+
if (!pending.toolCalls) {
328+
pending.toolCalls = new Set();
329+
}
330+
if (pending.toolCalls.has(toolCallId)) {
331+
return;
332+
}
315333
pending.toolCalls.add(toolCallId);
316334
const args = data.args as Record<string, unknown> | undefined;
317335
await this.connection.sessionUpdate({
@@ -344,17 +362,25 @@ export class AcpGatewayAgent implements Agent {
344362

345363
private async handleChatEvent(evt: EventFrame): Promise<void> {
346364
const payload = evt.payload as Record<string, unknown> | undefined;
347-
if (!payload) return;
365+
if (!payload) {
366+
return;
367+
}
348368

349369
const sessionKey = payload.sessionKey as string | undefined;
350370
const state = payload.state as string | undefined;
351371
const runId = payload.runId as string | undefined;
352372
const messageData = payload.message as Record<string, unknown> | undefined;
353-
if (!sessionKey || !state) return;
373+
if (!sessionKey || !state) {
374+
return;
375+
}
354376

355377
const pending = this.findPendingBySessionKey(sessionKey);
356-
if (!pending) return;
357-
if (runId && pending.idempotencyKey !== runId) return;
378+
if (!pending) {
379+
return;
380+
}
381+
if (runId && pending.idempotencyKey !== runId) {
382+
return;
383+
}
358384

359385
if (state === "delta" && messageData) {
360386
await this.handleDeltaEvent(pending.sessionId, messageData);
@@ -381,10 +407,14 @@ export class AcpGatewayAgent implements Agent {
381407
const content = messageData.content as Array<{ type: string; text?: string }> | undefined;
382408
const fullText = content?.find((c) => c.type === "text")?.text ?? "";
383409
const pending = this.pendingPrompts.get(sessionId);
384-
if (!pending) return;
410+
if (!pending) {
411+
return;
412+
}
385413

386414
const sentSoFar = pending.sentTextLength ?? 0;
387-
if (fullText.length <= sentSoFar) return;
415+
if (fullText.length <= sentSoFar) {
416+
return;
417+
}
388418

389419
const newText = fullText.slice(sentSoFar);
390420
pending.sentTextLength = fullText.length;
@@ -407,7 +437,9 @@ export class AcpGatewayAgent implements Agent {
407437

408438
private findPendingBySessionKey(sessionKey: string): PendingPrompt | undefined {
409439
for (const pending of this.pendingPrompts.values()) {
410-
if (pending.sessionKey === sessionKey) return pending;
440+
if (pending.sessionKey === sessionKey) {
441+
return pending;
442+
}
411443
}
412444
return undefined;
413445
}

0 commit comments

Comments
 (0)