Design System backend - #12
Merged
Merged
Conversation
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus ^<clio-agent@sisyphuslabs.ai^>
Implements the Design System requirements (v1.0) alongside the user research
component, mirroring its structure.
- design domain: Spark, seven sections, sequential first-pass traversal with
the two branch orders (experience-first / mechanics-first), path gate after
Context, skip semantics, free navigation after a full traversal, dashboard
with per-section status and percentages gated on traversal plus content
- storage: design_states (postgres, per project) and design:{sessionId}
(redis, session TTL) behind one StateStore interface; design_reports history
- reports: standard version renders content as entered; AI-enhanced version
rewrites sections into prose via the assistant; every generated report is
retained per project and both versions work for anonymous sessions
- ai provider behind the same switch pattern as the mailer: noop (deterministic
fallbacks, keyword branch heuristic) and openai-compatible (base URL, key,
model via env); endpoints for rewrite (single-level undo via previousText)
and per-section contextual chat
- routes: /sessions/{id}/design/*, /projects/{id}/design/* (auth, ownership),
/ai/*; project design import from an anonymous session for save-as-draft
- migration 000004; config AI_* vars with validation; tests for the traversal
state machine and the noop assistant
Fixes from a full multi-perspective review of the new component. - first-pass traversal no longer conflates saving with advancing: visited sections can be re-saved freely (auto-save, prefill edits), the cursor only moves on frontier saves (FR-15, FR-28/29) - generate-pdf now produces BOTH report versions in one trigger (FR-23), body optional; session-generated reports are kept in the design state and migrated into design_reports on import (FR-27) - AI-enhanced reports consolidate repeated content across sections in a single provider call (FR-23); the noop provider deduplicates repeated lines; the silent noop fallback inside the openai provider is removed (errors surface) - standard reports preserve the original field order instead of sorting keys - dashboard sections carry the required scope description (FR-12) - per-section FAQ added and returned by the chatbot, plus a faq endpoint (FR-32) - rewrite and chat moved under the guarded session/project design routes; the bare /ai mount is gone - saveSpark reports prefill outcome (prefillApplied/prefillFailed) instead of swallowing provider errors, and calls the provider before the state read - import-session refuses an empty session state and a non-empty project state - complete flag is now a pointer: omitting it preserves completion status - redis design state keeps its TTL on update instead of re-leasing - doctor gains config.ai and ai.init checks
- renumber the design migration to 000005 after upstream took 000004 for activity_events - classify design routes in the activity middleware (design_section_saved, design_path_chosen, design_pdf_generated, design_imported) with tests - document the Design System API in docs/api/design.md and link it from the index - add the AI provider variables to both env examples - untrack the accidentally committed gamidoc-backend.exe and ignore *.exe - fix the wizard step-1 test left behind by the projectType validation removal (assert on participants, which is still validated)
Second full review round after the rebase onto upstream main. Confirmed findings fixed: - import-session no longer requires the session record to exist: upstream convert deletes the session, which made anonymous design work unreachable on the register-and-convert journey; the design state lives independently, so it can now be imported after conversion (404 only when neither the session nor any design state exists) - migrated session reports get fresh ids and keep their timestamps, so importing the same session twice no longer collides on the design_reports primary key with a 500 - design_states.data changed from JSONB to TEXT: Postgres normalised JSONB key order, which broke the documented field-order preservation for project reports (the repository now passes strings so lib/pq does not apply bytea encoding) - SectionLines decodes with UseNumber and renders nested values by token walking: large numbers no longer come out in scientific notation and nested objects keep their key order (regression tests added) - generate-pdf distinguishes AI failures (502 AI_PROVIDER_ERROR) from build, storage, and database failures (500); a failed report insert deletes the just-written blob - the openai-compatible client gets a timeout (AI_TIMEOUT, default 60s) instead of http.DefaultClient; empty completions are errors; branch recommendations accept verbose answers instead of defaulting them to A - the redis design state save is a single Lua script, so a crash between SET and EXPIRE can no longer leave an immortal key - SafeSummary and the startup log include ai_provider - docs/api/design.md corrected to the actual contract (sectionNumber, reportId, not_started/in_progress/complete, dashboard fields, error codes) Deliberately not addressed, consistent with the repo baseline: project deletion does not remove design report blobs (upstream deletes only the wizard PDF), and the fpdf core-font reports render latin-1 text only (same limitation as the upstream builder; the Gotenberg path is the answer for rich text).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.