GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
docs: refresh AGENTS hierarchy
Aldino Kemal4e01e33fa990
diff --git a/AGENTS.md b/AGENTS.mdindex 41cbdc19..d985fe50 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,54 +1,57 @@# PROJECT KNOWLEDGE BASE-Generated: 2026-05-24-Commit: 438d0a1-Branch: feat/daily-presence-pulse+Generated: 2026-06-05+Commit: c83de24+Branch: main## OVERVIEW-Go WhatsApp Web Multi-Device is a Go 1.25.5 WhatsApp Web API server with REST and MCP SSE modes. It uses whatsmeow for multi-device WhatsApp sessions, Fiber for REST, plain Vue 3 modules for the embedded UI, and SQLite-backed chat/session storage by default.+Go WhatsApp Web Multi-Device is a Go 1.25.5 WhatsApp Web API server with REST and MCP SSE modes.+It uses whatsmeow sessions, Fiber, plain Vue 3 modules, and SQLite-backed chat/session storage by default.## STRUCTURE```textgo-whatsapp-web-multidevice/-├── src/ # Go module root; run Go commands here-│ ├── main.go # go:embed views, then cmd.Execute-│ ├── cmd/ # Cobra root, rest, mcp, global app wiring-│ ├── config/ # Mutable package globals bound from flags/env-│ ├── domains/ # Interfaces and DTOs; see child AGENTS-│ ├── usecase/ # Business orchestration; see child AGENTS-│ ├── validations/ # ozzo-validation plus table tests-│ ├── ui/ # REST, MCP, websocket adapters-│ ├── infrastructure/-│ │ ├── whatsapp/ # Device manager, events, presence pulse, JID utilities-│ │ ├── chatstorage/ # chat/message/device SQL repository-│ │ └── chatwoot/ # Chatwoot REST sync and direct PG import-│ ├── views/ # Embedded Vue 3 plain JS UI-│ ├── statics/ # Runtime media, QR codes, send items-│ └── storages/ # Runtime SQLite DBs and history dumps-├── docs/ # OpenAPI, webhook payload docs, SDK config-├── docker/ # Multi-stage Alpine image and entrypoint-└── .github/workflows/ # Docker publish, release, latest promotion+|-- src/ # Go module root; run Go commands here+| |-- main.go # go:embed views, then cmd.Execute+| |-- cmd/ # Cobra root, rest, mcp, global app wiring+| |-- config/ # Mutable package globals bound from flags/env+| |-- domains/ # Interfaces and DTOs; see child AGENTS+| |-- usecase/ # Business orchestration; see child AGENTS+| |-- validations/ # ozzo-validation plus table tests+| |-- ui/ # REST, MCP, websocket adapters+| |-- infrastructure/+| | |-- whatsapp/ # Device manager, events, presence pulse, JID utilities+| | |-- chatstorage/ # chat/message/device SQL repository+| | `-- chatwoot/ # Chatwoot REST sync and direct PG import+| |-- views/ # Embedded Vue 3 plain JS UI+| |-- statics/ # Runtime media, QR codes, send items+| `-- storages/ # Runtime SQLite DBs and history dumps+|-- docs/ # OpenAPI, webhook payload docs, SDK config+|-- docker/ # Multi-stage Alpine image and entrypoint+|-- gallery/ # Static screenshots and project images+`-- .github/workflows/ # Docker publish, release, latest promotion```## WHERE TO LOOK| Task | Location | Notes ||------|----------|-------|-| Add message type | `src/domains/send/`, `src/usecase/send.go`, `src/validations/send_validation.go`, `src/ui/rest/send.go` | MCP support is optional and currently partial. |+| Add message type | `src/domains/send/`, `src/usecase/send.go`, `src/ui/rest/send.go` | REST is primary; MCP support is selective. |+| Add quoted reply support | `src/domains/send/`, `src/usecase/send.go`, `src/views/components/Send*.js` | Optional `reply_message_id`; use device-scoped quote lookup. || Add REST endpoint | `src/ui/rest/`, `src/usecase/`, `src/domains/` | Handler parses request, usecase validates/executes, domain owns DTO/interface. || Add MCP tool | `src/ui/mcp/` | Register in `Add*Tools`; resolve a device with `helpers.ContextWithDefaultDevice`. || Handle WhatsApp event | `src/infrastructure/whatsapp/event_*.go` | Register the concrete event in `event_handler.go`. |-| Presence behavior | `src/infrastructure/whatsapp/event_handler.go`, `src/infrastructure/whatsapp/presence_pulse.go`, `src/cmd/helpers.go` | Connect-time presence and scheduled available/unavailable pulses. |-| Add chat storage method | `src/domains/chatstorage/interfaces.go`, `src/infrastructure/chatstorage/sqlite_repository.go`, `src/infrastructure/whatsapp/chatstorage_wrapper.go` | Keep wrapper behavior in sync with the interface. |+| Presence behavior | `src/infrastructure/whatsapp/event_handler.go`, `presence_pulse.go`, `src/cmd/helpers.go` | Connect-time and scheduled pulse presence. |+| Add chat storage method | `src/domains/chatstorage/interfaces.go`, `sqlite_repository.go`, `chatstorage_wrapper.go` | Update domain, repository, and wrapper together. || Add DB migration | `src/infrastructure/chatstorage/sqlite_repository.go` `getMigrations()` | Append only. Current list has 22 migrations. || Add UI component | `src/views/components/`, `src/views/index.html` | Plain JS modules, no `.vue` single-file components. || Device management | `src/infrastructure/whatsapp/device_manager.go` | Central registry and purge/load/create logic. |-| Chatwoot integration | `src/infrastructure/chatwoot/` and `src/ui/rest/chatwoot.go` | REST sync plus optional direct Postgres import. |+| Chatwoot integration | `src/infrastructure/chatwoot/` and `src/ui/rest/chatwoot.go` | REST sync, public webhook, optional direct Postgres import. || CLI flags / config | `src/cmd/root.go`, `src/config/settings.go`, `src/.env.example` | Flags and env mutate config package globals. || Shared helpers | `src/pkg/utils/`, `src/pkg/error/`, `src/pkg/sqlite/` | Utilities, aliased package errors, and CGO/purego SQLite driver selection. |-| Docker/release | `docker/golang.Dockerfile`, `.github/workflows/*.yaml` | Multi-arch Docker, GitHub Actions, and generated GoReleaser configs. |+| Docker/release | `docker/golang.Dockerfile`, `.github/workflows/*.yaml` | Multi-arch Docker, tag/manual workflows, generated GoReleaser configs. |## CODE MAP@@ -58,7 +61,7 @@ go-whatsapp-web-multidevice/| `initApp` | function | `src/cmd/root.go` | Creates folders, DBs, WhatsApp client, device manager, repositories, and usecases. || `DeviceManager` | struct | `src/infrastructure/whatsapp/device_manager.go` | Owns active device registry and persisted device records. || `DeviceInstance` | struct | `src/infrastructure/whatsapp/device_instance.go` | Wraps per-device ID, JID, client, state, and storage. |-| `IChatStorageRepository` | interface | `src/domains/chatstorage/interfaces.go` | Storage contract for chats, messages, calls, stats, schema, and device records. |+| `IChatStorageRepository` | interface | `src/domains/chatstorage/interfaces.go` | Storage contract for chats, messages, edits, calls, stats, schema, and device records. || `SQLiteRepository` | struct | `src/infrastructure/chatstorage/sqlite_repository.go` | Implements chat storage and inline migrations. || `deviceChatStorage` | wrapper | `src/infrastructure/whatsapp/chatstorage_wrapper.go` | Injects or enforces device scoping for event-side storage access. || `StartPresencePulseScheduler` | function | `src/infrastructure/whatsapp/presence_pulse.go` | Periodically marks connected devices available, then unavailable. |@@ -69,6 +72,7 @@ go-whatsapp-web-multidevice/## CONVENTIONS- Go commands run from `src/`; the repo root is not the Go module root.+- Local runtime paths are relative to process cwd, so direct local runs should start from `src/`.- Config priority is Cobra flags, then env/Viper, then `.env` loaded from `src/`.- REST and MCP share the same app initialization and cannot safely run together against the same whatsmeow state in one process.- Process-wide helpers in `cmd/helpers.go` guard auto-reconnect and presence-pulse startup for both REST and MCP.@@ -87,17 +91,19 @@ go-whatsapp-web-multidevice/- Do not add `IChatStorageRepository` methods without updating `chatstorage_wrapper.go` and the concrete repository.- Do not insert migrations in the middle of `getMigrations()`; append new entries only.- Do not remove the `evt.Sender.Device != 0` receipt check; it prevents duplicate webhook deliveries from linked devices.-- Do not put generated/runtime media, QR codes, SQLite DBs, or history dumps into source-oriented docs or commits unless explicitly requested.+- Do not put generated/runtime media, QR codes, SQLite DBs, `.env`, or history dumps into source-oriented docs or commits unless explicitly requested.## UNIQUE STYLES- Cobra subcommands are registered by `init()` side effects in `cmd/rest.go` and `cmd/mcp.go`.- The app uses mutable package globals for config, clients, repositories, and usecases instead of dependency injection from `main`.-- REST has wider coverage than MCP: REST send has 12 routes, MCP send currently has 6 tools.+- REST has wider coverage than MCP: REST send has 12 routes; MCP exposes send, query, app, and group tool subsets.- Chat storage migrations are Go string literals in the repository, not external migration files.- The embedded UI uses Vue 3 from CDN, Fomantic UI modals/toasts, and custom delimiters `[[`, `]]`.- Release workflows generate GoReleaser YAML into `/tmp`; there is no committed `.goreleaser.yml`.+- `AppVersion` is hard-coded as `v8.6.0` in `src/config/settings.go`; release workflows do not inject it with ldflags.- `src/pkg/error` declares package name `error`; import it with aliases such as `pkgError`.+- Default SQLite builds use CGO `github.com/mattn/go-sqlite3`; `-tags purego` switches to `modernc.org/sqlite`.## COMMANDS@@ -114,8 +120,10 @@ docker compose up --build## NOTES- Docker builds use `docker/golang.Dockerfile`, Go `1.25-alpine3.23`, CGO, and a final non-root `gowauser` process after the entrypoint fixes volume ownership.-- Docker publish is tag/manual driven. Arch-specific `-amd`, `-arm`, and `-armv7` images are merged into a versioned manifest; `latest` is promoted by a separate manual workflow.-- `release.yml` declares `workflow_dispatch`, but jobs are guarded to tag pushes, so manual dispatch currently skips release jobs.-- `AppVersion` is hard-coded in `src/config/settings.go`; release workflows do not inject it with ldflags.+- Docker Compose mounts root-level `./storages` and `./statics` into `/app`; direct local runs from `src/` use `src/storages` and `src/statics`.+- Docker publish is tag/manual driven. Arch-specific `-amd`, `-arm`, and `-armv7` images are merged into a versioned manifest; `latest` is also promoted by workflows.+- `release.yml` declares `workflow_dispatch`, but release jobs are still guarded to tag refs.+- GitHub workflows are release/publish oriented; there is no PR workflow that runs `go test`, `go vet`, or lint.+- `DBKeysURI` defaults to the main DB URI when empty; avoid in-memory keys storage in production because privacy tokens must survive long-lived sessions.- `status@broadcast` chat names intentionally resolve to `Status`.- `src/.air.toml` excludes `statics` and `storages`; keep hot reload from watching runtime data.diff --git a/src/domains/AGENTS.md b/src/domains/AGENTS.mdindex 2b960aaa..9f054160 100644--- a/src/domains/AGENTS.md+++ b/src/domains/AGENTS.md@@ -1,6 +1,6 @@# DOMAINS-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW@@ -10,9 +10,9 @@ Domain packages hold request/response DTOs and interfaces for usecases and stora```textdomains/-├── app/ chat/ device/ group/ message/ newsletter/ user/-├── send/ # one file per send request type plus combined sender interface-└── chatstorage/ # chat/message/device storage entities, filters, repository interface+|-- app/ chat/ device/ group/ message/ newsletter/ user/+|-- send/ # one file per send request type plus combined sender interface+`-- chatstorage/ # chat/message/edit/device storage entities, filters, repository interface```## WHERE TO LOOK@@ -20,6 +20,7 @@ domains/| Task | Location | Notes ||------|----------|-------|| Add send request | `send/<type>.go`, `send/interfaces.go` | Keep `BaseRequest` embedding if the request targets a chat/contact. |+| Add reply field | `send/text.go`, media request DTOs | Optional `ReplyMessageID *string` serializes as `reply_message_id`. || Add usecase contract | `<domain>/interfaces.go` | Return the domain interface from `usecase.New*Service`. || Add chat storage method | `chatstorage/interfaces.go` | Also update concrete repository and WhatsApp storage wrapper. || Add response field | Matching DTO file | Check REST/MCP serialization expectations before renaming JSON fields. |@@ -29,11 +30,12 @@ domains/- DTOs use JSON tags for API payloads and may include form/multipart fields where existing request types already do.- Send requests are split by message type, but `ISendUsecase` composes smaller sender interfaces for compatibility.- Chat filters use pointer booleans, for example `*bool`, when "not set" differs from `false`.-- Storage entities carry `DeviceID`; preserve it through chat/message flows.+- Storage entities carry `DeviceID`; preserve it through chat/message/edit flows.+- `GetMessageByIDAndDevice` is the device-scoped ID lookup for user/device-isolated flows.- Existing contracts expose whatsmeow types in places. Keep that local to contracts that already need protocol details.## ANTI-PATTERNS- Do not put validation rules, SQL, Fiber handlers, MCP tool parsing, or whatsmeow send logic in domain packages.-- Do not add a chat/message repository method that cannot be scoped by device.+- Do not add a chat/message repository method that cannot be scoped by device unless the caller contract is explicitly global.- Do not rename JSON fields casually; views, REST clients, MCP tools, docs, and tests may rely on them.diff --git a/src/infrastructure/chatstorage/AGENTS.md b/src/infrastructure/chatstorage/AGENTS.mdindex dfaa5063..86aa7f1b 100644--- a/src/infrastructure/chatstorage/AGENTS.md+++ b/src/infrastructure/chatstorage/AGENTS.md@@ -1,10 +1,10 @@# CHAT STORAGE-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW-`SQLiteRepository` implements chat, message, call, reaction, statistic, schema, and device-record storage behind `domains/chatstorage.IChatStorageRepository`.+`SQLiteRepository` implements chat, message, edit-history, call, reaction, statistic, schema, and device-record storage behind `domains/chatstorage.IChatStorageRepository`.## WHERE TO LOOK@@ -13,13 +13,15 @@ Generated: 2026-05-24| Repository contract | `../../domains/chatstorage/interfaces.go` | Any method addition must be implemented here and in WhatsApp wrapper. || SQL implementation | `sqlite_repository.go` | Single large repository file. || Migrations | `sqlite_repository.go` `getMigrations()` | Append-only list, currently 22 migrations. |-| Tests | `sqlite_repository_test.go` | Add coverage for schema/data isolation changes. |+| Message edit history | `sqlite_repository.go`, `sqlite_repository_edit_test.go` | `message_edits` is append-only history while original message content updates. |+| Tests | `sqlite_repository_test.go`, `sqlite_repository_edit_test.go` | Add coverage for schema/data isolation changes. |## CONVENTIONS- Default chat storage URI is `file:storages/chatstorage.db`; connection setup is in `cmd/root.go`.- `chats` primary key is `(jid, device_id)`; `messages` primary key is `(id, chat_jid, device_id)`.- `GetMessages` and `SearchMessages` fail fast if device ID is missing.+- Use `GetMessageByIDAndDevice` for device-scoped ID lookups such as quoted replies.- Use `GetChatByDevice`, `DeleteChatByDevice`, `DeleteMessageByDevice`, and count-by-device variants for scoped flows.- `CreateMessage` and sent-message storage derive the current device identity from the whatsmeow client context.- `status@broadcast` must always produce display name `Status`.diff --git a/src/infrastructure/chatwoot/AGENTS.md b/src/infrastructure/chatwoot/AGENTS.mdindex 0a140956..0724a98f 100644--- a/src/infrastructure/chatwoot/AGENTS.md+++ b/src/infrastructure/chatwoot/AGENTS.md@@ -1,41 +1,44 @@# CHATWOOT INFRASTRUCTURE-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW-This package handles Chatwoot API calls, live sync, historical import, and optional direct Postgres writes for Chatwoot history.+This package handles Chatwoot API calls, live sync, historical import, echo-loop suppression, and optional direct Postgres writes for Chatwoot history.## STRUCTURE```textchatwoot/-├── client.go # Chatwoot REST API client-├── sync.go # Sync service and message import flow-├── sync_types.go # Sync DTOs/state-├── types.go # Chatwoot API payloads-└── pgimport/ # Direct PostgreSQL importer for historical messages+|-- client.go # Chatwoot REST API client, contact lookup, echo-loop cache+|-- sync.go # Sync service and message import flow+|-- sync_types.go # Sync DTOs/state+|-- types.go # Chatwoot API payloads+`-- pgimport/ # Direct PostgreSQL importer for historical messages```## WHERE TO LOOK| Task | Location | Notes ||------|----------|-------|-| REST API behavior | `client.go` | HTTP calls to Chatwoot. |+| REST API behavior | `client.go` | HTTP calls to Chatwoot, contact lookup, sent-message cache. || Live/history sync | `sync.go` | Uses app/send usecases, storage, and Chatwoot settings. || Direct DB import | `pgimport/` | SQL writer and identity mapping with sqlmock tests. |-| REST surface | `../../ui/rest/chatwoot.go` | Webhook and manual sync endpoints. |+| REST surface | `../../ui/rest/chatwoot.go` | Public webhook plus authenticated manual sync/status endpoints. || Config | `../../config/settings.go`, `../../cmd/root.go` | `CHATWOOT_*` env/flags. |## CONVENTIONS- Chatwoot webhook route is public relative to app Basic Auth and is registered before the Basic Auth middleware.+- Webhook handling accepts only outgoing Chatwoot messages for WhatsApp send-back and skips IDs marked as sent by this app.- Outbound Chatwoot messages require a configured/selected device; preserve device context when calling send usecases.-- Direct import is controlled by `ChatwootImportDBURI`; live forwarding still uses the REST API.+- Direct import is controlled separately from live REST forwarding.+- Groups and `@lid` contacts use identifier/custom attributes; private chats use normalized phone lookup.- Tests include regular sync tests and `pgimport` sqlmock tests.## ANTI-PATTERNS- Do not mix direct Postgres historical import with live REST forwarding semantics.+- Do not remove the sent-message cache unless another echo-loop guard exists.- Do not log API tokens or raw secrets from Chatwoot config.- Do not assume imported media is always downloadable; placeholder behavior is configurable.diff --git a/src/infrastructure/whatsapp/AGENTS.md b/src/infrastructure/whatsapp/AGENTS.mdindex 41d59986..2336c34b 100644--- a/src/infrastructure/whatsapp/AGENTS.md+++ b/src/infrastructure/whatsapp/AGENTS.md@@ -1,10 +1,11 @@# WHATSAPP INFRASTRUCTURE-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW-This package owns whatsmeow clients, multi-device lifecycle, JID normalization, event handling, presence pulse scheduling, webhook forwarding, and the event-side chatstorage wrapper.+This package owns whatsmeow clients, multi-device lifecycle, JID normalization, events, send retry helpers,+presence pulse scheduling, webhook forwarding, and the event-side chatstorage wrapper.## WHERE TO LOOK@@ -13,6 +14,7 @@ This package owns whatsmeow clients, multi-device lifecycle, JID normalization,| Device lifecycle | `device_manager.go`, `device_instance.go`, `client_lifecycle.go` | Create/load/purge/reconnect and persisted registry behavior. || Event routing | `event_handler.go`, `event_*.go` | Add new event types to the central switch. || Message webhooks | `event_message.go`, `webhook_forward.go` | Payload construction, media fields, signatures, event filters. |+| Send retry / 463 | `send_retry.go`, `key_cache.go` | Reachout timelock retry and privacy-token store wiring. || Presence behavior | `event_handler.go`, `event_chat_presence.go`, `presence_pulse.go` | Connect-time presence, chat presence webhooks, scheduled daily pulses. || History import | `history_sync.go` | Stores chats/messages for history sync batches. || JID conversion | `jid_utils.go`, `context_device.go` | LID normalization and request/device context. |@@ -27,6 +29,7 @@ This package owns whatsmeow clients, multi-device lifecycle, JID normalization,- Normalize `@lid` JIDs with `NormalizeJIDFromLID(ctx, jid, client)` before DB lookup/storage when a phone JID is needed.- Use `ToNonAD()` when persisting or emitting stable non-device JIDs.- Webhook forwarding uses goroutines and bounded contexts in selected handlers; keep failures logged without blocking the event loop.+- `chatstorage_wrapper.go` should provide device defaults for scoped repository methods, including message edit and device-scoped ID lookups.## ANTI-PATTERNS@@ -35,6 +38,7 @@ This package owns whatsmeow clients, multi-device lifecycle, JID normalization,- Do not add an `IChatStorageRepository` method without implementing the wrapper method.- Do not remove the receipt `Device == 0` filter; linked devices produce duplicate receipts.- Do not start a second presence pulse loop; `cmd/helpers.go` uses `sync.Once` for process-wide startup.+- Do not move privacy tokens to a volatile keys DB; long-lived sessions need them in durable primary WhatsApp storage.- Do not assume `client`, `client.Store`, or `client.Store.LIDs` is non-nil during LID resolution.## TESTINGdiff --git a/src/ui/AGENTS.md b/src/ui/AGENTS.mdindex e0b2f8a6..82773a4b 100644--- a/src/ui/AGENTS.md+++ b/src/ui/AGENTS.md@@ -1,6 +1,6 @@# UI ADAPTERS-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW@@ -10,9 +10,9 @@ Generated: 2026-05-24```textui/-├── rest/ # Fiber handlers, helpers, middleware-├── mcp/ # MCP tools and default-device context helper-└── websocket/ # Browser device/status broadcast hub+|-- rest/ # Fiber handlers, helpers, middleware+|-- mcp/ # MCP tools and default-device context helper+`-- websocket/ # Browser device/status broadcast hub```## WHERE TO LOOK@@ -22,7 +22,8 @@ ui/| Add REST route | `rest/<domain>.go` | `InitRest*` registers paths and stores the domain service. || Add REST middleware | `rest/middleware/` | Use `fiber.Test()` for middleware tests. || Add MCP tool | `mcp/<domain>.go` | Define `tool*`, `handle*`, and register in `Add*Tools`. |-| Device context | `rest/middleware/device.go`, `mcp/helpers/context.go` | REST uses headers/query; MCP uses default/only device. |+| Device context | `rest/middleware/device.go`, `mcp/helpers/context.go` | REST uses header/query; MCP uses default/only device. |+| Send transport fields | `rest/send.go`, `mcp/send.go` | REST receives full send DTOs; MCP send is a smaller tool subset with manual args. || Websocket changes | `websocket/websocket.go`, `../views/index.html` | Browser connects with `?device_id=`. |## CONVENTIONS@@ -32,11 +33,12 @@ ui/- Device management routes are registered outside `DeviceMiddleware`; most operational routes are wrapped by it.- Chatwoot webhook is registered before basic auth so Chatwoot can POST without the app's Basic Auth header.- MCP handlers validate argument types manually and return `mcp.NewToolResultText(...)`.-- MCP tool coverage is intentionally smaller than REST; add only tools that are useful to agents.+- MCP handlers must call `ContextWithDefaultDevice` before device-bound usecase calls.+- MCP coverage is intentionally selective: send has 6 tools, query 5, app 5, and group 13.## ANTI-PATTERNS- Do not put WhatsApp business logic in REST/MCP handlers.-- Do not assume MCP receives a device header; use `ContextWithDefaultDevice`.+- Do not assume MCP receives a device header or device ID argument; use `ContextWithDefaultDevice`.- Do not register device-scoped REST operations outside `DeviceMiddleware`.- Do not expose new unauthenticated REST paths unless they are health checks or explicitly public webhooks.diff --git a/src/usecase/AGENTS.md b/src/usecase/AGENTS.mdindex 5ef2fff1..9a5ce1e8 100644--- a/src/usecase/AGENTS.md+++ b/src/usecase/AGENTS.md@@ -1,6 +1,6 @@# USECASE-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW@@ -10,8 +10,10 @@ Usecases orchestrate validation, device/client lookup, WhatsApp operations, stor| Task | Location | Notes ||------|----------|-------|-| Send message/media | `send.go` | Largest file; handles text, media, links, contacts, polls, presence, and stored sent messages. |+| Send message/media | `send.go` | Largest file; handles text, media, links, contacts, polls, presence, quote context, and stored sent messages. |+| Quoted replies | `send.go` `mergeReplyContext` | Uses `GetMessageByIDAndDevice(deviceIDFromContext(ctx), id)` before setting `ContextInfo`. || Chat listing/history | `chat.go` | Device ID comes from context and must reach chat/message filters. |+| Message actions | `message.go` | Reaction/revoke may use global ID lookup to resolve sender for WhatsApp protocol behavior. || Group operations | `group.go` | Handles participant JID conversion, names, invite links, and group settings. || Account/user operations | `user.go` | Uses current device client and chat storage. || Device operations | `device.go` | Delegates to `whatsapp.DeviceManager`. |@@ -23,6 +25,7 @@ Usecases orchestrate validation, device/client lookup, WhatsApp operations, stor- Resolve WhatsApp clients from context with `whatsapp.ClientFromContext(ctx)`.- For chat history, derive device scope with `deviceIDFromContext(ctx)` and pass it to repository filters.- For send operations, sanitize/validate phone/JID, build whatsmeow payloads, send, then store sent messages with context when appropriate.+- `wrapSendMessage` uses `whatsapp.SendMessageWithReachoutRetry`; keep 463 normalization in this layer aligned with infrastructure retry behavior.- Preserve existing error style: package errors from `pkg/error`, wrapped validation errors, and direct `fmt.Errorf` for contextual failures.## ANTI-PATTERNS@@ -30,9 +33,10 @@ Usecases orchestrate validation, device/client lookup, WhatsApp operations, stor- Do not fall back to the global client when a request has an explicit device context.- Do not skip validation because the REST handler already parsed the body.- Do not return Fiber/MCP response objects from usecases.-- Do not perform unscoped chat/message reads from this layer.+- Do not perform unscoped chat/message reads from this layer unless the operation documents why global ID lookup is protocol-safe.+- Do not replace device-scoped reply lookup with `GetMessageByID`; quoted replies must not bind a message from another device.## TESTING-- Existing usecase tests are narrow. Add focused tests when changing mapping, MIME/media decisions, or device-scoped chat behavior.+- Existing usecase tests are narrow. Add focused tests when changing mapping, MIME/media decisions, reply context, or device-scoped chat behavior.- Stubs live beside tests rather than using gomock/mockery.diff --git a/src/validations/AGENTS.md b/src/validations/AGENTS.mdindex f97dd568..36ef9e50 100644--- a/src/validations/AGENTS.md+++ b/src/validations/AGENTS.md@@ -1,6 +1,6 @@# VALIDATIONS-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW@@ -11,6 +11,7 @@ Validation functions enforce request shape before usecases touch whatsmeow, stor| Task | Location | Notes ||------|----------|-------|| Send validation | `send_validation.go` | Phone format, file-vs-URL, MIME, max sizes, duration, mentions, poll options. |+| Reply message fields | `send_validation.go`, `send_validation_test.go` | `reply_message_id` is optional; tests cover pass-through for text/media requests. || Chat validation | `chat_validation.go` | Mutates request defaults for limit/offset before validating. || Group validation | `group_validation.go` | Uses whatsmeow participant action constants. || Message validation | `message_validation.go` | Watch boolean `Required` behavior. |@@ -24,9 +25,10 @@ Validation functions enforce request shape before usecases touch whatsmeow, stor- Phone numbers must be international format; Indonesian local `08...` should fail.- `@everyone` is a special mention and bypasses phone validation.- Multipart tests usually construct `multipart.FileHeader` with a `Content-Type` header directly.+- Max-size checks must read from `config.WhatsappSettingMax*`, not duplicated literals.## ANTI-PATTERNS- Do not use `validation.Required` on a plain `bool` when `false` is valid; use a pointer or explicit validation pattern.- Do not accept both file and URL for request types that require exactly one input.-- Do not let max-size checks drift from `config.WhatsappSettingMax*`.+- Do not make optional metadata like `reply_message_id` required unless the API contract changes.diff --git a/src/views/AGENTS.md b/src/views/AGENTS.mdindex 3d19df0f..f163167b 100644--- a/src/views/AGENTS.md+++ b/src/views/AGENTS.md@@ -1,6 +1,6 @@# EMBEDDED WEB UI-Generated: 2026-05-24+Generated: 2026-06-05## OVERVIEW@@ -10,11 +10,11 @@ The UI is embedded into the Go binary and served by Fiber. It uses Vue 3 plain J```textviews/-├── index.html # Imports all components, creates Vue app, manages selected device-├── assets/app.css # Local CSS-├── assets/gowa.svg # Logo-└── components/ # One plain JS module per card/modal- └── generic/ # Reused form pieces+|-- index.html # Imports all components, creates Vue app, manages selected device+|-- assets/app.css # Local CSS+|-- assets/gowa.svg # Logo+`-- components/ # One plain JS module per card/modal+ `-- generic/ # Reused form pieces```## WHERE TO LOOK@@ -23,6 +23,8 @@ views/|------|----------|-------|| Add card/modal | `components/<Name>.js`, `index.html` | Import, register component, and place tag in the right grid. || Shared recipient fields | `components/generic/FormRecipient.js` | Used by send/message/group components. |+| Send forms | `components/Send*.js` | Text/link use JSON payloads; media forms append fields to `FormData`. |+| Reply Message ID UI | `SendMessage.js` and media/link send components | Keep optional `reply_message_id` omitted when blank. || Device selector | `components/DeviceManager.js`, `index.html` | Sets `X-Device-Id` and websocket query param. || Chat UI | `components/ChatList.js`, `components/ChatMessages.js` | Handles null/empty API result cases. |