chainlesschain 0.81.0 → 0.143.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 (209) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +62 -0
  4. package/src/commands/activitypub.js +61 -0
  5. package/src/commands/agent-network.js +254 -1
  6. package/src/commands/agent.js +117 -0
  7. package/src/commands/audit.js +302 -0
  8. package/src/commands/automation.js +271 -1
  9. package/src/commands/bi.js +61 -0
  10. package/src/commands/bm25.js +78 -0
  11. package/src/commands/browse.js +64 -0
  12. package/src/commands/ccron.js +78 -0
  13. package/src/commands/codegen.js +224 -0
  14. package/src/commands/collab.js +341 -0
  15. package/src/commands/compliance.js +1075 -0
  16. package/src/commands/compt.js +78 -0
  17. package/src/commands/consol.js +231 -0
  18. package/src/commands/cowork.js +263 -0
  19. package/src/commands/crosschain.js +62 -0
  20. package/src/commands/dao.js +62 -0
  21. package/src/commands/dbevo.js +284 -0
  22. package/src/commands/dev.js +252 -0
  23. package/src/commands/did.js +358 -0
  24. package/src/commands/dlp.js +61 -0
  25. package/src/commands/economy.js +56 -0
  26. package/src/commands/encrypt.js +341 -0
  27. package/src/commands/evolution.js +56 -0
  28. package/src/commands/evomap.js +61 -0
  29. package/src/commands/export.js +256 -1
  30. package/src/commands/fflag.js +178 -0
  31. package/src/commands/fusion.js +258 -0
  32. package/src/commands/git.js +45 -0
  33. package/src/commands/governance.js +325 -0
  34. package/src/commands/hardening.js +411 -0
  35. package/src/commands/hmemory.js +56 -0
  36. package/src/commands/hook.js +148 -0
  37. package/src/commands/import.js +252 -0
  38. package/src/commands/incentive.js +322 -0
  39. package/src/commands/inference.js +42 -0
  40. package/src/commands/infra.js +244 -0
  41. package/src/commands/instinct.js +260 -0
  42. package/src/commands/ipfs.js +318 -0
  43. package/src/commands/itbudget.js +45 -0
  44. package/src/commands/kg.js +387 -0
  45. package/src/commands/llm.js +263 -0
  46. package/src/commands/lowcode.js +44 -0
  47. package/src/commands/matrix.js +62 -0
  48. package/src/commands/mcp.js +221 -0
  49. package/src/commands/mcpscaf.js +41 -0
  50. package/src/commands/meminj.js +41 -0
  51. package/src/commands/memory.js +248 -0
  52. package/src/commands/multimodal.js +296 -0
  53. package/src/commands/nlprog.js +356 -0
  54. package/src/commands/nostr.js +62 -0
  55. package/src/commands/note.js +244 -0
  56. package/src/commands/ops.js +354 -0
  57. package/src/commands/orchestrate.js +166 -0
  58. package/src/commands/orchgov.js +45 -0
  59. package/src/commands/org.js +277 -0
  60. package/src/commands/p2p.js +390 -0
  61. package/src/commands/pdfp.js +78 -0
  62. package/src/commands/perception.js +290 -0
  63. package/src/commands/perf.js +39 -0
  64. package/src/commands/perm.js +45 -0
  65. package/src/commands/permmem.js +251 -0
  66. package/src/commands/pipeline.js +57 -1
  67. package/src/commands/planmode.js +45 -0
  68. package/src/commands/plugin-ecosystem.js +273 -0
  69. package/src/commands/pqc.js +393 -0
  70. package/src/commands/promcomp.js +82 -0
  71. package/src/commands/quantization.js +351 -0
  72. package/src/commands/rcache.js +271 -0
  73. package/src/commands/recommend.js +382 -0
  74. package/src/commands/runtime.js +307 -0
  75. package/src/commands/scim.js +262 -0
  76. package/src/commands/seshhook.js +41 -0
  77. package/src/commands/seshsearch.js +41 -0
  78. package/src/commands/seshtail.js +41 -0
  79. package/src/commands/seshu.js +41 -0
  80. package/src/commands/session.js +258 -0
  81. package/src/commands/sganal.js +78 -0
  82. package/src/commands/siem.js +40 -0
  83. package/src/commands/skill.js +267 -1
  84. package/src/commands/slotfill.js +41 -0
  85. package/src/commands/social.js +290 -0
  86. package/src/commands/sso.js +186 -1
  87. package/src/commands/svccont.js +45 -0
  88. package/src/commands/sync.js +256 -0
  89. package/src/commands/tech.js +338 -0
  90. package/src/commands/tenant.js +351 -0
  91. package/src/commands/tms.js +45 -0
  92. package/src/commands/tokens.js +269 -0
  93. package/src/commands/topiccls.js +45 -0
  94. package/src/commands/trust.js +249 -0
  95. package/src/commands/uprof.js +45 -0
  96. package/src/commands/vcheck.js +78 -0
  97. package/src/commands/wallet.js +277 -0
  98. package/src/commands/webfetch.js +41 -0
  99. package/src/commands/workflow.js +171 -0
  100. package/src/commands/zkp.js +62 -0
  101. package/src/harness/prompt-compressor.js +331 -0
  102. package/src/index.js +65 -1
  103. package/src/lib/a2a-protocol.js +105 -0
  104. package/src/lib/activitypub-bridge.js +105 -0
  105. package/src/lib/agent-coordinator.js +325 -0
  106. package/src/lib/agent-economy.js +105 -0
  107. package/src/lib/agent-network.js +387 -0
  108. package/src/lib/agent-router.js +395 -0
  109. package/src/lib/aiops.js +478 -0
  110. package/src/lib/app-builder.js +105 -0
  111. package/src/lib/audit-logger.js +379 -0
  112. package/src/lib/automation-engine.js +330 -0
  113. package/src/lib/autonomous-agent.js +105 -0
  114. package/src/lib/autonomous-developer.js +350 -0
  115. package/src/lib/bi-engine.js +105 -0
  116. package/src/lib/bm25-search.js +81 -0
  117. package/src/lib/browser-automation.js +105 -0
  118. package/src/lib/code-agent.js +323 -0
  119. package/src/lib/collaboration-governance.js +364 -0
  120. package/src/lib/community-governance.js +436 -0
  121. package/src/lib/compliance-framework-reporter.js +105 -0
  122. package/src/lib/compliance-manager.js +434 -0
  123. package/src/lib/compression-telemetry.js +81 -0
  124. package/src/lib/content-recommendation.js +469 -0
  125. package/src/lib/content-recommender.js +105 -0
  126. package/src/lib/cowork-cron.js +81 -0
  127. package/src/lib/cowork-task-runner.js +105 -0
  128. package/src/lib/cross-chain.js +105 -0
  129. package/src/lib/crypto-manager.js +350 -0
  130. package/src/lib/dao-governance.js +105 -0
  131. package/src/lib/dbevo.js +338 -0
  132. package/src/lib/decentral-infra.js +340 -0
  133. package/src/lib/did-manager.js +367 -0
  134. package/src/lib/dlp-engine.js +105 -0
  135. package/src/lib/evolution-system.js +105 -0
  136. package/src/lib/evomap-manager.js +105 -0
  137. package/src/lib/execution-backend.js +105 -0
  138. package/src/lib/feature-flags.js +85 -0
  139. package/src/lib/git-integration.js +105 -0
  140. package/src/lib/hardening-manager.js +348 -0
  141. package/src/lib/hierarchical-memory.js +105 -0
  142. package/src/lib/hook-manager.js +380 -0
  143. package/src/lib/inference-network.js +105 -0
  144. package/src/lib/instinct-manager.js +332 -0
  145. package/src/lib/ipfs-storage.js +334 -0
  146. package/src/lib/iteration-budget.js +105 -0
  147. package/src/lib/knowledge-exporter.js +381 -0
  148. package/src/lib/knowledge-graph.js +432 -0
  149. package/src/lib/knowledge-importer.js +379 -0
  150. package/src/lib/llm-providers.js +391 -0
  151. package/src/lib/matrix-bridge.js +105 -0
  152. package/src/lib/mcp-registry.js +333 -0
  153. package/src/lib/mcp-scaffold.js +81 -0
  154. package/src/lib/memory-injection.js +81 -0
  155. package/src/lib/memory-manager.js +330 -0
  156. package/src/lib/multimodal.js +346 -0
  157. package/src/lib/nl-programming.js +343 -0
  158. package/src/lib/nostr-bridge.js +105 -0
  159. package/src/lib/note-versioning.js +327 -0
  160. package/src/lib/orchestrator.js +105 -0
  161. package/src/lib/org-manager.js +323 -0
  162. package/src/lib/p2p-manager.js +387 -0
  163. package/src/lib/pdf-parser.js +81 -0
  164. package/src/lib/perception.js +346 -0
  165. package/src/lib/perf-tuning.js +109 -1
  166. package/src/lib/permanent-memory.js +320 -0
  167. package/src/lib/permission-engine.js +81 -0
  168. package/src/lib/pipeline-orchestrator.js +105 -0
  169. package/src/lib/plan-mode.js +81 -0
  170. package/src/lib/plugin-ecosystem.js +377 -0
  171. package/src/lib/pqc-manager.js +368 -0
  172. package/src/lib/prompt-compressor.js +1 -10
  173. package/src/lib/protocol-fusion.js +417 -0
  174. package/src/lib/quantization.js +325 -0
  175. package/src/lib/response-cache.js +327 -0
  176. package/src/lib/scim-manager.js +329 -0
  177. package/src/lib/service-container.js +81 -0
  178. package/src/lib/session-consolidator.js +105 -0
  179. package/src/lib/session-hooks.js +81 -0
  180. package/src/lib/session-manager.js +329 -0
  181. package/src/lib/session-search.js +81 -0
  182. package/src/lib/session-tail.js +81 -0
  183. package/src/lib/session-usage.js +83 -0
  184. package/src/lib/siem-exporter.js +105 -0
  185. package/src/lib/skill-loader.js +377 -0
  186. package/src/lib/slot-filler.js +81 -0
  187. package/src/lib/social-graph-analytics.js +81 -0
  188. package/src/lib/social-graph.js +81 -0
  189. package/src/lib/social-manager.js +326 -0
  190. package/src/lib/sso-manager.js +332 -0
  191. package/src/lib/sub-agent-registry.js +110 -0
  192. package/src/lib/sync-manager.js +326 -0
  193. package/src/lib/task-model-selector.js +81 -0
  194. package/src/lib/tech-learning-engine.js +369 -0
  195. package/src/lib/tenant-saas.js +460 -0
  196. package/src/lib/threat-intel.js +335 -0
  197. package/src/lib/todo-manager.js +105 -0
  198. package/src/lib/token-incentive.js +293 -0
  199. package/src/lib/token-tracker.js +329 -0
  200. package/src/lib/topic-classifier.js +105 -0
  201. package/src/lib/trust-security.js +390 -0
  202. package/src/lib/ueba.js +389 -0
  203. package/src/lib/universal-runtime.js +325 -0
  204. package/src/lib/user-profile.js +81 -0
  205. package/src/lib/version-checker.js +81 -0
  206. package/src/lib/wallet-manager.js +326 -0
  207. package/src/lib/web-fetch.js +81 -0
  208. package/src/lib/workflow-engine.js +322 -0
  209. package/src/lib/zkp-engine.js +105 -0
