refactor: remove the main room concept
No room has room_settings.is_main = 1, so every main-only path was dead, and admin work is done from the host shell. Each room's agent may now only act on its own room: - IPC: messages/inbound injection only to the source room; schedule, update, pause, resume and cancel only for the source room's tasks; drop the assign_room and refresh_groups IPC tasks and the deps they needed (assignRoom/syncGroups/getAvailableGroups/writeGroupsSnapshot) - DB/host evidence is always scoped to the source group folder - runner MCP server: drop the assign_room tool, the target_group_jid parameters and the isMain flag; list_tasks shows only the room's tasks - drop EJCLAW_IS_MAIN, RunnerInput.isMain and AgentInput.isMain; the global CLAUDE.md memory is now included for every room - drop the available_groups.json snapshot (available-groups.ts), the inferred restart announcement that only went to the main room, and the unused Channel.syncGroups hook - setup register: drop --is-main; deregister-room: drop the main-room refusal and --force, and fix its unknown[] binding type error - remove the groups/main/ template The room_settings.is_main column and migrations are untouched; new rows get the column default (0) and nothing reads it anymore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -26,11 +25,6 @@ export interface RestartContext {
|
||||
interruptedGroups?: RestartInterruptedGroup[];
|
||||
}
|
||||
|
||||
export interface InferredRestartContext {
|
||||
chatJid: string;
|
||||
lines: string[];
|
||||
}
|
||||
|
||||
export interface RestartRecoveryCandidate {
|
||||
chatJid: string;
|
||||
groupFolder: string;
|
||||
@@ -39,8 +33,6 @@ export interface RestartRecoveryCandidate {
|
||||
pendingTasks: number;
|
||||
}
|
||||
|
||||
const INFER_WINDOW_MS = 3 * 60 * 1000;
|
||||
|
||||
function getRestartContextPath(serviceId: string = SERVICE_ID): string {
|
||||
return path.join(DATA_DIR, `restart-context.${serviceId}.json`);
|
||||
}
|
||||
@@ -52,15 +44,6 @@ function formatKoreanTimestamp(timestamp: string | number | Date): string {
|
||||
});
|
||||
}
|
||||
|
||||
function getMainGroupJid(
|
||||
roomBindings: Record<string, RegisteredGroup>,
|
||||
): string | null {
|
||||
const mainEntry = Object.entries(roomBindings).find(
|
||||
([, group]) => group.isMain === true,
|
||||
);
|
||||
return mainEntry?.[0] ?? null;
|
||||
}
|
||||
|
||||
function readRestartContextFile(filePath: string): RestartContext | null {
|
||||
const data = readJsonFile<RestartContext>(filePath);
|
||||
if (data === null && fs.existsSync(filePath)) {
|
||||
@@ -86,55 +69,7 @@ export function getRecoverableInterruptedGroups(
|
||||
);
|
||||
}
|
||||
|
||||
function getLatestDistBuildTime(): number | null {
|
||||
const distDir = path.join(process.cwd(), 'dist');
|
||||
if (!fs.existsSync(distDir)) return null;
|
||||
|
||||
let latestMtime = 0;
|
||||
for (const entry of fs.readdirSync(distDir)) {
|
||||
if (!entry.endsWith('.js')) continue;
|
||||
const stat = fs.statSync(path.join(distDir, entry));
|
||||
latestMtime = Math.max(latestMtime, stat.mtimeMs);
|
||||
}
|
||||
return latestMtime > 0 ? latestMtime : null;
|
||||
}
|
||||
|
||||
function getRecentCommit(processStartedAtMs: number): string | null {
|
||||
try {
|
||||
const sinceSeconds = Math.max(
|
||||
60,
|
||||
Math.ceil(INFER_WINDOW_MS / 1000) + 30,
|
||||
).toString();
|
||||
const output = execSync(
|
||||
`git log --since='${sinceSeconds} seconds ago' -1 --format=%h%x20%s`,
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
encoding: 'utf8',
|
||||
},
|
||||
).trim();
|
||||
if (!output) return null;
|
||||
|
||||
const commitTime = execSync('git log -1 --format=%ct', {
|
||||
cwd: process.cwd(),
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
encoding: 'utf8',
|
||||
}).trim();
|
||||
const commitTimeMs = Number(commitTime) * 1000;
|
||||
if (
|
||||
Number.isFinite(commitTimeMs) &&
|
||||
commitTimeMs >= processStartedAtMs - INFER_WINDOW_MS
|
||||
) {
|
||||
return output;
|
||||
}
|
||||
} catch {
|
||||
// Ignore git inference failures on deployed environments without .git.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function writeShutdownRestartContext(
|
||||
roomBindings: Record<string, RegisteredGroup>,
|
||||
interruptedGroups: RestartInterruptedGroup[],
|
||||
signal: string,
|
||||
serviceIds: string[] = [SERVICE_ID],
|
||||
@@ -145,8 +80,7 @@ export function writeShutdownRestartContext(
|
||||
if (recoverableInterruptedGroups.length === 0) return [];
|
||||
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
const mainChatJid =
|
||||
getMainGroupJid(roomBindings) ?? interruptedGroups[0].chatJid;
|
||||
const fallbackChatJid = interruptedGroups[0].chatJid;
|
||||
const writtenPaths: string[] = [];
|
||||
|
||||
for (const serviceId of serviceIds) {
|
||||
@@ -162,7 +96,7 @@ export function writeShutdownRestartContext(
|
||||
);
|
||||
|
||||
const payload: RestartContext = {
|
||||
chatJid: existing?.chatJid || mainChatJid,
|
||||
chatJid: existing?.chatJid || fallbackChatJid,
|
||||
summary: existing?.summary || '서비스 재시작으로 진행 중인 작업이 중단됨',
|
||||
verify: existing?.verify ?? [],
|
||||
writtenAt: new Date().toISOString(),
|
||||
@@ -254,30 +188,3 @@ export function getInterruptedRecoveryCandidates(
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
export function inferRecentRestartContext(
|
||||
roomBindings: Record<string, RegisteredGroup>,
|
||||
processStartedAtMs: number,
|
||||
): InferredRestartContext | null {
|
||||
const chatJid = getMainGroupJid(roomBindings);
|
||||
if (!chatJid) return null;
|
||||
|
||||
const latestBuildTime = getLatestDistBuildTime();
|
||||
const recentCommit = getRecentCommit(processStartedAtMs);
|
||||
const buildLooksRecent =
|
||||
latestBuildTime !== null &&
|
||||
latestBuildTime >= processStartedAtMs - INFER_WINDOW_MS;
|
||||
|
||||
if (!buildLooksRecent && !recentCommit) return null;
|
||||
|
||||
const lines = ['재시작 감지.', '- 명시적 재시작 힌트는 없어 추론 기반임.'];
|
||||
if (recentCommit) {
|
||||
lines.push(`- 최근 커밋: ${recentCommit}`);
|
||||
}
|
||||
if (latestBuildTime !== null) {
|
||||
lines.push(`- 최근 빌드: ${formatKoreanTimestamp(latestBuildTime)}`);
|
||||
}
|
||||
lines.push(`- 시작 시각: ${formatKoreanTimestamp(processStartedAtMs)}`);
|
||||
|
||||
return { chatJid, lines };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user