Files
openclaw/src/tasks/agent-harness-task-runtime-scope.ts
Bryan P f9d35dc681 fix(codex): deliver native subagent completions
Deliver Codex-native subagent completions through the generic plugin harness task runtime.

Proof:
- Autoreview clean on final branch.
- Testbox changed gate: tbx_01ks80eqs7d2e3jq3p99zbm4wd, pnpm check:changed, exit 0.
- Live Codex harness: tbx_01ks80p4ky32sqv2ksan2p0w0q, codex/gpt-5.5 API-key auth, native parent/child bridge tokens observed, exit 0.

Co-authored-by: bryanpearson <bryanmpearson@gmail.com>
2026-05-22 15:28:46 +01:00

52 lines
1.6 KiB
TypeScript

import { normalizeDeliveryContext } from "../utils/delivery-context.shared.js";
import type { DeliveryContext } from "../utils/delivery-context.types.js";
const scopeRegistryKey = Symbol.for("openclaw.agentHarnessTaskRuntimeScope.registry");
type ScopeRegistry = {
hostIssuedScopes: WeakSet<object>;
};
type GlobalWithScopeRegistry = typeof globalThis & {
[scopeRegistryKey]?: ScopeRegistry;
};
function getScopeRegistry(): ScopeRegistry {
const globalState = globalThis as GlobalWithScopeRegistry;
globalState[scopeRegistryKey] ??= {
hostIssuedScopes: new WeakSet<object>(),
};
return globalState[scopeRegistryKey];
}
export type AgentHarnessTaskRuntimeScope = {
readonly requesterSessionKey: string;
readonly requesterOrigin?: DeliveryContext;
};
export function createAgentHarnessTaskRuntimeScope(params: {
requesterSessionKey: string;
requesterOrigin?: DeliveryContext;
}): AgentHarnessTaskRuntimeScope {
const requesterSessionKey = params.requesterSessionKey.trim();
if (!requesterSessionKey) {
throw new Error("Agent harness task runtime scope requires requesterSessionKey");
}
const requesterOrigin = normalizeDeliveryContext(params.requesterOrigin);
const scope: AgentHarnessTaskRuntimeScope = {
requesterSessionKey,
...(requesterOrigin ? { requesterOrigin } : {}),
};
getScopeRegistry().hostIssuedScopes.add(scope);
return scope;
}
export function assertAgentHarnessTaskRuntimeScope(
scope: AgentHarnessTaskRuntimeScope,
): AgentHarnessTaskRuntimeScope {
if (!getScopeRegistry().hostIssuedScopes.has(scope)) {
throw new Error("Agent harness task runtime requires a host-issued scope");
}
return scope;
}