mcard-js 2.1.47 → 2.1.49

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.
Files changed (52) hide show
  1. package/dist/AbstractSqlEngine-DKka6XjT.d.cts +451 -0
  2. package/dist/AbstractSqlEngine-DKka6XjT.d.ts +451 -0
  3. package/dist/CardCollection-TYC67XOH.js +10 -0
  4. package/dist/CardCollection-ZQ3G3Q3A.js +10 -0
  5. package/dist/EventProducer-VFDOM5W2.js +47 -0
  6. package/dist/IndexedDBEngine-5CEFZDOG.js +12 -0
  7. package/dist/IndexedDBEngine-BWXAB46W.js +12 -0
  8. package/dist/LLMRuntime-PH3MOQ2Y.js +17 -0
  9. package/dist/LambdaRuntime-DMEBYJIN.js +19 -0
  10. package/dist/LambdaRuntime-YH74FHIW.js +19 -0
  11. package/dist/Loader-OBPDJNFH.js +12 -0
  12. package/dist/Loader-WZXYG4GE.js +12 -0
  13. package/dist/MCard-RHTWJPHJ.js +8 -0
  14. package/dist/NetworkRuntime-KBQURQ6A.js +1598 -0
  15. package/dist/NetworkRuntime-S4DZCGVN.js +1598 -0
  16. package/dist/OllamaProvider-SPGO5Z5E.js +9 -0
  17. package/dist/chunk-3FFEA2XK.js +149 -0
  18. package/dist/chunk-7AXRV7NS.js +112 -0
  19. package/dist/chunk-AAO4GDBI.js +2360 -0
  20. package/dist/chunk-ASW6AOA7.js +140 -0
  21. package/dist/chunk-BJJZWPIF.js +112 -0
  22. package/dist/chunk-GGQCF7ZK.js +170 -0
  23. package/dist/chunk-HIVVDGE5.js +497 -0
  24. package/dist/chunk-HWBEGVEN.js +364 -0
  25. package/dist/chunk-ISY5LYLF.js +217 -0
  26. package/dist/chunk-KVZYFZJ5.js +427 -0
  27. package/dist/chunk-NGTY4P6A.js +275 -0
  28. package/dist/chunk-OAHWTOEB.js +275 -0
  29. package/dist/chunk-OUW2SUGM.js +368 -0
  30. package/dist/chunk-QKH3N62B.js +2360 -0
  31. package/dist/chunk-QPVEUPMU.js +299 -0
  32. package/dist/chunk-RZENJZGX.js +299 -0
  33. package/dist/chunk-VYDZR4ZD.js +364 -0
  34. package/dist/chunk-XJZOEM5F.js +903 -0
  35. package/dist/chunk-Z7EFXSTO.js +217 -0
  36. package/dist/index.browser.cjs +58 -20
  37. package/dist/index.browser.d.cts +34 -17
  38. package/dist/index.browser.d.ts +34 -17
  39. package/dist/index.browser.js +12 -8
  40. package/dist/index.cjs +644 -167
  41. package/dist/index.d.cts +725 -5
  42. package/dist/index.d.ts +725 -5
  43. package/dist/index.js +536 -95
  44. package/dist/storage/SqliteNodeEngine.cjs +28 -20
  45. package/dist/storage/SqliteNodeEngine.d.cts +1 -1
  46. package/dist/storage/SqliteNodeEngine.d.ts +1 -1
  47. package/dist/storage/SqliteNodeEngine.js +5 -5
  48. package/dist/storage/SqliteWasmEngine.cjs +28 -20
  49. package/dist/storage/SqliteWasmEngine.d.cts +1 -1
  50. package/dist/storage/SqliteWasmEngine.d.ts +1 -1
  51. package/dist/storage/SqliteWasmEngine.js +5 -5
  52. package/package.json +3 -1
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { S as StorageEngine, M as MCard } from './AbstractSqlEngine-BSfp8S_Y.cjs';
2
- export { P as Page } from './AbstractSqlEngine-BSfp8S_Y.cjs';
1
+ import { S as StorageEngine, M as MCard, D as DOTSMetadata } from './AbstractSqlEngine-DKka6XjT.cjs';
2
+ export { P as Page } from './AbstractSqlEngine-DKka6XjT.cjs';
3
3
  import { CardCollection, Either, IO, Maybe } from './index.browser.cjs';
4
- export { ALGORITHM_HIERARCHY, ContentHandle, ContentTypeInterpreter, EVENT_CONSTANTS, ErrorCodes, ExecutionResult, FaroSidecar, FaroSidecarConfig, GTime, HandleValidationError, HashValidator, IndexedDBEngine, JsonRpcRequest, JsonRpcResponse, LensProtocol, LivenessMetric, MCardStore, PolynomialTerm, PrimeHash, Reader, SafetyViolation, ServiceWorkerPTR, State, ValidationRegistry, VerificationStatus, Writer, computeHash, validateHandle, validationRegistry } from './index.browser.cjs';
4
+ export { ALGORITHM_HIERARCHY, ContentHandle, ContentTypeInterpreter, EVENT_CONSTANTS, ErrorCodes, ExecutionResult, FaroSidecar, FaroSidecarConfig, GTime, HandleValidationError, HashValidator, IndexedDBEngine, JsonRpcRequest, JsonRpcResponse, LensProtocol, LivenessMetric, MCardStore, PolynomialTerm, PostconditionViolation, PreconditionViolation, PrimeHash, Reader, SafetyViolation, ServiceWorkerPTR, State, ValidationRegistry, VerificationStatus, Writer, computeHash, validateHandle, validationRegistry } from './index.browser.cjs';
5
5
  export { SqliteWasmEngine } from './storage/SqliteWasmEngine.cjs';
