Skip to content

Commit 4484ed3

Browse files
committed
refactor: improve type safety by replacing 'any' with specific types in multiple files
1 parent 47801d3 commit 4484ed3

14 files changed

Lines changed: 72 additions & 53 deletions

File tree

packages/syncpoint-cli/src/commands/adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as fs from "node:fs";
77
import * as path from "node:path";
88
import * as repo from "syncpoint-server/repositories";
99
import { buildAdapterInstruction, getAdapterConfig, listAdapterProviders } from "syncpoint-adapters";
10-
import type { AdapterLifecycleEvent } from "syncpoint-adapters";
10+
import type { AdapterLifecycleEvent, AgentProvider } from "syncpoint-adapters";
1111

1212
export function registerAdapterCommand(program: Command): void {
1313
program
@@ -25,7 +25,7 @@ export function registerAdapterCommand(program: Command): void {
2525
const ctx = repo.getResumeContext(opts.task, opts.agent);
2626
ctx.projectMemories = []; // P3B: no raw PM in adapter output
2727
const provider = opts.provider ?? ctx.agent.name;
28-
const instruction = buildAdapterInstruction(ctx, provider as any, opts.event as AdapterLifecycleEvent);
28+
const instruction = buildAdapterInstruction(ctx, provider as AgentProvider, opts.event as AdapterLifecycleEvent);
2929
if (!instruction.ready) {
3030
console.error("⚠ Context not ready:");
3131
for (const w of instruction.warnings) console.error(` - ${w}`);

packages/syncpoint-cli/src/commands/admin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import os from "node:os";
1111
import * as repo from "syncpoint-server/repositories";
1212
import { getDbPath, getRawDb } from "syncpoint-server";
1313
import { EventType, ResourceNotFoundError, ValidationError } from "syncpoint-kernel";
14+
import type { AgentCreate, TaskCreate } from "syncpoint-adapters";
1415
import { unlockAllGuards } from "syncpoint-server/application";
1516
import { handleError, printError } from "./error-handler.js";
1617

@@ -279,15 +280,15 @@ export function registerAdminCommands(program: Command): void {
279280
let imported = 0;
280281
for (const agent of data.agents ?? []) {
281282
try {
282-
repo.createAgent(agent as any);
283+
repo.createAgent(agent as AgentCreate);
283284
imported++;
284285
} catch { /* skip duplicates */ }
285286
}
286287

287288
// Import tasks
288289
for (const task of data.tasks ?? []) {
289290
try {
290-
repo.createTask(task as any);
291+
repo.createTask(task as TaskCreate);
291292
imported++;
292293
} catch { /* skip duplicates */ }
293294
}
@@ -359,9 +360,8 @@ export function registerAdminCommands(program: Command): void {
359360

360361
console.log(`${Math.min(filtered.length, limit)} event(s):`);
361362
for (const event of filtered.slice(0, limit)) {
362-
const e = event as any;
363-
const ts = formatTimestamp(e.createdAt ?? e.timestamp ?? "");
364-
const typeLabel = (e.eventType ?? e.type ?? "unknown").padEnd(30);
363+
const ts = formatTimestamp(event.createdAt ?? "");
364+
const typeLabel = (event.eventType ?? "unknown").padEnd(30);
365365
const entity = `${e.entityType ?? ""}:${e.entityId ?? e.id ?? ""}`.padEnd(25);
366366
console.log(` ${ts} ${typeLabel} ${entity}`);
367367
if (e.detail) {

packages/syncpoint-cli/src/commands/connect.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import path from "node:path";
1313
import os from "node:os";
1414
import { fileURLToPath } from "node:url";
1515
import { Command, Option } from "commander";
16-
import { RuntimeKind } from "syncpoint-adapters";
16+
import { RuntimeKind, type AgentProvider, type AgentRole } from "syncpoint-adapters";
1717
import { InternalError } from "syncpoint-kernel";
1818
import { initSyncpointDir, getSyncpointDir, isProjectLocal, getRawDb } from "syncpoint-server";
1919
import * as repo from "syncpoint-server/repositories";
@@ -206,8 +206,8 @@ export function registerConnectCommands(program: Command): void {
206206

207207
const agent = repo.createAgent({
208208
name: p.name,
209-
provider: p.provider as any,
210-
role: p.role as any,
209+
provider: p.provider as AgentProvider,
210+
role: p.role as AgentRole,
211211
});
212212

213213
const boundAgent = bindRuntime(agent, p.provider, projectRoot);
@@ -338,13 +338,13 @@ export function registerConnectCommands(program: Command): void {
338338
try {
339339
const rawDb = getRawDb();
340340
if (rawDb) {
341-
const integrityResult = rawDb.prepare("PRAGMA integrity_check").get() as any;
341+
const integrityResult = rawDb.prepare("PRAGMA integrity_check").get() as { integrity_check: string };
342342
if (integrityResult?.integrity_check === "ok") {
343343
checks.push({ check: "db-integrity", status: "ok", detail: "PRAGMA integrity_check: ok" });
344344
} else {
345345
checks.push({ check: "db-integrity", status: "fail", detail: `integrity_check: ${JSON.stringify(integrityResult)}` });
346346
}
347-
const journalMode = rawDb.prepare("PRAGMA journal_mode").get() as any;
347+
const journalMode = rawDb.prepare("PRAGMA journal_mode").get() as { journal_mode: string };
348348
const mode = journalMode?.journal_mode ?? "unknown";
349349
checks.push({ check: "db-wal", status: mode === "wal" ? "ok" : "warn", detail: `journal_mode: ${mode}` });
350350
}
@@ -363,7 +363,7 @@ export function registerConnectCommands(program: Command): void {
363363
if (rawDb) {
364364
const orphanResources = rawDb.prepare(
365365
"SELECT COUNT(*) as cnt FROM resource_claim_resource WHERE claim_id NOT IN (SELECT id FROM resource_claim)"
366-
).get() as any;
366+
).get() as { cnt: number };
367367
if (orphanResources?.cnt > 0) {
368368
checks.push({ check: "orphans", status: "warn", detail: `${orphanResources.cnt} orphan resource_claim_resource rows` });
369369
}

packages/syncpoint-cli/src/commands/facade.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ export function registerFacadeCommands(program: Command): void {
224224
}
225225

226226
const scopeDesc = opts.scope !== "file" ? `, scope=${opts.scope}${opts.function ? `:${opts.function}` : ""}${lineRange ? `:${lineRange.start}-${lineRange.end}` : ""}` : "";
227-
const resourceList = resources.map((r: typeof resources[number]) => {
227+
const resourceList = resources.map((r) => {
228228
let desc = r.locator;
229-
if ((r as any).scope === "function" && (r as any).functionName) desc += ` [function:${(r as any).functionName}]`;
230-
if ((r as any).scope === "line_range" && (r as any).lineRange) desc += ` [lines:${(r as any).lineRange.start}-${(r as any).lineRange.end}]`;
229+
if (r.scope === "function" && r.functionName) desc += ` [function:${r.functionName}]`;
230+
if (r.scope === "line_range" && r.lineRange) desc += ` [lines:${r.lineRange.start}-${r.lineRange.end}]`;
231231
return desc;
232232
}).join(", ");
233233
console.log(`✅ Claimed: ${resourceList}`);

packages/syncpoint-cli/src/commands/review.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ export function registerReviewCommands(program: Command): void {
236236
try {
237237
const reviews = listReviewRequests(session.id);
238238
for (const r of reviews) {
239-
if (opts.task && (r as any).taskId !== opts.task) continue;
239+
if (opts.task && r.taskId !== opts.task) continue;
240240
// Only approve PENDING or IN_PROGRESS reviews
241-
if ((r as any).status !== "PENDING" && (r as any).status !== "IN_PROGRESS") continue;
241+
if (r.status !== "PENDING" && r.status !== "IN_PROGRESS") continue;
242242
allReviewRequests.push({
243243
id: r.id,
244-
taskId: (r as any).taskId ?? "",
244+
taskId: r.taskId,
245245
sessionId: session.id,
246-
status: (r as any).status,
246+
status: r.status,
247247
});
248248
}
249249
} catch { /* session may not have reviews */ }

packages/syncpoint-mcp/src/prompts-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export function registerReviewPrompts(server: McpServer): void {
273273
for (const resource of claim.resources ?? []) {
274274
if (resource.scope === "file" && resource.locator === file) {
275275
warned = true;
276-
lines.push((claim as any).mode === "exclusive"
276+
lines.push(claim.mode === "exclusive"
277277
? `🔒 Claimed exclusively by ${claim.actorId} — DO NOT EDIT`
278278
: `⚠️ Shared claim by ${claim.actorId} — coordinate before editing`);
279279
}

packages/syncpoint-mcp/src/tools/constraint.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function registerConstraintTools(server: McpServer): void {
127127
const activeClaims = sessionId ? rcList({ sessionId, status: "ACTIVE" }) : [];
128128
for (const claim of activeClaims) {
129129
for (const resource of claim.resources ?? []) {
130-
if (resource.scope === "file" && resource.locator === locator && (claim as any).mode === "exclusive") {
130+
if (resource.scope === "file" && resource.locator === locator && claim.mode === "exclusive") {
131131
violations.push(`active_claim: ${locator} is exclusively claimed by ${claim.actorId} (task: ${claim.taskId})`);
132132
}
133133
}
@@ -193,7 +193,7 @@ export function registerConstraintTools(server: McpServer): void {
193193
if (resolved && claim.actorId === resolved) continue;
194194
for (const resource of claim.resources ?? []) {
195195
if (resource.scope === "file" && resource.locator === file) {
196-
if ((claim as any).mode === "exclusive") {
196+
if (claim.mode === "exclusive") {
197197
fileViolations.push(`claimed exclusively by ${claim.actorId} (${claim.taskId})`);
198198
} else {
199199
fileWarnings.push(`shared claim by ${claim.actorId} (${claim.taskId})`);
@@ -317,8 +317,8 @@ export function registerConstraintTools(server: McpServer): void {
317317
agents: [c.claimA.actorId, c.claimB.actorId],
318318
tasks: [c.claimA.taskId, c.claimB.taskId],
319319
claimIds: [c.claimA.id, c.claimB.id],
320-
claimAMode: (c.claimA as any).mode ?? "exclusive",
321-
claimBMode: (c.claimB as any).mode ?? "exclusive",
320+
claimAMode: c.claimA.mode,
321+
claimBMode: c.claimB.mode,
322322
claimAScope: c.claimA.resources?.[0]?.scope ?? "file",
323323
claimBScope: c.claimB.resources?.[0]?.scope ?? "file",
324324
}));

packages/syncpoint-mcp/src/tools/guard.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
guardCreateSession,
99
reconcileBackingStore,
1010
constraintCheck,
11+
type ConstraintRuntimeCheckInput,
1112
} from "syncpoint-server/application";
1213
import { WriteIntent } from "syncpoint-kernel";
1314
import { resolveBoundAgentId } from "../identity.js";
@@ -190,7 +191,7 @@ export function registerGuardTools(server: McpServer): void {
190191
},
191192
async (input) => {
192193
try {
193-
const result = constraintCheck(input as any);
194+
const result = constraintCheck(input as ConstraintRuntimeCheckInput);
194195
return ok(result);
195196
} catch (e) { return fail(e); }
196197
}

packages/syncpoint-mcp/src/tools/loop-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
loopHandoff,
88
} from "syncpoint-server/application";
99
import { getResumeContext } from "syncpoint-server/repositories";
10-
import { formatResumePrompt } from "syncpoint-context";
10+
import { formatResumePrompt, type ContextMode } from "syncpoint-context";
1111
import { resolveBoundAgentId } from "../identity.js";
1212
import { fail, ok } from "./_shared.js";
1313

@@ -48,7 +48,7 @@ export function registerLoopContextTools(server: McpServer): void {
4848
try {
4949
const resolved = resolveBoundAgentId(agentId);
5050
if (!resolved) return fail(new Error("agentId required (no bound identity)"));
51-
return ok(loopResume({ agentId: resolved, taskId, provider, format, contextMode: contextMode as any, sessionId }));
51+
return ok(loopResume({ agentId: resolved, taskId, provider, format, contextMode: contextMode as ContextMode, sessionId }));
5252
} catch (e) { return fail(e); }
5353
}
5454
);

packages/syncpoint-mcp/src/tools/runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function registerRuntimeTools(server: McpServer): void {
7777
}
7878
const rt = createRuntime({
7979
name: input.name,
80-
kind: (input.kind as any) ?? RuntimeKind.LOCAL_MCP,
80+
kind: (input.kind as RuntimeKind) ?? RuntimeKind.LOCAL_MCP,
8181
provider: input.provider ?? "",
8282
host: input.host ?? "",
8383
workspaceRoot: input.workspaceRoot ?? "",

0 commit comments

Comments
 (0)