chainlesschain 0.143.0 → 0.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- 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 +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -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-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- 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 +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- 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 +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- 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/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
|
@@ -1069,25 +1069,53 @@ export function _resetV2State() {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
-
|
|
1073
1072
|
// ===== V2 Surface: Hierarchical Memory governance overlay (CLI v0.137.0) =====
|
|
1074
1073
|
export const HMEM_TIER_MATURITY_V2 = Object.freeze({
|
|
1075
|
-
PENDING: "pending",
|
|
1074
|
+
PENDING: "pending",
|
|
1075
|
+
ACTIVE: "active",
|
|
1076
|
+
DORMANT: "dormant",
|
|
1077
|
+
RETIRED: "retired",
|
|
1076
1078
|
});
|
|
1077
1079
|
export const HMEM_PROMOTION_LIFECYCLE_V2 = Object.freeze({
|
|
1078
|
-
QUEUED: "queued",
|
|
1080
|
+
QUEUED: "queued",
|
|
1081
|
+
PROMOTING: "promoting",
|
|
1082
|
+
PROMOTED: "promoted",
|
|
1083
|
+
FAILED: "failed",
|
|
1084
|
+
CANCELLED: "cancelled",
|
|
1079
1085
|
});
|
|
1080
1086
|
|
|
1081
1087
|
const _hmemTierTrans = new Map([
|
|
1082
|
-
[
|
|
1083
|
-
|
|
1084
|
-
|
|
1088
|
+
[
|
|
1089
|
+
HMEM_TIER_MATURITY_V2.PENDING,
|
|
1090
|
+
new Set([HMEM_TIER_MATURITY_V2.ACTIVE, HMEM_TIER_MATURITY_V2.RETIRED]),
|
|
1091
|
+
],
|
|
1092
|
+
[
|
|
1093
|
+
HMEM_TIER_MATURITY_V2.ACTIVE,
|
|
1094
|
+
new Set([HMEM_TIER_MATURITY_V2.DORMANT, HMEM_TIER_MATURITY_V2.RETIRED]),
|
|
1095
|
+
],
|
|
1096
|
+
[
|
|
1097
|
+
HMEM_TIER_MATURITY_V2.DORMANT,
|
|
1098
|
+
new Set([HMEM_TIER_MATURITY_V2.ACTIVE, HMEM_TIER_MATURITY_V2.RETIRED]),
|
|
1099
|
+
],
|
|
1085
1100
|
[HMEM_TIER_MATURITY_V2.RETIRED, new Set()],
|
|
1086
1101
|
]);
|
|
1087
1102
|
const _hmemTierTerminal = new Set([HMEM_TIER_MATURITY_V2.RETIRED]);
|
|
1088
1103
|
const _hmemPromoTrans = new Map([
|
|
1089
|
-
[
|
|
1090
|
-
|
|
1104
|
+
[
|
|
1105
|
+
HMEM_PROMOTION_LIFECYCLE_V2.QUEUED,
|
|
1106
|
+
new Set([
|
|
1107
|
+
HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING,
|
|
1108
|
+
HMEM_PROMOTION_LIFECYCLE_V2.CANCELLED,
|
|
1109
|
+
]),
|
|
1110
|
+
],
|
|
1111
|
+
[
|
|
1112
|
+
HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING,
|
|
1113
|
+
new Set([
|
|
1114
|
+
HMEM_PROMOTION_LIFECYCLE_V2.PROMOTED,
|
|
1115
|
+
HMEM_PROMOTION_LIFECYCLE_V2.FAILED,
|
|
1116
|
+
HMEM_PROMOTION_LIFECYCLE_V2.CANCELLED,
|
|
1117
|
+
]),
|
|
1118
|
+
],
|
|
1091
1119
|
[HMEM_PROMOTION_LIFECYCLE_V2.PROMOTED, new Set()],
|
|
1092
1120
|
[HMEM_PROMOTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
1093
1121
|
[HMEM_PROMOTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -1100,21 +1128,45 @@ let _hmemMaxPendingPerTier = 30;
|
|
|
1100
1128
|
let _hmemTierIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1101
1129
|
let _hmemPromoStuckMs = 5 * 60 * 1000;
|
|
1102
1130
|
|
|
1103
|
-
function _hmemPos(n, lbl) {
|
|
1131
|
+
function _hmemPos(n, lbl) {
|
|
1132
|
+
const v = Math.floor(Number(n));
|
|
1133
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1134
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
1135
|
+
return v;
|
|
1136
|
+
}
|
|
1104
1137
|
|
|
1105
|
-
export function setMaxActiveHmemTiersPerOwnerV2(n) {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
export function
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
export function
|
|
1112
|
-
|
|
1138
|
+
export function setMaxActiveHmemTiersPerOwnerV2(n) {
|
|
1139
|
+
_hmemMaxActivePerOwner = _hmemPos(n, "maxActiveHmemTiersPerOwner");
|
|
1140
|
+
}
|
|
1141
|
+
export function getMaxActiveHmemTiersPerOwnerV2() {
|
|
1142
|
+
return _hmemMaxActivePerOwner;
|
|
1143
|
+
}
|
|
1144
|
+
export function setMaxPendingHmemPromotionsPerTierV2(n) {
|
|
1145
|
+
_hmemMaxPendingPerTier = _hmemPos(n, "maxPendingHmemPromotionsPerTier");
|
|
1146
|
+
}
|
|
1147
|
+
export function getMaxPendingHmemPromotionsPerTierV2() {
|
|
1148
|
+
return _hmemMaxPendingPerTier;
|
|
1149
|
+
}
|
|
1150
|
+
export function setHmemTierIdleMsV2(n) {
|
|
1151
|
+
_hmemTierIdleMs = _hmemPos(n, "hmemTierIdleMs");
|
|
1152
|
+
}
|
|
1153
|
+
export function getHmemTierIdleMsV2() {
|
|
1154
|
+
return _hmemTierIdleMs;
|
|
1155
|
+
}
|
|
1156
|
+
export function setHmemPromotionStuckMsV2(n) {
|
|
1157
|
+
_hmemPromoStuckMs = _hmemPos(n, "hmemPromotionStuckMs");
|
|
1158
|
+
}
|
|
1159
|
+
export function getHmemPromotionStuckMsV2() {
|
|
1160
|
+
return _hmemPromoStuckMs;
|
|
1161
|
+
}
|
|
1113
1162
|
|
|
1114
1163
|
export function _resetStateHierarchicalMemoryV2() {
|
|
1115
|
-
_hmemTiers.clear();
|
|
1116
|
-
|
|
1117
|
-
|
|
1164
|
+
_hmemTiers.clear();
|
|
1165
|
+
_hmemPromos.clear();
|
|
1166
|
+
_hmemMaxActivePerOwner = 12;
|
|
1167
|
+
_hmemMaxPendingPerTier = 30;
|
|
1168
|
+
_hmemTierIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1169
|
+
_hmemPromoStuckMs = 5 * 60 * 1000;
|
|
1118
1170
|
}
|
|
1119
1171
|
|
|
1120
1172
|
export function registerHmemTierV2({ id, owner, level, metadata } = {}) {
|
|
@@ -1122,54 +1174,238 @@ export function registerHmemTierV2({ id, owner, level, metadata } = {}) {
|
|
|
1122
1174
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
1123
1175
|
if (_hmemTiers.has(id)) throw new Error(`hmem tier ${id} already registered`);
|
|
1124
1176
|
const now = Date.now();
|
|
1125
|
-
const t = {
|
|
1177
|
+
const t = {
|
|
1178
|
+
id,
|
|
1179
|
+
owner,
|
|
1180
|
+
level: level || "short-term",
|
|
1181
|
+
status: HMEM_TIER_MATURITY_V2.PENDING,
|
|
1182
|
+
createdAt: now,
|
|
1183
|
+
updatedAt: now,
|
|
1184
|
+
activatedAt: null,
|
|
1185
|
+
retiredAt: null,
|
|
1186
|
+
lastTouchedAt: now,
|
|
1187
|
+
metadata: { ...(metadata || {}) },
|
|
1188
|
+
};
|
|
1126
1189
|
_hmemTiers.set(id, t);
|
|
1127
1190
|
return { ...t, metadata: { ...t.metadata } };
|
|
1128
1191
|
}
|
|
1129
|
-
function _hmemCheckT(from, to) {
|
|
1130
|
-
|
|
1192
|
+
function _hmemCheckT(from, to) {
|
|
1193
|
+
const a = _hmemTierTrans.get(from);
|
|
1194
|
+
if (!a || !a.has(to))
|
|
1195
|
+
throw new Error(`invalid hmem tier transition ${from} → ${to}`);
|
|
1196
|
+
}
|
|
1197
|
+
function _hmemCountActive(owner) {
|
|
1198
|
+
let n = 0;
|
|
1199
|
+
for (const t of _hmemTiers.values())
|
|
1200
|
+
if (t.owner === owner && t.status === HMEM_TIER_MATURITY_V2.ACTIVE) n++;
|
|
1201
|
+
return n;
|
|
1202
|
+
}
|
|
1131
1203
|
|
|
1132
1204
|
export function activateHmemTierV2(id) {
|
|
1133
|
-
const t = _hmemTiers.get(id);
|
|
1205
|
+
const t = _hmemTiers.get(id);
|
|
1206
|
+
if (!t) throw new Error(`hmem tier ${id} not found`);
|
|
1134
1207
|
_hmemCheckT(t.status, HMEM_TIER_MATURITY_V2.ACTIVE);
|
|
1135
1208
|
const recovery = t.status === HMEM_TIER_MATURITY_V2.DORMANT;
|
|
1136
|
-
if (!recovery) {
|
|
1137
|
-
|
|
1209
|
+
if (!recovery) {
|
|
1210
|
+
const c = _hmemCountActive(t.owner);
|
|
1211
|
+
if (c >= _hmemMaxActivePerOwner)
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
`max active hmem tiers per owner (${_hmemMaxActivePerOwner}) reached for ${t.owner}`,
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
const now = Date.now();
|
|
1217
|
+
t.status = HMEM_TIER_MATURITY_V2.ACTIVE;
|
|
1218
|
+
t.updatedAt = now;
|
|
1219
|
+
t.lastTouchedAt = now;
|
|
1220
|
+
if (!t.activatedAt) t.activatedAt = now;
|
|
1221
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
1222
|
+
}
|
|
1223
|
+
export function dormantHmemTierV2(id) {
|
|
1224
|
+
const t = _hmemTiers.get(id);
|
|
1225
|
+
if (!t) throw new Error(`hmem tier ${id} not found`);
|
|
1226
|
+
_hmemCheckT(t.status, HMEM_TIER_MATURITY_V2.DORMANT);
|
|
1227
|
+
t.status = HMEM_TIER_MATURITY_V2.DORMANT;
|
|
1228
|
+
t.updatedAt = Date.now();
|
|
1229
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
1230
|
+
}
|
|
1231
|
+
export function retireHmemTierV2(id) {
|
|
1232
|
+
const t = _hmemTiers.get(id);
|
|
1233
|
+
if (!t) throw new Error(`hmem tier ${id} not found`);
|
|
1234
|
+
_hmemCheckT(t.status, HMEM_TIER_MATURITY_V2.RETIRED);
|
|
1235
|
+
const now = Date.now();
|
|
1236
|
+
t.status = HMEM_TIER_MATURITY_V2.RETIRED;
|
|
1237
|
+
t.updatedAt = now;
|
|
1238
|
+
if (!t.retiredAt) t.retiredAt = now;
|
|
1239
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
1240
|
+
}
|
|
1241
|
+
export function touchHmemTierV2(id) {
|
|
1242
|
+
const t = _hmemTiers.get(id);
|
|
1243
|
+
if (!t) throw new Error(`hmem tier ${id} not found`);
|
|
1244
|
+
if (_hmemTierTerminal.has(t.status))
|
|
1245
|
+
throw new Error(`cannot touch terminal hmem tier ${id}`);
|
|
1246
|
+
const now = Date.now();
|
|
1247
|
+
t.lastTouchedAt = now;
|
|
1248
|
+
t.updatedAt = now;
|
|
1249
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
1250
|
+
}
|
|
1251
|
+
export function getHmemTierV2(id) {
|
|
1252
|
+
const t = _hmemTiers.get(id);
|
|
1253
|
+
if (!t) return null;
|
|
1138
1254
|
return { ...t, metadata: { ...t.metadata } };
|
|
1139
1255
|
}
|
|
1140
|
-
export function
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1256
|
+
export function listHmemTiersV2() {
|
|
1257
|
+
return [..._hmemTiers.values()].map((t) => ({
|
|
1258
|
+
...t,
|
|
1259
|
+
metadata: { ...t.metadata },
|
|
1260
|
+
}));
|
|
1261
|
+
}
|
|
1145
1262
|
|
|
1146
|
-
function _hmemCountPending(tid) {
|
|
1263
|
+
function _hmemCountPending(tid) {
|
|
1264
|
+
let n = 0;
|
|
1265
|
+
for (const p of _hmemPromos.values())
|
|
1266
|
+
if (
|
|
1267
|
+
p.tierId === tid &&
|
|
1268
|
+
(p.status === HMEM_PROMOTION_LIFECYCLE_V2.QUEUED ||
|
|
1269
|
+
p.status === HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING)
|
|
1270
|
+
)
|
|
1271
|
+
n++;
|
|
1272
|
+
return n;
|
|
1273
|
+
}
|
|
1147
1274
|
|
|
1148
1275
|
export function createHmemPromotionV2({ id, tierId, itemKey, metadata } = {}) {
|
|
1149
1276
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
1150
|
-
if (!tierId || typeof tierId !== "string")
|
|
1151
|
-
|
|
1277
|
+
if (!tierId || typeof tierId !== "string")
|
|
1278
|
+
throw new Error("tierId is required");
|
|
1279
|
+
if (_hmemPromos.has(id))
|
|
1280
|
+
throw new Error(`hmem promotion ${id} already exists`);
|
|
1152
1281
|
if (!_hmemTiers.has(tierId)) throw new Error(`hmem tier ${tierId} not found`);
|
|
1153
1282
|
const pending = _hmemCountPending(tierId);
|
|
1154
|
-
if (pending >= _hmemMaxPendingPerTier)
|
|
1283
|
+
if (pending >= _hmemMaxPendingPerTier)
|
|
1284
|
+
throw new Error(
|
|
1285
|
+
`max pending hmem promotions per tier (${_hmemMaxPendingPerTier}) reached for ${tierId}`,
|
|
1286
|
+
);
|
|
1155
1287
|
const now = Date.now();
|
|
1156
|
-
const p = {
|
|
1288
|
+
const p = {
|
|
1289
|
+
id,
|
|
1290
|
+
tierId,
|
|
1291
|
+
itemKey: itemKey || "",
|
|
1292
|
+
status: HMEM_PROMOTION_LIFECYCLE_V2.QUEUED,
|
|
1293
|
+
createdAt: now,
|
|
1294
|
+
updatedAt: now,
|
|
1295
|
+
startedAt: null,
|
|
1296
|
+
settledAt: null,
|
|
1297
|
+
metadata: { ...(metadata || {}) },
|
|
1298
|
+
};
|
|
1157
1299
|
_hmemPromos.set(id, p);
|
|
1158
1300
|
return { ...p, metadata: { ...p.metadata } };
|
|
1159
1301
|
}
|
|
1160
|
-
function _hmemCheckP(from, to) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
export function
|
|
1166
|
-
|
|
1302
|
+
function _hmemCheckP(from, to) {
|
|
1303
|
+
const a = _hmemPromoTrans.get(from);
|
|
1304
|
+
if (!a || !a.has(to))
|
|
1305
|
+
throw new Error(`invalid hmem promotion transition ${from} → ${to}`);
|
|
1306
|
+
}
|
|
1307
|
+
export function startHmemPromotionV2(id) {
|
|
1308
|
+
const p = _hmemPromos.get(id);
|
|
1309
|
+
if (!p) throw new Error(`hmem promotion ${id} not found`);
|
|
1310
|
+
_hmemCheckP(p.status, HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING);
|
|
1311
|
+
const now = Date.now();
|
|
1312
|
+
p.status = HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING;
|
|
1313
|
+
p.updatedAt = now;
|
|
1314
|
+
if (!p.startedAt) p.startedAt = now;
|
|
1315
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1316
|
+
}
|
|
1317
|
+
export function completeHmemPromotionV2(id) {
|
|
1318
|
+
const p = _hmemPromos.get(id);
|
|
1319
|
+
if (!p) throw new Error(`hmem promotion ${id} not found`);
|
|
1320
|
+
_hmemCheckP(p.status, HMEM_PROMOTION_LIFECYCLE_V2.PROMOTED);
|
|
1321
|
+
const now = Date.now();
|
|
1322
|
+
p.status = HMEM_PROMOTION_LIFECYCLE_V2.PROMOTED;
|
|
1323
|
+
p.updatedAt = now;
|
|
1324
|
+
if (!p.settledAt) p.settledAt = now;
|
|
1325
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1326
|
+
}
|
|
1327
|
+
export function failHmemPromotionV2(id, reason) {
|
|
1328
|
+
const p = _hmemPromos.get(id);
|
|
1329
|
+
if (!p) throw new Error(`hmem promotion ${id} not found`);
|
|
1330
|
+
_hmemCheckP(p.status, HMEM_PROMOTION_LIFECYCLE_V2.FAILED);
|
|
1331
|
+
const now = Date.now();
|
|
1332
|
+
p.status = HMEM_PROMOTION_LIFECYCLE_V2.FAILED;
|
|
1333
|
+
p.updatedAt = now;
|
|
1334
|
+
if (!p.settledAt) p.settledAt = now;
|
|
1335
|
+
if (reason) p.metadata.failReason = String(reason);
|
|
1336
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1337
|
+
}
|
|
1338
|
+
export function cancelHmemPromotionV2(id, reason) {
|
|
1339
|
+
const p = _hmemPromos.get(id);
|
|
1340
|
+
if (!p) throw new Error(`hmem promotion ${id} not found`);
|
|
1341
|
+
_hmemCheckP(p.status, HMEM_PROMOTION_LIFECYCLE_V2.CANCELLED);
|
|
1342
|
+
const now = Date.now();
|
|
1343
|
+
p.status = HMEM_PROMOTION_LIFECYCLE_V2.CANCELLED;
|
|
1344
|
+
p.updatedAt = now;
|
|
1345
|
+
if (!p.settledAt) p.settledAt = now;
|
|
1346
|
+
if (reason) p.metadata.cancelReason = String(reason);
|
|
1347
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1348
|
+
}
|
|
1349
|
+
export function getHmemPromotionV2(id) {
|
|
1350
|
+
const p = _hmemPromos.get(id);
|
|
1351
|
+
if (!p) return null;
|
|
1352
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1353
|
+
}
|
|
1354
|
+
export function listHmemPromotionsV2() {
|
|
1355
|
+
return [..._hmemPromos.values()].map((p) => ({
|
|
1356
|
+
...p,
|
|
1357
|
+
metadata: { ...p.metadata },
|
|
1358
|
+
}));
|
|
1359
|
+
}
|
|
1167
1360
|
|
|
1168
|
-
export function autoDormantIdleHmemTiersV2({ now } = {}) {
|
|
1169
|
-
|
|
1361
|
+
export function autoDormantIdleHmemTiersV2({ now } = {}) {
|
|
1362
|
+
const t = now ?? Date.now();
|
|
1363
|
+
const flipped = [];
|
|
1364
|
+
for (const tier of _hmemTiers.values())
|
|
1365
|
+
if (
|
|
1366
|
+
tier.status === HMEM_TIER_MATURITY_V2.ACTIVE &&
|
|
1367
|
+
t - tier.lastTouchedAt >= _hmemTierIdleMs
|
|
1368
|
+
) {
|
|
1369
|
+
tier.status = HMEM_TIER_MATURITY_V2.DORMANT;
|
|
1370
|
+
tier.updatedAt = t;
|
|
1371
|
+
flipped.push(tier.id);
|
|
1372
|
+
}
|
|
1373
|
+
return { flipped, count: flipped.length };
|
|
1374
|
+
}
|
|
1375
|
+
export function autoFailStuckHmemPromotionsV2({ now } = {}) {
|
|
1376
|
+
const t = now ?? Date.now();
|
|
1377
|
+
const flipped = [];
|
|
1378
|
+
for (const p of _hmemPromos.values())
|
|
1379
|
+
if (
|
|
1380
|
+
p.status === HMEM_PROMOTION_LIFECYCLE_V2.PROMOTING &&
|
|
1381
|
+
p.startedAt != null &&
|
|
1382
|
+
t - p.startedAt >= _hmemPromoStuckMs
|
|
1383
|
+
) {
|
|
1384
|
+
p.status = HMEM_PROMOTION_LIFECYCLE_V2.FAILED;
|
|
1385
|
+
p.updatedAt = t;
|
|
1386
|
+
if (!p.settledAt) p.settledAt = t;
|
|
1387
|
+
p.metadata.failReason = "auto-fail-stuck";
|
|
1388
|
+
flipped.push(p.id);
|
|
1389
|
+
}
|
|
1390
|
+
return { flipped, count: flipped.length };
|
|
1391
|
+
}
|
|
1170
1392
|
|
|
1171
1393
|
export function getHierarchicalMemoryGovStatsV2() {
|
|
1172
|
-
const tiersByStatus = {};
|
|
1173
|
-
|
|
1174
|
-
|
|
1394
|
+
const tiersByStatus = {};
|
|
1395
|
+
for (const s of Object.values(HMEM_TIER_MATURITY_V2)) tiersByStatus[s] = 0;
|
|
1396
|
+
for (const t of _hmemTiers.values()) tiersByStatus[t.status]++;
|
|
1397
|
+
const promotionsByStatus = {};
|
|
1398
|
+
for (const s of Object.values(HMEM_PROMOTION_LIFECYCLE_V2))
|
|
1399
|
+
promotionsByStatus[s] = 0;
|
|
1400
|
+
for (const p of _hmemPromos.values()) promotionsByStatus[p.status]++;
|
|
1401
|
+
return {
|
|
1402
|
+
totalTiersV2: _hmemTiers.size,
|
|
1403
|
+
totalPromotionsV2: _hmemPromos.size,
|
|
1404
|
+
maxActiveHmemTiersPerOwner: _hmemMaxActivePerOwner,
|
|
1405
|
+
maxPendingHmemPromotionsPerTier: _hmemMaxPendingPerTier,
|
|
1406
|
+
hmemTierIdleMs: _hmemTierIdleMs,
|
|
1407
|
+
hmemPromotionStuckMs: _hmemPromoStuckMs,
|
|
1408
|
+
tiersByStatus,
|
|
1409
|
+
promotionsByStatus,
|
|
1410
|
+
};
|
|
1175
1411
|
}
|