// @bun
var{defineProperty:H,getOwnPropertyNames:M,getOwnPropertyDescriptor:R}=Object,S=Object.prototype.hasOwnProperty;function f(D){return this[D]}var l=(D)=>{var O=($??=new WeakMap).get(D),Y;if(O)return O;if(O=H({},"__esModule",{value:!0}),D&&typeof D==="object"||typeof D==="function"){for(var _ of M(D))if(!S.call(O,_))H(O,_,{get:f.bind(D,_),enumerable:!(Y=R(D,_))||Y.enumerable})}return $.set(D,O),O},$;var g=(D)=>D;function h(D,O){this[D]=g.bind(null,O)}var y=(D,O)=>{for(var Y in O)H(D,Y,{get:O[Y],enumerable:!0,configurable:!0,set:h.bind(O,Y)})};var c=(D,O)=>()=>(D&&(O=D(D=0)),O);var j={Idea:"idea",InCreation:"in_creation",Experimental:"experimental",Beta:"beta",Stable:"stable",Deprecated:"deprecated"},E={PlatformCore:"platform.core",PlatformSigil:"platform.sigil",PlatformMarketplace:"platform.marketplace",PlatformMessaging:"platform.messaging",PlatformContent:"platform.content",PlatformFeatureFlags:"platform.featureflags",PlatformFinance:"platform.finance"},t=E,x={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"},a=x;import{compareVersions as C}from"compare-versions";var A=(D,O)=>`${D}.v${O}`;class m{items=new Map;surfaceIndex=null;register(D){let O=A(D.meta.key,D.meta.version);if(this.items.has(O))throw Error(`Duplicate capability ${O}`);return this.items.set(O,D),this.surfaceIndex=null,this}list(){return[...this.items.values()]}get(D,O){if(O!=null)return this.items.get(A(D,O));let Y;for(let _ of this.items.values()){if(_.meta.key!==D)continue;if(!Y||C(_.meta.version,Y.meta.version)>0)Y=_}return Y}satisfies(D,O){if(D.optional)return!0;if(O?.some((_)=>q(_,D)))return!0;let Y=D.version?this.get(D.key,D.version):this.get(D.key);if(!Y)return!1;if(D.kind&&Y.meta.kind!==D.kind)return!1;if(D.version!=null&&Y.meta.version!==D.version)return!1;return!0}buildSurfaceIndex(){if(this.surfaceIndex)return this.surfaceIndex;this.surfaceIndex=new Map;for(let D of this.items.values()){let O=A(D.meta.key,D.meta.version);for(let Y of D.provides??[]){let _=`${Y.surface}:${Y.key}`;if(!this.surfaceIndex.has(_))this.surfaceIndex.set(_,new Set);this.surfaceIndex.get(_)?.add(O)}}return this.surfaceIndex}getOperationsFor(D,O){let Y=this.get(D,O);if(!Y)return[];return Y.provides?.filter((_)=>_.surface==="operation").map((_)=>_.key)??[]}getEventsFor(D,O){let Y=this.get(D,O);if(!Y)return[];return Y.provides?.filter((_)=>_.surface==="event").map((_)=>_.key)??[]}getPresentationsFor(D,O){let Y=this.get(D,O);if(!Y)return[];return Y.provides?.filter((_)=>_.surface==="presentation").map((_)=>_.key)??[]}getWorkflowsFor(D,O){let Y=this.get(D,O);if(!Y)return[];return Y.provides?.filter((_)=>_.surface==="workflow").map((_)=>_.key)??[]}getResourcesFor(D,O){let Y=this.get(D,O);if(!Y)return[];return Y.provides?.filter((_)=>_.surface==="resource").map((_)=>_.key)??[]}getCapabilitiesForOperation(D){let Y=this.buildSurfaceIndex().get(`operation:${D}`);if(!Y)return[];return[...Y].map((_)=>{let B=this.items.get(_);return{key:B?.meta.key??"",version:B?.meta.version??""}})}getCapabilitiesForEvent(D){let Y=this.buildSurfaceIndex().get(`event:${D}`);if(!Y)return[];return[...Y].map((_)=>{let B=this.items.get(_);return{key:B?.meta.key??"",version:B?.meta.version??""}})}getCapabilitiesForPresentation(D){let Y=this.buildSurfaceIndex().get(`presentation:${D}`);if(!Y)return[];return[...Y].map((_)=>{let B=this.items.get(_);return{key:B?.meta.key??"",version:B?.meta.version??""}})}getAncestors(D,O){let Y=[],_=new Set,B=this.get(D,O);while(B?.extends){let I=A(B.extends.key,B.extends.version);if(_.has(I))break;_.add(I);let L=this.get(B.extends.key,B.extends.version);if(!L)break;Y.push(L),B=L}return Y}getEffectiveRequirements(D,O){let Y=this.get(D,O);if(!Y)return[];let _=this.getAncestors(D,O),B=new Map;for(let I of[..._].reverse())for(let L of I.requires??[])B.set(L.key,L);for(let I of Y.requires??[])B.set(I.key,I);return[...B.values()]}getEffectiveSurfaces(D,O){let Y=this.get(D,O);if(!Y)return[];let _=this.getAncestors(D,O),B=[];for(let I of[..._].reverse())B.push(...I.provides??[]);return B.push(...Y.provides??[]),B}}function q(D,O){if(D.key!==O.key)return!1;if(O.version!=null&&D.version!==O.version)return!1;return!0}function s(D){return A(D.meta.key,D.meta.version)}function T(D){return D}var r=[{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 z extends Error{capabilityKey;requiredVersion;constructor(D,O){let Y=O?`.v${O}`:"";super(`Missing required capability: ${D}${Y}`);this.name="CapabilityMissingError",this.capabilityKey=D,this.requiredVersion=O}}class G{capabilities;capabilityVersions;constructor(D){let O=new Set,Y=new Map;for(let _ of D)O.add(_.key),Y.set(_.key,_.version);this.capabilities=O,this.capabilityVersions=Y}hasCapability(D,O){if(!this.capabilities.has(D))return!1;if(O!=null)return this.capabilityVersions.get(D)===O;return!0}requireCapability(D,O){if(!this.hasCapability(D,O))throw new z(D,O)}hasAllCapabilities(D){return D.every((O)=>this.capabilities.has(O))}hasAnyCapability(D){return D.some((O)=>this.capabilities.has(O))}getMatchingCapabilities(D){if(!D.includes("*"))return this.capabilities.has(D)?[D]:[];let O=D.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),Y=new RegExp(`^${O}$`);return[...this.capabilities].filter((_)=>Y.test(_))}}function D0(D){return new G(D)}function _0(){return new G([])}function O0(D){return new G(D)}function U(D,O){if(!O.capability)return{allowed:!0};let{key:Y,version:_}=O.capability;if(D.hasCapability(Y,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:Y,version:_},reason:`Operation "${O.meta.key}" requires capability "${Y}.v${_}"`}}function I0(D,O){let Y=U(D,O);if(!Y.allowed&&Y.missingCapability)throw new z(Y.missingCapability.key,Y.missingCapability.version)}function N(D,O){if(!O.capability)return{allowed:!0};let{key:Y,version:_}=O.capability;if(D.hasCapability(Y,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:Y,version:_},reason:`Event "${O.meta.key}" requires capability "${Y}.v${_}"`}}function L0(D,O){let Y=N(D,O);if(!Y.allowed&&Y.missingCapability)throw new z(Y.missingCapability.key,Y.missingCapability.version)}function P(D,O){if(!O.capability)return{allowed:!0};let{key:Y,version:_}=O.capability;if(D.hasCapability(Y,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:Y,version:_},reason:`Presentation "${O.meta.key}" requires capability "${Y}.v${_}"`}}function j0(D,O){let Y=P(D,O);if(!Y.allowed&&Y.missingCapability)throw new z(Y.missingCapability.key,Y.missingCapability.version)}function z0(D,O){return O.filter((Y)=>U(D,Y).allowed)}function A0(D,O){return O.filter((Y)=>N(D,Y).allowed)}function G0(D,O){return O.filter((Y)=>P(D,Y).allowed)}var J=["platform.integrations"],Q=["meeting-recorder","transcripts","integrations"],d={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:[...J],tags:[...Q,"meetings"],stability:j.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."}]},K={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:[...J],tags:[...Q,"transcripts"],stability:j.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."}]},k={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:[...J],tags:[...Q,"webhooks"],stability:j.Experimental},provides:[{surface:"operation",key:"meeting-recorder.webhooks.ingest",version:"1.0.0",description:"Ingest and verify meeting recorder webhook payloads."}]};function Q0(D){return D.register(d).register(K).register(k)}var X=["platform.finance"],Z=["open-banking","finance"],b={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:[...X],tags:[...Z],stability:j.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."}]},u={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:[...X],tags:[...Z,"transactions"],stability:j.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."}]},v={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:[...X],tags:[...Z,"balances"],stability:j.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 $0(D){return D.register(b).register(u).register(v)}function U0(D){let O=[],Y=[];for(let _ of D.capabilities.list()){let B=`${_.meta.key}.v${_.meta.version}`;for(let I of _.provides??[])if(!o(D,I.surface,I.key))O.push({type:"missing_surface_spec",message:`Capability "${B}" provides ${I.surface} "${I.key}" but spec not found`,capabilityKey:B,surface:I.surface,specKey:I.key})}if(D.operations){for(let _ of D.operations.list())if(_.capability){let B=D.capabilities.get(_.capability.key,_.capability.version);if(!B)O.push({type:"capability_not_found",message:`Operation "${_.meta.key}" references capability "${_.capability.key}.v${_.capability.version}" but capability not found`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"operation"});else if(!B.provides?.some((L)=>L.surface==="operation"&&L.key===_.meta.key))O.push({type:"surface_not_in_provides",message:`Operation "${_.meta.key}" claims capability "${_.capability.key}.v${_.capability.version}" but not in capability's provides`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"operation"})}}if(D.events){for(let _ of D.events.list())if(_.capability){let B=D.capabilities.get(_.capability.key,_.capability.version);if(!B)O.push({type:"capability_not_found",message:`Event "${_.meta.key}" references capability "${_.capability.key}.v${_.capability.version}" but capability not found`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"event"});else if(!B.provides?.some((L)=>L.surface==="event"&&L.key===_.meta.key))O.push({type:"surface_not_in_provides",message:`Event "${_.meta.key}" claims capability "${_.capability.key}.v${_.capability.version}" but not in capability's provides`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"event"})}}if(D.presentations){for(let _ of D.presentations.list())if(_.capability){let B=D.capabilities.get(_.capability.key,_.capability.version);if(!B)O.push({type:"capability_not_found",message:`Presentation "${_.meta.key}" references capability "${_.capability.key}.v${_.capability.version}" but capability not found`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"presentation"});else if(!B.provides?.some((L)=>L.surface==="presentation"&&L.key===_.meta.key))O.push({type:"surface_not_in_provides",message:`Presentation "${_.meta.key}" claims capability "${_.capability.key}.v${_.capability.version}" but not in capability's provides`,specKey:_.meta.key,capabilityKey:`${_.capability.key}.v${_.capability.version}`,surface:"presentation"})}}return{valid:O.length===0,errors:O,warnings:Y}}function o(D,O,Y){switch(O){case"operation":return D.operations?.has(Y)??!0;case"event":return D.events?.has(Y)??!0;case"presentation":return D.presentations?.has(Y)??!0;case"workflow":case"resource":return!0;default:return!0}}function N0(D){let O={operations:[],events:[],presentations:[]};if(D.operations){for(let Y of D.operations.list())if(!Y.capability)O.operations.push(Y.meta.key)}if(D.events){for(let Y of D.events.list())if(!Y.capability)O.events.push(Y.meta.key)}if(D.presentations){for(let Y of D.presentations.list())if(!Y.capability)O.presentations.push(Y.meta.key)}return O}var W="docs",w=["docs-platform"],V=["docs","documentation"],F=j.Experimental;var x0=T({meta:{key:"docs.system",version:"1.0.0",kind:"ui",title:"Documentation System",description:"End-to-end docs generation, indexing, and presentation.",domain:W,owners:w,tags:[...V,"system"],stability:F},provides:[{surface:"operation",key:"docs.generate",version:"1.0.0",description:"Generate documentation artifacts."},{surface:"operation",key:"docs.publish",version:"1.0.0",description:"Publish documentation artifacts."},{surface:"operation",key:"docs_search",version:"1.0.0",description:"Index and search DocBlocks."},{surface:"operation",key:"docs.contract.reference",version:"1.0.0",description:"Resolve contract references for docs."},{surface:"event",key:"docs.generated",version:"1.0.0",description:"Docs generation completed."},{surface:"event",key:"docs.published",version:"1.0.0",description:"Docs publish completed."},{surface:"presentation",key:"docs.layout",version:"1.0.0",description:"Docs layout presentation."},{surface:"presentation",key:"docs.reference.page",version:"1.0.0",description:"Docs reference page presentation."}]});export{x0 as DocumentationSystemCapability};
