agent-ecosystem/src/main/ipc/context.ts
matt 524a62438e feat(visualization): enhance team and subagent visualization in README
- Updated the README to reflect new features in Claude Code, including the ability to spawn subagents via the Task tool and coordinate teams with improved visibility.
- Added details on the rendering of subagent sessions as expandable inline cards, including execution traces, metrics, and tool calls.
- Enhanced description of teammate messages, highlighting color-coded cards and team lifecycle visibility.
- Clarified session summary metrics to differentiate between teammate and subagent counts for better user insights.

This commit significantly improves the documentation of team and subagent visualization features, providing users with a clearer understanding of the capabilities and enhancements in the application.
2026-02-12 23:43:28 +09:00

96 lines
3.3 KiB
TypeScript

/**
* Context IPC Handlers - Manages context switching and listing.
*
* Channels:
* - context:list - List all available contexts (local + SSH)
* - context:getActive - Get current active context ID
* - context:switch - Switch to a different context
*/
import { createLogger } from '@shared/utils/logger';
// Channel constants (mirrored from preload/constants/ipcChannels.ts to respect module boundaries)
const CONTEXT_LIST = 'context:list';
const CONTEXT_GET_ACTIVE = 'context:getActive';
const CONTEXT_SWITCH = 'context:switch';
import type { ServiceContext, ServiceContextRegistry } from '../services';
import type { IpcMain } from 'electron';
const logger = createLogger('IPC:context');
// =============================================================================
// Module State
// =============================================================================
let registry: ServiceContextRegistry;
let onContextRewire: (context: ServiceContext) => void;
// =============================================================================
// Initialization
// =============================================================================
/**
* Initialize context handlers with required services.
* @param contextRegistry - The service context registry
* @param onRewire - Rewire-only callback (no renderer notification) for renderer-initiated switches
*/
export function initializeContextHandlers(
contextRegistry: ServiceContextRegistry,
onRewire: (context: ServiceContext) => void
): void {
registry = contextRegistry;
onContextRewire = onRewire;
}
// =============================================================================
// Handler Registration
// =============================================================================
export function registerContextHandlers(ipcMain: IpcMain): void {
ipcMain.handle(CONTEXT_LIST, async () => {
try {
const contexts = registry.list();
return { success: true, data: contexts };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
logger.error('Failed to list contexts:', message);
return { success: false, error: message };
}
});
ipcMain.handle(CONTEXT_GET_ACTIVE, async () => {
try {
const activeContextId = registry.getActiveContextId();
return { success: true, data: activeContextId };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
logger.error('Failed to get active context:', message);
return { success: false, error: message };
}
});
ipcMain.handle(CONTEXT_SWITCH, async (_event, contextId: string) => {
try {
// Switch to the new context
const { current } = registry.switch(contextId);
// Re-wire file watcher events only (no renderer notification — renderer initiated this switch)
onContextRewire(current);
return { success: true, data: { contextId } };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
logger.error(`Context switch to "${contextId}" failed:`, message);
return { success: false, error: message };
}
});
logger.info('Context handlers registered');
}
export function removeContextHandlers(ipcMain: IpcMain): void {
ipcMain.removeHandler(CONTEXT_LIST);
ipcMain.removeHandler(CONTEXT_GET_ACTIVE);
ipcMain.removeHandler(CONTEXT_SWITCH);
}