# HITL feature — pre-branch ports 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:** In each of the four repos, build a local `feature/webhook-chatbot-hitl-PRE` branch from the pre branch that carries the whole webhook-chatbot HITL feature, tested there.

**Architecture:** One repo at a time, in the existing checkout (no new worktrees — limited disk). Create the branch from the pre branch, reinstall dependencies in place from its lockfile, cherry-pick every non-merge feature commit, resolve conflicts keeping pre-branch behaviour, test against the pre branch, then switch back and restore the feature branch's dependencies.

**Tech Stack:** git cherry-pick; npm ci; mocha (server, tybot); Angular/Karma + `ng build` (chat21-ionic Node 14, design-studio Node 16).

**Spec:** `docs/superpowers/specs/2026-09-15-webhook-chatbot-hitl-design.md` §12.1 decisions 2–3, §12.4, §12.5.

## Global Constraints

- Runs AFTER `2026-09-29-hitl-known-limits-server.md` and `2026-09-29-hitl-known-limits-tybot.md` are complete (their commits are part of the port).
- Pre branches exactly: tiledesk-server `origin/master-COLLAUDO`, tiledesk-chatbot `origin/main_pre`, chat21-ionic `origin/master-PRE`, design-studio `origin/master-pre`. `git fetch origin` first.
- New branch name exactly `feature/webhook-chatbot-hitl-PRE`, upstream unset. Never push, never merge.
- Commits to port: `git rev-list --reverse --no-merges origin/<default>..feature/webhook-chatbot-hitl` (defaults: server `master`, tybot `main`, chat21-ionic `master`, design-studio `master`), cherry-picked in that order with `git cherry-pick -x`.
- Conflict rule: keep the pre branch's code and add the feature's change; never delete pre-branch behaviour to make the change fit. Every resolution goes in the task report (file, what each side had, what was kept).
- No new git worktrees except a temporary one for a comparison run that has no `node_modules` of its own (symlinked) — and only with `df -h` showing > 2 GB free. Build outputs (`www/`, `dist/`) deleted after the build check.
- Dependencies: install in place from the checked-out lockfile — server `npm ci`; tybot `npm ci` at the repo root; chat21-ionic `source ~/.nvm/nvm.sh >/dev/null && nvm use 14 >/dev/null && npm ci --ignore-scripts`; design-studio `… nvm use 16 … npm ci`. Before each install check `df -h` shows > 5 GB free; if not, stop and report.
- End state per repo: back on `feature/webhook-chatbot-hitl`, dependencies reinstalled from its lockfile, `git status` clean (apart from pre-existing untracked files), and the controller notified that the checkout is usable again.
- Conflict-resolution commits keep the cherry-picked commit's message (git's default) — the `(cherry picked from commit …)` line from `-x` plus the original `Co-Authored-By` trailer; an extra fix commit, if needed, ends with `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>` after a blank line.

## Review Focus

1. A cherry-pick that applies cleanly but references code the pre branch renamed or removed → caught only by tests/build; the build and feature suites must run after the last pick, not just "no conflicts".
2. tybot `main_pre` internal jumps go through `/exec`: the lock fix and lock-ownership tests must pass there, or the adaptation must be recorded.
3. Server `master-COLLAUDO` has different routes/middleware (`routes/request.js`, `middleware/has-role.js`): the invite/remove routes must keep project scoping and role checks.
4. A pre branch that already contains an equivalent change → `git cherry-pick` reports an empty commit; skip it with `--skip` and record it.
5. Restoring the feature branch's dependencies after the port — the feature branch's own test must pass again before handing the checkout back.

---

### Task 1: tiledesk-server → `master-COLLAUDO`

**Files:** all files touched by the ported commits.

