// Force strict mode and setup for ESM
"use strict";
import {
  isTeammate
} from "./chunk-GO6LNQXT.js";
import {
  ToolNames
} from "./chunk-4VZH35PN.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/core/src/agents/runtime/agent-context.ts
init_esbuild_shims();
import { AsyncLocalStorage } from "node:async_hooks";
var storage = new AsyncLocalStorage();
function runWithAgentContext(agentId, fn) {
  const current = storage.getStore() ?? {};
  const depth = (current.depth ?? -1) + 1;
  return storage.run({ ...current, agentId, depth }, fn);
}
__name(runWithAgentContext, "runWithAgentContext");
function runWithRuntimeContentGenerator(view, fn) {
  const current = storage.getStore() ?? {};
  return storage.run({ ...current, runtimeView: view }, fn);
}
__name(runWithRuntimeContentGenerator, "runWithRuntimeContentGenerator");
function getCurrentAgentId() {
  return storage.getStore()?.agentId ?? null;
}
__name(getCurrentAgentId, "getCurrentAgentId");
function getCurrentAgentDepth() {
  return storage.getStore()?.depth ?? 0;
}
__name(getCurrentAgentDepth, "getCurrentAgentDepth");
function getRuntimeContentGenerator() {
  return storage.getStore()?.runtimeView;
}
__name(getRuntimeContentGenerator, "getRuntimeContentGenerator");

// packages/core/src/agents/runtime/subagent-plan-tool-policy.ts
init_esbuild_shims();
var SUBAGENT_PLAN_LIFECYCLE_TOOLS = /* @__PURE__ */ new Set([
  ToolNames.ENTER_PLAN_MODE,
  ToolNames.EXIT_PLAN_MODE
]);
function isSubagentLikeExecutionContext() {
  return getCurrentAgentId() !== null || isTeammate();
}
__name(isSubagentLikeExecutionContext, "isSubagentLikeExecutionContext");
function isPlanLifecycleToolUnavailableInSubagent(toolName) {
  return isSubagentLikeExecutionContext() && SUBAGENT_PLAN_LIFECYCLE_TOOLS.has(toolName);
}
__name(isPlanLifecycleToolUnavailableInSubagent, "isPlanLifecycleToolUnavailableInSubagent");
function getSubagentPlanToolUnavailableMessage(toolName) {
  return `${toolName} is not available inside subagents or team agents. Plan mode is owned by the caller/main session; return your plan, findings, or constraints to the caller in your normal response instead of entering or exiting plan mode.`;
}
__name(getSubagentPlanToolUnavailableMessage, "getSubagentPlanToolUnavailableMessage");
function buildSubagentPlanToolBlockedResult(toolName, logTag, logger) {
  const message = getSubagentPlanToolUnavailableMessage(toolName);
  logger.warn(
    `[${logTag}] Blocked plan lifecycle tool call from subagent: ${toolName}`
  );
  return {
    llmContent: message,
    returnDisplay: message,
    error: { message }
  };
}
__name(buildSubagentPlanToolBlockedResult, "buildSubagentPlanToolBlockedResult");

export {
  runWithAgentContext,
  runWithRuntimeContentGenerator,
  getCurrentAgentId,
  getCurrentAgentDepth,
  getRuntimeContentGenerator,
  SUBAGENT_PLAN_LIFECYCLE_TOOLS,
  isSubagentLikeExecutionContext,
  isPlanLifecycleToolUnavailableInSubagent,
  getSubagentPlanToolUnavailableMessage,
  buildSubagentPlanToolBlockedResult
};
/**
 * @license
 * Copyright 2025 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
