@ibgib/core-gib 0.1.48 → 0.1.50

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 (94) hide show
  1. package/dist/common/comment/comment-constants.d.mts +5 -0
  2. package/dist/common/comment/comment-constants.d.mts.map +1 -1
  3. package/dist/common/comment/comment-constants.mjs +5 -0
  4. package/dist/common/comment/comment-constants.mjs.map +1 -1
  5. package/dist/common/comment/comment-helper.d.mts +9 -1
  6. package/dist/common/comment/comment-helper.d.mts.map +1 -1
  7. package/dist/common/comment/comment-helper.mjs +7 -5
  8. package/dist/common/comment/comment-helper.mjs.map +1 -1
  9. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs +1 -1
  10. package/dist/sync/sync-conflict-adv-multitimelines.respec.mjs.map +1 -1
  11. package/dist/sync/sync-conflict-basic-divergence.respec.mjs +1 -1
  12. package/dist/sync/sync-conflict-basic-divergence.respec.mjs.map +1 -1
  13. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs +1 -1
  14. package/dist/sync/sync-conflict-basic-multitimelines.respec.mjs.map +1 -1
  15. package/dist/sync/sync-conflict-text-merge.respec.mjs +1 -1
  16. package/dist/sync/sync-conflict-text-merge.respec.mjs.map +1 -1
  17. package/dist/sync/sync-innerspace-constants.respec.mjs +1 -1
  18. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  19. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +1 -1
  20. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  21. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs +13 -13
  22. package/dist/sync/sync-innerspace-dest-ahead-withid.respec.mjs.map +1 -1
  23. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +1 -1
  24. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  25. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +1 -1
  26. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  27. package/dist/sync/sync-innerspace-partial-update.respec.mjs +1 -1
  28. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  29. package/dist/sync/sync-innerspace.respec.mjs +1 -1
  30. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  31. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.d.mts +57 -0
  32. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.d.mts.map +1 -0
  33. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs +310 -0
  34. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mjs.map +1 -0
  35. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts +27 -0
  36. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.d.mts.map +1 -0
  37. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mjs +2 -0
  38. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mjs.map +1 -0
  39. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts +29 -0
  40. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts.map +1 -0
  41. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs +122 -0
  42. package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs.map +1 -0
  43. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts +27 -0
  44. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.d.mts.map +1 -0
  45. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mjs +2 -0
  46. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mjs.map +1 -0
  47. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts +24 -0
  48. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.d.mts.map +1 -0
  49. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs +111 -0
  50. package/dist/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mjs.map +1 -0
  51. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts +8 -0
  52. package/dist/sync/sync-peer/sync-peer-http.respec.d.mts.map +1 -0
  53. package/dist/sync/sync-peer/sync-peer-http.respec.mjs +333 -0
  54. package/dist/sync/sync-peer/sync-peer-http.respec.mjs.map +1 -0
  55. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  56. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +8 -7
  57. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  58. package/dist/sync/sync-peer/sync-peer-types.d.mts +5 -5
  59. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
  60. package/dist/sync/sync-peer/sync-peer-v1.d.mts +0 -2
  61. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  62. package/dist/sync/sync-peer/sync-peer-v1.mjs +21 -5
  63. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  64. package/dist/sync/sync-saga-coordinator.mjs +1 -1
  65. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  66. package/ibgib-foundations.md +109 -89
  67. package/package.json +1 -1
  68. package/src/common/comment/comment-constants.mts +6 -0
  69. package/src/common/comment/comment-helper.mts +13 -4
  70. package/src/sync/sync-conflict-adv-multitimelines.respec.mts +1 -1
  71. package/src/sync/sync-conflict-basic-divergence.respec.mts +1 -1
  72. package/src/sync/sync-conflict-basic-multitimelines.respec.mts +1 -1
  73. package/src/sync/sync-conflict-text-merge.respec.mts +1 -1
  74. package/src/sync/sync-innerspace-constants.respec.mts +1 -1
  75. package/src/sync/sync-innerspace-deep-updates.respec.mts +1 -1
  76. package/src/sync/sync-innerspace-dest-ahead-withid.respec.mts +12 -12
  77. package/src/sync/sync-innerspace-dest-ahead.respec.mts +1 -1
  78. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +1 -1
  79. package/src/sync/sync-innerspace-partial-update.respec.mts +1 -1
  80. package/src/sync/sync-innerspace.respec.mts +1 -1
  81. package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts +319 -0
  82. package/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts.metadata.md +72 -0
  83. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-types.mts +30 -0
  84. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +146 -0
  85. package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts.metadata.md +71 -0
  86. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-types.mts +32 -0
  87. package/src/sync/sync-peer/sync-peer-http-sender/sync-peer-http-sender-v1.mts +129 -0
  88. package/src/sync/sync-peer/sync-peer-http.respec.mts +364 -0
  89. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +8 -8
  90. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +10 -7
  91. package/src/sync/sync-peer/sync-peer-types.mts +11 -11
  92. package/src/sync/sync-peer/sync-peer-v1.mts +5 -7
  93. package/src/sync/sync-saga-coordinator.mts +1 -1
  94. package/tmp-certs/server.pfx +0 -0
