Skip to content

Latest commit

 

History

History
124 lines (91 loc) · 12.1 KB

execution-context.mdx

File metadata and controls

124 lines (91 loc) · 12.1 KB
title Execution Context — Kernel Protocol reference
navTitle Execution Context
description Execution Context schemas of the ObjectStack Kernel Protocol: AuthGateCode and 3 more — each property with its type, default and a TypeScript example.

{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}

**Source:** `packages/spec/src/kernel/execution-context.zod.ts`

TypeScript Usage

import { AuthGateCodeSchema, AuthGateScopeSchema, ExecutionContextSchema, PermissionSetAddressSchema } from '@objectstack/spec/kernel';
import type { AuthGateCode, AuthGateScope, ExecutionContext, PermissionSetAddress } from '@objectstack/spec/kernel';

// Validate data
const result = AuthGateCodeSchema.parse(data);

AuthGateCode

Allowed Values

  • PASSWORD_EXPIRED
  • PASSWORD_RESET_REQUIRED
  • MFA_REQUIRED

AuthGateScope

Allowed Values

  • account
  • credential

ExecutionContext

Properties

Property Type Required Description
userId string optional
actor string optional
attributedUserId string optional
email string optional
tenantId string optional
timezone string optional
locale string optional
workspaceLocale string optional
currency string optional
positions string[] optional (default: [])
principalKind Enum<'human' | 'agent' | 'service' | 'guest' | 'system'> optional
audience Enum<'internal' | 'external'> optional
posture Enum<'PLATFORM_ADMIN' | 'TENANT_ADMIN' | 'MEMBER' | 'EXTERNAL'> optional ADR-0095 D2 posture rung — PLATFORM_ADMIN crosses the tenant wall where object posture permits; TENANT_ADMIN sees all rows in the org; MEMBER gets business RLS; EXTERNAL (an external organization member) reaches explicit grants only — shares, sharing rules, and grant RLS — never the OWD baseline.
authGate { code: Enum<'PASSWORD_EXPIRED' | 'PASSWORD_RESET_REQUIRED' | 'MFA_REQUIRED'>; message: string } optional ADR-0069 authentication-policy gate: present only while the principal is blocked from protected resources until they remediate (expired password, enforced MFA), absent for every healthy session. code is the stable machine code the client branches on, from the closed vocabulary PASSWORD_EXPIRED / PASSWORD_RESET_REQUIRED (an administrator forced a password change) / MFA_REQUIRED, and message is what the blocked user reads; both are required because the transport seam renders them as the 403 body. Each code declares a scope: MFA_REQUIRED holds the account, so an API key whose owner holds it is refused with the same 403; PASSWORD_EXPIRED and PASSWORD_RESET_REQUIRED hold password sign-in alone, and API keys of that owner keep working. AUTHENTICATION, not authorization — it suspends access entirely rather than narrowing it, and nothing in the permission/RLS path reads it, while the allow-listed remediation endpoints stay reachable. Server-constructed only, never client-supplied; a guest/anonymous principal never carries one.
onBehalfOf { userId: string; principalKind?: Enum<'human' | 'agent' | 'service' | 'guest' | 'system'> } optional
performedBy { clientId?: string; agentId?: string; conversationId?: string; confirmationId?: string } optional ADR-0090 D10 rule 4 dual attribution: what PERFORMED this operation, when the performer is not the principal the write is authorized as. Two server-side producers set it: the /mcp OAuth door names the agent client in clientId, on the same branch that decides principalKind: agent and onBehalfOf; the server-constructed in-product AI path, acting for the signed-in person and running as them, names its agent in agentId with conversationId and, when the person confirmed the call, confirmationId. Absent everywhere else, and the absence is the record that the principal acted for itself; when present it names its performer, at least one of clientId and agentId, each set only by its own producer. ATTRIBUTION ONLY — no security middleware reads it, it never becomes the authorization subject, and userId stays the human so owner-stamping and current_user.* RLS still resolve to them. Server-constructed only, never client-supplied: an id a request named (an agent name, a conversation, a pending item) is stamped only after the server resolved it in its own store for the person in userId, and an unresolved id is not stamped. Surfaced to hooks as HookContext.provenance.performedByClientId / performedByAgentId / performedByConversationId / performedByConfirmationId. The audit writer records clientId as sys_audit_log.metadata.performed_by beside on_behalf_of; the in-product AI keys are carried for the audit writer, which does not record them yet. It does not move actor, which ADR-0118 D1/D5 keeps two-valued.
surface Enum<'rest' | 'mcp'> optional The door an action invocation came through: rest (the REST POST /actions/:object/:action door — console buttons, the SDK) or mcp (the /mcp bridge's run_action and resume_run tools — an AI client). Set only by those two doors, on the envelope of the invocation they hand the audit writer, from the door's own identity (an upstream value, header or body member never moves it); absent on every other operation. ATTRIBUTION ONLY — no security middleware reads it and it is never an authorization subject, scope or gate. Server-constructed only, never client-supplied. Recorded by the audit writer as sys_audit_log.metadata.surface on the action_invocation row.
impersonatedBy string optional The administrator (a sys_user id) who started the impersonation session this request runs in — better-auth admin plugin session.impersonatedBy, stored as sys_session.impersonated_by. Absent on every other request; absence is the record that the user in userId acted themselves. userId stays the impersonated user, so ownership, current_user.* RLS and permissions still resolve to them. ATTRIBUTION ONLY — no security middleware reads it and it never becomes the authorization subject. Server-constructed only from the session read that admitted the caller, never client-supplied. Surfaced to hooks as HookContext.provenance.impersonatedBy and recorded by the audit writer as sys_audit_log.metadata.impersonated_by and on the sys_activity row metadata; it does not move actor or user_id.
permissions string[] optional (default: [])
permissionSetAddresses { packageId: string | null; name: string }[] optional The permission sets the principal was granted, each as its (packageId, name) address (ADR-0150 D3). Filled only from a resolved (package, name), never from a guessed holder; a name the resolution rule refuses never appears. permissions stays the display and compatibility field, same order and contents. Optional with no default: a context resolved without addresses parses without the key, and since no reader consumes it yet its absence changes no answer. Not an access gate. Server-constructed only, never client-supplied.
systemPermissions string[] optional
tabPermissions Record<string, Enum<'visible' | 'hidden' | 'default_on' | 'default_off'>> optional
org_user_ids string[] optional
accessible_org_ids string[] optional
rlsMembership Record<string, string[]> optional
isSystem boolean optional (default: false)
flowRunId string optional
skipTriggers boolean optional
skipAutomations boolean optional
seedReplay boolean optional
skipStateMachine boolean optional
preserveAudit boolean optional Historical import: preserve the ORIGINAL audit timeline for this write instead of stamping it "now". Opt-in and server-constructed only, never client-supplied. On the UPDATE path it admits a whitelist — the audit/timestamp family (created_at / created_by / updated_at / updated_by) plus author-declared business readonly fields — while platform-managed system columns (tenancy, generated) stay stripped. On INSERT the exemption does NOT apply: the create-side static readonly strip runs inside engine.insert itself (after the beforeInsert hooks, before validation — the 2026-09-03 ruling; the DataProtocol ingress copy it replaced is deleted) and reads only context.isSystem, so a non-system create carrying preserveAudit still has those fields stripped and is warned (WARN) that the exemption is UPDATE-only — replaying archival readonly facts on create requires a system context. Permissions / RLS / field-level security are unaffected.
keptOptionValues Record<string, string[]> optional Import with createMissingOptions: per field name, the option values the import kept because they matched none of the field's options. The write-path option check admits exactly these values on this write (and still refuses every other value outside the options); the field's options are not changed, and a later write that sends the field is judged against them again. Server-constructed only (set by the import runner), never client-supplied.
oauthScopes string[] optional
accessToken string optional
transaction any optional
traceId string optional

Nested Shape: ExecutionContext.performedBy

Property Type Required Description
clientId string optional The OAuth client (azp, a registered sys_oauth_application id) that performed the operation. Set by the /mcp OAuth door only; absent when the in-product AI performed it.
agentId string optional The in-product AI agent that performed the operation for the signed-in person in userId: the agent the chat runs as (the same value as ToolExecutionContext.agentId). Set by the server-constructed in-product AI path only, and only after the server resolved it as the agent it actually ran; never a sys_user id or an OAuth client id.
conversationId string optional The AI conversation the operation was performed in (the same id as ToolExecutionContext.conversationId). Set beside agentId by the in-product AI path, and only after the server resolved it as a conversation the person in userId owns.
confirmationId string optional The confirmation the person gave before the operation ran: the id of the pending item their approval decided (the in-app pending action id, or the pending-confirmation service item id). Stamped only after the server resolved it as a pending item the person in userId decided for this operation; absent when the operation needed no confirmation.

Nested Shape: ExecutionContext.permissionSetAddresses[number]

The address of one granted permission set (ADR-0150 D3): the package that holds it (null for the environment's own or the platform's) and its name.

Property Type Required Description
packageId string | null ✅ The package that holds the permission set, a non-empty package id; null for a set no package holds (environment-authored, or registered by the platform). Always present: an address names its holder.
name string ✅ The permission set's name, as its holder declares it (never rewritten or prefixed).

PermissionSetAddress

The address of one granted permission set (ADR-0150 D3): the package that holds it (null for the environment's own or the platform's) and its name.

Properties

Property Type Required Description
packageId string | null ✅ The package that holds the permission set, a non-empty package id; null for a set no package holds (environment-authored, or registered by the platform). Always present: an address names its holder.
name string ✅ The permission set's name, as its holder declares it (never rewritten or prefixed).