@explorer02/cfm-survey-sdk 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +140 -33
- package/dist/cli/index.mjs +140 -33
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -1
- package/postinstall.js +8 -5
- package/templates/AGENT.md +60 -19
- package/templates/deploy-wizard-to-s3.sh +52 -0
- package/templates/docs/00-integration/agent-execution-flow.md +281 -0
- package/templates/docs/00-integration/agent-operating-contract.md +260 -0
- package/templates/docs/00-integration/apply-ui-config.md +365 -0
- package/templates/docs/00-integration/canonical-survey-fixtures.md +94 -0
- package/templates/docs/00-integration/client-integration-guide.md +9 -7
- package/templates/docs/00-integration/client-lib-folder.md +115 -0
- package/templates/docs/00-integration/component-checklist.md +88 -62
- package/templates/docs/00-integration/constraints.md +13 -5
- package/templates/docs/00-integration/custom-field-logic-and-navigation.md +56 -0
- package/templates/docs/00-integration/progress.md +4 -2
- package/templates/docs/00-integration/setup.md +12 -0
- package/templates/docs/00-integration/ui-customization-wizard.md +144 -0
- package/templates/docs/00-integration/useSurveySDK.md +35 -1
- package/templates/docs/00-integration/wizard-api.md +134 -0
- package/templates/docs/00-integration/wizard-config-handoff.md +246 -0
- package/templates/docs/00-integration/wizard-preview-build-guide.md +400 -0
- package/templates/docs/00-integration/wizard-question-type-styling.md +195 -0
- package/templates/docs/01-components/01-survey-page.md +18 -8
- package/templates/docs/01-components/02-question.md +2 -2
- package/templates/docs/01-components/03-rating-scale.md +12 -18
- package/templates/docs/01-components/05-csat-matrix-scale.md +18 -26
- package/templates/docs/01-components/06-likert-matrix-scale.md +19 -39
- package/templates/docs/01-components/07-slider-matrix-scale.md +48 -33
- package/templates/docs/01-components/09-custom-slider-track.md +15 -25
- package/templates/docs/01-components/10-header-footer.md +23 -4
- package/templates/docs/01-components/11-progress-bar.md +14 -6
- package/templates/docs/01-components/19-survey-sticky-chrome.md +79 -0
- package/templates/docs/01-components/README.md +2 -2
- package/templates/docs/02-reference/question-types/10-slider-matrix.md +38 -26
- package/templates/docs/02-reference/routing-table.md +1 -0
- package/templates/docs/02-reference/value-derivation.md +1 -1
- package/templates/docs/03-ui-specs/00-question-shell.md +10 -0
- package/templates/docs/03-ui-specs/01-rating.md +18 -0
- package/templates/docs/03-ui-specs/02-radio.md +16 -1
- package/templates/docs/03-ui-specs/03-text.md +12 -1
- package/templates/docs/03-ui-specs/04-csat.md +84 -50
- package/templates/docs/03-ui-specs/06-slider.md +3 -1
- package/templates/docs/03-ui-specs/07-matrix-cfm.md +71 -48
- package/templates/docs/03-ui-specs/08-matrix-csat-rating.md +48 -18
- package/templates/docs/03-ui-specs/09-slider-matrix.md +59 -32
- package/templates/docs/03-ui-specs/10-file-upload.md +11 -0
- package/templates/docs/03-ui-specs/11-text-and-media.md +4 -0
- package/templates/docs/03-ui-specs/12-survey-chrome.md +54 -5
- package/templates/docs/03-ui-specs/13-heatmap.md +12 -1
- package/templates/docs/03-ui-specs/14-rank-order.md +11 -0
- package/templates/docs/03-ui-specs/README.md +4 -2
- package/templates/docs/03-ui-specs/shared/matrix-dropdown.md +1 -1
- package/templates/docs/MANIFEST.json +162 -6
- package/templates/docs/index.md +116 -117
- package/templates/docs/templates/CsatMatrixScale.tsx +637 -0
- package/templates/docs/templates/FileUploadScale.tsx +262 -0
- package/templates/docs/templates/HeatmapScale.tsx +114 -0
- package/templates/docs/templates/LikertMatrixScale.tsx +414 -0
- package/templates/docs/templates/Question.tsx +3 -0
- package/templates/docs/templates/RatingScale.tsx +129 -0
- package/templates/docs/templates/SliderMatrixScale.tsx +248 -0
- package/templates/docs/templates/SurveyStickyChrome.tsx +24 -0
- package/templates/docs/templates/customFieldValues.ts +36 -0
- package/templates/docs/templates/implementation_plan.md +56 -9
- package/templates/docs/templates/labelStyles.ts +33 -0
- package/templates/docs/templates/selectionStyles.ts +100 -0
- package/templates/docs/templates/surveyUiIcons.tsx +11 -0
- package/templates/docs/templates/surveyUiScaleUtils.ts +51 -0
- package/templates/docs/templates/verify-agent-build.sh +119 -0
- package/templates/preview-harness/preview-bridge.inline.js +201 -0
- package/templates/preview-harness/previewPages.js +108 -0
- package/templates/preview-harness/previewPages.ts +298 -0
- package/templates/preview-harness/vite-app/src/PreviewConfigContext.tsx +67 -0
- package/templates/preview-harness/vite-app/src/QuestionPreview.tsx +122 -0
- package/templates/preview-harness/vite-app/src/SurveyPagePreview.tsx +75 -0
- package/templates/preview-harness/vite-app/src/fixtures/questions.ts +311 -0
- package/templates/preview-harness/vite-app/src/globals.css +16 -0
- package/templates/preview-harness/vite-app/src/mount.tsx +9 -0
- package/templates/preview-harness/vite-app/src/preview-live-overrides.css +101 -0
- package/templates/preview-harness/vite-app/stubs/next-dynamic.tsx +25 -0
- package/templates/preview-harness/vite-app/stubs/next-image.tsx +29 -0
- package/templates/previewBridge.ts +153 -0
- package/templates/survey-theme.css +295 -0
- package/templates/survey-ui-config.schema.json +213 -0
- package/templates/wizard-dist/assets/PreviewMock-DgHfrVeb.js +1 -0
- package/templates/wizard-dist/assets/TypePanel-CFVC3Ptn.js +1 -0
- package/templates/wizard-dist/assets/index-BhWM50Yu.css +1 -0
- package/templates/wizard-dist/assets/index-DYK3X1e5.js +34 -0
- package/templates/wizard-dist/assets/vendor-BwkXDkd3.js +17 -0
- package/templates/wizard-dist/index.html +20 -0
- package/templates/wizard.html +13 -1129
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# UI Customization Wizard
|
|
2
|
+
|
|
3
|
+
> Optional **run** after Phase 6 verify. **Wizard-ready build** is mandatory in Phase 5 — see [`agent-execution-flow.md`](agent-execution-flow.md).
|
|
4
|
+
> **Wait + apply protocol:** [`wizard-config-handoff.md`](wizard-config-handoff.md).
|
|
5
|
+
|
|
6
|
+
**Before the client opts in:** agents must already have wired [`wizard-preview-build-guide.md`](wizard-preview-build-guide.md) artifacts so AWS wizard previews update live (`--cfm-*` CSS vars + `data-cfm-*` content hooks).
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
After **Phase 6** (verify + `npm run dev`), ask the client:
|
|
11
|
+
|
|
12
|
+
> *"Your survey is running locally. Would you like to customize the UI through the web wizard?"*
|
|
13
|
+
|
|
14
|
+
- **Yes** → Phase 6b: run `npx cfm-sdk customize-ui` (AWS) or `customize` (local)
|
|
15
|
+
- **No** → proceed to Phase 7 deploy
|
|
16
|
+
|
|
17
|
+
## AWS flow (production) — agent waits for client
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export CFM_INSTANCE_ID="..." CFM_DEPLOY_API_BASE="http://43.204.26.213:3000"
|
|
21
|
+
npx cfm-sdk customize-ui
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Default = review mode.** The CLI:
|
|
25
|
+
|
|
26
|
+
1. Resolves seed config from project (`survey-ui-config.json` → `survey-theme.css` → `Header.tsx` → defaults)
|
|
27
|
+
2. Exports component preview pages (`export-previews`) — one HTML per preview key (`header`, `footer`, `MCQ_single`, …)
|
|
28
|
+
3. Uploads preview HTML to S3 via EC2 API (`POST /wizard/session/start` → presigned PUTs → `upload/complete`)
|
|
29
|
+
4. Prints the **deployed wizard link** and opens it for the agent — **agent must copy this link to the client**
|
|
30
|
+
5. **Polls until client submits** (`GET /wizard/config/:surveyId` → `status: ready`)
|
|
31
|
+
6. Writes review artifacts — **does not auto-apply to codebase**
|
|
32
|
+
|
|
33
|
+
### Client wizard link (after S3 upload)
|
|
34
|
+
|
|
35
|
+
Once previews are on S3, the CLI prints:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
✅ Previews uploaded
|
|
39
|
+
🔗 Client wizard link — share with the client:
|
|
40
|
+
http://43.204.26.213:3000/wizard-app/index.html?session=<uuid>&secret=<hex>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Who | Uses |
|
|
44
|
+
|-----|------|
|
|
45
|
+
| **Client** | Opens the **deployed EC2 wizard link** only — customizes branding, colors, question-type tokens; previews update live from S3-backed component pages |
|
|
46
|
+
| **Agent** | Keeps `customize-ui` running (polls API); does **not** ask client to use localhost |
|
|
47
|
+
|
|
48
|
+
**URL shape:** `{CFM_DEPLOY_API_BASE}/wizard-app/index.html?session={sessionId}&secret={sessionSecret}`
|
|
49
|
+
|
|
50
|
+
Default production API: `http://43.204.26.213:3000` (see `MANIFEST.json` `apiBaseDefault`).
|
|
51
|
+
|
|
52
|
+
**Agent script (after CLI prints the link):**
|
|
53
|
+
|
|
54
|
+
> *"I've uploaded your survey component previews. Open this link to customize the UI: [paste wizard URL]. When you're done, click **Review & Build** on the last step. I'll wait here until your changes are saved."*
|
|
55
|
+
|
|
56
|
+
**On success, CLI prints:**
|
|
57
|
+
```
|
|
58
|
+
✅ Configuration ready
|
|
59
|
+
Final: survey-ui-config.final.json
|
|
60
|
+
Diff: survey-ui-config.diff.md
|
|
61
|
+
Apply when ready: npx cfm-sdk confirm-ui-config
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Agent must:**
|
|
65
|
+
- [ ] Keep terminal open until CLI exits 0
|
|
66
|
+
- [ ] **Copy the deployed wizard link from CLI output and send it to the client** (after previews upload to S3)
|
|
67
|
+
- [ ] Tell client: *"Please complete the wizard and click Review & Build."*
|
|
68
|
+
- [ ] Read `survey-ui-config.diff.md` before Phase 6c
|
|
69
|
+
- [ ] Apply codebase per [`apply-ui-config.md`](apply-ui-config.md) from **`.final.json`**
|
|
70
|
+
- [ ] Run `npx cfm-sdk confirm-ui-config` after codebase apply
|
|
71
|
+
|
|
72
|
+
See [`wizard-config-handoff.md`](wizard-config-handoff.md) for full handoff checklist.
|
|
73
|
+
|
|
74
|
+
### Legacy immediate write
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx cfm-sdk customize-ui --apply
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Writes `survey-ui-config.json` + logo immediately (no diff review). Phase 6c apply still required.
|
|
81
|
+
|
|
82
|
+
### Detached session
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx cfm-sdk customize-ui --no-wait
|
|
86
|
+
# Later, when client done:
|
|
87
|
+
export CFM_WIZARD_SESSION_ID="..."
|
|
88
|
+
npx cfm-sdk fetch-ui-config
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Local flow (development)
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npx cfm-sdk customize
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Opens browser at `http://localhost:4200`. **Blocks** until client saves → writes `survey-ui-config.json` directly. Then Phase 6c apply from that file (no `confirm-ui-config`).
|
|
98
|
+
|
|
99
|
+
## Seed config
|
|
100
|
+
|
|
101
|
+
| Priority | Source |
|
|
102
|
+
|----------|--------|
|
|
103
|
+
| 1 | `./survey-ui-config.json` (draft) |
|
|
104
|
+
| 2 | `src/styles/survey-theme.css` (`--cfm-*` vars) |
|
|
105
|
+
| 3 | `implementation_plan.md` branding hints |
|
|
106
|
+
| 4 | `Header.tsx` — `data-cfm-logo` / `data-cfm-logo-text` |
|
|
107
|
+
| 5 | SDK defaults |
|
|
108
|
+
|
|
109
|
+
Debug: `npx cfm-sdk resolve-ui-config --write`
|
|
110
|
+
|
|
111
|
+
## Wizard Steps
|
|
112
|
+
|
|
113
|
+
| Step | Controls |
|
|
114
|
+
|------|----------|
|
|
115
|
+
| Identity | Survey title, company name, tab title, thank-you message |
|
|
116
|
+
| Logo | Upload → S3 (AWS) or `public/` (local) |
|
|
117
|
+
| Header / Footer | Logo box, company, links, copyright, colors |
|
|
118
|
+
| Theme & Colors | Presets, palette, question card (cell selected + focus ring) |
|
|
119
|
+
| Layout & Chrome | Header/footer toggles, nav, width, font |
|
|
120
|
+
| Question Types | Per-type tokens + format preview tabs |
|
|
121
|
+
| Testing & Tokens | Placeholders, custom fields, debug |
|
|
122
|
+
| Deploy | AWS or Vercel target |
|
|
123
|
+
| Review & Build | **Client submits** — triggers CLI poll success |
|
|
124
|
+
|
|
125
|
+
## Output artifacts
|
|
126
|
+
|
|
127
|
+
| File | When |
|
|
128
|
+
|------|------|
|
|
129
|
+
| `survey-ui-config.final.json` | AWS — client's submitted config (apply source) |
|
|
130
|
+
| `survey-ui-config.diff.md` | AWS — every changed path (audit before apply) |
|
|
131
|
+
| `survey-ui-config.json` | Active config (seed until `confirm-ui-config`; or final for local/`--apply`) |
|
|
132
|
+
|
|
133
|
+
Apply tokens per [`apply-ui-config.md`](apply-ui-config.md).
|
|
134
|
+
|
|
135
|
+
## Agent Checklist
|
|
136
|
+
|
|
137
|
+
- [ ] Phase 5: components wired per [`wizard-preview-build-guide.md`](wizard-preview-build-guide.md)
|
|
138
|
+
- [ ] Client opted in after localhost preview (INPUT 3)
|
|
139
|
+
- [ ] Ran `customize-ui` or `customize` and **waited** for CLI exit 0
|
|
140
|
+
- [ ] Read `survey-ui-config.diff.md` (AWS review mode)
|
|
141
|
+
- [ ] Phase 6c: applied **all** diff paths per [`apply-ui-config.md`](apply-ui-config.md)
|
|
142
|
+
- [ ] AWS: ran `confirm-ui-config` after codebase apply
|
|
143
|
+
- [ ] Re-ran verify script + build
|
|
144
|
+
- [ ] Did not modify SDK integration (`onAction`, dispatch logic)
|
|
@@ -88,7 +88,41 @@ Missing ids in the map are treated as empty for logic evaluation.
|
|
|
88
88
|
|
|
89
89
|
When the survey uses custom-field logic, also pass the same map into `Question.tsx` visibility helpers — see [`custom-field-logic-and-navigation.md`](custom-field-logic-and-navigation.md).
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Custom field values (required when survey uses CRM logic)
|
|
94
|
+
|
|
95
|
+
Custom field values are **not** survey UI inputs — they come from CRM/transaction context (host app API, JWT claims, etc.) and enable SDK evaluation of rules where `entityType: 'CUSTOM_FIELD'`.
|
|
96
|
+
|
|
97
|
+
| Situation | Action |
|
|
98
|
+
|-----------|--------|
|
|
99
|
+
| No `_c_…` ids in fetched survey logic | `customFieldValues: {}` or omit — empty map is fine |
|
|
100
|
+
| Any skip/display/answer/end rule references `CUSTOM_FIELD` | **Required** — copy [`templates/customFieldValues.ts`](../templates/customFieldValues.ts) → `src/lib/customFieldValues.ts` |
|
|
101
|
+
|
|
102
|
+
### Import and wire (two places)
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { CUSTOM_FIELD_VALUES } from '@/lib/customFieldValues';
|
|
106
|
+
|
|
107
|
+
// 1. Hook options (skip, display, progress, validation, end-page logic)
|
|
108
|
+
const surveyOptions = useMemo(
|
|
109
|
+
() => ({
|
|
110
|
+
instanceId,
|
|
111
|
+
placeholders: SURVEY_PLACEHOLDERS,
|
|
112
|
+
customFieldValues: CUSTOM_FIELD_VALUES,
|
|
113
|
+
}),
|
|
114
|
+
[instanceId, selectedLanguage]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// 2. Question prop (answer-logic UI — same map)
|
|
118
|
+
<Question customFieldValues={CUSTOM_FIELD_VALUES} ... />
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Both wiring points are mandatory** when custom-field logic exists. Hook-only wiring breaks answer-logic UI; Question-only wiring breaks skip/display/progress.
|
|
122
|
+
|
|
123
|
+
Discovery steps: [`custom-field-logic-and-navigation.md`](custom-field-logic-and-navigation.md) · lib layout: [`client-lib-folder.md`](client-lib-folder.md).
|
|
124
|
+
|
|
125
|
+
---
|
|
92
126
|
|
|
93
127
|
| Namespace | Field | Type | Purpose |
|
|
94
128
|
|-----------|-------|------|---------|
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Wizard API (`/wizard/*`)
|
|
2
|
+
|
|
3
|
+
> EC2 middle API routes for AWS-hosted UI customization. Consumed by `npx cfm-sdk customize-ui` and the survey-wizard SPA.
|
|
4
|
+
|
|
5
|
+
Base URL: `CFM_DEPLOY_API_BASE` — production default: `http://43.204.26.213:3000`
|
|
6
|
+
|
|
7
|
+
## Client wizard link (deployed)
|
|
8
|
+
|
|
9
|
+
After `customize-ui` uploads component previews to S3, the CLI prints a **deployed wizard URL** for the client:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
{CFM_DEPLOY_API_BASE}/wizard-app/index.html?session={sessionId}&secret={sessionSecret}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
http://43.204.26.213:3000/wizard-app/index.html?session=abc-123&secret=fe7698d0...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Piece | Role |
|
|
22
|
+
|-------|------|
|
|
23
|
+
| `/wizard-app/` | Wizard SPA on EC2 (customization forms + preview panel) |
|
|
24
|
+
| `session` + `secret` | Tie the client to the S3 preview session |
|
|
25
|
+
| S3 `previews/` | Component-wise HTML (`header`, `footer`, `MCQ_single`, …) — loaded via EC2 proxy |
|
|
26
|
+
|
|
27
|
+
**Agent:** copy link from CLI → send to client. **Client:** opens link only (no localhost). **Agent:** keeps CLI polling until submit.
|
|
28
|
+
|
|
29
|
+
`wizardUrl` in `POST /wizard/session/start` response is this full URL (built by `getWizardPublicUrl` in deploy-api).
|
|
30
|
+
|
|
31
|
+
## Auth
|
|
32
|
+
|
|
33
|
+
| Caller | Header |
|
|
34
|
+
|--------|--------|
|
|
35
|
+
| CLI | `Authorization: Bearer {CFM_INSTANCE_ID}` |
|
|
36
|
+
| Wizard SPA | `X-Wizard-Session: {secret}` + `X-Wizard-Session-Id: {sessionId}` |
|
|
37
|
+
|
|
38
|
+
## Endpoints
|
|
39
|
+
|
|
40
|
+
### `POST /wizard/session/start`
|
|
41
|
+
|
|
42
|
+
Starts session; returns presigned PUT URLs for preview HTML files.
|
|
43
|
+
|
|
44
|
+
**Body:** `{ "files": [...], "surveyTypes": ["MCQ", "NPS_SCALE"], "initialConfig": { ... } }`
|
|
45
|
+
|
|
46
|
+
`initialConfig` is optional. When present, the CLI sends the agent's resolved UI config (from draft `survey-ui-config.json`, parsed `survey-theme.css`, `Header.tsx` logo contract, or defaults). The API normalizes, validates, stores on the session, and persists to `sites/{surveyId}/wizard-sessions/{sessionId}/seed-config.json` for restart durability.
|
|
47
|
+
|
|
48
|
+
**Response:** `{ sessionId, sessionSecret, wizardUrl, uploads[] }`
|
|
49
|
+
|
|
50
|
+
### `POST /wizard/previews/upload/complete`
|
|
51
|
+
|
|
52
|
+
**Body:** `{ "sessionId": "uuid" }`
|
|
53
|
+
|
|
54
|
+
Activates session; builds same-origin `previewManifest` (API proxy URLs — session previews are private in S3).
|
|
55
|
+
|
|
56
|
+
### `GET /wizard/preview/:sessionId/:component/index.html?secret=...`
|
|
57
|
+
|
|
58
|
+
Serves preview HTML from S3 for wizard iframes. Auth via `secret` query param (iframes cannot send session headers).
|
|
59
|
+
|
|
60
|
+
### `GET /wizard/session/:sessionId`
|
|
61
|
+
|
|
62
|
+
Wizard boot — returns `surveyTypes`, `previewManifest`, `sessionExpiresAt`, and `initialConfig` when the session was seeded.
|
|
63
|
+
|
|
64
|
+
**Response:** `{ surveyTypes, instanceId, previewManifest, sessionExpiresAt, initialConfig? }`
|
|
65
|
+
|
|
66
|
+
The wizard SPA calls `loadConfig(initialConfig)` on boot so the client edits on top of the agent build.
|
|
67
|
+
|
|
68
|
+
### `POST /wizard/logo`
|
|
69
|
+
|
|
70
|
+
**Body:** `{ "filename": "logo.png", "base64": "data:image/png;base64,..." }`
|
|
71
|
+
|
|
72
|
+
Max 512KB. Stores in session S3 prefix.
|
|
73
|
+
|
|
74
|
+
### `POST /wizard/complete`
|
|
75
|
+
|
|
76
|
+
**Body:** full `survey-ui-config.json` object.
|
|
77
|
+
|
|
78
|
+
On success:
|
|
79
|
+
|
|
80
|
+
1. Copies uploaded logo to **permanent** S3 key: `sites/{surveyId}/assets/{fileName}`
|
|
81
|
+
2. Saves final config to `sites/{surveyId}/wizard/config.json` (with `logoKey` + `logoUrl` metadata)
|
|
82
|
+
3. **Deletes** entire wizard session folder `sites/{surveyId}/wizard-sessions/{sessionId}/` (previews, seed-config, temp logo)
|
|
83
|
+
4. Returns public logo URL: `{ logoUrl, logoKey, logoFileName }`
|
|
84
|
+
|
|
85
|
+
Public logo URL format: `{CLOUDFRONT_BASE_URL}/sites/{surveyId}/assets/{fileName}` — readable by anyone with the link (via CloudFront, bucket stays private).
|
|
86
|
+
|
|
87
|
+
### `GET /wizard/config/:surveyId`
|
|
88
|
+
|
|
89
|
+
CLI poll. Query `?sessionId=` to scope to current session.
|
|
90
|
+
|
|
91
|
+
**Pending:** `{ "status": "pending" }`
|
|
92
|
+
**Ready:** `{ "status": "ready", "config": { ... }, "logoUrl": "...", "logoKey": "...", "sessionId": "..." }`
|
|
93
|
+
|
|
94
|
+
`config.global.logo.url` is populated with the public CloudFront URL when a logo was uploaded.
|
|
95
|
+
|
|
96
|
+
### `GET /wizard/logo/:surveyId/:fileName`
|
|
97
|
+
|
|
98
|
+
Returns `{ "downloadUrl": "presigned-get" }` for CLI to save logo to agent `public/` (fallback when CloudFront is not reachable from agent network).
|
|
99
|
+
|
|
100
|
+
## Env (deploy-api)
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
WIZARD_DEV_URL=http://localhost:5173 # dev only
|
|
104
|
+
WIZARD_PATH=/sites/_wizard # prod CloudFront path
|
|
105
|
+
WIZARD_SESSION_TTL_MS=7200000 # 2h — expired sessions trigger S3 GC
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## AWS console (one-time — logo public URL)
|
|
109
|
+
|
|
110
|
+
Logos are **not** public on S3 directly. They are served through **CloudFront** (same distribution as survey deploys).
|
|
111
|
+
|
|
112
|
+
Verify (usually already done if deploy works):
|
|
113
|
+
|
|
114
|
+
1. **CloudFront** → your distribution → Origins → hosting bucket is the origin
|
|
115
|
+
2. **Origin access** → OAC/OAI allows CloudFront to read the bucket (bucket policy blocks public access)
|
|
116
|
+
3. **Behavior** → default or `sites/*` path serves objects from the bucket
|
|
117
|
+
|
|
118
|
+
No extra bucket policy for public read is required. The public URL is:
|
|
119
|
+
|
|
120
|
+
`https://{CLOUDFRONT_DOMAIN}/sites/{surveyId}/assets/{logoFileName}`
|
|
121
|
+
|
|
122
|
+
**IAM (EC2 instance role)** must allow: `s3:PutObject`, `s3:GetObject`, `s3:DeleteObject`, `s3:ListBucket` on the hosting bucket, plus `cloudfront:CreateInvalidation` on the distribution.
|
|
123
|
+
|
|
124
|
+
## CLI flow (review mode — default)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
export CFM_INSTANCE_ID="..." CFM_DEPLOY_API_BASE="http://43.204.26.213:3000"
|
|
128
|
+
npx cfm-sdk customize-ui
|
|
129
|
+
# export-previews → upload component previews to S3 → print client wizard link →
|
|
130
|
+
# POLL until client submits → survey-ui-config.final.json + .diff.md
|
|
131
|
+
# Agent applies codebase → npx cfm-sdk confirm-ui-config
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See [`wizard-config-handoff.md`](wizard-config-handoff.md).
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Wizard Config Handoff — Wait, Capture, Apply
|
|
2
|
+
|
|
3
|
+
> **Phase 6b → 6c.** Read with [`ui-customization-wizard.md`](ui-customization-wizard.md) and [`apply-ui-config.md`](apply-ui-config.md).
|
|
4
|
+
> Pipeline: [`agent-execution-flow.md`](agent-execution-flow.md).
|
|
5
|
+
|
|
6
|
+
This doc tells the agent **exactly** how to wait for the client to finish the wizard, capture the JSON output, and apply **every** change without omission.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Prime rule
|
|
11
|
+
|
|
12
|
+
**Do not apply wizard changes until the client has submitted the wizard.**
|
|
13
|
+
|
|
14
|
+
- **AWS (`customize-ui`):** CLI blocks and polls until status `ready` — wait for CLI success message.
|
|
15
|
+
- **Local (`customize`):** CLI blocks until client saves in browser — wait for `✅ UI configuration saved`.
|
|
16
|
+
|
|
17
|
+
**Do not** guess final colors from memory, skip the diff, or proceed to deploy while `survey-ui-config.json` still holds the **seed** (AWS review mode).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## AWS flow (default — review mode)
|
|
22
|
+
|
|
23
|
+
### Step 1 — Agent runs CLI (and waits)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
export CFM_INSTANCE_ID="<JWT>"
|
|
27
|
+
export CFM_DEPLOY_API_BASE="<EC2 URL>"
|
|
28
|
+
npx cfm-sdk customize-ui
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Default is review mode** (no flags). The CLI will:
|
|
32
|
+
|
|
33
|
+
1. Export component preview pages (`export-previews`)
|
|
34
|
+
2. Upload preview HTML to S3 (one page per component key — `header`, `footer`, `MCQ_single`, …)
|
|
35
|
+
3. Print the **deployed EC2 wizard link** — agent **must share this URL with the client**
|
|
36
|
+
4. **Poll every ~3s** (`GET /wizard/config/:surveyId`) until the client submits
|
|
37
|
+
5. Print `✅ Configuration ready` when `status === 'ready'`
|
|
38
|
+
|
|
39
|
+
### Deployed wizard link (give to client after S3 upload)
|
|
40
|
+
|
|
41
|
+
The client does **not** use localhost. After previews are uploaded, the CLI prints:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
🔗 Client wizard link — share with the client:
|
|
45
|
+
http://43.204.26.213:3000/wizard-app/index.html?session=<uuid>&secret=<hex>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- **Previews:** stored in S3 under `sites/{surveyId}/wizard-sessions/{sessionId}/previews/`; wizard iframes load them via EC2 proxy (`GET /wizard/preview/:sessionId/:component/...`)
|
|
49
|
+
- **Wizard UI:** served from EC2 at `/wizard-app/` (not CloudFront `sites/_wizard` — agents and clients use the EC2 link from `customize-ui`)
|
|
50
|
+
|
|
51
|
+
Set `CFM_DEPLOY_API_BASE=http://43.204.26.213:3000` (or your EC2 host). The link is built from that base + session credentials returned by `POST /wizard/session/start`.
|
|
52
|
+
|
|
53
|
+
**Agent must:**
|
|
54
|
+
|
|
55
|
+
- [ ] Keep the terminal process **running** — do not Ctrl+C while polling
|
|
56
|
+
- [ ] Tell the client: *"Please complete all wizard steps and click **Review & Build** / save to finish."*
|
|
57
|
+
- [ ] Wait until CLI exits **0** with `Configuration ready`
|
|
58
|
+
- [ ] **Not** start Phase 6c apply until this completes
|
|
59
|
+
|
|
60
|
+
**Timeout:** default 2 hours (`CFM_WIZARD_TIMEOUT_MS`). If timeout, ask client to re-run or use `fetch-ui-config` (see §5).
|
|
61
|
+
|
|
62
|
+
### Step 2 — Review artifacts (written on success)
|
|
63
|
+
|
|
64
|
+
| File | Role |
|
|
65
|
+
|------|------|
|
|
66
|
+
| `survey-ui-config.seed.json` | Snapshot before client edits |
|
|
67
|
+
| `survey-ui-config.final.json` | Client config + `global.logo.url` (public CloudFront URL) |
|
|
68
|
+
| `survey-ui-config.diff.json` / `.diff.md` | Every changed path — **read before apply** |
|
|
69
|
+
| `survey-ui-config.json` | Still **seed** until `confirm-ui-config` |
|
|
70
|
+
| `public/{logoFileName}` | Logo file downloaded from `logoUrl` |
|
|
71
|
+
|
|
72
|
+
Poll response includes `logoUrl` and `logoKey` — CLI merges `logo.url` into final JSON.
|
|
73
|
+
|
|
74
|
+
**If all diff counts are 0:** client submitted without changes — still verify; skip heavy apply.
|
|
75
|
+
|
|
76
|
+
### S3 garbage collection
|
|
77
|
+
|
|
78
|
+
| When | Deleted | Kept |
|
|
79
|
+
|------|---------|------|
|
|
80
|
+
| Client **Review & Build** | `wizard-sessions/{sessionId}/` (previews, seed-config, temp logo) | `sites/{surveyId}/assets/{logo}`, `wizard/config.json` |
|
|
81
|
+
| Session **expires** (2h default) | Same session prefix — auto sweep every 5 min | N/A |
|
|
82
|
+
|
|
83
|
+
### Step 3 — Agent reads diff before touching code
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Agent MUST open and read:
|
|
87
|
+
cat survey-ui-config.diff.md
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
For **every** section in the diff (`Changed`, `Added`, `Removed`):
|
|
91
|
+
|
|
92
|
+
1. Find the config path (e.g. `global.colorScheme.primary`)
|
|
93
|
+
2. Look up apply target in [`apply-ui-config.md`](apply-ui-config.md) § Complete mapping
|
|
94
|
+
3. Apply to the listed file/CSS var/`data-cfm-*` attribute
|
|
95
|
+
4. Mark the path done (mental checklist or notes in `implementation_plan.md`)
|
|
96
|
+
|
|
97
|
+
**Blocking rule:** If a path appears in the diff, it **must** be reflected in the codebase after Phase 6c.
|
|
98
|
+
|
|
99
|
+
### Step 4 — Apply to codebase (Phase 6c)
|
|
100
|
+
|
|
101
|
+
Follow [`apply-ui-config.md`](apply-ui-config.md) using **`survey-ui-config.final.json`** as input.
|
|
102
|
+
|
|
103
|
+
Order:
|
|
104
|
+
|
|
105
|
+
1. Validate `survey-ui-config.final.json` against `templates/survey-ui-config.schema.json`
|
|
106
|
+
2. Regenerate `src/styles/survey-theme.css` from **all** tokens in final config (not only diff paths — full sync prevents missed derived vars)
|
|
107
|
+
3. Apply `data-cfm-*` content patches (title, buttons, footer links, logo)
|
|
108
|
+
4. Apply layout toggles in `SurveyPage` / chrome
|
|
109
|
+
5. Apply `placeholders`, `customFields`, `debug` in hook options
|
|
110
|
+
6. Re-run `bash templates/verify-agent-build.sh` and `npm run build`
|
|
111
|
+
|
|
112
|
+
### Step 5 — Promote config + logo
|
|
113
|
+
|
|
114
|
+
After codebase apply succeeds:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
export CFM_INSTANCE_ID="<JWT>"
|
|
118
|
+
export CFM_DEPLOY_API_BASE="<EC2 URL>"
|
|
119
|
+
npx cfm-sdk confirm-ui-config
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This:
|
|
123
|
+
|
|
124
|
+
- Copies `survey-ui-config.final.json` → `survey-ui-config.json`
|
|
125
|
+
- Downloads logo to `public/{fileName}` when `global.logo.fileName` is set
|
|
126
|
+
|
|
127
|
+
**Do not run `confirm-ui-config` before applying tokens to the codebase** — you would promote JSON while the UI still shows seed styling.
|
|
128
|
+
|
|
129
|
+
Optional: `npx cfm-sdk confirm-ui-config --diff-only` to re-print diff without writing.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Local flow (`customize`)
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx cfm-sdk customize
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
1. CLI starts wizard at `http://localhost:4200`
|
|
140
|
+
2. **Blocks** until client clicks save → `POST /api/save-config`
|
|
141
|
+
3. Writes **`survey-ui-config.json` directly** (no `.final.json` / diff artifacts)
|
|
142
|
+
4. Prints `✅ UI configuration saved` and exits
|
|
143
|
+
|
|
144
|
+
**Agent must:**
|
|
145
|
+
|
|
146
|
+
- [ ] Wait for CLI to exit 0 after client saves
|
|
147
|
+
- [ ] Apply from `survey-ui-config.json` per [`apply-ui-config.md`](apply-ui-config.md)
|
|
148
|
+
- [ ] No `confirm-ui-config` step (not used locally)
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Legacy AWS mode (`--apply`)
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npx cfm-sdk customize-ui --apply
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Writes final config + logo immediately (no review artifacts). Still requires Phase 6c codebase apply from `survey-ui-config.json`.
|
|
159
|
+
|
|
160
|
+
**Prefer default review mode** so the agent can audit `survey-ui-config.diff.md` before apply.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Detached session (`--no-wait`)
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npx cfm-sdk customize-ui --no-wait
|
|
168
|
+
# CLI prints wizard URL and exits — client works asynchronously
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
When client finishes:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
export CFM_WIZARD_SESSION_ID="<sessionId from CLI output>"
|
|
175
|
+
npx cfm-sdk fetch-ui-config
|
|
176
|
+
# Writes .final.json + .diff.md — then apply + confirm-ui-config
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Do not apply** until `fetch-ui-config` succeeds.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Agent ↔ client script
|
|
184
|
+
|
|
185
|
+
**When starting wizard (tell client after you send the link):**
|
|
186
|
+
|
|
187
|
+
> *"I've uploaded your survey component previews to the cloud. Open this customization link: [paste deployed wizard URL]. Adjust branding, colors, and question-type styling — the preview panel shows your real components. When finished, click **Review & Build** on the last step. I'll wait here until your changes are saved."*
|
|
188
|
+
|
|
189
|
+
**While waiting (agent):**
|
|
190
|
+
|
|
191
|
+
- Do not refactor unrelated code
|
|
192
|
+
- Do not start deploy
|
|
193
|
+
- Do not re-run `customize-ui` (overwrites session artifacts)
|
|
194
|
+
|
|
195
|
+
**After CLI success (tell client):**
|
|
196
|
+
|
|
197
|
+
> *"Your wizard changes are captured. I'm applying them to the survey UI now and will verify the build."*
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Phase checklist
|
|
202
|
+
|
|
203
|
+
### Phase 6b — Wizard session
|
|
204
|
+
|
|
205
|
+
- [ ] Client explicitly said yes to wizard (INPUT 3)
|
|
206
|
+
- [ ] `CFM_INSTANCE_ID` and `CFM_DEPLOY_API_BASE` set
|
|
207
|
+
- [ ] Ran `npx cfm-sdk customize-ui` (or `customize` locally)
|
|
208
|
+
- [ ] **Waited** until CLI exit 0 (`Configuration ready` or `UI configuration saved`)
|
|
209
|
+
- [ ] AWS: `survey-ui-config.final.json` and `survey-ui-config.diff.md` exist
|
|
210
|
+
- [ ] Read `survey-ui-config.diff.md` completely
|
|
211
|
+
|
|
212
|
+
### Phase 6c — Apply (no skipped paths)
|
|
213
|
+
|
|
214
|
+
- [ ] Applied from **`survey-ui-config.final.json`** (AWS) or **`survey-ui-config.json`** (local)
|
|
215
|
+
- [ ] Every diff path in `changed` + `added` + `removed` addressed
|
|
216
|
+
- [ ] `src/styles/survey-theme.css` fully synced to final config
|
|
217
|
+
- [ ] All `data-cfm-*` content hooks updated
|
|
218
|
+
- [ ] Logo file exists in `public/` when config has `global.logo.fileName`
|
|
219
|
+
- [ ] `placeholders` / `customFields` / `debug` wired if present in final
|
|
220
|
+
- [ ] AWS: ran `npx cfm-sdk confirm-ui-config` after codebase apply
|
|
221
|
+
- [ ] `verify-agent-build.sh` + `npm run build` pass
|
|
222
|
+
- [ ] Visually spot-check: header, footer, progress, one question type from inventory
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Common mistakes
|
|
227
|
+
|
|
228
|
+
| Mistake | Fix |
|
|
229
|
+
|---------|-----|
|
|
230
|
+
| Killed CLI during poll | Re-run `customize-ui`; client re-submits |
|
|
231
|
+
| Applied from `survey-ui-config.json` while still seed | Use `.final.json` or run `confirm-ui-config` after apply |
|
|
232
|
+
| Only changed primary color, ignored diff | Read **entire** `diff.md` — clients often change 20+ paths |
|
|
233
|
+
| Skipped `confirm-ui-config` | Active JSON stays seed; next wizard re-open is wrong |
|
|
234
|
+
| Changed `Question.tsx` dispatch during apply | UI tokens only — see `apply-ui-config.md` scope |
|
|
235
|
+
| Proceeded to deploy before apply | Complete Phase 6c first |
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Related docs
|
|
240
|
+
|
|
241
|
+
| Doc | Role |
|
|
242
|
+
|-----|------|
|
|
243
|
+
| [`apply-ui-config.md`](apply-ui-config.md) | Complete config path → file mapping |
|
|
244
|
+
| [`wizard-api.md`](wizard-api.md) | Poll endpoint, complete payload |
|
|
245
|
+
| [`wizard-question-type-styling.md`](wizard-question-type-styling.md) | Per-type CSS vars |
|
|
246
|
+
| [`agent-operating-contract.md`](agent-operating-contract.md) | Anti-hallucination gates |
|