- [ ] **Step 1:** Branch from `origin/master-COLLAUDO`; `npm ci`.
- [ ] **Step 2:** Cherry-pick the commit list; resolve conflicts per the rule; record each.
- [ ] **Step 3:** Feature suites: `./node_modules/.bin/mocha test/webhookRoute.js test/webhookConversationRoute.js test/webhookConversationService.js test/inviteParticipantsRoute.js test/removeParticipantsRoute.js test/hitlWaitingReset.js test/hitlParticipantListener.js test/botEventHitlFallback.js test/requestServiceRemoveParticipant.js --timeout 60000 --exit` → all pass (MongoDB/Redis test containers running).
- [ ] **Step 4:** Full-suite comparison: `npm test` on the `-PRE` head, then on `origin/master-COLLAUDO` (detached checkout in the same directory — lockfile identical, no reinstall; return to the `-PRE` branch afterwards). Compare failing titles: none failing only on `-PRE`; branch-only titles re-run alone on both sides.
- [ ] **Step 5:** Switch back to `feature/webhook-chatbot-hitl`, `npm ci`, run `test/hitlParticipantListener.js` once → passes. Report.

### Task 2: tiledesk-chatbot → `main_pre`

- [ ] **Step 1:** Branch from `origin/main_pre`; `npm ci` at the repo root.
- [ ] **Step 2:** Cherry-pick the list; resolve conflicts (known: `tybotRoute/engine/TiledeskChatbot.js`, `tiledeskChatbotPlugs/directives/Directives.js`, `utils/HttpUtils.js`).
- [ ] **Step 3:** Feature suites from `tybotRoute/`, each file alone: `invite_human_members_test.js`, `remove_human_test.js`, `http_utils_test.js`, `capture_user_reply_test.js`, `conversation-invite_human_test.js`, `conversation-remove_human_test.js`, `conversation-lock_internal_jump_test.js`, `conversation-lock_ownership_test.js`, `conversation-capture_test.js`, `conversation-replyv2_button_match_test.js`, `conversation-replyv2_noinput_test.js`. If a lock test fails because internal jumps use `/exec` on this branch, adapt the fix (not the test's intent) in a separate commit and record why.
- [ ] **Step 4:** Full-suite comparison with `origin/main_pre` (detached in the same directory; no reinstall — same lockfile); failing-title diff; port-10002 cascades verified file by file.
- [ ] **Step 5:** Switch back, `npm ci`, run `test/conversation-invite_human_test.js` once → passes. Report.

### Task 3: chat21-ionic → `master-PRE`

- [ ] **Step 1:** Branch from `origin/master-PRE`; Node 14 `npm ci --ignore-scripts`.
- [ ] **Step 2:** Cherry-pick the list; resolve conflicts (known candidates: `src/app/app.component.ts`, `src/app/services/websocket/websocket.service.ts`, `package.json`/lock/CHANGELOG from version bumps — keep the pre branch's versions).
- [ ] **Step 3:** Specs with the workspace harness `.superpowers/sdd/2026-09-29-hitl-participant-removal-chat21-ionic/tsconfig.leave-specs.json` (same command as that plan's Ruling 1) → `TOTAL: 15 SUCCESS`; `npx ng build` → exit 0; compare its warnings with a build of `origin/master-PRE` (same directory, detached) — no new warnings; delete `www/`.
- [ ] **Step 4:** Switch back, Node 14 `npm ci --ignore-scripts`, run the spec command once → 15 SUCCESS. Report.

### Task 4: design-studio → `master-pre`

- [ ] **Step 1:** Branch from `origin/master-pre`; Node 16 `npm ci`.
- [ ] **Step 2:** Cherry-pick the list; resolve conflicts (known: `cds-canvas.component.ts`, `cds-intent.component.{ts,html}`, `cds-header.component.ts`, `intent.service.ts`, `utils-actions.ts`). `master-pre` may have new actions/enum entries next to ours — keep both.
- [ ] **Step 3:** Specs with `.superpowers/sdd/2026-09-29-hitl-participant-removal-design-studio/test-hitl.ts` + `tsconfig.hitl-specs.json` → `TOTAL: 13 SUCCESS`; `npx ng build` → exit 0; warnings compared with a build of `origin/master-pre` — no new ones; delete `dist/`.
- [ ] **Step 4:** Switch back, Node 16 `npm ci`, run the spec command once → 13 SUCCESS. Report.
