Skip to content

Commit 34528af

Browse files
committed
refactor: delete code nothing reaches
`biome.json:101-102` turns off `noUnusedVariables` and `noUnusedFunctionParameters`, so none of this was ever going to be flagged. Everything here was confirmed by grepping the symbol across `apps/` and `packages/` and finding only its own declaration; `tsc --noEmit` then proves each deleted binding was unread, since a read one fails to compile. - Eleven module-scope loggers that nothing logs through, with the now-orphaned `createLogger` import each left behind. - `execute-platform-context-use-case.ts` — the whole file. No importer, no barrel, and neither export is named anywhere. - `routeToolCall` and, once it goes, `ToolRoute` and `ToolRouteTarget` with it. The catalog accessors around them stay live. - `processPastChat`, superseded by `processPastChatFromDb`. It carried the last `boundary-raw-fetch` exemption in the file. - `withMessageId`, pasted into three server tools and called in none. - Write-only locals: `activeSubagent` (assigned twice, read never — the scoped maps replaced it), `resolvedReadPath`, `workflowPath`, and `workflow` in an execution-core destructure. - `ACCEPTED_AUDIO_TYPES` / `ACCEPTED_VIDEO_TYPES`, never wired to an accept attribute the way their live sibling is. - Unused `catch` bindings in `error-extractors.ts` and `defaults.ts`. `diff-engine.ts` drops a `proposedSubKeys.includes(key)` guard that the `!proposedSub` check three lines down already covers: a key absent from the proposed block reads back `undefined` there, and so does a key present with a nullish value. Same answer on every input, without the O(n) scan per iteration.
1 parent 50594b8 commit 34528af

25 files changed

Lines changed: 8 additions & 152 deletions

apps/sim/lib/copilot/application/execute-platform-context-use-case.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

