chainlesschain 0.143.0 → 0.145.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 (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -99,83 +99,337 @@ function filterByChannel(releases, channel) {
99
99
 
100
100
  export { fetchReleases, filterByChannel };
101
101
 
102
-
103
102
  // =====================================================================
104
103
  // Version Checker V2 governance overlay
105
104
  // =====================================================================
106
- export const VCHK_PROFILE_MATURITY_V2 = Object.freeze({ PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived" });
107
- export const VCHK_CHECK_LIFECYCLE_V2 = Object.freeze({ QUEUED: "queued", CHECKING: "checking", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled" });
105
+ export const VCHK_PROFILE_MATURITY_V2 = Object.freeze({
106
+ PENDING: "pending",
107
+ ACTIVE: "active",
108
+ STALE: "stale",
109
+ ARCHIVED: "archived",
110
+ });
111
+ export const VCHK_CHECK_LIFECYCLE_V2 = Object.freeze({
112
+ QUEUED: "queued",
113
+ CHECKING: "checking",
114
+ COMPLETED: "completed",
115
+ FAILED: "failed",
116
+ CANCELLED: "cancelled",
117
+ });
108
118
  const _vchkPTrans = new Map([
109
- [VCHK_PROFILE_MATURITY_V2.PENDING, new Set([VCHK_PROFILE_MATURITY_V2.ACTIVE, VCHK_PROFILE_MATURITY_V2.ARCHIVED])],
110
- [VCHK_PROFILE_MATURITY_V2.ACTIVE, new Set([VCHK_PROFILE_MATURITY_V2.STALE, VCHK_PROFILE_MATURITY_V2.ARCHIVED])],
111
- [VCHK_PROFILE_MATURITY_V2.STALE, new Set([VCHK_PROFILE_MATURITY_V2.ACTIVE, VCHK_PROFILE_MATURITY_V2.ARCHIVED])],
119
+ [
120
+ VCHK_PROFILE_MATURITY_V2.PENDING,
121
+ new Set([
122
+ VCHK_PROFILE_MATURITY_V2.ACTIVE,
123
+ VCHK_PROFILE_MATURITY_V2.ARCHIVED,
124
+ ]),
125
+ ],
126
+ [
127
+ VCHK_PROFILE_MATURITY_V2.ACTIVE,
128
+ new Set([
129
+ VCHK_PROFILE_MATURITY_V2.STALE,
130
+ VCHK_PROFILE_MATURITY_V2.ARCHIVED,
131
+ ]),
132
+ ],
133
+ [
134
+ VCHK_PROFILE_MATURITY_V2.STALE,
135
+ new Set([
136
+ VCHK_PROFILE_MATURITY_V2.ACTIVE,
137
+ VCHK_PROFILE_MATURITY_V2.ARCHIVED,
138
+ ]),
139
+ ],
112
140
  [VCHK_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
113
141
  ]);
114
142
  const _vchkPTerminal = new Set([VCHK_PROFILE_MATURITY_V2.ARCHIVED]);
115
143
  const _vchkCTrans = new Map([
116
- [VCHK_CHECK_LIFECYCLE_V2.QUEUED, new Set([VCHK_CHECK_LIFECYCLE_V2.CHECKING, VCHK_CHECK_LIFECYCLE_V2.CANCELLED])],
117
- [VCHK_CHECK_LIFECYCLE_V2.CHECKING, new Set([VCHK_CHECK_LIFECYCLE_V2.COMPLETED, VCHK_CHECK_LIFECYCLE_V2.FAILED, VCHK_CHECK_LIFECYCLE_V2.CANCELLED])],
144
+ [
145
+ VCHK_CHECK_LIFECYCLE_V2.QUEUED,
146
+ new Set([
147
+ VCHK_CHECK_LIFECYCLE_V2.CHECKING,
148
+ VCHK_CHECK_LIFECYCLE_V2.CANCELLED,
149
+ ]),
150
+ ],
151
+ [
152
+ VCHK_CHECK_LIFECYCLE_V2.CHECKING,
153
+ new Set([
154
+ VCHK_CHECK_LIFECYCLE_V2.COMPLETED,
155
+ VCHK_CHECK_LIFECYCLE_V2.FAILED,
156
+ VCHK_CHECK_LIFECYCLE_V2.CANCELLED,
157
+ ]),
158
+ ],
118
159
  [VCHK_CHECK_LIFECYCLE_V2.COMPLETED, new Set()],
119
160
  [VCHK_CHECK_LIFECYCLE_V2.FAILED, new Set()],
120
161
  [VCHK_CHECK_LIFECYCLE_V2.CANCELLED, new Set()],
121
162
  ]);
122
163
  const _vchkPsV2 = new Map();
123
164
  const _vchkCsV2 = new Map();
124
- let _vchkMaxActive = 5, _vchkMaxPending = 10, _vchkIdleMs = 30 * 24 * 60 * 60 * 1000, _vchkStuckMs = 30 * 1000;
125
- function _vchkPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
126
- function _vchkCheckP(from, to) { const a = _vchkPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid vchk profile transition ${from} → ${to}`); }
127
- function _vchkCheckC(from, to) { const a = _vchkCTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid vchk check transition ${from} → ${to}`); }
128
- function _vchkCountActive(owner) { let c = 0; for (const p of _vchkPsV2.values()) if (p.owner === owner && p.status === VCHK_PROFILE_MATURITY_V2.ACTIVE) c++; return c; }
129
- function _vchkCountPending(profileId) { let c = 0; for (const x of _vchkCsV2.values()) if (x.profileId === profileId && (x.status === VCHK_CHECK_LIFECYCLE_V2.QUEUED || x.status === VCHK_CHECK_LIFECYCLE_V2.CHECKING)) c++; return c; }
130
- export function setMaxActiveVchkProfilesPerOwnerV2(n) { _vchkMaxActive = _vchkPos(n, "maxActiveVchkProfilesPerOwner"); }
131
- export function getMaxActiveVchkProfilesPerOwnerV2() { return _vchkMaxActive; }
132
- export function setMaxPendingVchkChecksPerProfileV2(n) { _vchkMaxPending = _vchkPos(n, "maxPendingVchkChecksPerProfile"); }
133
- export function getMaxPendingVchkChecksPerProfileV2() { return _vchkMaxPending; }
134
- export function setVchkProfileIdleMsV2(n) { _vchkIdleMs = _vchkPos(n, "vchkProfileIdleMs"); }
135
- export function getVchkProfileIdleMsV2() { return _vchkIdleMs; }
136
- export function setVchkCheckStuckMsV2(n) { _vchkStuckMs = _vchkPos(n, "vchkCheckStuckMs"); }
137
- export function getVchkCheckStuckMsV2() { return _vchkStuckMs; }
138
- export function _resetStateVersionCheckerV2() { _vchkPsV2.clear(); _vchkCsV2.clear(); _vchkMaxActive = 5; _vchkMaxPending = 10; _vchkIdleMs = 30 * 24 * 60 * 60 * 1000; _vchkStuckMs = 30 * 1000; }
165
+ let _vchkMaxActive = 5,
166
+ _vchkMaxPending = 10,
167
+ _vchkIdleMs = 30 * 24 * 60 * 60 * 1000,
168
+ _vchkStuckMs = 30 * 1000;
169
+ function _vchkPos(n, label) {
170
+ const v = Math.floor(Number(n));
171
+ if (!Number.isFinite(v) || v <= 0)
172
+ throw new Error(`${label} must be positive integer`);
173
+ return v;
174
+ }
175
+ function _vchkCheckP(from, to) {
176
+ const a = _vchkPTrans.get(from);
177
+ if (!a || !a.has(to))
178
+ throw new Error(`invalid vchk profile transition ${from} ${to}`);
179
+ }
180
+ function _vchkCheckC(from, to) {
181
+ const a = _vchkCTrans.get(from);
182
+ if (!a || !a.has(to))
183
+ throw new Error(`invalid vchk check transition ${from} → ${to}`);
184
+ }
185
+ function _vchkCountActive(owner) {
186
+ let c = 0;
187
+ for (const p of _vchkPsV2.values())
188
+ if (p.owner === owner && p.status === VCHK_PROFILE_MATURITY_V2.ACTIVE) c++;
189
+ return c;
190
+ }
191
+ function _vchkCountPending(profileId) {
192
+ let c = 0;
193
+ for (const x of _vchkCsV2.values())
194
+ if (
195
+ x.profileId === profileId &&
196
+ (x.status === VCHK_CHECK_LIFECYCLE_V2.QUEUED ||
197
+ x.status === VCHK_CHECK_LIFECYCLE_V2.CHECKING)
198
+ )
199
+ c++;
200
+ return c;
201
+ }
202
+ export function setMaxActiveVchkProfilesPerOwnerV2(n) {
203
+ _vchkMaxActive = _vchkPos(n, "maxActiveVchkProfilesPerOwner");
204
+ }
205
+ export function getMaxActiveVchkProfilesPerOwnerV2() {
206
+ return _vchkMaxActive;
207
+ }
208
+ export function setMaxPendingVchkChecksPerProfileV2(n) {
209
+ _vchkMaxPending = _vchkPos(n, "maxPendingVchkChecksPerProfile");
210
+ }
211
+ export function getMaxPendingVchkChecksPerProfileV2() {
212
+ return _vchkMaxPending;
213
+ }
214
+ export function setVchkProfileIdleMsV2(n) {
215
+ _vchkIdleMs = _vchkPos(n, "vchkProfileIdleMs");
216
+ }
217
+ export function getVchkProfileIdleMsV2() {
218
+ return _vchkIdleMs;
219
+ }
220
+ export function setVchkCheckStuckMsV2(n) {
221
+ _vchkStuckMs = _vchkPos(n, "vchkCheckStuckMs");
222
+ }
223
+ export function getVchkCheckStuckMsV2() {
224
+ return _vchkStuckMs;
225
+ }
226
+ export function _resetStateVersionCheckerV2() {
227
+ _vchkPsV2.clear();
228
+ _vchkCsV2.clear();
229
+ _vchkMaxActive = 5;
230
+ _vchkMaxPending = 10;
231
+ _vchkIdleMs = 30 * 24 * 60 * 60 * 1000;
232
+ _vchkStuckMs = 30 * 1000;
233
+ }
139
234
  export function registerVchkProfileV2({ id, owner, channel, metadata } = {}) {
140
235
  if (!id || !owner) throw new Error("id and owner required");
141
236
  if (_vchkPsV2.has(id)) throw new Error(`vchk profile ${id} already exists`);
142
237
  const now = Date.now();
143
- const p = { id, owner, channel: channel || "stable", status: VCHK_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, lastTouchedAt: now, activatedAt: null, archivedAt: null, metadata: { ...(metadata || {}) } };
144
- _vchkPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
238
+ const p = {
239
+ id,
240
+ owner,
241
+ channel: channel || "stable",
242
+ status: VCHK_PROFILE_MATURITY_V2.PENDING,
243
+ createdAt: now,
244
+ updatedAt: now,
245
+ lastTouchedAt: now,
246
+ activatedAt: null,
247
+ archivedAt: null,
248
+ metadata: { ...(metadata || {}) },
249
+ };
250
+ _vchkPsV2.set(id, p);
251
+ return { ...p, metadata: { ...p.metadata } };
145
252
  }
146
253
  export function activateVchkProfileV2(id) {
147
- const p = _vchkPsV2.get(id); if (!p) throw new Error(`vchk profile ${id} not found`);
254
+ const p = _vchkPsV2.get(id);
255
+ if (!p) throw new Error(`vchk profile ${id} not found`);
148
256
  const isInitial = p.status === VCHK_PROFILE_MATURITY_V2.PENDING;
149
257
  _vchkCheckP(p.status, VCHK_PROFILE_MATURITY_V2.ACTIVE);
150
- if (isInitial && _vchkCountActive(p.owner) >= _vchkMaxActive) throw new Error(`max active vchk profiles for owner ${p.owner} reached`);
151
- const now = Date.now(); p.status = VCHK_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now;
258
+ if (isInitial && _vchkCountActive(p.owner) >= _vchkMaxActive)
259
+ throw new Error(`max active vchk profiles for owner ${p.owner} reached`);
260
+ const now = Date.now();
261
+ p.status = VCHK_PROFILE_MATURITY_V2.ACTIVE;
262
+ p.updatedAt = now;
263
+ p.lastTouchedAt = now;
152
264
  if (!p.activatedAt) p.activatedAt = now;
153
265
  return { ...p, metadata: { ...p.metadata } };
154
266
  }
155
- export function staleVchkProfileV2(id) { const p = _vchkPsV2.get(id); if (!p) throw new Error(`vchk profile ${id} not found`); _vchkCheckP(p.status, VCHK_PROFILE_MATURITY_V2.STALE); p.status = VCHK_PROFILE_MATURITY_V2.STALE; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
156
- export function archiveVchkProfileV2(id) { const p = _vchkPsV2.get(id); if (!p) throw new Error(`vchk profile ${id} not found`); _vchkCheckP(p.status, VCHK_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = VCHK_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
157
- export function touchVchkProfileV2(id) { const p = _vchkPsV2.get(id); if (!p) throw new Error(`vchk profile ${id} not found`); if (_vchkPTerminal.has(p.status)) throw new Error(`cannot touch terminal vchk profile ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
158
- export function getVchkProfileV2(id) { const p = _vchkPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
159
- export function listVchkProfilesV2() { return [..._vchkPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
160
- export function createVchkCheckV2({ id, profileId, currentVersion, metadata } = {}) {
267
+ export function staleVchkProfileV2(id) {
268
+ const p = _vchkPsV2.get(id);
269
+ if (!p) throw new Error(`vchk profile ${id} not found`);
270
+ _vchkCheckP(p.status, VCHK_PROFILE_MATURITY_V2.STALE);
271
+ p.status = VCHK_PROFILE_MATURITY_V2.STALE;
272
+ p.updatedAt = Date.now();
273
+ return { ...p, metadata: { ...p.metadata } };
274
+ }
275
+ export function archiveVchkProfileV2(id) {
276
+ const p = _vchkPsV2.get(id);
277
+ if (!p) throw new Error(`vchk profile ${id} not found`);
278
+ _vchkCheckP(p.status, VCHK_PROFILE_MATURITY_V2.ARCHIVED);
279
+ const now = Date.now();
280
+ p.status = VCHK_PROFILE_MATURITY_V2.ARCHIVED;
281
+ p.updatedAt = now;
282
+ if (!p.archivedAt) p.archivedAt = now;
283
+ return { ...p, metadata: { ...p.metadata } };
284
+ }
285
+ export function touchVchkProfileV2(id) {
286
+ const p = _vchkPsV2.get(id);
287
+ if (!p) throw new Error(`vchk profile ${id} not found`);
288
+ if (_vchkPTerminal.has(p.status))
289
+ throw new Error(`cannot touch terminal vchk profile ${id}`);
290
+ const now = Date.now();
291
+ p.lastTouchedAt = now;
292
+ p.updatedAt = now;
293
+ return { ...p, metadata: { ...p.metadata } };
294
+ }
295
+ export function getVchkProfileV2(id) {
296
+ const p = _vchkPsV2.get(id);
297
+ if (!p) return null;
298
+ return { ...p, metadata: { ...p.metadata } };
299
+ }
300
+ export function listVchkProfilesV2() {
301
+ return [..._vchkPsV2.values()].map((p) => ({
302
+ ...p,
303
+ metadata: { ...p.metadata },
304
+ }));
305
+ }
306
+ export function createVchkCheckV2({
307
+ id,
308
+ profileId,
309
+ currentVersion,
310
+ metadata,
311
+ } = {}) {
161
312
  if (!id || !profileId) throw new Error("id and profileId required");
162
313
  if (_vchkCsV2.has(id)) throw new Error(`vchk check ${id} already exists`);
163
- if (!_vchkPsV2.has(profileId)) throw new Error(`vchk profile ${profileId} not found`);
164
- if (_vchkCountPending(profileId) >= _vchkMaxPending) throw new Error(`max pending vchk checks for profile ${profileId} reached`);
314
+ if (!_vchkPsV2.has(profileId))
315
+ throw new Error(`vchk profile ${profileId} not found`);
316
+ if (_vchkCountPending(profileId) >= _vchkMaxPending)
317
+ throw new Error(`max pending vchk checks for profile ${profileId} reached`);
318
+ const now = Date.now();
319
+ const c = {
320
+ id,
321
+ profileId,
322
+ currentVersion: currentVersion || "",
323
+ status: VCHK_CHECK_LIFECYCLE_V2.QUEUED,
324
+ createdAt: now,
325
+ updatedAt: now,
326
+ startedAt: null,
327
+ settledAt: null,
328
+ metadata: { ...(metadata || {}) },
329
+ };
330
+ _vchkCsV2.set(id, c);
331
+ return { ...c, metadata: { ...c.metadata } };
332
+ }
333
+ export function checkingVchkCheckV2(id) {
334
+ const c = _vchkCsV2.get(id);
335
+ if (!c) throw new Error(`vchk check ${id} not found`);
336
+ _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.CHECKING);
337
+ const now = Date.now();
338
+ c.status = VCHK_CHECK_LIFECYCLE_V2.CHECKING;
339
+ c.updatedAt = now;
340
+ if (!c.startedAt) c.startedAt = now;
341
+ return { ...c, metadata: { ...c.metadata } };
342
+ }
343
+ export function completeVchkCheckV2(id) {
344
+ const c = _vchkCsV2.get(id);
345
+ if (!c) throw new Error(`vchk check ${id} not found`);
346
+ _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.COMPLETED);
347
+ const now = Date.now();
348
+ c.status = VCHK_CHECK_LIFECYCLE_V2.COMPLETED;
349
+ c.updatedAt = now;
350
+ if (!c.settledAt) c.settledAt = now;
351
+ return { ...c, metadata: { ...c.metadata } };
352
+ }
353
+ export function failVchkCheckV2(id, reason) {
354
+ const c = _vchkCsV2.get(id);
355
+ if (!c) throw new Error(`vchk check ${id} not found`);
356
+ _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.FAILED);
165
357
  const now = Date.now();
166
- const c = { id, profileId, currentVersion: currentVersion || "", status: VCHK_CHECK_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
167
- _vchkCsV2.set(id, c); return { ...c, metadata: { ...c.metadata } };
168
- }
169
- export function checkingVchkCheckV2(id) { const c = _vchkCsV2.get(id); if (!c) throw new Error(`vchk check ${id} not found`); _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.CHECKING); const now = Date.now(); c.status = VCHK_CHECK_LIFECYCLE_V2.CHECKING; c.updatedAt = now; if (!c.startedAt) c.startedAt = now; return { ...c, metadata: { ...c.metadata } }; }
170
- export function completeVchkCheckV2(id) { const c = _vchkCsV2.get(id); if (!c) throw new Error(`vchk check ${id} not found`); _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.COMPLETED); const now = Date.now(); c.status = VCHK_CHECK_LIFECYCLE_V2.COMPLETED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; return { ...c, metadata: { ...c.metadata } }; }
171
- export function failVchkCheckV2(id, reason) { const c = _vchkCsV2.get(id); if (!c) throw new Error(`vchk check ${id} not found`); _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.FAILED); const now = Date.now(); c.status = VCHK_CHECK_LIFECYCLE_V2.FAILED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; if (reason) c.metadata.failReason = String(reason); return { ...c, metadata: { ...c.metadata } }; }
172
- export function cancelVchkCheckV2(id, reason) { const c = _vchkCsV2.get(id); if (!c) throw new Error(`vchk check ${id} not found`); _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.CANCELLED); const now = Date.now(); c.status = VCHK_CHECK_LIFECYCLE_V2.CANCELLED; c.updatedAt = now; if (!c.settledAt) c.settledAt = now; if (reason) c.metadata.cancelReason = String(reason); return { ...c, metadata: { ...c.metadata } }; }
173
- export function getVchkCheckV2(id) { const c = _vchkCsV2.get(id); if (!c) return null; return { ...c, metadata: { ...c.metadata } }; }
174
- export function listVchkChecksV2() { return [..._vchkCsV2.values()].map((c) => ({ ...c, metadata: { ...c.metadata } })); }
175
- export function autoStaleIdleVchkProfilesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _vchkPsV2.values()) if (p.status === VCHK_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _vchkIdleMs) { p.status = VCHK_PROFILE_MATURITY_V2.STALE; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
176
- export function autoFailStuckVchkChecksV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const c of _vchkCsV2.values()) if (c.status === VCHK_CHECK_LIFECYCLE_V2.CHECKING && c.startedAt != null && (t - c.startedAt) >= _vchkStuckMs) { c.status = VCHK_CHECK_LIFECYCLE_V2.FAILED; c.updatedAt = t; if (!c.settledAt) c.settledAt = t; c.metadata.failReason = "auto-fail-stuck"; flipped.push(c.id); } return { flipped, count: flipped.length }; }
358
+ c.status = VCHK_CHECK_LIFECYCLE_V2.FAILED;
359
+ c.updatedAt = now;
360
+ if (!c.settledAt) c.settledAt = now;
361
+ if (reason) c.metadata.failReason = String(reason);
362
+ return { ...c, metadata: { ...c.metadata } };
363
+ }
364
+ export function cancelVchkCheckV2(id, reason) {
365
+ const c = _vchkCsV2.get(id);
366
+ if (!c) throw new Error(`vchk check ${id} not found`);
367
+ _vchkCheckC(c.status, VCHK_CHECK_LIFECYCLE_V2.CANCELLED);
368
+ const now = Date.now();
369
+ c.status = VCHK_CHECK_LIFECYCLE_V2.CANCELLED;
370
+ c.updatedAt = now;
371
+ if (!c.settledAt) c.settledAt = now;
372
+ if (reason) c.metadata.cancelReason = String(reason);
373
+ return { ...c, metadata: { ...c.metadata } };
374
+ }
375
+ export function getVchkCheckV2(id) {
376
+ const c = _vchkCsV2.get(id);
377
+ if (!c) return null;
378
+ return { ...c, metadata: { ...c.metadata } };
379
+ }
380
+ export function listVchkChecksV2() {
381
+ return [..._vchkCsV2.values()].map((c) => ({
382
+ ...c,
383
+ metadata: { ...c.metadata },
384
+ }));
385
+ }
386
+ export function autoStaleIdleVchkProfilesV2({ now } = {}) {
387
+ const t = now ?? Date.now();
388
+ const flipped = [];
389
+ for (const p of _vchkPsV2.values())
390
+ if (
391
+ p.status === VCHK_PROFILE_MATURITY_V2.ACTIVE &&
392
+ t - p.lastTouchedAt >= _vchkIdleMs
393
+ ) {
394
+ p.status = VCHK_PROFILE_MATURITY_V2.STALE;
395
+ p.updatedAt = t;
396
+ flipped.push(p.id);
397
+ }
398
+ return { flipped, count: flipped.length };
399
+ }
400
+ export function autoFailStuckVchkChecksV2({ now } = {}) {
401
+ const t = now ?? Date.now();
402
+ const flipped = [];
403
+ for (const c of _vchkCsV2.values())
404
+ if (
405
+ c.status === VCHK_CHECK_LIFECYCLE_V2.CHECKING &&
406
+ c.startedAt != null &&
407
+ t - c.startedAt >= _vchkStuckMs
408
+ ) {
409
+ c.status = VCHK_CHECK_LIFECYCLE_V2.FAILED;
410
+ c.updatedAt = t;
411
+ if (!c.settledAt) c.settledAt = t;
412
+ c.metadata.failReason = "auto-fail-stuck";
413
+ flipped.push(c.id);
414
+ }
415
+ return { flipped, count: flipped.length };
416
+ }
177
417
  export function getVersionCheckerGovStatsV2() {
178
- const profilesByStatus = {}; for (const v of Object.values(VCHK_PROFILE_MATURITY_V2)) profilesByStatus[v] = 0; for (const p of _vchkPsV2.values()) profilesByStatus[p.status]++;
179
- const checksByStatus = {}; for (const v of Object.values(VCHK_CHECK_LIFECYCLE_V2)) checksByStatus[v] = 0; for (const c of _vchkCsV2.values()) checksByStatus[c.status]++;
180
- return { totalVchkProfilesV2: _vchkPsV2.size, totalVchkChecksV2: _vchkCsV2.size, maxActiveVchkProfilesPerOwner: _vchkMaxActive, maxPendingVchkChecksPerProfile: _vchkMaxPending, vchkProfileIdleMs: _vchkIdleMs, vchkCheckStuckMs: _vchkStuckMs, profilesByStatus, checksByStatus };
418
+ const profilesByStatus = {};
419
+ for (const v of Object.values(VCHK_PROFILE_MATURITY_V2))
420
+ profilesByStatus[v] = 0;
421
+ for (const p of _vchkPsV2.values()) profilesByStatus[p.status]++;
422
+ const checksByStatus = {};
423
+ for (const v of Object.values(VCHK_CHECK_LIFECYCLE_V2)) checksByStatus[v] = 0;
424
+ for (const c of _vchkCsV2.values()) checksByStatus[c.status]++;
425
+ return {
426
+ totalVchkProfilesV2: _vchkPsV2.size,
427
+ totalVchkChecksV2: _vchkCsV2.size,
428
+ maxActiveVchkProfilesPerOwner: _vchkMaxActive,
429
+ maxPendingVchkChecksPerProfile: _vchkMaxPending,
430
+ vchkProfileIdleMs: _vchkIdleMs,
431
+ vchkCheckStuckMs: _vchkStuckMs,
432
+ profilesByStatus,
433
+ checksByStatus,
434
+ };
181
435
  }