6
6
  export { SqliteNodeEngine } from './storage/SqliteNodeEngine.cjs';
7
7
  import '@grafana/faro-web-sdk';
@@ -898,6 +898,725 @@ declare namespace index {
898
898
  export { type index_AbsTerm as AbsTerm, type index_AppTerm as AppTerm, type index_LambdaConfig as LambdaConfig, type index_LambdaOperation as LambdaOperation, index_LambdaRuntime as LambdaRuntime, type index_LambdaRuntimeResult as LambdaRuntimeResult, type index_LambdaTerm as LambdaTerm, type index_NormalizationResult as NormalizationResult, type index_ReductionStrategy as ReductionStrategy, type index_VarTerm as VarTerm, index_alphaEquivalent as alphaEquivalent, index_alphaNormalize as alphaNormalize, index_alphaRename as alphaRename, index_betaReduce as betaReduce, index_boundVariables as boundVariables, index_deserializeTerm as deserializeTerm, index_difference as difference, index_etaEquivalent as etaEquivalent, index_etaExpand as etaExpand, index_etaNormalize as etaNormalize, index_etaReduce as etaReduce, index_etaReduceE as etaReduceE, index_findEtaRedexes as findEtaRedexes, index_findInnermostRedex as findInnermostRedex, index_findLeftmostRedex as findLeftmostRedex, index_freeVariables as freeVariables, index_generateFresh as generateFresh, index_generateFreshFor as generateFreshFor, index_hasNormalForm as hasNormalForm, index_intersection as intersection, index_isAbs as isAbs, index_isApp as isApp, index_isClosed as isClosed, index_isEtaRedex as isEtaRedex, index_isFreeIn as isFreeIn, index_isNormalForm as isNormalForm, index_isRedex as isRedex, index_isVar as isVar, index_loadTerm as loadTerm, index_mcardToTerm as mcardToTerm, index_mkAbs as mkAbs, index_mkApp as mkApp, index_mkVar as mkVar, index_normalize as normalize, index_parseLambdaExpression as parseLambdaExpression, index_prettyPrintDeep as prettyPrintDeep, index_prettyPrintShallow as prettyPrintShallow, index_reduceStep as reduceStep, index_serializeTerm as serializeTerm, index_storeTerm as storeTerm, index_termExists as termExists, index_termToMCard as termToMCard };
899
899
  }
900
900
 
