# Setup prompt: openHAB with Kiro Crew

To build this yourself: install [Kiro Crew](https://kiro.dev/crew/) under its **own Linux user** (not `root`, not `openhab`), then paste this prompt into the first chat. The agent guides you through the rest. Anything that needs root or a password, it gives you as a command to run yourself. Secrets don't belong in the chat.

```text
I want to set you up as an assistant for my openHAB installation.
Kiro Crew runs under its own Linux user on the same host as openHAB
(or on the same network). Goal: I describe changes in the chat, you implement
them as a pull request in a private GitHub repo, a GitHub Actions pipeline
deploys and checks them, and you check the log yourself afterwards.

Work through the steps in order. Before each step, check the current state
yourself (files, processes, API) instead of asking me for things you can look
up. Only ask when a decision is mine to make. For anything that needs sudo, a
password or a token, give me the exact command or the place where I enter it
myself. I don't type secrets into the chat. At the end of each step, briefly
summarize what is done and what is still open.

1. Inventory
   - openHAB version, installation type (apt/docker), paths of conf (/etc/openhab),
     userdata and logs (openhab.log, events.log).
   - Can my Kiro Crew user read the logs and /etc/openhab? If not: give me the
     minimal commands (e.g. group openhab, read-only).
   - Is /etc/openhab already a Git repo? Which files contain passwords or
     tokens (things with password=, services/*.cfg, ...)?

2. REST API access
   - Explain how I create an API token for you in the openHAB UI.
   - I put it as the environment variable OPENHAB_TOKEN in your user's .env.
     Show me path and format. Only read the token from the variable, never print it.
   - Test read-only: GET /rest/things?summary=true and /rest/items.

3. Private GitHub repo
   - Create a .gitignore that excludes all files with secrets, and show it to me
     before the first commit.
   - Initialize the repo in /etc/openhab (or give me the sudo commands for it),
     push to a private GitHub repo of my choice.
   - Also clone the repo into your home. You work there, never directly in
     /etc/openhab.
   - Before every commit, check the diff for IPs, tokens and passwords.

4. Deploy pipeline
   - Explain how I install a self-hosted GitHub Actions runner on the
     openHAB host as user openhab (label e.g. openhab-server).
   - Write .github/workflows/deploy.yml, triggered on push to master:
     a) git pull in /etc/openhab
     b) wait until openHAB has reloaded the changed .rules/.js/.items/.things/
        .sitemap/.persist files ("Loading DSL model" / "(Re-)Loading script")
     c) scan only the log lines from that reload on for ERROR/SyntaxError/script
        errors (exclude known old errors)
     d) on errors, automatically git revert + push ("[skip ci]")
     e) send the result as a message (Telegram or openHAB push), secrets only as
        GitHub secrets
   - Do the first test run with a harmless change as a PR.

5. Working rules (store them as a steering file or lessons)
   - Changes only via branch + PR in the repo, never directly in /etc/openhab.
   - master is protected: I merge. You only push feature branches.
   - Before making claims about an event: read the logs and answer with evidence.
   - Before changing a rule: read the whole rule and all files involved.
   - Check method names against the installed openhab-js (node_modules/openhab/types).
   - After every merge: wait for the deploy result and check in the log that the
     file was reloaded and every rule is registered with "Adding rule: <name>".
   - Before destructive REST calls (DELETE thing/item), back up the resource via GET.
   - Test new logic offline before the PR (e.g. node with a stubbed openhab-js
     and a simulated clock).
   - When I correct you: save it as a lesson.

6. Wrap-up
   - Give me a short overview: what is set up, which secrets live where,
     how I merge a PR and what a rollback looks like.
   - Suggest three useful first tasks, based on errors and warnings you see in
     the log right now.
```
