chainlesschain 0.143.0 → 0.152.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 (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -1030,3 +1030,344 @@ export function getHardeningStatsV2() {
1030
1030
  baselinesByStatus,
1031
1031
  };
1032
1032
  }
1033
+
1034
+ // =====================================================================
1035
+ // hardening-manager V2 governance overlay (iter17)
1036
+ // =====================================================================
1037
+ export const HARDGOV_PROFILE_MATURITY_V2 = Object.freeze({
1038
+ PENDING: "pending",
1039
+ ACTIVE: "active",
1040
+ DISABLED: "disabled",
1041
+ ARCHIVED: "archived",
1042
+ });
1043
+ export const HARDGOV_SCAN_LIFECYCLE_V2 = Object.freeze({
1044
+ QUEUED: "queued",
1045
+ SCANNING: "scanning",
1046
+ SCANNED: "scanned",
1047
+ FAILED: "failed",
1048
+ CANCELLED: "cancelled",
1049
+ });
1050
+ const _hardgovPTrans = new Map([
1051
+ [
1052
+ HARDGOV_PROFILE_MATURITY_V2.PENDING,
1053
+ new Set([
1054
+ HARDGOV_PROFILE_MATURITY_V2.ACTIVE,
1055
+ HARDGOV_PROFILE_MATURITY_V2.ARCHIVED,
1056
+ ]),
1057
+ ],
1058
+ [
1059
+ HARDGOV_PROFILE_MATURITY_V2.ACTIVE,
1060
+ new Set([
1061
+ HARDGOV_PROFILE_MATURITY_V2.DISABLED,
1062
+ HARDGOV_PROFILE_MATURITY_V2.ARCHIVED,
1063
+ ]),
1064
+ ],
1065
+ [
1066
+ HARDGOV_PROFILE_MATURITY_V2.DISABLED,
1067
+ new Set([
1068
+ HARDGOV_PROFILE_MATURITY_V2.ACTIVE,
1069
+ HARDGOV_PROFILE_MATURITY_V2.ARCHIVED,
1070
+ ]),
1071
+ ],
1072
+ [HARDGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
1073
+ ]);
1074
+ const _hardgovPTerminal = new Set([HARDGOV_PROFILE_MATURITY_V2.ARCHIVED]);
1075
+ const _hardgovJTrans = new Map([
1076
+ [
1077
+ HARDGOV_SCAN_LIFECYCLE_V2.QUEUED,
1078
+ new Set([
1079
+ HARDGOV_SCAN_LIFECYCLE_V2.SCANNING,
1080
+ HARDGOV_SCAN_LIFECYCLE_V2.CANCELLED,
1081
+ ]),
1082
+ ],
1083
+ [
1084
+ HARDGOV_SCAN_LIFECYCLE_V2.SCANNING,
1085
+ new Set([
1086
+ HARDGOV_SCAN_LIFECYCLE_V2.SCANNED,
1087
+ HARDGOV_SCAN_LIFECYCLE_V2.FAILED,
1088
+ HARDGOV_SCAN_LIFECYCLE_V2.CANCELLED,
1089
+ ]),
1090
+ ],
1091
+ [HARDGOV_SCAN_LIFECYCLE_V2.SCANNED, new Set()],
1092
+ [HARDGOV_SCAN_LIFECYCLE_V2.FAILED, new Set()],
1093
+ [HARDGOV_SCAN_LIFECYCLE_V2.CANCELLED, new Set()],
1094
+ ]);
1095
+ const _hardgovPsV2 = new Map();
1096
+ const _hardgovJsV2 = new Map();
1097
+ let _hardgovMaxActive = 8,
1098
+ _hardgovMaxPending = 20,
1099
+ _hardgovIdleMs = 30 * 24 * 60 * 60 * 1000,
1100
+ _hardgovStuckMs = 60 * 1000;
1101
+ function _hardgovPos(n, label) {
1102
+ const v = Math.floor(Number(n));
1103
+ if (!Number.isFinite(v) || v <= 0)
1104
+ throw new Error(`${label} must be positive integer`);
1105
+ return v;
1106
+ }
1107
+ function _hardgovCheckP(from, to) {
1108
+ const a = _hardgovPTrans.get(from);
1109
+ if (!a || !a.has(to))
1110
+ throw new Error(`invalid hardgov profile transition ${from} → ${to}`);
1111
+ }
1112
+ function _hardgovCheckJ(from, to) {
1113
+ const a = _hardgovJTrans.get(from);
1114
+ if (!a || !a.has(to))
1115
+ throw new Error(`invalid hardgov scan transition ${from} → ${to}`);
1116
+ }
1117
+ function _hardgovCountActive(owner) {
1118
+ let c = 0;
1119
+ for (const p of _hardgovPsV2.values())
1120
+ if (p.owner === owner && p.status === HARDGOV_PROFILE_MATURITY_V2.ACTIVE)
1121
+ c++;
1122
+ return c;
1123
+ }
1124
+ function _hardgovCountPending(profileId) {
1125
+ let c = 0;
1126
+ for (const j of _hardgovJsV2.values())
1127
+ if (
1128
+ j.profileId === profileId &&
1129
+ (j.status === HARDGOV_SCAN_LIFECYCLE_V2.QUEUED ||
1130
+ j.status === HARDGOV_SCAN_LIFECYCLE_V2.SCANNING)
1131
+ )
1132
+ c++;
1133
+ return c;
1134
+ }
1135
+ export function setMaxActiveHardgovProfilesPerOwnerV2(n) {
1136
+ _hardgovMaxActive = _hardgovPos(n, "maxActiveHardgovProfilesPerOwner");
1137
+ }
1138
+ export function getMaxActiveHardgovProfilesPerOwnerV2() {
1139
+ return _hardgovMaxActive;
1140
+ }
1141
+ export function setMaxPendingHardgovScansPerProfileV2(n) {
1142
+ _hardgovMaxPending = _hardgovPos(n, "maxPendingHardgovScansPerProfile");
1143
+ }
1144
+ export function getMaxPendingHardgovScansPerProfileV2() {
1145
+ return _hardgovMaxPending;
1146
+ }
1147
+ export function setHardgovProfileIdleMsV2(n) {
1148
+ _hardgovIdleMs = _hardgovPos(n, "hardgovProfileIdleMs");
1149
+ }
1150
+ export function getHardgovProfileIdleMsV2() {
1151
+ return _hardgovIdleMs;
1152
+ }
1153
+ export function setHardgovScanStuckMsV2(n) {
1154
+ _hardgovStuckMs = _hardgovPos(n, "hardgovScanStuckMs");
1155
+ }
1156
+ export function getHardgovScanStuckMsV2() {
1157
+ return _hardgovStuckMs;
1158
+ }
1159
+ export function _resetStateHardeningManagerV2() {
1160
+ _hardgovPsV2.clear();
1161
+ _hardgovJsV2.clear();
1162
+ _hardgovMaxActive = 8;
1163
+ _hardgovMaxPending = 20;
1164
+ _hardgovIdleMs = 30 * 24 * 60 * 60 * 1000;
1165
+ _hardgovStuckMs = 60 * 1000;
1166
+ }
1167
+ export function registerHardgovProfileV2({
1168
+ id,
1169
+ owner,
1170
+ category,
1171
+ metadata,
1172
+ } = {}) {
1173
+ if (!id || !owner) throw new Error("id and owner required");
1174
+ if (_hardgovPsV2.has(id))
1175
+ throw new Error(`hardgov profile ${id} already exists`);
1176
+ const now = Date.now();
1177
+ const p = {
1178
+ id,
1179
+ owner,
1180
+ category: category || "system",
1181
+ status: HARDGOV_PROFILE_MATURITY_V2.PENDING,
1182
+ createdAt: now,
1183
+ updatedAt: now,
1184
+ lastTouchedAt: now,
1185
+ activatedAt: null,
1186
+ archivedAt: null,
1187
+ metadata: { ...(metadata || {}) },
1188
+ };
1189
+ _hardgovPsV2.set(id, p);
1190
+ return { ...p, metadata: { ...p.metadata } };
1191
+ }
1192
+ export function activateHardgovProfileV2(id) {
1193
+ const p = _hardgovPsV2.get(id);
1194
+ if (!p) throw new Error(`hardgov profile ${id} not found`);
1195
+ const isInitial = p.status === HARDGOV_PROFILE_MATURITY_V2.PENDING;
1196
+ _hardgovCheckP(p.status, HARDGOV_PROFILE_MATURITY_V2.ACTIVE);
1197
+ if (isInitial && _hardgovCountActive(p.owner) >= _hardgovMaxActive)
1198
+ throw new Error(`max active hardgov profiles for owner ${p.owner} reached`);
1199
+ const now = Date.now();
1200
+ p.status = HARDGOV_PROFILE_MATURITY_V2.ACTIVE;
1201
+ p.updatedAt = now;
1202
+ p.lastTouchedAt = now;
1203
+ if (!p.activatedAt) p.activatedAt = now;
1204
+ return { ...p, metadata: { ...p.metadata } };
1205
+ }
1206
+ export function disableHardgovProfileV2(id) {
1207
+ const p = _hardgovPsV2.get(id);
1208
+ if (!p) throw new Error(`hardgov profile ${id} not found`);
1209
+ _hardgovCheckP(p.status, HARDGOV_PROFILE_MATURITY_V2.DISABLED);
1210
+ p.status = HARDGOV_PROFILE_MATURITY_V2.DISABLED;
1211
+ p.updatedAt = Date.now();
1212
+ return { ...p, metadata: { ...p.metadata } };
1213
+ }
1214
+ export function archiveHardgovProfileV2(id) {
1215
+ const p = _hardgovPsV2.get(id);
1216
+ if (!p) throw new Error(`hardgov profile ${id} not found`);
1217
+ _hardgovCheckP(p.status, HARDGOV_PROFILE_MATURITY_V2.ARCHIVED);
1218
+ const now = Date.now();
1219
+ p.status = HARDGOV_PROFILE_MATURITY_V2.ARCHIVED;
1220
+ p.updatedAt = now;
1221
+ if (!p.archivedAt) p.archivedAt = now;
1222
+ return { ...p, metadata: { ...p.metadata } };
1223
+ }
1224
+ export function touchHardgovProfileV2(id) {
1225
+ const p = _hardgovPsV2.get(id);
1226
+ if (!p) throw new Error(`hardgov profile ${id} not found`);
1227
+ if (_hardgovPTerminal.has(p.status))
1228
+ throw new Error(`cannot touch terminal hardgov profile ${id}`);
1229
+ const now = Date.now();
1230
+ p.lastTouchedAt = now;
1231
+ p.updatedAt = now;
1232
+ return { ...p, metadata: { ...p.metadata } };
1233
+ }
1234
+ export function getHardgovProfileV2(id) {
1235
+ const p = _hardgovPsV2.get(id);
1236
+ if (!p) return null;
1237
+ return { ...p, metadata: { ...p.metadata } };
1238
+ }
1239
+ export function listHardgovProfilesV2() {
1240
+ return [..._hardgovPsV2.values()].map((p) => ({
1241
+ ...p,
1242
+ metadata: { ...p.metadata },
1243
+ }));
1244
+ }
1245
+ export function createHardgovScanV2({ id, profileId, target, metadata } = {}) {
1246
+ if (!id || !profileId) throw new Error("id and profileId required");
1247
+ if (_hardgovJsV2.has(id))
1248
+ throw new Error(`hardgov scan ${id} already exists`);
1249
+ if (!_hardgovPsV2.has(profileId))
1250
+ throw new Error(`hardgov profile ${profileId} not found`);
1251
+ if (_hardgovCountPending(profileId) >= _hardgovMaxPending)
1252
+ throw new Error(
1253
+ `max pending hardgov scans for profile ${profileId} reached`,
1254
+ );
1255
+ const now = Date.now();
1256
+ const j = {
1257
+ id,
1258
+ profileId,
1259
+ target: target || "",
1260
+ status: HARDGOV_SCAN_LIFECYCLE_V2.QUEUED,
1261
+ createdAt: now,
1262
+ updatedAt: now,
1263
+ startedAt: null,
1264
+ settledAt: null,
1265
+ metadata: { ...(metadata || {}) },
1266
+ };
1267
+ _hardgovJsV2.set(id, j);
1268
+ return { ...j, metadata: { ...j.metadata } };
1269
+ }
1270
+ export function scanningHardgovScanV2(id) {
1271
+ const j = _hardgovJsV2.get(id);
1272
+ if (!j) throw new Error(`hardgov scan ${id} not found`);
1273
+ _hardgovCheckJ(j.status, HARDGOV_SCAN_LIFECYCLE_V2.SCANNING);
1274
+ const now = Date.now();
1275
+ j.status = HARDGOV_SCAN_LIFECYCLE_V2.SCANNING;
1276
+ j.updatedAt = now;
1277
+ if (!j.startedAt) j.startedAt = now;
1278
+ return { ...j, metadata: { ...j.metadata } };
1279
+ }
1280
+ export function completeScanHardgovV2(id) {
1281
+ const j = _hardgovJsV2.get(id);
1282
+ if (!j) throw new Error(`hardgov scan ${id} not found`);
1283
+ _hardgovCheckJ(j.status, HARDGOV_SCAN_LIFECYCLE_V2.SCANNED);
1284
+ const now = Date.now();
1285
+ j.status = HARDGOV_SCAN_LIFECYCLE_V2.SCANNED;
1286
+ j.updatedAt = now;
1287
+ if (!j.settledAt) j.settledAt = now;
1288
+ return { ...j, metadata: { ...j.metadata } };
1289
+ }
1290
+ export function failHardgovScanV2(id, reason) {
1291
+ const j = _hardgovJsV2.get(id);
1292
+ if (!j) throw new Error(`hardgov scan ${id} not found`);
1293
+ _hardgovCheckJ(j.status, HARDGOV_SCAN_LIFECYCLE_V2.FAILED);
1294
+ const now = Date.now();
1295
+ j.status = HARDGOV_SCAN_LIFECYCLE_V2.FAILED;
1296
+ j.updatedAt = now;
1297
+ if (!j.settledAt) j.settledAt = now;
1298
+ if (reason) j.metadata.failReason = String(reason);
1299
+ return { ...j, metadata: { ...j.metadata } };
1300
+ }
1301
+ export function cancelHardgovScanV2(id, reason) {
1302
+ const j = _hardgovJsV2.get(id);
1303
+ if (!j) throw new Error(`hardgov scan ${id} not found`);
1304
+ _hardgovCheckJ(j.status, HARDGOV_SCAN_LIFECYCLE_V2.CANCELLED);
1305
+ const now = Date.now();
1306
+ j.status = HARDGOV_SCAN_LIFECYCLE_V2.CANCELLED;
1307
+ j.updatedAt = now;
1308
+ if (!j.settledAt) j.settledAt = now;
1309
+ if (reason) j.metadata.cancelReason = String(reason);
1310
+ return { ...j, metadata: { ...j.metadata } };
1311
+ }
1312
+ export function getHardgovScanV2(id) {
1313
+ const j = _hardgovJsV2.get(id);
1314
+ if (!j) return null;
1315
+ return { ...j, metadata: { ...j.metadata } };
1316
+ }
1317
+ export function listHardgovScansV2() {
1318
+ return [..._hardgovJsV2.values()].map((j) => ({
1319
+ ...j,
1320
+ metadata: { ...j.metadata },
1321
+ }));
1322
+ }
1323
+ export function autoDisableIdleHardgovProfilesV2({ now } = {}) {
1324
+ const t = now ?? Date.now();
1325
+ const flipped = [];
1326
+ for (const p of _hardgovPsV2.values())
1327
+ if (
1328
+ p.status === HARDGOV_PROFILE_MATURITY_V2.ACTIVE &&
1329
+ t - p.lastTouchedAt >= _hardgovIdleMs
1330
+ ) {
1331
+ p.status = HARDGOV_PROFILE_MATURITY_V2.DISABLED;
1332
+ p.updatedAt = t;
1333
+ flipped.push(p.id);
1334
+ }
1335
+ return { flipped, count: flipped.length };
1336
+ }
1337
+ export function autoFailStuckHardgovScansV2({ now } = {}) {
1338
+ const t = now ?? Date.now();
1339
+ const flipped = [];
1340
+ for (const j of _hardgovJsV2.values())
1341
+ if (
1342
+ j.status === HARDGOV_SCAN_LIFECYCLE_V2.SCANNING &&
1343
+ j.startedAt != null &&
1344
+ t - j.startedAt >= _hardgovStuckMs
1345
+ ) {
1346
+ j.status = HARDGOV_SCAN_LIFECYCLE_V2.FAILED;
1347
+ j.updatedAt = t;
1348
+ if (!j.settledAt) j.settledAt = t;
1349
+ j.metadata.failReason = "auto-fail-stuck";
1350
+ flipped.push(j.id);
1351
+ }
1352
+ return { flipped, count: flipped.length };
1353
+ }
1354
+ export function getHardeningManagerGovStatsV2() {
1355
+ const profilesByStatus = {};
1356
+ for (const v of Object.values(HARDGOV_PROFILE_MATURITY_V2))
1357
+ profilesByStatus[v] = 0;
1358
+ for (const p of _hardgovPsV2.values()) profilesByStatus[p.status]++;
1359
+ const scansByStatus = {};
1360
+ for (const v of Object.values(HARDGOV_SCAN_LIFECYCLE_V2))
1361
+ scansByStatus[v] = 0;
1362
+ for (const j of _hardgovJsV2.values()) scansByStatus[j.status]++;
1363
+ return {
1364
+ totalHardgovProfilesV2: _hardgovPsV2.size,
1365
+ totalHardgovScansV2: _hardgovJsV2.size,
1366
+ maxActiveHardgovProfilesPerOwner: _hardgovMaxActive,
1367
+ maxPendingHardgovScansPerProfile: _hardgovMaxPending,
1368
+ hardgovProfileIdleMs: _hardgovIdleMs,
1369
+ hardgovScanStuckMs: _hardgovStuckMs,
1370
+ profilesByStatus,
1371
+ scansByStatus,
1372
+ };
1373
+ }