901
+ /**
902
+ * PCard Model (Control Plane) - Petri Net TRANSITION
903
+ *
904
+ * This module defines PCard, the execution unit in the MVP Cards architecture.
905
+ * PCards are MCards containing a valid CLM (Cubical Logic Model) specification.
906
+ *
907
+ * ## Categorical Foundation: STRONG PROFUNCTOR
908
+ *
909
+ * PCard implements the Strong Profunctor pattern from category theory:
910
+ *
911
+ * P: A^op × B → Set
912
+ *
913
+ * Where:
914
+ * - A^op denotes contravariance in input types (accepts MORE general)
915
+ * - B denotes covariance in output types (produces MORE specific)
916
+ * - Set is the category of sets (our value space)
917
+ *
918
+ * The "Strong" property means PCard supports:
919
+ * - first: P(A, B) → P(C × A, C × B) (threading context through)
920
+ * - second: P(A, B) → P(A × C, B × C) (preserving additional structure)
921
+ *
922
+ * ## Composition via Coend
923
+ *
924
+ * Two PCards compose via the Coend (categorical integral):
925
+ *
926
+ * (P ⨾ Q)(A, C) = ∫ᴮ P(A, B) × Q(B, C)
927
+ *
928
+ * Where:
929
+ * - ∫ᴮ is the Coend over the intermediate type B
930
+ * - P(A, B) is the first PCard (input A, output B)
931
+ * - Q(B, C) is the second PCard (input B, output C)
932
+ * - Result is a new PCard from A to C
933
+ *
934
+ * The `andThen()` method implements this Coend composition.
935
+ *
936
+ * ## SMC Structure (Symmetric Monoidal Category)
937
+ *
938
+ * PCard composition forms a Symmetric Monoidal Category:
939
+ * - **Identity**: The "pass-through" PCard
940
+ * - **Composition**: Sequential chaining via `andThen()` (;)
941
+ * - **Tensor Product**: Parallel composition via `andAlso()` (⊗)
942
+ * - **Symmetry**: Port swapping via `swap()` (σ)
943
+ *
944
+ * ## Functor Role in MVP Cards Hierarchy
945
+ *
946
+ * PCard is the **Functor** in the categorical hierarchy:
947
+ * - **MCard (Monad)**: Data container
948
+ * - **PCard (Functor)**: Pure transformation `fmap :: (a -> b) -> F a -> F b`
949
+ * - **VCard (Applicative)**: Context-aware application
950
+ *
951
+ * ## Petri Net Role: TRANSITION
952
+ *
953
+ * In the Categorical Petri Net model, PCard is the **Transition**:
954
+ * - Consumes input VCards (Tokens) from input Places
955
+ * - Executes CLM logic (Abstract → Concrete transformation)
956
+ * - Produces output VCards (Tokens) for output Places
957
+ *
958
+ * ### The Firing Rule
959
+ *
960
+ * M' = M - •t + t•
961
+ *
962
+ * Where:
963
+ * - M = Current marking (token distribution)
964
+ * - •t = Pre-set (input VCards required)
965
+ * - t• = Post-set (output VCards produced)
966
+ *
967
+ * ## CLM Triad: Abstract, Concrete, Balanced
968
+ *
969
+ * PCard content encodes the three dimensions:
970
+ * - **Abstract (A)**: WHY - Specification, intent, type signature
971
+ * - **Concrete (C)**: HOW - Implementation, runtime logic
972
+ * - **Balanced (B)**: WHAT - Tests, verification expectations
973
+ *
974
+ * ## DOTS Vocabulary Role: LENS + CHART
975
+ *
976
+ * - **Lens**: Tight morphism (Abstract ↔ Concrete coherence)
977
+ * - **Chart**: Loose morphism (Balanced expectations wiring)
978
+ *
979
+ * @see docs/PCard_Impl.md for full implementation specification
980
+ */
981
+
982
+ type ClmObject = Record<string, unknown>;
983
+ /**
984
+ * Input VCard reference for Petri Net pre-condition
985
+ */
986
+ interface InputVCardRef {
987
+ /** Handle name (Place) where precondition VCard must exist */
988
+ handle: string;
989
+ /** Expected VCard hash (optional, for strict matching) */
990
+ expectedHash?: string;
991
+ /** Purpose of this precondition (e.g., 'authenticate', 'authorize') */
992
+ purpose?: string;
993
+ }
994
+ /**
995
+ * Output VCard specification for Petri Net post-condition
996
+ */
997
+ interface OutputVCardSpec {
998
+ /** Handle name (Place) where output VCard will be deposited */
999
+ handle: string;
1000
+ /** Type of VCard to generate */
1001
+ type: 'verification' | 'authorization' | 'audit' | 'result';
1002
+ /** Additional metadata to include in the VCard */
1003
+ metadata?: Record<string, unknown>;
1004
+ }
1005
+ /**
1006
+ * PCard - The Control Plane unit (Petri Net Transition)
1007
+ *
1008
+ * A PCard is an MCard whose content is a valid CLM specification.
1009
+ * It represents a transformation (Lens) with a specific interaction pattern (Chart).
1010
+ */
1011
+ declare class PCard extends MCard {
1012
+ private readonly parsedClm;
1013
+ private readonly isLens;
1014
+ protected constructor(content: Uint8Array, hash: string, g_time: string, contentType: string, hashFunction: string, parsedClm: ClmObject, isLens: boolean);
1015
+ /**
1016
+ * Create a new PCard from CLM content
1017
+ *
1018
+ * @param content - The CLM YAML string or bytes
1019
+ * @param hashAlgorithm - Hash algorithm to use
1020
+ * @param isLens - Whether this acts primarily as a Lens (default true)
1021
+ */
1022
+ static create(content: string | Uint8Array, hashAlgorithm?: string, isLens?: boolean): Promise<PCard>;
1023
+ /**
1024
+ * Get DOTS vocabulary metadata for this PCard
1025
+ *
1026
+ * Automatically extracts dependencies from the CLM structure if available.
1027
+ */
1028
+ getDOTSMetadata(): DOTSMetadata;
1029
+ /**
1030
+ * Get the parsed CLM object
1031
+ */
1032
+ get clm(): ClmObject;
1033
+ private getSection;
1034
+ /**
1035
+ * Get the Abstract Specification section (UPTV Role: Abstract)
1036
+ */
1037
+ get abstract(): unknown;
1038
+ /**
1039
+ * Get the Concrete Implementation section (UPTV Role: Concrete)
1040
+ */
1041
+ get concrete(): unknown;
1042
+ /**
1043
+ * Get the Balanced Expectations (tests) section (UPTV Role: Balanced)
1044
+ */
1045
+ get balanced(): unknown;
1046
+ /**
1047
+ * Get the Abstract Specification section (Legacy)
1048
+ */
1049
+ get abstractSpec(): unknown;
1050
+ /**
1051
+ * Get the Concrete Implementation section (Legacy)
1052
+ */
1053
+ get concreteImpl(): unknown;
1054
+ /**
1055
+ * Get the Balanced Expectations (tests) section (Legacy)
1056
+ */
1057
+ get balancedExpectations(): unknown;
1058
+ /**
1059
+ * Sequential Composition via Coend (P ⨾ Q)
1060
+ *
1061
+ * Implements profunctor composition using the Coend formula:
1062
+ *
1063
+ * (P ⨾ Q)(A, C) = ∫ᴮ P(A, B) × Q(B, C)
1064
+ *
1065
+ * Where:
1066
+ * - this is P: A → B
1067
+ * - otherPCard is Q: B → C
1068
+ * - Result is P ⨾ Q: A → C
1069
+ *
1070
+ * The Coend (∫ᴮ) "integrates out" the intermediate type B by:
1071
+ * 1. Matching P's output type with Q's input type
1072
+ * 2. Creating a chain where P's result feeds into Q
1073
+ * 3. The composition is associative: (P ⨾ Q) ⨾ R = P ⨾ (Q ⨾ R)
1074
+ *
1075
+ * In PTR execution:
1076
+ * - P is executed first (prep → exec → post)
1077
+ * - P's output VCard becomes Q's input VCard
1078
+ * - Q is executed second
1079
+ * - Final result is Q's output VCard
1080
+ *
1081
+ * Note: Named 'andThen' to avoid conflict with Promise.then (Thenable).
1082
+ *
1083
+ * @param otherPCard - The PCard to execute after this one (Q in P ⨾ Q)
1084
+ * @returns A new PCard representing the composed profunctor (P ⨾ Q)
1085
+ */
1086
+ andThen(otherPCard: PCard): Promise<PCard>;
1087
+ /**
1088
+ * Tensor Product ($A \otimes B$)
1089
+ *
1090
+ * Runs this PCard and otherPCard in parallel.
1091
+ */
1092
+ andAlso(otherPCard: PCard): Promise<PCard>;
1093
+ /**
1094
+ * Symmetry ($\sigma$)
1095
+ *
1096
+ * Swaps the input/output ports of a tensor product.
1097
+ */
1098
+ swap(): Promise<PCard>;
1099
+ /**
1100
+ * Run the Balanced Expectations (Proof)
1101
+ */
1102
+ verify(): Record<string, unknown>;
1103
+ /**
1104
+ * Run with instrumentation (eBPF/Tracing)
1105
+ */
1106
+ profile(): Record<string, unknown>;
1107
+ /**
1108
+ * Run in Operative mode (Step-by-step)
1109
+ */
1110
+ debug(): Record<string, unknown>;
1111
+ /**
1112
+ * Return documentation/explanation
1113
+ */
1114
+ explain(): Record<string, unknown>;
1115
+ /**
1116
+ * Get input VCard references (Pre-set: •t)
1117
+ *
1118
+ * These represent the preconditions that must be satisfied before
1119
+ * this PCard (Transition) can fire.
1120
+ *
1121
+ * @returns Array of input VCard references from CLM specification
1122
+ */
1123
+ getInputVCardRefs(): InputVCardRef[];
1124
+ /**
1125
+ * Get output VCard specifications (Post-set: t•)
1126
+ *
1127
+ * These define what VCards (Tokens) this PCard produces when fired.
1128
+ *
1129
+ * @returns Array of output VCard specifications
1130
+ */
1131
+ getOutputVCardSpecs(): OutputVCardSpec[];
1132
+ /**
1133
+ * Get the canonical handle for this PCard (Transition)
1134
+ *
1135
+ * @returns Handle string in form `clm://{module}/{function}/spec`
1136
+ */
1137
+ getTransitionHandle(): string;
1138
+ /**
1139
+ * Get the balanced expectations handle for this PCard
1140
+ *
1141
+ * This is where verification history is tracked in handle_history.
1142
+ *
1143
+ * @returns Handle string for balanced expectations
1144
+ */
1145
+ getBalancedHandle(): string;
1146
+ /**
1147
+ * Check if this PCard (Transition) can fire given the available VCards
1148
+ *
1149
+ * A transition can fire when all input VCards (preconditions) are present.
1150
+ *
1151
+ * @param availableVCards - Map of handle → VCard hash
1152
+ * @returns Object with canFire boolean and missing preconditions
1153
+ */
1154
+ canFire(availableVCards: Map<string, string>): {
1155
+ canFire: boolean;
1156
+ missing: string[];
1157
+ };
1158
+ /**
1159
+ * Get the runtime required for this PCard
1160
+ *
1161
+ * @returns Runtime name (e.g., 'javascript', 'python', 'lean')
1162
+ */
1163
+ getRuntime(): string;
1164
+ /**
1165
+ * Check if this is a multi-runtime PCard
1166
+ *
1167
+ * @returns True if this PCard supports multiple runtimes
1168
+ */
1169
+ isMultiRuntime(): boolean;
1170
+ /**
1171
+ * Get precondition specification for VCard Sandwich evaluation.
1172
+ *
1173
+ * Extracts the precondition spec from abstract.preconditions,
1174
+ * classifying each condition by type.
1175
+ *
1176
+ * @returns Object with conditions array and classified conditions
1177
+ */
1178
+ getPreVCardSpec(): {
1179
+ conditions: unknown[];
1180
+ classified: {
1181
+ type: string;
1182
+ condition: unknown;
1183
+ }[];
1184
+ };
1185
+ /**
1186
+ * Get postcondition specification for VCard Sandwich evaluation.
1187
+ *
1188
+ * Extracts the postcondition spec from abstract.postconditions,
1189
+ * classifying each condition by type.
1190
+ *
1191
+ * @returns Object with conditions array and classified conditions
1192
+ */
1193
+ getPostVCardSpec(): {
1194
+ conditions: unknown[];
1195
+ classified: {
1196
+ type: string;
1197
+ condition: unknown;
1198
+ }[];
1199
+ };
1200
+ /**
1201
+ * Classify a condition by its type (function, schema, capability, declarative).
1202
+ *
1203
+ * @param condition - The condition to classify
1204
+ * @returns Object with type and the original condition
1205
+ */
1206
+ private classifyCondition;
1207
+ }
1208
+
1209
+ /**
1210
+ * VCard Model (Application Plane) - Petri Net TOKEN / PRE-CONDITION CARRIER
1211
+ *
1212
+ * This module defines VCard, the sovereign decision layer in the MVP Cards architecture.
1213
+ * VCard is the Applicative that manages all side effects and authorization.
1214
+ *
1215
+ * ## Category Theory Role: APPLICATIVE
1216
+ *
1217
+ * VCard is the **Applicative** in the MVP Cards categorical hierarchy:
1218
+ * - **MCard (Monad)**: Data container with unit and bind
1219
+ * - **PCard (Functor)**: Pure transformation
1220
+ * - **VCard (Applicative)**: Context-aware application `<*> :: F (a -> b) -> F a -> F b`
1221
+ *
1222
+ * The Applicative nature means VCard can encode **static pre-conditions**:
1223
+ * the authorization graph is known ahead of time, while actual execution
1224
+ * depends on runtime results.
1225
+ *
1226
+ * ## Petri Net Role: TOKEN + PRE-CONDITION
1227
+ *
1228
+ * In the Categorical Petri Net model, VCard serves dual roles:
1229
+ *
1230
+ * ### As Token
1231
+ * - VCard is the **Token** that resides in Places (Handles)
1232
+ * - Tokens enable Transitions (PCards) to fire
1233
+ * - Token movement represents verification cascade
1234
+ *
1235
+ * ### As Pre-Condition (Firing Guard)
1236
+ * A Petri Net transition fires when all input VCards exist:
1237
+ *
1238
+ * ```
1239
+ * M' = M - •t + t•
1240
+ * ```
1241
+ *
1242
+ * VCard as Input Arc encodes:
1243
+ * - **Input Place**: Handle pointing to required VCard
1244
+ * - **Token in Place**: VCard content in `card` table
1245
+ * - **Arc Guard**: VCard's Applicative authorization check
1246
+ * - **Token "Consumption"**: Recording `previous_hash` in new VCard
1247
+ *
1248
+ * ### Hash as Token AND Certificate (Dual Role)
1249
+ *
1250
+ * | Role | Function | Implementation |
1251
+ * |------|----------|----------------|
1252
+ * | **Token** | Triggers firing (enables transitions) | `handle_registry.current_hash IS NOT NULL` |
1253
+ * | **Certificate** | Proves correctness after verification | VCard content witnesses Hoare Triple |
1254
+ *
1255
+ * ```
1256
+ * {h_pre} PCard {h_post}
1257
+ * ```
1258
+ *
1259
+ * Where:
1260
+ * - h_pre = hash of input VCard (precondition satisfied)
1261
+ * - PCard = CLM specification (transformation logic)
1262
+ * - h_post = hash of output VCard (postcondition witnessed)
1263
+ *
1264
+ * ## Cascade Pattern: Propagating Verification
1265
+ *
1266
+ * VCards enable **verification cascades** across the network:
1267
+ *
1268
+ * ```
1269
+ * T1 → V1 → T2 → V2 → T3 → ... → Vn
1270
+ * ```
1271
+ *
1272
+ * Each VerificationVCard (Vi) serves as:
1273
+ * 1. **Post-condition** of transition Ti (what it produces)
1274
+ * 2. **Pre-condition** of transition Ti+1 (what enables next step)
1275
+ *
1276
+ * ## DOTS Vocabulary Role: ARENA + ACTION
1277
+ *
1278
+ * VCard is both:
1279
+ * - **Arena**: Interface type defining what can interact (subject_did, capabilities, external_refs)
1280
+ * - **Action**: Morphism where interactions (PCards) act on systems (MCards)
1281
+ *
1282
+ * ## The Four Roles:
1283
+ * 1. Identity & Credential Container (The "Who")
1284
+ * 2. Verification Hub (The "Rules")
1285
+ * 3. Side Effect Manager (The "Bridge")
1286
+ * 4. Input/Output Gatekeeper (The "Gate")
1287
+ *
1288
+ * ## VCard as Egress Gate: The Sovereign Boundary
1289
+ *
1290
+ * When a VerificationVCard is produced, it may also serve as **egress authorization**:
1291
+ *
1292
+ * | Egress Role | VCard Content | Enables |
1293
+ * |-------------|--------------|---------|
1294
+ * | Export Authorization | `egress_capability: { destination_did, scope }` | Sharing to specific PKCs |
1295
+ * | Cross-PKC Transition | `transferable: true` | Token moves to destination's Petri Net |
1296
+ * | Federation Trigger | Signed VCard bundle | Downstream PKC's transitions enabled |
1297
+ *
1298
+ * @see docs/VCard_Impl.md for full implementation specification
1299
+ */
1300
+
1301
+ /**
1302
+ * Scope of a capability token.
1303
+ */
1304
+ declare enum CapabilityScope {
1305
+ READ = "read",
1306
+ WRITE = "write",
1307
+ EXECUTE = "execute",
1308
+ ADMIN = "admin",
1309
+ DELEGATE = "delegate"
1310
+ }
1311
+ /**
1312
+ * Direction of gatekeeper authorization.
1313
+ */
1314
+ declare enum GatekeeperDirection {
1315
+ INGRESS = "ingress",
1316
+ EGRESS = "egress"
1317
+ }
1318
+ /**
1319
+ * A capability token defining authorized actions.
1320
+ */
1321
+ interface Capability {
1322
+ capabilityId: string;
1323
+ actorDid: string;
1324
+ scope: CapabilityScope;
1325
+ resourcePattern: string;
1326
+ expiresAt?: Date;
1327
+ constraints?: Record<string, unknown>;
1328
+ transferable: boolean;
1329
+ }
1330
+ /**
1331
+ * A verified external reference managed by VCard.
1332
+ */
1333
+ interface ExternalRef {
1334
+ uri: string;
1335
+ contentHash: string;
1336
+ status: 'verified' | 'pending' | 'stale' | 'invalid';
1337
+ signature?: string;
1338
+ lastVerified?: Date;
1339
+ qosMetrics?: Record<string, unknown>;
1340
+ }
1341
+ type ParsedVCardContent = Record<string, unknown>;
1342
+ type SimulationLogEntry = {
1343
+ timestamp: Date;
1344
+ effectType: string;
1345
+ details: unknown;
1346
+ simulated: true;
1347
+ };
1348
+ /**
1349
+ * An ingress or egress gatekeeper event.
1350
+ */
1351
+ interface GatekeeperEvent {
1352
+ direction: GatekeeperDirection;
1353
+ timestamp: Date;
1354
+ sourceDid?: string;
1355
+ destinationDid?: string;
1356
+ contentHash: string;
1357
+ authorized: boolean;
1358
+ capabilityUsed?: string;
1359
+ signature?: string;
1360
+ }
1361
+ /**
1362
+ * VCard - The Application Plane unit (Petri Net Token)
1363
+ *
1364
+ * Implements the Empty Schema Principle: VCard IS an MCard.
1365
+ * This class provides a view and runtime state management over the immutable content.
1366
+ *
1367
+ * In Petri Net terms:
1368
+ * - VCard is a **Token** that resides in a **Place** (Handle)
1369
+ * - VCard enables **Transitions** (PCards) to fire when present
1370
+ * - VCard serves as both **Pre-condition** (what enables) and **Post-condition** (what is produced)
1371
+ */
1372
+ declare class VCard extends MCard {
1373
+ private _subjectDid;
1374
+ private _controllerPubkeys;
1375
+ private _capabilities;
1376
+ private _externalRefs;
1377
+ private _exportManifest;
1378
+ private _gatekeeperLog;
1379
+ private _pcardRefsHashes;
1380
+ protected constructor(content: Uint8Array, hash: string, g_time: string, contentType: string, hashFunction: string, initialData: ParsedVCardContent);
1381
+ private _initializeMutableState;
1382
+ /**
1383
+ * Create a new VCard from parameters.
1384
+ * Follows strict UPTV structure { vcard: { ... } }.
1385
+ */
1386
+ static createVCard(subjectDid: string, controllerPubkeys: string[], capabilities?: Capability[], externalRefs?: ExternalRef[], hashAlgorithm?: string): Promise<VCard>;
1387
+ /**
1388
+ * Create a VCard wrapper from an existing MCard.
1389
+ */
1390
+ static fromMCard(card: MCard): Promise<VCard>;
1391
+ getDOTSMetadata(): DOTSMetadata;
1392
+ get subjectDid(): string;
1393
+ get controllerPubkeys(): string[];
1394
+ get capabilities(): Capability[];
1395
+ get externalRefs(): ExternalRef[];
1396
+ addCapability(capability: Capability): void;
1397
+ getValidCapabilities(): Capability[];
1398
+ hasCapability(scope: CapabilityScope, resourceHash: string): boolean;
1399
+ addPCardReference(pcardHash: string): void;
1400
+ getPCardReferences(): string[];
1401
+ addExternalRef(ref: ExternalRef): void;
1402
+ getExternalRefsByStatus(status: ExternalRef['status']): ExternalRef[];
1403
+ verifyExternalRef(uri: string, newHash: string): boolean;
1404
+ authorizeIngress(sourceDid: string, contentHash: string, capabilityId?: string): boolean;
1405
+ registerForEgress(contentHash: string): boolean;
1406
+ authorizeEgress(destinationDid: string, contentHash: string, capabilityId?: string): boolean;
1407
+ private _logEgress;
1408
+ getGatekeeperLog(direction?: GatekeeperDirection): GatekeeperEvent[];
1409
+ getExportManifest(): string[];
1410
+ simulateMode(): VCardSimulation;
1411
+ /**
1412
+ * Get the handle where this VCard token currently resides
1413
+ *
1414
+ * In Petri Net terms, this is the "Place" where the token is located.
1415
+ *
1416
+ * @returns Handle string if available in content, or hash-based handle
1417
+ */
1418
+ getTokenHandle(): string;
1419
+ /**
1420
+ * Check if this VCard is a VerificationVCard (result of PCard execution)
1421
+ *
1422
+ * VerificationVCards are produced by PCard transitions and contain
1423
+ * execution results with provenance chain.
1424
+ *
1425
+ * @returns True if this is a verification token
1426
+ */
1427
+ isVerificationVCard(): boolean;
1428
+ /**
1429
+ * Get the previous hash in the provenance chain
1430
+ *
1431
+ * In Petri Net terms, this links to the input VCard that was "consumed"
1432
+ * when the transition fired to produce this VCard.
1433
+ *
1434
+ * @returns Previous VCard hash if this is part of a verification cascade
1435
+ */
1436
+ getPreviousHash(): string | undefined;
1437
+ /**
1438
+ * Get the PCard hash that produced this VCard (if verification)
1439
+ *
1440
+ * This links the output token to the transition that created it.
1441
+ *
1442
+ * @returns PCard hash that produced this VCard
1443
+ */
1444
+ getSourcePCardHash(): string | undefined;
1445
+ /**
1446
+ * Create a VerificationVCard from PCard execution result
1447
+ *
1448
+ * This is the factory method for producing output tokens in the Petri Net.
1449
+ *
1450
+ * @param pcard - The PCard (Transition) that executed
1451
+ * @param result - Execution result
1452
+ * @param previousVCard - Input VCard (pre-condition) if any
1453
+ * @param success - Whether execution succeeded
1454
+ * @returns New VerificationVCard
1455
+ */
1456
+ static createVerificationVCard(pcard: {
1457
+ hash: string;
1458
+ getTransitionHandle?: () => string;
1459
+ getBalancedHandle?: () => string;
1460
+ }, result: unknown, previousVCard?: VCard, success?: boolean, hashAlgorithm?: string): Promise<VCard>;
1461
+ /**
1462
+ * Check if this VCard enables a specific PCard to fire
1463
+ *
1464
+ * @param requiredHandle - The handle where a precondition VCard must exist
1465
+ * @returns True if this VCard satisfies that precondition
1466
+ */
1467
+ enablesTransition(requiredHandle: string): boolean;
1468
+ /**
1469
+ * Witness Precondition (V_pre) — creates a VCard that witnesses
1470
+ * the input was accepted for evaluation.
1471
+ *
1472
+ * @param inputMCard - The input MCard being evaluated
1473
+ * @param hashAlgorithm - Hash algorithm to use
1474
+ * @returns VCard with type "precondition-witness"
1475
+ */
1476
+ static witnessPrecondition(inputMCard: MCard, hashAlgorithm?: string): Promise<VCard>;
1477
+ /**
1478
+ * Witness Postcondition (V_post) — creates a VCard that witnesses
1479
+ * the output was produced by a PCard evaluation.
1480
+ *
1481
+ * @param output - The execution output
1482
+ * @param pcardHash - Hash of the PCard that produced the output
1483
+ * @param hashAlgorithm - Hash algorithm to use
1484
+ * @returns VCard with type "postcondition-witness"
1485
+ */
1486
+ static witnessPostcondition(output: unknown, pcardHash?: string, hashAlgorithm?: string): Promise<VCard>;
1487
+ /**
1488
+ * Create a Sandwich Proof — combines V_pre and V_post into a
1489
+ * composite verification proof.
1490
+ *
1491
+ * @param vPre - Precondition witness VCard
1492
+ * @param vPost - Postcondition witness VCard
1493
+ * @param pcardHash - Hash of the PCard that was evaluated
1494
+ * @param hashAlgorithm - Hash algorithm to use
1495
+ * @returns VCard with type "verification-sandwich"
1496
+ */
1497
+ static sandwich(vPre: VCard, vPost: VCard, pcardHash?: string, hashAlgorithm?: string): Promise<VCard>;
1498
+ }
1499
+ /**
1500
+ * Simulation context for VCard (EOS Compliance).
1501
+ */
1502
+ declare class VCardSimulation {
1503
+ private vcard;
1504
+ private log;
1505
+ constructor(vcard: VCard);
1506
+ logEffect(effectType: string, details: unknown): void;
1507
+ getSimulationLog(): SimulationLogEntry[];
1508
+ }
1509
+
1510
+ /**
1511
+ * PTREngine — The Polynomial Type Runtime Engine (Arrow Interface)
1512
+ *
1513
+ * This is the canonical execution primitive for the MVP Cards architecture.
1514
+ * It implements the formal Arrow interface mandated by the design documents:
1515
+ *
1516
+ * - arr: Lift a pure function into a PTR-managed Arrow (PCard)
1517
+ * - compose: Sequential composition (>>>)
1518
+ * - first: Operate on first element of a product, preserving second
1519
+ *
1520
+ * The `runWithSandwich()` method is the core Arrow evaluation function,
1521
+ * implementing the VCard Sandwich lifecycle:
1522
+ *
1523
+ * V_pre → PCard(Evaluation Map) → V_post → Sandwich(V_pre, V_post)
1524
+ *
1525
+ * Mirrors Python: mcard.ptr.core.engine.PTREngine
1526
+ *
1527
+ * Usage:
1528
+ * import { PTREngine } from './PTREngine.js';
1529
+ * const engine = new PTREngine(collection);
1530
+ * const [output, sandwich] = await engine.runWithSandwich(pcardHash, inputHash);
1531
+ *
1532
+ * @module PTREngine
1533
+ */
1534
+
1535
+ type PreCheck = (input: MCard) => boolean;
1536
+ type PostCheck = (output: unknown) => boolean;
1537
+ /**
1538
+ * PTREngine — The formal Arrow execution engine.
1539
+ *
1540
+ * Replaces ad-hoc CLMRunner execution paths with a formal
1541
+ * VCard Sandwich lifecycle. Every PCard execution generates
1542
+ * (V_pre, V_post) boundary proofs.
1543
+ */
1544
+ declare class PTREngine {
1545
+ private collection;
1546
+ private executionLog;
1547
+ private runner;
1548
+ /**
1549
+ * Initialize PTREngine.
1550
+ *
1551
+ * @param storageCollection - MCard collection for long-term knowledge (mcard_collection.db)
1552
+ * @param executionLogCollection - MCard collection for execution traces (execution_log.db).
1553
+ * If not provided, traces are written to storageCollection.
1554
+ * @param options - Additional configuration
1555
+ */
1556
+ constructor(storageCollection?: CardCollection, executionLogCollection?: CardCollection, options?: {
1557
+ basePath?: string;
1558
+ timeout?: number;
1559
+ });
1560
+ /**
1561
+ * The Arrow execution primitive — the entire PTR in one method.
1562
+ *
1563
+ * Implements the VCard Sandwich lifecycle:
1564
+ * V_pre → PCard(Evaluation Map) → V_post
1565
+ *
1566
+ * @param pcardHash - Hash of the PCard to execute
1567
+ * @param inputHash - Hash of the input MCard
1568
+ * @param preCheck - Optional callable to validate preconditions on input
1569
+ * @param postCheck - Optional callable to validate postconditions on output
1570
+ * @returns Tuple of [execution_output, vcard_sandwich]
1571
+ * @throws PreconditionViolation if preCheck returns false
1572
+ * @throws PostconditionViolation if postCheck returns false
1573
+ */
1574
+ runWithSandwich(pcardHash: string, inputHash: string, preCheck?: PreCheck, postCheck?: PostCheck): Promise<[unknown, VCard]>;
1575
+ /**
1576
+ * Execute a CLM specification from a YAML file.
1577
+ *
1578
+ * Absorbs CLMRunner.runFile(), routing all file-based execution
1579
+ * through the formal PTREngine lifecycle with VCard Sandwich generation.
1580
+ *
1581
+ * @param filePath - Path to the YAML file
1582
+ * @param context - Execution context (inputs)
1583
+ * @returns Execution report with VCard Sandwich proof hashes
1584
+ */
1585
+ runFile(filePath: string, context?: Record<string, unknown>): Promise<Record<string, unknown>>;
1586
+ /**
1587
+ * Arrow `arr` — lift a pure function into a PCard.
1588
+ *
1589
+ * Creates a PCard whose Concrete implementation is the given function.
1590
+ *
1591
+ * @param func - A pure function from string to string
1592
+ * @param name - Human-readable name for the PCard
1593
+ * @returns The created PCard (stored in collection)
1594
+ */
1595
+ arr(func: (input: string) => string, name?: string): Promise<PCard>;
1596
+ /**
1597
+ * Arrow `>>>` — sequential composition of two PCards.
1598
+ *
1599
+ * Creates a new PCard representing pcardA >>> pcardB,
1600
+ * where the output of A feeds into the input of B.
1601
+ *
1602
+ * @param pcardAHash - Hash of the first PCard (executed first)
1603
+ * @param pcardBHash - Hash of the second PCard (executed second)
1604
+ * @returns The composed PCard (stored in collection)
1605
+ */
1606
+ compose(pcardAHash: string, pcardBHash: string): Promise<PCard>;
1607
+ /**
1608
+ * Arrow `first` — operate on first element of a product.
1609
+ *
1610
+ * Creates a new PCard that applies the original PCard to the
1611
+ * first element of a (A, C) pair while preserving C.
1612
+ *
1613
+ * @param pcardHash - Hash of the PCard to lift
1614
+ * @returns The first-lifted PCard (stored in collection)
1615
+ */
1616
+ first(pcardHash: string): Promise<PCard>;
1617
+ private recordToExecutionLog;
1618
+ }
1619
+
901
1620
  /**
902
1621
  * Type definitions for CLM (Cubical Logic Model) execution.
903
1622
  */
