[AAASM-1561] ✨ (sdk): Add enforcementMode parameter to initAssembly#48
Merged
Merged
Conversation
Operator surface for the per-agent observe-mode override the gateway landed in AAASM-1557 + AAASM-1564, mirroring AAASM-1560 (Python SDK). * New EnforcementMode = 'enforce' | 'observe' | 'disabled' union type in src/types/enforcement-mode.ts, exported from the public types index. * New ENFORCEMENT_MODES readonly-array constant for runtime validation from non-TS callers (plain JS, JSON config, dynamic input). * AssemblyConfig gains optional enforcementMode?: EnforcementMode. Default (undefined) omits the field from the registration body so a pre-feature SDK call produces a pre-feature wire shape; the gateway applies its server-side default of live enforce. * initAssembly validates an unknown string with a RangeError so a typo fails fast instead of silently registering under live enforcement. * buildRegistrationEvent emits enforcement_mode (snake_case wire token) when set. The gateway's REST -> gRPC bridge maps it onto RegisterRequest.enforcement_mode (proto enum) per AAASM-1555. * AssemblyContext echoes the value for parity with the existing parentAgentId / teamId / delegationReason fields. Refs: AAASM-1561
Eight new vitest cases (3 parametrized + 5 standalone) covering AAASM-1561: * Each of enforce / observe / disabled lands on AssemblyContext * Default (undefined) is preserved on the context * Unknown string raises RangeError with a clear message * Setting an unrelated field doesn't leak enforcementMode onto context * Registration body carries enforcement_mode (snake_case) when set * Registration body omits enforcement_mode when caller didn't set it The wire-shape tests reuse the mock-binding pattern from tests/topology-registration.test.ts so the assertion is on the actual event passed to the native sendEvent call. Refs: AAASM-1561
Lets callers import the type/value directly from '@agent-assembly/sdk':
import { initAssembly, type EnforcementMode } from '@agent-assembly/sdk';
instead of the longer '@agent-assembly/sdk/types' subpath. Matches the
re-export pattern the package already uses for AssemblyConfig /
AssemblyContext / AssemblyMode.
Refs: AAASM-1561
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Contributor
Author
Review by Claude CodeCI status✅ All 26 checks green on the first pass — no flakes, no reruns.
Scope review vs AAASM-1561
Design choices worth noting
Bisectability3 commits, each builds and tests green at its tip:
Verdict✅ Ready to approve and merge. After merge, three SDKs will be at parity with import { initAssembly, type EnforcementMode } from '@agent-assembly/sdk';
const mode: EnforcementMode = process.env.AA_ENFORCEMENT_MODE === 'observe' ? 'observe' : 'enforce';
const ctx = await initAssembly({
gatewayUrl: 'http://localhost:8080',
apiKey: '...',
agentId: 'experimental-agent',
enforcementMode: mode,
});The last SDK pickup — AAASM-1562 (Go SDK) — is fully independent of any open PR. After that, only AAASM-1563 (dashboard) and AAASM-1565 (docs) remain. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Per-agent governance posture override for the Node.js SDK. Mirrors the design that landed in AAASM-1560 (python-sdk #59):
Shipped
EnforcementMode = 'enforce' | 'observe' | 'disabled'union typesrc/types/enforcement-mode.tsENFORCEMENT_MODESreadonly-array constant for runtime validationAssemblyConfig.enforcementMode?: EnforcementMode(optional)src/types/assembly-config.tsAssemblyContext.enforcementMode?: EnforcementMode(echo)src/types/assembly-context.tsinitAssemblyrejects unknown strings withRangeErrorsrc/core/init-assembly.tsbuildRegistrationEventemitsenforcement_mode(snake_case) when setAssemblyContextechoes the value at returnsrc/types/index.ts+src/index.tsType of Change
Breaking Changes
AssemblyConfig.enforcementModeis optional. When omitted,buildRegistrationEventleaves the field off the wire — a pre-feature SDK call produces a pre-featureevent_type: registerbody shape, and the gateway then applies its server-side default (liveenforce). Semantically identical to before. Explicit'enforce'/'observe'/'disabled'from the caller still serialize.Related Issues
What's in here
3 commits:
enforcementModeend-to-end ininitAssembly(new type alias + AssemblyConfig + AssemblyContext + validation + buildRegistrationEvent + context echo)EnforcementMode+ENFORCEMENT_MODESfrom package root so callers don't need the/typessubpathTesting
AC checklist
initAssembly({ enforcementMode: 'observe' })passesenforcement_mode: OBSERVEinRegisterAgent(wire shape verified byemits enforcement_mode on the registration body when set)enforcementModedefaults to'enforce'semantically (via gateway server-side default when unset); existing tests pass without changesRangeError)pnpm typecheckcleanChecklist
pnpm lint,pnpm format— only my changed files committed; pre-existing format drift in 56 unrelated files was deliberately not staged)