@triedotdev/mcp 1.0.113 → 1.0.114

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 (75) hide show
  1. package/dist/auto-fix-apply-PCAHWLXF.js +10 -0
  2. package/dist/autonomy-config-O4H3Z7YV.js +30 -0
  3. package/dist/chunk-2GIAROBF.js +173 -0
  4. package/dist/chunk-2GIAROBF.js.map +1 -0
  5. package/dist/{chunk-33WL3D7A.js → chunk-2SIFK7OW.js} +7 -419
  6. package/dist/chunk-2SIFK7OW.js.map +1 -0
  7. package/dist/chunk-43X6JBEM.js +36 -0
  8. package/dist/chunk-43X6JBEM.js.map +1 -0
  9. package/dist/{chunk-2764KZZQ.js → chunk-4SBZXIMG.js} +133 -595
  10. package/dist/chunk-4SBZXIMG.js.map +1 -0
  11. package/dist/chunk-55DOQNHJ.js +772 -0
  12. package/dist/chunk-55DOQNHJ.js.map +1 -0
  13. package/dist/chunk-6LXSA2OZ.js +425 -0
  14. package/dist/chunk-6LXSA2OZ.js.map +1 -0
  15. package/dist/{chunk-SDS3UVFY.js → chunk-AOFYU6T3.js} +113 -559
  16. package/dist/chunk-AOFYU6T3.js.map +1 -0
  17. package/dist/{chunk-6QR6QZIX.js → chunk-D3EXBJE2.js} +25 -658
  18. package/dist/chunk-D3EXBJE2.js.map +1 -0
  19. package/dist/chunk-DJ2YAGHK.js +50 -0
  20. package/dist/chunk-DJ2YAGHK.js.map +1 -0
  21. package/dist/chunk-DRDEEF6G.js +328 -0
  22. package/dist/chunk-DRDEEF6G.js.map +1 -0
  23. package/dist/chunk-DZREHOGW.js +706 -0
  24. package/dist/chunk-DZREHOGW.js.map +1 -0
  25. package/dist/chunk-KRH642MT.js +947 -0
  26. package/dist/chunk-KRH642MT.js.map +1 -0
  27. package/dist/{chunk-QYOACM2C.js → chunk-MVNJPJBK.js} +22 -252
  28. package/dist/chunk-MVNJPJBK.js.map +1 -0
  29. package/dist/chunk-NS2MSZMB.js +394 -0
  30. package/dist/chunk-NS2MSZMB.js.map +1 -0
  31. package/dist/chunk-SWSK7ANT.js +340 -0
  32. package/dist/chunk-SWSK7ANT.js.map +1 -0
  33. package/dist/chunk-VRLMTOB6.js +566 -0
  34. package/dist/chunk-VRLMTOB6.js.map +1 -0
  35. package/dist/chunk-YR4BMGYO.js +130 -0
  36. package/dist/chunk-YR4BMGYO.js.map +1 -0
  37. package/dist/chunk-ZV2K6M7T.js +74 -0
  38. package/dist/chunk-ZV2K6M7T.js.map +1 -0
  39. package/dist/cli/main.js +107 -375
  40. package/dist/cli/main.js.map +1 -1
  41. package/dist/cli/yolo-daemon.js +18 -8
  42. package/dist/cli/yolo-daemon.js.map +1 -1
  43. package/dist/client-7XZHCMD3.js +28 -0
  44. package/dist/client-7XZHCMD3.js.map +1 -0
  45. package/dist/{goal-manager-AP4LTE6U.js → goal-manager-LMS6ZJB7.js} +7 -3
  46. package/dist/goal-manager-LMS6ZJB7.js.map +1 -0
  47. package/dist/goal-validator-7UPLOVAZ.js +184 -0
  48. package/dist/goal-validator-7UPLOVAZ.js.map +1 -0
  49. package/dist/graph-U5JWSAB5.js +10 -0
  50. package/dist/graph-U5JWSAB5.js.map +1 -0
  51. package/dist/guardian-agent-EXP7APLC.js +25 -0
  52. package/dist/guardian-agent-EXP7APLC.js.map +1 -0
  53. package/dist/hypothesis-KGC3P54C.js +19 -0
  54. package/dist/hypothesis-KGC3P54C.js.map +1 -0
  55. package/dist/incident-index-PNIVT47T.js +11 -0
  56. package/dist/incident-index-PNIVT47T.js.map +1 -0
  57. package/dist/index.js +285 -16
  58. package/dist/index.js.map +1 -1
  59. package/dist/ledger-SR6OEBLO.js +15 -0
  60. package/dist/ledger-SR6OEBLO.js.map +1 -0
  61. package/dist/output-manager-BOTMXSND.js +13 -0
  62. package/dist/output-manager-BOTMXSND.js.map +1 -0
  63. package/dist/pattern-discovery-F7LU5K6E.js +8 -0
  64. package/dist/pattern-discovery-F7LU5K6E.js.map +1 -0
  65. package/package.json +1 -1
  66. package/dist/chunk-2764KZZQ.js.map +0 -1
  67. package/dist/chunk-33WL3D7A.js.map +0 -1
  68. package/dist/chunk-6JPPYG7F.js +0 -1813
  69. package/dist/chunk-6JPPYG7F.js.map +0 -1
  70. package/dist/chunk-6QR6QZIX.js.map +0 -1
  71. package/dist/chunk-QYOACM2C.js.map +0 -1
  72. package/dist/chunk-SDS3UVFY.js.map +0 -1
  73. package/dist/guardian-agent-XEYNG7RH.js +0 -18
  74. /package/dist/{goal-manager-AP4LTE6U.js.map → auto-fix-apply-PCAHWLXF.js.map} +0 -0
  75. /package/dist/{guardian-agent-XEYNG7RH.js.map → autonomy-config-O4H3Z7YV.js.map} +0 -0
