@hiveai/core 0.13.7 → 0.13.9

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/dist/index.d.ts CHANGED
@@ -469,6 +469,14 @@ interface MemoryUsage {
469
469
  */
470
470
  applied_count: number;
471
471
  last_applied_at: string | null;
472
+ /**
473
+ * Number of *prevention* events — times this memory's sensor actually fired on a scanned diff,
474
+ * intercepting a known mistake before it landed. This is an OUTCOME signal (defect prevented),
475
+ * the closest proxy hAIve has to "did the knowledge stop a real problem?", distinct from
476
+ * retrieval (read) and self-reported usefulness (applied). Recorded by `haive sensors check`.
477
+ */
478
+ prevented_count: number;
479
+ last_prevented_at: string | null;
472
480
  }
473
481
  interface UsageIndex {
474
482
  version: 1;
@@ -490,6 +498,15 @@ declare function recordRejection(index: UsageIndex, id: string, reason: string |
490
498
  * a memory that merely got surfaced from one that demonstrably steered work.
491
499
  */
492
500
  declare function recordApplied(index: UsageIndex, id: string): UsageIndex;
501
+ /** Debounce window so re-scanning the same diff within a few minutes doesn't inflate prevention
502
+ * counts (a pre-commit hook can run the check several times for one commit). */
503
+ declare const PREVENTION_DEBOUNCE_MS: number;
504
+ /**
505
+ * Record a *prevention* event: a memory's sensor fired on a scanned diff, intercepting a known
506
+ * mistake before it landed. Outcome signal (defect prevented), stronger than a read. Debounced by
507
+ * {@link PREVENTION_DEBOUNCE_MS}. Returns true if a NEW event was recorded (false if debounced).
508
+ */
509
+ declare function recordPrevention(index: UsageIndex, id: string, now?: number): boolean;
493
510
  declare const DECAY_DAYS = 90;
494
511
  declare function isDecaying(usage: MemoryUsage, createdAt: string): boolean;
495
512
  declare function trackReads(paths: HaivePaths, ids: string[]): Promise<UsageIndex>;
@@ -549,6 +566,49 @@ interface ImpactSummary {
549
566
  /** Roll up a set of impact scores into tier counts. */
550
567
  declare function summarizeImpact(scores: ImpactScore[]): ImpactSummary;
551
568
 
569
+ type PreventionSource = "sensor" | "anti-pattern";
570
+ interface PreventionEvent {
571
+ /** ISO timestamp of the catch. */
572
+ at: string;
573
+ /** Memory id whose lesson fired. */
574
+ id: string;
575
+ /** Which gate path recorded it. */
576
+ source: PreventionSource;
577
+ }
578
+ declare function preventionLogPath(paths: HaivePaths): string;
579
+ /** Append one catch to the log. Best-effort, creates the dir on demand. */
580
+ declare function appendPreventionEvent(paths: HaivePaths, event: PreventionEvent): Promise<void>;
581
+ /** Read all catch events (skips malformed lines). */
582
+ declare function loadPreventionEvents(paths: HaivePaths): Promise<PreventionEvent[]>;
583
+ interface PreventionTrend {
584
+ /** Catches in the last 7 days. */
585
+ last_7d: number;
586
+ /** Catches in the last 30 days. */
587
+ last_30d: number;
588
+ /** Catch counts per ISO week, oldest → newest, for the last N weeks (default 6). */
589
+ weekly: number[];
590
+ }
591
+ declare function computePreventionTrend(events: PreventionEvent[], now?: Date, weeks?: number): PreventionTrend;
592
+ interface RecurrenceRow {
593
+ id: string;
594
+ /** Total catches for this memory. */
595
+ catches: number;
596
+ /** Number of distinct UTC days the lesson fired — the recurrence signal. */
597
+ distinct_days: number;
598
+ last_at: string;
599
+ }
600
+ interface RecurrenceReport {
601
+ /**
602
+ * Memories whose lesson was caught on >= 2 distinct days — i.e. the mistake was RE-INTRODUCED
603
+ * after it had already been captured and caught once. A high count means a recurring problem the
604
+ * team keeps reintroducing (the guardrail is earning its keep, and the root cause may need a
605
+ * stronger fix than a memory).
606
+ */
607
+ recurring_count: number;
608
+ top: RecurrenceRow[];
609
+ }
610
+ declare function computeRecurrence(events: PreventionEvent[]): RecurrenceReport;
611
+
552
612
  /**
553
613
  * A rigorous, model-free, repeatable evaluation of hAIve's core promise: surfacing
554
614
  * the right knowledge and guardrails at the right moment. Unlike the agent benchmark
@@ -1580,6 +1640,8 @@ interface DashboardOptions {
1580
1640
  /** Dormancy window for impact scoring. Defaults to impact's own default. */
1581
1641
  dormantDays?: number;
1582
1642
  now?: Date;
1643
+ /** Prevention event log (from `loadPreventionEvents`) — powers the trend + recurrence rollups. */
1644
+ preventionEvents?: PreventionEvent[];
1583
1645
  }
1584
1646
  interface ImpactRow {
1585
1647
  id: string;
@@ -1598,6 +1660,12 @@ interface DormantRow {
1598
1660
  last_read_at: string | null;
1599
1661
  age_days: number;
1600
1662
  }
1663
+ interface PreventionRow {
1664
+ id: string;
1665
+ type: string;
1666
+ prevented_count: number;
1667
+ last_prevented_at: string | null;
1668
+ }
1601
1669
  interface DashboardReport {
1602
1670
  generated_at: string;
1603
1671
  inventory: {
@@ -1635,6 +1703,17 @@ interface DashboardReport {
1635
1703
  decaying: number;
1636
1704
  top_dormant: DormantRow[];
1637
1705
  };
1706
+ /** OUTCOME measurement: prevention events = times a memory's sensor/anti-pattern fired on a real
1707
+ * diff, intercepting a known mistake. Distinct from retrieval (reads) — demonstrated value. */
1708
+ prevention: {
1709
+ total_events: number;
1710
+ memories_with_catches: number;
1711
+ top: PreventionRow[];
1712
+ /** Catch volume over time (from the prevention event log). */
1713
+ trend: PreventionTrend;
1714
+ /** Lessons re-introduced after capture (caught on >= 2 distinct days). */
1715
+ recurrence: RecurrenceReport;
1716
+ };
1638
1717
  corpus: {
1639
1718
  /** Number of memory files (policy corpus, excludes session_recap). */
1640
1719
  memory_files: number;
@@ -1646,4 +1725,4 @@ interface DashboardReport {
1646
1725
  /** Build the full observability rollup from the loaded corpus + usage index. Pure. */
1647
1726
  declare function buildDashboard(memories: LoadedMemory[], usage: UsageIndex, options?: DashboardOptions): DashboardReport;
1648
1727
 
1649
- export { AUTOPILOT_DEFAULTS, type Activation, type ActivationContext, ActivationSchema, type Anchor, AnchorSchema, type AntiPatternGate, type AutoPromoteRule, BRIEFING_MARKER_TTL_MS, BRIEFING_PRESET_DEFAULTS, type BreakingChange, type BriefingBudgetNumbers, type BriefingBudgetPreset, type BriefingMarker, type BudgetPart, type BudgetSlice, type BuildCodeMapOptions, CHARS_PER_TOKEN, CODE_MAP_FILE, CODE_STOPWORDS, CONFIG_FILE, type CodeExport, type CodeExportKind, type CodeFileEntry, type CodeMap, type CodeMapQueryOptions, type CollectTimelineOpts, type ConfidenceLevel, type ConfidenceThresholds, type ConflictCandidatePair, type ConflictCandidatesOpts, type ContractDiffResult, type ContractFile, type ContractSnapshot, CrossRepoProvenanceSchema, type CrossRepoReport, type CrossRepoSource, DECAY_DAYS, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_CONFIDENCE_THRESHOLDS, DEFAULT_CONFIG, DEFAULT_DORMANT_DAYS, type DashboardOptions, type DashboardReport, type DepChange, type DepTrackResult, type DependencySnapshot, type DocFrequency, type DormantRow, type DraftOptions, type DraftsOptions, type EvalDelta, type EvalReport, type EvalSpec, type Finding, type FindingSeverity, GUESSABLE_THRESHOLD, HAIVE_DIR, type HaiveConfig, type HaivePaths, type ImpactOptions, type ImpactRow, type ImpactScore, type ImpactSummary, type ImpactTier, type LexicalRankResult, type LoadedMemory, MEMORIES_DIR, MIN_WORD_LEN, type Memory, type MemoryDraft, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, type MetricDelta, PROJECT_CONTEXT_FILE, RUNTIME_JOURNAL_FILENAME, type ResolveProjectInfo, type RetirementSignal, type RetrievalAggregate, type RetrievalCase, type RetrievalCaseResult, type RuntimeJournalEntry, SESSION_RECAP_TTL_MS, STACK_PACK_TAG, type SelfEvalOptions, type Sensor, type SensorAggregate, type SensorCase, type SensorCaseResult, type SensorHit, type SensorRow, SensorSchema, type SensorSuggestionOptions, type SensorTarget, type SkillActivation, type TimelineEntry, type TopicStatusPair, type TruncateOptions, type TruncateResult, USAGE_FILE, USAGE_LOG_DIR, USAGE_LOG_FILE, type UsageAggregate, type UsageEvent, type UsageIndex, type VerifyOptions, type VerifyResult, addedLinesFromDiff, aggregateRetrieval, aggregateSensors, aggregateUsage, allocateBudget, antiPatternGateParams, appendRuntimeJournalEntry, appendUsageEvent, briefingMarkerPath, briefingMarkersDir, buildCodeMap, buildDashboard, buildDocFrequency, buildFrontmatter, buildReport, bumpRead, codeMapPath, collectTimelineEntries, compareEvalReports, compareImpact, compileRegexSensor, computeImpact, configPath, contractLockPath, deriveConfidence, diffContract, diffHasDistinctiveOverlap, distinctiveCap, draftsFromFindings, emptyUsage, emptyUsageIndex, enforcementDir, estimateTokens, evaluateSkillActivation, extractActionsBriefBody, extractSnippet, filterNewDrafts, findLexicalConflictPairs, findProjectRoot, findTopicStatusConflictPairs, findingBody, findingToDraft, firstMemoryOneLine, getUsage, globToRegExp, hasRecentBriefingMarker, inferModulesFromPaths, isAutoPromoteEligible, isDecaying, isDistinctiveToken, isFreshIsoDate, isGlobPath, isLikelyGuessable, isRetiredMemory, isSkill, isSkillSuppressed, isStackPackSeed, listMarkdownFilesRecursive, literalMatchesAllTokens, literalMatchesAnyToken, loadCodeMap, loadConfig, loadConfigSync, loadMemoriesFromDir, loadMemory, loadUsageIndex, memoryFilePath, memoryMatchesAnchorPaths, newMemoryId, normalizeFindingSeverity, normalizeSessionId, overallScore, parseFindings, parseMemory, parseSarif, parseSince, parseSonar, pathsOverlap, pickSnippetNeedle, pullCrossRepoSources, queryCodeMap, rankMemoriesLexical, readRecentBriefingMarker, readRuntimeJournalTail, readUsageEvents, recordApplied, recordRejection, relPathFrom, resolveBriefingBudget, resolveHaivePaths, resolveManifestFiles, resolveProjectInfo, retirementSignal, runRegexSensor, runSensors, runtimeJournalPath, saveCodeMap, saveConfig, saveUsageIndex, scoreRetrievalCase, scoreSensorCase, sensorAppliesToPath, sensorTargetsFromDiff, serializeMemory, snapshotContract, specificityScore, stripPrivate, suggestSensorFromMemory, suggestTopicKey, summarizeImpact, synthesizeSelfEvalCases, titleFromBody, tokenizeQuery, tokenizeWords, trackDependencies, trackReads, truncateToTokens, usageLogPath, usageLogSize, usagePath, verifyAnchor, watchContracts, writeBriefingMarker };
1728
+ export { AUTOPILOT_DEFAULTS, type Activation, type ActivationContext, ActivationSchema, type Anchor, AnchorSchema, type AntiPatternGate, type AutoPromoteRule, BRIEFING_MARKER_TTL_MS, BRIEFING_PRESET_DEFAULTS, type BreakingChange, type BriefingBudgetNumbers, type BriefingBudgetPreset, type BriefingMarker, type BudgetPart, type BudgetSlice, type BuildCodeMapOptions, CHARS_PER_TOKEN, CODE_MAP_FILE, CODE_STOPWORDS, CONFIG_FILE, type CodeExport, type CodeExportKind, type CodeFileEntry, type CodeMap, type CodeMapQueryOptions, type CollectTimelineOpts, type ConfidenceLevel, type ConfidenceThresholds, type ConflictCandidatePair, type ConflictCandidatesOpts, type ContractDiffResult, type ContractFile, type ContractSnapshot, CrossRepoProvenanceSchema, type CrossRepoReport, type CrossRepoSource, DECAY_DAYS, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_CONFIDENCE_THRESHOLDS, DEFAULT_CONFIG, DEFAULT_DORMANT_DAYS, type DashboardOptions, type DashboardReport, type DepChange, type DepTrackResult, type DependencySnapshot, type DocFrequency, type DormantRow, type DraftOptions, type DraftsOptions, type EvalDelta, type EvalReport, type EvalSpec, type Finding, type FindingSeverity, GUESSABLE_THRESHOLD, HAIVE_DIR, type HaiveConfig, type HaivePaths, type ImpactOptions, type ImpactRow, type ImpactScore, type ImpactSummary, type ImpactTier, type LexicalRankResult, type LoadedMemory, MEMORIES_DIR, MIN_WORD_LEN, type Memory, type MemoryDraft, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, type MetricDelta, PREVENTION_DEBOUNCE_MS, PROJECT_CONTEXT_FILE, type PreventionEvent, type PreventionRow, type PreventionSource, type PreventionTrend, RUNTIME_JOURNAL_FILENAME, type RecurrenceReport, type RecurrenceRow, type ResolveProjectInfo, type RetirementSignal, type RetrievalAggregate, type RetrievalCase, type RetrievalCaseResult, type RuntimeJournalEntry, SESSION_RECAP_TTL_MS, STACK_PACK_TAG, type SelfEvalOptions, type Sensor, type SensorAggregate, type SensorCase, type SensorCaseResult, type SensorHit, type SensorRow, SensorSchema, type SensorSuggestionOptions, type SensorTarget, type SkillActivation, type TimelineEntry, type TopicStatusPair, type TruncateOptions, type TruncateResult, USAGE_FILE, USAGE_LOG_DIR, USAGE_LOG_FILE, type UsageAggregate, type UsageEvent, type UsageIndex, type VerifyOptions, type VerifyResult, addedLinesFromDiff, aggregateRetrieval, aggregateSensors, aggregateUsage, allocateBudget, antiPatternGateParams, appendPreventionEvent, appendRuntimeJournalEntry, appendUsageEvent, briefingMarkerPath, briefingMarkersDir, buildCodeMap, buildDashboard, buildDocFrequency, buildFrontmatter, buildReport, bumpRead, codeMapPath, collectTimelineEntries, compareEvalReports, compareImpact, compileRegexSensor, computeImpact, computePreventionTrend, computeRecurrence, configPath, contractLockPath, deriveConfidence, diffContract, diffHasDistinctiveOverlap, distinctiveCap, draftsFromFindings, emptyUsage, emptyUsageIndex, enforcementDir, estimateTokens, evaluateSkillActivation, extractActionsBriefBody, extractSnippet, filterNewDrafts, findLexicalConflictPairs, findProjectRoot, findTopicStatusConflictPairs, findingBody, findingToDraft, firstMemoryOneLine, getUsage, globToRegExp, hasRecentBriefingMarker, inferModulesFromPaths, isAutoPromoteEligible, isDecaying, isDistinctiveToken, isFreshIsoDate, isGlobPath, isLikelyGuessable, isRetiredMemory, isSkill, isSkillSuppressed, isStackPackSeed, listMarkdownFilesRecursive, literalMatchesAllTokens, literalMatchesAnyToken, loadCodeMap, loadConfig, loadConfigSync, loadMemoriesFromDir, loadMemory, loadPreventionEvents, loadUsageIndex, memoryFilePath, memoryMatchesAnchorPaths, newMemoryId, normalizeFindingSeverity, normalizeSessionId, overallScore, parseFindings, parseMemory, parseSarif, parseSince, parseSonar, pathsOverlap, pickSnippetNeedle, preventionLogPath, pullCrossRepoSources, queryCodeMap, rankMemoriesLexical, readRecentBriefingMarker, readRuntimeJournalTail, readUsageEvents, recordApplied, recordPrevention, recordRejection, relPathFrom, resolveBriefingBudget, resolveHaivePaths, resolveManifestFiles, resolveProjectInfo, retirementSignal, runRegexSensor, runSensors, runtimeJournalPath, saveCodeMap, saveConfig, saveUsageIndex, scoreRetrievalCase, scoreSensorCase, sensorAppliesToPath, sensorTargetsFromDiff, serializeMemory, snapshotContract, specificityScore, stripPrivate, suggestSensorFromMemory, suggestTopicKey, summarizeImpact, synthesizeSelfEvalCases, titleFromBody, tokenizeQuery, tokenizeWords, trackDependencies, trackReads, truncateToTokens, usageLogPath, usageLogSize, usagePath, verifyAnchor, watchContracts, writeBriefingMarker };