import { r as redactToolDetail } from "../redact-oXJoCM7I.js";
import { r as formatErrorMessage } from "../errors-CGMew-1w.js";
import { b as truncateUtf16Safe, m as resolveUserPath } from "../utils-CE5zxr9Z.js";
import { n as VERSION } from "../version-CL-VJOV3.js";
import { x as isSubagentSessionKey } from "../session-key-NGoeHrFI.js";
import { a as resolveAgentDir, y as resolveSessionAgentIds } from "../agent-scope-BA9YeMqS.js";
import { t as emitSessionTranscriptUpdate } from "../transcript-events-D3cOzr3J.js";
import { a as normalizeUsage } from "../usage-BOqkinpp.js";
import { i as resolveBootstrapContextForRun } from "../bootstrap-files-7_zENDFm.js";
import { c as resolveModelAuthMode } from "../model-auth-BqWY8X0_.js";
import { F as isToolWrappedWithBeforeToolCallHook, I as runBeforeToolCallHook, L as wrapToolWithBeforeToolCallHook, R as supportsModelTools, a as resolveAttemptSpawnWorkspaceDir, h as resolveCompactionTimeoutMs, n as normalizeProviderToolSchemas } from "../tool-schema-runtime-oH5gpy2r.js";
import { a as selectDefaultNodeFromList, i as resolveNodeIdFromList, o as callGatewayTool, t as listNodes } from "../nodes-utils-BEupCx9p.js";
import { r as resolveToolDisplay, t as formatToolDetail } from "../tool-display-C_AaHeLj.js";
import { d as resetAgentEventsForTest, i as emitAgentEvent, l as onAgentEvent } from "../agent-events-Ca1q9xo_.js";
import { c as resolveActiveEmbeddedRunSessionId, l as setActiveEmbeddedRun, n as clearActiveEmbeddedRun, t as abortEmbeddedPiRun } from "../runs-gYao2sT0.js";
import { o as resolveSandboxContext } from "../sandbox-FMmpzkFU.js";
import { t as log } from "../logger-B9bYCVGh.js";
import { c as filterToolResultMediaUrls, f as isMessagingTool, m as formatToolAggregate, n as shouldPreemptivelyCompactBeforePrompt, o as extractToolResultMediaArtifact, p as isMessagingToolSendAction, r as buildEmbeddedAttemptToolRunContext, t as PREEMPTIVE_OVERFLOW_ERROR_TEXT } from "../preemptive-compaction-DxNiB9C7.js";
//#region src/plugin-sdk/agent-harness-runtime.ts
const TOOL_PROGRESS_OUTPUT_MAX_CHARS = 8e3;
function queueAgentHarnessMessage(sessionId, text) {
	return abortEmbeddedPiRun(sessionId) && false;
}
async function loadCodexBundleMcpThreadConfig(_params) {
	throw new Error("loadCodexBundleMcpThreadConfig: codex-mcp-config not yet ported to KaijiBot");
}
function inferToolMetaFromArgs(toolName, args, _options) {
	return formatToolDetail(resolveToolDisplay({
		name: toolName,
		args
	}));
}
/**
* Prepare verbose tool output for user-facing progress messages.
*/
function formatToolProgressOutput(output, options) {
	const trimmed = output.replace(/\r\n/g, "\n").replace(/\r/g, "\n").trim();
	if (!trimmed) return;
	const redacted = redactToolDetail(trimmed);
	const maxChars = options?.maxChars ?? 8e3;
	if (redacted.length <= maxChars) return redacted;
	return `${truncateUtf16Safe(redacted, maxChars)}\n...(truncated)...`;
}
/**
* Classify terminal harness turns that completed without assistant output that
* should advance fallback. Deliberate silent replies such as NO_REPLY count as
* intentional output, while whitespace-only text remains fallback-eligible.
* This is intentionally SDK-level so plugin harness adapters such as Codex
* preserve the same KaijiBot-owned fallback signals as the built-in PI path
* without re-implementing terminal-result policy.
*/
function classifyAgentHarnessTerminalOutcome(params) {
	if (!params.turnCompleted || params.promptError !== void 0 && params.promptError !== null || hasVisibleAssistantText(params.assistantTexts)) return;
	if (params.planText?.trim()) return "planning-only";
	if (params.reasoningText?.trim()) return "reasoning-only";
	return "empty";
}
function hasVisibleAssistantText(assistantTexts) {
	return assistantTexts.some((text) => text.trim().length > 0);
}
//#endregion
export { VERSION as KAIJIBOT_VERSION, PREEMPTIVE_OVERFLOW_ERROR_TEXT, TOOL_PROGRESS_OUTPUT_MAX_CHARS, abortEmbeddedPiRun as abortAgentHarnessRun, buildEmbeddedAttemptToolRunContext, callGatewayTool, classifyAgentHarnessTerminalOutcome, clearActiveEmbeddedRun, log as embeddedAgentLog, emitAgentEvent, emitSessionTranscriptUpdate, extractToolResultMediaArtifact, filterToolResultMediaUrls, formatErrorMessage, formatToolAggregate, formatToolProgressOutput, inferToolMetaFromArgs, isMessagingTool, isMessagingToolSendAction, isSubagentSessionKey, isToolWrappedWithBeforeToolCallHook, listNodes, loadCodexBundleMcpThreadConfig, normalizeProviderToolSchemas, normalizeUsage, onAgentEvent, queueAgentHarnessMessage, resetAgentEventsForTest, resolveActiveEmbeddedRunSessionId, resolveAgentDir, resolveAttemptSpawnWorkspaceDir, resolveBootstrapContextForRun, resolveCompactionTimeoutMs, resolveModelAuthMode, resolveNodeIdFromList, resolveSandboxContext, resolveSessionAgentIds, resolveUserPath, runBeforeToolCallHook, selectDefaultNodeFromList, setActiveEmbeddedRun, shouldPreemptivelyCompactBeforePrompt, supportsModelTools, wrapToolWithBeforeToolCallHook };
