@hiveai/core 0.13.8 → 0.14.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/dist/index.d.ts CHANGED
@@ -566,6 +566,57 @@ interface ImpactSummary {
566
566
  /** Roll up a set of impact scores into tier counts. */
567
567
  declare function summarizeImpact(scores: ImpactScore[]): ImpactSummary;
568
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
+
612
+ /** How long an emitted project context is considered "still fresh in the agent's context". */
613
+ declare const PROJECT_CONTEXT_THROTTLE_MS: number;
614
+ declare function hashProjectContext(content: string): string;
615
+ /** True if an identical project-context body was already emitted within the throttle window. */
616
+ declare function projectContextRecentlyEmitted(paths: HaivePaths, hash: string, now?: number): Promise<boolean>;
617
+ /** Record that this exact project-context body was just emitted. Best-effort. */
618
+ declare function recordProjectContextEmission(paths: HaivePaths, hash: string, now?: number): Promise<void>;
619
+
569
620
  /**
570
621
  * A rigorous, model-free, repeatable evaluation of hAIve's core promise: surfacing
571
622
  * the right knowledge and guardrails at the right moment. Unlike the agent benchmark
@@ -1059,6 +1110,14 @@ interface HaiveConfig {
1059
1110
  mode?: "off" | "advisory" | "strict";
1060
1111
  /** Require get_briefing / mem_relevant_to before state-changing MCP tools. */
1061
1112
  requireBriefingFirst?: boolean;
1113
+ /**
1114
+ * Pre-edit (PreToolUse) behaviour when a file's anchored policy was not yet surfaced:
1115
+ * - "advise" (default): inject the relevant memory content into the agent's context and record
1116
+ * it in the briefing marker, then ALLOW the edit — no round-trip, no separate briefing command.
1117
+ * - "block": hard-block the edit until a briefing covers the file (the legacy strict behaviour).
1118
+ * The commit-time decision-coverage gate and CI enforcement remain the hard backstops either way.
1119
+ */
1120
+ preEditGate?: "advise" | "block";
1062
1121
  /** Require a session recap before pre-push / CI gates pass. */
1063
1122
  requireSessionRecap?: boolean;
1064
1123
  /** Require memory anchor verification before pre-commit / CI gates pass. */
@@ -1597,6 +1656,8 @@ interface DashboardOptions {
1597
1656
  /** Dormancy window for impact scoring. Defaults to impact's own default. */
1598
1657
  dormantDays?: number;
1599
1658
  now?: Date;
1659
+ /** Prevention event log (from `loadPreventionEvents`) — powers the trend + recurrence rollups. */
1660
+ preventionEvents?: PreventionEvent[];
1600
1661
  }
1601
1662
  interface ImpactRow {
1602
1663
  id: string;
@@ -1658,12 +1719,16 @@ interface DashboardReport {
1658
1719
  decaying: number;
1659
1720
  top_dormant: DormantRow[];
1660
1721
  };
1661
- /** OUTCOME measurement: prevention events = times a memory's sensor fired on a real diff,
1662
- * intercepting a known mistake. Distinct from retrieval (reads) — demonstrated value. */
1722
+ /** OUTCOME measurement: prevention events = times a memory's sensor/anti-pattern fired on a real
1723
+ * diff, intercepting a known mistake. Distinct from retrieval (reads) — demonstrated value. */
1663
1724
  prevention: {
1664
1725
  total_events: number;
1665
1726
  memories_with_catches: number;
1666
1727
  top: PreventionRow[];
1728
+ /** Catch volume over time (from the prevention event log). */
1729
+ trend: PreventionTrend;
1730
+ /** Lessons re-introduced after capture (caught on >= 2 distinct days). */
1731
+ recurrence: RecurrenceReport;
1667
1732
  };
1668
1733
  corpus: {
1669
1734
  /** Number of memory files (policy corpus, excludes session_recap). */
@@ -1676,4 +1741,4 @@ interface DashboardReport {
1676
1741
  /** Build the full observability rollup from the loaded corpus + usage index. Pure. */
1677
1742
  declare function buildDashboard(memories: LoadedMemory[], usage: UsageIndex, options?: DashboardOptions): DashboardReport;
1678
1743
 
1679
- 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 PreventionRow, 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, 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 };
1744
+ 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, PROJECT_CONTEXT_THROTTLE_MS, 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, hashProjectContext, 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, projectContextRecentlyEmitted, pullCrossRepoSources, queryCodeMap, rankMemoriesLexical, readRecentBriefingMarker, readRuntimeJournalTail, readUsageEvents, recordApplied, recordPrevention, recordProjectContextEmission, 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 };