@@ -0,0 +1,319 @@
1
+ import * as http2 from 'http2';
2
+
3
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
4
+
5
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
6
+ import { SyncPeerHttpReceiver_V1 } from './sync-peer-http-receiver-v1.mjs';
7
+ import { SyncSagaContextIbGib_V1 } from '../../sync-saga-context/sync-saga-context-types.mjs';
8
+
9
+ const logalot = GLOBAL_LOG_A_LOT;
10
+
11
+ export interface SyncHttpNodeAdapterOpts {
12
+ /** The receiver peer to route sync traffic to */
13
+ receiverPeer: SyncPeerHttpReceiver_V1;
14
+ /** The port to listen on. Defaults to 8080. */
15
+ port?: number;
16
+ /**
17
+ * Base path for the sync routes. Defaults to '/sync'.
18
+ * Will expose `/sync/frame` (POST) and `/sync/events` (GET).
19
+ */
20
+ basePath?: string;
21
+ /** TLS/SSL Private Key (needed for secure HTTP/2) */
22
+ key?: string | Buffer;
23
+ /** TLS/SSL Certificate (needed for secure HTTP/2) */
24
+ cert?: string | Buffer;
25
+ /** TLS/SSL PFX file (alternative to key/cert on Windows) */
26
+ pfx?: string | Buffer;
27
+ /** Passphrase for TLS/SSL PFX file */
28
+ passphrase?: string;
29
+ }
30
+
31
+ /**
32
+ * A basic Node HTTP adapter for the Symmetric Sync Protocol.
33
+ *
34
+ * Handles establishing the SSE EventSource stream (GET /sync/events)
35
+ * and receiving the Uplink (POST /sync/frame).
36
+ *
37
+ * NOTE: This is built using Node's standard `http` module. In a real
38
+ * production app (e.g. `node-gib` or a consumer app), you might adapt this
39
+ * to Express, Fastify, or directly to an HTTP/2 server.
40
+ */
41
+ export class SyncHttpNodeAdapter_V1 {
42
+ protected lc: string = `[${SyncHttpNodeAdapter_V1.name}]`;
43
+
44
+ protected server?: http2.Http2Server | http2.Http2SecureServer;
45
+ protected receiverPeer: SyncPeerHttpReceiver_V1;
46
+ protected port: number;
47
+ protected basePath: string;
48
+
49
+ /**
50
+ * Map of clientId to their active Server-Sent Events HTTP Response streams.
51
+ */
52
+ protected activeSseStreams = new Map<string, http2.Http2ServerResponse>();
53
+
54
+ constructor(public opts: SyncHttpNodeAdapterOpts) {
55
+ this.receiverPeer = opts.receiverPeer;
56
+ this.port = opts.port || 8080;
57
+ this.basePath = opts.basePath || '/sync';
58
+ }
59
+
60
+ /**
61
+ * Starts the HTTP Server listening on the configured port.
62
+ */
63
+ public async start(): Promise<void> {
64
+ const lc = `[${this.start.name}]`;
65
+ return new Promise((resolve, reject) => {
66
+ try {
67
+ if (logalot) { console.log(`${lc} starting... (I: fc09bcef98bda9d91429161355c2e626)`); }
68
+ const requestHandler = (req: http2.Http2ServerRequest, res: http2.Http2ServerResponse) => {
69
+ this.handleRequest(req, res).catch(e => {
70
+ console.error(`${lc} Uncaught request error: ${extractErrorMsg(e)}`);
71
+ if (!res.headersSent) {
72
+ res.writeHead(500);
73
+ res.end('Internal Server Error');
74
+ }
75
+ });
76
+ };
77
+
78
+ // Use Secure Server if TLS credentials are provided, otherwise fallback to unencrypted (h2c)
79
+ if ((this.opts.key && this.opts.cert) || this.opts.pfx) {
80
+ const secureOpts: http2.SecureServerOptions = {
81
+ allowHTTP1: true // Fallback to HTTP/1.1 for clients that don't support HTTP/2
82
+ };
83
+ if (this.opts.key) secureOpts.key = this.opts.key;
84
+ if (this.opts.cert) secureOpts.cert = this.opts.cert;
85
+ if (this.opts.pfx) secureOpts.pfx = this.opts.pfx;
86
+ if (this.opts.passphrase) secureOpts.passphrase = this.opts.passphrase;
87
+
88
+ this.server = http2.createSecureServer(secureOpts, requestHandler);
89
+ } else {
90
+ this.server = http2.createServer({}, requestHandler);
91
+ }
92
+
93
+ this.server.listen(this.port, () => {
94
+ const protocol = ((this.opts.key && this.opts.cert) || this.opts.pfx) ? 'https/h2' : 'http/h2c';
95
+ if (logalot) { console.log(`${lc} Server listening on port ${this.port} (${protocol}) (I: 67a5ce98074c5aaaff022f5b3804c226)`); }
96
+ resolve();
97
+ });
98
+ } catch (error) {
99
+ console.error(`${lc} ${extractErrorMsg(error)}`);
100
+ reject(error);
101
+ } finally {
102
+ if (logalot) { console.log(`${lc} complete. (I: 1d9e40501e6c191b186ae32edf151526)`); }
103
+ }
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Stops the HTTP Server and closes all active streams.
109
+ */
110
+ public async stop(): Promise<void> {
111
+ const lc = `[${this.stop.name}]`;
112
+ return new Promise((resolve, reject) => {
113
+ try {
114
+ if (logalot) { console.log(`${lc} starting... (I: d7bca060bb02a9fa0cbd4fb65971fb26)`); }
115
+ for (const res of this.activeSseStreams.values()) {
116
+ res.end(); // close all open streams
117
+ }
118
+ this.activeSseStreams.clear();
119
+
120
+ if (this.server) {
121
+ this.server.close((err) => {
122
+ if (err) return reject(err);
123
+ resolve();
124
+ });
125
+ } else {
126
+ resolve();
127
+ }
128
+ } catch (error) {
129
+ console.error(`${lc} ${extractErrorMsg(error)}`);
130
+ reject(error);
131
+ } finally {
132
+ if (logalot) { console.log(`${lc} complete. (I: afa81c5b3a3f88fb6fe0066dd096ff26)`); }
133
+ }
134
+ });
135
+ }
136
+
137
+ protected async handleRequest(req: http2.Http2ServerRequest, res: http2.Http2ServerResponse) {
138
+ const lc = `${this.lc}[${this.handleRequest.name}]`;
139
+ try {
140
+ if (logalot) { console.log(`${lc} starting... (I: 286853cd380d13292d2d36171ca11a26)`); }
141
+ // Set basic CORS headers for browser clients
142
+ res.setHeader('Access-Control-Allow-Origin', '*');
143
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
144
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
145
+
146
+ if (req.method === 'OPTIONS') {
147
+ res.writeHead(204);
148
+ res.end();
149
+ return;
150
+ }
151
+
152
+ const url = new URL(req.url || '/', `http://${req.headers.host}`);
153
+
154
+ // Route: GET /sync/events
155
+ if (req.method === 'GET' && url.pathname.startsWith(`${this.basePath}/events`)) {
156
+ return this.handleSseStreamRequest(req, res, url);
157
+ }
158
+
159
+ // Route: POST /sync/frame
160
+ if (req.method === 'POST' && url.pathname.startsWith(`${this.basePath}/frame`)) {
161
+ return this.handleSyncFrameRequest(req, res, url);
162
+ }
163
+
164
+ res.writeHead(404);
165
+ res.end('Not Found');
166
+ } catch (error) {
167
+ console.error(`${lc} ${extractErrorMsg(error)}`);
168
+ throw error;
169
+ } finally {
170
+ if (logalot) { console.log(`${lc} complete.`); }
171
+ }
172
+ }
173
+
174
+ protected async handleSseStreamRequest(req: http2.Http2ServerRequest, res: http2.Http2ServerResponse, url: URL) {
175
+ const lc = `${this.lc}[${this.handleSseStreamRequest.name}]`;
176
+ try {
177
+ if (logalot) { console.log(`${lc} starting... (I: 17800c6b501b3b07436303e97b930626)`); }
178
+
179
+ // Get clientId from query param, or generate one
180
+ const clientId = url.searchParams.get('clientId') || Math.random().toString(36).substring(2, 10);
181
+
182
+ if (logalot) { console.log(`${lc} New SSE Connection: ${clientId} (I: c1ebeeb91763b76ed0a64cf8af7c6326)`); }
183
+
184
+ res.writeHead(200, {
185
+ 'Content-Type': 'text/event-stream',
186
+ 'Cache-Control': 'no-cache',
187
+ 'Connection': 'keep-alive'
188
+ });
189
+
190
+ // Register the stream
191
+ this.activeSseStreams.set(clientId, res);
192
+
193
+ // Keep connection alive
194
+ const keepAliveInterval = setInterval(() => {
195
+ res.write(`:\n\n`); // comment line
196
+ }, 30000);
197
+
198
+ req.on('close', () => {
199
+ if (logalot) { console.log(`${lc} SSE Connection Closed: ${clientId} (I: 44aea766eb8b7279e5d9cf699a12cb26)`); }
200
+ clearInterval(keepAliveInterval);
201
+ this.activeSseStreams.delete(clientId);
202
+ });
203
+
204
+ // Send an initial connected message (optional)
205
+ res.write(`data: ${JSON.stringify({ type: 'connected', clientId })}\n\n`);
206
+ } catch (error) {
207
+ console.error(`${lc} ${extractErrorMsg(error)}`);
208
+ throw error;
209
+ } finally {
210
+ if (logalot) { console.log(`${lc} complete.`); }
211
+ }
212
+ }
213
+
214
+ protected async handleSyncFrameRequest(req: http2.Http2ServerRequest, res: http2.Http2ServerResponse, url: URL) {
215
+ const lc = `${this.lc}[${this.handleSyncFrameRequest.name}]`;
216
+ try {
217
+ if (logalot) { console.log(`${lc} starting... (I: fee247b53b894f2b6cf3f1f2d4dec726)`); }
218
+ // Assume the client ID is passed via query param or header
219
+ const clientId = url.searchParams.get('clientId') || req.headers['x-client-id'] as string;
220
+
221
+ if (!clientId) {
222
+ res.writeHead(400);
223
+ res.end('clientId required');
224
+ return;
225
+ }
226
+
227
+ const streamRes = this.activeSseStreams.get(clientId);
228
+ if (!streamRes) {
229
+ res.writeHead(400);
230
+ res.end(`No active SSE stream found for clientId: ${clientId}`);
231
+ return;
232
+ }
233
+
234
+ // 1. Parse incoming POST body
235
+ const body = await this.readRequestBody(req);
236
+
237
+ // TODO [USER]: Deserialize your incoming JSON request body into the expected IbGib variables
238
+ const parsedBody = JSON.parse(body);
239
+
240
+ // EXPECTED TYPES:
241
+ const context: SyncSagaContextIbGib_V1 = parsedBody.context;
242
+ const controlIbGibs: any[] = parsedBody.controlIbGibs || [];
243
+
244
+ // 2. Hand it off to the HTTP Receiver Peer
245
+ if (logalot) { console.log(`${lc} Handling Incoming Sync Request from ${clientId} (I: d89d3d28a418d9f6b261b61a164bd326)`); }
246
+ const responseContext = await this.receiverPeer.handleIncomingSyncRequest({
247
+ context,
248
+ controlIbGibs
249
+ });
250
+
251
+ if (!responseContext) {
252
+ res.writeHead(200);
253
+ res.end('OK - No Response Context');
254
+ return;
255
+ }
256
+
257
+ // 3. We successfully processed it and got a responseContext.
258
+ // Now, we must stream the response down the `streamRes` (SSE Connection).
259
+
260
+ // Stream Domain IbGibs first
261
+ if (responseContext.payloadIbGibsDomain) {
262
+ for (const domainIbGib of responseContext.payloadIbGibsDomain) {
263
+ // TODO [USER]: Serialize Domain IbGib for transport
264
+ const payloadChunk = JSON.stringify({
265
+ type: 'domain',
266
+ ibGib: domainIbGib
267
+ });
268
+ streamRes.write(`data: ${payloadChunk}\n\n`);
269
+ }
270
+ // Clean it up so we don't send the entire domain payload list again in the control context
271
+ delete responseContext.payloadIbGibsDomain;
272
+ }
273
+
274
+ // Stream Control Context response
275
+ // TODO [USER]: Serialize Response Context for transport
276
+ const contextChunk = JSON.stringify({
277
+ type: 'context',
278
+ context: responseContext
279
+ });
280
+ streamRes.write(`data: ${contextChunk}\n\n`);
281
+
282
+ // Ack the POST request
283
+ res.writeHead(200);
284
+ res.end('OK');
285
+
286
+ } catch (error) {
287
+ console.error(`${lc} ${extractErrorMsg(error)}`);
288
+ res.writeHead(500);
289
+ res.end(`Internal Server Error`);
290
+ } finally {
291
+ if (logalot) { console.log(`${lc} complete.`); }
292
+ }
293
+ }
294
+
295
+ protected readRequestBody(req: http2.Http2ServerRequest): Promise<string> {
296
+ const lc = `${this.lc}[${this.readRequestBody.name}]`;
297
+ return new Promise((resolve, reject) => {
298
+ try {
299
+ if (logalot) { console.log(`${lc} starting... (I: 95cf4f489e1b7174dc5294096c651326)`); }
300
+ let body = '';
301
+ req.on('data', chunk => {
302
+ body += chunk.toString();
303
+ });
304
+ req.on('end', () => {
305
+ resolve(body);
306
+ });
307
+ req.on('error', (err) => {
308
+ console.error(`${lc} ${extractErrorMsg(err)}`);
309
+ reject(err);
310
+ });
311
+ } catch (error) {
312
+ console.error(`${lc} ${extractErrorMsg(error)}`);
313
+ reject(error);
314
+ } finally {
315
+ if (logalot) { console.log(`${lc} complete.`); }
316
+ }
317
+ });
318
+ }
319
+ }
@@ -0,0 +1,72 @@
1
+ # agent refactor metadata
2
+
3
+ ## guidelines
4
+
5
+ * **Imports Order & logalot**:
6
+ * Imports should be organized in the following order:
7
+ 1. non-@ibgib external dependencies
8
+ 2. blank line
9
+ 3. @ibgib external dependencies (order: helper-gib, ts-gib, encrypt-gib, core-gib, node-gib, web-gib)
10
+ 4. blank line
11
+ 5. `import { GLOBAL_LOG_A_LOT } from '../path/to/constants/file.mts';` (if applicable)
12
+ 6. other local file imports
13
+ 7. blank line
14
+ 8. `const logalot = GLOBAL_LOG_A_LOT` (if applicable)
15
+ 9. blank line
16
+ * So the `GLOBAL_LOG_A_LOT` is a local import, and this should be first iif the file contains any functions with logging.
17
+ * **Destructured params and logging**:
18
+ * Use destructured arguments for functions (unless it's an extremely small helper with a single obvious param).
19
+ * Harness most functions with `try/catch/finally` blocks and logging using `if (logalot)`.
20
+ * Define `const lc = \`[${functionName.name}]\`;` at the top of the function.
21
+ * In the `catch` block, explicitly log using `console.error(\`${lc} ${extractErrorMsg(error)}\`);` and `throw error;` (Do NOT add a UUID here).
22
+ * For Promises, include a `reject` inside the catch block.
23
+ * **Tag Logging Messages with UUIDs**:
24
+ * Tag ALL logging messages, warnings, and errors with the proper prefix (e.g., I:, W:, E:) and a uuid inside parens, e.g., `(I: cfe7c7f220c84bd832bad493a9453826)`. Note: we will use `generate-id.js` for this.
25
+
26
+ ## libs/core-gib/src/sync/sync-peer/sync-peer-http-receiver/sync-http-node-adapter.mts
27
+
28
+ [changes will go here]
29
+
30
+ ### 2026/02/27 - 10:17 AM
31
+
32
+ #### line 1 - Imports Order & logalot
33
+
34
+ ```typescript
35
+ import * as http2 from 'http2';
36
+
37
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
38
+
39
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
40
+ import { SyncPeerHttpReceiver_V1 } from './sync-peer-http-receiver-v1.mjs';
41
+ import { SyncSagaContextIbGib_V1 } from '../../sync-saga-context/sync-saga-context-types.mjs';
42
+
43
+ const logalot = GLOBAL_LOG_A_LOT;
44
+ ```
45
+
46
+ #### lines 55-274 - Destructured params and logging / Tag Logging Messages
47
+
48
+ ```typescript
49
+ // Wrapped functions matching the try/catch/finally logging pattern:
50
+ public async start(): Promise<void> { ... }
51
+ public async stop(): Promise<void> { ... }
52
+ protected async handleRequest(...) { ... }
53
+ protected async handleSseStreamRequest(...) { ... }
54
+ protected async handleSyncFrameRequest(...) { ... }
55
+ protected readRequestBody(...) { ... }
56
+
57
+ // Example of changes applied to methods:
58
+ public async start(): Promise<void> {
59
+ const lc = `[${this.start.name}]`;
60
+ return new Promise((resolve, reject) => {
61
+ try {
62
+ if (logalot) { console.log(`${lc} starting... (I: fc09bcef98bda9d91429161355c2e626)`); }
63
+ // ...
64
+ } catch (error) {
65
+ console.error(`${lc} ${extractErrorMsg(error)}`);
66
+ reject(error);
67
+ } finally {
68
+ if (logalot) { console.log(`${lc} complete. (I: 1d9e40501e6c191b186ae32edf151526)`); }
69
+ }
70
+ });
71
+ }
72
+ ```
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module sync-peer-http-receiver-types
3
+ */
4
+ import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
5
+ import { SyncPeerData_V1, SyncPeerRel8ns_V1, SyncPeerWitness, InitializeSyncPeerOpts } from '../sync-peer-types.mjs';
6
+ import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs';
7
+ import { SyncSagaCoordinator } from '../../sync-saga-coordinator.mjs';
8
+ import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
9
+
10
+ /**
11
+ * Data for the SyncPeerHttpReceiver witness.
12
+ */
13
+ export interface SyncPeerHttpReceiverData_V1 extends SyncPeerData_V1 {
14
+ }
15
+
16
+ /**
17
+ * Relations for the SyncPeerHttpReceiver witness.
18
+ */
19
+ export interface SyncPeerHttpReceiverRel8ns_V1 extends SyncPeerRel8ns_V1 {
20
+ }
21
+
22
+ /**
23
+ * The SyncPeerHttpReceiver witness IbGib.
24
+ */
25
+ export interface SyncPeerHttpReceiverIbGib_V1 extends IbGib_V1<SyncPeerHttpReceiverData_V1, SyncPeerHttpReceiverRel8ns_V1> { }
26
+
27
+ export interface InitializeSyncPeerHttpReceiverOpts extends InitializeSyncPeerOpts {
28
+ localCoordinator: SyncSagaCoordinator;
29
+ localMetaspace: MetaspaceService;
30
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @module sync-peer-http-receiver-v1
3
+ */
4
+
5
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
6
+ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
7
+
8
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
9
+ import { SyncPeer_V1 } from '../sync-peer-v1.mjs';
10
+ import { SyncSagaContextIbGib_V1 } from '../../sync-saga-context/sync-saga-context-types.mjs';
11
+ import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
12
+ import {
13
+ InitializeSyncPeerHttpReceiverOpts,
14
+ SyncPeerHttpReceiverData_V1,
15
+ SyncPeerHttpReceiverRel8ns_V1,
16
+ SyncPeerHttpReceiverIbGib_V1
17
+ } from './sync-peer-http-receiver-types.mjs';
18
+ import { putInSpace } from '../../../witness/space/space-helper.mjs';
19
+
20
+ const logalot = GLOBAL_LOG_A_LOT;
21
+
22
+ /**
23
+ * Http Receiver Peer implementation.
24
+ * Acts as the Symmetric Server Node. Accepts requests, routes to Receiver Coordinator.
25
+ */
26
+ export class SyncPeerHttpReceiver_V1
27
+ extends SyncPeer_V1<InitializeSyncPeerHttpReceiverOpts>
28
+ implements SyncPeerHttpReceiverIbGib_V1 {
29
+
30
+ protected override lc: string = `[${SyncPeerHttpReceiver_V1.name}]`;
31
+
32
+ override get classname(): string {
33
+ return SyncPeerHttpReceiver_V1.name;
34
+ }
35
+
36
+ declare data: SyncPeerHttpReceiverData_V1 | undefined;
37
+ declare rel8ns: SyncPeerHttpReceiverRel8ns_V1 | undefined;
38
+
39
+ constructor(
40
+ initialData: SyncPeerHttpReceiverData_V1,
41
+ initialRel8ns?: SyncPeerHttpReceiverRel8ns_V1,
42
+ ) {
43
+ super(initialData, initialRel8ns);
44
+ }
45
+
46
+ protected async ensureLocalTempSpace(): Promise<IbGibSpaceAny> {
47
+ const lc = `${this.lc}[${this.ensureLocalTempSpace.name}]`;
48
+ try {
49
+ if (!this.opts) { throw new Error(`opts not initialized. (E: 3a77d1f466b92cc7940c0f241ac6c926)`); }
50
+
51
+ if (!this.opts.localTempSpace) {
52
+ const { localMetaspace } = this.opts;
53
+
54
+ const uuid = crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36);
55
+ const tempSpaceName = `tmp_sync_recv_${uuid.substring(0, 8)}`;
56
+ const localTempSpace = await localMetaspace.createNewLocalSpace({
57
+ opts: {
58
+ allowCancel: false,
59
+ spaceName: tempSpaceName,
60
+ getFnPrompt: localMetaspace.getFnPrompt!,
61
+ logalot
62
+ }
63
+ });
64
+ if (!localTempSpace) { throw new Error(`couldn't create a temp space (E: fed96e4491b7297240031fb7f04adf26)`); }
65
+ await localTempSpace.initialized;
66
+ this.opts.localTempSpace = localTempSpace;
67
+ }
68
+
69
+ return this.opts.localTempSpace;
70
+ } catch (error) {
71
+ console.error(`${lc} ${extractErrorMsg(error)}`);
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ protected override async sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined> {
77
+ const lc = `${this.lc}[${this.sendContextRequest.name}]`;
78
+ try {
79
+ if (logalot) { console.log(`${lc} starting... (I: 5297013216ae491894600b5a81115d26)`); }
80
+
81
+ // This method might not be directly called on the receiver in the same way
82
+ // as it is on the sender, or it handles the internal routing for the HTTP request.
83
+ // When an HTTP Endpoint receives a POST, it deserializes the context and triggers this.
84
+
85
+ throw new Error(`Not implemented (E: c56d5d6799b76bd8fd661846f6b9ee26)`);
86
+ } catch (error) {
87
+ console.error(`${lc} ${extractErrorMsg(error)}`);
88
+ throw error;
89
+ } finally {
90
+ if (logalot) { console.log(`${lc} complete.`); }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Entry point from the HTTP Endpoint Adapter (e.g. Express POST route)
96
+ */
97
+ public async handleIncomingSyncRequest({
98
+ context,
99
+ controlIbGibs = [],
100
+ }: {
101
+ context: SyncSagaContextIbGib_V1;
102
+ controlIbGibs?: IbGib_V1[];
103
+ }): Promise<SyncSagaContextIbGib_V1 | undefined> {
104
+ const lc = `${this.lc}[${this.handleIncomingSyncRequest.name}]`;
105
+ try {
106
+ if (logalot) { console.log(`${lc} starting... (I: 1de30d7db7e404ddf59eeed22a3bde26)`); }
107
+
108
+ if (!this.opts) { throw new Error(`opts not initialized. (E: 56f585e25a54489280c9ba1393a46226)`); }
109
+ const { localCoordinator, localMetaspace, localSpace } = this.opts;
110
+ const localTempSpace = await this.ensureLocalTempSpace();
111
+
112
+ // Put control ibgibs into durable space
113
+ const allControlIbGibs = [context, ...controlIbGibs];
114
+ for (const ibGib of allControlIbGibs) {
115
+ await putInSpace({ space: localSpace, ibGibs: [ibGib] });
116
+ }
117
+
118
+ // Put domain payloads into temp space
119
+ if (context.payloadIbGibsDomain && context.payloadIbGibsDomain.length > 0) {
120
+ for (const ibGib of context.payloadIbGibsDomain) {
121
+ await putInSpace({ space: localTempSpace, ibGibs: [ibGib] });
122
+ }
123
+ }
124
+
125
+ const identitySecret = context.fnIdentitySecret ?
126
+ await context.fnIdentitySecret() :
127
+ undefined;
128
+
129
+ const responseCtx = await localCoordinator.continueSync({
130
+ sagaContext: context,
131
+ metaspace: localMetaspace,
132
+ mySpace: localSpace,
133
+ myTempSpace: localTempSpace,
134
+ identity: context.signedSessionKeystone,
135
+ identitySecret,
136
+ });
137
+
138
+ return responseCtx || undefined;
139
+ } catch (error) {
140
+ console.error(`${lc} ${extractErrorMsg(error)}`);
141
+ throw error;
142
+ } finally {
143
+ if (logalot) { console.log(`${lc} complete.`); }
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,71 @@
1
+ # agent refactor metadata
2
+
3
+ ## guidelines
4
+
5
+ * **Imports Order & logalot**:
6
+ * Imports should be organized in the following order:
7
+ 1. non-@ibgib external dependencies
8
+ 2. blank line
9
+ 3. @ibgib external dependencies (order: helper-gib, ts-gib, encrypt-gib, core-gib, node-gib, web-gib)
10
+ 4. blank line
11
+ 5. `import { GLOBAL_LOG_A_LOT } from '../path/to/constants/file.mts';` (if applicable)
12
+ 6. other local file imports
13
+ 7. blank line
14
+ 8. `const logalot = GLOBAL_LOG_A_LOT` (if applicable)
15
+ 9. blank line
16
+ * So the `GLOBAL_LOG_A_LOT` is a local import, and this should be first iif the file contains any functions with logging.
17
+ * **Tag Logging Messages with UUIDs**:
18
+ * Tag ALL logging messages, warnings, and errors with the proper prefix (e.g., I:, W:, E:) and a uuid inside parens, e.g., `(I: cfe7c7f220c84bd832bad493a9453826)`. Note: we will use `generate-id.js` for this.
19
+ * **Exception**: `console.error` logs inside a `catch` block should NOT have their own `(E: uuid)` since the thrown error or rejected promise should already contain it. Simply use `console.error(\`${lc} ${extractErrorMsg(error)}\`);`.
20
+
21
+ ## libs/core-gib/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts
22
+
23
+ [changes will go here]
24
+
25
+ ### 2026/02/27 - 10:49 AM
26
+
27
+ #### line 5 - Imports Order & logalot
28
+
29
+ ```typescript
30
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
31
+ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
32
+
33
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
34
+ import { SyncPeer_V1 } from '../sync-peer-v1.mjs';
35
+ import { SyncSagaContextIbGib_V1 } from '../../sync-saga-context/sync-saga-context-types.mjs';
36
+ import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
37
+ import {
38
+ InitializeSyncPeerHttpReceiverOpts,
39
+ SyncPeerHttpReceiverData_V1,
40
+ SyncPeerHttpReceiverRel8ns_V1,
41
+ SyncPeerHttpReceiverIbGib_V1
42
+ } from './sync-peer-http-receiver-types.mjs';
43
+ import { putInSpace } from '../../../witness/space/space-helper.mjs';
44
+
45
+ const logalot = GLOBAL_LOG_A_LOT;
46
+ ```
47
+
48
+ #### line 48+ - Tag Logging Messages with UUIDs
49
+
50
+ ```typescript
51
+ protected async ensureLocalTempSpace(): Promise<IbGibSpaceAny> {
52
+ // ...
53
+ if (!this.opts) { throw new Error(`opts not initialized. (E: 3a77d1f466b92cc7940c0f241ac6c926)`); }
54
+ // ...
55
+ ```
56
+
57
+ ```typescript
58
+ protected override async sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined> {
59
+ const lc = `${this.lc}[${this.sendContextRequest.name}]`;
60
+ try {
61
+ if (logalot) { console.log(`${lc} starting... (I: 5297013216ae491894600b5a81115d26)`); }
62
+ // ...
63
+ ```
64
+
65
+ ```typescript
66
+ public async handleIncomingSyncRequest({ ... }): Promise<SyncSagaContextIbGib_V1 | undefined> {
67
+ const lc = `${this.lc}[${this.handleIncomingSyncRequest.name}]`;
68
+ try {
69
+ if (logalot) { console.log(`${lc} starting... (I: 1de30d7db7e404ddf59eeed22a3bde26)`); }
70
+ // ...
71
+ ```
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @module sync-peer-http-sender-types
3
+ */
4
+ import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
5
+ import { SyncPeerData_V1, SyncPeerRel8ns_V1, SyncPeerWitness, InitializeSyncPeerOpts } from '../sync-peer-types.mjs';
6
+
7
+ /**
8
+ * Data for the SyncPeerHttpSender witness.
9
+ */
10
+ export interface SyncPeerHttpSenderData_V1 extends SyncPeerData_V1 {
11
+ /** Http POST endpoint for sending context */
12
+ syncRoute: string;
13
+ /** Http GET endpoint for SSE events */
14
+ syncEventsRoute: string;
15
+ }
16
+
17
+ /**
18
+ * Relations for the SyncPeerHttpSender witness.
19
+ */
20
+ export interface SyncPeerHttpSenderRel8ns_V1 extends SyncPeerRel8ns_V1 {
21
+ }
22
+
23
+ /**
24
+ * The SyncPeerHttpSender witness IbGib.
25
+ */
26
+ export interface SyncPeerHttpSenderIbGib_V1 extends IbGib_V1<SyncPeerHttpSenderData_V1, SyncPeerHttpSenderRel8ns_V1> { }
27
+
28
+ export interface InitializeSyncPeerHttpSenderOpts extends InitializeSyncPeerOpts {
29
+ /**
30
+ * Specific options needed for initializing the HTTP sender
31
+ */
32
+ }