@xkwdstore/agent 2.0.5 → 2.0.6
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 +4 -6
- package/package.json +1 -1
- package/src/actions/comment.js +18 -2
- package/src/actions/follow.js +44 -4
- package/src/actions/tweet.js +17 -1
- package/src/cli.js +6 -1
- package/src/enrollmentClient.js +43 -2
- package/src/sessionHandler.js +304 -581
package/README.md
CHANGED
|
@@ -6,8 +6,7 @@ Terminal-only, cryptographically authenticated CLI for XKWDStore browser automat
|
|
|
6
6
|
|
|
7
7
|
> **@xkwdstore/agent 2.0.3 is the last version published on npm.**
|
|
8
8
|
>
|
|
9
|
-
> The current source version is **2.0.
|
|
10
|
-
> lifecycle cause codes, cookie parity, stopped-frame dedupe). It is
|
|
9
|
+
> The current source version is **2.0.6** (Tweet/Comment/Follow confirmation-safety fixes). It is
|
|
11
10
|
> NOT claimed to be published unless the release workflow has published it — see
|
|
12
11
|
> `reports/` for the authoritative publication state.
|
|
13
12
|
|
|
@@ -30,7 +29,7 @@ curl -L -o "%TEMP%\xkwdstore-install.ps1" https://raw.githubusercontent.com/Essa
|
|
|
30
29
|
The generated launcher runs the pinned command:
|
|
31
30
|
|
|
32
31
|
```powershell
|
|
33
|
-
npx --yes @xkwdstore/agent@2.0.
|
|
32
|
+
npx --yes @xkwdstore/agent@2.0.6 start
|
|
34
33
|
```
|
|
35
34
|
|
|
36
35
|
Automated installer tests use `-NoLaunch` or a mocked `npx` command so the
|
|
@@ -178,11 +177,10 @@ The agent does NOT update itself. To use a newer version, change the version
|
|
|
178
177
|
number in the command. The pinned command for this release is:
|
|
179
178
|
|
|
180
179
|
```powershell
|
|
181
|
-
npx --yes @xkwdstore/agent@2.0.
|
|
180
|
+
npx --yes @xkwdstore/agent@2.0.6 start
|
|
182
181
|
```
|
|
183
182
|
|
|
184
|
-
> 2.0.
|
|
185
|
-
> lifecycle cause codes, cookie parity, stopped-frame dedupe).
|
|
183
|
+
> 2.0.6 is the current local agent version (Tweet/Comment/Follow confirmation-safety fixes).
|
|
186
184
|
> 2.0.3 was the previous release.
|
|
187
185
|
>
|
|
188
186
|
> The server checks compatibility at startup and displays a clear message if
|
package/package.json
CHANGED
package/src/actions/comment.js
CHANGED
|
@@ -118,12 +118,19 @@ async function comment(page, payload) {
|
|
|
118
118
|
await page.keyboard.press('Control+Enter');
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
// Wait for
|
|
121
|
+
// Wait for the compose surface to close. The comment editor detaching is the
|
|
122
|
+
// ONLY reliable success signal we have; if it never closes the comment may or
|
|
123
|
+
// may not have been submitted, so the outcome is UNKNOWN — never report
|
|
124
|
+
// success (and never auto-retry, since a comment is not idempotent).
|
|
125
|
+
let editorDetached = false;
|
|
122
126
|
try {
|
|
123
|
-
await page.waitForSelector('
|
|
127
|
+
await page.waitForSelector('[data-testid="tweetTextarea_0"]', { state: 'detached', timeout: 15000 });
|
|
128
|
+
editorDetached = true;
|
|
124
129
|
} catch {
|
|
125
130
|
await page.keyboard.press('Control+Enter');
|
|
126
131
|
await sleep(3000);
|
|
132
|
+
const stillVisible = await page.locator('[data-testid="tweetTextarea_0"]').first().isVisible({ timeout: 2000 }).catch(() => false);
|
|
133
|
+
editorDetached = !stillVisible;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
// Check for failure
|
|
@@ -132,6 +139,15 @@ async function comment(page, payload) {
|
|
|
132
139
|
throw new Error('Comment submit reported a failure');
|
|
133
140
|
}
|
|
134
141
|
|
|
142
|
+
if (!editorDetached) {
|
|
143
|
+
return {
|
|
144
|
+
success: false,
|
|
145
|
+
code: 'UNKNOWN_OUTCOME',
|
|
146
|
+
outcome: 'unknown',
|
|
147
|
+
error: 'Comment submit could not be confirmed (editor is still open); outcome unknown',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
return { success: true, message: 'Comment posted' };
|
|
136
152
|
}
|
|
137
153
|
|
package/src/actions/follow.js
CHANGED
|
@@ -19,6 +19,42 @@ const FOLLOWING_LABELS = [
|
|
|
19
19
|
'unfollow', 'dejar de seguir', 'ne plus suivre', 'entfolgen', 'إلغاء المتابعة',
|
|
20
20
|
];
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Confirm a follow actually took effect. A click that did not throw is NOT
|
|
24
|
+
* evidence. We accept the standard post-follow signals (the unfollow testid or
|
|
25
|
+
* a Following/Unfollow control). Bounded wait; never throws.
|
|
26
|
+
*/
|
|
27
|
+
const FOLLOW_CONFIRM_TIMEOUT_MS = parseInt(process.env.LOCAL_AGENT_FOLLOW_CONFIRM_TIMEOUT_MS || '8000', 10);
|
|
28
|
+
|
|
29
|
+
async function confirmFollow(page, cleanUsername) {
|
|
30
|
+
const deadline = Date.now() + FOLLOW_CONFIRM_TIMEOUT_MS;
|
|
31
|
+
while (Date.now() < deadline) {
|
|
32
|
+
const candidates = [
|
|
33
|
+
`[data-testid="${cleanUsername}-unfollow"]`,
|
|
34
|
+
'[data-testid="unfollow"]',
|
|
35
|
+
'[role="button"][aria-label*="Following"]',
|
|
36
|
+
'[role="button"][aria-label*="Unfollow"]',
|
|
37
|
+
'button[aria-label*="Following"]',
|
|
38
|
+
'button[aria-label*="Unfollow"]',
|
|
39
|
+
];
|
|
40
|
+
for (const sel of candidates) {
|
|
41
|
+
const el = page.locator(sel).first();
|
|
42
|
+
if (await el.isVisible({ timeout: 500 }).catch(() => false)) return true;
|
|
43
|
+
}
|
|
44
|
+
await sleep(1000);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function unconfirmedFollow(cleanUsername) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
code: 'UNKNOWN_OUTCOME',
|
|
53
|
+
outcome: 'unknown',
|
|
54
|
+
error: `Follow click for @${cleanUsername} could not be confirmed; outcome unknown`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
22
58
|
async function follow(page, payload) {
|
|
23
59
|
const { username } = payload;
|
|
24
60
|
if (!username) throw new Error('username required');
|
|
@@ -48,8 +84,10 @@ async function follow(page, payload) {
|
|
|
48
84
|
const btn = page.locator(sel).first();
|
|
49
85
|
if (await btn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
|
50
86
|
await humanClick(page, btn);
|
|
51
|
-
await
|
|
52
|
-
|
|
87
|
+
if (await confirmFollow(page, cleanUsername)) {
|
|
88
|
+
return { success: true, message: `Following @${cleanUsername}` };
|
|
89
|
+
}
|
|
90
|
+
return unconfirmedFollow(cleanUsername);
|
|
53
91
|
}
|
|
54
92
|
}
|
|
55
93
|
|
|
@@ -63,8 +101,10 @@ async function follow(page, payload) {
|
|
|
63
101
|
// Check if it's actually "following" (already following)
|
|
64
102
|
if (FOLLOWING_LABELS.some(label => text.includes(label))) continue;
|
|
65
103
|
await humanClick(page, btn);
|
|
66
|
-
await
|
|
67
|
-
|
|
104
|
+
if (await confirmFollow(page, cleanUsername)) {
|
|
105
|
+
return { success: true, message: `Following @${cleanUsername}` };
|
|
106
|
+
}
|
|
107
|
+
return unconfirmedFollow(cleanUsername);
|
|
68
108
|
}
|
|
69
109
|
}
|
|
70
110
|
|
package/src/actions/tweet.js
CHANGED
|
@@ -70,13 +70,20 @@ async function tweet(page, payload) {
|
|
|
70
70
|
await page.keyboard.press('Control+Enter');
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// Wait for compose
|
|
73
|
+
// Wait for the compose surface to close. Detachment of the composer is the
|
|
74
|
+
// ONLY reliable success signal we have; if it never closes the tweet may or
|
|
75
|
+
// may not have been submitted, so the outcome is UNKNOWN — never report
|
|
76
|
+
// success (and never auto-retry, since a tweet is not idempotent).
|
|
77
|
+
let editorDetached = false;
|
|
74
78
|
try {
|
|
75
79
|
await page.waitForSelector(editorSelector, { state: 'detached', timeout: 15000 });
|
|
80
|
+
editorDetached = true;
|
|
76
81
|
} catch {
|
|
77
82
|
// Retry with Ctrl+Enter
|
|
78
83
|
await page.keyboard.press('Control+Enter');
|
|
79
84
|
await sleep(3000);
|
|
85
|
+
const stillVisible = await page.locator(editorSelector).first().isVisible({ timeout: 2000 }).catch(() => false);
|
|
86
|
+
editorDetached = !stillVisible;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
// Check for failure toast
|
|
@@ -85,6 +92,15 @@ async function tweet(page, payload) {
|
|
|
85
92
|
throw new Error('Tweet submit reported a failure toast');
|
|
86
93
|
}
|
|
87
94
|
|
|
95
|
+
if (!editorDetached) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
code: 'UNKNOWN_OUTCOME',
|
|
99
|
+
outcome: 'unknown',
|
|
100
|
+
error: 'Tweet submit could not be confirmed (compose box is still open); outcome unknown',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
88
104
|
return { success: true, message: 'Tweet posted' };
|
|
89
105
|
}
|
|
90
106
|
|
package/src/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ const crypto = require('crypto');
|
|
|
24
24
|
const os = require('os');
|
|
25
25
|
const path = require('path');
|
|
26
26
|
|
|
27
|
-
const CLI_VERSION = '2.0.
|
|
27
|
+
const CLI_VERSION = '2.0.6';
|
|
28
28
|
const PROTOCOL_VERSION = 2;
|
|
29
29
|
|
|
30
30
|
// ── Command parsing ──────────────────────────────────────────────────────────
|
|
@@ -120,6 +120,11 @@ async function start(serverOrigin, flags) {
|
|
|
120
120
|
console.error('The agent will not start enrollment until the server is compatible.');
|
|
121
121
|
process.exit(1);
|
|
122
122
|
}
|
|
123
|
+
// NOTE: the server's declared `capabilities` are INFORMATIONAL. They are
|
|
124
|
+
// never a reason to refuse a server — a server that does not advertise the
|
|
125
|
+
// profile-identity capability may still supply the identity tuple, and every
|
|
126
|
+
// currently-deployed backend omits the field. A missing capability must not
|
|
127
|
+
// block startup (see validateCompatibilityResponse).
|
|
123
128
|
// compat.ok — enforce minimum agent version
|
|
124
129
|
const minVer = compat.body.minimumAgentVersion;
|
|
125
130
|
const recVer = compat.body.recommendedAgentVersion;
|
package/src/enrollmentClient.js
CHANGED
|
@@ -299,6 +299,26 @@ function _isHtmlResponse(data, contentType) {
|
|
|
299
299
|
return body.startsWith('<!doctype html>') || body.startsWith('<html');
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
/**
|
|
303
|
+
* The server capability that indicates the backend can send the complete
|
|
304
|
+
* immutable profile-identity tuple inside startSession.options.
|
|
305
|
+
*
|
|
306
|
+
* THIS IS INFORMATIONAL ONLY — IT MUST NEVER GATE COMPATIBILITY.
|
|
307
|
+
* ------------------------------------------------------------
|
|
308
|
+
* An earlier revision made this a hard requirement of
|
|
309
|
+
* validateCompatibilityResponse. That was WRONG and would have been an outage:
|
|
310
|
+
* every currently-deployed server (including the live production backend) and
|
|
311
|
+
* every currently-published agent (2.0.4, 2.0.5) treat `capabilities` as an
|
|
312
|
+
* unknown/extra field, so requiring it would have REFUSED servers that in fact
|
|
313
|
+
* work correctly. Availability has to be able to report a capability that a
|
|
314
|
+
* server does not yet advertise without breaking that server.
|
|
315
|
+
*
|
|
316
|
+
* The field is therefore parsed and surfaced (see `capabilities` on the returned
|
|
317
|
+
* object) so operator tooling can DISPLAY the difference, but its absence never
|
|
318
|
+
* produces { ok: false }.
|
|
319
|
+
*/
|
|
320
|
+
const PROFILE_IDENTITY_CAPABILITY = 'profile-identity-v1';
|
|
321
|
+
|
|
302
322
|
/**
|
|
303
323
|
* Shared strict compatibility validator (Protocol-v2 contract).
|
|
304
324
|
*
|
|
@@ -311,12 +331,20 @@ function _isHtmlResponse(data, contentType) {
|
|
|
311
331
|
* - non-empty minimumAgentVersion
|
|
312
332
|
* - non-empty recommendedAgentVersion
|
|
313
333
|
*
|
|
334
|
+
* OPTIONAL (never a failure condition):
|
|
335
|
+
* - capabilities[] — parsed and returned when present, so a caller can show
|
|
336
|
+
* whether the server advertises the profile-identity contract. A missing or
|
|
337
|
+
* ill-typed value is IGNORED, not rejected: the declared capability set is
|
|
338
|
+
* metadata about the server, and treating absent metadata as an
|
|
339
|
+
* incompatibility would break servers that are perfectly usable.
|
|
340
|
+
*
|
|
314
341
|
* Never prints the HTML body or undefined values. For HTML/SPA responses it
|
|
315
342
|
* returns { ok: false, html: true } and the caller prints the exact required
|
|
316
343
|
* message.
|
|
317
344
|
*
|
|
318
345
|
* @param {object} resp — { status, body, contentType }
|
|
319
|
-
* @returns {object} { ok: boolean, html?: boolean, reason?: string, body?: object
|
|
346
|
+
* @returns {object} { ok: boolean, html?: boolean, reason?: string, body?: object,
|
|
347
|
+
* capabilities: string[], hasProfileIdentityCapability: boolean }
|
|
320
348
|
*/
|
|
321
349
|
function validateCompatibilityResponse(resp) {
|
|
322
350
|
if (!resp || typeof resp !== 'object') {
|
|
@@ -348,7 +376,19 @@ function validateCompatibilityResponse(resp) {
|
|
|
348
376
|
if (!body.recommendedAgentVersion || typeof body.recommendedAgentVersion !== 'string') {
|
|
349
377
|
return { ok: false, reason: 'missing recommendedAgentVersion' };
|
|
350
378
|
}
|
|
351
|
-
|
|
379
|
+
// OPTIONAL capabilities: read for DISPLAY only. An absent, empty, or
|
|
380
|
+
// ill-typed value must NOT fail compatibility — a server that does not
|
|
381
|
+
// advertise capabilities can still be fully usable (every deployed server
|
|
382
|
+
// today omits it). Only well-formed string entries are surfaced.
|
|
383
|
+
const capabilities = Array.isArray(body.capabilities)
|
|
384
|
+
? body.capabilities.filter((c) => typeof c === 'string' && c.trim()).map((c) => c.trim())
|
|
385
|
+
: [];
|
|
386
|
+
return {
|
|
387
|
+
ok: true,
|
|
388
|
+
body,
|
|
389
|
+
capabilities,
|
|
390
|
+
hasProfileIdentityCapability: capabilities.includes(PROFILE_IDENTITY_CAPABILITY),
|
|
391
|
+
};
|
|
352
392
|
}
|
|
353
393
|
|
|
354
394
|
/**
|
|
@@ -586,4 +626,5 @@ module.exports = {
|
|
|
586
626
|
_isHtmlResponse,
|
|
587
627
|
validateCompatibilityResponse,
|
|
588
628
|
COMPAT_HTML_MESSAGE,
|
|
629
|
+
PROFILE_IDENTITY_CAPABILITY,
|
|
589
630
|
};
|