refactor: rename container references to agent across codebase

- container-runner.ts → agent-runner.ts
- ContainerInput/Output → AgentInput/Output
- ContainerConfig → AgentConfig
- runContainerAgent → runAgentProcess
- CONTAINER_TIMEOUT → AGENT_TIMEOUT (with env fallback)
- MAX_CONCURRENT_CONTAINERS → MAX_CONCURRENT_AGENTS
- containerName → processName, isTaskContainer → isTaskProcess
- DB column container_config kept as-is (backwards compat)
This commit is contained in:
Eyejoker
2026-03-13 16:18:36 +09:00
parent 35277cea0a
commit bd7f4408ae
12 changed files with 144 additions and 133 deletions

View File

@@ -14,11 +14,11 @@ import {
getRegisteredChannelNames,
} from './channels/registry.js';
import {
ContainerOutput,
runContainerAgent,
AgentOutput,
runAgentProcess,
writeGroupsSnapshot,
writeTasksSnapshot,
} from './container-runner.js';
} from './agent-runner.js';
import {
getAllChats,
getAllRegisteredGroups,
@@ -121,7 +121,7 @@ function registerGroup(jid: string, group: RegisteredGroup): void {
* Get available groups list for the agent.
* Returns groups ordered by most recent activity.
*/
export function getAvailableGroups(): import('./container-runner.js').AvailableGroup[] {
export function getAvailableGroups(): import('./agent-runner.js').AvailableGroup[] {
const chats = getAllChats();
const registeredJids = new Set(Object.keys(registeredGroups));
@@ -237,7 +237,7 @@ async function processGroupMessages(chatJid: string): Promise<boolean> {
idleTimer = setTimeout(() => {
logger.debug(
{ group: group.name },
'Idle timeout, closing container stdin',
'Idle timeout, closing agent stdin',
);
queue.closeStdin(chatJid);
}, IDLE_TIMEOUT);
@@ -307,12 +307,12 @@ async function runAgent(
group: RegisteredGroup,
prompt: string,
chatJid: string,
onOutput?: (output: ContainerOutput) => Promise<void>,
onOutput?: (output: AgentOutput) => Promise<void>,
): Promise<'success' | 'error'> {
const isMain = group.isMain === true;
const sessionId = sessions[group.folder];
// Update tasks snapshot for container to read (filtered by group)
// Update tasks snapshot for agent to read (filtered by group)
const tasks = getAllTasks();
writeTasksSnapshot(
group.folder,
@@ -339,7 +339,7 @@ async function runAgent(
// Wrap onOutput to track session ID from streamed results
const wrappedOnOutput = onOutput
? async (output: ContainerOutput) => {
? async (output: AgentOutput) => {
if (output.newSessionId) {
sessions[group.folder] = output.newSessionId;
setSession(group.folder, output.newSessionId);
@@ -349,7 +349,7 @@ async function runAgent(
: undefined;
try {
const output = await runContainerAgent(
const output = await runAgentProcess(
group,
{
prompt,
@@ -359,8 +359,8 @@ async function runAgent(
isMain,
assistantName: ASSISTANT_NAME,
},
(proc, containerName) =>
queue.registerProcess(chatJid, proc, containerName, group.folder),
(proc, processName) =>
queue.registerProcess(chatJid, proc, processName, group.folder),
wrappedOnOutput,
);
@@ -372,7 +372,7 @@ async function runAgent(
if (output.status === 'error') {
logger.error(
{ group: group.name, error: output.error },
'Container agent error',
'Agent process error',
);
return 'error';
}
@@ -461,9 +461,9 @@ async function startMessageLoop(): Promise<void> {
);
if (loopCmdMsg) {
// Only close active container if the sender is authorized — otherwise an
// Only close active agent if the sender is authorized — otherwise an
// untrusted user could kill in-flight work by sending /compact (DoS).
// closeStdin no-ops internally when no container is active.
// closeStdin no-ops internally when no agent is active.
if (
isSessionCommandAllowed(
isMainGroup,
@@ -473,7 +473,7 @@ async function startMessageLoop(): Promise<void> {
queue.closeStdin(chatJid);
}
// Enqueue so processGroupMessages handles auth + cursor advancement.
// Don't pipe via IPC — slash commands need a fresh container with
// Don't pipe via IPC — slash commands need a fresh agent with
// string prompt (not MessageStream) for SDK recognition.
queue.enqueueMessageCheck(chatJid);
continue;
@@ -510,19 +510,19 @@ async function startMessageLoop(): Promise<void> {
if (queue.sendMessage(chatJid, formatted)) {
logger.debug(
{ chatJid, count: messagesToSend.length },
'Piped messages to active container',
'Piped messages to active agent',
);
lastAgentTimestamp[chatJid] =
messagesToSend[messagesToSend.length - 1].timestamp;
saveState();
// Show typing indicator while the container processes the piped message
// Show typing indicator while the agent processes the piped message
channel
.setTyping?.(chatJid, true)
?.catch((err) =>
logger.warn({ chatJid, err }, 'Failed to set typing indicator'),
);
} else {
// No active container — enqueue for a new one
// No active agent — enqueue for a new one
queue.enqueueMessageCheck(chatJid, group.folder);
}
}
@@ -628,8 +628,8 @@ async function main(): Promise<void> {
registeredGroups: () => registeredGroups,
getSessions: () => sessions,
queue,
onProcess: (groupJid, proc, containerName, groupFolder) =>
queue.registerProcess(groupJid, proc, containerName, groupFolder),
onProcess: (groupJid, proc, processName, groupFolder) =>
queue.registerProcess(groupJid, proc, processName, groupFolder),
sendMessage: async (jid, rawText) => {
const channel = findChannel(channels, jid);
if (!channel) {