// @bun
var{defineProperty:z,getOwnPropertyNames:M,getOwnPropertyDescriptor:x}=Object,g=Object.prototype.hasOwnProperty;function f(L){return this[L]}var o=(L)=>{var P=(X??=new WeakMap).get(L),N;if(P)return P;if(P=z({},"__esModule",{value:!0}),L&&typeof L==="object"||typeof L==="function"){for(var _ of M(L))if(!g.call(P,_))z(P,_,{get:f.bind(L,_),enumerable:!(N=x(L,_))||N.enumerable})}return X.set(L,P),P},X;var S=(L)=>L;function C(L,P){this[L]=S.bind(null,P)}var c=(L,P)=>{for(var N in P)z(L,N,{get:P[N],enumerable:!0,configurable:!0,set:C.bind(P,N)})};var y=(L,P)=>()=>(L&&(P=L(L=0)),P);var D={Idea:"idea",InCreation:"in_creation",Experimental:"experimental",Beta:"beta",Stable:"stable",Deprecated:"deprecated"},B={PlatformCore:"platform.core",PlatformSigil:"platform.sigil",PlatformMarketplace:"platform.marketplace",PlatformMessaging:"platform.messaging",PlatformContent:"platform.content",PlatformFeatureFlags:"platform.featureflags",PlatformFinance:"platform.finance"},t=B,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"},a=G;import{compareVersions as h}from"compare-versions";var I=(L,P)=>`${L}.v${P}`;class m{items=new Map;surfaceIndex=null;register(L){let P=I(L.meta.key,L.meta.version);if(this.items.has(P))throw Error(`Duplicate capability ${P}`);return this.items.set(P,L),this.surfaceIndex=null,this}list(){return[...this.items.values()]}get(L,P){if(P!=null)return this.items.get(I(L,P));let N;for(let _ of this.items.values()){if(_.meta.key!==L)continue;if(!N||h(_.meta.version,N.meta.version)>0)N=_}return N}satisfies(L,P){if(L.optional)return!0;if(P?.some((_)=>q(_,L)))return!0;let N=L.version?this.get(L.key,L.version):this.get(L.key);if(!N)return!1;if(L.kind&&N.meta.kind!==L.kind)return!1;if(L.version!=null&&N.meta.version!==L.version)return!1;return!0}buildSurfaceIndex(){if(this.surfaceIndex)return this.surfaceIndex;this.surfaceIndex=new Map;for(let L of this.items.values()){let P=I(L.meta.key,L.meta.version);for(let N of L.provides??[]){let _=`${N.surface}:${N.key}`;if(!this.surfaceIndex.has(_))this.surfaceIndex.set(_,new Set);this.surfaceIndex.get(_)?.add(P)}}return this.surfaceIndex}getOperationsFor(L,P){let N=this.get(L,P);if(!N)return[];return N.provides?.filter((_)=>_.surface==="operation").map((_)=>_.key)??[]}getEventsFor(L,P){let N=this.get(L,P);if(!N)return[];return N.provides?.filter((_)=>_.surface==="event").map((_)=>_.key)??[]}getPresentationsFor(L,P){let N=this.get(L,P);if(!N)return[];return N.provides?.filter((_)=>_.surface==="presentation").map((_)=>_.key)??[]}getWorkflowsFor(L,P){let N=this.get(L,P);if(!N)return[];return N.provides?.filter((_)=>_.surface==="workflow").map((_)=>_.key)??[]}getResourcesFor(L,P){let N=this.get(L,P);if(!N)return[];return N.provides?.filter((_)=>_.surface==="resource").map((_)=>_.key)??[]}getCapabilitiesForOperation(L){let N=this.buildSurfaceIndex().get(`operation:${L}`);if(!N)return[];return[...N].map((_)=>{let O=this.items.get(_);return{key:O?.meta.key??"",version:O?.meta.version??""}})}getCapabilitiesForEvent(L){let N=this.buildSurfaceIndex().get(`event:${L}`);if(!N)return[];return[...N].map((_)=>{let O=this.items.get(_);return{key:O?.meta.key??"",version:O?.meta.version??""}})}getCapabilitiesForPresentation(L){let N=this.buildSurfaceIndex().get(`presentation:${L}`);if(!N)return[];return[...N].map((_)=>{let O=this.items.get(_);return{key:O?.meta.key??"",version:O?.meta.version??""}})}getAncestors(L,P){let N=[],_=new Set,O=this.get(L,P);while(O?.extends){let A=I(O.extends.key,O.extends.version);if(_.has(A))break;_.add(A);let T=this.get(O.extends.key,O.extends.version);if(!T)break;N.push(T),O=T}return N}getEffectiveRequirements(L,P){let N=this.get(L,P);if(!N)return[];let _=this.getAncestors(L,P),O=new Map;for(let A of[..._].reverse())for(let T of A.requires??[])O.set(T.key,T);for(let A of N.requires??[])O.set(A.key,A);return[...O.values()]}getEffectiveSurfaces(L,P){let N=this.get(L,P);if(!N)return[];let _=this.getAncestors(L,P),O=[];for(let A of[..._].reverse())O.push(...A.provides??[]);return O.push(...N.provides??[]),O}}function q(L,P){if(L.key!==P.key)return!1;if(P.version!=null&&L.version!==P.version)return!1;return!0}function r(L){return I(L.meta.key,L.meta.version)}function Z(L){return L}var s=[{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 Y extends Error{capabilityKey;requiredVersion;constructor(L,P){let N=P?`.v${P}`:"";super(`Missing required capability: ${L}${N}`);this.name="CapabilityMissingError",this.capabilityKey=L,this.requiredVersion=P}}class j{capabilities;capabilityVersions;constructor(L){let P=new Set,N=new Map;for(let _ of L)P.add(_.key),N.set(_.key,_.version);this.capabilities=P,this.capabilityVersions=N}hasCapability(L,P){if(!this.capabilities.has(L))return!1;if(P!=null)return this.capabilityVersions.get(L)===P;return!0}requireCapability(L,P){if(!this.hasCapability(L,P))throw new Y(L,P)}hasAllCapabilities(L){return L.every((P)=>this.capabilities.has(P))}hasAnyCapability(L){return L.some((P)=>this.capabilities.has(P))}getMatchingCapabilities(L){if(!L.includes("*"))return this.capabilities.has(L)?[L]:[];let P=L.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),N=new RegExp(`^${P}$`);return[...this.capabilities].filter((_)=>N.test(_))}}function LL(L){return new j(L)}function _L(){return new j([])}function PL(L){return new j(L)}function $(L,P){if(!P.capability)return{allowed:!0};let{key:N,version:_}=P.capability;if(L.hasCapability(N,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:_},reason:`Operation "${P.meta.key}" requires capability "${N}.v${_}"`}}function AL(L,P){let N=$(L,P);if(!N.allowed&&N.missingCapability)throw new Y(N.missingCapability.key,N.missingCapability.version)}function U(L,P){if(!P.capability)return{allowed:!0};let{key:N,version:_}=P.capability;if(L.hasCapability(N,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:_},reason:`Event "${P.meta.key}" requires capability "${N}.v${_}"`}}function TL(L,P){let N=U(L,P);if(!N.allowed&&N.missingCapability)throw new Y(N.missingCapability.key,N.missingCapability.version)}function W(L,P){if(!P.capability)return{allowed:!0};let{key:N,version:_}=P.capability;if(L.hasCapability(N,_))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:_},reason:`Presentation "${P.meta.key}" requires capability "${N}.v${_}"`}}function DL(L,P){let N=W(L,P);if(!N.allowed&&N.missingCapability)throw new Y(N.missingCapability.key,N.missingCapability.version)}function YL(L,P){return P.filter((N)=>$(L,N).allowed)}function IL(L,P){return P.filter((N)=>U(L,N).allowed)}function jL(L,P){return P.filter((N)=>W(L,N).allowed)}var H=["platform.integrations"],J=["meeting-recorder","transcripts","integrations"],K={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:[...H],tags:[...J,"meetings"],stability:D.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:[...H],tags:[...J,"transcripts"],stability:D.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."}]},d={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:[...H],tags:[...J,"webhooks"],stability:D.Experimental},provides:[{surface:"operation",key:"meeting-recorder.webhooks.ingest",version:"1.0.0",description:"Ingest and verify meeting recorder webhook payloads."}]};function GL(L){return L.register(K).register(k).register(d)}var Q=["platform.finance"],R=["open-banking","finance"],u={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:[...Q],tags:[...R],stability:D.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."}]},v={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:[...Q],tags:[...R,"transactions"],stability:D.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."}]},b={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:[...Q],tags:[...R,"balances"],stability:D.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 QL(L){return L.register(u).register(v).register(b)}function XL(L){let P=[],N=[];for(let _ of L.capabilities.list()){let O=`${_.meta.key}.v${_.meta.version}`;for(let A of _.provides??[])if(!l(L,A.surface,A.key))P.push({type:"missing_surface_spec",message:`Capability "${O}" provides ${A.surface} "${A.key}" but spec not found`,capabilityKey:O,surface:A.surface,specKey:A.key})}if(L.operations){for(let _ of L.operations.list())if(_.capability){let O=L.capabilities.get(_.capability.key,_.capability.version);if(!O)P.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(!O.provides?.some((T)=>T.surface==="operation"&&T.key===_.meta.key))P.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(L.events){for(let _ of L.events.list())if(_.capability){let O=L.capabilities.get(_.capability.key,_.capability.version);if(!O)P.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(!O.provides?.some((T)=>T.surface==="event"&&T.key===_.meta.key))P.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(L.presentations){for(let _ of L.presentations.list())if(_.capability){let O=L.capabilities.get(_.capability.key,_.capability.version);if(!O)P.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(!O.provides?.some((T)=>T.surface==="presentation"&&T.key===_.meta.key))P.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:P.length===0,errors:P,warnings:N}}function l(L,P,N){switch(P){case"operation":return L.operations?.has(N)??!0;case"event":return L.events?.has(N)??!0;case"presentation":return L.presentations?.has(N)??!0;case"workflow":case"resource":return!0;default:return!0}}function ZL(L){let P={operations:[],events:[],presentations:[]};if(L.operations){for(let N of L.operations.list())if(!N.capability)P.operations.push(N.meta.key)}if(L.events){for(let N of L.events.list())if(!N.capability)P.events.push(N.meta.key)}if(L.presentations){for(let N of L.presentations.list())if(!N.capability)P.presentations.push(N.meta.key)}return P}var w="control-plane",V=[B.PlatformCore],E=[G.Automation,"control-plane","agent-runtime"],F=D.Experimental;var CL=Z({meta:{key:"control-plane.core",version:"1.0.0",kind:"integration",title:"Control Plane Core",description:"Core intent, planning, and execution surfaces.",domain:w,owners:V,tags:[...E,"core"],stability:F},provides:[{surface:"operation",key:"controlPlane.intent.submit",version:"1.0.0",description:"Submit intent for controlled execution."},{surface:"operation",key:"controlPlane.plan.compile",version:"1.0.0",description:"Compile deterministic plan DAG."},{surface:"operation",key:"controlPlane.execution.start",version:"1.0.0",description:"Start approved plan execution."},{surface:"operation",key:"controlPlane.execution.cancel",version:"1.0.0",description:"Cancel in-flight execution."},{surface:"operation",key:"controlPlane.execution.get",version:"1.0.0",description:"Read one execution state."},{surface:"operation",key:"controlPlane.execution.list",version:"1.0.0",description:"List execution states."},{surface:"event",key:"controlPlane.intent.received",version:"1.0.0",description:"Intent accepted into runtime pipeline."},{surface:"event",key:"controlPlane.plan.compiled",version:"1.0.0",description:"Plan compilation completed."}]});export{CL as ControlPlaneCoreCapability};
