Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

51.1 KB
Raw Blame
import {createWorkspaceArtifactAdmission,createWorkspaceArtifactTool} from './workspace-artifact.mjs';
import {createAgentSkillTool} from './agent-skills.mjs';
import {registerProjectBuild} from './project-registration.mjs';
import {createProjectRunControl} from './project-run-control.mjs';
import {registerBootstrapCapabilities} from './bootstrap-capabilities.mjs';
import {registerStableRuntimeLine} from './runtime-line.mjs';
import {executionLocationContext} from './execution-location.mjs';
import {createRuntimeIdentity} from './runtime-identity.mjs';
import {fileURLToPath} from 'node:url';
import {subagentDeliveryFor,delegationAccessIdentity} from './subagent-delivery.mjs';
import {createActivityTool, ACTIVITY_CONTRACT} from './activity-display.mjs';
import {inResponseLanguage, readResponseLanguage, responseLanguageTurnContext} from './response-language.mjs';
import {previewRecoveryAllowed} from './preview-delivery-recovery.mjs';
import {compactToolResultEnvelope} from './tool-result-envelope.mjs';
import {withPiToolErrorContract} from './pi-tool-result.mjs';
import {createGoalProgress, createGoalProgressTool, GOAL_CONTRACT} from './goal-progress.mjs';
// Pixel ODS integration plugin entry.
//
// Registers status projection tools plus one targeted, strictly guarded public
// page extractor for the Pixel agent only. Status data is untrusted evidence,
// never authority; targeted web content is explicitly bounded and marked
// untrusted before it reaches the model.

import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import {
  abortAgentHarnessRun,
  abortAndDrainAgentHarnessRun,
  callGatewayTool,
  resolveActiveEmbeddedRunSessionId,
  resolveUserPath,
} from "openclaw/plugin-sdk/agent-harness-runtime";
import {getSessionEntry, patchSessionEntry, resolveStorePath} from "openclaw/plugin-sdk/session-store-runtime";
import {withSessionTranscriptWriteLock,appendAssistantMirrorMessageByIdentity} from 'openclaw/plugin-sdk/session-transcript-runtime';
import {
  extractBasicHtmlContent,
  extractAssistantVisibleText,
  fetchWithWebToolsNetworkGuard,
  readResponseText,
  resolveAgentWorkspaceDir,
} from "openclaw/plugin-sdk/agent-runtime";
import {
  appsPayload,
  readProjection,
  statusFileFromEnv,
  statusPayload,
} from "./projection.mjs";
import { promptContractForAgent } from "./prompt-contract.mjs";
import { executionContext } from "./completion-assurance.mjs";
import { createAskUserTool } from "./ask-user.mjs";
import { createPendingClarifications } from "./pending-clarification.mjs";
import {
  appsToolText,
  statusToolText,
  unavailableToolText,
} from "./tool-content.mjs";
import {
  createExecCancellationControl,
  createRunAbortAdapter,
  createToolLoopGuardRegistry,
  managedTeamRole,
  privateBrowserAccessForAgent,
} from "./tool-loop-guard.mjs";
import { withPixelCronDeliveryDefault } from "./cron-delivery-default.mjs";
import { withCronCommandPayloadBlock } from "./cron-command-payload-guard.mjs";
import { withPixelSubagentWorkspace } from "./subagent-workspace.mjs";
import { createPublicPageReader, createPublicWebExtractTool } from "./web-extract.mjs";
import { citationPageReadsAllowed, createHostCitationVerifier } from "./citation-verification.mjs";
import { createStopSynthesisClient } from "./stop-synthesis.mjs";
import { createExtensionRepositoryContext } from './extension-repository-context.mjs';

const extensionRepositoryContext = createExtensionRepositoryContext({
  tool: createPublicWebExtractTool({
    guardedFetch: fetchWithWebToolsNetworkGuard, readResponseText, extractBasicHtmlContent,
  }),
});
import { createPerplexicaAvailability, createPerplexicaResearchTool, researchOutputChars,
  researchToolWhenAvailable } from "./perplexica-research.mjs";
import { createDownloadPromoteTool } from "./download-promote.mjs";
import {
  createExtensionReadTool,
  createHostCommandProposeTool,
  createHostObserveTool,
} from "./host-observe.mjs";
import { createEvidenceArtifactWriter } from "./evidence-artifact.mjs";
import { createWorkspacePreviewPublisher, createWorkspacePreviewTool, createWorkspacePreviewVerifier } from "./workspace-preview.mjs";
import { createExampleProjectRoute } from "./example-projects.mjs";
import { createWorkspacePreviewInspectTool } from "./workspace-preview-inspect.mjs";
import { previewScreenshotCapability } from "./preview-screenshot.mjs";
import {createWorkspaceBundleAdmission, createWorkspaceBundleService, createWorkspaceBundleTool} from './workspace-bundle.mjs';
import {createWorkspaceBundleExecution} from './workspace-bundle-execution.mjs';
import { createTaskActivity } from "./task-activity.mjs";
import { createWorkspaceProjects } from "./workspace-projects.mjs";
import { createAccessRuntime, executionHostForAgent } from "./access-runtime.mjs";
import { createManagedRuntimeRegistry } from "./managed-runtime-lifecycle.mjs";
import {createContextCompaction, readContextRequest, prepareStableContextModel} from './context-compaction.mjs';
import {registerHistoryIntegration} from './history-context.mjs';
import {createConversationImageLifecycle} from './conversation-image-lifecycle.mjs';
import {createChatImageReadTool,CHAT_IMAGE_READ_TOOL} from './chat-image-read.mjs';
import {readConversationImage,readConversationImagePolicy} from './chat-image-transport.mjs';
import {createExtensionProposalTool, createSourceProposalTool, createPythonLibraryProposalTool, createExtensionRequestStatusTool, createExtensionRequestPrepareTool, createExtensionRequestAdvanceTool, createExtensionRequestRetryTool, submitExtensionProposal} from './extension-proposal.mjs';
import { createOpenClawCodingTools, resolveSandboxContext, OPENCLAW_VERSION } from "openclaw/plugin-sdk/agent-harness";

