@web-auto/camo 0.1.2 → 0.1.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.
- package/README.md +137 -0
- package/package.json +7 -3
- package/scripts/check-file-size.mjs +80 -0
- package/scripts/file-size-policy.json +8 -0
- package/src/autoscript/action-providers/index.mjs +9 -0
- package/src/autoscript/action-providers/xhs/comments.mjs +412 -0
- package/src/autoscript/action-providers/xhs/common.mjs +77 -0
- package/src/autoscript/action-providers/xhs/detail.mjs +181 -0
- package/src/autoscript/action-providers/xhs/interaction.mjs +466 -0
- package/src/autoscript/action-providers/xhs/like-rules.mjs +57 -0
- package/src/autoscript/action-providers/xhs/persistence.mjs +167 -0
- package/src/autoscript/action-providers/xhs/search.mjs +174 -0
- package/src/autoscript/action-providers/xhs.mjs +133 -0
- package/src/autoscript/impact-engine.mjs +78 -0
- package/src/autoscript/runtime.mjs +1015 -0
- package/src/autoscript/schema.mjs +370 -0
- package/src/autoscript/xhs-unified-template.mjs +931 -0
- package/src/cli.mjs +190 -78
- package/src/commands/autoscript.mjs +1100 -0
- package/src/commands/browser.mjs +20 -4
- package/src/commands/container.mjs +401 -0
- package/src/commands/events.mjs +152 -0
- package/src/commands/lifecycle.mjs +17 -3
- package/src/commands/window.mjs +32 -1
- package/src/container/change-notifier.mjs +311 -0
- package/src/container/element-filter.mjs +143 -0
- package/src/container/index.mjs +3 -0
- package/src/container/runtime-core/checkpoint.mjs +195 -0
- package/src/container/runtime-core/index.mjs +21 -0
- package/src/container/runtime-core/operations/index.mjs +351 -0
- package/src/container/runtime-core/operations/selector-scripts.mjs +68 -0
- package/src/container/runtime-core/operations/tab-pool.mjs +544 -0
- package/src/container/runtime-core/operations/viewport.mjs +143 -0
- package/src/container/runtime-core/subscription.mjs +87 -0
- package/src/container/runtime-core/utils.mjs +94 -0
- package/src/container/runtime-core/validation.mjs +127 -0
- package/src/container/runtime-core.mjs +1 -0
- package/src/container/subscription-registry.mjs +459 -0
- package/src/core/actions.mjs +573 -0
- package/src/core/browser.mjs +270 -0
- package/src/core/index.mjs +53 -0
- package/src/core/utils.mjs +87 -0
- package/src/events/daemon-entry.mjs +33 -0
- package/src/events/daemon.mjs +80 -0
- package/src/events/progress-log.mjs +109 -0
- package/src/events/ws-server.mjs +239 -0
- package/src/lib/client.mjs +200 -0
- package/src/lifecycle/session-registry.mjs +8 -4
- package/src/lifecycle/session-watchdog.mjs +220 -0
- package/src/utils/browser-service.mjs +232 -9
- package/src/utils/help.mjs +28 -0
package/src/cli.mjs
CHANGED
|
@@ -11,6 +11,9 @@ import { handleCookiesCommand } from './commands/cookies.mjs';
|
|
|
11
11
|
import { handleWindowCommand } from './commands/window.mjs';
|
|
12
12
|
import { handleMouseCommand } from './commands/mouse.mjs';
|
|
13
13
|
import { handleSystemCommand } from './commands/system.mjs';
|
|
14
|
+
import { handleContainerCommand } from './commands/container.mjs';
|
|
15
|
+
import { handleAutoscriptCommand } from './commands/autoscript.mjs';
|
|
16
|
+
import { handleEventsCommand } from './commands/events.mjs';
|
|
14
17
|
import {
|
|
15
18
|
handleStartCommand, handleStopCommand, handleStatusCommand,
|
|
16
19
|
handleGotoCommand, handleBackCommand, handleScreenshotCommand,
|
|
@@ -23,10 +26,88 @@ import {
|
|
|
23
26
|
handleCleanupCommand, handleForceStopCommand, handleLockCommand,
|
|
24
27
|
handleUnlockCommand, handleSessionsCommand
|
|
25
28
|
} from './commands/lifecycle.mjs';
|
|
29
|
+
import { handleSessionWatchdogCommand } from './lifecycle/session-watchdog.mjs';
|
|
30
|
+
import { safeAppendProgressEvent } from './events/progress-log.mjs';
|
|
31
|
+
import { ensureProgressEventDaemon } from './events/daemon.mjs';
|
|
26
32
|
|
|
27
33
|
const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
28
34
|
const START_SCRIPT_REL = path.join('runtime', 'infra', 'utils', 'scripts', 'service', 'start-browser-service.mjs');
|
|
29
35
|
|
|
36
|
+
function readFlagValue(args, names) {
|
|
37
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
38
|
+
if (!names.includes(args[i])) continue;
|
|
39
|
+
const value = args[i + 1];
|
|
40
|
+
if (!value || String(value).startsWith('-')) return null;
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function inferProfileId(cmd, args) {
|
|
47
|
+
const explicitProfile = readFlagValue(args, ['--profile', '-p']);
|
|
48
|
+
if (explicitProfile) return explicitProfile;
|
|
49
|
+
const positionals = args.slice(1).filter((item) => item && !String(item).startsWith('-'));
|
|
50
|
+
if (positionals.length === 0) return null;
|
|
51
|
+
|
|
52
|
+
if ([
|
|
53
|
+
'start', 'stop', 'status', 'list', 'goto', 'navigate', 'back', 'screenshot',
|
|
54
|
+
'scroll', 'click', 'type', 'highlight', 'clear-highlight', 'viewport',
|
|
55
|
+
'new-page', 'close-page', 'switch-page', 'list-pages',
|
|
56
|
+
'cleanup', 'force-stop', 'lock', 'unlock', 'sessions',
|
|
57
|
+
].includes(cmd)) {
|
|
58
|
+
return positionals[0] || null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (cmd === 'autoscript' && positionals[0] === 'run') {
|
|
62
|
+
return explicitProfile || null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (cmd === 'container' && ['watch', 'filter', 'list', 'targets', 'register'].includes(positionals[0])) {
|
|
66
|
+
return positionals[1] || null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function runTrackedCommand(cmd, args, fn) {
|
|
73
|
+
const startedAt = Date.now();
|
|
74
|
+
const profileId = inferProfileId(cmd, args);
|
|
75
|
+
safeAppendProgressEvent({
|
|
76
|
+
source: 'cli.command',
|
|
77
|
+
mode: cmd === 'autoscript' ? 'autoscript' : 'normal',
|
|
78
|
+
profileId,
|
|
79
|
+
event: 'cli.command_start',
|
|
80
|
+
payload: { cmd, args: args.slice(1), startedAt },
|
|
81
|
+
});
|
|
82
|
+
try {
|
|
83
|
+
const result = await fn();
|
|
84
|
+
safeAppendProgressEvent({
|
|
85
|
+
source: 'cli.command',
|
|
86
|
+
mode: cmd === 'autoscript' ? 'autoscript' : 'normal',
|
|
87
|
+
profileId,
|
|
88
|
+
event: 'cli.command_done',
|
|
89
|
+
payload: { cmd, args: args.slice(1), startedAt, endedAt: Date.now(), durationMs: Date.now() - startedAt },
|
|
90
|
+
});
|
|
91
|
+
return result;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
safeAppendProgressEvent({
|
|
94
|
+
source: 'cli.command',
|
|
95
|
+
mode: cmd === 'autoscript' ? 'autoscript' : 'normal',
|
|
96
|
+
profileId,
|
|
97
|
+
event: 'cli.command_error',
|
|
98
|
+
payload: {
|
|
99
|
+
cmd,
|
|
100
|
+
args: args.slice(1),
|
|
101
|
+
startedAt,
|
|
102
|
+
endedAt: Date.now(),
|
|
103
|
+
durationMs: Date.now() - startedAt,
|
|
104
|
+
error: err?.message || String(err),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
30
111
|
async function handleConfigCommand(args) {
|
|
31
112
|
const sub = args[1];
|
|
32
113
|
if (sub !== 'repo-root') {
|
|
@@ -59,6 +140,20 @@ async function main() {
|
|
|
59
140
|
return;
|
|
60
141
|
}
|
|
61
142
|
|
|
143
|
+
if (cmd === '__session-watchdog') {
|
|
144
|
+
await handleSessionWatchdogCommand(args);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const skipProgressAutoStart = new Set(['help', '--help', '-h', 'profiles', 'events', '__session-watchdog']);
|
|
149
|
+
if (!skipProgressAutoStart.has(cmd)) {
|
|
150
|
+
try {
|
|
151
|
+
await ensureProgressEventDaemon();
|
|
152
|
+
} catch {
|
|
153
|
+
// Progress daemon auto-start is best-effort and must not block command execution.
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
62
157
|
if (cmd === 'profiles') {
|
|
63
158
|
const profiles = listProfiles();
|
|
64
159
|
const defaultProfile = getDefaultProfile();
|
|
@@ -67,48 +162,63 @@ async function main() {
|
|
|
67
162
|
}
|
|
68
163
|
|
|
69
164
|
if (cmd === 'profile') {
|
|
70
|
-
await handleProfileCommand(args);
|
|
165
|
+
await runTrackedCommand(cmd, args, () => handleProfileCommand(args));
|
|
71
166
|
return;
|
|
72
167
|
}
|
|
73
168
|
|
|
74
169
|
if (cmd === 'config') {
|
|
75
|
-
await handleConfigCommand(args);
|
|
170
|
+
await runTrackedCommand(cmd, args, () => handleConfigCommand(args));
|
|
76
171
|
return;
|
|
77
172
|
}
|
|
78
173
|
|
|
79
174
|
if (cmd === 'init') {
|
|
80
|
-
await handleInitCommand(args);
|
|
175
|
+
await runTrackedCommand(cmd, args, () => handleInitCommand(args));
|
|
81
176
|
return;
|
|
82
177
|
}
|
|
83
178
|
|
|
84
179
|
if (cmd === 'create') {
|
|
85
|
-
await handleCreateCommand(args);
|
|
180
|
+
await runTrackedCommand(cmd, args, () => handleCreateCommand(args));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (cmd === 'events') {
|
|
185
|
+
await runTrackedCommand(cmd, args, () => handleEventsCommand(args));
|
|
86
186
|
return;
|
|
87
187
|
}
|
|
88
188
|
|
|
89
189
|
// Lifecycle commands
|
|
90
190
|
if (cmd === 'cleanup') {
|
|
91
|
-
await handleCleanupCommand(args);
|
|
191
|
+
await runTrackedCommand(cmd, args, () => handleCleanupCommand(args));
|
|
92
192
|
return;
|
|
93
193
|
}
|
|
94
194
|
|
|
95
195
|
if (cmd === 'force-stop') {
|
|
96
|
-
await handleForceStopCommand(args);
|
|
196
|
+
await runTrackedCommand(cmd, args, () => handleForceStopCommand(args));
|
|
97
197
|
return;
|
|
98
198
|
}
|
|
99
199
|
|
|
100
200
|
if (cmd === 'lock') {
|
|
101
|
-
await handleLockCommand(args);
|
|
201
|
+
await runTrackedCommand(cmd, args, () => handleLockCommand(args));
|
|
102
202
|
return;
|
|
103
203
|
}
|
|
104
204
|
|
|
105
205
|
if (cmd === 'unlock') {
|
|
106
|
-
await handleUnlockCommand(args);
|
|
206
|
+
await runTrackedCommand(cmd, args, () => handleUnlockCommand(args));
|
|
107
207
|
return;
|
|
108
208
|
}
|
|
109
209
|
|
|
110
210
|
if (cmd === 'sessions') {
|
|
111
|
-
await handleSessionsCommand(args);
|
|
211
|
+
await runTrackedCommand(cmd, args, () => handleSessionsCommand(args));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (cmd === 'container') {
|
|
216
|
+
await runTrackedCommand(cmd, args, () => handleContainerCommand(args));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (cmd === 'autoscript') {
|
|
221
|
+
await runTrackedCommand(cmd, args, () => handleAutoscriptCommand(args));
|
|
112
222
|
return;
|
|
113
223
|
}
|
|
114
224
|
|
|
@@ -116,81 +226,83 @@ async function main() {
|
|
|
116
226
|
'start', 'stop', 'close', 'status', 'list', 'goto', 'navigate', 'back', 'screenshot',
|
|
117
227
|
'new-page', 'close-page', 'switch-page', 'list-pages', 'shutdown',
|
|
118
228
|
'scroll', 'click', 'type', 'highlight', 'clear-highlight', 'viewport',
|
|
119
|
-
'cookies', 'window', 'mouse', 'system',
|
|
229
|
+
'cookies', 'window', 'mouse', 'system', 'container', 'autoscript', 'events',
|
|
120
230
|
]);
|
|
121
231
|
|
|
122
232
|
if (!serviceCommands.has(cmd)) {
|
|
123
233
|
throw new Error(`Unknown command: ${cmd}`);
|
|
124
234
|
}
|
|
125
235
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
await runTrackedCommand(cmd, args, async () => {
|
|
237
|
+
switch (cmd) {
|
|
238
|
+
case 'start':
|
|
239
|
+
await handleStartCommand(args);
|
|
240
|
+
break;
|
|
241
|
+
case 'stop':
|
|
242
|
+
case 'close':
|
|
243
|
+
await handleStopCommand(args);
|
|
244
|
+
break;
|
|
245
|
+
case 'status':
|
|
246
|
+
case 'list':
|
|
247
|
+
await handleStatusCommand(args);
|
|
248
|
+
break;
|
|
249
|
+
case 'goto':
|
|
250
|
+
case 'navigate':
|
|
251
|
+
await handleGotoCommand(args);
|
|
252
|
+
break;
|
|
253
|
+
case 'back':
|
|
254
|
+
await handleBackCommand(args);
|
|
255
|
+
break;
|
|
256
|
+
case 'screenshot':
|
|
257
|
+
await handleScreenshotCommand(args);
|
|
258
|
+
break;
|
|
259
|
+
case 'scroll':
|
|
260
|
+
await handleScrollCommand(args);
|
|
261
|
+
break;
|
|
262
|
+
case 'click':
|
|
263
|
+
await handleClickCommand(args);
|
|
264
|
+
break;
|
|
265
|
+
case 'type':
|
|
266
|
+
await handleTypeCommand(args);
|
|
267
|
+
break;
|
|
268
|
+
case 'highlight':
|
|
269
|
+
await handleHighlightCommand(args);
|
|
270
|
+
break;
|
|
271
|
+
case 'clear-highlight':
|
|
272
|
+
await handleClearHighlightCommand(args);
|
|
273
|
+
break;
|
|
274
|
+
case 'viewport':
|
|
275
|
+
await handleViewportCommand(args);
|
|
276
|
+
break;
|
|
277
|
+
case 'new-page':
|
|
278
|
+
await handleNewPageCommand(args);
|
|
279
|
+
break;
|
|
280
|
+
case 'close-page':
|
|
281
|
+
await handleClosePageCommand(args);
|
|
282
|
+
break;
|
|
283
|
+
case 'switch-page':
|
|
284
|
+
await handleSwitchPageCommand(args);
|
|
285
|
+
break;
|
|
286
|
+
case 'list-pages':
|
|
287
|
+
await handleListPagesCommand(args);
|
|
288
|
+
break;
|
|
289
|
+
case 'shutdown':
|
|
290
|
+
await handleShutdownCommand();
|
|
291
|
+
break;
|
|
292
|
+
case 'cookies':
|
|
293
|
+
await handleCookiesCommand(args);
|
|
294
|
+
break;
|
|
295
|
+
case 'window':
|
|
296
|
+
await handleWindowCommand(args);
|
|
297
|
+
break;
|
|
298
|
+
case 'mouse':
|
|
299
|
+
await handleMouseCommand(args);
|
|
300
|
+
break;
|
|
301
|
+
case 'system':
|
|
302
|
+
await handleSystemCommand(args);
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
194
306
|
}
|
|
195
307
|
|
|
196
308
|
main().catch((err) => {
|