Editable analysis prompts on the admin page
CI / test (push) Successful in 44s
CI / build (push) Successful in 4m13s
CI / deploy (push) Skipped

The system prompts of the free summary and the paid detailed analysis can be
edited per language under /admin/promptok. Every save is a new row in
prompt_revisions (NULL = built-in text); new analyses record the revision in
prompt_version (v2-r<id>) and the worker uses exactly that text. Existing
analyses stay; the cross-user cache only copies results of the same revision.

The prompt code moves to the shared analysis-prompt crate so the backend can
show the built-in text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 14:25:08 +00:00
co-authored by Claude Opus 5.5
parent 0ba80abb47
commit 86d5dc5503
25 changed files with 1051 additions and 347 deletions
+11 -3
View File
@@ -145,8 +145,14 @@ async fn queue(
Target::Summary { chart_id, hash } => ("summary", hash, Some(*chart_id), None),
Target::Synastry { synastry_id, hash } => ("synastry", hash, None, Some(*synastry_id)),
};
let prompt_version = &state.config.prompt_version;
let cache_key = sha256_hex(&format!("{kind}|{hash}|{prompt_version}|{model}|{language}"));
// The cache key leaves out the admin-edited prompt revision, so a chart keeps
// its analysis when the prompt changes; copying from another chart needs the same revision.
let base_version = &state.config.prompt_version;
let cache_key = sha256_hex(&format!("{kind}|{hash}|{base_version}|{model}|{language}"));
let prompt_version = &match super::prompts::current_revision(&state.db, kind, language).await? {
Some(id) => format!("{base_version}-r{id}"),
None => base_version.clone(),
};
// Already requested for this chart/synastry: return it.
let existing: Option<AnalysisRow> = sqlx::query_as(&format!(
@@ -172,9 +178,11 @@ async fn queue(
// The same chart elsewhere (another user, same birth data) was already analysed: copy it.
let cached: Option<(Value, Option<i32>, Option<i32>)> = sqlx::query_as(
"SELECT content, input_tokens, output_tokens FROM analyses WHERE cache_key = $1 AND status = 'done' LIMIT 1",
"SELECT content, input_tokens, output_tokens FROM analyses \
WHERE cache_key = $1 AND prompt_version = $2 AND status = 'done' LIMIT 1",
)
.bind(&cache_key)
.bind(prompt_version)
.fetch_optional(&state.db)
.await?;
if let Some((content, input_tokens, output_tokens)) = cached {