const AGENT_ID = process.env.PIXEL_AGENT_ID ?? "pixel";
let runtimeIdentity;
const ABORT_BODY_LIMIT = 256;
const OPENAI_RUN_ID = /^chatcmpl_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
const toolLoopGuardRegistry = createToolLoopGuardRegistry();
const projectRunControl = createProjectRunControl();
const goalProgress = createGoalProgress({agentId:AGENT_ID});
const workspaceProjects = createWorkspaceProjects();
// A clarification card's answer gets its request back as model-only context,
// even when OpenClaw runs it in a replacement native session. Conversation
// deletion removes the chat's card with its transcripts.
const pendingClarifications = createPendingClarifications();
const taskActivity = createTaskActivity({agentId:AGENT_ID, goalForRun:id=>goalProgress.projection(id),projectsForSession:key=>workspaceProjects.forSession(key)});
let execCancellationControl;
let accessRuntime;
let contextCompaction;
let conversationImageLifecycle;
let currentManagedRuntime;
const managedRuntimeRegistry = createManagedRuntimeRegistry();
const evidenceArtifactWriter = createEvidenceArtifactWriter();
let perplexicaAvailability;
const bundleAdmission = createWorkspaceBundleAdmission();
const artifactAdmission = createWorkspaceArtifactAdmission();

// Restrict tool registration to the Pixel agent. Tools are only offered to the
// agent id declared by this plugin (see openclaw.plugin.json); this guards the
// registration path regardless of how the plugin is loaded.
const onlyPixel = (factory) => (context) => {
  if (context.agentId !== AGENT_ID) return null;
  const tool = withPiToolErrorContract(factory(context));
  runtimeIdentity?.observeTool(tool);
  return tool;
};

function registerTool(api, tool, opts) {
  const names = opts.names || [tool.name];
  api.registerTool(onlyPixel(() => tool), { names });
}

function toolResult(projection, details, text) {
  return {
    content: [
      {
        type: "text",
        text,
      },
    ],
    details: { ...details, projection },
  };
}

function statusDetails(projection) {
  return {
    boundary: "status-only",
    evidence: "untrusted status projection",
    timestamp: projection.timestamp,
    stale: projection.stale,
    ingress_ready: projection.ingress_ready,
    gateway_reachable: projection.gateway_reachable,
    docker: projection.docker,
    ods_version: projection.ods_version,
    online_app_count: projection.online_app_count,
    app_count: projection.app_count,
    runtime: projection.runtime,
  };
}

function appsDetails(projection) {
  return {
    boundary: "status-only",
    evidence: "untrusted status projection",
    timestamp: projection.timestamp,
    stale: projection.stale,
    app_count: projection.app_count,
    online_app_count: projection.online_app_count,
  };
}

function errorResult() {
  // Generic only: no path, no raw content, no environment detail.
  return {
    content: [
      {
        type: "text",
        text: unavailableToolText(),
      },
    ],
    details: { boundary: "status-only", evidence: "untrusted status projection" },
  };
}

function guardedEvidenceAdapterResult() {
  return {
    content: [{
      type: "text",
      text: "This evidence adapter is available only inside a guard-verified host report continuation.",
    }],
    details: { boundary: "guard-only evidence adapter" },
    isError: true,
  };
}

function sendJson(res, status, payload) {
  const body = JSON.stringify(payload);
  res.statusCode = status;
  res.setHeader("Content-Type", "application/json");
  res.setHeader("Cache-Control", "no-store");
  res.end(body);
}

async function readAbortUser(req) {
  if (req.method !== "POST") return { status: 405 };
  const contentType = String(req.headers["content-type"] ?? "").toLowerCase();
  if (contentType.split(";", 1)[0].trim() !== "application/json") return { status: 415 };
  const chunks = [];
  let total = 0;
  for await (const chunk of req) {
    total += chunk.length;
    if (total > ABORT_BODY_LIMIT) return { status: 413 };
    chunks.push(chunk);
  }
  try {
    const body = JSON.parse(Buffer.concat(chunks, total).toString("utf8"));
    if (
      !body ||
      typeof body !== "object" ||
      Array.isArray(body) ||
      Object.keys(body).length !== 1 ||
      typeof body.user !== "string" ||
      !/^ods-[0-9a-f]{64}$/.test(body.user)
    ) {
      return { status: 400 };
    }
    return { status: 200, user: body.user };
  } catch {
    return { status: 400 };
  }
}

async function readVerificationRun(req) {
  if (req.method !== "POST") return { status: 405 };
  const contentType = String(req.headers["content-type"] ?? "").toLowerCase();
  if (contentType.split(";", 1)[0].trim() !== "application/json") return { status: 415 };
  const chunks = [];
  let total = 0;
  for await (const chunk of req) {
    total += chunk.length;
    if (total > ABORT_BODY_LIMIT) return { status: 413 };
    chunks.push(chunk);
  }
  try {
    const body = JSON.parse(Buffer.concat(chunks, total).toString("utf8"));
    if (
      !body ||
      typeof body !== "object" ||
      Array.isArray(body) ||
      Object.keys(body).length !== 1 ||
      typeof body.runId !== "string" ||
      !OPENAI_RUN_ID.test(body.runId)
    ) {
      return { status: 400 };
    }
    return { status: 200, runId: body.runId };
  } catch {
    return { status: 400 };
  }
}

