feat: add structured silent output contract

This commit is contained in:
Eyejoker
2026-03-28 05:56:58 +09:00
parent e1fdc47552
commit fe6314108c
13 changed files with 346 additions and 52 deletions

View File

@@ -1,6 +1,8 @@
import { getAgentOutputText } from './agent-output.js';
import type { NewMessage } from './types.js';
import { logger } from './logger.js';
import { formatOutbound } from './router.js';
import type { StructuredAgentOutput } from './types.js';
const SESSION_COMMAND_CONTROL_PATTERNS = [
/^Current session cleared\. The next message will start a new conversation\.$/,
@@ -48,6 +50,7 @@ export function isSessionCommandControlMessage(content: string): boolean {
export interface AgentResult {
status: 'success' | 'error';
result?: string | object | null;
output?: StructuredAgentOutput;
}
/** Dependencies injected by the orchestrator. */
@@ -73,6 +76,14 @@ function resultToText(result: string | object | null | undefined): string {
return formatOutbound(raw);
}
function agentResultToText(result: AgentResult): string {
const raw = getAgentOutputText({
result: result.result ?? null,
output: result.output,
});
return raw ? formatOutbound(raw) : '';
}
/**
* Handle session command interception in processGroupMessages.
* Scans messages for a session command, handles auth + execution.
@@ -149,7 +160,7 @@ export async function handleSessionCommand(opts: {
const preResult = await deps.runAgent(prePrompt, async (result) => {
if (result.status === 'error') hadPreError = true;
const text = resultToText(result.result);
const text = agentResultToText(result);
if (text) {
await deps.sendMessage(text);
preOutputSent = true;
@@ -185,7 +196,7 @@ export async function handleSessionCommand(opts: {
let hadCmdError = false;
const cmdOutput = await deps.runAgent(command, async (result) => {
if (result.status === 'error') hadCmdError = true;
const text = resultToText(result.result);
const text = agentResultToText(result);
if (text) await deps.sendMessage(text);
});