@@ -1,23 +1,34 @@
1
1
  import {
2
- ContextGraph,
2
+ getGoalManager
3
+ } from "./chunk-2SIFK7OW.js";
4
+ import {
5
+ getHypothesisEngine
6
+ } from "./chunk-DZREHOGW.js";
7
+ import {
8
+ getInsightStore
9
+ } from "./chunk-6LXSA2OZ.js";
10
+ import {
3
11
  GotchaPredictor,
4
12
  findCrossProjectPatterns,
13
+ recordToGlobalMemory
14
+ } from "./chunk-D3EXBJE2.js";
15
+ import {
5
16
  isAIAvailable,
6
- recordToGlobalMemory,
7
17
  runAIAnalysis
8
- } from "./chunk-6QR6QZIX.js";
9
- import {
10
- getGoalManager,
11
- getInsightStore
12
- } from "./chunk-33WL3D7A.js";
18
+ } from "./chunk-SWSK7ANT.js";
13
19
  import {
14
20
  autoResolveIssues,
15
- getGuardianState,
16
21
  getHistoricalInsights,
17
22
  getIssueHash,
18
23
  searchIssues,
19
24
  storeIssues
20
- } from "./chunk-6JPPYG7F.js";
25
+ } from "./chunk-55DOQNHJ.js";
26
+ import {
27
+ getGuardianState
28
+ } from "./chunk-KRH642MT.js";
29
+ import {
30
+ ContextGraph
31
+ } from "./chunk-NS2MSZMB.js";
21
32
 
22
33
  // src/guardian/guardian-agent.ts
23
34
  import { basename as basename2 } from "path";
@@ -341,554 +352,6 @@ function getRiskPredictor(projectPath) {
341
352
  return predictor;
342
353
  }
343
354
 
