@shotik/mcp 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/README.ru.md +40 -0
- package/data/PROTOCOL.md +386 -0
- package/data/flutter/INTEGRATION.md +197 -0
- package/data/flutter/README.md +112 -0
- package/data/flutter/README.ru.md +165 -0
- package/data/flutter/guide.json +190 -0
- package/data/flutter/recipe.json +364 -0
- package/data/react-native/README.md +194 -0
- package/data/react-native/README.ru.md +192 -0
- package/data/react-native/guide.json +136 -0
- package/data/react-native/recipe.json +263 -0
- package/data/react-native/src/analytics/README.md +32 -0
- package/data/react-native/src/analytics/recipe.json +263 -0
- package/data/storecheck/packs/ai.json +1 -0
- package/data/storecheck/packs/dating.json +1 -0
- package/data/storecheck/packs/education.json +1 -0
- package/data/storecheck/packs/finance.json +1 -0
- package/data/storecheck/packs/fitness.json +1 -0
- package/data/storecheck/packs/health.json +1 -0
- package/data/storecheck/packs/kids.json +1 -0
- package/data/storecheck/packs/language.json +1 -0
- package/data/storecheck/packs/mindfulness.json +1 -0
- package/data/storecheck/packs/music.json +1 -0
- package/data/storecheck/packs/nutrition.json +1 -0
- package/data/storecheck/packs/photo-video.json +1 -0
- package/data/storecheck/packs/productivity.json +1 -0
- package/data/storecheck/packs/spirituality.json +1 -0
- package/data/storecheck/packs/taxonomy.json +1 -0
- package/data/storecheck/packs/utilities.json +1 -0
- package/data/storecheck/storecheck.browser.js +314 -0
- package/data/swift/README.md +327 -0
- package/data/swift/README.ru.md +333 -0
- package/data/swift/guide.json +189 -0
- package/data/swift/recipe.json +506 -0
- package/package.json +42 -4
- package/server.mjs +144 -0
- package/sources.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shotik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @shotik/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server that gives any coding agent (Claude Code, Codex, Cursor and others) Shotik's SDK install recipes, guides
|
|
4
|
+
and wire protocol, so the agent adds Shotik Support and Analytics to an app by itself. Русская версия:
|
|
5
|
+
[README.ru.md](README.ru.md).
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
claude mcp add shotik -- npx -y @shotik/mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Any other MCP client:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{ "mcpServers": { "shotik": { "command": "npx", "args": ["-y", "@shotik/mcp"] } } }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then ask the agent: "Add Shotik support chat to this app." It needs two values from you: the public app key (`spk_…`,
|
|
18
|
+
from Shotik → Support → SDK) and your Shotik server URL.
|
|
19
|
+
|
|
20
|
+
| Tool | What it returns |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `detect_project { path? }` | Which SDK fits the app folder (default: the current directory), whether it is already installed, and the install command |
|
|
23
|
+
| `list_sdks` | Every SDK with its package and install command |
|
|
24
|
+
| `get_recipe { sdk }` | The machine-readable recipe (`shotik.recipe/1`): detect rules, edits, commands and checks, step by step |
|
|
25
|
+
| `get_guide { sdk, lang? }` | The human guide and README, in `en` or `ru` |
|
|
26
|
+
| `get_protocol` | The wire protocol every SDK follows, for building or debugging an SDK |
|
|
27
|
+
| `store_check { app, lang?, country? }` | An App Store listing against its category: listing facts, category, what top apps in that subtype do, trial and subscription wording, last update, screenshots, rating and reviews. Ends with a `shotik://continue` link that opens it in Shotik |
|
|
28
|
+
|
|
29
|
+
The same files are resources: `shotik://recipe/<sdk>`, `shotik://guide/<sdk>`, `shotik://readme/<sdk>` (and `/ru`),
|
|
30
|
+
`shotik://protocol`.
|
|
31
|
+
|
|
32
|
+
| `sdk` | Package | Install |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `react-native` | [@shotik/react-native](https://www.npmjs.com/package/@shotik/react-native) | `npx expo install @shotik/react-native` |
|
|
35
|
+
| `react-native-analytics` | `@shotik/react-native/analytics` | the same package |
|
|
36
|
+
| `swift` | [github.com/rahimwws/shotik-app](https://github.com/rahimwws/shotik-app) | Xcode → Add Package Dependencies…, from `0.1.0` |
|
|
37
|
+
| `flutter` | [shotik](https://pub.dev/packages/shotik) | `flutter pub add shotik` |
|
|
38
|
+
|
|
39
|
+
The server reads only the files bundled in the package and, for `detect_project`, the top level of the folder you pass.
|
|
40
|
+
It has no dependencies. Its only network calls are `store_check`'s reads of Apple's public App Store lookup and review
|
|
41
|
+
RSS; in-app purchase prices aren't public, so it never states them.
|
package/README.ru.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @shotik/mcp
|
|
2
|
+
|
|
3
|
+
MCP-сервер, который даёт любому агенту для кода (Claude Code, Codex, Cursor и другим) рецепты установки SDK Shotik,
|
|
4
|
+
инструкции и протокол, чтобы агент сам подключил Shotik Support и аналитику к приложению. English: [README.md](README.md).
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
claude mcp add shotik -- npx -y @shotik/mcp
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Любой другой MCP-клиент:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{ "mcpServers": { "shotik": { "command": "npx", "args": ["-y", "@shotik/mcp"] } } }
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Потом попросите агента: «Подключи чат поддержки Shotik к этому приложению». От вас нужны два значения: публичный ключ
|
|
17
|
+
приложения (`spk_…`, в Shotik → Support → SDK) и адрес вашего сервера Shotik.
|
|
18
|
+
|
|
19
|
+
| Инструмент | Что возвращает |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `detect_project { path? }` | Какой SDK подходит папке приложения (по умолчанию текущей), установлен ли он уже и команду установки |
|
|
22
|
+
| `list_sdks` | Все SDK с пакетом и командой установки |
|
|
23
|
+
| `get_recipe { sdk }` | Машиночитаемый рецепт (`shotik.recipe/1`): правила определения, правки, команды и проверки по шагам |
|
|
24
|
+
| `get_guide { sdk, lang? }` | Инструкцию и README на `en` или `ru` |
|
|
25
|
+
| `get_protocol` | Протокол, которому следует каждый SDK, — чтобы написать или отладить SDK |
|
|
26
|
+
| `store_check { app, lang?, country? }` | Страница в App Store против её категории: факты листинга, категория, что делают топ-приложения подтипа, формулировки триала и подписки, последнее обновление, скриншоты, рейтинг и отзывы. В конце ссылка `shotik://continue`, которая открывает это в Shotik |
|
|
27
|
+
|
|
28
|
+
Те же файлы доступны как ресурсы: `shotik://recipe/<sdk>`, `shotik://guide/<sdk>`, `shotik://readme/<sdk>` (и `/ru`),
|
|
29
|
+
`shotik://protocol`.
|
|
30
|
+
|
|
31
|
+
| `sdk` | Пакет | Установка |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| `react-native` | [@shotik/react-native](https://www.npmjs.com/package/@shotik/react-native) | `npx expo install @shotik/react-native` |
|
|
34
|
+
| `react-native-analytics` | `@shotik/react-native/analytics` | тот же пакет |
|
|
35
|
+
| `swift` | [github.com/rahimwws/shotik-app](https://github.com/rahimwws/shotik-app) | Xcode → Add Package Dependencies…, от `0.1.0` |
|
|
36
|
+
| `flutter` | [shotik](https://pub.dev/packages/shotik) | `flutter pub add shotik` |
|
|
37
|
+
|
|
38
|
+
Сервер читает только файлы, вложенные в пакет, а для `detect_project` — верхний уровень папки, которую вы передали.
|
|
39
|
+
Зависимостей нет. В сеть ходит только `store_check`: публичный lookup App Store и RSS отзывов Apple; цены встроенных
|
|
40
|
+
покупок не публичны, поэтому он их никогда не называет.
|
package/data/PROTOCOL.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# Shotik SDK protocol (v1)
|
|
2
|
+
|
|
3
|
+
One platform-neutral contract for every Shotik SDK: React Native (sdk/react-native, the reference), Swift
|
|
4
|
+
(sdk/swift), Flutter (sdk/flutter) and any later port. A port is correct when it puts the same bytes on the wire, keeps
|
|
5
|
+
the same state machine and stores the same keys as the reference. Where this file and the reference disagree, the
|
|
6
|
+
reference code wins and this file gets fixed.
|
|
7
|
+
|
|
8
|
+
Reference sources (2026-11-28):
|
|
9
|
+
|
|
10
|
+
| Part | File | Owner |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| Support client | sdk/react-native/src/client.ts (branch wt/sdk-ui) | APPC-11 |
|
|
13
|
+
| Support server | server/src/support.ts, server/src/sdkauth.ts (wt/sdk-ui, wt/backend) | APPC-11 |
|
|
14
|
+
| Analytics wire format | sdk/react-native/src/analytics/wire.ts (wt/analytics) | APPC-20 |
|
|
15
|
+
| Analytics client | sdk/react-native/src/analytics/core.ts, rn.tsx (wt/analytics) | APPC-20 |
|
|
16
|
+
| Analytics store | server/src/analytics/store.ts (wt/analytics) | APPC-20 |
|
|
17
|
+
|
|
18
|
+
Contents: 1 Transport and auth · 2 Identity · 3 Support · 4 Analytics · 5 Storage keys · 6 Widget contract ·
|
|
19
|
+
7 Privacy · 8 Performance budgets · 9 Conformance tests · 10 Versioning.
|
|
20
|
+
|
|
21
|
+
## 1. Transport and auth
|
|
22
|
+
|
|
23
|
+
- **Base URL.** `serverUrl` with trailing slashes removed. The simulator reaches the Mac at `http://127.0.0.1:4590`;
|
|
24
|
+
a device needs the Mac's LAN address or an HTTPS deployment. `GET /health` answers `{"ok":true,…}`.
|
|
25
|
+
- **App key.** Every SDK request carries `x-shotik-key: spk_…`, the app's public key from Shotik → Support → SDK
|
|
26
|
+
(`support.enable`). It is public by design: it is shipped in the app binary and only identifies the app.
|
|
27
|
+
- **User token.** `POST /support/v1/identify` returns `userToken` = `<userId>.<base64url HMAC-SHA256(ws|appId|userId)>`.
|
|
28
|
+
Support requests carry it as `x-shotik-user`. Clients treat it as opaque, never parse it, and store it in the platform's
|
|
29
|
+
secure store where one exists (Keychain on iOS).
|
|
30
|
+
- **Bodies.** JSON, UTF-8, `content-type: application/json`, except the attachment upload (multipart). v1 sends
|
|
31
|
+
identity encoding: the server does not decompress request bodies, so no `content-encoding: gzip`. Analytics gets its
|
|
32
|
+
compression from dictionary packing (section 4.3).
|
|
33
|
+
- **Errors.** Non-2xx answers carry `{"error": "<reason>"}`. Clients classify them like this:
|
|
34
|
+
|
|
35
|
+
| Status | Meaning | Client action |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| network error, 5xx, 429 | transient | keep the work queued, back off, retry |
|
|
38
|
+
| 401 on identify | unknown app key | status `error`, error "unknown app key", stop retrying until reconfigured |
|
|
39
|
+
| 401 on other support routes | user token no longer valid | drop the session, identify again, then resume the queue |
|
|
40
|
+
| other 4xx | the request itself is wrong | drop that one item (mark a message `failed`), continue with the next |
|
|
41
|
+
|
|
42
|
+
- **Backoff.** Reconnect delay = `min(30 s, 500 ms × 2^n) × uniform(0.8, 1.2)`, n = consecutive failures, reset to 0 on
|
|
43
|
+
`ready`. Send retry delay = `min(30 s, 500 ms × 2^attempts)`. Analytics flush interval = `flushMs × 2^backoff`, backoff
|
|
44
|
+
capped at 5 (10 s → 320 s), reset after a successful upload.
|
|
45
|
+
- **CORS.** `/support/v1/*` answers OPTIONS with 204 and `access-control-allow-headers: content-type, x-shotik-key,
|
|
46
|
+
x-shotik-user`, so a web build works too.
|
|
47
|
+
|
|
48
|
+
## 2. Identity
|
|
49
|
+
|
|
50
|
+
One install has one anonymous id, shared by Support and Analytics.
|
|
51
|
+
|
|
52
|
+
- `anonymousId` = `"anon_" + random`, created on first use, persisted under `shotik.support.anon`, replaced on `reset()`.
|
|
53
|
+
- The server derives the support user id: `su_ + sha(appId | "u:" + userId)` when the app passes its own `userId`,
|
|
54
|
+
else `su_ + sha(appId | "a:" + anonymousId)`.
|
|
55
|
+
- **Anonymous → signed in.** Identify with both `anonymousId` and `userId`: the server moves the anonymous user's
|
|
56
|
+
conversations to the signed-in user. Analytics sends `userId` on each batch and an `identify` event.
|
|
57
|
+
- **Sign-out** (`reset()`): a new anonymous id, the session, send queue, read marks and conversations are cleared, the
|
|
58
|
+
socket closes; analytics flushes what it has, then starts a new session under the new anonymous id.
|
|
59
|
+
- Calls made before `configure` (identify, track, open) are held and replayed in order once it runs.
|
|
60
|
+
|
|
61
|
+
## 3. Support
|
|
62
|
+
|
|
63
|
+
### 3.1 Model
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
type Author = 'user' | 'ai' | 'founder' | 'system'
|
|
67
|
+
type ConversationStatus = 'open' | 'needs_human' | 'resolved' | 'closed' // unknown strings must be tolerated
|
|
68
|
+
type Status = 'idle' | 'identifying' | 'connecting' | 'live' | 'offline' | 'error'
|
|
69
|
+
|
|
70
|
+
Conversation { id, status, subject: string|null, lastMessageAt: ms, lastPreview: string|null,
|
|
71
|
+
lastAuthor: Author|null, createdAt: ms, founderUnread?: number }
|
|
72
|
+
Message { id, conversationId, author, body, createdAt: ms, meta?: object|null, deliveredAt?: ms|null,
|
|
73
|
+
localId?, pending?: 'sending'|'waiting'|'failed' } // localId and pending are client-only
|
|
74
|
+
Attachment { id, type, size, width|null, height|null, path } // path is server-relative and signed
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- Times are Unix milliseconds. Ids are server strings (`sc_…` conversations, `sm_…` messages, `sa_…` attachments).
|
|
78
|
+
- `meta` known keys: `localId` (client dedupe), `attachments` (≤ 4), `quickReplies: string[]` (on AI answers),
|
|
79
|
+
`handoff: true` (the system note). Unknown keys are kept and ignored.
|
|
80
|
+
- Body ≤ 8000 characters after trim. A photo-only message has an empty body; its preview is "Photo".
|
|
81
|
+
|
|
82
|
+
### 3.2 HTTP routes (SDK side)
|
|
83
|
+
|
|
84
|
+
| Route | Body / query | Answer |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `POST /support/v1/identify` | `{ anonymousId, userId?, name?, email?, attributes?, device?, appVersion?, locale? }` | `{ user: { id }, userToken, conversations: Conversation[] }` |
|
|
87
|
+
| `POST /support/v1/push-token` | `{ token: string\|null, platform: 'ios'\|'android'\|… }` | `{ ok }` |
|
|
88
|
+
| `GET /support/v1/conversations` | | `{ conversations }` |
|
|
89
|
+
| `POST /support/v1/conversations` | `{ body, meta? }` (starts a conversation) | `{ conversation, message }` |
|
|
90
|
+
| `GET /support/v1/conversations/:id/messages` | `?after=<ms>` (strictly greater) | `{ messages }` ascending; stamps `delivered_at` on replies |
|
|
91
|
+
| `POST /support/v1/conversations/:id/messages` | `{ body, meta? }` | `{ message }` |
|
|
92
|
+
| `POST /support/v1/conversations/:id/read` | `{}` | `{ ok }` (founder sees "Read") |
|
|
93
|
+
| `POST /support/v1/conversations/:id/handoff` | `{}` | `{ conversation }` status `needs_human`, plus a system message |
|
|
94
|
+
| `POST /support/v1/attachments` | multipart: `file` (image/jpeg, png, heic, heif, webp, gif; ≤ 8 MB), optional `width`, `height` | `{ attachment }` |
|
|
95
|
+
| `GET /support/v1/attachments/:id?s=<sig>` | no headers needed | the image, immutable cache |
|
|
96
|
+
|
|
97
|
+
- **Identify device fields** (support naming): `device = { platform, osVersion, model, appVersion, build, locale, timezone }`;
|
|
98
|
+
`appVersion` at the top level is `"1.4.2 (87)"` (version plus build in parentheses); `locale` is a BCP 47 tag (`ru-RU`).
|
|
99
|
+
The server picks the AI's answer language and the handoff note's language from the locale's first two letters.
|
|
100
|
+
- **Attachments.** Upload each picked image once, keep the returned attachment on the queue item (a retry never uploads
|
|
101
|
+
twice), then send the message with `meta.attachments: [{ id }]`. The server keeps only this user's uploads and
|
|
102
|
+
rewrites each to the full Attachment. Show one as `serverUrl + path` without headers; the signature is the auth.
|
|
103
|
+
Clients downscale to ≤ 2048 px on the long edge and encode JPEG at quality 0.8 before upload (HEIC is accepted but
|
|
104
|
+
Shotik's renderer shows JPEG faster).
|
|
105
|
+
|
|
106
|
+
### 3.3 Live stream
|
|
107
|
+
|
|
108
|
+
`ws(s)://<host>/support/v1/stream?key=<spk>&user=<userToken>` (scheme from serverUrl: http → ws, https → wss).
|
|
109
|
+
|
|
110
|
+
| Frame (server → app) | Client action |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `{ t: 'ready' }` | status `live`, reset backoff, start the ping timer, `pull()`, flush the send queue |
|
|
113
|
+
| `{ t: 'message', message }` | merge into its conversation (also receipts: a user message re-sent with `deliveredAt`); update the conversation's last fields; mark read if that thread is open; clear typing for that conversation when the author isn't `user` |
|
|
114
|
+
| `{ t: 'conversation', conversation }` | upsert (status, founderUnread, last fields) |
|
|
115
|
+
| `{ t: 'typing', conversationId, who: 'ai'\|'founder', ttl }` | show "<who> is typing" for ttl ms; ttl 0 clears it |
|
|
116
|
+
| text `pong` | ignore |
|
|
117
|
+
|
|
118
|
+
- The client sends the text frame `ping` every 25 s while open. No other client → server frames exist.
|
|
119
|
+
- Close code **4003** = unauthorized: drop the session and identify again. Any other close: status `offline`, reconnect
|
|
120
|
+
with backoff.
|
|
121
|
+
- Keep the socket open only while the app is in the foreground. On background: close it (`disconnect()`). On
|
|
122
|
+
foreground: reconnect now (or `pull()` if still open) and flush the queue. This is also why the widget costs nothing
|
|
123
|
+
while the app is backgrounded.
|
|
124
|
+
|
|
125
|
+
### 3.4 Send queue (offline-first)
|
|
126
|
+
|
|
127
|
+
1. `send(body, conversationId?, attachments?)` trims the body, returns `null` when there is neither text nor an
|
|
128
|
+
attachment, and otherwise appends `{ localId: "local_"+random, conversationId, body, createdAt, attempts: 0,
|
|
129
|
+
attachments? }` to the queue, persists the queue, and shows an optimistic message (`pending: 'sending'`) at once.
|
|
130
|
+
2. Without a conversation id (and none active), the item gets a local conversation id `local_conv_<random>`; the client
|
|
131
|
+
lists a local conversation for it until the server answers.
|
|
132
|
+
3. `flush()` runs one at a time, oldest first, only with a session. Delivery: local conversation → `POST
|
|
133
|
+
/conversations`, then remap every queued item and message from the local id to the server id; otherwise `POST
|
|
134
|
+
/conversations/:id/messages`. `meta.localId` is always sent so the answer (and a later stream echo) replaces the
|
|
135
|
+
optimistic message instead of duplicating it.
|
|
136
|
+
4. Failure handling follows section 1. A transient failure (network error, 5xx, 429) never fails a message: it stays
|
|
137
|
+
queued, turns `pending: 'waiting'` (receipt `queued`: a clock and "Will send when you're back online" / «Отправим,
|
|
138
|
+
когда появится связь») and keeps retrying on its own with the send backoff, however many attempts it takes. Only
|
|
139
|
+
another 4xx drops the item and marks the message `failed` ("Not sent · Retry"). `retry(localId)` puts a failed
|
|
140
|
+
message back in the queue (`pending: 'sending'`), resets attempts and flushes now.
|
|
141
|
+
5. The queue survives restarts: it is restored on load and its items show as optimistic messages again (`waiting` when
|
|
142
|
+
they already have attempts, else `sending`).
|
|
143
|
+
|
|
144
|
+
### 3.5 Reading, unread and receipts
|
|
145
|
+
|
|
146
|
+
- Read marks are local: `readAt[conversationId] = max(createdAt)` of what the user has seen, persisted.
|
|
147
|
+
- Unread per conversation = replies (author ≠ `user`) newer than its read mark; with no messages loaded yet, 1 when
|
|
148
|
+
`lastAuthor ≠ user` and `lastMessageAt` is newer than the mark. Total unread drives the launcher badge.
|
|
149
|
+
- Opening a thread (or a reply arriving into the open thread) marks it read locally and posts `/read`.
|
|
150
|
+
- `loadMessages(id)`: the first load fetches `after=0`; later loads fetch `after = lastCreatedAt - 1` and merge by id or
|
|
151
|
+
`meta.localId`, sorted by `createdAt`.
|
|
152
|
+
- Receipt of one of your messages: `failed` → `queued` (`waiting`, or any pending message while offline) or
|
|
153
|
+
`sending` → `seen` when it is not among the conversation's last `founderUnread` user messages → `delivered` when
|
|
154
|
+
`deliveredAt` is set → `sent`. Only the last user message shows its receipt line.
|
|
155
|
+
- `pull()` (after `ready` and on foreground): list conversations, then reload every conversation with messages in memory
|
|
156
|
+
plus the active one.
|
|
157
|
+
|
|
158
|
+
### 3.6 Client API (every platform, same names in the platform's casing)
|
|
159
|
+
|
|
160
|
+
`configure({ appKey, serverUrl })`, `identify(user?)`, `reset()`, `setPushToken(token|null, platform)`,
|
|
161
|
+
`open(conversationId?)`, `close()`, `select(conversationId|null)`, `send(body, conversationId?, attachments?)`,
|
|
162
|
+
`retry(localId)`, `handoff(conversationId)`, `markRead(id)`, `pull()`, `foreground()`, `disconnect()`, `stop()`,
|
|
163
|
+
observable state `{ status, userId, conversations, messages, unread, unreadBy, typing, open, activeConversationId, error }`.
|
|
164
|
+
|
|
165
|
+
## 4. Analytics
|
|
166
|
+
|
|
167
|
+
### 4.1 Events
|
|
168
|
+
|
|
169
|
+
Type codes are array positions: **append only, never reorder.**
|
|
170
|
+
|
|
171
|
+
| Code | Type | When | Props |
|
|
172
|
+
|---|---|---|---|
|
|
173
|
+
| 0 | session | a new session starts | `first: 1` on the first session of the install; `store: 'none' \| 'error'` when the install id can't be persisted (no storage, or the read threw), so every launch looks new (APPC-20, additive). Key order `first, store` |
|
|
174
|
+
| 1 | open | app to foreground | |
|
|
175
|
+
| 2 | close | app to background | |
|
|
176
|
+
| 3 | screen | screen shown (`name` = screen) | `from` (previous screen), `resume: 1` after foreground, `ms` ready time |
|
|
177
|
+
| 4 | leave | screen left (`name` = the screen left) | `dur` ms, `depth` 0..1 (2 decimals), `drag` pt, `stalls`, `maxStall` ms |
|
|
178
|
+
| 5 | tap | any tap | `el`, `label`, `x`, `y` (pt, rounded), `nx`, `ny` (0..1000 of the window), `dead: 1`, `input: 1`, `id` |
|
|
179
|
+
| 6 | rage | 3 taps within 800 ms and 40 pt | `el`, `label`, `n: 3`, `x`, `y`, `id` |
|
|
180
|
+
| 7 | scroll | reserved (scroll goes into `leave`) | |
|
|
181
|
+
| 8 | error | uncaught error or reported one | `msg` ≤ 200 chars, `fatal: 1`, `stack` top 5 frames ≤ 120 chars each, no values, no URLs |
|
|
182
|
+
| 9 | slow | screen ready > 700 ms, or a main-thread stall > 1000 ms | `ms`, `kind: 'ready'\|'stall'` |
|
|
183
|
+
| 10 | purchase | purchase lifecycle (`name` = product id) | `product`, `status: start\|done\|cancel\|fail`, `price` (decimal major units), `currency` (ISO 4217), `store` (`app_store`, `play`, `stripe`…), `trial: 1` |
|
|
184
|
+
| 11 | custom | `track(name, props)` | free-form, no PII by contract |
|
|
185
|
+
| 12 | identify | `identify(userId, traits)` | `traits` |
|
|
186
|
+
| 13 | snapshot | a wireframe was recorded for this screen | `n` node count |
|
|
187
|
+
|
|
188
|
+
Every event: `{ seq, ts, type, sessionId, screen?, name?, props? }`. `screen` is the current screen when the event happened.
|
|
189
|
+
Props whose value is undefined/nil are left out; booleans travel as `1` and are absent when false.
|
|
190
|
+
|
|
191
|
+
- **Element identity (`el`).** A short, stable path of meaningful component/view names from the window down to the
|
|
192
|
+
touched element, joined with `>`, at most 3 segments, plus `#<id>` when the element has a developer id (testID,
|
|
193
|
+
accessibilityIdentifier, Flutter `Key` value). Generic containers are skipped. `label` is the element's accessibility
|
|
194
|
+
label, else its visible text, ≤ 40 characters, and empty for masked elements and inputs. Tap targets that handle no
|
|
195
|
+
press are `dead: 1`; text inputs are `input: 1`.
|
|
196
|
+
- **Stable element key (`id`, added 2026-11-28 by APPC-20, additive).** The developer's id for the element: testID or
|
|
197
|
+
nativeID in React Native, accessibilityIdentifier on iOS, the `Key` value or `Semantics(identifier:)` in Flutter; React
|
|
198
|
+
Native falls back to `"h" + hash(fiber index path)`. It is a plain prop (not dictionary packed). Key order as core.ts builds it: tap `el, x, y, nx, ny,
|
|
199
|
+
id, label, dead, input`; rage `el, id, label, n, x, y`. Without it the server keys elements on `el|label`.
|
|
200
|
+
- **Sessions.** A new session starts when there is none or the app was idle longer than `sessionTimeoutMs` (30 min).
|
|
201
|
+
`sessionId` = `"s_" + random`; `seq` restarts at 1 per session and increases by 1 per event.
|
|
202
|
+
- **Dedupe.** The server keys events on `(app, sessionId, seq)` and ignores repeats, so a retried batch never double
|
|
203
|
+
counts. It follows that `sessionId` and `seq` must be persisted together with the queue: a client that reused a
|
|
204
|
+
`(sessionId, seq)` pair after a crash would lose the new event as a "duplicate".
|
|
205
|
+
- **Stalls.** The main thread is watched from a background thread at 500 ms; a stall is the time the main thread
|
|
206
|
+
answered late. `stall(ms)` counts into the screen's `stalls`/`maxStall`, and over 1000 ms it also emits `slow`.
|
|
207
|
+
|
|
208
|
+
### 4.2 Batches and upload
|
|
209
|
+
|
|
210
|
+
`POST /analytics/v1/events` with `x-shotik-key`, body = the packed batch (4.3) → `{ accepted, duplicate }`.
|
|
211
|
+
|
|
212
|
+
- Queue limit **2000** events (oldest dropped). Batch size **300**. Flush every **10 s** (`flushMs`), at 300 queued, on
|
|
213
|
+
background, and on `flush()`. One upload at a time; while the queue holds ≥ 300 after a success, flush again at once.
|
|
214
|
+
- Status: 2xx → remove the sent events. 5xx, 429, network → keep, back off. Other 4xx → drop that batch (it is malformed
|
|
215
|
+
and would fail forever).
|
|
216
|
+
- Wireframes: `POST /analytics/v1/snapshots` body `{ anonymousId, sessionId, screen, ts, w, h, dark?, nodes }`, at most 4
|
|
217
|
+
per flush, after the events.
|
|
218
|
+
- Consent: `granted` (default) uploads; `pending` keeps events on the device until granted; `denied` drops the queue and
|
|
219
|
+
records nothing. Persisted under `shotik.analytics.consent`.
|
|
220
|
+
- Background: emit `leave` and `close`, persist, flush. On iOS the flush runs inside a background task assertion; on
|
|
221
|
+
Android inside the lifecycle stop callback with a short timeout. Never block the main thread on it.
|
|
222
|
+
- Persist the state and queue at most once a second (debounced) and immediately on background and on a fatal error.
|
|
223
|
+
|
|
224
|
+
### 4.3 Wire format (packed batch v1)
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
PackedBatch { v: 1, a: anonymousId, u?: userId|null, f?: firstSeen ms, c?: DeviceContext, t0: first event ts,
|
|
228
|
+
d: string[], e: PackedEvent[] }
|
|
229
|
+
PackedEvent = [dt, type, seq, session, screen, name, props]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- `d` is a per-batch string dictionary. `session`, `screen` and `name` are indexes into it, `-1` when absent. Inside props,
|
|
233
|
+
string values of `el`, `label` and `from` are also dictionary indexes; every other prop keeps its value.
|
|
234
|
+
- Strings enter the dictionary in first-use order while events are packed in order. Inside one event the props come
|
|
235
|
+
first, in the object's key order, and then session, screen and name, exactly as wire.ts `pack()` does it. The order matters only for byte-identical conformance tests; the server just looks indexes up.
|
|
236
|
+
- `dt` is the delta from the previous event's `ts` (the first event's is relative to `t0`, so 0). `type` is the code from 4.1.
|
|
237
|
+
`dt` can be negative: a tap is resolved after the event and can be queued behind the next screen's events while
|
|
238
|
+
keeping its own earlier `ts` and screen. Servers sort by `ts` (store.ts ingest does) and never assume order.
|
|
239
|
+
- `props` is `0` when the event has none, else an object.
|
|
240
|
+
- `DeviceContext` (analytics naming): `{ platform, os, model, app, build, locale, tz, w, h }` (`w`/`h` = window size in
|
|
241
|
+
points, rounded). `platform` is `ios`, `android`, `macos`, or `web`.
|
|
242
|
+
|
|
243
|
+
Example: two taps and a screen on Paywall become
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{"v":1,"a":"anon_m3k2…","u":null,"f":1764280000000,"c":{"platform":"ios","os":"26.1","model":"iPhone18,1","app":"1.4.2","build":"87","locale":"en-US","tz":"Asia/Kuala_Lumpur","w":402,"h":874},
|
|
247
|
+
"t0":1764281000000,"d":["Onboarding","s_m3k2…","Paywall","PlanCard>Button#annual","Start trial"],
|
|
248
|
+
"e":[[0,3,4,1,2,2,{"from":0}],[1800,5,5,1,2,-1,{"el":3,"x":201,"y":610,"nx":500,"ny":698,"label":4}],[240,5,6,1,2,-1,{"el":3,"x":203,"y":612,"nx":505,"ny":700,"label":4}]]}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 4.4 Wireframes
|
|
252
|
+
|
|
253
|
+
A privacy-safe picture of one screen, recorded once per screen per sampled session (`snapshots` share, default 0.2,
|
|
254
|
+
decided at session start). `WireNode = [kind, x, y, w, h, fill?, radius?]` in points, kinds `v` view, `t` text (a bar,
|
|
255
|
+
never characters), `i` image (a box, never pixels), `b` button, `n` input (never its value), `s` scroll, `m` masked.
|
|
256
|
+
Cap 400 nodes; skip views smaller than 2×2 pt, hidden, fully transparent or off screen. `fill` is `#RRGGBB` of the
|
|
257
|
+
background when opaque. The server keeps the newest 3 per screen.
|
|
258
|
+
|
|
259
|
+
### 4.5 Client API
|
|
260
|
+
|
|
261
|
+
`configure({ appKey, serverUrl, consent?, snapshots?, flushMs?, sessionTimeoutMs?, debug? })`, `track(name, props?)`,
|
|
262
|
+
`identify(userId|null, traits?)`, `screen(name)`, `purchase({ product, status, price?, currency?, store?, trial? })`,
|
|
263
|
+
`error(e, fatal?)`, `setConsent(granted|denied|pending)`, `optIn()`, `optOut()`, `reset()`, `flush()`, `ids`.
|
|
264
|
+
|
|
265
|
+
### 4.6 Automatic capture per platform
|
|
266
|
+
|
|
267
|
+
| Signal | React Native | Swift (UIKit + SwiftUI) | Flutter |
|
|
268
|
+
|---|---|---|---|
|
|
269
|
+
| Screens | Navigation / Expo Router state | top view controller after each transition, named by `.shotikScreen()` / navigation title / class; opt-in `ShotikAnalytics.screen` | a `NavigatorObserver` (route name), `ShotikScreen` widget, GoRouter-friendly |
|
|
270
|
+
| Taps | one capture-phase responder on a root View | one passive gesture recognizer per window (`cancelsTouchesInView = false`, never recognizes): no swizzling | one `Listener` at the root + a hit test to find the element |
|
|
271
|
+
| Open / close | AppState | scene / application notifications | `AppLifecycleListener` |
|
|
272
|
+
| Crashes | global error handler | `NSSetUncaughtExceptionHandler` chained to the previous handler (Swift traps stay with the crash reporter) | `FlutterError.onError` + `PlatformDispatcher.onError`, chained |
|
|
273
|
+
| Stalls | 500 ms timer drift | background watchdog pinging the main queue | `SchedulerBinding` frame timings |
|
|
274
|
+
| Purchases | RevenueCat calls wrapped | StoreKit 2 `Transaction.updates` + a watermark scan of `Transaction.all` on foreground; `ShotikAnalytics.purchase(product:result:)` for start/cancel | `in_app_purchase` purchase stream adapter (duck typed, no dependency) |
|
|
275
|
+
| Wireframes | host tree measure | view hierarchy walk on the main thread inside the ≤ 2 ms frame budget, encoded off main | render tree walk, encoded off main |
|
|
276
|
+
| Masking | `<ShotikMask>` / `shotikMask` | `.shotikMask()` / `view.shotikMasked = true`; secure text fields and all inputs always | `ShotikMask` widget; all `EditableText` always |
|
|
277
|
+
|
|
278
|
+
## 5. Storage keys
|
|
279
|
+
|
|
280
|
+
Same names on every platform (UserDefaults suite `ai.shotik.sdk` / SharedPreferences file `shotik_sdk` / a JSON file in
|
|
281
|
+
the app support dir), except that secrets go to the secure store.
|
|
282
|
+
|
|
283
|
+
| Key | Value | Secure |
|
|
284
|
+
|---|---|---|
|
|
285
|
+
| `shotik.support.anon` | anonymous id (shared with analytics) | no |
|
|
286
|
+
| `shotik.support.session` | `{ userToken, userId, externalId }` | yes (Keychain, `kSecAttrAccessibleAfterFirstUnlock`) |
|
|
287
|
+
| `shotik.support.queue` | send queue items | no |
|
|
288
|
+
| `shotik.support.read` | `{ conversationId: readAtMs }` | no |
|
|
289
|
+
| `shotik.support.push` | `{ token, platform }` | no |
|
|
290
|
+
| `shotik.analytics.state` | `{ f: firstSeen, s: sessionId, l: lastActive, q: seq, p: sampled 0/1, u: userId }` | no |
|
|
291
|
+
| `shotik.analytics.queue` | unsent WireEvents (unpacked) | no |
|
|
292
|
+
| `shotik.analytics.consent` | `granted` / `denied` / `pending` | no |
|
|
293
|
+
|
|
294
|
+
Storage is read once, off the main thread, after `configure`; nothing is read at app launch before that.
|
|
295
|
+
Swift always has UserDefaults and never sends `store`. Flutter's file store can fail (no app-support path from the plugin, or
|
|
296
|
+
a read error), so it should send `store` too: not done yet, tracked in reports/APPC-22.md.
|
|
297
|
+
|
|
298
|
+
## 6. Widget contract (Support UI)
|
|
299
|
+
|
|
300
|
+
Every platform's widget follows the reference's design, refs and copy so a founder's users see one product.
|
|
301
|
+
|
|
302
|
+
- **Refs.** Each element, size and motion token comes from sdk/react-native/REFS.md (marked.dev refs). Native ports add
|
|
303
|
+
a REFS.md that points at those rows and logs only what differs (system components such as the iOS sheet).
|
|
304
|
+
- **Parts.** Launcher (56 pt accent circle, chat glyph, unread badge), sheet (top radius = bubble radius + 10, grabber
|
|
305
|
+
36×5), header (avatar, title 16/600, presence word, close), conversation list, thread (bubbles radius 18, 13×8 padding,
|
|
306
|
+
16/21 text, 82 % max width), receipts line, typing row, quick reply pills (34 pt), handoff strip, composer (radius 22,
|
|
307
|
+
attach, growing field up to 5 lines, 32 pt send), attachment thumbnail (56 pt), image message (200 wide, ≤ 260 tall,
|
|
308
|
+
radius 14), empty state.
|
|
309
|
+
- **Motion tokens.** Sheet spring damping 30 / stiffness 320 / mass 1; backdrop 260 ms in, 200 ms out; new bubble
|
|
310
|
+
170 ms cubic-bezier(0.25, 0.1, 0.25, 1), y 4 → 0; chips 200 ms, 40 ms stagger, y 6 → 0; typing dots 900 ms loop,
|
|
311
|
+
150 ms apart, opacity 0.3 → 1. Reduce Motion: fades only, static dots.
|
|
312
|
+
- **Palette.** light `bg #FFFFFF raised #F2F2F4 line rgba(0,0,0,.08) text #0B0B0C sub #6B6B73 faint #A3A3AB danger #E5484D
|
|
313
|
+
ok #30A46C warn #E38A1B`; dark `bg #161617 raised #252527 line rgba(255,255,255,.09) text #F4F4F5 sub #9B9BA3 faint
|
|
314
|
+
#6B6B73 danger #FF6369 ok #3DD68C warn #FFB224`. Accent default system blue (#007AFF / #0A84FF). Brand theme: `accent`,
|
|
315
|
+
`onAccent`, `radius`, `font`, `fontBold`, `scheme`, per-scheme color overrides.
|
|
316
|
+
- **Copy.** The en/ru catalog in sdk/react-native/src/theme.ts, key for key (`title`, `greeting`, `online`, …, `unreadN`),
|
|
317
|
+
picked from the device locale or a `locale` option. `{n}` and `{who}` are placeholders. Sentence case, no all caps.
|
|
318
|
+
- **Accessibility.** Every control has a label in the selected language; the typing row is one element; text scales with
|
|
319
|
+
the system setting (Dynamic Type / text scale) up to 2×; touch targets ≥ 44 pt; contrast follows the palette above.
|
|
320
|
+
- **Deep link.** `<scheme>://support` opens the sheet over the current screen.
|
|
321
|
+
|
|
322
|
+
## 7. Privacy
|
|
323
|
+
|
|
324
|
+
- No IDFA, no fingerprinting, no contacts or location. Device context is the fields listed above and nothing else.
|
|
325
|
+
- Inputs never send their value: taps on inputs carry `input: 1` and no label; wireframes draw them as `n` boxes.
|
|
326
|
+
- Masked subtrees send no label, and wireframes draw them as one `m` box.
|
|
327
|
+
- `custom` and `identify` props are the developer's responsibility; the docs say "no PII" for custom props.
|
|
328
|
+
- The app key is public; the user token is per-user and kept in the secure store.
|
|
329
|
+
- Apple privacy manifest (`PrivacyInfo.xcprivacy`) ships with the Swift and Flutter iOS packages: UserDefaults access
|
|
330
|
+
(CA92.1), `NSPrivacyTracking` false, no tracking domains, and these collected data types (none used for tracking):
|
|
331
|
+
|
|
332
|
+
| Data type | Linked to the user | Purpose |
|
|
333
|
+
|---|---|---|
|
|
334
|
+
| Product Interaction | no | Analytics |
|
|
335
|
+
| Crash Data | no | Analytics |
|
|
336
|
+
| Performance Data | no | Analytics |
|
|
337
|
+
| Purchase History | yes | Analytics |
|
|
338
|
+
| Device ID (the install's anonymous id) | yes | Analytics |
|
|
339
|
+
| Customer Support | yes | App Functionality |
|
|
340
|
+
| User ID | yes | App Functionality |
|
|
341
|
+
|
|
342
|
+
## 8. Performance budgets
|
|
343
|
+
|
|
344
|
+
| Budget | Target | How it is measured |
|
|
345
|
+
|---|---|---|
|
|
346
|
+
| `configure` on the main thread | < 5 ms cold (< 1 ms typical) | signpost / Stopwatch around configure in the sample app, release build, 20 launches, p95 |
|
|
347
|
+
| Main-thread I/O | none | storage, network, JSON and wireframe encoding on a background queue/isolate; checked with a main-thread I/O assertion in debug |
|
|
348
|
+
| Tap handler on main | < 0.1 ms p95 | measured over 1000 synthetic taps |
|
|
349
|
+
| Network | ≤ 1 analytics request per 10 s while active, 1 on background; support: 1 socket in the foreground, 0 in the background | counted in tests with a fake transport |
|
|
350
|
+
| Memory | < 2 MB resident added with both modules idle, widget closed | sample app with and without the SDK, same build |
|
|
351
|
+
| CPU idle | 0 timers firing while the app is backgrounded; one 10 s flush timer and one 500 ms watchdog in the foreground | Instruments Time Profiler / DevTools |
|
|
352
|
+
| Binary size | Swift: < 400 KiB added for Core + Analytics, < 900 KiB with SupportUI (arm64, release, stripped); Flutter: < 150 KB of Dart AOT | size report of the sample app with and without the SDK |
|
|
353
|
+
| Widget | opens in < 100 ms, 60 fps scrolling with 500 messages | sample app, release build |
|
|
354
|
+
|
|
355
|
+
Units: KiB = 1024 bytes. Binary size is the SDK's section bytes (`size -m`, so `__TEXT`, `__DATA` and the rest without the
|
|
356
|
+
16 KiB segment padding) in the sample app's stripped arm64 Release executable, minus the same sample built without the
|
|
357
|
+
SDK. A stripped-file delta is also reported, but it moves in 16 KiB page steps when the app's own code changes, so
|
|
358
|
+
budgets are judged on section bytes.
|
|
359
|
+
|
|
360
|
+
"Loading nothing": modules are separate (Core, Support, SupportUI, Analytics) so an app links only what it uses; the
|
|
361
|
+
widget's views are created on first `open()`; no fonts, images, or third-party packages are bundled.
|
|
362
|
+
|
|
363
|
+
## 9. Conformance tests
|
|
364
|
+
|
|
365
|
+
Each SDK runs the same cases against a fake transport and, where a server can run, against the real server
|
|
366
|
+
(server/test/support.test.ts is the reference):
|
|
367
|
+
|
|
368
|
+
1. `pack` of the example batch in 4.3 equals the JSON above byte for byte (tap props are built in the order el, x, y, nx, ny, id, label, dead, input, as core.ts does; the example has no id).
|
|
369
|
+
2. `unpack(pack(b))` returns b.
|
|
370
|
+
3. Session timeout after 30 min starts a new session with seq 1; `first: 1` only on the first session of an install.
|
|
371
|
+
4. Three taps within 800 ms and 40 pt emit one `rage`.
|
|
372
|
+
5. Queue: 2001 events keep the newest 2000; a 500 retries with backoff; a 400 drops the batch; 300 queued flush at once.
|
|
373
|
+
6. Consent `pending` holds, `granted` sends, `denied` clears.
|
|
374
|
+
7. Support identify → send while offline → reconnect → the optimistic message is replaced (localId), not duplicated.
|
|
375
|
+
8. Local conversation id is remapped to the server id for queued follow-ups.
|
|
376
|
+
9. Receipts: sending, queued, failed, sent, delivered, seen from the rules in 3.5. Network errors, 5xx and 429 on a
|
|
377
|
+
send keep the message `waiting` (receipt `queued`) through any number of attempts; a 400 fails it at once.
|
|
378
|
+
10. Stream: `ready` → live; `typing` ttl clears; close 4003 re-identifies; other closes back off with jitter.
|
|
379
|
+
11. Unread counts per conversation and in total; reading the open thread clears them.
|
|
380
|
+
12. Reset gives a new anonymous id and clears the session, queue and read marks.
|
|
381
|
+
|
|
382
|
+
## 10. Versioning
|
|
383
|
+
|
|
384
|
+
The packed batch carries `v: 1`. New event types are appended to the type list; new props and new frames must be ignored
|
|
385
|
+
by older clients and servers. A breaking change bumps `v` and the route (`/analytics/v2/…`). SDK versions follow semver
|
|
386
|
+
and send nothing about themselves except through the device context.
|