@web-auto/camo 0.1.2
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 +243 -0
- package/bin/camo.mjs +22 -0
- package/package.json +39 -0
- package/scripts/build.mjs +19 -0
- package/scripts/bump-version.mjs +38 -0
- package/scripts/install.mjs +76 -0
- package/scripts/release.sh +54 -0
- package/src/cli.mjs +199 -0
- package/src/commands/browser.mjs +462 -0
- package/src/commands/cookies.mjs +69 -0
- package/src/commands/create.mjs +98 -0
- package/src/commands/init.mjs +68 -0
- package/src/commands/lifecycle.mjs +256 -0
- package/src/commands/mouse.mjs +49 -0
- package/src/commands/profile.mjs +46 -0
- package/src/commands/system.mjs +14 -0
- package/src/commands/window.mjs +31 -0
- package/src/lifecycle/cleanup.mjs +83 -0
- package/src/lifecycle/lock.mjs +122 -0
- package/src/lifecycle/session-registry.mjs +163 -0
- package/src/utils/args.mjs +25 -0
- package/src/utils/browser-service.mjs +194 -0
- package/src/utils/config.mjs +90 -0
- package/src/utils/fingerprint.mjs +181 -0
- package/src/utils/help.mjs +128 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getDefaultProfile } from '../utils/config.mjs';
|
|
2
|
+
import { callAPI, ensureBrowserService } from '../utils/browser-service.mjs';
|
|
3
|
+
import { getPositionals } from '../utils/args.mjs';
|
|
4
|
+
|
|
5
|
+
export async function handleCookiesCommand(args) {
|
|
6
|
+
await ensureBrowserService();
|
|
7
|
+
|
|
8
|
+
const sub = args[1];
|
|
9
|
+
const profileId = getPositionals(args, 2)[0] || getDefaultProfile();
|
|
10
|
+
if (!profileId) throw new Error('No profile specified and no default profile set');
|
|
11
|
+
|
|
12
|
+
switch (sub) {
|
|
13
|
+
case 'get':
|
|
14
|
+
await handleGetCookies(profileId);
|
|
15
|
+
break;
|
|
16
|
+
case 'save':
|
|
17
|
+
await handleSaveCookies(profileId, args);
|
|
18
|
+
break;
|
|
19
|
+
case 'load':
|
|
20
|
+
await handleLoadCookies(profileId, args);
|
|
21
|
+
break;
|
|
22
|
+
case 'auto':
|
|
23
|
+
await handleAutoCookies(profileId, args);
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error('Usage: camo cookies <get|save|load|auto> [profileId] [--path <path>] [--interval <ms>]');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function handleGetCookies(profileId) {
|
|
31
|
+
const result = await callAPI('getCookies', { profileId });
|
|
32
|
+
console.log(JSON.stringify(result, null, 2));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function handleSaveCookies(profileId, args) {
|
|
36
|
+
const pathIdx = args.indexOf('--path');
|
|
37
|
+
if (pathIdx === -1) throw new Error('--path <file> is required for save');
|
|
38
|
+
const cookiePath = args[pathIdx + 1];
|
|
39
|
+
const result = await callAPI('saveCookies', { profileId, path: cookiePath });
|
|
40
|
+
console.log(JSON.stringify(result, null, 2));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function handleLoadCookies(profileId, args) {
|
|
44
|
+
const pathIdx = args.indexOf('--path');
|
|
45
|
+
if (pathIdx === -1) throw new Error('--path <file> is required for load');
|
|
46
|
+
const cookiePath = args[pathIdx + 1];
|
|
47
|
+
const result = await callAPI('loadCookies', { profileId, path: cookiePath });
|
|
48
|
+
console.log(JSON.stringify(result, null, 2));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function handleAutoCookies(profileId, args) {
|
|
52
|
+
const action = args[2];
|
|
53
|
+
if (!action) throw new Error('Usage: camo cookies auto <start|stop|status> [profileId] [--interval <ms>]');
|
|
54
|
+
|
|
55
|
+
if (action === 'start') {
|
|
56
|
+
const intervalIdx = args.indexOf('--interval');
|
|
57
|
+
const intervalMs = intervalIdx >= 0 ? parseInt(args[intervalIdx + 1]) : 2500;
|
|
58
|
+
const result = await callAPI('autoCookies:start', { profileId, intervalMs });
|
|
59
|
+
console.log(JSON.stringify(result, null, 2));
|
|
60
|
+
} else if (action === 'stop') {
|
|
61
|
+
const result = await callAPI('autoCookies:stop', { profileId });
|
|
62
|
+
console.log(JSON.stringify(result, null, 2));
|
|
63
|
+
} else if (action === 'status') {
|
|
64
|
+
const result = await callAPI('autoCookies:status', { profileId });
|
|
65
|
+
console.log(JSON.stringify(result, null, 2));
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error('auto subcommand must be start, stop, or status');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { CONFIG_DIR, PROFILES_DIR, ensureDir, createProfile, listProfiles } from '../utils/config.mjs';
|
|
5
|
+
import { generateFingerprint, listAvailableRegions, listAvailableOS, GEOIP_REGIONS, OS_OPTIONS } from '../utils/fingerprint.mjs';
|
|
6
|
+
|
|
7
|
+
const FINGERPRINTS_DIR = path.join(CONFIG_DIR, 'fingerprints');
|
|
8
|
+
|
|
9
|
+
export async function handleCreateCommand(args) {
|
|
10
|
+
const what = args[1];
|
|
11
|
+
|
|
12
|
+
if (what === 'fingerprint') {
|
|
13
|
+
await handleCreateFingerprint(args);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (what === 'profile') {
|
|
18
|
+
const profileId = args[2];
|
|
19
|
+
if (!profileId) throw new Error('Usage: camo create profile <profileId>');
|
|
20
|
+
createProfile(profileId);
|
|
21
|
+
console.log(`Created profile: ${profileId}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw new Error('Usage: camo create <profile|fingerprint> [options]');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function handleCreateFingerprint(args) {
|
|
29
|
+
// Parse options
|
|
30
|
+
const osIdx = args.indexOf('--os');
|
|
31
|
+
const regionIdx = args.indexOf('--region');
|
|
32
|
+
const outputIdx = args.indexOf('--output');
|
|
33
|
+
const nameIdx = args.indexOf('--name');
|
|
34
|
+
|
|
35
|
+
const osKey = osIdx >= 0 ? args[osIdx + 1] : 'mac';
|
|
36
|
+
const regionKey = regionIdx >= 0 ? args[regionIdx + 1] : 'us';
|
|
37
|
+
const output = outputIdx >= 0 ? args[outputIdx + 1] : null;
|
|
38
|
+
const name = nameIdx >= 0 ? args[nameIdx + 1] : null;
|
|
39
|
+
|
|
40
|
+
// Validate options
|
|
41
|
+
if (!OS_OPTIONS[osKey]) {
|
|
42
|
+
console.error(`Invalid OS: ${osKey}`);
|
|
43
|
+
console.error('Available:', Object.keys(OS_OPTIONS).join(', '));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!GEOIP_REGIONS[regionKey]) {
|
|
48
|
+
console.error(`Invalid region: ${regionKey}`);
|
|
49
|
+
console.error('Available:', Object.keys(GEOIP_REGIONS).join(', '));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Generate fingerprint
|
|
54
|
+
const fingerprint = generateFingerprint({ os: osKey, region: regionKey });
|
|
55
|
+
|
|
56
|
+
// Add metadata
|
|
57
|
+
fingerprint.name = name || `fingerprint-${osKey}-${regionKey}-${Date.now()}`;
|
|
58
|
+
fingerprint.createdAt = new Date().toISOString();
|
|
59
|
+
fingerprint.id = `fp_${Buffer.from(fingerprint.name).toString('base64').slice(0, 12)}`;
|
|
60
|
+
|
|
61
|
+
// Save or output
|
|
62
|
+
if (output) {
|
|
63
|
+
fs.writeFileSync(output, JSON.stringify(fingerprint, null, 2));
|
|
64
|
+
console.log(`Fingerprint saved to: ${output}`);
|
|
65
|
+
} else {
|
|
66
|
+
// Save to fingerprints directory
|
|
67
|
+
ensureDir(FINGERPRINTS_DIR);
|
|
68
|
+
const fpPath = path.join(FINGERPRINTS_DIR, `${fingerprint.id}.json`);
|
|
69
|
+
fs.writeFileSync(fpPath, JSON.stringify(fingerprint, null, 2));
|
|
70
|
+
console.log(JSON.stringify({
|
|
71
|
+
ok: true,
|
|
72
|
+
fingerprint,
|
|
73
|
+
path: fpPath,
|
|
74
|
+
}, null, 2));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function listFingerprints() {
|
|
79
|
+
if (!fs.existsSync(FINGERPRINTS_DIR)) return [];
|
|
80
|
+
return fs.readdirSync(FINGERPRINTS_DIR, { withFileTypes: true })
|
|
81
|
+
.filter((f) => f.isFile() && f.name.endsWith('.json'))
|
|
82
|
+
.map((f) => {
|
|
83
|
+
try {
|
|
84
|
+
const content = fs.readFileSync(path.join(FINGERPRINTS_DIR, f.name), 'utf8');
|
|
85
|
+
const fp = JSON.parse(content);
|
|
86
|
+
return { id: fp.id, name: fp.name, os: fp.os, country: fp.country };
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function getFingerprint(id) {
|
|
95
|
+
const fpPath = path.join(FINGERPRINTS_DIR, `${id}.json`);
|
|
96
|
+
if (!fs.existsSync(fpPath)) return null;
|
|
97
|
+
return JSON.parse(fs.readFileSync(fpPath, 'utf8'));
|
|
98
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ensureCamoufox } from '../utils/browser-service.mjs';
|
|
2
|
+
import { listProfiles, getDefaultProfile } from '../utils/config.mjs';
|
|
3
|
+
import { downloadGeoIP, hasGeoIP, listAvailableRegions, listAvailableOS } from '../utils/fingerprint.mjs';
|
|
4
|
+
|
|
5
|
+
export async function handleInitCommand(args) {
|
|
6
|
+
const subCmd = args[1];
|
|
7
|
+
|
|
8
|
+
if (subCmd === 'geoip') {
|
|
9
|
+
await handleInitGeoIP();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (subCmd === 'list') {
|
|
14
|
+
handleInitList();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Default init: ensure camoufox + browser-service
|
|
19
|
+
ensureCamoufox();
|
|
20
|
+
const { ensureBrowserService } = await import('../utils/browser-service.mjs');
|
|
21
|
+
await ensureBrowserService();
|
|
22
|
+
|
|
23
|
+
const profiles = listProfiles();
|
|
24
|
+
const defaultProfile = getDefaultProfile();
|
|
25
|
+
const geoipReady = hasGeoIP();
|
|
26
|
+
|
|
27
|
+
console.log(JSON.stringify({
|
|
28
|
+
ok: true,
|
|
29
|
+
profiles,
|
|
30
|
+
defaultProfile,
|
|
31
|
+
count: profiles.length,
|
|
32
|
+
geoip: geoipReady,
|
|
33
|
+
camoufox: true,
|
|
34
|
+
browserService: true,
|
|
35
|
+
}, null, 2));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function handleInitGeoIP() {
|
|
39
|
+
try {
|
|
40
|
+
const path = await downloadGeoIP(console.log);
|
|
41
|
+
console.log(JSON.stringify({
|
|
42
|
+
ok: true,
|
|
43
|
+
path,
|
|
44
|
+
message: 'GeoIP database ready',
|
|
45
|
+
}, null, 2));
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(`Error: ${err.message}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function handleInitList() {
|
|
53
|
+
console.log('\n=== Available OS Options ===');
|
|
54
|
+
const osList = listAvailableOS();
|
|
55
|
+
osList.forEach(item => {
|
|
56
|
+
console.log(` ${item.key.padEnd(12)} - ${item.os} ${item.osVersion} (${item.platform})`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('\n=== Available Regions ===');
|
|
60
|
+
const regions = listAvailableRegions();
|
|
61
|
+
regions.forEach(item => {
|
|
62
|
+
console.log(` ${item.key.padEnd(12)} - ${item.country}, ${item.city} (${item.timezone})`);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log('\nUsage:');
|
|
66
|
+
console.log(' camo create fingerprint --os mac --region us');
|
|
67
|
+
console.log(' camo create fingerprint --os windows --region uk');
|
|
68
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Lifecycle commands: cleanup, force-stop, lock management, session recovery
|
|
4
|
+
*/
|
|
5
|
+
import { getDefaultProfile } from '../utils/config.mjs';
|
|
6
|
+
import { callAPI, ensureBrowserService, checkBrowserService } from '../utils/browser-service.mjs';
|
|
7
|
+
import { resolveProfileId } from '../utils/args.mjs';
|
|
8
|
+
import { acquireLock, getLockInfo, releaseLock, isLocked, cleanupStaleLocks, listActiveLocks } from '../lifecycle/lock.mjs';
|
|
9
|
+
import {
|
|
10
|
+
getSessionInfo, unregisterSession, markSessionClosed, cleanupStaleSessions,
|
|
11
|
+
listRegisteredSessions, registerSession, updateSession
|
|
12
|
+
} from '../lifecycle/session-registry.mjs';
|
|
13
|
+
|
|
14
|
+
export async function handleCleanupCommand(args) {
|
|
15
|
+
const sub = args[1];
|
|
16
|
+
|
|
17
|
+
if (sub === 'locks') {
|
|
18
|
+
const cleaned = cleanupStaleLocks();
|
|
19
|
+
console.log(JSON.stringify({ ok: true, cleanedStaleLocks: cleaned }, null, 2));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (sub === 'sessions') {
|
|
24
|
+
const cleaned = cleanupStaleSessions();
|
|
25
|
+
console.log(JSON.stringify({ ok: true, cleanedStaleSessions: cleaned }, null, 2));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (sub === 'all') {
|
|
30
|
+
const serviceUp = await checkBrowserService();
|
|
31
|
+
const results = [];
|
|
32
|
+
|
|
33
|
+
if (serviceUp) {
|
|
34
|
+
try {
|
|
35
|
+
const status = await callAPI('getStatus', {});
|
|
36
|
+
const sessions = Array.isArray(status?.sessions) ? status.sessions : [];
|
|
37
|
+
|
|
38
|
+
for (const session of sessions) {
|
|
39
|
+
try {
|
|
40
|
+
await callAPI('stop', { profileId: session.profileId });
|
|
41
|
+
releaseLock(session.profileId);
|
|
42
|
+
markSessionClosed(session.profileId);
|
|
43
|
+
results.push({ profileId: session.profileId, ok: true });
|
|
44
|
+
} catch (err) {
|
|
45
|
+
results.push({ profileId: session.profileId, ok: false, error: err.message });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Cleanup stale locks and sessions
|
|
52
|
+
const cleanedLocks = cleanupStaleLocks();
|
|
53
|
+
const cleanedSessions = cleanupStaleSessions();
|
|
54
|
+
|
|
55
|
+
console.log(JSON.stringify({
|
|
56
|
+
ok: true,
|
|
57
|
+
sessions: results,
|
|
58
|
+
cleanedStaleLocks: cleanedLocks,
|
|
59
|
+
cleanedStaleSessions: cleanedSessions,
|
|
60
|
+
}, null, 2));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Clean specific profile
|
|
65
|
+
const profileId = resolveProfileId(args, 1, getDefaultProfile);
|
|
66
|
+
if (!profileId) {
|
|
67
|
+
throw new Error('Usage: camo cleanup [profileId] | camo cleanup all | camo cleanup locks | camo cleanup sessions');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const serviceUp = await checkBrowserService();
|
|
71
|
+
if (serviceUp) {
|
|
72
|
+
try {
|
|
73
|
+
await callAPI('stop', { profileId });
|
|
74
|
+
} catch {}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
releaseLock(profileId);
|
|
78
|
+
markSessionClosed(profileId);
|
|
79
|
+
console.log(JSON.stringify({ ok: true, profileId }, null, 2));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function handleForceStopCommand(args) {
|
|
83
|
+
await ensureBrowserService();
|
|
84
|
+
const profileId = resolveProfileId(args, 1, getDefaultProfile);
|
|
85
|
+
if (!profileId) throw new Error('Usage: camo force-stop [profileId]');
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const result = await callAPI('stop', { profileId, force: true });
|
|
89
|
+
releaseLock(profileId);
|
|
90
|
+
markSessionClosed(profileId);
|
|
91
|
+
console.log(JSON.stringify({ ok: true, profileId, ...result }, null, 2));
|
|
92
|
+
} catch (err) {
|
|
93
|
+
// Even if stop fails, cleanup local state
|
|
94
|
+
releaseLock(profileId);
|
|
95
|
+
markSessionClosed(profileId);
|
|
96
|
+
console.log(JSON.stringify({ ok: true, profileId, warning: 'Session stopped locally but remote stop failed: ' + err.message }, null, 2));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function handleLockCommand(args) {
|
|
101
|
+
const sub = args[1];
|
|
102
|
+
|
|
103
|
+
if (sub === 'list') {
|
|
104
|
+
const locks = listActiveLocks();
|
|
105
|
+
console.log(JSON.stringify({ ok: true, locks, count: locks.length }, null, 2));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (sub === 'cleanup') {
|
|
110
|
+
const cleaned = cleanupStaleLocks();
|
|
111
|
+
console.log(JSON.stringify({ ok: true, cleanedStaleLocks: cleaned }, null, 2));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const profileId = resolveProfileId(args, 1, getDefaultProfile);
|
|
116
|
+
if (!profileId) {
|
|
117
|
+
throw new Error('Usage: camo lock list | camo lock cleanup | camo lock [profileId]');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const info = getLockInfo(profileId);
|
|
121
|
+
if (!info) {
|
|
122
|
+
console.log(JSON.stringify({ ok: true, locked: false, profileId }, null, 2));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log(JSON.stringify({ ok: true, locked: true, ...info }, null, 2));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function handleUnlockCommand(args) {
|
|
130
|
+
const profileId = resolveProfileId(args, 1, getDefaultProfile);
|
|
131
|
+
if (!profileId) throw new Error('Usage: camo unlock [profileId]');
|
|
132
|
+
|
|
133
|
+
const released = releaseLock(profileId);
|
|
134
|
+
console.log(JSON.stringify({ ok: released, profileId, released }, null, 2));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function handleSessionsCommand(args) {
|
|
138
|
+
const serviceUp = await checkBrowserService();
|
|
139
|
+
const registeredSessions = listRegisteredSessions();
|
|
140
|
+
|
|
141
|
+
let liveSessions = [];
|
|
142
|
+
if (serviceUp) {
|
|
143
|
+
try {
|
|
144
|
+
const status = await callAPI('getStatus', {});
|
|
145
|
+
liveSessions = Array.isArray(status?.sessions) ? status.sessions : [];
|
|
146
|
+
} catch {}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Build a map of live sessions
|
|
150
|
+
const liveMap = new Map(liveSessions.map(s => [s.profileId, s]));
|
|
151
|
+
|
|
152
|
+
// Merge live and registered sessions
|
|
153
|
+
const merged = [];
|
|
154
|
+
|
|
155
|
+
// Add all live sessions
|
|
156
|
+
for (const live of liveSessions) {
|
|
157
|
+
const reg = getSessionInfo(live.profileId);
|
|
158
|
+
merged.push({
|
|
159
|
+
profileId: live.profileId,
|
|
160
|
+
sessionId: live.session_id || live.profileId,
|
|
161
|
+
url: live.current_url,
|
|
162
|
+
mode: live.mode,
|
|
163
|
+
live: true,
|
|
164
|
+
registered: !!reg,
|
|
165
|
+
registryStatus: reg?.status,
|
|
166
|
+
lastSeen: reg?.lastSeen,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Add registered sessions that are not live (orphaned)
|
|
171
|
+
for (const reg of registeredSessions) {
|
|
172
|
+
if (!liveMap.has(reg.profileId) && reg.status !== 'closed') {
|
|
173
|
+
merged.push({
|
|
174
|
+
...reg,
|
|
175
|
+
live: false,
|
|
176
|
+
orphaned: true,
|
|
177
|
+
needsRecovery: reg.status === 'active',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
console.log(JSON.stringify({
|
|
183
|
+
ok: true,
|
|
184
|
+
serviceUp,
|
|
185
|
+
sessions: merged,
|
|
186
|
+
count: merged.length,
|
|
187
|
+
registered: registeredSessions.length,
|
|
188
|
+
live: liveSessions.length,
|
|
189
|
+
orphaned: merged.filter(s => s.orphaned).length,
|
|
190
|
+
}, null, 2));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export async function handleRecoverCommand(args) {
|
|
194
|
+
const profileId = resolveProfileId(args, 1, getDefaultProfile);
|
|
195
|
+
if (!profileId) throw new Error('Usage: camo recover [profileId]');
|
|
196
|
+
|
|
197
|
+
const reg = getSessionInfo(profileId);
|
|
198
|
+
if (!reg) {
|
|
199
|
+
console.log(JSON.stringify({ ok: false, error: 'No registered session found for profile', profileId }, null, 2));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const serviceUp = await checkBrowserService();
|
|
204
|
+
|
|
205
|
+
if (!serviceUp) {
|
|
206
|
+
// Service is down - session cannot be recovered, clean up
|
|
207
|
+
unregisterSession(profileId);
|
|
208
|
+
releaseLock(profileId);
|
|
209
|
+
console.log(JSON.stringify({
|
|
210
|
+
ok: true,
|
|
211
|
+
recovered: false,
|
|
212
|
+
reason: 'browser_service_down',
|
|
213
|
+
profileId,
|
|
214
|
+
message: 'Browser service is down. Session cleaned up. Restart with: camo start ' + profileId,
|
|
215
|
+
}, null, 2));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Service is up - check if session is still there
|
|
220
|
+
try {
|
|
221
|
+
const status = await callAPI('getStatus', {});
|
|
222
|
+
const existing = status?.sessions?.find(s => s.profileId === profileId);
|
|
223
|
+
|
|
224
|
+
if (existing) {
|
|
225
|
+
// Session is alive - update registry
|
|
226
|
+
updateSession(profileId, {
|
|
227
|
+
sessionId: existing.session_id || existing.profileId,
|
|
228
|
+
url: existing.current_url,
|
|
229
|
+
status: 'active',
|
|
230
|
+
recoveredAt: Date.now(),
|
|
231
|
+
});
|
|
232
|
+
acquireLock(profileId, { sessionId: existing.session_id || existing.profileId });
|
|
233
|
+
console.log(JSON.stringify({
|
|
234
|
+
ok: true,
|
|
235
|
+
recovered: true,
|
|
236
|
+
profileId,
|
|
237
|
+
sessionId: existing.session_id || existing.profileId,
|
|
238
|
+
url: existing.current_url,
|
|
239
|
+
message: 'Session reconnected successfully',
|
|
240
|
+
}, null, 2));
|
|
241
|
+
} else {
|
|
242
|
+
// Session not in browser service - clean up
|
|
243
|
+
unregisterSession(profileId);
|
|
244
|
+
releaseLock(profileId);
|
|
245
|
+
console.log(JSON.stringify({
|
|
246
|
+
ok: true,
|
|
247
|
+
recovered: false,
|
|
248
|
+
reason: 'session_not_found',
|
|
249
|
+
profileId,
|
|
250
|
+
message: 'Session not found in browser service. Cleaned up. Restart with: camo start ' + profileId,
|
|
251
|
+
}, null, 2));
|
|
252
|
+
}
|
|
253
|
+
} catch (err) {
|
|
254
|
+
console.log(JSON.stringify({ ok: false, error: err.message, profileId }, null, 2));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getDefaultProfile } from '../utils/config.mjs';
|
|
2
|
+
import { callAPI, ensureBrowserService } from '../utils/browser-service.mjs';
|
|
3
|
+
import { getPositionals } from '../utils/args.mjs';
|
|
4
|
+
|
|
5
|
+
export async function handleMouseCommand(args) {
|
|
6
|
+
await ensureBrowserService();
|
|
7
|
+
|
|
8
|
+
const sub = args[1];
|
|
9
|
+
const profileId = getPositionals(args, 2)[0] || getDefaultProfile();
|
|
10
|
+
if (!profileId) throw new Error('No profile specified and no default profile set');
|
|
11
|
+
|
|
12
|
+
if (sub === 'move') {
|
|
13
|
+
const xIdx = args.indexOf('--x');
|
|
14
|
+
const yIdx = args.indexOf('--y');
|
|
15
|
+
const stepsIdx = args.indexOf('--steps');
|
|
16
|
+
if (xIdx === -1 || yIdx === -1) throw new Error('Usage: camo mouse move [profileId] --x <x> --y <y> [--steps <n>]');
|
|
17
|
+
const x = parseInt(args[xIdx + 1]);
|
|
18
|
+
const y = parseInt(args[yIdx + 1]);
|
|
19
|
+
const steps = stepsIdx >= 0 ? parseInt(args[stepsIdx + 1]) : undefined;
|
|
20
|
+
const result = await callAPI('mouse:move', { profileId, x, y, steps });
|
|
21
|
+
console.log(JSON.stringify(result, null, 2));
|
|
22
|
+
} else if (sub === 'click') {
|
|
23
|
+
// Use existing click command? We already have click command for element clicking.
|
|
24
|
+
// This is for raw mouse click at coordinates.
|
|
25
|
+
const xIdx = args.indexOf('--x');
|
|
26
|
+
const yIdx = args.indexOf('--y');
|
|
27
|
+
const buttonIdx = args.indexOf('--button');
|
|
28
|
+
const clicksIdx = args.indexOf('--clicks');
|
|
29
|
+
const delayIdx = args.indexOf('--delay');
|
|
30
|
+
if (xIdx === -1 || yIdx === -1) throw new Error('Usage: camo mouse click [profileId] --x <x> --y <y> [--button left|right|middle] [--clicks <n>] [--delay <ms>]');
|
|
31
|
+
const x = parseInt(args[xIdx + 1]);
|
|
32
|
+
const y = parseInt(args[yIdx + 1]);
|
|
33
|
+
const button = buttonIdx >= 0 ? args[buttonIdx + 1] : 'left';
|
|
34
|
+
const clicks = clicksIdx >= 0 ? parseInt(args[clicksIdx + 1]) : 1;
|
|
35
|
+
const delay = delayIdx >= 0 ? parseInt(args[delayIdx + 1]) : undefined;
|
|
36
|
+
const result = await callAPI('mouse:click', { profileId, x, y, button, clicks, delay });
|
|
37
|
+
console.log(JSON.stringify(result, null, 2));
|
|
38
|
+
} else if (sub === 'wheel') {
|
|
39
|
+
const deltaXIdx = args.indexOf('--deltax');
|
|
40
|
+
const deltaYIdx = args.indexOf('--deltay');
|
|
41
|
+
if (deltaXIdx === -1 && deltaYIdx === -1) throw new Error('Usage: camo mouse wheel [profileId] [--deltax <px>] [--deltay <px>]');
|
|
42
|
+
const deltaX = deltaXIdx >= 0 ? parseInt(args[deltaXIdx + 1]) : 0;
|
|
43
|
+
const deltaY = deltaYIdx >= 0 ? parseInt(args[deltaYIdx + 1]) : 0;
|
|
44
|
+
const result = await callAPI('mouse:wheel', { profileId, deltaX, deltaY });
|
|
45
|
+
console.log(JSON.stringify(result, null, 2));
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error('Usage: camo mouse <move|click|wheel> [profileId] [options]');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { listProfiles, createProfile, deleteProfile, setDefaultProfile, getDefaultProfile, loadConfig, saveConfig } from '../utils/config.mjs';
|
|
2
|
+
|
|
3
|
+
export async function handleProfileCommand(args) {
|
|
4
|
+
const sub = args[1];
|
|
5
|
+
const profileId = args[2];
|
|
6
|
+
|
|
7
|
+
if (sub === 'list' || !sub) {
|
|
8
|
+
const profiles = listProfiles();
|
|
9
|
+
const defaultProfile = getDefaultProfile();
|
|
10
|
+
console.log(JSON.stringify({ ok: true, profiles, defaultProfile, count: profiles.length }, null, 2));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (sub === 'create') {
|
|
15
|
+
if (!profileId) throw new Error('Usage: camo profile create <profileId>');
|
|
16
|
+
createProfile(profileId);
|
|
17
|
+
console.log(`Created profile: ${profileId}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (sub === 'delete' || sub === 'remove') {
|
|
22
|
+
if (!profileId) throw new Error('Usage: camo profile delete <profileId>');
|
|
23
|
+
deleteProfile(profileId);
|
|
24
|
+
const cfg = loadConfig();
|
|
25
|
+
if (cfg.defaultProfile === profileId) {
|
|
26
|
+
cfg.defaultProfile = null;
|
|
27
|
+
saveConfig(cfg);
|
|
28
|
+
}
|
|
29
|
+
console.log(`Deleted profile: ${profileId}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (sub === 'default') {
|
|
34
|
+
if (!profileId) {
|
|
35
|
+
console.log(JSON.stringify({ ok: true, defaultProfile: getDefaultProfile() }, null, 2));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const profiles = listProfiles();
|
|
39
|
+
if (!profiles.includes(profileId)) throw new Error(`Profile not found: ${profileId}`);
|
|
40
|
+
setDefaultProfile(profileId);
|
|
41
|
+
console.log(`Default profile set to: ${profileId}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new Error('Usage: camo profile <list|create|delete|default> [profileId]');
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { callAPI, ensureBrowserService } from '../utils/browser-service.mjs';
|
|
2
|
+
|
|
3
|
+
export async function handleSystemCommand(args) {
|
|
4
|
+
await ensureBrowserService();
|
|
5
|
+
|
|
6
|
+
const sub = args[1];
|
|
7
|
+
|
|
8
|
+
if (sub === 'display') {
|
|
9
|
+
const result = await callAPI('system:display', {});
|
|
10
|
+
console.log(JSON.stringify(result, null, 2));
|
|
11
|
+
} else {
|
|
12
|
+
throw new Error('Usage: camo system display');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getDefaultProfile } from '../utils/config.mjs';
|
|
2
|
+
import { callAPI, ensureBrowserService } from '../utils/browser-service.mjs';
|
|
3
|
+
import { getPositionals } from '../utils/args.mjs';
|
|
4
|
+
|
|
5
|
+
export async function handleWindowCommand(args) {
|
|
6
|
+
await ensureBrowserService();
|
|
7
|
+
|
|
8
|
+
const sub = args[1];
|
|
9
|
+
const profileId = getPositionals(args, 2)[0] || getDefaultProfile();
|
|
10
|
+
if (!profileId) throw new Error('No profile specified and no default profile set');
|
|
11
|
+
|
|
12
|
+
if (sub === 'move') {
|
|
13
|
+
const xIdx = args.indexOf('--x');
|
|
14
|
+
const yIdx = args.indexOf('--y');
|
|
15
|
+
if (xIdx === -1 || yIdx === -1) throw new Error('Usage: camo window move [profileId] --x <x> --y <y>');
|
|
16
|
+
const x = parseInt(args[xIdx + 1]);
|
|
17
|
+
const y = parseInt(args[yIdx + 1]);
|
|
18
|
+
const result = await callAPI('window:move', { profileId, x, y });
|
|
19
|
+
console.log(JSON.stringify(result, null, 2));
|
|
20
|
+
} else if (sub === 'resize') {
|
|
21
|
+
const widthIdx = args.indexOf('--width');
|
|
22
|
+
const heightIdx = args.indexOf('--height');
|
|
23
|
+
if (widthIdx === -1 || heightIdx === -1) throw new Error('Usage: camo window resize [profileId] --width <w> --height <h>');
|
|
24
|
+
const width = parseInt(args[widthIdx + 1]);
|
|
25
|
+
const height = parseInt(args[heightIdx + 1]);
|
|
26
|
+
const result = await callAPI('window:resize', { profileId, width, height });
|
|
27
|
+
console.log(JSON.stringify(result, null, 2));
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error('Usage: camo window <move|resize> [profileId] --x <x> --y <y> / --width <w> --height <h>');
|
|
30
|
+
}
|
|
31
|
+
}
|