chainlesschain 0.132.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.
- package/package.json +1 -1
- package/src/commands/a2a.js +230 -0
- package/src/commands/activitypub.js +191 -0
- package/src/commands/agent.js +601 -0
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +186 -0
- package/src/commands/bm25.js +162 -0
- package/src/commands/browse.js +225 -0
- package/src/commands/ccron.js +178 -0
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +420 -0
- package/src/commands/compt.js +176 -0
- package/src/commands/consol.js +237 -0
- package/src/commands/cowork.js +588 -0
- package/src/commands/crosschain.js +216 -0
- package/src/commands/dao.js +216 -0
- package/src/commands/dlp.js +206 -0
- package/src/commands/economy.js +211 -0
- package/src/commands/evolution.js +209 -0
- package/src/commands/evomap.js +216 -0
- package/src/commands/fflag.js +230 -0
- package/src/commands/git.js +185 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +210 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +178 -0
- package/src/commands/itbudget.js +161 -0
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +201 -0
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +214 -0
- package/src/commands/mcpscaf.js +153 -0
- package/src/commands/meminj.js +153 -0
- package/src/commands/nostr.js +213 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +156 -0
- package/src/commands/pdfp.js +160 -0
- package/src/commands/perf.js +176 -0
- package/src/commands/perm.js +156 -0
- package/src/commands/pipeline.js +211 -0
- package/src/commands/planmode.js +154 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +166 -0
- package/src/commands/recommend.js +185 -0
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +153 -0
- package/src/commands/seshsearch.js +149 -0
- package/src/commands/seshtail.js +152 -0
- package/src/commands/seshu.js +160 -0
- package/src/commands/sganal.js +172 -0
- package/src/commands/siem.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +154 -0
- package/src/commands/social.js +159 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +157 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +183 -0
- package/src/commands/topiccls.js +158 -0
- package/src/commands/uprof.js +154 -0
- package/src/commands/vcheck.js +172 -0
- package/src/commands/webfetch.js +150 -0
- package/src/commands/zkp.js +218 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +101 -1
- package/src/lib/a2a-protocol.js +373 -0
- package/src/lib/activitypub-bridge.js +343 -0
- package/src/lib/agent-economy.js +358 -0
- package/src/lib/app-builder.js +338 -0
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +341 -0
- package/src/lib/bi-engine.js +339 -0
- package/src/lib/bm25-search.js +333 -0
- package/src/lib/browser-automation.js +352 -0
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +359 -0
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +333 -0
- package/src/lib/content-recommender.js +370 -0
- package/src/lib/cowork-cron.js +330 -0
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +362 -0
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +365 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dlp-engine.js +343 -0
- package/src/lib/evolution-system.js +336 -0
- package/src/lib/evomap-manager.js +339 -0
- package/src/lib/execution-backend.js +351 -0
- package/src/lib/feature-flags.js +330 -0
- package/src/lib/git-integration.js +343 -0
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +341 -0
- package/src/lib/inference-network.js +362 -0
- package/src/lib/iteration-budget.js +357 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-scaffold.js +345 -0
- package/src/lib/memory-injection.js +320 -0
- package/src/lib/nostr-bridge.js +342 -0
- package/src/lib/orchestrator.js +350 -0
- package/src/lib/pdf-parser.js +330 -0
- package/src/lib/perf-tuning.js +364 -0
- package/src/lib/permission-engine.js +319 -0
- package/src/lib/pipeline-orchestrator.js +345 -0
- package/src/lib/plan-mode.js +328 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +342 -0
- package/src/lib/session-consolidator.js +352 -0
- package/src/lib/session-hooks.js +340 -0
- package/src/lib/session-search.js +334 -0
- package/src/lib/session-tail.js +320 -0
- package/src/lib/session-usage.js +329 -0
- package/src/lib/siem-exporter.js +352 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +333 -0
- package/src/lib/social-graph-analytics.js +327 -0
- package/src/lib/social-graph.js +304 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +359 -0
- package/src/lib/task-model-selector.js +333 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +339 -0
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +353 -0
- package/src/lib/user-profile.js +325 -0
- package/src/lib/version-checker.js +335 -0
- package/src/lib/web-fetch.js +322 -0
- package/src/lib/zkp-engine.js +342 -0
package/src/lib/social-graph.js
CHANGED
|
@@ -406,3 +406,307 @@ export function _resetState() {
|
|
|
406
406
|
_nodes.clear();
|
|
407
407
|
_bus.removeAllListeners();
|
|
408
408
|
}
|
|
409
|
+
|
|
410
|
+
// ===== V2 Surface: Social Graph governance overlay (CLI v0.141.0) =====
|
|
411
|
+
export const SG_NODE_MATURITY_V2 = Object.freeze({
|
|
412
|
+
PENDING: "pending",
|
|
413
|
+
ACTIVE: "active",
|
|
414
|
+
INACTIVE: "inactive",
|
|
415
|
+
REMOVED: "removed",
|
|
416
|
+
});
|
|
417
|
+
export const SG_EDGE_LIFECYCLE_V2 = Object.freeze({
|
|
418
|
+
PROPOSED: "proposed",
|
|
419
|
+
ESTABLISHED: "established",
|
|
420
|
+
SEVERED: "severed",
|
|
421
|
+
EXPIRED: "expired",
|
|
422
|
+
CANCELLED: "cancelled",
|
|
423
|
+
});
|
|
424
|
+
const _sgNTrans = new Map([
|
|
425
|
+
[
|
|
426
|
+
SG_NODE_MATURITY_V2.PENDING,
|
|
427
|
+
new Set([SG_NODE_MATURITY_V2.ACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
SG_NODE_MATURITY_V2.ACTIVE,
|
|
431
|
+
new Set([SG_NODE_MATURITY_V2.INACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
SG_NODE_MATURITY_V2.INACTIVE,
|
|
435
|
+
new Set([SG_NODE_MATURITY_V2.ACTIVE, SG_NODE_MATURITY_V2.REMOVED]),
|
|
436
|
+
],
|
|
437
|
+
[SG_NODE_MATURITY_V2.REMOVED, new Set()],
|
|
438
|
+
]);
|
|
439
|
+
const _sgNTerminal = new Set([SG_NODE_MATURITY_V2.REMOVED]);
|
|
440
|
+
const _sgETrans = new Map([
|
|
441
|
+
[
|
|
442
|
+
SG_EDGE_LIFECYCLE_V2.PROPOSED,
|
|
443
|
+
new Set([SG_EDGE_LIFECYCLE_V2.ESTABLISHED, SG_EDGE_LIFECYCLE_V2.CANCELLED]),
|
|
444
|
+
],
|
|
445
|
+
[
|
|
446
|
+
SG_EDGE_LIFECYCLE_V2.ESTABLISHED,
|
|
447
|
+
new Set([SG_EDGE_LIFECYCLE_V2.SEVERED, SG_EDGE_LIFECYCLE_V2.EXPIRED]),
|
|
448
|
+
],
|
|
449
|
+
[SG_EDGE_LIFECYCLE_V2.SEVERED, new Set()],
|
|
450
|
+
[SG_EDGE_LIFECYCLE_V2.EXPIRED, new Set()],
|
|
451
|
+
[SG_EDGE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
452
|
+
]);
|
|
453
|
+
const _sgNsV2 = new Map();
|
|
454
|
+
const _sgEsV2 = new Map();
|
|
455
|
+
let _sgMaxActivePerOwner = 50,
|
|
456
|
+
_sgMaxPendingEdgesPerNode = 100,
|
|
457
|
+
_sgIdleMs = 60 * 24 * 60 * 60 * 1000,
|
|
458
|
+
_sgStuckMs = 14 * 24 * 60 * 60 * 1000;
|
|
459
|
+
function _sgPos(n, label) {
|
|
460
|
+
const v = Math.floor(Number(n));
|
|
461
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
462
|
+
throw new Error(`${label} must be positive integer`);
|
|
463
|
+
return v;
|
|
464
|
+
}
|
|
465
|
+
function _sgCheckN(from, to) {
|
|
466
|
+
const a = _sgNTrans.get(from);
|
|
467
|
+
if (!a || !a.has(to))
|
|
468
|
+
throw new Error(`invalid sg node transition ${from} → ${to}`);
|
|
469
|
+
}
|
|
470
|
+
function _sgCheckE(from, to) {
|
|
471
|
+
const a = _sgETrans.get(from);
|
|
472
|
+
if (!a || !a.has(to))
|
|
473
|
+
throw new Error(`invalid sg edge transition ${from} → ${to}`);
|
|
474
|
+
}
|
|
475
|
+
export function setMaxActiveSgNodesPerOwnerV2(n) {
|
|
476
|
+
_sgMaxActivePerOwner = _sgPos(n, "maxActiveSgNodesPerOwner");
|
|
477
|
+
}
|
|
478
|
+
export function getMaxActiveSgNodesPerOwnerV2() {
|
|
479
|
+
return _sgMaxActivePerOwner;
|
|
480
|
+
}
|
|
481
|
+
export function setMaxPendingSgEdgesPerNodeV2(n) {
|
|
482
|
+
_sgMaxPendingEdgesPerNode = _sgPos(n, "maxPendingSgEdgesPerNode");
|
|
483
|
+
}
|
|
484
|
+
export function getMaxPendingSgEdgesPerNodeV2() {
|
|
485
|
+
return _sgMaxPendingEdgesPerNode;
|
|
486
|
+
}
|
|
487
|
+
export function setSgNodeIdleMsV2(n) {
|
|
488
|
+
_sgIdleMs = _sgPos(n, "sgNodeIdleMs");
|
|
489
|
+
}
|
|
490
|
+
export function getSgNodeIdleMsV2() {
|
|
491
|
+
return _sgIdleMs;
|
|
492
|
+
}
|
|
493
|
+
export function setSgEdgeStuckMsV2(n) {
|
|
494
|
+
_sgStuckMs = _sgPos(n, "sgEdgeStuckMs");
|
|
495
|
+
}
|
|
496
|
+
export function getSgEdgeStuckMsV2() {
|
|
497
|
+
return _sgStuckMs;
|
|
498
|
+
}
|
|
499
|
+
export function _resetStateSocialGraphV2() {
|
|
500
|
+
_sgNsV2.clear();
|
|
501
|
+
_sgEsV2.clear();
|
|
502
|
+
_sgMaxActivePerOwner = 50;
|
|
503
|
+
_sgMaxPendingEdgesPerNode = 100;
|
|
504
|
+
_sgIdleMs = 60 * 24 * 60 * 60 * 1000;
|
|
505
|
+
_sgStuckMs = 14 * 24 * 60 * 60 * 1000;
|
|
506
|
+
}
|
|
507
|
+
export function registerSgNodeV2({ id, owner, handle, metadata } = {}) {
|
|
508
|
+
if (!id) throw new Error("sg node id required");
|
|
509
|
+
if (!owner) throw new Error("sg node owner required");
|
|
510
|
+
if (_sgNsV2.has(id)) throw new Error(`sg node ${id} already registered`);
|
|
511
|
+
const now = Date.now();
|
|
512
|
+
const n = {
|
|
513
|
+
id,
|
|
514
|
+
owner,
|
|
515
|
+
handle: handle || id,
|
|
516
|
+
status: SG_NODE_MATURITY_V2.PENDING,
|
|
517
|
+
createdAt: now,
|
|
518
|
+
updatedAt: now,
|
|
519
|
+
activatedAt: null,
|
|
520
|
+
removedAt: null,
|
|
521
|
+
lastTouchedAt: now,
|
|
522
|
+
metadata: { ...(metadata || {}) },
|
|
523
|
+
};
|
|
524
|
+
_sgNsV2.set(id, n);
|
|
525
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
526
|
+
}
|
|
527
|
+
function _sgCountActive(owner) {
|
|
528
|
+
let n = 0;
|
|
529
|
+
for (const v of _sgNsV2.values())
|
|
530
|
+
if (v.owner === owner && v.status === SG_NODE_MATURITY_V2.ACTIVE) n++;
|
|
531
|
+
return n;
|
|
532
|
+
}
|
|
533
|
+
export function activateSgNodeV2(id) {
|
|
534
|
+
const n = _sgNsV2.get(id);
|
|
535
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
536
|
+
_sgCheckN(n.status, SG_NODE_MATURITY_V2.ACTIVE);
|
|
537
|
+
const recovery = n.status === SG_NODE_MATURITY_V2.INACTIVE;
|
|
538
|
+
if (!recovery && _sgCountActive(n.owner) >= _sgMaxActivePerOwner)
|
|
539
|
+
throw new Error(`max active sg nodes for owner ${n.owner} reached`);
|
|
540
|
+
const now = Date.now();
|
|
541
|
+
n.status = SG_NODE_MATURITY_V2.ACTIVE;
|
|
542
|
+
n.updatedAt = now;
|
|
543
|
+
n.lastTouchedAt = now;
|
|
544
|
+
if (!n.activatedAt) n.activatedAt = now;
|
|
545
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
546
|
+
}
|
|
547
|
+
export function deactivateSgNodeV2(id) {
|
|
548
|
+
const n = _sgNsV2.get(id);
|
|
549
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
550
|
+
_sgCheckN(n.status, SG_NODE_MATURITY_V2.INACTIVE);
|
|
551
|
+
n.status = SG_NODE_MATURITY_V2.INACTIVE;
|
|
552
|
+
n.updatedAt = Date.now();
|
|
553
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
554
|
+
}
|
|
555
|
+
export function removeSgNodeV2(id) {
|
|
556
|
+
const n = _sgNsV2.get(id);
|
|
557
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
558
|
+
_sgCheckN(n.status, SG_NODE_MATURITY_V2.REMOVED);
|
|
559
|
+
const now = Date.now();
|
|
560
|
+
n.status = SG_NODE_MATURITY_V2.REMOVED;
|
|
561
|
+
n.updatedAt = now;
|
|
562
|
+
if (!n.removedAt) n.removedAt = now;
|
|
563
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
564
|
+
}
|
|
565
|
+
export function touchSgNodeV2(id) {
|
|
566
|
+
const n = _sgNsV2.get(id);
|
|
567
|
+
if (!n) throw new Error(`sg node ${id} not found`);
|
|
568
|
+
if (_sgNTerminal.has(n.status))
|
|
569
|
+
throw new Error(`cannot touch terminal sg node ${id}`);
|
|
570
|
+
const now = Date.now();
|
|
571
|
+
n.lastTouchedAt = now;
|
|
572
|
+
n.updatedAt = now;
|
|
573
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
574
|
+
}
|
|
575
|
+
export function getSgNodeV2(id) {
|
|
576
|
+
const n = _sgNsV2.get(id);
|
|
577
|
+
if (!n) return null;
|
|
578
|
+
return { ...n, metadata: { ...n.metadata } };
|
|
579
|
+
}
|
|
580
|
+
export function listSgNodesV2() {
|
|
581
|
+
return [..._sgNsV2.values()].map((n) => ({
|
|
582
|
+
...n,
|
|
583
|
+
metadata: { ...n.metadata },
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
function _sgCountPending(nodeId) {
|
|
587
|
+
let n = 0;
|
|
588
|
+
for (const e of _sgEsV2.values())
|
|
589
|
+
if (e.nodeId === nodeId && e.status === SG_EDGE_LIFECYCLE_V2.PROPOSED) n++;
|
|
590
|
+
return n;
|
|
591
|
+
}
|
|
592
|
+
export function createSgEdgeV2({ id, nodeId, targetId, metadata } = {}) {
|
|
593
|
+
if (!id) throw new Error("sg edge id required");
|
|
594
|
+
if (!nodeId) throw new Error("sg edge nodeId required");
|
|
595
|
+
if (_sgEsV2.has(id)) throw new Error(`sg edge ${id} already exists`);
|
|
596
|
+
if (!_sgNsV2.has(nodeId)) throw new Error(`sg node ${nodeId} not found`);
|
|
597
|
+
if (_sgCountPending(nodeId) >= _sgMaxPendingEdgesPerNode)
|
|
598
|
+
throw new Error(`max pending sg edges for node ${nodeId} reached`);
|
|
599
|
+
const now = Date.now();
|
|
600
|
+
const e = {
|
|
601
|
+
id,
|
|
602
|
+
nodeId,
|
|
603
|
+
targetId: targetId || "",
|
|
604
|
+
status: SG_EDGE_LIFECYCLE_V2.PROPOSED,
|
|
605
|
+
createdAt: now,
|
|
606
|
+
updatedAt: now,
|
|
607
|
+
startedAt: now,
|
|
608
|
+
settledAt: null,
|
|
609
|
+
metadata: { ...(metadata || {}) },
|
|
610
|
+
};
|
|
611
|
+
_sgEsV2.set(id, e);
|
|
612
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
613
|
+
}
|
|
614
|
+
export function establishSgEdgeV2(id) {
|
|
615
|
+
const e = _sgEsV2.get(id);
|
|
616
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
617
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.ESTABLISHED);
|
|
618
|
+
const now = Date.now();
|
|
619
|
+
e.status = SG_EDGE_LIFECYCLE_V2.ESTABLISHED;
|
|
620
|
+
e.updatedAt = now;
|
|
621
|
+
if (!e.settledAt) e.settledAt = now;
|
|
622
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
623
|
+
}
|
|
624
|
+
export function severSgEdgeV2(id, reason) {
|
|
625
|
+
const e = _sgEsV2.get(id);
|
|
626
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
627
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.SEVERED);
|
|
628
|
+
const now = Date.now();
|
|
629
|
+
e.status = SG_EDGE_LIFECYCLE_V2.SEVERED;
|
|
630
|
+
e.updatedAt = now;
|
|
631
|
+
if (reason) e.metadata.severReason = String(reason);
|
|
632
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
633
|
+
}
|
|
634
|
+
export function expireSgEdgeV2(id) {
|
|
635
|
+
const e = _sgEsV2.get(id);
|
|
636
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
637
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.EXPIRED);
|
|
638
|
+
const now = Date.now();
|
|
639
|
+
e.status = SG_EDGE_LIFECYCLE_V2.EXPIRED;
|
|
640
|
+
e.updatedAt = now;
|
|
641
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
642
|
+
}
|
|
643
|
+
export function cancelSgEdgeV2(id, reason) {
|
|
644
|
+
const e = _sgEsV2.get(id);
|
|
645
|
+
if (!e) throw new Error(`sg edge ${id} not found`);
|
|
646
|
+
_sgCheckE(e.status, SG_EDGE_LIFECYCLE_V2.CANCELLED);
|
|
647
|
+
const now = Date.now();
|
|
648
|
+
e.status = SG_EDGE_LIFECYCLE_V2.CANCELLED;
|
|
649
|
+
e.updatedAt = now;
|
|
650
|
+
if (!e.settledAt) e.settledAt = now;
|
|
651
|
+
if (reason) e.metadata.cancelReason = String(reason);
|
|
652
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
653
|
+
}
|
|
654
|
+
export function getSgEdgeV2(id) {
|
|
655
|
+
const e = _sgEsV2.get(id);
|
|
656
|
+
if (!e) return null;
|
|
657
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
658
|
+
}
|
|
659
|
+
export function listSgEdgesV2() {
|
|
660
|
+
return [..._sgEsV2.values()].map((e) => ({
|
|
661
|
+
...e,
|
|
662
|
+
metadata: { ...e.metadata },
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
export function autoDeactivateIdleSgNodesV2({ now } = {}) {
|
|
666
|
+
const t = now ?? Date.now();
|
|
667
|
+
const flipped = [];
|
|
668
|
+
for (const n of _sgNsV2.values())
|
|
669
|
+
if (
|
|
670
|
+
n.status === SG_NODE_MATURITY_V2.ACTIVE &&
|
|
671
|
+
t - n.lastTouchedAt >= _sgIdleMs
|
|
672
|
+
) {
|
|
673
|
+
n.status = SG_NODE_MATURITY_V2.INACTIVE;
|
|
674
|
+
n.updatedAt = t;
|
|
675
|
+
flipped.push(n.id);
|
|
676
|
+
}
|
|
677
|
+
return { flipped, count: flipped.length };
|
|
678
|
+
}
|
|
679
|
+
export function autoExpireStaleSgEdgesV2({ now } = {}) {
|
|
680
|
+
const t = now ?? Date.now();
|
|
681
|
+
const flipped = [];
|
|
682
|
+
for (const e of _sgEsV2.values())
|
|
683
|
+
if (
|
|
684
|
+
e.status === SG_EDGE_LIFECYCLE_V2.PROPOSED &&
|
|
685
|
+
t - e.startedAt >= _sgStuckMs
|
|
686
|
+
) {
|
|
687
|
+
e.status = SG_EDGE_LIFECYCLE_V2.CANCELLED;
|
|
688
|
+
e.updatedAt = t;
|
|
689
|
+
if (!e.settledAt) e.settledAt = t;
|
|
690
|
+
e.metadata.cancelReason = "auto-cancel-stale";
|
|
691
|
+
flipped.push(e.id);
|
|
692
|
+
}
|
|
693
|
+
return { flipped, count: flipped.length };
|
|
694
|
+
}
|
|
695
|
+
export function getSocialGraphGovStatsV2() {
|
|
696
|
+
const nodesByStatus = {};
|
|
697
|
+
for (const v of Object.values(SG_NODE_MATURITY_V2)) nodesByStatus[v] = 0;
|
|
698
|
+
for (const n of _sgNsV2.values()) nodesByStatus[n.status]++;
|
|
699
|
+
const edgesByStatus = {};
|
|
700
|
+
for (const v of Object.values(SG_EDGE_LIFECYCLE_V2)) edgesByStatus[v] = 0;
|
|
701
|
+
for (const e of _sgEsV2.values()) edgesByStatus[e.status]++;
|
|
702
|
+
return {
|
|
703
|
+
totalSgNodesV2: _sgNsV2.size,
|
|
704
|
+
totalSgEdgesV2: _sgEsV2.size,
|
|
705
|
+
maxActiveSgNodesPerOwner: _sgMaxActivePerOwner,
|
|
706
|
+
maxPendingSgEdgesPerNode: _sgMaxPendingEdgesPerNode,
|
|
707
|
+
sgNodeIdleMs: _sgIdleMs,
|
|
708
|
+
sgEdgeStuckMs: _sgStuckMs,
|
|
709
|
+
nodesByStatus,
|
|
710
|
+
edgesByStatus,
|
|
711
|
+
};
|
|
712
|
+
}
|
package/src/lib/stress-tester.js
CHANGED
|
@@ -711,3 +711,345 @@ export function getStressStatsV2() {
|
|
|
711
711
|
},
|
|
712
712
|
};
|
|
713
713
|
}
|
|
714
|
+
|
|
715
|
+
// =====================================================================
|
|
716
|
+
// stress-tester V2 governance overlay (iter16)
|
|
717
|
+
// =====================================================================
|
|
718
|
+
export const STRGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
719
|
+
PENDING: "pending",
|
|
720
|
+
ACTIVE: "active",
|
|
721
|
+
STALE: "stale",
|
|
722
|
+
ARCHIVED: "archived",
|
|
723
|
+
});
|
|
724
|
+
export const STRGOV_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
725
|
+
QUEUED: "queued",
|
|
726
|
+
RUNNING: "running",
|
|
727
|
+
COMPLETED: "completed",
|
|
728
|
+
FAILED: "failed",
|
|
729
|
+
CANCELLED: "cancelled",
|
|
730
|
+
});
|
|
731
|
+
const _strgovPTrans = new Map([
|
|
732
|
+
[
|
|
733
|
+
STRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
734
|
+
new Set([
|
|
735
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
736
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
737
|
+
]),
|
|
738
|
+
],
|
|
739
|
+
[
|
|
740
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
741
|
+
new Set([
|
|
742
|
+
STRGOV_PROFILE_MATURITY_V2.STALE,
|
|
743
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
744
|
+
]),
|
|
745
|
+
],
|
|
746
|
+
[
|
|
747
|
+
STRGOV_PROFILE_MATURITY_V2.STALE,
|
|
748
|
+
new Set([
|
|
749
|
+
STRGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
750
|
+
STRGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
751
|
+
]),
|
|
752
|
+
],
|
|
753
|
+
[STRGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
754
|
+
]);
|
|
755
|
+
const _strgovPTerminal = new Set([STRGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
756
|
+
const _strgovJTrans = new Map([
|
|
757
|
+
[
|
|
758
|
+
STRGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
759
|
+
new Set([
|
|
760
|
+
STRGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
761
|
+
STRGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
762
|
+
]),
|
|
763
|
+
],
|
|
764
|
+
[
|
|
765
|
+
STRGOV_RUN_LIFECYCLE_V2.RUNNING,
|
|
766
|
+
new Set([
|
|
767
|
+
STRGOV_RUN_LIFECYCLE_V2.COMPLETED,
|
|
768
|
+
STRGOV_RUN_LIFECYCLE_V2.FAILED,
|
|
769
|
+
STRGOV_RUN_LIFECYCLE_V2.CANCELLED,
|
|
770
|
+
]),
|
|
771
|
+
],
|
|
772
|
+
[STRGOV_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
773
|
+
[STRGOV_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
774
|
+
[STRGOV_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
775
|
+
]);
|
|
776
|
+
const _strgovPsV2 = new Map();
|
|
777
|
+
const _strgovJsV2 = new Map();
|
|
778
|
+
let _strgovMaxActive = 5,
|
|
779
|
+
_strgovMaxPending = 10,
|
|
780
|
+
_strgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
781
|
+
_strgovStuckMs = 60 * 1000;
|
|
782
|
+
function _strgovPos(n, label) {
|
|
783
|
+
const v = Math.floor(Number(n));
|
|
784
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
785
|
+
throw new Error(`${label} must be positive integer`);
|
|
786
|
+
return v;
|
|
787
|
+
}
|
|
788
|
+
function _strgovCheckP(from, to) {
|
|
789
|
+
const a = _strgovPTrans.get(from);
|
|
790
|
+
if (!a || !a.has(to))
|
|
791
|
+
throw new Error(`invalid strgov profile transition ${from} → ${to}`);
|
|
792
|
+
}
|
|
793
|
+
function _strgovCheckJ(from, to) {
|
|
794
|
+
const a = _strgovJTrans.get(from);
|
|
795
|
+
if (!a || !a.has(to))
|
|
796
|
+
throw new Error(`invalid strgov run transition ${from} → ${to}`);
|
|
797
|
+
}
|
|
798
|
+
function _strgovCountActive(owner) {
|
|
799
|
+
let c = 0;
|
|
800
|
+
for (const p of _strgovPsV2.values())
|
|
801
|
+
if (p.owner === owner && p.status === STRGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
802
|
+
c++;
|
|
803
|
+
return c;
|
|
804
|
+
}
|
|
805
|
+
function _strgovCountPending(profileId) {
|
|
806
|
+
let c = 0;
|
|
807
|
+
for (const j of _strgovJsV2.values())
|
|
808
|
+
if (
|
|
809
|
+
j.profileId === profileId &&
|
|
810
|
+
(j.status === STRGOV_RUN_LIFECYCLE_V2.QUEUED ||
|
|
811
|
+
j.status === STRGOV_RUN_LIFECYCLE_V2.RUNNING)
|
|
812
|
+
)
|
|
813
|
+
c++;
|
|
814
|
+
return c;
|
|
815
|
+
}
|
|
816
|
+
export function setMaxActiveStrgovProfilesPerOwnerV2(n) {
|
|
817
|
+
_strgovMaxActive = _strgovPos(n, "maxActiveStrgovProfilesPerOwner");
|
|
818
|
+
}
|
|
819
|
+
export function getMaxActiveStrgovProfilesPerOwnerV2() {
|
|
820
|
+
return _strgovMaxActive;
|
|
821
|
+
}
|
|
822
|
+
export function setMaxPendingStrgovRunsPerProfileV2(n) {
|
|
823
|
+
_strgovMaxPending = _strgovPos(n, "maxPendingStrgovRunsPerProfile");
|
|
824
|
+
}
|
|
825
|
+
export function getMaxPendingStrgovRunsPerProfileV2() {
|
|
826
|
+
return _strgovMaxPending;
|
|
827
|
+
}
|
|
828
|
+
export function setStrgovProfileIdleMsV2(n) {
|
|
829
|
+
_strgovIdleMs = _strgovPos(n, "strgovProfileIdleMs");
|
|
830
|
+
}
|
|
831
|
+
export function getStrgovProfileIdleMsV2() {
|
|
832
|
+
return _strgovIdleMs;
|
|
833
|
+
}
|
|
834
|
+
export function setStrgovRunStuckMsV2(n) {
|
|
835
|
+
_strgovStuckMs = _strgovPos(n, "strgovRunStuckMs");
|
|
836
|
+
}
|
|
837
|
+
export function getStrgovRunStuckMsV2() {
|
|
838
|
+
return _strgovStuckMs;
|
|
839
|
+
}
|
|
840
|
+
export function _resetStateStressTesterV2() {
|
|
841
|
+
_strgovPsV2.clear();
|
|
842
|
+
_strgovJsV2.clear();
|
|
843
|
+
_strgovMaxActive = 5;
|
|
844
|
+
_strgovMaxPending = 10;
|
|
845
|
+
_strgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
846
|
+
_strgovStuckMs = 60 * 1000;
|
|
847
|
+
}
|
|
848
|
+
export function registerStrgovProfileV2({
|
|
849
|
+
id,
|
|
850
|
+
owner,
|
|
851
|
+
scenario,
|
|
852
|
+
metadata,
|
|
853
|
+
} = {}) {
|
|
854
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
855
|
+
if (_strgovPsV2.has(id))
|
|
856
|
+
throw new Error(`strgov profile ${id} already exists`);
|
|
857
|
+
const now = Date.now();
|
|
858
|
+
const p = {
|
|
859
|
+
id,
|
|
860
|
+
owner,
|
|
861
|
+
scenario: scenario || "ramp",
|
|
862
|
+
status: STRGOV_PROFILE_MATURITY_V2.PENDING,
|
|
863
|
+
createdAt: now,
|
|
864
|
+
updatedAt: now,
|
|
865
|
+
lastTouchedAt: now,
|
|
866
|
+
activatedAt: null,
|
|
867
|
+
archivedAt: null,
|
|
868
|
+
metadata: { ...(metadata || {}) },
|
|
869
|
+
};
|
|
870
|
+
_strgovPsV2.set(id, p);
|
|
871
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
872
|
+
}
|
|
873
|
+
export function activateStrgovProfileV2(id) {
|
|
874
|
+
const p = _strgovPsV2.get(id);
|
|
875
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
876
|
+
const isInitial = p.status === STRGOV_PROFILE_MATURITY_V2.PENDING;
|
|
877
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
878
|
+
if (isInitial && _strgovCountActive(p.owner) >= _strgovMaxActive)
|
|
879
|
+
throw new Error(`max active strgov profiles for owner ${p.owner} reached`);
|
|
880
|
+
const now = Date.now();
|
|
881
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
882
|
+
p.updatedAt = now;
|
|
883
|
+
p.lastTouchedAt = now;
|
|
884
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
885
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
886
|
+
}
|
|
887
|
+
export function staleStrgovProfileV2(id) {
|
|
888
|
+
const p = _strgovPsV2.get(id);
|
|
889
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
890
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.STALE);
|
|
891
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.STALE;
|
|
892
|
+
p.updatedAt = Date.now();
|
|
893
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
894
|
+
}
|
|
895
|
+
export function archiveStrgovProfileV2(id) {
|
|
896
|
+
const p = _strgovPsV2.get(id);
|
|
897
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
898
|
+
_strgovCheckP(p.status, STRGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
899
|
+
const now = Date.now();
|
|
900
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
901
|
+
p.updatedAt = now;
|
|
902
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
903
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
904
|
+
}
|
|
905
|
+
export function touchStrgovProfileV2(id) {
|
|
906
|
+
const p = _strgovPsV2.get(id);
|
|
907
|
+
if (!p) throw new Error(`strgov profile ${id} not found`);
|
|
908
|
+
if (_strgovPTerminal.has(p.status))
|
|
909
|
+
throw new Error(`cannot touch terminal strgov profile ${id}`);
|
|
910
|
+
const now = Date.now();
|
|
911
|
+
p.lastTouchedAt = now;
|
|
912
|
+
p.updatedAt = now;
|
|
913
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
914
|
+
}
|
|
915
|
+
export function getStrgovProfileV2(id) {
|
|
916
|
+
const p = _strgovPsV2.get(id);
|
|
917
|
+
if (!p) return null;
|
|
918
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
919
|
+
}
|
|
920
|
+
export function listStrgovProfilesV2() {
|
|
921
|
+
return [..._strgovPsV2.values()].map((p) => ({
|
|
922
|
+
...p,
|
|
923
|
+
metadata: { ...p.metadata },
|
|
924
|
+
}));
|
|
925
|
+
}
|
|
926
|
+
export function createStrgovRunV2({
|
|
927
|
+
id,
|
|
928
|
+
profileId,
|
|
929
|
+
profileRef,
|
|
930
|
+
metadata,
|
|
931
|
+
} = {}) {
|
|
932
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
933
|
+
if (_strgovJsV2.has(id)) throw new Error(`strgov run ${id} already exists`);
|
|
934
|
+
if (!_strgovPsV2.has(profileId))
|
|
935
|
+
throw new Error(`strgov profile ${profileId} not found`);
|
|
936
|
+
if (_strgovCountPending(profileId) >= _strgovMaxPending)
|
|
937
|
+
throw new Error(`max pending strgov runs for profile ${profileId} reached`);
|
|
938
|
+
const now = Date.now();
|
|
939
|
+
const j = {
|
|
940
|
+
id,
|
|
941
|
+
profileId,
|
|
942
|
+
profileRef: profileRef || "",
|
|
943
|
+
status: STRGOV_RUN_LIFECYCLE_V2.QUEUED,
|
|
944
|
+
createdAt: now,
|
|
945
|
+
updatedAt: now,
|
|
946
|
+
startedAt: null,
|
|
947
|
+
settledAt: null,
|
|
948
|
+
metadata: { ...(metadata || {}) },
|
|
949
|
+
};
|
|
950
|
+
_strgovJsV2.set(id, j);
|
|
951
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
952
|
+
}
|
|
953
|
+
export function runningStrgovRunV2(id) {
|
|
954
|
+
const j = _strgovJsV2.get(id);
|
|
955
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
956
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.RUNNING);
|
|
957
|
+
const now = Date.now();
|
|
958
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.RUNNING;
|
|
959
|
+
j.updatedAt = now;
|
|
960
|
+
if (!j.startedAt) j.startedAt = now;
|
|
961
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
962
|
+
}
|
|
963
|
+
export function completeRunStrgovV2(id) {
|
|
964
|
+
const j = _strgovJsV2.get(id);
|
|
965
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
966
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.COMPLETED);
|
|
967
|
+
const now = Date.now();
|
|
968
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.COMPLETED;
|
|
969
|
+
j.updatedAt = now;
|
|
970
|
+
if (!j.settledAt) j.settledAt = now;
|
|
971
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
972
|
+
}
|
|
973
|
+
export function failStrgovRunV2(id, reason) {
|
|
974
|
+
const j = _strgovJsV2.get(id);
|
|
975
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
976
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.FAILED);
|
|
977
|
+
const now = Date.now();
|
|
978
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
979
|
+
j.updatedAt = now;
|
|
980
|
+
if (!j.settledAt) j.settledAt = now;
|
|
981
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
982
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
983
|
+
}
|
|
984
|
+
export function cancelStrgovRunV2(id, reason) {
|
|
985
|
+
const j = _strgovJsV2.get(id);
|
|
986
|
+
if (!j) throw new Error(`strgov run ${id} not found`);
|
|
987
|
+
_strgovCheckJ(j.status, STRGOV_RUN_LIFECYCLE_V2.CANCELLED);
|
|
988
|
+
const now = Date.now();
|
|
989
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.CANCELLED;
|
|
990
|
+
j.updatedAt = now;
|
|
991
|
+
if (!j.settledAt) j.settledAt = now;
|
|
992
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
993
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
994
|
+
}
|
|
995
|
+
export function getStrgovRunV2(id) {
|
|
996
|
+
const j = _strgovJsV2.get(id);
|
|
997
|
+
if (!j) return null;
|
|
998
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
999
|
+
}
|
|
1000
|
+
export function listStrgovRunsV2() {
|
|
1001
|
+
return [..._strgovJsV2.values()].map((j) => ({
|
|
1002
|
+
...j,
|
|
1003
|
+
metadata: { ...j.metadata },
|
|
1004
|
+
}));
|
|
1005
|
+
}
|
|
1006
|
+
export function autoStaleIdleStrgovProfilesV2({ now } = {}) {
|
|
1007
|
+
const t = now ?? Date.now();
|
|
1008
|
+
const flipped = [];
|
|
1009
|
+
for (const p of _strgovPsV2.values())
|
|
1010
|
+
if (
|
|
1011
|
+
p.status === STRGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1012
|
+
t - p.lastTouchedAt >= _strgovIdleMs
|
|
1013
|
+
) {
|
|
1014
|
+
p.status = STRGOV_PROFILE_MATURITY_V2.STALE;
|
|
1015
|
+
p.updatedAt = t;
|
|
1016
|
+
flipped.push(p.id);
|
|
1017
|
+
}
|
|
1018
|
+
return { flipped, count: flipped.length };
|
|
1019
|
+
}
|
|
1020
|
+
export function autoFailStuckStrgovRunsV2({ now } = {}) {
|
|
1021
|
+
const t = now ?? Date.now();
|
|
1022
|
+
const flipped = [];
|
|
1023
|
+
for (const j of _strgovJsV2.values())
|
|
1024
|
+
if (
|
|
1025
|
+
j.status === STRGOV_RUN_LIFECYCLE_V2.RUNNING &&
|
|
1026
|
+
j.startedAt != null &&
|
|
1027
|
+
t - j.startedAt >= _strgovStuckMs
|
|
1028
|
+
) {
|
|
1029
|
+
j.status = STRGOV_RUN_LIFECYCLE_V2.FAILED;
|
|
1030
|
+
j.updatedAt = t;
|
|
1031
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1032
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1033
|
+
flipped.push(j.id);
|
|
1034
|
+
}
|
|
1035
|
+
return { flipped, count: flipped.length };
|
|
1036
|
+
}
|
|
1037
|
+
export function getStressTesterGovStatsV2() {
|
|
1038
|
+
const profilesByStatus = {};
|
|
1039
|
+
for (const v of Object.values(STRGOV_PROFILE_MATURITY_V2))
|
|
1040
|
+
profilesByStatus[v] = 0;
|
|
1041
|
+
for (const p of _strgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1042
|
+
const runsByStatus = {};
|
|
1043
|
+
for (const v of Object.values(STRGOV_RUN_LIFECYCLE_V2)) runsByStatus[v] = 0;
|
|
1044
|
+
for (const j of _strgovJsV2.values()) runsByStatus[j.status]++;
|
|
1045
|
+
return {
|
|
1046
|
+
totalStrgovProfilesV2: _strgovPsV2.size,
|
|
1047
|
+
totalStrgovRunsV2: _strgovJsV2.size,
|
|
1048
|
+
maxActiveStrgovProfilesPerOwner: _strgovMaxActive,
|
|
1049
|
+
maxPendingStrgovRunsPerProfile: _strgovMaxPending,
|
|
1050
|
+
strgovProfileIdleMs: _strgovIdleMs,
|
|
1051
|
+
strgovRunStuckMs: _strgovStuckMs,
|
|
1052
|
+
profilesByStatus,
|
|
1053
|
+
runsByStatus,
|
|
1054
|
+
};
|
|
1055
|
+
}
|