Skip to content

Commit 40bb413

Browse files
committed
style: fix biome lint/format on RPC files
1 parent db8acb1 commit 40bb413

5 files changed

Lines changed: 54 additions & 69 deletions

File tree

packages/plugin/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import { startDreamScheduleTimer } from "./plugin/dream-timer";
1515
import { createEventHandler } from "./plugin/event";
1616
import { createSessionHooks } from "./plugin/hooks/create-session-hooks";
1717
import { createMessagesTransformHandler } from "./plugin/messages-transform";
18-
import { createToolRegistry } from "./plugin/tool-registry";
1918
import { registerRpcHandlers } from "./plugin/rpc-handlers";
19+
import { createToolRegistry } from "./plugin/tool-registry";
2020
import { type ConflictResult, detectConflicts } from "./shared/conflict-detector";
2121
import { getOpenCodeStorageDir } from "./shared/data-path";
22-
import { MagicContextRpcServer } from "./shared/rpc-server";
2322
import { log } from "./shared/logger";
2423
import { getAgentFallbackModels } from "./shared/model-requirements";
24+
import { MagicContextRpcServer } from "./shared/rpc-server";
2525

2626
const plugin: Plugin = async (ctx) => {
2727
const pluginConfig = loadPluginConfig(ctx.directory);

packages/plugin/src/plugin/rpc-handlers.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55
import type { Database } from "bun:sqlite";
66
import type { MagicContextConfig } from "../config/schema/magic-context";
7+
import { resolveProjectIdentity } from "../features/magic-context/memory/project-identity";
78
import { openDatabase } from "../features/magic-context/storage";
9+
import { log } from "../shared/logger";
810
import { drainNotifications } from "../shared/rpc-notifications";
911
import type { MagicContextRpcServer } from "../shared/rpc-server";
1012
import type { SidebarSnapshot, StatusDetail } from "../shared/rpc-types";
11-
import { log } from "../shared/logger";
12-
import { resolveProjectIdentity } from "../features/magic-context/memory/project-identity";
1313

1414
function getDb(): Database | null {
1515
try {
@@ -57,11 +57,7 @@ function resolveConfigValue<T>(
5757
return defaultValue;
5858
}
5959

60-
function buildSidebarSnapshot(
61-
db: Database,
62-
sessionId: string,
63-
directory: string,
64-
): SidebarSnapshot {
60+
function buildSidebarSnapshot(db: Database, sessionId: string, directory: string): SidebarSnapshot {
6561
const empty: SidebarSnapshot = {
6662
sessionId,
6763
usagePercentage: 0,
@@ -471,9 +467,7 @@ export function registerRpcHandlers(
471467
const sessionId = String(params.sessionId ?? "");
472468
if (!sessionId) return { ok: false, error: "no session" };
473469

474-
const { executeContextRecomp } = await import(
475-
"../hooks/magic-context/compartment-runner"
476-
);
470+
const { executeContextRecomp } = await import("../hooks/magic-context/compartment-runner");
477471
const { sendIgnoredMessage } = await import(
478472
"../hooks/magic-context/send-session-notification"
479473
);

packages/plugin/src/shared/rpc-client.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ export class MagicContextRpcClient {
2424
throw new Error("Magic Context RPC server not available");
2525
}
2626

27-
const response = await this.fetchWithTimeout(
28-
`http://127.0.0.1:${port}/rpc/${method}`,
29-
{
30-
method: "POST",
31-
headers: { "Content-Type": "application/json" },
32-
body: JSON.stringify(params),
33-
},
34-
);
27+
const response = await this.fetchWithTimeout(`http://127.0.0.1:${port}/rpc/${method}`, {
28+
method: "POST",
29+
headers: { "Content-Type": "application/json" },
30+
body: JSON.stringify(params),
31+
});
3532

3633
if (!response.ok) {
3734
const text = await response.text();
@@ -100,10 +97,9 @@ export class MagicContextRpcClient {
10097

10198
private async healthCheck(port: number): Promise<boolean> {
10299
try {
103-
const response = await this.fetchWithTimeout(
104-
`http://127.0.0.1:${port}/health`,
105-
{ method: "GET" },
106-
);
100+
const response = await this.fetchWithTimeout(`http://127.0.0.1:${port}/health`, {
101+
method: "GET",
102+
});
107103
return response.ok;
108104
} catch {
109105
return false;

packages/plugin/src/shared/rpc-server.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { mkdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
2-
import {
3-
createServer,
4-
type IncomingMessage,
5-
type Server,
6-
type ServerResponse,
7-
} from "node:http";
2+
import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
83
import { dirname } from "node:path";
94
import { log } from "./logger";
105
import { rpcPortFilePath } from "./rpc-utils";

packages/plugin/src/tui/data/context-db.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
* TUI data layer — pure RPC client, no direct SQLite access.
33
* All data is fetched from the server plugin via HTTP RPC.
44
*/
5-
import os from "node:os"
6-
import path from "node:path"
7-
import { MagicContextRpcClient } from "../../shared/rpc-client"
8-
import type { SidebarSnapshot, StatusDetail, RpcNotificationMessage } from "../../shared/rpc-types"
5+
import os from "node:os";
6+
import path from "node:path";
7+
import { MagicContextRpcClient } from "../../shared/rpc-client";
8+
import type { RpcNotificationMessage, SidebarSnapshot, StatusDetail } from "../../shared/rpc-types";
99

10-
export type { SidebarSnapshot, StatusDetail }
10+
export type { SidebarSnapshot, StatusDetail };
1111

12-
let rpcClient: MagicContextRpcClient | null = null
12+
let rpcClient: MagicContextRpcClient | null = null;
1313

1414
function getStorageDir(): string {
15-
const dataDir = process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share")
16-
return path.join(dataDir, "opencode", "storage", "plugin", "magic-context")
15+
const dataDir = process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
16+
return path.join(dataDir, "opencode", "storage", "plugin", "magic-context");
1717
}
1818

1919
/** Initialize the RPC client. Call once on TUI startup. */
2020
export function initRpcClient(directory: string): void {
21-
const storageDir = getStorageDir()
22-
rpcClient = new MagicContextRpcClient(storageDir, directory)
21+
const storageDir = getStorageDir();
22+
rpcClient = new MagicContextRpcClient(storageDir, directory);
2323
}
2424

2525
/** Clean up the RPC client. */
2626
export function closeRpc(): void {
27-
rpcClient?.reset()
28-
rpcClient = null
27+
rpcClient?.reset();
28+
rpcClient = null;
2929
}
3030

3131
const EMPTY_SNAPSHOT: SidebarSnapshot = {
@@ -48,25 +48,25 @@ const EMPTY_SNAPSHOT: SidebarSnapshot = {
4848
compartmentTokens: 0,
4949
factTokens: 0,
5050
memoryTokens: 0,
51-
}
51+
};
5252

5353
/** Fetch sidebar snapshot from the server via RPC. */
5454
export async function loadSidebarSnapshot(
5555
sessionId: string,
5656
directory: string,
5757
): Promise<SidebarSnapshot> {
58-
if (!rpcClient) return { ...EMPTY_SNAPSHOT, sessionId }
58+
if (!rpcClient) return { ...EMPTY_SNAPSHOT, sessionId };
5959
try {
6060
const result = await rpcClient.call<SidebarSnapshot>("sidebar-snapshot", {
6161
sessionId,
6262
directory,
63-
})
63+
});
6464
if ((result as unknown as Record<string, unknown>).error) {
65-
return { ...EMPTY_SNAPSHOT, sessionId }
65+
return { ...EMPTY_SNAPSHOT, sessionId };
6666
}
67-
return result
67+
return result;
6868
} catch {
69-
return { ...EMPTY_SNAPSHOT, sessionId }
69+
return { ...EMPTY_SNAPSHOT, sessionId };
7070
}
7171
}
7272

@@ -102,65 +102,65 @@ export async function loadStatusDetail(
102102
historyBlockTokens: 0,
103103
compressionBudget: null,
104104
compressionUsage: null,
105-
}
105+
};
106106

107-
if (!rpcClient) return emptyDetail
107+
if (!rpcClient) return emptyDetail;
108108
try {
109109
const result = await rpcClient.call<StatusDetail>("status-detail", {
110110
sessionId,
111111
directory,
112112
modelKey,
113-
})
113+
});
114114
if ((result as unknown as Record<string, unknown>).error) {
115-
return emptyDetail
115+
return emptyDetail;
116116
}
117-
return result
117+
return result;
118118
} catch {
119-
return emptyDetail
119+
return emptyDetail;
120120
}
121121
}
122122

123123
/** Get compartment count via RPC. */
124124
export async function getCompartmentCount(sessionId: string): Promise<number> {
125-
if (!rpcClient) return 0
125+
if (!rpcClient) return 0;
126126
try {
127-
const result = await rpcClient.call<{ count: number }>("compartment-count", { sessionId })
128-
return result.count ?? 0
127+
const result = await rpcClient.call<{ count: number }>("compartment-count", { sessionId });
128+
return result.count ?? 0;
129129
} catch {
130-
return 0
130+
return 0;
131131
}
132132
}
133133

134134
/** Send recomp request to server via RPC. */
135135
export async function requestRecomp(sessionId: string): Promise<boolean> {
136-
if (!rpcClient) return false
136+
if (!rpcClient) return false;
137137
try {
138-
const result = await rpcClient.call<{ ok: boolean }>("recomp", { sessionId })
139-
return result.ok ?? false
138+
const result = await rpcClient.call<{ ok: boolean }>("recomp", { sessionId });
139+
return result.ok ?? false;
140140
} catch {
141-
return false
141+
return false;
142142
}
143143
}
144144

145145
export interface TuiMessage {
146-
type: string
147-
payload: Record<string, unknown>
148-
sessionId?: string
146+
type: string;
147+
payload: Record<string, unknown>;
148+
sessionId?: string;
149149
}
150150

151151
/** Poll for pending server→TUI notifications via RPC. */
152152
export async function consumeTuiMessages(): Promise<TuiMessage[]> {
153-
if (!rpcClient) return []
153+
if (!rpcClient) return [];
154154
try {
155155
const result = await rpcClient.call<{ messages: RpcNotificationMessage[] }>(
156156
"pending-notifications",
157-
)
157+
);
158158
return (result.messages ?? []).map((m) => ({
159159
type: m.type,
160160
payload: m.payload,
161161
sessionId: m.sessionId,
162-
}))
162+
}));
163163
} catch {
164-
return []
164+
return [];
165165
}
166166
}

0 commit comments

Comments
 (0)