@hiveai/core 0.13.5 → 0.13.8
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 +32 -2
- package/dist/index.js +40 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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>;
|
|
@@ -553,7 +570,7 @@ declare function summarizeImpact(scores: ImpactScore[]): ImpactSummary;
|
|
|
553
570
|
* A rigorous, model-free, repeatable evaluation of hAIve's core promise: surfacing
|
|
554
571
|
* the right knowledge and guardrails at the right moment. Unlike the agent benchmark
|
|
555
572
|
* (which parses human-written reports), this is deterministic and CI-runnable — it
|
|
556
|
-
* produces a
|
|
573
|
+
* produces a numeric quality score from labeled cases, so a regression in ranking or
|
|
557
574
|
* sensor coverage fails the build instead of silently degrading every agent session.
|
|
558
575
|
*
|
|
559
576
|
* Two case families:
|
|
@@ -1598,6 +1615,12 @@ interface DormantRow {
|
|
|
1598
1615
|
last_read_at: string | null;
|
|
1599
1616
|
age_days: number;
|
|
1600
1617
|
}
|
|
1618
|
+
interface PreventionRow {
|
|
1619
|
+
id: string;
|
|
1620
|
+
type: string;
|
|
1621
|
+
prevented_count: number;
|
|
1622
|
+
last_prevented_at: string | null;
|
|
1623
|
+
}
|
|
1601
1624
|
interface DashboardReport {
|
|
1602
1625
|
generated_at: string;
|
|
1603
1626
|
inventory: {
|
|
@@ -1635,6 +1658,13 @@ interface DashboardReport {
|
|
|
1635
1658
|
decaying: number;
|
|
1636
1659
|
top_dormant: DormantRow[];
|
|
1637
1660
|
};
|
|
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. */
|
|
1663
|
+
prevention: {
|
|
1664
|
+
total_events: number;
|
|
1665
|
+
memories_with_catches: number;
|
|
1666
|
+
top: PreventionRow[];
|
|
1667
|
+
};
|
|
1638
1668
|
corpus: {
|
|
1639
1669
|
/** Number of memory files (policy corpus, excludes session_recap). */
|
|
1640
1670
|
memory_files: number;
|
|
@@ -1646,4 +1676,4 @@ interface DashboardReport {
|
|
|
1646
1676
|
/** Build the full observability rollup from the loaded corpus + usage index. Pure. */
|
|
1647
1677
|
declare function buildDashboard(memories: LoadedMemory[], usage: UsageIndex, options?: DashboardOptions): DashboardReport;
|
|
1648
1678
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -596,7 +596,9 @@ function emptyUsage() {
|
|
|
596
596
|
last_rejected_at: null,
|
|
597
597
|
rejection_reason: null,
|
|
598
598
|
applied_count: 0,
|
|
599
|
-
last_applied_at: null
|
|
599
|
+
last_applied_at: null,
|
|
600
|
+
prevented_count: 0,
|
|
601
|
+
last_prevented_at: null
|
|
600
602
|
};
|
|
601
603
|
}
|
|
602
604
|
function normalizeUsage(stored) {
|
|
@@ -667,6 +669,21 @@ function recordApplied(index, id) {
|
|
|
667
669
|
};
|
|
668
670
|
return index;
|
|
669
671
|
}
|
|
672
|
+
var PREVENTION_DEBOUNCE_MS = 5 * 60 * 1e3;
|
|
673
|
+
function recordPrevention(index, id, now = Date.now()) {
|
|
674
|
+
const current = normalizeUsage(index.by_id[id]);
|
|
675
|
+
const last = current.last_prevented_at ? Date.parse(current.last_prevented_at) : 0;
|
|
676
|
+
if (Number.isFinite(last) && last > 0 && now - last < PREVENTION_DEBOUNCE_MS) {
|
|
677
|
+
index.by_id[id] = current;
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
index.by_id[id] = {
|
|
681
|
+
...current,
|
|
682
|
+
prevented_count: current.prevented_count + 1,
|
|
683
|
+
last_prevented_at: new Date(now).toISOString()
|
|
684
|
+
};
|
|
685
|
+
return true;
|
|
686
|
+
}
|
|
670
687
|
var DECAY_DAYS = 90;
|
|
671
688
|
function isDecaying(usage, createdAt) {
|
|
672
689
|
const threshold = Date.now() - DECAY_DAYS * 24 * 60 * 60 * 1e3;
|
|
@@ -710,7 +727,10 @@ function computeImpact(fm, usage, options = {}) {
|
|
|
710
727
|
raw += Math.min(1, usage.applied_count / 4) * 0.6;
|
|
711
728
|
signals.push(`applied ${usage.applied_count}\xD7`);
|
|
712
729
|
}
|
|
713
|
-
if (
|
|
730
|
+
if (usage.prevented_count > 0) {
|
|
731
|
+
raw += Math.min(1, usage.prevented_count / 3) * 0.6;
|
|
732
|
+
signals.push(`prevented ${usage.prevented_count}\xD7`);
|
|
733
|
+
} else if (hasSensorFired(fm)) {
|
|
714
734
|
raw += 0.25;
|
|
715
735
|
signals.push("sensor fired");
|
|
716
736
|
}
|
|
@@ -3294,6 +3314,8 @@ function buildDashboard(memories, usage, options = {}) {
|
|
|
3294
3314
|
let decaying = 0;
|
|
3295
3315
|
let bodyChars = 0;
|
|
3296
3316
|
const dormantRows = [];
|
|
3317
|
+
let preventionEvents = 0;
|
|
3318
|
+
const preventionRows = [];
|
|
3297
3319
|
for (const { memory } of memories) {
|
|
3298
3320
|
const fm = memory.frontmatter;
|
|
3299
3321
|
if (fm.type === "session_recap") {
|
|
@@ -3338,6 +3360,15 @@ function buildDashboard(memories, usage, options = {}) {
|
|
|
3338
3360
|
signals: impact.signals,
|
|
3339
3361
|
prune_candidate: impact.pruneCandidate
|
|
3340
3362
|
});
|
|
3363
|
+
if (memUsage.prevented_count > 0) {
|
|
3364
|
+
preventionEvents += memUsage.prevented_count;
|
|
3365
|
+
preventionRows.push({
|
|
3366
|
+
id: fm.id,
|
|
3367
|
+
type: fm.type,
|
|
3368
|
+
prevented_count: memUsage.prevented_count,
|
|
3369
|
+
last_prevented_at: memUsage.last_prevented_at
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3341
3372
|
if (isDecaying(memUsage, fm.created_at)) decaying += 1;
|
|
3342
3373
|
if (impact.tier === "dormant") {
|
|
3343
3374
|
const anchor = memUsage.last_read_at ?? fm.created_at;
|
|
@@ -3377,6 +3408,11 @@ function buildDashboard(memories, usage, options = {}) {
|
|
|
3377
3408
|
decaying,
|
|
3378
3409
|
top_dormant: dormantRows.slice(0, top)
|
|
3379
3410
|
},
|
|
3411
|
+
prevention: {
|
|
3412
|
+
total_events: preventionEvents,
|
|
3413
|
+
memories_with_catches: preventionRows.length,
|
|
3414
|
+
top: preventionRows.sort((a, b) => b.prevented_count - a.prevented_count).slice(0, top)
|
|
3415
|
+
},
|
|
3380
3416
|
corpus: {
|
|
3381
3417
|
memory_files: inventory.total,
|
|
3382
3418
|
body_chars: bodyChars,
|
|
@@ -3408,6 +3444,7 @@ export {
|
|
|
3408
3444
|
MemoryScopeSchema,
|
|
3409
3445
|
MemoryStatusSchema,
|
|
3410
3446
|
MemoryTypeSchema,
|
|
3447
|
+
PREVENTION_DEBOUNCE_MS,
|
|
3411
3448
|
PROJECT_CONTEXT_FILE,
|
|
3412
3449
|
RUNTIME_JOURNAL_FILENAME,
|
|
3413
3450
|
SESSION_RECAP_TTL_MS,
|
|
@@ -3502,6 +3539,7 @@ export {
|
|
|
3502
3539
|
readRuntimeJournalTail,
|
|
3503
3540
|
readUsageEvents,
|
|
3504
3541
|
recordApplied,
|
|
3542
|
+
recordPrevention,
|
|
3505
3543
|
recordRejection,
|
|
3506
3544
|
relPathFrom,
|
|
3507
3545
|
resolveBriefingBudget,
|