ai generated tasks check for duplicates, existing streaks, and more before creation

This commit is contained in:
masongga
2026-05-23 23:39:54 -06:00
parent c5b20e094e
commit bffe0f941c
8 changed files with 401 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import {
sanitizePlausibleAiTaskLabels,
} from "@/lib/ai-habit-utils";
import {
filterExcludedSimilarTaskLabels,
getFocusTopicDefaultTasks,
isPlausibleTaskLabel,
} from "@/lib/ai-task-guardrails";
@@ -241,12 +242,29 @@ export function buildJournalAwareFallbackLabels(context: AiTaskContext): string[
export function mergeJournalHintsIntoLabels(
labels: string[],
context: AiTaskContext,
): string[] {
options?: {
fillInOnly?: boolean;
maxCount?: number;
excludeLabels?: string[];
},
) {
const journalHints = extractJournalTaskHints(context.journal);
const merged = sanitizePlausibleAiTaskLabels([
let merged = sanitizePlausibleAiTaskLabels([
...journalHints,
...labels.map(normalizeAiTaskLabel),
]);
if (options?.excludeLabels?.length) {
merged = filterExcludedSimilarTaskLabels(merged, options.excludeLabels);
}
if (options?.maxCount !== undefined) {
merged = merged.slice(0, options.maxCount);
}
if (options?.fillInOnly) {
return merged;
}
return ensureMinimumFallbackTasks(new Set(merged), context);
}