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
@@ -964,3 +964,337 @@ export function getActivityPubBridgeStatsV2() {
964
964
  activitiesByStatus,
965
965
  };
966
966
  }
967
+
968
+ // =====================================================================
969
+ // activitypub-bridge V2 governance overlay (iter21)
970
+ // =====================================================================
971
+ export const APGOV_PROFILE_MATURITY_V2 = Object.freeze({
972
+ PENDING: "pending",
973
+ ACTIVE: "active",
974
+ SUSPENDED: "suspended",
975
+ ARCHIVED: "archived",
976
+ });
977
+ export const APGOV_DELIVERY_LIFECYCLE_V2 = Object.freeze({
978
+ QUEUED: "queued",
979
+ DELIVERING: "delivering",
980
+ DELIVERED: "delivered",
981
+ FAILED: "failed",
982
+ CANCELLED: "cancelled",
983
+ });
984
+ const _apgovPTrans = new Map([
985
+ [
986
+ APGOV_PROFILE_MATURITY_V2.PENDING,
987
+ new Set([
988
+ APGOV_PROFILE_MATURITY_V2.ACTIVE,
989
+ APGOV_PROFILE_MATURITY_V2.ARCHIVED,
990
+ ]),
991
+ ],
992
+ [
993
+ APGOV_PROFILE_MATURITY_V2.ACTIVE,
994
+ new Set([
995
+ APGOV_PROFILE_MATURITY_V2.SUSPENDED,
996
+ APGOV_PROFILE_MATURITY_V2.ARCHIVED,
997
+ ]),
998
+ ],
999
+ [
1000
+ APGOV_PROFILE_MATURITY_V2.SUSPENDED,
1001
+ new Set([
1002
+ APGOV_PROFILE_MATURITY_V2.ACTIVE,
1003
+ APGOV_PROFILE_MATURITY_V2.ARCHIVED,
1004
+ ]),
1005
+ ],
1006
+ [APGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1007
+ ]);
1008
+ const _apgovPTerminal = new Set([APGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1009
+ const _apgovJTrans = new Map([
1010
+ [
1011
+ APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
1012
+ new Set([
1013
+ APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
1014
+ APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
1015
+ ]),
1016
+ ],
1017
+ [
1018
+ APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING,
1019
+ new Set([
1020
+ APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED,
1021
+ APGOV_DELIVERY_LIFECYCLE_V2.FAILED,
1022
+ APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED,
1023
+ ]),
1024
+ ],
1025
+ [APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED, new Set()],
1026
+ [APGOV_DELIVERY_LIFECYCLE_V2.FAILED, new Set()],
1027
+ [APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED, new Set()],
1028
+ ]);
1029
+ const _apgovPsV2 = new Map();
1030
+ const _apgovJsV2 = new Map();
1031
+ let _apgovMaxActive = 8,
1032
+ _apgovMaxPending = 25,
1033
+ _apgovIdleMs = 30 * 24 * 60 * 60 * 1000,
1034
+ _apgovStuckMs = 60 * 1000;
1035
+ function _apgovPos(n, label) {
1036
+ const v = Math.floor(Number(n));
1037
+ if (!Number.isFinite(v) || v <= 0)
1038
+ throw new Error(`${label} must be positive integer`);
1039
+ return v;
1040
+ }
1041
+ function _apgovCheckP(from, to) {
1042
+ const a = _apgovPTrans.get(from);
1043
+ if (!a || !a.has(to))
1044
+ throw new Error(`invalid apgov profile transition ${from} → ${to}`);
1045
+ }
1046
+ function _apgovCheckJ(from, to) {
1047
+ const a = _apgovJTrans.get(from);
1048
+ if (!a || !a.has(to))
1049
+ throw new Error(`invalid apgov delivery transition ${from} → ${to}`);
1050
+ }
1051
+ function _apgovCountActive(owner) {
1052
+ let c = 0;
1053
+ for (const p of _apgovPsV2.values())
1054
+ if (p.owner === owner && p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
1055
+ return c;
1056
+ }
1057
+ function _apgovCountPending(profileId) {
1058
+ let c = 0;
1059
+ for (const j of _apgovJsV2.values())
1060
+ if (
1061
+ j.profileId === profileId &&
1062
+ (j.status === APGOV_DELIVERY_LIFECYCLE_V2.QUEUED ||
1063
+ j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING)
1064
+ )
1065
+ c++;
1066
+ return c;
1067
+ }
1068
+ export function setMaxActiveApgovProfilesPerOwnerV2(n) {
1069
+ _apgovMaxActive = _apgovPos(n, "maxActiveApgovProfilesPerOwner");
1070
+ }
1071
+ export function getMaxActiveApgovProfilesPerOwnerV2() {
1072
+ return _apgovMaxActive;
1073
+ }
1074
+ export function setMaxPendingApgovDeliverysPerProfileV2(n) {
1075
+ _apgovMaxPending = _apgovPos(n, "maxPendingApgovDeliverysPerProfile");
1076
+ }
1077
+ export function getMaxPendingApgovDeliverysPerProfileV2() {
1078
+ return _apgovMaxPending;
1079
+ }
1080
+ export function setApgovProfileIdleMsV2(n) {
1081
+ _apgovIdleMs = _apgovPos(n, "apgovProfileIdleMs");
1082
+ }
1083
+ export function getApgovProfileIdleMsV2() {
1084
+ return _apgovIdleMs;
1085
+ }
1086
+ export function setApgovDeliveryStuckMsV2(n) {
1087
+ _apgovStuckMs = _apgovPos(n, "apgovDeliveryStuckMs");
1088
+ }
1089
+ export function getApgovDeliveryStuckMsV2() {
1090
+ return _apgovStuckMs;
1091
+ }
1092
+ export function _resetStateActivityPubBridgeGovV2() {
1093
+ _apgovPsV2.clear();
1094
+ _apgovJsV2.clear();
1095
+ _apgovMaxActive = 8;
1096
+ _apgovMaxPending = 25;
1097
+ _apgovIdleMs = 30 * 24 * 60 * 60 * 1000;
1098
+ _apgovStuckMs = 60 * 1000;
1099
+ }
1100
+ export function registerApgovProfileV2({ id, owner, actor, metadata } = {}) {
1101
+ if (!id || !owner) throw new Error("id and owner required");
1102
+ if (_apgovPsV2.has(id)) throw new Error(`apgov profile ${id} already exists`);
1103
+ const now = Date.now();
1104
+ const p = {
1105
+ id,
1106
+ owner,
1107
+ actor: actor || "person",
1108
+ status: APGOV_PROFILE_MATURITY_V2.PENDING,
1109
+ createdAt: now,
1110
+ updatedAt: now,
1111
+ lastTouchedAt: now,
1112
+ activatedAt: null,
1113
+ archivedAt: null,
1114
+ metadata: { ...(metadata || {}) },
1115
+ };
1116
+ _apgovPsV2.set(id, p);
1117
+ return { ...p, metadata: { ...p.metadata } };
1118
+ }
1119
+ export function activateApgovProfileV2(id) {
1120
+ const p = _apgovPsV2.get(id);
1121
+ if (!p) throw new Error(`apgov profile ${id} not found`);
1122
+ const isInitial = p.status === APGOV_PROFILE_MATURITY_V2.PENDING;
1123
+ _apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ACTIVE);
1124
+ if (isInitial && _apgovCountActive(p.owner) >= _apgovMaxActive)
1125
+ throw new Error(`max active apgov profiles for owner ${p.owner} reached`);
1126
+ const now = Date.now();
1127
+ p.status = APGOV_PROFILE_MATURITY_V2.ACTIVE;
1128
+ p.updatedAt = now;
1129
+ p.lastTouchedAt = now;
1130
+ if (!p.activatedAt) p.activatedAt = now;
1131
+ return { ...p, metadata: { ...p.metadata } };
1132
+ }
1133
+ export function suspendApgovProfileV2(id) {
1134
+ const p = _apgovPsV2.get(id);
1135
+ if (!p) throw new Error(`apgov profile ${id} not found`);
1136
+ _apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.SUSPENDED);
1137
+ p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
1138
+ p.updatedAt = Date.now();
1139
+ return { ...p, metadata: { ...p.metadata } };
1140
+ }
1141
+ export function archiveApgovProfileV2(id) {
1142
+ const p = _apgovPsV2.get(id);
1143
+ if (!p) throw new Error(`apgov profile ${id} not found`);
1144
+ _apgovCheckP(p.status, APGOV_PROFILE_MATURITY_V2.ARCHIVED);
1145
+ const now = Date.now();
1146
+ p.status = APGOV_PROFILE_MATURITY_V2.ARCHIVED;
1147
+ p.updatedAt = now;
1148
+ if (!p.archivedAt) p.archivedAt = now;
1149
+ return { ...p, metadata: { ...p.metadata } };
1150
+ }
1151
+ export function touchApgovProfileV2(id) {
1152
+ const p = _apgovPsV2.get(id);
1153
+ if (!p) throw new Error(`apgov profile ${id} not found`);
1154
+ if (_apgovPTerminal.has(p.status))
1155
+ throw new Error(`cannot touch terminal apgov profile ${id}`);
1156
+ const now = Date.now();
1157
+ p.lastTouchedAt = now;
1158
+ p.updatedAt = now;
1159
+ return { ...p, metadata: { ...p.metadata } };
1160
+ }
1161
+ export function getApgovProfileV2(id) {
1162
+ const p = _apgovPsV2.get(id);
1163
+ if (!p) return null;
1164
+ return { ...p, metadata: { ...p.metadata } };
1165
+ }
1166
+ export function listApgovProfilesV2() {
1167
+ return [..._apgovPsV2.values()].map((p) => ({
1168
+ ...p,
1169
+ metadata: { ...p.metadata },
1170
+ }));
1171
+ }
1172
+ export function createApgovDeliveryV2({ id, profileId, inbox, metadata } = {}) {
1173
+ if (!id || !profileId) throw new Error("id and profileId required");
1174
+ if (_apgovJsV2.has(id))
1175
+ throw new Error(`apgov delivery ${id} already exists`);
1176
+ if (!_apgovPsV2.has(profileId))
1177
+ throw new Error(`apgov profile ${profileId} not found`);
1178
+ if (_apgovCountPending(profileId) >= _apgovMaxPending)
1179
+ throw new Error(
1180
+ `max pending apgov deliverys for profile ${profileId} reached`,
1181
+ );
1182
+ const now = Date.now();
1183
+ const j = {
1184
+ id,
1185
+ profileId,
1186
+ inbox: inbox || "",
1187
+ status: APGOV_DELIVERY_LIFECYCLE_V2.QUEUED,
1188
+ createdAt: now,
1189
+ updatedAt: now,
1190
+ startedAt: null,
1191
+ settledAt: null,
1192
+ metadata: { ...(metadata || {}) },
1193
+ };
1194
+ _apgovJsV2.set(id, j);
1195
+ return { ...j, metadata: { ...j.metadata } };
1196
+ }
1197
+ export function deliveringApgovDeliveryV2(id) {
1198
+ const j = _apgovJsV2.get(id);
1199
+ if (!j) throw new Error(`apgov delivery ${id} not found`);
1200
+ _apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING);
1201
+ const now = Date.now();
1202
+ j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING;
1203
+ j.updatedAt = now;
1204
+ if (!j.startedAt) j.startedAt = now;
1205
+ return { ...j, metadata: { ...j.metadata } };
1206
+ }
1207
+ export function completeDeliveryApgovV2(id) {
1208
+ const j = _apgovJsV2.get(id);
1209
+ if (!j) throw new Error(`apgov delivery ${id} not found`);
1210
+ _apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED);
1211
+ const now = Date.now();
1212
+ j.status = APGOV_DELIVERY_LIFECYCLE_V2.DELIVERED;
1213
+ j.updatedAt = now;
1214
+ if (!j.settledAt) j.settledAt = now;
1215
+ return { ...j, metadata: { ...j.metadata } };
1216
+ }
1217
+ export function failApgovDeliveryV2(id, reason) {
1218
+ const j = _apgovJsV2.get(id);
1219
+ if (!j) throw new Error(`apgov delivery ${id} not found`);
1220
+ _apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.FAILED);
1221
+ const now = Date.now();
1222
+ j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
1223
+ j.updatedAt = now;
1224
+ if (!j.settledAt) j.settledAt = now;
1225
+ if (reason) j.metadata.failReason = String(reason);
1226
+ return { ...j, metadata: { ...j.metadata } };
1227
+ }
1228
+ export function cancelApgovDeliveryV2(id, reason) {
1229
+ const j = _apgovJsV2.get(id);
1230
+ if (!j) throw new Error(`apgov delivery ${id} not found`);
1231
+ _apgovCheckJ(j.status, APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED);
1232
+ const now = Date.now();
1233
+ j.status = APGOV_DELIVERY_LIFECYCLE_V2.CANCELLED;
1234
+ j.updatedAt = now;
1235
+ if (!j.settledAt) j.settledAt = now;
1236
+ if (reason) j.metadata.cancelReason = String(reason);
1237
+ return { ...j, metadata: { ...j.metadata } };
1238
+ }
1239
+ export function getApgovDeliveryV2(id) {
1240
+ const j = _apgovJsV2.get(id);
1241
+ if (!j) return null;
1242
+ return { ...j, metadata: { ...j.metadata } };
1243
+ }
1244
+ export function listApgovDeliverysV2() {
1245
+ return [..._apgovJsV2.values()].map((j) => ({
1246
+ ...j,
1247
+ metadata: { ...j.metadata },
1248
+ }));
1249
+ }
1250
+ export function autoSuspendIdleApgovProfilesV2({ now } = {}) {
1251
+ const t = now ?? Date.now();
1252
+ const flipped = [];
1253
+ for (const p of _apgovPsV2.values())
1254
+ if (
1255
+ p.status === APGOV_PROFILE_MATURITY_V2.ACTIVE &&
1256
+ t - p.lastTouchedAt >= _apgovIdleMs
1257
+ ) {
1258
+ p.status = APGOV_PROFILE_MATURITY_V2.SUSPENDED;
1259
+ p.updatedAt = t;
1260
+ flipped.push(p.id);
1261
+ }
1262
+ return { flipped, count: flipped.length };
1263
+ }
1264
+ export function autoFailStuckApgovDeliverysV2({ now } = {}) {
1265
+ const t = now ?? Date.now();
1266
+ const flipped = [];
1267
+ for (const j of _apgovJsV2.values())
1268
+ if (
1269
+ j.status === APGOV_DELIVERY_LIFECYCLE_V2.DELIVERING &&
1270
+ j.startedAt != null &&
1271
+ t - j.startedAt >= _apgovStuckMs
1272
+ ) {
1273
+ j.status = APGOV_DELIVERY_LIFECYCLE_V2.FAILED;
1274
+ j.updatedAt = t;
1275
+ if (!j.settledAt) j.settledAt = t;
1276
+ j.metadata.failReason = "auto-fail-stuck";
1277
+ flipped.push(j.id);
1278
+ }
1279
+ return { flipped, count: flipped.length };
1280
+ }
1281
+ export function getActivityPubBridgeGovStatsV2() {
1282
+ const profilesByStatus = {};
1283
+ for (const v of Object.values(APGOV_PROFILE_MATURITY_V2))
1284
+ profilesByStatus[v] = 0;
1285
+ for (const p of _apgovPsV2.values()) profilesByStatus[p.status]++;
1286
+ const deliverysByStatus = {};
1287
+ for (const v of Object.values(APGOV_DELIVERY_LIFECYCLE_V2))
1288
+ deliverysByStatus[v] = 0;
1289
+ for (const j of _apgovJsV2.values()) deliverysByStatus[j.status]++;
1290
+ return {
1291
+ totalApgovProfilesV2: _apgovPsV2.size,
1292
+ totalApgovDeliverysV2: _apgovJsV2.size,
1293
+ maxActiveApgovProfilesPerOwner: _apgovMaxActive,
1294
+ maxPendingApgovDeliverysPerProfile: _apgovMaxPending,
1295
+ apgovProfileIdleMs: _apgovIdleMs,
1296
+ apgovDeliveryStuckMs: _apgovStuckMs,
1297
+ profilesByStatus,
1298
+ deliverysByStatus,
1299
+ };
1300
+ }
@@ -707,3 +707,337 @@ export function getAgentCoordinatorStatsV2() {
707
707
  assignmentsByStatus,
708
708
  };
