var{defineProperty:L,getOwnPropertyNames:w,getOwnPropertyDescriptor:T}=Object,V=Object.prototype.hasOwnProperty;function F(j){return this[j]}var b=(j)=>{var H=(A??=new WeakMap).get(j),J;if(H)return H;if(H=L({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var z of w(j))if(!V.call(H,z))L(H,z,{get:F.bind(j,z),enumerable:!(J=T(j,z))||J.enumerable})}return A.set(j,H),H},A;var O=(j)=>j;function M(j,H){this[j]=O.bind(null,H)}var d=(j,H)=>{for(var J in H)L(j,J,{get:H[J],enumerable:!0,configurable:!0,set:M.bind(H,J)})};var v=(j,H)=>()=>(j&&(H=j(j=0)),H);var Z={Idea:"idea",InCreation:"in_creation",Experimental:"experimental",Beta:"beta",Stable:"stable",Deprecated:"deprecated"},R={PlatformCore:"platform.core",PlatformSigil:"platform.sigil",PlatformMarketplace:"platform.marketplace",PlatformMessaging:"platform.messaging",PlatformContent:"platform.content",PlatformFeatureFlags:"platform.featureflags",PlatformFinance:"platform.finance"},l=R,g={Spots:"spots",Collectivity:"collectivity",Marketplace:"marketplace",Sellers:"sellers",Auth:"auth",Login:"login",Signup:"signup",Guide:"guide",Docs:"docs",I18n:"i18n",Incident:"incident",Automation:"automation",Hygiene:"hygiene"},y=g;import{compareVersions as h}from"compare-versions";var $=(j,H)=>`${j}.v${H}`;class E{items=new Map;surfaceIndex=null;register(j){let H=$(j.meta.key,j.meta.version);if(this.items.has(H))throw Error(`Duplicate capability ${H}`);return this.items.set(H,j),this.surfaceIndex=null,this}list(){return[...this.items.values()]}get(j,H){if(H!=null)return this.items.get($(j,H));let J;for(let z of this.items.values()){if(z.meta.key!==j)continue;if(!J||h(z.meta.version,J.meta.version)>0)J=z}return J}satisfies(j,H){if(j.optional)return!0;if(H?.some((z)=>S(z,j)))return!0;let J=j.version?this.get(j.key,j.version):this.get(j.key);if(!J)return!1;if(j.kind&&J.meta.kind!==j.kind)return!1;if(j.version!=null&&J.meta.version!==j.version)return!1;return!0}buildSurfaceIndex(){if(this.surfaceIndex)return this.surfaceIndex;this.surfaceIndex=new Map;for(let j of this.items.values()){let H=$(j.meta.key,j.meta.version);for(let J of j.provides??[]){let z=`${J.surface}:${J.key}`;if(!this.surfaceIndex.has(z))this.surfaceIndex.set(z,new Set);this.surfaceIndex.get(z)?.add(H)}}return this.surfaceIndex}getOperationsFor(j,H){let J=this.get(j,H);if(!J)return[];return J.provides?.filter((z)=>z.surface==="operation").map((z)=>z.key)??[]}getEventsFor(j,H){let J=this.get(j,H);if(!J)return[];return J.provides?.filter((z)=>z.surface==="event").map((z)=>z.key)??[]}getPresentationsFor(j,H){let J=this.get(j,H);if(!J)return[];return J.provides?.filter((z)=>z.surface==="presentation").map((z)=>z.key)??[]}getWorkflowsFor(j,H){let J=this.get(j,H);if(!J)return[];return J.provides?.filter((z)=>z.surface==="workflow").map((z)=>z.key)??[]}getResourcesFor(j,H){let J=this.get(j,H);if(!J)return[];return J.provides?.filter((z)=>z.surface==="resource").map((z)=>z.key)??[]}getCapabilitiesForOperation(j){let J=this.buildSurfaceIndex().get(`operation:${j}`);if(!J)return[];return[...J].map((z)=>{let Q=this.items.get(z);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getCapabilitiesForEvent(j){let J=this.buildSurfaceIndex().get(`event:${j}`);if(!J)return[];return[...J].map((z)=>{let Q=this.items.get(z);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getCapabilitiesForPresentation(j){let J=this.buildSurfaceIndex().get(`presentation:${j}`);if(!J)return[];return[...J].map((z)=>{let Q=this.items.get(z);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getAncestors(j,H){let J=[],z=new Set,Q=this.get(j,H);while(Q?.extends){let X=$(Q.extends.key,Q.extends.version);if(z.has(X))break;z.add(X);let Y=this.get(Q.extends.key,Q.extends.version);if(!Y)break;J.push(Y),Q=Y}return J}getEffectiveRequirements(j,H){let J=this.get(j,H);if(!J)return[];let z=this.getAncestors(j,H),Q=new Map;for(let X of[...z].reverse())for(let Y of X.requires??[])Q.set(Y.key,Y);for(let X of J.requires??[])Q.set(X.key,X);return[...Q.values()]}getEffectiveSurfaces(j,H){let J=this.get(j,H);if(!J)return[];let z=this.getAncestors(j,H),Q=[];for(let X of[...z].reverse())Q.push(...X.provides??[]);return Q.push(...J.provides??[]),Q}}function S(j,H){if(j.key!==H.key)return!1;if(H.version!=null&&j.version!==H.version)return!1;return!0}function n(j){return $(j.meta.key,j.meta.version)}function p(j){return j}var a=[{id:"docs.tech.contracts.capabilities",title:"CapabilitySpec Overview",summary:"Capability specs define what a module provides (operations, events, presentations) and requires (dependencies). They enable bidirectional linking, inheritance, runtime enforcement, and automated validation.",kind:"reference",visibility:"public",route:"/docs/tech/contracts/capabilities",tags:["tech","contracts","capabilities"],body:`# CapabilitySpec Overview

## Purpose

Capabilities are **module interfaces** that define:
1. What operations, events, and presentations a module exposes (\`provides\`)
2. What other capabilities it depends on (\`requires\`)
3. Inheritance hierarchies via \`extends\`

They enable:
- **Bidirectional linking**: Specs reference capabilities, capabilities list their specs
- **Dependency validation**: Features can't install without satisfying requirements
- **Runtime enforcement**: Check capabilities before executing operations
- **Inheritance**: Build capability hierarchies with shared requirements

## Schema

\`\`\`ts
export interface CapabilitySpec {
  meta: CapabilityMeta;              // ownership metadata + { key, version, kind }
  extends?: CapabilityRef;           // NEW: inherit from parent capability
  provides?: CapabilitySurfaceRef[]; // surfaces this capability exposes
  requires?: CapabilityRequirement[];// capabilities that must exist
}
\`\`\`

### Bidirectional Linking

Operations, events, and presentations can now declare their capability:

\`\`\`ts
// In OperationSpec
{
  meta: { key: 'payments.charge.create', ... },
  capability: { key: 'payments', version: '1.0.0' }, // Links to capability
  io: { ... }
}

// In CapabilitySpec
{
  meta: { key: 'payments', version: '1.0.0', ... },
  provides: [
    { surface: 'operation', key: 'payments.charge.create' }
  ]
}
\`\`\`

Validation ensures both sides match via \`validateCapabilityConsistency()\`.

## Registry Query Methods

The \`CapabilityRegistry\` now provides rich query capabilities:

\`\`\`ts
// Forward lookups: Capability → Specs
registry.getOperationsFor('payments');      // ['payments.charge.create', ...]
registry.getEventsFor('payments');          // ['payments.charge.succeeded', ...]
registry.getPresentationsFor('payments');   // ['payments.dashboard', ...]

// Reverse lookups: Spec → Capabilities
registry.getCapabilitiesForOperation('payments.charge.create');
registry.getCapabilitiesForEvent('payments.charge.succeeded');
registry.getCapabilitiesForPresentation('payments.dashboard');

// Inheritance
registry.getAncestors('payments.stripe');           // Parent chain
registry.getEffectiveRequirements('payments.stripe'); // Includes inherited
registry.getEffectiveSurfaces('payments.stripe');     // Includes inherited
\`\`\`

## Inheritance

Capabilities can extend other capabilities:

\`\`\`ts
// Base capability
defineCapability({
  meta: { key: 'payments.base', version: '1.0.0', ... },
  requires: [{ key: 'auth', version: '1.0.0' }],
  provides: [{ surface: 'operation', key: 'payments.list' }]
});

// Child capability inherits requirements
defineCapability({
  meta: { key: 'payments.stripe', version: '1.0.0', ... },
  extends: { key: 'payments.base', version: '1.0.0' },
  requires: [{ key: 'encryption', version: '1.0.0' }], // Added
  provides: [{ surface: 'operation', key: 'payments.stripe.charge' }]
});

// getEffectiveRequirements('payments.stripe') returns:
// [{ key: 'auth', ... }, { key: 'encryption', ... }]
\`\`\`

## Runtime Enforcement

Use \`CapabilityContext\` for opt-in runtime checks:

\`\`\`ts

// Create context from user's enabled capabilities
const ctx = createCapabilityContext(user.capabilities);

// Check capability
if (ctx.hasCapability('payments')) {
  // User can access payments features
}

// Assert capability (throws if missing)
ctx.requireCapability('payments');

// Guard an operation
assertCapabilityForOperation(ctx, paymentOperation);

// Filter operations by enabled capabilities
const allowedOps = filterOperationsByCapability(ctx, allOperations);
\`\`\`

## Validation

Validate bidirectional consistency between capabilities and specs:

\`\`\`ts

const result = validateCapabilityConsistency({
  capabilities: capabilityRegistry,
  operations: operationRegistry,
  events: eventRegistry,
  presentations: presentationRegistry,
});

if (!result.valid) {
  console.error('Validation errors:', result.errors);
}

// Find specs without capability assignment (informational)
const orphans = findOrphanSpecs({ capabilities, operations });
\`\`\`

## Feature Integration

During \`installFeature()\`:
1. \`provides\` capabilities must exist in the registry
2. \`requires\` must be satisfied by registered capabilities or local \`provides\`
3. Referenced operations/events/presentations must exist

## Authoring Guidelines

1. **Register capabilities first** before referencing them in features
2. **Use bidirectional linking** - set \`capability\` on specs and list them in \`provides\`
3. **Version consciously** - bump versions on breaking changes
4. **Document dependencies** with \`reason\` strings
5. **Use inheritance** for capability families with shared requirements
6. **Validate during CI** with \`validateCapabilityConsistency()\`

## Error Handling

\`\`\`ts

try {
  ctx.requireCapability('premium-features');
} catch (err) {
  if (err instanceof CapabilityMissingError) {
    console.log('Missing:', err.capabilityKey);
    console.log('Required version:', err.requiredVersion);
  }
}
\`\`\`

## API Reference

### Types
- \`CapabilitySpec\` - Capability definition
- \`CapabilityRef\` - Reference to a capability (key + version)
- \`CapabilitySurfaceRef\` - Reference to a provided surface
- \`CapabilityRequirement\` - Dependency requirement
- \`CapabilityContext\` - Runtime capability context
- \`CapabilityValidationResult\` - Validation result

### Functions
- \`defineCapability(spec)\` - Define a capability spec
- \`createCapabilityContext(caps)\` - Create runtime context
- \`validateCapabilityConsistency(deps)\` - Validate bidirectional links
- \`findOrphanSpecs(deps)\` - Find specs without capability assignment
- \`assertCapabilityForOperation/Event/Presentation(ctx, spec)\` - Guards
- \`filterOperationsByCapability(ctx, ops)\` - Filter by enabled capabilities
`}];class _ extends Error{capabilityKey;requiredVersion;constructor(j,H){let J=H?`.v${H}`:"";super(`Missing required capability: ${j}${J}`);this.name="CapabilityMissingError",this.capabilityKey=j,this.requiredVersion=H}}class D{capabilities;capabilityVersions;constructor(j){let H=new Set,J=new Map;for(let z of j)H.add(z.key),J.set(z.key,z.version);this.capabilities=H,this.capabilityVersions=J}hasCapability(j,H){if(!this.capabilities.has(j))return!1;if(H!=null)return this.capabilityVersions.get(j)===H;return!0}requireCapability(j,H){if(!this.hasCapability(j,H))throw new _(j,H)}hasAllCapabilities(j){return j.every((H)=>this.capabilities.has(H))}hasAnyCapability(j){return j.some((H)=>this.capabilities.has(H))}getMatchingCapabilities(j){if(!j.includes("*"))return this.capabilities.has(j)?[j]:[];let H=j.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),J=new RegExp(`^${H}$`);return[...this.capabilities].filter((z)=>J.test(z))}}function i(j){return new D(j)}function r(){return new D([])}function s(j){return new D(j)}function I(j,H){if(!H.capability)return{allowed:!0};let{key:J,version:z}=H.capability;if(j.hasCapability(J,z))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:z},reason:`Operation "${H.meta.key}" requires capability "${J}.v${z}"`}}function zj(j,H){let J=I(j,H);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function N(j,H){if(!H.capability)return{allowed:!0};let{key:J,version:z}=H.capability;if(j.hasCapability(J,z))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:z},reason:`Event "${H.meta.key}" requires capability "${J}.v${z}"`}}function Hj(j,H){let J=N(j,H);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function W(j,H){if(!H.capability)return{allowed:!0};let{key:J,version:z}=H.capability;if(j.hasCapability(J,z))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:z},reason:`Presentation "${H.meta.key}" requires capability "${J}.v${z}"`}}function Jj(j,H){let J=W(j,H);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function Qj(j,H){return H.filter((J)=>I(j,J).allowed)}function Xj(j,H){return H.filter((J)=>N(j,J).allowed)}function Yj(j,H){return H.filter((J)=>W(j,J).allowed)}var U=["platform.integrations"],B=["meeting-recorder","transcripts","integrations"],x={meta:{key:"meeting-recorder.meetings.read",version:"1.0.0",kind:"integration",title:"Meeting Recorder Meetings (Read)",description:"Provides read-only access to recorded meetings and their metadata.",domain:"integrations",owners:[...U],tags:[...B,"meetings"],stability:Z.Experimental},provides:[{surface:"operation",key:"meeting-recorder.meetings.list",version:"1.0.0",description:"List meetings available from the recorder provider."},{surface:"operation",key:"meeting-recorder.meetings.get",version:"1.0.0",description:"Fetch detailed metadata for a specific meeting."}]},f={meta:{key:"meeting-recorder.transcripts.read",version:"1.0.0",kind:"integration",title:"Meeting Recorder Transcripts (Read)",description:"Enables retrieval of transcripts for recorded meetings from external providers.",domain:"integrations",owners:[...U],tags:[...B,"transcripts"],stability:Z.Experimental},provides:[{surface:"operation",key:"meeting-recorder.transcripts.get",version:"1.0.0",description:"Fetch the transcript for a specific meeting recording."},{surface:"operation",key:"meeting-recorder.transcripts.sync",version:"1.0.0",description:"Trigger a transcript sync from the recorder provider."}]},C={meta:{key:"meeting-recorder.webhooks",version:"1.0.0",kind:"integration",title:"Meeting Recorder Webhooks",description:"Allows processing of webhook events for meeting transcript readiness.",domain:"integrations",owners:[...U],tags:[...B,"webhooks"],stability:Z.Experimental},provides:[{surface:"operation",key:"meeting-recorder.webhooks.ingest",version:"1.0.0",description:"Ingest and verify meeting recorder webhook payloads."}]};function $j(j){return j.register(x).register(f).register(C)}var G=["platform.finance"],P=["open-banking","finance"],q={meta:{key:"openbanking.accounts.read",version:"1.0.0",kind:"integration",title:"Open Banking Accounts (Read)",description:"Provides read-only access to linked bank accounts, including account summaries and metadata.",domain:"finance",owners:[...G],tags:[...P],stability:Z.Experimental},provides:[{surface:"operation",key:"openbanking.accounts.list",version:"1.0.0",description:"List bank accounts linked to a Powens open banking connection."},{surface:"operation",key:"openbanking.accounts.get",version:"1.0.0",description:"Retrieve the canonical bank account record for a specific account."},{surface:"operation",key:"openbanking.accounts.sync",version:"1.0.0",description:"Trigger a refresh of bank account metadata from the open banking provider."}]},K={meta:{key:"openbanking.transactions.read",version:"1.0.0",kind:"integration",title:"Open Banking Transactions (Read)",description:"Enables retrieval of transaction history for linked bank accounts via open banking providers.",domain:"finance",owners:[...G],tags:[...P,"transactions"],stability:Z.Experimental},provides:[{surface:"operation",key:"openbanking.transactions.list",version:"1.0.0",description:"List transactions for a given bank account with optional date filtering."},{surface:"operation",key:"openbanking.transactions.sync",version:"1.0.0",description:"Synchronise transactions from the open banking provider into the canonical ledger."}]},m={meta:{key:"openbanking.balances.read",version:"1.0.0",kind:"integration",title:"Open Banking Balances (Read)",description:"Allows querying of current and available balances for linked bank accounts via open banking providers.",domain:"finance",owners:[...G],tags:[...P,"balances"],stability:Z.Experimental},provides:[{surface:"operation",key:"openbanking.balances.get",version:"1.0.0",description:"Retrieve the latest known balances for a specified bank account."},{surface:"operation",key:"openbanking.balances.refresh",version:"1.0.0",description:"Force a balance refresh from the open banking provider."}]};function Uj(j){return j.register(q).register(K).register(m)}function Gj(j){let H=[],J=[];for(let z of j.capabilities.list()){let Q=`${z.meta.key}.v${z.meta.version}`;for(let X of z.provides??[])if(!k(j,X.surface,X.key))H.push({type:"missing_surface_spec",message:`Capability "${Q}" provides ${X.surface} "${X.key}" but spec not found`,capabilityKey:Q,surface:X.surface,specKey:X.key})}if(j.operations){for(let z of j.operations.list())if(z.capability){let Q=j.capabilities.get(z.capability.key,z.capability.version);if(!Q)H.push({type:"capability_not_found",message:`Operation "${z.meta.key}" references capability "${z.capability.key}.v${z.capability.version}" but capability not found`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"operation"});else if(!Q.provides?.some((Y)=>Y.surface==="operation"&&Y.key===z.meta.key))H.push({type:"surface_not_in_provides",message:`Operation "${z.meta.key}" claims capability "${z.capability.key}.v${z.capability.version}" but not in capability's provides`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"operation"})}}if(j.events){for(let z of j.events.list())if(z.capability){let Q=j.capabilities.get(z.capability.key,z.capability.version);if(!Q)H.push({type:"capability_not_found",message:`Event "${z.meta.key}" references capability "${z.capability.key}.v${z.capability.version}" but capability not found`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"event"});else if(!Q.provides?.some((Y)=>Y.surface==="event"&&Y.key===z.meta.key))H.push({type:"surface_not_in_provides",message:`Event "${z.meta.key}" claims capability "${z.capability.key}.v${z.capability.version}" but not in capability's provides`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"event"})}}if(j.presentations){for(let z of j.presentations.list())if(z.capability){let Q=j.capabilities.get(z.capability.key,z.capability.version);if(!Q)H.push({type:"capability_not_found",message:`Presentation "${z.meta.key}" references capability "${z.capability.key}.v${z.capability.version}" but capability not found`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"presentation"});else if(!Q.provides?.some((Y)=>Y.surface==="presentation"&&Y.key===z.meta.key))H.push({type:"surface_not_in_provides",message:`Presentation "${z.meta.key}" claims capability "${z.capability.key}.v${z.capability.version}" but not in capability's provides`,specKey:z.meta.key,capabilityKey:`${z.capability.key}.v${z.capability.version}`,surface:"presentation"})}}return{valid:H.length===0,errors:H,warnings:J}}function k(j,H,J){switch(H){case"operation":return j.operations?.has(J)??!0;case"event":return j.events?.has(J)??!0;case"presentation":return j.presentations?.has(J)??!0;case"workflow":case"resource":return!0;default:return!0}}function Pj(j){let H={operations:[],events:[],presentations:[]};if(j.operations){for(let J of j.operations.list())if(!J.capability)H.operations.push(J.meta.key)}if(j.events){for(let J of j.events.list())if(!J.capability)H.events.push(J.meta.key)}if(j.presentations){for(let J of j.presentations.list())if(!J.capability)H.presentations.push(J.meta.key)}return H}export{Gj as validateCapabilityConsistency,a as tech_contracts_capabilities_DocBlocks,Uj as registerOpenBankingCapabilities,$j as registerMeetingRecorderCapabilities,K as openBankingTransactionsReadCapability,m as openBankingBalancesReadCapability,q as openBankingAccountsReadCapability,C as meetingRecorderWebhooksCapability,f as meetingRecorderTranscriptsReadCapability,x as meetingRecorderMeetingsReadCapability,Pj as findOrphanSpecs,Yj as filterPresentationsByCapability,Qj as filterOperationsByCapability,Xj as filterEventsByCapability,p as defineCapability,r as createEmptyCapabilityContext,i as createCapabilityContext,s as createBypassCapabilityContext,W as checkCapabilityForPresentation,I as checkCapabilityForOperation,N as checkCapabilityForEvent,n as capabilityKey,Jj as assertCapabilityForPresentation,zj as assertCapabilityForOperation,Hj as assertCapabilityForEvent,E as CapabilityRegistry,_ as CapabilityMissingError};
