command-cmd 1.0.2 → 1.0.5

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.
Files changed (6) hide show
  1. package/cmd.js +2165 -16
  2. package/doc.md +292 -152
  3. package/docPTBR.md +299 -152
  4. package/map.md +244 -0
  5. package/mapPTBR.md +244 -0
  6. package/package.json +5 -2
package/map.md ADDED
@@ -0,0 +1,244 @@
1
+ # map.json (Mapper Guide - English)
2
+
3
+ This guide explains how to create `map.json` so the library knows:
4
+
5
+ - where to click to open each app;
6
+ - where app-specific buttons are;
7
+ - current app state (`open` / `closed` or `aberto` / `fechado`).
8
+
9
+ Note: `move_sequence` does not depend on `map.json`; it uses coordinates from the command payload.
10
+
11
+ ## File location
12
+
13
+ Create `map.json` in your project root (where Node runs).
14
+
15
+ By default, the library auto-creates this file if it does not exist.
16
+
17
+ You can also create it explicitly:
18
+
19
+ ```js
20
+ await initMap();
21
+ ```
22
+
23
+ If you need another path:
24
+
25
+ ```js
26
+ await cursor(commands, { mapPath: './config/map.json' });
27
+ ```
28
+
29
+ ## Minimal structure
30
+
31
+ ```json
32
+ {
33
+ "version": 1,
34
+ "apps": {
35
+ "youtube": {
36
+ "state": "closed",
37
+ "launcher": { "x": 20, "y": 225 },
38
+ "buttons": {}
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ Even with minimal setup, the generated default map includes:
45
+
46
+ - `state`;
47
+ - `buttons`;
48
+ - a default `close/fechar` button per app (`setState: "fechado"`).
49
+
50
+ ## Recommended structure (with buttons)
51
+
52
+ ```json
53
+ {
54
+ "version": 1,
55
+ "apps": {
56
+ "tiktok": {
57
+ "state": "closed",
58
+ "launcher": {
59
+ "position": { "x": 28, "y": 260 },
60
+ "path": {
61
+ "points": ["60x740", "140x740", "220x740", "28x260"],
62
+ "click": "between",
63
+ "interval": 180,
64
+ "clickDelay": 120
65
+ }
66
+ },
67
+ "searchIcon": { "x": 612, "y": 138 },
68
+ "buttons": {
69
+ "search_bar": { "x": 612, "y": 138 }
70
+ }
71
+ },
72
+ "youtube": {
73
+ "state": "open",
74
+ "launcher": { "x": 20, "y": 225 },
75
+ "searchIcon": { "x": 575, "y": 144 },
76
+ "buttons": {
77
+ "skip_ads": { "x": 808, "y": 569 },
78
+ "close": {
79
+ "position": { "x": 1888, "y": 16 },
80
+ "setState": "closed"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## App fields
89
+
90
+ - `state`: `open`, `closed`, `aberto`, or `fechado`
91
+ - `launcher`: click point used to open/focus app
92
+ - `searchIcon`: search icon point (optional)
93
+ - `buttons`: per-app button map
94
+ - optional `path/caminho` inside `launcher`: movement route before final click
95
+
96
+ ## Button fields
97
+
98
+ Simple format:
99
+
100
+ ```json
101
+ "skip_ads": { "x": 808, "y": 569 }
102
+ ```
103
+
104
+ Full format:
105
+
106
+ ```json
107
+ "close": {
108
+ "position": { "x": 1888, "y": 16 },
109
+ "setState": "closed"
110
+ }
111
+ ```
112
+
113
+ With path:
114
+
115
+ ```json
116
+ "search_bar": {
117
+ "position": { "x": 612, "y": 138 },
118
+ "path": {
119
+ "points": ["500x140", "560x140", "612x138"],
120
+ "click": "between",
121
+ "interval": 150,
122
+ "clickDelay": 100,
123
+ "doubleClick": false
124
+ }
125
+ }
126
+ ```
127
+
128
+ When `setState` is present, the library updates app state in `map.json` after click.
129
+
130
+ ## App and button names
131
+
132
+ You can name buttons freely in `map.json`.
133
+
134
+ Same for app names inside `apps`.
135
+
136
+ Example:
137
+
138
+ ```json
139
+ "buttons": {
140
+ "my_custom_button": { "x": 500, "y": 300 }
141
+ }
142
+ ```
143
+
144
+ Then call it using:
145
+
146
+ ```txt
147
+ [open_app, command: tiktok, button: my_custom_button]
148
+ ```
149
+
150
+ Lookup uses normalization (case-insensitive, spaces/hyphens to `_`, accent-insensitive).
151
+
152
+ ## Optional `path/caminho` field
153
+
154
+ You can use `path/caminho` in:
155
+
156
+ - `apps.<name>.launcher`
157
+ - `apps.<name>.searchIcon`
158
+ - `apps.<name>.buttons.<buttonName>`
159
+
160
+ Format:
161
+
162
+ ```json
163
+ "path": {
164
+ "points": ["100x200", "300x260", "640x420"],
165
+ "click": "between",
166
+ "interval": 200,
167
+ "clickDelay": 120,
168
+ "doubleClick": false
169
+ }
170
+ ```
171
+
172
+ Fields:
173
+
174
+ - `points`: coordinate sequence
175
+ - `click`: `none`, `between`, `each`, `first`, `last`
176
+ - `interval`: delay between points (ms)
177
+ - `clickDelay`: delay between arriving and clicking at that point (ms)
178
+ - `doubleClick`: whether path clicks are double clicks
179
+
180
+ Note:
181
+
182
+ - after the path, the library still performs the final click on `position`.
183
+
184
+ ## How app state is used
185
+
186
+ Command:
187
+
188
+ ```txt
189
+ [open_app, command: youtube, button: skipADS]
190
+ ```
191
+
192
+ Flow:
193
+
194
+ 1. Reads `apps.youtube.state`.
195
+ 2. If already open, it does not open again.
196
+ 3. Resolves `buttons.skip_ads` and clicks.
197
+ 4. If that button has `setState`, it writes the new state to file.
198
+
199
+ ## AI command examples
200
+
201
+ ```txt
202
+ [open_app, command: tiktok, button: search_bar]
203
+ [open_app, command: youtube, button: skipADS]
204
+ [close_app, command: youtube, button: close]
205
+ ```
206
+
207
+ ## Accepted aliases
208
+
209
+ App:
210
+
211
+ - `google` -> `chrome`
212
+
213
+ Button:
214
+
215
+ - `skipADS` -> `skip_ads`
216
+ - `search`, `search_bar`, `barra_pesquisa` -> same logical key
217
+ - `close`, `fechar` -> `close`/`fechar` mapping
218
+
219
+ ## Quick coordinate calibration
220
+
221
+ Use this script to read current mouse coordinates:
222
+
223
+ ```js
224
+ import robot from 'robotjs';
225
+
226
+ setInterval(() => {
227
+ const p = robot.getMousePos();
228
+ console.log(`x=${p.x}, y=${p.y}`);
229
+ }, 300);
230
+ ```
231
+
232
+ Move mouse over launcher/buttons and copy values into `map.json`.
233
+
234
+ ## Common errors
235
+
236
+ - `unknown_app:<name>`: app not found in `map.json`
237
+ - `unknown_button:<app>:<button>`: missing button under `apps.<app>.buttons`
238
+ - `missing_launcher:<app>`: app has no `launcher`
239
+ - `map_not_found:<path>`: map file not found
240
+
241
+ ## Maintenance tip
242
+
243
+ Keep stable button keys (`search_bar`, `skip_ads`, `close`).
244
+ If UI changes, update only `map.json`, not your code.
package/mapPTBR.md ADDED
@@ -0,0 +1,244 @@
1
+ # map.json (Guia do Mapeador PT-BR)
2
+
3
+ Este arquivo explica como criar o `map.json` para a lib saber:
4
+
5
+ - onde clicar para abrir cada app;
6
+ - onde ficam botoes internos de cada app;
7
+ - qual o estado atual do app (`aberto` ou `fechado`).
8
+
9
+ Obs.: o comando `mover_sequencia` nao depende do `map.json`. Ele usa coordenadas enviadas no proprio comando.
10
+
11
+ ## Onde criar o arquivo
12
+
13
+ Crie `map.json` na raiz do seu projeto (mesma pasta onde voce roda o Node).
14
+
15
+ Por padrao, a lib cria esse arquivo automaticamente se ele nao existir.
16
+
17
+ Tambem da para criar explicitamente:
18
+
19
+ ```js
20
+ await initMap();
21
+ ```
22
+
23
+ Se quiser outro caminho, passe em `cursor`:
24
+
25
+ ```js
26
+ await cursor(comandos, { mapPath: './config/map.json' });
27
+ ```
28
+
29
+ ## Estrutura minima
30
+
31
+ ```json
32
+ {
33
+ "version": 1,
34
+ "apps": {
35
+ "youtube": {
36
+ "state": "fechado",
37
+ "launcher": { "x": 20, "y": 225 },
38
+ "buttons": {}
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ Mesmo no arquivo minimo, o gerador padrao sempre inclui:
45
+
46
+ - `state`;
47
+ - `buttons`;
48
+ - botao `fechar` por app (com `setState: "fechado"`).
49
+
50
+ ## Estrutura recomendada (com botoes)
51
+
52
+ ```json
53
+ {
54
+ "version": 1,
55
+ "apps": {
56
+ "tiktok": {
57
+ "state": "fechado",
58
+ "launcher": {
59
+ "position": { "x": 28, "y": 260 },
60
+ "caminho": {
61
+ "points": ["60x740", "140x740", "220x740", "28x260"],
62
+ "click": "between",
63
+ "interval": 180,
64
+ "clickDelay": 120
65
+ }
66
+ },
67
+ "searchIcon": { "x": 612, "y": 138 },
68
+ "buttons": {
69
+ "barra_pesquisa": { "x": 612, "y": 138 }
70
+ }
71
+ },
72
+ "youtube": {
73
+ "state": "aberto",
74
+ "launcher": { "x": 20, "y": 225 },
75
+ "searchIcon": { "x": 575, "y": 144 },
76
+ "buttons": {
77
+ "pular_ads": { "x": 808, "y": 569 },
78
+ "fechar": {
79
+ "position": { "x": 1888, "y": 16 },
80
+ "setState": "fechado"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## Campos do app
89
+
90
+ - `state`: `aberto` ou `fechado`
91
+ - `launcher`: ponto para clicar e abrir/focar app
92
+ - `searchIcon`: ponto da lupa/barra de busca (opcional)
93
+ - `buttons`: mapa de botoes do app
94
+ - `caminho` dentro de `launcher` (opcional): rota de pontos antes do clique final no app
95
+
96
+ ## Campos de botao
97
+
98
+ Formato simples:
99
+
100
+ ```json
101
+ "pular_ads": { "x": 808, "y": 569 }
102
+ ```
103
+
104
+ Formato completo:
105
+
106
+ ```json
107
+ "fechar": {
108
+ "position": { "x": 1888, "y": 16 },
109
+ "setState": "fechado"
110
+ }
111
+ ```
112
+
113
+ Com caminho:
114
+
115
+ ```json
116
+ "barra_pesquisa": {
117
+ "position": { "x": 612, "y": 138 },
118
+ "caminho": {
119
+ "points": ["500x140", "560x140", "612x138"],
120
+ "click": "between",
121
+ "interval": 150,
122
+ "clickDelay": 100,
123
+ "doubleClick": false
124
+ }
125
+ }
126
+ ```
127
+
128
+ Quando `setState` existe, a lib atualiza o estado do app apos clicar no botao.
129
+
130
+ ## Nome de apps e botoes
131
+
132
+ Voce pode definir o nome como quiser no `map.json`.
133
+
134
+ O mesmo vale para nome de app dentro de `apps`.
135
+
136
+ Exemplo:
137
+
138
+ ```json
139
+ "buttons": {
140
+ "meu_botao_custom": { "x": 500, "y": 300 }
141
+ }
142
+ ```
143
+
144
+ Depois, a IA ou seu codigo pode chamar:
145
+
146
+ ```txt
147
+ [abrir_app, comando: tiktok, botao: meu_botao_custom]
148
+ ```
149
+
150
+ A busca aplica normalizacao (case-insensitive, troca espaco/hifen por `_`, remove acento).
151
+
152
+ ## Campo `caminho` (opcional)
153
+
154
+ `caminho` pode ser usado em:
155
+
156
+ - `apps.<nome>.launcher`
157
+ - `apps.<nome>.searchIcon`
158
+ - `apps.<nome>.buttons.<nomeBotao>`
159
+
160
+ Formato:
161
+
162
+ ```json
163
+ "caminho": {
164
+ "points": ["100x200", "300x260", "640x420"],
165
+ "click": "between",
166
+ "interval": 200,
167
+ "clickDelay": 120,
168
+ "doubleClick": false
169
+ }
170
+ ```
171
+
172
+ Campos:
173
+
174
+ - `points`: sequencia de coordenadas
175
+ - `click`: `none`, `between`, `each`, `first`, `last`
176
+ - `interval`: delay entre pontos (ms)
177
+ - `clickDelay`: delay entre chegada no ponto e clique (ms)
178
+ - `doubleClick`: se o clique do caminho e duplo
179
+
180
+ Observacao:
181
+
182
+ - ao final do caminho, a lib ainda executa o clique final no destino (`position`).
183
+
184
+ ## Como a lib usa o estado
185
+
186
+ No comando:
187
+
188
+ ```txt
189
+ [abrir_app, comando: youtube, botao: pularADS]
190
+ ```
191
+
192
+ Fluxo:
193
+
194
+ 1. Le `apps.youtube.state`.
195
+ 2. Se estiver `aberto`, nao tenta abrir novamente.
196
+ 3. Busca `buttons.pular_ads` no mapeador e clica.
197
+ 4. Se esse botao tiver `setState`, atualiza o estado no arquivo.
198
+
199
+ ## Exemplo de comandos da IA
200
+
201
+ ```txt
202
+ [abrir_app, comando: tiktok, botao: barra_pesquisa]
203
+ [abrir_app, comando: youtube, botao: pularADS]
204
+ [fechar_app, comando: youtube, botao: fechar]
205
+ ```
206
+
207
+ ## Alias aceitos
208
+
209
+ App:
210
+
211
+ - `google` -> `chrome`
212
+
213
+ Botao:
214
+
215
+ - `pularADS` -> `pular_ads`
216
+ - `search`, `search_bar`, `barra_pesquisa` -> mesma chave logica
217
+ - `close`, `fechar` -> `fechar`
218
+
219
+ ## Calibrando coordenadas (rapido)
220
+
221
+ Use este script para ler a posicao atual do mouse:
222
+
223
+ ```js
224
+ import robot from 'robotjs';
225
+
226
+ setInterval(() => {
227
+ const p = robot.getMousePos();
228
+ console.log(`x=${p.x}, y=${p.y}`);
229
+ }, 300);
230
+ ```
231
+
232
+ Passe o mouse sobre launcher/botoes e copie os valores para o `map.json`.
233
+
234
+ ## Erros comuns
235
+
236
+ - `unknown_app:<nome>`: app nao existe em `map.json`.
237
+ - `unknown_button:<app>:<botao>`: botao nao existe em `apps.<app>.buttons`.
238
+ - `missing_launcher:<app>`: faltou `launcher`.
239
+ - `map_not_found:<caminho>`: faltou criar `map.json`.
240
+
241
+ ## Dica de manutencao
242
+
243
+ - Mantenha nomes de botoes curtos e estaveis (`barra_pesquisa`, `pular_ads`, `fechar`).
244
+ - Se a UI mudar de lugar, atualize apenas o `map.json`, sem mexer no codigo.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "command-cmd",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "main": "cmd.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -9,5 +9,8 @@
9
9
  "keywords": [],
10
10
  "author": "cmstudio",
11
11
  "license": "ISC",
12
- "description": "Extraia comandos, ótimo para usar com agentes de IA"
12
+ "description": "Extraia comandos, ótimo para usar com agentes de IA",
13
+ "dependencies": {
14
+ "robotjs": "^0.6.0"
15
+ }
13
16
  }