# VC 164 — Phase B build ALIGN plan (chat builds → project folder) **Status**: ALIGN-only dispatch (READ + plan). No code, no commits, no deploys. **Author**: id 9 (avidcreation-mavis). **Goal**: Align the 4-sub-phase implementation plan before any code lands. Each sub-phase ships as its own T3 dispatch. --- ## ALIGN — 8 layers ### [1] git - HEAD: `fd355ff368ed06200570e12e1bba8ebfe10d655a` (VC 154 SHIPPED) - origin/main: `fd355ff368ed06200570e12e1bba8ebfe10d655a` - Divergence: 0/0 - Working tree: clean (only `.mavis/` untracked) - Locked reflex #105 (explicit-branch workflow) applies to every sub-phase **Per-sub-phase git pattern** (4 separate branches): - `feat/id9-vc164b1-post-build-hook` → merge --no-ff → push → delete branch - `feat/id9-vc164b2-vibechat-tools` → same - `feat/id9-vc164b3-switcher-auto-include` → same - `feat/id9-vc164b4-list-endpoint` → same (optional) ### [2] deploy **Per-sub-phase**: - B.1, B.3, B.4: bridge-side change → `systemctl restart vibecoder-bridge` + sibling-route probe - B.2: frontend + bridge → build (`npm run build`), tarball deploy, bridge restart, smoke **Verification** (canonical end-to-end): - `prompt "build me a coffee shop"` → chat → cascade → bridge post-build hook fires → folder created → switcher dropdown updates → home canvas renders chat-built project - Each sub-phase verified independently before next dispatched **Deployment protection**: - Bridge NOT restarted until sub-phase is verified locally (node --check + grep for required exports) - Mirror ALL bridge changes in monolith (`bridge/main.cjs` + `bridge-server/` if split) per VC 56 lesson - No in-place edits to deployed `/var/www/...` — source-only, deploy via the established path ### [3] HQ **Per-sub-phase**: - Bulletin (≤2048 bytes body): `POST /api/mavis/bulletin` with `level=info|warn|error`, summary + commit + verification result - Doc (long form, posted via post_bulletin.sh if body > 8192 bytes): full Step 0/1/2/3 narrative + diff stats + smoke results - Bulletin id + doc id back-referenced in next dispatch **Cross-references**: - VC 163 (d000326): scoping doc — base - VC 156 (d000319): FC_REQUIREMENTS.md §1/§2/§3/§8 — annotation.json field shape - VC 157 (d000302): output shapes audit — Cinema /api/agent/cinema/save_scene pattern to mirror - VC 154 (d000314): Phase A HOME canvas — sibling feature - VC 150 (d000288): sample-project 4-file scaffold — base pattern ### [4] Notion SKIPPED (no `NOTION_API_KEY` in sandbox env, consistent with VC 145/147/150/153/156/157/163). All detail lives in HQ doc. ### [5] memory **Per-sub-phase** (additive, no overwrite of existing): - Locked reflex per sub-phase (e.g. B.1 locks the tail-write invariant) - Cross-project tag if the pattern applies beyond Phase B (likely: yes — any future "AI generates → filesystem" pipeline) - Cumulative reflexes table updated **Reflexes already locked in scoping (VC 163)**: - 9-#241: tail-write for cascade → fs (manifest/version first, primary content last) - 9-#242: deployed-URL vs. local-folder at origin field (don't merge schemes) **To lock in B.1**: - Bridge write endpoints MUST mirror in monolith (`bridge/main.cjs` + `bridge-server/`); split-brain = silent bug **To lock in B.2**: - VibeChat tool operator-only = schema marker + dispatch-side session check, NOT LLM-side restriction (LLM-side is cosmetic) **To lock in B.3**: - WDM registry merge path: server-side list → localStorage merge on init + window focus, NOT continuous polling (sandbox-ephemeral trap) ### [6] task board n/a — single-agent T3s, no parallel agents on this work. ### [7] report **Per-sub-phase** (inline reply to operator): - Heart (1 line): what shipped - Meat (4-6 lines): verification + smoke result + key files - Reminder (3 bullets): next sub-phase + open decisions + commit hash - USAGE line per VC 178 - Footer: `PROMPT #VC 164b | id 9` **This dispatch's report**: this doc IS the deliverable. ALIGN [1-8] + DELIVERABLE inline reply. HARD STOP. ### [8] doctrine **Phase B does NOT change doctrine**. It consumes existing patterns: - FvW §40/§45 → annotation.json shape - VC 157 findings → file types and persistence paths - VC 150/154 → 4-file base shape (VERSION → MANIFEST → annotation → index.html) - bridge/lib/fs-safe.cjs writeToBridgeDir() → EACCES fallback pattern - bridge/routes/cinema.cjs save_scene → cascade-output → fs pattern **FC lane coordination** (b004187 = ACCEPT WITH EDITS verdict on d000319): - Post-write re-index hook for FC lane is OUT OF SCOPE for v1 - Coordinate with FC lane (thread 11) before B.3 ships — chat-built projects need FC index visibility **Cross-project doctrine observation**: - The "AI generates → fs" pattern repeats: Cinema render, VSIL scene save, now Phase B project folders. All use `writeToBridgeDir` + tail-write + manifest-first. This IS the canonical FreshVibe persistence pattern for AI-generated content. Lock it as doctrine candidate for v9. --- ## DELIVERABLE **This dispatch (VC 164, ALIGN-only)**: - ✅ Phase 0 VA probe bounded retry (4 attempts, 15/30/60s backoff per VC 177) — VA UP at attempt 1 - ✅ Step 0 — repo state, scoping doc read, source-side feasibility for each B.1–B.4 - ✅ ALIGN plan written to this doc - ✅ Bulletin b004248 posted (info level, pointer to ALIGN plan) - ⏸ NO code changes, NO commits, NO deploys (per dispatch HARD STOP after ALIGN) - 📌 AWAITING operator dispatch: `PROMPT #VC 164b1` (B.1 — bridge post-build hook) as separate T3 **Sub-phase dispatches queued** (each as its own T3): - `PROMPT #VC 164b1` — B.1 bridge post-build hook (~1 working day) - `PROMPT #VC 164b2` — B.2 VibeChat tools (~2 working days) - `PROMPT #VC 164b3` — B.3 switcher auto-include (~1 working day) - `PROMPT #VC 164b4` — B.4 list endpoint (~0.5 working day, optional) **Operator decisions to make before B.1 dispatch**: 1. Branch naming: `feat/id9-vc164b1-post-build-hook` (my proposal) or operator preference? 2. Bridge monolith split: keep `bridge/main.cjs` + `bridge-server/` parity per VC 56 (my proposal) or single track? 3. Server-side registry path: `/var/www/freshvibeapps/clients/vibecoder/clients/_chat-builds.json` (my proposal) or somewhere else? 4. Hook trigger: only when `/api/agent/ai/chat` matches `__isOriginBuild` regex (current scoping) or any build-style prompt? --- ## Step 0 — feasibility findings (this dispatch) **B.1 feasible**: `bridge/lib/chat-handler.cjs:358` is the cascade completion point. `result` from `multiStepDriver.buildOrigin()` already has `{ok, files, validation, workspaceRoot, attempt}`. `bridge/lib/fs-safe.cjs:33` has `writeToBridgeDir()` with EACCES fallback. Tail-write strategy in scoping (manifest/version first, primary last) is implementable. **B.2 feasible**: `src/vibechat/tools.ts:413` has `register_project` pattern (schema + handler). Adding `create_project` + `save_build` follows the same shape. Operator-only semantics via schema marker (`operatorOnly: true`) + dispatch-side session check (already in `bridge/middleware/auth.cjs`). **B.3 feasible**: `src/host/workspace/registry.ts:108` has `bootstrapBuiltInProjects()` seeding pattern. Adding `mergeServerProjects()` server-fetch path follows the same shape. `workspace-manager.ts:133` calls `listProjects()` which seeds from registry — adding server-fetch path is a 1-line change. **B.4 feasible**: `bridge/routes/chat.cjs:14` has the `/api/agent/ai/chat` mount pattern. Adding `/api/agent/list_chat_projects` in a new `routes/phase-b.cjs` is a copy-paste. Mount order: must be BEFORE `routes/agent.cjs:35` per main.cjs:28-30 comment. --- ## Cross-references - **VC 163** (d000326, id 9, 2026-09-20): Phase B scoping doc — base reference for this dispatch - **VC 156** (d000319, id 9): FC_REQUIREMENTS.md §1/§2/§3/§8 — annotation.json shape - **VC 157** (d000302, id 9): output shapes audit (Cinema/VSIL/Origin/VibeScope) - **VC 154** (d000314, id 9): Phase A HOME canvas — sibling feature - **VC 150** (d000288, id 9): sample-project 4-file scaffold — base shape pattern - **VC 145** (id 9): four hardcoded deployed-URL built-ins — confirms no collision - **VC 161** (d000319, id 9): FvW location correction — `gallery-pact/fvw/` (gallery repo, owner id 8) per VC 161 correction - **VC 177** (id 44): Phase 0 VA probe bounded retry — applied at this dispatch attempt 1 - **VC 178** (id 44): USAGE tracking — USAGE line in every sub-phase report - **VC 56** (id 9, 2026-09-16): VPS write-endpoint canonical pattern (mirror monolith + modular bridge) — applies to B.1 + B.4 - **VC 168** (id 44): dispatch templates T1/T2/T3 — each sub-phase ships as T3 - **FC lane** (thread 11): b004187 ACCEPT WITH EDITS verdict on d000317/d000319 — coordinate on post-write re-index hook (B.3) --- PROMPT #VC 164 | id 9