@hivelore/core 0.38.0 → 0.39.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
@@ -2006,6 +2006,26 @@ declare function isSensorScannablePath(p: string): boolean;
2006
2006
  * with bare content) — never when every header was a Hivelore-owned path, so `.ai/`-only diffs scan nothing.
2007
2007
  */
2008
2008
  declare function scannableSensorTargets(diff: string): SensorTarget[];
2009
+ interface SensorWeakening {
2010
+ /** The `.ai/memories/**` file whose sensor the diff weakens. */
2011
+ file: string;
2012
+ /** Memory id derived from the filename (best-effort). */
2013
+ memory_id: string;
2014
+ change: "severity-demoted" | "oracle-changed" | "oracle-removed" | "sensor-removed" | "memory-deleted" | "suppression-broadened";
2015
+ detail: string;
2016
+ }
2017
+ /**
2018
+ * Detect diff hunks that WEAKEN the enforcement surface: demoting a block sensor to warn, changing
2019
+ * or removing its oracle (`pattern`/`command`), broadening its `absent` suppression, deleting the
2020
+ * whole sensor block, or deleting a memory file that carried a block sensor.
2021
+ *
2022
+ * Rationale: the gate is written in `.ai/` — the same tree the agent it constrains can edit. A
2023
+ * legitimate demotion exists (that's why this yields REVIEW findings, never blocks), but a weakening
2024
+ * that sails through unmentioned is exactly how a documented lesson silently stops protecting.
2025
+ * Deterministic, pure, diff-text only. Additions (new sensors) never flag; removing `absent`
2026
+ * TIGHTENS a sensor and never flags.
2027
+ */
2028
+ declare function detectSensorWeakening(diff: string): SensorWeakening[];
2009
2029
  interface SensorSelfCheck {
2010
2030
  /** The sensor stays SILENT on the current, presumed-correct code — i.e. it won't false-positive. */
2011
2031
  silent_on_current: boolean;
@@ -2216,6 +2236,12 @@ interface ScaffoldOptions {
2216
2236
  * test path and run command are placed inside it. Empty/omitted → repo root.
2217
2237
  */
2218
2238
  baseDir?: string;
2239
+ /**
2240
+ * Override the propose command embedded in the header and returned. Used by multi-package
2241
+ * scaffolds: a memory carries ONE sensor, so several generated tests share a single proposal
2242
+ * whose command chains every run command.
2243
+ */
2244
+ proposeCommandOverride?: string;
2219
2245
  }
2220
2246
  /** Map a user-supplied framework string (with common aliases) to a TestFramework, or null. */
2221
2247
  declare function normalizeFramework(input: string): TestFramework | null;
@@ -2242,8 +2268,41 @@ declare function parseLessonFields(body: string): {
2242
2268
  whyFailed?: string;
2243
2269
  instead?: string;
2244
2270
  };
2271
+ /**
2272
+ * Build the `sensors propose --kind test` line that arms a written post-incident test as the
2273
+ * lesson's oracle. Exported so multi-package scaffolds can chain several run commands into ONE
2274
+ * proposal (a memory carries a single sensor).
2275
+ */
2276
+ declare function buildProposeCommand(lesson: PostIncidentLesson, runCommand: string): string;
2245
2277
  /** Build a scaffold for the given lesson + framework. Pure — the caller writes `content` to `relPath`. */
2246
2278
  declare function scaffoldPostIncidentTest(lesson: PostIncidentLesson, options: ScaffoldOptions): TestScaffold;
2279
+ /** First-line provenance marker every generated scaffold carries. */
2280
+ declare const SCAFFOLD_MARKER_RE: RegExp;
2281
+ interface ScaffoldLoopGap {
2282
+ /** Memory id the scaffold was generated from (parsed from the provenance marker). */
2283
+ memory_id: string;
2284
+ /** Project-relative path of the scaffold file. */
2285
+ path: string;
2286
+ /** The stub is still pending (todo/skip) — the assertion was never written. */
2287
+ pending: boolean;
2288
+ /** The lesson carries a validated shell/test sensor — the oracle is routed to the gate. */
2289
+ armed: boolean;
2290
+ /** The referenced memory no longer exists (scaffold orphaned). */
2291
+ memory_missing: boolean;
2292
+ }
2293
+ /**
2294
+ * Cross-check written post-incident scaffolds against the corpus: a scaffold whose assertion is
2295
+ * still pending, or whose lesson has no armed command sensor, is an OPEN behaviour loop — the
2296
+ * incident is documented but nothing deterministic guards it yet. Pure: callers collect the files.
2297
+ * Returns only the gaps (closed loops are silent).
2298
+ */
2299
+ declare function assessScaffoldLoop(files: Array<{
2300
+ path: string;
2301
+ content: string;
2302
+ }>, memories: Array<{
2303
+ id: string;
2304
+ sensorKind?: "regex" | "shell" | "test" | null;
2305
+ }>): ScaffoldLoopGap[];
2247
2306
 
2248
2307
  /**
2249
2308
  * First-agent bootstrap state — is the repo's knowledge layer filled enough for later agents to rely on?
@@ -3093,4 +3152,4 @@ interface AgentContext {
3093
3152
  }
3094
3153
  declare function detectAgentContext(env?: Record<string, string | undefined>): AgentContext;
3095
3154
 
3096
- export { AUTOPILOT_DEFAULTS, type Activation, type ActivationContext, ActivationSchema, type AgentContext, type Anchor, AnchorSchema, type AntiPatternGate, type AppliedConflictResolution, type AstExport, type AutoPromoteRule, BRIDGE_MARKERS, BRIDGE_TARGETS, BRIDGE_TARGET_PATH, BRIEFING_MARKER_TTL_MS, BRIEFING_PRESET_DEFAULTS, type BootstrapAssessment, type BootstrapGap, type BootstrapGate, type BootstrapMetrics, type BootstrapState, type BootstrapStateInput, type BreakingChange, type BridgeFileOutput, type BridgeMemoryEntry, type BridgeSensor, type BridgeTarget, type BriefingBudgetNumbers, type BriefingBudgetPreset, type BriefingMarker, type BriefingProofLineOptions, type BudgetPart, type BudgetSlice, type BuildCodeMapOptions, CHARS_PER_TOKEN, CODE_MAP_DEFAULT_EXCLUDE, CODE_MAP_DEFAULT_INCLUDE, CODE_MAP_FILE, CODE_STOPWORDS, CONFIG_FILE, type CaughtForYouOptions, type CaughtForYouRow, type CaughtForYouSummary, type CodeExport, type CodeExportKind, type CodeFileEntry, type CodeMap, type CodeMapQueryOptions, type CollectTimelineOpts, type CommandSensorSpec, type ConfidenceLevel, type ConfidenceThresholds, type ConflictCandidatePair, type ConflictCandidatesOpts, type ConflictResolution, type ContractDiffResult, type ContractFile, type ContractSnapshot, type CoverageGap, type CoverageOptions, CrossRepoProvenanceSchema, type CrossRepoReport, type CrossRepoSource, DECAY_DAYS, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_BRIEFING_EXCLUDE_TAGS, DEFAULT_CONFIDENCE_THRESHOLDS, DEFAULT_CONFIG, DEFAULT_DORMANT_DAYS, DEFAULT_PRIORITY_SIGNALS, type DashboardOptions, type DashboardReport, type DepChange, type DepTrackResult, type DependencySnapshot, type DetectStacksInput, type DetectableStack, type DocFrequency, type DormantRow, type DraftOptions, type DraftsOptions, ENV_WORKAROUND_TAGS, type EvalDelta, type EvalHistoryEntry, type EvalReport, type EvalSpec, type EvalTrend, type FailureCoverageOptions, type FailureObservation, type FeedbackAdjustment, type FeedbackAdjustmentAction, type FeedbackAdjustmentOptions, type Finding, type FindingFormat, type FindingSeverity, GUESSABLE_THRESHOLD, type GateMissProposal, type GatePrecision, type GatePrecisionDelta, type GatePrecisionMetricDelta, type GateTuningSuggestion, type GenerateBridgesOptions, type GitCommit, type GitWatchPlan, type GitWatchState, HAIVE_DIR, HAIVE_OWNED_FILES, HANDOFF_FILENAME, HIVELORE_ATTRIBUTION, type HaiveConfig, type HaivePaths, type HotFile, type HotFileSource, type ImpactOptions, type ImpactRow, type ImpactScore, type ImpactSummary, type ImpactTier, type InvalidMemoryFile, type LexicalRankResult, type LoadedMemory, MEMORIES_DIR, MIN_WORD_LEN, type Memory, type MemoryDraft, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryPriority, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, type MergeResult, type MetricDelta, PREVENTION_DEBOUNCE_MS, PROJECT_CONTEXT_FILE, PROJECT_CONTEXT_THROTTLE_MS, type PostIncidentLesson, type PreventionEvent, type PreventionEventDetail, type PreventionReceipt, type PreventionReceiptRow, type PreventionRow, type PreventionSource, type PreventionTrend, type PrioritySignals, type ProposedSensorVerdict, RUNTIME_JOURNAL_FILENAME, type RecurrenceReport, type RecurrenceRow, type ResolveProjectInfo, type RetirementSignal, type RetrievalAggregate, type RetrievalCase, type RetrievalCaseResult, type RuntimeJournalEntry, SEED_QUALITY_FLOOR, SENSOR_ABSENT_LOOKBACK, SENSOR_ABSENT_WINDOW, SESSION_RECAP_TTL_MS, STACK_PACK_TAG, type ScaffoldOptions, type SeedProposal, type SelfEvalOptions, type Sensor, type SensorAggregate, type SensorCase, type SensorCaseResult, type SensorEvaluation, type SensorEvaluationOutcome, type SensorEvaluationStage, type SensorFlap, type SensorHealth, type SensorHit, type SensorRow, SensorSchema, type SensorSeed, type SensorSelfCheck, type SensorSuggestionOptions, type SensorTarget, type SessionHandoffData, type SkillActivation, TEST_FRAMEWORKS, type TestFramework, type TestScaffold, type TimelineEntry, type TopicStatusPair, type TruncateOptions, type TruncateResult, USAGE_FILE, USAGE_LOG_DIR, USAGE_LOG_FILE, type UncapturedFailure, type UsageAggregate, type UsageEvent, type UsageIndex, type VerifyOptions, type VerifyResult, addedLinesFromDiff, aggregateRetrieval, aggregateSensors, aggregateUsage, allocateBudget, antiPatternGateParams, appendEvalHistory, appendPreventionEvent, appendRuntimeJournalEntry, appendSensorEvaluations, appendUsageEvent, applyConflictResolution, applyFeedbackAdjustment, assessBootstrapState, assessSensorHealth, bridgeMemorySummary, briefingMarkerPath, briefingMarkersDir, briefingProofLine, buildCodeMap, buildCoverageIndex, buildDashboard, buildDocFrequency, buildFrontmatter, buildHandoffMarkdown, buildPreventionReceipt, buildReport, bumpRead, classifyMemoryPriority, codeMapPath, collectTimelineEntries, compactAutoRecapBody, compareEvalReports, compareGatePrecision, compareImpact, compileRegexSensor, componentOf, computeEvalTrend, computeGatePrecision, computeImpact, computePreventionTrend, computeRecurrence, computeScopeHash, configPath, contractLockPath, countSourceFilesOnDisk, deriveConfidence, detectAgentContext, detectStacksFromManifests, diffContract, diffHasDistinctiveOverlap, distinctiveCap, draftsFromFindings, emptyUsage, emptyUsageIndex, enforcementDir, estimateTokens, evalHistoryPath, evaluateSkillActivation, existingGateMissShas, extractActionsBriefBody, extractReferencedPaths, extractSensorExamples, extractSnippet, filterNewDrafts, findCoverageGaps, findLexicalConflictPairs, findProjectRoot, findTopicStatusConflictPairs, findUncapturedFailures, findingBody, findingToDraft, firstMemoryOneLine, gatePassedShas, generateBridges, getUsage, globToRegExp, handoffAgeMs, handoffFilePath, hasRecentBriefingMarker, hashProjectContext, incidentSuffix, inferModulesFromPaths, isAutoPromoteEligible, isAutoRecap, isCovered, isDecaying, isDistinctiveToken, isEnvWorkaroundMemory, isFreshIsoDate, isGlobPath, isLikelyGuessable, isNoiseSubject, isRetiredMemory, isSensorScannablePath, isSkill, isSkillSuppressed, isStackPackSeed, isStylisticRule, isTemplateProjectContext, judgeProposedSensor, lessonShortName, listMarkdownFilesRecursive, literalMatchesAllTokens, literalMatchesAnyToken, loadCodeMap, loadConfig, loadConfigSync, loadEvalHistory, loadMemoriesFromDir, loadMemoriesFromDirDetailed, loadMemory, loadPreventionEvents, loadSensorLedger, loadUsageIndex, looksLikeGenericAdvice, meetsSeedQualityFloor, memoryFilePath, memoryHasExcludedTag, memoryMatchesAnchorPaths, mergeHotFiles, mergeMemoryVersions, moduleNameOf, newMemoryId, normalizeFindingSeverity, normalizeFramework, normalizeSessionId, overallScore, parseEslintJson, parseFileAst, parseFindings, parseLessonFields, parseMemory, parseNpmAudit, parseSarif, parseSince, parseSonar, pathsOverlap, pickSnippetNeedle, pickTestFramework, planConflictResolution, planGitWatch, prepareBridgeData, preventionLogPath, priorityRank, prioritySignals, projectContextRecentlyEmitted, proposeGateMissDrafts, proposeSeedsFromCommits, pullCrossRepoSources, quarantineNote, queryCodeMap, rankMemoriesLexical, readRecentBriefingMarker, readRuntimeJournalTail, readSessionHandoff, readUsageEvents, recommendFeedbackAdjustment, recordApplied, recordPrevention, recordPreventionHits, recordProjectContextEmission, recordRejection, relPathFrom, renderBootstrapChecklist, renderCaughtForYou, renderPreventionReceipt, renderPreventionReceiptShare, resolveBriefingBudget, resolveHaivePaths, resolveManifestFiles, resolveProjectInfo, retirementSignal, revertedShaFromCommit, runRegexSensor, runSensors, runtimeJournalPath, saveCodeMap, saveConfig, saveUsageIndex, scaffoldPostIncidentTest, scannableSensorTargets, scoreRetrievalCase, scoreSensorCase, selectCommandSensors, sensorAppliesToPath, sensorLedgerPath, sensorPatternBrittleness, sensorPromotedAtMap, sensorSelfCheck, sensorTargetsFromDiff, serializeMemory, snapshotContract, specificityScore, stripPrivate, suggestGate, suggestSensorFromMemory, suggestSensorSeed, suggestTopicKey, summarizeCaughtForYou, summarizeImpact, synthesizeSelfEvalCases, tallyHotFiles, titleFromBody, tokenizeQuery, tokenizeWords, trackDependencies, trackReads, truncateToTokens, usageLogPath, usageLogSize, usagePath, verifyAnchor, watchContracts, withQuarantineNote, withoutQuarantineNote, writeBriefingMarker, writeSessionHandoff };
3155
+ export { AUTOPILOT_DEFAULTS, type Activation, type ActivationContext, ActivationSchema, type AgentContext, type Anchor, AnchorSchema, type AntiPatternGate, type AppliedConflictResolution, type AstExport, type AutoPromoteRule, BRIDGE_MARKERS, BRIDGE_TARGETS, BRIDGE_TARGET_PATH, BRIEFING_MARKER_TTL_MS, BRIEFING_PRESET_DEFAULTS, type BootstrapAssessment, type BootstrapGap, type BootstrapGate, type BootstrapMetrics, type BootstrapState, type BootstrapStateInput, type BreakingChange, type BridgeFileOutput, type BridgeMemoryEntry, type BridgeSensor, type BridgeTarget, type BriefingBudgetNumbers, type BriefingBudgetPreset, type BriefingMarker, type BriefingProofLineOptions, type BudgetPart, type BudgetSlice, type BuildCodeMapOptions, CHARS_PER_TOKEN, CODE_MAP_DEFAULT_EXCLUDE, CODE_MAP_DEFAULT_INCLUDE, CODE_MAP_FILE, CODE_STOPWORDS, CONFIG_FILE, type CaughtForYouOptions, type CaughtForYouRow, type CaughtForYouSummary, type CodeExport, type CodeExportKind, type CodeFileEntry, type CodeMap, type CodeMapQueryOptions, type CollectTimelineOpts, type CommandSensorSpec, type ConfidenceLevel, type ConfidenceThresholds, type ConflictCandidatePair, type ConflictCandidatesOpts, type ConflictResolution, type ContractDiffResult, type ContractFile, type ContractSnapshot, type CoverageGap, type CoverageOptions, CrossRepoProvenanceSchema, type CrossRepoReport, type CrossRepoSource, DECAY_DAYS, DEFAULT_AUTO_PROMOTE_RULE, DEFAULT_BRIEFING_EXCLUDE_TAGS, DEFAULT_CONFIDENCE_THRESHOLDS, DEFAULT_CONFIG, DEFAULT_DORMANT_DAYS, DEFAULT_PRIORITY_SIGNALS, type DashboardOptions, type DashboardReport, type DepChange, type DepTrackResult, type DependencySnapshot, type DetectStacksInput, type DetectableStack, type DocFrequency, type DormantRow, type DraftOptions, type DraftsOptions, ENV_WORKAROUND_TAGS, type EvalDelta, type EvalHistoryEntry, type EvalReport, type EvalSpec, type EvalTrend, type FailureCoverageOptions, type FailureObservation, type FeedbackAdjustment, type FeedbackAdjustmentAction, type FeedbackAdjustmentOptions, type Finding, type FindingFormat, type FindingSeverity, GUESSABLE_THRESHOLD, type GateMissProposal, type GatePrecision, type GatePrecisionDelta, type GatePrecisionMetricDelta, type GateTuningSuggestion, type GenerateBridgesOptions, type GitCommit, type GitWatchPlan, type GitWatchState, HAIVE_DIR, HAIVE_OWNED_FILES, HANDOFF_FILENAME, HIVELORE_ATTRIBUTION, type HaiveConfig, type HaivePaths, type HotFile, type HotFileSource, type ImpactOptions, type ImpactRow, type ImpactScore, type ImpactSummary, type ImpactTier, type InvalidMemoryFile, type LexicalRankResult, type LoadedMemory, MEMORIES_DIR, MIN_WORD_LEN, type Memory, type MemoryDraft, type MemoryFrontmatter, MemoryFrontmatterSchema, type MemoryPriority, type MemoryScope, MemoryScopeSchema, type MemoryStatus, MemoryStatusSchema, type MemoryType, MemoryTypeSchema, type MemoryUsage, type MergeResult, type MetricDelta, PREVENTION_DEBOUNCE_MS, PROJECT_CONTEXT_FILE, PROJECT_CONTEXT_THROTTLE_MS, type PostIncidentLesson, type PreventionEvent, type PreventionEventDetail, type PreventionReceipt, type PreventionReceiptRow, type PreventionRow, type PreventionSource, type PreventionTrend, type PrioritySignals, type ProposedSensorVerdict, RUNTIME_JOURNAL_FILENAME, type RecurrenceReport, type RecurrenceRow, type ResolveProjectInfo, type RetirementSignal, type RetrievalAggregate, type RetrievalCase, type RetrievalCaseResult, type RuntimeJournalEntry, SCAFFOLD_MARKER_RE, SEED_QUALITY_FLOOR, SENSOR_ABSENT_LOOKBACK, SENSOR_ABSENT_WINDOW, SESSION_RECAP_TTL_MS, STACK_PACK_TAG, type ScaffoldLoopGap, type ScaffoldOptions, type SeedProposal, type SelfEvalOptions, type Sensor, type SensorAggregate, type SensorCase, type SensorCaseResult, type SensorEvaluation, type SensorEvaluationOutcome, type SensorEvaluationStage, type SensorFlap, type SensorHealth, type SensorHit, type SensorRow, SensorSchema, type SensorSeed, type SensorSelfCheck, type SensorSuggestionOptions, type SensorTarget, type SensorWeakening, type SessionHandoffData, type SkillActivation, TEST_FRAMEWORKS, type TestFramework, type TestScaffold, type TimelineEntry, type TopicStatusPair, type TruncateOptions, type TruncateResult, USAGE_FILE, USAGE_LOG_DIR, USAGE_LOG_FILE, type UncapturedFailure, type UsageAggregate, type UsageEvent, type UsageIndex, type VerifyOptions, type VerifyResult, addedLinesFromDiff, aggregateRetrieval, aggregateSensors, aggregateUsage, allocateBudget, antiPatternGateParams, appendEvalHistory, appendPreventionEvent, appendRuntimeJournalEntry, appendSensorEvaluations, appendUsageEvent, applyConflictResolution, applyFeedbackAdjustment, assessBootstrapState, assessScaffoldLoop, assessSensorHealth, bridgeMemorySummary, briefingMarkerPath, briefingMarkersDir, briefingProofLine, buildCodeMap, buildCoverageIndex, buildDashboard, buildDocFrequency, buildFrontmatter, buildHandoffMarkdown, buildPreventionReceipt, buildProposeCommand, buildReport, bumpRead, classifyMemoryPriority, codeMapPath, collectTimelineEntries, compactAutoRecapBody, compareEvalReports, compareGatePrecision, compareImpact, compileRegexSensor, componentOf, computeEvalTrend, computeGatePrecision, computeImpact, computePreventionTrend, computeRecurrence, computeScopeHash, configPath, contractLockPath, countSourceFilesOnDisk, deriveConfidence, detectAgentContext, detectSensorWeakening, detectStacksFromManifests, diffContract, diffHasDistinctiveOverlap, distinctiveCap, draftsFromFindings, emptyUsage, emptyUsageIndex, enforcementDir, estimateTokens, evalHistoryPath, evaluateSkillActivation, existingGateMissShas, extractActionsBriefBody, extractReferencedPaths, extractSensorExamples, extractSnippet, filterNewDrafts, findCoverageGaps, findLexicalConflictPairs, findProjectRoot, findTopicStatusConflictPairs, findUncapturedFailures, findingBody, findingToDraft, firstMemoryOneLine, gatePassedShas, generateBridges, getUsage, globToRegExp, handoffAgeMs, handoffFilePath, hasRecentBriefingMarker, hashProjectContext, incidentSuffix, inferModulesFromPaths, isAutoPromoteEligible, isAutoRecap, isCovered, isDecaying, isDistinctiveToken, isEnvWorkaroundMemory, isFreshIsoDate, isGlobPath, isLikelyGuessable, isNoiseSubject, isRetiredMemory, isSensorScannablePath, isSkill, isSkillSuppressed, isStackPackSeed, isStylisticRule, isTemplateProjectContext, judgeProposedSensor, lessonShortName, listMarkdownFilesRecursive, literalMatchesAllTokens, literalMatchesAnyToken, loadCodeMap, loadConfig, loadConfigSync, loadEvalHistory, loadMemoriesFromDir, loadMemoriesFromDirDetailed, loadMemory, loadPreventionEvents, loadSensorLedger, loadUsageIndex, looksLikeGenericAdvice, meetsSeedQualityFloor, memoryFilePath, memoryHasExcludedTag, memoryMatchesAnchorPaths, mergeHotFiles, mergeMemoryVersions, moduleNameOf, newMemoryId, normalizeFindingSeverity, normalizeFramework, normalizeSessionId, overallScore, parseEslintJson, parseFileAst, parseFindings, parseLessonFields, parseMemory, parseNpmAudit, parseSarif, parseSince, parseSonar, pathsOverlap, pickSnippetNeedle, pickTestFramework, planConflictResolution, planGitWatch, prepareBridgeData, preventionLogPath, priorityRank, prioritySignals, projectContextRecentlyEmitted, proposeGateMissDrafts, proposeSeedsFromCommits, pullCrossRepoSources, quarantineNote, queryCodeMap, rankMemoriesLexical, readRecentBriefingMarker, readRuntimeJournalTail, readSessionHandoff, readUsageEvents, recommendFeedbackAdjustment, recordApplied, recordPrevention, recordPreventionHits, recordProjectContextEmission, recordRejection, relPathFrom, renderBootstrapChecklist, renderCaughtForYou, renderPreventionReceipt, renderPreventionReceiptShare, resolveBriefingBudget, resolveHaivePaths, resolveManifestFiles, resolveProjectInfo, retirementSignal, revertedShaFromCommit, runRegexSensor, runSensors, runtimeJournalPath, saveCodeMap, saveConfig, saveUsageIndex, scaffoldPostIncidentTest, scannableSensorTargets, scoreRetrievalCase, scoreSensorCase, selectCommandSensors, sensorAppliesToPath, sensorLedgerPath, sensorPatternBrittleness, sensorPromotedAtMap, sensorSelfCheck, sensorTargetsFromDiff, serializeMemory, snapshotContract, specificityScore, stripPrivate, suggestGate, suggestSensorFromMemory, suggestSensorSeed, suggestTopicKey, summarizeCaughtForYou, summarizeImpact, synthesizeSelfEvalCases, tallyHotFiles, titleFromBody, tokenizeQuery, tokenizeWords, trackDependencies, trackReads, truncateToTokens, usageLogPath, usageLogSize, usagePath, verifyAnchor, watchContracts, withQuarantineNote, withoutQuarantineNote, writeBriefingMarker, writeSessionHandoff };
package/dist/index.js CHANGED
@@ -4035,6 +4035,79 @@ function scannableSensorTargets(diff) {
4035
4035
  if (all.length === 0) return [{ path: "", content: diff }];
4036
4036
  return all.filter((t) => isSensorScannablePath(t.path));
4037
4037
  }
4038
+ function diffFileChanges(diff) {
4039
+ const files = [];
4040
+ let current = null;
4041
+ let oldPath = null;
4042
+ for (const line of diff.split("\n")) {
4043
+ if (line.startsWith("--- ")) {
4044
+ const raw = line.slice(4).trim();
4045
+ oldPath = raw === "/dev/null" ? null : normalizeProjectPath(raw);
4046
+ continue;
4047
+ }
4048
+ if (line.startsWith("+++ ")) {
4049
+ const raw = line.slice(4).trim();
4050
+ const newPath = raw === "/dev/null" ? null : normalizeProjectPath(raw);
4051
+ current = {
4052
+ path: newPath ?? oldPath ?? "",
4053
+ deleted: newPath === null,
4054
+ removed: [],
4055
+ added: []
4056
+ };
4057
+ files.push(current);
4058
+ continue;
4059
+ }
4060
+ if (!current) continue;
4061
+ if (line.startsWith("-") && !line.startsWith("---")) current.removed.push(line.slice(1));
4062
+ else if (line.startsWith("+") && !line.startsWith("+++")) current.added.push(line.slice(1));
4063
+ }
4064
+ return files;
4065
+ }
4066
+ var SENSOR_ORACLE_KEY_RE = /^\s*(pattern|command):\s*(.*)$/;
4067
+ var SENSOR_ABSENT_KEY_RE = /^\s*absent:\s*(.*)$/;
4068
+ var SEVERITY_BLOCK_RE = /^\s*severity:\s*['"]?block['"]?\s*$/;
4069
+ var SEVERITY_WARN_RE = /^\s*severity:\s*['"]?warn['"]?\s*$/;
4070
+ var SENSOR_BLOCK_START_RE = /^\s*sensor:\s*$/;
4071
+ function detectSensorWeakening(diff) {
4072
+ const weakenings = [];
4073
+ for (const file of diffFileChanges(diff)) {
4074
+ if (!file.path.startsWith(".ai/memories/") || !file.path.endsWith(".md")) continue;
4075
+ const memoryId = file.path.replace(/^.*\//, "").replace(/\.md$/, "");
4076
+ const flag = (change, detail) => {
4077
+ weakenings.push({ file: file.path, memory_id: memoryId, change, detail });
4078
+ };
4079
+ const removedBlockSeverity = file.removed.some((l) => SEVERITY_BLOCK_RE.test(l));
4080
+ if (file.deleted) {
4081
+ if (file.removed.some((l) => SENSOR_BLOCK_START_RE.test(l)) && removedBlockSeverity) {
4082
+ flag("memory-deleted", "memory file with a block sensor deleted");
4083
+ }
4084
+ continue;
4085
+ }
4086
+ if (removedBlockSeverity && file.added.some((l) => SEVERITY_WARN_RE.test(l))) {
4087
+ flag("severity-demoted", "severity: block \u2192 warn");
4088
+ }
4089
+ for (const line of file.removed) {
4090
+ const m = line.match(SENSOR_ORACLE_KEY_RE);
4091
+ if (!m) continue;
4092
+ const key = m[1];
4093
+ const replacement = file.added.find((l) => l.match(SENSOR_ORACLE_KEY_RE)?.[1] === key);
4094
+ if (replacement === void 0) {
4095
+ flag("oracle-removed", `sensor ${key} removed`);
4096
+ } else if (replacement.trim() !== line.trim()) {
4097
+ flag("oracle-changed", `sensor ${key} changed`);
4098
+ }
4099
+ }
4100
+ const removedAbsent = file.removed.find((l) => SENSOR_ABSENT_KEY_RE.test(l));
4101
+ const addedAbsent = file.added.find((l) => SENSOR_ABSENT_KEY_RE.test(l));
4102
+ if (addedAbsent !== void 0 && addedAbsent.trim() !== removedAbsent?.trim()) {
4103
+ flag("suppression-broadened", removedAbsent === void 0 ? "absent marker added" : "absent marker changed");
4104
+ }
4105
+ if (file.removed.some((l) => SENSOR_BLOCK_START_RE.test(l)) && removedBlockSeverity && !file.added.some((l) => SENSOR_BLOCK_START_RE.test(l))) {
4106
+ flag("sensor-removed", "block sensor block deleted");
4107
+ }
4108
+ }
4109
+ return weakenings;
4110
+ }
4038
4111
  function sensorSelfCheck(sensor, input) {
4039
4112
  const firedOn = [];
4040
4113
  for (const target of input.currentTargets) {
@@ -4531,7 +4604,7 @@ function parseLessonFields(body) {
4531
4604
  const instead = body.match(/\*\*Instead,\s*use:\*\*\s*([^\n]+)/i)?.[1]?.trim();
4532
4605
  return { title, whyFailed, instead };
4533
4606
  }
4534
- function proposeCommand(lesson, runCommand) {
4607
+ function buildProposeCommand(lesson, runCommand) {
4535
4608
  const parts = [
4536
4609
  `hivelore sensors propose ${lesson.memoryId}`,
4537
4610
  "--kind test",
@@ -4559,6 +4632,7 @@ function scaffoldPostIncidentTest(lesson, options) {
4559
4632
  const framework = options.framework;
4560
4633
  const short = lessonShortName(lesson.memoryId);
4561
4634
  const desc = oneLine(lesson.title) || short;
4635
+ const propose = (run) => options.proposeCommandOverride ?? buildProposeCommand(lesson, run);
4562
4636
  let relPath;
4563
4637
  let runCommand;
4564
4638
  let content;
@@ -4570,7 +4644,7 @@ function scaffoldPostIncidentTest(lesson, options) {
4570
4644
 
4571
4645
  ` : "";
4572
4646
  content = `${header(lesson, hc)}
4573
- // ${proposeCommand(lesson, runCommand)}
4647
+ // ${propose(runCommand)}
4574
4648
 
4575
4649
  ` + importLine + `describe(${JSON.stringify(desc)}, () => {
4576
4650
  it.todo("reproduces ${lesson.memoryId} and stays fixed");
@@ -4587,7 +4661,7 @@ function scaffoldPostIncidentTest(lesson, options) {
4587
4661
  runCommand = `pytest ${relPath}`;
4588
4662
  const hc = (l) => l ? `# ${l}` : "#";
4589
4663
  content = `${header(lesson, hc)}
4590
- # ${proposeCommand(lesson, runCommand)}
4664
+ # ${propose(runCommand)}
4591
4665
 
4592
4666
  import pytest
4593
4667
 
@@ -4604,7 +4678,7 @@ def test_${fn}():
4604
4678
  runCommand = `go test ./${dir}/`;
4605
4679
  const hc = (l) => l ? `// ${l}` : "//";
4606
4680
  content = `${header(lesson, hc)}
4607
- // ${proposeCommand(lesson, runCommand)}
4681
+ // ${propose(runCommand)}
4608
4682
 
4609
4683
  package incidents
4610
4684
 
@@ -4616,7 +4690,29 @@ func Test${fn}(t *testing.T) {
4616
4690
  }
4617
4691
  `;
4618
4692
  }
4619
- return { framework, relPath, content, runCommand, proposeCommand: proposeCommand(lesson, runCommand) };
4693
+ return { framework, relPath, content, runCommand, proposeCommand: propose(runCommand) };
4694
+ }
4695
+ var SCAFFOLD_MARKER_RE = /Post-incident guard generated by Hivelore from (\S+?)\.?\s*$/m;
4696
+ var PENDING_MARKERS = [/\bit\.todo\(/, /\bpytest\.mark\.skip\b/, /\bt\.Skip\(/];
4697
+ function assessScaffoldLoop(files, memories) {
4698
+ const byId = new Map(memories.map((m) => [m.id, m]));
4699
+ const gaps = [];
4700
+ for (const file of files) {
4701
+ const memoryId = file.content.match(SCAFFOLD_MARKER_RE)?.[1];
4702
+ if (!memoryId) continue;
4703
+ const memory = byId.get(memoryId);
4704
+ const pending = PENDING_MARKERS.some((re) => re.test(file.content));
4705
+ const armed = memory?.sensorKind === "shell" || memory?.sensorKind === "test";
4706
+ if (!pending && armed) continue;
4707
+ gaps.push({
4708
+ memory_id: memoryId,
4709
+ path: file.path,
4710
+ pending,
4711
+ armed,
4712
+ memory_missing: memory === void 0
4713
+ });
4714
+ }
4715
+ return gaps;
4620
4716
  }
4621
4717
 
4622
4718
  // src/bootstrap-state.ts
@@ -5876,6 +5972,7 @@ export {
5876
5972
  PROJECT_CONTEXT_FILE,
5877
5973
  PROJECT_CONTEXT_THROTTLE_MS,
5878
5974
  RUNTIME_JOURNAL_FILENAME,
5975
+ SCAFFOLD_MARKER_RE,
5879
5976
  SEED_QUALITY_FLOOR,
5880
5977
  SENSOR_ABSENT_LOOKBACK,
5881
5978
  SENSOR_ABSENT_WINDOW,
@@ -5900,6 +5997,7 @@ export {
5900
5997
  applyConflictResolution,
5901
5998
  applyFeedbackAdjustment,
5902
5999
  assessBootstrapState,
6000
+ assessScaffoldLoop,
5903
6001
  assessSensorHealth,
5904
6002
  bridgeMemorySummary,
5905
6003
  briefingMarkerPath,
@@ -5912,6 +6010,7 @@ export {
5912
6010
  buildFrontmatter,
5913
6011
  buildHandoffMarkdown,
5914
6012
  buildPreventionReceipt,
6013
+ buildProposeCommand,
5915
6014
  buildReport,
5916
6015
  bumpRead,
5917
6016
  classifyMemoryPriority,
@@ -5934,6 +6033,7 @@ export {
5934
6033
  countSourceFilesOnDisk,
5935
6034
  deriveConfidence,
5936
6035
  detectAgentContext,
6036
+ detectSensorWeakening,
5937
6037
  detectStacksFromManifests,
5938
6038
  diffContract,
5939
6039
  diffHasDistinctiveOverlap,