@capabilityhostprotocol/types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,542 @@
1
+ /**
2
+ * Risk Classification Types
3
+ *
4
+ * Risk classes determine the level of governance scrutiny applied to a capability.
5
+ * Higher risk classes require stronger assurance and more evidence.
6
+ *
7
+ * @module risk
8
+ */
9
+ /**
10
+ * Risk classification for capabilities.
11
+ *
12
+ * Ordered from lowest to highest risk:
13
+ * - INFORMATIONAL: Read-only, no side effects
14
+ * - LOW: Minor side effects, easily reversible
15
+ * - MEDIUM: Moderate side effects, may require coordination
16
+ * - HIGH: Significant side effects, requires authorization
17
+ * - CRITICAL: System-wide impact, requires multi-party approval
18
+ */
19
+ type RiskClass = "informational" | "low" | "medium" | "high" | "critical";
20
+ /**
21
+ * Risk class values as a const array for iteration.
22
+ */
23
+ declare const RISK_CLASSES: readonly ["informational", "low", "medium", "high", "critical"];
24
+ /**
25
+ * Risk class numeric order for comparison.
26
+ */
27
+ declare const RISK_CLASS_ORDER: Record<RiskClass, number>;
28
+ /**
29
+ * Compare two risk classes.
30
+ * @returns negative if a < b, 0 if equal, positive if a > b
31
+ */
32
+ declare function compareRiskClass(a: RiskClass, b: RiskClass): number;
33
+ /**
34
+ * Check if a risk class is at least as high as another.
35
+ */
36
+ declare function isRiskAtLeast(actual: RiskClass, required: RiskClass): boolean;
37
+
38
+ /**
39
+ * Assurance Tier Types
40
+ *
41
+ * Three-tier assurance model for execution trust.
42
+ * Each tier provides increasing levels of confidence in execution evidence.
43
+ *
44
+ * @module assurance
45
+ */
46
+ /**
47
+ * Assurance tiers for execution trust.
48
+ *
49
+ * - S1: Observational - Execution was observed by the host
50
+ * - S2: Structural - Deterministic replay is possible
51
+ * - S3: Attested - Cryptographic proof with verified environment
52
+ */
53
+ type AssuranceTier = "S1" | "S2" | "S3";
54
+ /**
55
+ * Assurance tier values as a const array.
56
+ */
57
+ declare const ASSURANCE_TIERS: readonly ["S1", "S2", "S3"];
58
+ /**
59
+ * Human-readable names for assurance tiers.
60
+ */
61
+ declare const ASSURANCE_TIER_DISPLAY_NAMES: Record<AssuranceTier, string>;
62
+ /**
63
+ * Assurance tier numeric order for comparison.
64
+ */
65
+ declare const ASSURANCE_TIER_ORDER: Record<AssuranceTier, number>;
66
+ /**
67
+ * Compare two assurance tiers.
68
+ * @returns negative if a < b, 0 if equal, positive if a > b
69
+ */
70
+ declare function compareAssuranceTier(a: AssuranceTier, b: AssuranceTier): number;
71
+ /**
72
+ * Check if an assurance tier meets a minimum requirement.
73
+ */
74
+ declare function meetsAssuranceTier(actual: AssuranceTier, required: AssuranceTier): boolean;
75
+ /**
76
+ * Get the display name for an assurance tier.
77
+ */
78
+ declare function getAssuranceTierDisplayName(tier: AssuranceTier): string;
79
+
80
+ /**
81
+ * Evidence Types
82
+ *
83
+ * Evidence is the immutable record of capability execution.
84
+ * Every capability execution produces one or more Evidence records.
85
+ * These form the basis of the capability graph and audit trail.
86
+ *
87
+ * @module evidence
88
+ */
89
+
90
+ /**
91
+ * Evidence types for capability execution tracking.
92
+ *
93
+ * Every capability execution produces evidence. The type indicates
94
+ * what kind of execution event occurred.
95
+ */
96
+ type EvidenceType = "execution_started" | "execution_completed" | "execution_failed" | "execution_denied" | "execution_aborted" | "invocation_received" | "invocation_validated" | "invocation_rejected" | "entitlement_checked" | "entitlement_granted" | "entitlement_denied" | "invariant_checked" | "invariant_passed" | "invariant_failed" | "retry_attempted" | "retry_exhausted" | "timeout_exceeded" | "circuit_opened" | "circuit_closed" | "rate_limited" | "assurance_derived" | "assurance_degraded" | "lineage_traced" | "causal_link_created";
97
+ /**
98
+ * All evidence types as a const array for iteration.
99
+ */
100
+ declare const EVIDENCE_TYPES: readonly ["execution_started", "execution_completed", "execution_failed", "execution_denied", "execution_aborted", "invocation_received", "invocation_validated", "invocation_rejected", "entitlement_checked", "entitlement_granted", "entitlement_denied", "invariant_checked", "invariant_passed", "invariant_failed", "retry_attempted", "retry_exhausted", "timeout_exceeded", "circuit_opened", "circuit_closed", "rate_limited", "assurance_derived", "assurance_degraded", "lineage_traced", "causal_link_created"];
101
+ /**
102
+ * Immutable evidence record for capability execution.
103
+ *
104
+ * This is the canonical CHP evidence structure that must be
105
+ * faithfully serialized/deserialized across language boundaries.
106
+ */
107
+ interface Evidence {
108
+ /** Unique identifier for this evidence */
109
+ evidence_id: string;
110
+ /** Type of evidence (from EvidenceType) */
111
+ evidence_type: EvidenceType;
112
+ /** The capability that produced this evidence */
113
+ capability_id: string;
114
+ /** ISO-8601 timestamp when the evidence was created */
115
+ timestamp: string;
116
+ /** The subject (user/agent) that triggered execution */
117
+ subject_id?: string | null;
118
+ /** Links related evidence across executions */
119
+ correlation_id?: string | null;
120
+ /** Trust level of this evidence */
121
+ assurance_tier: AssuranceTier;
122
+ /** Additional context-specific data */
123
+ payload: Record<string, unknown>;
124
+ /** W3C Trace Context trace ID for distributed tracing */
125
+ trace_id?: string | null;
126
+ }
127
+ /**
128
+ * Create a new evidence record.
129
+ *
130
+ * @param params - Evidence creation parameters
131
+ * @returns A new Evidence object
132
+ */
133
+ declare function createEvidence(params: {
134
+ evidence_type: EvidenceType;
135
+ capability_id: string;
136
+ subject_id?: string | null;
137
+ correlation_id?: string | null;
138
+ assurance_tier?: AssuranceTier;
139
+ payload?: Record<string, unknown>;
140
+ trace_id?: string | null;
141
+ }): Evidence;
142
+ /**
143
+ * Validate that an object conforms to the Evidence interface.
144
+ */
145
+ declare function isEvidence(obj: unknown): obj is Evidence;
146
+
147
+ /**
148
+ * Invariant Types
149
+ *
150
+ * Invariants are constraints that must hold for a capability to execute.
151
+ * They are checked at the invocation boundary or during execution.
152
+ *
153
+ * @module invariants
154
+ */
155
+ /**
156
+ * Classification of invariant constraints.
157
+ *
158
+ * Determines when and how invariants are checked and enforced.
159
+ *
160
+ * - STRUCTURAL: Code/schema correctness (compile-time checkable)
161
+ * - ENVIRONMENTAL: Runtime environment constraints
162
+ * - DATA: Input/output data validation
163
+ * - TEMPORAL: Time-based constraints (deadlines, ordering)
164
+ * - CAUSAL: Dependency and causality constraints
165
+ */
166
+ type InvariantClass = "structural" | "environmental" | "data" | "temporal" | "causal";
167
+ /**
168
+ * Invariant classes as a const array.
169
+ */
170
+ declare const INVARIANT_CLASSES: readonly ["structural", "environmental", "data", "temporal", "causal"];
171
+ /**
172
+ * Who is responsible for enforcing an invariant.
173
+ *
174
+ * - HOST: The capability host enforces at invocation boundary
175
+ * - RUNTIME: Enforced during capability execution
176
+ * - SUBSTRATE: Enforced by underlying infrastructure (e.g., Zenoh)
177
+ * - DECLARATIVE: Declared but not actively enforced
178
+ */
179
+ type EnforcementResponsibility = "host" | "runtime" | "substrate" | "declarative";
180
+ /**
181
+ * What happens when an invariant fails.
182
+ *
183
+ * - DENY: Prevent execution entirely
184
+ * - ABORT: Stop execution and rollback if possible
185
+ * - WARN: Log warning but allow execution
186
+ * - DEGRADE: Continue with reduced assurance
187
+ */
188
+ type FailureBehavior = "deny" | "abort" | "warn" | "degrade";
189
+ /**
190
+ * A declared invariant constraint for a capability.
191
+ *
192
+ * This is the canonical CHP invariant structure that must be
193
+ * faithfully serialized/deserialized across language boundaries.
194
+ */
195
+ interface DeclaredInvariant {
196
+ /** Unique identifier for this invariant */
197
+ invariant_id: string;
198
+ /** Type of invariant (structural, temporal, etc.) */
199
+ invariant_class: InvariantClass;
200
+ /** Who enforces this invariant */
201
+ enforcement: EnforcementResponsibility;
202
+ /** What happens on failure */
203
+ failure_behavior: FailureBehavior;
204
+ /** Human-readable description */
205
+ description: string;
206
+ /** Invariant-specific configuration */
207
+ parameters: Record<string, unknown>;
208
+ }
209
+ /**
210
+ * Create a new declared invariant.
211
+ */
212
+ declare function createDeclaredInvariant(params: {
213
+ invariant_id: string;
214
+ invariant_class: InvariantClass;
215
+ enforcement?: EnforcementResponsibility;
216
+ failure_behavior?: FailureBehavior;
217
+ description?: string;
218
+ parameters?: Record<string, unknown>;
219
+ }): DeclaredInvariant;
220
+ /**
221
+ * Validate that an object conforms to the DeclaredInvariant interface.
222
+ */
223
+ declare function isDeclaredInvariant(obj: unknown): obj is DeclaredInvariant;
224
+
225
+ /**
226
+ * Context Types
227
+ *
228
+ * Context types for subject (user/agent) and invocation tracking.
229
+ * These provide the "who" and "what" for capability execution.
230
+ *
231
+ * @module context
232
+ */
233
+ /**
234
+ * Context about the subject (user/agent) invoking a capability.
235
+ *
236
+ * Subjects are the actors in the system - they invoke capabilities
237
+ * and are tracked for authorization and audit purposes.
238
+ */
239
+ interface SubjectContext {
240
+ /** Unique identifier for the subject */
241
+ subject_id: string;
242
+ /** Type of subject (user, agent, service) */
243
+ subject_type: string;
244
+ /** List of entitlements the subject holds */
245
+ entitlements: string[];
246
+ /** Additional subject-specific data */
247
+ metadata: Record<string, unknown>;
248
+ }
249
+ /**
250
+ * Create a new subject context.
251
+ */
252
+ declare function createSubjectContext(params: {
253
+ subject_id: string;
254
+ subject_type?: string;
255
+ entitlements?: string[];
256
+ metadata?: Record<string, unknown>;
257
+ }): SubjectContext;
258
+ /**
259
+ * Check if a subject has a specific entitlement.
260
+ */
261
+ declare function hasEntitlement(subject: SubjectContext, entitlement: string): boolean;
262
+ /**
263
+ * Context for a capability invocation.
264
+ *
265
+ * Provides access to subject information, correlation tracking,
266
+ * and execution metadata during capability execution.
267
+ */
268
+ interface InvocationContext {
269
+ /** Unique ID for this invocation */
270
+ invocation_id: string;
271
+ /** The capability being invoked */
272
+ capability_id: string;
273
+ /** The subject invoking the capability */
274
+ subject: SubjectContext;
275
+ /** For linking related invocations */
276
+ correlation_id: string | null;
277
+ /** W3C Trace Context trace ID */
278
+ trace_id: string | null;
279
+ /** If this is a child invocation */
280
+ parent_invocation_id: string | null;
281
+ /** ISO-8601 timestamp when the invocation started */
282
+ timestamp: string;
283
+ /** Additional context data */
284
+ metadata: Record<string, unknown>;
285
+ }
286
+ /**
287
+ * Create a new invocation context.
288
+ */
289
+ declare function createInvocationContext(params: {
290
+ capability_id: string;
291
+ subject: SubjectContext;
292
+ correlation_id?: string | null;
293
+ trace_id?: string | null;
294
+ parent_invocation_id?: string | null;
295
+ metadata?: Record<string, unknown>;
296
+ }): InvocationContext;
297
+ /**
298
+ * Outcome of a capability execution.
299
+ *
300
+ * - SUCCESS: Execution completed successfully
301
+ * - FAILURE: Execution failed with an error
302
+ * - DENIED: Execution was denied (entitlement/invariant)
303
+ * - TIMEOUT: Execution exceeded time limit
304
+ * - ABORTED: Execution was aborted (e.g., circuit breaker)
305
+ */
306
+ type ExecutionOutcome = "success" | "failure" | "denied" | "timeout" | "aborted";
307
+ /**
308
+ * Execution outcomes as a const array.
309
+ */
310
+ declare const EXECUTION_OUTCOMES: readonly ["success", "failure", "denied", "timeout", "aborted"];
311
+
312
+ /**
313
+ * Governance Types
314
+ *
315
+ * Governance layer types for capability execution control.
316
+ * These determine how governance violations are handled.
317
+ *
318
+ * @module governance
319
+ */
320
+
321
+ /**
322
+ * Mode of governance enforcement.
323
+ *
324
+ * Determines how governance violations are handled.
325
+ *
326
+ * - ENFORCE: Violations block execution (production)
327
+ * - AUDIT: Violations are logged but allowed (testing)
328
+ * - DISABLED: No governance checks (development only)
329
+ * - SHADOW: Parallel check without blocking (migration)
330
+ */
331
+ type GovernanceMode = "enforce" | "audit" | "disabled" | "shadow";
332
+ /**
333
+ * Governance modes as a const array.
334
+ */
335
+ declare const GOVERNANCE_MODES: readonly ["enforce", "audit", "disabled", "shadow"];
336
+ /**
337
+ * Check if a governance mode blocks execution on violations.
338
+ */
339
+ declare function blocksExecution(mode: GovernanceMode): boolean;
340
+ /**
341
+ * Check if a governance mode emits evidence.
342
+ */
343
+ declare function emitsEvidence(mode: GovernanceMode): boolean;
344
+ /**
345
+ * Execution context for governed capabilities.
346
+ *
347
+ * Provides access to subject information, governance state, evidence emission,
348
+ * and execution metadata during capability execution.
349
+ */
350
+ interface GovernedContext {
351
+ /** Unique ID for this invocation */
352
+ invocation_id: string;
353
+ /** The capability being invoked */
354
+ capability_id: string;
355
+ /** The subject (user/agent) invoking */
356
+ subject: SubjectContext;
357
+ /** For linking related invocations */
358
+ correlation_id: string;
359
+ /** W3C Trace Context trace ID */
360
+ trace_id: string | null;
361
+ /** Active enforcement mode */
362
+ governance_mode: GovernanceMode;
363
+ /** Risk classification of the capability */
364
+ risk_class: RiskClass;
365
+ /** Required assurance tier */
366
+ minimum_tier: AssuranceTier;
367
+ /** Active invariants */
368
+ invariants: DeclaredInvariant[];
369
+ /** Evidence emitted during execution */
370
+ evidence: Evidence[];
371
+ /** Additional context data */
372
+ metadata: Record<string, unknown>;
373
+ /** ISO-8601 timestamp when context was created */
374
+ started_at: string;
375
+ }
376
+ /**
377
+ * Create a new governed context.
378
+ */
379
+ declare function createGovernedContext(params: {
380
+ capability_id: string;
381
+ subject: SubjectContext;
382
+ governance_mode?: GovernanceMode;
383
+ risk_class?: RiskClass;
384
+ minimum_tier?: AssuranceTier;
385
+ correlation_id?: string | null;
386
+ trace_id?: string | null;
387
+ invariants?: DeclaredInvariant[];
388
+ metadata?: Record<string, unknown>;
389
+ }): GovernedContext;
390
+ /**
391
+ * Emit evidence within a governed context.
392
+ * Mutates the context by appending to evidence array.
393
+ */
394
+ declare function emitEvidence(ctx: GovernedContext, evidence_type: EvidenceType, payload?: Record<string, unknown>, assurance_tier?: AssuranceTier): Evidence;
395
+ /**
396
+ * Create a child context for invoking another capability.
397
+ * Maintains correlation and trace context.
398
+ */
399
+ declare function createChildContext(parent: GovernedContext, capability_id: string): GovernedContext;
400
+ /**
401
+ * Calculate elapsed time in milliseconds.
402
+ */
403
+ declare function elapsedMs(ctx: GovernedContext): number;
404
+ /**
405
+ * Configuration for governance behavior.
406
+ */
407
+ interface GovernanceConfig {
408
+ /** Default enforcement mode */
409
+ default_mode: GovernanceMode;
410
+ /** Whether a subject is always required */
411
+ require_subject: boolean;
412
+ /** Whether to emit evidence */
413
+ emit_evidence: boolean;
414
+ /** Whether to emit evidence for denials */
415
+ audit_denials: boolean;
416
+ /** Default assurance tier */
417
+ default_tier: AssuranceTier;
418
+ }
419
+ /**
420
+ * Create default governance configuration.
421
+ */
422
+ declare function createGovernanceConfig(overrides?: Partial<GovernanceConfig>): GovernanceConfig;
423
+ /**
424
+ * Development environment configuration.
425
+ */
426
+ declare const DEVELOPMENT_CONFIG: GovernanceConfig;
427
+ /**
428
+ * Production environment configuration.
429
+ */
430
+ declare const PRODUCTION_CONFIG: GovernanceConfig;
431
+ /**
432
+ * Testing environment configuration.
433
+ */
434
+ declare const TESTING_CONFIG: GovernanceConfig;
435
+
436
+ /**
437
+ * Capability Declaration Types
438
+ *
439
+ * Capabilities are the units of authority in CHP.
440
+ * This module defines the canonical capability declaration structure.
441
+ *
442
+ * @module capability
443
+ */
444
+
445
+ /**
446
+ * Metadata for a declared capability.
447
+ *
448
+ * This is the canonical record of what a capability is, what it can do,
449
+ * and what governance applies to it.
450
+ */
451
+ interface CapabilityDeclaration {
452
+ /** Unique capability identifier (e.g., "payment.process") */
453
+ name: string;
454
+ /** Semantic version string (e.g., "1.0.0") */
455
+ version: string;
456
+ /** Risk classification (INFORMATIONAL to CRITICAL) */
457
+ risk_class: RiskClass;
458
+ /** Human-readable description */
459
+ description: string;
460
+ /** Constraints that must hold for execution */
461
+ invariants: DeclaredInvariant[];
462
+ /** Evidence types this capability produces */
463
+ evidence_types: EvidenceType[];
464
+ /** Whether invocation requires authorization */
465
+ require_entitlement: boolean;
466
+ /** Minimum assurance tier for execution */
467
+ minimum_tier: AssuranceTier;
468
+ /** Team or individual responsible */
469
+ owner: string | null;
470
+ /** Categorization tags */
471
+ tags: string[];
472
+ }
473
+ /**
474
+ * Get the full capability identifier with version.
475
+ */
476
+ declare function getCapabilityId(decl: CapabilityDeclaration): string;
477
+ /**
478
+ * Create a new capability declaration.
479
+ */
480
+ declare function createCapabilityDeclaration(params: {
481
+ name: string;
482
+ version?: string;
483
+ risk_class?: RiskClass;
484
+ description?: string;
485
+ invariants?: DeclaredInvariant[];
486
+ evidence_types?: EvidenceType[];
487
+ require_entitlement?: boolean;
488
+ minimum_tier?: AssuranceTier;
489
+ owner?: string | null;
490
+ tags?: string[];
491
+ }): CapabilityDeclaration;
492
+ /**
493
+ * Validate that an object conforms to the CapabilityDeclaration interface.
494
+ */
495
+ declare function isCapabilityDeclaration(obj: unknown): obj is CapabilityDeclaration;
496
+ /**
497
+ * Supported invocation modes for a capability.
498
+ */
499
+ type InvocationMode = "sync" | "async" | "stream" | "fire_and_forget";
500
+ /**
501
+ * Invocation modes as a const array.
502
+ */
503
+ declare const INVOCATION_MODES: readonly ["sync", "async", "stream", "fire_and_forget"];
504
+ /**
505
+ * Host identity for capability hosting.
506
+ * Identifies where capabilities are hosted.
507
+ */
508
+ interface HostIdentity {
509
+ /** Unique host identifier */
510
+ host_id: string;
511
+ /** Host type (server, edge, agent, etc.) */
512
+ host_type: string;
513
+ /** Host version/build */
514
+ version: string;
515
+ /** Environment (production, staging, development) */
516
+ environment: string;
517
+ /** Additional host metadata */
518
+ metadata: Record<string, unknown>;
519
+ }
520
+ /**
521
+ * Create a new host identity.
522
+ */
523
+ declare function createHostIdentity(params: {
524
+ host_id: string;
525
+ host_type?: string;
526
+ version?: string;
527
+ environment?: string;
528
+ metadata?: Record<string, unknown>;
529
+ }): HostIdentity;
530
+
531
+ /**
532
+ * Legacy/internal TypeScript types for pre-v0.1 CHP work.
533
+ *
534
+ * These exports are retained for internal packages that still use the older
535
+ * mesh/governance model. They are not the public CHP v0.1 protocol surface.
536
+ *
537
+ * @packageDocumentation
538
+ */
539
+
540
+ declare const LEGACY_CHP_VERSION = "1.0";
541
+
542
+ export { ASSURANCE_TIERS, ASSURANCE_TIER_DISPLAY_NAMES, ASSURANCE_TIER_ORDER, type AssuranceTier, type CapabilityDeclaration, DEVELOPMENT_CONFIG, type DeclaredInvariant, EVIDENCE_TYPES, EXECUTION_OUTCOMES, type EnforcementResponsibility, type Evidence, type EvidenceType, type ExecutionOutcome, type FailureBehavior, GOVERNANCE_MODES, type GovernanceConfig, type GovernanceMode, type GovernedContext, type HostIdentity, INVARIANT_CLASSES, INVOCATION_MODES, type InvariantClass, type InvocationContext, type InvocationMode, LEGACY_CHP_VERSION, PRODUCTION_CONFIG, RISK_CLASSES, RISK_CLASS_ORDER, type RiskClass, type SubjectContext, TESTING_CONFIG, blocksExecution, compareAssuranceTier, compareRiskClass, createCapabilityDeclaration, createChildContext, createDeclaredInvariant, createEvidence, createGovernanceConfig, createGovernedContext, createHostIdentity, createInvocationContext, createSubjectContext, elapsedMs, emitEvidence, emitsEvidence, getAssuranceTierDisplayName, getCapabilityId, hasEntitlement, isCapabilityDeclaration, isDeclaredInvariant, isEvidence, isRiskAtLeast, meetsAssuranceTier };