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
package/src/lib/pqc-manager.js
CHANGED
|
@@ -326,3 +326,371 @@ export function _resetState() {
|
|
|
326
326
|
_keys.clear();
|
|
327
327
|
_migrations.clear();
|
|
328
328
|
}
|
|
329
|
+
|
|
330
|
+
/* ─────────────────────────────────────────────────────────────────────────
|
|
331
|
+
* V2 in-memory governance layer (independent of SQLite pqc_keys)
|
|
332
|
+
* ───────────────────────────────────────────────────────────────────────── */
|
|
333
|
+
|
|
334
|
+
export const KEY_MATURITY_V2 = Object.freeze({
|
|
335
|
+
PENDING: "pending",
|
|
336
|
+
ACTIVE: "active",
|
|
337
|
+
DEPRECATED: "deprecated",
|
|
338
|
+
ARCHIVED: "archived",
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
export const MIGRATION_LIFECYCLE_V2 = Object.freeze({
|
|
342
|
+
QUEUED: "queued",
|
|
343
|
+
RUNNING: "running",
|
|
344
|
+
COMPLETED: "completed",
|
|
345
|
+
FAILED: "failed",
|
|
346
|
+
CANCELLED: "cancelled",
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const KEY_TERMINAL_V2 = new Set([KEY_MATURITY_V2.ARCHIVED]);
|
|
350
|
+
const MIGRATION_TERMINAL_V2 = new Set([
|
|
351
|
+
MIGRATION_LIFECYCLE_V2.COMPLETED,
|
|
352
|
+
MIGRATION_LIFECYCLE_V2.FAILED,
|
|
353
|
+
MIGRATION_LIFECYCLE_V2.CANCELLED,
|
|
354
|
+
]);
|
|
355
|
+
|
|
356
|
+
const KEY_TRANSITIONS_V2 = new Map([
|
|
357
|
+
[
|
|
358
|
+
KEY_MATURITY_V2.PENDING,
|
|
359
|
+
new Set([KEY_MATURITY_V2.ACTIVE, KEY_MATURITY_V2.ARCHIVED]),
|
|
360
|
+
],
|
|
361
|
+
[
|
|
362
|
+
KEY_MATURITY_V2.ACTIVE,
|
|
363
|
+
new Set([KEY_MATURITY_V2.DEPRECATED, KEY_MATURITY_V2.ARCHIVED]),
|
|
364
|
+
],
|
|
365
|
+
[
|
|
366
|
+
KEY_MATURITY_V2.DEPRECATED,
|
|
367
|
+
new Set([KEY_MATURITY_V2.ACTIVE, KEY_MATURITY_V2.ARCHIVED]),
|
|
368
|
+
],
|
|
369
|
+
]);
|
|
370
|
+
|
|
371
|
+
const MIGRATION_TRANSITIONS_V2 = new Map([
|
|
372
|
+
[
|
|
373
|
+
MIGRATION_LIFECYCLE_V2.QUEUED,
|
|
374
|
+
new Set([MIGRATION_LIFECYCLE_V2.RUNNING, MIGRATION_LIFECYCLE_V2.CANCELLED]),
|
|
375
|
+
],
|
|
376
|
+
[
|
|
377
|
+
MIGRATION_LIFECYCLE_V2.RUNNING,
|
|
378
|
+
new Set([
|
|
379
|
+
MIGRATION_LIFECYCLE_V2.COMPLETED,
|
|
380
|
+
MIGRATION_LIFECYCLE_V2.FAILED,
|
|
381
|
+
MIGRATION_LIFECYCLE_V2.CANCELLED,
|
|
382
|
+
]),
|
|
383
|
+
],
|
|
384
|
+
]);
|
|
385
|
+
|
|
386
|
+
export const PQC_DEFAULT_MAX_ACTIVE_KEYS_PER_OWNER = 16;
|
|
387
|
+
export const PQC_DEFAULT_MAX_PENDING_MIGRATIONS_PER_KEY = 8;
|
|
388
|
+
export const PQC_DEFAULT_KEY_IDLE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
389
|
+
export const PQC_DEFAULT_MIGRATION_STUCK_MS = 10 * 60 * 1000;
|
|
390
|
+
|
|
391
|
+
let _maxActiveKeysPerOwnerV2 = PQC_DEFAULT_MAX_ACTIVE_KEYS_PER_OWNER;
|
|
392
|
+
let _maxPendingMigrationsPerKeyV2 = PQC_DEFAULT_MAX_PENDING_MIGRATIONS_PER_KEY;
|
|
393
|
+
let _keyIdleMsV2 = PQC_DEFAULT_KEY_IDLE_MS;
|
|
394
|
+
let _migrationStuckMsV2 = PQC_DEFAULT_MIGRATION_STUCK_MS;
|
|
395
|
+
|
|
396
|
+
const _keysV2 = new Map();
|
|
397
|
+
const _migrationsV2 = new Map();
|
|
398
|
+
|
|
399
|
+
function _posIntPqcV2(n, label) {
|
|
400
|
+
if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) {
|
|
401
|
+
throw new Error(`${label} must be a positive number`);
|
|
402
|
+
}
|
|
403
|
+
return Math.floor(n);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function getMaxActiveKeysPerOwnerV2() {
|
|
407
|
+
return _maxActiveKeysPerOwnerV2;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function setMaxActiveKeysPerOwnerV2(n) {
|
|
411
|
+
_maxActiveKeysPerOwnerV2 = _posIntPqcV2(n, "maxActiveKeysPerOwner");
|
|
412
|
+
return _maxActiveKeysPerOwnerV2;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function getMaxPendingMigrationsPerKeyV2() {
|
|
416
|
+
return _maxPendingMigrationsPerKeyV2;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export function setMaxPendingMigrationsPerKeyV2(n) {
|
|
420
|
+
_maxPendingMigrationsPerKeyV2 = _posIntPqcV2(n, "maxPendingMigrationsPerKey");
|
|
421
|
+
return _maxPendingMigrationsPerKeyV2;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export function getKeyIdleMsV2() {
|
|
425
|
+
return _keyIdleMsV2;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export function setKeyIdleMsV2(ms) {
|
|
429
|
+
_keyIdleMsV2 = _posIntPqcV2(ms, "keyIdleMs");
|
|
430
|
+
return _keyIdleMsV2;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export function getMigrationStuckMsV2() {
|
|
434
|
+
return _migrationStuckMsV2;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export function setMigrationStuckMsV2(ms) {
|
|
438
|
+
_migrationStuckMsV2 = _posIntPqcV2(ms, "migrationStuckMs");
|
|
439
|
+
return _migrationStuckMsV2;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function getActiveKeyCountV2(ownerId) {
|
|
443
|
+
let n = 0;
|
|
444
|
+
for (const k of _keysV2.values()) {
|
|
445
|
+
if (k.status !== KEY_MATURITY_V2.ACTIVE) continue;
|
|
446
|
+
if (ownerId && k.ownerId !== ownerId) continue;
|
|
447
|
+
n++;
|
|
448
|
+
}
|
|
449
|
+
return n;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function getPendingMigrationCountV2(keyId) {
|
|
453
|
+
let n = 0;
|
|
454
|
+
for (const m of _migrationsV2.values()) {
|
|
455
|
+
if (
|
|
456
|
+
m.status !== MIGRATION_LIFECYCLE_V2.QUEUED &&
|
|
457
|
+
m.status !== MIGRATION_LIFECYCLE_V2.RUNNING
|
|
458
|
+
)
|
|
459
|
+
continue;
|
|
460
|
+
if (keyId && m.keyId !== keyId) continue;
|
|
461
|
+
n++;
|
|
462
|
+
}
|
|
463
|
+
return n;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function _cloneKeyV2(k) {
|
|
467
|
+
return { ...k, metadata: { ...k.metadata } };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function _cloneMigrationV2(m) {
|
|
471
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export function registerKeyV2(
|
|
475
|
+
id,
|
|
476
|
+
{ ownerId, algorithm, purpose, metadata } = {},
|
|
477
|
+
) {
|
|
478
|
+
if (!id || typeof id !== "string") throw new Error("key id required");
|
|
479
|
+
if (!ownerId || typeof ownerId !== "string")
|
|
480
|
+
throw new Error("ownerId required");
|
|
481
|
+
if (!algorithm || typeof algorithm !== "string")
|
|
482
|
+
throw new Error("algorithm required");
|
|
483
|
+
if (_keysV2.has(id)) throw new Error(`key ${id} already exists`);
|
|
484
|
+
const now = Date.now();
|
|
485
|
+
const key = {
|
|
486
|
+
id,
|
|
487
|
+
ownerId,
|
|
488
|
+
algorithm,
|
|
489
|
+
purpose: purpose || "general",
|
|
490
|
+
status: KEY_MATURITY_V2.PENDING,
|
|
491
|
+
createdAt: now,
|
|
492
|
+
activatedAt: null,
|
|
493
|
+
archivedAt: null,
|
|
494
|
+
lastSeenAt: now,
|
|
495
|
+
metadata: metadata ? { ...metadata } : {},
|
|
496
|
+
};
|
|
497
|
+
_keysV2.set(id, key);
|
|
498
|
+
return _cloneKeyV2(key);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function getKeyV2(id) {
|
|
502
|
+
const k = _keysV2.get(id);
|
|
503
|
+
return k ? _cloneKeyV2(k) : null;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export function listKeysV2({ ownerId, status, algorithm } = {}) {
|
|
507
|
+
const out = [];
|
|
508
|
+
for (const k of _keysV2.values()) {
|
|
509
|
+
if (ownerId && k.ownerId !== ownerId) continue;
|
|
510
|
+
if (status && k.status !== status) continue;
|
|
511
|
+
if (algorithm && k.algorithm !== algorithm) continue;
|
|
512
|
+
out.push(_cloneKeyV2(k));
|
|
513
|
+
}
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export function setKeyStatusV2(id, next) {
|
|
518
|
+
const k = _keysV2.get(id);
|
|
519
|
+
if (!k) throw new Error(`unknown key ${id}`);
|
|
520
|
+
if (KEY_TERMINAL_V2.has(k.status)) {
|
|
521
|
+
throw new Error(`key ${id} is terminal (${k.status})`);
|
|
522
|
+
}
|
|
523
|
+
const allowed = KEY_TRANSITIONS_V2.get(k.status);
|
|
524
|
+
if (!allowed || !allowed.has(next)) {
|
|
525
|
+
throw new Error(`invalid key transition ${k.status} -> ${next}`);
|
|
526
|
+
}
|
|
527
|
+
if (next === KEY_MATURITY_V2.ACTIVE && k.status === KEY_MATURITY_V2.PENDING) {
|
|
528
|
+
const owned = getActiveKeyCountV2(k.ownerId);
|
|
529
|
+
if (owned >= _maxActiveKeysPerOwnerV2) {
|
|
530
|
+
throw new Error(
|
|
531
|
+
`owner ${k.ownerId} active key cap reached (${_maxActiveKeysPerOwnerV2})`,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const now = Date.now();
|
|
536
|
+
k.status = next;
|
|
537
|
+
if (next === KEY_MATURITY_V2.ACTIVE && !k.activatedAt) k.activatedAt = now;
|
|
538
|
+
if (next === KEY_MATURITY_V2.ARCHIVED && !k.archivedAt) k.archivedAt = now;
|
|
539
|
+
k.lastSeenAt = now;
|
|
540
|
+
return _cloneKeyV2(k);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export function activateKeyV2(id) {
|
|
544
|
+
return setKeyStatusV2(id, KEY_MATURITY_V2.ACTIVE);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export function deprecateKeyV2(id) {
|
|
548
|
+
return setKeyStatusV2(id, KEY_MATURITY_V2.DEPRECATED);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function archiveKeyV2(id) {
|
|
552
|
+
return setKeyStatusV2(id, KEY_MATURITY_V2.ARCHIVED);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export function touchKeyV2(id) {
|
|
556
|
+
const k = _keysV2.get(id);
|
|
557
|
+
if (!k) throw new Error(`unknown key ${id}`);
|
|
558
|
+
k.lastSeenAt = Date.now();
|
|
559
|
+
return _cloneKeyV2(k);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export function createMigrationV2(
|
|
563
|
+
id,
|
|
564
|
+
{ keyId, targetAlgorithm, metadata } = {},
|
|
565
|
+
) {
|
|
566
|
+
if (!id || typeof id !== "string") throw new Error("migration id required");
|
|
567
|
+
if (!keyId || typeof keyId !== "string") throw new Error("keyId required");
|
|
568
|
+
if (!targetAlgorithm || typeof targetAlgorithm !== "string") {
|
|
569
|
+
throw new Error("targetAlgorithm required");
|
|
570
|
+
}
|
|
571
|
+
if (_migrationsV2.has(id)) throw new Error(`migration ${id} already exists`);
|
|
572
|
+
const k = _keysV2.get(keyId);
|
|
573
|
+
if (!k) throw new Error(`unknown key ${keyId}`);
|
|
574
|
+
const pending = getPendingMigrationCountV2(keyId);
|
|
575
|
+
if (pending >= _maxPendingMigrationsPerKeyV2) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
`key ${keyId} pending migration cap reached (${_maxPendingMigrationsPerKeyV2})`,
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
const now = Date.now();
|
|
581
|
+
const job = {
|
|
582
|
+
id,
|
|
583
|
+
keyId,
|
|
584
|
+
sourceAlgorithm: k.algorithm,
|
|
585
|
+
targetAlgorithm,
|
|
586
|
+
status: MIGRATION_LIFECYCLE_V2.QUEUED,
|
|
587
|
+
createdAt: now,
|
|
588
|
+
startedAt: null,
|
|
589
|
+
settledAt: null,
|
|
590
|
+
metadata: metadata ? { ...metadata } : {},
|
|
591
|
+
};
|
|
592
|
+
_migrationsV2.set(id, job);
|
|
593
|
+
return _cloneMigrationV2(job);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function getMigrationV2(id) {
|
|
597
|
+
const m = _migrationsV2.get(id);
|
|
598
|
+
return m ? _cloneMigrationV2(m) : null;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export function listMigrationsV2({ keyId, status } = {}) {
|
|
602
|
+
const out = [];
|
|
603
|
+
for (const m of _migrationsV2.values()) {
|
|
604
|
+
if (keyId && m.keyId !== keyId) continue;
|
|
605
|
+
if (status && m.status !== status) continue;
|
|
606
|
+
out.push(_cloneMigrationV2(m));
|
|
607
|
+
}
|
|
608
|
+
return out;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export function setMigrationStatusV2(id, next) {
|
|
612
|
+
const m = _migrationsV2.get(id);
|
|
613
|
+
if (!m) throw new Error(`unknown migration ${id}`);
|
|
614
|
+
if (MIGRATION_TERMINAL_V2.has(m.status)) {
|
|
615
|
+
throw new Error(`migration ${id} is terminal (${m.status})`);
|
|
616
|
+
}
|
|
617
|
+
const allowed = MIGRATION_TRANSITIONS_V2.get(m.status);
|
|
618
|
+
if (!allowed || !allowed.has(next)) {
|
|
619
|
+
throw new Error(`invalid migration transition ${m.status} -> ${next}`);
|
|
620
|
+
}
|
|
621
|
+
const now = Date.now();
|
|
622
|
+
m.status = next;
|
|
623
|
+
if (next === MIGRATION_LIFECYCLE_V2.RUNNING && !m.startedAt)
|
|
624
|
+
m.startedAt = now;
|
|
625
|
+
if (MIGRATION_TERMINAL_V2.has(next) && !m.settledAt) m.settledAt = now;
|
|
626
|
+
return _cloneMigrationV2(m);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export function startMigrationV2(id) {
|
|
630
|
+
return setMigrationStatusV2(id, MIGRATION_LIFECYCLE_V2.RUNNING);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function completeMigrationV2(id) {
|
|
634
|
+
return setMigrationStatusV2(id, MIGRATION_LIFECYCLE_V2.COMPLETED);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export function failMigrationV2(id) {
|
|
638
|
+
return setMigrationStatusV2(id, MIGRATION_LIFECYCLE_V2.FAILED);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export function cancelMigrationV2(id) {
|
|
642
|
+
return setMigrationStatusV2(id, MIGRATION_LIFECYCLE_V2.CANCELLED);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export function autoDeprecateIdleKeysV2({ now = Date.now() } = {}) {
|
|
646
|
+
const out = [];
|
|
647
|
+
for (const k of _keysV2.values()) {
|
|
648
|
+
if (k.status !== KEY_MATURITY_V2.ACTIVE) continue;
|
|
649
|
+
if (now - k.lastSeenAt < _keyIdleMsV2) continue;
|
|
650
|
+
k.status = KEY_MATURITY_V2.DEPRECATED;
|
|
651
|
+
k.lastSeenAt = now;
|
|
652
|
+
out.push(_cloneKeyV2(k));
|
|
653
|
+
}
|
|
654
|
+
return out;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export function autoFailStuckMigrationsV2({ now = Date.now() } = {}) {
|
|
658
|
+
const out = [];
|
|
659
|
+
for (const m of _migrationsV2.values()) {
|
|
660
|
+
if (m.status !== MIGRATION_LIFECYCLE_V2.RUNNING) continue;
|
|
661
|
+
if (!m.startedAt || now - m.startedAt < _migrationStuckMsV2) continue;
|
|
662
|
+
m.status = MIGRATION_LIFECYCLE_V2.FAILED;
|
|
663
|
+
m.settledAt = now;
|
|
664
|
+
out.push(_cloneMigrationV2(m));
|
|
665
|
+
}
|
|
666
|
+
return out;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export function getPqcManagerStatsV2() {
|
|
670
|
+
const keysByStatus = {};
|
|
671
|
+
for (const s of Object.values(KEY_MATURITY_V2)) keysByStatus[s] = 0;
|
|
672
|
+
for (const k of _keysV2.values()) keysByStatus[k.status]++;
|
|
673
|
+
const migrationsByStatus = {};
|
|
674
|
+
for (const s of Object.values(MIGRATION_LIFECYCLE_V2))
|
|
675
|
+
migrationsByStatus[s] = 0;
|
|
676
|
+
for (const m of _migrationsV2.values()) migrationsByStatus[m.status]++;
|
|
677
|
+
return {
|
|
678
|
+
totalKeysV2: _keysV2.size,
|
|
679
|
+
totalMigrationsV2: _migrationsV2.size,
|
|
680
|
+
maxActiveKeysPerOwner: _maxActiveKeysPerOwnerV2,
|
|
681
|
+
maxPendingMigrationsPerKey: _maxPendingMigrationsPerKeyV2,
|
|
682
|
+
keyIdleMs: _keyIdleMsV2,
|
|
683
|
+
migrationStuckMs: _migrationStuckMsV2,
|
|
684
|
+
keysByStatus,
|
|
685
|
+
migrationsByStatus,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export function _resetStatePqcManagerV2() {
|
|
690
|
+
_keysV2.clear();
|
|
691
|
+
_migrationsV2.clear();
|
|
692
|
+
_maxActiveKeysPerOwnerV2 = PQC_DEFAULT_MAX_ACTIVE_KEYS_PER_OWNER;
|
|
693
|
+
_maxPendingMigrationsPerKeyV2 = PQC_DEFAULT_MAX_PENDING_MIGRATIONS_PER_KEY;
|
|
694
|
+
_keyIdleMsV2 = PQC_DEFAULT_KEY_IDLE_MS;
|
|
695
|
+
_migrationStuckMsV2 = PQC_DEFAULT_MIGRATION_STUCK_MS;
|
|
696
|
+
}
|
|
@@ -9,13 +9,4 @@
|
|
|
9
9
|
* in new code.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
estimateTokens,
|
|
14
|
-
estimateMessagesTokens,
|
|
15
|
-
CONTEXT_WINDOWS,
|
|
16
|
-
getContextWindow,
|
|
17
|
-
COMPRESSION_VARIANTS,
|
|
18
|
-
getCompressionVariant,
|
|
19
|
-
adaptiveThresholds,
|
|
20
|
-
PromptCompressor,
|
|
21
|
-
} from "../harness/prompt-compressor.js";
|
|
12
|
+
export * from "../harness/prompt-compressor.js";
|