@sema-agent/core
Version:
Stateless, task-oriented AI agent core
343 lines (342 loc) • 27 kB
JavaScript
import { DELEGATION_OWNER_MISMATCH, delegationOwnerUnbound, forkedRowNotOurs } from "./delegation-owner.js";
import { contentExposureOf } from "../content-exposure.js";
import { memoryEntryPortOf } from "../memory-engine/entry-create.js";
import { forkGovernanceDenial, resolveDelegationEntryCaps } from "../../agents/subagent.js";
import { isLiveQuestionFace } from "../ask-question.js";
import { parentSpecSeatOf } from "../parent-spec-seat.js";
import { legIdentityOf } from "../isolation-scope.js";
import { rootAnchorOf, rootPrincipalOf } from "../leg-identity.js";
import { chainJudges, sameInstallation } from "../mods/stations.js";
import { childClampSeats, clampSourceOf, handsReadOnlyCarried } from "../child-clamp-seats.js";
import { inheritedRuleKeyOf } from "../session-policy-store.js";
import { rowFollowsFloor } from "./session-rule-policy.js";
import { declaresSubagentPlacement } from "../session.js";
import { durableMandateSourceOf, effectiveDurableApprovalOf } from "../tool-policy.js";
import { engineLaneLegOf } from "../park-resumability.js";
import { askSeamFormOf, reachSetsAside, wiringLegKindOf } from "../wiring-manifest.js";
import { chainAnchorRecords } from "./child-tree.js";
import { defaultTaskRegistry } from "../task-registry.js";
import { joinRuleBuckets, persistedRuleBucketsOf, readRuleBuckets } from "../persisted-rule-buckets.js";
import { deliverEngineNotice } from "../types.js";
import { PermissionModeController, autoModeFaceOf, modeRequestAfterResume, withheldApprovalMode } from "../mode-policy.js";
import { SessionModeSeats } from "./session-mode-seats.js";
import { recordedModeSeed } from "../checkpoint-row-verdict.js";
import { frozenSkillGrants } from "../skill-grant.js";
import { attachRebuiltDenialTrackers, createDenialLimitStop } from "./denial-limit-arms.js";
import { delegationReviewSeat } from "./classifier-ladder.js";
import { valveLeaves } from "../../agents/tool-filter.js";
import { mountRowVerdict } from "../tool-mount-plan.js";
import { reviewRequestFor } from "../present-plan-tool.js";
import { bindRevivedLegClassifier, chainRootLeg, legConstraintLayers } from "./constraint-layers.js";
export function prepareInheritedGate(input) {
const { spec, deps, askSeat, internals, resume, sessions, sessionId, runId, hostTaskId, taskRootFinal, delegationCwd, executionEnv, ownedEnv, lockedPreflight, pathRuleAnchors, toolFaceSnapshot, mountsCallerTool, promptLean, resolvedInteractionPosture, permissionModeSeat, spendSeat, harnessRef, skillGrants, forwardEvent, subagentRetain, taskArtifacts, worktreeIsolation, requestReview, requestStopAfterTurn, enterPlanMode, reminderMark, reminderDisclosureCounts, fileHistoryEnabled, historyScope, historyRoot, historyFs, abortRun } = input;
const sharedArtifactReadsCell = resume === undefined && engineLaneLegOf(internals) && internals?.inheritedGate?.sharedArtifactReads !== undefined ? { current: internals.inheritedGate.sharedArtifactReads } : {};
const liveInheritedGate = internals?.inheritedGate;
const seedInheritedGate = resume?.seed.inheritedGate;
const inheritedRuleBuckets = joinRuleBuckets(readRuleBuckets(liveInheritedGate?.persistedRuleBuckets, "chain"), readRuleBuckets(seedInheritedGate?.persistedRuleBuckets, "checkpoint"));
const inheritedAncestorRules = (() => {
const seedRules = seedInheritedGate?.ancestorRules?.map(inheritedRuleKeyOf);
const liveRules = liveInheritedGate?.ancestorRules?.map(inheritedRuleKeyOf);
if (seedRules === undefined || seedRules.length === 0) {
const only = liveRules ?? seedRules;
return only === undefined ? undefined : [...only];
}
if (liveRules === undefined || liveRules.length === 0)
return [...seedRules];
const merged = seedRules.map((s) => {
const live = liveRules.find((l) => l.sessionId === s.sessionId && l.principal === s.principal);
const follows = live !== undefined && rowFollowsFloor(live, s);
return follows && live.rev >= s.rev ? live : s;
});
const extras = liveRules.filter((l) => !seedRules.some((s) => s.sessionId === l.sessionId && s.principal === l.principal));
return [...merged, ...extras];
})();
const modeSeed = recordedModeSeed(seedInheritedGate);
const inheritedShellGate = liveInheritedGate?.shellGate === "always" || modeSeed.shellGate === "always" ? "always" : undefined;
const askView = askSeat.reach === "none" ? liveInheritedGate?.parentConstraints?.map((pc) => (reachSetsAside(askSeamFormOf(pc.onAsk)) ? ((({ onAsk: _person, ...rest }) => rest)(pc)) : pc)) : liveInheritedGate?.parentConstraints;
const chainView = askView?.map((held, position) => {
const pc = bindRevivedLegClassifier(held, input.autoModeDecider, () => liveInheritedGate?.permissionMode ?? "default");
if (pc.policy === undefined)
return pc;
const policy = pathRuleAnchors.onLeg(pc.policy, position);
return policy === pc.policy ? pc : { ...pc, policy };
});
const autoModeFace = autoModeFaceOf(deps, liveInheritedGate);
const inheritedParentConstraints = attachRebuiltDenialTrackers(chainView, autoModeFace?.denialLimit);
const parentSeat = liveInheritedGate?.permissionModeCeiling;
const ceiling = parentSeat ?? liveInheritedGate?.permissionMode;
const announceModeFold = (receipt, folded) => {
if (receipt.foldedBy === undefined)
return;
const because = receipt.foldedBy === "operator_deny" ? "the deployment denies it for this principal" : receipt.foldedBy === "face_absent" ? "no auto-mode classifier face is wired on this deployment" : `the parent leg's mode is the ceiling a child's declaration is clamped under`;
const message = `permission mode "${folded}"${receipt.requested === undefined ? " (inherited)" : ""} is not available on this leg (${because}) — it runs under "${receipt.effective}"`;
deliverEngineNotice(deps.onNotice, { code: "config.permission_mode_unavailable", message, detail: { requested: folded, effective: receipt.effective, by: receipt.foldedBy, sessionId, runId } });
if (parentSeat !== undefined) {
deliverEngineNotice(deps.onNotice, { code: "config.permission_mode_unavailable", message: `${message} (a child leg, ${sessionId})`, detail: { requested: folded, effective: receipt.effective, by: receipt.foldedBy, sessionId: parentSeat.sessionId, childSessionId: sessionId, runId } });
}
};
const parentModeUnknown = input.delegated && ceiling === undefined ? true : undefined;
const withheldMode = withheldApprovalMode(permissionModeSeat, modeSeed, resume?.outcome, parentModeUnknown);
const permissionMode = new PermissionModeController(modeRequestAfterResume(permissionModeSeat, modeSeed, resume?.outcome, parentModeUnknown), ceiling, { onFold: announceModeFold, ...(modeSeed.prePlanMode !== undefined ? { prePlanMode: modeSeed.prePlanMode } : {}), ...(wiringLegKindOf(resume !== undefined, internals) === "root" && deps.permissionModeWhenUnset !== undefined ? { whenUnset: deps.permissionModeWhenUnset } : {}) });
permissionMode.announceStart();
if (withheldMode !== undefined) {
const message = `permission mode "${withheldMode}" the approval named is not taken on this leg (its parent's mode was not handed to this resume, so the ceiling a widening is held to is unknown) — it runs under "${permissionMode.current}"`;
deliverEngineNotice(deps.onNotice, { code: "config.permission_mode_unavailable", message, detail: { requested: withheldMode, effective: permissionMode.current, by: "inherited_ceiling", sessionId, runId } });
}
const { ceiling: legModeCeiling, commit: commitLegModeCeiling, end: endModeCeiling } = (internals?.sessionModeSeats ?? new SessionModeSeats()).legCeiling(sessionId, permissionMode);
const commitModeSeats = (legSignal) => {
commitLegModeCeiling();
parentSeat?.hold?.(permissionMode, legSignal);
};
const liveAdmittedOrg = liveInheritedGate?.admittedOrgScopes;
const seedAdmittedOrg = seedInheritedGate?.admittedOrgScopes;
const inheritedAdmittedOrgScopes = liveAdmittedOrg === undefined ? seedAdmittedOrg : seedAdmittedOrg === undefined ? liveAdmittedOrg : liveAdmittedOrg.filter((s) => seedAdmittedOrg.includes(s));
const inheritedOrgGoverned = liveInheritedGate?.orgAdmissionGoverned === true || seedInheritedGate?.orgAdmissionGoverned === true;
const childRuleBuckets = joinRuleBuckets(inheritedRuleBuckets, persistedRuleBucketsOf({ provider: deps.permissionRuleStore, localOwnerDeclared: deps.localOwnerRules === true, principal: spec.principal }));
const checkpointOwnOrgVerdict = resume?.seed.inheritedGate?.ownAdmittedOrgScopes !== undefined
? { scopes: resume.seed.inheritedGate.ownAdmittedOrgScopes, writeScope: resume.seed.inheritedGate.ownAdmittedOrgWriteScope ?? null }
: undefined;
const refOwnOrgVerdict = internals?.ownOrgAdmissionRef?.current;
const priorOwnOrgVerdict = checkpointOwnOrgVerdict === undefined
? refOwnOrgVerdict
: refOwnOrgVerdict === undefined
? checkpointOwnOrgVerdict
: {
scopes: checkpointOwnOrgVerdict.scopes.filter((sc) => refOwnOrgVerdict.scopes.includes(sc)),
writeScope: checkpointOwnOrgVerdict.writeScope !== null && checkpointOwnOrgVerdict.writeScope === refOwnOrgVerdict.writeScope
? checkpointOwnOrgVerdict.writeScope
: null,
};
const orgGovernedProvenance = deps.memoryScopeAdmission !== undefined ||
(deps.deploymentMemoryScopes !== undefined && deps.deploymentMemoryScopes.length > 0) ||
deps.compliancePostureResolver !== undefined ||
inheritedOrgGoverned ||
priorOwnOrgVerdict !== undefined;
const effectiveShellGate = spec.shellGate ?? inheritedShellGate;
const ownSessionRulesRef = {};
const ancestorSessionRulesRef = { current: new Map() };
const ancestorRulesNow = () => inheritedAncestorRules === undefined ? undefined : inheritedAncestorRules.map((a, i) => ancestorSessionRulesRef.current.get(i) ?? a);
const memoryAdmittedOrgScopesRef = { current: [] };
const ownOrgVerdictRef = { current: undefined };
const faceCheckpointSection = () => {
const resolvedReadFace = input.resolvedReadFace();
const handsLessResolvedFace = input.handsLessResolvedFace();
const readDenyAdditionsNormalized = input.readDenyAdditionsNormalized();
if (resolvedReadFace === undefined && resume !== undefined) {
const seed = resume.seed.readFace;
if (seed === undefined)
return undefined;
return { face: handsLessResolvedFace ?? seed.face, ...(seed.denyEntries !== undefined ? { denyEntries: seed.denyEntries.map((e) => ({ ...e })) } : {}) };
}
const face = input.carriedFaces()?.read === "open" ? "open" : (resolvedReadFace ?? handsLessResolvedFace);
if (face === undefined)
return undefined;
if (face === "open" || readDenyAdditionsNormalized.length > 0) {
return { face, ...(readDenyAdditionsNormalized.length > 0 ? { denyEntries: readDenyAdditionsNormalized.map((e) => ({ ...e })) } : {}) };
}
return undefined;
};
const writeFaceCheckpointSection = () => {
if (input.carriedFaces()?.writeSeatOpen === true && input.carriedFaces()?.write.inForce() === "open")
return { face: "open" };
const seat = input.resolvedWriteFace() ?? input.handsLessResolvedWriteFace();
return seat === undefined ? undefined : seat.inForce() === "open" ? { face: "open" } : seat.fenced ? { face: "roots" } : undefined;
};
const skillGrantCheckpointSection = () => frozenSkillGrants(skillGrants);
const frozenOnAsk = askSeat.value;
const hookEnvSource = (ownedEnv ?? deps.executionEnv) != null ? executionEnv : undefined;
const frozenOnQuestion = spec.onQuestion ?? deps.onQuestion;
const parentSpecSeat = parentSpecSeatOf({ ...spec, sandbox: input.commandSandboxRequirement }, frozenOnQuestion);
const provenanceForChildrenRef = {};
const delegationProvenanceForChildren = () => provenanceForChildrenRef.current;
const delegationSettlementRef = {};
const delegationSettlementForChildren = () => delegationSettlementRef.current;
const inheritedGateForChildren = () => {
const autoModeDecider = permissionMode.current === "auto" ? input.autoModeDecider() : undefined;
const autoModeDenialTracking = input.autoModeDenialTracking();
const autoModeArming = input.autoModeArming();
const ancestorRules = [
...(ancestorRulesNow() ?? []),
...(ownSessionRulesRef.current !== undefined ? [ownSessionRulesRef.current] : []),
];
const ownCallerPolicy = lockedPreflight.toolPolicy;
const durableMandate = durableMandateSourceOf({ forceDurableGate: input.runtimeCaps()?.forceDurableGate === true, durableApprovalDeclared: spec.durableApproval !== undefined, onAsk: frozenOnAsk }) !== undefined;
const contentMandate = input.runtimeCaps()?.forceDurableGate === true ||
(spec.durableApproval !== undefined && !isLiveQuestionFace(frozenOnQuestion));
const ownInstallation = { chain: input.ownModChain, onAsk: frozenOnAsk, durableMandate, contentMandate, hookEnv: hookEnvSource, decider: autoModeDecider };
const regime = {
...(frozenOnAsk !== undefined ? { onAsk: frozenOnAsk } : {}),
...(durableMandate ? { durableMandate: true } : {}),
...(contentMandate ? { contentMandate: true } : {}),
...(autoModeDecider !== undefined
? { autoMode: { decider: autoModeDecider, ...(autoModeDenialTracking !== undefined ? { denialTracking: autoModeDenialTracking } : {}), ...(autoModeArming !== undefined ? { arming: autoModeArming } : {}), liveMode: legModeCeiling } }
: {}),
};
const handsInstallation = chainJudges(input.modBus) && !(inheritedParentConstraints ?? []).some((pc) => sameInstallation(pc, ownInstallation));
const parentConstraints = [
...(inheritedParentConstraints ?? []),
...legConstraintLayers({
installation: handsInstallation ? { bus: input.modBus, ...(hookEnvSource !== undefined ? { hookEnv: hookEnvSource } : {}), regime } : undefined,
policy: ownCallerPolicy !== undefined && lockedPreflight.toolPolicyKind !== undefined ? { policy: ownCallerPolicy, kind: lockedPreflight.toolPolicyKind, regime } : undefined,
rootLeg: chainRootLeg(inheritedParentConstraints, input.delegated),
}),
];
return {
...(ancestorRules.length > 0 ? { ancestorRules } : {}),
...(effectiveShellGate !== undefined ? { shellGate: effectiveShellGate } : {}),
permissionMode: permissionMode.current,
permissionModeCeiling: legModeCeiling,
...(autoModeFace !== undefined ? { autoModeFace } : {}),
...(parentConstraints.length > 0 ? { parentConstraints } : {}),
...chainAnchorRecords(pathRuleAnchors.chainTop, parentConstraints, pathRuleAnchors.siteOf),
...(childRuleBuckets !== undefined ? { persistedRuleBuckets: childRuleBuckets } : {}),
admittedOrgScopes: memoryAdmittedOrgScopesRef.current,
...(orgGovernedProvenance ? { orgAdmissionGoverned: true } : {}),
...(sharedArtifactReadsCell.current !== undefined ? { sharedArtifactReads: sharedArtifactReadsCell.current } : {}),
};
};
const carrierReadFace = () => input.resolvedReadFace() ?? input.handsLessResolvedFace();
const carrierWriteFace = () => (input.resolvedWriteFace() ?? input.handsLessResolvedWriteFace())?.inForce();
const runClampSource = () => ({
...clampSourceOf(spec, "clamp"),
handsReadOnly: handsReadOnlyCarried(spec),
readFace: input.carriedFaces()?.read ?? carrierReadFace(),
writeFace: input.carriedFaces()?.write.inForce() ?? carrierWriteFace(),
blockReadsOutsideRoots: input.readBlock() ? true : undefined,
readDenyPatterns: input.readDenyAdditionsNormalized(),
agentConfigDirs: input.callerPlaces.configRoots.carried, agentHomeDirs: input.callerPlaces.homes.carried,
approvalReach: askSeat.reach,
durableApproval: input.hostApprovalParksNotResumable ? false : undefined,
});
const fullShellReachable = mountRowVerdict("bash", input.mountFacts, valveLeaves(toolFaceSnapshot.selector));
const { gateStopRef, stopForDenialLimit } = createDenialLimitStop({ sessionId, runId, onNotice: deps.onNotice, abort: abortRun });
const delegationEntryCapsResolved = resolveDelegationEntryCaps(deps.delegationEntryCaps);
const leg = legIdentityOf(spec);
const enrichSpecToolCtx = (ctx) => {
const agentForkDenial = input.agentForkDenial();
const observersActive = input.observersActive();
const autoModeDecider = input.autoModeDecider();
const centerAdoption = input.centerAdoption();
const agentStations = input.agentStations();
const sendStation = input.sendStation();
const taskStations = input.taskStations();
const rootSessionIncarnation = rootAnchorOf(internals, sessionId, input.sessionIncarnation()).occupant;
const rootSessionScope = internals?.rootSessionId !== undefined ? internals.rootSessionScope : input.taskScope, rootPrincipal = rootPrincipalOf(internals, leg.principal);
return {
...ctx,
delegationEntryCaps: delegationEntryCapsResolved,
...(agentStations !== undefined ? { agentStations } : {}),
...(sendStation !== undefined ? { sendStation } : {}),
...(taskStations !== undefined ? { taskStations } : {}),
continuationReach: input.continuationReach,
spendSeat,
model: harnessRef.current?.getModel(),
modelRef: harnessRef.current?.getModelRef(),
thinkingLevel: harnessRef.current?.getThinkingLevel(),
principal: leg.principal, contentExposure: contentExposureOf(input.memoryEngineSession), memoryEntryCreate: memoryEntryPortOf(input.memoryEngineSession),
...(leg.isolationScope !== undefined ? { isolationScope: leg.isolationScope } : {}),
...(frozenOnAsk !== undefined ? { onAsk: frozenOnAsk } : {}),
...childClampSeats(runClampSource()),
...(internals?.runLedgerBook !== undefined ? { runLedgerBook: internals.runLedgerBook } : {}),
...(frozenOnQuestion !== undefined ? { onQuestion: frozenOnQuestion } : {}),
oneShot: spec.oneShot,
mountsCallerTool,
mountedMcp: input.mountedMcp,
parentSpecSeat,
...(internals?.questionFaceStripped === true ? { questionFaceStripped: true } : {}),
toolSelector: toolFaceSnapshot.selector,
deferTools: toolFaceSnapshot.defer,
alwaysLoadTools: toolFaceSnapshot.alwaysLoad,
...(toolFaceSnapshot.restoreGated !== undefined ? { restoreGatedTools: toolFaceSnapshot.restoreGated } : {}),
...(promptLean !== undefined ? { promptLean } : {}),
...(spec.memoryPersistenceCapable !== undefined ? { memoryPersistenceCapable: spec.memoryPersistenceCapable } : {}),
get memoryCaptureOptedOut() {
return input.memoryEngineSession()?.captureOptOut?.optedOut() ?? false;
},
get memoryCaptureIndeterminate() {
return input.memoryEngineSession()?.captureOptOut?.indeterminate() ?? false;
},
get memoryCaptureControlDir() {
return input.memoryEngineSession()?.engine.controlPlaneRoot;
},
get memoryCaptureAncestors() {
const ctl = input.memoryEngineSession()?.engine.controlPlaneRoot;
return [...(internals?.memoryCaptureAncestors ?? []), { sessionId, ...(ctl !== undefined ? { controlDir: ctl } : {}) }];
},
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
get parentCwd() {
return input.givenNoWorkspace ? undefined : delegationCwd();
},
...(input.givenNoWorkspace ? {} : { callerRoot: taskRootFinal }),
...(input.ownTarget !== undefined ? { placementTarget: input.ownTarget } : {}),
...(input.hostFloor !== undefined ? { hostFloor: input.hostFloor } : {}),
...(fileHistoryEnabled && historyScope !== undefined ? { fileHistoryLineage: { scope: historyScope, root: historyRoot, fs: historyFs } } : {}),
reminderMark,
reminderDisclosureCounts,
...(centerAdoption !== undefined ? { centerArtifactDigest: centerAdoption.artifact.artifactDigest } : {}),
...(centerAdoption?.sourceRevision !== undefined ? { centerSourceRevision: centerAdoption.sourceRevision } : {}),
activeSkillGrants: () => skillGrants.records(),
activeRequestAllowedTools: () => input.requestAllowedTools.entries(),
inheritedGateForChildren,
crossBoundaryTreeForChildren: input.crossBoundaryTree,
delegationProvenanceForChildren,
delegationSettlement: delegationSettlementForChildren,
...(autoModeDecider ? { autoModeReview: delegationReviewSeat({ decider: autoModeDecider, legNotice: input.legNotice, onNotice: deps.onNotice, runId }) } : {}),
...((own) => (own !== undefined ? { durableApprovalForChildren: { ...own } } : {}))(effectiveDurableApprovalOf({ declared: spec.durableApproval, forceDurableGate: input.runtimeCaps()?.forceDurableGate === true, approvalParkNotResumable: input.approvalParkNotResumable, scope: input.checkpointScope })),
...(input.checkpointSeat !== undefined ? { checkpointStoreForChildren: input.checkpointSeat } : {}),
checkpointScopeForChildren: input.checkpointScope, ...(input.managerSeatForChildren !== undefined ? { managerSeatForChildren: input.managerSeatForChildren } : {}),
taskRegistry: defaultTaskRegistry,
hostRunParked: () => input.pausedRef.current !== undefined,
taskId: hostTaskId,
...(internals?.parentTaskId !== undefined ? { parentTaskId: internals.parentTaskId } : {}),
...(internals?.parentSessionId !== undefined ? { parentSessionId: internals.parentSessionId } : {}),
...(internals?.rootSessionId !== undefined ? { rootSessionId: internals.rootSessionId } : {}), ...(internals?.placementRoot !== undefined ? { placementRoot: internals.placementRoot } : {}),
...(rootSessionIncarnation !== undefined ? { rootSessionIncarnation } : {}), ...(rootSessionScope !== undefined ? { rootSessionScope } : {}), ...(rootPrincipal !== undefined ? { rootPrincipal } : {}),
delegationOwner: input.delegationOwner, ...(internals?.treeHolder !== undefined ? { treeHolder: internals.treeHolder } : {}),
...(internals?.explicitAgentName !== undefined ? { spawnedAgentName: internals.explicitAgentName } : {}),
...(internals?.peerSelfRef !== undefined ? { peerSelfRef: internals.peerSelfRef } : {}),
...(internals?.peerInboundChainRef !== undefined ? { peerInboundChainRef: internals.peerInboundChainRef } : {}),
...(deps.rosterStore !== undefined ? { roster: deps.rosterStore } : {}),
...(sessions.fork !== undefined
? {
hostSessionFork: async (forkOpts) => {
const tree = await input.delegationOwner.read();
if (!tree.bound)
throw delegationOwnerUnbound(tree.reason);
const source = { sessionId, occupant: input.sessionIncarnation() ?? null };
const forked = (await sessions.fork(sessionId, tree.owner, forkOpts !== undefined && declaresSubagentPlacement(sessions) ? forkOpts : undefined)) ?? null;
if (forked === null)
return null;
const notOurs = await forkedRowNotOurs(sessions, forked, source);
if (notOurs !== undefined)
throw Object.assign(new Error(notOurs), { code: DELEGATION_OWNER_MISMATCH });
return {
sessionId: forked,
release: async () => {
await sessions.release?.(forked);
},
};
},
}
: {}),
sessionId,
...(spec.backgroundScope !== undefined ? { backgroundScope: spec.backgroundScope } : {}),
...(resolvedInteractionPosture !== undefined ? { interactionPosture: resolvedInteractionPosture } : {}),
...(deps.onBackgroundChildEvent ? { onBackgroundChildEvent: deps.onBackgroundChildEvent } : {}),
...(internals?.onTaskNotification ? { onTaskNotification: internals.onTaskNotification } : {}),
...(taskArtifacts !== undefined ? { taskArtifacts } : {}),
...(forwardEvent ? { forwardEvent } : {}),
...(internals?.onSubtreeActivity ? { onSubtreeActivity: internals.onSubtreeActivity } : {}),
...(internals?.onSubagentSpawn ? { onSubagentSpawn: internals.onSubagentSpawn } : {}),
...(subagentRetain ? { subagentRetain } : {}),
...(worktreeIsolation ? { worktreeIsolation } : {}),
...(internals?.insideFork === true ? { insideFork: true } : {}),
...(agentForkDenial !== undefined ? { forkAccess: { denied: agentForkDenial } } : {}),
...(observersActive ? { observersAllowed: true } : {}),
requestReview: (opts) => requestReview(reviewRequestFor(ctx, opts?.reason)),
requestStopAfterTurn,
...(spec.enablePlanMode === true ? { enterPlanMode } : {}),
};
};
return { sharedArtifactReadsCell, liveInheritedGate, seedInheritedGate, inheritedAncestorRules, inheritedShellGate, inheritedParentConstraints, permissionMode, commitModeSeats, endModeCeiling, inheritedAdmittedOrgScopes, inheritedRuleBuckets, priorOwnOrgVerdict, orgGovernedProvenance, effectiveShellGate, ownSessionRulesRef, ancestorSessionRulesRef, ancestorRulesNow, memoryAdmittedOrgScopesRef, ownOrgVerdictRef, runClampSource, faceCheckpointSection, writeFaceCheckpointSection, skillGrantCheckpointSection, frozenOnAsk, hookEnvSource, frozenOnQuestion, parentSpecSeat, provenanceForChildrenRef, delegationSettlementRef, inheritedGateForChildren, carrierReadFace, carrierWriteFace, fullShellReachable, gateStopRef, stopForDenialLimit, enrichSpecToolCtx };
}