# Flow start points — tybot 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:** Flows can read `start_type`, and a `/start` pointing to a missing start box falls back to the `start` block.

**Architecture:** Two small changes in the tybot engine: `TiledeskChatbotUtil.updateRequestAttributes` adds the `start_type` variable from request attributes; the explicit-intent branch of `TiledeskChatbot` retries with the `start` intent when an action from a `/start` message resolves to nothing.

**Tech Stack:** Node, mocha (in-process tilebot on 10001 + mock Tiledesk API on 10002, Redis).

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

## Global Constraints

- Repo `/Users/nicocardone/Desktop/DEV/TILEDESK/tiledesk-chatbot`, branch `feature/webhook-chatbot-hitl`. Never push. Commit trailer: blank line + `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`.
- Variable name exactly `start_type`, value copied from `message.request.attributes.start_type`; not set when absent.
- Fallback only when `message.text === '/start'` and `message.attributes.action` resolves to no intent; fallback intent name `start`; warn log `"(TiledeskChatbot) Start box not found: <action>, falling back to start"`.
- Tests from `tybotRoute/`, one file per process: `API_ENDPOINT=http://localhost:10002 TILEBOT_ENDPOINT=http://localhost:10001 REDIS_HOST=localhost REDIS_PORT=6379 ../node_modules/.bin/mocha test/<file> --exit`. A live tybot may run on 3001: don't kill it.

## Review Focus

1. A widget `/start` without `action` → runs `start`, no `start_type` variable (unchanged).
2. An `action` on a non-`/start` message (e.g. a button) that points to a missing block → unchanged behaviour ("Intent not found"), no fallback.
3. `start_type` present with a payload → both `start_type` and payload keys available.

---

### Task 1: start_type variable and missing-box fallback

**Files:**
- Modify: `tybotRoute/utils/TiledeskChatbotUtil.js` (`updateRequestAttributes`, near the payload import ~850-870)
- Modify: `tybotRoute/engine/TiledeskChatbot.js` (explicit intent "Intent not found" branch ~180)
- Create: `tybotRoute/test/conversation-start_point_bot.js`, `tybotRoute/test/conversation-start_point_test.js` (mirror `conversation-webhook_bot.js` / `conversation-webhook_test.js`)

- [ ] **Step 1: Write the failing conversation tests** with a bot having blocks `start` (reply "web start|{{start_type}}") and `wbox` (intent_id `wbox-id`, reply "webhook box|{{start_type}}|{{alertname}}"):
  - `/start` with `attributes.action: '#wbox-id'` and request attributes `{start_type:'webhook', payload:{alertname:'X'}}` → reply `webhook box|webhook|X`.
  - `/start` with `attributes.action: '#missing-id'` → reply starts with `web start|`.
  - `/start` without action and no start_type → reply `web start|` (empty variable renders empty).
  - A text `hello` with `attributes.action: '#missing-id'` → no `web start` reply (no fallback).
- [ ] **Step 2: Run to verify they fail** (the first renders an empty start_type; the second answers nothing).
- [ ] **Step 3: Implement** both changes.
- [ ] **Step 4: Run** the new file, then `conversation-webhook_test.js`, `conversation-invite_human_test.js`, `conversation-remove_human_test.js` (one per process) → all pass.
- [ ] **Step 5: Commit** — `feat(engine): start_type variable and start box fallback`.
