chainlesschain 0.51.0 → 0.81.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.
Files changed (70) hide show
  1. package/package.json +1 -1
  2. package/src/assets/web-panel/.build-hash +1 -1
  3. package/src/assets/web-panel/assets/{AppLayout-Rvi759IS.js → AppLayout-6SPt_8Y_.js} +1 -1
  4. package/src/assets/web-panel/assets/{Dashboard-DBhFxXYQ.js → Dashboard-Br7kCwKJ.js} +2 -2
  5. package/src/assets/web-panel/assets/Dashboard-CKeMmCoT.css +1 -0
  6. package/src/assets/web-panel/assets/{index-uL0cZ8N_.js → index-tN-8TosE.js} +2 -2
  7. package/src/assets/web-panel/index.html +2 -2
  8. package/src/commands/a2a.js +380 -0
  9. package/src/commands/agent-network.js +785 -0
  10. package/src/commands/automation.js +654 -0
  11. package/src/commands/bi.js +348 -0
  12. package/src/commands/crosschain.js +218 -0
  13. package/src/commands/dao.js +565 -0
  14. package/src/commands/did-v2.js +620 -0
  15. package/src/commands/dlp.js +341 -0
  16. package/src/commands/economy.js +578 -0
  17. package/src/commands/evolution.js +391 -0
  18. package/src/commands/evomap.js +394 -0
  19. package/src/commands/federation.js +283 -0
  20. package/src/commands/hmemory.js +442 -0
  21. package/src/commands/inference.js +318 -0
  22. package/src/commands/lowcode.js +356 -0
  23. package/src/commands/marketplace.js +256 -0
  24. package/src/commands/perf.js +433 -0
  25. package/src/commands/pipeline.js +449 -0
  26. package/src/commands/plugin-ecosystem.js +517 -0
  27. package/src/commands/privacy.js +321 -0
  28. package/src/commands/reputation.js +261 -0
  29. package/src/commands/sandbox.js +401 -0
  30. package/src/commands/siem.js +246 -0
  31. package/src/commands/sla.js +259 -0
  32. package/src/commands/social.js +311 -0
  33. package/src/commands/sso.js +798 -0
  34. package/src/commands/stress.js +230 -0
  35. package/src/commands/terraform.js +245 -0
  36. package/src/commands/workflow.js +320 -0
  37. package/src/commands/zkp.js +562 -1
  38. package/src/index.js +21 -0
  39. package/src/lib/a2a-protocol.js +451 -0
  40. package/src/lib/agent-economy.js +479 -0
  41. package/src/lib/agent-network.js +1121 -0
  42. package/src/lib/app-builder.js +239 -0
  43. package/src/lib/automation-engine.js +948 -0
  44. package/src/lib/bi-engine.js +338 -0
  45. package/src/lib/cross-chain.js +345 -0
  46. package/src/lib/dao-governance.js +569 -0
  47. package/src/lib/did-v2-manager.js +1127 -0
  48. package/src/lib/dlp-engine.js +389 -0
  49. package/src/lib/evolution-system.js +453 -0
  50. package/src/lib/evomap-federation.js +177 -0
  51. package/src/lib/evomap-governance.js +276 -0
  52. package/src/lib/federation-hardening.js +259 -0
  53. package/src/lib/hierarchical-memory.js +481 -0
  54. package/src/lib/inference-network.js +330 -0
  55. package/src/lib/perf-tuning.js +734 -0
  56. package/src/lib/pipeline-orchestrator.js +928 -0
  57. package/src/lib/plugin-ecosystem.js +1109 -0
  58. package/src/lib/privacy-computing.js +427 -0
  59. package/src/lib/reputation-optimizer.js +299 -0
  60. package/src/lib/sandbox-v2.js +306 -0
  61. package/src/lib/siem-exporter.js +333 -0
  62. package/src/lib/skill-marketplace.js +325 -0
  63. package/src/lib/sla-manager.js +275 -0
  64. package/src/lib/social-graph-analytics.js +707 -0
  65. package/src/lib/sso-manager.js +841 -0
  66. package/src/lib/stress-tester.js +330 -0
  67. package/src/lib/terraform-manager.js +363 -0
  68. package/src/lib/workflow-engine.js +454 -1
  69. package/src/lib/zkp-engine.js +523 -20
  70. package/src/assets/web-panel/assets/Dashboard-BS-tzGNj.css +0 -1