@@ -266,3 +266,338 @@ export function clearAll(db) {
266
266
  const info = db.prepare(`DELETE FROM threat_intel_indicators`).run();
267
267
  return info.changes;
268
268
  }
269
+
270
+ /* ═══════════════════════════════════════════════════════════════
271
+ * V2 Surface — In-memory feed-maturity + indicator-lifecycle layer.
272
+ * Independent of the SQLite IoC catalog above; tracks feed sources
273
+ * and indicator lifecycle transitions with caps and auto-flip.
274
+ * ═══════════════════════════════════════════════════════════════ */
275
+
276
+ export const FEED_MATURITY_V2 = Object.freeze({
277
+ PENDING: "pending",
278
+ TRUSTED: "trusted",
279
+ DEPRECATED: "deprecated",
280
+ RETIRED: "retired",
281
+ });
282
+
283
+ export const INDICATOR_LIFECYCLE_V2 = Object.freeze({
284
+ PENDING: "pending",
285
+ ACTIVE: "active",
286
+ EXPIRED: "expired",
287
+ REVOKED: "revoked",
288
+ SUPERSEDED: "superseded",
289
+ });
290
+
291
+ const FEED_TRANSITIONS_V2 = new Map([
292
+ ["pending", new Set(["trusted", "retired"])],
293
+ ["trusted", new Set(["deprecated", "retired"])],
294
+ ["deprecated", new Set(["trusted", "retired"])],
295
+ ["retired", new Set()],
296
+ ]);
297
+ const FEED_TERMINALS_V2 = new Set(["retired"]);
298
+
299
+ const INDICATOR_TRANSITIONS_V2 = new Map([
300
+ ["pending", new Set(["active", "revoked", "superseded"])],
301
+ ["active", new Set(["expired", "revoked", "superseded"])],
302
+ ["expired", new Set()],
303
+ ["revoked", new Set()],
304
+ ["superseded", new Set()],
305
+ ]);
306
+ const INDICATOR_TERMINALS_V2 = new Set(["expired", "revoked", "superseded"]);
307
+
308
+ export const TI_DEFAULT_MAX_ACTIVE_FEEDS_PER_OWNER = 15;
309
+ export const TI_DEFAULT_MAX_ACTIVE_INDICATORS_PER_FEED = 500;
310
+ export const TI_DEFAULT_FEED_IDLE_MS = 1000 * 60 * 60 * 24 * 60; // 60 days
311
+ export const TI_DEFAULT_INDICATOR_STALE_MS = 1000 * 60 * 60 * 24 * 90; // 90 days
312
+
313
+ const _feedsV2 = new Map();
314
+ const _indicatorsV2 = new Map();
315
+ let _maxActiveFeedsPerOwnerV2 = TI_DEFAULT_MAX_ACTIVE_FEEDS_PER_OWNER;
316
+ let _maxActiveIndicatorsPerFeedV2 = TI_DEFAULT_MAX_ACTIVE_INDICATORS_PER_FEED;
317
+ let _feedIdleMsV2 = TI_DEFAULT_FEED_IDLE_MS;
318
+ let _indicatorStaleMsV2 = TI_DEFAULT_INDICATOR_STALE_MS;
319
+
320
+ function _posIntV2(n, label) {
321
+ const v = Math.floor(Number(n));
322
+ if (!Number.isFinite(v) || v <= 0)
323
+ throw new Error(`${label} must be a positive integer`);
324
+ return v;
325
+ }
326
+
327
+ export function getMaxActiveFeedsPerOwnerV2() {
328
+ return _maxActiveFeedsPerOwnerV2;
329
+ }
330
+ export function setMaxActiveFeedsPerOwnerV2(n) {
331
+ _maxActiveFeedsPerOwnerV2 = _posIntV2(n, "maxActiveFeedsPerOwner");
332
+ }
333
+ export function getMaxActiveIndicatorsPerFeedV2() {
334
+ return _maxActiveIndicatorsPerFeedV2;
335
+ }
336
+ export function setMaxActiveIndicatorsPerFeedV2(n) {
337
+ _maxActiveIndicatorsPerFeedV2 = _posIntV2(n, "maxActiveIndicatorsPerFeed");
338
+ }
339
+ export function getFeedIdleMsV2() {
340
+ return _feedIdleMsV2;
341
+ }
342
+ export function setFeedIdleMsV2(n) {
343
+ _feedIdleMsV2 = _posIntV2(n, "feedIdleMs");
344
+ }
345
+ export function getIndicatorStaleMsV2() {
346
+ return _indicatorStaleMsV2;
347
+ }
348
+ export function setIndicatorStaleMsV2(n) {
349
+ _indicatorStaleMsV2 = _posIntV2(n, "indicatorStaleMs");
350
+ }
351
+
352
+ export function getActiveFeedCountV2(owner) {
353
+ let n = 0;
354
+ for (const f of _feedsV2.values()) {
355
+ if (f.owner === owner && f.maturity === "trusted") n += 1;
356
+ }
357
+ return n;
358
+ }
359
+
360
+ export function getActiveIndicatorCountV2(feedId) {
361
+ let n = 0;
362
+ for (const i of _indicatorsV2.values()) {
363
+ if (i.feedId === feedId && i.status === "active") n += 1;
364
+ }
365
+ return n;
366
+ }
367
+
368
+ function _copyFeedV2(f) {
369
+ return { ...f, metadata: { ...f.metadata } };
370
+ }
371
+ function _copyIndicatorV2(i) {
372
+ return { ...i, metadata: { ...i.metadata } };
373
+ }
374
+
375
+ export function registerFeedV2(id, { owner, name, metadata = {} } = {}) {
376
+ if (!id || typeof id !== "string") throw new Error("id must be a string");
377
+ if (!owner || typeof owner !== "string")
378
+ throw new Error("owner must be a string");
379
+ if (!name || typeof name !== "string")
380
+ throw new Error("name must be a string");
381
+ if (_feedsV2.has(id)) throw new Error(`feed ${id} already exists`);
382
+ const now = Date.now();
383
+ const feed = {
384
+ id,
385
+ owner,
386
+ name,
387
+ maturity: "pending",
388
+ createdAt: now,
389
+ lastSeenAt: now,
390
+ activatedAt: null,
391
+ metadata: { ...metadata },
392
+ };
393
+ _feedsV2.set(id, feed);
394
+ return _copyFeedV2(feed);
395
+ }
396
+
397
+ export function getFeedV2(id) {
398
+ const f = _feedsV2.get(id);
399
+ return f ? _copyFeedV2(f) : null;
400
+ }
401
+
402
+ export function listFeedsV2({ owner, maturity } = {}) {
403
+ const out = [];
404
+ for (const f of _feedsV2.values()) {
405
+ if (owner && f.owner !== owner) continue;
406
+ if (maturity && f.maturity !== maturity) continue;
407
+ out.push(_copyFeedV2(f));
408
+ }
409
+ return out;
410
+ }
411
+
412
+ export function setFeedMaturityV2(id, next, { now = Date.now() } = {}) {
413
+ const f = _feedsV2.get(id);
414
+ if (!f) throw new Error(`feed ${id} not found`);
415
+ if (!FEED_TRANSITIONS_V2.has(next))
416
+ throw new Error(`unknown feed maturity: ${next}`);
417
+ if (FEED_TERMINALS_V2.has(f.maturity))
418
+ throw new Error(`feed ${id} is in terminal state ${f.maturity}`);
419
+ const allowed = FEED_TRANSITIONS_V2.get(f.maturity);
420
+ if (!allowed.has(next))
421
+ throw new Error(`cannot transition feed from ${f.maturity} to ${next}`);
422
+ if (next === "trusted") {
423
+ if (f.maturity === "pending") {
424
+ const count = getActiveFeedCountV2(f.owner);
425
+ if (count >= _maxActiveFeedsPerOwnerV2)
426
+ throw new Error(
427
+ `owner ${f.owner} already at active-feed cap (${_maxActiveFeedsPerOwnerV2})`,
428
+ );
429
+ }
430
+ if (!f.activatedAt) f.activatedAt = now;
431
+ }
432
+ f.maturity = next;
433
+ f.lastSeenAt = now;
434
+ return _copyFeedV2(f);
435
+ }
436
+
437
+ export function trustFeedV2(id, opts) {
438
+ return setFeedMaturityV2(id, "trusted", opts);
439
+ }
440
+ export function deprecateFeedV2(id, opts) {
441
+ return setFeedMaturityV2(id, "deprecated", opts);
442
+ }
443
+ export function retireFeedV2(id, opts) {
444
+ return setFeedMaturityV2(id, "retired", opts);
445
+ }
446
+
447
+ export function touchFeedV2(id, { now = Date.now() } = {}) {
448
+ const f = _feedsV2.get(id);
449
+ if (!f) throw new Error(`feed ${id} not found`);
450
+ f.lastSeenAt = now;
451
+ return _copyFeedV2(f);
452
+ }
453
+
454
+ export function createIndicatorV2(
455
+ id,
456
+ { feedId, iocType, value, metadata = {} } = {},
457
+ ) {
458
+ if (!id || typeof id !== "string") throw new Error("id must be a string");
459
+ if (!feedId || typeof feedId !== "string")
460
+ throw new Error("feedId must be a string");
461
+ if (!iocType || typeof iocType !== "string")
462
+ throw new Error("iocType must be a string");
463
+ if (!value || typeof value !== "string")
464
+ throw new Error("value must be a string");
465
+ if (!_feedsV2.has(feedId)) throw new Error(`feed ${feedId} not found`);
466
+ if (_indicatorsV2.has(id)) throw new Error(`indicator ${id} already exists`);
467
+ const now = Date.now();
468
+ const indicator = {
469
+ id,
470
+ feedId,
471
+ iocType,
472
+ value,
473
+ status: "pending",
474
+ createdAt: now,
475
+ lastSeenAt: now,
476
+ activatedAt: null,
477
+ resolvedAt: null,
478
+ metadata: { ...metadata },
479
+ };
480
+ _indicatorsV2.set(id, indicator);
481
+ return _copyIndicatorV2(indicator);
482
+ }
483
+
484
+ export function getIndicatorV2(id) {
485
+ const i = _indicatorsV2.get(id);
486
+ return i ? _copyIndicatorV2(i) : null;
487
+ }
488
+
489
+ export function listIndicatorsV2({ feedId, status } = {}) {
490
+ const out = [];
491
+ for (const i of _indicatorsV2.values()) {
492
+ if (feedId && i.feedId !== feedId) continue;
493
+ if (status && i.status !== status) continue;
494
+ out.push(_copyIndicatorV2(i));
495
+ }
496
+ return out;
497
+ }
498
+
499
+ export function setIndicatorStatusV2(id, next, { now = Date.now() } = {}) {
500
+ const i = _indicatorsV2.get(id);
501
+ if (!i) throw new Error(`indicator ${id} not found`);
502
+ if (!INDICATOR_TRANSITIONS_V2.has(next))
503
+ throw new Error(`unknown indicator status: ${next}`);
504
+ if (INDICATOR_TERMINALS_V2.has(i.status))
505
+ throw new Error(`indicator ${id} is in terminal state ${i.status}`);
506
+ const allowed = INDICATOR_TRANSITIONS_V2.get(i.status);
507
+ if (!allowed.has(next))
508
+ throw new Error(`cannot transition indicator from ${i.status} to ${next}`);
509
+ if (next === "active" && i.status === "pending") {
510
+ const count = getActiveIndicatorCountV2(i.feedId);
511
+ if (count >= _maxActiveIndicatorsPerFeedV2)
512
+ throw new Error(
513
+ `feed ${i.feedId} already at active-indicator cap (${_maxActiveIndicatorsPerFeedV2})`,
514
+ );
515
+ if (!i.activatedAt) i.activatedAt = now;
516
+ }
517
+ if (INDICATOR_TERMINALS_V2.has(next) && !i.resolvedAt) {
518
+ i.resolvedAt = now;
519
+ }
520
+ i.status = next;
521
+ i.lastSeenAt = now;
522
+ return _copyIndicatorV2(i);
523
+ }
524
+
525
+ export function activateIndicatorV2(id, opts) {
526
+ return setIndicatorStatusV2(id, "active", opts);
527
+ }
528
+ export function expireIndicatorV2(id, opts) {
529
+ return setIndicatorStatusV2(id, "expired", opts);
530
+ }
531
+ export function revokeIndicatorV2(id, opts) {
532
+ return setIndicatorStatusV2(id, "revoked", opts);
533
+ }
534
+ export function supersedeIndicatorV2(id, opts) {
535
+ return setIndicatorStatusV2(id, "superseded", opts);
536
+ }
537
+
538
+ export function refreshIndicatorV2(id, { now = Date.now() } = {}) {
539
+ const i = _indicatorsV2.get(id);
540
+ if (!i) throw new Error(`indicator ${id} not found`);
541
+ if (INDICATOR_TERMINALS_V2.has(i.status))
542
+ throw new Error(`indicator ${id} is in terminal state ${i.status}`);
543
+ i.lastSeenAt = now;
544
+ return _copyIndicatorV2(i);
545
+ }
546
+
547
+ export function autoDeprecateIdleFeedsV2({ now = Date.now() } = {}) {
548
+ const flipped = [];
549
+ for (const f of _feedsV2.values()) {
550
+ if (f.maturity !== "trusted") continue;
551
+ if (now - f.lastSeenAt > _feedIdleMsV2) {
552
+ f.maturity = "deprecated";
553
+ f.lastSeenAt = now;
554
+ flipped.push(_copyFeedV2(f));
555
+ }
556
+ }
557
+ return flipped;
558
+ }
559
+
560
+ export function autoExpireStaleIndicatorsV2({ now = Date.now() } = {}) {
561
+ const flipped = [];
562
+ for (const i of _indicatorsV2.values()) {
563
+ if (i.status !== "active") continue;
564
+ if (now - i.lastSeenAt > _indicatorStaleMsV2) {
565
+ i.status = "expired";
566
+ i.lastSeenAt = now;
567
+ if (!i.resolvedAt) i.resolvedAt = now;
568
+ flipped.push(_copyIndicatorV2(i));
569
+ }
570
+ }
571
+ return flipped;
572
+ }
573
+
574
+ export function getThreatIntelStatsV2() {
575
+ const feedsByMaturity = {};
576
+ for (const m of Object.values(FEED_MATURITY_V2)) feedsByMaturity[m] = 0;
577
+ for (const f of _feedsV2.values()) feedsByMaturity[f.maturity] += 1;
578
+
579
+ const indicatorsByStatus = {};
580
+ for (const s of Object.values(INDICATOR_LIFECYCLE_V2))
581
+ indicatorsByStatus[s] = 0;
582
+ for (const i of _indicatorsV2.values()) indicatorsByStatus[i.status] += 1;
583
+
584
+ return {
585
+ totalFeedsV2: _feedsV2.size,
586
+ totalIndicatorsV2: _indicatorsV2.size,
587
+ maxActiveFeedsPerOwner: _maxActiveFeedsPerOwnerV2,
588
+ maxActiveIndicatorsPerFeed: _maxActiveIndicatorsPerFeedV2,
589
+ feedIdleMs: _feedIdleMsV2,
590
+ indicatorStaleMs: _indicatorStaleMsV2,
591
+ feedsByMaturity,
592
+ indicatorsByStatus,
593
+ };
594
+ }
595
+
596
+ export function _resetStateThreatIntelV2() {
597
+ _feedsV2.clear();
598
+ _indicatorsV2.clear();
599
+ _maxActiveFeedsPerOwnerV2 = TI_DEFAULT_MAX_ACTIVE_FEEDS_PER_OWNER;
600
+ _maxActiveIndicatorsPerFeedV2 = TI_DEFAULT_MAX_ACTIVE_INDICATORS_PER_FEED;
601
+ _feedIdleMsV2 = TI_DEFAULT_FEED_IDLE_MS;
602
+ _indicatorStaleMsV2 = TI_DEFAULT_INDICATOR_STALE_MS;
603
+ }
@@ -106,3 +106,108 @@ export function resetAllStores() {
106
106
  }
