// @bun
var{defineProperty:J,getOwnPropertyNames:V,getOwnPropertyDescriptor:F}=Object,M=Object.prototype.hasOwnProperty;function h(A){return this[A]}var o=(A)=>{var _=($??=new WeakMap).get(A),N;if(_)return _;if(_=J({},"__esModule",{value:!0}),A&&typeof A==="object"||typeof A==="function"){for(var H of V(A))if(!M.call(_,H))J(_,H,{get:h.bind(A,H),enumerable:!(N=F(A,H))||N.enumerable})}return $.set(A,_),_},$;var g=(A)=>A;function f(A,_){this[A]=g.bind(null,_)}var y=(A,_)=>{for(var N in _)J(A,N,{get:_[N],enumerable:!0,configurable:!0,set:f.bind(_,N)})};var c=(A,_)=>()=>(A&&(_=A(A=0)),_);var D={Idea:"idea",InCreation:"in_creation",Experimental:"experimental",Beta:"beta",Stable:"stable",Deprecated:"deprecated"},x={PlatformCore:"platform.core",PlatformSigil:"platform.sigil",PlatformMarketplace:"platform.marketplace",PlatformMessaging:"platform.messaging",PlatformContent:"platform.content",PlatformFeatureFlags:"platform.featureflags",PlatformFinance:"platform.finance"},a=x,Q={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"},p=Q;import{compareVersions as C}from"compare-versions";var B=(A,_)=>`${A}.v${_}`;class q{items=new Map;surfaceIndex=null;register(A){let _=B(A.meta.key,A.meta.version);if(this.items.has(_))throw Error(`Duplicate capability ${_}`);return this.items.set(_,A),this.surfaceIndex=null,this}list(){return[...this.items.values()]}get(A,_){if(_!=null)return this.items.get(B(A,_));let N;for(let H of this.items.values()){if(H.meta.key!==A)continue;if(!N||C(H.meta.version,N.meta.version)>0)N=H}return N}satisfies(A,_){if(A.optional)return!0;if(_?.some((H)=>m(H,A)))return!0;let N=A.version?this.get(A.key,A.version):this.get(A.key);if(!N)return!1;if(A.kind&&N.meta.kind!==A.kind)return!1;if(A.version!=null&&N.meta.version!==A.version)return!1;return!0}buildSurfaceIndex(){if(this.surfaceIndex)return this.surfaceIndex;this.surfaceIndex=new Map;for(let A of this.items.values()){let _=B(A.meta.key,A.meta.version);for(let N of A.provides??[]){let H=`${N.surface}:${N.key}`;if(!this.surfaceIndex.has(H))this.surfaceIndex.set(H,new Set);this.surfaceIndex.get(H)?.add(_)}}return this.surfaceIndex}getOperationsFor(A,_){let N=this.get(A,_);if(!N)return[];return N.provides?.filter((H)=>H.surface==="operation").map((H)=>H.key)??[]}getEventsFor(A,_){let N=this.get(A,_);if(!N)return[];return N.provides?.filter((H)=>H.surface==="event").map((H)=>H.key)??[]}getPresentationsFor(A,_){let N=this.get(A,_);if(!N)return[];return N.provides?.filter((H)=>H.surface==="presentation").map((H)=>H.key)??[]}getWorkflowsFor(A,_){let N=this.get(A,_);if(!N)return[];return N.provides?.filter((H)=>H.surface==="workflow").map((H)=>H.key)??[]}getResourcesFor(A,_){let N=this.get(A,_);if(!N)return[];return N.provides?.filter((H)=>H.surface==="resource").map((H)=>H.key)??[]}getCapabilitiesForOperation(A){let N=this.buildSurfaceIndex().get(`operation:${A}`);if(!N)return[];return[...N].map((H)=>{let L=this.items.get(H);return{key:L?.meta.key??"",version:L?.meta.version??""}})}getCapabilitiesForEvent(A){let N=this.buildSurfaceIndex().get(`event:${A}`);if(!N)return[];return[...N].map((H)=>{let L=this.items.get(H);return{key:L?.meta.key??"",version:L?.meta.version??""}})}getCapabilitiesForPresentation(A){let N=this.buildSurfaceIndex().get(`presentation:${A}`);if(!N)return[];return[...N].map((H)=>{let L=this.items.get(H);return{key:L?.meta.key??"",version:L?.meta.version??""}})}getAncestors(A,_){let N=[],H=new Set,L=this.get(A,_);while(L?.extends){let Y=B(L.extends.key,L.extends.version);if(H.has(Y))break;H.add(Y);let z=this.get(L.extends.key,L.extends.version);if(!z)break;N.push(z),L=z}return N}getEffectiveRequirements(A,_){let N=this.get(A,_);if(!N)return[];let H=this.getAncestors(A,_),L=new Map;for(let Y of[...H].reverse())for(let z of Y.requires??[])L.set(z.key,z);for(let Y of N.requires??[])L.set(Y.key,Y);return[...L.values()]}getEffectiveSurfaces(A,_){let N=this.get(A,_);if(!N)return[];let H=this.getAncestors(A,_),L=[];for(let Y of[...H].reverse())L.push(...Y.provides??[]);return L.push(...N.provides??[]),L}}function m(A,_){if(A.key!==_.key)return!1;if(_.version!=null&&A.version!==_.version)return!1;return!0}function r(A){return B(A.meta.key,A.meta.version)}function G(A){return A}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 j extends Error{capabilityKey;requiredVersion;constructor(A,_){let N=_?`.v${_}`:"";super(`Missing required capability: ${A}${N}`);this.name="CapabilityMissingError",this.capabilityKey=A,this.requiredVersion=_}}class I{capabilities;capabilityVersions;constructor(A){let _=new Set,N=new Map;for(let H of A)_.add(H.key),N.set(H.key,H.version);this.capabilities=_,this.capabilityVersions=N}hasCapability(A,_){if(!this.capabilities.has(A))return!1;if(_!=null)return this.capabilityVersions.get(A)===_;return!0}requireCapability(A,_){if(!this.hasCapability(A,_))throw new j(A,_)}hasAllCapabilities(A){return A.every((_)=>this.capabilities.has(_))}hasAnyCapability(A){return A.some((_)=>this.capabilities.has(_))}getMatchingCapabilities(A){if(!A.includes("*"))return this.capabilities.has(A)?[A]:[];let _=A.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*"),N=new RegExp(`^${_}$`);return[...this.capabilities].filter((H)=>N.test(H))}}function AA(A){return new I(A)}function HA(){return new I([])}function _A(A){return new I(A)}function U(A,_){if(!_.capability)return{allowed:!0};let{key:N,version:H}=_.capability;if(A.hasCapability(N,H))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:H},reason:`Operation "${_.meta.key}" requires capability "${N}.v${H}"`}}function YA(A,_){let N=U(A,_);if(!N.allowed&&N.missingCapability)throw new j(N.missingCapability.key,N.missingCapability.version)}function S(A,_){if(!_.capability)return{allowed:!0};let{key:N,version:H}=_.capability;if(A.hasCapability(N,H))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:H},reason:`Event "${_.meta.key}" requires capability "${N}.v${H}"`}}function zA(A,_){let N=S(A,_);if(!N.allowed&&N.missingCapability)throw new j(N.missingCapability.key,N.missingCapability.version)}function W(A,_){if(!_.capability)return{allowed:!0};let{key:N,version:H}=_.capability;if(A.hasCapability(N,H))return{allowed:!0};return{allowed:!1,missingCapability:{key:N,version:H},reason:`Presentation "${_.meta.key}" requires capability "${N}.v${H}"`}}function DA(A,_){let N=W(A,_);if(!N.allowed&&N.missingCapability)throw new j(N.missingCapability.key,N.missingCapability.version)}function jA(A,_){return _.filter((N)=>U(A,N).allowed)}function BA(A,_){return _.filter((N)=>S(A,N).allowed)}function IA(A,_){return _.filter((N)=>W(A,N).allowed)}var R=["platform.integrations"],T=["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:[...R],tags:[...T,"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."}]},d={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:[...R],tags:[...T,"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."}]},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:[...R],tags:[...T,"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 RA(A){return A.register(K).register(d).register(k)}var X=["platform.finance"],Z=["open-banking","finance"],v={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: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."}]},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: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:[...X],tags:[...Z,"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 ZA(A){return A.register(v).register(u).register(b)}function GA(A){let _=[],N=[];for(let H of A.capabilities.list()){let L=`${H.meta.key}.v${H.meta.version}`;for(let Y of H.provides??[])if(!l(A,Y.surface,Y.key))_.push({type:"missing_surface_spec",message:`Capability "${L}" provides ${Y.surface} "${Y.key}" but spec not found`,capabilityKey:L,surface:Y.surface,specKey:Y.key})}if(A.operations){for(let H of A.operations.list())if(H.capability){let L=A.capabilities.get(H.capability.key,H.capability.version);if(!L)_.push({type:"capability_not_found",message:`Operation "${H.meta.key}" references capability "${H.capability.key}.v${H.capability.version}" but capability not found`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"operation"});else if(!L.provides?.some((z)=>z.surface==="operation"&&z.key===H.meta.key))_.push({type:"surface_not_in_provides",message:`Operation "${H.meta.key}" claims capability "${H.capability.key}.v${H.capability.version}" but not in capability's provides`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"operation"})}}if(A.events){for(let H of A.events.list())if(H.capability){let L=A.capabilities.get(H.capability.key,H.capability.version);if(!L)_.push({type:"capability_not_found",message:`Event "${H.meta.key}" references capability "${H.capability.key}.v${H.capability.version}" but capability not found`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"event"});else if(!L.provides?.some((z)=>z.surface==="event"&&z.key===H.meta.key))_.push({type:"surface_not_in_provides",message:`Event "${H.meta.key}" claims capability "${H.capability.key}.v${H.capability.version}" but not in capability's provides`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"event"})}}if(A.presentations){for(let H of A.presentations.list())if(H.capability){let L=A.capabilities.get(H.capability.key,H.capability.version);if(!L)_.push({type:"capability_not_found",message:`Presentation "${H.meta.key}" references capability "${H.capability.key}.v${H.capability.version}" but capability not found`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"presentation"});else if(!L.provides?.some((z)=>z.surface==="presentation"&&z.key===H.meta.key))_.push({type:"surface_not_in_provides",message:`Presentation "${H.meta.key}" claims capability "${H.capability.key}.v${H.capability.version}" but not in capability's provides`,specKey:H.meta.key,capabilityKey:`${H.capability.key}.v${H.capability.version}`,surface:"presentation"})}}return{valid:_.length===0,errors:_,warnings:N}}function l(A,_,N){switch(_){case"operation":return A.operations?.has(N)??!0;case"event":return A.events?.has(N)??!0;case"presentation":return A.presentations?.has(N)??!0;case"workflow":case"resource":return!0;default:return!0}}function UA(A){let _={operations:[],events:[],presentations:[]};if(A.operations){for(let N of A.operations.list())if(!N.capability)_.operations.push(N.meta.key)}if(A.events){for(let N of A.events.list())if(!N.capability)_.events.push(N.meta.key)}if(A.presentations){for(let N of A.presentations.list())if(!N.capability)_.presentations.push(N.meta.key)}return _}var O="harness",P=["platform.harness"],w=[Q.Automation,"harness","evidence","evaluation"],E=D.Experimental;var xA=G({meta:{key:"harness.evidence",version:"1.0.0",kind:"data",title:"Harness Evidence",description:"Capture and retrieve normalized evidence artifacts.",domain:O,owners:P,tags:[...w,"evidence"],stability:E},provides:[{surface:"operation",key:"harness.evidence.list",version:"1.0.0",description:"List evidence for a run."},{surface:"operation",key:"harness.evidence.get",version:"1.0.0",description:"Read one evidence artifact."},{surface:"event",key:"harness.evidence.captured",version:"1.0.0",description:"Evidence captured during execution."},{surface:"presentation",key:"harness.run.audit",version:"1.0.0",description:"Audit presentation for harness runs and evidence."}]});export{xA as HarnessEvidenceCapability};