@@ -301,4 +301,393 @@ export function _resetState() {
301
301
  _scanCount = 0;
302
302
  _blockCount = 0;
303
303
  _alertCount = 0;
304
+ _v2PolicyMeta.clear();
305
+ _v2IncidentMeta.clear();
304
306
  }
307
+
308
+ // ═══════════════════════════════════════════════════════════════
309
+ // V2 Canonical Surface (Phase 50)
310
+ // ═══════════════════════════════════════════════════════════════
311
+
312
+ export const DLP_ACTION = Object.freeze({
313
+ ALLOW: "allow",
314
+ ALERT: "alert",
315
+ BLOCK: "block",
316
+ QUARANTINE: "quarantine",
317
+ });
318
+
319
+ export const DLP_CHANNEL = Object.freeze({
320
+ EMAIL: "email",
321
+ CHAT: "chat",
322
+ FILE_TRANSFER: "file_transfer",
323
+ CLIPBOARD: "clipboard",
324
+ EXPORT: "export",
325
+ });
326
+
327
+ export const DLP_SEVERITY = Object.freeze({
328
+ LOW: "low",
329
+ MEDIUM: "medium",
330
+ HIGH: "high",
331
+ CRITICAL: "critical",
332
+ });
333
+
334
+ // Ordered priority for "highest action wins" aggregation.
335
+ const _actionPriority = Object.freeze({
336
+ allow: 0,
337
+ alert: 1,
338
+ block: 2,
339
+ quarantine: 3,
340
+ });
341
+
342
+ const _severityOrder = Object.freeze(["low", "medium", "high", "critical"]);
343
+
344
+ // Default maxContentSize (10 MB — matches Phase 50 design §六)
345
+ export const DLP_DEFAULT_MAX_CONTENT_SIZE = 10 * 1024 * 1024;
346
+
347
+ // Parallel V2 metadata Maps (policy → {description, channels}), (incident → {metadata})
348
+ const _v2PolicyMeta = new Map();
349
+ const _v2IncidentMeta = new Map();
350
+
351
+ // Built-in policy templates from Phase 50 design §七
352
+ const _builtinPolicyTemplates = Object.freeze([
353
+ Object.freeze({
354
+ name: "credit-card",
355
+ description:
356
+ "Detects credit card numbers (13-19 digits, optional separators)",
357
+ patterns: ["\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b"],
358
+ keywords: [],
359
+ channels: [],
360
+ action: "block",
361
+ severity: "high",
362
+ }),
363
+ Object.freeze({
364
+ name: "cn-id-number",
365
+ description: "Detects Chinese 18-digit ID numbers",
366
+ patterns: ["\\b\\d{17}[\\dXx]\\b"],
367
+ keywords: [],
368
+ channels: [],
369
+ action: "block",
370
+ severity: "high",
371
+ }),
372
+ Object.freeze({
373
+ name: "email-address",
374
+ description: "Detects email addresses (alert-only for export channel)",
375
+ patterns: ["[\\w.]+@[\\w.]+\\.\\w+"],
376
+ keywords: [],
377
+ channels: ["export"],
378
+ action: "alert",
379
+ severity: "medium",
380
+ }),
381
+ Object.freeze({
382
+ name: "api-key",
383
+ description:
384
+ "Detects common API-key tokens (sk-*, api_key=..., secret_key=...)",
385
+ patterns: ["sk-[A-Za-z0-9]{20,}", "(?:api_key|secret_key)\\s*[:=]\\s*\\S+"],
386
+ keywords: [],
387
+ channels: [],
388
+ action: "block",
389
+ severity: "critical",
390
+ }),
391
+ Object.freeze({
392
+ name: "plaintext-password",
393
+ description: "Detects plaintext passwords in content",
394
+ patterns: ["password\\s*[:=]\\s*\\S+"],
395
+ keywords: [],
396
+ channels: [],
397
+ action: "alert",
398
+ severity: "medium",
399
+ }),
400
+ ]);
401
+
402
+ function _validateAction(action) {
403
+ if (!Object.values(DLP_ACTION).includes(action)) {
404
+ throw new Error(
405
+ `Invalid action: ${action}. Expected one of ${Object.values(DLP_ACTION).join("|")}`,
406
+ );
407
+ }
408
+ }
409
+
410
+ function _validateSeverity(severity) {
411
+ if (!Object.values(DLP_SEVERITY).includes(severity)) {
412
+ throw new Error(
413
+ `Invalid severity: ${severity}. Expected one of ${Object.values(DLP_SEVERITY).join("|")}`,
414
+ );
415
+ }
416
+ }
417
+
418
+ function _validateChannels(channels) {
419
+ if (!Array.isArray(channels)) {
420
+ throw new Error("channels must be an array");
421
+ }
422
+ for (const c of channels) {
423
+ if (!Object.values(DLP_CHANNEL).includes(c)) {
424
+ throw new Error(
425
+ `Invalid channel: ${c}. Expected one of ${Object.values(DLP_CHANNEL).join("|")}`,
426
+ );
427
+ }
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Create a policy with V2 canonical validation + channel filter + description.
433
+ */
434
+ export function createPolicyV2(db, options) {
435
+ if (!options || typeof options !== "object") {
436
+ throw new Error("options object is required");
437
+ }
438
+ const {
439
+ name,
440
+ description = "",
441
+ channels = [],
442
+ patterns = [],
443
+ keywords = [],
444
+ action = DLP_ACTION.ALERT,
445
+ severity = DLP_SEVERITY.MEDIUM,
446
+ } = options;
447
+ if (!name) throw new Error("Policy name is required");
448
+ _validateAction(action);
449
+ _validateSeverity(severity);
450
+ _validateChannels(channels);
451
+ const policy = createPolicy(db, name, patterns, keywords, action, severity);
452
+ _v2PolicyMeta.set(policy.id, {
453
+ description,
454
+ channels: [...channels],
455
+ });
456
+ return { ...policy, description, channels: [...channels] };
457
+ }
458
+
459
+ /**
460
+ * Get V2 metadata for a policy (description + channels).
461
+ */
462
+ export function getPolicyV2(policyId) {
463
+ const base = [..._policies.values()].find((p) => p.id === policyId);
464
+ if (!base) throw new Error(`Policy not found: ${policyId}`);
465
+ const meta = _v2PolicyMeta.get(policyId) || {
466
+ description: "",
467
+ channels: [],
468
+ };
469
+ return {
470
+ ...base,
471
+ description: meta.description,
472
+ channels: [...meta.channels],
473
+ };
474
+ }
475
+
476
+ /**
477
+ * List active (enabled) policies applicable to a specific channel.
478
+ * Policies with an empty channels array are considered "all channels".
479
+ */
480
+ export function listActivePoliciesForChannel(channel) {
481
+ if (!Object.values(DLP_CHANNEL).includes(channel)) {
482
+ throw new Error(`Invalid channel: ${channel}`);
483
+ }
484
+ const results = [];
485
+ for (const p of _policies.values()) {
486
+ if (!p.enabled) continue;
487
+ const meta = _v2PolicyMeta.get(p.id);
488
+ const channels = meta ? meta.channels : [];
489
+ if (channels.length === 0 || channels.includes(channel)) {
490
+ results.push({
491
+ ...p,
492
+ description: meta ? meta.description : "",
493
+ channels: [...channels],
494
+ });
495
+ }
496
+ }
497
+ return results;
498
+ }
499
+
500
+ /**
501
+ * Scan content with V2 channel filter + size limit + metadata attach.
502
+ * Throws if content exceeds maxContentSize (default 10 MB).
503
+ */
504
+ export function scanContentV2(db, options) {
505
+ if (!options || typeof options !== "object") {
506
+ throw new Error("options object is required");
507
+ }
508
+ const {
509
+ content,
510
+ channel,
511
+ userId,
512
+ metadata = {},
513
+ maxContentSize = DLP_DEFAULT_MAX_CONTENT_SIZE,
514
+ } = options;
515
+ if (!content) throw new Error("Content is required");
516
+ if (channel !== undefined && !Object.values(DLP_CHANNEL).includes(channel)) {
517
+ throw new Error(`Invalid channel: ${channel}`);
518
+ }
519
+ // Size gate — byte length of UTF-8 representation
520
+ const byteLen = Buffer.byteLength(content, "utf8");
521
+ if (byteLen > maxContentSize) {
522
+ throw new Error(
523
+ `Content size ${byteLen}B exceeds maxContentSize ${maxContentSize}B`,
524
+ );
525
+ }
526
+
527
+ // Hold channel-filtered policies while scanning.
528
+ const originalEnabled = new Map();
529
+ if (channel) {
530
+ for (const p of _policies.values()) {
531
+ const meta = _v2PolicyMeta.get(p.id);
532
+ const channels = meta ? meta.channels : [];
533
+ if (channels.length > 0 && !channels.includes(channel)) {
534
+ originalEnabled.set(p.id, p.enabled);
535
+ p.enabled = false;
536
+ }
537
+ }
538
+ }
539
+
540
+ let result;
541
+ try {
542
+ result = scanContent(db, content, channel, userId);
543
+ } finally {
544
+ for (const [id, enabled] of originalEnabled) {
545
+ const p = _policies.get(id);
546
+ if (p) p.enabled = enabled;
547
+ }
548
+ }
549
+
550
+ // Attach V2 metadata to every incident.
551
+ for (const incident of result.incidents) {
552
+ _v2IncidentMeta.set(incident.id, { ...metadata });
553
+ }
554
+
555
+ return { ...result, contentBytes: byteLen, channel: channel || "unknown" };
556
+ }
557
+
558
+ /**
559
+ * List incidents with V2 filter (channel/severity/resolved/userId/policyId/from/to).
560
+ */
561
+ export function listIncidentsV2(filter = {}) {
562
+ let incidents = [..._incidents.values()];
563
+ if (filter.channel) {
564
+ if (!Object.values(DLP_CHANNEL).includes(filter.channel)) {
565
+ throw new Error(`Invalid channel: ${filter.channel}`);
566
+ }
567
+ incidents = incidents.filter((i) => i.channel === filter.channel);
568
+ }
569
+ if (filter.severity) {
570
+ if (!Object.values(DLP_SEVERITY).includes(filter.severity)) {
571
+ throw new Error(`Invalid severity: ${filter.severity}`);
572
+ }
573
+ incidents = incidents.filter((i) => i.severity === filter.severity);
574
+ }
575
+ if (filter.resolved === true) {
576
+ incidents = incidents.filter((i) => !!i.resolvedAt);
577
+ } else if (filter.resolved === false) {
578
+ incidents = incidents.filter((i) => !i.resolvedAt);
579
+ }
580
+ if (filter.userId) {
581
+ incidents = incidents.filter((i) => i.userId === filter.userId);
582
+ }
583
+ if (filter.policyId) {
584
+ incidents = incidents.filter((i) => i.policyId === filter.policyId);
585
+ }
586
+ if (filter.fromDate) {
587
+ incidents = incidents.filter((i) => i.createdAt >= filter.fromDate);
588
+ }
589
+ if (filter.toDate) {
590
+ incidents = incidents.filter((i) => i.createdAt <= filter.toDate);
591
+ }
592
+ incidents.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
593
+ const limit = filter.limit || 50;
594
+ return incidents.slice(0, limit).map((i) => ({
595
+ ...i,
596
+ metadata: _v2IncidentMeta.get(i.id) || {},
597
+ }));
598
+ }
599
+
600
+ /**
601
+ * Detailed incident snapshot including V2 metadata.
602
+ */
603
+ export function getIncidentV2(incidentId) {
604
+ const incident = _incidents.get(incidentId);
605
+ if (!incident) throw new Error(`Incident not found: ${incidentId}`);
606
+ return { ...incident, metadata: _v2IncidentMeta.get(incidentId) || {} };
607
+ }
608
+
609
+ /**
610
+ * Built-in policy template catalog.
611
+ */
612
+ export function listBuiltinPolicyTemplates() {
613
+ return _builtinPolicyTemplates.map((t) => ({ ...t }));
614
+ }
615
+
616
+ /**
617
+ * Install one or more built-in policy templates by name (or all if names omitted).
618
+ * Returns the list of installed policy records.
619
+ */
620
+ export function installBuiltinPolicies(db, names) {
621
+ const selected =
622
+ names && names.length > 0
623
+ ? _builtinPolicyTemplates.filter((t) => names.includes(t.name))
624
+ : _builtinPolicyTemplates;
625
+ if (names && names.length > 0) {
626
+ const requested = new Set(names);
627
+ for (const t of selected) requested.delete(t.name);
628
+ if (requested.size > 0) {
629
+ throw new Error(
630
+ `Unknown built-in template(s): ${[...requested].join(", ")}`,
631
+ );
632
+ }
633
+ }
634
+ const installed = [];
635
+ for (const t of selected) {
636
+ installed.push(createPolicyV2(db, { ...t }));
637
+ }
638
+ return installed;
639
+ }
640
+
641
+ /**
642
+ * Extended stats with byAction / bySeverity / byChannel breakdowns and top policies.
643
+ */
644
+ export function getDLPStatsV2() {
645
+ const base = getDLPStats();
646
+ const byAction = {};
647
+ for (const v of Object.values(DLP_ACTION)) byAction[v] = 0;
648
+ const bySeverity = {};
649
+ for (const v of Object.values(DLP_SEVERITY)) bySeverity[v] = 0;
650
+ const byChannel = {};
651
+ for (const v of Object.values(DLP_CHANNEL)) byChannel[v] = 0;
652
+ const byPolicy = {};
653
+ for (const incident of _incidents.values()) {
654
+ if (byAction[incident.actionTaken] !== undefined) {
655
+ byAction[incident.actionTaken] += 1;
656
+ }
657
+ if (bySeverity[incident.severity] !== undefined) {
658
+ bySeverity[incident.severity] += 1;
659
+ }
660
+ if (byChannel[incident.channel] !== undefined) {
661
+ byChannel[incident.channel] += 1;
662
+ }
663
+ byPolicy[incident.policyId] = (byPolicy[incident.policyId] || 0) + 1;
664
+ }
665
+ const topPolicies = Object.entries(byPolicy)
666
+ .sort((a, b) => b[1] - a[1])
667
+ .slice(0, 5)
668
+ .map(([policyId, count]) => ({ policyId, count }));
669
+ return {
670
+ ...base,
671
+ policies: _policies.size,
672
+ activePolicies: [..._policies.values()].filter((p) => p.enabled).length,
673
+ byAction,
674
+ bySeverity,
675
+ byChannel,
676
+ topPolicies,
677
+ };
678
+ }
679
+
680
+ /**
681
+ * Highest severity among unresolved incidents (for alert aggregation).
682
+ */
683
+ export function getHighestUnresolvedSeverity() {
684
+ let highestIdx = -1;
685
+ for (const incident of _incidents.values()) {
686
+ if (incident.resolvedAt) continue;
687
+ const idx = _severityOrder.indexOf(incident.severity);
688
+ if (idx > highestIdx) highestIdx = idx;
689
+ }
690
+ return highestIdx === -1 ? null : _severityOrder[highestIdx];
691
+ }
692
+
693
+ export { _v2PolicyMeta, _v2IncidentMeta, _builtinPolicyTemplates };