// @bun
var{defineProperty:L,getOwnPropertyNames:F,getOwnPropertyDescriptor:O}=Object,M=Object.prototype.hasOwnProperty;function R(H){return this[H]}var d=(H)=>{var z=(I??=new WeakMap).get(H),J;if(z)return z;if(z=L({},"__esModule",{value:!0}),H&&typeof H==="object"||typeof H==="function"){for(var j of F(H))if(!M.call(z,j))L(z,j,{get:R.bind(H,j),enumerable:!(J=O(H,j))||J.enumerable})}return I.set(H,z),z},I;var g=(H)=>H;function E(H,z){this[H]=g.bind(null,z)}var v=(H,z)=>{for(var J in z)L(H,J,{get:z[J],enumerable:!0,configurable:!0,set:E.bind(z,J)})};var u=(H,z)=>()=>(H&&(z=H(H=0)),z);var Z={Idea:"idea",InCreation:"in_creation",Experimental:"experimental",Beta:"beta",Stable:"stable",Deprecated:"deprecated"},U={PlatformCore:"platform.core",PlatformSigil:"platform.sigil",PlatformMarketplace:"platform.marketplace",PlatformMessaging:"platform.messaging",PlatformContent:"platform.content",PlatformFeatureFlags:"platform.featureflags",PlatformFinance:"platform.finance"},y=U,B={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"},o=B;import{compareVersions as f}from"compare-versions";var $=(H,z)=>`${H}.v${z}`;class h{items=new Map;surfaceIndex=null;register(H){let z=$(H.meta.key,H.meta.version);if(this.items.has(z))throw Error(`Duplicate capability ${z}`);return this.items.set(z,H),this.surfaceIndex=null,this}list(){return[...this.items.values()]}get(H,z){if(z!=null)return this.items.get($(H,z));let J;for(let j of this.items.values()){if(j.meta.key!==H)continue;if(!J||f(j.meta.version,J.meta.version)>0)J=j}return J}satisfies(H,z){if(H.optional)return!0;if(z?.some((j)=>S(j,H)))return!0;let J=H.version?this.get(H.key,H.version):this.get(H.key);if(!J)return!1;if(H.kind&&J.meta.kind!==H.kind)return!1;if(H.version!=null&&J.meta.version!==H.version)return!1;return!0}buildSurfaceIndex(){if(this.surfaceIndex)return this.surfaceIndex;this.surfaceIndex=new Map;for(let H of this.items.values()){let z=$(H.meta.key,H.meta.version);for(let J of H.provides??[]){let j=`${J.surface}:${J.key}`;if(!this.surfaceIndex.has(j))this.surfaceIndex.set(j,new Set);this.surfaceIndex.get(j)?.add(z)}}return this.surfaceIndex}getOperationsFor(H,z){let J=this.get(H,z);if(!J)return[];return J.provides?.filter((j)=>j.surface==="operation").map((j)=>j.key)??[]}getEventsFor(H,z){let J=this.get(H,z);if(!J)return[];return J.provides?.filter((j)=>j.surface==="event").map((j)=>j.key)??[]}getPresentationsFor(H,z){let J=this.get(H,z);if(!J)return[];return J.provides?.filter((j)=>j.surface==="presentation").map((j)=>j.key)??[]}getWorkflowsFor(H,z){let J=this.get(H,z);if(!J)return[];return J.provides?.filter((j)=>j.surface==="workflow").map((j)=>j.key)??[]}getResourcesFor(H,z){let J=this.get(H,z);if(!J)return[];return J.provides?.filter((j)=>j.surface==="resource").map((j)=>j.key)??[]}getCapabilitiesForOperation(H){let J=this.buildSurfaceIndex().get(`operation:${H}`);if(!J)return[];return[...J].map((j)=>{let Q=this.items.get(j);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getCapabilitiesForEvent(H){let J=this.buildSurfaceIndex().get(`event:${H}`);if(!J)return[];return[...J].map((j)=>{let Q=this.items.get(j);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getCapabilitiesForPresentation(H){let J=this.buildSurfaceIndex().get(`presentation:${H}`);if(!J)return[];return[...J].map((j)=>{let Q=this.items.get(j);return{key:Q?.meta.key??"",version:Q?.meta.version??""}})}getAncestors(H,z){let J=[],j=new Set,Q=this.get(H,z);while(Q?.extends){let X=$(Q.extends.key,Q.extends.version);if(j.has(X))break;j.add(X);let Y=this.get(Q.extends.key,Q.extends.version);if(!Y)break;J.push(Y),Q=Y}return J}getEffectiveRequirements(H,z){let J=this.get(H,z);if(!J)return[];let j=this.getAncestors(H,z),Q=new Map;for(let X of[...j].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(H,z){let J=this.get(H,z);if(!J)return[];let j=this.getAncestors(H,z),Q=[];for(let X of[...j].reverse())Q.push(...X.provides??[]);return Q.push(...J.provides??[]),Q}}function S(H,z){if(H.key!==z.key)return!1;if(z.version!=null&&H.version!==z.version)return!1;return!0}function p(H){return $(H.meta.key,H.meta.version)}function N(H){return H}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 \u2192 Specs
registry.getOperationsFor('payments');      // ['payments.charge.create', ...]
registry.getEventsFor('payments');          // ['payments.charge.succeeded', ...]
registry.getPresentationsFor('payments');   // ['payments.dashboard', ...]

// Reverse lookups: Spec \u2192 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(H,z){let J=z?`.v${z}`:"";super(`Missing required capability: ${H}${J}`);this.name="CapabilityMissingError",this.capabilityKey=H,this.requiredVersion=z}}class D{capabilities;capabilityVersions;constructor(H){let z=new Set,J=new Map;for(let j of H)z.add(j.key),J.set(j.key,j.version);this.capabilities=z,this.capabilityVersions=J}hasCapability(H,z){if(!this.capabilities.has(H))return!1;if(z!=null)return this.capabilityVersions.get(H)===z;return!0}requireCapability(H,z){if(!this.hasCapability(H,z))throw new _(H,z)}hasAllCapabilities(H){return H.every((z)=>this.capabilities.has(z))}hasAnyCapability(H){return H.some((z)=>this.capabilities.has(z))}getMatchingCapabilities(H){if(!H.includes("*"))return this.capabilities.has(H)?[H]:[];let z=H.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),J=new RegExp(`^${z}$`);return[...this.capabilities].filter((j)=>J.test(j))}}function t(H){return new D(H)}function r(){return new D([])}function s(H){return new D(H)}function T(H,z){if(!z.capability)return{allowed:!0};let{key:J,version:j}=z.capability;if(H.hasCapability(J,j))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:j},reason:`Operation "${z.meta.key}" requires capability "${J}.v${j}"`}}function j0(H,z){let J=T(H,z);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function W(H,z){if(!z.capability)return{allowed:!0};let{key:J,version:j}=z.capability;if(H.hasCapability(J,j))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:j},reason:`Event "${z.meta.key}" requires capability "${J}.v${j}"`}}function z0(H,z){let J=W(H,z);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function V(H,z){if(!z.capability)return{allowed:!0};let{key:J,version:j}=z.capability;if(H.hasCapability(J,j))return{allowed:!0};return{allowed:!1,missingCapability:{key:J,version:j},reason:`Presentation "${z.meta.key}" requires capability "${J}.v${j}"`}}function J0(H,z){let J=V(H,z);if(!J.allowed&&J.missingCapability)throw new _(J.missingCapability.key,J.missingCapability.version)}function Q0(H,z){return z.filter((J)=>T(H,J).allowed)}function X0(H,z){return z.filter((J)=>W(H,J).allowed)}function Y0(H,z){return z.filter((J)=>V(H,J).allowed)}var G=["platform.integrations"],P=["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:[...G],tags:[...P,"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."}]},C={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:[...G],tags:[...P,"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."}]},q={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:[...G],tags:[...P,"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 $0(H){return H.register(x).register(C).register(q)}var A=["platform.finance"],w=["open-banking","finance"],m={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:[...A],tags:[...w],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:[...A],tags:[...w,"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."}]},k={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:[...A],tags:[...w,"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 U0(H){return H.register(m).register(K).register(k)}function G0(H){let z=[],J=[];for(let j of H.capabilities.list()){let Q=`${j.meta.key}.v${j.meta.version}`;for(let X of j.provides??[])if(!b(H,X.surface,X.key))z.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(H.operations){for(let j of H.operations.list())if(j.capability){let Q=H.capabilities.get(j.capability.key,j.capability.version);if(!Q)z.push({type:"capability_not_found",message:`Operation "${j.meta.key}" references capability "${j.capability.key}.v${j.capability.version}" but capability not found`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"operation"});else if(!Q.provides?.some((Y)=>Y.surface==="operation"&&Y.key===j.meta.key))z.push({type:"surface_not_in_provides",message:`Operation "${j.meta.key}" claims capability "${j.capability.key}.v${j.capability.version}" but not in capability's provides`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"operation"})}}if(H.events){for(let j of H.events.list())if(j.capability){let Q=H.capabilities.get(j.capability.key,j.capability.version);if(!Q)z.push({type:"capability_not_found",message:`Event "${j.meta.key}" references capability "${j.capability.key}.v${j.capability.version}" but capability not found`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"event"});else if(!Q.provides?.some((Y)=>Y.surface==="event"&&Y.key===j.meta.key))z.push({type:"surface_not_in_provides",message:`Event "${j.meta.key}" claims capability "${j.capability.key}.v${j.capability.version}" but not in capability's provides`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"event"})}}if(H.presentations){for(let j of H.presentations.list())if(j.capability){let Q=H.capabilities.get(j.capability.key,j.capability.version);if(!Q)z.push({type:"capability_not_found",message:`Presentation "${j.meta.key}" references capability "${j.capability.key}.v${j.capability.version}" but capability not found`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"presentation"});else if(!Q.provides?.some((Y)=>Y.surface==="presentation"&&Y.key===j.meta.key))z.push({type:"surface_not_in_provides",message:`Presentation "${j.meta.key}" claims capability "${j.capability.key}.v${j.capability.version}" but not in capability's provides`,specKey:j.meta.key,capabilityKey:`${j.capability.key}.v${j.capability.version}`,surface:"presentation"})}}return{valid:z.length===0,errors:z,warnings:J}}function b(H,z,J){switch(z){case"operation":return H.operations?.has(J)??!0;case"event":return H.events?.has(J)??!0;case"presentation":return H.presentations?.has(J)??!0;case"workflow":case"resource":return!0;default:return!0}}function P0(H){let z={operations:[],events:[],presentations:[]};if(H.operations){for(let J of H.operations.list())if(!J.capability)z.operations.push(J.meta.key)}if(H.events){for(let J of H.events.list())if(!J.capability)z.events.push(J.meta.key)}if(H.presentations){for(let J of H.presentations.list())if(!J.capability)z.presentations.push(J.meta.key)}return z}var R0=N({meta:{key:"app-config",version:"1.0.0",title:"App Configuration Capability",description:"Provides tenant app configuration lifecycle management.",domain:"platform",owners:[U.PlatformSigil],tags:[B.Hygiene],kind:"api",stability:Z.Stable},provides:[],requires:[]});export{R0 as AppConfigCapability};
