mirror of
https://github.com/computerim/impactflow-discovery.git
synced 2026-08-27 07:20:36 +00:00
866bd60225
Save each discovery conversation's prompts and answers to durable CSV files (per-conversation + append-only master log) on both save and completion, so answers survive an extraction error, can be re-fed to the AI, and can be reviewed/resumed by the user. - app/services/answer_store.py: canonical prompt list + atomic CSV writes, master append, and read-back helpers (DB stays system of record; CSV failures are logged, never fatal). - discovery router: write CSV on /respond and /complete; new endpoints GET /answers, GET /answers.csv, POST /reprocess (shared extraction helper; locked profiles return 409). - discovery.html: prefill/resume from saved answers after an error and a "Re-run analysis" button wired to /reprocess. - scripts/reprocess_csv.py: offline CLI to re-run extraction from a CSV (print or --write-db). - QUESTIONS_DIR / QUESTIONS_MASTER_CSV config, .gitignore, README, tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dg6XWUwprmP5QCL18HxssY
294 lines
9.5 KiB
HTML
294 lines
9.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>ImpactFlow — Self Discovery</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@500;600&display=swap"
|
|
rel="stylesheet"
|
|
/>
|
|
<link rel="stylesheet" href="/static/style.css" />
|
|
<script src="/static/auth.js"></script>
|
|
</head>
|
|
<body>
|
|
<!-- Question flow -->
|
|
<div class="wrap" id="flow">
|
|
<div class="brand">ImpactFlow · Self Discovery</div>
|
|
<div class="progress" id="progress">1 of 5</div>
|
|
<h2 class="prompt-title" id="promptTitle"></h2>
|
|
<p class="prompt-text" id="promptText"></p>
|
|
<textarea
|
|
id="answer"
|
|
placeholder="Take your time. Tell the whole story…"
|
|
></textarea>
|
|
<div class="nav">
|
|
<button class="btn-ghost" id="backBtn">Back</button>
|
|
<button class="btn-primary" id="nextBtn">Next</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Loading state -->
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p>Reading your story…</p>
|
|
</div>
|
|
|
|
<script>
|
|
const PROMPTS = [
|
|
{
|
|
key: "prompt_alive",
|
|
title: "The Alive Moment",
|
|
text:
|
|
"Tell me about a time you felt most alive and useful. What were you doing, who was involved, and what made it matter?",
|
|
},
|
|
{
|
|
key: "prompt_friction",
|
|
title: "The Friction Moment",
|
|
text:
|
|
"Describe a situation where something felt deeply wrong or unfair. What was it, and what did you do about it?",
|
|
},
|
|
{
|
|
key: "prompt_pull",
|
|
title: "The Natural Pull",
|
|
text:
|
|
"What do you find yourself doing or thinking about in your free time, even when you're supposed to be doing something else?",
|
|
},
|
|
{
|
|
key: "prompt_recognition",
|
|
title: "The Recognition Moment",
|
|
text:
|
|
"When have you felt most seen or valued — and what were you being recognized for?",
|
|
},
|
|
{
|
|
key: "prompt_future",
|
|
title: "The Future Pull",
|
|
text:
|
|
"If you knew you couldn't fail and money wasn't a factor, what would you spend the next five years building or doing?",
|
|
},
|
|
{
|
|
key: "prompt_goals_short",
|
|
title: "The Near Horizon",
|
|
text:
|
|
"Looking at the next 6 to 12 months, what do you most want to make progress on or accomplish? Say it in your own words.",
|
|
},
|
|
{
|
|
key: "prompt_goals_long",
|
|
title: "The Long Horizon",
|
|
text:
|
|
"Now stretch out 3 to 5 years. What do you want to have built, become, or changed by then?",
|
|
},
|
|
];
|
|
|
|
// The signed-in user is resolved server-side from the session cookie, so
|
|
// the page no longer mints or tracks a user id of its own.
|
|
const answers = new Array(PROMPTS.length).fill("");
|
|
let index = 0;
|
|
let conversationId = null;
|
|
|
|
const el = {
|
|
progress: document.getElementById("progress"),
|
|
title: document.getElementById("promptTitle"),
|
|
text: document.getElementById("promptText"),
|
|
answer: document.getElementById("answer"),
|
|
back: document.getElementById("backBtn"),
|
|
next: document.getElementById("nextBtn"),
|
|
flow: document.getElementById("flow"),
|
|
loading: document.getElementById("loading"),
|
|
};
|
|
|
|
function render() {
|
|
const p = PROMPTS[index];
|
|
el.progress.textContent = `${index + 1} of ${PROMPTS.length}`;
|
|
el.title.textContent = p.title;
|
|
el.text.textContent = p.text;
|
|
el.answer.value = answers[index];
|
|
el.back.style.visibility = index === 0 ? "hidden" : "visible";
|
|
el.next.textContent =
|
|
index === PROMPTS.length - 1 ? "Submit" : "Next";
|
|
el.answer.focus();
|
|
}
|
|
|
|
function saveCurrent() {
|
|
answers[index] = el.answer.value;
|
|
}
|
|
|
|
el.back.addEventListener("click", () => {
|
|
saveCurrent();
|
|
if (index > 0) {
|
|
index -= 1;
|
|
render();
|
|
}
|
|
});
|
|
|
|
el.next.addEventListener("click", async () => {
|
|
saveCurrent();
|
|
if (index < PROMPTS.length - 1) {
|
|
index += 1;
|
|
render();
|
|
} else {
|
|
await submit();
|
|
}
|
|
});
|
|
|
|
const STORAGE_KEY = "discovery_conversation_id";
|
|
|
|
async function startConversation() {
|
|
const res = await authedFetch("/discovery/start", { method: "POST" });
|
|
if (!res.ok) throw new Error("Could not start conversation");
|
|
const data = await res.json();
|
|
conversationId = data.conversation_id;
|
|
// Remember the in-progress conversation so a reload after an error can
|
|
// resume from the original answers rather than losing them.
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, conversationId);
|
|
} catch (e) {
|
|
/* storage unavailable — non-fatal */
|
|
}
|
|
}
|
|
|
|
async function resumeOrStart() {
|
|
let savedId = null;
|
|
try {
|
|
savedId = localStorage.getItem(STORAGE_KEY);
|
|
} catch (e) {
|
|
/* storage unavailable */
|
|
}
|
|
if (savedId) {
|
|
try {
|
|
const res = await authedFetch(`/discovery/${savedId}/answers`);
|
|
if (res.ok) {
|
|
const data = await res.json();
|
|
const hasText = (data.answers || []).some((a) => a.answer.trim());
|
|
if (!data.completed_at && hasText) {
|
|
// Resume: restore the saved answers into the flow.
|
|
conversationId = savedId;
|
|
const byKey = {};
|
|
data.answers.forEach((a) => {
|
|
byKey[a.prompt_key] = a.answer;
|
|
});
|
|
PROMPTS.forEach((p, i) => {
|
|
// CSV/key uses the short key; PROMPTS uses prompt_* column names.
|
|
const shortKey = p.key.replace(/^prompt_/, "");
|
|
answers[i] = byKey[shortKey] || "";
|
|
});
|
|
render();
|
|
return;
|
|
}
|
|
}
|
|
} catch (e) {
|
|
/* fall through to a fresh start */
|
|
}
|
|
}
|
|
// No resumable conversation — start a fresh one.
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch (e) {
|
|
/* ignore */
|
|
}
|
|
await startConversation();
|
|
}
|
|
|
|
async function submit() {
|
|
el.flow.style.display = "none";
|
|
el.loading.classList.add("active");
|
|
|
|
try {
|
|
if (!conversationId) await startConversation();
|
|
|
|
const body = {};
|
|
PROMPTS.forEach((p, i) => {
|
|
body[p.key] = answers[i];
|
|
});
|
|
|
|
const respondRes = await authedFetch(
|
|
`/discovery/${conversationId}/respond`,
|
|
{
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
}
|
|
);
|
|
if (!respondRes.ok) throw new Error("Could not save responses");
|
|
|
|
const completeRes = await authedFetch(
|
|
`/discovery/${conversationId}/complete`,
|
|
{ method: "POST" }
|
|
);
|
|
if (!completeRes.ok) {
|
|
const detail = await completeRes
|
|
.json()
|
|
.catch(() => ({ detail: "Extraction failed" }));
|
|
throw new Error(detail.detail || "Extraction failed");
|
|
}
|
|
|
|
// Success: the conversation is complete, drop the resume marker.
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch (e) {
|
|
/* ignore */
|
|
}
|
|
window.location.href = "/static/profile.html";
|
|
} catch (err) {
|
|
el.loading.classList.remove("active");
|
|
el.flow.style.display = "block";
|
|
el.flow.innerHTML =
|
|
`<div class="error-box"><strong>Something went wrong.</strong><br/>` +
|
|
`${err.message}<br/><br/>Your answers are saved — you can ` +
|
|
`re-run the analysis or reload to keep editing.</div>` +
|
|
`<div class="nav">` +
|
|
`<button class="btn-ghost" onclick="location.reload()">Reload</button>` +
|
|
`<button class="btn-primary" id="rerunBtn">Re-run analysis</button>` +
|
|
`</div>`;
|
|
const rerun = document.getElementById("rerunBtn");
|
|
if (rerun) rerun.addEventListener("click", reprocess);
|
|
}
|
|
}
|
|
|
|
async function reprocess() {
|
|
if (!conversationId) {
|
|
location.reload();
|
|
return;
|
|
}
|
|
el.flow.style.display = "none";
|
|
el.loading.classList.add("active");
|
|
try {
|
|
const res = await authedFetch(
|
|
`/discovery/${conversationId}/reprocess`,
|
|
{ method: "POST" }
|
|
);
|
|
if (!res.ok) {
|
|
const detail = await res
|
|
.json()
|
|
.catch(() => ({ detail: "Re-run failed" }));
|
|
throw new Error(detail.detail || "Re-run failed");
|
|
}
|
|
try {
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
} catch (e) {
|
|
/* ignore */
|
|
}
|
|
window.location.href = "/static/profile.html";
|
|
} catch (err) {
|
|
el.loading.classList.remove("active");
|
|
el.flow.style.display = "block";
|
|
el.flow.innerHTML =
|
|
`<div class="error-box"><strong>Re-run failed.</strong><br/>` +
|
|
`${err.message}<br/><br/>Your answers are still saved.</div>` +
|
|
`<div class="nav"><span></span>` +
|
|
`<button class="btn-primary" onclick="location.reload()">Reload</button></div>`;
|
|
}
|
|
}
|
|
|
|
// Resume an in-progress conversation if one exists, otherwise start a
|
|
// fresh one so the id is ready by submit time.
|
|
render();
|
|
resumeOrStart().catch(() => {
|
|
/* will retry on submit */
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|