344
- // src/guardian/hypothesis.ts
345
- import { dirname as dirname2 } from "path";
346
- var HYPOTHESIS_TEMPLATES = [
347
- {
348
- category: "timing",
349
- statement: "Issues spike after weekend deployments",
350
- testCriteria: "Compare Monday issue counts to other days",
351
- minConfidence: 0.3,
352
- dataRequired: ["issue_timestamps", "deployment_data"]
353
- },
354
- {
355
- category: "timing",
356
- statement: "Code quality declines on Fridays",
357
- testCriteria: "Compare Friday issue introduction rate to weekly average",
358
- minConfidence: 0.3,
359
- dataRequired: ["issue_timestamps"]
360
- },
361
- {
362
- category: "pattern",
363
- statement: "Auth-related code has the highest incident rate",
364
- testCriteria: "Compare auth/ issue count to other directories",
365
- minConfidence: 0.4,
366
- dataRequired: ["issue_files"]
367
- },
368
- {
369
- category: "pattern",
370
- statement: "Security issues cluster in specific directories",
371
- testCriteria: "Check if security issues are concentrated (>50% in <3 dirs)",
372
- minConfidence: 0.4,
373
- dataRequired: ["issue_files", "issue_agents"]
374
- },
375
- {
376
- category: "code",
377
- statement: "Files with multiple authors have more issues",
378
- testCriteria: "Correlate file author count with issue count",
379
- minConfidence: 0.4,
380
- dataRequired: ["issue_files", "git_blame"]
381
- },
382
- {
383
- category: "code",
384
- statement: "Recently modified files are more likely to have issues",
385
- testCriteria: "Compare issue rate for recent vs old files",
386
- minConfidence: 0.3,
387
- dataRequired: ["issue_timestamps", "file_modification_times"]
388
- },
389
- {
390
- category: "pattern",
391
- statement: "Critical issues often come in clusters",
392
- testCriteria: "Check temporal clustering of critical issues",
393
- minConfidence: 0.3,
394
- dataRequired: ["issue_timestamps", "issue_severities"]
395
- }
396
- ];
397
- var HypothesisEngine = class {
398
- projectPath;
399
- guardianState;
400
- insightStore;
401
- constructor(projectPath) {
402
- this.projectPath = projectPath;
403
- this.guardianState = getGuardianState(projectPath);
404
- this.insightStore = getInsightStore(projectPath);
405
- }
406
- /**
407
- * Create a new hypothesis
408
- */
409
- async createHypothesis(statement, options) {
410
- const hypothesis = {
411
- id: `hyp-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
412
- statement,
413
- confidence: options?.initialConfidence ?? 0.5,
414
- status: "proposed",
415
- evidence: [],
416
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
417
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
418
- testCriteria: options?.testCriteria,
419
- category: options?.category ?? "general"
420
- };
421
- await this.guardianState.addHypothesis(hypothesis);
422
- return hypothesis;
423
- }
424
- /**
425
- * Auto-generate hypotheses based on detected patterns
426
- */
427
- async autoGenerateHypotheses() {
428
- const generated = [];
429
- try {
430
- await this.guardianState.load();
431
- const existing = this.guardianState.getAllHypotheses();
432
- const existingStatements = new Set(existing.map((h) => h.statement.toLowerCase()));
433
- const issues = await searchIssues("", {
434
- workDir: this.projectPath,
435
- limit: 500,
436
- includeResolved: true
437
- });
438
- if (issues.length < 10) {
439
- return generated;
440
- }
441
- for (const template of HYPOTHESIS_TEMPLATES) {
442
- if (existingStatements.has(template.statement.toLowerCase())) {
443
- continue;
444
- }
445
- const evidence = await this.gatherInitialEvidence(template, issues);
446
- if (evidence.length > 0 && evidence[0].weight >= template.minConfidence) {
447
- const hypothesis = await this.createHypothesis(template.statement, {
448
- category: template.category,
449
- testCriteria: template.testCriteria,
450
- initialConfidence: evidence[0].weight
451
- });
452
- for (const e of evidence) {
453
- await this.guardianState.addEvidence(hypothesis.id, e);
454
- }
455
- generated.push(hypothesis);
456
- if (generated.length >= 2) break;
457
- }
458
- }
459
- } catch (error) {
460
- console.error("Failed to auto-generate hypotheses:", error);
461
- }
462
- return generated;
463
- }
464
- /**
465
- * Gather initial evidence for a hypothesis template
466
- */
467
- async gatherInitialEvidence(template, issues) {
468
- const evidence = [];
469
- switch (template.category) {
470
- case "timing":
471
- evidence.push(...this.analyzeTimingPatterns(template, issues));
472
- break;
473
- case "pattern":
474
- evidence.push(...this.analyzeLocationPatterns(template, issues));
475
- break;
476
- case "code":
477
- evidence.push(...this.analyzeCodePatterns(template, issues));
478
- break;
479
- }
480
- return evidence;
481
- }
482
- /**
483
- * Analyze timing patterns in issues
484
- */
485
- analyzeTimingPatterns(template, issues) {
486
- const evidence = [];
487
- const dayOfWeekCounts = {};
488
- for (const { issue } of issues) {
489
- const date = new Date(issue.timestamp);
490
- const day = date.getDay();
491
- dayOfWeekCounts[day] = (dayOfWeekCounts[day] || 0) + 1;
492
- }
493
- if (template.statement.includes("Friday")) {
494
- const fridayCount = dayOfWeekCounts[5] || 0;
495
- const avgOtherDays = (Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0) - fridayCount) / 4;
496
- if (fridayCount > avgOtherDays * 1.5) {
497
- evidence.push({
498
- type: "supporting",
499
- description: `Friday has ${((fridayCount / avgOtherDays - 1) * 100).toFixed(0)}% more issues than average`,
500
- weight: Math.min(0.8, 0.3 + (fridayCount / avgOtherDays - 1) * 0.2),
501
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
502
- });
503
- } else {
504
- evidence.push({
505
- type: "contradicting",
506
- description: "Friday issue count is not significantly higher",
507
- weight: 0.3,
508
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
509
- });
510
- }
511
- }
512
- if (template.statement.includes("weekend") || template.statement.includes("Monday")) {
513
- const mondayCount = dayOfWeekCounts[1] || 0;
514
- const avgOtherDays = (Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0) - mondayCount) / 4;
515
- if (mondayCount > avgOtherDays * 1.5) {
516
- evidence.push({
517
- type: "supporting",
518
- description: `Monday has ${((mondayCount / avgOtherDays - 1) * 100).toFixed(0)}% more issues than average`,
519
- weight: Math.min(0.8, 0.3 + (mondayCount / avgOtherDays - 1) * 0.2),
520
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
521
- });
522
- }
523
- }
524
- return evidence;
525
- }
526
- /**
527
- * Analyze location patterns in issues
528
- */
529
- analyzeLocationPatterns(template, issues) {
530
- const evidence = [];
531
- const dirCounts = {};
532
- for (const { issue } of issues) {
533
- const dir = dirname2(issue.file);
534
- dirCounts[dir] = (dirCounts[dir] || 0) + 1;
535
- }
536
- const sortedDirs = Object.entries(dirCounts).sort(([, a], [, b]) => b - a);
537
- if (template.statement.includes("Auth")) {
538
- const authDirs = sortedDirs.filter(
539
- ([dir]) => dir.toLowerCase().includes("auth") || dir.toLowerCase().includes("login") || dir.toLowerCase().includes("session")
540
- );
541
- const authCount = authDirs.reduce((sum, [, count]) => sum + count, 0);
542
- const percentage = authCount / issues.length * 100;
543
- if (percentage >= 20) {
544
- evidence.push({
545
- type: "supporting",
546
- description: `Auth-related code has ${percentage.toFixed(0)}% of issues`,
547
- weight: Math.min(0.85, 0.4 + percentage / 100),
548
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
549
- });
550
- }
551
- }
552
- if (template.statement.includes("cluster")) {
553
- const topThreeDirs = sortedDirs.slice(0, 3);
554
- const topThreeCount = topThreeDirs.reduce((sum, [, count]) => sum + count, 0);
555
- const percentage = topThreeCount / issues.length * 100;
556
- if (percentage >= 50) {
557
- evidence.push({
558
- type: "supporting",
559
- description: `Top 3 directories have ${percentage.toFixed(0)}% of issues`,
560
- weight: Math.min(0.8, 0.3 + percentage / 100),
561
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
562
- });
563
- }
564
- }
565
- return evidence;
566
- }
567
- /**
568
- * Analyze code patterns
569
- */
570
- analyzeCodePatterns(template, issues) {
571
- const evidence = [];
572
- if (template.statement.includes("cluster")) {
573
- const criticalIssues = issues.filter((r) => r.issue.severity === "critical");
574
- if (criticalIssues.length >= 3) {
575
- const timestamps = criticalIssues.map((r) => new Date(r.issue.timestamp).getTime()).sort((a, b) => a - b);
576
- let clusteredCount = 0;
577
- for (let i = 1; i < timestamps.length; i++) {
578
- if (timestamps[i] - timestamps[i - 1] < 24 * 60 * 60 * 1e3) {
579
- clusteredCount++;
580
- }
581
- }
582
- const clusterRatio = clusteredCount / (timestamps.length - 1);
583
- if (clusterRatio >= 0.5) {
584
- evidence.push({
585
- type: "supporting",
586
- description: `${(clusterRatio * 100).toFixed(0)}% of critical issues occur within 24h of another`,
587
- weight: Math.min(0.75, 0.3 + clusterRatio * 0.4),
588
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
589
- });
590
- }
591
- }
592
- }
593
- return evidence;
594
- }
595
- /**
596
- * Update confidence scores based on new data
597
- */
598
- async updateConfidenceFromOutcomes() {
599
- const analyses = [];
600
- try {
601
- await this.guardianState.load();
602
- const activeHypotheses = this.guardianState.getActiveHypotheses();
603
- for (const hypothesis of activeHypotheses) {
604
- const analysis = await this.analyzeHypothesis(hypothesis);
605
- analyses.push(analysis);
606
- if (analysis.statusChange && this.insightStore.canCreateInsight("hypothesis-update")) {
607
- const insight = this.createHypothesisInsight(analysis);
608
- await this.insightStore.addInsight(insight);
609
- await this.insightStore.markInsightCreated("hypothesis-update");
610
- }
611
- }
612
- await this.guardianState.updateHypothesisAccuracy();
613
- } catch (error) {
614
- console.error("Failed to update hypothesis confidence:", error);
615
- }
616
- return analyses;
617
- }
618
- /**
619
- * Analyze a single hypothesis
620
- */
621
- async analyzeHypothesis(hypothesis) {
622
- const issues = await searchIssues("", {
623
- workDir: this.projectPath,
624
- limit: 100,
625
- includeResolved: false
626
- });
627
- const template = HYPOTHESIS_TEMPLATES.find(
628
- (t) => t.statement.toLowerCase() === hypothesis.statement.toLowerCase()
629
- );
630
- const recentEvidence = [];
631
- if (template) {
632
- recentEvidence.push(...await this.gatherInitialEvidence(template, issues));
633
- } else {
634
- recentEvidence.push(...this.gatherSemanticEvidence(hypothesis, issues));
635
- }
636
- const oldConfidence = hypothesis.confidence;
637
- let newConfidence = oldConfidence;
638
- for (const evidence of recentEvidence) {
639
- if (evidence.type === "supporting") {
640
- newConfidence = Math.min(1, newConfidence + evidence.weight * 0.1);
641
- } else {
642
- newConfidence = Math.max(0, newConfidence - evidence.weight * 0.1);
643
- }
644
- }
645
- let statusChange;
646
- if (newConfidence >= 0.8 && hypothesis.evidence.length >= 3) {
647
- statusChange = "validated";
648
- await this.guardianState.updateHypothesis(hypothesis.id, {
649
- status: "validated",
650
- confidence: newConfidence,
651
- validatedAt: (/* @__PURE__ */ new Date()).toISOString()
652
- });
653
- } else if (newConfidence <= 0.2 && hypothesis.evidence.length >= 3) {
654
- statusChange = "invalidated";
655
- await this.guardianState.updateHypothesis(hypothesis.id, {
656
- status: "invalidated",
657
- confidence: newConfidence
658
- });
659
- } else {
660
- await this.guardianState.updateHypothesis(hypothesis.id, {
661
- confidence: newConfidence
662
- });
663
- }
664
- for (const evidence of recentEvidence) {
665
- await this.guardianState.addEvidence(hypothesis.id, evidence);
666
- }
667
- const analysis = {
668
- hypothesis: { ...hypothesis, confidence: newConfidence },
669
- recentEvidence,
670
- confidenceChange: newConfidence - oldConfidence,
671
- actionRequired: statusChange !== void 0
672
- };
673
- if (statusChange) {
674
- analysis.statusChange = statusChange;
675
- }
676
- return analysis;
677
- }
678
- /**
679
- * Gather evidence for user-created hypotheses using semantic matching
680
- *
681
- * This enables agentic tracking for natural language hypotheses like:
682
- * - "Mondays have more bugs than Fridays"
683
- * - "Code reviews reduce bug rate"
684
- * - "Security issues cluster in auth code"
685
- */
686
- gatherSemanticEvidence(hypothesis, issues) {
687
- const evidence = [];
688
- const stmt = hypothesis.statement.toLowerCase();
689
- if (stmt.includes("monday") || stmt.includes("friday") || stmt.includes("weekend") || stmt.includes("morning") || stmt.includes("afternoon")) {
690
- const dayNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
691
- const dayOfWeekCounts = { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0 };
692
- for (const { issue } of issues) {
693
- const date = new Date(issue.timestamp);
694
- const day = date.getDay();
695
- dayOfWeekCounts[day] = (dayOfWeekCounts[day] || 0) + 1;
696
- }
697
- const totalIssues = Object.values(dayOfWeekCounts).reduce((a, b) => a + b, 0);
698
- const avgPerDay = totalIssues / 7;
699
- for (let dayIdx = 0; dayIdx < 7; dayIdx++) {
700
- const dayName = dayNames[dayIdx];
701
- if (stmt.includes(dayName)) {
702
- const dayCount = dayOfWeekCounts[dayIdx] || 0;
703
- if (stmt.includes("more") || stmt.includes("higher") || stmt.includes("spike")) {
704
- if (dayCount > avgPerDay * 1.3) {
705
- evidence.push({
706
- type: "supporting",
707
- description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has ${dayCount} issues (${((dayCount / avgPerDay - 1) * 100).toFixed(0)}% above average)`,
708
- weight: Math.min(0.7, 0.3 + (dayCount / avgPerDay - 1) * 0.3),
709
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
710
- });
711
- } else {
712
- evidence.push({
713
- type: "contradicting",
714
- description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has average or below average issue count`,
715
- weight: 0.3,
716
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
717
- });
718
- }
719
- } else if (stmt.includes("fewer") || stmt.includes("less") || stmt.includes("reduce")) {
720
- if (dayCount < avgPerDay * 0.7) {
721
- evidence.push({
722
- type: "supporting",
723
- description: `${dayName.charAt(0).toUpperCase() + dayName.slice(1)} has ${dayCount} issues (${((1 - dayCount / avgPerDay) * 100).toFixed(0)}% below average)`,
724
- weight: Math.min(0.7, 0.3 + (1 - dayCount / avgPerDay) * 0.3),
725
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
726
- });
727
- }
728
- }
729
- }
730
- }
731
- }
732
- if (stmt.includes("review") || stmt.includes("pr") || stmt.includes("pull request")) {
733
- const recentIssues = issues.slice(0, 30);
734
- const olderIssues = issues.slice(30);
735
- if (recentIssues.length >= 10 && olderIssues.length >= 10) {
736
- const recentRate = recentIssues.length;
737
- const olderRate = olderIssues.length;
738
- if (stmt.includes("reduce") || stmt.includes("fewer") || stmt.includes("less")) {
739
- if (recentRate < olderRate) {
740
- evidence.push({
741
- type: "supporting",
742
- description: `Recent period has ${((1 - recentRate / olderRate) * 100).toFixed(0)}% fewer issues`,
743
- weight: Math.min(0.6, 0.3 + (1 - recentRate / olderRate) * 0.3),
744
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
745
- });
746
- } else {
747
- evidence.push({
748
- type: "contradicting",
749
- description: `Issue rate has not decreased recently`,
750
- weight: 0.2,
751
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
752
- });
753
- }
754
- }
755
- }
756
- }
757
- if (stmt.includes("cluster") || stmt.includes("concentrate") || stmt.includes("auth") || stmt.includes("specific") || stmt.includes("certain files")) {
758
- const dirCounts = {};
759
- for (const { issue } of issues) {
760
- const dir = dirname2(issue.file);
761
- dirCounts[dir] = (dirCounts[dir] || 0) + 1;
762
- }
763
- const sortedDirs = Object.entries(dirCounts).sort(([, a], [, b]) => b - a);
764
- const topThreeCount = sortedDirs.slice(0, 3).reduce((sum, [, count]) => sum + count, 0);
765
- const totalCount = issues.length;
766
- const concentration = topThreeCount / totalCount;
767
- if (concentration >= 0.5) {
768
- evidence.push({
769
- type: "supporting",
770
- description: `Top 3 directories have ${(concentration * 100).toFixed(0)}% of issues (concentrated)`,
771
- weight: Math.min(0.7, 0.3 + concentration * 0.4),
772
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
773
- });
774
- } else {
775
- evidence.push({
776
- type: "contradicting",
777
- description: `Issues are distributed across many directories`,
778
- weight: 0.3,
779
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
780
- });
781
- }
782
- }
783
- if (stmt.includes("critical") || stmt.includes("security") || stmt.includes("severity")) {
784
- const criticalCount = issues.filter((r) => r.issue.severity === "critical").length;
785
- const seriousCount = issues.filter((r) => r.issue.severity === "serious").length;
786
- const highSeverityRatio = (criticalCount + seriousCount) / issues.length;
787
- if (stmt.includes("increase") || stmt.includes("more") || stmt.includes("rise")) {
788
- if (highSeverityRatio > 0.3) {
789
- evidence.push({
790
- type: "supporting",
791
- description: `${(highSeverityRatio * 100).toFixed(0)}% of issues are high severity`,
792
- weight: Math.min(0.7, 0.3 + highSeverityRatio),
793
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
794
- });
795
- }
796
- } else if (stmt.includes("decrease") || stmt.includes("fewer") || stmt.includes("reduce")) {
797
- if (highSeverityRatio < 0.2) {
798
- evidence.push({
799
- type: "supporting",
800
- description: `Only ${(highSeverityRatio * 100).toFixed(0)}% of issues are high severity`,
801
- weight: 0.5,
802
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
803
- });
804
- }
805
- }
806
- }
807
- const agents = ["security", "performance", "accessibility", "test", "typecheck", "bug-finding"];
808
- for (const agent of agents) {
809
- if (stmt.includes(agent) || stmt.includes(agent.replace("-", " "))) {
810
- const agentIssues = issues.filter((r) => r.issue.agent === agent);
811
- const agentRatio = agentIssues.length / issues.length;
812
- if (stmt.includes("most") || stmt.includes("majority") || stmt.includes("main")) {
813
- if (agentRatio > 0.4) {
814
- evidence.push({
815
- type: "supporting",
816
- description: `${agent} accounts for ${(agentRatio * 100).toFixed(0)}% of issues`,
817
- weight: Math.min(0.7, 0.3 + agentRatio),
818
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
819
- });
820
- } else {
821
- evidence.push({
822
- type: "contradicting",
823
- description: `${agent} only accounts for ${(agentRatio * 100).toFixed(0)}% of issues`,
824
- weight: 0.3,
825
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
826
- });
827
- }
828
- }
829
- }
830
- }
831
- return evidence;
832
- }
833
- /**
834
- * Create an insight for hypothesis status change
835
- */
836
- createHypothesisInsight(analysis) {
837
- const isValidated = analysis.statusChange === "validated";
838
- return {
839
- id: `insight-hyp-${analysis.hypothesis.id}`,
840
- type: isValidated ? "celebration" : "observation",
841
- message: isValidated ? `Hypothesis confirmed: "${analysis.hypothesis.statement}"` : `Hypothesis disproven: "${analysis.hypothesis.statement}"`,
842
- context: `Confidence: ${(analysis.hypothesis.confidence * 100).toFixed(0)}%. ${analysis.recentEvidence.length} evidence points analyzed.`,
843
- relatedIssues: [],
844
- priority: 5,
845
- timestamp: Date.now(),
846
- dismissed: false,
847
- category: "pattern",
848
- details: {
849
- examples: analysis.recentEvidence.map((e) => `${e.type}: ${e.description}`)
850
- }
851
- };
852
- }
853
- /**
854
- * Get hypothesis by ID
855
- */
856
- async getHypothesis(hypothesisId) {
857
- await this.guardianState.load();
858
- return this.guardianState.getHypothesis(hypothesisId);
859
- }
860
- /**
861
- * Get all hypotheses
862
- */
863
- async getAllHypotheses() {
864
- await this.guardianState.load();
865
- return this.guardianState.getAllHypotheses();
866
- }
867
- /**
868
- * Get validated hypotheses
869
- */
870
- async getValidatedHypotheses() {
871
- await this.guardianState.load();
872
- return this.guardianState.getValidatedHypotheses();
873
- }
874
- /**
875
- * Get hypothesis accuracy stats
876
- */
877
- getAccuracy() {
878
- const metrics = this.guardianState.getMetrics();
879
- return metrics.hypothesisAccuracy;
880
- }
881
- };
882
- var hypothesisEngines = /* @__PURE__ */ new Map();
883
- function getHypothesisEngine(projectPath) {
884
- let engine = hypothesisEngines.get(projectPath);
885
- if (!engine) {
886
- engine = new HypothesisEngine(projectPath);
887
- hypothesisEngines.set(projectPath, engine);
888
- }
889
- return engine;
890
- }
891
-
892
355
  // src/integrations/slack.ts
893
356
  var SlackIntegration = class {
894
357
  constructor(config) {
@@ -2164,6 +1627,97 @@ var GuardianAgent = class {
2164
1627
  await this.addInsight(insight);
2165
1628
  await this.markInsightCreated("celebration");
2166
1629
  }
1630
+ if (issues.length >= 10 && this.canCreateInsight("hypothesis-generation")) {
1631
+ try {
1632
+ const patterns = [];
1633
+ const observations = [];
1634
+ if (newIssues.length > issues.length * 0.3) {
1635
+ observations.push(`High new issue rate: ${newIssues.length} new out of ${issues.length} total`);
1636
+ }
1637
+ const fileFreq = {};
1638
+ for (const issue of issues) {
1639
+ fileFreq[issue.file] = (fileFreq[issue.file] || 0) + 1;
1640
+ }
1641
+ const hotFiles = Object.entries(fileFreq).filter(([, count]) => count >= 3);
1642
+ if (hotFiles.length > 0) {
1643
+ patterns.push(`Hotspot files: ${hotFiles.map(([f]) => basename2(f)).join(", ")}`);
1644
+ }
1645
+ const generated = await this.hypothesisEngine.generateHypothesesWithAI({
1646
+ recentIssues: issues.map((i) => ({ issue: i, score: 1 })),
1647
+ patterns,
1648
+ observations
1649
+ });
1650
+ for (const hypothesis of generated) {
1651
+ const insight = this.createInsight({
1652
+ type: "observation",
1653
+ message: `${this.pick(PERSONALITY.questions)} New hypothesis to test: "${hypothesis.statement}"`,
1654
+ context: `Confidence: ${Math.round(hypothesis.confidence * 100)}%`,
1655
+ suggestedAction: `Monitor this pattern over time`,
1656
+ priority: 4,
1657
+ category: "pattern",
1658
+ details: {
1659
+ hypothesis: hypothesis.statement,
1660
+ testCriteria: hypothesis.testCriteria || "Collecting evidence...",
1661
+ confidence: Math.round(hypothesis.confidence * 100)
1662
+ }
1663
+ });
1664
+ newInsights.push(insight);
1665
+ await this.addInsight(insight);
1666
+ }
1667
+ if (generated.length > 0) {
1668
+ await this.markInsightCreated("hypothesis-generation");
1669
+ }
1670
+ } catch (error) {
1671
+ }
1672
+ }
1673
+ if (issues.length >= 5 && this.canCreateInsight("pattern-discovery")) {
1674
+ try {
1675
+ const { IncidentIndex } = await import("./incident-index-PNIVT47T.js");
1676
+ const { TriePatternDiscovery } = await import("./pattern-discovery-F7LU5K6E.js");
1677
+ const { ContextGraph: ContextGraph2 } = await import("./graph-U5JWSAB5.js");
1678
+ const graph = new ContextGraph2(this.projectPath);
1679
+ const incidentIndex = await IncidentIndex.build(graph, this.projectPath);
1680
+ const discovery = new TriePatternDiscovery(graph, incidentIndex);
1681
+ const hotPatterns = discovery.discoverHotPatterns(2);
1682
+ let patternsAdded = 0;
1683
+ for (const hot of hotPatterns.slice(0, 5)) {
1684
+ const existingPatterns = await graph.listNodes();
1685
+ const alreadyExists = existingPatterns.some(
1686
+ (n) => n.type === "pattern" && n.data.description?.includes(hot.path)
1687
+ );
1688
+ if (!alreadyExists) {
1689
+ await graph.addNode("pattern", {
1690
+ description: `${hot.type === "directory" ? "Directory" : "File"} hot zone: ${hot.path}`,
1691
+ appliesTo: [hot.path],
1692
+ confidence: Math.min(0.95, hot.confidence),
1693
+ occurrences: hot.incidentCount,
1694
+ firstSeen: (/* @__PURE__ */ new Date()).toISOString(),
1695
+ lastSeen: (/* @__PURE__ */ new Date()).toISOString(),
1696
+ isAntiPattern: hot.incidentCount >= 3,
1697
+ source: "local"
1698
+ });
1699
+ patternsAdded++;
1700
+ }
1701
+ }
1702
+ if (patternsAdded > 0) {
1703
+ const insight = this.createInsight({
1704
+ type: "observation",
1705
+ message: `${this.pick(PERSONALITY.greetings)} Discovered ${patternsAdded} pattern${patternsAdded > 1 ? "s" : ""} in your codebase.`,
1706
+ suggestedAction: `Check Memory \u2192 Learned Patterns to see`,
1707
+ priority: 5,
1708
+ category: "pattern",
1709
+ details: {
1710
+ patternsCount: patternsAdded,
1711
+ topPattern: hotPatterns[0]?.path
1712
+ }
1713
+ });
1714
+ newInsights.push(insight);
1715
+ await this.addInsight(insight);
1716
+ await this.markInsightCreated("pattern-discovery");
1717
+ }
1718
+ } catch (error) {
1719
+ }
1720
+ }
2167
1721
  if (this.canCreateInsight("pattern-suggestion")) {
2168
1722
  try {
2169
1723
  const globalPatterns = await findCrossProjectPatterns();
@@ -2356,7 +1910,7 @@ var GuardianAgent = class {
2356
1910
  await this.guardianState.recordScan();
2357
1911
  try {
2358
1912
  const riskLevel = issues.filter((i) => i.severity === "critical").length > 0 ? "critical" : issues.filter((i) => i.severity === "serious").length >= 3 ? "high" : issues.length > 10 ? "medium" : "low";
2359
- const { calculateAdaptiveScanFrequency } = await import("./goal-manager-AP4LTE6U.js");
1913
+ const { calculateAdaptiveScanFrequency } = await import("./goal-manager-LMS6ZJB7.js");
2360
1914
  const result = await calculateAdaptiveScanFrequency(riskLevel);
2361
1915
  await this.guardianState.setScanFrequency(result.frequencyMs);
2362
1916
  } catch {
@@ -2589,4 +2143,4 @@ export {
2589
2143
  GuardianAgent,
2590
2144
  getGuardian
2591
2145
  };
2592
- //# sourceMappingURL=chunk-SDS3UVFY.js.map
2146
+ //# sourceMappingURL=chunk-AOFYU6T3.js.map