chainlesschain 0.81.0 → 0.143.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +62 -0
- package/src/commands/activitypub.js +61 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/agent.js +117 -0
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +61 -0
- package/src/commands/bm25.js +78 -0
- package/src/commands/browse.js +64 -0
- package/src/commands/ccron.js +78 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1075 -0
- package/src/commands/compt.js +78 -0
- package/src/commands/consol.js +231 -0
- package/src/commands/cowork.js +263 -0
- package/src/commands/crosschain.js +62 -0
- package/src/commands/dao.js +62 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +61 -0
- package/src/commands/economy.js +56 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evolution.js +56 -0
- package/src/commands/evomap.js +61 -0
- package/src/commands/export.js +256 -1
- package/src/commands/fflag.js +178 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/git.js +45 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hmemory.js +56 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +42 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/itbudget.js +45 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +44 -0
- package/src/commands/matrix.js +62 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/mcpscaf.js +41 -0
- package/src/commands/meminj.js +41 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/nostr.js +62 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/orchgov.js +45 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/pdfp.js +78 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/perf.js +39 -0
- package/src/commands/perm.js +45 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/pipeline.js +57 -1
- package/src/commands/planmode.js +45 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/promcomp.js +82 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +382 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/seshhook.js +41 -0
- package/src/commands/seshsearch.js +41 -0
- package/src/commands/seshtail.js +41 -0
- package/src/commands/seshu.js +41 -0
- package/src/commands/session.js +258 -0
- package/src/commands/sganal.js +78 -0
- package/src/commands/siem.js +40 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/slotfill.js +41 -0
- package/src/commands/social.js +290 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/svccont.js +45 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/tms.js +45 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/topiccls.js +45 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/uprof.js +45 -0
- package/src/commands/vcheck.js +78 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/webfetch.js +41 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +62 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +65 -1
- package/src/lib/a2a-protocol.js +105 -0
- package/src/lib/activitypub-bridge.js +105 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-economy.js +105 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +105 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-agent.js +105 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +105 -0
- package/src/lib/bm25-search.js +81 -0
- package/src/lib/browser-automation.js +105 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-framework-reporter.js +105 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/compression-telemetry.js +81 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/content-recommender.js +105 -0
- package/src/lib/cowork-cron.js +81 -0
- package/src/lib/cowork-task-runner.js +105 -0
- package/src/lib/cross-chain.js +105 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dao-governance.js +105 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +105 -0
- package/src/lib/evolution-system.js +105 -0
- package/src/lib/evomap-manager.js +105 -0
- package/src/lib/execution-backend.js +105 -0
- package/src/lib/feature-flags.js +85 -0
- package/src/lib/git-integration.js +105 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hierarchical-memory.js +105 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +105 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +105 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/matrix-bridge.js +105 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/mcp-scaffold.js +81 -0
- package/src/lib/memory-injection.js +81 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/nostr-bridge.js +105 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/orchestrator.js +105 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/pdf-parser.js +81 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +109 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/permission-engine.js +81 -0
- package/src/lib/pipeline-orchestrator.js +105 -0
- package/src/lib/plan-mode.js +81 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/service-container.js +81 -0
- package/src/lib/session-consolidator.js +105 -0
- package/src/lib/session-hooks.js +81 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/session-search.js +81 -0
- package/src/lib/session-tail.js +81 -0
- package/src/lib/session-usage.js +83 -0
- package/src/lib/siem-exporter.js +105 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/slot-filler.js +81 -0
- package/src/lib/social-graph-analytics.js +81 -0
- package/src/lib/social-graph.js +81 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/sub-agent-registry.js +110 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/task-model-selector.js +81 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/todo-manager.js +105 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/topic-classifier.js +105 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/user-profile.js +81 -0
- package/src/lib/version-checker.js +81 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/web-fetch.js +81 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +105 -0
|
@@ -1107,3 +1107,380 @@ export function getStats(db) {
|
|
|
1107
1107
|
totalDeveloperShare,
|
|
1108
1108
|
};
|
|
1109
1109
|
}
|
|
1110
|
+
|
|
1111
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1112
|
+
// Phase 64 V2 — Plugin maturity + formal install lifecycles,
|
|
1113
|
+
// per-developer active-plugin cap, per-user pending-install cap,
|
|
1114
|
+
// auto-deprecate + auto-archive
|
|
1115
|
+
// ═══════════════════════════════════════════════════════════════
|
|
1116
|
+
|
|
1117
|
+
export const PLUGIN_MATURITY_V2 = Object.freeze({
|
|
1118
|
+
ACTIVE: "active",
|
|
1119
|
+
DEPRECATED: "deprecated",
|
|
1120
|
+
ARCHIVED: "archived",
|
|
1121
|
+
REMOVED: "removed",
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
export const INSTALL_LIFECYCLE_V2 = Object.freeze({
|
|
1125
|
+
PENDING: "pending",
|
|
1126
|
+
RESOLVING: "resolving",
|
|
1127
|
+
INSTALLED: "installed",
|
|
1128
|
+
FAILED: "failed",
|
|
1129
|
+
UNINSTALLED: "uninstalled",
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
export const PLUGIN_DEFAULT_MAX_ACTIVE_PER_DEVELOPER = 20;
|
|
1133
|
+
export const PLUGIN_DEFAULT_MAX_PENDING_INSTALLS_PER_USER = 5;
|
|
1134
|
+
export const PLUGIN_DEFAULT_AUTO_DEPRECATE_AFTER_MS = 180 * 24 * 60 * 60 * 1000;
|
|
1135
|
+
export const PLUGIN_DEFAULT_AUTO_ARCHIVE_AFTER_MS = 90 * 24 * 60 * 60 * 1000;
|
|
1136
|
+
|
|
1137
|
+
let _maxActivePluginsPerDeveloper = PLUGIN_DEFAULT_MAX_ACTIVE_PER_DEVELOPER;
|
|
1138
|
+
let _maxPendingInstallsPerUser = PLUGIN_DEFAULT_MAX_PENDING_INSTALLS_PER_USER;
|
|
1139
|
+
let _autoDeprecateAfterMs = PLUGIN_DEFAULT_AUTO_DEPRECATE_AFTER_MS;
|
|
1140
|
+
let _autoArchiveAfterMs = PLUGIN_DEFAULT_AUTO_ARCHIVE_AFTER_MS;
|
|
1141
|
+
|
|
1142
|
+
const _maturityStatesV2 = new Map();
|
|
1143
|
+
const _installStatesV2 = new Map();
|
|
1144
|
+
|
|
1145
|
+
const MATURITY_TRANSITIONS_V2 = new Map([
|
|
1146
|
+
["active", new Set(["deprecated", "archived"])],
|
|
1147
|
+
["deprecated", new Set(["active", "archived", "removed"])],
|
|
1148
|
+
["archived", new Set(["active", "removed"])],
|
|
1149
|
+
]);
|
|
1150
|
+
const MATURITY_TERMINALS_V2 = new Set(["removed"]);
|
|
1151
|
+
|
|
1152
|
+
const INSTALL_TRANSITIONS_V2 = new Map([
|
|
1153
|
+
["pending", new Set(["resolving", "failed", "uninstalled"])],
|
|
1154
|
+
["resolving", new Set(["installed", "failed"])],
|
|
1155
|
+
["installed", new Set(["uninstalled"])],
|
|
1156
|
+
["failed", new Set(["pending", "uninstalled"])],
|
|
1157
|
+
]);
|
|
1158
|
+
const INSTALL_TERMINALS_V2 = new Set(["uninstalled"]);
|
|
1159
|
+
|
|
1160
|
+
function _positiveIntV2(n, label) {
|
|
1161
|
+
const v = Number(n);
|
|
1162
|
+
if (!Number.isFinite(v) || v <= 0) {
|
|
1163
|
+
throw new Error(`${label} must be a positive integer`);
|
|
1164
|
+
}
|
|
1165
|
+
return Math.floor(v);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
export function setMaxActivePluginsPerDeveloper(n) {
|
|
1169
|
+
_maxActivePluginsPerDeveloper = _positiveIntV2(
|
|
1170
|
+
n,
|
|
1171
|
+
"maxActivePluginsPerDeveloper",
|
|
1172
|
+
);
|
|
1173
|
+
return _maxActivePluginsPerDeveloper;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
export function setMaxPendingInstallsPerUser(n) {
|
|
1177
|
+
_maxPendingInstallsPerUser = _positiveIntV2(n, "maxPendingInstallsPerUser");
|
|
1178
|
+
return _maxPendingInstallsPerUser;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
export function setAutoDeprecateAfterMs(ms) {
|
|
1182
|
+
_autoDeprecateAfterMs = _positiveIntV2(ms, "autoDeprecateAfterMs");
|
|
1183
|
+
return _autoDeprecateAfterMs;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
export function setAutoArchiveAfterMs(ms) {
|
|
1187
|
+
_autoArchiveAfterMs = _positiveIntV2(ms, "autoArchiveAfterMs");
|
|
1188
|
+
return _autoArchiveAfterMs;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export function getMaxActivePluginsPerDeveloper() {
|
|
1192
|
+
return _maxActivePluginsPerDeveloper;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
export function getMaxPendingInstallsPerUser() {
|
|
1196
|
+
return _maxPendingInstallsPerUser;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
export function getAutoDeprecateAfterMs() {
|
|
1200
|
+
return _autoDeprecateAfterMs;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
export function getAutoArchiveAfterMs() {
|
|
1204
|
+
return _autoArchiveAfterMs;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export function getActivePluginCount(developerId) {
|
|
1208
|
+
let count = 0;
|
|
1209
|
+
for (const entry of _maturityStatesV2.values()) {
|
|
1210
|
+
if (entry.status !== PLUGIN_MATURITY_V2.ACTIVE) continue;
|
|
1211
|
+
if (!developerId || entry.developerId === developerId) count += 1;
|
|
1212
|
+
}
|
|
1213
|
+
return count;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export function getPendingInstallCount(userId) {
|
|
1217
|
+
let count = 0;
|
|
1218
|
+
for (const entry of _installStatesV2.values()) {
|
|
1219
|
+
if (
|
|
1220
|
+
entry.status !== INSTALL_LIFECYCLE_V2.PENDING &&
|
|
1221
|
+
entry.status !== INSTALL_LIFECYCLE_V2.RESOLVING
|
|
1222
|
+
) {
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
if (!userId || entry.userId === userId) count += 1;
|
|
1226
|
+
}
|
|
1227
|
+
return count;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/* ── Maturity V2 ────────────────────────────────────── */
|
|
1231
|
+
|
|
1232
|
+
export function registerPluginV2(db, { pluginId, developerId, metadata } = {}) {
|
|
1233
|
+
if (!pluginId) throw new Error("pluginId is required");
|
|
1234
|
+
if (!developerId) throw new Error("developerId is required");
|
|
1235
|
+
if (_maturityStatesV2.has(pluginId)) {
|
|
1236
|
+
throw new Error(`Plugin already registered: ${pluginId}`);
|
|
1237
|
+
}
|
|
1238
|
+
const activeCount = getActivePluginCount(developerId);
|
|
1239
|
+
if (activeCount >= _maxActivePluginsPerDeveloper) {
|
|
1240
|
+
throw new Error(
|
|
1241
|
+
`Max active plugins reached (${activeCount}/${_maxActivePluginsPerDeveloper}) for developer ${developerId}`,
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
const now = Date.now();
|
|
1245
|
+
const entry = {
|
|
1246
|
+
pluginId,
|
|
1247
|
+
developerId,
|
|
1248
|
+
status: PLUGIN_MATURITY_V2.ACTIVE,
|
|
1249
|
+
reason: null,
|
|
1250
|
+
metadata: metadata ? { ...metadata } : {},
|
|
1251
|
+
createdAt: now,
|
|
1252
|
+
updatedAt: now,
|
|
1253
|
+
lastActivityAt: now,
|
|
1254
|
+
};
|
|
1255
|
+
_maturityStatesV2.set(pluginId, entry);
|
|
1256
|
+
return { ...entry };
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
export function getMaturityV2(pluginId) {
|
|
1260
|
+
const entry = _maturityStatesV2.get(pluginId);
|
|
1261
|
+
return entry ? { ...entry } : null;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export function setPluginMaturityV2(db, pluginId, newStatus, patch = {}) {
|
|
1265
|
+
const entry = _maturityStatesV2.get(pluginId);
|
|
1266
|
+
if (!entry) throw new Error(`Plugin not registered: ${pluginId}`);
|
|
1267
|
+
if (!Object.values(PLUGIN_MATURITY_V2).includes(newStatus)) {
|
|
1268
|
+
throw new Error(`Invalid maturity status: ${newStatus}`);
|
|
1269
|
+
}
|
|
1270
|
+
if (MATURITY_TERMINALS_V2.has(entry.status)) {
|
|
1271
|
+
throw new Error(`Plugin is terminal: ${entry.status}`);
|
|
1272
|
+
}
|
|
1273
|
+
const allowed = MATURITY_TRANSITIONS_V2.get(entry.status) || new Set();
|
|
1274
|
+
if (!allowed.has(newStatus)) {
|
|
1275
|
+
throw new Error(`Invalid transition: ${entry.status} → ${newStatus}`);
|
|
1276
|
+
}
|
|
1277
|
+
entry.status = newStatus;
|
|
1278
|
+
entry.updatedAt = Date.now();
|
|
1279
|
+
if (patch.reason !== undefined) entry.reason = patch.reason;
|
|
1280
|
+
if (patch.metadata) entry.metadata = { ...entry.metadata, ...patch.metadata };
|
|
1281
|
+
return { ...entry };
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
export function deprecatePlugin(db, pluginId, reason) {
|
|
1285
|
+
return setPluginMaturityV2(db, pluginId, PLUGIN_MATURITY_V2.DEPRECATED, {
|
|
1286
|
+
reason,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
export function archivePluginV2(db, pluginId, reason) {
|
|
1291
|
+
return setPluginMaturityV2(db, pluginId, PLUGIN_MATURITY_V2.ARCHIVED, {
|
|
1292
|
+
reason,
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
export function removePluginV2(db, pluginId, reason) {
|
|
1297
|
+
return setPluginMaturityV2(db, pluginId, PLUGIN_MATURITY_V2.REMOVED, {
|
|
1298
|
+
reason,
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
export function touchPluginActivity(pluginId) {
|
|
1303
|
+
const entry = _maturityStatesV2.get(pluginId);
|
|
1304
|
+
if (!entry) throw new Error(`Plugin not registered: ${pluginId}`);
|
|
1305
|
+
const now = Date.now();
|
|
1306
|
+
entry.lastActivityAt = now;
|
|
1307
|
+
entry.updatedAt = now;
|
|
1308
|
+
return { ...entry };
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/* ── Install V2 ─────────────────────────────────────── */
|
|
1312
|
+
|
|
1313
|
+
export function submitInstallV2(
|
|
1314
|
+
db,
|
|
1315
|
+
{ installId, userId, pluginId, metadata } = {},
|
|
1316
|
+
) {
|
|
1317
|
+
if (!installId) throw new Error("installId is required");
|
|
1318
|
+
if (!userId) throw new Error("userId is required");
|
|
1319
|
+
if (!pluginId) throw new Error("pluginId is required");
|
|
1320
|
+
if (_installStatesV2.has(installId)) {
|
|
1321
|
+
throw new Error(`Install already registered: ${installId}`);
|
|
1322
|
+
}
|
|
1323
|
+
const maturityEntry = _maturityStatesV2.get(pluginId);
|
|
1324
|
+
if (
|
|
1325
|
+
maturityEntry &&
|
|
1326
|
+
maturityEntry.status !== PLUGIN_MATURITY_V2.ACTIVE &&
|
|
1327
|
+
maturityEntry.status !== PLUGIN_MATURITY_V2.DEPRECATED
|
|
1328
|
+
) {
|
|
1329
|
+
throw new Error(`Plugin not installable: ${maturityEntry.status}`);
|
|
1330
|
+
}
|
|
1331
|
+
const pendingCount = getPendingInstallCount(userId);
|
|
1332
|
+
if (pendingCount >= _maxPendingInstallsPerUser) {
|
|
1333
|
+
throw new Error(
|
|
1334
|
+
`Max pending installs reached (${pendingCount}/${_maxPendingInstallsPerUser}) for user ${userId}`,
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
const now = Date.now();
|
|
1338
|
+
const entry = {
|
|
1339
|
+
installId,
|
|
1340
|
+
userId,
|
|
1341
|
+
pluginId,
|
|
1342
|
+
status: INSTALL_LIFECYCLE_V2.PENDING,
|
|
1343
|
+
reason: null,
|
|
1344
|
+
metadata: metadata ? { ...metadata } : {},
|
|
1345
|
+
createdAt: now,
|
|
1346
|
+
updatedAt: now,
|
|
1347
|
+
};
|
|
1348
|
+
_installStatesV2.set(installId, entry);
|
|
1349
|
+
return { ...entry };
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
export function getInstallStatusV2(installId) {
|
|
1353
|
+
const entry = _installStatesV2.get(installId);
|
|
1354
|
+
return entry ? { ...entry } : null;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
export function setInstallStatusV2(db, installId, newStatus, patch = {}) {
|
|
1358
|
+
const entry = _installStatesV2.get(installId);
|
|
1359
|
+
if (!entry) throw new Error(`Install not found: ${installId}`);
|
|
1360
|
+
if (!Object.values(INSTALL_LIFECYCLE_V2).includes(newStatus)) {
|
|
1361
|
+
throw new Error(`Invalid install status: ${newStatus}`);
|
|
1362
|
+
}
|
|
1363
|
+
if (INSTALL_TERMINALS_V2.has(entry.status)) {
|
|
1364
|
+
throw new Error(`Install is terminal: ${entry.status}`);
|
|
1365
|
+
}
|
|
1366
|
+
const allowed = INSTALL_TRANSITIONS_V2.get(entry.status) || new Set();
|
|
1367
|
+
if (!allowed.has(newStatus)) {
|
|
1368
|
+
throw new Error(`Invalid transition: ${entry.status} → ${newStatus}`);
|
|
1369
|
+
}
|
|
1370
|
+
entry.status = newStatus;
|
|
1371
|
+
entry.updatedAt = Date.now();
|
|
1372
|
+
if (patch.reason !== undefined) entry.reason = patch.reason;
|
|
1373
|
+
if (patch.metadata) entry.metadata = { ...entry.metadata, ...patch.metadata };
|
|
1374
|
+
return { ...entry };
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
export function resolveInstall(db, installId, reason) {
|
|
1378
|
+
return setInstallStatusV2(db, installId, INSTALL_LIFECYCLE_V2.RESOLVING, {
|
|
1379
|
+
reason,
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
export function completeInstall(db, installId, reason) {
|
|
1384
|
+
return setInstallStatusV2(db, installId, INSTALL_LIFECYCLE_V2.INSTALLED, {
|
|
1385
|
+
reason,
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
export function failInstall(db, installId, reason) {
|
|
1390
|
+
return setInstallStatusV2(db, installId, INSTALL_LIFECYCLE_V2.FAILED, {
|
|
1391
|
+
reason,
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
export function uninstallInstallV2(db, installId, reason) {
|
|
1396
|
+
return setInstallStatusV2(db, installId, INSTALL_LIFECYCLE_V2.UNINSTALLED, {
|
|
1397
|
+
reason,
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
export function retryFailedInstall(db, installId, reason) {
|
|
1402
|
+
return setInstallStatusV2(db, installId, INSTALL_LIFECYCLE_V2.PENDING, {
|
|
1403
|
+
reason,
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/* ── Auto-flip bulk operations ──────────────────────── */
|
|
1408
|
+
|
|
1409
|
+
export function autoDeprecateStalePlugins(db, nowMs = Date.now()) {
|
|
1410
|
+
const deprecated = [];
|
|
1411
|
+
for (const entry of _maturityStatesV2.values()) {
|
|
1412
|
+
if (entry.status !== PLUGIN_MATURITY_V2.ACTIVE) continue;
|
|
1413
|
+
if (nowMs - entry.lastActivityAt > _autoDeprecateAfterMs) {
|
|
1414
|
+
entry.status = PLUGIN_MATURITY_V2.DEPRECATED;
|
|
1415
|
+
entry.reason = "stale";
|
|
1416
|
+
entry.updatedAt = nowMs;
|
|
1417
|
+
deprecated.push({ ...entry });
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
return deprecated;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
export function autoArchiveLongDeprecated(db, nowMs = Date.now()) {
|
|
1424
|
+
const archived = [];
|
|
1425
|
+
for (const entry of _maturityStatesV2.values()) {
|
|
1426
|
+
if (entry.status !== PLUGIN_MATURITY_V2.DEPRECATED) continue;
|
|
1427
|
+
if (nowMs - entry.updatedAt > _autoArchiveAfterMs) {
|
|
1428
|
+
entry.status = PLUGIN_MATURITY_V2.ARCHIVED;
|
|
1429
|
+
entry.reason = "long-deprecated";
|
|
1430
|
+
entry.updatedAt = nowMs;
|
|
1431
|
+
archived.push({ ...entry });
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
return archived;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/* ── Stats V2 ───────────────────────────────────────── */
|
|
1438
|
+
|
|
1439
|
+
export function getEcosystemStatsV2() {
|
|
1440
|
+
const maturityByStatus = {
|
|
1441
|
+
active: 0,
|
|
1442
|
+
deprecated: 0,
|
|
1443
|
+
archived: 0,
|
|
1444
|
+
removed: 0,
|
|
1445
|
+
};
|
|
1446
|
+
const installsByStatus = {
|
|
1447
|
+
pending: 0,
|
|
1448
|
+
resolving: 0,
|
|
1449
|
+
installed: 0,
|
|
1450
|
+
failed: 0,
|
|
1451
|
+
uninstalled: 0,
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
for (const entry of _maturityStatesV2.values()) {
|
|
1455
|
+
if (maturityByStatus[entry.status] !== undefined) {
|
|
1456
|
+
maturityByStatus[entry.status] += 1;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
for (const entry of _installStatesV2.values()) {
|
|
1460
|
+
if (installsByStatus[entry.status] !== undefined) {
|
|
1461
|
+
installsByStatus[entry.status] += 1;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
return {
|
|
1466
|
+
totalPluginsV2: _maturityStatesV2.size,
|
|
1467
|
+
totalInstallsV2: _installStatesV2.size,
|
|
1468
|
+
maxActivePluginsPerDeveloper: _maxActivePluginsPerDeveloper,
|
|
1469
|
+
maxPendingInstallsPerUser: _maxPendingInstallsPerUser,
|
|
1470
|
+
autoDeprecateAfterMs: _autoDeprecateAfterMs,
|
|
1471
|
+
autoArchiveAfterMs: _autoArchiveAfterMs,
|
|
1472
|
+
maturityByStatus,
|
|
1473
|
+
installsByStatus,
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/* ── Reset V2 (tests) ───────────────────────────────── */
|
|
1478
|
+
|
|
1479
|
+
export function _resetStateV2() {
|
|
1480
|
+
_maturityStatesV2.clear();
|
|
1481
|
+
_installStatesV2.clear();
|
|
1482
|
+
_maxActivePluginsPerDeveloper = PLUGIN_DEFAULT_MAX_ACTIVE_PER_DEVELOPER;
|
|
1483
|
+
_maxPendingInstallsPerUser = PLUGIN_DEFAULT_MAX_PENDING_INSTALLS_PER_USER;
|
|
1484
|
+
_autoDeprecateAfterMs = PLUGIN_DEFAULT_AUTO_DEPRECATE_AFTER_MS;
|
|
1485
|
+
_autoArchiveAfterMs = PLUGIN_DEFAULT_AUTO_ARCHIVE_AFTER_MS;
|
|
1486
|
+
}
|