709
709
  }
710
+
711
+ // === Iter28 V2 governance overlay: Acrdgov ===
712
+ export const ACRDGOV_PROFILE_MATURITY_V2 = Object.freeze({
713
+ PENDING: "pending",
714
+ ACTIVE: "active",
715
+ IDLE: "idle",
716
+ ARCHIVED: "archived",
717
+ });
718
+ export const ACRDGOV_COORD_LIFECYCLE_V2 = Object.freeze({
719
+ QUEUED: "queued",
720
+ COORDINATING: "coordinating",
721
+ COORDINATED: "coordinated",
722
+ FAILED: "failed",
723
+ CANCELLED: "cancelled",
724
+ });
725
+ const _acrdgovPTrans = new Map([
726
+ [
727
+ ACRDGOV_PROFILE_MATURITY_V2.PENDING,
728
+ new Set([
729
+ ACRDGOV_PROFILE_MATURITY_V2.ACTIVE,
730
+ ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED,
731
+ ]),
732
+ ],
733
+ [
734
+ ACRDGOV_PROFILE_MATURITY_V2.ACTIVE,
735
+ new Set([
736
+ ACRDGOV_PROFILE_MATURITY_V2.IDLE,
737
+ ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED,
738
+ ]),
739
+ ],
740
+ [
741
+ ACRDGOV_PROFILE_MATURITY_V2.IDLE,
742
+ new Set([
743
+ ACRDGOV_PROFILE_MATURITY_V2.ACTIVE,
744
+ ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED,
745
+ ]),
746
+ ],
747
+ [ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
748
+ ]);
749
+ const _acrdgovPTerminal = new Set([ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED]);
750
+ const _acrdgovJTrans = new Map([
751
+ [
752
+ ACRDGOV_COORD_LIFECYCLE_V2.QUEUED,
753
+ new Set([
754
+ ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING,
755
+ ACRDGOV_COORD_LIFECYCLE_V2.CANCELLED,
756
+ ]),
757
+ ],
758
+ [
759
+ ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING,
760
+ new Set([
761
+ ACRDGOV_COORD_LIFECYCLE_V2.COORDINATED,
762
+ ACRDGOV_COORD_LIFECYCLE_V2.FAILED,
763
+ ACRDGOV_COORD_LIFECYCLE_V2.CANCELLED,
764
+ ]),
765
+ ],
766
+ [ACRDGOV_COORD_LIFECYCLE_V2.COORDINATED, new Set()],
767
+ [ACRDGOV_COORD_LIFECYCLE_V2.FAILED, new Set()],
768
+ [ACRDGOV_COORD_LIFECYCLE_V2.CANCELLED, new Set()],
769
+ ]);
770
+ const _acrdgovPsV2 = new Map();
771
+ const _acrdgovJsV2 = new Map();
772
+ let _acrdgovMaxActive = 6,
773
+ _acrdgovMaxPending = 15,
774
+ _acrdgovIdleMs = 2592000000,
775
+ _acrdgovStuckMs = 60 * 1000;
776
+ function _acrdgovPos(n, label) {
777
+ const v = Math.floor(Number(n));
778
+ if (!Number.isFinite(v) || v <= 0)
779
+ throw new Error(`${label} must be positive integer`);
780
+ return v;
781
+ }
782
+ function _acrdgovCheckP(from, to) {
783
+ const a = _acrdgovPTrans.get(from);
784
+ if (!a || !a.has(to))
785
+ throw new Error(`invalid acrdgov profile transition ${from} → ${to}`);
786
+ }
787
+ function _acrdgovCheckJ(from, to) {
788
+ const a = _acrdgovJTrans.get(from);
789
+ if (!a || !a.has(to))
790
+ throw new Error(`invalid acrdgov coord transition ${from} → ${to}`);
791
+ }
792
+ function _acrdgovCountActive(owner) {
793
+ let c = 0;
794
+ for (const p of _acrdgovPsV2.values())
795
+ if (p.owner === owner && p.status === ACRDGOV_PROFILE_MATURITY_V2.ACTIVE)
796
+ c++;
797
+ return c;
798
+ }
799
+ function _acrdgovCountPending(profileId) {
800
+ let c = 0;
801
+ for (const j of _acrdgovJsV2.values())
802
+ if (
803
+ j.profileId === profileId &&
804
+ (j.status === ACRDGOV_COORD_LIFECYCLE_V2.QUEUED ||
805
+ j.status === ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING)
806
+ )
807
+ c++;
808
+ return c;
809
+ }
810
+ export function setMaxActiveAcrdProfilesPerOwnerV2(n) {
811
+ _acrdgovMaxActive = _acrdgovPos(n, "maxActiveAcrdProfilesPerOwner");
812
+ }
813
+ export function getMaxActiveAcrdProfilesPerOwnerV2() {
814
+ return _acrdgovMaxActive;
815
+ }
816
+ export function setMaxPendingAcrdCoordsPerProfileV2(n) {
817
+ _acrdgovMaxPending = _acrdgovPos(n, "maxPendingAcrdCoordsPerProfile");
818
+ }
819
+ export function getMaxPendingAcrdCoordsPerProfileV2() {
820
+ return _acrdgovMaxPending;
821
+ }
822
+ export function setAcrdProfileIdleMsV2(n) {
823
+ _acrdgovIdleMs = _acrdgovPos(n, "acrdgovProfileIdleMs");
824
+ }
825
+ export function getAcrdProfileIdleMsV2() {
826
+ return _acrdgovIdleMs;
827
+ }
828
+ export function setAcrdCoordStuckMsV2(n) {
829
+ _acrdgovStuckMs = _acrdgovPos(n, "acrdgovCoordStuckMs");
830
+ }
831
+ export function getAcrdCoordStuckMsV2() {
832
+ return _acrdgovStuckMs;
833
+ }
834
+ export function _resetStateAcrdgovV2() {
835
+ _acrdgovPsV2.clear();
836
+ _acrdgovJsV2.clear();
837
+ _acrdgovMaxActive = 6;
838
+ _acrdgovMaxPending = 15;
839
+ _acrdgovIdleMs = 2592000000;
840
+ _acrdgovStuckMs = 60 * 1000;
841
+ }
842
+ export function registerAcrdProfileV2({ id, owner, role, metadata } = {}) {
843
+ if (!id || !owner) throw new Error("id and owner required");
844
+ if (_acrdgovPsV2.has(id))
845
+ throw new Error(`acrdgov profile ${id} already exists`);
846
+ const now = Date.now();
847
+ const p = {
848
+ id,
849
+ owner,
850
+ role: role || "leader",
851
+ status: ACRDGOV_PROFILE_MATURITY_V2.PENDING,
852
+ createdAt: now,
853
+ updatedAt: now,
854
+ lastTouchedAt: now,
855
+ activatedAt: null,
856
+ archivedAt: null,
857
+ metadata: { ...(metadata || {}) },
858
+ };
859
+ _acrdgovPsV2.set(id, p);
860
+ return { ...p, metadata: { ...p.metadata } };
861
+ }
862
+ export function activateAcrdProfileV2(id) {
863
+ const p = _acrdgovPsV2.get(id);
864
+ if (!p) throw new Error(`acrdgov profile ${id} not found`);
865
+ const isInitial = p.status === ACRDGOV_PROFILE_MATURITY_V2.PENDING;
866
+ _acrdgovCheckP(p.status, ACRDGOV_PROFILE_MATURITY_V2.ACTIVE);
867
+ if (isInitial && _acrdgovCountActive(p.owner) >= _acrdgovMaxActive)
868
+ throw new Error(`max active acrdgov profiles for owner ${p.owner} reached`);
869
+ const now = Date.now();
870
+ p.status = ACRDGOV_PROFILE_MATURITY_V2.ACTIVE;
871
+ p.updatedAt = now;
872
+ p.lastTouchedAt = now;
873
+ if (!p.activatedAt) p.activatedAt = now;
874
+ return { ...p, metadata: { ...p.metadata } };
875
+ }
876
+ export function idleAcrdProfileV2(id) {
877
+ const p = _acrdgovPsV2.get(id);
878
+ if (!p) throw new Error(`acrdgov profile ${id} not found`);
879
+ _acrdgovCheckP(p.status, ACRDGOV_PROFILE_MATURITY_V2.IDLE);
880
+ p.status = ACRDGOV_PROFILE_MATURITY_V2.IDLE;
881
+ p.updatedAt = Date.now();
882
+ return { ...p, metadata: { ...p.metadata } };
883
+ }
884
+ export function archiveAcrdProfileV2(id) {
885
+ const p = _acrdgovPsV2.get(id);
886
+ if (!p) throw new Error(`acrdgov profile ${id} not found`);
887
+ _acrdgovCheckP(p.status, ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED);
888
+ const now = Date.now();
889
+ p.status = ACRDGOV_PROFILE_MATURITY_V2.ARCHIVED;
890
+ p.updatedAt = now;
891
+ if (!p.archivedAt) p.archivedAt = now;
892
+ return { ...p, metadata: { ...p.metadata } };
893
+ }
894
+ export function touchAcrdProfileV2(id) {
895
+ const p = _acrdgovPsV2.get(id);
896
+ if (!p) throw new Error(`acrdgov profile ${id} not found`);
897
+ if (_acrdgovPTerminal.has(p.status))
898
+ throw new Error(`cannot touch terminal acrdgov profile ${id}`);
899
+ const now = Date.now();
900
+ p.lastTouchedAt = now;
901
+ p.updatedAt = now;
902
+ return { ...p, metadata: { ...p.metadata } };
903
+ }
904
+ export function getAcrdProfileV2(id) {
905
+ const p = _acrdgovPsV2.get(id);
906
+ if (!p) return null;
907
+ return { ...p, metadata: { ...p.metadata } };
908
+ }
909
+ export function listAcrdProfilesV2() {
910
+ return [..._acrdgovPsV2.values()].map((p) => ({
911
+ ...p,
912
+ metadata: { ...p.metadata },
913
+ }));
914
+ }
915
+ export function createAcrdCoordV2({ id, profileId, taskId, metadata } = {}) {
916
+ if (!id || !profileId) throw new Error("id and profileId required");
917
+ if (_acrdgovJsV2.has(id))
918
+ throw new Error(`acrdgov coord ${id} already exists`);
919
+ if (!_acrdgovPsV2.has(profileId))
920
+ throw new Error(`acrdgov profile ${profileId} not found`);
921
+ if (_acrdgovCountPending(profileId) >= _acrdgovMaxPending)
922
+ throw new Error(
923
+ `max pending acrdgov coords for profile ${profileId} reached`,
924
+ );
925
+ const now = Date.now();
926
+ const j = {
927
+ id,
928
+ profileId,
929
+ taskId: taskId || "",
930
+ status: ACRDGOV_COORD_LIFECYCLE_V2.QUEUED,
931
+ createdAt: now,
932
+ updatedAt: now,
933
+ startedAt: null,
934
+ settledAt: null,
935
+ metadata: { ...(metadata || {}) },
936
+ };
937
+ _acrdgovJsV2.set(id, j);
938
+ return { ...j, metadata: { ...j.metadata } };
939
+ }
940
+ export function coordinatingAcrdCoordV2(id) {
941
+ const j = _acrdgovJsV2.get(id);
942
+ if (!j) throw new Error(`acrdgov coord ${id} not found`);
943
+ _acrdgovCheckJ(j.status, ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING);
944
+ const now = Date.now();
945
+ j.status = ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING;
946
+ j.updatedAt = now;
947
+ if (!j.startedAt) j.startedAt = now;
948
+ return { ...j, metadata: { ...j.metadata } };
949
+ }
950
+ export function completeCoordAcrdV2(id) {
951
+ const j = _acrdgovJsV2.get(id);
952
+ if (!j) throw new Error(`acrdgov coord ${id} not found`);
953
+ _acrdgovCheckJ(j.status, ACRDGOV_COORD_LIFECYCLE_V2.COORDINATED);
954
+ const now = Date.now();
955
+ j.status = ACRDGOV_COORD_LIFECYCLE_V2.COORDINATED;
956
+ j.updatedAt = now;
957
+ if (!j.settledAt) j.settledAt = now;
958
+ return { ...j, metadata: { ...j.metadata } };
959
+ }
960
+ export function failAcrdCoordV2(id, reason) {
961
+ const j = _acrdgovJsV2.get(id);
962
+ if (!j) throw new Error(`acrdgov coord ${id} not found`);
963
+ _acrdgovCheckJ(j.status, ACRDGOV_COORD_LIFECYCLE_V2.FAILED);
964
+ const now = Date.now();
965
+ j.status = ACRDGOV_COORD_LIFECYCLE_V2.FAILED;
966
+ j.updatedAt = now;
967
+ if (!j.settledAt) j.settledAt = now;
968
+ if (reason) j.metadata.failReason = String(reason);
969
+ return { ...j, metadata: { ...j.metadata } };
970
+ }
971
+ export function cancelAcrdCoordV2(id, reason) {
972
+ const j = _acrdgovJsV2.get(id);
973
+ if (!j) throw new Error(`acrdgov coord ${id} not found`);
974
+ _acrdgovCheckJ(j.status, ACRDGOV_COORD_LIFECYCLE_V2.CANCELLED);
975
+ const now = Date.now();
976
+ j.status = ACRDGOV_COORD_LIFECYCLE_V2.CANCELLED;
977
+ j.updatedAt = now;
978
+ if (!j.settledAt) j.settledAt = now;
979
+ if (reason) j.metadata.cancelReason = String(reason);
980
+ return { ...j, metadata: { ...j.metadata } };
981
+ }
982
+ export function getAcrdCoordV2(id) {
983
+ const j = _acrdgovJsV2.get(id);
984
+ if (!j) return null;
985
+ return { ...j, metadata: { ...j.metadata } };
986
+ }
987
+ export function listAcrdCoordsV2() {
988
+ return [..._acrdgovJsV2.values()].map((j) => ({
989
+ ...j,
990
+ metadata: { ...j.metadata },
991
+ }));
992
+ }
993
+ export function autoIdleIdleAcrdProfilesV2({ now } = {}) {
994
+ const t = now ?? Date.now();
995
+ const flipped = [];
996
+ for (const p of _acrdgovPsV2.values())
997
+ if (
998
+ p.status === ACRDGOV_PROFILE_MATURITY_V2.ACTIVE &&
999
+ t - p.lastTouchedAt >= _acrdgovIdleMs
1000
+ ) {
1001
+ p.status = ACRDGOV_PROFILE_MATURITY_V2.IDLE;
1002
+ p.updatedAt = t;
1003
+ flipped.push(p.id);
1004
+ }
1005
+ return { flipped, count: flipped.length };
1006
+ }
1007
+ export function autoFailStuckAcrdCoordsV2({ now } = {}) {
1008
+ const t = now ?? Date.now();
1009
+ const flipped = [];
1010
+ for (const j of _acrdgovJsV2.values())
1011
+ if (
1012
+ j.status === ACRDGOV_COORD_LIFECYCLE_V2.COORDINATING &&
1013
+ j.startedAt != null &&
1014
+ t - j.startedAt >= _acrdgovStuckMs
1015
+ ) {
1016
+ j.status = ACRDGOV_COORD_LIFECYCLE_V2.FAILED;
1017
+ j.updatedAt = t;
1018
+ if (!j.settledAt) j.settledAt = t;
1019
+ j.metadata.failReason = "auto-fail-stuck";
1020
+ flipped.push(j.id);
1021
+ }
1022
+ return { flipped, count: flipped.length };
1023
+ }
1024
+ export function getAcrdgovStatsV2() {
1025
+ const profilesByStatus = {};
1026
+ for (const v of Object.values(ACRDGOV_PROFILE_MATURITY_V2))
1027
+ profilesByStatus[v] = 0;
1028
+ for (const p of _acrdgovPsV2.values()) profilesByStatus[p.status]++;
1029
+ const coordsByStatus = {};
1030
+ for (const v of Object.values(ACRDGOV_COORD_LIFECYCLE_V2))
1031
+ coordsByStatus[v] = 0;
1032
+ for (const j of _acrdgovJsV2.values()) coordsByStatus[j.status]++;
1033
+ return {
1034
+ totalAcrdProfilesV2: _acrdgovPsV2.size,
1035
+ totalAcrdCoordsV2: _acrdgovJsV2.size,
1036
+ maxActiveAcrdProfilesPerOwner: _acrdgovMaxActive,
1037
+ maxPendingAcrdCoordsPerProfile: _acrdgovMaxPending,
1038
+ acrdgovProfileIdleMs: _acrdgovIdleMs,
1039
+ acrdgovCoordStuckMs: _acrdgovStuckMs,
1040
+ profilesByStatus,
1041
+ coordsByStatus,
1042
+ };
1043
+ }