linkedin-relay-mcp 1.3.3 → 1.5.0
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/dist/cli.js +268 -42
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +2 -2
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2668,8 +2668,8 @@ var COMMANDS = [
|
|
|
2668
2668
|
{
|
|
2669
2669
|
name: "comment",
|
|
2670
2670
|
cost: "1 call \u2014 write",
|
|
2671
|
-
summary: "Comment on a post.
|
|
2672
|
-
usage: 'lnrelay comment <activity-urn> "<text>"',
|
|
2671
|
+
summary: "Comment on a post. Harvests the binding tokens from the rendered page first \u2014 no browser needed, but it costs one heavy read.",
|
|
2672
|
+
usage: 'lnrelay comment <activity-urn> "<text>"\n Fetches the post page (~2.8 MB) to harvest a binding key and trackingId, proves the\n key belongs to that post, then asks. UNVERIFIED: never yet replayed successfully.',
|
|
2673
2673
|
audience: ["cli"],
|
|
2674
2674
|
risk: "write",
|
|
2675
2675
|
implemented: true
|
|
@@ -2911,23 +2911,222 @@ function share2(confirmed, token, deps) {
|
|
|
2911
2911
|
deps
|
|
2912
2912
|
);
|
|
2913
2913
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2914
|
+
|
|
2915
|
+
// src/engine/sdui-harvest.ts
|
|
2916
|
+
function zigzag(n) {
|
|
2917
|
+
return n << 1n ^ n >> 63n;
|
|
2918
|
+
}
|
|
2919
|
+
function varint(n) {
|
|
2920
|
+
const out = [];
|
|
2921
|
+
let v = n;
|
|
2922
|
+
while (v > 0x7fn) {
|
|
2923
|
+
out.push(Number(v & 0x7fn | 0x80n));
|
|
2924
|
+
v >>= 7n;
|
|
2925
|
+
}
|
|
2926
|
+
out.push(Number(v));
|
|
2927
|
+
return out;
|
|
2928
|
+
}
|
|
2929
|
+
function activityIdSegment(activityId) {
|
|
2930
|
+
if (!/^\d+$/.test(activityId)) {
|
|
2931
|
+
throw new Error(`'${activityId}' is not a numeric activity id`);
|
|
2932
|
+
}
|
|
2933
|
+
const inner = [8, ...varint(zigzag(BigInt(activityId)))];
|
|
2934
|
+
const message = Uint8Array.from([10, inner.length, ...inner]);
|
|
2935
|
+
return btoa(String.fromCharCode(...message)).replace(/=+$/, "");
|
|
2936
|
+
}
|
|
2937
|
+
function keyMatchesPost(bindingKey, activityId) {
|
|
2938
|
+
try {
|
|
2939
|
+
return bindingKey.startsWith(`commentBoxText-${activityIdSegment(activityId)}-`);
|
|
2940
|
+
} catch {
|
|
2941
|
+
return false;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
var NOT_THE_POST = /checkpoint\/challenge|\/uas\/login|authwall|"status"\s*:\s*999/i;
|
|
2945
|
+
var TRACKING_PROXIMITY = 400;
|
|
2946
|
+
function updateTrackingId(html, activityId) {
|
|
2947
|
+
const idAt = [...html.matchAll(new RegExp(activityId, "g"))].map((m) => m.index ?? 0);
|
|
2948
|
+
if (idAt.length === 0) return null;
|
|
2949
|
+
const pattern = /trackingId(?:"|\\?")+\s*:\s*(?:"|\\?")+([A-Za-z0-9+/=]{16,32})/g;
|
|
2950
|
+
let best = null;
|
|
2951
|
+
for (const m of html.matchAll(pattern)) {
|
|
2952
|
+
const at = m.index ?? 0;
|
|
2953
|
+
const distance = Math.min(...idAt.map((p) => Math.abs(p - at)));
|
|
2954
|
+
if (best === null || distance < best.distance) best = { value: m[1], distance };
|
|
2955
|
+
}
|
|
2956
|
+
return best !== null && best.distance <= TRACKING_PROXIMITY ? best.value : null;
|
|
2957
|
+
}
|
|
2958
|
+
function extractCommentTokens(html, activityId) {
|
|
2959
|
+
if (NOT_THE_POST.test(html)) {
|
|
2960
|
+
return {
|
|
2961
|
+
ok: false,
|
|
2962
|
+
message: "the page returned was a challenge or sign-in wall, not the post",
|
|
2963
|
+
hint: "Re-mint the session with `lnrelay login`, then check `lnrelay risk`."
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
let expected;
|
|
2967
|
+
try {
|
|
2968
|
+
expected = activityIdSegment(activityId);
|
|
2969
|
+
} catch (e) {
|
|
2970
|
+
return { ok: false, message: e.message };
|
|
2971
|
+
}
|
|
2972
|
+
const keyPattern = new RegExp(
|
|
2973
|
+
`commentBoxText-${expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[A-Za-z0-9+/_=-]*FeedType_[A-Z_]+`
|
|
2925
2974
|
);
|
|
2975
|
+
const key = keyPattern.exec(html)?.[0];
|
|
2976
|
+
if (key === void 0) {
|
|
2977
|
+
return {
|
|
2978
|
+
ok: false,
|
|
2979
|
+
message: `no comment-box binding key for post ${activityId} was found in the page`,
|
|
2980
|
+
hint: "Either the post does not accept comments, or LinkedIn changed the rendered shape. Re-capture with `bun run scripts/observe-write.ts` before changing this parser."
|
|
2981
|
+
};
|
|
2982
|
+
}
|
|
2983
|
+
const trackingId = updateTrackingId(html, activityId);
|
|
2984
|
+
if (trackingId === null) {
|
|
2985
|
+
return {
|
|
2986
|
+
ok: false,
|
|
2987
|
+
message: `no trackingId adjacent to post ${activityId} was found in the page`,
|
|
2988
|
+
hint: "The page carries several \u2014 one for the page itself, one per rendered update. Only the update's own will do, and guessing would build a malformed comment."
|
|
2989
|
+
};
|
|
2990
|
+
}
|
|
2991
|
+
return { ok: true, bindingKey: key, trackingId };
|
|
2926
2992
|
}
|
|
2927
2993
|
|
|
2928
|
-
// src/engine/sdui-
|
|
2994
|
+
// src/engine/sdui-comment.ts
|
|
2929
2995
|
var SDUI_ACTION = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
2996
|
+
var COMMENT_URL = `${SDUI_ACTION}?sduiid=com.linkedin.sdui.comments.createComment`;
|
|
2930
2997
|
var SCREEN_ID = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
2998
|
+
var STATE_PREFIXES = [
|
|
2999
|
+
"commentBoxText",
|
|
3000
|
+
"richCommentBoxText",
|
|
3001
|
+
"commentBoxLinkPreviewIngestedContentId",
|
|
3002
|
+
"commentBoxExternalImageUrl",
|
|
3003
|
+
"commentBoxExternalImageId"
|
|
3004
|
+
];
|
|
3005
|
+
var FEED_TYPES = { FEED_DETAIL: 3 };
|
|
3006
|
+
function keyBody(bindingKey) {
|
|
3007
|
+
return bindingKey.replace(/^commentBoxText-/, "");
|
|
3008
|
+
}
|
|
3009
|
+
function feedTypeFor(bindingKey) {
|
|
3010
|
+
const suffix = /FeedType_([A-Z_]+)$/.exec(bindingKey)?.[1];
|
|
3011
|
+
return suffix === void 0 ? null : FEED_TYPES[suffix] ?? null;
|
|
3012
|
+
}
|
|
3013
|
+
function stateKey(prefix, body) {
|
|
3014
|
+
return `${prefix}-${body}`;
|
|
3015
|
+
}
|
|
3016
|
+
function states(text2, body) {
|
|
3017
|
+
return STATE_PREFIXES.map((prefix) => {
|
|
3018
|
+
const key = stateKey(prefix, body);
|
|
3019
|
+
const base = {
|
|
3020
|
+
key,
|
|
3021
|
+
namespace: "MemoryNamespace",
|
|
3022
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
|
|
3023
|
+
};
|
|
3024
|
+
if (prefix === "commentBoxText") {
|
|
3025
|
+
return { ...base, value: text2, originalProtoCase: "stringValue" };
|
|
3026
|
+
}
|
|
3027
|
+
if (prefix === "richCommentBoxText") {
|
|
3028
|
+
return {
|
|
3029
|
+
...base,
|
|
3030
|
+
value: { text: text2, attribute: [], $type: "TextModel", source: "local" },
|
|
3031
|
+
originalProtoCase: "textModelForWrite"
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
return { ...base, value: "", originalProtoCase: "stringValue" };
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
function commentBody(activityId, text2, tokens, feedType) {
|
|
3038
|
+
const body = keyBody(tokens.bindingKey);
|
|
3039
|
+
const activityUrn = { activityUrn: { activityId } };
|
|
3040
|
+
const binding = (prefix) => ({
|
|
3041
|
+
key: stateKey(prefix, body),
|
|
3042
|
+
namespace: "MemoryNamespace"
|
|
3043
|
+
});
|
|
3044
|
+
const payload = {
|
|
3045
|
+
// The live client's handle for its optimistically-rendered comment. Server
|
|
3046
|
+
// relevance unknown, but it is cheap to send and being faithful to a
|
|
3047
|
+
// captured shape beats trimming fields whose purpose we are guessing at.
|
|
3048
|
+
optimisticKey: `auto-component-${crypto.randomUUID()}`,
|
|
3049
|
+
collection: {
|
|
3050
|
+
updateKey: {
|
|
3051
|
+
feedType,
|
|
3052
|
+
items: [
|
|
3053
|
+
{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId: tokens.trackingId }
|
|
3054
|
+
],
|
|
3055
|
+
aggregationType: 0,
|
|
3056
|
+
isVideoCarousel: false
|
|
3057
|
+
},
|
|
3058
|
+
threadUrn: { threadUrnActivityThreadUrn: activityUrn }
|
|
3059
|
+
},
|
|
3060
|
+
commentFieldBinding: binding("commentBoxText"),
|
|
3061
|
+
richCommentFieldBinding: binding("richCommentBoxText"),
|
|
3062
|
+
linkPreviewIngestedContentId: binding("commentBoxLinkPreviewIngestedContentId"),
|
|
3063
|
+
externalImageUrl: binding("commentBoxExternalImageUrl"),
|
|
3064
|
+
externalImageId: binding("commentBoxExternalImageId")
|
|
3065
|
+
};
|
|
3066
|
+
const requestedStateKeys = STATE_PREFIXES.map((p) => ({
|
|
3067
|
+
key: { value: { $case: "id", id: stateKey(p, body) } }
|
|
3068
|
+
}));
|
|
3069
|
+
const args = {
|
|
3070
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
3071
|
+
requestedStateKeys,
|
|
3072
|
+
payload,
|
|
3073
|
+
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
3074
|
+
};
|
|
3075
|
+
return {
|
|
3076
|
+
requestId: "com.linkedin.sdui.comments.createComment",
|
|
3077
|
+
serverRequest: {
|
|
3078
|
+
requestId: "com.linkedin.sdui.comments.createComment",
|
|
3079
|
+
requestedArguments: args,
|
|
3080
|
+
isApfcEnabled: false,
|
|
3081
|
+
isStreaming: false,
|
|
3082
|
+
rumPageKey: ""
|
|
3083
|
+
},
|
|
3084
|
+
states: states(text2, body),
|
|
3085
|
+
requestedArguments: {
|
|
3086
|
+
...args,
|
|
3087
|
+
states: states(text2, body),
|
|
3088
|
+
screenId: SCREEN_ID,
|
|
3089
|
+
knownTemplateIds: []
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
async function comment(confirmed, client) {
|
|
3094
|
+
const { activityId, text: text2, tokens } = confirmed.payload;
|
|
3095
|
+
if (!keyMatchesPost(tokens.bindingKey, activityId)) {
|
|
3096
|
+
return {
|
|
3097
|
+
ok: false,
|
|
3098
|
+
code: "INVALID_INPUT",
|
|
3099
|
+
message: "the harvested binding key does not belong to this post",
|
|
3100
|
+
hint: "Refusing to send: this is how a comment lands on the wrong post. Re-harvest."
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
const feedType = feedTypeFor(tokens.bindingKey);
|
|
3104
|
+
if (feedType === null) {
|
|
3105
|
+
return {
|
|
3106
|
+
ok: false,
|
|
3107
|
+
code: "NOT_IMPLEMENTED",
|
|
3108
|
+
message: `unknown feed type in binding key '${tokens.bindingKey.slice(-24)}'`,
|
|
3109
|
+
hint: "Only FeedType_FEED_DETAIL has been observed, carrying feedType 3. Inventing a number for another context would be a malformed write against a real post. Capture the missing one with `bun run scripts/observe-write.ts`."
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
const result = await client.request({
|
|
3113
|
+
url: COMMENT_URL,
|
|
3114
|
+
method: "POST",
|
|
3115
|
+
body: commentBody(activityId, text2, tokens, feedType),
|
|
3116
|
+
spendClass: "write",
|
|
3117
|
+
operation: "comment.create"
|
|
3118
|
+
});
|
|
3119
|
+
if (!result.ok) {
|
|
3120
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
3121
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
3122
|
+
return out;
|
|
3123
|
+
}
|
|
3124
|
+
return { ok: true, id: activityId };
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
// src/engine/sdui-write.ts
|
|
3128
|
+
var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
3129
|
+
var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
2931
3130
|
var REACTIONS = [
|
|
2932
3131
|
"LIKE",
|
|
2933
3132
|
"PRAISE",
|
|
@@ -2948,7 +3147,7 @@ function reactionLabel(reaction) {
|
|
|
2948
3147
|
return LABELS[reaction];
|
|
2949
3148
|
}
|
|
2950
3149
|
function reactionUrl(op) {
|
|
2951
|
-
return `${
|
|
3150
|
+
return `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.reactions.${op}`;
|
|
2952
3151
|
}
|
|
2953
3152
|
function targetFor(urn) {
|
|
2954
3153
|
const comment2 = /^urn:li:comment:\((urn:li:activity:\d+),(\d+)\)$/.exec(urn);
|
|
@@ -3004,7 +3203,7 @@ function sduiBody(op, target, reaction) {
|
|
|
3004
3203
|
requestedArguments: {
|
|
3005
3204
|
...args,
|
|
3006
3205
|
states: [],
|
|
3007
|
-
screenId:
|
|
3206
|
+
screenId: SCREEN_ID2,
|
|
3008
3207
|
knownTemplateIds: []
|
|
3009
3208
|
}
|
|
3010
3209
|
};
|
|
@@ -3104,21 +3303,6 @@ ${OAUTH_SETUP}`);
|
|
|
3104
3303
|
if (choice.note !== void 0) ctx.note = choice.note;
|
|
3105
3304
|
return ctx;
|
|
3106
3305
|
}
|
|
3107
|
-
function oauthToken(ctx) {
|
|
3108
|
-
if (ctx.transport.kind !== "oauth") {
|
|
3109
|
-
throw new Error("oauthToken called on a non-oauth transport");
|
|
3110
|
-
}
|
|
3111
|
-
return ctx.transport.token;
|
|
3112
|
-
}
|
|
3113
|
-
function requireOauth(command, ctx) {
|
|
3114
|
-
if (ctx.transport.kind === "oauth") return null;
|
|
3115
|
-
return err(
|
|
3116
|
-
command,
|
|
3117
|
-
"NOT_IMPLEMENTED",
|
|
3118
|
-
`'${command}' is not implemented over the private API`,
|
|
3119
|
-
"Commenting was captured from the live client on 2026-08-13 and is NOT replayable as a single request: com.linkedin.sdui.comments.createComment carries a trackingId from the feed render and an opaque binding key that only exists once a page has been rendered. Reaching it means fetching the SDUI screen first to harvest both. `share`, `delete` and `react` work over the private API. See docs/research/W5-sdui-writes.md."
|
|
3120
|
-
);
|
|
3121
|
-
}
|
|
3122
3306
|
async function gate(command, plan, ctx, deps) {
|
|
3123
3307
|
const gated = await gateWrite(command, plan, ctx.now, deps, {
|
|
3124
3308
|
commitSpend: ctx.transport.kind === "oauth"
|
|
@@ -3154,6 +3338,32 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
|
|
|
3154
3338
|
note: "note" in result ? result.note : ctx.note
|
|
3155
3339
|
});
|
|
3156
3340
|
}
|
|
3341
|
+
function activityIdOf(urn) {
|
|
3342
|
+
return /^urn:li:(?:activity|ugcPost|share):(\d+)$/.exec(urn)?.[1] ?? null;
|
|
3343
|
+
}
|
|
3344
|
+
async function harvest(activityId, session) {
|
|
3345
|
+
const headers2 = buildHeaders(session);
|
|
3346
|
+
let html;
|
|
3347
|
+
try {
|
|
3348
|
+
const res = await fetch(`https://www.linkedin.com/feed/update/urn:li:activity:${activityId}/`, {
|
|
3349
|
+
headers: {
|
|
3350
|
+
cookie: headers2.cookie ?? "",
|
|
3351
|
+
"user-agent": headers2["user-agent"] ?? "",
|
|
3352
|
+
accept: "text/html"
|
|
3353
|
+
},
|
|
3354
|
+
redirect: "manual"
|
|
3355
|
+
});
|
|
3356
|
+
if (res.status !== 200) {
|
|
3357
|
+
return err("comment", "FETCH_FAILED", `the post page returned ${res.status}`);
|
|
3358
|
+
}
|
|
3359
|
+
html = await res.text();
|
|
3360
|
+
} catch (e) {
|
|
3361
|
+
return err("comment", "FETCH_FAILED", `could not load the post page: ${e.message}`);
|
|
3362
|
+
}
|
|
3363
|
+
const found = extractCommentTokens(html, activityId);
|
|
3364
|
+
if (!found.ok) return err("comment", "SCHEMA_DRIFT", found.message, found.hint);
|
|
3365
|
+
return { ok: true, tokens: { bindingKey: found.bindingKey, trackingId: found.trackingId } };
|
|
3366
|
+
}
|
|
3157
3367
|
async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps()) {
|
|
3158
3368
|
if (postUrn2 === void 0 || text2 === void 0 || text2.trim() === "") {
|
|
3159
3369
|
return err(
|
|
@@ -3163,24 +3373,40 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3163
3373
|
'lnrelay comment <urn> "<text>"'
|
|
3164
3374
|
);
|
|
3165
3375
|
}
|
|
3166
|
-
const
|
|
3376
|
+
const activityId = activityIdOf(postUrn2);
|
|
3377
|
+
if (activityId === null) {
|
|
3378
|
+
return err("comment", "INVALID_INPUT", `'${postUrn2}' does not identify a post`);
|
|
3379
|
+
}
|
|
3380
|
+
if (!deps.isTty) {
|
|
3381
|
+
return err(
|
|
3382
|
+
"comment",
|
|
3383
|
+
"CONFIRMATION_REQUIRED",
|
|
3384
|
+
"commenting needs a human to confirm it at an interactive terminal",
|
|
3385
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3386
|
+
);
|
|
3387
|
+
}
|
|
3388
|
+
const ctx = prepare("comment", now, "voyager");
|
|
3167
3389
|
if ("ok" in ctx) return ctx;
|
|
3168
|
-
|
|
3169
|
-
|
|
3390
|
+
if (ctx.transport.kind !== "voyager") {
|
|
3391
|
+
return err("comment", "NOT_IMPLEMENTED", "commenting is only implemented over the private API");
|
|
3392
|
+
}
|
|
3393
|
+
const harvested = await harvest(activityId, ctx.transport.session);
|
|
3394
|
+
if ("ok" in harvested && harvested.ok !== true) return harvested;
|
|
3395
|
+
if (!("tokens" in harvested)) return harvested;
|
|
3170
3396
|
const plan = {
|
|
3171
3397
|
action: "comment on a post",
|
|
3172
|
-
payload: {
|
|
3398
|
+
payload: { activityId, text: text2, tokens: harvested.tokens },
|
|
3173
3399
|
summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
|
|
3174
|
-
reversibility: "deletable from the LinkedIn UI; the author is notified immediately",
|
|
3175
|
-
transport: "
|
|
3400
|
+
reversibility: "deletable from the LinkedIn UI; the author is notified immediately and cannot un-see it",
|
|
3401
|
+
transport: "voyager"
|
|
3176
3402
|
};
|
|
3177
3403
|
const gated = await gate("comment", plan, ctx, deps);
|
|
3178
3404
|
if ("ok" in gated) return gated;
|
|
3179
|
-
const result = await comment(
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
return result.ok ? ok("comment", { id: result.id }) : err("comment", result.code, result.message, result.hint);
|
|
3405
|
+
const result = await comment(
|
|
3406
|
+
gated.confirmed,
|
|
3407
|
+
createLiveClient(ctx.transport.session)
|
|
3408
|
+
);
|
|
3409
|
+
return result.ok ? ok("comment", { id: result.id, on: postUrn2 }) : err("comment", result.code, result.message, result.hint);
|
|
3184
3410
|
}
|
|
3185
3411
|
var REACTIONS2 = REACTIONS;
|
|
3186
3412
|
async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(), remove = false) {
|