export default definePluginEntry({
  id: "pixel-ods",
  name: "Pixel ODS Integration",
  description: "Read-only ODS status and strictly guarded public-page evidence for Pixel.",
  register(api) {
    // Discovery tools and build-time schema captures must never read host state.
    // Failure to collect diagnostics must also never prevent agent registration.
    if (api.registrationMode !== 'discovery' && !runtimeIdentity) {
      let pluginRoot, modulePath;
      try {
        pluginRoot = fileURLToPath(new URL('.', import.meta.url));
        modulePath = fileURLToPath(new URL('../tool-search-BInRpkE3.js', import.meta.resolve('openclaw/plugin-sdk/agent-harness')));
      } catch { /* preserve explicit unknown observations */ }
      runtimeIdentity = createRuntimeIdentity({pluginRoot, modulePath, openclawVersion:OPENCLAW_VERSION});
    }
    execCancellationControl ??= createExecCancellationControl({
      executionHost: executionHostForAgent(api.config, AGENT_ID),
    });
    accessRuntime ??= createAccessRuntime({config: () => api.config,
      settingsConfig: typeof api.runtime?.config?.current === 'function' ? () => api.runtime.config.current() : undefined,
      createTools: createOpenClawCodingTools, resolveSandbox: resolveSandboxContext,
      execControl: () => execCancellationControl, runtimeVersion: OPENCLAW_VERSION,
      hooksAllowed: api.config?.plugins?.entries?.["pixel-ods"]?.hooks?.allowConversationAccess === true});
    registerBootstrapCapabilities(api);
    const managedRuntime = managedRuntimeRegistry.register(api, accessRuntime);
    if (managedRuntime) currentManagedRuntime = managedRuntime;
    contextCompaction ??= createContextCompaction({agentId:AGENT_ID,
      readConfig:() => api.runtime?.config?.current?.() ?? api.config,
      readSession:scope => getSessionEntry({...scope,
        storePath:resolveStorePath((api.runtime?.config?.current?.() ?? api.config)?.session?.store, {agentId:AGENT_ID})}),
      callGateway:callGatewayTool,
      prepareModel:scope => {
        if (currentManagedRuntime) {
          // Per-turn managed routes need their own qualified maintenance lease;
          // never replay an expired turn token or bypass handoff approval.
          if (typeof currentManagedRuntime.prepareCompaction === 'function') return currentManagedRuntime.prepareCompaction(scope);
          throw Object.assign(new Error('managed compaction unavailable'),{code:'unsupported-model'});
        }
        return prepareStableContextModel(scope);
      },
      activeSession:key => Boolean(resolveActiveEmbeddedRunSessionId(key)),
      admission:{status:() => currentManagedRuntime?.status() ?? accessRuntime.status(),
        acquire:(token, revision) => currentManagedRuntime ? currentManagedRuntime.acquireMaintenance(token, revision)
          : accessRuntime.acquireMaintenance(token, revision),
        release:token => currentManagedRuntime ? currentManagedRuntime.releaseMaintenance(token)
          : accessRuntime.releaseMaintenance(token), owns:token => accessRuntime.owns(token)},
    });
    registerHistoryIntegration(api,{compactor:contextCompaction,getSessionEntry,patchSessionEntry,resolveStorePath,withSessionTranscriptWriteLock,appendAssistantMirrorMessageByIdentity});
    conversationImageLifecycle ??= createConversationImageLifecycle({
      readConfig:()=>api.runtime?.config?.current?.()??api.config,
      getSessionEntry,patchSessionEntry,resolveStorePath,callGateway:callGatewayTool,compactor:contextCompaction,
      forgetConversation:sessionKey=>pendingClarifications.forget(sessionKey),
    });
    conversationImageLifecycle.register(api);
    api.on('before_agent_run',(_event,context)=>{
      try {conversationImageLifecycle.observe(context);}
      catch {return {outcome:'block',reason:'conversation-image-custody-unavailable',message:'This conversation is deleted or its private image custody could not be confirmed. Start a new conversation or retry after checking storage.'};}
    });
    api.registerTool(onlyPixel(context=>createChatImageReadTool(context,{
      getSessionEntry,resolveStorePath,
      readConfig:()=>api.runtime?.config?.current?.()??api.config,
      readImage:readConversationImage,
      imagePolicyForContext:async trustedContext=>{
        const user=trustedContext.sessionKey.slice('agent:pixel:openai-user:'.length);
        return (await readConversationImagePolicy(user)).policy;
      },
    })),{names:[CHAT_IMAGE_READ_TOOL]});
    // One system prompt for every Pixel chat: no per-chat session key or id.
    registerStableRuntimeLine(api);
    const statusFile = statusFileFromEnv();
    const configuredContextWindow = api.pluginConfig?.modelContextWindow;
    const configuredLeanPrompt = api.pluginConfig?.leanPrompt === true;
    // An owner can fix Pixel to English (PIXEL_RESPONSE_LANGUAGE=en in .env).
    const configuredResponseLanguage = readResponseLanguage(undefined, message => api.logger.warn(message));
    // OpenClaw registers gateway HTTP routes and per-agent runtime hooks in
    // separate passes. Keep one process-local guard so the route can see the
    // opaque user -> active session mapping observed by the runtime hook.
    const toolLoopGuard = toolLoopGuardRegistry.get({
      abortRun: createRunAbortAdapter({resolveSessionId:resolveActiveEmbeddedRunSessionId,
        abort:abortAgentHarnessRun}),
      abortRunAndDrain: (sessionId, sessionKey) =>
        abortAndDrainAgentHarnessRun({
          sessionId: (sessionKey && resolveActiveEmbeddedRunSessionId(sessionKey)) || sessionId,
          sessionKey,
          settleMs: 4000,
          forceClear: false,
          reason: "ods_client_disconnect",
        }),
      execControl: execCancellationControl,
      cancelProjectRun: scope => projectRunControl.cancel(scope),
      evidenceArtifactWriter,
      onWorkspaceMutation:mutation=>workspaceProjects.record(mutation),
      verifyWorkspacePreview:createWorkspacePreviewVerifier({transport:api.pluginConfig?.workspacePreviewTransport}),
      workspacePreviewInspectionAvailable: ["unix", "native"].includes(api.pluginConfig?.workspacePreviewInspectionTransport),
      publishWorkspacePreview: previewRecoveryAllowed(api.config) ? (params, {signal}) =>
        createWorkspacePreviewTool({transport:api.pluginConfig?.workspacePreviewTransport})
          .execute('ods-preview-delivery', params, signal) : undefined,
      // Cited pages the model never opened are read once by the host through
      // the same strict guard as pixel_ods_web_extract, only where the
      // operator's configuration permits page reads.
      hostCitationVerifier: createHostCitationVerifier({
        readPage: createPublicPageReader({
          guardedFetch: fetchWithWebToolsNetworkGuard, readResponseText, extractBasicHtmlContent,
        }),
        allowed: () => citationPageReadsAllowed(api.runtime?.config?.current?.() ?? api.config, AGENT_ID),
      }),
      // After a tool-limit stop without an answer: one tool-free completion by
      // the same configured model, from the pages the run read.
      stopSynthesis: createStopSynthesisClient({runtime: api.runtime, agentId: AGENT_ID}),
      responseLanguage: configuredResponseLanguage,
      pendingClarifications,
      // The final reply a failed preview delivery keeps is the visible text of
      // the transcript's last assistant message, as the harness computes it.
      finalText: extractAssistantVisibleText,
      warn: (message) => api.logger.warn(message),
      info: (message) => api.logger.info?.(message),
      exampleOwnerRun: context => delegationDelivery.ownerRunOf(context),
      // Only a remote API route carries a route fingerprint
      // (model-runtime-readback.mjs); its output limit is the owner's setting.
      remoteModelRoute: () => typeof (api.runtime?.config?.current?.() ?? api.config)
        ?.plugins?.entries?.['pixel-ods']?.config?.modelRouteFingerprint === 'string',
    });
    const bundleExecution = createWorkspaceBundleExecution({
      readConfig: () => api.runtime?.config?.current?.() ?? api.config,
      createTools: createOpenClawCodingTools, resolveSandbox: resolveSandboxContext,
      execControl: () => execCancellationControl,
    });
    const delegationDelivery = subagentDeliveryFor(toolLoopGuard, {
      agentId:AGENT_ID,
      finalText:extractAssistantVisibleText,
      accessIdentity:() => {
        const state=accessRuntime.status();
        return delegationAccessIdentity(api.runtime?.config?.current?.() ?? api.config,state);
      },
      resolveOwnerSession:sessionKey => {
        const config=api.runtime?.config?.current?.() ?? api.config;
        return getSessionEntry({sessionKey,storePath:resolveStorePath(config?.session?.store,{agentId:AGENT_ID})});
      },
      verificationForRun:runId => toolLoopGuard.deliveryVerificationForRun(runId),
      abortSession:async sessionKey => {
        const sessionId=resolveActiveEmbeddedRunSessionId(sessionKey);
        if (!sessionId) return true; // Native active-run registry reports no running harness.
        await abortAndDrainAgentHarnessRun({sessionId,sessionKey,settleMs:4000,forceClear:false,reason:'ods_client_disconnect'});
        return !resolveActiveEmbeddedRunSessionId(sessionKey);
      },
    });
    api.on('subagent_spawned',(event,context)=>delegationDelivery.nativeSpawn(event,context));
    api.on('gateway_stop',()=>delegationDelivery.invalidate());
    const executeBundle = createWorkspaceBundleService({runHelper: bundleExecution.runHelper,
      invalidatePreview: scope => toolLoopGuard.invalidateWorkspaceBundle(scope)});
    api.registerTool(onlyPixel(context => createWorkspaceBundleTool(context, {
      admission: bundleAdmission, execute: executeBundle, scopeForContext: bundleExecution.scopeForContext,
    })), {names: ['pixel_ods_workspace_bundle']});

    // OpenClaw does not replay arbitrary plugin tools after an empty model
    // continuation. Give the Pixel agent an explicit, trusted prompt contract
    // so every ODS lookup is followed by a user-visible answer.
    api.on("before_prompt_build", async (event, context) => {
      // A canceled child's queued announcement must not replace the guard's
      // active owner mapping. The enforced before_agent_run gate below also
      // rejects it before inference; this prompt hook cannot veto execution.
      if (!accessRuntime.isProbe(context) && delegationDelivery.admission(context)) return;
      const privateBrowserAccess = privateBrowserAccessForAgent(api.config, AGENT_ID);
      const workspaceRoot = api.config?.agents?.list?.find(agent => agent.id === AGENT_ID)?.workspace
        ?? api.config?.agents?.defaults?.workspace;
      const executionHost = executionHostForAgent(api.config, AGENT_ID);
      // The run deadline the runtime just armed for this attempt.
      const runTimeoutSeconds = (api.runtime?.config?.current?.() ?? api.config)?.agents?.defaults?.timeoutSeconds;
      toolLoopGuard.observeRun(context, AGENT_ID, event, { privateBrowserAccess, workspaceRoot, executionHost, runTimeoutSeconds });
      // After delegation custody, which links a child or continuation to its
      // owner run: the shipped example's guard starts with the run.
      if (!accessRuntime.isProbe(context)) { delegationDelivery.observe(event,context); toolLoopGuard.observeExampleRun(context, AGENT_ID); }
      const ownerEvent = toolLoopGuard.ownerIntentEventForRun(context?.runId ?? event?.runId, event);
      if (!accessRuntime.isProbe(context)) { goalProgress.begin(ownerEvent, context); taskActivity.begin(ownerEvent, {...context,workspaceRoot}); }
      const contract = promptContractForAgent(context, AGENT_ID, ownerEvent, {
        verificationStatus: toolLoopGuard.verificationStatus(context?.runId),
        configuredContextWindow,
        configuredLeanPrompt,
        configuredResponseLanguage,
        privateBrowserAccess,
        executionHost,
      });
      const repositoryEvidence = contract ? await extensionRepositoryContext(ownerEvent,
        result => toolLoopGuard.observeRepositorySource(context?.runId ?? event?.runId, result)) : '';
      // Per-attempt, model-only context: not part of the cached system prompt.
      const cancelContext = toolLoopGuard.promptContextForRun(context?.runId ?? event?.runId);
      const deliveryContext = delegationDelivery.promptContext(context);
      // A turn that mentions the shipped example without naming it.
      const exampleContext = toolLoopGuard.exampleContextForRun(context?.runId ?? event?.runId);
      const prependContext = [contract?.prependContext,cancelContext,deliveryContext,exampleContext].filter(Boolean).join('\n\n');
      // Beside the owner turn (OpenClaw appendContext), also model-only. A
      // child's announce continuation of a clarification answer carries that
      // answer's note too: in a replacement session only the note names the
      // request, and the answer run's success already settled the card.
      // Portal wrote most of a team or goal message: a note says where the
      // owner's own words are, for the response-language rule. English-only
      // mode puts its reminder there instead, on every turn.
      const languageNote = responseLanguageTurnContext(configuredResponseLanguage,
        {goal: goalProgress.active(context?.runId ?? event?.runId), teamRole: managedTeamRole(ownerEvent)});
      const goalContract = inResponseLanguage(GOAL_CONTRACT, configuredResponseLanguage);
      const appendContext = [goalProgress.active(context?.runId ?? event?.runId) ? goalContract : '', languageNote,
        toolLoopGuard.clarificationContextForRun(context?.runId ?? event?.runId) ??
          toolLoopGuard.clarificationContextForRun(delegationDelivery.ownerRunFor(context))].filter(Boolean).join('\n\n');
      return contract ? { ...contract, ...(prependContext ? {prependContext} : {}), ...(appendContext ? {appendContext} : {}), appendSystemContext: `${inResponseLanguage(ACTIVITY_CONTRACT, configuredResponseLanguage)} ${executionLocationContext(context, AGENT_ID)} ${goalProgress.active(context?.runId ?? event?.runId) ? goalContract : ""} ${contract.appendSystemContext} ${inResponseLanguage(executionContext(), configuredResponseLanguage)} ${repositoryEvidence}` } : prependContext ? {prependContext} : undefined;
    });
    api.on("model_call_started", (event, context) =>
      toolLoopGuard.observeModelCall(event, context, AGENT_ID)
    );
    api.on("model_call_ended", (event, context) =>
      toolLoopGuard.observeModelEnd(event, context, AGENT_ID)
    );
    // In-session auto-compaction summarizes through the run's model stream;
    // its model calls are not agent turns (see observeCompaction).
    api.on("before_compaction", (_event, context) =>
      toolLoopGuard.observeCompaction(context, "start")
    );
    api.on("after_compaction", (_event, context) =>
      toolLoopGuard.observeCompaction(context, "end")
    );
    api.on("llm_input", (event, context) => {
      if (!accessRuntime.isProbe(context)) contextCompaction.observeModelInput(event, context);
    });
    api.on("llm_output", (event, context) => {
      if (!accessRuntime.isProbe(context)) {
        taskActivity.modelOutput(event, context);
        contextCompaction.observeModelOutput(event,context);
      }
    });
    if (!managedRuntime) {
      api.on("before_agent_run", (event, context) =>
        (!accessRuntime.isProbe(context) && delegationDelivery.admission(context)) || accessRuntime.admit(undefined, context));
    } else {
      api.on("before_agent_run", (_event, context) =>
        accessRuntime.isProbe(context) ? undefined : delegationDelivery.admission(context));
    }
    api.on("agent_end", (event, context) => {
      delegationDelivery.end(event,context);
      try {conversationImageLifecycle.observe(context);}catch {api.logger.warn('Portal conversation image custody could not be updated.');}
      toolLoopGuard.endPreviewRevalidation(event, context);
      toolLoopGuard.observeAgentEnd(event, context);
      if (!accessRuntime.isProbe(context)) { goalProgress.finish(event, context); taskActivity.finish(event, context); }
      if (!managedRuntime) return accessRuntime.finish({runId: event.runId}, context);
    });
    api.on("before_tool_call", async (event, context) => {
      if (accessRuntime.isProbe(context)) return;
      const interrupted=delegationDelivery.blocked(context,event);
      if (interrupted) return interrupted;
      let guard = withPixelCronDeliveryDefault(
        await toolLoopGuard.beforeToolCall(event, context, AGENT_ID,
          delegationDelivery.hasPendingChildren(context)),
        event, context, AGENT_ID,
      );
      const runtimeConfig = api.runtime?.config?.current?.() ?? api.config;
      guard = withPixelSubagentWorkspace(guard, event, context, AGENT_ID, runtimeConfig,
        scope => getSessionEntry({...scope,
          storePath: resolveStorePath(runtimeConfig?.session?.store, {agentId: AGENT_ID})}), {resolveUserPath, resolveAgentWorkspaceDir});
      guard = withCronCommandPayloadBlock(guard, event, context);
      const decision = guard?.block ? guard : delegationDelivery.blocked(context,event) ?? goalProgress.before(event, context) ?? accessRuntime.beforeTool(event, context) ?? guard;
      delegationDelivery.before(event,context,decision);
      bundleAdmission.before(event, context, decision);
      artifactAdmission.before(event, context, decision);
      projectRunControl.before(event, context, decision);
      taskActivity.before(event, context, decision?.block === true);
      return decision;
    });
    api.on("after_tool_call", (event, context) => {
      delegationDelivery.after(event,context);
      bundleAdmission.after(event, context);
      artifactAdmission.after(event, context);
      projectRunControl.after(event, context);
      accessRuntime.afterTool(event, context);
      if (!accessRuntime.isProbe(context)) {
        goalProgress.update(event, context);
        taskActivity.after(event, context);
        return toolLoopGuard.afterToolCall(event, context, AGENT_ID);
      }
    });
    api.registerHttpRoute({path: '/pixel-ods/runtime-identity', auth: 'gateway', match: 'exact',
      handler: async (req, res) => {
        if (req.url !== '/pixel-ods/runtime-identity') { sendJson(res, 400, {error: 'invalid request'}); return true; }
        if (req.method !== 'GET') { sendJson(res, 405, {error: 'method not allowed'}); return true; }
        res.setHeader('Cache-Control', 'no-store');
        if (!runtimeIdentity) { sendJson(res, 503, {error:'runtime-identity-unavailable'}); return true; }
        sendJson(res, 200, runtimeIdentity()); return true;
      },
    });
    api.registerHttpRoute({path: "/pixel-ods/access-runtime", auth: "gateway", match: "exact",
      handler: async (req, res) => {
        if (req.url !== "/pixel-ods/access-runtime") { sendJson(res, 400, {error: "invalid request"}); return true; }
        if (req.method === "GET") { sendJson(res, 200, managedRuntime ? await managedRuntime.readControlStatus() : accessRuntime.status()); return true; }
        if (req.method !== "POST") { sendJson(res, 405, {error: "method not allowed"}); return true; }
        try {
          let body = "";
          for await (const chunk of req) { body += chunk.toString(); if (body.length > 512) throw new Error(); }
          const value = JSON.parse(body);
          if (value?.operation === 'model-status' && Object.keys(value).join() === 'operation') {
            sendJson(res, 200, accessRuntime.readModel()); return true;
          }
          if (!value || Object.keys(value).sort().join() !== "operation,revision,token" ||
              !/^[a-f0-9]{64}$/.test(value.token) || !/^[a-f0-9]{64}$/.test(value.revision)) throw new Error();
          let result;
          if (value.operation === "acquire") {
            result = managedRuntime ? await managedRuntime.acquireTransition(value.token, value.revision)
              : accessRuntime.acquire(value.token, value.revision);
            delegationDelivery.invalidate();
          }
          else if (value.operation === "release") result = accessRuntime.release(value.token);
          else if (value.operation === "probe") {
            await managedRuntime?.qualifyTransition(value.token, value.revision);
            result = await accessRuntime.probe(value.token);
          }
          else if (value.operation === "settings-readback") {
            managedRuntime?.assertTransition();
            result = accessRuntime.readSettings(value.token, value.revision);
          }
          else if (value.operation === "model-readback") {
            result = accessRuntime.readModel(value.token, value.revision);
          }
          else if (value.operation === "provider-readback") {
            managedRuntime?.assertTransition();
            // The same owned transition and current-process snapshot gate this
            // diagnostic. Registration is distinct from successful inference.
            const settings = accessRuntime.readSettings(value.token, value.revision);
            result = {schemaVersion: 1, source: "current-provider-registration",
              pid: settings.pid, runtimeVersion: settings.runtimeVersion,
              revision: settings.revision, observedAt: settings.observedAt,
              registration: managedRuntime ? managedRuntime.readRegistration()
                : {status: "inactive", binding: null}, transportVerified: false};
          }
          else throw new Error();
          sendJson(res, 200, result);
        } catch (failure) {
          sendJson(res, 409, {error: (typeof managedRuntime?.classifyTransitionError === 'function'
            ? managedRuntime.classifyTransitionError(failure)
            : null) ?? (typeof accessRuntime.classifyTransitionError === 'function'
            ? accessRuntime.classifyTransitionError(failure)
            : null)
            ?? "access transition unavailable, busy, or proof failed"});
        }
        return true;
      },
    });
    api.on("tool_result_persist", (event, context) => {
      const decision = toolLoopGuard.toolResultPersist(event, context, AGENT_ID);
      if (context?.agentId !== AGENT_ID) return decision;
      const original = decision?.message ?? event?.message;
      const message = compactToolResultEnvelope(original);
      return message !== original ? {...decision, message} : decision;
    });
    // Observation only (never blocks or rewrites): after a tool-limit stop the
    // answer turn's message can carry partial-answer text with its tool calls,
    // and the last reply's stop reason shows an output-limit cut.
    api.on("before_message_write", (event, context) => {
      toolLoopGuard.observeAssistantMessage(event, context, AGENT_ID);
      toolLoopGuard.observeReplyEnd(event, context, AGENT_ID);
    });
    api.on("before_agent_finalize", async (event, context) => {
      await toolLoopGuard.revalidateWorkspacePreview(event, context, AGENT_ID);
      await toolLoopGuard.recoverWorkspacePreview(event, context, AGENT_ID);
      await toolLoopGuard.verifyCitedPages(event, context, AGENT_ID);
      const guardDecision = toolLoopGuard.beforeAgentFinalize(event, context, AGENT_ID);
      const verification = toolLoopGuard.deliveryVerificationForRun(context?.runId ?? event?.runId);
      const decision = goalProgress.finalize(event, context, {guardDecision,
        allowed:toolLoopGuard.continuationAllowed(context?.runId ?? event?.runId),
        waiting:verification?.status === 'pending'});
      delegationDelivery.finalize(event,context,decision);
      return decision;
    });
    // Delivery rewriting is limited to host-authoritative failed or pending
    // verification state. It neither requests nor receives conversation data;
    // a failed or pending preview delivery carries the agent's final reply,
    // seen at before_agent_finalize, ahead of Portal's one line about it
    // (preview-explanation.mjs).
    api.on("reply_payload_sending", (event) =>
      toolLoopGuard.replyPayloadSending(event)
    );
    api.registerHttpRoute({
      path: "/pixel-ods/abort",
      auth: "gateway",
      match: "exact",
      handler: async (req, res) => {
        const parsed = await readAbortUser(req);
        if (parsed.status !== 200) {
          sendJson(res, parsed.status, { error: "invalid cancellation request" });
          return true;
        }
        // Both synchronous fences are installed before either native abort
        // awaits drainage; queued announcements cannot steal owner custody.
        const delegatedPending=delegationDelivery.cancel(parsed.user);
        const compactionPending=contextCompaction.cancelPending(parsed.user);
        const parentPending=toolLoopGuard.abortUserRun(parsed.user);
        const [delegated,parentAborted,compactionAborted]=await Promise.all([delegatedPending,parentPending,compactionPending]);
        sendJson(res, 200, { aborted: delegated.tracked ? delegated.aborted : parentAborted || compactionAborted });
        return true;
      },
    });
    api.registerHttpRoute({
      path: '/pixel-ods/activity', auth: 'gateway', match: 'exact',
      handler: async (req, res) => {
        const parsed = await readAbortUser(req);
        if (parsed.status !== 200) { sendJson(res, parsed.status, {error:'invalid activity request'}); return true; }
        sendJson(res, 200, {task:taskActivity.activeForUser(parsed.user)});
        return true;
      },
    });
    api.registerHttpRoute({path:'/pixel-ods/subagent-delivery',auth:'gateway',match:'exact',
      handler:async (req,res) => {
        if (req.method !== 'POST') {sendJson(res,405,{error:'invalid delivery request'});return true;}
        try {
          if (String(req.headers['content-type'] ?? '').split(';',1)[0].trim() !== 'application/json') throw Error();
          const chunks=[];let bytes=0;
          for await (const chunk of req) {bytes+=chunk.length;if(bytes>ABORT_BODY_LIMIT)throw Error();chunks.push(chunk);}
          const value=JSON.parse(Buffer.concat(chunks).toString('utf8'));
          if (!value || Object.keys(value).sort().join()!=='runId,user' || !OPENAI_RUN_ID.test(value.runId ?? '') || !/^ods-[a-f0-9]{64}$/.test(value.user ?? '')) throw Error();
          const finalRun=delegationDelivery.finalRun(value.user,value.runId);
          if (finalRun) await toolLoopGuard.settleDelivery(finalRun);
          // Recheck cancellation/access/owner custody after asynchronous receipt settlement.
          sendJson(res,200,delegationDelivery.read(value.user,value.runId));
        } catch {sendJson(res,409,{error:'delegated delivery unavailable'});}
        return true;
      }});
    for (const operation of ['context','compact']) {
      api.registerHttpRoute({path:`/pixel-ods/${operation}`,auth:'gateway',match:'exact',
        handler:async (req,res) => {
          const parsed = await readContextRequest(req, operation === 'compact');
          if (parsed.status !== 200) {sendJson(res,parsed.status,{error:'invalid context request'});return true;}
          let result = operation === 'compact' ? await contextCompaction.compact(parsed.user,parsed.requestId)
            : contextCompaction.context(parsed.user);
          // The owner session can be idle while children it delegated to still
          // run or will report back into this chat. Then the chat is busy, so
          // restart recovery and a new turn wait for that work instead of
          // treating the turn as over.
          if (operation === 'context' && ['ready','missing'].includes(result?.status)
              && delegationDelivery.pending(parsed.user,key => Boolean(resolveActiveEmbeddedRunSessionId(key)))) result = {...result,status:'busy'};
          sendJson(res,200,result);return true;
        }});
    }
    // The OpenAI-compatible gateway route does not dispatch channel delivery
    // hooks. Give the private host ingress a narrow, authenticated way to ask
    // for host-observed verification and source-evidence truth before it
    // releases a response to the dashboard.
    api.registerHttpRoute({
      path: "/pixel-ods/verification",
      auth: "gateway",
      match: "exact",
      handler: async (req, res) => {
        const parsed = await readVerificationRun(req);
        if (parsed.status !== 200) {
          sendJson(res, parsed.status, { error: "invalid verification request" });
          return true;
        }
        await toolLoopGuard.settleDelivery(parsed.runId);
        const task = taskActivity.projection(parsed.runId);
        sendJson(res, 200, {...toolLoopGuard.deliveryVerificationForRun(parsed.runId), ...(task ? {task} : {})});
        return true;
      },
    });
    api.registerHttpRoute({
      path: "/pixel-ods/read-only-extension-continuation",
      auth: "gateway",
      match: "exact",
      handler: async (req, res) => {
        const parsed = await readVerificationRun(req);
        if (parsed.status !== 200) {
          sendJson(res, parsed.status, { error: "invalid continuation request" });
          return true;
        }
        const observed = toolLoopGuard.readOnlyExtensionRecoveryForRun(parsed.runId);
        if (!observed.eligible) { sendJson(res, 200, observed); return true; }
        try {
          // Reconcile the same durable request immediately before granting a
          // second model turn. This route never prepares or installs anything.
          const current = await submitExtensionProposal({schemaVersion:1, action:'github-request-status',
            chatId:observed.chatId, requestId:observed.requestId});
          if (current?.schemaVersion === 1 && current.kind === 'ods-extension-request-status' &&
              current.chatId === observed.chatId && current.requestId === observed.requestId &&
              current.requestState === 'pending' && current.authorizationMode === 'install') {
            sendJson(res, 200, observed);
            return true;
          }
        } catch { /* A missing or changed receipt never grants continuation. */ }
        sendJson(res, 200, {schemaVersion:1,kind:'ods-extension-read-only-continuation',eligible:false});
        return true;
      },
    });
    api.registerHttpRoute({
      path: "/pixel-ods/unfinished-extension-decision",
      auth: "gateway",
      match: "exact",
      handler: async (req, res) => {
        const parsed = await readVerificationRun(req);
        if (parsed.status !== 200) {
          sendJson(res, parsed.status, {error:"invalid continuation request"});
          return true;
        }
        const blocked = {schemaVersion:1,kind:'ods-extension-unfinished-decision',eligible:false};
        const observed = toolLoopGuard.unfinishedExtensionDecisionForRun(parsed.runId);
        if (!observed.eligible) { sendJson(res, 200, blocked); return true; }
        try {
          // Both reads are owner-bound and side-effect-free. A missing proposal
          // and unprepared runtime prove that this request did not dispatch an
          // installation; no GitHub lookup or model-supplied source is used.
          const identity = {chatId:observed.chatId,requestId:observed.requestId};
          const source = await submitExtensionProposal({schemaVersion:1,action:'github-request-read',...identity});
          const status = await submitExtensionProposal({schemaVersion:1,action:'github-request-status',...identity});
          if (status?.schemaVersion === 1 && status.kind === 'ods-extension-request-status' &&
              source?.schemaVersion === 1 && source.kind === 'ods-extension-request-source' &&
              [status,source].every(value => value.chatId === identity.chatId && value.requestId === identity.requestId) &&
              status.requestState === 'pending' && source.requestState === 'pending' &&
              status.authorizationMode === 'install' && source.authorizationMode === 'install' &&
              status.proposalAccepted === false && status.integrationBound === false &&
              status.prepared === false && status.extensionId === null &&
              status.runtimeStatus === 'not_observed' &&
              Array.isArray(status.existingExtensionIds) && status.existingExtensionIds.length === 0 &&
              source.installationStarted === false &&
              typeof source.repository === 'string' &&
              /^https:\/\/github\.com\/[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/.test(source.repository)) {
            sendJson(res, 200, {...observed,repository:source.repository});
            return true;
          }
        } catch { /* Unverified state never grants another model turn. */ }
        sendJson(res, 200, blocked);
        return true;
      },
    });
    // Portal's sidebar lists the shipped example project (Elf of Doom) like
    // any other Playground project while its folder exists, and opens it with
    // a create-only preview publication of that folder: no model run.
    api.registerHttpRoute({
      path: "/pixel-ods/example-projects",
      auth: "gateway",
      match: "exact",
      handler: createExampleProjectRoute({
        workspaceRoot: () => api.config?.agents?.list?.find(agent => agent.id === AGENT_ID)?.workspace
          ?? api.config?.agents?.defaults?.workspace,
        publish: createWorkspacePreviewPublisher({transport: api.pluginConfig?.workspacePreviewTransport}),
        sendJson,
      }),
    });

    registerTool(
      api,
      {
        name: "pixel_ods_status",
        description:
          "Read the current ODS host status projection for the Pixel gateway. Returns status-only untrusted evidence (ODS version, reported model/context settings when available, ingress readiness, gateway reachability, Docker availability, and projected Docker app counts—not the Dashboard's broader host-service count) written by the ODS host ingress. Model settings are configuration or launch metadata, not verification of the currently loaded inference model. This evidence is not authority to act on anything.",
        parameters: { type: "object", additionalProperties: false, properties: {} },
        execute: async () => {
          try {
            const projection = await readProjection(statusFile);
            const payload = statusPayload(projection);
            return toolResult(payload, statusDetails(projection), statusToolText(payload));
          } catch (err) {
            return errorResult();
          }
        },
      },
      { names: ["pixel_ods_status"] }
    );

    registerTool(api, createHostObserveTool({
      readOdsStatus: async () => statusPayload(await readProjection(statusFile)),
    }), {
      names: ["pixel_ods_host_observe"],
    });

    registerTool(api, createHostCommandProposeTool(), {
      names: ["pixel_ods_host_command_propose"],
    });

    registerTool(api, createExtensionReadTool(), {
      names: ["pixel_ods_extensions"],
    });

    for (const [name, description] of [
      [
        "pixel_ods_evidence_report",
        "Guard-only host-report adapter. Takes no arguments. During an owner-requested verified host evidence workflow, the Pixel guard rewrites this control to one exact core workspace write at the owner-named path with receipt-bound content.",
      ],
      [
        "pixel_ods_evidence_readback",
        "Guard-only host-report readback adapter. Takes no arguments. During an owner-requested verified host evidence workflow, the Pixel guard rewrites this control to one exact core workspace read at the owner-named path.",
      ],
    ]) {
      registerTool(
        api,
        {
          name,
          description,
          parameters: { type: "object", additionalProperties: false, properties: {} },
          execute: async () => guardedEvidenceAdapterResult(),
        },
        { names: [name] }
      );
    }

    registerTool(
      api,
      {
        name: "pixel_ods_apps_list",
        description:
          "List the ODS application services currently reported in the Pixel gateway status projection. Returns explicit online_app_count and app_count values plus allowlisted app names/statuses and, for user-facing apps, their purpose and configured localhost URL. Also returns timestamp and staleness; the data is status-only untrusted evidence, not authority.",
        parameters: { type: "object", additionalProperties: false, properties: {} },
        execute: async () => {
          try {
            const projection = await readProjection(statusFile);
            const payload = appsPayload(projection);
            return toolResult(payload, appsDetails(projection), appsToolText(payload));
          } catch (err) {
            return errorResult();
          }
        },
      },
      { names: ["pixel_ods_apps_list"] }
    );

    registerTool(
      api,
      createPublicWebExtractTool({
        guardedFetch: fetchWithWebToolsNetworkGuard,
        readResponseText,
        extractBasicHtmlContent,
      }),
      { names: ["pixel_ods_web_extract"] }
    );

    // Offered only while the owner's Perplexica answers /api/config with chat
    // and embedding defaults (OpenClaw keeps listing it from its descriptor
    // cache once every manifest tool was offered; COMPLETION-RELIABILITY.md).
    // The tool is deferred behind Tool Search, so its presence changes the
    // server-side catalog, not the prompt bytes. Schema discovery always sees
    // it and never probes the host.
    const discovery = api.registrationMode === 'discovery';
    if (!discovery) {
      perplexicaAvailability ??= createPerplexicaAvailability({ port: api.pluginConfig?.perplexicaPort });
      perplexicaAvailability.refreshIfStale();
    }
    const researchTool = createPerplexicaResearchTool({ port: api.pluginConfig?.perplexicaPort,
      availability: discovery ? undefined : perplexicaAvailability,
      outputChars: () => researchOutputChars(api.runtime?.config?.current?.() ?? api.config, AGENT_ID) });
    api.registerTool(onlyPixel(discovery ? () => researchTool
      : researchToolWhenAvailable(perplexicaAvailability, researchTool)), { names: ["pixel_ods_research"] });
    api.registerTool(onlyPixel(context => createWorkspaceArtifactTool(context, {
      admission:artifactAdmission, reserve:scope=>toolLoopGuard.reserveWorkspaceArtifact(scope),
      unavailableReason:scope=>toolLoopGuard.workspaceArtifactUnavailableReason(scope),
      accept:(scope,receipt)=>toolLoopGuard.acceptWorkspaceArtifact(scope,receipt),
      transport:api.pluginConfig?.workspacePreviewTransport,
    })), {names:['pixel_ods_workspace_artifact']});
    registerTool(api, createAgentSkillTool(), {names:['pixel_ods_skill']});
    registerTool(api, createAskUserTool({responseLanguage: configuredResponseLanguage}), {names:['pixel_ods_ask_user']});
    registerTool(api, createGoalProgressTool(), {names:['pixel_ods_goal']});
    registerTool(api, createActivityTool(), {names:['pixel_ods_activity']});
    registerProjectBuild(api, onlyPixel, projectRunControl);
    api.registerTool(onlyPixel(context => createExtensionProposalTool(context)), {names:['pixel_ods_extension_proposal']});
    api.registerTool(onlyPixel(context => createSourceProposalTool(context)), {names:['pixel_ods_source_proposal']});
    api.registerTool(onlyPixel(context => createPythonLibraryProposalTool(context)), {names:['pixel_ods_python_library_proposal']});
    api.registerTool(onlyPixel(context => createExtensionRequestStatusTool(context)), {names:['pixel_ods_extension_request_status']});
    api.registerTool(onlyPixel(context => createExtensionRequestPrepareTool(context)), {names:['pixel_ods_extension_request_prepare']});
    api.registerTool(onlyPixel(context => createExtensionRequestAdvanceTool(context)), {names:['pixel_ods_extension_request_advance']});
    api.registerTool(onlyPixel(context => createExtensionRequestRetryTool(context)), {names:['pixel_ods_extension_request_retry']});

    registerTool(api, createDownloadPromoteTool(), {
      names: ["pixel_ods_download_promote"],
    });

    registerTool(api, createWorkspacePreviewTool({ transport: api.pluginConfig?.workspacePreviewTransport }), {
      names: ["pixel_ods_workspace_preview"],
    });

    if (["unix", "native"].includes(api.pluginConfig?.workspacePreviewInspectionTransport)) {
      // Per run context: the screenshot gate reads this run's model.
      api.registerTool(onlyPixel(context => createWorkspacePreviewInspectTool({
        transport: api.pluginConfig.workspacePreviewInspectionTransport,
        // Finalize-time revisions do not reach the model after a plugin tool
        // call; an untested requested show/hide change is reported here.
        transitionRequirement: (toolCallId, params) => toolLoopGuard.previewInspectionTransition(toolCallId, params),
        // One bounded screenshot for a model declared to accept images, the
        // same declaration Portal's owner-image path reads.
        screenshots: {
          capability: () => previewScreenshotCapability(api.runtime?.config?.current?.() ?? api.config, context?.activeModel),
          reserve: (toolCallId, params) => toolLoopGuard.reservePreviewScreenshot(toolCallId, params),
        },
      })), { names: ["pixel_ods_workspace_preview_inspect"] });
    }

  },
});