chainlesschain 0.145.0 → 0.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/README.md +52 -3
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +201 -0
  4. package/src/commands/activitypub.js +207 -0
  5. package/src/commands/agent-network.js +217 -0
  6. package/src/commands/agent.js +1250 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +203 -0
  9. package/src/commands/browse.js +213 -0
  10. package/src/commands/chat.js +605 -0
  11. package/src/commands/cli-anything.js +426 -0
  12. package/src/commands/codegen.js +207 -0
  13. package/src/commands/collab.js +211 -0
  14. package/src/commands/compliance.js +822 -0
  15. package/src/commands/config.js +213 -0
  16. package/src/commands/cowork.js +1666 -0
  17. package/src/commands/crosschain.js +203 -0
  18. package/src/commands/dao.js +203 -0
  19. package/src/commands/dbevo.js +227 -0
  20. package/src/commands/dev.js +207 -0
  21. package/src/commands/did-v2.js +217 -0
  22. package/src/commands/did.js +221 -0
  23. package/src/commands/dlp.js +213 -0
  24. package/src/commands/economy.js +199 -0
  25. package/src/commands/encrypt.js +201 -0
  26. package/src/commands/evolution.js +199 -0
  27. package/src/commands/evomap.js +830 -0
  28. package/src/commands/export.js +213 -0
  29. package/src/commands/federation.js +209 -0
  30. package/src/commands/fusion.js +205 -0
  31. package/src/commands/governance.js +209 -0
  32. package/src/commands/hmemory.js +203 -0
  33. package/src/commands/hook.js +209 -0
  34. package/src/commands/import.js +209 -0
  35. package/src/commands/inference.js +207 -0
  36. package/src/commands/infra.js +203 -0
  37. package/src/commands/instinct.js +209 -0
  38. package/src/commands/ipfs.js +207 -0
  39. package/src/commands/kg.js +195 -0
  40. package/src/commands/llm.js +426 -0
  41. package/src/commands/matrix.js +207 -0
  42. package/src/commands/mcp.js +217 -0
  43. package/src/commands/memory.js +412 -0
  44. package/src/commands/multimodal.js +203 -0
  45. package/src/commands/nlprog.js +225 -0
  46. package/src/commands/nostr.js +209 -0
  47. package/src/commands/note.js +205 -0
  48. package/src/commands/ops.js +219 -0
  49. package/src/commands/orchestrate.js +406 -0
  50. package/src/commands/org.js +209 -0
  51. package/src/commands/p2p.js +209 -0
  52. package/src/commands/perception.js +209 -0
  53. package/src/commands/permmem.js +203 -0
  54. package/src/commands/pipeline.js +199 -0
  55. package/src/commands/planmode.js +426 -0
  56. package/src/commands/plugin-ecosystem.js +209 -0
  57. package/src/commands/plugin.js +209 -0
  58. package/src/commands/pqc.js +213 -0
  59. package/src/commands/quantization.js +207 -0
  60. package/src/commands/rcache.js +205 -0
  61. package/src/commands/recommend.js +233 -0
  62. package/src/commands/runtime.js +205 -0
  63. package/src/commands/scim.js +209 -0
  64. package/src/commands/services.js +207 -0
  65. package/src/commands/session.js +209 -0
  66. package/src/commands/setup.js +205 -0
  67. package/src/commands/skill.js +414 -0
  68. package/src/commands/social.js +201 -0
  69. package/src/commands/sso.js +209 -0
  70. package/src/commands/start.js +209 -0
  71. package/src/commands/stream.js +213 -0
  72. package/src/commands/sync.js +209 -0
  73. package/src/commands/tech.js +209 -0
  74. package/src/commands/tenant.js +217 -0
  75. package/src/commands/tokens.js +209 -0
  76. package/src/commands/trust.js +217 -0
  77. package/src/commands/ui.js +225 -0
  78. package/src/commands/wallet.js +209 -0
  79. package/src/commands/workflow.js +412 -0
  80. package/src/index.js +252 -0
  81. package/src/lib/a2a-protocol.js +332 -0
  82. package/src/lib/activitypub-bridge.js +334 -0
  83. package/src/lib/agent-coordinator.js +334 -0
  84. package/src/lib/agent-economy.js +334 -0
  85. package/src/lib/agent-network.js +341 -0
  86. package/src/lib/agent-router.js +333 -0
  87. package/src/lib/aiops.js +346 -0
  88. package/src/lib/automation-engine.js +335 -0
  89. package/src/lib/autonomous-agent.js +332 -0
  90. package/src/lib/autonomous-developer.js +332 -0
  91. package/src/lib/bi-engine.js +333 -0
  92. package/src/lib/browser-automation.js +334 -0
  93. package/src/lib/chat-core.js +335 -0
  94. package/src/lib/cli-anything-bridge.js +341 -0
  95. package/src/lib/cli-context-engineering.js +351 -0
  96. package/src/lib/code-agent.js +339 -0
  97. package/src/lib/collaboration-governance.js +334 -0
  98. package/src/lib/community-governance.js +346 -0
  99. package/src/lib/compliance-manager.js +334 -0
  100. package/src/lib/content-recommendation.js +351 -0
  101. package/src/lib/cowork-adapter.js +336 -0
  102. package/src/lib/cowork-evomap-adapter.js +341 -0
  103. package/src/lib/cowork-mcp-tools.js +341 -0
  104. package/src/lib/cowork-observe-html.js +341 -0
  105. package/src/lib/cowork-observe.js +341 -0
  106. package/src/lib/cowork-share.js +338 -0
  107. package/src/lib/cowork-task-templates.js +342 -1
  108. package/src/lib/cowork-template-marketplace.js +340 -0
  109. package/src/lib/cross-chain.js +339 -0
  110. package/src/lib/crypto-manager.js +334 -0
  111. package/src/lib/dao-governance.js +339 -0
  112. package/src/lib/dbevo.js +351 -0
  113. package/src/lib/decentral-infra.js +330 -0
  114. package/src/lib/did-manager.js +341 -0
  115. package/src/lib/did-v2-manager.js +341 -0
  116. package/src/lib/dlp-engine.js +339 -0
  117. package/src/lib/downloader.js +334 -0
  118. package/src/lib/evolution-system.js +334 -0
  119. package/src/lib/evomap-client.js +342 -0
  120. package/src/lib/evomap-federation.js +338 -0
  121. package/src/lib/evomap-governance.js +334 -0
  122. package/src/lib/evomap-manager.js +330 -0
  123. package/src/lib/execution-backend.js +330 -0
  124. package/src/lib/federation-hardening.js +340 -0
  125. package/src/lib/hashline.js +338 -0
  126. package/src/lib/hierarchical-memory.js +334 -0
  127. package/src/lib/hook-manager.js +341 -0
  128. package/src/lib/inference-network.js +341 -0
  129. package/src/lib/instinct-manager.js +346 -0
  130. package/src/lib/interaction-adapter.js +330 -0
  131. package/src/lib/interactive-planner.js +354 -0
  132. package/src/lib/ipfs-storage.js +334 -0
  133. package/src/lib/knowledge-exporter.js +341 -0
  134. package/src/lib/knowledge-graph.js +331 -0
  135. package/src/lib/knowledge-importer.js +341 -0
  136. package/src/lib/llm-providers.js +346 -0
  137. package/src/lib/matrix-bridge.js +339 -0
  138. package/src/lib/mcp-registry.js +346 -0
  139. package/src/lib/memory-manager.js +336 -0
  140. package/src/lib/multimodal.js +330 -0
  141. package/src/lib/nl-programming.js +341 -0
  142. package/src/lib/nostr-bridge.js +336 -0
  143. package/src/lib/note-versioning.js +339 -0
  144. package/src/lib/org-manager.js +336 -0
  145. package/src/lib/p2p-manager.js +341 -0
  146. package/src/lib/perception.js +346 -0
  147. package/src/lib/permanent-memory.js +327 -0
  148. package/src/lib/pipeline-orchestrator.js +332 -0
  149. package/src/lib/plan-mode.js +336 -0
  150. package/src/lib/plugin-autodiscovery.js +334 -0
  151. package/src/lib/plugin-ecosystem.js +346 -0
  152. package/src/lib/pqc-manager.js +346 -0
  153. package/src/lib/process-manager.js +336 -0
  154. package/src/lib/protocol-fusion.js +338 -0
  155. package/src/lib/provider-options.js +346 -0
  156. package/src/lib/provider-stream.js +348 -0
  157. package/src/lib/quantization.js +337 -0
  158. package/src/lib/response-cache.js +333 -0
  159. package/src/lib/scim-manager.js +346 -0
  160. package/src/lib/service-manager.js +337 -0
  161. package/src/lib/session-core-singletons.js +341 -0
  162. package/src/lib/session-manager.js +334 -0
  163. package/src/lib/skill-loader.js +334 -0
  164. package/src/lib/skill-mcp.js +336 -0
  165. package/src/lib/social-manager.js +330 -0
  166. package/src/lib/sso-manager.js +340 -0
  167. package/src/lib/stix-parser.js +346 -0
  168. package/src/lib/sub-agent-context.js +343 -0
  169. package/src/lib/sub-agent-profiles.js +335 -0
  170. package/src/lib/sub-agent-registry.js +336 -0
  171. package/src/lib/sync-manager.js +336 -0
  172. package/src/lib/tech-learning-engine.js +341 -0
  173. package/src/lib/tenant-saas.js +341 -0
  174. package/src/lib/threat-intel.js +330 -0
  175. package/src/lib/todo-manager.js +336 -0
  176. package/src/lib/token-tracker.js +336 -0
  177. package/src/lib/trust-security.js +343 -0
  178. package/src/lib/ueba.js +340 -0
  179. package/src/lib/universal-runtime.js +330 -0
  180. package/src/lib/wallet-manager.js +336 -0
  181. package/src/lib/web-ui-server.js +348 -0
  182. package/src/lib/workflow-engine.js +330 -0
  183. package/src/lib/workflow-expr.js +346 -0
  184. package/src/lib/ws-chat-handler.js +337 -0
