mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 06:02:54 +00:00
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>
52 lines
1.6 KiB
TypeScript
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;
|
|
}
|