chainlesschain 0.145.0 → 0.156.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -1409,3 +1409,337 @@ export function getHierarchicalMemoryGovStatsV2() {
|
|
|
1409
1409
|
promotionsByStatus,
|
|
1410
1410
|
};
|
|
1411
1411
|
}
|
|
1412
|
+
|
|
1413
|
+
// === Iter28 V2 governance overlay: Hmemgov ===
|
|
1414
|
+
export const HMEMGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1415
|
+
PENDING: "pending",
|
|
1416
|
+
ACTIVE: "active",
|
|
1417
|
+
STALE: "stale",
|
|
1418
|
+
ARCHIVED: "archived",
|
|
1419
|
+
});
|
|
1420
|
+
export const HMEMGOV_RECALL_LIFECYCLE_V2 = Object.freeze({
|
|
1421
|
+
QUEUED: "queued",
|
|
1422
|
+
RECALLING: "recalling",
|
|
1423
|
+
RECALLED: "recalled",
|
|
1424
|
+
FAILED: "failed",
|
|
1425
|
+
CANCELLED: "cancelled",
|
|
1426
|
+
});
|
|
1427
|
+
const _hmemgovPTrans = new Map([
|
|
1428
|
+
[
|
|
1429
|
+
HMEMGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1430
|
+
new Set([
|
|
1431
|
+
HMEMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1432
|
+
HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1433
|
+
]),
|
|
1434
|
+
],
|
|
1435
|
+
[
|
|
1436
|
+
HMEMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1437
|
+
new Set([
|
|
1438
|
+
HMEMGOV_PROFILE_MATURITY_V2.STALE,
|
|
1439
|
+
HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1440
|
+
]),
|
|
1441
|
+
],
|
|
1442
|
+
[
|
|
1443
|
+
HMEMGOV_PROFILE_MATURITY_V2.STALE,
|
|
1444
|
+
new Set([
|
|
1445
|
+
HMEMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1446
|
+
HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1447
|
+
]),
|
|
1448
|
+
],
|
|
1449
|
+
[HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1450
|
+
]);
|
|
1451
|
+
const _hmemgovPTerminal = new Set([HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1452
|
+
const _hmemgovJTrans = new Map([
|
|
1453
|
+
[
|
|
1454
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.QUEUED,
|
|
1455
|
+
new Set([
|
|
1456
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING,
|
|
1457
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.CANCELLED,
|
|
1458
|
+
]),
|
|
1459
|
+
],
|
|
1460
|
+
[
|
|
1461
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING,
|
|
1462
|
+
new Set([
|
|
1463
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.RECALLED,
|
|
1464
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.FAILED,
|
|
1465
|
+
HMEMGOV_RECALL_LIFECYCLE_V2.CANCELLED,
|
|
1466
|
+
]),
|
|
1467
|
+
],
|
|
1468
|
+
[HMEMGOV_RECALL_LIFECYCLE_V2.RECALLED, new Set()],
|
|
1469
|
+
[HMEMGOV_RECALL_LIFECYCLE_V2.FAILED, new Set()],
|
|
1470
|
+
[HMEMGOV_RECALL_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1471
|
+
]);
|
|
1472
|
+
const _hmemgovPsV2 = new Map();
|
|
1473
|
+
const _hmemgovJsV2 = new Map();
|
|
1474
|
+
let _hmemgovMaxActive = 10,
|
|
1475
|
+
_hmemgovMaxPending = 30,
|
|
1476
|
+
_hmemgovIdleMs = 2592000000,
|
|
1477
|
+
_hmemgovStuckMs = 60 * 1000;
|
|
1478
|
+
function _hmemgovPos(n, label) {
|
|
1479
|
+
const v = Math.floor(Number(n));
|
|
1480
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1481
|
+
throw new Error(`${label} must be positive integer`);
|
|
1482
|
+
return v;
|
|
1483
|
+
}
|
|
1484
|
+
function _hmemgovCheckP(from, to) {
|
|
1485
|
+
const a = _hmemgovPTrans.get(from);
|
|
1486
|
+
if (!a || !a.has(to))
|
|
1487
|
+
throw new Error(`invalid hmemgov profile transition ${from} → ${to}`);
|
|
1488
|
+
}
|
|
1489
|
+
function _hmemgovCheckJ(from, to) {
|
|
1490
|
+
const a = _hmemgovJTrans.get(from);
|
|
1491
|
+
if (!a || !a.has(to))
|
|
1492
|
+
throw new Error(`invalid hmemgov recall transition ${from} → ${to}`);
|
|
1493
|
+
}
|
|
1494
|
+
function _hmemgovCountActive(owner) {
|
|
1495
|
+
let c = 0;
|
|
1496
|
+
for (const p of _hmemgovPsV2.values())
|
|
1497
|
+
if (p.owner === owner && p.status === HMEMGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1498
|
+
c++;
|
|
1499
|
+
return c;
|
|
1500
|
+
}
|
|
1501
|
+
function _hmemgovCountPending(profileId) {
|
|
1502
|
+
let c = 0;
|
|
1503
|
+
for (const j of _hmemgovJsV2.values())
|
|
1504
|
+
if (
|
|
1505
|
+
j.profileId === profileId &&
|
|
1506
|
+
(j.status === HMEMGOV_RECALL_LIFECYCLE_V2.QUEUED ||
|
|
1507
|
+
j.status === HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING)
|
|
1508
|
+
)
|
|
1509
|
+
c++;
|
|
1510
|
+
return c;
|
|
1511
|
+
}
|
|
1512
|
+
export function setMaxActiveHmemProfilesPerOwnerV2(n) {
|
|
1513
|
+
_hmemgovMaxActive = _hmemgovPos(n, "maxActiveHmemProfilesPerOwner");
|
|
1514
|
+
}
|
|
1515
|
+
export function getMaxActiveHmemProfilesPerOwnerV2() {
|
|
1516
|
+
return _hmemgovMaxActive;
|
|
1517
|
+
}
|
|
1518
|
+
export function setMaxPendingHmemRecallsPerProfileV2(n) {
|
|
1519
|
+
_hmemgovMaxPending = _hmemgovPos(n, "maxPendingHmemRecallsPerProfile");
|
|
1520
|
+
}
|
|
1521
|
+
export function getMaxPendingHmemRecallsPerProfileV2() {
|
|
1522
|
+
return _hmemgovMaxPending;
|
|
1523
|
+
}
|
|
1524
|
+
export function setHmemProfileIdleMsV2(n) {
|
|
1525
|
+
_hmemgovIdleMs = _hmemgovPos(n, "hmemgovProfileIdleMs");
|
|
1526
|
+
}
|
|
1527
|
+
export function getHmemProfileIdleMsV2() {
|
|
1528
|
+
return _hmemgovIdleMs;
|
|
1529
|
+
}
|
|
1530
|
+
export function setHmemRecallStuckMsV2(n) {
|
|
1531
|
+
_hmemgovStuckMs = _hmemgovPos(n, "hmemgovRecallStuckMs");
|
|
1532
|
+
}
|
|
1533
|
+
export function getHmemRecallStuckMsV2() {
|
|
1534
|
+
return _hmemgovStuckMs;
|
|
1535
|
+
}
|
|
1536
|
+
export function _resetStateHmemgovV2() {
|
|
1537
|
+
_hmemgovPsV2.clear();
|
|
1538
|
+
_hmemgovJsV2.clear();
|
|
1539
|
+
_hmemgovMaxActive = 10;
|
|
1540
|
+
_hmemgovMaxPending = 30;
|
|
1541
|
+
_hmemgovIdleMs = 2592000000;
|
|
1542
|
+
_hmemgovStuckMs = 60 * 1000;
|
|
1543
|
+
}
|
|
1544
|
+
export function registerHmemProfileV2({ id, owner, tier, metadata } = {}) {
|
|
1545
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1546
|
+
if (_hmemgovPsV2.has(id))
|
|
1547
|
+
throw new Error(`hmemgov profile ${id} already exists`);
|
|
1548
|
+
const now = Date.now();
|
|
1549
|
+
const p = {
|
|
1550
|
+
id,
|
|
1551
|
+
owner,
|
|
1552
|
+
tier: tier || "short-term",
|
|
1553
|
+
status: HMEMGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1554
|
+
createdAt: now,
|
|
1555
|
+
updatedAt: now,
|
|
1556
|
+
lastTouchedAt: now,
|
|
1557
|
+
activatedAt: null,
|
|
1558
|
+
archivedAt: null,
|
|
1559
|
+
metadata: { ...(metadata || {}) },
|
|
1560
|
+
};
|
|
1561
|
+
_hmemgovPsV2.set(id, p);
|
|
1562
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1563
|
+
}
|
|
1564
|
+
export function activateHmemProfileV2(id) {
|
|
1565
|
+
const p = _hmemgovPsV2.get(id);
|
|
1566
|
+
if (!p) throw new Error(`hmemgov profile ${id} not found`);
|
|
1567
|
+
const isInitial = p.status === HMEMGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1568
|
+
_hmemgovCheckP(p.status, HMEMGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1569
|
+
if (isInitial && _hmemgovCountActive(p.owner) >= _hmemgovMaxActive)
|
|
1570
|
+
throw new Error(`max active hmemgov profiles for owner ${p.owner} reached`);
|
|
1571
|
+
const now = Date.now();
|
|
1572
|
+
p.status = HMEMGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1573
|
+
p.updatedAt = now;
|
|
1574
|
+
p.lastTouchedAt = now;
|
|
1575
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1576
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1577
|
+
}
|
|
1578
|
+
export function staleHmemProfileV2(id) {
|
|
1579
|
+
const p = _hmemgovPsV2.get(id);
|
|
1580
|
+
if (!p) throw new Error(`hmemgov profile ${id} not found`);
|
|
1581
|
+
_hmemgovCheckP(p.status, HMEMGOV_PROFILE_MATURITY_V2.STALE);
|
|
1582
|
+
p.status = HMEMGOV_PROFILE_MATURITY_V2.STALE;
|
|
1583
|
+
p.updatedAt = Date.now();
|
|
1584
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1585
|
+
}
|
|
1586
|
+
export function archiveHmemProfileV2(id) {
|
|
1587
|
+
const p = _hmemgovPsV2.get(id);
|
|
1588
|
+
if (!p) throw new Error(`hmemgov profile ${id} not found`);
|
|
1589
|
+
_hmemgovCheckP(p.status, HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1590
|
+
const now = Date.now();
|
|
1591
|
+
p.status = HMEMGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1592
|
+
p.updatedAt = now;
|
|
1593
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1594
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1595
|
+
}
|
|
1596
|
+
export function touchHmemProfileV2(id) {
|
|
1597
|
+
const p = _hmemgovPsV2.get(id);
|
|
1598
|
+
if (!p) throw new Error(`hmemgov profile ${id} not found`);
|
|
1599
|
+
if (_hmemgovPTerminal.has(p.status))
|
|
1600
|
+
throw new Error(`cannot touch terminal hmemgov profile ${id}`);
|
|
1601
|
+
const now = Date.now();
|
|
1602
|
+
p.lastTouchedAt = now;
|
|
1603
|
+
p.updatedAt = now;
|
|
1604
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1605
|
+
}
|
|
1606
|
+
export function getHmemProfileV2(id) {
|
|
1607
|
+
const p = _hmemgovPsV2.get(id);
|
|
1608
|
+
if (!p) return null;
|
|
1609
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1610
|
+
}
|
|
1611
|
+
export function listHmemProfilesV2() {
|
|
1612
|
+
return [..._hmemgovPsV2.values()].map((p) => ({
|
|
1613
|
+
...p,
|
|
1614
|
+
metadata: { ...p.metadata },
|
|
1615
|
+
}));
|
|
1616
|
+
}
|
|
1617
|
+
export function createHmemRecallV2({ id, profileId, queryId, metadata } = {}) {
|
|
1618
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1619
|
+
if (_hmemgovJsV2.has(id))
|
|
1620
|
+
throw new Error(`hmemgov recall ${id} already exists`);
|
|
1621
|
+
if (!_hmemgovPsV2.has(profileId))
|
|
1622
|
+
throw new Error(`hmemgov profile ${profileId} not found`);
|
|
1623
|
+
if (_hmemgovCountPending(profileId) >= _hmemgovMaxPending)
|
|
1624
|
+
throw new Error(
|
|
1625
|
+
`max pending hmemgov recalls for profile ${profileId} reached`,
|
|
1626
|
+
);
|
|
1627
|
+
const now = Date.now();
|
|
1628
|
+
const j = {
|
|
1629
|
+
id,
|
|
1630
|
+
profileId,
|
|
1631
|
+
queryId: queryId || "",
|
|
1632
|
+
status: HMEMGOV_RECALL_LIFECYCLE_V2.QUEUED,
|
|
1633
|
+
createdAt: now,
|
|
1634
|
+
updatedAt: now,
|
|
1635
|
+
startedAt: null,
|
|
1636
|
+
settledAt: null,
|
|
1637
|
+
metadata: { ...(metadata || {}) },
|
|
1638
|
+
};
|
|
1639
|
+
_hmemgovJsV2.set(id, j);
|
|
1640
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1641
|
+
}
|
|
1642
|
+
export function recallingHmemRecallV2(id) {
|
|
1643
|
+
const j = _hmemgovJsV2.get(id);
|
|
1644
|
+
if (!j) throw new Error(`hmemgov recall ${id} not found`);
|
|
1645
|
+
_hmemgovCheckJ(j.status, HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING);
|
|
1646
|
+
const now = Date.now();
|
|
1647
|
+
j.status = HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING;
|
|
1648
|
+
j.updatedAt = now;
|
|
1649
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1650
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1651
|
+
}
|
|
1652
|
+
export function completeRecallHmemV2(id) {
|
|
1653
|
+
const j = _hmemgovJsV2.get(id);
|
|
1654
|
+
if (!j) throw new Error(`hmemgov recall ${id} not found`);
|
|
1655
|
+
_hmemgovCheckJ(j.status, HMEMGOV_RECALL_LIFECYCLE_V2.RECALLED);
|
|
1656
|
+
const now = Date.now();
|
|
1657
|
+
j.status = HMEMGOV_RECALL_LIFECYCLE_V2.RECALLED;
|
|
1658
|
+
j.updatedAt = now;
|
|
1659
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1660
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1661
|
+
}
|
|
1662
|
+
export function failHmemRecallV2(id, reason) {
|
|
1663
|
+
const j = _hmemgovJsV2.get(id);
|
|
1664
|
+
if (!j) throw new Error(`hmemgov recall ${id} not found`);
|
|
1665
|
+
_hmemgovCheckJ(j.status, HMEMGOV_RECALL_LIFECYCLE_V2.FAILED);
|
|
1666
|
+
const now = Date.now();
|
|
1667
|
+
j.status = HMEMGOV_RECALL_LIFECYCLE_V2.FAILED;
|
|
1668
|
+
j.updatedAt = now;
|
|
1669
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1670
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1671
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1672
|
+
}
|
|
1673
|
+
export function cancelHmemRecallV2(id, reason) {
|
|
1674
|
+
const j = _hmemgovJsV2.get(id);
|
|
1675
|
+
if (!j) throw new Error(`hmemgov recall ${id} not found`);
|
|
1676
|
+
_hmemgovCheckJ(j.status, HMEMGOV_RECALL_LIFECYCLE_V2.CANCELLED);
|
|
1677
|
+
const now = Date.now();
|
|
1678
|
+
j.status = HMEMGOV_RECALL_LIFECYCLE_V2.CANCELLED;
|
|
1679
|
+
j.updatedAt = now;
|
|
1680
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1681
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1682
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1683
|
+
}
|
|
1684
|
+
export function getHmemRecallV2(id) {
|
|
1685
|
+
const j = _hmemgovJsV2.get(id);
|
|
1686
|
+
if (!j) return null;
|
|
1687
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1688
|
+
}
|
|
1689
|
+
export function listHmemRecallsV2() {
|
|
1690
|
+
return [..._hmemgovJsV2.values()].map((j) => ({
|
|
1691
|
+
...j,
|
|
1692
|
+
metadata: { ...j.metadata },
|
|
1693
|
+
}));
|
|
1694
|
+
}
|
|
1695
|
+
export function autoStaleIdleHmemProfilesV2({ now } = {}) {
|
|
1696
|
+
const t = now ?? Date.now();
|
|
1697
|
+
const flipped = [];
|
|
1698
|
+
for (const p of _hmemgovPsV2.values())
|
|
1699
|
+
if (
|
|
1700
|
+
p.status === HMEMGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1701
|
+
t - p.lastTouchedAt >= _hmemgovIdleMs
|
|
1702
|
+
) {
|
|
1703
|
+
p.status = HMEMGOV_PROFILE_MATURITY_V2.STALE;
|
|
1704
|
+
p.updatedAt = t;
|
|
1705
|
+
flipped.push(p.id);
|
|
1706
|
+
}
|
|
1707
|
+
return { flipped, count: flipped.length };
|
|
1708
|
+
}
|
|
1709
|
+
export function autoFailStuckHmemRecallsV2({ now } = {}) {
|
|
1710
|
+
const t = now ?? Date.now();
|
|
1711
|
+
const flipped = [];
|
|
1712
|
+
for (const j of _hmemgovJsV2.values())
|
|
1713
|
+
if (
|
|
1714
|
+
j.status === HMEMGOV_RECALL_LIFECYCLE_V2.RECALLING &&
|
|
1715
|
+
j.startedAt != null &&
|
|
1716
|
+
t - j.startedAt >= _hmemgovStuckMs
|
|
1717
|
+
) {
|
|
1718
|
+
j.status = HMEMGOV_RECALL_LIFECYCLE_V2.FAILED;
|
|
1719
|
+
j.updatedAt = t;
|
|
1720
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1721
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1722
|
+
flipped.push(j.id);
|
|
1723
|
+
}
|
|
1724
|
+
return { flipped, count: flipped.length };
|
|
1725
|
+
}
|
|
1726
|
+
export function getHmemgovStatsV2() {
|
|
1727
|
+
const profilesByStatus = {};
|
|
1728
|
+
for (const v of Object.values(HMEMGOV_PROFILE_MATURITY_V2))
|
|
1729
|
+
profilesByStatus[v] = 0;
|
|
1730
|
+
for (const p of _hmemgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1731
|
+
const recallsByStatus = {};
|
|
1732
|
+
for (const v of Object.values(HMEMGOV_RECALL_LIFECYCLE_V2))
|
|
1733
|
+
recallsByStatus[v] = 0;
|
|
1734
|
+
for (const j of _hmemgovJsV2.values()) recallsByStatus[j.status]++;
|
|
1735
|
+
return {
|
|
1736
|
+
totalHmemProfilesV2: _hmemgovPsV2.size,
|
|
1737
|
+
totalHmemRecallsV2: _hmemgovJsV2.size,
|
|
1738
|
+
maxActiveHmemProfilesPerOwner: _hmemgovMaxActive,
|
|
1739
|
+
maxPendingHmemRecallsPerProfile: _hmemgovMaxPending,
|
|
1740
|
+
hmemgovProfileIdleMs: _hmemgovIdleMs,
|
|
1741
|
+
hmemgovRecallStuckMs: _hmemgovStuckMs,
|
|
1742
|
+
profilesByStatus,
|
|
1743
|
+
recallsByStatus,
|
|
1744
|
+
};
|
|
1745
|
+
}
|
package/src/lib/hook-manager.js
CHANGED
|
@@ -767,3 +767,344 @@ export function getHookManagerStatsV2() {
|
|
|
767
767
|
execsByStatus,
|
|
768
768
|
};
|
|
769
769
|
}
|
|
770
|
+
|
|
771
|
+
// =====================================================================
|
|
772
|
+
// hook-manager V2 governance overlay (iter21)
|
|
773
|
+
// =====================================================================
|
|
774
|
+
export const HOOKGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
775
|
+
PENDING: "pending",
|
|
776
|
+
ACTIVE: "active",
|
|
777
|
+
DISABLED: "disabled",
|
|
778
|
+
ARCHIVED: "archived",
|
|
779
|
+
});
|
|
780
|
+
export const HOOKGOV_TRIGGER_LIFECYCLE_V2 = Object.freeze({
|
|
781
|
+
QUEUED: "queued",
|
|
782
|
+
FIRING: "firing",
|
|
783
|
+
FIRED: "fired",
|
|
784
|
+
FAILED: "failed",
|
|
785
|
+
CANCELLED: "cancelled",
|
|
786
|
+
});
|
|
787
|
+
const _hookgovPTrans = new Map([
|
|
788
|
+
[
|
|
789
|
+
HOOKGOV_PROFILE_MATURITY_V2.PENDING,
|
|
790
|
+
new Set([
|
|
791
|
+
HOOKGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
792
|
+
HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
793
|
+
]),
|
|
794
|
+
],
|
|
795
|
+
[
|
|
796
|
+
HOOKGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
797
|
+
new Set([
|
|
798
|
+
HOOKGOV_PROFILE_MATURITY_V2.DISABLED,
|
|
799
|
+
HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
800
|
+
]),
|
|
801
|
+
],
|
|
802
|
+
[
|
|
803
|
+
HOOKGOV_PROFILE_MATURITY_V2.DISABLED,
|
|
804
|
+
new Set([
|
|
805
|
+
HOOKGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
806
|
+
HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
807
|
+
]),
|
|
808
|
+
],
|
|
809
|
+
[HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
810
|
+
]);
|
|
811
|
+
const _hookgovPTerminal = new Set([HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
812
|
+
const _hookgovJTrans = new Map([
|
|
813
|
+
[
|
|
814
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
815
|
+
new Set([
|
|
816
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
817
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
818
|
+
]),
|
|
819
|
+
],
|
|
820
|
+
[
|
|
821
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING,
|
|
822
|
+
new Set([
|
|
823
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRED,
|
|
824
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.FAILED,
|
|
825
|
+
HOOKGOV_TRIGGER_LIFECYCLE_V2.CANCELLED,
|
|
826
|
+
]),
|
|
827
|
+
],
|
|
828
|
+
[HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRED, new Set()],
|
|
829
|
+
[HOOKGOV_TRIGGER_LIFECYCLE_V2.FAILED, new Set()],
|
|
830
|
+
[HOOKGOV_TRIGGER_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
831
|
+
]);
|
|
832
|
+
const _hookgovPsV2 = new Map();
|
|
833
|
+
const _hookgovJsV2 = new Map();
|
|
834
|
+
let _hookgovMaxActive = 12,
|
|
835
|
+
_hookgovMaxPending = 25,
|
|
836
|
+
_hookgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
837
|
+
_hookgovStuckMs = 60 * 1000;
|
|
838
|
+
function _hookgovPos(n, label) {
|
|
839
|
+
const v = Math.floor(Number(n));
|
|
840
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
841
|
+
throw new Error(`${label} must be positive integer`);
|
|
842
|
+
return v;
|
|
843
|
+
}
|
|
844
|
+
function _hookgovCheckP(from, to) {
|
|
845
|
+
const a = _hookgovPTrans.get(from);
|
|
846
|
+
if (!a || !a.has(to))
|
|
847
|
+
throw new Error(`invalid hookgov profile transition ${from} → ${to}`);
|
|
848
|
+
}
|
|
849
|
+
function _hookgovCheckJ(from, to) {
|
|
850
|
+
const a = _hookgovJTrans.get(from);
|
|
851
|
+
if (!a || !a.has(to))
|
|
852
|
+
throw new Error(`invalid hookgov trigger transition ${from} → ${to}`);
|
|
853
|
+
}
|
|
854
|
+
function _hookgovCountActive(owner) {
|
|
855
|
+
let c = 0;
|
|
856
|
+
for (const p of _hookgovPsV2.values())
|
|
857
|
+
if (p.owner === owner && p.status === HOOKGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
858
|
+
c++;
|
|
859
|
+
return c;
|
|
860
|
+
}
|
|
861
|
+
function _hookgovCountPending(profileId) {
|
|
862
|
+
let c = 0;
|
|
863
|
+
for (const j of _hookgovJsV2.values())
|
|
864
|
+
if (
|
|
865
|
+
j.profileId === profileId &&
|
|
866
|
+
(j.status === HOOKGOV_TRIGGER_LIFECYCLE_V2.QUEUED ||
|
|
867
|
+
j.status === HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING)
|
|
868
|
+
)
|
|
869
|
+
c++;
|
|
870
|
+
return c;
|
|
871
|
+
}
|
|
872
|
+
export function setMaxActiveHookgovProfilesPerOwnerV2(n) {
|
|
873
|
+
_hookgovMaxActive = _hookgovPos(n, "maxActiveHookgovProfilesPerOwner");
|
|
874
|
+
}
|
|
875
|
+
export function getMaxActiveHookgovProfilesPerOwnerV2() {
|
|
876
|
+
return _hookgovMaxActive;
|
|
877
|
+
}
|
|
878
|
+
export function setMaxPendingHookgovTriggersPerProfileV2(n) {
|
|
879
|
+
_hookgovMaxPending = _hookgovPos(n, "maxPendingHookgovTriggersPerProfile");
|
|
880
|
+
}
|
|
881
|
+
export function getMaxPendingHookgovTriggersPerProfileV2() {
|
|
882
|
+
return _hookgovMaxPending;
|
|
883
|
+
}
|
|
884
|
+
export function setHookgovProfileIdleMsV2(n) {
|
|
885
|
+
_hookgovIdleMs = _hookgovPos(n, "hookgovProfileIdleMs");
|
|
886
|
+
}
|
|
887
|
+
export function getHookgovProfileIdleMsV2() {
|
|
888
|
+
return _hookgovIdleMs;
|
|
889
|
+
}
|
|
890
|
+
export function setHookgovTriggerStuckMsV2(n) {
|
|
891
|
+
_hookgovStuckMs = _hookgovPos(n, "hookgovTriggerStuckMs");
|
|
892
|
+
}
|
|
893
|
+
export function getHookgovTriggerStuckMsV2() {
|
|
894
|
+
return _hookgovStuckMs;
|
|
895
|
+
}
|
|
896
|
+
export function _resetStateHookManagerGovV2() {
|
|
897
|
+
_hookgovPsV2.clear();
|
|
898
|
+
_hookgovJsV2.clear();
|
|
899
|
+
_hookgovMaxActive = 12;
|
|
900
|
+
_hookgovMaxPending = 25;
|
|
901
|
+
_hookgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
902
|
+
_hookgovStuckMs = 60 * 1000;
|
|
903
|
+
}
|
|
904
|
+
export function registerHookgovProfileV2({ id, owner, event, metadata } = {}) {
|
|
905
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
906
|
+
if (_hookgovPsV2.has(id))
|
|
907
|
+
throw new Error(`hookgov profile ${id} already exists`);
|
|
908
|
+
const now = Date.now();
|
|
909
|
+
const p = {
|
|
910
|
+
id,
|
|
911
|
+
owner,
|
|
912
|
+
event: event || "preTurn",
|
|
913
|
+
status: HOOKGOV_PROFILE_MATURITY_V2.PENDING,
|
|
914
|
+
createdAt: now,
|
|
915
|
+
updatedAt: now,
|
|
916
|
+
lastTouchedAt: now,
|
|
917
|
+
activatedAt: null,
|
|
918
|
+
archivedAt: null,
|
|
919
|
+
metadata: { ...(metadata || {}) },
|
|
920
|
+
};
|
|
921
|
+
_hookgovPsV2.set(id, p);
|
|
922
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
923
|
+
}
|
|
924
|
+
export function activateHookgovProfileV2(id) {
|
|
925
|
+
const p = _hookgovPsV2.get(id);
|
|
926
|
+
if (!p) throw new Error(`hookgov profile ${id} not found`);
|
|
927
|
+
const isInitial = p.status === HOOKGOV_PROFILE_MATURITY_V2.PENDING;
|
|
928
|
+
_hookgovCheckP(p.status, HOOKGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
929
|
+
if (isInitial && _hookgovCountActive(p.owner) >= _hookgovMaxActive)
|
|
930
|
+
throw new Error(`max active hookgov profiles for owner ${p.owner} reached`);
|
|
931
|
+
const now = Date.now();
|
|
932
|
+
p.status = HOOKGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
933
|
+
p.updatedAt = now;
|
|
934
|
+
p.lastTouchedAt = now;
|
|
935
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
936
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
937
|
+
}
|
|
938
|
+
export function disableHookgovProfileV2(id) {
|
|
939
|
+
const p = _hookgovPsV2.get(id);
|
|
940
|
+
if (!p) throw new Error(`hookgov profile ${id} not found`);
|
|
941
|
+
_hookgovCheckP(p.status, HOOKGOV_PROFILE_MATURITY_V2.DISABLED);
|
|
942
|
+
p.status = HOOKGOV_PROFILE_MATURITY_V2.DISABLED;
|
|
943
|
+
p.updatedAt = Date.now();
|
|
944
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
945
|
+
}
|
|
946
|
+
export function archiveHookgovProfileV2(id) {
|
|
947
|
+
const p = _hookgovPsV2.get(id);
|
|
948
|
+
if (!p) throw new Error(`hookgov profile ${id} not found`);
|
|
949
|
+
_hookgovCheckP(p.status, HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
950
|
+
const now = Date.now();
|
|
951
|
+
p.status = HOOKGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
952
|
+
p.updatedAt = now;
|
|
953
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
954
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
955
|
+
}
|
|
956
|
+
export function touchHookgovProfileV2(id) {
|
|
957
|
+
const p = _hookgovPsV2.get(id);
|
|
958
|
+
if (!p) throw new Error(`hookgov profile ${id} not found`);
|
|
959
|
+
if (_hookgovPTerminal.has(p.status))
|
|
960
|
+
throw new Error(`cannot touch terminal hookgov profile ${id}`);
|
|
961
|
+
const now = Date.now();
|
|
962
|
+
p.lastTouchedAt = now;
|
|
963
|
+
p.updatedAt = now;
|
|
964
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
965
|
+
}
|
|
966
|
+
export function getHookgovProfileV2(id) {
|
|
967
|
+
const p = _hookgovPsV2.get(id);
|
|
968
|
+
if (!p) return null;
|
|
969
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
970
|
+
}
|
|
971
|
+
export function listHookgovProfilesV2() {
|
|
972
|
+
return [..._hookgovPsV2.values()].map((p) => ({
|
|
973
|
+
...p,
|
|
974
|
+
metadata: { ...p.metadata },
|
|
975
|
+
}));
|
|
976
|
+
}
|
|
977
|
+
export function createHookgovTriggerV2({
|
|
978
|
+
id,
|
|
979
|
+
profileId,
|
|
980
|
+
payload,
|
|
981
|
+
metadata,
|
|
982
|
+
} = {}) {
|
|
983
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
984
|
+
if (_hookgovJsV2.has(id))
|
|
985
|
+
throw new Error(`hookgov trigger ${id} already exists`);
|
|
986
|
+
if (!_hookgovPsV2.has(profileId))
|
|
987
|
+
throw new Error(`hookgov profile ${profileId} not found`);
|
|
988
|
+
if (_hookgovCountPending(profileId) >= _hookgovMaxPending)
|
|
989
|
+
throw new Error(
|
|
990
|
+
`max pending hookgov triggers for profile ${profileId} reached`,
|
|
991
|
+
);
|
|
992
|
+
const now = Date.now();
|
|
993
|
+
const j = {
|
|
994
|
+
id,
|
|
995
|
+
profileId,
|
|
996
|
+
payload: payload || "",
|
|
997
|
+
status: HOOKGOV_TRIGGER_LIFECYCLE_V2.QUEUED,
|
|
998
|
+
createdAt: now,
|
|
999
|
+
updatedAt: now,
|
|
1000
|
+
startedAt: null,
|
|
1001
|
+
settledAt: null,
|
|
1002
|
+
metadata: { ...(metadata || {}) },
|
|
1003
|
+
};
|
|
1004
|
+
_hookgovJsV2.set(id, j);
|
|
1005
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1006
|
+
}
|
|
1007
|
+
export function firingHookgovTriggerV2(id) {
|
|
1008
|
+
const j = _hookgovJsV2.get(id);
|
|
1009
|
+
if (!j) throw new Error(`hookgov trigger ${id} not found`);
|
|
1010
|
+
_hookgovCheckJ(j.status, HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING);
|
|
1011
|
+
const now = Date.now();
|
|
1012
|
+
j.status = HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING;
|
|
1013
|
+
j.updatedAt = now;
|
|
1014
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1015
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1016
|
+
}
|
|
1017
|
+
export function completeTriggerHookgovV2(id) {
|
|
1018
|
+
const j = _hookgovJsV2.get(id);
|
|
1019
|
+
if (!j) throw new Error(`hookgov trigger ${id} not found`);
|
|
1020
|
+
_hookgovCheckJ(j.status, HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRED);
|
|
1021
|
+
const now = Date.now();
|
|
1022
|
+
j.status = HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRED;
|
|
1023
|
+
j.updatedAt = now;
|
|
1024
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1025
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1026
|
+
}
|
|
1027
|
+
export function failHookgovTriggerV2(id, reason) {
|
|
1028
|
+
const j = _hookgovJsV2.get(id);
|
|
1029
|
+
if (!j) throw new Error(`hookgov trigger ${id} not found`);
|
|
1030
|
+
_hookgovCheckJ(j.status, HOOKGOV_TRIGGER_LIFECYCLE_V2.FAILED);
|
|
1031
|
+
const now = Date.now();
|
|
1032
|
+
j.status = HOOKGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
1033
|
+
j.updatedAt = now;
|
|
1034
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1035
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1036
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1037
|
+
}
|
|
1038
|
+
export function cancelHookgovTriggerV2(id, reason) {
|
|
1039
|
+
const j = _hookgovJsV2.get(id);
|
|
1040
|
+
if (!j) throw new Error(`hookgov trigger ${id} not found`);
|
|
1041
|
+
_hookgovCheckJ(j.status, HOOKGOV_TRIGGER_LIFECYCLE_V2.CANCELLED);
|
|
1042
|
+
const now = Date.now();
|
|
1043
|
+
j.status = HOOKGOV_TRIGGER_LIFECYCLE_V2.CANCELLED;
|
|
1044
|
+
j.updatedAt = now;
|
|
1045
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1046
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1047
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1048
|
+
}
|
|
1049
|
+
export function getHookgovTriggerV2(id) {
|
|
1050
|
+
const j = _hookgovJsV2.get(id);
|
|
1051
|
+
if (!j) return null;
|
|
1052
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1053
|
+
}
|
|
1054
|
+
export function listHookgovTriggersV2() {
|
|
1055
|
+
return [..._hookgovJsV2.values()].map((j) => ({
|
|
1056
|
+
...j,
|
|
1057
|
+
metadata: { ...j.metadata },
|
|
1058
|
+
}));
|
|
1059
|
+
}
|
|
1060
|
+
export function autoDisableIdleHookgovProfilesV2({ now } = {}) {
|
|
1061
|
+
const t = now ?? Date.now();
|
|
1062
|
+
const flipped = [];
|
|
1063
|
+
for (const p of _hookgovPsV2.values())
|
|
1064
|
+
if (
|
|
1065
|
+
p.status === HOOKGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1066
|
+
t - p.lastTouchedAt >= _hookgovIdleMs
|
|
1067
|
+
) {
|
|
1068
|
+
p.status = HOOKGOV_PROFILE_MATURITY_V2.DISABLED;
|
|
1069
|
+
p.updatedAt = t;
|
|
1070
|
+
flipped.push(p.id);
|
|
1071
|
+
}
|
|
1072
|
+
return { flipped, count: flipped.length };
|
|
1073
|
+
}
|
|
1074
|
+
export function autoFailStuckHookgovTriggersV2({ now } = {}) {
|
|
1075
|
+
const t = now ?? Date.now();
|
|
1076
|
+
const flipped = [];
|
|
1077
|
+
for (const j of _hookgovJsV2.values())
|
|
1078
|
+
if (
|
|
1079
|
+
j.status === HOOKGOV_TRIGGER_LIFECYCLE_V2.FIRING &&
|
|
1080
|
+
j.startedAt != null &&
|
|
1081
|
+
t - j.startedAt >= _hookgovStuckMs
|
|
1082
|
+
) {
|
|
1083
|
+
j.status = HOOKGOV_TRIGGER_LIFECYCLE_V2.FAILED;
|
|
1084
|
+
j.updatedAt = t;
|
|
1085
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1086
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1087
|
+
flipped.push(j.id);
|
|
1088
|
+
}
|
|
1089
|
+
return { flipped, count: flipped.length };
|
|
1090
|
+
}
|
|
1091
|
+
export function getHookManagerGovStatsV2() {
|
|
1092
|
+
const profilesByStatus = {};
|
|
1093
|
+
for (const v of Object.values(HOOKGOV_PROFILE_MATURITY_V2))
|
|
1094
|
+
profilesByStatus[v] = 0;
|
|
1095
|
+
for (const p of _hookgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1096
|
+
const triggersByStatus = {};
|
|
1097
|
+
for (const v of Object.values(HOOKGOV_TRIGGER_LIFECYCLE_V2))
|
|
1098
|
+
triggersByStatus[v] = 0;
|
|
1099
|
+
for (const j of _hookgovJsV2.values()) triggersByStatus[j.status]++;
|
|
1100
|
+
return {
|
|
1101
|
+
totalHookgovProfilesV2: _hookgovPsV2.size,
|
|
1102
|
+
totalHookgovTriggersV2: _hookgovJsV2.size,
|
|
1103
|
+
maxActiveHookgovProfilesPerOwner: _hookgovMaxActive,
|
|
1104
|
+
maxPendingHookgovTriggersPerProfile: _hookgovMaxPending,
|
|
1105
|
+
hookgovProfileIdleMs: _hookgovIdleMs,
|
|
1106
|
+
hookgovTriggerStuckMs: _hookgovStuckMs,
|
|
1107
|
+
profilesByStatus,
|
|
1108
|
+
triggersByStatus,
|
|
1109
|
+
};
|
|
1110
|
+
}
|