107
107
 
108
108
  export const _deps = { _stores };
109
+
110
+
111
+ // ===== V2 Surface: Todo Manager governance overlay (CLI v0.133.0) =====
112
+ export const TODO_LIST_MATURITY_V2 = Object.freeze({
113
+ DRAFT: "draft", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
114
+ });
115
+ export const TODO_ITEM_LIFECYCLE_V2 = Object.freeze({
116
+ PENDING: "pending", IN_PROGRESS: "in_progress", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
117
+ });
118
+
119
+ const _tlListTrans = new Map([
120
+ [TODO_LIST_MATURITY_V2.DRAFT, new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED])],
121
+ [TODO_LIST_MATURITY_V2.ACTIVE, new Set([TODO_LIST_MATURITY_V2.PAUSED, TODO_LIST_MATURITY_V2.ARCHIVED])],
122
+ [TODO_LIST_MATURITY_V2.PAUSED, new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED])],
123
+ [TODO_LIST_MATURITY_V2.ARCHIVED, new Set()],
124
+ ]);
125
+ const _tlListTerminal = new Set([TODO_LIST_MATURITY_V2.ARCHIVED]);
126
+ const _tlItemTrans = new Map([
127
+ [TODO_ITEM_LIFECYCLE_V2.PENDING, new Set([TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS, TODO_ITEM_LIFECYCLE_V2.CANCELLED])],
128
+ [TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS, new Set([TODO_ITEM_LIFECYCLE_V2.COMPLETED, TODO_ITEM_LIFECYCLE_V2.FAILED, TODO_ITEM_LIFECYCLE_V2.CANCELLED])],
129
+ [TODO_ITEM_LIFECYCLE_V2.COMPLETED, new Set()],
130
+ [TODO_ITEM_LIFECYCLE_V2.FAILED, new Set()],
131
+ [TODO_ITEM_LIFECYCLE_V2.CANCELLED, new Set()],
132
+ ]);
133
+
134
+ const _tlLists = new Map();
135
+ const _tlItems = new Map();
136
+ let _tlMaxActivePerOwner = 10;
137
+ let _tlMaxPendingPerList = 40;
138
+ let _tlListIdleMs = 7 * 24 * 60 * 60 * 1000;
139
+ let _tlItemStuckMs = 24 * 60 * 60 * 1000;
140
+
141
+ function _tlPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
142
+
143
+ export function setMaxActiveTodoListsPerOwnerV2(n) { _tlMaxActivePerOwner = _tlPos(n, "maxActiveTodoListsPerOwner"); }
144
+ export function getMaxActiveTodoListsPerOwnerV2() { return _tlMaxActivePerOwner; }
145
+ export function setMaxPendingItemsPerTodoListV2(n) { _tlMaxPendingPerList = _tlPos(n, "maxPendingItemsPerTodoList"); }
146
+ export function getMaxPendingItemsPerTodoListV2() { return _tlMaxPendingPerList; }
147
+ export function setTodoListIdleMsV2(n) { _tlListIdleMs = _tlPos(n, "todoListIdleMs"); }
148
+ export function getTodoListIdleMsV2() { return _tlListIdleMs; }
149
+ export function setTodoItemStuckMsV2(n) { _tlItemStuckMs = _tlPos(n, "todoItemStuckMs"); }
150
+ export function getTodoItemStuckMsV2() { return _tlItemStuckMs; }
151
+
152
+ export function _resetStateTodoManagerV2() {
153
+ _tlLists.clear(); _tlItems.clear();
154
+ _tlMaxActivePerOwner = 10; _tlMaxPendingPerList = 40;
155
+ _tlListIdleMs = 7 * 24 * 60 * 60 * 1000; _tlItemStuckMs = 24 * 60 * 60 * 1000;
156
+ }
157
+
158
+ export function registerTodoListV2({ id, owner, title, metadata } = {}) {
159
+ if (!id || typeof id !== "string") throw new Error("id is required");
160
+ if (!owner || typeof owner !== "string") throw new Error("owner is required");
161
+ if (_tlLists.has(id)) throw new Error(`todo list ${id} already registered`);
162
+ const now = Date.now();
163
+ const l = { id, owner, title: title || id, status: TODO_LIST_MATURITY_V2.DRAFT, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
164
+ _tlLists.set(id, l);
165
+ return { ...l, metadata: { ...l.metadata } };
166
+ }
167
+ function _tlCheckL(from, to) { const allowed = _tlListTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid todo list transition ${from} → ${to}`); }
168
+ function _tlCountActive(owner) { let n = 0; for (const l of _tlLists.values()) if (l.owner === owner && l.status === TODO_LIST_MATURITY_V2.ACTIVE) n++; return n; }
169
+
170
+ export function activateTodoListV2(id) {
171
+ const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`);
172
+ _tlCheckL(l.status, TODO_LIST_MATURITY_V2.ACTIVE);
173
+ const recovery = l.status === TODO_LIST_MATURITY_V2.PAUSED;
174
+ if (!recovery) { const a = _tlCountActive(l.owner); if (a >= _tlMaxActivePerOwner) throw new Error(`max active todo lists per owner (${_tlMaxActivePerOwner}) reached for ${l.owner}`); }
175
+ const now = Date.now(); l.status = TODO_LIST_MATURITY_V2.ACTIVE; l.updatedAt = now; l.lastTouchedAt = now; if (!l.activatedAt) l.activatedAt = now;
176
+ return { ...l, metadata: { ...l.metadata } };
177
+ }
178
+ export function pauseTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); _tlCheckL(l.status, TODO_LIST_MATURITY_V2.PAUSED); l.status = TODO_LIST_MATURITY_V2.PAUSED; l.updatedAt = Date.now(); return { ...l, metadata: { ...l.metadata } }; }
179
+ export function archiveTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); _tlCheckL(l.status, TODO_LIST_MATURITY_V2.ARCHIVED); const now = Date.now(); l.status = TODO_LIST_MATURITY_V2.ARCHIVED; l.updatedAt = now; if (!l.archivedAt) l.archivedAt = now; return { ...l, metadata: { ...l.metadata } }; }
180
+ export function touchTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); if (_tlListTerminal.has(l.status)) throw new Error(`cannot touch terminal todo list ${id}`); const now = Date.now(); l.lastTouchedAt = now; l.updatedAt = now; return { ...l, metadata: { ...l.metadata } }; }
181
+ export function getTodoListV2(id) { const l = _tlLists.get(id); if (!l) return null; return { ...l, metadata: { ...l.metadata } }; }
182
+ export function listTodoListsV2() { return [..._tlLists.values()].map((l) => ({ ...l, metadata: { ...l.metadata } })); }
183
+
184
+ function _tlCountPending(lid) { let n = 0; for (const it of _tlItems.values()) if (it.listId === lid && (it.status === TODO_ITEM_LIFECYCLE_V2.PENDING || it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS)) n++; return n; }
185
+
186
+ export function createTodoItemV2({ id, listId, description, metadata } = {}) {
187
+ if (!id || typeof id !== "string") throw new Error("id is required");
188
+ if (!listId || typeof listId !== "string") throw new Error("listId is required");
189
+ if (_tlItems.has(id)) throw new Error(`todo item ${id} already exists`);
190
+ if (!_tlLists.has(listId)) throw new Error(`todo list ${listId} not found`);
191
+ const pending = _tlCountPending(listId);
192
+ if (pending >= _tlMaxPendingPerList) throw new Error(`max pending items per todo list (${_tlMaxPendingPerList}) reached for ${listId}`);
193
+ const now = Date.now();
194
+ const it = { id, listId, description: description || "", status: TODO_ITEM_LIFECYCLE_V2.PENDING, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
195
+ _tlItems.set(id, it);
196
+ return { ...it, metadata: { ...it.metadata } };
197
+ }
198
+ function _tlCheckI(from, to) { const allowed = _tlItemTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid todo item transition ${from} → ${to}`); }
199
+ export function startTodoItemV2(id) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS; it.updatedAt = now; if (!it.startedAt) it.startedAt = now; return { ...it, metadata: { ...it.metadata } }; }
200
+ export function completeTodoItemV2(id) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.COMPLETED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.COMPLETED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; return { ...it, metadata: { ...it.metadata } }; }
201
+ export function failTodoItemV2(id, reason) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.FAILED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.FAILED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; if (reason) it.metadata.failReason = String(reason); return { ...it, metadata: { ...it.metadata } }; }
202
+ export function cancelTodoItemV2(id, reason) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.CANCELLED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.CANCELLED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; if (reason) it.metadata.cancelReason = String(reason); return { ...it, metadata: { ...it.metadata } }; }
203
+ export function getTodoItemV2(id) { const it = _tlItems.get(id); if (!it) return null; return { ...it, metadata: { ...it.metadata } }; }
204
+ export function listTodoItemsV2() { return [..._tlItems.values()].map((it) => ({ ...it, metadata: { ...it.metadata } })); }
205
+
206
+ export function autoPauseIdleTodoListsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const l of _tlLists.values()) if (l.status === TODO_LIST_MATURITY_V2.ACTIVE && (t - l.lastTouchedAt) >= _tlListIdleMs) { l.status = TODO_LIST_MATURITY_V2.PAUSED; l.updatedAt = t; flipped.push(l.id); } return { flipped, count: flipped.length }; }
207
+ export function autoFailStuckTodoItemsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const it of _tlItems.values()) if (it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS && it.startedAt != null && (t - it.startedAt) >= _tlItemStuckMs) { it.status = TODO_ITEM_LIFECYCLE_V2.FAILED; it.updatedAt = t; if (!it.settledAt) it.settledAt = t; it.metadata.failReason = "auto-fail-stuck"; flipped.push(it.id); } return { flipped, count: flipped.length }; }
208
+
209
+ export function getTodoManagerStatsV2() {
210
+ const listsByStatus = {}; for (const s of Object.values(TODO_LIST_MATURITY_V2)) listsByStatus[s] = 0; for (const l of _tlLists.values()) listsByStatus[l.status]++;
211
+ const itemsByStatus = {}; for (const s of Object.values(TODO_ITEM_LIFECYCLE_V2)) itemsByStatus[s] = 0; for (const it of _tlItems.values()) itemsByStatus[it.status]++;
212
+ return { totalListsV2: _tlLists.size, totalItemsV2: _tlItems.size, maxActiveTodoListsPerOwner: _tlMaxActivePerOwner, maxPendingItemsPerTodoList: _tlMaxPendingPerList, todoListIdleMs: _tlListIdleMs, todoItemStuckMs: _tlItemStuckMs, listsByStatus, itemsByStatus };
213
+ }