refactor: remove dead exports and orphan modules

Delete exported symbols that nothing in src/, setup/, scripts/ or
runners/ references (and no test exercises), iterated to a fixed point:
service-routing lease/failover helpers, paired-workspace-manager
fingerprint/registration helpers, message-runtime-rules trigger helpers,
utils.fetchWithTimeout, detectPnpmStorePath, isCodexMainService,
isDeltaHandoffEnabledForGroup with the unused DELTA_HANDOFF config, the
deprecated db/schema.applySchemaMigrations alias, unused db wrappers
(memories, router state, sessions-by-agent-type, room skill override
writes, recent chat/turn-output queries) and a few unused type aliases.

Orphan files: src/dashboard.ts + src/dashboard-status-content.ts (only
referenced each other), src/restart-context-cli.ts (never invoked) and
the unused src/config/index.ts barrel.

Service-handoff / channel-owner-lease code is left for a later batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 19:04:03 +09:00
parent 02ea212be0
commit a9fe9dac54
40 changed files with 1 additions and 1101 deletions

View File

@@ -165,16 +165,6 @@ export function touchMemoriesInDatabase(
tx();
}
export function archiveMemoryInDatabase(database: Database, id: number): void {
database
.prepare(
`UPDATE memories
SET archived_at = COALESCE(archived_at, ?)
WHERE id = ?`,
)
.run(new Date().toISOString(), id);
}
function buildCompactMemoryExpiryCutoff(nowIso: string): string {
return new Date(
new Date(nowIso).getTime() - COMPACT_MEMORY_TTL_DAYS * 24 * 60 * 60 * 1000,

View File

@@ -95,17 +95,6 @@ export function getAllChatsFromDatabase(database: Database): ChatInfo[] {
.all() as ChatInfo[];
}
export function hasMessageInDatabase(
database: Database,
chatJid: string,
id: string,
): boolean {
const row = database
.prepare('SELECT 1 FROM messages WHERE chat_jid = ? AND id = ? LIMIT 1')
.get(chatJid, id);
return !!row;
}
export function storeMessageInDatabase(
database: Database,
msg: NewMessage,
@@ -352,44 +341,6 @@ export function getRecentChatMessagesFromDatabase(
return rows.map(normalizeMessageRow);
}
export function getRecentChatMessagesBatchFromDatabase(
database: Database,
chatJids: string[],
limit: number = 8,
): Map<string, NewMessage[]> {
const out = new Map<string, NewMessage[]>();
if (chatJids.length === 0) return out;
const placeholders = chatJids.map(() => '?').join(',');
const sql = `
WITH ranked AS (
SELECT id, chat_jid, sender, sender_name, content, timestamp,
is_from_me, is_bot_message, message_source_kind,
ROW_NUMBER() OVER (PARTITION BY chat_jid ORDER BY timestamp DESC) AS rn
FROM messages
WHERE chat_jid IN (${placeholders})
AND content != '' AND content IS NOT NULL
)
SELECT id, chat_jid, sender, sender_name, content, timestamp,
is_from_me, is_bot_message, message_source_kind
FROM ranked
WHERE rn <= ?
ORDER BY chat_jid, timestamp ASC
`;
const rows = database.prepare(sql).all(...chatJids, limit) as Array<
NewMessage & {
is_from_me?: boolean | number;
is_bot_message?: boolean | number;
}
>;
for (const row of rows) {
const normalized = normalizeMessageRow(row);
const existing = out.get(normalized.chat_jid);
if (existing) existing.push(normalized);
else out.set(normalized.chat_jid, [normalized]);
}
return out;
}
export function getLastHumanMessageTimestampFromDatabase(
database: Database,
chatJid: string,

View File

@@ -94,32 +94,6 @@ export function getPairedTurnOutputsFromDatabase(
.map((row) => hydratePairedTurnOutputRow(row as StoredPairedTurnOutputRow));
}
const recentOutputsForChatStmtCache = new WeakMap<
Database,
ReturnType<Database['prepare']>
>();
export function getRecentPairedTurnOutputsForChatFromDatabase(
database: Database,
chatJid: string,
limit: number = 8,
): PairedTurnOutput[] {
let stmt = recentOutputsForChatStmtCache.get(database);
if (!stmt) {
stmt = database.prepare(`
SELECT o.*
FROM paired_turn_outputs o
INNER JOIN paired_tasks t ON o.task_id = t.id
WHERE t.chat_jid = ?
ORDER BY o.created_at DESC
LIMIT ?
`);
recentOutputsForChatStmtCache.set(database, stmt);
}
const rows = stmt.all(chatJid, limit) as StoredPairedTurnOutputRow[];
return rows.reverse().map(hydratePairedTurnOutputRow);
}
export function getLatestTurnNumberFromDatabase(
database: Database,
taskId: string,

View File

@@ -38,14 +38,6 @@ export interface StoredRoomSkillOverride {
updatedAt: string;
}
export interface StoredRoomSkillOverrideInput {
chatJid: string;
agentType: AgentType;
skillScope: string;
skillName: string;
enabled: boolean;
}
export interface AssignRoomInput {
name: string;
roomMode?: RoomMode;
@@ -384,56 +376,6 @@ export function getStoredRoomSkillOverridesFromDatabase(
.filter((row): row is StoredRoomSkillOverride => Boolean(row));
}
export function upsertStoredRoomSkillOverrideInDatabase(
database: Database,
input: StoredRoomSkillOverrideInput,
): void {
const agentType = normalizeStoredAgentType(input.agentType);
if (!agentType) {
throw new Error(`Unsupported agent type: ${input.agentType}`);
}
const now = new Date().toISOString();
database
.prepare(
`INSERT INTO room_skill_overrides (
chat_jid, agent_type, skill_scope, skill_name, enabled,
created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(chat_jid, agent_type, skill_scope, skill_name)
DO UPDATE SET
enabled = excluded.enabled,
updated_at = excluded.updated_at`,
)
.run(
input.chatJid,
agentType,
input.skillScope,
input.skillName,
input.enabled ? 1 : 0,
now,
now,
);
}
export function deleteStoredRoomSkillOverrideFromDatabase(
database: Database,
input: Omit<StoredRoomSkillOverrideInput, 'enabled'>,
): void {
const agentType = normalizeStoredAgentType(input.agentType);
if (!agentType) {
throw new Error(`Unsupported agent type: ${input.agentType}`);
}
database
.prepare(
`DELETE FROM room_skill_overrides
WHERE chat_jid = ?
AND agent_type = ?
AND skill_scope = ?
AND skill_name = ?`,
)
.run(input.chatJid, agentType, input.skillScope, input.skillName);
}
function getStoredRoomModeRowFromDatabase(
database: Database,
chatJid: string,

View File

@@ -26,23 +26,6 @@ export function getRouterStateFromDatabase(
return prefixedRow.value;
}
export function getRouterStateForServiceFromDatabase(
database: Database,
key: string,
serviceId: string,
): string | undefined {
const prefixedKey = `${normalizeServiceId(serviceId)}:${key}`;
const row = database
.prepare('SELECT value FROM router_state WHERE key = ?')
.get(prefixedKey) as { value: string } | undefined;
if (row) return row.value;
const canonical = database
.prepare('SELECT value FROM router_state WHERE key = ?')
.get(key) as { value: string } | undefined;
return canonical?.value;
}
export function setRouterStateInDatabase(
database: Database,
key: string,
@@ -53,18 +36,6 @@ export function setRouterStateInDatabase(
.run(key, value);
}
export function setRouterStateForServiceInDatabase(
database: Database,
key: string,
value: string,
serviceId: string,
): void {
const prefixedKey = `${normalizeServiceId(serviceId)}:${key}`;
database
.prepare('INSERT OR REPLACE INTO router_state (key, value) VALUES (?, ?)')
.run(prefixedKey, value);
}
export function getUnsupportedRouterStateKeysFromDatabase(
database: Database,
): string[] {

View File

@@ -7,12 +7,8 @@ import {
type MemoryScopeKind,
type MemorySourceKind,
type RecallMemoryQuery,
archiveMemoryInDatabase,
enforceMemoryBoundsInDatabase,
expireStaleMemoriesInDatabase,
recallMemoriesFromDatabase,
rememberMemoryInDatabase,
touchMemoriesInDatabase,
} from './memories.js';
import {
type ChatInfo,
@@ -26,8 +22,6 @@ import {
getNewMessagesBySeqFromDatabase,
getNewMessagesFromDatabase,
getRecentChatMessagesFromDatabase,
getRecentChatMessagesBatchFromDatabase,
hasMessageInDatabase,
hasRecentRestartAnnouncementInDatabase,
storeChatMetadataInDatabase,
storeMessageInDatabase,
@@ -80,29 +74,6 @@ export function _setMemoryTimestampsForTests(
);
}
export function touchMemories(ids: number[]): void {
touchMemoriesInDatabase(requireDatabase(), ids);
}
export function archiveMemory(id: number): void {
archiveMemoryInDatabase(requireDatabase(), id);
}
export function expireStaleMemories(args?: {
scopeKind?: MemoryScopeKind;
scopeKey?: string;
now?: string;
}): number {
return expireStaleMemoriesInDatabase(requireDatabase(), args);
}
export function enforceMemoryBounds(
scopeKind: MemoryScopeKind,
scopeKey: string,
): void {
enforceMemoryBoundsInDatabase(requireDatabase(), scopeKind, scopeKey);
}
export function rememberMemory(input: {
scopeKind: MemoryScopeKind;
scopeKey: string;
@@ -144,10 +115,6 @@ export function storeMessage(msg: NewMessage): void {
storeMessageInDatabase(requireDatabase(), msg);
}
export function hasMessage(chatJid: string, id: string): boolean {
return hasMessageInDatabase(requireDatabase(), chatJid, id);
}
export function getNewMessages(
jids: string[],
lastTimestamp: string,
@@ -226,17 +193,6 @@ export function getRecentChatMessages(
return getRecentChatMessagesFromDatabase(requireDatabase(), chatJid, limit);
}
export function getRecentChatMessagesBatch(
chatJids: string[],
limit: number = 8,
): Map<string, NewMessage[]> {
return getRecentChatMessagesBatchFromDatabase(
requireDatabase(),
chatJids,
limit,
);
}
export function getLastHumanMessageTimestamp(chatJid: string): string | null {
return getLastHumanMessageTimestampFromDatabase(requireDatabase(), chatJid);
}

View File

@@ -53,7 +53,6 @@ import {
import {
getLatestTurnNumberFromDatabase,
getPairedTurnOutputsFromDatabase,
getRecentPairedTurnOutputsForChatFromDatabase,
insertPairedTurnOutputInDatabase,
} from './paired-turn-outputs.js';
import {
@@ -387,17 +386,6 @@ export function getPairedTurnOutputs(taskId: string): PairedTurnOutput[] {
return getPairedTurnOutputsFromDatabase(requireDatabase(), taskId);
}
export function getRecentPairedTurnOutputsForChat(
chatJid: string,
limit: number = 8,
): PairedTurnOutput[] {
return getRecentPairedTurnOutputsForChatFromDatabase(
requireDatabase(),
chatJid,
limit,
);
}
export function getLatestTurnNumber(taskId: string): number {
return getLatestTurnNumberFromDatabase(requireDatabase(), taskId);
}

View File

@@ -28,7 +28,6 @@ import {
assignRoomInDatabase,
clearExplicitRoomModeInDatabase,
deleteStoredRoomSettingsForTestsInDatabase,
deleteStoredRoomSkillOverrideFromDatabase,
getAllRoomBindingsFromDatabase,
getEffectiveRoomModeFromDatabase,
getEffectiveRuntimeRoomModeFromDatabase,
@@ -42,9 +41,7 @@ import {
setRegisteredGroupForTestsInDatabase,
setStoredRoomOwnerAgentTypeForTestsInDatabase,
type StoredRoomSkillOverride,
type StoredRoomSkillOverrideInput,
updateRegisteredGroupNameInDatabase,
upsertStoredRoomSkillOverrideInDatabase,
} from './rooms.js';
import { type StoredRoomSettings } from './room-registration.js';
import {
@@ -56,9 +53,7 @@ import {
} from './sessions.js';
import {
getLastRespondingAgentTypeFromDatabase,
getRouterStateForServiceFromDatabase,
getRouterStateFromDatabase,
setRouterStateForServiceInDatabase,
setRouterStateInDatabase,
} from './router-state.js';
import {
@@ -75,7 +70,6 @@ import {
getDueTasksFromDatabase,
getRecentConsecutiveErrorsFromDatabase,
getTaskByIdFromDatabase,
getTasksForGroupFromDatabase,
hasActiveCiWatcherForChatInDatabase,
logTaskRunInDatabase,
updateTaskAfterRunInDatabase,
@@ -121,17 +115,6 @@ export function findDuplicateCiWatcher(
);
}
export function getTasksForGroup(
groupFolder: string,
agentType?: AgentType,
): ScheduledTask[] {
return getTasksForGroupFromDatabase(
requireDatabase(),
groupFolder,
agentType,
);
}
export function getAllTasks(agentType?: AgentType): ScheduledTask[] {
return getAllTasksFromDatabase(requireDatabase(), agentType);
}
@@ -235,29 +218,10 @@ export function getRouterState(key: string): string | undefined {
return getRouterStateFromDatabase(requireDatabase(), key, SERVICE_ID);
}
export function getRouterStateForService(
key: string,
serviceId: string,
): string | undefined {
return getRouterStateForServiceFromDatabase(
requireDatabase(),
key,
serviceId,
);
}
export function setRouterState(key: string, value: string): void {
setRouterStateInDatabase(requireDatabase(), key, value);
}
export function setRouterStateForService(
key: string,
value: string,
serviceId: string,
): void {
setRouterStateForServiceInDatabase(requireDatabase(), key, value, serviceId);
}
export function getSession(
groupFolder: string,
agentType: AgentType = 'claude-code',
@@ -293,21 +257,6 @@ export function getAllSessions(): Record<string, string> {
);
}
export function getSessionForAgentType(
groupFolder: string,
agentType: string,
): string | undefined {
return getSessionFromDatabase(requireDatabase(), groupFolder, agentType);
}
export function setSessionForAgentType(
groupFolder: string,
agentType: string,
sessionId: string,
): void {
setSessionInDatabase(requireDatabase(), groupFolder, agentType, sessionId);
}
export function getLastRespondingAgentType(
chatJid: string,
): AgentType | undefined {
@@ -376,18 +325,6 @@ export function getStoredRoomSkillOverrides(
return getStoredRoomSkillOverridesFromDatabase(db, chatJid);
}
export function upsertStoredRoomSkillOverride(
input: StoredRoomSkillOverrideInput,
): void {
upsertStoredRoomSkillOverrideInDatabase(requireDatabase(), input);
}
export function deleteStoredRoomSkillOverride(
input: Omit<StoredRoomSkillOverrideInput, 'enabled'>,
): void {
deleteStoredRoomSkillOverrideFromDatabase(requireDatabase(), input);
}
export function getExplicitRoomMode(chatJid: string): RoomMode | undefined {
return getExplicitRoomModeFromDatabase(requireDatabase(), chatJid);
}

View File

@@ -23,6 +23,3 @@ export function applyLegacySchemaMigrations(
`ALTER TABLE work_items ADD COLUMN service_id TEXT`,
);
}
/** @deprecated New schema changes should be added under src/db/migrations/*. */
export const applySchemaMigrations = applyLegacySchemaMigrations;

View File

@@ -107,26 +107,6 @@ export function findDuplicateCiWatcherInDatabase(
.get(chatJid, ciProvider, ciMetadata) as ScheduledTask | undefined;
}
export function getTasksForGroupFromDatabase(
database: Database,
groupFolder: string,
agentType?: AgentType,
): ScheduledTask[] {
if (agentType) {
return database
.prepare(
'SELECT * FROM scheduled_tasks WHERE group_folder = ? AND agent_type = ? ORDER BY created_at DESC',
)
.all(groupFolder, agentType) as ScheduledTask[];
}
return database
.prepare(
'SELECT * FROM scheduled_tasks WHERE group_folder = ? ORDER BY created_at DESC',
)
.all(groupFolder) as ScheduledTask[];
}
export function getAllTasksFromDatabase(
database: Database,
agentType?: AgentType,

View File

@@ -273,34 +273,6 @@ export function getOpenWorkItemFromDatabase(
return row ? hydrateWorkItemRow(row) : undefined;
}
/**
* Recent delivered owner-side work items for a chat, newest last.
* Used by single-mode prompt building to surface the bot's own prior
* answers (which only live in work_items.result_payload) so a new turn
* can reference what it previously said.
*/
export function getRecentDeliveredOwnerWorkItemsForChatFromDatabase(
database: Database,
chatJid: string,
limit: number,
): WorkItem[] {
if (limit <= 0) {
return [];
}
const rows = database
.prepare(
`SELECT *
FROM work_items
WHERE chat_jid = ?
AND status = 'delivered'
AND (delivery_role = 'owner' OR delivery_role IS NULL)
ORDER BY id DESC
LIMIT ?`,
)
.all(chatJid, limit) as StoredWorkItemRow[];
return rows.map(hydrateWorkItemRow).reverse();
}
export function getOpenWorkItemForChatFromDatabase(
database: Database,
chatJid: string,