apps/sim/lib/copilot/chat/effective-transcript.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ function buildLiveAssistantMessage(params: {
134134
const toolIndexById = new Map<string, number>()
135135
const subagentByParentToolCallId = new Map<string, string>()
136136
const subagentBySpanId = new Map<string, string>()
137-
let activeSubagent: string | undefined
138137
let activeSubagentParentToolCallId: string | undefined
139138
const activeCompactionIdByLane = new Map<string, string>()
140139
let runningText = ''
@@ -143,8 +142,8 @@ function buildLiveAssistantMessage(params: {
143142
let lastTimestamp: string | undefined
144143

145144
// Scope-only resolution (mirrors the live browser stream loop): with
146-
// concurrent subagents the legacy activeSubagent fallback / name-match scan
147-
// would mis-attribute interleaved replayed events to the wrong lane.
145+
// concurrent subagents the legacy name-match scan would mis-attribute
146+
// interleaved replayed events to the wrong lane.
148147
const resolveScopedSubagent = (
149148
agentId: string | undefined,
150149
parentToolCallId: string | undefined,
@@ -404,7 +403,6 @@ function buildLiveAssistantMessage(params: {
404403
if (parentToolCallId) {
405404
subagentByParentToolCallId.set(parentToolCallId, name)
406405
}
407-
activeSubagent = name
408406
activeSubagentParentToolCallId = parentToolCallId
409407
blocks.push({
410408
type: MothershipStreamV1EventType.span,
@@ -431,7 +429,6 @@ function buildLiveAssistantMessage(params: {
431429
// or an unscoped end — never by agent name, which would tear down a
432430
// concurrent same-name sibling that is still open.
433431
if (!parentToolCallId || parentToolCallId === activeSubagentParentToolCallId) {
434-
activeSubagent = undefined
435432
activeSubagentParentToolCallId = undefined
436433
}
437434
blocks.push({

apps/sim/lib/copilot/chat/process-contents.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -558,46 +558,6 @@ async function processWorkflowFromDb(
558558
}
559559
}
560560

561-
async function processPastChat(chatId: string, tagOverride?: string): Promise<AgentContext | null> {
562-
try {
563-
// boundary-raw-fetch: GET /api/mothership/chat?chatId=... has no defineRouteContract;
564-
// the route forwards to the copilot chat handler and emits a free-form chat envelope
565-
// that isn't covered by mothershipChatGetQuerySchema or copilotChatGetContract.
566-
const resp = await fetch(`/api/mothership/chat?chatId=${encodeURIComponent(chatId)}`)
567-
if (!resp.ok) {
568-
logger.error('Failed to fetch past chat', { chatId, status: resp.status })
569-
return null
570-
}
571-
const data = await resp.json()
572-
const messages = Array.isArray(data?.chat?.messages) ? data.chat.messages : []
573-
const content = messages
574-
.map((m: any) => {
575-
const role = m.role || 'user'
576-
// Prefer contentBlocks text if present (joins text blocks), else use content
577-
let text = ''
578-
if (Array.isArray(m.contentBlocks) && m.contentBlocks.length > 0) {
579-
text = m.contentBlocks
580-
.filter((b: any) => b?.type === 'text')
581-
.map((b: any) => String(b.content || ''))
582-
.join('')
583-
.trim()
584-
}
585-
if (!text && typeof m.content === 'string') text = m.content
586-
return `${role}: ${text}`.trim()
587-
})
588-
.filter((s: string) => s.length > 0)
589-
.join('\n')
590-
logger.info('Processed past_chat context via API', { chatId, length: content.length })
591-
592-
return { type: 'past_chat', tag: tagOverride || '@', content }
593-
} catch (error) {
594-
logger.error('Error processing past chat', { chatId, error })
595-
return null
596-
}
597-
}
598-
599-
// Back-compat alias; used by processContexts above
600-
601561
async function processKnowledgeFromDb(
602562
knowledgeBaseId: string,
603563
userId: string | undefined,

apps/sim/lib/copilot/request/lifecycle/headless.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createLogger } from '@sim/logger'
21
import { generateId } from '@sim/utils/id'
32
import type { RequestTraceV1Outcome as RequestTraceOutcome } from '@/lib/copilot/generated/request-trace-v1'
43
import {
@@ -12,8 +11,6 @@ import { withCopilotOtelContext } from '@/lib/copilot/request/otel'
1211
import { TraceCollector } from '@/lib/copilot/request/trace'
1312
import type { OrchestratorResult } from '@/lib/copilot/request/types'
1413

15-
const logger = createLogger('CopilotHeadlessLifecycle')
16-
1714
export async function runHeadlessCopilotLifecycle(
1815
requestPayload: Record<string, unknown>,
1916
options: CopilotLifecycleOptions

apps/sim/lib/copilot/tool-executor/router.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { TOOL_CATALOG, type ToolCatalogEntry } from '@/lib/copilot/generated/tool-catalog-v1'
22

3-
export type ToolRouteTarget = ToolCatalogEntry['route']
4-
53
export function isToolInCatalog(toolId: string): boolean {
64
return toolId in TOOL_CATALOG
75
}
@@ -10,18 +8,6 @@ export function getToolEntry(toolId: string): ToolCatalogEntry | undefined {
108
return TOOL_CATALOG[toolId]
119
}
1210

13-
export type ToolRoute = {
14-
route: ToolRouteTarget
15-
mode: ToolCatalogEntry['mode']
16-
subagentId?: string
17-
}
18-
19-
export function routeToolCall(toolId: string): ToolRoute | null {
20-
const entry = getToolEntry(toolId)
21-
if (!entry) return null
22-
return { route: entry.route, mode: entry.mode, subagentId: entry.subagentId }
23-
}
24-
2511
export function isSimExecuted(toolId: string): boolean {
2612
return getToolEntry(toolId)?.route === 'sim'
2713
}

apps/sim/lib/copilot/tools/handlers/vfs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ export async function executeVfsRead(
563563
}
564564
}
565565

566-
let resolvedReadPath = path
567566
let result = await vfs.read(path, offset, limit)
568567
if (!result) {
569568
// Same name, wrong encoding (spaces instead of %20) is the most common
@@ -575,7 +574,6 @@ export async function executeVfsRead(
575574
requested: path,
576575
resolved: decodedEquivalent,
577576
})
578-
resolvedReadPath = decodedEquivalent
579577
result = await vfs.read(decodedEquivalent, offset, limit)
580578
}
581579
}

apps/sim/lib/copilot/tools/handlers/workflow/queries.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createLogger } from '@sim/logger'
21
import { executeCopilotCustomToolUseCase } from '@/lib/copilot/application/execute-custom-tool-use-case'
32
import { executeCopilotFileUseCase } from '@/lib/copilot/application/execute-file-use-case'
43
import { executeCopilotMcpServerUseCase } from '@/lib/copilot/application/execute-mcp-server-use-case'
@@ -26,8 +25,6 @@ import type {
2625
GetWorkflowRunOptionsParams,
2726
} from '../param-types'
2827

29-
const logger = createLogger('WorkflowQueries')
30-
3128
export async function executeGetWorkflowRunOptions(
3229
params: GetWorkflowRunOptionsParams,
3330
context: ExecutionContext

apps/sim/lib/copilot/tools/server/files/download-to-workspace-file.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ export const downloadToWorkspaceFileServerTool: BaseServerTool<
145145
params: DownloadToWorkspaceFileArgs,
146146
context?: ServerToolContext
147147
): Promise<DownloadToWorkspaceFileResult> {
148-
const withMessageId = (message: string) =>
149-
context?.messageId ? `${message} [messageId:${context.messageId}]` : message
150-
151148
if (!context?.userId) {
152149
throw new Error('Authentication required')
153150
}

apps/sim/lib/copilot/tools/server/image/generate-image.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ export const generateImageServerTool: BaseServerTool<GenerateImageArgs, Generate
6565
params: GenerateImageArgs,
6666
context?: ServerToolContext
6767
): Promise<GenerateImageResult> {
68-
const withMessageId = (message: string) =>
69-
context?.messageId ? `${message} [messageId:${context.messageId}]` : message
70-
7168
if (!context?.userId) {
7269
throw new Error('Authentication required')
7370
}

apps/sim/lib/copilot/tools/server/table/user-table.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ function mergeViewPredicate(
164164
export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult> = {
165165
name: UserTable.id,
166166
async execute(params: UserTableArgs, context?: ServerToolContext): Promise<UserTableResult> {
167-
const withMessageId = (message: string) =>
168-
context?.messageId ? `${message} [messageId:${context.messageId}]` : message
169-
170167
if (!context?.userId) {
171168
logger.error('Unauthorized attempt to access user table - no authenticated user context')
172169
throw new Error('Authentication required')

0 commit comments

Comments
 (0)