@@ -1089,7 +1808,8 @@ declare class CLMRunner {
1089
1808
  private loader;
1090
1809
  private timeout;
1091
1810
  private collection?;
1092
- constructor(basePath?: string, timeout?: number, collection?: CardCollection);
1811
+ private privateCollection?;
1812
+ constructor(basePath?: string, timeout?: number, collection?: CardCollection, privateCollection?: CardCollection);
1093
1813
  /**
1094
1814
  * Run a CLM directly from a file path.
1095
1815
  */
@@ -1153,4 +1873,4 @@ declare class CLMRunner {
1153
1873
  private buildRunCLM;
1154
1874
  }
1155
1875
 
1156
- export { CLMRunner, CardCollection, type CreateEngineOptions, ENGINE_INFO, Either, type EngineEnvironment, type EngineInfo, EngineType, FileIO, IO, LLMConfig, LLMRuntime, index as Lambda, LambdaRuntime, Loader, MCard, Maybe, SandboxWorker, StorageEngine, chatMonad, createEngine, getAvailableEngines, getEngineInfo, getEnginesByEnvironment, promptMonad };
1876
+ export { CLMRunner, CardCollection, type CreateEngineOptions, ENGINE_INFO, Either, type EngineEnvironment, type EngineInfo, EngineType, FileIO, IO, LLMConfig, LLMRuntime, index as Lambda, LambdaRuntime, Loader, MCard, Maybe, PTREngine, SandboxWorker, StorageEngine, chatMonad, createEngine, getAvailableEngines, getEngineInfo, getEnginesByEnvironment, promptMonad };