@@ -1171,3 +1171,343 @@ export function getSsoManagerStatsV2() {
1171
1171
  loginsByStatus,
1172
1172
  };
1173
1173
  }
1174
+
1175
+ // =====================================================================
1176
+ // sso-manager V2 governance overlay (iter19)
1177
+ // =====================================================================
1178
+ export const SSOGOV_PROFILE_MATURITY_V2 = Object.freeze({
1179
+ PENDING: "pending",
1180
+ ACTIVE: "active",
1181
+ SUSPENDED: "suspended",
1182
+ ARCHIVED: "archived",
1183
+ });
1184
+ export const SSOGOV_LOGIN_LIFECYCLE_V2 = Object.freeze({
1185
+ QUEUED: "queued",
1186
+ AUTHENTICATING: "authenticating",
1187
+ AUTHENTICATED: "authenticated",
1188
+ FAILED: "failed",
1189
+ CANCELLED: "cancelled",
1190
+ });
1191
+ const _ssogovPTrans = new Map([
1192
+ [
1193
+ SSOGOV_PROFILE_MATURITY_V2.PENDING,
1194
+ new Set([
1195
+ SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
1196
+ SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1197
+ ]),
1198
+ ],
1199
+ [
1200
+ SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
1201
+ new Set([
1202
+ SSOGOV_PROFILE_MATURITY_V2.SUSPENDED,
1203
+ SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1204
+ ]),
1205
+ ],
1206
+ [
1207
+ SSOGOV_PROFILE_MATURITY_V2.SUSPENDED,
1208
+ new Set([
1209
+ SSOGOV_PROFILE_MATURITY_V2.ACTIVE,
1210
+ SSOGOV_PROFILE_MATURITY_V2.ARCHIVED,
1211
+ ]),
1212
+ ],
1213
+ [SSOGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1214
+ ]);
1215
+ const _ssogovPTerminal = new Set([SSOGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1216
+ const _ssogovJTrans = new Map([
1217
+ [
1218
+ SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED,
1219
+ new Set([
1220
+ SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING,
1221
+ SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED,
1222
+ ]),
1223
+ ],
1224
+ [
1225
+ SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING,
1226
+ new Set([
1227
+ SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED,
1228
+ SSOGOV_LOGIN_LIFECYCLE_V2.FAILED,
1229
+ SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED,
1230
+ ]),
1231
+ ],
1232
+ [SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED, new Set()],
1233
+ [SSOGOV_LOGIN_LIFECYCLE_V2.FAILED, new Set()],
1234
+ [SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED, new Set()],
1235
+ ]);
1236
+ const _ssogovPsV2 = new Map();
1237
+ const _ssogovJsV2 = new Map();
1238
+ let _ssogovMaxActive = 8,
1239
+ _ssogovMaxPending = 30,
1240
+ _ssogovIdleMs = 30 * 24 * 60 * 60 * 1000,
1241
+ _ssogovStuckMs = 60 * 1000;
1242
+ function _ssogovPos(n, label) {
1243
+ const v = Math.floor(Number(n));
1244
+ if (!Number.isFinite(v) || v <= 0)
1245
+ throw new Error(`${label} must be positive integer`);
1246
+ return v;
1247
+ }
1248
+ function _ssogovCheckP(from, to) {
1249
+ const a = _ssogovPTrans.get(from);
1250
+ if (!a || !a.has(to))
1251
+ throw new Error(`invalid ssogov profile transition ${from} → ${to}`);
1252
+ }
1253
+ function _ssogovCheckJ(from, to) {
1254
+ const a = _ssogovJTrans.get(from);
1255
+ if (!a || !a.has(to))
1256
+ throw new Error(`invalid ssogov login transition ${from} → ${to}`);
1257
+ }
1258
+ function _ssogovCountActive(owner) {
1259
+ let c = 0;
1260
+ for (const p of _ssogovPsV2.values())
1261
+ if (p.owner === owner && p.status === SSOGOV_PROFILE_MATURITY_V2.ACTIVE)
1262
+ c++;
1263
+ return c;
1264
+ }
1265
+ function _ssogovCountPending(profileId) {
1266
+ let c = 0;
1267
+ for (const j of _ssogovJsV2.values())
1268
+ if (
1269
+ j.profileId === profileId &&
1270
+ (j.status === SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED ||
1271
+ j.status === SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING)
1272
+ )
1273
+ c++;
1274
+ return c;
1275
+ }
1276
+ export function setMaxActiveSsogovProfilesPerOwnerV2(n) {
1277
+ _ssogovMaxActive = _ssogovPos(n, "maxActiveSsogovProfilesPerOwner");
1278
+ }
1279
+ export function getMaxActiveSsogovProfilesPerOwnerV2() {
1280
+ return _ssogovMaxActive;
1281
+ }
1282
+ export function setMaxPendingSsogovLoginsPerProfileV2(n) {
1283
+ _ssogovMaxPending = _ssogovPos(n, "maxPendingSsogovLoginsPerProfile");
1284
+ }
1285
+ export function getMaxPendingSsogovLoginsPerProfileV2() {
1286
+ return _ssogovMaxPending;
1287
+ }
1288
+ export function setSsogovProfileIdleMsV2(n) {
1289
+ _ssogovIdleMs = _ssogovPos(n, "ssogovProfileIdleMs");
1290
+ }
1291
+ export function getSsogovProfileIdleMsV2() {
1292
+ return _ssogovIdleMs;
1293
+ }
1294
+ export function setSsogovLoginStuckMsV2(n) {
1295
+ _ssogovStuckMs = _ssogovPos(n, "ssogovLoginStuckMs");
1296
+ }
1297
+ export function getSsogovLoginStuckMsV2() {
1298
+ return _ssogovStuckMs;
1299
+ }
1300
+ export function _resetStateSsoManagerGovV2() {
1301
+ _ssogovPsV2.clear();
1302
+ _ssogovJsV2.clear();
1303
+ _ssogovMaxActive = 8;
1304
+ _ssogovMaxPending = 30;
1305
+ _ssogovIdleMs = 30 * 24 * 60 * 60 * 1000;
1306
+ _ssogovStuckMs = 60 * 1000;
1307
+ }
1308
+ export function registerSsogovProfileV2({
1309
+ id,
1310
+ owner,
1311
+ protocol,
1312
+ metadata,
1313
+ } = {}) {
1314
+ if (!id || !owner) throw new Error("id and owner required");
1315
+ if (_ssogovPsV2.has(id))
1316
+ throw new Error(`ssogov profile ${id} already exists`);
1317
+ const now = Date.now();
1318
+ const p = {
1319
+ id,
1320
+ owner,
1321
+ protocol: protocol || "oidc",
1322
+ status: SSOGOV_PROFILE_MATURITY_V2.PENDING,
1323
+ createdAt: now,
1324
+ updatedAt: now,
1325
+ lastTouchedAt: now,
1326
+ activatedAt: null,
1327
+ archivedAt: null,
1328
+ metadata: { ...(metadata || {}) },
1329
+ };
1330
+ _ssogovPsV2.set(id, p);
1331
+ return { ...p, metadata: { ...p.metadata } };
1332
+ }
1333
+ export function activateSsogovProfileV2(id) {
1334
+ const p = _ssogovPsV2.get(id);
1335
+ if (!p) throw new Error(`ssogov profile ${id} not found`);
1336
+ const isInitial = p.status === SSOGOV_PROFILE_MATURITY_V2.PENDING;
1337
+ _ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.ACTIVE);
1338
+ if (isInitial && _ssogovCountActive(p.owner) >= _ssogovMaxActive)
1339
+ throw new Error(`max active ssogov profiles for owner ${p.owner} reached`);
1340
+ const now = Date.now();
1341
+ p.status = SSOGOV_PROFILE_MATURITY_V2.ACTIVE;
1342
+ p.updatedAt = now;
1343
+ p.lastTouchedAt = now;
1344
+ if (!p.activatedAt) p.activatedAt = now;
1345
+ return { ...p, metadata: { ...p.metadata } };
1346
+ }
1347
+ export function suspendSsogovProfileV2(id) {
1348
+ const p = _ssogovPsV2.get(id);
1349
+ if (!p) throw new Error(`ssogov profile ${id} not found`);
1350
+ _ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.SUSPENDED);
1351
+ p.status = SSOGOV_PROFILE_MATURITY_V2.SUSPENDED;
1352
+ p.updatedAt = Date.now();
1353
+ return { ...p, metadata: { ...p.metadata } };
1354
+ }
1355
+ export function archiveSsogovProfileV2(id) {
1356
+ const p = _ssogovPsV2.get(id);
1357
+ if (!p) throw new Error(`ssogov profile ${id} not found`);
1358
+ _ssogovCheckP(p.status, SSOGOV_PROFILE_MATURITY_V2.ARCHIVED);
1359
+ const now = Date.now();
1360
+ p.status = SSOGOV_PROFILE_MATURITY_V2.ARCHIVED;
1361
+ p.updatedAt = now;
1362
+ if (!p.archivedAt) p.archivedAt = now;
1363
+ return { ...p, metadata: { ...p.metadata } };
1364
+ }
1365
+ export function touchSsogovProfileV2(id) {
1366
+ const p = _ssogovPsV2.get(id);
1367
+ if (!p) throw new Error(`ssogov profile ${id} not found`);
1368
+ if (_ssogovPTerminal.has(p.status))
1369
+ throw new Error(`cannot touch terminal ssogov profile ${id}`);
1370
+ const now = Date.now();
1371
+ p.lastTouchedAt = now;
1372
+ p.updatedAt = now;
1373
+ return { ...p, metadata: { ...p.metadata } };
1374
+ }
1375
+ export function getSsogovProfileV2(id) {
1376
+ const p = _ssogovPsV2.get(id);
1377
+ if (!p) return null;
1378
+ return { ...p, metadata: { ...p.metadata } };
1379
+ }
1380
+ export function listSsogovProfilesV2() {
1381
+ return [..._ssogovPsV2.values()].map((p) => ({
1382
+ ...p,
1383
+ metadata: { ...p.metadata },
1384
+ }));
1385
+ }
1386
+ export function createSsogovLoginV2({ id, profileId, subject, metadata } = {}) {
1387
+ if (!id || !profileId) throw new Error("id and profileId required");
1388
+ if (_ssogovJsV2.has(id)) throw new Error(`ssogov login ${id} already exists`);
1389
+ if (!_ssogovPsV2.has(profileId))
1390
+ throw new Error(`ssogov profile ${profileId} not found`);
1391
+ if (_ssogovCountPending(profileId) >= _ssogovMaxPending)
1392
+ throw new Error(
1393
+ `max pending ssogov logins for profile ${profileId} reached`,
1394
+ );
1395
+ const now = Date.now();
1396
+ const j = {
1397
+ id,
1398
+ profileId,
1399
+ subject: subject || "",
1400
+ status: SSOGOV_LOGIN_LIFECYCLE_V2.QUEUED,
1401
+ createdAt: now,
1402
+ updatedAt: now,
1403
+ startedAt: null,
1404
+ settledAt: null,
1405
+ metadata: { ...(metadata || {}) },
1406
+ };
1407
+ _ssogovJsV2.set(id, j);
1408
+ return { ...j, metadata: { ...j.metadata } };
1409
+ }
1410
+ export function authenticatingSsogovLoginV2(id) {
1411
+ const j = _ssogovJsV2.get(id);
1412
+ if (!j) throw new Error(`ssogov login ${id} not found`);
1413
+ _ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING);
1414
+ const now = Date.now();
1415
+ j.status = SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING;
1416
+ j.updatedAt = now;
1417
+ if (!j.startedAt) j.startedAt = now;
1418
+ return { ...j, metadata: { ...j.metadata } };
1419
+ }
1420
+ export function completeLoginSsogovV2(id) {
1421
+ const j = _ssogovJsV2.get(id);
1422
+ if (!j) throw new Error(`ssogov login ${id} not found`);
1423
+ _ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED);
1424
+ const now = Date.now();
1425
+ j.status = SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATED;
1426
+ j.updatedAt = now;
1427
+ if (!j.settledAt) j.settledAt = now;
1428
+ return { ...j, metadata: { ...j.metadata } };
1429
+ }
1430
+ export function failSsogovLoginV2(id, reason) {
1431
+ const j = _ssogovJsV2.get(id);
1432
+ if (!j) throw new Error(`ssogov login ${id} not found`);
1433
+ _ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.FAILED);
1434
+ const now = Date.now();
1435
+ j.status = SSOGOV_LOGIN_LIFECYCLE_V2.FAILED;
1436
+ j.updatedAt = now;
1437
+ if (!j.settledAt) j.settledAt = now;
1438
+ if (reason) j.metadata.failReason = String(reason);
1439
+ return { ...j, metadata: { ...j.metadata } };
1440
+ }
1441
+ export function cancelSsogovLoginV2(id, reason) {
1442
+ const j = _ssogovJsV2.get(id);
1443
+ if (!j) throw new Error(`ssogov login ${id} not found`);
1444
+ _ssogovCheckJ(j.status, SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED);
1445
+ const now = Date.now();
1446
+ j.status = SSOGOV_LOGIN_LIFECYCLE_V2.CANCELLED;
1447
+ j.updatedAt = now;
1448
+ if (!j.settledAt) j.settledAt = now;
1449
+ if (reason) j.metadata.cancelReason = String(reason);
1450
+ return { ...j, metadata: { ...j.metadata } };
1451
+ }
1452
+ export function getSsogovLoginV2(id) {
1453
+ const j = _ssogovJsV2.get(id);
1454
+ if (!j) return null;
1455
+ return { ...j, metadata: { ...j.metadata } };
1456
+ }
1457
+ export function listSsogovLoginsV2() {
1458
+ return [..._ssogovJsV2.values()].map((j) => ({
1459
+ ...j,
1460
+ metadata: { ...j.metadata },
1461
+ }));
1462
+ }
1463
+ export function autoSuspendIdleSsogovProfilesV2({ now } = {}) {
1464
+ const t = now ?? Date.now();
1465
+ const flipped = [];
1466
+ for (const p of _ssogovPsV2.values())
1467
+ if (
1468
+ p.status === SSOGOV_PROFILE_MATURITY_V2.ACTIVE &&
1469
+ t - p.lastTouchedAt >= _ssogovIdleMs
1470
+ ) {
1471
+ p.status = SSOGOV_PROFILE_MATURITY_V2.SUSPENDED;
1472
+ p.updatedAt = t;
1473
+ flipped.push(p.id);
1474
+ }
1475
+ return { flipped, count: flipped.length };
1476
+ }
1477
+ export function autoFailStuckSsogovLoginsV2({ now } = {}) {
1478
+ const t = now ?? Date.now();
1479
+ const flipped = [];
1480
+ for (const j of _ssogovJsV2.values())
1481
+ if (
1482
+ j.status === SSOGOV_LOGIN_LIFECYCLE_V2.AUTHENTICATING &&
1483
+ j.startedAt != null &&
1484
+ t - j.startedAt >= _ssogovStuckMs
1485
+ ) {
1486
+ j.status = SSOGOV_LOGIN_LIFECYCLE_V2.FAILED;
1487
+ j.updatedAt = t;
1488
+ if (!j.settledAt) j.settledAt = t;
1489
+ j.metadata.failReason = "auto-fail-stuck";
1490
+ flipped.push(j.id);
1491
+ }
1492
+ return { flipped, count: flipped.length };
1493
+ }
1494
+ export function getSsoManagerGovStatsV2() {
1495
+ const profilesByStatus = {};
1496
+ for (const v of Object.values(SSOGOV_PROFILE_MATURITY_V2))
1497
+ profilesByStatus[v] = 0;
1498
+ for (const p of _ssogovPsV2.values()) profilesByStatus[p.status]++;
1499
+ const loginsByStatus = {};
1500
+ for (const v of Object.values(SSOGOV_LOGIN_LIFECYCLE_V2))
1501
+ loginsByStatus[v] = 0;
1502
+ for (const j of _ssogovJsV2.values()) loginsByStatus[j.status]++;
1503
+ return {
1504
+ totalSsogovProfilesV2: _ssogovPsV2.size,
1505
+ totalSsogovLoginsV2: _ssogovJsV2.size,
1506
+ maxActiveSsogovProfilesPerOwner: _ssogovMaxActive,
1507
+ maxPendingSsogovLoginsPerProfile: _ssogovMaxPending,
1508
+ ssogovProfileIdleMs: _ssogovIdleMs,
1509
+ ssogovLoginStuckMs: _ssogovStuckMs,
1510
+ profilesByStatus,
1511
+ loginsByStatus,
1512
+ };
1513
+ }
@@ -165,3 +165,349 @@ export function classifyObservable(value) {
165
165
  if (/^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i.test(v)) return "domain";
166
166
  return "unknown";
167
167
  }
