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.
- package/dist/AbstractSqlEngine-DKka6XjT.d.cts +451 -0
- package/dist/AbstractSqlEngine-DKka6XjT.d.ts +451 -0
- package/dist/CardCollection-TYC67XOH.js +10 -0
- package/dist/CardCollection-ZQ3G3Q3A.js +10 -0
- package/dist/EventProducer-VFDOM5W2.js +47 -0
- package/dist/IndexedDBEngine-5CEFZDOG.js +12 -0
- package/dist/IndexedDBEngine-BWXAB46W.js +12 -0
- package/dist/LLMRuntime-PH3MOQ2Y.js +17 -0
- package/dist/LambdaRuntime-DMEBYJIN.js +19 -0
- package/dist/LambdaRuntime-YH74FHIW.js +19 -0
- package/dist/Loader-OBPDJNFH.js +12 -0
- package/dist/Loader-WZXYG4GE.js +12 -0
- package/dist/MCard-RHTWJPHJ.js +8 -0
- package/dist/NetworkRuntime-KBQURQ6A.js +1598 -0
- package/dist/NetworkRuntime-S4DZCGVN.js +1598 -0
- package/dist/OllamaProvider-SPGO5Z5E.js +9 -0
- package/dist/chunk-3FFEA2XK.js +149 -0
- package/dist/chunk-7AXRV7NS.js +112 -0
- package/dist/chunk-AAO4GDBI.js +2360 -0
- package/dist/chunk-ASW6AOA7.js +140 -0
- package/dist/chunk-BJJZWPIF.js +112 -0
- package/dist/chunk-GGQCF7ZK.js +170 -0
- package/dist/chunk-HIVVDGE5.js +497 -0
- package/dist/chunk-HWBEGVEN.js +364 -0
- package/dist/chunk-ISY5LYLF.js +217 -0
- package/dist/chunk-KVZYFZJ5.js +427 -0
- package/dist/chunk-NGTY4P6A.js +275 -0
- package/dist/chunk-OAHWTOEB.js +275 -0
- package/dist/chunk-OUW2SUGM.js +368 -0
- package/dist/chunk-QKH3N62B.js +2360 -0
- package/dist/chunk-QPVEUPMU.js +299 -0
- package/dist/chunk-RZENJZGX.js +299 -0
- package/dist/chunk-VYDZR4ZD.js +364 -0
- package/dist/chunk-XJZOEM5F.js +903 -0
- package/dist/chunk-Z7EFXSTO.js +217 -0
- package/dist/index.browser.cjs +58 -20
- package/dist/index.browser.d.cts +34 -17
- package/dist/index.browser.d.ts +34 -17
- package/dist/index.browser.js +12 -8
- package/dist/index.cjs +644 -167
- package/dist/index.d.cts +725 -5
- package/dist/index.d.ts +725 -5
- package/dist/index.js +536 -95
- package/dist/storage/SqliteNodeEngine.cjs +28 -20
- package/dist/storage/SqliteNodeEngine.d.cts +1 -1
- package/dist/storage/SqliteNodeEngine.d.ts +1 -1
- package/dist/storage/SqliteNodeEngine.js +5 -5
- package/dist/storage/SqliteWasmEngine.cjs +28 -20
- package/dist/storage/SqliteWasmEngine.d.cts +1 -1
- package/dist/storage/SqliteWasmEngine.d.ts +1 -1
- package/dist/storage/SqliteWasmEngine.js +5 -5
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -96,13 +96,13 @@ var init_GTime = __esm({
|
|
|
96
96
|
static DEFAULT_ALGORITHM = "sha256";
|
|
97
97
|
/**
|
|
98
98
|
* Generate a GTime stamp for the current moment
|
|
99
|
-
* Format:
|
|
99
|
+
* Format: ALGORITHM|TIMESTAMP|LOCALE_OR_DID
|
|
100
|
+
* Representing the mathematical coordinate (a,b,c) for an event signature.
|
|
100
101
|
*/
|
|
101
|
-
static stampNow(hashAlgorithm = this.DEFAULT_ALGORITHM) {
|
|
102
|
+
static stampNow(hashAlgorithm = this.DEFAULT_ALGORITHM, localeOrDID = "UTC") {
|
|
102
103
|
const algo = hashAlgorithm.toLowerCase();
|
|
103
104
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
104
|
-
|
|
105
|
-
return `${algo}|${timestamp}|${region}`;
|
|
105
|
+
return `${algo}|${timestamp}|${localeOrDID}`;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Parse a GTime string
|
|
@@ -115,26 +115,28 @@ var init_GTime = __esm({
|
|
|
115
115
|
return {
|
|
116
116
|
algorithm: parts[0],
|
|
117
117
|
timestamp: new Date(parts[1]),
|
|
118
|
-
|
|
118
|
+
localeOrDID: parts[2]
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
static getHashAlgorithm(gtime) {
|
|
121
|
+
/** Extract coordinate a: Algorithm */
|
|
122
|
+
static getAlgorithm(gtime) {
|
|
125
123
|
return this.parse(gtime).algorithm;
|
|
126
124
|
}
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
/** Alias for backward compatibility */
|
|
126
|
+
static getHashAlgorithm(gtime) {
|
|
127
|
+
return this.getAlgorithm(gtime);
|
|
128
|
+
}
|
|
129
|
+
/** Extract coordinate b: Timestamp */
|
|
130
130
|
static getTimestamp(gtime) {
|
|
131
131
|
return this.parse(gtime).timestamp;
|
|
132
132
|
}
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
/** Extract coordinate c: Locale or DID */
|
|
134
|
+
static getLocaleOrDID(gtime) {
|
|
135
|
+
return this.parse(gtime).localeOrDID;
|
|
136
|
+
}
|
|
137
|
+
/** Alias for backward compatibility */
|
|
136
138
|
static getRegionCode(gtime) {
|
|
137
|
-
return this.
|
|
139
|
+
return this.getLocaleOrDID(gtime);
|
|
138
140
|
}
|
|
139
141
|
/**
|
|
140
142
|
* Check if the provided hash function is valid.
|
|
@@ -147,11 +149,11 @@ var init_GTime = __esm({
|
|
|
147
149
|
return VALID_HASH_ALGORITHMS.includes(hashFunction.toLowerCase());
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
|
-
* Check if the provided region code is valid.
|
|
151
|
-
*
|
|
152
|
+
* Check if the provided locale/region code is valid.
|
|
153
|
+
* Maintains backward compatibility by checking for strings.
|
|
152
154
|
*/
|
|
153
155
|
static isValidRegionCode(regionCode) {
|
|
154
|
-
return Boolean(regionCode && regionCode ===
|
|
156
|
+
return Boolean(regionCode && typeof regionCode === "string");
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
159
|
* Check if the provided timestamp is in ISO format.
|
|
@@ -453,6 +455,8 @@ var init_app_config = __esm({
|
|
|
453
455
|
default_ws_host: "127.0.0.1",
|
|
454
456
|
default_ws_port: 5321,
|
|
455
457
|
default_api_port: 5320,
|
|
458
|
+
default_python_api_port: 28302,
|
|
459
|
+
default_js_api_port: 28303,
|
|
456
460
|
default_server_host: "0.0.0.0",
|
|
457
461
|
cors_origins: [
|
|
458
462
|
"http://localhost:3000",
|
|
@@ -482,7 +486,8 @@ var init_app_config = __esm({
|
|
|
482
486
|
default_server_memory_db: "servermemory.db",
|
|
483
487
|
default_mcard_db: "mcard.db",
|
|
484
488
|
default_server_log_db: "server_log.db",
|
|
485
|
-
default_push_subscriptions_file: "subscriptions.json"
|
|
489
|
+
default_push_subscriptions_file: "subscriptions.json",
|
|
490
|
+
default_vcard_db_path: "data/vcard.db"
|
|
486
491
|
},
|
|
487
492
|
services: {
|
|
488
493
|
default_ollama_base_url: "http://localhost:11434",
|
|
@@ -522,7 +527,7 @@ var init_app_config = __esm({
|
|
|
522
527
|
});
|
|
523
528
|
|
|
524
529
|
// src/config/constants.ts
|
|
525
|
-
var network, identity, services, web, DEFAULT_PAGE_SIZE, MAX_FILE_SIZE, READ_TIMEOUT_MS, KNOWN_TYPE_SIZE_LIMIT, BINARY_CHECK_SAMPLE_SIZE, CONTENT_DETECTION_SAMPLE_SIZE, DEFAULT_MAX_PROBLEM_BYTES, INDEXEDDB_DEFAULT_DB_NAME, INDEXEDDB_DEFAULT_DB_VERSION, SQLITE_BUSY_TIMEOUT_MS, DEFAULT_IDENTITY_PROVIDER, DEFAULT_IDENTITY_SPACE_PATH, DEFAULT_API_PORT, DEFAULT_WS_PORT, DEFAULT_WS_HOST, DEFAULT_SERVER_HOST, CORS_ORIGINS, getEnvUrl, API_KEY_HEADER_NAME, DEFAULT_OLLAMA_BASE_URL, DEFAULT_OTLP_ENDPOINT, DEFAULT_VLLM_BASE_URL, DEFAULT_LMSTUDIO_BASE_URL, DEFAULT_SQLJS_WASM_URL, DEFAULT_SANDBOX_TIMEOUT_MS, DEFAULT_CLM_TIMEOUT_MS, DEFAULT_VM_EXECUTION_TIMEOUT_MS, LLM_DEFAULT_TIMEOUT_SECS, LLM_DEFAULT_RETRY_COUNT, LLM_DEFAULT_RETRY_DELAY_SECS;
|
|
530
|
+
var network, identity, services, web, DEFAULT_PAGE_SIZE, MAX_FILE_SIZE, READ_TIMEOUT_MS, KNOWN_TYPE_SIZE_LIMIT, BINARY_CHECK_SAMPLE_SIZE, CONTENT_DETECTION_SAMPLE_SIZE, DEFAULT_MAX_PROBLEM_BYTES, INDEXEDDB_DEFAULT_DB_NAME, INDEXEDDB_DEFAULT_DB_VERSION, SQLITE_BUSY_TIMEOUT_MS, DEFAULT_IDENTITY_PROVIDER, DEFAULT_IDENTITY_SPACE_PATH, DEFAULT_API_PORT, DEFAULT_PYTHON_API_PORT, DEFAULT_JS_API_PORT, DEFAULT_VCARD_DB_PATH, DEFAULT_WS_PORT, DEFAULT_WS_HOST, DEFAULT_SERVER_HOST, CORS_ORIGINS, getEnvUrl, API_KEY_HEADER_NAME, DEFAULT_OLLAMA_BASE_URL, DEFAULT_OTLP_ENDPOINT, DEFAULT_VLLM_BASE_URL, DEFAULT_LMSTUDIO_BASE_URL, DEFAULT_SQLJS_WASM_URL, DEFAULT_SANDBOX_TIMEOUT_MS, DEFAULT_CLM_TIMEOUT_MS, DEFAULT_VM_EXECUTION_TIMEOUT_MS, LLM_DEFAULT_TIMEOUT_SECS, LLM_DEFAULT_RETRY_COUNT, LLM_DEFAULT_RETRY_DELAY_SECS;
|
|
526
531
|
var init_constants = __esm({
|
|
527
532
|
"src/config/constants.ts"() {
|
|
528
533
|
"use strict";
|
|
@@ -544,6 +549,9 @@ var init_constants = __esm({
|
|
|
544
549
|
DEFAULT_IDENTITY_PROVIDER = String(identity.provider ?? "sqlite");
|
|
545
550
|
DEFAULT_IDENTITY_SPACE_PATH = String(identity.space_path ?? "./data/IDENTITY_SPACE.db");
|
|
546
551
|
DEFAULT_API_PORT = Number(network.default_api_port ?? 5320);
|
|
552
|
+
DEFAULT_PYTHON_API_PORT = Number(network.default_python_api_port ?? 28302);
|
|
553
|
+
DEFAULT_JS_API_PORT = Number(network.default_js_api_port ?? 28303);
|
|
554
|
+
DEFAULT_VCARD_DB_PATH = String(app_config_default.storage?.default_vcard_db_path ?? "./data/vcard.db");
|
|
547
555
|
DEFAULT_WS_PORT = Number(network.default_ws_port ?? 5321);
|
|
548
556
|
DEFAULT_WS_HOST = String(network.default_ws_host ?? "127.0.0.1");
|
|
549
557
|
DEFAULT_SERVER_HOST = String(network.default_server_host ?? "0.0.0.0");
|
|
@@ -2853,7 +2861,7 @@ var init_OllamaProvider = __esm({
|
|
|
2853
2861
|
},
|
|
2854
2862
|
timeout: this.timeout
|
|
2855
2863
|
};
|
|
2856
|
-
return new Promise((
|
|
2864
|
+
return new Promise((resolve11) => {
|
|
2857
2865
|
let payload;
|
|
2858
2866
|
if (data) {
|
|
2859
2867
|
payload = JSON.stringify(data);
|
|
@@ -2868,33 +2876,33 @@ var init_OllamaProvider = __esm({
|
|
|
2868
2876
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
2869
2877
|
try {
|
|
2870
2878
|
if (body.includes("\n") && !body.trim().startsWith("{")) {
|
|
2871
|
-
|
|
2879
|
+
resolve11(Either.right(JSON.parse(body)));
|
|
2872
2880
|
} else {
|
|
2873
|
-
|
|
2881
|
+
resolve11(Either.right(JSON.parse(body)));
|
|
2874
2882
|
}
|
|
2875
2883
|
} catch (e) {
|
|
2876
2884
|
const lines = body.trim().split("\n").filter((l) => l);
|
|
2877
2885
|
if (lines.length > 0) {
|
|
2878
2886
|
try {
|
|
2879
|
-
|
|
2887
|
+
resolve11(Either.right(JSON.parse(lines[lines.length - 1])));
|
|
2880
2888
|
} catch (parseErr) {
|
|
2881
|
-
|
|
2889
|
+
resolve11(Either.left(`Ollama response parse error: ${parseErr}`));
|
|
2882
2890
|
}
|
|
2883
2891
|
} else {
|
|
2884
|
-
|
|
2892
|
+
resolve11(Either.left(`Ollama response parse error: ${e}`));
|
|
2885
2893
|
}
|
|
2886
2894
|
}
|
|
2887
2895
|
} else {
|
|
2888
|
-
|
|
2896
|
+
resolve11(Either.left(`Ollama HTTP error ${res.statusCode}: ${body}`));
|
|
2889
2897
|
}
|
|
2890
2898
|
});
|
|
2891
2899
|
});
|
|
2892
2900
|
req.on("error", (e) => {
|
|
2893
|
-
|
|
2901
|
+
resolve11(Either.left(`Ollama connection error: ${e.message}`));
|
|
2894
2902
|
});
|
|
2895
2903
|
req.on("timeout", () => {
|
|
2896
2904
|
req.destroy();
|
|
2897
|
-
|
|
2905
|
+
resolve11(Either.left(`Ollama request timed out after ${this.timeout}ms`));
|
|
2898
2906
|
});
|
|
2899
2907
|
if (payload) {
|
|
2900
2908
|
req.write(payload);
|
|
@@ -3166,26 +3174,26 @@ var init_MLCLLMProvider = __esm({
|
|
|
3166
3174
|
headers: options.headers || {},
|
|
3167
3175
|
timeout: this.timeout
|
|
3168
3176
|
};
|
|
3169
|
-
return new Promise((
|
|
3177
|
+
return new Promise((resolve11) => {
|
|
3170
3178
|
const req = client.request(url, reqOptions, (res) => {
|
|
3171
3179
|
let body = "";
|
|
3172
3180
|
res.on("data", (chunk) => body += chunk);
|
|
3173
3181
|
res.on("end", () => {
|
|
3174
3182
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
3175
3183
|
try {
|
|
3176
|
-
|
|
3184
|
+
resolve11(Either.right(JSON.parse(body)));
|
|
3177
3185
|
} catch (e) {
|
|
3178
|
-
|
|
3186
|
+
resolve11(Either.left(`Parse error: ${e}`));
|
|
3179
3187
|
}
|
|
3180
3188
|
} else {
|
|
3181
|
-
|
|
3189
|
+
resolve11(Either.left(`HTTP Error ${res.statusCode}: ${body}`));
|
|
3182
3190
|
}
|
|
3183
3191
|
});
|
|
3184
3192
|
});
|
|
3185
|
-
req.on("error", (e) =>
|
|
3193
|
+
req.on("error", (e) => resolve11(Either.left(e.message)));
|
|
3186
3194
|
req.on("timeout", () => {
|
|
3187
3195
|
req.destroy();
|
|
3188
|
-
|
|
3196
|
+
resolve11(Either.left("Request timed out"));
|
|
3189
3197
|
});
|
|
3190
3198
|
if (options.body) {
|
|
3191
3199
|
req.write(options.body);
|
|
@@ -4090,7 +4098,7 @@ function normalize(collection, termHash, strategy = "normal", maxSteps = 1e3, ma
|
|
|
4090
4098
|
const startTime = Date.now();
|
|
4091
4099
|
let current = termHash;
|
|
4092
4100
|
let steps = 0;
|
|
4093
|
-
const
|
|
4101
|
+
const path16 = [termHash];
|
|
4094
4102
|
while (steps < maxSteps) {
|
|
4095
4103
|
if (maxTimeMs !== void 0 && Date.now() - startTime > maxTimeMs) {
|
|
4096
4104
|
return Either.left(
|
|
@@ -4102,11 +4110,11 @@ function normalize(collection, termHash, strategy = "normal", maxSteps = 1e3, ma
|
|
|
4102
4110
|
return Either.right({
|
|
4103
4111
|
normalForm: current,
|
|
4104
4112
|
steps,
|
|
4105
|
-
reductionPath:
|
|
4113
|
+
reductionPath: path16
|
|
4106
4114
|
});
|
|
4107
4115
|
}
|
|
4108
4116
|
current = stepResult.value;
|
|
4109
|
-
|
|
4117
|
+
path16.push(current);
|
|
4110
4118
|
steps++;
|
|
4111
4119
|
if (onStep) {
|
|
4112
4120
|
await onStep(steps, current);
|
|
@@ -4688,7 +4696,7 @@ var init_wasm = __esm({
|
|
|
4688
4696
|
async execute(wasmPath, context, config, chapterDir) {
|
|
4689
4697
|
const fullPath = path7.resolve(chapterDir, wasmPath);
|
|
4690
4698
|
const contextStr = typeof context === "string" ? context : JSON.stringify(context ?? {});
|
|
4691
|
-
return new Promise((
|
|
4699
|
+
return new Promise((resolve11, reject) => {
|
|
4692
4700
|
const proc = child_process3.spawn("wasmtime", [fullPath, contextStr]);
|
|
4693
4701
|
proc.stdin.end();
|
|
4694
4702
|
let stdout = "";
|
|
@@ -4711,16 +4719,16 @@ var init_wasm = __esm({
|
|
|
4711
4719
|
}
|
|
4712
4720
|
const out = stdout.trim();
|
|
4713
4721
|
if (!out) {
|
|
4714
|
-
return
|
|
4722
|
+
return resolve11(void 0);
|
|
4715
4723
|
}
|
|
4716
4724
|
const numeric = out.trim();
|
|
4717
4725
|
if (numeric && !Number.isNaN(Number(numeric))) {
|
|
4718
|
-
return
|
|
4726
|
+
return resolve11(Number(numeric));
|
|
4719
4727
|
}
|
|
4720
4728
|
try {
|
|
4721
|
-
return
|
|
4729
|
+
return resolve11(JSON.parse(out));
|
|
4722
4730
|
} catch {
|
|
4723
|
-
return
|
|
4731
|
+
return resolve11(out);
|
|
4724
4732
|
}
|
|
4725
4733
|
});
|
|
4726
4734
|
});
|
|
@@ -5090,14 +5098,14 @@ var init_P2PChatSession = __esm({
|
|
|
5090
5098
|
|
|
5091
5099
|
// src/ptr/node/SignalingServer.ts
|
|
5092
5100
|
function killProcessOnPort(port) {
|
|
5093
|
-
return new Promise((
|
|
5101
|
+
return new Promise((resolve11) => {
|
|
5094
5102
|
(0, import_child_process.exec)(`lsof -ti:${port} | xargs kill -9 2>/dev/null`, (error) => {
|
|
5095
5103
|
if (error) {
|
|
5096
5104
|
Logger2.info(`No existing process on port ${port} to kill`);
|
|
5097
5105
|
} else {
|
|
5098
5106
|
Logger2.info(`Killed existing process on port ${port}`);
|
|
5099
5107
|
}
|
|
5100
|
-
setTimeout(
|
|
5108
|
+
setTimeout(resolve11, NETWORK_SIGNALING_PORT_RELEASE_WAIT_MS);
|
|
5101
5109
|
});
|
|
5102
5110
|
});
|
|
5103
5111
|
}
|
|
@@ -5117,8 +5125,8 @@ async function createSignalingServer(config = {}) {
|
|
|
5117
5125
|
return;
|
|
5118
5126
|
}
|
|
5119
5127
|
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
|
5120
|
-
const
|
|
5121
|
-
if (req.method === "GET" &&
|
|
5128
|
+
const path16 = url.pathname;
|
|
5129
|
+
if (req.method === "GET" && path16 === "/health") {
|
|
5122
5130
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5123
5131
|
res.end(JSON.stringify({
|
|
5124
5132
|
status: "ok",
|
|
@@ -5127,7 +5135,7 @@ async function createSignalingServer(config = {}) {
|
|
|
5127
5135
|
}));
|
|
5128
5136
|
return;
|
|
5129
5137
|
}
|
|
5130
|
-
if (req.method === "GET" &&
|
|
5138
|
+
if (req.method === "GET" && path16 === "/signal") {
|
|
5131
5139
|
const peerId = url.searchParams.get("peer_id");
|
|
5132
5140
|
if (!peerId) {
|
|
5133
5141
|
res.writeHead(400);
|
|
@@ -5160,7 +5168,7 @@ async function createSignalingServer(config = {}) {
|
|
|
5160
5168
|
});
|
|
5161
5169
|
return;
|
|
5162
5170
|
}
|
|
5163
|
-
if (req.method === "POST" &&
|
|
5171
|
+
if (req.method === "POST" && path16 === "/signal") {
|
|
5164
5172
|
let body = "";
|
|
5165
5173
|
req.on("data", (chunk) => body += chunk);
|
|
5166
5174
|
req.on("end", () => {
|
|
@@ -5200,7 +5208,7 @@ async function createSignalingServer(config = {}) {
|
|
|
5200
5208
|
for (let attempt = 0; attempt < maxTries; attempt++) {
|
|
5201
5209
|
const port = startPort + attempt;
|
|
5202
5210
|
try {
|
|
5203
|
-
await new Promise((
|
|
5211
|
+
await new Promise((resolve11, reject) => {
|
|
5204
5212
|
server.once("error", (err) => {
|
|
5205
5213
|
if (err.code === "EADDRINUSE") {
|
|
5206
5214
|
reject(err);
|
|
@@ -5210,7 +5218,7 @@ async function createSignalingServer(config = {}) {
|
|
|
5210
5218
|
});
|
|
5211
5219
|
server.listen(port, () => {
|
|
5212
5220
|
server.removeAllListeners("error");
|
|
5213
|
-
|
|
5221
|
+
resolve11();
|
|
5214
5222
|
});
|
|
5215
5223
|
});
|
|
5216
5224
|
Logger2.info(`Server running on port ${port}`);
|
|
@@ -5226,11 +5234,11 @@ async function createSignalingServer(config = {}) {
|
|
|
5226
5234
|
Logger2.info(`Port ${port} in use, trying to kill existing process...`);
|
|
5227
5235
|
await killProcessOnPort(port);
|
|
5228
5236
|
try {
|
|
5229
|
-
await new Promise((
|
|
5237
|
+
await new Promise((resolve11, reject) => {
|
|
5230
5238
|
server.once("error", reject);
|
|
5231
5239
|
server.listen(port, () => {
|
|
5232
5240
|
server.removeAllListeners("error");
|
|
5233
|
-
|
|
5241
|
+
resolve11();
|
|
5234
5242
|
});
|
|
5235
5243
|
});
|
|
5236
5244
|
Logger2.info(`Server running on port ${port} (after kill)`);
|
|
@@ -5491,7 +5499,7 @@ var init_NetworkInfrastructure = __esm({
|
|
|
5491
5499
|
*/
|
|
5492
5500
|
async waitFor(domain) {
|
|
5493
5501
|
while (!this.check(domain)) {
|
|
5494
|
-
await new Promise((
|
|
5502
|
+
await new Promise((resolve11) => setTimeout(resolve11, RATE_LIMIT_WAIT_INTERVAL_MS));
|
|
5495
5503
|
}
|
|
5496
5504
|
}
|
|
5497
5505
|
};
|
|
@@ -5637,7 +5645,7 @@ var init_HttpClient = __esm({
|
|
|
5637
5645
|
retryConfig.max_delay
|
|
5638
5646
|
);
|
|
5639
5647
|
console.log(`[Network] Retry ${attempt}/${retryConfig.max_attempts} for ${url} (status: ${response.status}, delay: ${delay}ms)`);
|
|
5640
|
-
await new Promise((
|
|
5648
|
+
await new Promise((resolve11) => setTimeout(resolve11, delay));
|
|
5641
5649
|
continue;
|
|
5642
5650
|
}
|
|
5643
5651
|
}
|
|
@@ -5701,7 +5709,7 @@ var init_HttpClient = __esm({
|
|
|
5701
5709
|
retryConfig.max_delay
|
|
5702
5710
|
);
|
|
5703
5711
|
console.log(`[Network] Retry ${attempt}/${retryConfig.max_attempts} for ${url} (error: ${lastError.message}, delay: ${delay}ms)`);
|
|
5704
|
-
await new Promise((
|
|
5712
|
+
await new Promise((resolve11) => setTimeout(resolve11, delay));
|
|
5705
5713
|
continue;
|
|
5706
5714
|
}
|
|
5707
5715
|
}
|
|
@@ -5871,10 +5879,10 @@ var init_NetworkRuntime = __esm({
|
|
|
5871
5879
|
}
|
|
5872
5880
|
async handleListenHttp(config, context) {
|
|
5873
5881
|
const port = Number(this.interpolate(String(config.port || NETWORK_DEFAULT_LISTEN_PORT), context));
|
|
5874
|
-
const
|
|
5875
|
-
return new Promise((
|
|
5882
|
+
const path16 = this.interpolate(config.path || "/mcard", context);
|
|
5883
|
+
return new Promise((resolve11, reject) => {
|
|
5876
5884
|
const server = http3.createServer(async (req, res) => {
|
|
5877
|
-
if (req.method === "POST" && req.url ===
|
|
5885
|
+
if (req.method === "POST" && req.url === path16) {
|
|
5878
5886
|
const bodyChunks = [];
|
|
5879
5887
|
req.on("data", (chunk) => bodyChunks.push(chunk));
|
|
5880
5888
|
req.on("end", async () => {
|
|
@@ -5901,8 +5909,8 @@ var init_NetworkRuntime = __esm({
|
|
|
5901
5909
|
}
|
|
5902
5910
|
});
|
|
5903
5911
|
server.listen(port, () => {
|
|
5904
|
-
console.
|
|
5905
|
-
|
|
5912
|
+
console.info(`[Network] Listening on port ${port} at ${path16}`);
|
|
5913
|
+
resolve11({
|
|
5906
5914
|
success: true,
|
|
5907
5915
|
message: `Server started on port ${port}`
|
|
5908
5916
|
});
|
|
@@ -6030,9 +6038,9 @@ var init_NetworkRuntime = __esm({
|
|
|
6030
6038
|
const myPeerId = config.peer_id ? this.interpolate(config.peer_id, context) : `peer_${Date.now()}`;
|
|
6031
6039
|
const channelLabel = config.channel_label || "mcard-sync";
|
|
6032
6040
|
if (signalingUrl === "mock://p2p") {
|
|
6033
|
-
return new Promise((
|
|
6041
|
+
return new Promise((resolve11) => {
|
|
6034
6042
|
setTimeout(() => {
|
|
6035
|
-
|
|
6043
|
+
resolve11({
|
|
6036
6044
|
success: true,
|
|
6037
6045
|
peer_id: myPeerId,
|
|
6038
6046
|
channel: channelLabel,
|
|
@@ -6042,12 +6050,12 @@ var init_NetworkRuntime = __esm({
|
|
|
6042
6050
|
}, WEBRTC_DEFAULT_MOCK_DELAY_MS);
|
|
6043
6051
|
});
|
|
6044
6052
|
}
|
|
6045
|
-
console.
|
|
6053
|
+
console.info(`[WebRTC] Connecting to ${targetPeerId} via ${signalingUrl} as ${myPeerId}`);
|
|
6046
6054
|
const pc = new PeerConnection({
|
|
6047
6055
|
iceServers: config.ice_servers || [{ urls: "stun:stun.l.google.com:19302" }]
|
|
6048
6056
|
});
|
|
6049
6057
|
const dc = pc.createDataChannel(channelLabel);
|
|
6050
|
-
const connectionPromise = new Promise((
|
|
6058
|
+
const connectionPromise = new Promise((resolve11, reject) => {
|
|
6051
6059
|
const timeoutMs = config.timeout || WEBRTC_DEFAULT_TIMEOUT_MS;
|
|
6052
6060
|
const timeoutId = setTimeout(() => {
|
|
6053
6061
|
pc.close();
|
|
@@ -6055,12 +6063,12 @@ var init_NetworkRuntime = __esm({
|
|
|
6055
6063
|
}, timeoutMs);
|
|
6056
6064
|
dc.onopen = () => {
|
|
6057
6065
|
clearTimeout(timeoutId);
|
|
6058
|
-
console.
|
|
6066
|
+
console.info(`[WebRTC] Data channel '${channelLabel}' open`);
|
|
6059
6067
|
if (config.message) {
|
|
6060
6068
|
const msg = typeof config.message === "string" ? this.interpolate(config.message, context) : JSON.stringify(config.message);
|
|
6061
6069
|
dc.send(msg);
|
|
6062
6070
|
}
|
|
6063
|
-
|
|
6071
|
+
resolve11({
|
|
6064
6072
|
success: true,
|
|
6065
6073
|
peer_id: myPeerId,
|
|
6066
6074
|
channel: channelLabel,
|
|
@@ -6076,7 +6084,7 @@ var init_NetworkRuntime = __esm({
|
|
|
6076
6084
|
});
|
|
6077
6085
|
const offer = await pc.createOffer();
|
|
6078
6086
|
await pc.setLocalDescription(offer);
|
|
6079
|
-
console.
|
|
6087
|
+
console.info("[WebRTC] Local Offer created. SDP ready to send.");
|
|
6080
6088
|
if (config.await_response !== false) {
|
|
6081
6089
|
return connectionPromise;
|
|
6082
6090
|
}
|
|
@@ -6127,7 +6135,7 @@ var init_NetworkRuntime = __esm({
|
|
|
6127
6135
|
await this.collection.add(card);
|
|
6128
6136
|
added++;
|
|
6129
6137
|
}
|
|
6130
|
-
console.
|
|
6138
|
+
console.info(`[WebRTC] Synced ${added} cards from peer.`);
|
|
6131
6139
|
}
|
|
6132
6140
|
} catch (e) {
|
|
6133
6141
|
console.error("[WebRTC] Protocol error:", e);
|
|
@@ -6145,9 +6153,9 @@ var init_NetworkRuntime = __esm({
|
|
|
6145
6153
|
const signalingUrl = this.interpolate(config.signaling_url ?? "", context);
|
|
6146
6154
|
const myPeerId = config.peer_id ? this.interpolate(config.peer_id, context) : `listener_${Date.now()}`;
|
|
6147
6155
|
if (signalingUrl === "mock://p2p") {
|
|
6148
|
-
return new Promise((
|
|
6156
|
+
return new Promise((resolve11) => {
|
|
6149
6157
|
setTimeout(() => {
|
|
6150
|
-
|
|
6158
|
+
resolve11({
|
|
6151
6159
|
success: true,
|
|
6152
6160
|
peer_id: myPeerId,
|
|
6153
6161
|
status: "listening",
|
|
@@ -6170,7 +6178,7 @@ var init_NetworkRuntime = __esm({
|
|
|
6170
6178
|
}
|
|
6171
6179
|
const port = Number(this.interpolate(String(config.port || NETWORK_DEFAULT_LISTEN_PORT), context));
|
|
6172
6180
|
const basePath = this.interpolate(config.base_path || "/sync", context);
|
|
6173
|
-
return new Promise((
|
|
6181
|
+
return new Promise((resolve11, reject) => {
|
|
6174
6182
|
const server = http3.createServer(async (req, res) => {
|
|
6175
6183
|
const url = req.url || "";
|
|
6176
6184
|
const readBody = async () => {
|
|
@@ -6232,7 +6240,7 @@ var init_NetworkRuntime = __esm({
|
|
|
6232
6240
|
});
|
|
6233
6241
|
server.listen(port, () => {
|
|
6234
6242
|
console.log(`[Network] Sync listening on port ${port} at ${basePath}`);
|
|
6235
|
-
|
|
6243
|
+
resolve11({
|
|
6236
6244
|
success: true,
|
|
6237
6245
|
message: `Sync Server started on port ${port}`,
|
|
6238
6246
|
port,
|
|
@@ -6246,8 +6254,8 @@ var init_NetworkRuntime = __esm({
|
|
|
6246
6254
|
}
|
|
6247
6255
|
interpolate(text, context) {
|
|
6248
6256
|
if (!text || typeof text !== "string") return text;
|
|
6249
|
-
return text.replace(/\$\{([^}]+)\}/g, (_,
|
|
6250
|
-
const keys =
|
|
6257
|
+
return text.replace(/\$\{([^}]+)\}/g, (_, path16) => {
|
|
6258
|
+
const keys = path16.split(".");
|
|
6251
6259
|
let val = context;
|
|
6252
6260
|
for (const key of keys) {
|
|
6253
6261
|
if (val && typeof val === "object" && key in val) {
|
|
@@ -6549,11 +6557,11 @@ var init_NetworkRuntime = __esm({
|
|
|
6549
6557
|
message: "Background process started"
|
|
6550
6558
|
};
|
|
6551
6559
|
}
|
|
6552
|
-
return new Promise((
|
|
6560
|
+
return new Promise((resolve11, reject) => {
|
|
6553
6561
|
exec3(command, (error, stdout, stderr) => {
|
|
6554
6562
|
if (error) {
|
|
6555
6563
|
console.error(`[NetworkRuntime] Command failed: ${error.message}`);
|
|
6556
|
-
return
|
|
6564
|
+
return resolve11({
|
|
6557
6565
|
success: false,
|
|
6558
6566
|
error: error.message,
|
|
6559
6567
|
stderr
|
|
@@ -6561,7 +6569,7 @@ var init_NetworkRuntime = __esm({
|
|
|
6561
6569
|
}
|
|
6562
6570
|
console.log(`[NetworkRuntime] Command output:
|
|
6563
6571
|
${stdout}`);
|
|
6564
|
-
|
|
6572
|
+
resolve11({
|
|
6565
6573
|
success: true,
|
|
6566
6574
|
stdout,
|
|
6567
6575
|
stderr
|
|
@@ -7551,6 +7559,9 @@ __export(index_exports, {
|
|
|
7551
7559
|
MCard: () => MCard,
|
|
7552
7560
|
MCardStore: () => MCardStore,
|
|
7553
7561
|
Maybe: () => Maybe,
|
|
7562
|
+
PTREngine: () => PTREngine,
|
|
7563
|
+
PostconditionViolation: () => PostconditionViolation,
|
|
7564
|
+
PreconditionViolation: () => PreconditionViolation,
|
|
7554
7565
|
Reader: () => Reader,
|
|
7555
7566
|
SandboxWorker: () => SandboxWorker,
|
|
7556
7567
|
ServiceWorkerPTR: () => ServiceWorkerPTR,
|
|
@@ -8088,12 +8099,12 @@ var SandboxWorker = class {
|
|
|
8088
8099
|
* Send request and wait for response
|
|
8089
8100
|
*/
|
|
8090
8101
|
sendRequest(request) {
|
|
8091
|
-
return new Promise((
|
|
8102
|
+
return new Promise((resolve11, reject) => {
|
|
8092
8103
|
const timeout = setTimeout(() => {
|
|
8093
8104
|
this.pendingRequests.delete(request.id);
|
|
8094
8105
|
reject(new Error(`Request ${request.id} timed out`));
|
|
8095
8106
|
}, this.defaultTimeout);
|
|
8096
|
-
this.pendingRequests.set(request.id, { resolve:
|
|
8107
|
+
this.pendingRequests.set(request.id, { resolve: resolve11, reject, timeout });
|
|
8097
8108
|
this.worker.postMessage(request);
|
|
8098
8109
|
});
|
|
8099
8110
|
}
|
|
@@ -8154,6 +8165,32 @@ var VerificationStatus = /* @__PURE__ */ ((VerificationStatus2) => {
|
|
|
8154
8165
|
VerificationStatus2["SKIPPED"] = "skipped";
|
|
8155
8166
|
return VerificationStatus2;
|
|
8156
8167
|
})(VerificationStatus || {});
|
|
8168
|
+
var PreconditionViolation = class extends Error {
|
|
8169
|
+
pcardHash;
|
|
8170
|
+
inputHash;
|
|
8171
|
+
detail;
|
|
8172
|
+
constructor(pcardHash, inputHash, detail = "") {
|
|
8173
|
+
const msg = `PreconditionViolation: PCard ${pcardHash.substring(0, 16)} rejected input ${inputHash.substring(0, 16)}${detail ? ` \u2014 ${detail}` : ""}`;
|
|
8174
|
+
super(msg);
|
|
8175
|
+
this.name = "PreconditionViolation";
|
|
8176
|
+
this.pcardHash = pcardHash;
|
|
8177
|
+
this.inputHash = inputHash;
|
|
8178
|
+
this.detail = detail;
|
|
8179
|
+
}
|
|
8180
|
+
};
|
|
8181
|
+
var PostconditionViolation = class extends Error {
|
|
8182
|
+
pcardHash;
|
|
8183
|
+
outputRepr;
|
|
8184
|
+
detail;
|
|
8185
|
+
constructor(pcardHash, outputRepr, detail = "") {
|
|
8186
|
+
const msg = `PostconditionViolation: PCard ${pcardHash.substring(0, 16)} postcondition failed for output ${outputRepr.substring(0, 64)}${detail ? ` \u2014 ${detail}` : ""}`;
|
|
8187
|
+
super(msg);
|
|
8188
|
+
this.name = "PostconditionViolation";
|
|
8189
|
+
this.pcardHash = pcardHash;
|
|
8190
|
+
this.outputRepr = outputRepr;
|
|
8191
|
+
this.detail = detail;
|
|
8192
|
+
}
|
|
8193
|
+
};
|
|
8157
8194
|
|
|
8158
8195
|
// src/ptr/browser/storage/MCardStore.ts
|
|
8159
8196
|
var import_idb2 = require("idb");
|
|
@@ -8639,78 +8676,10 @@ init_LambdaRuntime();
|
|
|
8639
8676
|
// src/index.ts
|
|
8640
8677
|
init_LambdaRuntime();
|
|
8641
8678
|
|
|
8642
|
-
// src/ptr/node/
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
if (typeof a === "number" && typeof b === "number") {
|
|
8647
|
-
if (Number.isNaN(a) && Number.isNaN(b)) return true;
|
|
8648
|
-
if (!Number.isFinite(a) || !Number.isFinite(b)) return a === b;
|
|
8649
|
-
return Math.abs(a - b) <= tolerance * Math.max(1, Math.abs(a), Math.abs(b));
|
|
8650
|
-
}
|
|
8651
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
8652
|
-
if (a.length !== b.length) return false;
|
|
8653
|
-
return a.every((val, i) => resultsEqual(val, b[i], tolerance));
|
|
8654
|
-
}
|
|
8655
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
8656
|
-
const keysA = Object.keys(a);
|
|
8657
|
-
const keysB = Object.keys(b);
|
|
8658
|
-
if (keysA.length !== keysB.length) return false;
|
|
8659
|
-
return keysA.every(
|
|
8660
|
-
(key) => keysB.includes(key) && resultsEqual(a[key], b[key], tolerance)
|
|
8661
|
-
);
|
|
8662
|
-
}
|
|
8663
|
-
return a === b;
|
|
8664
|
-
}
|
|
8665
|
-
function asObject(input) {
|
|
8666
|
-
return typeof input === "object" && input !== null ? input : {};
|
|
8667
|
-
}
|
|
8668
|
-
function buildBaseContext(clm, input) {
|
|
8669
|
-
const inputObj = asObject(input);
|
|
8670
|
-
return {
|
|
8671
|
-
balanced: clm.clm.balanced,
|
|
8672
|
-
input_arguments: clm.clm.concrete?.input_arguments,
|
|
8673
|
-
output_arguments: clm.clm.concrete?.output_arguments,
|
|
8674
|
-
params: inputObj,
|
|
8675
|
-
...inputObj
|
|
8676
|
-
};
|
|
8677
|
-
}
|
|
8678
|
-
function buildExecutionResult(success, result, startTime, clm, error, boundary) {
|
|
8679
|
-
return {
|
|
8680
|
-
success,
|
|
8681
|
-
result,
|
|
8682
|
-
error,
|
|
8683
|
-
executionTime: Date.now() - startTime,
|
|
8684
|
-
clm: {
|
|
8685
|
-
chapter: clm.chapter?.title || "Unknown",
|
|
8686
|
-
concept: clm.clm.abstract?.concept || "Unknown",
|
|
8687
|
-
manifestation: clm.clm.concrete?.manifestation || "Unknown",
|
|
8688
|
-
boundary
|
|
8689
|
-
}
|
|
8690
|
-
};
|
|
8691
|
-
}
|
|
8692
|
-
function isRecursiveCLM(runtimeName) {
|
|
8693
|
-
return runtimeName.endsWith(".clm") || runtimeName.endsWith(".yaml") || runtimeName.endsWith(".yml");
|
|
8694
|
-
}
|
|
8695
|
-
function isMultiRuntime(clm) {
|
|
8696
|
-
const runtimesConfig = clm.clm?.concrete?.runtimes_config;
|
|
8697
|
-
return Array.isArray(runtimesConfig) && runtimesConfig.length > 0;
|
|
8698
|
-
}
|
|
8699
|
-
|
|
8700
|
-
// src/ptr/node/clm/runner.ts
|
|
8701
|
-
var path14 = __toESM(require("path"), 1);
|
|
8702
|
-
var yaml2 = __toESM(require("yaml"), 1);
|
|
8703
|
-
init_constants();
|
|
8704
|
-
|
|
8705
|
-
// src/ptr/node/runtimes/index.ts
|
|
8706
|
-
init_base();
|
|
8707
|
-
init_javascript();
|
|
8708
|
-
init_python();
|
|
8709
|
-
init_binary();
|
|
8710
|
-
init_wasm();
|
|
8711
|
-
init_lean();
|
|
8712
|
-
init_loader();
|
|
8713
|
-
init_factory();
|
|
8679
|
+
// src/ptr/node/PTREngine.ts
|
|
8680
|
+
var path15 = __toESM(require("path"), 1);
|
|
8681
|
+
var yaml3 = __toESM(require("yaml"), 1);
|
|
8682
|
+
init_MCard();
|
|
8714
8683
|
|
|
8715
8684
|
// src/model/PCard.ts
|
|
8716
8685
|
var import_yaml = require("yaml");
|
|
@@ -8910,8 +8879,8 @@ var PCard = class _PCard extends MCard {
|
|
|
8910
8879
|
}
|
|
8911
8880
|
}
|
|
8912
8881
|
};
|
|
8913
|
-
const { stringify:
|
|
8914
|
-
return _PCard.create(
|
|
8882
|
+
const { stringify: stringify3 } = await import("yaml");
|
|
8883
|
+
return _PCard.create(stringify3(newClm), this.hashFunction);
|
|
8915
8884
|
}
|
|
8916
8885
|
/**
|
|
8917
8886
|
* Tensor Product ($A \otimes B$)
|
|
@@ -8938,8 +8907,8 @@ var PCard = class _PCard extends MCard {
|
|
|
8938
8907
|
}
|
|
8939
8908
|
}
|
|
8940
8909
|
};
|
|
8941
|
-
const { stringify:
|
|
8942
|
-
return _PCard.create(
|
|
8910
|
+
const { stringify: stringify3 } = await import("yaml");
|
|
8911
|
+
return _PCard.create(stringify3(newClm), this.hashFunction);
|
|
8943
8912
|
}
|
|
8944
8913
|
/**
|
|
8945
8914
|
* Symmetry ($\sigma$)
|
|
@@ -8965,8 +8934,8 @@ var PCard = class _PCard extends MCard {
|
|
|
8965
8934
|
}
|
|
8966
8935
|
}
|
|
8967
8936
|
};
|
|
8968
|
-
const { stringify:
|
|
8969
|
-
return _PCard.create(
|
|
8937
|
+
const { stringify: stringify3 } = await import("yaml");
|
|
8938
|
+
return _PCard.create(stringify3(newClm), this.hashFunction);
|
|
8970
8939
|
}
|
|
8971
8940
|
// =========================================================================
|
|
8972
8941
|
// Universal Tooling Interface
|
|
@@ -9170,6 +9139,70 @@ var PCard = class _PCard extends MCard {
|
|
|
9170
9139
|
const runtimesConfig = config?.runtimes_config;
|
|
9171
9140
|
return Array.isArray(runtimesConfig) && runtimesConfig.length > 1;
|
|
9172
9141
|
}
|
|
9142
|
+
// =========================================================================
|
|
9143
|
+
// VCard Sandwich Boundary Spec Accessors
|
|
9144
|
+
// =========================================================================
|
|
9145
|
+
// Mirrors Python: PCard.get_pre_vcard_spec(), PCard.get_post_vcard_spec()
|
|
9146
|
+
// =========================================================================
|
|
9147
|
+
/**
|
|
9148
|
+
* Get precondition specification for VCard Sandwich evaluation.
|
|
9149
|
+
*
|
|
9150
|
+
* Extracts the precondition spec from abstract.preconditions,
|
|
9151
|
+
* classifying each condition by type.
|
|
9152
|
+
*
|
|
9153
|
+
* @returns Object with conditions array and classified conditions
|
|
9154
|
+
*/
|
|
9155
|
+
getPreVCardSpec() {
|
|
9156
|
+
const abstractSpec = this.abstract;
|
|
9157
|
+
const preconditions = abstractSpec?.preconditions || [];
|
|
9158
|
+
return {
|
|
9159
|
+
conditions: preconditions,
|
|
9160
|
+
classified: preconditions.map((c) => this.classifyCondition(c))
|
|
9161
|
+
};
|
|
9162
|
+
}
|
|
9163
|
+
/**
|
|
9164
|
+
* Get postcondition specification for VCard Sandwich evaluation.
|
|
9165
|
+
*
|
|
9166
|
+
* Extracts the postcondition spec from abstract.postconditions,
|
|
9167
|
+
* classifying each condition by type.
|
|
9168
|
+
*
|
|
9169
|
+
* @returns Object with conditions array and classified conditions
|
|
9170
|
+
*/
|
|
9171
|
+
getPostVCardSpec() {
|
|
9172
|
+
const abstractSpec = this.abstract;
|
|
9173
|
+
const postconditions = abstractSpec?.postconditions || [];
|
|
9174
|
+
return {
|
|
9175
|
+
conditions: postconditions,
|
|
9176
|
+
classified: postconditions.map((c) => this.classifyCondition(c))
|
|
9177
|
+
};
|
|
9178
|
+
}
|
|
9179
|
+
/**
|
|
9180
|
+
* Classify a condition by its type (function, schema, capability, declarative).
|
|
9181
|
+
*
|
|
9182
|
+
* @param condition - The condition to classify
|
|
9183
|
+
* @returns Object with type and the original condition
|
|
9184
|
+
*/
|
|
9185
|
+
classifyCondition(condition) {
|
|
9186
|
+
if (typeof condition === "string") {
|
|
9187
|
+
return { type: "declarative", condition };
|
|
9188
|
+
}
|
|
9189
|
+
if (typeof condition === "object" && condition !== null) {
|
|
9190
|
+
const cond = condition;
|
|
9191
|
+
if (typeof cond.function === "string" || typeof cond.callable === "string") {
|
|
9192
|
+
return { type: "function", condition };
|
|
9193
|
+
}
|
|
9194
|
+
if (cond.schema || cond.json_schema) {
|
|
9195
|
+
return { type: "schema", condition };
|
|
9196
|
+
}
|
|
9197
|
+
if (typeof cond.capability === "string") {
|
|
9198
|
+
return { type: "capability", condition };
|
|
9199
|
+
}
|
|
9200
|
+
if (cond.description) {
|
|
9201
|
+
return { type: "declarative", condition };
|
|
9202
|
+
}
|
|
9203
|
+
}
|
|
9204
|
+
return { type: "unknown", condition };
|
|
9205
|
+
}
|
|
9173
9206
|
};
|
|
9174
9207
|
|
|
9175
9208
|
// src/model/VCard.ts
|
|
@@ -9565,6 +9598,127 @@ var VCard = class _VCard extends MCard {
|
|
|
9565
9598
|
const myHandle = this.getTokenHandle();
|
|
9566
9599
|
return myHandle === requiredHandle;
|
|
9567
9600
|
}
|
|
9601
|
+
// =========================================================================
|
|
9602
|
+
// VCard Sandwich — Arrow Boundary Evaluation Pattern
|
|
9603
|
+
// =========================================================================
|
|
9604
|
+
//
|
|
9605
|
+
// These static methods implement the formal VCard Sandwich lifecycle:
|
|
9606
|
+
// V_pre → PCard(Evaluation Map) → V_post → Sandwich(V_pre, V_post)
|
|
9607
|
+
//
|
|
9608
|
+
// Mirrors Python: VCard.witness_precondition(), witness_postcondition(), sandwich()
|
|
9609
|
+
// =========================================================================
|
|
9610
|
+
/**
|
|
9611
|
+
* Witness Precondition (V_pre) — creates a VCard that witnesses
|
|
9612
|
+
* the input was accepted for evaluation.
|
|
9613
|
+
*
|
|
9614
|
+
* @param inputMCard - The input MCard being evaluated
|
|
9615
|
+
* @param hashAlgorithm - Hash algorithm to use
|
|
9616
|
+
* @returns VCard with type "precondition-witness"
|
|
9617
|
+
*/
|
|
9618
|
+
static async witnessPrecondition(inputMCard, hashAlgorithm = "sha256") {
|
|
9619
|
+
const structure = {
|
|
9620
|
+
vcard: {
|
|
9621
|
+
type: "precondition-witness",
|
|
9622
|
+
identity: {
|
|
9623
|
+
subject_did: "did:ptr:system",
|
|
9624
|
+
controller_pubkeys: []
|
|
9625
|
+
},
|
|
9626
|
+
verification: {
|
|
9627
|
+
input_hash: inputMCard.hash,
|
|
9628
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9629
|
+
witness_type: "precondition"
|
|
9630
|
+
},
|
|
9631
|
+
gatekeeper: { capabilities: [] },
|
|
9632
|
+
external_refs: []
|
|
9633
|
+
}
|
|
9634
|
+
};
|
|
9635
|
+
const contentString = JSON.stringify(structure, null, 2);
|
|
9636
|
+
const bytes = new TextEncoder().encode(contentString);
|
|
9637
|
+
const hash = await HashValidator.computeHash(bytes, hashAlgorithm);
|
|
9638
|
+
const g_time = GTime.stampNow(hashAlgorithm);
|
|
9639
|
+
const contentType = ContentTypeInterpreter.detect(bytes);
|
|
9640
|
+
return new _VCard(bytes, hash, g_time, contentType, hashAlgorithm, structure);
|
|
9641
|
+
}
|
|
9642
|
+
/**
|
|
9643
|
+
* Witness Postcondition (V_post) — creates a VCard that witnesses
|
|
9644
|
+
* the output was produced by a PCard evaluation.
|
|
9645
|
+
*
|
|
9646
|
+
* @param output - The execution output
|
|
9647
|
+
* @param pcardHash - Hash of the PCard that produced the output
|
|
9648
|
+
* @param hashAlgorithm - Hash algorithm to use
|
|
9649
|
+
* @returns VCard with type "postcondition-witness"
|
|
9650
|
+
*/
|
|
9651
|
+
static async witnessPostcondition(output, pcardHash, hashAlgorithm = "sha256") {
|
|
9652
|
+
let outputRepr;
|
|
9653
|
+
try {
|
|
9654
|
+
outputRepr = typeof output === "string" ? output : JSON.stringify(output);
|
|
9655
|
+
} catch {
|
|
9656
|
+
outputRepr = String(output);
|
|
9657
|
+
}
|
|
9658
|
+
const outputHash = await HashValidator.computeHash(
|
|
9659
|
+
new TextEncoder().encode(outputRepr),
|
|
9660
|
+
hashAlgorithm
|
|
9661
|
+
);
|
|
9662
|
+
const structure = {
|
|
9663
|
+
vcard: {
|
|
9664
|
+
type: "postcondition-witness",
|
|
9665
|
+
identity: {
|
|
9666
|
+
subject_did: "did:ptr:system",
|
|
9667
|
+
controller_pubkeys: []
|
|
9668
|
+
},
|
|
9669
|
+
verification: {
|
|
9670
|
+
output_hash: outputHash,
|
|
9671
|
+
pcard_hash: pcardHash || null,
|
|
9672
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9673
|
+
witness_type: "postcondition"
|
|
9674
|
+
},
|
|
9675
|
+
gatekeeper: { capabilities: [] },
|
|
9676
|
+
external_refs: []
|
|
9677
|
+
}
|
|
9678
|
+
};
|
|
9679
|
+
const contentString = JSON.stringify(structure, null, 2);
|
|
9680
|
+
const bytes = new TextEncoder().encode(contentString);
|
|
9681
|
+
const hash = await HashValidator.computeHash(bytes, hashAlgorithm);
|
|
9682
|
+
const g_time = GTime.stampNow(hashAlgorithm);
|
|
9683
|
+
const contentType = ContentTypeInterpreter.detect(bytes);
|
|
9684
|
+
return new _VCard(bytes, hash, g_time, contentType, hashAlgorithm, structure);
|
|
9685
|
+
}
|
|
9686
|
+
/**
|
|
9687
|
+
* Create a Sandwich Proof — combines V_pre and V_post into a
|
|
9688
|
+
* composite verification proof.
|
|
9689
|
+
*
|
|
9690
|
+
* @param vPre - Precondition witness VCard
|
|
9691
|
+
* @param vPost - Postcondition witness VCard
|
|
9692
|
+
* @param pcardHash - Hash of the PCard that was evaluated
|
|
9693
|
+
* @param hashAlgorithm - Hash algorithm to use
|
|
9694
|
+
* @returns VCard with type "verification-sandwich"
|
|
9695
|
+
*/
|
|
9696
|
+
static async sandwich(vPre, vPost, pcardHash, hashAlgorithm = "sha256") {
|
|
9697
|
+
const structure = {
|
|
9698
|
+
vcard: {
|
|
9699
|
+
type: "verification-sandwich",
|
|
9700
|
+
identity: {
|
|
9701
|
+
subject_did: "did:ptr:system",
|
|
9702
|
+
controller_pubkeys: []
|
|
9703
|
+
},
|
|
9704
|
+
verification: {
|
|
9705
|
+
v_pre_hash: vPre.hash,
|
|
9706
|
+
v_post_hash: vPost.hash,
|
|
9707
|
+
pcard_hash: pcardHash || null,
|
|
9708
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9709
|
+
witness_type: "sandwich"
|
|
9710
|
+
},
|
|
9711
|
+
gatekeeper: { capabilities: [] },
|
|
9712
|
+
external_refs: []
|
|
9713
|
+
}
|
|
9714
|
+
};
|
|
9715
|
+
const contentString = JSON.stringify(structure, null, 2);
|
|
9716
|
+
const bytes = new TextEncoder().encode(contentString);
|
|
9717
|
+
const hash = await HashValidator.computeHash(bytes, hashAlgorithm);
|
|
9718
|
+
const g_time = GTime.stampNow(hashAlgorithm);
|
|
9719
|
+
const contentType = ContentTypeInterpreter.detect(bytes);
|
|
9720
|
+
return new _VCard(bytes, hash, g_time, contentType, hashAlgorithm, structure);
|
|
9721
|
+
}
|
|
9568
9722
|
};
|
|
9569
9723
|
var VCardSimulation = class {
|
|
9570
9724
|
vcard;
|
|
@@ -9586,6 +9740,79 @@ var VCardSimulation = class {
|
|
|
9586
9740
|
}
|
|
9587
9741
|
};
|
|
9588
9742
|
|
|
9743
|
+
// src/ptr/node/clm/runner.ts
|
|
9744
|
+
var path14 = __toESM(require("path"), 1);
|
|
9745
|
+
var yaml2 = __toESM(require("yaml"), 1);
|
|
9746
|
+
init_constants();
|
|
9747
|
+
|
|
9748
|
+
// src/ptr/node/runtimes/index.ts
|
|
9749
|
+
init_base();
|
|
9750
|
+
init_javascript();
|
|
9751
|
+
init_python();
|
|
9752
|
+
init_binary();
|
|
9753
|
+
init_wasm();
|
|
9754
|
+
init_lean();
|
|
9755
|
+
init_loader();
|
|
9756
|
+
init_factory();
|
|
9757
|
+
|
|
9758
|
+
// src/ptr/node/clm/utils.ts
|
|
9759
|
+
function resultsEqual(a, b, tolerance = 1e-9) {
|
|
9760
|
+
if (a === b) return true;
|
|
9761
|
+
if (a == null || b == null) return false;
|
|
9762
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
9763
|
+
if (Number.isNaN(a) && Number.isNaN(b)) return true;
|
|
9764
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) return a === b;
|
|
9765
|
+
return Math.abs(a - b) <= tolerance * Math.max(1, Math.abs(a), Math.abs(b));
|
|
9766
|
+
}
|
|
9767
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9768
|
+
if (a.length !== b.length) return false;
|
|
9769
|
+
return a.every((val, i) => resultsEqual(val, b[i], tolerance));
|
|
9770
|
+
}
|
|
9771
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
9772
|
+
const keysA = Object.keys(a);
|
|
9773
|
+
const keysB = Object.keys(b);
|
|
9774
|
+
if (keysA.length !== keysB.length) return false;
|
|
9775
|
+
return keysA.every(
|
|
9776
|
+
(key) => keysB.includes(key) && resultsEqual(a[key], b[key], tolerance)
|
|
9777
|
+
);
|
|
9778
|
+
}
|
|
9779
|
+
return a === b;
|
|
9780
|
+
}
|
|
9781
|
+
function asObject(input) {
|
|
9782
|
+
return typeof input === "object" && input !== null ? input : {};
|
|
9783
|
+
}
|
|
9784
|
+
function buildBaseContext(clm, input) {
|
|
9785
|
+
const inputObj = asObject(input);
|
|
9786
|
+
return {
|
|
9787
|
+
balanced: clm.clm.balanced,
|
|
9788
|
+
input_arguments: clm.clm.concrete?.input_arguments,
|
|
9789
|
+
output_arguments: clm.clm.concrete?.output_arguments,
|
|
9790
|
+
params: inputObj,
|
|
9791
|
+
...inputObj
|
|
9792
|
+
};
|
|
9793
|
+
}
|
|
9794
|
+
function buildExecutionResult(success, result, startTime, clm, error, boundary) {
|
|
9795
|
+
return {
|
|
9796
|
+
success,
|
|
9797
|
+
result,
|
|
9798
|
+
error,
|
|
9799
|
+
executionTime: Date.now() - startTime,
|
|
9800
|
+
clm: {
|
|
9801
|
+
chapter: clm.chapter?.title || "Unknown",
|
|
9802
|
+
concept: clm.clm.abstract?.concept || "Unknown",
|
|
9803
|
+
manifestation: clm.clm.concrete?.manifestation || "Unknown",
|
|
9804
|
+
boundary
|
|
9805
|
+
}
|
|
9806
|
+
};
|
|
9807
|
+
}
|
|
9808
|
+
function isRecursiveCLM(runtimeName) {
|
|
9809
|
+
return runtimeName.endsWith(".clm") || runtimeName.endsWith(".yaml") || runtimeName.endsWith(".yml");
|
|
9810
|
+
}
|
|
9811
|
+
function isMultiRuntime(clm) {
|
|
9812
|
+
const runtimesConfig = clm.clm?.concrete?.runtimes_config;
|
|
9813
|
+
return Array.isArray(runtimesConfig) && runtimesConfig.length > 0;
|
|
9814
|
+
}
|
|
9815
|
+
|
|
9589
9816
|
// src/ptr/node/core/operations/index.ts
|
|
9590
9817
|
var NETWORK_BUILTINS = /* @__PURE__ */ new Set([
|
|
9591
9818
|
"http_get",
|
|
@@ -9933,7 +10160,7 @@ setInterval(() => {}, 1000);
|
|
|
9933
10160
|
});
|
|
9934
10161
|
child.unref();
|
|
9935
10162
|
fs8.writeFileSync(pidFile, String(child.pid));
|
|
9936
|
-
await new Promise((
|
|
10163
|
+
await new Promise((resolve11) => setTimeout(resolve11, STATIC_SERVER_START_WAIT_MS));
|
|
9937
10164
|
if (isPortInUse(port)) {
|
|
9938
10165
|
return {
|
|
9939
10166
|
success: true,
|
|
@@ -9986,10 +10213,10 @@ setInterval(() => {}, 1000);
|
|
|
9986
10213
|
}
|
|
9987
10214
|
try {
|
|
9988
10215
|
process.kill(pid, "SIGTERM");
|
|
9989
|
-
await new Promise((
|
|
10216
|
+
await new Promise((resolve11) => setTimeout(resolve11, PROCESS_TERMINATE_WAIT_MS));
|
|
9990
10217
|
if (isPortInUse(port)) {
|
|
9991
10218
|
process.kill(pid, "SIGKILL");
|
|
9992
|
-
await new Promise((
|
|
10219
|
+
await new Promise((resolve11) => setTimeout(resolve11, PROCESS_TERMINATE_WAIT_MS));
|
|
9993
10220
|
}
|
|
9994
10221
|
if (fs8.existsSync(pidFile)) {
|
|
9995
10222
|
fs8.unlinkSync(pidFile);
|
|
@@ -10132,7 +10359,7 @@ Process exited with code ${code}
|
|
|
10132
10359
|
} catch {
|
|
10133
10360
|
}
|
|
10134
10361
|
fs9.writeFileSync(pidFile, String(child.pid));
|
|
10135
|
-
await new Promise((
|
|
10362
|
+
await new Promise((resolve11) => setTimeout(resolve11, WEBSOCKET_SERVER_START_WAIT_MS));
|
|
10136
10363
|
if (isPortInUse2(port)) {
|
|
10137
10364
|
console.log(`[WebSocket Server] Successfully started on port ${port}`);
|
|
10138
10365
|
return {
|
|
@@ -10196,10 +10423,10 @@ Process exited with code ${code}
|
|
|
10196
10423
|
}
|
|
10197
10424
|
try {
|
|
10198
10425
|
process.kill(pid, "SIGTERM");
|
|
10199
|
-
await new Promise((
|
|
10426
|
+
await new Promise((resolve11) => setTimeout(resolve11, PROCESS_TERMINATE_WAIT_MS));
|
|
10200
10427
|
if (isPortInUse2(port)) {
|
|
10201
10428
|
process.kill(pid, "SIGKILL");
|
|
10202
|
-
await new Promise((
|
|
10429
|
+
await new Promise((resolve11) => setTimeout(resolve11, PROCESS_TERMINATE_WAIT_MS));
|
|
10203
10430
|
}
|
|
10204
10431
|
if (fs9.existsSync(pidFile)) {
|
|
10205
10432
|
fs9.unlinkSync(pidFile);
|
|
@@ -10528,10 +10755,12 @@ var CLMRunner = class _CLMRunner {
|
|
|
10528
10755
|
loader;
|
|
10529
10756
|
timeout;
|
|
10530
10757
|
collection;
|
|
10531
|
-
|
|
10758
|
+
privateCollection;
|
|
10759
|
+
constructor(basePath = process.cwd(), timeout = DEFAULT_CLM_TIMEOUT_MS, collection, privateCollection) {
|
|
10532
10760
|
this.loader = new CLMLoader(basePath);
|
|
10533
10761
|
this.timeout = timeout;
|
|
10534
10762
|
this.collection = collection;
|
|
10763
|
+
this.privateCollection = privateCollection;
|
|
10535
10764
|
}
|
|
10536
10765
|
/**
|
|
10537
10766
|
* Run a CLM directly from a file path.
|
|
@@ -10642,7 +10871,8 @@ var CLMRunner = class _CLMRunner {
|
|
|
10642
10871
|
previousVCard,
|
|
10643
10872
|
result.success
|
|
10644
10873
|
);
|
|
10645
|
-
|
|
10874
|
+
const storageTarget = this.privateCollection || this.collection;
|
|
10875
|
+
await storageTarget.add(vcard);
|
|
10646
10876
|
result.petriNet = {
|
|
10647
10877
|
pcardHash: pcard.hash,
|
|
10648
10878
|
vcardHash: vcard.hash,
|
|
@@ -10918,6 +11148,250 @@ var CLMRunner = class _CLMRunner {
|
|
|
10918
11148
|
}
|
|
10919
11149
|
};
|
|
10920
11150
|
|
|
11151
|
+
// src/ptr/node/PTREngine.ts
|
|
11152
|
+
var PTREngine = class {
|
|
11153
|
+
collection;
|
|
11154
|
+
executionLog;
|
|
11155
|
+
runner;
|
|
11156
|
+
/**
|
|
11157
|
+
* Initialize PTREngine.
|
|
11158
|
+
*
|
|
11159
|
+
* @param storageCollection - MCard collection for long-term knowledge (mcard_collection.db)
|
|
11160
|
+
* @param executionLogCollection - MCard collection for execution traces (execution_log.db).
|
|
11161
|
+
* If not provided, traces are written to storageCollection.
|
|
11162
|
+
* @param options - Additional configuration
|
|
11163
|
+
*/
|
|
11164
|
+
constructor(storageCollection, executionLogCollection, options) {
|
|
11165
|
+
this.collection = storageCollection;
|
|
11166
|
+
this.executionLog = executionLogCollection || this.collection;
|
|
11167
|
+
this.runner = new CLMRunner(
|
|
11168
|
+
options?.basePath || process.cwd(),
|
|
11169
|
+
options?.timeout,
|
|
11170
|
+
this.collection,
|
|
11171
|
+
this.executionLog
|
|
11172
|
+
);
|
|
11173
|
+
}
|
|
11174
|
+
// =========================================================================
|
|
11175
|
+
// ARROW INTERFACE — The canonical PTR execution primitives
|
|
11176
|
+
// =========================================================================
|
|
11177
|
+
/**
|
|
11178
|
+
* The Arrow execution primitive — the entire PTR in one method.
|
|
11179
|
+
*
|
|
11180
|
+
* Implements the VCard Sandwich lifecycle:
|
|
11181
|
+
* V_pre → PCard(Evaluation Map) → V_post
|
|
11182
|
+
*
|
|
11183
|
+
* @param pcardHash - Hash of the PCard to execute
|
|
11184
|
+
* @param inputHash - Hash of the input MCard
|
|
11185
|
+
* @param preCheck - Optional callable to validate preconditions on input
|
|
11186
|
+
* @param postCheck - Optional callable to validate postconditions on output
|
|
11187
|
+
* @returns Tuple of [execution_output, vcard_sandwich]
|
|
11188
|
+
* @throws PreconditionViolation if preCheck returns false
|
|
11189
|
+
* @throws PostconditionViolation if postCheck returns false
|
|
11190
|
+
*/
|
|
11191
|
+
async runWithSandwich(pcardHash, inputHash, preCheck, postCheck) {
|
|
11192
|
+
const pcard = await this.collection.get(pcardHash);
|
|
11193
|
+
if (!pcard) throw new Error(`PCard not found: ${pcardHash}`);
|
|
11194
|
+
const inputMCard = await this.collection.get(inputHash);
|
|
11195
|
+
if (!inputMCard) throw new Error(`Input MCard not found: ${inputHash}`);
|
|
11196
|
+
if (preCheck && !preCheck(inputMCard)) {
|
|
11197
|
+
throw new PreconditionViolation(pcardHash, inputHash);
|
|
11198
|
+
}
|
|
11199
|
+
const vPre = await VCard.witnessPrecondition(inputMCard);
|
|
11200
|
+
const pcardObj = await PCard.create(
|
|
11201
|
+
new TextDecoder().decode(pcard.content)
|
|
11202
|
+
);
|
|
11203
|
+
const clmSpec = {
|
|
11204
|
+
chapter: { id: "runtime", title: "Runtime Execution" },
|
|
11205
|
+
clm: pcardObj.clm
|
|
11206
|
+
};
|
|
11207
|
+
const result = await this.runner.executeCLM(
|
|
11208
|
+
clmSpec,
|
|
11209
|
+
process.cwd(),
|
|
11210
|
+
inputMCard.getContentAsText()
|
|
11211
|
+
);
|
|
11212
|
+
const output = result.result;
|
|
11213
|
+
if (postCheck && !postCheck(output)) {
|
|
11214
|
+
throw new PostconditionViolation(
|
|
11215
|
+
pcardHash,
|
|
11216
|
+
typeof output === "string" ? output.substring(0, 64) : JSON.stringify(output).substring(0, 64)
|
|
11217
|
+
);
|
|
11218
|
+
}
|
|
11219
|
+
const vPost = await VCard.witnessPostcondition(output, pcardHash);
|
|
11220
|
+
const sandwich = await VCard.sandwich(vPre, vPost, pcardHash);
|
|
11221
|
+
await this.recordToExecutionLog(sandwich);
|
|
11222
|
+
return [output, sandwich];
|
|
11223
|
+
}
|
|
11224
|
+
/**
|
|
11225
|
+
* Execute a CLM specification from a YAML file.
|
|
11226
|
+
*
|
|
11227
|
+
* Absorbs CLMRunner.runFile(), routing all file-based execution
|
|
11228
|
+
* through the formal PTREngine lifecycle with VCard Sandwich generation.
|
|
11229
|
+
*
|
|
11230
|
+
* @param filePath - Path to the YAML file
|
|
11231
|
+
* @param context - Execution context (inputs)
|
|
11232
|
+
* @returns Execution report with VCard Sandwich proof hashes
|
|
11233
|
+
*/
|
|
11234
|
+
async runFile(filePath, context) {
|
|
11235
|
+
const loader = new CLMLoader(path15.dirname(filePath));
|
|
11236
|
+
const clm = loader.load(filePath);
|
|
11237
|
+
const chapterDir = path15.dirname(path15.resolve(filePath));
|
|
11238
|
+
const clmContent = yaml3.stringify(clm);
|
|
11239
|
+
const pcard = await PCard.create(clmContent);
|
|
11240
|
+
if (this.collection) {
|
|
11241
|
+
await this.collection.add(pcard);
|
|
11242
|
+
}
|
|
11243
|
+
const inputMCard = await MCard.create(JSON.stringify(context || {}));
|
|
11244
|
+
const vPre = await VCard.witnessPrecondition(inputMCard);
|
|
11245
|
+
const result = await this.runner.executeCLM(clm, chapterDir, context || {});
|
|
11246
|
+
const vPost = await VCard.witnessPostcondition(result.result, pcard.hash);
|
|
11247
|
+
const sandwich = await VCard.sandwich(vPre, vPost, pcard.hash);
|
|
11248
|
+
let eventRecordHash = null;
|
|
11249
|
+
try {
|
|
11250
|
+
if (this.executionLog) {
|
|
11251
|
+
await this.executionLog.add(sandwich);
|
|
11252
|
+
eventRecordHash = sandwich.hash;
|
|
11253
|
+
}
|
|
11254
|
+
} catch (e) {
|
|
11255
|
+
console.warn(`[PTREngine] Failed to store VCard Sandwich: ${e}`);
|
|
11256
|
+
}
|
|
11257
|
+
return {
|
|
11258
|
+
status: result.success ? "success" : "failure",
|
|
11259
|
+
result: result.result,
|
|
11260
|
+
error: result.error,
|
|
11261
|
+
chapter_id: clm.chapter?.id,
|
|
11262
|
+
chapter_title: clm.chapter?.title,
|
|
11263
|
+
event_record_hash: eventRecordHash,
|
|
11264
|
+
v_pre_hash: vPre.hash,
|
|
11265
|
+
v_post_hash: vPost.hash,
|
|
11266
|
+
sandwich_hash: sandwich.hash
|
|
11267
|
+
};
|
|
11268
|
+
}
|
|
11269
|
+
/**
|
|
11270
|
+
* Arrow `arr` — lift a pure function into a PCard.
|
|
11271
|
+
*
|
|
11272
|
+
* Creates a PCard whose Concrete implementation is the given function.
|
|
11273
|
+
*
|
|
11274
|
+
* @param func - A pure function from string to string
|
|
11275
|
+
* @param name - Human-readable name for the PCard
|
|
11276
|
+
* @returns The created PCard (stored in collection)
|
|
11277
|
+
*/
|
|
11278
|
+
async arr(func, name = "lifted") {
|
|
11279
|
+
const funcSource = func.toString();
|
|
11280
|
+
const clmYaml = yaml3.stringify({
|
|
11281
|
+
chapter: { id: `arr_${name}`, title: `Lifted: ${name}` },
|
|
11282
|
+
clm: {
|
|
11283
|
+
abstract: {
|
|
11284
|
+
purpose: `Lifted pure function: ${name}`,
|
|
11285
|
+
inputs: { input: "any" },
|
|
11286
|
+
outputs: { result: "any" },
|
|
11287
|
+
preconditions: [],
|
|
11288
|
+
postconditions: []
|
|
11289
|
+
},
|
|
11290
|
+
concrete: {
|
|
11291
|
+
runtime: "javascript",
|
|
11292
|
+
operation: `lifted_${name}`,
|
|
11293
|
+
code: funcSource
|
|
11294
|
+
},
|
|
11295
|
+
balanced: { test_cases: [], expectations: {} }
|
|
11296
|
+
}
|
|
11297
|
+
});
|
|
11298
|
+
const pcard = await PCard.create(clmYaml);
|
|
11299
|
+
if (this.collection) {
|
|
11300
|
+
await this.collection.add(pcard);
|
|
11301
|
+
}
|
|
11302
|
+
return pcard;
|
|
11303
|
+
}
|
|
11304
|
+
/**
|
|
11305
|
+
* Arrow `>>>` — sequential composition of two PCards.
|
|
11306
|
+
*
|
|
11307
|
+
* Creates a new PCard representing pcardA >>> pcardB,
|
|
11308
|
+
* where the output of A feeds into the input of B.
|
|
11309
|
+
*
|
|
11310
|
+
* @param pcardAHash - Hash of the first PCard (executed first)
|
|
11311
|
+
* @param pcardBHash - Hash of the second PCard (executed second)
|
|
11312
|
+
* @returns The composed PCard (stored in collection)
|
|
11313
|
+
*/
|
|
11314
|
+
async compose(pcardAHash, pcardBHash) {
|
|
11315
|
+
const clmYaml = yaml3.stringify({
|
|
11316
|
+
chapter: {
|
|
11317
|
+
id: `compose_${pcardAHash.substring(0, 8)}_${pcardBHash.substring(0, 8)}`,
|
|
11318
|
+
title: "Sequential Composition (Arrow >>>)"
|
|
11319
|
+
},
|
|
11320
|
+
clm: {
|
|
11321
|
+
abstract: {
|
|
11322
|
+
type: "sequential_composition",
|
|
11323
|
+
purpose: `Compose ${pcardAHash.substring(0, 16)} >>> ${pcardBHash.substring(0, 16)}`,
|
|
11324
|
+
inputs: { input: "any" },
|
|
11325
|
+
outputs: { result: "any" },
|
|
11326
|
+
preconditions: [],
|
|
11327
|
+
postconditions: []
|
|
11328
|
+
},
|
|
11329
|
+
concrete: {
|
|
11330
|
+
runtime: "ptr",
|
|
11331
|
+
operation: "compose_sequential",
|
|
11332
|
+
steps: [pcardAHash, pcardBHash]
|
|
11333
|
+
},
|
|
11334
|
+
balanced: { test_cases: [], expectations: {} }
|
|
11335
|
+
}
|
|
11336
|
+
});
|
|
11337
|
+
const pcard = await PCard.create(clmYaml);
|
|
11338
|
+
if (this.collection) {
|
|
11339
|
+
await this.collection.add(pcard);
|
|
11340
|
+
}
|
|
11341
|
+
return pcard;
|
|
11342
|
+
}
|
|
11343
|
+
/**
|
|
11344
|
+
* Arrow `first` — operate on first element of a product.
|
|
11345
|
+
*
|
|
11346
|
+
* Creates a new PCard that applies the original PCard to the
|
|
11347
|
+
* first element of a (A, C) pair while preserving C.
|
|
11348
|
+
*
|
|
11349
|
+
* @param pcardHash - Hash of the PCard to lift
|
|
11350
|
+
* @returns The first-lifted PCard (stored in collection)
|
|
11351
|
+
*/
|
|
11352
|
+
async first(pcardHash) {
|
|
11353
|
+
const clmYaml = yaml3.stringify({
|
|
11354
|
+
chapter: {
|
|
11355
|
+
id: `first_${pcardHash.substring(0, 8)}`,
|
|
11356
|
+
title: "Arrow First (Product Preservation)"
|
|
11357
|
+
},
|
|
11358
|
+
clm: {
|
|
11359
|
+
abstract: {
|
|
11360
|
+
type: "arrow_first",
|
|
11361
|
+
purpose: `Apply ${pcardHash.substring(0, 16)} to first element, preserve second`,
|
|
11362
|
+
inputs: { pair: "(A, C)" },
|
|
11363
|
+
outputs: { result: "(B, C)" },
|
|
11364
|
+
preconditions: [],
|
|
11365
|
+
postconditions: []
|
|
11366
|
+
},
|
|
11367
|
+
concrete: {
|
|
11368
|
+
runtime: "ptr",
|
|
11369
|
+
operation: "apply_first",
|
|
11370
|
+
target: pcardHash
|
|
11371
|
+
},
|
|
11372
|
+
balanced: { test_cases: [], expectations: {} }
|
|
11373
|
+
}
|
|
11374
|
+
});
|
|
11375
|
+
const pcard = await PCard.create(clmYaml);
|
|
11376
|
+
if (this.collection) {
|
|
11377
|
+
await this.collection.add(pcard);
|
|
11378
|
+
}
|
|
11379
|
+
return pcard;
|
|
11380
|
+
}
|
|
11381
|
+
// =========================================================================
|
|
11382
|
+
// Private Helpers
|
|
11383
|
+
// =========================================================================
|
|
11384
|
+
async recordToExecutionLog(sandwich) {
|
|
11385
|
+
try {
|
|
11386
|
+
if (this.executionLog) {
|
|
11387
|
+
await this.executionLog.add(sandwich);
|
|
11388
|
+
}
|
|
11389
|
+
} catch (e) {
|
|
11390
|
+
console.warn(`[PTREngine] Failed to record to execution log: ${e}`);
|
|
11391
|
+
}
|
|
11392
|
+
}
|
|
11393
|
+
};
|
|
11394
|
+
|
|
10921
11395
|
// src/model/hash/algorithms/LocalSHA256.ts
|
|
10922
11396
|
async function computeHash(content) {
|
|
10923
11397
|
let contentStr;
|
|
@@ -11155,6 +11629,9 @@ var validationRegistry = new ValidationRegistry();
|
|
|
11155
11629
|
MCard,
|
|
11156
11630
|
MCardStore,
|
|
11157
11631
|
Maybe,
|
|
11632
|
+
PTREngine,
|
|
11633
|
+
PostconditionViolation,
|
|
11634
|
+
PreconditionViolation,
|
|
11158
11635
|
Reader,
|
|
11159
11636
|
SandboxWorker,
|
|
11160
11637
|
ServiceWorkerPTR,
|