Files
conversation-history/SquareMCP/deployments/2026-06-16-phase1-week3-chat-ui-deploy-handoff.md
T

174 lines
8.9 KiB
Markdown

# Phase 1 Communications — Week 3 (Chat UI) — Engineering Handoff for kimi-cli
**Date:** 2026-06-16
**Branch:** `main`
**Author:** Claude Code
**Status:** READY TO DEPLOY — code complete, `npx tsc --noEmit` clean. NOT yet committed, NOT yet visually QA'd in a browser (built under a no-docker/no-dev-server constraint this session).
**Do not deploy:** No new env vars required. No new npm packages. Drop-in to existing hermes-mcp image build.
---
> ⚠️ **CRITICAL — DO NOT LEAVE DOCKER RUNNING**
>
> After building and pushing the image, **stop and remove all local Docker containers** before kubectl apply.
> Docker left running has previously caused port conflicts with the production Kubernetes cluster, breaking live services.
>
> ```bash
> docker stop $(docker ps -q) 2>/dev/null || true
> docker rm $(docker ps -aq) 2>/dev/null || true
> ```
>
> Verify nothing is bound to the relevant ports before applying to k8s:
> ```bash
> ss -tlnp | grep -E ':(80|443|3000|8080)'
> ```
>
> Only proceed with `kubectl apply` once Docker containers are confirmed stopped.
---
## What was built
Week 3 of the sprint plan: the chat UI, onboarding flow, and hardening on top of the Week 1+2 backend (already live — see `2026-06-15-phase1-communications-deploy-handoff.md`). This is the user-facing dashboard tab plus three small backend gaps closed along the way.
### Backend additions (closing gaps found vs. the engineering design doc)
- `PUT /api/communications/drafts/:draft_id` — edit `draft_text`/`draft_metadata` directly without an AI call (manual edits + Instagram `image_url` attachment use this same endpoint; metadata is shallow-merged server-side so `image_url` doesn't clobber `hashtags`).
- `GET /api/communications/status` / `PUT /api/communications/status` — exposes `approved_posts_count` and `autonomous_mode_enabled`; the PUT enforces the 10-approval gate server-side (defense in depth, not just a UI check).
### Frontend additions (vanilla JS dashboard, NOT React — the sprint plan mentions a "React SPA" but this repo's `product/app/` is plain HTML/CSS/JS with global-scope `<script>` tags, same pattern as the rest of the dashboard)
- New "Communications" nav tab and section in `product/app/index.html`.
- New `product/app/communications.js` — profile form (vertical-specific fields for mortgage_broker incl. NMLS, email recipients), onboarding chips, chat-driven draft generation, per-draft edit/save/regenerate/reject, failed-platform retry (re-calls `/chat` scoped to one platform since failed generations have no `draft_id` to `/regenerate`), approve-all + publish results, autonomous-mode toggle gated on `approved_posts_count >= 10`.
- New `.comm-*` CSS rules in `product/app/styles.css` matching the existing dark theme tokens (`--bg`, `--surface`, `--accent`, `--border`, `--radius`) and existing component conventions (`.btn`, `.status-badge`, card patterns).
- Small hook in `product/app/app.js`'s nav-link handler to toggle the new section and lazy-init `communications.js` on first visit.
Auth: no new auth path needed — `meterMiddleware` already accepts the dashboard's existing session cookie in addition to `x-api-key`, so the new routes work with the logged-in browser session as-is.
Sprint plan item 3.3 (learning-loop activation) required **no new work** — confirmed it was already implemented server-side in the Week 1+2 deploy (`getRecentExamples()` in `src/communications-chat.ts` injects the last 3 approved examples per platform into the Claude system prompt).
Sprint plan item 3.5 (pilot kickoff) is a business/ops action, not code — out of scope here.
---
## Files changed
### Modified
- `src/communications.ts` — added `updateDraftFields()`, `CommStatus` interface, `getCommStatus()`, `setAutonomousMode()`
- `src/index.ts` — added 3 imports + 3 route handlers (`PUT /drafts/:draft_id`, `GET`/`PUT /status`)
- `product/app/index.html` — new nav-link + `<section id="communications-section">` (profile form/summary + chat/drafts markup)
- `product/app/app.js` — nav-link handler now toggles the Communications section and calls `window.initCommunications()` on first view
- `product/app/styles.css` — ~330 new lines of `.comm-*` rules
### Created
- `product/app/communications.js` — all Week 3 chat UI logic (~330 lines)
### No changes to
- `package.json` — no new dependencies
- `hermes-k8s.yaml` — no new env vars needed
- `Dockerfile` — unchanged
- `src/db.ts` / schema — no new tables or columns this round (Week 1+2 schema already covers this UI)
- Any existing routes, tools, or OAuth logic
```
product/app/app.js | 2 +
product/app/index.html | 87 +++++++++++++
product/app/styles.css | 328 +++++++++++++++++++++++++++++++++++++++++++++++++
src/communications.ts | 61 +++++++++
src/index.ts | 44 +++++++
5 files changed, 522 insertions(+)
```
(plus the new `product/app/communications.js` file, currently untracked)
---
## What was verified this session vs. what was NOT
**Verified:**
- `npx tsc --noEmit` — clean, zero errors, after all backend changes.
**NOT verified (constraint: no docker, no dev server, no production DB/Redis touch this session):**
- No visual/browser QA of the new Communications tab — clicking through profile creation, chat generation, draft editing, approve/publish has not been exercised in a live browser.
- No integration test against a running server.
**kimi-cli should do a manual click-through after deploying to staging/production** before treating this as fully verified: create a profile, generate a draft via chat, edit text, attach an Instagram image URL, approve+publish, and confirm the autonomous toggle stays hidden below 10 approvals.
---
## Deploy commands
```bash
# 1. Commit the implementation
git add src/communications.ts src/index.ts product/app/index.html product/app/app.js product/app/styles.css product/app/communications.js
git commit -m "feat(communications): Week 3 — chat UI, onboarding, draft editing, status endpoints"
git push origin main
# 2. Build and push image
docker build -t <registry>/hermes-mcp:<sha> .
docker push <registry>/hermes-mcp:<sha>
# ⚠️ 3. STOP DOCKER BEFORE APPLYING TO K8S
docker stop $(docker ps -q) 2>/dev/null || true
docker rm $(docker ps -aq) 2>/dev/null || true
ss -tlnp | grep -E ':(80|443|3000|8080)' # must be empty before proceeding
# 4. Update image SHA in hermes-k8s.yaml, then apply
kubectl apply -f hermes-k8s.yaml
# 5. Verify rollout
kubectl rollout status deployment/hermes-mcp
kubectl logs -l app=hermes-mcp --tail=50 | grep '\[db\]'
```
No schema migration runs this time — `initDatabase()` has nothing new to create.
---
## Verification
```bash
BASE=https://hermes.squaremcp.com
KEY=<your-api-key>
# 1. Edit a draft directly (no AI call)
curl -X PUT "$BASE/api/communications/drafts/<draft_id>" \
-H "x-api-key: $KEY" -H "Content-Type: application/json" \
-d '{"draft_text": "Updated text", "draft_metadata": {"image_url": "https://example.com/img.jpg"}}'
# Expected: 200 with updated draft (only works while draft status is "pending")
# 2. Get communications status
curl "$BASE/api/communications/status" -H "x-api-key: $KEY"
# Expected: 200 { approved_posts_count, autonomous_mode_enabled }
# 3. Try enabling autonomous mode below threshold
curl -X PUT "$BASE/api/communications/status" \
-H "x-api-key: $KEY" -H "Content-Type: application/json" \
-d '{"autonomous_mode_enabled": true}'
# Expected: 400 "Autonomous mode unlocks after 10 approved posts" if approved_posts_count < 10
```
Then in a browser: log into the dashboard, click the new "Communications" nav tab, and walk through profile creation → chat prompt → draft edit → approve/publish.
---
## Open items for the engineer
1. **Browser QA** — see "What was NOT verified" above. Do this before telling Alex Ferrari the tab exists.
2. **React SPA mismatch** — the original sprint plan and engineering design doc both mention a "React SPA" for the chat interface. This repo's dashboard has no React; Week 3 was implemented in the same vanilla JS pattern as the rest of `product/app/`. If a React rewrite is actually wanted later, treat this as a known divergence from the design doc, not a bug.
3. **Instagram approve gate** — the UI disables the "include" checkbox for Instagram drafts missing `image_url` and shows a "(required to approve)" hint; confirm this matches what you want pilot users to see.
---
## Related vault docs
- Previous handoff (Week 1+2 backend): `SquareMCP/deployments/2026-06-15-phase1-communications-deploy-handoff.md`
- Sprint plan: `SquareMCP/products/chat-first-communications/2026-06-15-phase1-mvp-sprint-plan.md`
- Engineering design: `SquareMCP/products/chat-first-communications/2026-06-15-phase1-engineering-design.md`
- Product spec: `SquareMCP/products/chat-first-communications/2026-06-15-comprehensive-product-spec.md`
---
## Changelog
| Date | Author | Note |
|------|--------|------|
| 2026-06-16 | Claude Code | Initial handoff — Week 3 chat UI complete, built with no-docker constraint, not yet committed or browser-tested |