168
+
169
+ // =====================================================================
170
+ // stix-parser V2 governance overlay (iter27)
171
+ // =====================================================================
172
+ export const STIXGOV_PROFILE_MATURITY_V2 = Object.freeze({
173
+ PENDING: "pending",
174
+ ACTIVE: "active",
175
+ STALE: "stale",
176
+ ARCHIVED: "archived",
177
+ });
178
+ export const STIXGOV_PARSE_LIFECYCLE_V2 = Object.freeze({
179
+ QUEUED: "queued",
180
+ PARSING: "parsing",
181
+ PARSED: "parsed",
182
+ FAILED: "failed",
183
+ CANCELLED: "cancelled",
184
+ });
185
+ const _stixgovPTrans = new Map([
186
+ [
187
+ STIXGOV_PROFILE_MATURITY_V2.PENDING,
188
+ new Set([
189
+ STIXGOV_PROFILE_MATURITY_V2.ACTIVE,
190
+ STIXGOV_PROFILE_MATURITY_V2.ARCHIVED,
191
+ ]),
192
+ ],
193
+ [
194
+ STIXGOV_PROFILE_MATURITY_V2.ACTIVE,
195
+ new Set([
196
+ STIXGOV_PROFILE_MATURITY_V2.STALE,
197
+ STIXGOV_PROFILE_MATURITY_V2.ARCHIVED,
198
+ ]),
199
+ ],
200
+ [
201
+ STIXGOV_PROFILE_MATURITY_V2.STALE,
202
+ new Set([
203
+ STIXGOV_PROFILE_MATURITY_V2.ACTIVE,
204
+ STIXGOV_PROFILE_MATURITY_V2.ARCHIVED,
205
+ ]),
206
+ ],
207
+ [STIXGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
208
+ ]);
209
+ const _stixgovPTerminal = new Set([STIXGOV_PROFILE_MATURITY_V2.ARCHIVED]);
210
+ const _stixgovJTrans = new Map([
211
+ [
212
+ STIXGOV_PARSE_LIFECYCLE_V2.QUEUED,
213
+ new Set([
214
+ STIXGOV_PARSE_LIFECYCLE_V2.PARSING,
215
+ STIXGOV_PARSE_LIFECYCLE_V2.CANCELLED,
216
+ ]),
217
+ ],
218
+ [
219
+ STIXGOV_PARSE_LIFECYCLE_V2.PARSING,
220
+ new Set([
221
+ STIXGOV_PARSE_LIFECYCLE_V2.PARSED,
222
+ STIXGOV_PARSE_LIFECYCLE_V2.FAILED,
223
+ STIXGOV_PARSE_LIFECYCLE_V2.CANCELLED,
224
+ ]),
225
+ ],
226
+ [STIXGOV_PARSE_LIFECYCLE_V2.PARSED, new Set()],
227
+ [STIXGOV_PARSE_LIFECYCLE_V2.FAILED, new Set()],
228
+ [STIXGOV_PARSE_LIFECYCLE_V2.CANCELLED, new Set()],
229
+ ]);
230
+ const _stixgovPsV2 = new Map();
231
+ const _stixgovJsV2 = new Map();
232
+ let _stixgovMaxActive = 6,
233
+ _stixgovMaxPending = 15,
234
+ _stixgovIdleMs = 30 * 24 * 60 * 60 * 1000,
235
+ _stixgovStuckMs = 60 * 1000;
236
+ function _stixgovPos(n, label) {
237
+ const v = Math.floor(Number(n));
238
+ if (!Number.isFinite(v) || v <= 0)
239
+ throw new Error(`${label} must be positive integer`);
240
+ return v;
241
+ }
242
+ function _stixgovCheckP(from, to) {
243
+ const a = _stixgovPTrans.get(from);
244
+ if (!a || !a.has(to))
245
+ throw new Error(`invalid stixgov profile transition ${from} → ${to}`);
246
+ }
247
+ function _stixgovCheckJ(from, to) {
248
+ const a = _stixgovJTrans.get(from);
249
+ if (!a || !a.has(to))
250
+ throw new Error(`invalid stixgov parse transition ${from} → ${to}`);
251
+ }
252
+ function _stixgovCountActive(owner) {
253
+ let c = 0;
254
+ for (const p of _stixgovPsV2.values())
255
+ if (p.owner === owner && p.status === STIXGOV_PROFILE_MATURITY_V2.ACTIVE)
256
+ c++;
257
+ return c;
258
+ }
259
+ function _stixgovCountPending(profileId) {
260
+ let c = 0;
261
+ for (const j of _stixgovJsV2.values())
262
+ if (
263
+ j.profileId === profileId &&
264
+ (j.status === STIXGOV_PARSE_LIFECYCLE_V2.QUEUED ||
265
+ j.status === STIXGOV_PARSE_LIFECYCLE_V2.PARSING)
266
+ )
267
+ c++;
268
+ return c;
269
+ }
270
+ export function setMaxActiveStixgovProfilesPerOwnerV2(n) {
271
+ _stixgovMaxActive = _stixgovPos(n, "maxActiveStixgovProfilesPerOwner");
272
+ }
273
+ export function getMaxActiveStixgovProfilesPerOwnerV2() {
274
+ return _stixgovMaxActive;
275
+ }
276
+ export function setMaxPendingStixgovParsesPerProfileV2(n) {
277
+ _stixgovMaxPending = _stixgovPos(n, "maxPendingStixgovParsesPerProfile");
278
+ }
279
+ export function getMaxPendingStixgovParsesPerProfileV2() {
280
+ return _stixgovMaxPending;
281
+ }
282
+ export function setStixgovProfileIdleMsV2(n) {
283
+ _stixgovIdleMs = _stixgovPos(n, "stixgovProfileIdleMs");
284
+ }
285
+ export function getStixgovProfileIdleMsV2() {
286
+ return _stixgovIdleMs;
287
+ }
288
+ export function setStixgovParseStuckMsV2(n) {
289
+ _stixgovStuckMs = _stixgovPos(n, "stixgovParseStuckMs");
290
+ }
291
+ export function getStixgovParseStuckMsV2() {
292
+ return _stixgovStuckMs;
293
+ }
294
+ export function _resetStateStixParserGovV2() {
295
+ _stixgovPsV2.clear();
296
+ _stixgovJsV2.clear();
297
+ _stixgovMaxActive = 6;
298
+ _stixgovMaxPending = 15;
299
+ _stixgovIdleMs = 30 * 24 * 60 * 60 * 1000;
300
+ _stixgovStuckMs = 60 * 1000;
301
+ }
302
+ export function registerStixgovProfileV2({
303
+ id,
304
+ owner,
305
+ stixVersion,
306
+ metadata,
307
+ } = {}) {
308
+ if (!id || !owner) throw new Error("id and owner required");
309
+ if (_stixgovPsV2.has(id))
310
+ throw new Error(`stixgov profile ${id} already exists`);
311
+ const now = Date.now();
312
+ const p = {
313
+ id,
314
+ owner,
315
+ stixVersion: stixVersion || "2.1",
316
+ status: STIXGOV_PROFILE_MATURITY_V2.PENDING,
317
+ createdAt: now,
318
+ updatedAt: now,
319
+ lastTouchedAt: now,
320
+ activatedAt: null,
321
+ archivedAt: null,
322
+ metadata: { ...(metadata || {}) },
323
+ };
324
+ _stixgovPsV2.set(id, p);
325
+ return { ...p, metadata: { ...p.metadata } };
326
+ }
327
+ export function activateStixgovProfileV2(id) {
328
+ const p = _stixgovPsV2.get(id);
329
+ if (!p) throw new Error(`stixgov profile ${id} not found`);
330
+ const isInitial = p.status === STIXGOV_PROFILE_MATURITY_V2.PENDING;
331
+ _stixgovCheckP(p.status, STIXGOV_PROFILE_MATURITY_V2.ACTIVE);
332
+ if (isInitial && _stixgovCountActive(p.owner) >= _stixgovMaxActive)
333
+ throw new Error(`max active stixgov profiles for owner ${p.owner} reached`);
334
+ const now = Date.now();
335
+ p.status = STIXGOV_PROFILE_MATURITY_V2.ACTIVE;
336
+ p.updatedAt = now;
337
+ p.lastTouchedAt = now;
338
+ if (!p.activatedAt) p.activatedAt = now;
339
+ return { ...p, metadata: { ...p.metadata } };
340
+ }
341
+ export function staleStixgovProfileV2(id) {
342
+ const p = _stixgovPsV2.get(id);
343
+ if (!p) throw new Error(`stixgov profile ${id} not found`);
344
+ _stixgovCheckP(p.status, STIXGOV_PROFILE_MATURITY_V2.STALE);
345
+ p.status = STIXGOV_PROFILE_MATURITY_V2.STALE;
346
+ p.updatedAt = Date.now();
347
+ return { ...p, metadata: { ...p.metadata } };
348
+ }
349
+ export function archiveStixgovProfileV2(id) {
350
+ const p = _stixgovPsV2.get(id);
351
+ if (!p) throw new Error(`stixgov profile ${id} not found`);
352
+ _stixgovCheckP(p.status, STIXGOV_PROFILE_MATURITY_V2.ARCHIVED);
353
+ const now = Date.now();
354
+ p.status = STIXGOV_PROFILE_MATURITY_V2.ARCHIVED;
355
+ p.updatedAt = now;
356
+ if (!p.archivedAt) p.archivedAt = now;
357
+ return { ...p, metadata: { ...p.metadata } };
358
+ }
359
+ export function touchStixgovProfileV2(id) {
360
+ const p = _stixgovPsV2.get(id);
361
+ if (!p) throw new Error(`stixgov profile ${id} not found`);
362
+ if (_stixgovPTerminal.has(p.status))
363
+ throw new Error(`cannot touch terminal stixgov profile ${id}`);
364
+ const now = Date.now();
365
+ p.lastTouchedAt = now;
366
+ p.updatedAt = now;
367
+ return { ...p, metadata: { ...p.metadata } };
368
+ }
369
+ export function getStixgovProfileV2(id) {
370
+ const p = _stixgovPsV2.get(id);
371
+ if (!p) return null;
372
+ return { ...p, metadata: { ...p.metadata } };
373
+ }
374
+ export function listStixgovProfilesV2() {
375
+ return [..._stixgovPsV2.values()].map((p) => ({
376
+ ...p,
377
+ metadata: { ...p.metadata },
378
+ }));
379
+ }
380
+ export function createStixgovParseV2({
381
+ id,
382
+ profileId,
383
+ bundleId,
384
+ metadata,
385
+ } = {}) {
386
+ if (!id || !profileId) throw new Error("id and profileId required");
387
+ if (_stixgovJsV2.has(id))
388
+ throw new Error(`stixgov parse ${id} already exists`);
389
+ if (!_stixgovPsV2.has(profileId))
390
+ throw new Error(`stixgov profile ${profileId} not found`);
391
+ if (_stixgovCountPending(profileId) >= _stixgovMaxPending)
392
+ throw new Error(
393
+ `max pending stixgov parses for profile ${profileId} reached`,
394
+ );
395
+ const now = Date.now();
396
+ const j = {
397
+ id,
398
+ profileId,
399
+ bundleId: bundleId || "",
400
+ status: STIXGOV_PARSE_LIFECYCLE_V2.QUEUED,
401
+ createdAt: now,
402
+ updatedAt: now,
403
+ startedAt: null,
404
+ settledAt: null,
405
+ metadata: { ...(metadata || {}) },
406
+ };
407
+ _stixgovJsV2.set(id, j);
408
+ return { ...j, metadata: { ...j.metadata } };
409
+ }
410
+ export function parsingStixgovParseV2(id) {
411
+ const j = _stixgovJsV2.get(id);
412
+ if (!j) throw new Error(`stixgov parse ${id} not found`);
413
+ _stixgovCheckJ(j.status, STIXGOV_PARSE_LIFECYCLE_V2.PARSING);
414
+ const now = Date.now();
415
+ j.status = STIXGOV_PARSE_LIFECYCLE_V2.PARSING;
416
+ j.updatedAt = now;
417
+ if (!j.startedAt) j.startedAt = now;
418
+ return { ...j, metadata: { ...j.metadata } };
419
+ }
420
+ export function completeParseStixgovV2(id) {
421
+ const j = _stixgovJsV2.get(id);
422
+ if (!j) throw new Error(`stixgov parse ${id} not found`);
423
+ _stixgovCheckJ(j.status, STIXGOV_PARSE_LIFECYCLE_V2.PARSED);
424
+ const now = Date.now();
425
+ j.status = STIXGOV_PARSE_LIFECYCLE_V2.PARSED;
426
+ j.updatedAt = now;
427
+ if (!j.settledAt) j.settledAt = now;
428
+ return { ...j, metadata: { ...j.metadata } };
429
+ }
430
+ export function failStixgovParseV2(id, reason) {
431
+ const j = _stixgovJsV2.get(id);
432
+ if (!j) throw new Error(`stixgov parse ${id} not found`);
433
+ _stixgovCheckJ(j.status, STIXGOV_PARSE_LIFECYCLE_V2.FAILED);
434
+ const now = Date.now();
435
+ j.status = STIXGOV_PARSE_LIFECYCLE_V2.FAILED;
436
+ j.updatedAt = now;
437
+ if (!j.settledAt) j.settledAt = now;
438
+ if (reason) j.metadata.failReason = String(reason);
439
+ return { ...j, metadata: { ...j.metadata } };
440
+ }
441
+ export function cancelStixgovParseV2(id, reason) {
442
+ const j = _stixgovJsV2.get(id);
443
+ if (!j) throw new Error(`stixgov parse ${id} not found`);
444
+ _stixgovCheckJ(j.status, STIXGOV_PARSE_LIFECYCLE_V2.CANCELLED);
445
+ const now = Date.now();
446
+ j.status = STIXGOV_PARSE_LIFECYCLE_V2.CANCELLED;
447
+ j.updatedAt = now;
448
+ if (!j.settledAt) j.settledAt = now;
449
+ if (reason) j.metadata.cancelReason = String(reason);
450
+ return { ...j, metadata: { ...j.metadata } };
451
+ }
452
+ export function getStixgovParseV2(id) {
453
+ const j = _stixgovJsV2.get(id);
454
+ if (!j) return null;
455
+ return { ...j, metadata: { ...j.metadata } };
456
+ }
457
+ export function listStixgovParsesV2() {
458
+ return [..._stixgovJsV2.values()].map((j) => ({
459
+ ...j,
460
+ metadata: { ...j.metadata },
461
+ }));
462
+ }
463
+ export function autoStaleIdleStixgovProfilesV2({ now } = {}) {
464
+ const t = now ?? Date.now();
465
+ const flipped = [];
466
+ for (const p of _stixgovPsV2.values())
467
+ if (
468
+ p.status === STIXGOV_PROFILE_MATURITY_V2.ACTIVE &&
469
+ t - p.lastTouchedAt >= _stixgovIdleMs
470
+ ) {
471
+ p.status = STIXGOV_PROFILE_MATURITY_V2.STALE;
472
+ p.updatedAt = t;
473
+ flipped.push(p.id);
474
+ }
475
+ return { flipped, count: flipped.length };
476
+ }
477
+ export function autoFailStuckStixgovParsesV2({ now } = {}) {
478
+ const t = now ?? Date.now();
479
+ const flipped = [];
480
+ for (const j of _stixgovJsV2.values())
481
+ if (
482
+ j.status === STIXGOV_PARSE_LIFECYCLE_V2.PARSING &&
483
+ j.startedAt != null &&
484
+ t - j.startedAt >= _stixgovStuckMs
485
+ ) {
486
+ j.status = STIXGOV_PARSE_LIFECYCLE_V2.FAILED;
487
+ j.updatedAt = t;
488
+ if (!j.settledAt) j.settledAt = t;
489
+ j.metadata.failReason = "auto-fail-stuck";
490
+ flipped.push(j.id);
491
+ }
492
+ return { flipped, count: flipped.length };
493
+ }
494
+ export function getStixParserGovStatsV2() {
495
+ const profilesByStatus = {};
496
+ for (const v of Object.values(STIXGOV_PROFILE_MATURITY_V2))
497
+ profilesByStatus[v] = 0;
498
+ for (const p of _stixgovPsV2.values()) profilesByStatus[p.status]++;
499
+ const parsesByStatus = {};
500
+ for (const v of Object.values(STIXGOV_PARSE_LIFECYCLE_V2))
501
+ parsesByStatus[v] = 0;
502
+ for (const j of _stixgovJsV2.values()) parsesByStatus[j.status]++;
503
+ return {
504
+ totalStixgovProfilesV2: _stixgovPsV2.size,
505
+ totalStixgovParsesV2: _stixgovJsV2.size,
506
+ maxActiveStixgovProfilesPerOwner: _stixgovMaxActive,
507
+ maxPendingStixgovParsesPerProfile: _stixgovMaxPending,
508
+ stixgovProfileIdleMs: _stixgovIdleMs,
509
+ stixgovParseStuckMs: _stixgovStuckMs,
510
+ profilesByStatus,
511
+ parsesByStatus,
512
+ };
513
+ }