Format runtime refactor modules
This commit is contained in:
@@ -182,7 +182,10 @@ export function createPairedExecutionLifecycle(args: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const finishedTask = getPairedTaskById(pairedExecutionContext.task.id);
|
const finishedTask = getPairedTaskById(pairedExecutionContext.task.id);
|
||||||
if (finishedTask?.status === 'completed' && finishedTask.completion_reason) {
|
if (
|
||||||
|
finishedTask?.status === 'completed' &&
|
||||||
|
finishedTask.completion_reason
|
||||||
|
) {
|
||||||
const sender = getLastHumanMessageSender(chatJid);
|
const sender = getLastHumanMessageSender(chatJid);
|
||||||
const mention = sender ? `<@${sender}>` : '';
|
const mention = sender ? `<@${sender}>` : '';
|
||||||
const notifications: Record<string, string> = {
|
const notifications: Record<string, string> = {
|
||||||
|
|||||||
@@ -26,14 +26,10 @@ import {
|
|||||||
import { GroupQueue } from './group-queue.js';
|
import { GroupQueue } from './group-queue.js';
|
||||||
import { createScopedLogger } from './logger.js';
|
import { createScopedLogger } from './logger.js';
|
||||||
import { buildRoomMemoryBriefing } from './sqlite-memory-store.js';
|
import { buildRoomMemoryBriefing } from './sqlite-memory-store.js';
|
||||||
import {
|
import { preparePairedExecutionContext } from './paired-execution-context.js';
|
||||||
preparePairedExecutionContext,
|
|
||||||
} from './paired-execution-context.js';
|
|
||||||
import { resolveCodexFallbackHandoff } from './paired-turn-fallback.js';
|
import { resolveCodexFallbackHandoff } from './paired-turn-fallback.js';
|
||||||
import { createPairedExecutionLifecycle } from './message-agent-executor-paired.js';
|
import { createPairedExecutionLifecycle } from './message-agent-executor-paired.js';
|
||||||
import {
|
import { resolveExecutionTarget } from './message-runtime-rules.js';
|
||||||
resolveExecutionTarget,
|
|
||||||
} from './message-runtime-rules.js';
|
|
||||||
import { buildRoomRoleContext } from './room-role-context.js';
|
import { buildRoomRoleContext } from './room-role-context.js';
|
||||||
import { type AgentTriggerReason } from './agent-error-detection.js';
|
import { type AgentTriggerReason } from './agent-error-detection.js';
|
||||||
import {
|
import {
|
||||||
@@ -539,7 +535,9 @@ export async function runAgentForGroup(
|
|||||||
outputText.length > 0
|
outputText.length > 0
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
pairedExecutionLifecycle.recordFinalOutputBeforeDelivery(outputText);
|
pairedExecutionLifecycle.recordFinalOutputBeforeDelivery(
|
||||||
|
outputText,
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.warn(
|
log.warn(
|
||||||
{ pairedTaskId: pairedExecutionContext?.task.id ?? null, err },
|
{ pairedTaskId: pairedExecutionContext?.task.id ?? null, err },
|
||||||
@@ -648,7 +646,7 @@ export async function runAgentForGroup(
|
|||||||
runId,
|
runId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return runClaudeAttemptWithRotation({
|
return runClaudeAttemptWithRotation({
|
||||||
initialTrigger,
|
initialTrigger,
|
||||||
runAttempt: () => runAttempt('claude'),
|
runAttempt: () => runAttempt('claude'),
|
||||||
logContext: logCtx,
|
logContext: logCtx,
|
||||||
@@ -811,9 +809,9 @@ export async function runAgentForGroup(
|
|||||||
const finalOutputText = getAgentOutputText(output);
|
const finalOutputText = getAgentOutputText(output);
|
||||||
pairedExecutionLifecycle.updateSummary({
|
pairedExecutionLifecycle.updateSummary({
|
||||||
outputText:
|
outputText:
|
||||||
(typeof finalOutputText === 'string' && finalOutputText.length > 0
|
typeof finalOutputText === 'string' && finalOutputText.length > 0
|
||||||
? finalOutputText
|
? finalOutputText
|
||||||
: null),
|
: null,
|
||||||
errorText:
|
errorText:
|
||||||
typeof output.error === 'string' && output.error.length > 0
|
typeof output.error === 'string' && output.error.length > 0
|
||||||
? output.error
|
? output.error
|
||||||
|
|||||||
@@ -98,7 +98,10 @@ export async function deliverOpenWorkItem(args: {
|
|||||||
}),
|
}),
|
||||||
'Attempting to deliver produced work item as a new message',
|
'Attempting to deliver produced work item as a new message',
|
||||||
);
|
);
|
||||||
await args.channel.sendMessage(args.item.chat_jid, args.item.result_payload);
|
await args.channel.sendMessage(
|
||||||
|
args.item.chat_jid,
|
||||||
|
args.item.result_payload,
|
||||||
|
);
|
||||||
markWorkItemDelivered(args.item.id);
|
markWorkItemDelivered(args.item.id);
|
||||||
args.openContinuation(args.item.chat_jid);
|
args.openContinuation(args.item.chat_jid);
|
||||||
args.log.info(
|
args.log.info(
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
import {
|
import { getLatestOpenPairedTaskForChat, getMessagesSinceSeq } from './db.js';
|
||||||
getLatestOpenPairedTaskForChat,
|
|
||||||
getMessagesSinceSeq,
|
|
||||||
} from './db.js';
|
|
||||||
import {
|
import {
|
||||||
buildQueuedTurnDispatch,
|
buildQueuedTurnDispatch,
|
||||||
executeBotOnlyPairedFollowUpAction,
|
executeBotOnlyPairedFollowUpAction,
|
||||||
@@ -17,7 +14,10 @@ import {
|
|||||||
resolveNextTurnAction,
|
resolveNextTurnAction,
|
||||||
shouldSkipBotOnlyCollaboration,
|
shouldSkipBotOnlyCollaboration,
|
||||||
} from './message-runtime-rules.js';
|
} from './message-runtime-rules.js';
|
||||||
import { extractSessionCommand, isSessionCommandAllowed } from './session-commands.js';
|
import {
|
||||||
|
extractSessionCommand,
|
||||||
|
isSessionCommandAllowed,
|
||||||
|
} from './session-commands.js';
|
||||||
import { isSessionCommandSenderAllowed } from './config.js';
|
import { isSessionCommandSenderAllowed } from './config.js';
|
||||||
import { hasReviewerLease } from './service-routing.js';
|
import { hasReviewerLease } from './service-routing.js';
|
||||||
import type { ScheduledPairedFollowUpIntentKind } from './paired-follow-up-scheduler.js';
|
import type { ScheduledPairedFollowUpIntentKind } from './paired-follow-up-scheduler.js';
|
||||||
@@ -162,7 +162,10 @@ export async function processQueuedGroupDispatch(args: {
|
|||||||
);
|
);
|
||||||
const messagesToSend =
|
const messagesToSend =
|
||||||
pendingMessages.length > 0 ? pendingMessages : processableGroupMessages;
|
pendingMessages.length > 0 ? pendingMessages : processableGroupMessages;
|
||||||
const labeledMessagesToSend = args.labelPairedSenders(chatJid, messagesToSend);
|
const labeledMessagesToSend = args.labelPairedSenders(
|
||||||
|
chatJid,
|
||||||
|
messagesToSend,
|
||||||
|
);
|
||||||
const {
|
const {
|
||||||
formatted,
|
formatted,
|
||||||
botOnlyFollowUpAction,
|
botOnlyFollowUpAction,
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
import { hasAllowedTrigger } from './message-runtime-rules.js';
|
import { hasAllowedTrigger } from './message-runtime-rules.js';
|
||||||
import { handleSessionCommand, type SessionCommandDeps } from './session-commands.js';
|
import {
|
||||||
|
handleSessionCommand,
|
||||||
|
type SessionCommandDeps,
|
||||||
|
} from './session-commands.js';
|
||||||
import type { NewMessage, RegisteredGroup } from './types.js';
|
import type { NewMessage, RegisteredGroup } from './types.js';
|
||||||
|
|
||||||
export async function handleQueuedRunGates(args: {
|
export async function handleQueuedRunGates(args: {
|
||||||
|
|||||||
@@ -63,7 +63,10 @@ export async function processMessageLoopTick(args: {
|
|||||||
intentKind: ScheduledPairedFollowUpIntentKind;
|
intentKind: ScheduledPairedFollowUpIntentKind;
|
||||||
enqueue: () => void;
|
enqueue: () => void;
|
||||||
}) => boolean;
|
}) => boolean;
|
||||||
enqueueScopedGroupMessageCheck: (chatJid: string, groupFolder: string) => void;
|
enqueueScopedGroupMessageCheck: (
|
||||||
|
chatJid: string,
|
||||||
|
groupFolder: string,
|
||||||
|
) => void;
|
||||||
sendQueuedMessage: (chatJid: string, text: string) => boolean;
|
sendQueuedMessage: (chatJid: string, text: string) => boolean;
|
||||||
closeStdin: (chatJid: string, reason: string) => void;
|
closeStdin: (chatJid: string, reason: string) => void;
|
||||||
labelPairedSenders: (chatJid: string, messages: NewMessage[]) => NewMessage[];
|
labelPairedSenders: (chatJid: string, messages: NewMessage[]) => NewMessage[];
|
||||||
@@ -143,7 +146,10 @@ export function recoverPendingMessages(args: {
|
|||||||
getRegisteredGroups: () => Record<string, RegisteredGroup>;
|
getRegisteredGroups: () => Record<string, RegisteredGroup>;
|
||||||
lastAgentTimestamps: Record<string, string>;
|
lastAgentTimestamps: Record<string, string>;
|
||||||
saveState: () => void;
|
saveState: () => void;
|
||||||
enqueueScopedGroupMessageCheck: (chatJid: string, groupFolder: string) => void;
|
enqueueScopedGroupMessageCheck: (
|
||||||
|
chatJid: string,
|
||||||
|
groupFolder: string,
|
||||||
|
) => void;
|
||||||
}): void {
|
}): void {
|
||||||
const registeredGroups = args.getRegisteredGroups();
|
const registeredGroups = args.getRegisteredGroups();
|
||||||
for (const [chatJid, group] of Object.entries(registeredGroups)) {
|
for (const [chatJid, group] of Object.entries(registeredGroups)) {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { getPairedTurnOutputs, getRecentChatMessages } from './db.js';
|
||||||
getPairedTurnOutputs,
|
|
||||||
getRecentChatMessages,
|
|
||||||
} from './db.js';
|
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
import {
|
import {
|
||||||
buildArbiterPromptForTask,
|
buildArbiterPromptForTask,
|
||||||
@@ -45,7 +42,10 @@ type ExecuteTurnFn = (args: {
|
|||||||
visiblePhase: unknown;
|
visiblePhase: unknown;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
type RoleToChannelMap = Record<'owner' | 'reviewer' | 'arbiter', Channel | null>;
|
type RoleToChannelMap = Record<
|
||||||
|
'owner' | 'reviewer' | 'arbiter',
|
||||||
|
Channel | null
|
||||||
|
>;
|
||||||
|
|
||||||
export async function runPendingPairedTurnIfNeeded(args: {
|
export async function runPendingPairedTurnIfNeeded(args: {
|
||||||
chatJid: string;
|
chatJid: string;
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ import {
|
|||||||
normalizeMessageForDedupe,
|
normalizeMessageForDedupe,
|
||||||
} from './router.js';
|
} from './router.js';
|
||||||
import { isTriggerAllowed, loadSenderAllowlist } from './sender-allowlist.js';
|
import { isTriggerAllowed, loadSenderAllowlist } from './sender-allowlist.js';
|
||||||
import {
|
import { enqueueGenericFollowUpAfterDeliveryRetry as enqueueDeliveryRetryFollowUp } from './message-runtime-dispatch.js';
|
||||||
enqueueGenericFollowUpAfterDeliveryRetry as enqueueDeliveryRetryFollowUp,
|
|
||||||
} from './message-runtime-dispatch.js';
|
|
||||||
import {
|
import {
|
||||||
deliverOpenWorkItem,
|
deliverOpenWorkItem,
|
||||||
processOpenWorkItemDelivery,
|
processOpenWorkItemDelivery,
|
||||||
@@ -458,7 +456,10 @@ export function createMessageRuntime(deps: MessageRuntimeDeps): {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Resolve the correct Discord channel for a given task status.
|
// Resolve the correct Discord channel for a given task status.
|
||||||
const roleToChannel: Record<'owner' | 'reviewer' | 'arbiter', Channel | null> = {
|
const roleToChannel: Record<
|
||||||
|
'owner' | 'reviewer' | 'arbiter',
|
||||||
|
Channel | null
|
||||||
|
> = {
|
||||||
owner: channel,
|
owner: channel,
|
||||||
reviewer: foundReviewerChannel || null,
|
reviewer: foundReviewerChannel || null,
|
||||||
arbiter: foundArbiterChannel || null,
|
arbiter: foundArbiterChannel || null,
|
||||||
|
|||||||
Reference in New Issue
Block a user