|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Project |
| 4 | + |
| 5 | +API Monkey is a Go 1.26 Stream Deck plugin. It sends configured HTTP requests, processes responses, and updates Stream Deck keys. Releases package Windows x64 and macOS arm64 binaries with `resources/` into `com.ftt.apimonkey.sdPlugin.zip`. |
| 6 | + |
| 7 | +Read [README.md](README.md), [docs/usage.md](docs/usage.md), and [docs/lua.md](docs/lua.md) before changing user-visible behavior. |
| 8 | + |
| 9 | +## Repository map |
| 10 | + |
| 11 | +- `main.go`: application wiring and Stream Deck event handlers. |
| 12 | +- `pkg/common`: saved configuration and validation. |
| 13 | +- `pkg/executor`: request templates, HTTP execution, JSON selection, and response Lua dispatch. |
| 14 | +- `pkg/instance`: per-key lifecycle, polling, actions, response mapping, and Stream Deck updates. |
| 15 | +- `pkg/scripts`: response Lua, action Lua, JSON module setup, and action HTTP API. |
| 16 | +- `pkg/sdk`: Stream Deck SDK adapter. |
| 17 | +- `pkg/utils`: browser, file, and Go template helpers. |
| 18 | +- `resources/manifest.json`: plugin metadata and supported platforms. |
| 19 | +- `resources/pi/pi.html`: Property Inspector fields and saved settings. |
| 20 | +- `docs/usage.md`: canonical user-facing feature and configuration guide. |
| 21 | +- `docs/lua.md`: canonical Lua scripting contract. |
| 22 | + |
| 23 | +## Required workflow |
| 24 | + |
| 25 | +- Run `gopls go_workspace` before working in this Go workspace. |
| 26 | +- Read a package's `interfaces.go` before modifying that package. |
| 27 | +- After first reading a Go file, inspect its `gopls go_file_context`. |
| 28 | +- Use `gopls` for Go symbols, references, renames, diagnostics, and package APIs. |
| 29 | +- Use Codebase Memory for architecture, call chains, change impact, and structural discovery. |
| 30 | +- Prefer repository Makefile targets over direct tool commands when a matching target exists. |
| 31 | +- Keep changes inside requested scope. Ask before changing public APIs, schemas, dependencies, or unrelated packages. |
| 32 | +- Do not delete or rename existing assets, configuration, or fixtures to fix a failure. |
| 33 | + |
| 34 | +## Code rules |
| 35 | + |
| 36 | +- Keep code explicit, small, and boring. Avoid unrelated refactors. |
| 37 | +- Public blocking or I/O methods accept `context.Context` first. |
| 38 | +- Define minimal interfaces where consumed. |
| 39 | +- Never pass dependencies as `nil` unless a constructor explicitly documents a nil sentinel. |
| 40 | +- Use `github.com/golang/mock/gomock`. Generate mocks; never hand-edit generated mock files. |
| 41 | +- Use the logger carried by `context.Context` through `zerolog.Ctx(ctx)`. |
| 42 | +- Preserve error identity with wrapping. Use `errors.Is` and `errors.As`; never compare error strings. |
| 43 | +- Handle every returned error. Log only documented best-effort cleanup failures. |
| 44 | +- Tests must not perform real network, filesystem, clock, or random I/O. Database tests are the only real-I/O exception. |
| 45 | +- Keep success and failure test tables separate. Do not branch on expected outcomes inside tests. |
| 46 | + |
| 47 | +## Commands |
| 48 | + |
| 49 | +```bash |
| 50 | +make generate |
| 51 | +make lint |
| 52 | +go test -p 1 -timeout 60s ./... |
| 53 | +go build ./... |
| 54 | +``` |
| 55 | + |
| 56 | +Run `make generate` after interface changes. Before declaring work complete, `make lint`, tests for modified packages with `-p 1 -timeout 60s`, and `go build ./...` must pass. |
| 57 | + |
| 58 | +`make build-apimonkey-windows` builds a Windows development package in `dist/`. `Dockerfile` is the cross-platform release packaging source of truth. |
| 59 | + |
| 60 | +## Lua changes |
| 61 | + |
| 62 | +Response and action Lua are separate contracts: |
| 63 | + |
| 64 | +- Response Lua: `Lua.Execute`, globals `ResponseBody` and `ResponseStatusCode`. |
| 65 | +- Action Lua: `Lua.ExecuteAction`, globals `ButtonContextID`, `ButtonConfig`, and `http`. |
| 66 | + |
| 67 | +When changing Lua behavior: |
| 68 | + |
| 69 | +1. Read `pkg/scripts/interfaces.go` and `pkg/scripts/lua.go` with gopls context. |
| 70 | +2. Update `pkg/scripts/lua_test.go` without real HTTP calls. |
| 71 | +3. Update [docs/lua.md](docs/lua.md) in the same change. |
| 72 | +4. Update [docs/usage.md](docs/usage.md) when configuration or visible behavior changes. |
| 73 | +5. Update `README.md` only when the high-level feature list, install steps, platform support, or quick start changes. |
| 74 | + |
| 75 | +## Documentation rules |
| 76 | + |
| 77 | +- Treat current code, tests, Property Inspector, manifest, and release workflow as source of truth. |
| 78 | +- Keep README concise; link to detailed guides instead of duplicating them. |
| 79 | +- Put configuration and end-user examples in `docs/usage.md`. |
| 80 | +- Put all Lua globals, APIs, return rules, errors, and Lua examples in `docs/lua.md`. |
| 81 | +- Keep examples executable against the documented contract. Never document planned behavior as available. |
| 82 | +- Preserve existing images under `docs/` unless replacement is explicitly requested. |
| 83 | + |
| 84 | +## Git |
| 85 | + |
| 86 | +- Do not commit or push to `master`, `main`, `qa`, `uat`, or `Release/*` without explicit approval. |
| 87 | +- Sign every commit with `git commit -S`. Never bypass signing. |
| 88 | +- Do not add an AI co-author. |
0 commit comments