Skip to content

Add prompt version tracking to recipes#71

Merged
windoze95 merged 3 commits intomainfrom
feat/prompt-versioning
Apr 5, 2026
Merged

Add prompt version tracking to recipes#71
windoze95 merged 3 commits intomainfrom
feat/prompt-versioning

Conversation

@windoze95
Copy link
Copy Markdown
Owner

@windoze95 windoze95 commented Apr 5, 2026

Summary

  • Adds a PromptVersion field to the Recipe model that stores a 16-char SHA-256 hash of the prompt templates used to generate the recipe
  • Stamps the prompt version in all five Anthropic recipe-generating methods (GenerateRecipe, RegenerateRecipe, ForkRecipe, ExtractRecipeFromText, ExtractRecipeFromImage)
  • Flows the prompt version through all service layer paths: chat, regeneration, fork, and import (URL, photo, text)
  • Fix: PromptVersion now hashes only RecipePrompts instead of the entire Prompts struct, so unrelated prompt changes (voice, allergen, interview) no longer rotate the version stamp
  • Fix: Canonical records now store prompt_version and forward it on cache hits, so imports of previously-extracted URLs retain the original extraction's version metadata

How it works

  • config.PromptVersion() serializes prompts.Recipe to JSON and computes a SHA-256 hash, returning the first 16 hex characters
  • Any change to recipe-related prompt content produces a different hash, allowing comparison of recipe quality across prompt versions
  • The CanonicalRecipe model now includes PromptVersion, persisted on upsert and forwarded on cache-hit imports (ImportFromURL, ImportFromCanonical, PreviewFromURL)
  • The field is omitempty with GORM size:16, so existing recipes are unaffected and no migration is needed

Test plan

  • All existing tests pass (go test ./...)
  • Updated test call sites for extractFromURL (5 return values) and createImportedRecipe (8 params)
  • Verify PromptVersion is populated on a newly generated recipe
  • Verify PromptVersion is empty for manually entered recipes
  • Verify different prompts.yaml content produces different hashes
  • Verify canonical cache-hit imports retain the original prompt version

🤖 Generated with Claude Code

Each recipe now records a 16-char hex hash of the prompt templates
used to generate it. This enables comparing recipe quality across
prompt versions and knowing which recipes used old vs new prompts.

Changes:
- Add PromptVersion() hash function in config/prompts.go
- Add PromptVersion field to Recipe model (optional, GORM auto-migrates)
- Add PromptVersion to RecipeResult in ai/provider.go
- Stamp prompt version in all 5 Anthropic recipe methods
- Flow prompt version through service layer (chat, regen, fork, import)
- Update extractFromURL and createImportedRecipe signatures
- Update repository UpdateRecipeDef to persist PromptVersion
- Fix all test call sites for updated signatures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 609381b3df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/config/prompts.go Outdated
Comment thread internal/service/import.go Outdated
windoze95 and others added 2 commits April 4, 2026 21:10
PromptVersion now hashes only RecipePrompts instead of the entire
Prompts struct, so unrelated prompt changes (voice, allergen, etc.)
no longer rotate the recipe version stamp. Canonical records now
store and forward prompt_version so cache-hit imports retain the
version from the original extraction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Keep middleware wrapping from main (R5) and add PromptVersion stamping
from prompt-versioning (R10) inside each runWithMiddleware closure.
Applies to all 5 recipe-generating methods: GenerateRecipe,
RegenerateRecipe, ForkRecipe, ExtractRecipeFromText, ExtractRecipeFromImage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@windoze95 windoze95 merged commit d9d342f into main Apr 5, 2026
1 check passed
@windoze95 windoze95 deleted the feat/prompt-versioning branch April 5, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant