fix(cli): gate outbound factories by channel id

This commit is contained in:
Gio Della-Libera
2026-05-25 19:55:14 -07:00
parent a93db590f0
commit e5f5e3d23f
2 changed files with 17 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import { normalizeChannelId } from "../channels/registry.js";
import type { OutboundSendDeps } from "../infra/outbound/send-deps.js";
import { createLazyRuntimeSurface } from "../shared/lazy-runtime.js";
import type { CliDeps } from "./deps.types.js";
@@ -25,7 +26,6 @@ const NON_CHANNEL_DEP_KEYS = new Set([
"cronConfig",
"cronEnabled",
"defaultAgentId",
"discordVoice",
"enqueueSystemEvent",
"getQueueSize",
"hasOwnProperty",
@@ -40,7 +40,6 @@ const NON_CHANNEL_DEP_KEYS = new Set([
"runIsolatedAgentJob",
"runtime",
"sendCronFailureAlert",
"sendDiscordVoice",
"sessionStorePath",
"storePath",
"then",
@@ -49,6 +48,10 @@ const NON_CHANNEL_DEP_KEYS = new Set([
"valueOf",
]);
function resolveKnownChannelId(raw: string): string | undefined {
return normalizeChannelId(raw) ?? undefined;
}
// Per-channel module caches for lazy loading.
const senderCache = new Map<string, Promise<RuntimeSend>>();
@@ -102,7 +105,11 @@ export function createDefaultDeps(): CliDeps {
if (existing !== undefined || NON_CHANNEL_DEP_KEYS.has(property)) {
return existing;
}
const sender = resolveSender(property);
const channelId = resolveKnownChannelId(property);
if (!channelId) {
return existing;
}
const sender = resolveSender(channelId);
Reflect.set(target, property, sender, receiver);
return sender;
},

View File

@@ -1,3 +1,4 @@
import { normalizeChannelId } from "../channels/registry.js";
import {
resolveLegacyOutboundSendDepKeys,
type OutboundSendDeps,
@@ -18,8 +19,6 @@ export type CliOutboundSendSource = {
[CLI_OUTBOUND_SEND_FACTORY]?: CliOutboundSendFactory;
};
const NON_CHANNEL_OUTBOUND_KEYS = new Set(["discordVoice", "discordvoice", "sendDiscordVoice"]);
function normalizeLegacyChannelStem(raw: string): string {
const normalized = normalizeLowercaseStringOrEmpty(
raw
@@ -48,6 +47,10 @@ function resolveChannelIdFromLegacyOutboundKey(key: string): string | undefined
return normalizedStem || undefined;
}
function resolveKnownChannelId(raw: string): string | undefined {
return normalizeChannelId(raw) ?? undefined;
}
/**
* Pass CLI send sources through as-is — both CliOutboundSendSource and
* OutboundSendDeps are now channel-ID-keyed records.
@@ -84,17 +87,12 @@ export function createOutboundSendDepsFromCliSource(deps: CliOutboundSendSource)
}
const resolveFactoryValue = (key: string): unknown => {
if (NON_CHANNEL_OUTBOUND_KEYS.has(key)) {
return undefined;
}
const channelId =
const candidate =
outbound[key] === undefined ? (resolveChannelIdFromLegacyOutboundKey(key) ?? key) : key;
const channelId = resolveKnownChannelId(candidate);
if (!channelId || channelId === "then" || channelId === "toJSON") {
return undefined;
}
if (NON_CHANNEL_OUTBOUND_KEYS.has(channelId)) {
return undefined;
}
const value = sendFactory(channelId);
if (value !== undefined) {
outbound[channelId] = value;