command-cmd 1.0.1 → 1.0.4

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