# Flow start points — design-studio Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** A "Start points" palette section to drop a Webhook start box on the canvas, a webhook box panel, and the `start` box labelled "Web start", replacing the "Start from webhook" toggle of the `start` panel.

**Architecture:** `WebhookService` gains start-point calls matching the server routes; a pure `utils-start-points.ts` holds the type list and the "one per type" rule; the palette gets a new category whose items create a marker block (`attributes.start_point`) instead of an action; the intent component renders marker blocks as start boxes; a start-point panel replaces the webhook section of the start panel.

**Tech Stack:** Angular 14, Node 16 (nvm), Jasmine/Karma via the workspace harness.

**Spec:** `tiledesk-server/docs/superpowers/specs/2026-09-30-flow-start-points-design.md` (§6, §8).

## Global Constraints

- Repo `/Users/nicocardone/Desktop/DEV/TILEDESK/design-studio`, branch `feature/webhook-chatbot-hitl`. Never push. Commit trailer: blank line + `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`.
- Node 16 prefix for every npm/npx: `source ~/.nvm/nvm.sh >/dev/null && nvm use 16 >/dev/null && `. Never npm install/ci.
- Server API (tiledesk-server plan): `PUT {API}/{projectId}/webhooks/{chatbot_id}/start_points/{type}` body `{block_id, enabled?, mapping?:{source_name?}, confirm?}`; `DELETE` same path; 409 = automation webhook exists (confirm needed); `GET {API}/{projectId}/webhooks/{chatbot_id}` returns `start_points`.
- Start point types in UI: `web` (implicit = the `start` block, never sent to the server) and `webhook`. Block marker `attributes.start_point = 'webhook'`; default block name `"Webhook start"`; identify start boxes by the marker, never by name.
- Palette category key `START_POINTS`, label key `CDSActionCategory.StartPoints` = "Start points"; shown only for chatbot subtype `chatbot`.
- One per type: an item whose type is present is disabled with tooltip "Already in this flow"; click focuses the box.
- Automation-webhook confirmation text (reuse existing i18n key of `needsSwitchConfirmation`): "This chatbot already has a webhook that runs a block without a conversation. Switching it will make calls start conversations from the start block. Continue?" → retry with `confirm: true`.
- Change department help (en.json `CDSActionList.DOC.ChangeDept` description) gains: "In conversations started by a webhook, changing department re-routes the conversation and removes the chatbot."
- Remove from the `start` panel the "Start from webhook" section and its code (`createStartWebhook`, `updateWebhookSettings`, `utils-webhook.ts` toggle helpers and their specs) — replaced, not kept.
- Specs run with the workspace harness: `npx ng test --watch=false --browsers=ChromeHeadless --main=.superpowers/sdd/2026-09-29-hitl-participant-removal-design-studio/test-hitl.ts --ts-config=.superpowers/sdd/2026-09-29-hitl-participant-removal-design-studio/tsconfig.hitl-specs.json` (untracked harness; register new specs there, don't commit it). `npx ng build` must exit 0 with no new warnings; delete `dist/`.
- A live `ng serve --port 4204` of this checkout may be running; don't kill it.

## Review Focus

1. Dropping Webhook start twice quickly → one box, one start point (disable the item while the create is pending).
2. PUT fails after the block was created → the block is deleted again and an error toast shown (no orphan box).
3. Chatbot subtype `webhook`/`copilot` → no "Start points" category; their `webhook` block unchanged.
4. Reloading a flow whose webhook has a start point whose block is missing → the palette item is enabled again (start point treated as absent).
5. Published/read-only mode (`readOnlyService` if present on the branch) → palette items disabled, panel read-only.

---

### Task 1: start-point service calls and type rules

**Files:**
- Modify: `src/app/chatbot-design-studio/services/webhook-service.service.ts` (add methods; remove `createStartWebhook`, `updateWebhookSettings`)
- Create: `src/app/chatbot-design-studio/utils-start-points.ts`
- Replace: `src/app/chatbot-design-studio/utils-webhook.ts` toggle helpers (delete the file and its spec if nothing else uses them)
- Test: `webhook-service.service.spec.ts`, `utils-start-points.spec.ts`

**Interfaces:**
- Produces `WebhookService.upsertStartPoint(chatbot_id: string, type: 'webhook', body: { block_id: string, enabled?: boolean, mapping?: { source_name?: string }, confirm?: boolean }): Observable<any>` and `deleteStartPoint(chatbot_id: string, type: 'webhook'): Observable<any>`.
- Produces in `utils-start-points.ts`: `START_POINT_TYPES = ['web','webhook']`, `START_POINT_MARKER = 'start_point'`, `startPointTypeOf(intent): 'web' | 'webhook' | null` (`web` for the block named `start`, marker value otherwise), `presentStartPointTypes(intents, webhook): string[]` (web always; webhook only when the webhook has a `webhook` start point whose `block_id` is an existing intent carrying the marker).

- [ ] **Step 1: Failing specs:** HttpTestingController asserts PUT/DELETE URLs and bodies (`{block_id:'b1', enabled:true}` → `PUT https://api.test/p1/webhooks/bot1/start_points/webhook`); `presentStartPointTypes` cases: no webhook → `['web']`; start point + marker block → `['web','webhook']`; start point whose block is missing → `['web']` (Review Focus 4).
- [ ] **Step 2: Run** the harness → compile errors for the missing members.
- [ ] **Step 3: Implement**; remove the old toggle helpers and the `start` panel webhook section together with its template/i18n usage.
- [ ] **Step 4: Run** the harness → pass; report TOTAL.
- [ ] **Step 5: Commit** — `feat(start-points): service calls and start point rules`.

### Task 2: "Start points" palette section

**Files:**
- Modify: `src/app/chatbot-design-studio/utils-actions.ts` (`TYPE_ACTION_CATEGORY.START_POINTS = 'Start points'`, `ACTION_CATEGORY` entry, icon `assets/images/actions_category/start_points.svg` new)
- Modify: `cds-dashboard/cds-canvas/cds-panel-elements/cds-panel-elements.component.{ts,html}` (category items come from start point types, not `ACTIONS_LIST`; disabled state; hidden unless subtype `chatbot`)
- Modify: `cds-dashboard/cds-canvas/cds-canvas.component.ts` (drop of a start-point item → create marker block at the drop position, then `upsertStartPoint`; 409 → confirmation → retry with `confirm:true`; failure → delete the block, toast)
- Modify: `src/assets/i18n/en.json`
- Test: `cds-panel-elements.component.spec.ts` (harness), plus a pure helper spec if the drop logic is extracted (`createStartPointBox(...)` in `utils-start-points.ts` recommended)

**Interfaces:**
- Consumes Task 1 methods and helpers.
- Produces `createStartPointBlock(type: 'webhook', pos: {x:number,y:number}): Intent` — name "Webhook start", `attributes.start_point = type`, `attributes.position = pos`, `attributes.readonly = true`, actions `[ { _tdActionType: 'intent', intentName: '' } ]` like the `start` block.

- [ ] **Step 1: Failing specs:** category hidden for subtype `webhook`; items `Web` (always disabled, focus action) and `Webhook` (enabled when absent, disabled with tooltip "Already in this flow" when present, disabled while a create is pending — Review Focus 1); `createStartPointBlock` output as above.
- [ ] **Step 2: Run** → fail.
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run** harness → pass.
- [ ] **Step 5: Commit** — `feat(start-points): palette section to add a webhook start box`.

### Task 3: start boxes and the webhook box panel

**Files:**
- Modify: `cds-dashboard/cds-canvas/cds-intent/cds-intent.component.{ts,html}` (`isStart` also true for marker blocks; label "Web start" for `start`, "Webhook start" + webhook icon for the marker; no add-action, no "Start test from here" on start boxes)
- Modify: `cds-dashboard/cds-canvas/cds-panel-intent-detail/cds-panel-intent-detail.component.{ts,html}` (webhook box panel: enabled switch → `upsertStartPoint({block_id, enabled})`; production/dev URL with copy/regenerate (existing methods); Source name → `mapping.source_name` on change; Test webhook start button (existing controller subject); hint text; Delete button → confirm → `deleteStartPoint` → delete block)
- Modify: `cds-dashboard/cds-header/cds-header.component.ts` (Test webhook start highlights the webhook box by marker instead of `start`)
- Modify: `src/assets/i18n/en.json` (labels, hint, Change department help line from Global Constraints)
- Test: `cds-panel-intent-detail` pure logic extracted to `utils-start-points.ts` where possible (`startPointPanelState(webhook, intent)` → `{enabled, sourceName, url, devUrl}`) with specs

- [ ] **Step 1: Failing specs:** `startPointPanelState` for enabled/disabled/absent; start box detection by marker (renamed block still detected; a user block named "Webhook start" without marker is not).
- [ ] **Step 2: Run** → fail.
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run** harness → pass; `npx ng build` → exit 0, no new warnings; delete `dist/`.
- [ ] **Step 5: Manual check** on the local stack (record as pending if not running): drag Webhook start, copy URL, curl → conversation runs the box; disable → 422; delete box → palette item enabled again.
- [ ] **Step 6: Commit** — `feat(start-points): start boxes and webhook start panel`.
